Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting symbol table using clang

I am looking for a way to get the symbol table of a C program. I am looking for global and local variables, and their scope, etc.

Does clang have an option or API to dump out this information? Or any other compiler framework that makes this easy to do.

like image 855
rsinha Avatar asked Feb 09 '13 20:02

rsinha


1 Answers

I'm sure Clang has a set of interfaces to provide access to symbol table information. My understanding is there isn't a lot of documentation, so you simply have to examine the source code.

GCCXML does this for top level definitions. It doesn't report on the content of functions (e.g., you're not likely to get locals). You get XML and after that you're on your own.

Our DMS Software Reengineering Toolkit has full parsers for a variety of C dialects, and builds symbol tables. If your wanted to dump them, the [well-documented IMHO] symbol table APIs provide easy means to enumerate the members. Usually people want to do something with such information, such as generate or modify code. DMS provides a vast infrastructure to support doing more sophisticated analayses (including or driven by that symbol table structure) and/or modify the code.

like image 77
Ira Baxter Avatar answered Oct 12 '22 21:10

Ira Baxter