Skip to content

Commit be4be61

Browse files
committed
Add support to ProcessMachCore::DoLoadCore to handle an EFI UUID str.
If a core file has an EFI version string which includes a UUID (similar to what it returns for the kdp KDP_KERNELVERSION packet) in the LC_IDENT or LC_NOTE 'kern ver str' load command. In that case, we should try to find the binary and dSYM for the UUID listed. The dSYM may have python code which knows how to relocate the binary to the correct address in lldb's target section load list and loads other ancillary binaries. The test case is a little involved, 1. it compiles an inferior hello world apple (a.out), 2. it compiles a program which can create a corefile manually with a specific binary's UUID encoded in it, 3. it gets the UUID of the a.out binary, 4. it creates a shell script, dsym-for-uuid.sh, which will return the full path to the a.out + a.out.dSYM when called with teh correct UUID, 5. it sets the LLDB_APPLE_DSYMFORUUID_EXECUTABLE env var before creating the lldb target, to point to this dsym-for-uuid.sh, 6. runs the create-corefile binary we compiled in step #2, 7. loads the corefile from step #6 into lldb, 8. verifies that lldb loaded a.out by reading the LC_NOTE load command from the corefile, calling dsym-for-uuid.sh with that UUID, got back the path to a.out and loaded it. whew! <rdar://problem/47562911> llvm-svn: 366378
1 parent d0ac007 commit be4be61

File tree

6 files changed

+497
-0
lines changed

6 files changed

+497
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
LEVEL = ../../../make
2+
3+
MAKE_DSYM := NO
4+
5+
C_SOURCES := main.c
6+
7+
all: a.out create-empty-corefile
8+
9+
create-empty-corefile:
10+
$(MAKE) VPATH=$(VPATH) -f $(SRCDIR)/create-empty-corefile.mk
11+
12+
clean::
13+
$(MAKE) -f create-empty-corefile.mk clean
14+
15+
include $(LEVEL)/Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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

Comments
 (0)