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