Skip to content

Commit 1db9afb

Browse files
authored
[lldb/crashlog] Make registers always available & fix x29/x30 parsing (llvm#145104)
This patch addresses 2 issues: 1. It makes registers available on non-crashed threads all the time 2. It fixes arm64 registers parsing for registers that don't use the `x` prefix (`fp` -> `x29` / `lr` -> `x30`) --------- Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent b7be878 commit 1db9afb

File tree

3 files changed

+91
-9
lines changed

3 files changed

+91
-9
lines changed

lldb/examples/python/crashlog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,10 @@ def parse_threads(self, json_threads):
777777
if json_thread.get("triggered", False):
778778
self.crashlog.crashed_thread_idx = idx
779779
thread.crashed = True
780-
if "threadState" in json_thread:
781-
thread.registers = self.parse_thread_registers(
782-
json_thread["threadState"]
783-
)
780+
if "threadState" in json_thread:
781+
thread.registers = self.parse_thread_registers(
782+
json_thread["threadState"]
783+
)
784784
if "queue" in json_thread:
785785
thread.queue = json_thread.get("queue")
786786
self.parse_frames(thread, json_thread.get("frames", []))

lldb/examples/python/crashlog_scripted_process.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,22 @@ def get_process_metadata(self):
123123

124124
class CrashLogScriptedThread(ScriptedThread):
125125
def create_register_ctx(self):
126-
if not self.has_crashed:
127-
return dict.fromkeys(
128-
[*map(lambda reg: reg["name"], self.register_info["registers"])], 0
129-
)
130-
131126
if not self.backing_thread or not len(self.backing_thread.registers):
132127
return dict.fromkeys(
133128
[*map(lambda reg: reg["name"], self.register_info["registers"])], 0
134129
)
135130

136131
for reg in self.register_info["registers"]:
137132
reg_name = reg["name"]
133+
reg_alt_name = None
134+
if "alt-name" in reg:
135+
reg_alt_name = reg["alt-name"]
138136
if reg_name in self.backing_thread.registers:
139137
self.register_ctx[reg_name] = self.backing_thread.registers[reg_name]
138+
elif reg_alt_name and reg_alt_name in self.backing_thread.registers:
139+
self.register_ctx[reg_name] = self.backing_thread.registers[
140+
reg_alt_name
141+
]
140142
else:
141143
self.register_ctx[reg_name] = 0
142144

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# REQUIRES: python, native && system-darwin
2+
3+
# RUN: mkdir -p %t.dir
4+
# RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test
5+
# RUN: %lldb -o 'command script import lldb.macosx.crashlog' \
6+
# RUN: -o 'crashlog -a -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \
7+
# RUN: -o "thread list" -o "bt all" -o "register read" 2>&1 | FileCheck %s
8+
9+
# CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
10+
11+
# CHECK: (lldb) process status
12+
# CHECK-NEXT: Process 22511 stopped
13+
# CHECK-NEXT: * thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
14+
# CHECK-NEXT: frame #0: 0x0000000100ec58f4 multithread-test`bar
15+
16+
# CHECK: (lldb) thread backtrace
17+
# CHECK-NEXT: * thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
18+
# CHECK-NEXT: * frame #0: 0x0000000100ec58f4 multithread-test`bar{{.*}} [artificial]
19+
# CHECK-NEXT: frame #1: 0x0000000100ec591b multithread-test`foo{{.*}} [artificial]
20+
# CHECK-NEXT: frame #2: 0x0000000100ec5a87 multithread-test`compute_pow{{.*}} [artificial]
21+
22+
# CHECK: (lldb) thread list
23+
# CHECK-NEXT: Process 22511 stopped
24+
# CHECK-NEXT: thread #1: tid = 0x23c7fe, 0x000000019cc40b84{{.*}}, queue = 'com.apple.main-thread'
25+
# CHECK-NEXT: thread #2: tid = 0x23c800, 0x000000019cc42c9c{{.*}}
26+
# CHECK-NEXT: * thread #3: tid = 0x23c801, 0x0000000100ec58f4 multithread-test`bar{{.*}}, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
27+
28+
# CHECK: (lldb) bt all
29+
# CHECK: thread #1, queue = 'com.apple.main-thread'
30+
# CHECK: frame #{{[0-9]+}}: 0x000000019cc40b84{{.*}} [artificial]
31+
# CHECK: frame #{{[0-9]+}}: 0x0000000100ec5b3b multithread-test`main{{.*}} [artificial]
32+
# CHECK: frame #{{[0-9]+}}: 0x00000002230f8da7{{.*}} [artificial]
33+
# CHECK-NEXT: thread #2
34+
# CHECK-NEXT: frame #0: 0x000000019cc42c9c{{.*}} [artificial]
35+
# CHECK: frame #{{[0-9]+}}: 0x0000000100ec5957 multithread-test`call_and_wait{{.*}} [artificial]
36+
# CHECK: frame #{{[0-9]+}}: 0x000000019cc7e06b{{.*}} [artificial]
37+
# CHECK: frame #{{[0-9]+}}: 0x000000019cc78e2b{{.*}} [artificial]
38+
# CHECK-NEXT:* thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
39+
# CHECK-NEXT: * frame #0: 0x0000000100ec58f4 multithread-test`bar{{.*}} [artificial]
40+
# CHECK-NEXT: frame #1: 0x0000000100ec591b multithread-test`foo{{.*}} [artificial]
41+
# CHECK-NEXT: frame #2: 0x0000000100ec5a87 multithread-test`compute_pow{{.*}} [artificial]
42+
# CHECK: frame #{{[0-9]+}}: 0x000000019cc7e06b{{.*}} [artificial]
43+
# CHECK: frame #{{[0-9]+}}: 0x000000019cc78e2b{{.*}} [artificial]
44+
45+
# CHECK: (lldb) register read
46+
# CHECK: General Purpose Registers:
47+
# CHECK: x0 = 0x000000000000002a
48+
# CHECK: x1 = 0x0000600001d291b0
49+
# CHECK: x2 = 0x000000019cbbf000
50+
# CHECK: x3 = 0x0000000000000000
51+
# CHECK: x4 = 0x00000000000030a0
52+
# CHECK: x5 = 0x00000000190008ff
53+
# CHECK: x6 = 0x0000000000000000
54+
# CHECK: x7 = 0x0000000000000000
55+
# CHECK: x8 = 0x0000000000000001
56+
# CHECK: x9 = 0x0000000000000000
57+
# CHECK: x10 = 0xfffffffe634277cf
58+
# CHECK: x11 = 0x0000010000000102
59+
# CHECK: x12 = 0x0000010000000102
60+
# CHECK: x13 = 0x0000010000000100
61+
# CHECK: x14 = 0x0000010000000000
62+
# CHECK: x15 = 0x0000000000000001
63+
# CHECK: x16 = 0x000000019cc78ea8
64+
# CHECK: x17 = 0x00000001fd0a7698
65+
# CHECK: x18 = 0x0000000000000000
66+
# CHECK: x19 = 0x000000016f04f000
67+
# CHECK: x20 = 0x0000000000000000
68+
# CHECK: x21 = 0x0000000000000000
69+
# CHECK: x22 = 0x0000000000000000
70+
# CHECK: x23 = 0x0000000000000000
71+
# CHECK: x24 = 0x0000000000000000
72+
# CHECK: x25 = 0x0000000000000000
73+
# CHECK: x26 = 0x0000000000000000
74+
# CHECK: x27 = 0x0000000000000000
75+
# CHECK: x28 = 0x0000000000000000
76+
# CHECK: x29 = 0x000000016f04ef00
77+
# CHECK: x30 = 0x0000000100ec591c
78+
# CHECK: sp = 0x000000016f04eee0
79+
# CHECK: pc = 0x0000000100ec58f4
80+
# CHECK: cpsr = 0x80001000

0 commit comments

Comments
 (0)