xref: /llvm-project/lldb/test/API/lang/objc/forward-decl/TestForwardDecl.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""Test that a forward-declared class works when its complete definition is in a library"""
2
3
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class ForwardDeclTestCase(TestBase):
11    def setUp(self):
12        # Call super's setUp().
13        TestBase.setUp(self)
14        # Find the line number to break inside main().
15        self.source = "main.m"
16        self.line = line_number(self.source, "// Set breakpoint 0 here.")
17        self.shlib_names = ["Container"]
18
19    def do_test(self, dictionary=None):
20        self.build(dictionary=dictionary)
21
22        # Create a target by the debugger.
23        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
24        self.assertTrue(target, VALID_TARGET)
25
26        # Create the breakpoint inside function 'main'.
27        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
28        self.assertTrue(breakpoint, VALID_BREAKPOINT)
29
30        # Register our shared libraries for remote targets so they get
31        # automatically uploaded
32        environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names)
33
34        # Now launch the process, and do not stop at entry point.
35        process = target.LaunchSimple(
36            None, environment, self.get_process_working_directory()
37        )
38        self.assertTrue(process, PROCESS_IS_VALID)
39
40        # The stop reason of the thread should be breakpoint.
41        self.expect(
42            "thread list",
43            STOPPED_DUE_TO_BREAKPOINT,
44            substrs=["stopped", "stop reason = breakpoint"],
45        )
46
47        # The breakpoint should have a hit count of 1.
48        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
49
50        # This should display correctly.
51        self.expect(
52            "expression [j getMember]", VARIABLES_DISPLAYED_CORRECTLY, substrs=["= 0x"]
53        )
54
55    def test_expr(self):
56        self.do_test()
57
58    @no_debug_info_test
59    @skipIf(compiler=no_match("clang"))
60    @skipIf(compiler_version=["<", "7.0"])
61    def test_debug_names(self):
62        """Test that we are able to find complete types when using DWARF v5
63        accelerator tables"""
64        self.do_test(dict(CFLAGS_EXTRAS="-dwarf-version=5 -mllvm -accel-tables=Dwarf"))
65