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 52192Sraf * Common Development and Distribution License (the "License"). 62192Sraf * 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*12273SCasper.Dik@Sun.COM * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <stdio.h> 300Sstevel@tonic-gate #include <stdlib.h> 310Sstevel@tonic-gate #include <unistd.h> 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <libproc.h> 340Sstevel@tonic-gate #include "ramdata.h" 350Sstevel@tonic-gate #include "proto.h" 360Sstevel@tonic-gate #include "htbl.h" 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* 390Sstevel@tonic-gate * ramdata.c -- read/write data definitions are collected here. 400Sstevel@tonic-gate * Default initialization of zero applies in all cases. 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate 430Sstevel@tonic-gate thread_key_t private_key; /* set by thr_keycreate() */ 440Sstevel@tonic-gate char *command; /* name of command ("truss") */ 450Sstevel@tonic-gate int interrupt; /* interrupt signal was received */ 460Sstevel@tonic-gate int sigusr1; /* received SIGUSR1 (release process) */ 470Sstevel@tonic-gate int sfd; /* shared tmp file descriptor */ 480Sstevel@tonic-gate pid_t created; /* if process was created, its process id */ 490Sstevel@tonic-gate uid_t Euid; /* truss's effective uid */ 500Sstevel@tonic-gate uid_t Egid; /* truss's effective gid */ 510Sstevel@tonic-gate uid_t Ruid; /* truss's real uid */ 520Sstevel@tonic-gate uid_t Rgid; /* truss's real gid */ 530Sstevel@tonic-gate prcred_t credentials; /* traced process credentials */ 54*12273SCasper.Dik@Sun.COM prpriv_t *privdata; /* traced process privileges */ 550Sstevel@tonic-gate int istty; /* TRUE iff output is a tty */ 560Sstevel@tonic-gate time_t starttime; /* start time */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate int Fflag; /* option flags from getopt() */ 590Sstevel@tonic-gate int fflag; 600Sstevel@tonic-gate int cflag; 610Sstevel@tonic-gate int aflag; 620Sstevel@tonic-gate int eflag; 630Sstevel@tonic-gate int iflag; 640Sstevel@tonic-gate int lflag; 650Sstevel@tonic-gate int tflag; 660Sstevel@tonic-gate int pflag; 670Sstevel@tonic-gate int sflag; 680Sstevel@tonic-gate int mflag; 690Sstevel@tonic-gate int oflag; 700Sstevel@tonic-gate int vflag; 710Sstevel@tonic-gate int xflag; 720Sstevel@tonic-gate int hflag; 730Sstevel@tonic-gate 740Sstevel@tonic-gate int dflag; 750Sstevel@tonic-gate int Dflag; 760Sstevel@tonic-gate int Eflag; 770Sstevel@tonic-gate int Tflag; 780Sstevel@tonic-gate int Sflag; 790Sstevel@tonic-gate int Mflag; 800Sstevel@tonic-gate 810Sstevel@tonic-gate sysset_t trace; /* sys calls to trace */ 820Sstevel@tonic-gate sysset_t traceeven; /* sys calls to trace even if not reported */ 830Sstevel@tonic-gate sysset_t verbose; /* sys calls to be verbose about */ 840Sstevel@tonic-gate sysset_t rawout; /* sys calls to show in raw mode */ 850Sstevel@tonic-gate sigset_t signals; /* signals to trace */ 860Sstevel@tonic-gate fltset_t faults; /* faults to trace */ 870Sstevel@tonic-gate fileset_t readfd; /* read() file descriptors to dump */ 880Sstevel@tonic-gate fileset_t writefd; /* write() file descriptors to dump */ 890Sstevel@tonic-gate 900Sstevel@tonic-gate mutex_t truss_lock; /* protects almost everything */ 910Sstevel@tonic-gate cond_t truss_cv; 920Sstevel@tonic-gate mutex_t count_lock; /* lock protecting count struct Cp */ 930Sstevel@tonic-gate 940Sstevel@tonic-gate htbl_t *fcall_tbl; /* ptr to hash tbl counting function calls */ 950Sstevel@tonic-gate 960Sstevel@tonic-gate int truss_nlwp; /* number of truss lwps */ 970Sstevel@tonic-gate int truss_maxlwp; /* number of entries in truss_lwpid */ 980Sstevel@tonic-gate lwpid_t *truss_lwpid; /* array of truss lwpid's */ 990Sstevel@tonic-gate 1000Sstevel@tonic-gate struct counts *Cp; /* for counting: malloc() or shared memory */ 1010Sstevel@tonic-gate struct global_psinfo *gps; /* contains global process information */ 1020Sstevel@tonic-gate 1037675SEdward.Pilatowicz@Sun.COM struct dynlib *Dynlib; /* for tracing functions in shared libraries */ 1040Sstevel@tonic-gate struct dynpat *Dynpat; 1050Sstevel@tonic-gate struct dynpat *Lastpat; 1060Sstevel@tonic-gate struct bkpt **bpt_hashtable; /* breakpoint hash table */ 1070Sstevel@tonic-gate uint_t nthr_create; /* number of thr_create() calls seen so far */ 1080Sstevel@tonic-gate struct callstack *callstack; /* the callstack array */ 1090Sstevel@tonic-gate uint_t nstack; /* number of detected stacks */ 1100Sstevel@tonic-gate rd_agent_t *Rdb_agent; /* run-time linker debug handle */ 1110Sstevel@tonic-gate td_thragent_t *Thr_agent; /* thread debug handle */ 1120Sstevel@tonic-gate int not_consist; /* used while rebuilding breakpoint table */ 1132192Sraf int delete_library; /* used while rebuilding breakpoint table */ 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate pid_t ancestor; /* top-level parent process id */ 1160Sstevel@tonic-gate int descendent; /* TRUE iff descendent of top level */ 1170Sstevel@tonic-gate int is_vfork_child; /* TRUE iff process is a vfork()ed child */ 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate int ngrab; /* number of pid's that were grabbed */ 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate struct ps_prochandle *Proc; /* global reference to process */ 1220Sstevel@tonic-gate int data_model; /* PR_MODEL_LP64 or PR_MODEL_ILP32 */ 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate long pagesize; /* bytes per page; should be per-process */ 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate int exit_called; /* _exit() syscall was seen */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate lwpid_t primary_lwp; /* representative lwp on process grab */ 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate sysset_t syshang; /* sys calls to make process hang */ 1310Sstevel@tonic-gate sigset_t sighang; /* signals to make process hang */ 1320Sstevel@tonic-gate fltset_t flthang; /* faults to make process hang */ 1330Sstevel@tonic-gate 1341132Sraf sigset_t emptyset; /* no signals, for thr_sigsetmask() */ 1351132Sraf sigset_t fillset; /* all signals, for thr_sigsetmask() */ 1361132Sraf 1370Sstevel@tonic-gate int leave_hung; /* if TRUE, leave the process hung */ 138