I have a C code base and I need to programmatically identify all the global variables used. I think gcc can be done to create a memory card file, but I donβt know how, and this can let me see which variables are global? Any help would be appreciated.
Greetings
You can extract such information from your object files with nm.
nm
nm *.o | grep OBJT | grep GLOB
EDIT The command above for nm (Solaris) (SUNWbtool package). For portability, it nmhas a parameter for choosing the output format:
nm -f [posix|bsd|sysv] *.o
- -M , , gcc, gcc .... -Xlinker -M.
gcc .... -Xlinker -M
- ctags. , ( , ). , , gcc- ( , , , ).
ctags
? ( ) .
, , . , , . (, , C , .)
If you have dwarfdump, and your binary contains DWARF debugging information (not shared), you can check the contents of the .debug_pubnamesDWARF section by running
dwarfdump
.debug_pubnames
dwarfdump -p mybinary | awk '{print $2}'
It will create a set of strings with global character names, one per line.
I liked the gdb "information variables" for this.
Listed here: Global Variable Identification in the C Code Base