[Lldb-commits] [lldb] 343662a - [crashlog] Change heuristic to stripping the meta data from crashlogs

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 14 12:18:18 PST 2022


Author: Jonas Devlieghere
Date: 2022-02-14T12:18:12-08:00
New Revision: 343662a0287845eceba068df6ce59eddcbe7beb1

URL: https://github.com/llvm/llvm-project/commit/343662a0287845eceba068df6ce59eddcbe7beb1
DIFF: https://github.com/llvm/llvm-project/commit/343662a0287845eceba068df6ce59eddcbe7beb1.diff

LOG: [crashlog] Change heuristic to stripping the meta data from crashlogs

Instead trying to pro-actively determine if the first line in a
crashlog contains meta data, change the heuristic to do the following:

 1. To trying to parse the whole file. If that fails, then:
 2. Strip the first line and try parsing the remainder of the file. If
    that fails, then:
 3. Fall back to the textual crashlog parser.

rdar://88580543

Differential revision: https://reviews.llvm.org/D119755

Added: 
    

Modified: 
    lldb/examples/python/crashlog.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index ec9f2d4e92db..63be06662562 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -397,7 +397,7 @@ class CrashLogFormatException(Exception):
 
 
 class CrashLogParseException(Exception):
-   pass
+    pass
 
 
 class CrashLogParser:
@@ -414,22 +414,22 @@ def __init__(self, debugger, path, verbose):
         self.verbose = verbose
         self.crashlog = CrashLog(debugger, self.path, self.verbose)
 
+    def parse_json(self, buffer):
+        try:
+            return json.loads(buffer)
+        except:
+            # The first line can contain meta data. Try stripping it and try
+            # again.
+            head, _, tail = buffer.partition('\n')
+            return json.loads(tail)
+
     def parse(self):
         with open(self.path, 'r') as f:
             buffer = f.read()
 
-        # Skip the first line if it contains meta data.
-        head, _, tail = buffer.partition('\n')
         try:
-            metadata = json.loads(head)
-            if 'app_name' in metadata and 'app_version' in metadata:
-                buffer = tail
-        except ValueError:
-            pass
-
-        try:
-            self.data = json.loads(buffer)
-        except ValueError:
+            self.data = self.parse_json(buffer)
+        except:
             raise CrashLogFormatException()
 
         try:


        


More information about the lldb-commits mailing list