Return to BSD News archive
Xref: sserve comp.unix.bsd:8364 misc.test:15965 Newsgroups: comp.unix.bsd,misc.test Path: sserve!manuel.anu.edu.au!munnari.oz.au!metro!ipso!runxtsa!bde From: bde@runx.oz.au (Bruce Evans) Subject: Re: [386BSD] load symbols for ddb (source) Message-ID: <1992Nov29.092901.21848@runx.oz.au> Followup-To: comp.unix.bsd Organization: RUNX Un*x Timeshare. Sydney, Australia. Date: Sun, 29 Nov 92 09:29:01 GMT Lines: 179 This program loads symbols for the 386BSD kernel debugger. There doesn't seem to be any program to do this in the 0.1 distribution, although the original (Mach) version of the debugger has been changed to require something like it. The Mach version handles ordinary symbol tables loaded by the boot loader, but this does not work in 386BSD because the boot loader is too primitive and there is no room for the symbols below 640K. Instead, 63000 bytes of space is reserved for symbols inside the kernel's data. This program just copies the symbols from the kernel's symbol table to that space. Usage: db-symtab your-kernel This modifies `your-kernel' in place. Kernels with all features enabled may have more than 63000 bytes of of symbols. Increase SYMTAB_SIZE in db_aout.c and recompile the kernel to get more space. Kernels with all features including ddb may be too big to fit anyway. Kernels compiled with -g have far more than 63000 bytes of symbols. Strip the "debugging" symbols to get them to fit. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: db-symtab db-symtab-aux.c # Wrapped by local@besplex on Sun Nov 29 19:44:58 1992 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'db-symtab' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'db-symtab'\" else echo shar: Extracting \"'db-symtab'\" \(453 characters\) sed "s/^X//" >'db-symtab' <<'END_OF_FILE' Xif test $# -ne 1 Xthen X echo "usage: $0 filename" X exit 1 Xfi Xsize=`nm $1 | sed -n -e 's/^\(........\) D _db_symtabsize$/0x\1/p'` Xif test $? -ne 0 Xthen X exit 1 Xfi Xif test -z "$size" Xthen X echo "no symbol db_symtabsize in $1" X exit 1 Xfi Xaddr=`nm $1 | sed -n -e 's/^\(........\) D _db_symtab$/0x\1/p'` Xif test $? -ne 0 Xthen X exit 1 Xfi Xif test -z "$size" Xthen X echo "no symbol db_symtab in $1" X exit 1 Xfi Xdb-symtab-aux $1 $size $addr END_OF_FILE if test 453 -ne `wc -c <'db-symtab'`; then echo shar: \"'db-symtab'\" unpacked with wrong size! fi chmod +x 'db-symtab' # end of 'db-symtab' fi if test -f 'db-symtab-aux.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'db-symtab-aux.c'\" else echo shar: Extracting \"'db-symtab-aux.c'\" \(2454 characters\) sed "s/^X//" >'db-symtab-aux.c' <<'END_OF_FILE' X#include <machine/param.h> X#include <a.out.h> X#include <errno.h> X#include <stdio.h> X#include <stdlib.h> X#include <string.h> X Xint main(argc, argv) Xint argc; Xchar **argv; X{ X int ch; X unsigned long db_symtab; X unsigned long db_symtabsize; X struct exec hdr; X FILE *in; X FILE *out; X long symoff; X unsigned long residual; X int status = 0; X X if (argc != 4) X { X fprintf(stderr, "%s: usage: %s file db-symtab-size db-symtab-addr\n", X argv[0], argv[0]); X exit(1); X } X in = fopen(argv[1], "r"); X if (in == NULL) X { X fprintf(stderr, "%s: error opening %s for input: %s\n", X argv[0], argv[1], strerror(errno)); X exit(1); X } X fread(&hdr, sizeof hdr, 1, in); X db_symtabsize = strtoul(argv[2], (char **) NULL, 0); X if (db_symtabsize < KERNBASE) X { X fprintf(stderr, "%s: db_symtab (0x%x) is below KERNBASE (0x%x)\n", X argv[0], db_symtab, (unsigned long) KERNBASE); X exit(1); X } X fseek(in, db_symtabsize - KERNBASE + N_TXTOFF(hdr), SEEK_SET); X fread(&db_symtabsize, sizeof db_symtabsize, 1, in); X if (db_symtabsize < sizeof hdr.a_syms) X { X fprintf(stderr, "%s: db_symtabsize (0x%x) is far too small\n", X argv[0], db_symtabsize); X exit(1); X } X db_symtab = strtoul(argv[3], (char **) NULL, 0); X if (db_symtab < KERNBASE) X { X fprintf(stderr, "%s: db_symtab (0x%x) is below KERNBASE (0x%x)\n", X argv[0], db_symtab, (unsigned long) KERNBASE); X exit(1); X } X out = fopen(argv[1], "r+"); X if (out == NULL) X { X fprintf(stderr, "%s: error opening %s for output: %s\n", X argv[0], argv[1], strerror(errno)); X exit(1); X } X fseek(in, symoff = N_SYMOFF(hdr), SEEK_SET); X fseek(out, db_symtab - KERNBASE + N_TXTOFF(hdr), SEEK_SET); X fwrite(&hdr.a_syms, sizeof hdr.a_syms, 1, out); X residual = db_symtabsize - sizeof hdr.a_syms; X while ((ch = getc(in)) != EOF) X { X if (residual == 0) X { X fprintf(stderr, "%s: symbol table is to large in %s\n", X argv[0], argv[1]); X status = 1; X break; X } X putc(ch, out); X --residual; X } X fflush(out); X if (ferror(in)) X { X fprintf(stderr, "%s: error reading from %s: %s\n", X argv[0], argv[1], strerror(errno)); X status = 1; X } X if (ferror(out)) X { X fprintf(stderr, "%s: error writing to %s: %s\n", X argv[0], argv[1], strerror(errno)); X status = 1; X } X fprintf(stderr, "0x%0x bytes reserved for symbols, 0x%x used\n", X db_symtabsize, db_symtabsize - residual); X return status; X} END_OF_FILE if test 2454 -ne `wc -c <'db-symtab-aux.c'`; then echo shar: \"'db-symtab-aux.c'\" unpacked with wrong size! fi # end of 'db-symtab-aux.c' fi echo shar: End of shell archive. exit 0 -- Bruce Evans (bde@runx.oz.au)