diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -923,7 +923,7 @@ pass def __call__(self, debugger, command, exe_ctx, result): - SymbolicateCrashLogs(debugger, shlex.split(command)) + SymbolicateCrashLogs(debugger, shlex.split(command), result) def get_short_help(self): return "Symbolicate one or more darwin crash log files." @@ -1008,12 +1008,15 @@ for error in crash_log.errors: print(error) -def load_crashlog_in_scripted_process(debugger, crash_log_file, options): - result = lldb.SBCommandReturnObject() +def load_crashlog_in_scripted_process(debugger, crash_log_file, options, result): + def error(message, sb_error=lldb.SBError()): + nonlocal result + result.SetError(sb_error, "error: %s" % message) + return crashlog_path = os.path.expanduser(crash_log_file) if not os.path.exists(crashlog_path): - result.PutCString("error: crashlog file %s does not exist" % crashlog_path) + return error("crashlog file %s does not exist" % crashlog_path) crashlog = CrashLogParser().parse(debugger, crashlog_path, False) @@ -1029,19 +1032,15 @@ target = debugger.GetTargetAtIndex(0) # 4. Fail if target is None or not target.IsValid(): - result.PutCString("error: couldn't create target") - return + return error("couldn't create target") ci = debugger.GetCommandInterpreter() if not ci: - result.PutCString("error: couldn't get command interpreter") - return + return error("couldn't get command interpreter") - res = lldb.SBCommandReturnObject() - ci.HandleCommand('script from lldb.macosx import crashlog_scripted_process', res) - if not res.Succeeded(): - result.PutCString("error: couldn't import crashlog scripted process module") - return + ci.HandleCommand('script from lldb.macosx import crashlog_scripted_process', result) + if not result.Succeeded(): + return error("couldn't import crashlog scripted process module") structured_data = lldb.SBStructuredData() structured_data.SetFromJSON(json.dumps({ "crashlog_path" : crashlog_path, @@ -1050,11 +1049,11 @@ launch_info.SetProcessPluginName("ScriptedProcess") launch_info.SetScriptedProcessClassName("crashlog_scripted_process.CrashLogScriptedProcess") launch_info.SetScriptedProcessDictionary(structured_data) - error = lldb.SBError() - process = target.Launch(launch_info, error) + sb_error = lldb.SBError() + process = target.Launch(launch_info, sb_error) - if not process or error.Fail(): - return + if not process or sb_error.Fail(): + return error("couldn't launch Scripted Process", sb_error) @contextlib.contextmanager def synchronous(debugger): @@ -1209,7 +1208,7 @@ be disassembled and lookups can be performed using the addresses found in the crash log.''' return CreateSymbolicateCrashLogOptions('crashlog', description, True) -def SymbolicateCrashLogs(debugger, command_args): +def SymbolicateCrashLogs(debugger, command_args, result): option_parser = CrashLogOptionParser() if not len(command_args): @@ -1247,15 +1246,16 @@ for crash_log_file in args: if should_run_in_interactive_mode(options, ci): load_crashlog_in_scripted_process(debugger, crash_log_file, - options) + options, result) else: crash_log = CrashLogParser().parse(debugger, crash_log_file, options.verbose) - SymbolicateCrashLog(crash_log, options) + SymbolicateCrashLog(crash_log, options, result) if __name__ == '__main__': # Create a new debugger instance debugger = lldb.SBDebugger.Create() - SymbolicateCrashLogs(debugger, sys.argv[1:]) + result = lldb.SBCommandReturnObject() + SymbolicateCrashLogs(debugger, sys.argv[1:], result) lldb.SBDebugger.Destroy(debugger) def __lldb_init_module(debugger, internal_dict):