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