Skip to content

Group c_debug

Modules > c_debug

More...

Public Types

Type Name
enum MDBX_debug_flags_t
Runtime debug flags.
typedef void(* MDBX_debug_func
A log callback function that accepts a format string and arguments passed through the va_list pointer.
typedef void(* MDBX_debug_func_nofmt
A log callback function that accepts a formatted message with length.
enum MDBX_log_level_t
typedef void(* MDBX_panic_func
A callback function for most assertion failures, that called before printing the message and aborting.

Public Functions

Type Name
MDBX_NORETURN LIBMDBX_API void mdbx_assert_fail (const char * msg, const char * func, unsigned line)
Auxiliary function for MDBX_INLINE_API_ASSERT() .
LIBMDBX_API const char * mdbx_dump_val (const MDBX_val * key, char *const buf, const size_t bufsize)
Dump given MDBX_val to the buffer.
LIBMDBX_API void mdbx_set_panic (MDBX_panic_func func)
Sets or reset the callback for panic() and assert() for the current process.
LIBMDBX_API int mdbx_setup_debug (MDBX_log_level_t log_level, MDBX_debug_flags_t debug_flags, MDBX_debug_func logger)
Setups global log-level, debug options and logger for format string and va_list .
LIBMDBX_API int mdbx_setup_debug_nofmt (MDBX_log_level_t log_level, MDBX_debug_flags_t debug_flags, MDBX_debug_func_nofmt logger, char * logger_buffer, size_t logger_buffer_size)
Setups global log-level, debug options, buffer and logger for plain preformatted messages.

Macros

Type Name
define MDBX_LOGGER_DONTCHANGE (([**MDBX\_debug\_func**](group__c__debug.md#typedef-mdbx_debug_func))(intptr\_t)-1)
The "don't change logger" value for mdbx_setup_debug() .
define MDBX_LOGGER_NOFMT_DONTCHANGE (([**MDBX\_debug\_func\_nofmt**](group__c__debug.md#typedef-mdbx_debug_func_nofmt))(intptr\_t)-1)
The "don't change logger" value for mdbx_setup_debug_nofmt() .

Detailed Description

Note:

Most of debug feature enabled only when libmdbx built with MDBX_DEBUG build option.

Public Types Documentation

enum MDBX_debug_flags_t

Runtime debug flags.

enum MDBX_debug_flags_t {
    MDBX_DBG_DONTCHANGE = -1,
    MDBX_DBG_NONE = 0,
    MDBX_DBG_ASSERT = 1,
    MDBX_DBG_AUDIT = 2,
    MDBX_DBG_JITTER = 4,
    MDBX_DBG_DUMP = 8,
    MDBX_DBG_LEGACY_MULTIOPEN = 16,
    MDBX_DBG_LEGACY_OVERLAP = 32,
    MDBX_DBG_DONT_UPGRADE = 64,
    MDBX_DBG_MAX = ((unsigned)MDBX_LOG_MAX) << 16 | 127
};

MDBX_DBG_DUMP and MDBX_DBG_LEGACY_MULTIOPEN always have an effect, but MDBX_DBG_ASSERT, MDBX_DBG_AUDIT and MDBX_DBG_JITTER only if libmdbx built with MDBX_DEBUG.

See also: mdbx_setup_debug()

See also: MDBX_debug_flags_t


typedef MDBX_debug_func

A log callback function that accepts a format string and arguments passed through the va_list pointer.

typedef void(* MDBX_debug_func) (MDBX_log_level_t log_level, const char *function, int line, const char *fmt, va_list args) noexcept;

See also: mdbx_setup_debug()

Parameters:

  • log_level The severity of message.
  • function The function name which emits message, may be NULL.
  • line The source code line number which emits message, may be zero.
  • fmt The printf-like format string with message.
  • args The variable argument list respectively for the format-message string passed by fmt argument. Maybe NULL or invalid if the format-message string don't contain %-specification of arguments.

typedef MDBX_debug_func_nofmt

A log callback function that accepts a formatted message with length.

typedef void(* MDBX_debug_func_nofmt) (MDBX_log_level_t log_level, const char *function, int line, const char *msg, unsigned length) noexcept;

See also: mdbx_setup_debug()

Parameters:

  • log_level The severity of message.
  • function The function name which emits message, may be NULL.
  • line The source code line number which emits message, may be zero.
  • msg Pointer to the static buffer with formatted message for log.
  • length Length of formatted message in a chars.

enum MDBX_log_level_t

enum MDBX_log_level_t {
    MDBX_LOG_DONTCHANGE = -1,
    MDBX_LOG_FATAL = 0,
    MDBX_LOG_ERROR = 1,
    MDBX_LOG_WARN = 2,
    MDBX_LOG_NOTICE = 3,
    MDBX_LOG_VERBOSE = 4,
    MDBX_LOG_DEBUG = 5,
    MDBX_LOG_TRACE = 6,
    MDBX_LOG_EXTRA = 7,
    MDBX_LOG_MAX = 7
};

Log level

Note:

Levels detailed than (great than) MDBX_LOG_NOTICE requires build libmdbx with MDBX_DEBUG option.

See also: mdbx_setup_debug()

See also: MDBX_log_level_t


typedef MDBX_panic_func

A callback function for most assertion failures, that called before printing the message and aborting.

typedef void(* MDBX_panic_func) (const char *msg, const char *function, unsigned line, const void *obj, const char *obj_class) noexcept;

See also: mdbx_set_panic()

Parameters:

  • msg The assertion message, not including newline.
  • function The function name where the assertion check failed, may be NULL.
  • line The line number in the source file where the assertion check failed, may be zero.
  • obj A handle of object associated with the assertion, it could be MDBX_env, MDBX_txn, MDBX_cursor or an internal page structure.
  • obj_class A value corresponding to the object type: env, txn, cursor, etc.

Public Functions Documentation

function mdbx_assert_fail

Auxiliary function for MDBX_INLINE_API_ASSERT() .

MDBX_NORETURN  LIBMDBX_API void mdbx_assert_fail (
    const char * msg,
    const char * func,
    unsigned line
) 

function mdbx_dump_val

Dump given MDBX_val to the buffer.

LIBMDBX_API const char * mdbx_dump_val (
    const MDBX_val * key,
    char *const buf,
    const size_t bufsize
) 

Dumps it as string if value is printable (all bytes in the range 0x20..0x7E), otherwise made hexadecimal dump. Requires at least 4 byte length buffer.

Returns:

One of: * NULL if given buffer size less than 4 bytes; * pointer to constant string if given value NULL or empty; * otherwise pointer to given buffer.


function mdbx_set_panic

Sets or reset the callback for panic() and assert() for the current process.

LIBMDBX_API void mdbx_set_panic (
    MDBX_panic_func func
) 

Parameters:

  • func An MDBX_assert_func function, or 0.

function mdbx_setup_debug

Setups global log-level, debug options and logger for format string and va_list .

LIBMDBX_API int mdbx_setup_debug (
    MDBX_log_level_t log_level,
    MDBX_debug_flags_t debug_flags,
    MDBX_debug_func logger
) 

Parameters:

  • log_level New global log-level or MDBX_LOG_DONTCHANGE.
  • debug_flags New global debug flags or MDBX_DBG_DONTCHANGE.
  • logger New global logger callback function with MDBX_debug_func signature or MDBX_LOGGER_DONTCHANGE.

Returns:

A non-negative value on success, in which the previous value debug_flags is in 0-15 bits, and log_level is in 16-31 bits. Otherwise, a negative value will be returned, indicating that some parameters are invalid.

See also: MDBX_log_level_t

See also: MDBX_debug_flags_t


function mdbx_setup_debug_nofmt

Setups global log-level, debug options, buffer and logger for plain preformatted messages.

LIBMDBX_API int mdbx_setup_debug_nofmt (
    MDBX_log_level_t log_level,
    MDBX_debug_flags_t debug_flags,
    MDBX_debug_func_nofmt logger,
    char * logger_buffer,
    size_t logger_buffer_size
) 

Parameters:

  • log_level New global log-level or MDBX_LOG_DONTCHANGE.
  • debug_flags New global debug flags or MDBX_DBG_DONTCHANGE.
  • logger New global logger callback function with mdbx_setup_debug_nofmt signature or MDBX_LOGGER_NOFMT_DONTCHANGE.
  • logger_buffer A pointer to a static shared buffer that libmdbx will use internally to format log messages, either NULL if logger is MDBX_LOGGER_NOFMT_DONTCHANGE or NULL.
  • logger_buffer_size The size of passed static shared buffer, either zero if logger is MDBX_LOGGER_NOFMT_DONTCHANGE or NULL.

Returns:

A non-negative value on success, in which the previous value debug_flags is in 0-15 bits, and log_level is in 16-31 bits. Otherwise, a negative value will be returned, indicating that some parameters are invalid.

See also: MDBX_log_level_t

See also: MDBX_debug_flags_t


Macro Definition Documentation

define MDBX_LOGGER_DONTCHANGE

The "don't change logger" value for mdbx_setup_debug() .

#define MDBX_LOGGER_DONTCHANGE `(( MDBX_debug_func )(intptr_t)-1)`

define MDBX_LOGGER_NOFMT_DONTCHANGE

The "don't change logger" value for mdbx_setup_debug_nofmt() .

#define MDBX_LOGGER_NOFMT_DONTCHANGE `(( MDBX_debug_func_nofmt )(intptr_t)-1)`