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