bool TypeSystemClang::IsTypedefType(lldb::opaque_compiler_type_t type) {
if (!type)
return false;
- return GetQualType(type)->getTypeClass() == clang::Type::Typedef;
+ return RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef})
+ ->getTypeClass() == clang::Type::Typedef;
}
bool TypeSystemClang::IsVoidType(lldb::opaque_compiler_type_t type) {
CompilerType
TypeSystemClang::GetTypedefedType(lldb::opaque_compiler_type_t type) {
if (type) {
- const clang::TypedefType *typedef_type =
- llvm::dyn_cast<clang::TypedefType>(GetQualType(type));
+ const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(
+ RemoveWrappingTypes(GetQualType(type), {clang::Type::Typedef}));
if (typedef_type)
return GetType(typedef_type->getDecl()->getUnderlyingType());
}
--- /dev/null
+"""
+Test that we can retrieve typedefed types correctly
+"""
+
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import decorators
+
+class TestCppTypedef(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test_typedef(self):
+ """
+ Test that we retrieve typedefed types correctly
+ """
+
+ # Build and run until the breakpoint
+ self.build()
+ self.main_source_file = lldb.SBFileSpec("main.cpp")
+ (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+ self, "Set a breakpoint here", self.main_source_file)
+
+ # Get the current frame
+ frame = thread.GetSelectedFrame()
+
+ # First of all, check that we can get a typedefed type correctly in a simple case
+
+ expr_result = frame.EvaluateExpression("(SF)s")
+ self.assertTrue(expr_result.IsValid(), "Expression failed with: " + str(expr_result.GetError()))
+
+ typedef_type = expr_result.GetType();
+ self.assertTrue(typedef_type.IsValid(), "Can't get `SF` type of evaluated expression")
+ self.assertTrue(typedef_type.IsTypedefType(), "Type `SF` should be a typedef")
+
+ typedefed_type = typedef_type.GetTypedefedType()
+ self.assertTrue(typedefed_type.IsValid(), "Can't get `SF` typedefed type")
+ self.assertEqual(typedefed_type.GetName(), "S<float>", "Got invalid `SF` typedefed type")
+
+ # Check that we can get a typedefed type correctly in the case
+ # when an elaborated type is created during the parsing
+
+ expr_result = frame.EvaluateExpression("(SF::V)s.value")
+ self.assertTrue(expr_result.IsValid(), "Expression failed with: " + str(expr_result.GetError()))
+
+ typedef_type = expr_result.GetType();
+ self.assertTrue(typedef_type.IsValid(), "Can't get `SF::V` type of evaluated expression")
+ self.assertTrue(typedef_type.IsTypedefType(), "Type `SF::V` should be a typedef")
+
+ typedefed_type = typedef_type.GetTypedefedType()
+ self.assertTrue(typedefed_type.IsValid(), "Can't get `SF::V` typedefed type")
+ self.assertEqual(typedefed_type.GetName(), "float", "Got invalid `SF::V` typedefed type")