I am building a tool that process my VC++ source codes. For this, I need to obtain a list of symbols including local variable names and their types used by my codes. I know Visual C++ 2010 already provides a .bsc file that allows the object browser to locate symbols quickly. But this is an interactive tool. I need to obtain a list of the symbols in a file. Is there any tools allowing us to programmatically obtain the list of symbols used in our own VC++ source codes?
I tried the Debug Interface Access SDK provided by Microsoft. It allows us to read the .pdb file for the names of the local variables used. But I also want to obtain the exact type names used in my source codes. e.g.
MYTYPE dwordVar;
DIA SDK allows us to obtain the string "dwordVar" which is the name of a local variable. But it cannot tell its type name is "MYTYPE". It can only tell us what MYTYPE really represents (like unsigned long). But not the symbol "MYTYPE".
If Visual C++ isnt offering this feature, is there any third party tools supporting this feature?
Experimenting with this program:
both DIA SDK and DbgHelp return 16 (
SymTagBaseType) for the symtype of the type symbol fortest. It would be nice if the type symbol were a Typedef symbol (17/SymTagTypedef), but it might be that the PDB itself does not record whether the source file used atypedefor type name in declaring the type of the local variable.One possible work-around is to enumerate the
SymTagTypedefchildren of the global scope symbol, building astd::multimapfrom type IDs of the types to thetypedefnames. Then, for each local variable, if the multimap contains entries for the Data symbol's type ID (obtained viaIDiaSymbol::get_typeId), use theIDiaSession::findLinesmethod to figure out the line(s) on which the Data symbol is declared and search those lines for any of thetypedefname strings, possibly performing preprocessing before searching.