Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:05

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_DEBUGGER_HPP_INCLUDED
0009 #define CATCH_DEBUGGER_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_platform.hpp>
0012 
0013 namespace Catch {
0014     bool isDebuggerActive();
0015 }
0016 
0017 #ifdef CATCH_PLATFORM_MAC
0018 
0019     #if defined(__i386__) || defined(__x86_64__)
0020         #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
0021     #elif defined(__aarch64__)
0022         #define CATCH_TRAP() __asm__(".inst 0xd43e0000")
0023     #elif defined(__POWERPC__)
0024         #define CATCH_TRAP() __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
0025         : : : "memory","r0","r3","r4" ) /* NOLINT */
0026     #endif
0027 
0028 #elif defined(CATCH_PLATFORM_IPHONE)
0029 
0030     // use inline assembler
0031     #if defined(__i386__) || defined(__x86_64__)
0032         #define CATCH_TRAP()  __asm__("int $3")
0033     #elif defined(__aarch64__)
0034         #define CATCH_TRAP()  __asm__(".inst 0xd4200000")
0035     #elif defined(__arm__) && !defined(__thumb__)
0036         #define CATCH_TRAP()  __asm__(".inst 0xe7f001f0")
0037     #elif defined(__arm__) &&  defined(__thumb__)
0038         #define CATCH_TRAP()  __asm__(".inst 0xde01")
0039     #endif
0040 
0041 #elif defined(CATCH_PLATFORM_LINUX)
0042     // If we can use inline assembler, do it because this allows us to break
0043     // directly at the location of the failing check instead of breaking inside
0044     // raise() called from it, i.e. one stack frame below.
0045     #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
0046         #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
0047     #else // Fall back to the generic way.
0048         #include <signal.h>
0049 
0050         #define CATCH_TRAP() raise(SIGTRAP)
0051     #endif
0052 #elif defined(_MSC_VER)
0053     #define CATCH_TRAP() __debugbreak()
0054 #elif defined(__MINGW32__)
0055     extern "C" __declspec(dllimport) void __stdcall DebugBreak();
0056     #define CATCH_TRAP() DebugBreak()
0057 #endif
0058 
0059 #ifndef CATCH_BREAK_INTO_DEBUGGER
0060     #ifdef CATCH_TRAP
0061         #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
0062     #else
0063         #define CATCH_BREAK_INTO_DEBUGGER() []{}()
0064     #endif
0065 #endif
0066 
0067 #endif // CATCH_DEBUGGER_HPP_INCLUDED