1""" 2Test lldb data formatter subsystem. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class NSArraySyntheticTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 def setUp(self): 18 # Call super's setUp(). 19 TestBase.setUp(self) 20 # Find the line number to break at. 21 self.line = line_number('main.m', '// Set break point at this line.') 22 23 @skipUnlessDarwin 24 def test_rdar11086338_with_run_command(self): 25 """Test that NSArray reports its synthetic children properly.""" 26 self.build() 27 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 28 29 lldbutil.run_break_set_by_file_and_line( 30 self, "main.m", self.line, num_expected_locations=1, loc_exact=True) 31 32 self.runCmd("run", RUN_SUCCEEDED) 33 34 # The stop reason of the thread should be breakpoint. 35 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 36 substrs=['stopped', 37 'stop reason = breakpoint']) 38 39 # This is the function to remove the custom formats in order to have a 40 # clean slate for the next test case. 41 def cleanup(): 42 self.runCmd('type format clear', check=False) 43 self.runCmd('type summary clear', check=False) 44 self.runCmd('type synth clear', check=False) 45 46 # Execute the cleanup function during test case tear down. 47 self.addTearDownHook(cleanup) 48 49 # Now check that we are displaying Cocoa classes correctly 50 self.expect('frame variable arr', 51 substrs=['@"6 elements"']) 52 self.expect('frame variable other_arr', 53 substrs=['@"4 elements"']) 54 self.expect('frame variable empty_arr', 55 substrs=['@"0 elements"']) 56 self.expect( 57 'frame variable arr --ptr-depth 1', 58 substrs=[ 59 '@"6 elements"', 60 '[0] = 0x', 61 '[1] = 0x', 62 '[2] = 0x', 63 '[3] = 0x', 64 '[4] = 0x', 65 '[5] = 0x']) 66 self.expect( 67 'frame variable other_arr --ptr-depth 1', 68 substrs=[ 69 '@"4 elements"', 70 '[0] = 0x', 71 '[1] = 0x', 72 '[2] = 0x', 73 '[3] = 0x']) 74 self.expect( 75 'frame variable empty_arr --ptr-depth 1', 76 substrs=[ 77 '@"0 elements"']) 78 self.expect( 79 'frame variable arr --ptr-depth 1 -d no-run-target', 80 substrs=[ 81 '@"6 elements"', 82 '@"hello"', 83 '@"world"', 84 '@"this"', 85 '@"is"', 86 '@"me"', 87 '@"http://www.apple.com']) 88 self.expect( 89 'frame variable other_arr --ptr-depth 1 -d no-run-target', 90 substrs=[ 91 '@"4 elements"', 92 '(int)5', 93 '@"a string"', 94 '@"6 elements"']) 95 self.expect( 96 'frame variable other_arr --ptr-depth 2 -d no-run-target', 97 substrs=[ 98 '@"4 elements"', 99 '@"6 elements" {', 100 '@"hello"', 101 '@"world"', 102 '@"this"', 103 '@"is"', 104 '@"me"', 105 '@"http://www.apple.com']) 106 107 self.assertTrue( 108 self.frame().FindVariable("arr").MightHaveChildren(), 109 "arr says it does not have children!") 110 self.assertTrue( 111 self.frame().FindVariable("other_arr").MightHaveChildren(), 112 "arr says it does not have children!") 113 self.assertFalse( 114 self.frame().FindVariable("empty_arr").MightHaveChildren(), 115 "arr says it does have children!") 116