xref: /llvm-project/lldb/test/API/macosx/DBGSourcePathRemapping/TestDSYMSourcePathRemapping.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprechtimport lldb
299451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
399451b44SJordan Rupprechtimport lldbsuite.test.lldbtest as lldbtest
499451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil
599451b44SJordan Rupprechtimport os
699451b44SJordan Rupprecht
799451b44SJordan Rupprecht
899451b44SJordan Rupprechtclass TestDSYMSourcePathRemapping(lldbtest.TestBase):
999451b44SJordan Rupprecht    def build(self):
10*2238dcc3SJonas Devlieghere        botdir = self.getBuildArtifact("buildbot")
11*2238dcc3SJonas Devlieghere        userdir = self.getBuildArtifact("user")
12*2238dcc3SJonas Devlieghere        inputs = self.getSourcePath("Inputs")
1399451b44SJordan Rupprecht        lldbutil.mkdir_p(botdir)
1499451b44SJordan Rupprecht        lldbutil.mkdir_p(userdir)
1599451b44SJordan Rupprecht        import shutil
16*2238dcc3SJonas Devlieghere
17*2238dcc3SJonas Devlieghere        for f in ["main.c", "relative.c"]:
1899451b44SJordan Rupprecht            shutil.copyfile(os.path.join(inputs, f), os.path.join(botdir, f))
1999451b44SJordan Rupprecht            shutil.copyfile(os.path.join(inputs, f), os.path.join(userdir, f))
2099451b44SJordan Rupprecht
2199451b44SJordan Rupprecht        super(TestDSYMSourcePathRemapping, self).build()
2299451b44SJordan Rupprecht
2399451b44SJordan Rupprecht        # Remove the build sources.
2499451b44SJordan Rupprecht        self.assertTrue(os.path.isdir(botdir))
2599451b44SJordan Rupprecht        shutil.rmtree(botdir)
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht        # Create a plist.
2899451b44SJordan Rupprecht        import subprocess
2999451b44SJordan Rupprecht
30*2238dcc3SJonas Devlieghere        dsym = self.getBuildArtifact("a.out.dSYM")
31*2238dcc3SJonas Devlieghere        uuid = (
32*2238dcc3SJonas Devlieghere            subprocess.check_output(["/usr/bin/dwarfdump", "--uuid", dsym])
33*2238dcc3SJonas Devlieghere            .decode("utf-8")
34*2238dcc3SJonas Devlieghere            .split(" ")[1]
35*2238dcc3SJonas Devlieghere        )
36*2238dcc3SJonas Devlieghere        import re
37*2238dcc3SJonas Devlieghere
38*2238dcc3SJonas Devlieghere        self.assertTrue(re.match(r"[0-9a-fA-F-]+", uuid))
39*2238dcc3SJonas Devlieghere        plist = os.path.join(dsym, "Contents", "Resources", uuid + ".plist")
40*2238dcc3SJonas Devlieghere        with open(plist, "w") as f:
41*2238dcc3SJonas Devlieghere            f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
42*2238dcc3SJonas Devlieghere            f.write(
43*2238dcc3SJonas Devlieghere                '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
44*2238dcc3SJonas Devlieghere            )
45*2238dcc3SJonas Devlieghere            f.write('<plist version="1.0">\n')
46*2238dcc3SJonas Devlieghere            f.write("<dict>\n")
47*2238dcc3SJonas Devlieghere            f.write("  <key>DBGSourcePathRemapping</key>\n")
48*2238dcc3SJonas Devlieghere            f.write("  <dict>\n")
49*2238dcc3SJonas Devlieghere            f.write("    <key>" + os.path.realpath(botdir) + "</key>\n")
50*2238dcc3SJonas Devlieghere            f.write("    <string>" + userdir + "</string>\n")
51*2238dcc3SJonas Devlieghere            f.write("  </dict>\n")
52*2238dcc3SJonas Devlieghere            f.write("</dict>\n")
53*2238dcc3SJonas Devlieghere            f.write("</plist>\n")
5499451b44SJordan Rupprecht
5599451b44SJordan Rupprecht    @skipIf(debug_info=no_match("dsym"))
5699451b44SJordan Rupprecht    def test(self):
5799451b44SJordan Rupprecht        self.build()
5899451b44SJordan Rupprecht
59*2238dcc3SJonas Devlieghere        target, process, _, _ = lldbutil.run_to_name_breakpoint(self, "main")
6099451b44SJordan Rupprecht        self.expect("source list -n main", substrs=["Hello Absolute"])
61*2238dcc3SJonas Devlieghere        bkpt = target.BreakpointCreateByName("relative")
6299451b44SJordan Rupprecht        lldbutil.continue_to_breakpoint(process, bkpt)
6399451b44SJordan Rupprecht        self.expect("source list -n relative", substrs=["Hello Relative"])
64