This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] fix PR c++/16117
- From: Doug Evans <dje at google dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Mon, 4 Nov 2013 15:04:33 -0800
- Subject: Re: [PATCH] fix PR c++/16117
- Authentication-results: sourceware.org; auth=none
- References: <1383599806-19444-1-git-send-email-tromey at redhat dot com>
On Mon, Nov 4, 2013 at 1:16 PM, Tom Tromey <tromey@redhat.com> wrote:
> This patch fixes PR c++/16117.
>
> gdb has an extension so that users can use expressions like FILE::NAME
> to choose a variable of the given name from the given file. The bug
> is that this extension takes precedence over ordinary C++ expressions
> of the same form. You might think this is merely hypothetical, but
> now that C++ headers commonly do not use an extension, it is more
> common.
>
> This patch fixes the bug by making two related changes. First, it
> changes gdb to prefer the ordinary C++ meaning of a symbol over the
> extended meaning. Second, it arranges for single-quoting of the
> symbol to indicate a preference for the extension.
Do we need a NEWS entry for the change in behaviour?
Also, and this is just for discussion's sake,
I wonder if we'll ever need to handle nested quoting some day (blech :-)).
> [...]
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 28e6ff9..9737355 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -8322,11 +8322,23 @@ $4 = 0
> @end smallexample
>
> @cindex C@t{++} scope resolution
> -These uses of @samp{::} are very rarely in conflict with the very similar
> -use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
> -scope resolution operator in @value{GDBN} expressions.
> -@c FIXME: Um, so what happens in one of those rare cases where it's in
> -@c conflict?? --mew
> +These uses of @samp{::} are very rarely in conflict with the very
> +similar use of the same notation in C@t{++}. When they are in
> +conflict, the C@t{++} meaning takes precedence; however, this can be
> +overridden by quoting the file or function name.
Can you add text to indicate "quoting" here means single-quotes *only*?
> +For example, suppose the program is stopped in a method of a class
> +that has a field named ``includefile'', and there is also an include
> +file named ``includefile'' that defines a variable, ``some_global''.
> +
> +@smallexample
> +(@value{GDBP}) p includefile
> +$1 = 23
> +(@value{GDBP}) p includefile::some_global
> +A syntax error in expression, near `'.
> +(@value{GDBP}) p 'includefile'::some_global
> +$2 = 27
> +@end smallexample
>
> @cindex wrong values
> @cindex variable values, wrong
> [...]
> diff --git a/gdb/testsuite/gdb.cp/filename.exp b/gdb/testsuite/gdb.cp/filename.exp
> new file mode 100644
> index 0000000..943cdc6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/filename.exp
> @@ -0,0 +1,37 @@
> +# Copyright 2013 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/>.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +standard_testfile .cc
> +
> +if [get_compiler_info "c++"] {
> + return -1
> +}
> +
> +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
> + return -1
> +}
> +
> +if ![runto_main] then {
> + perror "couldn't run to main"
> + continue
> +}
> +
> +gdb_breakpoint [gdb_get_line_number "stop here"]
> +gdb_continue_to_breakpoint "stop here"
> +
> +gdb_test "print includefile\[0\]" " = 23"
> +gdb_test "print 'includefile'::some_global" " = 27"
Is 'class'::member intended to work? (static member or whatever)
[It works today, but I didn't check if that's intended. I presume it is.]
If so, maybe a test to verify that still works as well?
I grepped for "'::" in gdb.cp/*.exp and didn't find anything of use.
Since we're touching single-quote handling here, I figure this is as
good a place as any.