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