* GDB syntax error if class members overlap C++ header file names
@ 2018-02-13 15:37 Paul Smith
2018-02-13 15:52 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Paul Smith @ 2018-02-13 15:37 UTC (permalink / raw)
To: gdb
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 `'.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GDB syntax error if class members overlap C++ header file names
2018-02-13 15:37 GDB syntax error if class members overlap C++ header file names Paul Smith
@ 2018-02-13 15:52 ` Simon Marchi
2018-02-13 16:52 ` Paul Smith
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2018-02-13 15:52 UTC (permalink / raw)
To: psmith; +Cc: gdb
On 2018-02-13 10:37, Paul Smith wrote:
> 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 `'.
Hi Paul,
This looks like an issue that has been fixed recently, but it's not in
8.1, only master.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=59498c305e6f1db2a1ed8d44cb58f0d24ec092fe
Can you verify if it works for you?
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GDB syntax error if class members overlap C++ header file names
2018-02-13 15:52 ` Simon Marchi
@ 2018-02-13 16:52 ` Paul Smith
0 siblings, 0 replies; 3+ messages in thread
From: Paul Smith @ 2018-02-13 16:52 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb
On Tue, 2018-02-13 at 10:52 -0500, Simon Marchi wrote:
> On 2018-02-13 10:37, Paul Smith wrote:
> > 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".
>
> Hi Paul,
>
> This looks like an issue that has been fixed recently, but it's not
> in 8.1, only master.
>
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=5
> 9498c305e6f1db2a1ed8d44cb58f0d24ec092fe
>
> Can you verify if it works for you?
I ran applied SHA 59498c305e6f1db2a1ed8d44cb58f0d24ec092fe as a patch
to 8.1 (but had to toss the changelog diffs... yet another reason to
stop including them as source code artifacts...) and that does fix the
main problem... awesome!
There's still a weird error if there's no symbol in context; my first
example the the bug still prints "syntax error in expression, near `'"
rather than something more reasonable such as "No symbol "memory" in
current context". That's probably still something that should be
fixed, but it's basically an error messaging issue.
However, if there's a "memory" symbol in the current context (either
implicitly as in we're in a method and the class has a "memory" member,
or using something like foo.memory) it will find and print the right
thing.
So that's excellent! Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-13 16:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-13 15:37 GDB syntax error if class members overlap C++ header file names Paul Smith
2018-02-13 15:52 ` Simon Marchi
2018-02-13 16:52 ` Paul Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox