From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52488 invoked by alias); 30 Sep 2017 17:38:21 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 52470 invoked by uid 89); 30 Sep 2017 17:38:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*R:D*net, HContent-Transfer-Encoding:8bit X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 30 Sep 2017 17:38:18 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 233AD140585 for ; Sat, 30 Sep 2017 11:38:17 -0600 (MDT) Received: from box5008.bluehost.com ([50.116.64.19]) by cmgw3 with id FteD1w00T0QvKlu01teGlv; Sat, 30 Sep 2017 11:38:17 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=gch/BGY/Gm5DEW28s2kmlQ==:117 a=gch/BGY/Gm5DEW28s2kmlQ==:17 a=IkcTkHD0fZMA:10 a=2JCJgTwv5E4A:10 a=CCpqsmhAAAAA:8 a=SclGQrzN8BxOOigLqyoA:9 a=QEXdDO2ut3YA:10 a=ul9cdbp4aOFLsgKbc677:22 Received: from pool-74-104-137-100.bstnma.fios.verizon.net ([74.104.137.100]:45326 helo=homebase) by box5008.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dyLiP-001FzP-HM; Sat, 30 Sep 2017 11:38:13 -0600 Message-ID: <1506793092.25419.0.camel@mad-scientist.net> Subject: Re: GDB can't parse variables named "memory" or "array"? From: Paul Smith Reply-To: paul@mad-scientist.net To: Sergio Durigan Junior Cc: "gdb@sourceware.org" Date: Sat, 30 Sep 2017 17:38:00 -0000 In-Reply-To: <1506716238.6352.106.camel@mad-scientist.net> References: <1506705739.6352.95.camel@mad-scientist.net> <87h8vle3j3.fsf@redhat.com> <1506716238.6352.106.camel@mad-scientist.net> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-BWhitelist: no X-Exim-ID: 1dyLiP-001FzP-HM X-Source-Sender: pool-74-104-137-100.bstnma.fios.verizon.net (homebase) [74.104.137.100]:45326 X-Source-Auth: paul@mad-scientist.us X-Email-Count: 1 X-Source-Cap: bWFkc2NpZTE7bWFkc2NpZTE7Ym94NTAwOC5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2017-09/txt/msg00143.txt.bz2 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 > > 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?