Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call stack for code compiled without -g option (gcc compiler)

Tags:

c++

c

linux

gcc

gdb

How do I analyze the core dump (using gdb) which is not compiled with -g GCC option ?

like image 850
Onkar Mahajan Avatar asked Mar 07 '26 20:03

Onkar Mahajan


1 Answers

Generate a map file. The map file will tell you the address that each function starts at (as an offset from the start of the exe so you will need to know the base address its loaded too). So you then look at the instruction pointer and look up where it falls in the map file. This gives you a good idea of the location in a given function.

Manually unwinding a stack is a bit of a black art, however, as you have no idea what optimisations the compiler has performed. When you know, roughly, where you are in the code you can generally work out what ought to be on the stack and scan through memory to find the return pointer. its quite involved however. You effectively spend a lot of time reading memory data and looking for numbers that look like memory addresses and then checking that to see if its logical. Its perfectly doable and I, and I'm sure many others, have done it lots of times :)

like image 198
Goz Avatar answered Mar 09 '26 10:03

Goz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!