This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Where symbol is store?


* 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]