diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation')
15 files changed, 1103 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/Makefile new file mode 100644 index 00000000000..e95ebd94a94 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/Makefile @@ -0,0 +1,7 @@ +OBJC_SOURCES := main.m my-base.m +#OBJC_SOURCES := const-strings.m + + + +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestConstStrings.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestConstStrings.py new file mode 100644 index 00000000000..6e8e9898e19 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestConstStrings.py @@ -0,0 +1,57 @@ +""" +Test that objective-c constant strings are generated correctly by the expression +parser. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ConstStringTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + d = {'OBJC_SOURCES': 'const-strings.m'} + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.main_source = "const-strings.m" + self.line = line_number(self.main_source, '// Set breakpoint here.') + + @skipUnlessDarwin + def test_break(self): + """Test constant string generation amd comparison by the expression parser.""" + self.build(dictionary=self.d) + self.setTearDownCleanup(self.d) + + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + self.main_source, + self.line, + num_expected_locations=1, + loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + self.expect("process status", STOPPED_DUE_TO_BREAKPOINT, + substrs=[" at %s:%d" % (self.main_source, self.line), + "stop reason = breakpoint"]) + + self.expect('expression (int)[str compare:@"hello"]', + startstr="(int) $0 = 0") + self.expect('expression (int)[str compare:@"world"]', + startstr="(int) $1 = -1") + + # Test empty strings, too. + self.expect('expression (int)[@"" length]', + startstr="(int) $2 = 0") + + self.expect('expression (int)[@"123" length]', + startstr="(int) $3 = 3") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestFoundationDisassembly.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestFoundationDisassembly.py new file mode 100644 index 00000000000..9e39a735f8b --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestFoundationDisassembly.py @@ -0,0 +1,151 @@ +""" +Test the lldb disassemble command on foundation framework. +""" + +import unittest2 +import os +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class FoundationDisassembleTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + @skipIfAsan + def test_foundation_disasm(self): + """Do 'disassemble -n func' on each and every 'Code' symbol entry from the Foundation.framework.""" + self.build() + + # Enable synchronous mode + self.dbg.SetAsync(False) + + # Create a target by the debugger. + target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + self.assertTrue(target, VALID_TARGET) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + foundation_framework = None + for module in target.modules: + if module.file.basename == "Foundation": + foundation_framework = module.file.fullpath + break + + self.assertTrue( + foundation_framework is not None, + "Foundation.framework path located") + self.runCmd("image dump symtab '%s'" % foundation_framework) + raw_output = self.res.GetOutput() + # Now, grab every 'Code' symbol and feed it into the command: + # 'disassemble -n func'. + # + # The symbol name is on the last column and trails the flag column which + # looks like '0xhhhhhhhh', i.e., 8 hexadecimal digits. + codeRE = re.compile(r""" + \ Code\ {9} # ' Code' followed by 9 SPCs, + .* # the wildcard chars, + 0x[0-9a-f]{8} # the flag column, and + \ (.+)$ # finally the function symbol. + """, re.VERBOSE) + for line in raw_output.split(os.linesep): + match = codeRE.search(line) + if match: + func = match.group(1) + self.runCmd('image lookup -s "%s"' % func) + self.runCmd('disassemble -n "%s"' % func) + + @skipIfAsan + def test_simple_disasm(self): + """Test the lldb 'disassemble' command""" + self.build() + + # Create a target by the debugger. + target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + self.assertTrue(target, VALID_TARGET) + + # Stop at +[NSString stringWithFormat:]. + symbol_name = "+[NSString stringWithFormat:]" + break_results = lldbutil.run_break_set_command( + self, "_regexp-break %s" % (symbol_name)) + + lldbutil.check_breakpoint_result( + self, + break_results, + symbol_name=symbol_name, + num_locations=1) + + # Stop at -[MyString initWithNSString:]. + lldbutil.run_break_set_by_symbol( + self, + '-[MyString initWithNSString:]', + num_expected_locations=1, + sym_exact=True) + + # Stop at the "description" selector. + lldbutil.run_break_set_by_selector( + self, + 'description', + num_expected_locations=1, + module_name='a.out') + + # Stop at -[NSAutoreleasePool release]. + break_results = lldbutil.run_break_set_command( + self, "_regexp-break -[NSAutoreleasePool release]") + lldbutil.check_breakpoint_result( + self, + break_results, + symbol_name='-[NSAutoreleasePool release]', + num_locations=1) + + self.runCmd("run", RUN_SUCCEEDED) + + # First stop is +[NSString stringWithFormat:]. + self.expect( + "thread backtrace", + "Stop at +[NSString stringWithFormat:]", + substrs=["Foundation`+[NSString stringWithFormat:]"]) + + # Do the disassemble for the currently stopped function. + self.runCmd("disassemble -f") + + self.runCmd("process continue") + # Skip another breakpoint for +[NSString stringWithFormat:]. + self.runCmd("process continue") + + # Followed by a.out`-[MyString initWithNSString:]. + self.expect( + "thread backtrace", + "Stop at a.out`-[MyString initWithNSString:]", + substrs=["a.out`-[MyString initWithNSString:]"]) + + # Do the disassemble for the currently stopped function. + self.runCmd("disassemble -f") + + self.runCmd("process continue") + + # Followed by -[MyString description]. + self.expect("thread backtrace", "Stop at -[MyString description]", + substrs=["a.out`-[MyString description]"]) + + # Do the disassemble for the currently stopped function. + self.runCmd("disassemble -f") + + self.runCmd("process continue") + # Skip another breakpoint for -[MyString description]. + self.runCmd("process continue") + + # Followed by -[NSAutoreleasePool release]. + self.expect("thread backtrace", "Stop at -[NSAutoreleasePool release]", + substrs=["Foundation`-[NSAutoreleasePool release]"]) + + # Do the disassemble for the currently stopped function. + self.runCmd("disassemble -f") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods.py new file mode 100644 index 00000000000..7d4990c4f38 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods.py @@ -0,0 +1,325 @@ +""" +Set breakpoints on objective-c class and instance methods in foundation. +Also lookup objective-c data types and evaluate expressions. +""" + +from __future__ import print_function + + +import os +import os.path +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +file_index = 0 + + +@skipUnlessDarwin +class FoundationTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.main_source = "main.m" + self.line = line_number( + self.main_source, + '// Set break point at this line.') + + def test_break(self): + """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Stop at +[NSString stringWithFormat:]. + break_results = lldbutil.run_break_set_command( + self, "_regexp-break +[NSString stringWithFormat:]") + lldbutil.check_breakpoint_result( + self, + break_results, + symbol_name='+[NSString stringWithFormat:]', + num_locations=1) + + # Stop at -[MyString initWithNSString:]. + lldbutil.run_break_set_by_symbol( + self, + '-[MyString initWithNSString:]', + num_expected_locations=1, + sym_exact=True) + + # Stop at the "description" selector. + lldbutil.run_break_set_by_selector( + self, + 'description', + num_expected_locations=1, + module_name='a.out') + + # Stop at -[NSAutoreleasePool release]. + break_results = lldbutil.run_break_set_command( + self, "_regexp-break -[NSAutoreleasePool release]") + lldbutil.check_breakpoint_result( + self, + break_results, + symbol_name='-[NSAutoreleasePool release]', + num_locations=1) + + self.runCmd("run", RUN_SUCCEEDED) + + # First stop is +[NSString stringWithFormat:]. + self.expect( + "thread backtrace", + "Stop at +[NSString stringWithFormat:]", + substrs=["Foundation`+[NSString stringWithFormat:]"]) + + self.runCmd("process continue") + + # Second stop is still +[NSString stringWithFormat:]. + self.expect( + "thread backtrace", + "Stop at +[NSString stringWithFormat:]", + substrs=["Foundation`+[NSString stringWithFormat:]"]) + + self.runCmd("process continue") + + # Followed by a.out`-[MyString initWithNSString:]. + self.expect( + "thread backtrace", + "Stop at a.out`-[MyString initWithNSString:]", + substrs=["a.out`-[MyString initWithNSString:]"]) + + self.runCmd("process continue") + + # Followed by -[MyString description]. + self.expect("thread backtrace", "Stop at -[MyString description]", + substrs=["a.out`-[MyString description]"]) + + self.runCmd("process continue") + + # Followed by the same -[MyString description]. + self.expect("thread backtrace", "Stop at -[MyString description]", + substrs=["a.out`-[MyString description]"]) + + self.runCmd("process continue") + + # Followed by -[NSAutoreleasePool release]. + self.expect("thread backtrace", "Stop at -[NSAutoreleasePool release]", + substrs=["Foundation`-[NSAutoreleasePool release]"]) + + # rdar://problem/8542091 + # rdar://problem/8492646 + def test_data_type_and_expr(self): + """Lookup objective-c data types and evaluate expressions.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Stop at -[MyString description]. + lldbutil.run_break_set_by_symbol( + self, + '-[MyString description]', + num_expected_locations=1, + sym_exact=True) +# self.expect("breakpoint set -n '-[MyString description]", BREAKPOINT_CREATED, +# startstr = "Breakpoint created: 1: name = '-[MyString description]', +# locations = 1") + + self.runCmd("run", RUN_SUCCEEDED) + + # The backtrace should show we stop at -[MyString description]. + self.expect("thread backtrace", "Stop at -[MyString description]", + substrs=["a.out`-[MyString description]"]) + + # Lookup objc data type MyString and evaluate some expressions. + + self.expect("image lookup -t NSString", DATA_TYPES_DISPLAYED_CORRECTLY, + substrs=['name = "NSString"', + 'compiler_type = "@interface NSString']) + + self.expect("image lookup -t MyString", DATA_TYPES_DISPLAYED_CORRECTLY, + substrs=['name = "MyString"', + 'compiler_type = "@interface MyString', + 'NSString * str;', + 'NSDate * date;']) + + self.expect( + "frame variable --show-types --scope", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=["ARG: (MyString *) self"], + patterns=[ + "ARG: \(.*\) _cmd", + "(objc_selector *)|(SEL)"]) + + # rdar://problem/8651752 + # don't crash trying to ask clang how many children an empty record has + self.runCmd("frame variable *_cmd") + + # rdar://problem/8492646 + # test/foundation fails after updating to tot r115023 + # self->str displays nothing as output + self.expect( + "frame variable --show-types self->str", + VARIABLES_DISPLAYED_CORRECTLY, + startstr="(NSString *) self->str") + + # rdar://problem/8447030 + # 'frame variable self->date' displays the wrong data member + self.expect( + "frame variable --show-types self->date", + VARIABLES_DISPLAYED_CORRECTLY, + startstr="(NSDate *) self->date") + + # This should display the str and date member fields as well. + self.expect( + "frame variable --show-types *self", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + "(MyString) *self", + "(NSString *) str", + "(NSDate *) date"]) + + # isa should be accessible. + self.expect("expression self->isa", VARIABLES_DISPLAYED_CORRECTLY, + substrs=["(Class)"]) + + # This should fail expectedly. + self.expect( + "expression self->non_existent_member", + COMMAND_FAILED_AS_EXPECTED, + error=True, + substrs=["error:", "'MyString' does not have a member named 'non_existent_member'"]) + + # Use expression parser. + self.runCmd("expression self->str") + self.runCmd("expression self->date") + + # (lldb) expression self->str + # error: instance variable 'str' is protected + # error: 1 errors parsing expression + # + # (lldb) expression self->date + # error: instance variable 'date' is protected + # error: 1 errors parsing expression + # + + self.runCmd("breakpoint delete 1") + lldbutil.run_break_set_by_file_and_line( + self, "main.m", self.line, num_expected_locations=1, loc_exact=True) + + self.runCmd("process continue") + + # rdar://problem/8542091 + # test/foundation: expr -o -- my not working? + # + # Test new feature with r115115: + # Add "-o" option to "expression" which prints the object description + # if available. + self.expect( + "expression --object-description -- my", + "Object description displayed correctly", + patterns=["Hello from.*a.out.*with timestamp: "]) + + @add_test_categories(['pyapi']) + def test_print_ivars_correctly(self): + self.build() + # See: <rdar://problem/8717050> lldb needs to use the ObjC runtime symbols for ivar offsets + # Only fails for the ObjC 2.0 runtime. + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + break1 = target.BreakpointCreateByLocation(self.main_source, self.line) + self.assertTrue(break1, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + + self.assertTrue(process, PROCESS_IS_VALID) + + # The stop reason of the thread should be breakpoint. + thread = process.GetThreadAtIndex(0) + if thread.GetStopReason() != lldb.eStopReasonBreakpoint: + from lldbsuite.test.lldbutil import stop_reason_to_str + self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % + stop_reason_to_str(thread.GetStopReason())) + + # Make sure we stopped at the first breakpoint. + + cur_frame = thread.GetFrameAtIndex(0) + + line_number = cur_frame.GetLineEntry().GetLine() + self.assertTrue(line_number == self.line, "Hit the first breakpoint.") + + my_var = cur_frame.FindVariable("my") + self.assertTrue(my_var, "Made a variable object for my") + + str_var = cur_frame.FindVariable("str") + self.assertTrue(str_var, "Made a variable object for str") + + # Now make sure that the my->str == str: + + my_str_var = my_var.GetChildMemberWithName("str") + self.assertTrue(my_str_var, "Found a str ivar in my") + + str_value = int(str_var.GetValue(), 0) + + my_str_value = int(my_str_var.GetValue(), 0) + + self.assertTrue( + str_value == my_str_value, + "Got the correct value for my->str") + + def test_expression_lookups_objc(self): + """Test running an expression detect spurious debug info lookups (DWARF).""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Stop at -[MyString initWithNSString:]. + lldbutil.run_break_set_by_symbol( + self, + '-[MyString initWithNSString:]', + num_expected_locations=1, + sym_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + global file_index + # Log any DWARF lookups + ++file_index + logfile = os.path.join( + self.getBuildDir(), + "dwarf-lookups-" + + self.getArchitecture() + + "-" + + str(file_index) + + ".txt") + self.runCmd("log enable -f %s dwarf lookups" % (logfile)) + self.runCmd("expr self") + self.runCmd("log disable dwarf lookups") + + def cleanup(): + if os.path.exists(logfile): + os.unlink(logfile) + + self.addTearDownHook(cleanup) + + if os.path.exists(logfile): + f = open(logfile) + lines = f.readlines() + num_errors = 0 + for line in lines: + if "$__lldb" in line: + if num_errors == 0: + print( + "error: found spurious name lookups when evaluating an expression:") + num_errors += 1 + print(line, end='') + self.assertTrue(num_errors == 0, "Spurious lookups detected") + f.close() diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods2.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods2.py new file mode 100644 index 00000000000..b2d0d190eb0 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethods2.py @@ -0,0 +1,40 @@ +""" +Test more expression command sequences with objective-c. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class FoundationTestCase2(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def test_expr_commands(self): + """More expression commands for objective-c.""" + self.build() + main_spec = lldb.SBFileSpec("main.m") + + (target, process, thread, bp) = lldbutil.run_to_source_breakpoint( + self, "Break here for selector: tests", main_spec) + + # Test_Selector: + self.expect("expression (char *)sel_getName(sel)", + substrs=["(char *)", + "length"]) + + desc_bkpt = target.BreakpointCreateBySourceRegex("Break here for description test", + main_spec) + self.assertEqual(desc_bkpt.GetNumLocations(), 1, "description breakpoint has a location") + lldbutil.continue_to_breakpoint(process, desc_bkpt) + + self.expect("expression (char *)sel_getName(_cmd)", + substrs=["(char *)", + "description"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsNSArray.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsNSArray.py new file mode 100644 index 00000000000..8080029ef02 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsNSArray.py @@ -0,0 +1,36 @@ +""" +Test more expression command sequences with objective-c. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class FoundationTestCaseNSArray(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_NSArray_expr_commands(self): + """Test expression commands for NSArray.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Break here for NSArray tests', + lldb.SBFileSpec('main.m', False)) + + self.runCmd("thread backtrace") + self.expect("expression (int)[nil_mutable_array count]", + patterns=["\(int\) \$.* = 0"]) + self.expect("expression (int)[array1 count]", + patterns=["\(int\) \$.* = 3"]) + self.expect("expression (int)[array2 count]", + patterns=["\(int\) \$.* = 3"]) + self.expect("expression (int)array1.count", + patterns=["\(int\) \$.* = 3"]) + self.expect("expression (int)array2.count", + patterns=["\(int\) \$.* = 3"]) + self.runCmd("process continue") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsNSError.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsNSError.py new file mode 100644 index 00000000000..07717926b5e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsNSError.py @@ -0,0 +1,49 @@ +""" +Test more expression command sequences with objective-c. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class FoundationTestCaseNSError(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>") + def test_runtime_types(self): + """Test commands that require runtime types""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Break here for NSString tests', + lldb.SBFileSpec('main.m', False)) + + # Test_NSString: + self.runCmd("thread backtrace") + self.expect("expression [str length]", + patterns=["\(NSUInteger\) \$.* ="]) + self.expect("expression str.length") + self.expect('expression str = [NSString stringWithCString: "new"]') + self.expect( + 'po [NSError errorWithDomain:@"Hello" code:35 userInfo:@{@"NSDescription" : @"be completed."}]', + substrs=[ + "Error Domain=Hello", + "Code=35", + "be completed."]) + self.runCmd("process continue") + + @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>") + def test_NSError_p(self): + """Test that p of the result of an unknown method does require a cast.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line', + lldb.SBFileSpec('main.m', False)) + self.expect("p [NSError thisMethodIsntImplemented:0]", error=True, patterns=[ + "no known method", "cast the message send to the method's return type"]) + self.runCmd("process continue") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsString.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsString.py new file mode 100644 index 00000000000..65ccb0c19b5 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjCMethodsString.py @@ -0,0 +1,53 @@ +""" +Test more expression command sequences with objective-c. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class FoundationTestCaseString(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_NSString_expr_commands(self): + """Test expression commands for NSString.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Break here for NSString tests', + lldb.SBFileSpec('main.m', False)) + + # Test_NSString: + self.runCmd("thread backtrace") + self.expect("expression (int)[str length]", + patterns=["\(int\) \$.* ="]) + self.expect("expression (int)[str_id length]", + patterns=["\(int\) \$.* ="]) + self.expect("expression (id)[str description]", + patterns=["\(id\) \$.* = 0x"]) + self.expect("expression (id)[str_id description]", + patterns=["\(id\) \$.* = 0x"]) + self.expect("expression str.length") + self.expect('expression str = @"new"') + self.runCmd("image lookup -t NSString") + self.expect('expression str = (id)[NSString stringWithCString: "new"]') + self.runCmd("process continue") + + @expectedFailureAll(archs=["i[3-6]86"], bugnumber="<rdar://problem/28814052>") + def test_MyString_dump_with_runtime(self): + """Test dump of a known Objective-C object by dereferencing it.""" + self.build() + self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, '// Set break point at this line', + lldb.SBFileSpec('main.m', False)) + self.expect( + "expression --show-types -- *my", + patterns=[ + "\(MyString\) \$.* = ", + "\(MyBase\)"]) + self.runCmd("process continue") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjectDescriptionAPI.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjectDescriptionAPI.py new file mode 100644 index 00000000000..803cbfe1218 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestObjectDescriptionAPI.py @@ -0,0 +1,75 @@ +""" +Test SBValue.GetObjectDescription() with the value from SBTarget.FindGlobalVariables(). +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class ObjectDescriptionAPITestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.source = 'main.m' + self.line = line_number( + self.source, '// Set break point at this line.') + + # rdar://problem/10857337 + @skipUnlessDarwin + @add_test_categories(['pyapi']) + def test_find_global_variables_then_object_description(self): + """Exercise SBTarget.FindGlobalVariables() API.""" + d = {'EXE': 'b.out'} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + exe = self.getBuildArtifact('b.out') + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + breakpoint = target.BreakpointCreateByLocation(self.source, self.line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + # Make sure we hit our breakpoint: + thread_list = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint) + self.assertTrue(len(thread_list) == 1) + + thread = thread_list[0] + frame0 = thread.GetFrameAtIndex(0) + + # Note my_global_str's object description prints fine here. + value_list1 = frame0.GetVariables(True, True, True, True) + for v in value_list1: + self.DebugSBValue(v) + if self.TraceOn(): + print("val:", v) + print("object description:", v.GetObjectDescription()) + if v.GetName() == 'my_global_str': + self.assertTrue(v.GetObjectDescription() == + 'This is a global string') + + # But not here! + value_list2 = target.FindGlobalVariables('my_global_str', 3) + for v in value_list2: + self.DebugSBValue(v) + if self.TraceOn(): + print("val:", v) + print("object description:", v.GetObjectDescription()) + if v.GetName() == 'my_global_str': + self.assertTrue(v.GetObjectDescription() == + 'This is a global string') diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestRuntimeTypes.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestRuntimeTypes.py new file mode 100644 index 00000000000..f5cb75b4a6d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestRuntimeTypes.py @@ -0,0 +1,59 @@ +""" +Test that Objective-C methods from the runtime work correctly. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class RuntimeTypesTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll( + oslist=["macosx"], + debug_info="gmodules", + bugnumber="llvm.org/pr27862") + def test_break(self): + """Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'.""" + if self.getArchitecture() != 'x86_64': + self.skipTest("This only applies to the v2 runtime") + + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Stop at -[MyString description]. + lldbutil.run_break_set_by_symbol( + self, + '-[MyString description]', + num_expected_locations=1, + sym_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + # The backtrace should show we stop at -[MyString description]. + self.expect("thread backtrace", "Stop at -[MyString description]", + substrs=["a.out`-[MyString description]"]) + + # Use runtime information about NSString. + + # The length property should be usable. + self.expect("expression str.length", VARIABLES_DISPLAYED_CORRECTLY, + patterns=[r"(\(unsigned long long\))|\(NSUInteger\)"]) + + # Static methods on NSString should work. + self.expect( + "expr [NSString stringWithCString:\"foo\" encoding:1]", + VALID_TYPE, + substrs=[ + "(id)", + "$1"]) + + self.expect("po $1", VARIABLES_DISPLAYED_CORRECTLY, + substrs=["foo"]) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestSymbolTable.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestSymbolTable.py new file mode 100644 index 00000000000..abfc7621e2e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/TestSymbolTable.py @@ -0,0 +1,68 @@ +""" +Test symbol table access for main.m. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +@skipUnlessDarwin +class FoundationSymtabTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + symbols_list = ['-[MyString initWithNSString:]', + '-[MyString dealloc]', + '-[MyString description]', + '-[MyString descriptionPauses]', # synthesized property + # synthesized property + '-[MyString setDescriptionPauses:]', + 'Test_Selector', + 'Test_NSString', + 'Test_MyString', + 'Test_NSArray', + 'main' + ] + + @add_test_categories(['pyapi']) + def test_with_python_api(self): + """Test symbol table access with Python APIs.""" + self.build() + exe = self.getBuildArtifact("a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Launch the process, and do not stop at the entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + + # + # Exercise Python APIs to access the symbol table entries. + # + + # Create the filespec by which to locate our a.out module. + filespec = lldb.SBFileSpec(exe, False) + + module = target.FindModule(filespec) + self.assertTrue(module, VALID_MODULE) + + # Create the set of known symbols. As we iterate through the symbol + # table, remove the symbol from the set if it is a known symbol. + expected_symbols = set(self.symbols_list) + for symbol in module: + self.assertTrue(symbol, VALID_SYMBOL) + #print("symbol:", symbol) + name = symbol.GetName() + if name in expected_symbols: + #print("Removing %s from known_symbols %s" % (name, expected_symbols)) + expected_symbols.remove(name) + + # At this point, the known_symbols set should have become an empty set. + # If not, raise an error. + #print("symbols unaccounted for:", expected_symbols) + self.assertTrue(len(expected_symbols) == 0, + "All the known symbols are accounted for") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/const-strings.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/const-strings.m new file mode 100644 index 00000000000..8a43abee7b8 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/const-strings.m @@ -0,0 +1,24 @@ +#import <Foundation/Foundation.h> + +// Tests to run: + +// Breakpoint 1 +// -- +// (lldb) expr (int)[str compare:@"hello"] +// (int) $0 = 0 +// (lldb) expr (int)[str compare:@"world"] +// (int) $1 = -1 +// (lldb) expr (int)[@"" length] +// (int) $2 = 0 + +int main () +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSString *str = [NSString stringWithCString:"hello" encoding:NSASCIIStringEncoding]; + + NSLog(@"String \"%@\" has length %lu", str, [str length]); // Set breakpoint here. + + [pool drain]; + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/main.m new file mode 100644 index 00000000000..519bec5a3e6 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/main.m @@ -0,0 +1,141 @@ +#import <Foundation/Foundation.h> +#include <unistd.h> +#import "my-base.h" + +@interface MyString : MyBase { + NSString *str; + NSDate *date; + BOOL _desc_pauses; +} + +@property(retain) NSString * str_property; +@property BOOL descriptionPauses; + +- (id)initWithNSString:(NSString *)string; +@end + +@implementation MyString +@synthesize descriptionPauses = _desc_pauses; +@synthesize str_property = str; + +- (id)initWithNSString:(NSString *)string +{ + if (self = [super init]) + { + str = [NSString stringWithString:string]; + date = [NSDate date]; + } + self.descriptionPauses = NO; + return self; +} + +- (void)dealloc +{ + [date release]; + [str release]; + [super dealloc]; +} + +- (NSString *)description +{ + // Set a breakpoint on '-[MyString description]' and test expressions: + // expression (char *)sel_getName(_cmd) + if (self.descriptionPauses) // Break here for description test + { + printf ("\nAbout to sleep.\n"); + usleep(100000); + } + + return [str stringByAppendingFormat:@" with timestamp: %@", date]; +} +@end + +int +Test_Selector () +{ + SEL sel = @selector(length); + printf("sel = %p\n", sel); + // Expressions to test here for selector: + // expression (char *)sel_getName(sel) + // The expression above should return "sel" as it should be just + // a uniqued C string pointer. We were seeing the result pointer being + // truncated with recent LLDBs. + return 0; // Break here for selector: tests +} + +int +Test_NSString (const char *program) +{ + NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program]; + NSLog(@"NSString instance: %@", str); + printf("str = '%s'\n", [str cStringUsingEncoding: [NSString defaultCStringEncoding]]); + printf("[str length] = %zu\n", (size_t)[str length]); + printf("[str description] = %s\n", [[str description] UTF8String]); + id str_id = str; + // Expressions to test here for NSString: + // expression (char *)sel_getName(sel) + // expression [str length] + // expression [str_id length] + // expression [str description] + // expression [str_id description] + // expression str.length + // expression str.description + // expression str = @"new" + // expression str = [NSString stringWithFormat: @"%cew", 'N'] + return 0; // Break here for NSString tests +} + +NSString *my_global_str = NULL; + +void +Test_MyString (const char *program) +{ + my_global_str = @"This is a global string"; + NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program]; + MyString *my = [[MyString alloc] initWithNSString:str]; + NSLog(@"MyString instance: %@", [my description]); + my.descriptionPauses = YES; // Set break point at this line. Test 'expression -o -- my'. + NSLog(@"MyString instance: %@", [my description]); +} + +int +Test_NSArray () +{ + NSMutableArray *nil_mutable_array = nil; + NSArray *array1 = [NSArray arrayWithObjects: @"array1 object1", @"array1 object2", @"array1 object3", nil]; + NSArray *array2 = [NSArray arrayWithObjects: array1, @"array2 object2", @"array2 object3", nil]; + // Expressions to test here for NSArray: + // expression [nil_mutable_array count] + // expression [array1 count] + // expression array1.count + // expression [array2 count] + // expression array2.count + id obj; + // After each object at index call, use expression and validate object + obj = [array1 objectAtIndex: 0]; // Break here for NSArray tests + obj = [array1 objectAtIndex: 1]; + obj = [array1 objectAtIndex: 2]; + + obj = [array2 objectAtIndex: 0]; + obj = [array2 objectAtIndex: 1]; + obj = [array2 objectAtIndex: 2]; + NSUInteger count = [nil_mutable_array count]; + return 0; +} + + +int main (int argc, char const *argv[]) +{ + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + Test_Selector(); + Test_NSArray (); + Test_NSString (argv[0]); + Test_MyString (argv[0]); + + printf("sizeof(id) = %zu\n", sizeof(id)); + printf("sizeof(Class) = %zu\n", sizeof(Class)); + printf("sizeof(SEL) = %zu\n", sizeof(SEL)); + + [pool release]; + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/my-base.h b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/my-base.h new file mode 100644 index 00000000000..53202aa0de3 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/my-base.h @@ -0,0 +1,8 @@ +@interface MyBase : NSObject +{ +#if !__OBJC2__ + int maybe_used; // The 1.0 runtime needs to have backed properties... +#endif +} +@property int propertyMovesThings; +@end diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/my-base.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/my-base.m new file mode 100644 index 00000000000..0c316b244f2 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/objc/foundation/my-base.m @@ -0,0 +1,10 @@ +#import <Foundation/Foundation.h> +#import "my-base.h" +@implementation MyBase +#if __OBJC2__ +@synthesize propertyMovesThings; +#else +@synthesize propertyMovesThings = maybe_used; +#endif +@end + |