Reputation: 21
I am trying to get the address of a struct member from debug info using gdb.
My problem is that I have a structure like:
typedef struct{
int a;
int b;
int c;
}tstructDesc;
tstructDesc myStruct =
{
1,
2,
3,
};
int main()
{
/* Do something */
}
With gdb I can get the address of the myStruct structure with the command "info address myStruct", but I'd like to get the addresses of the member variables (myStruct.a, myStruct.b, myStruct.c). I discovered the "ptype myStruct" command which returns the definition of the struct, from which I can calculate the relative and absolute addresses, but I think it's not an effective way to get the task done.
Do you know any other way to get the addresses of the struct members?
Thanks in advance, Tamas
Upvotes: 1
Views: 2083
Reputation: 3454
In GDB you can:
(gdb) print myStruct
$1 = {a = 1, b = 2, c = 3}
(gdb) print &myStruct
$2 = (tstructDesc *) 0x600a58 <myStruct>
(gdb) print &myStruct.a
$3 = (int *) 0x600a58 <myStruct>
(gdb) print &myStruct.b
$4 = (int *) 0x600a5c <myStruct+4>
(gdb) print &myStruct.c
$5 = (int *) 0x600a60 <myStruct+8>
Upvotes: 4