I have a C code base and need to programmatically identify all of the global variables used. I think that gcc can be made to produce a memory map file but don't know how and this might let me see which variables are global? Any help would be appreciated.
Cheers
You can extract such information from your object files with nm.
nm *.o | grep OBJT | grep GLOB
EDIT
Command above is for Solaris' nm (SUNWbtool package). For portability, nm has a parameter to choose the output format:
nm -f [posix|bsd|sysv] *.o
The option to output memory map is -M with the linker, so to get it from gcc you have to use gcc .... -Xlinker -M.
Another way to to get these is to use the ctags program. It can not only tag the available functions, but also the available global variables (and does not collect the statics, this is different to memory map). As it doesnt compile everything this should also be faster than the gcc approach (if you have to compile, you would get that of course for free).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With