updated the assert macro to send SIGINT to the process (to break into the debugger) and also to be used on macos

This commit is contained in:
Arvid Norberg 2007-09-17 02:32:51 +00:00
parent 33add5bb91
commit 8e899fa9fd
3 changed files with 15 additions and 7 deletions

10
Jamfile
View File

@ -106,12 +106,12 @@ rule building ( properties * )
{ {
local result ; local result ;
if <toolset>gcc in $(properties) if <variant>debug in $(properties)
&& <target-os>linux in $(properties) && ( <target-os>linux in $(properties)
&& <variant>debug in $(properties) || <target-os>darwin in $(properties) )
&& ( <toolset>gcc in $(properties)
|| <toolset>darwin in $(properties) )
{ {
# for backtraces in assertion failures
# which only works on ELF targets with gcc
result += <source>src/assert.cpp ; result += <source>src/assert.cpp ;
} }

View File

@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cassert> #include <cassert>
#ifndef NDEBUG #ifndef NDEBUG
#if defined __linux__ && defined __GNUC__ #if (defined __linux__ || defined __MACH__) && defined __GNUC__
#ifdef assert #ifdef assert
#undef assert #undef assert
#endif #endif

View File

@ -34,7 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h>
#if defined __linux__ && defined __GNUC__
#include <execinfo.h> #include <execinfo.h>
#endif
void assert_fail(char const* expr, int line, char const* file, char const* function) void assert_fail(char const* expr, int line, char const* file, char const* function)
{ {
@ -48,6 +51,7 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct
"expression: %s\n" "expression: %s\n"
"stack:\n", file, line, function, expr); "stack:\n", file, line, function, expr);
#if defined __linux__ && defined __GNUC__
void* stack[50]; void* stack[50];
int size = backtrace(stack, 50); int size = backtrace(stack, 50);
char** symbols = backtrace_symbols(stack, size); char** symbols = backtrace_symbols(stack, size);
@ -58,7 +62,11 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct
} }
free(symbols); free(symbols);
exit(1); #endif
// send SIGINT to the current process
// to break into the debugger
raise(SIGINT);
abort();
} }
#endif #endif