Skip to content

Commit a667597

Browse files
authored
Merge pull request #7010 from medismailben/inlined-symbols-crashlog
[lldb/crashlog] Load inlined symbol into crashlog scripted process
2 parents e2b11c2 + 8a5e377 commit a667597

File tree

7 files changed

+420
-101
lines changed

7 files changed

+420
-101
lines changed

lldb/examples/python/crashlog.py

Lines changed: 201 additions & 76 deletions
Large diffs are not rendered by default.

lldb/examples/python/scripted_process/crashlog_scripted_process.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os,json,struct,signal,uuid
1+
import os, json, struct, signal, uuid, tempfile
22

33
from typing import Any, Dict
44

@@ -11,7 +11,13 @@
1111
class CrashLogScriptedProcess(ScriptedProcess):
1212
def set_crashlog(self, crashlog):
1313
self.crashlog = crashlog
14-
self.pid = self.crashlog.process_id
14+
if self.crashlog.process_id:
15+
if type(self.crashlog.process_id) is int:
16+
self.pid = self.crashlog.process_id
17+
elif type(self.crashlog.process_id) is str:
18+
self.pid = int(self.crashlog.process_id, 0)
19+
else:
20+
self.pid = super().get_process_id()
1521
self.addr_mask = self.crashlog.addr_mask
1622
self.crashed_thread_idx = self.crashlog.crashed_thread_idx
1723
self.loaded_images = []
@@ -32,16 +38,17 @@ def set_crashlog(self, crashlog):
3238
for image in self.crashlog.find_images_with_identifier(ident):
3339
image.resolve = True
3440

35-
for image in self.crashlog.images:
36-
if image not in self.loaded_images:
37-
if image.uuid == uuid.UUID(int=0):
38-
continue
39-
err = image.add_module(self.target)
40-
if err:
41-
# Append to SBCommandReturnObject
42-
print(err)
43-
else:
44-
self.loaded_images.append(image)
41+
with tempfile.TemporaryDirectory() as obj_dir:
42+
for image in self.crashlog.images:
43+
if image not in self.loaded_images:
44+
if image.uuid == uuid.UUID(int=0):
45+
continue
46+
err = image.add_module(self.target, obj_dir)
47+
if err:
48+
# Append to SBCommandReturnObject
49+
print(err)
50+
else:
51+
self.loaded_images.append(image)
4552

4653
for thread in self.crashlog.threads:
4754
if hasattr(thread, 'app_specific_backtrace') and thread.app_specific_backtrace:

lldb/examples/python/symbolication.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ def load_module(self, target):
394394
else:
395395
return "error: no section infos"
396396

