Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb data formatter subsystem. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | import datetime |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 10 | import lldbutil |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 11 | |
Enrico Granata | 54ed7e1 | 2015-08-25 23:55:10 +0000 | [diff] [blame] | 12 | class NSArraySyntheticTestCase(TestBase): |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 13 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 14 | mydir = TestBase.compute_mydir(__file__) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 15 | |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 16 | def setUp(self): |
| 17 | # Call super's setUp(). |
| 18 | TestBase.setUp(self) |
| 19 | # Find the line number to break at. |
| 20 | self.line = line_number('main.m', '// Set break point at this line.') |
| 21 | |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 22 | @skipUnlessDarwin |
| 23 | def test_rdar11086338_with_run_command(self): |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 24 | """Test that NSArray reports its synthetic children properly.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 25 | self.build() |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 26 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 27 | |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 28 | lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 29 | |
Sean Callanan | 05834cd | 2015-07-01 23:56:30 +0000 | [diff] [blame] | 30 | self.runCmd("run", RUN_SUCCEEDED) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 31 | |
| 32 | # The stop reason of the thread should be breakpoint. |
| 33 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 34 | substrs = ['stopped', |
| 35 | 'stop reason = breakpoint']) |
| 36 | |
| 37 | # This is the function to remove the custom formats in order to have a |
| 38 | # clean slate for the next test case. |
| 39 | def cleanup(): |
| 40 | self.runCmd('type format clear', check=False) |
| 41 | self.runCmd('type summary clear', check=False) |
| 42 | self.runCmd('type synth clear', check=False) |
| 43 | |
| 44 | # Execute the cleanup function during test case tear down. |
| 45 | self.addTearDownHook(cleanup) |
| 46 | |
| 47 | # Now check that we are displaying Cocoa classes correctly |
| 48 | self.expect('frame variable arr', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 49 | substrs = ['@"6 elements"']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 50 | self.expect('frame variable other_arr', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 51 | substrs = ['@"4 elements"']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 52 | self.expect('frame variable arr --ptr-depth 1', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 53 | substrs = ['@"6 elements"','[0] = 0x','[1] = 0x','[2] = 0x','[3] = 0x','[4] = 0x','[5] = 0x']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 54 | self.expect('frame variable other_arr --ptr-depth 1', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 55 | substrs = ['@"4 elements"','[0] = 0x','[1] = 0x','[2] = 0x','[3] = 0x']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 56 | self.expect('frame variable arr --ptr-depth 1 -d no-run-target', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 57 | substrs = ['@"6 elements"','@"hello"','@"world"','@"this"','@"is"','@"me"','@"http://www.apple.com']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 58 | self.expect('frame variable other_arr --ptr-depth 1 -d no-run-target', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 59 | substrs = ['@"4 elements"','(int)5','@"a string"','@"6 elements"']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 60 | self.expect('frame variable other_arr --ptr-depth 2 -d no-run-target', |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 61 | substrs = ['@"4 elements"','@"6 elements" {','@"hello"','@"world"','@"this"','@"is"','@"me"','@"http://www.apple.com']) |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 62 | |
Enrico Granata | 4481816 | 2012-10-24 01:23:57 +0000 | [diff] [blame] | 63 | self.assertTrue(self.frame().FindVariable("arr").MightHaveChildren(), "arr says it does not have children!") |
| 64 | self.assertTrue(self.frame().FindVariable("other_arr").MightHaveChildren(), "arr says it does not have children!") |
| 65 | |
Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 66 | |
| 67 | if __name__ == '__main__': |
| 68 | import atexit |
| 69 | lldb.SBDebugger.Initialize() |
| 70 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 71 | unittest2.main() |