[Lldb-commits] [lldb] 50e79d7 - [lldb] Minor cleanups at callsites of FileSpec::GetFileNameExtension

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Tue May 2 17:20:40 PDT 2023


Author: Alex Langford
Date: 2023-05-02T17:20:29-07:00
New Revision: 50e79d725c105344e292d1fe8044a69467c20346

URL: https://github.com/llvm/llvm-project/commit/50e79d725c105344e292d1fe8044a69467c20346
DIFF: https://github.com/llvm/llvm-project/commit/50e79d725c105344e292d1fe8044a69467c20346.diff

LOG: [lldb] Minor cleanups at callsites of FileSpec::GetFileNameExtension

FileSpec::GetFileNameExtension returns a StringRef. In some cases we
are calling it and then storing the result in a local. To prevent
cases where we store the StringRef, mutate the Filespec, and then try to
use the stored StringRef afterwards, I've audited the callsites and made
adjustments to mitigate: Either marking the FileSpec it comes from as
const (to avoid mutations) or by not storing the StringRef in a local if
it makes sense not to.

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

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectTarget.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
    lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 6d63b306d42a1..0a1cacfaf7509 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2161,7 +2161,7 @@ class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
     }
 
     const char *pcm_path = command.GetArgumentAtIndex(0);
-    FileSpec pcm_file{pcm_path};
+    const FileSpec pcm_file{pcm_path};
 
     if (pcm_file.GetFileNameExtension() != ".pcm") {
       result.AppendError("file must have a .pcm extension");

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
index 1a9229d76f439..a50d35b7d40ab 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -421,7 +421,7 @@ PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory(
   static constexpr llvm::StringLiteral g_kdk_suffix = ".kdk";
 
   PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton;
-  FileSpec file_spec(path);
+  const FileSpec file_spec(path);
   if (ft == llvm::sys::fs::file_type::directory_file &&
       (file_spec.GetFileNameExtension() == g_sdk_suffix ||
        file_spec.GetFileNameExtension() == g_kdk_suffix)) {
@@ -482,7 +482,7 @@ PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper(
   static constexpr llvm::StringLiteral g_kext_suffix = ".kext";
   static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM";
 
-  FileSpec file_spec(path);
+  const FileSpec file_spec(path);
   llvm::StringRef file_spec_extension = file_spec.GetFileNameExtension();
 
   Log *log = GetLog(LLDBLog::Platform);
@@ -691,7 +691,7 @@ bool PlatformDarwinKernel::KerneldSYMHasNoSiblingBinary(
 // it should iterate over every binary in the DWARF subdir
 // and return them all.
 std::vector<FileSpec>
-PlatformDarwinKernel::GetDWARFBinaryInDSYMBundle(FileSpec dsym_bundle) {
+PlatformDarwinKernel::GetDWARFBinaryInDSYMBundle(const FileSpec &dsym_bundle) {
   std::vector<FileSpec> results;
   static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM";
   if (dsym_bundle.GetFileNameExtension() != g_dsym_suffix) {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
index 1b0708cd9f8dc..e28f77cd44d55 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -137,7 +137,8 @@ class PlatformDarwinKernel : public PlatformDarwin {
   // with the binary inside it ('.../foo.dSYM/Contents/Resources/DWARF/foo').
   // A dSYM bundle may have multiple DWARF binaries in them, so a vector
   // of matches is returned.
-  static std::vector<FileSpec> GetDWARFBinaryInDSYMBundle(FileSpec dsym_bundle);
+  static std::vector<FileSpec>
+  GetDWARFBinaryInDSYMBundle(const FileSpec &dsym_bundle);
 
   Status GetSharedModuleKext(const ModuleSpec &module_spec, Process *process,
                              lldb::ModuleSP &module_sp,

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
index 852bb3bb14c6c..9c2227cc3884e 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -131,14 +131,13 @@ llvm::Error Lua::CheckSyntax(llvm::StringRef buffer) {
 }
 
 llvm::Error Lua::LoadModule(llvm::StringRef filename) {
-  FileSpec file(filename);
+  const FileSpec file(filename);
   if (!FileSystem::Instance().Exists(file)) {
     return llvm::make_error<llvm::StringError>("invalid path",
                                                llvm::inconvertibleErrorCode());
   }
 
-  llvm::StringRef module_extension = file.GetFileNameExtension();
-  if (module_extension != ".lua") {
+  if (file.GetFileNameExtension() != ".lua") {
     return llvm::make_error<llvm::StringError>("invalid extension",
                                                llvm::inconvertibleErrorCode());
   }


        


More information about the lldb-commits mailing list