mib updated this revision to Diff 449847. mib added a comment. Address @JDevlieghere comments
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131085/new/ https://reviews.llvm.org/D131085 Files: lldb/examples/python/crashlog.py lldb/examples/python/scripted_process/crashlog_scripted_process.py
Index: lldb/examples/python/scripted_process/crashlog_scripted_process.py =================================================================== --- lldb/examples/python/scripted_process/crashlog_scripted_process.py +++ lldb/examples/python/scripted_process/crashlog_scripted_process.py @@ -10,10 +10,8 @@ class CrashLogScriptedProcess(ScriptedProcess): def parse_crashlog(self): - try: - crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, False) - except Exception as e: - raise e + crashlog_parser = CrashLogParser(self.dbg, self.crashlog_path, False) + crash_log = crashlog_parser.parse() self.pid = crash_log.process_id self.addr_mask = crash_log.addr_mask Index: lldb/examples/python/crashlog.py =================================================================== --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -26,6 +26,7 @@ # PYTHONPATH=/path/to/LLDB.framework/Resources/Python ./crashlog.py ~/Library/Logs/DiagnosticReports/a.crash #---------------------------------------------------------------------- +import abc import concurrent.futures import contextlib import datetime @@ -414,20 +415,28 @@ class InteractiveCrashLogException(Exception): pass -class CrashLogParser: - def parse(self, debugger, path, verbose): +class CrashLogParser(object): + "CrashLog parser base class and factory." + def __new__(cls, debugger, path, verbose, *args, **kwargs): try: - return JSONCrashLogParser(debugger, path, verbose).parse() + return super(CrashLogParser, cls).__new__(JSONCrashLogParser, *args, **kwargs) except CrashLogFormatException: - return TextCrashLogParser(debugger, path, verbose).parse() + return super(CrashLogParser, cls).__new__(TextCrashLogParser, *args, **kwargs) - -class JSONCrashLogParser: def __init__(self, debugger, path, verbose): self.path = os.path.expanduser(path) self.verbose = verbose self.crashlog = CrashLog(debugger, self.path, self.verbose) + @abc.abstractmethod + def parse(self): + pass + + +class JSONCrashLogParser(CrashLogParser): + def __init__(self, debugger, path, verbose): + super().__init__(debugger, path, verbose) + def parse_json(self, buffer): try: return json.loads(buffer) @@ -592,7 +601,7 @@ INSTRS = 5 -class TextCrashLogParser: +class TextCrashLogParser(CrashLogParser): parent_process_regex = re.compile('^Parent Process:\s*(.*)\[(\d+)\]') thread_state_regex = re.compile('^Thread ([0-9]+) crashed with') thread_instrs_regex = re.compile('^Thread ([0-9]+) instruction stream') @@ -617,11 +626,9 @@ def __init__(self, debugger, path, verbose): - self.path = os.path.expanduser(path) - self.verbose = verbose + super().__init__(debugger, path, verbose) self.thread = None self.app_specific_backtrace = False - self.crashlog = CrashLog(debugger, self.path, self.verbose) self.parse_mode = CrashLogParseMode.NORMAL self.parsers = { CrashLogParseMode.NORMAL : self.parse_normal, @@ -1012,7 +1019,7 @@ if not os.path.exists(crashlog_path): raise InteractiveCrashLogException("crashlog file %s does not exist" % crashlog_path) - crashlog = CrashLogParser().parse(debugger, crashlog_path, False) + crashlog = CrashLogParser(debugger, crashlog_path, False).parse() target = lldb.SBTarget() # 1. Try to use the user-provided target @@ -1257,7 +1264,7 @@ except InteractiveCrashLogException as e: result.SetError(str(e)) else: - crash_log = CrashLogParser().parse(debugger, crash_log_file, options.verbose) + crash_log = CrashLogParser(debugger, crash_log_file, options.verbose).parse() SymbolicateCrashLog(crash_log, options) if __name__ == '__main__':
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits