* GDB can't parse variables named "memory" or "array"?
@ 2017-09-29 17:23 Paul Smith
2017-09-29 18:57 ` Sergio Durigan Junior
0 siblings, 1 reply; 4+ messages in thread
From: Paul Smith @ 2017-09-29 17:23 UTC (permalink / raw)
To: gdb
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 `'.
Note I don't even have to start the program to see this (but of course
it always happens, when debugging live processes, cores, etc.)
It's only "array" and "memory" (as far as I can tell); other variables
work fine. Also, it fails even for class members named "array" or
"memory", not just simple variables (e.g., "p obj.array" fails as
well). I'm starting GDB with -n to avoid any init files being loaded
etc.
Nothing I can do will let this work; I tried things like:
(gdb) p/r array
A syntax error in expression, near `'.
(gdb) set $a = array
A syntax error in expression, near `'.
However, I've tried to create simple repro cases and even when compiled
with identical flags, those work fine so it's something about my
program(s), or maybe some library I'm linking.
If I rename the variable to something else, then GDB will print it just
fine.
Any ideas about what can I do to try to figure out what's happening
here?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GDB can't parse variables named "memory" or "array"?
2017-09-29 17:23 GDB can't parse variables named "memory" or "array"? Paul Smith
@ 2017-09-29 18:57 ` Sergio Durigan Junior
2017-09-29 20:17 ` Paul Smith
0 siblings, 1 reply; 4+ messages in thread
From: Sergio Durigan Junior @ 2017-09-29 18:57 UTC (permalink / raw)
To: Paul Smith; +Cc: gdb
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 `'.
Without a reproducer it's really hard to tell what's happening.
> Any ideas about what can I do to try to figure out what's happening
> here?
If you're not willing to share your code, you could debug GDB and see
what's happening. Compile it with debugging symbols (CFLAGS='-g3 -O0'
CXXFLAGS='-g3 -O0'), put a breakpoint on the "print_command" function,
and follow from there.
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.
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GDB can't parse variables named "memory" or "array"?
2017-09-29 18:57 ` Sergio Durigan Junior
@ 2017-09-29 20:17 ` Paul Smith
2017-09-30 17:38 ` Paul Smith
0 siblings, 1 reply; 4+ messages in thread
From: Paul Smith @ 2017-09-29 20:17 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: gdb
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?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GDB can't parse variables named "memory" or "array"?
2017-09-29 20:17 ` Paul Smith
@ 2017-09-30 17:38 ` Paul Smith
0 siblings, 0 replies; 4+ messages in thread
From: Paul Smith @ 2017-09-30 17:38 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: gdb
I filed https://sourceware.org/bugzilla/show_bug.cgi?id=22231
On Fri, 2017-09-29 at 16:17 -0400, Paul Smith wrote:
> 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?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-09-30 17:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-29 17:23 GDB can't parse variables named "memory" or "array"? Paul Smith
2017-09-29 18:57 ` Sergio Durigan Junior
2017-09-29 20:17 ` Paul Smith
2017-09-30 17:38 ` Paul Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox