Skip to content

Commit 5b8b791

Browse files
authored
Merge pull request #2640 from apple/🍒/ganymede/cc52ea30012d3d9495a41255be50dccc77464cad
[lldb] Update crashlog script for JSON changes
2 parents 5a54e98 + 39831b7 commit 5b8b791

File tree

3 files changed

+165
-92
lines changed

3 files changed

+165
-92
lines changed

lldb/examples/python/crashlog.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,9 @@ def parse(self):
415415

416416
thread = self.crashlog.threads[self.crashlog.crashed_thread_idx]
417417
thread.reason = self.parse_crash_reason(self.data['exception'])
418-
thread.registers = self.parse_thread_registers(self.data['threadState'])
419418

420419
return self.crashlog
421420

422-
def get_image_extra_info(self, idx):
423-
return self.data['legacyInfo']['imageExtraInfo'][idx]
424-
425421
def get_used_image(self, idx):
426422
return self.data['usedImages'][idx]
427423

@@ -440,17 +436,16 @@ def parse_crash_reason(self, json_exception):
440436
else:
441437
exception_extra = ""
442438
return "{} ({}){}".format(exception_type, exception_signal,
443-
exception_extra)
439+
exception_extra)
444440

445441
def parse_images(self, json_images):
446442
idx = 0
447-
for json_images in json_images:
448-
img_uuid = uuid.UUID(json_images[0])
449-
low = int(json_images[1])
450-
high = 0
451-
extra_info = self.get_image_extra_info(idx)
452-
name = extra_info['name']
453-
path = extra_info['path']
443+
for json_image in json_images:
444+
img_uuid = uuid.UUID(json_image['uuid'])
445+
low = int(json_image['base'])
446+
high = int(0)
447+
name = json_image['name']
448+
path = json_image['path']
454449
version = ""
455450
darwin_image = self.crashlog.DarwinImage(low, high, name, version,
456451
img_uuid, path,
@@ -461,16 +456,14 @@ def parse_images(self, json_images):
461456
def parse_frames(self, thread, json_frames):
462457
idx = 0
463458
for json_frame in json_frames:
464-
image_id = int(json_frame[0])
465-
466-
ident = self.get_image_extra_info(image_id)['name']
459+
image_id = int(json_frame['imageIndex'])
460+
ident = self.get_used_image(image_id)['name']
467461
thread.add_ident(ident)
468462
if ident not in self.crashlog.idents:
469463
self.crashlog.idents.append(ident)
470464

471-
frame_offset = int(json_frame[1])
472-
image = self.get_used_image(image_id)
473-
image_addr = int(image[1])
465+
frame_offset = int(json_frame['imageOffset'])
466+
image_addr = self.get_used_image(image_id)['base']
474467
pc = image_addr + frame_offset
475468
thread.frames.append(self.crashlog.Frame(idx, pc, frame_offset))
476469
idx += 1
@@ -481,6 +474,8 @@ def parse_threads(self, json_threads):
481474
thread = self.crashlog.Thread(idx, False)
482475
if json_thread.get('triggered', False):
483476
self.crashlog.crashed_thread_idx = idx
477+
self.registers = self.parse_thread_registers(
478+
json_thread['threadState'])
484479
thread.queue = json_thread.get('queue')
485480
self.parse_frames(thread, json_thread.get('frames', []))
486481
self.crashlog.threads.append(thread)
@@ -489,15 +484,16 @@ def parse_threads(self, json_threads):
489484
def parse_thread_registers(self, json_thread_state):
490485
idx = 0
491486
registers = dict()
492-
for reg in json_thread_state.get('x', []):
487+
for json_reg in json_thread_state.get('x', []):
493488
key = str('x{}'.format(idx))
494-
value = int(reg)
489+
value = int(json_reg['value'])
495490
registers[key] = value
496491
idx += 1
497492

498493
for register in ['lr', 'cpsr', 'fp', 'sp', 'esr', 'pc']:
499494
if register in json_thread_state:
500-
registers[register] = int(json_thread_state[register])
495+
json_reg = json_thread_state[register]
496+
registers[register] = int(json_reg['value'])
501497

502498
return registers
503499

lldb/test/Shell/ScriptInterpreter/Python/Crashlog/Inputs/a.out.ips

Lines changed: 147 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,172 @@
1-
{"app_name":"a.out","timestamp":"2020-11-11 16:12:18.00 -0800","app_version":"","slice_uuid":"9b76648c-9b4e-33a9-a97e-10856e911631","build_version":"","platform":1,"share_with_app_devs":1,"is_first_party":1,"bug_type":"309","os_version":"macOS 11.0.1","incident_id":"598C4706-28B0-4D96-A2F9-AE6973BEC635","name":"a.out"}
1+
{"app_name":"json.test.tmp.out","timestamp":"2021-03-08 13:57:06.00 -0800","app_version":"","slice_uuid":"8f528c10-3e80-3dd6-b0be-5d558f64f7ab","build_version":"","platform":1,"share_with_app_devs":1,"is_first_party":1,"etl_key":"3","bug_type":"309","os_version":"macOS 11.3","incident_id":"FA21DF23-3344-4E45-BF27-4B8E63B7012B","name":"json.test.tmp.out"}
22
{
3-
"uptime" : 180,
4-
"procLaunch" : "2020-11-11 16:12:12.4375 -0800",
3+
"uptime" : 320000,
4+
"procLaunch" : "2021-03-08 13:56:51.7232 -0800",
55
"procRole" : "Unspecified",
6+
"version" : 2,
67
"exception" : {
78
"type" : "EXC_BAD_ACCESS",
89
"signal" : "SIGSEGV",
9-
"subtype" : "KERN_INVALID_ADDRESS at 0x00000000"
10+
"subtype" : "KERN_INVALID_ADDRESS at 0x0000000000000000"
1011
},
1112
"userID" : 501,
1213
"modelCode" : "iMacPro1,1",
13-
"coalitionID" : 471,
14+
"coalitionID" : 6086,
1415
"osVersion" : {
15-
"train" : "macOS 11.0.1",
16+
"train" : "macOS 11.3",
1617
"build" : "",
1718
"releaseType" : ""
1819
},
19-
"captureTime" : "2020-11-11 16:12:12.6267 -0800",
20-
"incident" : "598C4706-28B0-4D96-A2F9-AE6973BEC635",
21-
"pid" : 2187,
20+
"captureTime" : "2021-03-08 13:56:51.8610 -0800",
21+
"incident" : "FA21DF23-3344-4E45-BF27-4B8E63B7012B",
22+
"pid" : 72932,
2223
"cpuType" : "X86-64",
23-
"procName" : "a.out",
24-
"procPath" : "\/private\/tmp\/a.out",
24+
"procName" : "json.test.tmp.out",
25+
"procPath" : "\/Users\/USER\/*\/json.test.tmp.out",
2526
"parentProc" : "fish",
26-
"parentPid" : 1651,
27+
"parentPid" : 67002,
2728
"coalitionName" : "io.alacritty",
2829
"crashReporterKey" : "DCEF35CB-68D5-F524-FF13-060901F52EA8",
29-
"responsiblePid" : 428,
30+
"responsiblePid" : 65465,
3031
"responsibleProc" : "alacritty",
31-
"bridgeVersion" : {"build":"","train":""},
32+
"bridgeVersion" : {"build":"18P4544","train":"5.3"},
3233
"sip" : "enabled",
33-
"is_corpse" : 1,
34-
"termination" : {"reason":"Namespace SIGNAL, Code 0xb","signal":"Segmentation fault: 11","byProc":"exc handler","code":11,"namespace":"SIGNAL","byPid":2187,"flags":0},
35-
"asi" : ["dyld2 mode"],
36-
"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},
37-
"threads" : [{"triggered":true,"id":22172,"queue":"com.apple.main-thread","frames":[[0,@foo@],[0,@bar@],[0,@main@],[1,87601]]}],
38-
"threadState" : {
39-
"r13" : 0,
40-
"rax" : 0,
41-
"rflags" : 66054,
42-
"cpu" : 6,
43-
"rsi" : 140732908048520,
44-
"r14" : 0,
45-
"trap_description" : "(no mapping for user data write)",
46-
"r8" : 0,
47-
"cr2" : 0,
48-
"rdx" : 140732908048536,
49-
"r10" : 0,
50-
"r9" : 0,
51-
"r15" : 0,
52-
"rbx" : 0,
53-
"trap" : 14,
54-
"err" : 6,
55-
"r11" : 0,
56-
"rip" : 4307689328,
57-
"rbp" : 140732908048432,
58-
"rsp" : 140732908048432,
59-
"r12" : 0,
60-
"rcx" : 140732908048880,
61-
"flavor" : "x86_THREAD_STATE",
62-
"rdi" : 1
63-
},
34+
"isCorpse" : 1,
35+
"termination" : {"flags":0,"code":11,"namespace":"SIGNAL","indicator":"Segmentation fault: 11","byProc":"exc handler","byPid":72932},
36+
"asi" : {"dyld":["dyld2 mode"]},
37+
"extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":125361,"task_for_pid":9935},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
38+
"faultingThread" : 0,
39+
"threads" : [
40+
{
41+
"triggered": true,
42+
"id": 6152004,
43+
"threadState": {
44+
"r13": {
45+
"value": 0
46+
},
47+
"rax": {
48+
"value": 0
49+
},
50+
"rflags": {
51+
"value": 66054
52+
},
53+
"cpu": {
54+
"value": 4
55+
},
56+
"r14": {
57+
"value": 0
58+
},
59+
"rsi": {
60+
"value": 140732860114304
61+
},
62+
"r8": {
63+
"value": 0
64+
},
65+
"cr2": {
66+
"value": 0
67+
},
68+
"rdx": {
69+
"value": 140732860114320
70+
},
71+
"r10": {
72+
"value": 0
73+
},
74+
"r9": {
75+
"value": 0
76+
},
77+
"r15": {
78+
"value": 0
79+
},
80+
"rbx": {
81+
"value": 0
82+
},
83+
"trap": {
84+
"value": 14,
85+
"description": "(no mapping for user data write)"
86+
},
87+
"err": {
88+
"value": 6
89+
},
90+
"r11": {
91+
"value": 0
92+
},
93+
"rip": {
94+
"value": 4355624816
95+
},
96+
"rbp": {
97+
"value": 140732860114224
98+
},
99+
"rsp": {
100+
"value": 140732860114224
101+
},
102+
"r12": {
103+
"value": 0
104+
},
105+
"rcx": {
106+
"value": 140732860114656
107+
},
108+
"flavor": "x86_THREAD_STATE",
109+
"rdi": {
110+
"value": 1
111+
}
112+
},
113+
"queue": "com.apple.main-thread",
114+
"frames": [
115+
{
116+
"imageOffset": @foo@,
117+
"sourceLine": 3,
118+
"sourceFile": "test.c",
119+
"symbol": "foo",
120+
"imageIndex": 0,
121+
"symbolLocation": 16
122+
},
123+
{
124+
"imageOffset": @bar@,
125+
"sourceLine": 6,
126+
"sourceFile": "test.c",
127+
"symbol": "bar",
128+
"imageIndex": 0,
129+
"symbolLocation": 9
130+
},
131+
{
132+
"imageOffset": @main@,
133+
"sourceLine": 8,
134+
"sourceFile": "test.c",
135+
"symbol": "main",
136+
"imageIndex": 0,
137+
"symbolLocation": 20
138+
},
139+
{
140+
"imageOffset": 89917,
141+
"symbol": "start",
142+
"symbolLocation": 1,
143+
"imageIndex": 1
144+
}
145+
]
146+
}
147+
],
64148
"usedImages" : [
65-
[
66-
"@UUID@",
67-
4294967296,
68-
"P"
69-
],
70-
[
71-
"6a1f593e-3705-314d-bb40-e7f9d502bf81",
72-
140733737017344,
73-
"P"
74-
]
149+
{
150+
"source" : "P",
151+
"arch" : "x86_64",
152+
"base" : 4355608576,
153+
"size" : 16384,
154+
"uuid" : "@UUID@",
155+
"path" : "@EXEC@",
156+
"name" : "@NAME@"
157+
},
158+
{
159+
"source" : "P",
160+
"arch" : "x86_64",
161+
"base" : 140733734899712,
162+
"size" : 245760,
163+
"uuid" : "c5caf30b-0617-3b07-88c7-6319cd06f30a",
164+
"path" : "\/usr\/lib\/system\/libdyld.dylib",
165+
"name" : "libdyld.dylib"
166+
}
75167
],
76168
"legacyInfo" : {
77-
"imageExtraInfo" : [
78-
{
79-
"size" : 16384,
80-
"arch" : "x86_64",
81-
"path" : "@EXEC@",
82-
"name" : "@NAME@"
83-
},
84-
{
85-
"size" : 241664,
86-
"arch" : "x86_64",
87-
"path" : "\/usr\/lib\/system\/libdyld.dylib",
88-
"name" : "libdyld.dylib"
89-
}
90-
],
91169
"threadTriggered" : {
92-
"index" : 0,
93170
"queue" : "com.apple.main-thread"
94171
}
95172
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json
44
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s
55

6-
# CHECK: Thread[0] EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x00000000)
6+
# CHECK: Thread[0] EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000000)
77
# CHECK: [ 0] {{.*}}out`foo + 16 at test.c
88
# CHECK: [ 1] {{.*}}out`bar + 8 at test.c
99
# CHECK: [ 2] {{.*}}out`main + 19 at test.c

0 commit comments

Comments
 (0)