diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index 7ba9856fbeb91d3de37152c77136d92e396fc899..79da797181421cf4c78d9d850d808cf8297f349f 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -595,7 +595,9 @@ public: IsLoadedInTarget (Target *target); bool - LoadScriptingResourceInTarget (Target *target, Error& error); + LoadScriptingResourceInTarget (Target *target, + Error& error, + Stream* feedback_stream = NULL); //------------------------------------------------------------------ /// Get the number of compile units for this module. diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 2b690760014803db4252c7ce75a563fad87cd560..8da07cba9caae10e3fe62fb041828bf5e6d89923 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -488,6 +488,7 @@ public: bool LoadScriptingResourcesInTarget (Target *target, std::list& errors, + Stream* feedback_stream = NULL, bool continue_on_error = true); static bool diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 1c8a67da19869dd3a0785200cfa98c0c036afa54..2b305e1361435215e9cf033434c6bfb4ae420052 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -47,13 +47,6 @@ typedef enum InlineStrategy eInlineBreakpointsAlways } InlineStrategy; -enum class LoadScriptFromSymFile : int64_t -{ - eDefault, // warn me if there is a script but don't load it - eNo, // do not load any scripts - fail silently - eYes // load all scripts -}; - //---------------------------------------------------------------------- // TargetProperties //---------------------------------------------------------------------- @@ -155,8 +148,11 @@ public: bool GetUseFastStepping() const; - LoadScriptFromSymFile + bool GetLoadScriptFromSymbolFile() const; + + bool + GetWarnForScriptInSymbolFile() const; }; @@ -737,9 +733,10 @@ public: bool LoadScriptingResources (std::list& errors, + Stream* feedback_stream = NULL, bool continue_on_error = true) { - return m_images.LoadScriptingResourcesInTarget(this,errors,continue_on_error); + return m_images.LoadScriptingResourcesInTarget(this,errors,feedback_stream,continue_on_error); } //------------------------------------------------------------------ diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 8ed3c239672187f3828e7c8eaec3462c4ac84469..cd2e7c3c2aeb807f346d5ba18025734934d94e9f 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -4376,11 +4376,14 @@ protected: // Make sure we load any scripting resources that may be embedded // in the debug info files in case the platform supports that. Error error; - module_sp->LoadScriptingResourceInTarget (target, error); + StreamString feedback_stream; + module_sp->LoadScriptingResourceInTarget (target, error,&feedback_stream); if (error.Fail() && error.AsCString()) result.AppendWarningWithFormat("unable to load scripting data for module %s - error reported was %s", module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), error.AsCString()); + else if (feedback_stream.GetSize()) + result.AppendWarningWithFormat("%s",feedback_stream.GetData()); flush = true; result.SetStatus (eReturnStatusSuccessFinishResult); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 4cda3417de2b78a4331d4e616fdcb355aa2ccda0..15cf2fe31d4a864944a5d85468b2eab0b1e39d91 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -173,7 +173,7 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx, { bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0; TargetSP target_sp; - LoadScriptFromSymFile load_script_old_value; + bool load_script_old_value; if (is_load_script && exe_ctx->GetTargetSP()) { target_sp = exe_ctx->GetTargetSP(); @@ -189,17 +189,20 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx, EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt))); GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp); } - else if (is_load_script && target_sp && load_script_old_value == LoadScriptFromSymFile::eDefault) + else if (is_load_script && target_sp && load_script_old_value == false) { - if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == LoadScriptFromSymFile::eYes) + if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == true) { std::list errors; - if (!target_sp->LoadScriptingResources(errors)) + StreamString feedback_stream; + if (!target_sp->LoadScriptingResources(errors,&feedback_stream)) { for (auto error : errors) { - GetErrorStream().Printf("unable to autoload scripting data: %s\n",error.AsCString()); + GetErrorStream().Printf("%s\n",error.AsCString()); } + if (feedback_stream.GetSize()) + GetErrorStream().Printf("%s",feedback_stream.GetData()); } } } diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 86057c17eff6818a755b8267d2ff847e7ed5b3fb..f00afc10ad2be53af25247eee0876c9eb8d3461b 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1235,7 +1235,7 @@ Module::IsLoadedInTarget (Target *target) } bool -Module::LoadScriptingResourceInTarget (Target *target, Error& error) +Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream) { if (!target) { @@ -1243,7 +1243,8 @@ Module::LoadScriptingResourceInTarget (Target *target, Error& error) return false; } - LoadScriptFromSymFile shoud_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); + bool shoud_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); + bool should_warn = target->TargetProperties::GetWarnForScriptInSymbolFile(); Debugger &debugger = target->GetDebugger(); const ScriptLanguage script_language = debugger.GetScriptLanguage(); @@ -1273,10 +1274,10 @@ Module::LoadScriptingResourceInTarget (Target *target, Error& error) FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i)); if (scripting_fspec && scripting_fspec.Exists()) { - if (shoud_load != LoadScriptFromSymFile::eYes) + if (shoud_load == false) { - if (shoud_load == LoadScriptFromSymFile::eDefault) - error.SetErrorStringWithFormat("the setting target.load-script-from-symbol-file disallows loading script files - change it to yes or manually command script import %s",scripting_fspec.GetPath().c_str()); + if (should_warn == true && feedback_stream) + feedback_stream->Printf("warning: the debug info scripting resource for '%s' was not loaded for security reasons. to override, set the \"target.load-script-from-symbol-file\" setting to true or manually run \"command script import %s\"\n",GetFileSpec().GetFileNameStrippingExtension().GetCString(),scripting_fspec.GetPath().c_str()); return false; } StreamString scripting_stream; diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 449a800949e9c7a5cbcfa87b420c6417c3f0857d..07b20b8d91e132b2a1bbddf2cf3de33b936d9cc2 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -1011,6 +1011,7 @@ ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr) bool ModuleList::LoadScriptingResourcesInTarget (Target *target, std::list& errors, + Stream *feedback_stream, bool continue_on_error) { if (!target) @@ -1021,16 +1022,18 @@ ModuleList::LoadScriptingResourcesInTarget (Target *target, Error error; if (module) { - module->LoadScriptingResourceInTarget(target, error); - if (error.Fail() && error.AsCString()) + if (!module->LoadScriptingResourceInTarget(target, error, feedback_stream)) { - error.SetErrorStringWithFormat("unable to load scripting data for module %s - error reported was %s", - module->GetFileSpec().GetFileNameStrippingExtension().GetCString(), - error.AsCString()); - errors.push_back(error); + if (error.Fail() && error.AsCString()) + { + error.SetErrorStringWithFormat("unable to load scripting data for module %s - error reported was %s", + module->GetFileSpec().GetFileNameStrippingExtension().GetCString(), + error.AsCString()); + errors.push_back(error); + } + if (!continue_on_error) + return false; } - if (!continue_on_error) - return false; } } return errors.size() == 0; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 490c88e186d6b777881f89513f08615d283062a8..b40e210ca3f742d5827bd16b7019c2d25422861c 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -984,11 +984,16 @@ static void LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target) { Error error; - if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error) && error.AsCString()) + StreamString feedback_stream; + if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream)) { - target->GetDebugger().GetOutputStream().Printf("unable to load scripting data for module %s - error reported was %s\n", - module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), - error.AsCString()); + if (error.AsCString()) + target->GetDebugger().GetErrorStream().Printf("unable to load scripting data for module %s - error reported was %s\n", + module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), + error.AsCString()); + if (feedback_stream.GetSize()) + target->GetDebugger().GetOutputStream().Printf("%s\n", + feedback_stream.GetData()); } } @@ -2265,15 +2270,6 @@ g_x86_dis_flavor_value_types[] = { 0, NULL, NULL } }; -static OptionEnumValueElement -g_load_script_from_sym_file_enums[] = -{ - {(int64_t)LoadScriptFromSymFile::eDefault, "default", "Don't load scripts but warn when they are found (default)"}, - {(int64_t)LoadScriptFromSymFile::eNo, "no", "Don't load scripts"}, - {(int64_t)LoadScriptFromSymFile::eYes, "yes", "Load scripts"}, - { 0, NULL, NULL } -}; - static PropertyDefinition g_properties[] = { @@ -2310,7 +2306,8 @@ g_properties[] = // FIXME: This is the wrong way to do per-architecture settings, but we don't have a general per architecture settings system in place yet. { "x86-disassembly-flavor" , OptionValue::eTypeEnum , false, eX86DisFlavorDefault, NULL, g_x86_dis_flavor_value_types, "The default disassembly flavor to use for x86 or x86-64 targets." }, { "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." }, - { "load-script-from-symbol-file" , OptionValue::eTypeEnum , false, (int64_t)LoadScriptFromSymFile::eDefault, NULL, g_load_script_from_sym_file_enums, "Allow LLDB to load scripting resources embedded in symbol files when available." }, + { "load-script-from-symbol-file" , OptionValue::eTypeBoolean , false, false, NULL, NULL, "Allow LLDB to load scripting resources embedded in symbol files when available." }, + { "warn-on-script-from-symbol-file" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Tell me about scripting resources embedded in symbol files when available." }, { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL } }; enum @@ -2337,7 +2334,8 @@ enum ePropertyInlineStrategy, ePropertyDisassemblyFlavor, ePropertyUseFastStepping, - ePropertyLoadScriptFromSymbolFile + ePropertyLoadScriptFromSymbolFile, + ePropertyWarnForScriptFromSymbolFile }; @@ -2690,11 +2688,18 @@ TargetProperties::GetUseFastStepping () const return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); } -LoadScriptFromSymFile +bool TargetProperties::GetLoadScriptFromSymbolFile () const { const uint32_t idx = ePropertyLoadScriptFromSymbolFile; - return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); + return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); +} + +bool +TargetProperties::GetWarnForScriptInSymbolFile() const +{ + const uint32_t idx = ePropertyWarnForScriptFromSymbolFile; + return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); } const TargetPropertiesSP &