1 include("/sys/lib/acid/syscall");
3 // print various /proc files
5 rc("cat /proc/"+itoa(pid)+"/fd");
9 rc("cat /proc/"+itoa(pid)+"/segment");
13 rc("cat /proc/"+itoa(pid)+"/ns");
18 return itoa(qid.path\X)+"."+itoa(qid.vers\X);
29 // print Image cache contents
30 // requires include("/sys/src/9/xxx/segment.acid")
32 defn imagecacheline(h) {
35 print (h\X, " ", qid(h.qid), " type ", h.type\D, " ref ", h.ref, " next ", h.next\X, " ", cname(h.c.name), "\n");
43 i=0; loop 1,IHASHSIZE do {
44 imagecacheline(imagealloc.free[i]);
54 d=(Dev)(*(devtab+4*c.type));
56 print(c\X, " ref=", c.ref\D, " #", d.dc\r, c.dev\D, " (", q.path, " ", q.vers\D, " ", q.type\X, ")");
57 print(" fid=", c.fid\D, " iounit=", c.iounit\D);
59 print(" ", cname(c.name), " mchan=", c.mchan\X);
60 if c.mchan != 0 then {
61 print(" ", cname(c.mchan.name));
70 c = (Chan)chanalloc.list;
77 // manipulate processes
79 return procalloc.arena+sizeofProc*x;
86 if p.state != 0 then { // 0 is Dead
93 print(p\X, " ", p.pid, ": ", *(p.text\s), " ", *(p.user\s), " pc ", p.pc\X, " ", s, " (", *(statename[p.state]\s), ") ut ", p.time[0]\D, " st ", p.time[1]\D, " qpc ", p.qpc\X, "\n");
106 print(*(v.name\s), "=");
107 printstringn(v.value, v.len);
115 defn procstksize(p) {
119 if p.state != 0 then { // 0 is Dead
120 top = p.kstack+KSTACK;
122 print(top-sp\D, "\n");
130 if p.state != 0 then { // 0 is Dead
132 if objtype=="386" then
133 _stk(gotolabel, *l, linkreg(0), 0);
135 _stk(*(l+4), *l, linkreg(0), 0);
142 i=0; loop 1,conf.nproc do {
151 i=0; loop 1,conf.nproc do {
152 p = (Proc)proctab(i);
153 if p.state != 0 then {
154 print("=========================================================\n");
165 i=0; loop 1,conf.nproc do {
166 procstksize(proctab(i));
176 i=0; loop 1,NSEG do {
182 segtypes = { "text", "data", "bss", "stack", "shared", "physical", "shdata", "map" };
187 print(s\X, " ", segtypes[s.type&SG_TYPE], " ", s.base\X, "-", s.top\X, " image ", s.image\X, "\n");
191 // find physical address for an address in a given process
192 defn procaddr(p, a) {
197 i=0; loop 1,NSEG do {
201 if s.base <= a && a < s.top then {
210 // find an address in a given segment
216 if s.map == 0 || s.mapsize < a/PTEMAPMEM then {
220 pte = s.map[a/PTEMAPMEM];
226 pg = pte.pages[(a%PTEMAPMEM)/BY2PG];
231 if pg & 1 then { // swapped out, return disk address
236 return (0x80000000|(pg.pa+(a%BY2PG)))\X;
240 MACHADDR = 0x80004000;
241 PTEMAPMEM = (1024*1024);
243 PTEPERTAB = (PTEMAPMEM/BY2PG);
249 return mach.externup;
253 local p, pp, t, i, j;
267 print(itoa(i, "%5d"), " ", itoa(t, "%11d"), "\n");
275 print("\trc(\"cd /sys/src/9/", kdir, "; mk ", s, ".acid\")\n");
276 print("\tinclude(\"/sys/src/9/", kdir, "/", s, ".acid\")\n");
279 if (map()[2]) != {} then { // map has more than two elements -> active proc
282 if objtype == "386" then {
283 map({"*data", 0x80000000, 0xffffffff, 0x80000000});
286 if (objtype == "mips" || objtype == "mips2") then {
289 if objtype == "alpha" then {
290 map({"*data", 0x80000000, 0xffffffff, 0x80000000});