On Mon, 16 Mar 2015 10:33:26 +0100, Manuel López-Ibáñez wrote:
> On 16 March 2015 at 09:32, Jan Kratochvil <jan.kratoch...@redhat.com> wrote:
> > On Mon, 16 Mar 2015 04:22:35 +0100, Manuel López-Ibáñez wrote:
> >> Thus, the question is what info GDB needs from GCC to be able to print
> >> the contents of the array.
> >
> > Variable with an array type in DWARF.
> 
> How does it work then for pointers?
> 
> int *p = malloc(...);
> 
> (gdb) p *p@3
> 
> should also work.

The idea was GCC would create an int[3] __gdb_expr_val variable for the result
and GDB would read that int[3] type from __gdb_expr_val's DWARF.


> >> And it probably just needs the type of whatever is to the left of @ and the
> >> value of whatever is to the right of @, no?
> >
> > There are two ways how to fix that.  As '@' makes sense only at the 
> > outermost
> > operator of an expression GDB could strip it and not to pass it to GCC at 
> > all.
> > But then there would be unhandled corner cases like parentheses:
> >         (gdb) print (*a@3)
> 
> Would it be so difficult to strip parentheses? I honestly think it
> might be easier than adding special handling for @ to the C parser.

If it is really difficult to implement '@' in GCC then yes, that's the other
way.  I expected to learn GCC parser on this IMO-simpler case so one can later
implement for example the '{TYPE} ADDR' GDB extension, dropping C++ class
protections, FILE::VARIABLE or FUNCTION::VARIABLE notations etc.  So there are
more topics for the C/C++ parser but I tried this one first.


> I think there are more options: GDB could also convert @ to something
> that GCC can understand, like a function call, or a cast to a
> gdb-defined type, and that will trigger the generation of the desired
> DWARF.

I do not see how GDB could properly parse the expression with proper operator
priorities/association.


> > Depending on the DWARF types of __gdb_expr_val and __gdb_expr_ptr_type GDB 
> > will
> > pass the boolean flag '__gdb_expr_take_address' to handle arrays correctly, 
> > one
> > can see it for:
> 
> Would it be possible for GDB to generate code such that this trick is
> generated for @? Perhaps by creating a dummy array variable, then
> applying typeof(dummy) like you do below.

Sorry I do not get it.  GDB does not know how many elements the array should
have without parsing the expression on its own - and only GCC can parse C/C++.


Thanks,
Jan

Reply via email to