Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why works addr2line only for functions

Tags:

c

debugging

elf

I've got addr2line working for function addresses:

$ nm -S executable | grep main
08048742 000000a0 T main
$ addr2line -e executable 08048742
/home/blablabla/src/main.c:80

Unfortunately it only works if I supply an address of a function, when passing an address of a data symbol (e.g. the address of a crc table) it can never resolve the file/line number:

$ nm -S executable | grep tableCRC
080491bc 00000200 r tableCRC
$ addr2line -e executable 080491bc
??:0

I guess that that kind of debug information just isn't included for data because this feature is probably intended for analyzing backtraces, but maybe there's a compiler/linker option to force this?

I want to use the output of addr2line to generate detailed information about how much memory size a file or module uses (instead of the global number reported by the 'size' tool).

like image 271
Bart Avatar asked Aug 03 '11 07:08

Bart


1 Answers

The --print-size and --line-numbers options to nm are probably what you are looking for.

Please note that the ELF object needs to contain debugging information for the --line-numbers option to work.

like image 69
jkoshy Avatar answered Sep 30 '22 07:09

jkoshy