X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fdebug.h;h=f25cd426913f8a0bb518df0e77b6e1933c6d060c;hb=f94ed830df98218447f00b97f856de811bfcc4a2;hp=3e6772aacfd4d891fcfbf752a2c482143db01298;hpb=4e262455a252c700f81df75fb8107d112062bba8;p=mirror_frr.git diff --git a/lib/debug.h b/lib/debug.h index 3e6772aac..f25cd4269 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -24,6 +24,10 @@ #include "command.h" #include "frratomic.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Debugging modes. * @@ -76,10 +80,11 @@ * Human-readable description of this debugging record. */ struct debug { - _Atomic uint32_t flags; + atomic_uint_fast32_t flags; const char *desc; }; +PREDECL_LIST(debug_cb_list) /* * Callback set for debugging code. * @@ -88,6 +93,11 @@ struct debug { * mode set. */ struct debug_callbacks { + /* + * Linked list of Callbacks to call + */ + struct debug_cb_list_item item; + /* * flags * flags to set on debug flag fields @@ -104,76 +114,77 @@ struct debug_callbacks { * * MT-Safe */ -#define DEBUG_MODE_CHECK(name, type) \ - CHECK_FLAG_ATOMIC(&(name)->flags, (type)&DEBUG_MODE_ALL) +#define DEBUG_MODE_CHECK(name, mode) \ + CHECK_FLAG_ATOMIC(&(name)->flags, (mode)&DEBUG_MODE_ALL) /* * Check if an option bit is set for a debug. * * MT-Safe */ -#define DEBUG_OPT_CHECK(name, type) \ - CHECK_FLAG_ATOMIC(&(name)->flags, (type)&DEBUG_OPT_ALL) +#define DEBUG_OPT_CHECK(name, opt) \ + CHECK_FLAG_ATOMIC(&(name)->flags, (opt)&DEBUG_OPT_ALL) /* * Check if bits are set for a debug. * * MT-Safe */ -#define DEBUG_FLAGS_CHECK(name, type) CHECK_FLAG_ATOMIC(&(name)->flags, (type)) - -/* - * Check if any mode is on for a debug. - * - * MT-Safe - */ -#define DEBUG(name) DEBUG_MODE_CHECK((name), DEBUG_MODE_ALL) +#define DEBUG_FLAGS_CHECK(name, fl) CHECK_FLAG_ATOMIC(&(name)->flags, (fl)) /* * Set modes on a debug. * * MT-Safe */ -#define DEBUG_MODE_SET(name, type) \ - SET_FLAG_ATOMIC(&(name)->flags, (type)&DEBUG_MODE_ALL) +#define DEBUG_MODE_SET(name, mode, onoff) \ + do { \ + if (onoff) \ + SET_FLAG_ATOMIC(&(name)->flags, \ + (mode)&DEBUG_MODE_ALL); \ + else \ + UNSET_FLAG_ATOMIC(&(name)->flags, \ + (mode)&DEBUG_MODE_ALL); \ + } while (0) -/* - * Unset modes on a debug. - * - * MT-Safe - */ -#define DEBUG_MODE_UNSET(name, type) \ - UNSET_FLAG_ATOMIC(&(name)->flags, (type)&DEBUG_MODE_ALL) +/* Convenience macros for specific set operations. */ +#define DEBUG_MODE_ON(name, mode) DEBUG_MODE_SET(name, mode, true) +#define DEBUG_MODE_OFF(name, mode) DEBUG_MODE_SET(name, mode, false) /* * Set options on a debug. * * MT-Safe */ -#define DEBUG_OPT_SET(name, type) \ - SET_FLAG_ATOMIC(&(name)->flags, (type)&DEBUG_OPT_ALL) +#define DEBUG_OPT_SET(name, opt, onoff) \ + do { \ + if (onoff) \ + SET_FLAG_ATOMIC(&(name)->flags, (opt)&DEBUG_OPT_ALL); \ + else \ + UNSET_FLAG_ATOMIC(&(name)->flags, \ + (opt)&DEBUG_OPT_ALL); \ + } while (0) -/* - * Unset options on a debug. - * - * MT-Safe - */ -#define DEBUG_OPT_UNSET(name, type) \ - UNSET_FLAG_ATOMIC(&(name)->flags, (type)&DEBUG_OPT_ALL) +/* Convenience macros for specific set operations. */ +#define DEBUG_OPT_ON(name, opt) DEBUG_OPT_SET(name, opt, true) +#define DEBUG_OPT_OFF(name, opt) DEBUG_OPT_SET(name, opt, true) /* * Set bits on a debug. * * MT-Safe */ -#define DEBUG_FLAGS_SET(name, type) SET_FLAG_ATOMIC(&(name)->flags, (type)) +#define DEBUG_FLAGS_SET(name, fl, onoff) \ + do { \ + if (onoff) \ + SET_FLAG_ATOMIC(&(name)->flags, (fl)); \ + else \ + UNSET_FLAG_ATOMIC(&(name)->flags, (fl)); \ + } while (0) -/* - * Unset bits on a debug. - * - * MT-Safe - */ -#define DEBUG_FLAGS_UNSET(name, type) UNSET_FLAG_ATOMIC(&(name)->flags, (type)) +/* Convenience macros for specific set operations. */ +#define DEBUG_FLAGS_ON(name, fl) DEBUG_FLAGS_SET(&(name)->flags, (type), true) +#define DEBUG_FLAGS_OFF(name, fl) DEBUG_FLAGS_SET(&(name)->flags, (type), false) /* * Unset all modes and options on a debug. @@ -201,6 +212,23 @@ struct debug_callbacks { #define DEBUG_NODE2MODE(vtynode) \ (((vtynode) == CONFIG_NODE) ? DEBUG_MODE_ALL : DEBUG_MODE_TERM) +/* + * Debug at the given level to the default logging destination. + * + * MT-Safe + */ +#define DEBUG(level, name, fmt, ...) \ + do { \ + if (DEBUG_MODE_CHECK(name, DEBUG_MODE_ALL)) \ + zlog_##level(fmt, ##__VA_ARGS__); \ + } while (0) + +/* Convenience macros for the various levels. */ +#define DEBUGE(name, fmt, ...) DEBUG(err, name, fmt, ##__VA_ARGS__) +#define DEBUGW(name, fmt, ...) DEBUG(warn, name, fmt, ##__VA_ARGS__) +#define DEBUGI(name, fmt, ...) DEBUG(info, name, fmt, ##__VA_ARGS__) +#define DEBUGN(name, fmt, ...) DEBUG(notice, name, fmt, ##__VA_ARGS__) +#define DEBUGD(name, fmt, ...) DEBUG(debug, name, fmt, ##__VA_ARGS__) /* * Optional initializer for debugging. Highly recommended. @@ -211,6 +239,16 @@ struct debug_callbacks { * * MT-Safe */ -void debug_init(const struct debug_callbacks *cb); +void debug_init(struct debug_callbacks *cb); + +/* + * Turn on the cli to turn on/off debugs. + * Should only be called by libfrr + */ +void debug_init_cli(void); + +#ifdef __cplusplus +} +#endif #endif /* _FRRDEBUG_H */