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