|
| 1 | +"""Test that corefiles with an LC_NOTE "kern ver str" load command is used.""" |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | + |
| 5 | + |
| 6 | +import os |
| 7 | +import re |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | + |
| 11 | +import lldb |
| 12 | +from lldbsuite.test.decorators import * |
| 13 | +from lldbsuite.test.lldbtest import * |
| 14 | +from lldbsuite.test import lldbutil |
| 15 | + |
| 16 | + |
| 17 | +class TestKernVerStrLCNOTE(TestBase): |
| 18 | + |
| 19 | + mydir = TestBase.compute_mydir(__file__) |
| 20 | + |
| 21 | + @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM") |
| 22 | + @skipIfDarwinEmbedded |
| 23 | + @skipUnlessDarwin |
| 24 | + def test_lc_note(self): |
| 25 | + self.build() |
| 26 | + self.test_exe = self.getBuildArtifact("a.out") |
| 27 | + self.create_corefile = self.getBuildArtifact("create-empty-corefile") |
| 28 | + self.dsym_for_uuid = self.getBuildArtifact("dsym-for-uuid.sh") |
| 29 | + self.corefile = self.getBuildArtifact("core") |
| 30 | + |
| 31 | + ## We can hook in our dsym-for-uuid shell script to lldb with this env |
| 32 | + ## var instead of requiring a defaults write. |
| 33 | + os.environ['LLDB_APPLE_DSYMFORUUID_EXECUTABLE'] = self.dsym_for_uuid |
| 34 | + self.addTearDownHook(lambda: os.environ.pop('LLDB_APPLE_DSYMFORUUID_EXECUTABLE', None)) |
| 35 | + |
| 36 | + dwarfdump_uuid_regex = re.compile( |
| 37 | + 'UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*') |
| 38 | + dwarfdump_cmd_output = subprocess.check_output( |
| 39 | + ('/usr/bin/dwarfdump --uuid "%s"' % self.test_exe), shell=True).decode("utf-8") |
| 40 | + aout_uuid = None |
| 41 | + for line in dwarfdump_cmd_output.splitlines(): |
| 42 | + match = dwarfdump_uuid_regex.search(line) |
| 43 | + if match: |
| 44 | + aout_uuid = match.group(1) |
| 45 | + self.assertNotEqual(aout_uuid, None, "Could not get uuid of built a.out") |
| 46 | + |
| 47 | + ### Create our dsym-for-uuid shell script which returns self.test_exe |
| 48 | + ### and its dSYM when given self.test_exe's UUID. |
| 49 | + shell_cmds = [ |
| 50 | + '#! /bin/sh', |
| 51 | + 'ret=0', |
| 52 | + 'echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>"', |
| 53 | + 'echo "<!DOCTYPE plist PUBLIC \\"-//Apple//DTD PLIST 1.0//EN\\" \\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\">"', |
| 54 | + 'date >> /tmp/log', |
| 55 | + 'echo "<plist version=\\"1.0\\">"', |
| 56 | + '', |
| 57 | + '# the last arugment is probably the uuid', |
| 58 | + 'while [ $# -gt 1 ]', |
| 59 | + 'do', |
| 60 | + ' shift', |
| 61 | + 'done', |
| 62 | + 'echo "<dict><key>$1</key><dict>"', |
| 63 | + '', |
| 64 | + 'if [ "$1" = "%s" ]' % aout_uuid, |
| 65 | + 'then', |
| 66 | + ' echo "<key>DBGArchitecture</key><string>x86_64</string>"', |
| 67 | + ' echo "<key>DBGDSYMPath</key><string>%s.dSYM/Contents/Resources/DWARF/%s</string>"' % (self.test_exe, os.path.basename(self.test_exe)), |
| 68 | + ' echo "<key>DBGSymbolRichExecutable</key><string>%s</string>"' % 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 corefile |
| 84 | + retcode = call(self.create_corefile + " " + self.corefile + " " + self.test_exe, shell=True) |
| 85 | + |
| 86 | + ### Now run lldb on the corefile |
| 87 | + ### which will give us a UUID |
| 88 | + ### which we call dsym-for-uuid.sh with |
| 89 | + ### which gives us a binary and dSYM |
| 90 | + ### which lldb should load! |
| 91 | + |
| 92 | + |
| 93 | + self.target = self.dbg.CreateTarget('') |
| 94 | + err = lldb.SBError() |
| 95 | + self.process = self.target.LoadCore(self.corefile) |
| 96 | + self.assertEqual(self.process.IsValid(), True) |
| 97 | + if self.TraceOn(): |
| 98 | + self.runCmd("image list") |
| 99 | + self.assertEqual(self.target.GetNumModules(), 1) |
| 100 | + fspec = self.target.GetModuleAtIndex(0).GetFileSpec() |
| 101 | + filepath = fspec.GetDirectory() + "/" + fspec.GetFilename() |
| 102 | + self.assertEqual(filepath, self.test_exe) |
0 commit comments