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 PrintObjectArrayTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 @skipUnlessDarwin 18 def test_print_array(self): 19 """Test that expr -O -Z works""" 20 self.build() 21 self.printarray_data_formatter_commands() 22 23 @skipUnlessDarwin 24 def test_print_array_no_const(self): 25 """Test that expr -O -Z works""" 26 disable_constant_classes = { 27 'CC': 28 'xcrun clang', # FIXME: Remove when flags are available upstream. 29 'CFLAGS_EXTRAS': 30 '-fno-constant-nsnumber-literals ' + 31 '-fno-constant-nsarray-literals ' + 32 '-fno-constant-nsdictionary-literals' 33 } 34 self.build(dictionary=disable_constant_classes) 35 self.printarray_data_formatter_commands() 36 37 def setUp(self): 38 # Call super's setUp(). 39 TestBase.setUp(self) 40 # Find the line number to break at. 41 self.line = line_number('main.mm', 'break here') 42 43 def printarray_data_formatter_commands(self): 44 """Test that expr -O -Z works""" 45 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 46 47 lldbutil.run_break_set_by_file_and_line( 48 self, "main.mm", self.line, num_expected_locations=1, loc_exact=True) 49 50 self.runCmd("run", RUN_SUCCEEDED) 51 52 # The stop reason of the thread should be breakpoint. 53 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 54 substrs=['stopped', 55 'stop reason = breakpoint']) 56 57 # This is the function to remove the custom formats in order to have a 58 # clean slate for the next test case. 59 def cleanup(): 60 self.runCmd('type format clear', check=False) 61 self.runCmd('type summary clear', check=False) 62 self.runCmd('type synth clear', check=False) 63 64 # Execute the cleanup function during test case tear down. 65 self.addTearDownHook(cleanup) 66 67 self.expect( 68 'expr --element-count 3 --object-description -- objects', 69 substrs=[ 70 '3735928559', 71 '4276993775', 72 '3203398366', 73 'Hello', 74 'World', 75 'Two =', 76 '1 =']) 77 self.expect( 78 'poarray 3 objects', 79 substrs=[ 80 '3735928559', 81 '4276993775', 82 '3203398366', 83 'Hello', 84 'World', 85 'Two =', 86 '1 =']) 87 self.expect( 88 'expr --element-count 3 --object-description --description-verbosity=full -- objects', 89 substrs=[ 90 '[0] =', 91 '3735928559', 92 '4276993775', 93 '3203398366', 94 '[1] =', 95 'Hello', 96 'World', 97 '[2] =', 98 'Two =', 99 '1 =']) 100 self.expect( 101 'parray 3 objects', 102 substrs=[ 103 '[0] = 0x', 104 '[1] = 0x', 105 '[2] = 0x']) 106 self.expect( 107 'expr --element-count 3 -d run -- objects', 108 substrs=[ 109 '3 elements', 110 '2 elements', 111 '2 key/value pairs']) 112 self.expect( 113 'expr --element-count 3 -d run --ptr-depth=1 -- objects', 114 substrs=[ 115 '3 elements', 116 '3735928559', 117 '4276993775', 118 '3203398366', 119 '2 elements', 120 '"Hello"', 121 '"World"', 122 '2 key/value pairs', 123 ]) 124