Skip to content

Commit fcc3d3e

Browse files
committed
[lldb/crashlog] Refactor CrashLogParser into a Factory pattern
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 `create` static method. rdar://100527640 Differential Revision: https://reviews.llvm.org/D139951 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 77f22d7 commit fcc3d3e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lldb/examples/python/crashlog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,15 @@ class InteractiveCrashLogException(Exception):
417417
pass
418418

419419
class CrashLogParser:
420-
"CrashLog parser base class and factory."
421-
def __new__(cls, debugger, path, verbose):
420+
@staticmethod
421+
def create(debugger, path, verbose):
422422
data = JSONCrashLogParser.is_valid_json(path)
423423
if data:
424-
self = object.__new__(JSONCrashLogParser)
425-
self.data = data
426-
return self
424+
parser = JSONCrashLogParser(debugger, path, verbose)
425+
parser.data = data
426+
return parser
427427
else:
428-
return object.__new__(TextCrashLogParser)
428+
return TextCrashLogParser(debugger, path, verbose)
429429

430430
def __init__(self, debugger, path, verbose):
431431
self.path = os.path.expanduser(path)
@@ -1076,7 +1076,7 @@ def load_crashlog_in_scripted_process(debugger, crash_log_file, options, result)
10761076
if not os.path.exists(crashlog_path):
10771077
raise InteractiveCrashLogException("crashlog file %s does not exist" % crashlog_path)
10781078

1079-
crashlog = CrashLogParser(debugger, crashlog_path, False).parse()
1079+
crashlog = CrashLogParser.create(debugger, crashlog_path, False).parse()
10801080

10811081
target = lldb.SBTarget()
10821082
# 1. Try to use the user-provided target
@@ -1332,7 +1332,7 @@ def should_run_in_interactive_mode(options, ci):
13321332
except InteractiveCrashLogException as e:
13331333
result.SetError(str(e))
13341334
else:
1335-
crash_log = CrashLogParser(debugger, crash_log_file, options.verbose).parse()
1335+
crash_log = CrashLogParser.create(debugger, crash_log_file, options.verbose).parse()
13361336
SymbolicateCrashLog(crash_log, options)
13371337

13381338
if __name__ == '__main__':

lldb/examples/python/scripted_process/crashlog_scripted_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class CrashLogScriptedProcess(ScriptedProcess):
1212
def parse_crashlog(self):
13-
crashlog_parser = CrashLogParser(self.dbg, self.crashlog_path, False)
13+
crashlog_parser = CrashLogParser.create(self.dbg, self.crashlog_path, False)
1414
crash_log = crashlog_parser.parse()
1515

1616
self.pid = crash_log.process_id

0 commit comments

Comments
 (0)