[Lldb-commits] [lldb] abba5de - [lldb/crashlog] Remove tempfile prefix from inlined symbol object file
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Mon May 22 16:14:45 PDT 2023
Author: Med Ismail Bennani
Date: 2023-05-22T16:14:00-07:00
New Revision: abba5de724665362db707d4cfab598cfbf5a475e
URL: https://github.com/llvm/llvm-project/commit/abba5de724665362db707d4cfab598cfbf5a475e
DIFF: https://github.com/llvm/llvm-project/commit/abba5de724665362db707d4cfab598cfbf5a475e.diff
LOG: [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 <ismail at bennani.ma>
Added:
Modified:
lldb/examples/python/crashlog.py
lldb/examples/python/scripted_process/crashlog_scripted_process.py
lldb/examples/python/symbolication.py
Removed:
################################################################################
diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index d207af10f36f2..7bfa4021f49df 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -40,6 +40,7 @@
import string
import subprocess
import sys
+import tempfile
import threading
import time
import uuid
@@ -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:
diff --git a/lldb/examples/python/scripted_process/crashlog_scripted_process.py b/lldb/examples/python/scripted_process/crashlog_scripted_process.py
index 46b2816032a59..43e307bbe69b5 100644
--- a/lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ b/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
@@ -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:
diff --git a/lldb/examples/python/symbolication.py b/lldb/examples/python/symbolication.py
index 3a42f340ea578..74de7dda8e4a3 100755
--- a/lldb/examples/python/symbolication.py
+++ b/lldb/examples/python/symbolication.py
@@ -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
@@ -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,
@@ -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
More information about the lldb-commits
mailing list