xref: /titanic_53/usr/src/cmd/truss/ramdata.c (revision 53e568b1ee489fdac00d297d895e708230548b79)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*53e568b1Sraf 
237c478bd9Sstevel@tonic-gate /*
24*53e568b1Sraf  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
297c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <unistd.h>
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <libproc.h>
397c478bd9Sstevel@tonic-gate #include "ramdata.h"
407c478bd9Sstevel@tonic-gate #include "proto.h"
417c478bd9Sstevel@tonic-gate #include "htbl.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * ramdata.c -- read/write data definitions are collected here.
457c478bd9Sstevel@tonic-gate  * Default initialization of zero applies in all cases.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate thread_key_t private_key;	/* set by thr_keycreate() */
497c478bd9Sstevel@tonic-gate char	*command;		/* name of command ("truss") */
507c478bd9Sstevel@tonic-gate int	interrupt;		/* interrupt signal was received */
517c478bd9Sstevel@tonic-gate int	sigusr1;		/* received SIGUSR1 (release process) */
527c478bd9Sstevel@tonic-gate int	sfd;			/* shared tmp file descriptor */
537c478bd9Sstevel@tonic-gate pid_t	created;		/* if process was created, its process id */
547c478bd9Sstevel@tonic-gate uid_t	Euid;			/* truss's effective uid */
557c478bd9Sstevel@tonic-gate uid_t	Egid;			/* truss's effective gid */
567c478bd9Sstevel@tonic-gate uid_t	Ruid;			/* truss's real uid */
577c478bd9Sstevel@tonic-gate uid_t	Rgid;			/* truss's real gid */
587c478bd9Sstevel@tonic-gate prcred_t credentials;		/* traced process credentials */
597c478bd9Sstevel@tonic-gate int	istty;			/* TRUE iff output is a tty */
607c478bd9Sstevel@tonic-gate time_t	starttime;		/* start time */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate int	Fflag;			/* option flags from getopt() */
637c478bd9Sstevel@tonic-gate int	fflag;
647c478bd9Sstevel@tonic-gate int	cflag;
657c478bd9Sstevel@tonic-gate int	aflag;
667c478bd9Sstevel@tonic-gate int	eflag;
677c478bd9Sstevel@tonic-gate int	iflag;
687c478bd9Sstevel@tonic-gate int	lflag;
697c478bd9Sstevel@tonic-gate int	tflag;
707c478bd9Sstevel@tonic-gate int	pflag;
717c478bd9Sstevel@tonic-gate int	sflag;
727c478bd9Sstevel@tonic-gate int	mflag;
737c478bd9Sstevel@tonic-gate int	oflag;
747c478bd9Sstevel@tonic-gate int	vflag;
757c478bd9Sstevel@tonic-gate int	xflag;
767c478bd9Sstevel@tonic-gate int	hflag;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate int	dflag;
797c478bd9Sstevel@tonic-gate int	Dflag;
807c478bd9Sstevel@tonic-gate int	Eflag;
817c478bd9Sstevel@tonic-gate int	Tflag;
827c478bd9Sstevel@tonic-gate int	Sflag;
837c478bd9Sstevel@tonic-gate int	Mflag;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate sysset_t trace;			/* sys calls to trace */
867c478bd9Sstevel@tonic-gate sysset_t traceeven;		/* sys calls to trace even if not reported */
877c478bd9Sstevel@tonic-gate sysset_t verbose;		/* sys calls to be verbose about */
887c478bd9Sstevel@tonic-gate sysset_t rawout;		/* sys calls to show in raw mode */
897c478bd9Sstevel@tonic-gate sigset_t signals;		/* signals to trace */
907c478bd9Sstevel@tonic-gate fltset_t faults;		/* faults to trace */
917c478bd9Sstevel@tonic-gate fileset_t readfd;		/* read() file descriptors to dump */
927c478bd9Sstevel@tonic-gate fileset_t writefd;		/* write() file descriptors to dump */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate mutex_t	truss_lock;		/* protects almost everything */
957c478bd9Sstevel@tonic-gate cond_t	truss_cv;
967c478bd9Sstevel@tonic-gate mutex_t count_lock;		/* lock protecting count struct Cp */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate htbl_t	*fcall_tbl;		/* ptr to hash tbl counting function calls */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate int	truss_nlwp;		/* number of truss lwps */
1017c478bd9Sstevel@tonic-gate int	truss_maxlwp;		/* number of entries in truss_lwpid */
1027c478bd9Sstevel@tonic-gate lwpid_t	*truss_lwpid;		/* array of truss lwpid's */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate struct counts *Cp;		/* for counting: malloc() or shared memory */
1057c478bd9Sstevel@tonic-gate struct global_psinfo *gps;	/* contains global process information */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate struct dynlib *Dyn;		/* for tracing functions in shared libraries */
1087c478bd9Sstevel@tonic-gate struct dynpat *Dynpat;
1097c478bd9Sstevel@tonic-gate struct dynpat *Lastpat;
1107c478bd9Sstevel@tonic-gate struct bkpt **bpt_hashtable;	/* breakpoint hash table */
1117c478bd9Sstevel@tonic-gate uint_t	nthr_create;		/* number of thr_create() calls seen so far */
1127c478bd9Sstevel@tonic-gate struct callstack *callstack;	/* the callstack array */
1137c478bd9Sstevel@tonic-gate uint_t	nstack;			/* number of detected stacks */
1147c478bd9Sstevel@tonic-gate rd_agent_t *Rdb_agent;		/* run-time linker debug handle */
1157c478bd9Sstevel@tonic-gate td_thragent_t *Thr_agent;	/* thread debug handle */
1167c478bd9Sstevel@tonic-gate int	not_consist;		/* used while rebuilding breakpoint table */
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate pid_t	ancestor;		/* top-level parent process id */
1197c478bd9Sstevel@tonic-gate int	descendent;		/* TRUE iff descendent of top level */
1207c478bd9Sstevel@tonic-gate int	is_vfork_child;		/* TRUE iff process is a vfork()ed child */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate int	ngrab;			/* number of pid's that were grabbed */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate struct ps_prochandle *Proc;	/* global reference to process */
1257c478bd9Sstevel@tonic-gate int	data_model;		/* PR_MODEL_LP64 or PR_MODEL_ILP32 */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate long	pagesize;		/* bytes per page; should be per-process */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate int	exit_called;		/* _exit() syscall was seen */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate lwpid_t	primary_lwp;		/* representative lwp on process grab */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate sysset_t syshang;		/* sys calls to make process hang */
1347c478bd9Sstevel@tonic-gate sigset_t sighang;		/* signals to make process hang */
1357c478bd9Sstevel@tonic-gate fltset_t flthang;		/* faults to make process hang */
1367c478bd9Sstevel@tonic-gate 
137*53e568b1Sraf sigset_t emptyset;		/* no signals, for thr_sigsetmask() */
138*53e568b1Sraf sigset_t fillset;		/* all signals, for thr_sigsetmask() */
139*53e568b1Sraf 
1407c478bd9Sstevel@tonic-gate int	leave_hung;		/* if TRUE, leave the process hung */
141