说我有一个简单的类,如下所示:
class Foo
{
public:
Foo(){};
protected:
int meth1( void ){return 0;};
public:
int var1;
};
使用MSVC编译并通过DbgHelp API解析相应的PDB,我可以遍历子节点并解析方法和变量,但是我无法弄清楚如何确定给定子节点的访问说明符。我的代码看起来像这样:
// The symbol tag for 'index' is a SymTagEnum::SymTagBaseClass
DWORD item_count;
if( !::SymGetTypeInfo( process, base_address, index, TI_GET_CHILDRENCOUNT, &item_count ) )
break;
if( item_count > 0 )
{
TI_FINDCHILDREN_PARAMS * item_indexs = new TI_FINDCHILDREN_PARAMS[item_count];
item_indexs->Count = item_count;
item_indexs->Start = 0;
if( ::SymGetTypeInfo( process, base_address, index, TI_FINDCHILDREN, item_indexs ) )
{
for( DWORD i=0 ; i<item_count ; i++ )
{
DWORD item_tag;
if( !::SymGetTypeInfo( process, base_address, item_indexs->ChildId[i], TI_GET_SYMTAG, &item_tag ) )
break;
DWORD item_type_index;
if( !::SymGetTypeInfo( process, base_address, item_indexs->ChildId[i], TI_GET_TYPEID, &item_type_index ) )
break;
// XXX: How to discover the access specifier (public, private, protected) for
// the class method/variable at 'item_type_index'?
switch( item_tag )
{
case SymTagEnum::SymTagFunction:
{
// parse out the class method at 'item_type_index'
break;
}
case SymTagEnum::SymTagData:
{
// parse out the class variable at 'item_type_index'
break;
}
default:
{
break;
}
}
}
}
}
是否可以通过DbgHelp API确定类子项的访问说明符(public,private,protected),如果是,如何确定?
答案 0 :(得分:1)
是的,这在技术上是可行的。您将检索该函数的装饰(又称已损坏)名称。在您的情况下将是?meth1@Foo@@IAEHXZ
。装饰的C ++名称始终以问号开头。您可以将其提供给UnDecorateSymbolName() function以将其转换回C ++标识符名称。这将是:
protected: int __thiscall Foo::meth1(void)
请注意它是如何包含访问说明符的。