Use inline assembly with gcc under Linux for CATCH_TRAP

This is more convenient than using the generic portable raise(SIGTRAP) as it
avoids having another stack frame in the debugger when the break happens.
This commit is contained in:
Vadim Zeitlin 2016-02-05 15:09:16 +01:00 committed by Martin Hořeňovský
parent 25d017763b
commit e1c4a4bd9b

View File

@ -34,9 +34,16 @@ namespace Catch{
#endif #endif
#elif defined(CATCH_PLATFORM_LINUX) #elif defined(CATCH_PLATFORM_LINUX)
// If we can use inline assembler, do it because this allows us to break
// directly at the location of the failing check instead of breaking inside
// raise() called from it, i.e. one stack frame below.
#if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
#define CATCH_TRAP() asm volatile ("int $3")
#else // Fall back to the generic way.
#include <signal.h> #include <signal.h>
#define CATCH_TRAP() raise(SIGTRAP) #define CATCH_TRAP() raise(SIGTRAP)
#endif
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define CATCH_TRAP() __debugbreak() #define CATCH_TRAP() __debugbreak()
#elif defined(__MINGW32__) #elif defined(__MINGW32__)