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
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@182336 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/Core/Module.h b/include/lldb/Core/Module.h
index 7ba9856..79da797 100644
--- a/include/lldb/Core/Module.h
+++ b/include/lldb/Core/Module.h
@@ -595,7 +595,9 @@
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/include/lldb/Core/ModuleList.h b/include/lldb/Core/ModuleList.h
index 2b69076..8da07cb 100644
--- a/include/lldb/Core/ModuleList.h
+++ b/include/lldb/Core/ModuleList.h
@@ -488,6 +488,7 @@
bool
LoadScriptingResourcesInTarget (Target *target,
std::list<Error>& errors,
+ Stream* feedback_stream = NULL,
bool continue_on_error = true);
static bool
diff --git a/include/lldb/Target/Target.h b/include/lldb/Target/Target.h
index 1c8a67d..2b305e1 100644
--- a/include/lldb/Target/Target.h
+++ b/include/lldb/Target/Target.h
@@ -47,13 +47,6 @@
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 @@
bool
GetUseFastStepping() const;
- LoadScriptFromSymFile
+ bool
GetLoadScriptFromSymbolFile() const;
+
+ bool
+ GetWarnForScriptInSymbolFile() const;
};
@@ -737,9 +733,10 @@
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/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 8ed3c23..cd2e7c3 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -4376,11 +4376,14 @@
// 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/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index 4cda341..15cf2fe 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -173,7 +173,7 @@
{
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 @@
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/source/Core/Module.cpp b/source/Core/Module.cpp
index 86057c1..f00afc1 100644
--- a/source/Core/Module.cpp
+++ b/source/Core/Module.cpp
@@ -1235,7 +1235,7 @@
}
bool
-Module::LoadScriptingResourceInTarget (Target *target, Error& error)
+Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
{
if (!target)
{
@@ -1243,7 +1243,8 @@
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 @@
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/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp
index 449a800..07b20b8 100644
--- a/source/Core/ModuleList.cpp
+++ b/source/Core/ModuleList.cpp
@@ -1011,6 +1011,7 @@
bool
ModuleList::LoadScriptingResourcesInTarget (Target *target,
std::list<Error>& errors,
+ Stream *feedback_stream,
bool continue_on_error)
{
if (!target)
@@ -1021,16 +1022,18 @@
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/source/Target/Target.cpp b/source/Target/Target.cpp
index 490c88e..b40e210 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -984,11 +984,16 @@
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 @@
{ 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 @@
// 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 @@
ePropertyInlineStrategy,
ePropertyDisassemblyFlavor,
ePropertyUseFastStepping,
- ePropertyLoadScriptFromSymbolFile
+ ePropertyLoadScriptFromSymbolFile,
+ ePropertyWarnForScriptFromSymbolFile
};
@@ -2690,11 +2688,18 @@
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 &