I'm trying to print backtrace from c code which is compiled under cygwin. I have followed the first answer from here: Win32 - Backtrace from C code
And I have written under cygwin shell:
User@WIN-EO6FNSIC9C1 ~
$ cat test.c
#include <windows.h>
#include <dbghelp.h>
#include <assert.h>
#include <stdio.h>
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, 50, 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 );
}
int foo2() {
        printStack();
}
void foo() {
        foo2();
}
int main() {
foo();
}
User@WIN-EO6FNSIC9C1 ~
$ gcc test.c -ldbghelp -g
test.c: In function ‘printStack’:
test.c:22:32: warning: cast from pointer to integer of different size    [-Wpointer-to-int-cast]
      SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
                                ^
User@WIN-EO6FNSIC9C1 ~
$ ./a.exe
4:  - 0x0
3:  - 0x0
2:  - 0x0
1:  - 0x0
0: cygwin_dll_init - 0x61006C30
Why it prints empty lines and zeroes addresses? Is it possible to print backtrace under cygwin using CaptureStackBackTrace or something like it?
 
    