This is the mail archive of the mailing list for the GCC 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: How to implement '@' GDB-like operator for libcc1

> But GDB features a useful custom expression operator '@':
> I have problems implementing '@' into GCC, could you suggest at which place
> should I call build_array_type_nelts()?  Or is it the right way at all?
> Testing it on a sample code - it should return 2:
>     int a[]={1,2,3};int main(void){ return (*a@3)[1]; }

Sorry if I'm missing something, but this example does not make sense
to me. You can directly use a[1], no need for the @-operator here. In
my experience (and again, sorry if I'm missing other interesting
usercases), the utility of @ is to be able to do things like:

print a@3
print (*&(something complicated expression))@(some integer expression)

Thus, the question is what info GDB needs from GCC to be able to print
the contents of the array. 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?

Also note that given this code and breaking in main()

int a[]={1,2,3};int main(void){ return (a[1]); }


(gdb) p a
$1 = {1, 2, 3}
(gdb) p a@3
$2 = {{1, 2, 3}, {0, 0, 0}, {0, 0, 0}}

This is because:

(gdb) ptype a
type = int [3]
(gdb)  ptype a@3
type = int [3][3]

Thus, what happens currently when you do?
(gdb) compile int a[]={1,2,3}
(gdb) compile print a



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