|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1991,1990 Carnegie Mellon University
4: * All Rights Reserved.
5: *
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.
11: *
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.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie the
24: * rights to redistribute these changes.
25: */
26: /*
27: * HISTORY
28: * $Log: db_aout.c,v $
1.1.1.2 ! root 29: * Revision 1.1.1.1 1993/03/21 09:46:26 cgd
! 30: * initial import of 386bsd-0.1 sources
! 31: *
1.1 root 32: * Revision 1.1 1992/03/25 21:44:55 pace
33: * Initial revision
34: *
35: * Revision 2.3 91/02/05 17:05:55 mrt
36: * Changed to new Mach copyright
37: * [91/01/31 16:16:44 mrt]
38: *
39: * Revision 2.2 90/08/27 21:48:35 dbg
40: * Created.
41: * [90/08/17 dbg]
42: *
43: */
44: /*
45: * Author: David B. Golub, Carnegie Mellon University
46: * Date: 7/90
47: */
48: /*
49: * Symbol table routines for a.out format files.
50: */
51:
52: #include "param.h"
53: #include "proc.h"
54: #include <machine/db_machdep.h> /* data types */
55: #include <ddb/db_sym.h>
56:
57: #ifndef DB_NO_AOUT
58:
59: #define _AOUT_INCLUDE_
60: #include "nlist.h"
61:
62: /*
63: * An a.out symbol table as loaded into the kernel debugger:
64: *
65: * symtab -> size of symbol entries, in bytes
66: * sp -> first symbol entry
67: * ...
68: * ep -> last symbol entry + 1
69: * strtab == start of string table
70: * size of string table in bytes,
71: * including this word
72: * -> strings
73: */
74:
75: /*
76: * Find pointers to the start and end of the symbol entries,
77: * given a pointer to the start of the symbol table.
78: */
79: #define db_get_aout_symtab(symtab, sp, ep) \
80: (sp = (struct nlist *)((symtab) + 1), \
81: ep = (struct nlist *)((char *)sp + *(symtab)))
82:
83: #define SYMTAB_SPACE 63000
84: int db_symtabsize = SYMTAB_SPACE;
85: char db_symtab[SYMTAB_SPACE] = { 1 };
86:
87: X_db_sym_init(symtab, esymtab, name)
88: int * symtab; /* pointer to start of symbol table */
89: char * esymtab; /* pointer to end of string table,
90: for checking - rounded up to integer
91: boundary */
92: char * name;
93: {
94: register struct nlist *sym_start, *sym_end;
95: register struct nlist *sp;
96: register char * strtab;
97: register int strlen;
98:
99: if (*symtab < 4) {
100: printf ("DDB: no symbols\n");
101: return;
102: }
103:
104: db_get_aout_symtab(symtab, sym_start, sym_end);
105:
106: strtab = (char *)sym_end;
107: strlen = *(int *)strtab;
108:
109: #if 0
110: if (strtab + ((strlen + sizeof(int) - 1) & ~(sizeof(int)-1))
111: != esymtab)
112: {
113: db_printf("[ %s symbol table not valid ]\n", name);
114: return;
115: }
116:
117: db_printf("[ preserving %#x bytes of %s symbol table ]\n",
118: esymtab - (char *)symtab, name);
119: #endif
120:
121: for (sp = sym_start; sp < sym_end; sp++) {
122: register int strx;
123: strx = sp->n_un.n_strx;
124: if (strx != 0) {
125: if (strx > strlen) {
126: db_printf("Bad string table index (%#x)\n", strx);
127: sp->n_un.n_name = 0;
128: continue;
129: }
130: sp->n_un.n_name = strtab + strx;
131: }
132: }
133:
134: db_add_symbol_table(sym_start, sym_end, name, (char *)symtab);
135: }
136:
137: db_sym_t
138: X_db_lookup(stab, symstr)
139: db_symtab_t *stab;
140: char * symstr;
141: {
142: register struct nlist *sp, *ep;
143:
144: sp = (struct nlist *)stab->start;
145: ep = (struct nlist *)stab->end;
146:
147: for (; sp < ep; sp++) {
148: if (sp->n_un.n_name == 0)
149: continue;
150: if ((sp->n_type & N_STAB) == 0 &&
151: sp->n_un.n_name != 0 &&
152: db_eqname(sp->n_un.n_name, symstr, '_'))
153: {
154: return ((db_sym_t)sp);
155: }
156: }
157: return ((db_sym_t)0);
158: }
159:
160: db_sym_t
161: X_db_search_symbol(symtab, off, strategy, diffp)
162: db_symtab_t * symtab;
163: register
164: db_addr_t off;
165: db_strategy_t strategy;
166: db_expr_t *diffp; /* in/out */
167: {
168: register unsigned int diff = *diffp;
169: register struct nlist *symp = 0;
170: register struct nlist *sp, *ep;
171:
172: sp = (struct nlist *)symtab->start;
173: ep = (struct nlist *)symtab->end;
174:
175: for (; sp < ep; sp++) {
176: if (sp->n_un.n_name == 0)
177: continue;
178: if ((sp->n_type & N_STAB) != 0)
179: continue;
180: if (off >= sp->n_value) {
181: if (off - sp->n_value < diff) {
182: diff = off - sp->n_value;
183: symp = sp;
184: if (diff == 0)
185: break;
186: }
187: else if (off - sp->n_value == diff) {
188: if (symp == 0)
189: symp = sp;
190: else if ((symp->n_type & N_EXT) == 0 &&
191: (sp->n_type & N_EXT) != 0)
192: symp = sp; /* pick the external symbol */
193: }
194: }
195: }
196: if (symp == 0) {
197: *diffp = off;
198: }
199: else {
200: *diffp = diff;
201: }
202: return ((db_sym_t)symp);
203: }
204:
205: /*
206: * Return the name and value for a symbol.
207: */
208: void
209: X_db_symbol_values(sym, namep, valuep)
210: db_sym_t sym;
211: char **namep;
212: db_expr_t *valuep;
213: {
214: register struct nlist *sp;
215:
216: sp = (struct nlist *)sym;
217: if (namep)
218: *namep = sp->n_un.n_name;
219: if (valuep)
220: *valuep = sp->n_value;
221: }
222:
223: boolean_t
224: X_db_line_at_pc()
225: {
226: return (FALSE);
227: }
228:
229: /*
230: * Initialization routine for a.out files.
231: */
232: kdb_init()
233: {
234: #if 0
235: extern char *esym;
236: extern int end;
237:
238: if (esym > (char *)&end) {
239: X_db_sym_init((int *)&end, esym, "mach");
240: }
241: #endif
242:
243: X_db_sym_init (db_symtab, 0, "mach");
244: }
245:
246: #if 0
247: /*
248: * Read symbol table from file.
249: * (should be somewhere else)
250: */
251: #include <boot_ufs/file_io.h>
252: #include <vm/vm_kern.h>
253:
254: read_symtab_from_file(fp, symtab_name)
255: struct file *fp;
256: char * symtab_name;
257: {
258: vm_size_t resid;
259: kern_return_t result;
260: vm_offset_t symoff;
261: vm_size_t symsize;
262: vm_offset_t stroff;
263: vm_size_t strsize;
264: vm_size_t table_size;
265: vm_offset_t symtab;
266:
267: if (!get_symtab(fp, &symoff, &symsize)) {
268: boot_printf("[ error %d reading %s file header ]\n",
269: result, symtab_name);
270: return;
271: }
272:
273: stroff = symoff + symsize;
274: result = read_file(fp, (vm_offset_t)stroff,
275: (vm_offset_t)&strsize, sizeof(strsize), &resid);
276: if (result || resid) {
277: boot_printf("[ no valid symbol table present for %s ]\n",
278: symtab_name);
279: return;
280: }
281:
282: table_size = sizeof(int) + symsize + strsize;
283: table_size = (table_size + sizeof(int)-1) & ~(sizeof(int)-1);
284:
285: symtab = kmem_alloc_wired(kernel_map, table_size);
286:
287: *(int *)symtab = symsize;
288:
289: result = read_file(fp, symoff,
290: symtab + sizeof(int), symsize, &resid);
291: if (result || resid) {
292: boot_printf("[ error %d reading %s symbol table ]\n",
293: result, symtab_name);
294: return;
295: }
296:
297: result = read_file(fp, stroff,
298: symtab + sizeof(int) + symsize, strsize, &resid);
299: if (result || resid) {
300: boot_printf("[ error %d reading %s string table ]\n",
301: result, symtab_name);
302: return;
303: }
304:
305: X_db_sym_init((int *)symtab,
306: (char *)(symtab + table_size),
307: symtab_name);
308:
309: }
310: #endif
311:
312: #endif /* DB_NO_AOUT */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.