xref: /plan9/sys/src/cmd/rc/pfnc.c (revision 9b943567965ba040fd275927fbe088656eb8ce4f)
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 	Xread, "Xread",
22 	Xreturn, "Xreturn",
23 	Xtrue, "Xtrue",
24 	Xif, "Xif",
25 	Xwastrue, "Xwastrue",
26 	Xword, "Xword",
27 	Xwrite, "Xwrite",
28 	Xmatch, "Xmatch",
29 	Xcase, "Xcase",
30 	Xconc, "Xconc",
31 	Xassign, "Xassign",
32 	Xdol, "Xdol",
33 	Xcount, "Xcount",
34 	Xlocal, "Xlocal",
35 	Xunlocal, "Xunlocal",
36 	Xfn, "Xfn",
37 	Xdelfn, "Xdelfn",
38 	Xpipe, "Xpipe",
39 	Xpipewait, "Xpipewait",
40 	Xrdcmds, "Xrdcmds",
41 	(void (*)(void))Xerror, "Xerror",
42 	Xbackq, "Xbackq",
43 	Xpipefd, "Xpipefd",
44 	Xsubshell, "Xsubshell",
45 	Xdelhere, "Xdelhere",
46 	Xfor, "Xfor",
47 	Xglob, "Xglob",
48 	Xrdfn, "Xrdfn",
49 	Xsimple, "Xsimple",
50 	Xrdfn, "Xrdfn",
51 	Xqdol, "Xqdol",
52 0};
53 
54 void
55 pfnc(io *fd, thread *t)
56 {
57 	int i;
58 	void (*fn)(void) = t->code[t->pc].f;
59 	list *a;
60 	pfmt(fd, "pid %d cycle %p %d ", getpid(), t->code, t->pc);
61 	for(i = 0;fname[i].f;i++) if(fname[i].f==fn){
62 		pstr(fd, fname[i].name);
63 		break;
64 	}
65 	if(!fname[i].f)
66 		pfmt(fd, "%p", fn);
67 	for(a = t->argv;a;a = a->next) pfmt(fd, " (%v)", a->words);
68 	pchr(fd, '\n');
69 	flush(fd);
70 }
71