🔖 prelude
Useful C header files
Loading...
Searching...
No Matches
debug.h File Reference

Assertions and other debug tools. More...

#include "hint.h"
#include <stdlib.h>

Go to the source code of this file.

Macros

#define debug_break()
 Causes a debug breakpoint and signals any attached debugger.
#define debug_msg_always(FMT, ...)
 Prints a debug message to the standard error output.
#define panic(FMT, ...)
 Prints a debug message, then invokes debug_break().
#define debug_msg(FMT, ...)
 Prints a debug message to the standard error output.
#define assert_msg(COND, FMT, ...)
 Performs an assertion, printing a debug message on failure.

Detailed Description

Assertions and other debug tools.

Macro Definition Documentation

◆ assert_msg

#define assert_msg ( COND,
FMT,
... )

Performs an assertion, printing a debug message on failure.

Parameters
CONDA condition to test
FMTA format string, as would be passed to printf()
Note
When NDEBUG is defined, this is treated as an assume instead.

◆ debug_break

#define debug_break ( )

Causes a debug breakpoint and signals any attached debugger.

Note
When NDEBUG is defined, this aborts the program instead.
See also
POSIX raise(SIGTRAP)
MSVC __debugbreak()

◆ debug_msg

#define debug_msg ( FMT,
... )

Prints a debug message to the standard error output.

Automatically included in the message is the file, line, and function this macro was invoked from.

Parameters
FMTA format string, as would be passed to printf()
Note
This macro is elided when NDEBUG is defined.

◆ debug_msg_always

#define debug_msg_always ( FMT,
... )
Value:
fprintf(stderr, __FILE__ ":%d:%s: " FMT "\n", __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__)

Prints a debug message to the standard error output.

Automatically included in the message is the file, line, and function this macro was invoked from.

Parameters
FMTA format string, as would be passed to printf()
Warning
This macro unconditionally prints this message, regardless whether NDEBUG is defined or not. Prefer using debug_msg() instead, which is automatically elided when NDEBUG is defined.

◆ panic

#define panic ( FMT,
... )
Value:
do { debug_msg_always(FMT __VA_OPT__(,) __VA_ARGS__); debug_break(); } while (0)
#define debug_break()
Causes a debug breakpoint and signals any attached debugger.
Definition debug.h:41
#define debug_msg_always(FMT,...)
Prints a debug message to the standard error output.
Definition debug.h:53

Prints a debug message, then invokes debug_break().