1""" 2Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs 3""" 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class SyntheticCappingTestCase(TestBase): 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 # Find the line number to break at. 17 self.line = line_number("main.cpp", "// Set break point at this line.") 18 19 def test_with_run_command(self): 20 """Check for an issue where capping does not work because the Target pointer appears to be changing behind our backs.""" 21 self.build() 22 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) 23 24 lldbutil.run_break_set_by_file_and_line( 25 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True 26 ) 27 28 self.runCmd("run", RUN_SUCCEEDED) 29 30 process = self.dbg.GetSelectedTarget().GetProcess() 31 32 # The stop reason of the thread should be breakpoint. 33 self.expect( 34 "thread list", 35 STOPPED_DUE_TO_BREAKPOINT, 36 substrs=["stopped", "stop reason = breakpoint"], 37 ) 38 39 # This is the function to remove the custom formats in order to have a 40 # clean slate for the next test case. 41 def cleanup(): 42 self.runCmd("type format clear", check=False) 43 self.runCmd("type summary clear", check=False) 44 self.runCmd("type filter clear", check=False) 45 self.runCmd("type synth clear", check=False) 46 self.runCmd("settings set target.max-children-count 256", check=False) 47 48 # Execute the cleanup function during test case tear down. 49 self.addTearDownHook(cleanup) 50 51 # set up the synthetic children provider 52 self.runCmd("script from fooSynthProvider import *") 53 self.runCmd("type synth add -l fooSynthProvider foo") 54 55 # note that the value of fake_a depends on target byte order 56 if process.GetByteOrder() == lldb.eByteOrderLittle: 57 fake_a_val = 0x02000000 58 else: 59 fake_a_val = 0x00000100 60 61 # check that the synthetic children work, so we know we are doing the 62 # right thing 63 self.expect( 64 "frame variable f00_1", 65 substrs=[ 66 "a = 1", 67 "fake_a = %d" % fake_a_val, 68 "r = 34", 69 ], 70 ) 71 # num_children() should be called with at most max_num_children=257 72 # (target.max-children-count + 1) 73 self.expect( 74 "script fooSynthProvider.reset_max_num_children_max()", substrs=["257"] 75 ) 76 77 # check that capping works 78 self.runCmd("settings set target.max-children-count 2", check=False) 79 80 self.expect( 81 "frame variable f00_1", 82 substrs=[ 83 "a = 1", 84 "fake_a = %d" % fake_a_val, 85 "...", 86 ], 87 ) 88 self.expect( 89 "script fooSynthProvider.reset_max_num_children_max()", substrs=["3"] 90 ) 91 92 self.expect("frame variable f00_1", matching=False, substrs=["r = 34"]) 93 94 self.runCmd("settings set target.max-children-count 256", check=False) 95 96 self.expect("frame variable f00_1", matching=True, substrs=["r = 34"]) 97 self.expect( 98 "script fooSynthProvider.reset_max_num_children_max()", substrs=["257"] 99 ) 100