From ae51b3cd4aaaaf8007e0ff951380efdbf7c3300f Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 6 Jan 2003 07:46:26 +0000 Subject: [PATCH] Update kernbb(8) to deal with GCC's new way of doing things. --- usr.sbin/kernbb/Makefile | 1 + usr.sbin/kernbb/kernbb.8 | 31 ++++++++---- usr.sbin/kernbb/kernbb.c | 105 +++++++++++---------------------------- 3 files changed, 51 insertions(+), 86 deletions(-) diff --git a/usr.sbin/kernbb/Makefile b/usr.sbin/kernbb/Makefile index 19473059a74..eb0209f6882 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 diff --git a/usr.sbin/kernbb/kernbb.8 b/usr.sbin/kernbb/kernbb.8 index 0143de9a7dd..fd03110fc32 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 99b0d68c94b..cb314c8923f 100644 --- a/usr.sbin/kernbb/kernbb.c +++ b/usr.sbin/kernbb/kernbb.c @@ -22,8 +22,6 @@ static const char rcsid[] = #include #include -#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]); + 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; - 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