/* Written by Pace Willisson (pace@blitz.com)
* and placed in the public domain.
static char rcsid
[] = "$Id: dbsym.c,v 1.8 1993/08/02 17:57:02 mycroft Exp $";
#include <machine/param.h>
#define FILE_OFFSET(vadr) (((vadr) - text_adr) - N_DATADDR(hdr) + \
N_DATOFF(hdr) + N_TXTADDR(hdr))
u_int text_adr
= KERNBASE
;
fprintf (stderr
, "usage: dbsym [-fgx] [-T addr] file\n");
while ((c
= getopt (argc
, argv
, "fgxT:")) != EOF
) {
text_adr
= strtoul(optarg
, &p
, 16);
err("illegal text address: %s", optarg
);
if ((f
= fopen (name
, "r+")) == NULL
) {
fprintf (stderr
, "can't open %s\n", name
);
if (fread ((char *)&hdr
, sizeof hdr
, 1, f
) != 1) {
fprintf (stderr
, "can't read header\n");
fprintf (stderr
, "bad magic number\n");
fprintf (stderr
, "no symbols\n");
fseek (f
, N_STROFF (hdr
), 0);
if (fread ((char *)&old_strtab_size
, sizeof (int), 1, f
) != 1) {
fprintf (stderr
, "can't read old strtab size\n");
if ((old_syms
= (struct nlist
*)malloc (hdr
.a_syms
)) == NULL
|| ((old_strtab
= malloc (old_strtab_size
)) == NULL
)
|| ((new_syms
= (struct nlist
*)malloc (hdr
.a_syms
)) == NULL
)
|| ((new_strtab
= malloc (old_strtab_size
)) == NULL
)) {
fprintf (stderr
, "out of memory\n");
fseek (f
, N_SYMOFF (hdr
), 0);
if (fread ((char *)old_syms
, hdr
.a_syms
, 1, f
) != 1) {
fprintf (stderr
, "can't read symbols\n");
fseek (f
, N_STROFF (hdr
), 0);
if (fread ((char *)old_strtab
, old_strtab_size
, 1, f
) != 1) {
fprintf (stderr
, "can't read string table\n");
num_old_syms
= hdr
.a_syms
/ sizeof (struct nlist
);
for (i
= 0, sp
= old_syms
; i
< num_old_syms
; i
++, sp
++) {
if (zap_locals
&& !(sp
->n_type
& N_EXT
))
switch (sp
->n_type
& ~N_EXT
) {
if ((sp
->n_type
& ~N_EXT
) == N_UNDF
)
if (!debugging
&& (sp
->n_type
& ~N_EXT
) == N_FN
)
if (sp
->n_un
.n_strx
== 0)
if (sp
->n_value
< text_adr
)
if (sp
->n_value
> (text_adr
+ hdr
.a_text
+ hdr
.a_data
+
name
= old_strtab
+ sp
->n_un
.n_strx
;
if (strcmp (name
, "gcc_compiled.") == 0)
if (strcmp (name
, "gcc2_compiled.") == 0)
if (strcmp (name
, "___gnu_compiled_c") == 0)
nsp
->n_un
.n_strx
= new_strtab_size
;
strcpy (new_strtab
+ new_strtab_size
, name
);
new_strtab_size
+= len
+ 1;
if (strcmp (name
, "_db_symtab") == 0)
db_symtab_adr
= sp
->n_value
;
if (strcmp (name
, "_db_symtabsize") == 0)
db_symtabsize_adr
= sp
->n_value
;
if (db_symtab_adr
== 0 || db_symtabsize_adr
== 0)
fprintf (stderr
, "couldn't find db_symtab symbols\n");
*(int *)new_strtab
= new_strtab_size
;
num_new_syms
= nsp
- new_syms
;
new_syms_bytes
= num_new_syms
* sizeof (struct nlist
);
+ num_new_syms
* sizeof (struct nlist
)
fseek (f
, FILE_OFFSET (db_symtabsize_adr
), 0);
if (fread ((char *)&avail
, sizeof (int), 1, f
) != 1) {
fprintf (stderr
, "can't read symtabsize\n");
printf ("dbsym: need %d; avail %d\n", need
, avail
);
fprintf (stderr
, "not enough room in db_symtab array\n");
fseek (f
, FILE_OFFSET (db_symtab_adr
), 0);
fwrite ((char *)&new_syms_bytes
, sizeof (int), 1, f
);
fwrite ((char *)new_syms
, new_syms_bytes
, 1, f
);
fwrite (new_strtab
, new_strtab_size
, 1, f
);
if (feof (f
) || ferror (f
)) {
fprintf (stderr
, "write error\n");