[Lldb-commits] [lldb] r182323 - <rdar://problem/13878726>

Enrico Granata egranata at apple.com
Mon May 20 15:29:23 PDT 2013


Author: enrico
Date: Mon May 20 17:29:23 2013
New Revision: 182323

URL: http://llvm.org/viewvc/llvm-project?rev=182323&view=rev
Log:
<rdar://problem/13878726>

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


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

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Mon May 20 17:29:23 2013
@@ -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);
 

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon May 20 17:29:23 2013
@@ -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.
     ///

Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Mon May 20 17:29:23 2013
@@ -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);

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Mon May 20 17:29:23 2013
@@ -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 Execut
                             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;
 }

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon May 20 17:29:23 2013
@@ -1243,7 +1243,7 @@ Module::LoadScriptingResourceInTarget (T
         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 (T
                     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;

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Mon May 20 17:29:23 2013
@@ -1008,4 +1008,30 @@ ModuleList::RemoveSharedModuleIfOrphaned
     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;
+}

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=182323&r1=182322&r2=182323&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon May 20 17:29:23 2013
@@ -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 ()
     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 &





More information about the lldb-commits mailing list