I would like to use this stacktrace method #4 implementation upon assertion failure.
So if there are no signals triggered, could you suggest a way to detect an assertion failure before the executable exits?
I would like to use this stacktrace method #4 implementation upon assertion failure.
So if there are no signals triggered, could you suggest a way to detect an assertion failure before the executable exits?
On Linux, an assert failure (if not disabled with -DNDEBUG) is doing (from /usr/include/assert.h)
# define assert(expr) \
((expr) \
? __ASSERT_VOID_CAST (0) \
: __assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
and the internal __assert_fail routine is calling abort, which sends a SIGABRT to the process, which you might catch if you really wanted to.
But a simpler way is to have your own "assert"-like macro. This is what many free software (GTK with g_assert, GCC with gcc_assert, ...) are actually doing.