# vorher ein 'touch usr/src/cmd/sh/probes.d' machen --- usr/src/cmd/sh/Makefile.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/Makefile Wed Nov 10 05:40:57 2010 @@ -29,7 +29,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 @@ -55,6 +56,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) --- usr/src/cmd/sh/cmd.c.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/cmd.c Wed Nov 10 05:50:59 2010 @@ -76,6 +76,7 @@ t->forktyp = flgs|TFORK; t->forktre = i; t->forkio = 0; + t->line = standin->comline; return((struct trenod *)t); } @@ -94,6 +95,7 @@ t->lsttyp = type; t->lstlef = i; t->lstrit = r; + t->line = standin->comline; } return((struct trenod *)t); } @@ -274,6 +276,8 @@ t = (struct swnod *)getstor(sizeof(struct swnod)); r = (struct trenod *)t; + t->line = standin->comline; + chkword(); if (fndef) t->swarg = make(wdarg->argval); @@ -293,6 +297,7 @@ t = (struct ifnod *)getstor(sizeof(struct ifnod)); r = (struct trenod *)t; + t->line = standin->comline; t->iftyp = TIF; t->iftre = cmd(THSYM, NLFLG); @@ -312,6 +317,7 @@ t->fortyp = TFOR; t->forlst = 0; + t->line = standin->comline; chkword(); if (fndef) t->fornam = make(wdarg->argval); @@ -344,6 +350,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); @@ -359,6 +367,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); @@ -400,6 +409,7 @@ r = (struct trenod *)f; f->fndtyp = TFND; + f->line = standin->comline; f->fndnam = make(wdarg->argval); f->fndref = 0; reserv++; @@ -426,6 +436,8 @@ r = (struct trenod *)t; t->comio = io; /*initial io chain*/ + t->line = standin->comline; + argtail = &(t->comarg); while (wdval == 0) @@ -464,6 +476,7 @@ } t->comtyp = TCOM; + t->line = standin->comline; t->comset = (struct argnod *)argset; *argtail = 0; --- usr/src/cmd/sh/error.c.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/error.c Wed Nov 10 05:40:57 2010 @@ -34,6 +34,7 @@ */ #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); --- usr/src/cmd/sh/main.c.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/main.c Wed Nov 10 05:40:57 2010 @@ -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; } --- usr/src/cmd/sh/mode.h.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/mode.h Wed Nov 10 05:40:57 2010 @@ -95,6 +95,7 @@ { int fdes; unsigned flin; + unsigned comline; /* line number starting last command */ BOOL feof; unsigned char fsiz; unsigned char *fnxt; @@ -139,6 +140,7 @@ struct trenod { int tretyp; + int line; struct ionod *treio; }; @@ -159,6 +161,7 @@ struct forknod { int forktyp; + int line; struct ionod *forkio; struct trenod *forktre; }; @@ -166,6 +169,7 @@ struct comnod { int comtyp; + int line; struct ionod *comio; struct argnod *comarg; struct argnod *comset; @@ -174,6 +178,7 @@ struct fndnod { int fndtyp; + int line; unsigned char *fndnam; struct trenod *fndval; int fndref; @@ -182,6 +187,7 @@ struct ifnod { int iftyp; + int line; struct trenod *iftre; struct trenod *thtre; struct trenod *eltre; @@ -190,6 +196,7 @@ struct whnod { int whtyp; + int line; struct trenod *whtre; struct trenod *dotre; }; @@ -197,6 +204,7 @@ struct fornod { int fortyp; + int line; struct trenod *fortre; unsigned char *fornam; struct comnod *forlst; @@ -205,6 +213,7 @@ struct swnod { int swtyp; + int line; unsigned char *swarg; struct regnod *swlst; }; @@ -219,6 +228,7 @@ struct parnod { int partyp; + int line; struct trenod *partre; }; @@ -225,6 +235,7 @@ struct lstnod { int lsttyp; + int line; struct trenod *lstlef; struct trenod *lstrit; }; --- usr/src/cmd/sh/word.c.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/word.c Wed Nov 10 05:41:22 2010 @@ -303,6 +303,8 @@ } f = standin; + f->comline = f->flin; + retry: if (f->fend > f->fnxt) { /* --- /dev/null Mon Nov 15 03:33:33 2010 +++ usr/src/cmd/sh/probes.d Mon Nov 15 02:50:37 2010 @@ -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, pid_t); + 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 --- usr/src/cmd/sh/xec.c.orig Tue Dec 1 09:41:35 2009 +++ usr/src/cmd/sh/xec.c Mon Nov 15 02:51:09 2010 @@ -40,8 +40,10 @@ #include "hash.h" #include #include +#include pid_t parent; +int lastline = -1; void execprint(unsigned char **); @@ -67,12 +69,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: @@ -125,7 +139,7 @@ case TCOM: { unsigned char *a1, *name; - int argn, internal; + int internal; struct argnod *schain = gchain; struct ionod *io = t->treio; short cmdhash; @@ -176,7 +190,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; } @@ -200,8 +216,10 @@ funcnt++; index = initio(io, 1); setargs(com); + DTRACE_PROBE5(sh, function__entry, cmdadr, *com, t->line, argn, com); execute(f->fndval, xflags, errorflg, pf1, pf2); + DTRACE_PROBE3(sh, function__return, cmdadr, *com, exitval); execbrk = 0; restore(index); (void) restorargs(olddolh, funcnt); @@ -292,7 +310,15 @@ 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); if (treeflgs & FPIN) @@ -301,6 +327,11 @@ postjob(parent,!(treeflgs&FAMP)); freejobs(); } + if (type != TFORK) { + DTRACE_PROBE3(sh, command__return, cmdadr, *com, exitval); + } else { + DTRACE_PROBE3(sh, subshell__return, cmdadr, exitval, parent); + } chktrap(); break; }