[Lldb-commits] [lldb] r252390 - Add SBType::IsAnonymousType() and relative plumbing in the debugger internals
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Fri Nov 6 18:06:57 PST 2015
Author: enrico
Date: Fri Nov 6 20:06:57 2015
New Revision: 252390
URL: http://llvm.org/viewvc/llvm-project?rev=252390&view=rev
Log:
Add SBType::IsAnonymousType() and relative plumbing in the debugger internals
For language that support such a thing, this API allows to ask whether a type is anonymous (i.e. has been given no name)
Comes with test case
Modified:
lldb/trunk/include/lldb/API/SBType.h
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/include/lldb/Symbol/CompilerType.h
lldb/trunk/include/lldb/Symbol/TypeSystem.h
lldb/trunk/packages/Python/lldbsuite/test/python_api/type/TestTypeList.py
lldb/trunk/packages/Python/lldbsuite/test/python_api/type/main.cpp
lldb/trunk/scripts/interface/SBType.i
lldb/trunk/source/API/SBType.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp
lldb/trunk/source/Symbol/CompilerType.cpp
lldb/trunk/source/Symbol/TypeSystem.cpp
Modified: lldb/trunk/include/lldb/API/SBType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBType.h (original)
+++ lldb/trunk/include/lldb/API/SBType.h Fri Nov 6 20:06:57 2015
@@ -158,6 +158,9 @@ public:
bool
IsTypedefType ();
+ bool
+ IsAnonymousType ();
+
lldb::SBType
GetPointerType();
Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Fri Nov 6 20:06:57 2015
@@ -606,6 +606,9 @@ public:
IsAggregateType (lldb::opaque_compiler_type_t type) override;
bool
+ IsAnonymousType (lldb::opaque_compiler_type_t type) override;
+
+ bool
IsBeingDefined (lldb::opaque_compiler_type_t type) override;
bool
Modified: lldb/trunk/include/lldb/Symbol/CompilerType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/CompilerType.h?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/CompilerType.h (original)
+++ lldb/trunk/include/lldb/Symbol/CompilerType.h Fri Nov 6 20:06:57 2015
@@ -107,6 +107,9 @@ public:
IsAggregateType () const;
bool
+ IsAnonymousType () const;
+
+ bool
IsBeingDefined () const;
bool
Modified: lldb/trunk/include/lldb/Symbol/TypeSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeSystem.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeSystem.h Fri Nov 6 20:06:57 2015
@@ -153,6 +153,9 @@ public:
virtual bool
IsAggregateType (lldb::opaque_compiler_type_t type) = 0;
+
+ virtual bool
+ IsAnonymousType (lldb::opaque_compiler_type_t type);
virtual bool
IsCharType (lldb::opaque_compiler_type_t type) = 0;
Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/type/TestTypeList.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/type/TestTypeList.py?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/type/TestTypeList.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/type/TestTypeList.py Fri Nov 6 20:06:57 2015
@@ -59,11 +59,16 @@ class TypeAndTypeListTestCase(TestBase):
for type in type_list:
self.assertTrue(type)
self.DebugSBType(type)
+ self.assertFalse(type.IsAnonymousType(), "Task is not anonymous")
for field in type.fields:
if field.name == "type":
for enum_member in field.type.enum_members:
self.assertTrue(enum_member)
self.DebugSBType(enum_member.type)
+ elif field.name == "my_type_is_nameless":
+ self.assertTrue(field.type.IsAnonymousType(), "my_type_is_nameless has an anonymous type")
+ elif field.name == "my_type_is_named":
+ self.assertFalse(field.type.IsAnonymousType(), "my_type_is_named has a named type")
# Pass an empty string. LLDB should not crash. :-)
fuzz_types = target.FindTypes(None)
Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/type/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/type/main.cpp?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/type/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/type/main.cpp Fri Nov 6 20:06:57 2015
@@ -16,6 +16,12 @@ public:
TASK_TYPE_1,
TASK_TYPE_2
} type;
+ struct {
+ int x;
+ } my_type_is_nameless;
+ struct name {
+ int x;
+ } my_type_is_named;
Task(int i, Task *n):
id(i),
next(n),
Modified: lldb/trunk/scripts/interface/SBType.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBType.i?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBType.i (original)
+++ lldb/trunk/scripts/interface/SBType.i Fri Nov 6 20:06:57 2015
@@ -215,6 +215,9 @@ public:
bool
IsTypedefType ();
+ bool
+ IsAnonymousType ();
+
lldb::SBType
GetPointerType();
Modified: lldb/trunk/source/API/SBType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/source/API/SBType.cpp (original)
+++ lldb/trunk/source/API/SBType.cpp Fri Nov 6 20:06:57 2015
@@ -264,6 +264,14 @@ SBType::IsTypedefType ()
return m_opaque_sp->GetCompilerType(true).IsTypedefType();
}
+bool
+SBType::IsAnonymousType ()
+{
+ if (!IsValid())
+ return false;
+ return m_opaque_sp->GetCompilerType(true).IsAnonymousType();
+}
+
lldb::SBType
SBType::GetFunctionReturnType ()
{
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Nov 6 20:06:57 2015
@@ -2585,6 +2585,38 @@ ClangASTContext::IsAggregateType (lldb::
}
bool
+ClangASTContext::IsAnonymousType (lldb::opaque_compiler_type_t type)
+{
+ clang::QualType qual_type (GetCanonicalQualType(type));
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Record:
+ {
+ if (const clang::RecordType *record_type = llvm::dyn_cast_or_null<clang::RecordType>(qual_type.getTypePtrOrNull()))
+ {
+ if (const clang::RecordDecl *record_decl = record_type->getDecl())
+ {
+ return record_decl->isAnonymousStructOrUnion();
+ }
+ }
+ break;
+ }
+ case clang::Type::Elaborated:
+ return IsAnonymousType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
+ case clang::Type::Typedef:
+ return IsAnonymousType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
+ case clang::Type::Paren:
+ return IsAnonymousType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
+ default:
+ break;
+ }
+ // The clang type does have a value
+ return false;
+}
+
+bool
ClangASTContext::IsArrayType (lldb::opaque_compiler_type_t type,
CompilerType *element_type_ptr,
uint64_t *size,
Modified: lldb/trunk/source/Symbol/CompilerType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CompilerType.cpp?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/CompilerType.cpp (original)
+++ lldb/trunk/source/Symbol/CompilerType.cpp Fri Nov 6 20:06:57 2015
@@ -64,6 +64,14 @@ CompilerType::IsAggregateType () const
}
bool
+CompilerType::IsAnonymousType () const
+{
+ if (IsValid())
+ return m_type_system->IsAnonymousType(m_type);
+ return false;
+}
+
+bool
CompilerType::IsArrayType (CompilerType *element_type_ptr,
uint64_t *size,
bool *is_incomplete) const
Modified: lldb/trunk/source/Symbol/TypeSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeSystem.cpp?rev=252390&r1=252389&r2=252390&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeSystem.cpp (original)
+++ lldb/trunk/source/Symbol/TypeSystem.cpp Fri Nov 6 20:06:57 2015
@@ -55,6 +55,12 @@ TypeSystem::CreateInstance (lldb::Langua
return lldb::TypeSystemSP();
}
+bool
+TypeSystem::IsAnonymousType (lldb::opaque_compiler_type_t type)
+{
+ return false;
+}
+
CompilerType
TypeSystem::GetLValueReferenceType (lldb::opaque_compiler_type_t type)
{
More information about the lldb-commits
mailing list