Skip to content

Commit b913065

Browse files
committed
[lldb] Support missing threadState in JSON crashlogs
Gracefully deal with JSON crashlogs that don't have thread state available and print an error saying as much: "No thread state (register information) available". rdar://83955858 Differential revision: https://reviews.llvm.org/D111341
1 parent 690da88 commit b913065

File tree

3 files changed

+123
-2
lines changed

3 files changed

+123
-2
lines changed

lldb/examples/python/crashlog.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(self, index, app_specific_backtrace):
8383
self.registers = dict()
8484
self.reason = None
8585
self.queue = None
86+
self.crashed = False
8687
self.app_specific_backtrace = app_specific_backtrace
8788

8889
def dump(self, prefix):
@@ -160,6 +161,9 @@ def dump_symbolicated(self, crash_log, options):
160161
print()
161162
for reg in self.registers.keys():
162163
print(" %-8s = %#16.16x" % (reg, self.registers[reg]))
164+
elif self.crashed:
165+
print()
166+
print("No thread state (register information) available")
163167

164168
def add_ident(self, ident):
165169
if ident not in self.idents:
@@ -505,8 +509,10 @@ def parse_threads(self, json_threads):
505509
thread.reason = json_thread['name']
506510
if json_thread.get('triggered', False):
507511
self.crashlog.crashed_thread_idx = idx
508-
thread.registers = self.parse_thread_registers(
509-
json_thread['threadState'])
512+
thread.crashed = True
513+
if 'threadState' in json_thread:
514+
thread.registers = self.parse_thread_registers(
515+
json_thread['threadState'])
510516
thread.queue = json_thread.get('queue')
511517
self.parse_frames(thread, json_thread.get('frames', []))
512518
self.crashlog.threads.append(thread)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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"}
2+
{
3+
"uptime" : 320000,
4+
"procLaunch" : "2021-03-08 13:56:51.7232 -0800",
5+
"procRole" : "Unspecified",
6+
"version" : 2,
7+
"exception" : {
8+
"type" : "EXC_BAD_ACCESS",
9+
"signal" : "SIGSEGV",
10+
"subtype" : "KERN_INVALID_ADDRESS at 0x0000000000000000"
11+
},
12+
"userID" : 501,
13+
"modelCode" : "iMacPro1,1",
14+
"coalitionID" : 6086,
15+
"osVersion" : {
16+
"train" : "macOS 11.3",
17+
"build" : "",
18+
"releaseType" : ""
19+
},
20+
"captureTime" : "2021-03-08 13:56:51.8610 -0800",
21+
"incident" : "FA21DF23-3344-4E45-BF27-4B8E63B7012B",
22+
"pid" : 72932,
23+
"cpuType" : "X86-64",
24+
"procName" : "json.test.tmp.out",
25+
"procPath" : "\/Users\/USER\/*\/json.test.tmp.out",
26+
"parentProc" : "fish",
27+
"parentPid" : 67002,
28+
"coalitionName" : "io.alacritty",
29+
"crashReporterKey" : "DCEF35CB-68D5-F524-FF13-060901F52EA8",
30+
"responsiblePid" : 65465,
31+
"responsibleProc" : "alacritty",
32+
"bridgeVersion" : {"build":"18P4544","train":"5.3"},
33+
"sip" : "enabled",
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+
"name": "Crashing Thread Name",
44+
"queue": "com.apple.main-thread",
45+
"frames": [
46+
{
47+
"imageOffset": @foo@,
48+
"sourceLine": 3,
49+
"sourceFile": "test.c",
50+
"symbol": "foo",
51+
"imageIndex": 0,
52+
"symbolLocation": 16
53+
},
54+
{
55+
"imageOffset": @bar@,
56+
"sourceLine": 6,
57+
"sourceFile": "test.c",
58+
"symbol": "bar",
59+
"imageIndex": 0,
60+
"symbolLocation": 9
61+
},
62+
{
63+
"imageOffset": @main@,
64+
"sourceLine": 8,
65+
"sourceFile": "test.c",
66+
"symbol": "main",
67+
"imageIndex": 0,
68+
"symbolLocation": 20
69+
},
70+
{
71+
"imageOffset": 89917,
72+
"symbol": "start",
73+
"symbolLocation": 1,
74+
"imageIndex": 1
75+
}
76+
]
77+
}
78+
],
79+
"usedImages" : [
80+
{
81+
"source" : "P",
82+
"arch" : "x86_64",
83+
"base" : 4355608576,
84+
"size" : 16384,
85+
"uuid" : "@UUID@",
86+
"path" : "@EXEC@",
87+
"name" : "@NAME@"
88+
},
89+
{
90+
"source" : "P",
91+
"arch" : "x86_64",
92+
"base" : 140733734899712,
93+
"size" : 245760,
94+
"uuid" : "c5caf30b-0617-3b07-88c7-6319cd06f30a",
95+
"path" : "\/usr\/lib\/system\/libdyld.dylib",
96+
"name" : "libdyld.dylib"
97+
}
98+
],
99+
"legacyInfo" : {
100+
"threadTriggered" : {
101+
"queue" : "com.apple.main-thread"
102+
}
103+
}
104+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: %clang_host -g %S/Inputs/test.c -o %t.out
2+
3+
# RUN: cp %S/Inputs/no_threadState.ips %t.crash
4+
# RUN: python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json
5+
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s
6+
7+
# CHECK: Thread[0] Crashing Thread Name EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000000)
8+
# CHECK: [ 0] {{.*}}out`foo + 16 at test.c
9+
# CHECK: [ 1] {{.*}}out`bar + 8 at test.c
10+
# CHECK: [ 2] {{.*}}out`main + 19 at test.c
11+
# CHECK: No thread state (register information) available

0 commit comments

Comments
 (0)