Index: lldb/examples/python/crashlog.py =================================================================== --- lldb/examples/python/crashlog.py +++ lldb/examples/python/crashlog.py @@ -449,7 +449,7 @@ head, _, tail = buffer.partition('\n') return json.loads(tail) - with open(path, 'r', encoding='utf-8') as f: + with open(os.path.normpath(os.path.expanduser(path)), 'r', encoding='utf-8') as f: buffer = f.read() try: return parse_json(buffer) @@ -1103,6 +1103,10 @@ if not result.Succeeded(): raise InteractiveCrashLogException("couldn't import crashlog scripted process module") + ci.HandleCommand('settings set symbols.enable-background-lookup true', result) + if not result.Succeeded(): + raise InteractiveCrashLogException("couldn't enable background symbol lookup") + structured_data = lldb.SBStructuredData() structured_data.SetFromJSON(json.dumps({ "file_path" : crashlog_path, "load_all_images": options.load_all_images })) @@ -1245,19 +1249,13 @@ dest='source_all', help='show source for all threads, not just the crashed thread', default=False) + option_parser.add_option( + '-b', + '--batch', + action='store_true', + help='dump symbolicated stackframes without creating a debug session', + default=False) if add_interactive_options: - option_parser.add_option( - '-i', - '--interactive', - action='store_true', - help='parse a crash log and load it in a ScriptedProcess', - default=False) - option_parser.add_option( - '-b', - '--batch', - action='store_true', - help='dump symbolicated stackframes without creating a debug session', - default=True) option_parser.add_option( '--target', '-t', @@ -1297,6 +1295,13 @@ except: return + if options.batch and (options.target_path or options.skip_status): + print("Batch mode (-b) doesn't allow specifying target path (-t) or skipping process status (-s).") + print("Aborting symbolication.") + print() + option_parser.print_help() + return + if options.version: print(debugger.GetVersionString()) return @@ -1312,12 +1317,10 @@ error = lldb.SBError() def should_run_in_interactive_mode(options, ci): - if options.interactive: - return True - elif options.batch: + if options.batch: return False - # elif ci and ci.IsInteractive(): - # return True + elif ci and ci.IsInteractive(): + return True else: return False 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 @@ -31,12 +31,10 @@ if image not in self.loaded_images: if image.uuid == uuid.UUID(int=0): continue - err = image.add_module(self.target) - if err: - # Append to SBCommandReturnObject - print(err) - else: - self.loaded_images.append(image) + for section in image.section_infos: + if section.start_addr and section.name == "__TEXT": + self.loaded_images.append({"uuid": str(image.uuid), + "load_addr": section.start_addr}) for thread in crash_log.threads: if self.load_all_images: Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp =================================================================== --- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp +++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp @@ -11,7 +11,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" - +#include "lldb/Core/Progress.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/ThreadLauncher.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -19,6 +19,7 @@ #include "lldb/Interpreter/OptionGroupBoolean.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Interpreter/ScriptedMetadata.h" +#include "lldb/Symbol/LocateSymbolFile.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Target/Queue.h" #include "lldb/Target/RegisterContext.h" @@ -410,15 +411,18 @@ StructuredData::ArraySP loaded_images_sp = GetInterface().GetLoadedImages(); - if (!loaded_images_sp || !loaded_images_sp->GetSize()) + size_t num_image_to_load = loaded_images_sp->GetSize(); + if (!loaded_images_sp || !num_image_to_load) return ScriptedInterface::ErrorWithMessage( LLVM_PRETTY_FUNCTION, "No loaded images.", error); ModuleList module_list; Target &target = GetTarget(); - auto reload_image = [&target, &module_list, &error_with_message]( - StructuredData::Object *obj) -> bool { + Progress progress("Fetching external dependencies", num_image_to_load); + auto reload_image = [&target, &module_list, &error_with_message, + &progress](StructuredData::Object *obj) -> bool { + progress.Increment(); StructuredData::Dictionary *dict = obj->GetAsDictionary(); if (!dict) @@ -445,6 +449,13 @@ } module_spec.GetArchitecture() = target.GetArchitecture(); + Status error; + Symbols::DownloadObjectAndSymbolFile(module_spec, error, true); + if (error.Fail() || + !FileSystem::Instance().Exists(module_spec.GetFileSpec())) { + return error_with_message(error.AsCString()); + } + ModuleSP module_sp = target.GetOrCreateModule(module_spec, true /* notify */); @@ -469,9 +480,11 @@ if (!changed && !module_sp->GetObjectFile()) return error_with_message("Couldn't set the load address for module."); - dict->GetValueForKeyAsString("path", value); - FileSpec objfile(value); - module_sp->SetFileSpecAndObjectName(objfile, objfile.GetFilename()); + if (has_path) { + dict->GetValueForKeyAsString("path", value); + FileSpec objfile(value); + module_sp->SetFileSpecAndObjectName(objfile, objfile.GetFilename()); + } return module_list.AppendIfNeeded(module_sp); }; Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/app_specific_backtrace_crashlog.test @@ -3,7 +3,7 @@ # RUN: mkdir -p %t.dir # RUN: yaml2obj %S/Inputs/application_specific_info/asi.yaml > %t.dir/asi # RUN: %lldb -o 'command script import lldb.macosx.crashlog' \ -# RUN: -o 'crashlog -a -i -t %t.dir/asi %S/Inputs/application_specific_info/asi.txt' \ +# RUN: -o 'crashlog -a -t %t.dir/asi %S/Inputs/application_specific_info/asi.txt' \ # RUN: -o "thread list" -o "bt all" 2>&1 | FileCheck %s # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test @@ -2,7 +2,7 @@ # RUN: %lldb -o 'command script import lldb.macosx.crashlog' \ # RUN: -o 'crashlog -V' \ -# RUN: -o 'crashlog -a -i -t /this_file_does_not_exist %S/Inputs/interactive_crashlog/multithread-test.ips' 2>&1 | FileCheck %s +# RUN: -o 'crashlog -a -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 Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/json.test @@ -2,11 +2,11 @@ # RUN: cp %S/Inputs/a.out.ips %t.crash # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json -# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s +# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -b %t.crash' 2>&1 | FileCheck %s # RUN: cp %S/Inputs/a.out.ips %t.nometadata.crash # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.nometadata.crash --offsets '{"main":20, "bar":9, "foo":16}' --json --no-metadata -# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.nometadata.crash' 2>&1 | FileCheck %s +# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -b %t.nometadata.crash' 2>&1 | FileCheck %s # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no_threadState.test @@ -2,7 +2,7 @@ # RUN: cp %S/Inputs/no_threadState.ips %t.crash # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json -# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s +# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -b %t.crash' 2>&1 | FileCheck %s # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test @@ -3,7 +3,7 @@ # RUN: mkdir -p %t.dir # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test # 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 'crashlog -a -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 Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test @@ -3,7 +3,7 @@ # RUN: mkdir -p %t.dir # RUN: yaml2obj %S/Inputs/interactive_crashlog/multithread-test.yaml > %t.dir/multithread-test # RUN: %lldb -b -o 'command script import lldb.macosx.crashlog' \ -# RUN: -o 'crashlog -a -i -s -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \ +# RUN: -o 'crashlog -a -s -t %t.dir/multithread-test %S/Inputs/interactive_crashlog/multithread-test.ips' \ # RUN: -o 'command source -s 0 %s' 2>&1 | FileCheck %s # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test =================================================================== --- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test +++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/text.test @@ -1,7 +1,7 @@ # RUN: %clang_host -g %S/Inputs/test.c -o %t.out # RUN: cp %S/Inputs/a.out.crash %t.crash # RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' -# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog %t.crash' 2>&1 | FileCheck %s +# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -b %t.crash' 2>&1 | FileCheck %s # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands