本文整理汇总了C++中IDiaSymbol类的典型用法代码示例。如果您正苦于以下问题:C++ IDiaSymbol类的具体用法?C++ IDiaSymbol怎么用?C++ IDiaSymbol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDiaSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetBaseTypeSymbol
//------------------------------------------------------------------------
// pSymbol의 데이타 길이를 리턴한다.
//------------------------------------------------------------------------
ULONGLONG dia::GetSymbolLength(IDiaSymbol *pSymbol)
{
ULONGLONG len = 0;
SymbolState state;
IDiaSymbol *pTypeSymbol = GetBaseTypeSymbol(pSymbol, 1, state);
if (!pTypeSymbol)
return 0;
enum SymTagEnum symTag;
HRESULT hr = pTypeSymbol->get_symTag((DWORD*)&symTag);
switch (symTag)
{
case SymTagPointerType:
case SymTagArrayType:
{
IDiaSymbol *pBaseType;
hr = pTypeSymbol->get_type(&pBaseType);
if (NEW_SYMBOL == state)
SAFE_RELEASE(pTypeSymbol);
pTypeSymbol = pBaseType;
}
break;
}
hr = pTypeSymbol->get_length(&len);
if (NEW_SYMBOL == state)
SAFE_RELEASE(pTypeSymbol);
return len;
}
示例2: DumpTypes
static void DumpTypes(IDiaSession *session)
{
IDiaSymbol * globalScope = NULL;
IDiaEnumSymbols * enumSymbols = NULL;
IDiaSymbol * symbol = NULL;
HRESULT hr = session->get_globalScope(&globalScope);
if (FAILED(hr))
return;
AddReportSepLine();
g_report.Append("Types:\n");
DWORD flags = nsfCaseInsensitive|nsfUndecoratedName; // nsNone ?
hr = globalScope->findChildren(SymTagUDT, 0, flags, &enumSymbols);
if (FAILED(hr))
goto Exit;
ULONG celt = 0;
for (;;)
{
hr = enumSymbols->Next(1, &symbol, &celt);
if (FAILED(hr) || (celt != 1))
break;
DumpType(symbol, 0);
symbol->Release();
}
Exit:
UnkReleaseSafe(enumSymbols);
UnkReleaseSafe(globalScope);
}
示例3: Enum
IDiaSymbol* CSym::Enum(
__in IDiaSymbol* symParent,
__in enum SymTagEnum enTag,
__in EnumProc cbEnum,
__in_opt PVOID param)
{
if (NULL == symParent)
return NULL;
CComPtr<IDiaEnumSymbols> pEnum = NULL;
HRESULT hr = symParent->findChildren(enTag, NULL, nsNone, &pEnum);
if (SUCCEEDED(hr) && pEnum)
{
ULONG count = 1;
IDiaSymbol* curItem = NULL;
pEnum->Next(1, &curItem, &count);
do
{
if (NULL != curItem)
{
if (cbEnum(curItem, param))
return curItem;
curItem->Release();
}
pEnum->Next(1, &curItem, &count);
} while (0 != count);
}
return NULL;
}
示例4: for_all_children
//----------------------------------------------------------------------
static HRESULT for_all_children(
IDiaSymbol *sym,
enum SymTagEnum type,
children_visitor_t &cv)
{
IDiaEnumSymbols *pEnumSymbols;
HRESULT hr = sym->findChildren(type, NULL, nsNone, &pEnumSymbols);
if ( SUCCEEDED(hr) )
{
while ( true )
{
ULONG celt = 0;
IDiaSymbol *pChild;
hr = pEnumSymbols->Next(1, &pChild, &celt);
if ( FAILED(hr) || celt != 1 )
{
hr = S_OK; // end of enumeration
break;
}
hr = cv.visit_child(pChild);
pChild->Release();
if ( FAILED(hr) )
break;
}
pEnumSymbols->Release();
}
return hr;
}
示例5: DumpType
static void DumpType(IDiaSymbol *symbol, int deep)
{
IDiaEnumSymbols * enumChilds = NULL;
HRESULT hr;
const char * nameStr = NULL;
const char * type;
LONG offset;
ULONGLONG length;
ULONG celt = 0;
ULONG symtag;
DWORD locType;
bool typeSeen;
#if 0
if (deep > 2)
return;
#endif
if (symbol->get_symTag(&symtag) != S_OK)
return;
nameStr = GetTypeName(symbol);
g_typesSeen.Intern(nameStr, &typeSeen);
if (typeSeen)
return;
symbol->get_length(&length);
symbol->get_offset(&offset);
if (SymTagData == symtag) {
if (symbol->get_locationType(&locType) != S_OK)
return; // must be a symbol in optimized code
// TODO: use get_offsetInUdt (http://msdn.microsoft.com/en-us/library/dd997149.aspx) ?
// TODO: use get_type (http://msdn.microsoft.com/en-US/library/cwx3656b(v=vs.80).aspx) ?
// TODO: see what else we can get http://msdn.microsoft.com/en-US/library/w8ae4k32(v=vs.80).aspx
if (LocIsThisRel == locType) {
g_report.AppendFmt("%s%s|%d\n", spaces(deep), nameStr, (int)offset);
}
} else if (SymTagUDT == symtag) {
// TODO: why is it always "struct" even for classes?
type = GetUdtType(symbol);
g_report.AppendFmt("%s%s|%s|%d\n", spaces(deep), type, nameStr, (int)length);
hr = symbol->findChildren(SymTagNull, NULL, nsNone, &enumChilds);
if (!SUCCEEDED(hr))
return;
IDiaSymbol* child;
while (SUCCEEDED(enumChilds->Next(1, &child, &celt)) && (celt == 1))
{
DumpType(child, deep+1);
child->Release();
}
enumChilds->Release();
} else {
if (symbol->get_locationType(&locType) != S_OK)
return; // must be a symbol in optimized code
// TODO: assert?
}
}
示例6: DumpSymbol
static void DumpSymbol(IDiaSymbol *symbol)
{
DWORD section, offset, rva;
DWORD dwTag;
enum SymTagEnum tag;
ULONGLONG length = 0;
const char * typeName = NULL;
char * dataTypeName = NULL;
const char * thunkTypeName = NULL;
symbol->get_symTag(&dwTag);
tag = (enum SymTagEnum)dwTag;
typeName = GetSymTypeName(tag);
symbol->get_relativeVirtualAddress(&rva);
symbol->get_addressSection(§ion);
symbol->get_addressOffset(&offset);
// for data, get length from type
if (SymTagData == tag)
{
IDiaSymbol *type = NULL;
if (symbol->get_type(&type) == S_OK) // no SUCCEEDED test as may return S_FALSE!
{
type->get_length(&length);
const char *s = GetUndecoratedSymbolName(type, "");
if (s && *s)
dataTypeName = str::Dup(s);
type->Release();
}
} if (SymTagThunk == tag) {
DWORD dwThunkKind;
if (S_OK == symbol->get_thunkOrdinal(&dwThunkKind))
thunkTypeName = GetThunkTypeName(dwThunkKind);
} else {
symbol->get_length(&length);
}
const char *nameStr = GetUndecoratedSymbolName(symbol);
if (SymTagData == tag) {
// type | section | length | offset | rva | name | dataTypeName
char *tmp = dataTypeName ? dataTypeName : "";
g_report.AppendFmt("%s|%d|%d|%d|%d|%s|%s\n", typeName, (int)section, (int)length, (int)offset, (int)rva, nameStr, tmp);
free(dataTypeName);
} else if (SymTagThunk == tag) {
const char *tmp = thunkTypeName ? thunkTypeName : "";
// type | section | length | offset | rva | name | thunkTypeName
g_report.AppendFmt("%s|%d|%d|%d|%d|%s|%s\n", typeName, (int)section, (int)length, (int)offset, (int)rva, nameStr, tmp);
} else {
// type | section | length | offset | rva | name
g_report.AppendFmt("%s|%d|%d|%d|%d|%s\n", typeName, (int)section, (int)length, (int)offset, (int)rva, nameStr);
}
}
示例7: BStrToString
// the result doesn't have to be free()d but is only valid until the next call to this function
static const char *GetObjFileName(IDiaSectionContrib *item)
{
static str::Str<char> strTmp;
BSTR name = 0;
IDiaSymbol * compiland = 0;
item->get_compiland(&compiland);
if (compiland) {
compiland->get_name(&name);
compiland->Release();
}
BStrToString(strTmp, name, "<noobjfile>");
SysFreeStringSafe(name);
return strTmp.Get();
}
示例8: DumpSymbols
static void DumpSymbols(IDiaSession *session)
{
HRESULT hr;
IDiaEnumSymbolsByAddr * enumByAddr = NULL;
IDiaSymbol * symbol = NULL;
hr = session->getSymbolsByAddr(&enumByAddr);
if (!SUCCEEDED(hr))
goto Exit;
// get first symbol to get first RVA (argh)
hr = enumByAddr->symbolByAddr(1, 0, &symbol);
if (!SUCCEEDED(hr))
goto Exit;
DWORD rva;
hr = symbol->get_relativeVirtualAddress(&rva);
if (S_OK != hr)
goto Exit;
symbol->Release();
symbol = NULL;
// enumerate by rva
hr = enumByAddr->symbolByRVA(rva, &symbol);
if (!SUCCEEDED(hr))
goto Exit;
AddReportSepLine();
g_report.Append("Symbols:\n");
ULONG numFetched;
for (;;)
{
DumpSymbol(symbol);
symbol->Release();
symbol = NULL;
hr = enumByAddr->Next(1, &symbol, &numFetched);
if (FAILED(hr) || (numFetched != 1))
break;
}
Exit:
UnkReleaseSafe(symbol);
UnkReleaseSafe(enumByAddr);
}
示例9: get_symbol_length
//----------------------------------------------------------------------
size_t get_symbol_length(IDiaSymbol *sym)
{
DWORD64 size = 0;
DWORD tag = 0;
sym->get_symTag(&tag);
if ( tag == SymTagData )
{
IDiaSymbol *pType;
if ( sym->get_type(&pType) == S_OK )
{
pType->get_length(&size);
pType->Release();
}
}
else
{
sym->get_length(&size);
}
return size_t(size);
}
示例10: RETV
//------------------------------------------------------------------------
//
//------------------------------------------------------------------------
IDiaSymbol* dia::FindType(const std::string &typeName)
{
RETV(!m_pGlobalSymbol, NULL);
CComPtr<IDiaEnumSymbols> pEnumSymbols;
if (FAILED(m_pGlobalSymbol->findChildren(SymTagNull, memmonitor::str2wstr(typeName).c_str(),
nsRegularExpression, &pEnumSymbols)))
return NULL;
std::list<IDiaSymbol *> childSymbols;
IDiaSymbol *pSymbol = NULL;
ULONG celt = 0;
// 첫번째로 발견되는 정보만 찾아서 리턴한다.
while (SUCCEEDED(pEnumSymbols->Next(1, &pSymbol, &celt)) && (celt == 1))
{
childSymbols.push_back(pSymbol);
enum SymTagEnum symTag;
HRESULT hr = pSymbol->get_symTag((DWORD*)&symTag);
if (SymTagData == symTag || SymTagUDT == symTag)
break;
}
if (childSymbols.empty())
return NULL;
// SymTagEnum 값이 SymTagData 이거나 SymTagUDT 을 먼저 선택하도록 한다.
// 가장 나중에 추가된 것을 제외하고 나머지는 제거한다.
while (childSymbols.size() > 1)
{
childSymbols.front()->Release();
childSymbols.pop_front();
}
return childSymbols.back();
}
示例11: ASSERT_RETV
//------------------------------------------------------------------------
// pSymbol 타입의 정보를 srcPtr 주소에서 가져온다.
// pSymbol 은 srcPtr 에 저장된 심볼의 타입을 가르킨다.
// pSymbol 은 SymTagData 이거나 SymTagBaseType 타입이어야 한다.
// isApplyOffset : false 이면 변수의 offset을 적용하지 않는다.
// 이미 계산된 상태라면 할필요 없음
//------------------------------------------------------------------------
_variant_t dia::GetValueFromSymbol(void *srcPtr, IDiaSymbol *pSymbol )
{
_variant_t value;
void *ptr = (BYTE*)srcPtr;
enum SymTagEnum symTag;
HRESULT hr = pSymbol->get_symTag((DWORD*)&symTag);
ASSERT_RETV((S_OK == hr), value);
bool isReleaseBaseType=false;
IDiaSymbol *pBaseType;
if (SymTagData == symTag)
{
hr = pSymbol->get_type(&pBaseType);
ASSERT_RETV((S_OK == hr), value);
pSymbol = pBaseType;
isReleaseBaseType = true;
}
else
{
pBaseType = pSymbol;
}
enum SymTagEnum baseSymTag;
hr = pBaseType->get_symTag((DWORD*)&baseSymTag);
ASSERT_RETV(S_OK==hr, value);
BasicType btype;
switch (baseSymTag)
{
case SymTagBaseType:
hr = pBaseType->get_baseType((DWORD*)&btype);
ASSERT_RETV((S_OK == hr), value );
break;
case SymTagPointerType:
btype = btULong;
break;
default:
if (isReleaseBaseType)
pBaseType->Release();
return value;
}
ULONGLONG length = 0;
hr = pBaseType->get_length(&length);
ASSERT_RETV((S_OK == hr), value );
value = dia::GetValueFromAddress(ptr, btype, length);
if (isReleaseBaseType)
pBaseType->Release();
return value;
}
示例12: LoadDIASymbols
bool LoadDIASymbols(const wxString &strPDBFile,
wxInt32 modulenum,
std::list<CFunctionDescription> & llFuncs,
stdext::hash_map<BasedAddress,int> & addressmap
)
{
// Create DIA80 Data Source Object
IDiaDataSource *pDataSource;
HRESULT hr = NoRegCoCreate( L"msdia80.dll", _uuidof( DiaSource ), _uuidof( IDiaDataSource ), (void **) &(pDataSource));
if(!SUCCEEDED(hr))
{
return false;
}
/*
HMODULE mod=LoadLibrary(L"msdia80.dll");
if(!mod)
{
return false;
}
TYPEOF_DllGetClassObject *pGetClassObject=(TYPEOF_DllGetClassObject *)GetProcAddress(mod,"DllGetClassObject");
if(!pGetClassObject)
{
FreeLibrary(mod);
return false;
}
IClassFactory *pcf;
HRESULT hr=(*pGetClassObject)(CLSID_DiaSource,IID_IClassFactory,(void **)&pcf);
if(!SUCCEEDED(hr))
{
FreeLibrary(mod);
return false;
}
IDiaDataSource *pDataSource;
hr=pcf->CreateInstance(NULL,_uuidof(IDiaDataSource),(void **)&pDataSource);
if(!SUCCEEDED(hr))
{
pcf->Release();
FreeLibrary(mod);
return false;
}
pcf->Release();
*/
// Load the executable's debug symbols
hr=pDataSource->loadDataFromPdb(strPDBFile);
if(!SUCCEEDED(hr))
{
pDataSource->Release();
return false;
}
// Open a symbol session
IDiaSession *pDIASession;
hr=pDataSource->openSession(&pDIASession);
if(!SUCCEEDED(hr))
{
pDataSource->Release();
return false;
}
// Set the UNBASED address on the session, for resolving BasedAddress addrs
hr=pDIASession->put_loadAddress(0);
if(!SUCCEEDED(hr))
{
pDIASession->Release();
pDataSource->Release();
return false;
}
// Get addresses for this module
std::list<BasedAddress> addresses;
for(stdext::hash_map<BasedAddress,int>::iterator iter=addressmap.begin();iter!=addressmap.end();iter++)
{
if(iter->first.nModule==modulenum)
{
addresses.push_back(iter->first);
}
}
stdext::hash_map<DWORD,wxInt32> functions;
int curidx=(int)llFuncs.size();
for(std::list<BasedAddress>::iterator itera=addresses.begin();itera!=addresses.end();itera++)
{
// Get the symbol for this thing
IDiaSymbol* pFunc;
if(FAILED(pDIASession->findSymbolByVA(itera->nAddr, SymTagFunction, &pFunc)) || pFunc==NULL)
{
continue;
}
// Get the unique symbol index id
DWORD indexId;
if(FAILED(pFunc->get_symIndexId(&indexId)))
{
pFunc->Release();
continue;
//.........这里部分代码省略.........
示例13: fputc
void PDBFileReader::ProcessSymbol(IDiaSymbol *symbol,DebugInfo &to)
{
// print a dot for each 1000 symbols processed
static int counter = 0;
++counter;
if( counter == 1000 ) {
fputc( '.', stderr );
counter = 0;
}
DWORD section,offset,rva;
enum SymTagEnum tag;
ULONGLONG length = 0;
BSTR name = 0, srcFileName = 0;
symbol->get_symTag((DWORD *) &tag);
symbol->get_relativeVirtualAddress(&rva);
symbol->get_length(&length);
symbol->get_addressSection(§ion);
symbol->get_addressOffset(&offset);
// get length from type for data
if( tag == SymTagData )
{
IDiaSymbol *type = NULL;
if( symbol->get_type(&type) == S_OK ) // no SUCCEEDED test as may return S_FALSE!
{
if( FAILED(type->get_length(&length)) )
length = 0;
type->Release();
}
else
length = 0;
}
const SectionContrib *contrib = ContribFromSectionOffset(section,offset);
sInt objFile = 0;
sInt sectionType = DIC_UNKNOWN;
if(contrib)
{
objFile = contrib->ObjFile;
sectionType = contrib->Type;
}
symbol->get_name(&name);
// fill out structure
sChar *nameStr = BStrToString( name, "<noname>", true);
to.Symbols.push_back( DISymbol() );
DISymbol *outSym = &to.Symbols.back();
outSym->name = outSym->mangledName = to.MakeString(nameStr);
outSym->objFileNum = objFile;
outSym->VA = rva;
outSym->Size = (sU32) length;
outSym->Class = sectionType;
outSym->NameSpNum = to.GetNameSpaceByName(nameStr);
// clean up
delete[] nameStr;
if(name) SysFreeString(name);
}
示例14: SysAllocString
void PDBFileReader::ReadEverything(DebugInfo &to)
{
ULONG celt;
Contribs = 0;
nContribs = 0;
// read section table
IDiaEnumTables *enumTables;
if(Session->getEnumTables(&enumTables) == S_OK)
{
VARIANT vIndex;
vIndex.vt = VT_BSTR;
vIndex.bstrVal = SysAllocString(L"Sections");
IDiaTable *secTable;
if(enumTables->Item(vIndex,&secTable) == S_OK)
{
LONG count;
secTable->get_Count(&count);
Contribs = new SectionContrib[count];
nContribs = 0;
IDiaSectionContrib *item;
while(SUCCEEDED(secTable->Next(1,(IUnknown **)&item,&celt)) && celt == 1)
{
SectionContrib &contrib = Contribs[nContribs++];
item->get_addressOffset(&contrib.Offset);
item->get_addressSection(&contrib.Section);
item->get_length(&contrib.Length);
item->get_compilandId(&contrib.Compiland);
BOOL code=FALSE,initData=FALSE,uninitData=FALSE;
item->get_code(&code);
item->get_initializedData(&initData);
item->get_uninitializedData(&uninitData);
if(code && !initData && !uninitData)
contrib.Type = DIC_CODE;
else if(!code && initData && !uninitData)
contrib.Type = DIC_DATA;
else if(!code && !initData && uninitData)
contrib.Type = DIC_BSS;
else
contrib.Type = DIC_UNKNOWN;
BSTR objFileName = 0;
IDiaSymbol *compiland = 0;
item->get_compiland(&compiland);
if(compiland)
{
compiland->get_name(&objFileName);
compiland->Release();
}
sChar *objFileStr = BStrToString(objFileName,"<noobjfile>");
contrib.ObjFile = to.GetFileByName(objFileStr);
delete[] objFileStr;
if(objFileName)
SysFreeString(objFileName);
item->Release();
}
secTable->Release();
}
SysFreeString(vIndex.bstrVal);
enumTables->Release();
}
// enumerate symbols by (virtual) address
IDiaEnumSymbolsByAddr *enumByAddr;
if(SUCCEEDED(Session->getSymbolsByAddr(&enumByAddr)))
{
IDiaSymbol *symbol;
// get first symbol to get first RVA (argh)
if(SUCCEEDED(enumByAddr->symbolByAddr(1,0,&symbol)))
{
DWORD rva;
if(symbol->get_relativeVirtualAddress(&rva) == S_OK)
{
symbol->Release();
// now, enumerate by rva.
if(SUCCEEDED(enumByAddr->symbolByRVA(rva,&symbol)))
{
do
{
ProcessSymbol(symbol,to);
symbol->Release();
if(FAILED(enumByAddr->Next(1,&symbol,&celt)))
break;
}
while(celt == 1);
//.........这里部分代码省略.........
示例15: GetAddr
AddrInfo GetAddr(wstring req)
{
uint32_t module;
uint64_t addr;
int charsRead = swscanf_s(req.c_str(), L"%d %llu", &module, &addr);
AddrInfo ret;
ZeroMemory(&ret, sizeof(ret));
if(module > 0 && module < modules.size())
{
SymTagEnum tag = SymTagFunction;
IDiaSymbol *pFunc = NULL;
HRESULT hr = modules[module].pSession->findSymbolByVA(addr, tag, &pFunc);
if(hr != S_OK)
{
if(pFunc)
pFunc->Release();
// try again looking for public symbols
tag = SymTagPublicSymbol;
hr = modules[module].pSession->findSymbolByVA(addr, tag, &pFunc);
if(hr != S_OK)
{
if(pFunc)
pFunc->Release();
return ret;
}
}
DWORD opts = 0;
opts |= UNDNAME_NO_LEADING_UNDERSCORES;
opts |= UNDNAME_NO_MS_KEYWORDS;
opts |= UNDNAME_NO_FUNCTION_RETURNS;
opts |= UNDNAME_NO_ALLOCATION_MODEL;
opts |= UNDNAME_NO_ALLOCATION_LANGUAGE;
opts |= UNDNAME_NO_THISTYPE;
opts |= UNDNAME_NO_ACCESS_SPECIFIERS;
opts |= UNDNAME_NO_THROW_SIGNATURES;
opts |= UNDNAME_NO_MEMBER_TYPE;
opts |= UNDNAME_NO_RETURN_UDT_MODEL;
opts |= UNDNAME_32_BIT_DECODE;
opts |= UNDNAME_NO_LEADING_UNDERSCORES;
// first try undecorated name
BSTR file;
hr = pFunc->get_undecoratedNameEx(opts, &file);
// if not, just try name
if(hr != S_OK)
{
hr = pFunc->get_name(&file);
if(hr != S_OK)
{
pFunc->Release();
SysFreeString(file);
return ret;
}
wcsncpy_s(ret.funcName, file, 126);
}
else
{
wcsncpy_s(ret.funcName, file, 126);
wchar_t *voidparam = wcsstr(ret.funcName, L"(void)");
// remove stupid (void) for empty parameters
if(voidparam != NULL)
{
*(voidparam + 1) = L')';
*(voidparam + 2) = 0;
}
}
pFunc->Release();
pFunc = NULL;
SysFreeString(file);
// find the line numbers touched by this address.
IDiaEnumLineNumbers *lines = NULL;
hr = modules[module].pSession->findLinesByVA(addr, DWORD(4), &lines);
if(FAILED(hr))
{
if(lines)
lines->Release();
return ret;
}
IDiaLineNumber *line = NULL;
ULONG count = 0;
// just take the first one
if(SUCCEEDED(lines->Next(1, &line, &count)) && count == 1)
{
IDiaSourceFile *dia_source = NULL;
//.........这里部分代码省略.........