JDevlieghere created this revision.
JDevlieghere added a reviewer: mib.
JDevlieghere requested review of this revision.
Instead of pro-actively trying to determine if the first line in a crashlog
contains meta data, change the heuristic to trying to parse the whole file
first. If that fails, strip the first line and try again. If that fails again,
we assume the input is not JSON and we fall back to the old textual parser.
rdar://88580543
https://reviews.llvm.org/D119755
Files:
lldb/examples/python/crashlog.py
Index: lldb/examples/python/crashlog.py
===================================================================
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -399,7 +399,7 @@
class CrashLogParseException(Exception):
- pass
+ pass
class CrashLogParser:
@@ -416,22 +416,22 @@
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:
Index: lldb/examples/python/crashlog.py
===================================================================
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -399,7 +399,7 @@
class CrashLogParseException(Exception):
- pass
+ pass
class CrashLogParser:
@@ -416,22 +416,22 @@
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:
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits