From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2561 invoked by alias); 21 Apr 2010 20:34:06 -0000 Received: (qmail 2495 invoked by uid 22791); 21 Apr 2010 20:34:01 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=BAYES_00,TW_RG X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Apr 2010 20:33:56 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 253E72BACFA for ; Wed, 21 Apr 2010 16:33:55 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lluciuE2WFoN for ; Wed, 21 Apr 2010 16:33:55 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 0B4DC2BACEF for ; Wed, 21 Apr 2010 16:33:55 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 5C806F5895; Wed, 21 Apr 2010 13:33:54 -0700 (PDT) Date: Wed, 21 Apr 2010 20:34:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Cc: gdb-patches@sourceware.org Subject: [RFC] Do not treat '\' as escape character on MinGW Windows hosts Message-ID: <20100421203354.GD6588@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="uAKRQypu60I7Lcqm" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-04/txt/msg00702.txt.bz2 --uAKRQypu60I7Lcqm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1763 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 --uAKRQypu60I7Lcqm Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="argv-mingw.diff" Content-length: 1104 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; } --uAKRQypu60I7Lcqm--