Skip to content

Commit

Permalink
Refactored Platform Breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
muit committed Oct 17, 2024
1 parent 5af3fac commit 580a99c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Include/Pipe/Core/Checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}()))

Expand All @@ -47,7 +47,7 @@ namespace p::details
if (!(expression)) [[unlikely]] \
{ \
p::details::FailedCheckError(#expression, __FILE__, __LINE__, text); \
P_DEBUG_PLATFORM_BREAK(); \
p::PlatformDebugBreak(); \
}
#endif

Expand Down
2 changes: 0 additions & 2 deletions Include/Pipe/Core/LinuxPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 0 additions & 7 deletions Include/Pipe/Core/MacPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
61 changes: 55 additions & 6 deletions Include/Pipe/Core/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once


#ifndef P_PLATFORM_WINDOWS
#if defined(_WIN64) || defined(_WIN32)
#define P_PLATFORM_WINDOWS 1
Expand Down Expand Up @@ -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 <signal.h>
#endif


namespace p
{
/////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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()

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'always_inline': undeclared identifier

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before identifier '__inline__'

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'always_inline': undeclared identifier

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before identifier '__inline__'

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'always_inline': undeclared identifier

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before identifier '__inline__'

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'always_inline': undeclared identifier

Check failure on line 140 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before identifier '__inline__'
{

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before '{'

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'{': missing function header (old-style formal list?)

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before '{'

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'{': missing function header (old-style formal list?)

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before '{'

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'{': missing function header (old-style formal list?)

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before '{'

Check failure on line 141 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'{': missing function header (old-style formal list?)
#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();

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Debug)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?

Check failure on line 151 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / macos-15 (gcc-14, Release)

'__builtin_debugtrap' was not declared in this scope; did you mean '__builtin_trap'?
#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()

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'p::__attribute__': redefinition; multiple initialization

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'always_inline': undeclared identifier

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before identifier '__inline__'

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'p::__attribute__': redefinition; multiple initialization

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

'always_inline': undeclared identifier

Check failure on line 167 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before identifier '__inline__'
{

Check failure on line 168 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before '{'

Check failure on line 168 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Debug)

syntax error: missing ';' before '{'
PlatformBreak();
}
#else
__attribute__((always_inline)) __inline__ static void PlatformDebugBreak() {}

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'p::__attribute__': redefinition; multiple initialization

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'always_inline': undeclared identifier

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before identifier '__inline__'

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before '{'

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'p::__attribute__': redefinition; multiple initialization

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

'always_inline': undeclared identifier

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before identifier '__inline__'

Check failure on line 172 in Include/Pipe/Core/Platform.h

View workflow job for this annotation

GitHub Actions / windows-2022 (msvc, Release)

syntax error: missing ';' before '{'
#endif
} // namespace p

#pragma endregion Platform Break


#if !defined(TX)
#if PLATFORM_TCHAR_IS_WCHAR
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions Include/Pipe/Core/WindowsPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 580a99c

Please sign in to comment.