Where symbol is store?

Andrew Burgess andrew.burgess@embecosm.com
Mon Sep 17 11:00:00 GMT 2018


* kuba@witominska.net <kuba@witominska.net> [2018-09-17 09:43:51 +0200]:

> Question:
> Where in GDB we get symbol itself?
> 
> I try to dig into it and I found it coud heppen in:
> eval.c:1290
>      in evaluate_subexp_standard()
>      by symbol *var = exp->elts[pc + 2].symbol;
> but it has no sens to me because in
> expression.h:84
>      in struct expression
>      union exp_element elts[1];
> is well 1 element union and it feel like access to unknown part of
> memory.

Placing a single element array at the end of a struct like this is a
trick to remove a level of indirection when accessing the elts array.

In this case elts is contains within 'struct expression'.  Lets say
you want to allocate an expression with 5 'elts'.  You'd do:

  malloc (sizeof (struct expression) + ((5 - 1) * sizeof (union exp_element)));

The '5 - 1' is because 1 exp_element is already contained within
'struct expression', the remaining 4 can then be stored directly after
the allocated expression.

The number of 'elts' will be in the 'nelts' element within 'struct
expression' which allows you to validate that you're not accessing
undefined memory.

Hope that helps,

Andrew



More information about the Gdb mailing list