1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc.
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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>
35 #include "gdb_string.h"
38 #include <sys/param.h>
43 #include <sys/debug.h>
45 #include "coff/internal.h"
46 #include "libcoff.h" /* FIXME, internal data from BFD */
47 #include "coff/rs6000.h"
54 #include "stabsread.h"
55 #include "complaints.h"
57 #include "gdb-stabs.h"
59 /* For interface with stabsread.c. */
60 #include "aout/stab_gnu.h"
62 /* For interface with partial-stab.h. */
63 #define N_UNDF 0 /* Undefined symbol */
66 #define N_TEXT 4 /* Text sym -- defined at offset in text seg */
67 #define N_DATA 6 /* Data sym -- defined at offset in data seg */
68 #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */
69 #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */
70 #define N_FN 0x1f /* File name of .o file */
71 #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
72 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
73 N_DATA, or N_BSS. When the low-order bit of other types is set,
74 (e.g. N_WARNING versus N_FN), they are two different types. */
75 #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */
78 /* The following symbols refer to set elements.
79 All the N_SET[ATDB] symbols with the same name form one set.
80 Space is allocated for the set in the text section, and each set
81 elements value is stored into one word of the space.
82 The first word of the space is the length of the set (number of elements).
84 The address of the set is made into an N_SETV symbol
85 whose name is the same as the name of the set.
86 This symbol acts like a N_DATA global symbol
87 in that it can satisfy undefined external references. */
89 /* These appear as input to LD, in a .o file. */
90 #define N_SETA 0x14 /* Absolute set element symbol */
91 #define N_SETT 0x16 /* Text set element symbol */
92 #define N_SETD 0x18 /* Data set element symbol */
93 #define N_SETB 0x1A /* Bss set element symbol */
95 /* This is output from LD. */
96 #define N_SETV 0x1C /* Pointer to set vector in data area. */
98 /* We put a pointer to this structure in the read_symtab_private field
103 /* First symbol number for this file. */
107 /* Number of symbols in the section of the symbol table devoted to
108 this file's symbols (actually, the section bracketed may contain
109 more than just this file's symbols). If numsyms is 0, the only
110 reason for this thing's existence is the dependency list. Nothing
111 else will happen when it is read in. */
115 /* Position of the start of the line number information for this psymtab. */
116 unsigned int lineno_off;
119 /* Remember what we deduced to be the source language of this psymtab. */
121 static enum language psymtab_language = language_unknown;
124 /* Simplified internal version of coff symbol table information */
128 int c_symnum; /* symbol number of this entry */
129 int c_naux; /* 0 if syment only, 1 if syment + auxent */
131 unsigned char c_sclass;
136 /* The COFF line table, in raw form. */
137 static char *linetab = NULL; /* Its actual contents */
138 static long linetab_offset; /* Its offset in the file */
139 static unsigned long linetab_size; /* Its size */
141 /* last function's saved coff symbol `cs' */
143 static struct coff_symbol fcn_cs_saved;
145 static bfd *symfile_bfd;
147 /* Core address of start and end of text of current source file.
148 This is calculated from the first function seen after a C_FILE
152 static CORE_ADDR cur_src_end_addr;
154 /* Core address of the end of the first object file. */
156 static CORE_ADDR first_object_file_end;
158 /* initial symbol-table-debug-string vector length */
160 #define INITIAL_STABVECTOR_LENGTH 40
162 /* Nonzero if within a function (so symbols should be local,
163 if nothing says specifically). */
167 /* Size of a COFF symbol. I think it is always 18, so I'm not sure
168 there is any reason not to just use a #define, but might as well
169 ask BFD for the size and store it here, I guess. */
171 static unsigned local_symesz;
173 struct coff_symfile_info {
174 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
175 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
177 /* Pointer to the string table. */
180 /* Pointer to debug section. */
183 /* Pointer to the a.out symbol table. */
186 /* Number of symbols in symtbl. */
190 static struct complaint rsym_complaint =
191 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
193 static struct complaint storclass_complaint =
194 {"Unexpected storage class: %d", 0, 0};
196 static struct complaint bf_notfound_complaint =
197 {"line numbers off, `.bf' symbol not found", 0, 0};
199 extern struct complaint ef_complaint;
200 extern struct complaint eb_complaint;
203 enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
204 CORE_ADDR, CORE_ADDR, unsigned *));
207 init_stringtab PARAMS ((bfd *, file_ptr, struct objfile *));
210 xcoff_symfile_init PARAMS ((struct objfile *));
213 xcoff_new_init PARAMS ((struct objfile *));
216 xcoff_symfile_finish PARAMS ((struct objfile *));
218 static struct section_offsets *
219 xcoff_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
222 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
225 coff_getfilename PARAMS ((union internal_auxent *, struct objfile *));
228 read_symbol PARAMS ((struct internal_syment *, int));
231 read_symbol_lineno PARAMS ((int));
234 read_symbol_nvalue PARAMS ((int));
236 static struct symbol *
237 process_xcoff_symbol PARAMS ((struct coff_symbol *, struct objfile *));
240 read_xcoff_symtab PARAMS ((struct partial_symtab *));
243 add_stab_to_list PARAMS ((char *, struct pending_stabs **));
246 /* Translate from a COFF section number (target_index) to a SECT_OFF_*
248 static int secnum_to_section PARAMS ((int, struct objfile *));
250 struct find_targ_sec_arg {
255 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
257 static void find_targ_sec (abfd, sect, obj)
262 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
263 if (sect->target_index == args->targ_index)
265 /* This is the section. Figure out what SECT_OFF_* code it is. */
266 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
267 *args->resultp = SECT_OFF_TEXT;
268 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
269 *args->resultp = SECT_OFF_DATA;
271 *args->resultp = SECT_OFF_BSS;
275 /* Return the section number (SECT_OFF_*) that CS points to. */
277 secnum_to_section (secnum, objfile)
279 struct objfile *objfile;
281 int off = SECT_OFF_TEXT;
282 struct find_targ_sec_arg args;
283 args.targ_index = secnum;
285 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
289 /* add a given stab string into given stab vector. */
292 add_stab_to_list (stabname, stabvector)
294 struct pending_stabs **stabvector;
296 if ( *stabvector == NULL) {
297 *stabvector = (struct pending_stabs *)
298 xmalloc (sizeof (struct pending_stabs) +
299 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
300 (*stabvector)->count = 0;
301 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
303 else if ((*stabvector)->count >= (*stabvector)->length) {
304 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
305 *stabvector = (struct pending_stabs *)
306 xrealloc ((char *) *stabvector, sizeof (struct pending_stabs) +
307 (*stabvector)->length * sizeof (char*));
309 (*stabvector)->stab [(*stabvector)->count++] = stabname;
312 /* Linenos are processed on a file-by-file basis.
316 1) xlc (IBM's native c compiler) postpones static function code
317 emission to the end of a compilation unit. This way it can
318 determine if those functions (statics) are needed or not, and
319 can do some garbage collection (I think). This makes line
320 numbers and corresponding addresses unordered, and we end up
321 with a line table like:
338 and that breaks gdb's binary search on line numbers, if the
339 above table is not sorted on line numbers. And that sort
340 should be on function based, since gcc can emit line numbers
343 10 0x100 - for the init/test part of a for stmt.
346 10 0x400 - for the increment part of a for stmt.
348 arrange_linetable() will do this sorting.
350 2) aix symbol table might look like:
352 c_file // beginning of a new file
353 .bi // beginning of include file
354 .ei // end of include file
358 basically, .bi/.ei pairs do not necessarily encapsulate
359 their scope. They need to be recorded, and processed later
360 on when we come the end of the compilation unit.
361 Include table (inclTable) and process_linenos() handle
364 /* compare line table entry addresses. */
367 compare_lte (lte1, lte2)
368 struct linetable_entry *lte1, *lte2;
370 return lte1->pc - lte2->pc;
373 /* Give a line table with function entries are marked, arrange its functions
374 in assending order and strip off function entry markers and return it in
375 a newly created table. If the old one is good enough, return the old one. */
376 /* FIXME: I think all this stuff can be replaced by just passing
377 sort_linevec = 1 to end_symtab. */
379 static struct linetable *
380 arrange_linetable (oldLineTb)
381 struct linetable *oldLineTb; /* old linetable */
384 newline, /* new line count */
385 function_count; /* # of functions */
387 struct linetable_entry *fentry; /* function entry vector */
388 int fentry_size; /* # of function entries */
389 struct linetable *newLineTb; /* new line table */
391 #define NUM_OF_FUNCTIONS 20
393 fentry_size = NUM_OF_FUNCTIONS;
394 fentry = (struct linetable_entry*)
395 xmalloc (fentry_size * sizeof (struct linetable_entry));
397 for (function_count=0, ii=0; ii <oldLineTb->nitems; ++ii) {
399 if (oldLineTb->item[ii].line == 0) { /* function entry found. */
401 if (function_count >= fentry_size) { /* make sure you have room. */
403 fentry = (struct linetable_entry*)
404 xrealloc (fentry, fentry_size * sizeof (struct linetable_entry));
406 fentry[function_count].line = ii;
407 fentry[function_count].pc = oldLineTb->item[ii].pc;
412 if (function_count == 0) {
416 else if (function_count > 1)
417 qsort (fentry, function_count, sizeof(struct linetable_entry), compare_lte);
419 /* allocate a new line table. */
420 newLineTb = (struct linetable *)
422 (sizeof (struct linetable) +
423 (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry));
425 /* if line table does not start with a function beginning, copy up until
429 if (oldLineTb->item[0].line != 0)
431 newline < oldLineTb->nitems && oldLineTb->item[newline].line; ++newline)
432 newLineTb->item[newline] = oldLineTb->item[newline];
434 /* Now copy function lines one by one. */
436 for (ii=0; ii < function_count; ++ii) {
437 for (jj = fentry[ii].line + 1;
438 jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0;
440 newLineTb->item[newline] = oldLineTb->item[jj];
443 newLineTb->nitems = oldLineTb->nitems - function_count;
447 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
448 following `IncludeChain'. At the end of each symtab (end_symtab),
449 we will determine if we should create additional symtab's to
450 represent if (the include files. */
453 typedef struct _inclTable {
454 char *name; /* include filename */
456 /* Offsets to the line table. end points to the last entry which is
457 part of this include file. */
460 struct subfile *subfile;
461 unsigned funStartLine; /* start line # of its function */
464 #define INITIAL_INCLUDE_TABLE_LENGTH 20
465 static InclTable *inclTable; /* global include table */
466 static int inclIndx; /* last entry to table */
467 static int inclLength; /* table length */
468 static int inclDepth; /* nested include depth */
470 static void allocate_include_entry PARAMS ((void));
473 record_include_begin (cs)
474 struct coff_symbol *cs;
478 /* In xcoff, we assume include files cannot be nested (not in .c files
479 of course, but in corresponding .s files.). */
481 /* This can happen with old versions of GCC.
482 GCC 2.3.3-930426 does not exhibit this on a test case which
483 a user said produced the message for him. */
484 static struct complaint msg = {"Nested C_BINCL symbols", 0, 0};
489 allocate_include_entry ();
491 inclTable [inclIndx].name = cs->c_name;
492 inclTable [inclIndx].begin = cs->c_value;
496 record_include_end (cs)
497 struct coff_symbol *cs;
503 static struct complaint msg = {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
507 allocate_include_entry ();
509 pTbl = &inclTable [inclIndx];
510 pTbl->end = cs->c_value;
517 allocate_include_entry ()
519 if (inclTable == NULL)
521 inclTable = (InclTable *)
522 xmalloc (sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
524 '\0', sizeof (InclTable) * INITIAL_INCLUDE_TABLE_LENGTH);
525 inclLength = INITIAL_INCLUDE_TABLE_LENGTH;
528 else if (inclIndx >= inclLength)
530 inclLength += INITIAL_INCLUDE_TABLE_LENGTH;
531 inclTable = (InclTable *)
532 xrealloc (inclTable, sizeof (InclTable) * inclLength);
533 memset (inclTable + inclLength - INITIAL_INCLUDE_TABLE_LENGTH,
534 '\0', sizeof (InclTable)*INITIAL_INCLUDE_TABLE_LENGTH);
538 /* Global variable to pass the psymtab down to all the routines involved
539 in psymtab to symtab processing. */
540 static struct partial_symtab *this_symtab_psymtab;
542 /* given the start and end addresses of a compilation unit (or a csect,
543 at times) process its lines and create appropriate line vectors. */
546 process_linenos (start, end)
547 CORE_ADDR start, end;
551 file_ptr max_offset =
552 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
555 /* subfile structure for the main compilation unit. */
556 struct subfile main_subfile;
558 /* In the main source file, any time we see a function entry, we
559 reset this variable to function's absolute starting line number.
560 All the following line numbers in the function are relative to
561 this, and we record absolute line numbers in record_line(). */
563 int main_source_baseline = 0;
569 ((struct symloc *)this_symtab_psymtab->read_symtab_private)->lineno_off;
571 goto return_after_cleanup;
573 memset (&main_subfile, '\0', sizeof (main_subfile));
576 /* All source lines were in the main source file. None in include files. */
578 enter_line_range (&main_subfile, offset, 0, start, end,
579 &main_source_baseline);
583 /* There was source with line numbers in include files. */
584 main_source_baseline = 0;
585 for (ii=0; ii < inclIndx; ++ii)
587 struct subfile *tmpSubfile;
589 /* If there is main file source before include file, enter it. */
590 if (offset < inclTable[ii].begin)
593 (&main_subfile, offset, inclTable[ii].begin - LINESZ,
594 start, 0, &main_source_baseline);
597 /* Have a new subfile for the include file. */
599 tmpSubfile = inclTable[ii].subfile =
600 (struct subfile *) xmalloc (sizeof (struct subfile));
602 memset (tmpSubfile, '\0', sizeof (struct subfile));
603 firstLine = &(inclTable[ii].funStartLine);
605 /* Enter include file's lines now. */
606 enter_line_range (tmpSubfile, inclTable[ii].begin,
607 inclTable[ii].end, start, 0, firstLine);
609 if (offset < = inclTable[ii].end)
610 offset = inclTable[ii].end + LINESZ;
613 /* All the include files' line have been processed at this point. Now,
614 enter remaining lines of the main file, if any left. */
615 if (offset < max_offset + 1 - LINESZ)
617 enter_line_range (&main_subfile, offset, 0, start, end,
618 &main_source_baseline);
622 /* Process main file's line numbers. */
623 if (main_subfile.line_vector)
625 struct linetable *lineTb, *lv;
627 lv = main_subfile.line_vector;
629 /* Line numbers are not necessarily ordered. xlc compilation will
630 put static function to the end. */
632 lineTb = arrange_linetable (lv);
635 current_subfile->line_vector = (struct linetable *)
636 xrealloc (lv, (sizeof (struct linetable)
637 + lv->nitems * sizeof (struct linetable_entry)));
642 current_subfile->line_vector = lineTb;
645 current_subfile->line_vector_length =
646 current_subfile->line_vector->nitems;
649 /* Now, process included files' line numbers. */
651 for (ii=0; ii < inclIndx; ++ii)
653 if ((inclTable[ii].subfile)->line_vector) /* Useless if!!! FIXMEmgo */
655 struct linetable *lineTb, *lv;
657 lv = (inclTable[ii].subfile)->line_vector;
659 /* Line numbers are not necessarily ordered. xlc compilation will
660 put static function to the end. */
662 lineTb = arrange_linetable (lv);
666 /* For the same include file, we might want to have more than one
667 subfile. This happens if we have something like:
675 while foo.h including code in it. (stupid but possible)
676 Since start_subfile() looks at the name and uses an
677 existing one if finds, we need to provide a fake name and
681 start_subfile (inclTable[ii].name, (char*)0);
684 /* Pick a fake name that will produce the same results as this
685 one when passed to deduce_language_from_filename. Kludge on
687 char *fakename = strrchr (inclTable[ii].name, '.');
688 if (fakename == NULL)
690 start_subfile (fakename, (char*)0);
691 free (current_subfile->name);
693 current_subfile->name = strdup (inclTable[ii].name);
698 current_subfile->line_vector =
699 (struct linetable *) xrealloc
700 (lv, (sizeof (struct linetable)
701 + lv->nitems * sizeof (struct linetable_entry)));
707 current_subfile->line_vector = lineTb;
710 current_subfile->line_vector_length =
711 current_subfile->line_vector->nitems;
712 start_subfile (pop_subfile (), (char*)0);
716 return_after_cleanup:
718 /* We don't want to keep alloc/free'ing the global include file table. */
721 /* Start with a fresh subfile structure for the next file. */
722 memset (&main_subfile, '\0', sizeof (struct subfile));
726 aix_process_linenos ()
728 /* process line numbers and enter them into line vector */
729 process_linenos (last_source_start_addr, cur_src_end_addr);
733 /* Enter a given range of lines into the line vector.
734 can be called in the following two ways:
735 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
736 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
738 endoffset points to the last line table entry that we should pay
742 enter_line_range (subfile, beginoffset, endoffset, startaddr, endaddr,
744 struct subfile *subfile;
745 unsigned beginoffset, endoffset; /* offsets to line table */
746 CORE_ADDR startaddr, endaddr;
749 unsigned int curoffset;
751 struct external_lineno ext_lnno;
752 struct internal_lineno int_lnno;
753 unsigned int limit_offset;
756 if (endoffset == 0 && startaddr == 0 && endaddr == 0)
758 curoffset = beginoffset;
760 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
765 if (endoffset >= limit_offset)
767 static struct complaint msg =
768 {"Bad line table offset in C_EINCL directive", 0, 0};
772 limit_offset = endoffset;
776 abfd = this_symtab_psymtab->objfile->obfd;
778 while (curoffset <= limit_offset)
780 bfd_seek (abfd, curoffset, SEEK_SET);
781 bfd_read (&ext_lnno, sizeof (struct external_lineno), 1, abfd);
782 bfd_coff_swap_lineno_in (abfd, &ext_lnno, &int_lnno);
784 /* Find the address this line represents. */
785 addr = (int_lnno.l_lnno
786 ? int_lnno.l_addr.l_paddr
787 : read_symbol_nvalue (int_lnno.l_addr.l_symndx));
788 addr += ANOFFSET (this_symtab_psymtab->objfile->section_offsets,
791 if (addr < startaddr || (endaddr && addr >= endaddr))
794 if (int_lnno.l_lnno == 0)
796 *firstLine = read_symbol_lineno (int_lnno.l_addr.l_symndx);
797 record_line (subfile, 0, addr);
801 record_line (subfile, *firstLine + int_lnno.l_lnno, addr);
807 int fsize; /* file size */
808 int fixedparms; /* number of fixed parms */
809 int floatparms; /* number of float parms */
810 unsigned int parminfo; /* parameter info.
811 See /usr/include/sys/debug.h
812 tbtable_ext.parminfo */
813 int framesize; /* function frame size */
816 static TracebackInfo *retrieve_tracebackinfo
817 PARAMS ((bfd *, struct coff_symbol *));
819 /* Given a function symbol, return its traceback information. */
821 static TracebackInfo *
822 retrieve_tracebackinfo (abfd, cs)
824 struct coff_symbol *cs;
826 #define TBTABLE_BUFSIZ 2000
828 static TracebackInfo tbInfo;
831 static char buffer [TBTABLE_BUFSIZ];
834 int bytesread=0; /* total # of bytes read so far */
835 int bufferbytes; /* number of bytes in the buffer */
840 /* FIXME: Should be looking through all sections, based on the
841 address we are considering. Just using ".text" loses if more
842 than one section has code in it. */
843 textsec = bfd_get_section_by_name (abfd, ".text");
847 /* If there is only data, no text, that is OK. */
848 printf_unfiltered ("Unable to locate text section!\n");
853 functionstart = cs->c_value - textsec->vma;
855 memset (&tbInfo, '\0', sizeof (tbInfo));
857 /* keep reading blocks of data from the text section, until finding a zero
858 word and a traceback table. */
860 /* Note: The logical thing way to write this code would be to assign
861 to bufferbytes within the while condition. But that triggers a
862 compiler (xlc in AIX 3.2) bug, so simplify it... */
864 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
865 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
867 && (bfd_get_section_contents
868 (abfd, textsec, buffer,
869 (file_ptr)(functionstart + bytesread), bufferbytes)))
871 bytesread += bufferbytes;
872 pinsn = (int*) buffer;
874 /* If this is the first time we filled the buffer, retrieve function
877 if (bytesread == bufferbytes) {
879 /* skip over unrelated instructions */
881 if (*pinsn == 0x7c0802a6) /* mflr r0 */
883 if ((*pinsn & 0xfc00003e) == 0x7c000026) /* mfcr Rx */
885 if ((*pinsn & 0xfc000000) == 0x48000000) /* bl foo, save fprs */
887 if ((*pinsn & 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
891 int tmp = (*pinsn >> 16) & 0xffff;
893 if (tmp == 0x9421) { /* stu r1, NUM(r1) */
894 tbInfo.framesize = 0x10000 - (*pinsn & 0xffff);
897 else if ((*pinsn == 0x93e1fffc) || /* st r31,-4(r1) */
898 (tmp == 0x9001)) /* st r0, NUM(r1) */
900 /* else, could not find a frame size. */
904 } while (++pinsn && *pinsn);
906 if (!tbInfo.framesize)
911 /* look for a zero word. */
913 while (*pinsn && (pinsn < (int*)(buffer + bufferbytes - sizeof(int))))
916 if (pinsn >= (int*)(buffer + bufferbytes))
921 /* function size is the amount of bytes we have skipped so far. */
922 tbInfo.fsize = bytesread - (buffer + bufferbytes - (char*)pinsn);
926 /* if we don't have the whole traceback table in the buffer, re-read
929 /* This is how much to read to get the traceback table.
930 8 bytes of the traceback table are always present, plus we
932 #define MIN_TBTABSIZ 12
934 if ((char*)pinsn > (buffer + bufferbytes - MIN_TBTABSIZ)) {
936 /* In case if we are *very* close to the end of the text section
937 and cannot read properly from that point on, abort by returning
940 This could happen if the traceback table is only 8 bytes,
941 but we try to read 12 bytes of it.
942 Handle this case more graciously -- FIXME */
944 if (!bfd_get_section_contents (
945 abfd, textsec, buffer,
946 (file_ptr)(functionstart +
947 bytesread - (buffer + bufferbytes - (char*)pinsn)),MIN_TBTABSIZ))
948 { printf_unfiltered ("Abnormal return!..\n"); return NULL; }
950 ptb = (struct tbtable *)buffer;
953 ptb = (struct tbtable *)pinsn;
955 tbInfo.fixedparms = ptb->tb.fixedparms;
956 tbInfo.floatparms = ptb->tb.floatparms;
957 tbInfo.parminfo = ptb->tb_ext.parminfo;
961 (TBTABLE_BUFSIZ < (textsec->_raw_size - functionstart - bytesread) ?
962 TBTABLE_BUFSIZ : (textsec->_raw_size - functionstart - bytesread));
967 /* Save the vital information for use when closing off the current file.
968 NAME is the file name the symbols came from, START_ADDR is the first
969 text address for the file, and SIZE is the number of bytes of text. */
971 #define complete_symtab(name, start_addr) { \
972 last_source_file = savestring (name, strlen (name)); \
973 last_source_start_addr = start_addr; \
977 /* Refill the symbol table input buffer
978 and set the variables that control fetching entries from it.
979 Reports an error if no data available.
980 This function can read past the end of the symbol table
981 (into the string table) but this does no harm. */
983 /* Reading symbol table has to be fast! Keep the followings as macros, rather
986 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \
990 if (namestr[0] == '.') ++namestr; \
991 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
992 (char *)NULL, (SECTION), (OBJFILE)); \
993 misc_func_recorded = 1; \
997 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
998 in our initializer function at the bottom of the file, to avoid
999 dependencies on the exact "struct symbol" format. */
1001 static struct symbol parmsym;
1003 /* Add a parameter to a given pending symbol list. */
1005 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
1007 PARM = (struct symbol *) \
1008 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1009 *(PARM) = parmsym; \
1010 SYMBOL_TYPE (PARM) = PTYPE; \
1011 SYMBOL_VALUE (PARM) = VALUE; \
1012 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
1016 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
1017 nested. At any given time, a symbol can only be in one static block.
1018 This is the base address of current static block, zero if non exists. */
1020 static int static_block_base = 0;
1022 /* Section number for the current static block. */
1024 static int static_block_section = -1;
1026 /* true if space for symbol name has been allocated. */
1028 static int symname_alloced = 0;
1030 /* Next symbol to read. Pointer into raw seething symbol table. */
1032 static char *raw_symbol;
1034 /* This is the function which stabsread.c calls to get symbol
1037 xcoff_next_symbol_text ()
1039 struct internal_syment symbol;
1040 static struct complaint msg =
1041 {"Unexpected symbol continuation", 0, 0};
1043 struct objfile *objfile = this_symtab_psymtab->objfile;
1045 bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
1046 if (symbol.n_zeroes)
1050 /* Return something which points to '\0' and hope the symbol reading
1051 code does something reasonable. */
1054 else if (symbol.n_sclass & 0x80)
1057 ((struct coff_symfile_info *)objfile->sym_private)->debugsec
1060 coff_data (objfile->obfd)->local_symesz;
1067 /* Return something which points to '\0' and hope the symbol reading
1068 code does something reasonable. */
1074 /* Read symbols for a given partial symbol table. */
1077 read_xcoff_symtab (pst)
1078 struct partial_symtab *pst;
1080 struct objfile *objfile = pst->objfile;
1081 bfd *abfd = objfile->obfd;
1082 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
1083 TracebackInfo *ptb; /* Pointer to traceback table */
1084 char *strtbl = ((struct coff_symfile_info *)objfile->sym_private)->strtbl;
1086 ((struct coff_symfile_info *)objfile->sym_private)->debugsec;
1088 struct internal_syment symbol[1];
1089 union internal_auxent main_aux;
1090 struct coff_symbol cs[1];
1091 CORE_ADDR file_start_addr = 0;
1092 CORE_ADDR file_end_addr = 0;
1094 int next_file_symnum = -1;
1095 unsigned int max_symnum;
1096 int just_started = 1;
1102 struct coff_symbol fcn_stab_saved;
1104 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1105 union internal_auxent fcn_aux_saved;
1106 struct type *fcn_type_saved = NULL;
1107 struct context_stack *new;
1109 char *filestring = " _start_ "; /* Name of the current file. */
1111 char *last_csect_name; /* last seen csect's name and value */
1112 CORE_ADDR last_csect_val;
1114 int misc_func_recorded; /* true if any misc. function */
1116 this_symtab_psymtab = pst;
1118 /* Get the appropriate COFF "constants" related to the file we're
1120 local_symesz = coff_data (abfd)->local_symesz;
1122 last_source_file = NULL;
1123 last_csect_name = 0;
1125 misc_func_recorded = 0;
1128 start_symtab (filestring, (char *)NULL, file_start_addr);
1129 symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum;
1131 symnum + ((struct symloc *)pst->read_symtab_private)->numsyms;
1132 first_object_file_end = 0;
1135 ((struct coff_symfile_info *) objfile->sym_private)->symtbl
1136 + symnum * local_symesz;
1138 while (symnum < max_symnum)
1141 QUIT; /* make this command interruptable. */
1143 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1144 /* read one symbol into `cs' structure. After processing the
1145 whole symbol table, only string table will be kept in memory,
1146 symbol table and debug section of xcoff will be freed. Thus
1147 we can mark symbols with names in string table as
1152 /* Swap and align the symbol into a reasonable C structure. */
1153 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
1155 cs->c_symnum = symnum;
1156 cs->c_naux = symbol->n_numaux;
1157 if (symbol->n_zeroes)
1159 symname_alloced = 0;
1160 /* We must use the original, unswapped, name here so the name field
1161 pointed to by cs->c_name will persist throughout xcoffread. If
1162 we use the new field, it gets overwritten for each symbol. */
1163 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
1164 /* If it's exactly E_SYMNMLEN characters long it isn't
1166 if (cs->c_name[E_SYMNMLEN - 1] != '\0')
1169 p = obstack_alloc (&objfile->symbol_obstack, E_SYMNMLEN + 1);
1170 strncpy (p, cs->c_name, E_SYMNMLEN);
1171 p[E_SYMNMLEN] = '\0';
1173 symname_alloced = 1;
1176 else if (symbol->n_sclass & 0x80)
1178 cs->c_name = debugsec + symbol->n_offset;
1179 symname_alloced = 0;
1183 /* in string table */
1184 cs->c_name = strtbl + (int)symbol->n_offset;
1185 symname_alloced = 1;
1187 cs->c_value = symbol->n_value;
1188 cs->c_sclass = symbol->n_sclass;
1189 cs->c_secnum = symbol->n_scnum;
1190 cs->c_type = (unsigned)symbol->n_type;
1192 raw_symbol += coff_data (abfd)->local_symesz;
1195 /* Save addr of first aux entry. */
1196 raw_auxptr = raw_symbol;
1198 /* Skip all the auxents associated with this symbol. */
1199 for (ii = symbol->n_numaux; ii; --ii)
1201 raw_symbol += coff_data (abfd)->local_auxesz;
1206 /* if symbol name starts with ".$" or "$", ignore it. */
1207 if (cs->c_name[0] == '$'
1208 || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
1211 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
1213 if (last_source_file)
1216 end_symtab (cur_src_end_addr, 1, 0, objfile, SECT_OFF_TEXT);
1221 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
1222 cur_src_end_addr = first_object_file_end;
1223 /* done with all files, everything from here on is globals */
1226 /* if explicitly specified as a function, treat is as one. */
1227 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF)
1229 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1230 0, cs->c_naux, &main_aux);
1231 goto function_entry_point;
1234 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT)
1237 /* Dealing with a symbol with a csect entry. */
1239 #define CSECT(PP) ((PP)->x_csect)
1240 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1241 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1242 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1243 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1245 /* Convert the auxent to something we can access. */
1246 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1247 0, cs->c_naux, &main_aux);
1249 switch (CSECT_SMTYP (&main_aux))
1253 /* Ignore all external references. */
1257 /* A section description. */
1259 switch (CSECT_SCLAS (&main_aux))
1265 /* A program csect is seen. We have to allocate one
1266 symbol table for each program csect. Normally gdb
1267 prefers one symtab for each source file. In case
1268 of AIX, one source file might include more than one
1269 [PR] csect, and they don't have to be adjacent in
1270 terms of the space they occupy in memory. Thus, one
1271 single source file might get fragmented in the
1272 memory and gdb's file start and end address
1273 approach does not work! GCC (and I think xlc) seem
1274 to put all the code in the unnamed program csect. */
1276 if (last_csect_name)
1278 complete_symtab (filestring, file_start_addr);
1279 cur_src_end_addr = file_end_addr;
1280 end_symtab (file_end_addr, 1, 0, objfile,
1284 /* Give all csects for this source file the same
1286 start_symtab (filestring, NULL, (CORE_ADDR)0);
1289 /* If this is the very first csect seen,
1290 basically `__start'. */
1293 first_object_file_end
1294 = cs->c_value + CSECT_LEN (&main_aux);
1299 cs->c_value + ANOFFSET (objfile->section_offsets,
1301 file_end_addr = file_start_addr + CSECT_LEN (&main_aux);
1303 if (cs->c_name && cs->c_name[0] == '.')
1305 last_csect_name = cs->c_name;
1306 last_csect_val = cs->c_value;
1307 last_csect_sec = secnum_to_section (cs->c_secnum, objfile);
1310 misc_func_recorded = 0;
1316 /* If the section is not a data description,
1317 ignore it. Note that uninitialized data will
1318 show up as XTY_CM/XMC_RW pair. */
1327 /* Ignore the symbol. */
1335 switch (CSECT_SCLAS (&main_aux))
1338 /* a function entry point. */
1339 function_entry_point:
1341 fcn_start_addr = cs->c_value;
1343 /* save the function header info, which will be used
1344 when `.bf' is seen. */
1346 fcn_aux_saved = main_aux;
1350 /* If function has two auxent, then debugging information is
1351 already available for it. Process traceback table for
1352 functions with only one auxent. */
1354 if (cs->c_naux == 1)
1355 ptb = retrieve_tracebackinfo (abfd, cs);
1357 else if (cs->c_naux != 2)
1359 static struct complaint msg =
1360 {"Expected one or two auxents for function", 0, 0};
1364 /* If there is traceback info, create and add parameters
1367 if (ptb && (ptb->fixedparms || ptb->floatparms))
1370 int parmcnt = ptb->fixedparms + ptb->floatparms;
1371 char *parmcode = (char*) &ptb->parminfo;
1373 /* The link area is 0x18 bytes. */
1374 int parmvalue = ptb->framesize + 0x18;
1375 unsigned int ii, mask;
1377 for (ii=0, mask = 0x80000000; ii <parmcnt; ++ii)
1379 struct symbol *parm;
1381 if (ptb->parminfo & mask)
1383 /* float or double */
1385 if (ptb->parminfo & mask)
1389 (parm, parmvalue, builtin_type_double,
1391 parmvalue += sizeof (double);
1397 (parm, parmvalue, builtin_type_float,
1399 parmvalue += sizeof (float);
1404 static struct type *intparm_type;
1405 if (intparm_type == NULL)
1408 /* Create a type, which is a pointer
1409 type (a kludge to make it print
1410 in hex), but which has a name
1411 indicating we don't know the real
1417 TARGET_PTR_BIT / HOST_CHAR_BIT,
1419 "<non-float parameter>",
1421 TYPE_TARGET_TYPE (intparm_type) =
1428 parmvalue += sizeof (int);
1433 /* Fake this as a function. Needed in
1434 process_xcoff_symbol(). */
1438 (process_xcoff_symbol (cs, objfile), &local_symbols,
1439 pending_blocks, cs->c_value,
1440 cs->c_value + ptb->fsize, objfile);
1445 /* shared library function trampoline code entry point. */
1449 /* The symbols often have the same names as debug symbols for
1450 functions, and confuse lookup_symbol. */
1454 /* xlc puts each variable in a separate csect, so we get
1455 an XTY_SD for each variable. But gcc puts several
1456 variables in a csect, so that each variable only gets
1457 an XTY_LD. We still need to record them. This will
1458 typically be XMC_RW; I suspect XMC_RO and XMC_BS might
1468 switch (cs->c_sclass)
1473 /* c_value field contains symnum of next .file entry in table
1474 or symnum of first global after last .file. */
1476 next_file_symnum = cs->c_value;
1478 /* Complete symbol table for last object file containing
1479 debugging information. */
1481 /* Whether or not there was a csect in the previous file, we
1482 have to call `end_stabs' and `start_stabs' to reset
1483 type_vector, line_vector, etc. structures. */
1485 complete_symtab (filestring, file_start_addr);
1486 cur_src_end_addr = file_end_addr;
1487 end_symtab (file_end_addr, 1, 0, objfile, SECT_OFF_TEXT);
1490 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1491 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1492 standard COFF way and put it in the auxent. We use the auxent if
1493 the symbol is ".file" and an auxent exists, otherwise use the symbol
1494 itself. Simple enough. */
1495 if (!strcmp (cs->c_name, ".file") && cs->c_naux > 0)
1497 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1498 0, cs->c_naux, &main_aux);
1499 filestring = coff_getfilename (&main_aux, objfile);
1502 filestring = cs->c_name;
1505 start_symtab (filestring, (char *)NULL, (CORE_ADDR)0);
1506 last_csect_name = 0;
1508 /* reset file start and end addresses. A compilation unit with no text
1509 (only data) should have zero file boundaries. */
1510 file_start_addr = file_end_addr = 0;
1514 fcn_stab_saved = *cs;
1518 if (STREQ (cs->c_name, ".bf"))
1520 CORE_ADDR off = ANOFFSET (objfile->section_offsets,
1522 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1523 0, cs->c_naux, &main_aux);
1525 within_function = 1;
1527 new = push_context (0, fcn_start_addr + off);
1529 new->name = define_symbol
1530 (fcn_cs_saved.c_value + off,
1531 fcn_stab_saved.c_name, 0, 0, objfile);
1532 if (new->name != NULL)
1533 SYMBOL_SECTION (new->name) = SECT_OFF_TEXT;
1535 else if (STREQ (cs->c_name, ".ef"))
1538 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
1539 0, cs->c_naux, &main_aux);
1541 /* The value of .ef is the address of epilogue code;
1542 not useful for gdb. */
1543 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1544 contains number of lines to '}' */
1546 new = pop_context ();
1547 /* Stack must be empty now. */
1548 if (context_stack_depth > 0 || new == NULL)
1550 complain (&ef_complaint, cs->c_symnum);
1551 within_function = 0;
1555 finish_block (new->name, &local_symbols, new->old_blocks,
1557 (fcn_cs_saved.c_value
1558 + fcn_aux_saved.x_sym.x_misc.x_fsize
1559 + ANOFFSET (objfile->section_offsets,
1562 within_function = 0;
1567 /* Begin static block. */
1569 struct internal_syment symbol;
1571 read_symbol (&symbol, cs->c_value);
1572 static_block_base = symbol.n_value;
1573 static_block_section =
1574 secnum_to_section (symbol.n_scnum, objfile);
1579 /* End of static block. */
1580 static_block_base = 0;
1581 static_block_section = -1;
1592 static struct complaint msg =
1593 {"Unrecognized storage class %d.", 0, 0};
1594 complain (&msg, cs->c_sclass);
1607 /* beginning of include file */
1608 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1609 order. Thus, when wee see them, we might not know enough info
1610 to process them. Thus, we'll be saving them into a table
1611 (inclTable) and postpone their processing. */
1613 record_include_begin (cs);
1617 /* End of include file. */
1618 /* See the comment after case C_BINCL. */
1619 record_include_end (cs);
1623 if (STREQ (cs->c_name, ".bb"))
1626 new = push_context (depth,
1628 + ANOFFSET (objfile->section_offsets,
1631 else if (STREQ (cs->c_name, ".eb"))
1633 new = pop_context ();
1634 if (depth-- != new->depth)
1636 complain (&eb_complaint, symnum);
1639 if (local_symbols && context_stack_depth > 0)
1641 /* Make a block for the local symbols within. */
1642 finish_block (new->name, &local_symbols, new->old_blocks,
1645 + ANOFFSET (objfile->section_offsets,
1649 local_symbols = new->locals;
1654 process_xcoff_symbol (cs, objfile);
1659 if (last_source_file)
1663 complete_symtab (filestring, file_start_addr);
1664 cur_src_end_addr = file_end_addr;
1665 s = end_symtab (file_end_addr, 1, 0, objfile, SECT_OFF_TEXT);
1666 /* When reading symbols for the last C_FILE of the objfile, try
1667 to make sure that we set pst->symtab to the symtab for the
1668 file, not to the _globals_ symtab. I'm not sure whether this
1669 actually works right or when/if it comes up. */
1670 if (pst->symtab == NULL)
1676 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1677 (SYMBOL2) = (struct symbol *) \
1678 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1679 *(SYMBOL2) = *(SYMBOL1);
1682 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1683 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1686 static struct type *func_symbol_type;
1687 static struct type *var_symbol_type;
1689 /* process one xcoff symbol. */
1691 static struct symbol *
1692 process_xcoff_symbol (cs, objfile)
1693 register struct coff_symbol *cs;
1694 struct objfile *objfile;
1696 struct symbol onesymbol;
1697 register struct symbol *sym = &onesymbol;
1698 struct symbol *sym2 = NULL;
1700 char *name, *pp, *qq;
1701 int struct_and_type_combined;
1707 if (cs->c_secnum < 0)
1709 /* The value is a register number, offset within a frame, etc.,
1710 and does not get relocated. */
1716 sec = secnum_to_section (cs->c_secnum, objfile);
1717 off = ANOFFSET (objfile->section_offsets, sec);
1724 memset (sym, '\0', sizeof (struct symbol));
1726 /* default assumptions */
1727 SYMBOL_VALUE (sym) = cs->c_value + off;
1728 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1729 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1731 if (ISFCN (cs->c_type))
1733 /* At this point, we don't know the type of the function. This
1734 will be patched with the type from its stab entry later on in
1735 patch_block_stabs (), unless the file was compiled without -g. */
1737 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1738 SYMBOL_TYPE (sym) = func_symbol_type;
1740 SYMBOL_CLASS (sym) = LOC_BLOCK;
1741 SYMBOL_DUP (sym, sym2);
1743 if (cs->c_sclass == C_EXT)
1744 add_symbol_to_list (sym2, &global_symbols);
1745 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
1746 add_symbol_to_list (sym2, &file_symbols);
1750 /* In case we can't figure out the type, provide default. */
1751 SYMBOL_TYPE (sym) = var_symbol_type;
1753 switch (cs->c_sclass)
1757 if (fcn_cs_saved.c_sclass == C_EXT)
1758 add_stab_to_list (name, &global_stabs);
1760 add_stab_to_list (name, &file_stabs);
1765 add_stab_to_list (name, &global_stabs);
1769 common_block_start (cs->c_name, objfile);
1773 common_block_end (objfile);
1777 complain (&storclass_complaint, cs->c_sclass);
1788 sym = define_symbol (cs->c_value + off, cs->c_name, 0, 0, objfile);
1791 SYMBOL_SECTION (sym) = sec;
1798 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1799 all statics and we need to distinguish file-scope versus
1800 function-scope using within_function. We do this by
1801 changing the string we pass to define_symbol to use 'S'
1802 where we need to, which is not necessarily super-clean,
1803 but seems workable enough. */
1805 if (*name == ':' || (pp = (char *) strchr(name, ':')) == NULL)
1809 if (*pp == 'V' && !within_function)
1811 sym = define_symbol ((cs->c_value
1812 + ANOFFSET (objfile->section_offsets,
1813 static_block_section)),
1814 cs->c_name, 0, 0, objfile);
1817 SYMBOL_VALUE (sym) += static_block_base;
1818 SYMBOL_SECTION (sym) = static_block_section;
1823 /* These appear to be vestigial remnants of coffread.c; I don't
1824 think any of them are used for xcoff. */
1827 SYMBOL_CLASS (sym) = LOC_LOCAL;
1828 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1829 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1830 SYMBOL_DUP (sym, sym2);
1831 add_symbol_to_list (sym2, &local_symbols);
1835 SYMBOL_CLASS (sym) = LOC_STATIC;
1836 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1837 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1838 SYMBOL_DUP (sym, sym2);
1840 (sym2, within_function ? &local_symbols : &file_symbols);
1844 pp = (char*) strchr (name, ':');
1847 sym = define_symbol (cs->c_value, cs->c_name, 0, 0, objfile);
1849 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1854 complain (&rsym_complaint, name);
1859 /* I think this one is used (dubious, I think, shouldn't
1860 it go into the msyms only?). */
1862 SYMBOL_CLASS (sym) = LOC_STATIC;
1863 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
1864 SYMBOL_SECTION (sym) = secnum_to_section (cs->c_secnum, objfile);
1865 SYMBOL_DUP (sym, sym2);
1866 add_symbol_to_list (sym2, &global_symbols);
1874 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1875 only the last component of the name. Result is in static storage and
1876 is only good for temporary use. */
1879 coff_getfilename (aux_entry, objfile)
1880 union internal_auxent *aux_entry;
1881 struct objfile *objfile;
1883 static char buffer[BUFSIZ];
1884 register char *temp;
1887 if (aux_entry->x_file.x_n.x_zeroes == 0)
1889 ((struct coff_symfile_info *)objfile->sym_private)->strtbl
1890 + aux_entry->x_file.x_n.x_offset);
1893 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1894 buffer[FILNMLEN] = '\0';
1898 /* FIXME: We should not be throwing away the information about what
1899 directory. It should go into dirname of the symtab, or some such
1901 if ((temp = strrchr (result, '/')) != NULL)
1906 /* Set *SYMBOL to symbol number symno in symtbl. */
1908 read_symbol (symbol, symno)
1909 struct internal_syment *symbol;
1913 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1916 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1918 if (symno < 0 || symno >= nsyms)
1920 static struct complaint msg =
1921 {"Invalid symbol offset", 0, 0};
1923 symbol->n_value = 0;
1924 symbol->n_scnum = -1;
1927 bfd_coff_swap_sym_in (this_symtab_psymtab->objfile->obfd,
1928 stbl + (symno*local_symesz),
1932 /* Get value corresponding to symbol number symno in symtbl. */
1935 read_symbol_nvalue (symno)
1938 struct internal_syment symbol[1];
1940 read_symbol (symbol, symno);
1941 return symbol->n_value;
1945 /* Find the address of the function corresponding to symno, where
1946 symno is the symbol pointed to by the linetable. */
1949 read_symbol_lineno (symno)
1953 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1956 ((struct coff_symfile_info *)this_symtab_psymtab->objfile->sym_private)
1958 struct internal_syment symbol[1];
1959 union internal_auxent main_aux[1];
1963 complain (&bf_notfound_complaint);
1967 /* Note that just searching for a short distance (e.g. 50 symbols)
1968 is not enough, at least in the following case.
1971 [many .stabx entries]
1972 [a few functions, referring to foo]
1976 What happens here is that the assembler moves the .stabx entries
1977 to right before the ".bf" for foo, but the symbol for "foo" is before
1978 all the stabx entries. See PR gdb/2222. */
1980 /* Maintaining a table of .bf entries might be preferable to this search.
1981 If I understand things correctly it would need to be done only for
1982 the duration of a single psymtab to symtab conversion. */
1983 while (symno < nsyms)
1985 bfd_coff_swap_sym_in (symfile_bfd,
1986 stbl + (symno * local_symesz), symbol);
1987 if (symbol->n_sclass == C_FCN && STREQ (symbol->n_name, ".bf"))
1989 symno += symbol->n_numaux + 1;
1992 complain (&bf_notfound_complaint);
1996 /* take aux entry and return its lineno */
1998 bfd_coff_swap_aux_in (this_symtab_psymtab->objfile->obfd,
1999 stbl + symno * local_symesz,
2000 symbol->n_type, symbol->n_sclass,
2001 0, symbol->n_numaux, main_aux);
2003 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
2006 /* Support for line number handling */
2008 /* This function is called for every section; it finds the outer limits
2009 * of the line table (minimum and maximum file offset) so that the
2010 * mainline code can read the whole thing for efficiency.
2013 find_linenos (abfd, asect, vpinfo)
2018 struct coff_symfile_info *info;
2020 file_ptr offset, maxoff;
2022 count = asect->lineno_count;
2024 if (!STREQ (asect->name, ".text") || count == 0)
2027 size = count * coff_data (abfd)->local_linesz;
2028 info = (struct coff_symfile_info *)vpinfo;
2029 offset = asect->line_filepos;
2030 maxoff = offset + size;
2032 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
2033 info->min_lineno_offset = offset;
2035 if (maxoff > info->max_lineno_offset)
2036 info->max_lineno_offset = maxoff;
2039 static void xcoff_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
2042 xcoff_psymtab_to_symtab_1 (pst)
2043 struct partial_symtab *pst;
2045 struct cleanup *old_chain;
2054 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2059 /* Read in all partial symtabs on which this one is dependent */
2060 for (i = 0; i < pst->number_of_dependencies; i++)
2061 if (!pst->dependencies[i]->readin)
2063 /* Inform about additional files that need to be read in. */
2066 fputs_filtered (" ", gdb_stdout);
2068 fputs_filtered ("and ", gdb_stdout);
2070 printf_filtered ("%s...", pst->dependencies[i]->filename);
2071 wrap_here (""); /* Flush output */
2072 gdb_flush (gdb_stdout);
2074 xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
2077 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0)
2079 /* Init stuff necessary for reading in symbols. */
2082 old_chain = make_cleanup (really_free_pendings, 0);
2084 read_xcoff_symtab (pst);
2085 sort_symtab_syms (pst->symtab);
2087 do_cleanups (old_chain);
2093 static void xcoff_psymtab_to_symtab PARAMS ((struct partial_symtab *));
2095 /* Read in all of the symbols for a given psymtab for real.
2096 Be verbose about it if the user wants that. */
2099 xcoff_psymtab_to_symtab (pst)
2100 struct partial_symtab *pst;
2110 (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2115 if (((struct symloc *)pst->read_symtab_private)->numsyms != 0
2116 || pst->number_of_dependencies)
2118 /* Print the message now, before reading the string table,
2119 to avoid disconcerting pauses. */
2122 printf_filtered ("Reading in symbols for %s...", pst->filename);
2123 gdb_flush (gdb_stdout);
2126 sym_bfd = pst->objfile->obfd;
2128 next_symbol_text_func = xcoff_next_symbol_text;
2130 xcoff_psymtab_to_symtab_1 (pst);
2132 /* Match with global symbols. This only needs to be done once,
2133 after all of the symtabs and dependencies have been read in. */
2134 scan_file_globals (pst->objfile);
2136 /* Finish up the debug error message. */
2138 printf_filtered ("done.\n");
2143 xcoff_new_init (objfile)
2144 struct objfile *objfile;
2148 /* Do initialization in preparation for reading symbols from OBJFILE.
2150 We will only be called if this is an XCOFF or XCOFF-like file.
2151 BFD handles figuring out the format of the file, and code in symfile.c
2152 uses BFD's determination to vector to us. */
2155 xcoff_symfile_init (objfile)
2156 struct objfile *objfile;
2158 /* Allocate struct to keep track of the symfile */
2159 objfile -> sym_private = xmmalloc (objfile -> md,
2160 sizeof (struct coff_symfile_info));
2161 init_entry_point_info (objfile);
2164 /* Perform any local cleanups required when we are done with a particular
2165 objfile. I.E, we are in the process of discarding all symbol information
2166 for an objfile, freeing up all memory held for it, and unlinking the
2167 objfile struct from the global list of known objfiles. */
2170 xcoff_symfile_finish (objfile)
2171 struct objfile *objfile;
2173 if (objfile -> sym_private != NULL)
2175 mfree (objfile -> md, objfile -> sym_private);
2178 /* Start with a fresh include table for the next objfile. */
2184 inclIndx = inclLength = inclDepth = 0;
2189 init_stringtab (abfd, offset, objfile)
2192 struct objfile *objfile;
2196 unsigned char lengthbuf[4];
2199 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = NULL;
2201 if (bfd_seek (abfd, offset, L_SET) < 0)
2202 error ("cannot seek to string table in %s: %s",
2203 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
2205 val = bfd_read ((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
2206 length = bfd_h_get_32 (abfd, lengthbuf);
2208 /* If no string table is needed, then the file may end immediately
2209 after the symbols. Just return with `strtbl' set to NULL. */
2211 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
2214 /* Allocate string table from symbol_obstack. We will need this table
2215 as long as we have its symbol table around. */
2217 strtbl = (char *) obstack_alloc (&objfile->symbol_obstack, length);
2218 ((struct coff_symfile_info *)objfile->sym_private)->strtbl = strtbl;
2220 if (length == sizeof lengthbuf)
2223 val = bfd_read (strtbl + sizeof lengthbuf, 1, length - sizeof lengthbuf,
2226 if (val != length - sizeof lengthbuf)
2227 error ("cannot read string table from %s: %s",
2228 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
2229 if (strtbl[length - 1] != '\0')
2230 error ("bad symbol file: string table does not end with null character");
2235 /* If we have not yet seen a function for this psymtab, this is 0. If we
2236 have seen one, it is the offset in the line numbers of the line numbers
2238 static unsigned int first_fun_line_offset;
2240 static struct partial_symtab *xcoff_start_psymtab
2241 PARAMS ((struct objfile *, struct section_offsets *, char *, int,
2242 struct partial_symbol *, struct partial_symbol *));
2244 /* Allocate and partially fill a partial symtab. It will be
2245 completely filled at the end of the symbol list.
2247 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2248 is the address relative to which its symbols are (incremental) or 0
2251 static struct partial_symtab *
2252 xcoff_start_psymtab (objfile, section_offsets,
2253 filename, first_symnum, global_syms, static_syms)
2254 struct objfile *objfile;
2255 struct section_offsets *section_offsets;
2258 struct partial_symbol *global_syms;
2259 struct partial_symbol *static_syms;
2261 struct partial_symtab *result =
2262 start_psymtab_common (objfile, section_offsets,
2264 /* We fill in textlow later. */
2266 global_syms, static_syms);
2268 result->read_symtab_private = (char *)
2269 obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
2270 ((struct symloc *)result->read_symtab_private)->first_symnum = first_symnum;
2271 result->read_symtab = xcoff_psymtab_to_symtab;
2273 /* Deduce the source language from the filename for this psymtab. */
2274 psymtab_language = deduce_language_from_filename (filename);
2279 static struct partial_symtab *xcoff_end_psymtab
2280 PARAMS ((struct partial_symtab *, char **, int, int,
2281 struct partial_symtab **, int));
2283 /* Close off the current usage of PST.
2284 Returns PST, or NULL if the partial symtab was empty and thrown away.
2286 CAPPING_SYMBOL_NUMBER is the end of pst (exclusive).
2288 INCLUDE_LIST, NUM_INCLUDES, DEPENDENCY_LIST, and NUMBER_DEPENDENCIES
2289 are the information for includes and dependencies. */
2291 static struct partial_symtab *
2292 xcoff_end_psymtab (pst, include_list, num_includes, capping_symbol_number,
2293 dependency_list, number_dependencies)
2294 struct partial_symtab *pst;
2295 char **include_list;
2297 int capping_symbol_number;
2298 struct partial_symtab **dependency_list;
2299 int number_dependencies;
2302 struct objfile *objfile = pst -> objfile;
2304 if (capping_symbol_number != -1)
2305 ((struct symloc *)pst->read_symtab_private)->numsyms =
2306 capping_symbol_number
2307 - ((struct symloc *)pst->read_symtab_private)->first_symnum;
2308 ((struct symloc *)pst->read_symtab_private)->lineno_off =
2309 first_fun_line_offset;
2310 first_fun_line_offset = 0;
2311 pst->n_global_syms =
2312 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2313 pst->n_static_syms =
2314 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2316 pst->number_of_dependencies = number_dependencies;
2317 if (number_dependencies)
2319 pst->dependencies = (struct partial_symtab **)
2320 obstack_alloc (&objfile->psymbol_obstack,
2321 number_dependencies * sizeof (struct partial_symtab *));
2322 memcpy (pst->dependencies, dependency_list,
2323 number_dependencies * sizeof (struct partial_symtab *));
2326 pst->dependencies = 0;
2328 for (i = 0; i < num_includes; i++)
2330 struct partial_symtab *subpst =
2331 allocate_psymtab (include_list[i], objfile);
2333 subpst->section_offsets = pst->section_offsets;
2334 subpst->read_symtab_private =
2335 (char *) obstack_alloc (&objfile->psymbol_obstack,
2336 sizeof (struct symloc));
2337 ((struct symloc *)subpst->read_symtab_private)->first_symnum = 0;
2338 ((struct symloc *)subpst->read_symtab_private)->numsyms = 0;
2339 subpst->textlow = 0;
2340 subpst->texthigh = 0;
2342 /* We could save slight bits of space by only making one of these,
2343 shared by the entire set of include files. FIXME-someday. */
2344 subpst->dependencies = (struct partial_symtab **)
2345 obstack_alloc (&objfile->psymbol_obstack,
2346 sizeof (struct partial_symtab *));
2347 subpst->dependencies[0] = pst;
2348 subpst->number_of_dependencies = 1;
2350 subpst->globals_offset =
2351 subpst->n_global_syms =
2352 subpst->statics_offset =
2353 subpst->n_static_syms = 0;
2357 subpst->read_symtab = pst->read_symtab;
2360 sort_pst_symbols (pst);
2362 /* If there is already a psymtab or symtab for a file of this name,
2363 remove it. (If there is a symtab, more drastic things also
2364 happen.) This happens in VxWorks. */
2365 free_named_symtabs (pst->filename);
2367 if (num_includes == 0
2368 && number_dependencies == 0
2369 && pst->n_global_syms == 0
2370 && pst->n_static_syms == 0)
2372 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2373 it is on the obstack, but we can forget to chain it on the list. */
2374 /* Empty psymtabs happen as a result of header files which don't have
2375 any symbols in them. There can be a lot of them. But this check
2376 is wrong, in that a psymtab with N_SLINE entries but nothing else
2377 is not empty, but we don't realize that. Fixing that without slowing
2378 things down might be tricky. (FIXME: For XCOFF, it shouldn't be
2380 struct partial_symtab *prev_pst;
2382 /* First, snip it out of the psymtab chain */
2384 if (pst->objfile->psymtabs == pst)
2385 pst->objfile->psymtabs = pst->next;
2387 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
2388 if (prev_pst->next == pst)
2389 prev_pst->next = pst->next;
2391 /* Next, put it on a free list for recycling */
2393 pst->next = pst->objfile->free_psymtabs;
2394 pst->objfile->free_psymtabs = pst;
2396 /* Indicate that psymtab was thrown away. */
2397 pst = (struct partial_symtab *)NULL;
2402 static void swap_sym PARAMS ((struct internal_syment *,
2403 union internal_auxent *, char **, char **,
2407 /* Swap raw symbol at *RAW and put the name in *NAME, the symbol in
2408 *SYMBOL, the first auxent in *AUX. Advance *RAW and *SYMNUMP over
2409 the symbol and its auxents. */
2412 swap_sym (symbol, aux, name, raw, symnump, objfile)
2413 struct internal_syment *symbol;
2414 union internal_auxent *aux;
2417 unsigned int *symnump;
2418 struct objfile *objfile;
2420 bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
2421 if (symbol->n_zeroes)
2423 /* If it's exactly E_SYMNMLEN characters long it isn't
2425 if (symbol->n_name[E_SYMNMLEN - 1] != '\0')
2427 /* FIXME: wastes memory for symbols which we don't end up putting
2428 into the minimal symbols. */
2430 p = obstack_alloc (&objfile->psymbol_obstack, E_SYMNMLEN + 1);
2431 strncpy (p, symbol->n_name, E_SYMNMLEN);
2432 p[E_SYMNMLEN] = '\0';
2436 /* Point to the unswapped name as that persists as long as the
2438 *name = ((struct external_syment *)*raw)->e.e_name;
2440 else if (symbol->n_sclass & 0x80)
2442 *name = ((struct coff_symfile_info *)objfile->sym_private)->debugsec
2447 *name = ((struct coff_symfile_info *)objfile->sym_private)->strtbl
2451 *raw += coff_data (objfile->obfd)->local_symesz;
2452 if (symbol->n_numaux > 0)
2454 bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
2455 symbol->n_sclass, 0, symbol->n_numaux, aux);
2457 *symnump += symbol->n_numaux;
2458 *raw += coff_data (objfile->obfd)->local_symesz * symbol->n_numaux;
2463 scan_xcoff_symtab (section_offsets, objfile)
2464 struct section_offsets *section_offsets;
2465 struct objfile *objfile;
2467 int toc_offset = 0; /* toc offset value in data section. */
2472 int past_first_source_file = 0;
2473 CORE_ADDR last_o_file_start = 0;
2474 struct cleanup *back_to;
2478 /* Current partial symtab */
2479 struct partial_symtab *pst;
2481 /* List of current psymtab's include files */
2482 char **psymtab_include_list;
2483 int includes_allocated;
2486 /* Index within current psymtab dependency list */
2487 struct partial_symtab **dependency_list;
2488 int dependencies_used, dependencies_allocated;
2491 struct internal_syment symbol;
2492 union internal_auxent main_aux;
2493 unsigned int ssymnum;
2495 char *last_csect_name = NULL; /* last seen csect's name and value */
2496 CORE_ADDR last_csect_val;
2498 int misc_func_recorded; /* true if any misc. function */
2500 pst = (struct partial_symtab *) 0;
2502 includes_allocated = 30;
2504 psymtab_include_list = (char **) alloca (includes_allocated *
2507 dependencies_allocated = 30;
2508 dependencies_used = 0;
2510 (struct partial_symtab **) alloca (dependencies_allocated *
2511 sizeof (struct partial_symtab *));
2513 last_source_file = NULL;
2515 abfd = objfile->obfd;
2517 sraw_symbol = ((struct coff_symfile_info *)objfile->sym_private)->symtbl;
2518 nsyms = ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms;
2520 while (ssymnum < nsyms)
2522 int sclass = ((struct external_syment *)sraw_symbol)->e_sclass[0];
2523 /* This is the type we pass to partial-stab.h. A less kludgy solution
2524 would be to break out partial-stab.h into its various parts--shuffle
2525 off the DBXREAD_ONLY stuff to dbxread.c, and make separate
2526 pstab-norm.h (for most types), pstab-sol.h (for N_SOL), etc. */
2536 /* The CSECT auxent--always the last auxent. */
2537 union internal_auxent csect_aux;
2538 unsigned int symnum_before = ssymnum;
2540 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2542 if (symbol.n_numaux > 1)
2544 bfd_coff_swap_aux_in
2546 sraw_symbol - coff_data(abfd)->local_symesz,
2549 symbol.n_numaux - 1,
2554 csect_aux = main_aux;
2556 switch (csect_aux.x_csect.x_smtyp & 0x7)
2559 switch (csect_aux.x_csect.x_smclas)
2562 if (last_csect_name)
2564 /* If no misc. function recorded in the last
2565 seen csect, enter it as a function. This
2566 will take care of functions like strcmp()
2569 if (!misc_func_recorded)
2571 RECORD_MINIMAL_SYMBOL
2572 (last_csect_name, last_csect_val,
2573 mst_text, last_csect_sec,
2579 /* We have to allocate one psymtab for
2580 each program csect, because their text
2581 sections need not be adjacent. */
2583 (pst, psymtab_include_list,
2586 dependency_list, dependencies_used);
2588 dependencies_used = 0;
2589 /* Give all psymtabs for this source file the same
2591 pst = xcoff_start_psymtab
2592 (objfile, section_offsets,
2595 objfile->global_psymbols.next,
2596 objfile->static_psymbols.next);
2599 if (namestring && namestring[0] == '.')
2601 last_csect_name = namestring;
2602 last_csect_val = symbol.n_value;
2604 secnum_to_section (symbol.n_scnum, objfile);
2609 symbol.n_value + csect_aux.x_csect.x_scnlen.l;
2610 if (highval > pst->texthigh)
2611 pst->texthigh = highval;
2612 if (pst->textlow == 0 || symbol.n_value < pst->textlow)
2613 pst->textlow = symbol.n_value;
2615 misc_func_recorded = 0;
2621 warning ("More than one XMC_TC0 symbol found.");
2622 toc_offset = symbol.n_value;
2625 /* These symbols tell us where the TOC entry for a
2626 variable is, not the variable itself. */
2634 switch (csect_aux.x_csect.x_smclas)
2638 /* A function entry point. */
2639 char *namestr = namestring;
2641 if (first_fun_line_offset == 0)
2642 first_fun_line_offset =
2643 main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
2644 if (namestr[0] == '.')
2646 prim_record_minimal_symbol_and_info
2647 (namestr, symbol.n_value, mst_text,
2648 NULL, secnum_to_section (symbol.n_scnum, objfile),
2650 misc_func_recorded = 1;
2652 /* We also create full symbols for these, so
2653 better make a partial symbol. This seems bogus
2654 to me, but I'm not going to try to fix it now.
2655 (Note that allocate_space_in_inferior can't
2656 yet deal with a minimal symbol for malloc on xcoff
2657 because it doesn't understand the fact that
2658 function pointers don't just contain the address of
2660 ADD_PSYMBOL_ADDR_TO_LIST (namestr, strlen (namestr),
2661 VAR_NAMESPACE, LOC_BLOCK,
2662 objfile->global_psymbols,
2664 psymtab_language, objfile);
2668 /* shared library function trampoline code entry
2671 /* record trampoline code entries as
2672 mst_solib_trampoline symbol. When we lookup mst
2673 symbols, we will choose mst_text over
2674 mst_solib_trampoline. */
2675 RECORD_MINIMAL_SYMBOL
2676 (namestring, symbol.n_value,
2677 mst_solib_trampoline,
2678 secnum_to_section (symbol.n_scnum, objfile),
2683 /* The symbols often have the same names as
2684 debug symbols for functions, and confuse
2690 /* xlc puts each variable in a separate csect,
2691 so we get an XTY_SD for each variable. But
2692 gcc puts several variables in a csect, so
2693 that each variable only gets an XTY_LD. We
2694 still need to record them. This will
2695 typically be XMC_RW; I suspect XMC_RO and
2696 XMC_BS might be possible too. */
2698 /* FIXME: Shouldn't these be going into the minimal
2699 symbols instead of partial/full symbols? */
2701 ADD_PSYMBOL_ADDR_TO_LIST (namestring, strlen (namestring),
2702 VAR_NAMESPACE, LOC_STATIC,
2703 objfile->global_psymbols,
2705 psymtab_language, objfile);
2715 unsigned int symnum_before;
2717 symnum_before = ssymnum;
2718 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2721 /* See if the last csect needs to be recorded. */
2723 if (last_csect_name && !misc_func_recorded)
2726 /* If no misc. function recorded in the last seen csect, enter
2727 it as a function. This will take care of functions like
2728 strcmp() compiled by xlc. */
2730 RECORD_MINIMAL_SYMBOL
2731 (last_csect_name, last_csect_val,
2732 mst_text, last_csect_sec, objfile);
2737 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2739 dependency_list, dependencies_used);
2741 dependencies_used = 0;
2743 first_fun_line_offset = 0;
2745 /* XCOFF, according to the AIX 3.2 documentation, puts the
2746 filename in cs->c_name. But xlc 1.3.0.2 has decided to
2747 do things the standard COFF way and put it in the auxent.
2748 We use the auxent if the symbol is ".file" and an auxent
2749 exists, otherwise use the symbol itself. */
2750 if (!strcmp (namestring, ".file") && symbol.n_numaux > 0)
2752 filestring = coff_getfilename (&main_aux, objfile);
2755 filestring = namestring;
2757 pst = xcoff_start_psymtab (objfile, section_offsets,
2760 objfile->global_psymbols.next,
2761 objfile->static_psymbols.next);
2762 last_csect_name = NULL;
2768 static struct complaint msg =
2769 {"Storage class %d not recognized during scan", 0, 0};
2770 complain (&msg, sclass);
2774 /* C_FCN is .bf and .ef symbols. I think it is sufficient
2775 to handle only the C_FUN and C_EXT. */
2790 /* C_EINCL means we are switching back to the main file. But there
2791 is no reason to care; the only thing we want to know about
2792 includes is the names of all the included (.h) files. */
2797 /* I don't think C_STAT is used in xcoff; C_HIDEXT appears to be
2801 /* I don't think the name of the common block (as opposed to the
2802 variables within it) is something which is user visible
2810 /* I think we can ignore C_LSYM; types on xcoff seem to use C_DECL
2811 so C_LSYM would appear to be only for locals. */
2817 /* We probably could save a few instructions by assuming that
2818 C_LSYM, C_PSYM, etc., never have auxents. */
2820 ((struct external_syment *)sraw_symbol)->e_numaux[0] + 1;
2822 sraw_symbol += sizeof (struct external_syment) * naux1;
2831 /* The value of the C_FUN is not the address of the function (it
2832 appears to be the address before linking), but as long as it
2833 is smaller than the actual address, then find_pc_partial_function
2834 will use the minimal symbols instead. I hope. */
2842 swap_sym (&symbol, &main_aux, &namestring, &sraw_symbol,
2844 #define CUR_SYMBOL_TYPE stype
2845 #define CUR_SYMBOL_VALUE symbol.n_value
2847 /* START_PSYMTAB and END_PSYMTAB are never used, because they are only
2848 called from DBXREAD_ONLY or N_SO code. Likewise for the symnum
2850 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms) 0
2851 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps)\
2853 /* We have already set the namestring. */
2854 #define SET_NAMESTRING() 0
2856 #include "partial-stab.h"
2861 /* If there's stuff to be cleaned up, clean it up. */
2862 if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */
2863 /*FIXME, does this have a bug at start address 0? */
2864 && last_o_file_start
2865 && objfile -> ei.entry_point < bufp->n_value
2866 && objfile -> ei.entry_point >= last_o_file_start)
2868 objfile -> ei.entry_file_lowpc = last_o_file_start;
2869 objfile -> ei.entry_file_highpc = bufp->n_value;
2875 xcoff_end_psymtab (pst, psymtab_include_list, includes_used,
2877 dependency_list, dependencies_used);
2880 /* Record the toc offset value of this symbol table into ldinfo structure.
2881 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
2882 this information would be file auxiliary header. */
2884 #ifndef FAKING_RS6000
2885 xcoff_add_toc_to_loadinfo (toc_offset);
2889 /* Scan and build partial symbols for a symbol file.
2890 We have been initialized by a call to dbx_symfile_init, which
2891 put all the relevant info into a "struct dbx_symfile_info",
2892 hung off the objfile structure.
2894 SECTION_OFFSETS contains offsets relative to which the symbols in the
2895 various sections are (depending where the sections were actually loaded).
2896 MAINLINE is true if we are reading the main symbol
2897 table (as opposed to a shared lib or dynamically loaded file). */
2900 xcoff_initial_scan (objfile, section_offsets, mainline)
2901 struct objfile *objfile;
2902 struct section_offsets *section_offsets;
2903 int mainline; /* FIXME comments above */
2907 struct cleanup *back_to;
2908 int num_symbols; /* # of symbols */
2909 file_ptr symtab_offset; /* symbol table and */
2910 file_ptr stringtab_offset; /* string table file offsets */
2911 struct coff_symfile_info *info;
2915 #ifndef FAKING_RS6000
2916 /* Initialize load info structure. */
2918 xcoff_init_loadinfo ();
2921 info = (struct coff_symfile_info *) objfile -> sym_private;
2922 symfile_bfd = abfd = objfile->obfd;
2923 name = objfile->name;
2925 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
2926 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
2927 stringtab_offset = symtab_offset +
2928 num_symbols * coff_data(abfd)->local_symesz;
2930 info->min_lineno_offset = 0;
2931 info->max_lineno_offset = 0;
2932 bfd_map_over_sections (abfd, find_linenos, info);
2934 if (num_symbols > 0)
2936 /* Read the string table. */
2937 init_stringtab (abfd, stringtab_offset, objfile);
2939 /* Read the .debug section, if present. */
2942 bfd_size_type length;
2943 char *debugsec = NULL;
2945 secp = bfd_get_section_by_name (abfd, ".debug");
2948 length = bfd_section_size (abfd, secp);
2952 (char *) obstack_alloc (&objfile->symbol_obstack, length);
2954 if (!bfd_get_section_contents (abfd, secp, debugsec,
2955 (file_ptr) 0, length))
2957 error ("Error reading .debug section of `%s': %s",
2958 name, bfd_errmsg (bfd_get_error ()));
2962 ((struct coff_symfile_info *)objfile->sym_private)->debugsec =
2967 /* Read the symbols. We keep them in core because we will want to
2968 access them randomly in read_symbol*. */
2969 val = bfd_seek (abfd, symtab_offset, L_SET);
2971 error ("Error reading symbols from %s: %s",
2972 name, bfd_errmsg (bfd_get_error ()));
2973 size = coff_data (abfd)->local_symesz * num_symbols;
2974 ((struct coff_symfile_info *)objfile->sym_private)->symtbl =
2975 obstack_alloc (&objfile->symbol_obstack, size);
2976 ((struct coff_symfile_info *)objfile->sym_private)->symtbl_num_syms =
2979 val = bfd_read (((struct coff_symfile_info *)objfile->sym_private)->symtbl,
2982 perror_with_name ("reading symbol table");
2984 /* If we are reinitializing, or if we have never loaded syms yet, init */
2986 || objfile->global_psymbols.size == 0
2987 || objfile->static_psymbols.size == 0)
2988 /* I'm not sure how how good num_symbols is; the rule of thumb in
2989 init_psymbol_list was developed for a.out. On the one hand,
2990 num_symbols includes auxents. On the other hand, it doesn't
2992 init_psymbol_list (objfile, num_symbols);
2995 back_to = make_cleanup (really_free_pendings, 0);
2997 init_minimal_symbol_collection ();
2998 make_cleanup (discard_minimal_symbols, 0);
3000 /* Now that the symbol table data of the executable file are all in core,
3001 process them and define symbols accordingly. */
3003 scan_xcoff_symtab (section_offsets, objfile);
3005 /* Install any minimal symbols that have been collected as the current
3006 minimal symbols for this objfile. */
3008 install_minimal_symbols (objfile);
3010 do_cleanups (back_to);
3013 static struct section_offsets *
3014 xcoff_symfile_offsets (objfile, addr)
3015 struct objfile *objfile;
3018 struct section_offsets *section_offsets;
3021 objfile->num_sections = SECT_OFF_MAX;
3022 section_offsets = (struct section_offsets *)
3024 (&objfile -> psymbol_obstack,
3025 sizeof (struct section_offsets)
3026 + sizeof (section_offsets->offsets) * objfile->num_sections);
3028 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
3029 of the .text section. This strikes me as wrong--whether the
3030 offset to be applied to symbol reading is relative to the start
3031 address of the section depends on the symbol format. In any
3032 event, this whole "addr" concept is pretty broken (it doesn't
3033 handle any section but .text sensibly), so just ignore the addr
3034 parameter and use 0. rs6000-nat.c will set the correct section
3035 offsets via objfile_relocate. */
3036 for (i = 0; i < objfile->num_sections; ++i)
3037 ANOFFSET (section_offsets, i) = addr;
3039 return section_offsets;
3042 /* Register our ability to parse symbols for xcoff BFD files. */
3044 static struct sym_fns xcoff_sym_fns =
3047 /* Because the bfd uses coff_flavour, we need to specially kludge
3048 the flavour. It is possible that coff and xcoff should be merged as
3049 they do have fundamental similarities (for example, the extra storage
3050 classes used for stabs could presumably be recognized in any COFF file).
3051 However, in addition to obvious things like all the csect hair, there are
3052 some subtler differences between xcoffread.c and coffread.c, notably
3053 the fact that coffread.c has no need to read in all the symbols, but
3054 xcoffread.c reads all the symbols and does in fact randomly access them
3055 (in C_BSTAT and line number processing). */
3057 (enum bfd_flavour)-1,
3059 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3060 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3061 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
3062 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
3063 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
3064 NULL /* next: pointer to next struct sym_fns */
3068 _initialize_xcoffread ()
3070 add_symtab_fns(&xcoff_sym_fns);
3072 /* Initialize symbol template later used for arguments. Its other
3073 fields are zero, or are filled in later. */
3074 SYMBOL_NAME (&parmsym) = "";
3075 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym, language_c);
3076 SYMBOL_NAMESPACE (&parmsym) = VAR_NAMESPACE;
3077 SYMBOL_CLASS (&parmsym) = LOC_ARG;
3079 func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
3080 "<function, no debug info>", NULL);
3081 TYPE_TARGET_TYPE (func_symbol_type) = builtin_type_int;
3083 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
3084 "<variable, no debug info>", NULL);