[RFA] 12843

Keith Seitz
2011-08-25T21:59:21Z

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

Hi,

A long time ago, some linespec hacking that I did broke the ability to
use drive letters on Windows. This turned out especially bad since
linespec canonicalization could unexpectedly (to the user) include them.
As a result, gdb was/is unable to re-set some breakpoints on Windows hosts.

This is a pretty simple patch to workaround this problem. It is not
perfect, but implementing something "proper" would be very involved, and
I am not quite sure I want to commit to hacking more of linespec.c
without rewriting the whole thing (which would certainly interfer with
Tom's ambiguous linespec work).

So I'm not sure whether this should be an RFC or and RFA, but I've
decided the later.

This patch checks if ':' is followed by '/' and/or '\\' (depending on
definition of IS_DIR_SEPARATOR). If it is, we keep looking for the next
terminal in the string. This is problematic for filenames with ":\\" or
"://" in them, but locate_first_half has gotten those wrong for a long,
long time (in fact, any filename at all with a colon(s) in it).

In any case, this patch will allow Windows hosts to function properly
again, and causes no regressions on x86_64-linux and i686-pc-cygwin32.

Keith

ChangeLog
2011-08-25 Keith Seitz <keiths@redhat.com>

PR gdb/12843
* linespec.c (locate_first_half): Do not stop on a colon
if the next character is a directory separator character.

testsuite/ChangeLog
2011-08-25 Keith Seitz <keiths@redhat.com>

PR gdb/12843
* gdb.base/ls-driveletter.exp: New file.

[-- Attachment #2: 12843.patch --]
[-- Type: text/plain, Size: 2399 bytes --]

diff --git a/gdb/linespec.c b/gdb/linespec.c
index b96c79f..b35ac6a 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -43,6 +43,7 @@
#include "arch-utils.h"
#include <ctype.h>
#include "cli/cli-utils.h"
+#include "filenames.h"

/* Prototypes for local functions. */

@@ -1216,10 +1217,16 @@ locate_first_half (char **argptr, int *is_quote_enclosed)
}
/* Check for the end of the first half of the linespec. End of
line, a tab, a colon or a space. But if enclosed in double
- quotes we do not break on enclosed spaces. */
+ quotes we do not break on enclosed spaces.
+
+ Colons are especially problematic, since we don't really want to stop
+ if the colon is part of a filename. The simple heuristic used here
+ is to keep going if the colon is followed by a directory separator.
+ This will capture drive letters on Windows, but it will (still) fail
+ for any filename containing ":", "::", ":/", or ":\\". */
if (!*p
|| p[0] == '\t'
- || (p[0] == ':')
+ || (p[0] == ':' && !IS_DIR_SEPARATOR (p[1]))
|| ((p[0] == ' ') && !*is_quote_enclosed))
break;
if (p[0] == '.' && strchr (p, ':') == NULL)
diff --git a/gdb/testsuite/gdb.base/ls-driveletter.exp b/gdb/testsuite/gdb.base/ls-driveletter.exp
new file mode 100644
index 0000000..66efd1f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/ls-driveletter.exp
@@ -0,0 +1,26 @@
+# Copyright 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test linespecs containing drive letters.
+# PR gdb/12843
+
+# We don't actually need our own test case to test this, so grab
+# another one.
+
+if {[prepare_for_testing ls-driveletter.exp memattr memattr.c {debug}]} {
+ return -1
+}
+
+gdb_test "list c:/foo/bar/baz.c:1" "No source file named c:/foo/bar/baz.c."