From 33c118f999800471244e76caae3164a77a74ca6e Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 7 Dec 2014 23:43:51 +0000 Subject: [PATCH] Enable Int3 as d_debugbreak Change Int3 from a no-op to a platform-specific trap to debugger. Requested by btb: https://github.com/dxx-rebirth/dxx-rebirth/pull/18 --- common/include/dxxerror.h | 46 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/common/include/dxxerror.h b/common/include/dxxerror.h index d84bfefd7..89051328f 100644 --- a/common/include/dxxerror.h +++ b/common/include/dxxerror.h @@ -23,8 +23,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. * */ -#ifndef _ERROR_H -#define _ERROR_H +#pragma once #include #include "dxxsconf.h" @@ -51,21 +50,42 @@ void Error_puts(const char *func, unsigned line, const char *str) __noreturn __a void Error(const char *func, unsigned line, const char *fmt,...) __noreturn __attribute_format_printf(3, 4); //exit with error code=1, print message #define Error(F,...) dxx_call_printf_checked(Error,(Error_puts),(__func__, __LINE__),(F),##__VA_ARGS__) #define Assert assert + +/* Compatibility with x86-specific name */ +#define Int3() d_debugbreak() + +#ifndef d_debugbreak #ifndef NDEBUG //macros for debugging +# if defined __unix__ +/* for raise */ +# include +# endif +#endif -# if defined(__APPLE__) || defined(macintosh) -extern void Debugger(void); // Avoids some name clashes -# define Int3 Debugger -# else -# define Int3() ((void)0) -# endif // Macintosh +/* Allow macro override */ +static inline void d_debugbreak() +{ + /* If NDEBUG, expand to nothing */ +#ifndef NDEBUG -#else //macros for real game - -//Changed Assert and Int3 because I couldn't get the macros to compile -KRB -#define Int3() ((void)0) +#if defined __clang__ + /* Must be first, since clang also defines __GNUC__ */ + __builtin_debugtrap(); +#elif defined __GNUC__ +# if defined(__i386__) || defined(__amd64__) + __asm__ __volatile__("int3" ::: "cc", "memory"); +# elif defined __unix__ + raise(SIGTRAP); +# else + /* May terminate execution */ + __builtin_trap(); +# endif +#elif defined _MSC_VER + __debugbreak(); #endif +#endif +} #endif -#endif /* _ERROR_H */ +#endif