Switched to DebugBreak() for Windows machines to snap the debugger and allow a continue
parent
1e103c0e5b
commit
09b5d2f5dd
56
trap.h
56
trap.h
|
|
@ -4,24 +4,38 @@
|
||||||
#ifndef CRYPTOPP_TRAP_H
|
#ifndef CRYPTOPP_TRAP_H
|
||||||
#define CRYPTOPP_TRAP_H
|
#define CRYPTOPP_TRAP_H
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#include "config.h"
|
||||||
#ifdef CRYPTOPP_UNIX_AVAILABLE
|
|
||||||
|
// CRYPTOPP_POSIX_ASSERT unconditionally disables the library assert and yields
|
||||||
|
// to Posix assert. CRYPTOPP_POSIX_ASSERT can be set in config.h. if you want
|
||||||
|
// to disable asserts, then define NDEBUG or _NDEBUG when building the library.
|
||||||
|
|
||||||
|
// Needed for NDEBUG and CRYPTOPP_POSIX_ASSERT
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#if defined(CRYPTOPP_DEBUG)
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
# include <sstream>
|
# include <sstream>
|
||||||
|
# if defined(CRYPTOPP_WIN32_AVAILABLE)
|
||||||
|
# pragma push_macro("WIN32_LEAN_AND_MEAN")
|
||||||
|
# pragma push_macro("_WIN32_WINNT")
|
||||||
|
# pragma push_macro("NOMINMAX")
|
||||||
|
# define WIN32_LEAN_AND_MEAN
|
||||||
|
# define _WIN32_WINNT 0x0400
|
||||||
|
# define NOMINMAX
|
||||||
|
# include <Windows.h>
|
||||||
|
# elif defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE)
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
#endif // CRYPTOPP_UNIX_AVAILABLE
|
# endif
|
||||||
#endif // NDEBUG
|
#endif // CRYPTOPP_DEBUG
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
// ************** run-time assertion ***************
|
// ************** run-time assertion ***************
|
||||||
|
|
||||||
// See test.cpp and DebugTrapHandler for code to install a NULL
|
// See test.cpp and DebugTrapHandler for code to install a null signal handler
|
||||||
// signal handler for SIGTRAP. The handler installs itself during
|
// for SIGTRAP on BSD, Linux and Unix. The handler installs itself during
|
||||||
// initialization of the test program.
|
// initialization of the test program.
|
||||||
|
|
||||||
// Linux and Unix
|
#if defined(CRYPTOPP_DEBUG) && (defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE))
|
||||||
#if !defined(NDEBUG) && defined(CRYPTOPP_UNIX_AVAILABLE)
|
|
||||||
# define CRYPTOPP_ASSERT(exp) { \
|
# define CRYPTOPP_ASSERT(exp) { \
|
||||||
if (!(exp)) { \
|
if (!(exp)) { \
|
||||||
std::ostringstream oss; \
|
std::ostringstream oss; \
|
||||||
|
|
@ -32,10 +46,26 @@
|
||||||
raise(SIGTRAP); \
|
raise(SIGTRAP); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
// Fallback to original behavior (including for NDEBUG)
|
#elif defined(CRYPTOPP_DEBUG) && defined(CRYPTOPP_WIN32_AVAILABLE)
|
||||||
|
# define CRYPTOPP_ASSERT(exp) { \
|
||||||
|
if (!(exp)) { \
|
||||||
|
std::ostringstream oss; \
|
||||||
|
oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
|
||||||
|
<< (int)(__LINE__) << "): " << (char*)(__FUNCTION__) \
|
||||||
|
<< std::endl; \
|
||||||
|
DebugBreak(); \
|
||||||
|
std::cerr << oss.str(); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
// Fallback to original behavior for NDEBUG (and non-Windows/non-Unix builds)
|
||||||
#else
|
#else
|
||||||
# define CRYPTOPP_ASSERT(exp) assert(exp)
|
# define CRYPTOPP_ASSERT(exp) assert(exp)
|
||||||
#endif // DEBUG and CRYPTOPP_UNIX_AVAILABLE
|
#endif // DEBUG and Unix or Windows
|
||||||
|
|
||||||
|
#if defined(CRYPTOPP_DEBUG) && defined(CRYPTOPP_WIN32_AVAILABLE)
|
||||||
|
# pragma pop_macro("WIN32_LEAN_AND_MEAN")
|
||||||
|
# pragma pop_macro("_WIN32_WINNT")
|
||||||
|
# pragma pop_macro("NOMINMAX")
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // CRYPTOPP_TRAP_H
|
#endif // CRYPTOPP_TRAP_H
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue