Skip to content

Commit

Permalink
[lldb/crashlog] Remove tempfile prefix from inlined symbol object file
Browse files Browse the repository at this point in the history
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 <ismail@bennani.ma>
  • Loading branch information
medismailben committed May 22, 2023
1 parent 273a2d3 commit abba5de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
14 changes: 10 additions & 4 deletions lldb/examples/python/crashlog.py
Expand Up @@ -40,6 +40,7 @@
import string
import subprocess
import sys
import tempfile
import threading
import time
import uuid
Expand Down Expand Up @@ -1154,12 +1155,17 @@ def SymbolicateCrashLog(crash_log, options):
futures = []
loaded_images = []
with concurrent.futures.ThreadPoolExecutor() as executor:
def add_module(image, target):
return image, image.add_module(target)
with tempfile.TemporaryDirectory() as obj_dir:

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

for image in crash_log.images:
futures.append(
executor.submit(
add_module, image=image, target=target, obj_dir=obj_dir
)
)
for future in concurrent.futures.as_completed(futures):
image, err = future.result()
if err:
Expand Down
23 changes: 12 additions & 11 deletions lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -1,4 +1,4 @@
import os,json,struct,signal,uuid
import os, json, struct, signal, uuid, tempfile

from typing import Any, Dict

Expand Down Expand Up @@ -38,16 +38,17 @@ def set_crashlog(self, crashlog):
for image in self.crashlog.find_images_with_identifier(ident):
image.resolve = True

for image in self.crashlog.images:
if image not in self.loaded_images:
if image.uuid == uuid.UUID(int=0):
continue
err = image.add_module(self.target)
if err:
# Append to SBCommandReturnObject
print(err)
else:
self.loaded_images.append(image)
with tempfile.TemporaryDirectory() as obj_dir:
for image in self.crashlog.images:
if image not in self.loaded_images:
if image.uuid == uuid.UUID(int=0):
continue
err = image.add_module(self.target, obj_dir)
if err:
# Append to SBCommandReturnObject
print(err)
else:
self.loaded_images.append(image)

for thread in self.crashlog.threads:
if hasattr(thread, 'app_specific_backtrace') and thread.app_specific_backtrace:
Expand Down
9 changes: 5 additions & 4 deletions lldb/examples/python/symbolication.py
Expand Up @@ -368,7 +368,7 @@ def load_module(self, target):
else:
return 'error: no section infos'

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

0 comments on commit abba5de

Please sign in to comment.