diff options
| author | Sean Callanan <scallanan@apple.com> | 2011-12-08 19:04:34 +0000 |
|---|---|---|
| committer | Sean Callanan <scallanan@apple.com> | 2011-12-08 19:04:34 +0000 |
| commit | 5780f9df56ec5efda7e40df8a88d8c6057663033 (patch) | |
| tree | 0ce22c6287cb52428592bfa51586316a051c6dbb | |
| parent | 4d1a2d449fff9d0883f5419766c60c8c54be70be (diff) | |
| download | bcm5719-llvm-5780f9df56ec5efda7e40df8a88d8c6057663033.tar.gz bcm5719-llvm-5780f9df56ec5efda7e40df8a88d8c6057663033.zip | |
Added the ability to dereference an Objective-C object
pointer to make the result of an expression. LLDB now
dumps the ivars of the Objective-C object and all of
its parents. This just required fixing a bug where we
didn't distinguish between Objective-C object pointers
and regular C-style pointers.
Also added a testcase to verify that this continues to
work.
llvm-svn: 146164
| -rw-r--r-- | lldb/source/Expression/ASTResultSynthesizer.cpp | 7 | ||||
| -rw-r--r-- | lldb/source/Expression/IRForTarget.cpp | 23 | ||||
| -rw-r--r-- | lldb/test/lang/objc/foundation/TestObjCMethods2.py | 29 |
3 files changed, 51 insertions, 8 deletions
diff --git a/lldb/source/Expression/ASTResultSynthesizer.cpp b/lldb/source/Expression/ASTResultSynthesizer.cpp index ff3b2f4814d..6e2551cf1d5 100644 --- a/lldb/source/Expression/ASTResultSynthesizer.cpp +++ b/lldb/source/Expression/ASTResultSynthesizer.cpp @@ -331,7 +331,12 @@ ASTResultSynthesizer::SynthesizeBodyResult (CompoundStmt *Body, else result_ptr_id = &Ctx.Idents.get("$__lldb_expr_result_ptr"); - QualType ptr_qual_type = Ctx.getPointerType(expr_qual_type); + QualType ptr_qual_type; + + if (isa<ObjCObjectType>(expr_qual_type)) + ptr_qual_type = Ctx.getObjCObjectPointerType(expr_qual_type); + else + ptr_qual_type = Ctx.getPointerType(expr_qual_type); result_decl = VarDecl::Create(Ctx, DC, diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index 4cf8d792f72..3722f34bd5d 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -631,9 +631,25 @@ IRForTarget::CreateResultVariable (llvm::Function &llvm_function) { clang::QualType pointer_qual_type = result_var->getType(); const clang::Type *pointer_type = pointer_qual_type.getTypePtr(); + const clang::PointerType *pointer_pointertype = dyn_cast<clang::PointerType>(pointer_type); + const clang::ObjCObjectPointerType *pointer_objcobjpointertype = dyn_cast<clang::ObjCObjectPointerType>(pointer_type); - if (!pointer_pointertype) + if (pointer_pointertype) + { + clang::QualType element_qual_type = pointer_pointertype->getPointeeType(); + + m_result_type = lldb_private::TypeFromParser(element_qual_type.getAsOpaquePtr(), + &result_decl->getASTContext()); + } + else if (pointer_objcobjpointertype) + { + clang::QualType element_qual_type = clang::QualType(pointer_objcobjpointertype->getObjectType(), 0); + + m_result_type = lldb_private::TypeFromParser(element_qual_type.getAsOpaquePtr(), + &result_decl->getASTContext()); + } + else { if (log) log->PutCString("Expected result to have pointer type, but it did not"); @@ -643,11 +659,6 @@ IRForTarget::CreateResultVariable (llvm::Function &llvm_function) return false; } - - clang::QualType element_qual_type = pointer_pointertype->getPointeeType(); - - m_result_type = lldb_private::TypeFromParser(element_qual_type.getAsOpaquePtr(), - &result_decl->getASTContext()); } else { diff --git a/lldb/test/lang/objc/foundation/TestObjCMethods2.py b/lldb/test/lang/objc/foundation/TestObjCMethods2.py index 07d36f81193..9092482dbd1 100644 --- a/lldb/test/lang/objc/foundation/TestObjCMethods2.py +++ b/lldb/test/lang/objc/foundation/TestObjCMethods2.py @@ -42,6 +42,16 @@ class FoundationTestCase2(TestBase): self.buildDwarf() self.NSString_expr() + def test_MyString_dump_with_dsym(self): + """Test dump of a known Objective-C object by dereferencing it.""" + self.buildDsym() + self.MyString_dump() + + def test_MyString_dump_with_dwarf(self): + """Test dump of a known Objective-C object by dereferencing it.""" + self.buildDwarf() + self.MyString_dump() + def setUp(self): # Call super's setUp(). TestBase.setUp(self) @@ -51,7 +61,8 @@ class FoundationTestCase2(TestBase): self.lines.append(line_number('main.m', '// Expressions to test here for NSArray:')) self.lines.append(line_number('main.m', '// Expressions to test here for NSString:')) self.lines.append(line_number('main.m', "// Set a breakpoint on '-[MyString description]' and test expressions:")) - + self.lines.append(line_number('main.m', '// Set break point at this line')) + def more_expr_objc(self): """More expression commands for objective-c.""" exe = os.path.join(os.getcwd(), "a.out") @@ -149,6 +160,22 @@ class FoundationTestCase2(TestBase): self.expect('expression str = [NSString stringWithFormat: @"%cew", \'N\']') self.runCmd("process continue") + def MyString_dump(self): + """Test dump of a known Objective-C object by dereferencing it.""" + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + line = self.lines[4] + + self.expect("breakpoint set -f main.m -l %d" % line, BREAKPOINT_CREATED, + substrs = ["Breakpoint created:", + "file ='main.m', line = %d, locations = 1" % line]) + + self.runCmd("run", RUN_SUCCEEDED) + + self.expect("expression *my", + patterns = ["\(MyString\) \$.* = ", "\(MyBase\)", "\(NSObject\)", "\(Class\)"]) + self.runCmd("process continue") if __name__ == '__main__': import atexit |

