[Lldb-commits] [PATCH] D131719: [lldb/crashlog] Adapt raw text crashlog exception to json format

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 11 15:06:43 PDT 2022


mib updated this revision to Diff 451998.
mib added a comment.

Change regex to support **actual** hex addresses


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131719/new/

https://reviews.llvm.org/D131719

Files:
  lldb/examples/python/crashlog.py


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[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)')
+    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(1)
+            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])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131719.451998.patch
Type: text/x-patch
Size: 4465 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220811/342e4922/attachment-0001.bin>


More information about the lldb-commits mailing list