brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · a3f9144 Raw
104 lines · python
1"""Test that corefiles with an LC_NOTE "kern ver str" load command is used."""2 3 4import os5import re6import subprocess7 8import lldb9from lldbsuite.test.decorators import *10from lldbsuite.test.lldbtest import *11from lldbsuite.test import lldbutil12 13 14class TestKernVerStrLCNOTE(TestBase):15    @skipIf(16        debug_info=no_match(["dsym"]),17        bugnumber="This test is looking explicitly for a dSYM",18    )19    @skipIf(archs=no_match(["x86_64"]))20    @skipUnlessDarwin21    def test_lc_note(self):22        self.build()23        self.test_exe = self.getBuildArtifact("a.out")24        self.create_corefile = self.getBuildArtifact("create-empty-corefile")25        self.dsym_for_uuid = self.getBuildArtifact("dsym-for-uuid.sh")26        self.corefile = self.getBuildArtifact("core")27 28        ## We can hook in our dsym-for-uuid shell script to lldb with this env29        ## var instead of requiring a defaults write.30        os.environ["LLDB_APPLE_DSYMFORUUID_EXECUTABLE"] = self.dsym_for_uuid31        self.addTearDownHook(32            lambda: os.environ.pop("LLDB_APPLE_DSYMFORUUID_EXECUTABLE", None)33        )34 35        dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")36        dwarfdump_cmd_output = subprocess.check_output(37            ('/usr/bin/dwarfdump --uuid "%s"' % self.test_exe), shell=True38        ).decode("utf-8")39        aout_uuid = None40        for line in dwarfdump_cmd_output.splitlines():41            match = dwarfdump_uuid_regex.search(line)42            if match:43                aout_uuid = match.group(1)44        self.assertNotEqual(aout_uuid, None, "Could not get uuid of built a.out")45 46        ###  Create our dsym-for-uuid shell script which returns self.test_exe47        ###  and its dSYM when given self.test_exe's UUID.48        shell_cmds = [49            "#! /bin/sh",50            "ret=0",51            'echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>"',52            'echo "<!DOCTYPE plist PUBLIC \\"-//Apple//DTD PLIST 1.0//EN\\" \\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\">"',53            'echo "<plist version=\\"1.0\\">"',54            "",55            "# the last argument is probably the uuid",56            "while [ $# -gt 1 ]",57            "do",58            "  shift",59            "done",60            'echo "<dict><key>$1</key><dict>"',61            "",62            'if [ "$1" = "%s" ]' % aout_uuid,63            "then",64            '  echo "<key>DBGArchitecture</key><string>x86_64</string>"',65            '  echo "<key>DBGDSYMPath</key><string>%s.dSYM/Contents/Resources/DWARF/%s</string>"'66            % (self.test_exe, os.path.basename(self.test_exe)),67            '  echo "<key>DBGSymbolRichExecutable</key><string>%s</string>"'68            % self.test_exe,69            "else",70            '  echo "<key>DBGError</key><string>not found</string>"',71            "  ret=1",72            "fi",73            'echo "</dict></dict></plist>"',74            "exit $ret",75        ]76 77        with open(self.dsym_for_uuid, "w") as writer:78            for l in shell_cmds:79                writer.write(l + "\n")80 81        os.chmod(self.dsym_for_uuid, 0o755)82 83        ### Create our corefile84        retcode = call(85            self.create_corefile + " " + self.corefile + " " + self.test_exe, shell=True86        )87 88        ### Now run lldb on the corefile89        ### which will give us a UUID90        ### which we call dsym-for-uuid.sh with91        ### which gives us a binary and dSYM92        ### which lldb should load!93 94        self.target = self.dbg.CreateTarget("")95        err = lldb.SBError()96        self.process = self.target.LoadCore(self.corefile)97        self.assertTrue(self.process.IsValid())98        if self.TraceOn():99            self.runCmd("image list")100        self.assertEqual(self.target.GetNumModules(), 1)101        fspec = self.target.GetModuleAtIndex(0).GetFileSpec()102        filepath = fspec.GetDirectory() + "/" + fspec.GetFilename()103        self.assertEqual(filepath, self.test_exe)104