snap: add debug flag, make debug less verbose

This commit is contained in:
cinap_lenrek 2018-11-22 15:09:54 +01:00
parent 9d471caaae
commit 6bd0764167
4 changed files with 25 additions and 11 deletions

View file

@ -124,7 +124,7 @@ readdata(Biobuf *b)
} }
static Seg* static Seg*
readseg(Seg **ps, Biobuf *b, Proc *plist) readseg(Seg **ps, Biobuf *b, Proc *plist, char *name)
{ {
Seg *s; Seg *s;
Page **pp; Page **pp;
@ -141,6 +141,9 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
|| Breaduvlong(b, &s->len) < 0) || Breaduvlong(b, &s->len) < 0)
sysfatal("error reading segment: %r"); 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; npg = (s->len + Pagesize-1)/Pagesize;
s->npg = npg; s->npg = npg;
@ -159,7 +162,7 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
switch(t = Bgetc(b)) { switch(t = Bgetc(b)) {
case 'z': case 'z':
pp[i] = datapage(zeros, len); pp[i] = datapage(zeros, len);
if(debug) if(debug > 1)
fprint(2, "0x%.8llux all zeros\n", s->offset+(uvlong)i*Pagesize); fprint(2, "0x%.8llux all zeros\n", s->offset+(uvlong)i*Pagesize);
break; break;
case 'm': case 'm':
@ -170,7 +173,7 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
pp[i] = findpage(plist, pid, t, off); pp[i] = findpage(plist, pid, t, off);
if(pp[i] == nil) if(pp[i] == nil)
sysfatal("bad page reference in snapshot"); sysfatal("bad page reference in snapshot");
if(debug) if(debug > 1)
fprint(2, "0x%.8llux same as %s pid %lud 0x%.8llux\n", fprint(2, "0x%.8llux same as %s pid %lud 0x%.8llux\n",
s->offset+(uvlong)i*Pagesize, t=='m'?"mem":"text", pid, off); s->offset+(uvlong)i*Pagesize, t=='m'?"mem":"text", pid, off);
break; break;
@ -178,7 +181,7 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
if((n=Bread(b, buf, len)) != len) if((n=Bread(b, buf, len)) != len)
sysfatal("short read of segment %d/%d at %llx: %r", n, len, Boffset(b)); sysfatal("short read of segment %d/%d at %llx: %r", n, len, Boffset(b));
pp[i] = datapage(buf, len); pp[i] = datapage(buf, len);
if(debug) if(debug > 1)
fprint(2, "0x%.8llux is raw data\n", s->offset+(uvlong)i*Pagesize); fprint(2, "0x%.8llux is raw data\n", s->offset+(uvlong)i*Pagesize);
break; break;
default: default:
@ -233,11 +236,13 @@ readsnap(Biobuf *b)
sysfatal("bad segment count: %d", n); sysfatal("bad segment count: %d", n);
p->nseg = n; p->nseg = n;
p->seg = emalloc(n*sizeof(*p->seg)); p->seg = emalloc(n*sizeof(*p->seg));
for(i=0; i<n; i++) for(i=0; i<n; i++){
readseg(&p->seg[i], b, plist); snprint(buf, sizeof(buf), "[%d]", i);
} else if(strcmp(q, "text") == 0) readseg(&p->seg[i], b, plist, buf);
readseg(&p->text, b, plist); }
else } else if(strcmp(q, "text") == 0) {
readseg(&p->text, b, plist, q);
} else
sysfatal("unknown section"); sysfatal("unknown section");
} }
return plist; return plist;

View file

@ -6,7 +6,7 @@
void void
usage(void) usage(void)
{ {
fprint(2, "usage: %s [-o snapfile] pid...\n", argv0); fprint(2, "usage: %s [-d] [-o snapfile] pid...\n", argv0);
exits("usage"); exits("usage");
} }
@ -22,6 +22,9 @@ main(int argc, char **argv)
ofile = "/fd/1"; ofile = "/fd/1";
ARGBEGIN{ ARGBEGIN{
case 'd':
debug++;
break;
case 'o': case 'o':
ofile = ARGF(); ofile = ARGF();
break; break;

View file

@ -139,7 +139,7 @@ main(int argc, char **argv)
chatty9p++; chatty9p++;
break; break;
case 'd': case 'd':
debug = 1; debug++;
break; break;
case 'a': case 'a':
mflag = MAFTER; mflag = MAFTER;

View file

@ -89,6 +89,9 @@ readseg(int fd, uvlong off, uvlong len, char *name)
Seg *s; Seg *s;
int n; int n;
if(debug)
fprint(2, "readseg %.8llux - %.8llux %s\n", off, off+len, name);
s = emalloc(sizeof(*s)); s = emalloc(sizeof(*s));
s->name = estrdup(name); s->name = estrdup(name);
if(seek(fd, off, 0) < 0) { if(seek(fd, off, 0) < 0) {
@ -263,6 +266,9 @@ snap(long pid, int usetext)
/* stack hack: figure sp so don't need to page in the whole segment */ /* stack hack: figure sp so don't need to page in the whole segment */
if(stacklen) { if(stacklen) {
sp = stackptr(proc, fd); sp = stackptr(proc, fd);
if(debug)
fprint(2, "stackseg %.8llux - %.8llux sp %.8llux\n",
stackoff, stackoff+stacklen, sp);
if(stackoff <= sp && sp < stackoff+stacklen) { if(stackoff <= sp && sp < stackoff+stacklen) {
off = sp - 8*1024; off = sp - 8*1024;
} else { /* stack pointer not in segment. thread library? */ } else { /* stack pointer not in segment. thread library? */