How can I examine in gdb a variable that has the same name as its type
c, debugging, gcc, gdb
Solution
Try this workaround. For your binary do something like:
nm your-executable |grep rtx_class
You should get address (let's say it's 0xabcdef, assuming this is global variable. Then in gdb do something like:
print *(rtx_class*)(0xabcdef+sizeof(rtx_class)*n)
This should print rtx_class[n]. Or at least it does in my simple testcase.
Problem
I'm debugging an existing C library with gdb 7.4 I'm trying to examine a variable which, unfortunately, was declared with the same name as its type: ``` extern const enum rtx_class rtx_class[NUM_RTX_CODE]; ``` Now I just can't find a way to examine this variable. `p rtx_class` returns Attempt to use a type name as an expression, the same with `p &rtx_class` and `p rtx_class[0]`. However, `info var rtx_class` works and returns const rtx_class rtx_class[145] as expected. Any idea?