1 /* Read AIXcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3 Derived from coffread.c, dbxread.c, and a lot of hacking.
4 Contributed by IBM Corporation.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 /* Native only: Need struct tbtable in <sys/debug.h>. */
28 /* AIX COFF names have a preceeding dot `.' */
29 #define NAMES_HAVE_DOT 1
31 #include <sys/types.h>
36 #include <sys/param.h>
41 #include <sys/debug.h>
48 #include "gdb-stabs.h"
50 #include "coff/internal.h" /* FIXME, internal data from BFD */
51 #include "libcoff.h" /* FIXME, internal data from BFD */
52 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
55 /* Define this if you want gdb use the old xcoff symbol processing. This
56 way it won't use common `define_symbol()' function and Sun dbx stab
57 string grammar. And likely it won't be able to do G++ debugging. */
59 /* #define NO_DEFINE_SYMBOL 1 */
61 /* Define this if you want gdb to ignore typdef stabs. This was needed for
62 one of Transarc, to reduce the size of the symbol table. Types won't be
63 recognized, but tag names will be. */
65 /* #define NO_TYPEDEFS 1 */
67 /* Simplified internal version of coff symbol table information */
71 int c_symnum; /* symbol number of this entry */
72 int c_nsyms; /* 0 if syment only, 1 if syment + auxent */
79 /* The COFF line table, in raw form. */
80 static char *linetab = NULL; /* Its actual contents */
81 static long linetab_offset; /* Its offset in the file */
82 static unsigned long linetab_size; /* Its size */
84 /* last function's saved coff symbol `cs' */
86 static struct coff_symbol fcn_cs_saved;
88 static bfd *symfile_bfd;
90 /* Core address of start and end of text of current source file.
91 This is calculated from the first function seen after a C_FILE
95 static CORE_ADDR cur_src_end_addr;
97 /* Core address of the end of the first object file. */
99 static CORE_ADDR first_object_file_end;
101 /* pointer to the string table */
104 /* length of the string table */
105 static int strtbl_len;
107 /* pointer to debug section */
108 static char *debugsec;
110 /* pointer to the a.out symbol table */
113 /* initial symbol-table-debug-string vector length */
115 #define INITIAL_STABVECTOR_LENGTH 40
117 struct pending_stabs *global_stabs;
120 /* Nonzero if within a function (so symbols should be local,
121 if nothing says specifically). */
125 /* Local variables that hold the shift and mask values for the
126 COFF file that we are currently reading. These come back to us
127 from BFD, and are referenced by their macro names, as well as
128 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
129 macros from ../internalcoff.h . */
131 static unsigned local_n_btshft;
132 static unsigned local_n_tmask;
135 #define N_BTSHFT local_n_btshft
137 #define N_TMASK local_n_tmask
139 /* Local variables that hold the sizes in the file of various COFF structures.
140 (We only need to know this to read them from the file -- BFD will then
141 translate the data in them, into `internal_xxx' structs in the right
142 byte order, alignment, etc.) */
144 static unsigned local_symesz;
147 /* coff_symfile_init()
148 is the coff-specific initialization routine for reading symbols.
149 It is passed a struct sym_fns which contains, among other things,
150 the BFD for the file whose symbols are being read, and a slot for
151 a pointer to "private data" which we fill with cookies and other
152 treats for coff_symfile_read().
154 We will only be called if this is a COFF or COFF-like file.
155 BFD handles figuring out the format of the file, and code in symtab.c
156 uses BFD's determination to vector to us.
158 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
160 struct coff_symfile_info {
161 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
162 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
167 enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
168 CORE_ADDR, CORE_ADDR, unsigned *));
171 free_debugsection PARAMS ((void));
174 init_debugsection PARAMS ((bfd *));
177 init_stringtab PARAMS ((bfd *, long, struct objfile *));
180 aixcoff_symfile_init PARAMS ((struct objfile *));
183 aixcoff_new_init PARAMS ((struct objfile *));
186 aixcoff_symfile_read PARAMS ((struct objfile *, struct section_offset *, int));
189 aixcoff_symfile_finish PARAMS ((struct objfile *));
191 static struct section_offsets *
192 aixcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
195 init_lineno PARAMS ((bfd *, long, int));
198 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
201 read_symbol_lineno PARAMS ((char *, int));
204 read_symbol_nvalue PARAMS ((char *, int));
206 static struct symbol *
207 process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
210 read_xcoff_symtab PARAMS ((struct objfile *, int));
213 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
216 sort_syms PARAMS ((void));
219 compare_symbols PARAMS ((const void *, const void *));
221 /* Call sort_syms to sort alphabetically
222 the symbols of each block of each symtab. */
225 compare_symbols (s1p, s2p)
229 /* Names that are less should come first. */
230 register struct symbol **s1 = (struct symbol **) s1p;
231 register struct symbol **s2 = (struct symbol **) s2p;
232 register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
236 /* For symbols of the same name, registers should come first. */
237 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
238 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
242 /* Sort a vector of symbols by their value. */
247 register struct symtab *s;
248 register struct objfile *objfile;
250 register struct blockvector *bv;
251 register struct block *b;
253 for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
255 for (s = objfile -> symtabs; s != NULL; s = s -> next)
257 bv = BLOCKVECTOR (s);
258 nbl = BLOCKVECTOR_NBLOCKS (bv);
259 for (i = 0; i < nbl; i++)
261 b = BLOCKVECTOR_BLOCK (bv, i);
262 if (BLOCK_SHOULD_SORT (b))
264 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
265 sizeof (struct symbol *), compare_symbols);
273 /* add a given stab string into given stab vector. */
276 add_stab_to_list (stabname, stabvector)
278 struct pending_stabs **stabvector;
280 if ( *stabvector == NULL) {
281 *stabvector = (struct pending_stabs *)
282 xmalloc (sizeof (struct pending_stabs) +
283 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
284 (*stabvector)->count = 0;
285 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
287 else if ((*stabvector)->count >= (*stabvector)->length) {
288 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
289 *stabvector = (struct pending_stabs *)
290 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
291 (*stabvector)->length * sizeof (char*));
293 (*stabvector)->stab [(*stabvector)->count++] = stabname;
298 /* for all the stabs in a given stab vector, build appropriate types
299 and fix their symbols in given symbol vector. */
302 patch_block_stabs (symbols, stabs)
303 struct pending *symbols;
304 struct pending_stabs *stabs;
311 /* for all the stab entries, find their corresponding symbols and
312 patch their types! */
314 for (ii=0; ii < stabs->count; ++ii) {
315 char *name = stabs->stab[ii];
316 char *pp = (char*) index (name, ':');
317 struct symbol *sym = find_symbol_in_list (symbols, name, pp-name);
320 /* printf ("ERROR! stab symbol not found!\n"); */ /* FIXME */
321 /* The above is a false alarm. There are cases the we can have
322 a stab, without its symbol. xlc generates this for the extern
323 definitions in inner blocks. */
328 if (*(pp-1) == 'F' || *(pp-1) == 'f')
329 SYMBOL_TYPE (sym) = lookup_function_type (read_type (&pp));
331 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
338 /* compare line table entry addresses. */
341 compare_lte (lte1, lte2)
342 struct linetable_entry *lte1, *lte2;
344 return lte1->pc - lte2->pc;
347 /* Give a line table with function entries are marked, arrange its functions
348 in assending order and strip off function entry markers and return it in
349 a newly created table. If the old one is good enough, return the old one. */
351 static struct linetable *
352 arrange_linetable (oldLineTb)
353 struct linetable *oldLineTb; /* old linetable */
356 newline, /* new line count */
357 function_count; /* # of functions */
359 struct linetable_entry *fentry; /* function entry vector */
360 int fentry_size; /* # of function entries */
361 struct linetable *newLineTb; /* new line table */
363 #define NUM_OF_FUNCTIONS 20
365 fentry_size = NUM_OF_FUNCTIONS;
366 fentry = (struct linetable_entry*)
367 malloc (fentry_size * sizeof (struct linetable_entry));
369 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
371 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
373 if (function_count >= fentry_size) { /* make sure you have room. */
375 fentry = (struct linetable_entry*)
376 realloc (fentry, fentry_size * sizeof (struct linetable_entry));
378 fentry[function_count].line = ii;
379 fentry[function_count].pc = oldLineTb->item[ii].pc;
384 if (function_count == 0) {
388 else if (function_count > 1)
389 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
391 /* allocate a new line table. */
392 newLineTb = (struct linetable*) malloc (sizeof (struct linetable) +
393 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
395 /* if line table does not start with a function beginning, copy up until
399 if (oldLineTb->item[0].line != 0)
401 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
402 newLineTb->item[newline] = oldLineTb->item[newline];
404 /* Now copy function lines one by one. */
406 for (ii=0; ii < function_count; ++ii) {
407 for (jj = fentry[ii].line + 1;
408 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
410 newLineTb->item[newline] = oldLineTb->item[jj];
413 newLineTb->nitems = oldLineTb->nitems - function_count;
419 /* We try to detect the beginning of a compilation unit. That info will
420 be used as an entry in line number recording routines (enter_line_range) */
422 static unsigned first_fun_line_offset;
423 static unsigned first_fun_bf;
425 #define mark_first_line(OFFSET, SYMNUM) \
426 if (!first_fun_line_offset) { \
427 first_fun_line_offset = OFFSET; \
428 first_fun_bf = SYMNUM; \
432 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
433 following `IncludeChain'. At the end of each symtab (end_symtab),
434 we will determine if we should create additional symtab's to
435 represent if (the include files. */
438 typedef struct _inclTable {
439 char *name; /* include filename */
440 int begin, end; /* offsets to the line table */
441 struct subfile *subfile;
442 unsigned funStartLine; /* start line # of its function */
445 #define INITIAL_INCLUDE_TABLE_LENGTH 20
446 static InclTable *inclTable; /* global include table */
447 static int inclIndx; /* last entry to table */
448 static int inclLength; /* table length */
449 static int inclDepth; /* nested include depth */
453 record_include_begin (cs)
454 struct coff_symbol *cs;
456 /* In aixcoff, we assume include files cannot be nested (not in .c files
457 of course, but in corresponding .s files.) */
460 fatal ("aix internal: pending include file exists.");
464 /* allocate an include file, or make room for the new entry */
465 if (inclLength == 0) {
466 inclTable = (InclTable*)
467 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
468 bzero (inclTable, sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
469 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
472 else if (inclIndx >= inclLength) {
473 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
474 inclTable = (InclTable*)
475 xrealloc (inclTable, sizeof (InclTable) * inclLength);
476 bzero (inclTable+inclLength-INITIAL_INCLUDE_TABLE_LENGTH,
477 sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
480 inclTable [inclIndx].name = cs->c_name;
481 inclTable [inclIndx].begin = cs->c_value;
486 record_include_end (cs)
487 struct coff_symbol *cs;
492 fatal ("aix internal: Mismatch C_BINCL/C_EINCL pair found.");
494 pTbl = &inclTable [inclIndx];
495 pTbl->end = cs->c_value;
502 /* given the start and end addresses of a compilation unit (or a csect, at times)
503 process its lines and create appropriate line vectors. */
506 process_linenos (start, end)
507 CORE_ADDR start, end;
512 struct subfile main_subfile; /* subfile structure for the main
515 /* in the main source file, any time we see a function entry, we reset
516 this variable to function's absolute starting line number. All the
517 following line numbers in the function are relative to this, and
518 we record absolute line numbers in record_line(). */
520 int main_source_baseline = 0;
526 if (!(offset = first_fun_line_offset))
527 goto return_after_cleanup;
529 bzero (&main_subfile, sizeof (main_subfile));
530 first_fun_line_offset = 0;
533 /* All source lines were in the main source file. None in include files. */
535 enter_line_range (&main_subfile, offset, 0, start, end,
536 &main_source_baseline);
538 /* else, there was source with line numbers in include files */
541 main_source_baseline = 0;
542 for (ii=0; ii < inclIndx; ++ii) {
544 struct subfile *tmpSubfile;
546 /* if there is main file source before include file, enter it. */
547 if (offset < inclTable[ii].begin) {
549 (&main_subfile, offset, inclTable[ii].begin - LINESZ, start, 0,
550 &main_source_baseline);
553 /* Have a new subfile for the include file */
555 tmpSubfile = inclTable[ii].subfile = (struct subfile*)
556 xmalloc (sizeof (struct subfile));
558 bzero (tmpSubfile, sizeof (struct subfile));
559 firstLine = &(inclTable[ii].funStartLine);
561 /* enter include file's lines now. */
562 enter_line_range (tmpSubfile, inclTable[ii].begin,
563 inclTable[ii].end, start, 0, firstLine);
565 offset = inclTable[ii].end + LINESZ;
568 /* all the include files' line have been processed at this point. Now,
569 enter remaining lines of the main file, if any left. */
570 if (offset < (linetab_offset + linetab_size + 1 - LINESZ)) {
571 enter_line_range (&main_subfile, offset, 0, start, end,
572 &main_source_baseline);
576 /* Process main file's line numbers. */
577 if (main_subfile.line_vector) {
578 struct linetable *lineTb, *lv;
580 lv = main_subfile.line_vector;
582 /* Line numbers are not necessarily ordered. xlc compilation will
583 put static function to the end. */
585 lineTb = arrange_linetable (lv);
587 current_subfile->line_vector = (struct linetable *)
588 xrealloc (lv, (sizeof (struct linetable)
589 + lv->nitems * sizeof (struct linetable_entry)));
594 current_subfile->line_vector = lineTb;
597 current_subfile->line_vector_length =
598 current_subfile->line_vector->nitems;
601 /* Now, process included files' line numbers. */
603 for (ii=0; ii < inclIndx; ++ii) {
605 if ( (inclTable[ii].subfile)->line_vector) { /* Useless if!!! FIXMEmgo */
606 struct linetable *lineTb, *lv;
608 lv = (inclTable[ii].subfile)->line_vector;
610 /* Line numbers are not necessarily ordered. xlc compilation will
611 put static function to the end. */
613 lineTb = arrange_linetable (lv);
617 /* For the same include file, we might want to have more than one subfile.
618 This happens if we have something like:
626 while foo.h including code in it. (stupid but possible)
627 Since start_subfile() looks at the name and uses an existing one if finds,
628 we need to provide a fake name and fool it. */
630 /* start_subfile (inclTable[ii].name, (char*)0); */
631 start_subfile (" ?", (char*)0);
632 current_subfile->name =
633 obsavestring (inclTable[ii].name, strlen (inclTable[ii].name),
634 ¤t_objfile->symbol_obstack);
637 current_subfile->line_vector = (struct linetable *)
638 xrealloc (lv, (sizeof (struct linetable)
639 + lv->nitems * sizeof (struct linetable_entry)));
644 current_subfile->line_vector = lineTb;
647 current_subfile->line_vector_length =
648 current_subfile->line_vector->nitems;
649 start_subfile (pop_subfile (), (char*)0);
653 return_after_cleanup:
655 /* We don't want to keep alloc/free'ing the global include file table. */
658 /* start with a fresh subfile structure for the next file. */
659 bzero (&main_subfile, sizeof (struct subfile));
663 aix_process_linenos ()
665 /* process line numbers and enter them into line vector */
666 process_linenos (last_source_start_addr, cur_src_end_addr);
670 /* Enter a given range of lines into the line vector.
671 can be called in the following two ways:
672 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
673 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine) */
676 enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr, firstLine)
677 struct subfile *subfile;
678 unsigned beginoffset, endoffset; /* offsets to line table */
679 CORE_ADDR startaddr, endaddr;
685 /* Do Byte swapping, if needed. FIXME! */
686 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
687 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
688 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
690 pp = &linetab [beginoffset - linetab_offset];
691 limit = endoffset ? &linetab [endoffset - linetab_offset]
692 : &linetab [linetab_size -1];
694 while (pp <= limit) {
696 /* find the address this line represents */
697 addr = P_LINENO(pp) ?
698 P_LINEADDR(pp) : read_symbol_nvalue (symtbl, P_LINESYM(pp));
700 if (addr < startaddr || (endaddr && addr > endaddr))
703 if (P_LINENO(pp) == 0) {
704 *firstLine = read_symbol_lineno (symtbl, P_LINESYM(pp));
705 record_line (subfile, 0, addr);
709 record_line (subfile, *firstLine + P_LINENO(pp), addr);
716 int fsize; /* file size */
717 int fixedparms; /* number of fixed parms */
718 int floatparms; /* number of float parms */
719 unsigned int parminfo; /* parameter info.
720 See /usr/include/sys/debug.h
721 tbtable_ext.parminfo */
722 int framesize; /* function frame size */
726 /* Given a function symbol, return its traceback information. */
729 retrieve_tracebackinfo (abfd, textsec, cs)
732 struct coff_symbol *cs;
734 #define TBTABLE_BUFSIZ 2000
735 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
738 static TracebackInfo tbInfo;
741 static char buffer [TBTABLE_BUFSIZ];
744 int bytesread=0; /* total # of bytes read so far */
745 int bufferbytes; /* number of bytes in the buffer */
747 int functionstart = cs->c_value - textsec->vma;
749 bzero (&tbInfo, sizeof (tbInfo));
751 /* keep reading blocks of data from the text section, until finding a zero
752 word and a traceback table. */
756 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread)) ?
757 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread))
759 && bfd_get_section_contents (abfd, textsec, buffer,
760 (file_ptr)(functionstart + bytesread), bufferbytes))
762 bytesread += bufferbytes;
763 pinsn = (int*) buffer;
765 /* if this is the first time we filled the buffer, retrieve function
768 if (bytesread == bufferbytes) {
770 /* skip over unrelated instructions */
772 if (*pinsn == 0x7c0802a6) /* mflr r0 */
774 if ((*pinsn & 0xfc00003e) == 0x7c000026) /* mfcr Rx */
776 if ((*pinsn & 0xfc000000) == 0x48000000) /* bl foo, save fprs */
778 if ((*pinsn & 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
782 int tmp = (*pinsn >> 16) & 0xffff;
784 if (tmp == 0x9421) { /* stu r1, NUM(r1) */
785 tbInfo.framesize = 0x10000 - (*pinsn & 0xffff);
788 else if ((*pinsn == 0x93e1fffc) || /* st r31,-4(r1) */
789 (tmp == 0x9001)) /* st r0, NUM(r1) */
791 /* else, could not find a frame size. */
795 } while (++pinsn && *pinsn);
797 if (!tbInfo.framesize)
801 /* look for a zero word. */
803 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
806 if (pinsn >= (int*)(buffer + bufferbytes))
811 /* function size is the amount of bytes we have skipped so far. */
812 tbInfo.fsize = bytesread - (buffer + bufferbytes - (char*)pinsn);
816 /* if we don't have the whole traceback table in the buffer, re-read
819 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
821 /* In case if we are *very* close to the end of the text section
822 and cannot read properly from that point on, abort by returning
824 Handle this case more graciously -- FIXME */
826 if (!bfd_get_section_contents (
827 abfd, textsec, buffer,
828 (file_ptr)(functionstart +
829 bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ))
830 { printf ("Abnormal return!..\n"); return NULL; }
832 ptb = (struct tbtable *)buffer;
835 ptb = (struct tbtable *)pinsn;
837 tbInfo.fixedparms = ptb->tb.fixedparms;
838 tbInfo.floatparms = ptb->tb.floatparms;
839 tbInfo.parminfo = ptb->tb_ext.parminfo;
847 /* Given a function symbol, return a pointer to its traceback table. */
850 retrieve_traceback (abfd, textsec, cs, size)
853 struct coff_symbol *cs;
854 int *size; /* return function size */
856 #define TBTABLE_BUFSIZ 2000
857 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
860 static char buffer [TBTABLE_BUFSIZ];
863 int bytesread=0; /* total # of bytes read so far */
864 int bufferbytes; /* number of bytes in the buffer */
866 int functionstart = cs->c_value - textsec->filepos + textsec->vma;
869 /* keep reading blocks of data from the text section, until finding a zero
870 word and a traceback table. */
872 while (bfd_get_section_contents (abfd, textsec, buffer,
873 (file_ptr)(functionstart + bytesread),
875 (TBTABLE_BUFSIZ < (textsec->size - functionstart - bytesread)) ?
876 TBTABLE_BUFSIZ : (textsec->size - functionstart - bytesread))))
878 bytesread += bufferbytes;
879 pinsn = (int*) buffer;
881 /* look for a zero word. */
883 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
886 if (pinsn >= (int*)(buffer + bufferbytes))
891 /* function size is the amount of bytes we have skipped so far. */
892 *size = bytesread - (buffer + bufferbytes - pinsn);
896 /* if we don't have the whole traceback table in the buffer, re-read
899 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
901 /* In case if we are *very* close to the end of the text section
902 and cannot read properly from that point on, abort for now.
903 Handle this case more graciously -- FIXME */
905 if (!bfd_get_section_contents (
906 abfd, textsec, buffer,
907 (file_ptr)(functionstart +
908 bytesread - (buffer + bufferbytes - pinsn)),MIN_TBTABSIZ))
909 /* abort (); */ { printf ("abort!!!\n"); return NULL; }
911 return (struct tbtable *)buffer;
914 return (struct tbtable *)pinsn;
924 /* Save the vital information for use when closing off the current file.
925 NAME is the file name the symbols came from, START_ADDR is the first
926 text address for the file, and SIZE is the number of bytes of text. */
928 #define complete_symtab(name, start_addr) { \
929 last_source_file = savestring (name, strlen (name)); \
930 last_source_start_addr = start_addr; \
934 /* Refill the symbol table input buffer
935 and set the variables that control fetching entries from it.
936 Reports an error if no data available.
937 This function can read past the end of the symbol table
938 (into the string table) but this does no harm. */
940 /* Reading symbol table has to be fast! Keep the followings as macros, rather
943 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \
947 namestr = (NAME) + 1; \
950 obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
953 prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \
954 misc_func_recorded = 1; \
958 /* A parameter template, used by ADD_PARM_TO_PENDING. */
960 static struct symbol parmsym = { /* default parameter symbol */
962 VAR_NAMESPACE, /* namespace */
969 /* Add a parameter to a given pending symbol list. */
971 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
973 PARM = (struct symbol *) \
974 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
976 SYMBOL_TYPE (PARM) = PTYPE; \
977 SYMBOL_VALUE (PARM) = VALUE; \
978 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
982 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
983 nested. At any given time, a symbol can only be in one static block.
984 This is the base address of current static block, zero if non exists. */
986 static int static_block_base = 0;
988 /* true if space for symbol name has been allocated. */
990 static int symname_alloced = 0;
992 /* read the whole symbol table of a given bfd. */
995 read_xcoff_symtab (objfile, nsyms)
996 struct objfile *objfile; /* Object file we're reading from */
997 int nsyms; /* # of symbols */
999 bfd *abfd = objfile->obfd;
1000 char *raw_symbol; /* Pointer into raw seething symbol table */
1001 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
1002 sec_ptr textsec; /* Pointer to text section */
1003 TracebackInfo *ptb; /* Pointer to traceback table */
1005 struct internal_syment symbol[1];
1006 union internal_auxent main_aux[1];
1007 struct coff_symbol cs[1];
1008 CORE_ADDR file_start_addr = 0;
1009 CORE_ADDR file_end_addr = 0;
1011 int next_file_symnum = -1;
1012 int just_started = 1;
1014 int toc_offset = 0; /* toc offset value in data section. */
1018 long fcn_line_offset;
1021 struct coff_symbol fcn_stab_saved;
1023 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1024 union internal_auxent fcn_aux_saved;
1025 struct type *fcn_type_saved = NULL;
1026 struct context_stack *new;
1028 char *filestring = " _start_ "; /* Name of the current file. */
1030 char *last_csect_name; /* last seen csect's name and value */
1031 CORE_ADDR last_csect_val;
1032 int misc_func_recorded; /* true if any misc. function */
1034 current_objfile = objfile;
1036 /* Get the appropriate COFF "constants" related to the file we're handling. */
1037 N_TMASK = coff_data (abfd)->local_n_tmask;
1038 N_BTSHFT = coff_data (abfd)->local_n_btshft;
1039 local_symesz = coff_data (abfd)->local_symesz;
1041 last_source_file = 0;
1042 last_csect_name = 0;
1044 misc_func_recorded = 0;
1046 start_symtab (filestring, (char *)NULL, file_start_addr);
1048 first_object_file_end = 0;
1050 /* Allocate space for the entire symbol table at once, and read it
1051 all in. The bfd is already positioned at the beginning of
1052 the symbol table. */
1054 size = coff_data (abfd)->local_symesz * nsyms;
1055 symtbl = xmalloc (size);
1057 val = bfd_read (symtbl, size, 1, abfd);
1059 perror_with_name ("reading symbol table");
1061 raw_symbol = symtbl;
1063 textsec = bfd_get_section_by_name (abfd, ".text");
1065 printf ("Unable to locate text section!\n");
1068 while (symnum < nsyms) {
1070 QUIT; /* make this command interruptable. */
1072 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1073 /* read one symbol into `cs' structure. After processing the whole symbol
1074 table, only string table will be kept in memory, symbol table and debug
1075 section of aixcoff will be freed. Thus we can mark symbols with names
1076 in string table as `alloced'. */
1080 /* Swap and align the symbol into a reasonable C structure. */
1081 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1083 cs->c_symnum = symnum;
1084 cs->c_nsyms = symbol->n_numaux;
1085 if (symbol->n_zeroes) {
1086 symname_alloced = 0;
1087 /* We must use the original, unswapped, name here so the name field
1088 pointed to by cs->c_name will persist throughout xcoffread. If
1089 we use the new field, it gets overwritten for each symbol. */
1090 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
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 /* n_sclass is signed (FIXME), so we had better not mask off any
1100 high bits it contains, since the values we will be comparing
1101 it to are also signed (FIXME). Defined in <coff/internal.h>.
1103 make the fields and values unsigned chars, but changing the next
1104 line is a simple patch late in the release cycle, for now. */
1105 cs->c_sclass = symbol->n_sclass /* & 0xff */;
1106 cs->c_secnum = symbol->n_scnum;
1107 cs->c_type = (unsigned)symbol->n_type;
1109 raw_symbol += coff_data (abfd)->local_symesz;
1112 raw_auxptr = raw_symbol; /* Save addr of first aux entry */
1114 /* Skip all the auxents associated with this symbol. */
1115 for (ii = symbol->n_numaux; ii; --ii ) {
1116 raw_symbol += coff_data (abfd)->local_auxesz;
1121 /* if symbol name starts with ".$" or "$", ignore it. */
1122 if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1125 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) {
1126 if (last_source_file)
1127 end_symtab (cur_src_end_addr, 1, 0, objfile);
1129 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
1130 cur_src_end_addr = first_object_file_end;
1131 /* done with all files, everything from here on is globals */
1134 /* if explicitly specified as a function, treat is as one. */
1135 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) {
1136 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1138 goto function_entry_point;
1141 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
1143 /* dealing with a symbol with a csect entry. */
1145 # define CSECT(PP) ((PP)->x_csect)
1146 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1147 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1148 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1149 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1151 /* Convert the auxent to something we can access. */
1152 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1155 switch (CSECT_SMTYP (main_aux)) {
1158 continue; /* ignore all external references. */
1160 case XTY_SD : /* a section description. */
1162 switch (CSECT_SCLAS (main_aux)) {
1164 case XMC_PR : /* a `.text' csect. */
1167 /* A program csect is seen.
1169 We have to allocate one symbol table for each program csect. Normally
1170 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
1171 CU might include more than one prog csect, and they don't have to be
1172 adjacent in terms of the space they occupy in memory. Thus, one single
1173 CU might get fragmented in the memory and gdb's file start and end address
1174 approach does not work! */
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,
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 start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0);
1195 /* If this is the very first csect seen, basically `__start'. */
1197 first_object_file_end = cs->c_value + CSECT_LEN (main_aux);
1201 file_start_addr = cs->c_value;
1202 file_end_addr = cs->c_value + CSECT_LEN (main_aux);
1204 if (cs->c_name && cs->c_name[0] == '.') {
1205 last_csect_name = cs->c_name;
1206 last_csect_val = cs->c_value;
1209 misc_func_recorded = 0;
1215 /* If the section is not a data description, ignore it. Note that
1216 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1220 warning ("More than one xmc_tc0 symbol found.");
1221 toc_offset = cs->c_value;
1224 case XMC_TC : /* ignore toc entries */
1225 default : /* any other XMC_XXX */
1229 break; /* switch CSECT_SCLAS() */
1233 /* a function entry point. */
1234 if (CSECT_SCLAS (main_aux) == XMC_PR) {
1236 function_entry_point:
1237 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_text,
1240 fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
1241 fcn_start_addr = cs->c_value;
1243 /* save the function header info, which will be used
1244 when `.bf' is seen. */
1246 fcn_aux_saved = *main_aux;
1251 /* If function has two auxent, then debugging information is
1252 already available for it. Process traceback table for
1253 functions with only one auxent. */
1255 if (cs->c_nsyms == 1)
1256 ptb = retrieve_tracebackinfo (abfd, textsec, cs);
1258 else if (cs->c_nsyms != 2)
1261 /* If there is traceback info, create and add parameters for it. */
1263 if (ptb && (ptb->fixedparms || ptb->floatparms)) {
1265 int parmcnt = ptb->fixedparms + ptb->floatparms;
1266 char *parmcode = (char*) &ptb->parminfo;
1267 int parmvalue = ptb->framesize + 0x18; /* sizeof(LINK AREA) == 0x18 */
1268 unsigned int ii, mask;
1270 for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii) {
1271 struct symbol *parm;
1273 if (ptb->parminfo & mask) { /* float or double */
1275 if (ptb->parminfo & mask) { /* double parm */
1277 (parm, parmvalue, builtin_type_double, local_symbols);
1278 parmvalue += sizeof (double);
1280 else { /* float parm */
1282 (parm, parmvalue, builtin_type_float, local_symbols);
1283 parmvalue += sizeof (float);
1286 else { /* fixed parm, use (int*) for hex rep. */
1287 ADD_PARM_TO_PENDING (parm, parmvalue,
1288 lookup_pointer_type (builtin_type_int),
1290 parmvalue += sizeof (int);
1295 /* Fake this as a function. Needed in process_xcoff_symbol() */
1298 finish_block(process_xcoff_symbol (cs, objfile), &local_symbols,
1299 pending_blocks, cs->c_value,
1300 cs->c_value + ptb->fsize, objfile);
1304 /* shared library function trampoline code entry point. */
1305 else if (CSECT_SCLAS (main_aux) == XMC_GL) {
1307 /* record trampoline code entries as mst_unknown symbol. When we
1308 lookup mst symbols, we will choose mst_text over mst_unknown. */
1311 /* After the implementation of incremental loading of shared
1312 libraries, we don't want to access trampoline entries. This
1313 approach has a consequence of the necessity to bring the whole
1314 shared library at first, in order do anything with it (putting
1315 breakpoints, using malloc, etc). On the other side, this is
1316 consistient with gdb's behaviour on a SUN platform. */
1318 /* Trying to prefer *real* function entry over its trampoline,
1319 by assigning `mst_unknown' type to trampoline entries fails.
1320 Gdb treats those entries as chars. FIXME. */
1322 /* Recording this entry is necessary. Single stepping relies on
1323 this vector to get an idea about function address boundaries. */
1325 prim_record_minimal_symbol (0, cs->c_value, mst_unknown);
1328 /* record trampoline code entries as mst_unknown symbol. When we
1329 lookup mst symbols, we will choose mst_text over mst_unknown. */
1331 RECORD_MINIMAL_SYMBOL (cs->c_name, cs->c_value, mst_unknown,
1338 default : /* all other XTY_XXXs */
1340 } /* switch CSECT_SMTYP() */ }
1342 switch (cs->c_sclass) {
1346 /* see if the last csect needs to be recorded. */
1348 if (last_csect_name && !misc_func_recorded) {
1350 /* if no misc. function recorded in the last seen csect, enter
1351 it as a function. This will take care of functions like
1352 strcmp() compiled by xlc. */
1355 RECORD_MINIMAL_SYMBOL (last_csect_name, last_csect_val,
1359 /* c_value field contains symnum of next .file entry in table
1360 or symnum of first global after last .file. */
1362 next_file_symnum = cs->c_value;
1364 /* complete symbol table for last object file containing
1365 debugging information. */
1367 /* Whether or not there was a csect in the previous file, we have
1368 to call `end_symtab' and `start_symtab' to reset type_vector,
1369 line_vector, etc. structures. */
1371 complete_symtab (filestring, file_start_addr);
1372 cur_src_end_addr = file_end_addr;
1373 end_symtab (file_end_addr, 1, 0, objfile);
1374 start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
1375 last_csect_name = 0;
1377 /* reset file start and end addresses. A compilation unit with no text
1378 (only data) should have zero file boundaries. */
1379 file_start_addr = file_end_addr = 0;
1381 filestring = cs->c_name;
1387 #ifdef NO_DEFINE_SYMBOL
1388 /* For a function stab, just save its type in `fcn_type_saved', and leave
1389 it for the `.bf' processing. */
1391 char *pp = (char*) index (cs->c_name, ':');
1393 if (!pp || ( *(pp+1) != 'F' && *(pp+1) != 'f'))
1394 fatal ("Unrecognized stab");
1398 fatal ("Unprocessed function type");
1400 fcn_type_saved = lookup_function_type (read_type (&pp, objfile));
1403 fcn_stab_saved = *cs;
1409 if (strcmp (cs->c_name, ".bf") == 0) {
1411 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1414 within_function = 1;
1416 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
1421 1) xlc (IBM's native c compiler) postpones static function code
1422 emission to the end of a compilation unit. This way it can
1423 determine if those functions (statics) are needed or not, and
1424 can do some garbage collection (I think). This makes line
1425 numbers and corresponding addresses unordered, and we end up
1426 with a line table like:
1443 and that breaks gdb's binary search on line numbers, if the
1444 above table is not sorted on line numbers. And that sort
1445 should be on function based, since gcc can emit line numbers
1448 10 0x100 - for the init/test part of a for stmt.
1451 10 0x400 - for the increment part of a for stmt.
1453 arrange_linenos() will do this sorting.
1456 2) aix symbol table might look like:
1458 c_file // beginning of a new file
1459 .bi // beginning of include file
1460 .ei // end of include file
1464 basically, .bi/.ei pairs do not necessarily encapsulate
1465 their scope. They need to be recorded, and processed later
1466 on when we come the end of the compilation unit.
1467 Include table (inclTable) and process_linenos() handle
1470 mark_first_line (fcn_line_offset, cs->c_symnum);
1472 new = push_context (0, fcn_start_addr);
1474 #ifdef NO_DEFINE_SYMBOL
1475 new->name = process_xcoff_symbol (&fcn_cs_saved, objfile);
1477 /* Between a function symbol and `.bf', there always will be a function
1478 stab. We save function type when processing that stab. */
1480 if (fcn_type_saved == NULL) {
1481 printf ("Unknown function type: symbol 0x%x\n", cs->c_symnum);
1482 SYMBOL_TYPE (new->name) = lookup_function_type (builtin_type_int);
1485 SYMBOL_TYPE (new->name) = fcn_type_saved;
1486 fcn_type_saved = NULL;
1489 new->name = define_symbol
1490 (fcn_cs_saved.c_value, fcn_stab_saved.c_name, 0, 0, objfile);
1493 else if (strcmp (cs->c_name, ".ef") == 0) {
1495 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1498 /* the value of .ef is the address of epilogue code;
1499 not useful for gdb */
1500 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1501 contains number of lines to '}' */
1503 fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1504 new = pop_context ();
1505 if (context_stack_depth != 0)
1506 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1509 finish_block (new->name, &local_symbols, new->old_blocks,
1511 fcn_cs_saved.c_value +
1512 fcn_aux_saved.x_sym.x_misc.x_fsize, objfile);
1513 within_function = 0;
1517 case C_BSTAT : /* begin static block */
1518 static_block_base = read_symbol_nvalue (symtbl, cs->c_value);
1521 case C_ESTAT : /* end of static block */
1522 static_block_base = 0;
1525 case C_ARG : /* These are not implemented. */
1531 printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
1534 case C_HIDEXT : /* ignore these.. */
1539 case C_BINCL : /* beginning of include file */
1541 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1542 order. Thus, when wee see them, we might not know enough info
1543 to process them. Thus, we'll be saving them into a table
1544 (inclTable) and postpone their processing. */
1546 record_include_begin (cs);
1549 case C_EINCL : /* end of include file */
1550 /* see the comment after case C_BINCL. */
1551 record_include_end (cs);
1555 if (strcmp (cs->c_name, ".bb") == 0) {
1557 new = push_context (depth, cs->c_value);
1559 else if (strcmp (cs->c_name, ".eb") == 0) {
1560 new = pop_context ();
1561 if (depth != new->depth)
1562 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1566 if (local_symbols && context_stack_depth > 0) {
1567 /* Make a block for the local symbols within. */
1568 finish_block (new->name, &local_symbols, new->old_blocks,
1569 new->start_addr, cs->c_value, objfile);
1571 local_symbols = new->locals;
1576 process_xcoff_symbol (cs, objfile);
1582 if (last_source_file)
1583 end_symtab (cur_src_end_addr, 1, 0, objfile);
1586 current_objfile = NULL;
1588 /* Record the toc offset value of this symbol table into ldinfo structure.
1589 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1590 this information would be file auxiliary header. */
1592 xcoff_add_toc_to_loadinfo (toc_offset);
1595 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1596 (SYMBOL2) = (struct symbol *) \
1597 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1598 *(SYMBOL2) = *(SYMBOL1);
1601 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1602 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1605 /* process one xcoff symbol. */
1607 static struct symbol *
1608 process_xcoff_symbol (cs, objfile)
1609 register struct coff_symbol *cs;
1610 struct objfile *objfile;
1612 struct symbol onesymbol;
1613 register struct symbol *sym = &onesymbol;
1614 struct symbol *sym2 = NULL;
1616 char *name, *pp, *qq;
1617 int struct_and_type_combined;
1624 bzero (sym, sizeof (struct symbol));
1626 /* default assumptions */
1627 SYMBOL_VALUE (sym) = cs->c_value;
1628 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1630 if (ISFCN (cs->c_type)) {
1632 /* At this point, we don't know the type of the function and assume it
1633 is int. This will be patched with the type from its stab entry later
1634 on in patch_block_stabs () */
1636 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1637 SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (objfile, FT_INTEGER));
1639 SYMBOL_CLASS (sym) = LOC_BLOCK;
1640 SYMBOL_DUP (sym, sym2);
1642 if (cs->c_sclass == C_EXT)
1643 add_symbol_to_list (sym2, &global_symbols);
1644 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1645 add_symbol_to_list (sym2, &file_symbols);
1650 /* in case we can't figure out the type, default is `int'. */
1651 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, FT_INTEGER);
1653 switch (cs->c_sclass)
1657 if (fcn_cs_saved.c_sclass == C_EXT)
1658 add_stab_to_list (name, &global_stabs);
1660 add_stab_to_list (name, &file_stabs);
1664 case C_DECL: /* a type decleration?? */
1666 #if defined(NO_TYPEDEFS) || defined(NO_DEFINE_SYMBOL)
1667 qq = (char*) strchr (name, ':');
1668 if (!qq) /* skip if there is no ':' */
1671 nameless = (qq == name);
1673 struct_and_type_combined = (qq[1] == 'T' && qq[2] == 't');
1674 pp = qq + (struct_and_type_combined ? 3 : 2);
1677 /* To handle GNU C++ typename abbreviation, we need to be able to fill
1678 in a type's name as soon as space for that type is allocated. */
1680 if (struct_and_type_combined && name != qq) {
1683 struct type *tmp_type;
1686 read_type_number (&tmp_pp, typenums);
1687 tmp_type = dbx_alloc_type (typenums, objfile);
1689 if (tmp_type && !TYPE_NAME (tmp_type) && !nameless)
1690 TYPE_NAME (tmp_type) = SYMBOL_NAME (sym) =
1691 obsavestring (name, qq-name,
1692 &objfile->symbol_obstack);
1694 ttype = SYMBOL_TYPE (sym) = read_type (&pp);
1696 /* if there is no name for this typedef, you don't have to keep its
1697 symbol, since nobody could ask for it. Otherwise, build a symbol
1698 and add it into symbol_list. */
1704 /* Transarc wants to eliminate type definitions from the symbol table.
1705 Limited debugging capabilities, but faster symbol table processing
1706 and less memory usage. Note that tag definitions (starting with
1707 'T') will remain intact. */
1709 if (qq[1] != 'T' && (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0')) {
1711 if (SYMBOL_NAME (sym))
1712 TYPE_NAME (ttype) = SYMBOL_NAME (sym);
1714 TYPE_NAME (ttype) = obsavestring (name, qq-name);
1719 #endif /* !NO_TYPEDEFS */
1721 /* read_type() will return null if type (or tag) definition was
1722 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
1723 there is no need to keep it in symbol table. */
1724 /* The above argument no longer valid. read_type() never returns NULL. */
1729 /* if there is no name for this typedef, you don't have to keep its
1730 symbol, since nobody could ask for it. Otherwise, build a symbol
1731 and add it into symbol_list. */
1734 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1735 else if (qq[1] == 't')
1736 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1738 warning ("Unrecognized stab string.\n");
1742 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1743 if (!SYMBOL_NAME (sym))
1744 SYMBOL_NAME (sym) = obsavestring (name, qq-name);
1746 SYMBOL_DUP (sym, sym2);
1748 (sym2, within_function ? &local_symbols : &file_symbols);
1750 /* For a combination of struct and type, add one more symbol
1753 if (struct_and_type_combined) {
1754 SYMBOL_DUP (sym, sym2);
1755 SYMBOL_NAMESPACE (sym2) = VAR_NAMESPACE;
1757 (sym2, within_function ? &local_symbols : &file_symbols);
1760 /* assign a name to the type node. */
1762 if (!TYPE_NAME (ttype) || *(TYPE_NAME (ttype)) == '\0') {
1763 if (struct_and_type_combined)
1764 TYPE_NAME (ttype) = SYMBOL_NAME (sym);
1765 else if (qq[1] == 'T') /* struct namespace */
1766 TYPE_NAME (ttype) = concat (
1767 TYPE_CODE (ttype) == TYPE_CODE_UNION ? "union " :
1768 TYPE_CODE (ttype) == TYPE_CODE_STRUCT? "struct " : "enum ",
1769 SYMBOL_NAME (sym), NULL);
1773 #else /* !NO_DEFINE_SYMBOL */
1774 return define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1778 add_stab_to_list (name, &global_stabs);
1784 #ifdef NO_DEFINE_SYMBOL
1785 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1787 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
1788 SYMBOL_CLASS (sym) = (cs->c_sclass == C_PSYM) ? LOC_ARG : LOC_REGPARM;
1790 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
1791 SYMBOL_DUP (sym, sym2);
1792 add_symbol_to_list (sym2, &local_symbols);
1795 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1796 SYMBOL_CLASS (sym) = (cs->c_sclass == C_PSYM) ? LOC_ARG : LOC_REGPARM;
1802 #ifdef NO_DEFINE_SYMBOL
1803 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1805 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
1806 SYMBOL_CLASS (sym) = LOC_STATIC;
1807 SYMBOL_VALUE (sym) += static_block_base;
1809 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
1810 SYMBOL_DUP (sym, sym2);
1812 (sym2, within_function ? &local_symbols : &file_symbols);
1815 /* If we are going to use Sun dbx's define_symbol(), we need to
1816 massage our stab string a little. Change 'V' type to 'S' to be
1817 comparible with Sun. */
1819 if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
1823 if (*pp == 'V') *pp = 'S';
1824 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1825 SYMBOL_VALUE (sym) += static_block_base;
1830 if (*name == ':' || (pp = (char *) strchr (name, ':')) == NULL)
1832 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
1833 SYMBOL_CLASS (sym) = LOC_LOCAL;
1835 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
1836 SYMBOL_DUP (sym, sym2);
1837 add_symbol_to_list (sym2, &local_symbols);
1841 SYMBOL_CLASS (sym) = LOC_LOCAL;
1842 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1843 SYMBOL_DUP (sym, sym2);
1844 add_symbol_to_list (sym2, &local_symbols);
1848 SYMBOL_CLASS (sym) = LOC_STATIC;
1849 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1850 SYMBOL_DUP (sym, sym2);
1851 add_symbol_to_list (sym2, &global_symbols);
1855 SYMBOL_CLASS (sym) = LOC_STATIC;
1856 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1857 SYMBOL_DUP (sym, sym2);
1859 (sym2, within_function ? &local_symbols : &file_symbols);
1863 printf ("ERROR! C_REG is not fully implemented!\n");
1864 SYMBOL_CLASS (sym) = LOC_REGISTER;
1865 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1866 SYMBOL_DUP (sym, sym2);
1867 add_symbol_to_list (sym2, &local_symbols);
1872 #ifdef NO_DEFINE_SYMBOL
1873 pp = (char*) strchr (name, ':');
1874 SYMBOL_CLASS (sym) = LOC_REGISTER;
1875 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value);
1877 SYMBOL_NAME (sym) = obsavestring (name, pp-name, &objfile -> symbol_obstack);
1880 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
1883 /* else this is not a stab entry, suppose the type is either
1884 `int' or `float', depending on the register class. */
1886 SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32)
1887 ? lookup_fundamental_type (objfile, FT_INTEGER)
1888 : lookup_fundamental_type (objfile, FT_FLOAT);
1890 SYMBOL_DUP (sym, sym2);
1891 add_symbol_to_list (sym2, &local_symbols);
1895 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1899 warning ("A non-stab C_RSYM needs special handling.");
1905 warning ("Unexpected storage class: %d.", cs->c_sclass);
1914 read_symbol_nvalue (symtable, symno)
1918 struct internal_syment symbol[1];
1920 bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol);
1921 return symbol->n_value;
1926 read_symbol_lineno (symtable, symno)
1930 struct internal_syment symbol[1];
1931 union internal_auxent main_aux[1];
1935 for (ii = 0; ii < 50; ii++) {
1936 bfd_coff_swap_sym_in (symfile_bfd,
1937 symtable + (symno*local_symesz), symbol);
1938 if (symbol->n_sclass == C_FCN && 0 == strcmp (symbol->n_name, ".bf"))
1940 symno += symbol->n_numaux+1;
1943 printf ("GDB Error: `.bf' not found.\n");
1947 /* take aux entry and return its lineno */
1949 bfd_coff_swap_aux_in (symfile_bfd, symtable+(symno*local_symesz),
1950 symbol->n_type, symbol->n_sclass, main_aux);
1952 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
1955 /* Support for line number handling */
1957 /* This function is called for every section; it finds the outer limits
1958 * of the line table (minimum and maximum file offset) so that the
1959 * mainline code can read the whole thing for efficiency.
1962 find_linenos(abfd, asect, vpinfo)
1967 struct coff_symfile_info *info;
1969 file_ptr offset, maxoff;
1971 count = asect->lineno_count;
1973 if (strcmp (asect->name, ".text") || count == 0)
1976 size = count * coff_data (symfile_bfd)->local_linesz;
1977 info = (struct coff_symfile_info *)vpinfo;
1978 offset = asect->line_filepos;
1979 maxoff = offset + size;
1981 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1982 info->min_lineno_offset = offset;
1984 if (maxoff > info->max_lineno_offset)
1985 info->max_lineno_offset = maxoff;
1989 /* Read in all the line numbers for fast lookups later. Leave them in
1990 external (unswapped) format in memory; we'll swap them as we enter
1991 them into GDB's data structures. */
1994 init_lineno (abfd, offset, size)
2001 if (bfd_seek(abfd, offset, 0) < 0)
2004 linetab = (char *) xmalloc(size);
2006 val = bfd_read(linetab, 1, size, abfd);
2010 linetab_offset = offset;
2011 linetab_size = size;
2012 make_cleanup (free, linetab); /* Be sure it gets de-allocated. */
2016 /* dbx allows the text of a symbol name to be continued into the
2017 next symbol name! When such a continuation is encountered
2018 (a \ at the end of the text of a name)
2019 call this function to get the continuation. */
2020 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
2023 #undef next_symbol_text
2024 #define next_symbol_text() \
2025 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
2028 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
2029 the proper type node fora given builtin type #. */
2038 printf ("ERROR!, unknown built-in type!\n");
2042 read_type_number (pp, typenums);
2044 /* default types are defined in dbxstclass.h. */
2045 switch ( typenums[1] ) {
2047 return lookup_fundamental_type (current_objfile, FT_INTEGER);
2049 return lookup_fundamental_type (current_objfile, FT_CHAR);
2051 return lookup_fundamental_type (current_objfile, FT_SHORT);
2053 return lookup_fundamental_type (current_objfile, FT_LONG);
2055 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
2057 return lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR);
2059 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
2061 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
2063 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
2065 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
2067 return lookup_fundamental_type (current_objfile, FT_VOID);
2069 return lookup_fundamental_type (current_objfile, FT_FLOAT);
2071 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
2073 return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
2075 /* requires a builtin `integer' */
2076 return lookup_fundamental_type (current_objfile, FT_INTEGER);
2078 return lookup_fundamental_type (current_objfile, FT_BOOLEAN);
2080 /* requires builtin `short real' */
2081 return lookup_fundamental_type (current_objfile, FT_FLOAT);
2083 /* requires builtin `real' */
2084 return lookup_fundamental_type (current_objfile, FT_FLOAT);
2086 printf ("ERROR! Unknown builtin type -%d\n", typenums[1]);
2091 #if 0 /* Seems to be unused, don't bother converting from old misc function
2092 vector usage to new minimal symbol tables. FIXME: Delete this? */
2094 /* if we now nothing about a function but its address, make a function symbol
2095 out of it with the limited knowladge you have. This will be used when
2096 somebody refers to a function, which doesn't exist in the symbol table,
2097 but is in the minimal symbol table. */
2100 build_function_symbol (ind, objfile)
2102 struct objfile *objfile;
2104 struct symbol *sym =
2105 (struct symbol *) obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2106 SYMBOL_NAME (sym) = misc_function_vector[ind].name;
2107 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
2108 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2109 SYMBOL_CLASS (sym) = LOC_BLOCK;
2110 SYMBOL_TYPE (sym) = lookup_function_type (lookup_fundamental_type (current_objfile, FT_INTEGER));
2111 SYMBOL_BLOCK_VALUE (sym) = (struct block *)
2112 obstack_alloc (&objfile->symbol_obstack, sizeof (struct block));
2113 BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) = misc_function_vector[ind].address;
2120 aixcoff_new_init (objfile)
2121 struct objfile *objfile;
2126 aixcoff_symfile_init (objfile)
2127 struct objfile *objfile;
2129 bfd *abfd = objfile->obfd;
2131 /* Allocate struct to keep track of the symfile */
2132 objfile -> sym_private = xmmalloc (objfile -> md,
2133 sizeof (struct coff_symfile_info));
2134 init_entry_point_info (objfile);
2137 /* Perform any local cleanups required when we are done with a particular
2138 objfile. I.E, we are in the process of discarding all symbol information
2139 for an objfile, freeing up all memory held for it, and unlinking the
2140 objfile struct from the global list of known objfiles. */
2143 aixcoff_symfile_finish (objfile)
2144 struct objfile *objfile;
2146 if (objfile -> sym_private != NULL)
2148 mfree (objfile -> md, objfile -> sym_private);
2151 /* Start with a fresh include table for the next objfile. */
2158 inclIndx = inclLength = inclDepth = 0;
2163 init_stringtab(abfd, offset, objfile)
2166 struct objfile *objfile;
2170 unsigned char lengthbuf[4];
2172 if (bfd_seek(abfd, offset, 0) < 0)
2175 val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
2176 length = bfd_h_get_32(abfd, lengthbuf);
2178 /* If no string table is needed, then the file may end immediately
2179 after the symbols. Just return with `strtbl' set to null. */
2181 if (val != sizeof length || length < sizeof length)
2184 /* Allocate string table from symbol_obstack. We will need this table
2185 as long as we have its symbol table around. */
2187 strtbl = (char*) obstack_alloc (&objfile->symbol_obstack, length);
2191 bcopy(&length, strtbl, sizeof length);
2192 if (length == sizeof length)
2195 val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd);
2197 if (val != length - sizeof length || strtbl[length - 1] != '\0')
2204 init_debugsection(abfd)
2207 register sec_ptr secp;
2208 bfd_size_type length;
2215 secp = bfd_get_section_by_name(abfd, ".debug");
2219 if (!(length = bfd_section_size(abfd, secp)))
2222 debugsec = (char *) xmalloc ((unsigned)length);
2223 if (debugsec == NULL)
2226 if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) {
2227 printf ("Can't read .debug section from symbol file\n");
2242 /* aixcoff version of symbol file read. */
2245 aixcoff_symfile_read (objfile, section_offset, mainline)
2246 struct objfile *objfile;
2247 struct section_offset *section_offset;
2250 int num_symbols; /* # of symbols */
2251 int symtab_offset; /* symbol table and */
2252 int stringtab_offset; /* string table file offsets */
2255 struct coff_symfile_info *info;
2258 info = (struct coff_symfile_info *) objfile -> sym_private;
2259 symfile_bfd = abfd = objfile->obfd;
2260 name = objfile->name;
2262 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2263 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2264 stringtab_offset = symtab_offset +
2265 num_symbols * coff_data(abfd)->local_symesz;
2267 info->min_lineno_offset = 0;
2268 info->max_lineno_offset = 0;
2269 bfd_map_over_sections (abfd, find_linenos, info);
2271 /* FIXME! This stuff should move into symfile_init */
2272 if (info->min_lineno_offset != 0
2273 && info->max_lineno_offset > info->min_lineno_offset) {
2275 /* only read in the line # table if one exists */
2276 val = init_lineno(abfd, info->min_lineno_offset,
2277 info->max_lineno_offset - info->min_lineno_offset);
2280 error("\"%s\": error reading line numbers\n", name);
2283 val = init_stringtab(abfd, stringtab_offset, objfile);
2285 error ("\"%s\": can't get string table", name);
2288 if (init_debugsection(abfd) < 0) {
2289 error ("Error reading .debug section of `%s'\n", name);
2292 /* Position to read the symbol table. Do not read it all at once. */
2293 val = bfd_seek(abfd, (long)symtab_offset, 0);
2295 perror_with_name(name);
2297 if (bfd_tell(abfd) != symtab_offset)
2300 init_minimal_symbol_collection ();
2301 make_cleanup (discard_minimal_symbols, 0);
2303 /* Initialize load info structure. */
2305 xcoff_init_loadinfo ();
2307 /* Now that the executable file is positioned at symbol table,
2308 process it and define symbols accordingly. */
2310 read_xcoff_symtab(objfile, num_symbols);
2312 /* Free debug section. */
2313 free_debugsection ();
2315 /* Sort symbols alphabetically within each block. */
2318 /* Install any minimal symbols that have been collected as the current
2319 minimal symbols for this objfile. */
2321 install_minimal_symbols (objfile);
2323 /* Make a default for file to list. */
2324 select_source_symtab (0);
2327 /* XCOFF-specific parsing routine for section offsets.
2328 Plain and simple for now. */
2331 struct section_offsets *
2332 aixcoff_symfile_offsets (objfile, addr)
2333 struct objfile *objfile;
2336 struct section_offsets *section_offsets;
2339 section_offsets = (struct section_offsets *)
2340 obstack_alloc (&objfile -> psymbol_obstack,
2341 sizeof (struct section_offsets) +
2342 sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
2344 for (i = 0; i < SECT_OFF_MAX; i++)
2345 ANOFFSET (section_offsets, i) = addr;
2347 return section_offsets;
2349 /* Register our ability to parse symbols for aixcoff BFD files. */
2351 static struct sym_fns aixcoff_sym_fns =
2353 "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */
2354 15, /* sym_namelen: number of significant sym_name chars */
2355 aixcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2356 aixcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2357 aixcoff_symfile_read, /* sym_read: read a symbol file into symtab */
2358 aixcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
2359 aixcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
2360 NULL /* next: pointer to next struct sym_fns */
2364 _initialize_xcoffread ()
2366 add_symtab_fns(&aixcoff_sym_fns);
2369 #else /* IBM6000_HOST */
2371 builtin_type (ignore)
2374 fatal ("GDB internal eror: builtin_type called on non-RS/6000!");
2376 #endif /* IBM6000_HOST */