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, 2002
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>
45 #include "gdb_obstack.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 for local_hex_string */
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 /* Offset within the file symbol table of first local symbol for this
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. */
92 /* The size of each symbol in the symbol file (in external form). */
96 /* Further information needed to locate the symbols if they are in
101 int file_string_offset
;
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)
113 /* Remember what we deduced to be the source language of this psymtab. */
115 static enum language psymtab_language
= language_unknown
;
117 /* The BFD for this file -- implicit parameter to next_symbol_text. */
119 static bfd
*symfile_bfd
;
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. */
125 static unsigned symbol_size
;
127 /* This is the offset of the symbol table in the executable file. */
129 static unsigned symbol_table_offset
;
131 /* This is the offset of the string table in the executable file. */
133 static unsigned string_table_offset
;
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. */
141 static unsigned int file_string_table_offset
;
142 static unsigned int next_file_string_table_offset
;
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. */
148 static int symfile_relocatable
= 0;
150 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
151 relative to the function start address. */
153 static int block_address_function_relative
= 0;
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). */
161 static CORE_ADDR lowest_text_address
;
163 /* Non-zero if there is any line number info in the objfile. Prevents
164 end_psymtab from discarding an otherwise empty psymtab. */
166 static int has_line_numbers
;
168 /* Complaints about the symbols we have encountered. */
170 struct complaint lbrac_complaint
=
171 {"bad block start address patched", 0, 0};
173 struct complaint string_table_offset_complaint
=
174 {"bad string table offset in symbol %d", 0, 0};
176 struct complaint unknown_symtype_complaint
=
177 {"unknown symbol type %s", 0, 0};
179 struct complaint unknown_symchar_complaint
=
180 {"unknown symbol descriptor `%c'", 0, 0};
182 struct complaint lbrac_rbrac_complaint
=
183 {"block start larger than block end", 0, 0};
185 struct complaint lbrac_unmatched_complaint
=
186 {"unmatched N_LBRAC before symtab pos %d", 0, 0};
188 struct complaint lbrac_mismatch_complaint
=
189 {"N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", 0, 0};
191 struct complaint repeated_header_complaint
=
192 {"\"repeated\" header file %s not previously seen, at symtab pos %d", 0, 0};
194 struct complaint unclaimed_bincl_complaint
=
195 {"N_BINCL %s not in entries for any file, at symtab pos %d", 0, 0};
197 struct complaint discarding_local_symbols_complaint
=
198 {"misplaced N_LBRAC entry; discarding local symbols which have no enclosing block", 0, 0};
200 /* find_text_range --- find start and end of loadable code sections
202 The find_text_range function finds the shortest address range that
203 encloses all sections containing executable code, and stores it in
204 objfile's text_addr and text_size members.
206 dbx_symfile_read will use this to finish off the partial symbol
207 table, in some cases. */
210 find_text_range (bfd
* sym_bfd
, struct objfile
*objfile
)
217 for (sec
= sym_bfd
->sections
; sec
; sec
= sec
->next
)
218 if (bfd_get_section_flags (sym_bfd
, sec
) & SEC_CODE
)
220 CORE_ADDR sec_start
= bfd_section_vma (sym_bfd
, sec
);
221 CORE_ADDR sec_end
= sec_start
+ bfd_section_size (sym_bfd
, sec
);
225 if (sec_start
< start
)
240 error ("Can't find any code sections in symbol file");
242 DBX_TEXT_ADDR (objfile
) = start
;
243 DBX_TEXT_SIZE (objfile
) = end
- start
;
248 /* During initial symbol readin, we need to have a structure to keep
249 track of which psymtabs have which bincls in them. This structure
250 is used during readin to setup the list of dependencies within each
251 partial symbol table. */
253 struct header_file_location
255 char *name
; /* Name of header file */
256 int instance
; /* See above */
257 struct partial_symtab
*pst
; /* Partial symtab that has the
258 BINCL/EINCL defs for this file */
261 /* The actual list and controling variables */
262 static struct header_file_location
*bincl_list
, *next_bincl
;
263 static int bincls_allocated
;
265 /* Local function prototypes */
267 extern void _initialize_dbxread (void);
269 static void process_now (struct objfile
*);
271 static void read_ofile_symtab (struct partial_symtab
*);
273 static void dbx_psymtab_to_symtab (struct partial_symtab
*);
275 static void dbx_psymtab_to_symtab_1 (struct partial_symtab
*);
277 static void read_dbx_dynamic_symtab (struct objfile
*objfile
);
279 static void read_dbx_symtab (struct objfile
*);
281 static void free_bincl_list (struct objfile
*);
283 static struct partial_symtab
*find_corresponding_bincl_psymtab (char *, int);
285 static void add_bincl_to_list (struct partial_symtab
*, char *, int);
287 static void init_bincl_list (int, struct objfile
*);
289 static char *dbx_next_symbol_text (struct objfile
*);
291 static void fill_symbuf (bfd
*);
293 static void dbx_symfile_init (struct objfile
*);
295 static void dbx_new_init (struct objfile
*);
297 static void dbx_symfile_read (struct objfile
*, int);
299 static void dbx_symfile_finish (struct objfile
*);
301 static void record_minimal_symbol (char *, CORE_ADDR
, int, struct objfile
*);
303 static void add_new_header_file (char *, int);
305 static void add_old_header_file (char *, int);
307 static void add_this_object_header_file (int);
309 static struct partial_symtab
*start_psymtab (struct objfile
*, char *,
311 struct partial_symbol
**,
312 struct partial_symbol
**);
314 /* Free up old header file tables */
317 free_header_files (void)
319 if (this_object_header_files
)
321 xfree (this_object_header_files
);
322 this_object_header_files
= NULL
;
324 n_allocated_this_object_header_files
= 0;
327 /* Allocate new header file tables */
330 init_header_files (void)
332 n_allocated_this_object_header_files
= 10;
333 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
336 /* Add header file number I for this object file
337 at the next successive FILENUM. */
340 add_this_object_header_file (int i
)
342 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
344 n_allocated_this_object_header_files
*= 2;
345 this_object_header_files
346 = (int *) xrealloc ((char *) this_object_header_files
,
347 n_allocated_this_object_header_files
* sizeof (int));
350 this_object_header_files
[n_this_object_header_files
++] = i
;
353 /* Add to this file an "old" header file, one already seen in
354 a previous object file. NAME is the header file's name.
355 INSTANCE is its instance code, to select among multiple
356 symbol tables for the same header file. */
359 add_old_header_file (char *name
, int instance
)
361 register struct header_file
*p
= HEADER_FILES (current_objfile
);
364 for (i
= 0; i
< N_HEADER_FILES (current_objfile
); i
++)
365 if (STREQ (p
[i
].name
, name
) && instance
== p
[i
].instance
)
367 add_this_object_header_file (i
);
370 complain (&repeated_header_complaint
, name
, symnum
);
373 /* Add to this file a "new" header file: definitions for its types follow.
374 NAME is the header file's name.
375 Most often this happens only once for each distinct header file,
376 but not necessarily. If it happens more than once, INSTANCE has
377 a different value each time, and references to the header file
378 use INSTANCE values to select among them.
380 dbx output contains "begin" and "end" markers for each new header file,
381 but at this level we just need to know which files there have been;
382 so we record the file when its "begin" is seen and ignore the "end". */
385 add_new_header_file (char *name
, int instance
)
388 register struct header_file
*hfile
;
390 /* Make sure there is room for one more header file. */
392 i
= N_ALLOCATED_HEADER_FILES (current_objfile
);
394 if (N_HEADER_FILES (current_objfile
) == i
)
398 N_ALLOCATED_HEADER_FILES (current_objfile
) = 10;
399 HEADER_FILES (current_objfile
) = (struct header_file
*)
400 xmalloc (10 * sizeof (struct header_file
));
405 N_ALLOCATED_HEADER_FILES (current_objfile
) = i
;
406 HEADER_FILES (current_objfile
) = (struct header_file
*)
407 xrealloc ((char *) HEADER_FILES (current_objfile
),
408 (i
* sizeof (struct header_file
)));
412 /* Create an entry for this header file. */
414 i
= N_HEADER_FILES (current_objfile
)++;
415 hfile
= HEADER_FILES (current_objfile
) + i
;
416 hfile
->name
= savestring (name
, strlen (name
));
417 hfile
->instance
= instance
;
420 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
421 memset (hfile
->vector
, 0, 10 * sizeof (struct type
*));
423 add_this_object_header_file (i
);
427 static struct type
**
428 explicit_lookup_type (int real_filenum
, int index
)
430 register struct header_file
*f
= &HEADER_FILES (current_objfile
)[real_filenum
];
432 if (index
>= f
->length
)
435 f
->vector
= (struct type
**)
436 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
437 memset (&f
->vector
[f
->length
/ 2],
438 '\0', f
->length
* sizeof (struct type
*) / 2);
440 return &f
->vector
[index
];
445 record_minimal_symbol (char *name
, CORE_ADDR address
, int type
,
446 struct objfile
*objfile
)
448 enum minimal_symbol_type ms_type
;
450 asection
*bfd_section
;
456 section
= SECT_OFF_TEXT (objfile
);
457 bfd_section
= DBX_TEXT_SECTION (objfile
);
461 section
= SECT_OFF_DATA (objfile
);
462 bfd_section
= DBX_DATA_SECTION (objfile
);
466 section
= SECT_OFF_BSS (objfile
);
467 bfd_section
= DBX_BSS_SECTION (objfile
);
477 section
= SECT_OFF_DATA (objfile
);
478 bfd_section
= DBX_DATA_SECTION (objfile
);
481 /* I don't think this type actually exists; since a N_SETV is the result
482 of going over many .o files, it doesn't make sense to have one
484 ms_type
= mst_file_data
;
485 section
= SECT_OFF_DATA (objfile
);
486 bfd_section
= DBX_DATA_SECTION (objfile
);
493 ms_type
= mst_file_text
;
494 section
= SECT_OFF_TEXT (objfile
);
495 bfd_section
= DBX_TEXT_SECTION (objfile
);
498 ms_type
= mst_file_data
;
500 /* Check for __DYNAMIC, which is used by Sun shared libraries.
501 Record it as global even if it's local, not global, so
502 lookup_minimal_symbol can find it. We don't check symbol_leading_char
503 because for SunOS4 it always is '_'. */
504 if (name
[8] == 'C' && STREQ ("__DYNAMIC", name
))
507 /* Same with virtual function tables, both global and static. */
509 char *tempstring
= name
;
510 if (tempstring
[0] == bfd_get_symbol_leading_char (objfile
->obfd
))
512 if (is_vtable_name (tempstring
))
515 section
= SECT_OFF_DATA (objfile
);
516 bfd_section
= DBX_DATA_SECTION (objfile
);
519 ms_type
= mst_file_bss
;
520 section
= SECT_OFF_BSS (objfile
);
521 bfd_section
= DBX_BSS_SECTION (objfile
);
524 ms_type
= mst_unknown
;
530 if ((ms_type
== mst_file_text
|| ms_type
== mst_text
)
531 && address
< lowest_text_address
)
532 lowest_text_address
= address
;
534 prim_record_minimal_symbol_and_info
535 (name
, address
, ms_type
, NULL
, section
, bfd_section
, objfile
);
538 /* Scan and build partial symbols for a symbol file.
539 We have been initialized by a call to dbx_symfile_init, which
540 put all the relevant info into a "struct dbx_symfile_info",
541 hung off the objfile structure.
543 MAINLINE is true if we are reading the main symbol
544 table (as opposed to a shared lib or dynamically loaded file). */
547 dbx_symfile_read (struct objfile
*objfile
, int mainline
)
551 struct cleanup
*back_to
;
553 sym_bfd
= objfile
->obfd
;
555 /* .o and .nlm files are relocatables with text, data and bss segs based at
556 0. This flag disables special (Solaris stabs-in-elf only) fixups for
557 symbols with a value of 0. */
559 symfile_relocatable
= bfd_get_file_flags (sym_bfd
) & HAS_RELOC
;
561 /* This is true for Solaris (and all other systems which put stabs
562 in sections, hopefully, since it would be silly to do things
563 differently from Solaris), and false for SunOS4 and other a.out
565 block_address_function_relative
=
566 ((0 == strncmp (bfd_get_target (sym_bfd
), "elf", 3))
567 || (0 == strncmp (bfd_get_target (sym_bfd
), "som", 3))
568 || (0 == strncmp (bfd_get_target (sym_bfd
), "coff", 4))
569 || (0 == strncmp (bfd_get_target (sym_bfd
), "pe", 2))
570 || (0 == strncmp (bfd_get_target (sym_bfd
), "epoc-pe", 7))
571 || (0 == strncmp (bfd_get_target (sym_bfd
), "nlm", 3)));
573 val
= bfd_seek (sym_bfd
, DBX_SYMTAB_OFFSET (objfile
), SEEK_SET
);
575 perror_with_name (objfile
->name
);
577 /* If we are reinitializing, or if we have never loaded syms yet, init */
579 || (objfile
->global_psymbols
.size
== 0
580 && objfile
->static_psymbols
.size
== 0))
581 init_psymbol_list (objfile
, DBX_SYMCOUNT (objfile
));
583 symbol_size
= DBX_SYMBOL_SIZE (objfile
);
584 symbol_table_offset
= DBX_SYMTAB_OFFSET (objfile
);
586 free_pending_blocks ();
587 back_to
= make_cleanup (really_free_pendings
, 0);
589 init_minimal_symbol_collection ();
590 make_cleanup_discard_minimal_symbols ();
592 /* Read stabs data from executable file and define symbols. */
594 read_dbx_symtab (objfile
);
596 /* Add the dynamic symbols. */
598 read_dbx_dynamic_symtab (objfile
);
600 /* Install any minimal symbols that have been collected as the current
601 minimal symbols for this objfile. */
603 install_minimal_symbols (objfile
);
605 do_cleanups (back_to
);
608 /* Initialize anything that needs initializing when a completely new
609 symbol file is specified (not just adding some symbols from another
610 file, e.g. a shared library). */
613 dbx_new_init (struct objfile
*ignore
)
615 stabsread_new_init ();
616 buildsym_new_init ();
617 init_header_files ();
621 /* dbx_symfile_init ()
622 is the dbx-specific initialization routine for reading symbols.
623 It is passed a struct objfile which contains, among other things,
624 the BFD for the file whose symbols are being read, and a slot for a pointer
625 to "private data" which we fill with goodies.
627 We read the string table into malloc'd space and stash a pointer to it.
629 Since BFD doesn't know how to read debug symbols in a format-independent
630 way (and may never do so...), we have to do it ourselves. We will never
631 be called unless this is an a.out (or very similar) file.
632 FIXME, there should be a cleaner peephole into the BFD environment here. */
634 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
637 dbx_symfile_init (struct objfile
*objfile
)
640 bfd
*sym_bfd
= objfile
->obfd
;
641 char *name
= bfd_get_filename (sym_bfd
);
643 unsigned char size_temp
[DBX_STRINGTAB_SIZE_SIZE
];
645 /* Allocate struct to keep track of the symfile */
646 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
647 xmmalloc (objfile
->md
, sizeof (struct dbx_symfile_info
));
648 memset ((PTR
) objfile
->sym_stab_info
, 0, sizeof (struct dbx_symfile_info
));
650 DBX_TEXT_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".text");
651 DBX_DATA_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".data");
652 DBX_BSS_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".bss");
654 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
655 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
656 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
658 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
660 DBX_SYMFILE_INFO (objfile
)->stab_section_info
= NULL
;
662 text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
664 error ("Can't find .text section in symbol file");
665 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
666 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
668 DBX_SYMBOL_SIZE (objfile
) = obj_symbol_entry_size (sym_bfd
);
669 DBX_SYMCOUNT (objfile
) = bfd_get_symcount (sym_bfd
);
670 DBX_SYMTAB_OFFSET (objfile
) = SYMBOL_TABLE_OFFSET
;
672 /* Read the string table and stash it away in the psymbol_obstack. It is
673 only needed as long as we need to expand psymbols into full symbols,
674 so when we blow away the psymbol the string table goes away as well.
675 Note that gdb used to use the results of attempting to malloc the
676 string table, based on the size it read, as a form of sanity check
677 for botched byte swapping, on the theory that a byte swapped string
678 table size would be so totally bogus that the malloc would fail. Now
679 that we put in on the psymbol_obstack, we can't do this since gdb gets
680 a fatal error (out of virtual memory) if the size is bogus. We can
681 however at least check to see if the size is less than the size of
682 the size field itself, or larger than the size of the entire file.
683 Note that all valid string tables have a size greater than zero, since
684 the bytes used to hold the size are included in the count. */
686 if (STRING_TABLE_OFFSET
== 0)
688 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
689 will never be zero, even when there is no string table. This
690 would appear to be a bug in bfd. */
691 DBX_STRINGTAB_SIZE (objfile
) = 0;
692 DBX_STRINGTAB (objfile
) = NULL
;
696 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, SEEK_SET
);
698 perror_with_name (name
);
700 memset ((PTR
) size_temp
, 0, sizeof (size_temp
));
701 val
= bfd_bread ((PTR
) size_temp
, sizeof (size_temp
), sym_bfd
);
704 perror_with_name (name
);
708 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
709 EOF if there is no string table, and attempting to read the size
710 from EOF will read zero bytes. */
711 DBX_STRINGTAB_SIZE (objfile
) = 0;
712 DBX_STRINGTAB (objfile
) = NULL
;
716 /* Read some data that would appear to be the string table size.
717 If there really is a string table, then it is probably the right
718 size. Byteswap if necessary and validate the size. Note that
719 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
720 random data that happened to be at STRING_TABLE_OFFSET, because
721 bfd can't tell us there is no string table, the sanity checks may
722 or may not catch this. */
723 DBX_STRINGTAB_SIZE (objfile
) = bfd_h_get_32 (sym_bfd
, size_temp
);
725 if (DBX_STRINGTAB_SIZE (objfile
) < sizeof (size_temp
)
726 || DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
727 error ("ridiculous string table size (%d bytes).",
728 DBX_STRINGTAB_SIZE (objfile
));
730 DBX_STRINGTAB (objfile
) =
731 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
732 DBX_STRINGTAB_SIZE (objfile
));
733 OBJSTAT (objfile
, sz_strtab
+= DBX_STRINGTAB_SIZE (objfile
));
735 /* Now read in the string table in one big gulp. */
737 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, SEEK_SET
);
739 perror_with_name (name
);
740 val
= bfd_bread (DBX_STRINGTAB (objfile
),
741 DBX_STRINGTAB_SIZE (objfile
),
743 if (val
!= DBX_STRINGTAB_SIZE (objfile
))
744 perror_with_name (name
);
749 /* Perform any local cleanups required when we are done with a particular
750 objfile. I.E, we are in the process of discarding all symbol information
751 for an objfile, freeing up all memory held for it, and unlinking the
752 objfile struct from the global list of known objfiles. */
755 dbx_symfile_finish (struct objfile
*objfile
)
757 if (objfile
->sym_stab_info
!= NULL
)
759 if (HEADER_FILES (objfile
) != NULL
)
761 register int i
= N_HEADER_FILES (objfile
);
762 register struct header_file
*hfiles
= HEADER_FILES (objfile
);
766 xfree (hfiles
[i
].name
);
767 xfree (hfiles
[i
].vector
);
771 xmfree (objfile
->md
, objfile
->sym_stab_info
);
773 free_header_files ();
777 /* Buffer for reading the symbol table entries. */
778 static struct external_nlist symbuf
[4096];
779 static int symbuf_idx
;
780 static int symbuf_end
;
782 /* cont_elem is used for continuing information in cfront.
783 It saves information about which types need to be fixed up and
784 completed after all the stabs are read. */
787 /* sym and stabstring for continuing information in cfront */
790 /* state dependencies (statics that must be preserved) */
794 int (*func
) (struct objfile
*, struct symbol
*, char *);
795 /* other state dependencies include:
796 (assumption is that these will not change since process_now FIXME!!)
803 static struct cont_elem
*cont_list
= 0;
804 static int cont_limit
= 0;
805 static int cont_count
= 0;
807 /* Arrange for function F to be called with arguments SYM and P later
808 in the stabs reading process. */
810 process_later (struct symbol
*sym
, char *p
,
811 int (*f
) (struct objfile
*, struct symbol
*, char *))
814 /* Allocate more space for the deferred list. */
815 if (cont_count
>= cont_limit
- 1)
817 cont_limit
+= 32; /* chunk size */
820 = (struct cont_elem
*) xrealloc (cont_list
,
822 * sizeof (struct cont_elem
)));
824 error ("Virtual memory exhausted\n");
827 /* Save state variables so we can process these stabs later. */
828 cont_list
[cont_count
].sym_idx
= symbuf_idx
;
829 cont_list
[cont_count
].sym_end
= symbuf_end
;
830 cont_list
[cont_count
].symnum
= symnum
;
831 cont_list
[cont_count
].sym
= sym
;
832 cont_list
[cont_count
].stabs
= p
;
833 cont_list
[cont_count
].func
= f
;
837 /* Call deferred funtions in CONT_LIST. */
840 process_now (struct objfile
*objfile
)
849 int (*func
) (struct objfile
*, struct symbol
*, char *);
851 /* Save the state of our caller, we'll want to restore it before
853 save_symbuf_idx
= symbuf_idx
;
854 save_symbuf_end
= symbuf_end
;
855 save_symnum
= symnum
;
857 /* Iterate over all the deferred stabs. */
858 for (i
= 0; i
< cont_count
; i
++)
860 /* Restore the state for this deferred stab. */
861 symbuf_idx
= cont_list
[i
].sym_idx
;
862 symbuf_end
= cont_list
[i
].sym_end
;
863 symnum
= cont_list
[i
].symnum
;
864 sym
= cont_list
[i
].sym
;
865 stabs
= cont_list
[i
].stabs
;
866 func
= cont_list
[i
].func
;
868 /* Call the function to handle this deferrd stab. */
869 err
= (*func
) (objfile
, sym
, stabs
);
871 error ("Internal error: unable to resolve stab.\n");
874 /* Restore our caller's state. */
875 symbuf_idx
= save_symbuf_idx
;
876 symbuf_end
= save_symbuf_end
;
877 symnum
= save_symnum
;
882 /* Name of last function encountered. Used in Solaris to approximate
883 object file boundaries. */
884 static char *last_function_name
;
886 /* The address in memory of the string table of the object file we are
887 reading (which might not be the "main" object file, but might be a
888 shared library or some other dynamically loaded thing). This is
889 set by read_dbx_symtab when building psymtabs, and by
890 read_ofile_symtab when building symtabs, and is used only by
891 next_symbol_text. FIXME: If that is true, we don't need it when
892 building psymtabs, right? */
893 static char *stringtab_global
;
895 /* These variables are used to control fill_symbuf when the stabs
896 symbols are not contiguous (as may be the case when a COFF file is
897 linked using --split-by-reloc). */
898 static struct stab_section_list
*symbuf_sections
;
899 static unsigned int symbuf_left
;
900 static unsigned int symbuf_read
;
902 /* Refill the symbol table input buffer
903 and set the variables that control fetching entries from it.
904 Reports an error if no data available.
905 This function can read past the end of the symbol table
906 (into the string table) but this does no harm. */
909 fill_symbuf (bfd
*sym_bfd
)
914 if (symbuf_sections
== NULL
)
915 count
= sizeof (symbuf
);
918 if (symbuf_left
<= 0)
920 file_ptr filepos
= symbuf_sections
->section
->filepos
;
921 if (bfd_seek (sym_bfd
, filepos
, SEEK_SET
) != 0)
922 perror_with_name (bfd_get_filename (sym_bfd
));
923 symbuf_left
= bfd_section_size (sym_bfd
, symbuf_sections
->section
);
924 symbol_table_offset
= filepos
- symbuf_read
;
925 symbuf_sections
= symbuf_sections
->next
;
929 if (count
> sizeof (symbuf
))
930 count
= sizeof (symbuf
);
933 nbytes
= bfd_bread ((PTR
) symbuf
, count
, sym_bfd
);
935 perror_with_name (bfd_get_filename (sym_bfd
));
936 else if (nbytes
== 0)
937 error ("Premature end of file reading symbol table");
938 symbuf_end
= nbytes
/ symbol_size
;
940 symbuf_left
-= nbytes
;
941 symbuf_read
+= nbytes
;
944 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
946 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
947 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
948 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
949 if (bfd_get_sign_extend_vma (abfd)) \
950 (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
952 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
955 /* Invariant: The symbol pointed to by symbuf_idx is the first one
956 that hasn't been swapped. Swap the symbol at the same time
957 that symbuf_idx is incremented. */
959 /* dbx allows the text of a symbol name to be continued into the
960 next symbol name! When such a continuation is encountered
961 (a \ at the end of the text of a name)
962 call this function to get the continuation. */
965 dbx_next_symbol_text (struct objfile
*objfile
)
967 struct internal_nlist nlist
;
969 if (symbuf_idx
== symbuf_end
)
970 fill_symbuf (symfile_bfd
);
973 INTERNALIZE_SYMBOL (nlist
, &symbuf
[symbuf_idx
], symfile_bfd
);
974 OBJSTAT (objfile
, n_stabs
++);
978 return nlist
.n_strx
+ stringtab_global
+ file_string_table_offset
;
981 /* Initialize the list of bincls to contain none and have some
985 init_bincl_list (int number
, struct objfile
*objfile
)
987 bincls_allocated
= number
;
988 next_bincl
= bincl_list
= (struct header_file_location
*)
989 xmmalloc (objfile
->md
, bincls_allocated
* sizeof (struct header_file_location
));
992 /* Add a bincl to the list. */
995 add_bincl_to_list (struct partial_symtab
*pst
, char *name
, int instance
)
997 if (next_bincl
>= bincl_list
+ bincls_allocated
)
999 int offset
= next_bincl
- bincl_list
;
1000 bincls_allocated
*= 2;
1001 bincl_list
= (struct header_file_location
*)
1002 xmrealloc (pst
->objfile
->md
, (char *) bincl_list
,
1003 bincls_allocated
* sizeof (struct header_file_location
));
1004 next_bincl
= bincl_list
+ offset
;
1006 next_bincl
->pst
= pst
;
1007 next_bincl
->instance
= instance
;
1008 next_bincl
++->name
= name
;
1011 /* Given a name, value pair, find the corresponding
1012 bincl in the list. Return the partial symtab associated
1013 with that header_file_location. */
1015 static struct partial_symtab
*
1016 find_corresponding_bincl_psymtab (char *name
, int instance
)
1018 struct header_file_location
*bincl
;
1020 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
1021 if (bincl
->instance
== instance
1022 && STREQ (name
, bincl
->name
))
1025 complain (&repeated_header_complaint
, name
, symnum
);
1026 return (struct partial_symtab
*) 0;
1029 /* Free the storage allocated for the bincl list. */
1032 free_bincl_list (struct objfile
*objfile
)
1034 xmfree (objfile
->md
, (PTR
) bincl_list
);
1035 bincls_allocated
= 0;
1039 do_free_bincl_list_cleanup (void *objfile
)
1041 free_bincl_list (objfile
);
1044 static struct cleanup
*
1045 make_cleanup_free_bincl_list (struct objfile
*objfile
)
1047 return make_cleanup (do_free_bincl_list_cleanup
, objfile
);
1050 /* Set namestring based on nlist. If the string table index is invalid,
1051 give a fake name, and print a single error message per symbol file read,
1052 rather than abort the symbol reading or flood the user with messages. */
1055 set_namestring (struct objfile
*objfile
, struct internal_nlist nlist
)
1059 if (((unsigned) nlist
.n_strx
+ file_string_table_offset
) >=
1060 DBX_STRINGTAB_SIZE (objfile
))
1062 complain (&string_table_offset_complaint
, symnum
);
1063 namestring
= "<bad string table offset>";
1066 namestring
= nlist
.n_strx
+ file_string_table_offset
+
1067 DBX_STRINGTAB (objfile
);
1071 /* Scan a SunOs dynamic symbol table for symbols of interest and
1072 add them to the minimal symbol table. */
1075 read_dbx_dynamic_symtab (struct objfile
*objfile
)
1077 bfd
*abfd
= objfile
->obfd
;
1078 struct cleanup
*back_to
;
1088 CORE_ADDR sym_value
;
1091 /* Check that the symbol file has dynamic symbols that we know about.
1092 bfd_arch_unknown can happen if we are reading a sun3 symbol file
1093 on a sun4 host (and vice versa) and bfd is not configured
1094 --with-target=all. This would trigger an assertion in bfd/sunos.c,
1095 so we ignore the dynamic symbols in this case. */
1096 if (bfd_get_flavour (abfd
) != bfd_target_aout_flavour
1097 || (bfd_get_file_flags (abfd
) & DYNAMIC
) == 0
1098 || bfd_get_arch (abfd
) == bfd_arch_unknown
)
1101 dynsym_size
= bfd_get_dynamic_symtab_upper_bound (abfd
);
1102 if (dynsym_size
< 0)
1105 dynsyms
= (asymbol
**) xmalloc (dynsym_size
);
1106 back_to
= make_cleanup (xfree
, dynsyms
);
1108 dynsym_count
= bfd_canonicalize_dynamic_symtab (abfd
, dynsyms
);
1109 if (dynsym_count
< 0)
1111 do_cleanups (back_to
);
1115 /* Enter dynamic symbols into the minimal symbol table
1116 if this is a stripped executable. */
1117 if (bfd_get_symcount (abfd
) <= 0)
1120 for (counter
= 0; counter
< dynsym_count
; counter
++, symptr
++)
1122 asymbol
*sym
= *symptr
;
1126 sec
= bfd_get_section (sym
);
1128 /* BFD symbols are section relative. */
1129 sym_value
= sym
->value
+ sec
->vma
;
1131 if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1133 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1136 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1138 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1141 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1143 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
1149 if (sym
->flags
& BSF_GLOBAL
)
1152 record_minimal_symbol ((char *) bfd_asymbol_name (sym
), sym_value
,
1157 /* Symbols from shared libraries have a dynamic relocation entry
1158 that points to the associated slot in the procedure linkage table.
1159 We make a mininal symbol table entry with type mst_solib_trampoline
1160 at the address in the procedure linkage table. */
1161 dynrel_size
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1162 if (dynrel_size
< 0)
1164 do_cleanups (back_to
);
1168 dynrels
= (arelent
**) xmalloc (dynrel_size
);
1169 make_cleanup (xfree
, dynrels
);
1171 dynrel_count
= bfd_canonicalize_dynamic_reloc (abfd
, dynrels
, dynsyms
);
1172 if (dynrel_count
< 0)
1174 do_cleanups (back_to
);
1178 for (counter
= 0, relptr
= dynrels
;
1179 counter
< dynrel_count
;
1180 counter
++, relptr
++)
1182 arelent
*rel
= *relptr
;
1184 rel
->address
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1186 switch (bfd_get_arch (abfd
))
1188 case bfd_arch_sparc
:
1189 if (rel
->howto
->type
!= RELOC_JMP_SLOT
)
1193 /* `16' is the type BFD produces for a jump table relocation. */
1194 if (rel
->howto
->type
!= 16)
1197 /* Adjust address in the jump table to point to
1198 the start of the bsr instruction. */
1205 name
= (char *) bfd_asymbol_name (*rel
->sym_ptr_ptr
);
1206 prim_record_minimal_symbol (name
, address
, mst_solib_trampoline
,
1210 do_cleanups (back_to
);
1213 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1215 find_stab_function_addr (char *namestring
, char *filename
,
1216 struct objfile
*objfile
)
1218 struct minimal_symbol
*msym
;
1222 p
= strchr (namestring
, ':');
1227 strncpy (p
, namestring
, n
);
1230 msym
= lookup_minimal_symbol (p
, filename
, objfile
);
1233 /* Sun Fortran appends an underscore to the minimal symbol name,
1234 try again with an appended underscore if the minimal symbol
1238 msym
= lookup_minimal_symbol (p
, filename
, objfile
);
1241 if (msym
== NULL
&& filename
!= NULL
)
1243 /* Try again without the filename. */
1245 msym
= lookup_minimal_symbol (p
, NULL
, objfile
);
1247 if (msym
== NULL
&& filename
!= NULL
)
1249 /* And try again for Sun Fortran, but without the filename. */
1252 msym
= lookup_minimal_symbol (p
, NULL
, objfile
);
1255 return msym
== NULL
? 0 : SYMBOL_VALUE_ADDRESS (msym
);
1257 #endif /* SOFUN_ADDRESS_MAYBE_MISSING */
1259 /* Setup partial_symtab's describing each source file for which
1260 debugging information is available. */
1263 read_dbx_symtab (struct objfile
*objfile
)
1265 register struct external_nlist
*bufp
= 0; /* =0 avoids gcc -Wall glitch */
1266 struct internal_nlist nlist
;
1267 CORE_ADDR text_addr
;
1270 register char *namestring
;
1272 int past_first_source_file
= 0;
1273 CORE_ADDR last_o_file_start
= 0;
1274 CORE_ADDR last_function_start
= 0;
1275 struct cleanup
*back_to
;
1277 int textlow_not_set
;
1279 /* Current partial symtab */
1280 struct partial_symtab
*pst
;
1282 /* List of current psymtab's include files */
1283 char **psymtab_include_list
;
1284 int includes_allocated
;
1287 /* Index within current psymtab dependency list */
1288 struct partial_symtab
**dependency_list
;
1289 int dependencies_used
, dependencies_allocated
;
1291 text_addr
= DBX_TEXT_ADDR (objfile
);
1292 text_size
= DBX_TEXT_SIZE (objfile
);
1294 /* FIXME. We probably want to change stringtab_global rather than add this
1295 while processing every symbol entry. FIXME. */
1296 file_string_table_offset
= 0;
1297 next_file_string_table_offset
= 0;
1299 stringtab_global
= DBX_STRINGTAB (objfile
);
1301 pst
= (struct partial_symtab
*) 0;
1303 includes_allocated
= 30;
1305 psymtab_include_list
= (char **) alloca (includes_allocated
*
1308 dependencies_allocated
= 30;
1309 dependencies_used
= 0;
1311 (struct partial_symtab
**) alloca (dependencies_allocated
*
1312 sizeof (struct partial_symtab
*));
1314 /* Init bincl list */
1315 init_bincl_list (20, objfile
);
1316 back_to
= make_cleanup_free_bincl_list (objfile
);
1318 last_source_file
= NULL
;
1320 lowest_text_address
= (CORE_ADDR
) -1;
1322 symfile_bfd
= objfile
->obfd
; /* For next_text_symbol */
1323 abfd
= objfile
->obfd
;
1324 symbuf_end
= symbuf_idx
= 0;
1325 next_symbol_text_func
= dbx_next_symbol_text
;
1326 textlow_not_set
= 1;
1327 has_line_numbers
= 0;
1329 for (symnum
= 0; symnum
< DBX_SYMCOUNT (objfile
); symnum
++)
1331 /* Get the symbol for this run and pull out some info */
1332 QUIT
; /* allow this to be interruptable */
1333 if (symbuf_idx
== symbuf_end
)
1335 bufp
= &symbuf
[symbuf_idx
++];
1338 * Special case to speed up readin.
1340 if (bfd_h_get_8 (abfd
, bufp
->e_type
) == N_SLINE
)
1342 has_line_numbers
= 1;
1346 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
1347 OBJSTAT (objfile
, n_stabs
++);
1349 /* Ok. There is a lot of code duplicated in the rest of this
1350 switch statement (for efficiency reasons). Since I don't
1351 like duplicating code, I will do my penance here, and
1352 describe the code which is duplicated:
1354 *) The assignment to namestring.
1355 *) The call to strchr.
1356 *) The addition of a partial symbol the the two partial
1357 symbol lists. This last is a large section of code, so
1358 I've imbedded it in the following macro.
1361 switch (nlist
.n_type
)
1363 static struct complaint function_outside_compilation_unit
= {
1364 "function `%s' appears to be defined outside of all compilation units", 0, 0
1368 * Standard, external, non-debugger, symbols
1371 case N_TEXT
| N_EXT
:
1372 case N_NBTEXT
| N_EXT
:
1373 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1376 case N_DATA
| N_EXT
:
1377 case N_NBDATA
| N_EXT
:
1378 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
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
));
1390 namestring
= set_namestring (objfile
, nlist
);
1393 record_minimal_symbol (namestring
, nlist
.n_value
,
1394 nlist
.n_type
, objfile
); /* Always */
1397 /* Standard, local, non-debugger, symbols */
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. */
1409 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1410 namestring
= set_namestring (objfile
, nlist
);
1412 if ((namestring
[0] == '-' && namestring
[1] == 'l')
1413 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
1414 && namestring
[nsl
- 2] == '.'))
1416 if (objfile
->ei
.entry_point
< nlist
.n_value
&&
1417 objfile
->ei
.entry_point
>= last_o_file_start
)
1419 objfile
->ei
.entry_file_lowpc
= last_o_file_start
;
1420 objfile
->ei
.entry_file_highpc
= nlist
.n_value
;
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. */
1425 && nlist
.n_value
>= pst
->textlow
)
1427 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1428 symnum
* symbol_size
,
1429 nlist
.n_value
> pst
->texthigh
1430 ? nlist
.n_value
: pst
->texthigh
,
1431 dependency_list
, dependencies_used
, textlow_not_set
);
1432 pst
= (struct partial_symtab
*) 0;
1434 dependencies_used
= 0;
1437 past_first_source_file
= 1;
1438 last_o_file_start
= nlist
.n_value
;
1445 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1448 case N_UNDF
| N_EXT
:
1449 if (nlist
.n_value
!= 0)
1451 /* This is a "Fortran COMMON" symbol. See if the target
1452 environment knows where it has been relocated to. */
1456 namestring
= set_namestring (objfile
, nlist
);
1457 if (target_lookup_symbol (namestring
, &reladdr
))
1459 continue; /* Error in lookup; ignore symbol for now. */
1461 nlist
.n_type
^= (N_BSS
^ N_UNDF
); /* Define it as a bss-symbol */
1462 nlist
.n_value
= reladdr
;
1463 goto bss_ext_symbol
;
1465 continue; /* Just undefined, not COMMON */
1468 if (processing_acc_compilation
&& nlist
.n_strx
== 1)
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. */
1486 /* Lots of symbol types we can just ignore. */
1493 /* Keep going . . . */
1496 * Special symbol types for GNU
1499 case N_INDR
| N_EXT
:
1501 case N_SETA
| N_EXT
:
1503 case N_SETT
| N_EXT
:
1505 case N_SETD
| N_EXT
:
1507 case N_SETB
| N_EXT
:
1518 static int prev_so_symnum
= -10;
1519 static int first_so_symnum
;
1521 int prev_textlow_not_set
;
1523 valu
= nlist
.n_value
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1525 prev_textlow_not_set
= textlow_not_set
;
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. */
1532 if (nlist
.n_value
== 0)
1534 textlow_not_set
= 1;
1538 textlow_not_set
= 0;
1540 textlow_not_set
= 0;
1542 past_first_source_file
= 1;
1544 if (prev_so_symnum
!= symnum
- 1)
1545 { /* Here if prev stab wasn't N_SO */
1546 first_so_symnum
= symnum
;
1550 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1551 symnum
* symbol_size
,
1552 valu
> pst
->texthigh
? valu
: pst
->texthigh
,
1553 dependency_list
, dependencies_used
,
1554 prev_textlow_not_set
);
1555 pst
= (struct partial_symtab
*) 0;
1557 dependencies_used
= 0;
1561 prev_so_symnum
= symnum
;
1563 /* End the current partial symtab and start a new one */
1565 namestring
= set_namestring (objfile
, nlist
);
1567 /* Null name means end of .o file. Don't start a new one. */
1568 if (*namestring
== '\000')
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. */
1576 p
= strrchr (namestring
, '/');
1577 if (p
&& *(p
+ 1) == '\000')
1578 continue; /* Simply ignore directory name SOs */
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. */
1585 pst
= start_psymtab (objfile
,
1587 first_so_symnum
* symbol_size
,
1588 objfile
->global_psymbols
.next
,
1589 objfile
->static_psymbols
.next
);
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 */
1600 namestring
= set_namestring (objfile
, nlist
);
1601 tmp_language
= deduce_language_from_filename (namestring
);
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
1607 if (tmp_language
!= language_unknown
1608 && (tmp_language
!= language_c
1609 || psymtab_language
!= language_cplus
))
1610 psymtab_language
= tmp_language
;
1614 /* FIXME: we should not get here without a PST to work on.
1615 Attempt to recover. */
1616 complain (&unclaimed_bincl_complaint
, namestring
, symnum
);
1619 add_bincl_to_list (pst
, namestring
, nlist
.n_value
);
1621 /* Mark down an include file in the current psymtab */
1623 goto record_include_file
;
1628 enum language tmp_language
;
1629 /* Mark down an include file in the current psymtab */
1631 namestring
= set_namestring (objfile
, nlist
);
1632 tmp_language
= deduce_language_from_filename (namestring
);
1634 /* Only change the psymtab's language if we've learned
1635 something useful (eg. tmp_language is not language_unknown).
1636 In addition, to match what start_subfile does, never change
1638 if (tmp_language
!= language_unknown
1639 && (tmp_language
!= language_c
1640 || psymtab_language
!= language_cplus
))
1641 psymtab_language
= tmp_language
;
1643 /* In C++, one may expect the same filename to come round many
1644 times, when code is coming alternately from the main file
1645 and from inline functions in other files. So I check to see
1646 if this is a file we've seen before -- either the main
1647 source file, or a previously included file.
1649 This seems to be a lot of time to be spending on N_SOL, but
1650 things like "break c-exp.y:435" need to work (I
1651 suppose the psymtab_include_list could be hashed or put
1652 in a binary tree, if profiling shows this is a major hog). */
1653 if (pst
&& STREQ (namestring
, pst
->filename
))
1657 for (i
= 0; i
< includes_used
; i
++)
1658 if (STREQ (namestring
, psymtab_include_list
[i
]))
1667 record_include_file
:
1669 psymtab_include_list
[includes_used
++] = namestring
;
1670 if (includes_used
>= includes_allocated
)
1672 char **orig
= psymtab_include_list
;
1674 psymtab_include_list
= (char **)
1675 alloca ((includes_allocated
*= 2) *
1677 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
1678 includes_used
* sizeof (char *));
1682 case N_LSYM
: /* Typedef or automatic variable. */
1683 case N_STSYM
: /* Data seg var -- static */
1684 case N_LCSYM
: /* BSS " */
1685 case N_ROSYM
: /* Read-only data seg var -- static. */
1686 case N_NBSTS
: /* Gould nobase. */
1687 case N_NBLCS
: /* symbols. */
1689 case N_GSYM
: /* Global (extern) variable; can be
1690 data or bss (sigh FIXME). */
1692 /* Following may probably be ignored; I'll leave them here
1693 for now (until I do Pascal and Modula 2 extensions). */
1695 case N_PC
: /* I may or may not need this; I
1697 case N_M2C
: /* I suspect that I can ignore this here. */
1698 case N_SCOPE
: /* Same. */
1700 namestring
= set_namestring (objfile
, nlist
);
1702 /* See if this is an end of function stab. */
1703 if (pst
&& nlist
.n_type
== N_FUN
&& *namestring
== '\000')
1707 /* It's value is the size (in bytes) of the function for
1708 function relative stabs, or the address of the function's
1709 end for old style stabs. */
1710 valu
= nlist
.n_value
+ last_function_start
;
1711 if (pst
->texthigh
== 0 || valu
> pst
->texthigh
)
1712 pst
->texthigh
= valu
;
1716 p
= (char *) strchr (namestring
, ':');
1718 continue; /* Not a debugging symbol. */
1722 /* Main processing section for debugging symbols which
1723 the initial read through the symbol tables needs to worry
1724 about. If we reach this point, the symbol which we are
1725 considering is definitely one we are interested in.
1726 p must also contain the (valid) index into the namestring
1727 which indicates the debugging type symbol. */
1732 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1733 #ifdef STATIC_TRANSFORM_NAME
1734 namestring
= STATIC_TRANSFORM_NAME (namestring
);
1736 add_psymbol_to_list (namestring
, p
- namestring
,
1737 VAR_NAMESPACE
, LOC_STATIC
,
1738 &objfile
->static_psymbols
,
1740 psymtab_language
, objfile
);
1743 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1744 /* The addresses in these entries are reported to be
1745 wrong. See the code that reads 'G's for symtabs. */
1746 add_psymbol_to_list (namestring
, p
- namestring
,
1747 VAR_NAMESPACE
, LOC_STATIC
,
1748 &objfile
->global_psymbols
,
1750 psymtab_language
, objfile
);
1754 /* When a 'T' entry is defining an anonymous enum, it
1755 may have a name which is the empty string, or a
1756 single space. Since they're not really defining a
1757 symbol, those shouldn't go in the partial symbol
1758 table. We do pick up the elements of such enums at
1759 'check_enum:', below. */
1760 if (p
>= namestring
+ 2
1761 || (p
== namestring
+ 1
1762 && namestring
[0] != ' '))
1764 add_psymbol_to_list (namestring
, p
- namestring
,
1765 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1766 &objfile
->static_psymbols
,
1768 psymtab_language
, objfile
);
1771 /* Also a typedef with the same name. */
1772 add_psymbol_to_list (namestring
, p
- namestring
,
1773 VAR_NAMESPACE
, LOC_TYPEDEF
,
1774 &objfile
->static_psymbols
,
1776 psymtab_language
, objfile
);
1779 /* The semantics of C++ state that "struct foo { ... }"
1780 also defines a typedef for "foo". Unfortuantely, cfront
1781 never makes the typedef when translating from C++ to C.
1782 We make the typedef here so that "ptype foo" works as
1783 expected for cfront translated code. */
1784 else if (psymtab_language
== language_cplus
)
1786 /* Also a typedef with the same name. */
1787 add_psymbol_to_list (namestring
, p
- namestring
,
1788 VAR_NAMESPACE
, LOC_TYPEDEF
,
1789 &objfile
->static_psymbols
,
1791 psymtab_language
, objfile
);
1796 if (p
!= namestring
) /* a name is there, not just :T... */
1798 add_psymbol_to_list (namestring
, p
- namestring
,
1799 VAR_NAMESPACE
, LOC_TYPEDEF
,
1800 &objfile
->static_psymbols
,
1802 psymtab_language
, objfile
);
1805 /* If this is an enumerated type, we need to
1806 add all the enum constants to the partial symbol
1807 table. This does not cover enums without names, e.g.
1808 "enum {a, b} c;" in C, but fortunately those are
1809 rare. There is no way for GDB to find those from the
1810 enum type without spending too much time on it. Thus
1811 to solve this problem, the compiler needs to put out the
1812 enum in a nameless type. GCC2 does this. */
1814 /* We are looking for something of the form
1815 <name> ":" ("t" | "T") [<number> "="] "e"
1816 {<constant> ":" <value> ","} ";". */
1818 /* Skip over the colon and the 't' or 'T'. */
1820 /* This type may be given a number. Also, numbers can come
1821 in pairs like (0,26). Skip over it. */
1822 while ((*p
>= '0' && *p
<= '9')
1823 || *p
== '(' || *p
== ',' || *p
== ')'
1829 /* The aix4 compiler emits extra crud before the members. */
1832 /* Skip over the type (?). */
1836 /* Skip over the colon. */
1840 /* We have found an enumerated type. */
1841 /* According to comments in read_enum_type
1842 a comma could end it instead of a semicolon.
1843 I don't know where that happens.
1845 while (*p
&& *p
!= ';' && *p
!= ',')
1849 /* Check for and handle cretinous dbx symbol name
1851 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
1852 p
= next_symbol_text (objfile
);
1854 /* Point to the character after the name
1855 of the enum constant. */
1856 for (q
= p
; *q
&& *q
!= ':'; q
++)
1858 /* Note that the value doesn't matter for
1859 enum constants in psymtabs, just in symtabs. */
1860 add_psymbol_to_list (p
, q
- p
,
1861 VAR_NAMESPACE
, LOC_CONST
,
1862 &objfile
->static_psymbols
, 0,
1863 0, psymtab_language
, objfile
);
1864 /* Point past the name. */
1866 /* Skip over the value. */
1867 while (*p
&& *p
!= ',')
1869 /* Advance past the comma. */
1876 /* Constant, e.g. from "const" in Pascal. */
1877 add_psymbol_to_list (namestring
, p
- namestring
,
1878 VAR_NAMESPACE
, LOC_CONST
,
1879 &objfile
->static_psymbols
, nlist
.n_value
,
1880 0, psymtab_language
, objfile
);
1886 int name_len
= p
- namestring
;
1887 char *name
= xmalloc (name_len
+ 1);
1888 memcpy (name
, namestring
, name_len
);
1889 name
[name_len
] = '\0';
1890 complain (&function_outside_compilation_unit
, name
);
1893 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1894 /* Kludges for ELF/STABS with Sun ACC */
1895 last_function_name
= namestring
;
1896 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1897 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1898 value for the bottom of the text seg in those cases. */
1899 if (nlist
.n_value
== ANOFFSET (objfile
->section_offsets
,
1900 SECT_OFF_TEXT (objfile
)))
1902 CORE_ADDR minsym_valu
=
1903 find_stab_function_addr (namestring
, pst
->filename
, objfile
);
1904 /* find_stab_function_addr will return 0 if the minimal
1905 symbol wasn't found. (Unfortunately, this might also
1906 be a valid address.) Anyway, if it *does* return 0,
1907 it is likely that the value was set correctly to begin
1909 if (minsym_valu
!= 0)
1910 nlist
.n_value
= minsym_valu
;
1912 if (pst
&& textlow_not_set
)
1914 pst
->textlow
= nlist
.n_value
;
1915 textlow_not_set
= 0;
1920 /* Keep track of the start of the last function so we
1921 can handle end of function symbols. */
1922 last_function_start
= nlist
.n_value
;
1924 /* In reordered executables this function may lie outside
1925 the bounds created by N_SO symbols. If that's the case
1926 use the address of this function as the low bound for
1927 the partial symbol table. */
1930 || (nlist
.n_value
< pst
->textlow
1932 != ANOFFSET (objfile
->section_offsets
,
1933 SECT_OFF_TEXT (objfile
))))))
1935 pst
->textlow
= nlist
.n_value
;
1936 textlow_not_set
= 0;
1938 add_psymbol_to_list (namestring
, p
- namestring
,
1939 VAR_NAMESPACE
, LOC_BLOCK
,
1940 &objfile
->static_psymbols
,
1942 psymtab_language
, objfile
);
1945 /* Global functions were ignored here, but now they
1946 are put into the global psymtab like one would expect.
1947 They're also in the minimal symbol table. */
1951 int name_len
= p
- namestring
;
1952 char *name
= xmalloc (name_len
+ 1);
1953 memcpy (name
, namestring
, name_len
);
1954 name
[name_len
] = '\0';
1955 complain (&function_outside_compilation_unit
, name
);
1958 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1959 /* Kludges for ELF/STABS with Sun ACC */
1960 last_function_name
= namestring
;
1961 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1962 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1963 value for the bottom of the text seg in those cases. */
1964 if (nlist
.n_value
== ANOFFSET (objfile
->section_offsets
,
1965 SECT_OFF_TEXT (objfile
)))
1967 CORE_ADDR minsym_valu
=
1968 find_stab_function_addr (namestring
, pst
->filename
, objfile
);
1969 /* find_stab_function_addr will return 0 if the minimal
1970 symbol wasn't found. (Unfortunately, this might also
1971 be a valid address.) Anyway, if it *does* return 0,
1972 it is likely that the value was set correctly to begin
1974 if (minsym_valu
!= 0)
1975 nlist
.n_value
= minsym_valu
;
1977 if (pst
&& textlow_not_set
)
1979 pst
->textlow
= nlist
.n_value
;
1980 textlow_not_set
= 0;
1985 /* Keep track of the start of the last function so we
1986 can handle end of function symbols. */
1987 last_function_start
= nlist
.n_value
;
1989 /* In reordered executables this function may lie outside
1990 the bounds created by N_SO symbols. If that's the case
1991 use the address of this function as the low bound for
1992 the partial symbol table. */
1995 || (nlist
.n_value
< pst
->textlow
1997 != ANOFFSET (objfile
->section_offsets
,
1998 SECT_OFF_TEXT (objfile
))))))
2000 pst
->textlow
= nlist
.n_value
;
2001 textlow_not_set
= 0;
2003 add_psymbol_to_list (namestring
, p
- namestring
,
2004 VAR_NAMESPACE
, LOC_BLOCK
,
2005 &objfile
->global_psymbols
,
2007 psymtab_language
, objfile
);
2010 /* Two things show up here (hopefully); static symbols of
2011 local scope (static used inside braces) or extensions
2012 of structure symbols. We can ignore both. */
2026 case '#': /* for symbol identification (used in live ranges) */
2027 /* added to support cfront stabs strings */
2028 case 'Z': /* for definition continuations */
2029 case 'P': /* for prototypes */
2033 /* It is a C++ nested symbol. We don't need to record it
2034 (I don't think); if we try to look up foo::bar::baz,
2035 then symbols for the symtab containing foo should get
2036 read in, I think. */
2037 /* Someone says sun cc puts out symbols like
2038 /foo/baz/maclib::/usr/local/bin/maclib,
2039 which would get here with a symbol type of ':'. */
2043 /* Unexpected symbol descriptor. The second and subsequent stabs
2044 of a continued stab can show up here. The question is
2045 whether they ever can mimic a normal stab--it would be
2046 nice if not, since we certainly don't want to spend the
2047 time searching to the end of every string looking for
2050 complain (&unknown_symchar_complaint
, p
[1]);
2052 /* Ignore it; perhaps it is an extension that we don't
2059 namestring
= set_namestring (objfile
, nlist
);
2061 /* Find the corresponding bincl and mark that psymtab on the
2062 psymtab dependency list */
2064 struct partial_symtab
*needed_pst
=
2065 find_corresponding_bincl_psymtab (namestring
, nlist
.n_value
);
2067 /* If this include file was defined earlier in this file,
2069 if (needed_pst
== pst
)
2077 for (i
= 0; i
< dependencies_used
; i
++)
2078 if (dependency_list
[i
] == needed_pst
)
2084 /* If it's already in the list, skip the rest. */
2088 dependency_list
[dependencies_used
++] = needed_pst
;
2089 if (dependencies_used
>= dependencies_allocated
)
2091 struct partial_symtab
**orig
= dependency_list
;
2093 (struct partial_symtab
**)
2094 alloca ((dependencies_allocated
*= 2)
2095 * sizeof (struct partial_symtab
*));
2096 memcpy ((PTR
) dependency_list
, (PTR
) orig
,
2098 * sizeof (struct partial_symtab
*)));
2100 fprintf_unfiltered (gdb_stderr
, "Had to reallocate dependency list.\n");
2101 fprintf_unfiltered (gdb_stderr
, "New dependencies allocated: %d\n",
2102 dependencies_allocated
);
2110 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2111 /* Solaris 2 end of module, finish current partial symbol table.
2112 end_psymtab will set pst->texthigh to the proper value, which
2113 is necessary if a module compiled without debugging info
2114 follows this module. */
2117 end_psymtab (pst
, psymtab_include_list
, includes_used
,
2118 symnum
* symbol_size
,
2120 dependency_list
, dependencies_used
, textlow_not_set
);
2121 pst
= (struct partial_symtab
*) 0;
2123 dependencies_used
= 0;
2130 HANDLE_RBRAC (nlist
.n_value
);
2136 case N_SSYM
: /* Claim: Structure or union element.
2137 Hopefully, I can ignore this. */
2138 case N_ENTRY
: /* Alternate entry point; can ignore. */
2139 case N_MAIN
: /* Can definitely ignore this. */
2140 case N_CATCH
: /* These are GNU C++ extensions */
2141 case N_EHDECL
: /* that can safely be ignored here. */
2151 case N_NSYMS
: /* Ultrix 4.0: symbol count */
2152 case N_DEFD
: /* GNU Modula-2 */
2153 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
2155 case N_OBJ
: /* useless types from Solaris */
2157 /* These symbols aren't interesting; don't worry about them */
2162 /* If we haven't found it yet, ignore it. It's probably some
2163 new type we don't know about yet. */
2164 complain (&unknown_symtype_complaint
,
2165 local_hex_string (nlist
.n_type
));
2170 /* If there's stuff to be cleaned up, clean it up. */
2171 if (DBX_SYMCOUNT (objfile
) > 0 /* We have some syms */
2172 /*FIXME, does this have a bug at start address 0? */
2173 && last_o_file_start
2174 && objfile
->ei
.entry_point
< nlist
.n_value
2175 && objfile
->ei
.entry_point
>= last_o_file_start
)
2177 objfile
->ei
.entry_file_lowpc
= last_o_file_start
;
2178 objfile
->ei
.entry_file_highpc
= nlist
.n_value
;
2183 /* Don't set pst->texthigh lower than it already is. */
2184 CORE_ADDR text_end
=
2185 (lowest_text_address
== (CORE_ADDR
) -1
2186 ? (text_addr
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
)))
2187 : lowest_text_address
)
2190 end_psymtab (pst
, psymtab_include_list
, includes_used
,
2191 symnum
* symbol_size
,
2192 text_end
> pst
->texthigh
? text_end
: pst
->texthigh
,
2193 dependency_list
, dependencies_used
, textlow_not_set
);
2196 do_cleanups (back_to
);
2199 /* Allocate and partially fill a partial symtab. It will be
2200 completely filled at the end of the symbol list.
2202 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2203 is the address relative to which its symbols are (incremental) or 0
2207 static struct partial_symtab
*
2208 start_psymtab (struct objfile
*objfile
, char *filename
, CORE_ADDR textlow
,
2209 int ldsymoff
, struct partial_symbol
**global_syms
,
2210 struct partial_symbol
**static_syms
)
2212 struct partial_symtab
*result
=
2213 start_psymtab_common (objfile
, objfile
->section_offsets
,
2214 filename
, textlow
, global_syms
, static_syms
);
2216 result
->read_symtab_private
= (char *)
2217 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2218 LDSYMOFF (result
) = ldsymoff
;
2219 result
->read_symtab
= dbx_psymtab_to_symtab
;
2220 SYMBOL_SIZE (result
) = symbol_size
;
2221 SYMBOL_OFFSET (result
) = symbol_table_offset
;
2222 STRING_OFFSET (result
) = string_table_offset
;
2223 FILE_STRING_OFFSET (result
) = file_string_table_offset
;
2225 /* If we're handling an ELF file, drag some section-relocation info
2226 for this source file out of the ELF symbol table, to compensate for
2227 Sun brain death. This replaces the section_offsets in this psymtab,
2229 elfstab_offset_sections (objfile
, result
);
2231 /* Deduce the source language from the filename for this psymtab. */
2232 psymtab_language
= deduce_language_from_filename (filename
);
2237 /* Close off the current usage of PST.
2238 Returns PST or NULL if the partial symtab was empty and thrown away.
2240 FIXME: List variables and peculiarities of same. */
2242 struct partial_symtab
*
2243 end_psymtab (struct partial_symtab
*pst
, char **include_list
, int num_includes
,
2244 int capping_symbol_offset
, CORE_ADDR capping_text
,
2245 struct partial_symtab
**dependency_list
, int number_dependencies
,
2246 int textlow_not_set
)
2249 struct objfile
*objfile
= pst
->objfile
;
2251 if (capping_symbol_offset
!= -1)
2252 LDSYMLEN (pst
) = capping_symbol_offset
- LDSYMOFF (pst
);
2253 pst
->texthigh
= capping_text
;
2255 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2256 /* Under Solaris, the N_SO symbols always have a value of 0,
2257 instead of the usual address of the .o file. Therefore,
2258 we have to do some tricks to fill in texthigh and textlow.
2259 The first trick is: if we see a static
2260 or global function, and the textlow for the current pst
2261 is not set (ie: textlow_not_set), then we use that function's
2262 address for the textlow of the pst. */
2264 /* Now, to fill in texthigh, we remember the last function seen
2265 in the .o file. Also, there's a hack in
2266 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
2267 to here via the misc_info field. Therefore, we can fill in
2268 a reliable texthigh by taking the address plus size of the
2269 last function in the file. */
2271 if (pst
->texthigh
== 0 && last_function_name
)
2275 struct minimal_symbol
*minsym
;
2277 p
= strchr (last_function_name
, ':');
2279 p
= last_function_name
;
2280 n
= p
- last_function_name
;
2282 strncpy (p
, last_function_name
, n
);
2285 minsym
= lookup_minimal_symbol (p
, pst
->filename
, objfile
);
2288 /* Sun Fortran appends an underscore to the minimal symbol name,
2289 try again with an appended underscore if the minimal symbol
2293 minsym
= lookup_minimal_symbol (p
, pst
->filename
, objfile
);
2297 pst
->texthigh
= SYMBOL_VALUE_ADDRESS (minsym
) + MSYMBOL_SIZE (minsym
);
2299 last_function_name
= NULL
;
2302 /* this test will be true if the last .o file is only data */
2303 if (textlow_not_set
)
2304 pst
->textlow
= pst
->texthigh
;
2307 struct partial_symtab
*p1
;
2309 /* If we know our own starting text address, then walk through all other
2310 psymtabs for this objfile, and if any didn't know their ending text
2311 address, set it to our starting address. Take care to not set our
2312 own ending address to our starting address, nor to set addresses on
2313 `dependency' files that have both textlow and texthigh zero. */
2315 ALL_OBJFILE_PSYMTABS (objfile
, p1
)
2317 if (p1
->texthigh
== 0 && p1
->textlow
!= 0 && p1
!= pst
)
2319 p1
->texthigh
= pst
->textlow
;
2320 /* if this file has only data, then make textlow match texthigh */
2321 if (p1
->textlow
== 0)
2322 p1
->textlow
= p1
->texthigh
;
2327 /* End of kludge for patching Solaris textlow and texthigh. */
2328 #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */
2330 pst
->n_global_syms
=
2331 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2332 pst
->n_static_syms
=
2333 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2335 pst
->number_of_dependencies
= number_dependencies
;
2336 if (number_dependencies
)
2338 pst
->dependencies
= (struct partial_symtab
**)
2339 obstack_alloc (&objfile
->psymbol_obstack
,
2340 number_dependencies
* sizeof (struct partial_symtab
*));
2341 memcpy (pst
->dependencies
, dependency_list
,
2342 number_dependencies
* sizeof (struct partial_symtab
*));
2345 pst
->dependencies
= 0;
2347 for (i
= 0; i
< num_includes
; i
++)
2349 struct partial_symtab
*subpst
=
2350 allocate_psymtab (include_list
[i
], objfile
);
2352 /* Copy the sesction_offsets array from the main psymtab. */
2353 subpst
->section_offsets
= pst
->section_offsets
;
2354 subpst
->read_symtab_private
=
2355 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2356 sizeof (struct symloc
));
2360 subpst
->texthigh
= 0;
2362 /* We could save slight bits of space by only making one of these,
2363 shared by the entire set of include files. FIXME-someday. */
2364 subpst
->dependencies
= (struct partial_symtab
**)
2365 obstack_alloc (&objfile
->psymbol_obstack
,
2366 sizeof (struct partial_symtab
*));
2367 subpst
->dependencies
[0] = pst
;
2368 subpst
->number_of_dependencies
= 1;
2370 subpst
->globals_offset
=
2371 subpst
->n_global_syms
=
2372 subpst
->statics_offset
=
2373 subpst
->n_static_syms
= 0;
2377 subpst
->read_symtab
= pst
->read_symtab
;
2380 sort_pst_symbols (pst
);
2382 /* If there is already a psymtab or symtab for a file of this name, remove it.
2383 (If there is a symtab, more drastic things also happen.)
2384 This happens in VxWorks. */
2385 free_named_symtabs (pst
->filename
);
2387 if (num_includes
== 0
2388 && number_dependencies
== 0
2389 && pst
->n_global_syms
== 0
2390 && pst
->n_static_syms
== 0
2391 && has_line_numbers
== 0)
2393 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2394 it is on the obstack, but we can forget to chain it on the list. */
2395 /* Empty psymtabs happen as a result of header files which don't have
2396 any symbols in them. There can be a lot of them. But this check
2397 is wrong, in that a psymtab with N_SLINE entries but nothing else
2398 is not empty, but we don't realize that. Fixing that without slowing
2399 things down might be tricky. */
2401 discard_psymtab (pst
);
2403 /* Indicate that psymtab was thrown away. */
2404 pst
= (struct partial_symtab
*) NULL
;
2410 dbx_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2412 struct cleanup
*old_chain
;
2420 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2425 /* Read in all partial symtabs on which this one is dependent */
2426 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2427 if (!pst
->dependencies
[i
]->readin
)
2429 /* Inform about additional files that need to be read in. */
2432 fputs_filtered (" ", gdb_stdout
);
2434 fputs_filtered ("and ", gdb_stdout
);
2436 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2437 wrap_here (""); /* Flush output */
2438 gdb_flush (gdb_stdout
);
2440 dbx_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2443 if (LDSYMLEN (pst
)) /* Otherwise it's a dummy */
2445 /* Init stuff necessary for reading in symbols */
2448 old_chain
= make_cleanup (really_free_pendings
, 0);
2449 file_string_table_offset
= FILE_STRING_OFFSET (pst
);
2450 symbol_size
= SYMBOL_SIZE (pst
);
2452 /* Read in this file's symbols */
2453 bfd_seek (pst
->objfile
->obfd
, SYMBOL_OFFSET (pst
), SEEK_SET
);
2454 read_ofile_symtab (pst
);
2455 sort_symtab_syms (pst
->symtab
);
2457 do_cleanups (old_chain
);
2463 /* Read in all of the symbols for a given psymtab for real.
2464 Be verbose about it if the user wants that. */
2467 dbx_psymtab_to_symtab (struct partial_symtab
*pst
)
2476 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2481 if (LDSYMLEN (pst
) || pst
->number_of_dependencies
)
2483 /* Print the message now, before reading the string table,
2484 to avoid disconcerting pauses. */
2487 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2488 gdb_flush (gdb_stdout
);
2491 sym_bfd
= pst
->objfile
->obfd
;
2493 next_symbol_text_func
= dbx_next_symbol_text
;
2495 dbx_psymtab_to_symtab_1 (pst
);
2497 /* Match with global symbols. This only needs to be done once,
2498 after all of the symtabs and dependencies have been read in. */
2499 scan_file_globals (pst
->objfile
);
2501 /* Finish up the debug error message. */
2503 printf_filtered ("done.\n");
2507 /* Read in a defined section of a specific object file's symbols. */
2510 read_ofile_symtab (struct partial_symtab
*pst
)
2512 register char *namestring
;
2513 register struct external_nlist
*bufp
;
2514 struct internal_nlist nlist
;
2516 unsigned max_symnum
;
2518 struct objfile
*objfile
;
2519 int sym_offset
; /* Offset to start of symbols to read */
2520 int sym_size
; /* Size of symbols to read */
2521 CORE_ADDR text_offset
; /* Start of text segment for symbols */
2522 int text_size
; /* Size of text segment for symbols */
2523 struct section_offsets
*section_offsets
;
2525 objfile
= pst
->objfile
;
2526 sym_offset
= LDSYMOFF (pst
);
2527 sym_size
= LDSYMLEN (pst
);
2528 text_offset
= pst
->textlow
;
2529 text_size
= pst
->texthigh
- pst
->textlow
;
2530 /* This cannot be simply objfile->section_offsets because of
2531 elfstab_offset_sections() which initializes the psymtab section
2532 offsets information in a special way, and that is different from
2533 objfile->section_offsets. */
2534 section_offsets
= pst
->section_offsets
;
2536 current_objfile
= objfile
;
2537 subfile_stack
= NULL
;
2539 stringtab_global
= DBX_STRINGTAB (objfile
);
2540 last_source_file
= NULL
;
2542 abfd
= objfile
->obfd
;
2543 symfile_bfd
= objfile
->obfd
; /* Implicit param to next_text_symbol */
2544 symbuf_end
= symbuf_idx
= 0;
2546 /* It is necessary to actually read one symbol *before* the start
2547 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2548 occurs before the N_SO symbol.
2550 Detecting this in read_dbx_symtab
2551 would slow down initial readin, so we look for it here instead. */
2552 if (!processing_acc_compilation
&& sym_offset
>= (int) symbol_size
)
2554 bfd_seek (symfile_bfd
, sym_offset
- symbol_size
, SEEK_CUR
);
2556 bufp
= &symbuf
[symbuf_idx
++];
2557 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
2558 OBJSTAT (objfile
, n_stabs
++);
2560 namestring
= set_namestring (objfile
, nlist
);
2562 processing_gcc_compilation
= 0;
2563 if (nlist
.n_type
== N_TEXT
)
2565 const char *tempstring
= namestring
;
2567 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
2568 processing_gcc_compilation
= 1;
2569 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
2570 processing_gcc_compilation
= 2;
2571 if (tempstring
[0] == bfd_get_symbol_leading_char (symfile_bfd
))
2573 if (STREQN (tempstring
, "__gnu_compiled", 14))
2574 processing_gcc_compilation
= 2;
2577 /* Try to select a C++ demangling based on the compilation unit
2581 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2582 know whether it will use the old style or v3 mangling. */
2583 if (processing_gcc_compilation
)
2585 if (AUTO_DEMANGLING
)
2587 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
2594 /* The N_SO starting this symtab is the first symbol, so we
2595 better not check the symbol before it. I'm not this can
2596 happen, but it doesn't hurt to check for it. */
2597 bfd_seek (symfile_bfd
, sym_offset
, SEEK_CUR
);
2598 processing_gcc_compilation
= 0;
2601 if (symbuf_idx
== symbuf_end
)
2603 bufp
= &symbuf
[symbuf_idx
];
2604 if (bfd_h_get_8 (abfd
, bufp
->e_type
) != N_SO
)
2605 error ("First symbol in segment of executable not a source symbol");
2607 max_symnum
= sym_size
/ symbol_size
;
2610 symnum
< max_symnum
;
2613 QUIT
; /* Allow this to be interruptable */
2614 if (symbuf_idx
== symbuf_end
)
2616 bufp
= &symbuf
[symbuf_idx
++];
2617 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
2618 OBJSTAT (objfile
, n_stabs
++);
2620 type
= bfd_h_get_8 (abfd
, bufp
->e_type
);
2622 namestring
= set_namestring (objfile
, nlist
);
2626 process_one_symbol (type
, nlist
.n_desc
, nlist
.n_value
,
2627 namestring
, section_offsets
, objfile
);
2629 /* We skip checking for a new .o or -l file; that should never
2630 happen in this routine. */
2631 else if (type
== N_TEXT
)
2633 /* I don't think this code will ever be executed, because
2634 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2635 the N_SO symbol which starts this source file.
2636 However, there is no reason not to accept
2637 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2639 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
2640 processing_gcc_compilation
= 1;
2641 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
2642 processing_gcc_compilation
= 2;
2645 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2646 know whether it will use the old style or v3 mangling. */
2647 if (AUTO_DEMANGLING
)
2649 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
2653 else if (type
& N_EXT
|| type
== (unsigned char) N_TEXT
2654 || type
== (unsigned char) N_NBTEXT
2657 /* Global symbol: see if we came across a dbx defintion for
2658 a corresponding symbol. If so, store the value. Remove
2659 syms from the chain when their values are stored, but
2660 search the whole chain, as there may be several syms from
2661 different files with the same name. */
2662 /* This is probably not true. Since the files will be read
2663 in one at a time, each reference to a global symbol will
2664 be satisfied in each file as it appears. So we skip this
2670 current_objfile
= NULL
;
2672 /* In a Solaris elf file, this variable, which comes from the
2673 value of the N_SO symbol, will still be 0. Luckily, text_offset,
2674 which comes from pst->textlow is correct. */
2675 if (last_source_start_addr
== 0)
2676 last_source_start_addr
= text_offset
;
2678 /* In reordered executables last_source_start_addr may not be the
2679 lower bound for this symtab, instead use text_offset which comes
2680 from pst->textlow which is correct. */
2681 if (last_source_start_addr
> text_offset
)
2682 last_source_start_addr
= text_offset
;
2684 pst
->symtab
= end_symtab (text_offset
+ text_size
, objfile
, SECT_OFF_TEXT (objfile
));
2686 /* Process items which we had to "process_later" due to dependencies
2688 process_now (objfile
);
2694 /* This handles a single symbol from the symbol-file, building symbols
2695 into a GDB symtab. It takes these arguments and an implicit argument.
2697 TYPE is the type field of the ".stab" symbol entry.
2698 DESC is the desc field of the ".stab" entry.
2699 VALU is the value field of the ".stab" entry.
2700 NAME is the symbol name, in our address space.
2701 SECTION_OFFSETS is a set of amounts by which the sections of this object
2702 file were relocated when it was loaded into memory.
2703 Note that these section_offsets are not the
2704 objfile->section_offsets but the pst->section_offsets.
2705 All symbols that refer
2706 to memory locations need to be offset by these amounts.
2707 OBJFILE is the object file from which we are reading symbols.
2708 It is used in end_symtab. */
2711 process_one_symbol (int type
, int desc
, CORE_ADDR valu
, char *name
,
2712 struct section_offsets
*section_offsets
,
2713 struct objfile
*objfile
)
2715 #ifdef SUN_FIXED_LBRAC_BUG
2716 /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
2717 to correct the address of N_LBRAC's. If it is not defined, then
2718 we never need to correct the addresses. */
2720 /* This records the last pc address we've seen. We depend on there being
2721 an SLINE or FUN or SO before the first LBRAC, since the variable does
2722 not get reset in between reads of different symbol files. */
2723 static CORE_ADDR last_pc_address
;
2726 register struct context_stack
*new;
2727 /* This remembers the address of the start of a function. It is used
2728 because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
2729 relative to the current function's start address. On systems
2730 other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
2731 used to relocate these symbol types rather than SECTION_OFFSETS. */
2732 static CORE_ADDR function_start_offset
;
2734 /* This holds the address of the start of a function, without the system
2735 peculiarities of function_start_offset. */
2736 static CORE_ADDR last_function_start
;
2738 /* If this is nonzero, we've seen an N_SLINE since the start of the current
2739 function. Initialized to nonzero to assure that last_function_start
2740 is never used uninitialized. */
2741 static int sline_found_in_function
= 1;
2743 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
2744 file. Used to detect the SunPRO solaris compiler. */
2745 static int n_opt_found
;
2747 /* The stab type used for the definition of the last function.
2748 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
2749 static int function_stab_type
= 0;
2751 if (!block_address_function_relative
)
2752 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
2753 function start address, so just use the text offset. */
2754 function_start_offset
= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2756 /* Something is wrong if we see real data before
2757 seeing a source file name. */
2759 if (last_source_file
== NULL
&& type
!= (unsigned char) N_SO
)
2761 /* Ignore any symbols which appear before an N_SO symbol.
2762 Currently no one puts symbols there, but we should deal
2763 gracefully with the case. A complain()t might be in order,
2764 but this should not be an error (). */
2773 if (*name
== '\000')
2775 /* This N_FUN marks the end of a function. This closes off the
2777 record_line (current_subfile
, 0, function_start_offset
+ valu
);
2778 within_function
= 0;
2779 new = pop_context ();
2781 /* Make a block for the local symbols within. */
2782 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2783 new->start_addr
, new->start_addr
+ valu
,
2786 /* May be switching to an assembler file which may not be using
2787 block relative stabs, so reset the offset. */
2788 if (block_address_function_relative
)
2789 function_start_offset
= 0;
2794 sline_found_in_function
= 0;
2796 /* Relocate for dynamic loading */
2797 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2798 valu
= SMASH_TEXT_ADDRESS (valu
);
2799 last_function_start
= valu
;
2801 goto define_a_symbol
;
2804 /* This "symbol" just indicates the start of an inner lexical
2805 context within a function. */
2807 /* Ignore extra outermost context from SunPRO cc and acc. */
2808 if (n_opt_found
&& desc
== 1)
2811 if (block_address_function_relative
)
2812 /* Relocate for Sun ELF acc fn-relative syms. */
2813 valu
+= function_start_offset
;
2815 /* On most machines, the block addresses are relative to the
2816 N_SO, the linker did not relocate them (sigh). */
2817 valu
+= last_source_start_addr
;
2819 #ifdef SUN_FIXED_LBRAC_BUG
2820 if (!SUN_FIXED_LBRAC_BUG
&& valu
< last_pc_address
)
2822 /* Patch current LBRAC pc value to match last handy pc value */
2823 complain (&lbrac_complaint
);
2824 valu
= last_pc_address
;
2827 new = push_context (desc
, valu
);
2831 /* This "symbol" just indicates the end of an inner lexical
2832 context that was started with N_LBRAC. */
2834 /* Ignore extra outermost context from SunPRO cc and acc. */
2835 if (n_opt_found
&& desc
== 1)
2838 if (block_address_function_relative
)
2839 /* Relocate for Sun ELF acc fn-relative syms. */
2840 valu
+= function_start_offset
;
2842 /* On most machines, the block addresses are relative to the
2843 N_SO, the linker did not relocate them (sigh). */
2844 valu
+= last_source_start_addr
;
2846 new = pop_context ();
2847 if (desc
!= new->depth
)
2848 complain (&lbrac_mismatch_complaint
, symnum
);
2850 /* Some compilers put the variable decls inside of an
2851 LBRAC/RBRAC block. This macro should be nonzero if this
2852 is true. DESC is N_DESC from the N_RBRAC symbol.
2853 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
2854 or the GCC2_COMPILED_SYMBOL. */
2855 #if !defined (VARIABLES_INSIDE_BLOCK)
2856 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2859 /* Can only use new->locals as local symbols here if we're in
2860 gcc or on a machine that puts them before the lbrack. */
2861 if (!VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2863 if (local_symbols
!= NULL
)
2865 /* GCC development snapshots from March to December of
2866 2000 would output N_LSYM entries after N_LBRAC
2867 entries. As a consequence, these symbols are simply
2868 discarded. Complain if this is the case. Note that
2869 there are some compilers which legitimately put local
2870 symbols within an LBRAC/RBRAC block; this complaint
2871 might also help sort out problems in which
2872 VARIABLES_INSIDE_BLOCK is incorrectly defined. */
2873 complain (&discarding_local_symbols_complaint
);
2875 local_symbols
= new->locals
;
2878 if (context_stack_depth
2879 > !VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2881 /* This is not the outermost LBRAC...RBRAC pair in the function,
2882 its local symbols preceded it, and are the ones just recovered
2883 from the context stack. Define the block for them (but don't
2884 bother if the block contains no symbols. Should we complain
2885 on blocks without symbols? I can't think of any useful purpose
2887 if (local_symbols
!= NULL
)
2889 /* Muzzle a compiler bug that makes end < start. (which
2890 compilers? Is this ever harmful?). */
2891 if (new->start_addr
> valu
)
2893 complain (&lbrac_rbrac_complaint
);
2894 new->start_addr
= valu
;
2896 /* Make a block for the local symbols within. */
2897 finish_block (0, &local_symbols
, new->old_blocks
,
2898 new->start_addr
, valu
, objfile
);
2903 /* This is the outermost LBRAC...RBRAC pair. There is no
2904 need to do anything; leave the symbols that preceded it
2905 to be attached to the function's own block. We need to
2906 indicate that we just moved outside of the function. */
2907 within_function
= 0;
2910 if (VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2911 /* Now pop locals of block just finished. */
2912 local_symbols
= new->locals
;
2917 /* This kind of symbol indicates the start of an object file. */
2918 /* Relocate for dynamic loading */
2919 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2923 /* This type of symbol indicates the start of data
2924 for one source file.
2925 Finish the symbol table of the previous source file
2926 (if any) and start accumulating a new symbol table. */
2927 /* Relocate for dynamic loading */
2928 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2932 #ifdef SUN_FIXED_LBRAC_BUG
2933 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2936 #ifdef PCC_SOL_BROKEN
2937 /* pcc bug, occasionally puts out SO for SOL. */
2938 if (context_stack_depth
> 0)
2940 start_subfile (name
, NULL
);
2944 if (last_source_file
)
2946 /* Check if previous symbol was also an N_SO (with some
2947 sanity checks). If so, that one was actually the directory
2948 name, and the current one is the real file name.
2950 if (previous_stab_code
== (unsigned char) N_SO
)
2952 patch_subfile_names (current_subfile
, name
);
2953 break; /* Ignore repeated SOs */
2955 end_symtab (valu
, objfile
, SECT_OFF_TEXT (objfile
));
2959 /* Null name means this just marks the end of text for this .o file.
2960 Don't start a new symtab in this case. */
2961 if (*name
== '\000')
2964 if (block_address_function_relative
)
2965 function_start_offset
= 0;
2968 start_symtab (name
, NULL
, valu
);
2969 record_debugformat ("stabs");
2973 /* This type of symbol indicates the start of data for
2974 a sub-source-file, one whose contents were copied or
2975 included in the compilation of the main source file
2976 (whose name was given in the N_SO symbol.) */
2977 /* Relocate for dynamic loading */
2978 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2979 start_subfile (name
, current_subfile
->dirname
);
2984 add_new_header_file (name
, valu
);
2985 start_subfile (name
, current_subfile
->dirname
);
2989 start_subfile (pop_subfile (), current_subfile
->dirname
);
2993 add_old_header_file (name
, valu
);
2997 /* This type of "symbol" really just records
2998 one line-number -- core-address correspondence.
2999 Enter it in the line list for this symbol table. */
3001 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
3002 valu
+= function_start_offset
;
3004 #ifdef SUN_FIXED_LBRAC_BUG
3005 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3007 /* If this is the first SLINE note in the function, record it at
3008 the start of the function instead of at the listed location. */
3009 if (within_function
&& sline_found_in_function
== 0)
3011 record_line (current_subfile
, desc
, last_function_start
);
3012 sline_found_in_function
= 1;
3015 record_line (current_subfile
, desc
, valu
);
3019 common_block_start (name
, objfile
);
3023 common_block_end (objfile
);
3026 /* The following symbol types need to have the appropriate offset added
3027 to their value; then we process symbol definitions in the name. */
3029 case N_STSYM
: /* Static symbol in data seg */
3030 case N_LCSYM
: /* Static symbol in BSS seg */
3031 case N_ROSYM
: /* Static symbol in Read-only data seg */
3032 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
3033 Solaris2's stabs-in-elf makes *most* symbols relative
3034 but leaves a few absolute (at least for Solaris 2.1 and version
3035 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence.
3036 .stab "foo:S...",N_STSYM is absolute (ld relocates it)
3037 .stab "foo:V...",N_STSYM is relative (section base subtracted).
3038 This leaves us no choice but to search for the 'S' or 'V'...
3039 (or pass the whole section_offsets stuff down ONE MORE function
3040 call level, which we really don't want to do). */
3044 /* .o files and NLMs have non-zero text seg offsets, but don't need
3045 their static syms offset in this fashion. XXX - This is really a
3046 crock that should be fixed in the solib handling code so that I
3047 don't have to work around it here. */
3049 if (!symfile_relocatable
)
3051 p
= strchr (name
, ':');
3052 if (p
!= 0 && p
[1] == 'S')
3054 /* The linker relocated it. We don't want to add an
3055 elfstab_offset_sections-type offset, but we *do* want
3056 to add whatever solib.c passed to symbol_file_add as
3057 addr (this is known to affect SunOS4, and I suspect ELF
3058 too). Since elfstab_offset_sections currently does not
3059 muck with the text offset (there is no Ttext.text
3060 symbol), we can get addr from the text offset. If
3061 elfstab_offset_sections ever starts dealing with the
3062 text offset, and we still need to do this, we need to
3063 invent a SECT_OFF_ADDR_KLUDGE or something. */
3064 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
3065 goto define_a_symbol
;
3068 /* Since it's not the kludge case, re-dispatch to the right handler. */
3078 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
3082 case_N_STSYM
: /* Static symbol in data seg */
3083 case N_DSLINE
: /* Source line number, data seg */
3084 valu
+= ANOFFSET (section_offsets
, SECT_OFF_DATA (objfile
));
3085 goto define_a_symbol
;
3087 case_N_LCSYM
: /* Static symbol in BSS seg */
3088 case N_BSLINE
: /* Source line number, bss seg */
3089 /* N_BROWS: overlaps with N_BSLINE */
3090 valu
+= ANOFFSET (section_offsets
, SECT_OFF_BSS (objfile
));
3091 goto define_a_symbol
;
3093 case_N_ROSYM
: /* Static symbol in Read-only data seg */
3094 valu
+= ANOFFSET (section_offsets
, SECT_OFF_RODATA (objfile
));
3095 goto define_a_symbol
;
3097 case N_ENTRY
: /* Alternate entry point */
3098 /* Relocate for dynamic loading */
3099 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
3100 goto define_a_symbol
;
3102 /* The following symbol types we don't know how to process. Handle
3103 them in a "default" way, but complain to people who care. */
3105 case N_CATCH
: /* Exception handler catcher */
3106 case N_EHDECL
: /* Exception handler name */
3107 case N_PC
: /* Global symbol in Pascal */
3108 case N_M2C
: /* Modula-2 compilation unit */
3109 /* N_MOD2: overlaps with N_EHDECL */
3110 case N_SCOPE
: /* Modula-2 scope information */
3111 case N_ECOML
: /* End common (local name) */
3112 case N_NBTEXT
: /* Gould Non-Base-Register symbols??? */
3117 complain (&unknown_symtype_complaint
, local_hex_string (type
));
3120 /* The following symbol types don't need the address field relocated,
3121 since it is either unused, or is absolute. */
3123 case N_GSYM
: /* Global variable */
3124 case N_NSYMS
: /* Number of symbols (ultrix) */
3125 case N_NOMAP
: /* No map? (ultrix) */
3126 case N_RSYM
: /* Register variable */
3127 case N_DEFD
: /* Modula-2 GNU module dependency */
3128 case N_SSYM
: /* Struct or union element */
3129 case N_LSYM
: /* Local symbol in stack */
3130 case N_PSYM
: /* Parameter variable */
3131 case N_LENG
: /* Length of preceding symbol type */
3135 char *colon_pos
= strchr (name
, ':');
3136 if (colon_pos
== NULL
)
3139 deftype
= colon_pos
[1];
3145 function_stab_type
= type
;
3147 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
3148 /* Deal with the SunPRO 3.0 compiler which omits the address
3149 from N_FUN symbols. */
3151 && valu
== ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
)))
3153 CORE_ADDR minsym_valu
=
3154 find_stab_function_addr (name
, last_source_file
, objfile
);
3156 /* find_stab_function_addr will return 0 if the minimal
3157 symbol wasn't found. (Unfortunately, this might also
3158 be a valid address.) Anyway, if it *does* return 0,
3159 it is likely that the value was set correctly to begin
3161 if (minsym_valu
!= 0)
3166 #ifdef SUN_FIXED_LBRAC_BUG
3167 /* The Sun acc compiler, under SunOS4, puts out
3168 functions with N_GSYM or N_STSYM. The problem is
3169 that the address of the symbol is no good (for N_GSYM
3170 it doesn't even attept an address; for N_STSYM it
3171 puts out an address but then it gets relocated
3172 relative to the data segment, not the text segment).
3173 Currently we can't fix this up later as we do for
3174 some types of symbol in scan_file_globals.
3175 Fortunately we do have a way of finding the address -
3176 we know that the value in last_pc_address is either
3177 the one we want (if we're dealing with the first
3178 function in an object file), or somewhere in the
3179 previous function. This means that we can use the
3180 minimal symbol table to get the address. */
3182 /* Starting with release 3.0, the Sun acc compiler,
3183 under SunOS4, puts out functions with N_FUN and a value
3184 of zero. This gets relocated to the start of the text
3185 segment of the module, which is no good either.
3186 Under SunOS4 we can deal with this as N_SLINE and N_SO
3187 entries contain valid absolute addresses.
3188 Release 3.0 acc also puts out N_OPT entries, which makes
3189 it possible to discern acc from cc or gcc. */
3191 if (type
== N_GSYM
|| type
== N_STSYM
3193 && n_opt_found
&& !block_address_function_relative
))
3195 struct minimal_symbol
*m
;
3196 int l
= colon_pos
- name
;
3198 m
= lookup_minimal_symbol_by_pc (last_pc_address
);
3199 if (m
&& STREQN (SYMBOL_NAME (m
), name
, l
)
3200 && SYMBOL_NAME (m
)[l
] == '\0')
3201 /* last_pc_address was in this function */
3202 valu
= SYMBOL_VALUE (m
);
3203 else if (m
&& SYMBOL_NAME (m
+ 1)
3204 && STREQN (SYMBOL_NAME (m
+ 1), name
, l
)
3205 && SYMBOL_NAME (m
+ 1)[l
] == '\0')
3206 /* last_pc_address was in last function */
3207 valu
= SYMBOL_VALUE (m
+ 1);
3209 /* Not found - use last_pc_address (for finish_block) */
3210 valu
= last_pc_address
;
3213 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3216 if (block_address_function_relative
)
3217 /* For Solaris 2.0 compilers, the block addresses and
3218 N_SLINE's are relative to the start of the
3219 function. On normal systems, and when using gcc on
3220 Solaris 2.0, these addresses are just absolute, or
3221 relative to the N_SO, depending on
3222 BLOCK_ADDRESS_ABSOLUTE. */
3223 function_start_offset
= valu
;
3225 within_function
= 1;
3227 if (context_stack_depth
> 1)
3229 complain (&lbrac_unmatched_complaint
, symnum
);
3233 if (context_stack_depth
> 0)
3235 new = pop_context ();
3236 /* Make a block for the local symbols within. */
3237 finish_block (new->name
, &local_symbols
, new->old_blocks
,
3238 new->start_addr
, valu
, objfile
);
3241 new = push_context (0, valu
);
3242 new->name
= define_symbol (valu
, name
, desc
, type
, objfile
);
3246 define_symbol (valu
, name
, desc
, type
, objfile
);
3252 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
3253 for a bunch of other flags, too. Someday we may parse their
3254 flags; for now we ignore theirs and hope they'll ignore ours. */
3255 case N_OPT
: /* Solaris 2: Compiler options */
3258 if (STREQ (name
, GCC2_COMPILED_FLAG_SYMBOL
))
3260 processing_gcc_compilation
= 2;
3261 #if 0 /* Works, but is experimental. -fnf */
3262 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
3263 know whether it will use the old style or v3 mangling. */
3264 if (AUTO_DEMANGLING
)
3266 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
3275 case N_MAIN
: /* Name of main routine. */
3276 /* FIXME: If one has a symbol file with N_MAIN and then replaces
3277 it with a symbol file with "main" and without N_MAIN. I'm
3278 not sure exactly what rule to follow but probably something
3279 like: N_MAIN takes precedence over "main" no matter what
3280 objfile it is in; If there is more than one N_MAIN, choose
3281 the one in the symfile_objfile; If there is more than one
3282 N_MAIN within a given objfile, complain() and choose
3283 arbitrarily. (kingdon) */
3285 set_main_name (name
);
3288 /* The following symbol types can be ignored. */
3289 case N_OBJ
: /* Solaris 2: Object file dir and name */
3290 /* N_UNDF: Solaris 2: file separator mark */
3291 /* N_UNDF: -- we will never encounter it, since we only process one
3292 file's symbols at once. */
3293 case N_ENDM
: /* Solaris 2: End of module */
3294 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
3298 /* '#' is a GNU C extension to allow one symbol to refer to another
3301 Generally this is used so that an alias can refer to its main
3305 /* Initialize symbol reference names and determine if this is
3306 a definition. If symbol reference is being defined, go
3307 ahead and add it. Otherwise, just return sym. */
3312 /* If this stab defines a new reference ID that is not on the
3313 reference list, then put it on the reference list.
3315 We go ahead and advance NAME past the reference, even though
3316 it is not strictly necessary at this time. */
3317 refnum
= symbol_reference_defined (&s
);
3319 if (!ref_search (refnum
))
3320 ref_add (refnum
, 0, name
, valu
);
3325 previous_stab_code
= type
;
3328 /* FIXME: The only difference between this and elfstab_build_psymtabs
3329 is the call to install_minimal_symbols for elf, and the support for
3330 split sections. If the differences are really that small, the code
3331 should be shared. */
3333 /* Scan and build partial symbols for an coff symbol file.
3334 The coff file has already been processed to get its minimal symbols.
3336 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3339 OBJFILE is the object file we are reading symbols from.
3340 ADDR is the address relative to which the symbols are (e.g.
3341 the base address of the text segment).
3342 MAINLINE is true if we are reading the main symbol
3343 table (as opposed to a shared lib or dynamically loaded file).
3344 TEXTADDR is the address of the text section.
3345 TEXTSIZE is the size of the text section.
3346 STABSECTS is the list of .stab sections in OBJFILE.
3347 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3348 .stabstr section exists.
3350 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3351 adjusted for coff details. */
3354 coffstab_build_psymtabs (struct objfile
*objfile
, int mainline
,
3355 CORE_ADDR textaddr
, unsigned int textsize
,
3356 struct stab_section_list
*stabsects
,
3357 file_ptr stabstroffset
, unsigned int stabstrsize
)
3360 bfd
*sym_bfd
= objfile
->obfd
;
3361 char *name
= bfd_get_filename (sym_bfd
);
3362 struct dbx_symfile_info
*info
;
3363 unsigned int stabsize
;
3365 /* There is already a dbx_symfile_info allocated by our caller.
3366 It might even contain some info from the coff symtab to help us. */
3367 info
= objfile
->sym_stab_info
;
3369 DBX_TEXT_ADDR (objfile
) = textaddr
;
3370 DBX_TEXT_SIZE (objfile
) = textsize
;
3372 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3373 DBX_SYMBOL_SIZE (objfile
) = COFF_STABS_SYMBOL_SIZE
;
3374 DBX_STRINGTAB_SIZE (objfile
) = stabstrsize
;
3376 if (stabstrsize
> bfd_get_size (sym_bfd
))
3377 error ("ridiculous string table size: %d bytes", stabstrsize
);
3378 DBX_STRINGTAB (objfile
) = (char *)
3379 obstack_alloc (&objfile
->psymbol_obstack
, stabstrsize
+ 1);
3380 OBJSTAT (objfile
, sz_strtab
+= stabstrsize
+ 1);
3382 /* Now read in the string table in one big gulp. */
3384 val
= bfd_seek (sym_bfd
, stabstroffset
, SEEK_SET
);
3386 perror_with_name (name
);
3387 val
= bfd_bread (DBX_STRINGTAB (objfile
), stabstrsize
, sym_bfd
);
3388 if (val
!= stabstrsize
)
3389 perror_with_name (name
);
3391 stabsread_new_init ();
3392 buildsym_new_init ();
3393 free_header_files ();
3394 init_header_files ();
3396 processing_acc_compilation
= 1;
3398 /* In a coff file, we've already installed the minimal symbols that came
3399 from the coff (non-stab) symbol table, so always act like an
3400 incremental load here. */
3401 if (stabsects
->next
== NULL
)
3403 stabsize
= bfd_section_size (sym_bfd
, stabsects
->section
);
3404 DBX_SYMCOUNT (objfile
) = stabsize
/ DBX_SYMBOL_SIZE (objfile
);
3405 DBX_SYMTAB_OFFSET (objfile
) = stabsects
->section
->filepos
;
3409 struct stab_section_list
*stabsect
;
3411 DBX_SYMCOUNT (objfile
) = 0;
3412 for (stabsect
= stabsects
; stabsect
!= NULL
; stabsect
= stabsect
->next
)
3414 stabsize
= bfd_section_size (sym_bfd
, stabsect
->section
);
3415 DBX_SYMCOUNT (objfile
) += stabsize
/ DBX_SYMBOL_SIZE (objfile
);
3418 DBX_SYMTAB_OFFSET (objfile
) = stabsects
->section
->filepos
;
3420 symbuf_sections
= stabsects
->next
;
3421 symbuf_left
= bfd_section_size (sym_bfd
, stabsects
->section
);
3425 dbx_symfile_read (objfile
, 0);
3428 /* Scan and build partial symbols for an ELF symbol file.
3429 This ELF file has already been processed to get its minimal symbols,
3430 and any DWARF symbols that were in it.
3432 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3435 OBJFILE is the object file we are reading symbols from.
3436 ADDR is the address relative to which the symbols are (e.g.
3437 the base address of the text segment).
3438 MAINLINE is true if we are reading the main symbol
3439 table (as opposed to a shared lib or dynamically loaded file).
3440 STABOFFSET and STABSIZE define the location in OBJFILE where the .stab
3442 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3443 .stabstr section exists.
3445 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3446 adjusted for elf details. */
3449 elfstab_build_psymtabs (struct objfile
*objfile
, int mainline
,
3450 file_ptr staboffset
, unsigned int stabsize
,
3451 file_ptr stabstroffset
, unsigned int stabstrsize
)
3454 bfd
*sym_bfd
= objfile
->obfd
;
3455 char *name
= bfd_get_filename (sym_bfd
);
3456 struct dbx_symfile_info
*info
;
3458 /* There is already a dbx_symfile_info allocated by our caller.
3459 It might even contain some info from the ELF symtab to help us. */
3460 info
= objfile
->sym_stab_info
;
3462 /* Find the first and last text address. dbx_symfile_read seems to
3464 find_text_range (sym_bfd
, objfile
);
3466 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3467 DBX_SYMBOL_SIZE (objfile
) = ELF_STABS_SYMBOL_SIZE
;
3468 DBX_SYMCOUNT (objfile
) = stabsize
/ DBX_SYMBOL_SIZE (objfile
);
3469 DBX_STRINGTAB_SIZE (objfile
) = stabstrsize
;
3470 DBX_SYMTAB_OFFSET (objfile
) = staboffset
;
3472 if (stabstrsize
> bfd_get_size (sym_bfd
))
3473 error ("ridiculous string table size: %d bytes", stabstrsize
);
3474 DBX_STRINGTAB (objfile
) = (char *)
3475 obstack_alloc (&objfile
->psymbol_obstack
, stabstrsize
+ 1);
3476 OBJSTAT (objfile
, sz_strtab
+= stabstrsize
+ 1);
3478 /* Now read in the string table in one big gulp. */
3480 val
= bfd_seek (sym_bfd
, stabstroffset
, SEEK_SET
);
3482 perror_with_name (name
);
3483 val
= bfd_bread (DBX_STRINGTAB (objfile
), stabstrsize
, sym_bfd
);
3484 if (val
!= stabstrsize
)
3485 perror_with_name (name
);
3487 stabsread_new_init ();
3488 buildsym_new_init ();
3489 free_header_files ();
3490 init_header_files ();
3491 install_minimal_symbols (objfile
);
3493 processing_acc_compilation
= 1;
3495 /* In an elf file, we've already installed the minimal symbols that came
3496 from the elf (non-stab) symbol table, so always act like an
3497 incremental load here. */
3498 dbx_symfile_read (objfile
, 0);
3501 /* Scan and build partial symbols for a file with special sections for stabs
3502 and stabstrings. The file has already been processed to get its minimal
3503 symbols, and any other symbols that might be necessary to resolve GSYMs.
3505 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3508 OBJFILE is the object file we are reading symbols from.
3509 ADDR is the address relative to which the symbols are (e.g. the base address
3510 of the text segment).
3511 MAINLINE is true if we are reading the main symbol table (as opposed to a
3512 shared lib or dynamically loaded file).
3513 STAB_NAME is the name of the section that contains the stabs.
3514 STABSTR_NAME is the name of the section that contains the stab strings.
3516 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */
3519 stabsect_build_psymtabs (struct objfile
*objfile
, int mainline
, char *stab_name
,
3520 char *stabstr_name
, char *text_name
)
3523 bfd
*sym_bfd
= objfile
->obfd
;
3524 char *name
= bfd_get_filename (sym_bfd
);
3526 asection
*stabstrsect
;
3527 asection
*text_sect
;
3529 stabsect
= bfd_get_section_by_name (sym_bfd
, stab_name
);
3530 stabstrsect
= bfd_get_section_by_name (sym_bfd
, stabstr_name
);
3536 error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)",
3537 stab_name
, stabstr_name
);
3539 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
3540 xmalloc (sizeof (struct dbx_symfile_info
));
3541 memset (objfile
->sym_stab_info
, 0, sizeof (struct dbx_symfile_info
));
3543 text_sect
= bfd_get_section_by_name (sym_bfd
, text_name
);
3545 error ("Can't find %s section in symbol file", text_name
);
3546 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
3547 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
3549 DBX_SYMBOL_SIZE (objfile
) = sizeof (struct external_nlist
);
3550 DBX_SYMCOUNT (objfile
) = bfd_section_size (sym_bfd
, stabsect
)
3551 / DBX_SYMBOL_SIZE (objfile
);
3552 DBX_STRINGTAB_SIZE (objfile
) = bfd_section_size (sym_bfd
, stabstrsect
);
3553 DBX_SYMTAB_OFFSET (objfile
) = stabsect
->filepos
; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */
3555 if (DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
3556 error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile
));
3557 DBX_STRINGTAB (objfile
) = (char *)
3558 obstack_alloc (&objfile
->psymbol_obstack
, DBX_STRINGTAB_SIZE (objfile
) + 1);
3559 OBJSTAT (objfile
, sz_strtab
+= DBX_STRINGTAB_SIZE (objfile
) + 1);
3561 /* Now read in the string table in one big gulp. */
3563 val
= bfd_get_section_contents (sym_bfd
, /* bfd */
3564 stabstrsect
, /* bfd section */
3565 DBX_STRINGTAB (objfile
), /* input buffer */
3566 0, /* offset into section */
3567 DBX_STRINGTAB_SIZE (objfile
)); /* amount to read */
3570 perror_with_name (name
);
3572 stabsread_new_init ();
3573 buildsym_new_init ();
3574 free_header_files ();
3575 init_header_files ();
3576 install_minimal_symbols (objfile
);
3578 /* Now, do an incremental load */
3580 processing_acc_compilation
= 1;
3581 dbx_symfile_read (objfile
, 0);
3584 static struct sym_fns aout_sym_fns
=
3586 bfd_target_aout_flavour
,
3587 dbx_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3588 dbx_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3589 dbx_symfile_read
, /* sym_read: read a symbol file into symtab */
3590 dbx_symfile_finish
, /* sym_finish: finished with file, cleanup */
3591 default_symfile_offsets
, /* sym_offsets: parse user's offsets to internal form */
3592 NULL
/* next: pointer to next struct sym_fns */
3596 _initialize_dbxread (void)
3598 add_symtab_fns (&aout_sym_fns
);