Timeline: Fix graphics corruption. Also, indicate loop point by modifying waveform...
[nondaw.git] / nonlib / debug.h
blobee490eb20e5935083179e1bb18a18906b1afd6d9
2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles */
4 /* */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
13 /* more details. */
14 /* */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
20 /* debug.h
22 * 11/21/2003 - Jonathan Moore Liles
24 * Debuging support.
26 * Disable by defining the preprocessor variable NDEBUG prior to inclusion.
28 * The following macros sould be defined as string literals
30 * name value
32 * __MODULE__ Name of module. eg. "libfoo"
34 * __FILE__ Name of file. eg. "foo.c"
36 * __FUNCTION__ Name of enclosing function. eg. "bar"
38 * (inteter literal)
39 * __LINE__ Number of enclosing line.
42 * __FILE__, and __LINE__ are automatically defined by standard CPP
43 * implementations. __FUNCTION__ is more or less unique to GNU, and isn't
44 * strictly a preprocessor macro, but rather a reserved word in the compiler.
45 * There is a sed script available with this toolset that is able to fake
46 * __FUNCTION__ (among other things) with an extra preprocesessing step.
48 * __MODULE__ is nonstandard and should be defined the enclosing program(s).
49 * Autoconf defines PACKAGE as the module name, and these routines will use its
50 * value instead if __MODULE__ is undefined.
52 * The following routines are provided (as macros) and take the same arguments
53 * as printf():
55 * MESSAGE( const char *format, ... )
56 * WARNING( const char *format, ... )
57 * FATAL( const char *format, ... )
59 * Calling MESSAGE or WARNING prints the message to stderr along with module,
60 * file and line information, as well as appropriate emphasis. Calling
61 * FATAL will do the same, and then call abort() to end the program. It is
62 * unwise to supply any of these marcros with arguments that produce side
63 * effects. As, doing so will most likely result in Heisenbugs; program
64 * behavior that changes when debugging is disabled.
69 #ifndef _DEBUG_H
70 #define _DEBUG_H
72 #ifndef __MODULE__
73 #ifdef PACKAGE
74 #define __MODULE__ PACKAGE
75 #else
76 #define __MODULE__ NULL
77 #endif
78 #endif
80 #ifndef __GNUC__
81 #define __FUNCTION__ NULL
82 #endif
84 typedef enum {
85 W_MESSAGE = 0,
86 W_WARNING,
87 W_FATAL
88 } warning_t;
90 void
91 warnf ( warning_t level,
92 const char *module,
93 const char *file,
94 const char *function, int line, const char *fmt, ... );
97 #ifndef NDEBUG
98 #define DMESSAGE( fmt, args... ) warnf( W_MESSAGE, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args )
99 #define DWARNING( fmt, args... ) warnf( W_WARNING, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args )
100 #define ASSERT( pred, fmt, args... ) do { if ( ! (pred) ) { warnf( W_FATAL, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ); abort(); } } while ( 0 )
101 #else
102 #define DMESSAGE( fmt, args... )
103 #define DWARNING( fmt, args... )
104 #define ASSERT( pred, fmt, args... )
105 #endif
107 /* these are always defined */
108 #define MESSAGE( fmt, args... ) warnf( W_MESSAGE, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args )
109 #define WARNING( fmt, args... ) warnf( W_WARNING, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args )
110 #define FATAL( fmt, args... ) ( warnf( W_FATAL, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ), abort() )
112 #endif