xref: /titanic_51/usr/src/lib/libast/common/include/debug.h (revision d42c7aec1963a7ded6694ac33a5bd96422fc8ca7)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 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_DECLARE(t,v)	t v
50 #define DEBUG_SET(n,v)		((n) = (v))
51 #define DEBUG_PRINT(fd,s,v)	do {char _b[1024];write(fd,_b,sfsprintf(_b,sizeof(_b),s,v));} while(0)
52 #define DEBUG_WRITE(fd,d,n)	write((fd),(d),(n))
53 #define DEBUG_TEMP(temp)	(temp) /* debugging stuff that should be removed */
54 #define DEBUG_RETURN(x)		(debug_fatal(__FILE__, __LINE__), (x))
55 #define DEBUG_BREAK		(debug_fatal(__FILE__, __LINE__))
56 #define DEBUG_GOTO(label)	do { debug_fatal(__FILE__, __LINE__); goto label; } while(0)
57 
58 #else
59 
60 #define debug(x)
61 #define message(x)
62 #define messagef(x)
63 
64 #define DEBUG_BEGTIME()
65 #define DEBUG_GETTIME()
66 #define DEBUG_ASSERT(p)
67 #define DEBUG_COUNT(n)
68 #define DEBUG_TALLY(c,n,v)
69 #define DEBUG_DECLARE(t,v)
70 #define DEBUG_SET(n,v)
71 #define DEBUG_PRINT(fd,s,v)
72 #define DEBUG_WRITE(fd,d,n)
73 #define DEBUG_KPV(x)
74 #define DEBUG_RETURN(x)		return(x)
75 #define DEBUG_BREAK		break
76 #define DEBUG_GOTO(label)	goto label
77 
78 #endif
79 
80 #if _BLD_ast && defined(__EXPORT__)
81 #define extern		__EXPORT__
82 #endif
83 
84 extern double		debug_elapsed(int);
85 extern void		debug_fatal(const char*, int);
86 extern void		systrace(const char*);
87 
88 #undef	extern
89 
90 #endif
91