Improve process launch comments for Windows

The existing comment about over-allocating the command line was incorrect.  The
contents of the command line may be changed, but it's not necessary to over
allocate.  The changes will be limited to the existing contents of the string
(e.g., by replacing spaces with L'\0' to tokenize the command line).

Also added a comment explaining a possible cause of failure to save the next
programmer some time when they try to debug a 64-bit process from a 32-bit
LLDB.

llvm-svn: 355121
This commit is contained in:
Adrian McCarthy 2019-02-28 19:14:02 +00:00
parent e47d32f165
commit 34f2bee0fb
1 changed files with 7 additions and 3 deletions

View File

@ -104,17 +104,21 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
llvm::ConvertUTF8toWide(commandLine, wcommandLine); llvm::ConvertUTF8toWide(commandLine, wcommandLine);
llvm::ConvertUTF8toWide(launch_info.GetWorkingDirectory().GetCString(), llvm::ConvertUTF8toWide(launch_info.GetWorkingDirectory().GetCString(),
wworkingDirectory); wworkingDirectory);
// If the command line is empty, it's best to pass a null pointer to tell
// CreateProcessW to use the executable name as the command line. If the
// command line is not empty, its contents may be modified by CreateProcessW.
WCHAR *pwcommandLine = wcommandLine.empty() ? nullptr : &wcommandLine[0];
wcommandLine.resize(PATH_MAX); // Needs to be over-allocated because
// CreateProcessW can modify it
BOOL result = ::CreateProcessW( BOOL result = ::CreateProcessW(
wexecutable.c_str(), &wcommandLine[0], NULL, NULL, TRUE, flags, env_block, wexecutable.c_str(), pwcommandLine, NULL, NULL, TRUE, flags, env_block,
wworkingDirectory.size() == 0 ? NULL : wworkingDirectory.c_str(), wworkingDirectory.size() == 0 ? NULL : wworkingDirectory.c_str(),
&startupinfo, &pi); &startupinfo, &pi);
if (!result) { if (!result) {
// Call GetLastError before we make any other system calls. // Call GetLastError before we make any other system calls.
error.SetError(::GetLastError(), eErrorTypeWin32); error.SetError(::GetLastError(), eErrorTypeWin32);
// Note that error 50 ("The request is not supported") will occur if you
// try debug a 64-bit inferior from a 32-bit LLDB.
} }
if (result) { if (result) {