diff --git a/Include/Pipe/Core/Checks.h b/Include/Pipe/Core/Checks.h index a9efc34e..619201e3 100644 --- a/Include/Pipe/Core/Checks.h +++ b/Include/Pipe/Core/Checks.h @@ -31,7 +31,7 @@ namespace p::details return false; \ }()) && ([capture]() { \ p::details::FailedCheckError(#expression, __FILE__, __LINE__, text); \ - P_DEBUG_PLATFORM_BREAK(); \ + p::PlatformDebugBreak(); \ return false; \ }())) @@ -47,7 +47,7 @@ namespace p::details if (!(expression)) [[unlikely]] \ { \ p::details::FailedCheckError(#expression, __FILE__, __LINE__, text); \ - P_DEBUG_PLATFORM_BREAK(); \ + p::PlatformDebugBreak(); \ } #endif diff --git a/Include/Pipe/Core/LinuxPlatform.h b/Include/Pipe/Core/LinuxPlatform.h index 1986f59c..30ddc85d 100644 --- a/Include/Pipe/Core/LinuxPlatform.h +++ b/Include/Pipe/Core/LinuxPlatform.h @@ -32,8 +32,6 @@ namespace p #endif // P_DEBUG #define P_NOINLINE __attribute__((noinline)) -#define P_PLATFORM_BREAK() __asm__ volatile("int $0x03") - #if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)) #define DISABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize off") #define ENABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize on") diff --git a/Include/Pipe/Core/MacPlatform.h b/Include/Pipe/Core/MacPlatform.h index c85e054e..70e83447 100644 --- a/Include/Pipe/Core/MacPlatform.h +++ b/Include/Pipe/Core/MacPlatform.h @@ -37,13 +37,6 @@ namespace p #endif #define P_NOINLINE __attribute__((noinline)) -#if defined(__aarch64__) - #define P_PLATFORM_BREAK() __builtin_debugtrap() -#else - #define P_PLATFORM_BREAK() __asm__("int $3") -#endif - - #if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)) #define DISABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize off") #define ENABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize on") diff --git a/Include/Pipe/Core/Platform.h b/Include/Pipe/Core/Platform.h index e95a72d6..1bab5249 100644 --- a/Include/Pipe/Core/Platform.h +++ b/Include/Pipe/Core/Platform.h @@ -2,6 +2,7 @@ #pragma once + #ifndef P_PLATFORM_WINDOWS #if defined(_WIN64) || defined(_WIN32) #define P_PLATFORM_WINDOWS 1 @@ -58,6 +59,19 @@ #endif +// Platform break includes +#if defined(__i386__) || defined(__x86_64__) +#elif defined(__thumb__) +#elif defined(__arm__) && !defined(__thumb__) +#elif defined(__aarch64__) && defined(__APPLE__) +#elif defined(__aarch64__) +#elif defined(__powerpc__) +#elif defined(__riscv) +#else + #include +#endif + + namespace p { ///////////////////////////////////////////////////////////// @@ -120,6 +134,47 @@ namespace p constexpr i32 NO_INDEX = -1; } // namespace p +#pragma region Platform Break +namespace p +{ + __attribute__((always_inline)) __inline__ static void PlatformBreak() + { +#if defined(__i386__) || defined(__x86_64__) + __asm__ volatile("int $0x03"); +#elif defined(__thumb__) + // See 'arm-linux-tdep.c' in GDB source, 'eabi_linux_thumb_le_breakpoint' + __asm__ volatile(".inst 0xde01"); +#elif defined(__arm__) && !defined(__thumb__) + // See 'arm-linux-tdep.c' in GDB source, 'eabi_linux_arm_le_breakpoint' + __asm__ volatile(".inst 0xe7f001f0"); +#elif defined(__aarch64__) && defined(__APPLE__) + __builtin_debugtrap(); +#elif defined(__aarch64__) + // See 'aarch64-tdep.c' in GDB source, 'aarch64_default_breakpoint' + __asm__ volatile(".inst 0xd4200000"); +#elif defined(__powerpc__) + // See 'rs6000-tdep.c' in GDB source, 'rs6000_breakpoint' + __asm__ volatile(".4byte 0x7d821008"); +#elif defined(__riscv) + // See 'riscv-tdep.c' in GDB source, 'riscv_sw_breakpoint_from_kind' + __asm__ volatile(".4byte 0x00100073"); +#else + raise(SIGTRAP); +#endif + } + +#if P_DEBUG + __attribute__((always_inline)) __inline__ static void PlatformDebugBreak() + { + PlatformBreak(); + } +#else + __attribute__((always_inline)) __inline__ static void PlatformDebugBreak() {} +#endif +} // namespace p + +#pragma endregion Platform Break + #if !defined(TX) #if PLATFORM_TCHAR_IS_WCHAR @@ -144,12 +199,6 @@ namespace p #endif #endif -#if P_RELEASE - #define P_DEBUG_PLATFORM_BREAK() -#else - #define P_DEBUG_PLATFORM_BREAK() P_PLATFORM_BREAK() -#endif - #define DISABLE_OPTIMIZATION DISABLE_OPTIMIZATION_ACTUAL #if P_DEBUG #define ENABLE_OPTIMIZATION DISABLE_OPTIMIZATION_ACTUAL diff --git a/Include/Pipe/Core/WindowsPlatform.h b/Include/Pipe/Core/WindowsPlatform.h index 3c985b79..56db3458 100644 --- a/Include/Pipe/Core/WindowsPlatform.h +++ b/Include/Pipe/Core/WindowsPlatform.h @@ -25,8 +25,6 @@ namespace p #define P_FORCEINLINE __forceinline /* Force code to be inline */ #define P_NOINLINE __declspec(noinline) /* Force code to not be inlined */ -#define P_PLATFORM_BREAK() (__nop(), __debugbreak()) - #if !defined(__clang__) #define DISABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", off)) #define ENABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", on))