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