1995-03-10 08:53:55 +00:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-09-22 06:30:04 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1997-09-22 06:30:04 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <kvm.h>
|
2002-08-18 17:57:08 +00:00
|
|
|
#include <nlist.h>
|
1995-03-10 08:53:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-09-22 06:30:04 +00:00
|
|
|
#include <unistd.h>
|
1995-03-10 08:53:55 +00:00
|
|
|
|
|
|
|
struct bb {
|
|
|
|
u_long zero_one;
|
|
|
|
u_long filename;
|
|
|
|
u_long counts;
|
|
|
|
u_long ncounts;
|
|
|
|
u_long next;
|
|
|
|
u_long addr;
|
|
|
|
u_long nwords;
|
|
|
|
u_long func;
|
|
|
|
u_long lineno;
|
|
|
|
u_long file;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nlist namelist[] = {
|
2003-01-06 07:46:26 +00:00
|
|
|
{ "bbhead", 0, 0, 0, 0 },
|
|
|
|
{ NULL, 0, 0, 0, 0 }
|
1995-03-10 08:53:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
kvm_t *kv;
|
1995-10-22 19:45:28 +00:00
|
|
|
|
|
|
|
int
|
2003-01-06 07:46:26 +00:00
|
|
|
main(int argc __unused, char **argv __unused)
|
1995-03-10 08:53:55 +00:00
|
|
|
{
|
2003-01-06 07:46:26 +00:00
|
|
|
int i;
|
2001-06-24 23:41:57 +00:00
|
|
|
u_long l1,l2,l4;
|
1995-03-10 08:53:55 +00:00
|
|
|
struct bb bb;
|
2003-01-06 07:46:26 +00:00
|
|
|
char buf[BUFSIZ], *p;
|
|
|
|
FILE *f;
|
1995-03-10 08:53:55 +00:00
|
|
|
|
|
|
|
kv = kvm_open(NULL,NULL,NULL,O_RDWR,"dnc");
|
1995-10-22 19:45:28 +00:00
|
|
|
if (!kv)
|
|
|
|
err(1,"kvm_open");
|
1995-03-10 08:53:55 +00:00
|
|
|
i = kvm_nlist(kv,namelist);
|
1995-10-22 19:45:28 +00:00
|
|
|
if (i)
|
|
|
|
err(1,"kvm_nlist");
|
1995-03-10 08:53:55 +00:00
|
|
|
|
|
|
|
l1 = namelist[0].n_value;
|
|
|
|
kvm_read(kv,l1,&l2,sizeof l2);
|
1999-03-21 12:32:17 +00:00
|
|
|
while(l2) {
|
1995-03-10 08:53:55 +00:00
|
|
|
l1 += sizeof l1;
|
1999-03-21 12:32:17 +00:00
|
|
|
kvm_read(kv,l2,&bb,sizeof bb);
|
|
|
|
l2 = bb.next;
|
2003-01-06 07:46:26 +00:00
|
|
|
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");
|
1995-03-10 08:53:55 +00:00
|
|
|
}
|
2003-01-06 07:46:26 +00:00
|
|
|
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);
|
1995-03-10 08:53:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|