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 #if defined(__i386__) || defined(__x86_64__) 21 #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ 22 #elif defined(__aarch64__) 23 #define CATCH_TRAP() __asm__(".inst 0xd4200000") 24 #endif 25 26 #elif defined(CATCH_PLATFORM_IPHONE) 27 28 // use inline assembler 29 #if defined(__i386__) || defined(__x86_64__) 30 #define CATCH_TRAP() __asm__("int $3") 31 #elif defined(__aarch64__) 32 #define CATCH_TRAP() __asm__(".inst 0xd4200000") 33 #elif defined(__arm__) && !defined(__thumb__) 34 #define CATCH_TRAP() __asm__(".inst 0xe7f001f0") 35 #elif defined(__arm__) && defined(__thumb__) 36 #define CATCH_TRAP() __asm__(".inst 0xde01") 37 #endif 38 39 #elif defined(CATCH_PLATFORM_LINUX) 40 // If we can use inline assembler, do it because this allows us to break 41 // directly at the location of the failing check instead of breaking inside 42 // raise() called from it, i.e. one stack frame below. 43 #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) 44 #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ 45 #else // Fall back to the generic way. 46 #include <signal.h> 47 48 #define CATCH_TRAP() raise(SIGTRAP) 49 #endif 50 #elif defined(_MSC_VER) 51 #define CATCH_TRAP() __debugbreak() 52 #elif defined(__MINGW32__) 53 extern "C" __declspec(dllimport) void __stdcall DebugBreak(); 54 #define CATCH_TRAP() DebugBreak() 55 #endif 56 57 #ifndef CATCH_BREAK_INTO_DEBUGGER 58 #ifdef CATCH_TRAP 59 #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() 60 #else 61 #define CATCH_BREAK_INTO_DEBUGGER() []{}() 62 #endif 63 #endif 64 65 #endif // TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED 66