xref: /llvm-project/lldb/test/API/functionalities/dwo/TestZeroDwoId.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test things related to the fission debug information style where the main object
3file contains a skeleton compile unit and the main debug info is in .dwo files.
4"""
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10import os
11
12
13class ExecTestCase(TestBase):
14    NO_DEBUG_INFO_TESTCASE = True
15
16    def test_zero_dwo_id(self):
17        """
18        Test that we can load a .o file that has a skeleton compile unit
19        with a DWO ID of zero. We do this by hacking up the yaml to emit
20        zero as a DWO ID is both the .o file and .dwo file. Then we make
21        sure we can resolve something in the debug information to verify
22        that we were able to load the .dwo file corrrectly since that is
23        the only place that has this information.
24        """
25        src_dir = self.getSourceDir()
26        dwo_yaml_path = os.path.join(src_dir, "main.dwo.yaml")
27        obj_yaml_path = os.path.join(src_dir, "main.o.yaml")
28        dwo_path = self.getBuildArtifact("main.dwo")
29        obj_path = self.getBuildArtifact("main.o")
30        self.yaml2obj(dwo_yaml_path, dwo_path)
31        self.yaml2obj(obj_yaml_path, obj_path)
32
33        # We need the current working directory to be set to the build directory
34        os.chdir(self.getBuildDir())
35        # Create a target with the object file we just created from YAML
36        target = self.dbg.CreateTarget(obj_path)
37        self.assertTrue(target, VALID_TARGET)
38
39        # Set a breakpoint by file and line, this doesn't require anything from
40        # the .dwo file.
41        bp = target.BreakpointCreateByLocation("main.cpp", 6)
42        self.assertEqual(bp.GetNumLocations(), 1)
43        bp_loc = bp.GetLocationAtIndex(0)
44        self.assertTrue(bp_loc.IsValid())
45
46        # We will use the address of the location to resolve the function "main"
47        # to make sure we were able to open the .dwo file since this is the only
48        # place that contains debug info for the function.
49        self.assertTrue(bp_loc.GetAddress().GetFunction().IsValid())
50