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