xref: /llvm-project/lldb/test/API/lang/c/conflicting-symbol/TestConflictingSymbol.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""Test that conflicting symbols in different shared libraries work correctly"""
2
3
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestConflictingSymbols(TestBase):
11    NO_DEBUG_INFO_TESTCASE = True
12
13    def setUp(self):
14        TestBase.setUp(self)
15        lldbutil.mkdir_p(self.getBuildArtifact("One"))
16        lldbutil.mkdir_p(self.getBuildArtifact("Two"))
17
18    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489")
19    def test_conflicting_symbols(self):
20        self.build()
21        exe = self.getBuildArtifact("a.out")
22        target = self.dbg.CreateTarget(exe)
23        self.assertTrue(target, VALID_TARGET)
24
25        # Register our shared libraries for remote targets so they get
26        # automatically uploaded
27        environment = self.registerSharedLibrariesWithTarget(target, ["One", "Two"])
28
29        lldbutil.run_break_set_by_source_regexp(
30            self, "// break here", extra_options="-f One.c", num_expected_locations=-2
31        )
32        lldbutil.run_break_set_by_source_regexp(
33            self, "// break here", extra_options="-f Two.c", num_expected_locations=-2
34        )
35        lldbutil.run_break_set_by_source_regexp(
36            self, "// break here", extra_options="-f main.c", num_expected_locations=1
37        )
38
39        process = target.LaunchSimple(
40            None, environment, self.get_process_working_directory()
41        )
42        self.assertTrue(process, PROCESS_IS_VALID)
43
44        # The stop reason of the thread should be breakpoint.
45        self.expect(
46            "thread list",
47            STOPPED_DUE_TO_BREAKPOINT,
48            substrs=["stopped", "stop reason = breakpoint"],
49        )
50
51        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
52
53        # This should display correctly.
54        self.expect(
55            "expr (unsigned long long)conflicting_symbol",
56            "Symbol from One should be found",
57            substrs=["11111"],
58        )
59
60        self.runCmd("continue", RUN_SUCCEEDED)
61
62        # The stop reason of the thread should be breakpoint.
63        self.expect(
64            "thread list",
65            STOPPED_DUE_TO_BREAKPOINT,
66            substrs=["stopped", "stop reason = breakpoint"],
67        )
68
69        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
70
71        self.expect(
72            "expr (unsigned long long)conflicting_symbol",
73            "Symbol from Two should be found",
74            substrs=["22222"],
75        )
76
77        self.runCmd("continue", RUN_SUCCEEDED)
78
79        # The stop reason of the thread should be breakpoint.
80        self.expect(
81            "thread list",
82            STOPPED_DUE_TO_BREAKPOINT,
83            substrs=["stopped", "stop reason = breakpoint"],
84        )
85
86        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
87
88        self.expect(
89            "expr (unsigned long long)conflicting_symbol",
90            "An error should be printed when symbols can't be ordered",
91            error=True,
92            substrs=["Multiple internal symbols"],
93        )
94
95    @expectedFailureAll(bugnumber="llvm.org/pr35043")
96    @skipIfWindows  # This test is "passing" on Windows, but it is a false positive.
97    def test_shadowed(self):
98        self.build()
99        exe = self.getBuildArtifact("a.out")
100        target = self.dbg.CreateTarget(exe)
101        self.assertTrue(target, VALID_TARGET)
102
103        # Register our shared libraries for remote targets so they get
104        # automatically uploaded
105        environment = self.registerSharedLibrariesWithTarget(target, ["One", "Two"])
106
107        lldbutil.run_break_set_by_source_regexp(
108            self, "// break here", extra_options="-f main.c", num_expected_locations=1
109        )
110
111        process = target.LaunchSimple(
112            None, environment, self.get_process_working_directory()
113        )
114        self.assertTrue(process, PROCESS_IS_VALID)
115
116        # The stop reason of the thread should be breakpoint.
117        self.expect(
118            "thread list",
119            STOPPED_DUE_TO_BREAKPOINT,
120            substrs=["stopped", "stop reason = breakpoint"],
121        )
122
123        # As we are shadowing the conflicting symbol, there should be no
124        # ambiguity in this expression.
125        self.expect(
126            "expr int conflicting_symbol = 474747; conflicting_symbol",
127            substrs=["474747"],
128        )
129