Skip to content

Commit 94a0014

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 c80b051 commit 94a0014

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

lldb/examples/python/crashlog.py

Lines changed: 10 additions & 5 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
@@ -1243,13 +1244,17 @@ def SymbolicateCrashLog(crash_log, options):
12431244
futures = []
12441245
loaded_images = []
12451246
with concurrent.futures.ThreadPoolExecutor() as executor:
1247+
with tempfile.TemporaryDirectory() as obj_dir:
12461248

1247-
def add_module(image, target):
1248-
return image, image.add_module(target)
1249-
1250-
for image in crash_log.images:
1251-
futures.append(executor.submit(add_module, image=image, target=target))
1249+
def add_module(image, target, obj_dir):
1250+
return image, image.add_module(target, obj_dir)
12521251

1252+
for image in crash_log.images:
1253+
futures.append(
1254+
executor.submit(
1255+
add_module, image=image, target=target, obj_dir=obj_dir
1256+
)
1257+
)
12531258
for future in concurrent.futures.as_completed(futures):
12541259
image, err = future.result()
12551260
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: 11 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,15 @@ 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)
433432
if self.module:
434433
# If we were able to add the module with inlined
435434
# symbols, we should mark it as available so load_module

0 commit comments

Comments
 (0)