Fabcoin Core  0.16.2
P2P Digital Currency
trap.h
Go to the documentation of this file.
1 // trap.h - written and placed in public domain by Jeffrey Walton.
2 // Copyright assigned to Crypto++ project
3 
15 
16 #ifndef CRYPTOPP_TRAP_H
17 #define CRYPTOPP_TRAP_H
18 
19 #include "config.h"
20 
21 #if defined(CRYPTOPP_DEBUG)
22 # include <iostream>
23 # include <sstream>
24 # if defined(UNIX_SIGNALS_AVAILABLE)
25 # include "ossig.h"
26 # elif defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(__CYGWIN__)
27 # if (_MSC_VER >= 1400)
28 # include <intrin.h>
29 # endif
30 # endif
31 #endif // CRYPTOPP_DEBUG
32 
33 // ************** run-time assertion ***************
34 
35 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
36 # define CRYPTOPP_ASSERT(exp) { ... }
63 #endif
64 
65 #if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
66 # define CRYPTOPP_ASSERT(exp) { \
67  if (!(exp)) { \
68  std::ostringstream oss; \
69  oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
70  << (int)(__LINE__) << "): " << (char*)(__func__) \
71  << std::endl; \
72  std::cerr << oss.str(); \
73  raise(SIGTRAP); \
74  } \
75  }
76 #elif CRYPTOPP_DEBUG && defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(__CYGWIN__)
77 # define CRYPTOPP_ASSERT(exp) { \
78  if (!(exp)) { \
79  std::ostringstream oss; \
80  oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
81  << (int)(__LINE__) << "): " << (char*)(__FUNCTION__) \
82  << std::endl; \
83  std::cerr << oss.str(); \
84  __debugbreak(); \
85  } \
86  }
87 #endif // DEBUG and Unix or Windows
88 
89 // Remove CRYPTOPP_ASSERT in non-debug builds.
90 // Can't use CRYPTOPP_UNUSED due to circular dependency
91 #ifndef CRYPTOPP_ASSERT
92 # define CRYPTOPP_ASSERT(exp) (void)0
93 #endif
94 
96 
97 // ************** SIGTRAP handler ***************
98 
99 #if (CRYPTOPP_DEBUG && defined(UNIX_SIGNALS_AVAILABLE)) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
100 
136 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
137 class DebugTrapHandler : public SignalHandler<SIGILL, false> { };
138 #else
139 typedef SignalHandler<SIGILL, false> DebugTrapHandler;
140 #endif
141 
142 #endif // Linux, Unix and Documentation
143 
145 
146 #endif // CRYPTOPP_TRAP_H
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Library configuration file.
Utility class for trapping OS signals.
#define NAMESPACE_END
Definition: config.h:201