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

llvm-svn: 182336
This commit is contained in:
Enrico Granata 2013-05-21 00:00:30 +00:00
parent a13a12d317
commit 9730339bdf
8 changed files with 61 additions and 46 deletions

View File

@ -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.

View File

@ -488,6 +488,7 @@ public:
bool
LoadScriptingResourcesInTarget (Target *target,
std::list<Error>& errors,
Stream* feedback_stream = NULL,
bool continue_on_error = true);
static bool

View File

@ -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);
}
//------------------------------------------------------------------

View File

@ -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);

View File

@ -173,7 +173,7 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
{
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 ExecutionContext *exe_ctx,
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());
}
}
}

View File

@ -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 (Target *target, Error& error)
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 (Target *target, Error& error)
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;

View File

@ -1011,6 +1011,7 @@ ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr)
bool
ModuleList::LoadScriptingResourcesInTarget (Target *target,
std::list<Error>& errors,
Stream *feedback_stream,
bool continue_on_error)
{
if (!target)
@ -1021,16 +1022,18 @@ ModuleList::LoadScriptingResourcesInTarget (Target *target,
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;

View File

@ -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 () const
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 &