Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Smith <paul@mad-scientist.net>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: Re: GDB can't parse variables named "memory" or "array"?
Date: Fri, 29 Sep 2017 20:17:00 -0000	[thread overview]
Message-ID: <1506716238.6352.106.camel@mad-scientist.net> (raw)
In-Reply-To: <87h8vle3j3.fsf@redhat.com>

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?


  reply	other threads:[~2017-09-29 20:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-29 17:23 Paul Smith
2017-09-29 18:57 ` Sergio Durigan Junior
2017-09-29 20:17   ` Paul Smith [this message]
2017-09-30 17:38     ` Paul Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1506716238.6352.106.camel@mad-scientist.net \
    --to=paul@mad-scientist.net \
    --cc=gdb@sourceware.org \
    --cc=sergiodj@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox