diff options
| author | Vadim Zeitlin | 2016-02-05 15:09:16 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-01-15 19:29:34 +0100 |
| commit | e1c4a4bd9b4507c86643ac825deb61da047f53e1 (patch) | |
| tree | cb5c2519397c15a2eb39878136e2b2ef3942b486 /include | |
| parent | 25d017763b73e09d3e9adf7f4db9ce71992f0471 (diff) | |
| download | catch3-e1c4a4bd9b4507c86643ac825deb61da047f53e1.tar.gz | |
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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/internal/catch_debugger.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/include/internal/catch_debugger.h b/include/internal/catch_debugger.h index 4c83efd2..060cbc90 100644 --- a/include/internal/catch_debugger.h +++ b/include/internal/catch_debugger.h @@ -34,9 +34,16 @@ namespace Catch{ #endif #elif defined(CATCH_PLATFORM_LINUX) - #include <signal.h> - - #define CATCH_TRAP() raise(SIGTRAP) + // 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> + + #define CATCH_TRAP() raise(SIGTRAP) + #endif #elif defined(_MSC_VER) #define CATCH_TRAP() __debugbreak() #elif defined(__MINGW32__) |