2023-09-25 09:12:11 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-28 20:46:50 -07:00
|
|
|
# pragma once
|
2024-12-10 17:45:00 -08:00
|
|
|
# include "dependencies/platform.hpp"
|
|
|
|
# include "dependencies/macros.hpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
# include "basic_types.hpp"
|
2024-12-10 17:45:00 -08:00
|
|
|
# include "macros.hpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
#pragma region Debug
|
2023-07-25 20:00:57 -07:00
|
|
|
|
2024-12-12 08:35:50 -08:00
|
|
|
#if GEN_BUILD_DEBUG
|
|
|
|
# if defined( GEN_COMPILER_MSVC )
|
|
|
|
# if _MSC_VER < 1300
|
2024-12-15 19:53:32 -08:00
|
|
|
// #pragma message("GEN_BUILD_DEBUG: __asm int 3")
|
2024-12-12 08:35:50 -08:00
|
|
|
# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */
|
|
|
|
# else
|
2024-12-15 19:53:32 -08:00
|
|
|
// #pragma message("GEN_BUILD_DEBUG: __debugbreak()")
|
2024-12-12 08:35:50 -08:00
|
|
|
# define GEN_DEBUG_TRAP() __debugbreak()
|
|
|
|
# endif
|
|
|
|
# elif defined( GEN_COMPILER_TINYC )
|
|
|
|
# define GEN_DEBUG_TRAP() process_exit( 1 )
|
2023-07-24 15:19:37 -07:00
|
|
|
# else
|
2024-12-12 08:35:50 -08:00
|
|
|
# define GEN_DEBUG_TRAP() __builtin_trap()
|
2023-07-24 15:19:37 -07:00
|
|
|
# endif
|
|
|
|
#else
|
2024-12-15 19:53:32 -08:00
|
|
|
// #pragma message("GEN_BUILD_DEBUG: omitted")
|
2024-12-12 08:35:50 -08:00
|
|
|
# define GEN_DEBUG_TRAP()
|
2023-07-24 15:19:37 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GEN_ASSERT( cond ) GEN_ASSERT_MSG( cond, NULL )
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
#define GEN_ASSERT_MSG( cond, msg, ... ) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if ( ! ( cond ) ) \
|
|
|
|
{ \
|
|
|
|
assert_handler( #cond, __FILE__, __func__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
|
|
|
GEN_DEBUG_TRAP(); \
|
|
|
|
} \
|
2023-07-24 15:19:37 -07:00
|
|
|
} while ( 0 )
|
|
|
|
|
|
|
|
#define GEN_ASSERT_NOT_NULL( ptr ) GEN_ASSERT_MSG( ( ptr ) != NULL, #ptr " must not be NULL" )
|
|
|
|
|
|
|
|
// NOTE: Things that shouldn't happen with a message!
|
|
|
|
#define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ )
|
|
|
|
|
2024-12-15 14:52:31 -08:00
|
|
|
#if GEN_BUILD_DEBUG
|
2023-08-19 05:21:28 -07:00
|
|
|
#define GEN_FATAL( ... ) \
|
2023-08-08 06:48:50 -07:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
local_persist thread_local \
|
|
|
|
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
|
2023-11-22 11:23:21 -08:00
|
|
|
\
|
2024-12-13 11:38:27 -08:00
|
|
|
c_str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
|
2023-08-08 06:48:50 -07:00
|
|
|
GEN_PANIC(buf); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
|
|
|
|
2023-08-19 05:21:28 -07:00
|
|
|
# define GEN_FATAL( ... ) \
|
2023-08-09 06:50:12 -07:00
|
|
|
do \
|
2023-11-22 11:23:21 -08:00
|
|
|
{ \
|
2024-12-13 11:38:27 -08:00
|
|
|
c_str_fmt_out_err( __VA_ARGS__ ); \
|
|
|
|
GEN_DEBUG_TRAP(); \
|
2023-08-09 06:50:12 -07:00
|
|
|
process_exit(1); \
|
2023-11-22 11:23:21 -08:00
|
|
|
} \
|
2023-08-08 06:48:50 -07:00
|
|
|
while (0)
|
|
|
|
#endif
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... );
|
2024-10-27 15:58:37 -07:00
|
|
|
s32 assert_crash( char const* condition );
|
|
|
|
void process_exit( u32 code );
|
|
|
|
|
2023-07-25 20:00:57 -07:00
|
|
|
#pragma endregion Debug
|