Skip to content

Commit 02a248d

Browse files
authored
Merge pull request #3344 from apple/🍒/FBI/730fca46fc87dad09040cb0b27ede10ae2c7c9d7
[lldb] Improve meta data stripping from JSON crashlogs
2 parents dc2c0ec + bf6f27e commit 02a248d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lldb/examples/python/crashlog.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,14 @@ def parse(self):
415415
with open(self.path, 'r') as f:
416416
buffer = f.read()
417417

418-
# First line is meta-data.
419-
buffer = buffer[buffer.index('\n') + 1:]
418+
# Skip the first line if it contains meta data.
419+
head, _, tail = buffer.partition('\n')
420+
try:
421+
metadata = json.loads(head)
422+
if 'app_name' in metadata and 'app_version' in metadata:
423+
buffer = tail
424+
except ValueError:
425+
pass
420426

421427
try:
422428
self.data = json.loads(buffer)

lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# RUN: %clang_host -g %S/Inputs/test.c -o %t.out
2+
23
# RUN: cp %S/Inputs/a.out.ips %t.crash
34
# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json
45
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s
56

7+
# RUN: cp %S/Inputs/a.out.ips %t.nometadata.crash
8+
# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.nometadata.crash --offsets '{"main":20, "bar":9, "foo":16}' --json --no-metadata
9+
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.nometadata.crash' 2>&1 | FileCheck %s
10+
611
# CHECK: Thread[0] Crashing Thread Name EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000000)
712
# CHECK: [ 0] {{.*}}out`foo + 16 at test.c
813
# CHECK: [ 1] {{.*}}out`bar + 8 at test.c

lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ def patch_addresses(self):
4949
self.data = self.data.replace(
5050
"@{}@".format(symbol), str(representation(patch_addr)))
5151

52+
def remove_metadata(self):
53+
self.data= self.data[self.data.index('\n') + 1:]
54+
5255

5356
if __name__ == '__main__':
5457
parser = argparse.ArgumentParser(description='Crashlog Patcher')
5558
parser.add_argument('--binary', required=True)
5659
parser.add_argument('--crashlog', required=True)
5760
parser.add_argument('--offsets', required=True)
5861
parser.add_argument('--json', default=False, action='store_true')
62+
parser.add_argument('--no-metadata', default=False, action='store_true')
5963
args = parser.parse_args()
6064

6165
offsets = json.loads(args.offsets)
@@ -68,5 +72,8 @@ def patch_addresses(self):
6872
p.patch_uuid()
6973
p.patch_addresses()
7074

75+
if args.no_metadata:
76+
p.remove_metadata()
77+
7178
with open(args.crashlog, 'w') as file:
7279
file.write(p.data)

0 commit comments

Comments
 (0)