1997-11-30 18:49:34 +03:00
|
|
|
/* $NetBSD: db_aout.c,v 1.18 1997/11/30 15:49:34 drochner Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
1993-12-18 07:46:25 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <machine/db_machdep.h> /* data types */
|
1993-12-18 07:46:25 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ddb/db_sym.h>
|
1996-02-05 04:56:47 +03:00
|
|
|
#include <ddb/db_output.h>
|
|
|
|
#include <ddb/db_extern.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-06-26 05:11:00 +04:00
|
|
|
#ifdef DB_AOUT_SYMBOLS
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-02-27 23:54:43 +03:00
|
|
|
#include <ddb/db_aout.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* An a.out symbol table as loaded into the kernel debugger:
|
|
|
|
*
|
|
|
|
* symtab -> size of symbol entries, in bytes
|
|
|
|
* sp -> first symbol entry
|
|
|
|
* ...
|
|
|
|
* ep -> last symbol entry + 1
|
|
|
|
* strtab == start of string table
|
|
|
|
* size of string table in bytes,
|
|
|
|
* including this word
|
|
|
|
* -> strings
|
|
|
|
*/
|
|
|
|
|
1993-07-22 17:02:15 +04:00
|
|
|
#ifdef SYMTAB_SPACE
|
1993-03-21 12:45:37 +03:00
|
|
|
int db_symtabsize = SYMTAB_SPACE;
|
1994-06-03 05:58:32 +04:00
|
|
|
int db_symtab[SYMTAB_SPACE/sizeof(int)] = { 0, 1 };
|
1993-07-22 17:02:15 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-03 05:58:32 +04:00
|
|
|
/*
|
|
|
|
* Find the symbol table and strings; tell ddb about them.
|
|
|
|
*/
|
1996-02-05 04:56:47 +03:00
|
|
|
void
|
1997-06-26 05:11:00 +04:00
|
|
|
X_db_sym_init(vsymtab, vesymtab, name)
|
|
|
|
void *vsymtab; /* pointer to start of symbol table */
|
|
|
|
void *vesymtab; /* pointer to end of string table,
|
1993-03-21 12:45:37 +03:00
|
|
|
for checking - rounded up to integer
|
|
|
|
boundary */
|
1996-02-05 04:56:47 +03:00
|
|
|
char *name;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
register struct nlist *sym_start, *sym_end;
|
|
|
|
register struct nlist *sp;
|
1996-02-05 04:56:47 +03:00
|
|
|
register char *strtab;
|
|
|
|
register int slen;
|
|
|
|
char *estrtab;
|
1997-06-26 05:11:00 +04:00
|
|
|
int *symtab = vsymtab;
|
|
|
|
char *esymtab = vesymtab;
|
|
|
|
|
|
|
|
if (ALIGNED_POINTER(symtab, int) == 0) {
|
|
|
|
printf("DDB: bad symtol table start address %p\n", symtab);
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-07-22 17:02:15 +04:00
|
|
|
#ifdef SYMTAB_SPACE
|
1994-06-03 05:58:32 +04:00
|
|
|
if (*symtab < sizeof(int)) {
|
1996-10-13 08:10:34 +04:00
|
|
|
printf ("DDB: no symbols\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1993-07-22 17:02:15 +04:00
|
|
|
#endif
|
1994-06-03 05:58:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find pointers to the start and end of the symbol entries,
|
|
|
|
* given a pointer to the start of the symbol table.
|
|
|
|
*/
|
|
|
|
sym_start = (struct nlist *)(symtab + 1);
|
|
|
|
sym_end = (struct nlist *)((char *)sym_start + *symtab);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
strtab = (char *)sym_end;
|
1996-02-05 04:56:47 +03:00
|
|
|
slen = *(int *)strtab;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-03 05:58:32 +04:00
|
|
|
#ifdef SYMTAB_SPACE
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("DDB: found symbols [%d + %d bytes]\n",
|
1996-02-05 04:56:47 +03:00
|
|
|
*symtab, slen);
|
|
|
|
if ((*symtab + slen) > db_symtabsize) {
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("DDB: symbols larger than SYMTAB_SPACE?\n");
|
1994-06-03 05:58:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
1996-02-05 04:56:47 +03:00
|
|
|
estrtab = strtab + slen;
|
1993-07-22 17:02:15 +04:00
|
|
|
|
|
|
|
#define round_to_size(x) \
|
|
|
|
(((vm_offset_t)(x) + sizeof(vm_size_t) - 1) & ~(sizeof(vm_size_t) - 1))
|
|
|
|
|
|
|
|
if (round_to_size(estrtab) != round_to_size(esymtab)) {
|
1997-11-30 18:49:34 +03:00
|
|
|
printf("[ %s symbol table not valid ]\n", name);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1993-08-29 16:48:10 +04:00
|
|
|
}
|
1993-07-22 17:02:15 +04:00
|
|
|
#undef round_to_size
|
1993-08-29 16:48:10 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (sp = sym_start; sp < sym_end; sp++) {
|
|
|
|
register int strx;
|
|
|
|
strx = sp->n_un.n_strx;
|
|
|
|
if (strx != 0) {
|
1996-02-05 04:56:47 +03:00
|
|
|
if (strx > slen) {
|
1997-11-30 18:49:34 +03:00
|
|
|
printf("Bad string table index (%#x)\n", strx);
|
1993-03-21 12:45:37 +03:00
|
|
|
sp->n_un.n_name = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sp->n_un.n_name = strtab + strx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-10-09 11:19:29 +03:00
|
|
|
if (db_add_symbol_table((char *)sym_start, (char *)sym_end, name,
|
|
|
|
(char *)symtab) != -1) {
|
1993-07-22 17:02:15 +04:00
|
|
|
#ifndef SYMTAB_SPACE
|
1997-11-30 18:49:34 +03:00
|
|
|
printf("[ preserving %d bytes of %s symbol table ]\n",
|
|
|
|
esymtab - (char *)symtab, name);
|
1993-07-22 17:02:15 +04:00
|
|
|
#endif
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
db_sym_t
|
|
|
|
X_db_lookup(stab, symstr)
|
|
|
|
db_symtab_t *stab;
|
|
|
|
char * symstr;
|
|
|
|
{
|
|
|
|
register struct nlist *sp, *ep;
|
|
|
|
|
|
|
|
sp = (struct nlist *)stab->start;
|
|
|
|
ep = (struct nlist *)stab->end;
|
|
|
|
|
|
|
|
for (; sp < ep; sp++) {
|
|
|
|
if (sp->n_un.n_name == 0)
|
|
|
|
continue;
|
|
|
|
if ((sp->n_type & N_STAB) == 0 &&
|
|
|
|
sp->n_un.n_name != 0 &&
|
|
|
|
db_eqname(sp->n_un.n_name, symstr, '_'))
|
|
|
|
{
|
|
|
|
return ((db_sym_t)sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ((db_sym_t)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
db_sym_t
|
|
|
|
X_db_search_symbol(symtab, off, strategy, diffp)
|
|
|
|
db_symtab_t * symtab;
|
|
|
|
register
|
|
|
|
db_addr_t off;
|
|
|
|
db_strategy_t strategy;
|
|
|
|
db_expr_t *diffp; /* in/out */
|
|
|
|
{
|
|
|
|
register unsigned int diff = *diffp;
|
|
|
|
register struct nlist *symp = 0;
|
|
|
|
register struct nlist *sp, *ep;
|
|
|
|
|
|
|
|
sp = (struct nlist *)symtab->start;
|
|
|
|
ep = (struct nlist *)symtab->end;
|
|
|
|
|
|
|
|
for (; sp < ep; sp++) {
|
|
|
|
if (sp->n_un.n_name == 0)
|
|
|
|
continue;
|
1993-07-10 07:25:02 +04:00
|
|
|
if ((sp->n_type & N_STAB) != 0 || (sp->n_type & N_TYPE) == N_FN)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
if (off >= sp->n_value) {
|
|
|
|
if (off - sp->n_value < diff) {
|
|
|
|
diff = off - sp->n_value;
|
|
|
|
symp = sp;
|
1993-07-10 07:25:02 +04:00
|
|
|
if (diff == 0 &&
|
1996-02-05 04:56:47 +03:00
|
|
|
((strategy == DB_STGY_PROC &&
|
|
|
|
sp->n_type == (N_TEXT|N_EXT)) ||
|
|
|
|
(strategy == DB_STGY_ANY &&
|
|
|
|
(sp->n_type & N_EXT))))
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (off - sp->n_value == diff) {
|
|
|
|
if (symp == 0)
|
|
|
|
symp = sp;
|
|
|
|
else if ((symp->n_type & N_EXT) == 0 &&
|
|
|
|
(sp->n_type & N_EXT) != 0)
|
|
|
|
symp = sp; /* pick the external symbol */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (symp == 0) {
|
|
|
|
*diffp = off;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*diffp = diff;
|
|
|
|
}
|
|
|
|
return ((db_sym_t)symp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the name and value for a symbol.
|
|
|
|
*/
|
|
|
|
void
|
1997-06-26 05:11:00 +04:00
|
|
|
X_db_symbol_values(symtab, sym, namep, valuep)
|
|
|
|
db_symtab_t *symtab;
|
1993-03-21 12:45:37 +03:00
|
|
|
db_sym_t sym;
|
|
|
|
char **namep;
|
|
|
|
db_expr_t *valuep;
|
|
|
|
{
|
|
|
|
register struct nlist *sp;
|
|
|
|
|
|
|
|
sp = (struct nlist *)sym;
|
|
|
|
if (namep)
|
|
|
|
*namep = sp->n_un.n_name;
|
|
|
|
if (valuep)
|
|
|
|
*valuep = sp->n_value;
|
|
|
|
}
|
|
|
|
|
1993-07-10 07:25:02 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
boolean_t
|
1993-07-10 07:25:02 +04:00
|
|
|
X_db_line_at_pc(symtab, cursym, filename, linenum, off)
|
|
|
|
db_symtab_t * symtab;
|
|
|
|
db_sym_t cursym;
|
|
|
|
char **filename;
|
|
|
|
int *linenum;
|
|
|
|
db_expr_t off;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1993-07-10 07:25:02 +04:00
|
|
|
register struct nlist *sp, *ep;
|
|
|
|
unsigned long sodiff = -1UL, lndiff = -1UL, ln = 0;
|
|
|
|
char *fname = NULL;
|
|
|
|
|
|
|
|
sp = (struct nlist *)symtab->start;
|
|
|
|
ep = (struct nlist *)symtab->end;
|
|
|
|
|
|
|
|
/* XXX - gcc specific */
|
|
|
|
#define NEWSRC(str) ((str) != NULL && \
|
|
|
|
(str)[0] == 'g' && strcmp((str), "gcc_compiled.") == 0)
|
|
|
|
|
|
|
|
for (; sp < ep; sp++) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent bogus linenumbers in case module not compiled
|
|
|
|
* with debugging options
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
if (sp->n_value <= off && (off - sp->n_value) <= sodiff &&
|
|
|
|
NEWSRC(sp->n_un.n_name)) {
|
|
|
|
#endif
|
|
|
|
if ((sp->n_type & N_TYPE) == N_FN || NEWSRC(sp->n_un.n_name)) {
|
|
|
|
sodiff = lndiff = -1UL;
|
|
|
|
ln = 0;
|
|
|
|
fname = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp->n_type == N_SO) {
|
|
|
|
if (sp->n_value <= off && (off - sp->n_value) < sodiff) {
|
|
|
|
sodiff = off - sp->n_value;
|
|
|
|
fname = sp->n_un.n_name;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp->n_type != N_SLINE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sp->n_value > off)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (off - sp->n_value < lndiff) {
|
|
|
|
lndiff = off - sp->n_value;
|
|
|
|
ln = sp->n_desc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fname != NULL && ln != 0) {
|
|
|
|
*filename = fname;
|
|
|
|
*linenum = ln;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
1993-07-10 07:25:02 +04:00
|
|
|
boolean_t
|
|
|
|
X_db_sym_numargs(symtab, cursym, nargp, argnamep)
|
|
|
|
db_symtab_t * symtab;
|
|
|
|
db_sym_t cursym;
|
|
|
|
int *nargp;
|
|
|
|
char **argnamep;
|
|
|
|
{
|
|
|
|
register struct nlist *sp, *ep;
|
|
|
|
u_long addr;
|
|
|
|
int maxnarg = *nargp, nargs = 0;
|
|
|
|
|
|
|
|
if (cursym == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
addr = ((struct nlist *)cursym)->n_value;
|
|
|
|
sp = (struct nlist *)symtab->start;
|
|
|
|
ep = (struct nlist *)symtab->end;
|
|
|
|
|
|
|
|
for (; sp < ep; sp++) {
|
|
|
|
if (sp->n_type == N_FUN && sp->n_value == addr) {
|
|
|
|
while (++sp < ep && sp->n_type == N_PSYM) {
|
|
|
|
if (nargs >= maxnarg)
|
|
|
|
break;
|
|
|
|
nargs++;
|
|
|
|
*argnamep++ = sp->n_un.n_name?sp->n_un.n_name:"???";
|
|
|
|
{
|
|
|
|
/* XXX - remove trailers */
|
|
|
|
char *cp = *(argnamep-1);
|
|
|
|
while (*cp != '\0' && *cp != ':') cp++;
|
|
|
|
if (*cp == ':') *cp = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*nargp = nargs;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialization routine for a.out files.
|
|
|
|
*/
|
1996-02-05 04:56:47 +03:00
|
|
|
void
|
1993-07-22 17:02:15 +04:00
|
|
|
ddb_init()
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1993-07-22 17:02:15 +04:00
|
|
|
#ifndef SYMTAB_SPACE
|
1993-03-21 12:45:37 +03:00
|
|
|
extern char *esym;
|
|
|
|
extern int end;
|
|
|
|
|
|
|
|
if (esym > (char *)&end) {
|
1993-07-10 07:25:02 +04:00
|
|
|
X_db_sym_init((int *)&end, esym, "netbsd");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-07-22 17:02:15 +04:00
|
|
|
#else
|
1993-07-10 07:25:02 +04:00
|
|
|
X_db_sym_init (db_symtab, 0, "netbsd");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1993-07-22 17:02:15 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-06-26 05:11:00 +04:00
|
|
|
#endif /* DB_AOUT_SYMBOLS */
|