diff --git a/lldb/bindings/interface/SBType.i b/lldb/bindings/interface/SBType.i --- a/lldb/bindings/interface/SBType.i +++ b/lldb/bindings/interface/SBType.i @@ -244,6 +244,9 @@ lldb::SBType GetCanonicalType(); + lldb::SBType + GetEnumerationIntegerType(); + lldb::SBType GetArrayElementType (); diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -152,6 +152,9 @@ lldb::SBType GetVectorElementType(); lldb::SBType GetCanonicalType(); + + lldb::SBType GetEnumerationIntegerType(); + // Get the "lldb::BasicType" enumeration for a type. If a type is not a basic // type eBasicTypeInvalid will be returned lldb::BasicType GetBasicType(); diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -187,6 +187,8 @@ CompilerType GetFullyUnqualifiedType() const; + CompilerType GetEnumerationIntegerType() const; + /// Returns -1 if this isn't a function of if the function doesn't /// have a prototype Returns a value >= 0 if there is a prototype. int GetFunctionArgumentCount() const; diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -228,6 +228,9 @@ virtual CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) = 0; + virtual CompilerType + GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) = 0; + // Returns -1 if this isn't a function of if the function doesn't have a // prototype Returns a value >= 0 if there is a prototype. virtual int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) = 0; diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -344,6 +344,16 @@ return LLDB_RECORD_RESULT(SBType()); } +SBType SBType::GetEnumerationIntegerType() { + LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetEnumerationIntegerType); + + if (IsValid()) { + return LLDB_RECORD_RESULT( + SBType(m_opaque_sp->GetCompilerType(true).GetEnumerationIntegerType())); + } + return LLDB_RECORD_RESULT(SBType()); +} + lldb::BasicType SBType::GetBasicType() { LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType); @@ -952,6 +962,7 @@ GetMemberFunctionAtIndex, (uint32_t)); LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ()); LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ()); + LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetEnumerationIntegerType, ()); LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ()); LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType)); LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ()); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -698,6 +698,9 @@ CompilerType GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override; + CompilerType + GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override; + // Returns -1 if this isn't a function of if the function doesn't have a // prototype Returns a value >= 0 if there is a prototype. int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override; diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -4189,6 +4189,13 @@ return CompilerType(); } +CompilerType +TypeSystemClang::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) { + if (type) + return GetEnumerationIntegerType(GetType(GetCanonicalQualType(type))); + return CompilerType(); +} + int TypeSystemClang::GetFunctionArgumentCount( lldb::opaque_compiler_type_t type) { if (type) { diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -350,6 +350,12 @@ return CompilerType(); } +CompilerType CompilerType::GetEnumerationIntegerType() const { + if (IsValid()) + return m_type_system->GetEnumerationIntegerType(m_type); + return CompilerType(); +} + int CompilerType::GetFunctionArgumentCount() const { if (IsValid()) { return m_type_system->GetFunctionArgumentCount(m_type); diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -150,7 +150,24 @@ self.assertTrue(enum_type) self.DebugSBType(enum_type) self.assertFalse(enum_type.IsScopedEnumerationType()) + int_enum_type = enum_type.GetEnumerationIntegerType() + self.assertTrue(int_enum_type) + self.DebugSBType(int_enum_type) + self.assertEquals(int_enum_type.GetName(), 'unsigned int') + scoped_enum_type = target.FindFirstType('ScopedEnumType') self.assertTrue(scoped_enum_type) self.DebugSBType(scoped_enum_type) self.assertTrue(scoped_enum_type.IsScopedEnumerationType()) + int_scoped_enum_type = scoped_enum_type.GetEnumerationIntegerType() + self.assertTrue(int_scoped_enum_type) + self.DebugSBType(int_scoped_enum_type) + self.assertEquals(int_scoped_enum_type.GetName(), 'int') + + enum_uchar = target.FindFirstType('EnumUChar') + self.assertTrue(enum_uchar) + self.DebugSBType(enum_uchar) + int_enum_uchar = enum_uchar.GetEnumerationIntegerType() + self.assertTrue(int_enum_uchar) + self.DebugSBType(int_enum_uchar) + self.assertEquals(int_enum_uchar.GetName(), 'unsigned char') diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -31,6 +31,7 @@ enum EnumType {}; enum class ScopedEnumType {}; +enum class EnumUChar : unsigned char {}; int main (int argc, char const *argv[]) { @@ -63,6 +64,7 @@ EnumType enum_type; ScopedEnumType scoped_enum_type; + EnumUChar scoped_enum_type_uchar; return 0; // Break at this line }