1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  *
24*0Sstevel@tonic-gate  *			mdbug.h
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  *	Include file for the mdbug class.
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*0Sstevel@tonic-gate /* Copyright (c) 1994 by Sun Microsystems, Inc. */
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * .LIBRARY base
34*0Sstevel@tonic-gate  * .NAME mdbug - macros for debugging C++ programs.
35*0Sstevel@tonic-gate  * .FILE dbug.cc
36*0Sstevel@tonic-gate  * .FILE mdbug.h
37*0Sstevel@tonic-gate  */
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate  * .SECTION Description
41*0Sstevel@tonic-gate  * The mdbug package provides a set of macros for debugging C++ programs.
42*0Sstevel@tonic-gate  * Features include tracing function entry and exit points, printing
43*0Sstevel@tonic-gate  * of debug messages, and heap corruption detection.  All features can
44*0Sstevel@tonic-gate  * be selectively enabled at run time using command line options.  Also
45*0Sstevel@tonic-gate  * defining the macro DBUG_OFF removes all mdbug code from the compilation.
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #ifndef MDBUG_H
49*0Sstevel@tonic-gate #define	MDBUG_H
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate #define	DBUG_STMT(A) do { A } while (0)
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate #ifndef DBUG_OFF
54*0Sstevel@tonic-gate #define	DBUG_LENGTH 64
55*0Sstevel@tonic-gate typedef struct dbug_object {
56*0Sstevel@tonic-gate 	char	d_func[DBUG_LENGTH];		/* Name of current function. */
57*0Sstevel@tonic-gate 	char	d_file[DBUG_LENGTH];		/* Name of current file. */
58*0Sstevel@tonic-gate 	struct dbug_object	*d_prev;	/* dbug_routine object */
59*0Sstevel@tonic-gate 	int	 d_leaveline;			/* Exit line from routine. */
60*0Sstevel@tonic-gate } dbug_object_t;
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate void dbug_object_create();
63*0Sstevel@tonic-gate void dbug_object_destroy(char *function_name, int line);
64*0Sstevel@tonic-gate int db_keyword(dbug_object_t *dbug_object_p, const char *keyword);
65*0Sstevel@tonic-gate void db_pargs(dbug_object_t *dbug_object_p, int line, char *keyword);
66*0Sstevel@tonic-gate void db_printf(char *keyword, char *format, ...);
67*0Sstevel@tonic-gate void db_traceprint(int line, const char *keyword);
68*0Sstevel@tonic-gate void db_assert(dbug_object_t *dbug_object_p, int line, const char *msgp);
69*0Sstevel@tonic-gate void db_precond(dbug_object_t *dbug_object_p, int line, const char *msgp);
70*0Sstevel@tonic-gate char *db_push(const char *control);
71*0Sstevel@tonic-gate void db_pop();
72*0Sstevel@tonic-gate void db_process(const char *namep);
73*0Sstevel@tonic-gate void dbug_thread_exit(void *data);
74*0Sstevel@tonic-gate dbug_object_t *db_get_dbug_object_p();
75*0Sstevel@tonic-gate void doabort();
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate #define	dbug_enter(A)		dbug_object_create(__LINE__, __FILE__, A)
79*0Sstevel@tonic-gate #define	dbug_leave(A)		dbug_object_destroy(A, __LINE__)
80*0Sstevel@tonic-gate #define	dbug_traceprint(KEY)	db_traceprint(__LINE__, KEY)
81*0Sstevel@tonic-gate #define	dbug_push(A)		db_push(A)
82*0Sstevel@tonic-gate void	dbug_pop();
83*0Sstevel@tonic-gate #define	dbug_process(A)		db_process(A)
84*0Sstevel@tonic-gate void	dbug_assert();
85*0Sstevel@tonic-gate #define	dbug_assert(A)\
86*0Sstevel@tonic-gate 	if (!(A)) { db_assert(db_get_dbug_object_p(), __LINE__, ""); }
87*0Sstevel@tonic-gate #define	dbug_precond(A)\
88*0Sstevel@tonic-gate 	if (!(A)) { db_precond(db_get_dbug_object_p(), __LINE__, ""); }
89*0Sstevel@tonic-gate void	dbug_execute();
90*0Sstevel@tonic-gate #define	dbug_print(A)		db_printf A
91*0Sstevel@tonic-gate int	db_debugon();
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate #else /* if DBUG_OFF */
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate #define	dbug_enter(A)			0
96*0Sstevel@tonic-gate #define	dbug_leave(A)			0
97*0Sstevel@tonic-gate #define	dbug_traceprint(KEY)		0
98*0Sstevel@tonic-gate #define	dbug_push(A)			0
99*0Sstevel@tonic-gate #define	dbug_pop()			0
100*0Sstevel@tonic-gate #define	dbug_process(A)			0
101*0Sstevel@tonic-gate #define	dbug_execute(KEY, CODE)		0
102*0Sstevel@tonic-gate #define	dbug_print(A)
103*0Sstevel@tonic-gate #define	dbug_assert(A)			0
104*0Sstevel@tonic-gate #define	dbug_precond(A)			0
105*0Sstevel@tonic-gate #define	db_debugon()			0
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate #endif /* DBUG_OFF */
108*0Sstevel@tonic-gate #endif /* MDBUG_H */
109