Debug

Helpers for logging, asserting and aborting.

Types

oc_log_level

typedef enum oc_log_level
{
    OC_LOG_LEVEL_ERROR = 0,
    OC_LOG_LEVEL_WARNING = 1,
    OC_LOG_LEVEL_INFO = 2,
    OC_LOG_LEVEL_COUNT = 3
} oc_log_level;

Constants allowing to specify the level of logging verbosity.

Enum Constants

  • OC_LOG_LEVEL_ERROR Only errors are logged.
  • OC_LOG_LEVEL_WARNING Only warnings and errors are logged.
  • OC_LOG_LEVEL_INFO All messages are logged.
  • OC_LOG_LEVEL_COUNT

Macros

oc_log_error

#define oc_log_error(msg, ...)

Log an error to the console.

Parameters

  • msg The format string of the message, similar to printf().
  • ... Additional arguments of the message.

oc_log_warning

#define oc_log_warning(msg, ...)

Log a warning to the console.

Parameters

  • msg The format string of the message, similar to printf().
  • ... Additional arguments of the message.

oc_log_info

#define oc_log_info(msg, ...)

Log a informative message to the console.

Parameters

  • msg The format string of the message, similar to printf().
  • ... Additional arguments of the message.

OC_ABORT

#define OC_ABORT(...)

Abort the application with an optional error message.

Parameters

  • ... An optional format string for the error message, followed by additional message arguments, similar to printf().

OC_ASSERT

#define OC_ASSERT(test, ...)

Test a given condition, and abort the application if it is false.

Parameters

  • test The condition expression to test.
  • ... An optional format string for the error message, followed by additional message arguments, similar to printf().

OC_DEBUG_ASSERT

#define OC_DEBUG_ASSERT(test, ...)

Similar to OC_ASSERT, but only run in Debug mode.

Parameters

  • test The condition expression to test.
  • ... An optional format string for the error message, followed by additional message arguments, similar to printf().

Functions

oc_abort_ext

void oc_abort_ext(char* file, char* function, i32 line, char* fmt,  ...);

Abort the application, showing an error message.

This function should not be called directly by user code, which should use the OC_ABORT macro instead, as the macro takes care of filling in the source location parameters of the function.

Parameters

  • file The name of the source file the abort originates from.
  • function The name of the function the abort originates from.
  • line The source line the abort originates from.
  • fmt The format string of the abort message similar to printf().
  • ... Additional arguments for the abort message.

Note

This function does not return.


oc_assert_fail

void oc_assert_fail(char* file, char* function, i32 line, char* src, char* fmt,  ...);

Tigger a failed assertion. This aborts the application, showing the failed assertion and an error message.

This function should not be called directly by user code, which should use the OC_ASSERT macro instead. The macro checks the assert condition and calls the function if it is false. It also takes care of filling in the source location parameters of the function.

Parameters

  • file The name of the source file the failed assertion originates from.
  • function The name of the function the failed assertion originates from.
  • line The source line the failed assertion originates from.
  • src The source code of the failed assert condition.
  • fmt The format string of the error message, similar to printf().
  • ... Additional arguments for the error message.

Note

This function does not return.


oc_log_set_level

void oc_log_set_level(oc_log_level level);

Set the logging verbosity.

Parameters

  • level The desired logging level. Messages whose level is below this threshold will not be logged.

oc_log_ext

void oc_log_ext(oc_log_level level, char* function, char* file, i32 line, char* fmt,  ...);

Log a message to the console.

This function should not be called directly by user code, which should use the oc_log_XXX family of macros instead. The macros take care of filling in the message level and source location parameters of the function.

Parameters

  • level The logging level of the message.
  • function The name of the function the message originated from
  • file The name of the source file the message originated from
  • line The source line the message originated from
  • fmt The format string of the message, similar to printf().
  • ... Additional arguments of the message