CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants > Class Template Reference

Conditional debug class. More...

#include <debug.hh>

Classes

struct  Invariant
 Function-like class for invariants that is expected to be used via the deduction guide as: More...
struct  Assert
 Function-like class for assertions that is expected to be used via the deduction guide as: More...

Public Member Functions

template<typename T, typename... Ts>
 Invariant (T, const char *, Ts &&...) -> Invariant< Ts... >
 Deduction guide, allows Invariant to be used as if it were a function.
template<typename... Ts>
 Assert (bool, const char *, Ts &&...) -> Assert< Ts... >
 Deduction guide, allows Assert to be used as if it were a function.
template<typename... Ts>
 Assert (auto, const char *, Ts &&...) -> Assert< Ts... >
 Deduction guide, allows Assert to be used as if it were a function with a lambda argument.

Static Public Member Functions

template<DebugLevel Level = DebugLevel::Information>
static void log (const char *fmt, auto... args)
 Log a message.
template<DebugLevel Level = DebugLevel::Information>
static void log_if (bool condition, const char *fmt, auto... args)
template<DebugLevel Level = DebugLevel::Information, DebugConcepts::LazyAssertion Condition>
static void log_if (Condition condition, const char *fmt, auto... args)
template<typename... Args>
static void report_failure (const char *kind, const char *file, const char *function, int line, const char *fmt, Args... args)
 Helper to report failure.
template<typename T, typename... Args>
static void invariant (T condition, const char *fmt, std::tuple< Args... > args=std::make_tuple(), SourceLocation loc=SourceLocation::current())
 Overt wrapper function around Invariant.
template<typename T, typename... Args>
static void assertion (T condition, const char *fmt, std::tuple< Args... > args=std::make_tuple(), SourceLocation loc=SourceLocation::current())
 Overt wrapper function around Assert.

Detailed Description

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
class anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >

Conditional debug class.

Used to control conditional output and assertion checking. The first template parameter is a threshold for reporting. Log messages will be printed if they are at or above this threshold.

By default, assertions will be checked if the threshold is Warning or lower. This can be overridden by passing true or false as the third template argument, to explicitly enable or disable assertions.

Invariants are always checked but, by default, will log a message only if the threshold is warning or lower. This can be overridden by passing true or false as the fourth template argument, to explicitly enable or disable verbose messages on invariant failure.

If you wish to reduce verbosity of log messages but still have verbose error messages for invariant failure, you can pass true as the third template argument. This will unconditionally enable assertions and verbose messages from invariants, even if

Uses Context to print additional detail on debug lines. Each line is prefixed with the context string in magenta to make it easy to see debug output from different subsystems in the same trace.

This class is expected to be used as a type alias, something like:

using Debug = ConditionalDebug<DEBUG_FOO, "Foo">;

The xmake build system exposes debugOption and debugLevelOption values to define these macros. If debugOption(foo) is used, the option will be exposed as --debug-foo=[y,n], where setting the option to true defines the threshold as Information and false (the default) as None. If debugLevelOption(foo) is used, the user can specify any level from none to critical on the command line.

Definition at line 787 of file debug.hh.

Member Function Documentation

◆ assertion()

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
template<typename T, typename... Args>
void anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >::assertion ( T condition,
const char * fmt,
std::tuple< Args... > args = std::make_tuple(),
SourceLocation loc = SourceLocation::current() )
inlinestatic

Overt wrapper function around Assert.

Sometimes template deduction guides just don't cut it. At the cost of a std::make_tuple at the call site, we can still take advantage of much of the machinery here.

Definition at line 1038 of file debug.hh.

References anonymous_namespace{debug.hh}::SourceLocation::current().

◆ invariant()

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
template<typename T, typename... Args>
void anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >::invariant ( T condition,
const char * fmt,
std::tuple< Args... > args = std::make_tuple(),
SourceLocation loc = SourceLocation::current() )
inlinestatic

Overt wrapper function around Invariant.

Sometimes template deduction guides just don't cut it. At the cost of a std::make_tuple at the call site, we can still take advantage of much of the machinery here.

Definition at line 1003 of file debug.hh.

References anonymous_namespace{debug.hh}::SourceLocation::current().

◆ log()

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
template<DebugLevel Level = DebugLevel::Information>
void anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >::log ( const char * fmt,
auto... args )
inlinestatic

Log a message.

This function does nothing if the level is less than the threshold.

Definition at line 796 of file debug.hh.

References debug_log_message_write(), make_debug_arguments_list(), and anonymous_namespace{debug.hh}::None.

Referenced by anonymous_namespace{debug.hh}::StackUsageCheck< Mode, Expected, Fn >::~StackUsageCheck().

◆ log_if() [1/2]

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
template<DebugLevel Level = DebugLevel::Information>
void anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >::log_if ( bool condition,
const char * fmt,
auto... args )
inlinestatic

Definition at line 824 of file debug.hh.

◆ log_if() [2/2]

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
template<DebugLevel Level = DebugLevel::Information, DebugConcepts::LazyAssertion Condition>
void anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >::log_if ( Condition condition,
const char * fmt,
auto... args )
inlinestatic

Definition at line 841 of file debug.hh.

◆ report_failure()

template<DebugLevelTemplateArgument Threshold, DebugContext Context, bool EnableAssertions = (Threshold <= DebugLevel::Warning), bool VerboseInvariants = (Threshold <= DebugLevel::Warning)>
template<typename... Args>
void anonymous_namespace{debug.hh}::ConditionalDebug< Threshold, Context, EnableAssertions, VerboseInvariants >::report_failure ( const char * kind,
const char * file,
const char * function,
int line,
const char * fmt,
Args... args )
inlinestatic

The documentation for this class was generated from the following file: