Getting a List of Symbols Used by My VC++ Code

醉酒当歌 提交于 2019-12-01 11:15:17

问题


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?


回答1:


Experimenting with this program:

typedef unsigned long MYTYPE;

int wmain(int argc, wchar_t *argv[])
{
    MYTYPE test = 99LU;
}

both DIA SDK and DbgHelp return 16 (SymTagBaseType) for the symtype of the type symbol for test. 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 a typedef or type name in declaring the type of the local variable.

One possible work-around is to enumerate the SymTagTypedef children of the global scope symbol, building a std::multimap from type IDs of the types to the typedef names. Then, for each local variable, if the multimap contains entries for the Data symbol's type ID (obtained via IDiaSymbol::get_typeId), use the IDiaSession::findLines method to figure out the line(s) on which the Data symbol is declared and search those lines for any of the typedef name strings, possibly performing preprocessing before searching.



来源:https://stackoverflow.com/questions/7220882/getting-a-list-of-symbols-used-by-my-vc-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!