This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
GDB syntax error if class members overlap C++ header file names
- From: Paul Smith <psmith at gnu dot org>
- To: gdb at sourceware dot org
- Date: Tue, 13 Feb 2018 10:37:12 -0500
- Subject: GDB syntax error if class members overlap C++ header file names
- Authentication-results: sourceware.org; auth=none
- Reply-to: psmith at gnu dot org
Has anyone had any thoughts about
https://sourceware.org/bugzilla/show_bug.cgi?id=22231
This is a really unfortunate bug, because there are so many useful
symbol names which are also C++ header files! Just ran into this again
with "queue".
Quoted from the bug:
> I've discovered that if you compile a C++ program with -ggdb3 (not
> -g) then any C++ header file (sans .h extension) that is included
> will cause a syntax error whenever you try to print that name. Also,
> if you try to print a class member with that name it will also fail.
>
> I've tried this with GDB 7.7, 7.11, and 8.0 and all behave the same
> way. I've used both GCC 6.2 and 6.3.
And I've tried 8.1 as well just to be sure; same behavior:
> (gdb) p memory
> A syntax error in expression, near `'.
>
> This will be the same for any other C++ (without .h) header that is
> included. If you change to #include <memory.h> then you won't get
> this error (you'll get 'No symbole "memory" in current context.' as
> expected).
>
> If you create a local variable or an auto variable named "memory",
> GDB will print it properly.
>
> However, if you have a class member named "memory", GDB again won't
> parse it;
> (gdb) p foo.memory
> A syntax error in expression, near `'.
>
>
>
> If you enable debugging you'll see:
>
> (gdb) set debug parser on
> (gdb) p memory
> Starting parse
> Entering state 0
> Reading a token: Next token is token FILENAME (bval<0x1a66ac0>)
> Shifting token FILENAME (bval<0x1a66ac0>)
> Entering state 47
> Reducing stack by rule 107 (line 877):
> $1 = token FILENAME (bval<0x1a66ac0>)
> -> $$ = nterm block ()
> Stack now 0
> Entering state 57
> Reading a token: Now at end of input.
> A syntax error in expression, near `'.