I recently came through this post which talks about how you can a get a backtrace in windows using C.
void printStack( void ) {
unsigned int i;
void * stack[ 100 ];
unsigned short frames;
SYMBOL_INFO * symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize( process, NULL, TRUE );
frames = CaptureStackBackTrace( 0, 100, stack, NULL );
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
for( i = 0; i < frames; i++ )
{
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
printf( "%i: %s - 0x%0X\n", frames - i - 1, symbol->Name, symbol->Address );
}
free( symbol );
}
I compiled the code libdbghelp.lib
successfully. But problem is when I run the program it prints six frames, Three of which is empty with 0x0 address, However the first three are okay with slight difference than output of above post (Not a big deal, right?). I don't think any of function failed!
5: - 0x0
4: - 0x0
3: - 0x0
2: BaseThreadInitThunk - 0x7570FA10
1: RtlGetAppContainerNamedObjectPath - 0x772D7980
0: RtlGetAppContainerNamedObjectPath - 0x772D7980
At first, I gave a quick google search but didn't found any solution. I came to guess that I'm missing a pdb
file!
Now how do I get the other three symbols? Is it possible using GCC or I'll be punished for not bowing against lord Visual Studio IDE? If no, Is it possible to generate pdb
file anyway or using <dbghelp.h>
functions.