[Lldb-commits] [lldb] [lldb] Replace ConstString in Platform::GetFullNameForDylib (PR #214874)

via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 7 15:48:54 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

<details>
<summary>Changes</summary>

Basename is read-only, so it can be a StringRef. Similarly, there's no need to create a ConstString of a dylib name that may or may not exist.

---
Full diff: https://github.com/llvm/llvm-project/pull/214874.diff


8 Files Affected:

- (modified) lldb/include/lldb/Target/Platform.h (+1-1) 
- (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (+4-6) 
- (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h (+1-1) 
- (modified) lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (+4-6) 
- (modified) lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h (+1-1) 
- (modified) lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp (+4-6) 
- (modified) lldb/source/Plugins/Platform/Windows/PlatformWindows.h (+1-1) 
- (modified) lldb/source/Target/Platform.cpp (+2-2) 


``````````diff
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 8760cb9fc6a8c..bf7a3faf30eaf 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -204,7 +204,7 @@ class Platform : public PluginInterface {
 
   virtual const char *GetHostname();
 
-  virtual ConstString GetFullNameForDylib(ConstString basename);
+  virtual std::string GetFullNameForDylib(llvm::StringRef basename);
 
   virtual llvm::StringRef GetDescription() = 0;
 
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 8efe164dd2901..daddc2b162ef4 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1249,13 +1249,11 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
   }
 }
 
-ConstString PlatformDarwin::GetFullNameForDylib(ConstString basename) {
-  if (basename.IsEmpty())
-    return basename;
+std::string PlatformDarwin::GetFullNameForDylib(llvm::StringRef basename) {
+  if (basename.empty())
+    return basename.str();
 
-  StreamString stream;
-  stream.Printf("lib%s.dylib", basename.GetCString());
-  return ConstString(stream.GetString());
+  return llvm::formatv("lib{0}.dylib", basename).str();
 }
 
 llvm::VersionTuple PlatformDarwin::GetOSVersion(Process *process) {
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 7c10216bb8b2e..3415f74a8fbe8 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -110,7 +110,7 @@ class PlatformDarwin : public PlatformPOSIX {
 
   bool SupportsModules() override { return true; }
 
-  ConstString GetFullNameForDylib(ConstString basename) override;
+  std::string GetFullNameForDylib(llvm::StringRef basename) override;
 
   FileSpec LocateExecutable(const char *basename) override;
 
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index 1a62145083f8f..d297b97ab24f7 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -999,11 +999,9 @@ PlatformPOSIX::GetLibdlFunctionDeclarations(lldb_private::Process *process) {
              )";
 }
 
-ConstString PlatformPOSIX::GetFullNameForDylib(ConstString basename) {
-  if (basename.IsEmpty())
-    return basename;
+std::string PlatformPOSIX::GetFullNameForDylib(llvm::StringRef basename) {
+  if (basename.empty())
+    return basename.str();
 
-  StreamString stream;
-  stream.Printf("lib%s.so", basename.GetCString());
-  return ConstString(stream.GetString());
+  return llvm::formatv("lib{0}.so", basename).str();
 }
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
index 511797ce6bb7c..0a02ecd279cfe 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -67,7 +67,7 @@ class PlatformPOSIX : public lldb_private::RemoteAwarePlatform {
   lldb_private::Status UnloadImage(lldb_private::Process *process,
                                    uint32_t image_token) override;
 
-  lldb_private::ConstString GetFullNameForDylib(lldb_private::ConstString basename) override;
+  std::string GetFullNameForDylib(llvm::StringRef basename) override;
 
 protected:
   std::unique_ptr<lldb_private::OptionGroupPlatformRSync>
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index 224d13babfd12..7aadc37d0e1fc 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -686,13 +686,11 @@ void PlatformWindows::GetStatus(Stream &strm) {
 
 bool PlatformWindows::CanDebugProcess() { return true; }
 
-ConstString PlatformWindows::GetFullNameForDylib(ConstString basename) {
-  if (basename.IsEmpty())
-    return basename;
+std::string PlatformWindows::GetFullNameForDylib(llvm::StringRef basename) {
+  if (basename.empty())
+    return basename.str();
 
-  StreamString stream;
-  stream.Printf("%s.dll", basename.GetCString());
-  return ConstString(stream.GetString());
+  return llvm::formatv("{0}.dll", basename).str();
 }
 
 size_t
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
index dff3113686c39..6f8c20a8456a2 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
@@ -77,7 +77,7 @@ class PlatformWindows : public RemoteAwarePlatform {
   // FIXME not sure what the _sigtramp equivalent would be on this platform
   void CalculateTrapHandlerSymbolNames() override {}
 
-  ConstString GetFullNameForDylib(ConstString basename) override;
+  std::string GetFullNameForDylib(llvm::StringRef basename) override;
 
   size_t GetSoftwareBreakpointTrapOpcode(Target &target,
                                          BreakpointSite *bp_site) override;
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 0b2290c98d55e..4113592bddec3 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -791,8 +791,8 @@ const char *Platform::GetHostname() {
   return m_hostname.c_str();
 }
 
-ConstString Platform::GetFullNameForDylib(ConstString basename) {
-  return basename;
+std::string Platform::GetFullNameForDylib(llvm::StringRef basename) {
+  return basename.str();
 }
 
 bool Platform::SetRemoteWorkingDirectory(const FileSpec &working_dir) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/214874


More information about the lldb-commits mailing list