xref: /plan9/sys/src/cmd/rc/pfnc.c (revision 4d44ba9b9ee4246ddbd96c7fcaf0918ab92ab35a)
1 #include "rc.h"
2 #include "exec.h"
3 #include "io.h"
4 #include "fns.h"
5 struct{
6 	void (*f)(void);
7 	char *name;
8 }fname[] = {
9 	Xappend, "Xappend",
10 	Xasync, "Xasync",
11 	Xbang, "Xbang",
12 	Xclose, "Xclose",
13 	Xdup, "Xdup",
14 	Xeflag, "Xeflag",
15 	Xexit, "Xexit",
16 	Xfalse, "Xfalse",
17 	Xifnot, "Xifnot",
18 	Xjump, "Xjump",
19 	Xmark, "Xmark",
20 	Xpopm, "Xpopm",
21 	Xrdwr, "Xrdwr",
22 	Xread, "Xread",
23 	Xreturn, "Xreturn",
24 	Xtrue, "Xtrue",
25 	Xif, "Xif",
26 	Xwastrue, "Xwastrue",
27 	Xword, "Xword",
28 	Xwrite, "Xwrite",
29 	Xmatch, "Xmatch",
30 	Xcase, "Xcase",
31 	Xconc, "Xconc",
32 	Xassign, "Xassign",
33 	Xdol, "Xdol",
34 	Xcount, "Xcount",
35 	Xlocal, "Xlocal",
36 	Xunlocal, "Xunlocal",
37 	Xfn, "Xfn",
38 	Xdelfn, "Xdelfn",
39 	Xpipe, "Xpipe",
40 	Xpipewait, "Xpipewait",
41 	Xrdcmds, "Xrdcmds",
42 	(void (*)(void))Xerror, "Xerror",
43 	Xbackq, "Xbackq",
44 	Xpipefd, "Xpipefd",
45 	Xsubshell, "Xsubshell",
46 	Xdelhere, "Xdelhere",
47 	Xfor, "Xfor",
48 	Xglob, "Xglob",
49 	Xrdfn, "Xrdfn",
50 	Xsimple, "Xsimple",
51 	Xrdfn, "Xrdfn",
52 	Xqdol, "Xqdol",
53 0};
54 
55 void
56 pfnc(io *fd, thread *t)
57 {
58 	int i;
59 	void (*fn)(void) = t->code[t->pc].f;
60 	list *a;
61 	pfmt(fd, "pid %d cycle %p %d ", getpid(), t->code, t->pc);
62 	for(i = 0;fname[i].f;i++) if(fname[i].f==fn){
63 		pstr(fd, fname[i].name);
64 		break;
65 	}
66 	if(!fname[i].f)
67 		pfmt(fd, "%p", fn);
68 	for(a = t->argv;a;a = a->next) pfmt(fd, " (%v)", a->words);
69 	pchr(fd, '\n');
70 	flush(fd);
71 }
72