2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
30 * Author: David B. Golub, Carnegie Mellon University
34 * Symbol table routines for a.out format files.
39 #include <machine/db_machdep.h> /* data types */
40 #include <ddb/db_sym.h>
44 #define _AOUT_INCLUDE_
48 * An a.out symbol table as loaded into the kernel debugger:
50 * symtab -> size of symbol entries, in bytes
51 * sp -> first symbol entry
53 * ep -> last symbol entry + 1
54 * strtab == start of string table
55 * size of string table in bytes,
61 * Find pointers to the start and end of the symbol entries,
62 * given a pointer to the start of the symbol table.
64 #define db_get_aout_symtab(symtab, sp, ep) \
65 (sp = (struct nlist *)((symtab) + 1), \
66 ep = (struct nlist *)((char *)sp + *(symtab)))
69 #define SYMTAB_SPACE 63000
70 #endif /*SYMTAB_SPACE*/
72 int db_symtabsize = SYMTAB_SPACE;
73 char db_symtab[SYMTAB_SPACE] = { 1 };
75 X_db_sym_init(symtab, esymtab, name)
76 int * symtab; /* pointer to start of symbol table */
77 char * esymtab; /* pointer to end of string table,
78 for checking - rounded up to integer
82 register struct nlist *sym_start, *sym_end;
83 register struct nlist *sp;
84 register char * strtab;
88 printf ("DDB: no symbols\n");
92 db_get_aout_symtab(symtab, sym_start, sym_end);
94 strtab = (char *)sym_end;
95 strlen = *(int *)strtab;
98 if (strtab + ((strlen + sizeof(int) - 1) & ~(sizeof(int)-1))
101 db_printf("[ %s symbol table not valid ]\n", name);
105 db_printf("[ preserving %#x bytes of %s symbol table ]\n",
106 esymtab - (char *)symtab, name);
109 for (sp = sym_start; sp < sym_end; sp++) {
111 strx = sp->n_un.n_strx;
114 db_printf("Bad string table index (%#x)\n", strx);
118 sp->n_un.n_name = strtab + strx;
122 db_add_symbol_table(sym_start, sym_end, name, (char *)symtab);
126 X_db_lookup(stab, symstr)
130 register struct nlist *sp, *ep;
132 sp = (struct nlist *)stab->start;
133 ep = (struct nlist *)stab->end;
135 for (; sp < ep; sp++) {
136 if (sp->n_un.n_name == 0)
138 if ((sp->n_type & N_STAB) == 0 &&
139 sp->n_un.n_name != 0 &&
140 db_eqname(sp->n_un.n_name, symstr, '_'))
142 return ((db_sym_t)sp);
145 return ((db_sym_t)0);
149 X_db_search_symbol(symtab, off, strategy, diffp)
150 db_symtab_t * symtab;
153 db_strategy_t strategy;
154 db_expr_t *diffp; /* in/out */
156 register unsigned int diff = *diffp;
157 register struct nlist *symp = 0;
158 register struct nlist *sp, *ep;
160 sp = (struct nlist *)symtab->start;
161 ep = (struct nlist *)symtab->end;
163 for (; sp < ep; sp++) {
164 if (sp->n_un.n_name == 0)
166 if ((sp->n_type & N_STAB) != 0)
168 if (off >= sp->n_value) {
169 if (off - sp->n_value < diff) {
170 diff = off - sp->n_value;
175 else if (off - sp->n_value == diff) {
178 else if ((symp->n_type & N_EXT) == 0 &&
179 (sp->n_type & N_EXT) != 0)
180 symp = sp; /* pick the external symbol */
190 return ((db_sym_t)symp);
194 * Return the name and value for a symbol.
197 X_db_symbol_values(sym, namep, valuep)
202 register struct nlist *sp;
204 sp = (struct nlist *)sym;
206 *namep = sp->n_un.n_name;
208 *valuep = sp->n_value;
218 * Initialization routine for a.out files.
226 if (esym > (char *)&end) {
227 X_db_sym_init((int *)&end, esym, "mach");
231 X_db_sym_init (db_symtab, 0, "mach");
236 * Read symbol table from file.
237 * (should be somewhere else)
239 #include <boot_ufs/file_io.h>
240 #include <vm/vm_kern.h>
242 read_symtab_from_file(fp, symtab_name)
247 kern_return_t result;
252 vm_size_t table_size;
255 if (!get_symtab(fp, &symoff, &symsize)) {
256 boot_printf("[ error %d reading %s file header ]\n",
257 result, symtab_name);
261 stroff = symoff + symsize;
262 result = read_file(fp, (vm_offset_t)stroff,
263 (vm_offset_t)&strsize, sizeof(strsize), &resid);
264 if (result || resid) {
265 boot_printf("[ no valid symbol table present for %s ]\n",
270 table_size = sizeof(int) + symsize + strsize;
271 table_size = (table_size + sizeof(int)-1) & ~(sizeof(int)-1);
273 symtab = kmem_alloc_wired(kernel_map, table_size);
275 *(int *)symtab = symsize;
277 result = read_file(fp, symoff,
278 symtab + sizeof(int), symsize, &resid);
279 if (result || resid) {
280 boot_printf("[ error %d reading %s symbol table ]\n",
281 result, symtab_name);
285 result = read_file(fp, stroff,
286 symtab + sizeof(int) + symsize, strsize, &resid);
287 if (result || resid) {
288 boot_printf("[ error %d reading %s string table ]\n",
289 result, symtab_name);
293 X_db_sym_init((int *)symtab,
294 (char *)(symtab + table_size),
300 #endif /* DB_NO_AOUT */