Skip to content

Commit dc67b57

Browse files
[lldb] Respect arg0 override in fork/exec launcher
1 parent ea0a08e commit dc67b57

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lldb/source/Host/posix/ProcessLauncherPosixFork.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct ForkLaunchInfo {
9494
bool debug;
9595
bool disable_aslr;
9696
std::string wd;
97+
std::string executable;
9798
const char **argv;
9899
Environment::Envp envp;
99100
std::vector<ForkFileAction> actions;
@@ -194,7 +195,8 @@ struct ForkLaunchInfo {
194195
}
195196

196197
// Execute. We should never return...
197-
execve(info.argv[0], const_cast<char *const *>(info.argv), info.envp);
198+
execve(info.executable.c_str(), const_cast<char *const *>(info.argv),
199+
info.envp);
198200

199201
#if defined(__linux__)
200202
if (errno == ETXTBSY) {
@@ -207,7 +209,8 @@ struct ForkLaunchInfo {
207209
// Since this state should clear up quickly, wait a while and then give it
208210
// one more go.
209211
usleep(50000);
210-
execve(info.argv[0], const_cast<char *const *>(info.argv), info.envp);
212+
execve(info.executable.c_str(), const_cast<char *const *>(info.argv),
213+
info.envp);
211214
}
212215
#endif
213216

@@ -236,8 +239,17 @@ ForkLaunchInfo::ForkLaunchInfo(const ProcessLaunchInfo &info)
236239
debug(info.GetFlags().Test(eLaunchFlagDebug)),
237240
disable_aslr(info.GetFlags().Test(eLaunchFlagDisableASLR)),
238241
wd(info.GetWorkingDirectory().GetPath()),
242+
executable(info.GetExecutableFile().GetPath()),
239243
argv(info.GetArguments().GetConstArgumentVector()),
240-
envp(info.GetEnvironment().getEnvp()), actions(MakeForkActions(info)) {}
244+
envp(info.GetEnvironment().getEnvp()), actions(MakeForkActions(info)) {
245+
// If we didn't get an executable, use args vector to locate the executable
246+
// instead
247+
if (executable.empty())
248+
executable = argv[0];
249+
// If it was requested to override arg 0 at exec, respect that
250+
if (!info.GetArg0().empty())
251+
argv[0] = info.GetArg0().data();
252+
}
241253

242254
HostProcess
243255
ProcessLauncherPosixFork::LaunchProcess(const ProcessLaunchInfo &launch_info,

0 commit comments

Comments
 (0)