1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This module provides three functions: dbx_symfile_init,
21 which initializes to read a symbol file; dbx_new_init, which
22 discards existing cached information when all symbols are being
23 discarded; and dbx_symfile_read, which reads a symbol table
26 dbx_symfile_read only does the minimum work necessary for letting the
27 user "name" things symbolically; it does not read the entire symtab.
28 Instead, it reads the external and static symbols and puts them in partial
29 symbol tables. When more extensive information is requested of a
30 file, the corresponding partial symbol table is mutated into a full
31 fledged symbol table by going back and reading the symbols
32 for real. dbx_psymtab_to_symtab() is the function that does this */
38 #include <sys/types.h>
45 #include <sys/param.h>
52 #include "breakpoint.h"
55 #include "gdbcore.h" /* for bfd stuff */
56 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
60 #include "aout/aout64.h"
61 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
63 /* Information is passed among various dbxread routines for accessing
64 symbol files. A pointer to this structure is kept in the sym_private
65 field of the objfile struct passed in by symfile.h. */
67 struct dbx_symfile_info {
68 asection *text_sect; /* Text section accessor */
69 int symcount; /* How many symbols are there in the file */
70 char *stringtab; /* The actual string table */
71 int stringtab_size; /* Its size */
72 off_t symtab_offset; /* Offset in file to symbol table */
76 /* Each partial symbol table entry contains a pointer to private data for the
77 read_symtab() function to use when expanding a partial symbol table entry
78 to a full symbol table entry.
80 For dbxread this structure contains the offset within the file symbol table
81 of first local symbol for this file, and length (in bytes) of the section
82 of the symbol table devoted to this file's symbols (actually, the section
83 bracketed may contain more than just this file's symbols). If ldsymlen is
84 0, the only reason for this thing's existence is the dependency list.
85 Nothing else will happen when it is read in. */
87 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
88 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
95 /* Macro to determine which symbols to ignore when reading the first symbol
96 of a file. Some machines override this definition. */
98 /* This code is used on Ultrix systems. Ignore it */
99 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
102 /* Macro for name of symbol to indicate a file compiled with gcc. */
103 #ifndef GCC_COMPILED_FLAG_SYMBOL
104 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
107 /* Macro for name of symbol to indicate a file compiled with gcc2. */
108 #ifndef GCC2_COMPILED_FLAG_SYMBOL
109 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
112 /* Define this as 1 if a pcc declaration of a char or short argument
113 gives the correct address. Otherwise assume pcc gives the
114 address of the corresponding int, which is not the same on a
115 big-endian machine. */
117 #ifndef BELIEVE_PCC_PROMOTION
118 #define BELIEVE_PCC_PROMOTION 0
121 /* Nonzero means give verbose info on gdb action. From main.c. */
122 extern int info_verbose;
124 /* The BFD for this file -- implicit parameter to next_symbol_text. */
126 static bfd *symfile_bfd;
128 /* The objfile for this file -- only good in process_one_symbol(). */
130 static struct objfile *our_objfile;
132 /* String table for the main symbol file. It is kept in memory
133 permanently, to speed up symbol reading. Other files' symbol tables
134 are read in on demand. FIXME, this should be cleaner. */
136 static char *symfile_string_table;
137 static int symfile_string_table_size;
139 /* The size of each symbol in the symbol file (in external form).
140 This is set by dbx_symfile_read when building psymtabs, and by
141 dbx_psymtab_to_symtab when building symtabs. */
143 static unsigned symbol_size;
145 /* Complaints about the symbols we have encountered. */
147 struct complaint lbrac_complaint =
148 {"bad block start address patched", 0, 0};
150 struct complaint string_table_offset_complaint =
151 {"bad string table offset in symbol %d", 0, 0};
153 struct complaint unknown_symtype_complaint =
154 {"unknown symbol type %s", 0, 0};
156 struct complaint lbrac_rbrac_complaint =
157 {"block start larger than block end", 0, 0};
159 struct complaint lbrac_unmatched_complaint =
160 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
162 struct complaint lbrac_mismatch_complaint =
163 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
165 /* During initial symbol readin, we need to have a structure to keep
166 track of which psymtabs have which bincls in them. This structure
167 is used during readin to setup the list of dependencies within each
168 partial symbol table. */
170 struct header_file_location
172 char *name; /* Name of header file */
173 int instance; /* See above */
174 struct partial_symtab *pst; /* Partial symtab that has the
175 BINCL/EINCL defs for this file */
178 /* The actual list and controling variables */
179 static struct header_file_location *bincl_list, *next_bincl;
180 static int bincls_allocated;
182 /* Local function prototypes */
185 free_header_files PARAMS ((void));
188 init_header_files PARAMS ((void));
190 static struct pending *
191 copy_pending PARAMS ((struct pending *, int, struct pending *));
193 static struct symtab *
194 read_ofile_symtab PARAMS ((struct objfile *, char *, unsigned int, int, int,
195 CORE_ADDR, int, int));
198 dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
201 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *, int, int));
204 read_dbx_symtab PARAMS ((CORE_ADDR, struct objfile *, char *, long, int,
208 free_bincl_list PARAMS ((struct objfile *));
210 static struct partial_symtab *
211 find_corresponding_bincl_psymtab PARAMS ((char *, int));
214 add_bincl_to_list PARAMS ((struct partial_symtab *, char *, int));
217 init_bincl_list PARAMS ((int, struct objfile *));
220 init_psymbol_list PARAMS ((int, struct objfile *));
223 dbx_next_symbol_text PARAMS ((void));
226 fill_symbuf PARAMS ((bfd *));
229 dbx_symfile_init PARAMS ((struct objfile *));
232 dbx_new_init PARAMS ((struct objfile *));
235 dbx_symfile_read PARAMS ((struct objfile *, CORE_ADDR, int));
238 dbx_symfile_finish PARAMS ((struct objfile *));
241 record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *));
244 add_new_header_file PARAMS ((char *, int));
247 add_old_header_file PARAMS ((char *, int));
250 add_this_object_header_file PARAMS ((int));
252 /* Free up old header file tables */
259 if (header_files != NULL)
261 for (i = 0; i < n_header_files; i++)
263 free (header_files[i].name);
269 if (this_object_header_files)
271 free (this_object_header_files);
272 this_object_header_files = NULL;
274 n_allocated_header_files = 0;
275 n_allocated_this_object_header_files = 0;
278 /* Allocate new header file tables */
284 n_allocated_header_files = 10;
285 header_files = (struct header_file *)
286 xmalloc (10 * sizeof (struct header_file));
288 n_allocated_this_object_header_files = 10;
289 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
292 /* Add header file number I for this object file
293 at the next successive FILENUM. */
296 add_this_object_header_file (i)
299 if (n_this_object_header_files == n_allocated_this_object_header_files)
301 n_allocated_this_object_header_files *= 2;
302 this_object_header_files
303 = (int *) xrealloc ((char *) this_object_header_files,
304 n_allocated_this_object_header_files * sizeof (int));
307 this_object_header_files[n_this_object_header_files++] = i;
310 /* Add to this file an "old" header file, one already seen in
311 a previous object file. NAME is the header file's name.
312 INSTANCE is its instance code, to select among multiple
313 symbol tables for the same header file. */
316 add_old_header_file (name, instance)
320 register struct header_file *p = header_files;
323 for (i = 0; i < n_header_files; i++)
324 if (!strcmp (p[i].name, name) && instance == p[i].instance)
326 add_this_object_header_file (i);
329 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
333 /* Add to this file a "new" header file: definitions for its types follow.
334 NAME is the header file's name.
335 Most often this happens only once for each distinct header file,
336 but not necessarily. If it happens more than once, INSTANCE has
337 a different value each time, and references to the header file
338 use INSTANCE values to select among them.
340 dbx output contains "begin" and "end" markers for each new header file,
341 but at this level we just need to know which files there have been;
342 so we record the file when its "begin" is seen and ignore the "end". */
345 add_new_header_file (name, instance)
350 header_file_prev_index = -1;
352 /* Make sure there is room for one more header file. */
354 if (n_header_files == n_allocated_header_files)
356 n_allocated_header_files *= 2;
357 header_files = (struct header_file *)
358 xrealloc ((char *) header_files,
359 (n_allocated_header_files * sizeof (struct header_file)));
362 /* Create an entry for this header file. */
364 i = n_header_files++;
365 header_files[i].name = savestring (name, strlen(name));
366 header_files[i].instance = instance;
367 header_files[i].length = 10;
368 header_files[i].vector
369 = (struct type **) xmalloc (10 * sizeof (struct type *));
370 bzero (header_files[i].vector, 10 * sizeof (struct type *));
372 add_this_object_header_file (i);
376 static struct type **
377 explicit_lookup_type (real_filenum, index)
378 int real_filenum, index;
380 register struct header_file *f = &header_files[real_filenum];
382 if (index >= f->length)
385 f->vector = (struct type **)
386 xrealloc (f->vector, f->length * sizeof (struct type *));
387 bzero (&f->vector[f->length / 2],
388 f->length * sizeof (struct type *) / 2);
390 return &f->vector[index];
395 record_minimal_symbol (name, address, type, objfile)
399 struct objfile *objfile;
401 enum minimal_symbol_type ms_type;
403 switch (type &~ N_EXT) {
404 case N_TEXT: ms_type = mst_text; break;
405 case N_DATA: ms_type = mst_data; break;
406 case N_BSS: ms_type = mst_bss; break;
407 case N_ABS: ms_type = mst_abs; break;
409 case N_SETV: ms_type = mst_data; break;
411 default: ms_type = mst_unknown; break;
414 prim_record_minimal_symbol (obsavestring (name, strlen (name), &objfile -> symbol_obstack),
418 /* Scan and build partial symbols for a symbol file.
419 We have been initialized by a call to dbx_symfile_init, which
420 put all the relevant info into a "struct dbx_symfile_info"
421 hung off the struct sym_fns SF.
423 ADDR is the address relative to which the symbols in it are (e.g.
424 the base address of the text segment).
425 MAINLINE is true if we are reading the main symbol
426 table (as opposed to a shared lib or dynamically loaded file). */
429 dbx_symfile_read (objfile, addr, mainline)
430 struct objfile *objfile;
432 int mainline; /* FIXME comments above */
434 struct dbx_symfile_info *info;
438 sym_bfd = objfile->obfd;
439 info = (struct dbx_symfile_info *) (objfile -> sym_private);
440 val = bfd_seek (objfile->obfd, info->symtab_offset, L_SET);
442 perror_with_name (objfile->name);
444 /* If mainline, set global string table pointers, and reinitialize global
445 partial symbol list. */
447 symfile_string_table = info->stringtab;
448 symfile_string_table_size = info->stringtab_size;
451 /* If we are reinitializing, or if we have never loaded syms yet, init */
452 if (mainline || objfile->global_psymbols.size == 0 || objfile->static_psymbols.size == 0)
453 init_psymbol_list (info->symcount, objfile);
455 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
456 symbol_size = obj_symbol_entry_size (sym_bfd);
459 make_cleanup (really_free_pendings, 0);
461 init_minimal_symbol_collection ();
462 make_cleanup (discard_minimal_symbols, 0);
464 /* Now that the symbol table data of the executable file are all in core,
465 process them and define symbols accordingly. */
467 read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
468 objfile, info->stringtab, info->stringtab_size,
470 bfd_section_vma (sym_bfd, info->text_sect),
471 bfd_section_size (sym_bfd, info->text_sect));
473 /* Install any minimal symbols that have been collected as the current
474 minimal symbols for this objfile. */
476 install_minimal_symbols (objfile);
478 /* Free up any memory we allocated for ourselves. */
481 mfree (objfile->md, info->stringtab); /* Stringtab is only saved for mainline */
483 mfree (objfile->md, info);
484 /* Zap pointer to our (now gone) info struct */
485 objfile -> sym_private = NULL;
486 if (!have_partial_symbols ()) {
488 printf_filtered ("(no debugging symbols found)...");
493 /* Initialize anything that needs initializing when a completely new
494 symbol file is specified (not just adding some symbols from another
495 file, e.g. a shared library). */
498 dbx_new_init (objfile)
499 struct objfile *objfile;
501 buildsym_new_init ();
502 init_header_files ();
506 /* dbx_symfile_init ()
507 is the dbx-specific initialization routine for reading symbols.
508 It is passed a struct objfile which contains, among other things,
509 the BFD for the file whose symbols are being read, and a slot for a pointer
510 to "private data" which we fill with goodies.
512 We read the string table into malloc'd space and stash a pointer to it.
514 Since BFD doesn't know how to read debug symbols in a format-independent
515 way (and may never do so...), we have to do it ourselves. We will never
516 be called unless this is an a.out (or very similar) file.
517 FIXME, there should be a cleaner peephole into the BFD environment here. */
520 dbx_symfile_init (objfile)
521 struct objfile *objfile;
524 bfd *sym_bfd = objfile->obfd;
525 char *name = bfd_get_filename (sym_bfd);
526 struct dbx_symfile_info *info;
527 unsigned char size_temp[4];
529 /* Allocate struct to keep track of the symfile */
530 objfile-> sym_private = xmmalloc (objfile -> md, sizeof (*info));
531 info = (struct dbx_symfile_info *) objfile -> sym_private;
533 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
534 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
535 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
536 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
538 info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
539 if (!info->text_sect)
541 info->symcount = bfd_get_symcount (sym_bfd);
543 /* Read the string table size and check it for bogosity. */
544 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
546 perror_with_name (name);
548 val = bfd_read (size_temp, sizeof (long), 1, sym_bfd);
550 perror_with_name (name);
551 info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
553 if (info->stringtab_size >= 0)
555 /* Yes, this should be malloc, not xmalloc. We check its result. */
556 info->stringtab = (char *) mmalloc (objfile->md, info->stringtab_size);
557 /* Caller is responsible for freeing the string table. No cleanup. */
560 info->stringtab = NULL;
561 if (info->stringtab == NULL && info->stringtab_size != 0)
562 error ("ridiculous string table size: %d bytes", info->stringtab_size);
564 /* Now read in the string table in one big gulp. */
566 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
568 perror_with_name (name);
569 val = bfd_read (info->stringtab, info->stringtab_size, 1, sym_bfd);
570 if (val != info->stringtab_size)
571 perror_with_name (name);
573 /* Record the position of the symbol table for later use. */
575 info->symtab_offset = SYMBOL_TABLE_OFFSET;
578 /* Perform any local cleanups required when we are done with a particular
579 objfile. I.E, we are in the process of discarding all symbol information
580 for an objfile, freeing up all memory held for it, and unlinking the
581 objfile struct from the global list of known objfiles. */
584 dbx_symfile_finish (objfile)
585 struct objfile *objfile;
587 if (objfile -> sym_private != NULL)
589 mfree (objfile -> md, objfile -> sym_private);
591 if (symfile_string_table)
593 free (symfile_string_table);
594 symfile_string_table = 0;
595 symfile_string_table_size = 0;
597 free_header_files ();
601 /* Buffer for reading the symbol table entries. */
602 static struct internal_nlist symbuf[4096];
603 static int symbuf_idx;
604 static int symbuf_end;
606 /* The address in memory of the string table of the object file we are
607 reading (which might not be the "main" object file, but might be a
608 shared library or some other dynamically loaded thing). This is set
609 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
610 when building symtabs, and is used only by next_symbol_text. */
611 static char *stringtab_global;
613 /* Refill the symbol table input buffer
614 and set the variables that control fetching entries from it.
615 Reports an error if no data available.
616 This function can read past the end of the symbol table
617 (into the string table) but this does no harm. */
620 fill_symbuf (sym_bfd)
623 int nbytes = bfd_read (symbuf, sizeof (symbuf), 1, sym_bfd);
625 perror_with_name (bfd_get_filename (sym_bfd));
626 else if (nbytes == 0)
627 error ("Premature end of file reading symbol table");
628 symbuf_end = nbytes / symbol_size;
632 #define SWAP_SYMBOL(symp, abfd) \
634 (symp)->n_strx = bfd_h_get_32(abfd, \
635 (unsigned char *)&(symp)->n_strx); \
636 (symp)->n_desc = bfd_h_get_16 (abfd, \
637 (unsigned char *)&(symp)->n_desc); \
638 (symp)->n_value = bfd_h_get_32 (abfd, \
639 (unsigned char *)&(symp)->n_value); \
642 /* Invariant: The symbol pointed to by symbuf_idx is the first one
643 that hasn't been swapped. Swap the symbol at the same time
644 that symbuf_idx is incremented. */
646 /* dbx allows the text of a symbol name to be continued into the
647 next symbol name! When such a continuation is encountered
648 (a \ at the end of the text of a name)
649 call this function to get the continuation. */
652 dbx_next_symbol_text ()
654 if (symbuf_idx == symbuf_end)
655 fill_symbuf (symfile_bfd);
657 SWAP_SYMBOL(&symbuf[symbuf_idx], symfile_bfd);
658 return symbuf[symbuf_idx++].n_strx + stringtab_global;
661 /* Initializes storage for all of the partial symbols that will be
662 created by read_dbx_symtab and subsidiaries. */
665 init_psymbol_list (total_symbols, objfile)
667 struct objfile *objfile;
669 /* Free any previously allocated psymbol lists. */
670 if (objfile -> global_psymbols.list)
671 mfree (objfile -> md, objfile -> global_psymbols.list);
672 if (objfile -> static_psymbols.list)
673 mfree (objfile -> md, objfile -> static_psymbols.list);
675 /* Current best guess is that there are approximately a twentieth
676 of the total symbols (in a debugging file) are global or static
678 objfile -> global_psymbols.size = total_symbols / 10;
679 objfile -> static_psymbols.size = total_symbols / 10;
680 objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)
681 xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol));
682 objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)
683 xmmalloc (objfile -> md, objfile -> static_psymbols.size * sizeof (struct partial_symbol));
686 /* Initialize the list of bincls to contain none and have some
690 init_bincl_list (number, objfile)
692 struct objfile *objfile;
694 bincls_allocated = number;
695 next_bincl = bincl_list = (struct header_file_location *)
696 xmmalloc (objfile -> md, bincls_allocated * sizeof(struct header_file_location));
699 /* Add a bincl to the list. */
702 add_bincl_to_list (pst, name, instance)
703 struct partial_symtab *pst;
707 if (next_bincl >= bincl_list + bincls_allocated)
709 int offset = next_bincl - bincl_list;
710 bincls_allocated *= 2;
711 bincl_list = (struct header_file_location *)
712 xmrealloc (pst->objfile->md, (char *)bincl_list,
713 bincls_allocated * sizeof (struct header_file_location));
714 next_bincl = bincl_list + offset;
716 next_bincl->pst = pst;
717 next_bincl->instance = instance;
718 next_bincl++->name = name;
721 /* Given a name, value pair, find the corresponding
722 bincl in the list. Return the partial symtab associated
723 with that header_file_location. */
725 static struct partial_symtab *
726 find_corresponding_bincl_psymtab (name, instance)
730 struct header_file_location *bincl;
732 for (bincl = bincl_list; bincl < next_bincl; bincl++)
733 if (bincl->instance == instance
734 && !strcmp (name, bincl->name))
737 return (struct partial_symtab *) 0;
740 /* Free the storage allocated for the bincl list. */
743 free_bincl_list (objfile)
744 struct objfile *objfile;
746 mfree (objfile -> md, bincl_list);
747 bincls_allocated = 0;
750 /* Given pointers to an a.out symbol table in core containing dbx
751 style data, setup partial_symtab's describing each source file for
752 which debugging information is available. NLISTLEN is the number
753 of symbols in the symbol table. All symbol names are given as
754 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
755 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
756 and ADDR is its relocated address (if incremental) or 0 (if not). */
759 read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
760 text_addr, text_size)
762 struct objfile *objfile;
763 register char *stringtab;
764 register long stringtab_size;
765 register int nlistlen;
769 register struct internal_nlist *bufp;
770 register char *namestring;
772 int past_first_source_file = 0;
773 CORE_ADDR last_o_file_start = 0;
774 struct cleanup *old_chain;
777 /* End of the text segment of the executable file. */
778 CORE_ADDR end_of_text_addr;
780 /* Current partial symtab */
781 struct partial_symtab *pst;
783 /* List of current psymtab's include files */
784 char **psymtab_include_list;
785 int includes_allocated;
788 /* Index within current psymtab dependency list */
789 struct partial_symtab **dependency_list;
790 int dependencies_used, dependencies_allocated;
792 stringtab_global = stringtab;
794 pst = (struct partial_symtab *) 0;
796 includes_allocated = 30;
798 psymtab_include_list = (char **) alloca (includes_allocated *
801 dependencies_allocated = 30;
802 dependencies_used = 0;
804 (struct partial_symtab **) alloca (dependencies_allocated *
805 sizeof (struct partial_symtab *));
807 old_chain = make_cleanup (free_objfile, objfile);
809 /* Init bincl list */
810 init_bincl_list (20, objfile);
811 make_cleanup (free_bincl_list, objfile);
813 last_source_file = 0;
815 #ifdef END_OF_TEXT_DEFAULT
816 end_of_text_addr = END_OF_TEXT_DEFAULT;
818 end_of_text_addr = text_addr + addr + text_size; /* Relocate */
821 symfile_bfd = objfile->obfd; /* For next_text_symbol */
822 abfd = objfile->obfd;
823 symbuf_end = symbuf_idx = 0;
824 next_symbol_text_func = dbx_next_symbol_text;
826 for (symnum = 0; symnum < nlistlen; symnum++)
828 /* Get the symbol for this run and pull out some info */
829 QUIT; /* allow this to be interruptable */
830 if (symbuf_idx == symbuf_end)
832 bufp = &symbuf[symbuf_idx++];
835 * Special case to speed up readin.
837 if (bufp->n_type == (unsigned char)N_SLINE) continue;
839 SWAP_SYMBOL (bufp, abfd);
841 /* Ok. There is a lot of code duplicated in the rest of this
842 switch statement (for efficiency reasons). Since I don't
843 like duplicating code, I will do my penance here, and
844 describe the code which is duplicated:
846 *) The assignment to namestring.
847 *) The call to strchr.
848 *) The addition of a partial symbol the the two partial
849 symbol lists. This last is a large section of code, so
850 I've imbedded it in the following macro.
853 /* Set namestring based on bufp. If the string table index is invalid,
854 give a fake name, and print a single error message per symbol file read,
855 rather than abort the symbol reading or flood the user with messages. */
856 #define SET_NAMESTRING()\
857 if (((unsigned)bufp->n_strx) >= stringtab_size) { \
858 complain (&string_table_offset_complaint, (char *) symnum); \
859 namestring = "foo"; \
861 namestring = bufp->n_strx + stringtab
863 #define CUR_SYMBOL_TYPE bufp->n_type
864 #define CUR_SYMBOL_VALUE bufp->n_value
866 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
867 start_psymtab(ofile, addr, fname, low, symoff, global_syms, static_syms)
868 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\
869 end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)
871 #include "partial-stab.h"
874 /* If there's stuff to be cleaned up, clean it up. */
875 if (nlistlen > 0 /* We have some syms */
876 && entry_point < bufp->n_value
877 && entry_point >= last_o_file_start)
879 startup_file_start = last_o_file_start;
880 startup_file_end = bufp->n_value;
885 end_psymtab (pst, psymtab_include_list, includes_used,
886 symnum * symbol_size, end_of_text_addr,
887 dependency_list, dependencies_used);
890 free_bincl_list (objfile);
891 discard_cleanups (old_chain);
894 /* Allocate and partially fill a partial symtab. It will be
895 completely filled at the end of the symbol list.
897 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
898 is the address relative to which its symbols are (incremental) or 0
902 struct partial_symtab *
903 start_psymtab (objfile, addr,
904 filename, textlow, ldsymoff, global_syms, static_syms)
905 struct objfile *objfile;
910 struct partial_symbol *global_syms;
911 struct partial_symbol *static_syms;
913 struct partial_symtab *result =
914 start_psymtab_common(objfile, addr,
915 filename, textlow, global_syms, static_syms);
917 result->read_symtab_private = (char *)
918 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
919 LDSYMOFF(result) = ldsymoff;
920 result->read_symtab = dbx_psymtab_to_symtab;
925 /* Close off the current usage of a partial_symbol table entry. This
926 involves setting the correct number of includes (with a realloc),
927 setting the high text mark, setting the symbol length in the
928 executable, and setting the length of the global and static lists
931 The global symbols and static symbols are then seperately sorted.
933 Then the partial symtab is put on the global list.
934 *** List variables and peculiarities of same. ***
938 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
939 capping_text, dependency_list, number_dependencies)
940 struct partial_symtab *pst;
943 int capping_symbol_offset;
944 CORE_ADDR capping_text;
945 struct partial_symtab **dependency_list;
946 int number_dependencies;
947 /* struct partial_symbol *capping_global, *capping_static;*/
950 struct objfile *objfile = pst -> objfile;
952 if (capping_symbol_offset != -1)
953 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
954 pst->texthigh = capping_text;
957 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
959 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
961 pst->number_of_dependencies = number_dependencies;
962 if (number_dependencies)
964 pst->dependencies = (struct partial_symtab **)
965 obstack_alloc (&objfile->psymbol_obstack,
966 number_dependencies * sizeof (struct partial_symtab *));
967 memcpy (pst->dependencies, dependency_list,
968 number_dependencies * sizeof (struct partial_symtab *));
971 pst->dependencies = 0;
973 for (i = 0; i < num_includes; i++)
975 struct partial_symtab *subpst =
976 allocate_psymtab (include_list[i], objfile);
978 subpst->addr = pst->addr;
979 subpst->read_symtab_private =
980 (char *) obstack_alloc (&objfile->psymbol_obstack,
981 sizeof (struct symloc));
985 subpst->texthigh = 0;
987 /* We could save slight bits of space by only making one of these,
988 shared by the entire set of include files. FIXME-someday. */
989 subpst->dependencies = (struct partial_symtab **)
990 obstack_alloc (&objfile->psymbol_obstack,
991 sizeof (struct partial_symtab *));
992 subpst->dependencies[0] = pst;
993 subpst->number_of_dependencies = 1;
995 subpst->globals_offset =
996 subpst->n_global_syms =
997 subpst->statics_offset =
998 subpst->n_static_syms = 0;
1002 subpst->read_symtab = dbx_psymtab_to_symtab;
1005 sort_pst_symbols (pst);
1007 /* If there is already a psymtab or symtab for a file of this name, remove it.
1008 (If there is a symtab, more drastic things also happen.)
1009 This happens in VxWorks. */
1010 free_named_symtabs (pst->filename);
1012 if (num_includes == 0
1013 && number_dependencies == 0
1014 && pst->n_global_syms == 0
1015 && pst->n_static_syms == 0) {
1016 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1017 it is on the obstack, but we can forget to chain it on the list. */
1018 struct partial_symtab *prev_pst;
1020 /* First, snip it out of the psymtab chain */
1022 if (pst->objfile->psymtabs == pst)
1023 pst->objfile->psymtabs = pst->next;
1025 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
1026 if (prev_pst->next == pst)
1027 prev_pst->next = pst->next;
1029 /* Next, put it on a free list for recycling */
1031 pst->next = pst->objfile->free_psymtabs;
1032 pst->objfile->free_psymtabs = pst;
1037 psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
1038 struct partial_symtab *pst;
1043 struct cleanup *old_chain;
1051 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1056 /* Read in all partial symtabs on which this one is dependent */
1057 for (i = 0; i < pst->number_of_dependencies; i++)
1058 if (!pst->dependencies[i]->readin)
1060 /* Inform about additional files that need to be read in. */
1063 fputs_filtered (" ", stdout);
1065 fputs_filtered ("and ", stdout);
1067 printf_filtered ("%s...", pst->dependencies[i]->filename);
1068 wrap_here (""); /* Flush output */
1071 psymtab_to_symtab_1 (pst->dependencies[i],
1072 stringtab, stringtab_size, sym_offset);
1075 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
1077 /* Init stuff necessary for reading in symbols */
1079 old_chain = make_cleanup (really_free_pendings, 0);
1081 /* Read in this files symbols */
1082 bfd_seek (pst->objfile->obfd, sym_offset, L_SET);
1084 read_ofile_symtab (pst->objfile, stringtab, stringtab_size,
1086 LDSYMLEN(pst), pst->textlow,
1087 pst->texthigh - pst->textlow, pst->addr);
1088 sort_symtab_syms (pst->symtab);
1090 do_cleanups (old_chain);
1097 * Read in all of the symbols for a given psymtab for real.
1098 * Be verbose about it if the user wants that.
1101 dbx_psymtab_to_symtab (pst)
1102 struct partial_symtab *pst;
1114 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1119 if (LDSYMLEN(pst) || pst->number_of_dependencies)
1121 /* Print the message now, before reading the string table,
1122 to avoid disconcerting pauses. */
1125 printf_filtered ("Reading in symbols for %s...", pst->filename);
1129 sym_bfd = pst->objfile->obfd;
1131 /* We keep the string table for the main symfile resident in memory, but
1132 not the string table for any other symbol files. */
1133 if (symfile_objfile != pst->objfile)
1135 /* Read in the string table */
1137 /* FIXME, this uses internal BFD variables. See above in
1138 dbx_symbol_file_open where the macro is defined! */
1139 bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
1141 val = bfd_read (&st_temp, sizeof st_temp, 1, sym_bfd);
1143 perror_with_name (pst->objfile->name);
1144 stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
1146 /* BFD doesn't provide a way to know the total file size, sigh */
1147 struct stat statbuf;
1148 if (fstat (desc, &statbuf) < 0)
1149 perror_with_name (pst->objfile->name);
1151 if (stsize >= 0 && stsize < statbuf.st_size)
1156 #ifdef BROKEN_LARGE_ALLOCA
1157 stringtab = (char *) xmalloc (stsize);
1158 make_cleanup (free, stringtab);
1160 stringtab = (char *) alloca (stsize);
1165 if (stringtab == NULL && stsize != 0)
1166 error ("ridiculous string table size: %d bytes", stsize);
1168 /* FIXME, this uses internal BFD variables. See above in
1169 dbx_symbol_file_open where the macro is defined! */
1170 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
1172 perror_with_name (pst->objfile->name);
1173 val = bfd_read (stringtab, stsize, 1, sym_bfd);
1175 perror_with_name (pst->objfile->name);
1179 stringtab = symfile_string_table;
1180 stsize = symfile_string_table_size;
1183 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1184 symbol_size = obj_symbol_entry_size (sym_bfd);
1186 next_symbol_text_func = dbx_next_symbol_text;
1188 /* FIXME, this uses internal BFD variables. See above in
1189 dbx_symbol_file_open where the macro is defined! */
1190 psymtab_to_symtab_1 (pst, stringtab, stsize,
1191 SYMBOL_TABLE_OFFSET);
1193 /* Match with global symbols. This only needs to be done once,
1194 after all of the symtabs and dependencies have been read in. */
1195 scan_file_globals (pst->objfile);
1197 /* Finish up the debug error message. */
1199 printf_filtered ("done.\n");
1204 * Read in a defined section of a specific object file's symbols.
1206 * DESC is the file descriptor for the file, positioned at the
1207 * beginning of the symtab
1208 * STRINGTAB is a pointer to the files string
1209 * table, already read in
1210 * SYM_OFFSET is the offset within the file of
1211 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
1212 * number of symbols to read
1213 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1214 * TEXT_SIZE is the size of the text segment read in.
1215 * OFFSET is a relocation offset which gets added to each symbol
1218 static struct symtab *
1219 read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset,
1220 sym_size, text_offset, text_size, offset)
1221 struct objfile *objfile;
1222 register char *stringtab;
1223 unsigned int stringtab_size;
1226 CORE_ADDR text_offset;
1230 register char *namestring;
1231 register struct internal_nlist *bufp;
1233 unsigned max_symnum;
1236 current_objfile = objfile;
1239 stringtab_global = stringtab;
1240 last_source_file = 0;
1242 abfd = objfile->obfd;
1243 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */
1244 our_objfile = objfile; /* For end_symtab calls in process_one_symbol */
1245 symbuf_end = symbuf_idx = 0;
1247 /* It is necessary to actually read one symbol *before* the start
1248 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1249 occurs before the N_SO symbol.
1251 Detecting this in read_dbx_symtab
1252 would slow down initial readin, so we look for it here instead. */
1253 if (sym_offset >= (int)symbol_size)
1255 bfd_seek (symfile_bfd, sym_offset - symbol_size, L_INCR);
1257 bufp = &symbuf[symbuf_idx++];
1258 SWAP_SYMBOL (bufp, abfd);
1262 processing_gcc_compilation =
1263 (bufp->n_type == N_TEXT
1264 && (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0
1265 || strcmp(namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0));
1269 /* The N_SO starting this symtab is the first symbol, so we
1270 better not check the symbol before it. I'm not this can
1271 happen, but it doesn't hurt to check for it. */
1272 bfd_seek (symfile_bfd, sym_offset, L_INCR);
1273 processing_gcc_compilation = 0;
1276 if (symbuf_idx == symbuf_end)
1278 bufp = &symbuf[symbuf_idx];
1279 if (bufp->n_type != (unsigned char)N_SO)
1280 error("First symbol in segment of executable not a source symbol");
1282 max_symnum = sym_size / symbol_size;
1285 symnum < max_symnum;
1288 QUIT; /* Allow this to be interruptable */
1289 if (symbuf_idx == symbuf_end)
1291 bufp = &symbuf[symbuf_idx++];
1292 SWAP_SYMBOL (bufp, abfd);
1294 type = bufp->n_type;
1295 if (type == (unsigned char)N_CATCH)
1297 /* N_CATCH is not fixed up by the linker, and unfortunately,
1298 there's no other place to put it in the .stab map. */
1299 bufp->n_value += text_offset - offset;
1304 if (type & N_STAB) {
1305 process_one_symbol (type, bufp->n_desc, bufp->n_value,
1306 namestring, offset);
1307 /* our_objfile is an implicit parameter. */
1309 /* We skip checking for a new .o or -l file; that should never
1310 happen in this routine. */
1311 else if (type == N_TEXT
1312 && (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0
1313 || strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0))
1314 /* I don't think this code will ever be executed, because
1315 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1316 the N_SO symbol which starts this source file.
1317 However, there is no reason not to accept
1318 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1319 processing_gcc_compilation = 1;
1320 else if (type & N_EXT || type == (unsigned char)N_TEXT
1321 || type == (unsigned char)N_NBTEXT
1323 /* Global symbol: see if we came across a dbx defintion for
1324 a corresponding symbol. If so, store the value. Remove
1325 syms from the chain when their values are stored, but
1326 search the whole chain, as there may be several syms from
1327 different files with the same name. */
1328 /* This is probably not true. Since the files will be read
1329 in one at a time, each reference to a global symbol will
1330 be satisfied in each file as it appears. So we skip this
1336 current_objfile = NULL;
1337 return (end_symtab (text_offset + text_size, 0, 0, objfile));
1340 /* This handles a single symbol from the symbol-file, building symbols
1341 into a GDB symtab. It takes these arguments and an implicit argument.
1343 TYPE is the type field of the ".stab" symbol entry.
1344 DESC is the desc field of the ".stab" entry.
1345 VALU is the value field of the ".stab" entry.
1346 NAME is the symbol name, in our address space.
1347 OFFSET is the amount by which this object file was relocated
1348 when it was loaded into memory. All symbols that refer
1349 to memory locations need to be offset by this amount.
1351 The implicit argument is:
1352 OUR_OBJFILE is the object file from which we are reading symbols.
1353 It is used in end_symtab. */
1356 process_one_symbol (type, desc, valu, name, offset)
1362 #ifndef SUN_FIXED_LBRAC_BUG
1363 /* This records the last pc address we've seen. We depend on there being
1364 an SLINE or FUN or SO before the first LBRAC, since the variable does
1365 not get reset in between reads of different symbol files. */
1366 static CORE_ADDR last_pc_address;
1368 register struct context_stack *new;
1371 /* Something is wrong if we see real data before
1372 seeing a source file name. */
1374 if (last_source_file == 0 && type != (unsigned char)N_SO)
1376 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
1377 where that code is defined. */
1378 if (IGNORE_SYMBOL (type))
1381 /* FIXME, this should not be an error, since it precludes extending
1382 the symbol table information in this way... */
1383 error ("Invalid symbol data: does not start by identifying a source file.");
1391 /* It seems that the Sun ANSI C compiler (acc) replaces N_FUN with N_GSYM and
1392 N_STSYM with a type code of f or F. Can't enable this until we get some
1393 stuff straightened out with psymtabs. */
1399 valu += offset; /* Relocate for dynamic loading */
1401 /* Either of these types of symbols indicates the start of
1402 a new function. We must process its "name" normally for dbx,
1403 but also record the start of a new lexical context, and possibly
1404 also the end of the lexical context for the previous function. */
1405 /* This is not always true. This type of symbol may indicate a
1406 text segment variable. */
1408 colon_pos = strchr (name, ':');
1410 || (*colon_pos != 'f' && *colon_pos != 'F'))
1412 define_symbol (valu, name, desc, type, our_objfile);
1416 #ifndef SUN_FIXED_LBRAC_BUG
1417 last_pc_address = valu; /* Save for SunOS bug circumcision */
1420 within_function = 1;
1421 if (context_stack_depth > 0)
1423 new = pop_context ();
1424 /* Make a block for the local symbols within. */
1425 finish_block (new->name, &local_symbols, new->old_blocks,
1426 new->start_addr, valu, our_objfile);
1428 /* Stack must be empty now. */
1429 if (context_stack_depth != 0)
1430 complain (&lbrac_unmatched_complaint, (char *) symnum);
1432 new = push_context (0, valu);
1433 new->name = define_symbol (valu, name, desc, type, our_objfile);
1437 /* Record the address at which this catch takes place. */
1438 define_symbol (valu+offset, name, desc, type, our_objfile);
1442 /* This "symbol" just indicates the start of an inner lexical
1443 context within a function. */
1445 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1446 valu += offset; /* Relocate for dynamic loading */
1448 /* On most machines, the block addresses are relative to the
1449 N_SO, the linker did not relocate them (sigh). */
1450 valu += last_source_start_addr;
1453 #ifndef SUN_FIXED_LBRAC_BUG
1454 if (valu < last_pc_address) {
1455 /* Patch current LBRAC pc value to match last handy pc value */
1456 complain (&lbrac_complaint, 0);
1457 valu = last_pc_address;
1460 new = push_context (desc, valu);
1464 /* This "symbol" just indicates the end of an inner lexical
1465 context that was started with N_LBRAC. */
1467 #if defined (BLOCK_ADDRESS_ABSOLUTE)
1468 valu += offset; /* Relocate for dynamic loading */
1470 /* On most machines, the block addresses are relative to the
1471 N_SO, the linker did not relocate them (sigh). */
1472 valu += last_source_start_addr;
1475 new = pop_context();
1476 if (desc != new->depth)
1477 complain (&lbrac_mismatch_complaint, (char *) symnum);
1479 /* Some compilers put the variable decls inside of an
1480 LBRAC/RBRAC block. This macro should be nonzero if this
1481 is true. DESC is N_DESC from the N_RBRAC symbol.
1482 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
1483 or the GCC2_COMPILED_SYMBOL. */
1484 #if !defined (VARIABLES_INSIDE_BLOCK)
1485 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
1488 /* Can only use new->locals as local symbols here if we're in
1489 gcc or on a machine that puts them before the lbrack. */
1490 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1491 local_symbols = new->locals;
1493 /* If this is not the outermost LBRAC...RBRAC pair in the
1494 function, its local symbols preceded it, and are the ones
1495 just recovered from the context stack. Defined the block for them.
1497 If this is the outermost LBRAC...RBRAC pair, there is no
1498 need to do anything; leave the symbols that preceded it
1499 to be attached to the function's own block. However, if
1500 it is so, we need to indicate that we just moved outside
1503 && (context_stack_depth
1504 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
1506 /* FIXME Muzzle a compiler bug that makes end < start. */
1507 if (new->start_addr > valu)
1509 complain(&lbrac_rbrac_complaint, 0);
1510 new->start_addr = valu;
1512 /* Make a block for the local symbols within. */
1513 finish_block (0, &local_symbols, new->old_blocks,
1514 new->start_addr, valu, our_objfile);
1518 within_function = 0;
1520 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1521 /* Now pop locals of block just finished. */
1522 local_symbols = new->locals;
1527 /* This kind of symbol indicates the start of an object file. */
1528 valu += offset; /* Relocate for dynamic loading */
1532 /* This type of symbol indicates the start of data
1533 for one source file.
1534 Finish the symbol table of the previous source file
1535 (if any) and start accumulating a new symbol table. */
1536 valu += offset; /* Relocate for dynamic loading */
1538 #ifndef SUN_FIXED_LBRAC_BUG
1539 last_pc_address = valu; /* Save for SunOS bug circumcision */
1542 #ifdef PCC_SOL_BROKEN
1543 /* pcc bug, occasionally puts out SO for SOL. */
1544 if (context_stack_depth > 0)
1546 start_subfile (name, NULL);
1550 if (last_source_file)
1552 /* Check if previous symbol was also an N_SO (with some
1553 sanity checks). If so, that one was actually the directory
1554 name, and the current one is the real file name.
1556 if (previous_stab_code == N_SO
1557 && current_subfile && current_subfile->dirname == NULL
1558 && current_subfile->name != NULL
1559 && current_subfile->name[strlen(current_subfile->name)-1] == '/')
1561 current_subfile->dirname = current_subfile->name;
1562 current_subfile->name =
1563 obsavestring (name, strlen (name),
1564 &our_objfile -> symbol_obstack);
1567 (void) end_symtab (valu, 0, 0, our_objfile);
1569 start_symtab (name, NULL, valu);
1574 /* This type of symbol indicates the start of data for
1575 a sub-source-file, one whose contents were copied or
1576 included in the compilation of the main source file
1577 (whose name was given in the N_SO symbol.) */
1578 valu += offset; /* Relocate for dynamic loading */
1579 start_subfile (name, NULL);
1584 add_new_header_file (name, valu);
1585 start_subfile (name, NULL);
1589 start_subfile (pop_subfile (), NULL);
1593 add_old_header_file (name, valu);
1597 /* This type of "symbol" really just records
1598 one line-number -- core-address correspondence.
1599 Enter it in the line list for this symbol table. */
1600 valu += offset; /* Relocate for dynamic loading */
1601 #ifndef SUN_FIXED_LBRAC_BUG
1602 last_pc_address = valu; /* Save for SunOS bug circumcision */
1604 record_line (current_subfile, desc, valu);
1609 error ("Invalid symbol data: common within common at symtab pos %d",
1611 common_block = local_symbols;
1612 common_block_i = local_symbols ? local_symbols->nsyms : 0;
1616 /* Symbols declared since the BCOMM are to have the common block
1617 start address added in when we know it. common_block points to
1618 the first symbol after the BCOMM in the local_symbols list;
1619 copy the list and hang it off the symbol for the common block name
1623 struct symbol *sym =
1624 (struct symbol *) xmmalloc (our_objfile -> md, sizeof (struct symbol));
1625 bzero (sym, sizeof *sym);
1626 SYMBOL_NAME (sym) = savestring (name, strlen (name));
1627 SYMBOL_CLASS (sym) = LOC_BLOCK;
1628 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
1629 copy_pending (local_symbols, common_block_i, common_block));
1630 i = hashname (SYMBOL_NAME (sym));
1631 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1632 global_sym_chain[i] = sym;
1637 /* The following symbol types need to have the offset added to their
1638 value; then we process symbol definitions in the name. */
1639 case N_STSYM: /* Global symbol */
1640 case N_LCSYM: /* Local symbol */
1641 case N_DSLINE: /* Source line number, data seg */
1642 case N_BSLINE: /* Source line number, bss seg */
1643 /* N_BROWS: overlaps with N_BSLINE */
1644 case N_ENTRY: /* Alternate entry point */
1645 valu += offset; /* Relocate for dynamic loading */
1648 /* The following symbol types don't need the address field relocated,
1649 since it is either unused, or is absolute. */
1650 case N_GSYM: /* Global variable */
1651 case N_NSYMS: /* Number of symbols (ultrix) */
1652 case N_NOMAP: /* No map? (ultrix) */
1653 case N_RSYM: /* Register variable */
1654 case N_DEFD: /* Modula-2 GNU module dependency */
1655 case N_SSYM: /* Struct or union element */
1656 case N_LSYM: /* Local symbol in stack */
1657 case N_PSYM: /* Parameter variable */
1658 case N_LENG: /* Length of preceding symbol type */
1660 define_symbol (valu, name, desc, type, our_objfile);
1663 /* The following symbol types we don't know how to process. Handle
1664 them in a "default" way, but complain to people who care. */
1666 case N_EHDECL: /* Exception handler name */
1667 case N_MAIN: /* Name of main routine (not used in C) */
1668 case N_PC: /* Global symbol in Pascal */
1669 case N_M2C: /* Modula-2 compilation unit */
1670 /* N_MOD2: overlaps with N_EHDECL */
1671 case N_SCOPE: /* Modula-2 scope information */
1672 case N_ECOML: /* End common (local name) */
1673 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
1678 complain (&unknown_symtype_complaint, local_hex_string(type));
1680 define_symbol (valu, name, desc, type, our_objfile);
1683 previous_stab_code = type;
1686 /* Copy a pending list, used to record the contents of a common
1687 block for later fixup. */
1688 static struct pending *
1689 copy_pending (beg, begi, end)
1690 struct pending *beg;
1692 struct pending *end;
1694 struct pending *new = 0;
1695 struct pending *next;
1697 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
1698 next = next->next, begi = 0)
1701 for (j = begi; j < next->nsyms; j++)
1702 add_symbol_to_list (next->symbol[j], &new);
1707 /* Register our willingness to decode symbols for SunOS and a.out and
1708 b.out files handled by BFD... */
1709 static struct sym_fns sunos_sym_fns =
1711 "sunOs", /* sym_name: name or name prefix of BFD target type */
1712 6, /* sym_namelen: number of significant sym_name chars */
1713 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
1714 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1715 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
1716 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
1717 NULL /* next: pointer to next struct sym_fns */
1720 static struct sym_fns aout_sym_fns =
1722 "a.out", /* sym_name: name or name prefix of BFD target type */
1723 5, /* sym_namelen: number of significant sym_name chars */
1724 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
1725 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1726 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
1727 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
1728 NULL /* next: pointer to next struct sym_fns */
1731 static struct sym_fns bout_sym_fns =
1733 "b.out", /* sym_name: name or name prefix of BFD target type */
1734 5, /* sym_namelen: number of significant sym_name chars */
1735 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
1736 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1737 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
1738 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
1739 NULL /* next: pointer to next struct sym_fns */
1743 _initialize_dbxread ()
1745 add_symtab_fns(&sunos_sym_fns);
1746 add_symtab_fns(&aout_sym_fns);
1747 add_symtab_fns(&bout_sym_fns);