Use inline assembly for MIJIN_TRAP() so the debugger stops at the exact location. Only works for x64, but that's currently my only target.

This commit is contained in:
Patrick 2023-12-07 17:15:42 +01:00
parent 0e877f4769
commit b89f19ed98

View File

@ -14,14 +14,24 @@ extern "C" __declspec(dllimport) void __stdcall DebugBreak();
#define MIJIN_TRAP() DebugBreak()
#define MIJIN_FUNC() __FUNCSIG__
#else // _WIN32
#include <csignal>
#define MIJIN_TRAP() (void) std::raise(SIGTRAP)
#include <unistd.h>
#define MIJIN_TRAP() \
{ \
const pid_t tid = gettid(); \
const pid_t pid = getpid(); \
__asm__ __volatile__ \
( \
"syscall" \
: \
: "D"(pid), "S"(tid), "d"(5), "a"(0xea) \
: "rcx", "r11", "memory" \
); \
}
#define MIJIN_FUNC() "" // TODO: __PRETTY_FUNCTION__ is not working for some reason -.-
#endif // !_WIN32
namespace mijin
{
//
// public defines
//
@ -35,7 +45,7 @@ switch (mijin::handleError(msg, source_loc)) \
break; \
case mijin::ErrorHandling::TRAP: \
MIJIN_TRAP(); \
[[fallthrough]]; \
break; \
default: /* ABORT */ \
std::abort(); \
}
@ -76,7 +86,7 @@ if (!static_cast<bool>(condition))
#define MIJIN_ASSERT_FATAL(condition, msg) \
if (!static_cast<bool>(condition)) \
{ \
MIJIN_ERROR("Debug assertion failed: " #condition "\nMessage: " msg); \
MIJIN_FATAL("Debug assertion failed: " #condition "\nMessage: " msg); \
}
#else // MIJIN_DEBUG
#define MIJIN_ERROR(...)