Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Read os9/os9k symbol tables and convert to internal format, for GDB. |
b6ba6518 KB |
2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
3 | 1996, 1997, 1998, 1999, 2000, 2001 | |
c906108c SS |
4 | Free Software Foundation, Inc. |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | /* This module provides three functions: os9k_symfile_init, | |
24 | which initializes to read a symbol file; os9k_new_init, which | |
25 | discards existing cached information when all symbols are being | |
26 | discarded; and os9k_symfile_read, which reads a symbol table | |
27 | from a file. | |
28 | ||
29 | os9k_symfile_read only does the minimum work necessary for letting the | |
30 | user "name" things symbolically; it does not read the entire symtab. | |
31 | Instead, it reads the external and static symbols and puts them in partial | |
32 | symbol tables. When more extensive information is requested of a | |
33 | file, the corresponding partial symbol table is mutated into a full | |
34 | fledged symbol table by going back and reading the symbols | |
35 | for real. os9k_psymtab_to_symtab() is the function that does this */ | |
36 | ||
37 | #include "defs.h" | |
38 | #include "gdb_string.h" | |
088d891f | 39 | #include "gdb_assert.h" |
c906108c SS |
40 | #include <stdio.h> |
41 | ||
42 | #if defined(USG) || defined(__CYGNUSCLIB__) | |
43 | #include <sys/types.h> | |
44 | #include <fcntl.h> | |
45 | #endif | |
46 | ||
47 | #include "obstack.h" | |
48 | #include "gdb_stat.h" | |
c906108c SS |
49 | #include "symtab.h" |
50 | #include "breakpoint.h" | |
51 | #include "command.h" | |
52 | #include "target.h" | |
53 | #include "gdbcore.h" /* for bfd stuff */ | |
c5aa993b | 54 | #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ |
c906108c SS |
55 | #include "symfile.h" |
56 | #include "objfiles.h" | |
57 | #include "buildsym.h" | |
58 | #include "gdb-stabs.h" | |
59 | #include "demangle.h" | |
60 | #include "language.h" /* Needed inside partial-stab.h */ | |
61 | #include "complaints.h" | |
62 | #include "os9k.h" | |
63 | #include "stabsread.h" | |
64 | ||
a14ed312 | 65 | extern void _initialize_os9kread (void); |
392a587b | 66 | |
c906108c SS |
67 | /* Each partial symbol table entry contains a pointer to private data for the |
68 | read_symtab() function to use when expanding a partial symbol table entry | |
69 | to a full symbol table entry. | |
70 | ||
71 | For dbxread this structure contains the offset within the file symbol table | |
72 | of first local symbol for this file, and count of the section | |
73 | of the symbol table devoted to this file's symbols (actually, the section | |
74 | bracketed may contain more than just this file's symbols). It also contains | |
75 | further information needed to locate the symbols if they are in an ELF file. | |
76 | ||
77 | If ldsymcnt is 0, the only reason for this thing's existence is the | |
78 | dependency list. Nothing else will happen when it is read in. */ | |
79 | ||
80 | #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) | |
81 | #define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum) | |
82 | ||
c5aa993b JM |
83 | struct symloc |
84 | { | |
85 | int ldsymoff; | |
86 | int ldsymnum; | |
87 | }; | |
c906108c SS |
88 | |
89 | /* Remember what we deduced to be the source language of this psymtab. */ | |
90 | static enum language psymtab_language = language_unknown; | |
91 | ||
92 | /* keep partial symbol table file nested depth */ | |
93 | static int psymfile_depth = 0; | |
94 | ||
95 | /* keep symbol table file nested depth */ | |
96 | static int symfile_depth = 0; | |
97 | ||
98 | /* Nonzero means give verbose info on gdb action. From main.c. */ | |
99 | extern int info_verbose; | |
100 | ||
101 | extern int previous_stab_code; | |
102 | ||
103 | /* Name of last function encountered. Used in Solaris to approximate | |
104 | object file boundaries. */ | |
105 | static char *last_function_name; | |
106 | ||
107 | /* Complaints about the symbols we have encountered. */ | |
108 | extern struct complaint lbrac_complaint; | |
109 | ||
110 | extern struct complaint unknown_symtype_complaint; | |
111 | ||
112 | extern struct complaint unknown_symchar_complaint; | |
113 | ||
114 | extern struct complaint lbrac_rbrac_complaint; | |
115 | ||
116 | extern struct complaint repeated_header_complaint; | |
117 | ||
118 | extern struct complaint repeated_header_name_complaint; | |
119 | ||
120 | #if 0 | |
121 | static struct complaint lbrac_unmatched_complaint = | |
c5aa993b | 122 | {"unmatched Increment Block Entry before symtab pos %d", 0, 0}; |
c906108c SS |
123 | |
124 | static struct complaint lbrac_mismatch_complaint = | |
c5aa993b | 125 | {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0}; |
c906108c SS |
126 | #endif |
127 | \f | |
128 | /* Local function prototypes */ | |
129 | ||
a14ed312 | 130 | static void read_minimal_symbols (struct objfile *); |
c906108c | 131 | |
a14ed312 | 132 | static void os9k_read_ofile_symtab (struct partial_symtab *); |
c906108c | 133 | |
a14ed312 | 134 | static void os9k_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 135 | |
a14ed312 | 136 | static void os9k_psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 137 | |
a14ed312 | 138 | static void read_os9k_psymtab (struct objfile *, CORE_ADDR, int); |
c906108c | 139 | |
a14ed312 | 140 | static int fill_sym (FILE *, bfd *); |
c906108c | 141 | |
a14ed312 | 142 | static void os9k_symfile_init (struct objfile *); |
c906108c | 143 | |
a14ed312 | 144 | static void os9k_new_init (struct objfile *); |
c906108c | 145 | |
a14ed312 | 146 | static void os9k_symfile_read (struct objfile *, int); |
c906108c | 147 | |
a14ed312 | 148 | static void os9k_symfile_finish (struct objfile *); |
c906108c SS |
149 | |
150 | static void | |
a14ed312 KB |
151 | os9k_process_one_symbol (int, int, CORE_ADDR, char *, |
152 | struct section_offsets *, struct objfile *); | |
c906108c | 153 | |
a14ed312 KB |
154 | static struct partial_symtab *os9k_start_psymtab (struct objfile *, char *, |
155 | CORE_ADDR, int, int, | |
156 | struct partial_symbol **, | |
157 | struct partial_symbol **); | |
c906108c | 158 | |
a14ed312 KB |
159 | static struct partial_symtab *os9k_end_psymtab (struct partial_symtab *, |
160 | char **, int, int, CORE_ADDR, | |
161 | struct partial_symtab **, | |
162 | int); | |
c906108c | 163 | |
a14ed312 | 164 | static void record_minimal_symbol (char *, CORE_ADDR, int, struct objfile *); |
c906108c SS |
165 | \f |
166 | #define HANDLE_RBRAC(val) \ | |
167 | if ((val) > pst->texthigh) pst->texthigh = (val); | |
168 | ||
169 | #define SWAP_STBHDR(hdrp, abfd) \ | |
170 | { \ | |
171 | (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \ | |
172 | (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \ | |
173 | (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \ | |
174 | (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \ | |
175 | } | |
176 | #define SWAP_STBSYM(symp, abfd) \ | |
177 | { \ | |
178 | (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \ | |
179 | (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \ | |
180 | (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \ | |
181 | } | |
182 | #define N_DATA 0 | |
183 | #define N_BSS 1 | |
184 | #define N_RDATA 2 | |
185 | #define N_IDATA 3 | |
186 | #define N_TEXT 4 | |
187 | #define N_ABS 6 | |
188 | ||
189 | static void | |
fba45db2 KB |
190 | record_minimal_symbol (char *name, CORE_ADDR address, int type, |
191 | struct objfile *objfile) | |
c906108c SS |
192 | { |
193 | enum minimal_symbol_type ms_type; | |
194 | ||
195 | switch (type) | |
196 | { | |
197 | case N_TEXT: | |
c5aa993b | 198 | ms_type = mst_text; |
b8fbeb18 | 199 | address += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b | 200 | break; |
c906108c | 201 | case N_DATA: |
c5aa993b JM |
202 | ms_type = mst_data; |
203 | break; | |
c906108c | 204 | case N_BSS: |
c5aa993b JM |
205 | ms_type = mst_bss; |
206 | break; | |
c906108c | 207 | case N_RDATA: |
c5aa993b JM |
208 | ms_type = mst_bss; |
209 | break; | |
210 | case N_IDATA: | |
211 | ms_type = mst_data; | |
212 | break; | |
c906108c | 213 | case N_ABS: |
c5aa993b JM |
214 | ms_type = mst_abs; |
215 | break; | |
c906108c | 216 | default: |
c5aa993b JM |
217 | ms_type = mst_unknown; |
218 | break; | |
219 | } | |
c906108c SS |
220 | |
221 | prim_record_minimal_symbol (name, address, ms_type, objfile); | |
222 | } | |
223 | ||
224 | /* read and process .stb file and store in minimal symbol table */ | |
225 | typedef char mhhdr[80]; | |
c5aa993b JM |
226 | struct stbhdr |
227 | { | |
228 | mhhdr comhdr; | |
229 | char *name; | |
230 | short fmtno; | |
231 | int crc; | |
232 | int offset; | |
233 | int nsym; | |
234 | char *pad; | |
235 | }; | |
236 | struct stbsymbol | |
237 | { | |
238 | int value; | |
239 | short type; | |
240 | int stroff; | |
241 | }; | |
c906108c SS |
242 | #define STBSYMSIZE 10 |
243 | ||
244 | static void | |
fba45db2 | 245 | read_minimal_symbols (struct objfile *objfile) |
c906108c | 246 | { |
c5aa993b JM |
247 | FILE *fp; |
248 | bfd *abfd; | |
249 | struct stbhdr hdr; | |
250 | struct stbsymbol sym; | |
251 | int ch, i, j, off; | |
252 | char buf[64], buf1[128]; | |
253 | ||
c906108c | 254 | fp = objfile->auxf1; |
c5aa993b JM |
255 | if (fp == NULL) |
256 | return; | |
c906108c | 257 | abfd = objfile->obfd; |
c5aa993b | 258 | fread (&hdr.comhdr[0], sizeof (mhhdr), 1, fp); |
c906108c | 259 | i = 0; |
c5aa993b JM |
260 | ch = getc (fp); |
261 | while (ch != -1) | |
262 | { | |
263 | buf[i] = (char) ch; | |
264 | i++; | |
265 | if (ch == 0) | |
266 | break; | |
267 | ch = getc (fp); | |
268 | }; | |
269 | if (i % 2) | |
270 | ch = getc (fp); | |
c906108c SS |
271 | hdr.name = &buf[0]; |
272 | ||
c5aa993b JM |
273 | fread (&hdr.fmtno, sizeof (hdr.fmtno), 1, fp); |
274 | fread (&hdr.crc, sizeof (hdr.crc), 1, fp); | |
275 | fread (&hdr.offset, sizeof (hdr.offset), 1, fp); | |
276 | fread (&hdr.nsym, sizeof (hdr.nsym), 1, fp); | |
277 | SWAP_STBHDR (&hdr, abfd); | |
278 | ||
c906108c | 279 | /* read symbols */ |
c5aa993b | 280 | init_minimal_symbol_collection (); |
c906108c | 281 | off = hdr.offset; |
c5aa993b JM |
282 | for (i = hdr.nsym; i > 0; i--) |
283 | { | |
284 | fseek (fp, (long) off, 0); | |
285 | fread (&sym.value, sizeof (sym.value), 1, fp); | |
286 | fread (&sym.type, sizeof (sym.type), 1, fp); | |
287 | fread (&sym.stroff, sizeof (sym.stroff), 1, fp); | |
288 | SWAP_STBSYM (&sym, abfd); | |
289 | fseek (fp, (long) sym.stroff, 0); | |
290 | j = 0; | |
291 | ch = getc (fp); | |
292 | while (ch != -1) | |
293 | { | |
294 | buf1[j] = (char) ch; | |
295 | j++; | |
296 | if (ch == 0) | |
297 | break; | |
298 | ch = getc (fp); | |
299 | }; | |
d4f3574e | 300 | record_minimal_symbol (buf1, sym.value, sym.type & 7, objfile); |
c5aa993b | 301 | off += STBSYMSIZE; |
c906108c | 302 | }; |
c906108c SS |
303 | install_minimal_symbols (objfile); |
304 | return; | |
305 | } | |
306 | \f | |
307 | /* Scan and build partial symbols for a symbol file. | |
308 | We have been initialized by a call to os9k_symfile_init, which | |
309 | put all the relevant info into a "struct os9k_symfile_info", | |
310 | hung off the objfile structure. | |
311 | ||
c906108c SS |
312 | MAINLINE is true if we are reading the main symbol |
313 | table (as opposed to a shared lib or dynamically loaded file). */ | |
314 | ||
315 | static void | |
fa6b9313 | 316 | os9k_symfile_read (struct objfile *objfile, int mainline) |
c906108c SS |
317 | { |
318 | bfd *sym_bfd; | |
319 | struct cleanup *back_to; | |
320 | ||
321 | sym_bfd = objfile->obfd; | |
322 | /* If we are reinitializing, or if we have never loaded syms yet, init */ | |
c5aa993b JM |
323 | if (mainline || objfile->global_psymbols.size == 0 || |
324 | objfile->static_psymbols.size == 0) | |
c906108c SS |
325 | init_psymbol_list (objfile, DBX_SYMCOUNT (objfile)); |
326 | ||
327 | free_pending_blocks (); | |
a0b3c4fd | 328 | back_to = make_cleanup (really_free_pendings, 0); |
c906108c | 329 | |
56e290f4 | 330 | make_cleanup_discard_minimal_symbols (); |
d4f3574e | 331 | read_minimal_symbols (objfile); |
c906108c SS |
332 | |
333 | /* Now that the symbol table data of the executable file are all in core, | |
334 | process them and define symbols accordingly. */ | |
d4f3574e | 335 | read_os9k_psymtab (objfile, |
c906108c SS |
336 | DBX_TEXT_ADDR (objfile), |
337 | DBX_TEXT_SIZE (objfile)); | |
338 | ||
339 | do_cleanups (back_to); | |
340 | } | |
341 | ||
342 | /* Initialize anything that needs initializing when a completely new | |
343 | symbol file is specified (not just adding some symbols from another | |
344 | file, e.g. a shared library). */ | |
345 | ||
346 | static void | |
fba45db2 | 347 | os9k_new_init (struct objfile *ignore) |
c906108c SS |
348 | { |
349 | stabsread_new_init (); | |
350 | buildsym_new_init (); | |
351 | psymfile_depth = 0; | |
352 | /* | |
c5aa993b JM |
353 | init_header_files (); |
354 | */ | |
c906108c SS |
355 | } |
356 | ||
357 | /* os9k_symfile_init () | |
358 | It is passed a struct objfile which contains, among other things, | |
359 | the BFD for the file whose symbols are being read, and a slot for a pointer | |
360 | to "private data" which we fill with goodies. | |
361 | ||
362 | Since BFD doesn't know how to read debug symbols in a format-independent | |
363 | way (and may never do so...), we have to do it ourselves. We will never | |
364 | be called unless this is an a.out (or very similar) file. | |
365 | FIXME, there should be a cleaner peephole into the BFD environment here. */ | |
366 | ||
367 | static void | |
fba45db2 | 368 | os9k_symfile_init (struct objfile *objfile) |
c906108c SS |
369 | { |
370 | bfd *sym_bfd = objfile->obfd; | |
371 | char *name = bfd_get_filename (sym_bfd); | |
372 | char dbgname[512], stbname[512]; | |
373 | FILE *symfile = 0; | |
374 | FILE *minfile = 0; | |
375 | asection *text_sect; | |
376 | ||
c5aa993b JM |
377 | strcpy (dbgname, name); |
378 | strcat (dbgname, ".dbg"); | |
379 | strcpy (stbname, name); | |
380 | strcat (stbname, ".stb"); | |
c906108c | 381 | |
c5aa993b JM |
382 | if ((symfile = fopen (dbgname, "r")) == NULL) |
383 | { | |
384 | warning ("Symbol file %s not found", dbgname); | |
385 | } | |
c906108c SS |
386 | objfile->auxf2 = symfile; |
387 | ||
c5aa993b JM |
388 | if ((minfile = fopen (stbname, "r")) == NULL) |
389 | { | |
390 | warning ("Symbol file %s not found", stbname); | |
391 | } | |
c906108c SS |
392 | objfile->auxf1 = minfile; |
393 | ||
394 | /* Allocate struct to keep track of the symfile */ | |
395 | objfile->sym_stab_info = (struct dbx_symfile_info *) | |
c5aa993b | 396 | xmmalloc (objfile->md, sizeof (struct dbx_symfile_info)); |
c906108c SS |
397 | DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL; |
398 | ||
399 | text_sect = bfd_get_section_by_name (sym_bfd, ".text"); | |
400 | if (!text_sect) | |
401 | error ("Can't find .text section in file"); | |
402 | DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); | |
403 | DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); | |
404 | ||
c5aa993b JM |
405 | DBX_SYMBOL_SIZE (objfile) = 0; /* variable size symbol */ |
406 | DBX_SYMCOUNT (objfile) = 0; /* used to be bfd_get_symcount(sym_bfd) */ | |
407 | DBX_SYMTAB_OFFSET (objfile) = 0; /* used to be SYMBOL_TABLE_OFFSET */ | |
c906108c SS |
408 | } |
409 | ||
410 | /* Perform any local cleanups required when we are done with a particular | |
411 | objfile. I.E, we are in the process of discarding all symbol information | |
412 | for an objfile, freeing up all memory held for it, and unlinking the | |
413 | objfile struct from the global list of known objfiles. */ | |
414 | ||
415 | static void | |
fba45db2 | 416 | os9k_symfile_finish (struct objfile *objfile) |
c906108c SS |
417 | { |
418 | if (objfile->sym_stab_info != NULL) | |
419 | { | |
c5aa993b | 420 | mfree (objfile->md, objfile->sym_stab_info); |
c906108c SS |
421 | } |
422 | /* | |
c5aa993b JM |
423 | free_header_files (); |
424 | */ | |
c906108c | 425 | } |
c906108c | 426 | \f |
c5aa993b JM |
427 | |
428 | struct st_dbghdr | |
429 | { | |
c906108c SS |
430 | int sync; |
431 | short rev; | |
432 | int crc; | |
433 | short os; | |
434 | short cpu; | |
435 | }; | |
436 | #define SYNC (int)0xefbefeca | |
437 | ||
438 | #define SWAP_DBGHDR(hdrp, abfd) \ | |
439 | { \ | |
440 | (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \ | |
441 | (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \ | |
442 | (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \ | |
443 | (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \ | |
444 | (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \ | |
445 | } | |
446 | ||
447 | #define N_SYM_CMPLR 0 | |
448 | #define N_SYM_SLINE 1 | |
449 | #define N_SYM_SYM 2 | |
450 | #define N_SYM_LBRAC 3 | |
451 | #define N_SYM_RBRAC 4 | |
452 | #define N_SYM_SE 5 | |
453 | ||
c5aa993b JM |
454 | struct internal_symstruct |
455 | { | |
456 | short n_type; | |
457 | short n_desc; | |
458 | long n_value; | |
459 | char *n_strx; | |
460 | }; | |
c906108c SS |
461 | static struct internal_symstruct symbol; |
462 | static struct internal_symstruct *symbuf = &symbol; | |
463 | static char strbuf[4096]; | |
464 | static struct st_dbghdr dbghdr; | |
465 | static short cmplrid; | |
466 | ||
467 | #define VER_PRE_ULTRAC ((short)4) | |
468 | #define VER_ULTRAC ((short)5) | |
469 | ||
470 | static int | |
fba45db2 | 471 | fill_sym (FILE *dbg_file, bfd *abfd) |
c906108c | 472 | { |
c5aa993b JM |
473 | short si, nmask; |
474 | long li; | |
475 | int ii; | |
476 | char *p; | |
c906108c | 477 | |
c5aa993b | 478 | int nbytes = fread (&si, sizeof (si), 1, dbg_file); |
c906108c SS |
479 | if (nbytes == 0) |
480 | return 0; | |
481 | if (nbytes < 0) | |
482 | perror_with_name ("reading .dbg file."); | |
483 | symbuf->n_desc = 0; | |
484 | symbuf->n_value = 0; | |
485 | symbuf->n_strx = NULL; | |
c5aa993b | 486 | symbuf->n_type = bfd_get_16 (abfd, (unsigned char *) &si); |
c906108c SS |
487 | symbuf->n_type = 0xf & symbuf->n_type; |
488 | switch (symbuf->n_type) | |
489 | { | |
490 | case N_SYM_CMPLR: | |
c5aa993b JM |
491 | fread (&si, sizeof (si), 1, dbg_file); |
492 | symbuf->n_desc = bfd_get_16 (abfd, (unsigned char *) &si); | |
c906108c SS |
493 | cmplrid = symbuf->n_desc & 0xff; |
494 | break; | |
495 | case N_SYM_SLINE: | |
c5aa993b JM |
496 | fread (&li, sizeof (li), 1, dbg_file); |
497 | symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li); | |
498 | fread (&li, sizeof (li), 1, dbg_file); | |
499 | li = bfd_get_32 (abfd, (unsigned char *) &li); | |
500 | symbuf->n_strx = (char *) (li >> 12); | |
c906108c SS |
501 | symbuf->n_desc = li & 0xfff; |
502 | break; | |
503 | case N_SYM_SYM: | |
c5aa993b JM |
504 | fread (&li, sizeof (li), 1, dbg_file); |
505 | symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li); | |
c906108c | 506 | si = 0; |
c5aa993b JM |
507 | do |
508 | { | |
509 | ii = getc (dbg_file); | |
510 | strbuf[si++] = (char) ii; | |
511 | } | |
512 | while (ii != 0 || si % 2 != 0); | |
c906108c SS |
513 | symbuf->n_strx = strbuf; |
514 | p = (char *) strchr (strbuf, ':'); | |
c5aa993b JM |
515 | if (!p) |
516 | break; | |
c906108c SS |
517 | if ((p[1] == 'F' || p[1] == 'f') && cmplrid == VER_PRE_ULTRAC) |
518 | { | |
c5aa993b JM |
519 | fread (&si, sizeof (si), 1, dbg_file); |
520 | nmask = bfd_get_16 (abfd, (unsigned char *) &si); | |
521 | for (ii = 0; ii < nmask; ii++) | |
522 | fread (&si, sizeof (si), 1, dbg_file); | |
c906108c SS |
523 | } |
524 | break; | |
525 | case N_SYM_LBRAC: | |
c5aa993b JM |
526 | fread (&li, sizeof (li), 1, dbg_file); |
527 | symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li); | |
c906108c SS |
528 | break; |
529 | case N_SYM_RBRAC: | |
c5aa993b JM |
530 | fread (&li, sizeof (li), 1, dbg_file); |
531 | symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li); | |
c906108c SS |
532 | break; |
533 | case N_SYM_SE: | |
534 | break; | |
535 | } | |
c5aa993b | 536 | return 1; |
c906108c SS |
537 | } |
538 | \f | |
539 | /* Given pointers to an a.out symbol table in core containing dbx | |
540 | style data, setup partial_symtab's describing each source file for | |
541 | which debugging information is available. | |
d4f3574e | 542 | SYMFILE_NAME is the name of the file we are reading from. */ |
c906108c SS |
543 | |
544 | static void | |
fba45db2 | 545 | read_os9k_psymtab (struct objfile *objfile, CORE_ADDR text_addr, int text_size) |
c906108c | 546 | { |
c5aa993b | 547 | register struct internal_symstruct *bufp = 0; /* =0 avoids gcc -Wall glitch */ |
c906108c SS |
548 | register char *namestring; |
549 | int past_first_source_file = 0; | |
550 | CORE_ADDR last_o_file_start = 0; | |
551 | #if 0 | |
552 | struct cleanup *back_to; | |
553 | #endif | |
554 | bfd *abfd; | |
555 | FILE *fp; | |
556 | ||
557 | /* End of the text segment of the executable file. */ | |
558 | static CORE_ADDR end_of_text_addr; | |
559 | ||
560 | /* Current partial symtab */ | |
561 | static struct partial_symtab *pst = 0; | |
562 | ||
563 | /* List of current psymtab's include files */ | |
564 | char **psymtab_include_list; | |
565 | int includes_allocated; | |
566 | int includes_used; | |
567 | ||
568 | /* Index within current psymtab dependency list */ | |
569 | struct partial_symtab **dependency_list; | |
570 | int dependencies_used, dependencies_allocated; | |
571 | ||
572 | includes_allocated = 30; | |
573 | includes_used = 0; | |
574 | psymtab_include_list = (char **) alloca (includes_allocated * | |
575 | sizeof (char *)); | |
576 | ||
577 | dependencies_allocated = 30; | |
578 | dependencies_used = 0; | |
579 | dependency_list = | |
580 | (struct partial_symtab **) alloca (dependencies_allocated * | |
581 | sizeof (struct partial_symtab *)); | |
582 | ||
583 | last_source_file = NULL; | |
584 | ||
585 | #ifdef END_OF_TEXT_DEFAULT | |
586 | end_of_text_addr = END_OF_TEXT_DEFAULT; | |
587 | #else | |
b8fbeb18 | 588 | end_of_text_addr = text_addr + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)) |
c5aa993b | 589 | + text_size; /* Relocate */ |
c906108c SS |
590 | #endif |
591 | ||
592 | abfd = objfile->obfd; | |
c5aa993b JM |
593 | fp = objfile->auxf2; |
594 | if (!fp) | |
595 | return; | |
596 | ||
597 | fread (&dbghdr.sync, sizeof (dbghdr.sync), 1, fp); | |
598 | fread (&dbghdr.rev, sizeof (dbghdr.rev), 1, fp); | |
599 | fread (&dbghdr.crc, sizeof (dbghdr.crc), 1, fp); | |
600 | fread (&dbghdr.os, sizeof (dbghdr.os), 1, fp); | |
601 | fread (&dbghdr.cpu, sizeof (dbghdr.cpu), 1, fp); | |
602 | SWAP_DBGHDR (&dbghdr, abfd); | |
c906108c SS |
603 | |
604 | symnum = 0; | |
c5aa993b | 605 | while (1) |
c906108c | 606 | { |
c5aa993b JM |
607 | int ret; |
608 | long cursymoffset; | |
c906108c SS |
609 | |
610 | /* Get the symbol for this run and pull out some info */ | |
c5aa993b JM |
611 | QUIT; /* allow this to be interruptable */ |
612 | cursymoffset = ftell (objfile->auxf2); | |
613 | ret = fill_sym (objfile->auxf2, abfd); | |
614 | if (ret <= 0) | |
615 | break; | |
616 | else | |
617 | symnum++; | |
c906108c SS |
618 | bufp = symbuf; |
619 | ||
620 | /* Special case to speed up readin. */ | |
c5aa993b JM |
621 | if (bufp->n_type == (short) N_SYM_SLINE) |
622 | continue; | |
c906108c SS |
623 | |
624 | #define CUR_SYMBOL_VALUE bufp->n_value | |
625 | /* partial-stab.h */ | |
626 | ||
627 | switch (bufp->n_type) | |
628 | { | |
c5aa993b | 629 | char *p; |
c906108c SS |
630 | |
631 | case N_SYM_CMPLR: | |
632 | continue; | |
633 | ||
634 | case N_SYM_SE: | |
b8fbeb18 | 635 | CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
636 | if (psymfile_depth == 1 && pst) |
637 | { | |
638 | os9k_end_psymtab (pst, psymtab_include_list, includes_used, | |
c5aa993b JM |
639 | symnum, CUR_SYMBOL_VALUE, |
640 | dependency_list, dependencies_used); | |
c906108c SS |
641 | pst = (struct partial_symtab *) 0; |
642 | includes_used = 0; | |
643 | dependencies_used = 0; | |
644 | } | |
c5aa993b | 645 | psymfile_depth--; |
c906108c SS |
646 | continue; |
647 | ||
c5aa993b | 648 | case N_SYM_SYM: /* Typedef or automatic variable. */ |
c906108c | 649 | namestring = bufp->n_strx; |
c5aa993b JM |
650 | p = (char *) strchr (namestring, ':'); |
651 | if (!p) | |
652 | continue; /* Not a debugging symbol. */ | |
c906108c SS |
653 | |
654 | /* Main processing section for debugging symbols which | |
655 | the initial read through the symbol tables needs to worry | |
656 | about. If we reach this point, the symbol which we are | |
657 | considering is definitely one we are interested in. | |
658 | p must also contain the (valid) index into the namestring | |
659 | which indicates the debugging type symbol. */ | |
660 | ||
661 | switch (p[1]) | |
662 | { | |
c5aa993b | 663 | case 'S': |
c906108c SS |
664 | { |
665 | unsigned long valu; | |
c5aa993b | 666 | enum language tmp_language; |
c906108c SS |
667 | char *str, *p; |
668 | int n; | |
c5aa993b | 669 | |
c906108c SS |
670 | valu = CUR_SYMBOL_VALUE; |
671 | if (valu) | |
b8fbeb18 | 672 | valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
673 | past_first_source_file = 1; |
674 | ||
c5aa993b JM |
675 | p = strchr (namestring, ':'); |
676 | if (p) | |
677 | n = p - namestring; | |
678 | else | |
679 | n = strlen (namestring); | |
680 | str = alloca (n + 1); | |
681 | strncpy (str, namestring, n); | |
682 | str[n] = '\0'; | |
c906108c | 683 | |
c5aa993b | 684 | if (psymfile_depth == 0) |
c906108c | 685 | { |
c5aa993b | 686 | if (!pst) |
d4f3574e | 687 | pst = os9k_start_psymtab (objfile, |
c5aa993b JM |
688 | str, valu, |
689 | cursymoffset, | |
690 | symnum - 1, | |
691 | objfile->global_psymbols.next, | |
692 | objfile->static_psymbols.next); | |
c906108c | 693 | } |
c5aa993b JM |
694 | else |
695 | { /* this is a include file */ | |
696 | tmp_language = deduce_language_from_filename (str); | |
697 | if (tmp_language != language_unknown | |
698 | && (tmp_language != language_c | |
699 | || psymtab_language != language_cplus)) | |
700 | psymtab_language = tmp_language; | |
c906108c | 701 | |
c5aa993b JM |
702 | /* |
703 | if (pst && STREQ (str, pst->filename)) | |
704 | continue; | |
705 | { | |
706 | register int i; | |
707 | for (i = 0; i < includes_used; i++) | |
708 | if (STREQ (str, psymtab_include_list[i])) | |
709 | { | |
710 | i = -1; | |
711 | break; | |
712 | } | |
713 | if (i == -1) | |
714 | continue; | |
715 | } | |
716 | */ | |
717 | ||
718 | psymtab_include_list[includes_used++] = str; | |
719 | if (includes_used >= includes_allocated) | |
720 | { | |
721 | char **orig = psymtab_include_list; | |
722 | ||
723 | psymtab_include_list = (char **) | |
724 | alloca ((includes_allocated *= 2) * sizeof (char *)); | |
725 | memcpy ((PTR) psymtab_include_list, (PTR) orig, | |
726 | includes_used * sizeof (char *)); | |
727 | } | |
c906108c | 728 | |
c5aa993b JM |
729 | } |
730 | psymfile_depth++; | |
c906108c SS |
731 | continue; |
732 | } | |
733 | ||
734 | case 'v': | |
735 | add_psymbol_to_list (namestring, p - namestring, | |
736 | VAR_NAMESPACE, LOC_STATIC, | |
737 | &objfile->static_psymbols, | |
738 | 0, CUR_SYMBOL_VALUE, | |
739 | psymtab_language, objfile); | |
740 | continue; | |
741 | case 'V': | |
742 | add_psymbol_to_list (namestring, p - namestring, | |
743 | VAR_NAMESPACE, LOC_STATIC, | |
744 | &objfile->global_psymbols, | |
745 | 0, CUR_SYMBOL_VALUE, | |
746 | psymtab_language, objfile); | |
747 | continue; | |
748 | ||
749 | case 'T': | |
750 | if (p != namestring) /* a name is there, not just :T... */ | |
751 | { | |
752 | add_psymbol_to_list (namestring, p - namestring, | |
753 | STRUCT_NAMESPACE, LOC_TYPEDEF, | |
754 | &objfile->static_psymbols, | |
755 | CUR_SYMBOL_VALUE, 0, | |
756 | psymtab_language, objfile); | |
757 | if (p[2] == 't') | |
758 | { | |
759 | /* Also a typedef with the same name. */ | |
760 | add_psymbol_to_list (namestring, p - namestring, | |
761 | VAR_NAMESPACE, LOC_TYPEDEF, | |
762 | &objfile->static_psymbols, | |
c5aa993b | 763 | CUR_SYMBOL_VALUE, 0, psymtab_language, |
c906108c SS |
764 | objfile); |
765 | p += 1; | |
766 | } | |
767 | /* The semantics of C++ state that "struct foo { ... }" | |
768 | also defines a typedef for "foo". Unfortuantely, cfront | |
769 | never makes the typedef when translating from C++ to C. | |
770 | We make the typedef here so that "ptype foo" works as | |
771 | expected for cfront translated code. */ | |
772 | else if (psymtab_language == language_cplus) | |
c5aa993b | 773 | { |
c906108c SS |
774 | /* Also a typedef with the same name. */ |
775 | add_psymbol_to_list (namestring, p - namestring, | |
776 | VAR_NAMESPACE, LOC_TYPEDEF, | |
777 | &objfile->static_psymbols, | |
c5aa993b | 778 | CUR_SYMBOL_VALUE, 0, psymtab_language, |
c906108c | 779 | objfile); |
c5aa993b | 780 | } |
c906108c SS |
781 | } |
782 | goto check_enum; | |
783 | case 't': | |
784 | if (p != namestring) /* a name is there, not just :T... */ | |
785 | { | |
786 | add_psymbol_to_list (namestring, p - namestring, | |
787 | VAR_NAMESPACE, LOC_TYPEDEF, | |
788 | &objfile->static_psymbols, | |
789 | CUR_SYMBOL_VALUE, 0, | |
790 | psymtab_language, objfile); | |
791 | } | |
792 | check_enum: | |
793 | /* If this is an enumerated type, we need to | |
c5aa993b JM |
794 | add all the enum constants to the partial symbol |
795 | table. This does not cover enums without names, e.g. | |
796 | "enum {a, b} c;" in C, but fortunately those are | |
797 | rare. There is no way for GDB to find those from the | |
798 | enum type without spending too much time on it. Thus | |
799 | to solve this problem, the compiler needs to put out the | |
800 | enum in a nameless type. GCC2 does this. */ | |
c906108c SS |
801 | |
802 | /* We are looking for something of the form | |
c5aa993b JM |
803 | <name> ":" ("t" | "T") [<number> "="] "e" <size> |
804 | {<constant> ":" <value> ","} ";". */ | |
c906108c SS |
805 | |
806 | /* Skip over the colon and the 't' or 'T'. */ | |
807 | p += 2; | |
808 | /* This type may be given a number. Also, numbers can come | |
c5aa993b | 809 | in pairs like (0,26). Skip over it. */ |
c906108c SS |
810 | while ((*p >= '0' && *p <= '9') |
811 | || *p == '(' || *p == ',' || *p == ')' | |
812 | || *p == '=') | |
813 | p++; | |
814 | ||
815 | if (*p++ == 'e') | |
816 | { | |
817 | /* We have found an enumerated type. skip size */ | |
c5aa993b JM |
818 | while (*p >= '0' && *p <= '9') |
819 | p++; | |
c906108c SS |
820 | /* According to comments in read_enum_type |
821 | a comma could end it instead of a semicolon. | |
822 | I don't know where that happens. | |
823 | Accept either. */ | |
824 | while (*p && *p != ';' && *p != ',') | |
825 | { | |
826 | char *q; | |
827 | ||
828 | /* Check for and handle cretinous dbx symbol name | |
c5aa993b JM |
829 | continuation! |
830 | if (*p == '\\') | |
831 | p = next_symbol_text (objfile); | |
832 | */ | |
c906108c SS |
833 | |
834 | /* Point to the character after the name | |
c5aa993b | 835 | of the enum constant. */ |
c906108c SS |
836 | for (q = p; *q && *q != ':'; q++) |
837 | ; | |
838 | /* Note that the value doesn't matter for | |
c5aa993b | 839 | enum constants in psymtabs, just in symtabs. */ |
c906108c SS |
840 | add_psymbol_to_list (p, q - p, |
841 | VAR_NAMESPACE, LOC_CONST, | |
842 | &objfile->static_psymbols, 0, | |
843 | 0, psymtab_language, objfile); | |
844 | /* Point past the name. */ | |
845 | p = q; | |
846 | /* Skip over the value. */ | |
847 | while (*p && *p != ',') | |
848 | p++; | |
849 | /* Advance past the comma. */ | |
850 | if (*p) | |
851 | p++; | |
852 | } | |
853 | } | |
854 | continue; | |
855 | case 'c': | |
856 | /* Constant, e.g. from "const" in Pascal. */ | |
857 | add_psymbol_to_list (namestring, p - namestring, | |
858 | VAR_NAMESPACE, LOC_CONST, | |
c5aa993b | 859 | &objfile->static_psymbols, CUR_SYMBOL_VALUE, |
c906108c SS |
860 | 0, psymtab_language, objfile); |
861 | continue; | |
862 | ||
863 | case 'f': | |
b8fbeb18 | 864 | CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
865 | if (pst && pst->textlow == 0) |
866 | pst->textlow = CUR_SYMBOL_VALUE; | |
c906108c SS |
867 | |
868 | add_psymbol_to_list (namestring, p - namestring, | |
869 | VAR_NAMESPACE, LOC_BLOCK, | |
c5aa993b | 870 | &objfile->static_psymbols, CUR_SYMBOL_VALUE, |
c906108c SS |
871 | 0, psymtab_language, objfile); |
872 | continue; | |
873 | ||
874 | case 'F': | |
b8fbeb18 | 875 | CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
876 | if (pst && pst->textlow == 0) |
877 | pst->textlow = CUR_SYMBOL_VALUE; | |
c906108c SS |
878 | |
879 | add_psymbol_to_list (namestring, p - namestring, | |
880 | VAR_NAMESPACE, LOC_BLOCK, | |
c5aa993b | 881 | &objfile->global_psymbols, CUR_SYMBOL_VALUE, |
c906108c SS |
882 | 0, psymtab_language, objfile); |
883 | continue; | |
884 | ||
885 | case 'p': | |
886 | case 'l': | |
c5aa993b | 887 | case 's': |
c906108c SS |
888 | continue; |
889 | ||
890 | case ':': | |
891 | /* It is a C++ nested symbol. We don't need to record it | |
c5aa993b JM |
892 | (I don't think); if we try to look up foo::bar::baz, |
893 | then symbols for the symtab containing foo should get | |
894 | read in, I think. */ | |
c906108c | 895 | /* Someone says sun cc puts out symbols like |
c5aa993b JM |
896 | /foo/baz/maclib::/usr/local/bin/maclib, |
897 | which would get here with a symbol type of ':'. */ | |
c906108c SS |
898 | continue; |
899 | ||
900 | default: | |
901 | /* Unexpected symbol descriptor. The second and subsequent stabs | |
c5aa993b JM |
902 | of a continued stab can show up here. The question is |
903 | whether they ever can mimic a normal stab--it would be | |
904 | nice if not, since we certainly don't want to spend the | |
905 | time searching to the end of every string looking for | |
906 | a backslash. */ | |
c906108c SS |
907 | |
908 | complain (&unknown_symchar_complaint, p[1]); | |
909 | continue; | |
910 | } | |
911 | ||
912 | case N_SYM_RBRAC: | |
b8fbeb18 | 913 | CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 914 | #ifdef HANDLE_RBRAC |
c5aa993b | 915 | HANDLE_RBRAC (CUR_SYMBOL_VALUE); |
c906108c SS |
916 | continue; |
917 | #endif | |
918 | case N_SYM_LBRAC: | |
919 | continue; | |
920 | ||
921 | default: | |
922 | /* If we haven't found it yet, ignore it. It's probably some | |
923 | new type we don't know about yet. */ | |
924 | complain (&unknown_symtype_complaint, | |
925 | local_hex_string ((unsigned long) bufp->n_type)); | |
926 | continue; | |
927 | } | |
928 | } | |
929 | ||
930 | DBX_SYMCOUNT (objfile) = symnum; | |
931 | ||
932 | /* If there's stuff to be cleaned up, clean it up. */ | |
933 | if (DBX_SYMCOUNT (objfile) > 0 | |
934 | /*FIXME, does this have a bug at start address 0? */ | |
935 | && last_o_file_start | |
c5aa993b JM |
936 | && objfile->ei.entry_point < bufp->n_value |
937 | && objfile->ei.entry_point >= last_o_file_start) | |
c906108c | 938 | { |
c5aa993b JM |
939 | objfile->ei.entry_file_lowpc = last_o_file_start; |
940 | objfile->ei.entry_file_highpc = bufp->n_value; | |
c906108c SS |
941 | } |
942 | ||
943 | if (pst) | |
944 | { | |
945 | os9k_end_psymtab (pst, psymtab_include_list, includes_used, | |
c5aa993b JM |
946 | symnum, end_of_text_addr, |
947 | dependency_list, dependencies_used); | |
c906108c SS |
948 | } |
949 | /* | |
c5aa993b JM |
950 | do_cleanups (back_to); |
951 | */ | |
c906108c SS |
952 | } |
953 | ||
954 | /* Allocate and partially fill a partial symtab. It will be | |
955 | completely filled at the end of the symbol list. | |
956 | ||
957 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
958 | is the address relative to which its symbols are (incremental) or 0 | |
959 | (normal). */ | |
960 | ||
961 | ||
962 | static struct partial_symtab * | |
fba45db2 KB |
963 | os9k_start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow, |
964 | int ldsymoff, int ldsymcnt, | |
965 | struct partial_symbol **global_syms, | |
966 | struct partial_symbol **static_syms) | |
c906108c SS |
967 | { |
968 | struct partial_symtab *result = | |
d4f3574e | 969 | start_psymtab_common (objfile, objfile->section_offsets, |
c5aa993b | 970 | filename, textlow, global_syms, static_syms); |
c906108c SS |
971 | |
972 | result->read_symtab_private = (char *) | |
c5aa993b | 973 | obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc)); |
c906108c | 974 | |
c5aa993b JM |
975 | LDSYMOFF (result) = ldsymoff; |
976 | LDSYMCNT (result) = ldsymcnt; | |
c906108c SS |
977 | result->read_symtab = os9k_psymtab_to_symtab; |
978 | ||
979 | /* Deduce the source language from the filename for this psymtab. */ | |
980 | psymtab_language = deduce_language_from_filename (filename); | |
981 | return result; | |
982 | } | |
983 | ||
984 | /* Close off the current usage of PST. | |
985 | Returns PST or NULL if the partial symtab was empty and thrown away. | |
986 | FIXME: List variables and peculiarities of same. */ | |
987 | ||
988 | static struct partial_symtab * | |
fa6b9313 KB |
989 | os9k_end_psymtab (struct partial_symtab *pst, char **include_list, |
990 | int num_includes, int capping_symbol_cnt, | |
991 | CORE_ADDR capping_text, | |
992 | struct partial_symtab **dependency_list, | |
993 | int number_dependencies) | |
c906108c SS |
994 | { |
995 | int i; | |
996 | struct partial_symtab *p1; | |
c5aa993b | 997 | struct objfile *objfile = pst->objfile; |
c906108c SS |
998 | |
999 | if (capping_symbol_cnt != -1) | |
c5aa993b | 1000 | LDSYMCNT (pst) = capping_symbol_cnt - LDSYMCNT (pst); |
c906108c SS |
1001 | |
1002 | /* Under Solaris, the N_SO symbols always have a value of 0, | |
1003 | instead of the usual address of the .o file. Therefore, | |
1004 | we have to do some tricks to fill in texthigh and textlow. | |
1005 | The first trick is in partial-stab.h: if we see a static | |
1006 | or global function, and the textlow for the current pst | |
1007 | is still 0, then we use that function's address for | |
1008 | the textlow of the pst. | |
1009 | ||
1010 | Now, to fill in texthigh, we remember the last function seen | |
1011 | in the .o file (also in partial-stab.h). Also, there's a hack in | |
1012 | bfd/elf.c and gdb/elfread.c to pass the ELF st_size field | |
1013 | to here via the misc_info field. Therefore, we can fill in | |
1014 | a reliable texthigh by taking the address plus size of the | |
1015 | last function in the file. | |
1016 | ||
1017 | Unfortunately, that does not cover the case where the last function | |
1018 | in the file is static. See the paragraph below for more comments | |
1019 | on this situation. | |
1020 | ||
1021 | Finally, if we have a valid textlow for the current file, we run | |
1022 | down the partial_symtab_list filling in previous texthighs that | |
1023 | are still unknown. */ | |
1024 | ||
c5aa993b JM |
1025 | if (pst->texthigh == 0 && last_function_name) |
1026 | { | |
1027 | char *p; | |
1028 | int n; | |
1029 | struct minimal_symbol *minsym; | |
1030 | ||
1031 | p = strchr (last_function_name, ':'); | |
1032 | if (p == NULL) | |
1033 | p = last_function_name; | |
1034 | n = p - last_function_name; | |
1035 | p = alloca (n + 1); | |
1036 | strncpy (p, last_function_name, n); | |
1037 | p[n] = 0; | |
1038 | ||
1039 | minsym = lookup_minimal_symbol (p, NULL, objfile); | |
1040 | ||
1041 | if (minsym) | |
1042 | { | |
1043 | pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + (long) MSYMBOL_INFO (minsym); | |
1044 | } | |
1045 | else | |
1046 | { | |
1047 | /* This file ends with a static function, and it's | |
1048 | difficult to imagine how hard it would be to track down | |
1049 | the elf symbol. Luckily, most of the time no one will notice, | |
1050 | since the next file will likely be compiled with -g, so | |
1051 | the code below will copy the first fuction's start address | |
1052 | back to our texthigh variable. (Also, if this file is the | |
1053 | last one in a dynamically linked program, texthigh already | |
1054 | has the right value.) If the next file isn't compiled | |
1055 | with -g, then the last function in this file winds up owning | |
1056 | all of the text space up to the next -g file, or the end (minus | |
1057 | shared libraries). This only matters for single stepping, | |
1058 | and even then it will still work, except that it will single | |
1059 | step through all of the covered functions, instead of setting | |
1060 | breakpoints around them as it usualy does. This makes it | |
1061 | pretty slow, but at least it doesn't fail. | |
1062 | ||
1063 | We can fix this with a fairly big change to bfd, but we need | |
1064 | to coordinate better with Cygnus if we want to do that. FIXME. */ | |
1065 | } | |
1066 | last_function_name = NULL; | |
c906108c | 1067 | } |
c906108c SS |
1068 | |
1069 | /* this test will be true if the last .o file is only data */ | |
1070 | if (pst->textlow == 0) | |
1071 | pst->textlow = pst->texthigh; | |
1072 | ||
1073 | /* If we know our own starting text address, then walk through all other | |
1074 | psymtabs for this objfile, and if any didn't know their ending text | |
1075 | address, set it to our starting address. Take care to not set our | |
1076 | own ending address to our starting address, nor to set addresses on | |
1077 | `dependency' files that have both textlow and texthigh zero. */ | |
c5aa993b JM |
1078 | if (pst->textlow) |
1079 | { | |
1080 | ALL_OBJFILE_PSYMTABS (objfile, p1) | |
1081 | { | |
1082 | if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) | |
1083 | { | |
1084 | p1->texthigh = pst->textlow; | |
1085 | /* if this file has only data, then make textlow match texthigh */ | |
1086 | if (p1->textlow == 0) | |
1087 | p1->textlow = p1->texthigh; | |
1088 | } | |
c906108c SS |
1089 | } |
1090 | } | |
c906108c SS |
1091 | |
1092 | /* End of kludge for patching Solaris textlow and texthigh. */ | |
1093 | ||
1094 | pst->n_global_syms = | |
1095 | objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset); | |
1096 | pst->n_static_syms = | |
1097 | objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset); | |
1098 | ||
1099 | pst->number_of_dependencies = number_dependencies; | |
1100 | if (number_dependencies) | |
1101 | { | |
1102 | pst->dependencies = (struct partial_symtab **) | |
1103 | obstack_alloc (&objfile->psymbol_obstack, | |
c5aa993b | 1104 | number_dependencies * sizeof (struct partial_symtab *)); |
c906108c | 1105 | memcpy (pst->dependencies, dependency_list, |
c5aa993b | 1106 | number_dependencies * sizeof (struct partial_symtab *)); |
c906108c SS |
1107 | } |
1108 | else | |
1109 | pst->dependencies = 0; | |
1110 | ||
1111 | for (i = 0; i < num_includes; i++) | |
1112 | { | |
1113 | struct partial_symtab *subpst = | |
c5aa993b | 1114 | allocate_psymtab (include_list[i], objfile); |
c906108c SS |
1115 | |
1116 | subpst->section_offsets = pst->section_offsets; | |
1117 | subpst->read_symtab_private = | |
c5aa993b JM |
1118 | (char *) obstack_alloc (&objfile->psymbol_obstack, |
1119 | sizeof (struct symloc)); | |
1120 | LDSYMOFF (subpst) = | |
1121 | LDSYMCNT (subpst) = | |
1122 | subpst->textlow = | |
1123 | subpst->texthigh = 0; | |
c906108c SS |
1124 | |
1125 | /* We could save slight bits of space by only making one of these, | |
c5aa993b | 1126 | shared by the entire set of include files. FIXME-someday. */ |
c906108c SS |
1127 | subpst->dependencies = (struct partial_symtab **) |
1128 | obstack_alloc (&objfile->psymbol_obstack, | |
1129 | sizeof (struct partial_symtab *)); | |
1130 | subpst->dependencies[0] = pst; | |
1131 | subpst->number_of_dependencies = 1; | |
1132 | ||
1133 | subpst->globals_offset = | |
1134 | subpst->n_global_syms = | |
c5aa993b JM |
1135 | subpst->statics_offset = |
1136 | subpst->n_static_syms = 0; | |
c906108c SS |
1137 | |
1138 | subpst->readin = 0; | |
1139 | subpst->symtab = 0; | |
1140 | subpst->read_symtab = pst->read_symtab; | |
1141 | } | |
1142 | ||
1143 | sort_pst_symbols (pst); | |
1144 | ||
1145 | /* If there is already a psymtab or symtab for a file of this name, | |
1146 | remove it. | |
1147 | (If there is a symtab, more drastic things also happen.) | |
1148 | This happens in VxWorks. */ | |
1149 | free_named_symtabs (pst->filename); | |
1150 | ||
1151 | if (num_includes == 0 | |
c5aa993b JM |
1152 | && number_dependencies == 0 |
1153 | && pst->n_global_syms == 0 | |
1154 | && pst->n_static_syms == 0) | |
1155 | { | |
1156 | /* Throw away this psymtab, it's empty. We can't deallocate it, since | |
1157 | it is on the obstack, but we can forget to chain it on the list. */ | |
1158 | /* Indicate that psymtab was thrown away. */ | |
c906108c | 1159 | |
c5aa993b | 1160 | discard_psymtab (pst); |
c906108c | 1161 | |
c5aa993b JM |
1162 | pst = (struct partial_symtab *) NULL; |
1163 | } | |
c906108c SS |
1164 | return pst; |
1165 | } | |
1166 | \f | |
1167 | static void | |
fba45db2 | 1168 | os9k_psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c SS |
1169 | { |
1170 | struct cleanup *old_chain; | |
1171 | int i; | |
c5aa993b | 1172 | |
c906108c SS |
1173 | if (!pst) |
1174 | return; | |
1175 | ||
1176 | if (pst->readin) | |
1177 | { | |
1178 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
c5aa993b | 1179 | pst->filename); |
c906108c SS |
1180 | return; |
1181 | } | |
1182 | ||
1183 | /* Read in all partial symtabs on which this one is dependent */ | |
1184 | for (i = 0; i < pst->number_of_dependencies; i++) | |
1185 | if (!pst->dependencies[i]->readin) | |
1186 | { | |
1187 | /* Inform about additional files that need to be read in. */ | |
1188 | if (info_verbose) | |
1189 | { | |
1190 | fputs_filtered (" ", gdb_stdout); | |
1191 | wrap_here (""); | |
1192 | fputs_filtered ("and ", gdb_stdout); | |
1193 | wrap_here (""); | |
1194 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
c5aa993b | 1195 | wrap_here (""); /* Flush output */ |
c906108c SS |
1196 | gdb_flush (gdb_stdout); |
1197 | } | |
1198 | os9k_psymtab_to_symtab_1 (pst->dependencies[i]); | |
1199 | } | |
1200 | ||
c5aa993b | 1201 | if (LDSYMCNT (pst)) /* Otherwise it's a dummy */ |
c906108c SS |
1202 | { |
1203 | /* Init stuff necessary for reading in symbols */ | |
1204 | stabsread_init (); | |
1205 | buildsym_init (); | |
a0b3c4fd | 1206 | old_chain = make_cleanup (really_free_pendings, 0); |
c906108c SS |
1207 | |
1208 | /* Read in this file's symbols */ | |
1209 | os9k_read_ofile_symtab (pst); | |
1210 | sort_symtab_syms (pst->symtab); | |
1211 | do_cleanups (old_chain); | |
1212 | } | |
1213 | ||
1214 | pst->readin = 1; | |
1215 | } | |
1216 | ||
1217 | /* Read in all of the symbols for a given psymtab for real. | |
1218 | Be verbose about it if the user wants that. */ | |
1219 | ||
1220 | static void | |
fba45db2 | 1221 | os9k_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
1222 | { |
1223 | bfd *sym_bfd; | |
1224 | ||
1225 | if (!pst) | |
1226 | return; | |
1227 | ||
1228 | if (pst->readin) | |
1229 | { | |
1230 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
c5aa993b | 1231 | pst->filename); |
c906108c SS |
1232 | return; |
1233 | } | |
1234 | ||
c5aa993b | 1235 | if (LDSYMCNT (pst) || pst->number_of_dependencies) |
c906108c SS |
1236 | { |
1237 | /* Print the message now, before reading the string table, | |
c5aa993b | 1238 | to avoid disconcerting pauses. */ |
c906108c SS |
1239 | if (info_verbose) |
1240 | { | |
1241 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
1242 | gdb_flush (gdb_stdout); | |
1243 | } | |
1244 | ||
1245 | sym_bfd = pst->objfile->obfd; | |
1246 | os9k_psymtab_to_symtab_1 (pst); | |
1247 | ||
1248 | /* Match with global symbols. This only needs to be done once, | |
1249 | after all of the symtabs and dependencies have been read in. */ | |
1250 | scan_file_globals (pst->objfile); | |
1251 | ||
1252 | /* Finish up the debug error message. */ | |
1253 | if (info_verbose) | |
1254 | printf_filtered ("done.\n"); | |
1255 | } | |
1256 | } | |
1257 | ||
1258 | /* Read in a defined section of a specific object file's symbols. */ | |
1259 | static void | |
fba45db2 | 1260 | os9k_read_ofile_symtab (struct partial_symtab *pst) |
c906108c SS |
1261 | { |
1262 | register struct internal_symstruct *bufp; | |
1263 | unsigned char type; | |
1264 | unsigned max_symnum; | |
1265 | register bfd *abfd; | |
1266 | struct objfile *objfile; | |
1267 | int sym_offset; /* Offset to start of symbols to read */ | |
1268 | CORE_ADDR text_offset; /* Start of text segment for symbols */ | |
1269 | int text_size; /* Size of text segment for symbols */ | |
c906108c SS |
1270 | FILE *dbg_file; |
1271 | ||
1272 | objfile = pst->objfile; | |
c5aa993b JM |
1273 | sym_offset = LDSYMOFF (pst); |
1274 | max_symnum = LDSYMCNT (pst); | |
c906108c SS |
1275 | text_offset = pst->textlow; |
1276 | text_size = pst->texthigh - pst->textlow; | |
c906108c SS |
1277 | |
1278 | current_objfile = objfile; | |
1279 | subfile_stack = NULL; | |
1280 | last_source_file = NULL; | |
1281 | ||
1282 | abfd = objfile->obfd; | |
1283 | dbg_file = objfile->auxf2; | |
1284 | ||
1285 | #if 0 | |
1286 | /* It is necessary to actually read one symbol *before* the start | |
1287 | of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL | |
1288 | occurs before the N_SO symbol. | |
1289 | Detecting this in read_dbx_symtab | |
1290 | would slow down initial readin, so we look for it here instead. */ | |
c5aa993b | 1291 | if (!processing_acc_compilation && sym_offset >= (int) symbol_size) |
c906108c SS |
1292 | { |
1293 | fseek (objefile->auxf2, sym_offset, SEEK_CUR); | |
c5aa993b | 1294 | fill_sym (objfile->auxf2, abfd); |
c906108c SS |
1295 | bufp = symbuf; |
1296 | ||
1297 | processing_gcc_compilation = 0; | |
1298 | if (bufp->n_type == N_TEXT) | |
1299 | { | |
1300 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
1301 | processing_gcc_compilation = 1; | |
1302 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) | |
1303 | processing_gcc_compilation = 2; | |
1304 | } | |
1305 | ||
1306 | /* Try to select a C++ demangling based on the compilation unit | |
c5aa993b | 1307 | producer. */ |
c906108c SS |
1308 | |
1309 | if (processing_gcc_compilation) | |
1310 | { | |
1311 | if (AUTO_DEMANGLING) | |
1312 | { | |
1313 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
1314 | } | |
1315 | } | |
1316 | } | |
1317 | else | |
1318 | { | |
1319 | /* The N_SO starting this symtab is the first symbol, so we | |
c5aa993b JM |
1320 | better not check the symbol before it. I'm not this can |
1321 | happen, but it doesn't hurt to check for it. */ | |
c906108c SS |
1322 | bfd_seek (symfile_bfd, sym_offset, SEEK_CUR); |
1323 | processing_gcc_compilation = 0; | |
1324 | } | |
1325 | #endif /* 0 */ | |
1326 | ||
c5aa993b | 1327 | fseek (dbg_file, (long) sym_offset, 0); |
c906108c | 1328 | /* |
c5aa993b JM |
1329 | if (bufp->n_type != (unsigned char)N_SYM_SYM) |
1330 | error("First symbol in segment of executable not a source symbol"); | |
1331 | */ | |
c906108c SS |
1332 | |
1333 | for (symnum = 0; symnum < max_symnum; symnum++) | |
1334 | { | |
1335 | QUIT; /* Allow this to be interruptable */ | |
c5aa993b | 1336 | fill_sym (dbg_file, abfd); |
c906108c SS |
1337 | bufp = symbuf; |
1338 | type = bufp->n_type; | |
1339 | ||
c5aa993b | 1340 | os9k_process_one_symbol ((int) type, (int) bufp->n_desc, |
d4f3574e | 1341 | (CORE_ADDR) bufp->n_value, bufp->n_strx, pst->section_offsets, objfile); |
c906108c SS |
1342 | |
1343 | /* We skip checking for a new .o or -l file; that should never | |
1344 | happen in this routine. */ | |
1345 | #if 0 | |
c5aa993b JM |
1346 | else |
1347 | if (type == N_TEXT) | |
c906108c SS |
1348 | { |
1349 | /* I don't think this code will ever be executed, because | |
1350 | the GCC_COMPILED_FLAG_SYMBOL usually is right before | |
1351 | the N_SO symbol which starts this source file. | |
1352 | However, there is no reason not to accept | |
1353 | the GCC_COMPILED_FLAG_SYMBOL anywhere. */ | |
1354 | ||
1355 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
1356 | processing_gcc_compilation = 1; | |
1357 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) | |
1358 | processing_gcc_compilation = 2; | |
1359 | ||
1360 | if (AUTO_DEMANGLING) | |
1361 | { | |
1362 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
1363 | } | |
1364 | } | |
c5aa993b JM |
1365 | else if (type & N_EXT || type == (unsigned char) N_TEXT |
1366 | || type == (unsigned char) N_NBTEXT | |
1367 | ) | |
1368 | { | |
c906108c SS |
1369 | /* Global symbol: see if we came across a dbx defintion for |
1370 | a corresponding symbol. If so, store the value. Remove | |
1371 | syms from the chain when their values are stored, but | |
1372 | search the whole chain, as there may be several syms from | |
1373 | different files with the same name. */ | |
1374 | /* This is probably not true. Since the files will be read | |
1375 | in one at a time, each reference to a global symbol will | |
1376 | be satisfied in each file as it appears. So we skip this | |
1377 | section. */ | |
1378 | ; | |
c5aa993b | 1379 | } |
c906108c SS |
1380 | #endif /* 0 */ |
1381 | } | |
1382 | ||
1383 | current_objfile = NULL; | |
1384 | ||
1385 | /* In a Solaris elf file, this variable, which comes from the | |
1386 | value of the N_SO symbol, will still be 0. Luckily, text_offset, | |
1387 | which comes from pst->textlow is correct. */ | |
1388 | if (last_source_start_addr == 0) | |
1389 | last_source_start_addr = text_offset; | |
b8fbeb18 | 1390 | pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1391 | end_stabs (); |
1392 | } | |
c906108c | 1393 | \f |
c5aa993b | 1394 | |
c906108c SS |
1395 | /* This handles a single symbol from the symbol-file, building symbols |
1396 | into a GDB symtab. It takes these arguments and an implicit argument. | |
1397 | ||
1398 | TYPE is the type field of the ".stab" symbol entry. | |
1399 | DESC is the desc field of the ".stab" entry. | |
1400 | VALU is the value field of the ".stab" entry. | |
1401 | NAME is the symbol name, in our address space. | |
1402 | SECTION_OFFSETS is a set of amounts by which the sections of this object | |
c5aa993b JM |
1403 | file were relocated when it was loaded into memory. |
1404 | All symbols that refer | |
1405 | to memory locations need to be offset by these amounts. | |
c906108c | 1406 | OBJFILE is the object file from which we are reading symbols. |
c5aa993b | 1407 | It is used in end_symtab. */ |
c906108c SS |
1408 | |
1409 | static void | |
fba45db2 KB |
1410 | os9k_process_one_symbol (int type, int desc, CORE_ADDR valu, char *name, |
1411 | struct section_offsets *section_offsets, | |
1412 | struct objfile *objfile) | |
c906108c SS |
1413 | { |
1414 | register struct context_stack *new; | |
1415 | /* The stab type used for the definition of the last function. | |
1416 | N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */ | |
1417 | static int function_stab_type = 0; | |
1418 | ||
1419 | #if 0 | |
1420 | /* Something is wrong if we see real data before | |
1421 | seeing a source file name. */ | |
c5aa993b | 1422 | if (last_source_file == NULL && type != (unsigned char) N_SO) |
c906108c SS |
1423 | { |
1424 | /* Ignore any symbols which appear before an N_SO symbol. | |
c5aa993b JM |
1425 | Currently no one puts symbols there, but we should deal |
1426 | gracefully with the case. A complain()t might be in order, | |
1427 | but this should not be an error (). */ | |
c906108c SS |
1428 | return; |
1429 | } | |
1430 | #endif /* 0 */ | |
1431 | ||
1432 | switch (type) | |
1433 | { | |
1434 | case N_SYM_LBRAC: | |
1435 | /* On most machines, the block addresses are relative to the | |
c5aa993b | 1436 | N_SO, the linker did not relocate them (sigh). */ |
b8fbeb18 | 1437 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1438 | new = push_context (desc, valu); |
1439 | break; | |
1440 | ||
1441 | case N_SYM_RBRAC: | |
b8fbeb18 | 1442 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b | 1443 | new = pop_context (); |
c906108c SS |
1444 | |
1445 | #if !defined (OS9K_VARIABLES_INSIDE_BLOCK) | |
1446 | #define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1 | |
1447 | #endif | |
1448 | ||
c5aa993b | 1449 | if (!OS9K_VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation)) |
c906108c SS |
1450 | local_symbols = new->locals; |
1451 | ||
1452 | if (context_stack_depth > 1) | |
1453 | { | |
1454 | /* This is not the outermost LBRAC...RBRAC pair in the function, | |
1455 | its local symbols preceded it, and are the ones just recovered | |
1456 | from the context stack. Define the block for them (but don't | |
1457 | bother if the block contains no symbols. Should we complain | |
1458 | on blocks without symbols? I can't think of any useful purpose | |
1459 | for them). */ | |
1460 | if (local_symbols != NULL) | |
1461 | { | |
1462 | /* Muzzle a compiler bug that makes end < start. (which | |
c5aa993b | 1463 | compilers? Is this ever harmful?). */ |
c906108c SS |
1464 | if (new->start_addr > valu) |
1465 | { | |
1466 | complain (&lbrac_rbrac_complaint); | |
1467 | new->start_addr = valu; | |
1468 | } | |
1469 | /* Make a block for the local symbols within. */ | |
1470 | finish_block (0, &local_symbols, new->old_blocks, | |
1471 | new->start_addr, valu, objfile); | |
1472 | } | |
1473 | } | |
1474 | else | |
1475 | { | |
1476 | if (context_stack_depth == 0) | |
1477 | { | |
1478 | within_function = 0; | |
1479 | /* Make a block for the local symbols within. */ | |
1480 | finish_block (new->name, &local_symbols, new->old_blocks, | |
c5aa993b | 1481 | new->start_addr, valu, objfile); |
c906108c SS |
1482 | } |
1483 | else | |
1484 | { | |
1485 | /* attach local_symbols to the end of new->locals */ | |
c5aa993b JM |
1486 | if (!new->locals) |
1487 | new->locals = local_symbols; | |
1488 | else | |
1489 | { | |
1490 | struct pending *p; | |
c906108c | 1491 | |
c5aa993b JM |
1492 | p = new->locals; |
1493 | while (p->next) | |
1494 | p = p->next; | |
1495 | p->next = local_symbols; | |
1496 | } | |
c906108c SS |
1497 | } |
1498 | } | |
1499 | ||
c5aa993b | 1500 | if (OS9K_VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation)) |
c906108c SS |
1501 | /* Now pop locals of block just finished. */ |
1502 | local_symbols = new->locals; | |
1503 | break; | |
1504 | ||
1505 | ||
1506 | case N_SYM_SLINE: | |
1507 | /* This type of "symbol" really just records | |
c5aa993b JM |
1508 | one line-number -- core-address correspondence. |
1509 | Enter it in the line list for this symbol table. */ | |
c906108c | 1510 | /* Relocate for dynamic loading and for ELF acc fn-relative syms. */ |
b8fbeb18 | 1511 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 1512 | /* FIXME: loses if sizeof (char *) > sizeof (int) */ |
088d891f | 1513 | gdb_assert (sizeof (name) <= sizeof (int)); |
c5aa993b | 1514 | record_line (current_subfile, (int) name, valu); |
c906108c SS |
1515 | break; |
1516 | ||
c5aa993b JM |
1517 | /* The following symbol types need to have the appropriate offset added |
1518 | to their value; then we process symbol definitions in the name. */ | |
c906108c SS |
1519 | case N_SYM_SYM: |
1520 | ||
1521 | if (name) | |
1522 | { | |
1523 | char deftype; | |
1524 | char *dirn, *n; | |
1525 | char *p = strchr (name, ':'); | |
1526 | if (p == NULL) | |
1527 | deftype = '\0'; | |
1528 | else | |
1529 | deftype = p[1]; | |
1530 | ||
1531 | ||
1532 | switch (deftype) | |
1533 | { | |
1534 | case 'S': | |
b8fbeb18 | 1535 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
1536 | n = strrchr (name, '/'); |
1537 | if (n != NULL) | |
1538 | { | |
1539 | *n = '\0'; | |
1540 | n++; | |
1541 | dirn = name; | |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | n = name; | |
1546 | dirn = NULL; | |
1547 | } | |
c906108c | 1548 | *p = '\0'; |
c5aa993b JM |
1549 | if (symfile_depth++ == 0) |
1550 | { | |
1551 | if (last_source_file) | |
1552 | { | |
b8fbeb18 | 1553 | end_symtab (valu, objfile, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
1554 | end_stabs (); |
1555 | } | |
1556 | start_stabs (); | |
1557 | os9k_stabs = 1; | |
1558 | start_symtab (n, dirn, valu); | |
1559 | record_debugformat ("OS9"); | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | push_subfile (); | |
1564 | start_subfile (n, dirn != NULL ? dirn : current_subfile->dirname); | |
c906108c | 1565 | } |
c906108c SS |
1566 | break; |
1567 | ||
1568 | case 'f': | |
1569 | case 'F': | |
b8fbeb18 | 1570 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1571 | function_stab_type = type; |
1572 | ||
1573 | within_function = 1; | |
1574 | new = push_context (0, valu); | |
1575 | new->name = define_symbol (valu, name, desc, type, objfile); | |
1576 | break; | |
1577 | ||
1578 | case 'V': | |
1579 | case 'v': | |
b8fbeb18 | 1580 | valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
1581 | define_symbol (valu, name, desc, type, objfile); |
1582 | break; | |
1583 | ||
1584 | default: | |
1585 | define_symbol (valu, name, desc, type, objfile); | |
1586 | break; | |
1587 | } | |
1588 | } | |
1589 | break; | |
1590 | ||
1591 | case N_SYM_SE: | |
c5aa993b JM |
1592 | if (--symfile_depth != 0) |
1593 | start_subfile (pop_subfile (), current_subfile->dirname); | |
c906108c SS |
1594 | break; |
1595 | ||
1596 | default: | |
1597 | complain (&unknown_symtype_complaint, | |
c5aa993b | 1598 | local_hex_string ((unsigned long) type)); |
c906108c SS |
1599 | /* FALLTHROUGH */ |
1600 | break; | |
1601 | ||
1602 | case N_SYM_CMPLR: | |
1603 | break; | |
1604 | } | |
1605 | previous_stab_code = type; | |
1606 | } | |
1607 | ||
1608 | static struct sym_fns os9k_sym_fns = | |
1609 | { | |
1610 | bfd_target_os9k_flavour, | |
c5aa993b JM |
1611 | os9k_new_init, /* sym_new_init: init anything gbl to entire symtab */ |
1612 | os9k_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
1613 | os9k_symfile_read, /* sym_read: read a symbol file into symtab */ | |
1614 | os9k_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
96baa820 | 1615 | default_symfile_offsets, /* sym_offsets: parse user's offsets to internal form */ |
c5aa993b | 1616 | NULL /* next: pointer to next struct sym_fns */ |
c906108c SS |
1617 | }; |
1618 | ||
1619 | void | |
fba45db2 | 1620 | _initialize_os9kread (void) |
c906108c | 1621 | { |
c5aa993b | 1622 | add_symtab_fns (&os9k_sym_fns); |
c906108c | 1623 | } |