This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: GDB can't parse variables named "memory" or "array"?
- From: Paul Smith <paul at mad-scientist dot net>
- To: Sergio Durigan Junior <sergiodj at redhat dot com>
- Cc: "gdb at sourceware dot org" <gdb at sourceware dot org>
- Date: Fri, 29 Sep 2017 16:17:18 -0400
- Subject: Re: GDB can't parse variables named "memory" or "array"?
- Authentication-results: sourceware.org; auth=none
- References: <1506705739.6352.95.camel@mad-scientist.net> <87h8vle3j3.fsf@redhat.com>
- Reply-to: paul at mad-scientist dot net
On Fri, 2017-09-29 at 14:57 -0400, Sergio Durigan Junior wrote:
> On Friday, September 29 2017, Paul Smith wrote:
> > I've tried this with lots of different versions of GDB (7.7.1,
> > 7.11, 7.12, etc.), and none of them work when debugging my programs
> > (not just my main program but all my unit tests as well):
> >
> > (gdb) p memory
> > A syntax error in expression, near `'.
> >
> > (gdb) p array
> > A syntax error in expression, near `'.
> You can also enable "set debug parser on" and/or "set debug
> expression 1" inside your "faulty" GDB and see if it helps with
> anything.
This gave very useful information, actually. I now see what's
happening, although I can't understand why no one has noticed this so
I'm not sure.
Printing "array" or "memory" shows:
(gdb) p memory
Starting parse
Entering state 0
Reading a token: Next token is token FILENAME (bval<0x335a1d0>)
Shifting token FILENAME (bval<0x335a1d0>)
Entering state 47
Reducing stack by rule 107 (line 932):
$1 = token FILENAME (bval<0x335a1d0>)
-> $$ = nterm block ()
Stack now 0
Entering state 57
Reading a token: Now at end of input.
A syntax error in expression, near `'.
The problem appears to be with the C++ header files, which don't have
extensions. Here's a repro case:
$ cat gdbtest.cpp
// must include memory
#include <memory>
class Foo
{
char* memory;
};
Foo foo;
int main(int, char**)
{
return 1;
}
$ g++ --ggdb3 -o gdbtest gdbtest.cpp
$ gdb -n gdbtest
...
(gdb) br 13
(gdb) run
(gdb) p foo.memory
A syntax error in expression, near `'.
Note that you have to use -ggdb3 to see the problem; just using -g
doesn't show the error. Also it ends up that the symbol must be part
of a class (or probably struct but not tested): if it's a global or
auto symbol it's interpreted correctly.
Why is GDB even considering a filename to be part of a print
expression?