397-
def add_module(self, target):
398-
"""Add the Image described in this object to "target" and load the sections if "load" is True."""
397+
def add_module(self, target, obj_dir=None):
398+
'''Add the Image described in this object to "target" and load the sections if "load" is True.'''
399399
if target:
400400
# Try and find using UUID only first so that paths need not match
401401
# up
@@ -411,7 +411,7 @@ def add_module(self, target):
411411
)
412412
if not self.module and self.section_infos:
413413
name = os.path.basename(self.path)
414-
with tempfile.NamedTemporaryFile(suffix="." + name) as tf:
414+
if obj_dir and os.path.isdir(obj_dir):
415415
data = {
416416
"triple": target.triple,
417417
"uuid": uuid_str,
@@ -420,16 +420,20 @@ def add_module(self, target):
420420
"symbols": list(),
421421
}
422422
for section in self.section_infos:
423-
data["sections"].append(
424-
{
425-
"name": section.name,
426-
"size": section.end_addr - section.start_addr,
427-
}
428-
)
429-
data["symbols"] = list(self.symbols.values())
430-
with open(tf.name, "w") as f:
423+
data['sections'].append({
424+
'name' : section.name,
425+
'size': section.end_addr - section.start_addr
426+
})
427+
data['symbols'] = list(self.symbols.values())
428+
obj_file = os.path.join(obj_dir, name)
429+
with open(obj_file, "w") as f:
431430
f.write(json.dumps(data, indent=4))
432-
self.module = target.AddModule(tf.name, None, uuid_str)
431+
self.module = target.AddModule(obj_file, None, uuid_str)
432+
if self.module:
433+
# If we were able to add the module with inlined
434+
# symbols, we should mark it as available so load_module
435+
# does not exit early.
436+
self.unavailable = False
433437
if not self.module and not self.unavailable:
434438
return 'error: unable to get module for (%s) "%s"' % (
435439
self.arch,

lldb/source/Target/Process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,7 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,
26692669

26702670
FileSpec exe_spec_to_use;
26712671
if (!exe_module) {
2672-
if (!launch_info.GetExecutableFile()) {
2672+
if (!launch_info.GetExecutableFile() && !launch_info.IsScriptedProcess()) {
26732673
error.SetErrorString("executable module does not exist");
26742674
return error;
26752675
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
Process: multithread-test [22511]
2+
Path: /Users/USER/*/multithread-test
3+
Identifier: multithread-test
4+
Version: ???
5+
Code Type: ARM-64 (Native)
6+
Parent Process: zsh [59146]
7+
Responsible: Terminal [1640]
8+
User ID: 501
9+
10+
Date/Time: 2022-07-28 11:10:19.4194 -0700
11+
OS Version: macOS 13.0 ()
12+
Report Version: 12
13+
Anonymous UUID: CDC11418-EDBF-2A49-0D83-8B441A5004B0
14+
15+
Sleep/Wake UUID: 7B2A0D73-8966-4B8D-98E9-CC6EC1B44967
16+
17+
Time Awake Since Boot: 110000 seconds
18+
Time Since Wake: 214 seconds
19+
20+
System Integrity Protection: disabled
21+
22+
Crashed Thread: 2
23+
24+
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
25+
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
26+
Exception Codes: 0x0000000000000001, 0x0000000000000000
27+
28+
Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
29+
Terminating Process: exc handler [22511]
30+
31+
VM Region Info: 0 is not in any region. Bytes before following region: 4310450176
32+
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
33+
UNUSED SPACE AT START
34+
--->
35+
__TEXT 100ec4000-100ec8000 [ 16K] r-x/r-x SM=COW ...tithread-test
36+
37+
Thread 0:: Dispatch queue: com.apple.main-thread
38+
0 libsystem_kernel.dylib 0x19cc40b84 __ulock_wait + 8
39+
1 libsystem_pthread.dylib 0x19cc80394 _pthread_join + 444
40+
2 libc++.1.dylib 0x19cbd8274 std::__1::thread::join() + 36
41+
3 multithread-test 0x100ec5b3c main + 160 (multithread-test.cpp:31)
42+
4 dyld 0x2230f8da8 start + 2376
43+
44+
Thread 1:
45+
0 libsystem_kernel.dylib 0x19cc42c9c __write_nocancel + 8
46+
1 libsystem_c.dylib 0x19cb719a8 __swrite + 24
47+
2 libsystem_c.dylib 0x19cb50ac8 _swrite + 108
48+
3 libsystem_c.dylib 0x19cb4ec2c __sflush + 232
49+
4 libsystem_c.dylib 0x19cb42f20 __sfvwrite + 792
50+
5 libsystem_c.dylib 0x19cb61f64 fwrite + 152
51+
6 libc++.1.dylib 0x19cbed084 std::__1::__stdoutbuf<char>::overflow(int) + 96
52+
7 libc++.1.dylib 0x19cbe06b4 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >::operator=(char) + 96
53+
8 libc++.1.dylib 0x19cbe0798 std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char) + 200
54+
9 multithread-test 0x100ec5a54 std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) + 64 (ostream:994)
55+
10 multithread-test 0x100ec5a08 std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >& (*)(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)) + 32 (ostream:189)
56+
11 multithread-test 0x100ec5958 call_and_wait(int&) + 48 (multithread-test.cpp:14)
57+
12 multithread-test 0x100ec7684 decltype(static_cast<void (*>(fp)(static_cast<std::__1::reference_wrapper<int>>(fp0))) std::__1::__invoke<void (*)(int&), std::__1::reference_wrapper<int> >(void (*&&)(int&), std::__1::reference_wrapper<int>&&) + 48 (type_traits:3918)
58+
13 multithread-test 0x100ec7608 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(int&), std::__1::reference_wrapper<int>, 2ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(int&), std::__1::reference_wrapper<int> >&, std::__1::__tuple_indices<2ul>) + 56 (thread:287)
59+
14 multithread-test 0x100ec6d58 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(int&), std::__1::reference_wrapper<int> > >(void*) + 84 (thread:298)
60+
15 libsystem_pthread.dylib 0x19cc7e06c _pthread_start + 148
61+
16 libsystem_pthread.dylib 0x19cc78e2c thread_start + 8
62+
63+
Thread 2 Crashed:
64+
0 multithread-test 0x100ec58f4 bar(int) + 20 (multithread-test.cpp:7)
65+
1 multithread-test 0x100ec591c foo(int) + 24 (multithread-test.cpp:11)
66+
2 multithread-test 0x100ec5a88 compute_pow(int&) + 28 (multithread-test.cpp:20)
67+
3 multithread-test 0x100ec7684 decltype(static_cast<void (*>(fp)(static_cast<std::__1::reference_wrapper<int>>(fp0))) std::__1::__invoke<void (*)(int&), std::__1::reference_wrapper<int> >(void (*&&)(int&), std::__1::reference_wrapper<int>&&) + 48 (type_traits:3918)
68+
4 multithread-test 0x100ec7608 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(int&), std::__1::reference_wrapper<int>, 2ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(int&), std::__1::reference_wrapper<int> >&, std::__1::__tuple_indices<2ul>) + 56 (thread:287)
69+
5 multithread-test 0x100ec6d58 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(int&), std::__1::reference_wrapper<int> > >(void*) + 84 (thread:298)
70+
6 libsystem_pthread.dylib 0x19cc7e06c _pthread_start + 148
71+
7 libsystem_pthread.dylib 0x19cc78e2c thread_start + 8
72+
73+
74+
Thread 2 crashed with ARM Thread State (64-bit):
75+
x0: 0x000000000000002a x1: 0x0000600001d291b0 x2: 0x000000019cbbf000 x3: 0x0000000000000000
76+
x4: 0x00000000000030a0 x5: 0x00000000190008ff x6: 0x0000000000000000 x7: 0x0000000000000000
77+
x8: 0x0000000000000001 x9: 0x0000000000000000 x10: 0xfffffffe634277cf x11: 0x0000010000000102
78+
x12: 0x0000010000000102 x13: 0x0000010000000100 x14: 0x0000010000000000 x15: 0x0000000000000001
79+
x16: 0x000000019cc78ea8 x17: 0x00000001fd0a7698 x18: 0x0000000000000000 x19: 0x000000016f04f000
80+
x20: 0x0000000000000000 x21: 0x0000000000000000 x22: 0x0000000000000000 x23: 0x0000000000000000
81+
x24: 0x0000000000000000 x25: 0x0000000000000000 x26: 0x0000000000000000 x27: 0x0000000000000000
82+
x28: 0x0000000000000000 fp: 0x000000016f04ef00 lr: 0x0000000100ec591c
83+
sp: 0x000000016f04eee0 pc: 0x0000000100ec58f4 cpsr: 0x80001000
84+
far: 0x0000000000000000 esr: 0x92000046 (Data Abort) byte write Translation fault
85+
86+
Binary Images:
87+
0x19cc3e000 - 0x19cc76feb libsystem_kernel.dylib (*) <b8898079-5424-3e89-92b0-33022c3be1bb> /usr/lib/system/libsystem_kernel.dylib
88+
0x19cc77000 - 0x19cc83ffb libsystem_pthread.dylib (*) <ffd36328-45f2-31c5-9240-9f76f26a1a2b> /usr/lib/system/libsystem_pthread.dylib
89+
0x19cbbf000 - 0x19cc25ff3 libc++.1.dylib (*) <da619b87-2723-3731-919a-bb3467eab9e1> /usr/lib/libc++.1.dylib
90+
0x100ec4000 - 0x100ec7fff multithread-test (*) <ab9b94f9-6cdf-3b8e-b140-fae3cb13d327> /Users/USER/*/multithread-test
91+
0x2230f3000 - 0x22317be4b dyld (*) <e81312a0-f3e5-3c60-8c25-4599b62b8b4a> /usr/lib/dyld
92+
0x19cb3e000 - 0x19cbbefff libsystem_c.dylib (*) <b8f1c3ed-9048-34a6-8070-6c18d4ade541> /usr/lib/system/libsystem_c.dylib
93+
0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
94+
0x3039 - 0x3420 bogus.dylib (*) <11111111-2222-3333-4444-555555555555> /usr/lib/system/bogus.dylib
95+
96+
External Modification Summary:
97+
Calls made by other processes targeting this process:
98+
task_for_pid: 0
99+
thread_create: 0
100+
thread_set_state: 0
101+
Calls made by this process:
102+
task_for_pid: 0
103+
thread_create: 0
104+
thread_set_state: 0
105+
Calls made by all processes on this machine:
106+
task_for_pid: 23
107+
thread_create: 0
108+
thread_set_state: 812
109+
110+
VM Region Summary:
111+
ReadOnly portion of Libraries: Total=762.9M resident=0K(0%) swapped_out_or_unallocated=762.9M(100%)
112+
Writable regions: Total=538.2M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=538.2M(100%)
113+
114+
VIRTUAL REGION
115+
REGION TYPE SIZE COUNT (non-coalesced)
116+
=========== ======= =======
117+
Kernel Alloc Once 32K 1
118+
MALLOC 145.2M 12
119+
MALLOC guard page 96K 5
120+
MALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated)
121+
STACK GUARD 56.0M 3
122+
Stack 9264K 3
123+
__AUTH 46K 11
124+
__AUTH_CONST 70K 38
125+
__DATA 169K 36
126+
__DATA_CONST 187K 40
127+
__DATA_DIRTY 78K 22
128+
__LINKEDIT 758.0M 2
129+
__OBJC_CONST 11K 5
130+
__OBJC_RO 64.7M 1
131+
__OBJC_RW 1971K 1
132+
__TEXT 5076K 42
133+
dyld private memory 256K 1
134+
shared memory 64K 3
135+
=========== ======= =======
136+
TOTAL 1.4G 227
137+
TOTAL, minus reserved VM space 1.0G 227
138+
139+
140+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# REQUIRES: python, native && target-aarch64 && 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 -i -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.crash' \
7+
# RUN: -o "thread list" -o "bt all" 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 = 0x0000, 0x000000019cc40b84{{.*}}
25+
# CHECK-NEXT: thread #2: tid = 0x0001, 0x000000019cc42c9c{{.*}}
26+
# CHECK-NEXT: * thread #3: tid = 0x0002, 0x0000000100ec58f4 multithread-test`bar{{.*}}, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
27+
28+
# CHECK: (lldb) bt all
29+
# CHECK: thread #1
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]

0 commit comments

Comments
 (0)