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 @@ -1017,11 +1017,22 @@ crashlog = CrashLogParser().parse(debugger, crashlog_path, False) - if debugger.GetNumTargets() > 0: - target = debugger.GetTargetAtIndex(0) - else: + target = lldb.SBTarget() + # 1. Try to use the user-provided target + 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 + # 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() - if not target: + # 3. If that didn't work, and a target is already loaded, use it + if (target is None or not target.IsValid()) and debugger.GetNumTargets() > 0: + target = debugger.GetTargetAtIndex(0) + # 4. Fail + if target is None or not target.IsValid(): result.PutCString("error: couldn't create target") return @@ -1183,6 +1194,12 @@ action='store_true', help='dump symbolicated stackframes without creating a debug session', default=True) + option_parser.add_option( + '--target', + '-t', + dest='target_path', + help='the target binary path that should be used for interactive crashlog (optional)', + default=None) return option_parser diff --git a/lldb/examples/python/scripted_process/crashlog_scripted_process.py b/lldb/examples/python/scripted_process/crashlog_scripted_process.py --- a/lldb/examples/python/scripted_process/crashlog_scripted_process.py +++ b/lldb/examples/python/scripted_process/crashlog_scripted_process.py @@ -13,7 +13,7 @@ try: crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, False) except Exception as e: - return + raise e self.pid = crash_log.process_id self.addr_mask = crash_log.addr_mask @@ -44,6 +44,7 @@ super().__init__(target, args) if not self.target or not self.target.IsValid(): + # Return error return self.crashlog_path = None @@ -54,6 +55,7 @@ self.crashlog_path = crashlog_path.GetStringValue(4096) if not self.crashlog_path: + # Return error return load_all_images = args.GetValueForKey("load_all_images") diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test --- a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test +++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test @@ -2,8 +2,8 @@ # RUN: mkdir -p %t.dir # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test -# RUN: %lldb %t.dir/multithread-test -o 'command script import lldb.macosx.crashlog' \ -# RUN: -o 'crashlog -a -i %S/Inputs/interactive_crashlog/multithread-test.ips' \ +# RUN: %lldb -o 'command script import lldb.macosx.crashlog' \ +# RUN: -o 'crashlog -a -i -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \ # RUN: -o "thread list" -o "bt all" 2>&1 | FileCheck %s # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands