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_LINUX)
23     // If we can use inline assembler, do it because this allows us to break
24     // directly at the location of the failing check instead of breaking inside
25     // raise() called from it, i.e. one stack frame below.
26     #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
27         #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
28     #else // Fall back to the generic way.
29         #include <signal.h>
30 
31         #define CATCH_TRAP() raise(SIGTRAP)
32     #endif
33 #elif defined(_MSC_VER)
34     #define CATCH_TRAP() __debugbreak()
35 #elif defined(__MINGW32__)
36     extern "C" __declspec(dllimport) void __stdcall DebugBreak();
37     #define CATCH_TRAP() DebugBreak()
38 #endif
39 
40 #ifdef CATCH_TRAP
41     #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
42 #else
43     namespace Catch {
doNothing()44         inline void doNothing() {}
45     }
46     #define CATCH_BREAK_INTO_DEBUGGER() Catch::doNothing()
47 #endif
48 
49 #endif // TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
50