xref: /illumos-gate/usr/src/cmd/truss/ramdata.h (revision b1dd958f54f8bfa984d306bb8ca8264855761d7b)
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  * Copyright 2004 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 
31 #ifndef _RAMDATA_H
32 #define	_RAMDATA_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * ramdata.h -- read/write data declarations.
42  */
43 
44 #include <errno.h>
45 #include <signal.h>
46 #include <synch.h>
47 #include <thread.h>
48 #include <thread_db.h>
49 #include "htbl.h"
50 
51 /*
52  * Set type for possible filedescriptors.
53  */
54 #define	NOFILES_MAX	(64 * 1024)
55 typedef struct {
56 	uint32_t word[(NOFILES_MAX+31)/32];
57 } fileset_t;
58 
59 /*
60  * Previous stop state enumeration (used by signalled() and requested()).
61  */
62 #define	SLEEPING	1
63 #define	JOBSIG		2
64 #define	JOBSTOP		3
65 
66 /*
67  * Simple convenience.
68  */
69 #ifdef	TRUE
70 #undef	TRUE
71 #endif
72 #ifdef	FALSE
73 #undef	FALSE
74 #endif
75 #define	TRUE	1
76 #define	FALSE	0
77 
78 /*
79  * Definition of private data.  See get_private().
80  */
81 
82 #define	IOBSIZE	12		/* number of bytes shown by prt_iob() */
83 
84 #define	CACHE_LN_SZ 64
85 
86 typedef struct private {
87 	struct ps_lwphandle *Lwp;	/* non-NULL for each lwp controller */
88 	const lwpstatus_t *lwpstat; /* lwp status information while stopped */
89 	int	length;		/* length of printf() output so far */
90 	pid_t	child;		/* pid of fork()ed child process */
91 	char	pname[32];	/* formatted pid/tid of controlled lwp */
92 	struct {		/* remembered parameters for make_pname() */
93 		int	ff;
94 		int	lf;
95 		pid_t	pid;
96 		id_t	lwpid;
97 		id_t	tid;
98 	} pparam;
99 	int	Errno;		/* errno for controlled process's syscall */
100 	int	ErrPriv;	/* privilege missing for last syscall */
101 	long	Rval1;		/* rval1 (%r0) for syscall */
102 	long	Rval2;		/* rval2 (%r1) for syscall */
103 	timestruc_t syslast;	/* most recent value of stime */
104 	timestruc_t usrlast;	/* most recent value of utime */
105 	long	sys_args[9];	/* the arguments to the last syscall */
106 	int	sys_nargs;	/* number of arguments to the last syscall */
107 	int	sys_indirect;	/* if TRUE, this is an indirect system call */
108 	char	sys_name[12];	/* name of unknown system call */
109 	char	raw_sig_name[SIG2STR_MAX+4]; /* name of known signal */
110 	char	sig_name[12];	/* name of unknown signal */
111 	char	flt_name[12];	/* name of unknown fault */
112 	char	*sys_path;	/* first pathname given to syscall */
113 	size_t	sys_psize;	/* sizeof(*sys_path) */
114 	int	sys_valid;	/* pathname was fetched and is valid */
115 	char	*sys_string;	/* buffer for formatted syscall string */
116 	size_t	sys_ssize;	/* sizeof(*sys_string) */
117 	size_t	sys_leng;	/* strlen(sys_string) */
118 	char	*exec_string;	/* copy of sys_string for exec() only */
119 	char	exec_pname[32];	/* formatted pid for exec() only */
120 	id_t	exec_lwpid;	/* lwpid that performed the exec */
121 	char	*str_buffer;	/* fetchstring() buffer */
122 	size_t	str_bsize;	/* sizeof(*str_buffer) */
123 	char	iob_buf[2*IOBSIZE+8];	/* where prt_iob() leaves its stuff */
124 	char	code_buf[160];	/* for symbolic arguments, e.g., ioctl codes */
125 	int	recur;		/* show_strioctl() -- to prevent recursion */
126 	int	seconds;	/* seconds, fraction for timestamps */
127 	int	fraction;	/* fraction in 1/10 milliseconds */
128 } private_t;
129 
130 extern	thread_key_t	private_key;	/* set by thr_keycreate() */
131 
132 extern	char	*command;	/* name of command ("truss") */
133 extern	int	interrupt;	/* interrupt signal was received */
134 extern	int	sigusr1;	/* received SIGUSR1 (release process) */
135 extern	int	sfd;		/* file descriptor to shared tmp file */
136 extern	pid_t	created;	/* if process was created, its process id */
137 extern	uid_t	Euid;		/* truss's effective uid */
138 extern	uid_t	Egid;		/* truss's effective gid */
139 extern	uid_t	Ruid;		/* truss's real uid */
140 extern	uid_t	Rgid;		/* truss's real gid */
141 extern	prcred_t credentials;	/* traced process credentials */
142 extern	int	istty;		/* TRUE iff output is a tty */
143 extern	time_t	starttime;	/* start time */
144 
145 extern	int	Fflag;		/* option flags from getopt() */
146 extern	int	fflag;
147 extern	int	cflag;
148 extern	int	aflag;
149 extern	int	eflag;
150 extern	int	iflag;
151 extern	int	lflag;
152 extern	int	tflag;
153 extern	int	pflag;
154 extern	int	sflag;
155 extern	int	mflag;
156 extern	int	oflag;
157 extern	int	vflag;
158 extern	int	xflag;
159 extern	int	hflag;
160 
161 extern	int	dflag;
162 extern	int	Dflag;
163 extern	int	Eflag;
164 extern	int	Tflag;
165 extern	int	Sflag;
166 extern	int	Mflag;
167 
168 extern	sysset_t trace;		/* sys calls to trace */
169 extern	sysset_t traceeven;	/* sys calls to trace even if not reported */
170 extern	sysset_t verbose;	/* sys calls to be verbose about */
171 extern	sysset_t rawout;	/* sys calls to show in raw mode */
172 extern	sigset_t signals;	/* signals to trace */
173 extern	fltset_t faults;	/* faults to trace */
174 extern	fileset_t readfd;	/* read() file descriptors to dump */
175 extern	fileset_t writefd;	/* write() file descriptors to dump */
176 
177 #pragma align CACHE_LN_SZ(truss_lock, count_lock)
178 extern	mutex_t	truss_lock;	/* protects almost everything */
179 extern	cond_t	truss_cv;	/* condition variable associated w truss_lock */
180 extern	mutex_t count_lock;	/* lock protecting count struct Cp */
181 
182 extern	htbl_t	*fcall_tbl;	/* function call hash table (per-proc) */
183 
184 extern	int	truss_nlwp;	/* number of truss lwps */
185 extern	int	truss_maxlwp;	/* number of entries in truss_lwpid */
186 extern	lwpid_t	*truss_lwpid;	/* array of truss lwpid's */
187 
188 
189 struct syscount {
190 	long count;		/* system call count */
191 	long error;		/* system call errors */
192 	timestruc_t stime;	/* time spent in system call */
193 };
194 
195 struct counts {		/* structure for keeping counts */
196 	long sigcount[PRMAXSIG+1];	/* signals count [0..PRMAXSIG] */
197 	long fltcount[PRMAXFAULT+1];	/* faults count [0..MAXFAULT] */
198 	struct syscount *syscount[PRMAXSYS+1];
199 	timestruc_t systotal;		/* total time spent in kernel */
200 	timestruc_t usrtotal;		/* total time spent in user mode */
201 	timestruc_t basetime;		/* base time for timestamps */
202 };
203 
204 struct global_psinfo {
205 	mutex_t	fork_lock;		/* protects list of truss pids */
206 	cond_t	fork_cv;
207 	char p1[CACHE_LN_SZ - (sizeof (mutex_t) + sizeof (cond_t))];
208 	mutex_t ps_mutex0;		/* see ipc.c:Ecritical */
209 	char p2[CACHE_LN_SZ - sizeof (mutex_t)];
210 	mutex_t	ps_mutex1;		/* see ipc.c:Ecritical */
211 	char p3[CACHE_LN_SZ - sizeof (mutex_t)];
212 	pid_t	fork_pid;
213 	pid_t tpid[1000];	/* truss process pid */
214 	pid_t spid[1000];	/* subject process pid */
215 	const char *lwps[1000];	/* optional lwp list */
216 };
217 
218 extern	struct counts *Cp;	/* for counting: malloc() or shared memory */
219 extern	struct global_psinfo *gps;	/* ptr to global_psinfo struct */
220 
221 struct bkpt {		/* to describe one function's entry point */
222 	struct bkpt *next;	/* hash table linked list */
223 	char	*sym_name;	/* function name */
224 	struct dynlib *dyn;	/* enclosing library */
225 	uintptr_t addr;		/* function address, breakpointed */
226 	ulong_t	instr;		/* original instruction at addr */
227 	int	flags;		/* see below */
228 };
229 #define	BPT_HANG	0x01	/* leave stopped and abandoned when called */
230 #define	BPT_EXCLUDE	0x02	/* function found but is being excluded */
231 #define	BPT_INTERNAL	0x04	/* trace internal calls on this function */
232 #define	BPT_ACTIVE	0x08	/* function breakpoint is set in process */
233 #define	BPT_PREINIT	0x10	/* PREINIT event in ld.so.1 */
234 #define	BPT_POSTINIT	0x20	/* POSTINIT event in ld.so.1 */
235 #define	BPT_DLACTIVITY	0x40	/* DLACTIVITY event in ld.so.1 */
236 #define	BPT_TD_CREATE	0x80	/* TD_CREATE threading event */
237 
238 struct dynlib {		/* structure for tracing functions */
239 	struct dynlib *next;
240 	char	*lib_name;	/* full library name */
241 	char	*match_name;	/* library name used in name matching */
242 	char	*prt_name;	/* library name for printing */
243 	int	built;		/* if true, bkpt list has been built */
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 
289 extern	pid_t	ancestor;	/* top-level parent process id */
290 extern	int	descendent;	/* TRUE iff descendent of top level */
291 extern	int	is_vfork_child;	/* TRUE iff process is a vfork()ed child */
292 
293 extern	int	ngrab;		/* number of pid's that were grabbed */
294 
295 extern	struct ps_prochandle *Proc;	/* global reference to process */
296 extern	int	data_model;	/* PR_MODEL_LP64 or PR_MODEL_ILP32 */
297 
298 extern	long	pagesize;	/* bytes per page; should be per-process */
299 
300 extern	int	exit_called;	/* _exit() syscall was seen */
301 
302 extern	lwpid_t	primary_lwp;	/* representative lwp on process grab */
303 
304 extern	sysset_t syshang;	/* sys calls to make process hang */
305 extern	sigset_t sighang;	/* signals to make process hang */
306 extern	fltset_t flthang;	/* faults to make process hang */
307 
308 extern	int	leave_hung;	/* if TRUE, leave the process hung */
309 
310 
311 #ifdef	__cplusplus
312 }
313 #endif
314 
315 #endif /* _RAMDATA_H */
316