2 * Copyright (c) 2012, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Intel Corporation nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __MURPHY_DEBUG_H__
31 #define __MURPHY_DEBUG_H__
35 #include <murphy/common/macros.h>
36 #include <murphy/common/debug-info.h>
40 /** Log a debug message if the invoking debug site is enabled. */
41 #define mrp_debug(fmt, args...) do { \
42 static int __site_stamp = -1; \
43 static int __site_enabled; \
45 if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) { \
46 __site_enabled = mrp_debug_check(__FUNCTION__, \
47 __FILE__, __LINE__); \
48 __site_stamp = mrp_debug_stamp; \
51 if (MRP_UNLIKELY(__site_enabled)) \
52 mrp_debug_msg(__LOC__, fmt, ## args); \
56 /** mrp_debug variant with explicitly passed site info. */
57 #define mrp_debug_at(_file, _line, _func, fmt, args...) do { \
58 static int __site_stamp = -1; \
59 static int __site_enabled; \
61 if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) { \
62 __site_enabled = mrp_debug_check(_func, _file, _line); \
63 __site_stamp = mrp_debug_stamp; \
66 if (MRP_UNLIKELY(__site_enabled)) \
67 mrp_debug_msg(_file, _line, _func, fmt, ## args); \
71 /** Run a block of code if the invoking debug site is enabled. */
72 #define mrp_debug_code(...) do { \
73 static int __site_stamp = -1; \
74 static int __site_enabled; \
76 if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) { \
77 __site_enabled = mrp_debug_check(__FUNCTION__, \
78 __FILE__, __LINE__); \
79 __site_stamp = mrp_debug_stamp; \
82 if (MRP_UNLIKELY(__site_enabled)) { \
87 /** Global debug configuration stamp, exported for minimum-overhead checking. */
88 extern int mrp_debug_stamp;
90 /** Enable/disable debug messages globally. */
91 int mrp_debug_enable(int enabled);
93 /** Reset all debug configuration to the defaults. */
94 void mrp_debug_reset(void);
96 /** Apply the debug configuration settings given in cmd. */
97 int mrp_debug_set_config(const char *cmd);
99 /** Dump the active debug configuration. */
100 int mrp_debug_dump_config(FILE *fp);
102 /** Low-level log wrapper for debug messages. */
103 void mrp_debug_msg(const char *file, int line, const char *func,
104 const char *format, ...) MRP_PRINTF_LIKE(4, 5);
106 /** Check if the given debug site is enabled. */
107 int mrp_debug_check(const char *func, const char *file, int line);
111 #endif /* __MURPHY_DEBUG_H__ */