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, 2003.
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. */
171 unknown_symtype_complaint (const char *arg1
)
173 complaint (&symfile_complaints
, "unknown symbol type %s", arg1
);
177 lbrac_mismatch_complaint (int arg1
)
179 complaint (&symfile_complaints
,
180 "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1
);
184 repeated_header_complaint (const char *arg1
, int arg2
)
186 complaint (&symfile_complaints
,
187 "\"repeated\" header file %s not previously seen, at symtab pos %d",
191 /* find_text_range --- find start and end of loadable code sections
193 The find_text_range function finds the shortest address range that
194 encloses all sections containing executable code, and stores it in
195 objfile's text_addr and text_size members.
197 dbx_symfile_read will use this to finish off the partial symbol
198 table, in some cases. */
201 find_text_range (bfd
* sym_bfd
, struct objfile
*objfile
)
208 for (sec
= sym_bfd
->sections
; sec
; sec
= sec
->next
)
209 if (bfd_get_section_flags (sym_bfd
, sec
) & SEC_CODE
)
211 CORE_ADDR sec_start
= bfd_section_vma (sym_bfd
, sec
);
212 CORE_ADDR sec_end
= sec_start
+ bfd_section_size (sym_bfd
, sec
);
216 if (sec_start
< start
)
231 error ("Can't find any code sections in symbol file");
233 DBX_TEXT_ADDR (objfile
) = start
;
234 DBX_TEXT_SIZE (objfile
) = end
- start
;
239 /* During initial symbol readin, we need to have a structure to keep
240 track of which psymtabs have which bincls in them. This structure
241 is used during readin to setup the list of dependencies within each
242 partial symbol table. */
244 struct header_file_location
246 char *name
; /* Name of header file */
247 int instance
; /* See above */
248 struct partial_symtab
*pst
; /* Partial symtab that has the
249 BINCL/EINCL defs for this file */
252 /* The actual list and controling variables */
253 static struct header_file_location
*bincl_list
, *next_bincl
;
254 static int bincls_allocated
;
256 /* Local function prototypes */
258 extern void _initialize_dbxread (void);
260 #if 0 /* OBSOLETE CFront */
261 // OBSOLETE static void process_now (struct objfile *);
262 #endif /* OBSOLETE CFront */
264 static void read_ofile_symtab (struct partial_symtab
*);
266 static void dbx_psymtab_to_symtab (struct partial_symtab
*);
268 static void dbx_psymtab_to_symtab_1 (struct partial_symtab
*);
270 static void read_dbx_dynamic_symtab (struct objfile
*objfile
);
272 static void read_dbx_symtab (struct objfile
*);
274 static void free_bincl_list (struct objfile
*);
276 static struct partial_symtab
*find_corresponding_bincl_psymtab (char *, int);
278 static void add_bincl_to_list (struct partial_symtab
*, char *, int);
280 static void init_bincl_list (int, struct objfile
*);
282 static char *dbx_next_symbol_text (struct objfile
*);
284 static void fill_symbuf (bfd
*);
286 static void dbx_symfile_init (struct objfile
*);
288 static void dbx_new_init (struct objfile
*);
290 static void dbx_symfile_read (struct objfile
*, int);
292 static void dbx_symfile_finish (struct objfile
*);
294 static void record_minimal_symbol (char *, CORE_ADDR
, int, struct objfile
*);
296 static void add_new_header_file (char *, int);
298 static void add_old_header_file (char *, int);
300 static void add_this_object_header_file (int);
302 static struct partial_symtab
*start_psymtab (struct objfile
*, char *,
304 struct partial_symbol
**,
305 struct partial_symbol
**);
307 /* Free up old header file tables */
310 free_header_files (void)
312 if (this_object_header_files
)
314 xfree (this_object_header_files
);
315 this_object_header_files
= NULL
;
317 n_allocated_this_object_header_files
= 0;
320 /* Allocate new header file tables */
323 init_header_files (void)
325 n_allocated_this_object_header_files
= 10;
326 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
329 /* Add header file number I for this object file
330 at the next successive FILENUM. */
333 add_this_object_header_file (int i
)
335 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
337 n_allocated_this_object_header_files
*= 2;
338 this_object_header_files
339 = (int *) xrealloc ((char *) this_object_header_files
,
340 n_allocated_this_object_header_files
* sizeof (int));
343 this_object_header_files
[n_this_object_header_files
++] = i
;
346 /* Add to this file an "old" header file, one already seen in
347 a previous object file. NAME is the header file's name.
348 INSTANCE is its instance code, to select among multiple
349 symbol tables for the same header file. */
352 add_old_header_file (char *name
, int instance
)
354 register struct header_file
*p
= HEADER_FILES (current_objfile
);
357 for (i
= 0; i
< N_HEADER_FILES (current_objfile
); i
++)
358 if (STREQ (p
[i
].name
, name
) && instance
== p
[i
].instance
)
360 add_this_object_header_file (i
);
363 repeated_header_complaint (name
, symnum
);
366 /* Add to this file a "new" header file: definitions for its types follow.
367 NAME is the header file's name.
368 Most often this happens only once for each distinct header file,
369 but not necessarily. If it happens more than once, INSTANCE has
370 a different value each time, and references to the header file
371 use INSTANCE values to select among them.
373 dbx output contains "begin" and "end" markers for each new header file,
374 but at this level we just need to know which files there have been;
375 so we record the file when its "begin" is seen and ignore the "end". */
378 add_new_header_file (char *name
, int instance
)
381 register struct header_file
*hfile
;
383 /* Make sure there is room for one more header file. */
385 i
= N_ALLOCATED_HEADER_FILES (current_objfile
);
387 if (N_HEADER_FILES (current_objfile
) == i
)
391 N_ALLOCATED_HEADER_FILES (current_objfile
) = 10;
392 HEADER_FILES (current_objfile
) = (struct header_file
*)
393 xmalloc (10 * sizeof (struct header_file
));
398 N_ALLOCATED_HEADER_FILES (current_objfile
) = i
;
399 HEADER_FILES (current_objfile
) = (struct header_file
*)
400 xrealloc ((char *) HEADER_FILES (current_objfile
),
401 (i
* sizeof (struct header_file
)));
405 /* Create an entry for this header file. */
407 i
= N_HEADER_FILES (current_objfile
)++;
408 hfile
= HEADER_FILES (current_objfile
) + i
;
409 hfile
->name
= savestring (name
, strlen (name
));
410 hfile
->instance
= instance
;
413 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
414 memset (hfile
->vector
, 0, 10 * sizeof (struct type
*));
416 add_this_object_header_file (i
);
420 static struct type
**
421 explicit_lookup_type (int real_filenum
, int index
)
423 register struct header_file
*f
= &HEADER_FILES (current_objfile
)[real_filenum
];
425 if (index
>= f
->length
)
428 f
->vector
= (struct type
**)
429 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
430 memset (&f
->vector
[f
->length
/ 2],
431 '\0', f
->length
* sizeof (struct type
*) / 2);
433 return &f
->vector
[index
];
438 record_minimal_symbol (char *name
, CORE_ADDR address
, int type
,
439 struct objfile
*objfile
)
441 enum minimal_symbol_type ms_type
;
443 asection
*bfd_section
;
449 section
= SECT_OFF_TEXT (objfile
);
450 bfd_section
= DBX_TEXT_SECTION (objfile
);
454 section
= SECT_OFF_DATA (objfile
);
455 bfd_section
= DBX_DATA_SECTION (objfile
);
459 section
= SECT_OFF_BSS (objfile
);
460 bfd_section
= DBX_BSS_SECTION (objfile
);
470 section
= SECT_OFF_DATA (objfile
);
471 bfd_section
= DBX_DATA_SECTION (objfile
);
474 /* I don't think this type actually exists; since a N_SETV is the result
475 of going over many .o files, it doesn't make sense to have one
477 ms_type
= mst_file_data
;
478 section
= SECT_OFF_DATA (objfile
);
479 bfd_section
= DBX_DATA_SECTION (objfile
);
486 ms_type
= mst_file_text
;
487 section
= SECT_OFF_TEXT (objfile
);
488 bfd_section
= DBX_TEXT_SECTION (objfile
);
491 ms_type
= mst_file_data
;
493 /* Check for __DYNAMIC, which is used by Sun shared libraries.
494 Record it as global even if it's local, not global, so
495 lookup_minimal_symbol can find it. We don't check symbol_leading_char
496 because for SunOS4 it always is '_'. */
497 if (name
[8] == 'C' && STREQ ("__DYNAMIC", name
))
500 /* Same with virtual function tables, both global and static. */
502 char *tempstring
= name
;
503 if (tempstring
[0] == bfd_get_symbol_leading_char (objfile
->obfd
))
505 if (is_vtable_name (tempstring
))
508 section
= SECT_OFF_DATA (objfile
);
509 bfd_section
= DBX_DATA_SECTION (objfile
);
512 ms_type
= mst_file_bss
;
513 section
= SECT_OFF_BSS (objfile
);
514 bfd_section
= DBX_BSS_SECTION (objfile
);
517 ms_type
= mst_unknown
;
523 if ((ms_type
== mst_file_text
|| ms_type
== mst_text
)
524 && address
< lowest_text_address
)
525 lowest_text_address
= address
;
527 prim_record_minimal_symbol_and_info
528 (name
, address
, ms_type
, NULL
, section
, bfd_section
, objfile
);
531 /* Scan and build partial symbols for a symbol file.
532 We have been initialized by a call to dbx_symfile_init, which
533 put all the relevant info into a "struct dbx_symfile_info",
534 hung off the objfile structure.
536 MAINLINE is true if we are reading the main symbol
537 table (as opposed to a shared lib or dynamically loaded file). */
540 dbx_symfile_read (struct objfile
*objfile
, int mainline
)
544 struct cleanup
*back_to
;
546 sym_bfd
= objfile
->obfd
;
548 /* .o and .nlm files are relocatables with text, data and bss segs based at
549 0. This flag disables special (Solaris stabs-in-elf only) fixups for
550 symbols with a value of 0. */
552 symfile_relocatable
= bfd_get_file_flags (sym_bfd
) & HAS_RELOC
;
554 /* This is true for Solaris (and all other systems which put stabs
555 in sections, hopefully, since it would be silly to do things
556 differently from Solaris), and false for SunOS4 and other a.out
558 block_address_function_relative
=
559 ((0 == strncmp (bfd_get_target (sym_bfd
), "elf", 3))
560 || (0 == strncmp (bfd_get_target (sym_bfd
), "som", 3))
561 || (0 == strncmp (bfd_get_target (sym_bfd
), "coff", 4))
562 || (0 == strncmp (bfd_get_target (sym_bfd
), "pe", 2))
563 || (0 == strncmp (bfd_get_target (sym_bfd
), "epoc-pe", 7))
564 || (0 == strncmp (bfd_get_target (sym_bfd
), "nlm", 3)));
566 val
= bfd_seek (sym_bfd
, DBX_SYMTAB_OFFSET (objfile
), SEEK_SET
);
568 perror_with_name (objfile
->name
);
570 /* If we are reinitializing, or if we have never loaded syms yet, init */
572 || (objfile
->global_psymbols
.size
== 0
573 && objfile
->static_psymbols
.size
== 0))
574 init_psymbol_list (objfile
, DBX_SYMCOUNT (objfile
));
576 symbol_size
= DBX_SYMBOL_SIZE (objfile
);
577 symbol_table_offset
= DBX_SYMTAB_OFFSET (objfile
);
579 free_pending_blocks ();
580 back_to
= make_cleanup (really_free_pendings
, 0);
582 init_minimal_symbol_collection ();
583 make_cleanup_discard_minimal_symbols ();
585 /* Read stabs data from executable file and define symbols. */
587 read_dbx_symtab (objfile
);
589 /* Add the dynamic symbols. */
591 read_dbx_dynamic_symtab (objfile
);
593 /* Install any minimal symbols that have been collected as the current
594 minimal symbols for this objfile. */
596 install_minimal_symbols (objfile
);
598 do_cleanups (back_to
);
601 /* Initialize anything that needs initializing when a completely new
602 symbol file is specified (not just adding some symbols from another
603 file, e.g. a shared library). */
606 dbx_new_init (struct objfile
*ignore
)
608 stabsread_new_init ();
609 buildsym_new_init ();
610 init_header_files ();
614 /* dbx_symfile_init ()
615 is the dbx-specific initialization routine for reading symbols.
616 It is passed a struct objfile which contains, among other things,
617 the BFD for the file whose symbols are being read, and a slot for a pointer
618 to "private data" which we fill with goodies.
620 We read the string table into malloc'd space and stash a pointer to it.
622 Since BFD doesn't know how to read debug symbols in a format-independent
623 way (and may never do so...), we have to do it ourselves. We will never
624 be called unless this is an a.out (or very similar) file.
625 FIXME, there should be a cleaner peephole into the BFD environment here. */
627 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
630 dbx_symfile_init (struct objfile
*objfile
)
633 bfd
*sym_bfd
= objfile
->obfd
;
634 char *name
= bfd_get_filename (sym_bfd
);
636 unsigned char size_temp
[DBX_STRINGTAB_SIZE_SIZE
];
638 /* Allocate struct to keep track of the symfile */
639 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
640 xmmalloc (objfile
->md
, sizeof (struct dbx_symfile_info
));
641 memset (objfile
->sym_stab_info
, 0, sizeof (struct dbx_symfile_info
));
643 DBX_TEXT_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".text");
644 DBX_DATA_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".data");
645 DBX_BSS_SECTION (objfile
) = bfd_get_section_by_name (sym_bfd
, ".bss");
647 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
648 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
649 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
651 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
653 DBX_SYMFILE_INFO (objfile
)->stab_section_info
= NULL
;
655 text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
657 error ("Can't find .text section in symbol file");
658 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
659 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
661 DBX_SYMBOL_SIZE (objfile
) = obj_symbol_entry_size (sym_bfd
);
662 DBX_SYMCOUNT (objfile
) = bfd_get_symcount (sym_bfd
);
663 DBX_SYMTAB_OFFSET (objfile
) = SYMBOL_TABLE_OFFSET
;
665 /* Read the string table and stash it away in the psymbol_obstack. It is
666 only needed as long as we need to expand psymbols into full symbols,
667 so when we blow away the psymbol the string table goes away as well.
668 Note that gdb used to use the results of attempting to malloc the
669 string table, based on the size it read, as a form of sanity check
670 for botched byte swapping, on the theory that a byte swapped string
671 table size would be so totally bogus that the malloc would fail. Now
672 that we put in on the psymbol_obstack, we can't do this since gdb gets
673 a fatal error (out of virtual memory) if the size is bogus. We can
674 however at least check to see if the size is less than the size of
675 the size field itself, or larger than the size of the entire file.
676 Note that all valid string tables have a size greater than zero, since
677 the bytes used to hold the size are included in the count. */
679 if (STRING_TABLE_OFFSET
== 0)
681 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
682 will never be zero, even when there is no string table. This
683 would appear to be a bug in bfd. */
684 DBX_STRINGTAB_SIZE (objfile
) = 0;
685 DBX_STRINGTAB (objfile
) = NULL
;
689 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, SEEK_SET
);
691 perror_with_name (name
);
693 memset (size_temp
, 0, sizeof (size_temp
));
694 val
= bfd_bread (size_temp
, sizeof (size_temp
), sym_bfd
);
697 perror_with_name (name
);
701 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
702 EOF if there is no string table, and attempting to read the size
703 from EOF will read zero bytes. */
704 DBX_STRINGTAB_SIZE (objfile
) = 0;
705 DBX_STRINGTAB (objfile
) = NULL
;
709 /* Read some data that would appear to be the string table size.
710 If there really is a string table, then it is probably the right
711 size. Byteswap if necessary and validate the size. Note that
712 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
713 random data that happened to be at STRING_TABLE_OFFSET, because
714 bfd can't tell us there is no string table, the sanity checks may
715 or may not catch this. */
716 DBX_STRINGTAB_SIZE (objfile
) = bfd_h_get_32 (sym_bfd
, size_temp
);
718 if (DBX_STRINGTAB_SIZE (objfile
) < sizeof (size_temp
)
719 || DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
720 error ("ridiculous string table size (%d bytes).",
721 DBX_STRINGTAB_SIZE (objfile
));
723 DBX_STRINGTAB (objfile
) =
724 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
725 DBX_STRINGTAB_SIZE (objfile
));
726 OBJSTAT (objfile
, sz_strtab
+= DBX_STRINGTAB_SIZE (objfile
));
728 /* Now read in the string table in one big gulp. */
730 val
= bfd_seek (sym_bfd
, STRING_TABLE_OFFSET
, SEEK_SET
);
732 perror_with_name (name
);
733 val
= bfd_bread (DBX_STRINGTAB (objfile
),
734 DBX_STRINGTAB_SIZE (objfile
),
736 if (val
!= DBX_STRINGTAB_SIZE (objfile
))
737 perror_with_name (name
);
742 /* Perform any local cleanups required when we are done with a particular
743 objfile. I.E, we are in the process of discarding all symbol information
744 for an objfile, freeing up all memory held for it, and unlinking the
745 objfile struct from the global list of known objfiles. */
748 dbx_symfile_finish (struct objfile
*objfile
)
750 if (objfile
->sym_stab_info
!= NULL
)
752 if (HEADER_FILES (objfile
) != NULL
)
754 register int i
= N_HEADER_FILES (objfile
);
755 register struct header_file
*hfiles
= HEADER_FILES (objfile
);
759 xfree (hfiles
[i
].name
);
760 xfree (hfiles
[i
].vector
);
764 xmfree (objfile
->md
, objfile
->sym_stab_info
);
766 free_header_files ();
770 /* Buffer for reading the symbol table entries. */
771 static struct external_nlist symbuf
[4096];
772 static int symbuf_idx
;
773 static int symbuf_end
;
775 #if 0 /* OBSOLETE CFront */
776 // OBSOLETE /* cont_elem is used for continuing information in cfront.
777 // OBSOLETE It saves information about which types need to be fixed up and
778 // OBSOLETE completed after all the stabs are read. */
779 // OBSOLETE struct cont_elem
781 // OBSOLETE /* sym and stabstring for continuing information in cfront */
782 // OBSOLETE struct symbol *sym;
783 // OBSOLETE char *stabs;
784 // OBSOLETE /* state dependencies (statics that must be preserved) */
785 // OBSOLETE int sym_idx;
786 // OBSOLETE int sym_end;
787 // OBSOLETE int symnum;
788 // OBSOLETE int (*func) (struct objfile *, struct symbol *, char *);
789 // OBSOLETE /* other state dependencies include:
790 // OBSOLETE (assumption is that these will not change since process_now FIXME!!)
791 // OBSOLETE stringtab_global
794 // OBSOLETE symfile_bfd */
797 // OBSOLETE static struct cont_elem *cont_list = 0;
798 // OBSOLETE static int cont_limit = 0;
799 // OBSOLETE static int cont_count = 0;
801 // OBSOLETE /* Arrange for function F to be called with arguments SYM and P later
802 // OBSOLETE in the stabs reading process. */
804 // OBSOLETE process_later (struct symbol *sym, char *p,
805 // OBSOLETE int (*f) (struct objfile *, struct symbol *, char *))
808 // OBSOLETE /* Allocate more space for the deferred list. */
809 // OBSOLETE if (cont_count >= cont_limit - 1)
811 // OBSOLETE cont_limit += 32; /* chunk size */
813 // OBSOLETE cont_list
814 // OBSOLETE = (struct cont_elem *) xrealloc (cont_list,
815 // OBSOLETE (cont_limit
816 // OBSOLETE * sizeof (struct cont_elem)));
817 // OBSOLETE if (!cont_list)
818 // OBSOLETE error ("Virtual memory exhausted\n");
821 // OBSOLETE /* Save state variables so we can process these stabs later. */
822 // OBSOLETE cont_list[cont_count].sym_idx = symbuf_idx;
823 // OBSOLETE cont_list[cont_count].sym_end = symbuf_end;
824 // OBSOLETE cont_list[cont_count].symnum = symnum;
825 // OBSOLETE cont_list[cont_count].sym = sym;
826 // OBSOLETE cont_list[cont_count].stabs = p;
827 // OBSOLETE cont_list[cont_count].func = f;
828 // OBSOLETE cont_count++;
831 // OBSOLETE /* Call deferred funtions in CONT_LIST. */
833 // OBSOLETE static void
834 // OBSOLETE process_now (struct objfile *objfile)
837 // OBSOLETE int save_symbuf_idx;
838 // OBSOLETE int save_symbuf_end;
839 // OBSOLETE int save_symnum;
840 // OBSOLETE struct symbol *sym;
841 // OBSOLETE char *stabs;
843 // OBSOLETE int (*func) (struct objfile *, struct symbol *, char *);
845 // OBSOLETE /* Save the state of our caller, we'll want to restore it before
846 // OBSOLETE returning. */
847 // OBSOLETE save_symbuf_idx = symbuf_idx;
848 // OBSOLETE save_symbuf_end = symbuf_end;
849 // OBSOLETE save_symnum = symnum;
851 // OBSOLETE /* Iterate over all the deferred stabs. */
852 // OBSOLETE for (i = 0; i < cont_count; i++)
854 // OBSOLETE /* Restore the state for this deferred stab. */
855 // OBSOLETE symbuf_idx = cont_list[i].sym_idx;
856 // OBSOLETE symbuf_end = cont_list[i].sym_end;
857 // OBSOLETE symnum = cont_list[i].symnum;
858 // OBSOLETE sym = cont_list[i].sym;
859 // OBSOLETE stabs = cont_list[i].stabs;
860 // OBSOLETE func = cont_list[i].func;
862 // OBSOLETE /* Call the function to handle this deferrd stab. */
863 // OBSOLETE err = (*func) (objfile, sym, stabs);
865 // OBSOLETE error ("Internal error: unable to resolve stab.\n");
868 // OBSOLETE /* Restore our caller's state. */
869 // OBSOLETE symbuf_idx = save_symbuf_idx;
870 // OBSOLETE symbuf_end = save_symbuf_end;
871 // OBSOLETE symnum = save_symnum;
872 // OBSOLETE cont_count = 0;
874 #endif /* OBSOLETE CFront */
876 /* Name of last function encountered. Used in Solaris to approximate
877 object file boundaries. */
878 static char *last_function_name
;
880 /* The address in memory of the string table of the object file we are
881 reading (which might not be the "main" object file, but might be a
882 shared library or some other dynamically loaded thing). This is
883 set by read_dbx_symtab when building psymtabs, and by
884 read_ofile_symtab when building symtabs, and is used only by
885 next_symbol_text. FIXME: If that is true, we don't need it when
886 building psymtabs, right? */
887 static char *stringtab_global
;
889 /* These variables are used to control fill_symbuf when the stabs
890 symbols are not contiguous (as may be the case when a COFF file is
891 linked using --split-by-reloc). */
892 static struct stab_section_list
*symbuf_sections
;
893 static unsigned int symbuf_left
;
894 static unsigned int symbuf_read
;
896 /* Refill the symbol table input buffer
897 and set the variables that control fetching entries from it.
898 Reports an error if no data available.
899 This function can read past the end of the symbol table
900 (into the string table) but this does no harm. */
903 fill_symbuf (bfd
*sym_bfd
)
908 if (symbuf_sections
== NULL
)
909 count
= sizeof (symbuf
);
912 if (symbuf_left
<= 0)
914 file_ptr filepos
= symbuf_sections
->section
->filepos
;
915 if (bfd_seek (sym_bfd
, filepos
, SEEK_SET
) != 0)
916 perror_with_name (bfd_get_filename (sym_bfd
));
917 symbuf_left
= bfd_section_size (sym_bfd
, symbuf_sections
->section
);
918 symbol_table_offset
= filepos
- symbuf_read
;
919 symbuf_sections
= symbuf_sections
->next
;
923 if (count
> sizeof (symbuf
))
924 count
= sizeof (symbuf
);
927 nbytes
= bfd_bread (symbuf
, count
, sym_bfd
);
929 perror_with_name (bfd_get_filename (sym_bfd
));
930 else if (nbytes
== 0)
931 error ("Premature end of file reading symbol table");
932 symbuf_end
= nbytes
/ symbol_size
;
934 symbuf_left
-= nbytes
;
935 symbuf_read
+= nbytes
;
938 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
940 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
941 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
942 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
943 if (bfd_get_sign_extend_vma (abfd)) \
944 (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
946 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
949 /* Invariant: The symbol pointed to by symbuf_idx is the first one
950 that hasn't been swapped. Swap the symbol at the same time
951 that symbuf_idx is incremented. */
953 /* dbx allows the text of a symbol name to be continued into the
954 next symbol name! When such a continuation is encountered
955 (a \ at the end of the text of a name)
956 call this function to get the continuation. */
959 dbx_next_symbol_text (struct objfile
*objfile
)
961 struct internal_nlist nlist
;
963 if (symbuf_idx
== symbuf_end
)
964 fill_symbuf (symfile_bfd
);
967 INTERNALIZE_SYMBOL (nlist
, &symbuf
[symbuf_idx
], symfile_bfd
);
968 OBJSTAT (objfile
, n_stabs
++);
972 return nlist
.n_strx
+ stringtab_global
+ file_string_table_offset
;
975 /* Initialize the list of bincls to contain none and have some
979 init_bincl_list (int number
, struct objfile
*objfile
)
981 bincls_allocated
= number
;
982 next_bincl
= bincl_list
= (struct header_file_location
*)
983 xmmalloc (objfile
->md
, bincls_allocated
* sizeof (struct header_file_location
));
986 /* Add a bincl to the list. */
989 add_bincl_to_list (struct partial_symtab
*pst
, char *name
, int instance
)
991 if (next_bincl
>= bincl_list
+ bincls_allocated
)
993 int offset
= next_bincl
- bincl_list
;
994 bincls_allocated
*= 2;
995 bincl_list
= (struct header_file_location
*)
996 xmrealloc (pst
->objfile
->md
, (char *) bincl_list
,
997 bincls_allocated
* sizeof (struct header_file_location
));
998 next_bincl
= bincl_list
+ offset
;
1000 next_bincl
->pst
= pst
;
1001 next_bincl
->instance
= instance
;
1002 next_bincl
++->name
= name
;
1005 /* Given a name, value pair, find the corresponding
1006 bincl in the list. Return the partial symtab associated
1007 with that header_file_location. */
1009 static struct partial_symtab
*
1010 find_corresponding_bincl_psymtab (char *name
, int instance
)
1012 struct header_file_location
*bincl
;
1014 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
1015 if (bincl
->instance
== instance
1016 && STREQ (name
, bincl
->name
))
1019 repeated_header_complaint (name
, symnum
);
1020 return (struct partial_symtab
*) 0;
1023 /* Free the storage allocated for the bincl list. */
1026 free_bincl_list (struct objfile
*objfile
)
1028 xmfree (objfile
->md
, bincl_list
);
1029 bincls_allocated
= 0;
1033 do_free_bincl_list_cleanup (void *objfile
)
1035 free_bincl_list (objfile
);
1038 static struct cleanup
*
1039 make_cleanup_free_bincl_list (struct objfile
*objfile
)
1041 return make_cleanup (do_free_bincl_list_cleanup
, objfile
);
1044 /* Set namestring based on nlist. If the string table index is invalid,
1045 give a fake name, and print a single error message per symbol file read,
1046 rather than abort the symbol reading or flood the user with messages. */
1049 set_namestring (struct objfile
*objfile
, struct internal_nlist nlist
)
1053 if (((unsigned) nlist
.n_strx
+ file_string_table_offset
) >=
1054 DBX_STRINGTAB_SIZE (objfile
))
1056 complaint (&symfile_complaints
, "bad string table offset in symbol %d",
1058 namestring
= "<bad string table offset>";
1061 namestring
= nlist
.n_strx
+ file_string_table_offset
+
1062 DBX_STRINGTAB (objfile
);
1066 /* Scan a SunOs dynamic symbol table for symbols of interest and
1067 add them to the minimal symbol table. */
1070 read_dbx_dynamic_symtab (struct objfile
*objfile
)
1072 bfd
*abfd
= objfile
->obfd
;
1073 struct cleanup
*back_to
;
1083 CORE_ADDR sym_value
;
1086 /* Check that the symbol file has dynamic symbols that we know about.
1087 bfd_arch_unknown can happen if we are reading a sun3 symbol file
1088 on a sun4 host (and vice versa) and bfd is not configured
1089 --with-target=all. This would trigger an assertion in bfd/sunos.c,
1090 so we ignore the dynamic symbols in this case. */
1091 if (bfd_get_flavour (abfd
) != bfd_target_aout_flavour
1092 || (bfd_get_file_flags (abfd
) & DYNAMIC
) == 0
1093 || bfd_get_arch (abfd
) == bfd_arch_unknown
)
1096 dynsym_size
= bfd_get_dynamic_symtab_upper_bound (abfd
);
1097 if (dynsym_size
< 0)
1100 dynsyms
= (asymbol
**) xmalloc (dynsym_size
);
1101 back_to
= make_cleanup (xfree
, dynsyms
);
1103 dynsym_count
= bfd_canonicalize_dynamic_symtab (abfd
, dynsyms
);
1104 if (dynsym_count
< 0)
1106 do_cleanups (back_to
);
1110 /* Enter dynamic symbols into the minimal symbol table
1111 if this is a stripped executable. */
1112 if (bfd_get_symcount (abfd
) <= 0)
1115 for (counter
= 0; counter
< dynsym_count
; counter
++, symptr
++)
1117 asymbol
*sym
= *symptr
;
1121 sec
= bfd_get_section (sym
);
1123 /* BFD symbols are section relative. */
1124 sym_value
= sym
->value
+ sec
->vma
;
1126 if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1128 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1131 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1133 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1136 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1138 sym_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
1144 if (sym
->flags
& BSF_GLOBAL
)
1147 record_minimal_symbol ((char *) bfd_asymbol_name (sym
), sym_value
,
1152 /* Symbols from shared libraries have a dynamic relocation entry
1153 that points to the associated slot in the procedure linkage table.
1154 We make a mininal symbol table entry with type mst_solib_trampoline
1155 at the address in the procedure linkage table. */
1156 dynrel_size
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1157 if (dynrel_size
< 0)
1159 do_cleanups (back_to
);
1163 dynrels
= (arelent
**) xmalloc (dynrel_size
);
1164 make_cleanup (xfree
, dynrels
);
1166 dynrel_count
= bfd_canonicalize_dynamic_reloc (abfd
, dynrels
, dynsyms
);
1167 if (dynrel_count
< 0)
1169 do_cleanups (back_to
);
1173 for (counter
= 0, relptr
= dynrels
;
1174 counter
< dynrel_count
;
1175 counter
++, relptr
++)
1177 arelent
*rel
= *relptr
;
1179 rel
->address
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1181 switch (bfd_get_arch (abfd
))
1183 case bfd_arch_sparc
:
1184 if (rel
->howto
->type
!= RELOC_JMP_SLOT
)
1188 /* `16' is the type BFD produces for a jump table relocation. */
1189 if (rel
->howto
->type
!= 16)
1192 /* Adjust address in the jump table to point to
1193 the start of the bsr instruction. */
1200 name
= (char *) bfd_asymbol_name (*rel
->sym_ptr_ptr
);
1201 prim_record_minimal_symbol (name
, address
, mst_solib_trampoline
,
1205 do_cleanups (back_to
);
1208 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1210 find_stab_function_addr (char *namestring
, char *filename
,
1211 struct objfile
*objfile
)
1213 struct minimal_symbol
*msym
;
1217 p
= strchr (namestring
, ':');
1222 strncpy (p
, namestring
, n
);
1225 msym
= lookup_minimal_symbol (p
, filename
, objfile
);
1228 /* Sun Fortran appends an underscore to the minimal symbol name,
1229 try again with an appended underscore if the minimal symbol
1233 msym
= lookup_minimal_symbol (p
, filename
, objfile
);
1236 if (msym
== NULL
&& filename
!= NULL
)
1238 /* Try again without the filename. */
1240 msym
= lookup_minimal_symbol (p
, NULL
, objfile
);
1242 if (msym
== NULL
&& filename
!= NULL
)
1244 /* And try again for Sun Fortran, but without the filename. */
1247 msym
= lookup_minimal_symbol (p
, NULL
, objfile
);
1250 return msym
== NULL
? 0 : SYMBOL_VALUE_ADDRESS (msym
);
1252 #endif /* SOFUN_ADDRESS_MAYBE_MISSING */
1255 function_outside_compilation_unit_complaint (const char *arg1
)
1257 complaint (&symfile_complaints
,
1258 "function `%s' appears to be defined outside of all compilation units",
1262 /* Setup partial_symtab's describing each source file for which
1263 debugging information is available. */
1266 read_dbx_symtab (struct objfile
*objfile
)
1268 register struct external_nlist
*bufp
= 0; /* =0 avoids gcc -Wall glitch */
1269 struct internal_nlist nlist
;
1270 CORE_ADDR text_addr
;
1273 register char *namestring
;
1275 int past_first_source_file
= 0;
1276 CORE_ADDR last_o_file_start
= 0;
1277 CORE_ADDR last_function_start
= 0;
1278 struct cleanup
*back_to
;
1280 int textlow_not_set
;
1282 /* Current partial symtab */
1283 struct partial_symtab
*pst
;
1285 /* List of current psymtab's include files */
1286 char **psymtab_include_list
;
1287 int includes_allocated
;
1290 /* Index within current psymtab dependency list */
1291 struct partial_symtab
**dependency_list
;
1292 int dependencies_used
, dependencies_allocated
;
1294 text_addr
= DBX_TEXT_ADDR (objfile
);
1295 text_size
= DBX_TEXT_SIZE (objfile
);
1297 /* FIXME. We probably want to change stringtab_global rather than add this
1298 while processing every symbol entry. FIXME. */
1299 file_string_table_offset
= 0;
1300 next_file_string_table_offset
= 0;
1302 stringtab_global
= DBX_STRINGTAB (objfile
);
1304 pst
= (struct partial_symtab
*) 0;
1306 includes_allocated
= 30;
1308 psymtab_include_list
= (char **) alloca (includes_allocated
*
1311 dependencies_allocated
= 30;
1312 dependencies_used
= 0;
1314 (struct partial_symtab
**) alloca (dependencies_allocated
*
1315 sizeof (struct partial_symtab
*));
1317 /* Init bincl list */
1318 init_bincl_list (20, objfile
);
1319 back_to
= make_cleanup_free_bincl_list (objfile
);
1321 last_source_file
= NULL
;
1323 lowest_text_address
= (CORE_ADDR
) -1;
1325 symfile_bfd
= objfile
->obfd
; /* For next_text_symbol */
1326 abfd
= objfile
->obfd
;
1327 symbuf_end
= symbuf_idx
= 0;
1328 next_symbol_text_func
= dbx_next_symbol_text
;
1329 textlow_not_set
= 1;
1330 has_line_numbers
= 0;
1332 for (symnum
= 0; symnum
< DBX_SYMCOUNT (objfile
); symnum
++)
1334 /* Get the symbol for this run and pull out some info */
1335 QUIT
; /* allow this to be interruptable */
1336 if (symbuf_idx
== symbuf_end
)
1338 bufp
= &symbuf
[symbuf_idx
++];
1341 * Special case to speed up readin.
1343 if (bfd_h_get_8 (abfd
, bufp
->e_type
) == N_SLINE
)
1345 has_line_numbers
= 1;
1349 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
1350 OBJSTAT (objfile
, n_stabs
++);
1352 /* Ok. There is a lot of code duplicated in the rest of this
1353 switch statement (for efficiency reasons). Since I don't
1354 like duplicating code, I will do my penance here, and
1355 describe the code which is duplicated:
1357 *) The assignment to namestring.
1358 *) The call to strchr.
1359 *) The addition of a partial symbol the the two partial
1360 symbol lists. This last is a large section of code, so
1361 I've imbedded it in the following macro.
1364 switch (nlist
.n_type
)
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 complaint (&symfile_complaints
,
1617 "N_BINCL %s not in entries for any file, at symtab pos %d",
1618 namestring
, symnum
);
1621 add_bincl_to_list (pst
, namestring
, nlist
.n_value
);
1623 /* Mark down an include file in the current psymtab */
1625 goto record_include_file
;
1630 enum language tmp_language
;
1631 /* Mark down an include file in the current psymtab */
1633 namestring
= set_namestring (objfile
, nlist
);
1634 tmp_language
= deduce_language_from_filename (namestring
);
1636 /* Only change the psymtab's language if we've learned
1637 something useful (eg. tmp_language is not language_unknown).
1638 In addition, to match what start_subfile does, never change
1640 if (tmp_language
!= language_unknown
1641 && (tmp_language
!= language_c
1642 || psymtab_language
!= language_cplus
))
1643 psymtab_language
= tmp_language
;
1645 /* In C++, one may expect the same filename to come round many
1646 times, when code is coming alternately from the main file
1647 and from inline functions in other files. So I check to see
1648 if this is a file we've seen before -- either the main
1649 source file, or a previously included file.
1651 This seems to be a lot of time to be spending on N_SOL, but
1652 things like "break c-exp.y:435" need to work (I
1653 suppose the psymtab_include_list could be hashed or put
1654 in a binary tree, if profiling shows this is a major hog). */
1655 if (pst
&& STREQ (namestring
, pst
->filename
))
1659 for (i
= 0; i
< includes_used
; i
++)
1660 if (STREQ (namestring
, psymtab_include_list
[i
]))
1669 record_include_file
:
1671 psymtab_include_list
[includes_used
++] = namestring
;
1672 if (includes_used
>= includes_allocated
)
1674 char **orig
= psymtab_include_list
;
1676 psymtab_include_list
= (char **)
1677 alloca ((includes_allocated
*= 2) *
1679 memcpy (psymtab_include_list
, orig
,
1680 includes_used
* sizeof (char *));
1684 case N_LSYM
: /* Typedef or automatic variable. */
1685 case N_STSYM
: /* Data seg var -- static */
1686 case N_LCSYM
: /* BSS " */
1687 case N_ROSYM
: /* Read-only data seg var -- static. */
1688 case N_NBSTS
: /* Gould nobase. */
1689 case N_NBLCS
: /* symbols. */
1691 case N_GSYM
: /* Global (extern) variable; can be
1692 data or bss (sigh FIXME). */
1694 /* Following may probably be ignored; I'll leave them here
1695 for now (until I do Pascal and Modula 2 extensions). */
1697 case N_PC
: /* I may or may not need this; I
1699 case N_M2C
: /* I suspect that I can ignore this here. */
1700 case N_SCOPE
: /* Same. */
1702 namestring
= set_namestring (objfile
, nlist
);
1704 /* See if this is an end of function stab. */
1705 if (pst
&& nlist
.n_type
== N_FUN
&& *namestring
== '\000')
1709 /* It's value is the size (in bytes) of the function for
1710 function relative stabs, or the address of the function's
1711 end for old style stabs. */
1712 valu
= nlist
.n_value
+ last_function_start
;
1713 if (pst
->texthigh
== 0 || valu
> pst
->texthigh
)
1714 pst
->texthigh
= valu
;
1718 p
= (char *) strchr (namestring
, ':');
1720 continue; /* Not a debugging symbol. */
1724 /* Main processing section for debugging symbols which
1725 the initial read through the symbol tables needs to worry
1726 about. If we reach this point, the symbol which we are
1727 considering is definitely one we are interested in.
1728 p must also contain the (valid) index into the namestring
1729 which indicates the debugging type symbol. */
1734 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1735 #ifdef STATIC_TRANSFORM_NAME
1736 namestring
= STATIC_TRANSFORM_NAME (namestring
);
1738 add_psymbol_to_list (namestring
, p
- namestring
,
1739 VAR_NAMESPACE
, LOC_STATIC
,
1740 &objfile
->static_psymbols
,
1742 psymtab_language
, objfile
);
1745 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
1746 /* The addresses in these entries are reported to be
1747 wrong. See the code that reads 'G's for symtabs. */
1748 add_psymbol_to_list (namestring
, p
- namestring
,
1749 VAR_NAMESPACE
, LOC_STATIC
,
1750 &objfile
->global_psymbols
,
1752 psymtab_language
, objfile
);
1756 /* When a 'T' entry is defining an anonymous enum, it
1757 may have a name which is the empty string, or a
1758 single space. Since they're not really defining a
1759 symbol, those shouldn't go in the partial symbol
1760 table. We do pick up the elements of such enums at
1761 'check_enum:', below. */
1762 if (p
>= namestring
+ 2
1763 || (p
== namestring
+ 1
1764 && namestring
[0] != ' '))
1766 add_psymbol_to_list (namestring
, p
- namestring
,
1767 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1768 &objfile
->static_psymbols
,
1770 psymtab_language
, objfile
);
1773 /* Also a typedef with the same name. */
1774 add_psymbol_to_list (namestring
, p
- namestring
,
1775 VAR_NAMESPACE
, LOC_TYPEDEF
,
1776 &objfile
->static_psymbols
,
1778 psymtab_language
, objfile
);
1781 #if 0 /* OBSOLETE CFront */
1782 // OBSOLETE /* The semantics of C++ state that "struct foo { ... }"
1783 // OBSOLETE also defines a typedef for "foo". Unfortuantely, cfront
1784 // OBSOLETE never makes the typedef when translating from C++ to C.
1785 // OBSOLETE We make the typedef here so that "ptype foo" works as
1786 // OBSOLETE expected for cfront translated code. */
1787 // OBSOLETE else if (psymtab_language == language_cplus)
1789 // OBSOLETE /* Also a typedef with the same name. */
1790 // OBSOLETE add_psymbol_to_list (namestring, p - namestring,
1791 // OBSOLETE VAR_NAMESPACE, LOC_TYPEDEF,
1792 // OBSOLETE &objfile->static_psymbols,
1793 // OBSOLETE nlist.n_value, 0,
1794 // OBSOLETE psymtab_language, objfile);
1796 #endif /* OBSOLETE CFront */
1800 if (p
!= namestring
) /* a name is there, not just :T... */
1802 add_psymbol_to_list (namestring
, p
- namestring
,
1803 VAR_NAMESPACE
, LOC_TYPEDEF
,
1804 &objfile
->static_psymbols
,
1806 psymtab_language
, objfile
);
1809 /* If this is an enumerated type, we need to
1810 add all the enum constants to the partial symbol
1811 table. This does not cover enums without names, e.g.
1812 "enum {a, b} c;" in C, but fortunately those are
1813 rare. There is no way for GDB to find those from the
1814 enum type without spending too much time on it. Thus
1815 to solve this problem, the compiler needs to put out the
1816 enum in a nameless type. GCC2 does this. */
1818 /* We are looking for something of the form
1819 <name> ":" ("t" | "T") [<number> "="] "e"
1820 {<constant> ":" <value> ","} ";". */
1822 /* Skip over the colon and the 't' or 'T'. */
1824 /* This type may be given a number. Also, numbers can come
1825 in pairs like (0,26). Skip over it. */
1826 while ((*p
>= '0' && *p
<= '9')
1827 || *p
== '(' || *p
== ',' || *p
== ')'
1833 /* The aix4 compiler emits extra crud before the members. */
1836 /* Skip over the type (?). */
1840 /* Skip over the colon. */
1844 /* We have found an enumerated type. */
1845 /* According to comments in read_enum_type
1846 a comma could end it instead of a semicolon.
1847 I don't know where that happens.
1849 while (*p
&& *p
!= ';' && *p
!= ',')
1853 /* Check for and handle cretinous dbx symbol name
1855 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
1856 p
= next_symbol_text (objfile
);
1858 /* Point to the character after the name
1859 of the enum constant. */
1860 for (q
= p
; *q
&& *q
!= ':'; q
++)
1862 /* Note that the value doesn't matter for
1863 enum constants in psymtabs, just in symtabs. */
1864 add_psymbol_to_list (p
, q
- p
,
1865 VAR_NAMESPACE
, LOC_CONST
,
1866 &objfile
->static_psymbols
, 0,
1867 0, psymtab_language
, objfile
);
1868 /* Point past the name. */
1870 /* Skip over the value. */
1871 while (*p
&& *p
!= ',')
1873 /* Advance past the comma. */
1880 /* Constant, e.g. from "const" in Pascal. */
1881 add_psymbol_to_list (namestring
, p
- namestring
,
1882 VAR_NAMESPACE
, LOC_CONST
,
1883 &objfile
->static_psymbols
, nlist
.n_value
,
1884 0, psymtab_language
, objfile
);
1890 int name_len
= p
- namestring
;
1891 char *name
= xmalloc (name_len
+ 1);
1892 memcpy (name
, namestring
, name_len
);
1893 name
[name_len
] = '\0';
1894 function_outside_compilation_unit_complaint (name
);
1897 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1898 /* Kludges for ELF/STABS with Sun ACC */
1899 last_function_name
= namestring
;
1900 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1901 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1902 value for the bottom of the text seg in those cases. */
1903 if (nlist
.n_value
== ANOFFSET (objfile
->section_offsets
,
1904 SECT_OFF_TEXT (objfile
)))
1906 CORE_ADDR minsym_valu
=
1907 find_stab_function_addr (namestring
, pst
->filename
, objfile
);
1908 /* find_stab_function_addr will return 0 if the minimal
1909 symbol wasn't found. (Unfortunately, this might also
1910 be a valid address.) Anyway, if it *does* return 0,
1911 it is likely that the value was set correctly to begin
1913 if (minsym_valu
!= 0)
1914 nlist
.n_value
= minsym_valu
;
1916 if (pst
&& textlow_not_set
)
1918 pst
->textlow
= nlist
.n_value
;
1919 textlow_not_set
= 0;
1924 /* Keep track of the start of the last function so we
1925 can handle end of function symbols. */
1926 last_function_start
= nlist
.n_value
;
1928 /* In reordered executables this function may lie outside
1929 the bounds created by N_SO symbols. If that's the case
1930 use the address of this function as the low bound for
1931 the partial symbol table. */
1934 || (nlist
.n_value
< pst
->textlow
1936 != ANOFFSET (objfile
->section_offsets
,
1937 SECT_OFF_TEXT (objfile
))))))
1939 pst
->textlow
= nlist
.n_value
;
1940 textlow_not_set
= 0;
1942 add_psymbol_to_list (namestring
, p
- namestring
,
1943 VAR_NAMESPACE
, LOC_BLOCK
,
1944 &objfile
->static_psymbols
,
1946 psymtab_language
, objfile
);
1949 /* Global functions were ignored here, but now they
1950 are put into the global psymtab like one would expect.
1951 They're also in the minimal symbol table. */
1955 int name_len
= p
- namestring
;
1956 char *name
= xmalloc (name_len
+ 1);
1957 memcpy (name
, namestring
, name_len
);
1958 name
[name_len
] = '\0';
1959 function_outside_compilation_unit_complaint (name
);
1962 nlist
.n_value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1963 /* Kludges for ELF/STABS with Sun ACC */
1964 last_function_name
= namestring
;
1965 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1966 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1967 value for the bottom of the text seg in those cases. */
1968 if (nlist
.n_value
== ANOFFSET (objfile
->section_offsets
,
1969 SECT_OFF_TEXT (objfile
)))
1971 CORE_ADDR minsym_valu
=
1972 find_stab_function_addr (namestring
, pst
->filename
, objfile
);
1973 /* find_stab_function_addr will return 0 if the minimal
1974 symbol wasn't found. (Unfortunately, this might also
1975 be a valid address.) Anyway, if it *does* return 0,
1976 it is likely that the value was set correctly to begin
1978 if (minsym_valu
!= 0)
1979 nlist
.n_value
= minsym_valu
;
1981 if (pst
&& textlow_not_set
)
1983 pst
->textlow
= nlist
.n_value
;
1984 textlow_not_set
= 0;
1989 /* Keep track of the start of the last function so we
1990 can handle end of function symbols. */
1991 last_function_start
= nlist
.n_value
;
1993 /* In reordered executables this function may lie outside
1994 the bounds created by N_SO symbols. If that's the case
1995 use the address of this function as the low bound for
1996 the partial symbol table. */
1999 || (nlist
.n_value
< pst
->textlow
2001 != ANOFFSET (objfile
->section_offsets
,
2002 SECT_OFF_TEXT (objfile
))))))
2004 pst
->textlow
= nlist
.n_value
;
2005 textlow_not_set
= 0;
2007 add_psymbol_to_list (namestring
, p
- namestring
,
2008 VAR_NAMESPACE
, LOC_BLOCK
,
2009 &objfile
->global_psymbols
,
2011 psymtab_language
, objfile
);
2014 /* Two things show up here (hopefully); static symbols of
2015 local scope (static used inside braces) or extensions
2016 of structure symbols. We can ignore both. */
2030 case '#': /* for symbol identification (used in live ranges) */
2031 #if 0 /* OBSOLETE CFront */
2032 // OBSOLETE /* added to support cfront stabs strings */
2033 // OBSOLETE case 'Z': /* for definition continuations */
2034 // OBSOLETE case 'P': /* for prototypes */
2035 #endif /* OBSOLETE CFront */
2039 /* It is a C++ nested symbol. We don't need to record it
2040 (I don't think); if we try to look up foo::bar::baz,
2041 then symbols for the symtab containing foo should get
2042 read in, I think. */
2043 /* Someone says sun cc puts out symbols like
2044 /foo/baz/maclib::/usr/local/bin/maclib,
2045 which would get here with a symbol type of ':'. */
2049 /* Unexpected symbol descriptor. The second and subsequent stabs
2050 of a continued stab can show up here. The question is
2051 whether they ever can mimic a normal stab--it would be
2052 nice if not, since we certainly don't want to spend the
2053 time searching to the end of every string looking for
2056 complaint (&symfile_complaints
, "unknown symbol descriptor `%c'",
2059 /* Ignore it; perhaps it is an extension that we don't
2066 namestring
= set_namestring (objfile
, nlist
);
2068 /* Find the corresponding bincl and mark that psymtab on the
2069 psymtab dependency list */
2071 struct partial_symtab
*needed_pst
=
2072 find_corresponding_bincl_psymtab (namestring
, nlist
.n_value
);
2074 /* If this include file was defined earlier in this file,
2076 if (needed_pst
== pst
)
2084 for (i
= 0; i
< dependencies_used
; i
++)
2085 if (dependency_list
[i
] == needed_pst
)
2091 /* If it's already in the list, skip the rest. */
2095 dependency_list
[dependencies_used
++] = needed_pst
;
2096 if (dependencies_used
>= dependencies_allocated
)
2098 struct partial_symtab
**orig
= dependency_list
;
2100 (struct partial_symtab
**)
2101 alloca ((dependencies_allocated
*= 2)
2102 * sizeof (struct partial_symtab
*));
2103 memcpy (dependency_list
, orig
,
2105 * sizeof (struct partial_symtab
*)));
2107 fprintf_unfiltered (gdb_stderr
, "Had to reallocate dependency list.\n");
2108 fprintf_unfiltered (gdb_stderr
, "New dependencies allocated: %d\n",
2109 dependencies_allocated
);
2117 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2118 /* Solaris 2 end of module, finish current partial symbol table.
2119 end_psymtab will set pst->texthigh to the proper value, which
2120 is necessary if a module compiled without debugging info
2121 follows this module. */
2124 end_psymtab (pst
, psymtab_include_list
, includes_used
,
2125 symnum
* symbol_size
,
2127 dependency_list
, dependencies_used
, textlow_not_set
);
2128 pst
= (struct partial_symtab
*) 0;
2130 dependencies_used
= 0;
2137 HANDLE_RBRAC (nlist
.n_value
);
2143 case N_SSYM
: /* Claim: Structure or union element.
2144 Hopefully, I can ignore this. */
2145 case N_ENTRY
: /* Alternate entry point; can ignore. */
2146 case N_MAIN
: /* Can definitely ignore this. */
2147 case N_CATCH
: /* These are GNU C++ extensions */
2148 case N_EHDECL
: /* that can safely be ignored here. */
2158 case N_NSYMS
: /* Ultrix 4.0: symbol count */
2159 case N_DEFD
: /* GNU Modula-2 */
2160 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
2162 case N_OBJ
: /* useless types from Solaris */
2164 /* These symbols aren't interesting; don't worry about them */
2169 /* If we haven't found it yet, ignore it. It's probably some
2170 new type we don't know about yet. */
2171 unknown_symtype_complaint (local_hex_string (nlist
.n_type
));
2176 /* If there's stuff to be cleaned up, clean it up. */
2177 if (DBX_SYMCOUNT (objfile
) > 0 /* We have some syms */
2178 /*FIXME, does this have a bug at start address 0? */
2179 && last_o_file_start
2180 && objfile
->ei
.entry_point
< nlist
.n_value
2181 && objfile
->ei
.entry_point
>= last_o_file_start
)
2183 objfile
->ei
.entry_file_lowpc
= last_o_file_start
;
2184 objfile
->ei
.entry_file_highpc
= nlist
.n_value
;
2189 /* Don't set pst->texthigh lower than it already is. */
2190 CORE_ADDR text_end
=
2191 (lowest_text_address
== (CORE_ADDR
) -1
2192 ? (text_addr
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
)))
2193 : lowest_text_address
)
2196 end_psymtab (pst
, psymtab_include_list
, includes_used
,
2197 symnum
* symbol_size
,
2198 text_end
> pst
->texthigh
? text_end
: pst
->texthigh
,
2199 dependency_list
, dependencies_used
, textlow_not_set
);
2202 do_cleanups (back_to
);
2205 /* Allocate and partially fill a partial symtab. It will be
2206 completely filled at the end of the symbol list.
2208 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2209 is the address relative to which its symbols are (incremental) or 0
2213 static struct partial_symtab
*
2214 start_psymtab (struct objfile
*objfile
, char *filename
, CORE_ADDR textlow
,
2215 int ldsymoff
, struct partial_symbol
**global_syms
,
2216 struct partial_symbol
**static_syms
)
2218 struct partial_symtab
*result
=
2219 start_psymtab_common (objfile
, objfile
->section_offsets
,
2220 filename
, textlow
, global_syms
, static_syms
);
2222 result
->read_symtab_private
= (char *)
2223 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2224 LDSYMOFF (result
) = ldsymoff
;
2225 result
->read_symtab
= dbx_psymtab_to_symtab
;
2226 SYMBOL_SIZE (result
) = symbol_size
;
2227 SYMBOL_OFFSET (result
) = symbol_table_offset
;
2228 STRING_OFFSET (result
) = string_table_offset
;
2229 FILE_STRING_OFFSET (result
) = file_string_table_offset
;
2231 /* If we're handling an ELF file, drag some section-relocation info
2232 for this source file out of the ELF symbol table, to compensate for
2233 Sun brain death. This replaces the section_offsets in this psymtab,
2235 elfstab_offset_sections (objfile
, result
);
2237 /* Deduce the source language from the filename for this psymtab. */
2238 psymtab_language
= deduce_language_from_filename (filename
);
2243 /* Close off the current usage of PST.
2244 Returns PST or NULL if the partial symtab was empty and thrown away.
2246 FIXME: List variables and peculiarities of same. */
2248 struct partial_symtab
*
2249 end_psymtab (struct partial_symtab
*pst
, char **include_list
, int num_includes
,
2250 int capping_symbol_offset
, CORE_ADDR capping_text
,
2251 struct partial_symtab
**dependency_list
, int number_dependencies
,
2252 int textlow_not_set
)
2255 struct objfile
*objfile
= pst
->objfile
;
2257 if (capping_symbol_offset
!= -1)
2258 LDSYMLEN (pst
) = capping_symbol_offset
- LDSYMOFF (pst
);
2259 pst
->texthigh
= capping_text
;
2261 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2262 /* Under Solaris, the N_SO symbols always have a value of 0,
2263 instead of the usual address of the .o file. Therefore,
2264 we have to do some tricks to fill in texthigh and textlow.
2265 The first trick is: if we see a static
2266 or global function, and the textlow for the current pst
2267 is not set (ie: textlow_not_set), then we use that function's
2268 address for the textlow of the pst. */
2270 /* Now, to fill in texthigh, we remember the last function seen
2271 in the .o file. Also, there's a hack in
2272 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
2273 to here via the misc_info field. Therefore, we can fill in
2274 a reliable texthigh by taking the address plus size of the
2275 last function in the file. */
2277 if (pst
->texthigh
== 0 && last_function_name
)
2281 struct minimal_symbol
*minsym
;
2283 p
= strchr (last_function_name
, ':');
2285 p
= last_function_name
;
2286 n
= p
- last_function_name
;
2288 strncpy (p
, last_function_name
, n
);
2291 minsym
= lookup_minimal_symbol (p
, pst
->filename
, objfile
);
2294 /* Sun Fortran appends an underscore to the minimal symbol name,
2295 try again with an appended underscore if the minimal symbol
2299 minsym
= lookup_minimal_symbol (p
, pst
->filename
, objfile
);
2303 pst
->texthigh
= SYMBOL_VALUE_ADDRESS (minsym
) + MSYMBOL_SIZE (minsym
);
2305 last_function_name
= NULL
;
2308 /* this test will be true if the last .o file is only data */
2309 if (textlow_not_set
)
2310 pst
->textlow
= pst
->texthigh
;
2313 struct partial_symtab
*p1
;
2315 /* If we know our own starting text address, then walk through all other
2316 psymtabs for this objfile, and if any didn't know their ending text
2317 address, set it to our starting address. Take care to not set our
2318 own ending address to our starting address, nor to set addresses on
2319 `dependency' files that have both textlow and texthigh zero. */
2321 ALL_OBJFILE_PSYMTABS (objfile
, p1
)
2323 if (p1
->texthigh
== 0 && p1
->textlow
!= 0 && p1
!= pst
)
2325 p1
->texthigh
= pst
->textlow
;
2326 /* if this file has only data, then make textlow match texthigh */
2327 if (p1
->textlow
== 0)
2328 p1
->textlow
= p1
->texthigh
;
2333 /* End of kludge for patching Solaris textlow and texthigh. */
2334 #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */
2336 pst
->n_global_syms
=
2337 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2338 pst
->n_static_syms
=
2339 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2341 pst
->number_of_dependencies
= number_dependencies
;
2342 if (number_dependencies
)
2344 pst
->dependencies
= (struct partial_symtab
**)
2345 obstack_alloc (&objfile
->psymbol_obstack
,
2346 number_dependencies
* sizeof (struct partial_symtab
*));
2347 memcpy (pst
->dependencies
, dependency_list
,
2348 number_dependencies
* sizeof (struct partial_symtab
*));
2351 pst
->dependencies
= 0;
2353 for (i
= 0; i
< num_includes
; i
++)
2355 struct partial_symtab
*subpst
=
2356 allocate_psymtab (include_list
[i
], objfile
);
2358 /* Copy the sesction_offsets array from the main psymtab. */
2359 subpst
->section_offsets
= pst
->section_offsets
;
2360 subpst
->read_symtab_private
=
2361 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
2362 sizeof (struct symloc
));
2366 subpst
->texthigh
= 0;
2368 /* We could save slight bits of space by only making one of these,
2369 shared by the entire set of include files. FIXME-someday. */
2370 subpst
->dependencies
= (struct partial_symtab
**)
2371 obstack_alloc (&objfile
->psymbol_obstack
,
2372 sizeof (struct partial_symtab
*));
2373 subpst
->dependencies
[0] = pst
;
2374 subpst
->number_of_dependencies
= 1;
2376 subpst
->globals_offset
=
2377 subpst
->n_global_syms
=
2378 subpst
->statics_offset
=
2379 subpst
->n_static_syms
= 0;
2383 subpst
->read_symtab
= pst
->read_symtab
;
2386 sort_pst_symbols (pst
);
2388 /* If there is already a psymtab or symtab for a file of this name, remove it.
2389 (If there is a symtab, more drastic things also happen.)
2390 This happens in VxWorks. */
2391 free_named_symtabs (pst
->filename
);
2393 if (num_includes
== 0
2394 && number_dependencies
== 0
2395 && pst
->n_global_syms
== 0
2396 && pst
->n_static_syms
== 0
2397 && has_line_numbers
== 0)
2399 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2400 it is on the obstack, but we can forget to chain it on the list. */
2401 /* Empty psymtabs happen as a result of header files which don't have
2402 any symbols in them. There can be a lot of them. But this check
2403 is wrong, in that a psymtab with N_SLINE entries but nothing else
2404 is not empty, but we don't realize that. Fixing that without slowing
2405 things down might be tricky. */
2407 discard_psymtab (pst
);
2409 /* Indicate that psymtab was thrown away. */
2410 pst
= (struct partial_symtab
*) NULL
;
2416 dbx_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2418 struct cleanup
*old_chain
;
2426 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2431 /* Read in all partial symtabs on which this one is dependent */
2432 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2433 if (!pst
->dependencies
[i
]->readin
)
2435 /* Inform about additional files that need to be read in. */
2438 fputs_filtered (" ", gdb_stdout
);
2440 fputs_filtered ("and ", gdb_stdout
);
2442 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2443 wrap_here (""); /* Flush output */
2444 gdb_flush (gdb_stdout
);
2446 dbx_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2449 if (LDSYMLEN (pst
)) /* Otherwise it's a dummy */
2451 /* Init stuff necessary for reading in symbols */
2454 old_chain
= make_cleanup (really_free_pendings
, 0);
2455 file_string_table_offset
= FILE_STRING_OFFSET (pst
);
2456 symbol_size
= SYMBOL_SIZE (pst
);
2458 /* Read in this file's symbols */
2459 bfd_seek (pst
->objfile
->obfd
, SYMBOL_OFFSET (pst
), SEEK_SET
);
2460 read_ofile_symtab (pst
);
2461 sort_symtab_syms (pst
->symtab
);
2463 do_cleanups (old_chain
);
2469 /* Read in all of the symbols for a given psymtab for real.
2470 Be verbose about it if the user wants that. */
2473 dbx_psymtab_to_symtab (struct partial_symtab
*pst
)
2482 fprintf_unfiltered (gdb_stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2487 if (LDSYMLEN (pst
) || pst
->number_of_dependencies
)
2489 /* Print the message now, before reading the string table,
2490 to avoid disconcerting pauses. */
2493 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2494 gdb_flush (gdb_stdout
);
2497 sym_bfd
= pst
->objfile
->obfd
;
2499 next_symbol_text_func
= dbx_next_symbol_text
;
2501 dbx_psymtab_to_symtab_1 (pst
);
2503 /* Match with global symbols. This only needs to be done once,
2504 after all of the symtabs and dependencies have been read in. */
2505 scan_file_globals (pst
->objfile
);
2507 /* Finish up the debug error message. */
2509 printf_filtered ("done.\n");
2513 /* Read in a defined section of a specific object file's symbols. */
2516 read_ofile_symtab (struct partial_symtab
*pst
)
2518 register char *namestring
;
2519 register struct external_nlist
*bufp
;
2520 struct internal_nlist nlist
;
2522 unsigned max_symnum
;
2524 struct objfile
*objfile
;
2525 int sym_offset
; /* Offset to start of symbols to read */
2526 int sym_size
; /* Size of symbols to read */
2527 CORE_ADDR text_offset
; /* Start of text segment for symbols */
2528 int text_size
; /* Size of text segment for symbols */
2529 struct section_offsets
*section_offsets
;
2531 objfile
= pst
->objfile
;
2532 sym_offset
= LDSYMOFF (pst
);
2533 sym_size
= LDSYMLEN (pst
);
2534 text_offset
= pst
->textlow
;
2535 text_size
= pst
->texthigh
- pst
->textlow
;
2536 /* This cannot be simply objfile->section_offsets because of
2537 elfstab_offset_sections() which initializes the psymtab section
2538 offsets information in a special way, and that is different from
2539 objfile->section_offsets. */
2540 section_offsets
= pst
->section_offsets
;
2542 current_objfile
= objfile
;
2543 subfile_stack
= NULL
;
2545 stringtab_global
= DBX_STRINGTAB (objfile
);
2546 last_source_file
= NULL
;
2548 abfd
= objfile
->obfd
;
2549 symfile_bfd
= objfile
->obfd
; /* Implicit param to next_text_symbol */
2550 symbuf_end
= symbuf_idx
= 0;
2552 /* It is necessary to actually read one symbol *before* the start
2553 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2554 occurs before the N_SO symbol.
2556 Detecting this in read_dbx_symtab
2557 would slow down initial readin, so we look for it here instead. */
2558 if (!processing_acc_compilation
&& sym_offset
>= (int) symbol_size
)
2560 bfd_seek (symfile_bfd
, sym_offset
- symbol_size
, SEEK_CUR
);
2562 bufp
= &symbuf
[symbuf_idx
++];
2563 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
2564 OBJSTAT (objfile
, n_stabs
++);
2566 namestring
= set_namestring (objfile
, nlist
);
2568 processing_gcc_compilation
= 0;
2569 if (nlist
.n_type
== N_TEXT
)
2571 const char *tempstring
= namestring
;
2573 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
2574 processing_gcc_compilation
= 1;
2575 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
2576 processing_gcc_compilation
= 2;
2577 if (tempstring
[0] == bfd_get_symbol_leading_char (symfile_bfd
))
2579 if (STREQN (tempstring
, "__gnu_compiled", 14))
2580 processing_gcc_compilation
= 2;
2583 /* Try to select a C++ demangling based on the compilation unit
2587 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2588 know whether it will use the old style or v3 mangling. */
2589 if (processing_gcc_compilation
)
2591 if (AUTO_DEMANGLING
)
2593 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
2600 /* The N_SO starting this symtab is the first symbol, so we
2601 better not check the symbol before it. I'm not this can
2602 happen, but it doesn't hurt to check for it. */
2603 bfd_seek (symfile_bfd
, sym_offset
, SEEK_CUR
);
2604 processing_gcc_compilation
= 0;
2607 if (symbuf_idx
== symbuf_end
)
2609 bufp
= &symbuf
[symbuf_idx
];
2610 if (bfd_h_get_8 (abfd
, bufp
->e_type
) != N_SO
)
2611 error ("First symbol in segment of executable not a source symbol");
2613 max_symnum
= sym_size
/ symbol_size
;
2616 symnum
< max_symnum
;
2619 QUIT
; /* Allow this to be interruptable */
2620 if (symbuf_idx
== symbuf_end
)
2622 bufp
= &symbuf
[symbuf_idx
++];
2623 INTERNALIZE_SYMBOL (nlist
, bufp
, abfd
);
2624 OBJSTAT (objfile
, n_stabs
++);
2626 type
= bfd_h_get_8 (abfd
, bufp
->e_type
);
2628 namestring
= set_namestring (objfile
, nlist
);
2632 process_one_symbol (type
, nlist
.n_desc
, nlist
.n_value
,
2633 namestring
, section_offsets
, objfile
);
2635 /* We skip checking for a new .o or -l file; that should never
2636 happen in this routine. */
2637 else if (type
== N_TEXT
)
2639 /* I don't think this code will ever be executed, because
2640 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2641 the N_SO symbol which starts this source file.
2642 However, there is no reason not to accept
2643 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2645 if (STREQ (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
2646 processing_gcc_compilation
= 1;
2647 else if (STREQ (namestring
, GCC2_COMPILED_FLAG_SYMBOL
))
2648 processing_gcc_compilation
= 2;
2651 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2652 know whether it will use the old style or v3 mangling. */
2653 if (AUTO_DEMANGLING
)
2655 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
2659 else if (type
& N_EXT
|| type
== (unsigned char) N_TEXT
2660 || type
== (unsigned char) N_NBTEXT
2663 /* Global symbol: see if we came across a dbx defintion for
2664 a corresponding symbol. If so, store the value. Remove
2665 syms from the chain when their values are stored, but
2666 search the whole chain, as there may be several syms from
2667 different files with the same name. */
2668 /* This is probably not true. Since the files will be read
2669 in one at a time, each reference to a global symbol will
2670 be satisfied in each file as it appears. So we skip this
2676 current_objfile
= NULL
;
2678 /* In a Solaris elf file, this variable, which comes from the
2679 value of the N_SO symbol, will still be 0. Luckily, text_offset,
2680 which comes from pst->textlow is correct. */
2681 if (last_source_start_addr
== 0)
2682 last_source_start_addr
= text_offset
;
2684 /* In reordered executables last_source_start_addr may not be the
2685 lower bound for this symtab, instead use text_offset which comes
2686 from pst->textlow which is correct. */
2687 if (last_source_start_addr
> text_offset
)
2688 last_source_start_addr
= text_offset
;
2690 pst
->symtab
= end_symtab (text_offset
+ text_size
, objfile
, SECT_OFF_TEXT (objfile
));
2692 #if 0 /* OBSOLETE CFront */
2693 // OBSOLETE /* Process items which we had to "process_later" due to dependencies
2694 // OBSOLETE on other stabs. */
2695 // OBSOLETE process_now (objfile);
2696 #endif /* OBSOLETE CFront */
2701 /* This handles a single symbol from the symbol-file, building symbols
2702 into a GDB symtab. It takes these arguments and an implicit argument.
2704 TYPE is the type field of the ".stab" symbol entry.
2705 DESC is the desc field of the ".stab" entry.
2706 VALU is the value field of the ".stab" entry.
2707 NAME is the symbol name, in our address space.
2708 SECTION_OFFSETS is a set of amounts by which the sections of this object
2709 file were relocated when it was loaded into memory.
2710 Note that these section_offsets are not the
2711 objfile->section_offsets but the pst->section_offsets.
2712 All symbols that refer
2713 to memory locations need to be offset by these amounts.
2714 OBJFILE is the object file from which we are reading symbols.
2715 It is used in end_symtab. */
2718 process_one_symbol (int type
, int desc
, CORE_ADDR valu
, char *name
,
2719 struct section_offsets
*section_offsets
,
2720 struct objfile
*objfile
)
2722 #ifdef SUN_FIXED_LBRAC_BUG
2723 /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
2724 to correct the address of N_LBRAC's. If it is not defined, then
2725 we never need to correct the addresses. */
2727 /* This records the last pc address we've seen. We depend on there being
2728 an SLINE or FUN or SO before the first LBRAC, since the variable does
2729 not get reset in between reads of different symbol files. */
2730 static CORE_ADDR last_pc_address
;
2733 register struct context_stack
*new;
2734 /* This remembers the address of the start of a function. It is used
2735 because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
2736 relative to the current function's start address. On systems
2737 other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
2738 used to relocate these symbol types rather than SECTION_OFFSETS. */
2739 static CORE_ADDR function_start_offset
;
2741 /* This holds the address of the start of a function, without the system
2742 peculiarities of function_start_offset. */
2743 static CORE_ADDR last_function_start
;
2745 /* If this is nonzero, we've seen an N_SLINE since the start of the current
2746 function. Initialized to nonzero to assure that last_function_start
2747 is never used uninitialized. */
2748 static int sline_found_in_function
= 1;
2750 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
2751 file. Used to detect the SunPRO solaris compiler. */
2752 static int n_opt_found
;
2754 /* The stab type used for the definition of the last function.
2755 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
2756 static int function_stab_type
= 0;
2758 if (!block_address_function_relative
)
2759 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
2760 function start address, so just use the text offset. */
2761 function_start_offset
= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2763 /* Something is wrong if we see real data before
2764 seeing a source file name. */
2766 if (last_source_file
== NULL
&& type
!= (unsigned char) N_SO
)
2768 /* Ignore any symbols which appear before an N_SO symbol.
2769 Currently no one puts symbols there, but we should deal
2770 gracefully with the case. A complain()t might be in order,
2771 but this should not be an error (). */
2780 if (*name
== '\000')
2782 /* This N_FUN marks the end of a function. This closes off the
2785 if (context_stack_depth
<= 0)
2787 lbrac_mismatch_complaint (symnum
);
2791 record_line (current_subfile
, 0, function_start_offset
+ valu
);
2792 within_function
= 0;
2793 new = pop_context ();
2795 /* Make a block for the local symbols within. */
2796 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2797 new->start_addr
, new->start_addr
+ valu
,
2800 /* May be switching to an assembler file which may not be using
2801 block relative stabs, so reset the offset. */
2802 if (block_address_function_relative
)
2803 function_start_offset
= 0;
2808 sline_found_in_function
= 0;
2810 /* Relocate for dynamic loading */
2811 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2812 valu
= SMASH_TEXT_ADDRESS (valu
);
2813 last_function_start
= valu
;
2815 goto define_a_symbol
;
2818 /* This "symbol" just indicates the start of an inner lexical
2819 context within a function. */
2821 /* Ignore extra outermost context from SunPRO cc and acc. */
2822 if (n_opt_found
&& desc
== 1)
2825 if (block_address_function_relative
)
2826 /* Relocate for Sun ELF acc fn-relative syms. */
2827 valu
+= function_start_offset
;
2829 /* On most machines, the block addresses are relative to the
2830 N_SO, the linker did not relocate them (sigh). */
2831 valu
+= last_source_start_addr
;
2833 #ifdef SUN_FIXED_LBRAC_BUG
2834 if (!SUN_FIXED_LBRAC_BUG
&& valu
< last_pc_address
)
2836 /* Patch current LBRAC pc value to match last handy pc value */
2837 complaint (&symfile_complaints
, "bad block start address patched");
2838 valu
= last_pc_address
;
2841 new = push_context (desc
, valu
);
2845 /* This "symbol" just indicates the end of an inner lexical
2846 context that was started with N_LBRAC. */
2848 /* Ignore extra outermost context from SunPRO cc and acc. */
2849 if (n_opt_found
&& desc
== 1)
2852 if (block_address_function_relative
)
2853 /* Relocate for Sun ELF acc fn-relative syms. */
2854 valu
+= function_start_offset
;
2856 /* On most machines, the block addresses are relative to the
2857 N_SO, the linker did not relocate them (sigh). */
2858 valu
+= last_source_start_addr
;
2860 if (context_stack_depth
<= 0)
2862 lbrac_mismatch_complaint (symnum
);
2866 new = pop_context ();
2867 if (desc
!= new->depth
)
2868 lbrac_mismatch_complaint (symnum
);
2870 /* Some compilers put the variable decls inside of an
2871 LBRAC/RBRAC block. This macro should be nonzero if this
2872 is true. DESC is N_DESC from the N_RBRAC symbol.
2873 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
2874 or the GCC2_COMPILED_SYMBOL. */
2875 #if !defined (VARIABLES_INSIDE_BLOCK)
2876 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2879 /* Can only use new->locals as local symbols here if we're in
2880 gcc or on a machine that puts them before the lbrack. */
2881 if (!VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2883 if (local_symbols
!= NULL
)
2885 /* GCC development snapshots from March to December of
2886 2000 would output N_LSYM entries after N_LBRAC
2887 entries. As a consequence, these symbols are simply
2888 discarded. Complain if this is the case. Note that
2889 there are some compilers which legitimately put local
2890 symbols within an LBRAC/RBRAC block; this complaint
2891 might also help sort out problems in which
2892 VARIABLES_INSIDE_BLOCK is incorrectly defined. */
2893 complaint (&symfile_complaints
,
2894 "misplaced N_LBRAC entry; discarding local symbols which have no enclosing block");
2896 local_symbols
= new->locals
;
2899 if (context_stack_depth
2900 > !VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2902 /* This is not the outermost LBRAC...RBRAC pair in the function,
2903 its local symbols preceded it, and are the ones just recovered
2904 from the context stack. Define the block for them (but don't
2905 bother if the block contains no symbols. Should we complain
2906 on blocks without symbols? I can't think of any useful purpose
2908 if (local_symbols
!= NULL
)
2910 /* Muzzle a compiler bug that makes end < start. (which
2911 compilers? Is this ever harmful?). */
2912 if (new->start_addr
> valu
)
2914 complaint (&symfile_complaints
,
2915 "block start larger than block end");
2916 new->start_addr
= valu
;
2918 /* Make a block for the local symbols within. */
2919 finish_block (0, &local_symbols
, new->old_blocks
,
2920 new->start_addr
, valu
, objfile
);
2925 /* This is the outermost LBRAC...RBRAC pair. There is no
2926 need to do anything; leave the symbols that preceded it
2927 to be attached to the function's own block. We need to
2928 indicate that we just moved outside of the function. */
2929 within_function
= 0;
2932 if (VARIABLES_INSIDE_BLOCK (desc
, processing_gcc_compilation
))
2933 /* Now pop locals of block just finished. */
2934 local_symbols
= new->locals
;
2939 /* This kind of symbol indicates the start of an object file. */
2940 /* Relocate for dynamic loading */
2941 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2945 /* This type of symbol indicates the start of data
2946 for one source file.
2947 Finish the symbol table of the previous source file
2948 (if any) and start accumulating a new symbol table. */
2949 /* Relocate for dynamic loading */
2950 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
2954 #ifdef SUN_FIXED_LBRAC_BUG
2955 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2958 #ifdef PCC_SOL_BROKEN
2959 /* pcc bug, occasionally puts out SO for SOL. */
2960 if (context_stack_depth
> 0)
2962 start_subfile (name
, NULL
);
2966 if (last_source_file
)
2968 /* Check if previous symbol was also an N_SO (with some
2969 sanity checks). If so, that one was actually the directory
2970 name, and the current one is the real file name.
2972 if (previous_stab_code
== (unsigned char) N_SO
)
2974 patch_subfile_names (current_subfile
, name
);
2975 break; /* Ignore repeated SOs */
2977 end_symtab (valu
, objfile
, SECT_OFF_TEXT (objfile
));
2981 /* Null name means this just marks the end of text for this .o file.
2982 Don't start a new symtab in this case. */
2983 if (*name
== '\000')
2986 if (block_address_function_relative
)
2987 function_start_offset
= 0;
2990 start_symtab (name
, NULL
, valu
);
2991 record_debugformat ("stabs");
2995 /* This type of symbol indicates the start of data for
2996 a sub-source-file, one whose contents were copied or
2997 included in the compilation of the main source file
2998 (whose name was given in the N_SO symbol.) */
2999 /* Relocate for dynamic loading */
3000 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
3001 start_subfile (name
, current_subfile
->dirname
);
3006 add_new_header_file (name
, valu
);
3007 start_subfile (name
, current_subfile
->dirname
);
3011 start_subfile (pop_subfile (), current_subfile
->dirname
);
3015 add_old_header_file (name
, valu
);
3019 /* This type of "symbol" really just records
3020 one line-number -- core-address correspondence.
3021 Enter it in the line list for this symbol table. */
3023 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
3024 valu
+= function_start_offset
;
3026 #ifdef SUN_FIXED_LBRAC_BUG
3027 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3029 /* If this is the first SLINE note in the function, record it at
3030 the start of the function instead of at the listed location. */
3031 if (within_function
&& sline_found_in_function
== 0)
3033 record_line (current_subfile
, desc
, last_function_start
);
3034 sline_found_in_function
= 1;
3037 record_line (current_subfile
, desc
, valu
);
3041 common_block_start (name
, objfile
);
3045 common_block_end (objfile
);
3048 /* The following symbol types need to have the appropriate offset added
3049 to their value; then we process symbol definitions in the name. */
3051 case N_STSYM
: /* Static symbol in data seg */
3052 case N_LCSYM
: /* Static symbol in BSS seg */
3053 case N_ROSYM
: /* Static symbol in Read-only data seg */
3054 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
3055 Solaris2's stabs-in-elf makes *most* symbols relative
3056 but leaves a few absolute (at least for Solaris 2.1 and version
3057 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence.
3058 .stab "foo:S...",N_STSYM is absolute (ld relocates it)
3059 .stab "foo:V...",N_STSYM is relative (section base subtracted).
3060 This leaves us no choice but to search for the 'S' or 'V'...
3061 (or pass the whole section_offsets stuff down ONE MORE function
3062 call level, which we really don't want to do). */
3066 /* .o files and NLMs have non-zero text seg offsets, but don't need
3067 their static syms offset in this fashion. XXX - This is really a
3068 crock that should be fixed in the solib handling code so that I
3069 don't have to work around it here. */
3071 if (!symfile_relocatable
)
3073 p
= strchr (name
, ':');
3074 if (p
!= 0 && p
[1] == 'S')
3076 /* The linker relocated it. We don't want to add an
3077 elfstab_offset_sections-type offset, but we *do* want
3078 to add whatever solib.c passed to symbol_file_add as
3079 addr (this is known to affect SunOS4, and I suspect ELF
3080 too). Since elfstab_offset_sections currently does not
3081 muck with the text offset (there is no Ttext.text
3082 symbol), we can get addr from the text offset. If
3083 elfstab_offset_sections ever starts dealing with the
3084 text offset, and we still need to do this, we need to
3085 invent a SECT_OFF_ADDR_KLUDGE or something. */
3086 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
3087 goto define_a_symbol
;
3090 /* Since it's not the kludge case, re-dispatch to the right handler. */
3100 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
3104 case_N_STSYM
: /* Static symbol in data seg */
3105 case N_DSLINE
: /* Source line number, data seg */
3106 valu
+= ANOFFSET (section_offsets
, SECT_OFF_DATA (objfile
));
3107 goto define_a_symbol
;
3109 case_N_LCSYM
: /* Static symbol in BSS seg */
3110 case N_BSLINE
: /* Source line number, bss seg */
3111 /* N_BROWS: overlaps with N_BSLINE */
3112 valu
+= ANOFFSET (section_offsets
, SECT_OFF_BSS (objfile
));
3113 goto define_a_symbol
;
3115 case_N_ROSYM
: /* Static symbol in Read-only data seg */
3116 valu
+= ANOFFSET (section_offsets
, SECT_OFF_RODATA (objfile
));
3117 goto define_a_symbol
;
3119 case N_ENTRY
: /* Alternate entry point */
3120 /* Relocate for dynamic loading */
3121 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
3122 goto define_a_symbol
;
3124 /* The following symbol types we don't know how to process. Handle
3125 them in a "default" way, but complain to people who care. */
3127 case N_CATCH
: /* Exception handler catcher */
3128 case N_EHDECL
: /* Exception handler name */
3129 case N_PC
: /* Global symbol in Pascal */
3130 case N_M2C
: /* Modula-2 compilation unit */
3131 /* N_MOD2: overlaps with N_EHDECL */
3132 case N_SCOPE
: /* Modula-2 scope information */
3133 case N_ECOML
: /* End common (local name) */
3134 case N_NBTEXT
: /* Gould Non-Base-Register symbols??? */
3139 unknown_symtype_complaint (local_hex_string (type
));
3142 /* The following symbol types don't need the address field relocated,
3143 since it is either unused, or is absolute. */
3145 case N_GSYM
: /* Global variable */
3146 case N_NSYMS
: /* Number of symbols (ultrix) */
3147 case N_NOMAP
: /* No map? (ultrix) */
3148 case N_RSYM
: /* Register variable */
3149 case N_DEFD
: /* Modula-2 GNU module dependency */
3150 case N_SSYM
: /* Struct or union element */
3151 case N_LSYM
: /* Local symbol in stack */
3152 case N_PSYM
: /* Parameter variable */
3153 case N_LENG
: /* Length of preceding symbol type */
3157 char *colon_pos
= strchr (name
, ':');
3158 if (colon_pos
== NULL
)
3161 deftype
= colon_pos
[1];
3167 function_stab_type
= type
;
3169 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
3170 /* Deal with the SunPRO 3.0 compiler which omits the address
3171 from N_FUN symbols. */
3173 && valu
== ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
)))
3175 CORE_ADDR minsym_valu
=
3176 find_stab_function_addr (name
, last_source_file
, objfile
);
3178 /* find_stab_function_addr will return 0 if the minimal
3179 symbol wasn't found. (Unfortunately, this might also
3180 be a valid address.) Anyway, if it *does* return 0,
3181 it is likely that the value was set correctly to begin
3183 if (minsym_valu
!= 0)
3188 #ifdef SUN_FIXED_LBRAC_BUG
3189 /* The Sun acc compiler, under SunOS4, puts out
3190 functions with N_GSYM or N_STSYM. The problem is
3191 that the address of the symbol is no good (for N_GSYM
3192 it doesn't even attept an address; for N_STSYM it
3193 puts out an address but then it gets relocated
3194 relative to the data segment, not the text segment).
3195 Currently we can't fix this up later as we do for
3196 some types of symbol in scan_file_globals.
3197 Fortunately we do have a way of finding the address -
3198 we know that the value in last_pc_address is either
3199 the one we want (if we're dealing with the first
3200 function in an object file), or somewhere in the
3201 previous function. This means that we can use the
3202 minimal symbol table to get the address. */
3204 /* Starting with release 3.0, the Sun acc compiler,
3205 under SunOS4, puts out functions with N_FUN and a value
3206 of zero. This gets relocated to the start of the text
3207 segment of the module, which is no good either.
3208 Under SunOS4 we can deal with this as N_SLINE and N_SO
3209 entries contain valid absolute addresses.
3210 Release 3.0 acc also puts out N_OPT entries, which makes
3211 it possible to discern acc from cc or gcc. */
3213 if (type
== N_GSYM
|| type
== N_STSYM
3215 && n_opt_found
&& !block_address_function_relative
))
3217 struct minimal_symbol
*m
;
3218 int l
= colon_pos
- name
;
3220 m
= lookup_minimal_symbol_by_pc (last_pc_address
);
3221 if (m
&& STREQN (SYMBOL_NAME (m
), name
, l
)
3222 && SYMBOL_NAME (m
)[l
] == '\0')
3223 /* last_pc_address was in this function */
3224 valu
= SYMBOL_VALUE (m
);
3225 else if (m
&& SYMBOL_NAME (m
+ 1)
3226 && STREQN (SYMBOL_NAME (m
+ 1), name
, l
)
3227 && SYMBOL_NAME (m
+ 1)[l
] == '\0')
3228 /* last_pc_address was in last function */
3229 valu
= SYMBOL_VALUE (m
+ 1);
3231 /* Not found - use last_pc_address (for finish_block) */
3232 valu
= last_pc_address
;
3235 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3238 if (block_address_function_relative
)
3239 /* For Solaris 2.0 compilers, the block addresses and
3240 N_SLINE's are relative to the start of the
3241 function. On normal systems, and when using gcc on
3242 Solaris 2.0, these addresses are just absolute, or
3243 relative to the N_SO, depending on
3244 BLOCK_ADDRESS_ABSOLUTE. */
3245 function_start_offset
= valu
;
3247 within_function
= 1;
3249 if (context_stack_depth
> 1)
3251 complaint (&symfile_complaints
,
3252 "unmatched N_LBRAC before symtab pos %d", symnum
);
3256 if (context_stack_depth
> 0)
3258 new = pop_context ();
3259 /* Make a block for the local symbols within. */
3260 finish_block (new->name
, &local_symbols
, new->old_blocks
,
3261 new->start_addr
, valu
, objfile
);
3264 new = push_context (0, valu
);
3265 new->name
= define_symbol (valu
, name
, desc
, type
, objfile
);
3269 define_symbol (valu
, name
, desc
, type
, objfile
);
3275 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
3276 for a bunch of other flags, too. Someday we may parse their
3277 flags; for now we ignore theirs and hope they'll ignore ours. */
3278 case N_OPT
: /* Solaris 2: Compiler options */
3281 if (STREQ (name
, GCC2_COMPILED_FLAG_SYMBOL
))
3283 processing_gcc_compilation
= 2;
3284 #if 0 /* Works, but is experimental. -fnf */
3285 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
3286 know whether it will use the old style or v3 mangling. */
3287 if (AUTO_DEMANGLING
)
3289 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
3298 case N_MAIN
: /* Name of main routine. */
3299 /* FIXME: If one has a symbol file with N_MAIN and then replaces
3300 it with a symbol file with "main" and without N_MAIN. I'm
3301 not sure exactly what rule to follow but probably something
3302 like: N_MAIN takes precedence over "main" no matter what
3303 objfile it is in; If there is more than one N_MAIN, choose
3304 the one in the symfile_objfile; If there is more than one
3305 N_MAIN within a given objfile, complain() and choose
3306 arbitrarily. (kingdon) */
3308 set_main_name (name
);
3311 /* The following symbol types can be ignored. */
3312 case N_OBJ
: /* Solaris 2: Object file dir and name */
3313 /* N_UNDF: Solaris 2: file separator mark */
3314 /* N_UNDF: -- we will never encounter it, since we only process one
3315 file's symbols at once. */
3316 case N_ENDM
: /* Solaris 2: End of module */
3317 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
3321 /* '#' is a GNU C extension to allow one symbol to refer to another
3324 Generally this is used so that an alias can refer to its main
3328 /* Initialize symbol reference names and determine if this is
3329 a definition. If symbol reference is being defined, go
3330 ahead and add it. Otherwise, just return sym. */
3335 /* If this stab defines a new reference ID that is not on the
3336 reference list, then put it on the reference list.
3338 We go ahead and advance NAME past the reference, even though
3339 it is not strictly necessary at this time. */
3340 refnum
= symbol_reference_defined (&s
);
3342 if (!ref_search (refnum
))
3343 ref_add (refnum
, 0, name
, valu
);
3348 previous_stab_code
= type
;
3351 /* FIXME: The only difference between this and elfstab_build_psymtabs
3352 is the call to install_minimal_symbols for elf, and the support for
3353 split sections. If the differences are really that small, the code
3354 should be shared. */
3356 /* Scan and build partial symbols for an coff symbol file.
3357 The coff file has already been processed to get its minimal symbols.
3359 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3362 OBJFILE is the object file we are reading symbols from.
3363 ADDR is the address relative to which the symbols are (e.g.
3364 the base address of the text segment).
3365 MAINLINE is true if we are reading the main symbol
3366 table (as opposed to a shared lib or dynamically loaded file).
3367 TEXTADDR is the address of the text section.
3368 TEXTSIZE is the size of the text section.
3369 STABSECTS is the list of .stab sections in OBJFILE.
3370 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3371 .stabstr section exists.
3373 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3374 adjusted for coff details. */
3377 coffstab_build_psymtabs (struct objfile
*objfile
, int mainline
,
3378 CORE_ADDR textaddr
, unsigned int textsize
,
3379 struct stab_section_list
*stabsects
,
3380 file_ptr stabstroffset
, unsigned int stabstrsize
)
3383 bfd
*sym_bfd
= objfile
->obfd
;
3384 char *name
= bfd_get_filename (sym_bfd
);
3385 struct dbx_symfile_info
*info
;
3386 unsigned int stabsize
;
3388 /* There is already a dbx_symfile_info allocated by our caller.
3389 It might even contain some info from the coff symtab to help us. */
3390 info
= objfile
->sym_stab_info
;
3392 DBX_TEXT_ADDR (objfile
) = textaddr
;
3393 DBX_TEXT_SIZE (objfile
) = textsize
;
3395 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3396 DBX_SYMBOL_SIZE (objfile
) = COFF_STABS_SYMBOL_SIZE
;
3397 DBX_STRINGTAB_SIZE (objfile
) = stabstrsize
;
3399 if (stabstrsize
> bfd_get_size (sym_bfd
))
3400 error ("ridiculous string table size: %d bytes", stabstrsize
);
3401 DBX_STRINGTAB (objfile
) = (char *)
3402 obstack_alloc (&objfile
->psymbol_obstack
, stabstrsize
+ 1);
3403 OBJSTAT (objfile
, sz_strtab
+= stabstrsize
+ 1);
3405 /* Now read in the string table in one big gulp. */
3407 val
= bfd_seek (sym_bfd
, stabstroffset
, SEEK_SET
);
3409 perror_with_name (name
);
3410 val
= bfd_bread (DBX_STRINGTAB (objfile
), stabstrsize
, sym_bfd
);
3411 if (val
!= stabstrsize
)
3412 perror_with_name (name
);
3414 stabsread_new_init ();
3415 buildsym_new_init ();
3416 free_header_files ();
3417 init_header_files ();
3419 processing_acc_compilation
= 1;
3421 /* In a coff file, we've already installed the minimal symbols that came
3422 from the coff (non-stab) symbol table, so always act like an
3423 incremental load here. */
3424 if (stabsects
->next
== NULL
)
3426 stabsize
= bfd_section_size (sym_bfd
, stabsects
->section
);
3427 DBX_SYMCOUNT (objfile
) = stabsize
/ DBX_SYMBOL_SIZE (objfile
);
3428 DBX_SYMTAB_OFFSET (objfile
) = stabsects
->section
->filepos
;
3432 struct stab_section_list
*stabsect
;
3434 DBX_SYMCOUNT (objfile
) = 0;
3435 for (stabsect
= stabsects
; stabsect
!= NULL
; stabsect
= stabsect
->next
)
3437 stabsize
= bfd_section_size (sym_bfd
, stabsect
->section
);
3438 DBX_SYMCOUNT (objfile
) += stabsize
/ DBX_SYMBOL_SIZE (objfile
);
3441 DBX_SYMTAB_OFFSET (objfile
) = stabsects
->section
->filepos
;
3443 symbuf_sections
= stabsects
->next
;
3444 symbuf_left
= bfd_section_size (sym_bfd
, stabsects
->section
);
3448 dbx_symfile_read (objfile
, 0);
3451 /* Scan and build partial symbols for an ELF symbol file.
3452 This ELF file has already been processed to get its minimal symbols,
3453 and any DWARF symbols that were in it.
3455 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3458 OBJFILE is the object file we are reading symbols from.
3459 ADDR is the address relative to which the symbols are (e.g.
3460 the base address of the text segment).
3461 MAINLINE is true if we are reading the main symbol
3462 table (as opposed to a shared lib or dynamically loaded file).
3463 STABOFFSET and STABSIZE define the location in OBJFILE where the .stab
3465 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3466 .stabstr section exists.
3468 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3469 adjusted for elf details. */
3472 elfstab_build_psymtabs (struct objfile
*objfile
, int mainline
,
3473 file_ptr staboffset
, unsigned int stabsize
,
3474 file_ptr stabstroffset
, unsigned int stabstrsize
)
3477 bfd
*sym_bfd
= objfile
->obfd
;
3478 char *name
= bfd_get_filename (sym_bfd
);
3479 struct dbx_symfile_info
*info
;
3481 /* There is already a dbx_symfile_info allocated by our caller.
3482 It might even contain some info from the ELF symtab to help us. */
3483 info
= objfile
->sym_stab_info
;
3485 /* Find the first and last text address. dbx_symfile_read seems to
3487 find_text_range (sym_bfd
, objfile
);
3489 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3490 DBX_SYMBOL_SIZE (objfile
) = ELF_STABS_SYMBOL_SIZE
;
3491 DBX_SYMCOUNT (objfile
) = stabsize
/ DBX_SYMBOL_SIZE (objfile
);
3492 DBX_STRINGTAB_SIZE (objfile
) = stabstrsize
;
3493 DBX_SYMTAB_OFFSET (objfile
) = staboffset
;
3495 if (stabstrsize
> bfd_get_size (sym_bfd
))
3496 error ("ridiculous string table size: %d bytes", stabstrsize
);
3497 DBX_STRINGTAB (objfile
) = (char *)
3498 obstack_alloc (&objfile
->psymbol_obstack
, stabstrsize
+ 1);
3499 OBJSTAT (objfile
, sz_strtab
+= stabstrsize
+ 1);
3501 /* Now read in the string table in one big gulp. */
3503 val
= bfd_seek (sym_bfd
, stabstroffset
, SEEK_SET
);
3505 perror_with_name (name
);
3506 val
= bfd_bread (DBX_STRINGTAB (objfile
), stabstrsize
, sym_bfd
);
3507 if (val
!= stabstrsize
)
3508 perror_with_name (name
);
3510 stabsread_new_init ();
3511 buildsym_new_init ();
3512 free_header_files ();
3513 init_header_files ();
3514 install_minimal_symbols (objfile
);
3516 processing_acc_compilation
= 1;
3518 /* In an elf file, we've already installed the minimal symbols that came
3519 from the elf (non-stab) symbol table, so always act like an
3520 incremental load here. */
3521 dbx_symfile_read (objfile
, 0);
3524 /* Scan and build partial symbols for a file with special sections for stabs
3525 and stabstrings. The file has already been processed to get its minimal
3526 symbols, and any other symbols that might be necessary to resolve GSYMs.
3528 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3531 OBJFILE is the object file we are reading symbols from.
3532 ADDR is the address relative to which the symbols are (e.g. the base address
3533 of the text segment).
3534 MAINLINE is true if we are reading the main symbol table (as opposed to a
3535 shared lib or dynamically loaded file).
3536 STAB_NAME is the name of the section that contains the stabs.
3537 STABSTR_NAME is the name of the section that contains the stab strings.
3539 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */
3542 stabsect_build_psymtabs (struct objfile
*objfile
, int mainline
, char *stab_name
,
3543 char *stabstr_name
, char *text_name
)
3546 bfd
*sym_bfd
= objfile
->obfd
;
3547 char *name
= bfd_get_filename (sym_bfd
);
3549 asection
*stabstrsect
;
3550 asection
*text_sect
;
3552 stabsect
= bfd_get_section_by_name (sym_bfd
, stab_name
);
3553 stabstrsect
= bfd_get_section_by_name (sym_bfd
, stabstr_name
);
3559 error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)",
3560 stab_name
, stabstr_name
);
3562 objfile
->sym_stab_info
= (struct dbx_symfile_info
*)
3563 xmalloc (sizeof (struct dbx_symfile_info
));
3564 memset (objfile
->sym_stab_info
, 0, sizeof (struct dbx_symfile_info
));
3566 text_sect
= bfd_get_section_by_name (sym_bfd
, text_name
);
3568 error ("Can't find %s section in symbol file", text_name
);
3569 DBX_TEXT_ADDR (objfile
) = bfd_section_vma (sym_bfd
, text_sect
);
3570 DBX_TEXT_SIZE (objfile
) = bfd_section_size (sym_bfd
, text_sect
);
3572 DBX_SYMBOL_SIZE (objfile
) = sizeof (struct external_nlist
);
3573 DBX_SYMCOUNT (objfile
) = bfd_section_size (sym_bfd
, stabsect
)
3574 / DBX_SYMBOL_SIZE (objfile
);
3575 DBX_STRINGTAB_SIZE (objfile
) = bfd_section_size (sym_bfd
, stabstrsect
);
3576 DBX_SYMTAB_OFFSET (objfile
) = stabsect
->filepos
; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */
3578 if (DBX_STRINGTAB_SIZE (objfile
) > bfd_get_size (sym_bfd
))
3579 error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile
));
3580 DBX_STRINGTAB (objfile
) = (char *)
3581 obstack_alloc (&objfile
->psymbol_obstack
, DBX_STRINGTAB_SIZE (objfile
) + 1);
3582 OBJSTAT (objfile
, sz_strtab
+= DBX_STRINGTAB_SIZE (objfile
) + 1);
3584 /* Now read in the string table in one big gulp. */
3586 val
= bfd_get_section_contents (sym_bfd
, /* bfd */
3587 stabstrsect
, /* bfd section */
3588 DBX_STRINGTAB (objfile
), /* input buffer */
3589 0, /* offset into section */
3590 DBX_STRINGTAB_SIZE (objfile
)); /* amount to read */
3593 perror_with_name (name
);
3595 stabsread_new_init ();
3596 buildsym_new_init ();
3597 free_header_files ();
3598 init_header_files ();
3599 install_minimal_symbols (objfile
);
3601 /* Now, do an incremental load */
3603 processing_acc_compilation
= 1;
3604 dbx_symfile_read (objfile
, 0);
3607 static struct sym_fns aout_sym_fns
=
3609 bfd_target_aout_flavour
,
3610 dbx_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3611 dbx_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3612 dbx_symfile_read
, /* sym_read: read a symbol file into symtab */
3613 dbx_symfile_finish
, /* sym_finish: finished with file, cleanup */
3614 default_symfile_offsets
, /* sym_offsets: parse user's offsets to internal form */
3615 NULL
/* next: pointer to next struct sym_fns */
3619 _initialize_dbxread (void)
3621 add_symtab_fns (&aout_sym_fns
);