win32 symbols now work for trace-malloc
r=dbaron,sr=brendan
This commit is contained in:
blythe%netscape.com 2001-11-27 22:54:05 +00:00
Родитель 9744cbf722
Коммит e916dcd71f
4 изменённых файлов: 168 добавлений и 16 удалений

Просмотреть файл

@ -579,6 +579,81 @@ static PLHashTable *methods = NULL;
#ifdef XP_WIN32
/*
* Callback used by SymGetModuleInfoEspecial
*/
static BOOL CALLBACK callbackEspecial(LPSTR aModuleName, ULONG aModuleBase, ULONG aModuleSize, PVOID aUserContext)
{
BOOL retval = TRUE;
DWORD addr = (DWORD)aUserContext;
/*
* You'll want to control this if we are running on an
* architecture where the addresses go the other direction.
* Not sure this is even a realistic consideration.
*/
const BOOL addressIncreases = TRUE;
/*
* If it falls in side the known range, load the symbols.
*/
if(addressIncreases
? (addr >= aModuleBase && addr <= (aModuleBase + aModuleSize))
: (addr <= aModuleBase && addr >= (aModuleBase - aModuleSize))
)
{
BOOL loadRes = FALSE;
HANDLE process = GetCurrentProcess();
loadRes = _SymLoadModule(process, NULL, aModuleName, NULL, aModuleBase, aModuleSize);
PR_ASSERT(FALSE != loadRes);
}
return retval;
}
/*
* SymGetModuleInfoEspecial
*
* Attempt to determine the module information.
* Bug 112196 says this DLL may not have been loaded at the time
* SymInitialize was called, and thus the module information
* and symbol information is not available.
* This code rectifies that problem.
*/
BOOL SymGetModuleInfoEspecial(HANDLE aProcess, DWORD aAddr, PIMAGEHLP_MODULE aModuleInfo)
{
BOOL retval = FALSE;
/*
* Give it a go.
* It may already be loaded.
*/
retval = _SymGetModuleInfo(aProcess, aAddr, aModuleInfo);
if(FALSE == retval)
{
BOOL enumRes = FALSE;
/*
* Not loaded, here's the magic.
* Go through all the modules.
*/
enumRes = EnumerateLoadedModules(aProcess, callbackEspecial, (PVOID)aAddr);
if(FALSE != enumRes)
{
/*
* One final go.
* If it fails, then well, we have other problems.
*/
retval = _SymGetModuleInfo(aProcess, aAddr, aModuleInfo);
}
}
return retval;
}
#define MAX_STACKFRAMES 256
#define MAX_UNMANGLED_NAME_LEN 256
@ -717,19 +792,18 @@ static callsite *calltree(int skip)
* callsite info. XXX static syms are masked by nearest lower global
* Load up the info for the dll.
*/
if (!_SymGetModuleInfo(myProcess,
if (!SymGetModuleInfoEspecial(myProcess,
frame[framenum].AddrPC.Offset,
&imagehelp)) {
DWORD error = GetLastError();
PR_ASSERT(error);
library = "unknown"; /* XXX mjudge sez "ew!" */
library = "unknown";
} else {
library = imagehelp.ModuleName;
}
symbol = (PIMAGEHLP_SYMBOL) buf;
symbol->SizeOfStruct = sizeof(buf);
symbol->MaxNameLength = 512;
symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
symbol->MaxNameLength = sizeof(buf) - sizeof(IMAGEHLP_SYMBOL);
symbol->Name[symbol->MaxNameLength] = '\0';
ok = _SymGetSymFromAddr(myProcess,
frame[framenum].AddrPC.Offset,

Просмотреть файл

@ -80,6 +80,7 @@ static PRBool GetModuleFromAddress(uint32 addr, char* outBuf)
/***************************************************************************/
#ifdef VERBOSE
// XXX This is a quick hack to show that x86 Win32 stack walking can be done
// with this sort of loop following the bp.
@ -105,6 +106,7 @@ void dumpStack()
}
printf("\n");
}
#endif
char* _stdcall call2(void* v)
{
@ -239,8 +241,8 @@ void * __cdecl dhw_new(size_t size)
#ifdef VERBOSE
printf("* new called to get %d bytes. returned %#x\n", size, result);
#endif
dumpStack();
#endif
MallocCallback(result,size);//do we need a different one for new?
// printf("\n");
g_lockOut = FALSE;
@ -263,8 +265,8 @@ void __cdecl dhw_delete(void* p)
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* delete called for %#x\n", p);
#endif
dumpStack();
#endif
FreeCallback(p);
// printf("\n");
g_lockOut = FALSE;

Просмотреть файл

@ -579,6 +579,81 @@ static PLHashTable *methods = NULL;
#ifdef XP_WIN32
/*
* Callback used by SymGetModuleInfoEspecial
*/
static BOOL CALLBACK callbackEspecial(LPSTR aModuleName, ULONG aModuleBase, ULONG aModuleSize, PVOID aUserContext)
{
BOOL retval = TRUE;
DWORD addr = (DWORD)aUserContext;
/*
* You'll want to control this if we are running on an
* architecture where the addresses go the other direction.
* Not sure this is even a realistic consideration.
*/
const BOOL addressIncreases = TRUE;
/*
* If it falls in side the known range, load the symbols.
*/
if(addressIncreases
? (addr >= aModuleBase && addr <= (aModuleBase + aModuleSize))
: (addr <= aModuleBase && addr >= (aModuleBase - aModuleSize))
)
{
BOOL loadRes = FALSE;
HANDLE process = GetCurrentProcess();
loadRes = _SymLoadModule(process, NULL, aModuleName, NULL, aModuleBase, aModuleSize);
PR_ASSERT(FALSE != loadRes);
}
return retval;
}
/*
* SymGetModuleInfoEspecial
*
* Attempt to determine the module information.
* Bug 112196 says this DLL may not have been loaded at the time
* SymInitialize was called, and thus the module information
* and symbol information is not available.
* This code rectifies that problem.
*/
BOOL SymGetModuleInfoEspecial(HANDLE aProcess, DWORD aAddr, PIMAGEHLP_MODULE aModuleInfo)
{
BOOL retval = FALSE;
/*
* Give it a go.
* It may already be loaded.
*/
retval = _SymGetModuleInfo(aProcess, aAddr, aModuleInfo);
if(FALSE == retval)
{
BOOL enumRes = FALSE;
/*
* Not loaded, here's the magic.
* Go through all the modules.
*/
enumRes = EnumerateLoadedModules(aProcess, callbackEspecial, (PVOID)aAddr);
if(FALSE != enumRes)
{
/*
* One final go.
* If it fails, then well, we have other problems.
*/
retval = _SymGetModuleInfo(aProcess, aAddr, aModuleInfo);
}
}
return retval;
}
#define MAX_STACKFRAMES 256
#define MAX_UNMANGLED_NAME_LEN 256
@ -717,19 +792,18 @@ static callsite *calltree(int skip)
* callsite info. XXX static syms are masked by nearest lower global
* Load up the info for the dll.
*/
if (!_SymGetModuleInfo(myProcess,
if (!SymGetModuleInfoEspecial(myProcess,
frame[framenum].AddrPC.Offset,
&imagehelp)) {
DWORD error = GetLastError();
PR_ASSERT(error);
library = "unknown"; /* XXX mjudge sez "ew!" */
library = "unknown";
} else {
library = imagehelp.ModuleName;
}
symbol = (PIMAGEHLP_SYMBOL) buf;
symbol->SizeOfStruct = sizeof(buf);
symbol->MaxNameLength = 512;
symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
symbol->MaxNameLength = sizeof(buf) - sizeof(IMAGEHLP_SYMBOL);
symbol->Name[symbol->MaxNameLength] = '\0';
ok = _SymGetSymFromAddr(myProcess,
frame[framenum].AddrPC.Offset,

Просмотреть файл

@ -80,6 +80,7 @@ static PRBool GetModuleFromAddress(uint32 addr, char* outBuf)
/***************************************************************************/
#ifdef VERBOSE
// XXX This is a quick hack to show that x86 Win32 stack walking can be done
// with this sort of loop following the bp.
@ -105,6 +106,7 @@ void dumpStack()
}
printf("\n");
}
#endif
char* _stdcall call2(void* v)
{
@ -239,8 +241,8 @@ void * __cdecl dhw_new(size_t size)
#ifdef VERBOSE
printf("* new called to get %d bytes. returned %#x\n", size, result);
#endif
dumpStack();
#endif
MallocCallback(result,size);//do we need a different one for new?
// printf("\n");
g_lockOut = FALSE;
@ -263,8 +265,8 @@ void __cdecl dhw_delete(void* p)
g_lockOut = TRUE;
#ifdef VERBOSE
printf("* delete called for %#x\n", p);
#endif
dumpStack();
#endif
FreeCallback(p);
// printf("\n");
g_lockOut = FALSE;