[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
This revision was automatically updated to reflect the committed changes. Closed by commit rGa07a75180c01: [lldb/crashlog] Surface error using SBCommandReturnObject argument (authored by mib). Changed prior to commit: https://reviews.llvm.org/D129614?vs=449784=451346#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 Files: lldb/examples/python/crashlog.py lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test @@ -0,0 +1,8 @@ +# REQUIRES: python, native && target-aarch64 && system-darwin + +# RUN: %lldb -o 'command script import lldb.macosx.crashlog' \ +# RUN: -o 'crashlog -a -i -t /this_file_does_not_exist %S/Inputs/interactive_crashlog/multithread-test.ips' 2>&1 | FileCheck %s + +# CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands + +# CHECK: error: couldn't create target provided by the user (/this_file_does_not_exist) Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp === --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2888,9 +2888,10 @@ if (!ret_val) error.SetErrorString("unable to execute script function"); - else -error.Clear(); + else if (cmd_retobj.GetStatus() == eReturnStatusFailed) +return false; + error.Clear(); return ret_val; } @@ -2932,9 +2933,10 @@ if (!ret_val) error.SetErrorString("unable to execute script function"); - else -error.Clear(); + else if (cmd_retobj.GetStatus() == eReturnStatusFailed) +return false; + error.Clear(); return ret_val; } Index: lldb/examples/python/crashlog.py === --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -411,6 +411,8 @@ class CrashLogParseException(Exception): pass +class InteractiveCrashLogException(Exception): +pass class CrashLogParser: def parse(self, debugger, path, verbose): @@ -923,7 +925,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 +1010,10 @@ 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): 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) +raise InteractiveCrashLogException("crashlog file %s does not exist" % crashlog_path) crashlog = CrashLogParser().parse(debugger, crashlog_path, False) @@ -1022,9 +1022,8 @@ if options.target_path: target = debugger.CreateTarget(options.target_path) if not target: -result.PutCString("error: couldn't create target provided by the \ - user ({})".format(options.target_path)) -return +raise InteractiveCrashLogException("couldn't create target provided by the user (%s)" % options.target_path) + # 2. If the user didn't provide a target, try to create a target using the symbolicator if not target or not target.IsValid(): target = crashlog.create_target() @@ -1033,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 +raise InteractiveCrashLogException("couldn't create target") ci = debugger.GetCommandInterpreter() if not ci: -result.PutCString("error: couldn't get command interpreter") -return +raise InteractiveCrashLogException("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
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
JDevlieghere accepted this revision. JDevlieghere added a comment. This revision is now accepted and ready to land. LGTM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
mib updated this revision to Diff 449784. mib added a comment. - Add custom `InteractiveCrashLogException` - Simplify the `except` block CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 Files: lldb/examples/python/crashlog.py lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test @@ -0,0 +1,8 @@ +# REQUIRES: python, native && target-aarch64 && system-darwin + +# RUN: %lldb -o 'command script import lldb.macosx.crashlog' \ +# RUN: -o 'crashlog -a -i -t /this_file_does_not_exist %S/Inputs/interactive_crashlog/multithread-test.ips' 2>&1 | FileCheck %s + +# CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands + +# CHECK: error: couldn't create target provided by the user (/this_file_does_not_exist) Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp === --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2888,9 +2888,10 @@ if (!ret_val) error.SetErrorString("unable to execute script function"); - else -error.Clear(); + else if (cmd_retobj.GetStatus() == eReturnStatusFailed) +return false; + error.Clear(); return ret_val; } @@ -2932,9 +2933,10 @@ if (!ret_val) error.SetErrorString("unable to execute script function"); - else -error.Clear(); + else if (cmd_retobj.GetStatus() == eReturnStatusFailed) +return false; + error.Clear(); return ret_val; } Index: lldb/examples/python/crashlog.py === --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -411,6 +411,8 @@ class CrashLogParseException(Exception): pass +class InteractiveCrashLogException(Exception): +pass class CrashLogParser: def parse(self, debugger, path, verbose): @@ -923,7 +925,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 +1010,10 @@ 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): 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) +raise InteractiveCrashLogException("crashlog file %s does not exist" % crashlog_path) crashlog = CrashLogParser().parse(debugger, crashlog_path, False) @@ -1022,9 +1022,8 @@ if options.target_path: target = debugger.CreateTarget(options.target_path) if not target: -result.PutCString("error: couldn't create target provided by the \ - user ({})".format(options.target_path)) -return +raise InteractiveCrashLogException("couldn't create target provided by the user (%s)" % options.target_path) + # 2. If the user didn't provide a target, try to create a target using the symbolicator if not target or not target.IsValid(): target = crashlog.create_target() @@ -1033,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 +raise InteractiveCrashLogException("couldn't create target") ci = debugger.GetCommandInterpreter() if not ci: -result.PutCString("error: couldn't get command interpreter") -return +raise InteractiveCrashLogException("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(): +raise InteractiveCrashLogException("couldn't import crashlog scripted process module") structured_data =
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
JDevlieghere requested changes to this revision. JDevlieghere added inline comments. This revision now requires changes to proceed. Comment at: lldb/examples/python/crashlog.py:1013-1015 +nonlocal result +result.SetError(sb_error, "error: %s" % message) +return kastiglione wrote: > Is this `error` function needed? `SetError` prepends the string "error: ". Rather than raising a generic Exception, we should define our own. Now there's no way to differentiate between these issues and any other exception that was thrown. Maybe that's the goal, in which case you can still catch the generic Exception, but by defining our own we leave the option open to be more specific. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
kastiglione accepted this revision. kastiglione added a comment. This revision is now accepted and ready to land. lgtm Comment at: lldb/examples/python/crashlog.py:1251-1253 +err = lldb.SBError() +err.SetErrorString(str(e)) +result.SetError(err) minor but I think this can be a single statement: `result.SetError(str(e))` CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
mib updated this revision to Diff 449472. mib added a comment. Address @JDevlieghere comments: - Use exception approach / Remove `error` helper function - Add test CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 Files: lldb/examples/python/crashlog.py lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test === --- /dev/null +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test @@ -0,0 +1,8 @@ +# REQUIRES: python, native && target-aarch64 && system-darwin + +# RUN: %lldb -o 'command script import lldb.macosx.crashlog' \ +# RUN: -o 'crashlog -a -i -t /this_file_does_not_exist %S/Inputs/interactive_crashlog/multithread-test.ips' 2>&1 | FileCheck %s + +# CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands + +# CHECK: error: couldn't create target provided by the user (/this_file_does_not_exist) Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp === --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2888,9 +2888,10 @@ if (!ret_val) error.SetErrorString("unable to execute script function"); - else -error.Clear(); + else if (cmd_retobj.GetStatus() == eReturnStatusFailed) +return false; + error.Clear(); return ret_val; } @@ -2932,9 +2933,10 @@ if (!ret_val) error.SetErrorString("unable to execute script function"); - else -error.Clear(); + else if (cmd_retobj.GetStatus() == eReturnStatusFailed) +return false; + error.Clear(); return ret_val; } Index: lldb/examples/python/crashlog.py === --- lldb/examples/python/crashlog.py +++ 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,10 @@ 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): 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) +raise Exception("crashlog file %s does not exist" % crashlog_path) crashlog = CrashLogParser().parse(debugger, crashlog_path, False) @@ -1022,8 +1020,8 @@ if options.target_path: target = debugger.CreateTarget(options.target_path) if not target: -result.PutCString("error: couldn't create target provided by the user ({option.target_path})") -return +raise Exception(f"couldn't create target provided by the user ({options.target_path})") + # 2. If the user didn't provide a target, try to create a target using the symbolicator if not target or not target.IsValid(): target = crashlog.create_target() @@ -1032,19 +1030,15 @@ target = debugger.GetTargetAtIndex(0) # 4. Fail if target is None or not target.IsValid(): -result.PutCString("error: couldn't create target") -return +raise Exception("couldn't create target") ci = debugger.GetCommandInterpreter() if not ci: -result.PutCString("error: couldn't get command interpreter") -return +raise Exception("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(): +raise Exception("couldn't import crashlog scripted process module") structured_data = lldb.SBStructuredData() structured_data.SetFromJSON(json.dumps({ "crashlog_path" : crashlog_path, @@ -1057,7 +1051,7 @@ process = target.Launch(launch_info, error) if not process or error.Fail(): -return +raise Exception("couldn't launch Scripted Process", error)
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
JDevlieghere added inline comments. Comment at: lldb/examples/python/crashlog.py:1012-1015 +def error(message, sb_error=lldb.SBError()): +nonlocal result +result.SetError(sb_error, "error: %s" % message) +return mib wrote: > JDevlieghere wrote: > > Can we do this with a try-catch + an exception? > @JDevlieghere As mentioned on D129611, if we raise an exception we won't be > able to surface the error to lldb or even to IDEs. I think it's better to use > the `SBCommandReturnObject` > > @kastiglione true! I'll remove the "error: " prefix, but I think it's > reasonable to keep this helper function to avoid code duplication. Couldn't you still raise the error where it happens and then catch it and then take it's value and put it into the SBCommandReturnObject? CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
mib updated this revision to Diff 448465. mib marked an inline comment as done. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 Files: lldb/examples/python/crashlog.py Index: lldb/examples/python/crashlog.py === --- lldb/examples/python/crashlog.py +++ 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, 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) @@ -1032,19 +1035,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, @@ -1053,11 +1052,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): @@ -1213,7 +1212,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): @@ -1251,15 +1250,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): ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
mib marked 2 inline comments as done. mib added inline comments. Comment at: lldb/examples/python/crashlog.py:1012-1015 +def error(message, sb_error=lldb.SBError()): +nonlocal result +result.SetError(sb_error, "error: %s" % message) +return JDevlieghere wrote: > Can we do this with a try-catch + an exception? @JDevlieghere As mentioned on D129611, if we raise an exception we won't be able to surface the error to lldb or even to IDEs. I think it's better to use the `SBCommandReturnObject` @kastiglione true! I'll remove the "error: " prefix, but I think it's reasonable to keep this helper function to avoid code duplication. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
kastiglione added inline comments. Comment at: lldb/examples/python/crashlog.py:1013-1015 +nonlocal result +result.SetError(sb_error, "error: %s" % message) +return Is this `error` function needed? `SetError` prepends the string "error: ". Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
JDevlieghere added inline comments. Comment at: lldb/examples/python/crashlog.py:1012-1015 +def error(message, sb_error=lldb.SBError()): +nonlocal result +result.SetError(sb_error, "error: %s" % message) +return Can we do this with a try-catch + an exception? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129614/new/ https://reviews.llvm.org/D129614 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D129614: [lldb/crashlog] Surface error using SBCommandReturnObject argument
mib created this revision. mib added a reviewer: JDevlieghere. mib added a project: LLDB. Herald added a project: All. mib requested review of this revision. Herald added a subscriber: lldb-commits. This patch allows the crashlog script to surface its errors to lldb by using the provided SBCommandReturnObject argument. rdar://95048193 Signed-off-by: Med Ismail Bennani Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129614 Files: lldb/examples/python/crashlog.py Index: lldb/examples/python/crashlog.py === --- lldb/examples/python/crashlog.py +++ 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): ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits