Fix our kernel support for Basic Block Profiling to work with GCC33.

Approved by:	re@
This commit is contained in:
phk 2003-12-03 07:43:03 +00:00
parent 5074e467d2
commit b1742663d4
2 changed files with 69 additions and 13 deletions

View File

@ -6,6 +6,8 @@ MAN= kernbb.8
DPADD= ${LIBKVM}
LDADD= -lkvm
CFLAGS+= -I${.CURDIR}/../../contrib/gcc
WARNS?= 3
.include <bsd.prog.mk>

View File

@ -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;
}