This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: sizeof evaluates expression to compute size?
- From: Senthil Kumar Selvaraj <senthil_kumar dot selvaraj at atmel dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: <gdb at sourceware dot org>
- Date: Thu, 17 Sep 2015 19:39:49 +0530
- Subject: Re: sizeof evaluates expression to compute size?
- Authentication-results: sourceware.org; auth=none
- References: <20150916144109 dot GB14658 at jaguar dot corp dot atmel dot com> <20150916145632 dot GA19688 at adacore dot com>
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