Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] Do not treat '\' as escape character on MinGW Windows hosts
@ 2010-04-21 20:34 Joel Brobecker
  2010-04-21 22:08 ` Christopher Faylor
  2010-05-05 18:49 ` Joel Brobecker
  0 siblings, 2 replies; 16+ messages in thread
From: Joel Brobecker @ 2010-04-21 20:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1763 bytes --]

Hello,

With the MinGW debugger, it is currently not possible to use a path
that follows the Windows convention.  For instance:

        (gdb) file c:\foo\bar.exe
        c:foobar.exe: No such file or directory.

This is because the routine that parses arguments treats all backslashes
as an escape character.  With a MinGW tool, this does not make sense
when the argument is a path, since the canonical directory separator
on Windows is a backslash...

What the user has to do, at this point, is escape every backslash,
which can be quite painful when the path starts getting longer...

        (gdb) file c:\\foo\\bar.exe
        Reading symbols from c:\foo\bar.exe...done.

What we have done, at AdaCore, is disabling the special nature of
the backslash character when the host is MinGW (we left cygwin alone,
since cygwin users most likely expect a unix-y type of behavior).
It's a incompatible change, and as you'll see with the attached patch,
it changes the behavior for all arguments, not just path names.
Polling the few Windows users we have a AdaCore, they all seem to agree
that they did not expect backslash to be a special character in any
context, so the change seemed right to them.

Before officially submitting this patch for inclusion (including
formal testing), I wanted to see what the feeling towards this sort
of change was...

Note that GDB uses a wrapper around this routine, mostly to add
an out-of-memory exception raised when the routine returns null.
One possible way of achieving the same result, while limiting the
change to GDB alone, would be to modify the gdb_buildargv routine
to escape all backslashes before calling libiberty's buildargv.
But I think that other tools should also consider this change as
beneficial.

-- 
Joel

[-- Attachment #2: argv-mingw.diff --]
[-- Type: text/x-diff, Size: 1104 bytes --]

diff --git a/libiberty/argv.c b/libiberty/argv.c
index 3084248..b5cf71f 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -177,7 +177,8 @@ returned, as appropriate.
 
 */
 
-char **buildargv (const char *input)
+char **
+buildargv (const char *input)
 {
   char *arg;
   char *copybuf;
@@ -189,6 +190,15 @@ char **buildargv (const char *input)
   char **argv = NULL;
   char **nargv;
 
+/* On Windows hosts, the backslash character should not be treated
+   as an escape character.  Define a constant bs_is_escape whose value
+   is non-zero when the backslash is an escape character.  */
+#if !defined (__MINGW32__)
+  const int bs_is_escape = 1;
+#else
+  const int bs_is_escape = 0;
+#endif
+
   if (input != NULL)
     {
       copybuf = (char *) alloca (strlen (input) + 1);
@@ -234,12 +244,12 @@ char **buildargv (const char *input)
 		}
 	      else
 		{
-		  if (bsquote)
+		  if (bs_is_escape && bsquote)
 		    {
 		      bsquote = 0;
 		      *arg++ = *input;
 		    }
-		  else if (*input == '\\')
+		  else if (bs_is_escape && (*input == '\\'))
 		    {
 		      bsquote = 1;
 		    }

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-06-04 21:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21 20:34 [RFC] Do not treat '\' as escape character on MinGW Windows hosts Joel Brobecker
2010-04-21 22:08 ` Christopher Faylor
2010-04-22  0:17   ` Joel Brobecker
2010-04-22  2:34     ` Christopher Faylor
2010-04-22  8:17       ` Mark Kettenis
2010-04-22 10:37       ` Joel Brobecker
2010-04-22 11:51         ` Joel Brobecker
2010-04-22 12:01           ` Pierre Muller
2010-04-22 12:26             ` Joel Brobecker
2010-04-22 11:54         ` Chris Moller
2010-04-22 12:33           ` Joel Brobecker
2010-04-22 11:49       ` Chris Moller
2010-04-22 12:47       ` André Pönitz
2010-05-05 18:49 ` Joel Brobecker
2010-05-06 23:56   ` Sergio Durigan Junior
2010-06-04 21:53     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox