开发者

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

开发者 https://www.devze.com 2023-03-31 02:12 出处:网络
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 provi

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 o开发者_运维问答f 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:

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.

0

上一篇:

:下一篇

精彩评论

暂无评论...
验证码 换一张
取 消