From 9730339bdf8f18d0d3f773c797b189949159c1be Mon Sep 17 00:00:00 2001 From: Enrico Granata <egranata@apple.com> Date: Tue, 21 May 2013 00:00:30 +0000 Subject: [PATCH] Improving the previous checkin about target.load-script-from-symbol-file There are two settings: target.load-script-from-symbol-file is a boolean that says load or no load (default: false) target.warn-on-script-from-symbol-file is also a boolean, it says whether you want to be warned when a script file is not loaded due to security (default: true) the auto loading on change for target.load-script-from-symbol-file is preserved llvm-svn: 182336 --- lldb/include/lldb/Core/Module.h | 4 +- lldb/include/lldb/Core/ModuleList.h | 1 + lldb/include/lldb/Target/Target.h | 15 +++----- lldb/source/Commands/CommandObjectTarget.cpp | 5 ++- lldb/source/Core/Debugger.cpp | 13 ++++--- lldb/source/Core/Module.cpp | 11 +++--- lldb/source/Core/ModuleList.cpp | 19 ++++++---- lldb/source/Target/Target.cpp | 39 +++++++++++--------- 8 files changed, 61 insertions(+), 46 deletions(-) diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index 7ba9856fbeb9..79da79718142 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 2b6907600148..8da07cba9caa 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<Error>& 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 1c8a67da1986..2b305e136143 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<Error>& 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 8ed3c2396721..cd2e7c3c2aeb 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 4cda3417de2b..15cf2fe31d4a 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<Error> 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 86057c17eff6..f00afc10ad2b 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 449a800949e9..07b20b8d91e1 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<Error>& 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 490c88e186d6..b40e210ca3f7 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 & -- GitLab