xref: /onnv-gate/usr/src/cmd/truss/ramdata.c (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 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <stdio.h>
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate #include <unistd.h>
36*0Sstevel@tonic-gate #include <sys/types.h>
37*0Sstevel@tonic-gate #include <libproc.h>
38*0Sstevel@tonic-gate #include "ramdata.h"
39*0Sstevel@tonic-gate #include "proto.h"
40*0Sstevel@tonic-gate #include "htbl.h"
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * ramdata.c -- read/write data definitions are collected here.
44*0Sstevel@tonic-gate  * Default initialization of zero applies in all cases.
45*0Sstevel@tonic-gate  */
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate thread_key_t private_key;	/* set by thr_keycreate() */
48*0Sstevel@tonic-gate char	*command;		/* name of command ("truss") */
49*0Sstevel@tonic-gate int	interrupt;		/* interrupt signal was received */
50*0Sstevel@tonic-gate int	sigusr1;		/* received SIGUSR1 (release process) */
51*0Sstevel@tonic-gate int	sfd;			/* shared tmp file descriptor */
52*0Sstevel@tonic-gate pid_t	created;		/* if process was created, its process id */
53*0Sstevel@tonic-gate uid_t	Euid;			/* truss's effective uid */
54*0Sstevel@tonic-gate uid_t	Egid;			/* truss's effective gid */
55*0Sstevel@tonic-gate uid_t	Ruid;			/* truss's real uid */
56*0Sstevel@tonic-gate uid_t	Rgid;			/* truss's real gid */
57*0Sstevel@tonic-gate prcred_t credentials;		/* traced process credentials */
58*0Sstevel@tonic-gate int	istty;			/* TRUE iff output is a tty */
59*0Sstevel@tonic-gate time_t	starttime;		/* start time */
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate int	Fflag;			/* option flags from getopt() */
62*0Sstevel@tonic-gate int	fflag;
63*0Sstevel@tonic-gate int	cflag;
64*0Sstevel@tonic-gate int	aflag;
65*0Sstevel@tonic-gate int	eflag;
66*0Sstevel@tonic-gate int	iflag;
67*0Sstevel@tonic-gate int	lflag;
68*0Sstevel@tonic-gate int	tflag;
69*0Sstevel@tonic-gate int	pflag;
70*0Sstevel@tonic-gate int	sflag;
71*0Sstevel@tonic-gate int	mflag;
72*0Sstevel@tonic-gate int	oflag;
73*0Sstevel@tonic-gate int	vflag;
74*0Sstevel@tonic-gate int	xflag;
75*0Sstevel@tonic-gate int	hflag;
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate int	dflag;
78*0Sstevel@tonic-gate int	Dflag;
79*0Sstevel@tonic-gate int	Eflag;
80*0Sstevel@tonic-gate int	Tflag;
81*0Sstevel@tonic-gate int	Sflag;
82*0Sstevel@tonic-gate int	Mflag;
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate sysset_t trace;			/* sys calls to trace */
85*0Sstevel@tonic-gate sysset_t traceeven;		/* sys calls to trace even if not reported */
86*0Sstevel@tonic-gate sysset_t verbose;		/* sys calls to be verbose about */
87*0Sstevel@tonic-gate sysset_t rawout;		/* sys calls to show in raw mode */
88*0Sstevel@tonic-gate sigset_t signals;		/* signals to trace */
89*0Sstevel@tonic-gate fltset_t faults;		/* faults to trace */
90*0Sstevel@tonic-gate fileset_t readfd;		/* read() file descriptors to dump */
91*0Sstevel@tonic-gate fileset_t writefd;		/* write() file descriptors to dump */
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate mutex_t	truss_lock;		/* protects almost everything */
94*0Sstevel@tonic-gate cond_t	truss_cv;
95*0Sstevel@tonic-gate mutex_t count_lock;		/* lock protecting count struct Cp */
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate htbl_t	*fcall_tbl;		/* ptr to hash tbl counting function calls */
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate int	truss_nlwp;		/* number of truss lwps */
100*0Sstevel@tonic-gate int	truss_maxlwp;		/* number of entries in truss_lwpid */
101*0Sstevel@tonic-gate lwpid_t	*truss_lwpid;		/* array of truss lwpid's */
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate struct counts *Cp;		/* for counting: malloc() or shared memory */
104*0Sstevel@tonic-gate struct global_psinfo *gps;	/* contains global process information */
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate struct dynlib *Dyn;		/* for tracing functions in shared libraries */
107*0Sstevel@tonic-gate struct dynpat *Dynpat;
108*0Sstevel@tonic-gate struct dynpat *Lastpat;
109*0Sstevel@tonic-gate struct bkpt **bpt_hashtable;	/* breakpoint hash table */
110*0Sstevel@tonic-gate uint_t	nthr_create;		/* number of thr_create() calls seen so far */
111*0Sstevel@tonic-gate struct callstack *callstack;	/* the callstack array */
112*0Sstevel@tonic-gate uint_t	nstack;			/* number of detected stacks */
113*0Sstevel@tonic-gate rd_agent_t *Rdb_agent;		/* run-time linker debug handle */
114*0Sstevel@tonic-gate td_thragent_t *Thr_agent;	/* thread debug handle */
115*0Sstevel@tonic-gate int	not_consist;		/* used while rebuilding breakpoint table */
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate pid_t	ancestor;		/* top-level parent process id */
118*0Sstevel@tonic-gate int	descendent;		/* TRUE iff descendent of top level */
119*0Sstevel@tonic-gate int	is_vfork_child;		/* TRUE iff process is a vfork()ed child */
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate int	ngrab;			/* number of pid's that were grabbed */
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate struct ps_prochandle *Proc;	/* global reference to process */
124*0Sstevel@tonic-gate int	data_model;		/* PR_MODEL_LP64 or PR_MODEL_ILP32 */
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate long	pagesize;		/* bytes per page; should be per-process */
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate int	exit_called;		/* _exit() syscall was seen */
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate lwpid_t	primary_lwp;		/* representative lwp on process grab */
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate sysset_t syshang;		/* sys calls to make process hang */
133*0Sstevel@tonic-gate sigset_t sighang;		/* signals to make process hang */
134*0Sstevel@tonic-gate fltset_t flthang;		/* faults to make process hang */
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate int	leave_hung;		/* if TRUE, leave the process hung */
137