1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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. */
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
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 */
38 #include "gdb_string.h"
40 #if defined(USG) || defined(__CYGNUSCLIB__)
41 #include <sys/types.h>
48 #include "breakpoint.h"
50 #include "gdbcore.h" /* for bfd stuff */
51 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
55 #include "stabsread.h"
56 #include "gdb-stabs.h"
58 #include "language.h" /* Needed inside partial-stab.h */
59 #include "complaints.h"
62 #include "aout/aout64.h"
63 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
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. */
70 #define MSYMBOL_SIZE(msym) ((long) MSYMBOL_INFO (msym))
74 /* We put a pointer to this structure in the read_symtab_private field
79 /* The start (inclusive) and end (exclusive) addresses for this
80 partial symtab's text. STABS doesn't reliably give us nice
81 start and end addresses for each function. Instead, we are
82 told the addresses of various boundary points, and we have to
83 gather those together to build ranges. These are our running
84 best guess as to the range of text addresses for this psymtab. */
85 CORE_ADDR textlow
, texthigh
;
87 /* Offset within the file symbol table of first local symbol for this
92 /* Length (in bytes) of the section of the symbol table devoted to
93 this file's symbols (actually, the section bracketed may contain
94 more than just this file's symbols). If ldsymlen is 0, the only
95 reason for this thing's existence is the dependency list. Nothing
96 else will happen when it is read in. */
100 /* The size of each symbol in the symbol file (in external form). */
104 /* Further information needed to locate the symbols if they are in
109 int file_string_offset
;
112 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
113 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
114 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
115 #define TEXTLOW(p) (SYMLOC(p)->textlow)
116 #define TEXTHIGH(p) (SYMLOC(p)->texthigh)
117 #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
118 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
119 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
120 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
123 /* Remember what we deduced to be the source language of this psymtab. */
125 static enum language psymtab_language
= language_unknown
;
127 /* Nonzero means give verbose info on gdb action. From main.c. */
129 extern int info_verbose
;
131 /* The BFD for this file -- implicit parameter to next_symbol_text. */
133 static bfd
*symfile_bfd
;
135 /* The size of each symbol in the symbol file (in external form).
136 This is set by dbx_symfile_read when building psymtabs, and by
137 dbx_psymtab_to_symtab when building symtabs. */
139 static unsigned symbol_size
;
141 /* This is the offset of the symbol table in the executable file. */
143 static unsigned symbol_table_offset
;
145 /* This is the offset of the string table in the executable file. */
147 static unsigned string_table_offset
;
149 /* For elf+stab executables, the n_strx field is not a simple index
150 into the string table. Instead, each .o file has a base offset in
151 the string table, and the associated symbols contain offsets from
152 this base. The following two variables contain the base offset for
153 the current and next .o files. */
155 static unsigned int file_string_table_offset
;
156 static unsigned int next_file_string_table_offset
;
158 /* .o and NLM files contain unrelocated addresses which are based at
159 0. When non-zero, this flag disables some of the special cases for
160 Solaris elf+stab text addresses at location 0. */
162 static int symfile_relocatable
= 0;
164 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
165 relative to the function start address. */
167 static int block_address_function_relative
= 0;
169 /* The lowest text address we have yet encountered. This is needed
170 because in an a.out file, there is no header field which tells us
171 what address the program is actually going to be loaded at, so we
172 need to make guesses based on the symbols (which *are* relocated to
173 reflect the address it will be loaded at). */
175 static CORE_ADDR lowest_text_address
;
177 /* Non-zero if there is any line number info in the objfile. Prevents
178 end_psymtab from discarding an otherwise empty psymtab. */
180 static int has_line_numbers
;
182 /* Complaints about the symbols we have encountered. */
184 struct complaint lbrac_complaint
=
185 {"bad block start address patched", 0, 0};
187 struct complaint string_table_offset_complaint
=
188 {"bad string table offset in symbol %d", 0, 0};
190 struct complaint unknown_symtype_complaint
=
191 {"unknown symbol type %s", 0, 0};
193 struct complaint unknown_symchar_complaint
=
194 {"unknown symbol descriptor `%c'", 0, 0};
196 struct complaint lbrac_rbrac_complaint
=
197 {"block start larger than block end", 0, 0};
199 struct complaint lbrac_unmatched_complaint
=
200 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
202 struct complaint lbrac_mismatch_complaint
=
203 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
205 struct complaint repeated_header_complaint
=
206 {"\"repeated\" header file %s not previously seen, at symtab pos %d", 0, 0};
208 struct complaint unclaimed_bincl_complaint
=
209 {"N_BINCL %s not in entries for any file, at symtab pos %d", 0, 0};
211 /* find_text_range --- find start and end of loadable code sections
213 The find_text_range function finds the shortest address range that
214 encloses all sections containing executable code, and stores it in
215 objfile's text_addr and text_size members.
217 dbx_symfile_read will use this to finish off the partial symbol
218 table, in some cases. */
221 find_text_range (bfd
* sym_bfd
, struct objfile
*objfile
)
228 for (sec
= sym_bfd
->sections
; sec
; sec
= sec
->next
)
229 if (bfd_get_section_flags (sym_bfd
, sec
) & SEC_CODE
)
231 CORE_ADDR sec_start
= bfd_section_vma (sym_bfd
, sec
);
232 CORE_ADDR sec_end
= sec_start
+ bfd_section_size (sym_bfd
, sec
);
236 if (sec_start
< start
)
251 error ("Can't find any code sections in symbol file");
253 DBX_TEXT_ADDR (objfile
) = start
;
254 DBX_TEXT_SIZE (objfile
) = end
- start
;
259 /* During initial symbol readin, we need to have a structure to keep
260 track of which psymtabs have which bincls in them. This structure
261 is used during readin to setup the list of dependencies within each
262 partial symbol table. */
264 struct header_file_location
266 char *name
; /* Name of header file */
267 int instance
; /* See above */
268 struct partial_symtab
*pst
; /* Partial symtab that has the
269 BINCL/EINCL defs for this file */
272 /* The actual list and controling variables */
273 static struct header_file_location
*bincl_list
, *next_bincl
;
274 static int bincls_allocated
;
276 /* Local function prototypes */
278 extern void _initialize_dbxread (void);
280 static void process_now (struct objfile
*);
282 static void read_ofile_symtab (struct partial_symtab
*);
284 static void dbx_psymtab_to_symtab (struct partial_symtab
*);
286 static void dbx_psymtab_to_symtab_1 (struct partial_symtab
*);
288 static void read_dbx_dynamic_symtab (struct objfile
*objfile
);
290 static void read_dbx_symtab (struct objfile
*);
292 static void free_bincl_list (struct objfile
*);
294 static struct partial_symtab
*find_corresponding_bincl_psymtab (char *, int);
296 static void add_bincl_to_list (struct partial_symtab
*, char *, int);
298 static void init_bincl_list (int, struct objfile
*);
300 static char *dbx_next_symbol_text (struct objfile
*);
302 static void fill_symbuf (bfd
*);
304 static void dbx_symfile_init (struct objfile
*);
306 static void dbx_new_init (struct objfile
*);
308 static void dbx_symfile_read (struct objfile
*, int);
310 static void dbx_symfile_finish (struct objfile
*);
312 static void record_minimal_symbol (char *, CORE_ADDR
, int, struct objfile
*);
314 static void add_new_header_file (char *, int);
316 static void add_old_header_file (char *, int);
318 static void add_this_object_header_file (int);
320 static struct partial_symtab
*start_psymtab (struct objfile
*, char *,
322 struct partial_symbol
**,
323 struct partial_symbol
**);
325 /* Free up old header file tables */
328 free_header_files (void)
330 if (this_object_header_files
)
332 xfree (this_object_header_files
);
333 this_object_header_files
= NULL
;
335 n_allocated_this_object_header_files
= 0;
338 /* Allocate new header file tables */
341 init_header_files (void)
343 n_allocated_this_object_header_files
= 10;
344 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
347 /* Add header file number I for this object file
348 at the next successive FILENUM. */
351 add_this_object_header_file (int i
)
353 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
355 n_allocated_this_object_header_files
*= 2;
356 this_object_header_files
357 = (int *) xrealloc ((char *) this_object_header_files
,
358 n_allocated_this_object_header_files
* sizeof (int));
361 this_object_header_files
[n_this_object_header_files
++] = i
;
364 /* Add to this file an "old" header file, one already seen in
365 a previous object file. NAME is the header file's name.
366 INSTANCE is its instance code, to select among multiple
367 symbol tables for the same header file. */
370 add_old_header_file (char *name
, int instance
)
372 register struct header_file
*p
= HEADER_FILES (current_objfile
);
375 for (i
= 0; i
< N_HEADER_FILES (current_objfile
); i
++)
376 if (STREQ (p
[i
].name
, name
) && instance
== p
[i
].instance
)
378 add_this_object_header_file (i
);
381 complain (&repeated_header_complaint
, name
, symnum
);
384 /* Add to this file a "new" header file: definitions for its types follow.
385 NAME is the header file's name.
386 Most often this happens only once for each distinct header file,
387 but not necessarily. If it happens more than once, INSTANCE has
388 a different value each time, and references to the header file
389 use INSTANCE values to select among them.
391 dbx output contains "begin" and "end" markers for each new header file,
392 but at this level we just need to know which files there have been;
393 so we record the file when its "begin" is seen and ignore the "end". */
396 add_new_header_file (char *name
, int instance
)
399 register struct header_file
*hfile
;
401 /* Make sure there is room for one more header file. */
403 i
= N_ALLOCATED_HEADER_FILES (current_objfile
);
405 if (N_HEADER_FILES (current_objfile
) == i
)
409 N_ALLOCATED_HEADER_FILES (current_objfile
) = 10;
410 HEADER_FILES (current_objfile
) = (struct header_file
*)
411 xmalloc (10 * sizeof (struct header_file
));
416 N_ALLOCATED_HEADER_FILES (current_objfile
) = i
;
417 HEADER_FILES (current_objfile
) = (struct header_file
*)
418 xrealloc ((char *) HEADER_FILES (current_objfile
),
419 (i
* sizeof (struct header_file
)));
423 /* Create an entry for this header file. */
425 i
= N_HEADER_FILES (current_objfile
)++;
426 hfile
= HEADER_FILES (current_objfile
) + i
;
427 hfile
->name
= savestring (name
, strlen (name
));
428 hfile
->instance
= instance
;
431 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
432 memset (hfile
->vector
, 0, 10 * sizeof (struct type
*));
434 add_this_object_header_file (i
);
438 static struct type
**
439 explicit_lookup_type (int real_filenum
, int index
)
441 register struct header_file
*f
= &HEADER_FILES (current_objfile
)[real_filenum
];
443 if (index
>= f
->length
)
446 f
->vector
= (struct type
**)
447 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
448 memset (&f
->vector
[f
->length
/ 2],
449 '\0', f
->length
* sizeof (struct type
*) / 2);
451 return &f
->vector
[index
];
456 record_minimal_symbol (char *name
, CORE_ADDR address
, int type
,
457 struct objfile
*objfile
)
459 enum minimal_symbol_type ms_type
;
461 asection
*bfd_section
;
467 section
= SECT_OFF_TEXT (objfile
);
468 bfd_section
= DBX_TEXT_SECTION (objfile
);
472 section
= SECT_OFF_DATA (objfile
);
473 bfd_section
= DBX_DATA_SECTION (objfile
);
477 section
= SECT_OFF_BSS (objfile
);
478 bfd_section
= DBX_BSS_SECTION (objfile
);
488 section
= SECT_OFF_DATA (objfile
);
489 bfd_section
= DBX_DATA_SECTION (objfile
);
492 /* I don't think this type actually exists; since a N_SETV is the result
493 of going over many .o files, it doesn't make sense to have one
495 ms_type
= mst_file_data
;
496 section
= SECT_OFF_DATA (objfile
);
497 bfd_section
= DBX_DATA_SECTION (objfile
);
504 ms_type
= mst_file_text
;
505 section
= SECT_OFF_TEXT (objfile
);
506 bfd_section
= DBX_TEXT_SECTION (objfile
);
509 ms_type
= mst_file_data
;
511 /* Check for __DYNAMIC, which is used by Sun shared libraries.
512 Record it as global even if it's local, not global, so
513 lookup_minimal_symbol can find it. We don't check symbol_leading_char
514 because for SunOS4 it always is '_'. */
515 if (name
[8] == 'C' && STREQ ("__DYNAMIC", name
))
518 /* Same with virtual function tables, both global and static. */
520 char *tempstring
= name
;
521 if (tempstring
[0] == bfd_get_symbol_leading_char (objfile
->obfd
))
523 if (is_vtable_name (tempstring
))
526 section
= SECT_OFF_DATA (objfile
);
527 bfd_section
= DBX_DATA_SECTION (objfile
);
530 ms_type
= mst_file_bss
;
531 section
= SECT_OFF_BSS (objfile
);
532 bfd_section
= DBX_BSS_SECTION (objfile
);
535 ms_type
= mst_unknown
;
541 if ((ms_type
== mst_file_text
|| ms_type
== mst_text
)
542 && address
< lowest_text_address
)
543 lowest_text_address
= address
;
545 prim_record_minimal_symbol_and_info
546 (name
, address
, ms_type
, NULL
, section
, bfd_section
, objfile
);
549 /* Scan and build partial symbols for a symbol file.
550 We have been initialized by a call to dbx_symfile_init, which
551 put all the relevant info into a "struct dbx_symfile_info",
552 hung off the objfile structure.
554 MAINLINE is true if we are reading the main symbol
555 table (as opposed to a shared lib or dynamically loaded file). */
558 dbx_symfile_read (struct objfile
*objfile
, int mainline
)
562 struct cleanup
*back_to
;
564 sym_bfd
= objfile
->obfd
;
566 /* .o and .nlm files are relocatables with text, data and bss segs based at
567 0. This flag disables special (Solaris stabs-in-elf only) fixups for
568 symbols with a value of 0. */
570 symfile_relocatable
= bfd_get_file_flags (sym_bfd
) & HAS_RELOC
;
572 /* This is true for Solaris (and all other systems which put stabs
573 in sections, hopefully, since it would be silly to do things
574 differently from Solaris), and false for SunOS4 and other a.out
576 block_address_function_relative
=
577 ((0 == strncmp (bfd_get_target (sym_bfd
), "elf", 3))
578 || (0 == strncmp (bfd_get_target (sym_bfd
), "som", 3))
579 || (0 == strncmp (bfd_get_target (sym_bfd
), "coff", 4))
580 || (0 == strncmp (bfd_get_target (sym_bfd
), "pe", 2))
581 || (0 == strncmp (bfd_get_target (sym_bfd
), "epoc-pe", 7))
582 || (0 == strncmp (bfd_get_target (sym_bfd
), "nlm", 3)));
584 val
= bfd_seek (sym_bfd
, DBX_SYMTAB_OFFSET (objfile
), SEEK_SET
);
586 perror_with_name (objfile
->name
);
588 /* If we are reinitializing, or if we have never loaded syms yet, init */
590 || (objfile
->global_psymbols
.size
== 0
591 && objfile
->static_psymbols
.size
== 0))
592 init_psymbol_list (objfile
, DBX_SYMCOUNT (objfile
));
594 symbol_size
= DBX_SYMBOL_SIZE (objfile
);
595 symbol_table_offset
= DBX_SYMTAB_OFFSET (objfile
);
597 free_pending_blocks ();
598 back_to
= make_cleanup (really_free_pendings
, 0);
600 init_minimal_symbol_collection ();
601 make_cleanup_discard_minimal_symbols ();
603 /* Read stabs data from executable file and define symbols. */
605 read_dbx_symtab (objfile
);
607 /* Add the dynamic symbols. */
609 read_dbx_dynamic_symtab (objfile
);
611 /* Take the text ranges the STABS partial symbol scanner computed
612 for each of the psymtabs and convert it into the canonical form
615 struct partial_symtab
*p
;
617 ALL_OBJFILE_PSYMTABS (objfile
, p
)
619 p
->textlow
= TEXTLOW (p
);
620 p
->texthigh
= TEXTHIGH (p
);
624 /* Install any minimal symbols that have been collected as the current
625 minimal symbols for this objfile. */
627 install_minimal_symbols (objfile
);
629 do_cleanups (back_to
);
632 /* Initialize anything that needs initializing when a completely new
633 symbol file is specified (not just adding some symbols from another
634 file, e.g. a shared library). */
637 dbx_new_init (struct objfile
*ignore
)
639 stabsread_new_init ();
640 buildsym_new_init ();
641 init_header_files ();
645 /* dbx_symfile_init ()
646 is the dbx-specific initialization routine for reading symbols.
647 It is passed a struct objfile which contains, among other things,
648 the BFD for the file whose symbols are being read, and a slot for a pointer
649 to "private data" which we fill with goodies.
651 We read the string table into malloc'd space and stash a pointer to it.
653 Since BFD doesn't know how to read debug symbols in a format-independent
654 way (and may never do so...), we have to do it ourselves. We will never
655 be called unless this is an a.out (or very similar) file.
656 FIXME, there should be a cleaner peephole into the BFD environment here. */
658 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
661 dbx_symfile_init (struct objfile
*objfile
)
664 bfd
*sym_bfd
= objfile
->obfd
;
665 char *name
= bfd_get_filename (sym_bfd
);
667 unsigned char size_temp
[DBX_STRINGTAB_SIZE_SIZE
];
669 /* Allocate struct to keep track of the symfile */
670 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
671 xmmalloc (objfile
->md
, sizeof (struct dbx_symfile_info
));
672 memset ((PTR
) objfile
->sym_stab_info
, 0, sizeof (struct dbx_symfile_info
));
674 DBX_TEXT_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".text");
675 DBX_DATA_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".data");
676 DBX_BSS_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".bss");
678 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
679 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
680 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
682 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
684 DBX_SYMFILE_INFO (objfile
)->stab_section_info
= NULL
;
686 text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
688 error ("Can't find .text section in symbol file");
689 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
690 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
692 DBX_SYMBOL_SIZE (objfile
) = obj_symbol_entry_size (sym_bfd
);
693 DBX_SYMCOUNT (objfile
) = bfd_get_symcount (sym_bfd
);
694 DBX_SYMTAB_OFFSET (objfile
) = SYMBOL_TABLE_OFFSET
;
696 /* Read the string table and stash it away in the psymbol_obstack. It is
697 only needed as long as we need to expand psymbols into full symbols,
698 so when we blow away the psymbol the string table goes away as well.
699 Note that gdb used to use the results of attempting to malloc the
700 string table, based on the size it read, as a form of sanity check
701 for botched byte swapping, on the theory that a byte swapped string
702 table size would be so totally bogus that the malloc would fail. Now
703 that we put in on the psymbol_obstack, we can't do this since gdb gets
704 a fatal error (out of virtual memory) if the size is bogus. We can
705 however at least check to see if the size is less than the size of
706 the size field itself, or larger than the size of the entire file.
707 Note that all valid string tables have a size greater than zero, since
708 the bytes used to hold the size are included in the count. */
710 if (STRING_TABLE_OFFSET
== 0)
712 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
713 will never be zero, even when there is no string table. This
714 would appear to be a bug in bfd. */
715 DBX_STRINGTAB_SIZE (objfile
) = 0;
716 DBX_STRINGTAB (objfile
) = NULL
;
720 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, SEEK_SET
);
722 perror_with_name (name
);
724 memset ((PTR
) size_temp
, 0, sizeof (size_temp
));
725 val
= bfd_bread ((PTR
) size_temp
, sizeof (size_temp
), sym_bfd
);
728 perror_with_name (name
);
732 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
733 EOF if there is no string table, and attempting to read the size
734 from EOF will read zero bytes. */
735 DBX_STRINGTAB_SIZE (objfile
) = 0;
736 DBX_STRINGTAB (objfile
) = NULL
;
740 /* Read some data that would appear to be the string table size.
741 If there really is a string table, then it is probably the right
742 size. Byteswap if necessary and validate the size. Note that
743 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
744 random data that happened to be at STRING_TABLE_OFFSET, because
745 bfd can't tell us there is no string table, the sanity checks may
746 or may not catch this. */
747 DBX_STRINGTAB_SIZE (objfile
) = bfd_h_get_32 (sym_bfd
, size_temp
);
749 if (DBX_STRINGTAB_SIZE (objfile
) < sizeof (size_temp
)
750 || DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
751 error ("ridiculous string table size (%d bytes).",
752 DBX_STRINGTAB_SIZE (objfile
));
754 DBX_STRINGTAB (objfile
) =
755 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
756 DBX_STRINGTAB_SIZE (objfile
));
757 OBJSTAT (objfile
, sz_strtab
+= DBX_STRINGTAB_SIZE (objfile
));
759 /* Now read in the string table in one big gulp. */
761 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, SEEK_SET
);
763 perror_with_name (name
);
764 val
= bfd_bread (DBX_STRINGTAB (objfile
),
765 DBX_STRINGTAB_SIZE (objfile
),
767 if (val
!= DBX_STRINGTAB_SIZE (objfile
))
768 perror_with_name (name
);
773 /* Perform any local cleanups required when we are done with a particular
774 objfile. I.E, we are in the process of discarding all symbol information
775 for an objfile, freeing up all memory held for it, and unlinking the
776 objfile struct from the global list of known objfiles. */
779 dbx_symfile_finish (struct objfile
*objfile
)
781 if (objfile
->sym_stab_info
!= NULL
)
783 if (HEADER_FILES (objfile
) != NULL
)
785 register int i
= N_HEADER_FILES (objfile
);
786 register struct header_file
*hfiles
= HEADER_FILES (objfile
);
790 xfree (hfiles
[i
].name
);
791 xfree (hfiles
[i
].vector
);
795 mfree (objfile
->md
, objfile
->sym_stab_info
);
797 free_header_files ();
801 /* Buffer for reading the symbol table entries. */
802 static struct external_nlist symbuf
[4096];
803 static int symbuf_idx
;
804 static int symbuf_end
;
806 /* cont_elem is used for continuing information in cfront.
807 It saves information about which types need to be fixed up and
808 completed after all the stabs are read. */
811 /* sym and stabstring for continuing information in cfront */
814 /* state dependencies (statics that must be preserved) */
818 int (*func
) (struct objfile
*, struct symbol
*, char *);
819 /* other state dependencies include:
820 (assumption is that these will not change since process_now FIXME!!)
827 static struct cont_elem
*cont_list
= 0;
828 static int cont_limit
= 0;
829 static int cont_count
= 0;
831 /* Arrange for function F to be called with arguments SYM and P later
832 in the stabs reading process. */
834 process_later (struct symbol
*sym
, char *p
,
835 int (*f
) (struct objfile
*, struct symbol
*, char *))
838 /* Allocate more space for the deferred list. */
839 if (cont_count
>= cont_limit
- 1)
841 cont_limit
+= 32; /* chunk size */
844 = (struct cont_elem
*) xrealloc (cont_list
,
846 * sizeof (struct cont_elem
)));
848 error ("Virtual memory exhausted\n");
851 /* Save state variables so we can process these stabs later. */
852 cont_list
[cont_count
].sym_idx
= symbuf_idx
;
853 cont_list
[cont_count
].sym_end
= symbuf_end
;
854 cont_list
[cont_count
].symnum
= symnum
;
855 cont_list
[cont_count
].sym
= sym
;
856 cont_list
[cont_count
].stabs
= p
;
857 cont_list
[cont_count
].func
= f
;
861 /* Call deferred funtions in CONT_LIST. */
864 process_now (struct objfile
*objfile
)
873 int (*func
) (struct objfile
*, struct symbol
*, char *);
875 /* Save the state of our caller, we'll want to restore it before
877 save_symbuf_idx
= symbuf_idx
;
878 save_symbuf_end
= symbuf_end
;
879 save_symnum
= symnum
;
881 /* Iterate over all the deferred stabs. */
882 for (i
= 0; i
< cont_count
; i
++)
884 /* Restore the state for this deferred stab. */
885 symbuf_idx
= cont_list
[i
].sym_idx
;
886 symbuf_end
= cont_list
[i
].sym_end
;
887 symnum
= cont_list
[i
].symnum
;
888 sym
= cont_list
[i
].sym
;
889 stabs
= cont_list
[i
].stabs
;
890 func
= cont_list
[i
].func
;
892 /* Call the function to handle this deferrd stab. */
893 err
= (*func
) (objfile
, sym
, stabs
);
895 error ("Internal error: unable to resolve stab.\n");
898 /* Restore our caller's state. */
899 symbuf_idx
= save_symbuf_idx
;
900 symbuf_end
= save_symbuf_end
;
901 symnum
= save_symnum
;
906 /* Name of last function encountered. Used in Solaris to approximate
907 object file boundaries. */
908 static char *last_function_name
;
910 /* The address in memory of the string table of the object file we are
911 reading (which might not be the "main" object file, but might be a
912 shared library or some other dynamically loaded thing). This is
913 set by read_dbx_symtab when building psymtabs, and by
914 read_ofile_symtab when building symtabs, and is used only by
915 next_symbol_text. FIXME: If that is true, we don't need it when
916 building psymtabs, right? */
917 static char *stringtab_global
;
919 /* These variables are used to control fill_symbuf when the stabs
920 symbols are not contiguous (as may be the case when a COFF file is
921 linked using --split-by-reloc). */
922 static struct stab_section_list
*symbuf_sections
;
923 static unsigned int symbuf_left
;
924 static unsigned int symbuf_read
;
926 /* Refill the symbol table input buffer
927 and set the variables that control fetching entries from it.
928 Reports an error if no data available.
929 This function can read past the end of the symbol table
930 (into the string table) but this does no harm. */
933 fill_symbuf (bfd
*sym_bfd
)
938 if (symbuf_sections
== NULL
)
939 count
= sizeof (symbuf
);
942 if (symbuf_left
<= 0)
944 file_ptr filepos
= symbuf_sections
->section
->filepos
;
945 if (bfd_seek (sym_bfd
, filepos
, SEEK_SET
) != 0)
946 perror_with_name (bfd_get_filename (sym_bfd
));
947 symbuf_left
= bfd_section_size (sym_bfd
, symbuf_sections
->section
);
948 symbol_table_offset
= filepos
- symbuf_read
;
949 symbuf_sections
= symbuf_sections
->next
;
953 if (count
> sizeof (symbuf
))
954 count
= sizeof (symbuf
);
957 nbytes
= bfd_bread ((PTR
) symbuf
, count
, sym_bfd
);
959 perror_with_name (bfd_get_filename (sym_bfd
));
960 else if (nbytes
== 0)
961 error ("Premature end of file reading symbol table");
962 symbuf_end
= nbytes
/ symbol_size
;
964 symbuf_left
-= nbytes
;
965 symbuf_read
+= nbytes
;
968 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
970 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
971 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
972 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
973 if (bfd_get_sign_extend_vma (abfd)) \
974 (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
976 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
979 /* Invariant: The symbol pointed to by symbuf_idx is the first one
980 that hasn't been swapped. Swap the symbol at the same time
981 that symbuf_idx is incremented. */
983 /* dbx allows the text of a symbol name to be continued into the
984 next symbol name! When such a continuation is encountered
985 (a \ at the end of the text of a name)
986 call this function to get the continuation. */
989 dbx_next_symbol_text (struct objfile
*objfile
)
991 struct internal_nlist nlist
;
993 if (symbuf_idx
== symbuf_end
)
994 fill_symbuf (symfile_bfd
);
997 INTERNALIZE_SYMBOL (nlist
, &symbuf
[symbuf_idx
], symfile_bfd
);
998 OBJSTAT (objfile
, n_stabs
++);
1002 return nlist
.n_strx
+ stringtab_global
+ file_string_table_offset
;
1005 /* Initialize the list of bincls to contain none and have some
1009 init_bincl_list (int number
, struct objfile
*objfile
)
1011 bincls_allocated
= number
;
1012 next_bincl
= bincl_list
= (struct header_file_location
*)
1013 xmmalloc (objfile
->md
, bincls_allocated
* sizeof (struct header_file_location
));
1016 /* Add a bincl to the list. */
1019 add_bincl_to_list (struct partial_symtab
*pst
, char *name
, int instance
)
1021 if (next_bincl
>= bincl_list
+ bincls_allocated
)
1023 int offset
= next_bincl
- bincl_list
;
1024 bincls_allocated
*= 2;
1025 bincl_list
= (struct header_file_location
*)
1026 xmrealloc (pst
->objfile
->md
, (char *) bincl_list
,
1027 bincls_allocated
* sizeof (struct header_file_location
));
1028 next_bincl
= bincl_list
+ offset
;
1030 next_bincl
->pst
= pst
;
1031 next_bincl
->instance
= instance
;
1032 next_bincl
++->name
= name
;
1035 /* Given a name, value pair, find the corresponding
1036 bincl in the list. Return the partial symtab associated
1037 with that header_file_location. */
1039 static struct partial_symtab
*
1040 find_corresponding_bincl_psymtab (char *name
, int instance
)
1042 struct header_file_location
*bincl
;
1044 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
1045 if (bincl
->instance
== instance
1046 && STREQ (name
, bincl
->name
))
1049 complain (&repeated_header_complaint
, name
, symnum
);
1050 return (struct partial_symtab
*) 0;
1053 /* Free the storage allocated for the bincl list. */
1056 free_bincl_list (struct objfile
*objfile
)
1058 mfree (objfile
->md
, (PTR
) bincl_list
);
1059 bincls_allocated
= 0;
1063 do_free_bincl_list_cleanup (void *objfile
)
1065 free_bincl_list (objfile
);
1068 static struct cleanup
*
1069 make_cleanup_free_bincl_list (struct objfile
*objfile
)
1071 return make_cleanup (do_free_bincl_list_cleanup
, objfile
);
1074 /* Scan a SunOs dynamic symbol table for symbols of interest and
1075 add them to the minimal symbol table. */
1078 read_dbx_dynamic_symtab (struct objfile
*objfile
)
1080 bfd
*abfd
= objfile
->obfd
;
1081 struct cleanup
*back_to
;
1091 CORE_ADDR sym_value
;
1094 /* Check that the symbol file has dynamic symbols that we know about.
1095 bfd_arch_unknown can happen if we are reading a sun3 symbol file
1096 on a sun4 host (and vice versa) and bfd is not configured
1097 --with-target=all. This would trigger an assertion in bfd/sunos.c,
1098 so we ignore the dynamic symbols in this case. */
1099 if (bfd_get_flavour (abfd
) != bfd_target_aout_flavour
1100 || (bfd_get_file_flags (abfd
) & DYNAMIC
) == 0
1101 || bfd_get_arch (abfd
) == bfd_arch_unknown
)
1104 dynsym_size
= bfd_get_dynamic_symtab_upper_bound (abfd
);
1105 if (dynsym_size
< 0)
1108 dynsyms
= (asymbol
**) xmalloc (dynsym_size
);
1109 back_to
= make_cleanup (xfree
, dynsyms
);
1111 dynsym_count
= bfd_canonicalize_dynamic_symtab (abfd
, dynsyms
);
1112 if (dynsym_count
< 0)
1114 do_cleanups (back_to
);
1118 /* Enter dynamic symbols into the minimal symbol table
1119 if this is a stripped executable. */
1120 if (bfd_get_symcount (abfd
) <= 0)
1123 for (counter
= 0; counter
< dynsym_count
; counter
++, symptr
++)
1125 asymbol
*sym
= *symptr
;
1129 sec
= bfd_get_section (sym
);
1131 /* BFD symbols are section relative. */
1132 sym_value
= sym
->value
+ sec
->vma
;
1134 if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1136 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1139 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1141 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1144 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1146 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
1152 if (sym
->flags
& BSF_GLOBAL
)
1155 record_minimal_symbol ((char *) bfd_asymbol_name (sym
), sym_value
,
1160 /* Symbols from shared libraries have a dynamic relocation entry
1161 that points to the associated slot in the procedure linkage table.
1162 We make a mininal symbol table entry with type mst_solib_trampoline
1163 at the address in the procedure linkage table. */
1164 dynrel_size
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1165 if (dynrel_size
< 0)
1167 do_cleanups (back_to
);
1171 dynrels
= (arelent
**) xmalloc (dynrel_size
);
1172 make_cleanup (xfree
, dynrels
);
1174 dynrel_count
= bfd_canonicalize_dynamic_reloc (abfd
, dynrels
, dynsyms
);
1175 if (dynrel_count
< 0)
1177 do_cleanups (back_to
);
1181 for (counter
= 0, relptr
= dynrels
;
1182 counter
< dynrel_count
;
1183 counter
++, relptr
++)
1185 arelent
*rel
= *relptr
;
1187 rel
->address
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1189 switch (bfd_get_arch (abfd
))
1191 case bfd_arch_sparc
:
1192 if (rel
->howto
->type
!= RELOC_JMP_SLOT
)
1196 /* `16' is the type BFD produces for a jump table relocation. */
1197 if (rel
->howto
->type
!= 16)
1200 /* Adjust address in the jump table to point to
1201 the start of the bsr instruction. */
1208 name
= (char *) bfd_asymbol_name (*rel
->sym_ptr_ptr
);
1209 prim_record_minimal_symbol (name
, address
, mst_solib_trampoline
,
1213 do_cleanups (back_to
);
1216 /* Setup partial_symtab's describing each source file for which
1217 debugging information is available. */
1220 read_dbx_symtab (struct objfile
*objfile
)
1222 register struct external_nlist
*bufp
= 0; /* =0 avoids gcc -Wall glitch */
1223 struct internal_nlist nlist
;
1224 CORE_ADDR text_addr
;
1227 register char *namestring
;
1229 int past_first_source_file
= 0;
1230 CORE_ADDR last_o_file_start
= 0;
1231 CORE_ADDR last_function_start
= 0;
1232 struct cleanup
*back_to
;
1234 int textlow_not_set
;
1236 /* Current partial symtab */
1237 struct partial_symtab
*pst
;
1239 /* List of current psymtab's include files */
1240 char **psymtab_include_list
;
1241 int includes_allocated
;
1244 /* Index within current psymtab dependency list */
1245 struct partial_symtab
**dependency_list
;
1246 int dependencies_used
, dependencies_allocated
;
1248 text_addr
= DBX_TEXT_ADDR (objfile
);
1249 text_size
= DBX_TEXT_SIZE (objfile
);
1251 /* FIXME. We probably want to change stringtab_global rather than add this
1252 while processing every symbol entry. FIXME. */
1253 file_string_table_offset
= 0;
1254 next_file_string_table_offset
= 0;
1256 stringtab_global
= DBX_STRINGTAB (objfile
);
1258 pst
= (struct partial_symtab
*) 0;
1260 includes_allocated
= 30;
1262 psymtab_include_list
= (char **) alloca (includes_allocated
*
1265 dependencies_allocated
= 30;
1266 dependencies_used
= 0;
1268 (struct partial_symtab
**) alloca (dependencies_allocated
*
1269 sizeof (struct partial_symtab
*));
1271 /* Init bincl list */
1272 init_bincl_list (20, objfile
);
1273 back_to
= make_cleanup_free_bincl_list (objfile
);
1275 last_source_file
= NULL
;
1277 lowest_text_address
= (CORE_ADDR
) -1;
1279 symfile_bfd
= objfile
->obfd
; /* For next_text_symbol */
1280 abfd
= objfile
->obfd
;
1281 symbuf_end
= symbuf_idx
= 0;
1282 next_symbol_text_func
= dbx_next_symbol_text
;
1283 textlow_not_set
= 1;
1284 has_line_numbers
= 0;
1286 for (symnum
= 0; symnum
< DBX_SYMCOUNT (objfile
); symnum
++)
1288 /* Get the symbol for this run and pull out some info */
1289 QUIT
; /* allow this to be interruptable */
1290 if (symbuf_idx
== symbuf_end
)
1292 bufp
= &symbuf
[symbuf_idx
++];
1295 * Special case to speed up readin.
1297 if (bfd_h_get_8 (abfd
, bufp
->e_type
) == N_SLINE
)
1299 has_line_numbers
= 1;
1303 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
1304 OBJSTAT (objfile
, n_stabs
++);
1306 /* Ok. There is a lot of code duplicated in the rest of this
1307 switch statement (for efficiency reasons). Since I don't
1308 like duplicating code, I will do my penance here, and
1309 describe the code which is duplicated:
1311 *) The assignment to namestring.
1312 *) The call to strchr.
1313 *) The addition of a partial symbol the the two partial
1314 symbol lists. This last is a large section of code, so
1315 I've imbedded it in the following macro.
1318 /* Set namestring based on nlist. If the string table index is invalid,
1319 give a fake name, and print a single error message per symbol file read,
1320 rather than abort the symbol reading or flood the user with messages. */
1322 /*FIXME: Too many adds and indirections in here for the inner loop. */
1323 #define SET_NAMESTRING()\
1324 if (((unsigned)CUR_SYMBOL_STRX + file_string_table_offset) >= \
1325 DBX_STRINGTAB_SIZE (objfile)) { \
1326 complain (&string_table_offset_complaint, symnum); \
1327 namestring = "<bad string table offset>"; \
1329 namestring = CUR_SYMBOL_STRX + file_string_table_offset + \
1330 DBX_STRINGTAB (objfile)
1332 #define CUR_SYMBOL_TYPE nlist.n_type
1333 #define CUR_SYMBOL_VALUE nlist.n_value
1334 #define CUR_SYMBOL_STRX nlist.n_strx
1335 #define DBXREAD_ONLY
1336 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms)\
1337 start_psymtab(ofile, fname, low, symoff, global_syms, static_syms)
1338 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
1339 end_psymtab(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)
1341 #include "partial-stab.h"
1344 /* If there's stuff to be cleaned up, clean it up. */
1345 if (DBX_SYMCOUNT (objfile
) > 0 /* We have some syms */
1346 /*FIXME, does this have a bug at start address 0? */
1347 && last_o_file_start
1348 && objfile
->ei
.entry_point
< nlist
.n_value
1349 && objfile
->ei
.entry_point
>= last_o_file_start
)
1351 objfile
->ei
.entry_file_lowpc
= last_o_file_start
;
1352 objfile
->ei
.entry_file_highpc
= nlist
.n_value
;
1357 /* Don't set pst->texthigh lower than it already is. */
1358 CORE_ADDR text_end
=
1359 (lowest_text_address
== (CORE_ADDR
) -1
1360 ? (text_addr
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
)))
1361 : lowest_text_address
)
1364 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1365 symnum
* symbol_size
,
1366 text_end
> TEXTHIGH (pst
) ? text_end
: TEXTHIGH (pst
),
1367 dependency_list
, dependencies_used
, textlow_not_set
);
1370 do_cleanups (back_to
);
1373 /* Allocate and partially fill a partial symtab. It will be
1374 completely filled at the end of the symbol list.
1376 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1377 is the address relative to which its symbols are (incremental) or 0
1381 static struct partial_symtab
*
1382 start_psymtab (struct objfile
*objfile
, char *filename
, CORE_ADDR textlow
,
1383 int ldsymoff
, struct partial_symbol
**global_syms
,
1384 struct partial_symbol
**static_syms
)
1386 struct partial_symtab
*result
=
1387 start_psymtab_common (objfile
, objfile
->section_offsets
,
1388 filename
, textlow
, global_syms
, static_syms
);
1390 result
->read_symtab_private
= (char *)
1391 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1392 TEXTLOW (result
) = result
->textlow
;
1393 TEXTHIGH (result
) = result
->texthigh
;
1394 LDSYMOFF (result
) = ldsymoff
;
1395 result
->read_symtab
= dbx_psymtab_to_symtab
;
1396 SYMBOL_SIZE (result
) = symbol_size
;
1397 SYMBOL_OFFSET (result
) = symbol_table_offset
;
1398 STRING_OFFSET (result
) = string_table_offset
;
1399 FILE_STRING_OFFSET (result
) = file_string_table_offset
;
1401 /* If we're handling an ELF file, drag some section-relocation info
1402 for this source file out of the ELF symbol table, to compensate for
1403 Sun brain death. This replaces the section_offsets in this psymtab,
1405 elfstab_offset_sections (objfile
, result
);
1407 /* Deduce the source language from the filename for this psymtab. */
1408 psymtab_language
= deduce_language_from_filename (filename
);
1413 /* Close off the current usage of PST.
1414 Returns PST or NULL if the partial symtab was empty and thrown away.
1416 FIXME: List variables and peculiarities of same. */
1418 struct partial_symtab
*
1419 end_psymtab (struct partial_symtab
*pst
, char **include_list
, int num_includes
,
1420 int capping_symbol_offset
, CORE_ADDR capping_text
,
1421 struct partial_symtab
**dependency_list
, int number_dependencies
,
1422 int textlow_not_set
)
1425 struct objfile
*objfile
= pst
->objfile
;
1427 if (capping_symbol_offset
!= -1)
1428 LDSYMLEN (pst
) = capping_symbol_offset
- LDSYMOFF (pst
);
1429 TEXTHIGH (pst
) = capping_text
;
1431 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1432 /* Under Solaris, the N_SO symbols always have a value of 0,
1433 instead of the usual address of the .o file. Therefore,
1434 we have to do some tricks to fill in texthigh and textlow.
1435 The first trick is in partial-stab.h: if we see a static
1436 or global function, and the textlow for the current pst
1437 is not set (ie: textlow_not_set), then we use that function's
1438 address for the textlow of the pst. */
1440 /* Now, to fill in texthigh, we remember the last function seen
1441 in the .o file (also in partial-stab.h). Also, there's a hack in
1442 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1443 to here via the misc_info field. Therefore, we can fill in
1444 a reliable texthigh by taking the address plus size of the
1445 last function in the file. */
1447 if (TEXTHIGH (pst
) == 0 && last_function_name
)
1451 struct minimal_symbol
*minsym
;
1453 p
= strchr (last_function_name
, ':');
1455 p
= last_function_name
;
1456 n
= p
- last_function_name
;
1458 strncpy (p
, last_function_name
, n
);
1461 minsym
= lookup_minimal_symbol (p
, pst
->filename
, objfile
);
1464 /* Sun Fortran appends an underscore to the minimal symbol name,
1465 try again with an appended underscore if the minimal symbol
1469 minsym
= lookup_minimal_symbol (p
, pst
->filename
, objfile
);
1473 TEXTHIGH (pst
) = SYMBOL_VALUE_ADDRESS (minsym
) + MSYMBOL_SIZE (minsym
);
1475 last_function_name
= NULL
;
1478 /* this test will be true if the last .o file is only data */
1479 if (textlow_not_set
)
1480 TEXTLOW (pst
) = TEXTHIGH (pst
);
1483 struct partial_symtab
*p1
;
1485 /* If we know our own starting text address, then walk through all other
1486 psymtabs for this objfile, and if any didn't know their ending text
1487 address, set it to our starting address. Take care to not set our
1488 own ending address to our starting address, nor to set addresses on
1489 `dependency' files that have both textlow and texthigh zero. */
1491 ALL_OBJFILE_PSYMTABS (objfile
, p1
)
1493 if (TEXTHIGH (p1
) == 0 && TEXTLOW (p1
) != 0 && p1
!= pst
)
1495 TEXTHIGH (p1
) = TEXTLOW (pst
);
1496 /* if this file has only data, then make textlow match texthigh */
1497 if (TEXTLOW (p1
) == 0)
1498 TEXTLOW (p1
) = TEXTHIGH (p1
);
1503 /* End of kludge for patching Solaris textlow and texthigh. */
1504 #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */
1506 pst
->n_global_syms
=
1507 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1508 pst
->n_static_syms
=
1509 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1511 pst
->number_of_dependencies
= number_dependencies
;
1512 if (number_dependencies
)
1514 pst
->dependencies
= (struct partial_symtab
**)
1515 obstack_alloc (&objfile
->psymbol_obstack
,
1516 number_dependencies
* sizeof (struct partial_symtab
*));
1517 memcpy (pst
->dependencies
, dependency_list
,
1518 number_dependencies
* sizeof (struct partial_symtab
*));
1521 pst
->dependencies
= 0;
1523 for (i
= 0; i
< num_includes
; i
++)
1525 struct partial_symtab
*subpst
=
1526 allocate_psymtab (include_list
[i
], objfile
);
1528 /* Copy the sesction_offsets array from the main psymtab. */
1529 subpst
->section_offsets
= pst
->section_offsets
;
1530 subpst
->read_symtab_private
=
1531 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
1532 sizeof (struct symloc
));
1536 TEXTHIGH (subpst
) = 0;
1538 /* We could save slight bits of space by only making one of these,
1539 shared by the entire set of include files. FIXME-someday. */
1540 subpst
->dependencies
= (struct partial_symtab
**)
1541 obstack_alloc (&objfile
->psymbol_obstack
,
1542 sizeof (struct partial_symtab
*));
1543 subpst
->dependencies
[0] = pst
;
1544 subpst
->number_of_dependencies
= 1;
1546 subpst
->globals_offset
=
1547 subpst
->n_global_syms
=
1548 subpst
->statics_offset
=
1549 subpst
->n_static_syms
= 0;
1553 subpst
->read_symtab
= pst
->read_symtab
;
1556 sort_pst_symbols (pst
);
1558 /* If there is already a psymtab or symtab for a file of this name, remove it.
1559 (If there is a symtab, more drastic things also happen.)
1560 This happens in VxWorks. */
1561 free_named_symtabs (pst
->filename
);
1563 if (num_includes
== 0
1564 && number_dependencies
== 0
1565 && pst
->n_global_syms
== 0
1566 && pst
->n_static_syms
== 0
1567 && has_line_numbers
== 0)
1569 /* Throw away this psymtab, it's empty. We can't deallocate it, since
1570 it is on the obstack, but we can forget to chain it on the list. */
1571 /* Empty psymtabs happen as a result of header files which don't have
1572 any symbols in them. There can be a lot of them. But this check
1573 is wrong, in that a psymtab with N_SLINE entries but nothing else
1574 is not empty, but we don't realize that. Fixing that without slowing
1575 things down might be tricky. */
1577 discard_psymtab (pst
);
1579 /* Indicate that psymtab was thrown away. */
1580 pst
= (struct partial_symtab
*) NULL
;
1586 dbx_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1588 struct cleanup
*old_chain
;
1596 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1601 /* Read in all partial symtabs on which this one is dependent */
1602 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1603 if (!pst
->dependencies
[i
]->readin
)
1605 /* Inform about additional files that need to be read in. */
1608 fputs_filtered (" ", gdb_stdout
);
1610 fputs_filtered ("and ", gdb_stdout
);
1612 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
1613 wrap_here (""); /* Flush output */
1614 gdb_flush (gdb_stdout
);
1616 dbx_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
1619 if (LDSYMLEN (pst
)) /* Otherwise it's a dummy */
1621 /* Init stuff necessary for reading in symbols */
1624 old_chain
= make_cleanup (really_free_pendings
, 0);
1625 file_string_table_offset
= FILE_STRING_OFFSET (pst
);
1626 symbol_size
= SYMBOL_SIZE (pst
);
1628 /* Read in this file's symbols */
1629 bfd_seek (pst
->objfile
->obfd
, SYMBOL_OFFSET (pst
), SEEK_SET
);
1630 read_ofile_symtab (pst
);
1631 sort_symtab_syms (pst
->symtab
);
1633 do_cleanups (old_chain
);
1639 /* Read in all of the symbols for a given psymtab for real.
1640 Be verbose about it if the user wants that. */
1643 dbx_psymtab_to_symtab (struct partial_symtab
*pst
)
1652 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1657 if (LDSYMLEN (pst
) || pst
->number_of_dependencies
)
1659 /* Print the message now, before reading the string table,
1660 to avoid disconcerting pauses. */
1663 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1664 gdb_flush (gdb_stdout
);
1667 sym_bfd
= pst
->objfile
->obfd
;
1669 next_symbol_text_func
= dbx_next_symbol_text
;
1671 dbx_psymtab_to_symtab_1 (pst
);
1673 /* Match with global symbols. This only needs to be done once,
1674 after all of the symtabs and dependencies have been read in. */
1675 scan_file_globals (pst
->objfile
);
1677 /* Finish up the debug error message. */
1679 printf_filtered ("done.\n");
1683 /* Read in a defined section of a specific object file's symbols. */
1686 read_ofile_symtab (struct partial_symtab
*pst
)
1688 register char *namestring
;
1689 register struct external_nlist
*bufp
;
1690 struct internal_nlist nlist
;
1692 unsigned max_symnum
;
1694 struct objfile
*objfile
;
1695 int sym_offset
; /* Offset to start of symbols to read */
1696 int sym_size
; /* Size of symbols to read */
1697 CORE_ADDR text_offset
; /* Start of text segment for symbols */
1698 int text_size
; /* Size of text segment for symbols */
1699 struct section_offsets
*section_offsets
;
1701 objfile
= pst
->objfile
;
1702 sym_offset
= LDSYMOFF (pst
);
1703 sym_size
= LDSYMLEN (pst
);
1704 text_offset
= TEXTLOW (pst
);
1705 text_size
= TEXTHIGH (pst
) - TEXTLOW (pst
);
1706 /* This cannot be simply objfile->section_offsets because of
1707 elfstab_offset_sections() which initializes the psymtab section
1708 offsets information in a special way, and that is different from
1709 objfile->section_offsets. */
1710 section_offsets
= pst
->section_offsets
;
1712 current_objfile
= objfile
;
1713 subfile_stack
= NULL
;
1715 stringtab_global
= DBX_STRINGTAB (objfile
);
1716 last_source_file
= NULL
;
1718 abfd
= objfile
->obfd
;
1719 symfile_bfd
= objfile
->obfd
; /* Implicit param to next_text_symbol */
1720 symbuf_end
= symbuf_idx
= 0;
1722 /* It is necessary to actually read one symbol *before* the start
1723 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1724 occurs before the N_SO symbol.
1726 Detecting this in read_dbx_symtab
1727 would slow down initial readin, so we look for it here instead. */
1728 if (!processing_acc_compilation
&& sym_offset
>= (int) symbol_size
)
1730 bfd_seek (symfile_bfd
, sym_offset
- symbol_size
, SEEK_CUR
);
1732 bufp
= &symbuf
[symbuf_idx
++];
1733 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
1734 OBJSTAT (objfile
, n_stabs
++);
1738 processing_gcc_compilation
= 0;
1739 if (nlist
.n_type
== N_TEXT
)
1741 const char *tempstring
= namestring
;
1743 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
1744 processing_gcc_compilation
= 1;
1745 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
1746 processing_gcc_compilation
= 2;
1747 if (tempstring
[0] == bfd_get_symbol_leading_char (symfile_bfd
))
1749 if (STREQN (tempstring
, "__gnu_compiled", 14))
1750 processing_gcc_compilation
= 2;
1753 /* Try to select a C++ demangling based on the compilation unit
1757 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
1758 know whether it will use the old style or v3 mangling. */
1759 if (processing_gcc_compilation
)
1761 if (AUTO_DEMANGLING
)
1763 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
1770 /* The N_SO starting this symtab is the first symbol, so we
1771 better not check the symbol before it. I'm not this can
1772 happen, but it doesn't hurt to check for it. */
1773 bfd_seek (symfile_bfd
, sym_offset
, SEEK_CUR
);
1774 processing_gcc_compilation
= 0;
1777 if (symbuf_idx
== symbuf_end
)
1779 bufp
= &symbuf
[symbuf_idx
];
1780 if (bfd_h_get_8 (abfd
, bufp
->e_type
) != N_SO
)
1781 error ("First symbol in segment of executable not a source symbol");
1783 max_symnum
= sym_size
/ symbol_size
;
1786 symnum
< max_symnum
;
1789 QUIT
; /* Allow this to be interruptable */
1790 if (symbuf_idx
== symbuf_end
)
1792 bufp
= &symbuf
[symbuf_idx
++];
1793 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
1794 OBJSTAT (objfile
, n_stabs
++);
1796 type
= bfd_h_get_8 (abfd
, bufp
->e_type
);
1802 process_one_symbol (type
, nlist
.n_desc
, nlist
.n_value
,
1803 namestring
, section_offsets
, objfile
);
1805 /* We skip checking for a new .o or -l file; that should never
1806 happen in this routine. */
1807 else if (type
== N_TEXT
)
1809 /* I don't think this code will ever be executed, because
1810 the GCC_COMPILED_FLAG_SYMBOL usually is right before
1811 the N_SO symbol which starts this source file.
1812 However, there is no reason not to accept
1813 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
1815 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
1816 processing_gcc_compilation
= 1;
1817 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
1818 processing_gcc_compilation
= 2;
1821 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
1822 know whether it will use the old style or v3 mangling. */
1823 if (AUTO_DEMANGLING
)
1825 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
1829 else if (type
& N_EXT
|| type
== (unsigned char) N_TEXT
1830 || type
== (unsigned char) N_NBTEXT
1833 /* Global symbol: see if we came across a dbx defintion for
1834 a corresponding symbol. If so, store the value. Remove
1835 syms from the chain when their values are stored, but
1836 search the whole chain, as there may be several syms from
1837 different files with the same name. */
1838 /* This is probably not true. Since the files will be read
1839 in one at a time, each reference to a global symbol will
1840 be satisfied in each file as it appears. So we skip this
1846 current_objfile
= NULL
;
1848 /* In a Solaris elf file, this variable, which comes from the
1849 value of the N_SO symbol, will still be 0. Luckily, text_offset,
1850 which comes from TEXTLOW (pst) is correct. */
1851 if (last_source_start_addr
== 0)
1852 last_source_start_addr
= text_offset
;
1854 /* In reordered executables last_source_start_addr may not be the
1855 lower bound for this symtab, instead use text_offset which comes
1856 from TEXTLOW (pst) which is correct. */
1857 if (last_source_start_addr
> text_offset
)
1858 last_source_start_addr
= text_offset
;
1860 pst
->symtab
= end_symtab (text_offset
+ text_size
, objfile
, SECT_OFF_TEXT (objfile
));
1862 /* Process items which we had to "process_later" due to dependencies
1864 process_now (objfile
);
1870 /* This handles a single symbol from the symbol-file, building symbols
1871 into a GDB symtab. It takes these arguments and an implicit argument.
1873 TYPE is the type field of the ".stab" symbol entry.
1874 DESC is the desc field of the ".stab" entry.
1875 VALU is the value field of the ".stab" entry.
1876 NAME is the symbol name, in our address space.
1877 SECTION_OFFSETS is a set of amounts by which the sections of this object
1878 file were relocated when it was loaded into memory.
1879 Note that these section_offsets are not the
1880 objfile->section_offsets but the pst->section_offsets.
1881 All symbols that refer
1882 to memory locations need to be offset by these amounts.
1883 OBJFILE is the object file from which we are reading symbols.
1884 It is used in end_symtab. */
1887 process_one_symbol (int type
, int desc
, CORE_ADDR valu
, char *name
,
1888 struct section_offsets
*section_offsets
,
1889 struct objfile
*objfile
)
1891 #ifdef SUN_FIXED_LBRAC_BUG
1892 /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
1893 to correct the address of N_LBRAC's. If it is not defined, then
1894 we never need to correct the addresses. */
1896 /* This records the last pc address we've seen. We depend on there being
1897 an SLINE or FUN or SO before the first LBRAC, since the variable does
1898 not get reset in between reads of different symbol files. */
1899 static CORE_ADDR last_pc_address
;
1902 register struct context_stack
*new;
1903 /* This remembers the address of the start of a function. It is used
1904 because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
1905 relative to the current function's start address. On systems
1906 other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
1907 used to relocate these symbol types rather than SECTION_OFFSETS. */
1908 static CORE_ADDR function_start_offset
;
1910 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
1911 file. Used to detect the SunPRO solaris compiler. */
1912 static int n_opt_found
;
1914 /* The stab type used for the definition of the last function.
1915 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
1916 static int function_stab_type
= 0;
1918 if (!block_address_function_relative
)
1919 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
1920 function start address, so just use the text offset. */
1921 function_start_offset
= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1923 /* Something is wrong if we see real data before
1924 seeing a source file name. */
1926 if (last_source_file
== NULL
&& type
!= (unsigned char) N_SO
)
1928 /* Ignore any symbols which appear before an N_SO symbol.
1929 Currently no one puts symbols there, but we should deal
1930 gracefully with the case. A complain()t might be in order,
1931 but this should not be an error (). */
1940 if (*name
== '\000')
1942 /* This N_FUN marks the end of a function. This closes off the
1944 within_function
= 0;
1945 new = pop_context ();
1947 /* Make a block for the local symbols within. */
1948 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1949 new->start_addr
, new->start_addr
+ valu
,
1952 /* May be switching to an assembler file which may not be using
1953 block relative stabs, so reset the offset. */
1954 if (block_address_function_relative
)
1955 function_start_offset
= 0;
1960 /* Relocate for dynamic loading */
1961 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1962 #ifdef SMASH_TEXT_ADDRESS
1963 SMASH_TEXT_ADDRESS (valu
);
1965 goto define_a_symbol
;
1968 /* This "symbol" just indicates the start of an inner lexical
1969 context within a function. */
1971 /* Ignore extra outermost context from SunPRO cc and acc. */
1972 if (n_opt_found
&& desc
== 1)
1975 if (block_address_function_relative
)
1976 /* Relocate for Sun ELF acc fn-relative syms. */
1977 valu
+= function_start_offset
;
1979 /* On most machines, the block addresses are relative to the
1980 N_SO, the linker did not relocate them (sigh). */
1981 valu
+= last_source_start_addr
;
1983 #ifdef SUN_FIXED_LBRAC_BUG
1984 if (!SUN_FIXED_LBRAC_BUG
&& valu
< last_pc_address
)
1986 /* Patch current LBRAC pc value to match last handy pc value */
1987 complain (&lbrac_complaint
);
1988 valu
= last_pc_address
;
1991 new = push_context (desc
, valu
);
1995 /* This "symbol" just indicates the end of an inner lexical
1996 context that was started with N_LBRAC. */
1998 /* Ignore extra outermost context from SunPRO cc and acc. */
1999 if (n_opt_found
&& desc
== 1)
2002 if (block_address_function_relative
)
2003 /* Relocate for Sun ELF acc fn-relative syms. */
2004 valu
+= function_start_offset
;
2006 /* On most machines, the block addresses are relative to the
2007 N_SO, the linker did not relocate them (sigh). */
2008 valu
+= last_source_start_addr
;
2010 new = pop_context ();
2011 if (desc
!= new->depth
)
2012 complain (&lbrac_mismatch_complaint
, symnum
);
2014 /* Some compilers put the variable decls inside of an
2015 LBRAC/RBRAC block. This macro should be nonzero if this
2016 is true. DESC is N_DESC from the N_RBRAC symbol.
2017 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
2018 or the GCC2_COMPILED_SYMBOL. */
2019 #if !defined (VARIABLES_INSIDE_BLOCK)
2020 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2023 /* Can only use new->locals as local symbols here if we're in
2024 gcc or on a machine that puts them before the lbrack. */
2025 if (!VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2026 local_symbols
= new->locals
;
2028 if (context_stack_depth
2029 > !VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2031 /* This is not the outermost LBRAC...RBRAC pair in the function,
2032 its local symbols preceded it, and are the ones just recovered
2033 from the context stack. Define the block for them (but don't
2034 bother if the block contains no symbols. Should we complain
2035 on blocks without symbols? I can't think of any useful purpose
2037 if (local_symbols
!= NULL
)
2039 /* Muzzle a compiler bug that makes end < start. (which
2040 compilers? Is this ever harmful?). */
2041 if (new->start_addr
> valu
)
2043 complain (&lbrac_rbrac_complaint
);
2044 new->start_addr
= valu
;
2046 /* Make a block for the local symbols within. */
2047 finish_block (0, &local_symbols
, new->old_blocks
,
2048 new->start_addr
, valu
, objfile
);
2053 /* This is the outermost LBRAC...RBRAC pair. There is no
2054 need to do anything; leave the symbols that preceded it
2055 to be attached to the function's own block. We need to
2056 indicate that we just moved outside of the function. */
2057 within_function
= 0;
2060 if (VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2061 /* Now pop locals of block just finished. */
2062 local_symbols
= new->locals
;
2067 /* This kind of symbol indicates the start of an object file. */
2068 /* Relocate for dynamic loading */
2069 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2073 /* This type of symbol indicates the start of data
2074 for one source file.
2075 Finish the symbol table of the previous source file
2076 (if any) and start accumulating a new symbol table. */
2077 /* Relocate for dynamic loading */
2078 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2082 #ifdef SUN_FIXED_LBRAC_BUG
2083 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2086 #ifdef PCC_SOL_BROKEN
2087 /* pcc bug, occasionally puts out SO for SOL. */
2088 if (context_stack_depth
> 0)
2090 start_subfile (name
, NULL
);
2094 if (last_source_file
)
2096 /* Check if previous symbol was also an N_SO (with some
2097 sanity checks). If so, that one was actually the directory
2098 name, and the current one is the real file name.
2100 if (previous_stab_code
== (unsigned char) N_SO
)
2102 patch_subfile_names (current_subfile
, name
);
2103 break; /* Ignore repeated SOs */
2105 end_symtab (valu
, objfile
, SECT_OFF_TEXT (objfile
));
2109 /* Null name means this just marks the end of text for this .o file.
2110 Don't start a new symtab in this case. */
2111 if (*name
== '\000')
2114 if (block_address_function_relative
)
2115 function_start_offset
= 0;
2118 start_symtab (name
, NULL
, valu
);
2119 record_debugformat ("stabs");
2123 /* This type of symbol indicates the start of data for
2124 a sub-source-file, one whose contents were copied or
2125 included in the compilation of the main source file
2126 (whose name was given in the N_SO symbol.) */
2127 /* Relocate for dynamic loading */
2128 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2129 start_subfile (name
, current_subfile
->dirname
);
2134 add_new_header_file (name
, valu
);
2135 start_subfile (name
, current_subfile
->dirname
);
2139 start_subfile (pop_subfile (), current_subfile
->dirname
);
2143 add_old_header_file (name
, valu
);
2147 /* This type of "symbol" really just records
2148 one line-number -- core-address correspondence.
2149 Enter it in the line list for this symbol table. */
2151 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
2152 valu
+= function_start_offset
;
2154 #ifdef SUN_FIXED_LBRAC_BUG
2155 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2157 record_line (current_subfile
, desc
, valu
);
2161 common_block_start (name
, objfile
);
2165 common_block_end (objfile
);
2168 /* The following symbol types need to have the appropriate offset added
2169 to their value; then we process symbol definitions in the name. */
2171 case N_STSYM
: /* Static symbol in data seg */
2172 case N_LCSYM
: /* Static symbol in BSS seg */
2173 case N_ROSYM
: /* Static symbol in Read-only data seg */
2174 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
2175 Solaris2's stabs-in-elf makes *most* symbols relative
2176 but leaves a few absolute (at least for Solaris 2.1 and version
2177 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence.
2178 .stab "foo:S...",N_STSYM is absolute (ld relocates it)
2179 .stab "foo:V...",N_STSYM is relative (section base subtracted).
2180 This leaves us no choice but to search for the 'S' or 'V'...
2181 (or pass the whole section_offsets stuff down ONE MORE function
2182 call level, which we really don't want to do). */
2186 /* .o files and NLMs have non-zero text seg offsets, but don't need
2187 their static syms offset in this fashion. XXX - This is really a
2188 crock that should be fixed in the solib handling code so that I
2189 don't have to work around it here. */
2191 if (!symfile_relocatable
)
2193 p
= strchr (name
, ':');
2194 if (p
!= 0 && p
[1] == 'S')
2196 /* The linker relocated it. We don't want to add an
2197 elfstab_offset_sections-type offset, but we *do* want
2198 to add whatever solib.c passed to symbol_file_add as
2199 addr (this is known to affect SunOS4, and I suspect ELF
2200 too). Since elfstab_offset_sections currently does not
2201 muck with the text offset (there is no Ttext.text
2202 symbol), we can get addr from the text offset. If
2203 elfstab_offset_sections ever starts dealing with the
2204 text offset, and we still need to do this, we need to
2205 invent a SECT_OFF_ADDR_KLUDGE or something. */
2206 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2207 goto define_a_symbol
;
2210 /* Since it's not the kludge case, re-dispatch to the right handler. */
2220 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
2224 case_N_STSYM
: /* Static symbol in data seg */
2225 case N_DSLINE
: /* Source line number, data seg */
2226 valu
+= ANOFFSET (section_offsets
, SECT_OFF_DATA (objfile
));
2227 goto define_a_symbol
;
2229 case_N_LCSYM
: /* Static symbol in BSS seg */
2230 case N_BSLINE
: /* Source line number, bss seg */
2231 /* N_BROWS: overlaps with N_BSLINE */
2232 valu
+= ANOFFSET (section_offsets
, SECT_OFF_BSS (objfile
));
2233 goto define_a_symbol
;
2235 case_N_ROSYM
: /* Static symbol in Read-only data seg */
2236 valu
+= ANOFFSET (section_offsets
, SECT_OFF_RODATA (objfile
));
2237 goto define_a_symbol
;
2239 case N_ENTRY
: /* Alternate entry point */
2240 /* Relocate for dynamic loading */
2241 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2242 goto define_a_symbol
;
2244 /* The following symbol types we don't know how to process. Handle
2245 them in a "default" way, but complain to people who care. */
2247 case N_CATCH
: /* Exception handler catcher */
2248 case N_EHDECL
: /* Exception handler name */
2249 case N_PC
: /* Global symbol in Pascal */
2250 case N_M2C
: /* Modula-2 compilation unit */
2251 /* N_MOD2: overlaps with N_EHDECL */
2252 case N_SCOPE
: /* Modula-2 scope information */
2253 case N_ECOML
: /* End common (local name) */
2254 case N_NBTEXT
: /* Gould Non-Base-Register symbols??? */
2259 complain (&unknown_symtype_complaint
, local_hex_string (type
));
2262 /* The following symbol types don't need the address field relocated,
2263 since it is either unused, or is absolute. */
2265 case N_GSYM
: /* Global variable */
2266 case N_NSYMS
: /* Number of symbols (ultrix) */
2267 case N_NOMAP
: /* No map? (ultrix) */
2268 case N_RSYM
: /* Register variable */
2269 case N_DEFD
: /* Modula-2 GNU module dependency */
2270 case N_SSYM
: /* Struct or union element */
2271 case N_LSYM
: /* Local symbol in stack */
2272 case N_PSYM
: /* Parameter variable */
2273 case N_LENG
: /* Length of preceding symbol type */
2277 char *colon_pos
= strchr (name
, ':');
2278 if (colon_pos
== NULL
)
2281 deftype
= colon_pos
[1];
2287 function_stab_type
= type
;
2289 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2290 /* Deal with the SunPRO 3.0 compiler which omits the address
2291 from N_FUN symbols. */
2293 && valu
== ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
)))
2295 CORE_ADDR minsym_valu
=
2296 find_stab_function_addr (name
, last_source_file
, objfile
);
2298 /* find_stab_function_addr will return 0 if the minimal
2299 symbol wasn't found. (Unfortunately, this might also
2300 be a valid address.) Anyway, if it *does* return 0,
2301 it is likely that the value was set correctly to begin
2303 if (minsym_valu
!= 0)
2308 #ifdef SUN_FIXED_LBRAC_BUG
2309 /* The Sun acc compiler, under SunOS4, puts out
2310 functions with N_GSYM or N_STSYM. The problem is
2311 that the address of the symbol is no good (for N_GSYM
2312 it doesn't even attept an address; for N_STSYM it
2313 puts out an address but then it gets relocated
2314 relative to the data segment, not the text segment).
2315 Currently we can't fix this up later as we do for
2316 some types of symbol in scan_file_globals.
2317 Fortunately we do have a way of finding the address -
2318 we know that the value in last_pc_address is either
2319 the one we want (if we're dealing with the first
2320 function in an object file), or somewhere in the
2321 previous function. This means that we can use the
2322 minimal symbol table to get the address. */
2324 /* Starting with release 3.0, the Sun acc compiler,
2325 under SunOS4, puts out functions with N_FUN and a value
2326 of zero. This gets relocated to the start of the text
2327 segment of the module, which is no good either.
2328 Under SunOS4 we can deal with this as N_SLINE and N_SO
2329 entries contain valid absolute addresses.
2330 Release 3.0 acc also puts out N_OPT entries, which makes
2331 it possible to discern acc from cc or gcc. */
2333 if (type
== N_GSYM
|| type
== N_STSYM
2335 && n_opt_found
&& !block_address_function_relative
))
2337 struct minimal_symbol
*m
;
2338 int l
= colon_pos
- name
;
2340 m
= lookup_minimal_symbol_by_pc (last_pc_address
);
2341 if (m
&& STREQN (SYMBOL_NAME (m
), name
, l
)
2342 && SYMBOL_NAME (m
)[l
] == '\0')
2343 /* last_pc_address was in this function */
2344 valu
= SYMBOL_VALUE (m
);
2345 else if (m
&& SYMBOL_NAME (m
+ 1)
2346 && STREQN (SYMBOL_NAME (m
+ 1), name
, l
)
2347 && SYMBOL_NAME (m
+ 1)[l
] == '\0')
2348 /* last_pc_address was in last function */
2349 valu
= SYMBOL_VALUE (m
+ 1);
2351 /* Not found - use last_pc_address (for finish_block) */
2352 valu
= last_pc_address
;
2355 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2358 if (block_address_function_relative
)
2359 /* For Solaris 2.0 compilers, the block addresses and
2360 N_SLINE's are relative to the start of the
2361 function. On normal systems, and when using gcc on
2362 Solaris 2.0, these addresses are just absolute, or
2363 relative to the N_SO, depending on
2364 BLOCK_ADDRESS_ABSOLUTE. */
2365 function_start_offset
= valu
;
2367 within_function
= 1;
2369 if (context_stack_depth
> 1)
2371 complain (&lbrac_unmatched_complaint
, symnum
);
2375 if (context_stack_depth
> 0)
2377 new = pop_context ();
2378 /* Make a block for the local symbols within. */
2379 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2380 new->start_addr
, valu
, objfile
);
2383 new = push_context (0, valu
);
2384 new->name
= define_symbol (valu
, name
, desc
, type
, objfile
);
2388 define_symbol (valu
, name
, desc
, type
, objfile
);
2394 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
2395 for a bunch of other flags, too. Someday we may parse their
2396 flags; for now we ignore theirs and hope they'll ignore ours. */
2397 case N_OPT
: /* Solaris 2: Compiler options */
2400 if (STREQ (name
, GCC2_COMPILED_FLAG_SYMBOL
))
2402 processing_gcc_compilation
= 2;
2403 #if 0 /* Works, but is experimental. -fnf */
2404 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2405 know whether it will use the old style or v3 mangling. */
2406 if (AUTO_DEMANGLING
)
2408 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
2417 case N_MAIN
: /* Name of main routine. */
2418 /* FIXME: If one has a symbol file with N_MAIN and then replaces
2419 it with a symbol file with "main" and without N_MAIN. I'm
2420 not sure exactly what rule to follow but probably something
2421 like: N_MAIN takes precedence over "main" no matter what
2422 objfile it is in; If there is more than one N_MAIN, choose
2423 the one in the symfile_objfile; If there is more than one
2424 N_MAIN within a given objfile, complain() and choose
2425 arbitrarily. (kingdon) */
2427 set_main_name (name
);
2430 /* The following symbol types can be ignored. */
2431 case N_OBJ
: /* Solaris 2: Object file dir and name */
2432 /* N_UNDF: Solaris 2: file separator mark */
2433 /* N_UNDF: -- we will never encounter it, since we only process one
2434 file's symbols at once. */
2435 case N_ENDM
: /* Solaris 2: End of module */
2436 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
2440 /* '#' is a GNU C extension to allow one symbol to refer to another
2443 Generally this is used so that an alias can refer to its main
2447 /* Initialize symbol reference names and determine if this is
2448 a definition. If symbol reference is being defined, go
2449 ahead and add it. Otherwise, just return sym. */
2454 /* If this stab defines a new reference ID that is not on the
2455 reference list, then put it on the reference list.
2457 We go ahead and advance NAME past the reference, even though
2458 it is not strictly necessary at this time. */
2459 refnum
= symbol_reference_defined (&s
);
2461 if (!ref_search (refnum
))
2462 ref_add (refnum
, 0, name
, valu
);
2467 previous_stab_code
= type
;
2470 /* FIXME: The only difference between this and elfstab_build_psymtabs
2471 is the call to install_minimal_symbols for elf, and the support for
2472 split sections. If the differences are really that small, the code
2473 should be shared. */
2475 /* Scan and build partial symbols for an coff symbol file.
2476 The coff file has already been processed to get its minimal symbols.
2478 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
2481 OBJFILE is the object file we are reading symbols from.
2482 ADDR is the address relative to which the symbols are (e.g.
2483 the base address of the text segment).
2484 MAINLINE is true if we are reading the main symbol
2485 table (as opposed to a shared lib or dynamically loaded file).
2486 TEXTADDR is the address of the text section.
2487 TEXTSIZE is the size of the text section.
2488 STABSECTS is the list of .stab sections in OBJFILE.
2489 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
2490 .stabstr section exists.
2492 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
2493 adjusted for coff details. */
2496 coffstab_build_psymtabs (struct objfile
*objfile
, int mainline
,
2497 CORE_ADDR textaddr
, unsigned int textsize
,
2498 struct stab_section_list
*stabsects
,
2499 file_ptr stabstroffset
, unsigned int stabstrsize
)
2502 bfd
*sym_bfd
= objfile
->obfd
;
2503 char *name
= bfd_get_filename (sym_bfd
);
2504 struct dbx_symfile_info
*info
;
2505 unsigned int stabsize
;
2507 /* There is already a dbx_symfile_info allocated by our caller.
2508 It might even contain some info from the coff symtab to help us. */
2509 info
= objfile
->sym_stab_info
;
2511 DBX_TEXT_ADDR (objfile
) = textaddr
;
2512 DBX_TEXT_SIZE (objfile
) = textsize
;
2514 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
2515 DBX_SYMBOL_SIZE (objfile
) = COFF_STABS_SYMBOL_SIZE
;
2516 DBX_STRINGTAB_SIZE (objfile
) = stabstrsize
;
2518 if (stabstrsize
> bfd_get_size (sym_bfd
))
2519 error ("ridiculous string table size: %d bytes", stabstrsize
);
2520 DBX_STRINGTAB (objfile
) = (char *)
2521 obstack_alloc (&objfile
->psymbol_obstack
, stabstrsize
+ 1);
2522 OBJSTAT (objfile
, sz_strtab
+= stabstrsize
+ 1);
2524 /* Now read in the string table in one big gulp. */
2526 val
= bfd_seek (sym_bfd
, stabstroffset
, SEEK_SET
);
2528 perror_with_name (name
);
2529 val
= bfd_bread (DBX_STRINGTAB (objfile
), stabstrsize
, sym_bfd
);
2530 if (val
!= stabstrsize
)
2531 perror_with_name (name
);
2533 stabsread_new_init ();
2534 buildsym_new_init ();
2535 free_header_files ();
2536 init_header_files ();
2538 processing_acc_compilation
= 1;
2540 /* In a coff file, we've already installed the minimal symbols that came
2541 from the coff (non-stab) symbol table, so always act like an
2542 incremental load here. */
2543 if (stabsects
->next
== NULL
)
2545 stabsize
= bfd_section_size (sym_bfd
, stabsects
->section
);
2546 DBX_SYMCOUNT (objfile
) = stabsize
/ DBX_SYMBOL_SIZE (objfile
);
2547 DBX_SYMTAB_OFFSET (objfile
) = stabsects
->section
->filepos
;
2551 struct stab_section_list
*stabsect
;
2553 DBX_SYMCOUNT (objfile
) = 0;
2554 for (stabsect
= stabsects
; stabsect
!= NULL
; stabsect
= stabsect
->next
)
2556 stabsize
= bfd_section_size (sym_bfd
, stabsect
->section
);
2557 DBX_SYMCOUNT (objfile
) += stabsize
/ DBX_SYMBOL_SIZE (objfile
);
2560 DBX_SYMTAB_OFFSET (objfile
) = stabsects
->section
->filepos
;
2562 symbuf_sections
= stabsects
->next
;
2563 symbuf_left
= bfd_section_size (sym_bfd
, stabsects
->section
);
2567 dbx_symfile_read (objfile
, 0);
2570 /* Scan and build partial symbols for an ELF symbol file.
2571 This ELF file has already been processed to get its minimal symbols,
2572 and any DWARF symbols that were in it.
2574 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
2577 OBJFILE is the object file we are reading symbols from.
2578 ADDR is the address relative to which the symbols are (e.g.
2579 the base address of the text segment).
2580 MAINLINE is true if we are reading the main symbol
2581 table (as opposed to a shared lib or dynamically loaded file).
2582 STABOFFSET and STABSIZE define the location in OBJFILE where the .stab
2584 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
2585 .stabstr section exists.
2587 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
2588 adjusted for elf details. */
2591 elfstab_build_psymtabs (struct objfile
*objfile
, int mainline
,
2592 file_ptr staboffset
, unsigned int stabsize
,
2593 file_ptr stabstroffset
, unsigned int stabstrsize
)
2596 bfd
*sym_bfd
= objfile
->obfd
;
2597 char *name
= bfd_get_filename (sym_bfd
);
2598 struct dbx_symfile_info
*info
;
2600 /* There is already a dbx_symfile_info allocated by our caller.
2601 It might even contain some info from the ELF symtab to help us. */
2602 info
= objfile
->sym_stab_info
;
2604 /* Find the first and last text address. dbx_symfile_read seems to
2606 find_text_range (sym_bfd
, objfile
);
2608 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
2609 DBX_SYMBOL_SIZE (objfile
) = ELF_STABS_SYMBOL_SIZE
;
2610 DBX_SYMCOUNT (objfile
) = stabsize
/ DBX_SYMBOL_SIZE (objfile
);
2611 DBX_STRINGTAB_SIZE (objfile
) = stabstrsize
;
2612 DBX_SYMTAB_OFFSET (objfile
) = staboffset
;
2614 if (stabstrsize
> bfd_get_size (sym_bfd
))
2615 error ("ridiculous string table size: %d bytes", stabstrsize
);
2616 DBX_STRINGTAB (objfile
) = (char *)
2617 obstack_alloc (&objfile
->psymbol_obstack
, stabstrsize
+ 1);
2618 OBJSTAT (objfile
, sz_strtab
+= stabstrsize
+ 1);
2620 /* Now read in the string table in one big gulp. */
2622 val
= bfd_seek (sym_bfd
, stabstroffset
, SEEK_SET
);
2624 perror_with_name (name
);
2625 val
= bfd_bread (DBX_STRINGTAB (objfile
), stabstrsize
, sym_bfd
);
2626 if (val
!= stabstrsize
)
2627 perror_with_name (name
);
2629 stabsread_new_init ();
2630 buildsym_new_init ();
2631 free_header_files ();
2632 init_header_files ();
2633 install_minimal_symbols (objfile
);
2635 processing_acc_compilation
= 1;
2637 /* In an elf file, we've already installed the minimal symbols that came
2638 from the elf (non-stab) symbol table, so always act like an
2639 incremental load here. */
2640 dbx_symfile_read (objfile
, 0);
2643 /* Scan and build partial symbols for a file with special sections for stabs
2644 and stabstrings. The file has already been processed to get its minimal
2645 symbols, and any other symbols that might be necessary to resolve GSYMs.
2647 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
2650 OBJFILE is the object file we are reading symbols from.
2651 ADDR is the address relative to which the symbols are (e.g. the base address
2652 of the text segment).
2653 MAINLINE is true if we are reading the main symbol table (as opposed to a
2654 shared lib or dynamically loaded file).
2655 STAB_NAME is the name of the section that contains the stabs.
2656 STABSTR_NAME is the name of the section that contains the stab strings.
2658 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */
2661 stabsect_build_psymtabs (struct objfile
*objfile
, int mainline
, char *stab_name
,
2662 char *stabstr_name
, char *text_name
)
2665 bfd
*sym_bfd
= objfile
->obfd
;
2666 char *name
= bfd_get_filename (sym_bfd
);
2668 asection
*stabstrsect
;
2669 asection
*text_sect
;
2671 stabsect
= bfd_get_section_by_name (sym_bfd
, stab_name
);
2672 stabstrsect
= bfd_get_section_by_name (sym_bfd
, stabstr_name
);
2678 error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)",
2679 stab_name
, stabstr_name
);
2681 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
2682 xmalloc (sizeof (struct dbx_symfile_info
));
2683 memset (objfile
->sym_stab_info
, 0, sizeof (struct dbx_symfile_info
));
2685 text_sect
= bfd_get_section_by_name (sym_bfd
, text_name
);
2687 error ("Can't find %s section in symbol file", text_name
);
2688 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
2689 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
2691 DBX_SYMBOL_SIZE (objfile
) = sizeof (struct external_nlist
);
2692 DBX_SYMCOUNT (objfile
) = bfd_section_size (sym_bfd
, stabsect
)
2693 / DBX_SYMBOL_SIZE (objfile
);
2694 DBX_STRINGTAB_SIZE (objfile
) = bfd_section_size (sym_bfd
, stabstrsect
);
2695 DBX_SYMTAB_OFFSET (objfile
) = stabsect
->filepos
; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */
2697 if (DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
2698 error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile
));
2699 DBX_STRINGTAB (objfile
) = (char *)
2700 obstack_alloc (&objfile
->psymbol_obstack
, DBX_STRINGTAB_SIZE (objfile
) + 1);
2701 OBJSTAT (objfile
, sz_strtab
+= DBX_STRINGTAB_SIZE (objfile
) + 1);
2703 /* Now read in the string table in one big gulp. */
2705 val
= bfd_get_section_contents (sym_bfd
, /* bfd */
2706 stabstrsect
, /* bfd section */
2707 DBX_STRINGTAB (objfile
), /* input buffer */
2708 0, /* offset into section */
2709 DBX_STRINGTAB_SIZE (objfile
)); /* amount to read */
2712 perror_with_name (name
);
2714 stabsread_new_init ();
2715 buildsym_new_init ();
2716 free_header_files ();
2717 init_header_files ();
2718 install_minimal_symbols (objfile
);
2720 /* Now, do an incremental load */
2722 processing_acc_compilation
= 1;
2723 dbx_symfile_read (objfile
, 0);
2726 static struct sym_fns aout_sym_fns
=
2728 bfd_target_aout_flavour
,
2729 dbx_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2730 dbx_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2731 dbx_symfile_read
, /* sym_read: read a symbol file into symtab */
2732 dbx_symfile_finish
, /* sym_finish: finished with file, cleanup */
2733 default_symfile_offsets
, /* sym_offsets: parse user's offsets to internal form */
2734 NULL
/* next: pointer to next struct sym_fns */
2738 _initialize_dbxread (void)
2740 add_symtab_fns (&aout_sym_fns
);