Index: usr/src/cmd/sh/Makefile --- /ws/onnv-clone/usr/src/cmd/sh/Makefile Thu May 17 23:11:56 2007 +++ usr/src/cmd/sh/Makefile Mon Aug 20 01:09:12 2007 @@ -31,7 +31,8 @@ OBJS= args.o blok.o cmd.o defs.o error.o fault.o hash.o hashserv.o \ io.o msg.o print.o stak.o string.o word.o xec.o \ ctype.o echo.o expand.o func.o macro.o pwd.o setbrk.o test.o \ - bltin.o jobs.o ulimit.o sh_policy.o main.o name.o service.o + bltin.o jobs.o ulimit.o sh_policy.o main.o name.o service.o \ + probes.o SRCS= $(OBJS:%.o=%.c) include ../Makefile.cmd @@ -60,6 +61,9 @@ all: $(ROOTFS_PROG) +probes.o: error.o main.o word.o xec.o probes.d + dtrace -32 -G -s probes.d error.o main.o word.o xec.o + $(PROG): $(OBJS) $(MAPFILES) $(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) Index: usr/src/cmd/sh/cmd.c --- /ws/onnv-clone/usr/src/cmd/sh/cmd.c Wed Jun 21 23:06:32 2006 +++ usr/src/cmd/sh/cmd.c Mon Aug 20 01:09:14 2007 @@ -77,6 +77,7 @@ t->forktyp = flgs|TFORK; t->forktre = i; t->forkio = 0; + t->line = standin->comline; return((struct trenod *)t); } @@ -95,6 +96,7 @@ t->lsttyp = type; t->lstlef = i; t->lstrit = r; + t->line = standin->comline; } return((struct trenod *)t); } @@ -275,6 +277,8 @@ t = (struct swnod *)getstor(sizeof(struct swnod)); r = (struct trenod *)t; + t->line = standin->comline; + chkword(); if (fndef) t->swarg = make(wdarg->argval); @@ -294,6 +298,7 @@ t = (struct ifnod *)getstor(sizeof(struct ifnod)); r = (struct trenod *)t; + t->line = standin->comline; t->iftyp = TIF; t->iftre = cmd(THSYM, NLFLG); @@ -313,6 +318,7 @@ t->fortyp = TFOR; t->forlst = 0; + t->line = standin->comline; chkword(); if (fndef) t->fornam = make(wdarg->argval); @@ -345,6 +351,8 @@ t = (struct whnod *)getstor(sizeof(struct whnod)); r = (struct trenod *)t; + t->line = standin->comline; + t->whtyp = (wdval == WHSYM ? TWH : TUN); t->whtre = cmd(DOSYM, NLFLG); t->dotre = cmd(ODSYM, NLFLG); @@ -360,6 +368,7 @@ struct parnod *p; p = (struct parnod *)getstor(sizeof(struct parnod)); + p->line = standin->comline; p->partre = cmd(')', NLFLG); p->partyp = TPAR; r = makefork(0, p); @@ -393,6 +402,8 @@ r = (struct trenod *)f; f->fndtyp = TFND; + f->line = standin->comline; + if (fndef) f->fndnam = make(wdarg->argval); else @@ -422,6 +433,8 @@ r = (struct trenod *)t; t->comio = io; /*initial io chain*/ + t->line = standin->comline; + argtail = &(t->comarg); while (wdval == 0) @@ -460,6 +473,7 @@ } t->comtyp = TCOM; + t->line = standin->comline; t->comset = (struct argnod *)argset; *argtail = 0; Index: usr/src/cmd/sh/error.c --- /ws/onnv-clone/usr/src/cmd/sh/error.c Wed Jun 21 23:06:32 2006 +++ usr/src/cmd/sh/error.c Mon Aug 20 01:09:15 2007 @@ -32,8 +32,9 @@ /* * UNIX shell */ #include "defs.h" +#include /* ======== error handling ======== */ @@ -94,6 +95,7 @@ * Action is to return to command level or exit. */ exitval = xno; + DTRACE_PROBE2(sh, script__done, cmdadr, exitval); flags |= eflag; if ((flags & (forcexit | forked | errflg | ttyflg)) != ttyflg) done(0); Index: usr/src/cmd/sh/main.c --- /ws/onnv-clone/usr/src/cmd/sh/main.c Wed Jun 21 23:06:32 2006 +++ usr/src/cmd/sh/main.c Mon Aug 20 01:09:17 2007 @@ -46,6 +46,8 @@ #include #endif +#include + pid_t mypid, mypgid, mysid; static BOOL beenhere = FALSE; @@ -388,6 +390,7 @@ /* * command loop */ + DTRACE_PROBE1(sh, script__start, cmdadr); for (;;) { tdystak(0); stakchk(); /* may reduce sbrk */ @@ -419,8 +422,10 @@ trapnote = 0; peekc = readwc(); if (eof) { - if (endjobs(JOB_STOPPED)) + if (endjobs(JOB_STOPPED)) { + DTRACE_PROBE2(sh, script__done, cmdadr, exitval); return; + } eof = 0; } Index: usr/src/cmd/sh/mode.h --- /ws/onnv-clone/usr/src/cmd/sh/mode.h Fri May 19 23:04:13 2006 +++ usr/src/cmd/sh/mode.h Mon Aug 20 01:09:19 2007 @@ -97,6 +97,7 @@ { int fdes; unsigned flin; + unsigned comline; /* line number starting last command */ BOOL feof; unsigned char fsiz; unsigned char *fnxt; @@ -141,6 +142,7 @@ struct trenod { int tretyp; + int line; struct ionod *treio; }; @@ -161,6 +163,7 @@ struct forknod { int forktyp; + int line; struct ionod *forkio; struct trenod *forktre; }; @@ -168,6 +171,7 @@ struct comnod { int comtyp; + int line; struct ionod *comio; struct argnod *comarg; struct argnod *comset; @@ -176,6 +180,7 @@ struct fndnod { int fndtyp; + int line; unsigned char *fndnam; struct trenod *fndval; }; @@ -183,6 +188,7 @@ struct ifnod { int iftyp; + int line; struct trenod *iftre; struct trenod *thtre; struct trenod *eltre; @@ -191,6 +197,7 @@ struct whnod { int whtyp; + int line; struct trenod *whtre; struct trenod *dotre; }; @@ -198,6 +205,7 @@ struct fornod { int fortyp; + int line; struct trenod *fortre; unsigned char *fornam; struct comnod *forlst; @@ -206,6 +214,7 @@ struct swnod { int swtyp; + int line; unsigned char *swarg; struct regnod *swlst; }; @@ -220,6 +229,7 @@ struct parnod { int partyp; + int line; struct trenod *partre; }; @@ -226,6 +236,7 @@ struct lstnod { int lsttyp; + int line; struct trenod *lstlef; struct trenod *lstrit; }; --- /dev/null Mon Aug 20 01:11:56 2007 +++ usr/src/cmd/sh/probes.d Mon Aug 20 01:09:20 2007 @@ -1,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)probes.d 1.1 07/08/20 SMI" + +provider sh { + probe function__entry(char *, char *, int, int, char **); + probe function__return(char *, char *, int); + probe builtin__entry(char *, char *, int, int, char **); + probe builtin__return(char *, char *, int); + probe script__start(char *); + probe script__done(char *, int); + probe command__entry(char *, char *, int, int, char **); + probe command__return(char *, char *, int); + probe subshell__entry(char *, pid_t, int); + probe subshell__return(char *, int); + probe line(char *, int); +}; + +#pragma D attributes Unstable/Unstable/Common provider sh provider +#pragma D attributes Private/Private/Unknown provider sh module +#pragma D attributes Private/Private/Unknown provider sh function +#pragma D attributes Unstable/Unstable/Common provider sh name +#pragma D attributes Unstable/Unstable/Common provider sh args Index: usr/src/cmd/sh/word.c --- /ws/onnv-clone/usr/src/cmd/sh/word.c Fri Feb 10 16:13:11 2006 +++ usr/src/cmd/sh/word.c Mon Aug 20 01:09:22 2007 @@ -303,6 +303,8 @@ } f = standin; + f->comline = f->flin; + retry: if (f->fend > f->fnxt) { /* Index: usr/src/cmd/sh/xec.c --- /ws/onnv-clone/usr/src/cmd/sh/xec.c Wed Jun 21 23:06:33 2006 +++ usr/src/cmd/sh/xec.c Mon Aug 20 01:09:23 2007 @@ -41,8 +41,10 @@ #include "hash.h" #include #include +#include pid_t parent; +int lastline = -1; void execprint(unsigned char **); @@ -68,12 +70,24 @@ if ((t = argt) && execbrk == 0) { int treeflgs; unsigned char **com; - int type; + int type, argn; short pos; treeflgs = t->tretyp; type = treeflgs & COMMSK; + if (t->line != lastline) { + switch(type) { + case TFORK: + case TLST: + case TFND: + break; + default: + DTRACE_PROBE2(sh, line, cmdadr, t->line); + lastline = t->line; + } + } + switch (type) { case TFND: @@ -112,7 +126,7 @@ case TCOM: { unsigned char *a1, *name; - int argn, internal; + int internal; struct argnod *schain = gchain; struct ionod *io = t->treio; short cmdhash; @@ -163,7 +177,9 @@ } else if (comtype == BUILTIN) { + DTRACE_PROBE5(sh, builtin__entry, cmdadr, *com, t->line, argn, com); builtin(hashdata(cmdhash),argn,com,t); + DTRACE_PROBE3(sh, builtin__return, cmdadr, *com, exitval); freejobs(); break; } @@ -180,7 +196,9 @@ funcnt++; index = initio(io, 1); setargs(com); + DTRACE_PROBE5(sh, function__entry, cmdadr, *com, t->line, argn, com); execute((struct trenod *)(n->namenv), xflags, errorflg, pf1, pf2); + DTRACE_PROBE3(sh, function__return, cmdadr, *com, exitval); execbrk = 0; restore(index); (void) restorargs(olddolh, funcnt); @@ -264,6 +282,14 @@ sh_sleep(forkcnt); } + if (type != TFORK) { + if (parent) { + DTRACE_PROBE5(sh, command__entry, cmdadr, *com, t->line, argn, com); + } + } else { + DTRACE_PROBE3(sh, subshell__entry, cmdadr, parent, t->line); + } + if (parent) { if (monitor) setpgid(parent, 0); @@ -273,6 +299,11 @@ postjob(parent,!(treeflgs&FAMP)); freejobs(); } + if (type != TFORK) { + DTRACE_PROBE3(sh, command__return, cmdadr, *com, exitval); + } else { + DTRACE_PROBE2(sh, subshell__return, cmdadr, exitval); + } chktrap(); break; }