1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-2004, 2007-2012 Free Software Foundation, Inc.
3 Derived from coffread.c, dbxread.c, and a lot of hacking.
4 Contributed by IBM Corporation.
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 3 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, see <http://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
27 #include "gdb_string.h"
29 #include <sys/param.h>
30 #ifdef HAVE_SYS_FILE_H
35 #include "coff/internal.h"
36 #include "libcoff.h" /* FIXME, internal data from BFD */
37 #include "coff/xcoff.h"
39 #include "coff/rs6000.h"
40 #include "xcoffread.h"
44 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
48 #include "stabsread.h"
49 #include "expression.h"
50 #include "complaints.h"
53 #include "gdb-stabs.h"
55 /* For interface with stabsread.c. */
56 #include "aout/stab_gnu.h"
59 /* We put a pointer to this structure in the read_symtab_private field
65 /* First symbol number for this file. */
69 /* Number of symbols in the section of the symbol table devoted to
70 this file's symbols (actually, the section bracketed may contain
71 more than just this file's symbols). If numsyms is 0, the only
72 reason for this thing's existence is the dependency list. Nothing
73 else will happen when it is read in. */
77 /* Position of the start of the line number information for this
79 unsigned int lineno_off;
82 /* Remember what we deduced to be the source language of this psymtab. */
84 static enum language psymtab_language = language_unknown;
87 /* Simplified internal version of coff symbol table information. */
92 int c_symnum; /* Symbol number of this entry. */
93 int c_naux; /* 0 if syment only, 1 if syment + auxent. */
95 unsigned char c_sclass;
100 /* Last function's saved coff symbol `cs'. */
102 static struct coff_symbol fcn_cs_saved;
104 static bfd *symfile_bfd;
106 /* Core address of start and end of text of current source file.
107 This is calculated from the first function seen after a C_FILE
111 static CORE_ADDR cur_src_end_addr;
113 /* Core address of the end of the first object file. */
115 static CORE_ADDR first_object_file_end;
117 /* Initial symbol-table-debug-string vector length. */
119 #define INITIAL_STABVECTOR_LENGTH 40
121 /* Nonzero if within a function (so symbols should be local,
122 if nothing says specifically). */
126 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
127 there is any reason not to just use a #define, but might as well
128 ask BFD for the size and store it here, I guess. */
130 static unsigned local_symesz;
132 struct coff_symfile_info
134 file_ptr min_lineno_offset; /* Where in file lowest line#s are. */
135 file_ptr max_lineno_offset; /* 1+last byte of line#s in file. */
137 /* Pointer to the string table. */
140 /* Pointer to debug section. */
143 /* Pointer to the a.out symbol table. */
146 /* Number of symbols in symtbl. */
149 /* Offset in data section to TOC anchor. */
150 CORE_ADDR toc_offset;
153 /* XCOFF names for dwarf sections. There is no compressed sections. */
155 static const struct dwarf2_debug_sections dwarf2_xcoff_names = {
157 { ".dwabrev", NULL },
160 { NULL, NULL }, /* debug_macinfo */
161 { NULL, NULL }, /* debug_macro */
163 { ".dwrnges", NULL },
164 { NULL, NULL }, /* debug_types */
165 { ".dwframe", NULL },
166 { NULL, NULL }, /* eh_frame */
167 { NULL, NULL }, /* gdb_index */
172 bf_notfound_complaint (void)
174 complaint (&symfile_complaints,
175 _("line numbers off, `.bf' symbol not found"));
179 ef_complaint (int arg1)
181 complaint (&symfile_complaints,
182 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1);
186 eb_complaint (int arg1)
188 complaint (&symfile_complaints,
189 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1);
192 static void xcoff_initial_scan (struct objfile *, int);
194 static void scan_xcoff_symtab (struct objfile *);
196 static char *xcoff_next_symbol_text (struct objfile *);
198 static void record_include_begin (struct coff_symbol *);
201 enter_line_range (struct subfile *, unsigned, unsigned,
202 CORE_ADDR, CORE_ADDR, unsigned *);
204 static void init_stringtab (bfd *, file_ptr, struct objfile *);
206 static void xcoff_symfile_init (struct objfile *);
208 static void xcoff_new_init (struct objfile *);
210 static void xcoff_symfile_finish (struct objfile *);
212 static void xcoff_symfile_offsets (struct objfile *,
213 struct section_addr_info *addrs);
215 static char *coff_getfilename (union internal_auxent *, struct objfile *);
217 static void read_symbol (struct internal_syment *, int);
219 static int read_symbol_lineno (int);
221 static CORE_ADDR read_symbol_nvalue (int);
223 static struct symbol *process_xcoff_symbol (struct coff_symbol *,
226 static void read_xcoff_symtab (struct partial_symtab *);
229 static void add_stab_to_list (char *, struct pending_stabs **);
232 static int compare_lte (const void *, const void *);
234 static struct linetable *arrange_linetable (struct linetable *);
236 static void record_include_end (struct coff_symbol *);
238 static void process_linenos (CORE_ADDR, CORE_ADDR);
241 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
243 static int secnum_to_section (int, struct objfile *);
244 static asection *secnum_to_bfd_section (int, struct objfile *);
246 struct find_targ_sec_arg
251 struct objfile *objfile;
254 static void find_targ_sec (bfd *, asection *, void *);
257 find_targ_sec (bfd *abfd, asection *sect, void *obj)
259 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
260 struct objfile *objfile = args->objfile;
262 if (sect->target_index == args->targ_index)
264 /* This is the section. Figure out what SECT_OFF_* code it is. */
265 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
266 *args->resultp = SECT_OFF_TEXT (objfile);
267 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
268 *args->resultp = SECT_OFF_DATA (objfile);
270 *args->resultp = sect->index;
271 *args->bfd_sect = sect;
275 /* Search all BFD sections for the section whose target_index is
276 equal to N_SCNUM. Set *BFD_SECT to that section. The section's
277 associated index in the objfile's section_offset table is also
280 If no match is found, *BFD_SECT is set to NULL, and *SECNUM
281 is set to the text section's number. */
284 xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile,
285 asection **bfd_sect, int *secnum)
287 struct find_targ_sec_arg args;
289 args.targ_index = n_scnum;
290 args.resultp = secnum;
291 args.bfd_sect = bfd_sect;
292 args.objfile = objfile;
295 *secnum = SECT_OFF_TEXT (objfile);
297 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
300 /* Return the section number (SECT_OFF_*) that N_SCNUM points to. */
303 secnum_to_section (int n_scnum, struct objfile *objfile)
308 xcoff_secnum_to_sections (n_scnum, objfile, &ignored, &secnum);
312 /* Return the BFD section that N_SCNUM points to. */
315 secnum_to_bfd_section (int n_scnum, struct objfile *objfile)
320 xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &ignored);
324 /* add a given stab string into given stab vector. */
329 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
331 if (*stabvector == NULL)
333 *stabvector = (struct pending_stabs *)
334 xmalloc (sizeof (struct pending_stabs) +
335 INITIAL_STABVECTOR_LENGTH * sizeof (char *));
336 (*stabvector)->count = 0;
337 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
339 else if ((*stabvector)->count >= (*stabvector)->length)
341 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
342 *stabvector = (struct pending_stabs *)
343 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
344 (*stabvector)->length * sizeof (char *));
346 (*stabvector)->stab[(*stabvector)->count++] = stabname;
351 /* Linenos are processed on a file-by-file basis.
355 1) xlc (IBM's native c compiler) postpones static function code
356 emission to the end of a compilation unit. This way it can
357 determine if those functions (statics) are needed or not, and
358 can do some garbage collection (I think). This makes line
359 numbers and corresponding addresses unordered, and we end up
360 with a line table like:
377 and that breaks gdb's binary search on line numbers, if the
378 above table is not sorted on line numbers. And that sort
379 should be on function based, since gcc can emit line numbers
382 10 0x100 - for the init/test part of a for stmt.
385 10 0x400 - for the increment part of a for stmt.
387 arrange_linetable() will do this sorting.
389 2) aix symbol table might look like:
391 c_file // beginning of a new file
392 .bi // beginning of include file
393 .ei // end of include file
397 basically, .bi/.ei pairs do not necessarily encapsulate
398 their scope. They need to be recorded, and processed later
399 on when we come the end of the compilation unit.
400 Include table (inclTable) and process_linenos() handle
406 /* compare line table entry addresses. */
409 compare_lte (const void *lte1p, const void *lte2p)
411 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
412 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
414 return lte1->pc - lte2->pc;
417 /* Given a line table with function entries are marked, arrange its
418 functions in ascending order and strip off function entry markers
419 and return it in a newly created table. If the old one is good
420 enough, return the old one. */
421 /* FIXME: I think all this stuff can be replaced by just passing
422 sort_linevec = 1 to end_symtab. */
424 static struct linetable *
425 arrange_linetable (struct linetable *oldLineTb)
427 int ii, jj, newline, /* new line count */
428 function_count; /* # of functions */
430 struct linetable_entry *fentry; /* function entry vector */
431 int fentry_size; /* # of function entries */
432 struct linetable *newLineTb; /* new line table */
434 #define NUM_OF_FUNCTIONS 20
436 fentry_size = NUM_OF_FUNCTIONS;
437 fentry = (struct linetable_entry *)
438 xmalloc (fentry_size * sizeof (struct linetable_entry));
440 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
442 if (oldLineTb->item[ii].line == 0)
443 { /* Function entry found. */
444 if (function_count >= fentry_size)
445 { /* Make sure you have room. */
447 fentry = (struct linetable_entry *)
449 fentry_size * sizeof (struct linetable_entry));
451 fentry[function_count].line = ii;
452 fentry[function_count].pc = oldLineTb->item[ii].pc;
457 if (function_count == 0)
462 else if (function_count > 1)
463 qsort (fentry, function_count,
464 sizeof (struct linetable_entry), compare_lte);
466 /* Allocate a new line table. */
467 newLineTb = (struct linetable *)
469 (sizeof (struct linetable) +
470 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
472 /* If line table does not start with a function beginning, copy up until
476 if (oldLineTb->item[0].line != 0)
478 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
479 newLineTb->item[newline] = oldLineTb->item[newline];
481 /* Now copy function lines one by one. */
483 for (ii = 0; ii < function_count; ++ii)
485 for (jj = fentry[ii].line + 1;
486 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
488 newLineTb->item[newline] = oldLineTb->item[jj];
491 newLineTb->nitems = oldLineTb->nitems - function_count;
495 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
496 following `IncludeChain'. At the end of each symtab (end_symtab),
497 we will determine if we should create additional symtab's to
498 represent if (the include files. */
501 typedef struct _inclTable
503 char *name; /* include filename */
505 /* Offsets to the line table. end points to the last entry which is
506 part of this include file. */
509 struct subfile *subfile;
510 unsigned funStartLine; /* Start line # of its function. */
514 #define INITIAL_INCLUDE_TABLE_LENGTH 20
515 static InclTable *inclTable; /* global include table */
516 static int inclIndx; /* last entry to table */
517 static int inclLength; /* table length */
518 static int inclDepth; /* nested include depth */
520 static void allocate_include_entry (void);
523 record_include_begin (struct coff_symbol *cs)
527 /* In xcoff, we assume include files cannot be nested (not in .c files
528 of course, but in corresponding .s files.). */
530 /* This can happen with old versions of GCC.
531 GCC 2.3.3-930426 does not exhibit this on a test case which
532 a user said produced the message for him. */
533 complaint (&symfile_complaints, _("Nested C_BINCL symbols"));
537 allocate_include_entry ();
539 inclTable[inclIndx].name = cs->c_name;
540 inclTable[inclIndx].begin = cs->c_value;
544 record_include_end (struct coff_symbol *cs)
550 complaint (&symfile_complaints, _("Mismatched C_BINCL/C_EINCL pair"));
553 allocate_include_entry ();
555 pTbl = &inclTable[inclIndx];
556 pTbl->end = cs->c_value;
563 allocate_include_entry (void)
565 if (inclTable == NULL)
567 inclTable = (InclTable *)
568 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
570 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
571 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
574 else if (inclIndx >= inclLength)
576 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
577 inclTable = (InclTable *)
578 xrealloc (inclTable, sizeof (InclTable) * inclLength);
579 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
580 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
584 /* Global variable to pass the psymtab down to all the routines involved
585 in psymtab to symtab processing. */
586 static struct partial_symtab *this_symtab_psymtab;
588 /* given the start and end addresses of a compilation unit (or a csect,
589 at times) process its lines and create appropriate line vectors. */
592 process_linenos (CORE_ADDR start, CORE_ADDR end)
595 file_ptr max_offset =
596 ((struct coff_symfile_info *) this_symtab_psymtab->objfile
597 ->deprecated_sym_private)->max_lineno_offset;
599 /* subfile structure for the main compilation unit. */
600 struct subfile main_subfile;
602 /* In the main source file, any time we see a function entry, we
603 reset this variable to function's absolute starting line number.
604 All the following line numbers in the function are relative to
605 this, and we record absolute line numbers in record_line(). */
607 unsigned int main_source_baseline = 0;
612 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
614 goto return_after_cleanup;
616 memset (&main_subfile, '\0', sizeof (main_subfile));
619 /* All source lines were in the main source file. None in include
622 enter_line_range (&main_subfile, offset, 0, start, end,
623 &main_source_baseline);
627 /* There was source with line numbers in include files. */
630 coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
631 main_source_baseline = 0;
633 for (ii = 0; ii < inclIndx; ++ii)
635 struct subfile *tmpSubfile;
637 /* If there is main file source before include file, enter it. */
638 if (offset < inclTable[ii].begin)
641 (&main_subfile, offset, inclTable[ii].begin - linesz,
642 start, 0, &main_source_baseline);
645 if (strcmp (inclTable[ii].name, last_source_file) == 0)
647 /* The entry in the include table refers to the main source
648 file. Add the lines to the main subfile. */
650 main_source_baseline = inclTable[ii].funStartLine;
652 (&main_subfile, inclTable[ii].begin, inclTable[ii].end,
653 start, 0, &main_source_baseline);
654 inclTable[ii].subfile = &main_subfile;
658 /* Have a new subfile for the include file. */
660 tmpSubfile = inclTable[ii].subfile =
661 (struct subfile *) xmalloc (sizeof (struct subfile));
663 memset (tmpSubfile, '\0', sizeof (struct subfile));
664 firstLine = &(inclTable[ii].funStartLine);
666 /* Enter include file's lines now. */
667 enter_line_range (tmpSubfile, inclTable[ii].begin,
668 inclTable[ii].end, start, 0, firstLine);
671 if (offset <= inclTable[ii].end)
672 offset = inclTable[ii].end + linesz;
675 /* All the include files' line have been processed at this point. Now,
676 enter remaining lines of the main file, if any left. */
677 if (offset < max_offset + 1 - linesz)
679 enter_line_range (&main_subfile, offset, 0, start, end,
680 &main_source_baseline);
684 /* Process main file's line numbers. */
685 if (main_subfile.line_vector)
687 struct linetable *lineTb, *lv;
689 lv = main_subfile.line_vector;
691 /* Line numbers are not necessarily ordered. xlc compilation will
692 put static function to the end. */
694 lineTb = arrange_linetable (lv);
697 current_subfile->line_vector = (struct linetable *)
698 xrealloc (lv, (sizeof (struct linetable)
699 + lv->nitems * sizeof (struct linetable_entry)));
704 current_subfile->line_vector = lineTb;
707 current_subfile->line_vector_length =
708 current_subfile->line_vector->nitems;
711 /* Now, process included files' line numbers. */
713 for (ii = 0; ii < inclIndx; ++ii)
715 if (inclTable[ii].subfile != ((struct subfile *) &main_subfile)
716 && (inclTable[ii].subfile)->line_vector) /* Useless if!!!
719 struct linetable *lineTb, *lv;
721 lv = (inclTable[ii].subfile)->line_vector;
723 /* Line numbers are not necessarily ordered. xlc compilation will
724 put static function to the end. */
726 lineTb = arrange_linetable (lv);
730 /* For the same include file, we might want to have more than one
731 subfile. This happens if we have something like:
739 while foo.h including code in it. (stupid but possible)
740 Since start_subfile() looks at the name and uses an
741 existing one if finds, we need to provide a fake name and
745 start_subfile (inclTable[ii].name, (char *) 0);
748 /* Pick a fake name that will produce the same results as this
749 one when passed to deduce_language_from_filename. Kludge on
751 char *fakename = strrchr (inclTable[ii].name, '.');
753 if (fakename == NULL)
755 start_subfile (fakename, (char *) 0);
756 xfree (current_subfile->name);
758 current_subfile->name = xstrdup (inclTable[ii].name);
763 current_subfile->line_vector =
764 (struct linetable *) xrealloc
765 (lv, (sizeof (struct linetable)
766 + lv->nitems * sizeof (struct linetable_entry)));
772 current_subfile->line_vector = lineTb;
775 current_subfile->line_vector_length =
776 current_subfile->line_vector->nitems;
777 start_subfile (pop_subfile (), (char *) 0);
781 return_after_cleanup:
783 /* We don't want to keep alloc/free'ing the global include file table. */
786 /* Start with a fresh subfile structure for the next file. */
787 memset (&main_subfile, '\0', sizeof (struct subfile));
791 aix_process_linenos (void)
793 /* There is no linenos to read if there are only dwarf info. */
794 if (this_symtab_psymtab == NULL)
797 /* Process line numbers and enter them into line vector. */
798 process_linenos (last_source_start_addr, cur_src_end_addr);
802 /* Enter a given range of lines into the line vector.
803 can be called in the following two ways:
804 enter_line_range (subfile, beginoffset, endoffset,
805 startaddr, 0, firstLine) or
806 enter_line_range (subfile, beginoffset, 0,
807 startaddr, endaddr, firstLine)
809 endoffset points to the last line table entry that we should pay
813 enter_line_range (struct subfile *subfile, unsigned beginoffset,
814 unsigned endoffset, /* offsets to line table */
815 CORE_ADDR startaddr, /* offsets to line table */
816 CORE_ADDR endaddr, unsigned *firstLine)
818 struct objfile *objfile = this_symtab_psymtab->objfile;
819 struct gdbarch *gdbarch = get_objfile_arch (objfile);
820 unsigned int curoffset;
823 struct internal_lineno int_lnno;
824 unsigned int limit_offset;
828 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
830 curoffset = beginoffset;
832 ((struct coff_symfile_info *) objfile->deprecated_sym_private)
837 if (endoffset >= limit_offset)
839 complaint (&symfile_complaints,
840 _("Bad line table offset in C_EINCL directive"));
843 limit_offset = endoffset;
848 abfd = objfile->obfd;
849 linesz = coff_data (abfd)->local_linesz;
850 ext_lnno = alloca (linesz);
852 while (curoffset <= limit_offset)
854 bfd_seek (abfd, curoffset, SEEK_SET);
855 bfd_bread (ext_lnno, linesz, abfd);
856 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
858 /* Find the address this line represents. */
859 addr = (int_lnno.l_lnno
860 ? int_lnno.l_addr.l_paddr
861 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
862 addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
864 if (addr < startaddr || (endaddr && addr >= endaddr))
867 if (int_lnno.l_lnno == 0)
869 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
870 record_line (subfile, 0, gdbarch_addr_bits_remove (gdbarch, addr));
874 record_line (subfile, *firstLine + int_lnno.l_lnno,
875 gdbarch_addr_bits_remove (gdbarch, addr));
881 /* Save the vital information for use when closing off the current file.
882 NAME is the file name the symbols came from, START_ADDR is the first
883 text address for the file, and SIZE is the number of bytes of text. */
885 #define complete_symtab(name, start_addr) { \
886 last_source_file = xstrdup (name); \
887 last_source_start_addr = start_addr; \
891 /* Refill the symbol table input buffer
892 and set the variables that control fetching entries from it.
893 Reports an error if no data available.
894 This function can read past the end of the symbol table
895 (into the string table) but this does no harm. */
897 /* Create a new minimal symbol (using prim_record_minimal_symbol_and_info).
901 NAME - the symbol's name (but if NAME starts with a period, that
902 leading period is discarded).
903 ADDRESS - the symbol's address.
904 MS_TYPE - the symbol's type.
905 N_SCNUM - the symbol's XCOFF section number.
906 OBJFILE - the objfile associated with the minimal symbol. */
909 record_minimal_symbol (const char *name, CORE_ADDR address,
910 enum minimal_symbol_type ms_type,
912 struct objfile *objfile)
914 struct find_targ_sec_arg args;
921 xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &secnum);
922 prim_record_minimal_symbol_and_info (name, address, ms_type,
923 secnum, bfd_sect, objfile);
926 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
927 nested. At any given time, a symbol can only be in one static block.
928 This is the base address of current static block, zero if non exists. */
930 static int static_block_base = 0;
932 /* Section number for the current static block. */
934 static int static_block_section = -1;
936 /* true if space for symbol name has been allocated. */
938 static int symname_alloced = 0;
940 /* Next symbol to read. Pointer into raw seething symbol table. */
942 static char *raw_symbol;
944 /* This is the function which stabsread.c calls to get symbol
948 xcoff_next_symbol_text (struct objfile *objfile)
950 struct internal_syment symbol;
953 /* FIXME: is this the same as the passed arg? */
954 if (this_symtab_psymtab)
955 objfile = this_symtab_psymtab->objfile;
957 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
960 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
962 /* Return something which points to '\0' and hope the symbol reading
963 code does something reasonable. */
966 else if (symbol.n_sclass & 0x80)
968 retval = ((struct coff_symfile_info *)
969 objfile->deprecated_sym_private)->debugsec
971 raw_symbol += coff_data (objfile->obfd)->local_symesz;
976 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
978 /* Return something which points to '\0' and hope the symbol reading
979 code does something reasonable. */
985 /* Read symbols for a given partial symbol table. */
988 read_xcoff_symtab (struct partial_symtab *pst)
990 struct objfile *objfile = pst->objfile;
991 bfd *abfd = objfile->obfd;
992 char *raw_auxptr; /* Pointer to first raw aux entry for sym. */
994 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl;
996 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec;
997 const char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
999 struct internal_syment symbol[1];
1000 union internal_auxent main_aux;
1001 struct coff_symbol cs[1];
1002 CORE_ADDR file_start_addr = 0;
1003 CORE_ADDR file_end_addr = 0;
1005 int next_file_symnum = -1;
1006 unsigned int max_symnum;
1007 int just_started = 1;
1009 int fcn_start_addr = 0;
1011 struct coff_symbol fcn_stab_saved = { 0 };
1013 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1014 union internal_auxent fcn_aux_saved = main_aux;
1015 struct context_stack *new;
1017 char *filestring = " _start_ "; /* Name of the current file. */
1019 const char *last_csect_name; /* Last seen csect's name. */
1021 this_symtab_psymtab = pst;
1023 /* Get the appropriate COFF "constants" related to the file we're
1025 local_symesz = coff_data (abfd)->local_symesz;
1027 last_source_file = NULL;
1028 last_csect_name = 0;
1031 start_symtab (filestring, (char *) NULL, file_start_addr);
1032 record_debugformat (debugfmt);
1033 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
1035 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
1036 first_object_file_end = 0;
1039 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl
1040 + symnum * local_symesz;
1042 while (symnum < max_symnum)
1044 QUIT; /* make this command interruptable. */
1046 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1047 /* read one symbol into `cs' structure. After processing the
1048 whole symbol table, only string table will be kept in memory,
1049 symbol table and debug section of xcoff will be freed. Thus
1050 we can mark symbols with names in string table as
1055 /* Swap and align the symbol into a reasonable C structure. */
1056 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1058 cs->c_symnum = symnum;
1059 cs->c_naux = symbol->n_numaux;
1060 if (symbol->n_zeroes)
1062 symname_alloced = 0;
1063 /* We must use the original, unswapped, name here so the name field
1064 pointed to by cs->c_name will persist throughout xcoffread. If
1065 we use the new field, it gets overwritten for each symbol. */
1066 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
1067 /* If it's exactly E_SYMNMLEN characters long it isn't
1069 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1073 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
1074 strncpy (p, cs->c_name, E_SYMNMLEN);
1075 p[E_SYMNMLEN] = '\0';
1077 symname_alloced = 1;
1080 else if (symbol->n_sclass & 0x80)
1082 cs->c_name = debugsec + symbol->n_offset;
1083 symname_alloced = 0;
1087 /* in string table */
1088 cs->c_name = strtbl + (int) symbol->n_offset;
1089 symname_alloced = 1;
1091 cs->c_value = symbol->n_value;
1092 cs->c_sclass = symbol->n_sclass;
1093 cs->c_secnum = symbol->n_scnum;
1094 cs->c_type = (unsigned) symbol->n_type;
1096 raw_symbol += local_symesz;
1099 /* Save addr of first aux entry. */
1100 raw_auxptr = raw_symbol;
1102 /* Skip all the auxents associated with this symbol. */
1103 for (ii = symbol->n_numaux; ii; --ii)
1105 raw_symbol += coff_data (abfd)->local_auxesz;
1110 /* if symbol name starts with ".$" or "$", ignore it. */
1111 if (cs->c_name[0] == '$'
1112 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1115 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1117 if (last_source_file)
1119 pst->symtab = end_symtab (cur_src_end_addr, objfile,
1120 SECT_OFF_TEXT (objfile));
1125 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1126 record_debugformat (debugfmt);
1127 cur_src_end_addr = first_object_file_end;
1128 /* Done with all files, everything from here on is globals. */
1131 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1134 /* Dealing with a symbol with a csect entry. */
1136 #define CSECT(PP) ((PP)->x_csect)
1137 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1138 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1139 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1140 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1142 /* Convert the auxent to something we can access. */
1143 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1144 0, cs->c_naux, &main_aux);
1146 switch (CSECT_SMTYP (&main_aux))
1150 /* Ignore all external references. */
1154 /* A section description. */
1156 switch (CSECT_SCLAS (&main_aux))
1162 /* A program csect is seen. We have to allocate one
1163 symbol table for each program csect. Normally gdb
1164 prefers one symtab for each source file. In case
1165 of AIX, one source file might include more than one
1166 [PR] csect, and they don't have to be adjacent in
1167 terms of the space they occupy in memory. Thus, one
1168 single source file might get fragmented in the
1169 memory and gdb's file start and end address
1170 approach does not work! GCC (and I think xlc) seem
1171 to put all the code in the unnamed program csect. */
1173 if (last_csect_name)
1175 complete_symtab (filestring, file_start_addr);
1176 cur_src_end_addr = file_end_addr;
1177 end_symtab (file_end_addr, objfile,
1178 SECT_OFF_TEXT (objfile));
1181 /* Give all csects for this source file the same
1183 start_symtab (filestring, NULL, (CORE_ADDR) 0);
1184 record_debugformat (debugfmt);
1187 /* If this is the very first csect seen,
1188 basically `__start'. */
1191 first_object_file_end
1192 = cs->c_value + CSECT_LEN (&main_aux);
1197 cs->c_value + ANOFFSET (objfile->section_offsets,
1198 SECT_OFF_TEXT (objfile));
1199 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1201 if (cs->c_name && (cs->c_name[0] == '.' || cs->c_name[0] == '@'))
1202 last_csect_name = cs->c_name;
1206 /* All other symbols are put into the minimal symbol
1219 /* Ignore the symbol. */
1227 switch (CSECT_SCLAS (&main_aux))
1230 /* a function entry point. */
1231 function_entry_point:
1233 fcn_start_addr = cs->c_value;
1235 /* save the function header info, which will be used
1236 when `.bf' is seen. */
1238 fcn_aux_saved = main_aux;
1242 /* shared library function trampoline code entry point. */
1246 /* The symbols often have the same names as debug symbols for
1247 functions, and confuse lookup_symbol. */
1251 /* xlc puts each variable in a separate csect, so we get
1252 an XTY_SD for each variable. But gcc puts several
1253 variables in a csect, so that each variable only gets
1254 an XTY_LD. This will typically be XMC_RW; I suspect
1255 XMC_RO and XMC_BS might be possible too.
1256 These variables are put in the minimal symbol table
1263 /* Common symbols are put into the minimal symbol table only. */
1271 /* If explicitly specified as a function, treat is as one. This check
1272 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1273 after the above CSECT check. */
1274 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1276 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1277 0, cs->c_naux, &main_aux);
1278 goto function_entry_point;
1281 switch (cs->c_sclass)
1285 /* c_value field contains symnum of next .file entry in table
1286 or symnum of first global after last .file. */
1288 next_file_symnum = cs->c_value;
1290 /* Complete symbol table for last object file containing
1291 debugging information. */
1293 /* Whether or not there was a csect in the previous file, we
1294 have to call `end_stabs' and `start_stabs' to reset
1295 type_vector, line_vector, etc. structures. */
1297 complete_symtab (filestring, file_start_addr);
1298 cur_src_end_addr = file_end_addr;
1299 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1302 /* XCOFF, according to the AIX 3.2 documentation, puts the
1303 filename in cs->c_name. But xlc 1.3.0.2 has decided to
1304 do things the standard COFF way and put it in the auxent.
1305 We use the auxent if the symbol is ".file" and an auxent
1306 exists, otherwise use the symbol itself. Simple
1308 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1310 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1311 0, cs->c_naux, &main_aux);
1312 filestring = coff_getfilename (&main_aux, objfile);
1315 filestring = cs->c_name;
1318 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1319 record_debugformat (debugfmt);
1320 last_csect_name = 0;
1322 /* reset file start and end addresses. A compilation unit
1323 with no text (only data) should have zero file
1325 file_start_addr = file_end_addr = 0;
1329 fcn_stab_saved = *cs;
1333 if (strcmp (cs->c_name, ".bf") == 0)
1335 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1336 SECT_OFF_TEXT (objfile));
1338 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1339 0, cs->c_naux, &main_aux);
1341 within_function = 1;
1343 new = push_context (0, fcn_start_addr + off);
1345 new->name = define_symbol
1346 (fcn_cs_saved.c_value + off,
1347 fcn_stab_saved.c_name, 0, 0, objfile);
1348 if (new->name != NULL)
1349 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1351 else if (strcmp (cs->c_name, ".ef") == 0)
1353 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1354 0, cs->c_naux, &main_aux);
1356 /* The value of .ef is the address of epilogue code;
1357 not useful for gdb. */
1358 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1359 contains number of lines to '}' */
1361 if (context_stack_depth <= 0)
1362 { /* We attempted to pop an empty context stack. */
1363 ef_complaint (cs->c_symnum);
1364 within_function = 0;
1367 new = pop_context ();
1368 /* Stack must be empty now. */
1369 if (context_stack_depth > 0 || new == NULL)
1371 ef_complaint (cs->c_symnum);
1372 within_function = 0;
1376 finish_block (new->name, &local_symbols, new->old_blocks,
1378 (fcn_cs_saved.c_value
1379 + fcn_aux_saved.x_sym.x_misc.x_fsize
1380 + ANOFFSET (objfile->section_offsets,
1381 SECT_OFF_TEXT (objfile))),
1383 within_function = 0;
1388 /* Begin static block. */
1390 struct internal_syment symbol;
1392 read_symbol (&symbol, cs->c_value);
1393 static_block_base = symbol.n_value;
1394 static_block_section =
1395 secnum_to_section (symbol.n_scnum, objfile);
1400 /* End of static block. */
1401 static_block_base = 0;
1402 static_block_section = -1;
1413 complaint (&symfile_complaints,
1414 _("Unrecognized storage class %d."),
1429 /* beginning of include file */
1430 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1431 order. Thus, when wee see them, we might not know enough info
1432 to process them. Thus, we'll be saving them into a table
1433 (inclTable) and postpone their processing. */
1435 record_include_begin (cs);
1439 /* End of include file. */
1440 /* See the comment after case C_BINCL. */
1441 record_include_end (cs);
1445 if (strcmp (cs->c_name, ".bb") == 0)
1448 new = push_context (depth,
1450 + ANOFFSET (objfile->section_offsets,
1451 SECT_OFF_TEXT (objfile))));
1453 else if (strcmp (cs->c_name, ".eb") == 0)
1455 if (context_stack_depth <= 0)
1456 { /* We attempted to pop an empty context stack. */
1457 eb_complaint (cs->c_symnum);
1460 new = pop_context ();
1461 if (depth-- != new->depth)
1463 eb_complaint (cs->c_symnum);
1466 if (local_symbols && context_stack_depth > 0)
1468 /* Make a block for the local symbols within. */
1469 finish_block (new->name, &local_symbols, new->old_blocks,
1472 + ANOFFSET (objfile->section_offsets,
1473 SECT_OFF_TEXT (objfile))),
1476 local_symbols = new->locals;
1481 process_xcoff_symbol (cs, objfile);
1486 if (last_source_file)
1490 complete_symtab (filestring, file_start_addr);
1491 cur_src_end_addr = file_end_addr;
1492 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1493 /* When reading symbols for the last C_FILE of the objfile, try
1494 to make sure that we set pst->symtab to the symtab for the
1495 file, not to the _globals_ symtab. I'm not sure whether this
1496 actually works right or when/if it comes up. */
1497 if (pst->symtab == NULL)
1503 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1504 (SYMBOL2) = (struct symbol *) \
1505 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1506 *(SYMBOL2) = *(SYMBOL1);
1509 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1510 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), \
1511 &objfile->objfile_obstack))
1514 /* process one xcoff symbol. */
1516 static struct symbol *
1517 process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
1519 struct symbol onesymbol;
1520 struct symbol *sym = &onesymbol;
1521 struct symbol *sym2 = NULL;
1527 if (cs->c_secnum < 0)
1529 /* The value is a register number, offset within a frame, etc.,
1530 and does not get relocated. */
1536 sec = secnum_to_section (cs->c_secnum, objfile);
1537 off = ANOFFSET (objfile->section_offsets, sec);
1544 memset (sym, '\0', sizeof (struct symbol));
1546 /* default assumptions */
1547 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1548 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1549 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1551 if (ISFCN (cs->c_type))
1553 /* At this point, we don't know the type of the function. This
1554 will be patched with the type from its stab entry later on in
1555 patch_block_stabs (), unless the file was compiled without -g. */
1557 SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced));
1558 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
1560 SYMBOL_CLASS (sym) = LOC_BLOCK;
1561 SYMBOL_DUP (sym, sym2);
1563 if (cs->c_sclass == C_EXT)
1564 add_symbol_to_list (sym2, &global_symbols);
1565 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1566 add_symbol_to_list (sym2, &file_symbols);
1570 /* In case we can't figure out the type, provide default. */
1571 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_data_symbol;
1573 switch (cs->c_sclass)
1576 /* The values of functions and global symbols are now resolved
1577 via the global_sym_chain in stabsread.c. */
1579 if (fcn_cs_saved.c_sclass == C_EXT)
1580 add_stab_to_list (name, &global_stabs);
1582 add_stab_to_list (name, &file_stabs);
1586 add_stab_to_list (name, &global_stabs);
1591 common_block_start (cs->c_name, objfile);
1595 common_block_end (objfile);
1599 complaint (&symfile_complaints, _("Unexpected storage class: %d"),
1612 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1615 SYMBOL_SECTION (sym) = sec;
1622 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1623 all statics and we need to distinguish file-scope versus
1624 function-scope using within_function. We do this by
1625 changing the string we pass to define_symbol to use 'S'
1626 where we need to, which is not necessarily super-clean,
1627 but seems workable enough. */
1632 pp = strchr (name, ':');
1637 if (*pp == 'V' && !within_function)
1639 sym = define_symbol ((cs->c_value
1640 + ANOFFSET (objfile->section_offsets,
1641 static_block_section)),
1642 cs->c_name, 0, 0, objfile);
1645 SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1646 SYMBOL_SECTION (sym) = static_block_section;
1655 /* Extract the file name from the aux entry of a C_FILE symbol.
1656 Result is in static storage and is only good for temporary use. */
1659 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1661 static char buffer[BUFSIZ];
1663 if (aux_entry->x_file.x_n.x_zeroes == 0)
1664 strcpy (buffer, ((struct coff_symfile_info *)
1665 objfile->deprecated_sym_private)->strtbl
1666 + aux_entry->x_file.x_n.x_offset);
1669 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1670 buffer[FILNMLEN] = '\0';
1675 /* Set *SYMBOL to symbol number symno in symtbl. */
1677 read_symbol (struct internal_syment *symbol, int symno)
1680 = ((struct coff_symfile_info *)
1681 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl_num_syms;
1682 char *stbl = ((struct coff_symfile_info *)
1683 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl;
1685 if (symno < 0 || symno >= nsyms)
1687 complaint (&symfile_complaints, _("Invalid symbol offset"));
1688 symbol->n_value = 0;
1689 symbol->n_scnum = -1;
1692 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1693 stbl + (symno * local_symesz),
1697 /* Get value corresponding to symbol number symno in symtbl. */
1700 read_symbol_nvalue (int symno)
1702 struct internal_syment symbol[1];
1704 read_symbol (symbol, symno);
1705 return symbol->n_value;
1709 /* Find the address of the function corresponding to symno, where
1710 symno is the symbol pointed to by the linetable. */
1713 read_symbol_lineno (int symno)
1715 struct objfile *objfile = this_symtab_psymtab->objfile;
1716 int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd);
1718 struct coff_symfile_info *info =
1719 (struct coff_symfile_info *)objfile->deprecated_sym_private;
1720 int nsyms = info->symtbl_num_syms;
1721 char *stbl = info->symtbl;
1722 char *strtbl = info->strtbl;
1724 struct internal_syment symbol[1];
1725 union internal_auxent main_aux[1];
1729 bf_notfound_complaint ();
1733 /* Note that just searching for a short distance (e.g. 50 symbols)
1734 is not enough, at least in the following case.
1737 [many .stabx entries]
1738 [a few functions, referring to foo]
1742 What happens here is that the assembler moves the .stabx entries
1743 to right before the ".bf" for foo, but the symbol for "foo" is before
1744 all the stabx entries. See PR gdb/2222. */
1746 /* Maintaining a table of .bf entries might be preferable to this search.
1747 If I understand things correctly it would need to be done only for
1748 the duration of a single psymtab to symtab conversion. */
1749 while (symno < nsyms)
1751 bfd_coff_swap_sym_in (symfile_bfd,
1752 stbl + (symno * local_symesz), symbol);
1753 if (symbol->n_sclass == C_FCN)
1755 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1757 if (strcmp (name, ".bf") == 0)
1760 symno += symbol->n_numaux + 1;
1763 bf_notfound_complaint ();
1767 /* Take aux entry and return its lineno. */
1769 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1770 symbol->n_type, symbol->n_sclass,
1771 0, symbol->n_numaux, main_aux);
1773 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1776 /* Support for line number handling. */
1778 /* This function is called for every section; it finds the outer limits
1779 * of the line table (minimum and maximum file offset) so that the
1780 * mainline code can read the whole thing for efficiency.
1783 find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo)
1785 struct coff_symfile_info *info;
1787 file_ptr offset, maxoff;
1789 count = asect->lineno_count;
1791 if (strcmp (asect->name, ".text") != 0 || count == 0)
1794 size = count * coff_data (abfd)->local_linesz;
1795 info = (struct coff_symfile_info *) vpinfo;
1796 offset = asect->line_filepos;
1797 maxoff = offset + size;
1799 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1800 info->min_lineno_offset = offset;
1802 if (maxoff > info->max_lineno_offset)
1803 info->max_lineno_offset = maxoff;
1806 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1809 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1811 struct cleanup *old_chain;
1820 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1825 /* Read in all partial symtabs on which this one is dependent. */
1826 for (i = 0; i < pst->number_of_dependencies; i++)
1827 if (!pst->dependencies[i]->readin)
1829 /* Inform about additional files that need to be read in. */
1832 fputs_filtered (" ", gdb_stdout);
1834 fputs_filtered ("and ", gdb_stdout);
1836 printf_filtered ("%s...", pst->dependencies[i]->filename);
1837 wrap_here (""); /* Flush output */
1838 gdb_flush (gdb_stdout);
1840 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1843 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1845 /* Init stuff necessary for reading in symbols. */
1848 old_chain = make_cleanup (really_free_pendings, 0);
1850 read_xcoff_symtab (pst);
1852 do_cleanups (old_chain);
1858 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1860 /* Read in all of the symbols for a given psymtab for real.
1861 Be verbose about it if the user wants that. */
1864 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1874 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1879 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1880 || pst->number_of_dependencies)
1882 /* Print the message now, before reading the string table,
1883 to avoid disconcerting pauses. */
1886 printf_filtered ("Reading in symbols for %s...", pst->filename);
1887 gdb_flush (gdb_stdout);
1890 sym_bfd = pst->objfile->obfd;
1892 next_symbol_text_func = xcoff_next_symbol_text;
1894 xcoff_psymtab_to_symtab_1 (pst);
1896 /* Match with global symbols. This only needs to be done once,
1897 after all of the symtabs and dependencies have been read in. */
1898 scan_file_globals (pst->objfile);
1900 /* Finish up the debug error message. */
1902 printf_filtered ("done.\n");
1907 xcoff_new_init (struct objfile *objfile)
1909 stabsread_new_init ();
1910 buildsym_new_init ();
1913 /* Do initialization in preparation for reading symbols from OBJFILE.
1915 We will only be called if this is an XCOFF or XCOFF-like file.
1916 BFD handles figuring out the format of the file, and code in symfile.c
1917 uses BFD's determination to vector to us. */
1920 xcoff_symfile_init (struct objfile *objfile)
1922 /* Allocate struct to keep track of the symfile. */
1923 objfile->deprecated_sym_private
1924 = xmalloc (sizeof (struct coff_symfile_info));
1926 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1927 find this causes a significant slowdown in gdb then we could
1928 set it in the debug symbol readers only when necessary. */
1929 objfile->flags |= OBJF_REORDERED;
1931 init_entry_point_info (objfile);
1934 /* Perform any local cleanups required when we are done with a particular
1935 objfile. I.E, we are in the process of discarding all symbol information
1936 for an objfile, freeing up all memory held for it, and unlinking the
1937 objfile struct from the global list of known objfiles. */
1940 xcoff_symfile_finish (struct objfile *objfile)
1942 if (objfile->deprecated_sym_private != NULL)
1944 xfree (objfile->deprecated_sym_private);
1947 /* Start with a fresh include table for the next objfile. */
1953 inclIndx = inclLength = inclDepth = 0;
1955 dwarf2_free_objfile (objfile);
1960 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1964 unsigned char lengthbuf[4];
1967 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1970 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1971 error (_("cannot seek to string table in %s: %s"),
1972 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1974 val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd);
1975 length = bfd_h_get_32 (abfd, lengthbuf);
1977 /* If no string table is needed, then the file may end immediately
1978 after the symbols. Just return with `strtbl' set to NULL. */
1980 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1983 /* Allocate string table from objfile_obstack. We will need this table
1984 as long as we have its symbol table around. */
1986 strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length);
1987 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1990 /* Copy length buffer, the first byte is usually zero and is
1991 used for stabs with a name length of zero. */
1992 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1993 if (length == sizeof lengthbuf)
1996 val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd);
1998 if (val != length - sizeof lengthbuf)
1999 error (_("cannot read string table from %s: %s"),
2000 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
2001 if (strtbl[length - 1] != '\0')
2002 error (_("bad symbol file: string table "
2003 "does not end with null character"));
2008 /* If we have not yet seen a function for this psymtab, this is 0. If we
2009 have seen one, it is the offset in the line numbers of the line numbers
2011 static unsigned int first_fun_line_offset;
2013 /* Allocate and partially fill a partial symtab. It will be
2014 completely filled at the end of the symbol list.
2016 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2017 is the address relative to which its symbols are (incremental) or 0
2020 static struct partial_symtab *
2021 xcoff_start_psymtab (struct objfile *objfile,
2022 const char *filename, int first_symnum,
2023 struct partial_symbol **global_syms,
2024 struct partial_symbol **static_syms)
2026 struct partial_symtab *result =
2027 start_psymtab_common (objfile, objfile->section_offsets,
2029 /* We fill in textlow later. */
2031 global_syms, static_syms);
2033 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2034 sizeof (struct symloc));
2035 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
2036 result->read_symtab = xcoff_psymtab_to_symtab;
2038 /* Deduce the source language from the filename for this psymtab. */
2039 psymtab_language = deduce_language_from_filename (filename);
2044 /* Close off the current usage of PST.
2045 Returns PST, or NULL if the partial symtab was empty and thrown away.
2047 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2049 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2050 are the information for includes and dependencies. */
2052 static struct partial_symtab *
2053 xcoff_end_psymtab (struct partial_symtab *pst, const char **include_list,
2054 int num_includes, int capping_symbol_number,
2055 struct partial_symtab **dependency_list,
2056 int number_dependencies, int textlow_not_set)
2059 struct objfile *objfile = pst->objfile;
2061 if (capping_symbol_number != -1)
2062 ((struct symloc *) pst->read_symtab_private)->numsyms =
2063 capping_symbol_number
2064 - ((struct symloc *) pst->read_symtab_private)->first_symnum;
2065 ((struct symloc *) pst->read_symtab_private)->lineno_off =
2066 first_fun_line_offset;
2067 first_fun_line_offset = 0;
2068 pst->n_global_syms = objfile->global_psymbols.next
2069 - (objfile->global_psymbols.list + pst->globals_offset);
2070 pst->n_static_syms = objfile->static_psymbols.next
2071 - (objfile->static_psymbols.list + pst->statics_offset);
2073 pst->number_of_dependencies = number_dependencies;
2074 if (number_dependencies)
2076 pst->dependencies = (struct partial_symtab **)
2077 obstack_alloc (&objfile->objfile_obstack,
2078 number_dependencies * sizeof (struct partial_symtab *));
2079 memcpy (pst->dependencies, dependency_list,
2080 number_dependencies * sizeof (struct partial_symtab *));
2083 pst->dependencies = 0;
2085 for (i = 0; i < num_includes; i++)
2087 struct partial_symtab *subpst =
2088 allocate_psymtab (include_list[i], objfile);
2090 subpst->section_offsets = pst->section_offsets;
2091 subpst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2092 sizeof (struct symloc));
2093 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2094 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2095 subpst->textlow = 0;
2096 subpst->texthigh = 0;
2098 /* We could save slight bits of space by only making one of these,
2099 shared by the entire set of include files. FIXME-someday. */
2100 subpst->dependencies = (struct partial_symtab **)
2101 obstack_alloc (&objfile->objfile_obstack,
2102 sizeof (struct partial_symtab *));
2103 subpst->dependencies[0] = pst;
2104 subpst->number_of_dependencies = 1;
2106 subpst->globals_offset =
2107 subpst->n_global_syms =
2108 subpst->statics_offset =
2109 subpst->n_static_syms = 0;
2113 subpst->read_symtab = pst->read_symtab;
2116 sort_pst_symbols (pst);
2118 if (num_includes == 0
2119 && number_dependencies == 0
2120 && pst->n_global_syms == 0
2121 && pst->n_static_syms == 0)
2123 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2124 it is on the obstack, but we can forget to chain it on the list. */
2125 /* Empty psymtabs happen as a result of header files which don't have
2126 any symbols in them. There can be a lot of them. */
2128 discard_psymtab (pst);
2130 /* Indicate that psymtab was thrown away. */
2131 pst = (struct partial_symtab *) NULL;
2136 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2137 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2138 the symbol and its auxents. */
2141 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2142 const char **name, char **raw, unsigned int *symnump,
2143 struct objfile *objfile)
2145 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2146 if (symbol->n_zeroes)
2148 /* If it's exactly E_SYMNMLEN characters long it isn't
2150 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2152 /* FIXME: wastes memory for symbols which we don't end up putting
2153 into the minimal symbols. */
2156 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
2157 strncpy (p, symbol->n_name, E_SYMNMLEN);
2158 p[E_SYMNMLEN] = '\0';
2162 /* Point to the unswapped name as that persists as long as the
2164 *name = ((struct external_syment *) *raw)->e.e_name;
2166 else if (symbol->n_sclass & 0x80)
2168 *name = ((struct coff_symfile_info *)
2169 objfile->deprecated_sym_private)->debugsec + symbol->n_offset;
2173 *name = ((struct coff_symfile_info *)
2174 objfile->deprecated_sym_private)->strtbl + symbol->n_offset;
2177 *raw += coff_data (objfile->obfd)->local_symesz;
2178 if (symbol->n_numaux > 0)
2180 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2181 symbol->n_sclass, 0, symbol->n_numaux, aux);
2183 *symnump += symbol->n_numaux;
2184 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2189 function_outside_compilation_unit_complaint (const char *arg1)
2191 complaint (&symfile_complaints,
2192 _("function `%s' appears to be defined "
2193 "outside of all compilation units"),
2198 scan_xcoff_symtab (struct objfile *objfile)
2200 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2201 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
2202 const char *filestring = NULL;
2204 const char *namestring;
2205 int past_first_source_file = 0;
2210 /* Current partial symtab */
2211 struct partial_symtab *pst;
2213 /* List of current psymtab's include files. */
2214 const char **psymtab_include_list;
2215 int includes_allocated;
2218 /* Index within current psymtab dependency list. */
2219 struct partial_symtab **dependency_list;
2220 int dependencies_used, dependencies_allocated;
2223 struct internal_syment symbol;
2224 union internal_auxent main_aux[5];
2225 unsigned int ssymnum;
2227 const char *last_csect_name = NULL; /* Last seen csect's name and value. */
2228 CORE_ADDR last_csect_val = 0;
2229 int last_csect_sec = 0;
2230 int misc_func_recorded = 0; /* true if any misc. function. */
2231 int textlow_not_set = 1;
2233 pst = (struct partial_symtab *) 0;
2235 includes_allocated = 30;
2237 psymtab_include_list = (const char **) alloca (includes_allocated *
2238 sizeof (const char *));
2240 dependencies_allocated = 30;
2241 dependencies_used = 0;
2243 (struct partial_symtab **) alloca (dependencies_allocated *
2244 sizeof (struct partial_symtab *));
2246 last_source_file = NULL;
2248 abfd = objfile->obfd;
2249 next_symbol_text_func = xcoff_next_symbol_text;
2251 sraw_symbol = ((struct coff_symfile_info *)
2252 objfile->deprecated_sym_private)->symtbl;
2253 nsyms = ((struct coff_symfile_info *)
2254 objfile->deprecated_sym_private)->symtbl_num_syms;
2256 while (ssymnum < nsyms)
2262 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2263 sclass = symbol.n_sclass;
2270 /* The CSECT auxent--always the last auxent. */
2271 union internal_auxent csect_aux;
2272 unsigned int symnum_before = ssymnum;
2274 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2276 if (symbol.n_numaux > 1)
2278 bfd_coff_swap_aux_in
2280 sraw_symbol - coff_data (abfd)->local_symesz,
2283 symbol.n_numaux - 1,
2288 csect_aux = main_aux[0];
2290 /* If symbol name starts with ".$" or "$", ignore it. */
2291 if (namestring[0] == '$'
2292 || (namestring[0] == '.' && namestring[1] == '$'))
2295 switch (csect_aux.x_csect.x_smtyp & 0x7)
2298 switch (csect_aux.x_csect.x_smclas)
2301 if (last_csect_name)
2303 /* If no misc. function recorded in the last
2304 seen csect, enter it as a function. This
2305 will take care of functions like strcmp()
2308 if (!misc_func_recorded)
2310 record_minimal_symbol
2311 (last_csect_name, last_csect_val,
2312 mst_text, last_csect_sec, objfile);
2313 misc_func_recorded = 1;
2318 /* We have to allocate one psymtab for
2319 each program csect, because their text
2320 sections need not be adjacent. */
2322 (pst, psymtab_include_list, includes_used,
2323 symnum_before, dependency_list,
2324 dependencies_used, textlow_not_set);
2326 dependencies_used = 0;
2327 /* Give all psymtabs for this source file the same
2329 pst = xcoff_start_psymtab
2333 objfile->global_psymbols.next,
2334 objfile->static_psymbols.next);
2337 /* Activate the misc_func_recorded mechanism for
2338 compiler- and linker-generated CSECTs like ".strcmp"
2340 if (namestring && (namestring[0] == '.'
2341 || namestring[0] == '@'))
2343 last_csect_name = namestring;
2344 last_csect_val = symbol.n_value;
2345 last_csect_sec = symbol.n_scnum;
2350 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2352 if (highval > pst->texthigh)
2353 pst->texthigh = highval;
2354 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2355 pst->textlow = symbol.n_value;
2357 misc_func_recorded = 0;
2362 /* Data variables are recorded in the minimal symbol
2363 table, except for section symbols. */
2364 if (*namestring != '.')
2365 prim_record_minimal_symbol_and_info
2366 (namestring, symbol.n_value,
2367 sclass == C_HIDEXT ? mst_file_data : mst_data,
2368 secnum_to_section (symbol.n_scnum, objfile),
2369 secnum_to_bfd_section (symbol.n_scnum, objfile),
2375 warning (_("More than one XMC_TC0 symbol found."));
2376 toc_offset = symbol.n_value;
2378 /* Make TOC offset relative to start address of
2380 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2382 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
2386 /* These symbols tell us where the TOC entry for a
2387 variable is, not the variable itself. */
2396 switch (csect_aux.x_csect.x_smclas)
2399 /* A function entry point. */
2401 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2402 first_fun_line_offset =
2403 main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
2405 record_minimal_symbol
2406 (namestring, symbol.n_value,
2407 sclass == C_HIDEXT ? mst_file_text : mst_text,
2408 symbol.n_scnum, objfile);
2409 misc_func_recorded = 1;
2414 /* shared library function trampoline code entry
2417 /* record trampoline code entries as
2418 mst_solib_trampoline symbol. When we lookup mst
2419 symbols, we will choose mst_text over
2420 mst_solib_trampoline. */
2421 record_minimal_symbol
2422 (namestring, symbol.n_value,
2423 mst_solib_trampoline, symbol.n_scnum, objfile);
2424 misc_func_recorded = 1;
2428 /* The symbols often have the same names as
2429 debug symbols for functions, and confuse
2435 /* xlc puts each variable in a separate csect,
2436 so we get an XTY_SD for each variable. But
2437 gcc puts several variables in a csect, so
2438 that each variable only gets an XTY_LD. We
2439 still need to record them. This will
2440 typically be XMC_RW; I suspect XMC_RO and
2441 XMC_BS might be possible too. */
2442 if (*namestring != '.')
2443 prim_record_minimal_symbol_and_info
2444 (namestring, symbol.n_value,
2445 sclass == C_HIDEXT ? mst_file_data : mst_data,
2446 secnum_to_section (symbol.n_scnum, objfile),
2447 secnum_to_bfd_section (symbol.n_scnum, objfile),
2454 switch (csect_aux.x_csect.x_smclas)
2458 /* Common variables are recorded in the minimal symbol
2459 table, except for section symbols. */
2460 if (*namestring != '.')
2461 prim_record_minimal_symbol_and_info
2462 (namestring, symbol.n_value,
2463 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2464 secnum_to_section (symbol.n_scnum, objfile),
2465 secnum_to_bfd_section (symbol.n_scnum, objfile),
2478 unsigned int symnum_before;
2480 symnum_before = ssymnum;
2481 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2484 /* See if the last csect needs to be recorded. */
2486 if (last_csect_name && !misc_func_recorded)
2488 /* If no misc. function recorded in the last seen csect, enter
2489 it as a function. This will take care of functions like
2490 strcmp() compiled by xlc. */
2492 record_minimal_symbol (last_csect_name, last_csect_val,
2493 mst_text, last_csect_sec, objfile);
2494 misc_func_recorded = 1;
2499 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2500 symnum_before, dependency_list,
2501 dependencies_used, textlow_not_set);
2503 dependencies_used = 0;
2505 first_fun_line_offset = 0;
2507 /* XCOFF, according to the AIX 3.2 documentation, puts the
2508 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2509 do things the standard COFF way and put it in the auxent.
2510 We use the auxent if the symbol is ".file" and an auxent
2511 exists, otherwise use the symbol itself. */
2512 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2514 filestring = coff_getfilename (&main_aux[0], objfile);
2517 filestring = namestring;
2519 pst = xcoff_start_psymtab (objfile,
2522 objfile->global_psymbols.next,
2523 objfile->static_psymbols.next);
2524 last_csect_name = NULL;
2530 complaint (&symfile_complaints,
2531 _("Storage class %d not recognized during scan"),
2536 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2537 to handle only the C_FUN and C_EXT. */
2552 /* C_EINCL means we are switching back to the main file. But there
2553 is no reason to care; the only thing we want to know about
2554 includes is the names of all the included (.h) files. */
2559 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2563 /* I don't think the name of the common block (as opposed to the
2564 variables within it) is something which is user visible
2572 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2573 so C_LSYM would appear to be only for locals. */
2579 /* We probably could save a few instructions by assuming that
2580 C_LSYM, C_PSYM, etc., never have auxents. */
2581 int naux1 = symbol.n_numaux + 1;
2584 sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2590 /* Mark down an include file in the current psymtab. */
2591 enum language tmp_language;
2593 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2596 tmp_language = deduce_language_from_filename (namestring);
2598 /* Only change the psymtab's language if we've learned
2599 something useful (eg. tmp_language is not language_unknown).
2600 In addition, to match what start_subfile does, never change
2602 if (tmp_language != language_unknown
2603 && (tmp_language != language_c
2604 || psymtab_language != language_cplus))
2605 psymtab_language = tmp_language;
2607 /* In C++, one may expect the same filename to come round many
2608 times, when code is coming alternately from the main file
2609 and from inline functions in other files. So I check to see
2610 if this is a file we've seen before -- either the main
2611 source file, or a previously included file.
2613 This seems to be a lot of time to be spending on N_SOL, but
2614 things like "break c-exp.y:435" need to work (I
2615 suppose the psymtab_include_list could be hashed or put
2616 in a binary tree, if profiling shows this is a major hog). */
2617 if (pst && strcmp (namestring, pst->filename) == 0)
2623 for (i = 0; i < includes_used; i++)
2624 if (strcmp (namestring, psymtab_include_list[i]) == 0)
2632 psymtab_include_list[includes_used++] = namestring;
2633 if (includes_used >= includes_allocated)
2635 const char **orig = psymtab_include_list;
2637 psymtab_include_list = (const char **)
2638 alloca ((includes_allocated *= 2) *
2639 sizeof (const char *));
2640 memcpy (psymtab_include_list, orig,
2641 includes_used * sizeof (const char *));
2646 /* The value of the C_FUN is not the address of the function (it
2647 appears to be the address before linking), but as long as it
2648 is smaller than the actual address, then find_pc_partial_function
2649 will use the minimal symbols instead. I hope. */
2658 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2661 p = strchr (namestring, ':');
2663 continue; /* Not a debugging symbol. */
2665 /* Main processing section for debugging symbols which
2666 the initial read through the symbol tables needs to worry
2667 about. If we reach this point, the symbol which we are
2668 considering is definitely one we are interested in.
2669 p must also contain the (valid) index into the namestring
2670 which indicates the debugging type symbol. */
2675 symbol.n_value += ANOFFSET (objfile->section_offsets,
2676 SECT_OFF_DATA (objfile));
2678 if (gdbarch_static_transform_name_p (gdbarch))
2679 namestring = gdbarch_static_transform_name
2680 (gdbarch, namestring);
2682 add_psymbol_to_list (namestring, p - namestring, 1,
2683 VAR_DOMAIN, LOC_STATIC,
2684 &objfile->static_psymbols,
2686 psymtab_language, objfile);
2690 symbol.n_value += ANOFFSET (objfile->section_offsets,
2691 SECT_OFF_DATA (objfile));
2692 /* The addresses in these entries are reported to be
2693 wrong. See the code that reads 'G's for symtabs. */
2694 add_psymbol_to_list (namestring, p - namestring, 1,
2695 VAR_DOMAIN, LOC_STATIC,
2696 &objfile->global_psymbols,
2698 psymtab_language, objfile);
2702 /* When a 'T' entry is defining an anonymous enum, it
2703 may have a name which is the empty string, or a
2704 single space. Since they're not really defining a
2705 symbol, those shouldn't go in the partial symbol
2706 table. We do pick up the elements of such enums at
2707 'check_enum:', below. */
2708 if (p >= namestring + 2
2709 || (p == namestring + 1
2710 && namestring[0] != ' '))
2712 add_psymbol_to_list (namestring, p - namestring, 1,
2713 STRUCT_DOMAIN, LOC_TYPEDEF,
2714 &objfile->static_psymbols,
2716 psymtab_language, objfile);
2719 /* Also a typedef with the same name. */
2720 add_psymbol_to_list (namestring, p - namestring, 1,
2721 VAR_DOMAIN, LOC_TYPEDEF,
2722 &objfile->static_psymbols,
2724 psymtab_language, objfile);
2731 if (p != namestring) /* a name is there, not just :T... */
2733 add_psymbol_to_list (namestring, p - namestring, 1,
2734 VAR_DOMAIN, LOC_TYPEDEF,
2735 &objfile->static_psymbols,
2737 psymtab_language, objfile);
2740 /* If this is an enumerated type, we need to
2741 add all the enum constants to the partial symbol
2742 table. This does not cover enums without names, e.g.
2743 "enum {a, b} c;" in C, but fortunately those are
2744 rare. There is no way for GDB to find those from the
2745 enum type without spending too much time on it. Thus
2746 to solve this problem, the compiler needs to put out the
2747 enum in a nameless type. GCC2 does this. */
2749 /* We are looking for something of the form
2750 <name> ":" ("t" | "T") [<number> "="] "e"
2751 {<constant> ":" <value> ","} ";". */
2753 /* Skip over the colon and the 't' or 'T'. */
2755 /* This type may be given a number. Also, numbers can come
2756 in pairs like (0,26). Skip over it. */
2757 while ((*p >= '0' && *p <= '9')
2758 || *p == '(' || *p == ',' || *p == ')'
2764 /* The aix4 compiler emits extra crud before the
2768 /* Skip over the type (?). */
2772 /* Skip over the colon. */
2776 /* We have found an enumerated type. */
2777 /* According to comments in read_enum_type
2778 a comma could end it instead of a semicolon.
2779 I don't know where that happens.
2781 while (*p && *p != ';' && *p != ',')
2785 /* Check for and handle cretinous dbx symbol name
2787 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
2788 p = next_symbol_text (objfile);
2790 /* Point to the character after the name
2791 of the enum constant. */
2792 for (q = p; *q && *q != ':'; q++)
2794 /* Note that the value doesn't matter for
2795 enum constants in psymtabs, just in symtabs. */
2796 add_psymbol_to_list (p, q - p, 1,
2797 VAR_DOMAIN, LOC_CONST,
2798 &objfile->static_psymbols, 0,
2799 0, psymtab_language, objfile);
2800 /* Point past the name. */
2802 /* Skip over the value. */
2803 while (*p && *p != ',')
2805 /* Advance past the comma. */
2813 /* Constant, e.g. from "const" in Pascal. */
2814 add_psymbol_to_list (namestring, p - namestring, 1,
2815 VAR_DOMAIN, LOC_CONST,
2816 &objfile->static_psymbols, symbol.n_value,
2817 0, psymtab_language, objfile);
2823 int name_len = p - namestring;
2824 char *name = xmalloc (name_len + 1);
2826 memcpy (name, namestring, name_len);
2827 name[name_len] = '\0';
2828 function_outside_compilation_unit_complaint (name);
2831 symbol.n_value += ANOFFSET (objfile->section_offsets,
2832 SECT_OFF_TEXT (objfile));
2833 add_psymbol_to_list (namestring, p - namestring, 1,
2834 VAR_DOMAIN, LOC_BLOCK,
2835 &objfile->static_psymbols,
2837 psymtab_language, objfile);
2840 /* Global functions were ignored here, but now they
2841 are put into the global psymtab like one would expect.
2842 They're also in the minimal symbol table. */
2846 int name_len = p - namestring;
2847 char *name = xmalloc (name_len + 1);
2849 memcpy (name, namestring, name_len);
2850 name[name_len] = '\0';
2851 function_outside_compilation_unit_complaint (name);
2855 /* We need only the minimal symbols for these
2856 loader-generated definitions. Keeping the global
2857 symbols leads to "in psymbols but not in symbols"
2859 if (strncmp (namestring, "@FIX", 4) == 0)
2862 symbol.n_value += ANOFFSET (objfile->section_offsets,
2863 SECT_OFF_TEXT (objfile));
2864 add_psymbol_to_list (namestring, p - namestring, 1,
2865 VAR_DOMAIN, LOC_BLOCK,
2866 &objfile->global_psymbols,
2868 psymtab_language, objfile);
2871 /* Two things show up here (hopefully); static symbols of
2872 local scope (static used inside braces) or extensions
2873 of structure symbols. We can ignore both. */
2887 case '#': /* For symbol identification (used in
2892 /* It is a C++ nested symbol. We don't need to record it
2893 (I don't think); if we try to look up foo::bar::baz,
2894 then symbols for the symtab containing foo should get
2895 read in, I think. */
2896 /* Someone says sun cc puts out symbols like
2897 /foo/baz/maclib::/usr/local/bin/maclib,
2898 which would get here with a symbol type of ':'. */
2902 /* Unexpected symbol descriptor. The second and
2903 subsequent stabs of a continued stab can show up
2904 here. The question is whether they ever can mimic
2905 a normal stab--it would be nice if not, since we
2906 certainly don't want to spend the time searching to
2907 the end of every string looking for a
2910 complaint (&symfile_complaints,
2911 _("unknown symbol descriptor `%c'"), p[1]);
2913 /* Ignore it; perhaps it is an extension that we don't
2923 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2924 ssymnum, dependency_list,
2925 dependencies_used, textlow_not_set);
2928 /* Record the toc offset value of this symbol table into objfile
2929 structure. If no XMC_TC0 is found, toc_offset should be zero.
2930 Another place to obtain this information would be file auxiliary
2933 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset
2937 /* Return the toc offset value for a given objfile. */
2940 xcoff_get_toc_offset (struct objfile *objfile)
2943 return ((struct coff_symfile_info *)
2944 objfile->deprecated_sym_private)->toc_offset;
2948 /* Scan and build partial symbols for a symbol file.
2949 We have been initialized by a call to dbx_symfile_init, which
2950 put all the relevant info into a "struct dbx_symfile_info",
2951 hung off the objfile structure.
2953 SECTION_OFFSETS contains offsets relative to which the symbols in the
2954 various sections are (depending where the sections were actually
2958 xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
2962 struct cleanup *back_to;
2963 int num_symbols; /* # of symbols */
2964 file_ptr symtab_offset; /* symbol table and */
2965 file_ptr stringtab_offset; /* string table file offsets */
2966 struct coff_symfile_info *info;
2970 info = (struct coff_symfile_info *) objfile->deprecated_sym_private;
2971 symfile_bfd = abfd = objfile->obfd;
2972 name = objfile->name;
2974 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2975 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2976 stringtab_offset = symtab_offset +
2977 num_symbols * coff_data (abfd)->local_symesz;
2979 info->min_lineno_offset = 0;
2980 info->max_lineno_offset = 0;
2981 bfd_map_over_sections (abfd, find_linenos, info);
2983 if (num_symbols > 0)
2985 /* Read the string table. */
2986 init_stringtab (abfd, stringtab_offset, objfile);
2988 /* Read the .debug section, if present. */
2990 struct bfd_section *secp;
2991 bfd_size_type length;
2992 char *debugsec = NULL;
2994 secp = bfd_get_section_by_name (abfd, ".debug");
2997 length = bfd_section_size (abfd, secp);
3001 (char *) obstack_alloc (&objfile->objfile_obstack, length);
3003 if (!bfd_get_section_contents (abfd, secp, debugsec,
3004 (file_ptr) 0, length))
3006 error (_("Error reading .debug section of `%s': %s"),
3007 name, bfd_errmsg (bfd_get_error ()));
3011 ((struct coff_symfile_info *)
3012 objfile->deprecated_sym_private)->debugsec
3017 /* Read the symbols. We keep them in core because we will want to
3018 access them randomly in read_symbol*. */
3019 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
3021 error (_("Error reading symbols from %s: %s"),
3022 name, bfd_errmsg (bfd_get_error ()));
3023 size = coff_data (abfd)->local_symesz * num_symbols;
3024 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl =
3025 obstack_alloc (&objfile->objfile_obstack, size);
3026 ((struct coff_symfile_info *)
3027 objfile->deprecated_sym_private)->symtbl_num_syms
3030 val = bfd_bread (((struct coff_symfile_info *)
3031 objfile->deprecated_sym_private)->symtbl,
3034 perror_with_name (_("reading symbol table"));
3036 /* If we are reinitializing, or if we have never loaded syms yet, init. */
3037 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
3038 /* I'm not sure how how good num_symbols is; the rule of thumb in
3039 init_psymbol_list was developed for a.out. On the one hand,
3040 num_symbols includes auxents. On the other hand, it doesn't
3042 init_psymbol_list (objfile, num_symbols);
3044 free_pending_blocks ();
3045 back_to = make_cleanup (really_free_pendings, 0);
3047 init_minimal_symbol_collection ();
3048 make_cleanup_discard_minimal_symbols ();
3050 /* Now that the symbol table data of the executable file are all in core,
3051 process them and define symbols accordingly. */
3053 scan_xcoff_symtab (objfile);
3055 /* Install any minimal symbols that have been collected as the current
3056 minimal symbols for this objfile. */
3058 install_minimal_symbols (objfile);
3060 /* DWARF2 sections. */
3062 if (dwarf2_has_info (objfile, &dwarf2_xcoff_names))
3063 dwarf2_build_psymtabs (objfile);
3065 dwarf2_build_frame_info (objfile);
3067 do_cleanups (back_to);
3071 xcoff_symfile_offsets (struct objfile *objfile,
3072 struct section_addr_info *addrs)
3074 asection *sect = NULL;
3077 objfile->num_sections = bfd_count_sections (objfile->obfd);
3078 objfile->section_offsets = (struct section_offsets *)
3079 obstack_alloc (&objfile->objfile_obstack,
3080 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
3082 /* Initialize the section indexes for future use. */
3083 sect = bfd_get_section_by_name (objfile->obfd, ".text");
3085 objfile->sect_index_text = sect->index;
3087 sect = bfd_get_section_by_name (objfile->obfd, ".data");
3089 objfile->sect_index_data = sect->index;
3091 sect = bfd_get_section_by_name (objfile->obfd, ".bss");
3093 objfile->sect_index_bss = sect->index;
3095 sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
3097 objfile->sect_index_rodata = sect->index;
3099 for (i = 0; i < objfile->num_sections; ++i)
3101 /* syms_from_objfile kindly subtracts from addr the
3102 bfd_section_vma of the .text section. This strikes me as
3103 wrong--whether the offset to be applied to symbol reading is
3104 relative to the start address of the section depends on the
3105 symbol format. In any event, this whole "addr" concept is
3106 pretty broken (it doesn't handle any section but .text
3107 sensibly), so just ignore the addr parameter and use 0.
3108 rs6000-nat.c will set the correct section offsets via
3109 objfile_relocate. */
3110 (objfile->section_offsets)->offsets[i] = 0;
3114 /* Register our ability to parse symbols for xcoff BFD files. */
3116 static const struct sym_fns xcoff_sym_fns =
3119 /* It is possible that coff and xcoff should be merged as
3120 they do have fundamental similarities (for example, the extra storage
3121 classes used for stabs could presumably be recognized in any COFF file).
3122 However, in addition to obvious things like all the csect hair, there are
3123 some subtler differences between xcoffread.c and coffread.c, notably
3124 the fact that coffread.c has no need to read in all the symbols, but
3125 xcoffread.c reads all the symbols and does in fact randomly access them
3126 (in C_BSTAT and line number processing). */
3128 bfd_target_xcoff_flavour,
3130 xcoff_new_init, /* init anything gbl to entire symtab */
3131 xcoff_symfile_init, /* read initial info, setup for sym_read() */
3132 xcoff_initial_scan, /* read a symbol file into symtab */
3133 NULL, /* sym_read_psymbols */
3134 xcoff_symfile_finish, /* finished with file, cleanup */
3135 xcoff_symfile_offsets, /* xlate offsets ext->int form */
3136 default_symfile_segments, /* Get segment information from a file. */
3137 aix_process_linenos,
3138 default_symfile_relocate, /* Relocate a debug section. */
3142 /* Provide a prototype to silence -Wmissing-prototypes. */
3143 extern initialize_file_ftype _initialize_xcoffread;
3146 _initialize_xcoffread (void)
3148 add_symtab_fns (&xcoff_sym_fns);