1""" 2Test lldb data formatter subsystem. 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test.decorators import * 10import lldbsuite.test.lldbutil as lldbutil 11 12 13class GlobalsDataFormatterTestCase(TestBase): 14 15 def setUp(self): 16 # Call super's setUp(). 17 TestBase.setUp(self) 18 # Find the line number to break at. 19 self.line = line_number('main.cpp', '// Set break point at this line.') 20 21 def test_with_run_command(self): 22 """Test that that file and class static variables display correctly.""" 23 self.build() 24 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 25 26 lldbutil.run_break_set_by_file_and_line( 27 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 28 29 # This is the function to remove the custom formats in order to have a 30 # clean slate for the next test case. 31 def cleanup(): 32 self.runCmd('type format clear', check=False) 33 self.runCmd('type summary clear', check=False) 34 35 # Execute the cleanup function during test case tear down. 36 self.addTearDownHook(cleanup) 37 38 self.runCmd("type summary add --summary-string \"JustATest\" Point") 39 40 # Simply check we can get at global variables 41 self.expect("target variable g_point", 42 substrs=['JustATest']) 43 44 self.expect("target variable g_point_pointer", 45 substrs=['(Point *) g_point_pointer =']) 46 47 # Print some information about the variables 48 # (we ignore the actual values) 49 self.runCmd( 50 "type summary add --summary-string \"(x=${var.x},y=${var.y})\" Point") 51 52 self.expect("target variable g_point", 53 substrs=['x=', 54 'y=']) 55 56 self.expect("target variable g_point_pointer", 57 substrs=['(Point *) g_point_pointer =']) 58 59 # Test Python code on resulting SBValue 60 self.runCmd( 61 "type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point") 62 63 self.expect("target variable g_point", 64 substrs=['x=']) 65 66 self.expect("target variable g_point_pointer", 67 substrs=['(Point *) g_point_pointer =']) 68