Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

51 lignes
1.4 KiB

  1. #pragma once
  2. #include "platform.hpp"
  3. #if defined FTB_WINDOWS
  4. # include <dbghelp.h>
  5. #else
  6. # include <execinfo.h>
  7. # include <unistd.h>
  8. # include "stdio.h"
  9. # include "stdlib.h"
  10. #endif
  11. auto print_stacktrace() -> void {
  12. #if defined FTB_WINDOWS
  13. printf("Stacktrace: \n");
  14. unsigned int i;
  15. void * stack[ 100 ];
  16. HANDLE process;
  17. SYMBOL_INFO * symbol;
  18. symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
  19. symbol->MaxNameLen = 255;
  20. symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
  21. unsigned short frames;
  22. frames = CaptureStackBackTrace( 1, 100, stack, NULL );
  23. process = GetCurrentProcess();
  24. SymInitialize( process, NULL, TRUE );
  25. for( i = 0; i < frames; i++ ) {
  26. SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
  27. printf( " %3i: %s\n", frames - i - 1, symbol->Name);
  28. }
  29. fflush(stdout);
  30. #else
  31. // NOTE(Felix): Don't forget to compile with "-rdynamic"
  32. printf("Stacktrace (this is unmagled -- sorry): \n");
  33. char **strings;
  34. size_t i, size;
  35. enum Constexpr { MAX_SIZE = 1024 };
  36. void *array[MAX_SIZE];
  37. size = backtrace(array, MAX_SIZE);
  38. strings = backtrace_symbols(array, size);
  39. for (i = 0; i < size; i++)
  40. printf(" %3lu: %s\n", size - i - 1, strings[i]);
  41. puts("");
  42. ftb_free(strings);
  43. #endif
  44. }