2 * Copyright 2004-2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * DEBUG must be defined before including this file
26 * 2: BUG, BUG_ON, d_print
28 * void debug_init(FILE *stream)
29 * Call this before any other functions in this file.
30 * Sets the debug stream.
32 * void d_print(const char *format, ...)
33 * Print debugging information to the debug stream.
35 * void BUG(const char *format, ...)
36 * Print debugging information to the debug stream and to
37 * stderr if debug stream is NOT stdout or stderr.
38 * Exits with return value 127.
40 * void BUG_ON(int condition)
41 * Calls BUG if condition is true.
56 #error DEBUG not defined
60 #error DEBUG must be >= 0
63 extern void debug_init(FILE *stream
);
64 extern void __debug_bug(const char *function
, const char *fmt
, ...) __FORMAT(2, 3) __NORETURN
;
65 extern void __debug_print(const char *function
, const char *fmt
, ...) __FORMAT(2, 3);
67 /* ------------------------------------------------------------------------ */
71 #define BUG(...) do { } while (0)
75 #define BUG(...) __debug_bug(__FUNCTION__, __VA_ARGS__)
79 /* ------------------------------------------------------------------------ */
81 #if DEBUG == 0 || DEBUG == 1
83 #define d_print(...) do { } while (0)
85 static inline void timer_get(uint64_t *usec
)
90 static inline void timer_print(const char *what
, uint64_t usec
)
96 #define d_print(...) __debug_print(__FUNCTION__, __VA_ARGS__)
98 static inline void timer_get(uint64_t *usec
)
102 gettimeofday(&tv
, NULL
);
103 *usec
= tv
.tv_sec
* 1e6L
+ tv
.tv_usec
;
106 static inline void timer_print(const char *what
, uint64_t usec
)
108 uint64_t a
= usec
/ 1e6
;
109 uint64_t b
= usec
- a
* 1e6
;
111 __debug_print("TIMER", "%s: %11Lu.%06Lu\n", what
, a
, b
);
116 /* ------------------------------------------------------------------------ */
123 BUG("%s\n", __STR(a)); \