parent
df988dfff3
commit
cdf081dbd5
|
@ -434,19 +434,19 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * /*context*
|
||||||
|
|
||||||
static const ULONG maxnamelength = 512;
|
static const ULONG maxnamelength = 512;
|
||||||
struct IMAGEHLP_SYMBOL64_EXT : public IMAGEHLP_SYMBOL64 {
|
struct IMAGEHLP_SYMBOL64_EXT : public IMAGEHLP_SYMBOL64 {
|
||||||
TCHAR NameExt[maxnamelength];
|
TCHAR NameExt[maxnamelength];
|
||||||
};
|
};
|
||||||
typedef BOOL (WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
|
typedef BOOL (WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
|
||||||
static fpStackWalk64 pStackWalk64;
|
static fpStackWalk64 pStackWalk64;
|
||||||
typedef DWORD64 (WINAPI *fpSymGetModuleBase64)(HANDLE, DWORD64);
|
typedef DWORD64(WINAPI *fpSymGetModuleBase64)(HANDLE, DWORD64);
|
||||||
static fpSymGetModuleBase64 pSymGetModuleBase64;
|
static fpSymGetModuleBase64 pSymGetModuleBase64;
|
||||||
typedef BOOL (WINAPI *fpSymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
|
typedef BOOL (WINAPI *fpSymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
|
||||||
static fpSymGetSymFromAddr64 pSymGetSymFromAddr64;
|
static fpSymGetSymFromAddr64 pSymGetSymFromAddr64;
|
||||||
typedef BOOL (WINAPI *fpSymGetLineFromAddr64)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
|
typedef BOOL (WINAPI *fpSymGetLineFromAddr64)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
|
||||||
static fpSymGetLineFromAddr64 pSymGetLineFromAddr64;
|
static fpSymGetLineFromAddr64 pSymGetLineFromAddr64;
|
||||||
typedef DWORD (WINAPI *fpUnDecorateSymbolName)( const TCHAR*, PTSTR, DWORD, DWORD) ;
|
typedef DWORD (WINAPI *fpUnDecorateSymbolName)(const TCHAR*, PTSTR, DWORD, DWORD) ;
|
||||||
static fpUnDecorateSymbolName pUnDecorateSymbolName;
|
static fpUnDecorateSymbolName pUnDecorateSymbolName;
|
||||||
typedef PVOID (WINAPI *fpSymFunctionTableAccess64)(HANDLE, DWORD64);
|
typedef PVOID(WINAPI *fpSymFunctionTableAccess64)(HANDLE, DWORD64);
|
||||||
static fpSymFunctionTableAccess64 pSymFunctionTableAccess64;
|
static fpSymFunctionTableAccess64 pSymFunctionTableAccess64;
|
||||||
typedef BOOL (WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL);
|
typedef BOOL (WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL);
|
||||||
static fpSymInitialize pSymInitialize;
|
static fpSymInitialize pSymInitialize;
|
||||||
|
@ -454,33 +454,33 @@ static fpSymInitialize pSymInitialize;
|
||||||
// avoid explicit dependency on Dbghelp.dll
|
// avoid explicit dependency on Dbghelp.dll
|
||||||
static bool loadDbgHelp()
|
static bool loadDbgHelp()
|
||||||
{
|
{
|
||||||
HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll");
|
HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll");
|
||||||
if (!hLib)
|
if (!hLib)
|
||||||
return true;
|
return true;
|
||||||
pStackWalk64 = (fpStackWalk64) ::GetProcAddress(hLib, "StackWalk64");
|
pStackWalk64 = (fpStackWalk64) ::GetProcAddress(hLib, "StackWalk64");
|
||||||
pSymGetModuleBase64 = (fpSymGetModuleBase64) ::GetProcAddress(hLib, "SymGetModuleBase64");
|
pSymGetModuleBase64 = (fpSymGetModuleBase64) ::GetProcAddress(hLib, "SymGetModuleBase64");
|
||||||
pSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) ::GetProcAddress(hLib, "SymGetSymFromAddr64");
|
pSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) ::GetProcAddress(hLib, "SymGetSymFromAddr64");
|
||||||
pSymGetLineFromAddr64 = (fpSymGetLineFromAddr64)::GetProcAddress(hLib, "SymGetLineFromAddr64");
|
pSymGetLineFromAddr64 = (fpSymGetLineFromAddr64)::GetProcAddress(hLib, "SymGetLineFromAddr64");
|
||||||
pSymFunctionTableAccess64 = (fpSymFunctionTableAccess64)::GetProcAddress(hLib, "SymFunctionTableAccess64");
|
pSymFunctionTableAccess64 = (fpSymFunctionTableAccess64)::GetProcAddress(hLib, "SymFunctionTableAccess64");
|
||||||
pSymInitialize = (fpSymInitialize) ::GetProcAddress(hLib, "SymInitialize");
|
pSymInitialize = (fpSymInitialize) ::GetProcAddress(hLib, "SymInitialize");
|
||||||
pUnDecorateSymbolName = (fpUnDecorateSymbolName)::GetProcAddress(hLib, "UnDecorateSymbolName");
|
pUnDecorateSymbolName = (fpUnDecorateSymbolName)::GetProcAddress(hLib, "UnDecorateSymbolName");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex)
|
static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex)
|
||||||
{
|
{
|
||||||
if (!loadDbgHelp())
|
if (!loadDbgHelp())
|
||||||
return;
|
return;
|
||||||
const HANDLE hProcess = GetCurrentProcess();
|
const HANDLE hProcess = GetCurrentProcess();
|
||||||
const HANDLE hThread = GetCurrentThread();
|
const HANDLE hThread = GetCurrentThread();
|
||||||
BOOL result = pSymInitialize(
|
BOOL result = pSymInitialize(
|
||||||
hProcess,
|
hProcess,
|
||||||
0,
|
0,
|
||||||
TRUE
|
TRUE
|
||||||
);
|
);
|
||||||
CONTEXT context = *(ex->ContextRecord);
|
CONTEXT context = *(ex->ContextRecord);
|
||||||
STACKFRAME64 stack={0};
|
STACKFRAME64 stack= {0};
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
stack.AddrPC.Offset = context.Eip;
|
stack.AddrPC.Offset = context.Eip;
|
||||||
stack.AddrPC.Mode = AddrModeFlat;
|
stack.AddrPC.Mode = AddrModeFlat;
|
||||||
|
@ -489,53 +489,52 @@ static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex)
|
||||||
stack.AddrFrame.Offset = context.Ebp;
|
stack.AddrFrame.Offset = context.Ebp;
|
||||||
stack.AddrFrame.Mode = AddrModeFlat;
|
stack.AddrFrame.Mode = AddrModeFlat;
|
||||||
#else
|
#else
|
||||||
stack.AddrPC.Offset = context.Rip;
|
stack.AddrPC.Offset = context.Rip;
|
||||||
stack.AddrPC.Mode = AddrModeFlat;
|
stack.AddrPC.Mode = AddrModeFlat;
|
||||||
stack.AddrStack.Offset = context.Rsp;
|
stack.AddrStack.Offset = context.Rsp;
|
||||||
stack.AddrStack.Mode = AddrModeFlat;
|
stack.AddrStack.Mode = AddrModeFlat;
|
||||||
stack.AddrFrame.Offset = context.Rsp;
|
stack.AddrFrame.Offset = context.Rsp;
|
||||||
stack.AddrFrame.Mode = AddrModeFlat;
|
stack.AddrFrame.Mode = AddrModeFlat;
|
||||||
#endif
|
#endif
|
||||||
IMAGEHLP_SYMBOL64_EXT symbol;
|
IMAGEHLP_SYMBOL64_EXT symbol;
|
||||||
IMAGEHLP_SYMBOL64* pSymbol = &symbol;
|
IMAGEHLP_SYMBOL64* pSymbol = &symbol;
|
||||||
pSymbol->SizeOfStruct = sizeof( IMAGEHLP_SYMBOL64 );
|
pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
||||||
pSymbol->MaxNameLength = maxnamelength;
|
pSymbol->MaxNameLength = maxnamelength;
|
||||||
DWORD64 displacement = 0;
|
DWORD64 displacement = 0;
|
||||||
int beyond_main=-1; // emergency exit, see below
|
int beyond_main=-1; // emergency exit, see below
|
||||||
for( ULONG frame = 0; ; frame++ )
|
for (ULONG frame = 0; ; frame++) {
|
||||||
{
|
|
||||||
result = pStackWalk64
|
result = pStackWalk64
|
||||||
(
|
(
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
IMAGE_FILE_MACHINE_I386,
|
IMAGE_FILE_MACHINE_I386,
|
||||||
#else
|
#else
|
||||||
IMAGE_FILE_MACHINE_AMD64,
|
IMAGE_FILE_MACHINE_AMD64,
|
||||||
#endif
|
#endif
|
||||||
hProcess,
|
hProcess,
|
||||||
hThread,
|
hThread,
|
||||||
&stack,
|
&stack,
|
||||||
&context,
|
&context,
|
||||||
NULL,
|
NULL,
|
||||||
pSymFunctionTableAccess64,
|
pSymFunctionTableAccess64,
|
||||||
pSymGetModuleBase64,
|
pSymGetModuleBase64,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
if( !result ) // official end...
|
if (!result) // official end...
|
||||||
|
break;
|
||||||
|
result = pSymGetSymFromAddr64(hProcess, (ULONG64)stack.AddrPC.Offset, &displacement, pSymbol);
|
||||||
|
TCHAR undname[maxnamelength]= {0};
|
||||||
|
pUnDecorateSymbolName((const TCHAR*)pSymbol->Name, (PTSTR)undname, GetArrayLength(undname), UNDNAME_COMPLETE);
|
||||||
|
if (beyond_main>=0)
|
||||||
|
++beyond_main;
|
||||||
|
if (_tcscmp(undname, _T("main"))==0)
|
||||||
|
beyond_main=0;
|
||||||
|
fprintf(f,
|
||||||
|
"%lu. 0x%08LX in ",
|
||||||
|
frame, (ULONG64)stack.AddrPC.Offset);
|
||||||
|
fputs((const char *)undname, f);
|
||||||
|
fputs("\n", f);
|
||||||
|
if (0==stack.AddrReturn.Offset || beyond_main>2) // StackWalk64() sometimes doesn't reach any end...
|
||||||
break;
|
break;
|
||||||
result = pSymGetSymFromAddr64( hProcess, ( ULONG64 )stack.AddrPC.Offset, &displacement, pSymbol );
|
|
||||||
TCHAR undname[maxnamelength]={0};
|
|
||||||
pUnDecorateSymbolName( (const TCHAR*)pSymbol->Name, (PTSTR)undname, GetArrayLength(undname), UNDNAME_COMPLETE );
|
|
||||||
if (beyond_main>=0)
|
|
||||||
++beyond_main;
|
|
||||||
if (_tcscmp(undname, _T("main"))==0)
|
|
||||||
beyond_main=0;
|
|
||||||
fprintf( f,
|
|
||||||
"%lu. 0x%08LX in ",
|
|
||||||
frame, (ULONG64)stack.AddrPC.Offset);
|
|
||||||
fputs((const char *)undname, f);
|
|
||||||
fputs("\n", f);
|
|
||||||
if (0==stack.AddrReturn.Offset || beyond_main>2) // StackWalk64() sometimes doesn't reach any end...
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +650,7 @@ static int filterException(int code, PEXCEPTION_POINTERS ex)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fputs("\n", f);
|
fputs("\n", f);
|
||||||
PrintCallstack(f, ex);
|
PrintCallstack(f, ex);
|
||||||
return EXCEPTION_EXECUTE_HANDLER;
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue