I'm trying to write a program that lists all of the publicly exported variables and functions of a C or C++ program by using Clang.
I followed part 05 of this tutorial, but it doesn't work for current version of clang. Above that, I got some hints that CompilerInstance
can make the code shorter, but I'm not entirely sure how to use it.
How would you implement this functionality? Can you give me any pointers into the right direction? For example: is there a large hash table of globally declared variables or do I have to traverse the AST?
publicly exported - do you mean symbols with external linkage?
You can use nm
on object files, shared libraries and executables with --extern-only --defined-only --demangle
options to display defined symbols with external linkage. Symbol type field tells you what kind of symbol it is, global variables normally have types B, b, C, D, d, G, g, R, r, S, s and W, w for static data members of templates declared in header files and function-scope statics.
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