1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
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 2 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include <sys/types.h>
31 #include "gdb_string.h"
33 #include <sys/param.h>
39 #include "coff/internal.h"
40 #include "libcoff.h" /* FIXME, internal data from BFD */
41 #include "coff/xcoff.h"
43 #include "coff/rs6000.h"
50 #include "stabsread.h"
51 #include "expression.h"
52 #include "complaints.h"
54 #include "gdb-stabs.h"
56 /* For interface with stabsread.c. */
57 #include "aout/stab_gnu.h"
60 /* We put a pointer to this structure in the read_symtab_private field
66 /* First symbol number for this file. */
70 /* Number of symbols in the section of the symbol table devoted to
71 this file's symbols (actually, the section bracketed may contain
72 more than just this file's symbols). If numsyms is 0, the only
73 reason for this thing's existence is the dependency list. Nothing
74 else will happen when it is read in. */
78 /* Position of the start of the line number information for this psymtab. */
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;
154 bf_notfound_complaint (void)
156 complaint (&symfile_complaints, "line numbers off, `.bf' symbol not found");
160 ef_complaint (int arg1)
162 complaint (&symfile_complaints,
163 "Mismatched .ef symbol ignored starting at symnum %d", arg1);
167 eb_complaint (int arg1)
169 complaint (&symfile_complaints,
170 "Mismatched .eb symbol ignored starting at symnum %d", arg1);
173 static void xcoff_initial_scan (struct objfile *, int);
175 static void scan_xcoff_symtab (struct objfile *);
177 static char *xcoff_next_symbol_text (struct objfile *);
179 static void record_include_begin (struct coff_symbol *);
182 enter_line_range (struct subfile *, unsigned, unsigned,
183 CORE_ADDR, CORE_ADDR, unsigned *);
185 static void init_stringtab (bfd *, file_ptr, struct objfile *);
187 static void xcoff_symfile_init (struct objfile *);
189 static void xcoff_new_init (struct objfile *);
191 static void xcoff_symfile_finish (struct objfile *);
193 static void xcoff_symfile_offsets (struct objfile *,
194 struct section_addr_info *addrs);
196 static void find_linenos (bfd *, sec_ptr, void *);
198 static char *coff_getfilename (union internal_auxent *, struct objfile *);
200 static void read_symbol (struct internal_syment *, int);
202 static int read_symbol_lineno (int);
204 static CORE_ADDR read_symbol_nvalue (int);
206 static struct symbol *process_xcoff_symbol (struct coff_symbol *,
209 static void read_xcoff_symtab (struct partial_symtab *);
212 static void add_stab_to_list (char *, struct pending_stabs **);
215 static int compare_lte (const void *, const void *);
217 static struct linetable *arrange_linetable (struct linetable *);
219 static void record_include_end (struct coff_symbol *);
221 static void process_linenos (CORE_ADDR, CORE_ADDR);
224 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
226 static int secnum_to_section (int, struct objfile *);
227 static asection *secnum_to_bfd_section (int, struct objfile *);
229 struct find_targ_sec_arg
234 struct objfile *objfile;
237 static void find_targ_sec (bfd *, asection *, void *);
240 find_targ_sec (bfd *abfd, asection *sect, void *obj)
242 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
243 struct objfile *objfile = args->objfile;
244 if (sect->target_index == args->targ_index)
246 /* This is the section. Figure out what SECT_OFF_* code it is. */
247 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
248 *args->resultp = SECT_OFF_TEXT (objfile);
249 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
250 *args->resultp = SECT_OFF_DATA (objfile);
252 *args->resultp = sect->index;
253 *args->bfd_sect = sect;
257 /* Return the section number (SECT_OFF_*) that CS points to. */
259 secnum_to_section (int secnum, struct objfile *objfile)
261 int off = SECT_OFF_TEXT (objfile);
262 asection *sect = NULL;
263 struct find_targ_sec_arg args;
264 args.targ_index = secnum;
266 args.bfd_sect = §
267 args.objfile = objfile;
268 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
272 /* Return the BFD section that CS points to. */
274 secnum_to_bfd_section (int secnum, struct objfile *objfile)
276 int off = SECT_OFF_TEXT (objfile);
277 asection *sect = NULL;
278 struct find_targ_sec_arg args;
279 args.targ_index = secnum;
281 args.bfd_sect = §
282 args.objfile = objfile;
283 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
287 /* add a given stab string into given stab vector. */
292 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
294 if (*stabvector == NULL)
296 *stabvector = (struct pending_stabs *)
297 xmalloc (sizeof (struct pending_stabs) +
298 INITIAL_STABVECTOR_LENGTH * sizeof (char *));
299 (*stabvector)->count = 0;
300 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
302 else if ((*stabvector)->count >= (*stabvector)->length)
304 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
305 *stabvector = (struct pending_stabs *)
306 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
307 (*stabvector)->length * sizeof (char *));
309 (*stabvector)->stab[(*stabvector)->count++] = stabname;
314 /* Linenos are processed on a file-by-file basis.
318 1) xlc (IBM's native c compiler) postpones static function code
319 emission to the end of a compilation unit. This way it can
320 determine if those functions (statics) are needed or not, and
321 can do some garbage collection (I think). This makes line
322 numbers and corresponding addresses unordered, and we end up
323 with a line table like:
340 and that breaks gdb's binary search on line numbers, if the
341 above table is not sorted on line numbers. And that sort
342 should be on function based, since gcc can emit line numbers
345 10 0x100 - for the init/test part of a for stmt.
348 10 0x400 - for the increment part of a for stmt.
350 arrange_linetable() will do this sorting.
352 2) aix symbol table might look like:
354 c_file // beginning of a new file
355 .bi // beginning of include file
356 .ei // end of include file
360 basically, .bi/.ei pairs do not necessarily encapsulate
361 their scope. They need to be recorded, and processed later
362 on when we come the end of the compilation unit.
363 Include table (inclTable) and process_linenos() handle
369 /* compare line table entry addresses. */
372 compare_lte (const void *lte1p, const void *lte2p)
374 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
375 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
376 return lte1->pc - lte2->pc;
379 /* Given a line table with function entries are marked, arrange its functions
380 in ascending order and strip off function entry markers and return it in
381 a newly created table. If the old one is good enough, return the old one. */
382 /* FIXME: I think all this stuff can be replaced by just passing
383 sort_linevec = 1 to end_symtab. */
385 static struct linetable *
386 arrange_linetable (struct linetable *oldLineTb)
388 int ii, jj, newline, /* new line count */
389 function_count; /* # of functions */
391 struct linetable_entry *fentry; /* function entry vector */
392 int fentry_size; /* # of function entries */
393 struct linetable *newLineTb; /* new line table */
395 #define NUM_OF_FUNCTIONS 20
397 fentry_size = NUM_OF_FUNCTIONS;
398 fentry = (struct linetable_entry *)
399 xmalloc (fentry_size * sizeof (struct linetable_entry));
401 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
404 if (oldLineTb->item[ii].line == 0)
405 { /* function entry found. */
407 if (function_count >= fentry_size)
408 { /* make sure you have room. */
410 fentry = (struct linetable_entry *)
411 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
413 fentry[function_count].line = ii;
414 fentry[function_count].pc = oldLineTb->item[ii].pc;
419 if (function_count == 0)
424 else if (function_count > 1)
425 qsort (fentry, function_count, sizeof (struct linetable_entry), compare_lte);
427 /* allocate a new line table. */
428 newLineTb = (struct linetable *)
430 (sizeof (struct linetable) +
431 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
433 /* if line table does not start with a function beginning, copy up until
437 if (oldLineTb->item[0].line != 0)
439 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
440 newLineTb->item[newline] = oldLineTb->item[newline];
442 /* Now copy function lines one by one. */
444 for (ii = 0; ii < function_count; ++ii)
446 for (jj = fentry[ii].line + 1;
447 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
449 newLineTb->item[newline] = oldLineTb->item[jj];
452 newLineTb->nitems = oldLineTb->nitems - function_count;
456 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
457 following `IncludeChain'. At the end of each symtab (end_symtab),
458 we will determine if we should create additional symtab's to
459 represent if (the include files. */
462 typedef struct _inclTable
464 char *name; /* include filename */
466 /* Offsets to the line table. end points to the last entry which is
467 part of this include file. */
470 struct subfile *subfile;
471 unsigned funStartLine; /* start line # of its function */
475 #define INITIAL_INCLUDE_TABLE_LENGTH 20
476 static InclTable *inclTable; /* global include table */
477 static int inclIndx; /* last entry to table */
478 static int inclLength; /* table length */
479 static int inclDepth; /* nested include depth */
481 static void allocate_include_entry (void);
484 record_include_begin (struct coff_symbol *cs)
488 /* In xcoff, we assume include files cannot be nested (not in .c files
489 of course, but in corresponding .s files.). */
491 /* This can happen with old versions of GCC.
492 GCC 2.3.3-930426 does not exhibit this on a test case which
493 a user said produced the message for him. */
494 complaint (&symfile_complaints, "Nested C_BINCL symbols");
498 allocate_include_entry ();
500 inclTable[inclIndx].name = cs->c_name;
501 inclTable[inclIndx].begin = cs->c_value;
505 record_include_end (struct coff_symbol *cs)
511 complaint (&symfile_complaints, "Mismatched C_BINCL/C_EINCL pair");
514 allocate_include_entry ();
516 pTbl = &inclTable[inclIndx];
517 pTbl->end = cs->c_value;
524 allocate_include_entry (void)
526 if (inclTable == NULL)
528 inclTable = (InclTable *)
529 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
531 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
532 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
535 else if (inclIndx >= inclLength)
537 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
538 inclTable = (InclTable *)
539 xrealloc (inclTable, sizeof (InclTable) * inclLength);
540 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
541 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
545 /* Global variable to pass the psymtab down to all the routines involved
546 in psymtab to symtab processing. */
547 static struct partial_symtab *this_symtab_psymtab;
549 /* given the start and end addresses of a compilation unit (or a csect,
550 at times) process its lines and create appropriate line vectors. */
553 process_linenos (CORE_ADDR start, CORE_ADDR end)
556 file_ptr max_offset =
557 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
560 /* subfile structure for the main compilation unit. */
561 struct subfile main_subfile;
563 /* In the main source file, any time we see a function entry, we
564 reset this variable to function's absolute starting line number.
565 All the following line numbers in the function are relative to
566 this, and we record absolute line numbers in record_line(). */
568 unsigned int main_source_baseline = 0;
573 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
575 goto return_after_cleanup;
577 memset (&main_subfile, '\0', sizeof (main_subfile));
580 /* All source lines were in the main source file. None in include files. */
582 enter_line_range (&main_subfile, offset, 0, start, end,
583 &main_source_baseline);
587 /* There was source with line numbers in include files. */
590 coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
591 main_source_baseline = 0;
593 for (ii = 0; ii < inclIndx; ++ii)
595 struct subfile *tmpSubfile;
597 /* If there is main file source before include file, enter it. */
598 if (offset < inclTable[ii].begin)
601 (&main_subfile, offset, inclTable[ii].begin - linesz,
602 start, 0, &main_source_baseline);
605 /* Have a new subfile for the include file. */
607 tmpSubfile = inclTable[ii].subfile =
608 (struct subfile *) xmalloc (sizeof (struct subfile));
610 memset (tmpSubfile, '\0', sizeof (struct subfile));
611 firstLine = &(inclTable[ii].funStartLine);
613 /* Enter include file's lines now. */
614 enter_line_range (tmpSubfile, inclTable[ii].begin,
615 inclTable[ii].end, start, 0, firstLine);
617 if (offset <= inclTable[ii].end)
618 offset = inclTable[ii].end + linesz;
621 /* All the include files' line have been processed at this point. Now,
622 enter remaining lines of the main file, if any left. */
623 if (offset < max_offset + 1 - linesz)
625 enter_line_range (&main_subfile, offset, 0, start, end,
626 &main_source_baseline);
630 /* Process main file's line numbers. */
631 if (main_subfile.line_vector)
633 struct linetable *lineTb, *lv;
635 lv = main_subfile.line_vector;
637 /* Line numbers are not necessarily ordered. xlc compilation will
638 put static function to the end. */
640 lineTb = arrange_linetable (lv);
643 current_subfile->line_vector = (struct linetable *)
644 xrealloc (lv, (sizeof (struct linetable)
645 + lv->nitems * sizeof (struct linetable_entry)));
650 current_subfile->line_vector = lineTb;
653 current_subfile->line_vector_length =
654 current_subfile->line_vector->nitems;
657 /* Now, process included files' line numbers. */
659 for (ii = 0; ii < inclIndx; ++ii)
661 if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */
663 struct linetable *lineTb, *lv;
665 lv = (inclTable[ii].subfile)->line_vector;
667 /* Line numbers are not necessarily ordered. xlc compilation will
668 put static function to the end. */
670 lineTb = arrange_linetable (lv);
674 /* For the same include file, we might want to have more than one
675 subfile. This happens if we have something like:
683 while foo.h including code in it. (stupid but possible)
684 Since start_subfile() looks at the name and uses an
685 existing one if finds, we need to provide a fake name and
689 start_subfile (inclTable[ii].name, (char *) 0);
692 /* Pick a fake name that will produce the same results as this
693 one when passed to deduce_language_from_filename. Kludge on
695 char *fakename = strrchr (inclTable[ii].name, '.');
696 if (fakename == NULL)
698 start_subfile (fakename, (char *) 0);
699 xfree (current_subfile->name);
701 current_subfile->name = xstrdup (inclTable[ii].name);
706 current_subfile->line_vector =
707 (struct linetable *) xrealloc
708 (lv, (sizeof (struct linetable)
709 + lv->nitems * sizeof (struct linetable_entry)));
715 current_subfile->line_vector = lineTb;
718 current_subfile->line_vector_length =
719 current_subfile->line_vector->nitems;
720 start_subfile (pop_subfile (), (char *) 0);
724 return_after_cleanup:
726 /* We don't want to keep alloc/free'ing the global include file table. */
729 /* Start with a fresh subfile structure for the next file. */
730 memset (&main_subfile, '\0', sizeof (struct subfile));
734 aix_process_linenos (void)
736 /* process line numbers and enter them into line vector */
737 process_linenos (last_source_start_addr, cur_src_end_addr);
741 /* Enter a given range of lines into the line vector.
742 can be called in the following two ways:
743 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
744 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
746 endoffset points to the last line table entry that we should pay
750 enter_line_range (struct subfile *subfile, unsigned beginoffset, unsigned endoffset, /* offsets to line table */
751 CORE_ADDR startaddr, /* offsets to line table */
752 CORE_ADDR endaddr, unsigned *firstLine)
754 unsigned int curoffset;
757 struct internal_lineno int_lnno;
758 unsigned int limit_offset;
762 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
764 curoffset = beginoffset;
766 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
771 if (endoffset >= limit_offset)
773 complaint (&symfile_complaints,
774 "Bad line table offset in C_EINCL directive");
777 limit_offset = endoffset;
782 abfd = this_symtab_psymtab->objfile->obfd;
783 linesz = coff_data (abfd)->local_linesz;
784 ext_lnno = alloca (linesz);
786 while (curoffset <= limit_offset)
788 bfd_seek (abfd, curoffset, SEEK_SET);
789 bfd_bread (ext_lnno, linesz, abfd);
790 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
792 /* Find the address this line represents. */
793 addr = (int_lnno.l_lnno
794 ? int_lnno.l_addr.l_paddr
795 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
796 addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
797 SECT_OFF_TEXT (this_symtab_psymtab->objfile));
799 if (addr < startaddr || (endaddr && addr >= endaddr))
802 if (int_lnno.l_lnno == 0)
804 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
805 record_line (subfile, 0, addr);
809 record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
815 /* Save the vital information for use when closing off the current file.
816 NAME is the file name the symbols came from, START_ADDR is the first
817 text address for the file, and SIZE is the number of bytes of text. */
819 #define complete_symtab(name, start_addr) { \
820 last_source_file = savestring (name, strlen (name)); \
821 last_source_start_addr = start_addr; \
825 /* Refill the symbol table input buffer
826 and set the variables that control fetching entries from it.
827 Reports an error if no data available.
828 This function can read past the end of the symbol table
829 (into the string table) but this does no harm. */
831 /* Reading symbol table has to be fast! Keep the followings as macros, rather
834 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
838 if (namestr[0] == '.') ++namestr; \
839 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
840 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
841 misc_func_recorded = 1; \
845 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
846 nested. At any given time, a symbol can only be in one static block.
847 This is the base address of current static block, zero if non exists. */
849 static int static_block_base = 0;
851 /* Section number for the current static block. */
853 static int static_block_section = -1;
855 /* true if space for symbol name has been allocated. */
857 static int symname_alloced = 0;
859 /* Next symbol to read. Pointer into raw seething symbol table. */
861 static char *raw_symbol;
863 /* This is the function which stabsread.c calls to get symbol
867 xcoff_next_symbol_text (struct objfile *objfile)
869 struct internal_syment symbol;
871 /* FIXME: is this the same as the passed arg? */
872 objfile = this_symtab_psymtab->objfile;
874 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
877 complaint (&symfile_complaints, "Unexpected symbol continuation");
879 /* Return something which points to '\0' and hope the symbol reading
880 code does something reasonable. */
883 else if (symbol.n_sclass & 0x80)
886 ((struct coff_symfile_info *) objfile->sym_private)->debugsec
889 coff_data (objfile->obfd)->local_symesz;
894 complaint (&symfile_complaints, "Unexpected symbol continuation");
896 /* Return something which points to '\0' and hope the symbol reading
897 code does something reasonable. */
903 /* Read symbols for a given partial symbol table. */
906 read_xcoff_symtab (struct partial_symtab *pst)
908 struct objfile *objfile = pst->objfile;
909 bfd *abfd = objfile->obfd;
910 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
911 char *strtbl = ((struct coff_symfile_info *) objfile->sym_private)->strtbl;
913 ((struct coff_symfile_info *) objfile->sym_private)->debugsec;
914 char *debugfmt = bfd_xcoff_is_xcoff64 (abfd) ? "XCOFF64" : "XCOFF";
916 struct internal_syment symbol[1];
917 union internal_auxent main_aux;
918 struct coff_symbol cs[1];
919 CORE_ADDR file_start_addr = 0;
920 CORE_ADDR file_end_addr = 0;
922 int next_file_symnum = -1;
923 unsigned int max_symnum;
924 int just_started = 1;
926 int fcn_start_addr = 0;
928 struct coff_symbol fcn_stab_saved;
930 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
931 union internal_auxent fcn_aux_saved;
932 struct context_stack *new;
934 char *filestring = " _start_ "; /* Name of the current file. */
936 char *last_csect_name; /* last seen csect's name and value */
937 CORE_ADDR last_csect_val;
940 this_symtab_psymtab = pst;
942 /* Get the appropriate COFF "constants" related to the file we're
944 local_symesz = coff_data (abfd)->local_symesz;
946 last_source_file = NULL;
951 start_symtab (filestring, (char *) NULL, file_start_addr);
952 record_debugformat (debugfmt);
953 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
955 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
956 first_object_file_end = 0;
959 ((struct coff_symfile_info *) objfile->sym_private)->symtbl
960 + symnum * local_symesz;
962 while (symnum < max_symnum)
965 QUIT; /* make this command interruptable. */
967 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
968 /* read one symbol into `cs' structure. After processing the
969 whole symbol table, only string table will be kept in memory,
970 symbol table and debug section of xcoff will be freed. Thus
971 we can mark symbols with names in string table as
976 /* Swap and align the symbol into a reasonable C structure. */
977 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
979 cs->c_symnum = symnum;
980 cs->c_naux = symbol->n_numaux;
981 if (symbol->n_zeroes)
984 /* We must use the original, unswapped, name here so the name field
985 pointed to by cs->c_name will persist throughout xcoffread. If
986 we use the new field, it gets overwritten for each symbol. */
987 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
988 /* If it's exactly E_SYMNMLEN characters long it isn't
990 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
993 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
994 strncpy (p, cs->c_name, E_SYMNMLEN);
995 p[E_SYMNMLEN] = '\0';
1000 else if (symbol->n_sclass & 0x80)
1002 cs->c_name = debugsec + symbol->n_offset;
1003 symname_alloced = 0;
1007 /* in string table */
1008 cs->c_name = strtbl + (int) symbol->n_offset;
1009 symname_alloced = 1;
1011 cs->c_value = symbol->n_value;
1012 cs->c_sclass = symbol->n_sclass;
1013 cs->c_secnum = symbol->n_scnum;
1014 cs->c_type = (unsigned) symbol->n_type;
1016 raw_symbol += local_symesz;
1019 /* Save addr of first aux entry. */
1020 raw_auxptr = raw_symbol;
1022 /* Skip all the auxents associated with this symbol. */
1023 for (ii = symbol->n_numaux; ii; --ii)
1025 raw_symbol += coff_data (abfd)->local_auxesz;
1030 /* if symbol name starts with ".$" or "$", ignore it. */
1031 if (cs->c_name[0] == '$'
1032 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1035 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1037 if (last_source_file)
1040 end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT (objfile));
1045 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1046 record_debugformat (debugfmt);
1047 cur_src_end_addr = first_object_file_end;
1048 /* done with all files, everything from here on is globals */
1051 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1054 /* Dealing with a symbol with a csect entry. */
1056 #define CSECT(PP) ((PP)->x_csect)
1057 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1058 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1059 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1060 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1062 /* Convert the auxent to something we can access. */
1063 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1064 0, cs->c_naux, &main_aux);
1066 switch (CSECT_SMTYP (&main_aux))
1070 /* Ignore all external references. */
1074 /* A section description. */
1076 switch (CSECT_SCLAS (&main_aux))
1082 /* A program csect is seen. We have to allocate one
1083 symbol table for each program csect. Normally gdb
1084 prefers one symtab for each source file. In case
1085 of AIX, one source file might include more than one
1086 [PR] csect, and they don't have to be adjacent in
1087 terms of the space they occupy in memory. Thus, one
1088 single source file might get fragmented in the
1089 memory and gdb's file start and end address
1090 approach does not work! GCC (and I think xlc) seem
1091 to put all the code in the unnamed program csect. */
1093 if (last_csect_name)
1095 complete_symtab (filestring, file_start_addr);
1096 cur_src_end_addr = file_end_addr;
1097 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1100 /* Give all csects for this source file the same
1102 start_symtab (filestring, NULL, (CORE_ADDR) 0);
1103 record_debugformat (debugfmt);
1106 /* If this is the very first csect seen,
1107 basically `__start'. */
1110 first_object_file_end
1111 = cs->c_value + CSECT_LEN (&main_aux);
1116 cs->c_value + ANOFFSET (objfile->section_offsets,
1117 SECT_OFF_TEXT (objfile));
1118 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1120 if (cs->c_name && (cs->c_name[0] == '.'
1121 || cs->c_name[0] == '@'))
1123 last_csect_name = cs->c_name;
1124 last_csect_val = cs->c_value;
1125 last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
1130 /* All other symbols are put into the minimal symbol
1143 /* Ignore the symbol. */
1151 switch (CSECT_SCLAS (&main_aux))
1154 /* a function entry point. */
1155 function_entry_point:
1157 fcn_start_addr = cs->c_value;
1159 /* save the function header info, which will be used
1160 when `.bf' is seen. */
1162 fcn_aux_saved = main_aux;
1166 /* shared library function trampoline code entry point. */
1170 /* The symbols often have the same names as debug symbols for
1171 functions, and confuse lookup_symbol. */
1175 /* xlc puts each variable in a separate csect, so we get
1176 an XTY_SD for each variable. But gcc puts several
1177 variables in a csect, so that each variable only gets
1178 an XTY_LD. This will typically be XMC_RW; I suspect
1179 XMC_RO and XMC_BS might be possible too.
1180 These variables are put in the minimal symbol table
1187 /* Common symbols are put into the minimal symbol table only. */
1195 /* If explicitly specified as a function, treat is as one. This check
1196 evaluates to true for @FIX* bigtoc CSECT symbols, so it must occur
1197 after the above CSECT check. */
1198 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1200 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1201 0, cs->c_naux, &main_aux);
1202 goto function_entry_point;
1205 switch (cs->c_sclass)
1210 /* c_value field contains symnum of next .file entry in table
1211 or symnum of first global after last .file. */
1213 next_file_symnum = cs->c_value;
1215 /* Complete symbol table for last object file containing
1216 debugging information. */
1218 /* Whether or not there was a csect in the previous file, we
1219 have to call `end_stabs' and `start_stabs' to reset
1220 type_vector, line_vector, etc. structures. */
1222 complete_symtab (filestring, file_start_addr);
1223 cur_src_end_addr = file_end_addr;
1224 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1227 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1228 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1229 standard COFF way and put it in the auxent. We use the auxent if
1230 the symbol is ".file" and an auxent exists, otherwise use the symbol
1231 itself. Simple enough. */
1232 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1234 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1235 0, cs->c_naux, &main_aux);
1236 filestring = coff_getfilename (&main_aux, objfile);
1239 filestring = cs->c_name;
1242 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1243 record_debugformat (debugfmt);
1244 last_csect_name = 0;
1246 /* reset file start and end addresses. A compilation unit with no text
1247 (only data) should have zero file boundaries. */
1248 file_start_addr = file_end_addr = 0;
1252 fcn_stab_saved = *cs;
1256 if (STREQ (cs->c_name, ".bf"))
1258 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1259 SECT_OFF_TEXT (objfile));
1260 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1261 0, cs->c_naux, &main_aux);
1263 within_function = 1;
1265 new = push_context (0, fcn_start_addr + off);
1267 new->name = define_symbol
1268 (fcn_cs_saved.c_value + off,
1269 fcn_stab_saved.c_name, 0, 0, objfile);
1270 if (new->name != NULL)
1271 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1273 else if (STREQ (cs->c_name, ".ef"))
1276 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1277 0, cs->c_naux, &main_aux);
1279 /* The value of .ef is the address of epilogue code;
1280 not useful for gdb. */
1281 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1282 contains number of lines to '}' */
1284 if (context_stack_depth <= 0)
1285 { /* We attempted to pop an empty context stack */
1286 ef_complaint (cs->c_symnum);
1287 within_function = 0;
1290 new = pop_context ();
1291 /* Stack must be empty now. */
1292 if (context_stack_depth > 0 || new == NULL)
1294 ef_complaint (cs->c_symnum);
1295 within_function = 0;
1299 finish_block (new->name, &local_symbols, new->old_blocks,
1301 (fcn_cs_saved.c_value
1302 + fcn_aux_saved.x_sym.x_misc.x_fsize
1303 + ANOFFSET (objfile->section_offsets,
1304 SECT_OFF_TEXT (objfile))),
1306 within_function = 0;
1311 /* Begin static block. */
1313 struct internal_syment symbol;
1315 read_symbol (&symbol, cs->c_value);
1316 static_block_base = symbol.n_value;
1317 static_block_section =
1318 secnum_to_section (symbol.n_scnum, objfile);
1323 /* End of static block. */
1324 static_block_base = 0;
1325 static_block_section = -1;
1336 complaint (&symfile_complaints, "Unrecognized storage class %d.",
1351 /* beginning of include file */
1352 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1353 order. Thus, when wee see them, we might not know enough info
1354 to process them. Thus, we'll be saving them into a table
1355 (inclTable) and postpone their processing. */
1357 record_include_begin (cs);
1361 /* End of include file. */
1362 /* See the comment after case C_BINCL. */
1363 record_include_end (cs);
1367 if (STREQ (cs->c_name, ".bb"))
1370 new = push_context (depth,
1372 + ANOFFSET (objfile->section_offsets,
1373 SECT_OFF_TEXT (objfile))));
1375 else if (STREQ (cs->c_name, ".eb"))
1377 if (context_stack_depth <= 0)
1378 { /* We attempted to pop an empty context stack */
1379 eb_complaint (cs->c_symnum);
1382 new = pop_context ();
1383 if (depth-- != new->depth)
1385 eb_complaint (cs->c_symnum);
1388 if (local_symbols && context_stack_depth > 0)
1390 /* Make a block for the local symbols within. */
1391 finish_block (new->name, &local_symbols, new->old_blocks,
1394 + ANOFFSET (objfile->section_offsets,
1395 SECT_OFF_TEXT (objfile))),
1398 local_symbols = new->locals;
1403 process_xcoff_symbol (cs, objfile);
1408 if (last_source_file)
1412 complete_symtab (filestring, file_start_addr);
1413 cur_src_end_addr = file_end_addr;
1414 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1415 /* When reading symbols for the last C_FILE of the objfile, try
1416 to make sure that we set pst->symtab to the symtab for the
1417 file, not to the _globals_ symtab. I'm not sure whether this
1418 actually works right or when/if it comes up. */
1419 if (pst->symtab == NULL)
1425 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1426 (SYMBOL2) = (struct symbol *) \
1427 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1428 *(SYMBOL2) = *(SYMBOL1);
1431 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1432 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1435 static struct type *func_symbol_type;
1436 static struct type *var_symbol_type;
1438 /* process one xcoff symbol. */
1440 static struct symbol *
1441 process_xcoff_symbol (register struct coff_symbol *cs, struct objfile *objfile)
1443 struct symbol onesymbol;
1444 register struct symbol *sym = &onesymbol;
1445 struct symbol *sym2 = NULL;
1451 if (cs->c_secnum < 0)
1453 /* The value is a register number, offset within a frame, etc.,
1454 and does not get relocated. */
1460 sec = secnum_to_section (cs->c_secnum, objfile);
1461 off = ANOFFSET (objfile->section_offsets, sec);
1468 memset (sym, '\0', sizeof (struct symbol));
1470 /* default assumptions */
1471 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1472 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
1473 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1475 if (ISFCN (cs->c_type))
1477 /* At this point, we don't know the type of the function. This
1478 will be patched with the type from its stab entry later on in
1479 patch_block_stabs (), unless the file was compiled without -g. */
1481 DEPRECATED_SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1482 SYMBOL_TYPE (sym) = func_symbol_type;
1484 SYMBOL_CLASS (sym) = LOC_BLOCK;
1485 SYMBOL_DUP (sym, sym2);
1487 if (cs->c_sclass == C_EXT)
1488 add_symbol_to_list (sym2, &global_symbols);
1489 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1490 add_symbol_to_list (sym2, &file_symbols);
1494 /* In case we can't figure out the type, provide default. */
1495 SYMBOL_TYPE (sym) = var_symbol_type;
1497 switch (cs->c_sclass)
1500 /* The values of functions and global symbols are now resolved
1501 via the global_sym_chain in stabsread.c. */
1503 if (fcn_cs_saved.c_sclass == C_EXT)
1504 add_stab_to_list (name, &global_stabs);
1506 add_stab_to_list (name, &file_stabs);
1510 add_stab_to_list (name, &global_stabs);
1515 common_block_start (cs->c_name, objfile);
1519 common_block_end (objfile);
1523 complaint (&symfile_complaints, "Unexpected storage class: %d",
1536 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1539 SYMBOL_SECTION (sym) = sec;
1546 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1547 all statics and we need to distinguish file-scope versus
1548 function-scope using within_function. We do this by
1549 changing the string we pass to define_symbol to use 'S'
1550 where we need to, which is not necessarily super-clean,
1551 but seems workable enough. */
1553 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1557 if (*pp == 'V' && !within_function)
1559 sym = define_symbol ((cs->c_value
1560 + ANOFFSET (objfile->section_offsets,
1561 static_block_section)),
1562 cs->c_name, 0, 0, objfile);
1565 SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1566 SYMBOL_SECTION (sym) = static_block_section;
1575 /* Extract the file name from the aux entry of a C_FILE symbol.
1576 Result is in static storage and is only good for temporary use. */
1579 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1581 static char buffer[BUFSIZ];
1583 if (aux_entry->x_file.x_n.x_zeroes == 0)
1585 ((struct coff_symfile_info *) objfile->sym_private)->strtbl
1586 + aux_entry->x_file.x_n.x_offset);
1589 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1590 buffer[FILNMLEN] = '\0';
1595 /* Set *SYMBOL to symbol number symno in symtbl. */
1597 read_symbol (struct internal_syment *symbol, int symno)
1600 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
1603 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
1605 if (symno < 0 || symno >= nsyms)
1607 complaint (&symfile_complaints, "Invalid symbol offset");
1608 symbol->n_value = 0;
1609 symbol->n_scnum = -1;
1612 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1613 stbl + (symno * local_symesz),
1617 /* Get value corresponding to symbol number symno in symtbl. */
1620 read_symbol_nvalue (int symno)
1622 struct internal_syment symbol[1];
1624 read_symbol (symbol, symno);
1625 return symbol->n_value;
1629 /* Find the address of the function corresponding to symno, where
1630 symno is the symbol pointed to by the linetable. */
1633 read_symbol_lineno (int symno)
1635 struct objfile *objfile = this_symtab_psymtab->objfile;
1636 int xcoff64 = bfd_xcoff_is_xcoff64 (objfile->obfd);
1638 struct coff_symfile_info *info =
1639 (struct coff_symfile_info *)objfile->sym_private;
1640 int nsyms = info->symtbl_num_syms;
1641 char *stbl = info->symtbl;
1642 char *strtbl = info->strtbl;
1644 struct internal_syment symbol[1];
1645 union internal_auxent main_aux[1];
1649 bf_notfound_complaint ();
1653 /* Note that just searching for a short distance (e.g. 50 symbols)
1654 is not enough, at least in the following case.
1657 [many .stabx entries]
1658 [a few functions, referring to foo]
1662 What happens here is that the assembler moves the .stabx entries
1663 to right before the ".bf" for foo, but the symbol for "foo" is before
1664 all the stabx entries. See PR gdb/2222. */
1666 /* Maintaining a table of .bf entries might be preferable to this search.
1667 If I understand things correctly it would need to be done only for
1668 the duration of a single psymtab to symtab conversion. */
1669 while (symno < nsyms)
1671 bfd_coff_swap_sym_in (symfile_bfd,
1672 stbl + (symno * local_symesz), symbol);
1673 if (symbol->n_sclass == C_FCN)
1675 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1676 if (STREQ (name, ".bf"))
1679 symno += symbol->n_numaux + 1;
1682 bf_notfound_complaint ();
1686 /* take aux entry and return its lineno */
1688 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1689 symbol->n_type, symbol->n_sclass,
1690 0, symbol->n_numaux, main_aux);
1692 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1695 /* Support for line number handling */
1697 /* This function is called for every section; it finds the outer limits
1698 * of the line table (minimum and maximum file offset) so that the
1699 * mainline code can read the whole thing for efficiency.
1702 find_linenos (bfd *abfd, sec_ptr asect, void *vpinfo)
1704 struct coff_symfile_info *info;
1706 file_ptr offset, maxoff;
1708 count = asect->lineno_count;
1710 if (!STREQ (asect->name, ".text") || count == 0)
1713 size = count * coff_data (abfd)->local_linesz;
1714 info = (struct coff_symfile_info *) vpinfo;
1715 offset = asect->line_filepos;
1716 maxoff = offset + size;
1718 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1719 info->min_lineno_offset = offset;
1721 if (maxoff > info->max_lineno_offset)
1722 info->max_lineno_offset = maxoff;
1725 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1728 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1730 struct cleanup *old_chain;
1739 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1744 /* Read in all partial symtabs on which this one is dependent */
1745 for (i = 0; i < pst->number_of_dependencies; i++)
1746 if (!pst->dependencies[i]->readin)
1748 /* Inform about additional files that need to be read in. */
1751 fputs_filtered (" ", gdb_stdout);
1753 fputs_filtered ("and ", gdb_stdout);
1755 printf_filtered ("%s...", pst->dependencies[i]->filename);
1756 wrap_here (""); /* Flush output */
1757 gdb_flush (gdb_stdout);
1759 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1762 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1764 /* Init stuff necessary for reading in symbols. */
1767 old_chain = make_cleanup (really_free_pendings, 0);
1769 read_xcoff_symtab (pst);
1771 do_cleanups (old_chain);
1777 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1779 /* Read in all of the symbols for a given psymtab for real.
1780 Be verbose about it if the user wants that. */
1783 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1793 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1798 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1799 || pst->number_of_dependencies)
1801 /* Print the message now, before reading the string table,
1802 to avoid disconcerting pauses. */
1805 printf_filtered ("Reading in symbols for %s...", pst->filename);
1806 gdb_flush (gdb_stdout);
1809 sym_bfd = pst->objfile->obfd;
1811 next_symbol_text_func = xcoff_next_symbol_text;
1813 xcoff_psymtab_to_symtab_1 (pst);
1815 /* Match with global symbols. This only needs to be done once,
1816 after all of the symtabs and dependencies have been read in. */
1817 scan_file_globals (pst->objfile);
1819 /* Finish up the debug error message. */
1821 printf_filtered ("done.\n");
1826 xcoff_new_init (struct objfile *objfile)
1828 stabsread_new_init ();
1829 buildsym_new_init ();
1832 /* Do initialization in preparation for reading symbols from OBJFILE.
1834 We will only be called if this is an XCOFF or XCOFF-like file.
1835 BFD handles figuring out the format of the file, and code in symfile.c
1836 uses BFD's determination to vector to us. */
1839 xcoff_symfile_init (struct objfile *objfile)
1841 /* Allocate struct to keep track of the symfile */
1842 objfile->sym_private = xmmalloc (objfile->md,
1843 sizeof (struct coff_symfile_info));
1845 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1846 find this causes a significant slowdown in gdb then we could
1847 set it in the debug symbol readers only when necessary. */
1848 objfile->flags |= OBJF_REORDERED;
1850 init_entry_point_info (objfile);
1853 /* Perform any local cleanups required when we are done with a particular
1854 objfile. I.E, we are in the process of discarding all symbol information
1855 for an objfile, freeing up all memory held for it, and unlinking the
1856 objfile struct from the global list of known objfiles. */
1859 xcoff_symfile_finish (struct objfile *objfile)
1861 if (objfile->sym_private != NULL)
1863 xmfree (objfile->md, objfile->sym_private);
1866 /* Start with a fresh include table for the next objfile. */
1872 inclIndx = inclLength = inclDepth = 0;
1877 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1881 unsigned char lengthbuf[4];
1884 ((struct coff_symfile_info *) objfile->sym_private)->strtbl = NULL;
1886 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1887 error ("cannot seek to string table in %s: %s",
1888 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1890 val = bfd_bread ((char *) lengthbuf, sizeof lengthbuf, abfd);
1891 length = bfd_h_get_32 (abfd, lengthbuf);
1893 /* If no string table is needed, then the file may end immediately
1894 after the symbols. Just return with `strtbl' set to NULL. */
1896 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1899 /* Allocate string table from symbol_obstack. We will need this table
1900 as long as we have its symbol table around. */
1902 strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
1903 ((struct coff_symfile_info *) objfile->sym_private)->strtbl = strtbl;
1905 /* Copy length buffer, the first byte is usually zero and is
1906 used for stabs with a name length of zero. */
1907 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1908 if (length == sizeof lengthbuf)
1911 val = bfd_bread (strtbl + sizeof lengthbuf, length - sizeof lengthbuf, abfd);
1913 if (val != length - sizeof lengthbuf)
1914 error ("cannot read string table from %s: %s",
1915 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1916 if (strtbl[length - 1] != '\0')
1917 error ("bad symbol file: string table does not end with null character");
1922 /* If we have not yet seen a function for this psymtab, this is 0. If we
1923 have seen one, it is the offset in the line numbers of the line numbers
1925 static unsigned int first_fun_line_offset;
1927 static struct partial_symtab *xcoff_start_psymtab
1928 (struct objfile *, char *, int,
1929 struct partial_symbol **, struct partial_symbol **);
1931 /* Allocate and partially fill a partial symtab. It will be
1932 completely filled at the end of the symbol list.
1934 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1935 is the address relative to which its symbols are (incremental) or 0
1938 static struct partial_symtab *
1939 xcoff_start_psymtab (struct objfile *objfile, char *filename, int first_symnum,
1940 struct partial_symbol **global_syms,
1941 struct partial_symbol **static_syms)
1943 struct partial_symtab *result =
1944 start_psymtab_common (objfile, objfile->section_offsets,
1946 /* We fill in textlow later. */
1948 global_syms, static_syms);
1950 result->read_symtab_private = (char *)
1951 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
1952 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
1953 result->read_symtab = xcoff_psymtab_to_symtab;
1955 /* Deduce the source language from the filename for this psymtab. */
1956 psymtab_language = deduce_language_from_filename (filename);
1961 static struct partial_symtab *xcoff_end_psymtab
1962 (struct partial_symtab *, char **, int, int,
1963 struct partial_symtab **, int, int);
1965 /* Close off the current usage of PST.
1966 Returns PST, or NULL if the partial symtab was empty and thrown away.
1968 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1970 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1971 are the information for includes and dependencies. */
1973 static struct partial_symtab *
1974 xcoff_end_psymtab (struct partial_symtab *pst, char **include_list,
1975 int num_includes, int capping_symbol_number,
1976 struct partial_symtab **dependency_list,
1977 int number_dependencies, int textlow_not_set)
1980 struct objfile *objfile = pst->objfile;
1982 if (capping_symbol_number != -1)
1983 ((struct symloc *) pst->read_symtab_private)->numsyms =
1984 capping_symbol_number
1985 - ((struct symloc *) pst->read_symtab_private)->first_symnum;
1986 ((struct symloc *) pst->read_symtab_private)->lineno_off =
1987 first_fun_line_offset;
1988 first_fun_line_offset = 0;
1989 pst->n_global_syms =
1990 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1991 pst->n_static_syms =
1992 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1994 pst->number_of_dependencies = number_dependencies;
1995 if (number_dependencies)
1997 pst->dependencies = (struct partial_symtab **)
1998 obstack_alloc (&objfile->psymbol_obstack,
1999 number_dependencies * sizeof (struct partial_symtab *));
2000 memcpy (pst->dependencies, dependency_list,
2001 number_dependencies * sizeof (struct partial_symtab *));
2004 pst->dependencies = 0;
2006 for (i = 0; i < num_includes; i++)
2008 struct partial_symtab *subpst =
2009 allocate_psymtab (include_list[i], objfile);
2011 subpst->section_offsets = pst->section_offsets;
2012 subpst->read_symtab_private =
2013 (char *) obstack_alloc (&objfile->psymbol_obstack,
2014 sizeof (struct symloc));
2015 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2016 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2017 subpst->textlow = 0;
2018 subpst->texthigh = 0;
2020 /* We could save slight bits of space by only making one of these,
2021 shared by the entire set of include files. FIXME-someday. */
2022 subpst->dependencies = (struct partial_symtab **)
2023 obstack_alloc (&objfile->psymbol_obstack,
2024 sizeof (struct partial_symtab *));
2025 subpst->dependencies[0] = pst;
2026 subpst->number_of_dependencies = 1;
2028 subpst->globals_offset =
2029 subpst->n_global_syms =
2030 subpst->statics_offset =
2031 subpst->n_static_syms = 0;
2035 subpst->read_symtab = pst->read_symtab;
2038 sort_pst_symbols (pst);
2040 /* If there is already a psymtab or symtab for a file of this name,
2041 remove it. (If there is a symtab, more drastic things also
2042 happen.) This happens in VxWorks. */
2043 free_named_symtabs (pst->filename);
2045 if (num_includes == 0
2046 && number_dependencies == 0
2047 && pst->n_global_syms == 0
2048 && pst->n_static_syms == 0)
2050 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2051 it is on the obstack, but we can forget to chain it on the list. */
2052 /* Empty psymtabs happen as a result of header files which don't have
2053 any symbols in them. There can be a lot of them. */
2055 discard_psymtab (pst);
2057 /* Indicate that psymtab was thrown away. */
2058 pst = (struct partial_symtab *) NULL;
2063 static void swap_sym (struct internal_syment *,
2064 union internal_auxent *, char **, char **,
2065 unsigned int *, struct objfile *);
2067 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2068 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2069 the symbol and its auxents. */
2072 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2073 char **name, char **raw, unsigned int *symnump,
2074 struct objfile *objfile)
2076 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2077 if (symbol->n_zeroes)
2079 /* If it's exactly E_SYMNMLEN characters long it isn't
2081 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2083 /* FIXME: wastes memory for symbols which we don't end up putting
2084 into the minimal symbols. */
2086 p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2087 strncpy (p, symbol->n_name, E_SYMNMLEN);
2088 p[E_SYMNMLEN] = '\0';
2092 /* Point to the unswapped name as that persists as long as the
2094 *name = ((struct external_syment *) *raw)->e.e_name;
2096 else if (symbol->n_sclass & 0x80)
2098 *name = ((struct coff_symfile_info *) objfile->sym_private)->debugsec
2103 *name = ((struct coff_symfile_info *) objfile->sym_private)->strtbl
2107 *raw += coff_data (objfile->obfd)->local_symesz;
2108 if (symbol->n_numaux > 0)
2110 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2111 symbol->n_sclass, 0, symbol->n_numaux, aux);
2113 *symnump += symbol->n_numaux;
2114 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2119 function_outside_compilation_unit_complaint (const char *arg1)
2121 complaint (&symfile_complaints,
2122 "function `%s' appears to be defined outside of all compilation units",
2127 scan_xcoff_symtab (struct objfile *objfile)
2129 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
2130 char *filestring = NULL;
2133 int past_first_source_file = 0;
2138 /* Current partial symtab */
2139 struct partial_symtab *pst;
2141 /* List of current psymtab's include files */
2142 char **psymtab_include_list;
2143 int includes_allocated;
2146 /* Index within current psymtab dependency list */
2147 struct partial_symtab **dependency_list;
2148 int dependencies_used, dependencies_allocated;
2151 struct internal_syment symbol;
2152 union internal_auxent main_aux[5];
2153 unsigned int ssymnum;
2155 char *last_csect_name = NULL; /* last seen csect's name and value */
2156 CORE_ADDR last_csect_val = 0;
2157 int last_csect_sec = 0;
2158 int misc_func_recorded = 0; /* true if any misc. function */
2159 int textlow_not_set = 1;
2161 pst = (struct partial_symtab *) 0;
2163 includes_allocated = 30;
2165 psymtab_include_list = (char **) alloca (includes_allocated *
2168 dependencies_allocated = 30;
2169 dependencies_used = 0;
2171 (struct partial_symtab **) alloca (dependencies_allocated *
2172 sizeof (struct partial_symtab *));
2174 last_source_file = NULL;
2176 abfd = objfile->obfd;
2178 sraw_symbol = ((struct coff_symfile_info *) objfile->sym_private)->symtbl;
2179 nsyms = ((struct coff_symfile_info *) objfile->sym_private)->symtbl_num_syms;
2181 while (ssymnum < nsyms)
2187 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2188 sclass = symbol.n_sclass;
2195 /* The CSECT auxent--always the last auxent. */
2196 union internal_auxent csect_aux;
2197 unsigned int symnum_before = ssymnum;
2199 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2201 if (symbol.n_numaux > 1)
2203 bfd_coff_swap_aux_in
2205 sraw_symbol - coff_data (abfd)->local_symesz,
2208 symbol.n_numaux - 1,
2213 csect_aux = main_aux[0];
2215 /* If symbol name starts with ".$" or "$", ignore it. */
2216 if (namestring[0] == '$'
2217 || (namestring[0] == '.' && namestring[1] == '$'))
2220 switch (csect_aux.x_csect.x_smtyp & 0x7)
2223 switch (csect_aux.x_csect.x_smclas)
2226 if (last_csect_name)
2228 /* If no misc. function recorded in the last
2229 seen csect, enter it as a function. This
2230 will take care of functions like strcmp()
2233 if (!misc_func_recorded)
2235 RECORD_MINIMAL_SYMBOL
2236 (last_csect_name, last_csect_val,
2237 mst_text, last_csect_sec,
2243 /* We have to allocate one psymtab for
2244 each program csect, because their text
2245 sections need not be adjacent. */
2247 (pst, psymtab_include_list, includes_used,
2248 symnum_before, dependency_list,
2249 dependencies_used, textlow_not_set);
2251 dependencies_used = 0;
2252 /* Give all psymtabs for this source file the same
2254 pst = xcoff_start_psymtab
2258 objfile->global_psymbols.next,
2259 objfile->static_psymbols.next);
2262 /* Activate the misc_func_recorded mechanism for
2263 compiler- and linker-generated CSECTs like ".strcmp"
2265 if (namestring && (namestring[0] == '.'
2266 || namestring[0] == '@'))
2268 last_csect_name = namestring;
2269 last_csect_val = symbol.n_value;
2271 secnum_to_section (symbol.n_scnum, objfile);
2276 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2277 if (highval > pst->texthigh)
2278 pst->texthigh = highval;
2279 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2280 pst->textlow = symbol.n_value;
2282 misc_func_recorded = 0;
2287 /* Data variables are recorded in the minimal symbol
2288 table, except for section symbols. */
2289 if (*namestring != '.')
2290 prim_record_minimal_symbol_and_info
2291 (namestring, symbol.n_value,
2292 sclass == C_HIDEXT ? mst_file_data : mst_data,
2293 NULL, secnum_to_section (symbol.n_scnum, objfile),
2299 warning ("More than one XMC_TC0 symbol found.");
2300 toc_offset = symbol.n_value;
2302 /* Make TOC offset relative to start address of section. */
2303 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2305 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
2309 /* These symbols tell us where the TOC entry for a
2310 variable is, not the variable itself. */
2319 switch (csect_aux.x_csect.x_smclas)
2322 /* A function entry point. */
2324 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2325 first_fun_line_offset =
2326 main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
2327 RECORD_MINIMAL_SYMBOL
2328 (namestring, symbol.n_value,
2329 sclass == C_HIDEXT ? mst_file_text : mst_text,
2330 secnum_to_section (symbol.n_scnum, objfile),
2335 /* shared library function trampoline code entry
2338 /* record trampoline code entries as
2339 mst_solib_trampoline symbol. When we lookup mst
2340 symbols, we will choose mst_text over
2341 mst_solib_trampoline. */
2342 RECORD_MINIMAL_SYMBOL
2343 (namestring, symbol.n_value,
2344 mst_solib_trampoline,
2345 secnum_to_section (symbol.n_scnum, objfile),
2350 /* The symbols often have the same names as
2351 debug symbols for functions, and confuse
2357 /* xlc puts each variable in a separate csect,
2358 so we get an XTY_SD for each variable. But
2359 gcc puts several variables in a csect, so
2360 that each variable only gets an XTY_LD. We
2361 still need to record them. This will
2362 typically be XMC_RW; I suspect XMC_RO and
2363 XMC_BS might be possible too. */
2364 if (*namestring != '.')
2365 prim_record_minimal_symbol_and_info
2366 (namestring, symbol.n_value,
2367 sclass == C_HIDEXT ? mst_file_data : mst_data,
2368 NULL, secnum_to_section (symbol.n_scnum, objfile),
2375 switch (csect_aux.x_csect.x_smclas)
2379 /* Common variables are recorded in the minimal symbol
2380 table, except for section symbols. */
2381 if (*namestring != '.')
2382 prim_record_minimal_symbol_and_info
2383 (namestring, symbol.n_value,
2384 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2385 NULL, secnum_to_section (symbol.n_scnum, objfile),
2398 unsigned int symnum_before;
2400 symnum_before = ssymnum;
2401 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2404 /* See if the last csect needs to be recorded. */
2406 if (last_csect_name && !misc_func_recorded)
2409 /* If no misc. function recorded in the last seen csect, enter
2410 it as a function. This will take care of functions like
2411 strcmp() compiled by xlc. */
2413 RECORD_MINIMAL_SYMBOL
2414 (last_csect_name, last_csect_val,
2415 mst_text, last_csect_sec, objfile);
2420 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2421 symnum_before, dependency_list,
2422 dependencies_used, textlow_not_set);
2424 dependencies_used = 0;
2426 first_fun_line_offset = 0;
2428 /* XCOFF, according to the AIX 3.2 documentation, puts the
2429 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2430 do things the standard COFF way and put it in the auxent.
2431 We use the auxent if the symbol is ".file" and an auxent
2432 exists, otherwise use the symbol itself. */
2433 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2435 filestring = coff_getfilename (&main_aux[0], objfile);
2438 filestring = namestring;
2440 pst = xcoff_start_psymtab (objfile,
2443 objfile->global_psymbols.next,
2444 objfile->static_psymbols.next);
2445 last_csect_name = NULL;
2451 complaint (&symfile_complaints,
2452 "Storage class %d not recognized during scan", sclass);
2456 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2457 to handle only the C_FUN and C_EXT. */
2472 /* C_EINCL means we are switching back to the main file. But there
2473 is no reason to care; the only thing we want to know about
2474 includes is the names of all the included (.h) files. */
2479 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2483 /* I don't think the name of the common block (as opposed to the
2484 variables within it) is something which is user visible
2492 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2493 so C_LSYM would appear to be only for locals. */
2499 /* We probably could save a few instructions by assuming that
2500 C_LSYM, C_PSYM, etc., never have auxents. */
2501 int naux1 = symbol.n_numaux + 1;
2503 sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2509 /* Mark down an include file in the current psymtab */
2510 enum language tmp_language;
2511 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2514 tmp_language = deduce_language_from_filename (namestring);
2516 /* Only change the psymtab's language if we've learned
2517 something useful (eg. tmp_language is not language_unknown).
2518 In addition, to match what start_subfile does, never change
2520 if (tmp_language != language_unknown
2521 && (tmp_language != language_c
2522 || psymtab_language != language_cplus))
2523 psymtab_language = tmp_language;
2525 /* In C++, one may expect the same filename to come round many
2526 times, when code is coming alternately from the main file
2527 and from inline functions in other files. So I check to see
2528 if this is a file we've seen before -- either the main
2529 source file, or a previously included file.
2531 This seems to be a lot of time to be spending on N_SOL, but
2532 things like "break c-exp.y:435" need to work (I
2533 suppose the psymtab_include_list could be hashed or put
2534 in a binary tree, if profiling shows this is a major hog). */
2535 if (pst && STREQ (namestring, pst->filename))
2539 for (i = 0; i < includes_used; i++)
2540 if (STREQ (namestring, psymtab_include_list[i]))
2548 psymtab_include_list[includes_used++] = namestring;
2549 if (includes_used >= includes_allocated)
2551 char **orig = psymtab_include_list;
2553 psymtab_include_list = (char **)
2554 alloca ((includes_allocated *= 2) *
2556 memcpy (psymtab_include_list, orig,
2557 includes_used * sizeof (char *));
2562 /* The value of the C_FUN is not the address of the function (it
2563 appears to be the address before linking), but as long as it
2564 is smaller than the actual address, then find_pc_partial_function
2565 will use the minimal symbols instead. I hope. */
2573 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2576 p = (char *) strchr (namestring, ':');
2578 continue; /* Not a debugging symbol. */
2580 /* Main processing section for debugging symbols which
2581 the initial read through the symbol tables needs to worry
2582 about. If we reach this point, the symbol which we are
2583 considering is definitely one we are interested in.
2584 p must also contain the (valid) index into the namestring
2585 which indicates the debugging type symbol. */
2590 symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2591 #ifdef STATIC_TRANSFORM_NAME
2592 namestring = STATIC_TRANSFORM_NAME (namestring);
2594 add_psymbol_to_list (namestring, p - namestring,
2595 VAR_DOMAIN, LOC_STATIC,
2596 &objfile->static_psymbols,
2598 psymtab_language, objfile);
2602 symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2603 /* The addresses in these entries are reported to be
2604 wrong. See the code that reads 'G's for symtabs. */
2605 add_psymbol_to_list (namestring, p - namestring,
2606 VAR_DOMAIN, LOC_STATIC,
2607 &objfile->global_psymbols,
2609 psymtab_language, objfile);
2613 /* When a 'T' entry is defining an anonymous enum, it
2614 may have a name which is the empty string, or a
2615 single space. Since they're not really defining a
2616 symbol, those shouldn't go in the partial symbol
2617 table. We do pick up the elements of such enums at
2618 'check_enum:', below. */
2619 if (p >= namestring + 2
2620 || (p == namestring + 1
2621 && namestring[0] != ' '))
2623 add_psymbol_to_list (namestring, p - namestring,
2624 STRUCT_DOMAIN, LOC_TYPEDEF,
2625 &objfile->static_psymbols,
2627 psymtab_language, objfile);
2630 /* Also a typedef with the same name. */
2631 add_psymbol_to_list (namestring, p - namestring,
2632 VAR_DOMAIN, LOC_TYPEDEF,
2633 &objfile->static_psymbols,
2635 psymtab_language, objfile);
2638 #if 0 /* OBSOLETE CFront */
2639 // OBSOLETE /* The semantics of C++ state that "struct foo { ... }"
2640 // OBSOLETE also defines a typedef for "foo". Unfortuantely, cfront
2641 // OBSOLETE never makes the typedef when translating from C++ to C.
2642 // OBSOLETE We make the typedef here so that "ptype foo" works as
2643 // OBSOLETE expected for cfront translated code. */
2644 // OBSOLETE else if (psymtab_language == language_cplus)
2646 // OBSOLETE /* Also a typedef with the same name. */
2647 // OBSOLETE add_psymbol_to_list (namestring, p - namestring,
2648 // OBSOLETE VAR_DOMAIN, LOC_TYPEDEF,
2649 // OBSOLETE &objfile->static_psymbols,
2650 // OBSOLETE symbol.n_value, 0,
2651 // OBSOLETE psymtab_language, objfile);
2653 #endif /* OBSOLETE CFront */
2658 if (p != namestring) /* a name is there, not just :T... */
2660 add_psymbol_to_list (namestring, p - namestring,
2661 VAR_DOMAIN, LOC_TYPEDEF,
2662 &objfile->static_psymbols,
2664 psymtab_language, objfile);
2667 /* If this is an enumerated type, we need to
2668 add all the enum constants to the partial symbol
2669 table. This does not cover enums without names, e.g.
2670 "enum {a, b} c;" in C, but fortunately those are
2671 rare. There is no way for GDB to find those from the
2672 enum type without spending too much time on it. Thus
2673 to solve this problem, the compiler needs to put out the
2674 enum in a nameless type. GCC2 does this. */
2676 /* We are looking for something of the form
2677 <name> ":" ("t" | "T") [<number> "="] "e"
2678 {<constant> ":" <value> ","} ";". */
2680 /* Skip over the colon and the 't' or 'T'. */
2682 /* This type may be given a number. Also, numbers can come
2683 in pairs like (0,26). Skip over it. */
2684 while ((*p >= '0' && *p <= '9')
2685 || *p == '(' || *p == ',' || *p == ')'
2691 /* The aix4 compiler emits extra crud before the members. */
2694 /* Skip over the type (?). */
2698 /* Skip over the colon. */
2702 /* We have found an enumerated type. */
2703 /* According to comments in read_enum_type
2704 a comma could end it instead of a semicolon.
2705 I don't know where that happens.
2707 while (*p && *p != ';' && *p != ',')
2711 /* Check for and handle cretinous dbx symbol name
2713 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
2714 p = next_symbol_text (objfile);
2716 /* Point to the character after the name
2717 of the enum constant. */
2718 for (q = p; *q && *q != ':'; q++)
2720 /* Note that the value doesn't matter for
2721 enum constants in psymtabs, just in symtabs. */
2722 add_psymbol_to_list (p, q - p,
2723 VAR_DOMAIN, LOC_CONST,
2724 &objfile->static_psymbols, 0,
2725 0, psymtab_language, objfile);
2726 /* Point past the name. */
2728 /* Skip over the value. */
2729 while (*p && *p != ',')
2731 /* Advance past the comma. */
2739 /* Constant, e.g. from "const" in Pascal. */
2740 add_psymbol_to_list (namestring, p - namestring,
2741 VAR_DOMAIN, LOC_CONST,
2742 &objfile->static_psymbols, symbol.n_value,
2743 0, psymtab_language, objfile);
2749 int name_len = p - namestring;
2750 char *name = xmalloc (name_len + 1);
2751 memcpy (name, namestring, name_len);
2752 name[name_len] = '\0';
2753 function_outside_compilation_unit_complaint (name);
2756 symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2757 add_psymbol_to_list (namestring, p - namestring,
2758 VAR_DOMAIN, LOC_BLOCK,
2759 &objfile->static_psymbols,
2761 psymtab_language, objfile);
2764 /* Global functions were ignored here, but now they
2765 are put into the global psymtab like one would expect.
2766 They're also in the minimal symbol table. */
2770 int name_len = p - namestring;
2771 char *name = xmalloc (name_len + 1);
2772 memcpy (name, namestring, name_len);
2773 name[name_len] = '\0';
2774 function_outside_compilation_unit_complaint (name);
2777 symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2778 add_psymbol_to_list (namestring, p - namestring,
2779 VAR_DOMAIN, LOC_BLOCK,
2780 &objfile->global_psymbols,
2782 psymtab_language, objfile);
2785 /* Two things show up here (hopefully); static symbols of
2786 local scope (static used inside braces) or extensions
2787 of structure symbols. We can ignore both. */
2801 case '#': /* for symbol identification (used in live ranges) */
2802 #if 0 /* OBSOLETE CFront */
2803 // OBSOLETE /* added to support cfront stabs strings */
2804 // OBSOLETE case 'Z': /* for definition continuations */
2805 // OBSOLETE case 'P': /* for prototypes */
2806 #endif /* OBSOLETE CFront */
2810 /* It is a C++ nested symbol. We don't need to record it
2811 (I don't think); if we try to look up foo::bar::baz,
2812 then symbols for the symtab containing foo should get
2813 read in, I think. */
2814 /* Someone says sun cc puts out symbols like
2815 /foo/baz/maclib::/usr/local/bin/maclib,
2816 which would get here with a symbol type of ':'. */
2820 /* Unexpected symbol descriptor. The second and subsequent stabs
2821 of a continued stab can show up here. The question is
2822 whether they ever can mimic a normal stab--it would be
2823 nice if not, since we certainly don't want to spend the
2824 time searching to the end of every string looking for
2827 complaint (&symfile_complaints,
2828 "unknown symbol descriptor `%c'", p[1]);
2830 /* Ignore it; perhaps it is an extension that we don't
2840 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2841 ssymnum, dependency_list,
2842 dependencies_used, textlow_not_set);
2845 /* Record the toc offset value of this symbol table into objfile structure.
2846 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2847 this information would be file auxiliary header. */
2849 ((struct coff_symfile_info *) objfile->sym_private)->toc_offset = toc_offset;
2852 /* Return the toc offset value for a given objfile. */
2855 get_toc_offset (struct objfile *objfile)
2858 return ((struct coff_symfile_info *) objfile->sym_private)->toc_offset;
2862 /* Scan and build partial symbols for a symbol file.
2863 We have been initialized by a call to dbx_symfile_init, which
2864 put all the relevant info into a "struct dbx_symfile_info",
2865 hung off the objfile structure.
2867 SECTION_OFFSETS contains offsets relative to which the symbols in the
2868 various sections are (depending where the sections were actually loaded).
2869 MAINLINE is true if we are reading the main symbol
2870 table (as opposed to a shared lib or dynamically loaded file). */
2873 xcoff_initial_scan (struct objfile *objfile, int mainline)
2877 struct cleanup *back_to;
2878 int num_symbols; /* # of symbols */
2879 file_ptr symtab_offset; /* symbol table and */
2880 file_ptr stringtab_offset; /* string table file offsets */
2881 struct coff_symfile_info *info;
2885 info = (struct coff_symfile_info *) objfile->sym_private;
2886 symfile_bfd = abfd = objfile->obfd;
2887 name = objfile->name;
2889 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2890 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2891 stringtab_offset = symtab_offset +
2892 num_symbols * coff_data (abfd)->local_symesz;
2894 info->min_lineno_offset = 0;
2895 info->max_lineno_offset = 0;
2896 bfd_map_over_sections (abfd, find_linenos, info);
2898 if (num_symbols > 0)
2900 /* Read the string table. */
2901 init_stringtab (abfd, stringtab_offset, objfile);
2903 /* Read the .debug section, if present. */
2906 bfd_size_type length;
2907 char *debugsec = NULL;
2909 secp = bfd_get_section_by_name (abfd, ".debug");
2912 length = bfd_section_size (abfd, secp);
2916 (char *) obstack_alloc (&objfile->symbol_obstack, length);
2918 if (!bfd_get_section_contents (abfd, secp, debugsec,
2919 (file_ptr) 0, length))
2921 error ("Error reading .debug section of `%s': %s",
2922 name, bfd_errmsg (bfd_get_error ()));
2926 ((struct coff_symfile_info *) objfile->sym_private)->debugsec =
2931 /* Read the symbols. We keep them in core because we will want to
2932 access them randomly in read_symbol*. */
2933 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2935 error ("Error reading symbols from %s: %s",
2936 name, bfd_errmsg (bfd_get_error ()));
2937 size = coff_data (abfd)->local_symesz * num_symbols;
2938 ((struct coff_symfile_info *) objfile->sym_private)->symtbl =
2939 obstack_alloc (&objfile->symbol_obstack, size);
2940 ((struct coff_symfile_info *) objfile->sym_private)->symtbl_num_syms =
2943 val = bfd_bread (((struct coff_symfile_info *) objfile->sym_private)->symtbl,
2946 perror_with_name ("reading symbol table");
2948 /* If we are reinitializing, or if we have never loaded syms yet, init */
2950 || (objfile->global_psymbols.size == 0
2951 && objfile->static_psymbols.size == 0))
2952 /* I'm not sure how how good num_symbols is; the rule of thumb in
2953 init_psymbol_list was developed for a.out. On the one hand,
2954 num_symbols includes auxents. On the other hand, it doesn't
2956 init_psymbol_list (objfile, num_symbols);
2958 free_pending_blocks ();
2959 back_to = make_cleanup (really_free_pendings, 0);
2961 init_minimal_symbol_collection ();
2962 make_cleanup_discard_minimal_symbols ();
2964 /* Now that the symbol table data of the executable file are all in core,
2965 process them and define symbols accordingly. */
2967 scan_xcoff_symtab (objfile);
2969 /* Install any minimal symbols that have been collected as the current
2970 minimal symbols for this objfile. */
2972 install_minimal_symbols (objfile);
2974 do_cleanups (back_to);
2978 xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
2980 asection *sect = NULL;
2983 objfile->num_sections = bfd_count_sections (objfile->obfd);
2984 objfile->section_offsets = (struct section_offsets *)
2985 obstack_alloc (&objfile->psymbol_obstack,
2986 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
2988 /* Initialize the section indexes for future use. */
2989 sect = bfd_get_section_by_name (objfile->obfd, ".text");
2991 objfile->sect_index_text = sect->index;
2993 sect = bfd_get_section_by_name (objfile->obfd, ".data");
2995 objfile->sect_index_data = sect->index;
2997 sect = bfd_get_section_by_name (objfile->obfd, ".bss");
2999 objfile->sect_index_bss = sect->index;
3001 sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
3003 objfile->sect_index_rodata = sect->index;
3005 for (i = 0; i < objfile->num_sections; ++i)
3007 /* syms_from_objfile kindly subtracts from addr the
3008 bfd_section_vma of the .text section. This strikes me as
3009 wrong--whether the offset to be applied to symbol reading is
3010 relative to the start address of the section depends on the
3011 symbol format. In any event, this whole "addr" concept is
3012 pretty broken (it doesn't handle any section but .text
3013 sensibly), so just ignore the addr parameter and use 0.
3014 rs6000-nat.c will set the correct section offsets via
3015 objfile_relocate. */
3016 (objfile->section_offsets)->offsets[i] = 0;
3020 /* Register our ability to parse symbols for xcoff BFD files. */
3022 static struct sym_fns xcoff_sym_fns =
3025 /* It is possible that coff and xcoff should be merged as
3026 they do have fundamental similarities (for example, the extra storage
3027 classes used for stabs could presumably be recognized in any COFF file).
3028 However, in addition to obvious things like all the csect hair, there are
3029 some subtler differences between xcoffread.c and coffread.c, notably
3030 the fact that coffread.c has no need to read in all the symbols, but
3031 xcoffread.c reads all the symbols and does in fact randomly access them
3032 (in C_BSTAT and line number processing). */
3034 bfd_target_xcoff_flavour,
3036 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3037 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3038 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
3039 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
3040 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
3041 NULL /* next: pointer to next struct sym_fns */
3045 _initialize_xcoffread (void)
3047 add_symtab_fns (&xcoff_sym_fns);
3049 func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
3050 "<function, no debug info>", NULL);
3051 TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
3053 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
3054 "<variable, no debug info>", NULL);