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:
parent
33add5bb91
commit
8e899fa9fd
10
Jamfile
10
Jamfile
|
@ -106,12 +106,12 @@ rule building ( properties * )
|
|||
{
|
||||
local result ;
|
||||
|
||||
if <toolset>gcc in $(properties)
|
||||
&& <target-os>linux in $(properties)
|
||||
&& <variant>debug in $(properties)
|
||||
if <variant>debug in $(properties)
|
||||
&& ( <target-os>linux 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 ;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <cassert>
|
||||
|
||||
#ifndef NDEBUG
|
||||
#if defined __linux__ && defined __GNUC__
|
||||
#if (defined __linux__ || defined __MACH__) && defined __GNUC__
|
||||
#ifdef assert
|
||||
#undef assert
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#if defined __linux__ && defined __GNUC__
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
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"
|
||||
"stack:\n", file, line, function, expr);
|
||||
|
||||
#if defined __linux__ && defined __GNUC__
|
||||
void* stack[50];
|
||||
int size = backtrace(stack, 50);
|
||||
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);
|
||||
exit(1);
|
||||
#endif
|
||||
// send SIGINT to the current process
|
||||
// to break into the debugger
|
||||
raise(SIGINT);
|
||||
abort();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue