xref: /llvm-project/lldb/test/API/linux/add-symbols/TestTargetSymbolsAddCommand.py (revision ce825e46743be3e402820484bef639d12deefc2a)
1""" Testing explicit symbol loading via target symbols add. """
2import lldb
3from lldbsuite.test.decorators import *
4from lldbsuite.test.lldbtest import *
5from lldbsuite.test import lldbutil
6
7
8class TargetSymbolsAddCommand(TestBase):
9
10    mydir = TestBase.compute_mydir(__file__)
11
12    def setUp(self):
13        TestBase.setUp(self)
14        self.source = 'main.c'
15
16    @no_debug_info_test  # Prevent the genaration of the dwarf version of this test
17    @skipUnlessPlatform(['linux'])
18    def test_target_symbols_add(self):
19        """Test that 'target symbols add' can load the symbols
20        even if gnu.build-id and gnu_debuglink are not present in the module.
21        Similar to test_add_dsym_mid_execution test for macos."""
22        self.build()
23        exe = self.getBuildArtifact("stripped.out")
24
25        self.target = self.dbg.CreateTarget(exe)
26        self.assertTrue(self.target, VALID_TARGET)
27
28        main_bp = self.target.BreakpointCreateByName("main", "stripped.out")
29        self.assertTrue(main_bp, VALID_BREAKPOINT)
30
31        self.process = self.target.LaunchSimple(
32            None, None, self.get_process_working_directory())
33        self.assertTrue(self.process, PROCESS_IS_VALID)
34
35        # The stop reason of the thread should be breakpoint.
36        self.assertState(self.process.GetState(), lldb.eStateStopped,
37                         STOPPED_DUE_TO_BREAKPOINT)
38
39        exe_module = self.target.GetModuleAtIndex(0)
40
41        # Check that symbols are not loaded and main.c is not know to be
42        # the source file.
43        self.expect("frame select", substrs=['main.c'], matching=False)
44
45        # Tell LLDB that a.out has symbols for stripped.out
46        self.runCmd("target symbols add -s %s %s" %
47                    (exe, self.getBuildArtifact("a.out")))
48
49        # Check that symbols are now loaded and main.c is in the output.
50        self.expect("frame select", substrs=['main.c'])
51