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*
readseg(Seg **ps, Biobuf *b, Proc *plist)
readseg(Seg **ps, Biobuf *b, Proc *plist, char *name)
{
Seg *s;
Page **pp;
@ -141,6 +141,9 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
|| 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 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
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 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
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 @@ readseg(Seg **ps, Biobuf *b, Proc *plist)
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 @@ readsnap(Biobuf *b)
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;

View file

@ -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 @@ main(int argc, char **argv)
ofile = "/fd/1";
ARGBEGIN{
case 'd':
debug++;
break;
case 'o':
ofile = ARGF();
break;

View file

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

View file

@ -89,6 +89,9 @@ readseg(int fd, uvlong off, uvlong len, char *name)
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 @@ snap(long pid, int usetext)
/* 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? */