-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
An "assert with stacktrace" macro could be useful for times when debugging with GDB just isn't practical.
Here is one such possibility (may need tweaking) adapted from https://stackoverflow.com/questions/37473/how-can-i-assert-without-using-abort
#include <execinfo.h>
void print_stack_trace(int fd)
{
void *array[256];
size_t size;
size = backtrace (array, 256);
backtrace_symbols_fd(array, size, fd);
}
#define ASSERT_STACKTRACE(expr) do { \
if (!(expr)) \
{ \
fprintf(stderr, \
"file %s: line %d (%s): precondition `%s' failed.", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr); \
print_stack_trace(2); \
assert(expr); \
}; } while(0)
Reactions are currently unavailable