Motr  M0
Assertions, pre-conditions, post-conditions, invariants.

Data Structures

struct  m0_panic_ctx
 

Macros

#define M0_ASSERT_OFF   (0)
 
#define M0_ASSERT_EX_ON   (0)
 
#define likely(x)   __builtin_expect(!!(x), 1)
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 
#define _0C(exp)
 

Enumerations

enum  { BACKTRACE_DEPTH_MAX = 256 }
 

Functions

void m0_panic (const struct m0_panic_ctx *ctx,...)
 
M0_INTERNAL void m0_panic_only (const struct m0_panic_ctx *ctx,...)
 
void m0_backtrace (void)
 
M0_INTERNAL void m0__assertion_hook (void)
 
M0_INTERNAL void m0_arch_panic (const struct m0_panic_ctx *ctx, va_list ap) __attribute__((noreturn))
 
M0_INTERNAL void m0_arch_backtrace (void)
 
 __attribute__ ((format(printf, 1, 2))) static inline void printf_check(const char *fmt
 
M0_INTERNAL void m0_debugger_invoke (void)
 

Variables

static int m0_panic_delay_msec = 110
 
M0_EXTERN char * m0_debugger_args [4]
 

Detailed Description

User space m0_arch_panic() implementation.

Macro Definition Documentation

◆ _0C

#define _0C (   exp)
Value:
({ \
bool __exp = (exp); \
if (!M0_ASSERT_OFF) { \
if (__exp) { \
m0_failed_condition = NULL; \
} else { \
m0_failed_condition = #exp; \
m0__assertion_hook(); \
} \
} \
__exp; \
})
#define NULL
Definition: misc.h:38
M0_INTERNAL const char * m0_failed_condition
Definition: misc.c:224
#define M0_ASSERT_OFF
Definition: assert.h:56

A macro to remember failed invariant conjunct.

This macro is used like the following:

bool foo_invariant(const struct foo *f)
{
return _0C(f != NULL) && _0C(f->f_ref > 0) &&
m0_tl_forall(bar, s, &foo->f_list, _0C(b->b_parent == f) &&
_0C(b->b_nr < f->f_nr));
}

If during invocation of foo_invariant() one of invariant conjuncts evaluates to false, the string representing this conjunct is stored in m0_failed_condition and printed by m0_panic(). This simplifies debugging.

Note
This macro expressly and deliberately violates "M0_" prefix requirement to reduce verbosity.
This compiles to "exp" if M0_ASSERT_OFF is true.

Definition at line 311 of file assert.h.

◆ likely

#define likely (   x)    __builtin_expect(!!(x), 1)

Definition at line 70 of file assert.h.

◆ M0_ASSERT_EX_ON

#define M0_ASSERT_EX_ON   (0)

Definition at line 62 of file assert.h.

◆ M0_ASSERT_OFF

#define M0_ASSERT_OFF   (0)

Definition at line 56 of file assert.h.

◆ unlikely

#define unlikely (   x)    __builtin_expect(!!(x), 0)

Definition at line 74 of file assert.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BACKTRACE_DEPTH_MAX 

Definition at line 48 of file uassert.c.

Function Documentation

◆ __attribute__()

__attribute__ ( (format(printf, 1, 2))  ) const

Check printf format string against parameters.

This function does nothing except checking that the format string matches the rest of arguments and producing a compilation warning in case it doesn't. It is handy in macros which accept printf-like parameters with a format string.

For example usage, refer to M0_TRACE_POINT() macro

◆ m0__assertion_hook()

M0_INTERNAL void m0__assertion_hook ( void  )

Called by _0C() when invariant conjunct fails.

Useful thing to put a breakpoint at.

Definition at line 78 of file assert.c.

◆ m0_arch_backtrace()

void m0_arch_backtrace ( void  )

Definition at line 40 of file kassert.c.

Here is the caller graph for this function:

◆ m0_arch_panic()

M0_INTERNAL void m0_arch_panic ( const struct m0_panic_ctx c,
va_list  ap 
)

Simple user space panic function: issue diagnostics to the stderr, flush the stream, optionally print the backtrace and abort(3) the program.

Stack back-trace printing uses GNU extensions to the libc, declared in <execinfo.h> header (checked for by ./configure). Object files should be compiled with -rdynamic for this to work in the presence of dynamic linking.

Definition at line 45 of file kassert.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_backtrace()

void m0_backtrace ( void  )

Definition at line 72 of file assert.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_debugger_invoke()

M0_INTERNAL void m0_debugger_invoke ( void  )

Invokes a debugger, if possible.

This can be used for debugging purposes. Note that this function can return.

In user space, this function invokes the debugger specified in M0_DEBUGGER environment variable.

In Linux kernel this breaks in kgdb, if configured.

Definition at line 67 of file kassert.c.

◆ m0_panic()

void m0_panic ( const struct m0_panic_ctx ctx,
  ... 
)

Panic function.

Display panic message and abort program execution.

Parameters
ctxpanic context
...arguments for printf format string m0_panic_ctx::pc_fmt

Definition at line 40 of file assert.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_panic_only()

M0_INTERNAL void m0_panic_only ( const struct m0_panic_ctx ctx,
  ... 
)

Abort program execution.

This function is similar to m0_panic(), but doesn't call M0_LOG() nor checks for a double panic. Therefore, it can be called on early stages of initialisation.

Definition at line 63 of file assert.c.

Here is the call graph for this function:

Variable Documentation

◆ m0_debugger_args

M0_EXTERN char* m0_debugger_args[4]

Definition at line 50 of file uassert.c.

◆ m0_panic_delay_msec

int m0_panic_delay_msec = 110
static

Definition at line 38 of file kassert.c.