summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2003-01-06 07:46:26 +0000
committerphk <phk@FreeBSD.org>2003-01-06 07:46:26 +0000
commitcf4805ac14b0b14bf3408811df5f06733049ff02 (patch)
treee449f060c6ebf01e55aac4abddab6caf4603a5fc /usr.sbin
parent0023d2467427c4ef779f70ffdfc5d2fa908f6f97 (diff)
downloadFreeBSD-src-cf4805ac14b0b14bf3408811df5f06733049ff02.zip
FreeBSD-src-cf4805ac14b0b14bf3408811df5f06733049ff02.tar.gz
Update kernbb(8) to deal with GCC's new way of doing things.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/kernbb/Makefile1
-rw-r--r--usr.sbin/kernbb/kernbb.831
-rw-r--r--usr.sbin/kernbb/kernbb.c105
3 files changed, 51 insertions, 86 deletions
diff --git a/usr.sbin/kernbb/Makefile b/usr.sbin/kernbb/Makefile
index 1947305..eb0209f 100644
--- a/usr.sbin/kernbb/Makefile
+++ b/usr.sbin/kernbb/Makefile
@@ -6,5 +6,6 @@ MAN= kernbb.8
DPADD= ${LIBKVM}
LDADD= -lkvm
+WARNS?= 3
.include <bsd.prog.mk>
diff --git a/usr.sbin/kernbb/kernbb.8 b/usr.sbin/kernbb/kernbb.8
index 0143de9..fd03110 100644
--- a/usr.sbin/kernbb/kernbb.8
+++ b/usr.sbin/kernbb/kernbb.8
@@ -42,20 +42,28 @@
.Sh DESCRIPTION
The
.Nm
-utility is used to dump the basic-block profiling buffers of the running
-kernel.
+utility is used to extract the basic-block profiling buffers of the running
+kernel into the files needed for the
+.Xr gcov 1
+tool.
.Pp
At least one source file in the running kernel must have been compiled
with the
-.Fl a
-option.
+.Fl --test-coverage
+and
+.Fl --profile-arcs
+options.
.Pp
-The output format is
-.Tn ASCII ,
-consisting of one line per record with the
-following fields: filename, linenumber, procedure, address, count
-of executions, length of the basic-block in bytes and the product of
-the previous two fields.
+The output is stored in the filenames compiled into the kernel by
+.Xr gcc 1 .
+If the absolute pathname cannot be written to, the directory part
+of the filename is discarded and the file stored in the current
+directory under its basename.
+.Pp
+The output files are named *.da, and the
+.Xr gcov 1
+program will extract the counts and merge them with the source
+file to show actual execution counts.
.Sh FILES
.Bl -tag -width /boot/kernel/kernel -compact
.It Pa /boot/kernel/kernel
@@ -65,9 +73,12 @@ the default memory
.El
.Sh SEE ALSO
.Xr cc 1
+.Xr gcov 1
.Sh AUTHORS
The
.Nm
utility was written by
.An Poul-Henning Kamp ,
along with the kernel-support.
+.Sh BUGS
+There are far too much magic and internal knowledge from GCC in this.
diff --git a/usr.sbin/kernbb/kernbb.c b/usr.sbin/kernbb/kernbb.c
index 99b0d68..cb314c8 100644
--- a/usr.sbin/kernbb/kernbb.c
+++ b/usr.sbin/kernbb/kernbb.c
@@ -22,8 +22,6 @@ static const char rcsid[] =
#include <string.h>
#include <unistd.h>
-#define MAXBB 32768
-
struct bb {
u_long zero_one;
u_long filename;
@@ -38,27 +36,20 @@ struct bb {
};
struct nlist namelist[] = {
- { "bbhead" },
- { NULL }
+ { "bbhead", 0, 0, 0, 0 },
+ { NULL, 0, 0, 0, 0 }
};
-u_long lineno[MAXBB];
-u_long counts[MAXBB];
-u_long addr[MAXBB];
-u_long func[MAXBB];
-u_long file[MAXBB];
-char *fn[MAXBB];
-char *pn[MAXBB];
-
kvm_t *kv;
int
-main()
+main(int argc __unused, char **argv __unused)
{
- int i,j;
+ int i;
u_long l1,l2,l4;
struct bb bb;
- char buf[128];
+ char buf[BUFSIZ], *p;
+ FILE *f;
kv = kvm_open(NULL,NULL,NULL,O_RDWR,"dnc");
if (!kv)
@@ -73,68 +64,30 @@ main()
l1 += sizeof l1;
kvm_read(kv,l2,&bb,sizeof bb);
l2 = bb.next;
- if (!bb.ncounts)
- continue;
- if (bb.ncounts > MAXBB)
- errx(1, "found %lu counts above limit of %u",
- bb.ncounts, MAXBB);
- kvm_read(kv,bb.lineno,lineno, bb.ncounts * sizeof lineno[0]);
- kvm_read(kv,bb.counts,counts, bb.ncounts * sizeof counts[0]);
- kvm_read(kv,bb.addr, addr, bb.ncounts * sizeof addr[0]);
- kvm_read(kv,bb.file, file, bb.ncounts * sizeof file[0]);
- kvm_read(kv,bb.func, func, bb.ncounts * sizeof func[0]);
- l4 = 0;
- for (i=0; i < bb.ncounts; i++) {
- if (counts[i])
- l4++;
- if (!func[i] && i+1 < bb.ncounts)
- func[i] = func[i+1];
- }
- if (!l4)
- continue;
- for (i=0; i < bb.ncounts; i++) {
-
- if (0 && !counts[i])
- continue;
-
- if (!pn[i] && func[i]) {
- kvm_read(kv,func[i], buf, sizeof buf);
- buf[sizeof buf -1] = 0;
- pn[i] = strdup(buf);
- for(j=i+1;j<bb.ncounts;j++)
- if (func[j] == func[i]) {
- pn[j] = pn[i];
- func[j] = 0;
- }
- }
- if (!pn[i])
- pn[i] = "-";
- if (!fn[i] && file[i]) {
- kvm_read(kv,file[i], buf, sizeof buf);
- buf[sizeof buf -1] = 0;
- fn[i] = strdup(buf);
- for(j=i+1;j<bb.ncounts;j++)
- if (file[j] == file[i]) {
- fn[j] = fn[i];
- file[j] = 0;
- }
- }
- if (!fn[i])
- fn[i] = "-";
- l4 = 0;
- if (i+1 < bb.ncounts)
- l4 = addr[i+1] - addr[i];
- printf("%s %5lu %s %lu %lu %lu %lu\n",
- fn[i], lineno[i], pn[i], addr[i], counts[i], l4, counts[i] * l4);
- }
- for(i=0;i<bb.ncounts;i++) {
- if (func[i] && pn[i])
- free(pn[i]);
- if (file[i] && fn[i])
- free(fn[i]);
- pn[i] = 0;
- fn[i] = 0;
+ kvm_read(kv, bb.filename, buf, sizeof(buf));
+ p = buf;
+ f = fopen(p, "w");
+ if (f != NULL) {
+ printf("Writing \"%s\"\n", p);
+ } else {
+ p = strrchr(buf, '/');
+ if (p == NULL)
+ p = buf;
+ else
+ p++;
+ printf("Writing \"%s\" (spec \"%s\")\n", p, buf);
+ f = fopen(p, "w");
}
+ if (f == NULL)
+ err(1,"%s", p);
+ fwrite(&bb.ncounts, 4, 1, f);
+ l4 = 0;
+ fwrite(&l4, 4, 1, f);
+ p = malloc(bb.ncounts * 8);
+ kvm_read(kv, bb.counts, p, bb.ncounts * 8);
+ fwrite(p, 8, bb.ncounts, f);
+ fclose(f);
+ free(p);
}
return 0;
}
OpenPOWER on IntegriCloud