WARNSify, use err/warn, cleanup manpage

This commit is contained in:
lukem 1997-10-17 05:47:27 +00:00
parent 7df23bd595
commit 065400a1f3
2 changed files with 47 additions and 54 deletions

View File

@ -1,4 +1,4 @@
.\" $Id: dbsym.8,v 1.1 1994/08/25 20:40:32 gwr Exp $
.\" $NetBSD: dbsym.8,v 1.2 1997/10/17 05:47:27 lukem Exp $
.\"
.Dd 12 May 1994
.Dt DBSYM 8 sun3
@ -7,14 +7,14 @@
.Nm dbsym
.Nd copy kernel symbol table into db_symtab space
.Sh SYNOPSIS
.Nm dbsym
.Nm
.Ar kernel
.Sh DESCRIPTION
.Nm dbsym
.Nm
is used to copy the symbol table in a newly linked kernel into the
.Nm db_symtab
.Va db_symtab
array (in the data section) so that the
.Nm ddb
.Xr ddb 4
kernel debugger can find the symbols. This is program is only used
on systems for which the boot program does not load the symbol table
into memory with the kernel. The space for these symbols is
@ -27,20 +27,19 @@ at least as large as the kernel symbol table. If insufficient space
is reserved, dbsym will refuse to copy the symbol table.
.Pp
Note that debugging symbols are not useful to the
.Nm ddb
.Xr ddb 4
kernel debugger, so to minimize the size of the kernel, one should
either compile the kernel without debugging symbols (no
.Nm -g
.Fl g
flag) or use the
.Nm strip
.Xr strip 1
command to strip debugging symbols from the kernel before
.Nm dbsym
.Nm
is used to copy the symbol table. The command
.Pp
.Li strip -d netbsd
.Pp
will strip out debugging symbols.
.Sh "SEE ALSO"
.Xr strip 1
.Xr ddb 8
.\" XXX - Reminder, need: /src/share/man/man8/ddb.8
.Xr strip 1 ,
.Xr ddb 4

View File

@ -24,19 +24,24 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: dbsym.c,v 1.10 1994/06/27 22:21:20 gwr Exp $
* $NetBSD: dbsym.c,v 1.11 1997/10/17 05:47:30 lukem Exp $
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: dbsym.c,v 1.11 1997/10/17 05:47:30 lukem Exp $");
#endif
/* Copy the symbol table into the space reserved for it. */
#include <sys/types.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <stdio.h>
#include <a.out.h>
extern off_t lseek();
#include <err.h>
#include <stdio.h>
#include <unistd.h>
struct exec head;
char *file;
@ -61,36 +66,32 @@ int file_len;
int data_off;
int data_pgoff;
void find_db_symtab __P((const char *));
int main __P((int, char **));
int
main(argc,argv)
int argc;
char **argv;
{
int fd, n;
int *ip;
char *cp;
if (argc < 2) {
printf("%s: missing file name\n", argv[0]);
exit(1);
}
if (argc < 2)
errx(1, "missing file name");
file = argv[1];
fd = open(file, O_RDWR);
if (fd < 0) {
perror(file);
exit(1);
}
if (fd < 0)
err(1, "open `%s'", file);
n = read(fd, &head, sizeof(head));
if (n < sizeof(head)) {
printf("%s: reading header\n", file);
exit(1);
}
if (n < sizeof(head))
errx(1, "reading header of `%s'", file);
file_len = lseek(fd, (off_t)0, 2);
if (N_BADMAG(head)) {
printf("%s: bad magic number\n");
exit(1);
}
if (N_BADMAG(head))
errx(1, "%s: bad magic number", file);
#ifdef DEBUG
printf(" text: %9d\n", head.a_text);
@ -106,12 +107,8 @@ main(argc,argv)
printf("%s: no symbols\n", file);
exit(1);
}
if (head.a_trsize ||
head.a_drsize)
{
printf("%s: has relocations\n");
exit(1);
}
if (head.a_trsize || head.a_drsize)
errx(1, "%s: has relocations", file);
find_db_symtab(file);
@ -152,16 +149,12 @@ main(argc,argv)
db_symtabsize_val, db_symtabsize_val);
#endif
/* Is there room for the symbols + strings? */
if (db_symtabsize_val < (head.a_syms + strtab_len)) {
printf("%s: symbol space too small (%d < %d)\n", argv[0],
db_symtabsize_val, (head.a_syms + strtab_len));
exit(1);
}
printf("Symbols use %d of %d bytes available (%d%%)\n",
head.a_syms + strtab_len,
db_symtabsize_val,
(head.a_syms + strtab_len) * 100 /
db_symtabsize_val);
if (db_symtabsize_val < (head.a_syms + strtab_len))
errx(1, "symbol space too small (%ld < %ld)",
(long)db_symtabsize_val, (long)(head.a_syms + strtab_len));
printf("Symbols use %ld of %ld bytes available (%ld%%)\n",
(long)(head.a_syms + strtab_len), (long)db_symtabsize_val,
(long)((head.a_syms + strtab_len) * 100 / db_symtabsize_val));
/*
* Copy the symbol table and string table.
@ -192,13 +185,14 @@ main(argc,argv)
* Find locations of the symbols to patch.
*/
struct nlist wantsyms[] = {
{ "_db_symtabsize", 0 },
{ "_db_symtab", 0 },
{ NULL, 0 },
{ { "_db_symtabsize" }, 0 },
{ { "_db_symtab" }, 0 },
{ { NULL }, 0 },
};
void
find_db_symtab(file)
char *file;
const char *file;
{
int data_va;
int std_entry;
@ -211,7 +205,7 @@ find_db_symtab(file)
(head.a_entry & (N_PAGSIZ(head)-1));
data_va = N_DATADDR(head);
if (head.a_entry != std_entry) {
printf("%s: warning: non-standard entry point: 0x%08x\n",
printf("%s: warning: non-standard entry point: 0x%08lx\n",
file, head.a_entry);
printf("\texpecting entry=0x%X\n", std_entry);
data_va += (head.a_entry - std_entry);