import string
import subprocess
import sys
+import tempfile
import threading
import time
import uuid
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:
-import os,json,struct,signal,uuid
+import os, json, struct, signal, uuid, tempfile
from typing import Any, Dict
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:
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
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,
'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