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 #ifndef _RAMDATA_H 300Sstevel@tonic-gate #define _RAMDATA_H 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* 370Sstevel@tonic-gate * ramdata.h -- read/write data declarations. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate #include <errno.h> 410Sstevel@tonic-gate #include <signal.h> 420Sstevel@tonic-gate #include <synch.h> 430Sstevel@tonic-gate #include <thread.h> 440Sstevel@tonic-gate #include <thread_db.h> 450Sstevel@tonic-gate #include "htbl.h" 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * Set type for possible filedescriptors. 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate #define NOFILES_MAX (64 * 1024) 510Sstevel@tonic-gate typedef struct { 520Sstevel@tonic-gate uint32_t word[(NOFILES_MAX+31)/32]; 530Sstevel@tonic-gate } fileset_t; 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * Previous stop state enumeration (used by signalled() and requested()). 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate #define SLEEPING 1 590Sstevel@tonic-gate #define JOBSIG 2 600Sstevel@tonic-gate #define JOBSTOP 3 610Sstevel@tonic-gate 620Sstevel@tonic-gate /* 630Sstevel@tonic-gate * Simple convenience. 640Sstevel@tonic-gate */ 650Sstevel@tonic-gate #ifdef TRUE 660Sstevel@tonic-gate #undef TRUE 670Sstevel@tonic-gate #endif 680Sstevel@tonic-gate #ifdef FALSE 690Sstevel@tonic-gate #undef FALSE 700Sstevel@tonic-gate #endif 710Sstevel@tonic-gate #define TRUE 1 720Sstevel@tonic-gate #define FALSE 0 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * Definition of private data. See get_private(). 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate 780Sstevel@tonic-gate #define IOBSIZE 12 /* number of bytes shown by prt_iob() */ 790Sstevel@tonic-gate 800Sstevel@tonic-gate #define CACHE_LN_SZ 64 810Sstevel@tonic-gate 820Sstevel@tonic-gate typedef struct private { 830Sstevel@tonic-gate struct ps_lwphandle *Lwp; /* non-NULL for each lwp controller */ 840Sstevel@tonic-gate const lwpstatus_t *lwpstat; /* lwp status information while stopped */ 850Sstevel@tonic-gate int length; /* length of printf() output so far */ 860Sstevel@tonic-gate pid_t child; /* pid of fork()ed child process */ 870Sstevel@tonic-gate char pname[32]; /* formatted pid/tid of controlled lwp */ 880Sstevel@tonic-gate struct { /* remembered parameters for make_pname() */ 890Sstevel@tonic-gate int ff; 900Sstevel@tonic-gate int lf; 910Sstevel@tonic-gate pid_t pid; 920Sstevel@tonic-gate id_t lwpid; 930Sstevel@tonic-gate id_t tid; 940Sstevel@tonic-gate } pparam; 950Sstevel@tonic-gate int Errno; /* errno for controlled process's syscall */ 960Sstevel@tonic-gate int ErrPriv; /* privilege missing for last syscall */ 970Sstevel@tonic-gate long Rval1; /* rval1 (%r0) for syscall */ 980Sstevel@tonic-gate long Rval2; /* rval2 (%r1) for syscall */ 990Sstevel@tonic-gate timestruc_t syslast; /* most recent value of stime */ 1000Sstevel@tonic-gate timestruc_t usrlast; /* most recent value of utime */ 1010Sstevel@tonic-gate long sys_args[9]; /* the arguments to the last syscall */ 1020Sstevel@tonic-gate int sys_nargs; /* number of arguments to the last syscall */ 1030Sstevel@tonic-gate int sys_indirect; /* if TRUE, this is an indirect system call */ 1040Sstevel@tonic-gate char sys_name[12]; /* name of unknown system call */ 1050Sstevel@tonic-gate char raw_sig_name[SIG2STR_MAX+4]; /* name of known signal */ 1060Sstevel@tonic-gate char sig_name[12]; /* name of unknown signal */ 1070Sstevel@tonic-gate char flt_name[12]; /* name of unknown fault */ 10811798SRoger.Faulkner@Sun.COM char *sys_path; /* pathname given to syscall */ 1090Sstevel@tonic-gate size_t sys_psize; /* sizeof(*sys_path) */ 1100Sstevel@tonic-gate int sys_valid; /* pathname was fetched and is valid */ 1110Sstevel@tonic-gate char *sys_string; /* buffer for formatted syscall string */ 1120Sstevel@tonic-gate size_t sys_ssize; /* sizeof(*sys_string) */ 1130Sstevel@tonic-gate size_t sys_leng; /* strlen(sys_string) */ 1140Sstevel@tonic-gate char *exec_string; /* copy of sys_string for exec() only */ 1150Sstevel@tonic-gate char exec_pname[32]; /* formatted pid for exec() only */ 1160Sstevel@tonic-gate id_t exec_lwpid; /* lwpid that performed the exec */ 1170Sstevel@tonic-gate char *str_buffer; /* fetchstring() buffer */ 1180Sstevel@tonic-gate size_t str_bsize; /* sizeof(*str_buffer) */ 1190Sstevel@tonic-gate char iob_buf[2*IOBSIZE+8]; /* where prt_iob() leaves its stuff */ 1200Sstevel@tonic-gate char code_buf[160]; /* for symbolic arguments, e.g., ioctl codes */ 1210Sstevel@tonic-gate int recur; /* show_strioctl() -- to prevent recursion */ 1220Sstevel@tonic-gate int seconds; /* seconds, fraction for timestamps */ 1230Sstevel@tonic-gate int fraction; /* fraction in 1/10 milliseconds */ 1240Sstevel@tonic-gate } private_t; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate extern thread_key_t private_key; /* set by thr_keycreate() */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate extern char *command; /* name of command ("truss") */ 1290Sstevel@tonic-gate extern int interrupt; /* interrupt signal was received */ 1300Sstevel@tonic-gate extern int sigusr1; /* received SIGUSR1 (release process) */ 1310Sstevel@tonic-gate extern int sfd; /* file descriptor to shared tmp file */ 1320Sstevel@tonic-gate extern pid_t created; /* if process was created, its process id */ 1330Sstevel@tonic-gate extern uid_t Euid; /* truss's effective uid */ 1340Sstevel@tonic-gate extern uid_t Egid; /* truss's effective gid */ 1350Sstevel@tonic-gate extern uid_t Ruid; /* truss's real uid */ 1360Sstevel@tonic-gate extern uid_t Rgid; /* truss's real gid */ 1370Sstevel@tonic-gate extern prcred_t credentials; /* traced process credentials */ 138*12273SCasper.Dik@Sun.COM extern prpriv_t *privdata; /* traced process privileges */ 1390Sstevel@tonic-gate extern int istty; /* TRUE iff output is a tty */ 1400Sstevel@tonic-gate extern time_t starttime; /* start time */ 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate extern int Fflag; /* option flags from getopt() */ 1430Sstevel@tonic-gate extern int fflag; 1440Sstevel@tonic-gate extern int cflag; 1450Sstevel@tonic-gate extern int aflag; 1460Sstevel@tonic-gate extern int eflag; 1470Sstevel@tonic-gate extern int iflag; 1480Sstevel@tonic-gate extern int lflag; 1490Sstevel@tonic-gate extern int tflag; 1500Sstevel@tonic-gate extern int pflag; 1510Sstevel@tonic-gate extern int sflag; 1520Sstevel@tonic-gate extern int mflag; 1530Sstevel@tonic-gate extern int oflag; 1540Sstevel@tonic-gate extern int vflag; 1550Sstevel@tonic-gate extern int xflag; 1560Sstevel@tonic-gate extern int hflag; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate extern int dflag; 1590Sstevel@tonic-gate extern int Dflag; 1600Sstevel@tonic-gate extern int Eflag; 1610Sstevel@tonic-gate extern int Tflag; 1620Sstevel@tonic-gate extern int Sflag; 1630Sstevel@tonic-gate extern int Mflag; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate extern sysset_t trace; /* sys calls to trace */ 1660Sstevel@tonic-gate extern sysset_t traceeven; /* sys calls to trace even if not reported */ 1670Sstevel@tonic-gate extern sysset_t verbose; /* sys calls to be verbose about */ 1680Sstevel@tonic-gate extern sysset_t rawout; /* sys calls to show in raw mode */ 1690Sstevel@tonic-gate extern sigset_t signals; /* signals to trace */ 1700Sstevel@tonic-gate extern fltset_t faults; /* faults to trace */ 1710Sstevel@tonic-gate extern fileset_t readfd; /* read() file descriptors to dump */ 1720Sstevel@tonic-gate extern fileset_t writefd; /* write() file descriptors to dump */ 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #pragma align CACHE_LN_SZ(truss_lock, count_lock) 1750Sstevel@tonic-gate extern mutex_t truss_lock; /* protects almost everything */ 1760Sstevel@tonic-gate extern cond_t truss_cv; /* condition variable associated w truss_lock */ 1770Sstevel@tonic-gate extern mutex_t count_lock; /* lock protecting count struct Cp */ 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate extern htbl_t *fcall_tbl; /* function call hash table (per-proc) */ 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate extern int truss_nlwp; /* number of truss lwps */ 1820Sstevel@tonic-gate extern int truss_maxlwp; /* number of entries in truss_lwpid */ 1830Sstevel@tonic-gate extern lwpid_t *truss_lwpid; /* array of truss lwpid's */ 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate struct syscount { 1870Sstevel@tonic-gate long count; /* system call count */ 1880Sstevel@tonic-gate long error; /* system call errors */ 1890Sstevel@tonic-gate timestruc_t stime; /* time spent in system call */ 1900Sstevel@tonic-gate }; 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate struct counts { /* structure for keeping counts */ 1930Sstevel@tonic-gate long sigcount[PRMAXSIG+1]; /* signals count [0..PRMAXSIG] */ 1940Sstevel@tonic-gate long fltcount[PRMAXFAULT+1]; /* faults count [0..MAXFAULT] */ 1950Sstevel@tonic-gate struct syscount *syscount[PRMAXSYS+1]; 1960Sstevel@tonic-gate timestruc_t systotal; /* total time spent in kernel */ 1970Sstevel@tonic-gate timestruc_t usrtotal; /* total time spent in user mode */ 1980Sstevel@tonic-gate timestruc_t basetime; /* base time for timestamps */ 1990Sstevel@tonic-gate }; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate struct global_psinfo { 2020Sstevel@tonic-gate mutex_t fork_lock; /* protects list of truss pids */ 2030Sstevel@tonic-gate cond_t fork_cv; 2040Sstevel@tonic-gate char p1[CACHE_LN_SZ - (sizeof (mutex_t) + sizeof (cond_t))]; 2050Sstevel@tonic-gate mutex_t ps_mutex0; /* see ipc.c:Ecritical */ 2060Sstevel@tonic-gate char p2[CACHE_LN_SZ - sizeof (mutex_t)]; 2070Sstevel@tonic-gate mutex_t ps_mutex1; /* see ipc.c:Ecritical */ 2080Sstevel@tonic-gate char p3[CACHE_LN_SZ - sizeof (mutex_t)]; 2090Sstevel@tonic-gate pid_t fork_pid; 2100Sstevel@tonic-gate pid_t tpid[1000]; /* truss process pid */ 2110Sstevel@tonic-gate pid_t spid[1000]; /* subject process pid */ 2120Sstevel@tonic-gate const char *lwps[1000]; /* optional lwp list */ 2130Sstevel@tonic-gate }; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate extern struct counts *Cp; /* for counting: malloc() or shared memory */ 2160Sstevel@tonic-gate extern struct global_psinfo *gps; /* ptr to global_psinfo struct */ 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate struct bkpt { /* to describe one function's entry point */ 2190Sstevel@tonic-gate struct bkpt *next; /* hash table linked list */ 2200Sstevel@tonic-gate char *sym_name; /* function name */ 2210Sstevel@tonic-gate struct dynlib *dyn; /* enclosing library */ 2220Sstevel@tonic-gate uintptr_t addr; /* function address, breakpointed */ 2230Sstevel@tonic-gate ulong_t instr; /* original instruction at addr */ 2240Sstevel@tonic-gate int flags; /* see below */ 2250Sstevel@tonic-gate }; 2260Sstevel@tonic-gate #define BPT_HANG 0x01 /* leave stopped and abandoned when called */ 2270Sstevel@tonic-gate #define BPT_EXCLUDE 0x02 /* function found but is being excluded */ 2280Sstevel@tonic-gate #define BPT_INTERNAL 0x04 /* trace internal calls on this function */ 2290Sstevel@tonic-gate #define BPT_ACTIVE 0x08 /* function breakpoint is set in process */ 2300Sstevel@tonic-gate #define BPT_PREINIT 0x10 /* PREINIT event in ld.so.1 */ 2310Sstevel@tonic-gate #define BPT_POSTINIT 0x20 /* POSTINIT event in ld.so.1 */ 2320Sstevel@tonic-gate #define BPT_DLACTIVITY 0x40 /* DLACTIVITY event in ld.so.1 */ 2330Sstevel@tonic-gate #define BPT_TD_CREATE 0x80 /* TD_CREATE threading event */ 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate struct dynlib { /* structure for tracing functions */ 2360Sstevel@tonic-gate struct dynlib *next; 2370Sstevel@tonic-gate char *lib_name; /* full library name */ 2380Sstevel@tonic-gate char *match_name; /* library name used in name matching */ 2390Sstevel@tonic-gate char *prt_name; /* library name for printing */ 2400Sstevel@tonic-gate int built; /* if true, bkpt list has been built */ 2412192Sraf int present; /* true if library is still present */ 2420Sstevel@tonic-gate uintptr_t base; /* library's mapping base */ 2430Sstevel@tonic-gate size_t size; /* library's mapping size */ 2440Sstevel@tonic-gate }; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate struct dynpat { /* structure specifying patterns for dynlib's */ 2470Sstevel@tonic-gate struct dynpat *next; 2480Sstevel@tonic-gate const char **libpat; /* array of patterns for library names */ 2490Sstevel@tonic-gate const char **sympat; /* array of patterns for symbol names */ 2500Sstevel@tonic-gate int nlibpat; /* number of library patterns */ 2510Sstevel@tonic-gate int nsympat; /* number of symbol patterns */ 2520Sstevel@tonic-gate char flag; /* 0 or BPT_HANG */ 2530Sstevel@tonic-gate char exclude_lib; /* if true, exclude these libraries */ 2540Sstevel@tonic-gate char exclude; /* if true, exclude these functions */ 2550Sstevel@tonic-gate char internal; /* if true, trace internal calls */ 2560Sstevel@tonic-gate struct dynlib *Dp; /* set to the dynlib instance when searching */ 2570Sstevel@tonic-gate }; 2580Sstevel@tonic-gate 2597675SEdward.Pilatowicz@Sun.COM extern struct dynlib *Dynlib; /* for tracing functions in shared libraries */ 2600Sstevel@tonic-gate extern struct dynpat *Dynpat; 2610Sstevel@tonic-gate extern struct dynpat *Lastpat; 2620Sstevel@tonic-gate extern struct bkpt **bpt_hashtable; /* breakpoint hash table */ 2630Sstevel@tonic-gate extern uint_t nthr_create; /* number of thr_create() calls seen so far */ 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate struct callstack { 2660Sstevel@tonic-gate struct callstack *next; 2670Sstevel@tonic-gate uintptr_t stkbase; /* stkbase < stkend */ 2680Sstevel@tonic-gate uintptr_t stkend; /* stkend == base + size */ 2690Sstevel@tonic-gate prgreg_t tref; /* %g7 (sparc) or %gs (intel) */ 2700Sstevel@tonic-gate id_t tid; /* thread-id */ 2710Sstevel@tonic-gate uint_t nthr_create; /* value of nthr_create last time we looked */ 2720Sstevel@tonic-gate uint_t ncall; /* number of elements in stack */ 2730Sstevel@tonic-gate uint_t maxcall; /* max elements in stack (malloc'd) */ 2740Sstevel@tonic-gate struct { 2750Sstevel@tonic-gate uintptr_t sp; /* %sp for function call */ 2760Sstevel@tonic-gate uintptr_t pc; /* value of the return %pc */ 2770Sstevel@tonic-gate struct bkpt *fcn; /* name of function called */ 2780Sstevel@tonic-gate } *stack; /* pointer to the call stack info */ 2790Sstevel@tonic-gate }; 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate extern struct callstack *callstack; /* the callstack list */ 2820Sstevel@tonic-gate extern uint_t nstack; /* number of detected stacks */ 2830Sstevel@tonic-gate extern rd_agent_t *Rdb_agent; /* run-time linker debug handle */ 2840Sstevel@tonic-gate extern td_thragent_t *Thr_agent; /* thread debug handle */ 2850Sstevel@tonic-gate extern int not_consist; /* used while rebuilding breakpoint table */ 2862192Sraf extern int delete_library; /* used while rebuilding breakpoint table */ 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate extern pid_t ancestor; /* top-level parent process id */ 2890Sstevel@tonic-gate extern int descendent; /* TRUE iff descendent of top level */ 2900Sstevel@tonic-gate extern int is_vfork_child; /* TRUE iff process is a vfork()ed child */ 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate extern int ngrab; /* number of pid's that were grabbed */ 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate extern struct ps_prochandle *Proc; /* global reference to process */ 2950Sstevel@tonic-gate extern int data_model; /* PR_MODEL_LP64 or PR_MODEL_ILP32 */ 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate extern long pagesize; /* bytes per page; should be per-process */ 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate extern int exit_called; /* _exit() syscall was seen */ 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate extern lwpid_t primary_lwp; /* representative lwp on process grab */ 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate extern sysset_t syshang; /* sys calls to make process hang */ 3040Sstevel@tonic-gate extern sigset_t sighang; /* signals to make process hang */ 3050Sstevel@tonic-gate extern fltset_t flthang; /* faults to make process hang */ 3060Sstevel@tonic-gate 3071132Sraf extern sigset_t emptyset; /* no signals, for thr_sigsetmask() */ 3081132Sraf extern sigset_t fillset; /* all signals, for thr_sigsetmask() */ 3091132Sraf 3100Sstevel@tonic-gate extern int leave_hung; /* if TRUE, leave the process hung */ 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate #ifdef __cplusplus 3140Sstevel@tonic-gate } 3150Sstevel@tonic-gate #endif 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate #endif /* _RAMDATA_H */ 318