ref: 6bd0764167a0fbebb5ee90bf1a9c30e8d119442b
parent: 9d471caaae56a734728c3b19755adfe26f6c4f4c
author: cinap_lenrek <[email protected]>
date: Thu Nov 22 10:09:54 EST 2018
snap: add debug flag, make debug less verbose
--- a/sys/src/cmd/snap/read.c
+++ b/sys/src/cmd/snap/read.c
@@ -124,7 +124,7 @@
}
static Seg*
-readseg(Seg **ps, Biobuf *b, Proc *plist)
+readseg(Seg **ps, Biobuf *b, Proc *plist, char *name)
{
Seg *s;
Page **pp;
@@ -141,6 +141,9 @@
|| Breaduvlong(b, &s->len) < 0)
sysfatal("error reading segment: %r");
+ if(debug)
+ fprint(2, "readseg %.8llux - %.8llux %s\n", s->offset, s->offset + s->len, name);
+
npg = (s->len + Pagesize-1)/Pagesize;
s->npg = npg;
@@ -159,7 +162,7 @@
switch(t = Bgetc(b)) {
case 'z':
pp[i] = datapage(zeros, len);
- if(debug)
+ if(debug > 1)
fprint(2, "0x%.8llux all zeros\n", s->offset+(uvlong)i*Pagesize);
break;
case 'm':
@@ -170,7 +173,7 @@
pp[i] = findpage(plist, pid, t, off);
if(pp[i] == nil)
sysfatal("bad page reference in snapshot");
- if(debug)
+ if(debug > 1)
fprint(2, "0x%.8llux same as %s pid %lud 0x%.8llux\n",
s->offset+(uvlong)i*Pagesize, t=='m'?"mem":"text", pid, off);
break;
@@ -178,7 +181,7 @@
if((n=Bread(b, buf, len)) != len)
sysfatal("short read of segment %d/%d at %llx: %r", n, len, Boffset(b));
pp[i] = datapage(buf, len);
- if(debug)
+ if(debug > 1)
fprint(2, "0x%.8llux is raw data\n", s->offset+(uvlong)i*Pagesize);
break;
default:
@@ -233,11 +236,13 @@
sysfatal("bad segment count: %d", n);
p->nseg = n;
p->seg = emalloc(n*sizeof(*p->seg));
- for(i=0; i<n; i++)
- readseg(&p->seg[i], b, plist);
- } else if(strcmp(q, "text") == 0)
- readseg(&p->text, b, plist);
- else
+ for(i=0; i<n; i++){
+ snprint(buf, sizeof(buf), "[%d]", i);
+ readseg(&p->seg[i], b, plist, buf);
+ }
+ } else if(strcmp(q, "text") == 0) {
+ readseg(&p->text, b, plist, q);
+ } else
sysfatal("unknown section");
}
return plist;
--- a/sys/src/cmd/snap/snap.c
+++ b/sys/src/cmd/snap/snap.c
@@ -6,7 +6,7 @@
void
usage(void)
{
- fprint(2, "usage: %s [-o snapfile] pid...\n", argv0);
+ fprint(2, "usage: %s [-d] [-o snapfile] pid...\n", argv0);
exits("usage");
}
@@ -22,6 +22,9 @@
ofile = "/fd/1";
ARGBEGIN{
+ case 'd':
+ debug++;
+ break;
case 'o':
ofile = ARGF();
break;
--- a/sys/src/cmd/snap/snapfs.c
+++ b/sys/src/cmd/snap/snapfs.c
@@ -139,7 +139,7 @@
chatty9p++;
break;
case 'd':
- debug = 1;
+ debug++;
break;
case 'a':
mflag = MAFTER;
--- a/sys/src/cmd/snap/take.c
+++ b/sys/src/cmd/snap/take.c
@@ -89,6 +89,9 @@
Seg *s;
int n;
+ if(debug)
+ fprint(2, "readseg %.8llux - %.8llux %s\n", off, off+len, name);
+
s = emalloc(sizeof(*s));
s->name = estrdup(name);
if(seek(fd, off, 0) < 0) {
@@ -263,6 +266,9 @@
/* stack hack: figure sp so don't need to page in the whole segment */
if(stacklen) {
sp = stackptr(proc, fd);
+ if(debug)
+ fprint(2, "stackseg %.8llux - %.8llux sp %.8llux\n",
+ stackoff, stackoff+stacklen, sp);
if(stackoff <= sp && sp < stackoff+stacklen) {
off = sp - 8*1024;
} else { /* stack pointer not in segment. thread library? */