diff --git a/libmcount/mcount.c b/libmcount/mcount.c index 8b7d3a828..9912c807e 100644 --- a/libmcount/mcount.c +++ b/libmcount/mcount.c @@ -740,7 +740,8 @@ static void segv_handler(int sig, siginfo_t *si, void *ctx) rstack--; } - pr_red("\nPlease report this bug to https://github.com/namhyung/uftrace/issues.\n\n"); + pr_out("\n"); + pr_red(BUG_REPORT_MSG); out: sigaction(sig, &old_sigact[(sig == SIGSEGV)], NULL); diff --git a/utils/utils.h b/utils/utils.h index 7266098fd..0bdfd76b8 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "compiler.h" @@ -44,6 +45,8 @@ #define NSEC_PER_SEC 1000000000 #define NSEC_PER_MSEC 1000000 +#define BUG_REPORT_MSG "Please report this bug to https://github.com/namhyung/uftrace/issues.\n\n" + extern int debug; extern FILE *logfp; extern FILE *outfp; @@ -369,4 +372,22 @@ char *absolute_dirname(const char *path, char *resolved_path); void stacktrace(void); +#define ASSERT(cond) \ + if (unlikely(!(cond))) { \ + pr_red("%s:%d: %s: ASSERT `%s' failed.\n", \ + __FILE__, __LINE__, __func__, #cond); \ + stacktrace(); \ + pr_red(BUG_REPORT_MSG); \ + raise(SIGTRAP); \ + } + +#define DASSERT(cond) \ + if (DEBUG_MODE && unlikely(!(cond))) { \ + pr_red("%s:%d: %s: DEBUG ASSERT `%s' failed.\n", \ + __FILE__, __LINE__, __func__, #cond); \ + stacktrace(); \ + pr_red(BUG_REPORT_MSG); \ + raise(SIGTRAP); \ + } + #endif /* UFTRACE_UTILS_H */