xref: /llvm-project/lldb/test/API/lang/cpp/forward/TestCPPForwardDeclaration.py (revision 10b048c8922d746b14e991f468e00b3ca67c9d95)
1"""Test that forward declaration of a c++ template gets resolved correctly."""
2
3import lldb
4from lldbsuite.test.lldbtest import *
5from lldbsuite.test.decorators import *
6import lldbsuite.test.lldbutil as lldbutil
7
8
9class ForwardDeclarationTestCase(TestBase):
10    def do_test(self, dictionary=None):
11        """Display *bar_ptr when stopped on a function with forward declaration of struct bar."""
12        self.build(dictionary=dictionary)
13        exe = self.getBuildArtifact("a.out")
14        target = self.dbg.CreateTarget(exe)
15        self.assertTrue(target, VALID_TARGET)
16
17        environment = self.registerSharedLibrariesWithTarget(target, ["foo"])
18
19        # Break inside the foo function which takes a bar_ptr argument.
20        lldbutil.run_break_set_by_symbol(self, "foo", num_expected_locations=1)
21
22        process = target.LaunchSimple(
23            None, environment, self.get_process_working_directory()
24        )
25        self.assertTrue(process, PROCESS_IS_VALID)
26
27        # The stop reason of the thread should be breakpoint.
28        self.expect(
29            "thread list",
30            STOPPED_DUE_TO_BREAKPOINT,
31            substrs=["stopped", "stop reason = breakpoint"],
32        )
33
34        # The breakpoint should have a hit count of 1.
35        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
36
37        self.expect_expr(
38            "*bar_ptr",
39            result_type="bar<int>",
40            result_children=[ValueCheck(value="47", name="a", type="int")],
41        )
42
43    def test(self):
44        self.do_test()
45
46    @no_debug_info_test
47    @skipIfDarwin
48    @skipIf(compiler=no_match("clang"))
49    @skipIf(compiler_version=["<", "8.0"])
50    @expectedFailureAll(oslist=["windows"])
51    def test_debug_names(self):
52        """Test that we are able to find complete types when using DWARF v5
53        accelerator tables"""
54        self.do_test(dict(CFLAGS_EXTRAS="-gdwarf-5 -gpubnames"))
55
56    @no_debug_info_test
57    @skipIf(compiler=no_match("clang"))
58    def test_simple_template_names(self):
59        """Test that we are able to find complete types when using DWARF v5
60        accelerator tables"""
61        self.do_test(dict(CFLAGS_EXTRAS="-gsimple-template-names"))
62