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    def setUp(self):
11        TestBase.setUp(self)
12        self.source = 'main.c'
13
14    @no_debug_info_test  # Prevent the genaration of the dwarf version of this test
15    @skipUnlessPlatform(['linux'])
16    def test_target_symbols_add(self):
17        """Test that 'target symbols add' can load the symbols
18        even if gnu.build-id and gnu_debuglink are not present in the module.
19        Similar to test_add_dsym_mid_execution test for macos."""
20        self.build()
21        exe = self.getBuildArtifact("stripped.out")
22
23        self.target = self.dbg.CreateTarget(exe)
24        self.assertTrue(self.target, VALID_TARGET)
25
26        main_bp = self.target.BreakpointCreateByName("main", "stripped.out")
27        self.assertTrue(main_bp, VALID_BREAKPOINT)
28
29        self.process = self.target.LaunchSimple(
30            None, None, self.get_process_working_directory())
31        self.assertTrue(self.process, PROCESS_IS_VALID)
32
33        # The stop reason of the thread should be breakpoint.
34        self.assertState(self.process.GetState(), lldb.eStateStopped,
35                         STOPPED_DUE_TO_BREAKPOINT)
36
37        exe_module = self.target.GetModuleAtIndex(0)
38
39        # Check that symbols are not loaded and main.c is not know to be
40        # the source file.
41        self.expect("frame select", substrs=['main.c'], matching=False)
42
43        # Tell LLDB that a.out has symbols for stripped.out
44        self.runCmd("target symbols add -s %s %s" %
45                    (exe, self.getBuildArtifact("a.out")))
46
47        # Check that symbols are now loaded and main.c is in the output.
48        self.expect("frame select", substrs=['main.c'])
49