6

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?

Amir Gonnen
  • 3,525
  • 4
  • 32
  • 61
  • 1
    For me it's fine for enums (gdb 7.4), but for structs this has been there for a long time: http://sourceware.org/bugzilla/show_bug.cgi?id=7737 – dbrank0 Apr 25 '13 at 11:44

1 Answers1

6

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.

dbrank0
  • 9,026
  • 2
  • 37
  • 55