bulbazord created this revision. bulbazord added reviewers: JDevlieghere, mib, jingham, jasonmolenda. Herald added a project: All. bulbazord requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
FileSpec::GetFileNameExtension returns a StringRef. In some cases we are calling it and then storing the result in a StringRef. To prevent cases where we store the StringRef, mutate the Filespec, and then try to use the FileSpec 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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D149671 Files: 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 Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp @@ -131,14 +131,13 @@ } 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()); } Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h +++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h @@ -137,7 +137,8 @@ // 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, Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -422,7 +422,7 @@ 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)) { @@ -483,7 +483,7 @@ 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); @@ -692,7 +692,7 @@ // 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) { Index: lldb/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -2161,7 +2161,7 @@ } 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");
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp @@ -131,14 +131,13 @@ } 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()); } Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h +++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h @@ -137,7 +137,8 @@ // 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, Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -422,7 +422,7 @@ 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)) { @@ -483,7 +483,7 @@ 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); @@ -692,7 +692,7 @@ // 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) { Index: lldb/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -2161,7 +2161,7 @@ } 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");
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits