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 /* Return the section number (SECT_OFF_*) that CS points to. */
277 secnum_to_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 /* Return the BFD section that CS points to. */
293 secnum_to_bfd_section (int secnum, struct objfile *objfile)
295 int off = SECT_OFF_TEXT (objfile);
297 asection *sect = NULL;
298 struct find_targ_sec_arg args;
299 args.targ_index = secnum;
301 args.bfd_sect = §
302 args.objfile = objfile;
303 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
307 /* add a given stab string into given stab vector. */
312 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
314 if (*stabvector == NULL)
316 *stabvector = (struct pending_stabs *)
317 xmalloc (sizeof (struct pending_stabs) +
318 INITIAL_STABVECTOR_LENGTH * sizeof (char *));
319 (*stabvector)->count = 0;
320 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
322 else if ((*stabvector)->count >= (*stabvector)->length)
324 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
325 *stabvector = (struct pending_stabs *)
326 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
327 (*stabvector)->length * sizeof (char *));
329 (*stabvector)->stab[(*stabvector)->count++] = stabname;
334 /* Linenos are processed on a file-by-file basis.
338 1) xlc (IBM's native c compiler) postpones static function code
339 emission to the end of a compilation unit. This way it can
340 determine if those functions (statics) are needed or not, and
341 can do some garbage collection (I think). This makes line
342 numbers and corresponding addresses unordered, and we end up
343 with a line table like:
360 and that breaks gdb's binary search on line numbers, if the
361 above table is not sorted on line numbers. And that sort
362 should be on function based, since gcc can emit line numbers
365 10 0x100 - for the init/test part of a for stmt.
368 10 0x400 - for the increment part of a for stmt.
370 arrange_linetable() will do this sorting.
372 2) aix symbol table might look like:
374 c_file // beginning of a new file
375 .bi // beginning of include file
376 .ei // end of include file
380 basically, .bi/.ei pairs do not necessarily encapsulate
381 their scope. They need to be recorded, and processed later
382 on when we come the end of the compilation unit.
383 Include table (inclTable) and process_linenos() handle
389 /* compare line table entry addresses. */
392 compare_lte (const void *lte1p, const void *lte2p)
394 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
395 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
397 return lte1->pc - lte2->pc;
400 /* Given a line table with function entries are marked, arrange its
401 functions in ascending order and strip off function entry markers
402 and return it in a newly created table. If the old one is good
403 enough, return the old one. */
404 /* FIXME: I think all this stuff can be replaced by just passing
405 sort_linevec = 1 to end_symtab. */
407 static struct linetable *
408 arrange_linetable (struct linetable *oldLineTb)
410 int ii, jj, newline, /* new line count */
411 function_count; /* # of functions */
413 struct linetable_entry *fentry; /* function entry vector */
414 int fentry_size; /* # of function entries */
415 struct linetable *newLineTb; /* new line table */
417 #define NUM_OF_FUNCTIONS 20
419 fentry_size = NUM_OF_FUNCTIONS;
420 fentry = (struct linetable_entry *)
421 xmalloc (fentry_size * sizeof (struct linetable_entry));
423 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
425 if (oldLineTb->item[ii].line == 0)
426 { /* Function entry found. */
427 if (function_count >= fentry_size)
428 { /* Make sure you have room. */
430 fentry = (struct linetable_entry *)
432 fentry_size * sizeof (struct linetable_entry));
434 fentry[function_count].line = ii;
435 fentry[function_count].pc = oldLineTb->item[ii].pc;
440 if (function_count == 0)
445 else if (function_count > 1)
446 qsort (fentry, function_count,
447 sizeof (struct linetable_entry), compare_lte);
449 /* Allocate a new line table. */
450 newLineTb = (struct linetable *)
452 (sizeof (struct linetable) +
453 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
455 /* If line table does not start with a function beginning, copy up until
459 if (oldLineTb->item[0].line != 0)
461 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
462 newLineTb->item[newline] = oldLineTb->item[newline];
464 /* Now copy function lines one by one. */
466 for (ii = 0; ii < function_count; ++ii)
468 for (jj = fentry[ii].line + 1;
469 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
471 newLineTb->item[newline] = oldLineTb->item[jj];
474 newLineTb->nitems = oldLineTb->nitems - function_count;
478 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
479 following `IncludeChain'. At the end of each symtab (end_symtab),
480 we will determine if we should create additional symtab's to
481 represent if (the include files. */
484 typedef struct _inclTable
486 char *name; /* include filename */
488 /* Offsets to the line table. end points to the last entry which is
489 part of this include file. */
492 struct subfile *subfile;
493 unsigned funStartLine; /* Start line # of its function. */
497 #define INITIAL_INCLUDE_TABLE_LENGTH 20
498 static InclTable *inclTable; /* global include table */
499 static int inclIndx; /* last entry to table */
500 static int inclLength; /* table length */
501 static int inclDepth; /* nested include depth */
503 static void allocate_include_entry (void);
506 record_include_begin (struct coff_symbol *cs)
510 /* In xcoff, we assume include files cannot be nested (not in .c files
511 of course, but in corresponding .s files.). */
513 /* This can happen with old versions of GCC.
514 GCC 2.3.3-930426 does not exhibit this on a test case which
515 a user said produced the message for him. */
516 complaint (&symfile_complaints, _("Nested C_BINCL symbols"));
520 allocate_include_entry ();
522 inclTable[inclIndx].name = cs->c_name;
523 inclTable[inclIndx].begin = cs->c_value;
527 record_include_end (struct coff_symbol *cs)
533 complaint (&symfile_complaints, _("Mismatched C_BINCL/C_EINCL pair"));
536 allocate_include_entry ();
538 pTbl = &inclTable[inclIndx];
539 pTbl->end = cs->c_value;
546 allocate_include_entry (void)
548 if (inclTable == NULL)
550 inclTable = (InclTable *)
551 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
553 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
554 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
557 else if (inclIndx >= inclLength)
559 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
560 inclTable = (InclTable *)
561 xrealloc (inclTable, sizeof (InclTable) * inclLength);
562 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
563 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
567 /* Global variable to pass the psymtab down to all the routines involved
568 in psymtab to symtab processing. */
569 static struct partial_symtab *this_symtab_psymtab;
571 /* given the start and end addresses of a compilation unit (or a csect,
572 at times) process its lines and create appropriate line vectors. */
575 process_linenos (CORE_ADDR start, CORE_ADDR end)
578 file_ptr max_offset =
579 ((struct coff_symfile_info *) this_symtab_psymtab->objfile
580 ->deprecated_sym_private)->max_lineno_offset;
582 /* subfile structure for the main compilation unit. */
583 struct subfile main_subfile;
585 /* In the main source file, any time we see a function entry, we
586 reset this variable to function's absolute starting line number.
587 All the following line numbers in the function are relative to
588 this, and we record absolute line numbers in record_line(). */
590 unsigned int main_source_baseline = 0;
595 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
597 goto return_after_cleanup;
599 memset (&main_subfile, '\0', sizeof (main_subfile));
602 /* All source lines were in the main source file. None in include
605 enter_line_range (&main_subfile, offset, 0, start, end,
606 &main_source_baseline);
610 /* There was source with line numbers in include files. */
613 coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
614 main_source_baseline = 0;
616 for (ii = 0; ii < inclIndx; ++ii)
618 struct subfile *tmpSubfile;
620 /* If there is main file source before include file, enter it. */
621 if (offset < inclTable[ii].begin)
624 (&main_subfile, offset, inclTable[ii].begin - linesz,
625 start, 0, &main_source_baseline);
628 if (strcmp (inclTable[ii].name, last_source_file) == 0)
630 /* The entry in the include table refers to the main source
631 file. Add the lines to the main subfile. */
633 main_source_baseline = inclTable[ii].funStartLine;
635 (&main_subfile, inclTable[ii].begin, inclTable[ii].end,
636 start, 0, &main_source_baseline);
637 inclTable[ii].subfile = &main_subfile;
641 /* Have a new subfile for the include file. */
643 tmpSubfile = inclTable[ii].subfile =
644 (struct subfile *) xmalloc (sizeof (struct subfile));
646 memset (tmpSubfile, '\0', sizeof (struct subfile));
647 firstLine = &(inclTable[ii].funStartLine);
649 /* Enter include file's lines now. */
650 enter_line_range (tmpSubfile, inclTable[ii].begin,
651 inclTable[ii].end, start, 0, firstLine);
654 if (offset <= inclTable[ii].end)
655 offset = inclTable[ii].end + linesz;
658 /* All the include files' line have been processed at this point. Now,
659 enter remaining lines of the main file, if any left. */
660 if (offset < max_offset + 1 - linesz)
662 enter_line_range (&main_subfile, offset, 0, start, end,
663 &main_source_baseline);
667 /* Process main file's line numbers. */
668 if (main_subfile.line_vector)
670 struct linetable *lineTb, *lv;
672 lv = main_subfile.line_vector;
674 /* Line numbers are not necessarily ordered. xlc compilation will
675 put static function to the end. */
677 lineTb = arrange_linetable (lv);
680 current_subfile->line_vector = (struct linetable *)
681 xrealloc (lv, (sizeof (struct linetable)
682 + lv->nitems * sizeof (struct linetable_entry)));
687 current_subfile->line_vector = lineTb;
690 current_subfile->line_vector_length =
691 current_subfile->line_vector->nitems;
694 /* Now, process included files' line numbers. */
696 for (ii = 0; ii < inclIndx; ++ii)
698 if (inclTable[ii].subfile != ((struct subfile *) &main_subfile)
699 && (inclTable[ii].subfile)->line_vector) /* Useless if!!!
702 struct linetable *lineTb, *lv;
704 lv = (inclTable[ii].subfile)->line_vector;
706 /* Line numbers are not necessarily ordered. xlc compilation will
707 put static function to the end. */
709 lineTb = arrange_linetable (lv);
713 /* For the same include file, we might want to have more than one
714 subfile. This happens if we have something like:
722 while foo.h including code in it. (stupid but possible)
723 Since start_subfile() looks at the name and uses an
724 existing one if finds, we need to provide a fake name and
728 start_subfile (inclTable[ii].name, (char *) 0);
731 /* Pick a fake name that will produce the same results as this
732 one when passed to deduce_language_from_filename. Kludge on
734 char *fakename = strrchr (inclTable[ii].name, '.');
736 if (fakename == NULL)
738 start_subfile (fakename, (char *) 0);
739 xfree (current_subfile->name);
741 current_subfile->name = xstrdup (inclTable[ii].name);
746 current_subfile->line_vector =
747 (struct linetable *) xrealloc
748 (lv, (sizeof (struct linetable)
749 + lv->nitems * sizeof (struct linetable_entry)));
755 current_subfile->line_vector = lineTb;
758 current_subfile->line_vector_length =
759 current_subfile->line_vector->nitems;
760 start_subfile (pop_subfile (), (char *) 0);
764 return_after_cleanup:
766 /* We don't want to keep alloc/free'ing the global include file table. */
769 /* Start with a fresh subfile structure for the next file. */
770 memset (&main_subfile, '\0', sizeof (struct subfile));
774 aix_process_linenos (void)
776 /* There is no linenos to read if there are only dwarf info. */
777 if (this_symtab_psymtab == NULL)
780 /* Process line numbers and enter them into line vector. */
781 process_linenos (last_source_start_addr, cur_src_end_addr);
785 /* Enter a given range of lines into the line vector.
786 can be called in the following two ways:
787 enter_line_range (subfile, beginoffset, endoffset,
788 startaddr, 0, firstLine) or
789 enter_line_range (subfile, beginoffset, 0,
790 startaddr, endaddr, firstLine)
792 endoffset points to the last line table entry that we should pay
796 enter_line_range (struct subfile *subfile, unsigned beginoffset,
797 unsigned endoffset, /* offsets to line table */
798 CORE_ADDR startaddr, /* offsets to line table */
799 CORE_ADDR endaddr, unsigned *firstLine)
801 struct objfile *objfile = this_symtab_psymtab->objfile;
802 struct gdbarch *gdbarch = get_objfile_arch (objfile);
803 unsigned int curoffset;
806 struct internal_lineno int_lnno;
807 unsigned int limit_offset;
811 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
813 curoffset = beginoffset;
815 ((struct coff_symfile_info *) objfile->deprecated_sym_private)
820 if (endoffset >= limit_offset)
822 complaint (&symfile_complaints,
823 _("Bad line table offset in C_EINCL directive"));
826 limit_offset = endoffset;
831 abfd = objfile->obfd;
832 linesz = coff_data (abfd)->local_linesz;
833 ext_lnno = alloca (linesz);
835 while (curoffset <= limit_offset)
837 bfd_seek (abfd, curoffset, SEEK_SET);
838 bfd_bread (ext_lnno, linesz, abfd);
839 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
841 /* Find the address this line represents. */
842 addr = (int_lnno.l_lnno
843 ? int_lnno.l_addr.l_paddr
844 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
845 addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
847 if (addr < startaddr || (endaddr && addr >= endaddr))
850 if (int_lnno.l_lnno == 0)
852 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
853 record_line (subfile, 0, gdbarch_addr_bits_remove (gdbarch, addr));
857 record_line (subfile, *firstLine + int_lnno.l_lnno,
858 gdbarch_addr_bits_remove (gdbarch, addr));
864 /* Save the vital information for use when closing off the current file.
865 NAME is the file name the symbols came from, START_ADDR is the first
866 text address for the file, and SIZE is the number of bytes of text. */
868 #define complete_symtab(name, start_addr) { \
869 last_source_file = xstrdup (name); \
870 last_source_start_addr = start_addr; \
874 /* Refill the symbol table input buffer
875 and set the variables that control fetching entries from it.
876 Reports an error if no data available.
877 This function can read past the end of the symbol table
878 (into the string table) but this does no harm. */
880 /* Reading symbol table has to be fast! Keep the followings as macros, rather
883 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
885 const char *namestr; \
888 if (namestr[0] == '.') ++namestr; \
889 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
890 (SECTION), (asection *)NULL, \
892 misc_func_recorded = 1; \
896 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
897 nested. At any given time, a symbol can only be in one static block.
898 This is the base address of current static block, zero if non exists. */
900 static int static_block_base = 0;
902 /* Section number for the current static block. */
904 static int static_block_section = -1;
906 /* true if space for symbol name has been allocated. */
908 static int symname_alloced = 0;
910 /* Next symbol to read. Pointer into raw seething symbol table. */
912 static char *raw_symbol;
914 /* This is the function which stabsread.c calls to get symbol
918 xcoff_next_symbol_text (struct objfile *objfile)
920 struct internal_syment symbol;
923 /* FIXME: is this the same as the passed arg? */
924 if (this_symtab_psymtab)
925 objfile = this_symtab_psymtab->objfile;
927 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
930 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
932 /* Return something which points to '\0' and hope the symbol reading
933 code does something reasonable. */
936 else if (symbol.n_sclass & 0x80)
938 retval = ((struct coff_symfile_info *)
939 objfile->deprecated_sym_private)->debugsec
941 raw_symbol += coff_data (objfile->obfd)->local_symesz;
946 complaint (&symfile_complaints, _("Unexpected symbol continuation"));
948 /* Return something which points to '\0' and hope the symbol reading
949 code does something reasonable. */
955 /* Read symbols for a given partial symbol table. */
958 read_xcoff_symtab (struct partial_symtab *pst)
960 struct objfile *objfile = pst->objfile;
961 bfd *abfd = objfile->obfd;
962 char *raw_auxptr; /* Pointer to first raw aux entry for sym. */
964 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl;
966 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->debugsec;
967 const char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
969 struct internal_syment symbol[1];
970 union internal_auxent main_aux;
971 struct coff_symbol cs[1];
972 CORE_ADDR file_start_addr = 0;
973 CORE_ADDR file_end_addr = 0;
975 int next_file_symnum = -1;
976 unsigned int max_symnum;
977 int just_started = 1;
979 int fcn_start_addr = 0;
981 struct coff_symbol fcn_stab_saved = { 0 };
983 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
984 union internal_auxent fcn_aux_saved = main_aux;
985 struct context_stack *new;
987 char *filestring = " _start_ "; /* Name of the current file. */
989 const char *last_csect_name; /* Last seen csect's name and value. */
990 CORE_ADDR last_csect_val;
993 this_symtab_psymtab = pst;
995 /* Get the appropriate COFF "constants" related to the file we're
997 local_symesz = coff_data (abfd)->local_symesz;
999 last_source_file = NULL;
1000 last_csect_name = 0;
1004 start_symtab (filestring, (char *) NULL, file_start_addr);
1005 record_debugformat (debugfmt);
1006 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
1008 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
1009 first_object_file_end = 0;
1012 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl
1013 + symnum * local_symesz;
1015 while (symnum < max_symnum)
1017 QUIT; /* make this command interruptable. */
1019 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1020 /* read one symbol into `cs' structure. After processing the
1021 whole symbol table, only string table will be kept in memory,
1022 symbol table and debug section of xcoff will be freed. Thus
1023 we can mark symbols with names in string table as
1028 /* Swap and align the symbol into a reasonable C structure. */
1029 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1031 cs->c_symnum = symnum;
1032 cs->c_naux = symbol->n_numaux;
1033 if (symbol->n_zeroes)
1035 symname_alloced = 0;
1036 /* We must use the original, unswapped, name here so the name field
1037 pointed to by cs->c_name will persist throughout xcoffread. If
1038 we use the new field, it gets overwritten for each symbol. */
1039 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
1040 /* If it's exactly E_SYMNMLEN characters long it isn't
1042 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1046 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
1047 strncpy (p, cs->c_name, E_SYMNMLEN);
1048 p[E_SYMNMLEN] = '\0';
1050 symname_alloced = 1;
1053 else if (symbol->n_sclass & 0x80)
1055 cs->c_name = debugsec + symbol->n_offset;
1056 symname_alloced = 0;
1060 /* in string table */
1061 cs->c_name = strtbl + (int) symbol->n_offset;
1062 symname_alloced = 1;
1064 cs->c_value = symbol->n_value;
1065 cs->c_sclass = symbol->n_sclass;
1066 cs->c_secnum = symbol->n_scnum;
1067 cs->c_type = (unsigned) symbol->n_type;
1069 raw_symbol += local_symesz;
1072 /* Save addr of first aux entry. */
1073 raw_auxptr = raw_symbol;
1075 /* Skip all the auxents associated with this symbol. */
1076 for (ii = symbol->n_numaux; ii; --ii)
1078 raw_symbol += coff_data (abfd)->local_auxesz;
1083 /* if symbol name starts with ".$" or "$", ignore it. */
1084 if (cs->c_name[0] == '$'
1085 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1088 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1090 if (last_source_file)
1092 pst->symtab = end_symtab (cur_src_end_addr, objfile,
1093 SECT_OFF_TEXT (objfile));
1098 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1099 record_debugformat (debugfmt);
1100 cur_src_end_addr = first_object_file_end;
1101 /* Done with all files, everything from here on is globals. */
1104 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1107 /* Dealing with a symbol with a csect entry. */
1109 #define CSECT(PP) ((PP)->x_csect)
1110 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1111 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1112 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1113 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1115 /* Convert the auxent to something we can access. */
1116 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1117 0, cs->c_naux, &main_aux);
1119 switch (CSECT_SMTYP (&main_aux))
1123 /* Ignore all external references. */
1127 /* A section description. */
1129 switch (CSECT_SCLAS (&main_aux))
1135 /* A program csect is seen. We have to allocate one
1136 symbol table for each program csect. Normally gdb
1137 prefers one symtab for each source file. In case
1138 of AIX, one source file might include more than one
1139 [PR] csect, and they don't have to be adjacent in
1140 terms of the space they occupy in memory. Thus, one
1141 single source file might get fragmented in the
1142 memory and gdb's file start and end address
1143 approach does not work! GCC (and I think xlc) seem
1144 to put all the code in the unnamed program csect. */
1146 if (last_csect_name)
1148 complete_symtab (filestring, file_start_addr);
1149 cur_src_end_addr = file_end_addr;
1150 end_symtab (file_end_addr, objfile,
1151 SECT_OFF_TEXT (objfile));
1154 /* Give all csects for this source file the same
1156 start_symtab (filestring, NULL, (CORE_ADDR) 0);
1157 record_debugformat (debugfmt);
1160 /* If this is the very first csect seen,
1161 basically `__start'. */
1164 first_object_file_end
1165 = cs->c_value + CSECT_LEN (&main_aux);
1170 cs->c_value + ANOFFSET (objfile->section_offsets,
1171 SECT_OFF_TEXT (objfile));
1172 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1174 if (cs->c_name && (cs->c_name[0] == '.'
1175 || cs->c_name[0] == '@'))
1177 last_csect_name = cs->c_name;
1178 last_csect_val = cs->c_value;
1179 last_csect_sec = secnum_to_section (cs->c_secnum,
1185 /* All other symbols are put into the minimal symbol
1198 /* Ignore the symbol. */
1206 switch (CSECT_SCLAS (&main_aux))
1209 /* a function entry point. */
1210 function_entry_point:
1212 fcn_start_addr = cs->c_value;
1214 /* save the function header info, which will be used
1215 when `.bf' is seen. */
1217 fcn_aux_saved = main_aux;
1221 /* shared library function trampoline code entry point. */
1225 /* The symbols often have the same names as debug symbols for
1226 functions, and confuse lookup_symbol. */
1230 /* xlc puts each variable in a separate csect, so we get
1231 an XTY_SD for each variable. But gcc puts several
1232 variables in a csect, so that each variable only gets
1233 an XTY_LD. This will typically be XMC_RW; I suspect
1234 XMC_RO and XMC_BS might be possible too.
1235 These variables are put in the minimal symbol table
1242 /* Common symbols are put into the minimal symbol table only. */
1250 /* If explicitly specified as a function, treat is as one. This check
1251 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1252 after the above CSECT check. */
1253 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1255 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1256 0, cs->c_naux, &main_aux);
1257 goto function_entry_point;
1260 switch (cs->c_sclass)
1264 /* c_value field contains symnum of next .file entry in table
1265 or symnum of first global after last .file. */
1267 next_file_symnum = cs->c_value;
1269 /* Complete symbol table for last object file containing
1270 debugging information. */
1272 /* Whether or not there was a csect in the previous file, we
1273 have to call `end_stabs' and `start_stabs' to reset
1274 type_vector, line_vector, etc. structures. */
1276 complete_symtab (filestring, file_start_addr);
1277 cur_src_end_addr = file_end_addr;
1278 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1281 /* XCOFF, according to the AIX 3.2 documentation, puts the
1282 filename in cs->c_name. But xlc 1.3.0.2 has decided to
1283 do things the standard COFF way and put it in the auxent.
1284 We use the auxent if the symbol is ".file" and an auxent
1285 exists, otherwise use the symbol itself. Simple
1287 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1289 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1290 0, cs->c_naux, &main_aux);
1291 filestring = coff_getfilename (&main_aux, objfile);
1294 filestring = cs->c_name;
1297 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1298 record_debugformat (debugfmt);
1299 last_csect_name = 0;
1301 /* reset file start and end addresses. A compilation unit
1302 with no text (only data) should have zero file
1304 file_start_addr = file_end_addr = 0;
1308 fcn_stab_saved = *cs;
1312 if (strcmp (cs->c_name, ".bf") == 0)
1314 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1315 SECT_OFF_TEXT (objfile));
1317 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1318 0, cs->c_naux, &main_aux);
1320 within_function = 1;
1322 new = push_context (0, fcn_start_addr + off);
1324 new->name = define_symbol
1325 (fcn_cs_saved.c_value + off,
1326 fcn_stab_saved.c_name, 0, 0, objfile);
1327 if (new->name != NULL)
1328 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1330 else if (strcmp (cs->c_name, ".ef") == 0)
1332 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1333 0, cs->c_naux, &main_aux);
1335 /* The value of .ef is the address of epilogue code;
1336 not useful for gdb. */
1337 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1338 contains number of lines to '}' */
1340 if (context_stack_depth <= 0)
1341 { /* We attempted to pop an empty context stack. */
1342 ef_complaint (cs->c_symnum);
1343 within_function = 0;
1346 new = pop_context ();
1347 /* Stack must be empty now. */
1348 if (context_stack_depth > 0 || new == NULL)
1350 ef_complaint (cs->c_symnum);
1351 within_function = 0;
1355 finish_block (new->name, &local_symbols, new->old_blocks,
1357 (fcn_cs_saved.c_value
1358 + fcn_aux_saved.x_sym.x_misc.x_fsize
1359 + ANOFFSET (objfile->section_offsets,
1360 SECT_OFF_TEXT (objfile))),
1362 within_function = 0;
1367 /* Begin static block. */
1369 struct internal_syment symbol;
1371 read_symbol (&symbol, cs->c_value);
1372 static_block_base = symbol.n_value;
1373 static_block_section =
1374 secnum_to_section (symbol.n_scnum, objfile);
1379 /* End of static block. */
1380 static_block_base = 0;
1381 static_block_section = -1;
1392 complaint (&symfile_complaints,
1393 _("Unrecognized storage class %d."),
1408 /* beginning of include file */
1409 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1410 order. Thus, when wee see them, we might not know enough info
1411 to process them. Thus, we'll be saving them into a table
1412 (inclTable) and postpone their processing. */
1414 record_include_begin (cs);
1418 /* End of include file. */
1419 /* See the comment after case C_BINCL. */
1420 record_include_end (cs);
1424 if (strcmp (cs->c_name, ".bb") == 0)
1427 new = push_context (depth,
1429 + ANOFFSET (objfile->section_offsets,
1430 SECT_OFF_TEXT (objfile))));
1432 else if (strcmp (cs->c_name, ".eb") == 0)
1434 if (context_stack_depth <= 0)
1435 { /* We attempted to pop an empty context stack. */
1436 eb_complaint (cs->c_symnum);
1439 new = pop_context ();
1440 if (depth-- != new->depth)
1442 eb_complaint (cs->c_symnum);
1445 if (local_symbols && context_stack_depth > 0)
1447 /* Make a block for the local symbols within. */
1448 finish_block (new->name, &local_symbols, new->old_blocks,
1451 + ANOFFSET (objfile->section_offsets,
1452 SECT_OFF_TEXT (objfile))),
1455 local_symbols = new->locals;
1460 process_xcoff_symbol (cs, objfile);
1465 if (last_source_file)
1469 complete_symtab (filestring, file_start_addr);
1470 cur_src_end_addr = file_end_addr;
1471 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1472 /* When reading symbols for the last C_FILE of the objfile, try
1473 to make sure that we set pst->symtab to the symtab for the
1474 file, not to the _globals_ symtab. I'm not sure whether this
1475 actually works right or when/if it comes up. */
1476 if (pst->symtab == NULL)
1482 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1483 (SYMBOL2) = (struct symbol *) \
1484 obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); \
1485 *(SYMBOL2) = *(SYMBOL1);
1488 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1489 ((ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), \
1490 &objfile->objfile_obstack))
1493 /* process one xcoff symbol. */
1495 static struct symbol *
1496 process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
1498 struct symbol onesymbol;
1499 struct symbol *sym = &onesymbol;
1500 struct symbol *sym2 = NULL;
1506 if (cs->c_secnum < 0)
1508 /* The value is a register number, offset within a frame, etc.,
1509 and does not get relocated. */
1515 sec = secnum_to_section (cs->c_secnum, objfile);
1516 off = ANOFFSET (objfile->section_offsets, sec);
1523 memset (sym, '\0', sizeof (struct symbol));
1525 /* default assumptions */
1526 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1527 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1528 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1530 if (ISFCN (cs->c_type))
1532 /* At this point, we don't know the type of the function. This
1533 will be patched with the type from its stab entry later on in
1534 patch_block_stabs (), unless the file was compiled without -g. */
1536 SYMBOL_SET_LINKAGE_NAME (sym, SYMNAME_ALLOC (name, symname_alloced));
1537 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_text_symbol;
1539 SYMBOL_CLASS (sym) = LOC_BLOCK;
1540 SYMBOL_DUP (sym, sym2);
1542 if (cs->c_sclass == C_EXT)
1543 add_symbol_to_list (sym2, &global_symbols);
1544 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1545 add_symbol_to_list (sym2, &file_symbols);
1549 /* In case we can't figure out the type, provide default. */
1550 SYMBOL_TYPE (sym) = objfile_type (objfile)->nodebug_data_symbol;
1552 switch (cs->c_sclass)
1555 /* The values of functions and global symbols are now resolved
1556 via the global_sym_chain in stabsread.c. */
1558 if (fcn_cs_saved.c_sclass == C_EXT)
1559 add_stab_to_list (name, &global_stabs);
1561 add_stab_to_list (name, &file_stabs);
1565 add_stab_to_list (name, &global_stabs);
1570 common_block_start (cs->c_name, objfile);
1574 common_block_end (objfile);
1578 complaint (&symfile_complaints, _("Unexpected storage class: %d"),
1591 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1594 SYMBOL_SECTION (sym) = sec;
1601 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1602 all statics and we need to distinguish file-scope versus
1603 function-scope using within_function. We do this by
1604 changing the string we pass to define_symbol to use 'S'
1605 where we need to, which is not necessarily super-clean,
1606 but seems workable enough. */
1611 pp = strchr (name, ':');
1616 if (*pp == 'V' && !within_function)
1618 sym = define_symbol ((cs->c_value
1619 + ANOFFSET (objfile->section_offsets,
1620 static_block_section)),
1621 cs->c_name, 0, 0, objfile);
1624 SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1625 SYMBOL_SECTION (sym) = static_block_section;
1634 /* Extract the file name from the aux entry of a C_FILE symbol.
1635 Result is in static storage and is only good for temporary use. */
1638 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1640 static char buffer[BUFSIZ];
1642 if (aux_entry->x_file.x_n.x_zeroes == 0)
1643 strcpy (buffer, ((struct coff_symfile_info *)
1644 objfile->deprecated_sym_private)->strtbl
1645 + aux_entry->x_file.x_n.x_offset);
1648 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1649 buffer[FILNMLEN] = '\0';
1654 /* Set *SYMBOL to symbol number symno in symtbl. */
1656 read_symbol (struct internal_syment *symbol, int symno)
1659 = ((struct coff_symfile_info *)
1660 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl_num_syms;
1661 char *stbl = ((struct coff_symfile_info *)
1662 this_symtab_psymtab->objfile->deprecated_sym_private)->symtbl;
1664 if (symno < 0 || symno >= nsyms)
1666 complaint (&symfile_complaints, _("Invalid symbol offset"));
1667 symbol->n_value = 0;
1668 symbol->n_scnum = -1;
1671 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1672 stbl + (symno * local_symesz),
1676 /* Get value corresponding to symbol number symno in symtbl. */
1679 read_symbol_nvalue (int symno)
1681 struct internal_syment symbol[1];
1683 read_symbol (symbol, symno);
1684 return symbol->n_value;
1688 /* Find the address of the function corresponding to symno, where
1689 symno is the symbol pointed to by the linetable. */
1692 read_symbol_lineno (int symno)
1694 struct objfile *objfile = this_symtab_psymtab->objfile;
1695 int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd);
1697 struct coff_symfile_info *info =
1698 (struct coff_symfile_info *)objfile->deprecated_sym_private;
1699 int nsyms = info->symtbl_num_syms;
1700 char *stbl = info->symtbl;
1701 char *strtbl = info->strtbl;
1703 struct internal_syment symbol[1];
1704 union internal_auxent main_aux[1];
1708 bf_notfound_complaint ();
1712 /* Note that just searching for a short distance (e.g. 50 symbols)
1713 is not enough, at least in the following case.
1716 [many .stabx entries]
1717 [a few functions, referring to foo]
1721 What happens here is that the assembler moves the .stabx entries
1722 to right before the ".bf" for foo, but the symbol for "foo" is before
1723 all the stabx entries. See PR gdb/2222. */
1725 /* Maintaining a table of .bf entries might be preferable to this search.
1726 If I understand things correctly it would need to be done only for
1727 the duration of a single psymtab to symtab conversion. */
1728 while (symno < nsyms)
1730 bfd_coff_swap_sym_in (symfile_bfd,
1731 stbl + (symno * local_symesz), symbol);
1732 if (symbol->n_sclass == C_FCN)
1734 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1736 if (strcmp (name, ".bf") == 0)
1739 symno += symbol->n_numaux + 1;
1742 bf_notfound_complaint ();
1746 /* Take aux entry and return its lineno. */
1748 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1749 symbol->n_type, symbol->n_sclass,
1750 0, symbol->n_numaux, main_aux);
1752 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1755 /* Support for line number handling. */
1757 /* This function is called for every section; it finds the outer limits
1758 * of the line table (minimum and maximum file offset) so that the
1759 * mainline code can read the whole thing for efficiency.
1762 find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo)
1764 struct coff_symfile_info *info;
1766 file_ptr offset, maxoff;
1768 count = asect->lineno_count;
1770 if (strcmp (asect->name, ".text") != 0 || count == 0)
1773 size = count * coff_data (abfd)->local_linesz;
1774 info = (struct coff_symfile_info *) vpinfo;
1775 offset = asect->line_filepos;
1776 maxoff = offset + size;
1778 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1779 info->min_lineno_offset = offset;
1781 if (maxoff > info->max_lineno_offset)
1782 info->max_lineno_offset = maxoff;
1785 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1788 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1790 struct cleanup *old_chain;
1799 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1804 /* Read in all partial symtabs on which this one is dependent. */
1805 for (i = 0; i < pst->number_of_dependencies; i++)
1806 if (!pst->dependencies[i]->readin)
1808 /* Inform about additional files that need to be read in. */
1811 fputs_filtered (" ", gdb_stdout);
1813 fputs_filtered ("and ", gdb_stdout);
1815 printf_filtered ("%s...", pst->dependencies[i]->filename);
1816 wrap_here (""); /* Flush output */
1817 gdb_flush (gdb_stdout);
1819 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1822 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1824 /* Init stuff necessary for reading in symbols. */
1827 old_chain = make_cleanup (really_free_pendings, 0);
1829 read_xcoff_symtab (pst);
1831 do_cleanups (old_chain);
1837 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1839 /* Read in all of the symbols for a given psymtab for real.
1840 Be verbose about it if the user wants that. */
1843 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1853 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1858 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1859 || pst->number_of_dependencies)
1861 /* Print the message now, before reading the string table,
1862 to avoid disconcerting pauses. */
1865 printf_filtered ("Reading in symbols for %s...", pst->filename);
1866 gdb_flush (gdb_stdout);
1869 sym_bfd = pst->objfile->obfd;
1871 next_symbol_text_func = xcoff_next_symbol_text;
1873 xcoff_psymtab_to_symtab_1 (pst);
1875 /* Match with global symbols. This only needs to be done once,
1876 after all of the symtabs and dependencies have been read in. */
1877 scan_file_globals (pst->objfile);
1879 /* Finish up the debug error message. */
1881 printf_filtered ("done.\n");
1886 xcoff_new_init (struct objfile *objfile)
1888 stabsread_new_init ();
1889 buildsym_new_init ();
1892 /* Do initialization in preparation for reading symbols from OBJFILE.
1894 We will only be called if this is an XCOFF or XCOFF-like file.
1895 BFD handles figuring out the format of the file, and code in symfile.c
1896 uses BFD's determination to vector to us. */
1899 xcoff_symfile_init (struct objfile *objfile)
1901 /* Allocate struct to keep track of the symfile. */
1902 objfile->deprecated_sym_private
1903 = xmalloc (sizeof (struct coff_symfile_info));
1905 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1906 find this causes a significant slowdown in gdb then we could
1907 set it in the debug symbol readers only when necessary. */
1908 objfile->flags |= OBJF_REORDERED;
1910 init_entry_point_info (objfile);
1913 /* Perform any local cleanups required when we are done with a particular
1914 objfile. I.E, we are in the process of discarding all symbol information
1915 for an objfile, freeing up all memory held for it, and unlinking the
1916 objfile struct from the global list of known objfiles. */
1919 xcoff_symfile_finish (struct objfile *objfile)
1921 if (objfile->deprecated_sym_private != NULL)
1923 xfree (objfile->deprecated_sym_private);
1926 /* Start with a fresh include table for the next objfile. */
1932 inclIndx = inclLength = inclDepth = 0;
1934 dwarf2_free_objfile (objfile);
1939 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1943 unsigned char lengthbuf[4];
1946 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1949 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1950 error (_("cannot seek to string table in %s: %s"),
1951 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1953 val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd);
1954 length = bfd_h_get_32 (abfd, lengthbuf);
1956 /* If no string table is needed, then the file may end immediately
1957 after the symbols. Just return with `strtbl' set to NULL. */
1959 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1962 /* Allocate string table from objfile_obstack. We will need this table
1963 as long as we have its symbol table around. */
1965 strtbl = (char *) obstack_alloc (&objfile->objfile_obstack, length);
1966 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->strtbl
1969 /* Copy length buffer, the first byte is usually zero and is
1970 used for stabs with a name length of zero. */
1971 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1972 if (length == sizeof lengthbuf)
1975 val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd);
1977 if (val != length - sizeof lengthbuf)
1978 error (_("cannot read string table from %s: %s"),
1979 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1980 if (strtbl[length - 1] != '\0')
1981 error (_("bad symbol file: string table "
1982 "does not end with null character"));
1987 /* If we have not yet seen a function for this psymtab, this is 0. If we
1988 have seen one, it is the offset in the line numbers of the line numbers
1990 static unsigned int first_fun_line_offset;
1992 /* Allocate and partially fill a partial symtab. It will be
1993 completely filled at the end of the symbol list.
1995 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1996 is the address relative to which its symbols are (incremental) or 0
1999 static struct partial_symtab *
2000 xcoff_start_psymtab (struct objfile *objfile,
2001 const char *filename, int first_symnum,
2002 struct partial_symbol **global_syms,
2003 struct partial_symbol **static_syms)
2005 struct partial_symtab *result =
2006 start_psymtab_common (objfile, objfile->section_offsets,
2008 /* We fill in textlow later. */
2010 global_syms, static_syms);
2012 result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2013 sizeof (struct symloc));
2014 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
2015 result->read_symtab = xcoff_psymtab_to_symtab;
2017 /* Deduce the source language from the filename for this psymtab. */
2018 psymtab_language = deduce_language_from_filename (filename);
2023 /* Close off the current usage of PST.
2024 Returns PST, or NULL if the partial symtab was empty and thrown away.
2026 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2028 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2029 are the information for includes and dependencies. */
2031 static struct partial_symtab *
2032 xcoff_end_psymtab (struct partial_symtab *pst, const char **include_list,
2033 int num_includes, int capping_symbol_number,
2034 struct partial_symtab **dependency_list,
2035 int number_dependencies, int textlow_not_set)
2038 struct objfile *objfile = pst->objfile;
2040 if (capping_symbol_number != -1)
2041 ((struct symloc *) pst->read_symtab_private)->numsyms =
2042 capping_symbol_number
2043 - ((struct symloc *) pst->read_symtab_private)->first_symnum;
2044 ((struct symloc *) pst->read_symtab_private)->lineno_off =
2045 first_fun_line_offset;
2046 first_fun_line_offset = 0;
2047 pst->n_global_syms = objfile->global_psymbols.next
2048 - (objfile->global_psymbols.list + pst->globals_offset);
2049 pst->n_static_syms = objfile->static_psymbols.next
2050 - (objfile->static_psymbols.list + pst->statics_offset);
2052 pst->number_of_dependencies = number_dependencies;
2053 if (number_dependencies)
2055 pst->dependencies = (struct partial_symtab **)
2056 obstack_alloc (&objfile->objfile_obstack,
2057 number_dependencies * sizeof (struct partial_symtab *));
2058 memcpy (pst->dependencies, dependency_list,
2059 number_dependencies * sizeof (struct partial_symtab *));
2062 pst->dependencies = 0;
2064 for (i = 0; i < num_includes; i++)
2066 struct partial_symtab *subpst =
2067 allocate_psymtab (include_list[i], objfile);
2069 subpst->section_offsets = pst->section_offsets;
2070 subpst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2071 sizeof (struct symloc));
2072 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2073 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2074 subpst->textlow = 0;
2075 subpst->texthigh = 0;
2077 /* We could save slight bits of space by only making one of these,
2078 shared by the entire set of include files. FIXME-someday. */
2079 subpst->dependencies = (struct partial_symtab **)
2080 obstack_alloc (&objfile->objfile_obstack,
2081 sizeof (struct partial_symtab *));
2082 subpst->dependencies[0] = pst;
2083 subpst->number_of_dependencies = 1;
2085 subpst->globals_offset =
2086 subpst->n_global_syms =
2087 subpst->statics_offset =
2088 subpst->n_static_syms = 0;
2092 subpst->read_symtab = pst->read_symtab;
2095 sort_pst_symbols (pst);
2097 if (num_includes == 0
2098 && number_dependencies == 0
2099 && pst->n_global_syms == 0
2100 && pst->n_static_syms == 0)
2102 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2103 it is on the obstack, but we can forget to chain it on the list. */
2104 /* Empty psymtabs happen as a result of header files which don't have
2105 any symbols in them. There can be a lot of them. */
2107 discard_psymtab (pst);
2109 /* Indicate that psymtab was thrown away. */
2110 pst = (struct partial_symtab *) NULL;
2115 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2116 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2117 the symbol and its auxents. */
2120 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2121 const char **name, char **raw, unsigned int *symnump,
2122 struct objfile *objfile)
2124 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2125 if (symbol->n_zeroes)
2127 /* If it's exactly E_SYMNMLEN characters long it isn't
2129 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2131 /* FIXME: wastes memory for symbols which we don't end up putting
2132 into the minimal symbols. */
2135 p = obstack_alloc (&objfile->objfile_obstack, E_SYMNMLEN + 1);
2136 strncpy (p, symbol->n_name, E_SYMNMLEN);
2137 p[E_SYMNMLEN] = '\0';
2141 /* Point to the unswapped name as that persists as long as the
2143 *name = ((struct external_syment *) *raw)->e.e_name;
2145 else if (symbol->n_sclass & 0x80)
2147 *name = ((struct coff_symfile_info *)
2148 objfile->deprecated_sym_private)->debugsec + symbol->n_offset;
2152 *name = ((struct coff_symfile_info *)
2153 objfile->deprecated_sym_private)->strtbl + symbol->n_offset;
2156 *raw += coff_data (objfile->obfd)->local_symesz;
2157 if (symbol->n_numaux > 0)
2159 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2160 symbol->n_sclass, 0, symbol->n_numaux, aux);
2162 *symnump += symbol->n_numaux;
2163 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2168 function_outside_compilation_unit_complaint (const char *arg1)
2170 complaint (&symfile_complaints,
2171 _("function `%s' appears to be defined "
2172 "outside of all compilation units"),
2177 scan_xcoff_symtab (struct objfile *objfile)
2179 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2180 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
2181 const char *filestring = NULL;
2183 const char *namestring;
2184 int past_first_source_file = 0;
2189 /* Current partial symtab */
2190 struct partial_symtab *pst;
2192 /* List of current psymtab's include files. */
2193 const char **psymtab_include_list;
2194 int includes_allocated;
2197 /* Index within current psymtab dependency list. */
2198 struct partial_symtab **dependency_list;
2199 int dependencies_used, dependencies_allocated;
2202 struct internal_syment symbol;
2203 union internal_auxent main_aux[5];
2204 unsigned int ssymnum;
2206 const char *last_csect_name = NULL; /* Last seen csect's name and value. */
2207 CORE_ADDR last_csect_val = 0;
2208 int last_csect_sec = 0;
2209 int misc_func_recorded = 0; /* true if any misc. function. */
2210 int textlow_not_set = 1;
2212 pst = (struct partial_symtab *) 0;
2214 includes_allocated = 30;
2216 psymtab_include_list = (const char **) alloca (includes_allocated *
2217 sizeof (const char *));
2219 dependencies_allocated = 30;
2220 dependencies_used = 0;
2222 (struct partial_symtab **) alloca (dependencies_allocated *
2223 sizeof (struct partial_symtab *));
2225 last_source_file = NULL;
2227 abfd = objfile->obfd;
2228 next_symbol_text_func = xcoff_next_symbol_text;
2230 sraw_symbol = ((struct coff_symfile_info *)
2231 objfile->deprecated_sym_private)->symtbl;
2232 nsyms = ((struct coff_symfile_info *)
2233 objfile->deprecated_sym_private)->symtbl_num_syms;
2235 while (ssymnum < nsyms)
2241 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2242 sclass = symbol.n_sclass;
2249 /* The CSECT auxent--always the last auxent. */
2250 union internal_auxent csect_aux;
2251 unsigned int symnum_before = ssymnum;
2253 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2255 if (symbol.n_numaux > 1)
2257 bfd_coff_swap_aux_in
2259 sraw_symbol - coff_data (abfd)->local_symesz,
2262 symbol.n_numaux - 1,
2267 csect_aux = main_aux[0];
2269 /* If symbol name starts with ".$" or "$", ignore it. */
2270 if (namestring[0] == '$'
2271 || (namestring[0] == '.' && namestring[1] == '$'))
2274 switch (csect_aux.x_csect.x_smtyp & 0x7)
2277 switch (csect_aux.x_csect.x_smclas)
2280 if (last_csect_name)
2282 /* If no misc. function recorded in the last
2283 seen csect, enter it as a function. This
2284 will take care of functions like strcmp()
2287 if (!misc_func_recorded)
2289 RECORD_MINIMAL_SYMBOL
2290 (last_csect_name, last_csect_val,
2291 mst_text, last_csect_sec,
2297 /* We have to allocate one psymtab for
2298 each program csect, because their text
2299 sections need not be adjacent. */
2301 (pst, psymtab_include_list, includes_used,
2302 symnum_before, dependency_list,
2303 dependencies_used, textlow_not_set);
2305 dependencies_used = 0;
2306 /* Give all psymtabs for this source file the same
2308 pst = xcoff_start_psymtab
2312 objfile->global_psymbols.next,
2313 objfile->static_psymbols.next);
2316 /* Activate the misc_func_recorded mechanism for
2317 compiler- and linker-generated CSECTs like ".strcmp"
2319 if (namestring && (namestring[0] == '.'
2320 || namestring[0] == '@'))
2322 last_csect_name = namestring;
2323 last_csect_val = symbol.n_value;
2325 secnum_to_section (symbol.n_scnum, objfile);
2330 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2332 if (highval > pst->texthigh)
2333 pst->texthigh = highval;
2334 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2335 pst->textlow = symbol.n_value;
2337 misc_func_recorded = 0;
2342 /* Data variables are recorded in the minimal symbol
2343 table, except for section symbols. */
2344 if (*namestring != '.')
2345 prim_record_minimal_symbol_and_info
2346 (namestring, symbol.n_value,
2347 sclass == C_HIDEXT ? mst_file_data : mst_data,
2348 secnum_to_section (symbol.n_scnum, objfile),
2354 warning (_("More than one XMC_TC0 symbol found."));
2355 toc_offset = symbol.n_value;
2357 /* Make TOC offset relative to start address of
2359 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2361 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
2365 /* These symbols tell us where the TOC entry for a
2366 variable is, not the variable itself. */
2375 switch (csect_aux.x_csect.x_smclas)
2378 /* A function entry point. */
2380 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2381 first_fun_line_offset =
2382 main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
2383 RECORD_MINIMAL_SYMBOL
2384 (namestring, symbol.n_value,
2385 sclass == C_HIDEXT ? mst_file_text : mst_text,
2386 secnum_to_section (symbol.n_scnum, objfile),
2391 /* shared library function trampoline code entry
2394 /* record trampoline code entries as
2395 mst_solib_trampoline symbol. When we lookup mst
2396 symbols, we will choose mst_text over
2397 mst_solib_trampoline. */
2398 RECORD_MINIMAL_SYMBOL
2399 (namestring, symbol.n_value,
2400 mst_solib_trampoline,
2401 secnum_to_section (symbol.n_scnum, objfile),
2406 /* The symbols often have the same names as
2407 debug symbols for functions, and confuse
2413 /* xlc puts each variable in a separate csect,
2414 so we get an XTY_SD for each variable. But
2415 gcc puts several variables in a csect, so
2416 that each variable only gets an XTY_LD. We
2417 still need to record them. This will
2418 typically be XMC_RW; I suspect XMC_RO and
2419 XMC_BS might be possible too. */
2420 if (*namestring != '.')
2421 prim_record_minimal_symbol_and_info
2422 (namestring, symbol.n_value,
2423 sclass == C_HIDEXT ? mst_file_data : mst_data,
2424 secnum_to_section (symbol.n_scnum, objfile),
2431 switch (csect_aux.x_csect.x_smclas)
2435 /* Common variables are recorded in the minimal symbol
2436 table, except for section symbols. */
2437 if (*namestring != '.')
2438 prim_record_minimal_symbol_and_info
2439 (namestring, symbol.n_value,
2440 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2441 secnum_to_section (symbol.n_scnum, objfile),
2454 unsigned int symnum_before;
2456 symnum_before = ssymnum;
2457 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2460 /* See if the last csect needs to be recorded. */
2462 if (last_csect_name && !misc_func_recorded)
2464 /* If no misc. function recorded in the last seen csect, enter
2465 it as a function. This will take care of functions like
2466 strcmp() compiled by xlc. */
2468 RECORD_MINIMAL_SYMBOL
2469 (last_csect_name, last_csect_val,
2470 mst_text, last_csect_sec, objfile);
2475 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2476 symnum_before, dependency_list,
2477 dependencies_used, textlow_not_set);
2479 dependencies_used = 0;
2481 first_fun_line_offset = 0;
2483 /* XCOFF, according to the AIX 3.2 documentation, puts the
2484 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2485 do things the standard COFF way and put it in the auxent.
2486 We use the auxent if the symbol is ".file" and an auxent
2487 exists, otherwise use the symbol itself. */
2488 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2490 filestring = coff_getfilename (&main_aux[0], objfile);
2493 filestring = namestring;
2495 pst = xcoff_start_psymtab (objfile,
2498 objfile->global_psymbols.next,
2499 objfile->static_psymbols.next);
2500 last_csect_name = NULL;
2506 complaint (&symfile_complaints,
2507 _("Storage class %d not recognized during scan"),
2512 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2513 to handle only the C_FUN and C_EXT. */
2528 /* C_EINCL means we are switching back to the main file. But there
2529 is no reason to care; the only thing we want to know about
2530 includes is the names of all the included (.h) files. */
2535 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2539 /* I don't think the name of the common block (as opposed to the
2540 variables within it) is something which is user visible
2548 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2549 so C_LSYM would appear to be only for locals. */
2555 /* We probably could save a few instructions by assuming that
2556 C_LSYM, C_PSYM, etc., never have auxents. */
2557 int naux1 = symbol.n_numaux + 1;
2560 sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2566 /* Mark down an include file in the current psymtab. */
2567 enum language tmp_language;
2569 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2572 tmp_language = deduce_language_from_filename (namestring);
2574 /* Only change the psymtab's language if we've learned
2575 something useful (eg. tmp_language is not language_unknown).
2576 In addition, to match what start_subfile does, never change
2578 if (tmp_language != language_unknown
2579 && (tmp_language != language_c
2580 || psymtab_language != language_cplus))
2581 psymtab_language = tmp_language;
2583 /* In C++, one may expect the same filename to come round many
2584 times, when code is coming alternately from the main file
2585 and from inline functions in other files. So I check to see
2586 if this is a file we've seen before -- either the main
2587 source file, or a previously included file.
2589 This seems to be a lot of time to be spending on N_SOL, but
2590 things like "break c-exp.y:435" need to work (I
2591 suppose the psymtab_include_list could be hashed or put
2592 in a binary tree, if profiling shows this is a major hog). */
2593 if (pst && strcmp (namestring, pst->filename) == 0)
2599 for (i = 0; i < includes_used; i++)
2600 if (strcmp (namestring, psymtab_include_list[i]) == 0)
2608 psymtab_include_list[includes_used++] = namestring;
2609 if (includes_used >= includes_allocated)
2611 const char **orig = psymtab_include_list;
2613 psymtab_include_list = (const char **)
2614 alloca ((includes_allocated *= 2) *
2615 sizeof (const char *));
2616 memcpy (psymtab_include_list, orig,
2617 includes_used * sizeof (const char *));
2622 /* The value of the C_FUN is not the address of the function (it
2623 appears to be the address before linking), but as long as it
2624 is smaller than the actual address, then find_pc_partial_function
2625 will use the minimal symbols instead. I hope. */
2634 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2637 p = strchr (namestring, ':');
2639 continue; /* Not a debugging symbol. */
2641 /* Main processing section for debugging symbols which
2642 the initial read through the symbol tables needs to worry
2643 about. If we reach this point, the symbol which we are
2644 considering is definitely one we are interested in.
2645 p must also contain the (valid) index into the namestring
2646 which indicates the debugging type symbol. */
2651 symbol.n_value += ANOFFSET (objfile->section_offsets,
2652 SECT_OFF_DATA (objfile));
2654 if (gdbarch_static_transform_name_p (gdbarch))
2655 namestring = gdbarch_static_transform_name
2656 (gdbarch, namestring);
2658 add_psymbol_to_list (namestring, p - namestring, 1,
2659 VAR_DOMAIN, LOC_STATIC,
2660 &objfile->static_psymbols,
2662 psymtab_language, objfile);
2666 symbol.n_value += ANOFFSET (objfile->section_offsets,
2667 SECT_OFF_DATA (objfile));
2668 /* The addresses in these entries are reported to be
2669 wrong. See the code that reads 'G's for symtabs. */
2670 add_psymbol_to_list (namestring, p - namestring, 1,
2671 VAR_DOMAIN, LOC_STATIC,
2672 &objfile->global_psymbols,
2674 psymtab_language, objfile);
2678 /* When a 'T' entry is defining an anonymous enum, it
2679 may have a name which is the empty string, or a
2680 single space. Since they're not really defining a
2681 symbol, those shouldn't go in the partial symbol
2682 table. We do pick up the elements of such enums at
2683 'check_enum:', below. */
2684 if (p >= namestring + 2
2685 || (p == namestring + 1
2686 && namestring[0] != ' '))
2688 add_psymbol_to_list (namestring, p - namestring, 1,
2689 STRUCT_DOMAIN, LOC_TYPEDEF,
2690 &objfile->static_psymbols,
2692 psymtab_language, objfile);
2695 /* Also a typedef with the same name. */
2696 add_psymbol_to_list (namestring, p - namestring, 1,
2697 VAR_DOMAIN, LOC_TYPEDEF,
2698 &objfile->static_psymbols,
2700 psymtab_language, objfile);
2707 if (p != namestring) /* a name is there, not just :T... */
2709 add_psymbol_to_list (namestring, p - namestring, 1,
2710 VAR_DOMAIN, LOC_TYPEDEF,
2711 &objfile->static_psymbols,
2713 psymtab_language, objfile);
2716 /* If this is an enumerated type, we need to
2717 add all the enum constants to the partial symbol
2718 table. This does not cover enums without names, e.g.
2719 "enum {a, b} c;" in C, but fortunately those are
2720 rare. There is no way for GDB to find those from the
2721 enum type without spending too much time on it. Thus
2722 to solve this problem, the compiler needs to put out the
2723 enum in a nameless type. GCC2 does this. */
2725 /* We are looking for something of the form
2726 <name> ":" ("t" | "T") [<number> "="] "e"
2727 {<constant> ":" <value> ","} ";". */
2729 /* Skip over the colon and the 't' or 'T'. */
2731 /* This type may be given a number. Also, numbers can come
2732 in pairs like (0,26). Skip over it. */
2733 while ((*p >= '0' && *p <= '9')
2734 || *p == '(' || *p == ',' || *p == ')'
2740 /* The aix4 compiler emits extra crud before the
2744 /* Skip over the type (?). */
2748 /* Skip over the colon. */
2752 /* We have found an enumerated type. */
2753 /* According to comments in read_enum_type
2754 a comma could end it instead of a semicolon.
2755 I don't know where that happens.
2757 while (*p && *p != ';' && *p != ',')
2761 /* Check for and handle cretinous dbx symbol name
2763 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
2764 p = next_symbol_text (objfile);
2766 /* Point to the character after the name
2767 of the enum constant. */
2768 for (q = p; *q && *q != ':'; q++)
2770 /* Note that the value doesn't matter for
2771 enum constants in psymtabs, just in symtabs. */
2772 add_psymbol_to_list (p, q - p, 1,
2773 VAR_DOMAIN, LOC_CONST,
2774 &objfile->static_psymbols, 0,
2775 0, psymtab_language, objfile);
2776 /* Point past the name. */
2778 /* Skip over the value. */
2779 while (*p && *p != ',')
2781 /* Advance past the comma. */
2789 /* Constant, e.g. from "const" in Pascal. */
2790 add_psymbol_to_list (namestring, p - namestring, 1,
2791 VAR_DOMAIN, LOC_CONST,
2792 &objfile->static_psymbols, symbol.n_value,
2793 0, psymtab_language, objfile);
2799 int name_len = p - namestring;
2800 char *name = xmalloc (name_len + 1);
2802 memcpy (name, namestring, name_len);
2803 name[name_len] = '\0';
2804 function_outside_compilation_unit_complaint (name);
2807 symbol.n_value += ANOFFSET (objfile->section_offsets,
2808 SECT_OFF_TEXT (objfile));
2809 add_psymbol_to_list (namestring, p - namestring, 1,
2810 VAR_DOMAIN, LOC_BLOCK,
2811 &objfile->static_psymbols,
2813 psymtab_language, objfile);
2816 /* Global functions were ignored here, but now they
2817 are put into the global psymtab like one would expect.
2818 They're also in the minimal symbol table. */
2822 int name_len = p - namestring;
2823 char *name = xmalloc (name_len + 1);
2825 memcpy (name, namestring, name_len);
2826 name[name_len] = '\0';
2827 function_outside_compilation_unit_complaint (name);
2831 /* We need only the minimal symbols for these
2832 loader-generated definitions. Keeping the global
2833 symbols leads to "in psymbols but not in symbols"
2835 if (strncmp (namestring, "@FIX", 4) == 0)
2838 symbol.n_value += ANOFFSET (objfile->section_offsets,
2839 SECT_OFF_TEXT (objfile));
2840 add_psymbol_to_list (namestring, p - namestring, 1,
2841 VAR_DOMAIN, LOC_BLOCK,
2842 &objfile->global_psymbols,
2844 psymtab_language, objfile);
2847 /* Two things show up here (hopefully); static symbols of
2848 local scope (static used inside braces) or extensions
2849 of structure symbols. We can ignore both. */
2863 case '#': /* For symbol identification (used in
2868 /* It is a C++ nested symbol. We don't need to record it
2869 (I don't think); if we try to look up foo::bar::baz,
2870 then symbols for the symtab containing foo should get
2871 read in, I think. */
2872 /* Someone says sun cc puts out symbols like
2873 /foo/baz/maclib::/usr/local/bin/maclib,
2874 which would get here with a symbol type of ':'. */
2878 /* Unexpected symbol descriptor. The second and
2879 subsequent stabs of a continued stab can show up
2880 here. The question is whether they ever can mimic
2881 a normal stab--it would be nice if not, since we
2882 certainly don't want to spend the time searching to
2883 the end of every string looking for a
2886 complaint (&symfile_complaints,
2887 _("unknown symbol descriptor `%c'"), p[1]);
2889 /* Ignore it; perhaps it is an extension that we don't
2899 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2900 ssymnum, dependency_list,
2901 dependencies_used, textlow_not_set);
2904 /* Record the toc offset value of this symbol table into objfile
2905 structure. If no XMC_TC0 is found, toc_offset should be zero.
2906 Another place to obtain this information would be file auxiliary
2909 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->toc_offset
2913 /* Return the toc offset value for a given objfile. */
2916 xcoff_get_toc_offset (struct objfile *objfile)
2919 return ((struct coff_symfile_info *)
2920 objfile->deprecated_sym_private)->toc_offset;
2924 /* Scan and build partial symbols for a symbol file.
2925 We have been initialized by a call to dbx_symfile_init, which
2926 put all the relevant info into a "struct dbx_symfile_info",
2927 hung off the objfile structure.
2929 SECTION_OFFSETS contains offsets relative to which the symbols in the
2930 various sections are (depending where the sections were actually
2934 xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
2938 struct cleanup *back_to;
2939 int num_symbols; /* # of symbols */
2940 file_ptr symtab_offset; /* symbol table and */
2941 file_ptr stringtab_offset; /* string table file offsets */
2942 struct coff_symfile_info *info;
2946 info = (struct coff_symfile_info *) objfile->deprecated_sym_private;
2947 symfile_bfd = abfd = objfile->obfd;
2948 name = objfile->name;
2950 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2951 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2952 stringtab_offset = symtab_offset +
2953 num_symbols * coff_data (abfd)->local_symesz;
2955 info->min_lineno_offset = 0;
2956 info->max_lineno_offset = 0;
2957 bfd_map_over_sections (abfd, find_linenos, info);
2959 if (num_symbols > 0)
2961 /* Read the string table. */
2962 init_stringtab (abfd, stringtab_offset, objfile);
2964 /* Read the .debug section, if present. */
2966 struct bfd_section *secp;
2967 bfd_size_type length;
2968 char *debugsec = NULL;
2970 secp = bfd_get_section_by_name (abfd, ".debug");
2973 length = bfd_section_size (abfd, secp);
2977 (char *) obstack_alloc (&objfile->objfile_obstack, length);
2979 if (!bfd_get_section_contents (abfd, secp, debugsec,
2980 (file_ptr) 0, length))
2982 error (_("Error reading .debug section of `%s': %s"),
2983 name, bfd_errmsg (bfd_get_error ()));
2987 ((struct coff_symfile_info *)
2988 objfile->deprecated_sym_private)->debugsec
2993 /* Read the symbols. We keep them in core because we will want to
2994 access them randomly in read_symbol*. */
2995 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2997 error (_("Error reading symbols from %s: %s"),
2998 name, bfd_errmsg (bfd_get_error ()));
2999 size = coff_data (abfd)->local_symesz * num_symbols;
3000 ((struct coff_symfile_info *) objfile->deprecated_sym_private)->symtbl =
3001 obstack_alloc (&objfile->objfile_obstack, size);
3002 ((struct coff_symfile_info *)
3003 objfile->deprecated_sym_private)->symtbl_num_syms
3006 val = bfd_bread (((struct coff_symfile_info *)
3007 objfile->deprecated_sym_private)->symtbl,
3010 perror_with_name (_("reading symbol table"));
3012 /* If we are reinitializing, or if we have never loaded syms yet, init. */
3013 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
3014 /* I'm not sure how how good num_symbols is; the rule of thumb in
3015 init_psymbol_list was developed for a.out. On the one hand,
3016 num_symbols includes auxents. On the other hand, it doesn't
3018 init_psymbol_list (objfile, num_symbols);
3020 free_pending_blocks ();
3021 back_to = make_cleanup (really_free_pendings, 0);
3023 init_minimal_symbol_collection ();
3024 make_cleanup_discard_minimal_symbols ();
3026 /* Now that the symbol table data of the executable file are all in core,
3027 process them and define symbols accordingly. */
3029 scan_xcoff_symtab (objfile);
3031 /* Install any minimal symbols that have been collected as the current
3032 minimal symbols for this objfile. */
3034 install_minimal_symbols (objfile);
3036 /* DWARF2 sections. */
3038 if (dwarf2_has_info (objfile, &dwarf2_xcoff_names))
3039 dwarf2_build_psymtabs (objfile);
3041 dwarf2_build_frame_info (objfile);
3043 do_cleanups (back_to);
3047 xcoff_symfile_offsets (struct objfile *objfile,
3048 struct section_addr_info *addrs)
3050 asection *sect = NULL;
3053 objfile->num_sections = bfd_count_sections (objfile->obfd);
3054 objfile->section_offsets = (struct section_offsets *)
3055 obstack_alloc (&objfile->objfile_obstack,
3056 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
3058 /* Initialize the section indexes for future use. */
3059 sect = bfd_get_section_by_name (objfile->obfd, ".text");
3061 objfile->sect_index_text = sect->index;
3063 sect = bfd_get_section_by_name (objfile->obfd, ".data");
3065 objfile->sect_index_data = sect->index;
3067 sect = bfd_get_section_by_name (objfile->obfd, ".bss");
3069 objfile->sect_index_bss = sect->index;
3071 sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
3073 objfile->sect_index_rodata = sect->index;
3075 for (i = 0; i < objfile->num_sections; ++i)
3077 /* syms_from_objfile kindly subtracts from addr the
3078 bfd_section_vma of the .text section. This strikes me as
3079 wrong--whether the offset to be applied to symbol reading is
3080 relative to the start address of the section depends on the
3081 symbol format. In any event, this whole "addr" concept is
3082 pretty broken (it doesn't handle any section but .text
3083 sensibly), so just ignore the addr parameter and use 0.
3084 rs6000-nat.c will set the correct section offsets via
3085 objfile_relocate. */
3086 (objfile->section_offsets)->offsets[i] = 0;
3090 /* Register our ability to parse symbols for xcoff BFD files. */
3092 static const struct sym_fns xcoff_sym_fns =
3095 /* It is possible that coff and xcoff should be merged as
3096 they do have fundamental similarities (for example, the extra storage
3097 classes used for stabs could presumably be recognized in any COFF file).
3098 However, in addition to obvious things like all the csect hair, there are
3099 some subtler differences between xcoffread.c and coffread.c, notably
3100 the fact that coffread.c has no need to read in all the symbols, but
3101 xcoffread.c reads all the symbols and does in fact randomly access them
3102 (in C_BSTAT and line number processing). */
3104 bfd_target_xcoff_flavour,
3106 xcoff_new_init, /* init anything gbl to entire symtab */
3107 xcoff_symfile_init, /* read initial info, setup for sym_read() */
3108 xcoff_initial_scan, /* read a symbol file into symtab */
3109 NULL, /* sym_read_psymbols */
3110 xcoff_symfile_finish, /* finished with file, cleanup */
3111 xcoff_symfile_offsets, /* xlate offsets ext->int form */
3112 default_symfile_segments, /* Get segment information from a file. */
3113 aix_process_linenos,
3114 default_symfile_relocate, /* Relocate a debug section. */
3118 /* Provide a prototype to silence -Wmissing-prototypes. */
3119 extern initialize_file_ftype _initialize_xcoffread;
3122 _initialize_xcoffread (void)
3124 add_symtab_fns (&xcoff_sym_fns);