xref: /llvm-project/lldb/test/API/lang/c/forward/TestForwardDeclaration.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""Test that forward declaration of a data structure gets resolved correctly."""
2
3
4import lldb
5from lldbsuite.test.lldbtest import *
6from lldbsuite.test.decorators import *
7import lldbsuite.test.lldbutil as lldbutil
8
9
10class ForwardDeclarationTestCase(TestBase):
11    def do_test(self, dictionary=None):
12        """Display *bar_ptr when stopped on a function with forward declaration of struct bar."""
13        self.build(dictionary=dictionary)
14        exe = self.getBuildArtifact("a.out")
15        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
16
17        # Break inside the foo function which takes a bar_ptr argument.
18        lldbutil.run_break_set_by_symbol(
19            self, "foo", num_expected_locations=1, sym_exact=True
20        )
21
22        self.runCmd("run", RUN_SUCCEEDED)
23
24        # The stop reason of the thread should be breakpoint.
25        self.expect(
26            "thread list",
27            STOPPED_DUE_TO_BREAKPOINT,
28            substrs=["stopped", "stop reason = breakpoint"],
29        )
30
31        # The breakpoint should have a hit count of 1.
32        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
33
34        # This should display correctly.
35        # Note that the member fields of a = 1 and b = 2 is by design.
36        self.expect(
37            "frame variable --show-types *bar_ptr",
38            VARIABLES_DISPLAYED_CORRECTLY,
39            substrs=["(bar) *bar_ptr = ", "(int) a = 1", "(int) b = 2"],
40        )
41
42        # And so should this.
43        self.expect(
44            "expression --show-types -- *bar_ptr",
45            VARIABLES_DISPLAYED_CORRECTLY,
46            substrs=["(bar)", "(int) a = 1", "(int) b = 2"],
47        )
48
49    def test(self):
50        self.do_test()
51
52    @no_debug_info_test
53    @skipIfDarwin
54    @skipIf(compiler=no_match("clang"))
55    @skipIf(compiler_version=["<", "8.0"])
56    @expectedFailureAll(oslist=["windows"])
57    def test_debug_names(self):
58        """Test that we are able to find complete types when using DWARF v5
59        accelerator tables"""
60        self.do_test(dict(CFLAGS_EXTRAS="-gdwarf-5 -gpubnames"))
61