Author: Alex Langford
Date: 2023-07-03T10:03:49-07:00
New Revision: 1b102886c0c33bb01ff8f2360b57c7b8d039abcc

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

LOG: [lldb][NFCI] Change return type of GetProcessPluginName

Instead of just returning a raw `const char *`, I think llvm::StringRef
would make more sense. Most of the time that we use the return value of
`GetProcessPluginName` we're passing it to `CreateProcess` which takes a
StringRef anyway.

Differential Revision: https://reviews.llvm.org/D153825

Added: 
    

Modified: 
    lldb/include/lldb/Host/ProcessLaunchInfo.h
    lldb/include/lldb/Target/Process.h
    lldb/source/Host/common/ProcessLaunchInfo.cpp
    lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
    lldb/source/Target/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/ProcessLaunchInfo.h 
b/lldb/include/lldb/Host/ProcessLaunchInfo.h
index 891f46f650c8c5..25762bc65295d8 100644
--- a/lldb/include/lldb/Host/ProcessLaunchInfo.h
+++ b/lldb/include/lldb/Host/ProcessLaunchInfo.h
@@ -68,7 +68,7 @@ class ProcessLaunchInfo : public ProcessInfo {
 
   void SetWorkingDirectory(const FileSpec &working_dir);
 
-  const char *GetProcessPluginName() const;
+  llvm::StringRef GetProcessPluginName() const;
 
   void SetProcessPluginName(llvm::StringRef plugin);
 

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index cf0ddeed67e832..b358b7497ff9be 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -147,8 +147,8 @@ class ProcessAttachInfo : public ProcessInstanceInfo {
 
   void SetResumeCount(uint32_t c) { m_resume_count = c; }
 
-  const char *GetProcessPluginName() const {
-    return (m_plugin_name.empty() ? nullptr : m_plugin_name.c_str());
+  llvm::StringRef GetProcessPluginName() const {
+    return llvm::StringRef(m_plugin_name);
   }
 
   void SetProcessPluginName(llvm::StringRef plugin) {

diff  --git a/lldb/source/Host/common/ProcessLaunchInfo.cpp 
b/lldb/source/Host/common/ProcessLaunchInfo.cpp
index e737815750b2c0..0e2c3da11ba9fb 100644
--- a/lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ b/lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -126,8 +126,8 @@ void ProcessLaunchInfo::SetWorkingDirectory(const FileSpec 
&working_dir) {
   m_working_dir = working_dir;
 }
 
-const char *ProcessLaunchInfo::GetProcessPluginName() const {
-  return (m_plugin_name.empty() ? nullptr : m_plugin_name.c_str());
+llvm::StringRef ProcessLaunchInfo::GetProcessPluginName() const {
+  return llvm::StringRef(m_plugin_name);
 }
 
 void ProcessLaunchInfo::SetProcessPluginName(llvm::StringRef plugin) {

diff  --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp 
b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index 017318fe4b4204..1301a301f2111d 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -533,9 +533,9 @@ lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo 
&attach_info,
   if (!target || error.Fail())
     return process_sp;
 
-  const char *plugin_name = attach_info.GetProcessPluginName();
-  process_sp = target->CreateProcess(
-      attach_info.GetListenerForProcess(debugger), plugin_name, nullptr, 
false);
+  process_sp =
+      target->CreateProcess(attach_info.GetListenerForProcess(debugger),
+                            attach_info.GetProcessPluginName(), nullptr, 
false);
 
   process_sp->HijackProcessEvents(attach_info.GetHijackListener());
   if (process_sp)

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 1444bb6d1217ec..17181569cbca29 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3209,8 +3209,8 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, 
Stream *stream) {
       assert(m_process_sp);
     } else {
       // Use a Process plugin to construct the process.
-      const char *plugin_name = launch_info.GetProcessPluginName();
-      CreateProcess(launch_info.GetListener(), plugin_name, nullptr, false);
+      CreateProcess(launch_info.GetListener(),
+                    launch_info.GetProcessPluginName(), nullptr, false);
     }
 
     // Since we didn't have a platform launch the process, launch it here.
@@ -3371,14 +3371,14 @@ Status Target::Attach(ProcessAttachInfo &attach_info, 
Stream *stream) {
   } else {
     if (state != eStateConnected) {
       SaveScriptedLaunchInfo(attach_info);
-      const char *plugin_name = attach_info.GetProcessPluginName();
+      llvm::StringRef plugin_name = attach_info.GetProcessPluginName();
       process_sp =
           CreateProcess(attach_info.GetListenerForProcess(GetDebugger()),
                         plugin_name, nullptr, false);
-      if (process_sp == nullptr) {
-        error.SetErrorStringWithFormat(
-            "failed to create process using plugin %s",
-            (plugin_name) ? plugin_name : "null");
+      if (!process_sp) {
+        error.SetErrorStringWithFormatv(
+            "failed to create process using plugin '{0}'",
+            plugin_name.empty() ? "<empty>" : plugin_name);
         return error;
       }
     }


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

Reply via email to