Gabriel
2004-09-16 14:01:36 UTC
Hi!
I am implementing a StackWalker with the aid of dbgHelp.dll. A typical
process in our system depends on around 15 dlls (excluding MS and 3rd
party dlls). All dlls have the same preferred base address which means
they will be relocated by the OS.
I have two problems that I really can't solve nor understand:
1. Using StackWalk64 I don't get a complete callstack but only the
first two functions are resolved. It appears that the module lookup in
the callback fails for the other functions. But if I rebase all dlls
(ie distributing their load addresses) the complete call stacks
suddenly shows. I can't really understand why. An older version of
dbgHelp didn't have this problem.
My implementation is more or less a copy of the MFC dito, DbgHelp is
just a wrapper class for the dbgHelp.dll api
DWORD64 CALLBACK DbgHelp::getModuleBase(HANDLE process, DWORD64
address)
{
IMAGEHLP_MODULE64 moduleInfo;
moduleInfo.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
DWORD64 rc = 0;
// Check if present already
if(DbgHelp::instance()->SymGetModuleInfo64(address, &moduleInfo))
{
rc = moduleInfo.BaseOfImage;
}
else
{
// Find out the name of the module at requested address
MEMORY_BASIC_INFORMATION memoryBasicInfo;
if(::VirtualQueryEx(process, reinterpret_cast<void*>(address),
&memoryBasicInfo, sizeof(MEMORY_BASIC_INFORMATION)))
{
char file[MAX_PATH] = { 0 };
const DWORD cch = ::GetModuleFileNameA(
static_cast<HINSTANCE>(memoryBasicInfo.AllocationBase),
file, MAX_PATH);
// Load the module
DbgHelp::instance()->SymLoadModule64(0, cch ? file : 0, 0, 0, 0);
rc = reinterpret_cast<DWORD64>(memoryBasicInfo.AllocationBase);
}
}
return rc;
}
2. Since our app log the call stack quite frequently I would like to
just collect the stack addresses and do the symbol lookup at a later
stage. I would like to skip is the SymLoadModule64() in the code above
and move it to another part of the code. But doing this severly
cripples the stack as well, is StackWalk dependendant on the modules
being loaded in order to untangle the rest of the stack?
System:
Windows 2000 SP 4
Visual C++ 6.0 SP 5
DbgHelp.dll version 6.3.17.0 (latest)
I am implementing a StackWalker with the aid of dbgHelp.dll. A typical
process in our system depends on around 15 dlls (excluding MS and 3rd
party dlls). All dlls have the same preferred base address which means
they will be relocated by the OS.
I have two problems that I really can't solve nor understand:
1. Using StackWalk64 I don't get a complete callstack but only the
first two functions are resolved. It appears that the module lookup in
the callback fails for the other functions. But if I rebase all dlls
(ie distributing their load addresses) the complete call stacks
suddenly shows. I can't really understand why. An older version of
dbgHelp didn't have this problem.
My implementation is more or less a copy of the MFC dito, DbgHelp is
just a wrapper class for the dbgHelp.dll api
DWORD64 CALLBACK DbgHelp::getModuleBase(HANDLE process, DWORD64
address)
{
IMAGEHLP_MODULE64 moduleInfo;
moduleInfo.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
DWORD64 rc = 0;
// Check if present already
if(DbgHelp::instance()->SymGetModuleInfo64(address, &moduleInfo))
{
rc = moduleInfo.BaseOfImage;
}
else
{
// Find out the name of the module at requested address
MEMORY_BASIC_INFORMATION memoryBasicInfo;
if(::VirtualQueryEx(process, reinterpret_cast<void*>(address),
&memoryBasicInfo, sizeof(MEMORY_BASIC_INFORMATION)))
{
char file[MAX_PATH] = { 0 };
const DWORD cch = ::GetModuleFileNameA(
static_cast<HINSTANCE>(memoryBasicInfo.AllocationBase),
file, MAX_PATH);
// Load the module
DbgHelp::instance()->SymLoadModule64(0, cch ? file : 0, 0, 0, 0);
rc = reinterpret_cast<DWORD64>(memoryBasicInfo.AllocationBase);
}
}
return rc;
}
2. Since our app log the call stack quite frequently I would like to
just collect the stack addresses and do the symbol lookup at a later
stage. I would like to skip is the SymLoadModule64() in the code above
and move it to another part of the code. But doing this severly
cripples the stack as well, is StackWalk dependendant on the modules
being loaded in order to untangle the rest of the stack?
System:
Windows 2000 SP 4
Visual C++ 6.0 SP 5
DbgHelp.dll version 6.3.17.0 (latest)