<rdar://problem/13878726>
authorEnrico Granata <egranata@apple.com>
Mon, 20 May 2013 22:29:23 +0000 (22:29 +0000)
committerEnrico Granata <egranata@apple.com>
Mon, 20 May 2013 22:29:23 +0000 (22:29 +0000)
This changes the setting target.load-script-from-symbol-file to be a ternary enum value:
default (the default value) will NOT load the script files but will issue a warning suggesting workarounds
yes will load the script files
no will not load the script files AND will NOT issue any warning

if you change the setting value from default to yes, that will then cause the script files to be loaded
(the assumption is you didn't know about the setting, got a warning, and quickly want to remedy it)

if you have a settings set command for this in your lldbinit file, be sure to change "true" or "false" into an appropriate "yes" or "no" value

llvm-svn: 182323

lldb/include/lldb/Core/ModuleList.h
lldb/include/lldb/Target/Target.h
lldb/source/Commands/CommandObjectSettings.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Core/Module.cpp
lldb/source/Core/ModuleList.cpp
lldb/source/Target/Target.cpp

index 46b2468..2b69076 100644 (file)
@@ -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);
 
index 57e2270..1c8a67d 100644 (file)
@@ -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.
     ///
index cafb055..95cc9b6 100644 (file)
@@ -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);
index f6cffec..4cda341 100644 (file)
@@ -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;
 }
index 7ce0c1b..86057c1 100644 (file)
@@ -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;
index 376d046..96dbc4f 100644 (file)
@@ -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;
+}
index f1a09a7..c40b91b 100644 (file)
@@ -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 &