199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtCheck for an issue where capping does not work because the Target pointer appears to be changing behind our backs 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprechtimport lldb 799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass SyntheticCappingTestCase(TestBase): 1399451b44SJordan Rupprecht def setUp(self): 1499451b44SJordan Rupprecht # Call super's setUp(). 1599451b44SJordan Rupprecht TestBase.setUp(self) 1699451b44SJordan Rupprecht # Find the line number to break at. 172238dcc3SJonas Devlieghere self.line = line_number("main.cpp", "// Set break point at this line.") 1899451b44SJordan Rupprecht 1999451b44SJordan Rupprecht def test_with_run_command(self): 2099451b44SJordan Rupprecht """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" 2199451b44SJordan Rupprecht self.build() 2299451b44SJordan Rupprecht self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 2399451b44SJordan Rupprecht 2499451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 252238dcc3SJonas Devlieghere self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True 262238dcc3SJonas Devlieghere ) 2799451b44SJordan Rupprecht 2899451b44SJordan Rupprecht self.runCmd("run", RUN_SUCCEEDED) 2999451b44SJordan Rupprecht 3099451b44SJordan Rupprecht process = self.dbg.GetSelectedTarget().GetProcess() 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht # The stop reason of the thread should be breakpoint. 332238dcc3SJonas Devlieghere self.expect( 342238dcc3SJonas Devlieghere "thread list", 352238dcc3SJonas Devlieghere STOPPED_DUE_TO_BREAKPOINT, 362238dcc3SJonas Devlieghere substrs=["stopped", "stop reason = breakpoint"], 372238dcc3SJonas Devlieghere ) 3899451b44SJordan Rupprecht 3999451b44SJordan Rupprecht # This is the function to remove the custom formats in order to have a 4099451b44SJordan Rupprecht # clean slate for the next test case. 4199451b44SJordan Rupprecht def cleanup(): 422238dcc3SJonas Devlieghere self.runCmd("type format clear", check=False) 432238dcc3SJonas Devlieghere self.runCmd("type summary clear", check=False) 442238dcc3SJonas Devlieghere self.runCmd("type filter clear", check=False) 452238dcc3SJonas Devlieghere self.runCmd("type synth clear", check=False) 462238dcc3SJonas Devlieghere self.runCmd("settings set target.max-children-count 256", check=False) 4799451b44SJordan Rupprecht 4899451b44SJordan Rupprecht # Execute the cleanup function during test case tear down. 4999451b44SJordan Rupprecht self.addTearDownHook(cleanup) 5099451b44SJordan Rupprecht 5199451b44SJordan Rupprecht # set up the synthetic children provider 5299451b44SJordan Rupprecht self.runCmd("script from fooSynthProvider import *") 5399451b44SJordan Rupprecht self.runCmd("type synth add -l fooSynthProvider foo") 5499451b44SJordan Rupprecht 5599451b44SJordan Rupprecht # note that the value of fake_a depends on target byte order 5699451b44SJordan Rupprecht if process.GetByteOrder() == lldb.eByteOrderLittle: 5799451b44SJordan Rupprecht fake_a_val = 0x02000000 5899451b44SJordan Rupprecht else: 5999451b44SJordan Rupprecht fake_a_val = 0x00000100 6099451b44SJordan Rupprecht 6199451b44SJordan Rupprecht # check that the synthetic children work, so we know we are doing the 6299451b44SJordan Rupprecht # right thing 6399451b44SJordan Rupprecht self.expect( 6499451b44SJordan Rupprecht "frame variable f00_1", 6599451b44SJordan Rupprecht substrs=[ 662238dcc3SJonas Devlieghere "a = 1", 672238dcc3SJonas Devlieghere "fake_a = %d" % fake_a_val, 682238dcc3SJonas Devlieghere "r = 34", 692238dcc3SJonas Devlieghere ], 702238dcc3SJonas Devlieghere ) 71*763b96c8SPavel Labath # num_children() should be called with at most max_num_children=257 72*763b96c8SPavel Labath # (target.max-children-count + 1) 73*763b96c8SPavel Labath self.expect( 74*763b96c8SPavel Labath "script fooSynthProvider.reset_max_num_children_max()", substrs=["257"] 75*763b96c8SPavel Labath ) 7699451b44SJordan Rupprecht 7799451b44SJordan Rupprecht # check that capping works 7899451b44SJordan Rupprecht self.runCmd("settings set target.max-children-count 2", check=False) 7999451b44SJordan Rupprecht 802238dcc3SJonas Devlieghere self.expect( 812238dcc3SJonas Devlieghere "frame variable f00_1", 8299451b44SJordan Rupprecht substrs=[ 832238dcc3SJonas Devlieghere "a = 1", 842238dcc3SJonas Devlieghere "fake_a = %d" % fake_a_val, 852238dcc3SJonas Devlieghere "...", 862238dcc3SJonas Devlieghere ], 872238dcc3SJonas Devlieghere ) 88*763b96c8SPavel Labath self.expect( 89*763b96c8SPavel Labath "script fooSynthProvider.reset_max_num_children_max()", substrs=["3"] 90*763b96c8SPavel Labath ) 9199451b44SJordan Rupprecht 922238dcc3SJonas Devlieghere self.expect("frame variable f00_1", matching=False, substrs=["r = 34"]) 9399451b44SJordan Rupprecht 9499451b44SJordan Rupprecht self.runCmd("settings set target.max-children-count 256", check=False) 9599451b44SJordan Rupprecht 962238dcc3SJonas Devlieghere self.expect("frame variable f00_1", matching=True, substrs=["r = 34"]) 97*763b96c8SPavel Labath self.expect( 98*763b96c8SPavel Labath "script fooSynthProvider.reset_max_num_children_max()", substrs=["257"] 99*763b96c8SPavel Labath ) 100