[Lldb-commits] [lldb] 6b51e26 - [lldb][NFCI] Remove FileAction::GetPath (#170764)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 5 11:17:13 PST 2025
Author: Alex Langford
Date: 2025-12-05T11:17:09-08:00
New Revision: 6b51e26d39fa6ed5cf4a204921701e8168b39099
URL: https://github.com/llvm/llvm-project/commit/6b51e26d39fa6ed5cf4a204921701e8168b39099
DIFF: https://github.com/llvm/llvm-project/commit/6b51e26d39fa6ed5cf4a204921701e8168b39099.diff
LOG: [lldb][NFCI] Remove FileAction::GetPath (#170764)
This method puts strings into the ConstString pool and vends them as
llvm::StringRefs. Most of the uses only require a `std::string` or a
`const char *`. This can be achieved without wasting memory.
Added:
Modified:
lldb/include/lldb/Host/FileAction.h
lldb/source/Host/common/FileAction.cpp
lldb/source/Host/macosx/objcxx/Host.mm
lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
lldb/source/Target/Target.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Host/FileAction.h b/lldb/include/lldb/Host/FileAction.h
index d3166c16a5854..b2cc8be32d296 100644
--- a/lldb/include/lldb/Host/FileAction.h
+++ b/lldb/include/lldb/Host/FileAction.h
@@ -39,8 +39,6 @@ class FileAction {
int GetActionArgument() const { return m_arg; }
- llvm::StringRef GetPath() const;
-
const FileSpec &GetFileSpec() const;
void Dump(Stream &stream) const;
diff --git a/lldb/source/Host/common/FileAction.cpp b/lldb/source/Host/common/FileAction.cpp
index e1c3e14a165ea..ec271f7b920d8 100644
--- a/lldb/source/Host/common/FileAction.cpp
+++ b/lldb/source/Host/common/FileAction.cpp
@@ -25,10 +25,6 @@ void FileAction::Clear() {
m_file_spec.Clear();
}
-llvm::StringRef FileAction::GetPath() const {
- return m_file_spec.GetPathAsConstString().AsCString();
-}
-
const FileSpec &FileAction::GetFileSpec() const { return m_file_spec; }
bool FileAction::Open(int fd, const FileSpec &file_spec, bool read,
diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index 96a282c64e44c..16bca0f1b0079 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -1013,20 +1013,29 @@ static Status LaunchProcessXPC(const char *exe_path,
xpc_dictionary_set_int64(message, LauncherXPCServicePosixspawnFlagsKey,
GetPosixspawnFlags(launch_info));
const FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
- if (file_action && !file_action->GetPath().empty()) {
+ std::string file_action_path;
+ if (file_action)
+ file_action_path = file_action->GetFileSpec().GetPath();
+
+ if (!file_action_path.empty())
xpc_dictionary_set_string(message, LauncherXPCServiceStdInPathKeyKey,
- file_action->GetPath().str().c_str());
- }
+ file_action_path.c_str());
+
file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
- if (file_action && !file_action->GetPath().empty()) {
+ if (file_action)
+ file_action_path = file_action->GetFileSpec().GetPath();
+
+ if (!file_action_path.empty())
xpc_dictionary_set_string(message, LauncherXPCServiceStdOutPathKeyKey,
- file_action->GetPath().str().c_str());
- }
+ file_action_path.c_str());
+
file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
- if (file_action && !file_action->GetPath().empty()) {
+ if (file_action)
+ file_action_path = file_action->GetFileSpec().GetPath();
+
+ if (!file_action_path.empty())
xpc_dictionary_set_string(message, LauncherXPCServiceStdErrPathKeyKey,
- file_action->GetPath().str().c_str());
- }
+ file_action_path.c_str());
xpc_object_t reply =
xpc_connection_send_message_with_reply_sync(conn, message);
@@ -1135,16 +1144,16 @@ static bool AddPosixSpawnFileAction(void *_file_actions, const FileAction *info,
if (oflag & O_CREAT)
mode = 0640;
- error = Status(::posix_spawn_file_actions_addopen(
- file_actions, info->GetFD(),
- info->GetPath().str().c_str(), oflag, mode),
- eErrorTypePOSIX);
+ const std::string file_path(info->GetFileSpec().GetPath());
+ error = Status(
+ ::posix_spawn_file_actions_addopen(file_actions, info->GetFD(),
+ file_path.c_str(), oflag, mode),
+ eErrorTypePOSIX);
if (error.Fail())
LLDB_LOG(log,
"error: {0}, posix_spawn_file_actions_addopen (action={1}, "
"fd={2}, path='{3}', oflag={4}, mode={5})",
- error, file_actions, info->GetFD(), info->GetPath(), oflag,
- mode);
+ error, file_actions, info->GetFD(), file_path, oflag, mode);
}
break;
}
diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
index 15a809784fbc4..a5f5cc52697e4 100644
--- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -229,8 +229,8 @@ struct ForkLaunchInfo {
// End of code running in the child process.
ForkFileAction::ForkFileAction(const FileAction &act)
- : action(act.GetAction()), fd(act.GetFD()), path(act.GetPath().str()),
- arg(act.GetActionArgument()) {}
+ : action(act.GetAction()), fd(act.GetFD()),
+ path(act.GetFileSpec().GetPath()), arg(act.GetActionArgument()) {}
static std::vector<ForkFileAction>
MakeForkActions(const ProcessLaunchInfo &info) {
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index b6a662ad3f14d..2305f1019ea4f 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -5145,17 +5145,17 @@ void TargetProperties::SetProcessLaunchInfo(
const FileAction *input_file_action =
launch_info.GetFileActionForFD(STDIN_FILENO);
if (input_file_action) {
- SetStandardInputPath(input_file_action->GetPath());
+ SetStandardInputPath(input_file_action->GetFileSpec().GetPath());
}
const FileAction *output_file_action =
launch_info.GetFileActionForFD(STDOUT_FILENO);
if (output_file_action) {
- SetStandardOutputPath(output_file_action->GetPath());
+ SetStandardOutputPath(output_file_action->GetFileSpec().GetPath());
}
const FileAction *error_file_action =
launch_info.GetFileActionForFD(STDERR_FILENO);
if (error_file_action) {
- SetStandardErrorPath(error_file_action->GetPath());
+ SetStandardErrorPath(error_file_action->GetFileSpec().GetPath());
}
SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));
More information about the lldb-commits
mailing list