1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-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 */
40 #include <sys/types.h>
47 #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 */
61 #include "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 struct sym_fns 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 */
73 int desc; /* File descriptor of symbol file */
77 /* Each partial symbol table entry contains a pointer to private data for the
78 read_symtab() function to use when expanding a partial symbol table entry
79 to a full symbol table entry.
81 For dbxread this structure contains the offset within the file symbol table
82 of first local symbol for this file, and length (in bytes) of the section
83 of the symbol table devoted to this file's symbols (actually, the section
84 bracketed may contain more than just this file's symbols). If ldsymlen is
85 0, the only reason for this thing's existence is the dependency list.
86 Nothing else will happen when it is read in. */
88 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
89 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
97 extern double atof ();
99 /* Forward declarations */
101 static void read_dbx_symtab ();
102 static void init_psymbol_list ();
103 static void process_one_symbol ();
104 static struct symbol *define_symbol ();
105 void start_subfile ();
107 static struct pending *copy_pending ();
108 static struct symtab *read_ofile_symtab ();
109 static void dbx_psymtab_to_symtab ();
111 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
112 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
114 /* Macro to determine which symbols to ignore when reading the first symbol
115 of a file. Some machines override this definition. */
116 #ifndef IGNORE_SYMBOL
117 /* This code is used on Ultrix systems. Ignore it */
118 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
121 /* Macro for name of symbol to indicate a file compiled with gcc. */
122 #ifndef GCC_COMPILED_FLAG_SYMBOL
123 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
126 /* Define this as 1 if a pcc declaration of a char or short argument
127 gives the correct address. Otherwise assume pcc gives the
128 address of the corresponding int, which is not the same on a
129 big-endian machine. */
131 #ifndef BELIEVE_PCC_PROMOTION
132 #define BELIEVE_PCC_PROMOTION 0
135 /* Nonzero means give verbose info on gdb action. From main.c. */
136 extern int info_verbose;
138 /* The BFD for this file -- only good while we're actively reading
139 symbols into a psymtab or a symtab. */
141 static bfd *symfile_bfd;
143 /* String table for the main symbol file. It is kept in memory
144 permanently, to speed up symbol reading. Other files' symbol tables
145 are read in on demand. FIXME, this should be cleaner. */
147 static char *symfile_string_table;
148 static int symfile_string_table_size;
150 /* The size of each symbol in the symbol file (in external form).
151 This is set by dbx_symfile_read when building psymtabs, and by
152 dbx_psymtab_to_symtab when building symtabs. */
154 static unsigned symbol_size;
156 /* Complaints about the symbols we have encountered. */
158 struct complaint lbrac_complaint =
159 {"bad block start address patched", 0, 0};
161 struct complaint string_table_offset_complaint =
162 {"bad string table offset in symbol %d", 0, 0};
164 struct complaint unknown_symtype_complaint =
165 {"unknown symbol type %s", 0, 0};
167 struct complaint lbrac_rbrac_complaint =
168 {"block start larger than block end", 0, 0};
170 /* During initial symbol readin, we need to have a structure to keep
171 track of which psymtabs have which bincls in them. This structure
172 is used during readin to setup the list of dependencies within each
173 partial symbol table. */
175 struct header_file_location
177 char *name; /* Name of header file */
178 int instance; /* See above */
179 struct partial_symtab *pst; /* Partial symtab that has the
180 BINCL/EINCL defs for this file */
183 /* The actual list and controling variables */
184 static struct header_file_location *bincl_list, *next_bincl;
185 static int bincls_allocated;
187 /* When a header file is getting special overriding definitions
188 for one source file, record here the header_files index
189 of its normal definition vector.
190 At other times, this is -1. */
192 static int header_file_prev_index;
194 /* Free up old header file tables, and allocate new ones.
195 We're reading a new symbol file now. */
198 free_and_init_header_files ()
201 for (i = 0; i < n_header_files; i++)
202 free (header_files[i].name);
203 if (header_files) /* First time null */
205 if (this_object_header_files) /* First time null */
206 free (this_object_header_files);
208 n_allocated_header_files = 10;
209 header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
212 n_allocated_this_object_header_files = 10;
213 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
216 /* Called at the start of each object file's symbols.
217 Clear out the mapping of header file numbers to header files. */
220 new_object_header_files ()
222 /* Leave FILENUM of 0 free for builtin types and this file's types. */
223 n_this_object_header_files = 1;
224 header_file_prev_index = -1;
227 /* Add header file number I for this object file
228 at the next successive FILENUM. */
231 add_this_object_header_file (i)
234 if (n_this_object_header_files == n_allocated_this_object_header_files)
236 n_allocated_this_object_header_files *= 2;
237 this_object_header_files
238 = (int *) xrealloc (this_object_header_files,
239 n_allocated_this_object_header_files * sizeof (int));
242 this_object_header_files[n_this_object_header_files++] = i;
245 /* Add to this file an "old" header file, one already seen in
246 a previous object file. NAME is the header file's name.
247 INSTANCE is its instance code, to select among multiple
248 symbol tables for the same header file. */
251 add_old_header_file (name, instance)
255 register struct header_file *p = header_files;
258 for (i = 0; i < n_header_files; i++)
259 if (!strcmp (p[i].name, name) && instance == p[i].instance)
261 add_this_object_header_file (i);
264 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
268 /* Add to this file a "new" header file: definitions for its types follow.
269 NAME is the header file's name.
270 Most often this happens only once for each distinct header file,
271 but not necessarily. If it happens more than once, INSTANCE has
272 a different value each time, and references to the header file
273 use INSTANCE values to select among them.
275 dbx output contains "begin" and "end" markers for each new header file,
276 but at this level we just need to know which files there have been;
277 so we record the file when its "begin" is seen and ignore the "end". */
280 add_new_header_file (name, instance)
285 header_file_prev_index = -1;
287 /* Make sure there is room for one more header file. */
289 if (n_header_files == n_allocated_header_files)
291 n_allocated_header_files *= 2;
292 header_files = (struct header_file *)
293 xrealloc (header_files,
294 (n_allocated_header_files
295 * sizeof (struct header_file)));
298 /* Create an entry for this header file. */
300 i = n_header_files++;
301 header_files[i].name = savestring (name, strlen(name));
302 header_files[i].instance = instance;
303 header_files[i].length = 10;
304 header_files[i].vector
305 = (struct type **) xmalloc (10 * sizeof (struct type *));
306 bzero (header_files[i].vector, 10 * sizeof (struct type *));
308 add_this_object_header_file (i);
312 static struct type **
313 explicit_lookup_type (real_filenum, index)
314 int real_filenum, index;
316 register struct header_file *f = &header_files[real_filenum];
318 if (index >= f->length)
321 f->vector = (struct type **)
322 xrealloc (f->vector, f->length * sizeof (struct type *));
323 bzero (&f->vector[f->length / 2],
324 f->length * sizeof (struct type *) / 2);
326 return &f->vector[index];
330 /* Handle the N_BINCL and N_EINCL symbol types
331 that act like N_SOL for switching source files
332 (different subfiles, as we call them) within one object file,
333 but using a stack rather than in an arbitrary order. */
337 struct subfile_stack *next;
342 struct subfile_stack *subfile_stack;
347 register struct subfile_stack *tem
348 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
350 tem->next = subfile_stack;
352 if (current_subfile == 0 || current_subfile->name == 0)
354 tem->name = current_subfile->name;
355 tem->prev_index = header_file_prev_index;
362 register struct subfile_stack *link = subfile_stack;
368 subfile_stack = link->next;
369 header_file_prev_index = link->prev_index;
376 record_misc_function (name, address, type)
381 enum misc_function_type misc_type;
383 switch (type &~ N_EXT) {
384 case N_TEXT: misc_type = mf_text; break;
385 case N_DATA: misc_type = mf_data; break;
386 case N_BSS: misc_type = mf_bss; break;
387 case N_ABS: misc_type = mf_abs; break;
389 case N_SETV: misc_type = mf_data; break;
391 default: misc_type = mf_unknown; break;
394 prim_record_misc_function (obsavestring (name, strlen (name)),
398 /* Scan and build partial symbols for a symbol file.
399 We have been initialized by a call to dbx_symfile_init, which
400 put all the relevant info into a "struct dbx_symfile_info"
401 hung off the struct sym_fns SF.
403 ADDR is the address relative to which the symbols in it are (e.g.
404 the base address of the text segment).
405 MAINLINE is true if we are reading the main symbol
406 table (as opposed to a shared lib or dynamically loaded file). */
409 dbx_symfile_read (sf, addr, mainline)
412 int mainline; /* FIXME comments above */
414 struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
415 bfd *sym_bfd = sf->sym_bfd;
417 char *filename = bfd_get_filename (sym_bfd);
419 val = lseek (info->desc, info->symtab_offset, L_SET);
421 perror_with_name (filename);
423 /* If mainline, set global string table pointers, and reinitialize global
424 partial symbol list. */
426 symfile_string_table = info->stringtab;
427 symfile_string_table_size = info->stringtab_size;
430 /* If we are reinitializing, or if we have never loaded syms yet, init */
431 if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0)
432 init_psymbol_list (info->symcount);
434 symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */
436 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
437 symbol_size = obj_symbol_entry_size (sym_bfd);
440 make_cleanup (really_free_pendings, 0);
442 init_misc_bunches ();
443 make_cleanup (discard_misc_bunches, 0);
445 /* Now that the symbol table data of the executable file are all in core,
446 process them and define symbols accordingly. */
448 read_dbx_symtab (filename,
449 addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
450 info->desc, info->stringtab, info->stringtab_size,
452 bfd_section_vma (sym_bfd, info->text_sect),
453 bfd_section_size (sym_bfd, info->text_sect));
455 /* Go over the misc symbol bunches and install them in vector. */
457 condense_misc_bunches (!mainline);
459 /* Free up any memory we allocated for ourselves. */
462 free (info->stringtab); /* Stringtab is only saved for mainline */
465 sf->sym_private = 0; /* Zap pointer to our (now gone) info struct */
467 if (!partial_symtab_list) {
469 printf_filtered ("(no debugging symbols found)...");
474 /* Initialize anything that needs initializing when a completely new
475 symbol file is specified (not just adding some symbols from another
476 file, e.g. a shared library). */
481 buildsym_new_init ();
483 /* Don't put these on the cleanup chain; they need to stick around
484 until the next call to dbx_new_init. *Then* we'll free them. */
485 if (symfile_string_table)
487 free (symfile_string_table);
488 symfile_string_table = 0;
489 symfile_string_table_size = 0;
491 free_and_init_header_files ();
495 /* dbx_symfile_init ()
496 is the dbx-specific initialization routine for reading symbols.
497 It is passed a struct sym_fns which contains, among other things,
498 the BFD for the file whose symbols are being read, and a slot for a pointer
499 to "private data" which we fill with goodies.
501 We read the string table into malloc'd space and stash a pointer to it.
503 Since BFD doesn't know how to read debug symbols in a format-independent
504 way (and may never do so...), we have to do it ourselves. We will never
505 be called unless this is an a.out (or very similar) file.
506 FIXME, there should be a cleaner peephole into the BFD environment here. */
509 dbx_symfile_init (sf)
515 bfd *sym_bfd = sf->sym_bfd;
516 char *name = bfd_get_filename (sym_bfd);
517 struct dbx_symfile_info *info;
518 unsigned char size_temp[4];
520 /* Allocate struct to keep track of the symfile */
521 sf->sym_private = xmalloc (sizeof (*info));
522 info = (struct dbx_symfile_info *)sf->sym_private;
524 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
525 desc = fileno ((FILE *)(sym_bfd->iostream)); /* Raw file descriptor */
526 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
527 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
528 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
531 info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
532 if (!info->text_sect)
534 info->symcount = bfd_get_symcount (sym_bfd);
536 /* Read the string table size and check it for bogosity. */
537 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
539 perror_with_name (name);
540 if (fstat (desc, &statbuf) == -1)
541 perror_with_name (name);
543 val = myread (desc, size_temp, sizeof (long));
545 perror_with_name (name);
546 info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
548 if (info->stringtab_size >= 0 && info->stringtab_size < statbuf.st_size)
550 info->stringtab = (char *) xmalloc (info->stringtab_size);
551 /* Caller is responsible for freeing the string table. No cleanup. */
554 info->stringtab = NULL;
555 if (info->stringtab == NULL && info->stringtab_size != 0)
556 error ("ridiculous string table size: %d bytes", info->stringtab_size);
558 /* Now read in the string table in one big gulp. */
560 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
562 perror_with_name (name);
563 val = myread (desc, info->stringtab, info->stringtab_size);
565 perror_with_name (name);
567 /* Record the position of the symbol table for later use. */
569 info->symtab_offset = SYMBOL_TABLE_OFFSET;
572 /* Buffer for reading the symbol table entries. */
573 static struct internal_nlist symbuf[4096];
574 static int symbuf_idx;
575 static int symbuf_end;
577 /* I/O descriptor for reading the symbol table. */
578 static int symtab_input_desc;
580 /* The address in memory of the string table of the object file we are
581 reading (which might not be the "main" object file, but might be a
582 shared library or some other dynamically loaded thing). This is set
583 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
584 when building symtabs, and is used only by next_symbol_text. */
585 static char *stringtab_global;
587 /* Refill the symbol table input buffer
588 and set the variables that control fetching entries from it.
589 Reports an error if no data available.
590 This function can read past the end of the symbol table
591 (into the string table) but this does no harm. */
596 int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
598 perror_with_name ("<symbol file>");
599 else if (nbytes == 0)
600 error ("Premature end of file reading symbol table");
601 symbuf_end = nbytes / symbol_size;
606 #define SWAP_SYMBOL(symp) \
608 (symp)->n_strx = bfd_h_get_32(symfile_bfd, \
609 (unsigned char *)&(symp)->n_strx); \
610 (symp)->n_desc = bfd_h_get_16 (symfile_bfd, \
611 (unsigned char *)&(symp)->n_desc); \
612 (symp)->n_value = bfd_h_get_32 (symfile_bfd, \
613 (unsigned char *)&(symp)->n_value); \
616 /* Invariant: The symbol pointed to by symbuf_idx is the first one
617 that hasn't been swapped. Swap the symbol at the same time
618 that symbuf_idx is incremented. */
620 /* dbx allows the text of a symbol name to be continued into the
621 next symbol name! When such a continuation is encountered
622 (a \ at the end of the text of a name)
623 call this function to get the continuation. */
628 if (symbuf_idx == symbuf_end)
631 SWAP_SYMBOL(&symbuf[symbuf_idx]);
632 return symbuf[symbuf_idx++].n_strx + stringtab_global;
635 /* Initializes storage for all of the partial symbols that will be
636 created by read_dbx_symtab and subsidiaries. */
639 init_psymbol_list (total_symbols)
642 /* Free any previously allocated psymbol lists. */
643 if (global_psymbols.list)
644 free (global_psymbols.list);
645 if (static_psymbols.list)
646 free (static_psymbols.list);
648 /* Current best guess is that there are approximately a twentieth
649 of the total symbols (in a debugging file) are global or static
651 global_psymbols.size = total_symbols / 10;
652 static_psymbols.size = total_symbols / 10;
653 global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
654 xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
655 static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
656 xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
659 /* Initialize the list of bincls to contain none and have some
663 init_bincl_list (number)
666 bincls_allocated = number;
667 next_bincl = bincl_list = (struct header_file_location *)
668 xmalloc (bincls_allocated * sizeof(struct header_file_location));
671 /* Add a bincl to the list. */
674 add_bincl_to_list (pst, name, instance)
675 struct partial_symtab *pst;
679 if (next_bincl >= bincl_list + bincls_allocated)
681 int offset = next_bincl - bincl_list;
682 bincls_allocated *= 2;
683 bincl_list = (struct header_file_location *)
684 xrealloc ((char *)bincl_list,
685 bincls_allocated * sizeof (struct header_file_location));
686 next_bincl = bincl_list + offset;
688 next_bincl->pst = pst;
689 next_bincl->instance = instance;
690 next_bincl++->name = name;
693 /* Given a name, value pair, find the corresponding
694 bincl in the list. Return the partial symtab associated
695 with that header_file_location. */
697 static struct partial_symtab *
698 find_corresponding_bincl_psymtab (name, instance)
702 struct header_file_location *bincl;
704 for (bincl = bincl_list; bincl < next_bincl; bincl++)
705 if (bincl->instance == instance
706 && !strcmp (name, bincl->name))
709 return (struct partial_symtab *) 0;
712 /* Free the storage allocated for the bincl list. */
718 bincls_allocated = 0;
721 static struct partial_symtab *start_psymtab ();
722 static void end_psymtab();
725 /* This is normally a macro defined in read_dbx_symtab, but this
726 is a lot easier to debug. */
728 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, PLIST, VALUE)
731 enum namespace NAMESPACE;
732 enum address_class CLASS;
733 struct psymbol_allocation_list *PLIST;
736 register struct partial_symbol *psym;
741 (LIST).list + (LIST).size)
743 (LIST).list = (struct partial_symbol *)
744 xrealloc ((LIST).list,
746 * sizeof (struct partial_symbol)));
747 /* Next assumes we only went one over. Should be good if
748 program works correctly */
750 (LIST).list + (LIST).size;
753 psym = (LIST).next++;
756 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack,
758 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH));
759 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0';
760 SYMBOL_NAMESPACE (psym) = (NAMESPACE);
761 SYMBOL_CLASS (psym) = (CLASS);
762 SYMBOL_VALUE (psym) = (VALUE);
766 /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
767 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
768 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
772 /* Given pointers to an a.out symbol table in core containing dbx
773 style data, setup partial_symtab's describing each source file for
774 which debugging information is available. NLISTLEN is the number
775 of symbols in the symbol table. All symbol names are given as
776 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
777 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
778 and ADDR is its relocated address (if incremental) or 0 (if not). */
781 read_dbx_symtab (symfile_name, addr,
782 desc, stringtab, stringtab_size, nlistlen,
783 text_addr, text_size)
787 register char *stringtab;
788 register long stringtab_size;
789 register int nlistlen;
793 register struct internal_nlist *bufp;
794 register char *namestring;
795 register struct partial_symbol *psym;
797 int past_first_source_file = 0;
798 CORE_ADDR last_o_file_start = 0;
799 struct cleanup *old_chain;
802 /* End of the text segment of the executable file. */
803 CORE_ADDR end_of_text_addr;
805 /* Current partial symtab */
806 struct partial_symtab *pst;
808 /* List of current psymtab's include files */
809 char **psymtab_include_list;
810 int includes_allocated;
813 /* Index within current psymtab dependency list */
814 struct partial_symtab **dependency_list;
815 int dependencies_used, dependencies_allocated;
817 stringtab_global = stringtab;
819 pst = (struct partial_symtab *) 0;
821 includes_allocated = 30;
823 psymtab_include_list = (char **) alloca (includes_allocated *
826 dependencies_allocated = 30;
827 dependencies_used = 0;
829 (struct partial_symtab **) alloca (dependencies_allocated *
830 sizeof (struct partial_symtab *));
832 /* FIXME!! If an error occurs, this blows away the whole symbol table!
833 It should only blow away the psymtabs created herein. We could
834 be reading a shared library or a dynloaded file! */
835 old_chain = make_cleanup (free_all_psymtabs, 0);
837 /* Init bincl list */
838 init_bincl_list (20);
839 make_cleanup (free_bincl_list, 0);
841 last_source_file = 0;
843 #ifdef END_OF_TEXT_DEFAULT
844 end_of_text_addr = END_OF_TEXT_DEFAULT;
846 end_of_text_addr = text_addr + addr + text_size; /* Relocate */
849 symtab_input_desc = desc; /* This is needed for fill_symbuf below */
850 symbuf_end = symbuf_idx = 0;
852 for (symnum = 0; symnum < nlistlen; symnum++)
854 /* Get the symbol for this run and pull out some info */
855 QUIT; /* allow this to be interruptable */
856 if (symbuf_idx == symbuf_end)
858 bufp = &symbuf[symbuf_idx++];
861 * Special case to speed up readin.
863 if (bufp->n_type == (unsigned char)N_SLINE) continue;
867 /* Ok. There is a lot of code duplicated in the rest of this
868 switch statement (for efficiency reasons). Since I don't
869 like duplicating code, I will do my penance here, and
870 describe the code which is duplicated:
872 *) The assignment to namestring.
873 *) The call to strchr.
874 *) The addition of a partial symbol the the two partial
875 symbol lists. This last is a large section of code, so
876 I've imbedded it in the following macro.
879 /* Set namestring based on bufp. If the string table index is invalid,
880 give a fake name, and print a single error message per symbol file read,
881 rather than abort the symbol reading or flood the user with messages. */
882 #define SET_NAMESTRING()\
883 if (bufp->n_strx < 0 || bufp->n_strx >= stringtab_size) { \
884 complain (&string_table_offset_complaint, symnum); \
885 namestring = "foo"; \
887 namestring = bufp->n_strx + stringtab
889 /* Add a symbol with an integer value to a psymtab. */
890 /* This is a macro unless we're debugging. See above this function. */
892 # define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
893 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
897 /* Add a symbol with a CORE_ADDR value to a psymtab. */
898 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
899 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
900 SYMBOL_VALUE_ADDRESS)
902 /* Add any kind of symbol to a psymtab. */
903 #define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
906 (LIST).list + (LIST).size) \
908 (LIST).list = (struct partial_symbol *) \
909 xrealloc ((LIST).list, \
911 * sizeof (struct partial_symbol))); \
912 /* Next assumes we only went one over. Should be good if \
913 program works correctly */ \
915 (LIST).list + (LIST).size; \
918 psym = (LIST).next++; \
920 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
922 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
923 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
924 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
925 SYMBOL_CLASS (psym) = (CLASS); \
926 VT (psym) = (VALUE); \
929 /* End of macro definitions, now let's handle them symbols! */
931 switch (bufp->n_type)
934 * Standard, external, non-debugger, symbols
938 case N_NBTEXT | N_EXT:
939 case N_NBDATA | N_EXT:
940 case N_NBBSS | N_EXT:
946 bufp->n_value += addr; /* Relocate */
951 record_misc_function (namestring, bufp->n_value,
952 bufp->n_type); /* Always */
956 /* Standard, local, non-debugger, symbols */
960 /* We need to be able to deal with both N_FN or N_TEXT,
961 because we have no way of knowing whether the sys-supplied ld
962 or GNU ld was used to make the executable. Sequents throw
963 in another wrinkle -- they renumbered N_FN. */
967 bufp->n_value += addr; /* Relocate */
969 if ((namestring[0] == '-' && namestring[1] == 'l')
970 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
971 && namestring [nsl - 2] == '.'))
973 if (entry_point < bufp->n_value
974 && entry_point >= last_o_file_start
975 && addr == 0) /* FIXME nogood nomore */
977 startup_file_start = last_o_file_start;
978 startup_file_end = bufp->n_value;
980 if (past_first_source_file && pst
981 /* The gould NP1 uses low values for .o and -l symbols
982 which are not the address. */
983 && bufp->n_value > pst->textlow)
985 end_psymtab (pst, psymtab_include_list, includes_used,
986 symnum * symbol_size, bufp->n_value,
987 dependency_list, dependencies_used,
988 global_psymbols.next, static_psymbols.next);
989 pst = (struct partial_symtab *) 0;
991 dependencies_used = 0;
994 past_first_source_file = 1;
995 last_o_file_start = bufp->n_value;
1000 bufp->n_value += addr; /* Relocate */
1002 /* Check for __DYNAMIC, which is used by Sun shared libraries.
1003 Record it even if it's local, not global, so we can find it.
1004 Same with virtual function tables, both global and static. */
1005 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
1006 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
1008 /* Not really a function here, but... */
1009 record_misc_function (namestring, bufp->n_value,
1010 bufp->n_type); /* Always */
1014 case N_UNDF | N_EXT:
1015 if (bufp->n_value != 0) {
1016 /* This is a "Fortran COMMON" symbol. See if the target
1017 environment knows where it has been relocated to. */
1022 if (target_lookup_symbol (namestring, &reladdr)) {
1023 continue; /* Error in lookup; ignore symbol for now. */
1025 bufp->n_type ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
1026 bufp->n_value = reladdr;
1027 goto bss_ext_symbol;
1029 continue; /* Just undefined, not COMMON */
1031 /* Lots of symbol types we can just ignore. */
1040 /* Keep going . . .*/
1043 * Special symbol types for GNU
1046 case N_INDR | N_EXT:
1048 case N_SETA | N_EXT:
1050 case N_SETT | N_EXT:
1052 case N_SETD | N_EXT:
1054 case N_SETB | N_EXT:
1063 unsigned long valu = bufp->n_value;
1064 /* Symbol number of the first symbol of this file (i.e. the N_SO
1065 if there is just one, or the first if we have a pair). */
1066 int first_symnum = symnum;
1068 /* End the current partial symtab and start a new one */
1072 /* Peek at the next symbol. If it is also an N_SO, the
1073 first one just indicates the directory. */
1074 if (symbuf_idx == symbuf_end)
1076 bufp = &symbuf[symbuf_idx];
1077 /* n_type is only a char, so swapping swapping is irrelevant. */
1078 if (bufp->n_type == (unsigned char)N_SO)
1082 valu = bufp->n_value;
1086 valu += addr; /* Relocate */
1088 if (pst && past_first_source_file)
1090 end_psymtab (pst, psymtab_include_list, includes_used,
1091 first_symnum * symbol_size, valu,
1092 dependency_list, dependencies_used,
1093 global_psymbols.next, static_psymbols.next);
1094 pst = (struct partial_symtab *) 0;
1096 dependencies_used = 0;
1099 past_first_source_file = 1;
1101 pst = start_psymtab (symfile_name, addr,
1103 first_symnum * symbol_size,
1104 global_psymbols.next, static_psymbols.next);
1109 /* Add this bincl to the bincl_list for future EXCLs. No
1110 need to save the string; it'll be around until
1111 read_dbx_symtab function returns */
1115 add_bincl_to_list (pst, namestring, bufp->n_value);
1117 /* Mark down an include file in the current psymtab */
1119 psymtab_include_list[includes_used++] = namestring;
1120 if (includes_used >= includes_allocated)
1122 char **orig = psymtab_include_list;
1124 psymtab_include_list = (char **)
1125 alloca ((includes_allocated *= 2) *
1127 bcopy (orig, psymtab_include_list,
1128 includes_used * sizeof (char *));
1134 /* Mark down an include file in the current psymtab */
1138 /* In C++, one may expect the same filename to come round many
1139 times, when code is coming alternately from the main file
1140 and from inline functions in other files. So I check to see
1141 if this is a file we've seen before -- either the main
1142 source file, or a previously included file.
1144 This seems to be a lot of time to be spending on N_SOL, but
1145 things like "break c-exp.y:435" need to work (I
1146 suppose the psymtab_include_list could be hashed or put
1147 in a binary tree, if profiling shows this is a major hog). */
1148 if (pst && !strcmp (namestring, pst->filename))
1152 for (i = 0; i < includes_used; i++)
1153 if (!strcmp (namestring, psymtab_include_list[i]))
1162 psymtab_include_list[includes_used++] = namestring;
1163 if (includes_used >= includes_allocated)
1165 char **orig = psymtab_include_list;
1167 psymtab_include_list = (char **)
1168 alloca ((includes_allocated *= 2) *
1170 bcopy (orig, psymtab_include_list,
1171 includes_used * sizeof (char *));
1175 case N_LSYM: /* Typedef or automatic variable. */
1176 case N_STSYM: /* Data seg var -- static */
1177 case N_LCSYM: /* BSS " */
1178 case N_NBSTS: /* Gould nobase. */
1179 case N_NBLCS: /* symbols. */
1183 p = (char *) strchr (namestring, ':');
1185 /* Skip if there is no :. */
1191 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1192 STRUCT_NAMESPACE, LOC_TYPEDEF,
1193 static_psymbols, bufp->n_value);
1196 /* Also a typedef with the same name. */
1197 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1198 VAR_NAMESPACE, LOC_TYPEDEF,
1199 static_psymbols, bufp->n_value);
1204 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1205 VAR_NAMESPACE, LOC_TYPEDEF,
1206 static_psymbols, bufp->n_value);
1208 /* If this is an enumerated type, we need to
1209 add all the enum constants to the partial symbol
1210 table. This does not cover enums without names, e.g.
1211 "enum {a, b} c;" in C, but fortunately those are
1212 rare. There is no way for GDB to find those from the
1213 enum type without spending too much time on it. Thus
1214 to solve this problem, the compiler needs to put out separate
1215 constant symbols ('c' N_LSYMS) for enum constants in
1216 enums without names, or put out a dummy type. */
1218 /* We are looking for something of the form
1219 <name> ":" ("t" | "T") [<number> "="] "e"
1220 {<constant> ":" <value> ","} ";". */
1222 /* Skip over the colon and the 't' or 'T'. */
1224 /* This type may be given a number. Skip over it. */
1225 while ((*p >= '0' && *p <= '9')
1231 /* We have found an enumerated type. */
1232 /* According to comments in read_enum_type
1233 a comma could end it instead of a semicolon.
1234 I don't know where that happens.
1236 while (*p && *p != ';' && *p != ',')
1240 /* Check for and handle cretinous dbx symbol name
1243 p = next_symbol_text ();
1245 /* Point to the character after the name
1246 of the enum constant. */
1247 for (q = p; *q && *q != ':'; q++)
1249 /* Note that the value doesn't matter for
1250 enum constants in psymtabs, just in symtabs. */
1251 ADD_PSYMBOL_TO_LIST (p, q - p,
1252 VAR_NAMESPACE, LOC_CONST,
1253 static_psymbols, 0);
1254 /* Point past the name. */
1256 /* Skip over the value. */
1257 while (*p && *p != ',')
1259 /* Advance past the comma. */
1267 /* Constant, e.g. from "const" in Pascal. */
1268 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1269 VAR_NAMESPACE, LOC_CONST,
1270 static_psymbols, bufp->n_value);
1273 /* Skip if the thing following the : is
1274 not a letter (which indicates declaration of a local
1275 variable, which we aren't interested in). */
1280 case N_GSYM: /* Global (extern) variable; can be
1281 data or bss (sigh). */
1283 /* Following may probably be ignored; I'll leave them here
1284 for now (until I do Pascal and Modula 2 extensions). */
1286 case N_PC: /* I may or may not need this; I
1288 case N_M2C: /* I suspect that I can ignore this here. */
1289 case N_SCOPE: /* Same. */
1293 p = (char *) strchr (namestring, ':');
1295 continue; /* Not a debugging symbol. */
1299 /* Main processing section for debugging symbols which
1300 the initial read through the symbol tables needs to worry
1301 about. If we reach this point, the symbol which we are
1302 considering is definitely one we are interested in.
1303 p must also contain the (valid) index into the namestring
1304 which indicates the debugging type symbol. */
1309 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1310 VAR_NAMESPACE, LOC_CONST,
1311 static_psymbols, bufp->n_value);
1314 bufp->n_value += addr; /* Relocate */
1315 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
1316 VAR_NAMESPACE, LOC_STATIC,
1317 static_psymbols, bufp->n_value);
1320 bufp->n_value += addr; /* Relocate */
1321 /* The addresses in these entries are reported to be
1322 wrong. See the code that reads 'G's for symtabs. */
1323 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
1324 VAR_NAMESPACE, LOC_STATIC,
1325 global_psymbols, bufp->n_value);
1329 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1330 VAR_NAMESPACE, LOC_TYPEDEF,
1331 static_psymbols, bufp->n_value);
1335 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1336 VAR_NAMESPACE, LOC_BLOCK,
1337 static_psymbols, bufp->n_value);
1340 /* Global functions were ignored here, but now they
1341 are put into the global psymtab like one would expect.
1342 They're also in the misc fn vector...
1343 FIXME, why did it used to ignore these? That broke
1344 "i fun" on these functions. */
1346 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
1347 VAR_NAMESPACE, LOC_BLOCK,
1348 global_psymbols, bufp->n_value);
1351 /* Two things show up here (hopefully); static symbols of
1352 local scope (static used inside braces) or extensions
1353 of structure symbols. We can ignore both. */
1369 /* Unexpected symbol. Ignore it; perhaps it is an extension
1370 that we don't know about.
1372 Someone says sun cc puts out symbols like
1373 /foo/baz/maclib::/usr/local/bin/maclib,
1374 which would get here with a symbol type of ':'. */
1382 /* Find the corresponding bincl and mark that psymtab on the
1383 psymtab dependency list */
1385 struct partial_symtab *needed_pst =
1386 find_corresponding_bincl_psymtab (namestring, bufp->n_value);
1388 /* If this include file was defined earlier in this file,
1390 if (needed_pst == pst) continue;
1397 for (i = 0; i < dependencies_used; i++)
1398 if (dependency_list[i] == needed_pst)
1404 /* If it's already in the list, skip the rest. */
1405 if (found) continue;
1407 dependency_list[dependencies_used++] = needed_pst;
1408 if (dependencies_used >= dependencies_allocated)
1410 struct partial_symtab **orig = dependency_list;
1412 (struct partial_symtab **)
1413 alloca ((dependencies_allocated *= 2)
1414 * sizeof (struct partial_symtab *));
1415 bcopy (orig, dependency_list,
1417 * sizeof (struct partial_symtab *)));
1419 fprintf (stderr, "Had to reallocate dependency list.\n");
1420 fprintf (stderr, "New dependencies allocated: %d\n",
1421 dependencies_allocated);
1426 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
1434 case N_SSYM: /* Claim: Structure or union element.
1435 Hopefully, I can ignore this. */
1436 case N_ENTRY: /* Alternate entry point; can ignore. */
1437 case N_MAIN: /* Can definitely ignore this. */
1438 case N_CATCH: /* These are GNU C++ extensions */
1439 case N_EHDECL: /* that can safely be ignored here. */
1450 case N_NSYMS: /* Ultrix 4.0: symbol count */
1451 case N_DEFD: /* GNU Modula-2 */
1452 /* These symbols aren't interesting; don't worry about them */
1457 /* If we haven't found it yet, ignore it. It's probably some
1458 new type we don't know about yet. */
1459 complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
1464 /* If there's stuff to be cleaned up, clean it up. */
1465 if (nlistlen > 0 /* We have some syms */
1466 && entry_point < bufp->n_value
1467 && entry_point >= last_o_file_start)
1469 startup_file_start = last_o_file_start;
1470 startup_file_end = bufp->n_value;
1475 end_psymtab (pst, psymtab_include_list, includes_used,
1476 symnum * symbol_size, end_of_text_addr,
1477 dependency_list, dependencies_used,
1478 global_psymbols.next, static_psymbols.next);
1480 dependencies_used = 0;
1481 pst = (struct partial_symtab *) 0;
1485 discard_cleanups (old_chain);
1488 /* Allocate and partially fill a partial symtab. It will be
1489 completely filled at the end of the symbol list.
1491 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1492 is the address relative to which its symbols are (incremental) or 0
1496 static struct partial_symtab *
1497 start_psymtab (symfile_name, addr,
1498 filename, textlow, ldsymoff, global_syms, static_syms)
1504 struct partial_symbol *global_syms;
1505 struct partial_symbol *static_syms;
1507 struct partial_symtab *result =
1508 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
1509 sizeof (struct partial_symtab));
1511 result->addr = addr;
1513 result->symfile_name =
1514 (char *) obstack_alloc (psymbol_obstack,
1515 strlen (symfile_name) + 1);
1516 strcpy (result->symfile_name, symfile_name);
1519 (char *) obstack_alloc (psymbol_obstack,
1520 strlen (filename) + 1);
1521 strcpy (result->filename, filename);
1523 result->textlow = textlow;
1524 result->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
1525 sizeof (struct symloc));
1526 LDSYMOFF(result) = ldsymoff;
1530 result->read_symtab = dbx_psymtab_to_symtab;
1532 result->globals_offset = global_syms - global_psymbols.list;
1533 result->statics_offset = static_syms - static_psymbols.list;
1535 result->n_global_syms = 0;
1536 result->n_static_syms = 0;
1543 compare_psymbols (s1, s2)
1544 register struct partial_symbol *s1, *s2;
1547 *st1 = SYMBOL_NAME (s1),
1548 *st2 = SYMBOL_NAME (s2);
1550 if (st1[0] - st2[0])
1551 return st1[0] - st2[0];
1552 if (st1[1] - st2[1])
1553 return st1[1] - st2[1];
1554 return strcmp (st1 + 1, st2 + 1);
1558 /* Close off the current usage of a partial_symbol table entry. This
1559 involves setting the correct number of includes (with a realloc),
1560 setting the high text mark, setting the symbol length in the
1561 executable, and setting the length of the global and static lists
1564 The global symbols and static symbols are then seperately sorted.
1566 Then the partial symtab is put on the global list.
1567 *** List variables and peculiarities of same. ***
1570 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
1571 capping_text, dependency_list, number_dependencies,
1572 capping_global, capping_static)
1573 struct partial_symtab *pst;
1574 char **include_list;
1576 int capping_symbol_offset;
1577 CORE_ADDR capping_text;
1578 struct partial_symtab **dependency_list;
1579 int number_dependencies;
1580 struct partial_symbol *capping_global, *capping_static;
1584 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
1585 pst->texthigh = capping_text;
1587 pst->n_global_syms =
1588 capping_global - (global_psymbols.list + pst->globals_offset);
1589 pst->n_static_syms =
1590 capping_static - (static_psymbols.list + pst->statics_offset);
1592 pst->number_of_dependencies = number_dependencies;
1593 if (number_dependencies)
1595 pst->dependencies = (struct partial_symtab **)
1596 obstack_alloc (psymbol_obstack,
1597 number_dependencies * sizeof (struct partial_symtab *));
1598 bcopy (dependency_list, pst->dependencies,
1599 number_dependencies * sizeof (struct partial_symtab *));
1602 pst->dependencies = 0;
1604 for (i = 0; i < num_includes; i++)
1606 /* Eventually, put this on obstack */
1607 struct partial_symtab *subpst =
1608 (struct partial_symtab *)
1609 obstack_alloc (psymbol_obstack,
1610 sizeof (struct partial_symtab));
1613 (char *) obstack_alloc (psymbol_obstack,
1614 strlen (include_list[i]) + 1);
1615 strcpy (subpst->filename, include_list[i]);
1617 subpst->symfile_name = pst->symfile_name;
1618 subpst->addr = pst->addr;
1619 subpst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
1620 sizeof (struct symloc));
1624 subpst->texthigh = 0;
1626 /* We could save slight bits of space by only making one of these,
1627 shared by the entire set of include files. FIXME-someday. */
1628 subpst->dependencies = (struct partial_symtab **)
1629 obstack_alloc (psymbol_obstack,
1630 sizeof (struct partial_symtab *));
1631 subpst->dependencies[0] = pst;
1632 subpst->number_of_dependencies = 1;
1634 subpst->globals_offset =
1635 subpst->n_global_syms =
1636 subpst->statics_offset =
1637 subpst->n_static_syms = 0;
1641 subpst->read_symtab = dbx_psymtab_to_symtab;
1643 subpst->next = partial_symtab_list;
1644 partial_symtab_list = subpst;
1647 /* Sort the global list; don't sort the static list */
1648 qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
1649 sizeof (struct partial_symbol), compare_psymbols);
1651 /* If there is already a psymtab or symtab for a file of this name, remove it.
1652 (If there is a symtab, more drastic things also happen.)
1653 This happens in VxWorks. */
1654 free_named_symtabs (pst->filename);
1656 /* Put the psymtab on the psymtab list */
1657 pst->next = partial_symtab_list;
1658 partial_symtab_list = pst;
1662 psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
1663 struct partial_symtab *pst;
1669 struct cleanup *old_chain;
1677 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1682 /* Read in all partial symtabs on which this one is dependent */
1683 for (i = 0; i < pst->number_of_dependencies; i++)
1684 if (!pst->dependencies[i]->readin)
1686 /* Inform about additional files that need to be read in. */
1689 fputs_filtered (" ", stdout);
1691 fputs_filtered ("and ", stdout);
1693 printf_filtered ("%s...", pst->dependencies[i]->filename);
1694 wrap_here (""); /* Flush output */
1697 psymtab_to_symtab_1 (pst->dependencies[i], desc,
1698 stringtab, stringtab_size, sym_offset);
1701 if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
1703 /* Init stuff necessary for reading in symbols */
1705 old_chain = make_cleanup (really_free_pendings, 0);
1707 /* Read in this files symbols */
1708 lseek (desc, sym_offset, L_SET);
1710 read_ofile_symtab (desc, stringtab, stringtab_size,
1712 LDSYMLEN(pst), pst->textlow,
1713 pst->texthigh - pst->textlow, pst->addr);
1714 sort_symtab_syms (pst->symtab);
1716 do_cleanups (old_chain);
1723 * Read in all of the symbols for a given psymtab for real.
1724 * Be verbose about it if the user wants that.
1727 dbx_psymtab_to_symtab (pst)
1728 struct partial_symtab *pst;
1733 struct stat statbuf;
1734 struct cleanup *old_chain;
1743 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1748 if (LDSYMLEN(pst) || pst->number_of_dependencies)
1750 /* Print the message now, before reading the string table,
1751 to avoid disconcerting pauses. */
1754 printf_filtered ("Reading in symbols for %s...", pst->filename);
1758 /* Open symbol file and read in string table. Symbol_file_command
1759 guarantees that the symbol file name will be absolute, so there is
1760 no need for openp. */
1761 desc = open(pst->symfile_name, O_RDONLY, 0);
1764 perror_with_name (pst->symfile_name);
1766 sym_bfd = bfd_fdopenr (pst->symfile_name, NULL, desc);
1770 error ("Could not open `%s' to read symbols: %s",
1771 pst->symfile_name, bfd_errmsg (bfd_error));
1773 old_chain = make_cleanup (bfd_close, sym_bfd);
1774 if (!bfd_check_format (sym_bfd, bfd_object))
1775 error ("\"%s\": can't read symbols: %s.",
1776 pst->symfile_name, bfd_errmsg (bfd_error));
1778 /* We keep the string table for symfile resident in memory, but
1779 not the string table for any other symbol files. */
1780 if ((symfile == 0) || 0 != strcmp(pst->symfile_name, symfile))
1782 /* Read in the string table */
1784 /* FIXME, this uses internal BFD variables. See above in
1785 dbx_symbol_file_open where the macro is defined! */
1786 lseek (desc, STRING_TABLE_OFFSET, L_SET);
1788 val = myread (desc, &st_temp, sizeof st_temp);
1790 perror_with_name (pst->symfile_name);
1791 stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
1792 if (fstat (desc, &statbuf) < 0)
1793 perror_with_name (pst->symfile_name);
1795 if (stsize >= 0 && stsize < statbuf.st_size)
1797 #ifdef BROKEN_LARGE_ALLOCA
1798 stringtab = (char *) xmalloc (stsize);
1799 make_cleanup (free, stringtab);
1801 stringtab = (char *) alloca (stsize);
1806 if (stringtab == NULL && stsize != 0)
1807 error ("ridiculous string table size: %d bytes", stsize);
1809 /* FIXME, this uses internal BFD variables. See above in
1810 dbx_symbol_file_open where the macro is defined! */
1811 val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
1813 perror_with_name (pst->symfile_name);
1814 val = myread (desc, stringtab, stsize);
1816 perror_with_name (pst->symfile_name);
1820 stringtab = symfile_string_table;
1821 stsize = symfile_string_table_size;
1824 symfile_bfd = sym_bfd; /* Kludge for SWAP_SYMBOL */
1825 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1826 symbol_size = obj_symbol_entry_size (sym_bfd);
1828 /* FIXME, this uses internal BFD variables. See above in
1829 dbx_symbol_file_open where the macro is defined! */
1830 psymtab_to_symtab_1 (pst, desc, stringtab, stsize,
1831 SYMBOL_TABLE_OFFSET);
1833 /* Match with global symbols. This only needs to be done once,
1834 after all of the symtabs and dependencies have been read in. */
1835 scan_file_globals ();
1837 do_cleanups (old_chain);
1839 /* Finish up the debug error message. */
1841 printf_filtered ("done.\n");
1845 /* Process a pair of symbols. Currently they must both be N_SO's. */
1848 process_symbol_pair (type1, desc1, value1, name1,
1849 type2, desc2, value2, name2)
1859 /* No need to check PCC_SOL_BROKEN, on the assumption that such
1860 broken PCC's don't put out N_SO pairs. */
1861 if (last_source_file)
1862 (void)end_symtab (value2, 0, 0);
1863 start_symtab (name2, name1, value2);
1867 * Read in a defined section of a specific object file's symbols.
1869 * DESC is the file descriptor for the file, positioned at the
1870 * beginning of the symtab
1871 * STRINGTAB is a pointer to the files string
1872 * table, already read in
1873 * SYM_OFFSET is the offset within the file of
1874 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
1875 * number of symbols to read
1876 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1877 * TEXT_SIZE is the size of the text segment read in.
1878 * OFFSET is a relocation offset which gets added to each symbol
1881 static struct symtab *
1882 read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
1883 sym_size, text_offset, text_size, offset)
1885 register char *stringtab;
1886 unsigned int stringtab_size;
1889 CORE_ADDR text_offset;
1893 register char *namestring;
1894 struct internal_nlist *bufp;
1896 unsigned max_symnum;
1899 stringtab_global = stringtab;
1900 last_source_file = 0;
1902 symtab_input_desc = desc;
1903 symbuf_end = symbuf_idx = 0;
1905 /* It is necessary to actually read one symbol *before* the start
1906 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1907 occurs before the N_SO symbol.
1909 Detecting this in read_dbx_symtab
1910 would slow down initial readin, so we look for it here instead. */
1911 if (sym_offset >= (int)symbol_size)
1913 lseek (desc, sym_offset - symbol_size, L_INCR);
1915 bufp = &symbuf[symbuf_idx++];
1920 processing_gcc_compilation =
1921 (bufp->n_type == N_TEXT
1922 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
1923 /* FIXME!!! Check for gcc2_compiled... */
1927 /* The N_SO starting this symtab is the first symbol, so we
1928 better not check the symbol before it. I'm not this can
1929 happen, but it doesn't hurt to check for it. */
1930 lseek(desc, sym_offset, L_INCR);
1931 processing_gcc_compilation = 0;
1934 if (symbuf_idx == symbuf_end)
1936 bufp = &symbuf[symbuf_idx];
1937 if (bufp->n_type != (unsigned char)N_SO)
1938 error("First symbol in segment of executable not a source symbol");
1940 max_symnum = sym_size / symbol_size;
1943 symnum < max_symnum;
1946 QUIT; /* Allow this to be interruptable */
1947 if (symbuf_idx == symbuf_end)
1949 bufp = &symbuf[symbuf_idx++];
1952 type = bufp->n_type;
1953 if (type == (unsigned char)N_CATCH)
1955 /* N_CATCH is not fixed up by the linker, and unfortunately,
1956 there's no other place to put it in the .stab map. */
1957 bufp->n_value += text_offset + offset;
1960 type &= ~N_EXT; /* Ignore external-bit */
1961 if (type == N_TEXT || type == N_DATA || type == N_BSS)
1962 bufp->n_value += offset;
1963 type = bufp->n_type;
1970 short bufp_n_desc = bufp->n_desc;
1971 unsigned long valu = bufp->n_value;
1973 /* Check for a pair of N_SO symbols. */
1974 if (type == (unsigned char)N_SO)
1976 if (symbuf_idx == symbuf_end)
1978 bufp = &symbuf[symbuf_idx];
1979 if (bufp->n_type == (unsigned char)N_SO)
1981 char *namestring1 = namestring;
1984 bufp->n_value += offset; /* Relocate */
1989 process_symbol_pair (N_SO, bufp_n_desc, valu, namestring1,
1990 N_SO, bufp->n_desc, bufp->n_value,
1994 process_one_symbol(type, bufp_n_desc, valu, namestring);
1997 process_one_symbol (type, bufp_n_desc, valu, namestring);
1999 /* We skip checking for a new .o or -l file; that should never
2000 happen in this routine. */
2001 else if (type == N_TEXT
2002 && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
2003 /* I don't think this code will ever be executed, because
2004 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2005 the N_SO symbol which starts this source file.
2006 However, there is no reason not to accept
2007 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2008 processing_gcc_compilation = 1;
2009 else if (type & N_EXT || type == (unsigned char)N_TEXT
2010 || type == (unsigned char)N_NBTEXT
2012 /* Global symbol: see if we came across a dbx defintion for
2013 a corresponding symbol. If so, store the value. Remove
2014 syms from the chain when their values are stored, but
2015 search the whole chain, as there may be several syms from
2016 different files with the same name. */
2017 /* This is probably not true. Since the files will be read
2018 in one at a time, each reference to a global symbol will
2019 be satisfied in each file as it appears. So we skip this
2025 return end_symtab (text_offset + text_size, 0, 0);
2032 register char *p = name;
2033 register int total = p[0];
2046 /* Ensure result is positive. */
2047 if (total < 0) total += (1000 << 6);
2048 return total % HASHSIZE;
2053 process_one_symbol (type, desc, valu, name)
2058 #ifndef SUN_FIXED_LBRAC_BUG
2059 /* This records the last pc address we've seen. We depend on their being
2060 an SLINE or FUN or SO before the first LBRAC, since the variable does
2061 not get reset in between reads of different symbol files. */
2062 static CORE_ADDR last_pc_address;
2064 register struct context_stack *new;
2067 /* Something is wrong if we see real data before
2068 seeing a source file name. */
2070 if (last_source_file == 0 && type != (unsigned char)N_SO)
2072 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
2073 where that code is defined. */
2074 if (IGNORE_SYMBOL (type))
2077 /* FIXME, this should not be an error, since it precludes extending
2078 the symbol table information in this way... */
2079 error ("Invalid symbol data: does not start by identifying a source file.");
2086 /* Either of these types of symbols indicates the start of
2087 a new function. We must process its "name" normally for dbx,
2088 but also record the start of a new lexical context, and possibly
2089 also the end of the lexical context for the previous function. */
2090 /* This is not always true. This type of symbol may indicate a
2091 text segment variable. */
2093 #ifndef SUN_FIXED_LBRAC_BUG
2094 last_pc_address = valu; /* Save for SunOS bug circumcision */
2097 colon_pos = strchr (name, ':');
2099 || (*colon_pos != 'f' && *colon_pos != 'F'))
2101 define_symbol (valu, name, desc, type);
2105 within_function = 1;
2106 if (context_stack_depth > 0)
2108 new = &context_stack[--context_stack_depth];
2109 /* Make a block for the local symbols within. */
2110 finish_block (new->name, &local_symbols, new->old_blocks,
2111 new->start_addr, valu);
2113 /* Stack must be empty now. */
2114 if (context_stack_depth != 0)
2115 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
2118 new = &context_stack[context_stack_depth++];
2119 new->old_blocks = pending_blocks;
2120 new->start_addr = valu;
2121 new->name = define_symbol (valu, name, desc, type);
2126 /* Record the address at which this catch takes place. */
2127 define_symbol (valu, name, desc, type);
2131 /* Don't know what to do with these yet. */
2132 error ("action uncertain for eh extensions");
2136 /* This "symbol" just indicates the start of an inner lexical
2137 context within a function. */
2139 #if !defined (BLOCK_ADDRESS_ABSOLUTE)
2140 /* On most machines, the block addresses are relative to the
2141 N_SO, the linker did not relocate them (sigh). */
2142 valu += last_source_start_addr;
2145 #ifndef SUN_FIXED_LBRAC_BUG
2146 if (valu < last_pc_address) {
2147 /* Patch current LBRAC pc value to match last handy pc value */
2148 complain (&lbrac_complaint, 0);
2149 valu = last_pc_address;
2152 if (context_stack_depth == context_stack_size)
2154 context_stack_size *= 2;
2155 context_stack = (struct context_stack *)
2156 xrealloc (context_stack,
2158 * sizeof (struct context_stack)));
2161 new = &context_stack[context_stack_depth++];
2163 new->locals = local_symbols;
2164 new->old_blocks = pending_blocks;
2165 new->start_addr = valu;
2171 /* This "symbol" just indicates the end of an inner lexical
2172 context that was started with N_LBRAC. */
2174 #if !defined (BLOCK_ADDRESS_ABSOLUTE)
2175 /* On most machines, the block addresses are relative to the
2176 N_SO, the linker did not relocate them (sigh). */
2177 valu += last_source_start_addr;
2180 new = &context_stack[--context_stack_depth];
2181 if (desc != new->depth)
2182 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
2184 /* Some compilers put the variable decls inside of an
2185 LBRAC/RBRAC block. This macro should be nonzero if this
2186 is true. DESC is N_DESC from the N_RBRAC symbol.
2187 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */
2188 #if !defined (VARIABLES_INSIDE_BLOCK)
2189 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2192 /* Can only use new->locals as local symbols here if we're in
2193 gcc or on a machine that puts them before the lbrack. */
2194 if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2195 local_symbols = new->locals;
2197 /* If this is not the outermost LBRAC...RBRAC pair in the
2198 function, its local symbols preceded it, and are the ones
2199 just recovered from the context stack. Defined the block for them.
2201 If this is the outermost LBRAC...RBRAC pair, there is no
2202 need to do anything; leave the symbols that preceded it
2203 to be attached to the function's own block. However, if
2204 it is so, we need to indicate that we just moved outside
2207 && (context_stack_depth
2208 > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
2210 /* FIXME Muzzle a compiler bug that makes end < start. */
2211 if (new->start_addr > valu)
2213 complain(&lbrac_rbrac_complaint, 0);
2214 new->start_addr = valu;
2216 /* Make a block for the local symbols within. */
2217 finish_block (0, &local_symbols, new->old_blocks,
2218 new->start_addr, valu);
2222 within_function = 0;
2224 if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
2225 /* Now pop locals of block just finished. */
2226 local_symbols = new->locals;
2231 /* This kind of symbol indicates the start of an object file. */
2235 /* This type of symbol indicates the start of data
2236 for one source file.
2237 Finish the symbol table of the previous source file
2238 (if any) and start accumulating a new symbol table. */
2239 #ifndef SUN_FIXED_LBRAC_BUG
2240 last_pc_address = valu; /* Save for SunOS bug circumcision */
2243 #ifdef PCC_SOL_BROKEN
2244 /* pcc bug, occasionally puts out SO for SOL. */
2245 if (context_stack_depth > 0)
2247 start_subfile (name, NULL);
2251 if (last_source_file)
2252 (void)end_symtab (valu, 0, 0);
2253 start_symtab (name, NULL, valu);
2257 /* This type of symbol indicates the start of data for
2258 a sub-source-file, one whose contents were copied or
2259 included in the compilation of the main source file
2260 (whose name was given in the N_SO symbol.) */
2261 start_subfile (name, NULL);
2266 add_new_header_file (name, valu);
2267 start_subfile (name, NULL);
2271 start_subfile (pop_subfile (), NULL);
2275 add_old_header_file (name, valu);
2279 /* This type of "symbol" really just records
2280 one line-number -- core-address correspondence.
2281 Enter it in the line list for this symbol table. */
2282 #ifndef SUN_FIXED_LBRAC_BUG
2283 last_pc_address = valu; /* Save for SunOS bug circumcision */
2285 record_line (current_subfile, desc, valu);
2290 error ("Invalid symbol data: common within common at symtab pos %d",
2292 common_block = local_symbols;
2293 common_block_i = local_symbols ? local_symbols->nsyms : 0;
2297 /* Symbols declared since the BCOMM are to have the common block
2298 start address added in when we know it. common_block points to
2299 the first symbol after the BCOMM in the local_symbols list;
2300 copy the list and hang it off the symbol for the common block name
2304 struct symbol *sym =
2305 (struct symbol *) xmalloc (sizeof (struct symbol));
2306 bzero (sym, sizeof *sym);
2307 SYMBOL_NAME (sym) = savestring (name, strlen (name));
2308 SYMBOL_CLASS (sym) = LOC_BLOCK;
2309 SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
2310 copy_pending (local_symbols, common_block_i, common_block));
2311 i = hashname (SYMBOL_NAME (sym));
2312 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
2313 global_sym_chain[i] = sym;
2320 case N_DEFD: /* GNU Modula-2 symbol */
2325 define_symbol (valu, name, desc, type);
2329 /* To handle GNU C++ typename abbreviation, we need to be able to
2330 fill in a type's name as soon as space for that type is allocated.
2331 `type_synonym_name' is the name of the type being allocated.
2332 It is cleared as soon as it is used (lest all allocated types
2334 static char *type_synonym_name;
2337 static struct symbol *
2338 define_symbol (valu, string, desc, type)
2344 register struct symbol *sym;
2345 char *p = (char *) strchr (string, ':');
2350 /* Ignore syms with empty names. */
2354 /* Ignore old-style symbols from cc -go */
2358 sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
2360 if (processing_gcc_compilation) {
2361 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
2362 number of bytes occupied by a type or object, which we ignore. */
2363 SYMBOL_LINE(sym) = desc;
2365 SYMBOL_LINE(sym) = 0; /* unknown */
2368 if (string[0] == CPLUS_MARKER)
2370 /* Special GNU C++ names. */
2374 SYMBOL_NAME (sym) = "this";
2376 case 'v': /* $vtbl_ptr_type */
2377 /* Was: SYMBOL_NAME (sym) = "vptr"; */
2380 SYMBOL_NAME (sym) = "eh_throw";
2384 /* This was an anonymous type that was never fixed up. */
2395 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
2396 /* Open-coded bcopy--saves function call time. */
2398 register char *p1 = string;
2399 register char *p2 = SYMBOL_NAME (sym);
2406 /* Determine the type of name being defined. */
2407 /* The Acorn RISC machine's compiler can put out locals that don't
2408 start with "234=" or "(3,4)=", so assume anything other than the
2409 deftypes we know how to handle is a local. */
2410 /* (Peter Watkins @ Computervision)
2411 Handle Sun-style local fortran array types 'ar...' .
2414 if (!strchr ("cfFGpPrStTvVXC", *p))
2419 /* c is a special case, not followed by a type-number.
2420 SYMBOL:c=iVALUE for an integer constant symbol.
2421 SYMBOL:c=rVALUE for a floating constant symbol.
2422 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
2423 e.g. "b:c=e6,0" for "const b = blob1"
2424 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
2428 error ("Invalid symbol data at symtab pos %d.", symnum);
2433 double d = atof (p);
2436 SYMBOL_TYPE (sym) = builtin_type_double;
2438 (char *) obstack_alloc (symbol_obstack, sizeof (double));
2439 bcopy (&d, dbl_valu, sizeof (double));
2440 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
2441 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
2442 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
2447 SYMBOL_TYPE (sym) = builtin_type_int;
2448 SYMBOL_VALUE (sym) = atoi (p);
2449 SYMBOL_CLASS (sym) = LOC_CONST;
2453 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
2454 e.g. "b:c=e6,0" for "const b = blob1"
2455 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
2459 read_type_number (&p, typenums);
2461 error ("Invalid symbol data: no comma in enum const symbol");
2463 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
2464 SYMBOL_VALUE (sym) = atoi (p);
2465 SYMBOL_CLASS (sym) = LOC_CONST;
2469 error ("Invalid symbol data at symtab pos %d.", symnum);
2471 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2472 add_symbol_to_list (sym, &file_symbols);
2476 /* Now usually comes a number that says which data type,
2477 and possibly more stuff to define the type
2478 (all of which is handled by read_type) */
2480 if (deftype == 'p' && *p == 'F')
2481 /* pF is a two-letter code that means a function parameter in Fortran.
2482 The type-number specifies the type of the return value.
2483 Translate it into a pointer-to-function type. */
2487 = lookup_pointer_type (lookup_function_type (read_type (&p)));
2491 struct type *type_read;
2492 synonym = *p == 't';
2497 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
2498 strlen (SYMBOL_NAME (sym)));
2501 type_read = read_type (&p);
2503 if ((deftype == 'F' || deftype == 'f')
2504 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
2507 /* This code doesn't work -- it needs to realloc and can't. */
2508 struct type *new = (struct type *)
2509 obstack_alloc (symbol_obstack, sizeof (struct type));
2511 /* Generate a template for the type of this function. The
2512 types of the arguments will be added as we read the symbol
2514 *new = *lookup_function_type (type_read);
2515 SYMBOL_TYPE(sym) = new;
2516 in_function_type = new;
2518 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
2522 SYMBOL_TYPE (sym) = type_read;
2528 /* The name of a caught exception. */
2529 SYMBOL_CLASS (sym) = LOC_LABEL;
2530 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2531 SYMBOL_VALUE_ADDRESS (sym) = valu;
2532 add_symbol_to_list (sym, &local_symbols);
2536 SYMBOL_CLASS (sym) = LOC_BLOCK;
2537 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2538 add_symbol_to_list (sym, &file_symbols);
2542 SYMBOL_CLASS (sym) = LOC_BLOCK;
2543 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2544 add_symbol_to_list (sym, &global_symbols);
2548 /* For a class G (global) symbol, it appears that the
2549 value is not correct. It is necessary to search for the
2550 corresponding linker definition to find the value.
2551 These definitions appear at the end of the namelist. */
2552 i = hashname (SYMBOL_NAME (sym));
2553 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
2554 global_sym_chain[i] = sym;
2555 SYMBOL_CLASS (sym) = LOC_STATIC;
2556 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2557 add_symbol_to_list (sym, &global_symbols);
2560 /* This case is faked by a conditional above,
2561 when there is no code letter in the dbx data.
2562 Dbx data never actually contains 'l'. */
2564 SYMBOL_CLASS (sym) = LOC_LOCAL;
2565 SYMBOL_VALUE (sym) = valu;
2566 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2567 add_symbol_to_list (sym, &local_symbols);
2571 /* Normally this is a parameter, a LOC_ARG. On the i960, it
2572 can also be a LOC_LOCAL_ARG depending on symbol type. */
2573 #ifndef DBX_PARM_SYMBOL_CLASS
2574 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
2576 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
2577 SYMBOL_VALUE (sym) = valu;
2578 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2580 /* This doesn't work yet. */
2581 add_param_to_type (&in_function_type, sym);
2583 add_symbol_to_list (sym, &local_symbols);
2585 /* If it's gcc-compiled, if it says `short', believe it. */
2586 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
2589 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
2590 /* This macro is defined on machines (e.g. sparc) where
2591 we should believe the type of a PCC 'short' argument,
2592 but shouldn't believe the address (the address is
2593 the address of the corresponding int). Note that
2594 this is only different from the BELIEVE_PCC_PROMOTION
2595 case on big-endian machines.
2597 My guess is that this correction, as opposed to changing
2598 the parameter to an 'int' (as done below, for PCC
2599 on most machines), is the right thing to do
2600 on all machines, but I don't want to risk breaking
2601 something that already works. On most PCC machines,
2602 the sparc problem doesn't come up because the calling
2603 function has to zero the top bytes (not knowing whether
2604 the called function wants an int or a short), so there
2605 is no practical difference between an int and a short
2606 (except perhaps what happens when the GDB user types
2607 "print short_arg = 0x10000;").
2610 actually produces the correct address (we don't need to fix it
2611 up). I made this code adapt so that it will offset the symbol
2612 if it was pointing at an int-aligned location and not
2613 otherwise. This way you can use the same gdb for 4.0.x and
2616 if (0 == SYMBOL_VALUE (sym) % sizeof (int))
2618 if (SYMBOL_TYPE (sym) == builtin_type_char
2619 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
2620 SYMBOL_VALUE (sym) += 3;
2621 else if (SYMBOL_TYPE (sym) == builtin_type_short
2622 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
2623 SYMBOL_VALUE (sym) += 2;
2627 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
2629 /* If PCC says a parameter is a short or a char,
2630 it is really an int. */
2631 if (SYMBOL_TYPE (sym) == builtin_type_char
2632 || SYMBOL_TYPE (sym) == builtin_type_short)
2633 SYMBOL_TYPE (sym) = builtin_type_int;
2634 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
2635 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
2636 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
2639 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
2642 SYMBOL_CLASS (sym) = LOC_REGPARM;
2643 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2644 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2645 add_symbol_to_list (sym, &local_symbols);
2649 SYMBOL_CLASS (sym) = LOC_REGISTER;
2650 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2651 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2652 add_symbol_to_list (sym, &local_symbols);
2656 /* Static symbol at top level of file */
2657 SYMBOL_CLASS (sym) = LOC_STATIC;
2658 SYMBOL_VALUE_ADDRESS (sym) = valu;
2659 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2660 add_symbol_to_list (sym, &file_symbols);
2664 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2665 SYMBOL_VALUE (sym) = valu;
2666 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2667 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
2668 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
2669 TYPE_NAME (SYMBOL_TYPE (sym)) =
2670 obsavestring (SYMBOL_NAME (sym),
2671 strlen (SYMBOL_NAME (sym)));
2672 /* C++ vagaries: we may have a type which is derived from
2673 a base type which did not have its name defined when the
2674 derived class was output. We fill in the derived class's
2675 base part member's name here in that case. */
2676 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
2677 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
2678 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
2681 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
2682 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
2683 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
2684 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
2687 add_symbol_to_list (sym, &file_symbols);
2691 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2692 SYMBOL_VALUE (sym) = valu;
2693 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2694 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
2695 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
2696 TYPE_NAME (SYMBOL_TYPE (sym))
2698 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
2700 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
2701 ? "struct " : "union ")),
2703 add_symbol_to_list (sym, &file_symbols);
2707 register struct symbol *typedef_sym
2708 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
2709 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
2710 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
2712 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2713 SYMBOL_VALUE (typedef_sym) = valu;
2714 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2715 add_symbol_to_list (typedef_sym, &file_symbols);
2720 /* Static symbol of local scope */
2721 SYMBOL_CLASS (sym) = LOC_STATIC;
2722 SYMBOL_VALUE_ADDRESS (sym) = valu;
2723 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2724 add_symbol_to_list (sym, &local_symbols);
2728 /* Reference parameter */
2729 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2730 SYMBOL_VALUE (sym) = valu;
2731 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2732 add_symbol_to_list (sym, &local_symbols);
2736 /* This is used by Sun FORTRAN for "function result value".
2737 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2738 that Pascal uses it too, but when I tried it Pascal used
2739 "x:3" (local symbol) instead. */
2740 SYMBOL_CLASS (sym) = LOC_LOCAL;
2741 SYMBOL_VALUE (sym) = valu;
2742 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2743 add_symbol_to_list (sym, &local_symbols);
2747 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
2753 /* This would be a good idea, but it doesn't really work. The problem
2754 is that in order to get the virtual context for a particular type,
2755 you need to know the virtual info from all of its basetypes,
2756 and you need to have processed its methods. Since GDB reads
2757 symbols on a file-by-file basis, this means processing the symbols
2758 of all the files that are needed for each baseclass, which
2759 means potentially reading in all the debugging info just to fill
2760 in information we may never need. */
2762 /* This page contains subroutines of read_type. */
2764 /* FOR_TYPE is a struct type defining a virtual function NAME with type
2765 FN_TYPE. The `virtual context' for this virtual function is the
2766 first base class of FOR_TYPE in which NAME is defined with signature
2767 matching FN_TYPE. OFFSET serves as a hash on matches here.
2769 TYPE is the current type in which we are searching. */
2771 static struct type *
2772 virtual_context (for_type, type, name, fn_type, offset)
2773 struct type *for_type, *type;
2775 struct type *fn_type;
2778 struct type *basetype = 0;
2781 if (for_type != type)
2783 /* Check the methods of TYPE. */
2784 /* Need to do a check_stub_type here, but that breaks
2785 things because we can get infinite regress. */
2786 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
2787 if (!strcmp (TYPE_FN_FIELDLIST_NAME (type, i), name))
2791 int j = TYPE_FN_FIELDLIST_LENGTH (type, i);
2792 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
2795 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset-1)
2796 return TYPE_FN_FIELD_FCONTEXT (f, j);
2799 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
2801 basetype = virtual_context (for_type, TYPE_BASECLASS (type, i), name,
2803 if (basetype != for_type)
2810 /* Copy a pending list, used to record the contents of a common
2811 block for later fixup. */
2812 static struct pending *
2813 copy_pending (beg, begi, end)
2814 struct pending *beg, *end;
2817 struct pending *new = 0;
2818 struct pending *next;
2820 for (next = beg; next != 0 && (next != end || begi < end->nsyms);
2821 next = next->next, begi = 0)
2824 for (j = begi; j < next->nsyms; j++)
2825 add_symbol_to_list (next->symbol[j], &new);
2830 /* Register our willingness to decode symbols for SunOS and a.out and
2831 b.out files handled by BFD... */
2832 static struct sym_fns sunos_sym_fns = {"sunOs", 6,
2833 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
2835 static struct sym_fns aout_sym_fns = {"a.out", 5,
2836 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
2838 static struct sym_fns bout_sym_fns = {"b.out", 5,
2839 dbx_new_init, dbx_symfile_init, dbx_symfile_read};
2842 _initialize_dbxread ()
2844 add_symtab_fns(&sunos_sym_fns);
2845 add_symtab_fns(&aout_sym_fns);
2846 add_symtab_fns(&bout_sym_fns);