FreeRDP
TestBacktrace.c
1 #include <stdio.h>
2 #include <winpr/debug.h>
3 
4 int TestBacktrace(int argc, char* argv[])
5 {
6  int rc = -1;
7  size_t used = 0;
8  char** msg = NULL;
9  void* stack = winpr_backtrace(20);
10 
11  WINPR_UNUSED(argc);
12  WINPR_UNUSED(argv);
13 
14  if (!stack)
15  {
16  (void)fprintf(stderr, "winpr_backtrace failed!\n");
17  return -1;
18  }
19 
20  msg = winpr_backtrace_symbols(stack, &used);
21 
22  if (msg)
23  {
24  for (size_t x = 0; x < used; x++)
25  printf("%" PRIuz ": %s\n", x, msg[x]);
26 
27  rc = 0;
28  }
29 
30  winpr_backtrace_symbols_fd(stack, fileno(stdout));
31  winpr_backtrace_free(stack);
32  free(msg);
33  return rc;
34 }