1 #ifndef __MURPHY_DEBUG_H__
2 #define __MURPHY_DEBUG_H__
6 #include <murphy/common/macros.h>
10 /** Macro to generate a debug site string. */
11 #define MRP_DEBUG_SITE(file, line, func) \
12 "__DEBUG_SITE_"file":"MRP_STRINGIFY(line)
14 /** Log a debug message if the invoking debug site is enabled. */
15 #define mrp_debug(fmt, args...) do { \
16 static const char *__site = \
17 MRP_DEBUG_SITE(__FILE__, __LINE__, __FUNCTION__); \
18 static int __site_stamp = -1; \
19 static int __site_enabled; \
21 if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) { \
22 __site_enabled = mrp_debug_check(__FUNCTION__, \
23 __FILE__, __LINE__); \
24 __site_stamp = mrp_debug_stamp; \
27 if (MRP_UNLIKELY(__site_enabled)) \
28 mrp_debug_msg(__site, __LOC__, fmt, ## args); \
31 /** Global debug configuration stamp, exported for minimum-overhead checking. */
32 extern int mrp_debug_stamp;
34 /** Enable/disable debug messages globally. */
35 int mrp_debug_enable(int enabled);
37 /** Reset all debug configuration to the defaults. */
38 void mrp_debug_reset(void);
40 /** Apply the debug configuration settings given in cmd. */
41 int mrp_debug_set_config(const char *cmd);
43 /** Dump the active debug configuration. */
44 int mrp_debug_dump_config(FILE *fp);
46 /** Low-level log wrapper for debug messages. */
47 void mrp_debug_msg(const char *site, const char *file, int line,
48 const char *func, const char *format, ...);
50 /** Check if the given debug site is enabled. */
51 int mrp_debug_check(const char *func, const char *file, int line);
55 #endif /* __MURPHY_DEBUG_H__ */