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