├── TIMESTAMP ├── include ├── features.h ├── sys │ ├── zone.h │ ├── atomic.h │ ├── cmn_err.h │ ├── taskq.h │ ├── mutex_impl.h │ ├── rwlock_impl.h │ ├── stdint.h │ ├── time.h │ ├── types32.h │ ├── int_limits.h │ └── int_types.h └── ctl.h ├── linux ├── atomic.h ├── project.h ├── sys │ ├── fp.h │ ├── kobj.h │ ├── lwp.h │ ├── modctl.h │ ├── param.h │ ├── stdint.h │ ├── stream.h │ ├── task.h │ ├── int_types.h │ ├── kobj_impl.h │ ├── project.h │ ├── rctl_impl.h │ ├── systeminfo.h │ ├── time_impl.h │ ├── feature_tests.h │ ├── zmod.h │ ├── isa_defs.h │ ├── objfs.h │ ├── systm.h │ ├── types.h │ ├── statvfs.h │ ├── sysmacros.h │ ├── rwlock.h │ ├── proc.h │ ├── pset.h │ ├── sysi86.h │ ├── vmem.h │ ├── mkdev.h │ ├── processor.h │ ├── priv.h │ ├── cpupart.h │ └── stat.h ├── priv.h ├── procfs.h ├── rctl.h ├── stdio.h ├── link.h ├── synch.h ├── strings.h ├── zone.h ├── proc_service.h ├── ieeefp.h ├── door.h └── elf.h ├── driver ├── ctf_hash.c ├── ctf_open.c ├── ctf_types.c ├── ctf_util.c ├── uncompress.c ├── ctf_lookup.c ├── .gdbinit ├── README ├── linux_pure.c ├── libc.c ├── proc_compat.h ├── taskq.h └── kcpp ├── usdt ├── c │ ├── shlib.c │ ├── simple_probes.d │ ├── mkapple │ ├── simple_probes.h │ ├── README │ └── makefile ├── cpp │ ├── shlib.c │ ├── simple_probes.d │ ├── README │ ├── simple.cpp │ ├── makefile │ └── simple_probes.h └── README ├── s ├── z ├── z1 ├── z8 ├── clone ├── fork ├── vfork ├── vm86 ├── z7 ├── z11 ├── sigreturn ├── sigaltstack ├── z6 ├── chdir ├── execve ├── iopl ├── rt_sigreturn ├── all ├── z9 ├── README ├── z2 ├── z4 ├── z3 └── z5 ├── tests ├── dt001 ├── dt003 ├── dt009 ├── dt018 ├── dt002 ├── dt006 ├── cr001 ├── z001 ├── dt017 ├── dt012 ├── probeall ├── dt005 ├── dt007 ├── dt014 ├── dt019 ├── z002 ├── dt011 ├── dt015 ├── cr002 ├── fasttrap │ ├── README │ ├── ft3.c │ ├── ft5.c │ ├── ft6.c │ ├── ft4.c │ └── ft1.c ├── probe ├── dt020 ├── dt010 ├── fbt-all ├── dt022 ├── dt021 ├── dt023 ├── dt004 ├── open.pl ├── fbt ├── makefile └── sqlite-snoop.d ├── tools ├── cross-build │ ├── i386 │ │ ├── ar │ │ ├── objdump │ │ ├── ld │ │ ├── gcc │ │ └── include │ │ │ └── linux │ │ │ └── a.h │ └── README ├── sudo ├── get-deps-arch.sh ├── raspberrypi.sh └── get-deps-fedora.sh ├── CONTRIB ├── utils ├── ptrace ├── thread ├── ptrace2 ├── mon ├── kgdb ├── README ├── find-dups ├── ustack.pl ├── opcodes ├── execvp.c ├── fork.c ├── notes ├── loop ├── getpid.c ├── vmdis ├── pd ├── makefile ├── access.c ├── iopl.c ├── diffprobes ├── getuid.c ├── idt.c ├── doit2 ├── mknod.c ├── kmem.c ├── pgfault.c ├── thread.c ├── test_syscalls.pl ├── ptrace2.c └── ptrace.c ├── scripts ├── ext3 ├── README ├── exec.d ├── chdir.d ├── open.d ├── fbt ├── iotime.d ├── stat.d ├── syscalls ├── fbt2 ├── fork.d ├── remove.d ├── syscalls2 ├── pgfault ├── nonexist.d ├── fbt3 ├── file.d ├── mkdir.d ├── syscalls3 ├── bkl.d └── systime.d ├── .release ├── .gitignore ├── driver-2 ├── mk └── Makefile ├── driver-kmem ├── mk └── Makefile ├── liblinux ├── gmatch.c ├── cpu_status.c ├── makefile └── proc.c ├── archive.sh ├── restart ├── .gdbinit ├── doc ├── prov-instr.doc ├── prov-proc.doc ├── README.first └── TIPs ├── libdtrace ├── stubs.c ├── dt_linux.h ├── i386 │ ├── dt_asmsubr.s │ └── Makefile ├── sysevent.sed.in ├── mkerrno.sh ├── mksignal.sh └── dt_string.h ├── .ignore ├── cmd ├── intrstat │ ├── i386 │ │ └── Makefile │ ├── sparcv9 │ │ └── Makefile │ ├── amd64 │ │ └── Makefile │ ├── Makefile │ └── Makefile.com ├── instr │ └── makefile └── ctfconvert │ ├── linux.h │ ├── symbol.h │ └── memory.h ├── libproc ├── common │ ├── pisadep.c │ └── Psymtab_machelf64.c ├── i386 │ └── Makefile ├── sparc │ └── Makefile ├── amd64 │ └── Makefile └── sparcv9 │ └── Makefile ├── libctf ├── llib-lctf └── uncompress.c ├── etc ├── linux.d └── dtrace.conf ├── librtld └── makefile ├── demo ├── intro │ ├── hello.d │ ├── countdown.d │ ├── counter.d │ ├── trussrw.d │ └── rwtime.d ├── user │ ├── libc.d │ ├── userfunc.d │ ├── badopen.d │ └── errorpath.d ├── agg │ ├── writesbycmd.d │ ├── writes.d │ ├── writesbycmdfd.d │ ├── lquantize.d │ ├── writetime.d │ ├── writetimeq.d │ ├── renormalize.d │ ├── clear.d │ ├── trunc.d │ ├── denorm.d │ └── normalize.d ├── script │ ├── syscall.d │ ├── interp.d │ └── tracewrite.d ├── fbt │ ├── ssd.d │ ├── putnext.d │ └── delay.d ├── dtrace │ ├── error.d │ ├── end.d │ └── begin.d ├── sched │ ├── tick.d │ ├── pri.d │ ├── where.d │ ├── ticktime.d │ ├── qtime.d │ ├── qlen.d │ ├── pritime.d │ ├── xwork.d │ ├── xterm.d │ ├── whosteal.d │ ├── howlong.d │ ├── whofor.d │ └── nscd.d ├── profile │ ├── profpri.d │ └── prof.d ├── out │ └── printa.d ├── anon │ └── iprb.d ├── spec │ └── spec.d ├── proc │ ├── progtime.d │ ├── lwptime.d │ ├── sig.d │ └── whoexec.d ├── io │ ├── applicat.d │ ├── whowrite.d │ ├── iosnoop.d │ └── whoio.d ├── buf │ └── ring.d ├── lockstat │ └── whatlock.d ├── sdt │ ├── callout.d │ └── intr.d ├── act │ └── time.d ├── sysinfo │ └── find.d ├── vars │ └── rtime.d ├── ip │ └── ipproto.d └── struct │ └── kstat.d └── uts └── common └── os └── lockstat_subr.c /TIMESTAMP: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/features.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/sys/zone.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/atomic.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/project.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/fp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/kobj.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/lwp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/modctl.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/param.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/stdint.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/stream.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/task.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/sys/atomic.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/sys/cmn_err.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/sys/taskq.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/int_types.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/kobj_impl.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/project.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/rctl_impl.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/systeminfo.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/time_impl.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/sys/mutex_impl.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/sys/rwlock_impl.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/feature_tests.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linux/sys/zmod.h: -------------------------------------------------------------------------------- 1 | # define Z_OK 0 2 | -------------------------------------------------------------------------------- /driver/ctf_hash.c: -------------------------------------------------------------------------------- 1 | ../common/ctf/ctf_hash.c -------------------------------------------------------------------------------- /driver/ctf_open.c: -------------------------------------------------------------------------------- 1 | ../common/ctf/ctf_open.c -------------------------------------------------------------------------------- /driver/ctf_types.c: -------------------------------------------------------------------------------- 1 | ../common/ctf/ctf_types.c -------------------------------------------------------------------------------- /driver/ctf_util.c: -------------------------------------------------------------------------------- 1 | ../common/ctf/ctf_util.c -------------------------------------------------------------------------------- /driver/uncompress.c: -------------------------------------------------------------------------------- 1 | ../libctf/uncompress.c -------------------------------------------------------------------------------- /linux/priv.h: -------------------------------------------------------------------------------- 1 | # include 2 | -------------------------------------------------------------------------------- /linux/procfs.h: -------------------------------------------------------------------------------- 1 | # include 2 | -------------------------------------------------------------------------------- /usdt/c/shlib.c: -------------------------------------------------------------------------------- 1 | int fred() 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /driver/ctf_lookup.c: -------------------------------------------------------------------------------- 1 | ../common/ctf/ctf_lookup.c -------------------------------------------------------------------------------- /include/sys/stdint.h: -------------------------------------------------------------------------------- 1 | ../../linux/linux_types.h -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | # include 2 | -------------------------------------------------------------------------------- /include/sys/types32.h: -------------------------------------------------------------------------------- 1 | ../../linux/sys/types32.h -------------------------------------------------------------------------------- /s/z: -------------------------------------------------------------------------------- 1 | root build/dtrace -n syscall::execve: 2 | -------------------------------------------------------------------------------- /s/z1: -------------------------------------------------------------------------------- 1 | root build/dtrace -n syscall::clone: 2 | -------------------------------------------------------------------------------- /tests/dt001: -------------------------------------------------------------------------------- 1 | dtrace -s demo/agg/denorm.d "$@" 2 | -------------------------------------------------------------------------------- /tests/dt003: -------------------------------------------------------------------------------- 1 | dtrace -v -f log_wait_commit 2 | -------------------------------------------------------------------------------- /usdt/cpp/shlib.c: -------------------------------------------------------------------------------- 1 | void fred(void) 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /include/sys/int_limits.h: -------------------------------------------------------------------------------- 1 | ../../linux/sys/int_limits.h -------------------------------------------------------------------------------- /include/sys/int_types.h: -------------------------------------------------------------------------------- 1 | ../../linux/sys/int_types.h -------------------------------------------------------------------------------- /linux/rctl.h: -------------------------------------------------------------------------------- 1 | typedef struct rctlblk rctlblk_t; 2 | -------------------------------------------------------------------------------- /linux/sys/isa_defs.h: -------------------------------------------------------------------------------- 1 | # include 2 | -------------------------------------------------------------------------------- /s/z8: -------------------------------------------------------------------------------- 1 | while true 2 | do 3 | build/sys64 4 | done 5 | -------------------------------------------------------------------------------- /tests/dt009: -------------------------------------------------------------------------------- 1 | dtrace -s ../../demo/vars/rtime.d 2 | -------------------------------------------------------------------------------- /s/clone: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::clone: 3 | -------------------------------------------------------------------------------- /s/fork: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::fork: 3 | -------------------------------------------------------------------------------- /s/vfork: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::vfork: 3 | -------------------------------------------------------------------------------- /s/vm86: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::vm86: 3 | -------------------------------------------------------------------------------- /s/z7: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall:::'{x++}' 3 | -------------------------------------------------------------------------------- /tests/dt018: -------------------------------------------------------------------------------- 1 | dtrace -c $HOME/src/dtrace/build/simple-c 2 | -------------------------------------------------------------------------------- /tools/cross-build/i386/ar: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec ar "$@" 3 | -------------------------------------------------------------------------------- /s/z11: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::sigaltstack: 3 | -------------------------------------------------------------------------------- /CONTRIB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtrace4linux/linux/HEAD/CONTRIB -------------------------------------------------------------------------------- /s/sigreturn: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::sigreturn: 3 | -------------------------------------------------------------------------------- /tests/dt002: -------------------------------------------------------------------------------- 1 | setuid root ./dtrace -n 'dtrace:::BEGIN' 2 | -------------------------------------------------------------------------------- /tests/dt006: -------------------------------------------------------------------------------- 1 | syscall::open: 2 | { 3 | trace(timestamp); 4 | } 5 | -------------------------------------------------------------------------------- /tools/cross-build/i386/objdump: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | exec objdump "$@" 3 | -------------------------------------------------------------------------------- /s/sigaltstack: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::sigaltstack: 3 | -------------------------------------------------------------------------------- /s/z6: -------------------------------------------------------------------------------- 1 | sync 2 | sleep 1 3 | root build/dtrace -n fbt::a[A-p]*:'{x++;}' 4 | -------------------------------------------------------------------------------- /tests/cr001: -------------------------------------------------------------------------------- 1 | dtrace -n ':::function-entry {printf("%d\n", arg0);}' 2 | -------------------------------------------------------------------------------- /tests/z001: -------------------------------------------------------------------------------- 1 | prog=${1:-ft4} 2 | root build/dtrace -n pid`pgrep $prog`::: 3 | -------------------------------------------------------------------------------- /utils/ptrace: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtrace4linux/linux/HEAD/utils/ptrace -------------------------------------------------------------------------------- /utils/thread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtrace4linux/linux/HEAD/utils/thread -------------------------------------------------------------------------------- /linux/stdio.h: -------------------------------------------------------------------------------- 1 | # include 2 | # include "/usr/include/stdio.h" 3 | -------------------------------------------------------------------------------- /scripts/ext3: -------------------------------------------------------------------------------- 1 | build/dtrace -n 'fbt::ext3_*:entry { printf("%s", execname);}' 2 | -------------------------------------------------------------------------------- /tests/dt017: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | dtrace -n 'profile-1999{ @[execname] = count(); }' 3 | -------------------------------------------------------------------------------- /utils/ptrace2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtrace4linux/linux/HEAD/utils/ptrace2 -------------------------------------------------------------------------------- /.release: -------------------------------------------------------------------------------- 1 | date=Mon Jun 13 23:21:08 BST 2016 2 | release=dtrace-20160613 3 | build=499 4 | -------------------------------------------------------------------------------- /tests/dt012: -------------------------------------------------------------------------------- 1 | syscall::open:entry 2 | { 3 | printf("hello, arg0=%x\n", arg0); 4 | } 5 | -------------------------------------------------------------------------------- /s/chdir: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::chdir:'{printf("pid=%d %s", pid, execname);}' 3 | -------------------------------------------------------------------------------- /s/execve: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::execve:'{printf("pid=%d %s", pid, execname);}' 3 | -------------------------------------------------------------------------------- /s/iopl: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::iopl:'{printf("pid=%d %s", pid, execname);}' 3 | -------------------------------------------------------------------------------- /tests/probeall: -------------------------------------------------------------------------------- 1 | # dev_hard_start_xmit 2 | dtrace -n 'fbt:::entry{ @[probefunc] = count(); }' 3 | -------------------------------------------------------------------------------- /tests/dt005: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | dtrace -n 'syscall::open:return { printf("exec=%s\n", execname); } ' 3 | -------------------------------------------------------------------------------- /scripts/README: -------------------------------------------------------------------------------- 1 | This bunch of scripts will be subsumed into a single master 2 | Perl script very soon... 3 | -------------------------------------------------------------------------------- /usdt/c/simple_probes.d: -------------------------------------------------------------------------------- 1 | provider simple { 2 | probe saw__word(int); 3 | probe saw__line(int); 4 | }; 5 | -------------------------------------------------------------------------------- /usdt/cpp/simple_probes.d: -------------------------------------------------------------------------------- 1 | provider simple { 2 | probe saw__word(int); 3 | probe saw__line(int); 4 | }; 5 | -------------------------------------------------------------------------------- /s/rt_sigreturn: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n syscall::rt_sigreturn:'{printf("pid=%d %s", pid, execname);}' 3 | -------------------------------------------------------------------------------- /linux/sys/objfs.h: -------------------------------------------------------------------------------- 1 | typedef struct objfs_info { 2 | int objfs_info_primary; 3 | } objfs_info_t; 4 | -------------------------------------------------------------------------------- /tests/dt007: -------------------------------------------------------------------------------- 1 | syscall:::entry 2 | { 3 | @func[execname] = count(); 4 | } 5 | END 6 | { 7 | printa(@func); 8 | } 9 | -------------------------------------------------------------------------------- /tests/dt014: -------------------------------------------------------------------------------- 1 | syscall::access:return 2 | /arg1 < 0/ 3 | { 4 | printf("ustack follows\n"); 5 | ustack(); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /utils/mon: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | while true 3 | do 4 | echo `date +%H:%M:%S` `grep dcnt /dev/dtrace` 5 | sleep 1 6 | done 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .first-time 3 | .test.prompt 4 | .dtrace.nobug 5 | doc/lwn 6 | build* 7 | tags 8 | checksum.lst 9 | -------------------------------------------------------------------------------- /utils/kgdb: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # simple script to allow me to disassemble running kernel 3 | root gdb /proc/mem /proc/kcore 4 | -------------------------------------------------------------------------------- /tools/sudo: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | if [ -x $HOME/bin/setuid ]; then 4 | setuid root "$@" 5 | else 6 | sudo "$@" 7 | fi 8 | 9 | -------------------------------------------------------------------------------- /driver/.gdbinit: -------------------------------------------------------------------------------- 1 | dir ../../libctf 2 | dir ../../libdtrace 3 | dir ../../liblinux 4 | dir ../../libproc 5 | dir ../../cmd/dtrace 6 | -------------------------------------------------------------------------------- /usdt/cpp/README: -------------------------------------------------------------------------------- 1 | C++ code test/example of a USDT. Just make and run - and it should show 2 | up in the 'dtrace -l' list. 3 | 4 | 5 | -------------------------------------------------------------------------------- /driver-2/mk: -------------------------------------------------------------------------------- 1 | BUILD_KERNEL=${BUILD_KERNEL:-`uname -r`} 2 | build_dir=/lib/modules/$BUILD_KERNEL/build 3 | make -C $build_dir M=`pwd` $@ 4 | -------------------------------------------------------------------------------- /tools/cross-build/i386/ld: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | args=`echo $* | sed -e 's/elf_x86_64/elf_i386/'` 3 | #echo ld $* >/tmp/l 4 | exec ld $args 5 | -------------------------------------------------------------------------------- /driver-kmem/mk: -------------------------------------------------------------------------------- 1 | BUILD_KERNEL=${BUILD_KERNEL:-`uname -r`} 2 | build_dir=/lib/modules/$BUILD_KERNEL/build 3 | make -C $build_dir M=`pwd` $@ 4 | -------------------------------------------------------------------------------- /liblinux/gmatch.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int 5 | gmatch(const char *s, const char *p) 6 | { 7 | return !fnmatch(p, s, 0); 8 | } 9 | -------------------------------------------------------------------------------- /utils/README: -------------------------------------------------------------------------------- 1 | Mostly junk play/test files, e.g. mknod.c to stress test dtrace 2 | on a rare system call. 3 | 4 | Nothing of value here. 5 | -------------------------------------------------------------------------------- /linux/link.h: -------------------------------------------------------------------------------- 1 | # if !defined(LINK_H) 2 | # define LINK_H 3 | 4 | # include 5 | //# include "/usr/include/link.h" 6 | 7 | # endif 8 | -------------------------------------------------------------------------------- /tests/dt019: -------------------------------------------------------------------------------- 1 | # check usdt attaching/kill 2 | set +x 3 | 4 | build/simple-c & 5 | sleep 5 6 | echo launching dtrace... 7 | dtrace -n :::saw-word 8 | -------------------------------------------------------------------------------- /archive.sh: -------------------------------------------------------------------------------- 1 | NAME=dtrace 2 | MAJ_VERSION=1 3 | MIN_VERSION=0155 4 | EXCLUDE="*.ko *.o .git" 5 | EXCLUDE_DIRS="build-" 6 | #date Tue Mar 3 22:32:52 GMT 2015 7 | -------------------------------------------------------------------------------- /linux/sys/systm.h: -------------------------------------------------------------------------------- 1 | /*# include */ 2 | # define _SC_CPUID_MAX _SC_NPROCESSORS_ONLN 3 | # define _SC_NPROCESSORS_MAX _SC_NPROCESSORS_CONF 4 | -------------------------------------------------------------------------------- /linux/sys/types.h: -------------------------------------------------------------------------------- 1 | # if !defined(SYS_TYPES_H) 2 | # define SYS_TYPES_H 3 | 4 | # include 5 | //# include "/usr/include/sys/stat.h" 6 | # endif 7 | -------------------------------------------------------------------------------- /scripts/exec.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::exec*:entry 4 | { 5 | printf("%d %s: %s\n", pid, execname, copyinstr(arg0)); 6 | } 7 | ' 8 | -------------------------------------------------------------------------------- /tests/z002: -------------------------------------------------------------------------------- 1 | root build/dtrace -c /bin/date -n ' 2 | syscall::: 3 | { 4 | /*printf("%d %s %d", pid, execname, $target);*/ 5 | cnt++; 6 | } 7 | 8 | ' 9 | -------------------------------------------------------------------------------- /scripts/chdir.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::chdir:entry 4 | { 5 | printf("%d %s: cd %s\n", pid, execname, copyinstr(arg0)); 6 | } 7 | ' 8 | 9 | -------------------------------------------------------------------------------- /usdt/c/mkapple: -------------------------------------------------------------------------------- 1 | # This is how it is done on Apple, due to compiler/linker enhancements. 2 | dtrace -h -s simple_probes.d 3 | gcc -I../../uts/common -o simple simple.c 4 | -------------------------------------------------------------------------------- /scripts/open.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::open*:entry 4 | { 5 | printf("%d %s: %s %s\n", pid, execname, probefunc, copyinstr(arg0)); 6 | } 7 | ' 8 | -------------------------------------------------------------------------------- /tests/dt011: -------------------------------------------------------------------------------- 1 | syscall::open:entry 2 | { 3 | printf("%s (hello)\n", execname); 4 | self->path = copyinstr(arg0); 5 | printf("%s open(%s)\n", execname, (string)arg0); 6 | } 7 | -------------------------------------------------------------------------------- /tools/get-deps-arch.sh: -------------------------------------------------------------------------------- 1 | # pacman -Qo /bin/netstat -- to find packages 2 | pacman -S libelf linux linux-headers \ 3 | systemd gdb rsync net-tools strace openssh make bison flex 4 | -------------------------------------------------------------------------------- /scripts/fbt: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Fbt calls 3 | echo "Function calls, ordered by frequency. Press Ctrl-C to quit" 4 | set +x 5 | dtrace -n 'fbt:::entry { @num[probefunc] = count(); }' 6 | 7 | -------------------------------------------------------------------------------- /scripts/iotime.d: -------------------------------------------------------------------------------- 1 | io:::start 2 | { 3 | this->t = timestamp; 4 | } 5 | io:::done 6 | /timestamp - this->t > 1000/ 7 | { 8 | printf("%-20s %d", execname, timestamp - this->t); 9 | } 10 | -------------------------------------------------------------------------------- /tests/dt015: -------------------------------------------------------------------------------- 1 | syscall::access:return 2 | /* /arg1 < 0/ */ 3 | { 4 | printf("arg0=%d\n", arg0); 5 | printf("arg1=%d\n", arg1); 6 | printf("ustack follows\n"); 7 | ustack(); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /restart: -------------------------------------------------------------------------------- 1 | VBoxManage controlvm "Ubuntu 10.04-64bit" poweroff 2 | sleep 1 3 | VBoxManage snapshot "Ubuntu 10.04-64bit" restore "Snapshot 1" 4 | sleep 1 5 | VBoxManage startvm "Ubuntu 10.04-64bit" 6 | -------------------------------------------------------------------------------- /scripts/stat.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::lstat*:entry, 4 | syscall::stat*:entry 5 | { 6 | printf("%d %s: %s %s\n", pid, execname, probefunc, copyinstr(arg0)); 7 | } 8 | ' 9 | -------------------------------------------------------------------------------- /tests/cr002: -------------------------------------------------------------------------------- 1 | dtrace -n ':::function-entry {printf("arg0=%x str='%s' arg1=%x:%s arg2=%s arg3=%d\n", 2 | (int) arg0, copyinstr(arg0), 3 | (int) arg1, copyinstr(arg1), 4 | copyinstr(arg2), 5 | arg3);}' 6 | -------------------------------------------------------------------------------- /tests/fasttrap/README: -------------------------------------------------------------------------------- 1 | Miscellaneous dummy/test/unit-test apps to help me debug 2 | the pid provider - especially specific instructions or scenarios 3 | in the pid provider. 4 | 5 | Nothing clever in here! 6 | -------------------------------------------------------------------------------- /linux/synch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Definitions of synchronization types. 3 | */ 4 | #define USYNC_THREAD 0x00 /* private to a process */ 5 | #define USYNC_PROCESS 0x01 /* shared by processes */ 6 | -------------------------------------------------------------------------------- /utils/find-dups: -------------------------------------------------------------------------------- 1 | grep ' [Tt] ' /proc/kallsyms | awk '{print $1}' | 2 | sort | uniq -c | grep -v ' 1 ' | 3 | while read cnt addr 4 | do 5 | echo "" 6 | echo "=== $addr" 7 | grep "$addr [Tt] " /proc/kallsyms 8 | done 9 | -------------------------------------------------------------------------------- /scripts/syscalls: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Syscalls by function/process 3 | echo "System-calls ordered by frequency. Press Ctrl-C to terminate and view." 4 | set -x 5 | dtrace -n 'syscall:::entry { @num[probefunc] = count(); }' 6 | -------------------------------------------------------------------------------- /.gdbinit: -------------------------------------------------------------------------------- 1 | set auto-load safe-path / 2 | set confirm no 3 | set history expansion 1 4 | dir libctf 5 | dir libdtrace 6 | dir libproc 7 | dir liblinux 8 | dir cmd/dtrace 9 | define z 10 | stepi 11 | x/i $pc 12 | end 13 | -------------------------------------------------------------------------------- /driver-2/Makefile: -------------------------------------------------------------------------------- 1 | # Hello-World example driver, to show using SDT 2 | # probes in the kernel. 3 | 4 | EXTRA_CFLAGS += -I$(M)/../../uts/common 5 | 6 | hworlddrv-objs := hworld.o 7 | 8 | obj-m := hworld.o 9 | 10 | -------------------------------------------------------------------------------- /utils/ustack.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | my $cnt = 0; 4 | 5 | while (1) { 6 | printf("PID: $$ cnt=$cnt\n"); 7 | mkdir("/etc/hosts", 0755); # dont do anything but attempt to. 8 | sleep(1); 9 | $cnt++; 10 | } 11 | -------------------------------------------------------------------------------- /driver-kmem/Makefile: -------------------------------------------------------------------------------- 1 | # Hello-World example driver, to show using SDT 2 | # probes in the kernel. 3 | 4 | EXTRA_CFLAGS += -I$(M)/../../uts/common 5 | 6 | kmemdrv-objs := dtrace_kmem.o 7 | 8 | obj-m := dtrace_kmem.o 9 | 10 | -------------------------------------------------------------------------------- /s/all: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n ' 3 | BEGIN { tstart = timestamp; x = 0; } 4 | syscall:::{x++;} 5 | syscall::: /timestamp - tstart > 1000 * 1000 * 1000/ { 6 | printf("%d", x); 7 | tstart = timestamp; 8 | }' 9 | 10 | -------------------------------------------------------------------------------- /scripts/fbt2: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Fbt calls 3 | echo "Function calls, including process name, ordered by frequency. " 4 | echo "Press Ctrl-C to quit" 5 | set +x 6 | dtrace -n 'fbt:::entry { @num[probefunc, execname] = count(); }' 7 | 8 | -------------------------------------------------------------------------------- /linux/sys/statvfs.h: -------------------------------------------------------------------------------- 1 | # if !defined(SYS_STATVFS_H) 2 | # define SYS_STATVFS_H 3 | 4 | # include "/usr/include/sys/statvfs.h" 5 | 6 | typedef struct statvfs64 statvfs_t; 7 | typedef struct statvfs statvfs32_t; 8 | 9 | # endif 10 | -------------------------------------------------------------------------------- /utils/opcodes: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # simple script to get probes by opcodes, assuming fbt_linux.c has 3 | # been compiled or loaded to generate opcode prefixed probes. 4 | grep fbt /tmp/probes | sed -e 's/^.* x//' -e 's/_.*$//' | sort | uniq -c 5 | -------------------------------------------------------------------------------- /scripts/fork.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::fork*:entry, 4 | syscall::vfork*:entry, 5 | syscall::clone*:entry 6 | { 7 | printf("%d %s: %s %s\n", pid, execname, probefunc, copyinstr(arg0)); 8 | } 9 | ' 10 | -------------------------------------------------------------------------------- /tests/probe: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | #pragma D option quiet 3 | 4 | BEGIN { 5 | printf("Target pid: %d\n", $target); 6 | } 7 | 8 | pid$target:::entry { 9 | printf("%s:%s:%s:%s\n", probeprov, probemod, probefunc, probename); 10 | } 11 | -------------------------------------------------------------------------------- /utils/execvp.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { char *argv[2]; 3 | int ret; 4 | 5 | sleep(5); 6 | printf("execing...\n"); 7 | argv[0] = "/bin/date"; 8 | argv[1] = 0; 9 | ret = execvp(argv[0], argv); 10 | printf("ret=%d\n", ret); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /s/z9: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n ' 3 | BEGIN { tstart = timestamp; self->x = 0; } 4 | syscall:::{self->x++;} 5 | syscall::: /timestamp - tstart > 1000 * 1000 * 1000/ { 6 | printf("%d", self->x); 7 | tstart = timestamp; 8 | }' 9 | 10 | -------------------------------------------------------------------------------- /scripts/remove.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::unlink*:entry, 4 | syscall::rmdir*:entry, 5 | syscall::remove*:entry 6 | { 7 | printf("%d %s: %s %s\n", pid, execname, probefunc, copyinstr(arg0)); 8 | } 9 | ' 10 | -------------------------------------------------------------------------------- /tests/dt020: -------------------------------------------------------------------------------- 1 | /* Detect SIGSEGV - supplied by sling@rotateright.com */ 2 | /* 2 Jul 2010 */ 3 | 4 | typedef struct { 5 | int foo; 6 | int bar; 7 | } foobar_t; 8 | 9 | BEGIN 10 | { 11 | printf("hello"); 12 | exit(0); 13 | } 14 | -------------------------------------------------------------------------------- /utils/fork.c: -------------------------------------------------------------------------------- 1 | // test dtrace -n ::clone: 2 | // which is invoked from fork. 3 | 4 | int main(int argc, char **argv) 5 | { 6 | int ret; 7 | sleep(5); 8 | printf("forking...\n"); 9 | ret = fork(); 10 | printf("ret=%d\n", ret); 11 | } 12 | -------------------------------------------------------------------------------- /tests/dt010: -------------------------------------------------------------------------------- 1 | syscall::open:entry 2 | { 3 | self->path = copyinstr(arg0); 4 | } 5 | 6 | syscall::open:return 7 | /self->path != NULL && arg1 == -1/ 8 | { 9 | printf("open for '%s' failed", self->path); 10 | ustack(); 11 | } 12 | -------------------------------------------------------------------------------- /scripts/syscalls2: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Syscalls by function/process 3 | echo "System-calls including processname, ordered by frequency. " 4 | echo "Press Ctrl-C to terminate and view." 5 | set +x 6 | dtrace -n 'syscall:::entry { @num[probefunc, execname] = count(); }' 7 | -------------------------------------------------------------------------------- /utils/notes: -------------------------------------------------------------------------------- 1 | #random cut/paste stuff - ignore this file. 2 | 3 | #dtrace -n "syscall:::entry/pid==\$target/{ustack();}" -p 8924 4 | dtrace -n "fbt::sys*:entry/pid==\$target/{ustack();}" -p 8924 5 | dtrace -n "fbt::sys_open*:entry/pid==\$target/{ustack();}" -p 8924 6 | -------------------------------------------------------------------------------- /tests/fbt-all: -------------------------------------------------------------------------------- 1 | /* Trace everything in fbt, but dont flood our output stream - so we 2 | can get some output without making system unresponsive. 3 | */ 4 | fbt:::entry 5 | { 6 | @[probefunc] = count(); 7 | } 8 | profile:::tick-1sec 9 | { 10 | printa(@); 11 | } 12 | -------------------------------------------------------------------------------- /tests/dt022: -------------------------------------------------------------------------------- 1 | /* Script to investigate a kernel panic 2 | Author: John Blanchard 3 | */ 4 | 5 | *::*socket*:entry 6 | 7 | /pid == 23738/ 8 | 9 | { 10 | 11 | /* if we use *socket*, it will cause kernel crash */ 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /linux/sys/sysmacros.h: -------------------------------------------------------------------------------- 1 | # if !defined NBBY 2 | # define NBBY 8 3 | # endif 4 | 5 | /* 6 | # if !defined(major) 7 | # define major(x) 0 8 | # endif 9 | # if !defined(minor) 10 | # define minor(x) 0 11 | # endif 12 | # if !defined(makedev) 13 | # define makedev(x, y) 0 14 | # endif 15 | */ 16 | -------------------------------------------------------------------------------- /utils/loop: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | while true 3 | do 4 | echo '' 5 | load 6 | cat /proc/dtrace/trace 7 | grep --color irq=1 /proc/dtrace/trace 8 | if [ $? != 1 ]; then 9 | break 10 | fi 11 | grep --color fail /proc/dtrace/trace 12 | if [ $? != 1 ]; then 13 | break 14 | fi 15 | done 16 | -------------------------------------------------------------------------------- /utils/getpid.c: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | int main() 4 | { 5 | int pid = getpid(); 6 | int p; 7 | 8 | printf("mypid=%d\n", pid); 9 | while (1) { 10 | if ((p = getpid(&p)) != pid) { 11 | printf("oops: pid=%d vs getpid=%d\n", pid, p); 12 | } 13 | time(NULL); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /scripts/pgfault: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | echo "Show page faults for processes" 3 | echo "Press Ctrl-C to quit" 4 | set +x 5 | cat <dts_necbs); 11 | } 12 | -------------------------------------------------------------------------------- /tools/cross-build/i386/gcc: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | cross_dir=`dirname $0` 3 | args=`echo $* | sed -e s/-m64/-m32/g -e "s/ -mcmodel=kernel//" -e "s!-include include/linux/autoconf.h!-include $cross_dir/include/linux/a.h!"` 4 | #echo gcc -m32 $args > /tmp/o 5 | exec gcc -m32 -DFORTIFY_SOURCE=0 -D_ILP32=1 -D__i386=1 $args 6 | -------------------------------------------------------------------------------- /scripts/nonexist.d: -------------------------------------------------------------------------------- 1 | #pragma D option quiet 2 | 3 | syscall::open:entry 4 | { 5 | self->filename = copyinstr(arg0); 6 | } 7 | syscall::open:return 8 | /arg0 < 0/ 9 | { 10 | /* printf("%s Failed open %x\n", execname, arg0);*/ 11 | printf("%d: %s : %s\n", 12 | pid, execname, 13 | self->filename); 14 | } 15 | -------------------------------------------------------------------------------- /utils/pd: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | if [ "$1" = "-n" ]; then 4 | n_flag=1 5 | shift; 6 | fi 7 | 8 | grep " $1" /tmp/probes | 9 | awk '{printf "%s:%s:%s:%s {}\n", $2, $3, $4, $5;}' | 10 | sort | 11 | #grep :fbt: | 12 | cat >/tmp/s 13 | cat /tmp/s 14 | if [ "$n_flag" = "" ]; then 15 | dtrace -s /tmp/s 16 | fi 17 | -------------------------------------------------------------------------------- /tools/cross-build/i386/include/linux/a.h: -------------------------------------------------------------------------------- 1 | #include 2 | #undef CONFIG_64BIT 3 | #undef CONFIG_X86_64 4 | #undef CONFIG_X86_64_SMP 5 | #define CONFIG_X86_32_SMP 1 6 | #define CONFIG_X86_32 1 7 | #define CONFIG_M386 8 | #define CONFIG_PAGE_OFFSET 0xC0000000 9 | #define CONFIG_ARCH_FLATMEM_ENABLE 1 10 | -------------------------------------------------------------------------------- /scripts/fbt3: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Fbt calls 3 | echo "Function calls, including process name, ordered by frequency. " 4 | echo "Press Ctrl-C to quit" 5 | set +x 6 | cat < 6 | 7 | -------------------------------------------------------------------------------- /s/README: -------------------------------------------------------------------------------- 1 | Set of one liners to help test specific system calls - those that 2 | cause problems with pt_regs and Linux kernel mutations. Feel free to 3 | use especially to validate on your OS. 4 | 5 | You can run build/sys{32,64} to test out most of these syscalls - some 6 | of them are rare, without the test utility. 7 | 8 | Paul Fox Feb 2015 9 | -------------------------------------------------------------------------------- /usdt/README: -------------------------------------------------------------------------------- 1 | Simple USDT examples, so we can start testing out USDT. 2 | 3 | Thanks to: 4 | 5 | http://blogs.sun.com/barts/entry/putting_user_defined_dtrace_probe 6 | 7 | which helped me get my head around this... 8 | 9 | And Adam Leventhal for some other links: 10 | 11 | http://blogs.sun.com/ahl/entry/user_land_tracing_gets_better 12 | -------------------------------------------------------------------------------- /doc/prov-instr.doc: -------------------------------------------------------------------------------- 1 | The 'instr' provider is similar to the FBT provider, but provides 2 | the ability to instrument probes on various interesting instructions 3 | in the kernel, specifically jump instructions. This can be used to 4 | monitor control flow and look for exceptional or common scenarios when 5 | trying to understand what happens dynamically in the kernel. 6 | -------------------------------------------------------------------------------- /libdtrace/stubs.c: -------------------------------------------------------------------------------- 1 | int 2 | gettaskid() 3 | { 4 | return 0; 5 | } 6 | int 7 | getprojid() 8 | { 9 | return 0; 10 | } 11 | int 12 | _lwp_kill(int tid, int sig) 13 | { 14 | return 0; 15 | } 16 | # if 0 17 | void * 18 | Paddr_to_map(void *p, unsigned long addr) 19 | { 20 | printf("stubs.c:Paddr_to_map called -- help!\n"); 21 | return 0; 22 | } 23 | # endif 24 | -------------------------------------------------------------------------------- /scripts/file.d: -------------------------------------------------------------------------------- 1 | dtrace -n ' 2 | #pragma D option quiet 3 | syscall::open*:entry, 4 | syscall::chdir*:entry, 5 | syscall::chmod*:entry, 6 | syscall::chown*:entry, 7 | syscall::unlink*:entry, 8 | syscall::rmdir*:entry, 9 | syscall::mkdir*:entry, 10 | syscall::remove*:entry 11 | { 12 | printf("%d %s: %s %s\n", pid, execname, probefunc, copyinstr(arg0)); 13 | } 14 | ' 15 | -------------------------------------------------------------------------------- /doc/prov-proc.doc: -------------------------------------------------------------------------------- 1 | The proc provider provides high level probes which relate to 2 | process creation, termination, and other common and interesting 3 | events. 4 | 5 | The following probes are defined: 6 | 7 | proc:::create New process has been created. 8 | proc:::exit Process is terminating. 9 | proc:::start New process has been created. 10 | -------------------------------------------------------------------------------- /linux/sys/rwlock.h: -------------------------------------------------------------------------------- 1 | #if !defined(RWLOCK_H_INCLUDE) 2 | # define RWLOCK_H_INCLUDE 3 | 4 | typedef enum { 5 | RW_WRITER, 6 | RW_READER 7 | } krw_t; 8 | 9 | typedef struct krwlock_t { 10 | mutex_t k_mutex; 11 | int k_writer; 12 | int k_readers; 13 | } krwlock_t; 14 | 15 | void rw_enter(krwlock_t *, krw_t); 16 | void rw_exit(krwlock_t *); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /utils/makefile: -------------------------------------------------------------------------------- 1 | OBJDIR = ../build 2 | CFLAGS = -g 3 | 4 | all: $(OBJDIR)/access $(OBJDIR)/kmem $(OBJDIR)/mknod $(OBJDIR)/pread 5 | 6 | $(OBJDIR)/access: access.c 7 | $(CC) $(CFLAGS) -o $@ $< 8 | $(OBJDIR)/kmem: kmem.c 9 | $(CC) $(CFLAGS) -o $@ $< 10 | $(OBJDIR)/mknod: mknod.c 11 | $(CC) $(CFLAGS) -o $@ $< 12 | $(OBJDIR)/pread: pread.c 13 | $(CC) $(CFLAGS) -o $@ $< 14 | 15 | -------------------------------------------------------------------------------- /scripts/mkdir.d: -------------------------------------------------------------------------------- 1 | #pragma D option quiet 2 | 3 | syscall::mkdir:entry 4 | { 5 | self->filename = copyinstr(arg0); 6 | } 7 | syscall::mkdir:return 8 | /arg0 < 0/ 9 | { 10 | printf("%d: %s mkdir %s error %d\n", pid, execname, self->filename, errno) 11 | } 12 | syscall::mkdir:return 13 | /arg0 == 0/ 14 | { 15 | printf("%d: %s mkdir %s\n", pid, execname, self->filename) 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /utils/access.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | 4 | int main() 5 | { int ret; 6 | int i; 7 | char buf[1024]; 8 | memset(buf, 'a', sizeof buf); 9 | for (i = 0; ; i++) { 10 | printf("pid=%d %d: doing access\n", getpid(), i); 11 | if ((ret = access("/tmp/xxxx", 2)) < 0) { 12 | printf("access ret=%d ", ret); 13 | perror(""); 14 | } 15 | sleep(5); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tests/fasttrap/ft3.c: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | void fred() 4 | { 5 | printf("this is fred\n"); 6 | } 7 | void (*func) = fred; 8 | int main(int argc, char **argv) 9 | { char buf[BUFSIZ]; 10 | 11 | printf("pid %d ready: ", getpid()); 12 | fgets(buf, sizeof buf, stdin); 13 | asm("mov $fred,%edi\n"); 14 | asm("call *%edi\n"); 15 | 16 | asm("mov $func,%edx\n"); 17 | asm("call *(%edx)\n"); 18 | } 19 | -------------------------------------------------------------------------------- /tests/dt023: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | 4 | #pragma options quiet 5 | typedef struct buf_t { 6 | int a1, a2, a3, a4, a5, a6; 7 | } buf_t; 8 | 9 | io::start: 10 | { 11 | 12 | printf("%s\narg0=%p %p %p %p %p\n", execname, arg0, arg1, arg2, arg3, arg4); 13 | printf("x=%x %x %x %x\n", 14 | ((buf_t *) arg0)->a1, 15 | ((buf_t *) arg0)->a2, 16 | ((buf_t *) arg0)->a3, 17 | ((buf_t *) arg0)->a4); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /.ignore: -------------------------------------------------------------------------------- 1 | ./.git 2 | ./build* 3 | checksum.lst 4 | *.so 5 | *.o 6 | ./drivers/dtrace/syscalls-x86-64.tbl 7 | ./drivers/dtrace/syscalls-x86.tbl 8 | ./drivers/dtrace/Module.symvers 9 | ./drivers/dtrace/Module.markers 10 | ./libdtrace/dt_grammar.h 11 | ./libdtrace/dt_lex.c 12 | ./utils/access 13 | ./utils/eh 14 | ./utils/iopl 15 | ./utils/mknod 16 | ./utils/pread 17 | ./utils/ptrace 18 | ./utils/ptrace2 19 | ./utils/thread 20 | -------------------------------------------------------------------------------- /linux/sys/proc.h: -------------------------------------------------------------------------------- 1 | #define SSLEEP 1 /* awaiting an event */ 2 | #define SRUN 2 /* running */ 3 | #define SZOMB 3 /* process terminated but not waited for */ 4 | #define SSTOP 4 /* process stopped by debugger */ 5 | #define SIDL 5 /* intermediate state in process creation */ 6 | #define SONPROC 6 /* process is being run on a processor */ 7 | 8 | -------------------------------------------------------------------------------- /utils/iopl.c: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | void thread_func(void *arg) 4 | { int ret = iopl(3); 5 | 6 | printf("thread iopl=%d\n", ret); 7 | 8 | } 9 | int main(int argc, char **argv) 10 | { 11 | int pl = argc == 1 ? 3 : atoi(argv[1]); 12 | int ret; 13 | pthread_t thr; 14 | 15 | pthread_create(&thr, NULL, thread_func, NULL); 16 | 17 | ret = iopl(pl); 18 | printf("iopl(%d) = %d\n", pl, ret); 19 | pause(); 20 | } 21 | -------------------------------------------------------------------------------- /utils/diffprobes: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # compare the output of dtrace -l, because we keep getting random 4 | # differences and I need to debug this. 5 | 6 | sed -e 's/^ *[0-9][0-9]* *//' < /tmp/probes.current | awk '{printf "%s:%s:%s\n", $1, $2, $3; }' | sort > /tmp/current 7 | sed -e 's/^ *[0-9][0-9]* *//' < /tmp/probes.prev | awk '{printf "%s:%s:%s\n", $1, $2, $3; }' | sort > /tmp/prev 8 | 9 | sdiff /tmp/current /tmp/prev 10 | 11 | -------------------------------------------------------------------------------- /tests/fasttrap/ft5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | volatile unsigned cnt; 5 | int tick; 6 | 7 | void alarm_handler() 8 | { 9 | printf("%d tick: %2d %u\n", getpid(), tick++, cnt); 10 | } 11 | int main(int argc, char **argv) 12 | { 13 | while (1) { 14 | int old_tick = tick; 15 | signal(SIGALRM, alarm_handler); 16 | alarm(1); 17 | for (cnt = 0; ; cnt++) { 18 | if (tick != old_tick) 19 | break; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /linux/zone.h: -------------------------------------------------------------------------------- 1 | # if !defined(_ZONE_H) 2 | # define _ZONE_H 3 | /* 4 | * The zone support infrastructure uses the zone name as a component 5 | * of unix domain (AF_UNIX) sockets, which are limited to 108 characters 6 | * in length, so ZONENAME_MAX is limited by that. 7 | */ 8 | #define ZONENAME_MAX 64 9 | #define ZONE_ATTR_ROOT 1 10 | 11 | typedef struct { 12 | int zone_id; 13 | } zone_t; 14 | typedef int zoneid_t; 15 | 16 | # endif 17 | -------------------------------------------------------------------------------- /scripts/syscalls3: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Syscalls by function/process 3 | echo "System-calls including processname, ordered by frequency. " 4 | echo "Press Ctrl-C to terminate and view." 5 | set +x 6 | cat < 2 | # include 3 | 4 | int main() 5 | { 6 | int uid = getuid(); 7 | int p; 8 | unsigned long n = 0; 9 | time_t t = time(NULL); 10 | 11 | printf("myuid=%d\n", uid); 12 | while (1) { 13 | if ((p = getuid()) != uid) { 14 | printf("oops: uid=%d vs getuid=%d\n", uid, p); 15 | } 16 | n++; 17 | if (t != time(NULL)) { 18 | printf("counted: %lu\n", n); 19 | n = 0; 20 | t = time(NULL); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /utils/idt.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | static char buf[64]; 6 | 7 | int main() 8 | { void *idtr; 9 | int fd, ret; 10 | 11 | asm ("sidt %0" : "=m" (idtr)); 12 | idtr = (unsigned long) idtr & ~0xfff; 13 | 14 | printf("idt=%p\n", idtr); 15 | fd = open64("/dev/kmem", O_RDWR); 16 | lseek64(fd, idtr, SEEK_SET); 17 | ret = read(fd, buf, sizeof buf); 18 | if (ret < 0) { 19 | perror("read"); 20 | exit(1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cmd/intrstat/i386/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | #ident "@(#)Makefile 1.1 03/09/02 SMI" 10 | 11 | include ../Makefile.com 12 | 13 | install: all $(ROOTUSRSBINPROG32) 14 | -------------------------------------------------------------------------------- /libproc/common/pisadep.c: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Trampoline to correct C code. */ 3 | /**********************************************************************/ 4 | # if defined(__i386) 5 | # include "../i386/Pisadep.c" 6 | # elif defined(__amd64) 7 | # include "../amd64/Pisadep.c" 8 | # elif defined(__arm__) 9 | # include "../arm/Pisadep.c" 10 | # else 11 | # error "pisdaep.c: cannot compile for this CPU" 12 | # endif 13 | -------------------------------------------------------------------------------- /linux/sys/pset.h: -------------------------------------------------------------------------------- 1 | /* system call subcodes */ 2 | #define PSET_CREATE 0 3 | #define PSET_DESTROY 1 4 | #define PSET_ASSIGN 2 5 | #define PSET_INFO 3 6 | #define PSET_BIND 4 7 | #define PSET_GETLOADAVG 5 8 | #define PSET_LIST 6 9 | #define PSET_SETATTR 7 10 | #define PSET_GETATTR 8 11 | #define PSET_ASSIGN_FORCED 9 12 | 13 | /* attribute bits */ 14 | #define PSET_NOESCAPE 0x0001 15 | -------------------------------------------------------------------------------- /linux/sys/sysi86.h: -------------------------------------------------------------------------------- 1 | /* 2 | * XX64 Do we need to support this for 64-bit apps? 3 | * 4 | * request structure passed by user 5 | */ 6 | struct ssd { 7 | unsigned int sel; /* descriptor selector */ 8 | unsigned int bo; /* segment base or gate offset */ 9 | unsigned int ls; /* segment limit or gate selector */ 10 | unsigned int acc1; /* access byte 5 */ 11 | unsigned int acc2; /* access bits in byte 6 or gate count */ 12 | }; 13 | -------------------------------------------------------------------------------- /libctf/llib-lctf: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License, Version 1.0 only. 6 | * See the file usr/src/LICENSING.NOTICE in this distribution or 7 | * http://www.opensolaris.org/license/ for details. 8 | */ 9 | 10 | #pragma ident "@(#)llib-lctf 1.1 01/04/10 SMI" 11 | 12 | /*LINTLIBRARY*/ 13 | /*PROTOLIB1*/ 14 | 15 | #include 16 | -------------------------------------------------------------------------------- /libproc/i386/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | # ident "@(#)Makefile 1.3 04/01/28 SMI" 10 | # 11 | 12 | include ../Makefile.com 13 | 14 | install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) 15 | -------------------------------------------------------------------------------- /libproc/sparc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | #ident "@(#)Makefile 1.3 04/01/28 SMI" 10 | # 11 | 12 | include ../Makefile.com 13 | 14 | install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) 15 | -------------------------------------------------------------------------------- /cmd/intrstat/sparcv9/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | #ident "@(#)Makefile 1.1 03/09/02 SMI" 10 | 11 | include ../Makefile.com 12 | include ../../Makefile.cmd.64 13 | 14 | install: all $(ROOTUSRSBINPROG64) 15 | -------------------------------------------------------------------------------- /cmd/intrstat/amd64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | # ident "@(#)Makefile 1.1 04/09/28 SMI" 10 | # 11 | 12 | include ../Makefile.com 13 | include ../../Makefile.cmd.64 14 | 15 | install: all $(ROOTUSRSBINPROG64) 16 | -------------------------------------------------------------------------------- /utils/doit2: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | # simple script for testing dtrace -c: 3 | # dtrace -n 'syscall:::/pid==$target/{printf("%d",pid);}' -c utils/doit2 4 | print "This is doit2 -- PID $$\n"; 5 | $| = 1; 6 | my $x = 0; 7 | while (1) { 8 | open(FH, "/etc/nothing"); 9 | next; 10 | print "."; 11 | if ($x++ > 50) { 12 | $x = 0; 13 | print "\n"; 14 | } 15 | # for (my $i = 0; $i < 100; $i++) { 16 | # mkdir("/"); 17 | # } 18 | open(FH, "/etc/hosts"); 19 | sleep(1); 20 | } 21 | -------------------------------------------------------------------------------- /doc/README.first: -------------------------------------------------------------------------------- 1 | If you are building this, please make sure your system has 2 | the required dependency packages installed. There are presently 3 | two scripts you can use or try: 4 | 5 | tools/get-deps.pl Ubuntu or other apt-get based systems 6 | tools/get-deps-fedora.pl Fedora Core, or other yum based install systems 7 | 8 | Run these as root. Ubuntu 11.x/32 based systems will need to run the 9 | get-deps as this fixes an install issue with missing /usr/include/sys 10 | directory. 11 | ============================================= Paul Fox Dec 2012 12 | -------------------------------------------------------------------------------- /liblinux/cpu_status.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | cpu_online(int cpu) 5 | { char buf[BUFSIZ]; 6 | char *cp; 7 | FILE *fp; 8 | int n; 9 | 10 | if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) 11 | return -1; 12 | while (fgets(buf, sizeof buf, fp)) { 13 | if (strncmp(buf, "processor\t:", 11) != 0) 14 | continue; 15 | cp = buf + 12; 16 | n = atoi(cp); 17 | if (n == cpu) { 18 | fclose(fp); 19 | return 1; 20 | } 21 | if (n >= cpu) { 22 | fclose(fp); 23 | return -1; 24 | } 25 | } 26 | fclose(fp); 27 | return -1; 28 | } 29 | -------------------------------------------------------------------------------- /libproc/amd64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | # ident "@(#)Makefile 1.2 04/09/28 SMI" 10 | # 11 | 12 | include ../Makefile.com 13 | include ../../Makefile.lib.64 14 | 15 | CPPFLAGS += -D_SYSCALL32 16 | 17 | install: all $(ROOTLIBS64) $(ROOTLINKS64) 18 | -------------------------------------------------------------------------------- /s/z2: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n ' 3 | BEGIN { 4 | cnt = 0; 5 | tstart = timestamp; 6 | } 7 | syscall::: { 8 | this->pid = pid; 9 | this->ppid = ppid; 10 | this->execname = execname; 11 | this->arg0 = stringof(arg0); 12 | this->arg1 = stringof(arg1); 13 | this->arg2 = stringof(arg2); 14 | cnt++; 15 | } 16 | syscall::: /timestamp - tstart > 500 * 1000 * 1000 * 1000 / {exit(0);} 17 | tick-1ms /timestamp - tstart > 500 * 1000 * 1000 * 1000 / {exit(0);} 18 | tick-1s { printf("count so far: %d", cnt); } 19 | tick-500s { exit(0); } 20 | ' 21 | -------------------------------------------------------------------------------- /libproc/sparcv9/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | # ident "@(#)Makefile 1.4 04/01/28 SMI" 10 | # 11 | 12 | include ../Makefile.com 13 | include ../../Makefile.lib.64 14 | 15 | CPPFLAGS += -D_SYSCALL32 16 | 17 | install: all $(ROOTLIBS64) $(ROOTLINKS64) 18 | -------------------------------------------------------------------------------- /s/z4: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n ' 3 | BEGIN { 4 | cnt = 0; 5 | tstart = timestamp; 6 | } 7 | syscall::chdir: { 8 | this->pid = pid; 9 | this->ppid = ppid; 10 | this->execname = execname; 11 | this->arg0 = stringof(arg0); 12 | this->arg1 = stringof(arg1); 13 | this->arg2 = stringof(arg2); 14 | cnt++; 15 | } 16 | /* syscall::: /timestamp - tstart > 500 * 1000 * 1000 * 1000 / {exit(0);}*/ 17 | /* tick-1ms /timestamp - tstart > 500 * 1000 * 1000 * 1000 / {exit(0);}*/ 18 | tick-1s { printf("count so far: %d", cnt); } 19 | tick-500s { exit(0); } 20 | ' 21 | -------------------------------------------------------------------------------- /linux/proc_service.h: -------------------------------------------------------------------------------- 1 | typedef enum { 2 | PS_OK, /* generic "call succeeded" */ 3 | PS_ERR, /* generic error */ 4 | PS_BADPID, /* bad process handle */ 5 | PS_BADLID, /* bad lwp identifier */ 6 | PS_BADADDR, /* bad address */ 7 | PS_NOSYM, /* p_lookup() could not find given symbol */ 8 | PS_NOFREGS /* FPU register set not available for given lwp */ 9 | } ps_err_e; 10 | 11 | #ifdef _LP64 12 | typedef Elf64_Sym ps_sym_t; 13 | #else 14 | typedef Elf32_Sym ps_sym_t; 15 | #endif 16 | -------------------------------------------------------------------------------- /tools/raspberrypi.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # My RaspberryPi/wheeze seemed to be missing key /usr/include dirs 4 | # so patch them if we need to. 5 | 6 | # 19-Feb-2013 PDF New file 7 | 8 | if [ ! -d /usr/include/asm ]; then 9 | echo Creating /usr/include/asm 10 | ln -s arm-linux-gnueabihf/asm /usr/include/asm 11 | fi 12 | if [ ! -d /usr/include/bits ]; then 13 | echo Creating /usr/include/bits 14 | ln -s arm-linux-gnueabihf/bits /usr/include/bits 15 | fi 16 | if [ ! -d /usr/include/gnu ]; then 17 | echo Creating /usr/include/gnu 18 | ln -s arm-linux-gnueabihf/gnu /usr/include/gnu 19 | fi 20 | 21 | -------------------------------------------------------------------------------- /driver/README: -------------------------------------------------------------------------------- 1 | This directory contains the kernel code. We have a number 2 | of drivers here, corresponding to the Solaris dtrace /dev 3 | area. Major files are Solaris source code, with appropriate (small) 4 | changes for working under Linux. 5 | 6 | Other files, are linux drop-ins to complete the circle of 7 | bits needed to create a solaris driver. 8 | 9 | We no longer build in the source tree, since Linux kernel builder 10 | deposits lots of build output files here, but we build in the 11 | build-`uname -r`/ tree instead, so that output files are 12 | segregated from the input sources. 13 | 14 | P Fox Feb 2009 15 | -------------------------------------------------------------------------------- /tests/open.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | use FileHandle; 4 | use IO::File; 5 | use POSIX; 6 | 7 | my $n = 0; 8 | my $err = 0; 9 | my $lnerr = 0; 10 | my $t = time(); 11 | while (1) { 12 | if (time() >= $t + 5) { 13 | print strftime("%H:%M:%S", localtime), " opens=$n err=$err lnerr=$lnerr\n"; 14 | $t = time(); 15 | } 16 | my $fh = new FileHandle("/etc/hosts"); 17 | $n++; 18 | my $str = <$fh>; 19 | if (!$str) { 20 | print "error reading line\n"; 21 | $lnerr++; 22 | } 23 | next if $fh; 24 | $err++; 25 | print strftime("%H:%M:%S", localtime), " $n/$err/$lnerr failed to open /etc/hosts -- $!\n"; 26 | } 27 | -------------------------------------------------------------------------------- /utils/mknod.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | int main() 6 | { int ret; 7 | int i; 8 | 9 | /***********************************************/ 10 | /* Strange libc bug here -- remove the */ 11 | /* getpid and watch the first mknod() fail */ 12 | /* - not because of EEXIST, but because it */ 13 | /* is never actually executed! */ 14 | /***********************************************/ 15 | getpid(); 16 | for (i = 0; ; i++) { 17 | if (mknod("xxx", 0644, 0) < 0) { 18 | if (errno != EEXIST) 19 | perror("mknod(xxx)"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cmd/instr/makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-g -W $(PTR32) $(BUILD_BITS) 2 | BINDIR=../../$(BUILD_DIR) 3 | 4 | all: $(BINDIR)/instr 5 | @/bin/true 6 | 7 | ###################################################################### 8 | # Bit of a mess below - we want libelf, but some older distros # 9 | # may not have it or we are on 64b kernel wanting to cross build # 10 | # or vice versa. # 11 | ###################################################################### 12 | $(BINDIR)/instr: instr.c 13 | $(CC) -DUSERMODE -Dprintk=printf -DDIS_TEXT -I../../driver \ 14 | -o $(BINDIR)/instr instr.c ../../driver/instr_size.c ../../driver/dis_tables.c 15 | -------------------------------------------------------------------------------- /usdt/cpp/simple.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include "simple_probes.h" 3 | 4 | void fred(void); 5 | 6 | int main(int argc, char **argv) 7 | { 8 | /***********************************************/ 9 | /* Invoke shlib function. */ 10 | /***********************************************/ 11 | fred(); 12 | 13 | while (1) { 14 | printf("here on line %d\n", __LINE__); 15 | SIMPLE_SAW_LINE(0x1234); 16 | printf("here on line %d\n", __LINE__); 17 | SIMPLE_SAW_WORD(0x87654321); 18 | printf("here on line %d\n", __LINE__); 19 | SIMPLE_SAW_WORD(0xdeadbeef); 20 | printf("here on line %d\n", __LINE__); 21 | sleep(1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /driver/linux_pure.c: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* This file contains pure linux stuff - no #defines or other */ 3 | /* things which complicate us with the rest of the dtrace code. */ 4 | /**********************************************************************/ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | char * 16 | linux_get_proc_comm(void) 17 | { 18 | return current->comm; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /s/z3: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n ' 3 | BEGIN { 4 | cnt = 0; 5 | tstart = timestamp; 6 | } 7 | syscall::: { 8 | this->pid = pid; 9 | this->ppid = ppid; 10 | this->execname = execname; 11 | this->arg0 = stringof(arg0); 12 | this->arg1 = stringof(arg1); 13 | this->arg2 = stringof(arg2); 14 | cnt++; 15 | } 16 | /* syscall::: /tstart && timestamp - tstart > 500 * 1000 * 1000 * 1000 / {printf("done1 %d %d\n", timestamp - tstart, tstart); exit(0);}*/ 17 | tick-1ms /tstart && timestamp - tstart > 500 * 1000 * 1000 * 1000 / {printf("done2\n"); exit(0);} 18 | tick-1s { printf("count so far: %d", cnt); } 19 | tick-500s { exit(0); } 20 | ' 21 | -------------------------------------------------------------------------------- /cmd/ctfconvert/linux.h: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Simple wrapper to shield from some Linux isms. */ 3 | /**********************************************************************/ 4 | 5 | # if !defined(LINUX_H_INCLUDE) 6 | # define LINUX_H_INCLUDE 7 | 8 | #include 9 | #include 10 | 11 | # if HAVE_LIB_LIBDW 12 | # define dwarf_dealloc(a, b, c) 13 | # define dwarf_finish(a, b) dwarf_end(a) 14 | # define dwarf_next_cu_header(dw, hdrlen, vers, off, addrsz, nxthdr, err) \ 15 | dwarf_nextcu(dw, off, nxthdr, addrsz, hdrlen, off, addrsz) 16 | 17 | # endif 18 | 19 | # endif 20 | 21 | -------------------------------------------------------------------------------- /etc/linux.d: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Definitions for the Linux platform. */ 3 | /* $Header: Last edited: 06-Aug-2010 1.1 $ */ 4 | /**********************************************************************/ 5 | 6 | /**********************************************************************/ 7 | /* Normally this would be in the CTF ELF section of the kernel, */ 8 | /* but we cannot do that, but we can do it here instead. Allows */ 9 | /* use of "uid" in probe functions. */ 10 | /**********************************************************************/ 11 | typedef int uid_t; 12 | 13 | -------------------------------------------------------------------------------- /libdtrace/dt_linux.h: -------------------------------------------------------------------------------- 1 | #if !defined(dt_linux_h_INCLUDE) 2 | #define dt_linux_h_INCLUDE 3 | 4 | #if defined(_LP64) 5 | # define BITS_PER_LONG 64 6 | # define BITS_LOG2_LONG 6 7 | #else 8 | # define BITS_PER_LONG 32 9 | # define BITS_LOG2_LONG 5 10 | #endif 11 | #define BT_ULMASK ((1 << BITS_LOG2_LONG) - 1) 12 | #define BT_ULSHIFT BITS_LOG2_LONG 13 | 14 | #define BT_TEST(bitmap, bitindex) \ 15 | ((bitmap)[(bitindex) >> BITS_LOG2_LONG] & (1 << ((bitindex) & (BITS_PER_LONG-1))) ? 1 : 0) 16 | 17 | #define strdupa(str) ({int len = strlen(str) + 1; \ 18 | char *cp = alloca(len); \ 19 | strcpy(cp, str); \ 20 | cp; \ 21 | }) 22 | 23 | #endif /* !defined(dt_linux_h_INCLUDE) */ 24 | -------------------------------------------------------------------------------- /scripts/bkl.d: -------------------------------------------------------------------------------- 1 | /* Script to monitor calls to the BKL - Big Kernel Lock. */ 2 | 3 | #pragma D option quiet 4 | int waiting, tcnt; 5 | long time_start; 6 | long time_tot; 7 | 8 | fbt::lock_kernel:entry 9 | { 10 | time_start = timestamp; 11 | waiting++; 12 | tcnt++; 13 | @num[execname] = count(); 14 | } 15 | fbt::unlock_kernel:entry 16 | { 17 | time_tot += waiting ? timestamp - time_start : 0; 18 | waiting > 0 ? waiting-- : 0; 19 | } 20 | tick-1sec 21 | { 22 | printf("Locks: %4d Total: %4d Time/per lock: %4dus Lock time: %5dus\n", 23 | waiting, tcnt, time_tot / tcnt, time_tot); 24 | printa(@num); 25 | clear(@num); 26 | } 27 | END { 28 | printf("Locks acquired: %d\n", tcnt); 29 | } 30 | -------------------------------------------------------------------------------- /driver/libc.c: -------------------------------------------------------------------------------- 1 | #define NULL 0 2 | 3 | int 4 | libc_strcmp(const char *p1, const char *p2) 5 | { 6 | while (1) { 7 | int ch1 = *p1++; 8 | int ch2 = *p2++; 9 | int ret = ch2 - ch1; 10 | if (ret == 0 && ch1 == 0) 11 | return 0; 12 | if (ret) 13 | return ret; 14 | } 15 | } 16 | int 17 | libc_strlen(const char *str) 18 | { int len = 0; 19 | 20 | while (*str++) 21 | len++; 22 | return len; 23 | } 24 | int 25 | libc_strncmp(const char *s1, const char *s2, int len) 26 | { 27 | int c1, c2; 28 | 29 | if (s1 == s2 || len == 0) 30 | return (0); 31 | 32 | while (len > 0) { 33 | c1 = *s1++; 34 | c2 = *s2++; 35 | if (c1 != c2) 36 | return c1 - c2; 37 | len--; 38 | } 39 | 40 | return (0); 41 | } 42 | -------------------------------------------------------------------------------- /tests/fbt: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # simple script to work with one fbt function at a time. 3 | 4 | #func=${1:-ext3_free_inode} 5 | func=${1:-ipt_local_out_hook} 6 | 7 | mkupdate 8 | make all || exit 1 9 | load -here 10 | rm -rf /tmp/x 11 | sync 12 | echo Testing: $func 13 | case $func in 14 | ext3_mkdir) 15 | dtrace -n ::$func: & sleep 2 16 | echo about to mkdir /tmp/x 17 | mkdir /tmp/x 18 | ;; 19 | ext3_free_inode) 20 | dtrace -n ::$func: & sleep 2 21 | echo creating file 22 | touch /tmp/file 23 | rm /tmp/file 24 | ;; 25 | ipt_local_out_hook) 26 | # SUB $12,ESP -- special case 27 | dtrace -n "fbt::$func:entry { @[probefunc] = count(); } 28 | profile:::tick-1sec { exit(0); } 29 | " 30 | ;; 31 | esac 32 | -------------------------------------------------------------------------------- /tools/get-deps-fedora.sh: -------------------------------------------------------------------------------- 1 | # Packages we need under Fedora 2 | # yum provides 3 | # yum list 4 | yum install \ 5 | binutils-devel \ 6 | bison \ 7 | crash \ 8 | elfutils-devel \ 9 | elfutils-libelf-devel \ 10 | flex \ 11 | gcc \ 12 | glibc-devel \ 13 | glibc-devel.i686 \ 14 | kernel-devel \ 15 | libdwarf \ 16 | libdwarf-devel \ 17 | libdwarf-static \ 18 | libgcc.i686 \ 19 | make \ 20 | perl \ 21 | zlib-devel 22 | 23 | # Optional: 24 | # openssh-clients 25 | 26 | #binutils-devel 27 | #elfutils-libelf-devel 28 | #kernel-devel 29 | #libdwarf 30 | #libdwarf-devel 31 | #zlib-devel 32 | # yumdownloader --source kernel 33 | # yum install rpmdevtools yum-utils 34 | # http://fedoraproject.org/wiki/Building_a_custom_kernel 35 | -------------------------------------------------------------------------------- /tests/makefile: -------------------------------------------------------------------------------- 1 | BINDIR=../$(BUILD_DIR) 2 | 3 | ###################################################################### 4 | # Build useful test binaries. We may be a 64b host but not 32b # 5 | # dev system. We dont care that much whether we get both # 6 | # binaries. More for my benefit. # 7 | ###################################################################### 8 | all: 9 | case `uname -m` in \ 10 | x86_64) \ 11 | $(CC) -m64 -g -o $(BINDIR)/sys64 syscalls.c ; \ 12 | $(CC) -m32 -g -o $(BINDIR)/sys32 syscalls.c || true ; \ 13 | ;; \ 14 | i686) \ 15 | $(CC) -m32 -g -o $(BINDIR)/sys32 syscalls.c ; \ 16 | ;; \ 17 | arm*) \ 18 | $(CC) -g -o $(BINDIR)/sys32 syscalls.c ; \ 19 | ;; \ 20 | esac 21 | 22 | -------------------------------------------------------------------------------- /liblinux/makefile: -------------------------------------------------------------------------------- 1 | ARFLAGS=Urv 2 | CC=gcc -g $(BUILD_BITS) 3 | CPPFLAGS += -I../libproc/common \ 4 | -I../common/ctf \ 5 | -I../linux \ 6 | -I../lib/libproc/common \ 7 | -I../libctf \ 8 | -I../uts/common \ 9 | -DCTF_OLD_VERSIONS $(PTR32) 10 | CPPFLAGS += -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 11 | 12 | BINDIR = ../$(BUILD_DIR) 13 | LIB = $(BINDIR)/liblinux.a 14 | 15 | all: $(LIB) 16 | @/bin/true 17 | 18 | $(LIB): \ 19 | $(LIB)(cpu_status.o) \ 20 | $(LIB)(getopt.o) \ 21 | $(LIB)(gmatch.o) \ 22 | $(LIB)(proc.o) \ 23 | $(LIB)(proc2.o) \ 24 | $(LIB)(proc_create.o) \ 25 | $(LIB)(proc_names.o) \ 26 | $(LIB)(proc_util.o) \ 27 | $(LIB)(strlcpy.o) 28 | 29 | 30 | # $(LIB)(Psymtab.o) \ 31 | # $(LIB)(Putil.o) \ 32 | 33 | clean: 34 | -rm -f *.o *.a 35 | 36 | -------------------------------------------------------------------------------- /driver/proc_compat.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * proc compat with kernel older 2.6.18 (Centos 5.5) 4 | */ 5 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18) 6 | inline struct proc_dir_entry* proc_create_data( 7 | const char *name, umode_t mode, struct proc_dir_entry *parent, 8 | const struct file_operations *proc_fops, void *data) 9 | { 10 | struct proc_dir_entry *ent = create_proc_entry(name, mode, parent); 11 | if (ent != NULL) { 12 | ent->proc_fops = proc_fops; 13 | ent->data = data; 14 | } 15 | return ent; 16 | } 17 | 18 | static inline struct proc_dir_entry *proc_create( 19 | const char *name, umode_t mode, struct proc_dir_entry *parent, 20 | const struct file_operations *proc_fops) 21 | { 22 | return proc_create_data(name, mode, parent, proc_fops, NULL); 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libdtrace/i386/dt_asmsubr.s: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License, Version 1.0 only. 6 | * See the file usr/src/LICENSING.NOTICE in this distribution or 7 | * http://www.opensolaris.org/license/ for details. 8 | */ 9 | 10 | #pragma ident "@(#)dt_asmsubr.s 1.1 04/03/01 SMI" 11 | 12 | #include 13 | #include 14 | 15 | #ifdef lint 16 | 17 | #include 18 | 19 | /*ARGSUSED*/ 20 | int 21 | dtrace_probe(uintptr_t arg0, ...) 22 | { return (0); } 23 | 24 | #else 25 | 26 | ENTRY(dtrace_probe) 27 | int $T_DTRACE_PROBE 28 | xorl %eax, %eax 29 | ret 30 | SET_SIZE(dtrace_probe) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /tests/fasttrap/ft6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | volatile int cnt; 6 | 7 | void usr1_handler() 8 | { 9 | cnt++; 10 | } 11 | int main(int argc, char **argv) 12 | { int pid; 13 | time_t t0 = time(NULL); 14 | 15 | signal(SIGUSR1, usr1_handler); 16 | if ((pid = fork()) == 0) { 17 | /***********************************************/ 18 | /* Child gets the machine gun. */ 19 | /***********************************************/ 20 | while (1) { 21 | int ret = kill(pid, SIGUSR1); 22 | if (ret < 0) 23 | exit(0); 24 | } 25 | } 26 | while (1) { 27 | time_t t1 = time(NULL); 28 | char buf[BUFSIZ]; 29 | 30 | if (t1 != t0) { 31 | printf("%d: count=%d\n", getpid(), cnt); 32 | cnt = 0; 33 | t0 = t1; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /utils/kmem.c: -------------------------------------------------------------------------------- 1 | #define _LARGEFILE64_SOURCE 2 | 3 | # include 4 | # include 5 | # include 6 | # include 7 | # include 8 | 9 | int main(int argc, char **argv) 10 | { 11 | off64_t addr; 12 | char buf[4096]; 13 | int n, ret; 14 | int fd; 15 | char *device = "/dev/kmem"; 16 | 17 | sscanf(argv[1], "%llx", &addr); 18 | if (argc > 2) { 19 | device = argv[2]; 20 | } 21 | printf("addr: %llx\n", addr); 22 | 23 | fd = open64(device, O_RDONLY | O_LARGEFILE); 24 | if (fd < 0) { 25 | perror(device); 26 | exit(1); 27 | } 28 | if (lseek64(fd, addr, SEEK_SET) == -1) { 29 | perror("lseek64"); 30 | exit(1); 31 | } 32 | n = read(fd, buf, sizeof buf); 33 | printf("n=%d\n", n); 34 | if (n < 0) 35 | perror("read"); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /linux/sys/vmem.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_VMEM_H 2 | #define _SYS_VMEM_H 3 | 4 | //# ident "@(#)vmem.h 1.14 07/05/11 SMI" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | 11 | /* 12 | * Per-allocation flags 13 | */ 14 | #define VM_SLEEP 0x00000000 /* same as KM_SLEEP */ 15 | #define VM_NOSLEEP 0x00000001 /* same as KM_NOSLEEP */ 16 | #define VM_PANIC 0x00000002 /* same as KM_PANIC */ 17 | #define VM_PUSHPAGE 0x00000004 /* same as KM_PUSHPAGE */ 18 | #define VM_KMFLAGS 0x000000ff /* flags that must match KM_* flags */ 19 | 20 | #define VM_BESTFIT 0x00000100 21 | #define VM_FIRSTFIT 0x00000200 22 | #define VM_NEXTFIT 0x00000400 23 | 24 | typedef struct vmem vmem_t; 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /scripts/systime.d: -------------------------------------------------------------------------------- 1 | /* Script to time how long non-boring syscalls take. */ 2 | 3 | syscall:::entry 4 | { 5 | x[pid, probefunc] = timestamp; 6 | } 7 | syscall:::return 8 | /probefunc != "epoll_wait" && timestamp - x[pid, probefunc] > 100000/ 9 | { 10 | printf("%-20s %d", execname, timestamp - x[pid, probefunc]); 11 | } 12 | -------------------------------------------------------------------------------- /librtld/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc -g $(BUILD_BITS) 2 | CPPFLAGS += -I../libproc/common \ 3 | -I../common/ctf \ 4 | -I../linux \ 5 | -I../lib/libproc/common \ 6 | -I../libctf \ 7 | -I../uts/common \ 8 | -I. \ 9 | -DCTF_OLD_VERSIONS $(PTR32) 10 | CPPFLAGS += -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 11 | 12 | BINDIR = ../$(BUILD_DIR) 13 | LIB = $(BINDIR)/libdtrace.a 14 | 15 | all: $(LIB) 16 | @/bin/true 17 | 18 | $(LIB): \ 19 | $(LIB)(rd_elf.o) \ 20 | $(LIB)(rtld_db.o) 21 | 22 | $(LIB)(rd_elf32.o): rd_elf.c 23 | $(CC) $(CPPFLAGS) -c rd_elf.c 24 | mv rd_elf.o rd_elf32.o 25 | ar $(ARFLAGS) $(LIB) rd_elf32.o 26 | rm -f rd_elf32.o 27 | 28 | $(LIB)(rd_elf64.o): rd_elf.c 29 | $(CC) $(CPPFLAGS) -D_ELF64 -c rd_elf.c 30 | mv rd_elf.o rd_elf64.o 31 | ar $(ARFLAGS) $(LIB) rd_elf64.o 32 | rm -f rd_elf64.o 33 | clean: 34 | -rm -f *.o *.a 35 | 36 | -------------------------------------------------------------------------------- /tests/fasttrap/ft4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void sig() 6 | { 7 | printf("inside a signal\n"); 8 | } 9 | 10 | int main(int argc,char **argv) 11 | { char buf[BUFSIZ]; 12 | double x = (int) argv; 13 | 14 | signal(SIGINT,sig); 15 | 16 | printf("PID %d .. press enter when ready\n", getpid()); 17 | fgets(buf, sizeof buf, stdin); 18 | 19 | printf("%f\n", sin(x)); 20 | 21 | printf("PID %d .. press enter when ready\n", getpid()); 22 | /* run thru the rtld exit() code.... */ 23 | } 24 | int main2() 25 | { char buf[100000]; 26 | char *cp = buf; 27 | void (*func)() = buf; 28 | 29 | *cp++ = 0x90; 30 | *cp++ = 0xc3; 31 | *cp++ = 0x00; 32 | *cp++ = 0x00; 33 | 34 | func(); 35 | printf("hello world\n"); 36 | } 37 | int main3() 38 | { 39 | asm(".byte 0x42, 0xff, 0x24, 0xf5, 0x10, 0x5d, 0x51, 0x00\n"); 40 | } 41 | -------------------------------------------------------------------------------- /utils/pgfault.c: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Try and induce page faulting system calls on the kernel. */ 3 | /**********************************************************************/ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void 12 | int_handler() 13 | { 14 | printf("Interrupt!\n"); 15 | 16 | } 17 | int main() 18 | { 19 | 20 | signal(SIGSEGV, SIG_IGN); 21 | int fd = open("/dev/zero", O_RDONLY); 22 | printf("fd = %d\n", fd); 23 | char *cp = mmap(NULL, 1024 * 1024, PROT_READ, MAP_PRIVATE, fd, 0); 24 | printf("addr = %p\n", cp); 25 | 26 | while (1) { 27 | printf("cp=%p %x\n", cp, *cp); 28 | cp += 8192; 29 | int fd = open(cp, O_RDONLY); 30 | if (fd > 0) 31 | close(fd); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /usdt/cpp/makefile: -------------------------------------------------------------------------------- 1 | CC=g++ -I../../uts/common -fPIC 2 | #BITS=-m64 3 | CFLAGS=$(BITS) 4 | BINDIR=../../$(BUILD_DIR) 5 | DTRACE=$(BINDIR)/dtrace 6 | DTRACE_DRTI_O=$(BINDIR)/drti.o 7 | 8 | all: $(BINDIR)/simple-cpp 9 | 10 | $(BINDIR)/simple-cpp: simple_probes.h simple_probes.o simple.o shlib.so $(DTRACE_DRTI_O) 11 | cd $(BINDIR) ; \ 12 | $(CC) -Wl,-rpath `pwd` -o simple-cpp $(BITS) simple_probes.o simple.o shlib.so -ldl 13 | 14 | simple_probes.h: simple_probes.d 15 | $(DTRACE) -h -s simple_probes.d 16 | 17 | simple_probes.o: simple.o simple_probes.d $(DTRACE_DRTI_O) 18 | . $(BINDIR)/config.sh ; \ 19 | if [ "$BUILD_i386" = 1 ]; then \ 20 | BITS=32 ; \ 21 | else \ 22 | BITS=64 ; \ 23 | fi ; \ 24 | DTRACE_DRTI_O=$(DTRACE_DRTI_O) $(DTRACE) -x nolibs -G -$$BITS -s simple_probes.d simple.o 25 | 26 | shlib.so: shlib.c 27 | $(CC) -fPIC -c shlib.c 28 | ld -G -o shlib.so shlib.o 29 | clean: 30 | -rm -f simple *.o *.so simple_probes.h 31 | -------------------------------------------------------------------------------- /doc/TIPs: -------------------------------------------------------------------------------- 1 | === Centos/RedHat crash dump enabling 2 | 3 | http://marinovl.blogspot.co.uk/2012/04/how-to-enable-centosrhel-5-crash-dump.html 4 | yum install --enablerepo=debug kexec-tools crash kernel-debuginfo 5 | 6 | (or yum install --enablerepo=rhel-debuginfo kexec-tools crash kernel-debuginfo if using RHEL5) 7 | 8 | 9 | Tune /etc/kdump.conf. To enable the dump file compression, add the -c parameter, to remove zero pages and free pages add -d 17: 10 | core_collector makedumpfile -d 17 -c 11 | 12 | Update /boot/grub/grub.conf with the memory to be reserved for the crash kernel: 13 | 14 | grubby --update-kernel=ALL --args="crashkernel=128M@16M" 15 | 16 | Enable the kdump service: 17 | chkconfig kdump on 18 | 19 | Reboot: 20 | shutdown -r now 21 | 22 | === RedHat/Centos source 23 | wget ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/kernel-2.6.18-8.1.8.el5.src.rpm 24 | rpm -ivh kernel-2.6.18-8.1.8.el5.src.rpm 25 | => /usr/src/redhat/SOURCES 26 | -------------------------------------------------------------------------------- /linux/sys/mkdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 32-bit Solaris device major/minor sizes. 3 | */ 4 | #define NBITSMAJOR32 14 5 | #define NBITSMINOR32 18 6 | #define MAXMAJ32 0x3ffful /* SVR4 max major value */ 7 | #define MAXMIN32 0x3fffful /* SVR4 max minor value */ 8 | 9 | #ifdef _LP64 10 | 11 | #define NBITSMAJOR64 32 /* # of major device bits in 64-bit Solaris */ 12 | #define NBITSMINOR64 32 /* # of minor device bits in 64-bit Solaris */ 13 | #define MAXMAJ64 0xfffffffful /* max major value */ 14 | #define MAXMIN64 0xfffffffful /* max minor value */ 15 | 16 | #define NBITSMAJOR NBITSMAJOR64 17 | #define NBITSMINOR NBITSMINOR64 18 | #define MAXMAJ MAXMAJ64 19 | #define MAXMIN MAXMIN64 20 | 21 | #else /* !_LP64 */ 22 | 23 | #define NBITSMAJOR NBITSMAJOR32 24 | #define NBITSMINOR NBITSMINOR32 25 | #define MAXMAJ MAXMAJ32 26 | #define MAXMIN MAXMIN32 27 | 28 | #endif /* !_LP64 */ 29 | -------------------------------------------------------------------------------- /cmd/intrstat/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | #ident "@(#)Makefile 1.2 03/12/05 SMI" 10 | # 11 | 12 | PROG= intrstat 13 | 14 | include ../Makefile.cmd 15 | 16 | $(64ONLY)SUBDIRS= $(MACH) 17 | $(BUILD64)SUBDIRS += $(MACH64) 18 | 19 | all := TARGET = all 20 | install := TARGET = install 21 | clean := TARGET = clean 22 | clobber := TARGET = clobber 23 | lint := TARGET = lint 24 | 25 | .KEEP_STATE: 26 | 27 | all: $(SUBDIRS) 28 | 29 | clean clobber lint: $(SUBDIRS) 30 | 31 | install: $(SUBDIRS) 32 | -$(RM) $(ROOTUSRSBINPROG) 33 | -$(LN) $(ISAEXEC) $(ROOTUSRSBINPROG) 34 | 35 | $(SUBDIRS): FRC 36 | @cd $@; pwd; $(MAKE) $(TARGET) 37 | 38 | FRC: 39 | 40 | include ../Makefile.targ 41 | -------------------------------------------------------------------------------- /cmd/intrstat/Makefile.com: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | # ident "@(#)Makefile.com 1.3 04/09/28 SMI" 10 | # 11 | 12 | PROG = intrstat 13 | OBJS = intrstat.o 14 | SRCS = $(OBJS:%.o=../%.c) 15 | 16 | include ../../Makefile.cmd 17 | 18 | CFLAGS += $(CCVERBOSE) 19 | CFLAGS64 += $(CCVERBOSE) 20 | LDLIBS += -ldtrace -lrt 21 | 22 | STRIPFLAG = 23 | FILEMODE = 0555 24 | GROUP = bin 25 | 26 | CLEANFILES += $(OBJS) 27 | 28 | .KEEP_STATE: 29 | 30 | all: $(PROG) 31 | 32 | $(PROG): $(OBJS) 33 | $(LINK.c) -o $@ $(OBJS) $(LDLIBS) 34 | $(POST_PROCESS) ; $(STRIP_STABS) 35 | 36 | clean: 37 | -$(RM) $(CLEANFILES) 38 | 39 | lint: lint_SRCS 40 | 41 | %.o: ../%.c 42 | $(COMPILE.c) $< 43 | 44 | include ../../Makefile.targ 45 | -------------------------------------------------------------------------------- /include/ctl.h: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Driver for allowing direct access to process memory - similar */ 3 | /* to /proc/pid/mem, but bypassing various restrictions which mean */ 4 | /* that dtrace can have trouble ptrace() attaching to a process */ 5 | /* which is being debugged. */ 6 | /**********************************************************************/ 7 | 8 | #if !defined(_CTL_H_INCLUDE) 9 | # define _CTL_H_INCLUDE 10 | 11 | /**********************************************************************/ 12 | /* ioctl values and structures for /dev/dtrace_ctl */ 13 | /**********************************************************************/ 14 | #define CTLIOC (('c' << 24) | ('t' << 16) | ('l' << 8)) 15 | #define CTLIOC_RDMEM (CTLIOC | 1) 16 | #define CTLIOC_WRMEM (CTLIOC | 2) 17 | typedef struct ctl_mem_t { 18 | int c_pid; 19 | void *c_src; 20 | void *c_dst; 21 | int c_len; 22 | } ctl_mem_t; 23 | 24 | #endif /* _CTL_H_INCLUDE */ 25 | -------------------------------------------------------------------------------- /linux/ieeefp.h: -------------------------------------------------------------------------------- 1 | #if defined(__i386) || defined(__amd64) 2 | 3 | #if defined(__amd64) 4 | #define _fpstate _fpstate32 5 | #endif 6 | 7 | struct _fpstate { /* saved state info from an exception */ 8 | unsigned int cw, /* control word */ 9 | sw, /* status word after fnclex-not useful */ 10 | tag, /* tag word */ 11 | ipoff, /* %eip register */ 12 | cssel, /* code segment selector */ 13 | dataoff, /* data operand address */ 14 | datasel; /* data operand selector */ 15 | struct _fpreg _st[8]; /* saved register stack */ 16 | unsigned int status; /* status word saved at exception */ 17 | unsigned int mxcsr; 18 | unsigned int xstatus; /* status word saved at exception */ 19 | unsigned int __pad[2]; 20 | unsigned int xmm[8][4]; 21 | }; 22 | 23 | #if defined(__amd64) 24 | #undef _fpstate 25 | #endif 26 | 27 | #endif /* __i386 || __amd64 */ 28 | -------------------------------------------------------------------------------- /tools/cross-build/README: -------------------------------------------------------------------------------- 1 | The tools in this directory are designed to help do a 32-bit kernel 2 | compile on a 64-bit x86 platform. 3 | 4 | When building dtrace, life is easier if I can cross-compile 5 | the driver on a single box (rather than flipping between two 6 | cpu architectures on different boxes), and at least validate that 7 | it can compile on my collection of kernels. 8 | 9 | It may not work for you - we dont really care, at this stage, about 10 | the quality of a cross-compiled driver, since the driver needs to be 11 | built with the same linux/.config options as your target. 12 | 13 | We arent in the business of putting out binary distributions (maybe 14 | at a later date), but thats a support nightmare, and not GPL friendly. 15 | 16 | Its possible that some of this does more or more bad things than it needs, 17 | but this is the hoops I had to go through to get the same errors/warnings 18 | as my native 32-bit machine was getting. 19 | 20 | This is needed when the 21 | 22 | $ make kernels 23 | 24 | target is invoked. 25 | 26 | Paul Fox May 2009 27 | -------------------------------------------------------------------------------- /linux/sys/processor.h: -------------------------------------------------------------------------------- 1 | # if !defined(PROCESSOR_H) 2 | # define PROCESSOR_H 3 | 4 | typedef unsigned int processorid_t; 5 | 6 | /* 7 | * Flags and return values for p_online(2), and pi_state for processor_info(2). 8 | * These flags are *not* for in-kernel examination of CPU states. 9 | * See for appropriate informational functions. 10 | */ 11 | #define P_OFFLINE 0x0001 /* processor is offline, as quiet as possible */ 12 | #define P_ONLINE 0x0002 /* processor is online */ 13 | #define P_STATUS 0x0003 /* value passed to p_online to request status */ 14 | #define P_FAULTED 0x0004 /* processor is offline, in faulted state */ 15 | #define P_POWEROFF 0x0005 /* processor is powered off */ 16 | #define P_NOINTR 0x0006 /* processor is online, but no I/O interrupts */ 17 | #define P_SPARE 0x0007 /* processor is offline, can be reactivated */ 18 | #define P_BAD P_FAULTED /* unused but defined by USL */ 19 | #define P_FORCED 0x10000000 /* force processor offline */ 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /driver/taskq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as 3 | * KM_SLEEP/KM_NOSLEEP. 4 | */ 5 | #define TQ_SLEEP 0x00 /* Can block for memory */ 6 | #define TQ_NOSLEEP 0x01 /* cannot block for memory; may fail */ 7 | #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 8 | #define TQ_NOALLOC 0x04 /* cannot allocate memory; may fail */ 9 | 10 | #define maxclsyspri 1 11 | 12 | /**********************************************************************/ 13 | /* taskq interface for the probes garbage collection triggered in */ 14 | /* fasttrap. */ 15 | /**********************************************************************/ 16 | typedef uintptr_t taskqid_t; 17 | typedef int pri_t; 18 | typedef void (task_func_t)(void *); 19 | 20 | taskqid_t taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t flags); 21 | taskq_t * taskq_create(const char *name, int nthreads, pri_t pri, int minalloc, 22 | int maxalloc, uint_t flags); 23 | void taskq_destroy(taskq_t *tq); 24 | 25 | 26 | -------------------------------------------------------------------------------- /etc/dtrace.conf: -------------------------------------------------------------------------------- 1 | # Example configuration file for permissioning dtrace. 2 | # 3 | # Format of the file is: 4 | # 5 | # clear Empty the security table; useful if you need to reload 6 | # or change the security modelling without reloading the 7 | # driver. 8 | # 9 | # uid NNN [priv_proc | priv_owner | priv_kernel | priv_owner] 10 | # gid NNN [priv_proc | priv_owner | priv_kernel | priv_owner] 11 | # Allow specified uid or group id to have access to the 12 | # specified dtrace priviledge. 13 | # 14 | # Multiple priveleges can be specified (space separated) 15 | # 16 | # all [priv_proc | priv_owner | priv_kernel | priv_owner] 17 | # Apply priveleges to all user ids. Use this as a default. 18 | # 19 | # Following is a wide-open kernel - everyone can do anything from 20 | # inspecting kernel data structures, to probing any process 21 | # all priv_kernel 22 | 23 | # Example of a locked down kernel 24 | uid 200 priv_proc 25 | gid 201 priv_kernel 26 | all priv_owner 27 | -------------------------------------------------------------------------------- /driver/kcpp: -------------------------------------------------------------------------------- 1 | p=`pwd` 2 | cd /lib/modules/`uname -r`/build ; gcc -m32 -nostdinc -isystem /usr/lib/gcc/i486-linux-gnu/4.2.3/include -D__KERNEL__ -Iinclude \ 3 | -include include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing \ 4 | -fno-common -Werror-implicit-function-declaration -O2 -pipe -msoft-float -mregparm=3 -freg-struct-return \ 5 | -mpreferred-stack-boundary=2 -march=i586 -mtune=generic -ffreestanding -maccumulate-outgoing-args \ 6 | -Iinclude/asm-x86/mach-default -fomit-frame-pointer -g -fno-stack-protector -Wdeclaration-after-statement \ 7 | -Wno-pointer-sign -I/home/fox/src/dtrace/drivers/dtrace -I/home/fox/src/dtrace/drivers/dtrace/../.. \ 8 | -I/home/fox/src/dtrace/drivers/dtrace/../include -I/home/fox/src/dtrace/drivers/dtrace/../../linux \ 9 | -I/home/fox/src/dtrace/drivers/dtrace/../../common/ctf -I/home/fox/src/dtrace/drivers/dtrace/../../uts/common \ 10 | -D_KERNEL -DCTF_OLD_VERSIONS -D_ILP32 -DMODULE -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(dtrace)" \ 11 | -D"KBUILD_MODNAME=KBUILD_STR(dtracedrv)" -E $p/$1 12 | -------------------------------------------------------------------------------- /usdt/c/simple_probes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Generated by dtrace(1M). 3 | */ 4 | 5 | #ifndef _SIMPLE_PROBES_H 6 | #define _SIMPLE_PROBES_H 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #if _DTRACE_VERSION 15 | 16 | #define SIMPLE_SAW_LINE(arg0) \ 17 | __dtrace_simple___saw__line(arg0) 18 | #define SIMPLE_SAW_LINE_ENABLED() \ 19 | __dtraceenabled_simple___saw__line() 20 | #define SIMPLE_SAW_WORD(arg0) \ 21 | __dtrace_simple___saw__word(arg0) 22 | #define SIMPLE_SAW_WORD_ENABLED() \ 23 | __dtraceenabled_simple___saw__word() 24 | 25 | 26 | extern void __dtrace_simple___saw__line(int); 27 | extern int __dtraceenabled_simple___saw__line(void); 28 | extern void __dtrace_simple___saw__word(int); 29 | extern int __dtraceenabled_simple___saw__word(void); 30 | 31 | #else 32 | 33 | #define SIMPLE_SAW_LINE(arg0) 34 | #define SIMPLE_SAW_LINE_ENABLED() (0) 35 | #define SIMPLE_SAW_WORD(arg0) 36 | #define SIMPLE_SAW_WORD_ENABLED() (0) 37 | 38 | #endif 39 | 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _SIMPLE_PROBES_H */ 46 | -------------------------------------------------------------------------------- /usdt/cpp/simple_probes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Generated by dtrace(1M). 3 | */ 4 | 5 | #ifndef _SIMPLE_PROBES_H 6 | #define _SIMPLE_PROBES_H 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #if _DTRACE_VERSION 15 | 16 | #define SIMPLE_SAW_LINE(arg0) \ 17 | __dtrace_simple___saw__line(arg0) 18 | #define SIMPLE_SAW_LINE_ENABLED() \ 19 | __dtraceenabled_simple___saw__line() 20 | #define SIMPLE_SAW_WORD(arg0) \ 21 | __dtrace_simple___saw__word(arg0) 22 | #define SIMPLE_SAW_WORD_ENABLED() \ 23 | __dtraceenabled_simple___saw__word() 24 | 25 | 26 | extern void __dtrace_simple___saw__line(int); 27 | extern int __dtraceenabled_simple___saw__line(void); 28 | extern void __dtrace_simple___saw__word(int); 29 | extern int __dtraceenabled_simple___saw__word(void); 30 | 31 | #else 32 | 33 | #define SIMPLE_SAW_LINE(arg0) 34 | #define SIMPLE_SAW_LINE_ENABLED() (0) 35 | #define SIMPLE_SAW_WORD(arg0) 36 | #define SIMPLE_SAW_WORD_ENABLED() (0) 37 | 38 | #endif 39 | 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _SIMPLE_PROBES_H */ 46 | -------------------------------------------------------------------------------- /utils/thread.c: -------------------------------------------------------------------------------- 1 | /* Simple thread test - am having problems proving dtrace 2 | thread/posix locking works; could be a vmware issue... */ 3 | # include 4 | # include 5 | # include 6 | 7 | pthread_mutex_t m; 8 | static void 9 | thread(void *arg) 10 | { 11 | printf("2: in thread...about to lock\n"); 12 | pthread_mutex_lock(&m); 13 | printf("2: in thread .. succeeded lock\n"); 14 | pause(); 15 | } 16 | 17 | int main(int argc, char **argv) 18 | { pthread_t tid; 19 | pthread_attr_t a; 20 | sigset_t nset, oset; 21 | 22 | pthread_mutex_init(&m, NULL); 23 | printf("1: main creating thread\n"); 24 | pthread_mutex_lock(&m); 25 | 26 | (void) pthread_attr_init(&a); 27 | (void) pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); 28 | (void) sigfillset(&nset); 29 | (void) sigdelset(&nset, SIGABRT); /* unblocked for assert() */ 30 | (void) sigdelset(&nset, SIGUSR1); /* see dt_proc_destroy() */ 31 | (void) pthread_sigmask(SIG_SETMASK, &nset, &oset); 32 | pthread_create(&tid, NULL, thread, NULL); 33 | printf("1: thread created\n"); 34 | pause(); 35 | } 36 | -------------------------------------------------------------------------------- /linux/sys/priv.h: -------------------------------------------------------------------------------- 1 | # if !defined(SYS_PRIV_H) 2 | # define SYS_PRIV_H 3 | 4 | typedef struct priv_impl_info { 5 | uint32_t priv_headersize; /* sizeof (priv_impl_info) */ 6 | uint32_t priv_flags; /* additional flags */ 7 | uint32_t priv_nsets; /* number of priv sets */ 8 | uint32_t priv_setsize; /* size in priv_chunk_t */ 9 | uint32_t priv_max; /* highest actual valid priv */ 10 | uint32_t priv_infosize; /* Per proc. additional info */ 11 | uint32_t priv_globalinfosize; /* Per system info */ 12 | } priv_impl_info_t; 13 | 14 | #define PRIV_IMPL_INFO_SIZE(p) \ 15 | ((p)->priv_headersize + (p)->priv_globalinfosize) 16 | 17 | #define PRIV_PRPRIV_INFO_OFFSET(p) \ 18 | (sizeof (*(p)) + \ 19 | ((p)->pr_nsets * (p)->pr_setsize - 1) * sizeof (priv_chunk_t)) 20 | 21 | #define PRIV_PRPRIV_SIZE(p) \ 22 | (PRIV_PRPRIV_INFO_OFFSET(p) + (p)->pr_infosize) 23 | 24 | # endif 25 | -------------------------------------------------------------------------------- /demo/intro/hello.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | BEGIN 28 | { 29 | trace("hello, world"); 30 | exit(0); 31 | } 32 | -------------------------------------------------------------------------------- /demo/user/libc.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | pid$target:libc.so::entry 28 | { 29 | @[probefunc] = count(); 30 | } 31 | -------------------------------------------------------------------------------- /demo/agg/writesbycmd.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::write:entry 28 | { 29 | @counts[execname] = count(); 30 | } 31 | -------------------------------------------------------------------------------- /demo/agg/writes.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::write:entry 28 | { 29 | @counts["write system calls"] = count(); 30 | } 31 | -------------------------------------------------------------------------------- /demo/agg/writesbycmdfd.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::write:entry 28 | { 29 | @counts[execname, arg0] = count(); 30 | } 31 | -------------------------------------------------------------------------------- /demo/script/syscall.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall:::entry 28 | /pid == $target/ 29 | { 30 | @[probefunc] = count(); 31 | } 32 | -------------------------------------------------------------------------------- /demo/agg/lquantize.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::write:entry 28 | { 29 | @fds[execname] = lquantize(arg0, 0, 100, 1); 30 | } 31 | -------------------------------------------------------------------------------- /demo/script/interp.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #!/usr/sbin/dtrace -s 28 | 29 | BEGIN 30 | { 31 | trace("hello"); 32 | exit(0); 33 | } 34 | -------------------------------------------------------------------------------- /demo/script/tracewrite.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #!/usr/sbin/dtrace -s 28 | 29 | syscall::write:entry 30 | /pid == $1/ 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /demo/fbt/ssd.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | fbt:ssd::return 28 | /arg1 == EIO/ 29 | { 30 | printf("%s+%x returned EIO.", probefunc, arg0); 31 | } 32 | -------------------------------------------------------------------------------- /s/z5: -------------------------------------------------------------------------------- 1 | sync 2 | root build/dtrace -n ' 3 | BEGIN { 4 | cnt = 0; 5 | tstart = timestamp; 6 | } 7 | syscall::: { 8 | this->pid = pid; 9 | this->ppid = ppid; 10 | this->execname = execname; 11 | this->arg0 = stringof(0x000f); 12 | this->arg0 = stringof(0x00f0); 13 | this->arg0 = stringof(0x0f00); 14 | this->arg0 = stringof(0xf000); 15 | 16 | this->arg0 = stringof(0x000f0000); 17 | this->arg0 = stringof(0x00f00000); 18 | this->arg0 = stringof(0x0f000000); 19 | this->arg0 = stringof(0xf0000000); 20 | 21 | this->arg0 = stringof(0x000f00000000); 22 | this->arg0 = stringof(0x00f000000000); 23 | this->arg0 = stringof(0x0f0000000000); 24 | this->arg0 = stringof(0xf00000000000); 25 | 26 | this->arg0 = stringof(0x000f000000000000); 27 | this->arg0 = stringof(0x00f0000000000000); 28 | this->arg0 = stringof(0x0f00000000000000); 29 | this->arg0 = stringof(0xf000000000000000); 30 | 31 | cnt++; 32 | } 33 | /* syscall::: /timestamp - tstart > 15 * 1000 * 1000 * 1000 / {exit(0);} 34 | tick-1ms /timestamp - tstart > 15 * 1000 * 1000 * 1000 / {exit(0);}*/ 35 | tick-1s { printf("count so far: %d", cnt); } 36 | tick-5s { exit(0); } 37 | ' 38 | -------------------------------------------------------------------------------- /demo/dtrace/error.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | BEGIN 28 | { 29 | *(char *)NULL; 30 | } 31 | 32 | ERROR 33 | { 34 | printf("Hit an error!"); 35 | } 36 | -------------------------------------------------------------------------------- /demo/fbt/putnext.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | fbt::putnext:entry 28 | { 29 | @calls[stringof(args[0]->q_qinfo->qi_minfo->mi_idname)] = count(); 30 | } 31 | -------------------------------------------------------------------------------- /demo/sched/tick.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::tick, 28 | sched:::enqueue 29 | { 30 | @[probename] = lquantize((timestamp / 1000000) % 10, 0, 10); 31 | } 32 | -------------------------------------------------------------------------------- /libdtrace/i386/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | # 4 | # The contents of this file are subject to the terms of the 5 | # Common Development and Distribution License, Version 1.0 only. 6 | # See the file usr/src/LICENSING.NOTICE in this distribution or 7 | # http://www.opensolaris.org/license/ for details. 8 | # 9 | #ident "@(#)Makefile 1.6 04/11/11 SMI" 10 | 11 | ASFLAGS += $(AS_PICFLAGS) -P -D_ASM 12 | 13 | MAPDIR = ../spec/i386 14 | MACHOBJS = dis_tables.o dt_asmsubr.o 15 | DLIBSRCS = regs.d 16 | 17 | include ../Makefile.com 18 | 19 | SRCS += $(SRC)/common/dis/i386/dis_tables.c dt_asmsubr.s 20 | CPPFLAGS += -I$(SRC)/common/dis/i386 21 | 22 | LINTFLAGS += -erroff=E_BAD_PTR_CAST_ALIGN 23 | 24 | CLEANFILES += regs.sed regs.d 25 | 26 | %.sed: %.sed.in 27 | $(COMPILE.cpp) -D_KERNEL $< | \ 28 | tr -d ' ' | tr '@' ' ' | tr '"' '@' | grep '^s/' > $@ 29 | 30 | ../$(MACH)/regs.d: regs.sed regs.d.in 31 | sed -f regs.sed < regs.d.in > $@ 32 | 33 | pics/%.o: $(SRC)/common/dis/i386/%.c 34 | $(COMPILE.c) -o $@ $< 35 | $(POST_PROCESS_O) 36 | 37 | install yydebug: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) \ 38 | $(ROOTDLIBS) $(ROOTDOBJS) 39 | -------------------------------------------------------------------------------- /demo/profile/profpri.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | profile-1001 28 | /pid == $1/ 29 | { 30 | @proc[execname] = lquantize(curlwpsinfo->pr_pri, 0, 100, 10); 31 | } 32 | -------------------------------------------------------------------------------- /demo/out/printa.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | profile:::profile-997 28 | { 29 | @a[caller] = count(); 30 | } 31 | 32 | END 33 | { 34 | printa("%@8u %a\n", @a); 35 | } 36 | -------------------------------------------------------------------------------- /demo/sched/pri.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::change-pri 28 | { 29 | @[stringof(args[0]->pr_clname)] = 30 | lquantize(args[2] - args[0]->pr_pri, -50, 50, 5); 31 | } 32 | -------------------------------------------------------------------------------- /usdt/c/README: -------------------------------------------------------------------------------- 1 | C code test/example of a USDT. Just make and run - and it should show 2 | up in the 'dtrace -l' list. 3 | 4 | Run ../../build/simple-c from the usdt/c directory. (We need 5 | to adjust the LD_LIBRARY_PATH searching, so at the moment, run it 6 | from here). 7 | 8 | This will simply display something like: 9 | 10 | ... 11 | PID:1290 52: here on line 25: crc=000083cf 12 | PID:1290 here on line 27 13 | PID:1290 here on line 29 14 | PID:1290 here on line 31 15 | PID:1290 53: here on line 25: crc=000083cf 16 | PID:1290 here on line 27 17 | PID:1290 here on line 29 18 | PID:1290 here on line 31 19 | ... 20 | 21 | If a dtrace probe is placed on this process' probe, then you 22 | will see the crc change, indicating a breakpoint got placed. 23 | 24 | A test, might be to use gdb to place a breakpoint at the same place 25 | as the usdt and see what happens. (Dtrace will assume it belongs 26 | to it, whilst the process is running). 27 | 28 | The script, mkapple, shows that Apple does something a little 29 | easier for dtrace generation. They have modified the compiler and/or 30 | linker to auto generate the .SUNW_dof section without needing to 31 | directly invoke dtrace to post process the ELF file. 32 | -------------------------------------------------------------------------------- /uts/common/os/lockstat_subr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License, Version 1.0 only. 6 | * See the file usr/src/LICENSING.NOTICE in this distribution or 7 | * http://www.opensolaris.org/license/ for details. 8 | */ 9 | 10 | #pragma ident "@(#)lockstat_subr.c 1.3 03/09/02 SMI" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /* 22 | * Resident support for the lockstat driver. 23 | */ 24 | 25 | dtrace_id_t lockstat_probemap[LS_NPROBES]; 26 | void (*lockstat_probe)(dtrace_id_t, uintptr_t, uintptr_t, 27 | uintptr_t, uintptr_t, uintptr_t); 28 | 29 | int 30 | lockstat_active_threads(void) 31 | { 32 | kthread_t *tp; 33 | int active = 0; 34 | 35 | mutex_enter(&pidlock); 36 | tp = curthread; 37 | do { 38 | if (tp->t_lockstat) 39 | active++; 40 | } while ((tp = tp->t_next) != curthread); 41 | mutex_exit(&pidlock); 42 | return (active); 43 | } 44 | -------------------------------------------------------------------------------- /linux/door.h: -------------------------------------------------------------------------------- 1 | # if !defined(DOOR_H) 2 | # define DOOR_H 3 | 4 | /* Basic door type information */ 5 | typedef unsigned long long door_ptr_t; /* Handle 64 bit pointers */ 6 | typedef unsigned long long door_id_t; /* Unique door identifier */ 7 | typedef unsigned int door_attr_t; /* Door attributes */ 8 | 9 | /* 10 | * Structure used to return info from door_info 11 | */ 12 | typedef struct door_info { 13 | pid_t di_target; /* Server process */ 14 | door_ptr_t di_proc; /* Server procedure */ 15 | door_ptr_t di_data; /* Data cookie */ 16 | door_attr_t di_attributes; /* Attributes associated with door */ 17 | door_id_t di_uniquifier; /* Unique number */ 18 | int di_resv[4]; /* Future use */ 19 | } door_info_t; 20 | 21 | /* 22 | * System call subcodes 23 | */ 24 | #define DOOR_CREATE 0 25 | #define DOOR_REVOKE 1 26 | #define DOOR_INFO 2 27 | #define DOOR_CALL 3 28 | #define DOOR_BIND 6 29 | #define DOOR_UNBIND 7 30 | #define DOOR_UNREFSYS 8 31 | #define DOOR_UCRED 9 32 | #define DOOR_RETURN 10 33 | #define DOOR_GETPARAM 11 34 | #define DOOR_SETPARAM 12 35 | 36 | # endif 37 | -------------------------------------------------------------------------------- /demo/anon/iprb.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | fbt::iprbattach:entry 28 | { 29 | self->trace = 1; 30 | } 31 | 32 | fbt::: 33 | /self->trace/ 34 | {} 35 | 36 | fbt::iprbattach:return 37 | { 38 | self->trace = 0; 39 | } 40 | -------------------------------------------------------------------------------- /demo/sched/where.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::on-cpu 28 | { 29 | self->ts = timestamp; 30 | } 31 | 32 | sched:::off-cpu 33 | /self->ts/ 34 | { 35 | @[cpu] = quantize(timestamp - self->ts); 36 | self->ts = 0; 37 | } 38 | -------------------------------------------------------------------------------- /demo/sched/ticktime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | uint64_t last[int]; 28 | 29 | sched:::tick 30 | /last[cpu]/ 31 | { 32 | @[cpu] = min(timestamp - last[cpu]); 33 | } 34 | 35 | sched:::tick 36 | { 37 | last[cpu] = timestamp; 38 | } 39 | -------------------------------------------------------------------------------- /demo/spec/spec.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::open:entry 28 | { 29 | self->spec = speculation(); 30 | } 31 | 32 | syscall::: 33 | /self->spec/ 34 | { 35 | speculate(self->spec); 36 | printf("this is speculative"); 37 | } 38 | -------------------------------------------------------------------------------- /demo/proc/progtime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | proc:::start 28 | { 29 | self->start = timestamp; 30 | } 31 | 32 | proc:::exit 33 | /self->start/ 34 | { 35 | @[execname] = quantize(timestamp - self->start); 36 | self->start = 0; 37 | } 38 | -------------------------------------------------------------------------------- /demo/sched/qtime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::enqueue 28 | { 29 | self->ts = timestamp; 30 | } 31 | 32 | sched:::dequeue 33 | /self->ts/ 34 | { 35 | @[args[2]->cpu_id] = quantize(timestamp - self->ts); 36 | self->ts = 0; 37 | } 38 | -------------------------------------------------------------------------------- /demo/agg/writetime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::write:entry 28 | { 29 | self->ts = timestamp; 30 | } 31 | 32 | syscall::write:return 33 | /self->ts/ 34 | { 35 | @time[execname] = avg(timestamp - self->ts); 36 | self->ts = 0; 37 | } 38 | -------------------------------------------------------------------------------- /demo/agg/writetimeq.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::write:entry 28 | { 29 | self->ts = timestamp; 30 | } 31 | 32 | syscall::write:return 33 | /self->ts/ 34 | { 35 | @time[execname] = quantize(timestamp - self->ts); 36 | self->ts = 0; 37 | } 38 | -------------------------------------------------------------------------------- /demo/dtrace/end.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | BEGIN 28 | { 29 | start = timestamp; 30 | } 31 | 32 | /* 33 | * ... other tracing actions... 34 | */ 35 | 36 | END 37 | { 38 | printf("total time: %d secs", (timestamp - start) / 1000000000); 39 | } 40 | -------------------------------------------------------------------------------- /demo/io/applicat.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | io:::start 28 | /execname == "soffice.bin" && args[2]->fi_name == "applicat.rdb"/ 29 | { 30 | @ = lquantize(args[2]->fi_offset != -1 ? 31 | args[2]->fi_offset / (1000 * 1024) : -1, 0, 1000); 32 | } 33 | -------------------------------------------------------------------------------- /libdtrace/sysevent.sed.in: -------------------------------------------------------------------------------- 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 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | #pragma ident "%Z%%M% %I% %E% SMI" 27 | 28 | #include 29 | 30 | #define SED_MACRO(x) s/#x(ev)/x(ev)/g 31 | 32 | SED_MACRO(SE_CLASS_NAME) 33 | SED_MACRO(SE_SUBCLASS_NAME) 34 | SED_MACRO(SE_PUB_NAME) 35 | -------------------------------------------------------------------------------- /linux/elf.h: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Linux and Sun elf include files are complicated and different, */ 3 | /* having to both support 32 and 64 bit includes and provide the */ 4 | /* gelf.h wrapper. */ 5 | /* */ 6 | /* Solaris doesnt seem to allow for a 32-bit binary which can read */ 7 | /* 64-bit ELF files. We dont care about this on Linux, but we do */ 8 | /* want to build dtrace for 32-bit kernels. */ 9 | /**********************************************************************/ 10 | 11 | # if !defined(ELF_H) 12 | # define ELF_H 1 13 | 14 | # include 15 | # include 16 | 17 | typedef struct { 18 | uint64_t a_type; 19 | union { 20 | uint64_t a_val; 21 | } a_un; 22 | } Elf64_auxv_t; 23 | 24 | typedef struct 25 | { 26 | Elf64_Word l_name; /* Name (string table index) */ 27 | Elf64_Word l_time_stamp; /* Timestamp */ 28 | Elf64_Word l_checksum; /* Checksum */ 29 | Elf64_Word l_version; /* Interface version */ 30 | Elf64_Word l_flags; /* Flags */ 31 | } Elf64_Lib; 32 | 33 | typedef uint16_t Elf64_Section; 34 | typedef Elf64_Syminfo GElf_Syminfo; 35 | typedef Elf64_auxv_t GElf_auxv_t; 36 | 37 | # endif /* !defined(ELF_H) */ 38 | -------------------------------------------------------------------------------- /tests/sqlite-snoop.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -Zs 2 | 3 | /* 4 | 5 | sqlite-snoop.d 6 | 7 | Author: Damian Carrillo 8 | Usage: sudo ./libsqlite_snoop.d 9 | Date: 2012-04-03 10 | https://gist.github.com/damiancarrillo/2395146 11 | 12 | */ 13 | 14 | #pragma D option quiet 15 | #pragma D option switchrate=10hz 16 | 17 | dtrace:::BEGIN 18 | { 19 | printf("%-8s %6s %s\n", "TIME(ms)", "Q(ms)", "QUERY"); 20 | timezero = timestamp; 21 | } 22 | 23 | pid$1:libsqlite3*:sqlite3_prepare*:entry 24 | { 25 | self->query = copyinstr(arg1); 26 | self->start = timestamp; 27 | } 28 | 29 | pid$1:libsqlite3*:sqlite3_prepare*:entry 30 | /self->start/ 31 | { 32 | this->time = (timestamp - self->start) / 1000000; 33 | this->now = (timestamp - timezero) / 1000000; 34 | printf("%-8d %6d %s\n", this->now, this->time, self->query); 35 | self->start = 0; self->query = 0; 36 | } 37 | 38 | pid$1:libsqlite3*:sqlite3_exec*:entry 39 | { 40 | self->query = copyinstr(arg1); 41 | self->start = timestamp; 42 | } 43 | 44 | pid$1:libsqlite3*:sqlite3_exec*:entry 45 | /self->start/ 46 | { 47 | this->time = (timestamp - self->start) / 1000000; 48 | this->now = (timestamp - timezero) / 1000000; 49 | printf("%-8d %6d %s\n", this->now, this->time, self->query); 50 | self->start = 0; self->query = 0; 51 | } 52 | -------------------------------------------------------------------------------- /demo/buf/ring.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option bufpolicy=ring 28 | #pragma D option bufsize=16k 29 | 30 | syscall:::entry 31 | /execname == $1/ 32 | { 33 | trace(timestamp); 34 | } 35 | 36 | syscall::rexit:entry 37 | { 38 | exit(0); 39 | } 40 | -------------------------------------------------------------------------------- /demo/lockstat/whatlock.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | lockstat:::adaptive-acquire 28 | /execname == "date"/ 29 | { 30 | @locks["adaptive"] = count(); 31 | } 32 | 33 | lockstat:::spin-acquire 34 | /execname == "date"/ 35 | { 36 | @locks["spin"] = count(); 37 | } 38 | -------------------------------------------------------------------------------- /demo/proc/lwptime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | proc:::lwp-start 28 | /tid != 1/ 29 | { 30 | self->start = timestamp; 31 | } 32 | 33 | proc:::lwp-exit 34 | /self->start/ 35 | { 36 | @[execname] = quantize(timestamp - self->start); 37 | self->start = 0; 38 | } 39 | -------------------------------------------------------------------------------- /demo/user/userfunc.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | pid$1::$2:entry 28 | { 29 | self->trace = 1; 30 | } 31 | 32 | pid$1::$2:return 33 | /self->trace/ 34 | { 35 | self->trace = 0; 36 | } 37 | 38 | pid$1:::entry, 39 | pid$1:::return 40 | /self->trace/ 41 | { 42 | } 43 | -------------------------------------------------------------------------------- /tests/fasttrap/ft1.c: -------------------------------------------------------------------------------- 1 | /* Simple do-nothing executable, so we can debug pid provider 2 | without a lot of action/noise. */ 3 | #include 4 | 5 | void do_nothing(int n); 6 | void do_nothing2(void); 7 | 8 | int main(int argc, char **argv) 9 | { int n = 99; 10 | 11 | while (1) { 12 | char *cp = malloc(1234); 13 | free(cp); 14 | printf("pid: %d %p ", (int) getpid(), &cp); 15 | fflush(stdout); 16 | system("uptime"); 17 | system("head /proc/dtrace/fasttrap"); 18 | sleep(1); 19 | 20 | if (argc > 1) { 21 | char buf[1024]; 22 | printf("Ready: "); 23 | fgets(buf, sizeof buf, stdin); 24 | do_nothing2(); 25 | } else 26 | do_nothing(n++); 27 | } 28 | } 29 | /**********************************************************************/ 30 | /* Functions which are not called, so we can probe them, and not */ 31 | /* actually invoke a probe. Used for debugging. */ 32 | /**********************************************************************/ 33 | void 34 | do_nothing(int n) 35 | { 36 | if ((n & 3) == 0) 37 | system("df"); 38 | } 39 | void 40 | do_nothing2() 41 | { 42 | if (getpid() & 1) 43 | printf("something %x\n", getpid() + 3 * getpid()); 44 | else 45 | printf("something else %x\n", getpid() % 3); 46 | 47 | 48 | system("df"); 49 | } 50 | -------------------------------------------------------------------------------- /demo/intro/countdown.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | dtrace:::BEGIN 28 | { 29 | i = 10; 30 | } 31 | 32 | profile:::tick-1sec 33 | /i > 0/ 34 | { 35 | trace(i--); 36 | } 37 | 38 | profile:::tick-1sec 39 | /i == 0/ 40 | { 41 | trace("blastoff!"); 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /demo/sdt/callout.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | sdt:::callout-start 30 | { 31 | @callouts[((callout_t *)arg0)->c_func] = count(); 32 | } 33 | 34 | tick-1sec 35 | { 36 | printa("%40a %10@d\n", @callouts); 37 | clear(@callouts); 38 | } 39 | -------------------------------------------------------------------------------- /demo/sched/qlen.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::enqueue 28 | { 29 | this->len = qlen[args[2]->cpu_id]++; 30 | @[args[2]->cpu_id] = lquantize(this->len, 0, 100); 31 | } 32 | 33 | sched:::dequeue 34 | /qlen[args[2]->cpu_id]/ 35 | { 36 | qlen[args[2]->cpu_id]--; 37 | } 38 | -------------------------------------------------------------------------------- /demo/profile/prof.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | profile-97 30 | /pid != 0/ 31 | { 32 | @proc[pid, execname] = count(); 33 | } 34 | 35 | END 36 | { 37 | printf("%-8s %-40s %s\n", "PID", "CMD", "COUNT"); 38 | printa("%-8d %-40s %@d\n", @proc); 39 | } 40 | -------------------------------------------------------------------------------- /demo/user/badopen.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::open:entry 28 | /pid == $1/ 29 | { 30 | self->path = copyinstr(arg0); 31 | } 32 | 33 | syscall::open:return 34 | /self->path != NULL && arg1 == -1/ 35 | { 36 | printf("open for '%s' failed", self->path); 37 | ustack(); 38 | } 39 | -------------------------------------------------------------------------------- /demo/fbt/delay.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | fbt::delay:entry, 28 | fbt::drv_usecwait:entry 29 | { 30 | self->in = timestamp 31 | } 32 | 33 | fbt::delay:return, 34 | fbt::drv_usecwait:return 35 | /self->in/ 36 | { 37 | @snoozers[stack()] = quantize(timestamp - self->in); 38 | self->in = 0; 39 | } 40 | -------------------------------------------------------------------------------- /demo/intro/counter.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | /* 28 | * Count off and report the number of seconds elapsed 29 | */ 30 | dtrace:::BEGIN 31 | { 32 | i = 0; 33 | } 34 | 35 | profile:::tick-1sec 36 | { 37 | i = i + 1; 38 | trace(i); 39 | } 40 | 41 | dtrace:::END 42 | { 43 | trace(i); 44 | } 45 | -------------------------------------------------------------------------------- /demo/intro/trussrw.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::read:entry, 28 | syscall::write:entry 29 | /pid == $1/ 30 | { 31 | printf("%s(%d, 0x%x, %4d)", probefunc, arg0, arg1, arg2); 32 | } 33 | 34 | syscall::read:return, syscall::write:return 35 | /pid == $1/ 36 | { 37 | printf("\t\t = %d\n", arg1); 38 | } 39 | -------------------------------------------------------------------------------- /demo/io/whowrite.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | io:::start 30 | /args[0]->b_flags & B_WRITE/ 31 | { 32 | @[execname, args[2]->fi_dirname] = count(); 33 | } 34 | 35 | END 36 | { 37 | printf("%20s %51s %5s\n", "WHO", "WHERE", "COUNT"); 38 | printa("%20s %51s %5@d\n", @); 39 | } 40 | -------------------------------------------------------------------------------- /demo/agg/renormalize.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | start = timestamp; 32 | } 33 | 34 | syscall:::entry 35 | { 36 | @func[execname] = count(); 37 | } 38 | 39 | tick-10sec 40 | { 41 | normalize(@func, (timestamp - start) / 1000000000); 42 | printa(@func); 43 | } 44 | -------------------------------------------------------------------------------- /demo/io/iosnoop.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | printf("%10s %58s %2s\n", "DEVICE", "FILE", "RW"); 32 | } 33 | 34 | io:::start 35 | { 36 | printf("%10s %58s %2s\n", args[1]->dev_statname, 37 | args[2]->fi_pathname, args[0]->b_flags & B_READ ? "R" : "W"); 38 | } 39 | -------------------------------------------------------------------------------- /demo/io/whoio.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | io:::start 30 | { 31 | @[args[1]->dev_statname, execname, pid] = sum(args[0]->b_bcount); 32 | } 33 | 34 | END 35 | { 36 | printf("%10s %20s %10s %15s\n", "DEVICE", "APP", "PID", "BYTES"); 37 | printa("%10s %20s %10d %15@d\n", @); 38 | } 39 | -------------------------------------------------------------------------------- /libproc/common/Psymtab_machelf64.c: -------------------------------------------------------------------------------- 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 2007 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma ident "@(#)Psymtab_machelf64.c 1.1 07/01/01 SMI" 28 | 29 | /* 30 | * Defining _ELF64 causes the code in Psymtab_machelf32.c to generate 31 | * the ELFCLASS64 version of the code contained in that file. 32 | */ 33 | #define _ELF64 34 | #include "Psymtab_machelf32.c" 35 | -------------------------------------------------------------------------------- /usdt/c/makefile: -------------------------------------------------------------------------------- 1 | # $(DTRACE) -h -s simple_probes.d 2 | CC=gcc -I../../uts/common -fPIC 3 | #BITS=-m64 4 | CFLAGS=$(BITS) $(BUILD_BITS) 5 | BINDIR=../../$(BUILD_DIR) 6 | DTRACE=$(BINDIR)/dtrace 7 | DTRACE_DRTI_O=$(BINDIR)/drti.o 8 | DTRACE_LIB=$(BINDIR)/libdtrace.a 9 | 10 | all: $(BINDIR)/simple-c 11 | @/bin/true 12 | 13 | $(BINDIR)/simple-c: $(BINDIR)/simple_probes.o $(BINDIR)/simple.o \ 14 | $(BINDIR)/shlib.so $(DTRACE_DRTI_O) $(DTRACE_LIB) 15 | cd $(BINDIR) ; \ 16 | $(CC) -Wl,-rpath `pwd -P` -Wl,--library-path `pwd -P` -o simple-c $(BITS) simple_probes.o simple.o shlib.so -ldl 17 | 18 | $(BINDIR)/simple_probes.o: $(BINDIR)/simple.o simple_probes.d $(DTRACE_DRTI_O) $(DTRACE_LIB) 19 | @. $(BINDIR)/config.sh ; \ 20 | if [ "$$BUILD_i386" = 1 ]; then \ 21 | BITS=32 ; \ 22 | else \ 23 | BITS=64 ; \ 24 | fi ; \ 25 | echo DTRACE_DRTI_O=$(DTRACE_DRTI_O) $(DTRACE) -x nolibs -G -$$BITS -s simple_probes.d $(BINDIR)/simple.o ; \ 26 | DTRACE_DRTI_O=$(DTRACE_DRTI_O) $(DTRACE) -x nolibs -G -$$BITS -s simple_probes.d $(BINDIR)/simple.o 27 | mv simple_probes.o $(BINDIR) 28 | 29 | $(BINDIR)/simple.o: simple.c 30 | $(CC) -c simple.c 31 | mv simple.o $(BINDIR) 32 | 33 | $(BINDIR)/shlib.so: shlib.c 34 | $(CC) -c shlib.c 35 | mv shlib.o $(BINDIR) 36 | ld -G -o $(BINDIR)/shlib.so $(BINDIR)/shlib.o 37 | clean: 38 | -rm -f simple *.o *.so 39 | -------------------------------------------------------------------------------- /demo/intro/rwtime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::read:entry, 28 | syscall::write:entry 29 | /pid == $1/ 30 | { 31 | ts[probefunc] = timestamp; 32 | } 33 | 34 | syscall::read:return, 35 | syscall::write:return 36 | /pid == $1 && ts[probefunc] != 0/ 37 | { 38 | printf("%d nsecs", timestamp - ts[probefunc]); 39 | } 40 | -------------------------------------------------------------------------------- /demo/proc/sig.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | proc:::signal-send 30 | { 31 | @[execname, stringof(args[1]->pr_fname), args[2]] = count(); 32 | } 33 | 34 | END 35 | { 36 | printf("%20s %20s %12s %s\n", 37 | "SENDER", "RECIPIENT", "SIG", "COUNT"); 38 | printa("%20s %20s %12d %@d\n", @); 39 | } 40 | -------------------------------------------------------------------------------- /liblinux/proc.c: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | /**********************************************************************/ 4 | /* Stubs which we have yet to implement. Just log we got called so */ 5 | /* we can make porting progress and know what we forgot to do. */ 6 | /**********************************************************************/ 7 | 8 | int _libproc_debug; /* set non-zero to enable debugging printfs */ 9 | int blockable_sigs; /* signals to block when we need to be safe */ 10 | 11 | getzonenamebyid() { printf("%s\n", __func__); } 12 | 13 | int 14 | OBJFS_MODID(int x) 15 | { 16 | return x; 17 | } 18 | __priv_free_info() { printf("proc-stub:%s\n", __func__); } 19 | _rw_read_held() { printf("proc-stub:%s\n", __func__); } 20 | _rw_write_held() { printf("proc-stub:%s\n", __func__); } 21 | //dt_pid_create_entry_probe() { printf("proc-stub:%s\n", __func__); } 22 | //dt_pid_create_glob_offset_probes() { printf("proc-stub:%s\n", __func__); } 23 | //dt_pid_create_offset_probe() { printf("proc-stub:%s\n", __func__); } 24 | //dt_pid_create_return_probe() { printf("proc-stub:%s\n", __func__); } 25 | 26 | int modctl() { printf("proc-stub:%s\n", __func__); return -1; } 27 | int p_online(int processorid, int flag) 28 | { 29 | // printf("proc-stub:%s: processorid=%d flag=%d\n", __func__, processorid, flag); 30 | return 2; // P_ONLINE 31 | } 32 | 33 | -------------------------------------------------------------------------------- /utils/test_syscalls.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # $Header:$ 4 | 5 | use strict; 6 | use warnings; 7 | 8 | use File::Basename; 9 | use FileHandle; 10 | use Getopt::Long; 11 | use IO::File; 12 | use POSIX; 13 | 14 | ####################################################################### 15 | # Command line switches. # 16 | ####################################################################### 17 | my %opts; 18 | 19 | sub main 20 | { 21 | Getopt::Long::Configure('no_ignore_case'); 22 | usage() unless GetOptions(\%opts, 23 | 'help', 24 | ); 25 | 26 | usage() if ($opts{help}); 27 | 28 | my $fname = glob("build/driver/syscalls-*.tbl"); 29 | my $fh = new FileHandle($fname); 30 | my $str = <) { 35 | next if !/^.*defined\(__NR_(.*)\)/; 36 | my $func = $1; 37 | next if $func eq 'exit'; 38 | $str .= "\t$1();\n"; 39 | } 40 | $str .= " exit(0);\n"; 41 | $str .= "}\n"; 42 | print $str; 43 | } 44 | ####################################################################### 45 | # Print out command line usage. # 46 | ####################################################################### 47 | sub usage 48 | { 49 | print <ts = vtimestamp; 30 | } 31 | 32 | interrupt-complete 33 | /self->ts/ 34 | { 35 | this->devi = (struct dev_info *)arg0; 36 | @[stringof(`devnamesp[this->devi->devi_major].dn_name), 37 | this->devi->devi_instance] = quantize(vtimestamp - self->ts); 38 | } 39 | -------------------------------------------------------------------------------- /demo/sched/pritime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | start = timestamp; 32 | } 33 | 34 | sched:::change-pri 35 | /args[1]->pr_pid == $1 && args[0]->pr_lwpid == $2/ 36 | { 37 | printf("%d %d\n", timestamp - start, args[2]); 38 | } 39 | 40 | tick-1sec 41 | /++n == 5/ 42 | { 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /demo/dtrace/begin.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | BEGIN 28 | { 29 | prot[0] = "---"; 30 | prot[1] = "r--"; 31 | prot[2] = "-w-"; 32 | prot[3] = "rw-"; 33 | prot[4] = "--x"; 34 | prot[5] = "r-x"; 35 | prot[6] = "-wx"; 36 | prot[7] = "rwx"; 37 | } 38 | 39 | syscall::mmap:entry 40 | { 41 | printf("mmap with prot = %s", prot[arg2 & 0x7]); 42 | } 43 | -------------------------------------------------------------------------------- /demo/agg/clear.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | last = timestamp; 32 | } 33 | 34 | syscall:::entry 35 | { 36 | @func[execname] = count(); 37 | } 38 | 39 | tick-10sec 40 | { 41 | normalize(@func, (timestamp - last) / 1000000000); 42 | printa(@func); 43 | clear(@func); 44 | last = timestamp; 45 | } 46 | -------------------------------------------------------------------------------- /demo/sched/xwork.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | self int last; 28 | 29 | sched:::wakeup 30 | /self->last && args[0]->pr_stype == SOBJ_CV/ 31 | { 32 | @[stringof(args[1]->pr_fname)] = sum(vtimestamp - self->last); 33 | self->last = 0; 34 | } 35 | 36 | sched:::wakeup 37 | /execname == "Xsun" && self->last == 0/ 38 | { 39 | self->last = vtimestamp; 40 | } 41 | -------------------------------------------------------------------------------- /demo/sched/xterm.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | dtrace:::BEGIN 30 | { 31 | start = timestamp; 32 | } 33 | 34 | sched:::wakeup 35 | /stringof(args[1]->pr_fname) == "xterm"/ 36 | { 37 | @[execname] = lquantize((timestamp - start) / 1000000000, 0, 10); 38 | } 39 | 40 | profile:::tick-1sec 41 | /++x == 10/ 42 | { 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /demo/act/time.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | #pragma D option destructive 29 | #pragma D option switchrate=5sec 30 | 31 | tick-1sec 32 | /n++ < 5/ 33 | { 34 | printf("walltime : %Y\n", walltimestamp); 35 | printf("date : "); 36 | system("date"); 37 | printf("\n"); 38 | } 39 | 40 | tick-1sec 41 | /n == 5/ 42 | { 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /demo/agg/trunc.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | last = timestamp; 32 | } 33 | 34 | syscall:::entry 35 | { 36 | @func[execname] = count(); 37 | } 38 | 39 | tick-10sec 40 | { 41 | trunc(@func, 10); 42 | normalize(@func, (timestamp - last) / 1000000000); 43 | printa(@func); 44 | clear(@func); 45 | last = timestamp; 46 | } 47 | -------------------------------------------------------------------------------- /cmd/ctfconvert/symbol.h: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #ifndef _SYMBOL_H 28 | #define _SYMBOL_H 29 | 30 | #pragma ident "@(#)symbol.h 1.2 05/06/08 SMI" 31 | 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | int ignore_symbol(GElf_Sym *sym, const char *name); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* _SYMBOL_H */ 45 | -------------------------------------------------------------------------------- /demo/sched/whosteal.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | sched:::dequeue 30 | /args[2]->cpu_id != -1 && cpu != args[2]->cpu_id && 31 | (curlwpsinfo->pr_flag & PR_IDLE)/ 32 | { 33 | @[stringof(args[1]->pr_fname), args[2]->cpu_id] = 34 | lquantize(cpu, 0, 100); 35 | } 36 | 37 | END 38 | { 39 | printa("%s stolen from CPU %d by:\n%@d\n", @); 40 | } 41 | -------------------------------------------------------------------------------- /linux/sys/cpupart.h: -------------------------------------------------------------------------------- 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 2007 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #ifndef _COMPAT_OPENSOLARIS_SYS_CPUPART_H 28 | #define _COMPAT_OPENSOLARIS_SYS_CPUPART_H 29 | 30 | typedef int cpupartid_t; 31 | 32 | typedef struct cpupart { 33 | cpupartid_t cp_id; /* partition ID */ 34 | int cp_ncpus; /* number of online processors */ 35 | } cpupart_t; 36 | 37 | #endif /* _COMPAT_OPENSOLARIS_SYS_CPUPART_H */ 38 | -------------------------------------------------------------------------------- /demo/sysinfo/find.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall:::entry 28 | /execname == "find"/ 29 | { 30 | self->syscall = probefunc; 31 | self->insys = 1; 32 | } 33 | 34 | sysinfo:::xcalls 35 | /execname == "find"/ 36 | { 37 | @[self->insys ? self->syscall : ""] = count(); 38 | } 39 | 40 | syscall:::return 41 | /self->insys/ 42 | { 43 | self->insys = 0; 44 | self->syscall = NULL; 45 | } 46 | -------------------------------------------------------------------------------- /linux/sys/stat.h: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Wrapper around sys/types.h to get the right stuff defined for */ 3 | /* user and kernel land. */ 4 | /**********************************************************************/ 5 | # if !defined(SYS_STAT_H) 6 | # define SYS_STAT_H 7 | 8 | # include 9 | # include "/usr/include/sys/stat.h" 10 | 11 | #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 12 | #pragma pack(4) 13 | #endif 14 | #define _ST_FSTYPSZ 16 /* array size for file system type name */ 15 | 16 | struct stat64_32 { 17 | dev32_t st_dev; 18 | int32_t st_pad1[3]; 19 | ino64_t st_ino; 20 | mode32_t st_mode; 21 | nlink32_t st_nlink; 22 | uid32_t st_uid; 23 | gid32_t st_gid; 24 | dev32_t st_rdev; 25 | int32_t st_pad2[2]; 26 | off64_t st_size; 27 | timestruc32_t st_atim; 28 | timestruc32_t st_mtim; 29 | timestruc32_t st_ctim; 30 | int32_t st_blksize; 31 | blkcnt64_t st_blocks; 32 | char st_fstype[_ST_FSTYPSZ]; 33 | int32_t st_pad4[8]; 34 | }; 35 | 36 | #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 37 | #pragma pack() 38 | #endif 39 | 40 | struct stat64; 41 | 42 | # endif 43 | -------------------------------------------------------------------------------- /demo/sched/howlong.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::off-cpu 28 | /curlwpsinfo->pr_state == SSLEEP/ 29 | { 30 | self->cpu = cpu; 31 | self->ts = timestamp; 32 | } 33 | 34 | sched:::on-cpu 35 | /self->ts/ 36 | { 37 | @[self->cpu == cpu ? 38 | "sleep time, no CPU migration" : "sleep time, CPU migration"] = 39 | lquantize((timestamp - self->ts) / 1000000, 0, 500, 25); 40 | self->ts = 0; 41 | self->cpu = 0; 42 | } 43 | -------------------------------------------------------------------------------- /demo/vars/rtime.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | syscall::read:entry 28 | { 29 | self->t = timestamp; 30 | } 31 | 32 | syscall::read:return 33 | /self->t != 0/ 34 | { 35 | printf("%d/%d spent %d nsecs in read(2)\n", 36 | pid, tid, timestamp - self->t); 37 | 38 | /* 39 | * We're done with this thread-local variable; assign zero to it to 40 | * allow the DTrace runtime to reclaim the underlying storage. 41 | */ 42 | self->t = 0; 43 | } 44 | -------------------------------------------------------------------------------- /libctf/uncompress.c: -------------------------------------------------------------------------------- 1 | # if __KERNEL__ 2 | 3 | # include 4 | # include 5 | # include "../port.h" 6 | 7 | # else 8 | 9 | # include 10 | # define zlib_inflateInit inflateInit 11 | # define zlib_inflate inflate 12 | # define zlib_inflateEnd inflateEnd 13 | 14 | # endif 15 | 16 | static char *last_err; 17 | 18 | int ctf_uncompress (char *dest, int *destLen, char *source, int sourceLen) 19 | { 20 | #if defined(DO_NOT_HAVE_ZLIB_IN_KERNEL) 21 | return Z_BUF_ERROR; 22 | #else 23 | z_stream stream; 24 | int err; 25 | 26 | memset(&stream, 0, sizeof stream); 27 | 28 | stream.next_in = source; 29 | stream.avail_in = sourceLen; 30 | /* Check for source > 64K on 16-bit machine: */ 31 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 32 | 33 | stream.next_out = dest; 34 | stream.avail_out = (uInt)*destLen; 35 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 36 | 37 | err = zlib_inflateInit(&stream); 38 | if (err != Z_OK) return err; 39 | 40 | err = zlib_inflate(&stream, Z_FINISH); 41 | last_err = stream.msg; 42 | if (err != Z_STREAM_END) { 43 | zlib_inflateEnd(&stream); 44 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 45 | return Z_DATA_ERROR; 46 | return err; 47 | } 48 | *destLen = stream.total_out; 49 | 50 | err = zlib_inflateEnd(&stream); 51 | return err; 52 | #endif 53 | } 54 | char * 55 | ctf_zstrerror(void) 56 | { 57 | return last_err; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /libdtrace/mkerrno.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # CDDL HEADER START 4 | # 5 | # The contents of this file are subject to the terms of the 6 | # Common Development and Distribution License, Version 1.0 only 7 | # (the "License"). You may not use this file except in compliance 8 | # with the License. 9 | # 10 | # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing permissions 13 | # and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL HEADER in each 16 | # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 | # If applicable, add the following below this CDDL HEADER, with the 18 | # fields enclosed by brackets "[]" replaced with your own identifying 19 | # information: Portions Copyright [yyyy] [name of copyright owner] 20 | # 21 | # CDDL HEADER END 22 | # 23 | # 24 | # Copyright 2003 Sun Microsystems, Inc. All rights reserved. 25 | # Use is subject to license terms. 26 | # 27 | #ident "@(#)mkerrno.sh 1.2 05/06/08 SMI" 28 | 29 | echo "\ 30 | /*\n\ 31 | * Copyright 2003 Sun Microsystems, Inc. All rights reserved.\n\ 32 | * Use is subject to license terms.\n\ 33 | */\n\ 34 | \n\ 35 | #pragma ident\t\"@(#)mkerrno.sh\t1.2\t05/06/08 SMI\"\n" 36 | 37 | pattern='^#define[ ]\(E[A-Z0-9]*\)[ ]*\([A-Z0-9]*\).*$' 38 | replace='inline int \1 = \2;@#pragma D binding "1.0" \1' 39 | 40 | sed -n "s/$pattern/$replace/p" | tr '@' '\n' 41 | -------------------------------------------------------------------------------- /libdtrace/mksignal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # CDDL HEADER START 4 | # 5 | # The contents of this file are subject to the terms of the 6 | # Common Development and Distribution License, Version 1.0 only 7 | # (the "License"). You may not use this file except in compliance 8 | # with the License. 9 | # 10 | # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing permissions 13 | # and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL HEADER in each 16 | # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 | # If applicable, add the following below this CDDL HEADER, with the 18 | # fields enclosed by brackets "[]" replaced with your own identifying 19 | # information: Portions Copyright [yyyy] [name of copyright owner] 20 | # 21 | # CDDL HEADER END 22 | # 23 | # 24 | # Copyright 2003 Sun Microsystems, Inc. All rights reserved. 25 | # Use is subject to license terms. 26 | # 27 | #ident "@(#)mksignal.sh 1.2 05/06/08 SMI" 28 | 29 | echo "\ 30 | /*\n\ 31 | * Copyright 2003 Sun Microsystems, Inc. All rights reserved.\n\ 32 | * Use is subject to license terms.\n\ 33 | */\n\ 34 | \n\ 35 | #pragma ident\t\"@(#)mksignal.sh\t1.2\t05/06/08 SMI\"\n" 36 | 37 | pattern='^#define[ ]*_*\(SIG[A-Z0-9]*\)[ ]\{1,\}\([A-Z0-9]*\).*$' 38 | replace='inline int \1 = \2;@#pragma D binding "1.0" \1' 39 | 40 | sed -n "s/$pattern/$replace/p;/SIGRTMAX/q" | tr '@' '\n' 41 | -------------------------------------------------------------------------------- /demo/proc/whoexec.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | proc:::exec 30 | { 31 | self->parent = execname; 32 | } 33 | 34 | proc:::exec-success 35 | /self->parent != NULL/ 36 | { 37 | @[self->parent, execname] = count(); 38 | self->parent = NULL; 39 | } 40 | 41 | proc:::exec-failure 42 | /self->parent != NULL/ 43 | { 44 | self->parent = NULL; 45 | } 46 | 47 | END 48 | { 49 | printf("%-20s %-20s %s\n", "WHO", "WHAT", "COUNT"); 50 | printa("%-20s %-20s %@d\n", @); 51 | } 52 | -------------------------------------------------------------------------------- /utils/ptrace2.c: -------------------------------------------------------------------------------- 1 | /* Simple ptrace test - use PTRACE_ATTACH in a thread 2 | to see if it works; dtrace is having trouble attaching 3 | to a forked/execed proc. 4 | */ 5 | # include 6 | # include 7 | # include 8 | # include 9 | 10 | int pid; 11 | pthread_mutex_t m; 12 | 13 | static void 14 | thread(void *arg) 15 | { 16 | pid = fork(); 17 | if (pid == 0) { 18 | if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) { 19 | perror("PTRACE_TRACEME"); 20 | } 21 | printf("execing...\n"); 22 | execlp("/bin/date", "/bin/date", NULL); 23 | } 24 | if (ptrace(PTRACE_ATTACH, pid, 0, 0) < 0) { 25 | perror("PTRACE_ATTACH"); 26 | } 27 | printf("about to do PTRACE_CONT \n"); 28 | if (ptrace(PTRACE_CONT, pid, 0, 0) < 0) { 29 | perror("PTRACE_CONT"); 30 | } 31 | printf("PTRACE_CONT executed\n"); 32 | pause(); 33 | } 34 | 35 | int main(int argc, char **argv) 36 | { pthread_t tid; 37 | pthread_attr_t a; 38 | sigset_t nset, oset; 39 | 40 | //thread(0); 41 | pthread_mutex_init(&m, NULL); 42 | printf("1: main creating thread\n"); 43 | pthread_mutex_lock(&m); 44 | 45 | (void) pthread_attr_init(&a); 46 | // (void) pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); 47 | (void) sigfillset(&nset); 48 | (void) sigdelset(&nset, SIGABRT); /* unblocked for assert() */ 49 | (void) sigdelset(&nset, SIGUSR1); /* see dt_proc_destroy() */ 50 | // (void) pthread_sigmask(SIG_SETMASK, &nset, &oset); 51 | pthread_create(&tid, &a, thread, NULL); 52 | printf("1: thread created\n"); 53 | pause(); 54 | } 55 | -------------------------------------------------------------------------------- /demo/agg/denorm.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | start = timestamp; 32 | } 33 | 34 | syscall:::entry 35 | { 36 | @func[execname] = count(); 37 | } 38 | 39 | END 40 | { 41 | this->seconds = (timestamp - start) / 1000000000; 42 | printf("Ran for %d seconds.\n", this->seconds); 43 | 44 | printf("Per-second rate:\n"); 45 | normalize(@func, this->seconds); 46 | printa(@func); 47 | 48 | printf("\nRaw counts:\n"); 49 | denormalize(@func); 50 | printa(@func); 51 | } 52 | -------------------------------------------------------------------------------- /demo/agg/normalize.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | BEGIN 30 | { 31 | /* 32 | * Get the start time, in nanoseconds. 33 | */ 34 | start = timestamp; 35 | } 36 | 37 | syscall:::entry 38 | { 39 | @func[execname] = count(); 40 | } 41 | 42 | END 43 | { 44 | /* 45 | * Normalize the aggregation based on the number of seconds we have 46 | * been running. (There are 1,000,000,000 nanoseconds in one second.) 47 | */ 48 | normalize(@func, (timestamp - start) / 1000000000); 49 | } 50 | -------------------------------------------------------------------------------- /demo/ip/ipproto.d: -------------------------------------------------------------------------------- 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 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | #pragma D option quiet 27 | 28 | dtrace:::BEGIN 29 | { 30 | printf("Tracing... Hit Ctrl-C to end.\n"); 31 | } 32 | 33 | ip:::send, 34 | ip:::receive 35 | { 36 | this->protostr = args[2]->ip_ver == 4 ? 37 | args[4]->ipv4_protostr : args[5]->ipv6_nextstr; 38 | @num[args[2]->ip_saddr, args[2]->ip_daddr, this->protostr] = count(); 39 | } 40 | 41 | dtrace:::END 42 | { 43 | printf(" %-28s %-28s %6s %8s\n", "SADDR", "DADDR", "PROTO", "COUNT"); 44 | printa(" %-28s %-28s %6s %@8d\n", @num); 45 | } 46 | -------------------------------------------------------------------------------- /demo/sched/whofor.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #pragma D option quiet 28 | 29 | sched:::sleep 30 | /!(curlwpsinfo->pr_flag & PR_ISSYS) && curlwpsinfo->pr_stype == SOBJ_CV/ 31 | { 32 | bedtime[curlwpsinfo->pr_addr] = timestamp; 33 | } 34 | 35 | sched:::wakeup 36 | /bedtime[args[0]->pr_addr]/ 37 | { 38 | @[stringof(args[1]->pr_fname), execname] = 39 | quantize(timestamp - bedtime[args[0]->pr_addr]); 40 | bedtime[args[0]->pr_addr] = 0; 41 | } 42 | 43 | END 44 | { 45 | printa("%s sleeping on %s:\n%@d\n", @); 46 | } 47 | -------------------------------------------------------------------------------- /demo/user/errorpath.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | pid$1::$2:entry 28 | { 29 | self->spec = speculation(); 30 | speculate(self->spec); 31 | printf("%x %x %x %x %x", arg0, arg1, arg2, arg3, arg4); 32 | } 33 | 34 | pid$1::$2: 35 | /self->spec/ 36 | { 37 | speculate(self->spec); 38 | } 39 | 40 | pid$1::$2:return 41 | /self->spec && arg1 == 0/ 42 | { 43 | discard(self->spec); 44 | self->spec = 0; 45 | } 46 | 47 | pid$1::$2:return 48 | /self->spec && arg1 != 0/ 49 | { 50 | commit(self->spec); 51 | self->spec = 0; 52 | } 53 | -------------------------------------------------------------------------------- /demo/sched/nscd.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | sched:::sleep 28 | /curlwpsinfo->pr_stype == SOBJ_SHUTTLE/ 29 | { 30 | bedtime[curlwpsinfo->pr_addr] = timestamp; 31 | } 32 | 33 | sched:::wakeup 34 | /execname == "nscd" && bedtime[args[0]->pr_addr]/ 35 | { 36 | @[stringof(curpsinfo->pr_fname), stringof(args[1]->pr_fname)] = 37 | quantize(timestamp - bedtime[args[0]->pr_addr]); 38 | bedtime[args[0]->pr_addr] = 0; 39 | } 40 | 41 | sched:::wakeup 42 | /bedtime[args[0]->pr_addr]/ 43 | { 44 | bedtime[args[0]->pr_addr] = 0; 45 | } 46 | -------------------------------------------------------------------------------- /libdtrace/dt_string.h: -------------------------------------------------------------------------------- 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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 24 | */ 25 | 26 | #ifndef _DT_STRING_H 27 | #define _DT_STRING_H 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | extern size_t stresc2chr(char *); 37 | extern char *strchr2esc(const char *, size_t); 38 | extern const char *strbasename(const char *); 39 | extern const char *strbadidnum(const char *); 40 | extern int strisglob(const char *); 41 | extern char *strhyphenate(char *); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* _DT_STRING_H */ 48 | -------------------------------------------------------------------------------- /demo/struct/kstat.d: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | pid$1:libkstat:kstat_data_lookup:entry 28 | { 29 | self->ksname = arg1; 30 | } 31 | 32 | pid$1:libkstat:kstat_data_lookup:return 33 | /self->ksname != NULL && arg1 != NULL/ 34 | { 35 | this->ksp = (kstat_named_t *) copyin(arg1, sizeof (kstat_named_t)); 36 | printf("%s has ui64 value %u\n", 37 | copyinstr(self->ksname), this->ksp->value.ui64); 38 | } 39 | 40 | pid$1:libkstat:kstat_data_lookup:return 41 | /self->ksname != NULL && arg1 == NULL/ 42 | { 43 | self->ksname = NULL; 44 | } 45 | -------------------------------------------------------------------------------- /utils/ptrace.c: -------------------------------------------------------------------------------- 1 | /* Simple ptrace test - use PTRACE_ATTACH in a thread 2 | to see if it works; dtrace is having trouble attaching 3 | to a forked/execed proc. 4 | */ 5 | # include 6 | # include 7 | # include 8 | # include 9 | 10 | int pid; 11 | pthread_mutex_t m; 12 | 13 | static void 14 | thread(void *arg) 15 | { 16 | if (fork()) return; 17 | if (ptrace(PTRACE_ATTACH, pid, 0, 0) < 0) { 18 | perror("PTRACE_ATTACH"); 19 | } 20 | printf("about to do PTRACE_CONT \n"); 21 | if (ptrace(PTRACE_CONT, pid, 0, 0) < 0) { 22 | perror("PTRACE_CONT"); 23 | } 24 | printf("PTRACE_CONT executed\n"); 25 | pause(); 26 | } 27 | 28 | int main(int argc, char **argv) 29 | { pthread_t tid; 30 | pthread_attr_t a; 31 | sigset_t nset, oset; 32 | 33 | pid = fork(); 34 | if (pid == 0) { 35 | if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) { 36 | perror("PTRACE_TRACEME"); 37 | } 38 | printf("execing...\n"); 39 | execlp("/bin/date", "/bin/date", NULL); 40 | } 41 | //thread(0); 42 | pthread_mutex_init(&m, NULL); 43 | printf("1: main creating thread\n"); 44 | pthread_mutex_lock(&m); 45 | 46 | (void) pthread_attr_init(&a); 47 | // (void) pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); 48 | (void) sigfillset(&nset); 49 | (void) sigdelset(&nset, SIGABRT); /* unblocked for assert() */ 50 | (void) sigdelset(&nset, SIGUSR1); /* see dt_proc_destroy() */ 51 | // (void) pthread_sigmask(SIG_SETMASK, &nset, &oset); 52 | pthread_create(&tid, &a, thread, NULL); 53 | printf("1: thread created\n"); 54 | pause(); 55 | } 56 | -------------------------------------------------------------------------------- /cmd/ctfconvert/memory.h: -------------------------------------------------------------------------------- 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, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #ifndef _MEMORY_H 28 | #define _MEMORY_H 29 | 30 | #pragma ident "@(#)memory.h 1.3 05/06/08 SMI" 31 | 32 | /* 33 | * Routines for memory management 34 | */ 35 | 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | void *xmalloc(size_t); 43 | void *xcalloc(size_t); 44 | char *xstrdup(const char *); 45 | char *xstrndup(char *, size_t); 46 | void *xrealloc(void *, size_t); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _MEMORY_H */ 53 | --------------------------------------------------------------------------------