xref: /llvm-project/lldb/test/API/functionalities/source-map/TestTargetSourceMap.py (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1import lldb
2from lldbsuite.test.lldbtest import *
3from lldbsuite.test.decorators import *
4
5
6class TestTargetSourceMap(TestBase):
7
8    mydir = TestBase.compute_mydir(__file__)
9
10    @no_debug_info_test
11    def test_source_map(self):
12        """Test target.source-map' functionality."""
13        # Set the target soure map to map "./" to the current test directory
14        src_dir = self.getSourceDir()
15        src_path = os.path.join(src_dir, "main.c")
16        yaml_path = os.path.join(src_dir, "a.yaml")
17        yaml_base, ext = os.path.splitext(yaml_path)
18        obj_path = self.getBuildArtifact("main.o")
19        self.yaml2obj(yaml_path, obj_path)
20
21        # Create a target with the object file we just created from YAML
22        target = self.dbg.CreateTarget(obj_path)
23
24        # Set a breakpoint before we remap source and verify that it fails
25        bp = target.BreakpointCreateByLocation(src_path, 2)
26        self.assertTrue(bp.GetNumLocations() == 0,
27                        "make sure no breakpoints were resolved without map")
28        src_map_cmd = 'settings set target.source-map . "%s"' % (src_dir)
29        self.dbg.HandleCommand(src_map_cmd)
30
31        # Set a breakpoint after we remap source and verify that it succeeds
32        bp = target.BreakpointCreateByLocation(src_path, 2)
33        self.assertTrue(bp.GetNumLocations() == 1,
34                        "make sure breakpoint was resolved with map")
35
36        # Now make sure that we can actually FIND the source file using this
37        # remapping:
38        retval = lldb.SBCommandReturnObject()
39        self.dbg.GetCommandInterpreter().HandleCommand("source list -f main.c -l 2", retval)
40        self.assertTrue(retval.Succeeded(), "source list didn't succeed.")
41        self.assertTrue(retval.GetOutput() != None, "We got no ouput from source list")
42        self.assertTrue("return" in retval.GetOutput(), "We didn't find the source file...")
43
44