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 xcoff_initial_scan PARAMS ((struct objfile *, struct section_offsets *, int));
206 scan_xcoff_symtab PARAMS ((struct section_offsets *, struct objfile *));
209 xcoff_next_symbol_text PARAMS ((struct objfile *));
212 record_include_begin PARAMS ((struct coff_symbol *));
215 enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
216 CORE_ADDR, CORE_ADDR, unsigned *));
219 init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));
222 xcoff_symfile_init PARAMS ((struct objfile *));
225 xcoff_new_init PARAMS ((struct objfile *));
228 xcoff_symfile_finish PARAMS ((struct objfile *));
230 static struct section_offsets *
231 xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
234 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
237 coff_getfilename PARAMS ((union internal_auxent *, struct objfile *));
240 read_symbol PARAMS ((struct internal_syment *, int));
243 read_symbol_lineno PARAMS ((int));
246 read_symbol_nvalue PARAMS ((int));
248 static struct symbol *
249 process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
252 read_xcoff_symtab PARAMS ((struct partial_symtab *));
256 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
260 compare_lte PARAMS ((const void *, const void *));
262 static struct linetable *
263 arrange_linetable PARAMS ((struct linetable *));
266 record_include_end PARAMS ((struct coff_symbol *));
269 process_linenos PARAMS ((CORE_ADDR, CORE_ADDR));
272 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
274 static int secnum_to_section PARAMS ((int, struct objfile *));
276 struct find_targ_sec_arg {
281 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
283 static void find_targ_sec (abfd, sect, obj)
288 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
289 if (sect->target_index == args->targ_index)
291 /* This is the section. Figure out what SECT_OFF_* code it is. */
292 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
293 *args->resultp = SECT_OFF_TEXT;
294 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
295 *args->resultp = SECT_OFF_DATA;
297 *args->resultp = SECT_OFF_BSS;
301 /* Return the section number (SECT_OFF_*) that CS points to. */
303 secnum_to_section (secnum, objfile)
305 struct objfile *objfile;
307 int off = SECT_OFF_TEXT;
308 struct find_targ_sec_arg args;
309 args.targ_index = secnum;
311 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
315 /* add a given stab string into given stab vector. */
320 add_stab_to_list (stabname, stabvector)
322 struct pending_stabs **stabvector;
324 if ( *stabvector == NULL) {
325 *stabvector = (struct pending_stabs *)
326 xmalloc (sizeof (struct pending_stabs) +
327 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
328 (*stabvector)->count = 0;
329 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
331 else if ((*stabvector)->count >= (*stabvector)->length) {
332 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
333 *stabvector = (struct pending_stabs *)
334 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
335 (*stabvector)->length * sizeof (char*));
337 (*stabvector)->stab [(*stabvector)->count++] = stabname;
343 /* Linenos are processed on a file-by-file basis.
347 1) xlc (IBM's native c compiler) postpones static function code
348 emission to the end of a compilation unit. This way it can
349 determine if those functions (statics) are needed or not, and
350 can do some garbage collection (I think). This makes line
351 numbers and corresponding addresses unordered, and we end up
352 with a line table like:
369 and that breaks gdb's binary search on line numbers, if the
370 above table is not sorted on line numbers. And that sort
371 should be on function based, since gcc can emit line numbers
374 10 0x100 - for the init/test part of a for stmt.
377 10 0x400 - for the increment part of a for stmt.
379 arrange_linetable() will do this sorting.
381 2) aix symbol table might look like:
383 c_file // beginning of a new file
384 .bi // beginning of include file
385 .ei // end of include file
389 basically, .bi/.ei pairs do not necessarily encapsulate
390 their scope. They need to be recorded, and processed later
391 on when we come the end of the compilation unit.
392 Include table (inclTable) and process_linenos() handle
395 /* compare line table entry addresses. */
398 compare_lte (lte1p, lte2p)
402 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
403 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
404 return lte1->pc - lte2->pc;
407 /* Given a line table with function entries are marked, arrange its functions
408 in ascending order and strip off function entry markers and return it in
409 a newly created table. If the old one is good enough, return the old one. */
410 /* FIXME: I think all this stuff can be replaced by just passing
411 sort_linevec = 1 to end_symtab. */
413 static struct linetable *
414 arrange_linetable (oldLineTb)
415 struct linetable *oldLineTb; /* old linetable */
418 newline, /* new line count */
419 function_count; /* # of functions */
421 struct linetable_entry *fentry; /* function entry vector */
422 int fentry_size; /* # of function entries */
423 struct linetable *newLineTb; /* new line table */
425 #define NUM_OF_FUNCTIONS 20
427 fentry_size = NUM_OF_FUNCTIONS;
428 fentry = (struct linetable_entry*)
429 xmalloc (fentry_size * sizeof (struct linetable_entry));
431 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
433 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
435 if (function_count >= fentry_size) { /* make sure you have room. */
437 fentry = (struct linetable_entry*)
438 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
440 fentry[function_count].line = ii;
441 fentry[function_count].pc = oldLineTb->item[ii].pc;
446 if (function_count == 0) {
450 else if (function_count > 1)
451 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
453 /* allocate a new line table. */
454 newLineTb = (struct linetable *)
456 (sizeof (struct linetable) +
457 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
459 /* if line table does not start with a function beginning, copy up until
463 if (oldLineTb->item[0].line != 0)
465 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
466 newLineTb->item[newline] = oldLineTb->item[newline];
468 /* Now copy function lines one by one. */
470 for (ii=0; ii < function_count; ++ii) {
471 for (jj = fentry[ii].line + 1;
472 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
474 newLineTb->item[newline] = oldLineTb->item[jj];
477 newLineTb->nitems = oldLineTb->nitems - function_count;
481 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
482 following `IncludeChain'. At the end of each symtab (end_symtab),
483 we will determine if we should create additional symtab's to
484 represent if (the include files. */
487 typedef struct _inclTable {
488 char *name; /* include filename */
490 /* Offsets to the line table. end points to the last entry which is
491 part of this include file. */
494 struct subfile *subfile;
495 unsigned funStartLine; /* start line # of its function */
498 #define INITIAL_INCLUDE_TABLE_LENGTH 20
499 static InclTable *inclTable; /* global include table */
500 static int inclIndx; /* last entry to table */
501 static int inclLength; /* table length */
502 static int inclDepth; /* nested include depth */
504 static void allocate_include_entry PARAMS ((void));
507 record_include_begin (cs)
508 struct coff_symbol *cs;
512 /* In xcoff, we assume include files cannot be nested (not in .c files
513 of course, but in corresponding .s files.). */
515 /* This can happen with old versions of GCC.
516 GCC 2.3.3-930426 does not exhibit this on a test case which
517 a user said produced the message for him. */
518 static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
523 allocate_include_entry ();
525 inclTable [inclIndx].name = cs->c_name;
526 inclTable [inclIndx].begin = cs->c_value;
530 record_include_end (cs)
531 struct coff_symbol *cs;
537 static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
541 allocate_include_entry ();
543 pTbl = &inclTable [inclIndx];
544 pTbl->end = cs->c_value;
551 allocate_include_entry ()
553 if (inclTable == NULL)
555 inclTable = (InclTable *)
556 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
558 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
559 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
562 else if (inclIndx >= inclLength)
564 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
565 inclTable = (InclTable *)
566 xrealloc (inclTable, sizeof (InclTable) * inclLength);
567 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
568 '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
572 /* Global variable to pass the psymtab down to all the routines involved
573 in psymtab to symtab processing. */
574 static struct partial_symtab *this_symtab_psymtab;
576 /* given the start and end addresses of a compilation unit (or a csect,
577 at times) process its lines and create appropriate line vectors. */
580 process_linenos (start, end)
581 CORE_ADDR start, end;
584 file_ptr max_offset =
585 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
588 /* subfile structure for the main compilation unit. */
589 struct subfile main_subfile;
591 /* In the main source file, any time we see a function entry, we
592 reset this variable to function's absolute starting line number.
593 All the following line numbers in the function are relative to
594 this, and we record absolute line numbers in record_line(). */
596 unsigned int main_source_baseline = 0;
601 ((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off;
603 goto return_after_cleanup;
605 memset (&main_subfile, '\0', sizeof (main_subfile));
608 /* All source lines were in the main source file. None in include files. */
610 enter_line_range (&main_subfile, offset, 0, start, end,
611 &main_source_baseline);
615 /* There was source with line numbers in include files. */
616 main_source_baseline = 0;
617 for (ii=0; ii < inclIndx; ++ii)
619 struct subfile *tmpSubfile;
621 /* If there is main file source before include file, enter it. */
622 if (offset < inclTable[ii].begin)
625 (&main_subfile, offset, inclTable[ii].begin - LINESZ,
626 start, 0, &main_source_baseline);
629 /* Have a new subfile for the include file. */
631 tmpSubfile = inclTable[ii].subfile =
632 (struct subfile *) xmalloc (sizeof (struct subfile));
634 memset (tmpSubfile, '\0', sizeof (struct subfile));
635 firstLine = &(inclTable[ii].funStartLine);
637 /* Enter include file's lines now. */
638 enter_line_range (tmpSubfile, inclTable[ii].begin,
639 inclTable[ii].end, start, 0, firstLine);
641 if (offset <= inclTable[ii].end)
642 offset = inclTable[ii].end + LINESZ;
645 /* All the include files' line have been processed at this point. Now,
646 enter remaining lines of the main file, if any left. */
647 if (offset < max_offset + 1 - LINESZ)
649 enter_line_range (&main_subfile, offset, 0, start, end,
650 &main_source_baseline);
654 /* Process main file's line numbers. */
655 if (main_subfile.line_vector)
657 struct linetable *lineTb, *lv;
659 lv = main_subfile.line_vector;
661 /* Line numbers are not necessarily ordered. xlc compilation will
662 put static function to the end. */
664 lineTb = arrange_linetable (lv);
667 current_subfile->line_vector = (struct linetable *)
668 xrealloc (lv, (sizeof (struct linetable)
669 + lv->nitems * sizeof (struct linetable_entry)));
674 current_subfile->line_vector = lineTb;
677 current_subfile->line_vector_length =
678 current_subfile->line_vector->nitems;
681 /* Now, process included files' line numbers. */
683 for (ii=0; ii < inclIndx; ++ii)
685 if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */
687 struct linetable *lineTb, *lv;
689 lv = (inclTable[ii].subfile)->line_vector;
691 /* Line numbers are not necessarily ordered. xlc compilation will
692 put static function to the end. */
694 lineTb = arrange_linetable (lv);
698 /* For the same include file, we might want to have more than one
699 subfile. This happens if we have something like:
707 while foo.h including code in it. (stupid but possible)
708 Since start_subfile() looks at the name and uses an
709 existing one if finds, we need to provide a fake name and
713 start_subfile (inclTable[ii].name, (char*)0);
716 /* Pick a fake name that will produce the same results as this
717 one when passed to deduce_language_from_filename. Kludge on
719 char *fakename = strrchr (inclTable[ii].name, '.');
720 if (fakename == NULL)
722 start_subfile (fakename, (char*)0);
723 free (current_subfile->name);
725 current_subfile->name = strdup (inclTable[ii].name);
730 current_subfile->line_vector =
731 (struct linetable *) xrealloc
732 (lv, (sizeof (struct linetable)
733 + lv->nitems * sizeof (struct linetable_entry)));
739 current_subfile->line_vector = lineTb;
742 current_subfile->line_vector_length =
743 current_subfile->line_vector->nitems;
744 start_subfile (pop_subfile (), (char*)0);
748 return_after_cleanup:
750 /* We don't want to keep alloc/free'ing the global include file table. */
753 /* Start with a fresh subfile structure for the next file. */
754 memset (&main_subfile, '\0', sizeof (struct subfile));
758 aix_process_linenos ()
760 /* process line numbers and enter them into line vector */
761 process_linenos (last_source_start_addr, cur_src_end_addr);
765 /* Enter a given range of lines into the line vector.
766 can be called in the following two ways:
767 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
768 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
770 endoffset points to the last line table entry that we should pay
774 enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr,
776 struct subfile *subfile;
777 unsigned beginoffset, endoffset; /* offsets to line table */
778 CORE_ADDR startaddr, endaddr;
781 unsigned int curoffset;
783 struct external_lineno ext_lnno;
784 struct internal_lineno int_lnno;
785 unsigned int limit_offset;
788 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
790 curoffset = beginoffset;
792 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
797 if (endoffset >= limit_offset)
799 static struct complaint msg =
800 {"Bad line table offset in C_EINCL directive", 0, 0};
804 limit_offset = endoffset;
808 abfd = this_symtab_psymtab->objfile->obfd;
810 while (curoffset <= limit_offset)
812 bfd_seek (abfd, curoffset, SEEK_SET);
813 bfd_read (&ext_lnno, sizeof (struct external_lineno), 1, abfd);
814 bfd_coff_swap_lineno_in (abfd, &ext_lnno, &int_lnno);
816 /* Find the address this line represents. */
817 addr = (int_lnno.l_lnno
818 ? int_lnno.l_addr.l_paddr
819 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
820 addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
823 if (addr < startaddr || (endaddr && addr >= endaddr))
826 if (int_lnno.l_lnno == 0)
828 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
829 record_line (subfile, 0, addr);
833 record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
839 /* Save the vital information for use when closing off the current file.
840 NAME is the file name the symbols came from, START_ADDR is the first
841 text address for the file, and SIZE is the number of bytes of text. */
843 #define complete_symtab(name, start_addr) { \
844 last_source_file = savestring (name, strlen (name)); \
845 last_source_start_addr = start_addr; \
849 /* Refill the symbol table input buffer
850 and set the variables that control fetching entries from it.
851 Reports an error if no data available.
852 This function can read past the end of the symbol table
853 (into the string table) but this does no harm. */
855 /* Reading symbol table has to be fast! Keep the followings as macros, rather
858 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
862 if (namestr[0] == '.') ++namestr; \
863 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
864 (char *)NULL, (SECTION), (OBJFILE)); \
865 misc_func_recorded = 1; \
869 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
870 nested. At any given time, a symbol can only be in one static block.
871 This is the base address of current static block, zero if non exists. */
873 static int static_block_base = 0;
875 /* Section number for the current static block. */
877 static int static_block_section = -1;
879 /* true if space for symbol name has been allocated. */
881 static int symname_alloced = 0;
883 /* Next symbol to read. Pointer into raw seething symbol table. */
885 static char *raw_symbol;
887 /* This is the function which stabsread.c calls to get symbol
891 xcoff_next_symbol_text (objfile)
892 struct objfile *objfile;
894 struct internal_syment symbol;
895 static struct complaint msg =
896 {"Unexpected symbol continuation", 0, 0};
898 /* FIXME: is this the same as the passed arg? */
899 objfile = this_symtab_psymtab->objfile;
901 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
906 /* Return something which points to '\0' and hope the symbol reading
907 code does something reasonable. */
910 else if (symbol.n_sclass & 0x80)
913 ((struct coff_symfile_info *)objfile->sym_private)->debugsec
916 coff_data (objfile->obfd)->local_symesz;
923 /* Return something which points to '\0' and hope the symbol reading
924 code does something reasonable. */
930 /* Read symbols for a given partial symbol table. */
933 read_xcoff_symtab (pst)
934 struct partial_symtab *pst;
936 struct objfile *objfile = pst->objfile;
937 bfd *abfd = objfile->obfd;
938 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
939 char *strtbl = ((struct coff_symfile_info *)objfile->sym_private)->strtbl;
941 ((struct coff_symfile_info *)objfile->sym_private)->debugsec;
943 struct internal_syment symbol[1];
944 union internal_auxent main_aux;
945 struct coff_symbol cs[1];
946 CORE_ADDR file_start_addr = 0;
947 CORE_ADDR file_end_addr = 0;
949 int next_file_symnum = -1;
950 unsigned int max_symnum;
951 int just_started = 1;
953 int fcn_start_addr = 0;
955 struct coff_symbol fcn_stab_saved;
957 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
958 union internal_auxent fcn_aux_saved;
959 struct context_stack *new;
961 char *filestring = " _start_ "; /* Name of the current file. */
963 char *last_csect_name; /* last seen csect's name and value */
964 CORE_ADDR last_csect_val;
967 this_symtab_psymtab = pst;
969 /* Get the appropriate COFF "constants" related to the file we're
971 local_symesz = coff_data (abfd)->local_symesz;
973 last_source_file = NULL;
978 start_symtab (filestring, (char *)NULL, file_start_addr);
979 symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum;
981 symnum + ((struct symloc *)pst->read_symtab_private)->numsyms;
982 first_object_file_end = 0;
985 ((struct coff_symfile_info *) objfile->sym_private)->symtbl
986 + symnum * local_symesz;
988 while (symnum < max_symnum)
991 QUIT; /* make this command interruptable. */
993 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
994 /* read one symbol into `cs' structure. After processing the
995 whole symbol table, only string table will be kept in memory,
996 symbol table and debug section of xcoff will be freed. Thus
997 we can mark symbols with names in string table as
1002 /* Swap and align the symbol into a reasonable C structure. */
1003 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1005 cs->c_symnum = symnum;
1006 cs->c_naux = symbol->n_numaux;
1007 if (symbol->n_zeroes)
1009 symname_alloced = 0;
1010 /* We must use the original, unswapped, name here so the name field
1011 pointed to by cs->c_name will persist throughout xcoffread. If
1012 we use the new field, it gets overwritten for each symbol. */
1013 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
1014 /* If it's exactly E_SYMNMLEN characters long it isn't
1016 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1019 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1020 strncpy (p, cs->c_name, E_SYMNMLEN);
1021 p[E_SYMNMLEN] = '\0';
1023 symname_alloced = 1;
1026 else if (symbol->n_sclass & 0x80)
1028 cs->c_name = debugsec + symbol->n_offset;
1029 symname_alloced = 0;
1033 /* in string table */
1034 cs->c_name = strtbl + (int)symbol->n_offset;
1035 symname_alloced = 1;
1037 cs->c_value = symbol->n_value;
1038 cs->c_sclass = symbol->n_sclass;
1039 cs->c_secnum = symbol->n_scnum;
1040 cs->c_type = (unsigned)symbol->n_type;
1042 raw_symbol += coff_data (abfd)->local_symesz;
1045 /* Save addr of first aux entry. */
1046 raw_auxptr = raw_symbol;
1048 /* Skip all the auxents associated with this symbol. */
1049 for (ii = symbol->n_numaux; ii; --ii)
1051 raw_symbol += coff_data (abfd)->local_auxesz;
1056 /* if symbol name starts with ".$" or "$", ignore it. */
1057 if (cs->c_name[0] == '$'
1058 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1061 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1063 if (last_source_file)
1066 end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT);
1071 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
1072 cur_src_end_addr = first_object_file_end;
1073 /* done with all files, everything from here on is globals */
1076 /* if explicitly specified as a function, treat is as one. */
1077 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF)
1079 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1080 0, cs->c_naux, &main_aux);
1081 goto function_entry_point;
1084 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1087 /* Dealing with a symbol with a csect entry. */
1089 #define CSECT(PP) ((PP)->x_csect)
1090 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1091 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1092 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1093 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1095 /* Convert the auxent to something we can access. */
1096 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1097 0, cs->c_naux, &main_aux);
1099 switch (CSECT_SMTYP (&main_aux))
1103 /* Ignore all external references. */
1107 /* A section description. */
1109 switch (CSECT_SCLAS (&main_aux))
1115 /* A program csect is seen. We have to allocate one
1116 symbol table for each program csect. Normally gdb
1117 prefers one symtab for each source file. In case
1118 of AIX, one source file might include more than one
1119 [PR] csect, and they don't have to be adjacent in
1120 terms of the space they occupy in memory. Thus, one
1121 single source file might get fragmented in the
1122 memory and gdb's file start and end address
1123 approach does not work! GCC (and I think xlc) seem
1124 to put all the code in the unnamed program csect. */
1126 if (last_csect_name)
1128 complete_symtab (filestring, file_start_addr);
1129 cur_src_end_addr = file_end_addr;
1130 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
1133 /* Give all csects for this source file the same
1135 start_symtab (filestring, NULL, (CORE_ADDR)0);
1138 /* If this is the very first csect seen,
1139 basically `__start'. */
1142 first_object_file_end
1143 = cs->c_value + CSECT_LEN (&main_aux);
1148 cs->c_value + ANOFFSET (objfile->section_offsets,
1150 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1152 if (cs->c_name && cs->c_name[0] == '.')
1154 last_csect_name = cs->c_name;
1155 last_csect_val = cs->c_value;
1156 last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
1161 /* All other symbols are put into the minimal symbol
1174 /* Ignore the symbol. */
1182 switch (CSECT_SCLAS (&main_aux))
1185 /* a function entry point. */
1186 function_entry_point:
1188 fcn_start_addr = cs->c_value;
1190 /* save the function header info, which will be used
1191 when `.bf' is seen. */
1193 fcn_aux_saved = main_aux;
1197 /* shared library function trampoline code entry point. */
1201 /* The symbols often have the same names as debug symbols for
1202 functions, and confuse lookup_symbol. */
1206 /* xlc puts each variable in a separate csect, so we get
1207 an XTY_SD for each variable. But gcc puts several
1208 variables in a csect, so that each variable only gets
1209 an XTY_LD. This will typically be XMC_RW; I suspect
1210 XMC_RO and XMC_BS might be possible too.
1211 These variables are put in the minimal symbol table
1218 /* Common symbols are put into the minimal symbol table only. */
1226 switch (cs->c_sclass)
1231 /* c_value field contains symnum of next .file entry in table
1232 or symnum of first global after last .file. */
1234 next_file_symnum = cs->c_value;
1236 /* Complete symbol table for last object file containing
1237 debugging information. */
1239 /* Whether or not there was a csect in the previous file, we
1240 have to call `end_stabs' and `start_stabs' to reset
1241 type_vector, line_vector, etc. structures. */
1243 complete_symtab (filestring, file_start_addr);
1244 cur_src_end_addr = file_end_addr;
1245 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
1248 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1249 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1250 standard COFF way and put it in the auxent. We use the auxent if
1251 the symbol is ".file" and an auxent exists, otherwise use the symbol
1252 itself. Simple enough. */
1253 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1255 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1256 0, cs->c_naux, &main_aux);
1257 filestring = coff_getfilename (&main_aux, objfile);
1260 filestring = cs->c_name;
1263 start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
1264 last_csect_name = 0;
1266 /* reset file start and end addresses. A compilation unit with no text
1267 (only data) should have zero file boundaries. */
1268 file_start_addr = file_end_addr = 0;
1272 fcn_stab_saved = *cs;
1276 if (STREQ (cs->c_name, ".bf"))
1278 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1280 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1281 0, cs->c_naux, &main_aux);
1283 within_function = 1;
1285 new = push_context (0, fcn_start_addr + off);
1287 new->name = define_symbol
1288 (fcn_cs_saved.c_value + off,
1289 fcn_stab_saved.c_name, 0, 0, objfile);
1290 if (new->name != NULL)
1291 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT;
1293 else if (STREQ (cs->c_name, ".ef"))
1296 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1297 0, cs->c_naux, &main_aux);
1299 /* The value of .ef is the address of epilogue code;
1300 not useful for gdb. */
1301 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1302 contains number of lines to '}' */
1304 if (context_stack_depth <= 0)
1305 { /* We attempted to pop an empty context stack */
1306 complain (&ef_complaint, cs->c_symnum);
1307 within_function = 0;
1310 new = pop_context ();
1311 /* Stack must be empty now. */
1312 if (context_stack_depth > 0 || new == NULL)
1314 complain (&ef_complaint, cs->c_symnum);
1315 within_function = 0;
1319 finish_block (new->name, &local_symbols, new->old_blocks,
1321 (fcn_cs_saved.c_value
1322 + fcn_aux_saved.x_sym.x_misc.x_fsize
1323 + ANOFFSET (objfile->section_offsets,
1326 within_function = 0;
1331 /* Begin static block. */
1333 struct internal_syment symbol;
1335 read_symbol (&symbol, cs->c_value);
1336 static_block_base = symbol.n_value;
1337 static_block_section =
1338 secnum_to_section (symbol.n_scnum, objfile);
1343 /* End of static block. */
1344 static_block_base = 0;
1345 static_block_section = -1;
1356 static struct complaint msg =
1357 {"Unrecognized storage class %d.", 0, 0};
1358 complain (&msg, cs->c_sclass);
1372 /* beginning of include file */
1373 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1374 order. Thus, when wee see them, we might not know enough info
1375 to process them. Thus, we'll be saving them into a table
1376 (inclTable) and postpone their processing. */
1378 record_include_begin (cs);
1382 /* End of include file. */
1383 /* See the comment after case C_BINCL. */
1384 record_include_end (cs);
1388 if (STREQ (cs->c_name, ".bb"))
1391 new = push_context (depth,
1393 + ANOFFSET (objfile->section_offsets,
1396 else if (STREQ (cs->c_name, ".eb"))
1398 if (context_stack_depth <= 0)
1399 { /* We attempted to pop an empty context stack */
1400 complain (&eb_complaint, cs->c_symnum);
1403 new = pop_context ();
1404 if (depth-- != new->depth)
1406 complain (&eb_complaint, cs->c_symnum);
1409 if (local_symbols && context_stack_depth > 0)
1411 /* Make a block for the local symbols within. */
1412 finish_block (new->name, &local_symbols, new->old_blocks,
1415 + ANOFFSET (objfile->section_offsets,
1419 local_symbols = new->locals;
1424 process_xcoff_symbol (cs, objfile);
1429 if (last_source_file)
1433 complete_symtab (filestring, file_start_addr);
1434 cur_src_end_addr = file_end_addr;
1435 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT);
1436 /* When reading symbols for the last C_FILE of the objfile, try
1437 to make sure that we set pst->symtab to the symtab for the
1438 file, not to the _globals_ symtab. I'm not sure whether this
1439 actually works right or when/if it comes up. */
1440 if (pst->symtab == NULL)
1446 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1447 (SYMBOL2) = (struct symbol *) \
1448 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1449 *(SYMBOL2) = *(SYMBOL1);
1452 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1453 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1456 static struct type *func_symbol_type;
1457 static struct type *var_symbol_type;
1459 /* process one xcoff symbol. */
1461 static struct symbol *
1462 process_xcoff_symbol (cs, objfile)
1463 register struct coff_symbol *cs;
1464 struct objfile *objfile;
1466 struct symbol onesymbol;
1467 register struct symbol *sym = &onesymbol;
1468 struct symbol *sym2 = NULL;
1474 if (cs->c_secnum < 0)
1476 /* The value is a register number, offset within a frame, etc.,
1477 and does not get relocated. */
1483 sec = secnum_to_section (cs->c_secnum, objfile);
1484 off = ANOFFSET (objfile->section_offsets, sec);
1491 memset (sym, '\0', sizeof (struct symbol));
1493 /* default assumptions */
1494 SYMBOL_VALUE (sym) = cs->c_value + off;
1495 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1496 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1498 if (ISFCN (cs->c_type))
1500 /* At this point, we don't know the type of the function. This
1501 will be patched with the type from its stab entry later on in
1502 patch_block_stabs (), unless the file was compiled without -g. */
1504 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1505 SYMBOL_TYPE (sym) = func_symbol_type;
1507 SYMBOL_CLASS (sym) = LOC_BLOCK;
1508 SYMBOL_DUP (sym, sym2);
1510 if (cs->c_sclass == C_EXT)
1511 add_symbol_to_list (sym2, &global_symbols);
1512 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1513 add_symbol_to_list (sym2, &file_symbols);
1517 /* In case we can't figure out the type, provide default. */
1518 SYMBOL_TYPE (sym) = var_symbol_type;
1520 switch (cs->c_sclass)
1523 /* The values of functions and global symbols are now resolved
1524 via the global_sym_chain in stabsread.c. */
1526 if (fcn_cs_saved.c_sclass == C_EXT)
1527 add_stab_to_list (name, &global_stabs);
1529 add_stab_to_list (name, &file_stabs);
1533 add_stab_to_list (name, &global_stabs);
1538 common_block_start (cs->c_name, objfile);
1542 common_block_end (objfile);
1546 complain (&storclass_complaint, cs->c_sclass);
1558 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1561 SYMBOL_SECTION (sym) = sec;
1568 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1569 all statics and we need to distinguish file-scope versus
1570 function-scope using within_function. We do this by
1571 changing the string we pass to define_symbol to use 'S'
1572 where we need to, which is not necessarily super-clean,
1573 but seems workable enough. */
1575 if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
1579 if (*pp == 'V' && !within_function)
1581 sym = define_symbol ((cs->c_value
1582 + ANOFFSET (objfile->section_offsets,
1583 static_block_section)),
1584 cs->c_name, 0, 0, objfile);
1587 SYMBOL_VALUE (sym) += static_block_base;
1588 SYMBOL_SECTION (sym) = static_block_section;
1597 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1598 only the last component of the name. Result is in static storage and
1599 is only good for temporary use. */
1602 coff_getfilename (aux_entry, objfile)
1603 union internal_auxent *aux_entry;
1604 struct objfile *objfile;
1606 static char buffer[BUFSIZ];
1607 register char *temp;
1610 if (aux_entry->x_file.x_n.x_zeroes == 0)
1612 ((struct coff_symfile_info *)objfile->sym_private)->strtbl
1613 + aux_entry->x_file.x_n.x_offset);
1616 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1617 buffer[FILNMLEN] = '\0';
1621 /* FIXME: We should not be throwing away the information about what
1622 directory. It should go into dirname of the symtab, or some such
1624 if ((temp = strrchr (result, '/')) != NULL)
1629 /* Set *SYMBOL to symbol number symno in symtbl. */
1631 read_symbol (symbol, symno)
1632 struct internal_syment *symbol;
1636 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1639 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1641 if (symno < 0 || symno >= nsyms)
1643 static struct complaint msg =
1644 {"Invalid symbol offset", 0, 0};
1646 symbol->n_value = 0;
1647 symbol->n_scnum = -1;
1650 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1651 stbl + (symno*local_symesz),
1655 /* Get value corresponding to symbol number symno in symtbl. */
1658 read_symbol_nvalue (symno)
1661 struct internal_syment symbol[1];
1663 read_symbol (symbol, symno);
1664 return symbol->n_value;
1668 /* Find the address of the function corresponding to symno, where
1669 symno is the symbol pointed to by the linetable. */
1672 read_symbol_lineno (symno)
1676 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1679 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1681 struct internal_syment symbol[1];
1682 union internal_auxent main_aux[1];
1686 complain (&bf_notfound_complaint);
1690 /* Note that just searching for a short distance (e.g. 50 symbols)
1691 is not enough, at least in the following case.
1694 [many .stabx entries]
1695 [a few functions, referring to foo]
1699 What happens here is that the assembler moves the .stabx entries
1700 to right before the ".bf" for foo, but the symbol for "foo" is before
1701 all the stabx entries. See PR gdb/2222. */
1703 /* Maintaining a table of .bf entries might be preferable to this search.
1704 If I understand things correctly it would need to be done only for
1705 the duration of a single psymtab to symtab conversion. */
1706 while (symno < nsyms)
1708 bfd_coff_swap_sym_in (symfile_bfd,
1709 stbl + (symno * local_symesz), symbol);
1710 if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf"))
1712 symno += symbol->n_numaux + 1;
1715 complain (&bf_notfound_complaint);
1719 /* take aux entry and return its lineno */
1721 bfd_coff_swap_aux_in (this_symtab_psymtab->objfile->obfd,
1722 stbl + symno * local_symesz,
1723 symbol->n_type, symbol->n_sclass,
1724 0, symbol->n_numaux, main_aux);
1726 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1729 /* Support for line number handling */
1731 /* This function is called for every section; it finds the outer limits
1732 * of the line table (minimum and maximum file offset) so that the
1733 * mainline code can read the whole thing for efficiency.
1736 find_linenos (abfd, asect, vpinfo)
1741 struct coff_symfile_info *info;
1743 file_ptr offset, maxoff;
1745 count = asect->lineno_count;
1747 if (!STREQ (asect->name, ".text") || count == 0)
1750 size = count * coff_data (abfd)->local_linesz;
1751 info = (struct coff_symfile_info *)vpinfo;
1752 offset = asect->line_filepos;
1753 maxoff = offset + size;
1755 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1756 info->min_lineno_offset = offset;
1758 if (maxoff > info->max_lineno_offset)
1759 info->max_lineno_offset = maxoff;
1762 static void xcoff_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
1765 xcoff_psymtab_to_symtab_1 (pst)
1766 struct partial_symtab *pst;
1768 struct cleanup *old_chain;
1777 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1782 /* Read in all partial symtabs on which this one is dependent */
1783 for (i = 0; i < pst->number_of_dependencies; i++)
1784 if (!pst->dependencies[i]->readin)
1786 /* Inform about additional files that need to be read in. */
1789 fputs_filtered (" ", gdb_stdout);
1791 fputs_filtered ("and ", gdb_stdout);
1793 printf_filtered ("%s...", pst->dependencies[i]->filename);
1794 wrap_here (""); /* Flush output */
1795 gdb_flush (gdb_stdout);
1797 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1800 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0)
1802 /* Init stuff necessary for reading in symbols. */
1805 old_chain = make_cleanup (really_free_pendings, 0);
1807 read_xcoff_symtab (pst);
1808 sort_symtab_syms (pst->symtab);
1810 do_cleanups (old_chain);
1816 static void xcoff_psymtab_to_symtab PARAMS ((struct partial_symtab *));
1818 /* Read in all of the symbols for a given psymtab for real.
1819 Be verbose about it if the user wants that. */
1822 xcoff_psymtab_to_symtab (pst)
1823 struct partial_symtab *pst;
1833 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1838 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0
1839 || pst->number_of_dependencies)
1841 /* Print the message now, before reading the string table,
1842 to avoid disconcerting pauses. */
1845 printf_filtered ("Reading in symbols for %s...", pst->filename);
1846 gdb_flush (gdb_stdout);
1849 sym_bfd = pst->objfile->obfd;
1851 next_symbol_text_func = xcoff_next_symbol_text;
1853 xcoff_psymtab_to_symtab_1 (pst);
1855 /* Match with global symbols. This only needs to be done once,
1856 after all of the symtabs and dependencies have been read in. */
1857 scan_file_globals (pst->objfile);
1859 /* Finish up the debug error message. */
1861 printf_filtered ("done.\n");
1866 xcoff_new_init (objfile)
1867 struct objfile *objfile;
1869 stabsread_new_init ();
1870 buildsym_new_init ();
1873 /* Do initialization in preparation for reading symbols from OBJFILE.
1875 We will only be called if this is an XCOFF or XCOFF-like file.
1876 BFD handles figuring out the format of the file, and code in symfile.c
1877 uses BFD's determination to vector to us. */
1880 xcoff_symfile_init (objfile)
1881 struct objfile *objfile;
1883 /* Allocate struct to keep track of the symfile */
1884 objfile -> sym_private = xmmalloc (objfile -> md,
1885 sizeof (struct coff_symfile_info));
1887 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1888 find this causes a significant slowdown in gdb then we could
1889 set it in the debug symbol readers only when necessary. */
1890 objfile->flags |= OBJF_REORDERED;
1892 init_entry_point_info (objfile);
1895 /* Perform any local cleanups required when we are done with a particular
1896 objfile. I.E, we are in the process of discarding all symbol information
1897 for an objfile, freeing up all memory held for it, and unlinking the
1898 objfile struct from the global list of known objfiles. */
1901 xcoff_symfile_finish (objfile)
1902 struct objfile *objfile;
1904 if (objfile -> sym_private != NULL)
1906 mfree (objfile -> md, objfile -> sym_private);
1909 /* Start with a fresh include table for the next objfile. */
1915 inclIndx = inclLength = inclDepth = 0;
1920 init_stringtab (abfd, offset, objfile)
1923 struct objfile *objfile;
1927 unsigned char lengthbuf[4];
1930 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = NULL;
1932 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1933 error ("cannot seek to string table in %s: %s",
1934 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1936 val = bfd_read ((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1937 length = bfd_h_get_32 (abfd, lengthbuf);
1939 /* If no string table is needed, then the file may end immediately
1940 after the symbols. Just return with `strtbl' set to NULL. */
1942 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1945 /* Allocate string table from symbol_obstack. We will need this table
1946 as long as we have its symbol table around. */
1948 strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
1949 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = strtbl;
1951 /* Copy length buffer, the first byte is usually zero and is
1952 used for stabs with a name length of zero. */
1953 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1954 if (length == sizeof lengthbuf)
1957 val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf,
1960 if (val != length - sizeof lengthbuf)
1961 error ("cannot read string table from %s: %s",
1962 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1963 if (strtbl[length - 1] != '\0')
1964 error ("bad symbol file: string table does not end with null character");
1969 /* If we have not yet seen a function for this psymtab, this is 0. If we
1970 have seen one, it is the offset in the line numbers of the line numbers
1972 static unsigned int first_fun_line_offset;
1974 static struct partial_symtab *xcoff_start_psymtab
1975 PARAMS ((struct objfile *, struct section_offsets *, char *, int,
1976 struct partial_symbol **, struct partial_symbol **));
1978 /* Allocate and partially fill a partial symtab. It will be
1979 completely filled at the end of the symbol list.
1981 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1982 is the address relative to which its symbols are (incremental) or 0
1985 static struct partial_symtab *
1986 xcoff_start_psymtab (objfile, section_offsets,
1987 filename, first_symnum, global_syms, static_syms)
1988 struct objfile *objfile;
1989 struct section_offsets *section_offsets;
1992 struct partial_symbol **global_syms;
1993 struct partial_symbol **static_syms;
1995 struct partial_symtab *result =
1996 start_psymtab_common (objfile, section_offsets,
1998 /* We fill in textlow later. */
2000 global_syms, static_syms);
2002 result->read_symtab_private = (char *)
2003 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
2004 ((struct symloc *)result->read_symtab_private)->first_symnum = first_symnum;
2005 result->read_symtab = xcoff_psymtab_to_symtab;
2007 /* Deduce the source language from the filename for this psymtab. */
2008 psymtab_language = deduce_language_from_filename (filename);
2013 static struct partial_symtab *xcoff_end_psymtab
2014 PARAMS ((struct partial_symtab *, char **, int, int,
2015 struct partial_symtab **, int, int));
2017 /* Close off the current usage of PST.
2018 Returns PST, or NULL if the partial symtab was empty and thrown away.
2020 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2022 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2023 are the information for includes and dependencies. */
2025 static struct partial_symtab *
2026 xcoff_end_psymtab (pst, include_list, num_includes, capping_symbol_number,
2027 dependency_list, number_dependencies, textlow_not_set)
2028 struct partial_symtab *pst;
2029 char **include_list;
2031 int capping_symbol_number;
2032 struct partial_symtab **dependency_list;
2033 int number_dependencies;
2034 int textlow_not_set;
2037 struct objfile *objfile = pst -> objfile;
2039 if (capping_symbol_number != -1)
2040 ((struct symloc *)pst->read_symtab_private)->numsyms =
2041 capping_symbol_number
2042 - ((struct symloc *)pst->read_symtab_private)->first_symnum;
2043 ((struct symloc *)pst->read_symtab_private)->lineno_off =
2044 first_fun_line_offset;
2045 first_fun_line_offset = 0;
2046 pst->n_global_syms =
2047 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2048 pst->n_static_syms =
2049 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2051 pst->number_of_dependencies = number_dependencies;
2052 if (number_dependencies)
2054 pst->dependencies = (struct partial_symtab **)
2055 obstack_alloc (&objfile->psymbol_obstack,
2056 number_dependencies * sizeof (struct partial_symtab *));
2057 memcpy (pst->dependencies, dependency_list,
2058 number_dependencies * sizeof (struct partial_symtab *));
2061 pst->dependencies = 0;
2063 for (i = 0; i < num_includes; i++)
2065 struct partial_symtab *subpst =
2066 allocate_psymtab (include_list[i], objfile);
2068 subpst->section_offsets = pst->section_offsets;
2069 subpst->read_symtab_private =
2070 (char *) obstack_alloc (&objfile->psymbol_obstack,
2071 sizeof (struct symloc));
2072 ((struct symloc *)subpst->read_symtab_private)->first_symnum = 0;
2073 ((struct symloc *)subpst->read_symtab_private)->numsyms = 0;
2074 subpst->textlow = 0;
2075 subpst->texthigh = 0;
2077 /* We could save slight bits of space by only making one of these,
2078 shared by the entire set of include files. FIXME-someday. */
2079 subpst->dependencies = (struct partial_symtab **)
2080 obstack_alloc (&objfile->psymbol_obstack,
2081 sizeof (struct partial_symtab *));
2082 subpst->dependencies[0] = pst;
2083 subpst->number_of_dependencies = 1;
2085 subpst->globals_offset =
2086 subpst->n_global_syms =
2087 subpst->statics_offset =
2088 subpst->n_static_syms = 0;
2092 subpst->read_symtab = pst->read_symtab;
2095 sort_pst_symbols (pst);
2097 /* If there is already a psymtab or symtab for a file of this name,
2098 remove it. (If there is a symtab, more drastic things also
2099 happen.) This happens in VxWorks. */
2100 free_named_symtabs (pst->filename);
2102 if (num_includes == 0
2103 && number_dependencies == 0
2104 && pst->n_global_syms == 0
2105 && pst->n_static_syms == 0)
2107 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2108 it is on the obstack, but we can forget to chain it on the list. */
2109 /* Empty psymtabs happen as a result of header files which don't have
2110 any symbols in them. There can be a lot of them. */
2111 struct partial_symtab *prev_pst;
2113 /* First, snip it out of the psymtab chain */
2115 if (pst->objfile->psymtabs == pst)
2116 pst->objfile->psymtabs = pst->next;
2118 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
2119 if (prev_pst->next == pst)
2120 prev_pst->next = pst->next;
2122 /* Next, put it on a free list for recycling */
2124 pst->next = pst->objfile->free_psymtabs;
2125 pst->objfile->free_psymtabs = pst;
2127 /* Indicate that psymtab was thrown away. */
2128 pst = (struct partial_symtab *)NULL;
2133 static void swap_sym PARAMS ((struct internal_syment *,
2134 union internal_auxent *, char **, char **,
2138 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2139 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2140 the symbol and its auxents. */
2143 swap_sym (symbol, aux, name, raw, symnump, objfile)
2144 struct internal_syment *symbol;
2145 union internal_auxent *aux;
2148 unsigned int *symnump;
2149 struct objfile *objfile;
2151 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2152 if (symbol->n_zeroes)
2154 /* If it's exactly E_SYMNMLEN characters long it isn't
2156 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2158 /* FIXME: wastes memory for symbols which we don't end up putting
2159 into the minimal symbols. */
2161 p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2162 strncpy (p, symbol->n_name, E_SYMNMLEN);
2163 p[E_SYMNMLEN] = '\0';
2167 /* Point to the unswapped name as that persists as long as the
2169 *name = ((struct external_syment *)*raw)->e.e_name;
2171 else if (symbol->n_sclass & 0x80)
2173 *name = ((struct coff_symfile_info *)objfile->sym_private)->debugsec
2178 *name = ((struct coff_symfile_info *)objfile->sym_private)->strtbl
2182 *raw += coff_data (objfile->obfd)->local_symesz;
2183 if (symbol->n_numaux > 0)
2185 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2186 symbol->n_sclass, 0, symbol->n_numaux, aux);
2188 *symnump += symbol->n_numaux;
2189 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2194 scan_xcoff_symtab (section_offsets, objfile)
2195 struct section_offsets *section_offsets;
2196 struct objfile *objfile;
2198 int toc_offset = 0; /* toc offset value in data section. */
2199 char *filestring = NULL;
2202 int past_first_source_file = 0;
2206 /* Current partial symtab */
2207 struct partial_symtab *pst;
2209 /* List of current psymtab's include files */
2210 char **psymtab_include_list;
2211 int includes_allocated;
2214 /* Index within current psymtab dependency list */
2215 struct partial_symtab **dependency_list;
2216 int dependencies_used, dependencies_allocated;
2219 struct internal_syment symbol;
2220 union internal_auxent main_aux;
2221 unsigned int ssymnum;
2223 char *last_csect_name = NULL; /* last seen csect's name and value */
2224 CORE_ADDR last_csect_val = 0;
2225 int last_csect_sec = 0;
2226 int misc_func_recorded = 0; /* true if any misc. function */
2227 int textlow_not_set = 1;
2229 pst = (struct partial_symtab *) 0;
2231 includes_allocated = 30;
2233 psymtab_include_list = (char **) alloca (includes_allocated *
2236 dependencies_allocated = 30;
2237 dependencies_used = 0;
2239 (struct partial_symtab **) alloca (dependencies_allocated *
2240 sizeof (struct partial_symtab *));
2242 last_source_file = NULL;
2244 abfd = objfile->obfd;
2246 sraw_symbol = ((struct coff_symfile_info *)objfile->sym_private)->symtbl;
2247 nsyms = ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms;
2249 while (ssymnum < nsyms)
2251 int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0] & 0xff;
2252 /* This is the type we pass to partial-stab.h. A less kludgy solution
2253 would be to break out partial-stab.h into its various parts--shuffle
2254 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2255 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2265 /* The CSECT auxent--always the last auxent. */
2266 union internal_auxent csect_aux;
2267 unsigned int symnum_before = ssymnum;
2269 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2271 if (symbol.n_numaux > 1)
2273 bfd_coff_swap_aux_in
2275 sraw_symbol - coff_data(abfd)->local_symesz,
2278 symbol.n_numaux - 1,
2283 csect_aux = main_aux;
2285 /* If symbol name starts with ".$" or "$", ignore it. */
2286 if (namestring[0] == '$'
2287 || (namestring[0] == '.' && namestring[1] == '$'))
2290 switch (csect_aux.x_csect.x_smtyp & 0x7)
2293 switch (csect_aux.x_csect.x_smclas)
2296 if (last_csect_name)
2298 /* If no misc. function recorded in the last
2299 seen csect, enter it as a function. This
2300 will take care of functions like strcmp()
2303 if (!misc_func_recorded)
2305 RECORD_MINIMAL_SYMBOL
2306 (last_csect_name, last_csect_val,
2307 mst_text, last_csect_sec,
2313 /* We have to allocate one psymtab for
2314 each program csect, because their text
2315 sections need not be adjacent. */
2317 (pst, psymtab_include_list, includes_used,
2318 symnum_before, dependency_list,
2319 dependencies_used, textlow_not_set);
2321 dependencies_used = 0;
2322 /* Give all psymtabs for this source file the same
2324 pst = xcoff_start_psymtab
2325 (objfile, section_offsets,
2328 objfile->global_psymbols.next,
2329 objfile->static_psymbols.next);
2332 if (namestring && namestring[0] == '.')
2334 last_csect_name = namestring;
2335 last_csect_val = symbol.n_value;
2337 secnum_to_section (symbol.n_scnum, objfile);
2342 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2343 if (highval > pst->texthigh)
2344 pst->texthigh = highval;
2345 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2346 pst->textlow = symbol.n_value;
2348 misc_func_recorded = 0;
2352 /* Data variables are recorded in the minimal symbol
2353 table, except for section symbols. */
2354 if (*namestring != '.')
2355 prim_record_minimal_symbol_and_info
2356 (namestring, symbol.n_value,
2357 sclass == C_HIDEXT ? mst_file_data : mst_data,
2358 NULL, secnum_to_section (symbol.n_scnum, objfile),
2364 warning ("More than one XMC_TC0 symbol found.");
2365 toc_offset = symbol.n_value;
2369 /* These symbols tell us where the TOC entry for a
2370 variable is, not the variable itself. */
2379 switch (csect_aux.x_csect.x_smclas)
2382 /* A function entry point. */
2384 if (first_fun_line_offset == 0 && symbol.n_numaux > 1)
2385 first_fun_line_offset =
2386 main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
2387 RECORD_MINIMAL_SYMBOL
2388 (namestring, symbol.n_value,
2389 sclass == C_HIDEXT ? mst_file_text : mst_text,
2390 secnum_to_section (symbol.n_scnum, objfile),
2395 /* shared library function trampoline code entry
2398 /* record trampoline code entries as
2399 mst_solib_trampoline symbol. When we lookup mst
2400 symbols, we will choose mst_text over
2401 mst_solib_trampoline. */
2402 RECORD_MINIMAL_SYMBOL
2403 (namestring, symbol.n_value,
2404 mst_solib_trampoline,
2405 secnum_to_section (symbol.n_scnum, objfile),
2410 /* The symbols often have the same names as
2411 debug symbols for functions, and confuse
2417 /* xlc puts each variable in a separate csect,
2418 so we get an XTY_SD for each variable. But
2419 gcc puts several variables in a csect, so
2420 that each variable only gets an XTY_LD. We
2421 still need to record them. This will
2422 typically be XMC_RW; I suspect XMC_RO and
2423 XMC_BS might be possible too. */
2424 if (*namestring != '.')
2425 prim_record_minimal_symbol_and_info
2426 (namestring, symbol.n_value,
2427 sclass == C_HIDEXT ? mst_file_data : mst_data,
2428 NULL, secnum_to_section (symbol.n_scnum, objfile),
2435 switch (csect_aux.x_csect.x_smclas)
2439 /* Common variables are recorded in the minimal symbol
2440 table, except for section symbols. */
2441 if (*namestring != '.')
2442 prim_record_minimal_symbol_and_info
2443 (namestring, symbol.n_value,
2444 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
2445 NULL, secnum_to_section (symbol.n_scnum, objfile),
2458 unsigned int symnum_before;
2460 symnum_before = ssymnum;
2461 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2464 /* See if the last csect needs to be recorded. */
2466 if (last_csect_name && !misc_func_recorded)
2469 /* If no misc. function recorded in the last seen csect, enter
2470 it as a function. This will take care of functions like
2471 strcmp() compiled by xlc. */
2473 RECORD_MINIMAL_SYMBOL
2474 (last_csect_name, last_csect_val,
2475 mst_text, last_csect_sec, objfile);
2480 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2481 symnum_before, dependency_list,
2482 dependencies_used, textlow_not_set);
2484 dependencies_used = 0;
2486 first_fun_line_offset = 0;
2488 /* XCOFF, according to the AIX 3.2 documentation, puts the
2489 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2490 do things the standard COFF way and put it in the auxent.
2491 We use the auxent if the symbol is ".file" and an auxent
2492 exists, otherwise use the symbol itself. */
2493 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2495 filestring = coff_getfilename (&main_aux, objfile);
2498 filestring = namestring;
2500 pst = xcoff_start_psymtab (objfile, section_offsets,
2503 objfile->global_psymbols.next,
2504 objfile->static_psymbols.next);
2505 last_csect_name = NULL;
2511 static struct complaint msg =
2512 {"Storage class %d not recognized during scan", 0, 0};
2513 complain (&msg, sclass);
2517 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2518 to handle only the C_FUN and C_EXT. */
2533 /* C_EINCL means we are switching back to the main file. But there
2534 is no reason to care; the only thing we want to know about
2535 includes is the names of all the included (.h) files. */
2540 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2544 /* I don't think the name of the common block (as opposed to the
2545 variables within it) is something which is user visible
2553 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2554 so C_LSYM would appear to be only for locals. */
2560 /* We probably could save a few instructions by assuming that
2561 C_LSYM, C_PSYM, etc., never have auxents. */
2563 ((struct external_syment *)sraw_symbol)->e_numaux[0] + 1;
2565 sraw_symbol += sizeof (struct external_syment) * naux1;
2574 /* The value of the C_FUN is not the address of the function (it
2575 appears to be the address before linking), but as long as it
2576 is smaller than the actual address, then find_pc_partial_function
2577 will use the minimal symbols instead. I hope. */
2585 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2587 #define CUR_SYMBOL_TYPE stype
2588 #define CUR_SYMBOL_VALUE symbol.n_value
2590 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2591 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2593 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
2594 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2596 /* We have already set the namestring. */
2597 #define SET_NAMESTRING() /* */
2599 #include "partial-stab.h"
2605 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2606 ssymnum, dependency_list,
2607 dependencies_used, textlow_not_set);
2610 /* Record the toc offset value of this symbol table into ldinfo structure.
2611 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2612 this information would be file auxiliary header. */
2614 if (xcoff_add_toc_to_loadinfo_hook != NULL)
2615 (*xcoff_add_toc_to_loadinfo_hook) ((unsigned long) toc_offset);
2618 /* Scan and build partial symbols for a symbol file.
2619 We have been initialized by a call to dbx_symfile_init, which
2620 put all the relevant info into a "struct dbx_symfile_info",
2621 hung off the objfile structure.
2623 SECTION_OFFSETS contains offsets relative to which the symbols in the
2624 various sections are (depending where the sections were actually loaded).
2625 MAINLINE is true if we are reading the main symbol
2626 table (as opposed to a shared lib or dynamically loaded file). */
2629 xcoff_initial_scan (objfile, section_offsets, mainline)
2630 struct objfile *objfile;
2631 struct section_offsets *section_offsets;
2632 int mainline; /* FIXME comments above */
2636 struct cleanup *back_to;
2637 int num_symbols; /* # of symbols */
2638 file_ptr symtab_offset; /* symbol table and */
2639 file_ptr stringtab_offset; /* string table file offsets */
2640 struct coff_symfile_info *info;
2644 /* Initialize load info structure. */
2645 if (mainline && xcoff_init_loadinfo_hook != NULL)
2646 (*xcoff_init_loadinfo_hook) ();
2648 info = (struct coff_symfile_info *) objfile -> sym_private;
2649 symfile_bfd = abfd = objfile->obfd;
2650 name = objfile->name;
2652 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2653 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2654 stringtab_offset = symtab_offset +
2655 num_symbols * coff_data(abfd)->local_symesz;
2657 info->min_lineno_offset = 0;
2658 info->max_lineno_offset = 0;
2659 bfd_map_over_sections (abfd, find_linenos, info);
2661 if (num_symbols > 0)
2663 /* Read the string table. */
2664 init_stringtab (abfd, stringtab_offset, objfile);
2666 /* Read the .debug section, if present. */
2669 bfd_size_type length;
2670 char *debugsec = NULL;
2672 secp = bfd_get_section_by_name (abfd, ".debug");
2675 length = bfd_section_size (abfd, secp);
2679 (char *) obstack_alloc (&objfile->symbol_obstack, length);
2681 if (!bfd_get_section_contents (abfd, secp, debugsec,
2682 (file_ptr) 0, length))
2684 error ("Error reading .debug section of `%s': %s",
2685 name, bfd_errmsg (bfd_get_error ()));
2689 ((struct coff_symfile_info *)objfile->sym_private)->debugsec =
2694 /* Read the symbols. We keep them in core because we will want to
2695 access them randomly in read_symbol*. */
2696 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2698 error ("Error reading symbols from %s: %s",
2699 name, bfd_errmsg (bfd_get_error ()));
2700 size = coff_data (abfd)->local_symesz * num_symbols;
2701 ((struct coff_symfile_info *)objfile->sym_private)->symtbl =
2702 obstack_alloc (&objfile->symbol_obstack, size);
2703 ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms =
2706 val = bfd_read (((struct coff_symfile_info *)objfile->sym_private)->symtbl,
2709 perror_with_name ("reading symbol table");
2711 /* If we are reinitializing, or if we have never loaded syms yet, init */
2713 || objfile->global_psymbols.size == 0
2714 || objfile->static_psymbols.size == 0)
2715 /* I'm not sure how how good num_symbols is; the rule of thumb in
2716 init_psymbol_list was developed for a.out. On the one hand,
2717 num_symbols includes auxents. On the other hand, it doesn't
2719 init_psymbol_list (objfile, num_symbols);
2722 back_to = make_cleanup (really_free_pendings, 0);
2724 init_minimal_symbol_collection ();
2725 make_cleanup (discard_minimal_symbols, 0);
2727 /* Now that the symbol table data of the executable file are all in core,
2728 process them and define symbols accordingly. */
2730 scan_xcoff_symtab (section_offsets, objfile);
2732 /* Install any minimal symbols that have been collected as the current
2733 minimal symbols for this objfile. */
2735 install_minimal_symbols (objfile);
2737 do_cleanups (back_to);
2740 static struct section_offsets *
2741 xcoff_symfile_offsets (objfile, addr)
2742 struct objfile *objfile;
2745 struct section_offsets *section_offsets;
2748 objfile->num_sections = SECT_OFF_MAX;
2749 section_offsets = (struct section_offsets *)
2751 (&objfile -> psymbol_obstack,
2752 sizeof (struct section_offsets)
2753 + sizeof (section_offsets->offsets) * objfile->num_sections);
2755 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2756 of the .text section. This strikes me as wrong--whether the
2757 offset to be applied to symbol reading is relative to the start
2758 address of the section depends on the symbol format. In any
2759 event, this whole "addr" concept is pretty broken (it doesn't
2760 handle any section but .text sensibly), so just ignore the addr
2761 parameter and use 0. rs6000-nat.c will set the correct section
2762 offsets via objfile_relocate. */
2763 for (i = 0; i < objfile->num_sections; ++i)
2764 ANOFFSET (section_offsets, i) = 0;
2766 return section_offsets;
2769 /* Register our ability to parse symbols for xcoff BFD files. */
2771 static struct sym_fns xcoff_sym_fns =
2774 /* Because the bfd uses coff_flavour, we need to specially kludge
2775 the flavour. It is possible that coff and xcoff should be merged as
2776 they do have fundamental similarities (for example, the extra storage
2777 classes used for stabs could presumably be recognized in any COFF file).
2778 However, in addition to obvious things like all the csect hair, there are
2779 some subtler differences between xcoffread.c and coffread.c, notably
2780 the fact that coffread.c has no need to read in all the symbols, but
2781 xcoffread.c reads all the symbols and does in fact randomly access them
2782 (in C_BSTAT and line number processing). */
2784 (enum bfd_flavour)-1,
2786 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2787 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2788 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
2789 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2790 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
2791 NULL /* next: pointer to next struct sym_fns */
2795 _initialize_xcoffread ()
2797 add_symtab_fns(&xcoff_sym_fns);
2799 func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
2800 "<function, no debug info>", NULL);
2801 TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
2803 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
2804 "<variable, no debug info>", NULL);