Skip to content

Commit 6c9f3fe

Browse files
committed
[crashlog] Turn crash log parsing modes into a Python 'enum' (NFC)
Python doesn't support enums before PEP 435, but using a class with constants is how it's commonly emulated. It can be converted into a real Enum (in Python 3.4 and later) by extending the Enum class: class CrashLogParseMode(Enum): NORMAL = 0 THREAD = 1 IMAGES = 2 THREGS = 3 SYSTEM = 4 INSTRS = 5
1 parent d14e518 commit 6c9f3fe

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lldb/examples/python/crashlog.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def read_plist(s):
7272
else:
7373
return plistlib.readPlistFromString(s)
7474

75-
76-
PARSE_MODE_NORMAL = 0
77-
PARSE_MODE_THREAD = 1
78-
PARSE_MODE_IMAGES = 2
79-
PARSE_MODE_THREGS = 3
80-
PARSE_MODE_SYSTEM = 4
81-
PARSE_MODE_INSTRS = 5
75+
class CrashLogParseMode:
76+
NORMAL = 0
77+
THREAD = 1
78+
IMAGES = 2
79+
THREGS = 3
80+
SYSTEM = 4
81+
INSTRS = 5
8282

8383

8484
class CrashLog(symbolication.Symbolicator):
@@ -369,15 +369,15 @@ def __init__(self, path, verbose):
369369
return
370370

371371
self.file_lines = f.read().splitlines()
372-
parse_mode = PARSE_MODE_NORMAL
372+
parse_mode = CrashLogParseMode.NORMAL
373373
thread = None
374374
app_specific_backtrace = False
375375
for line in self.file_lines:
376376
# print line
377377
line_len = len(line)
378378
if line_len == 0:
379379
if thread:
380-
if parse_mode == PARSE_MODE_THREAD:
380+
if parse_mode == CrashLogParseMode.THREAD:
381381
if thread.index == self.crashed_thread_idx:
382382
thread.reason = ''
383383
if self.thread_exception:
@@ -394,9 +394,9 @@ def __init__(self, path, verbose):
394394
# in the info_lines wasn't empty
395395
if len(self.info_lines) > 0 and len(self.info_lines[-1]):
396396
self.info_lines.append(line)
397-
parse_mode = PARSE_MODE_NORMAL
398-
# print 'PARSE_MODE_NORMAL'
399-
elif parse_mode == PARSE_MODE_NORMAL:
397+
parse_mode = CrashLogParseMode.NORMAL
398+
# print 'CrashLogParseMode.NORMAL'
399+
elif parse_mode == CrashLogParseMode.NORMAL:
400400
if line.startswith('Process:'):
401401
(self.process_name, pid_with_brackets) = line[
402402
8:].strip().split(' [')
@@ -439,7 +439,7 @@ def __init__(self, path, verbose):
439439
self.version = int(line[15:].strip())
440440
continue
441441
elif line.startswith('System Profile:'):
442-
parse_mode = PARSE_MODE_SYSTEM
442+
parse_mode = CrashLogParseMode.SYSTEM
443443
continue
444444
elif (line.startswith('Interval Since Last Report:') or
445445
line.startswith('Crashes Since Last Report:') or
@@ -455,38 +455,38 @@ def __init__(self, path, verbose):
455455
app_specific_backtrace = False
456456
thread_state_match = self.thread_regex.search(line)
457457
thread_idx = int(thread_state_match.group(1))
458-
parse_mode = PARSE_MODE_THREGS
458+
parse_mode = CrashLogParseMode.THREGS
459459
thread = self.threads[thread_idx]
460460
continue
461461
thread_insts_match = self.thread_instrs_regex.search(line)
462462
if thread_insts_match:
463-
parse_mode = PARSE_MODE_INSTRS
463+
parse_mode = CrashLogParseMode.INSTRS
464464
continue
465465
thread_match = self.thread_regex.search(line)
466466
if thread_match:
467467
app_specific_backtrace = False
468-
parse_mode = PARSE_MODE_THREAD
468+
parse_mode = CrashLogParseMode.THREAD
469469
thread_idx = int(thread_match.group(1))
470470
thread = CrashLog.Thread(thread_idx, False)
471471
continue
472472
continue
473473
elif line.startswith('Binary Images:'):
474-
parse_mode = PARSE_MODE_IMAGES
474+
parse_mode = CrashLogParseMode.IMAGES
475475
continue
476476
elif line.startswith('Application Specific Backtrace'):
477477
app_backtrace_match = self.app_backtrace_regex.search(line)
478478
if app_backtrace_match:
479-
parse_mode = PARSE_MODE_THREAD
479+
parse_mode = CrashLogParseMode.THREAD
480480
app_specific_backtrace = True
481481
idx = int(app_backtrace_match.group(1))
482482
thread = CrashLog.Thread(idx, True)
483483
elif line.startswith('Last Exception Backtrace:'): # iOS
484-
parse_mode = PARSE_MODE_THREAD
484+
parse_mode = CrashLogParseMode.THREAD
485485
app_specific_backtrace = True
486486
idx = 1
487487
thread = CrashLog.Thread(idx, True)
488488
self.info_lines.append(line.strip())
489-
elif parse_mode == PARSE_MODE_THREAD:
489+
elif parse_mode == CrashLogParseMode.THREAD:
490490
if line.startswith('Thread'):
491491
continue
492492
if self.null_frame_regex.search(line):
@@ -504,7 +504,7 @@ def __init__(self, path, verbose):
504504
frame_addr, 0), frame_ofs))
505505
else:
506506
print('error: frame regex failed for line: "%s"' % line)
507-
elif parse_mode == PARSE_MODE_IMAGES:
507+
elif parse_mode == CrashLogParseMode.IMAGES:
508508
image_match = self.image_regex_uuid.search(line)
509509
if image_match:
510510
(img_lo, img_hi, img_name, _, img_version, _,
@@ -519,7 +519,7 @@ def __init__(self, path, verbose):
519519
else:
520520
print("error: image regex failed for: %s" % line)
521521

522-
elif parse_mode == PARSE_MODE_THREGS:
522+
elif parse_mode == CrashLogParseMode.THREGS:
523523
stripped_line = line.strip()
524524
# "r12: 0x00007fff6b5939c8 r13: 0x0000000007000006 r14: 0x0000000000002a03 r15: 0x0000000000000c00"
525525
reg_values = re.findall(
@@ -530,9 +530,9 @@ def __init__(self, path, verbose):
530530
# print 'reg = "%s"' % reg
531531
# print 'value = "%s"' % value
532532
thread.registers[reg.strip()] = int(value, 0)
533-
elif parse_mode == PARSE_MODE_SYSTEM:
533+
elif parse_mode == CrashLogParseMode.SYSTEM:
534534
self.system_profile.append(line)
535-
elif parse_mode == PARSE_MODE_INSTRS:
535+
elif parse_mode == CrashLogParseMode.INSTRS:
536536
pass
537537
f.close()
538538

0 commit comments

Comments
 (0)