mib created this revision. mib added reviewers: JDevlieghere, kastiglione. mib added a project: LLDB. Herald added a project: All. mib requested review of this revision. Herald added a subscriber: lldb-commits.
This patch should fix an undefined behaviour that's happening when parsing a crash report from an IDE. In the previous implementation, the CrashLogParser base class would use the `__new__` static class method to create the right parser instance depending on the crash report type. For some reasons, the derived parser initializer wouldn't be called when running the command from an IDE, so this patch refactors the CrashLogParser code to replace the use of the `__new__` method with a factory method. rdar://100527640 Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D139951 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 @@ -6,11 +6,11 @@ from lldb.plugins.scripted_process import ScriptedProcess from lldb.plugins.scripted_process import ScriptedThread -from lldb.macosx.crashlog import CrashLog,CrashLogParser +from lldb.macosx.crashlog import CrashLog,CrashLogParserFactory class CrashLogScriptedProcess(ScriptedProcess): def parse_crashlog(self): - crashlog_parser = CrashLogParser(self.dbg, self.crashlog_path, False) + crashlog_parser = CrashLogParserFactory(self.dbg, self.crashlog_path, False) crash_log = crashlog_parser.parse() self.pid = crash_log.process_id Index: lldb/examples/python/crashlog.py =================================================================== --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -416,17 +416,16 @@ class InteractiveCrashLogException(Exception): pass -class CrashLogParser: - "CrashLog parser base class and factory." - def __new__(cls, debugger, path, verbose): - data = JSONCrashLogParser.is_valid_json(path) - if data: - self = object.__new__(JSONCrashLogParser) - self.data = data - return self - else: - return object.__new__(TextCrashLogParser) +def CrashLogParserFactory(debugger, path, verbose): + data = JSONCrashLogParser.is_valid_json(path) + if data: + parser = JSONCrashLogParser(debugger, path, verbose) + parser.data = data + return parser + else: + return TextCrashLogParser(debugger, path, verbose) +class CrashLogParser: def __init__(self, debugger, path, verbose): self.path = os.path.expanduser(path) self.verbose = verbose @@ -1076,7 +1075,7 @@ if not os.path.exists(crashlog_path): raise InteractiveCrashLogException("crashlog file %s does not exist" % crashlog_path) - crashlog = CrashLogParser(debugger, crashlog_path, False).parse() + crashlog = CrashLogParserFactory(debugger, crashlog_path, False).parse() target = lldb.SBTarget() # 1. Try to use the user-provided target @@ -1332,7 +1331,7 @@ except InteractiveCrashLogException as e: result.SetError(str(e)) else: - crash_log = CrashLogParser(debugger, crash_log_file, options.verbose).parse() + crash_log = CrashLogParserFactory(debugger, crash_log_file, options.verbose).parse() SymbolicateCrashLog(crash_log, options) if __name__ == '__main__':
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 @@ -6,11 +6,11 @@ from lldb.plugins.scripted_process import ScriptedProcess from lldb.plugins.scripted_process import ScriptedThread -from lldb.macosx.crashlog import CrashLog,CrashLogParser +from lldb.macosx.crashlog import CrashLog,CrashLogParserFactory class CrashLogScriptedProcess(ScriptedProcess): def parse_crashlog(self): - crashlog_parser = CrashLogParser(self.dbg, self.crashlog_path, False) + crashlog_parser = CrashLogParserFactory(self.dbg, self.crashlog_path, False) crash_log = crashlog_parser.parse() self.pid = crash_log.process_id Index: lldb/examples/python/crashlog.py =================================================================== --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -416,17 +416,16 @@ class InteractiveCrashLogException(Exception): pass -class CrashLogParser: - "CrashLog parser base class and factory." - def __new__(cls, debugger, path, verbose): - data = JSONCrashLogParser.is_valid_json(path) - if data: - self = object.__new__(JSONCrashLogParser) - self.data = data - return self - else: - return object.__new__(TextCrashLogParser) +def CrashLogParserFactory(debugger, path, verbose): + data = JSONCrashLogParser.is_valid_json(path) + if data: + parser = JSONCrashLogParser(debugger, path, verbose) + parser.data = data + return parser + else: + return TextCrashLogParser(debugger, path, verbose) +class CrashLogParser: def __init__(self, debugger, path, verbose): self.path = os.path.expanduser(path) self.verbose = verbose @@ -1076,7 +1075,7 @@ if not os.path.exists(crashlog_path): raise InteractiveCrashLogException("crashlog file %s does not exist" % crashlog_path) - crashlog = CrashLogParser(debugger, crashlog_path, False).parse() + crashlog = CrashLogParserFactory(debugger, crashlog_path, False).parse() target = lldb.SBTarget() # 1. Try to use the user-provided target @@ -1332,7 +1331,7 @@ except InteractiveCrashLogException as e: result.SetError(str(e)) else: - crash_log = CrashLogParser(debugger, crash_log_file, options.verbose).parse() + crash_log = CrashLogParserFactory(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