1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Native only: Need struct tbtable in <sys/debug.h> from host, and
24 need xcoff_add_toc_to_loadinfo in rs6000-tdep.c from target.
25 need xcoff_init_loadinfo ditto.
26 However, if you grab <sys/debug.h> and make it available on your
27 host, and define FAKING_RS6000, then this code will compile. */
32 #include <sys/types.h>
37 #include <sys/param.h>
42 #include <sys/debug.h>
49 #include "stabsread.h"
50 #include "complaints.h"
52 #include "coff/internal.h" /* FIXME, internal data from BFD */
53 #include "libcoff.h" /* FIXME, internal data from BFD */
54 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
56 /* For interface with stabsread.c. */
57 #include "aout/stab_gnu.h"
59 /* Simplified internal version of coff symbol table information */
63 int c_symnum; /* symbol number of this entry */
64 int c_nsyms; /* 0 if syment only, 1 if syment + auxent */
66 unsigned char c_sclass;
71 /* The COFF line table, in raw form. */
72 static char *linetab = NULL; /* Its actual contents */
73 static long linetab_offset; /* Its offset in the file */
74 static unsigned long linetab_size; /* Its size */
76 /* last function's saved coff symbol `cs' */
78 static struct coff_symbol fcn_cs_saved;
80 static bfd *symfile_bfd;
82 /* Core address of start and end of text of current source file.
83 This is calculated from the first function seen after a C_FILE
87 static CORE_ADDR cur_src_end_addr;
89 /* Core address of the end of the first object file. */
91 static CORE_ADDR first_object_file_end;
93 /* pointer to the string table */
96 /* length of the string table */
97 static int strtbl_len;
99 /* pointer to debug section */
100 static char *debugsec;
102 /* pointer to the a.out symbol table */
105 /* Number of symbols in symtbl. */
106 static int symtbl_num_syms;
108 /* initial symbol-table-debug-string vector length */
110 #define INITIAL_STABVECTOR_LENGTH 40
112 /* Nonzero if within a function (so symbols should be local,
113 if nothing says specifically). */
117 /* Local variables that hold the shift and mask values for the
118 COFF file that we are currently reading. These come back to us
119 from BFD, and are referenced by their macro names, as well as
120 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
121 macros from ../internalcoff.h . */
123 static unsigned local_n_btshft;
124 static unsigned local_n_tmask;
127 #define N_BTSHFT local_n_btshft
129 #define N_TMASK local_n_tmask
131 /* Local variables that hold the sizes in the file of various COFF structures.
132 (We only need to know this to read them from the file -- BFD will then
133 translate the data in them, into `internal_xxx' structs in the right
134 byte order, alignment, etc.) */
136 static unsigned local_symesz;
138 struct coff_symfile_info {
139 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
140 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
143 static struct complaint rsym_complaint =
144 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
146 static struct complaint storclass_complaint =
147 {"Unexpected storage class: %d", 0, 0};
149 static struct complaint bf_notfound_complaint =
150 {"line numbers off, `.bf' symbol not found", 0, 0};
153 enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
154 CORE_ADDR, CORE_ADDR, unsigned *));
157 free_debugsection PARAMS ((void));
160 init_debugsection PARAMS ((bfd *));
163 init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));
166 xcoff_symfile_init PARAMS ((struct objfile *));
169 xcoff_new_init PARAMS ((struct objfile *));
172 struct section_offset;
176 xcoff_symfile_read PARAMS ((struct objfile *, struct section_offset *, int));
179 xcoff_symfile_finish PARAMS ((struct objfile *));
181 static struct section_offsets *
182 xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
185 init_lineno PARAMS ((bfd *, file_ptr, int));
188 free_linetab PARAMS ((void));
191 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
194 read_symbol PARAMS ((struct internal_syment *, int));
197 read_symbol_lineno PARAMS ((int));
200 read_symbol_nvalue PARAMS ((int));
202 static struct symbol *
203 process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
206 read_xcoff_symtab PARAMS ((struct objfile *, int));
209 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
211 /* add a given stab string into given stab vector. */
214 add_stab_to_list (stabname, stabvector)
216 struct pending_stabs **stabvector;
218 if ( *stabvector == NULL) {
219 *stabvector = (struct pending_stabs *)
220 xmalloc (sizeof (struct pending_stabs) +
221 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
222 (*stabvector)->count = 0;
223 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
225 else if ((*stabvector)->count >= (*stabvector)->length) {
226 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
227 *stabvector = (struct pending_stabs *)
228 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
229 (*stabvector)->length * sizeof (char*));
231 (*stabvector)->stab [(*stabvector)->count++] = stabname;
234 /* Linenos are processed on a file-by-file basis.
238 1) xlc (IBM's native c compiler) postpones static function code
239 emission to the end of a compilation unit. This way it can
240 determine if those functions (statics) are needed or not, and
241 can do some garbage collection (I think). This makes line
242 numbers and corresponding addresses unordered, and we end up
243 with a line table like:
260 and that breaks gdb's binary search on line numbers, if the
261 above table is not sorted on line numbers. And that sort
262 should be on function based, since gcc can emit line numbers
265 10 0x100 - for the init/test part of a for stmt.
268 10 0x400 - for the increment part of a for stmt.
270 arrange_linetable() will do this sorting.
272 2) aix symbol table might look like:
274 c_file // beginning of a new file
275 .bi // beginning of include file
276 .ei // end of include file
280 basically, .bi/.ei pairs do not necessarily encapsulate
281 their scope. They need to be recorded, and processed later
282 on when we come the end of the compilation unit.
283 Include table (inclTable) and process_linenos() handle
286 /* compare line table entry addresses. */
289 compare_lte (lte1, lte2)
290 struct linetable_entry *lte1, *lte2;
292 return lte1->pc - lte2->pc;
295 /* Give a line table with function entries are marked, arrange its functions
296 in assending order and strip off function entry markers and return it in
297 a newly created table. If the old one is good enough, return the old one. */
298 /* FIXME: I think all this stuff can be replaced by just passing
299 sort_linevec = 1 to end_symtab. */
301 static struct linetable *
302 arrange_linetable (oldLineTb)
303 struct linetable *oldLineTb; /* old linetable */
306 newline, /* new line count */
307 function_count; /* # of functions */
309 struct linetable_entry *fentry; /* function entry vector */
310 int fentry_size; /* # of function entries */
311 struct linetable *newLineTb; /* new line table */
313 #define NUM_OF_FUNCTIONS 20
315 fentry_size = NUM_OF_FUNCTIONS;
316 fentry = (struct linetable_entry*)
317 xmalloc (fentry_size * sizeof (struct linetable_entry));
319 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
321 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
323 if (function_count >= fentry_size) { /* make sure you have room. */
325 fentry = (struct linetable_entry*)
326 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
328 fentry[function_count].line = ii;
329 fentry[function_count].pc = oldLineTb->item[ii].pc;
334 if (function_count == 0) {
338 else if (function_count > 1)
339 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
341 /* allocate a new line table. */
342 newLineTb = (struct linetable *)
344 (sizeof (struct linetable) +
345 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
347 /* if line table does not start with a function beginning, copy up until
351 if (oldLineTb->item[0].line != 0)
353 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
354 newLineTb->item[newline] = oldLineTb->item[newline];
356 /* Now copy function lines one by one. */
358 for (ii=0; ii < function_count; ++ii) {
359 for (jj = fentry[ii].line + 1;
360 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
362 newLineTb->item[newline] = oldLineTb->item[jj];
365 newLineTb->nitems = oldLineTb->nitems - function_count;
371 /* We try to detect the beginning of a compilation unit. That info will
372 be used as an entry in line number recording routines (enter_line_range) */
374 static unsigned first_fun_line_offset;
375 static unsigned first_fun_bf;
377 #define mark_first_line(OFFSET, SYMNUM) \
378 if (!first_fun_line_offset) { \
379 first_fun_line_offset = OFFSET; \
380 first_fun_bf = SYMNUM; \
384 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
385 following `IncludeChain'. At the end of each symtab (end_symtab),
386 we will determine if we should create additional symtab's to
387 represent if (the include files. */
390 typedef struct _inclTable {
391 char *name; /* include filename */
393 /* Offsets to the line table. end points to the last entry which is
394 part of this include file. */
397 struct subfile *subfile;
398 unsigned funStartLine; /* start line # of its function */
401 #define INITIAL_INCLUDE_TABLE_LENGTH 20
402 static InclTable *inclTable; /* global include table */
403 static int inclIndx; /* last entry to table */
404 static int inclLength; /* table length */
405 static int inclDepth; /* nested include depth */
409 record_include_begin (cs)
410 struct coff_symbol *cs;
414 /* In xcoff, we assume include files cannot be nested (not in .c files
415 of course, but in corresponding .s files.). */
417 /* This can happen with old versions of GCC.
418 GCC 2.3.3-930426 does not exhibit this on a test case which
419 a user said produced the message for him. */
420 static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
425 /* allocate an include file, or make room for the new entry */
426 if (inclLength == 0) {
427 inclTable = (InclTable*)
428 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
429 memset (inclTable, '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
430 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
433 else if (inclIndx >= inclLength) {
434 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
435 inclTable = (InclTable*)
436 xrealloc (inclTable, sizeof (InclTable) * inclLength);
437 memset (inclTable+inclLength-INITIAL_INCLUDE_TABLE_LENGTH,
438 '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
441 inclTable [inclIndx].name = cs->c_name;
442 inclTable [inclIndx].begin = cs->c_value;
447 record_include_end (cs)
448 struct coff_symbol *cs;
454 static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
458 pTbl = &inclTable [inclIndx];
459 pTbl->end = cs->c_value;
466 /* given the start and end addresses of a compilation unit (or a csect, at times)
467 process its lines and create appropriate line vectors. */
470 process_linenos (start, end)
471 CORE_ADDR start, end;
476 struct subfile main_subfile; /* subfile structure for the main
479 /* in the main source file, any time we see a function entry, we reset
480 this variable to function's absolute starting line number. All the
481 following line numbers in the function are relative to this, and
482 we record absolute line numbers in record_line(). */
484 int main_source_baseline = 0;
490 if (!(offset = first_fun_line_offset))
491 goto return_after_cleanup;
493 memset (&main_subfile, '\0', sizeof (main_subfile));
494 first_fun_line_offset = 0;
497 /* All source lines were in the main source file. None in include files. */
499 enter_line_range (&main_subfile, offset, 0, start, end,
500 &main_source_baseline);
502 /* else, there was source with line numbers in include files */
505 main_source_baseline = 0;
506 for (ii=0; ii < inclIndx; ++ii) {
508 struct subfile *tmpSubfile;
510 /* if there is main file source before include file, enter it. */
511 if (offset < inclTable[ii].begin) {
513 (&main_subfile, offset, inclTable[ii].begin - LINESZ, start, 0,
514 &main_source_baseline);
517 /* Have a new subfile for the include file */
519 tmpSubfile = inclTable[ii].subfile = (struct subfile*)
520 xmalloc (sizeof (struct subfile));
522 memset (tmpSubfile, '\0', sizeof (struct subfile));
523 firstLine = &(inclTable[ii].funStartLine);
525 /* enter include file's lines now. */
526 enter_line_range (tmpSubfile, inclTable[ii].begin,
527 inclTable[ii].end, start, 0, firstLine);
529 offset = inclTable[ii].end + LINESZ;
532 /* all the include files' line have been processed at this point. Now,
533 enter remaining lines of the main file, if any left. */
534 if (offset < (linetab_offset + linetab_size + 1 - LINESZ)) {
535 enter_line_range (&main_subfile, offset, 0, start, end,
536 &main_source_baseline);
540 /* Process main file's line numbers. */
541 if (main_subfile.line_vector) {
542 struct linetable *lineTb, *lv;
544 lv = main_subfile.line_vector;
546 /* Line numbers are not necessarily ordered. xlc compilation will
547 put static function to the end. */
549 lineTb = arrange_linetable (lv);
551 current_subfile->line_vector = (struct linetable *)
552 xrealloc (lv, (sizeof (struct linetable)
553 + lv->nitems * sizeof (struct linetable_entry)));
558 current_subfile->line_vector = lineTb;
561 current_subfile->line_vector_length =
562 current_subfile->line_vector->nitems;
565 /* Now, process included files' line numbers. */
567 for (ii=0; ii < inclIndx; ++ii) {
569 if ( (inclTable[ii].subfile)->line_vector) { /* Useless if!!! FIXMEmgo */
570 struct linetable *lineTb, *lv;
572 lv = (inclTable[ii].subfile)->line_vector;
574 /* Line numbers are not necessarily ordered. xlc compilation will
575 put static function to the end. */
577 lineTb = arrange_linetable (lv);
581 /* For the same include file, we might want to have more than one subfile.
582 This happens if we have something like:
590 while foo.h including code in it. (stupid but possible)
591 Since start_subfile() looks at the name and uses an existing one if finds,
592 we need to provide a fake name and fool it. */
594 /* start_subfile (inclTable[ii].name, (char*)0); */
595 start_subfile (" ?", (char*)0);
596 free (current_subfile->name);
597 current_subfile->name = strdup (inclTable[ii].name);
600 current_subfile->line_vector = (struct linetable *)
601 xrealloc (lv, (sizeof (struct linetable)
602 + lv->nitems * sizeof (struct linetable_entry)));
607 current_subfile->line_vector = lineTb;
610 current_subfile->line_vector_length =
611 current_subfile->line_vector->nitems;
612 start_subfile (pop_subfile (), (char*)0);
616 return_after_cleanup:
618 /* We don't want to keep alloc/free'ing the global include file table. */
621 /* start with a fresh subfile structure for the next file. */
622 memset (&main_subfile, '\0', sizeof (struct subfile));
626 aix_process_linenos ()
628 /* process line numbers and enter them into line vector */
629 process_linenos (last_source_start_addr, cur_src_end_addr);
633 /* Enter a given range of lines into the line vector.
634 can be called in the following two ways:
635 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
636 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
638 endoffset points to the last line table entry that we should pay
642 enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr, firstLine)
643 struct subfile *subfile;
644 unsigned beginoffset, endoffset; /* offsets to line table */
645 CORE_ADDR startaddr, endaddr;
651 /* Do Byte swapping, if needed. FIXME! */
652 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
653 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
654 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
656 pp = &linetab [beginoffset - linetab_offset];
657 if (endoffset != 0 && endoffset - linetab_offset >= linetab_size)
659 static struct complaint msg =
660 {"Bad line table offset in C_EINCL directive", 0, 0};
664 limit = endoffset ? &linetab [endoffset - linetab_offset]
665 : &linetab [linetab_size -1];
667 while (pp <= limit) {
669 /* find the address this line represents */
670 addr = P_LINENO(pp) ?
671 P_LINEADDR(pp) : read_symbol_nvalue (P_LINESYM(pp));
673 if (addr < startaddr || (endaddr && addr >= endaddr))
676 if (P_LINENO(pp) == 0) {
677 *firstLine = read_symbol_lineno (P_LINESYM(pp));
678 record_line (subfile, 0, addr);
682 record_line (subfile, *firstLine + P_LINENO(pp), addr);
689 int fsize; /* file size */
690 int fixedparms; /* number of fixed parms */
691 int floatparms; /* number of float parms */
692 unsigned int parminfo; /* parameter info.
693 See /usr/include/sys/debug.h
694 tbtable_ext.parminfo */
695 int framesize; /* function frame size */
699 /* Given a function symbol, return its traceback information. */
702 retrieve_tracebackinfo (abfd, textsec, cs)
705 struct coff_symbol *cs;
707 #define TBTABLE_BUFSIZ 2000
709 static TracebackInfo tbInfo;
712 static char buffer [TBTABLE_BUFSIZ];
715 int bytesread=0; /* total # of bytes read so far */
716 int bufferbytes; /* number of bytes in the buffer */
718 int functionstart = cs->c_value - textsec->vma;
720 memset (&tbInfo, '\0', sizeof (tbInfo));
722 /* keep reading blocks of data from the text section, until finding a zero
723 word and a traceback table. */
725 /* Note: The logical thing way to write this code would be to assign
726 to bufferbytes within the while condition. But that triggers a
727 compiler (xlc in AIX 3.2) bug, so simplify it... */
729 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
730 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
732 && (bfd_get_section_contents
733 (abfd, textsec, buffer,
734 (file_ptr)(functionstart + bytesread), bufferbytes)))
736 bytesread += bufferbytes;
737 pinsn = (int*) buffer;
739 /* if this is the first time we filled the buffer, retrieve function
742 if (bytesread == bufferbytes) {
744 /* skip over unrelated instructions */
746 if (*pinsn == 0x7c0802a6) /* mflr r0 */
748 if ((*pinsn & 0xfc00003e) == 0x7c000026) /* mfcr Rx */
750 if ((*pinsn & 0xfc000000) == 0x48000000) /* bl foo, save fprs */
752 if ((*pinsn & 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
756 int tmp = (*pinsn >> 16) & 0xffff;
758 if (tmp == 0x9421) { /* stu r1, NUM(r1) */
759 tbInfo.framesize = 0x10000 - (*pinsn & 0xffff);
762 else if ((*pinsn == 0x93e1fffc) || /* st r31,-4(r1) */
763 (tmp == 0x9001)) /* st r0, NUM(r1) */
765 /* else, could not find a frame size. */
769 } while (++pinsn && *pinsn);
771 if (!tbInfo.framesize)
776 /* look for a zero word. */
778 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
781 if (pinsn >= (int*)(buffer + bufferbytes))
786 /* function size is the amount of bytes we have skipped so far. */
787 tbInfo.fsize = bytesread - (buffer + bufferbytes - (char*)pinsn);
791 /* if we don't have the whole traceback table in the buffer, re-read
794 /* This is how much to read to get the traceback table.
795 8 bytes of the traceback table are always present, plus we
797 #define MIN_TBTABSIZ 12
799 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
801 /* In case if we are *very* close to the end of the text section
802 and cannot read properly from that point on, abort by returning
805 This could happen if the traceback table is only 8 bytes,
806 but we try to read 12 bytes of it.
807 Handle this case more graciously -- FIXME */
809 if (!bfd_get_section_contents (
810 abfd, textsec, buffer,
811 (file_ptr)(functionstart +
812 bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ))
813 { printf ("Abnormal return!..\n"); return NULL; }
815 ptb = (struct tbtable *)buffer;
818 ptb = (struct tbtable *)pinsn;
820 tbInfo.fixedparms = ptb->tb.fixedparms;
821 tbInfo.floatparms = ptb->tb.floatparms;
822 tbInfo.parminfo = ptb->tb_ext.parminfo;
826 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
827 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
833 /* Given a function symbol, return a pointer to its traceback table. */
836 retrieve_traceback (abfd, textsec, cs, size)
839 struct coff_symbol *cs;
840 int *size; /* return function size */
842 #define TBTABLE_BUFSIZ 2000
843 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
846 static char buffer [TBTABLE_BUFSIZ];
849 int bytesread=0; /* total # of bytes read so far */
850 int bufferbytes; /* number of bytes in the buffer */
852 int functionstart = cs->c_value - textsec->filepos + textsec->vma;
855 /* keep reading blocks of data from the text section, until finding a zero
856 word and a traceback table. */
858 while (bfd_get_section_contents (abfd, textsec, buffer,
859 (file_ptr)(functionstart + bytesread),
861 (TBTABLE_BUFSIZ < (textsec->size - functionstart - bytesread)) ?
862 TBTABLE_BUFSIZ : (textsec->size - functionstart - bytesread))))
864 bytesread += bufferbytes;
865 pinsn = (int*) buffer;
867 /* look for a zero word. */
869 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
872 if (pinsn >= (int*)(buffer + bufferbytes))
877 /* function size is the amount of bytes we have skipped so far. */
878 *size = bytesread - (buffer + bufferbytes - pinsn);
882 /* if we don't have the whole traceback table in the buffer, re-read
885 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
887 /* In case if we are *very* close to the end of the text section
888 and cannot read properly from that point on, abort for now.
889 Handle this case more graciously -- FIXME */
891 if (!bfd_get_section_contents (
892 abfd, textsec, buffer,
893 (file_ptr)(functionstart +
894 bytesread - (buffer + bufferbytes - pinsn)),MIN_TBTABSIZ))
895 /* abort (); */ { printf ("abort!!!\n"); return NULL; }
897 return (struct tbtable *)buffer;
900 return (struct tbtable *)pinsn;
910 /* Save the vital information for use when closing off the current file.
911 NAME is the file name the symbols came from, START_ADDR is the first
912 text address for the file, and SIZE is the number of bytes of text. */
914 #define complete_symtab(name, start_addr) { \
915 last_source_file = savestring (name, strlen (name)); \
916 last_source_start_addr = start_addr; \
920 /* Refill the symbol table input buffer
921 and set the variables that control fetching entries from it.
922 Reports an error if no data available.
923 This function can read past the end of the symbol table
924 (into the string table) but this does no harm. */
926 /* Reading symbol table has to be fast! Keep the followings as macros, rather
929 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION) \
933 namestr = (NAME) + 1; \
936 obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
939 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
940 (char *)NULL, (SECTION)); \
941 misc_func_recorded = 1; \
945 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
946 in our initializer function at the bottom of the file, to avoid
947 dependencies on the exact "struct symbol" format. */
949 static struct symbol parmsym;
951 /* Add a parameter to a given pending symbol list. */
953 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
955 PARM = (struct symbol *) \
956 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
958 SYMBOL_TYPE (PARM) = PTYPE; \
959 SYMBOL_VALUE (PARM) = VALUE; \
960 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
964 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
965 nested. At any given time, a symbol can only be in one static block.
966 This is the base address of current static block, zero if non exists. */
968 static int static_block_base = 0;
970 /* Section number for the current static block. */
972 static int static_block_section = -1;
974 /* true if space for symbol name has been allocated. */
976 static int symname_alloced = 0;
978 /* read the whole symbol table of a given bfd. */
981 read_xcoff_symtab (objfile, nsyms)
982 struct objfile *objfile; /* Object file we're reading from */
983 int nsyms; /* # of symbols */
985 bfd *abfd = objfile->obfd;
986 char *raw_symbol; /* Pointer into raw seething symbol table */
987 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
988 sec_ptr textsec; /* Pointer to text section */
989 TracebackInfo *ptb; /* Pointer to traceback table */
991 struct internal_syment symbol[1];
992 union internal_auxent main_aux[1];
993 struct coff_symbol cs[1];
994 CORE_ADDR file_start_addr = 0;
995 CORE_ADDR file_end_addr = 0;
997 int next_file_symnum = -1;
998 int just_started = 1;
1000 int toc_offset = 0; /* toc offset value in data section. */
1004 long fcn_line_offset;
1007 struct coff_symbol fcn_stab_saved;
1009 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1010 union internal_auxent fcn_aux_saved;
1011 struct type *fcn_type_saved = NULL;
1012 struct context_stack *new;
1014 char *filestring = " _start_ "; /* Name of the current file. */
1016 char *last_csect_name; /* last seen csect's name and value */
1017 CORE_ADDR last_csect_val;
1019 int misc_func_recorded; /* true if any misc. function */
1021 current_objfile = objfile;
1023 /* Get the appropriate COFF "constants" related to the file we're handling. */
1024 N_TMASK = coff_data (abfd)->local_n_tmask;
1025 N_BTSHFT = coff_data (abfd)->local_n_btshft;
1026 local_symesz = coff_data (abfd)->local_symesz;
1028 last_source_file = NULL;
1029 last_csect_name = 0;
1031 misc_func_recorded = 0;
1034 start_symtab (filestring, (char *)NULL, file_start_addr);
1036 first_object_file_end = 0;
1038 /* Allocate space for the entire symbol table at once, and read it
1039 all in. The bfd is already positioned at the beginning of
1040 the symbol table. */
1042 size = coff_data (abfd)->local_symesz * nsyms;
1043 symtbl = xmalloc (size);
1044 symtbl_num_syms = nsyms;
1046 val = bfd_read (symtbl, size, 1, abfd);
1048 perror_with_name ("reading symbol table");
1050 raw_symbol = symtbl;
1052 textsec = bfd_get_section_by_name (abfd, ".text");
1054 printf ("Unable to locate text section!\n");
1057 while (symnum < nsyms) {
1059 QUIT; /* make this command interruptable. */
1061 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1062 /* read one symbol into `cs' structure. After processing the whole symbol
1063 table, only string table will be kept in memory, symbol table and debug
1064 section of xcoff will be freed. Thus we can mark symbols with names
1065 in string table as `alloced'. */
1069 /* Swap and align the symbol into a reasonable C structure. */
1070 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1072 cs->c_symnum = symnum;
1073 cs->c_nsyms = symbol->n_numaux;
1074 if (symbol->n_zeroes) {
1075 symname_alloced = 0;
1076 /* We must use the original, unswapped, name here so the name field
1077 pointed to by cs->c_name will persist throughout xcoffread. If
1078 we use the new field, it gets overwritten for each symbol. */
1079 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
1080 /* If it's exactly E_SYMNMLEN characters long it isn't
1082 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1085 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1086 strncpy (p, cs->c_name, E_SYMNMLEN);
1087 p[E_SYMNMLEN] = '\0';
1089 symname_alloced = 1;
1091 } else if (symbol->n_sclass & 0x80) {
1092 cs->c_name = debugsec + symbol->n_offset;
1093 symname_alloced = 0;
1094 } else { /* in string table */
1095 cs->c_name = strtbl + (int)symbol->n_offset;
1096 symname_alloced = 1;
1098 cs->c_value = symbol->n_value;
1099 cs->c_sclass = symbol->n_sclass;
1100 cs->c_secnum = symbol->n_scnum;
1101 cs->c_type = (unsigned)symbol->n_type;
1103 raw_symbol += coff_data (abfd)->local_symesz;
1106 raw_auxptr = raw_symbol; /* Save addr of first aux entry */
1108 /* Skip all the auxents associated with this symbol. */
1109 for (ii = symbol->n_numaux; ii; --ii ) {
1110 raw_symbol += coff_data (abfd)->local_auxesz;
1115 /* if symbol name starts with ".$" or "$", ignore it. */
1116 if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1119 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) {
1120 if (last_source_file)
1122 end_symtab (cur_src_end_addr, 1, 0, objfile, textsec->target_index);
1127 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
1128 cur_src_end_addr = first_object_file_end;
1129 /* done with all files, everything from here on is globals */
1132 /* if explicitly specified as a function, treat is as one. */
1133 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) {
1134 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1136 goto function_entry_point;
1139 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
1141 /* dealing with a symbol with a csect entry. */
1143 # define CSECT(PP) ((PP)->x_csect)
1144 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1145 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1146 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1147 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1149 /* Convert the auxent to something we can access. */
1150 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1153 switch (CSECT_SMTYP (main_aux)) {
1156 continue; /* ignore all external references. */
1158 case XTY_SD : /* a section description. */
1160 switch (CSECT_SCLAS (main_aux)) {
1162 case XMC_PR : /* a `.text' csect. */
1165 /* A program csect is seen. We have to allocate one
1166 symbol table for each program csect. Normally gdb
1167 prefers one symtab for each source file. In case
1168 of AIX, one source file might include more than one
1169 [PR] csect, and they don't have to be adjacent in
1170 terms of the space they occupy in memory. Thus, one
1171 single source file might get fragmented in the
1172 memory and gdb's file start and end address
1173 approach does not work! GCC (and I think xlc) seem
1174 to put all the code in the unnamed program csect. */
1176 if (last_csect_name) {
1178 /* if no misc. function recorded in the last seen csect, enter
1179 it as a function. This will take care of functions like
1180 strcmp() compiled by xlc. */
1182 if (!misc_func_recorded) {
1184 RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
1185 mst_text, alloced, last_csect_sec);
1189 complete_symtab (filestring, file_start_addr);
1190 cur_src_end_addr = file_end_addr;
1191 end_symtab (file_end_addr, 1, 0, objfile,
1192 textsec->target_index);
1195 /* Give all csects for this source file the same
1197 start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
1200 /* If this is the very first csect seen, basically `__start'. */
1202 first_object_file_end = cs->c_value + CSECT_LEN (main_aux);
1206 file_start_addr = cs->c_value;
1207 file_end_addr = cs->c_value + CSECT_LEN (main_aux);
1209 if (cs->c_name && cs->c_name[0] == '.') {
1210 last_csect_name = cs->c_name;
1211 last_csect_val = cs->c_value;
1212 last_csect_sec = cs->c_secnum;
1215 misc_func_recorded = 0;
1221 /* If the section is not a data description, ignore it. Note that
1222 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1226 warning ("More than one xmc_tc0 symbol found.");
1227 toc_offset = cs->c_value;
1230 case XMC_TC : /* ignore toc entries */
1231 default : /* any other XMC_XXX */
1235 break; /* switch CSECT_SCLAS() */
1239 /* a function entry point. */
1240 if (CSECT_SCLAS (main_aux) == XMC_PR) {
1242 function_entry_point:
1243 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text,
1244 symname_alloced, cs->c_secnum);
1246 fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
1247 fcn_start_addr = cs->c_value;
1249 /* save the function header info, which will be used
1250 when `.bf' is seen. */
1252 fcn_aux_saved = *main_aux;
1257 /* If function has two auxent, then debugging information is
1258 already available for it. Process traceback table for
1259 functions with only one auxent. */
1261 if (cs->c_nsyms == 1)
1262 ptb = retrieve_tracebackinfo (abfd, textsec, cs);
1264 else if (cs->c_nsyms != 2)
1267 /* If there is traceback info, create and add parameters for it. */
1269 if (ptb && (ptb->fixedparms || ptb->floatparms)) {
1271 int parmcnt = ptb->fixedparms + ptb->floatparms;
1272 char *parmcode = (char*) &ptb->parminfo;
1273 int parmvalue = ptb->framesize + 0x18; /* sizeof(LINK AREA) == 0x18 */
1274 unsigned int ii, mask;
1276 for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii) {
1277 struct symbol *parm;
1279 if (ptb->parminfo & mask) { /* float or double */
1281 if (ptb->parminfo & mask) { /* double parm */
1283 (parm, parmvalue, builtin_type_double, local_symbols);
1284 parmvalue += sizeof (double);
1286 else { /* float parm */
1288 (parm, parmvalue, builtin_type_float, local_symbols);
1289 parmvalue += sizeof (float);
1292 else { /* fixed parm, use (int*) for hex rep. */
1293 ADD_PARM_TO_PENDING (parm, parmvalue,
1294 lookup_pointer_type (builtin_type_int),
1296 parmvalue += sizeof (int);
1301 /* Fake this as a function. Needed in process_xcoff_symbol() */
1304 finish_block(process_xcoff_symbol (cs, objfile), &local_symbols,
1305 pending_blocks, cs->c_value,
1306 cs->c_value + ptb->fsize, objfile);
1310 /* shared library function trampoline code entry point. */
1311 else if (CSECT_SCLAS (main_aux) == XMC_GL) {
1313 /* record trampoline code entries as mst_unknown symbol. When we
1314 lookup mst symbols, we will choose mst_text over mst_unknown. */
1317 /* After the implementation of incremental loading of shared
1318 libraries, we don't want to access trampoline entries. This
1319 approach has a consequence of the necessity to bring the whole
1320 shared library at first, in order do anything with it (putting
1321 breakpoints, using malloc, etc). On the other side, this is
1322 consistient with gdb's behaviour on a SUN platform. */
1324 /* Trying to prefer *real* function entry over its trampoline,
1325 by assigning `mst_unknown' type to trampoline entries fails.
1326 Gdb treats those entries as chars. FIXME. */
1328 /* Recording this entry is necessary. Single stepping relies on
1329 this vector to get an idea about function address boundaries. */
1331 prim_record_minimal_symbol_and_info
1332 ("<trampoline>", cs->c_value, mst_unknown,
1333 (char *)NULL, cs->c_secnum);
1336 /* record trampoline code entries as mst_unknown symbol. When we
1337 lookup mst symbols, we will choose mst_text over mst_unknown. */
1339 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_unknown,
1346 default : /* all other XTY_XXXs */
1348 } /* switch CSECT_SMTYP() */ }
1350 switch (cs->c_sclass) {
1354 /* see if the last csect needs to be recorded. */
1356 if (last_csect_name && !misc_func_recorded) {
1358 /* if no misc. function recorded in the last seen csect, enter
1359 it as a function. This will take care of functions like
1360 strcmp() compiled by xlc. */
1363 RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
1364 mst_text, alloced, last_csect_sec);
1367 /* c_value field contains symnum of next .file entry in table
1368 or symnum of first global after last .file. */
1370 next_file_symnum = cs->c_value;
1372 /* complete symbol table for last object file containing
1373 debugging information. */
1375 /* Whether or not there was a csect in the previous file, we have to call
1376 `end_stabs' and `start_stabs' to reset type_vector,
1377 line_vector, etc. structures. */
1379 complete_symtab (filestring, file_start_addr);
1380 cur_src_end_addr = file_end_addr;
1381 end_symtab (file_end_addr, 1, 0, objfile, textsec->target_index);
1384 start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
1385 last_csect_name = 0;
1387 /* reset file start and end addresses. A compilation unit with no text
1388 (only data) should have zero file boundaries. */
1389 file_start_addr = file_end_addr = 0;
1391 filestring = cs->c_name;
1396 fcn_stab_saved = *cs;
1401 if (STREQ (cs->c_name, ".bf")) {
1403 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1406 within_function = 1;
1408 mark_first_line (fcn_line_offset, cs->c_symnum);
1410 new = push_context (0, fcn_start_addr);
1412 new->name = define_symbol
1413 (fcn_cs_saved.c_value, fcn_stab_saved.c_name, 0, 0, objfile);
1414 if (new->name != NULL)
1415 SYMBOL_SECTION (new->name) = cs->c_secnum;
1417 else if (STREQ (cs->c_name, ".ef")) {
1419 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1422 /* the value of .ef is the address of epilogue code;
1423 not useful for gdb */
1424 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1425 contains number of lines to '}' */
1427 fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1428 new = pop_context ();
1429 if (context_stack_depth != 0)
1430 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1433 finish_block (new->name, &local_symbols, new->old_blocks,
1435 fcn_cs_saved.c_value +
1436 fcn_aux_saved.x_sym.x_misc.x_fsize, objfile);
1437 within_function = 0;
1441 case C_BSTAT : /* begin static block */
1443 struct internal_syment symbol;
1445 read_symbol (&symbol, cs->c_value);
1446 static_block_base = symbol.n_value;
1447 static_block_section = symbol.n_scnum;
1451 case C_ESTAT : /* end of static block */
1452 static_block_base = 0;
1453 static_block_section = -1;
1456 case C_ARG : /* These are not implemented. */
1462 printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
1465 case C_HIDEXT : /* ignore these.. */
1470 case C_BINCL : /* beginning of include file */
1472 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1473 order. Thus, when wee see them, we might not know enough info
1474 to process them. Thus, we'll be saving them into a table
1475 (inclTable) and postpone their processing. */
1477 record_include_begin (cs);
1480 case C_EINCL : /* end of include file */
1481 /* see the comment after case C_BINCL. */
1482 record_include_end (cs);
1486 if (STREQ (cs->c_name, ".bb")) {
1488 new = push_context (depth, cs->c_value);
1490 else if (STREQ (cs->c_name, ".eb")) {
1491 new = pop_context ();
1492 if (depth != new->depth)
1493 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1497 if (local_symbols && context_stack_depth > 0) {
1498 /* Make a block for the local symbols within. */
1499 finish_block (new->name, &local_symbols, new->old_blocks,
1500 new->start_addr, cs->c_value, objfile);
1502 local_symbols = new->locals;
1507 process_xcoff_symbol (cs, objfile);
1513 if (last_source_file)
1515 end_symtab (cur_src_end_addr, 1, 0, objfile, textsec->target_index);
1520 current_objfile = NULL;
1522 /* Record the toc offset value of this symbol table into ldinfo structure.
1523 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1524 this information would be file auxiliary header. */
1526 #ifndef FAKING_RS6000
1527 xcoff_add_toc_to_loadinfo (toc_offset);
1531 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1532 (SYMBOL2) = (struct symbol *) \
1533 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1534 *(SYMBOL2) = *(SYMBOL1);
1537 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1538 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1541 /* process one xcoff symbol. */
1543 static struct symbol *
1544 process_xcoff_symbol (cs, objfile)
1545 register struct coff_symbol *cs;
1546 struct objfile *objfile;
1548 struct symbol onesymbol;
1549 register struct symbol *sym = &onesymbol;
1550 struct symbol *sym2 = NULL;
1552 char *name, *pp, *qq;
1553 int struct_and_type_combined;
1560 memset (sym, '\0', sizeof (struct symbol));
1562 /* default assumptions */
1563 SYMBOL_VALUE (sym) = cs->c_value;
1564 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1565 SYMBOL_SECTION (sym) = cs->c_secnum;
1567 if (ISFCN (cs->c_type)) {
1569 /* At this point, we don't know the type of the function and assume it
1570 is int. This will be patched with the type from its stab entry later
1571 on in patch_block_stabs () */
1573 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1574 SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (objfile, FT_INTEGER));
1576 SYMBOL_CLASS (sym) = LOC_BLOCK;
1577 SYMBOL_DUP (sym, sym2);
1579 if (cs->c_sclass == C_EXT)
1580 add_symbol_to_list (sym2, &global_symbols);
1581 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1582 add_symbol_to_list (sym2, &file_symbols);
1587 /* in case we can't figure out the type, default is `int'. */
1588 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, FT_INTEGER);
1590 switch (cs->c_sclass)
1594 if (fcn_cs_saved.c_sclass == C_EXT)
1595 add_stab_to_list (name, &global_stabs);
1597 add_stab_to_list (name, &file_stabs);
1601 case C_DECL: /* a type decleration?? */
1603 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1605 SYMBOL_SECTION (sym) = cs->c_secnum;
1609 add_stab_to_list (name, &global_stabs);
1615 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1618 SYMBOL_SECTION (sym) = cs->c_secnum;
1624 /* If we are going to use Sun dbx's define_symbol(), we need to
1625 massage our stab string a little. Change 'V' type to 'S' to be
1626 comparible with Sun. */
1627 /* FIXME: I believe this is to avoid a Sun-specific hack somewhere.
1628 Needs more investigation. */
1630 if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
1634 if (*pp == 'V') *pp = 'S';
1635 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1638 SYMBOL_VALUE (sym) += static_block_base;
1639 SYMBOL_SECTION (sym) = static_block_section;
1644 sym = define_symbol (cs->c_value, cs->c_name, 0, N_LSYM, objfile);
1647 SYMBOL_SECTION (sym) = cs->c_secnum;
1652 SYMBOL_CLASS (sym) = LOC_LOCAL;
1653 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1654 SYMBOL_SECTION (sym) = cs->c_secnum;
1655 SYMBOL_DUP (sym, sym2);
1656 add_symbol_to_list (sym2, &local_symbols);
1660 SYMBOL_CLASS (sym) = LOC_STATIC;
1661 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1662 SYMBOL_SECTION (sym) = cs->c_secnum;
1663 SYMBOL_DUP (sym, sym2);
1664 add_symbol_to_list (sym2, &global_symbols);
1668 SYMBOL_CLASS (sym) = LOC_STATIC;
1669 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1670 SYMBOL_SECTION (sym) = cs->c_secnum;
1671 SYMBOL_DUP (sym, sym2);
1673 (sym2, within_function ? &local_symbols : &file_symbols);
1677 printf ("ERROR! C_REG is not fully implemented!\n");
1678 SYMBOL_CLASS (sym) = LOC_REGISTER;
1679 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1680 SYMBOL_SECTION (sym) = cs->c_secnum;
1681 SYMBOL_DUP (sym, sym2);
1682 add_symbol_to_list (sym2, &local_symbols);
1686 pp = (char*) strchr (name, ':');
1688 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1690 SYMBOL_SECTION (sym) = cs->c_secnum;
1694 complain (&rsym_complaint, name);
1699 complain (&storclass_complaint, cs->c_sclass);
1706 /* Set *SYMBOL to symbol number symno in symtbl. */
1708 read_symbol (symbol, symno)
1709 struct internal_syment *symbol;
1712 if (symno < 0 || symno >= symtbl_num_syms)
1714 static struct complaint msg =
1715 {"Invalid symbol offset", 0, 0};
1717 symbol->n_value = 0;
1718 symbol->n_scnum = -1;
1721 bfd_coff_swap_sym_in (symfile_bfd, symtbl + (symno*local_symesz), symbol);
1724 /* Get value corresponding to symbol number symno in symtbl. */
1727 read_symbol_nvalue (symno)
1730 struct internal_syment symbol[1];
1732 read_symbol (symbol, symno);
1733 return symbol->n_value;
1737 /* Find the address of the function corresponding to symno, where
1738 symno is the symbol pointed to by the linetable. */
1741 read_symbol_lineno (symno)
1744 struct internal_syment symbol[1];
1745 union internal_auxent main_aux[1];
1747 /* Note that just searching for a short distance (e.g. 50 symbols)
1748 is not enough, at least in the following case.
1751 [many .stabx entries]
1752 [a few functions, referring to foo]
1756 What happens here is that the assembler moves the .stabx entries
1757 to right before the ".bf" for foo, but the symbol for "foo" is before
1758 all the stabx entries. See PR gdb/2222. */
1759 while (symno < symtbl_num_syms) {
1760 bfd_coff_swap_sym_in (symfile_bfd,
1761 symtbl + (symno*local_symesz), symbol);
1762 if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf"))
1764 symno += symbol->n_numaux+1;
1767 complain (&bf_notfound_complaint);
1771 /* take aux entry and return its lineno */
1773 bfd_coff_swap_aux_in (symfile_bfd, symtbl+(symno*local_symesz),
1774 symbol->n_type, symbol->n_sclass, main_aux);
1776 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1779 /* Support for line number handling */
1781 /* This function is called for every section; it finds the outer limits
1782 * of the line table (minimum and maximum file offset) so that the
1783 * mainline code can read the whole thing for efficiency.
1786 find_linenos(abfd, asect, vpinfo)
1791 struct coff_symfile_info *info;
1793 file_ptr offset, maxoff;
1795 count = asect->lineno_count;
1797 if (!STREQ (asect->name, ".text") || count == 0)
1800 size = count * coff_data (symfile_bfd)->local_linesz;
1801 info = (struct coff_symfile_info *)vpinfo;
1802 offset = asect->line_filepos;
1803 maxoff = offset + size;
1805 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1806 info->min_lineno_offset = offset;
1808 if (maxoff > info->max_lineno_offset)
1809 info->max_lineno_offset = maxoff;
1813 /* Read in all the line numbers for fast lookups later. Leave them in
1814 external (unswapped) format in memory; we'll swap them as we enter
1815 them into GDB's data structures. */
1818 init_lineno (abfd, offset, size)
1827 if (bfd_seek(abfd, offset, L_SET) < 0)
1830 linetab = (char *) xmalloc(size);
1832 val = bfd_read(linetab, 1, size, abfd);
1836 linetab_offset = offset;
1837 linetab_size = size;
1849 /* dbx allows the text of a symbol name to be continued into the
1850 next symbol name! When such a continuation is encountered
1851 (a \ at the end of the text of a name)
1852 call this function to get the continuation. */
1853 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1856 #undef next_symbol_text
1857 #define next_symbol_text() \
1858 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1862 xcoff_new_init (objfile)
1863 struct objfile *objfile;
1868 /* xcoff_symfile_init()
1869 is the xcoff-specific initialization routine for reading symbols.
1870 It is passed an objfile which contains, among other things,
1871 the BFD for the file whose symbols are being read, and a slot for
1872 a pointer to "private data" which we fill with cookies and other
1873 treats for xcoff_symfile_read().
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.
1879 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
1882 xcoff_symfile_init (objfile)
1883 struct objfile *objfile;
1885 bfd *abfd = objfile->obfd;
1887 /* Allocate struct to keep track of the symfile */
1888 objfile -> sym_private = xmmalloc (objfile -> md,
1889 sizeof (struct coff_symfile_info));
1890 init_entry_point_info (objfile);
1893 /* Perform any local cleanups required when we are done with a particular
1894 objfile. I.E, we are in the process of discarding all symbol information
1895 for an objfile, freeing up all memory held for it, and unlinking the
1896 objfile struct from the global list of known objfiles. */
1899 xcoff_symfile_finish (objfile)
1900 struct objfile *objfile;
1902 if (objfile -> sym_private != NULL)
1904 mfree (objfile -> md, objfile -> sym_private);
1907 /* Start with a fresh include table for the next objfile. */
1914 inclIndx = inclLength = inclDepth = 0;
1919 init_stringtab(abfd, offset, objfile)
1922 struct objfile *objfile;
1926 unsigned char lengthbuf[4];
1928 if (bfd_seek(abfd, offset, L_SET) < 0)
1931 val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1932 length = bfd_h_get_32(abfd, lengthbuf);
1934 /* If no string table is needed, then the file may end immediately
1935 after the symbols. Just return with `strtbl' set to null. */
1937 if (val != sizeof length || length < sizeof length)
1940 /* Allocate string table from symbol_obstack. We will need this table
1941 as long as we have its symbol table around. */
1943 strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length);
1947 memcpy(strtbl, &length, sizeof length);
1948 if (length == sizeof length)
1951 val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd);
1953 if (val != length - sizeof length || strtbl[length - 1] != '\0')
1960 init_debugsection(abfd)
1963 register sec_ptr secp;
1964 bfd_size_type length;
1971 secp = bfd_get_section_by_name(abfd, ".debug");
1975 if (!(length = bfd_section_size(abfd, secp)))
1978 debugsec = (char *) xmalloc ((unsigned)length);
1979 if (debugsec == NULL)
1982 if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) {
1983 printf ("Can't read .debug section from symbol file\n");
1998 /* xcoff version of symbol file read. */
2001 xcoff_symfile_read (objfile, section_offset, mainline)
2002 struct objfile *objfile;
2003 struct section_offset *section_offset;
2006 int num_symbols; /* # of symbols */
2007 file_ptr symtab_offset; /* symbol table and */
2008 file_ptr stringtab_offset; /* string table file offsets */
2011 struct coff_symfile_info *info;
2013 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2015 info = (struct coff_symfile_info *) objfile -> sym_private;
2016 symfile_bfd = abfd = objfile->obfd;
2017 name = objfile->name;
2019 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2020 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2021 stringtab_offset = symtab_offset +
2022 num_symbols * coff_data(abfd)->local_symesz;
2024 info->min_lineno_offset = 0;
2025 info->max_lineno_offset = 0;
2026 bfd_map_over_sections (abfd, find_linenos, info);
2028 /* FIXME! This stuff should move into symfile_init */
2029 if (info->min_lineno_offset != 0
2030 && info->max_lineno_offset > info->min_lineno_offset) {
2032 /* only read in the line # table if one exists */
2033 make_cleanup (free_linetab, 0);
2034 val = init_lineno(abfd, info->min_lineno_offset,
2035 (int) (info->max_lineno_offset - info->min_lineno_offset));
2038 error("\"%s\": error reading line numbers\n", name);
2041 if (num_symbols > 0)
2043 val = init_stringtab(abfd, stringtab_offset, objfile);
2045 error ("\"%s\": can't get string table", name);
2048 if (init_debugsection(abfd) < 0) {
2049 error ("Error reading .debug section of `%s'\n", name);
2053 /* Position to read the symbol table. Do not read it all at once. */
2054 val = bfd_seek(abfd, symtab_offset, L_SET);
2056 perror_with_name(name);
2058 if (bfd_tell(abfd) != symtab_offset)
2061 init_minimal_symbol_collection ();
2062 make_cleanup (discard_minimal_symbols, 0);
2064 #ifndef FAKING_RS6000
2065 /* Initialize load info structure. */
2067 xcoff_init_loadinfo ();
2070 /* Now that the executable file is positioned at symbol table,
2071 process it and define symbols accordingly. */
2073 read_xcoff_symtab(objfile, num_symbols);
2075 /* Free debug section. */
2076 free_debugsection ();
2078 /* Sort symbols alphabetically within each block. */
2079 sort_all_symtab_syms ();
2081 /* Install any minimal symbols that have been collected as the current
2082 minimal symbols for this objfile. */
2084 install_minimal_symbols (objfile);
2086 do_cleanups (back_to);
2089 /* XCOFF-specific parsing routine for section offsets. */
2091 static int largest_section;
2094 note_one_section (abfd, asect, ptr)
2099 if (asect->target_index > largest_section)
2100 largest_section = asect->target_index;
2104 struct section_offsets *
2105 xcoff_symfile_offsets (objfile, addr)
2106 struct objfile *objfile;
2109 struct section_offsets *section_offsets;
2112 largest_section = 0;
2113 bfd_map_over_sections (objfile->obfd, note_one_section, NULL);
2114 objfile->num_sections = largest_section + 1;
2115 section_offsets = (struct section_offsets *)
2117 (&objfile -> psymbol_obstack,
2118 sizeof (struct section_offsets)
2119 + sizeof (section_offsets->offsets) * (objfile->num_sections));
2121 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2122 of the .text section. This strikes me as wrong--whether the
2123 offset to be applied to symbol reading is relative to the start
2124 address of the section depends on the symbol format. In any
2125 event, this whole "addr" concept is pretty broken (it doesn't
2126 handle any section but .text sensibly), so just ignore the addr
2127 parameter and use 0. That matches the fact that xcoff_symfile_read
2128 ignores the section_offsets). */
2129 for (i = 0; i < objfile->num_sections; i++)
2130 ANOFFSET (section_offsets, i) = 0;
2132 return section_offsets;
2134 /* Register our ability to parse symbols for xcoff BFD files. */
2136 static struct sym_fns xcoff_sym_fns =
2138 "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */
2139 15, /* sym_namelen: number of significant sym_name chars */
2140 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2141 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2142 xcoff_symfile_read, /* sym_read: read a symbol file into symtab */
2143 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2144 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
2145 NULL /* next: pointer to next struct sym_fns */
2149 _initialize_xcoffread ()
2151 add_symtab_fns(&xcoff_sym_fns);
2153 /* Initialize symbol template later used for arguments. */
2154 SYMBOL_NAME (&parmsym) = "";
2155 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym, language_c);
2156 SYMBOL_NAMESPACE (&parmsym) = VAR_NAMESPACE;
2157 SYMBOL_CLASS (&parmsym) = LOC_ARG;
2158 /* Its other fields are zero, or are filled in later. */