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 /** Macro to generate a debug site string. */
41 #define MRP_DEBUG_SITE(file, line, func) \
42 "__DEBUG_SITE_"file":"MRP_STRINGIFY(line)
44 /** Log a debug message if the invoking debug site is enabled. */
45 #define mrp_debug(fmt, args...) do { \
46 static const char *__site = \
47 MRP_DEBUG_SITE(__FILE__, __LINE__, __FUNCTION__); \
48 static int __site_stamp = -1; \
49 static int __site_enabled; \
51 if (MRP_UNLIKELY(__site_stamp != mrp_debug_stamp)) { \
52 __site_enabled = mrp_debug_check(__FUNCTION__, \
53 __FILE__, __LINE__); \
54 __site_stamp = mrp_debug_stamp; \
57 if (MRP_UNLIKELY(__site_enabled)) \
58 mrp_debug_msg(__site, __LOC__, fmt, ## args); \
61 /** Global debug configuration stamp, exported for minimum-overhead checking. */
62 extern int mrp_debug_stamp;
64 /** Enable/disable debug messages globally. */
65 int mrp_debug_enable(int enabled);
67 /** Reset all debug configuration to the defaults. */
68 void mrp_debug_reset(void);
70 /** Apply the debug configuration settings given in cmd. */
71 int mrp_debug_set_config(const char *cmd);
73 /** Dump the active debug configuration. */
74 int mrp_debug_dump_config(FILE *fp);
76 /** Low-level log wrapper for debug messages. */
77 void mrp_debug_msg(const char *site, const char *file, int line,
78 const char *func, const char *format, ...);
80 /** Check if the given debug site is enabled. */
81 int mrp_debug_check(const char *func, const char *file, int line);
83 /** Register line->funcion mapping for file. */
84 int mrp_debug_register_file(mrp_debug_file_t *df);
86 /** Unregister line->funcion mapping for file. */
87 int mrp_debug_unregister_file(mrp_debug_file_t *df);
89 /** Return the name of the function that corresponds to file:line. */
90 const char *mrp_debug_site_function(const char *file, int line);
94 #endif /* __MURPHY_DEBUG_H__ */