Skip to content

[lldb] Improve meta data stripping from JSON crashlogs #3344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lldb/examples/python/crashlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,14 @@ def parse(self):
with open(self.path, 'r') as f:
buffer = f.read()

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

try:
self.data = json.loads(buffer)
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# 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 --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

# RUN: cp %S/Inputs/a.out.ips %t.nometadata.crash
# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.nometadata.crash --offsets '{"main":20, "bar":9, "foo":16}' --json --no-metadata
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.nometadata.crash' 2>&1 | FileCheck %s

# CHECK: Thread[0] Crashing Thread Name 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ def patch_addresses(self):
self.data = self.data.replace(
"@{}@".format(symbol), str(representation(patch_addr)))

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


if __name__ == '__main__':
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')
parser.add_argument('--no-metadata', default=False, action='store_true')
args = parser.parse_args()

offsets = json.loads(args.offsets)
Expand All @@ -68,5 +72,8 @@ def patch_addresses(self):
p.patch_uuid()
p.patch_addresses()

if args.no_metadata:
p.remove_metadata()

with open(args.crashlog, 'w') as file:
file.write(p.data)