diff options
author | phk <phk@FreeBSD.org> | 2003-12-03 07:43:03 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2003-12-03 07:43:03 +0000 |
commit | f9608ecffbe0e7a60bdbc3600b3093b752367925 (patch) | |
tree | ad11d90bdb7e14a715e11f75eceed6fa6b0b276b /usr.sbin | |
parent | 8bd5f2d4e22593a9db4825cd7c852d7fb3cb9c2a (diff) | |
download | FreeBSD-src-f9608ecffbe0e7a60bdbc3600b3093b752367925.zip FreeBSD-src-f9608ecffbe0e7a60bdbc3600b3093b752367925.tar.gz |
Fix our kernel support for Basic Block Profiling to work with GCC33.
Approved by: re@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/kernbb/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/kernbb/kernbb.c | 80 |
2 files changed, 69 insertions, 13 deletions
diff --git a/usr.sbin/kernbb/Makefile b/usr.sbin/kernbb/Makefile index eb0209f..7da462b 100644 --- a/usr.sbin/kernbb/Makefile +++ b/usr.sbin/kernbb/Makefile @@ -6,6 +6,8 @@ MAN= kernbb.8 DPADD= ${LIBKVM} LDADD= -lkvm +CFLAGS+= -I${.CURDIR}/../../contrib/gcc + WARNS?= 3 .include <bsd.prog.mk> diff --git a/usr.sbin/kernbb/kernbb.c b/usr.sbin/kernbb/kernbb.c index 83ddd53..5b4a9a38 100644 --- a/usr.sbin/kernbb/kernbb.c +++ b/usr.sbin/kernbb/kernbb.c @@ -19,6 +19,19 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/endian.h> + +typedef long long gcov_type; + +#define PARAMS(foo) foo +#define ATTRIBUTE_UNUSED __unused +#include "gcov-io.h" + +struct bbf { + long checksum; + long arc_count; + u_long name; +}; struct bb { u_long zero_one; @@ -26,11 +39,8 @@ struct bb { u_long counts; u_long ncounts; u_long next; - u_long addr; - u_long nwords; - u_long func; - u_long lineno; - u_long file; + u_long sizeof_bb; + u_long funcs; }; struct nlist namelist[] = { @@ -43,10 +53,13 @@ kvm_t *kv; int main(int argc __unused, char **argv __unused) { - int i; + int i, funcs; u_long l1,l2,l4; struct bb bb; + struct bbf bbf; char buf[BUFSIZ], *p; + gcov_type *q, *qr; + FILE *f; kv = kvm_open(NULL,NULL,NULL,O_RDWR,"dnc"); @@ -61,7 +74,22 @@ main(int argc __unused, char **argv __unused) while(l2) { l1 += sizeof l1; kvm_read(kv,l2,&bb,sizeof bb); +#if 0 +printf("%lx\n%lx\n%lx\n%lx\n%lx\n%lx\n%lx\n", + bb.zero_one, bb.filename, bb.counts, bb.ncounts, bb.next, + bb.sizeof_bb, bb.funcs); +#endif + + funcs = 0; + for (l4 = bb.funcs; ; l4 += sizeof (bbf)) { + kvm_read(kv, l4, &bbf, sizeof(bbf)); + if (bbf.arc_count == -1) + break; + funcs++; + } + l2 = bb.next; + kvm_read(kv, bb.filename, buf, sizeof(buf)); p = buf; f = fopen(p, "w"); @@ -78,14 +106,40 @@ main(int argc __unused, char **argv __unused) } 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); + __write_long(-123, f, 4); + + __write_long(funcs, f, 4); + + __write_long(4 + 8 + 8 + 4 + 8 + 8, f, 4); + + __write_long(bb.ncounts, f, 4); + __write_long(0, f, 8); + __write_long(0, f, 8); + + __write_long(bb.ncounts, f, 4); + __write_long(0, f, 8); + __write_long(0, f, 8); + + qr = malloc(bb.ncounts * 8); + kvm_read(kv, bb.counts, qr, bb.ncounts * 8); + q = qr; + for (l4 = bb.funcs; ; l4 += sizeof (bbf)) { + kvm_read(kv, l4, &bbf, sizeof(bbf)); + if (bbf.arc_count == -1) + break; + kvm_read(kv, bbf.name, buf, sizeof(buf)); + + __write_gcov_string(buf, strlen(buf), f, -1); + + __write_long(bbf.checksum, f, 4); + __write_long(bbf.arc_count, f, 4); + for (i = 0; i < bbf.arc_count; i++) { + __write_gcov_type(*q, f, 8); + q++; + } + } fclose(f); - free(p); + free(qr); } return 0; } |