2

I am trying to extract information from object file with nm command for some kind of static code analysis in which I have to count numbers of declared variables and functions in a C code. I have went through the documentation of GNU Binutils. I could find the variables declared in global scope in the symbol table returned by nmbut I couldn't find variables those are declared in local scope. Why is that? How can I access it?

Is there any way other than nm in which I can extract my desired information. As a compiler gcc is supposed to generate a symbol table for its use. Can I access it through any gcc command?

taufique
  • 2,701
  • 1
  • 26
  • 40

1 Answers1

4

You cannot access to local variables from object files, because gcc does not save information about it. You can use nm only to list symbol-table of object files. These symbol-tables is used to linking. Local variables is not needed in link time. Non static fields of structs and classes too.

For viewing of local variables gcc may compile programs with special debug information about it. But for puposes of static analysing you should analyse source code or machinary code in objectfiles.

Vasiliy
  • 314
  • 2
  • 5