[core] expose ck_bt() for debugging

master
Glenn Strauss 2 years ago
parent bd72d1927a
commit 84ff9ac9c9

@ -373,15 +373,31 @@ error:
#endif
__attribute_noreturn__
void
ck_bt_abort (const char *filename, unsigned int line, const char *msg)
__attribute_noinline__
__attribute_nonnull__
static void
ck_bt_stderr (const char *filename, unsigned int line, const char *msg, const char *fmt)
{
fprintf(stderr, "%s.%u: %s\n", filename, line, msg);
fprintf(stderr, fmt, filename, line, msg);
#ifdef HAVE_LIBUNWIND
ck_backtrace(stderr);
#endif
fflush(stderr);
}
void
ck_bt (const char *filename, unsigned int line, const char *msg)
{
ck_bt_stderr(filename, line, msg, "%s.%u: %s\n");
}
__attribute_noreturn__
void
ck_bt_abort (const char *filename, unsigned int line, const char *msg)
{
ck_bt(filename, line, msg);
abort();
}
@ -391,10 +407,6 @@ void ck_assert_failed(const char *filename, unsigned int line, const char *msg)
{
/* same as ck_bt_abort() but add "assertion failed: " prefix here
* to avoid bloating string tables in callers */
fprintf(stderr, "%s.%u: assertion failed: %s\n", filename, line, msg);
#ifdef HAVE_LIBUNWIND
ck_backtrace(stderr);
#endif
fflush(stderr);
ck_bt_stderr(filename, line, msg, "%s.%u: assertion failed: %s\n");
abort();
}

@ -56,6 +56,12 @@ __attribute_nonnull__
int ck_memeq_const_time_fixed_len (const void *a, const void *b, size_t len);
/*(ck_bt() is not from C11 Annex K)
* ck_bt() prints backtrace to stderr */
__attribute_cold__
__attribute_nonnull__
void ck_bt(const char *filename, unsigned int line, const char *msg);
/*(ck_bt_abort() is not from C11 Annex K)
* ck_bt_abort() prints backtrace to stderr and calls abort() */
__attribute_cold__

Loading…
Cancel
Save