Skip to content

Commit 343662a

Browse files
committed
[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
1 parent d52866e commit 343662a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lldb/examples/python/crashlog.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class CrashLogFormatException(Exception):
397397

398398

399399
class CrashLogParseException(Exception):
400-
pass
400+
pass
401401

402402

403403
class CrashLogParser:
@@ -414,22 +414,22 @@ def __init__(self, debugger, path, verbose):
414414
self.verbose = verbose
415415
self.crashlog = CrashLog(debugger, self.path, self.verbose)
416416

417+
def parse_json(self, buffer):
418+
try:
419+
return json.loads(buffer)
420+
except:
421+
# The first line can contain meta data. Try stripping it and try
422+
# again.
423+
head, _, tail = buffer.partition('\n')
424+
return json.loads(tail)
425+
417426
def parse(self):
418427
with open(self.path, 'r') as f:
419428
buffer = f.read()
420429

421-
# Skip the first line if it contains meta data.
422-
head, _, tail = buffer.partition('\n')
423430
try:
424-
metadata = json.loads(head)
425-
if 'app_name' in metadata and 'app_version' in metadata:
426-
buffer = tail
427-
except ValueError:
428-
pass
429-
430-
try:
431-
self.data = json.loads(buffer)
432-
except ValueError:
431+
self.data = self.parse_json(buffer)
432+
except:
433433
raise CrashLogFormatException()
434434

435435
try:

0 commit comments

Comments
 (0)