[lldb][NFCI] Methods to load scripting resources should take a Stream by reference

These methods all take a `Stream *` to get feedback about what's going
on. By default, it's a nullptr, but we always feed it with a valid
pointer. It would therefore make more sense to have this take a
reference.

Differential Revision: https://reviews.llvm.org/D154883
This commit is contained in:
Alex Langford
2023-07-10 13:19:13 -07:00
parent 95d62344c0
commit 1d796b48e4
12 changed files with 48 additions and 51 deletions

View File

@@ -563,7 +563,7 @@ public:
bool IsLoadedInTarget(Target *target);
bool LoadScriptingResourceInTarget(Target *target, Status &error,
Stream *feedback_stream = nullptr);
Stream &feedback_stream);
/// Get the number of compile units for this module.
///

View File

@@ -440,7 +440,7 @@ public:
bool IsEmpty() const { return !GetSize(); }
bool LoadScriptingResourcesInTarget(Target *target, std::list<Status> &errors,
Stream *feedback_stream = nullptr,
Stream &feedback_stream,
bool continue_on_error = true);
static ModuleListProperties &GetGlobalModuleListProperties();

View File

@@ -286,7 +286,7 @@ public:
// current computers global settings.
virtual FileSpecList
LocateExecutableScriptingResources(Target *target, Module &module,
Stream *feedback_stream);
Stream &feedback_stream);
virtual Status GetSharedModule(
const ModuleSpec &module_spec, Process *process,

View File

@@ -939,7 +939,7 @@ public:
LoadDependentFiles load_dependent_files = eLoadDependentsDefault);
bool LoadScriptingResources(std::list<Status> &errors,
Stream *feedback_stream = nullptr,
Stream &feedback_stream,
bool continue_on_error = true) {
return m_images.LoadScriptingResourcesInTarget(
this, errors, feedback_stream, continue_on_error);

View File

@@ -4219,7 +4219,7 @@ protected:
Status error;
StreamString feedback_stream;
module_sp->LoadScriptingResourceInTarget(target, error,
&feedback_stream);
feedback_stream);
if (error.Fail() && error.AsCString())
result.AppendWarningWithFormat(
"unable to load scripting data for module %s - error "

View File

@@ -248,7 +248,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
eLoadScriptFromSymFileTrue) {
std::list<Status> errors;
StreamString feedback_stream;
if (!target_sp->LoadScriptingResources(errors, &feedback_stream)) {
if (!target_sp->LoadScriptingResources(errors, feedback_stream)) {
Stream &s = GetErrorStream();
for (auto error : errors) {
s.Printf("%s\n", error.AsCString());

View File

@@ -1499,7 +1499,7 @@ bool Module::IsLoadedInTarget(Target *target) {
}
bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
Stream *feedback_stream) {
Stream &feedback_stream) {
if (!target) {
error.SetErrorString("invalid destination Target");
return false;
@@ -1534,17 +1534,16 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
if (scripting_fspec &&
FileSystem::Instance().Exists(scripting_fspec)) {
if (should_load == eLoadScriptFromSymFileWarn) {
if (feedback_stream)
feedback_stream->Printf(
"warning: '%s' contains a debug script. To run this script "
"in "
"this debug session:\n\n command script import "
"\"%s\"\n\n"
"To run all discovered debug scripts in this session:\n\n"
" settings set target.load-script-from-symbol-file "
"true\n",
GetFileSpec().GetFileNameStrippingExtension().GetCString(),
scripting_fspec.GetPath().c_str());
feedback_stream.Printf(
"warning: '%s' contains a debug script. To run this script "
"in "
"this debug session:\n\n command script import "
"\"%s\"\n\n"
"To run all discovered debug scripts in this session:\n\n"
" settings set target.load-script-from-symbol-file "
"true\n",
GetFileSpec().GetFileNameStrippingExtension().GetCString(),
scripting_fspec.GetPath().c_str());
return false;
}
StreamString scripting_stream;

View File

@@ -1028,7 +1028,7 @@ bool ModuleList::RemoveSharedModuleIfOrphaned(const Module *module_ptr) {
bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
std::list<Status> &errors,
Stream *feedback_stream,
Stream &feedback_stream,
bool continue_on_error) {
if (!target)
return false;

View File

@@ -194,7 +194,7 @@ PlatformDarwin::PutFile(const lldb_private::FileSpec &source,
}
FileSpecList PlatformDarwin::LocateExecutableScriptingResources(
Target *target, Module &module, Stream *feedback_stream) {
Target *target, Module &module, Stream &feedback_stream) {
FileSpecList file_list;
if (target &&
target->GetDebugger().GetScriptLanguage() == eScriptLanguagePython) {
@@ -266,33 +266,31 @@ FileSpecList PlatformDarwin::LocateExecutableScriptingResources(
// if we did some replacements of reserved characters, and a
// file with the untampered name exists, then warn the user
// that the file as-is shall not be loaded
if (feedback_stream) {
if (module_basename != original_module_basename &&
FileSystem::Instance().Exists(orig_script_fspec)) {
const char *reason_for_complaint =
was_keyword ? "conflicts with a keyword"
: "contains reserved characters";
if (FileSystem::Instance().Exists(script_fspec))
feedback_stream->Printf(
"warning: the symbol file '%s' contains a debug "
"script. However, its name"
" '%s' %s and as such cannot be loaded. LLDB will"
" load '%s' instead. Consider removing the file with "
"the malformed name to"
" eliminate this warning.\n",
symfile_spec.GetPath().c_str(),
original_path_string.GetData(), reason_for_complaint,
path_string.GetData());
else
feedback_stream->Printf(
"warning: the symbol file '%s' contains a debug "
"script. However, its name"
" %s and as such cannot be loaded. If you intend"
" to have this script loaded, please rename '%s' to "
"'%s' and retry.\n",
symfile_spec.GetPath().c_str(), reason_for_complaint,
original_path_string.GetData(), path_string.GetData());
}
if (module_basename != original_module_basename &&
FileSystem::Instance().Exists(orig_script_fspec)) {
const char *reason_for_complaint =
was_keyword ? "conflicts with a keyword"
: "contains reserved characters";
if (FileSystem::Instance().Exists(script_fspec))
feedback_stream.Printf(
"warning: the symbol file '%s' contains a debug "
"script. However, its name"
" '%s' %s and as such cannot be loaded. LLDB will"
" load '%s' instead. Consider removing the file with "
"the malformed name to"
" eliminate this warning.\n",
symfile_spec.GetPath().c_str(),
original_path_string.GetData(), reason_for_complaint,
path_string.GetData());
else
feedback_stream.Printf(
"warning: the symbol file '%s' contains a debug "
"script. However, its name"
" %s and as such cannot be loaded. If you intend"
" to have this script loaded, please rename '%s' to "
"'%s' and retry.\n",
symfile_spec.GetPath().c_str(), reason_for_complaint,
original_path_string.GetData(), path_string.GetData());
}
if (FileSystem::Instance().Exists(script_fspec)) {

View File

@@ -69,7 +69,7 @@ public:
FileSpecList
LocateExecutableScriptingResources(Target *target, Module &module,
Stream *feedback_stream) override;
Stream &feedback_stream) override;
Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,

View File

@@ -158,7 +158,7 @@ Status Platform::GetFileWithUUID(const FileSpec &platform_file,
FileSpecList
Platform::LocateExecutableScriptingResources(Target *target, Module &module,
Stream *feedback_stream) {
Stream &feedback_stream) {
return FileSpecList();
}

View File

@@ -1393,8 +1393,8 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
Target *target) {
Status error;
StreamString feedback_stream;
if (module_sp && !module_sp->LoadScriptingResourceInTarget(
target, error, &feedback_stream)) {
if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error,
feedback_stream)) {
if (error.AsCString())
target->GetDebugger().GetErrorStream().Printf(
"unable to load scripting data for module %s - error reported was "