[Lldb-commits] [lldb] a4d1e60 - [crashlog] Improve patch-crashlog.py script
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 16 23:27:48 PST 2020
Author: Jonas Devlieghere
Date: 2020-11-16T23:27:40-08:00
New Revision: a4d1e60910ede9456f5720bcd40b17279e3b9331
URL: https://github.com/llvm/llvm-project/commit/a4d1e60910ede9456f5720bcd40b17279e3b9331
DIFF: https://github.com/llvm/llvm-project/commit/a4d1e60910ede9456f5720bcd40b17279e3b9331.diff
LOG: [crashlog] Improve patch-crashlog.py script
Compute the real addresses and offsets for the json crashlog test.
Added:
Modified:
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/a.out.ips
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
Removed:
################################################################################
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/a.out.ips b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/a.out.ips
index 703acce05c65..13feba12c177 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/a.out.ips
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/a.out.ips
@@ -34,7 +34,7 @@
"termination" : {"reason":"Namespace SIGNAL, Code 0xb","signal":"Segmentation fault: 11","byProc":"exc handler","code":11,"namespace":"SIGNAL","byPid":2187,"flags":0},
"asi" : ["dyld2 mode"],
"extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":2067},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
- "threads" : [{"triggered":true,"id":22172,"queue":"com.apple.main-thread","frames":[[0,16240],[0,16265],[0,16292],[1,87601]]}],
+ "threads" : [{"triggered":true,"id":22172,"queue":"com.apple.main-thread","frames":[[0, at foo@],[0, at bar@],[0, at main@],[1,87601]]}],
"threadState" : {
"r13" : 0,
"rax" : 0,
@@ -64,7 +64,7 @@
"usedImages" : [
[
"@UUID@",
- 0,
+ 4294967296,
"P"
],
[
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
index c92be0b7f2d0..fbae32a801d5 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
@@ -1,10 +1,9 @@
# RUN: %clang_host -g %S/Inputs/test.c -o %t.out
# RUN: cp %S/Inputs/a.out.ips %t.crash
-# RUN: python %S/patch-crashlog.py %t.out %t.crash
+# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s
# CHECK: Thread[0] EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x00000000)
# CHECK: [ 0] {{.*}}out`foo + 16 at test.c
# CHECK: [ 1] {{.*}}out`bar + 8 at test.c
# CHECK: [ 2] {{.*}}out`main + 19 at test.c
-# CHECK: [ 3] {{.*}}start
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
index ba69547f6140..a8aeb357c846 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
@@ -5,6 +5,7 @@
import re
import subprocess
import sys
+import argparse
class CrashLogPatcher:
@@ -12,10 +13,11 @@ class CrashLogPatcher:
SYMBOL_REGEX = re.compile(r'^([0-9a-fA-F]+) T _(.*)$')
UUID_REGEX = re.compile(r'UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*')
- def __init__(self, data, binary, offsets):
+ def __init__(self, data, binary, offsets, json):
self.data = data
self.binary = binary
self.offsets = offsets
+ self.json = json
def patch_executable(self):
self.data = self.data.replace("@EXEC@", self.binary)
@@ -39,22 +41,32 @@ def patch_addresses(self):
if symbol in self.offsets:
patch_addr = int(m.group(1), 16) + int(
self.offsets[symbol])
- self.data = self.data.replace("@{}@".format(symbol),
- str(hex(patch_addr)))
+ if self.json:
+ patch_addr = patch_addr - 0x100000000
+ representation = int
+ else:
+ representation = hex
+ self.data = self.data.replace(
+ "@{}@".format(symbol), str(representation(patch_addr)))
if __name__ == '__main__':
- binary = sys.argv[1]
- crashlog = sys.argv[2]
- offsets = json.loads(sys.argv[3]) if len(sys.argv) > 3 else None
+ parser = argparse.ArgumentParser(description='Crashlog Patcher')
+ parser.add_argument('--binary', required=True)
+ parser.add_argument('--crashlog', required=True)
+ parser.add_argument('--offsets', required=True)
+ parser.add_argument('--json', default=False, action='store_true')
+ args = parser.parse_args()
- with open(crashlog, 'r') as file:
+ offsets = json.loads(args.offsets)
+
+ with open(args.crashlog, 'r') as file:
data = file.read()
- p = CrashLogPatcher(data, binary, offsets)
+ p = CrashLogPatcher(data, args.binary, offsets, args.json)
p.patch_executable()
p.patch_uuid()
p.patch_addresses()
- with open(crashlog, 'w') as file:
+ with open(args.crashlog, 'w') as file:
file.write(p.data)
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
index 137578494b0c..7c6e1fc1d1da 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test
@@ -1,10 +1,9 @@
# RUN: %clang_host -g %S/Inputs/test.c -o %t.out
# RUN: cp %S/Inputs/a.out.crash %t.crash
-# RUN: python %S/patch-crashlog.py %t.out %t.crash '{"main":20, "bar":9, "foo":16}'
+# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}'
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s
# CHECK: Thread[0] EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000000)
# CHECK: [ 0] {{.*}}out`foo + 16 at test.c
# CHECK: [ 1] {{.*}}out`bar + 8 at test.c
# CHECK: [ 2] {{.*}}out`main + 19 at test.c
-# CHECK: [ 3] {{.*}}start + 1
More information about the lldb-commits
mailing list