From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69495 invoked by alias); 17 Sep 2015 14:10:26 -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 68213 invoked by uid 89); 17 Sep 2015 14:10:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: eusmtp01.atmel.com Received: from eusmtp01.atmel.com (HELO eusmtp01.atmel.com) (212.144.249.242) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 17 Sep 2015 14:10:11 +0000 Received: from HNOCHT02.corp.atmel.com (10.161.30.162) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server (TLS) id 14.3.235.1; Thu, 17 Sep 2015 16:10:02 +0200 Received: from jaguar.corp.atmel.com (10.161.30.18) by HNOCHT02.corp.atmel.com (10.161.30.162) with Microsoft SMTP Server (TLS) id 14.3.235.1; Thu, 17 Sep 2015 16:10:06 +0200 Date: Thu, 17 Sep 2015 14:10:00 -0000 From: Senthil Kumar Selvaraj To: Joel Brobecker CC: Subject: Re: sizeof evaluates expression to compute size? Message-ID: <20150917140949.GA2332@jaguar.corp.atmel.com> References: <20150916144109.GB14658@jaguar.corp.atmel.com> <20150916145632.GA19688@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20150916145632.GA19688@adacore.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00012.txt.bz2 On Wed, Sep 16, 2015 at 07:56:32AM -0700, Joel Brobecker wrote: > > Is it true that gdb evaluates the expression in a "print > > sizeof(expression)" to figure out the size? > > Yes; it actually evaluates the entire expression (including the use > of the sizeof operator). > > > For one expression on the ARM target > > > > print sizeof((char*)(s->m) > > The expression is incomplete; but with the expression you gave and > assuming we're just missing a closing parenthesis, I don't see why > it would need to allocate memory in the inferior. Perhaps you've found > a bug. Here's a more complete testcase. typedef struct tagFoo { int x; char arr[10]; } Foo; Foo *pFoo; int main() { return 1; } Compiling with $ gcc test.c -O0 -g3 and then starting gdb (native x86_64, v7.10) gives $ gdb a.out >>> print sizeof((char*)pFoo->arr) evaluation of this expression requires the target program to be active Starting the program, putting a breakpoint on malloc, and then executing the above command causes the breakpoint to be hit. Evaluation works fine without the cast to char* >>> print sizeof(pFoo->arr) $2 = 10 Should I file a bug? Regards Senthil