1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009,
4 2010, 2011 Free Software Foundation, Inc.
5 Derived from coffread.c, dbxread.c, and a lot of hacking.
6 Contributed by IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include <sys/types.h>
29 #include "gdb_string.h"
31 #include <sys/param.h>
32 #ifdef HAVE_SYS_FILE_H
37 #include "coff/internal.h"
38 #include "libcoff.h" /* FIXME, internal data from BFD */
39 #include "coff/xcoff.h"
41 #include "coff/rs6000.h"
42 #include "xcoffread.h"
46 /* FIXME: ezannoni/2004-02-13 Verify if the include below is really needed. */
50 #include "stabsread.h"
51 #include "expression.h"
52 #include "complaints.h"
55 #include "gdb-stabs.h"
57 /* For interface with stabsread.c. */
58 #include "aout/stab_gnu.h"
61 /* We put a pointer to this structure in the read_symtab_private field
67 /* First symbol number for this file. */
71 /* Number of symbols in the section of the symbol table devoted to
72 this file's symbols (actually, the section bracketed may contain
73 more than just this file's symbols). If numsyms is 0, the only
74 reason for this thing's existence is the dependency list. Nothing
75 else will happen when it is read in. */
79 /* Position of the start of the line number information for this
81 unsigned int lineno_off;
84 /* Remember what we deduced to be the source language of this psymtab. */
86 static enum language psymtab_language = language_unknown;
89 /* Simplified internal version of coff symbol table information */
94 int c_symnum; /* symbol number of this entry */
95 int c_naux; /* 0 if syment only, 1 if syment + auxent */
97 unsigned char c_sclass;
102 /* last function's saved coff symbol `cs' */
104 static struct coff_symbol fcn_cs_saved;
106 static bfd *symfile_bfd;
108 /* Core address of start and end of text of current source file.
109 This is calculated from the first function seen after a C_FILE
113 static CORE_ADDR cur_src_end_addr;
115 /* Core address of the end of the first object file. */
117 static CORE_ADDR first_object_file_end;
119 /* initial symbol-table-debug-string vector length */
121 #define INITIAL_STABVECTOR_LENGTH 40
123 /* Nonzero if within a function (so symbols should be local,
124 if nothing says specifically). */
128 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
129 there is any reason not to just use a #define, but might as well
130 ask BFD for the size and store it here, I guess. */
132 static unsigned local_symesz;
134 struct coff_symfile_info
136 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
137 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
139 /* Pointer to the string table. */
142 /* Pointer to debug section. */
145 /* Pointer to the a.out symbol table. */
148 /* Number of symbols in symtbl. */
151 /* Offset in data section to TOC anchor. */
152 CORE_ADDR toc_offset;
156 bf_notfound_complaint (void)
158 complaint (&symfile_complaints,
159 _("line numbers off, `.bf' symbol not found"));
163 ef_complaint (int arg1)
165 complaint (&symfile_complaints,
166 _("Mismatched .ef symbol ignored starting at symnum %d"), arg1);
170 eb_complaint (int arg1)
172 complaint (&symfile_complaints,
173 _("Mismatched .eb symbol ignored starting at symnum %d"), arg1);
176 static void xcoff_initial_scan (struct objfile *, int);
178 static void scan_xcoff_symtab (struct objfile *);
180 static char *xcoff_next_symbol_text (struct objfile *);
182 static void record_include_begin (struct coff_symbol *);
185 enter_line_range (struct subfile *, unsigned, unsigned,
186 CORE_ADDR, CORE_ADDR, unsigned *);
188 static void init_stringtab (bfd *, file_ptr, struct objfile *);
190 static void xcoff_symfile_init (struct objfile *);
192 static void xcoff_new_init (struct objfile *);
194 static void xcoff_symfile_finish (struct objfile *);
196 static void xcoff_symfile_offsets (struct objfile *,
197 struct section_addr_info *addrs);
199 static char *coff_getfilename (union internal_auxent *, struct objfile *);
201 static void read_symbol (struct internal_syment *, int);
203 static int read_symbol_lineno (int);
205 static CORE_ADDR read_symbol_nvalue (int);
207 static struct symbol *process_xcoff_symbol (struct coff_symbol *,
210 static void read_xcoff_symtab (struct partial_symtab *);
213 static void add_stab_to_list (char *, struct pending_stabs **);
216 static int compare_lte (const void *, const void *);
218 static struct linetable *arrange_linetable (struct linetable *);
220 static void record_include_end (struct coff_symbol *);
222 static void process_linenos (CORE_ADDR, CORE_ADDR);
225 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
227 static int secnum_to_section (int, struct objfile *);
228 static asection *secnum_to_bfd_section (int, struct objfile *);
230 struct find_targ_sec_arg
235 struct objfile *objfile;
238 static void find_targ_sec (bfd *, asection *, void *);
241 find_targ_sec (bfd *abfd, asection *sect, void *obj)
243 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
244 struct objfile *objfile = args->objfile;
246 if (sect->target_index == args->targ_index)
248 /* This is the section. Figure out what SECT_OFF_* code it is. */
249 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
250 *args->resultp = SECT_OFF_TEXT (objfile);
251 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
252 *args->resultp = SECT_OFF_DATA (objfile);
254 *args->resultp = sect->index;
255 *args->bfd_sect = sect;
259 /* Return the section number (SECT_OFF_*) that CS points to. */
261 secnum_to_section (int secnum, struct objfile *objfile)
263 int off = SECT_OFF_TEXT (objfile);
265 asection *sect = NULL;
266 struct find_targ_sec_arg args;
267 args.targ_index = secnum;
269 args.bfd_sect = §
270 args.objfile = objfile;
271 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
275 /* Return the BFD section that CS points to. */
277 secnum_to_bfd_section (int secnum, struct objfile *objfile)
279 int off = SECT_OFF_TEXT (objfile);
281 asection *sect = NULL;
282 struct find_targ_sec_arg args;
283 args.targ_index = secnum;
285 args.bfd_sect = §
286 args.objfile = objfile;
287 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
291 /* add a given stab string into given stab vector. */
296 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
298 if (*stabvector == NULL)
300 *stabvector = (struct pending_stabs *)
301 xmalloc (sizeof (struct pending_stabs) +
302 INITIAL_STABVECTOR_LENGTH * sizeof (char *));
303 (*stabvector)->count = 0;
304 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
306 else if ((*stabvector)->count >= (*stabvector)->length)
308 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
309 *stabvector = (struct pending_stabs *)
310 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
311 (*stabvector)->length * sizeof (char *));
313 (*stabvector)->stab[(*stabvector)->count++] = stabname;
318 /* Linenos are processed on a file-by-file basis.
322 1) xlc (IBM's native c compiler) postpones static function code
323 emission to the end of a compilation unit. This way it can
324 determine if those functions (statics) are needed or not, and
325 can do some garbage collection (I think). This makes line
326 numbers and corresponding addresses unordered, and we end up
327 with a line table like:
344 and that breaks gdb's binary search on line numbers, if the
345 above table is not sorted on line numbers. And that sort
346 should be on function based, since gcc can emit line numbers
349 10 0x100 - for the init/test part of a for stmt.
352 10 0x400 - for the increment part of a for stmt.
354 arrange_linetable() will do this sorting.
356 2) aix symbol table might look like:
358 c_file // beginning of a new file
359 .bi // beginning of include file
360 .ei // end of include file
364 basically, .bi/.ei pairs do not necessarily encapsulate
365 their scope. They need to be recorded, and processed later
366 on when we come the end of the compilation unit.
367 Include table (inclTable) and process_linenos() handle
373 /* compare line table entry addresses. */
376 compare_lte (const void *lte1p, const void *lte2p)
378 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
379 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
381 return lte1->pc - lte2->pc;
384 /* Given a line table with function entries are marked, arrange its functions
385 in ascending order and strip off function entry markers and return it in
386 a newly created table. If the old one is good enough, return the old one. */
387 /* FIXME: I think all this stuff can be replaced by just passing
388 sort_linevec = 1 to end_symtab. */
390 static struct linetable *
391 arrange_linetable (struct linetable *oldLineTb)
393 int ii, jj, newline, /* new line count */
394 function_count; /* # of functions */
396 struct linetable_entry *fentry; /* function entry vector */
397 int fentry_size; /* # of function entries */
398 struct linetable *newLineTb; /* new line table */
400 #define NUM_OF_FUNCTIONS 20
402 fentry_size = NUM_OF_FUNCTIONS;
403 fentry = (struct linetable_entry *)
404 xmalloc (fentry_size * sizeof (struct linetable_entry));
406 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
408 if (oldLineTb->item[ii].line == 0)
409 { /* function entry found. */
410 if (function_count >= fentry_size)
411 { /* make sure you have room. */
413 fentry = (struct linetable_entry *)
415 fentry_size * sizeof (struct linetable_entry));
417 fentry[function_count].line = ii;
418 fentry[function_count].pc = oldLineTb->item[ii].pc;
423 if (function_count == 0)
428 else if (function_count > 1)
429 qsort (fentry, function_count,
430 sizeof (struct linetable_entry), compare_lte);
432 /* allocate a new line table. */
433 newLineTb = (struct linetable *)
435 (sizeof (struct linetable) +
436 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
438 /* if line table does not start with a function beginning, copy up until
442 if (oldLineTb->item[0].line != 0)
444 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
445 newLineTb->item[newline] = oldLineTb->item[newline];
447 /* Now copy function lines one by one. */
449 for (ii = 0; ii < function_count; ++ii)
451 for (jj = fentry[ii].line + 1;
452 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
454 newLineTb->item[newline] = oldLineTb->item[jj];
457 newLineTb->nitems = oldLineTb->nitems - function_count;
461 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
462 following `IncludeChain'. At the end of each symtab (end_symtab),
463 we will determine if we should create additional symtab's to
464 represent if (the include files. */
467 typedef struct _inclTable
469 char *name; /* include filename */
471 /* Offsets to the line table. end points to the last entry which is
472 part of this include file. */
475 struct subfile *subfile;
476 unsigned funStartLine; /* start line # of its function */
480 #define INITIAL_INCLUDE_TABLE_LENGTH 20
481 static InclTable *inclTable; /* global include table */
482 static int inclIndx; /* last entry to table */
483 static int inclLength; /* table length */
484 static int inclDepth; /* nested include depth */
486 static void allocate_include_entry (void);
489 record_include_begin (struct coff_symbol *cs)
493 /* In xcoff, we assume include files cannot be nested (not in .c files
494 of course, but in corresponding .s files.). */
496 /* This can happen with old versions of GCC.
497 GCC 2.3.3-930426 does not exhibit this on a test case which
498 a user said produced the message for him. */
499 complaint (&symfile_complaints, _("Nested C_BINCL symbols"));
503 allocate_include_entry ();
505 inclTable[inclIndx].name = cs->c_name;
506 inclTable[inclIndx].begin = cs->c_value;
510 record_include_end (struct coff_symbol *cs)
516 complaint (&symfile_complaints, _("Mismatched C_BINCL/C_EINCL pair"));
519 allocate_include_entry ();
521 pTbl = &inclTable[inclIndx];
522 pTbl->end = cs->c_value;
529 allocate_include_entry (void)
531 if (inclTable == NULL)
533 inclTable = (InclTable *)
534 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
536 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
537 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
540 else if (inclIndx >= inclLength)
542 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
543 inclTable = (InclTable *)
544 xrealloc (inclTable, sizeof (InclTable) * inclLength);
545 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
546 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
550 /* Global variable to pass the psymtab down to all the routines involved
551 in psymtab to symtab processing. */
552 static struct partial_symtab *this_symtab_psymtab;
554 /* given the start and end addresses of a compilation unit (or a csect,
555 at times) process its lines and create appropriate line vectors. */
558 process_linenos (CORE_ADDR start, CORE_ADDR end)
561 file_ptr max_offset =
562 ((struct coff_symfile_info *) this_symtab_psymtab->objfile
563 ->deprecated_sym_private)->max_lineno_offset;
565 /* subfile structure for the main compilation unit. */
566 struct subfile main_subfile;
568 /* In the main source file, any time we see a function entry, we
569 reset this variable to function's absolute starting line number.
570 All the following line numbers in the function are relative to
571 this, and we record absolute line numbers in record_line(). */
573 unsigned int main_source_baseline = 0;
578 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
580 goto return_after_cleanup;
582 memset (&main_subfile, '\0', sizeof (main_subfile));
585 /* All source lines were in the main source file. None in include files. */
587 enter_line_range (&main_subfile, offset, 0, start, end,
588 &main_source_baseline);
592 /* There was source with line numbers in include files. */
595 coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
596 main_source_baseline = 0;
598 for (ii = 0; ii < inclIndx; ++ii)
600 struct subfile *tmpSubfile;
602 /* If there is main file source before include file, enter it. */
603 if (offset < inclTable[ii].begin)
606 (&main_subfile, offset, inclTable[ii].begin - linesz,
607 start, 0, &main_source_baseline);
610 if (strcmp (inclTable[ii].name, last_source_file) == 0)
612 /* The entry in the include table refers to the main source
613 file. Add the lines to the main subfile. */
615 main_source_baseline = inclTable[ii].funStartLine;
617 (&main_subfile, inclTable[ii].begin, inclTable[ii].end,
618 start, 0, &main_source_baseline);
619 inclTable[ii].subfile = &main_subfile;
623 /* Have a new subfile for the include file. */
625 tmpSubfile = inclTable[ii].subfile =
626 (struct subfile *) xmalloc (sizeof (struct subfile));
628 memset (tmpSubfile, '\0', sizeof (struct subfile));
629 firstLine = &(inclTable[ii].funStartLine);
631 /* Enter include file's lines now. */
632 enter_line_range (tmpSubfile, inclTable[ii].begin,
633 inclTable[ii].end, start, 0, firstLine);
636 if (offset <= inclTable[ii].end)
637 offset = inclTable[ii].end + linesz;
640 /* All the include files' line have been processed at this point. Now,
641 enter remaining lines of the main file, if any left. */
642 if (offset < max_offset + 1 - linesz)
644 enter_line_range (&main_subfile, offset, 0, start, end,
645 &main_source_baseline);
649 /* Process main file's line numbers. */
650 if (main_subfile.line_vector)
652 struct linetable *lineTb, *lv;
654 lv = main_subfile.line_vector;
656 /* Line numbers are not necessarily ordered. xlc compilation will
657 put static function to the end. */
659 lineTb = arrange_linetable (lv);
662 current_subfile->line_vector = (struct linetable *)
663 xrealloc (lv, (sizeof (struct linetable)
664 + lv->nitems * sizeof (struct linetable_entry)));
669 current_subfile->line_vector = lineTb;
672 current_subfile->line_vector_length =
673 current_subfile->line_vector->nitems;
676 /* Now, process included files' line numbers. */
678 for (ii = 0; ii < inclIndx; ++ii)
680 if (inclTable[ii].subfile != ((struct subfile *) &main_subfile)
681 && (inclTable[ii].subfile)->line_vector) /* Useless if!!!
684 struct linetable *lineTb, *lv;
686 lv = (inclTable[ii].subfile)->line_vector;
688 /* Line numbers are not necessarily ordered. xlc compilation will
689 put static function to the end. */
691 lineTb = arrange_linetable (lv);
695 /* For the same include file, we might want to have more than one
696 subfile. This happens if we have something like:
704 while foo.h including code in it. (stupid but possible)
705 Since start_subfile() looks at the name and uses an
706 existing one if finds, we need to provide a fake name and
710 start_subfile (inclTable[ii].name, (char *) 0);
713 /* Pick a fake name that will produce the same results as this
714 one when passed to deduce_language_from_filename. Kludge on
716 char *fakename = strrchr (inclTable[ii].name, '.');
718 if (fakename == NULL)
720 start_subfile (fakename, (char *) 0);
721 xfree (current_subfile->name);
723 current_subfile->name = xstrdup (inclTable[ii].name);
728 current_subfile->line_vector =
729 (struct linetable *) xrealloc
730 (lv, (sizeof (struct linetable)
731 + lv->nitems * sizeof (struct linetable_entry)));
737 current_subfile->line_vector = lineTb;
740 current_subfile->line_vector_length =
741 current_subfile->line_vector->nitems;
742 start_subfile (pop_subfile (), (char *) 0);
746 return_after_cleanup:
748 /* We don't want to keep alloc/free'ing the global include file table. */
751 /* Start with a fresh subfile structure for the next file. */
752 memset (&main_subfile, '\0', sizeof (struct subfile));
756 aix_process_linenos (void)
758 /* process line numbers and enter them into line vector */
759 process_linenos (last_source_start_addr, cur_src_end_addr);
763 /* Enter a given range of lines into the line vector.
764 can be called in the following two ways:
765 enter_line_range (subfile, beginoffset, endoffset,
766 startaddr, 0, firstLine) or
767 enter_line_range (subfile, beginoffset, 0,
768 startaddr, endaddr, firstLine)
770 endoffset points to the last line table entry that we should pay
774 enter_line_range (struct subfile *subfile, unsigned beginoffset,
775 unsigned endoffset, /* offsets to line table */
776 CORE_ADDR startaddr, /* offsets to line table */
777 CORE_ADDR endaddr, unsigned *firstLine)
779 struct objfile *objfile = this_symtab_psymtab->objfile;
780 struct gdbarch *gdbarch = get_objfile_arch (objfile);
781 unsigned int curoffset;
784 struct internal_lineno int_lnno;
785 unsigned int limit_offset;
789 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
791 curoffset = beginoffset;
793 ((struct coff_symfile_info *) objfile->deprecated_sym_private)
798 if (endoffset >= limit_offset)
800 complaint (&symfile_complaints,
801 _("Bad line table offset in C_EINCL directive"));
804 limit_offset = endoffset;
809 abfd = objfile->obfd;
810 linesz = coff_data (abfd)->local_linesz;
811 ext_lnno = alloca (linesz);
813 while (curoffset <= limit_offset)
815 bfd_seek (abfd, curoffset, SEEK_SET);
816 bfd_bread (ext_lnno, linesz, abfd);
817 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
819 /* Find the address this line represents. */
820 addr = (int_lnno.l_lnno
821 ? int_lnno.l_addr.l_paddr
822 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
823 addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
825 if (addr < startaddr || (endaddr && addr >= endaddr))
828 if (int_lnno.l_lnno == 0)
830 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
831 record_line (subfile, 0, gdbarch_addr_bits_remove (gdbarch, addr));
835 record_line (subfile, *firstLine + int_lnno.l_lnno,
836 gdbarch_addr_bits_remove (gdbarch, addr));
842 /* Save the vital information for use when closing off the current file.
843 NAME is the file name the symbols came from, START_ADDR is the first
844 text address for the file, and SIZE is the number of bytes of text. */
846 #define complete_symtab(name, start_addr) { \
847 last_source_file = xstrdup (name); \
848 last_source_start_addr = start_addr; \
852 /* Refill the symbol table input buffer
853 and set the variables that control fetching entries from it.
854 Reports an error if no data available.
855 This function can read past the end of the symbol table
856 (into the string table) but this does no harm. */
858 /* Reading symbol table has to be fast! Keep the followings as macros, rather
861 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
866 if (namestr[0] == '.') ++namestr; \
867 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
868 (SECTION), (asection *)NULL, \
870 misc_func_recorded = 1; \
874 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
875 nested. At any given time, a symbol can only be in one static block.
876 This is the base address of current static block, zero if non exists. */
878 static int static_block_base = 0;
880 /* Section number for the current static block. */
882 static int static_block_section = -1;
884 /* true if space for symbol name has been allocated. */
886 static int symname_alloced = 0;
888 /* Next symbol to read. Pointer into raw seething symbol table. */
890 static char *raw_symbol;
892 /* This is the function which stabsread.c calls to get symbol
896 xcoff_next_symbol_text (struct objfile *objfile)
898 struct internal_syment symbol;
901 /* FIXME: is this the same as the passed arg? */
902 if (this_symtab_psymtab)
903 objfile = this_symtab_psymtab->objfile;
905 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
908 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
910 /* Return something which points to '\0' and hope the symbol reading
911 code does something reasonable. */
914 else if (symbol.n_sclass & 0x80)
916 retval = ((struct coff_symfile_info *)
917 objfile->deprecated_sym_private)->debugsec
919 raw_symbol += coff_data (objfile->obfd)->local_symesz;
924 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
926 /* Return something which points to '\0' and hope the symbol reading
927 code does something reasonable. */
933 /* Read symbols for a given partial symbol table. */
936 read_xcoff_symtab (struct partial_symtab *pst)
938 struct objfile *objfile = pst->objfile;
939 bfd *abfd = objfile->obfd;
940 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
942 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl;
944 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec;
945 char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
947 struct internal_syment symbol[1];
948 union internal_auxent main_aux;
949 struct coff_symbol cs[1];
950 CORE_ADDR file_start_addr = 0;
951 CORE_ADDR file_end_addr = 0;
953 int next_file_symnum = -1;
954 unsigned int max_symnum;
955 int just_started = 1;
957 int fcn_start_addr = 0;
959 struct coff_symbol fcn_stab_saved = { 0 };
961 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
962 union internal_auxent fcn_aux_saved;
963 struct context_stack *new;
965 char *filestring = " _start_ "; /* Name of the current file. */
967 char *last_csect_name; /* last seen csect's name and value */
968 CORE_ADDR last_csect_val;
971 this_symtab_psymtab = pst;
973 /* Get the appropriate COFF "constants" related to the file we're
975 local_symesz = coff_data (abfd)->local_symesz;
977 last_source_file = NULL;
982 start_symtab (filestring, (char *) NULL, file_start_addr);
983 record_debugformat (debugfmt);
984 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
986 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
987 first_object_file_end = 0;
990 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl
991 + symnum * local_symesz;
993 while (symnum < max_symnum)
995 QUIT; /* make this command interruptable. */
997 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
998 /* read one symbol into `cs' structure. After processing the
999 whole symbol table, only string table will be kept in memory,
1000 symbol table and debug section of xcoff will be freed. Thus
1001 we can mark symbols with names in string table as
1006 /* Swap and align the symbol into a reasonable C structure. */
1007 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1009 cs->c_symnum = symnum;
1010 cs->c_naux = symbol->n_numaux;
1011 if (symbol->n_zeroes)
1013 symname_alloced = 0;
1014 /* We must use the original, unswapped, name here so the name field
1015 pointed to by cs->c_name will persist throughout xcoffread. If
1016 we use the new field, it gets overwritten for each symbol. */
1017 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
1018 /* If it's exactly E_SYMNMLEN characters long it isn't
1020 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1024 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
1025 strncpy (p, cs->c_name, E_SYMNMLEN);
1026 p[E_SYMNMLEN] = '\0';
1028 symname_alloced = 1;
1031 else if (symbol->n_sclass & 0x80)
1033 cs->c_name = debugsec + symbol->n_offset;
1034 symname_alloced = 0;
1038 /* in string table */
1039 cs->c_name = strtbl + (int) symbol->n_offset;
1040 symname_alloced = 1;
1042 cs->c_value = symbol->n_value;
1043 cs->c_sclass = symbol->n_sclass;
1044 cs->c_secnum = symbol->n_scnum;
1045 cs->c_type = (unsigned) symbol->n_type;
1047 raw_symbol += local_symesz;
1050 /* Save addr of first aux entry. */
1051 raw_auxptr = raw_symbol;
1053 /* Skip all the auxents associated with this symbol. */
1054 for (ii = symbol->n_numaux; ii; --ii)
1056 raw_symbol += coff_data (abfd)->local_auxesz;
1061 /* if symbol name starts with ".$" or "$", ignore it. */
1062 if (cs->c_name[0] == '$'
1063 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1066 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1068 if (last_source_file)
1070 pst->symtab = end_symtab (cur_src_end_addr, objfile,
1071 SECT_OFF_TEXT (objfile));
1076 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1077 record_debugformat (debugfmt);
1078 cur_src_end_addr = first_object_file_end;
1079 /* done with all files, everything from here on is globals */
1082 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1085 /* Dealing with a symbol with a csect entry. */
1087 #define CSECT(PP) ((PP)->x_csect)
1088 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1089 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1090 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1091 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1093 /* Convert the auxent to something we can access. */
1094 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1095 0, cs->c_naux, &main_aux);
1097 switch (CSECT_SMTYP (&main_aux))
1101 /* Ignore all external references. */
1105 /* A section description. */
1107 switch (CSECT_SCLAS (&main_aux))
1113 /* A program csect is seen. We have to allocate one
1114 symbol table for each program csect. Normally gdb
1115 prefers one symtab for each source file. In case
1116 of AIX, one source file might include more than one
1117 [PR] csect, and they don't have to be adjacent in
1118 terms of the space they occupy in memory. Thus, one
1119 single source file might get fragmented in the
1120 memory and gdb's file start and end address
1121 approach does not work! GCC (and I think xlc) seem
1122 to put all the code in the unnamed program csect. */
1124 if (last_csect_name)
1126 complete_symtab (filestring, file_start_addr);
1127 cur_src_end_addr = file_end_addr;
1128 end_symtab (file_end_addr, objfile,
1129 SECT_OFF_TEXT (objfile));
1132 /* Give all csects for this source file the same
1134 start_symtab (filestring, NULL, (CORE_ADDR) 0);
1135 record_debugformat (debugfmt);
1138 /* If this is the very first csect seen,
1139 basically `__start'. */
1142 first_object_file_end
1143 = cs->c_value + CSECT_LEN (&main_aux);
1148 cs->c_value + ANOFFSET (objfile->section_offsets,
1149 SECT_OFF_TEXT (objfile));
1150 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1152 if (cs->c_name && (cs->c_name[0] == '.'
1153 || cs->c_name[0] == '@'))
1155 last_csect_name = cs->c_name;
1156 last_csect_val = cs->c_value;
1157 last_csect_sec = secnum_to_section (cs->c_secnum,
1163 /* All other symbols are put into the minimal symbol
1176 /* Ignore the symbol. */
1184 switch (CSECT_SCLAS (&main_aux))
1187 /* a function entry point. */
1188 function_entry_point:
1190 fcn_start_addr = cs->c_value;
1192 /* save the function header info, which will be used
1193 when `.bf' is seen. */
1195 fcn_aux_saved = main_aux;
1199 /* shared library function trampoline code entry point. */
1203 /* The symbols often have the same names as debug symbols for
1204 functions, and confuse lookup_symbol. */
1208 /* xlc puts each variable in a separate csect, so we get
1209 an XTY_SD for each variable. But gcc puts several
1210 variables in a csect, so that each variable only gets
1211 an XTY_LD. This will typically be XMC_RW; I suspect
1212 XMC_RO and XMC_BS might be possible too.
1213 These variables are put in the minimal symbol table
1220 /* Common symbols are put into the minimal symbol table only. */
1228 /* If explicitly specified as a function, treat is as one. This check
1229 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1230 after the above CSECT check. */
1231 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1233 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1234 0, cs->c_naux, &main_aux);
1235 goto function_entry_point;
1238 switch (cs->c_sclass)
1242 /* c_value field contains symnum of next .file entry in table
1243 or symnum of first global after last .file. */
1245 next_file_symnum = cs->c_value;
1247 /* Complete symbol table for last object file containing
1248 debugging information. */
1250 /* Whether or not there was a csect in the previous file, we
1251 have to call `end_stabs' and `start_stabs' to reset
1252 type_vector, line_vector, etc. structures. */
1254 complete_symtab (filestring, file_start_addr);
1255 cur_src_end_addr = file_end_addr;
1256 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1259 /* XCOFF, according to the AIX 3.2 documentation, puts the
1260 filename in cs->c_name. But xlc 1.3.0.2 has decided to
1261 do things the standard COFF way and put it in the auxent.
1262 We use the auxent if the symbol is ".file" and an auxent
1263 exists, otherwise use the symbol itself. Simple
1265 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1267 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1268 0, cs->c_naux, &main_aux);
1269 filestring = coff_getfilename (&main_aux, objfile);
1272 filestring = cs->c_name;
1275 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1276 record_debugformat (debugfmt);
1277 last_csect_name = 0;
1279 /* reset file start and end addresses. A compilation unit
1280 with no text (only data) should have zero file
1282 file_start_addr = file_end_addr = 0;
1286 fcn_stab_saved = *cs;
1290 if (strcmp (cs->c_name, ".bf") == 0)
1292 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1293 SECT_OFF_TEXT (objfile));
1295 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1296 0, cs->c_naux, &main_aux);
1298 within_function = 1;
1300 new = push_context (0, fcn_start_addr + off);
1302 new->name = define_symbol
1303 (fcn_cs_saved.c_value + off,
1304 fcn_stab_saved.c_name, 0, 0, objfile);
1305 if (new->name != NULL)
1306 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1308 else if (strcmp (cs->c_name, ".ef") == 0)
1310 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1311 0, cs->c_naux, &main_aux);
1313 /* The value of .ef is the address of epilogue code;
1314 not useful for gdb. */
1315 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1316 contains number of lines to '}' */
1318 if (context_stack_depth <= 0)
1319 { /* We attempted to pop an empty context stack */
1320 ef_complaint (cs->c_symnum);
1321 within_function = 0;
1324 new = pop_context ();
1325 /* Stack must be empty now. */
1326 if (context_stack_depth > 0 || new == NULL)
1328 ef_complaint (cs->c_symnum);
1329 within_function = 0;
1333 finish_block (new->name, &local_symbols, new->old_blocks,
1335 (fcn_cs_saved.c_value
1336 + fcn_aux_saved.x_sym.x_misc.x_fsize
1337 + ANOFFSET (objfile->section_offsets,
1338 SECT_OFF_TEXT (objfile))),
1340 within_function = 0;
1345 /* Begin static block. */
1347 struct internal_syment symbol;
1349 read_symbol (&symbol, cs->c_value);
1350 static_block_base = symbol.n_value;
1351 static_block_section =
1352 secnum_to_section (symbol.n_scnum, objfile);
1357 /* End of static block. */
1358 static_block_base = 0;
1359 static_block_section = -1;
1370 complaint (&symfile_complaints,
1371 _("Unrecognized storage class %d."),
1386 /* beginning of include file */
1387 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1388 order. Thus, when wee see them, we might not know enough info
1389 to process them. Thus, we'll be saving them into a table
1390 (inclTable) and postpone their processing. */
1392 record_include_begin (cs);
1396 /* End of include file. */
1397 /* See the comment after case C_BINCL. */
1398 record_include_end (cs);
1402 if (strcmp (cs->c_name, ".bb") == 0)
1405 new = push_context (depth,
1407 + ANOFFSET (objfile->section_offsets,
1408 SECT_OFF_TEXT (objfile))));
1410 else if (strcmp (cs->c_name, ".eb") == 0)
1412 if (context_stack_depth <= 0)
1413 { /* We attempted to pop an empty context stack */
1414 eb_complaint (cs->c_symnum);
1417 new = pop_context ();
1418 if (depth-- != new->depth)
1420 eb_complaint (cs->c_symnum);
1423 if (local_symbols && context_stack_depth > 0)
1425 /* Make a block for the local symbols within. */
1426 finish_block (new->name, &local_symbols, new->old_blocks,
1429 + ANOFFSET (objfile->section_offsets,
1430 SECT_OFF_TEXT (objfile))),
1433 local_symbols = new->locals;
1438 process_xcoff_symbol (cs, objfile);
1443 if (last_source_file)
1447 complete_symtab (filestring, file_start_addr);
1448 cur_src_end_addr = file_end_addr;
1449 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1450 /* When reading symbols for the last C_FILE of the objfile, try
1451 to make sure that we set pst->symtab to the symtab for the
1452 file, not to the _globals_ symtab. I'm not sure whether this
1453 actually works right or when/if it comes up. */
1454 if (pst->symtab == NULL)
1460 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1461 (SYMBOL2) = (struct symbol *) \
1462 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1463 *(SYMBOL2) = *(SYMBOL1);
1466 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1467 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), \
1468 &objfile->objfile_obstack))
1471 /* process one xcoff symbol. */
1473 static struct symbol *
1474 process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
1476 struct symbol onesymbol;
1477 struct symbol *sym = &onesymbol;
1478 struct symbol *sym2 = NULL;
1484 if (cs->c_secnum < 0)
1486 /* The value is a register number, offset within a frame, etc.,
1487 and does not get relocated. */
1493 sec = secnum_to_section (cs->c_secnum, objfile);
1494 off = ANOFFSET (objfile->section_offsets, sec);
1501 memset (sym, '\0', sizeof (struct symbol));
1503 /* default assumptions */
1504 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1505 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1506 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1508 if (ISFCN (cs->c_type))
1510 /* At this point, we don't know the type of the function. This
1511 will be patched with the type from its stab entry later on in
1512 patch_block_stabs (), unless the file was compiled without -g. */
1514 SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced));
1515 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
1517 SYMBOL_CLASS (sym) = LOC_BLOCK;
1518 SYMBOL_DUP (sym, sym2);
1520 if (cs->c_sclass == C_EXT)
1521 add_symbol_to_list (sym2, &global_symbols);
1522 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1523 add_symbol_to_list (sym2, &file_symbols);
1527 /* In case we can't figure out the type, provide default. */
1528 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_data_symbol;
1530 switch (cs->c_sclass)
1533 /* The values of functions and global symbols are now resolved
1534 via the global_sym_chain in stabsread.c. */
1536 if (fcn_cs_saved.c_sclass == C_EXT)
1537 add_stab_to_list (name, &global_stabs);
1539 add_stab_to_list (name, &file_stabs);
1543 add_stab_to_list (name, &global_stabs);
1548 common_block_start (cs->c_name, objfile);
1552 common_block_end (objfile);
1556 complaint (&symfile_complaints, _("Unexpected storage class: %d"),
1569 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1572 SYMBOL_SECTION (sym) = sec;
1579 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1580 all statics and we need to distinguish file-scope versus
1581 function-scope using within_function. We do this by
1582 changing the string we pass to define_symbol to use 'S'
1583 where we need to, which is not necessarily super-clean,
1584 but seems workable enough. */
1586 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1590 if (*pp == 'V' && !within_function)
1592 sym = define_symbol ((cs->c_value
1593 + ANOFFSET (objfile->section_offsets,
1594 static_block_section)),
1595 cs->c_name, 0, 0, objfile);
1598 SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1599 SYMBOL_SECTION (sym) = static_block_section;
1608 /* Extract the file name from the aux entry of a C_FILE symbol.
1609 Result is in static storage and is only good for temporary use. */
1612 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1614 static char buffer[BUFSIZ];
1616 if (aux_entry->x_file.x_n.x_zeroes == 0)
1617 strcpy (buffer, ((struct coff_symfile_info *)
1618 objfile->deprecated_sym_private)->strtbl
1619 + aux_entry->x_file.x_n.x_offset);
1622 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1623 buffer[FILNMLEN] = '\0';
1628 /* Set *SYMBOL to symbol number symno in symtbl. */
1630 read_symbol (struct internal_syment *symbol, int symno)
1633 = ((struct coff_symfile_info *)
1634 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl_num_syms;
1635 char *stbl = ((struct coff_symfile_info *)
1636 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl;
1638 if (symno < 0 || symno >= nsyms)
1640 complaint (&symfile_complaints, _("Invalid symbol offset"));
1641 symbol->n_value = 0;
1642 symbol->n_scnum = -1;
1645 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1646 stbl + (symno * local_symesz),
1650 /* Get value corresponding to symbol number symno in symtbl. */
1653 read_symbol_nvalue (int symno)
1655 struct internal_syment symbol[1];
1657 read_symbol (symbol, symno);
1658 return symbol->n_value;
1662 /* Find the address of the function corresponding to symno, where
1663 symno is the symbol pointed to by the linetable. */
1666 read_symbol_lineno (int symno)
1668 struct objfile *objfile = this_symtab_psymtab->objfile;
1669 int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd);
1671 struct coff_symfile_info *info =
1672 (struct coff_symfile_info *)objfile->deprecated_sym_private;
1673 int nsyms = info->symtbl_num_syms;
1674 char *stbl = info->symtbl;
1675 char *strtbl = info->strtbl;
1677 struct internal_syment symbol[1];
1678 union internal_auxent main_aux[1];
1682 bf_notfound_complaint ();
1686 /* Note that just searching for a short distance (e.g. 50 symbols)
1687 is not enough, at least in the following case.
1690 [many .stabx entries]
1691 [a few functions, referring to foo]
1695 What happens here is that the assembler moves the .stabx entries
1696 to right before the ".bf" for foo, but the symbol for "foo" is before
1697 all the stabx entries. See PR gdb/2222. */
1699 /* Maintaining a table of .bf entries might be preferable to this search.
1700 If I understand things correctly it would need to be done only for
1701 the duration of a single psymtab to symtab conversion. */
1702 while (symno < nsyms)
1704 bfd_coff_swap_sym_in (symfile_bfd,
1705 stbl + (symno * local_symesz), symbol);
1706 if (symbol->n_sclass == C_FCN)
1708 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1710 if (strcmp (name, ".bf") == 0)
1713 symno += symbol->n_numaux + 1;
1716 bf_notfound_complaint ();
1720 /* take aux entry and return its lineno */
1722 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1723 symbol->n_type, symbol->n_sclass,
1724 0, symbol->n_numaux, main_aux);
1726 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1729 /* Support for line number handling */
1731 /* This function is called for every section; it finds the outer limits
1732 * of the line table (minimum and maximum file offset) so that the
1733 * mainline code can read the whole thing for efficiency.
1736 find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo)
1738 struct coff_symfile_info *info;
1740 file_ptr offset, maxoff;
1742 count = asect->lineno_count;
1744 if (strcmp (asect->name, ".text") != 0 || count == 0)
1747 size = count * coff_data (abfd)->local_linesz;
1748 info = (struct coff_symfile_info *) vpinfo;
1749 offset = asect->line_filepos;
1750 maxoff = offset + size;
1752 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1753 info->min_lineno_offset = offset;
1755 if (maxoff > info->max_lineno_offset)
1756 info->max_lineno_offset = maxoff;
1759 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1762 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1764 struct cleanup *old_chain;
1773 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1778 /* Read in all partial symtabs on which this one is dependent */
1779 for (i = 0; i < pst->number_of_dependencies; i++)
1780 if (!pst->dependencies[i]->readin)
1782 /* Inform about additional files that need to be read in. */
1785 fputs_filtered (" ", gdb_stdout);
1787 fputs_filtered ("and ", gdb_stdout);
1789 printf_filtered ("%s...", pst->dependencies[i]->filename);
1790 wrap_here (""); /* Flush output */
1791 gdb_flush (gdb_stdout);
1793 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1796 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1798 /* Init stuff necessary for reading in symbols. */
1801 old_chain = make_cleanup (really_free_pendings, 0);
1803 read_xcoff_symtab (pst);
1805 do_cleanups (old_chain);
1811 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1813 /* Read in all of the symbols for a given psymtab for real.
1814 Be verbose about it if the user wants that. */
1817 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1827 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1832 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1833 || pst->number_of_dependencies)
1835 /* Print the message now, before reading the string table,
1836 to avoid disconcerting pauses. */
1839 printf_filtered ("Reading in symbols for %s...", pst->filename);
1840 gdb_flush (gdb_stdout);
1843 sym_bfd = pst->objfile->obfd;
1845 next_symbol_text_func = xcoff_next_symbol_text;
1847 xcoff_psymtab_to_symtab_1 (pst);
1849 /* Match with global symbols. This only needs to be done once,
1850 after all of the symtabs and dependencies have been read in. */
1851 scan_file_globals (pst->objfile);
1853 /* Finish up the debug error message. */
1855 printf_filtered ("done.\n");
1860 xcoff_new_init (struct objfile *objfile)
1862 stabsread_new_init ();
1863 buildsym_new_init ();
1866 /* Do initialization in preparation for reading symbols from OBJFILE.
1868 We will only be called if this is an XCOFF or XCOFF-like file.
1869 BFD handles figuring out the format of the file, and code in symfile.c
1870 uses BFD's determination to vector to us. */
1873 xcoff_symfile_init (struct objfile *objfile)
1875 /* Allocate struct to keep track of the symfile */
1876 objfile->deprecated_sym_private
1877 = xmalloc (sizeof (struct coff_symfile_info));
1879 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1880 find this causes a significant slowdown in gdb then we could
1881 set it in the debug symbol readers only when necessary. */
1882 objfile->flags |= OBJF_REORDERED;
1884 init_entry_point_info (objfile);
1887 /* Perform any local cleanups required when we are done with a particular
1888 objfile. I.E, we are in the process of discarding all symbol information
1889 for an objfile, freeing up all memory held for it, and unlinking the
1890 objfile struct from the global list of known objfiles. */
1893 xcoff_symfile_finish (struct objfile *objfile)
1895 if (objfile->deprecated_sym_private != NULL)
1897 xfree (objfile->deprecated_sym_private);
1900 /* Start with a fresh include table for the next objfile. */
1906 inclIndx = inclLength = inclDepth = 0;
1911 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1915 unsigned char lengthbuf[4];
1918 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1921 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1922 error (_("cannot seek to string table in %s: %s"),
1923 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1925 val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd);
1926 length = bfd_h_get_32 (abfd, lengthbuf);
1928 /* If no string table is needed, then the file may end immediately
1929 after the symbols. Just return with `strtbl' set to NULL. */
1931 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1934 /* Allocate string table from objfile_obstack. We will need this table
1935 as long as we have its symbol table around. */
1937 strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length);
1938 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1941 /* Copy length buffer, the first byte is usually zero and is
1942 used for stabs with a name length of zero. */
1943 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1944 if (length == sizeof lengthbuf)
1947 val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd);
1949 if (val != length - sizeof lengthbuf)
1950 error (_("cannot read string table from %s: %s"),
1951 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1952 if (strtbl[length - 1] != '\0')
1953 error (_("bad symbol file: string table "
1954 "does not end with null character"));
1959 /* If we have not yet seen a function for this psymtab, this is 0. If we
1960 have seen one, it is the offset in the line numbers of the line numbers
1962 static unsigned int first_fun_line_offset;
1964 static struct partial_symtab *xcoff_start_psymtab
1965 (struct objfile *, char *, int,
1966 struct partial_symbol **, struct partial_symbol **);
1968 /* Allocate and partially fill a partial symtab. It will be
1969 completely filled at the end of the symbol list.
1971 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1972 is the address relative to which its symbols are (incremental) or 0
1975 static struct partial_symtab *
1976 xcoff_start_psymtab (struct objfile *objfile, char *filename, int first_symnum,
1977 struct partial_symbol **global_syms,
1978 struct partial_symbol **static_syms)
1980 struct partial_symtab *result =
1981 start_psymtab_common (objfile, objfile->section_offsets,
1983 /* We fill in textlow later. */
1985 global_syms, static_syms);
1987 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
1988 sizeof (struct symloc));
1989 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
1990 result->read_symtab = xcoff_psymtab_to_symtab;
1992 /* Deduce the source language from the filename for this psymtab. */
1993 psymtab_language = deduce_language_from_filename (filename);
1998 static struct partial_symtab *xcoff_end_psymtab
1999 (struct partial_symtab *, char **, int, int,
2000 struct partial_symtab **, int, int);
2002 /* Close off the current usage of PST.
2003 Returns PST, or NULL if the partial symtab was empty and thrown away.
2005 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2007 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2008 are the information for includes and dependencies. */
2010 static struct partial_symtab *
2011 xcoff_end_psymtab (struct partial_symtab *pst, char **include_list,
2012 int num_includes, int capping_symbol_number,
2013 struct partial_symtab **dependency_list,
2014 int number_dependencies, int textlow_not_set)
2017 struct objfile *objfile = pst->objfile;
2019 if (capping_symbol_number != -1)
2020 ((struct symloc *) pst->read_symtab_private)->numsyms =
2021 capping_symbol_number
2022 - ((struct symloc *) pst->read_symtab_private)->first_symnum;
2023 ((struct symloc *) pst->read_symtab_private)->lineno_off =
2024 first_fun_line_offset;
2025 first_fun_line_offset = 0;
2026 pst->n_global_syms = objfile->global_psymbols.next
2027 - (objfile->global_psymbols.list + pst->globals_offset);
2028 pst->n_static_syms = objfile->static_psymbols.next
2029 - (objfile->static_psymbols.list + pst->statics_offset);
2031 pst->number_of_dependencies = number_dependencies;
2032 if (number_dependencies)
2034 pst->dependencies = (struct partial_symtab **)
2035 obstack_alloc (&objfile->objfile_obstack,
2036 number_dependencies * sizeof (struct partial_symtab *));
2037 memcpy (pst->dependencies, dependency_list,
2038 number_dependencies * sizeof (struct partial_symtab *));
2041 pst->dependencies = 0;
2043 for (i = 0; i < num_includes; i++)
2045 struct partial_symtab *subpst =
2046 allocate_psymtab (include_list[i], objfile);
2048 subpst->section_offsets = pst->section_offsets;
2049 subpst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2050 sizeof (struct symloc));
2051 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2052 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2053 subpst->textlow = 0;
2054 subpst->texthigh = 0;
2056 /* We could save slight bits of space by only making one of these,
2057 shared by the entire set of include files. FIXME-someday. */
2058 subpst->dependencies = (struct partial_symtab **)
2059 obstack_alloc (&objfile->objfile_obstack,
2060 sizeof (struct partial_symtab *));
2061 subpst->dependencies[0] = pst;
2062 subpst->number_of_dependencies = 1;
2064 subpst->globals_offset =
2065 subpst->n_global_syms =
2066 subpst->statics_offset =
2067 subpst->n_static_syms = 0;
2071 subpst->read_symtab = pst->read_symtab;
2074 sort_pst_symbols (pst);
2076 if (num_includes == 0
2077 && number_dependencies == 0
2078 && pst->n_global_syms == 0
2079 && pst->n_static_syms == 0)
2081 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2082 it is on the obstack, but we can forget to chain it on the list. */
2083 /* Empty psymtabs happen as a result of header files which don't have
2084 any symbols in them. There can be a lot of them. */
2086 discard_psymtab (pst);
2088 /* Indicate that psymtab was thrown away. */
2089 pst = (struct partial_symtab *) NULL;
2094 static void swap_sym (struct internal_syment *,
2095 union internal_auxent *, char **, char **,
2096 unsigned int *, struct objfile *);
2098 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2099 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2100 the symbol and its auxents. */
2103 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2104 char **name, char **raw, unsigned int *symnump,
2105 struct objfile *objfile)
2107 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2108 if (symbol->n_zeroes)
2110 /* If it's exactly E_SYMNMLEN characters long it isn't
2112 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2114 /* FIXME: wastes memory for symbols which we don't end up putting
2115 into the minimal symbols. */
2118 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
2119 strncpy (p, symbol->n_name, E_SYMNMLEN);
2120 p[E_SYMNMLEN] = '\0';
2124 /* Point to the unswapped name as that persists as long as the
2126 *name = ((struct external_syment *) *raw)->e.e_name;
2128 else if (symbol->n_sclass & 0x80)
2130 *name = ((struct coff_symfile_info *)
2131 objfile->deprecated_sym_private)->debugsec + symbol->n_offset;
2135 *name = ((struct coff_symfile_info *)
2136 objfile->deprecated_sym_private)->strtbl + symbol->n_offset;
2139 *raw += coff_data (objfile->obfd)->local_symesz;
2140 if (symbol->n_numaux > 0)
2142 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2143 symbol->n_sclass, 0, symbol->n_numaux, aux);
2145 *symnump += symbol->n_numaux;
2146 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2151 function_outside_compilation_unit_complaint (const char *arg1)
2153 complaint (&symfile_complaints,
2154 _("function `%s' appears to be defined "
2155 "outside of all compilation units"),
2160 scan_xcoff_symtab (struct objfile *objfile)
2162 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2163 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
2164 char *filestring = NULL;
2167 int past_first_source_file = 0;
2172 /* Current partial symtab */
2173 struct partial_symtab *pst;
2175 /* List of current psymtab's include files */
2176 char **psymtab_include_list;
2177 int includes_allocated;
2180 /* Index within current psymtab dependency list */
2181 struct partial_symtab **dependency_list;
2182 int dependencies_used, dependencies_allocated;
2185 struct internal_syment symbol;
2186 union internal_auxent main_aux[5];
2187 unsigned int ssymnum;
2189 char *last_csect_name = NULL; /* last seen csect's name and value */
2190 CORE_ADDR last_csect_val = 0;
2191 int last_csect_sec = 0;
2192 int misc_func_recorded = 0; /* true if any misc. function */
2193 int textlow_not_set = 1;
2195 pst = (struct partial_symtab *) 0;
2197 includes_allocated = 30;
2199 psymtab_include_list = (char **) alloca (includes_allocated *
2202 dependencies_allocated = 30;
2203 dependencies_used = 0;
2205 (struct partial_symtab **) alloca (dependencies_allocated *
2206 sizeof (struct partial_symtab *));
2208 last_source_file = NULL;
2210 abfd = objfile->obfd;
2211 next_symbol_text_func = xcoff_next_symbol_text;
2213 sraw_symbol = ((struct coff_symfile_info *)
2214 objfile->deprecated_sym_private)->symtbl;
2215 nsyms = ((struct coff_symfile_info *)
2216 objfile->deprecated_sym_private)->symtbl_num_syms;
2218 while (ssymnum < nsyms)
2224 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2225 sclass = symbol.n_sclass;
2232 /* The CSECT auxent--always the last auxent. */
2233 union internal_auxent csect_aux;
2234 unsigned int symnum_before = ssymnum;
2236 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2238 if (symbol.n_numaux > 1)
2240 bfd_coff_swap_aux_in
2242 sraw_symbol - coff_data (abfd)->local_symesz,
2245 symbol.n_numaux - 1,
2250 csect_aux = main_aux[0];
2252 /* If symbol name starts with ".$" or "$", ignore it. */
2253 if (namestring[0] == '$'
2254 || (namestring[0] == '.' && namestring[1] == '$'))
2257 switch (csect_aux.x_csect.x_smtyp & 0x7)
2260 switch (csect_aux.x_csect.x_smclas)
2263 if (last_csect_name)
2265 /* If no misc. function recorded in the last
2266 seen csect, enter it as a function. This
2267 will take care of functions like strcmp()
2270 if (!misc_func_recorded)
2272 RECORD_MINIMAL_SYMBOL
2273 (last_csect_name, last_csect_val,
2274 mst_text, last_csect_sec,
2280 /* We have to allocate one psymtab for
2281 each program csect, because their text
2282 sections need not be adjacent. */
2284 (pst, psymtab_include_list, includes_used,
2285 symnum_before, dependency_list,
2286 dependencies_used, textlow_not_set);
2288 dependencies_used = 0;
2289 /* Give all psymtabs for this source file the same
2291 pst = xcoff_start_psymtab
2295 objfile->global_psymbols.next,
2296 objfile->static_psymbols.next);
2299 /* Activate the misc_func_recorded mechanism for
2300 compiler- and linker-generated CSECTs like ".strcmp"
2302 if (namestring && (namestring[0] == '.'
2303 || namestring[0] == '@'))
2305 last_csect_name = namestring;
2306 last_csect_val = symbol.n_value;
2308 secnum_to_section (symbol.n_scnum, objfile);
2313 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2315 if (highval > pst->texthigh)
2316 pst->texthigh = highval;
2317 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2318 pst->textlow = symbol.n_value;
2320 misc_func_recorded = 0;
2325 /* Data variables are recorded in the minimal symbol
2326 table, except for section symbols. */
2327 if (*namestring != '.')
2328 prim_record_minimal_symbol_and_info
2329 (namestring, symbol.n_value,
2330 sclass == C_HIDEXT ? mst_file_data : mst_data,
2331 secnum_to_section (symbol.n_scnum, objfile),
2337 warning (_("More than one XMC_TC0 symbol found."));
2338 toc_offset = symbol.n_value;
2340 /* Make TOC offset relative to start address of
2342 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2344 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
2348 /* These symbols tell us where the TOC entry for a
2349 variable is, not the variable itself. */
2358 switch (csect_aux.x_csect.x_smclas)
2361 /* A function entry point. */
2363 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2364 first_fun_line_offset =
2365 main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
2366 RECORD_MINIMAL_SYMBOL
2367 (namestring, symbol.n_value,
2368 sclass == C_HIDEXT ? mst_file_text : mst_text,
2369 secnum_to_section (symbol.n_scnum, objfile),
2374 /* shared library function trampoline code entry
2377 /* record trampoline code entries as
2378 mst_solib_trampoline symbol. When we lookup mst
2379 symbols, we will choose mst_text over
2380 mst_solib_trampoline. */
2381 RECORD_MINIMAL_SYMBOL
2382 (namestring, symbol.n_value,
2383 mst_solib_trampoline,
2384 secnum_to_section (symbol.n_scnum, objfile),
2389 /* The symbols often have the same names as
2390 debug symbols for functions, and confuse
2396 /* xlc puts each variable in a separate csect,
2397 so we get an XTY_SD for each variable. But
2398 gcc puts several variables in a csect, so
2399 that each variable only gets an XTY_LD. We
2400 still need to record them. This will
2401 typically be XMC_RW; I suspect XMC_RO and
2402 XMC_BS might be possible too. */
2403 if (*namestring != '.')
2404 prim_record_minimal_symbol_and_info
2405 (namestring, symbol.n_value,
2406 sclass == C_HIDEXT ? mst_file_data : mst_data,
2407 secnum_to_section (symbol.n_scnum, objfile),
2414 switch (csect_aux.x_csect.x_smclas)
2418 /* Common variables are recorded in the minimal symbol
2419 table, except for section symbols. */
2420 if (*namestring != '.')
2421 prim_record_minimal_symbol_and_info
2422 (namestring, symbol.n_value,
2423 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2424 secnum_to_section (symbol.n_scnum, objfile),
2437 unsigned int symnum_before;
2439 symnum_before = ssymnum;
2440 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2443 /* See if the last csect needs to be recorded. */
2445 if (last_csect_name && !misc_func_recorded)
2447 /* If no misc. function recorded in the last seen csect, enter
2448 it as a function. This will take care of functions like
2449 strcmp() compiled by xlc. */
2451 RECORD_MINIMAL_SYMBOL
2452 (last_csect_name, last_csect_val,
2453 mst_text, last_csect_sec, objfile);
2458 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2459 symnum_before, dependency_list,
2460 dependencies_used, textlow_not_set);
2462 dependencies_used = 0;
2464 first_fun_line_offset = 0;
2466 /* XCOFF, according to the AIX 3.2 documentation, puts the
2467 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2468 do things the standard COFF way and put it in the auxent.
2469 We use the auxent if the symbol is ".file" and an auxent
2470 exists, otherwise use the symbol itself. */
2471 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2473 filestring = coff_getfilename (&main_aux[0], objfile);
2476 filestring = namestring;
2478 pst = xcoff_start_psymtab (objfile,
2481 objfile->global_psymbols.next,
2482 objfile->static_psymbols.next);
2483 last_csect_name = NULL;
2489 complaint (&symfile_complaints,
2490 _("Storage class %d not recognized during scan"),
2495 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2496 to handle only the C_FUN and C_EXT. */
2511 /* C_EINCL means we are switching back to the main file. But there
2512 is no reason to care; the only thing we want to know about
2513 includes is the names of all the included (.h) files. */
2518 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2522 /* I don't think the name of the common block (as opposed to the
2523 variables within it) is something which is user visible
2531 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2532 so C_LSYM would appear to be only for locals. */
2538 /* We probably could save a few instructions by assuming that
2539 C_LSYM, C_PSYM, etc., never have auxents. */
2540 int naux1 = symbol.n_numaux + 1;
2543 sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2549 /* Mark down an include file in the current psymtab */
2550 enum language tmp_language;
2552 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2555 tmp_language = deduce_language_from_filename (namestring);
2557 /* Only change the psymtab's language if we've learned
2558 something useful (eg. tmp_language is not language_unknown).
2559 In addition, to match what start_subfile does, never change
2561 if (tmp_language != language_unknown
2562 && (tmp_language != language_c
2563 || psymtab_language != language_cplus))
2564 psymtab_language = tmp_language;
2566 /* In C++, one may expect the same filename to come round many
2567 times, when code is coming alternately from the main file
2568 and from inline functions in other files. So I check to see
2569 if this is a file we've seen before -- either the main
2570 source file, or a previously included file.
2572 This seems to be a lot of time to be spending on N_SOL, but
2573 things like "break c-exp.y:435" need to work (I
2574 suppose the psymtab_include_list could be hashed or put
2575 in a binary tree, if profiling shows this is a major hog). */
2576 if (pst && strcmp (namestring, pst->filename) == 0)
2582 for (i = 0; i < includes_used; i++)
2583 if (strcmp (namestring, psymtab_include_list[i]) == 0)
2591 psymtab_include_list[includes_used++] = namestring;
2592 if (includes_used >= includes_allocated)
2594 char **orig = psymtab_include_list;
2596 psymtab_include_list = (char **)
2597 alloca ((includes_allocated *= 2) *
2599 memcpy (psymtab_include_list, orig,
2600 includes_used * sizeof (char *));
2605 /* The value of the C_FUN is not the address of the function (it
2606 appears to be the address before linking), but as long as it
2607 is smaller than the actual address, then find_pc_partial_function
2608 will use the minimal symbols instead. I hope. */
2617 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2620 p = (char *) strchr (namestring, ':');
2622 continue; /* Not a debugging symbol. */
2624 /* Main processing section for debugging symbols which
2625 the initial read through the symbol tables needs to worry
2626 about. If we reach this point, the symbol which we are
2627 considering is definitely one we are interested in.
2628 p must also contain the (valid) index into the namestring
2629 which indicates the debugging type symbol. */
2634 symbol.n_value += ANOFFSET (objfile->section_offsets,
2635 SECT_OFF_DATA (objfile));
2637 if (gdbarch_static_transform_name_p (gdbarch))
2638 namestring = gdbarch_static_transform_name
2639 (gdbarch, namestring);
2641 add_psymbol_to_list (namestring, p - namestring, 1,
2642 VAR_DOMAIN, LOC_STATIC,
2643 &objfile->static_psymbols,
2645 psymtab_language, objfile);
2649 symbol.n_value += ANOFFSET (objfile->section_offsets,
2650 SECT_OFF_DATA (objfile));
2651 /* The addresses in these entries are reported to be
2652 wrong. See the code that reads 'G's for symtabs. */
2653 add_psymbol_to_list (namestring, p - namestring, 1,
2654 VAR_DOMAIN, LOC_STATIC,
2655 &objfile->global_psymbols,
2657 psymtab_language, objfile);
2661 /* When a 'T' entry is defining an anonymous enum, it
2662 may have a name which is the empty string, or a
2663 single space. Since they're not really defining a
2664 symbol, those shouldn't go in the partial symbol
2665 table. We do pick up the elements of such enums at
2666 'check_enum:', below. */
2667 if (p >= namestring + 2
2668 || (p == namestring + 1
2669 && namestring[0] != ' '))
2671 add_psymbol_to_list (namestring, p - namestring, 1,
2672 STRUCT_DOMAIN, LOC_TYPEDEF,
2673 &objfile->static_psymbols,
2675 psymtab_language, objfile);
2678 /* Also a typedef with the same name. */
2679 add_psymbol_to_list (namestring, p - namestring, 1,
2680 VAR_DOMAIN, LOC_TYPEDEF,
2681 &objfile->static_psymbols,
2683 psymtab_language, objfile);
2690 if (p != namestring) /* a name is there, not just :T... */
2692 add_psymbol_to_list (namestring, p - namestring, 1,
2693 VAR_DOMAIN, LOC_TYPEDEF,
2694 &objfile->static_psymbols,
2696 psymtab_language, objfile);
2699 /* If this is an enumerated type, we need to
2700 add all the enum constants to the partial symbol
2701 table. This does not cover enums without names, e.g.
2702 "enum {a, b} c;" in C, but fortunately those are
2703 rare. There is no way for GDB to find those from the
2704 enum type without spending too much time on it. Thus
2705 to solve this problem, the compiler needs to put out the
2706 enum in a nameless type. GCC2 does this. */
2708 /* We are looking for something of the form
2709 <name> ":" ("t" | "T") [<number> "="] "e"
2710 {<constant> ":" <value> ","} ";". */
2712 /* Skip over the colon and the 't' or 'T'. */
2714 /* This type may be given a number. Also, numbers can come
2715 in pairs like (0,26). Skip over it. */
2716 while ((*p >= '0' && *p <= '9')
2717 || *p == '(' || *p == ',' || *p == ')'
2723 /* The aix4 compiler emits extra crud before the
2727 /* Skip over the type (?). */
2731 /* Skip over the colon. */
2735 /* We have found an enumerated type. */
2736 /* According to comments in read_enum_type
2737 a comma could end it instead of a semicolon.
2738 I don't know where that happens.
2740 while (*p && *p != ';' && *p != ',')
2744 /* Check for and handle cretinous dbx symbol name
2746 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
2747 p = next_symbol_text (objfile);
2749 /* Point to the character after the name
2750 of the enum constant. */
2751 for (q = p; *q && *q != ':'; q++)
2753 /* Note that the value doesn't matter for
2754 enum constants in psymtabs, just in symtabs. */
2755 add_psymbol_to_list (p, q - p, 1,
2756 VAR_DOMAIN, LOC_CONST,
2757 &objfile->static_psymbols, 0,
2758 0, psymtab_language, objfile);
2759 /* Point past the name. */
2761 /* Skip over the value. */
2762 while (*p && *p != ',')
2764 /* Advance past the comma. */
2772 /* Constant, e.g. from "const" in Pascal. */
2773 add_psymbol_to_list (namestring, p - namestring, 1,
2774 VAR_DOMAIN, LOC_CONST,
2775 &objfile->static_psymbols, symbol.n_value,
2776 0, psymtab_language, objfile);
2782 int name_len = p - namestring;
2783 char *name = xmalloc (name_len + 1);
2785 memcpy (name, namestring, name_len);
2786 name[name_len] = '\0';
2787 function_outside_compilation_unit_complaint (name);
2790 symbol.n_value += ANOFFSET (objfile->section_offsets,
2791 SECT_OFF_TEXT (objfile));
2792 add_psymbol_to_list (namestring, p - namestring, 1,
2793 VAR_DOMAIN, LOC_BLOCK,
2794 &objfile->static_psymbols,
2796 psymtab_language, objfile);
2799 /* Global functions were ignored here, but now they
2800 are put into the global psymtab like one would expect.
2801 They're also in the minimal symbol table. */
2805 int name_len = p - namestring;
2806 char *name = xmalloc (name_len + 1);
2808 memcpy (name, namestring, name_len);
2809 name[name_len] = '\0';
2810 function_outside_compilation_unit_complaint (name);
2814 /* We need only the minimal symbols for these
2815 loader-generated definitions. Keeping the global
2816 symbols leads to "in psymbols but not in symbols"
2818 if (strncmp (namestring, "@FIX", 4) == 0)
2821 symbol.n_value += ANOFFSET (objfile->section_offsets,
2822 SECT_OFF_TEXT (objfile));
2823 add_psymbol_to_list (namestring, p - namestring, 1,
2824 VAR_DOMAIN, LOC_BLOCK,
2825 &objfile->global_psymbols,
2827 psymtab_language, objfile);
2830 /* Two things show up here (hopefully); static symbols of
2831 local scope (static used inside braces) or extensions
2832 of structure symbols. We can ignore both. */
2846 case '#': /* For symbol identification (used in
2851 /* It is a C++ nested symbol. We don't need to record it
2852 (I don't think); if we try to look up foo::bar::baz,
2853 then symbols for the symtab containing foo should get
2854 read in, I think. */
2855 /* Someone says sun cc puts out symbols like
2856 /foo/baz/maclib::/usr/local/bin/maclib,
2857 which would get here with a symbol type of ':'. */
2861 /* Unexpected symbol descriptor. The second and
2862 subsequent stabs of a continued stab can show up
2863 here. The question is whether they ever can mimic
2864 a normal stab--it would be nice if not, since we
2865 certainly don't want to spend the time searching to
2866 the end of every string looking for a
2869 complaint (&symfile_complaints,
2870 _("unknown symbol descriptor `%c'"), p[1]);
2872 /* Ignore it; perhaps it is an extension that we don't
2882 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2883 ssymnum, dependency_list,
2884 dependencies_used, textlow_not_set);
2887 /* Record the toc offset value of this symbol table into objfile structure.
2888 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2889 this information would be file auxiliary header. */
2891 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset
2895 /* Return the toc offset value for a given objfile. */
2898 xcoff_get_toc_offset (struct objfile *objfile)
2901 return ((struct coff_symfile_info *)
2902 objfile->deprecated_sym_private)->toc_offset;
2906 /* Scan and build partial symbols for a symbol file.
2907 We have been initialized by a call to dbx_symfile_init, which
2908 put all the relevant info into a "struct dbx_symfile_info",
2909 hung off the objfile structure.
2911 SECTION_OFFSETS contains offsets relative to which the symbols in the
2912 various sections are (depending where the sections were actually loaded).
2916 xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
2920 struct cleanup *back_to;
2921 int num_symbols; /* # of symbols */
2922 file_ptr symtab_offset; /* symbol table and */
2923 file_ptr stringtab_offset; /* string table file offsets */
2924 struct coff_symfile_info *info;
2928 info = (struct coff_symfile_info *) objfile->deprecated_sym_private;
2929 symfile_bfd = abfd = objfile->obfd;
2930 name = objfile->name;
2932 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2933 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2934 stringtab_offset = symtab_offset +
2935 num_symbols * coff_data (abfd)->local_symesz;
2937 info->min_lineno_offset = 0;
2938 info->max_lineno_offset = 0;
2939 bfd_map_over_sections (abfd, find_linenos, info);
2941 if (num_symbols > 0)
2943 /* Read the string table. */
2944 init_stringtab (abfd, stringtab_offset, objfile);
2946 /* Read the .debug section, if present. */
2948 struct bfd_section *secp;
2949 bfd_size_type length;
2950 char *debugsec = NULL;
2952 secp = bfd_get_section_by_name (abfd, ".debug");
2955 length = bfd_section_size (abfd, secp);
2959 (char *) obstack_alloc (&objfile->objfile_obstack, length);
2961 if (!bfd_get_section_contents (abfd, secp, debugsec,
2962 (file_ptr) 0, length))
2964 error (_("Error reading .debug section of `%s': %s"),
2965 name, bfd_errmsg (bfd_get_error ()));
2969 ((struct coff_symfile_info *)
2970 objfile->deprecated_sym_private)->debugsec
2975 /* Read the symbols. We keep them in core because we will want to
2976 access them randomly in read_symbol*. */
2977 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2979 error (_("Error reading symbols from %s: %s"),
2980 name, bfd_errmsg (bfd_get_error ()));
2981 size = coff_data (abfd)->local_symesz * num_symbols;
2982 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl =
2983 obstack_alloc (&objfile->objfile_obstack, size);
2984 ((struct coff_symfile_info *)
2985 objfile->deprecated_sym_private)->symtbl_num_syms
2988 val = bfd_bread (((struct coff_symfile_info *)
2989 objfile->deprecated_sym_private)->symtbl,
2992 perror_with_name (_("reading symbol table"));
2994 /* If we are reinitializing, or if we have never loaded syms yet, init */
2995 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2996 /* I'm not sure how how good num_symbols is; the rule of thumb in
2997 init_psymbol_list was developed for a.out. On the one hand,
2998 num_symbols includes auxents. On the other hand, it doesn't
3000 init_psymbol_list (objfile, num_symbols);
3002 free_pending_blocks ();
3003 back_to = make_cleanup (really_free_pendings, 0);
3005 init_minimal_symbol_collection ();
3006 make_cleanup_discard_minimal_symbols ();
3008 /* Now that the symbol table data of the executable file are all in core,
3009 process them and define symbols accordingly. */
3011 scan_xcoff_symtab (objfile);
3013 /* Install any minimal symbols that have been collected as the current
3014 minimal symbols for this objfile. */
3016 install_minimal_symbols (objfile);
3018 do_cleanups (back_to);
3022 xcoff_symfile_offsets (struct objfile *objfile,
3023 struct section_addr_info *addrs)
3025 asection *sect = NULL;
3028 objfile->num_sections = bfd_count_sections (objfile->obfd);
3029 objfile->section_offsets = (struct section_offsets *)
3030 obstack_alloc (&objfile->objfile_obstack,
3031 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
3033 /* Initialize the section indexes for future use. */
3034 sect = bfd_get_section_by_name (objfile->obfd, ".text");
3036 objfile->sect_index_text = sect->index;
3038 sect = bfd_get_section_by_name (objfile->obfd, ".data");
3040 objfile->sect_index_data = sect->index;
3042 sect = bfd_get_section_by_name (objfile->obfd, ".bss");
3044 objfile->sect_index_bss = sect->index;
3046 sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
3048 objfile->sect_index_rodata = sect->index;
3050 for (i = 0; i < objfile->num_sections; ++i)
3052 /* syms_from_objfile kindly subtracts from addr the
3053 bfd_section_vma of the .text section. This strikes me as
3054 wrong--whether the offset to be applied to symbol reading is
3055 relative to the start address of the section depends on the
3056 symbol format. In any event, this whole "addr" concept is
3057 pretty broken (it doesn't handle any section but .text
3058 sensibly), so just ignore the addr parameter and use 0.
3059 rs6000-nat.c will set the correct section offsets via
3060 objfile_relocate. */
3061 (objfile->section_offsets)->offsets[i] = 0;
3065 /* Register our ability to parse symbols for xcoff BFD files. */
3067 static const struct sym_fns xcoff_sym_fns =
3070 /* It is possible that coff and xcoff should be merged as
3071 they do have fundamental similarities (for example, the extra storage
3072 classes used for stabs could presumably be recognized in any COFF file).
3073 However, in addition to obvious things like all the csect hair, there are
3074 some subtler differences between xcoffread.c and coffread.c, notably
3075 the fact that coffread.c has no need to read in all the symbols, but
3076 xcoffread.c reads all the symbols and does in fact randomly access them
3077 (in C_BSTAT and line number processing). */
3079 bfd_target_xcoff_flavour,
3081 xcoff_new_init, /* init anything gbl to entire symtab */
3082 xcoff_symfile_init, /* read initial info, setup for sym_read() */
3083 xcoff_initial_scan, /* read a symbol file into symtab */
3084 xcoff_symfile_finish, /* finished with file, cleanup */
3085 xcoff_symfile_offsets, /* xlate offsets ext->int form */
3086 default_symfile_segments, /* Get segment information from a file. */
3087 aix_process_linenos,
3088 default_symfile_relocate, /* Relocate a debug section. */
3092 /* Provide a prototype to silence -Wmissing-prototypes. */
3093 extern initialize_file_ftype _initialize_xcoffread;
3096 _initialize_xcoffread (void)
3098 add_symtab_fns (&xcoff_sym_fns);