xref: /llvm-project/lldb/test/API/functionalities/recursion/TestValueObjectRecursion.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test lldb data formatter subsystem.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8import lldbsuite.test.lldbutil as lldbutil
9
10
11class ValueObjectRecursionTestCase(TestBase):
12    def setUp(self):
13        # Call super's setUp().
14        TestBase.setUp(self)
15        # Find the line number to break at.
16        self.line = line_number("main.cpp", "// Set break point at this line.")
17
18    @no_debug_info_test
19    def test_with_run_command(self):
20        """Test that deeply nested ValueObjects still work."""
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        # The stop reason of the thread should be breakpoint.
31        self.expect(
32            "thread list",
33            STOPPED_DUE_TO_BREAKPOINT,
34            substrs=["stopped", "stop reason = breakpoint"],
35        )
36
37        # This is the function to remove the custom formats in order to have a
38        # clean slate for the next test case.
39        def cleanup():
40            self.runCmd("type format clear", check=False)
41            self.runCmd("type summary clear", check=False)
42
43        # Execute the cleanup function during test case tear down.
44        self.addTearDownHook(cleanup)
45
46        root = self.frame().FindVariable("root")
47        child = root.GetChildAtIndex(1)
48        if self.TraceOn():
49            print(root)
50            print(child)
51        for i in range(0, 15000):
52            child = child.GetChildAtIndex(1)
53        if self.TraceOn():
54            print(child)
55        self.assertTrue(child.IsValid(), "could not retrieve the deep ValueObject")
56        self.assertTrue(
57            child.GetChildAtIndex(0).IsValid(), "the deep ValueObject has no value"
58        )
59        self.assertNotEqual(
60            child.GetChildAtIndex(0).GetValueAsUnsigned(),
61            0,
62            "the deep ValueObject has a zero value",
63        )
64        self.assertNotEqual(
65            child.GetChildAtIndex(1).GetValueAsUnsigned(),
66            0,
67            "the deep ValueObject has no next",
68        )
69