xref: /titanic_51/usr/src/lib/libast/common/include/debug.h (revision b72c368a02e0464faeef362bc5a1cf0fc69981da)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2009 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * common ast debug definitions
25  * include after the ast headers
26  */
27 
28 #ifndef _DEBUG_H
29 #define _DEBUG_H
30 
31 #include <ast.h>
32 #include <error.h>
33 
34 #if !defined(DEBUG) && _BLD_DEBUG
35 #define DEBUG		_BLD_DEBUG
36 #endif
37 
38 #if DEBUG || _BLD_DEBUG
39 
40 #define debug(x)	x
41 #define message(x)	do if (error_info.trace < 0) { error x; } while (0)
42 #define messagef(x)	do if (error_info.trace < 0) { errorf x; } while (0)
43 
44 #define DEBUG_BEGTIME()		debug_elapsed(1)
45 #define DEBUG_GETTIME()		debug_elapsed(0)
46 #define DEBUG_ASSERT(p)		((p) ? 0 : (debug_fatal(__FILE__, __LINE__),0))
47 #define DEBUG_COUNT(n)		((n) += 1)
48 #define DEBUG_TALLY(c,n,v)	((c) ? ((n) += (v)) : (n))
49 #define DEBUG_INCREASE(n)	((n) += 1)
50 #define DEBUG_DECREASE(n)	((n) -= 1)
51 #define DEBUG_DECLARE(t,v)	t v
52 #define DEBUG_SET(n,v)		((n) = (v))
53 #define DEBUG_PRINT(fd,s,v)	do {char _b[1024];write(fd,_b,sfsprintf(_b,sizeof(_b),s,v));} while(0)
54 #define DEBUG_WRITE(fd,d,n)	write((fd),(d),(n))
55 #define DEBUG_TEMP(temp)	(temp) /* debugging stuff that should be removed */
56 #define DEBUG_BREAK		break
57 #define DEBUG_CONTINUE		continue
58 #define DEBUG_GOTO(label)	do { debug_fatal(__FILE__, __LINE__); goto label; } while(0)
59 #define DEBUG_RETURN(x)		do { debug_fatal(__FILE__, __LINE__); return(x); } while(0)
60 
61 #else
62 
63 #define debug(x)
64 #define message(x)
65 #define messagef(x)
66 
67 #define DEBUG_BEGTIME()
68 #define DEBUG_GETTIME()
69 #define DEBUG_ASSERT(p)
70 #define DEBUG_COUNT(n)
71 #define DEBUG_TALLY(c,n,v)
72 #define DEBUG_INCREASE(n)
73 #define DEBUG_DECREASE(n)
74 #define DEBUG_DECLARE(t,v)
75 #define DEBUG_SET(n,v)
76 #define DEBUG_PRINT(fd,s,v)
77 #define DEBUG_WRITE(fd,d,n)
78 #define DEBUG_TEMP(x)
79 #define DEBUG_BREAK		break
80 #define DEBUG_CONTINUE		continue
81 #define DEBUG_GOTO(label)	goto label
82 #define DEBUG_RETURN(x)		return(x)
83 
84 #endif
85 
86 #ifndef BREAK
87 #define BREAK			DEBUG_BREAK
88 #endif
89 #ifndef CONTINUE
90 #define CONTINUE		DEBUG_CONTINUE
91 #endif
92 #ifndef GOTO
93 #define GOTO(label)		DEBUG_GOTO(label)
94 #endif
95 #ifndef RETURN
96 #define RETURN(x)		DEBUG_RETURN(x)
97 #endif
98 
99 #if _BLD_ast && defined(__EXPORT__)
100 #define extern		__EXPORT__
101 #endif
102 
103 extern double		debug_elapsed(int);
104 extern void		debug_fatal(const char*, int);
105 extern void		systrace(const char*);
106 
107 #undef	extern
108 
109 #endif
110