Global identification of variables in the C code base

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

+3
source share
5 answers

You can extract such information from your object files with 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
+6
source

- -M , , gcc, gcc .... -Xlinker -M.

- ctags. , ( , ). , , gcc- ( , , , ).

+1

? ( ) .

, , . , , . (, , C , .)

0
source

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 -p mybinary | awk '{print $2}'

It will create a set of strings with global character names, one per line.

0
source

I liked the gdb "information variables" for this.

Listed here: Global Variable Identification in the C Code Base

0
source

All Articles