]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[Windows] run program with space in path to exe.
authorJoel Brobecker <brobecker@gnat.com>
Wed, 24 Oct 2012 13:40:16 +0000 (13:40 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Wed, 24 Oct 2012 13:40:16 +0000 (13:40 +0000)
The following works...

    % gdb c:\path to exe\foo.exe
    (gdb) start

... unless a file or directory called "c:\path" or "c:\path to" exist.
This is what happens in the latter case:

    (gdb) start
    [...]
    Error creating process C:\path to exe\foo.exe (error 193).

This is because we are calling CreateProcess (et al) without specifying
the lpApplicationName, so Windows determines the name of the executable
using the second argument, which is the entire command line.  This
command line is a space-separated list of tokens, so the space in
the path to the executable which potentially creates an ambiguity.
The ambiguity is automatically resolved unless we're in the situation
above.

The solution, as suggested by the MSDN documentation for CreateProcess
is to quote the executable name.

gdb/ChangeLog:

        * windows-nat.c (windows_create_inferior) [!__CYGWIN__]:
        New local variable args_len.
        Quote the name of the executable when computing the command line.

gdb/ChangeLog
gdb/windows-nat.c

index 2ccc5d791261c62d78f376a60ff3bdfe600fba1a..0a5e79ce5ba44c75324ae72cb5ad472eb464795d 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-24  Joel Brobecker  <brobecker@adacore.com>
+
+       * windows-nat.c (windows_create_inferior) [!__CYGWIN__]:
+       New local variable args_len.
+       Quote the name of the executable when computing the command line.
+
 2012-10-23  Mark Kettenis  <kettenis@gnu.org>
 
        PR gdb/12796
index 905d4bfe2e3bcdb6a184c3eefdfda2636b353342..5eb8f6710a9069477894a6083cdd276a8a5f49b9 100644 (file)
@@ -2036,6 +2036,7 @@ windows_create_inferior (struct target_ops *ops, char *exec_file,
   char shell[__PMAX]; /* Path to shell */
   char *toexec;
   char *args;
+  size_t args_len;
   HANDLE tty;
   char *w32env;
   char *temp;
@@ -2188,10 +2189,13 @@ windows_create_inferior (struct target_ops *ops, char *exec_file,
     }
 #else
   toexec = exec_file;
-  args = alloca (strlen (toexec) + strlen (allargs) + 2);
-  strcpy (args, toexec);
-  strcat (args, " ");
-  strcat (args, allargs);
+  /* Build the command line, a space-separated list of tokens where
+     the first token is the name of the module to be executed.
+     To avoid ambiguities introduced by spaces in the module name,
+     we quote it.  */
+  args_len = strlen (toexec) + 2 /* quotes */ + strlen (allargs) + 2;
+  args = alloca (args_len);
+  xsnprintf (args, args_len, "\"%s\" %s", toexec, allargs);
 
   flags |= DEBUG_ONLY_THIS_PROCESS;