1""" 2Check if changing Format on an SBValue correctly propagates that new format to children as it should 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class FormatPropagationTestCase(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 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.cpp', '// Set break point at this line.') 21 22 # rdar://problem/14035604 23 def test_with_run_command(self): 24 """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" 25 self.build() 26 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 27 28 lldbutil.run_break_set_by_file_and_line( 29 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 30 31 self.runCmd("run", RUN_SUCCEEDED) 32 33 # The stop reason of the thread should be breakpoint. 34 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 35 substrs=['stopped', 36 'stop reason = breakpoint']) 37 38 # This is the function to remove the custom formats in order to have a 39 # clean slate for the next test case. 40 def cleanup(): 41 pass 42 43 # Execute the cleanup function during test case tear down. 44 self.addTearDownHook(cleanup) 45 46 # extract the parent and the children 47 frame = self.frame() 48 parent = self.frame().FindVariable("f") 49 self.assertTrue( 50 parent is not None and parent.IsValid(), 51 "could not find f") 52 X = parent.GetChildMemberWithName("X") 53 self.assertTrue(X is not None and X.IsValid(), "could not find X") 54 Y = parent.GetChildMemberWithName("Y") 55 self.assertTrue(Y is not None and Y.IsValid(), "could not find Y") 56 # check their values now 57 self.assertEquals(X.GetValue(), "1", "X has an invalid value") 58 self.assertEquals(Y.GetValue(), "2", "Y has an invalid value") 59 # set the format on the parent 60 parent.SetFormat(lldb.eFormatHex) 61 self.assertTrue( 62 X.GetValue() == "0x00000001", 63 "X has not changed format") 64 self.assertTrue( 65 Y.GetValue() == "0x00000002", 66 "Y has not changed format") 67 # Step and check if the values make sense still 68 self.runCmd("next") 69 self.assertEquals(X.GetValue(), "0x00000004", "X has not become 4") 70 self.assertEquals(Y.GetValue(), "0x00000002", "Y has not stuck as hex") 71 # Check that children can still make their own choices 72 Y.SetFormat(lldb.eFormatDecimal) 73 self.assertEquals(X.GetValue(), "0x00000004", "X is still hex") 74 self.assertEquals(Y.GetValue(), "2", "Y has not been reset") 75 # Make a few more changes 76 parent.SetFormat(lldb.eFormatDefault) 77 X.SetFormat(lldb.eFormatHex) 78 Y.SetFormat(lldb.eFormatDefault) 79 self.assertTrue( 80 X.GetValue() == "0x00000004", 81 "X is not hex as it asked") 82 self.assertEquals(Y.GetValue(), "2", "Y is not defaulted") 83