xref: /titanic_44/usr/src/cmd/fs.d/cachefs/mdbug/priv.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *
24  *			priv.h
25  *
26  *    Internal header file for the mdbug package.
27  *
28  */
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 /* Copyright (c) 1994 by Sun Microsystems, Inc. */
32 
33 /*
34  * .LIBRARY base
35  * .NAME dbug_state - used by dbug_routine to maintain state
36  *
37  * .SECTION Description
38  * The dbug_state class is used by the dbug_routine class to maintain
39  * state established by the dbug_push() macro.
40  * The priv.h include file is also used to store constructs used internally
41  * by the mdbug package.
42  */
43 
44 #ifndef PRIV_H
45 #define	PRIV_H
46 
47 /* DBUG_DOS or DBUG_UNIX should be defined in the makefile to 1 */
48 
49 /* Define various shorthand notations. */
50 #define	boolean int
51 #define	TRUE 1
52 #define	FALSE 0
53 #define	NOT !
54 #define	XOR ^
55 #define	MAX(x, y) (((x) > (y)) ? (x) : (y))
56 #define	MIN(x, y) (((x) > (y)) ? (y) : (x))
57 
58 /* Determine which way the stack grows */
59 #if DBUG_DOS || DBUG_UNIX
60 const int GROWDOWN = TRUE;
61 #else
62 const int GROWDOWN = FALSE;
63 #endif
64 
65 /* Manifest constants which may be "tuned" if desired. */
66 #define	PRINTBUF	1024	/* Print buffer size */
67 #define	INDENT		4	/* Indentation per trace level */
68 #define	MAXDEPTH	200	/* Maximum trace depth default */
69 
70 boolean file_exists(const char *pathname);
71 boolean file_writable(const char *pathname);
72 
73 /*
74  * This class is used to maintain the state established by the
75  * push call.
76  */
77 typedef struct dbug_state_object {
78 
79 	boolean	 sf_trace:1;	/* TRUE if tracing is on */
80 	boolean	 sf_debug:1;	/* TRUE if debugging is on */
81 	boolean	 sf_file:1;	/* TRUE if file name print enabled */
82 	boolean	 sf_line:1;	/* TRUE if line number print enabled */
83 	boolean	 sf_depth:1;	/* TRUE if function nest level print enabled */
84 	boolean	 sf_process:1;	/* TRUE if process name print enabled */
85 	boolean	 sf_number:1;	/* TRUE if number each line */
86 	boolean	 sf_pid:1;	/* TRUE if identify each line with pid */
87 	boolean	 sf_stack:1;	/* TRUE if should print stack depth */
88 	boolean	 sf_time:1;	/* TRUE if should print time information */
89 	boolean	 sf_didopen:1;	/* TRUE if opened the log file */
90 	boolean	 sf_thread:1;	/* TRUE if should print thread information */
91 	int	 s_maxdepth;	/* Current maximum trace depth */
92 	int	 s_delay;	/* Delay amount after each output line */
93 	u_int	 s_level;	/* Current function nesting level */
94 	time_t	 s_starttime;	/* Time push was done */
95 	FILE	*s_out_file;	/* Current output stream */
96 	flist_object_t	*s_functions;	/* List of functions */
97 	flist_object_t	*s_pfunctions;	/* List of profiled functions */
98 	flist_object_t	*s_keywords;	/* List of debug keywords */
99 	flist_object_t	*s_processes;	/* List of process names */
100 
101 	struct dbug_state_object *s_next; /* pointer to next pushed state */
102 }dbug_state_object_t;
103 
104 dbug_state_object_t *dbug_state_create(int);
105 void dbug_state_destroy(dbug_state_object_t *);
106 
107 #ifdef _REENTRANT
108 #define	LOCK_THREAD_DATA()		mutex_lock(&mdt_lock)
109 #define	ALLOC_THREAD_DATA_PTR(TDP)	db_alloc_thread_data(TDP)
110 #define	GET_THREAD_DATA_PTR(TDP)	thr_getspecific(mdt_key, (void **)TDP)
111 #define	UNLOCK_THREAD_DATA()		mutex_unlock(&mdt_lock)
112 #define	FREE_THREAD_DATA(PTR)		free(PTR)
113 #else
114 #define	LOCK_THREAD_DATA()
115 #define	ALLOC_THREAD_DATA_PTR(TDP)	*TDP = &mdt_data
116 #define	GET_THREAD_DATA_PTR(TDP)	*TDP = &mdt_data
117 #define	UNLOCK_THREAD_DATA()
118 #define	FREE_THREAD_DATA(PTR)
119 #endif
120 #endif /* PRIV_H */
121