10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2192Sraf * Common Development and Distribution License (the "License"). 6*2192Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211132Sraf 220Sstevel@tonic-gate /* 23*2192Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <stdio.h> 330Sstevel@tonic-gate #include <stdlib.h> 340Sstevel@tonic-gate #include <unistd.h> 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <libproc.h> 370Sstevel@tonic-gate #include "ramdata.h" 380Sstevel@tonic-gate #include "proto.h" 390Sstevel@tonic-gate #include "htbl.h" 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * ramdata.c -- read/write data definitions are collected here. 430Sstevel@tonic-gate * Default initialization of zero applies in all cases. 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate thread_key_t private_key; /* set by thr_keycreate() */ 470Sstevel@tonic-gate char *command; /* name of command ("truss") */ 480Sstevel@tonic-gate int interrupt; /* interrupt signal was received */ 490Sstevel@tonic-gate int sigusr1; /* received SIGUSR1 (release process) */ 500Sstevel@tonic-gate int sfd; /* shared tmp file descriptor */ 510Sstevel@tonic-gate pid_t created; /* if process was created, its process id */ 520Sstevel@tonic-gate uid_t Euid; /* truss's effective uid */ 530Sstevel@tonic-gate uid_t Egid; /* truss's effective gid */ 540Sstevel@tonic-gate uid_t Ruid; /* truss's real uid */ 550Sstevel@tonic-gate uid_t Rgid; /* truss's real gid */ 560Sstevel@tonic-gate prcred_t credentials; /* traced process credentials */ 570Sstevel@tonic-gate int istty; /* TRUE iff output is a tty */ 580Sstevel@tonic-gate time_t starttime; /* start time */ 590Sstevel@tonic-gate 600Sstevel@tonic-gate int Fflag; /* option flags from getopt() */ 610Sstevel@tonic-gate int fflag; 620Sstevel@tonic-gate int cflag; 630Sstevel@tonic-gate int aflag; 640Sstevel@tonic-gate int eflag; 650Sstevel@tonic-gate int iflag; 660Sstevel@tonic-gate int lflag; 670Sstevel@tonic-gate int tflag; 680Sstevel@tonic-gate int pflag; 690Sstevel@tonic-gate int sflag; 700Sstevel@tonic-gate int mflag; 710Sstevel@tonic-gate int oflag; 720Sstevel@tonic-gate int vflag; 730Sstevel@tonic-gate int xflag; 740Sstevel@tonic-gate int hflag; 750Sstevel@tonic-gate 760Sstevel@tonic-gate int dflag; 770Sstevel@tonic-gate int Dflag; 780Sstevel@tonic-gate int Eflag; 790Sstevel@tonic-gate int Tflag; 800Sstevel@tonic-gate int Sflag; 810Sstevel@tonic-gate int Mflag; 820Sstevel@tonic-gate 830Sstevel@tonic-gate sysset_t trace; /* sys calls to trace */ 840Sstevel@tonic-gate sysset_t traceeven; /* sys calls to trace even if not reported */ 850Sstevel@tonic-gate sysset_t verbose; /* sys calls to be verbose about */ 860Sstevel@tonic-gate sysset_t rawout; /* sys calls to show in raw mode */ 870Sstevel@tonic-gate sigset_t signals; /* signals to trace */ 880Sstevel@tonic-gate fltset_t faults; /* faults to trace */ 890Sstevel@tonic-gate fileset_t readfd; /* read() file descriptors to dump */ 900Sstevel@tonic-gate fileset_t writefd; /* write() file descriptors to dump */ 910Sstevel@tonic-gate 920Sstevel@tonic-gate mutex_t truss_lock; /* protects almost everything */ 930Sstevel@tonic-gate cond_t truss_cv; 940Sstevel@tonic-gate mutex_t count_lock; /* lock protecting count struct Cp */ 950Sstevel@tonic-gate 960Sstevel@tonic-gate htbl_t *fcall_tbl; /* ptr to hash tbl counting function calls */ 970Sstevel@tonic-gate 980Sstevel@tonic-gate int truss_nlwp; /* number of truss lwps */ 990Sstevel@tonic-gate int truss_maxlwp; /* number of entries in truss_lwpid */ 1000Sstevel@tonic-gate lwpid_t *truss_lwpid; /* array of truss lwpid's */ 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate struct counts *Cp; /* for counting: malloc() or shared memory */ 1030Sstevel@tonic-gate struct global_psinfo *gps; /* contains global process information */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate struct dynlib *Dyn; /* for tracing functions in shared libraries */ 1060Sstevel@tonic-gate struct dynpat *Dynpat; 1070Sstevel@tonic-gate struct dynpat *Lastpat; 1080Sstevel@tonic-gate struct bkpt **bpt_hashtable; /* breakpoint hash table */ 1090Sstevel@tonic-gate uint_t nthr_create; /* number of thr_create() calls seen so far */ 1100Sstevel@tonic-gate struct callstack *callstack; /* the callstack array */ 1110Sstevel@tonic-gate uint_t nstack; /* number of detected stacks */ 1120Sstevel@tonic-gate rd_agent_t *Rdb_agent; /* run-time linker debug handle */ 1130Sstevel@tonic-gate td_thragent_t *Thr_agent; /* thread debug handle */ 1140Sstevel@tonic-gate int not_consist; /* used while rebuilding breakpoint table */ 115*2192Sraf int delete_library; /* used while rebuilding breakpoint table */ 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate pid_t ancestor; /* top-level parent process id */ 1180Sstevel@tonic-gate int descendent; /* TRUE iff descendent of top level */ 1190Sstevel@tonic-gate int is_vfork_child; /* TRUE iff process is a vfork()ed child */ 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate int ngrab; /* number of pid's that were grabbed */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate struct ps_prochandle *Proc; /* global reference to process */ 1240Sstevel@tonic-gate int data_model; /* PR_MODEL_LP64 or PR_MODEL_ILP32 */ 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate long pagesize; /* bytes per page; should be per-process */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate int exit_called; /* _exit() syscall was seen */ 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate lwpid_t primary_lwp; /* representative lwp on process grab */ 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate sysset_t syshang; /* sys calls to make process hang */ 1330Sstevel@tonic-gate sigset_t sighang; /* signals to make process hang */ 1340Sstevel@tonic-gate fltset_t flthang; /* faults to make process hang */ 1350Sstevel@tonic-gate 1361132Sraf sigset_t emptyset; /* no signals, for thr_sigsetmask() */ 1371132Sraf sigset_t fillset; /* all signals, for thr_sigsetmask() */ 1381132Sraf 1390Sstevel@tonic-gate int leave_hung; /* if TRUE, leave the process hung */ 140