00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ASSERT_HPP
00021 #define ASSERT_HPP
00022
00023 #ifndef NDEBUG
00024
00025 #include <config.h>
00026
00027 #include <ErrorHandler.hpp>
00028 #include <Stringify.hpp>
00029
00030 #include <signal.h>
00031
00032 #include <cstdlib>
00033 #include <iostream>
00034
00035 #include <RunningOptions.hpp>
00036
00037 #define ASSERT(expression) \
00038 if (not (expression)) { \
00039 std::cerr << "##############################################\n"; \
00040 std::cerr << __FILE__ << ':' << __LINE__ << ":\n"; \
00041 std::cerr << "assertion failed: '"+stringify(#expression)+"'\n"; \
00042 std::cerr << "in function '" << __PRETTY_FUNCTION__ << "'\n"; \
00043 if (RunningOptions::instance().pauseOnError()) { \
00044 std::cerr << "----------------------------------------------\n"; \
00045 std::cerr << "to attach gdb to this process do\n"; \
00046 std::cerr << "\tgdb -pid " << getpid() << '\n'; \
00047 std::cerr << "else press control-c\n"; \
00048 std::cerr << "##############################################\n"; \
00049 sigset_t s; \
00050 sigaddset(&s,SIGSTOP); \
00051 sigsuspend(&s); \
00052 } else { \
00053 std::cerr << "##############################################\n"; \
00054 } \
00055 std::exit(1); \
00056 }
00057
00058 #else // NDEBUG
00059
00060 #define ASSERT(expression)
00061
00062 #endif // NDEBUG
00063
00064 #endif // ASSERT_HPP