diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -395,6 +395,10 @@ self.version = -1 self.target = None self.verbose = verbose + self.process_id = None + self.process_identifier = None + self.process_path = None + self.process_arch = None def dump(self): print("Crash Log File: %s" % (self.path)) @@ -484,9 +488,9 @@ def __init__(self, debugger, path, verbose): self.path = os.path.expanduser(path) self.verbose = verbose - self.crashlog = CrashLog(debugger, self.path, self.verbose) # List of DarwinImages sorted by their index. self.images = list() + self.crashlog = CrashLog(debugger, self.path, self.verbose) @abc.abstractmethod def parse(self): @@ -547,6 +551,8 @@ def parse_process_info(self, json_data): self.crashlog.process_id = json_data["pid"] self.crashlog.process_identifier = json_data["procName"] + if "procPath" in json_data: + self.crashlog.process_path = json_data["procPath"] def parse_crash_reason(self, json_exception): self.crashlog.exception = json_exception @@ -574,6 +580,10 @@ darwin_image = self.crashlog.DarwinImage( low, high, name, version, img_uuid, path, self.verbose ) + if "arch" in json_image: + darwin_image.arch = json_image["arch"] + if path == self.crashlog.process_path: + self.crashlog.process_arch = darwin_image.arch self.images.append(darwin_image) self.crashlog.images.append(darwin_image) @@ -740,6 +750,13 @@ gpr_dict = {str(idx): reg for idx, reg in enumerate(state)} registers.update(self.parse_thread_registers(gpr_dict, key)) continue + if key == "flavor": + if not self.crashlog.process_arch: + if state == "ARM_THREAD_STATE64": + self.crashlog.process_arch = "arm64" + elif state == "X86_THREAD_STATE": + self.crashlog.process_arch = "x86_64" + continue try: value = int(state["value"]) registers["{}{}".format(prefix or "", key)] = value @@ -912,6 +929,8 @@ line[8:].strip().split(" [") ) self.crashlog.process_id = pid_with_brackets.strip("[]") + elif line.startswith("Path:"): + self.crashlog.process_path = line[5:].strip() elif line.startswith("Identifier:"): self.crashlog.process_identifier = line[11:].strip() elif line.startswith("Version:"): @@ -923,6 +942,11 @@ else: self.crashlog.process = version_string self.crashlog.process_compatability_version = version_string + elif line.startswith("Code Type:"): + if "ARM-64" in line: + self.crashlog.process_arch = "arm64" + elif "X86-64" in line: + self.crashlog.process_arch = "x86_64" elif self.parent_process_regex.search(line): parent_process_match = self.parent_process_regex.search(line) self.crashlog.parent_process_name = parent_process_match.group(1) @@ -1343,9 +1367,12 @@ # 2. If the user didn't provide a target, try to create a target using the symbolicator if not target or not target.IsValid(): target = crashlog.create_target() - # 3. If that didn't work, and a target is already loaded, use it - if (target is None or not target.IsValid()) and debugger.GetNumTargets() > 0: - target = debugger.GetTargetAtIndex(0) + # 3. If that didn't work, create a dummy target + if target is None or not target.IsValid(): + arch = crashlog.process_arch + if not arch: + raise InteractiveCrashLogException("couldn't create find the architecture to create the target") + target = debugger.CreateTargetWithFileAndArch(None, arch) # 4. Fail if target is None or not target.IsValid(): raise InteractiveCrashLogException("couldn't create target") diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2527,7 +2527,7 @@ FileSpec exe_spec_to_use; if (!exe_module) { - if (!launch_info.GetExecutableFile()) { + if (!launch_info.GetExecutableFile() && !launch_info.IsScriptedProcess()) { error.SetErrorString("executable module does not exist"); return error; }