Home | History | Annotate | Download | only in truss
      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 2008 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 #ifdef	__cplusplus
     34 extern "C" {
     35 #endif
     36 
     37 /*
     38  * ramdata.h -- read/write data declarations.
     39  */
     40 
     41 #include <errno.h>
     42 #include <signal.h>
     43 #include <synch.h>
     44 #include <thread.h>
     45 #include <thread_db.h>
     46 #include "htbl.h"
     47 
     48 /*
     49  * Set type for possible filedescriptors.
     50  */
     51 #define	NOFILES_MAX	(64 * 1024)
     52 typedef struct {
     53 	uint32_t word[(NOFILES_MAX+31)/32];
     54 } fileset_t;
     55 
     56 /*
     57  * Previous stop state enumeration (used by signalled() and requested()).
     58  */
     59 #define	SLEEPING	1
     60 #define	JOBSIG		2
     61 #define	JOBSTOP		3
     62 
     63 /*
     64  * Simple convenience.
     65  */
     66 #ifdef	TRUE
     67 #undef	TRUE
     68 #endif
     69 #ifdef	FALSE
     70 #undef	FALSE
     71 #endif
     72 #define	TRUE	1
     73 #define	FALSE	0
     74 
     75 /*
     76  * Definition of private data.  See get_private().
     77  */
     78 
     79 #define	IOBSIZE	12		/* number of bytes shown by prt_iob() */
     80 
     81 #define	CACHE_LN_SZ 64
     82 
     83 typedef struct private {
     84 	struct ps_lwphandle *Lwp;	/* non-NULL for each lwp controller */
     85 	const lwpstatus_t *lwpstat; /* lwp status information while stopped */
     86 	int	length;		/* length of printf() output so far */
     87 	pid_t	child;		/* pid of fork()ed child process */
     88 	char	pname[32];	/* formatted pid/tid of controlled lwp */
     89 	struct {		/* remembered parameters for make_pname() */
     90 		int	ff;
     91 		int	lf;
     92 		pid_t	pid;
     93 		id_t	lwpid;
     94 		id_t	tid;
     95 	} pparam;
     96 	int	Errno;		/* errno for controlled process's syscall */
     97 	int	ErrPriv;	/* privilege missing for last syscall */
     98 	long	Rval1;		/* rval1 (%r0) for syscall */
     99 	long	Rval2;		/* rval2 (%r1) for syscall */
    100 	timestruc_t syslast;	/* most recent value of stime */
    101 	timestruc_t usrlast;	/* most recent value of utime */
    102 	long	sys_args[9];	/* the arguments to the last syscall */
    103 	int	sys_nargs;	/* number of arguments to the last syscall */
    104 	int	sys_indirect;	/* if TRUE, this is an indirect system call */
    105 	char	sys_name[12];	/* name of unknown system call */
    106 	char	raw_sig_name[SIG2STR_MAX+4]; /* name of known signal */
    107 	char	sig_name[12];	/* name of unknown signal */
    108 	char	flt_name[12];	/* name of unknown fault */
    109 	char	*sys_path;	/* first pathname given to syscall */
    110 	size_t	sys_psize;	/* sizeof(*sys_path) */
    111 	int	sys_valid;	/* pathname was fetched and is valid */
    112 	char	*sys_string;	/* buffer for formatted syscall string */
    113 	size_t	sys_ssize;	/* sizeof(*sys_string) */
    114 	size_t	sys_leng;	/* strlen(sys_string) */
    115 	char	*exec_string;	/* copy of sys_string for exec() only */
    116 	char	exec_pname[32];	/* formatted pid for exec() only */
    117 	id_t	exec_lwpid;	/* lwpid that performed the exec */
    118 	char	*str_buffer;	/* fetchstring() buffer */
    119 	size_t	str_bsize;	/* sizeof(*str_buffer) */
    120 	char	iob_buf[2*IOBSIZE+8];	/* where prt_iob() leaves its stuff */
    121 	char	code_buf[160];	/* for symbolic arguments, e.g., ioctl codes */
    122 	int	recur;		/* show_strioctl() -- to prevent recursion */
    123 	int	seconds;	/* seconds, fraction for timestamps */
    124 	int	fraction;	/* fraction in 1/10 milliseconds */
    125 } private_t;
    126 
    127 extern	thread_key_t	private_key;	/* set by thr_keycreate() */
    128 
    129 extern	char	*command;	/* name of command ("truss") */
    130 extern	int	interrupt;	/* interrupt signal was received */
    131 extern	int	sigusr1;	/* received SIGUSR1 (release process) */
    132 extern	int	sfd;		/* file descriptor to shared tmp file */
    133 extern	pid_t	created;	/* if process was created, its process id */
    134 extern	uid_t	Euid;		/* truss's effective uid */
    135 extern	uid_t	Egid;		/* truss's effective gid */
    136 extern	uid_t	Ruid;		/* truss's real uid */
    137 extern	uid_t	Rgid;		/* truss's real gid */
    138 extern	prcred_t credentials;	/* traced process credentials */
    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