1 /* 2 * Created by Phil on 3/12/2013. 3 * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 * 8 */ 9 #ifndef TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED 10 #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED 11 12 #include "catch_platform.h" 13 14 namespace Catch { 15 bool isDebuggerActive(); 16 } 17 18 #ifdef CATCH_PLATFORM_MAC 19 20 #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ 21 22 #elif defined(CATCH_PLATFORM_IPHONE) 23 24 // use inline assembler 25 #if defined(__i386__) || defined(__x86_64__) 26 #define CATCH_TRAP() __asm__("int $3") 27 #elif defined(__aarch64__) 28 #define CATCH_TRAP() __asm__(".inst 0xd4200000") 29 #elif defined(__arm__) && !defined(__thumb__) 30 #define CATCH_TRAP() __asm__(".inst 0xe7f001f0") 31 #elif defined(__arm__) && defined(__thumb__) 32 #define CATCH_TRAP() __asm__(".inst 0xde01") 33 #endif 34 35 #elif defined(CATCH_PLATFORM_LINUX) 36 // If we can use inline assembler, do it because this allows us to break 37 // directly at the location of the failing check instead of breaking inside 38 // raise() called from it, i.e. one stack frame below. 39 #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) 40 #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ 41 #else // Fall back to the generic way. 42 #include <signal.h> 43 44 #define CATCH_TRAP() raise(SIGTRAP) 45 #endif 46 #elif defined(_MSC_VER) 47 #define CATCH_TRAP() __debugbreak() 48 #elif defined(__MINGW32__) 49 extern "C" __declspec(dllimport) void __stdcall DebugBreak(); 50 #define CATCH_TRAP() DebugBreak() 51 #endif 52 53 #ifndef CATCH_BREAK_INTO_DEBUGGER 54 #ifdef CATCH_TRAP 55 #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() 56 #else 57 #define CATCH_BREAK_INTO_DEBUGGER() []{}() 58 #endif 59 #endif 60 61 #endif // TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED 62