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