199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtCheck if changing Format on an SBValue correctly propagates that new format to children as it should 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass FormatPropagationTestCase(TestBase): 1399451b44SJordan Rupprecht 1499451b44SJordan Rupprecht def setUp(self): 1599451b44SJordan Rupprecht # Call super's setUp(). 1699451b44SJordan Rupprecht TestBase.setUp(self) 1799451b44SJordan Rupprecht # Find the line number to break at. 1899451b44SJordan Rupprecht self.line = line_number('main.cpp', '// Set break point at this line.') 1999451b44SJordan Rupprecht 2099451b44SJordan Rupprecht # rdar://problem/14035604 2199451b44SJordan Rupprecht def test_with_run_command(self): 2299451b44SJordan Rupprecht """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" 2399451b44SJordan Rupprecht self.build() 2499451b44SJordan Rupprecht self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 2599451b44SJordan Rupprecht 2699451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 2799451b44SJordan Rupprecht self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 2899451b44SJordan Rupprecht 2999451b44SJordan Rupprecht self.runCmd("run", RUN_SUCCEEDED) 3099451b44SJordan Rupprecht 3199451b44SJordan Rupprecht # The stop reason of the thread should be breakpoint. 3299451b44SJordan Rupprecht self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 3399451b44SJordan Rupprecht substrs=['stopped', 3499451b44SJordan Rupprecht 'stop reason = breakpoint']) 3599451b44SJordan Rupprecht 3699451b44SJordan Rupprecht # This is the function to remove the custom formats in order to have a 3799451b44SJordan Rupprecht # clean slate for the next test case. 3899451b44SJordan Rupprecht def cleanup(): 3999451b44SJordan Rupprecht pass 4099451b44SJordan Rupprecht 4199451b44SJordan Rupprecht # Execute the cleanup function during test case tear down. 4299451b44SJordan Rupprecht self.addTearDownHook(cleanup) 4399451b44SJordan Rupprecht 4499451b44SJordan Rupprecht # extract the parent and the children 4599451b44SJordan Rupprecht frame = self.frame() 4699451b44SJordan Rupprecht parent = self.frame().FindVariable("f") 4799451b44SJordan Rupprecht self.assertTrue( 4899451b44SJordan Rupprecht parent is not None and parent.IsValid(), 4999451b44SJordan Rupprecht "could not find f") 5099451b44SJordan Rupprecht X = parent.GetChildMemberWithName("X") 5199451b44SJordan Rupprecht self.assertTrue(X is not None and X.IsValid(), "could not find X") 5299451b44SJordan Rupprecht Y = parent.GetChildMemberWithName("Y") 5399451b44SJordan Rupprecht self.assertTrue(Y is not None and Y.IsValid(), "could not find Y") 5499451b44SJordan Rupprecht # check their values now 55b3a0c4d7SRaphael Isemann self.assertEquals(X.GetValue(), "1", "X has an invalid value") 56b3a0c4d7SRaphael Isemann self.assertEquals(Y.GetValue(), "2", "Y has an invalid value") 5799451b44SJordan Rupprecht # set the format on the parent 5899451b44SJordan Rupprecht parent.SetFormat(lldb.eFormatHex) 59*0ed758b2SDave Lee self.assertEqual( 60*0ed758b2SDave Lee X.GetValue(), "0x00000001", 6199451b44SJordan Rupprecht "X has not changed format") 62*0ed758b2SDave Lee self.assertEqual( 63*0ed758b2SDave Lee Y.GetValue(), "0x00000002", 6499451b44SJordan Rupprecht "Y has not changed format") 6599451b44SJordan Rupprecht # Step and check if the values make sense still 6699451b44SJordan Rupprecht self.runCmd("next") 67b3a0c4d7SRaphael Isemann self.assertEquals(X.GetValue(), "0x00000004", "X has not become 4") 68b3a0c4d7SRaphael Isemann self.assertEquals(Y.GetValue(), "0x00000002", "Y has not stuck as hex") 6999451b44SJordan Rupprecht # Check that children can still make their own choices 7099451b44SJordan Rupprecht Y.SetFormat(lldb.eFormatDecimal) 71b3a0c4d7SRaphael Isemann self.assertEquals(X.GetValue(), "0x00000004", "X is still hex") 72b3a0c4d7SRaphael Isemann self.assertEquals(Y.GetValue(), "2", "Y has not been reset") 7399451b44SJordan Rupprecht # Make a few more changes 7499451b44SJordan Rupprecht parent.SetFormat(lldb.eFormatDefault) 7599451b44SJordan Rupprecht X.SetFormat(lldb.eFormatHex) 7699451b44SJordan Rupprecht Y.SetFormat(lldb.eFormatDefault) 77*0ed758b2SDave Lee self.assertEqual( 78*0ed758b2SDave Lee X.GetValue(), "0x00000004", 7999451b44SJordan Rupprecht "X is not hex as it asked") 80b3a0c4d7SRaphael Isemann self.assertEquals(Y.GetValue(), "2", "Y is not defaulted") 81