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 def setUp(self): 15 # Call super's setUp(). 16 TestBase.setUp(self) 17 # Find the line number to break at. 18 self.line = line_number('main.cpp', '// Set break point at this line.') 19 20 # rdar://problem/14035604 21 def test_with_run_command(self): 22 """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" 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 self.runCmd("run", RUN_SUCCEEDED) 30 31 # The stop reason of the thread should be breakpoint. 32 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 33 substrs=['stopped', 34 'stop reason = breakpoint']) 35 36 # This is the function to remove the custom formats in order to have a 37 # clean slate for the next test case. 38 def cleanup(): 39 pass 40 41 # Execute the cleanup function during test case tear down. 42 self.addTearDownHook(cleanup) 43 44 # extract the parent and the children 45 frame = self.frame() 46 parent = self.frame().FindVariable("f") 47 self.assertTrue( 48 parent is not None and parent.IsValid(), 49 "could not find f") 50 X = parent.GetChildMemberWithName("X") 51 self.assertTrue(X is not None and X.IsValid(), "could not find X") 52 Y = parent.GetChildMemberWithName("Y") 53 self.assertTrue(Y is not None and Y.IsValid(), "could not find Y") 54 # check their values now 55 self.assertEquals(X.GetValue(), "1", "X has an invalid value") 56 self.assertEquals(Y.GetValue(), "2", "Y has an invalid value") 57 # set the format on the parent 58 parent.SetFormat(lldb.eFormatHex) 59 self.assertEqual( 60 X.GetValue(), "0x00000001", 61 "X has not changed format") 62 self.assertEqual( 63 Y.GetValue(), "0x00000002", 64 "Y has not changed format") 65 # Step and check if the values make sense still 66 self.runCmd("next") 67 self.assertEquals(X.GetValue(), "0x00000004", "X has not become 4") 68 self.assertEquals(Y.GetValue(), "0x00000002", "Y has not stuck as hex") 69 # Check that children can still make their own choices 70 Y.SetFormat(lldb.eFormatDecimal) 71 self.assertEquals(X.GetValue(), "0x00000004", "X is still hex") 72 self.assertEquals(Y.GetValue(), "2", "Y has not been reset") 73 # Make a few more changes 74 parent.SetFormat(lldb.eFormatDefault) 75 X.SetFormat(lldb.eFormatHex) 76 Y.SetFormat(lldb.eFormatDefault) 77 self.assertEqual( 78 X.GetValue(), "0x00000004", 79 "X is not hex as it asked") 80 self.assertEquals(Y.GetValue(), "2", "Y is not defaulted") 81