#ifndef UC_BACKTRACE_H_ #define UC_BACKTRACE_H_ #include #include #include "utils.h" #ifdef __cplusplus extern "C" { #endif #define UC_BACKTRACE_STDERR uc_backtrace_fd(2) /** * Print a stacktrace to the given file descriptor. * * @param fd filedescriptor to write to. */ void uc_backtrace_fd(int fd); /** * Print a stactrace to the given buffer * (Note that unlike uc_backtrace_fd(), this function * does malloc() call and may fail in a signal handler or * if memory is corrupted. * * @param buf buffer to place the stacktrace in. * @param len length of buffer */ void uc_backtrace_buf(char *buf, size_t len); /** * assert() that is not affected by NDEBUG define */ #define UC_ASSERT(expr)\ do {\ if (!(expr) ) {\ fprintf(stderr,\ "UC_ASSERT failed '%s' %s\n", UC_STRINGIFY(expr), UC_SRC_LOCATION);\ UC_BACKTRACE_STDERR;\ abort();\ }\ } while (0) /** * Macro for asserting code that should not be reached, * terminates the program if executed */ #define UC_NOT_REACED()\ do {\ fprintf(stderr, "UC_NOT_REACHED at %s\n", UC_SRC_LOCATION);\ UC_BACKTRACE_STDERR;\ abort();\ } while (0) #ifdef __cplusplus } #endif #endif