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