Files
metadesk/code/base/debug.h
T
2025-02-09 00:37:35 -05:00

64 lines
2.0 KiB
C

#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "context_cracking.h"
# include "linkage.h"
# include "macros.h"
# include "base_types.h"
#endif
// TODO(Ed): Review this
////////////////////////////////
//~ rjf: Asserts
#ifndef trap
# if COMPILER_MSVC
# if _MSC_VER < 1300
# define trap() __asm int 3 /* Trap to debugger! */
# else
# define trap() __debugbreak()
# endif
# elif COMPILER_CLANG || COMPILER_GCC
# define trap() __builtin_trap()
# else
# error Unknown trap intrinsic for this compiler.
# endif
#endif
#define assert_msg( cond, msg, ... ) \
do \
{ \
if ( ! ( cond ) ) \
{ \
assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \
trap(); \
} \
} while ( 0 )
#ifndef assert_always
#define assert_always(x) do { if ( !(x) ) { trap(); } } while(0)
#endif
#ifndef assert
# if BUILD_DEBUG
# define assert(x) assert_always(x)
# else
# define assert(x) (void)(x)
# endif
#endif
#ifndef invalid_path
#define invalid_path assert( ! "Invalid Path!")
#endif
#ifndef not_implemented
#define not_implemented assert( ! "Not Implemented!")
#endif
#ifndef no_op
#define no_op ((void)0)
#endif
#ifndef md_static_assert
#define md_static_assert(C, ID) global U8 glue(ID, __LINE__)[ (C) ? 1 : -1 ]
#endif
MD_API void assert_handler( char const* condition, char const* file, char const* function, S32 line, char const* msg, ... );