I'm trying to get symbols from addresses I got from my stack, but SymFromAddr keeps failing with system error 126 (The specified module could not be found.)
I'm initializing the symboling thing withSymInitialize(m_processHa开发者_高级运维ndle, NULL, TRUE);
(the last parameter == true ==> It loads the PDB automatically)
and I use SymFromAddr like this:
SYMBOL_INFO_PACKAGE sym = { sizeof(sym) };
sym.si.MaxNameLen = MAX_SYM_NAME;
DWORD64 displacement = 0;
bool ok = SymFromAddr(m_processHandle, address, &displacement, &sym.si);
The code is in C++ on windows. and the PDB FILE IS IN THE DIRECTORY OF THE EXE! What am I doing wrong? thanks :)
SymFromAddr is a little bit capricious.
- If any LoadLibrary occur between SymInitialize and SymFromAddr it may not work. If SymFromAddr you can perfom a SymInitialize again (hint: you can cache address to avoid a lot of SymInitialize which is a huge CPU consummer)
- 64 bits implementation of SymFromAddr (ie. SymFromAddr64) works better
- If code is not optimized it'll work better
- VC9 generated pdb works better than older version.
You can find some idea in the following code http://code.google.com/p/nprof/source/browse/0.11/Hook/StackWalker.cpp?r=281
精彩评论