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, 1996
3 Free Software Foundation, Inc.
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include <sys/types.h>
29 #include "gdb_string.h"
31 #include <sys/param.h>
37 #include "coff/internal.h"
38 #include "libcoff.h" /* FIXME, internal data from BFD */
39 #include "coff/rs6000.h"
46 #include "stabsread.h"
47 #include "expression.h"
48 #include "language.h" /* Needed inside partial-stab.h */
49 #include "complaints.h"
51 #include "gdb-stabs.h"
53 /* For interface with stabsread.c. */
54 #include "aout/stab_gnu.h"
56 /* For interface with partial-stab.h. */
57 #define N_UNDF 0 /* Undefined symbol */
60 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
61 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
62 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
63 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
64 #define N_FN 0x1f /* File name of .o file */
65 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
66 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
67 N_DATA, or N_BSS. When the low-order bit of other types is set,
68 (e.g. N_WARNING versus N_FN), they are two different types. */
69 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
72 /* The following symbols refer to set elements.
73 All the N_SET[ATDB] symbols with the same name form one set.
74 Space is allocated for the set in the text section, and each set
75 elements value is stored into one word of the space.
76 The first word of the space is the length of the set (number of elements).
78 The address of the set is made into an N_SETV symbol
79 whose name is the same as the name of the set.
80 This symbol acts like a N_DATA global symbol
81 in that it can satisfy undefined external references. */
83 /* These appear as input to LD, in a .o file. */
84 #define N_SETA 0x14 /* Absolute set element symbol */
85 #define N_SETT 0x16 /* Text set element symbol */
86 #define N_SETD 0x18 /* Data set element symbol */
87 #define N_SETB 0x1A /* Bss set element symbol */
89 /* This is output from LD. */
90 #define N_SETV 0x1C /* Pointer to set vector in data area. */
92 /* Hook for recording the toc offset value of a symbol table into
93 the ldinfo structure. */
95 void (*xcoff_add_toc_to_loadinfo_hook) PARAMS ((unsigned long)) = NULL;
97 /* Hook for recording how to call xcoff_init_loadinfo for a native
98 rs6000 config only. */
100 void (*xcoff_init_loadinfo_hook) PARAMS ((void)) = NULL;
103 /* We put a pointer to this structure in the read_symtab_private field
108 /* First symbol number for this file. */
112 /* Number of symbols in the section of the symbol table devoted to
113 this file's symbols (actually, the section bracketed may contain
114 more than just this file's symbols). If numsyms is 0, the only
115 reason for this thing's existence is the dependency list. Nothing
116 else will happen when it is read in. */
120 /* Position of the start of the line number information for this psymtab. */
121 unsigned int lineno_off;
124 /* Remember what we deduced to be the source language of this psymtab. */
126 static enum language psymtab_language = language_unknown;
129 /* Simplified internal version of coff symbol table information */
133 int c_symnum; /* symbol number of this entry */
134 int c_naux; /* 0 if syment only, 1 if syment + auxent */
136 unsigned char c_sclass;
141 /* last function's saved coff symbol `cs' */
143 static struct coff_symbol fcn_cs_saved;
145 static bfd *symfile_bfd;
147 /* Core address of start and end of text of current source file.
148 This is calculated from the first function seen after a C_FILE
152 static CORE_ADDR cur_src_end_addr;
154 /* Core address of the end of the first object file. */
156 static CORE_ADDR first_object_file_end;
158 /* initial symbol-table-debug-string vector length */
160 #define INITIAL_STABVECTOR_LENGTH 40
162 /* Nonzero if within a function (so symbols should be local,
163 if nothing says specifically). */
167 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
168 there is any reason not to just use a #define, but might as well
169 ask BFD for the size and store it here, I guess. */
171 static unsigned local_symesz;
173 struct coff_symfile_info {
174 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
175 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
177 /* Pointer to the string table. */
180 /* Pointer to debug section. */
183 /* Pointer to the a.out symbol table. */
186 /* Number of symbols in symtbl. */
190 static struct complaint storclass_complaint =
191 {"Unexpected storage class: %d", 0, 0};
193 static struct complaint bf_notfound_complaint =
194 {"line numbers off, `.bf' symbol not found", 0, 0};
196 static struct complaint ef_complaint =
197 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
199 static struct complaint eb_complaint =
200 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
203 enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
204 CORE_ADDR, CORE_ADDR, unsigned *));
207 init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));
210 xcoff_symfile_init PARAMS ((struct objfile *));
213 xcoff_new_init PARAMS ((struct objfile *));
216 xcoff_symfile_finish PARAMS ((struct objfile *));
218 static struct section_offsets *
219 xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
222 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
225 coff_getfilename PARAMS ((union internal_auxent *, struct objfile *));
228 read_symbol PARAMS ((struct internal_syment *, int));
231 read_symbol_lineno PARAMS ((int));
234 read_symbol_nvalue PARAMS ((int));
236 static struct symbol *
237 process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
240 read_xcoff_symtab PARAMS ((struct partial_symtab *));
243 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
246 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
248 static int secnum_to_section PARAMS ((int, struct objfile *));
250 struct find_targ_sec_arg {
255 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
257 static void find_targ_sec (abfd, sect, obj)
262 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
263 if (sect->target_index == args->targ_index)
265 /* This is the section. Figure out what SECT_OFF_* code it is. */
266 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
267 *args->resultp = SECT_OFF_TEXT;
268 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
269 *args->resultp = SECT_OFF_DATA;
271 *args->resultp = SECT_OFF_BSS;
275 /* Return the section number (SECT_OFF_*) that CS points to. */
277 secnum_to_section (secnum, objfile)
279 struct objfile *objfile;
281 int off = SECT_OFF_TEXT;
282 struct find_targ_sec_arg args;
283 args.targ_index = secnum;
285 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
289 /* add a given stab string into given stab vector. */
292 add_stab_to_list (stabname, stabvector)
294 struct pending_stabs **stabvector;
296 if ( *stabvector == NULL) {
297 *stabvector = (struct pending_stabs *)
298 xmalloc (sizeof (struct pending_stabs) +
299 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
300 (*stabvector)->count = 0;
301 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
303 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;
312 /* Linenos are processed on a file-by-file basis.
316 1) xlc (IBM's native c compiler) postpones static function code
317 emission to the end of a compilation unit. This way it can
318 determine if those functions (statics) are needed or not, and
319 can do some garbage collection (I think). This makes line
320 numbers and corresponding addresses unordered, and we end up
321 with a line table like:
338 and that breaks gdb's binary search on line numbers, if the
339 above table is not sorted on line numbers. And that sort
340 should be on function based, since gcc can emit line numbers
343 10 0x100 - for the init/test part of a for stmt.
346 10 0x400 - for the increment part of a for stmt.
348 arrange_linetable() will do this sorting.
350 2) aix symbol table might look like:
352 c_file // beginning of a new file
353 .bi // beginning of include file
354 .ei // end of include file
358 basically, .bi/.ei pairs do not necessarily encapsulate
359 their scope. They need to be recorded, and processed later
360 on when we come the end of the compilation unit.
361 Include table (inclTable) and process_linenos() handle
364 /* compare line table entry addresses. */
367 compare_lte (lte1, lte2)
368 struct linetable_entry *lte1, *lte2;
370 return lte1->pc - lte2->pc;
373 /* Given a line table with function entries are marked, arrange its functions
374 in ascending order and strip off function entry markers and return it in
375 a newly created table. If the old one is good enough, return the old one. */
376 /* FIXME: I think all this stuff can be replaced by just passing
377 sort_linevec = 1 to end_symtab. */
379 static struct linetable *
380 arrange_linetable (oldLineTb)
381 struct linetable *oldLineTb; /* old linetable */
384 newline, /* new line count */
385 function_count; /* # of functions */
387 struct linetable_entry *fentry; /* function entry vector */
388 int fentry_size; /* # of function entries */
389 struct linetable *newLineTb; /* new line table */
391 #define NUM_OF_FUNCTIONS 20
393 fentry_size = NUM_OF_FUNCTIONS;
394 fentry = (struct linetable_entry*)
395 xmalloc (fentry_size * sizeof (struct linetable_entry));
397 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
399 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
401 if (function_count >= fentry_size) { /* make sure you have room. */
403 fentry = (struct linetable_entry*)
404 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
406 fentry[function_count].line = ii;
407 fentry[function_count].pc = oldLineTb->item[ii].pc;
412 if (function_count == 0) {
416 else if (function_count > 1)
417 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
419 /* allocate a new line table. */
420 newLineTb = (struct linetable *)
422 (sizeof (struct linetable) +
423 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
425 /* if line table does not start with a function beginning, copy up until
429 if (oldLineTb->item[0].line != 0)
431 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
432 newLineTb->item[newline] = oldLineTb->item[newline];
434 /* Now copy function lines one by one. */
436 for (ii=0; ii < function_count; ++ii) {
437 for (jj = fentry[ii].line + 1;
438 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
440 newLineTb->item[newline] = oldLineTb->item[jj];
443 newLineTb->nitems = oldLineTb->nitems - function_count;
447 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
448 following `IncludeChain'. At the end of each symtab (end_symtab),
449 we will determine if we should create additional symtab's to
450 represent if (the include files. */
453 typedef struct _inclTable {
454 char *name; /* include filename */
456 /* Offsets to the line table. end points to the last entry which is
457 part of this include file. */
460 struct subfile *subfile;
461 unsigned funStartLine; /* start line # of its function */
464 #define INITIAL_INCLUDE_TABLE_LENGTH 20
465 static InclTable *inclTable; /* global include table */
466 static int inclIndx; /* last entry to table */
467 static int inclLength; /* table length */
468 static int inclDepth; /* nested include depth */
470 static void allocate_include_entry PARAMS ((void));
473 record_include_begin (cs)
474 struct coff_symbol *cs;
478 /* In xcoff, we assume include files cannot be nested (not in .c files
479 of course, but in corresponding .s files.). */
481 /* This can happen with old versions of GCC.
482 GCC 2.3.3-930426 does not exhibit this on a test case which
483 a user said produced the message for him. */
484 static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
489 allocate_include_entry ();
491 inclTable [inclIndx].name = cs->c_name;
492 inclTable [inclIndx].begin = cs->c_value;
496 record_include_end (cs)
497 struct coff_symbol *cs;
503 static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
507 allocate_include_entry ();
509 pTbl = &inclTable [inclIndx];
510 pTbl->end = cs->c_value;
517 allocate_include_entry ()
519 if (inclTable == NULL)
521 inclTable = (InclTable *)
522 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
524 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
525 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
528 else if (inclIndx >= inclLength)
530 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
531 inclTable = (InclTable *)
532 xrealloc (inclTable, sizeof (InclTable) * inclLength);
533 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
534 '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
538 /* Global variable to pass the psymtab down to all the routines involved
539 in psymtab to symtab processing. */
540 static struct partial_symtab *this_symtab_psymtab;
542 /* given the start and end addresses of a compilation unit (or a csect,
543 at times) process its lines and create appropriate line vectors. */
546 process_linenos (start, end)
547 CORE_ADDR start, end;
550 file_ptr max_offset =
551 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
554 /* subfile structure for the main compilation unit. */
555 struct subfile main_subfile;
557 /* In the main source file, any time we see a function entry, we
558 reset this variable to function's absolute starting line number.
559 All the following line numbers in the function are relative to
560 this, and we record absolute line numbers in record_line(). */
562 unsigned int main_source_baseline = 0;
567 ((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off;
569 goto return_after_cleanup;
571 memset (&main_subfile, '\0', sizeof (main_subfile));
574 /* All source lines were in the main source file. None in include files. */
576 enter_line_range (&main_subfile, offset, 0, start, end,
577 &main_source_baseline);
581 /* There was source with line numbers in include files. */
582 main_source_baseline = 0;
583 for (ii=0; ii < inclIndx; ++ii)
585 struct subfile *tmpSubfile;
587 /* If there is main file source before include file, enter it. */
588 if (offset < inclTable[ii].begin)
591 (&main_subfile, offset, inclTable[ii].begin - LINESZ,
592 start, 0, &main_source_baseline);
595 /* Have a new subfile for the include file. */
597 tmpSubfile = inclTable[ii].subfile =
598 (struct subfile *) xmalloc (sizeof (struct subfile));
600 memset (tmpSubfile, '\0', sizeof (struct subfile));
601 firstLine = &(inclTable[ii].funStartLine);
603 /* Enter include file's lines now. */
604 enter_line_range (tmpSubfile, inclTable[ii].begin,
605 inclTable[ii].end, start, 0, firstLine);
607 if (offset <= inclTable[ii].end)
608 offset = inclTable[ii].end + LINESZ;
611 /* All the include files' line have been processed at this point. Now,
612 enter remaining lines of the main file, if any left. */
613 if (offset < max_offset + 1 - LINESZ)
615 enter_line_range (&main_subfile, offset, 0, start, end,
616 &main_source_baseline);
620 /* Process main file's line numbers. */
621 if (main_subfile.line_vector)
623 struct linetable *lineTb, *lv;
625 lv = main_subfile.line_vector;
627 /* Line numbers are not necessarily ordered. xlc compilation will
628 put static function to the end. */
630 lineTb = arrange_linetable (lv);
633 current_subfile->line_vector = (struct linetable *)
634 xrealloc (lv, (sizeof (struct linetable)
635 + lv->nitems * sizeof (struct linetable_entry)));
640 current_subfile->line_vector = lineTb;
643 current_subfile->line_vector_length =
644 current_subfile->line_vector->nitems;
647 /* Now, process included files' line numbers. */
649 for (ii=0; ii < inclIndx; ++ii)
651 if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */
653 struct linetable *lineTb, *lv;
655 lv = (inclTable[ii].subfile)->line_vector;
657 /* Line numbers are not necessarily ordered. xlc compilation will
658 put static function to the end. */
660 lineTb = arrange_linetable (lv);
664 /* For the same include file, we might want to have more than one
665 subfile. This happens if we have something like:
673 while foo.h including code in it. (stupid but possible)
674 Since start_subfile() looks at the name and uses an
675 existing one if finds, we need to provide a fake name and
679 start_subfile (inclTable[ii].name, (char*)0);
682 /* Pick a fake name that will produce the same results as this
683 one when passed to deduce_language_from_filename. Kludge on
685 char *fakename = strrchr (inclTable[ii].name, '.');
686 if (fakename == NULL)
688 start_subfile (fakename, (char*)0);
689 free (current_subfile->name);
691 current_subfile->name = strdup (inclTable[ii].name);
696 current_subfile->line_vector =
697 (struct linetable *) xrealloc
698 (lv, (sizeof (struct linetable)
699 + lv->nitems * sizeof (struct linetable_entry)));
705 current_subfile->line_vector = lineTb;
708 current_subfile->line_vector_length =
709 current_subfile->line_vector->nitems;
710 start_subfile (pop_subfile (), (char*)0);
714 return_after_cleanup:
716 /* We don't want to keep alloc/free'ing the global include file table. */
719 /* Start with a fresh subfile structure for the next file. */
720 memset (&main_subfile, '\0', sizeof (struct subfile));
724 aix_process_linenos ()
726 /* process line numbers and enter them into line vector */
727 process_linenos (last_source_start_addr, cur_src_end_addr);
731 /* Enter a given range of lines into the line vector.
732 can be called in the following two ways:
733 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
734 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
736 endoffset points to the last line table entry that we should pay
740 enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr,
742 struct subfile *subfile;
743 unsigned beginoffset, endoffset; /* offsets to line table */
744 CORE_ADDR startaddr, endaddr;
747 unsigned int curoffset;
749 struct external_lineno ext_lnno;
750 struct internal_lineno int_lnno;
751 unsigned int limit_offset;
754 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
756 curoffset = beginoffset;
758 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
763 if (endoffset >= limit_offset)
765 static struct complaint msg =
766 {"Bad line table offset in C_EINCL directive", 0, 0};
770 limit_offset = endoffset;
774 abfd = this_symtab_psymtab->objfile->obfd;
776 while (curoffset <= limit_offset)
778 bfd_seek (abfd, curoffset, SEEK_SET);
779 bfd_read (&ext_lnno, sizeof (struct external_lineno), 1, abfd);
780 bfd_coff_swap_lineno_in (abfd, &ext_lnno, &int_lnno);
782 /* Find the address this line represents. */
783 addr = (int_lnno.l_lnno
784 ? int_lnno.l_addr.l_paddr
785 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
786 addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
789 if (addr < startaddr || (endaddr && addr >= endaddr))
792 if (int_lnno.l_lnno == 0)
794 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
795 record_line (subfile, 0, addr);
799 record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
805 /* Save the vital information for use when closing off the current file.
806 NAME is the file name the symbols came from, START_ADDR is the first
807 text address for the file, and SIZE is the number of bytes of text. */
809 #define complete_symtab(name, start_addr) { \
810 last_source_file = savestring (name, strlen (name)); \
811 last_source_start_addr = start_addr; \
815 /* Refill the symbol table input buffer
816 and set the variables that control fetching entries from it.
817 Reports an error if no data available.
818 This function can read past the end of the symbol table
819 (into the string table) but this does no harm. */
821 /* Reading symbol table has to be fast! Keep the followings as macros, rather
824 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
828 if (namestr[0] == '.') ++namestr; \
829 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
830 (char *)NULL, (SECTION), (OBJFILE)); \
831 misc_func_recorded = 1; \
835 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
836 nested. At any given time, a symbol can only be in one static block.
837 This is the base address of current static block, zero if non exists. */
839 static int static_block_base = 0;
841 /* Section number for the current static block. */
843 static int static_block_section = -1;
845 /* true if space for symbol name has been allocated. */
847 static int symname_alloced = 0;
849 /* Next symbol to read. Pointer into raw seething symbol table. */
851 static char *raw_symbol;
853 /* This is the function which stabsread.c calls to get symbol
856 xcoff_next_symbol_text (objfile)
857 struct objfile *objfile;
859 struct internal_syment symbol;
860 static struct complaint msg =
861 {"Unexpected symbol continuation", 0, 0};
863 /* FIXME: is this the same as the passed arg? */
864 objfile = this_symtab_psymtab->objfile;
866 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
871 /* Return something which points to '\0' and hope the symbol reading
872 code does something reasonable. */
875 else if (symbol.n_sclass & 0x80)
878 ((struct coff_symfile_info *)objfile->sym_private)->debugsec
881 coff_data (objfile->obfd)->local_symesz;
888 /* Return something which points to '\0' and hope the symbol reading
889 code does something reasonable. */
895 /* Read symbols for a given partial symbol table. */
898 read_xcoff_symtab (pst)
899 struct partial_symtab *pst;
901 struct objfile *objfile = pst->objfile;
902 bfd *abfd = objfile->obfd;
903 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
904 char *strtbl = ((struct coff_symfile_info *)objfile->sym_private)->strtbl;
906 ((struct coff_symfile_info *)objfile->sym_private)->debugsec;
908 struct internal_syment symbol[1];
909 union internal_auxent main_aux;
910 struct coff_symbol cs[1];
911 CORE_ADDR file_start_addr = 0;
912 CORE_ADDR file_end_addr = 0;
914 int next_file_symnum = -1;
915 unsigned int max_symnum;
916 int just_started = 1;
918 int fcn_start_addr = 0;
920 struct coff_symbol fcn_stab_saved;
922 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
923 union internal_auxent fcn_aux_saved;
924 struct context_stack *new;
926 char *filestring = " _start_ "; /* Name of the current file. */
928 char *last_csect_name; /* last seen csect's name and value */
929 CORE_ADDR last_csect_val;
932 this_symtab_psymtab = pst;
934 /* Get the appropriate COFF "constants" related to the file we're
936 local_symesz = coff_data (abfd)->local_symesz;
938 last_source_file = NULL;
943 start_symtab (filestring, (char *)NULL, file_start_addr);
944 symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum;
946 symnum + ((struct symloc *)pst->read_symtab_private)->numsyms;
947 first_object_file_end = 0;
950 ((struct coff_symfile_info *) objfile->sym_private)->symtbl
951 + symnum * local_symesz;
953 while (symnum < max_symnum)
956 QUIT; /* make this command interruptable. */
958 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
959 /* read one symbol into `cs' structure. After processing the
960 whole symbol table, only string table will be kept in memory,
961 symbol table and debug section of xcoff will be freed. Thus
962 we can mark symbols with names in string table as
967 /* Swap and align the symbol into a reasonable C structure. */
968 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
970 cs->c_symnum = symnum;
971 cs->c_naux = symbol->n_numaux;
972 if (symbol->n_zeroes)
975 /* We must use the original, unswapped, name here so the name field
976 pointed to by cs->c_name will persist throughout xcoffread. If
977 we use the new field, it gets overwritten for each symbol. */
978 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
979 /* If it's exactly E_SYMNMLEN characters long it isn't
981 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
984 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
985 strncpy (p, cs->c_name, E_SYMNMLEN);
986 p[E_SYMNMLEN] = '\0';
991 else if (symbol->n_sclass & 0x80)
993 cs->c_name = debugsec + symbol->n_offset;
998 /* in string table */
999 cs->c_name = strtbl + (int)symbol->n_offset;
1000 symname_alloced = 1;
1002 cs->c_value = symbol->n_value;
1003 cs->c_sclass = symbol->n_sclass;
1004 cs->c_secnum = symbol->n_scnum;
1005 cs->c_type = (unsigned)symbol->n_type;
1007 raw_symbol += coff_data (abfd)->local_symesz;
1010 /* Save addr of first aux entry. */
1011 raw_auxptr = raw_symbol;
1013 /* Skip all the auxents associated with this symbol. */
1014 for (ii = symbol->n_numaux; ii; --ii)
1016 raw_symbol += coff_data (abfd)->local_auxesz;
1021 /* if symbol name starts with ".$" or "$", ignore it. */
1022 if (cs->c_name[0] == '$'
1023 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1026 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1028 if (last_source_file)
1031 end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT);
1036 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
1037 cur_src_end_addr = first_object_file_end;
1038 /* done with all files, everything from here on is globals */
1041 /* if explicitly specified as a function, treat is as one. */
1042 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF)
1044 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1045 0, cs->c_naux, &main_aux);
1046 goto function_entry_point;
1049 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1052 /* Dealing with a symbol with a csect entry. */
1054 #define CSECT(PP) ((PP)->x_csect)
1055 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1056 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1057 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1058 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1060 /* Convert the auxent to something we can access. */
1061 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1062 0, cs->c_naux, &main_aux);
1064 switch (CSECT_SMTYP (&main_aux))
1068 /* Ignore all external references. */
1072 /* A section description. */
1074 switch (CSECT_SCLAS (&main_aux))
1080 /* A program csect is seen. We have to allocate one
1081 symbol table for each program csect. Normally gdb
1082 prefers one symtab for each source file. In case
1083 of AIX, one source file might include more than one
1084 [PR] csect, and they don't have to be adjacent in
1085 terms of the space they occupy in memory. Thus, one
1086 single source file might get fragmented in the
1087 memory and gdb's file start and end address
1088 approach does not work! GCC (and I think xlc) seem
1089 to put all the code in the unnamed program csect. */
1091 if (last_csect_name)
1093 complete_symtab (filestring, file_start_addr);
1094 cur_src_end_addr = file_end_addr;
1095 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
1098 /* Give all csects for this source file the same
1100 start_symtab (filestring, NULL, (CORE_ADDR)0);
1103 /* If this is the very first csect seen,
1104 basically `__start'. */
1107 first_object_file_end
1108 = cs->c_value + CSECT_LEN (&main_aux);
1113 cs->c_value + ANOFFSET (objfile->section_offsets,
1115 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1117 if (cs->c_name && cs->c_name[0] == '.')
1119 last_csect_name = cs->c_name;
1120 last_csect_val = cs->c_value;
1121 last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
1126 /* All other symbols are put into the minimal symbol
1139 /* Ignore the symbol. */
1147 switch (CSECT_SCLAS (&main_aux))
1150 /* a function entry point. */
1151 function_entry_point:
1153 fcn_start_addr = cs->c_value;
1155 /* save the function header info, which will be used
1156 when `.bf' is seen. */
1158 fcn_aux_saved = main_aux;
1162 /* shared library function trampoline code entry point. */
1166 /* The symbols often have the same names as debug symbols for
1167 functions, and confuse lookup_symbol. */
1171 /* xlc puts each variable in a separate csect, so we get
1172 an XTY_SD for each variable. But gcc puts several
1173 variables in a csect, so that each variable only gets
1174 an XTY_LD. This will typically be XMC_RW; I suspect
1175 XMC_RO and XMC_BS might be possible too.
1176 These variables are put in the minimal symbol table
1183 /* Common symbols are put into the minimal symbol table only. */
1191 switch (cs->c_sclass)
1196 /* c_value field contains symnum of next .file entry in table
1197 or symnum of first global after last .file. */
1199 next_file_symnum = cs->c_value;
1201 /* Complete symbol table for last object file containing
1202 debugging information. */
1204 /* Whether or not there was a csect in the previous file, we
1205 have to call `end_stabs' and `start_stabs' to reset
1206 type_vector, line_vector, etc. structures. */
1208 complete_symtab (filestring, file_start_addr);
1209 cur_src_end_addr = file_end_addr;
1210 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
1213 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1214 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1215 standard COFF way and put it in the auxent. We use the auxent if
1216 the symbol is ".file" and an auxent exists, otherwise use the symbol
1217 itself. Simple enough. */
1218 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1220 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1221 0, cs->c_naux, &main_aux);
1222 filestring = coff_getfilename (&main_aux, objfile);
1225 filestring = cs->c_name;
1228 start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
1229 last_csect_name = 0;
1231 /* reset file start and end addresses. A compilation unit with no text
1232 (only data) should have zero file boundaries. */
1233 file_start_addr = file_end_addr = 0;
1237 fcn_stab_saved = *cs;
1241 if (STREQ (cs->c_name, ".bf"))
1243 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1245 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1246 0, cs->c_naux, &main_aux);
1248 within_function = 1;
1250 new = push_context (0, fcn_start_addr + off);
1252 new->name = define_symbol
1253 (fcn_cs_saved.c_value + off,
1254 fcn_stab_saved.c_name, 0, 0, objfile);
1255 if (new->name != NULL)
1256 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT;
1258 else if (STREQ (cs->c_name, ".ef"))
1261 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1262 0, cs->c_naux, &main_aux);
1264 /* The value of .ef is the address of epilogue code;
1265 not useful for gdb. */
1266 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1267 contains number of lines to '}' */
1269 if (context_stack_depth <= 0)
1270 { /* We attempted to pop an empty context stack */
1271 complain (&ef_complaint, cs->c_symnum);
1272 within_function = 0;
1275 new = pop_context ();
1276 /* Stack must be empty now. */
1277 if (context_stack_depth > 0 || new == NULL)
1279 complain (&ef_complaint, cs->c_symnum);
1280 within_function = 0;
1284 finish_block (new->name, &local_symbols, new->old_blocks,
1286 (fcn_cs_saved.c_value
1287 + fcn_aux_saved.x_sym.x_misc.x_fsize
1288 + ANOFFSET (objfile->section_offsets,
1291 within_function = 0;
1296 /* Begin static block. */
1298 struct internal_syment symbol;
1300 read_symbol (&symbol, cs->c_value);
1301 static_block_base = symbol.n_value;
1302 static_block_section =
1303 secnum_to_section (symbol.n_scnum, objfile);
1308 /* End of static block. */
1309 static_block_base = 0;
1310 static_block_section = -1;
1321 static struct complaint msg =
1322 {"Unrecognized storage class %d.", 0, 0};
1323 complain (&msg, cs->c_sclass);
1337 /* beginning of include file */
1338 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1339 order. Thus, when wee see them, we might not know enough info
1340 to process them. Thus, we'll be saving them into a table
1341 (inclTable) and postpone their processing. */
1343 record_include_begin (cs);
1347 /* End of include file. */
1348 /* See the comment after case C_BINCL. */
1349 record_include_end (cs);
1353 if (STREQ (cs->c_name, ".bb"))
1356 new = push_context (depth,
1358 + ANOFFSET (objfile->section_offsets,
1361 else if (STREQ (cs->c_name, ".eb"))
1363 if (context_stack_depth <= 0)
1364 { /* We attempted to pop an empty context stack */
1365 complain (&eb_complaint, cs->c_symnum);
1368 new = pop_context ();
1369 if (depth-- != new->depth)
1371 complain (&eb_complaint, cs->c_symnum);
1374 if (local_symbols && context_stack_depth > 0)
1376 /* Make a block for the local symbols within. */
1377 finish_block (new->name, &local_symbols, new->old_blocks,
1380 + ANOFFSET (objfile->section_offsets,
1384 local_symbols = new->locals;
1389 process_xcoff_symbol (cs, objfile);
1394 if (last_source_file)
1398 complete_symtab (filestring, file_start_addr);
1399 cur_src_end_addr = file_end_addr;
1400 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
1401 /* When reading symbols for the last C_FILE of the objfile, try
1402 to make sure that we set pst->symtab to the symtab for the
1403 file, not to the _globals_ symtab. I'm not sure whether this
1404 actually works right or when/if it comes up. */
1405 if (pst->symtab == NULL)
1411 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1412 (SYMBOL2) = (struct symbol *) \
1413 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1414 *(SYMBOL2) = *(SYMBOL1);
1417 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1418 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1421 static struct type *func_symbol_type;
1422 static struct type *var_symbol_type;
1424 /* process one xcoff symbol. */
1426 static struct symbol *
1427 process_xcoff_symbol (cs, objfile)
1428 register struct coff_symbol *cs;
1429 struct objfile *objfile;
1431 struct symbol onesymbol;
1432 register struct symbol *sym = &onesymbol;
1433 struct symbol *sym2 = NULL;
1439 if (cs->c_secnum < 0)
1441 /* The value is a register number, offset within a frame, etc.,
1442 and does not get relocated. */
1448 sec = secnum_to_section (cs->c_secnum, objfile);
1449 off = ANOFFSET (objfile->section_offsets, sec);
1456 memset (sym, '\0', sizeof (struct symbol));
1458 /* default assumptions */
1459 SYMBOL_VALUE (sym) = cs->c_value + off;
1460 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1461 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1463 if (ISFCN (cs->c_type))
1465 /* At this point, we don't know the type of the function. This
1466 will be patched with the type from its stab entry later on in
1467 patch_block_stabs (), unless the file was compiled without -g. */
1469 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1470 SYMBOL_TYPE (sym) = func_symbol_type;
1472 SYMBOL_CLASS (sym) = LOC_BLOCK;
1473 SYMBOL_DUP (sym, sym2);
1475 if (cs->c_sclass == C_EXT)
1476 add_symbol_to_list (sym2, &global_symbols);
1477 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1478 add_symbol_to_list (sym2, &file_symbols);
1482 /* In case we can't figure out the type, provide default. */
1483 SYMBOL_TYPE (sym) = var_symbol_type;
1485 switch (cs->c_sclass)
1488 /* The values of functions and global symbols are now resolved
1489 via the global_sym_chain in stabsread.c. */
1491 if (fcn_cs_saved.c_sclass == C_EXT)
1492 add_stab_to_list (name, &global_stabs);
1494 add_stab_to_list (name, &file_stabs);
1498 add_stab_to_list (name, &global_stabs);
1503 common_block_start (cs->c_name, objfile);
1507 common_block_end (objfile);
1511 complain (&storclass_complaint, cs->c_sclass);
1523 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1526 SYMBOL_SECTION (sym) = sec;
1533 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1534 all statics and we need to distinguish file-scope versus
1535 function-scope using within_function. We do this by
1536 changing the string we pass to define_symbol to use 'S'
1537 where we need to, which is not necessarily super-clean,
1538 but seems workable enough. */
1540 if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
1544 if (*pp == 'V' && !within_function)
1546 sym = define_symbol ((cs->c_value
1547 + ANOFFSET (objfile->section_offsets,
1548 static_block_section)),
1549 cs->c_name, 0, 0, objfile);
1552 SYMBOL_VALUE (sym) += static_block_base;
1553 SYMBOL_SECTION (sym) = static_block_section;
1562 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1563 only the last component of the name. Result is in static storage and
1564 is only good for temporary use. */
1567 coff_getfilename (aux_entry, objfile)
1568 union internal_auxent *aux_entry;
1569 struct objfile *objfile;
1571 static char buffer[BUFSIZ];
1572 register char *temp;
1575 if (aux_entry->x_file.x_n.x_zeroes == 0)
1577 ((struct coff_symfile_info *)objfile->sym_private)->strtbl
1578 + aux_entry->x_file.x_n.x_offset);
1581 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1582 buffer[FILNMLEN] = '\0';
1586 /* FIXME: We should not be throwing away the information about what
1587 directory. It should go into dirname of the symtab, or some such
1589 if ((temp = strrchr (result, '/')) != NULL)
1594 /* Set *SYMBOL to symbol number symno in symtbl. */
1596 read_symbol (symbol, symno)
1597 struct internal_syment *symbol;
1601 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1604 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1606 if (symno < 0 || symno >= nsyms)
1608 static struct complaint msg =
1609 {"Invalid symbol offset", 0, 0};
1611 symbol->n_value = 0;
1612 symbol->n_scnum = -1;
1615 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1616 stbl + (symno*local_symesz),
1620 /* Get value corresponding to symbol number symno in symtbl. */
1623 read_symbol_nvalue (symno)
1626 struct internal_syment symbol[1];
1628 read_symbol (symbol, symno);
1629 return symbol->n_value;
1633 /* Find the address of the function corresponding to symno, where
1634 symno is the symbol pointed to by the linetable. */
1637 read_symbol_lineno (symno)
1641 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1644 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1646 struct internal_syment symbol[1];
1647 union internal_auxent main_aux[1];
1651 complain (&bf_notfound_complaint);
1655 /* Note that just searching for a short distance (e.g. 50 symbols)
1656 is not enough, at least in the following case.
1659 [many .stabx entries]
1660 [a few functions, referring to foo]
1664 What happens here is that the assembler moves the .stabx entries
1665 to right before the ".bf" for foo, but the symbol for "foo" is before
1666 all the stabx entries. See PR gdb/2222. */
1668 /* Maintaining a table of .bf entries might be preferable to this search.
1669 If I understand things correctly it would need to be done only for
1670 the duration of a single psymtab to symtab conversion. */
1671 while (symno < nsyms)
1673 bfd_coff_swap_sym_in (symfile_bfd,
1674 stbl + (symno * local_symesz), symbol);
1675 if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf"))
1677 symno += symbol->n_numaux + 1;
1680 complain (&bf_notfound_complaint);
1684 /* take aux entry and return its lineno */
1686 bfd_coff_swap_aux_in (this_symtab_psymtab->objfile->obfd,
1687 stbl + symno * local_symesz,
1688 symbol->n_type, symbol->n_sclass,
1689 0, symbol->n_numaux, main_aux);
1691 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1694 /* Support for line number handling */
1696 /* This function is called for every section; it finds the outer limits
1697 * of the line table (minimum and maximum file offset) so that the
1698 * mainline code can read the whole thing for efficiency.
1701 find_linenos (abfd, asect, vpinfo)
1706 struct coff_symfile_info *info;
1708 file_ptr offset, maxoff;
1710 count = asect->lineno_count;
1712 if (!STREQ (asect->name, ".text") || count == 0)
1715 size = count * coff_data (abfd)->local_linesz;
1716 info = (struct coff_symfile_info *)vpinfo;
1717 offset = asect->line_filepos;
1718 maxoff = offset + size;
1720 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1721 info->min_lineno_offset = offset;
1723 if (maxoff > info->max_lineno_offset)
1724 info->max_lineno_offset = maxoff;
1727 static void xcoff_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
1730 xcoff_psymtab_to_symtab_1 (pst)
1731 struct partial_symtab *pst;
1733 struct cleanup *old_chain;
1742 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1747 /* Read in all partial symtabs on which this one is dependent */
1748 for (i = 0; i < pst->number_of_dependencies; i++)
1749 if (!pst->dependencies[i]->readin)
1751 /* Inform about additional files that need to be read in. */
1754 fputs_filtered (" ", gdb_stdout);
1756 fputs_filtered ("and ", gdb_stdout);
1758 printf_filtered ("%s...", pst->dependencies[i]->filename);
1759 wrap_here (""); /* Flush output */
1760 gdb_flush (gdb_stdout);
1762 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1765 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0)
1767 /* Init stuff necessary for reading in symbols. */
1770 old_chain = make_cleanup (really_free_pendings, 0);
1772 read_xcoff_symtab (pst);
1773 sort_symtab_syms (pst->symtab);
1775 do_cleanups (old_chain);
1781 static void xcoff_psymtab_to_symtab PARAMS ((struct partial_symtab *));
1783 /* Read in all of the symbols for a given psymtab for real.
1784 Be verbose about it if the user wants that. */
1787 xcoff_psymtab_to_symtab (pst)
1788 struct partial_symtab *pst;
1798 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1803 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0
1804 || pst->number_of_dependencies)
1806 /* Print the message now, before reading the string table,
1807 to avoid disconcerting pauses. */
1810 printf_filtered ("Reading in symbols for %s...", pst->filename);
1811 gdb_flush (gdb_stdout);
1814 sym_bfd = pst->objfile->obfd;
1816 next_symbol_text_func = xcoff_next_symbol_text;
1818 xcoff_psymtab_to_symtab_1 (pst);
1820 /* Match with global symbols. This only needs to be done once,
1821 after all of the symtabs and dependencies have been read in. */
1822 scan_file_globals (pst->objfile);
1824 /* Finish up the debug error message. */
1826 printf_filtered ("done.\n");
1831 xcoff_new_init (objfile)
1832 struct objfile *objfile;
1834 stabsread_new_init ();
1835 buildsym_new_init ();
1838 /* Do initialization in preparation for reading symbols from OBJFILE.
1840 We will only be called if this is an XCOFF or XCOFF-like file.
1841 BFD handles figuring out the format of the file, and code in symfile.c
1842 uses BFD's determination to vector to us. */
1845 xcoff_symfile_init (objfile)
1846 struct objfile *objfile;
1848 /* Allocate struct to keep track of the symfile */
1849 objfile -> sym_private = xmmalloc (objfile -> md,
1850 sizeof (struct coff_symfile_info));
1852 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1853 find this causes a significant slowdown in gdb then we could
1854 set it in the debug symbol readers only when necessary. */
1855 objfile->flags |= OBJF_REORDERED;
1857 init_entry_point_info (objfile);
1860 /* Perform any local cleanups required when we are done with a particular
1861 objfile. I.E, we are in the process of discarding all symbol information
1862 for an objfile, freeing up all memory held for it, and unlinking the
1863 objfile struct from the global list of known objfiles. */
1866 xcoff_symfile_finish (objfile)
1867 struct objfile *objfile;
1869 if (objfile -> sym_private != NULL)
1871 mfree (objfile -> md, objfile -> sym_private);
1874 /* Start with a fresh include table for the next objfile. */
1880 inclIndx = inclLength = inclDepth = 0;
1885 init_stringtab (abfd, offset, objfile)
1888 struct objfile *objfile;
1892 unsigned char lengthbuf[4];
1895 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = NULL;
1897 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1898 error ("cannot seek to string table in %s: %s",
1899 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1901 val = bfd_read ((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1902 length = bfd_h_get_32 (abfd, lengthbuf);
1904 /* If no string table is needed, then the file may end immediately
1905 after the symbols. Just return with `strtbl' set to NULL. */
1907 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1910 /* Allocate string table from symbol_obstack. We will need this table
1911 as long as we have its symbol table around. */
1913 strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
1914 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = strtbl;
1916 /* Copy length buffer, the first byte is usually zero and is
1917 used for stabs with a name length of zero. */
1918 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1919 if (length == sizeof lengthbuf)
1922 val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf,
1925 if (val != length - sizeof lengthbuf)
1926 error ("cannot read string table from %s: %s",
1927 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1928 if (strtbl[length - 1] != '\0')
1929 error ("bad symbol file: string table does not end with null character");
1934 /* If we have not yet seen a function for this psymtab, this is 0. If we
1935 have seen one, it is the offset in the line numbers of the line numbers
1937 static unsigned int first_fun_line_offset;
1939 static struct partial_symtab *xcoff_start_psymtab
1940 PARAMS ((struct objfile *, struct section_offsets *, char *, int,
1941 struct partial_symbol **, struct partial_symbol **));
1943 /* Allocate and partially fill a partial symtab. It will be
1944 completely filled at the end of the symbol list.
1946 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1947 is the address relative to which its symbols are (incremental) or 0
1950 static struct partial_symtab *
1951 xcoff_start_psymtab (objfile, section_offsets,
1952 filename, first_symnum, global_syms, static_syms)
1953 struct objfile *objfile;
1954 struct section_offsets *section_offsets;
1957 struct partial_symbol **global_syms;
1958 struct partial_symbol **static_syms;
1960 struct partial_symtab *result =
1961 start_psymtab_common (objfile, section_offsets,
1963 /* We fill in textlow later. */
1965 global_syms, static_syms);
1967 result->read_symtab_private = (char *)
1968 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
1969 ((struct symloc *)result->read_symtab_private)->first_symnum = first_symnum;
1970 result->read_symtab = xcoff_psymtab_to_symtab;
1972 /* Deduce the source language from the filename for this psymtab. */
1973 psymtab_language = deduce_language_from_filename (filename);
1978 static struct partial_symtab *xcoff_end_psymtab
1979 PARAMS ((struct partial_symtab *, char **, int, int,
1980 struct partial_symtab **, int, int));
1982 /* Close off the current usage of PST.
1983 Returns PST, or NULL if the partial symtab was empty and thrown away.
1985 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
1987 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
1988 are the information for includes and dependencies. */
1990 static struct partial_symtab *
1991 xcoff_end_psymtab (pst, include_list, num_includes, capping_symbol_number,
1992 dependency_list, number_dependencies, textlow_not_set)
1993 struct partial_symtab *pst;
1994 char **include_list;
1996 int capping_symbol_number;
1997 struct partial_symtab **dependency_list;
1998 int number_dependencies;
1999 int textlow_not_set;
2002 struct objfile *objfile = pst -> objfile;
2004 if (capping_symbol_number != -1)
2005 ((struct symloc *)pst->read_symtab_private)->numsyms =
2006 capping_symbol_number
2007 - ((struct symloc *)pst->read_symtab_private)->first_symnum;
2008 ((struct symloc *)pst->read_symtab_private)->lineno_off =
2009 first_fun_line_offset;
2010 first_fun_line_offset = 0;
2011 pst->n_global_syms =
2012 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2013 pst->n_static_syms =
2014 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2016 pst->number_of_dependencies = number_dependencies;
2017 if (number_dependencies)
2019 pst->dependencies = (struct partial_symtab **)
2020 obstack_alloc (&objfile->psymbol_obstack,
2021 number_dependencies * sizeof (struct partial_symtab *));
2022 memcpy (pst->dependencies, dependency_list,
2023 number_dependencies * sizeof (struct partial_symtab *));
2026 pst->dependencies = 0;
2028 for (i = 0; i < num_includes; i++)
2030 struct partial_symtab *subpst =
2031 allocate_psymtab (include_list[i], objfile);
2033 subpst->section_offsets = pst->section_offsets;
2034 subpst->read_symtab_private =
2035 (char *) obstack_alloc (&objfile->psymbol_obstack,
2036 sizeof (struct symloc));
2037 ((struct symloc *)subpst->read_symtab_private)->first_symnum = 0;
2038 ((struct symloc *)subpst->read_symtab_private)->numsyms = 0;
2039 subpst->textlow = 0;
2040 subpst->texthigh = 0;
2042 /* We could save slight bits of space by only making one of these,
2043 shared by the entire set of include files. FIXME-someday. */
2044 subpst->dependencies = (struct partial_symtab **)
2045 obstack_alloc (&objfile->psymbol_obstack,
2046 sizeof (struct partial_symtab *));
2047 subpst->dependencies[0] = pst;
2048 subpst->number_of_dependencies = 1;
2050 subpst->globals_offset =
2051 subpst->n_global_syms =
2052 subpst->statics_offset =
2053 subpst->n_static_syms = 0;
2057 subpst->read_symtab = pst->read_symtab;
2060 sort_pst_symbols (pst);
2062 /* If there is already a psymtab or symtab for a file of this name,
2063 remove it. (If there is a symtab, more drastic things also
2064 happen.) This happens in VxWorks. */
2065 free_named_symtabs (pst->filename);
2067 if (num_includes == 0
2068 && number_dependencies == 0
2069 && pst->n_global_syms == 0
2070 && pst->n_static_syms == 0)
2072 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2073 it is on the obstack, but we can forget to chain it on the list. */
2074 /* Empty psymtabs happen as a result of header files which don't have
2075 any symbols in them. There can be a lot of them. */
2076 struct partial_symtab *prev_pst;
2078 /* First, snip it out of the psymtab chain */
2080 if (pst->objfile->psymtabs == pst)
2081 pst->objfile->psymtabs = pst->next;
2083 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
2084 if (prev_pst->next == pst)
2085 prev_pst->next = pst->next;
2087 /* Next, put it on a free list for recycling */
2089 pst->next = pst->objfile->free_psymtabs;
2090 pst->objfile->free_psymtabs = pst;
2092 /* Indicate that psymtab was thrown away. */
2093 pst = (struct partial_symtab *)NULL;
2098 static void swap_sym PARAMS ((struct internal_syment *,
2099 union internal_auxent *, char **, char **,
2103 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2104 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2105 the symbol and its auxents. */
2108 swap_sym (symbol, aux, name, raw, symnump, objfile)
2109 struct internal_syment *symbol;
2110 union internal_auxent *aux;
2113 unsigned int *symnump;
2114 struct objfile *objfile;
2116 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2117 if (symbol->n_zeroes)
2119 /* If it's exactly E_SYMNMLEN characters long it isn't
2121 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2123 /* FIXME: wastes memory for symbols which we don't end up putting
2124 into the minimal symbols. */
2126 p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2127 strncpy (p, symbol->n_name, E_SYMNMLEN);
2128 p[E_SYMNMLEN] = '\0';
2132 /* Point to the unswapped name as that persists as long as the
2134 *name = ((struct external_syment *)*raw)->e.e_name;
2136 else if (symbol->n_sclass & 0x80)
2138 *name = ((struct coff_symfile_info *)objfile->sym_private)->debugsec
2143 *name = ((struct coff_symfile_info *)objfile->sym_private)->strtbl
2147 *raw += coff_data (objfile->obfd)->local_symesz;
2148 if (symbol->n_numaux > 0)
2150 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2151 symbol->n_sclass, 0, symbol->n_numaux, aux);
2153 *symnump += symbol->n_numaux;
2154 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2159 scan_xcoff_symtab (section_offsets, objfile)
2160 struct section_offsets *section_offsets;
2161 struct objfile *objfile;
2163 int toc_offset = 0; /* toc offset value in data section. */
2164 char *filestring = NULL;
2167 int past_first_source_file = 0;
2171 /* Current partial symtab */
2172 struct partial_symtab *pst;
2174 /* List of current psymtab's include files */
2175 char **psymtab_include_list;
2176 int includes_allocated;
2179 /* Index within current psymtab dependency list */
2180 struct partial_symtab **dependency_list;
2181 int dependencies_used, dependencies_allocated;
2184 struct internal_syment symbol;
2185 union internal_auxent main_aux;
2186 unsigned int ssymnum;
2188 char *last_csect_name = NULL; /* last seen csect's name and value */
2189 CORE_ADDR last_csect_val = 0;
2190 int last_csect_sec = 0;
2191 int misc_func_recorded = 0; /* true if any misc. function */
2192 int textlow_not_set = 1;
2194 pst = (struct partial_symtab *) 0;
2196 includes_allocated = 30;
2198 psymtab_include_list = (char **) alloca (includes_allocated *
2201 dependencies_allocated = 30;
2202 dependencies_used = 0;
2204 (struct partial_symtab **) alloca (dependencies_allocated *
2205 sizeof (struct partial_symtab *));
2207 last_source_file = NULL;
2209 abfd = objfile->obfd;
2211 sraw_symbol = ((struct coff_symfile_info *)objfile->sym_private)->symtbl;
2212 nsyms = ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms;
2214 while (ssymnum < nsyms)
2216 int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0] & 0xff;
2217 /* This is the type we pass to partial-stab.h. A less kludgy solution
2218 would be to break out partial-stab.h into its various parts--shuffle
2219 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2220 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2230 /* The CSECT auxent--always the last auxent. */
2231 union internal_auxent csect_aux;
2232 unsigned int symnum_before = ssymnum;
2234 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2236 if (symbol.n_numaux > 1)
2238 bfd_coff_swap_aux_in
2240 sraw_symbol - coff_data(abfd)->local_symesz,
2243 symbol.n_numaux - 1,
2248 csect_aux = main_aux;
2250 /* If symbol name starts with ".$" or "$", ignore it. */
2251 if (namestring[0] == '$'
2252 || (namestring[0] == '.' && namestring[1] == '$'))
2255 switch (csect_aux.x_csect.x_smtyp & 0x7)
2258 switch (csect_aux.x_csect.x_smclas)
2261 if (last_csect_name)
2263 /* If no misc. function recorded in the last
2264 seen csect, enter it as a function. This
2265 will take care of functions like strcmp()
2268 if (!misc_func_recorded)
2270 RECORD_MINIMAL_SYMBOL
2271 (last_csect_name, last_csect_val,
2272 mst_text, last_csect_sec,
2278 /* We have to allocate one psymtab for
2279 each program csect, because their text
2280 sections need not be adjacent. */
2282 (pst, psymtab_include_list, includes_used,
2283 symnum_before, dependency_list,
2284 dependencies_used, textlow_not_set);
2286 dependencies_used = 0;
2287 /* Give all psymtabs for this source file the same
2289 pst = xcoff_start_psymtab
2290 (objfile, section_offsets,
2293 objfile->global_psymbols.next,
2294 objfile->static_psymbols.next);
2297 if (namestring && namestring[0] == '.')
2299 last_csect_name = namestring;
2300 last_csect_val = symbol.n_value;
2302 secnum_to_section (symbol.n_scnum, objfile);
2307 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2308 if (highval > pst->texthigh)
2309 pst->texthigh = highval;
2310 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2311 pst->textlow = symbol.n_value;
2313 misc_func_recorded = 0;
2317 /* Data variables are recorded in the minimal symbol
2318 table, except for section symbols. */
2319 if (*namestring != '.')
2320 prim_record_minimal_symbol_and_info
2321 (namestring, symbol.n_value,
2322 sclass == C_HIDEXT ? mst_file_data : mst_data,
2323 NULL, secnum_to_section (symbol.n_scnum, objfile),
2329 warning ("More than one XMC_TC0 symbol found.");
2330 toc_offset = symbol.n_value;
2334 /* These symbols tell us where the TOC entry for a
2335 variable is, not the variable itself. */
2344 switch (csect_aux.x_csect.x_smclas)
2347 /* A function entry point. */
2349 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2350 first_fun_line_offset =
2351 main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
2352 RECORD_MINIMAL_SYMBOL
2353 (namestring, symbol.n_value,
2354 sclass == C_HIDEXT ? mst_file_text : mst_text,
2355 secnum_to_section (symbol.n_scnum, objfile),
2360 /* shared library function trampoline code entry
2363 /* record trampoline code entries as
2364 mst_solib_trampoline symbol. When we lookup mst
2365 symbols, we will choose mst_text over
2366 mst_solib_trampoline. */
2367 RECORD_MINIMAL_SYMBOL
2368 (namestring, symbol.n_value,
2369 mst_solib_trampoline,
2370 secnum_to_section (symbol.n_scnum, objfile),
2375 /* The symbols often have the same names as
2376 debug symbols for functions, and confuse
2382 /* xlc puts each variable in a separate csect,
2383 so we get an XTY_SD for each variable. But
2384 gcc puts several variables in a csect, so
2385 that each variable only gets an XTY_LD. We
2386 still need to record them. This will
2387 typically be XMC_RW; I suspect XMC_RO and
2388 XMC_BS might be possible too. */
2389 if (*namestring != '.')
2390 prim_record_minimal_symbol_and_info
2391 (namestring, symbol.n_value,
2392 sclass == C_HIDEXT ? mst_file_data : mst_data,
2393 NULL, secnum_to_section (symbol.n_scnum, objfile),
2400 switch (csect_aux.x_csect.x_smclas)
2404 /* Common variables are recorded in the minimal symbol
2405 table, except for section symbols. */
2406 if (*namestring != '.')
2407 prim_record_minimal_symbol_and_info
2408 (namestring, symbol.n_value,
2409 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2410 NULL, secnum_to_section (symbol.n_scnum, objfile),
2423 unsigned int symnum_before;
2425 symnum_before = ssymnum;
2426 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2429 /* See if the last csect needs to be recorded. */
2431 if (last_csect_name && !misc_func_recorded)
2434 /* If no misc. function recorded in the last seen csect, enter
2435 it as a function. This will take care of functions like
2436 strcmp() compiled by xlc. */
2438 RECORD_MINIMAL_SYMBOL
2439 (last_csect_name, last_csect_val,
2440 mst_text, last_csect_sec, objfile);
2445 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2446 symnum_before, dependency_list,
2447 dependencies_used, textlow_not_set);
2449 dependencies_used = 0;
2451 first_fun_line_offset = 0;
2453 /* XCOFF, according to the AIX 3.2 documentation, puts the
2454 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2455 do things the standard COFF way and put it in the auxent.
2456 We use the auxent if the symbol is ".file" and an auxent
2457 exists, otherwise use the symbol itself. */
2458 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2460 filestring = coff_getfilename (&main_aux, objfile);
2463 filestring = namestring;
2465 pst = xcoff_start_psymtab (objfile, section_offsets,
2468 objfile->global_psymbols.next,
2469 objfile->static_psymbols.next);
2470 last_csect_name = NULL;
2476 static struct complaint msg =
2477 {"Storage class %d not recognized during scan", 0, 0};
2478 complain (&msg, sclass);
2482 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2483 to handle only the C_FUN and C_EXT. */
2498 /* C_EINCL means we are switching back to the main file. But there
2499 is no reason to care; the only thing we want to know about
2500 includes is the names of all the included (.h) files. */
2505 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2509 /* I don't think the name of the common block (as opposed to the
2510 variables within it) is something which is user visible
2518 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2519 so C_LSYM would appear to be only for locals. */
2525 /* We probably could save a few instructions by assuming that
2526 C_LSYM, C_PSYM, etc., never have auxents. */
2528 ((struct external_syment *)sraw_symbol)->e_numaux[0] + 1;
2530 sraw_symbol += sizeof (struct external_syment) * naux1;
2539 /* The value of the C_FUN is not the address of the function (it
2540 appears to be the address before linking), but as long as it
2541 is smaller than the actual address, then find_pc_partial_function
2542 will use the minimal symbols instead. I hope. */
2550 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2552 #define CUR_SYMBOL_TYPE stype
2553 #define CUR_SYMBOL_VALUE symbol.n_value
2555 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2556 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2558 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
2559 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2561 /* We have already set the namestring. */
2562 #define SET_NAMESTRING() /* */
2564 #include "partial-stab.h"
2570 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2571 ssymnum, dependency_list,
2572 dependencies_used, textlow_not_set);
2575 /* Record the toc offset value of this symbol table into ldinfo structure.
2576 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2577 this information would be file auxiliary header. */
2579 if (xcoff_add_toc_to_loadinfo_hook != NULL)
2580 (*xcoff_add_toc_to_loadinfo_hook) ((unsigned long) toc_offset);
2583 /* Scan and build partial symbols for a symbol file.
2584 We have been initialized by a call to dbx_symfile_init, which
2585 put all the relevant info into a "struct dbx_symfile_info",
2586 hung off the objfile structure.
2588 SECTION_OFFSETS contains offsets relative to which the symbols in the
2589 various sections are (depending where the sections were actually loaded).
2590 MAINLINE is true if we are reading the main symbol
2591 table (as opposed to a shared lib or dynamically loaded file). */
2594 xcoff_initial_scan (objfile, section_offsets, mainline)
2595 struct objfile *objfile;
2596 struct section_offsets *section_offsets;
2597 int mainline; /* FIXME comments above */
2601 struct cleanup *back_to;
2602 int num_symbols; /* # of symbols */
2603 file_ptr symtab_offset; /* symbol table and */
2604 file_ptr stringtab_offset; /* string table file offsets */
2605 struct coff_symfile_info *info;
2609 /* Initialize load info structure. */
2610 if (mainline && xcoff_init_loadinfo_hook != NULL)
2611 (*xcoff_init_loadinfo_hook) ();
2613 info = (struct coff_symfile_info *) objfile -> sym_private;
2614 symfile_bfd = abfd = objfile->obfd;
2615 name = objfile->name;
2617 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2618 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2619 stringtab_offset = symtab_offset +
2620 num_symbols * coff_data(abfd)->local_symesz;
2622 info->min_lineno_offset = 0;
2623 info->max_lineno_offset = 0;
2624 bfd_map_over_sections (abfd, find_linenos, info);
2626 if (num_symbols > 0)
2628 /* Read the string table. */
2629 init_stringtab (abfd, stringtab_offset, objfile);
2631 /* Read the .debug section, if present. */
2634 bfd_size_type length;
2635 char *debugsec = NULL;
2637 secp = bfd_get_section_by_name (abfd, ".debug");
2640 length = bfd_section_size (abfd, secp);
2644 (char *) obstack_alloc (&objfile->symbol_obstack, length);
2646 if (!bfd_get_section_contents (abfd, secp, debugsec,
2647 (file_ptr) 0, length))
2649 error ("Error reading .debug section of `%s': %s",
2650 name, bfd_errmsg (bfd_get_error ()));
2654 ((struct coff_symfile_info *)objfile->sym_private)->debugsec =
2659 /* Read the symbols. We keep them in core because we will want to
2660 access them randomly in read_symbol*. */
2661 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2663 error ("Error reading symbols from %s: %s",
2664 name, bfd_errmsg (bfd_get_error ()));
2665 size = coff_data (abfd)->local_symesz * num_symbols;
2666 ((struct coff_symfile_info *)objfile->sym_private)->symtbl =
2667 obstack_alloc (&objfile->symbol_obstack, size);
2668 ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms =
2671 val = bfd_read (((struct coff_symfile_info *)objfile->sym_private)->symtbl,
2674 perror_with_name ("reading symbol table");
2676 /* If we are reinitializing, or if we have never loaded syms yet, init */
2678 || objfile->global_psymbols.size == 0
2679 || objfile->static_psymbols.size == 0)
2680 /* I'm not sure how how good num_symbols is; the rule of thumb in
2681 init_psymbol_list was developed for a.out. On the one hand,
2682 num_symbols includes auxents. On the other hand, it doesn't
2684 init_psymbol_list (objfile, num_symbols);
2687 back_to = make_cleanup (really_free_pendings, 0);
2689 init_minimal_symbol_collection ();
2690 make_cleanup (discard_minimal_symbols, 0);
2692 /* Now that the symbol table data of the executable file are all in core,
2693 process them and define symbols accordingly. */
2695 scan_xcoff_symtab (section_offsets, objfile);
2697 /* Install any minimal symbols that have been collected as the current
2698 minimal symbols for this objfile. */
2700 install_minimal_symbols (objfile);
2702 do_cleanups (back_to);
2705 static struct section_offsets *
2706 xcoff_symfile_offsets (objfile, addr)
2707 struct objfile *objfile;
2710 struct section_offsets *section_offsets;
2713 objfile->num_sections = SECT_OFF_MAX;
2714 section_offsets = (struct section_offsets *)
2716 (&objfile -> psymbol_obstack,
2717 sizeof (struct section_offsets)
2718 + sizeof (section_offsets->offsets) * objfile->num_sections);
2720 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2721 of the .text section. This strikes me as wrong--whether the
2722 offset to be applied to symbol reading is relative to the start
2723 address of the section depends on the symbol format. In any
2724 event, this whole "addr" concept is pretty broken (it doesn't
2725 handle any section but .text sensibly), so just ignore the addr
2726 parameter and use 0. rs6000-nat.c will set the correct section
2727 offsets via objfile_relocate. */
2728 for (i = 0; i < objfile->num_sections; ++i)
2729 ANOFFSET (section_offsets, i) = 0;
2731 return section_offsets;
2734 /* Register our ability to parse symbols for xcoff BFD files. */
2736 static struct sym_fns xcoff_sym_fns =
2739 /* Because the bfd uses coff_flavour, we need to specially kludge
2740 the flavour. It is possible that coff and xcoff should be merged as
2741 they do have fundamental similarities (for example, the extra storage
2742 classes used for stabs could presumably be recognized in any COFF file).
2743 However, in addition to obvious things like all the csect hair, there are
2744 some subtler differences between xcoffread.c and coffread.c, notably
2745 the fact that coffread.c has no need to read in all the symbols, but
2746 xcoffread.c reads all the symbols and does in fact randomly access them
2747 (in C_BSTAT and line number processing). */
2749 (enum bfd_flavour)-1,
2751 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2752 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2753 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
2754 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2755 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
2756 NULL /* next: pointer to next struct sym_fns */
2760 _initialize_xcoffread ()
2762 add_symtab_fns(&xcoff_sym_fns);
2764 func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
2765 "<function, no debug info>", NULL);
2766 TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
2768 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
2769 "<variable, no debug info>", NULL);