[Lldb-commits] [lldb] r182336 - Improving the previous checkin about target.load-script-from-symbol-file

Enrico Granata egranata at apple.com
Mon May 20 17:00:31 PDT 2013


Author: enrico
Date: Mon May 20 19:00:30 2013
New Revision: 182336

URL: http://llvm.org/viewvc/llvm-project?rev=182336&view=rev
Log:
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


Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Core/ModuleList.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Commands/CommandObjectTarget.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/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Mon May 20 19:00:30 2013
@@ -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.

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Mon May 20 19:00:30 2013
@@ -488,6 +488,7 @@ public:
     bool
     LoadScriptingResourcesInTarget (Target *target,
                                     std::list<Error>& errors,
+                                    Stream* feedback_stream = NULL,
                                     bool continue_on_error = true);
     
     static bool

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon May 20 19:00:30 2013
@@ -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);
     }
     
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Mon May 20 19:00:30 2013
@@ -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);

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Mon May 20 19:00:30 2013
@@ -173,7 +173,7 @@ Debugger::SetPropertyValue (const Execut
 {
     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 Execut
             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());
                 }
             }
         }

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon May 20 19:00:30 2013
@@ -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 (T
         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 (T
                     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;

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=182336&r1=182335&r2=182336&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Mon May 20 19:00:30 2013
@@ -1011,6 +1011,7 @@ ModuleList::RemoveSharedModuleIfOrphaned
 bool
 ModuleList::LoadScriptingResourcesInTarget (Target *target,
                                             std::list<Error>& errors,
+                                            Stream *feedback_stream,
                                             bool continue_on_error)
 {
     if (!target)
@@ -1021,16 +1022,18 @@ ModuleList::LoadScriptingResourcesInTarg
         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;

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





More information about the lldb-commits mailing list