Skip to content

Commit f2b003f

Browse files
authored
Merge pull request #3427 from apple/🍒/FBI/b225c5f7861c+b913065bf470
🍒/FBI/b225c5f7861c+b913065bf470
2 parents 9594c69 + 4d7ee57 commit f2b003f

File tree

5 files changed

+141
-3
lines changed

5 files changed

+141
-3
lines changed

lldb/examples/python/crashlog.py

Lines changed: 19 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:
@@ -330,6 +334,7 @@ def __init__(self, debugger, path, verbose):
330334
self.threads = list()
331335
self.backtraces = list() # For application specific backtraces
332336
self.idents = list() # A list of the required identifiers for doing all stack backtraces
337+
self.errors = list()
333338
self.crashed_thread_idx = -1
334339
self.version = -1
335340
self.target = None
@@ -433,6 +438,7 @@ def parse(self):
433438
self.parse_process_info(self.data)
434439
self.parse_images(self.data['usedImages'])
435440
self.parse_threads(self.data['threads'])
441+
self.parse_errors(self.data)
436442
thread = self.crashlog.threads[self.crashlog.crashed_thread_idx]
437443
reason = self.parse_crash_reason(self.data['exception'])
438444
if thread.reason:
@@ -505,8 +511,10 @@ def parse_threads(self, json_threads):
505511
thread.reason = json_thread['name']
506512
if json_thread.get('triggered', False):
507513
self.crashlog.crashed_thread_idx = idx
508-
thread.registers = self.parse_thread_registers(
509-
json_thread['threadState'])
514+
thread.crashed = True
515+
if 'threadState' in json_thread:
516+
thread.registers = self.parse_thread_registers(
517+
json_thread['threadState'])
510518
thread.queue = json_thread.get('queue')
511519
self.parse_frames(thread, json_thread.get('frames', []))
512520
self.crashlog.threads.append(thread)
@@ -522,6 +530,10 @@ def parse_thread_registers(self, json_thread_state):
522530
pass
523531
return registers
524532

533+
def parse_errors(self, json_data):
534+
if 'reportNotes' in json_data:
535+
self.crashlog.errors = json_data['reportNotes']
536+
525537

526538
class CrashLogParseMode:
527539
NORMAL = 0
@@ -1061,6 +1073,11 @@ def SymbolicateCrashLog(crash_log, options):
10611073
thread.dump_symbolicated(crash_log, options)
10621074
print()
10631075

1076+
if crash_log.errors:
1077+
print("Errors:")
1078+
for error in crash_log.errors:
1079+
print(error)
1080+
10641081

10651082
def CreateSymbolicateCrashLogOptions(
10661083
command_name,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,9 @@
170170
"threadTriggered" : {
171171
"queue" : "com.apple.main-thread"
172172
}
173-
}
173+
},
174+
"reportNotes" : [
175+
"invalid foo",
176+
"invalid bar"
177+
]
174178
}
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+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
# CHECK: [ 1] {{.*}}out`bar + 8 at test.c
1414
# CHECK: [ 2] {{.*}}out`main + 19 at test.c
1515
# CHECK: rbp = 0x00007ffeec22a530
16+
# CHECK: invalid foo
17+
# CHECK: invalid bar
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)