]> git.lizzy.rs Git - nothing.git/blob - src/system/stacktrace.c
Remove TODO(#943)
[nothing.git] / src / system / stacktrace.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #ifdef __GNUC__
4 #include <execinfo.h>
5 #include <unistd.h>
6 #endif
7
8 #include "./stacktrace.h"
9
10 #define N 100
11
12 void print_stacktrace(void)
13 {
14 #ifdef __GNUC__
15     void *array[N];
16     int size;
17
18     size = backtrace(array, N);
19
20     if (size <= 0) {
21         return;
22     }
23
24     fprintf(stderr, "Stacktrace: \n");
25     backtrace_symbols_fd(array + 1, size - 1, STDERR_FILENO);
26 #endif
27 }
28
29 void __trace_assert(const char *file, int line, const char *function, const char *message)
30 {
31     fprintf(
32         stderr,
33         "%s:%d: %s: Assertion `%s' failed\n",
34         file, line,
35         function,
36         message);
37     print_stacktrace();
38     exit(1);
39 }