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