1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:07:00 -07:00

new flags to 6cov

-s	print source lines
	-n x	don't print about sections < x lines long.

R=r
DELTA=69  (57 added, 1 deleted, 11 changed)
OCL=19697
CL=19708
This commit is contained in:
Russ Cox 2008-11-20 11:58:07 -08:00
parent 2e7e76073a
commit 4af8ef6519

View File

@ -21,7 +21,7 @@ typedef struct Ureg Ureg;
void void
usage(void) usage(void)
{ {
fprint(2, "usage: cov [-lv] [-g regexp] [6.out args...]\n"); fprint(2, "usage: cov [-lsv] [-g regexp] [-m minlines] [6.out args...]\n");
fprint(2, "-g specifies pattern of interesting functions or files\n"); fprint(2, "-g specifies pattern of interesting functions or files\n");
exits("usage"); exits("usage");
} }
@ -37,12 +37,14 @@ int chatty;
int fd; int fd;
int longnames; int longnames;
int pid; int pid;
int doshowsrc;
Map *mem; Map *mem;
Map *text; Map *text;
Fhdr fhdr; Fhdr fhdr;
Reprog *grep; Reprog *grep;
char cwd[1000]; char cwd[1000];
int ncwd; int ncwd;
int minlines = -1000;
Tree breakpoints; // code ranges not run Tree breakpoints; // code ranges not run
@ -106,6 +108,37 @@ ran(uvlong pc, uvlong epc)
} }
} }
void
showsrc(char *file, int line1, int line2)
{
Biobuf *b;
char *p;
int n, stop;
if((b = Bopen(file, OREAD)) == nil) {
print("\topen %s: %r\n", file);
return;
}
for(n=1; n<line1 && (p = Brdstr(b, '\n', 1)) != nil; n++)
free(p);
// print up to five lines (this one and 4 more).
// if there are more than five lines, print 4 and "..."
stop = n+4;
if(stop > line2)
stop = line2;
if(stop < line2)
stop--;
for(; n<=stop && (p = Brdstr(b, '\n', 1)) != nil; n++) {
print(" %d %s\n", n, p);
free(p);
}
if(n < line2)
print(" ...\n");
Bterm(b);
}
/* /*
* if s is in the current directory or below, * if s is in the current directory or below,
* return the relative path. * return the relative path.
@ -125,20 +158,36 @@ shortname(char *s)
void void
missing(uvlong pc, uvlong epc) missing(uvlong pc, uvlong epc)
{ {
char src1[1000]; char file[1000];
char src2[1000]; int line1, line2;
char buf[100]; char buf[100];
Symbol s; Symbol s;
char *p; char *p;
uvlong uv;
if(!findsym(pc, CTEXT, &s) || !fileline(src1, sizeof src1, pc) || !fileline(src2, sizeof src2, pc)) { if(!findsym(pc, CTEXT, &s) || !fileline(file, sizeof file, pc)) {
notfound:
print("%#llux-%#llux\n", pc, epc); print("%#llux-%#llux\n", pc, epc);
return; return;
} }
p = strrchr(file, ':');
*p++ = 0;
line1 = atoi(p);
for(uv=pc; uv<epc; ) {
if(!fileline(file, sizeof file, epc-2))
goto notfound;
uv += machdata->instsize(text, uv);
}
p = strrchr(file, ':');
*p++ = 0;
line2 = atoi(p);
if(line2+1-line2 < minlines)
return;
if(pc == s.value) { if(pc == s.value) {
// never entered function // never entered function
print("%s %s never called (%#llux-%#llux)\n", shortname(src1), s.name, pc, epc); print("%s:%d %s never called (%#llux-%#llux)\n", shortname(file), line1, s.name, pc, epc);
return; return;
} }
if(pc <= s.value+13) { if(pc <= s.value+13) {
@ -204,13 +253,14 @@ missing(uvlong pc, uvlong epc)
// show first instruction to make clear where we were. // show first instruction to make clear where we were.
machdata->das(text, pc, 0, buf, sizeof buf); machdata->das(text, pc, 0, buf, sizeof buf);
// cut filename off src2, leaving just line number. if(line1 != line2)
p = strrchr(src2, ':'); print("%s:%d,%d %#llux-%#llux %s\n",
if(p != nil) shortname(file), line1, line2, pc, epc, buf);
p++;
else else
p = src2; print("%s:%d %#llux-%#llux %s\n",
print("%s,%s %s %#llux-%#llux %s\n", shortname(src1), p, s.name, pc, epc, buf); shortname(file), line1, pc, epc, buf);
if(doshowsrc)
showsrc(file, line1, line2);
} }
/* /*
@ -387,6 +437,12 @@ main(int argc, char **argv)
case 'l': case 'l':
longnames++; longnames++;
break; break;
case 'n':
minlines = atoi(EARGF(usage()));
break;
case 's':
doshowsrc = 1;
break;
case 'v': case 'v':
chatty++; chatty++;
break; break;