mib created this revision. mib added a reviewer: JDevlieghere. mib added a project: LLDB. Herald added a project: All. mib requested review of this revision. Herald added a subscriber: lldb-commits.
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. Signed-off-by: Med Ismail Bennani <ism...@bennani.ma> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D151045 Files: lldb/examples/python/crashlog.py lldb/examples/python/scripted_process/crashlog_scripted_process.py lldb/examples/python/symbolication.py
Index: lldb/examples/python/symbolication.py =================================================================== --- lldb/examples/python/symbolication.py +++ lldb/examples/python/symbolication.py @@ -368,7 +368,7 @@ else: return 'error: no section infos' - def add_module(self, target): + def add_module(self, target, obj_dir=tempfile.TemporaryDirectory()): '''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 @@ 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 os.path.isdir(obj_dir.name): data = { 'triple': target.triple, 'uuid': uuid_str, @@ -398,9 +398,10 @@ '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, 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 Index: lldb/examples/python/scripted_process/crashlog_scripted_process.py =================================================================== --- lldb/examples/python/scripted_process/crashlog_scripted_process.py +++ 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,17 +38,23 @@ for image in self.crashlog.find_images_with_identifier(ident): image.resolve = True + obj_dir = tempfile.TemporaryDirectory() 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) + err = image.add_module(self.target, obj_dir) if err: # Append to SBCommandReturnObject print(err) else: self.loaded_images.append(image) + if os.path.isdir(obj_dir.name): + for file in os.listdir(obj_dir.name): + os.unlink(os.path.join(obj_dir.name, file)) + os.rmdir(obj_dir.name) + for thread in self.crashlog.threads: if hasattr(thread, 'app_specific_backtrace') and thread.app_specific_backtrace: # We don't want to include the Application Specific Backtrace Index: lldb/examples/python/crashlog.py =================================================================== --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -40,6 +40,7 @@ import string import subprocess import sys +import tempfile import threading import time import uuid @@ -1151,14 +1152,20 @@ for image in self.crashlog.find_images_with_identifier(ident): image.resolve = True + obj_dir = tempfile.TemporaryDirectory() futures = [] loaded_images = [] with concurrent.futures.ThreadPoolExecutor() as executor: - def add_module(image, target): - return image, image.add_module(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)) + futures.append(executor.submit(add_module, image=image, + target=target, obj_dir=obj_dir)) + if os.path.isdir(obj_dir.name): + for file in os.listdir(obj_dir.name): + os.unlink(os.path.join(obj_dir.name, file)) + os.rmdir(obj_dir.name) for future in concurrent.futures.as_completed(futures): image, err = future.result()
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits