xref: /onnv-gate/usr/src/cmd/fs.d/cachefs/mdbug/priv.h (revision 0:68f95e015346)
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  *			priv.h
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  *    Internal header file for the mdbug package.
27*0Sstevel@tonic-gate  *
28*0Sstevel@tonic-gate  */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate /* Copyright (c) 1994 by Sun Microsystems, Inc. */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate  * .LIBRARY base
35*0Sstevel@tonic-gate  * .NAME dbug_state - used by dbug_routine to maintain state
36*0Sstevel@tonic-gate  *
37*0Sstevel@tonic-gate  * .SECTION Description
38*0Sstevel@tonic-gate  * The dbug_state class is used by the dbug_routine class to maintain
39*0Sstevel@tonic-gate  * state established by the dbug_push() macro.
40*0Sstevel@tonic-gate  * The priv.h include file is also used to store constructs used internally
41*0Sstevel@tonic-gate  * by the mdbug package.
42*0Sstevel@tonic-gate  */
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #ifndef PRIV_H
45*0Sstevel@tonic-gate #define	PRIV_H
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /* DBUG_DOS or DBUG_UNIX should be defined in the makefile to 1 */
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /* Define various shorthand notations. */
50*0Sstevel@tonic-gate #define	boolean int
51*0Sstevel@tonic-gate #define	TRUE 1
52*0Sstevel@tonic-gate #define	FALSE 0
53*0Sstevel@tonic-gate #define	NOT !
54*0Sstevel@tonic-gate #define	XOR ^
55*0Sstevel@tonic-gate #define	MAX(x, y) (((x) > (y)) ? (x) : (y))
56*0Sstevel@tonic-gate #define	MIN(x, y) (((x) > (y)) ? (y) : (x))
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate /* Determine which way the stack grows */
59*0Sstevel@tonic-gate #if DBUG_DOS || DBUG_UNIX
60*0Sstevel@tonic-gate const int GROWDOWN = TRUE;
61*0Sstevel@tonic-gate #else
62*0Sstevel@tonic-gate const int GROWDOWN = FALSE;
63*0Sstevel@tonic-gate #endif
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate /* Manifest constants which may be "tuned" if desired. */
66*0Sstevel@tonic-gate #define	PRINTBUF	1024	/* Print buffer size */
67*0Sstevel@tonic-gate #define	INDENT		4	/* Indentation per trace level */
68*0Sstevel@tonic-gate #define	MAXDEPTH	200	/* Maximum trace depth default */
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate boolean file_exists(const char *pathname);
71*0Sstevel@tonic-gate boolean file_writable(const char *pathname);
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate /*
74*0Sstevel@tonic-gate  * This class is used to maintain the state established by the
75*0Sstevel@tonic-gate  * push call.
76*0Sstevel@tonic-gate  */
77*0Sstevel@tonic-gate typedef struct dbug_state_object {
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate 	boolean	 sf_trace:1;	/* TRUE if tracing is on */
80*0Sstevel@tonic-gate 	boolean	 sf_debug:1;	/* TRUE if debugging is on */
81*0Sstevel@tonic-gate 	boolean	 sf_file:1;	/* TRUE if file name print enabled */
82*0Sstevel@tonic-gate 	boolean	 sf_line:1;	/* TRUE if line number print enabled */
83*0Sstevel@tonic-gate 	boolean	 sf_depth:1;	/* TRUE if function nest level print enabled */
84*0Sstevel@tonic-gate 	boolean	 sf_process:1;	/* TRUE if process name print enabled */
85*0Sstevel@tonic-gate 	boolean	 sf_number:1;	/* TRUE if number each line */
86*0Sstevel@tonic-gate 	boolean	 sf_pid:1;	/* TRUE if identify each line with pid */
87*0Sstevel@tonic-gate 	boolean	 sf_stack:1;	/* TRUE if should print stack depth */
88*0Sstevel@tonic-gate 	boolean	 sf_time:1;	/* TRUE if should print time information */
89*0Sstevel@tonic-gate 	boolean	 sf_didopen:1;	/* TRUE if opened the log file */
90*0Sstevel@tonic-gate 	boolean	 sf_thread:1;	/* TRUE if should print thread information */
91*0Sstevel@tonic-gate 	int	 s_maxdepth;	/* Current maximum trace depth */
92*0Sstevel@tonic-gate 	int	 s_delay;	/* Delay amount after each output line */
93*0Sstevel@tonic-gate 	u_int	 s_level;	/* Current function nesting level */
94*0Sstevel@tonic-gate 	time_t	 s_starttime;	/* Time push was done */
95*0Sstevel@tonic-gate 	FILE	*s_out_file;	/* Current output stream */
96*0Sstevel@tonic-gate 	flist_object_t	*s_functions;	/* List of functions */
97*0Sstevel@tonic-gate 	flist_object_t	*s_pfunctions;	/* List of profiled functions */
98*0Sstevel@tonic-gate 	flist_object_t	*s_keywords;	/* List of debug keywords */
99*0Sstevel@tonic-gate 	flist_object_t	*s_processes;	/* List of process names */
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate 	struct dbug_state_object *s_next; /* pointer to next pushed state */
102*0Sstevel@tonic-gate }dbug_state_object_t;
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate dbug_state_object_t *dbug_state_create(int);
105*0Sstevel@tonic-gate void dbug_state_destroy(dbug_state_object_t *);
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate #ifdef _REENTRANT
108*0Sstevel@tonic-gate #define	LOCK_THREAD_DATA()		mutex_lock(&mdt_lock)
109*0Sstevel@tonic-gate #define	ALLOC_THREAD_DATA_PTR(TDP)	db_alloc_thread_data(TDP)
110*0Sstevel@tonic-gate #define	GET_THREAD_DATA_PTR(TDP)	thr_getspecific(mdt_key, (void **)TDP)
111*0Sstevel@tonic-gate #define	UNLOCK_THREAD_DATA()		mutex_unlock(&mdt_lock)
112*0Sstevel@tonic-gate #define	FREE_THREAD_DATA(PTR)		free(PTR)
113*0Sstevel@tonic-gate #else
114*0Sstevel@tonic-gate #define	LOCK_THREAD_DATA()
115*0Sstevel@tonic-gate #define	ALLOC_THREAD_DATA_PTR(TDP)	*TDP = &mdt_data
116*0Sstevel@tonic-gate #define	GET_THREAD_DATA_PTR(TDP)	*TDP = &mdt_data
117*0Sstevel@tonic-gate #define	UNLOCK_THREAD_DATA()
118*0Sstevel@tonic-gate #define	FREE_THREAD_DATA(PTR)
119*0Sstevel@tonic-gate #endif
120*0Sstevel@tonic-gate #endif /* PRIV_H */
121