Skip to content

Commit abba5de

Browse files
committed
[lldb/crashlog] Remove tempfile prefix from inlined symbol object file
This patch changes the way we generate the ObjectFileJSON files containing the inlined symbols from the crash report to remove the tempfile prefix from the object file name. To do so, instead of creating a new tempfile for each module, we create a temporary directory that contains each module object file with the same name as the module. This makes the backtraces only contain the module name without the temfile prefix which makes it look like a regular stackframe. Differential Revision: https://reviews.llvm.org/D151045 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 273a2d3 commit abba5de

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

lldb/examples/python/crashlog.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import string
4141
import subprocess
4242
import sys
43+
import tempfile
4344
import threading
4445
import time
4546
import uuid
@@ -1154,12 +1155,17 @@ def SymbolicateCrashLog(crash_log, options):
11541155
futures = []
11551156
loaded_images = []
11561157
with concurrent.futures.ThreadPoolExecutor() as executor:
1157-
def add_module(image, target):
1158-
return image, image.add_module(target)
1158+
with tempfile.TemporaryDirectory() as obj_dir:
11591159

1160-
for image in crash_log.images:
1161-
futures.append(executor.submit(add_module, image=image, target=target))
1160+
def add_module(image, target, obj_dir):
1161+
return image, image.add_module(target, obj_dir)
11621162

1163+
for image in crash_log.images:
1164+
futures.append(
1165+
executor.submit(
1166+
add_module, image=image, target=target, obj_dir=obj_dir
1167+
)
1168+
)
11631169
for future in concurrent.futures.as_completed(futures):
11641170
image, err = future.result()
11651171
if err:

lldb/examples/python/scripted_process/crashlog_scripted_process.py

Lines changed: 12 additions & 11 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

@@ -38,16 +38,17 @@ def set_crashlog(self, crashlog):
3838
for image in self.crashlog.find_images_with_identifier(ident):
3939
image.resolve = True
4040

41-
for image in self.crashlog.images:
42-
if image not in self.loaded_images:
43-
if image.uuid == uuid.UUID(int=0):
44-
continue
45-
err = image.add_module(self.target)
46-
if err:
47-
# Append to SBCommandReturnObject
48-
print(err)
49-
else:
50-
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)
5152

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

lldb/examples/python/symbolication.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def load_module(self, target):
368368
else:
369369
return 'error: no section infos'
370370

371-
def add_module(self, target):
371+
def add_module(self, target, obj_dir=None):
372372
'''Add the Image described in this object to "target" and load the sections if "load" is True.'''
373373
if target:
374374
# Try and find using UUID only first so that paths need not match
@@ -384,7 +384,7 @@ def add_module(self, target):
384384
resolved_path, None, uuid_str, self.symfile)
385385
if not self.module and self.section_infos:
386386
name = os.path.basename(self.path)
387-
with tempfile.NamedTemporaryFile(suffix='.' + name) as tf:
387+
if obj_dir and os.path.isdir(obj_dir):
388388
data = {
389389
'triple': target.triple,
390390
'uuid': uuid_str,
@@ -398,9 +398,10 @@ def add_module(self, target):
398398
'size': section.end_addr - section.start_addr
399399
})
400400
data['symbols'] = list(self.symbols.values())
401-
with open(tf.name, 'w') as f:
401+
obj_file = os.path.join(obj_dir, name)
402+
with open(obj_file, "w") as f:
402403
f.write(json.dumps(data, indent=4))
403-
self.module = target.AddModule(tf.name, None, uuid_str)
404+
self.module = target.AddModule(obj_file, None, uuid_str)
404405
if self.module:
405406
# If we were able to add the module with inlined
406407
# symbols, we should mark it as available so load_module

0 commit comments

Comments
 (0)