From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97189 invoked by alias); 29 Sep 2017 20:17:27 -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 97076 invoked by uid 89); 29 Sep 2017 20:17:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*M:106, H*R:D*net, HContent-Transfer-Encoding:8bit X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Sep 2017 20:17:25 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy9.mail.unifiedlayer.com (Postfix) with ESMTP id C2A2D1E0610 for ; Fri, 29 Sep 2017 14:17:23 -0600 (MDT) Received: from box5008.bluehost.com ([50.116.64.19]) by cmgw4 with id FYHL1w0100QvKlu01YHPx5; Fri, 29 Sep 2017 14:17:23 -0600 X-Authority-Analysis: v=2.2 cv=OZLoNlbY c=1 sm=1 tr=0 a=gch/BGY/Gm5DEW28s2kmlQ==:117 a=gch/BGY/Gm5DEW28s2kmlQ==:17 a=IkcTkHD0fZMA:10 a=2JCJgTwv5E4A:10 a=g9lhac9ubU1rq3fUXZ4A:9 a=QEXdDO2ut3YA:10 Received: from [50.226.24.42] (port=43424 helo=pdsdesk) by box5008.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dy1iq-001bFP-5g; Fri, 29 Sep 2017 14:17:20 -0600 Message-ID: <1506716238.6352.106.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: Fri, 29 Sep 2017 20:17:00 -0000 In-Reply-To: <87h8vle3j3.fsf@redhat.com> References: <1506705739.6352.95.camel@mad-scientist.net> <87h8vle3j3.fsf@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-BWhitelist: no X-Exim-ID: 1dy1iq-001bFP-5g X-Source-Sender: (pdsdesk) [50.226.24.42]:43424 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/msg00142.txt.bz2 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?