获取我的VC ++代码使用的符号列表 [英] Getting a List of Symbols Used by My VC++ Code

查看:100
本文介绍了获取我的VC ++代码使用的符号列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个处理VC ++源代码的工具.为此,我需要获取符号列表,包括局部变量名称及其代码使用的类型.我知道Visual C ++ 2010已经提供了一个.bsc文件,该文件允许对象浏览器快速定位符号.但这是一个交互式工具.我需要获取文件中符号的列表.有什么工具可以让我们以编程方式获取我们自己的VC ++源代码中使用的符号列表?

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?

我尝试了Microsoft提供的Debug Interface Access SDK.它允许我们读取.pdb文件以获取所用局部变量的名称.但是我也想获得我的源代码中使用的确切类型名称.例如

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允许我们获取字符串"dwordVar",它是局部变量的名称.但是它不能说出它的类型名是"MYTYPE".它只能告诉我们MYTYPE真正代表什么(如unsigned long).但是不是符号"MYTYPE".

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".

如果Visual C ++不提供此功能,是否有任何第三方工具支持此功能?

If Visual C++ isnt offering this feature, is there any third party tools supporting this feature?

推荐答案

对此程序进行的实验:

typedef unsigned long MYTYPE;

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

DIA SDK和DbgHelp都为test的类型符号的符号类型返回16(SymTagBaseType).如果类型符号是Typedef符号(17/SymTagTypedef),那就太好了,但是可能是PDB本身不记录源文件在声明本地类型时是使用typedef还是类型名称.变量.

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.

一种可能的解决方法是枚举全局作用域符号的SymTagTypedef子代,从类型的类型ID到typedef名称构建std::multimap.然后,对于每个局部变量,如果多图包含数据符号类型ID的条目(通过 IDiaSession::findLines 方法来找出声明了数据符号的行,并在这些行中搜索任何typedef名称字符串,可能在搜索之前执行预处理.

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.

这篇关于获取我的VC ++代码使用的符号列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