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