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