Commit 2c3875a6 authored by sagnowski's avatar sagnowski
Browse files

Add stack backtrace on Windows

parent 7dc0df55
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ endif()
add_executable(EVS_cod lib_enc/encoder.c)
target_link_libraries(EVS_cod lib_evs)
if(WIN32)
  target_link_libraries(EVS_cod Ws2_32)
  target_link_libraries(EVS_cod Ws2_32 Dbghelp)
endif()

add_executable(EVS_dec lib_dec/decoder.c)
target_link_libraries(EVS_dec lib_evs)
if(WIN32)
  target_link_libraries(EVS_dec Ws2_32)
  target_link_libraries(EVS_dec Ws2_32 Dbghelp)
endif()

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
+23 −1
Original line number Diff line number Diff line
@@ -213,8 +213,30 @@ void print_stack(void) {
  free(strs);
}
#else
#include <windows.h>
#include <dbghelp.h>
void print_stack(void) {
  printf("[BASOP] <call stack would be here> - printing call stack currently only supported on UNIX\n");
  void *call_stack[200];
  int i;
  int num_frames;

  HANDLE process;
  SYMBOL_INFO *symbol;

  process = GetCurrentProcess();
  SymInitialize(process, NULL, TRUE);
  symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
  symbol->MaxNameLen = 255;
  symbol->SizeOfStruct = sizeof(SYMBOL_INFO);

  num_frames = CaptureStackBackTrace(0, 100, call_stack, NULL);

  for (i = 0; i < num_frames; ++i) {
    SymFromAddr(process, (DWORD64)(call_stack[i]), 0, symbol);
    printf("[BASOP] %i %s - 0x%llX\n", i, symbol->Name, symbol->Address);
  }

  free(symbol);
}
#endif