Debug

#load "std/debug.bl"

Set of common debugging tools.

print_log :: fn (format: string_view, args: ...)  #inline

Print debug log using current application_context print_log_fn function.

File: debug.bl

print_info :: fn (format: string_view, args: ...)  #inline

Print debug info using current application_context print_log_fn function.

File: debug.bl

print_warn :: fn (format: string_view, args: ...)  #inline

Print debug warning using current application_context print_log_fn function.

File: debug.bl

print_err :: fn { 
    print_err_e; 
    print_err_msg; 
}

Print debug error using current application_context.print_log_fn function.

File: debug.bl

assert

assert :: fn (condition: bool, message :: "", loc :: #call_location) 

Invoke assert handler from the application context in case the condition is false.

Important

All calls to the assert function are removed from release builds by default.

Warning

There is no argument validation in case the assert call is removed from compilation.

File: debug.bl

static_assert

static_assert :: fn (expr: bool) 

Assertion check evaluated in compile time.

File: debug.bl

panic

panic :: fn { 
    panic_empty; 
    panic_error; 
    panic_msg; 
}

Abort execution and eventually print panic message if there is one specified. First passed argument in 'args' will act like format string and can be eventually followed by any additional values required.

Example

panic(); // abort without any messages
panic(error); // abort with [Error](#error).
panic("oops!"); // abort with message printed out.
panic("Failed with error: %", errn); // first argument passed acts like formatting string

File: debug.bl

PrintLogKind

PrintLogKind :: enum u8 {
    MESSAGE;
    INFO;
    WARNING;
    ERROR;
    ASSERT;
    PANIC;
}

Kinds of log messages.

Variants

File: debug.bl

print_backtrace :: fn (skip_frames :: 0)  #inline

Print current stack trace into stdout. Does nothing in release modes (stack trace information is available only when the debug info is in place).

File: debug.bl

measure_elapsed_ms_begin

measure_elapsed_ms_begin :: fn ()  #inline

Start measure elapsed milliseconds in the current scope. This function call will push the current time into the thread-local queue. Measurement must be ended by measure_elapsed_ms_end call.

Example

measure_elapsed_ms_begin();
defer measure_elapsed_ms_end("Name");

Warning

Every measure_elapsed_ms_begin must have corresponding measure_elapsed_ms_end call.

File: debug.bl

measure_elapsed_ms_end

measure_elapsed_ms_end :: fn (_name : string_view: "", loc :: #call_location) f64 #inline

Pop the last start time from the runtime measurement queue and log the result time difference when the name is not '-'. The name may be empty, in such case parent function name is used implicitly for debug log.

Returns time difference between the current time and last start time.

File: debug.bl