1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
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,
22 Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
30 #include "gdb_string.h"
32 #include <sys/param.h>
38 #include "coff/internal.h"
39 #include "libcoff.h" /* FIXME, internal data from BFD */
40 #include "coff/rs6000.h"
47 #include "stabsread.h"
48 #include "expression.h"
49 #include "language.h" /* Needed inside partial-stab.h */
50 #include "complaints.h"
52 #include "gdb-stabs.h"
54 /* For interface with stabsread.c. */
55 #include "aout/stab_gnu.h"
57 /* For interface with partial-stab.h. */
58 #define N_UNDF 0 /* Undefined symbol */
61 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
62 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
63 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
64 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
65 #define N_FN 0x1f /* File name of .o file */
66 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
67 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
68 N_DATA, or N_BSS. When the low-order bit of other types is set,
69 (e.g. N_WARNING versus N_FN), they are two different types. */
70 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
73 /* The following symbols refer to set elements.
74 All the N_SET[ATDB] symbols with the same name form one set.
75 Space is allocated for the set in the text section, and each set
76 elements value is stored into one word of the space.
77 The first word of the space is the length of the set (number of elements).
79 The address of the set is made into an N_SETV symbol
80 whose name is the same as the name of the set.
81 This symbol acts like a N_DATA global symbol
82 in that it can satisfy undefined external references. */
84 /* These appear as input to LD, in a .o file. */
85 #define N_SETA 0x14 /* Absolute set element symbol */
86 #define N_SETT 0x16 /* Text set element symbol */
87 #define N_SETD 0x18 /* Data set element symbol */
88 #define N_SETB 0x1A /* Bss set element symbol */
90 /* This is output from LD. */
91 #define N_SETV 0x1C /* Pointer to set vector in data area. */
93 /* We put a pointer to this structure in the read_symtab_private field
99 /* First symbol number for this file. */
103 /* Number of symbols in the section of the symbol table devoted to
104 this file's symbols (actually, the section bracketed may contain
105 more than just this file's symbols). If numsyms is 0, the only
106 reason for this thing's existence is the dependency list. Nothing
107 else will happen when it is read in. */
111 /* Position of the start of the line number information for this psymtab. */
112 unsigned int lineno_off;
115 /* Remember what we deduced to be the source language of this psymtab. */
117 static enum language psymtab_language = language_unknown;
120 /* Simplified internal version of coff symbol table information */
125 int c_symnum; /* symbol number of this entry */
126 int c_naux; /* 0 if syment only, 1 if syment + auxent */
128 unsigned char c_sclass;
133 /* last function's saved coff symbol `cs' */
135 static struct coff_symbol fcn_cs_saved;
137 static bfd *symfile_bfd;
139 /* Core address of start and end of text of current source file.
140 This is calculated from the first function seen after a C_FILE
144 static CORE_ADDR cur_src_end_addr;
146 /* Core address of the end of the first object file. */
148 static CORE_ADDR first_object_file_end;
150 /* initial symbol-table-debug-string vector length */
152 #define INITIAL_STABVECTOR_LENGTH 40
154 /* Nonzero if within a function (so symbols should be local,
155 if nothing says specifically). */
159 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
160 there is any reason not to just use a #define, but might as well
161 ask BFD for the size and store it here, I guess. */
163 static unsigned local_symesz;
165 struct coff_symfile_info
167 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
168 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
170 /* Pointer to the string table. */
173 /* Pointer to debug section. */
176 /* Pointer to the a.out symbol table. */
179 /* Number of symbols in symtbl. */
182 /* Offset in data section to TOC anchor. */
183 CORE_ADDR toc_offset;
186 static struct complaint storclass_complaint =
187 {"Unexpected storage class: %d", 0, 0};
189 static struct complaint bf_notfound_complaint =
190 {"line numbers off, `.bf' symbol not found", 0, 0};
192 static struct complaint ef_complaint =
193 {"Mismatched .ef symbol ignored starting at symnum %d", 0, 0};
195 static struct complaint eb_complaint =
196 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
198 static void xcoff_initial_scan (struct objfile *, int);
200 static void scan_xcoff_symtab (struct objfile *);
202 static char *xcoff_next_symbol_text (struct objfile *);
204 static void record_include_begin (struct coff_symbol *);
207 enter_line_range (struct subfile *, unsigned, unsigned,
208 CORE_ADDR, CORE_ADDR, unsigned *);
210 static void init_stringtab (bfd *, file_ptr, struct objfile *);
212 static void xcoff_symfile_init (struct objfile *);
214 static void xcoff_new_init (struct objfile *);
216 static void xcoff_symfile_finish (struct objfile *);
219 xcoff_symfile_offsets (struct objfile *, struct section_addr_info *addrs);
221 static void find_linenos (bfd *, sec_ptr, PTR);
223 static char *coff_getfilename (union internal_auxent *, struct objfile *);
225 static void read_symbol (struct internal_syment *, int);
227 static int read_symbol_lineno (int);
229 static CORE_ADDR read_symbol_nvalue (int);
231 static struct symbol *process_xcoff_symbol (struct coff_symbol *,
234 static void read_xcoff_symtab (struct partial_symtab *);
237 static void add_stab_to_list (char *, struct pending_stabs **);
240 static int compare_lte (const void *, const void *);
242 static struct linetable *arrange_linetable (struct linetable *);
244 static void record_include_end (struct coff_symbol *);
246 static void process_linenos (CORE_ADDR, CORE_ADDR);
249 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
251 static int secnum_to_section (int, struct objfile *);
252 static asection *secnum_to_bfd_section (int, struct objfile *);
254 struct find_targ_sec_arg
259 struct objfile *objfile;
262 static void find_targ_sec (bfd *, asection *, void *);
265 find_targ_sec (bfd *abfd, asection *sect, PTR obj)
267 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
268 struct objfile *objfile = args->objfile;
269 if (sect->target_index == args->targ_index)
271 /* This is the section. Figure out what SECT_OFF_* code it is. */
272 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
273 *args->resultp = SECT_OFF_TEXT (objfile);
274 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
275 *args->resultp = SECT_OFF_DATA (objfile);
277 *args->resultp = sect->index;
278 *args->bfd_sect = sect;
282 /* Return the section number (SECT_OFF_*) that CS points to. */
284 secnum_to_section (int secnum, struct objfile *objfile)
286 int off = SECT_OFF_TEXT (objfile);
287 asection *sect = NULL;
288 struct find_targ_sec_arg args;
289 args.targ_index = secnum;
291 args.bfd_sect = §
292 args.objfile = objfile;
293 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
297 /* Return the BFD section that CS points to. */
299 secnum_to_bfd_section (int secnum, struct objfile *objfile)
301 int off = SECT_OFF_TEXT (objfile);
302 asection *sect = NULL;
303 struct find_targ_sec_arg args;
304 args.targ_index = secnum;
306 args.bfd_sect = §
307 args.objfile = objfile;
308 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
312 /* add a given stab string into given stab vector. */
317 add_stab_to_list (char *stabname, struct pending_stabs **stabvector)
319 if (*stabvector == NULL)
321 *stabvector = (struct pending_stabs *)
322 xmalloc (sizeof (struct pending_stabs) +
323 INITIAL_STABVECTOR_LENGTH * sizeof (char *));
324 (*stabvector)->count = 0;
325 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
327 else if ((*stabvector)->count >= (*stabvector)->length)
329 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
330 *stabvector = (struct pending_stabs *)
331 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
332 (*stabvector)->length * sizeof (char *));
334 (*stabvector)->stab[(*stabvector)->count++] = stabname;
339 /* Linenos are processed on a file-by-file basis.
343 1) xlc (IBM's native c compiler) postpones static function code
344 emission to the end of a compilation unit. This way it can
345 determine if those functions (statics) are needed or not, and
346 can do some garbage collection (I think). This makes line
347 numbers and corresponding addresses unordered, and we end up
348 with a line table like:
365 and that breaks gdb's binary search on line numbers, if the
366 above table is not sorted on line numbers. And that sort
367 should be on function based, since gcc can emit line numbers
370 10 0x100 - for the init/test part of a for stmt.
373 10 0x400 - for the increment part of a for stmt.
375 arrange_linetable() will do this sorting.
377 2) aix symbol table might look like:
379 c_file // beginning of a new file
380 .bi // beginning of include file
381 .ei // end of include file
385 basically, .bi/.ei pairs do not necessarily encapsulate
386 their scope. They need to be recorded, and processed later
387 on when we come the end of the compilation unit.
388 Include table (inclTable) and process_linenos() handle
394 /* compare line table entry addresses. */
397 compare_lte (const void *lte1p, const void *lte2p)
399 struct linetable_entry *lte1 = (struct linetable_entry *) lte1p;
400 struct linetable_entry *lte2 = (struct linetable_entry *) lte2p;
401 return lte1->pc - lte2->pc;
404 /* Given a line table with function entries are marked, arrange its functions
405 in ascending order and strip off function entry markers and return it in
406 a newly created table. If the old one is good enough, return the old one. */
407 /* FIXME: I think all this stuff can be replaced by just passing
408 sort_linevec = 1 to end_symtab. */
410 static struct linetable *
411 arrange_linetable (struct linetable *oldLineTb)
413 int ii, jj, newline, /* new line count */
414 function_count; /* # of functions */
416 struct linetable_entry *fentry; /* function entry vector */
417 int fentry_size; /* # of function entries */
418 struct linetable *newLineTb; /* new line table */
420 #define NUM_OF_FUNCTIONS 20
422 fentry_size = NUM_OF_FUNCTIONS;
423 fentry = (struct linetable_entry *)
424 xmalloc (fentry_size * sizeof (struct linetable_entry));
426 for (function_count = 0, ii = 0; ii < oldLineTb->nitems; ++ii)
429 if (oldLineTb->item[ii].line == 0)
430 { /* function entry found. */
432 if (function_count >= fentry_size)
433 { /* make sure you have room. */
435 fentry = (struct linetable_entry *)
436 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
438 fentry[function_count].line = ii;
439 fentry[function_count].pc = oldLineTb->item[ii].pc;
444 if (function_count == 0)
449 else if (function_count > 1)
450 qsort (fentry, function_count, sizeof (struct linetable_entry), compare_lte);
452 /* allocate a new line table. */
453 newLineTb = (struct linetable *)
455 (sizeof (struct linetable) +
456 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
458 /* if line table does not start with a function beginning, copy up until
462 if (oldLineTb->item[0].line != 0)
464 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
465 newLineTb->item[newline] = oldLineTb->item[newline];
467 /* Now copy function lines one by one. */
469 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
489 char *name; /* include filename */
491 /* Offsets to the line table. end points to the last entry which is
492 part of this include file. */
495 struct subfile *subfile;
496 unsigned funStartLine; /* start line # of its function */
500 #define INITIAL_INCLUDE_TABLE_LENGTH 20
501 static InclTable *inclTable; /* global include table */
502 static int inclIndx; /* last entry to table */
503 static int inclLength; /* table length */
504 static int inclDepth; /* nested include depth */
506 static void allocate_include_entry (void);
509 record_include_begin (struct coff_symbol *cs)
513 /* In xcoff, we assume include files cannot be nested (not in .c files
514 of course, but in corresponding .s files.). */
516 /* This can happen with old versions of GCC.
517 GCC 2.3.3-930426 does not exhibit this on a test case which
518 a user said produced the message for him. */
519 static struct complaint msg =
520 {"Nested C_BINCL symbols", 0, 0};
525 allocate_include_entry ();
527 inclTable[inclIndx].name = cs->c_name;
528 inclTable[inclIndx].begin = cs->c_value;
532 record_include_end (struct coff_symbol *cs)
538 static struct complaint msg =
539 {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
543 allocate_include_entry ();
545 pTbl = &inclTable[inclIndx];
546 pTbl->end = cs->c_value;
553 allocate_include_entry (void)
555 if (inclTable == NULL)
557 inclTable = (InclTable *)
558 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
560 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
561 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
564 else if (inclIndx >= inclLength)
566 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
567 inclTable = (InclTable *)
568 xrealloc (inclTable, sizeof (InclTable) * inclLength);
569 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
570 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
574 /* Global variable to pass the psymtab down to all the routines involved
575 in psymtab to symtab processing. */
576 static struct partial_symtab *this_symtab_psymtab;
578 /* given the start and end addresses of a compilation unit (or a csect,
579 at times) process its lines and create appropriate line vectors. */
582 process_linenos (CORE_ADDR start, CORE_ADDR end)
585 file_ptr max_offset =
586 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
589 /* subfile structure for the main compilation unit. */
590 struct subfile main_subfile;
592 /* In the main source file, any time we see a function entry, we
593 reset this variable to function's absolute starting line number.
594 All the following line numbers in the function are relative to
595 this, and we record absolute line numbers in record_line(). */
597 unsigned int main_source_baseline = 0;
602 ((struct symloc *) this_symtab_psymtab->read_symtab_private)->lineno_off;
604 goto return_after_cleanup;
606 memset (&main_subfile, '\0', sizeof (main_subfile));
609 /* All source lines were in the main source file. None in include files. */
611 enter_line_range (&main_subfile, offset, 0, start, end,
612 &main_source_baseline);
616 /* There was source with line numbers in include files. */
619 coff_data (this_symtab_psymtab->objfile->obfd)->local_linesz;
620 main_source_baseline = 0;
622 for (ii = 0; ii < inclIndx; ++ii)
624 struct subfile *tmpSubfile;
626 /* If there is main file source before include file, enter it. */
627 if (offset < inclTable[ii].begin)
630 (&main_subfile, offset, inclTable[ii].begin - linesz,
631 start, 0, &main_source_baseline);
634 /* Have a new subfile for the include file. */
636 tmpSubfile = inclTable[ii].subfile =
637 (struct subfile *) xmalloc (sizeof (struct subfile));
639 memset (tmpSubfile, '\0', sizeof (struct subfile));
640 firstLine = &(inclTable[ii].funStartLine);
642 /* Enter include file's lines now. */
643 enter_line_range (tmpSubfile, inclTable[ii].begin,
644 inclTable[ii].end, start, 0, firstLine);
646 if (offset <= inclTable[ii].end)
647 offset = inclTable[ii].end + linesz;
650 /* All the include files' line have been processed at this point. Now,
651 enter remaining lines of the main file, if any left. */
652 if (offset < max_offset + 1 - linesz)
654 enter_line_range (&main_subfile, offset, 0, start, end,
655 &main_source_baseline);
659 /* Process main file's line numbers. */
660 if (main_subfile.line_vector)
662 struct linetable *lineTb, *lv;
664 lv = main_subfile.line_vector;
666 /* Line numbers are not necessarily ordered. xlc compilation will
667 put static function to the end. */
669 lineTb = arrange_linetable (lv);
672 current_subfile->line_vector = (struct linetable *)
673 xrealloc (lv, (sizeof (struct linetable)
674 + lv->nitems * sizeof (struct linetable_entry)));
679 current_subfile->line_vector = lineTb;
682 current_subfile->line_vector_length =
683 current_subfile->line_vector->nitems;
686 /* Now, process included files' line numbers. */
688 for (ii = 0; ii < inclIndx; ++ii)
690 if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */
692 struct linetable *lineTb, *lv;
694 lv = (inclTable[ii].subfile)->line_vector;
696 /* Line numbers are not necessarily ordered. xlc compilation will
697 put static function to the end. */
699 lineTb = arrange_linetable (lv);
703 /* For the same include file, we might want to have more than one
704 subfile. This happens if we have something like:
712 while foo.h including code in it. (stupid but possible)
713 Since start_subfile() looks at the name and uses an
714 existing one if finds, we need to provide a fake name and
718 start_subfile (inclTable[ii].name, (char *) 0);
721 /* Pick a fake name that will produce the same results as this
722 one when passed to deduce_language_from_filename. Kludge on
724 char *fakename = strrchr (inclTable[ii].name, '.');
725 if (fakename == NULL)
727 start_subfile (fakename, (char *) 0);
728 free (current_subfile->name);
730 current_subfile->name = xstrdup (inclTable[ii].name);
735 current_subfile->line_vector =
736 (struct linetable *) xrealloc
737 (lv, (sizeof (struct linetable)
738 + lv->nitems * sizeof (struct linetable_entry)));
744 current_subfile->line_vector = lineTb;
747 current_subfile->line_vector_length =
748 current_subfile->line_vector->nitems;
749 start_subfile (pop_subfile (), (char *) 0);
753 return_after_cleanup:
755 /* We don't want to keep alloc/free'ing the global include file table. */
758 /* Start with a fresh subfile structure for the next file. */
759 memset (&main_subfile, '\0', sizeof (struct subfile));
763 aix_process_linenos (void)
765 /* process line numbers and enter them into line vector */
766 process_linenos (last_source_start_addr, cur_src_end_addr);
770 /* Enter a given range of lines into the line vector.
771 can be called in the following two ways:
772 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
773 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
775 endoffset points to the last line table entry that we should pay
779 enter_line_range (struct subfile *subfile, unsigned beginoffset, unsigned endoffset, /* offsets to line table */
780 CORE_ADDR startaddr, /* offsets to line table */
781 CORE_ADDR endaddr, unsigned *firstLine)
783 unsigned int curoffset;
786 struct internal_lineno int_lnno;
787 unsigned int limit_offset;
791 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
793 curoffset = beginoffset;
795 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
800 if (endoffset >= limit_offset)
802 static struct complaint msg =
803 {"Bad line table offset in C_EINCL directive", 0, 0};
807 limit_offset = endoffset;
812 abfd = this_symtab_psymtab->objfile->obfd;
813 linesz = coff_data (abfd)->local_linesz;
814 ext_lnno = alloca (linesz);
816 while (curoffset <= limit_offset)
818 bfd_seek (abfd, curoffset, SEEK_SET);
819 bfd_read (ext_lnno, linesz, 1, abfd);
820 bfd_coff_swap_lineno_in (abfd, ext_lnno, &int_lnno);
822 /* Find the address this line represents. */
823 addr = (int_lnno.l_lnno
824 ? int_lnno.l_addr.l_paddr
825 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
826 addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
827 SECT_OFF_TEXT (this_symtab_psymtab->objfile));
829 if (addr < startaddr || (endaddr && addr >= endaddr))
832 if (int_lnno.l_lnno == 0)
834 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
835 record_line (subfile, 0, addr);
839 record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
845 /* Save the vital information for use when closing off the current file.
846 NAME is the file name the symbols came from, START_ADDR is the first
847 text address for the file, and SIZE is the number of bytes of text. */
849 #define complete_symtab(name, start_addr) { \
850 last_source_file = savestring (name, strlen (name)); \
851 last_source_start_addr = start_addr; \
855 /* Refill the symbol table input buffer
856 and set the variables that control fetching entries from it.
857 Reports an error if no data available.
858 This function can read past the end of the symbol table
859 (into the string table) but this does no harm. */
861 /* Reading symbol table has to be fast! Keep the followings as macros, rather
864 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
868 if (namestr[0] == '.') ++namestr; \
869 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
870 (char *)NULL, (SECTION), (asection *)NULL, (OBJFILE)); \
871 misc_func_recorded = 1; \
875 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
876 nested. At any given time, a symbol can only be in one static block.
877 This is the base address of current static block, zero if non exists. */
879 static int static_block_base = 0;
881 /* Section number for the current static block. */
883 static int static_block_section = -1;
885 /* true if space for symbol name has been allocated. */
887 static int symname_alloced = 0;
889 /* Next symbol to read. Pointer into raw seething symbol table. */
891 static char *raw_symbol;
893 /* This is the function which stabsread.c calls to get symbol
897 xcoff_next_symbol_text (struct objfile *objfile)
899 struct internal_syment symbol;
900 static struct complaint msg =
901 {"Unexpected symbol continuation", 0, 0};
903 /* FIXME: is this the same as the passed arg? */
904 objfile = this_symtab_psymtab->objfile;
906 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
911 /* Return something which points to '\0' and hope the symbol reading
912 code does something reasonable. */
915 else if (symbol.n_sclass & 0x80)
918 ((struct coff_symfile_info *) objfile->sym_private)->debugsec
921 coff_data (objfile->obfd)->local_symesz;
928 /* Return something which points to '\0' and hope the symbol reading
929 code does something reasonable. */
935 /* Read symbols for a given partial symbol table. */
938 read_xcoff_symtab (struct partial_symtab *pst)
940 struct objfile *objfile = pst->objfile;
941 bfd *abfd = objfile->obfd;
942 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
943 char *strtbl = ((struct coff_symfile_info *) objfile->sym_private)->strtbl;
945 ((struct coff_symfile_info *) objfile->sym_private)->debugsec;
946 char *debugfmt = xcoff_data (abfd)->xcoff64 ? "XCOFF64" : "XCOFF";
948 struct internal_syment symbol[1];
949 union internal_auxent main_aux;
950 struct coff_symbol cs[1];
951 CORE_ADDR file_start_addr = 0;
952 CORE_ADDR file_end_addr = 0;
954 int next_file_symnum = -1;
955 unsigned int max_symnum;
956 int just_started = 1;
958 int fcn_start_addr = 0;
960 struct coff_symbol fcn_stab_saved;
962 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
963 union internal_auxent fcn_aux_saved;
964 struct context_stack *new;
966 char *filestring = " _start_ "; /* Name of the current file. */
968 char *last_csect_name; /* last seen csect's name and value */
969 CORE_ADDR last_csect_val;
972 this_symtab_psymtab = pst;
974 /* Get the appropriate COFF "constants" related to the file we're
976 local_symesz = coff_data (abfd)->local_symesz;
978 last_source_file = NULL;
983 start_symtab (filestring, (char *) NULL, file_start_addr);
984 record_debugformat (debugfmt);
985 symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
987 symnum + ((struct symloc *) pst->read_symtab_private)->numsyms;
988 first_object_file_end = 0;
991 ((struct coff_symfile_info *) objfile->sym_private)->symtbl
992 + symnum * local_symesz;
994 while (symnum < max_symnum)
997 QUIT; /* make this command interruptable. */
999 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1000 /* read one symbol into `cs' structure. After processing the
1001 whole symbol table, only string table will be kept in memory,
1002 symbol table and debug section of xcoff will be freed. Thus
1003 we can mark symbols with names in string table as
1008 /* Swap and align the symbol into a reasonable C structure. */
1009 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1011 cs->c_symnum = symnum;
1012 cs->c_naux = symbol->n_numaux;
1013 if (symbol->n_zeroes)
1015 symname_alloced = 0;
1016 /* We must use the original, unswapped, name here so the name field
1017 pointed to by cs->c_name will persist throughout xcoffread. If
1018 we use the new field, it gets overwritten for each symbol. */
1019 cs->c_name = ((struct external_syment *) raw_symbol)->e.e_name;
1020 /* If it's exactly E_SYMNMLEN characters long it isn't
1022 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1025 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1026 strncpy (p, cs->c_name, E_SYMNMLEN);
1027 p[E_SYMNMLEN] = '\0';
1029 symname_alloced = 1;
1032 else if (symbol->n_sclass & 0x80)
1034 cs->c_name = debugsec + symbol->n_offset;
1035 symname_alloced = 0;
1039 /* in string table */
1040 cs->c_name = strtbl + (int) symbol->n_offset;
1041 symname_alloced = 1;
1043 cs->c_value = symbol->n_value;
1044 cs->c_sclass = symbol->n_sclass;
1045 cs->c_secnum = symbol->n_scnum;
1046 cs->c_type = (unsigned) symbol->n_type;
1048 raw_symbol += local_symesz;
1051 /* Save addr of first aux entry. */
1052 raw_auxptr = raw_symbol;
1054 /* Skip all the auxents associated with this symbol. */
1055 for (ii = symbol->n_numaux; ii; --ii)
1057 raw_symbol += coff_data (abfd)->local_auxesz;
1062 /* if symbol name starts with ".$" or "$", ignore it. */
1063 if (cs->c_name[0] == '$'
1064 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1067 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1069 if (last_source_file)
1072 end_symtab (cur_src_end_addr, objfile, SECT_OFF_TEXT (objfile));
1077 start_symtab ("_globals_", (char *) NULL, (CORE_ADDR) 0);
1078 record_debugformat (debugfmt);
1079 cur_src_end_addr = first_object_file_end;
1080 /* done with all files, everything from here on is globals */
1083 /* if explicitly specified as a function, treat is as one. */
1084 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
1086 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1087 0, cs->c_naux, &main_aux);
1088 goto function_entry_point;
1091 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1094 /* Dealing with a symbol with a csect entry. */
1096 #define CSECT(PP) ((PP)->x_csect)
1097 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1098 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1099 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1100 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1102 /* Convert the auxent to something we can access. */
1103 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1104 0, cs->c_naux, &main_aux);
1106 switch (CSECT_SMTYP (&main_aux))
1110 /* Ignore all external references. */
1114 /* A section description. */
1116 switch (CSECT_SCLAS (&main_aux))
1122 /* A program csect is seen. We have to allocate one
1123 symbol table for each program csect. Normally gdb
1124 prefers one symtab for each source file. In case
1125 of AIX, one source file might include more than one
1126 [PR] csect, and they don't have to be adjacent in
1127 terms of the space they occupy in memory. Thus, one
1128 single source file might get fragmented in the
1129 memory and gdb's file start and end address
1130 approach does not work! GCC (and I think xlc) seem
1131 to put all the code in the unnamed program csect. */
1133 if (last_csect_name)
1135 complete_symtab (filestring, file_start_addr);
1136 cur_src_end_addr = file_end_addr;
1137 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1140 /* Give all csects for this source file the same
1142 start_symtab (filestring, NULL, (CORE_ADDR) 0);
1143 record_debugformat (debugfmt);
1146 /* If this is the very first csect seen,
1147 basically `__start'. */
1150 first_object_file_end
1151 = cs->c_value + CSECT_LEN (&main_aux);
1156 cs->c_value + ANOFFSET (objfile->section_offsets,
1157 SECT_OFF_TEXT (objfile));
1158 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1160 if (cs->c_name && cs->c_name[0] == '.')
1162 last_csect_name = cs->c_name;
1163 last_csect_val = cs->c_value;
1164 last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
1169 /* All other symbols are put into the minimal symbol
1182 /* Ignore the symbol. */
1190 switch (CSECT_SCLAS (&main_aux))
1193 /* a function entry point. */
1194 function_entry_point:
1196 fcn_start_addr = cs->c_value;
1198 /* save the function header info, which will be used
1199 when `.bf' is seen. */
1201 fcn_aux_saved = main_aux;
1205 /* shared library function trampoline code entry point. */
1209 /* The symbols often have the same names as debug symbols for
1210 functions, and confuse lookup_symbol. */
1214 /* xlc puts each variable in a separate csect, so we get
1215 an XTY_SD for each variable. But gcc puts several
1216 variables in a csect, so that each variable only gets
1217 an XTY_LD. This will typically be XMC_RW; I suspect
1218 XMC_RO and XMC_BS might be possible too.
1219 These variables are put in the minimal symbol table
1226 /* Common symbols are put into the minimal symbol table only. */
1234 switch (cs->c_sclass)
1239 /* c_value field contains symnum of next .file entry in table
1240 or symnum of first global after last .file. */
1242 next_file_symnum = cs->c_value;
1244 /* Complete symbol table for last object file containing
1245 debugging information. */
1247 /* Whether or not there was a csect in the previous file, we
1248 have to call `end_stabs' and `start_stabs' to reset
1249 type_vector, line_vector, etc. structures. */
1251 complete_symtab (filestring, file_start_addr);
1252 cur_src_end_addr = file_end_addr;
1253 end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1256 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1257 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1258 standard COFF way and put it in the auxent. We use the auxent if
1259 the symbol is ".file" and an auxent exists, otherwise use the symbol
1260 itself. Simple enough. */
1261 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1263 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1264 0, cs->c_naux, &main_aux);
1265 filestring = coff_getfilename (&main_aux, objfile);
1268 filestring = cs->c_name;
1271 start_symtab (filestring, (char *) NULL, (CORE_ADDR) 0);
1272 record_debugformat (debugfmt);
1273 last_csect_name = 0;
1275 /* reset file start and end addresses. A compilation unit with no text
1276 (only data) should have zero file boundaries. */
1277 file_start_addr = file_end_addr = 0;
1281 fcn_stab_saved = *cs;
1285 if (STREQ (cs->c_name, ".bf"))
1287 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1288 SECT_OFF_TEXT (objfile));
1289 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1290 0, cs->c_naux, &main_aux);
1292 within_function = 1;
1294 new = push_context (0, fcn_start_addr + off);
1296 new->name = define_symbol
1297 (fcn_cs_saved.c_value + off,
1298 fcn_stab_saved.c_name, 0, 0, objfile);
1299 if (new->name != NULL)
1300 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT (objfile);
1302 else if (STREQ (cs->c_name, ".ef"))
1305 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1306 0, cs->c_naux, &main_aux);
1308 /* The value of .ef is the address of epilogue code;
1309 not useful for gdb. */
1310 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1311 contains number of lines to '}' */
1313 if (context_stack_depth <= 0)
1314 { /* We attempted to pop an empty context stack */
1315 complain (&ef_complaint, cs->c_symnum);
1316 within_function = 0;
1319 new = pop_context ();
1320 /* Stack must be empty now. */
1321 if (context_stack_depth > 0 || new == NULL)
1323 complain (&ef_complaint, cs->c_symnum);
1324 within_function = 0;
1328 finish_block (new->name, &local_symbols, new->old_blocks,
1330 (fcn_cs_saved.c_value
1331 + fcn_aux_saved.x_sym.x_misc.x_fsize
1332 + ANOFFSET (objfile->section_offsets,
1333 SECT_OFF_TEXT (objfile))),
1335 within_function = 0;
1340 /* Begin static block. */
1342 struct internal_syment symbol;
1344 read_symbol (&symbol, cs->c_value);
1345 static_block_base = symbol.n_value;
1346 static_block_section =
1347 secnum_to_section (symbol.n_scnum, objfile);
1352 /* End of static block. */
1353 static_block_base = 0;
1354 static_block_section = -1;
1365 static struct complaint msg =
1366 {"Unrecognized storage class %d.", 0, 0};
1367 complain (&msg, cs->c_sclass);
1381 /* beginning of include file */
1382 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1383 order. Thus, when wee see them, we might not know enough info
1384 to process them. Thus, we'll be saving them into a table
1385 (inclTable) and postpone their processing. */
1387 record_include_begin (cs);
1391 /* End of include file. */
1392 /* See the comment after case C_BINCL. */
1393 record_include_end (cs);
1397 if (STREQ (cs->c_name, ".bb"))
1400 new = push_context (depth,
1402 + ANOFFSET (objfile->section_offsets,
1403 SECT_OFF_TEXT (objfile))));
1405 else if (STREQ (cs->c_name, ".eb"))
1407 if (context_stack_depth <= 0)
1408 { /* We attempted to pop an empty context stack */
1409 complain (&eb_complaint, cs->c_symnum);
1412 new = pop_context ();
1413 if (depth-- != new->depth)
1415 complain (&eb_complaint, cs->c_symnum);
1418 if (local_symbols && context_stack_depth > 0)
1420 /* Make a block for the local symbols within. */
1421 finish_block (new->name, &local_symbols, new->old_blocks,
1424 + ANOFFSET (objfile->section_offsets,
1425 SECT_OFF_TEXT (objfile))),
1428 local_symbols = new->locals;
1433 process_xcoff_symbol (cs, objfile);
1438 if (last_source_file)
1442 complete_symtab (filestring, file_start_addr);
1443 cur_src_end_addr = file_end_addr;
1444 s = end_symtab (file_end_addr, objfile, SECT_OFF_TEXT (objfile));
1445 /* When reading symbols for the last C_FILE of the objfile, try
1446 to make sure that we set pst->symtab to the symtab for the
1447 file, not to the _globals_ symtab. I'm not sure whether this
1448 actually works right or when/if it comes up. */
1449 if (pst->symtab == NULL)
1455 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1456 (SYMBOL2) = (struct symbol *) \
1457 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1458 *(SYMBOL2) = *(SYMBOL1);
1461 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1462 (ALLOCED) ? (NAME) : obsavestring ((NAME), strlen (NAME), &objfile->symbol_obstack);
1465 static struct type *func_symbol_type;
1466 static struct type *var_symbol_type;
1468 /* process one xcoff symbol. */
1470 static struct symbol *
1471 process_xcoff_symbol (register struct coff_symbol *cs, struct objfile *objfile)
1473 struct symbol onesymbol;
1474 register struct symbol *sym = &onesymbol;
1475 struct symbol *sym2 = NULL;
1481 if (cs->c_secnum < 0)
1483 /* The value is a register number, offset within a frame, etc.,
1484 and does not get relocated. */
1490 sec = secnum_to_section (cs->c_secnum, objfile);
1491 off = ANOFFSET (objfile->section_offsets, sec);
1498 memset (sym, '\0', sizeof (struct symbol));
1500 /* default assumptions */
1501 SYMBOL_VALUE_ADDRESS (sym) = cs->c_value + off;
1502 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1503 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1505 if (ISFCN (cs->c_type))
1507 /* At this point, we don't know the type of the function. This
1508 will be patched with the type from its stab entry later on in
1509 patch_block_stabs (), unless the file was compiled without -g. */
1511 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1512 SYMBOL_TYPE (sym) = func_symbol_type;
1514 SYMBOL_CLASS (sym) = LOC_BLOCK;
1515 SYMBOL_DUP (sym, sym2);
1517 if (cs->c_sclass == C_EXT)
1518 add_symbol_to_list (sym2, &global_symbols);
1519 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1520 add_symbol_to_list (sym2, &file_symbols);
1524 /* In case we can't figure out the type, provide default. */
1525 SYMBOL_TYPE (sym) = var_symbol_type;
1527 switch (cs->c_sclass)
1530 /* The values of functions and global symbols are now resolved
1531 via the global_sym_chain in stabsread.c. */
1533 if (fcn_cs_saved.c_sclass == C_EXT)
1534 add_stab_to_list (name, &global_stabs);
1536 add_stab_to_list (name, &file_stabs);
1540 add_stab_to_list (name, &global_stabs);
1545 common_block_start (cs->c_name, objfile);
1549 common_block_end (objfile);
1553 complain (&storclass_complaint, cs->c_sclass);
1565 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1568 SYMBOL_SECTION (sym) = sec;
1575 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1576 all statics and we need to distinguish file-scope versus
1577 function-scope using within_function. We do this by
1578 changing the string we pass to define_symbol to use 'S'
1579 where we need to, which is not necessarily super-clean,
1580 but seems workable enough. */
1582 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1586 if (*pp == 'V' && !within_function)
1588 sym = define_symbol ((cs->c_value
1589 + ANOFFSET (objfile->section_offsets,
1590 static_block_section)),
1591 cs->c_name, 0, 0, objfile);
1594 SYMBOL_VALUE_ADDRESS (sym) += static_block_base;
1595 SYMBOL_SECTION (sym) = static_block_section;
1604 /* Extract the file name from the aux entry of a C_FILE symbol.
1605 Result is in static storage and is only good for temporary use. */
1608 coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile)
1610 static char buffer[BUFSIZ];
1612 if (aux_entry->x_file.x_n.x_zeroes == 0)
1614 ((struct coff_symfile_info *) objfile->sym_private)->strtbl
1615 + aux_entry->x_file.x_n.x_offset);
1618 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1619 buffer[FILNMLEN] = '\0';
1624 /* Set *SYMBOL to symbol number symno in symtbl. */
1626 read_symbol (struct internal_syment *symbol, int symno)
1629 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
1632 ((struct coff_symfile_info *) this_symtab_psymtab->objfile->sym_private)
1634 if (symno < 0 || symno >= nsyms)
1636 static struct complaint msg =
1637 {"Invalid symbol offset", 0, 0};
1639 symbol->n_value = 0;
1640 symbol->n_scnum = -1;
1643 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1644 stbl + (symno * local_symesz),
1648 /* Get value corresponding to symbol number symno in symtbl. */
1651 read_symbol_nvalue (int symno)
1653 struct internal_syment symbol[1];
1655 read_symbol (symbol, symno);
1656 return symbol->n_value;
1660 /* Find the address of the function corresponding to symno, where
1661 symno is the symbol pointed to by the linetable. */
1664 read_symbol_lineno (int symno)
1666 struct objfile *objfile = this_symtab_psymtab->objfile;
1667 boolean xcoff64 = xcoff_data (objfile->obfd)->xcoff64;
1669 struct coff_symfile_info *info =
1670 (struct coff_symfile_info *)objfile->sym_private;
1671 int nsyms = info->symtbl_num_syms;
1672 char *stbl = info->symtbl;
1673 char *strtbl = info->strtbl;
1675 struct internal_syment symbol[1];
1676 union internal_auxent main_aux[1];
1680 complain (&bf_notfound_complaint);
1684 /* Note that just searching for a short distance (e.g. 50 symbols)
1685 is not enough, at least in the following case.
1688 [many .stabx entries]
1689 [a few functions, referring to foo]
1693 What happens here is that the assembler moves the .stabx entries
1694 to right before the ".bf" for foo, but the symbol for "foo" is before
1695 all the stabx entries. See PR gdb/2222. */
1697 /* Maintaining a table of .bf entries might be preferable to this search.
1698 If I understand things correctly it would need to be done only for
1699 the duration of a single psymtab to symtab conversion. */
1700 while (symno < nsyms)
1702 bfd_coff_swap_sym_in (symfile_bfd,
1703 stbl + (symno * local_symesz), symbol);
1704 if (symbol->n_sclass == C_FCN)
1706 char *name = xcoff64 ? strtbl + symbol->n_offset : symbol->n_name;
1707 if (STREQ (name, ".bf"))
1710 symno += symbol->n_numaux + 1;
1713 complain (&bf_notfound_complaint);
1717 /* take aux entry and return its lineno */
1719 bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
1720 symbol->n_type, symbol->n_sclass,
1721 0, symbol->n_numaux, main_aux);
1723 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1726 /* Support for line number handling */
1728 /* This function is called for every section; it finds the outer limits
1729 * of the line table (minimum and maximum file offset) so that the
1730 * mainline code can read the whole thing for efficiency.
1733 find_linenos (bfd *abfd, sec_ptr asect, PTR vpinfo)
1735 struct coff_symfile_info *info;
1737 file_ptr offset, maxoff;
1739 count = asect->lineno_count;
1741 if (!STREQ (asect->name, ".text") || count == 0)
1744 size = count * coff_data (abfd)->local_linesz;
1745 info = (struct coff_symfile_info *) vpinfo;
1746 offset = asect->line_filepos;
1747 maxoff = offset + size;
1749 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1750 info->min_lineno_offset = offset;
1752 if (maxoff > info->max_lineno_offset)
1753 info->max_lineno_offset = maxoff;
1756 static void xcoff_psymtab_to_symtab_1 (struct partial_symtab *);
1759 xcoff_psymtab_to_symtab_1 (struct partial_symtab *pst)
1761 struct cleanup *old_chain;
1770 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1775 /* Read in all partial symtabs on which this one is dependent */
1776 for (i = 0; i < pst->number_of_dependencies; i++)
1777 if (!pst->dependencies[i]->readin)
1779 /* Inform about additional files that need to be read in. */
1782 fputs_filtered (" ", gdb_stdout);
1784 fputs_filtered ("and ", gdb_stdout);
1786 printf_filtered ("%s...", pst->dependencies[i]->filename);
1787 wrap_here (""); /* Flush output */
1788 gdb_flush (gdb_stdout);
1790 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
1793 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
1795 /* Init stuff necessary for reading in symbols. */
1798 old_chain = make_cleanup (really_free_pendings, 0);
1800 read_xcoff_symtab (pst);
1801 sort_symtab_syms (pst->symtab);
1803 do_cleanups (old_chain);
1809 static void xcoff_psymtab_to_symtab (struct partial_symtab *);
1811 /* Read in all of the symbols for a given psymtab for real.
1812 Be verbose about it if the user wants that. */
1815 xcoff_psymtab_to_symtab (struct partial_symtab *pst)
1825 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1830 if (((struct symloc *) pst->read_symtab_private)->numsyms != 0
1831 || pst->number_of_dependencies)
1833 /* Print the message now, before reading the string table,
1834 to avoid disconcerting pauses. */
1837 printf_filtered ("Reading in symbols for %s...", pst->filename);
1838 gdb_flush (gdb_stdout);
1841 sym_bfd = pst->objfile->obfd;
1843 next_symbol_text_func = xcoff_next_symbol_text;
1845 xcoff_psymtab_to_symtab_1 (pst);
1847 /* Match with global symbols. This only needs to be done once,
1848 after all of the symtabs and dependencies have been read in. */
1849 scan_file_globals (pst->objfile);
1851 /* Finish up the debug error message. */
1853 printf_filtered ("done.\n");
1858 xcoff_new_init (struct objfile *objfile)
1860 stabsread_new_init ();
1861 buildsym_new_init ();
1864 /* Do initialization in preparation for reading symbols from OBJFILE.
1866 We will only be called if this is an XCOFF or XCOFF-like file.
1867 BFD handles figuring out the format of the file, and code in symfile.c
1868 uses BFD's determination to vector to us. */
1871 xcoff_symfile_init (struct objfile *objfile)
1873 /* Allocate struct to keep track of the symfile */
1874 objfile->sym_private = xmmalloc (objfile->md,
1875 sizeof (struct coff_symfile_info));
1877 /* XCOFF objects may be reordered, so set OBJF_REORDERED. If we
1878 find this causes a significant slowdown in gdb then we could
1879 set it in the debug symbol readers only when necessary. */
1880 objfile->flags |= OBJF_REORDERED;
1882 init_entry_point_info (objfile);
1885 /* Perform any local cleanups required when we are done with a particular
1886 objfile. I.E, we are in the process of discarding all symbol information
1887 for an objfile, freeing up all memory held for it, and unlinking the
1888 objfile struct from the global list of known objfiles. */
1891 xcoff_symfile_finish (struct objfile *objfile)
1893 if (objfile->sym_private != NULL)
1895 mfree (objfile->md, objfile->sym_private);
1898 /* Start with a fresh include table for the next objfile. */
1904 inclIndx = inclLength = inclDepth = 0;
1909 init_stringtab (bfd *abfd, file_ptr offset, struct objfile *objfile)
1913 unsigned char lengthbuf[4];
1916 ((struct coff_symfile_info *) objfile->sym_private)->strtbl = NULL;
1918 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1919 error ("cannot seek to string table in %s: %s",
1920 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1922 val = bfd_read ((char *) lengthbuf, 1, sizeof lengthbuf, abfd);
1923 length = bfd_h_get_32 (abfd, lengthbuf);
1925 /* If no string table is needed, then the file may end immediately
1926 after the symbols. Just return with `strtbl' set to NULL. */
1928 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1931 /* Allocate string table from symbol_obstack. We will need this table
1932 as long as we have its symbol table around. */
1934 strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
1935 ((struct coff_symfile_info *) objfile->sym_private)->strtbl = strtbl;
1937 /* Copy length buffer, the first byte is usually zero and is
1938 used for stabs with a name length of zero. */
1939 memcpy (strtbl, lengthbuf, sizeof lengthbuf);
1940 if (length == sizeof lengthbuf)
1943 val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf,
1946 if (val != length - sizeof lengthbuf)
1947 error ("cannot read string table from %s: %s",
1948 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
1949 if (strtbl[length - 1] != '\0')
1950 error ("bad symbol file: string table does not end with null character");
1955 /* If we have not yet seen a function for this psymtab, this is 0. If we
1956 have seen one, it is the offset in the line numbers of the line numbers
1958 static unsigned int first_fun_line_offset;
1960 static struct partial_symtab *xcoff_start_psymtab
1961 (struct objfile *, char *, int,
1962 struct partial_symbol **, struct partial_symbol **);
1964 /* Allocate and partially fill a partial symtab. It will be
1965 completely filled at the end of the symbol list.
1967 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1968 is the address relative to which its symbols are (incremental) or 0
1971 static struct partial_symtab *
1972 xcoff_start_psymtab (struct objfile *objfile, char *filename, int first_symnum,
1973 struct partial_symbol **global_syms,
1974 struct partial_symbol **static_syms)
1976 struct partial_symtab *result =
1977 start_psymtab_common (objfile, objfile->section_offsets,
1979 /* We fill in textlow later. */
1981 global_syms, static_syms);
1983 result->read_symtab_private = (char *)
1984 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
1985 ((struct symloc *) result->read_symtab_private)->first_symnum = first_symnum;
1986 result->read_symtab = xcoff_psymtab_to_symtab;
1988 /* Deduce the source language from the filename for this psymtab. */
1989 psymtab_language = deduce_language_from_filename (filename);
1994 static struct partial_symtab *xcoff_end_psymtab
1995 (struct partial_symtab *, char **, int, int,
1996 struct partial_symtab **, int, int);
1998 /* Close off the current usage of PST.
1999 Returns PST, or NULL if the partial symtab was empty and thrown away.
2001 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2003 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2004 are the information for includes and dependencies. */
2006 static struct partial_symtab *
2007 xcoff_end_psymtab (struct partial_symtab *pst, char **include_list,
2008 int num_includes, int capping_symbol_number,
2009 struct partial_symtab **dependency_list,
2010 int number_dependencies, int textlow_not_set)
2013 struct objfile *objfile = pst->objfile;
2015 if (capping_symbol_number != -1)
2016 ((struct symloc *) pst->read_symtab_private)->numsyms =
2017 capping_symbol_number
2018 - ((struct symloc *) pst->read_symtab_private)->first_symnum;
2019 ((struct symloc *) pst->read_symtab_private)->lineno_off =
2020 first_fun_line_offset;
2021 first_fun_line_offset = 0;
2022 pst->n_global_syms =
2023 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2024 pst->n_static_syms =
2025 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2027 pst->number_of_dependencies = number_dependencies;
2028 if (number_dependencies)
2030 pst->dependencies = (struct partial_symtab **)
2031 obstack_alloc (&objfile->psymbol_obstack,
2032 number_dependencies * sizeof (struct partial_symtab *));
2033 memcpy (pst->dependencies, dependency_list,
2034 number_dependencies * sizeof (struct partial_symtab *));
2037 pst->dependencies = 0;
2039 for (i = 0; i < num_includes; i++)
2041 struct partial_symtab *subpst =
2042 allocate_psymtab (include_list[i], objfile);
2044 subpst->section_offsets = pst->section_offsets;
2045 subpst->read_symtab_private =
2046 (char *) obstack_alloc (&objfile->psymbol_obstack,
2047 sizeof (struct symloc));
2048 ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
2049 ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
2050 subpst->textlow = 0;
2051 subpst->texthigh = 0;
2053 /* We could save slight bits of space by only making one of these,
2054 shared by the entire set of include files. FIXME-someday. */
2055 subpst->dependencies = (struct partial_symtab **)
2056 obstack_alloc (&objfile->psymbol_obstack,
2057 sizeof (struct partial_symtab *));
2058 subpst->dependencies[0] = pst;
2059 subpst->number_of_dependencies = 1;
2061 subpst->globals_offset =
2062 subpst->n_global_syms =
2063 subpst->statics_offset =
2064 subpst->n_static_syms = 0;
2068 subpst->read_symtab = pst->read_symtab;
2071 sort_pst_symbols (pst);
2073 /* If there is already a psymtab or symtab for a file of this name,
2074 remove it. (If there is a symtab, more drastic things also
2075 happen.) This happens in VxWorks. */
2076 free_named_symtabs (pst->filename);
2078 if (num_includes == 0
2079 && number_dependencies == 0
2080 && pst->n_global_syms == 0
2081 && pst->n_static_syms == 0)
2083 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2084 it is on the obstack, but we can forget to chain it on the list. */
2085 /* Empty psymtabs happen as a result of header files which don't have
2086 any symbols in them. There can be a lot of them. */
2088 discard_psymtab (pst);
2090 /* Indicate that psymtab was thrown away. */
2091 pst = (struct partial_symtab *) NULL;
2096 static void swap_sym (struct internal_syment *,
2097 union internal_auxent *, char **, char **,
2098 unsigned int *, struct objfile *);
2100 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2101 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2102 the symbol and its auxents. */
2105 swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
2106 char **name, char **raw, unsigned int *symnump,
2107 struct objfile *objfile)
2109 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2110 if (symbol->n_zeroes)
2112 /* If it's exactly E_SYMNMLEN characters long it isn't
2114 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2116 /* FIXME: wastes memory for symbols which we don't end up putting
2117 into the minimal symbols. */
2119 p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2120 strncpy (p, symbol->n_name, E_SYMNMLEN);
2121 p[E_SYMNMLEN] = '\0';
2125 /* Point to the unswapped name as that persists as long as the
2127 *name = ((struct external_syment *) *raw)->e.e_name;
2129 else if (symbol->n_sclass & 0x80)
2131 *name = ((struct coff_symfile_info *) objfile->sym_private)->debugsec
2136 *name = ((struct coff_symfile_info *) objfile->sym_private)->strtbl
2140 *raw += coff_data (objfile->obfd)->local_symesz;
2141 if (symbol->n_numaux > 0)
2143 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2144 symbol->n_sclass, 0, symbol->n_numaux, aux);
2146 *symnump += symbol->n_numaux;
2147 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2152 scan_xcoff_symtab (struct objfile *objfile)
2154 CORE_ADDR toc_offset = 0; /* toc offset value in data section. */
2155 char *filestring = NULL;
2158 int past_first_source_file = 0;
2163 /* Current partial symtab */
2164 struct partial_symtab *pst;
2166 /* List of current psymtab's include files */
2167 char **psymtab_include_list;
2168 int includes_allocated;
2171 /* Index within current psymtab dependency list */
2172 struct partial_symtab **dependency_list;
2173 int dependencies_used, dependencies_allocated;
2176 struct internal_syment symbol;
2177 union internal_auxent main_aux[5];
2178 unsigned int ssymnum;
2180 char *last_csect_name = NULL; /* last seen csect's name and value */
2181 CORE_ADDR last_csect_val = 0;
2182 int last_csect_sec = 0;
2183 int misc_func_recorded = 0; /* true if any misc. function */
2184 int textlow_not_set = 1;
2186 pst = (struct partial_symtab *) 0;
2188 includes_allocated = 30;
2190 psymtab_include_list = (char **) alloca (includes_allocated *
2193 dependencies_allocated = 30;
2194 dependencies_used = 0;
2196 (struct partial_symtab **) alloca (dependencies_allocated *
2197 sizeof (struct partial_symtab *));
2199 last_source_file = NULL;
2201 abfd = objfile->obfd;
2203 sraw_symbol = ((struct coff_symfile_info *) objfile->sym_private)->symtbl;
2204 nsyms = ((struct coff_symfile_info *) objfile->sym_private)->symtbl_num_syms;
2206 while (ssymnum < nsyms)
2209 /* This is the type we pass to partial-stab.h. A less kludgy solution
2210 would be to break out partial-stab.h into its various parts--shuffle
2211 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2212 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2217 bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol);
2218 sclass = symbol.n_sclass;
2225 /* The CSECT auxent--always the last auxent. */
2226 union internal_auxent csect_aux;
2227 unsigned int symnum_before = ssymnum;
2229 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2231 if (symbol.n_numaux > 1)
2233 bfd_coff_swap_aux_in
2235 sraw_symbol - coff_data (abfd)->local_symesz,
2238 symbol.n_numaux - 1,
2243 csect_aux = main_aux[0];
2245 /* If symbol name starts with ".$" or "$", ignore it. */
2246 if (namestring[0] == '$'
2247 || (namestring[0] == '.' && namestring[1] == '$'))
2250 switch (csect_aux.x_csect.x_smtyp & 0x7)
2253 switch (csect_aux.x_csect.x_smclas)
2256 if (last_csect_name)
2258 /* If no misc. function recorded in the last
2259 seen csect, enter it as a function. This
2260 will take care of functions like strcmp()
2263 if (!misc_func_recorded)
2265 RECORD_MINIMAL_SYMBOL
2266 (last_csect_name, last_csect_val,
2267 mst_text, last_csect_sec,
2273 /* We have to allocate one psymtab for
2274 each program csect, because their text
2275 sections need not be adjacent. */
2277 (pst, psymtab_include_list, includes_used,
2278 symnum_before, dependency_list,
2279 dependencies_used, textlow_not_set);
2281 dependencies_used = 0;
2282 /* Give all psymtabs for this source file the same
2284 pst = xcoff_start_psymtab
2288 objfile->global_psymbols.next,
2289 objfile->static_psymbols.next);
2292 if (namestring && namestring[0] == '.')
2294 last_csect_name = namestring;
2295 last_csect_val = symbol.n_value;
2297 secnum_to_section (symbol.n_scnum, objfile);
2302 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2303 if (highval > pst->texthigh)
2304 pst->texthigh = highval;
2305 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2306 pst->textlow = symbol.n_value;
2308 misc_func_recorded = 0;
2312 /* Data variables are recorded in the minimal symbol
2313 table, except for section symbols. */
2314 if (*namestring != '.')
2315 prim_record_minimal_symbol_and_info
2316 (namestring, symbol.n_value,
2317 sclass == C_HIDEXT ? mst_file_data : mst_data,
2318 NULL, secnum_to_section (symbol.n_scnum, objfile),
2324 warning ("More than one XMC_TC0 symbol found.");
2325 toc_offset = symbol.n_value;
2327 /* Make TOC offset relative to start address of section. */
2328 bfd_sect = secnum_to_bfd_section (symbol.n_scnum, objfile);
2330 toc_offset -= bfd_section_vma (objfile->obfd, bfd_sect);
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[0].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[0], &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[0], objfile);
2463 filestring = namestring;
2465 pst = xcoff_start_psymtab (objfile,
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. */
2527 int naux1 = symbol.n_numaux + 1;
2529 sraw_symbol += bfd_coff_symesz (abfd) * naux1;
2538 /* The value of the C_FUN is not the address of the function (it
2539 appears to be the address before linking), but as long as it
2540 is smaller than the actual address, then find_pc_partial_function
2541 will use the minimal symbols instead. I hope. */
2549 swap_sym (&symbol, &main_aux[0], &namestring, &sraw_symbol,
2551 #define CUR_SYMBOL_TYPE stype
2552 #define CUR_SYMBOL_VALUE symbol.n_value
2554 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2555 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2557 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms) 0
2558 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set)\
2560 /* We have already set the namestring. */
2561 #define SET_NAMESTRING() /* */
2563 #include "partial-stab.h"
2569 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2570 ssymnum, dependency_list,
2571 dependencies_used, textlow_not_set);
2574 /* Record the toc offset value of this symbol table into objfile structure.
2575 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2576 this information would be file auxiliary header. */
2578 ((struct coff_symfile_info *) objfile->sym_private)->toc_offset = toc_offset;
2581 /* Return the toc offset value for a given objfile. */
2584 get_toc_offset (struct objfile *objfile)
2587 return ((struct coff_symfile_info *) objfile->sym_private)->toc_offset;
2591 /* Scan and build partial symbols for a symbol file.
2592 We have been initialized by a call to dbx_symfile_init, which
2593 put all the relevant info into a "struct dbx_symfile_info",
2594 hung off the objfile structure.
2596 SECTION_OFFSETS contains offsets relative to which the symbols in the
2597 various sections are (depending where the sections were actually loaded).
2598 MAINLINE is true if we are reading the main symbol
2599 table (as opposed to a shared lib or dynamically loaded file). */
2602 xcoff_initial_scan (struct objfile *objfile, int mainline)
2606 struct cleanup *back_to;
2607 int num_symbols; /* # of symbols */
2608 file_ptr symtab_offset; /* symbol table and */
2609 file_ptr stringtab_offset; /* string table file offsets */
2610 struct coff_symfile_info *info;
2614 info = (struct coff_symfile_info *) objfile->sym_private;
2615 symfile_bfd = abfd = objfile->obfd;
2616 name = objfile->name;
2618 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2619 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2620 stringtab_offset = symtab_offset +
2621 num_symbols * coff_data (abfd)->local_symesz;
2623 info->min_lineno_offset = 0;
2624 info->max_lineno_offset = 0;
2625 bfd_map_over_sections (abfd, find_linenos, info);
2627 if (num_symbols > 0)
2629 /* Read the string table. */
2630 init_stringtab (abfd, stringtab_offset, objfile);
2632 /* Read the .debug section, if present. */
2635 bfd_size_type length;
2636 char *debugsec = NULL;
2638 secp = bfd_get_section_by_name (abfd, ".debug");
2641 length = bfd_section_size (abfd, secp);
2645 (char *) obstack_alloc (&objfile->symbol_obstack, length);
2647 if (!bfd_get_section_contents (abfd, secp, debugsec,
2648 (file_ptr) 0, length))
2650 error ("Error reading .debug section of `%s': %s",
2651 name, bfd_errmsg (bfd_get_error ()));
2655 ((struct coff_symfile_info *) objfile->sym_private)->debugsec =
2660 /* Read the symbols. We keep them in core because we will want to
2661 access them randomly in read_symbol*. */
2662 val = bfd_seek (abfd, symtab_offset, SEEK_SET);
2664 error ("Error reading symbols from %s: %s",
2665 name, bfd_errmsg (bfd_get_error ()));
2666 size = coff_data (abfd)->local_symesz * num_symbols;
2667 ((struct coff_symfile_info *) objfile->sym_private)->symtbl =
2668 obstack_alloc (&objfile->symbol_obstack, size);
2669 ((struct coff_symfile_info *) objfile->sym_private)->symtbl_num_syms =
2672 val = bfd_read (((struct coff_symfile_info *) objfile->sym_private)->symtbl,
2675 perror_with_name ("reading symbol table");
2677 /* If we are reinitializing, or if we have never loaded syms yet, init */
2679 || objfile->global_psymbols.size == 0
2680 || objfile->static_psymbols.size == 0)
2681 /* I'm not sure how how good num_symbols is; the rule of thumb in
2682 init_psymbol_list was developed for a.out. On the one hand,
2683 num_symbols includes auxents. On the other hand, it doesn't
2685 init_psymbol_list (objfile, num_symbols);
2687 free_pending_blocks ();
2688 back_to = make_cleanup (really_free_pendings, 0);
2690 init_minimal_symbol_collection ();
2691 make_cleanup_discard_minimal_symbols ();
2693 /* Now that the symbol table data of the executable file are all in core,
2694 process them and define symbols accordingly. */
2696 scan_xcoff_symtab (objfile);
2698 /* Install any minimal symbols that have been collected as the current
2699 minimal symbols for this objfile. */
2701 install_minimal_symbols (objfile);
2703 do_cleanups (back_to);
2707 xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
2709 asection *sect = NULL;
2712 objfile->num_sections = SECT_OFF_MAX;
2713 objfile->section_offsets = (struct section_offsets *)
2714 obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
2716 /* Initialize the section indexes for future use. */
2717 sect = bfd_get_section_by_name (objfile->obfd, ".text");
2719 objfile->sect_index_text = sect->index;
2721 sect = bfd_get_section_by_name (objfile->obfd, ".data");
2723 objfile->sect_index_data = sect->index;
2725 sect = bfd_get_section_by_name (objfile->obfd, ".bss");
2727 objfile->sect_index_bss = sect->index;
2729 sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
2731 objfile->sect_index_rodata = sect->index;
2733 for (i = 0; i < objfile->num_sections; ++i)
2735 /* syms_from_objfile kindly subtracts from addr the
2736 bfd_section_vma of the .text section. This strikes me as
2737 wrong--whether the offset to be applied to symbol reading is
2738 relative to the start address of the section depends on the
2739 symbol format. In any event, this whole "addr" concept is
2740 pretty broken (it doesn't handle any section but .text
2741 sensibly), so just ignore the addr parameter and use 0.
2742 rs6000-nat.c will set the correct section offsets via
2743 objfile_relocate. */
2744 (objfile->section_offsets)->offsets[i] = 0;
2748 /* Register our ability to parse symbols for xcoff BFD files. */
2750 static struct sym_fns xcoff_sym_fns =
2753 /* It is possible that coff and xcoff should be merged as
2754 they do have fundamental similarities (for example, the extra storage
2755 classes used for stabs could presumably be recognized in any COFF file).
2756 However, in addition to obvious things like all the csect hair, there are
2757 some subtler differences between xcoffread.c and coffread.c, notably
2758 the fact that coffread.c has no need to read in all the symbols, but
2759 xcoffread.c reads all the symbols and does in fact randomly access them
2760 (in C_BSTAT and line number processing). */
2762 bfd_target_xcoff_flavour,
2764 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2765 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2766 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
2767 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2768 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
2769 NULL /* next: pointer to next struct sym_fns */
2773 _initialize_xcoffread (void)
2775 add_symtab_fns (&xcoff_sym_fns);
2777 func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
2778 "<function, no debug info>", NULL);
2779 TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
2781 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
2782 "<variable, no debug info>", NULL);