Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I examine in gdb a variable that has the same name as its type

Tags:

c

gcc

debugging

gdb

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?

like image 265
Amir Gonnen Avatar asked Apr 25 '13 10:04

Amir Gonnen


1 Answers

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.

like image 170
dbrank0 Avatar answered Sep 24 '22 13:09

dbrank0