5 * Copyright (C) 2009 Pierre-Marc Fournier
6 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; version 2.1 of
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
29 #include "lttng/ust-tid.h"
33 UST_LOGLEVEL_UNKNOWN
= 0,
38 extern volatile enum ust_loglevel ust_loglevel
;
39 void init_usterr(void);
41 static inline int ust_debug(void)
43 return ust_loglevel
== UST_LOGLEVEL_DEBUG
;
47 #define UST_COMPONENT libust
50 /* To stringify the expansion of a define */
51 #define XSTR(d) STR(d)
54 #define UST_STR_COMPONENT XSTR(UST_COMPONENT)
56 #define ERRMSG(fmt, args...) \
58 fprintf(stderr, UST_STR_COMPONENT "[%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
65 #ifdef LTTNG_UST_DEBUG
66 # define DBG(fmt, args...) ERRMSG(fmt, ## args)
67 # define DBG_raw(fmt, args...) \
69 fprintf(stderr, fmt, ## args); \
72 # define DBG(fmt, args...) \
75 ERRMSG(fmt, ## args); \
77 # define DBG_raw(fmt, args...) \
80 fprintf(stderr, fmt, ## args); \
85 #define WARN(fmt, args...) ERRMSG("Warning: " fmt, ## args)
86 #define ERR(fmt, args...) ERRMSG("Error: " fmt, ## args)
87 #define BUG(fmt, args...) ERRMSG("BUG: " fmt, ## args)
89 #if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
91 * Version using XSI strerror_r.
93 #define PERROR(call, args...)\
95 char buf[200] = "Error in strerror_r()"; \
96 strerror_r(errno, buf, sizeof(buf)); \
97 ERRMSG("Error: " call ": %s", ## args, buf); \
101 * Version using GNU strerror_r, for linux with appropriate defines.
103 #define PERROR(call, args...)\
107 buf = strerror_r(errno, tmp, sizeof(tmp)); \
108 ERRMSG("Error: " call ": %s", ## args, buf); \
112 #define BUG_ON(condition) \
114 if (caa_unlikely(condition)) \
115 ERR("condition not respected (BUG) on line %s:%d", __FILE__, __LINE__); \
117 #define WARN_ON(condition) \
119 if (caa_unlikely(condition)) \
120 WARN("condition not respected on line %s:%d", __FILE__, __LINE__); \
122 #define WARN_ON_ONCE(condition) WARN_ON(condition)
124 #endif /* _USTERR_H */