xref: /titanic_50/usr/src/cmd/truss/ramdata.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <unistd.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*7c478bd9Sstevel@tonic-gate #include <libproc.h>
38*7c478bd9Sstevel@tonic-gate #include "ramdata.h"
39*7c478bd9Sstevel@tonic-gate #include "proto.h"
40*7c478bd9Sstevel@tonic-gate #include "htbl.h"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * ramdata.c -- read/write data definitions are collected here.
44*7c478bd9Sstevel@tonic-gate  * Default initialization of zero applies in all cases.
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate thread_key_t private_key;	/* set by thr_keycreate() */
48*7c478bd9Sstevel@tonic-gate char	*command;		/* name of command ("truss") */
49*7c478bd9Sstevel@tonic-gate int	interrupt;		/* interrupt signal was received */
50*7c478bd9Sstevel@tonic-gate int	sigusr1;		/* received SIGUSR1 (release process) */
51*7c478bd9Sstevel@tonic-gate int	sfd;			/* shared tmp file descriptor */
52*7c478bd9Sstevel@tonic-gate pid_t	created;		/* if process was created, its process id */
53*7c478bd9Sstevel@tonic-gate uid_t	Euid;			/* truss's effective uid */
54*7c478bd9Sstevel@tonic-gate uid_t	Egid;			/* truss's effective gid */
55*7c478bd9Sstevel@tonic-gate uid_t	Ruid;			/* truss's real uid */
56*7c478bd9Sstevel@tonic-gate uid_t	Rgid;			/* truss's real gid */
57*7c478bd9Sstevel@tonic-gate prcred_t credentials;		/* traced process credentials */
58*7c478bd9Sstevel@tonic-gate int	istty;			/* TRUE iff output is a tty */
59*7c478bd9Sstevel@tonic-gate time_t	starttime;		/* start time */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate int	Fflag;			/* option flags from getopt() */
62*7c478bd9Sstevel@tonic-gate int	fflag;
63*7c478bd9Sstevel@tonic-gate int	cflag;
64*7c478bd9Sstevel@tonic-gate int	aflag;
65*7c478bd9Sstevel@tonic-gate int	eflag;
66*7c478bd9Sstevel@tonic-gate int	iflag;
67*7c478bd9Sstevel@tonic-gate int	lflag;
68*7c478bd9Sstevel@tonic-gate int	tflag;
69*7c478bd9Sstevel@tonic-gate int	pflag;
70*7c478bd9Sstevel@tonic-gate int	sflag;
71*7c478bd9Sstevel@tonic-gate int	mflag;
72*7c478bd9Sstevel@tonic-gate int	oflag;
73*7c478bd9Sstevel@tonic-gate int	vflag;
74*7c478bd9Sstevel@tonic-gate int	xflag;
75*7c478bd9Sstevel@tonic-gate int	hflag;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate int	dflag;
78*7c478bd9Sstevel@tonic-gate int	Dflag;
79*7c478bd9Sstevel@tonic-gate int	Eflag;
80*7c478bd9Sstevel@tonic-gate int	Tflag;
81*7c478bd9Sstevel@tonic-gate int	Sflag;
82*7c478bd9Sstevel@tonic-gate int	Mflag;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate sysset_t trace;			/* sys calls to trace */
85*7c478bd9Sstevel@tonic-gate sysset_t traceeven;		/* sys calls to trace even if not reported */
86*7c478bd9Sstevel@tonic-gate sysset_t verbose;		/* sys calls to be verbose about */
87*7c478bd9Sstevel@tonic-gate sysset_t rawout;		/* sys calls to show in raw mode */
88*7c478bd9Sstevel@tonic-gate sigset_t signals;		/* signals to trace */
89*7c478bd9Sstevel@tonic-gate fltset_t faults;		/* faults to trace */
90*7c478bd9Sstevel@tonic-gate fileset_t readfd;		/* read() file descriptors to dump */
91*7c478bd9Sstevel@tonic-gate fileset_t writefd;		/* write() file descriptors to dump */
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate mutex_t	truss_lock;		/* protects almost everything */
94*7c478bd9Sstevel@tonic-gate cond_t	truss_cv;
95*7c478bd9Sstevel@tonic-gate mutex_t count_lock;		/* lock protecting count struct Cp */
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate htbl_t	*fcall_tbl;		/* ptr to hash tbl counting function calls */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate int	truss_nlwp;		/* number of truss lwps */
100*7c478bd9Sstevel@tonic-gate int	truss_maxlwp;		/* number of entries in truss_lwpid */
101*7c478bd9Sstevel@tonic-gate lwpid_t	*truss_lwpid;		/* array of truss lwpid's */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate struct counts *Cp;		/* for counting: malloc() or shared memory */
104*7c478bd9Sstevel@tonic-gate struct global_psinfo *gps;	/* contains global process information */
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate struct dynlib *Dyn;		/* for tracing functions in shared libraries */
107*7c478bd9Sstevel@tonic-gate struct dynpat *Dynpat;
108*7c478bd9Sstevel@tonic-gate struct dynpat *Lastpat;
109*7c478bd9Sstevel@tonic-gate struct bkpt **bpt_hashtable;	/* breakpoint hash table */
110*7c478bd9Sstevel@tonic-gate uint_t	nthr_create;		/* number of thr_create() calls seen so far */
111*7c478bd9Sstevel@tonic-gate struct callstack *callstack;	/* the callstack array */
112*7c478bd9Sstevel@tonic-gate uint_t	nstack;			/* number of detected stacks */
113*7c478bd9Sstevel@tonic-gate rd_agent_t *Rdb_agent;		/* run-time linker debug handle */
114*7c478bd9Sstevel@tonic-gate td_thragent_t *Thr_agent;	/* thread debug handle */
115*7c478bd9Sstevel@tonic-gate int	not_consist;		/* used while rebuilding breakpoint table */
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate pid_t	ancestor;		/* top-level parent process id */
118*7c478bd9Sstevel@tonic-gate int	descendent;		/* TRUE iff descendent of top level */
119*7c478bd9Sstevel@tonic-gate int	is_vfork_child;		/* TRUE iff process is a vfork()ed child */
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate int	ngrab;			/* number of pid's that were grabbed */
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate struct ps_prochandle *Proc;	/* global reference to process */
124*7c478bd9Sstevel@tonic-gate int	data_model;		/* PR_MODEL_LP64 or PR_MODEL_ILP32 */
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate long	pagesize;		/* bytes per page; should be per-process */
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate int	exit_called;		/* _exit() syscall was seen */
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate lwpid_t	primary_lwp;		/* representative lwp on process grab */
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate sysset_t syshang;		/* sys calls to make process hang */
133*7c478bd9Sstevel@tonic-gate sigset_t sighang;		/* signals to make process hang */
134*7c478bd9Sstevel@tonic-gate fltset_t flthang;		/* faults to make process hang */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate int	leave_hung;		/* if TRUE, leave the process hung */
137