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
32 defn imagecacheline(h) {
38 d=(Dev)devtab[h.type];
43 print (h\A, " ref=", h.ref, " pgref=", h.pgref, "\t#", d.dc\r, h.dev\D, " (",
44 q.path, " ", q.vers\D, " ", q.type\X, ") ", p, "\n");
52 i=0; loop 1,IHASHSIZE do {
53 imagecacheline(imagealloc.hash[i]);
63 d= (Dev)devtab[c.type];
65 print("chan(", c\A, "): ref=", c.ref\D, " #", d.dc\r, c.dev\D, " (", q.path, " ", q.vers\D, " ", q.type\X, ")");
66 print(" fid=", c.fid\D, " iounit=", c.iounit\D);
68 print(" ", path(c.path), " mchan=", c.mchan\A);
69 if c.mchan != 0 then {
70 print(" ", path(c.mchan.path));
79 c = (Chan)chanalloc.list;
87 defn findchan(dev,type,path) {
90 c = (Chan)chanalloc.list;
93 if c.dev == dev && c.type == type && c.qid.path == path then
105 c = (Chan)chanalloc.list;
114 defn activechanlist() {
118 c = (Chan)chanalloc.list;
127 defn difflist(a, b) {
133 if match(x, b) == -1 then
140 _active_chan_list = {};
144 l = activechanlist();
145 if _active_chan_list != {} then
146 newerchans(_active_chan_list);
147 _active_chan_list = l;
150 defn newerchans(oldlist){
153 new = difflist(activechanlist(), oldlist);
160 // look for channels that refer to themselves
162 local bad, c, i, len, mtpt, p;
164 c = (Chan)chanalloc.list;
175 bad = bad+" mtpt self-ref";
180 print("chan(", c\A, "):", bad, "\n");
190 i=0; loop 1,NHASH do {
194 print(m\A, " dev ", m.dev\D, " type ", m.type, " qid (",
195 m.qid.path, " ", m.qid.vers\D, ")\n");
196 c = findchan(m.dev, m.type, m.qid.path);
207 // manipulate processes
209 return procalloc.arena+sizeofProc*x;
216 if p.state != 0 && p.pid != 0 && p.text != 0 then { // 0 is Dead
223 print(p\A, " ", p.pid, ": ", *(p.text\s), " ", *(p.user\s), " pc ", p.pc, " ", s, " (", *(statename[p.state]\s), ") ut ", p.time[0]\D, " st ", p.time[1]\D, " qpc ", p.qpc, "\n");
233 i=0; loop 1,e.nent do {
237 print(*(v.name\s), "=");
238 printstringn(v.value, v.len);
244 if objtype=="amd64" then {
248 defn procstksize(p) {
252 if p.state != 0 then { // 0 is Dead
253 top = p.kstack+KSTACK;
255 print(top-sp\D, "\n");
263 if p.state != 0 then { // 0 is Dead
265 if objtype=="386" || objtype=="amd64" then
266 _stk(gotolabel, *l, linkreg(0), 0);
268 _stk(*(l+4), *l, linkreg(0), 0);
275 i=0; loop 1,conf.nproc do {
284 i=0; loop 1,conf.nproc do {
285 p = (Proc)proctab(i);
286 if p.state != 0 then {
287 print("=========================================================\n");
298 i=0; loop 1,conf.nproc do {
299 procstksize(proctab(i));
309 i=0; loop 1,NSEG do {
315 segtypes = { "text", "data", "bss", "stack", "shared", "physical", "shdata", "map" };
320 print(s\A, " ", segtypes[s.type&SG_TYPE], " ", s.base, "-", s.top, " image ", s.image, "\n");
324 // find physical address for an address in a given process
325 defn procaddr(p, a) {
330 i=0; loop 1,NSEG do {
334 if s.base <= a && a < s.top then {
343 // find an address in a given segment
349 if s.map == 0 || s.mapsize < a/PTEMAPMEM then {
353 pte = s.map[a/PTEMAPMEM];
359 pg = pte.pages[(a%PTEMAPMEM)/BY2PG];
364 if pg & 1 then { // swapped out, return disk address
369 return (KZERO|(pg.pa+(a%BY2PG)))\A;
373 return main - (main & 0x0FFFFFFF);
376 PTEMAPMEM = (1024*1024);
378 PTEPERTAB = (PTEMAPMEM/BY2PG);
380 if objtype == "386" then {
383 MACHADDR = KZERO+0x15000;
386 return mach.externup;
388 if objtype == "amd64" then {
395 print("up() not implemented for", objtype, "\n");
409 print(itoa(i, "%5d"), " ", itoa(t, "%11d"), "\n");
415 print("\trc(\"cd /sys/src/9/", kdir, "; mk ", s, ".acid\")\n");
416 print("\tinclude(\"/sys/src/9/", kdir, "/", s, ".acid\")\n");
420 if (map()[2]) != {} then { // map has more than two elements -> active proc
424 if objtype == "386" then {
425 map({"*data", KZERO, 0xffffffff, KZERO});
428 if objtype == "amd64" then {
429 map({"*data", KZERO, 0xffffffffffffffff, KZERO});
432 if (objtype == "mips" || objtype == "mips2") then {
435 if objtype == "alpha" then {
436 map({"*data", KZERO, 0xffffffff, KZERO});