I’m trying to figure this out as I’m trying to do the same thing (hopefully) with a home grown script:
Example C code:
typedef struct _B
{
A aa;
double b;
char c[LEN];
int d;
char *a_ptr[10];
} B;
B this_b;
If I compile this with gcc -g and gdb a.out afterwards, gdb knows exactly what and where a_ptr is:
(gdb) p &(this_b.a_ptr)
$1 = (char *(*)[10]) 0x804a084
how does it do that? And can I do the same thing (knowing it’s address and type) through other utilities?
When you build with the
-gflag, GCC (and most other compilers) stores additional “debugging info” in your binary (a.out).You can examine that info with tools other than GDB. For example,
readelf -w a.out(assuming you are on Linux or anotherELFplatform).You can also compare the size of
a.outwhen built with and without-g. It is not uncommon for the debug binary to be 5 to 10 times larger.