Display a line of information under the terminal, it will automatically wrap, debugging, release mode will be displayed
tb_trace_i("hello world");
Display: [tbox]: hello world
!> Each line of output has a tag prefix to indicate which module information, the default is [tbox]
, but can also be redefined by modifying the tb_TRACE_PREFIX
macro.
Output debug information, only in debug mode.
tb_trace_d("hello world");
Display: [tbox]: hello world
!> The output will only be output when the debug mode is enabled: make config DEBUG=y, or if the module internally defines TB_TRACE_MODULE_DEBUG == 1
, otherwise it will be ignored directly when compiling.
Output warning message, debugging and release mode will be displayed
tb_trace_w("hello world");
Display: [tbox]: [warning]: hello world
Prompt that some features have not been implemented yet.
tb_trace_noimpl();
Display: [tbox]: [no_impl]: at func: ..., line: ..., file: ...
Output submodule tag
#define TB_TRACE_MODULE_NAME "module"
#include "tbox.h"
tb_trace_i("hello world");
Display: [tbox]: [module]: hello world
tb_trace_mode_set(TB_TRACE_MODE_FILE);
tb_trace_file_set_path("/tmp/log", tb_false);
It can be output to /tmp/log.
In ios and android, in addition to output to the debug terminal, it will be directly output to syslog, which can be directly viewed through adb logcat or xcode.
Assertion is a fast and effective mechanism to detect and respond to errors during the debugging period. If you add some asserts at the input and output of each interface, you can find hidden bugs in the program early and improve development and debugging efficiency.
Detection at compile time, generally used for type size, constant detection, for example:
tb_assert_static(sizeof(tb_byte_t) == 1);
tb_assert_static(sizeof(tb_uint_t) == 4);
tb_assert_static(sizeof(tb_uint8_t) == 1);
tb_assert_static(sizeof(tb_uint16_t) == 2);
tb_assert_static(sizeof(tb_uint32_t) == 4);
tb_assert_static(sizeof(tb_hize_t) == 8);
Detect in debug mode, valid only in debug mode, if tb_debug is not defined, the code will be ignored
If the assertion fails, abort is fired and the full detailed current position stack is printed
tb_assert(x);
Detect in release mode, regardless of whether it is in debug mode
tb_check_return(x);
tb_check_return_val(x, v);
tb_check_goto(x, b);
tb_check_break(x);
tb_check_abort(x);
tb_check_continue(x);
Simultaneous detection in debug and release mode
tb_assert_and_check_abort(x);
tb_assert_and_check_return(x);
tb_assert_and_check_return_val(x, v);
tb_assert_and_check_goto(x, b);
tb_assert_and_check_break(x);
tb_assert_and_check_continue(x);