(#594) Introduce stacktrace unit
parent
cee8d11e65
commit
1b8f8b56f4
|
@ -119,6 +119,8 @@ add_executable(nothing
|
|||
src/game/level_script.h
|
||||
src/ebisp/std.h
|
||||
src/ebisp/std.c
|
||||
src/system/stacktrace.h
|
||||
src/system/stacktrace.c
|
||||
)
|
||||
|
||||
add_executable(repl
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#ifdef __GNUC__
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "./stacktrace.h"
|
||||
|
||||
#define N 10
|
||||
|
||||
void print_stacktrace(void)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
void *array[N];
|
||||
int size;
|
||||
|
||||
size = backtrace(array, N);
|
||||
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Stacktrace: \n");
|
||||
backtrace_symbols_fd(array + 1, size - 1, STDERR_FILENO);
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef STACKTRACE_H_
|
||||
#define STACKTRACE_H_
|
||||
|
||||
#define trace_assert(condition) \
|
||||
if (!(condition)) { \
|
||||
fprintf( \
|
||||
stderr, \
|
||||
"%s:%d: %s: Assertion `%s' failed\n", \
|
||||
__FILE__, __LINE__, \
|
||||
__func__, \
|
||||
#condition); \
|
||||
print_stacktrace(); \
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
void print_stacktrace(void);
|
||||
|
||||
#endif // STACKTRACE_H_
|
Loading…
Reference in New Issue