xref: /titanic_44/usr/src/cmd/truss/ramdata.h (revision 602ca9ea8f9ce0933f0944601cc5d230e91a950d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #ifndef _RAMDATA_H
31 #define	_RAMDATA_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * ramdata.h -- read/write data declarations.
41  */
42 
43 #include <errno.h>
44 #include <signal.h>
45 #include <synch.h>
46 #include <thread.h>
47 #include <thread_db.h>
48 #include "htbl.h"
49 
50 /*
51  * Set type for possible filedescriptors.
52  */
53 #define	NOFILES_MAX	(64 * 1024)
54 typedef struct {
55 	uint32_t word[(NOFILES_MAX+31)/32];
56 } fileset_t;
57 
58 /*
59  * Previous stop state enumeration (used by signalled() and requested()).
60  */
61 #define	SLEEPING	1
62 #define	JOBSIG		2
63 #define	JOBSTOP		3
64 
65 /*
66  * Simple convenience.
67  */
68 #ifdef	TRUE
69 #undef	TRUE
70 #endif
71 #ifdef	FALSE
72 #undef	FALSE
73 #endif
74 #define	TRUE	1
75 #define	FALSE	0
76 
77 /*
78  * Definition of private data.  See get_private().
79  */
80 
81 #define	IOBSIZE	12		/* number of bytes shown by prt_iob() */
82 
83 #define	CACHE_LN_SZ 64
84 
85 typedef struct private {
86 	struct ps_lwphandle *Lwp;	/* non-NULL for each lwp controller */
87 	const lwpstatus_t *lwpstat; /* lwp status information while stopped */
88 	int	length;		/* length of printf() output so far */
89 	pid_t	child;		/* pid of fork()ed child process */
90 	char	pname[32];	/* formatted pid/tid of controlled lwp */
91 	struct {		/* remembered parameters for make_pname() */
92 		int	ff;
93 		int	lf;
94 		pid_t	pid;
95 		id_t	lwpid;
96 		id_t	tid;
97 	} pparam;
98 	int	Errno;		/* errno for controlled process's syscall */
99 	int	ErrPriv;	/* privilege missing for last syscall */
100 	long	Rval1;		/* rval1 (%r0) for syscall */
101 	long	Rval2;		/* rval2 (%r1) for syscall */
102 	timestruc_t syslast;	/* most recent value of stime */
103 	timestruc_t usrlast;	/* most recent value of utime */
104 	long	sys_args[9];	/* the arguments to the last syscall */
105 	int	sys_nargs;	/* number of arguments to the last syscall */
106 	int	sys_indirect;	/* if TRUE, this is an indirect system call */
107 	char	sys_name[12];	/* name of unknown system call */
108 	char	raw_sig_name[SIG2STR_MAX+4]; /* name of known signal */
109 	char	sig_name[12];	/* name of unknown signal */
110 	char	flt_name[12];	/* name of unknown fault */
111 	char	*sys_path;	/* first pathname given to syscall */
112 	size_t	sys_psize;	/* sizeof(*sys_path) */
113 	int	sys_valid;	/* pathname was fetched and is valid */
114 	char	*sys_string;	/* buffer for formatted syscall string */
115 	size_t	sys_ssize;	/* sizeof(*sys_string) */
116 	size_t	sys_leng;	/* strlen(sys_string) */
117 	char	*exec_string;	/* copy of sys_string for exec() only */
118 	char	exec_pname[32];	/* formatted pid for exec() only */
119 	id_t	exec_lwpid;	/* lwpid that performed the exec */
120 	char	*str_buffer;	/* fetchstring() buffer */
121 	size_t	str_bsize;	/* sizeof(*str_buffer) */
122 	char	iob_buf[2*IOBSIZE+8];	/* where prt_iob() leaves its stuff */
123 	char	code_buf[160];	/* for symbolic arguments, e.g., ioctl codes */
124 	int	recur;		/* show_strioctl() -- to prevent recursion */
125 	int	seconds;	/* seconds, fraction for timestamps */
126 	int	fraction;	/* fraction in 1/10 milliseconds */
127 } private_t;
128 
129 extern	thread_key_t	private_key;	/* set by thr_keycreate() */
130 
131 extern	char	*command;	/* name of command ("truss") */
132 extern	int	interrupt;	/* interrupt signal was received */
133 extern	int	sigusr1;	/* received SIGUSR1 (release process) */
134 extern	int	sfd;		/* file descriptor to shared tmp file */
135 extern	pid_t	created;	/* if process was created, its process id */
136 extern	uid_t	Euid;		/* truss's effective uid */
137 extern	uid_t	Egid;		/* truss's effective gid */
138 extern	uid_t	Ruid;		/* truss's real uid */
139 extern	uid_t	Rgid;		/* truss's real gid */
140 extern	prcred_t credentials;	/* traced process credentials */
141 extern	int	istty;		/* TRUE iff output is a tty */
142 extern	time_t	starttime;	/* start time */
143 
144 extern	int	Fflag;		/* option flags from getopt() */
145 extern	int	fflag;
146 extern	int	cflag;
147 extern	int	aflag;
148 extern	int	eflag;
149 extern	int	iflag;
150 extern	int	lflag;
151 extern	int	tflag;
152 extern	int	pflag;
153 extern	int	sflag;
154 extern	int	mflag;
155 extern	int	oflag;
156 extern	int	vflag;
157 extern	int	xflag;
158 extern	int	hflag;
159 
160 extern	int	dflag;
161 extern	int	Dflag;
162 extern	int	Eflag;
163 extern	int	Tflag;
164 extern	int	Sflag;
165 extern	int	Mflag;
166 
167 extern	sysset_t trace;		/* sys calls to trace */
168 extern	sysset_t traceeven;	/* sys calls to trace even if not reported */
169 extern	sysset_t verbose;	/* sys calls to be verbose about */
170 extern	sysset_t rawout;	/* sys calls to show in raw mode */
171 extern	sigset_t signals;	/* signals to trace */
172 extern	fltset_t faults;	/* faults to trace */
173 extern	fileset_t readfd;	/* read() file descriptors to dump */
174 extern	fileset_t writefd;	/* write() file descriptors to dump */
175 
176 #pragma align CACHE_LN_SZ(truss_lock, count_lock)
177 extern	mutex_t	truss_lock;	/* protects almost everything */
178 extern	cond_t	truss_cv;	/* condition variable associated w truss_lock */
179 extern	mutex_t count_lock;	/* lock protecting count struct Cp */
180 
181 extern	htbl_t	*fcall_tbl;	/* function call hash table (per-proc) */
182 
183 extern	int	truss_nlwp;	/* number of truss lwps */
184 extern	int	truss_maxlwp;	/* number of entries in truss_lwpid */
185 extern	lwpid_t	*truss_lwpid;	/* array of truss lwpid's */
186 
187 
188 struct syscount {
189 	long count;		/* system call count */
190 	long error;		/* system call errors */
191 	timestruc_t stime;	/* time spent in system call */
192 };
193 
194 struct counts {		/* structure for keeping counts */
195 	long sigcount[PRMAXSIG+1];	/* signals count [0..PRMAXSIG] */
196 	long fltcount[PRMAXFAULT+1];	/* faults count [0..MAXFAULT] */
197 	struct syscount *syscount[PRMAXSYS+1];
198 	timestruc_t systotal;		/* total time spent in kernel */
199 	timestruc_t usrtotal;		/* total time spent in user mode */
200 	timestruc_t basetime;		/* base time for timestamps */
201 };
202 
203 struct global_psinfo {
204 	mutex_t	fork_lock;		/* protects list of truss pids */
205 	cond_t	fork_cv;
206 	char p1[CACHE_LN_SZ - (sizeof (mutex_t) + sizeof (cond_t))];
207 	mutex_t ps_mutex0;		/* see ipc.c:Ecritical */
208 	char p2[CACHE_LN_SZ - sizeof (mutex_t)];
209 	mutex_t	ps_mutex1;		/* see ipc.c:Ecritical */
210 	char p3[CACHE_LN_SZ - sizeof (mutex_t)];
211 	pid_t	fork_pid;
212 	pid_t tpid[1000];	/* truss process pid */
213 	pid_t spid[1000];	/* subject process pid */
214 	const char *lwps[1000];	/* optional lwp list */
215 };
216 
217 extern	struct counts *Cp;	/* for counting: malloc() or shared memory */
218 extern	struct global_psinfo *gps;	/* ptr to global_psinfo struct */
219 
220 struct bkpt {		/* to describe one function's entry point */
221 	struct bkpt *next;	/* hash table linked list */
222 	char	*sym_name;	/* function name */
223 	struct dynlib *dyn;	/* enclosing library */
224 	uintptr_t addr;		/* function address, breakpointed */
225 	ulong_t	instr;		/* original instruction at addr */
226 	int	flags;		/* see below */
227 };
228 #define	BPT_HANG	0x01	/* leave stopped and abandoned when called */
229 #define	BPT_EXCLUDE	0x02	/* function found but is being excluded */
230 #define	BPT_INTERNAL	0x04	/* trace internal calls on this function */
231 #define	BPT_ACTIVE	0x08	/* function breakpoint is set in process */
232 #define	BPT_PREINIT	0x10	/* PREINIT event in ld.so.1 */
233 #define	BPT_POSTINIT	0x20	/* POSTINIT event in ld.so.1 */
234 #define	BPT_DLACTIVITY	0x40	/* DLACTIVITY event in ld.so.1 */
235 #define	BPT_TD_CREATE	0x80	/* TD_CREATE threading event */
236 
237 struct dynlib {		/* structure for tracing functions */
238 	struct dynlib *next;
239 	char	*lib_name;	/* full library name */
240 	char	*match_name;	/* library name used in name matching */
241 	char	*prt_name;	/* library name for printing */
242 	int	built;		/* if true, bkpt list has been built */
243 	int	present;	/* true if library is still present */
244 	uintptr_t base;		/* library's mapping base */
245 	size_t	size;		/* library's mapping size */
246 };
247 
248 struct dynpat {		/* structure specifying patterns for dynlib's */
249 	struct dynpat *next;
250 	const char **libpat;	/* array of patterns for library names */
251 	const char **sympat;	/* array of patterns for symbol names */
252 	int	nlibpat;	/* number of library patterns */
253 	int	nsympat;	/* number of symbol patterns */
254 	char	flag;		/* 0 or BPT_HANG */
255 	char	exclude_lib;	/* if true, exclude these libraries */
256 	char	exclude;	/* if true, exclude these functions */
257 	char	internal;	/* if true, trace internal calls */
258 	struct dynlib *Dp;	/* set to the dynlib instance when searching */
259 };
260 
261 extern	struct dynlib *Dyn;	/* for tracing functions in shared libraries */
262 extern	struct dynpat *Dynpat;
263 extern	struct dynpat *Lastpat;
264 extern	struct bkpt **bpt_hashtable;	/* breakpoint hash table */
265 extern	uint_t	nthr_create;	/* number of thr_create() calls seen so far */
266 
267 struct callstack {
268 	struct callstack *next;
269 	uintptr_t stkbase;	/* stkbase < stkend */
270 	uintptr_t stkend;	/* stkend == base + size */
271 	prgreg_t tref;		/* %g7 (sparc) or %gs (intel) */
272 	id_t	tid;		/* thread-id */
273 	uint_t	nthr_create;	/* value of nthr_create last time we looked */
274 	uint_t	ncall;		/* number of elements in stack */
275 	uint_t	maxcall;	/* max elements in stack (malloc'd) */
276 	struct {
277 		uintptr_t sp;		/* %sp for function call */
278 		uintptr_t pc;		/* value of the return %pc */
279 		struct bkpt *fcn;	/* name of function called */
280 	} *stack;		/* pointer to the call stack info */
281 };
282 
283 extern	struct callstack *callstack;	/* the callstack list */
284 extern	uint_t	nstack;			/* number of detected stacks */
285 extern	rd_agent_t *Rdb_agent;		/* run-time linker debug handle */
286 extern	td_thragent_t *Thr_agent;	/* thread debug handle */
287 extern	int	not_consist;	/* used while rebuilding breakpoint table */
288 extern	int	delete_library;	/* used while rebuilding breakpoint table */
289 
290 extern	pid_t	ancestor;	/* top-level parent process id */
291 extern	int	descendent;	/* TRUE iff descendent of top level */
292 extern	int	is_vfork_child;	/* TRUE iff process is a vfork()ed child */
293 
294 extern	int	ngrab;		/* number of pid's that were grabbed */
295 
296 extern	struct ps_prochandle *Proc;	/* global reference to process */
297 extern	int	data_model;	/* PR_MODEL_LP64 or PR_MODEL_ILP32 */
298 
299 extern	long	pagesize;	/* bytes per page; should be per-process */
300 
301 extern	int	exit_called;	/* _exit() syscall was seen */
302 
303 extern	lwpid_t	primary_lwp;	/* representative lwp on process grab */
304 
305 extern	sysset_t syshang;	/* sys calls to make process hang */
306 extern	sigset_t sighang;	/* signals to make process hang */
307 extern	fltset_t flthang;	/* faults to make process hang */
308 
309 extern	sigset_t emptyset;	/* no signals, for thr_sigsetmask() */
310 extern	sigset_t fillset;	/* all signals, for thr_sigsetmask() */
311 
312 extern	int	leave_hung;	/* if TRUE, leave the process hung */
313 
314 
315 #ifdef	__cplusplus
316 }
317 #endif
318 
319 #endif /* _RAMDATA_H */
320