Author: Alex Langford
Date: 2023-07-11T10:36:11-07:00
New Revision: 1d796b48e4d48bd0e4b29972a1b8d653493ee30c

URL: 
https://github.com/llvm/llvm-project/commit/1d796b48e4d48bd0e4b29972a1b8d653493ee30c
DIFF: 
https://github.com/llvm/llvm-project/commit/1d796b48e4d48bd0e4b29972a1b8d653493ee30c.diff

LOG: [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

Added: 
    

Modified: 
    lldb/include/lldb/Core/Module.h
    lldb/include/lldb/Core/ModuleList.h
    lldb/include/lldb/Target/Platform.h
    lldb/include/lldb/Target/Target.h
    lldb/source/Commands/CommandObjectTarget.cpp
    lldb/source/Core/Debugger.cpp
    lldb/source/Core/Module.cpp
    lldb/source/Core/ModuleList.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    lldb/source/Target/Platform.cpp
    lldb/source/Target/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index 565c613f637021..67e15120f5e786 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -563,7 +563,7 @@ class Module : public std::enable_shared_from_this<Module>,
   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.
   ///

diff  --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index 631d7889f36796..28c1945c83c478 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -440,7 +440,7 @@ class ModuleList {
   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();

diff  --git a/lldb/include/lldb/Target/Platform.h 
b/lldb/include/lldb/Target/Platform.h
index b556e1aa3dd2e7..35227429b126ae 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -286,7 +286,7 @@ class Platform : public PluginInterface {
   // 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,

diff  --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 50cd315b0fdfa7..ed0ecbbddbf814 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -939,7 +939,7 @@ class Target : public std::enable_shared_from_this<Target>,
       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);

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 1b40651b7a4345..3e024ff91b382d 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4219,7 +4219,7 @@ class CommandObjectTargetSymbolsAdd : public 
CommandObjectParsed {
           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 "

diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 4f06ed07274914..f5410862918548 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -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());

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index be61f6f138c00b..672d86496bde6d 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -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;

diff  --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 212b1186b4ef95..d0d0b2050e181c 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -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;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index f3f0fd7de37512..5fd666b8ce8b58 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -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)) {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index a51e0b9cf2ac39..005dea5190604d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -69,7 +69,7 @@ class PlatformDarwin : public PlatformPOSIX {
 
   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,

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 15bc2091ab80af..eedf596f1977f3 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -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();
 }
 

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 6b255e084b28b7..06867d359a3c0f 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -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 "


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to