diff options
-rw-r--r-- | lldb/include/lldb/Core/ModuleList.h | 6 | ||||
-rw-r--r-- | lldb/include/lldb/Target/Target.h | 20 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectSettings.cpp | 9 | ||||
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 24 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 7 | ||||
-rw-r--r-- | lldb/source/Core/ModuleList.cpp | 28 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 29 |
7 files changed, 104 insertions, 19 deletions
diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 46b2468441e..2b690760014 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -11,6 +11,7 @@ #define liblldb_ModuleList_h_ #include <vector> +#include <list> #include "lldb/lldb-private.h" #include "lldb/Host/Mutex.h" @@ -484,6 +485,11 @@ public: size_t GetSize () const; + bool + LoadScriptingResourcesInTarget (Target *target, + std::list<Error>& errors, + bool continue_on_error = true); + static bool ModuleIsInCache (const Module *module_ptr); diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 57e2270da53..1c8a67da198 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include <list> // Other libraries and framework includes // Project includes @@ -45,6 +46,13 @@ typedef enum InlineStrategy eInlineBreakpointsHeaders, 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 @@ -147,12 +155,9 @@ public: bool GetUseFastStepping() const; - bool + LoadScriptFromSymFile GetLoadScriptFromSymbolFile() const; - void - SetLoadScriptFromSymbolFile(bool b); - }; typedef std::shared_ptr<TargetProperties> TargetPropertiesSP; @@ -730,6 +735,13 @@ public: void SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files); + bool + LoadScriptingResources (std::list<Error>& errors, + bool continue_on_error = true) + { + return m_images.LoadScriptingResourcesInTarget(this,errors,continue_on_error); + } + //------------------------------------------------------------------ /// Get accessor for the images for this process. /// diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index cafb05550f2..95cc9b68a8f 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -255,7 +255,14 @@ protected: if (error.Success()) { - error = m_interpreter.GetDebugger().SetPropertyValue (&m_exe_ctx, + // FIXME this is the same issue as the one in commands script import + // we could be setting target.load-script-from-symbol-file which would cause + // Python scripts to be loaded, which could run LLDB commands + // (e.g. settings set target.process.python-os-plugin-path) and cause a crash + // if we did not clear the command's exe_ctx first + ExecutionContext exe_ctx(m_exe_ctx); + m_exe_ctx.Clear(); + error = m_interpreter.GetDebugger().SetPropertyValue (&exe_ctx, eVarSetOperationAssign, var_name, var_value_cstr); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index f6cffec2b76..4cda3417de2 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -47,6 +47,7 @@ #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StopInfo.h" +#include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/AnsiTerminal.h" @@ -170,15 +171,38 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx, const char *property_path, const char *value) { + bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0; + TargetSP target_sp; + LoadScriptFromSymFile load_script_old_value; + if (is_load_script && exe_ctx->GetTargetSP()) + { + target_sp = exe_ctx->GetTargetSP(); + load_script_old_value = target_sp->TargetProperties::GetLoadScriptFromSymbolFile(); + } Error error (Properties::SetPropertyValue (exe_ctx, op, property_path, value)); if (error.Success()) { + // FIXME it would be nice to have "on-change" callbacks for properties if (strcmp(property_path, g_properties[ePropertyPrompt].name) == 0) { const char *new_prompt = GetPrompt(); 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) + { + if (target_sp->TargetProperties::GetLoadScriptFromSymbolFile() == LoadScriptFromSymFile::eYes) + { + std::list<Error> errors; + if (!target_sp->LoadScriptingResources(errors)) + { + for (auto error : errors) + { + GetErrorStream().Printf("unable to autoload scripting data: %s\n",error.AsCString()); + } + } + } + } } return error; } diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 7ce0c1b1f26..86057c17eff 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1243,7 +1243,7 @@ Module::LoadScriptingResourceInTarget (Target *target, Error& error) return false; } - bool shoud_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); + LoadScriptFromSymFile shoud_load = target->TargetProperties::GetLoadScriptFromSymbolFile(); Debugger &debugger = target->GetDebugger(); const ScriptLanguage script_language = debugger.GetScriptLanguage(); @@ -1273,9 +1273,10 @@ Module::LoadScriptingResourceInTarget (Target *target, Error& error) FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i)); if (scripting_fspec && scripting_fspec.Exists()) { - if (!shoud_load) + if (shoud_load != LoadScriptFromSymFile::eYes) { - error.SetErrorString("Target doesn't allow loading scripting resource. Please set target.load-script-from-symbol-file and retry."); + 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()); return false; } StreamString scripting_stream; diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 376d046eb61..96dbc4f6e62 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -1008,4 +1008,30 @@ ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr) return GetSharedModuleList ().RemoveIfOrphaned (module_ptr); } - +bool +ModuleList::LoadScriptingResourcesInTarget (Target *target, + std::list<Error>& errors, + bool continue_on_error) +{ + if (!target) + return false; + Mutex::Locker locker(m_modules_mutex); + for (auto module : m_modules) + { + Error error; + if (module) + { + module->LoadScriptingResourceInTarget(target, error); + if (error.Fail()) + { + 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; + } + } + return errors.size() == 0; +} diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index f1a09a7f979..c40b91b8ffb 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2265,6 +2265,15 @@ 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[] = { @@ -2301,7 +2310,7 @@ 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::eTypeBoolean , false, false, NULL, NULL, "Allow LLDB to load scripting resources embedded in symbol files when available." }, + { "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." }, { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL } }; enum @@ -2373,6 +2382,13 @@ public: } return ProtectedGetPropertyAtIndex (idx); } + + lldb::TargetSP + GetTargetSP () + { + return m_target->shared_from_this(); + } + protected: void @@ -2674,18 +2690,11 @@ TargetProperties::GetUseFastStepping () const return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); } -bool +LoadScriptFromSymFile TargetProperties::GetLoadScriptFromSymbolFile () const { const uint32_t idx = ePropertyLoadScriptFromSymbolFile; - return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); -} - -void -TargetProperties::SetLoadScriptFromSymbolFile (bool b) -{ - const uint32_t idx = ePropertyLoadScriptFromSymbolFile; - m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, b); + return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); } const TargetPropertiesSP & |