amccarth updated this revision to Diff 188263.
amccarth added a comment.

Forgot to include context in original diff.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58648/new/

https://reviews.llvm.org/D58648

Files:
  lldb/source/Host/windows/ProcessLauncherWindows.cpp


Index: lldb/source/Host/windows/ProcessLauncherWindows.cpp
===================================================================
--- lldb/source/Host/windows/ProcessLauncherWindows.cpp
+++ lldb/source/Host/windows/ProcessLauncherWindows.cpp
@@ -104,17 +104,21 @@
   llvm::ConvertUTF8toWide(commandLine, wcommandLine);
   llvm::ConvertUTF8toWide(launch_info.GetWorkingDirectory().GetCString(),
                           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(
-      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(),
       &startupinfo, &pi);
 
   if (!result) {
     // Call GetLastError before we make any other system calls.
     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) {


Index: lldb/source/Host/windows/ProcessLauncherWindows.cpp
===================================================================
--- lldb/source/Host/windows/ProcessLauncherWindows.cpp
+++ lldb/source/Host/windows/ProcessLauncherWindows.cpp
@@ -104,17 +104,21 @@
   llvm::ConvertUTF8toWide(commandLine, wcommandLine);
   llvm::ConvertUTF8toWide(launch_info.GetWorkingDirectory().GetCString(),
                           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(
-      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(),
       &startupinfo, &pi);
 
   if (!result) {
     // Call GetLastError before we make any other system calls.
     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) {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to