1"""
2Test that ValueObjectPrinter does not cause an infinite loop when a reference to a struct that contains a pointer to itself is printed.
3"""
4
5
6import lldb
7from lldbsuite.test.lldbtest import *
8import lldbsuite.test.lldbutil as lldbutil
9
10
11class DataFormatterRefPtrRecursionTestCase(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    def test_with_run_command(self):
19        """Test that ValueObjectPrinter does not cause an infinite loop when a reference to a struct that contains a pointer to itself is printed."""
20        self.build()
21        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
22
23        lldbutil.run_break_set_by_file_and_line(
24            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
25        )
26
27        self.runCmd("run", RUN_SUCCEEDED)
28
29        # The stop reason of the thread should be breakpoint.
30        self.expect(
31            "thread list",
32            STOPPED_DUE_TO_BREAKPOINT,
33            substrs=["stopped", "stop reason = breakpoint"],
34        )
35
36        self.expect("frame variable foo", substrs=[])
37        self.expect("frame variable foo --ptr-depth=1", substrs=["ID = 1"])
38        self.expect("frame variable foo --ptr-depth=2", substrs=["ID = 1"])
39        self.expect("frame variable foo --ptr-depth=3", substrs=["ID = 1"])
40