How to map segmentation fault address to the corresponding C code?
c, linux
Solution
Use the addr2line utility from the GNU binutils suite. For example, this prints out the filename, line number, and function name (demangling it if it's a C++ function) for the faulting address 0x157e8250:
addr2line -e my_executable_file -C -f 0x157e8250
You can also pass on any number of addresses in the command line, e.g. if you have a stack trace of only instruction addresses.
Make sure you compile your program with the `-g` compiler option to generate debugging symbols, otherwise `addr2line` will not be able to symbolicate anything for you.
Problem
I see a segmentation fault like this `segfault at 157e8250 ip 157e8250 sp bfa3fdfb` how do I map the this address to the corresponding code where the fault occurs?