Index: lldb/examples/python/crashlog.py =================================================================== --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -340,6 +340,7 @@ self.backtraces = list() # For application specific backtraces self.idents = list() # A list of the required identifiers for doing all stack backtraces self.errors = list() + self.exception = None self.crashed_thread_idx = -1 self.version = -1 self.target = None @@ -483,6 +484,7 @@ self.crashlog.process_identifier = json_data['procName'] def parse_crash_reason(self, json_exception): + self.crashlog.exception = json_exception exception_type = json_exception['type'] exception_signal = " " if 'signal' in json_exception: @@ -601,7 +603,6 @@ SYSTEM = 4 INSTRS = 5 - class TextCrashLogParser(CrashLogParser): parent_process_regex = re.compile(r'^Parent Process:\s*(.*)\[(\d+)\]') thread_state_regex = re.compile(r'^Thread \d+ crashed with') @@ -624,6 +625,9 @@ r'(?:<([-0-9a-fA-F]+)>\s+)?' # img_uuid r'(/.*)' # img_path ) + exception_type_regex = re.compile(r'^Exception Type:\s+(EXC_.*) \s*\((.*)\)') + exception_codes_regex = re.compile(r'^Exception Codes:\s+(0x[\d]+),\s*(0x[\d]+)') + exception_extra_regex = re.compile(r'^Exception\s+.*:\s+(.*)') def __init__(self, debugger, path, verbose): super().__init__(debugger, path, verbose) @@ -670,6 +674,41 @@ return self.crashlog + def parse_exception(self, line): + if not line.startswith('Exception'): + return + if line.startswith('Exception Type:'): + self.crashlog.thread_exception = line[15:].strip() + exception_type_match = self.exception_type_regex.search(line) + if exception_type_match: + (exc_type, exc_signal) = exception_type_match.groups() + self.crashlog.exception = {} + self.crashlog.exception['type'] = exc_type + self.crashlog.exception['signal'] = exc_signal + return + elif line.startswith('Exception Subtype:'): # iOS + self.crashlog.thread_exception_subtype = line[18:].strip() + if self.crashlog.exception['type']: + self.crashlog.exception['subtype']: self.crashlog.thread_exception_subtype + return + elif line.startswith('Exception Codes:'): + self.crashlog.thread_exception_data = line[16:].strip() + exception_codes_match = self.exception_codes_regex.search(line) + if exception_codes_match: + if not self.crashlog.exception['type']: + return + self.crashlog.exception['codes'] = self.crashlog.thread_exception_data + (code, subcode) = exception_codes_match.groups() + self.crashlog.exception['rawcodes'] = [int(code, base=16), + int(subcode, base=16)] + return + else: + exception_extra_match = self.exception_extra_regex.search(line) + if exception_extra_match: + if not self.crashlog.exception['type']: + return + self.crashlog.exception['message'] = exception_extra_match.group(0) + return def parse_normal(self, line): if line.startswith('Process:'): @@ -693,14 +732,8 @@ line) self.crashlog.parent_process_name = parent_process_match.group(1) self.crashlog.parent_process_id = parent_process_match.group(2) - elif line.startswith('Exception Type:'): - self.crashlog.thread_exception = line[15:].strip() - return - elif line.startswith('Exception Codes:'): - self.crashlog.thread_exception_data = line[16:].strip() - return - elif line.startswith('Exception Subtype:'): # iOS - self.crashlog.thread_exception_data = line[18:].strip() + elif line.startswith('Exception'): + self.parse_exception(line) return elif line.startswith('Crashed Thread:'): self.crashlog.crashed_thread_idx = int(line[15:].strip().split()[0])