StackWalk64 on Windows – Get symbol name

You have set symbol.MaxNameLength to 255, but you allocated “symbol” on the stack with IMAGEHLP_SYMBOL64 symbol;. That type is defined as: typedef struct _IMAGEHLP_SYMBOL64 { DWORD SizeOfStruct; DWORD64 Address; DWORD Size; DWORD Flags; DWORD MaxNameLength; TCHAR Name[1]; } IMAGEHLP_SYMBOL64; Notice that the Name field only has one character by default. If you want to store … Read more

Getting a backtrace of other thread

I implemented that myself here. Initially, I wanted to implement something similar as suggested here, i.e. getting somehow the top frame pointer of the thread and unwinding it manually (the linked source is derived from Apples backtrace implementation, thus might be Apple-specific, but the idea is generic). However, to have that safe (and the source … Read more

Win32 – Backtrace from C code

Alright, now I got it. : ) The problem was in the SYMBOL_INFO structure. It needs to be allocated on the heap, reserving space for the symbol name, and initialized properly. Here’s the final code: void printStack( void ); void printStack( void ) { unsigned int i; void * stack[ 100 ]; unsigned short frames; … Read more

How can I get PHP to produce a backtrace upon errors?

My script for installing an error handler that produces a backtrace: <?php function process_error_backtrace($errno, $errstr, $errfile, $errline, $errcontext) { if(!(error_reporting() & $errno)) return; switch($errno) { case E_WARNING : case E_USER_WARNING : case E_STRICT : case E_NOTICE : case E_USER_NOTICE : $type=”warning”; $fatal = false; break; default : $type=”fatal error”; $fatal = true; break; } $trace … Read more