Home | History | Annotate | Line # | Download | only in gdb
dbxread.c revision 1.1.1.2
      1      1.1  christos /* Read dbx symbol tables and convert to internal format, for GDB.
      2  1.1.1.2  christos    Copyright (C) 1986-2015 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos    This file is part of GDB.
      5      1.1  christos 
      6      1.1  christos    This program is free software; you can redistribute it and/or modify
      7      1.1  christos    it under the terms of the GNU General Public License as published by
      8      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      9      1.1  christos    (at your option) any later version.
     10      1.1  christos 
     11      1.1  christos    This program is distributed in the hope that it will be useful,
     12      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14      1.1  christos    GNU General Public License for more details.
     15      1.1  christos 
     16      1.1  christos    You should have received a copy of the GNU General Public License
     17      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18      1.1  christos 
     19      1.1  christos /* This module provides three functions: dbx_symfile_init,
     20      1.1  christos    which initializes to read a symbol file; dbx_new_init, which
     21      1.1  christos    discards existing cached information when all symbols are being
     22      1.1  christos    discarded; and dbx_symfile_read, which reads a symbol table
     23      1.1  christos    from a file.
     24      1.1  christos 
     25      1.1  christos    dbx_symfile_read only does the minimum work necessary for letting the
     26      1.1  christos    user "name" things symbolically; it does not read the entire symtab.
     27      1.1  christos    Instead, it reads the external and static symbols and puts them in partial
     28      1.1  christos    symbol tables.  When more extensive information is requested of a
     29      1.1  christos    file, the corresponding partial symbol table is mutated into a full
     30      1.1  christos    fledged symbol table by going back and reading the symbols
     31      1.1  christos    for real.  dbx_psymtab_to_symtab() is the function that does this */
     32      1.1  christos 
     33      1.1  christos #include "defs.h"
     34      1.1  christos #if defined(__CYGNUSCLIB__)
     35      1.1  christos #include <sys/types.h>
     36      1.1  christos #include <fcntl.h>
     37      1.1  christos #endif
     38      1.1  christos 
     39      1.1  christos #include "gdb_obstack.h"
     40      1.1  christos #include <sys/stat.h>
     41      1.1  christos #include "symtab.h"
     42      1.1  christos #include "breakpoint.h"
     43      1.1  christos #include "target.h"
     44      1.1  christos #include "gdbcore.h"		/* for bfd stuff */
     45      1.1  christos #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
     46      1.1  christos #include "filenames.h"
     47      1.1  christos #include "objfiles.h"
     48      1.1  christos #include "buildsym.h"
     49      1.1  christos #include "stabsread.h"
     50      1.1  christos #include "gdb-stabs.h"
     51      1.1  christos #include "demangle.h"
     52      1.1  christos #include "complaints.h"
     53      1.1  christos #include "cp-abi.h"
     54      1.1  christos #include "cp-support.h"
     55      1.1  christos #include "psympriv.h"
     56      1.1  christos #include "block.h"
     57      1.1  christos 
     58      1.1  christos #include "aout/aout64.h"
     59      1.1  christos #include "aout/stab_gnu.h"	/* We always use GNU stabs, not
     60      1.1  christos 				   native, now.  */
     61      1.1  christos 
     62      1.1  christos 
     64      1.1  christos /* Key for dbx-associated data.  */
     65      1.1  christos 
     66      1.1  christos const struct objfile_data *dbx_objfile_data_key;
     67      1.1  christos 
     68      1.1  christos /* We put a pointer to this structure in the read_symtab_private field
     69      1.1  christos    of the psymtab.  */
     70      1.1  christos 
     71      1.1  christos struct symloc
     72      1.1  christos   {
     73      1.1  christos     /* Offset within the file symbol table of first local symbol for this
     74      1.1  christos        file.  */
     75      1.1  christos 
     76      1.1  christos     int ldsymoff;
     77      1.1  christos 
     78      1.1  christos     /* Length (in bytes) of the section of the symbol table devoted to
     79      1.1  christos        this file's symbols (actually, the section bracketed may contain
     80      1.1  christos        more than just this file's symbols).  If ldsymlen is 0, the only
     81      1.1  christos        reason for this thing's existence is the dependency list.  Nothing
     82      1.1  christos        else will happen when it is read in.  */
     83      1.1  christos 
     84      1.1  christos     int ldsymlen;
     85      1.1  christos 
     86      1.1  christos     /* The size of each symbol in the symbol file (in external form).  */
     87      1.1  christos 
     88      1.1  christos     int symbol_size;
     89      1.1  christos 
     90      1.1  christos     /* Further information needed to locate the symbols if they are in
     91      1.1  christos        an ELF file.  */
     92      1.1  christos 
     93      1.1  christos     int symbol_offset;
     94      1.1  christos     int string_offset;
     95      1.1  christos     int file_string_offset;
     96      1.1  christos   };
     97      1.1  christos 
     98      1.1  christos #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
     99      1.1  christos #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
    100      1.1  christos #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
    101      1.1  christos #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
    102      1.1  christos #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
    103      1.1  christos #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
    104      1.1  christos #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
    105      1.1  christos 
    106      1.1  christos 
    108      1.1  christos /* The objfile we are currently reading.  */
    109      1.1  christos 
    110      1.1  christos static struct objfile *dbxread_objfile;
    111      1.1  christos 
    112      1.1  christos /* Remember what we deduced to be the source language of this psymtab.  */
    113      1.1  christos 
    114      1.1  christos static enum language psymtab_language = language_unknown;
    115      1.1  christos 
    116      1.1  christos /* The BFD for this file -- implicit parameter to next_symbol_text.  */
    117      1.1  christos 
    118      1.1  christos static bfd *symfile_bfd;
    119      1.1  christos 
    120      1.1  christos /* The size of each symbol in the symbol file (in external form).
    121      1.1  christos    This is set by dbx_symfile_read when building psymtabs, and by
    122      1.1  christos    dbx_psymtab_to_symtab when building symtabs.  */
    123      1.1  christos 
    124      1.1  christos static unsigned symbol_size;
    125      1.1  christos 
    126      1.1  christos /* This is the offset of the symbol table in the executable file.  */
    127      1.1  christos 
    128      1.1  christos static unsigned symbol_table_offset;
    129      1.1  christos 
    130      1.1  christos /* This is the offset of the string table in the executable file.  */
    131      1.1  christos 
    132      1.1  christos static unsigned string_table_offset;
    133      1.1  christos 
    134      1.1  christos /* For elf+stab executables, the n_strx field is not a simple index
    135      1.1  christos    into the string table.  Instead, each .o file has a base offset in
    136      1.1  christos    the string table, and the associated symbols contain offsets from
    137      1.1  christos    this base.  The following two variables contain the base offset for
    138      1.1  christos    the current and next .o files.  */
    139      1.1  christos 
    140      1.1  christos static unsigned int file_string_table_offset;
    141      1.1  christos static unsigned int next_file_string_table_offset;
    142      1.1  christos 
    143      1.1  christos /* .o and NLM files contain unrelocated addresses which are based at
    144      1.1  christos    0.  When non-zero, this flag disables some of the special cases for
    145      1.1  christos    Solaris elf+stab text addresses at location 0.  */
    146      1.1  christos 
    147      1.1  christos static int symfile_relocatable = 0;
    148      1.1  christos 
    149      1.1  christos /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
    150      1.1  christos    relative to the function start address.  */
    151      1.1  christos 
    152      1.1  christos static int block_address_function_relative = 0;
    153      1.1  christos 
    154      1.1  christos /* The lowest text address we have yet encountered.  This is needed
    156      1.1  christos    because in an a.out file, there is no header field which tells us
    157      1.1  christos    what address the program is actually going to be loaded at, so we
    158      1.1  christos    need to make guesses based on the symbols (which *are* relocated to
    159      1.1  christos    reflect the address it will be loaded at).  */
    160      1.1  christos 
    161      1.1  christos static CORE_ADDR lowest_text_address;
    162      1.1  christos 
    163      1.1  christos /* Non-zero if there is any line number info in the objfile.  Prevents
    164      1.1  christos    end_psymtab from discarding an otherwise empty psymtab.  */
    165      1.1  christos 
    166      1.1  christos static int has_line_numbers;
    167      1.1  christos 
    168      1.1  christos /* Complaints about the symbols we have encountered.  */
    169      1.1  christos 
    170      1.1  christos static void
    171      1.1  christos unknown_symtype_complaint (const char *arg1)
    172      1.1  christos {
    173      1.1  christos   complaint (&symfile_complaints, _("unknown symbol type %s"), arg1);
    174      1.1  christos }
    175      1.1  christos 
    176      1.1  christos static void
    177      1.1  christos lbrac_mismatch_complaint (int arg1)
    178      1.1  christos {
    179      1.1  christos   complaint (&symfile_complaints,
    180      1.1  christos 	     _("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
    181      1.1  christos }
    182      1.1  christos 
    183      1.1  christos static void
    184      1.1  christos repeated_header_complaint (const char *arg1, int arg2)
    185      1.1  christos {
    186      1.1  christos   complaint (&symfile_complaints,
    187      1.1  christos 	     _("\"repeated\" header file %s not "
    188      1.1  christos 	       "previously seen, at symtab pos %d"),
    189      1.1  christos 	     arg1, arg2);
    190      1.1  christos }
    191      1.1  christos 
    192      1.1  christos /* find_text_range --- find start and end of loadable code sections
    193      1.1  christos 
    194      1.1  christos    The find_text_range function finds the shortest address range that
    195      1.1  christos    encloses all sections containing executable code, and stores it in
    196      1.1  christos    objfile's text_addr and text_size members.
    197      1.1  christos 
    198      1.1  christos    dbx_symfile_read will use this to finish off the partial symbol
    199      1.1  christos    table, in some cases.  */
    200      1.1  christos 
    201      1.1  christos static void
    202      1.1  christos find_text_range (bfd * sym_bfd, struct objfile *objfile)
    203      1.1  christos {
    204      1.1  christos   asection *sec;
    205      1.1  christos   int found_any = 0;
    206      1.1  christos   CORE_ADDR start = 0;
    207      1.1  christos   CORE_ADDR end = 0;
    208      1.1  christos 
    209      1.1  christos   for (sec = sym_bfd->sections; sec; sec = sec->next)
    210      1.1  christos     if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE)
    211      1.1  christos       {
    212      1.1  christos 	CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec);
    213      1.1  christos 	CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec);
    214      1.1  christos 
    215      1.1  christos 	if (found_any)
    216      1.1  christos 	  {
    217      1.1  christos 	    if (sec_start < start)
    218      1.1  christos 	      start = sec_start;
    219      1.1  christos 	    if (sec_end > end)
    220      1.1  christos 	      end = sec_end;
    221      1.1  christos 	  }
    222      1.1  christos 	else
    223      1.1  christos 	  {
    224      1.1  christos 	    start = sec_start;
    225      1.1  christos 	    end = sec_end;
    226      1.1  christos 	  }
    227      1.1  christos 
    228      1.1  christos 	found_any = 1;
    229      1.1  christos       }
    230      1.1  christos 
    231      1.1  christos   if (!found_any)
    232      1.1  christos     error (_("Can't find any code sections in symbol file"));
    233      1.1  christos 
    234      1.1  christos   DBX_TEXT_ADDR (objfile) = start;
    235      1.1  christos   DBX_TEXT_SIZE (objfile) = end - start;
    236      1.1  christos }
    237      1.1  christos 
    238      1.1  christos 
    240      1.1  christos 
    241      1.1  christos /* During initial symbol readin, we need to have a structure to keep
    242      1.1  christos    track of which psymtabs have which bincls in them.  This structure
    243      1.1  christos    is used during readin to setup the list of dependencies within each
    244      1.1  christos    partial symbol table.  */
    245      1.1  christos 
    246      1.1  christos struct header_file_location
    247      1.1  christos {
    248      1.1  christos   char *name;			/* Name of header file */
    249      1.1  christos   int instance;			/* See above */
    250      1.1  christos   struct partial_symtab *pst;	/* Partial symtab that has the
    251      1.1  christos 				   BINCL/EINCL defs for this file.  */
    252      1.1  christos };
    253      1.1  christos 
    254      1.1  christos /* The actual list and controling variables.  */
    255      1.1  christos static struct header_file_location *bincl_list, *next_bincl;
    256      1.1  christos static int bincls_allocated;
    257      1.1  christos 
    258      1.1  christos /* Local function prototypes.  */
    259      1.1  christos 
    260      1.1  christos extern void _initialize_dbxread (void);
    261      1.1  christos 
    262      1.1  christos static void read_ofile_symtab (struct objfile *, struct partial_symtab *);
    263      1.1  christos 
    264      1.1  christos static void dbx_read_symtab (struct partial_symtab *self,
    265      1.1  christos 			     struct objfile *objfile);
    266      1.1  christos 
    267      1.1  christos static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *);
    268      1.1  christos 
    269      1.1  christos static void read_dbx_dynamic_symtab (struct objfile *objfile);
    270      1.1  christos 
    271      1.1  christos static void read_dbx_symtab (struct objfile *);
    272      1.1  christos 
    273      1.1  christos static void free_bincl_list (struct objfile *);
    274      1.1  christos 
    275      1.1  christos static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);
    276      1.1  christos 
    277      1.1  christos static void add_bincl_to_list (struct partial_symtab *, char *, int);
    278      1.1  christos 
    279      1.1  christos static void init_bincl_list (int, struct objfile *);
    280      1.1  christos 
    281      1.1  christos static char *dbx_next_symbol_text (struct objfile *);
    282      1.1  christos 
    283      1.1  christos static void fill_symbuf (bfd *);
    284      1.1  christos 
    285      1.1  christos static void dbx_symfile_init (struct objfile *);
    286      1.1  christos 
    287      1.1  christos static void dbx_new_init (struct objfile *);
    288      1.1  christos 
    289      1.1  christos static void dbx_symfile_read (struct objfile *, int);
    290      1.1  christos 
    291      1.1  christos static void dbx_symfile_finish (struct objfile *);
    292      1.1  christos 
    293      1.1  christos static void record_minimal_symbol (const char *, CORE_ADDR, int,
    294      1.1  christos 				   struct objfile *);
    295      1.1  christos 
    296      1.1  christos static void add_new_header_file (char *, int);
    297      1.1  christos 
    298      1.1  christos static void add_old_header_file (char *, int);
    299      1.1  christos 
    300      1.1  christos static void add_this_object_header_file (int);
    301      1.1  christos 
    302      1.1  christos static struct partial_symtab *start_psymtab (struct objfile *, char *,
    303      1.1  christos 					     CORE_ADDR, int,
    304      1.1  christos 					     struct partial_symbol **,
    305      1.1  christos 					     struct partial_symbol **);
    306      1.1  christos 
    307      1.1  christos /* Free up old header file tables.  */
    308      1.1  christos 
    309      1.1  christos void
    310      1.1  christos free_header_files (void)
    311      1.1  christos {
    312      1.1  christos   if (this_object_header_files)
    313      1.1  christos     {
    314      1.1  christos       xfree (this_object_header_files);
    315      1.1  christos       this_object_header_files = NULL;
    316      1.1  christos     }
    317      1.1  christos   n_allocated_this_object_header_files = 0;
    318      1.1  christos }
    319      1.1  christos 
    320      1.1  christos /* Allocate new header file tables.  */
    321      1.1  christos 
    322      1.1  christos void
    323      1.1  christos init_header_files (void)
    324      1.1  christos {
    325      1.1  christos   n_allocated_this_object_header_files = 10;
    326      1.1  christos   this_object_header_files = (int *) xmalloc (10 * sizeof (int));
    327      1.1  christos }
    328      1.1  christos 
    329      1.1  christos /* Add header file number I for this object file
    330      1.1  christos    at the next successive FILENUM.  */
    331      1.1  christos 
    332      1.1  christos static void
    333      1.1  christos add_this_object_header_file (int i)
    334      1.1  christos {
    335      1.1  christos   if (n_this_object_header_files == n_allocated_this_object_header_files)
    336      1.1  christos     {
    337      1.1  christos       n_allocated_this_object_header_files *= 2;
    338      1.1  christos       this_object_header_files
    339      1.1  christos 	= (int *) xrealloc ((char *) this_object_header_files,
    340      1.1  christos 		       n_allocated_this_object_header_files * sizeof (int));
    341      1.1  christos     }
    342      1.1  christos 
    343      1.1  christos   this_object_header_files[n_this_object_header_files++] = i;
    344      1.1  christos }
    345      1.1  christos 
    346      1.1  christos /* Add to this file an "old" header file, one already seen in
    347      1.1  christos    a previous object file.  NAME is the header file's name.
    348      1.1  christos    INSTANCE is its instance code, to select among multiple
    349      1.1  christos    symbol tables for the same header file.  */
    350      1.1  christos 
    351      1.1  christos static void
    352      1.1  christos add_old_header_file (char *name, int instance)
    353      1.1  christos {
    354      1.1  christos   struct header_file *p = HEADER_FILES (dbxread_objfile);
    355      1.1  christos   int i;
    356      1.1  christos 
    357      1.1  christos   for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++)
    358      1.1  christos     if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
    359      1.1  christos       {
    360      1.1  christos 	add_this_object_header_file (i);
    361      1.1  christos 	return;
    362      1.1  christos       }
    363      1.1  christos   repeated_header_complaint (name, symnum);
    364      1.1  christos }
    365      1.1  christos 
    366      1.1  christos /* Add to this file a "new" header file: definitions for its types follow.
    367      1.1  christos    NAME is the header file's name.
    368      1.1  christos    Most often this happens only once for each distinct header file,
    369      1.1  christos    but not necessarily.  If it happens more than once, INSTANCE has
    370      1.1  christos    a different value each time, and references to the header file
    371      1.1  christos    use INSTANCE values to select among them.
    372      1.1  christos 
    373      1.1  christos    dbx output contains "begin" and "end" markers for each new header file,
    374      1.1  christos    but at this level we just need to know which files there have been;
    375      1.1  christos    so we record the file when its "begin" is seen and ignore the "end".  */
    376      1.1  christos 
    377      1.1  christos static void
    378      1.1  christos add_new_header_file (char *name, int instance)
    379      1.1  christos {
    380      1.1  christos   int i;
    381      1.1  christos   struct header_file *hfile;
    382      1.1  christos 
    383      1.1  christos   /* Make sure there is room for one more header file.  */
    384      1.1  christos 
    385      1.1  christos   i = N_ALLOCATED_HEADER_FILES (dbxread_objfile);
    386      1.1  christos 
    387      1.1  christos   if (N_HEADER_FILES (dbxread_objfile) == i)
    388      1.1  christos     {
    389      1.1  christos       if (i == 0)
    390      1.1  christos 	{
    391      1.1  christos 	  N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10;
    392      1.1  christos 	  HEADER_FILES (dbxread_objfile) = (struct header_file *)
    393      1.1  christos 	    xmalloc (10 * sizeof (struct header_file));
    394      1.1  christos 	}
    395      1.1  christos       else
    396      1.1  christos 	{
    397      1.1  christos 	  i *= 2;
    398      1.1  christos 	  N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i;
    399      1.1  christos 	  HEADER_FILES (dbxread_objfile) = (struct header_file *)
    400      1.1  christos 	    xrealloc ((char *) HEADER_FILES (dbxread_objfile),
    401      1.1  christos 		      (i * sizeof (struct header_file)));
    402      1.1  christos 	}
    403      1.1  christos     }
    404      1.1  christos 
    405      1.1  christos   /* Create an entry for this header file.  */
    406      1.1  christos 
    407      1.1  christos   i = N_HEADER_FILES (dbxread_objfile)++;
    408      1.1  christos   hfile = HEADER_FILES (dbxread_objfile) + i;
    409      1.1  christos   hfile->name = xstrdup (name);
    410      1.1  christos   hfile->instance = instance;
    411      1.1  christos   hfile->length = 10;
    412      1.1  christos   hfile->vector
    413      1.1  christos     = (struct type **) xmalloc (10 * sizeof (struct type *));
    414      1.1  christos   memset (hfile->vector, 0, 10 * sizeof (struct type *));
    415      1.1  christos 
    416      1.1  christos   add_this_object_header_file (i);
    417      1.1  christos }
    418      1.1  christos 
    419      1.1  christos #if 0
    420      1.1  christos static struct type **
    421      1.1  christos explicit_lookup_type (int real_filenum, int index)
    422      1.1  christos {
    423      1.1  christos   struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum];
    424      1.1  christos 
    425      1.1  christos   if (index >= f->length)
    426      1.1  christos     {
    427      1.1  christos       f->length *= 2;
    428      1.1  christos       f->vector = (struct type **)
    429      1.1  christos 	xrealloc (f->vector, f->length * sizeof (struct type *));
    430      1.1  christos       memset (&f->vector[f->length / 2],
    431      1.1  christos 	      '\0', f->length * sizeof (struct type *) / 2);
    432      1.1  christos     }
    433      1.1  christos   return &f->vector[index];
    434      1.1  christos }
    435      1.1  christos #endif
    436      1.1  christos 
    437      1.1  christos static void
    439      1.1  christos record_minimal_symbol (const char *name, CORE_ADDR address, int type,
    440      1.1  christos 		       struct objfile *objfile)
    441      1.1  christos {
    442      1.1  christos   enum minimal_symbol_type ms_type;
    443      1.1  christos   int section;
    444      1.1  christos 
    445      1.1  christos   switch (type)
    446      1.1  christos     {
    447      1.1  christos     case N_TEXT | N_EXT:
    448      1.1  christos       ms_type = mst_text;
    449      1.1  christos       section = SECT_OFF_TEXT (objfile);
    450      1.1  christos       break;
    451      1.1  christos     case N_DATA | N_EXT:
    452      1.1  christos       ms_type = mst_data;
    453      1.1  christos       section = SECT_OFF_DATA (objfile);
    454      1.1  christos       break;
    455      1.1  christos     case N_BSS | N_EXT:
    456      1.1  christos       ms_type = mst_bss;
    457      1.1  christos       section = SECT_OFF_BSS (objfile);
    458      1.1  christos       break;
    459      1.1  christos     case N_ABS | N_EXT:
    460      1.1  christos       ms_type = mst_abs;
    461      1.1  christos       section = -1;
    462      1.1  christos       break;
    463      1.1  christos #ifdef N_SETV
    464      1.1  christos     case N_SETV | N_EXT:
    465      1.1  christos       ms_type = mst_data;
    466      1.1  christos       section = SECT_OFF_DATA (objfile);
    467      1.1  christos       break;
    468      1.1  christos     case N_SETV:
    469      1.1  christos       /* I don't think this type actually exists; since a N_SETV is the result
    470      1.1  christos          of going over many .o files, it doesn't make sense to have one
    471      1.1  christos          file local.  */
    472      1.1  christos       ms_type = mst_file_data;
    473      1.1  christos       section = SECT_OFF_DATA (objfile);
    474      1.1  christos       break;
    475      1.1  christos #endif
    476      1.1  christos     case N_TEXT:
    477      1.1  christos     case N_NBTEXT:
    478      1.1  christos     case N_FN:
    479      1.1  christos     case N_FN_SEQ:
    480      1.1  christos       ms_type = mst_file_text;
    481      1.1  christos       section = SECT_OFF_TEXT (objfile);
    482      1.1  christos       break;
    483      1.1  christos     case N_DATA:
    484      1.1  christos       ms_type = mst_file_data;
    485      1.1  christos 
    486      1.1  christos       /* Check for __DYNAMIC, which is used by Sun shared libraries.
    487      1.1  christos          Record it as global even if it's local, not global, so
    488      1.1  christos          lookup_minimal_symbol can find it.  We don't check symbol_leading_char
    489      1.1  christos          because for SunOS4 it always is '_'.  */
    490      1.1  christos       if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0)
    491      1.1  christos 	ms_type = mst_data;
    492      1.1  christos 
    493      1.1  christos       /* Same with virtual function tables, both global and static.  */
    494      1.1  christos       {
    495      1.1  christos 	const char *tempstring = name;
    496      1.1  christos 
    497      1.1  christos 	if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
    498      1.1  christos 	  ++tempstring;
    499      1.1  christos 	if (is_vtable_name (tempstring))
    500      1.1  christos 	  ms_type = mst_data;
    501      1.1  christos       }
    502      1.1  christos       section = SECT_OFF_DATA (objfile);
    503      1.1  christos       break;
    504      1.1  christos     case N_BSS:
    505      1.1  christos       ms_type = mst_file_bss;
    506      1.1  christos       section = SECT_OFF_BSS (objfile);
    507      1.1  christos       break;
    508      1.1  christos     default:
    509      1.1  christos       ms_type = mst_unknown;
    510      1.1  christos       section = -1;
    511      1.1  christos       break;
    512      1.1  christos     }
    513      1.1  christos 
    514      1.1  christos   if ((ms_type == mst_file_text || ms_type == mst_text)
    515      1.1  christos       && address < lowest_text_address)
    516      1.1  christos     lowest_text_address = address;
    517      1.1  christos 
    518      1.1  christos   prim_record_minimal_symbol_and_info
    519      1.1  christos     (name, address, ms_type, section, objfile);
    520      1.1  christos }
    521      1.1  christos 
    522      1.1  christos /* Scan and build partial symbols for a symbol file.
    524      1.1  christos    We have been initialized by a call to dbx_symfile_init, which
    525      1.1  christos    put all the relevant info into a "struct dbx_symfile_info",
    526      1.1  christos    hung off the objfile structure.  */
    527      1.1  christos 
    528      1.1  christos static void
    529      1.1  christos dbx_symfile_read (struct objfile *objfile, int symfile_flags)
    530      1.1  christos {
    531      1.1  christos   bfd *sym_bfd;
    532      1.1  christos   int val;
    533      1.1  christos   struct cleanup *back_to;
    534      1.1  christos 
    535      1.1  christos   sym_bfd = objfile->obfd;
    536      1.1  christos 
    537      1.1  christos   /* .o and .nlm files are relocatables with text, data and bss segs based at
    538      1.1  christos      0.  This flag disables special (Solaris stabs-in-elf only) fixups for
    539      1.1  christos      symbols with a value of 0.  */
    540      1.1  christos 
    541      1.1  christos   symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
    542      1.1  christos 
    543      1.1  christos   /* This is true for Solaris (and all other systems which put stabs
    544      1.1  christos      in sections, hopefully, since it would be silly to do things
    545      1.1  christos      differently from Solaris), and false for SunOS4 and other a.out
    546      1.1  christos      file formats.  */
    547      1.1  christos   block_address_function_relative =
    548      1.1  christos     ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
    549      1.1  christos      || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
    550      1.1  christos      || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
    551      1.1  christos      || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
    552      1.1  christos      || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7))
    553      1.1  christos      || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
    554      1.1  christos 
    555      1.1  christos   val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
    556      1.1  christos   if (val < 0)
    557      1.1  christos     perror_with_name (objfile_name (objfile));
    558      1.1  christos 
    559      1.1  christos   /* Size the symbol table.  */
    560      1.1  christos   if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
    561      1.1  christos     init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
    562      1.1  christos 
    563      1.1  christos   symbol_size = DBX_SYMBOL_SIZE (objfile);
    564      1.1  christos   symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
    565      1.1  christos 
    566      1.1  christos   free_pending_blocks ();
    567      1.1  christos   back_to = make_cleanup (really_free_pendings, 0);
    568      1.1  christos 
    569      1.1  christos   init_minimal_symbol_collection ();
    570      1.1  christos   make_cleanup_discard_minimal_symbols ();
    571      1.1  christos 
    572      1.1  christos   /* Read stabs data from executable file and define symbols.  */
    573      1.1  christos 
    574      1.1  christos   read_dbx_symtab (objfile);
    575      1.1  christos 
    576      1.1  christos   /* Add the dynamic symbols.  */
    577      1.1  christos 
    578      1.1  christos   read_dbx_dynamic_symtab (objfile);
    579      1.1  christos 
    580      1.1  christos   /* Install any minimal symbols that have been collected as the current
    581      1.1  christos      minimal symbols for this objfile.  */
    582      1.1  christos 
    583      1.1  christos   install_minimal_symbols (objfile);
    584      1.1  christos 
    585      1.1  christos   do_cleanups (back_to);
    586      1.1  christos }
    587      1.1  christos 
    588      1.1  christos /* Initialize anything that needs initializing when a completely new
    589      1.1  christos    symbol file is specified (not just adding some symbols from another
    590      1.1  christos    file, e.g. a shared library).  */
    591      1.1  christos 
    592      1.1  christos static void
    593      1.1  christos dbx_new_init (struct objfile *ignore)
    594      1.1  christos {
    595      1.1  christos   stabsread_new_init ();
    596      1.1  christos   buildsym_new_init ();
    597      1.1  christos   init_header_files ();
    598      1.1  christos }
    599      1.1  christos 
    600      1.1  christos 
    601      1.1  christos /* dbx_symfile_init ()
    602      1.1  christos    is the dbx-specific initialization routine for reading symbols.
    603      1.1  christos    It is passed a struct objfile which contains, among other things,
    604      1.1  christos    the BFD for the file whose symbols are being read, and a slot for a pointer
    605      1.1  christos    to "private data" which we fill with goodies.
    606      1.1  christos 
    607      1.1  christos    We read the string table into malloc'd space and stash a pointer to it.
    608      1.1  christos 
    609      1.1  christos    Since BFD doesn't know how to read debug symbols in a format-independent
    610      1.1  christos    way (and may never do so...), we have to do it ourselves.  We will never
    611      1.1  christos    be called unless this is an a.out (or very similar) file.
    612      1.1  christos    FIXME, there should be a cleaner peephole into the BFD environment here.  */
    613      1.1  christos 
    614      1.1  christos #define DBX_STRINGTAB_SIZE_SIZE sizeof(long)	/* FIXME */
    615      1.1  christos 
    616      1.1  christos static void
    617      1.1  christos dbx_symfile_init (struct objfile *objfile)
    618      1.1  christos {
    619      1.1  christos   int val;
    620      1.1  christos   bfd *sym_bfd = objfile->obfd;
    621      1.1  christos   char *name = bfd_get_filename (sym_bfd);
    622      1.1  christos   asection *text_sect;
    623      1.1  christos   unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
    624      1.1  christos   struct dbx_symfile_info *dbx;
    625      1.1  christos 
    626      1.1  christos   /* Allocate struct to keep track of the symfile.  */
    627      1.1  christos   dbx = XCNEW (struct dbx_symfile_info);
    628      1.1  christos   set_objfile_data (objfile, dbx_objfile_data_key, dbx);
    629      1.1  christos 
    630      1.1  christos   DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
    631      1.1  christos   DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
    632      1.1  christos   DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
    633      1.1  christos 
    634      1.1  christos   /* FIXME POKING INSIDE BFD DATA STRUCTURES.  */
    635      1.1  christos #define	STRING_TABLE_OFFSET	(sym_bfd->origin + obj_str_filepos (sym_bfd))
    636      1.1  christos #define	SYMBOL_TABLE_OFFSET	(sym_bfd->origin + obj_sym_filepos (sym_bfd))
    637      1.1  christos 
    638      1.1  christos   /* FIXME POKING INSIDE BFD DATA STRUCTURES.  */
    639      1.1  christos 
    640      1.1  christos   DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
    641      1.1  christos 
    642      1.1  christos   text_sect = bfd_get_section_by_name (sym_bfd, ".text");
    643      1.1  christos   if (!text_sect)
    644      1.1  christos     error (_("Can't find .text section in symbol file"));
    645      1.1  christos   DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
    646      1.1  christos   DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
    647      1.1  christos 
    648      1.1  christos   DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
    649      1.1  christos   DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
    650      1.1  christos   DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
    651      1.1  christos 
    652      1.1  christos   /* Read the string table and stash it away in the objfile_obstack.
    653      1.1  christos      When we blow away the objfile the string table goes away as well.
    654      1.1  christos      Note that gdb used to use the results of attempting to malloc the
    655      1.1  christos      string table, based on the size it read, as a form of sanity check
    656      1.1  christos      for botched byte swapping, on the theory that a byte swapped string
    657      1.1  christos      table size would be so totally bogus that the malloc would fail.  Now
    658      1.1  christos      that we put in on the objfile_obstack, we can't do this since gdb gets
    659      1.1  christos      a fatal error (out of virtual memory) if the size is bogus.  We can
    660      1.1  christos      however at least check to see if the size is less than the size of
    661      1.1  christos      the size field itself, or larger than the size of the entire file.
    662      1.1  christos      Note that all valid string tables have a size greater than zero, since
    663      1.1  christos      the bytes used to hold the size are included in the count.  */
    664      1.1  christos 
    665      1.1  christos   if (STRING_TABLE_OFFSET == 0)
    666      1.1  christos     {
    667      1.1  christos       /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
    668      1.1  christos          will never be zero, even when there is no string table.  This
    669      1.1  christos          would appear to be a bug in bfd.  */
    670      1.1  christos       DBX_STRINGTAB_SIZE (objfile) = 0;
    671      1.1  christos       DBX_STRINGTAB (objfile) = NULL;
    672      1.1  christos     }
    673      1.1  christos   else
    674      1.1  christos     {
    675      1.1  christos       val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
    676      1.1  christos       if (val < 0)
    677      1.1  christos 	perror_with_name (name);
    678      1.1  christos 
    679      1.1  christos       memset (size_temp, 0, sizeof (size_temp));
    680      1.1  christos       val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
    681      1.1  christos       if (val < 0)
    682      1.1  christos 	{
    683      1.1  christos 	  perror_with_name (name);
    684      1.1  christos 	}
    685      1.1  christos       else if (val == 0)
    686      1.1  christos 	{
    687      1.1  christos 	  /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
    688      1.1  christos 	     EOF if there is no string table, and attempting to read the size
    689      1.1  christos 	     from EOF will read zero bytes.  */
    690      1.1  christos 	  DBX_STRINGTAB_SIZE (objfile) = 0;
    691      1.1  christos 	  DBX_STRINGTAB (objfile) = NULL;
    692      1.1  christos 	}
    693      1.1  christos       else
    694      1.1  christos 	{
    695      1.1  christos 	  /* Read some data that would appear to be the string table size.
    696      1.1  christos 	     If there really is a string table, then it is probably the right
    697      1.1  christos 	     size.  Byteswap if necessary and validate the size.  Note that
    698      1.1  christos 	     the minimum is DBX_STRINGTAB_SIZE_SIZE.  If we just read some
    699      1.1  christos 	     random data that happened to be at STRING_TABLE_OFFSET, because
    700      1.1  christos 	     bfd can't tell us there is no string table, the sanity checks may
    701      1.1  christos 	     or may not catch this.  */
    702      1.1  christos 	  DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
    703      1.1  christos 
    704      1.1  christos 	  if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
    705      1.1  christos 	      || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
    706      1.1  christos 	    error (_("ridiculous string table size (%d bytes)."),
    707      1.1  christos 		   DBX_STRINGTAB_SIZE (objfile));
    708      1.1  christos 
    709      1.1  christos 	  DBX_STRINGTAB (objfile) =
    710      1.1  christos 	    (char *) obstack_alloc (&objfile->objfile_obstack,
    711      1.1  christos 				    DBX_STRINGTAB_SIZE (objfile));
    712      1.1  christos 	  OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
    713      1.1  christos 
    714      1.1  christos 	  /* Now read in the string table in one big gulp.  */
    715      1.1  christos 
    716      1.1  christos 	  val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
    717      1.1  christos 	  if (val < 0)
    718      1.1  christos 	    perror_with_name (name);
    719      1.1  christos 	  val = bfd_bread (DBX_STRINGTAB (objfile),
    720      1.1  christos 			   DBX_STRINGTAB_SIZE (objfile),
    721      1.1  christos 			   sym_bfd);
    722      1.1  christos 	  if (val != DBX_STRINGTAB_SIZE (objfile))
    723      1.1  christos 	    perror_with_name (name);
    724      1.1  christos 	}
    725      1.1  christos     }
    726      1.1  christos }
    727      1.1  christos 
    728      1.1  christos /* Perform any local cleanups required when we are done with a particular
    729      1.1  christos    objfile.  I.E, we are in the process of discarding all symbol information
    730      1.1  christos    for an objfile, freeing up all memory held for it, and unlinking the
    731      1.1  christos    objfile struct from the global list of known objfiles.  */
    732      1.1  christos 
    733      1.1  christos static void
    734      1.1  christos dbx_symfile_finish (struct objfile *objfile)
    735      1.1  christos {
    736      1.1  christos   free_header_files ();
    737      1.1  christos }
    738      1.1  christos 
    739      1.1  christos static void
    740      1.1  christos dbx_free_symfile_info (struct objfile *objfile, void *arg)
    741      1.1  christos {
    742      1.1  christos   struct dbx_symfile_info *dbx = arg;
    743      1.1  christos 
    744      1.1  christos   if (dbx->header_files != NULL)
    745      1.1  christos     {
    746      1.1  christos       int i = dbx->n_header_files;
    747      1.1  christos       struct header_file *hfiles = dbx->header_files;
    748      1.1  christos 
    749      1.1  christos       while (--i >= 0)
    750      1.1  christos 	{
    751      1.1  christos 	  xfree (hfiles[i].name);
    752      1.1  christos 	  xfree (hfiles[i].vector);
    753      1.1  christos 	}
    754      1.1  christos       xfree (hfiles);
    755      1.1  christos     }
    756      1.1  christos 
    757      1.1  christos   xfree (dbx);
    758      1.1  christos }
    759      1.1  christos 
    760      1.1  christos 
    761      1.1  christos 
    763      1.1  christos /* Buffer for reading the symbol table entries.  */
    764      1.1  christos static struct external_nlist symbuf[4096];
    765      1.1  christos static int symbuf_idx;
    766      1.1  christos static int symbuf_end;
    767      1.1  christos 
    768      1.1  christos /* Name of last function encountered.  Used in Solaris to approximate
    769      1.1  christos    object file boundaries.  */
    770      1.1  christos static char *last_function_name;
    771      1.1  christos 
    772      1.1  christos /* The address in memory of the string table of the object file we are
    773      1.1  christos    reading (which might not be the "main" object file, but might be a
    774      1.1  christos    shared library or some other dynamically loaded thing).  This is
    775      1.1  christos    set by read_dbx_symtab when building psymtabs, and by
    776      1.1  christos    read_ofile_symtab when building symtabs, and is used only by
    777      1.1  christos    next_symbol_text.  FIXME: If that is true, we don't need it when
    778      1.1  christos    building psymtabs, right?  */
    779      1.1  christos static char *stringtab_global;
    780      1.1  christos 
    781      1.1  christos /* These variables are used to control fill_symbuf when the stabs
    782      1.1  christos    symbols are not contiguous (as may be the case when a COFF file is
    783      1.1  christos    linked using --split-by-reloc).  */
    784      1.1  christos static struct stab_section_list *symbuf_sections;
    785      1.1  christos static unsigned int symbuf_left;
    786      1.1  christos static unsigned int symbuf_read;
    787      1.1  christos 
    788      1.1  christos /* This variable stores a global stabs buffer, if we read stabs into
    789      1.1  christos    memory in one chunk in order to process relocations.  */
    790      1.1  christos static bfd_byte *stabs_data;
    791      1.1  christos 
    792      1.1  christos /* Refill the symbol table input buffer
    793      1.1  christos    and set the variables that control fetching entries from it.
    794      1.1  christos    Reports an error if no data available.
    795      1.1  christos    This function can read past the end of the symbol table
    796      1.1  christos    (into the string table) but this does no harm.  */
    797      1.1  christos 
    798      1.1  christos static void
    799      1.1  christos fill_symbuf (bfd *sym_bfd)
    800      1.1  christos {
    801      1.1  christos   unsigned int count;
    802      1.1  christos   int nbytes;
    803      1.1  christos 
    804      1.1  christos   if (stabs_data)
    805      1.1  christos     {
    806      1.1  christos       nbytes = sizeof (symbuf);
    807      1.1  christos       if (nbytes > symbuf_left)
    808      1.1  christos         nbytes = symbuf_left;
    809      1.1  christos       memcpy (symbuf, stabs_data + symbuf_read, nbytes);
    810      1.1  christos     }
    811      1.1  christos   else if (symbuf_sections == NULL)
    812      1.1  christos     {
    813      1.1  christos       count = sizeof (symbuf);
    814      1.1  christos       nbytes = bfd_bread (symbuf, count, sym_bfd);
    815      1.1  christos     }
    816      1.1  christos   else
    817      1.1  christos     {
    818      1.1  christos       if (symbuf_left <= 0)
    819      1.1  christos 	{
    820      1.1  christos 	  file_ptr filepos = symbuf_sections->section->filepos;
    821      1.1  christos 
    822      1.1  christos 	  if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
    823      1.1  christos 	    perror_with_name (bfd_get_filename (sym_bfd));
    824      1.1  christos 	  symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
    825      1.1  christos 	  symbol_table_offset = filepos - symbuf_read;
    826      1.1  christos 	  symbuf_sections = symbuf_sections->next;
    827      1.1  christos 	}
    828      1.1  christos 
    829      1.1  christos       count = symbuf_left;
    830      1.1  christos       if (count > sizeof (symbuf))
    831      1.1  christos 	count = sizeof (symbuf);
    832      1.1  christos       nbytes = bfd_bread (symbuf, count, sym_bfd);
    833      1.1  christos     }
    834      1.1  christos 
    835      1.1  christos   if (nbytes < 0)
    836      1.1  christos     perror_with_name (bfd_get_filename (sym_bfd));
    837      1.1  christos   else if (nbytes == 0)
    838      1.1  christos     error (_("Premature end of file reading symbol table"));
    839      1.1  christos   symbuf_end = nbytes / symbol_size;
    840      1.1  christos   symbuf_idx = 0;
    841      1.1  christos   symbuf_left -= nbytes;
    842      1.1  christos   symbuf_read += nbytes;
    843      1.1  christos }
    844      1.1  christos 
    845      1.1  christos static void
    846      1.1  christos stabs_seek (int sym_offset)
    847      1.1  christos {
    848      1.1  christos   if (stabs_data)
    849      1.1  christos     {
    850      1.1  christos       symbuf_read += sym_offset;
    851      1.1  christos       symbuf_left -= sym_offset;
    852      1.1  christos     }
    853      1.1  christos   else
    854      1.1  christos     bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
    855      1.1  christos }
    856      1.1  christos 
    857      1.1  christos #define INTERNALIZE_SYMBOL(intern, extern, abfd)			\
    858      1.1  christos   {									\
    859      1.1  christos     (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx);		\
    860      1.1  christos     (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type);		\
    861      1.1  christos     (intern).n_other = 0;						\
    862      1.1  christos     (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc);  		\
    863      1.1  christos     if (bfd_get_sign_extend_vma (abfd))					\
    864      1.1  christos       (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value);	\
    865      1.1  christos     else								\
    866      1.1  christos       (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value);	\
    867      1.1  christos   }
    868      1.1  christos 
    869      1.1  christos /* Invariant: The symbol pointed to by symbuf_idx is the first one
    870      1.1  christos    that hasn't been swapped.  Swap the symbol at the same time
    871      1.1  christos    that symbuf_idx is incremented.  */
    872      1.1  christos 
    873      1.1  christos /* dbx allows the text of a symbol name to be continued into the
    874      1.1  christos    next symbol name!  When such a continuation is encountered
    875      1.1  christos    (a \ at the end of the text of a name)
    876      1.1  christos    call this function to get the continuation.  */
    877      1.1  christos 
    878      1.1  christos static char *
    879      1.1  christos dbx_next_symbol_text (struct objfile *objfile)
    880      1.1  christos {
    881      1.1  christos   struct internal_nlist nlist;
    882      1.1  christos 
    883      1.1  christos   if (symbuf_idx == symbuf_end)
    884      1.1  christos     fill_symbuf (symfile_bfd);
    885      1.1  christos 
    886      1.1  christos   symnum++;
    887      1.1  christos   INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
    888      1.1  christos   OBJSTAT (objfile, n_stabs++);
    889      1.1  christos 
    890      1.1  christos   symbuf_idx++;
    891      1.1  christos 
    892      1.1  christos   return nlist.n_strx + stringtab_global + file_string_table_offset;
    893      1.1  christos }
    894      1.1  christos 
    895      1.1  christos /* Initialize the list of bincls to contain none and have some
    897      1.1  christos    allocated.  */
    898      1.1  christos 
    899      1.1  christos static void
    900      1.1  christos init_bincl_list (int number, struct objfile *objfile)
    901      1.1  christos {
    902      1.1  christos   bincls_allocated = number;
    903      1.1  christos   next_bincl = bincl_list = (struct header_file_location *)
    904      1.1  christos     xmalloc (bincls_allocated * sizeof (struct header_file_location));
    905      1.1  christos }
    906      1.1  christos 
    907      1.1  christos /* Add a bincl to the list.  */
    908      1.1  christos 
    909      1.1  christos static void
    910      1.1  christos add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
    911      1.1  christos {
    912      1.1  christos   if (next_bincl >= bincl_list + bincls_allocated)
    913      1.1  christos     {
    914      1.1  christos       int offset = next_bincl - bincl_list;
    915      1.1  christos 
    916      1.1  christos       bincls_allocated *= 2;
    917      1.1  christos       bincl_list = (struct header_file_location *)
    918      1.1  christos 	xrealloc ((char *) bincl_list,
    919      1.1  christos 		  bincls_allocated * sizeof (struct header_file_location));
    920      1.1  christos       next_bincl = bincl_list + offset;
    921      1.1  christos     }
    922      1.1  christos   next_bincl->pst = pst;
    923      1.1  christos   next_bincl->instance = instance;
    924      1.1  christos   next_bincl++->name = name;
    925      1.1  christos }
    926      1.1  christos 
    927      1.1  christos /* Given a name, value pair, find the corresponding
    928      1.1  christos    bincl in the list.  Return the partial symtab associated
    929      1.1  christos    with that header_file_location.  */
    930      1.1  christos 
    931      1.1  christos static struct partial_symtab *
    932      1.1  christos find_corresponding_bincl_psymtab (char *name, int instance)
    933      1.1  christos {
    934      1.1  christos   struct header_file_location *bincl;
    935      1.1  christos 
    936      1.1  christos   for (bincl = bincl_list; bincl < next_bincl; bincl++)
    937      1.1  christos     if (bincl->instance == instance
    938      1.1  christos 	&& strcmp (name, bincl->name) == 0)
    939      1.1  christos       return bincl->pst;
    940      1.1  christos 
    941      1.1  christos   repeated_header_complaint (name, symnum);
    942      1.1  christos   return (struct partial_symtab *) 0;
    943      1.1  christos }
    944      1.1  christos 
    945      1.1  christos /* Free the storage allocated for the bincl list.  */
    946      1.1  christos 
    947      1.1  christos static void
    948      1.1  christos free_bincl_list (struct objfile *objfile)
    949      1.1  christos {
    950      1.1  christos   xfree (bincl_list);
    951      1.1  christos   bincls_allocated = 0;
    952      1.1  christos }
    953      1.1  christos 
    954      1.1  christos static void
    955      1.1  christos do_free_bincl_list_cleanup (void *objfile)
    956      1.1  christos {
    957      1.1  christos   free_bincl_list (objfile);
    958      1.1  christos }
    959      1.1  christos 
    960      1.1  christos static struct cleanup *
    961      1.1  christos make_cleanup_free_bincl_list (struct objfile *objfile)
    962      1.1  christos {
    963      1.1  christos   return make_cleanup (do_free_bincl_list_cleanup, objfile);
    964      1.1  christos }
    965      1.1  christos 
    966      1.1  christos /* Set namestring based on nlist.  If the string table index is invalid,
    967      1.1  christos    give a fake name, and print a single error message per symbol file read,
    968      1.1  christos    rather than abort the symbol reading or flood the user with messages.  */
    969      1.1  christos 
    970      1.1  christos static char *
    971      1.1  christos set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
    972      1.1  christos {
    973      1.1  christos   char *namestring;
    974      1.1  christos 
    975      1.1  christos   if (nlist->n_strx + file_string_table_offset
    976      1.1  christos       >= DBX_STRINGTAB_SIZE (objfile)
    977      1.1  christos       || nlist->n_strx + file_string_table_offset < nlist->n_strx)
    978      1.1  christos     {
    979      1.1  christos       complaint (&symfile_complaints,
    980      1.1  christos 		 _("bad string table offset in symbol %d"),
    981      1.1  christos 		 symnum);
    982      1.1  christos       namestring = "<bad string table offset>";
    983      1.1  christos     }
    984      1.1  christos   else
    985      1.1  christos     namestring = (nlist->n_strx + file_string_table_offset
    986      1.1  christos 		  + DBX_STRINGTAB (objfile));
    987      1.1  christos   return namestring;
    988      1.1  christos }
    989      1.1  christos 
    990      1.1  christos /* Scan a SunOs dynamic symbol table for symbols of interest and
    991      1.1  christos    add them to the minimal symbol table.  */
    992      1.1  christos 
    993      1.1  christos static void
    994      1.1  christos read_dbx_dynamic_symtab (struct objfile *objfile)
    995      1.1  christos {
    996      1.1  christos   bfd *abfd = objfile->obfd;
    997      1.1  christos   struct cleanup *back_to;
    998      1.1  christos   int counter;
    999      1.1  christos   long dynsym_size;
   1000      1.1  christos   long dynsym_count;
   1001      1.1  christos   asymbol **dynsyms;
   1002      1.1  christos   asymbol **symptr;
   1003      1.1  christos   arelent **relptr;
   1004      1.1  christos   long dynrel_size;
   1005      1.1  christos   long dynrel_count;
   1006      1.1  christos   arelent **dynrels;
   1007      1.1  christos   CORE_ADDR sym_value;
   1008      1.1  christos   const char *name;
   1009      1.1  christos 
   1010      1.1  christos   /* Check that the symbol file has dynamic symbols that we know about.
   1011      1.1  christos      bfd_arch_unknown can happen if we are reading a sun3 symbol file
   1012      1.1  christos      on a sun4 host (and vice versa) and bfd is not configured
   1013      1.1  christos      --with-target=all.  This would trigger an assertion in bfd/sunos.c,
   1014      1.1  christos      so we ignore the dynamic symbols in this case.  */
   1015      1.1  christos   if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
   1016      1.1  christos       || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
   1017      1.1  christos       || bfd_get_arch (abfd) == bfd_arch_unknown)
   1018      1.1  christos     return;
   1019      1.1  christos 
   1020      1.1  christos   dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
   1021      1.1  christos   if (dynsym_size < 0)
   1022      1.1  christos     return;
   1023      1.1  christos 
   1024      1.1  christos   dynsyms = (asymbol **) xmalloc (dynsym_size);
   1025      1.1  christos   back_to = make_cleanup (xfree, dynsyms);
   1026      1.1  christos 
   1027      1.1  christos   dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
   1028      1.1  christos   if (dynsym_count < 0)
   1029      1.1  christos     {
   1030      1.1  christos       do_cleanups (back_to);
   1031      1.1  christos       return;
   1032      1.1  christos     }
   1033      1.1  christos 
   1034      1.1  christos   /* Enter dynamic symbols into the minimal symbol table
   1035      1.1  christos      if this is a stripped executable.  */
   1036      1.1  christos   if (bfd_get_symcount (abfd) <= 0)
   1037      1.1  christos     {
   1038      1.1  christos       symptr = dynsyms;
   1039      1.1  christos       for (counter = 0; counter < dynsym_count; counter++, symptr++)
   1040      1.1  christos 	{
   1041      1.1  christos 	  asymbol *sym = *symptr;
   1042      1.1  christos 	  asection *sec;
   1043      1.1  christos 	  int type;
   1044      1.1  christos 
   1045      1.1  christos 	  sec = bfd_get_section (sym);
   1046      1.1  christos 
   1047      1.1  christos 	  /* BFD symbols are section relative.  */
   1048      1.1  christos 	  sym_value = sym->value + sec->vma;
   1049      1.1  christos 
   1050      1.1  christos 	  if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
   1051      1.1  christos 	    {
   1052      1.1  christos 	      type = N_TEXT;
   1053      1.1  christos 	    }
   1054      1.1  christos 	  else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
   1055      1.1  christos 	    {
   1056      1.1  christos 	      type = N_DATA;
   1057      1.1  christos 	    }
   1058      1.1  christos 	  else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
   1059      1.1  christos 	    {
   1060      1.1  christos 	      type = N_BSS;
   1061      1.1  christos 	    }
   1062      1.1  christos 	  else
   1063      1.1  christos 	    continue;
   1064      1.1  christos 
   1065      1.1  christos 	  if (sym->flags & BSF_GLOBAL)
   1066      1.1  christos 	    type |= N_EXT;
   1067      1.1  christos 
   1068      1.1  christos 	  record_minimal_symbol (bfd_asymbol_name (sym), sym_value,
   1069      1.1  christos 				 type, objfile);
   1070      1.1  christos 	}
   1071      1.1  christos     }
   1072      1.1  christos 
   1073      1.1  christos   /* Symbols from shared libraries have a dynamic relocation entry
   1074      1.1  christos      that points to the associated slot in the procedure linkage table.
   1075      1.1  christos      We make a mininal symbol table entry with type mst_solib_trampoline
   1076      1.1  christos      at the address in the procedure linkage table.  */
   1077      1.1  christos   dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
   1078      1.1  christos   if (dynrel_size < 0)
   1079      1.1  christos     {
   1080      1.1  christos       do_cleanups (back_to);
   1081      1.1  christos       return;
   1082      1.1  christos     }
   1083      1.1  christos 
   1084      1.1  christos   dynrels = (arelent **) xmalloc (dynrel_size);
   1085      1.1  christos   make_cleanup (xfree, dynrels);
   1086      1.1  christos 
   1087      1.1  christos   dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
   1088      1.1  christos   if (dynrel_count < 0)
   1089      1.1  christos     {
   1090      1.1  christos       do_cleanups (back_to);
   1091  1.1.1.2  christos       return;
   1092      1.1  christos     }
   1093      1.1  christos 
   1094      1.1  christos   for (counter = 0, relptr = dynrels;
   1095      1.1  christos        counter < dynrel_count;
   1096      1.1  christos        counter++, relptr++)
   1097      1.1  christos     {
   1098      1.1  christos       arelent *rel = *relptr;
   1099      1.1  christos       CORE_ADDR address = rel->address;
   1100      1.1  christos 
   1101      1.1  christos       switch (bfd_get_arch (abfd))
   1102      1.1  christos 	{
   1103      1.1  christos 	case bfd_arch_sparc:
   1104      1.1  christos 	  if (rel->howto->type != RELOC_JMP_SLOT)
   1105      1.1  christos 	    continue;
   1106      1.1  christos 	  break;
   1107      1.1  christos 	case bfd_arch_m68k:
   1108      1.1  christos 	  /* `16' is the type BFD produces for a jump table relocation.  */
   1109      1.1  christos 	  if (rel->howto->type != 16)
   1110      1.1  christos 	    continue;
   1111      1.1  christos 
   1112      1.1  christos 	  /* Adjust address in the jump table to point to
   1113      1.1  christos 	     the start of the bsr instruction.  */
   1114      1.1  christos 	  address -= 2;
   1115      1.1  christos 	  break;
   1116      1.1  christos 	default:
   1117      1.1  christos 	  continue;
   1118      1.1  christos 	}
   1119      1.1  christos 
   1120      1.1  christos       name = bfd_asymbol_name (*rel->sym_ptr_ptr);
   1121      1.1  christos       prim_record_minimal_symbol (name, address, mst_solib_trampoline,
   1122      1.1  christos 				  objfile);
   1123      1.1  christos     }
   1124  1.1.1.2  christos 
   1125      1.1  christos   do_cleanups (back_to);
   1126      1.1  christos }
   1127      1.1  christos 
   1128      1.1  christos static CORE_ADDR
   1129      1.1  christos find_stab_function_addr (char *namestring, const char *filename,
   1130      1.1  christos 			 struct objfile *objfile)
   1131      1.1  christos {
   1132      1.1  christos   struct bound_minimal_symbol msym;
   1133      1.1  christos   char *p;
   1134      1.1  christos   int n;
   1135      1.1  christos 
   1136      1.1  christos   p = strchr (namestring, ':');
   1137  1.1.1.2  christos   if (p == NULL)
   1138      1.1  christos     p = namestring;
   1139      1.1  christos   n = p - namestring;
   1140      1.1  christos   p = alloca (n + 2);
   1141      1.1  christos   strncpy (p, namestring, n);
   1142      1.1  christos   p[n] = 0;
   1143      1.1  christos 
   1144      1.1  christos   msym = lookup_minimal_symbol (p, filename, objfile);
   1145      1.1  christos   if (msym.minsym == NULL)
   1146      1.1  christos     {
   1147  1.1.1.2  christos       /* Sun Fortran appends an underscore to the minimal symbol name,
   1148      1.1  christos          try again with an appended underscore if the minimal symbol
   1149      1.1  christos          was not found.  */
   1150      1.1  christos       p[n] = '_';
   1151      1.1  christos       p[n + 1] = 0;
   1152      1.1  christos       msym = lookup_minimal_symbol (p, filename, objfile);
   1153  1.1.1.2  christos     }
   1154      1.1  christos 
   1155      1.1  christos   if (msym.minsym == NULL && filename != NULL)
   1156      1.1  christos     {
   1157      1.1  christos       /* Try again without the filename.  */
   1158      1.1  christos       p[n] = 0;
   1159      1.1  christos       msym = lookup_minimal_symbol (p, NULL, objfile);
   1160      1.1  christos     }
   1161  1.1.1.2  christos   if (msym.minsym == NULL && filename != NULL)
   1162      1.1  christos     {
   1163      1.1  christos       /* And try again for Sun Fortran, but without the filename.  */
   1164      1.1  christos       p[n] = '_';
   1165      1.1  christos       p[n + 1] = 0;
   1166      1.1  christos       msym = lookup_minimal_symbol (p, NULL, objfile);
   1167      1.1  christos     }
   1168      1.1  christos 
   1169      1.1  christos   return msym.minsym == NULL ? 0 : BMSYMBOL_VALUE_ADDRESS (msym);
   1170      1.1  christos }
   1171      1.1  christos 
   1172      1.1  christos static void
   1173      1.1  christos function_outside_compilation_unit_complaint (const char *arg1)
   1174      1.1  christos {
   1175      1.1  christos   complaint (&symfile_complaints,
   1176      1.1  christos 	     _("function `%s' appears to be defined "
   1177      1.1  christos 	       "outside of all compilation units"),
   1178      1.1  christos 	     arg1);
   1179      1.1  christos }
   1180      1.1  christos 
   1181      1.1  christos /* Setup partial_symtab's describing each source file for which
   1182      1.1  christos    debugging information is available.  */
   1183      1.1  christos 
   1184      1.1  christos static void
   1185      1.1  christos read_dbx_symtab (struct objfile *objfile)
   1186      1.1  christos {
   1187      1.1  christos   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   1188      1.1  christos   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
   1189      1.1  christos   struct internal_nlist nlist;
   1190      1.1  christos   CORE_ADDR text_addr;
   1191      1.1  christos   int text_size;
   1192      1.1  christos   char *sym_name;
   1193      1.1  christos   int sym_len;
   1194      1.1  christos 
   1195      1.1  christos   char *namestring;
   1196      1.1  christos   int nsl;
   1197      1.1  christos   int past_first_source_file = 0;
   1198      1.1  christos   CORE_ADDR last_function_start = 0;
   1199      1.1  christos   struct cleanup *back_to;
   1200      1.1  christos   bfd *abfd;
   1201      1.1  christos   int textlow_not_set;
   1202      1.1  christos   int data_sect_index;
   1203      1.1  christos 
   1204      1.1  christos   /* Current partial symtab.  */
   1205      1.1  christos   struct partial_symtab *pst;
   1206      1.1  christos 
   1207      1.1  christos   /* List of current psymtab's include files.  */
   1208      1.1  christos   const char **psymtab_include_list;
   1209      1.1  christos   int includes_allocated;
   1210      1.1  christos   int includes_used;
   1211      1.1  christos 
   1212      1.1  christos   /* Index within current psymtab dependency list.  */
   1213      1.1  christos   struct partial_symtab **dependency_list;
   1214      1.1  christos   int dependencies_used, dependencies_allocated;
   1215      1.1  christos 
   1216      1.1  christos   text_addr = DBX_TEXT_ADDR (objfile);
   1217      1.1  christos   text_size = DBX_TEXT_SIZE (objfile);
   1218      1.1  christos 
   1219      1.1  christos   /* FIXME.  We probably want to change stringtab_global rather than add this
   1220      1.1  christos      while processing every symbol entry.  FIXME.  */
   1221      1.1  christos   file_string_table_offset = 0;
   1222      1.1  christos   next_file_string_table_offset = 0;
   1223      1.1  christos 
   1224      1.1  christos   stringtab_global = DBX_STRINGTAB (objfile);
   1225      1.1  christos 
   1226      1.1  christos   pst = (struct partial_symtab *) 0;
   1227      1.1  christos 
   1228      1.1  christos   includes_allocated = 30;
   1229      1.1  christos   includes_used = 0;
   1230      1.1  christos   psymtab_include_list = (const char **) alloca (includes_allocated *
   1231      1.1  christos 						 sizeof (const char *));
   1232      1.1  christos 
   1233      1.1  christos   dependencies_allocated = 30;
   1234      1.1  christos   dependencies_used = 0;
   1235      1.1  christos   dependency_list =
   1236      1.1  christos     (struct partial_symtab **) alloca (dependencies_allocated *
   1237      1.1  christos 				       sizeof (struct partial_symtab *));
   1238      1.1  christos 
   1239      1.1  christos   /* Init bincl list */
   1240      1.1  christos   init_bincl_list (20, objfile);
   1241      1.1  christos   back_to = make_cleanup_free_bincl_list (objfile);
   1242      1.1  christos 
   1243      1.1  christos   set_last_source_file (NULL);
   1244      1.1  christos 
   1245      1.1  christos   lowest_text_address = (CORE_ADDR) -1;
   1246      1.1  christos 
   1247      1.1  christos   symfile_bfd = objfile->obfd;	/* For next_text_symbol.  */
   1248      1.1  christos   abfd = objfile->obfd;
   1249      1.1  christos   symbuf_end = symbuf_idx = 0;
   1250      1.1  christos   next_symbol_text_func = dbx_next_symbol_text;
   1251      1.1  christos   textlow_not_set = 1;
   1252      1.1  christos   has_line_numbers = 0;
   1253      1.1  christos 
   1254      1.1  christos   /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
   1255      1.1  christos      to global and static variables.  The stab for a global or static
   1256      1.1  christos      variable doesn't give us any indication of which section it's in,
   1257      1.1  christos      so we can't tell immediately which offset in
   1258      1.1  christos      objfile->section_offsets we should apply to the variable's
   1259      1.1  christos      address.
   1260      1.1  christos 
   1261      1.1  christos      We could certainly find out which section contains the variable
   1262      1.1  christos      by looking up the variable's unrelocated address with
   1263      1.1  christos      find_pc_section, but that would be expensive; this is the
   1264      1.1  christos      function that constructs the partial symbol tables by examining
   1265      1.1  christos      every symbol in the entire executable, and it's
   1266      1.1  christos      performance-critical.  So that expense would not be welcome.  I'm
   1267      1.1  christos      not sure what to do about this at the moment.
   1268      1.1  christos 
   1269      1.1  christos      What we have done for years is to simply assume that the .data
   1270      1.1  christos      section's offset is appropriate for all global and static
   1271      1.1  christos      variables.  Recently, this was expanded to fall back to the .bss
   1272      1.1  christos      section's offset if there is no .data section, and then to the
   1273      1.1  christos      .rodata section's offset.  */
   1274      1.1  christos   data_sect_index = objfile->sect_index_data;
   1275      1.1  christos   if (data_sect_index == -1)
   1276      1.1  christos     data_sect_index = SECT_OFF_BSS (objfile);
   1277      1.1  christos   if (data_sect_index == -1)
   1278      1.1  christos     data_sect_index = SECT_OFF_RODATA (objfile);
   1279      1.1  christos 
   1280      1.1  christos   /* If data_sect_index is still -1, that's okay.  It's perfectly fine
   1281      1.1  christos      for the file to have no .data, no .bss, and no .text at all, if
   1282      1.1  christos      it also has no global or static variables.  If it does, we will
   1283      1.1  christos      get an internal error from an ANOFFSET macro below when we try to
   1284      1.1  christos      use data_sect_index.  */
   1285      1.1  christos 
   1286      1.1  christos   for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
   1287      1.1  christos     {
   1288      1.1  christos       /* Get the symbol for this run and pull out some info.  */
   1289      1.1  christos       QUIT;			/* Allow this to be interruptable.  */
   1290      1.1  christos       if (symbuf_idx == symbuf_end)
   1291      1.1  christos 	fill_symbuf (abfd);
   1292      1.1  christos       bufp = &symbuf[symbuf_idx++];
   1293      1.1  christos 
   1294      1.1  christos       /*
   1295      1.1  christos        * Special case to speed up readin.
   1296      1.1  christos        */
   1297      1.1  christos       if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
   1298      1.1  christos 	{
   1299      1.1  christos 	  has_line_numbers = 1;
   1300      1.1  christos 	  continue;
   1301      1.1  christos 	}
   1302      1.1  christos 
   1303      1.1  christos       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   1304      1.1  christos       OBJSTAT (objfile, n_stabs++);
   1305      1.1  christos 
   1306      1.1  christos       /* Ok.  There is a lot of code duplicated in the rest of this
   1307      1.1  christos          switch statement (for efficiency reasons).  Since I don't
   1308      1.1  christos          like duplicating code, I will do my penance here, and
   1309      1.1  christos          describe the code which is duplicated:
   1310      1.1  christos 
   1311      1.1  christos          *) The assignment to namestring.
   1312      1.1  christos          *) The call to strchr.
   1313      1.1  christos          *) The addition of a partial symbol the two partial
   1314      1.1  christos          symbol lists.  This last is a large section of code, so
   1315      1.1  christos          I've imbedded it in the following macro.  */
   1316      1.1  christos 
   1317      1.1  christos       switch (nlist.n_type)
   1318      1.1  christos 	{
   1319      1.1  christos 	  /*
   1320      1.1  christos 	   * Standard, external, non-debugger, symbols
   1321      1.1  christos 	   */
   1322      1.1  christos 
   1323      1.1  christos 	case N_TEXT | N_EXT:
   1324      1.1  christos 	case N_NBTEXT | N_EXT:
   1325      1.1  christos 	  goto record_it;
   1326      1.1  christos 
   1327      1.1  christos 	case N_DATA | N_EXT:
   1328      1.1  christos 	case N_NBDATA | N_EXT:
   1329      1.1  christos 	  goto record_it;
   1330      1.1  christos 
   1331      1.1  christos 	case N_BSS:
   1332      1.1  christos 	case N_BSS | N_EXT:
   1333      1.1  christos 	case N_NBBSS | N_EXT:
   1334      1.1  christos 	case N_SETV | N_EXT:		/* FIXME, is this in BSS? */
   1335      1.1  christos 	  goto record_it;
   1336      1.1  christos 
   1337      1.1  christos 	case N_ABS | N_EXT:
   1338      1.1  christos 	  record_it:
   1339      1.1  christos 	  namestring = set_namestring (objfile, &nlist);
   1340      1.1  christos 
   1341      1.1  christos 	  record_minimal_symbol (namestring, nlist.n_value,
   1342      1.1  christos 				 nlist.n_type, objfile);	/* Always */
   1343      1.1  christos 	  continue;
   1344      1.1  christos 
   1345      1.1  christos 	  /* Standard, local, non-debugger, symbols.  */
   1346      1.1  christos 
   1347      1.1  christos 	case N_NBTEXT:
   1348      1.1  christos 
   1349      1.1  christos 	  /* We need to be able to deal with both N_FN or N_TEXT,
   1350      1.1  christos 	     because we have no way of knowing whether the sys-supplied ld
   1351      1.1  christos 	     or GNU ld was used to make the executable.  Sequents throw
   1352      1.1  christos 	     in another wrinkle -- they renumbered N_FN.  */
   1353      1.1  christos 
   1354      1.1  christos 	case N_FN:
   1355  1.1.1.2  christos 	case N_FN_SEQ:
   1356  1.1.1.2  christos 	case N_TEXT:
   1357  1.1.1.2  christos 	  namestring = set_namestring (objfile, &nlist);
   1358      1.1  christos 
   1359      1.1  christos 	  if ((namestring[0] == '-' && namestring[1] == 'l')
   1360      1.1  christos 	      || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
   1361      1.1  christos 		  && namestring[nsl - 2] == '.'))
   1362      1.1  christos 	    {
   1363      1.1  christos 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1364      1.1  christos 					 SECT_OFF_TEXT (objfile));
   1365      1.1  christos 
   1366      1.1  christos 	      if (past_first_source_file && pst
   1367      1.1  christos 		  /* The gould NP1 uses low values for .o and -l symbols
   1368      1.1  christos 		     which are not the address.  */
   1369      1.1  christos 		  && nlist.n_value >= pst->textlow)
   1370      1.1  christos 		{
   1371      1.1  christos 		  end_psymtab (objfile, pst, psymtab_include_list,
   1372      1.1  christos 			       includes_used, symnum * symbol_size,
   1373      1.1  christos 			       nlist.n_value > pst->texthigh
   1374      1.1  christos 			       ? nlist.n_value : pst->texthigh,
   1375      1.1  christos 			       dependency_list, dependencies_used,
   1376      1.1  christos 			       textlow_not_set);
   1377      1.1  christos 		  pst = (struct partial_symtab *) 0;
   1378      1.1  christos 		  includes_used = 0;
   1379      1.1  christos 		  dependencies_used = 0;
   1380      1.1  christos 		  has_line_numbers = 0;
   1381      1.1  christos 		}
   1382      1.1  christos 	      else
   1383      1.1  christos 		past_first_source_file = 1;
   1384      1.1  christos 	    }
   1385      1.1  christos 	  else
   1386      1.1  christos 	    goto record_it;
   1387      1.1  christos 	  continue;
   1388      1.1  christos 
   1389      1.1  christos 	case N_DATA:
   1390      1.1  christos 	  goto record_it;
   1391      1.1  christos 
   1392      1.1  christos 	case N_UNDF | N_EXT:
   1393      1.1  christos 	  /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
   1394      1.1  christos 	     We used to rely on the target to tell us whether it knows
   1395      1.1  christos 	     where the symbol has been relocated to, but none of the
   1396      1.1  christos 	     target implementations actually provided that operation.
   1397      1.1  christos 	     So we just ignore the symbol, the same way we would do if
   1398      1.1  christos 	     we had a target-side symbol lookup which returned no match.
   1399      1.1  christos 
   1400      1.1  christos 	     All other symbols (with nlist.n_value == 0), are really
   1401      1.1  christos 	     undefined, and so we ignore them too.  */
   1402      1.1  christos 	  continue;
   1403      1.1  christos 
   1404      1.1  christos 	case N_UNDF:
   1405      1.1  christos 	  if (processing_acc_compilation && nlist.n_strx == 1)
   1406      1.1  christos 	    {
   1407      1.1  christos 	      /* Deal with relative offsets in the string table
   1408      1.1  christos 		 used in ELF+STAB under Solaris.  If we want to use the
   1409      1.1  christos 		 n_strx field, which contains the name of the file,
   1410      1.1  christos 		 we must adjust file_string_table_offset *before* calling
   1411      1.1  christos 		 set_namestring().  */
   1412      1.1  christos 	      past_first_source_file = 1;
   1413      1.1  christos 	      file_string_table_offset = next_file_string_table_offset;
   1414      1.1  christos 	      next_file_string_table_offset =
   1415      1.1  christos 		file_string_table_offset + nlist.n_value;
   1416      1.1  christos 	      if (next_file_string_table_offset < file_string_table_offset)
   1417      1.1  christos 		error (_("string table offset backs up at %d"), symnum);
   1418      1.1  christos 	      /* FIXME -- replace error() with complaint.  */
   1419      1.1  christos 	      continue;
   1420      1.1  christos 	    }
   1421      1.1  christos 	  continue;
   1422      1.1  christos 
   1423      1.1  christos 	  /* Lots of symbol types we can just ignore.  */
   1424      1.1  christos 
   1425      1.1  christos 	case N_ABS:
   1426      1.1  christos 	case N_NBDATA:
   1427      1.1  christos 	case N_NBBSS:
   1428      1.1  christos 	  continue;
   1429      1.1  christos 
   1430      1.1  christos 	  /* Keep going . . .  */
   1431      1.1  christos 
   1432      1.1  christos 	  /*
   1433      1.1  christos 	   * Special symbol types for GNU
   1434      1.1  christos 	   */
   1435      1.1  christos 	case N_INDR:
   1436      1.1  christos 	case N_INDR | N_EXT:
   1437      1.1  christos 	case N_SETA:
   1438      1.1  christos 	case N_SETA | N_EXT:
   1439      1.1  christos 	case N_SETT:
   1440      1.1  christos 	case N_SETT | N_EXT:
   1441      1.1  christos 	case N_SETD:
   1442      1.1  christos 	case N_SETD | N_EXT:
   1443      1.1  christos 	case N_SETB:
   1444      1.1  christos 	case N_SETB | N_EXT:
   1445      1.1  christos 	case N_SETV:
   1446      1.1  christos 	  continue;
   1447      1.1  christos 
   1448      1.1  christos 	  /*
   1449      1.1  christos 	   * Debugger symbols
   1450      1.1  christos 	   */
   1451      1.1  christos 
   1452      1.1  christos 	case N_SO:
   1453      1.1  christos 	  {
   1454      1.1  christos 	    CORE_ADDR valu;
   1455      1.1  christos 	    static int prev_so_symnum = -10;
   1456      1.1  christos 	    static int first_so_symnum;
   1457      1.1  christos 	    const char *p;
   1458      1.1  christos 	    static char *dirname_nso;
   1459      1.1  christos 	    int prev_textlow_not_set;
   1460      1.1  christos 
   1461      1.1  christos 	    valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
   1462      1.1  christos 					     SECT_OFF_TEXT (objfile));
   1463      1.1  christos 
   1464      1.1  christos 	    prev_textlow_not_set = textlow_not_set;
   1465      1.1  christos 
   1466      1.1  christos 	    /* A zero value is probably an indication for the SunPRO 3.0
   1467      1.1  christos 	       compiler.  end_psymtab explicitly tests for zero, so
   1468      1.1  christos 	       don't relocate it.  */
   1469      1.1  christos 
   1470      1.1  christos 	    if (nlist.n_value == 0
   1471      1.1  christos 		&& gdbarch_sofun_address_maybe_missing (gdbarch))
   1472      1.1  christos 	      {
   1473      1.1  christos 		textlow_not_set = 1;
   1474      1.1  christos 		valu = 0;
   1475      1.1  christos 	      }
   1476      1.1  christos 	    else
   1477      1.1  christos 	      textlow_not_set = 0;
   1478      1.1  christos 
   1479      1.1  christos 	    past_first_source_file = 1;
   1480      1.1  christos 
   1481      1.1  christos 	    if (prev_so_symnum != symnum - 1)
   1482      1.1  christos 	      {			/* Here if prev stab wasn't N_SO.  */
   1483      1.1  christos 		first_so_symnum = symnum;
   1484      1.1  christos 
   1485      1.1  christos 		if (pst)
   1486      1.1  christos 		  {
   1487      1.1  christos 		    end_psymtab (objfile, pst, psymtab_include_list,
   1488      1.1  christos 				 includes_used, symnum * symbol_size,
   1489      1.1  christos 				 valu > pst->texthigh ? valu : pst->texthigh,
   1490      1.1  christos 				 dependency_list, dependencies_used,
   1491      1.1  christos 				 prev_textlow_not_set);
   1492      1.1  christos 		    pst = (struct partial_symtab *) 0;
   1493      1.1  christos 		    includes_used = 0;
   1494      1.1  christos 		    dependencies_used = 0;
   1495      1.1  christos 		    has_line_numbers = 0;
   1496      1.1  christos 		  }
   1497      1.1  christos 	      }
   1498      1.1  christos 
   1499      1.1  christos 	    prev_so_symnum = symnum;
   1500      1.1  christos 
   1501      1.1  christos 	    /* End the current partial symtab and start a new one.  */
   1502      1.1  christos 
   1503      1.1  christos 	    namestring = set_namestring (objfile, &nlist);
   1504      1.1  christos 
   1505      1.1  christos 	    /* Null name means end of .o file.  Don't start a new one.  */
   1506      1.1  christos 	    if (*namestring == '\000')
   1507      1.1  christos 	      continue;
   1508      1.1  christos 
   1509      1.1  christos 	    /* Some compilers (including gcc) emit a pair of initial N_SOs.
   1510      1.1  christos 	       The first one is a directory name; the second the file name.
   1511      1.1  christos 	       If pst exists, is empty, and has a filename ending in '/',
   1512      1.1  christos 	       we assume the previous N_SO was a directory name.  */
   1513      1.1  christos 
   1514      1.1  christos 	    p = lbasename (namestring);
   1515      1.1  christos 	    if (p != namestring && *p == '\000')
   1516      1.1  christos 	      {
   1517      1.1  christos 		/* Save the directory name SOs locally, then save it into
   1518      1.1  christos 		   the psymtab when it's created below.  */
   1519      1.1  christos 	        dirname_nso = namestring;
   1520      1.1  christos 	        continue;
   1521      1.1  christos 	      }
   1522      1.1  christos 
   1523      1.1  christos 	    /* Some other compilers (C++ ones in particular) emit useless
   1524      1.1  christos 	       SOs for non-existant .c files.  We ignore all subsequent SOs
   1525      1.1  christos 	       that immediately follow the first.  */
   1526      1.1  christos 
   1527      1.1  christos 	    if (!pst)
   1528      1.1  christos 	      {
   1529      1.1  christos 		pst = start_psymtab (objfile,
   1530      1.1  christos 				     namestring, valu,
   1531      1.1  christos 				     first_so_symnum * symbol_size,
   1532      1.1  christos 				     objfile->global_psymbols.next,
   1533      1.1  christos 				     objfile->static_psymbols.next);
   1534      1.1  christos 		pst->dirname = dirname_nso;
   1535      1.1  christos 		dirname_nso = NULL;
   1536      1.1  christos 	      }
   1537      1.1  christos 	    continue;
   1538      1.1  christos 	  }
   1539      1.1  christos 
   1540      1.1  christos 	case N_BINCL:
   1541      1.1  christos 	  {
   1542      1.1  christos 	    enum language tmp_language;
   1543      1.1  christos 
   1544      1.1  christos 	    /* Add this bincl to the bincl_list for future EXCLs.  No
   1545      1.1  christos 	       need to save the string; it'll be around until
   1546      1.1  christos 	       read_dbx_symtab function returns.  */
   1547      1.1  christos 
   1548      1.1  christos 	    namestring = set_namestring (objfile, &nlist);
   1549      1.1  christos 	    tmp_language = deduce_language_from_filename (namestring);
   1550      1.1  christos 
   1551      1.1  christos 	    /* Only change the psymtab's language if we've learned
   1552      1.1  christos 	       something useful (eg. tmp_language is not language_unknown).
   1553      1.1  christos 	       In addition, to match what start_subfile does, never change
   1554      1.1  christos 	       from C++ to C.  */
   1555      1.1  christos 	    if (tmp_language != language_unknown
   1556      1.1  christos 		&& (tmp_language != language_c
   1557      1.1  christos 		    || psymtab_language != language_cplus))
   1558      1.1  christos 	      psymtab_language = tmp_language;
   1559      1.1  christos 
   1560      1.1  christos 	    if (pst == NULL)
   1561      1.1  christos 	      {
   1562      1.1  christos 		/* FIXME: we should not get here without a PST to work on.
   1563      1.1  christos 		   Attempt to recover.  */
   1564      1.1  christos 		complaint (&symfile_complaints,
   1565      1.1  christos 			   _("N_BINCL %s not in entries for "
   1566      1.1  christos 			     "any file, at symtab pos %d"),
   1567      1.1  christos 			   namestring, symnum);
   1568      1.1  christos 		continue;
   1569      1.1  christos 	      }
   1570      1.1  christos 	    add_bincl_to_list (pst, namestring, nlist.n_value);
   1571      1.1  christos 
   1572      1.1  christos 	    /* Mark down an include file in the current psymtab.  */
   1573      1.1  christos 
   1574      1.1  christos 	    goto record_include_file;
   1575      1.1  christos 	  }
   1576      1.1  christos 
   1577      1.1  christos 	case N_SOL:
   1578      1.1  christos 	  {
   1579      1.1  christos 	    enum language tmp_language;
   1580      1.1  christos 
   1581      1.1  christos 	    /* Mark down an include file in the current psymtab.  */
   1582      1.1  christos 	    namestring = set_namestring (objfile, &nlist);
   1583      1.1  christos 	    tmp_language = deduce_language_from_filename (namestring);
   1584      1.1  christos 
   1585      1.1  christos 	    /* Only change the psymtab's language if we've learned
   1586      1.1  christos 	       something useful (eg. tmp_language is not language_unknown).
   1587      1.1  christos 	       In addition, to match what start_subfile does, never change
   1588      1.1  christos 	       from C++ to C.  */
   1589      1.1  christos 	    if (tmp_language != language_unknown
   1590      1.1  christos 		&& (tmp_language != language_c
   1591      1.1  christos 		    || psymtab_language != language_cplus))
   1592      1.1  christos 	      psymtab_language = tmp_language;
   1593      1.1  christos 
   1594      1.1  christos 	    /* In C++, one may expect the same filename to come round many
   1595      1.1  christos 	       times, when code is coming alternately from the main file
   1596      1.1  christos 	       and from inline functions in other files.  So I check to see
   1597      1.1  christos 	       if this is a file we've seen before -- either the main
   1598      1.1  christos 	       source file, or a previously included file.
   1599      1.1  christos 
   1600      1.1  christos 	       This seems to be a lot of time to be spending on N_SOL, but
   1601      1.1  christos 	       things like "break c-exp.y:435" need to work (I
   1602      1.1  christos 	       suppose the psymtab_include_list could be hashed or put
   1603      1.1  christos 	       in a binary tree, if profiling shows this is a major hog).  */
   1604      1.1  christos 	    if (pst && filename_cmp (namestring, pst->filename) == 0)
   1605      1.1  christos 	      continue;
   1606      1.1  christos 	    {
   1607      1.1  christos 	      int i;
   1608      1.1  christos 
   1609      1.1  christos 	      for (i = 0; i < includes_used; i++)
   1610      1.1  christos 		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
   1611      1.1  christos 		  {
   1612      1.1  christos 		    i = -1;
   1613      1.1  christos 		    break;
   1614      1.1  christos 		  }
   1615      1.1  christos 	      if (i == -1)
   1616      1.1  christos 		continue;
   1617      1.1  christos 	    }
   1618      1.1  christos 
   1619      1.1  christos 	  record_include_file:
   1620      1.1  christos 
   1621      1.1  christos 	    psymtab_include_list[includes_used++] = namestring;
   1622      1.1  christos 	    if (includes_used >= includes_allocated)
   1623      1.1  christos 	      {
   1624      1.1  christos 		const char **orig = psymtab_include_list;
   1625      1.1  christos 
   1626      1.1  christos 		psymtab_include_list = (const char **)
   1627      1.1  christos 		  alloca ((includes_allocated *= 2) * sizeof (const char *));
   1628      1.1  christos 		memcpy (psymtab_include_list, orig,
   1629      1.1  christos 			includes_used * sizeof (const char *));
   1630      1.1  christos 	      }
   1631      1.1  christos 	    continue;
   1632      1.1  christos 	  }
   1633      1.1  christos 	case N_LSYM:		/* Typedef or automatic variable.  */
   1634      1.1  christos 	case N_STSYM:		/* Data seg var -- static.  */
   1635      1.1  christos 	case N_LCSYM:		/* BSS      "  */
   1636      1.1  christos 	case N_ROSYM:		/* Read-only data seg var -- static.  */
   1637      1.1  christos 	case N_NBSTS:		/* Gould nobase.  */
   1638      1.1  christos 	case N_NBLCS:		/* symbols.  */
   1639      1.1  christos 	case N_FUN:
   1640      1.1  christos 	case N_GSYM:		/* Global (extern) variable; can be
   1641      1.1  christos 				   data or bss (sigh FIXME).  */
   1642      1.1  christos 
   1643      1.1  christos 	  /* Following may probably be ignored; I'll leave them here
   1644      1.1  christos 	     for now (until I do Pascal and Modula 2 extensions).  */
   1645      1.1  christos 
   1646      1.1  christos 	case N_PC:		/* I may or may not need this; I
   1647      1.1  christos 				   suspect not.  */
   1648      1.1  christos 	case N_M2C:		/* I suspect that I can ignore this here.  */
   1649      1.1  christos 	case N_SCOPE:		/* Same.   */
   1650      1.1  christos 	{
   1651      1.1  christos 	  char *p;
   1652      1.1  christos 
   1653      1.1  christos 	  namestring = set_namestring (objfile, &nlist);
   1654      1.1  christos 
   1655      1.1  christos 	  /* See if this is an end of function stab.  */
   1656      1.1  christos 	  if (pst && nlist.n_type == N_FUN && *namestring == '\000')
   1657      1.1  christos 	    {
   1658      1.1  christos 	      CORE_ADDR valu;
   1659      1.1  christos 
   1660      1.1  christos 	      /* It's value is the size (in bytes) of the function for
   1661      1.1  christos 		 function relative stabs, or the address of the function's
   1662      1.1  christos 		 end for old style stabs.  */
   1663      1.1  christos 	      valu = nlist.n_value + last_function_start;
   1664      1.1  christos 	      if (pst->texthigh == 0 || valu > pst->texthigh)
   1665      1.1  christos 		pst->texthigh = valu;
   1666      1.1  christos 	      break;
   1667      1.1  christos 	    }
   1668      1.1  christos 
   1669      1.1  christos 	  p = (char *) strchr (namestring, ':');
   1670      1.1  christos 	  if (!p)
   1671      1.1  christos 	    continue;		/* Not a debugging symbol.   */
   1672      1.1  christos 
   1673      1.1  christos  	  sym_len = 0;
   1674      1.1  christos 	  sym_name = NULL;	/* pacify "gcc -Werror" */
   1675      1.1  christos  	  if (psymtab_language == language_cplus)
   1676      1.1  christos  	    {
   1677      1.1  christos  	      char *new_name, *name = xmalloc (p - namestring + 1);
   1678      1.1  christos  	      memcpy (name, namestring, p - namestring);
   1679      1.1  christos 
   1680      1.1  christos  	      name[p - namestring] = '\0';
   1681      1.1  christos  	      new_name = cp_canonicalize_string (name);
   1682      1.1  christos  	      if (new_name != NULL)
   1683      1.1  christos  		{
   1684      1.1  christos  		  sym_len = strlen (new_name);
   1685      1.1  christos  		  sym_name = obstack_copy0 (&objfile->objfile_obstack,
   1686      1.1  christos 					    new_name, sym_len);
   1687      1.1  christos  		  xfree (new_name);
   1688      1.1  christos  		}
   1689      1.1  christos               xfree (name);
   1690      1.1  christos  	    }
   1691      1.1  christos 
   1692      1.1  christos  	  if (sym_len == 0)
   1693      1.1  christos  	    {
   1694      1.1  christos  	      sym_name = namestring;
   1695      1.1  christos  	      sym_len = p - namestring;
   1696      1.1  christos  	    }
   1697      1.1  christos 
   1698      1.1  christos 	  /* Main processing section for debugging symbols which
   1699      1.1  christos 	     the initial read through the symbol tables needs to worry
   1700      1.1  christos 	     about.  If we reach this point, the symbol which we are
   1701      1.1  christos 	     considering is definitely one we are interested in.
   1702      1.1  christos 	     p must also contain the (valid) index into the namestring
   1703      1.1  christos 	     which indicates the debugging type symbol.  */
   1704      1.1  christos 
   1705      1.1  christos 	  switch (p[1])
   1706      1.1  christos 	    {
   1707      1.1  christos 	    case 'S':
   1708      1.1  christos 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1709      1.1  christos 					 data_sect_index);
   1710      1.1  christos 
   1711      1.1  christos 	      if (gdbarch_static_transform_name_p (gdbarch))
   1712      1.1  christos 		gdbarch_static_transform_name (gdbarch, namestring);
   1713      1.1  christos 
   1714      1.1  christos 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1715      1.1  christos 				   VAR_DOMAIN, LOC_STATIC,
   1716      1.1  christos 				   &objfile->static_psymbols,
   1717      1.1  christos 				   0, nlist.n_value,
   1718      1.1  christos 				   psymtab_language, objfile);
   1719      1.1  christos 	      continue;
   1720      1.1  christos 
   1721      1.1  christos 	    case 'G':
   1722      1.1  christos 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1723      1.1  christos 					 data_sect_index);
   1724      1.1  christos 	      /* The addresses in these entries are reported to be
   1725      1.1  christos 		 wrong.  See the code that reads 'G's for symtabs.  */
   1726      1.1  christos 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1727      1.1  christos 				   VAR_DOMAIN, LOC_STATIC,
   1728      1.1  christos 				   &objfile->global_psymbols,
   1729      1.1  christos 				   0, nlist.n_value,
   1730      1.1  christos 				   psymtab_language, objfile);
   1731      1.1  christos 	      continue;
   1732      1.1  christos 
   1733      1.1  christos 	    case 'T':
   1734      1.1  christos 	      /* When a 'T' entry is defining an anonymous enum, it
   1735      1.1  christos 		 may have a name which is the empty string, or a
   1736      1.1  christos 		 single space.  Since they're not really defining a
   1737      1.1  christos 		 symbol, those shouldn't go in the partial symbol
   1738      1.1  christos 		 table.  We do pick up the elements of such enums at
   1739      1.1  christos 		 'check_enum:', below.  */
   1740      1.1  christos 	      if (p >= namestring + 2
   1741      1.1  christos 		  || (p == namestring + 1
   1742      1.1  christos 		      && namestring[0] != ' '))
   1743      1.1  christos 		{
   1744      1.1  christos 		  add_psymbol_to_list (sym_name, sym_len, 1,
   1745      1.1  christos 				       STRUCT_DOMAIN, LOC_TYPEDEF,
   1746      1.1  christos 				       &objfile->static_psymbols,
   1747      1.1  christos 				       nlist.n_value, 0,
   1748      1.1  christos 				       psymtab_language, objfile);
   1749      1.1  christos 		  if (p[2] == 't')
   1750      1.1  christos 		    {
   1751      1.1  christos 		      /* Also a typedef with the same name.  */
   1752      1.1  christos 		      add_psymbol_to_list (sym_name, sym_len, 1,
   1753      1.1  christos 					   VAR_DOMAIN, LOC_TYPEDEF,
   1754      1.1  christos 					   &objfile->static_psymbols,
   1755      1.1  christos 					   nlist.n_value, 0,
   1756      1.1  christos 					   psymtab_language, objfile);
   1757      1.1  christos 		      p += 1;
   1758      1.1  christos 		    }
   1759      1.1  christos 		}
   1760      1.1  christos 	      goto check_enum;
   1761      1.1  christos 
   1762      1.1  christos 	    case 't':
   1763      1.1  christos 	      if (p != namestring)	/* a name is there, not just :T...  */
   1764      1.1  christos 		{
   1765      1.1  christos 		  add_psymbol_to_list (sym_name, sym_len, 1,
   1766      1.1  christos 				       VAR_DOMAIN, LOC_TYPEDEF,
   1767      1.1  christos 				       &objfile->static_psymbols,
   1768      1.1  christos 				       nlist.n_value, 0,
   1769      1.1  christos 				       psymtab_language, objfile);
   1770      1.1  christos 		}
   1771      1.1  christos 	    check_enum:
   1772      1.1  christos 	      /* If this is an enumerated type, we need to
   1773      1.1  christos 		 add all the enum constants to the partial symbol
   1774      1.1  christos 		 table.  This does not cover enums without names, e.g.
   1775      1.1  christos 		 "enum {a, b} c;" in C, but fortunately those are
   1776      1.1  christos 		 rare.  There is no way for GDB to find those from the
   1777      1.1  christos 		 enum type without spending too much time on it.  Thus
   1778      1.1  christos 		 to solve this problem, the compiler needs to put out the
   1779      1.1  christos 		 enum in a nameless type.  GCC2 does this.  */
   1780      1.1  christos 
   1781      1.1  christos 	      /* We are looking for something of the form
   1782      1.1  christos 		 <name> ":" ("t" | "T") [<number> "="] "e"
   1783      1.1  christos 		 {<constant> ":" <value> ","} ";".  */
   1784      1.1  christos 
   1785      1.1  christos 	      /* Skip over the colon and the 't' or 'T'.  */
   1786      1.1  christos 	      p += 2;
   1787      1.1  christos 	      /* This type may be given a number.  Also, numbers can come
   1788      1.1  christos 		 in pairs like (0,26).  Skip over it.  */
   1789      1.1  christos 	      while ((*p >= '0' && *p <= '9')
   1790      1.1  christos 		     || *p == '(' || *p == ',' || *p == ')'
   1791      1.1  christos 		     || *p == '=')
   1792      1.1  christos 		p++;
   1793      1.1  christos 
   1794      1.1  christos 	      if (*p++ == 'e')
   1795      1.1  christos 		{
   1796      1.1  christos 		  /* The aix4 compiler emits extra crud before the members.  */
   1797      1.1  christos 		  if (*p == '-')
   1798      1.1  christos 		    {
   1799      1.1  christos 		      /* Skip over the type (?).  */
   1800      1.1  christos 		      while (*p != ':')
   1801      1.1  christos 			p++;
   1802      1.1  christos 
   1803      1.1  christos 		      /* Skip over the colon.  */
   1804      1.1  christos 		      p++;
   1805      1.1  christos 		    }
   1806      1.1  christos 
   1807      1.1  christos 		  /* We have found an enumerated type.  */
   1808      1.1  christos 		  /* According to comments in read_enum_type
   1809      1.1  christos 		     a comma could end it instead of a semicolon.
   1810      1.1  christos 		     I don't know where that happens.
   1811      1.1  christos 		     Accept either.  */
   1812      1.1  christos 		  while (*p && *p != ';' && *p != ',')
   1813      1.1  christos 		    {
   1814      1.1  christos 		      char *q;
   1815      1.1  christos 
   1816      1.1  christos 		      /* Check for and handle cretinous dbx symbol name
   1817      1.1  christos 			 continuation!  */
   1818      1.1  christos 		      if (*p == '\\' || (*p == '?' && p[1] == '\0'))
   1819      1.1  christos 			p = next_symbol_text (objfile);
   1820      1.1  christos 
   1821      1.1  christos 		      /* Point to the character after the name
   1822      1.1  christos 			 of the enum constant.  */
   1823      1.1  christos 		      for (q = p; *q && *q != ':'; q++)
   1824      1.1  christos 			;
   1825      1.1  christos 		      /* Note that the value doesn't matter for
   1826      1.1  christos 			 enum constants in psymtabs, just in symtabs.  */
   1827      1.1  christos 		      add_psymbol_to_list (p, q - p, 1,
   1828      1.1  christos 					   VAR_DOMAIN, LOC_CONST,
   1829      1.1  christos 					   &objfile->static_psymbols, 0,
   1830      1.1  christos 					   0, psymtab_language, objfile);
   1831      1.1  christos 		      /* Point past the name.  */
   1832      1.1  christos 		      p = q;
   1833      1.1  christos 		      /* Skip over the value.  */
   1834      1.1  christos 		      while (*p && *p != ',')
   1835      1.1  christos 			p++;
   1836      1.1  christos 		      /* Advance past the comma.  */
   1837      1.1  christos 		      if (*p)
   1838      1.1  christos 			p++;
   1839      1.1  christos 		    }
   1840      1.1  christos 		}
   1841      1.1  christos 	      continue;
   1842      1.1  christos 
   1843      1.1  christos 	    case 'c':
   1844      1.1  christos 	      /* Constant, e.g. from "const" in Pascal.  */
   1845      1.1  christos 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1846      1.1  christos 				   VAR_DOMAIN, LOC_CONST,
   1847      1.1  christos 				   &objfile->static_psymbols, nlist.n_value,
   1848      1.1  christos 				   0, psymtab_language, objfile);
   1849      1.1  christos 	      continue;
   1850      1.1  christos 
   1851      1.1  christos 	    case 'f':
   1852      1.1  christos 	      if (! pst)
   1853      1.1  christos 		{
   1854      1.1  christos 		  int name_len = p - namestring;
   1855      1.1  christos 		  char *name = xmalloc (name_len + 1);
   1856      1.1  christos 
   1857      1.1  christos 		  memcpy (name, namestring, name_len);
   1858      1.1  christos 		  name[name_len] = '\0';
   1859      1.1  christos 		  function_outside_compilation_unit_complaint (name);
   1860      1.1  christos 		  xfree (name);
   1861      1.1  christos 		}
   1862      1.1  christos 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1863      1.1  christos 					 SECT_OFF_TEXT (objfile));
   1864      1.1  christos 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1865      1.1  christos 	      last_function_name = namestring;
   1866      1.1  christos 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1867      1.1  christos 		 value for the bottom of the text seg in those cases.  */
   1868      1.1  christos 	      if (nlist.n_value == ANOFFSET (objfile->section_offsets,
   1869      1.1  christos 					     SECT_OFF_TEXT (objfile))
   1870      1.1  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1871      1.1  christos 		{
   1872      1.1  christos 		  CORE_ADDR minsym_valu =
   1873      1.1  christos 		    find_stab_function_addr (namestring,
   1874      1.1  christos 					     pst ? pst->filename : NULL,
   1875      1.1  christos 					     objfile);
   1876      1.1  christos 
   1877      1.1  christos 		  /* find_stab_function_addr will return 0 if the minimal
   1878      1.1  christos 		     symbol wasn't found.  (Unfortunately, this might also
   1879      1.1  christos 		     be a valid address.)  Anyway, if it *does* return 0,
   1880      1.1  christos 		     it is likely that the value was set correctly to begin
   1881      1.1  christos 		     with...  */
   1882      1.1  christos 		  if (minsym_valu != 0)
   1883      1.1  christos 		    nlist.n_value = minsym_valu;
   1884      1.1  christos 		}
   1885      1.1  christos 	      if (pst && textlow_not_set
   1886      1.1  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1887      1.1  christos 		{
   1888      1.1  christos 		  pst->textlow = nlist.n_value;
   1889      1.1  christos 		  textlow_not_set = 0;
   1890      1.1  christos 		}
   1891      1.1  christos 	      /* End kludge.  */
   1892      1.1  christos 
   1893      1.1  christos 	      /* Keep track of the start of the last function so we
   1894      1.1  christos 		 can handle end of function symbols.  */
   1895      1.1  christos 	      last_function_start = nlist.n_value;
   1896      1.1  christos 
   1897      1.1  christos 	      /* In reordered executables this function may lie outside
   1898      1.1  christos 		 the bounds created by N_SO symbols.  If that's the case
   1899      1.1  christos 		 use the address of this function as the low bound for
   1900      1.1  christos 		 the partial symbol table.  */
   1901      1.1  christos 	      if (pst
   1902      1.1  christos 		  && (textlow_not_set
   1903      1.1  christos 		      || (nlist.n_value < pst->textlow
   1904      1.1  christos 			  && (nlist.n_value
   1905      1.1  christos 			      != ANOFFSET (objfile->section_offsets,
   1906      1.1  christos 					   SECT_OFF_TEXT (objfile))))))
   1907      1.1  christos 		{
   1908      1.1  christos 		  pst->textlow = nlist.n_value;
   1909      1.1  christos 		  textlow_not_set = 0;
   1910      1.1  christos 		}
   1911      1.1  christos 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1912      1.1  christos 				   VAR_DOMAIN, LOC_BLOCK,
   1913      1.1  christos 				   &objfile->static_psymbols,
   1914      1.1  christos 				   0, nlist.n_value,
   1915      1.1  christos 				   psymtab_language, objfile);
   1916      1.1  christos 	      continue;
   1917      1.1  christos 
   1918      1.1  christos 	      /* Global functions were ignored here, but now they
   1919      1.1  christos 		 are put into the global psymtab like one would expect.
   1920      1.1  christos 		 They're also in the minimal symbol table.  */
   1921      1.1  christos 	    case 'F':
   1922      1.1  christos 	      if (! pst)
   1923      1.1  christos 		{
   1924      1.1  christos 		  int name_len = p - namestring;
   1925      1.1  christos 		  char *name = xmalloc (name_len + 1);
   1926      1.1  christos 
   1927      1.1  christos 		  memcpy (name, namestring, name_len);
   1928      1.1  christos 		  name[name_len] = '\0';
   1929      1.1  christos 		  function_outside_compilation_unit_complaint (name);
   1930      1.1  christos 		  xfree (name);
   1931      1.1  christos 		}
   1932      1.1  christos 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1933      1.1  christos 					 SECT_OFF_TEXT (objfile));
   1934      1.1  christos 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1935      1.1  christos 	      last_function_name = namestring;
   1936      1.1  christos 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1937      1.1  christos 		 value for the bottom of the text seg in those cases.  */
   1938      1.1  christos 	      if (nlist.n_value == ANOFFSET (objfile->section_offsets,
   1939      1.1  christos 					     SECT_OFF_TEXT (objfile))
   1940      1.1  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1941      1.1  christos 		{
   1942      1.1  christos 		  CORE_ADDR minsym_valu =
   1943      1.1  christos 		    find_stab_function_addr (namestring,
   1944      1.1  christos 					     pst ? pst->filename : NULL,
   1945      1.1  christos 					     objfile);
   1946      1.1  christos 
   1947      1.1  christos 		  /* find_stab_function_addr will return 0 if the minimal
   1948      1.1  christos 		     symbol wasn't found.  (Unfortunately, this might also
   1949      1.1  christos 		     be a valid address.)  Anyway, if it *does* return 0,
   1950      1.1  christos 		     it is likely that the value was set correctly to begin
   1951      1.1  christos 		     with...  */
   1952      1.1  christos 		  if (minsym_valu != 0)
   1953      1.1  christos 		    nlist.n_value = minsym_valu;
   1954      1.1  christos 		}
   1955      1.1  christos 	      if (pst && textlow_not_set
   1956      1.1  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1957      1.1  christos 		{
   1958      1.1  christos 		  pst->textlow = nlist.n_value;
   1959      1.1  christos 		  textlow_not_set = 0;
   1960      1.1  christos 		}
   1961      1.1  christos 	      /* End kludge.  */
   1962      1.1  christos 
   1963      1.1  christos 	      /* Keep track of the start of the last function so we
   1964      1.1  christos 		 can handle end of function symbols.  */
   1965      1.1  christos 	      last_function_start = nlist.n_value;
   1966      1.1  christos 
   1967      1.1  christos 	      /* In reordered executables this function may lie outside
   1968      1.1  christos 		 the bounds created by N_SO symbols.  If that's the case
   1969      1.1  christos 		 use the address of this function as the low bound for
   1970      1.1  christos 		 the partial symbol table.  */
   1971      1.1  christos 	      if (pst
   1972      1.1  christos 		  && (textlow_not_set
   1973      1.1  christos 		      || (nlist.n_value < pst->textlow
   1974      1.1  christos 			  && (nlist.n_value
   1975      1.1  christos 			      != ANOFFSET (objfile->section_offsets,
   1976      1.1  christos 					   SECT_OFF_TEXT (objfile))))))
   1977      1.1  christos 		{
   1978      1.1  christos 		  pst->textlow = nlist.n_value;
   1979      1.1  christos 		  textlow_not_set = 0;
   1980      1.1  christos 		}
   1981      1.1  christos 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1982      1.1  christos 				   VAR_DOMAIN, LOC_BLOCK,
   1983      1.1  christos 				   &objfile->global_psymbols,
   1984      1.1  christos 				   0, nlist.n_value,
   1985      1.1  christos 				   psymtab_language, objfile);
   1986      1.1  christos 	      continue;
   1987      1.1  christos 
   1988      1.1  christos 	      /* Two things show up here (hopefully); static symbols of
   1989      1.1  christos 		 local scope (static used inside braces) or extensions
   1990      1.1  christos 		 of structure symbols.  We can ignore both.  */
   1991      1.1  christos 	    case 'V':
   1992      1.1  christos 	    case '(':
   1993      1.1  christos 	    case '0':
   1994      1.1  christos 	    case '1':
   1995      1.1  christos 	    case '2':
   1996      1.1  christos 	    case '3':
   1997      1.1  christos 	    case '4':
   1998      1.1  christos 	    case '5':
   1999      1.1  christos 	    case '6':
   2000      1.1  christos 	    case '7':
   2001      1.1  christos 	    case '8':
   2002      1.1  christos 	    case '9':
   2003      1.1  christos 	    case '-':
   2004      1.1  christos 	    case '#':	/* For symbol identification (used in live ranges).  */
   2005      1.1  christos 	      continue;
   2006      1.1  christos 
   2007      1.1  christos 	    case ':':
   2008      1.1  christos 	      /* It is a C++ nested symbol.  We don't need to record it
   2009      1.1  christos 		 (I don't think); if we try to look up foo::bar::baz,
   2010      1.1  christos 		 then symbols for the symtab containing foo should get
   2011      1.1  christos 		 read in, I think.  */
   2012      1.1  christos 	      /* Someone says sun cc puts out symbols like
   2013      1.1  christos 		 /foo/baz/maclib::/usr/local/bin/maclib,
   2014      1.1  christos 		 which would get here with a symbol type of ':'.  */
   2015      1.1  christos 	      continue;
   2016      1.1  christos 
   2017      1.1  christos 	    default:
   2018      1.1  christos 	      /* Unexpected symbol descriptor.  The second and subsequent stabs
   2019      1.1  christos 		 of a continued stab can show up here.  The question is
   2020      1.1  christos 		 whether they ever can mimic a normal stab--it would be
   2021      1.1  christos 		 nice if not, since we certainly don't want to spend the
   2022      1.1  christos 		 time searching to the end of every string looking for
   2023      1.1  christos 		 a backslash.  */
   2024      1.1  christos 
   2025      1.1  christos 	      complaint (&symfile_complaints,
   2026      1.1  christos 			 _("unknown symbol descriptor `%c'"),
   2027      1.1  christos 			 p[1]);
   2028      1.1  christos 
   2029      1.1  christos 	      /* Ignore it; perhaps it is an extension that we don't
   2030      1.1  christos 		 know about.  */
   2031      1.1  christos 	      continue;
   2032      1.1  christos 	    }
   2033      1.1  christos 	}
   2034      1.1  christos 
   2035      1.1  christos 	case N_EXCL:
   2036      1.1  christos 
   2037      1.1  christos 	  namestring = set_namestring (objfile, &nlist);
   2038      1.1  christos 
   2039      1.1  christos 	  /* Find the corresponding bincl and mark that psymtab on the
   2040      1.1  christos 	     psymtab dependency list.  */
   2041      1.1  christos 	  {
   2042      1.1  christos 	    struct partial_symtab *needed_pst =
   2043      1.1  christos 	      find_corresponding_bincl_psymtab (namestring, nlist.n_value);
   2044      1.1  christos 
   2045      1.1  christos 	    /* If this include file was defined earlier in this file,
   2046      1.1  christos 	       leave it alone.  */
   2047      1.1  christos 	    if (needed_pst == pst)
   2048      1.1  christos 	      continue;
   2049      1.1  christos 
   2050      1.1  christos 	    if (needed_pst)
   2051      1.1  christos 	      {
   2052      1.1  christos 		int i;
   2053      1.1  christos 		int found = 0;
   2054      1.1  christos 
   2055      1.1  christos 		for (i = 0; i < dependencies_used; i++)
   2056      1.1  christos 		  if (dependency_list[i] == needed_pst)
   2057      1.1  christos 		    {
   2058      1.1  christos 		      found = 1;
   2059      1.1  christos 		      break;
   2060      1.1  christos 		    }
   2061      1.1  christos 
   2062      1.1  christos 		/* If it's already in the list, skip the rest.  */
   2063      1.1  christos 		if (found)
   2064      1.1  christos 		  continue;
   2065      1.1  christos 
   2066      1.1  christos 		dependency_list[dependencies_used++] = needed_pst;
   2067      1.1  christos 		if (dependencies_used >= dependencies_allocated)
   2068      1.1  christos 		  {
   2069      1.1  christos 		    struct partial_symtab **orig = dependency_list;
   2070      1.1  christos 
   2071      1.1  christos 		    dependency_list =
   2072      1.1  christos 		      (struct partial_symtab **)
   2073      1.1  christos 		      alloca ((dependencies_allocated *= 2)
   2074      1.1  christos 			      * sizeof (struct partial_symtab *));
   2075      1.1  christos 		    memcpy (dependency_list, orig,
   2076      1.1  christos 			    (dependencies_used
   2077      1.1  christos 			     * sizeof (struct partial_symtab *)));
   2078      1.1  christos #ifdef DEBUG_INFO
   2079      1.1  christos 		    fprintf_unfiltered (gdb_stderr,
   2080      1.1  christos 					"Had to reallocate "
   2081      1.1  christos 					"dependency list.\n");
   2082      1.1  christos 		    fprintf_unfiltered (gdb_stderr,
   2083      1.1  christos 					"New dependencies allocated: %d\n",
   2084      1.1  christos 					dependencies_allocated);
   2085      1.1  christos #endif
   2086      1.1  christos 		  }
   2087      1.1  christos 	      }
   2088      1.1  christos 	  }
   2089      1.1  christos 	  continue;
   2090      1.1  christos 
   2091      1.1  christos 	case N_ENDM:
   2092      1.1  christos 	  /* Solaris 2 end of module, finish current partial symbol table.
   2093      1.1  christos 	     end_psymtab will set pst->texthigh to the proper value, which
   2094      1.1  christos 	     is necessary if a module compiled without debugging info
   2095      1.1  christos 	     follows this module.  */
   2096      1.1  christos 	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
   2097      1.1  christos 	    {
   2098      1.1  christos 	      end_psymtab (objfile, pst, psymtab_include_list, includes_used,
   2099      1.1  christos 			   symnum * symbol_size,
   2100      1.1  christos 			   (CORE_ADDR) 0, dependency_list,
   2101      1.1  christos 			   dependencies_used, textlow_not_set);
   2102      1.1  christos 	      pst = (struct partial_symtab *) 0;
   2103      1.1  christos 	      includes_used = 0;
   2104      1.1  christos 	      dependencies_used = 0;
   2105      1.1  christos 	      has_line_numbers = 0;
   2106      1.1  christos 	    }
   2107      1.1  christos 	  continue;
   2108      1.1  christos 
   2109      1.1  christos 	case N_RBRAC:
   2110      1.1  christos #ifdef HANDLE_RBRAC
   2111      1.1  christos 	  HANDLE_RBRAC (nlist.n_value);
   2112      1.1  christos 	  continue;
   2113      1.1  christos #endif
   2114      1.1  christos 	case N_EINCL:
   2115      1.1  christos 	case N_DSLINE:
   2116      1.1  christos 	case N_BSLINE:
   2117      1.1  christos 	case N_SSYM:		/* Claim: Structure or union element.
   2118      1.1  christos 				   Hopefully, I can ignore this.  */
   2119      1.1  christos 	case N_ENTRY:		/* Alternate entry point; can ignore.  */
   2120      1.1  christos 	case N_MAIN:		/* Can definitely ignore this.   */
   2121      1.1  christos 	case N_CATCH:		/* These are GNU C++ extensions */
   2122      1.1  christos 	case N_EHDECL:		/* that can safely be ignored here.  */
   2123  1.1.1.2  christos 	case N_LENG:
   2124  1.1.1.2  christos 	case N_BCOMM:
   2125      1.1  christos 	case N_ECOMM:
   2126      1.1  christos 	case N_ECOML:
   2127      1.1  christos 	case N_FNAME:
   2128      1.1  christos 	case N_SLINE:
   2129      1.1  christos 	case N_RSYM:
   2130      1.1  christos 	case N_PSYM:
   2131      1.1  christos 	case N_BNSYM:
   2132      1.1  christos 	case N_ENSYM:
   2133      1.1  christos 	case N_LBRAC:
   2134      1.1  christos 	case N_NSYMS:		/* Ultrix 4.0: symbol count */
   2135      1.1  christos 	case N_DEFD:		/* GNU Modula-2 */
   2136      1.1  christos 	case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   2137      1.1  christos 
   2138      1.1  christos 	case N_OBJ:		/* Useless types from Solaris.  */
   2139      1.1  christos 	case N_OPT:
   2140      1.1  christos 	case N_PATCH:
   2141      1.1  christos 	  /* These symbols aren't interesting; don't worry about them.  */
   2142      1.1  christos 	  continue;
   2143      1.1  christos 
   2144      1.1  christos 	default:
   2145      1.1  christos 	  /* If we haven't found it yet, ignore it.  It's probably some
   2146      1.1  christos 	     new type we don't know about yet.  */
   2147      1.1  christos 	  unknown_symtype_complaint (hex_string (nlist.n_type));
   2148      1.1  christos 	  continue;
   2149      1.1  christos 	}
   2150      1.1  christos     }
   2151      1.1  christos 
   2152      1.1  christos   /* If there's stuff to be cleaned up, clean it up.  */
   2153      1.1  christos   if (pst)
   2154      1.1  christos     {
   2155      1.1  christos       /* Don't set pst->texthigh lower than it already is.  */
   2156      1.1  christos       CORE_ADDR text_end =
   2157      1.1  christos 	(lowest_text_address == (CORE_ADDR) -1
   2158      1.1  christos 	 ? (text_addr + ANOFFSET (objfile->section_offsets,
   2159      1.1  christos 				  SECT_OFF_TEXT (objfile)))
   2160      1.1  christos 	 : lowest_text_address)
   2161      1.1  christos 	+ text_size;
   2162      1.1  christos 
   2163      1.1  christos       end_psymtab (objfile, pst, psymtab_include_list, includes_used,
   2164      1.1  christos 		   symnum * symbol_size,
   2165      1.1  christos 		   text_end > pst->texthigh ? text_end : pst->texthigh,
   2166      1.1  christos 		   dependency_list, dependencies_used, textlow_not_set);
   2167      1.1  christos     }
   2168      1.1  christos 
   2169      1.1  christos   do_cleanups (back_to);
   2170      1.1  christos }
   2171      1.1  christos 
   2172      1.1  christos /* Allocate and partially fill a partial symtab.  It will be
   2173      1.1  christos    completely filled at the end of the symbol list.
   2174      1.1  christos 
   2175      1.1  christos    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
   2176      1.1  christos    is the address relative to which its symbols are (incremental) or 0
   2177      1.1  christos    (normal).  */
   2178      1.1  christos 
   2179      1.1  christos static struct partial_symtab *
   2180      1.1  christos start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
   2181      1.1  christos 	       int ldsymoff, struct partial_symbol **global_syms,
   2182      1.1  christos 	       struct partial_symbol **static_syms)
   2183      1.1  christos {
   2184      1.1  christos   struct partial_symtab *result =
   2185      1.1  christos     start_psymtab_common (objfile, objfile->section_offsets,
   2186      1.1  christos 			  filename, textlow, global_syms, static_syms);
   2187      1.1  christos 
   2188      1.1  christos   result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
   2189      1.1  christos 					       sizeof (struct symloc));
   2190      1.1  christos   LDSYMOFF (result) = ldsymoff;
   2191      1.1  christos   result->read_symtab = dbx_read_symtab;
   2192      1.1  christos   SYMBOL_SIZE (result) = symbol_size;
   2193      1.1  christos   SYMBOL_OFFSET (result) = symbol_table_offset;
   2194      1.1  christos   STRING_OFFSET (result) = string_table_offset;
   2195      1.1  christos   FILE_STRING_OFFSET (result) = file_string_table_offset;
   2196      1.1  christos 
   2197      1.1  christos #ifdef HAVE_ELF
   2198      1.1  christos   /* If we're handling an ELF file, drag some section-relocation info
   2199      1.1  christos      for this source file out of the ELF symbol table, to compensate for
   2200      1.1  christos      Sun brain death.  This replaces the section_offsets in this psymtab,
   2201      1.1  christos      if successful.  */
   2202      1.1  christos   elfstab_offset_sections (objfile, result);
   2203      1.1  christos #endif
   2204      1.1  christos 
   2205      1.1  christos   /* Deduce the source language from the filename for this psymtab.  */
   2206      1.1  christos   psymtab_language = deduce_language_from_filename (filename);
   2207      1.1  christos 
   2208      1.1  christos   return result;
   2209      1.1  christos }
   2210      1.1  christos 
   2211      1.1  christos /* Close off the current usage of PST.
   2212      1.1  christos    Returns PST or NULL if the partial symtab was empty and thrown away.
   2213      1.1  christos 
   2214      1.1  christos    FIXME:  List variables and peculiarities of same.  */
   2215      1.1  christos 
   2216      1.1  christos struct partial_symtab *
   2217      1.1  christos end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
   2218      1.1  christos 	     const char **include_list, int num_includes,
   2219      1.1  christos 	     int capping_symbol_offset, CORE_ADDR capping_text,
   2220      1.1  christos 	     struct partial_symtab **dependency_list, int number_dependencies,
   2221      1.1  christos 	     int textlow_not_set)
   2222      1.1  christos {
   2223      1.1  christos   int i;
   2224      1.1  christos   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   2225      1.1  christos 
   2226      1.1  christos   if (capping_symbol_offset != -1)
   2227      1.1  christos     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
   2228      1.1  christos   pst->texthigh = capping_text;
   2229      1.1  christos 
   2230      1.1  christos   /* Under Solaris, the N_SO symbols always have a value of 0,
   2231      1.1  christos      instead of the usual address of the .o file.  Therefore,
   2232      1.1  christos      we have to do some tricks to fill in texthigh and textlow.
   2233      1.1  christos      The first trick is: if we see a static
   2234      1.1  christos      or global function, and the textlow for the current pst
   2235      1.1  christos      is not set (ie: textlow_not_set), then we use that function's
   2236      1.1  christos      address for the textlow of the pst.  */
   2237      1.1  christos 
   2238      1.1  christos   /* Now, to fill in texthigh, we remember the last function seen
   2239      1.1  christos      in the .o file.  Also, there's a hack in
   2240      1.1  christos      bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
   2241      1.1  christos      to here via the misc_info field.  Therefore, we can fill in
   2242  1.1.1.2  christos      a reliable texthigh by taking the address plus size of the
   2243      1.1  christos      last function in the file.  */
   2244      1.1  christos 
   2245      1.1  christos   if (pst->texthigh == 0 && last_function_name
   2246      1.1  christos       && gdbarch_sofun_address_maybe_missing (gdbarch))
   2247      1.1  christos     {
   2248      1.1  christos       char *p;
   2249      1.1  christos       int n;
   2250      1.1  christos       struct bound_minimal_symbol minsym;
   2251      1.1  christos 
   2252      1.1  christos       p = strchr (last_function_name, ':');
   2253  1.1.1.2  christos       if (p == NULL)
   2254      1.1  christos 	p = last_function_name;
   2255      1.1  christos       n = p - last_function_name;
   2256      1.1  christos       p = alloca (n + 2);
   2257      1.1  christos       strncpy (p, last_function_name, n);
   2258      1.1  christos       p[n] = 0;
   2259      1.1  christos 
   2260      1.1  christos       minsym = lookup_minimal_symbol (p, pst->filename, objfile);
   2261      1.1  christos       if (minsym.minsym == NULL)
   2262      1.1  christos 	{
   2263  1.1.1.2  christos 	  /* Sun Fortran appends an underscore to the minimal symbol name,
   2264  1.1.1.2  christos 	     try again with an appended underscore if the minimal symbol
   2265  1.1.1.2  christos 	     was not found.  */
   2266      1.1  christos 	  p[n] = '_';
   2267      1.1  christos 	  p[n + 1] = 0;
   2268      1.1  christos 	  minsym = lookup_minimal_symbol (p, pst->filename, objfile);
   2269      1.1  christos 	}
   2270      1.1  christos 
   2271      1.1  christos       if (minsym.minsym)
   2272      1.1  christos 	pst->texthigh = (BMSYMBOL_VALUE_ADDRESS (minsym)
   2273      1.1  christos 			 + MSYMBOL_SIZE (minsym.minsym));
   2274      1.1  christos 
   2275      1.1  christos       last_function_name = NULL;
   2276      1.1  christos     }
   2277      1.1  christos 
   2278      1.1  christos   if (!gdbarch_sofun_address_maybe_missing (gdbarch))
   2279      1.1  christos     ;
   2280      1.1  christos   /* This test will be true if the last .o file is only data.  */
   2281      1.1  christos   else if (textlow_not_set)
   2282      1.1  christos     pst->textlow = pst->texthigh;
   2283      1.1  christos   else
   2284      1.1  christos     {
   2285      1.1  christos       struct partial_symtab *p1;
   2286      1.1  christos 
   2287      1.1  christos       /* If we know our own starting text address, then walk through all other
   2288      1.1  christos          psymtabs for this objfile, and if any didn't know their ending text
   2289      1.1  christos          address, set it to our starting address.  Take care to not set our
   2290      1.1  christos          own ending address to our starting address, nor to set addresses on
   2291      1.1  christos          `dependency' files that have both textlow and texthigh zero.  */
   2292      1.1  christos 
   2293      1.1  christos       ALL_OBJFILE_PSYMTABS (objfile, p1)
   2294      1.1  christos       {
   2295      1.1  christos 	if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
   2296      1.1  christos 	  {
   2297      1.1  christos 	    p1->texthigh = pst->textlow;
   2298      1.1  christos 	    /* If this file has only data, then make textlow match
   2299      1.1  christos 	       texthigh.  */
   2300      1.1  christos 	    if (p1->textlow == 0)
   2301      1.1  christos 	      p1->textlow = p1->texthigh;
   2302      1.1  christos 	  }
   2303      1.1  christos       }
   2304      1.1  christos     }
   2305      1.1  christos 
   2306      1.1  christos   /* End of kludge for patching Solaris textlow and texthigh.  */
   2307      1.1  christos 
   2308      1.1  christos   pst->n_global_syms =
   2309      1.1  christos     objfile->global_psymbols.next - (objfile->global_psymbols.list
   2310      1.1  christos 				     + pst->globals_offset);
   2311      1.1  christos   pst->n_static_syms =
   2312      1.1  christos     objfile->static_psymbols.next - (objfile->static_psymbols.list
   2313      1.1  christos 				     + pst->statics_offset);
   2314      1.1  christos 
   2315      1.1  christos   pst->number_of_dependencies = number_dependencies;
   2316      1.1  christos   if (number_dependencies)
   2317      1.1  christos     {
   2318      1.1  christos       pst->dependencies = (struct partial_symtab **)
   2319      1.1  christos 	obstack_alloc (&objfile->objfile_obstack,
   2320      1.1  christos 		       number_dependencies * sizeof (struct partial_symtab *));
   2321      1.1  christos       memcpy (pst->dependencies, dependency_list,
   2322      1.1  christos 	      number_dependencies * sizeof (struct partial_symtab *));
   2323      1.1  christos     }
   2324      1.1  christos   else
   2325      1.1  christos     pst->dependencies = 0;
   2326      1.1  christos 
   2327      1.1  christos   for (i = 0; i < num_includes; i++)
   2328      1.1  christos     {
   2329      1.1  christos       struct partial_symtab *subpst =
   2330      1.1  christos 	allocate_psymtab (include_list[i], objfile);
   2331      1.1  christos 
   2332      1.1  christos       /* Copy the sesction_offsets array from the main psymtab.  */
   2333      1.1  christos       subpst->section_offsets = pst->section_offsets;
   2334      1.1  christos       subpst->read_symtab_private =
   2335      1.1  christos 	obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
   2336      1.1  christos       LDSYMOFF (subpst) =
   2337      1.1  christos 	LDSYMLEN (subpst) =
   2338      1.1  christos 	subpst->textlow =
   2339      1.1  christos 	subpst->texthigh = 0;
   2340      1.1  christos 
   2341      1.1  christos       /* We could save slight bits of space by only making one of these,
   2342      1.1  christos          shared by the entire set of include files.  FIXME-someday.  */
   2343      1.1  christos       subpst->dependencies = (struct partial_symtab **)
   2344      1.1  christos 	obstack_alloc (&objfile->objfile_obstack,
   2345      1.1  christos 		       sizeof (struct partial_symtab *));
   2346      1.1  christos       subpst->dependencies[0] = pst;
   2347  1.1.1.2  christos       subpst->number_of_dependencies = 1;
   2348      1.1  christos 
   2349      1.1  christos       subpst->globals_offset =
   2350      1.1  christos 	subpst->n_global_syms =
   2351      1.1  christos 	subpst->statics_offset =
   2352      1.1  christos 	subpst->n_static_syms = 0;
   2353      1.1  christos 
   2354      1.1  christos       subpst->readin = 0;
   2355      1.1  christos       subpst->compunit_symtab = 0;
   2356      1.1  christos       subpst->read_symtab = pst->read_symtab;
   2357      1.1  christos     }
   2358      1.1  christos 
   2359      1.1  christos   sort_pst_symbols (objfile, pst);
   2360      1.1  christos 
   2361      1.1  christos   if (num_includes == 0
   2362      1.1  christos       && number_dependencies == 0
   2363      1.1  christos       && pst->n_global_syms == 0
   2364      1.1  christos       && pst->n_static_syms == 0
   2365      1.1  christos       && has_line_numbers == 0)
   2366      1.1  christos     {
   2367      1.1  christos       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
   2368      1.1  christos          it is on the obstack, but we can forget to chain it on the list.  */
   2369      1.1  christos       /* Empty psymtabs happen as a result of header files which don't have
   2370      1.1  christos          any symbols in them.  There can be a lot of them.  But this check
   2371      1.1  christos          is wrong, in that a psymtab with N_SLINE entries but nothing else
   2372      1.1  christos          is not empty, but we don't realize that.  Fixing that without slowing
   2373      1.1  christos          things down might be tricky.  */
   2374      1.1  christos 
   2375      1.1  christos       discard_psymtab (objfile, pst);
   2376      1.1  christos 
   2377      1.1  christos       /* Indicate that psymtab was thrown away.  */
   2378      1.1  christos       pst = (struct partial_symtab *) NULL;
   2379      1.1  christos     }
   2380      1.1  christos   return pst;
   2381      1.1  christos }
   2382      1.1  christos 
   2383      1.1  christos static void
   2385      1.1  christos dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst)
   2386      1.1  christos {
   2387      1.1  christos   struct cleanup *old_chain;
   2388      1.1  christos   int i;
   2389      1.1  christos 
   2390      1.1  christos   if (pst->readin)
   2391      1.1  christos     {
   2392      1.1  christos       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  "
   2393      1.1  christos 			  "Shouldn't happen.\n",
   2394      1.1  christos 			  pst->filename);
   2395      1.1  christos       return;
   2396      1.1  christos     }
   2397      1.1  christos 
   2398      1.1  christos   /* Read in all partial symtabs on which this one is dependent.  */
   2399      1.1  christos   for (i = 0; i < pst->number_of_dependencies; i++)
   2400      1.1  christos     if (!pst->dependencies[i]->readin)
   2401      1.1  christos       {
   2402      1.1  christos 	/* Inform about additional files that need to be read in.  */
   2403      1.1  christos 	if (info_verbose)
   2404      1.1  christos 	  {
   2405      1.1  christos 	    fputs_filtered (" ", gdb_stdout);
   2406      1.1  christos 	    wrap_here ("");
   2407      1.1  christos 	    fputs_filtered ("and ", gdb_stdout);
   2408      1.1  christos 	    wrap_here ("");
   2409      1.1  christos 	    printf_filtered ("%s...", pst->dependencies[i]->filename);
   2410      1.1  christos 	    wrap_here ("");	/* Flush output.  */
   2411      1.1  christos 	    gdb_flush (gdb_stdout);
   2412      1.1  christos 	  }
   2413      1.1  christos 	dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]);
   2414      1.1  christos       }
   2415      1.1  christos 
   2416      1.1  christos   if (LDSYMLEN (pst))		/* Otherwise it's a dummy.  */
   2417      1.1  christos     {
   2418      1.1  christos       /* Init stuff necessary for reading in symbols */
   2419      1.1  christos       stabsread_init ();
   2420      1.1  christos       buildsym_init ();
   2421      1.1  christos       old_chain = make_cleanup (really_free_pendings, 0);
   2422      1.1  christos       file_string_table_offset = FILE_STRING_OFFSET (pst);
   2423      1.1  christos       symbol_size = SYMBOL_SIZE (pst);
   2424      1.1  christos 
   2425      1.1  christos       /* Read in this file's symbols.  */
   2426      1.1  christos       bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
   2427      1.1  christos       read_ofile_symtab (objfile, pst);
   2428      1.1  christos 
   2429      1.1  christos       do_cleanups (old_chain);
   2430      1.1  christos     }
   2431      1.1  christos 
   2432      1.1  christos   pst->readin = 1;
   2433      1.1  christos }
   2434      1.1  christos 
   2435      1.1  christos /* Read in all of the symbols for a given psymtab for real.
   2436      1.1  christos    Be verbose about it if the user wants that.  SELF is not NULL.  */
   2437      1.1  christos 
   2438      1.1  christos static void
   2439      1.1  christos dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile)
   2440      1.1  christos {
   2441      1.1  christos   bfd *sym_bfd;
   2442      1.1  christos 
   2443      1.1  christos   if (self->readin)
   2444      1.1  christos     {
   2445      1.1  christos       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  "
   2446      1.1  christos 			  "Shouldn't happen.\n",
   2447      1.1  christos 			  self->filename);
   2448      1.1  christos       return;
   2449      1.1  christos     }
   2450      1.1  christos 
   2451      1.1  christos   if (LDSYMLEN (self) || self->number_of_dependencies)
   2452      1.1  christos     {
   2453      1.1  christos       struct cleanup *back_to;
   2454      1.1  christos 
   2455      1.1  christos       /* Print the message now, before reading the string table,
   2456      1.1  christos          to avoid disconcerting pauses.  */
   2457      1.1  christos       if (info_verbose)
   2458      1.1  christos 	{
   2459      1.1  christos 	  printf_filtered ("Reading in symbols for %s...", self->filename);
   2460      1.1  christos 	  gdb_flush (gdb_stdout);
   2461      1.1  christos 	}
   2462      1.1  christos 
   2463      1.1  christos       sym_bfd = objfile->obfd;
   2464      1.1  christos 
   2465      1.1  christos       next_symbol_text_func = dbx_next_symbol_text;
   2466      1.1  christos 
   2467      1.1  christos       back_to = make_cleanup (null_cleanup, NULL);
   2468      1.1  christos 
   2469      1.1  christos       if (DBX_STAB_SECTION (objfile))
   2470      1.1  christos 	{
   2471      1.1  christos 	  stabs_data
   2472      1.1  christos 	    = symfile_relocate_debug_section (objfile,
   2473      1.1  christos 					      DBX_STAB_SECTION (objfile),
   2474      1.1  christos 					      NULL);
   2475      1.1  christos 
   2476      1.1  christos 	  if (stabs_data)
   2477      1.1  christos 	    make_cleanup (free_current_contents, (void *) &stabs_data);
   2478      1.1  christos 	}
   2479      1.1  christos 
   2480      1.1  christos       dbx_psymtab_to_symtab_1 (objfile, self);
   2481      1.1  christos 
   2482      1.1  christos       do_cleanups (back_to);
   2483      1.1  christos 
   2484      1.1  christos       /* Match with global symbols.  This only needs to be done once,
   2485      1.1  christos          after all of the symtabs and dependencies have been read in.   */
   2486      1.1  christos       scan_file_globals (objfile);
   2487      1.1  christos 
   2488      1.1  christos       /* Finish up the debug error message.  */
   2489      1.1  christos       if (info_verbose)
   2490      1.1  christos 	printf_filtered ("done.\n");
   2491      1.1  christos     }
   2492      1.1  christos }
   2493      1.1  christos 
   2494      1.1  christos /* Read in a defined section of a specific object file's symbols.  */
   2495      1.1  christos 
   2496      1.1  christos static void
   2497      1.1  christos read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
   2498      1.1  christos {
   2499      1.1  christos   char *namestring;
   2500      1.1  christos   struct external_nlist *bufp;
   2501      1.1  christos   struct internal_nlist nlist;
   2502      1.1  christos   unsigned char type;
   2503      1.1  christos   unsigned max_symnum;
   2504      1.1  christos   bfd *abfd;
   2505      1.1  christos   int sym_offset;		/* Offset to start of symbols to read */
   2506      1.1  christos   int sym_size;			/* Size of symbols to read */
   2507      1.1  christos   CORE_ADDR text_offset;	/* Start of text segment for symbols */
   2508      1.1  christos   int text_size;		/* Size of text segment for symbols */
   2509      1.1  christos   struct section_offsets *section_offsets;
   2510      1.1  christos 
   2511      1.1  christos   sym_offset = LDSYMOFF (pst);
   2512      1.1  christos   sym_size = LDSYMLEN (pst);
   2513      1.1  christos   text_offset = pst->textlow;
   2514      1.1  christos   text_size = pst->texthigh - pst->textlow;
   2515      1.1  christos   /* This cannot be simply objfile->section_offsets because of
   2516      1.1  christos      elfstab_offset_sections() which initializes the psymtab section
   2517      1.1  christos      offsets information in a special way, and that is different from
   2518      1.1  christos      objfile->section_offsets.  */
   2519      1.1  christos   section_offsets = pst->section_offsets;
   2520      1.1  christos 
   2521      1.1  christos   dbxread_objfile = objfile;
   2522      1.1  christos 
   2523      1.1  christos   stringtab_global = DBX_STRINGTAB (objfile);
   2524      1.1  christos   set_last_source_file (NULL);
   2525      1.1  christos 
   2526      1.1  christos   abfd = objfile->obfd;
   2527      1.1  christos   symfile_bfd = objfile->obfd;	/* Implicit param to next_text_symbol.  */
   2528      1.1  christos   symbuf_end = symbuf_idx = 0;
   2529      1.1  christos   symbuf_read = 0;
   2530      1.1  christos   symbuf_left = sym_offset + sym_size;
   2531      1.1  christos 
   2532      1.1  christos   /* It is necessary to actually read one symbol *before* the start
   2533      1.1  christos      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
   2534      1.1  christos      occurs before the N_SO symbol.
   2535      1.1  christos 
   2536      1.1  christos      Detecting this in read_dbx_symtab
   2537      1.1  christos      would slow down initial readin, so we look for it here instead.  */
   2538      1.1  christos   if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
   2539      1.1  christos     {
   2540      1.1  christos       stabs_seek (sym_offset - symbol_size);
   2541      1.1  christos       fill_symbuf (abfd);
   2542      1.1  christos       bufp = &symbuf[symbuf_idx++];
   2543      1.1  christos       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   2544      1.1  christos       OBJSTAT (objfile, n_stabs++);
   2545      1.1  christos 
   2546      1.1  christos       namestring = set_namestring (objfile, &nlist);
   2547      1.1  christos 
   2548      1.1  christos       processing_gcc_compilation = 0;
   2549      1.1  christos       if (nlist.n_type == N_TEXT)
   2550      1.1  christos 	{
   2551      1.1  christos 	  const char *tempstring = namestring;
   2552      1.1  christos 
   2553      1.1  christos 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
   2554      1.1  christos 	    processing_gcc_compilation = 1;
   2555      1.1  christos 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   2556      1.1  christos 	    processing_gcc_compilation = 2;
   2557      1.1  christos 	  if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
   2558      1.1  christos 	    ++tempstring;
   2559      1.1  christos 	  if (strncmp (tempstring, "__gnu_compiled", 14) == 0)
   2560      1.1  christos 	    processing_gcc_compilation = 2;
   2561      1.1  christos 	}
   2562      1.1  christos     }
   2563      1.1  christos   else
   2564      1.1  christos     {
   2565      1.1  christos       /* The N_SO starting this symtab is the first symbol, so we
   2566      1.1  christos          better not check the symbol before it.  I'm not this can
   2567      1.1  christos          happen, but it doesn't hurt to check for it.  */
   2568      1.1  christos       stabs_seek (sym_offset);
   2569      1.1  christos       processing_gcc_compilation = 0;
   2570      1.1  christos     }
   2571      1.1  christos 
   2572      1.1  christos   if (symbuf_idx == symbuf_end)
   2573      1.1  christos     fill_symbuf (abfd);
   2574      1.1  christos   bufp = &symbuf[symbuf_idx];
   2575      1.1  christos   if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
   2576      1.1  christos     error (_("First symbol in segment of executable not a source symbol"));
   2577      1.1  christos 
   2578      1.1  christos   max_symnum = sym_size / symbol_size;
   2579      1.1  christos 
   2580      1.1  christos   for (symnum = 0;
   2581      1.1  christos        symnum < max_symnum;
   2582      1.1  christos        symnum++)
   2583      1.1  christos     {
   2584      1.1  christos       QUIT;			/* Allow this to be interruptable.  */
   2585      1.1  christos       if (symbuf_idx == symbuf_end)
   2586      1.1  christos 	fill_symbuf (abfd);
   2587      1.1  christos       bufp = &symbuf[symbuf_idx++];
   2588      1.1  christos       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   2589      1.1  christos       OBJSTAT (objfile, n_stabs++);
   2590      1.1  christos 
   2591      1.1  christos       type = bfd_h_get_8 (abfd, bufp->e_type);
   2592      1.1  christos 
   2593      1.1  christos       namestring = set_namestring (objfile, &nlist);
   2594      1.1  christos 
   2595      1.1  christos       if (type & N_STAB)
   2596      1.1  christos 	{
   2597      1.1  christos 	  if (sizeof (nlist.n_value) > 4
   2598      1.1  christos 	      /* We are a 64-bit debugger debugging a 32-bit program.  */
   2599      1.1  christos 	      && (type == N_LSYM || type == N_PSYM))
   2600      1.1  christos 	      /* We have to be careful with the n_value in the case of N_LSYM
   2601      1.1  christos 		 and N_PSYM entries, because they are signed offsets from frame
   2602      1.1  christos 		 pointer, but we actually read them as unsigned 32-bit values.
   2603      1.1  christos 		 This is not a problem for 32-bit debuggers, for which negative
   2604      1.1  christos 		 values end up being interpreted correctly (as negative
   2605      1.1  christos 		 offsets) due to integer overflow.
   2606      1.1  christos 		 But we need to sign-extend the value for 64-bit debuggers,
   2607      1.1  christos 		 or we'll end up interpreting negative values as very large
   2608      1.1  christos 		 positive offsets.  */
   2609      1.1  christos 	    nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
   2610      1.1  christos 	  process_one_symbol (type, nlist.n_desc, nlist.n_value,
   2611      1.1  christos 			      namestring, section_offsets, objfile);
   2612      1.1  christos 	}
   2613      1.1  christos       /* We skip checking for a new .o or -l file; that should never
   2614      1.1  christos          happen in this routine.  */
   2615      1.1  christos       else if (type == N_TEXT)
   2616      1.1  christos 	{
   2617      1.1  christos 	  /* I don't think this code will ever be executed, because
   2618      1.1  christos 	     the GCC_COMPILED_FLAG_SYMBOL usually is right before
   2619      1.1  christos 	     the N_SO symbol which starts this source file.
   2620      1.1  christos 	     However, there is no reason not to accept
   2621      1.1  christos 	     the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
   2622      1.1  christos 
   2623      1.1  christos 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
   2624      1.1  christos 	    processing_gcc_compilation = 1;
   2625      1.1  christos 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   2626      1.1  christos 	    processing_gcc_compilation = 2;
   2627      1.1  christos 	}
   2628      1.1  christos       else if (type & N_EXT || type == (unsigned char) N_TEXT
   2629      1.1  christos 	       || type == (unsigned char) N_NBTEXT)
   2630      1.1  christos 	{
   2631      1.1  christos 	  /* Global symbol: see if we came across a dbx defintion for
   2632      1.1  christos 	     a corresponding symbol.  If so, store the value.  Remove
   2633      1.1  christos 	     syms from the chain when their values are stored, but
   2634      1.1  christos 	     search the whole chain, as there may be several syms from
   2635      1.1  christos 	     different files with the same name.  */
   2636      1.1  christos 	  /* This is probably not true.  Since the files will be read
   2637      1.1  christos 	     in one at a time, each reference to a global symbol will
   2638      1.1  christos 	     be satisfied in each file as it appears.  So we skip this
   2639      1.1  christos 	     section.  */
   2640      1.1  christos 	  ;
   2641      1.1  christos 	}
   2642      1.1  christos     }
   2643      1.1  christos 
   2644      1.1  christos   /* In a Solaris elf file, this variable, which comes from the
   2645      1.1  christos      value of the N_SO symbol, will still be 0.  Luckily, text_offset,
   2646      1.1  christos      which comes from pst->textlow is correct.  */
   2647  1.1.1.2  christos   if (last_source_start_addr == 0)
   2648  1.1.1.2  christos     last_source_start_addr = text_offset;
   2649      1.1  christos 
   2650      1.1  christos   /* In reordered executables last_source_start_addr may not be the
   2651      1.1  christos      lower bound for this symtab, instead use text_offset which comes
   2652      1.1  christos      from pst->textlow which is correct.  */
   2653      1.1  christos   if (last_source_start_addr > text_offset)
   2654      1.1  christos     last_source_start_addr = text_offset;
   2655      1.1  christos 
   2656      1.1  christos   pst->compunit_symtab = end_symtab (text_offset + text_size,
   2657      1.1  christos 				     SECT_OFF_TEXT (objfile));
   2658      1.1  christos 
   2659      1.1  christos   end_stabs ();
   2660      1.1  christos 
   2661      1.1  christos   dbxread_objfile = NULL;
   2662      1.1  christos }
   2663      1.1  christos 
   2664      1.1  christos 
   2666      1.1  christos /* Record the namespace that the function defined by SYMBOL was
   2667      1.1  christos    defined in, if necessary.  BLOCK is the associated block; use
   2668      1.1  christos    OBSTACK for allocation.  */
   2669      1.1  christos 
   2670      1.1  christos static void
   2671      1.1  christos cp_set_block_scope (const struct symbol *symbol,
   2672      1.1  christos 		    struct block *block,
   2673      1.1  christos 		    struct obstack *obstack)
   2674      1.1  christos {
   2675      1.1  christos   if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
   2676      1.1  christos     {
   2677      1.1  christos       /* Try to figure out the appropriate namespace from the
   2678      1.1  christos 	 demangled name.  */
   2679      1.1  christos 
   2680      1.1  christos       /* FIXME: carlton/2003-04-15: If the function in question is
   2681      1.1  christos 	 a method of a class, the name will actually include the
   2682      1.1  christos 	 name of the class as well.  This should be harmless, but
   2683      1.1  christos 	 is a little unfortunate.  */
   2684      1.1  christos 
   2685      1.1  christos       const char *name = SYMBOL_DEMANGLED_NAME (symbol);
   2686      1.1  christos       unsigned int prefix_len = cp_entire_prefix_len (name);
   2687      1.1  christos 
   2688      1.1  christos       block_set_scope (block,
   2689      1.1  christos 		       obstack_copy0 (obstack, name, prefix_len),
   2690      1.1  christos 		       obstack);
   2691      1.1  christos     }
   2692      1.1  christos }
   2693      1.1  christos 
   2694      1.1  christos /* This handles a single symbol from the symbol-file, building symbols
   2695      1.1  christos    into a GDB symtab.  It takes these arguments and an implicit argument.
   2696      1.1  christos 
   2697      1.1  christos    TYPE is the type field of the ".stab" symbol entry.
   2698      1.1  christos    DESC is the desc field of the ".stab" entry.
   2699      1.1  christos    VALU is the value field of the ".stab" entry.
   2700      1.1  christos    NAME is the symbol name, in our address space.
   2701      1.1  christos    SECTION_OFFSETS is a set of amounts by which the sections of this
   2702      1.1  christos    object file were relocated when it was loaded into memory.  Note
   2703      1.1  christos    that these section_offsets are not the objfile->section_offsets but
   2704      1.1  christos    the pst->section_offsets.  All symbols that refer to memory
   2705      1.1  christos    locations need to be offset by these amounts.
   2706      1.1  christos    OBJFILE is the object file from which we are reading symbols.  It
   2707      1.1  christos    is used in end_symtab.  */
   2708      1.1  christos 
   2709      1.1  christos void
   2710      1.1  christos process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
   2711      1.1  christos 		    const struct section_offsets *section_offsets,
   2712      1.1  christos 		    struct objfile *objfile)
   2713      1.1  christos {
   2714      1.1  christos   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   2715      1.1  christos   struct context_stack *new;
   2716      1.1  christos   /* This remembers the address of the start of a function.  It is
   2717      1.1  christos      used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
   2718      1.1  christos      are relative to the current function's start address.  On systems
   2719      1.1  christos      other than Solaris 2, this just holds the SECT_OFF_TEXT value,
   2720      1.1  christos      and is used to relocate these symbol types rather than
   2721      1.1  christos      SECTION_OFFSETS.  */
   2722      1.1  christos   static CORE_ADDR function_start_offset;
   2723      1.1  christos 
   2724      1.1  christos   /* This holds the address of the start of a function, without the
   2725      1.1  christos      system peculiarities of function_start_offset.  */
   2726      1.1  christos   static CORE_ADDR last_function_start;
   2727      1.1  christos 
   2728      1.1  christos   /* If this is nonzero, we've seen an N_SLINE since the start of the
   2729      1.1  christos      current function.  We use this to tell us to move the first sline
   2730      1.1  christos      to the beginning of the function regardless of what its given
   2731      1.1  christos      value is.  */
   2732      1.1  christos   static int sline_found_in_function = 1;
   2733      1.1  christos 
   2734      1.1  christos   /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
   2735      1.1  christos      source file.  Used to detect the SunPRO solaris compiler.  */
   2736      1.1  christos   static int n_opt_found;
   2737      1.1  christos 
   2738      1.1  christos   /* The stab type used for the definition of the last function.
   2739      1.1  christos      N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers.  */
   2740      1.1  christos   static int function_stab_type = 0;
   2741      1.1  christos 
   2742      1.1  christos   if (!block_address_function_relative)
   2743      1.1  christos     {
   2744      1.1  christos       /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
   2745      1.1  christos 	 function start address, so just use the text offset.  */
   2746      1.1  christos       function_start_offset =
   2747      1.1  christos 	ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2748      1.1  christos     }
   2749      1.1  christos 
   2750      1.1  christos   /* Something is wrong if we see real data before seeing a source
   2751      1.1  christos      file name.  */
   2752      1.1  christos 
   2753      1.1  christos   if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
   2754      1.1  christos     {
   2755      1.1  christos       /* Ignore any symbols which appear before an N_SO symbol.
   2756      1.1  christos          Currently no one puts symbols there, but we should deal
   2757      1.1  christos          gracefully with the case.  A complain()t might be in order,
   2758      1.1  christos          but this should not be an error ().  */
   2759      1.1  christos       return;
   2760      1.1  christos     }
   2761      1.1  christos 
   2762      1.1  christos   switch (type)
   2763      1.1  christos     {
   2764      1.1  christos     case N_FUN:
   2765      1.1  christos     case N_FNAME:
   2766      1.1  christos 
   2767      1.1  christos       if (*name == '\000')
   2768      1.1  christos 	{
   2769      1.1  christos 	  /* This N_FUN marks the end of a function.  This closes off
   2770      1.1  christos 	     the current block.  */
   2771      1.1  christos 	  struct block *block;
   2772      1.1  christos 
   2773      1.1  christos  	  if (context_stack_depth <= 0)
   2774      1.1  christos  	    {
   2775      1.1  christos 	      lbrac_mismatch_complaint (symnum);
   2776      1.1  christos  	      break;
   2777      1.1  christos  	    }
   2778      1.1  christos 
   2779      1.1  christos 	  /* The following check is added before recording line 0 at
   2780      1.1  christos 	     end of function so as to handle hand-generated stabs
   2781      1.1  christos 	     which may have an N_FUN stabs at the end of the function,
   2782      1.1  christos 	     but no N_SLINE stabs.  */
   2783      1.1  christos 	  if (sline_found_in_function)
   2784      1.1  christos 	    {
   2785      1.1  christos 	      CORE_ADDR addr = last_function_start + valu;
   2786  1.1.1.2  christos 
   2787      1.1  christos 	      record_line (current_subfile, 0,
   2788      1.1  christos 			   gdbarch_addr_bits_remove (gdbarch, addr));
   2789      1.1  christos 	    }
   2790      1.1  christos 
   2791      1.1  christos 	  within_function = 0;
   2792      1.1  christos 	  new = pop_context ();
   2793      1.1  christos 
   2794      1.1  christos 	  /* Make a block for the local symbols within.  */
   2795      1.1  christos 	  block = finish_block (new->name, &local_symbols, new->old_blocks,
   2796      1.1  christos 				new->start_addr, new->start_addr + valu);
   2797      1.1  christos 
   2798      1.1  christos 	  /* For C++, set the block's scope.  */
   2799      1.1  christos 	  if (SYMBOL_LANGUAGE (new->name) == language_cplus)
   2800      1.1  christos 	    cp_set_block_scope (new->name, block, &objfile->objfile_obstack);
   2801      1.1  christos 
   2802      1.1  christos 	  /* May be switching to an assembler file which may not be using
   2803      1.1  christos 	     block relative stabs, so reset the offset.  */
   2804      1.1  christos 	  if (block_address_function_relative)
   2805      1.1  christos 	    function_start_offset = 0;
   2806      1.1  christos 
   2807      1.1  christos 	  break;
   2808      1.1  christos 	}
   2809      1.1  christos 
   2810      1.1  christos       sline_found_in_function = 0;
   2811      1.1  christos 
   2812      1.1  christos       /* Relocate for dynamic loading.  */
   2813      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2814      1.1  christos       valu = gdbarch_addr_bits_remove (gdbarch, valu);
   2815      1.1  christos       last_function_start = valu;
   2816      1.1  christos 
   2817      1.1  christos       goto define_a_symbol;
   2818      1.1  christos 
   2819      1.1  christos     case N_LBRAC:
   2820      1.1  christos       /* This "symbol" just indicates the start of an inner lexical
   2821      1.1  christos          context within a function.  */
   2822      1.1  christos 
   2823      1.1  christos       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2824      1.1  christos       if (n_opt_found && desc == 1)
   2825      1.1  christos 	break;
   2826      1.1  christos 
   2827      1.1  christos       if (block_address_function_relative)
   2828      1.1  christos 	/* Relocate for Sun ELF acc fn-relative syms.  */
   2829      1.1  christos 	valu += function_start_offset;
   2830      1.1  christos       else
   2831      1.1  christos 	/* On most machines, the block addresses are relative to the
   2832      1.1  christos 	   N_SO, the linker did not relocate them (sigh).  */
   2833      1.1  christos 	valu += last_source_start_addr;
   2834      1.1  christos 
   2835      1.1  christos       push_context (desc, valu);
   2836      1.1  christos       break;
   2837      1.1  christos 
   2838      1.1  christos     case N_RBRAC:
   2839      1.1  christos       /* This "symbol" just indicates the end of an inner lexical
   2840      1.1  christos          context that was started with N_LBRAC.  */
   2841      1.1  christos 
   2842      1.1  christos       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2843      1.1  christos       if (n_opt_found && desc == 1)
   2844      1.1  christos 	break;
   2845      1.1  christos 
   2846      1.1  christos       if (block_address_function_relative)
   2847      1.1  christos 	/* Relocate for Sun ELF acc fn-relative syms.  */
   2848      1.1  christos 	valu += function_start_offset;
   2849      1.1  christos       else
   2850      1.1  christos 	/* On most machines, the block addresses are relative to the
   2851      1.1  christos 	   N_SO, the linker did not relocate them (sigh).  */
   2852      1.1  christos 	valu += last_source_start_addr;
   2853      1.1  christos 
   2854      1.1  christos       if (context_stack_depth <= 0)
   2855      1.1  christos 	{
   2856      1.1  christos 	  lbrac_mismatch_complaint (symnum);
   2857      1.1  christos 	  break;
   2858      1.1  christos 	}
   2859      1.1  christos 
   2860      1.1  christos       new = pop_context ();
   2861      1.1  christos       if (desc != new->depth)
   2862      1.1  christos 	lbrac_mismatch_complaint (symnum);
   2863      1.1  christos 
   2864      1.1  christos       if (local_symbols != NULL)
   2865      1.1  christos 	{
   2866      1.1  christos 	  /* GCC development snapshots from March to December of
   2867      1.1  christos 	     2000 would output N_LSYM entries after N_LBRAC
   2868      1.1  christos 	     entries.  As a consequence, these symbols are simply
   2869      1.1  christos 	     discarded.  Complain if this is the case.  */
   2870      1.1  christos 	  complaint (&symfile_complaints,
   2871      1.1  christos 		     _("misplaced N_LBRAC entry; discarding local "
   2872      1.1  christos 		       "symbols which have no enclosing block"));
   2873      1.1  christos 	}
   2874      1.1  christos       local_symbols = new->locals;
   2875      1.1  christos 
   2876      1.1  christos       if (context_stack_depth > 1)
   2877      1.1  christos 	{
   2878      1.1  christos 	  /* This is not the outermost LBRAC...RBRAC pair in the
   2879      1.1  christos 	     function, its local symbols preceded it, and are the ones
   2880      1.1  christos 	     just recovered from the context stack.  Define the block
   2881      1.1  christos 	     for them (but don't bother if the block contains no
   2882      1.1  christos 	     symbols.  Should we complain on blocks without symbols?
   2883      1.1  christos 	     I can't think of any useful purpose for them).  */
   2884      1.1  christos 	  if (local_symbols != NULL)
   2885      1.1  christos 	    {
   2886      1.1  christos 	      /* Muzzle a compiler bug that makes end < start.
   2887  1.1.1.2  christos 
   2888      1.1  christos 		 ??? Which compilers?  Is this ever harmful?.  */
   2889      1.1  christos 	      if (new->start_addr > valu)
   2890      1.1  christos 		{
   2891      1.1  christos 		  complaint (&symfile_complaints,
   2892      1.1  christos 			     _("block start larger than block end"));
   2893      1.1  christos 		  new->start_addr = valu;
   2894      1.1  christos 		}
   2895      1.1  christos 	      /* Make a block for the local symbols within.  */
   2896      1.1  christos 	      finish_block (0, &local_symbols, new->old_blocks,
   2897      1.1  christos 			    new->start_addr, valu);
   2898      1.1  christos 	    }
   2899      1.1  christos 	}
   2900      1.1  christos       else
   2901      1.1  christos 	{
   2902      1.1  christos 	  /* This is the outermost LBRAC...RBRAC pair.  There is no
   2903      1.1  christos 	     need to do anything; leave the symbols that preceded it
   2904      1.1  christos 	     to be attached to the function's own block.  We need to
   2905      1.1  christos 	     indicate that we just moved outside of the function.  */
   2906      1.1  christos 	  within_function = 0;
   2907      1.1  christos 	}
   2908      1.1  christos 
   2909      1.1  christos       break;
   2910      1.1  christos 
   2911      1.1  christos     case N_FN:
   2912      1.1  christos     case N_FN_SEQ:
   2913      1.1  christos       /* This kind of symbol indicates the start of an object file.
   2914      1.1  christos          Relocate for dynamic loading.  */
   2915      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2916      1.1  christos       break;
   2917      1.1  christos 
   2918      1.1  christos     case N_SO:
   2919      1.1  christos       /* This type of symbol indicates the start of data for one
   2920      1.1  christos          source file.  Finish the symbol table of the previous source
   2921      1.1  christos          file (if any) and start accumulating a new symbol table.
   2922      1.1  christos          Relocate for dynamic loading.  */
   2923      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2924      1.1  christos 
   2925      1.1  christos       n_opt_found = 0;
   2926      1.1  christos 
   2927      1.1  christos       if (get_last_source_file ())
   2928  1.1.1.2  christos 	{
   2929      1.1  christos 	  /* Check if previous symbol was also an N_SO (with some
   2930      1.1  christos 	     sanity checks).  If so, that one was actually the
   2931      1.1  christos 	     directory name, and the current one is the real file
   2932      1.1  christos 	     name.  Patch things up.  */
   2933      1.1  christos 	  if (previous_stab_code == (unsigned char) N_SO)
   2934      1.1  christos 	    {
   2935      1.1  christos 	      patch_subfile_names (current_subfile, name);
   2936      1.1  christos 	      break;		/* Ignore repeated SOs.  */
   2937      1.1  christos 	    }
   2938      1.1  christos 	  end_symtab (valu, SECT_OFF_TEXT (objfile));
   2939      1.1  christos 	  end_stabs ();
   2940      1.1  christos 	}
   2941  1.1.1.2  christos 
   2942      1.1  christos       /* Null name means this just marks the end of text for this .o
   2943      1.1  christos          file.  Don't start a new symtab in this case.  */
   2944      1.1  christos       if (*name == '\000')
   2945      1.1  christos 	break;
   2946      1.1  christos 
   2947      1.1  christos       if (block_address_function_relative)
   2948      1.1  christos 	function_start_offset = 0;
   2949      1.1  christos 
   2950      1.1  christos       start_stabs ();
   2951  1.1.1.2  christos       start_symtab (objfile, name, NULL, valu);
   2952      1.1  christos       record_debugformat ("stabs");
   2953      1.1  christos       break;
   2954      1.1  christos 
   2955      1.1  christos     case N_SOL:
   2956      1.1  christos       /* This type of symbol indicates the start of data for a
   2957  1.1.1.2  christos          sub-source-file, one whose contents were copied or included
   2958      1.1  christos          in the compilation of the main source file (whose name was
   2959      1.1  christos          given in the N_SO symbol).  Relocate for dynamic loading.  */
   2960      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2961  1.1.1.2  christos       start_subfile (name);
   2962      1.1  christos       break;
   2963      1.1  christos 
   2964      1.1  christos     case N_BINCL:
   2965      1.1  christos       push_subfile ();
   2966      1.1  christos       add_new_header_file (name, valu);
   2967      1.1  christos       start_subfile (name);
   2968      1.1  christos       break;
   2969      1.1  christos 
   2970      1.1  christos     case N_EINCL:
   2971      1.1  christos       start_subfile (pop_subfile ());
   2972      1.1  christos       break;
   2973      1.1  christos 
   2974      1.1  christos     case N_EXCL:
   2975      1.1  christos       add_old_header_file (name, valu);
   2976      1.1  christos       break;
   2977      1.1  christos 
   2978      1.1  christos     case N_SLINE:
   2979      1.1  christos       /* This type of "symbol" really just records one line-number --
   2980      1.1  christos          core-address correspondence.  Enter it in the line list for
   2981      1.1  christos          this symbol table.  */
   2982      1.1  christos 
   2983      1.1  christos       /* Relocate for dynamic loading and for ELF acc
   2984      1.1  christos          function-relative symbols.  */
   2985      1.1  christos       valu += function_start_offset;
   2986      1.1  christos 
   2987      1.1  christos       /* GCC 2.95.3 emits the first N_SLINE stab somwehere in the
   2988      1.1  christos 	 middle of the prologue instead of right at the start of the
   2989      1.1  christos 	 function.  To deal with this we record the address for the
   2990      1.1  christos 	 first N_SLINE stab to be the start of the function instead of
   2991      1.1  christos 	 the listed location.  We really shouldn't to this.  When
   2992      1.1  christos 	 compiling with optimization, this first N_SLINE stab might be
   2993      1.1  christos 	 optimized away.  Other (non-GCC) compilers don't emit this
   2994      1.1  christos 	 stab at all.  There is no real harm in having an extra
   2995      1.1  christos 	 numbered line, although it can be a bit annoying for the
   2996      1.1  christos 	 user.  However, it totally screws up our testsuite.
   2997      1.1  christos 
   2998      1.1  christos 	 So for now, keep adjusting the address of the first N_SLINE
   2999      1.1  christos 	 stab, but only for code compiled with GCC.  */
   3000      1.1  christos 
   3001      1.1  christos       if (within_function && sline_found_in_function == 0)
   3002      1.1  christos 	{
   3003      1.1  christos 	  CORE_ADDR addr = processing_gcc_compilation == 2 ?
   3004      1.1  christos 			   last_function_start : valu;
   3005      1.1  christos 
   3006      1.1  christos 	  record_line (current_subfile, desc,
   3007      1.1  christos 		       gdbarch_addr_bits_remove (gdbarch, addr));
   3008      1.1  christos 	  sline_found_in_function = 1;
   3009      1.1  christos 	}
   3010      1.1  christos       else
   3011      1.1  christos 	record_line (current_subfile, desc,
   3012      1.1  christos 		     gdbarch_addr_bits_remove (gdbarch, valu));
   3013      1.1  christos       break;
   3014      1.1  christos 
   3015      1.1  christos     case N_BCOMM:
   3016      1.1  christos       common_block_start (name, objfile);
   3017      1.1  christos       break;
   3018      1.1  christos 
   3019      1.1  christos     case N_ECOMM:
   3020      1.1  christos       common_block_end (objfile);
   3021      1.1  christos       break;
   3022      1.1  christos 
   3023      1.1  christos       /* The following symbol types need to have the appropriate
   3024      1.1  christos          offset added to their value; then we process symbol
   3025      1.1  christos          definitions in the name.  */
   3026      1.1  christos 
   3027      1.1  christos     case N_STSYM:		/* Static symbol in data segment.  */
   3028      1.1  christos     case N_LCSYM:		/* Static symbol in BSS segment.  */
   3029      1.1  christos     case N_ROSYM:		/* Static symbol in read-only data segment.  */
   3030      1.1  christos       /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
   3031      1.1  christos          Solaris 2's stabs-in-elf makes *most* symbols relative but
   3032      1.1  christos          leaves a few absolute (at least for Solaris 2.1 and version
   3033      1.1  christos          2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
   3034      1.1  christos          the fence.  .stab "foo:S...",N_STSYM is absolute (ld
   3035      1.1  christos          relocates it) .stab "foo:V...",N_STSYM is relative (section
   3036      1.1  christos          base subtracted).  This leaves us no choice but to search for
   3037      1.1  christos          the 'S' or 'V'...  (or pass the whole section_offsets stuff
   3038      1.1  christos          down ONE MORE function call level, which we really don't want
   3039      1.1  christos          to do).  */
   3040      1.1  christos       {
   3041      1.1  christos 	char *p;
   3042      1.1  christos 
   3043      1.1  christos 	/* Normal object file and NLMs have non-zero text seg offsets,
   3044      1.1  christos 	   but don't need their static syms offset in this fashion.
   3045      1.1  christos 	   XXX - This is really a crock that should be fixed in the
   3046      1.1  christos 	   solib handling code so that I don't have to work around it
   3047      1.1  christos 	   here.  */
   3048      1.1  christos 
   3049      1.1  christos 	if (!symfile_relocatable)
   3050      1.1  christos 	  {
   3051      1.1  christos 	    p = strchr (name, ':');
   3052      1.1  christos 	    if (p != 0 && p[1] == 'S')
   3053      1.1  christos 	      {
   3054      1.1  christos 		/* The linker relocated it.  We don't want to add an
   3055      1.1  christos 		   elfstab_offset_sections-type offset, but we *do*
   3056      1.1  christos 		   want to add whatever solib.c passed to
   3057      1.1  christos 		   symbol_file_add as addr (this is known to affect
   3058      1.1  christos 		   SunOS 4, and I suspect ELF too).  Since
   3059      1.1  christos 		   elfstab_offset_sections currently does not muck
   3060      1.1  christos 		   with the text offset (there is no Ttext.text
   3061      1.1  christos 		   symbol), we can get addr from the text offset.  If
   3062      1.1  christos 		   elfstab_offset_sections ever starts dealing with
   3063      1.1  christos 		   the text offset, and we still need to do this, we
   3064      1.1  christos 		   need to invent a SECT_OFF_ADDR_KLUDGE or something.  */
   3065      1.1  christos 		valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   3066      1.1  christos 		goto define_a_symbol;
   3067      1.1  christos 	      }
   3068      1.1  christos 	  }
   3069      1.1  christos 	/* Since it's not the kludge case, re-dispatch to the right
   3070      1.1  christos            handler.  */
   3071      1.1  christos 	switch (type)
   3072      1.1  christos 	  {
   3073      1.1  christos 	  case N_STSYM:
   3074      1.1  christos 	    goto case_N_STSYM;
   3075      1.1  christos 	  case N_LCSYM:
   3076      1.1  christos 	    goto case_N_LCSYM;
   3077      1.1  christos 	  case N_ROSYM:
   3078      1.1  christos 	    goto case_N_ROSYM;
   3079      1.1  christos 	  default:
   3080      1.1  christos 	    internal_error (__FILE__, __LINE__,
   3081      1.1  christos 			    _("failed internal consistency check"));
   3082      1.1  christos 	  }
   3083      1.1  christos       }
   3084      1.1  christos 
   3085      1.1  christos     case_N_STSYM:		/* Static symbol in data segment.  */
   3086      1.1  christos     case N_DSLINE:		/* Source line number, data segment.  */
   3087      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
   3088      1.1  christos       goto define_a_symbol;
   3089      1.1  christos 
   3090      1.1  christos     case_N_LCSYM:		/* Static symbol in BSS segment.  */
   3091      1.1  christos     case N_BSLINE:		/* Source line number, BSS segment.  */
   3092      1.1  christos       /* N_BROWS: overlaps with N_BSLINE.  */
   3093      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
   3094      1.1  christos       goto define_a_symbol;
   3095      1.1  christos 
   3096      1.1  christos     case_N_ROSYM:		/* Static symbol in read-only data segment.  */
   3097      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
   3098      1.1  christos       goto define_a_symbol;
   3099      1.1  christos 
   3100      1.1  christos     case N_ENTRY:		/* Alternate entry point.  */
   3101      1.1  christos       /* Relocate for dynamic loading.  */
   3102      1.1  christos       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   3103      1.1  christos       goto define_a_symbol;
   3104      1.1  christos 
   3105      1.1  christos       /* The following symbol types we don't know how to process.
   3106      1.1  christos          Handle them in a "default" way, but complain to people who
   3107      1.1  christos          care.  */
   3108      1.1  christos     default:
   3109      1.1  christos     case N_CATCH:		/* Exception handler catcher.  */
   3110      1.1  christos     case N_EHDECL:		/* Exception handler name.  */
   3111      1.1  christos     case N_PC:			/* Global symbol in Pascal.  */
   3112      1.1  christos     case N_M2C:			/* Modula-2 compilation unit.  */
   3113      1.1  christos       /* N_MOD2: overlaps with N_EHDECL.  */
   3114      1.1  christos     case N_SCOPE:		/* Modula-2 scope information.  */
   3115      1.1  christos     case N_ECOML:		/* End common (local name).  */
   3116      1.1  christos     case N_NBTEXT:		/* Gould Non-Base-Register symbols???  */
   3117      1.1  christos     case N_NBDATA:
   3118      1.1  christos     case N_NBBSS:
   3119      1.1  christos     case N_NBSTS:
   3120      1.1  christos     case N_NBLCS:
   3121      1.1  christos       unknown_symtype_complaint (hex_string (type));
   3122      1.1  christos       /* FALLTHROUGH */
   3123      1.1  christos 
   3124      1.1  christos       /* The following symbol types don't need the address field
   3125      1.1  christos          relocated, since it is either unused, or is absolute.  */
   3126      1.1  christos     define_a_symbol:
   3127      1.1  christos     case N_GSYM:		/* Global variable.  */
   3128      1.1  christos     case N_NSYMS:		/* Number of symbols (Ultrix).  */
   3129      1.1  christos     case N_NOMAP:		/* No map?  (Ultrix).  */
   3130      1.1  christos     case N_RSYM:		/* Register variable.  */
   3131      1.1  christos     case N_DEFD:		/* Modula-2 GNU module dependency.  */
   3132      1.1  christos     case N_SSYM:		/* Struct or union element.  */
   3133      1.1  christos     case N_LSYM:		/* Local symbol in stack.  */
   3134      1.1  christos     case N_PSYM:		/* Parameter variable.  */
   3135      1.1  christos     case N_LENG:		/* Length of preceding symbol type.  */
   3136      1.1  christos       if (name)
   3137      1.1  christos 	{
   3138      1.1  christos 	  int deftype;
   3139      1.1  christos 	  char *colon_pos = strchr (name, ':');
   3140      1.1  christos 
   3141      1.1  christos 	  if (colon_pos == NULL)
   3142      1.1  christos 	    deftype = '\0';
   3143      1.1  christos 	  else
   3144      1.1  christos 	    deftype = colon_pos[1];
   3145      1.1  christos 
   3146      1.1  christos 	  switch (deftype)
   3147      1.1  christos 	    {
   3148      1.1  christos 	    case 'f':
   3149      1.1  christos 	    case 'F':
   3150      1.1  christos 	      function_stab_type = type;
   3151      1.1  christos 
   3152      1.1  christos 	      /* Deal with the SunPRO 3.0 compiler which omits the
   3153      1.1  christos 	         address from N_FUN symbols.  */
   3154      1.1  christos 	      if (type == N_FUN
   3155      1.1  christos 		  && valu == ANOFFSET (section_offsets,
   3156      1.1  christos 				       SECT_OFF_TEXT (objfile))
   3157      1.1  christos 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   3158      1.1  christos 		{
   3159      1.1  christos 		  CORE_ADDR minsym_valu =
   3160      1.1  christos 		    find_stab_function_addr (name, get_last_source_file (),
   3161      1.1  christos 					     objfile);
   3162      1.1  christos 
   3163      1.1  christos 		  /* The function find_stab_function_addr will return
   3164      1.1  christos 		     0 if the minimal symbol wasn't found.
   3165      1.1  christos 		     (Unfortunately, this might also be a valid
   3166      1.1  christos 		     address.)  Anyway, if it *does* return 0, it is
   3167      1.1  christos 		     likely that the value was set correctly to begin
   3168      1.1  christos 		     with...  */
   3169      1.1  christos 		  if (minsym_valu != 0)
   3170      1.1  christos 		    valu = minsym_valu;
   3171      1.1  christos 		}
   3172      1.1  christos 
   3173      1.1  christos 	      if (block_address_function_relative)
   3174      1.1  christos 		/* For Solaris 2 compilers, the block addresses and
   3175      1.1  christos 		   N_SLINE's are relative to the start of the
   3176      1.1  christos 		   function.  On normal systems, and when using GCC on
   3177      1.1  christos 		   Solaris 2, these addresses are just absolute, or
   3178      1.1  christos 		   relative to the N_SO, depending on
   3179      1.1  christos 		   BLOCK_ADDRESS_ABSOLUTE.  */
   3180      1.1  christos 		function_start_offset = valu;
   3181      1.1  christos 
   3182      1.1  christos 	      within_function = 1;
   3183      1.1  christos 
   3184      1.1  christos 	      if (context_stack_depth > 1)
   3185      1.1  christos 		{
   3186      1.1  christos 		  complaint (&symfile_complaints,
   3187      1.1  christos 			     _("unmatched N_LBRAC before symtab pos %d"),
   3188      1.1  christos 			     symnum);
   3189      1.1  christos 		  break;
   3190  1.1.1.2  christos 		}
   3191      1.1  christos 
   3192      1.1  christos 	      if (context_stack_depth > 0)
   3193      1.1  christos 		{
   3194      1.1  christos 		  struct block *block;
   3195      1.1  christos 
   3196      1.1  christos 		  new = pop_context ();
   3197      1.1  christos 		  /* Make a block for the local symbols within.  */
   3198      1.1  christos 		  block = finish_block (new->name, &local_symbols,
   3199      1.1  christos 					new->old_blocks, new->start_addr,
   3200      1.1  christos 					valu);
   3201      1.1  christos 
   3202      1.1  christos 		  /* For C++, set the block's scope.  */
   3203      1.1  christos 		  if (SYMBOL_LANGUAGE (new->name) == language_cplus)
   3204      1.1  christos 		    cp_set_block_scope (new->name, block,
   3205      1.1  christos 					&objfile->objfile_obstack);
   3206      1.1  christos 		}
   3207      1.1  christos 
   3208      1.1  christos 	      new = push_context (0, valu);
   3209      1.1  christos 	      new->name = define_symbol (valu, name, desc, type, objfile);
   3210      1.1  christos 	      break;
   3211      1.1  christos 
   3212      1.1  christos 	    default:
   3213      1.1  christos 	      define_symbol (valu, name, desc, type, objfile);
   3214      1.1  christos 	      break;
   3215      1.1  christos 	    }
   3216      1.1  christos 	}
   3217      1.1  christos       break;
   3218      1.1  christos 
   3219      1.1  christos       /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
   3220      1.1  christos          for a bunch of other flags, too.  Someday we may parse their
   3221      1.1  christos          flags; for now we ignore theirs and hope they'll ignore ours.  */
   3222      1.1  christos     case N_OPT:			/* Solaris 2: Compiler options.  */
   3223      1.1  christos       if (name)
   3224      1.1  christos 	{
   3225      1.1  christos 	  if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   3226      1.1  christos 	    {
   3227      1.1  christos 	      processing_gcc_compilation = 2;
   3228      1.1  christos 	    }
   3229      1.1  christos 	  else
   3230      1.1  christos 	    n_opt_found = 1;
   3231      1.1  christos 	}
   3232      1.1  christos       break;
   3233      1.1  christos 
   3234  1.1.1.2  christos     case N_MAIN:		/* Name of main routine.  */
   3235      1.1  christos       /* FIXME: If one has a symbol file with N_MAIN and then replaces
   3236      1.1  christos 	 it with a symbol file with "main" and without N_MAIN.  I'm
   3237      1.1  christos 	 not sure exactly what rule to follow but probably something
   3238      1.1  christos 	 like: N_MAIN takes precedence over "main" no matter what
   3239      1.1  christos 	 objfile it is in; If there is more than one N_MAIN, choose
   3240      1.1  christos 	 the one in the symfile_objfile; If there is more than one
   3241      1.1  christos 	 N_MAIN within a given objfile, complain() and choose
   3242      1.1  christos 	 arbitrarily.  (kingdon) */
   3243      1.1  christos       if (name != NULL)
   3244      1.1  christos 	set_objfile_main_name (objfile, name, language_unknown);
   3245      1.1  christos       break;
   3246      1.1  christos 
   3247      1.1  christos       /* The following symbol types can be ignored.  */
   3248      1.1  christos     case N_OBJ:			/* Solaris 2: Object file dir and name.  */
   3249      1.1  christos     case N_PATCH:		/* Solaris 2: Patch Run Time Checker.  */
   3250      1.1  christos       /* N_UNDF:                   Solaris 2: File separator mark.  */
   3251      1.1  christos       /* N_UNDF: -- we will never encounter it, since we only process
   3252      1.1  christos          one file's symbols at once.  */
   3253      1.1  christos     case N_ENDM:		/* Solaris 2: End of module.  */
   3254      1.1  christos     case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   3255      1.1  christos       break;
   3256      1.1  christos     }
   3257      1.1  christos 
   3258      1.1  christos   /* '#' is a GNU C extension to allow one symbol to refer to another
   3259      1.1  christos      related symbol.
   3260      1.1  christos 
   3261      1.1  christos      Generally this is used so that an alias can refer to its main
   3262      1.1  christos      symbol.  */
   3263      1.1  christos   gdb_assert (name);
   3264      1.1  christos   if (name[0] == '#')
   3265      1.1  christos     {
   3266      1.1  christos       /* Initialize symbol reference names and determine if this is a
   3267      1.1  christos          definition.  If a symbol reference is being defined, go ahead
   3268      1.1  christos          and add it.  Otherwise, just return.  */
   3269      1.1  christos 
   3270      1.1  christos       char *s = name;
   3271      1.1  christos       int refnum;
   3272      1.1  christos 
   3273      1.1  christos       /* If this stab defines a new reference ID that is not on the
   3274      1.1  christos          reference list, then put it on the reference list.
   3275      1.1  christos 
   3276      1.1  christos          We go ahead and advance NAME past the reference, even though
   3277      1.1  christos          it is not strictly necessary at this time.  */
   3278      1.1  christos       refnum = symbol_reference_defined (&s);
   3279      1.1  christos       if (refnum >= 0)
   3280      1.1  christos 	if (!ref_search (refnum))
   3281      1.1  christos 	  ref_add (refnum, 0, name, valu);
   3282      1.1  christos       name = s;
   3283      1.1  christos     }
   3284      1.1  christos 
   3285      1.1  christos   previous_stab_code = type;
   3286      1.1  christos }
   3287      1.1  christos 
   3288      1.1  christos /* FIXME: The only difference between this and elfstab_build_psymtabs
   3290      1.1  christos    is the call to install_minimal_symbols for elf, and the support for
   3291      1.1  christos    split sections.  If the differences are really that small, the code
   3292      1.1  christos    should be shared.  */
   3293      1.1  christos 
   3294      1.1  christos /* Scan and build partial symbols for an coff symbol file.
   3295      1.1  christos    The coff file has already been processed to get its minimal symbols.
   3296      1.1  christos 
   3297      1.1  christos    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
   3298      1.1  christos    rolled into one.
   3299      1.1  christos 
   3300      1.1  christos    OBJFILE is the object file we are reading symbols from.
   3301      1.1  christos    ADDR is the address relative to which the symbols are (e.g.
   3302      1.1  christos    the base address of the text segment).
   3303      1.1  christos    TEXTADDR is the address of the text section.
   3304      1.1  christos    TEXTSIZE is the size of the text section.
   3305      1.1  christos    STABSECTS is the list of .stab sections in OBJFILE.
   3306      1.1  christos    STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
   3307      1.1  christos    .stabstr section exists.
   3308      1.1  christos 
   3309      1.1  christos    This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
   3310      1.1  christos    adjusted for coff details.  */
   3311      1.1  christos 
   3312      1.1  christos void
   3313      1.1  christos coffstab_build_psymtabs (struct objfile *objfile,
   3314      1.1  christos 			 CORE_ADDR textaddr, unsigned int textsize,
   3315      1.1  christos 			 struct stab_section_list *stabsects,
   3316      1.1  christos 			 file_ptr stabstroffset, unsigned int stabstrsize)
   3317      1.1  christos {
   3318      1.1  christos   int val;
   3319      1.1  christos   bfd *sym_bfd = objfile->obfd;
   3320      1.1  christos   char *name = bfd_get_filename (sym_bfd);
   3321      1.1  christos   struct dbx_symfile_info *info;
   3322      1.1  christos   unsigned int stabsize;
   3323      1.1  christos 
   3324      1.1  christos   /* There is already a dbx_symfile_info allocated by our caller.
   3325      1.1  christos      It might even contain some info from the coff symtab to help us.  */
   3326      1.1  christos   info = DBX_SYMFILE_INFO (objfile);
   3327      1.1  christos 
   3328      1.1  christos   DBX_TEXT_ADDR (objfile) = textaddr;
   3329      1.1  christos   DBX_TEXT_SIZE (objfile) = textsize;
   3330      1.1  christos 
   3331      1.1  christos #define	COFF_STABS_SYMBOL_SIZE	12	/* XXX FIXME XXX */
   3332      1.1  christos   DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
   3333      1.1  christos   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
   3334      1.1  christos 
   3335      1.1  christos   if (stabstrsize > bfd_get_size (sym_bfd))
   3336      1.1  christos     error (_("ridiculous string table size: %d bytes"), stabstrsize);
   3337      1.1  christos   DBX_STRINGTAB (objfile) = (char *)
   3338      1.1  christos     obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
   3339      1.1  christos   OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
   3340      1.1  christos 
   3341      1.1  christos   /* Now read in the string table in one big gulp.  */
   3342      1.1  christos 
   3343      1.1  christos   val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
   3344      1.1  christos   if (val < 0)
   3345      1.1  christos     perror_with_name (name);
   3346      1.1  christos   val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
   3347      1.1  christos   if (val != stabstrsize)
   3348      1.1  christos     perror_with_name (name);
   3349      1.1  christos 
   3350      1.1  christos   stabsread_new_init ();
   3351      1.1  christos   buildsym_new_init ();
   3352      1.1  christos   free_header_files ();
   3353      1.1  christos   init_header_files ();
   3354      1.1  christos 
   3355      1.1  christos   processing_acc_compilation = 1;
   3356      1.1  christos 
   3357      1.1  christos   /* In a coff file, we've already installed the minimal symbols that came
   3358      1.1  christos      from the coff (non-stab) symbol table, so always act like an
   3359      1.1  christos      incremental load here.  */
   3360      1.1  christos   if (stabsects->next == NULL)
   3361      1.1  christos     {
   3362      1.1  christos       stabsize = bfd_section_size (sym_bfd, stabsects->section);
   3363      1.1  christos       DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
   3364      1.1  christos       DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
   3365      1.1  christos     }
   3366      1.1  christos   else
   3367      1.1  christos     {
   3368      1.1  christos       struct stab_section_list *stabsect;
   3369      1.1  christos 
   3370      1.1  christos       DBX_SYMCOUNT (objfile) = 0;
   3371      1.1  christos       for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
   3372      1.1  christos 	{
   3373      1.1  christos 	  stabsize = bfd_section_size (sym_bfd, stabsect->section);
   3374      1.1  christos 	  DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
   3375      1.1  christos 	}
   3376      1.1  christos 
   3377      1.1  christos       DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
   3378      1.1  christos 
   3379      1.1  christos       symbuf_sections = stabsects->next;
   3380      1.1  christos       symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
   3381      1.1  christos       symbuf_read = 0;
   3382      1.1  christos     }
   3383      1.1  christos 
   3384      1.1  christos   dbx_symfile_read (objfile, 0);
   3385      1.1  christos }
   3386      1.1  christos 
   3387      1.1  christos /* Scan and build partial symbols for an ELF symbol file.
   3389      1.1  christos    This ELF file has already been processed to get its minimal symbols.
   3390      1.1  christos 
   3391      1.1  christos    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
   3392      1.1  christos    rolled into one.
   3393      1.1  christos 
   3394      1.1  christos    OBJFILE is the object file we are reading symbols from.
   3395      1.1  christos    ADDR is the address relative to which the symbols are (e.g.
   3396      1.1  christos    the base address of the text segment).
   3397      1.1  christos    STABSECT is the BFD section information for the .stab section.
   3398      1.1  christos    STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
   3399      1.1  christos    .stabstr section exists.
   3400      1.1  christos 
   3401      1.1  christos    This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
   3402      1.1  christos    adjusted for elf details.  */
   3403      1.1  christos 
   3404      1.1  christos void
   3405      1.1  christos elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
   3406      1.1  christos 			file_ptr stabstroffset, unsigned int stabstrsize)
   3407      1.1  christos {
   3408      1.1  christos   int val;
   3409      1.1  christos   bfd *sym_bfd = objfile->obfd;
   3410      1.1  christos   char *name = bfd_get_filename (sym_bfd);
   3411      1.1  christos   struct dbx_symfile_info *info;
   3412      1.1  christos   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
   3413      1.1  christos 
   3414      1.1  christos   /* There is already a dbx_symfile_info allocated by our caller.
   3415      1.1  christos      It might even contain some info from the ELF symtab to help us.  */
   3416      1.1  christos   info = DBX_SYMFILE_INFO (objfile);
   3417      1.1  christos 
   3418      1.1  christos   /* Find the first and last text address.  dbx_symfile_read seems to
   3419      1.1  christos      want this.  */
   3420      1.1  christos   find_text_range (sym_bfd, objfile);
   3421      1.1  christos 
   3422      1.1  christos #define	ELF_STABS_SYMBOL_SIZE	12	/* XXX FIXME XXX */
   3423      1.1  christos   DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
   3424      1.1  christos   DBX_SYMCOUNT (objfile)
   3425      1.1  christos     = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile);
   3426      1.1  christos   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
   3427      1.1  christos   DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
   3428      1.1  christos   DBX_STAB_SECTION (objfile) = stabsect;
   3429      1.1  christos 
   3430      1.1  christos   if (stabstrsize > bfd_get_size (sym_bfd))
   3431      1.1  christos     error (_("ridiculous string table size: %d bytes"), stabstrsize);
   3432      1.1  christos   DBX_STRINGTAB (objfile) = (char *)
   3433      1.1  christos     obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
   3434      1.1  christos   OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
   3435      1.1  christos 
   3436      1.1  christos   /* Now read in the string table in one big gulp.  */
   3437      1.1  christos 
   3438      1.1  christos   val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
   3439      1.1  christos   if (val < 0)
   3440      1.1  christos     perror_with_name (name);
   3441      1.1  christos   val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
   3442      1.1  christos   if (val != stabstrsize)
   3443      1.1  christos     perror_with_name (name);
   3444      1.1  christos 
   3445      1.1  christos   stabsread_new_init ();
   3446      1.1  christos   buildsym_new_init ();
   3447      1.1  christos   free_header_files ();
   3448      1.1  christos   init_header_files ();
   3449      1.1  christos 
   3450      1.1  christos   processing_acc_compilation = 1;
   3451      1.1  christos 
   3452      1.1  christos   symbuf_read = 0;
   3453      1.1  christos   symbuf_left = bfd_section_size (objfile->obfd, stabsect);
   3454      1.1  christos   stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
   3455      1.1  christos   if (stabs_data)
   3456      1.1  christos     make_cleanup (free_current_contents, (void *) &stabs_data);
   3457      1.1  christos 
   3458      1.1  christos   /* In an elf file, we've already installed the minimal symbols that came
   3459      1.1  christos      from the elf (non-stab) symbol table, so always act like an
   3460      1.1  christos      incremental load here.  dbx_symfile_read should not generate any new
   3461      1.1  christos      minimal symbols, since we will have already read the ELF dynamic symbol
   3462      1.1  christos      table and normal symbol entries won't be in the ".stab" section; but in
   3463      1.1  christos      case it does, it will install them itself.  */
   3464      1.1  christos   dbx_symfile_read (objfile, 0);
   3465      1.1  christos 
   3466      1.1  christos   do_cleanups (back_to);
   3467      1.1  christos }
   3468      1.1  christos 
   3469      1.1  christos /* Scan and build partial symbols for a file with special sections for stabs
   3471      1.1  christos    and stabstrings.  The file has already been processed to get its minimal
   3472      1.1  christos    symbols, and any other symbols that might be necessary to resolve GSYMs.
   3473      1.1  christos 
   3474      1.1  christos    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
   3475      1.1  christos    rolled into one.
   3476      1.1  christos 
   3477      1.1  christos    OBJFILE is the object file we are reading symbols from.
   3478      1.1  christos    ADDR is the address relative to which the symbols are (e.g. the base address
   3479      1.1  christos    of the text segment).
   3480      1.1  christos    STAB_NAME is the name of the section that contains the stabs.
   3481      1.1  christos    STABSTR_NAME is the name of the section that contains the stab strings.
   3482      1.1  christos 
   3483      1.1  christos    This routine is mostly copied from dbx_symfile_init and
   3484      1.1  christos    dbx_symfile_read.  */
   3485      1.1  christos 
   3486      1.1  christos void
   3487      1.1  christos stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
   3488      1.1  christos 			 char *stabstr_name, char *text_name)
   3489      1.1  christos {
   3490      1.1  christos   int val;
   3491      1.1  christos   bfd *sym_bfd = objfile->obfd;
   3492      1.1  christos   char *name = bfd_get_filename (sym_bfd);
   3493      1.1  christos   asection *stabsect;
   3494      1.1  christos   asection *stabstrsect;
   3495      1.1  christos   asection *text_sect;
   3496      1.1  christos   struct dbx_symfile_info *dbx;
   3497      1.1  christos 
   3498      1.1  christos   stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
   3499      1.1  christos   stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
   3500      1.1  christos 
   3501      1.1  christos   if (!stabsect)
   3502      1.1  christos     return;
   3503      1.1  christos 
   3504      1.1  christos   if (!stabstrsect)
   3505      1.1  christos     error (_("stabsect_build_psymtabs:  Found stabs (%s), "
   3506      1.1  christos 	     "but not string section (%s)"),
   3507      1.1  christos 	   stab_name, stabstr_name);
   3508      1.1  christos 
   3509      1.1  christos   dbx = XCNEW (struct dbx_symfile_info);
   3510      1.1  christos   set_objfile_data (objfile, dbx_objfile_data_key, dbx);
   3511      1.1  christos 
   3512      1.1  christos   text_sect = bfd_get_section_by_name (sym_bfd, text_name);
   3513      1.1  christos   if (!text_sect)
   3514      1.1  christos     error (_("Can't find %s section in symbol file"), text_name);
   3515      1.1  christos   DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
   3516      1.1  christos   DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
   3517      1.1  christos 
   3518      1.1  christos   DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
   3519      1.1  christos   DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
   3520      1.1  christos     / DBX_SYMBOL_SIZE (objfile);
   3521      1.1  christos   DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
   3522      1.1  christos   DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;	/* XXX - FIXME: POKING
   3523      1.1  christos 							   INSIDE BFD DATA
   3524      1.1  christos 							   STRUCTURES */
   3525      1.1  christos 
   3526      1.1  christos   if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
   3527      1.1  christos     error (_("ridiculous string table size: %d bytes"),
   3528      1.1  christos 	   DBX_STRINGTAB_SIZE (objfile));
   3529      1.1  christos   DBX_STRINGTAB (objfile) = (char *)
   3530      1.1  christos     obstack_alloc (&objfile->objfile_obstack,
   3531      1.1  christos 		   DBX_STRINGTAB_SIZE (objfile) + 1);
   3532      1.1  christos   OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
   3533      1.1  christos 
   3534      1.1  christos   /* Now read in the string table in one big gulp.  */
   3535      1.1  christos 
   3536      1.1  christos   val = bfd_get_section_contents (sym_bfd,	/* bfd */
   3537      1.1  christos 				  stabstrsect,	/* bfd section */
   3538      1.1  christos 				  DBX_STRINGTAB (objfile), /* input buffer */
   3539      1.1  christos 				  0,		/* offset into section */
   3540      1.1  christos 				  DBX_STRINGTAB_SIZE (objfile)); /* amount to
   3541      1.1  christos 								    read */
   3542      1.1  christos 
   3543      1.1  christos   if (!val)
   3544      1.1  christos     perror_with_name (name);
   3545      1.1  christos 
   3546      1.1  christos   stabsread_new_init ();
   3547      1.1  christos   buildsym_new_init ();
   3548      1.1  christos   free_header_files ();
   3549      1.1  christos   init_header_files ();
   3550      1.1  christos 
   3551      1.1  christos   /* Now, do an incremental load.  */
   3552      1.1  christos 
   3553      1.1  christos   processing_acc_compilation = 1;
   3554      1.1  christos   dbx_symfile_read (objfile, 0);
   3555      1.1  christos }
   3556      1.1  christos 
   3557      1.1  christos static const struct sym_fns aout_sym_fns =
   3559      1.1  christos {
   3560      1.1  christos   dbx_new_init,			/* init anything gbl to entire symtab */
   3561      1.1  christos   dbx_symfile_init,		/* read initial info, setup for sym_read() */
   3562      1.1  christos   dbx_symfile_read,		/* read a symbol file into symtab */
   3563      1.1  christos   NULL,				/* sym_read_psymbols */
   3564      1.1  christos   dbx_symfile_finish,		/* finished with file, cleanup */
   3565      1.1  christos   default_symfile_offsets, 	/* parse user's offsets to internal form */
   3566      1.1  christos   default_symfile_segments,	/* Get segment information from a file.  */
   3567                      NULL,
   3568                      default_symfile_relocate,	/* Relocate a debug section.  */
   3569                      NULL,				/* sym_probe_fns */
   3570                      &psym_functions
   3571                    };
   3572                    
   3573                    void
   3574                    _initialize_dbxread (void)
   3575                    {
   3576                      add_symtab_fns (bfd_target_aout_flavour, &aout_sym_fns);
   3577                    
   3578                      dbx_objfile_data_key
   3579                        = register_objfile_data_with_cleanup (NULL, dbx_free_symfile_info);
   3580                    }
   3581