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., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Native only: Need struct tbtable in <sys/debug.h> from host, and
24 need xcoff_add_toc_to_loadinfo in rs6000-tdep.c from target.
25 need xcoff_init_loadinfo ditto.
26 However, if you grab <sys/debug.h> and make it available on your
27 host, and define FAKING_RS6000, then this code will compile. */
32 #include <sys/types.h>
38 #include <sys/param.h>
43 #include <sys/debug.h>
45 #include "coff/internal.h" /* FIXME, internal data from BFD */
46 #include "libcoff.h" /* FIXME, internal data from BFD */
47 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
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 /* Simplified internal version of coff symbol table information */
66 int c_symnum
; /* symbol number of this entry */
67 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
69 unsigned char c_sclass
;
74 /* The COFF line table, in raw form. */
75 static char *linetab
= NULL
; /* Its actual contents */
76 static long linetab_offset
; /* Its offset in the file */
77 static unsigned long linetab_size
; /* Its size */
79 /* last function's saved coff symbol `cs' */
81 static struct coff_symbol fcn_cs_saved
;
83 static bfd
*symfile_bfd
;
85 /* Core address of start and end of text of current source file.
86 This is calculated from the first function seen after a C_FILE
90 static CORE_ADDR cur_src_end_addr
;
92 /* Core address of the end of the first object file. */
94 static CORE_ADDR first_object_file_end
;
96 /* pointer to the string table */
99 /* length of the string table */
100 static int strtbl_len
;
102 /* pointer to debug section */
103 static char *debugsec
;
105 /* pointer to the a.out symbol table */
108 /* Number of symbols in symtbl. */
109 static int symtbl_num_syms
;
111 /* initial symbol-table-debug-string vector length */
113 #define INITIAL_STABVECTOR_LENGTH 40
115 /* Nonzero if within a function (so symbols should be local,
116 if nothing says specifically). */
120 /* Local variables that hold the shift and mask values for the
121 COFF file that we are currently reading. These come back to us
122 from BFD, and are referenced by their macro names, as well as
123 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
124 macros from ../internalcoff.h . */
126 static unsigned local_n_btshft
;
127 static unsigned local_n_tmask
;
130 #define N_BTSHFT local_n_btshft
132 #define N_TMASK local_n_tmask
134 /* Local variables that hold the sizes in the file of various COFF structures.
135 (We only need to know this to read them from the file -- BFD will then
136 translate the data in them, into `internal_xxx' structs in the right
137 byte order, alignment, etc.) */
139 static unsigned local_symesz
;
141 struct coff_symfile_info
{
142 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
143 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
146 static struct complaint rsym_complaint
=
147 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
149 static struct complaint storclass_complaint
=
150 {"Unexpected storage class: %d", 0, 0};
152 static struct complaint bf_notfound_complaint
=
153 {"line numbers off, `.bf' symbol not found", 0, 0};
156 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
157 CORE_ADDR
, CORE_ADDR
, unsigned *));
160 free_debugsection
PARAMS ((void));
163 init_debugsection
PARAMS ((bfd
*));
166 init_stringtab
PARAMS ((bfd
*, file_ptr
, struct objfile
*));
169 xcoff_symfile_init
PARAMS ((struct objfile
*));
172 xcoff_new_init
PARAMS ((struct objfile
*));
175 xcoff_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
178 xcoff_symfile_finish
PARAMS ((struct objfile
*));
180 static struct section_offsets
*
181 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
184 init_lineno
PARAMS ((bfd
*, file_ptr
, int));
187 free_linetab
PARAMS ((void));
190 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
193 coff_getfilename
PARAMS ((union internal_auxent
*));
196 read_symbol
PARAMS ((struct internal_syment
*, int));
199 read_symbol_lineno
PARAMS ((int));
202 read_symbol_nvalue
PARAMS ((int));
204 static struct symbol
*
205 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
208 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
211 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
214 #ifdef STATIC_NODEBUG_VARS
215 /* Return the section_offsets* that CS points to. */
216 static int cs_to_section
PARAMS ((struct coff_symbol
*, struct objfile
*));
218 struct find_targ_sec_arg
{
223 static void find_targ_sec
PARAMS ((bfd
*, asection
*, void *));
225 static void find_targ_sec (abfd
, sect
, obj
)
230 struct find_targ_sec_arg
*args
= (struct find_targ_sec_arg
*)obj
;
231 if (sect
->target_index
== args
->targ_index
)
233 /* This is the section. Figure out what SECT_OFF_* code it is. */
234 if (bfd_get_section_flags (abfd
, sect
) & SEC_CODE
)
235 *args
->resultp
= SECT_OFF_TEXT
;
236 else if (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
)
237 *args
->resultp
= SECT_OFF_DATA
;
239 *args
->resultp
= SECT_OFF_BSS
;
243 /* Return the section number (SECT_OFF_*) that CS points to. */
245 cs_to_section (cs
, objfile
)
246 struct coff_symbol
*cs
;
247 struct objfile
*objfile
;
249 int off
= SECT_OFF_TEXT
;
250 struct find_targ_sec_arg args
;
251 args
.targ_index
= cs
->c_secnum
;
253 bfd_map_over_sections (objfile
->obfd
, find_targ_sec
, &args
);
256 #endif /* STATIC_NODEBUG_VARS */
258 /* add a given stab string into given stab vector. */
261 add_stab_to_list (stabname
, stabvector
)
263 struct pending_stabs
**stabvector
;
265 if ( *stabvector
== NULL
) {
266 *stabvector
= (struct pending_stabs
*)
267 xmalloc (sizeof (struct pending_stabs
) +
268 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
269 (*stabvector
)->count
= 0;
270 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
272 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
273 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
274 *stabvector
= (struct pending_stabs
*)
275 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
276 (*stabvector
)->length
* sizeof (char*));
278 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
281 /* Linenos are processed on a file-by-file basis.
285 1) xlc (IBM's native c compiler) postpones static function code
286 emission to the end of a compilation unit. This way it can
287 determine if those functions (statics) are needed or not, and
288 can do some garbage collection (I think). This makes line
289 numbers and corresponding addresses unordered, and we end up
290 with a line table like:
307 and that breaks gdb's binary search on line numbers, if the
308 above table is not sorted on line numbers. And that sort
309 should be on function based, since gcc can emit line numbers
312 10 0x100 - for the init/test part of a for stmt.
315 10 0x400 - for the increment part of a for stmt.
317 arrange_linetable() will do this sorting.
319 2) aix symbol table might look like:
321 c_file // beginning of a new file
322 .bi // beginning of include file
323 .ei // end of include file
327 basically, .bi/.ei pairs do not necessarily encapsulate
328 their scope. They need to be recorded, and processed later
329 on when we come the end of the compilation unit.
330 Include table (inclTable) and process_linenos() handle
333 /* compare line table entry addresses. */
336 compare_lte (lte1
, lte2
)
337 struct linetable_entry
*lte1
, *lte2
;
339 return lte1
->pc
- lte2
->pc
;
342 /* Give a line table with function entries are marked, arrange its functions
343 in assending order and strip off function entry markers and return it in
344 a newly created table. If the old one is good enough, return the old one. */
345 /* FIXME: I think all this stuff can be replaced by just passing
346 sort_linevec = 1 to end_symtab. */
348 static struct linetable
*
349 arrange_linetable (oldLineTb
)
350 struct linetable
*oldLineTb
; /* old linetable */
353 newline
, /* new line count */
354 function_count
; /* # of functions */
356 struct linetable_entry
*fentry
; /* function entry vector */
357 int fentry_size
; /* # of function entries */
358 struct linetable
*newLineTb
; /* new line table */
360 #define NUM_OF_FUNCTIONS 20
362 fentry_size
= NUM_OF_FUNCTIONS
;
363 fentry
= (struct linetable_entry
*)
364 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
366 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
368 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
370 if (function_count
>= fentry_size
) { /* make sure you have room. */
372 fentry
= (struct linetable_entry
*)
373 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
375 fentry
[function_count
].line
= ii
;
376 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
381 if (function_count
== 0) {
385 else if (function_count
> 1)
386 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
388 /* allocate a new line table. */
389 newLineTb
= (struct linetable
*)
391 (sizeof (struct linetable
) +
392 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
394 /* if line table does not start with a function beginning, copy up until
398 if (oldLineTb
->item
[0].line
!= 0)
400 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
401 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
403 /* Now copy function lines one by one. */
405 for (ii
=0; ii
< function_count
; ++ii
) {
406 for (jj
= fentry
[ii
].line
+ 1;
407 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
409 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
412 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
418 /* We try to detect the beginning of a compilation unit. That info will
419 be used as an entry in line number recording routines (enter_line_range) */
421 static unsigned first_fun_line_offset
;
422 static unsigned first_fun_bf
;
424 #define mark_first_line(OFFSET, SYMNUM) \
425 if (!first_fun_line_offset) { \
426 first_fun_line_offset = OFFSET; \
427 first_fun_bf = SYMNUM; \
431 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
432 following `IncludeChain'. At the end of each symtab (end_symtab),
433 we will determine if we should create additional symtab's to
434 represent if (the include files. */
437 typedef struct _inclTable
{
438 char *name
; /* include filename */
440 /* Offsets to the line table. end points to the last entry which is
441 part of this include file. */
444 struct subfile
*subfile
;
445 unsigned funStartLine
; /* start line # of its function */
448 #define INITIAL_INCLUDE_TABLE_LENGTH 20
449 static InclTable
*inclTable
; /* global include table */
450 static int inclIndx
; /* last entry to table */
451 static int inclLength
; /* table length */
452 static int inclDepth
; /* nested include depth */
454 static void allocate_include_entry
PARAMS ((void));
457 record_include_begin (cs
)
458 struct coff_symbol
*cs
;
462 /* In xcoff, we assume include files cannot be nested (not in .c files
463 of course, but in corresponding .s files.). */
465 /* This can happen with old versions of GCC.
466 GCC 2.3.3-930426 does not exhibit this on a test case which
467 a user said produced the message for him. */
468 static struct complaint msg
= {"Nested C_BINCL symbols", 0, 0};
473 allocate_include_entry ();
475 inclTable
[inclIndx
].name
= cs
->c_name
;
476 inclTable
[inclIndx
].begin
= cs
->c_value
;
480 record_include_end (cs
)
481 struct coff_symbol
*cs
;
487 static struct complaint msg
= {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
491 allocate_include_entry ();
493 pTbl
= &inclTable
[inclIndx
];
494 pTbl
->end
= cs
->c_value
;
501 allocate_include_entry ()
503 if (inclTable
== NULL
)
505 inclTable
= (InclTable
*)
506 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
508 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
509 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
512 else if (inclIndx
>= inclLength
)
514 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
515 inclTable
= (InclTable
*)
516 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
517 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
518 '\0', sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
522 /* given the start and end addresses of a compilation unit (or a csect,
523 at times) process its lines and create appropriate line vectors. */
526 process_linenos (start
, end
)
527 CORE_ADDR start
, end
;
532 struct subfile main_subfile
; /* subfile structure for the main
535 /* in the main source file, any time we see a function entry, we reset
536 this variable to function's absolute starting line number. All the
537 following line numbers in the function are relative to this, and
538 we record absolute line numbers in record_line(). */
540 int main_source_baseline
= 0;
546 if (!(offset
= first_fun_line_offset
))
547 goto return_after_cleanup
;
549 memset (&main_subfile
, '\0', sizeof (main_subfile
));
550 first_fun_line_offset
= 0;
553 /* All source lines were in the main source file. None in include files. */
555 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
556 &main_source_baseline
);
558 /* else, there was source with line numbers in include files */
561 main_source_baseline
= 0;
562 for (ii
=0; ii
< inclIndx
; ++ii
) {
564 struct subfile
*tmpSubfile
;
566 /* if there is main file source before include file, enter it. */
567 if (offset
< inclTable
[ii
].begin
) {
569 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
, start
, 0,
570 &main_source_baseline
);
573 /* Have a new subfile for the include file */
575 tmpSubfile
= inclTable
[ii
].subfile
= (struct subfile
*)
576 xmalloc (sizeof (struct subfile
));
578 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
579 firstLine
= &(inclTable
[ii
].funStartLine
);
581 /* enter include file's lines now. */
582 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
583 inclTable
[ii
].end
, start
, 0, firstLine
);
585 offset
= inclTable
[ii
].end
+ LINESZ
;
588 /* all the include files' line have been processed at this point. Now,
589 enter remaining lines of the main file, if any left. */
590 if (offset
< (linetab_offset
+ linetab_size
+ 1 - LINESZ
)) {
591 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
592 &main_source_baseline
);
596 /* Process main file's line numbers. */
597 if (main_subfile
.line_vector
) {
598 struct linetable
*lineTb
, *lv
;
600 lv
= main_subfile
.line_vector
;
602 /* Line numbers are not necessarily ordered. xlc compilation will
603 put static function to the end. */
605 lineTb
= arrange_linetable (lv
);
607 current_subfile
->line_vector
= (struct linetable
*)
608 xrealloc (lv
, (sizeof (struct linetable
)
609 + lv
->nitems
* sizeof (struct linetable_entry
)));
614 current_subfile
->line_vector
= lineTb
;
617 current_subfile
->line_vector_length
=
618 current_subfile
->line_vector
->nitems
;
621 /* Now, process included files' line numbers. */
623 for (ii
=0; ii
< inclIndx
; ++ii
) {
625 if ( (inclTable
[ii
].subfile
)->line_vector
) { /* Useless if!!! FIXMEmgo */
626 struct linetable
*lineTb
, *lv
;
628 lv
= (inclTable
[ii
].subfile
)->line_vector
;
630 /* Line numbers are not necessarily ordered. xlc compilation will
631 put static function to the end. */
633 lineTb
= arrange_linetable (lv
);
637 /* For the same include file, we might want to have more than one subfile.
638 This happens if we have something like:
646 while foo.h including code in it. (stupid but possible)
647 Since start_subfile() looks at the name and uses an existing one if finds,
648 we need to provide a fake name and fool it. */
650 /* start_subfile (inclTable[ii].name, (char*)0); */
651 start_subfile (" ?", (char*)0);
652 free (current_subfile
->name
);
653 current_subfile
->name
= strdup (inclTable
[ii
].name
);
656 current_subfile
->line_vector
= (struct linetable
*)
657 xrealloc (lv
, (sizeof (struct linetable
)
658 + lv
->nitems
* sizeof (struct linetable_entry
)));
663 current_subfile
->line_vector
= lineTb
;
666 current_subfile
->line_vector_length
=
667 current_subfile
->line_vector
->nitems
;
668 start_subfile (pop_subfile (), (char*)0);
672 return_after_cleanup
:
674 /* We don't want to keep alloc/free'ing the global include file table. */
677 /* start with a fresh subfile structure for the next file. */
678 memset (&main_subfile
, '\0', sizeof (struct subfile
));
682 aix_process_linenos ()
684 /* process line numbers and enter them into line vector */
685 process_linenos (last_source_start_addr
, cur_src_end_addr
);
689 /* Enter a given range of lines into the line vector.
690 can be called in the following two ways:
691 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
692 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
694 endoffset points to the last line table entry that we should pay
698 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
, firstLine
)
699 struct subfile
*subfile
;
700 unsigned beginoffset
, endoffset
; /* offsets to line table */
701 CORE_ADDR startaddr
, endaddr
;
707 /* Do Byte swapping, if needed. FIXME! */
708 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
709 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
710 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
712 pp
= &linetab
[beginoffset
- linetab_offset
];
713 if (endoffset
!= 0 && endoffset
- linetab_offset
>= linetab_size
)
715 static struct complaint msg
=
716 {"Bad line table offset in C_EINCL directive", 0, 0};
720 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
721 : &linetab
[linetab_size
-1];
723 while (pp
<= limit
) {
725 /* find the address this line represents */
726 addr
= P_LINENO(pp
) ?
727 P_LINEADDR(pp
) : read_symbol_nvalue (P_LINESYM(pp
));
729 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
732 if (P_LINENO(pp
) == 0) {
733 *firstLine
= read_symbol_lineno (P_LINESYM(pp
));
734 record_line (subfile
, 0, addr
);
738 record_line (subfile
, *firstLine
+ P_LINENO(pp
), addr
);
745 int fsize
; /* file size */
746 int fixedparms
; /* number of fixed parms */
747 int floatparms
; /* number of float parms */
748 unsigned int parminfo
; /* parameter info.
749 See /usr/include/sys/debug.h
750 tbtable_ext.parminfo */
751 int framesize
; /* function frame size */
755 /* Given a function symbol, return its traceback information. */
758 retrieve_tracebackinfo (abfd
, textsec
, cs
)
761 struct coff_symbol
*cs
;
763 #define TBTABLE_BUFSIZ 2000
765 static TracebackInfo tbInfo
;
768 static char buffer
[TBTABLE_BUFSIZ
];
771 int bytesread
=0; /* total # of bytes read so far */
772 int bufferbytes
; /* number of bytes in the buffer */
774 int functionstart
= cs
->c_value
- textsec
->vma
;
776 memset (&tbInfo
, '\0', sizeof (tbInfo
));
778 /* keep reading blocks of data from the text section, until finding a zero
779 word and a traceback table. */
781 /* Note: The logical thing way to write this code would be to assign
782 to bufferbytes within the while condition. But that triggers a
783 compiler (xlc in AIX 3.2) bug, so simplify it... */
785 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
786 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
788 && (bfd_get_section_contents
789 (abfd
, textsec
, buffer
,
790 (file_ptr
)(functionstart
+ bytesread
), bufferbytes
)))
792 bytesread
+= bufferbytes
;
793 pinsn
= (int*) buffer
;
795 /* if this is the first time we filled the buffer, retrieve function
798 if (bytesread
== bufferbytes
) {
800 /* skip over unrelated instructions */
802 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
804 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
806 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
808 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
812 int tmp
= (*pinsn
>> 16) & 0xffff;
814 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
815 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
818 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
819 (tmp
== 0x9001)) /* st r0, NUM(r1) */
821 /* else, could not find a frame size. */
825 } while (++pinsn
&& *pinsn
);
827 if (!tbInfo
.framesize
)
832 /* look for a zero word. */
834 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
837 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
842 /* function size is the amount of bytes we have skipped so far. */
843 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
847 /* if we don't have the whole traceback table in the buffer, re-read
850 /* This is how much to read to get the traceback table.
851 8 bytes of the traceback table are always present, plus we
853 #define MIN_TBTABSIZ 12
855 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
857 /* In case if we are *very* close to the end of the text section
858 and cannot read properly from that point on, abort by returning
861 This could happen if the traceback table is only 8 bytes,
862 but we try to read 12 bytes of it.
863 Handle this case more graciously -- FIXME */
865 if (!bfd_get_section_contents (
866 abfd
, textsec
, buffer
,
867 (file_ptr
)(functionstart
+
868 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
869 { printf_unfiltered ("Abnormal return!..\n"); return NULL
; }
871 ptb
= (struct tbtable
*)buffer
;
874 ptb
= (struct tbtable
*)pinsn
;
876 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
877 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
878 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
882 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
883 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
889 /* Given a function symbol, return a pointer to its traceback table. */
892 retrieve_traceback (abfd
, textsec
, cs
, size
)
895 struct coff_symbol
*cs
;
896 int *size
; /* return function size */
898 #define TBTABLE_BUFSIZ 2000
899 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
902 static char buffer
[TBTABLE_BUFSIZ
];
905 int bytesread
=0; /* total # of bytes read so far */
906 int bufferbytes
; /* number of bytes in the buffer */
908 int functionstart
= cs
->c_value
- textsec
->filepos
+ textsec
->vma
;
911 /* keep reading blocks of data from the text section, until finding a zero
912 word and a traceback table. */
914 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
915 (file_ptr
)(functionstart
+ bytesread
),
917 (TBTABLE_BUFSIZ
< (textsec
->size
- functionstart
- bytesread
)) ?
918 TBTABLE_BUFSIZ
: (textsec
->size
- functionstart
- bytesread
))))
920 bytesread
+= bufferbytes
;
921 pinsn
= (int*) buffer
;
923 /* look for a zero word. */
925 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
928 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
933 /* function size is the amount of bytes we have skipped so far. */
934 *size
= bytesread
- (buffer
+ bufferbytes
- pinsn
);
938 /* if we don't have the whole traceback table in the buffer, re-read
941 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
943 /* In case if we are *very* close to the end of the text section
944 and cannot read properly from that point on, abort for now.
945 Handle this case more graciously -- FIXME */
947 if (!bfd_get_section_contents (
948 abfd
, textsec
, buffer
,
949 (file_ptr
)(functionstart
+
950 bytesread
- (buffer
+ bufferbytes
- pinsn
)),MIN_TBTABSIZ
))
951 /* abort (); */ { printf_unfiltered ("abort!!!\n"); return NULL
; }
953 return (struct tbtable
*)buffer
;
956 return (struct tbtable
*)pinsn
;
966 /* Save the vital information for use when closing off the current file.
967 NAME is the file name the symbols came from, START_ADDR is the first
968 text address for the file, and SIZE is the number of bytes of text. */
970 #define complete_symtab(name, start_addr) { \
971 last_source_file = savestring (name, strlen (name)); \
972 last_source_start_addr = start_addr; \
976 /* Refill the symbol table input buffer
977 and set the variables that control fetching entries from it.
978 Reports an error if no data available.
979 This function can read past the end of the symbol table
980 (into the string table) but this does no harm. */
982 /* Reading symbol table has to be fast! Keep the followings as macros, rather
985 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION, OBJFILE) \
989 if (namestr[0] == '.') ++namestr; \
992 obstack_copy0 (&objfile->symbol_obstack, namestr, strlen (namestr)); \
995 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
996 (char *)NULL, (SECTION), (OBJFILE)); \
997 misc_func_recorded = 1; \
1001 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
1002 in our initializer function at the bottom of the file, to avoid
1003 dependencies on the exact "struct symbol" format. */
1005 static struct symbol parmsym
;
1007 /* Add a parameter to a given pending symbol list. */
1009 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
1011 PARM = (struct symbol *) \
1012 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1013 *(PARM) = parmsym; \
1014 SYMBOL_TYPE (PARM) = PTYPE; \
1015 SYMBOL_VALUE (PARM) = VALUE; \
1016 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
1020 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
1021 nested. At any given time, a symbol can only be in one static block.
1022 This is the base address of current static block, zero if non exists. */
1024 static int static_block_base
= 0;
1026 /* Section number for the current static block. */
1028 static int static_block_section
= -1;
1030 /* true if space for symbol name has been allocated. */
1032 static int symname_alloced
= 0;
1034 /* Next symbol to read. Pointer into raw seething symbol table. */
1036 static char *raw_symbol
;
1038 /* This is the function which stabsread.c calls to get symbol
1041 xcoff_next_symbol_text ()
1043 struct internal_syment symbol
;
1044 static struct complaint msg
=
1045 {"Unexpected symbol continuation", 0, 0};
1048 bfd_coff_swap_sym_in (current_objfile
->obfd
, raw_symbol
, &symbol
);
1049 if (symbol
.n_zeroes
)
1053 /* Return something which points to '\0' and hope the symbol reading
1054 code does something reasonable. */
1057 else if (symbol
.n_sclass
& 0x80)
1059 retval
= debugsec
+ symbol
.n_offset
;
1060 raw_symbol
+= coff_data (current_objfile
->obfd
)->local_symesz
;
1067 /* Return something which points to '\0' and hope the symbol reading
1068 code does something reasonable. */
1074 /* read the whole symbol table of a given bfd. */
1077 read_xcoff_symtab (objfile
, nsyms
)
1078 struct objfile
*objfile
; /* Object file we're reading from */
1079 int nsyms
; /* # of symbols */
1081 bfd
*abfd
= objfile
->obfd
;
1082 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
1083 sec_ptr textsec
; /* Pointer to text section */
1084 TracebackInfo
*ptb
; /* Pointer to traceback table */
1086 struct internal_syment symbol
[1];
1087 union internal_auxent main_aux
;
1088 struct coff_symbol cs
[1];
1089 CORE_ADDR file_start_addr
= 0;
1090 CORE_ADDR file_end_addr
= 0;
1092 int next_file_symnum
= -1;
1093 int just_started
= 1;
1095 int toc_offset
= 0; /* toc offset value in data section. */
1099 long fcn_line_offset
;
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 current_objfile
= objfile
;
1118 /* Get the appropriate COFF "constants" related to the file we're
1120 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
1121 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
1122 local_symesz
= coff_data (abfd
)->local_symesz
;
1124 last_source_file
= NULL
;
1125 last_csect_name
= 0;
1127 misc_func_recorded
= 0;
1130 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1132 first_object_file_end
= 0;
1134 /* Allocate space for the entire symbol table at once, and read it
1135 all in. The bfd is already positioned at the beginning of
1136 the symbol table. */
1138 size
= coff_data (abfd
)->local_symesz
* nsyms
;
1139 symtbl
= xmalloc (size
);
1140 symtbl_num_syms
= nsyms
;
1142 val
= bfd_read (symtbl
, size
, 1, abfd
);
1144 perror_with_name ("reading symbol table");
1146 raw_symbol
= symtbl
;
1148 textsec
= bfd_get_section_by_name (abfd
, ".text");
1151 printf_unfiltered ("Unable to locate text section!\n");
1154 next_symbol_text_func
= xcoff_next_symbol_text
;
1156 while (symnum
< nsyms
)
1159 QUIT
; /* make this command interruptable. */
1161 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1162 /* read one symbol into `cs' structure. After processing the
1163 whole symbol table, only string table will be kept in memory,
1164 symbol table and debug section of xcoff will be freed. Thus
1165 we can mark symbols with names in string table as
1170 /* Swap and align the symbol into a reasonable C structure. */
1171 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1173 cs
->c_symnum
= symnum
;
1174 cs
->c_naux
= symbol
->n_numaux
;
1175 if (symbol
->n_zeroes
)
1177 symname_alloced
= 0;
1178 /* We must use the original, unswapped, name here so the name field
1179 pointed to by cs->c_name will persist throughout xcoffread. If
1180 we use the new field, it gets overwritten for each symbol. */
1181 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1182 /* If it's exactly E_SYMNMLEN characters long it isn't
1184 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1187 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1188 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1189 p
[E_SYMNMLEN
] = '\0';
1191 symname_alloced
= 1;
1194 else if (symbol
->n_sclass
& 0x80)
1196 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1197 symname_alloced
= 0;
1201 /* in string table */
1202 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1203 symname_alloced
= 1;
1205 cs
->c_value
= symbol
->n_value
;
1206 cs
->c_sclass
= symbol
->n_sclass
;
1207 cs
->c_secnum
= symbol
->n_scnum
;
1208 cs
->c_type
= (unsigned)symbol
->n_type
;
1210 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1213 /* Save addr of first aux entry. */
1214 raw_auxptr
= raw_symbol
;
1216 /* Skip all the auxents associated with this symbol. */
1217 for (ii
= symbol
->n_numaux
; ii
; --ii
)
1219 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1224 /* if symbol name starts with ".$" or "$", ignore it. */
1225 if (cs
->c_name
[0] == '$'
1226 || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1229 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
1231 if (last_source_file
)
1233 end_symtab (cur_src_end_addr
, 1, 0, objfile
,
1234 textsec
->target_index
);
1239 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1240 cur_src_end_addr
= first_object_file_end
;
1241 /* done with all files, everything from here on is globals */
1244 /* if explicitly specified as a function, treat is as one. */
1245 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
1247 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1248 0, cs
->c_naux
, &main_aux
);
1249 goto function_entry_point
;
1252 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
)
1255 /* Dealing with a symbol with a csect entry. */
1257 #define CSECT(PP) ((PP)->x_csect)
1258 #define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1259 #define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1260 #define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1261 #define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1263 /* Convert the auxent to something we can access. */
1264 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1265 0, cs
->c_naux
, &main_aux
);
1267 switch (CSECT_SMTYP (&main_aux
))
1271 /* Ignore all external references. */
1275 /* A section description. */
1277 switch (CSECT_SCLAS (&main_aux
))
1283 /* A program csect is seen. We have to allocate one
1284 symbol table for each program csect. Normally gdb
1285 prefers one symtab for each source file. In case
1286 of AIX, one source file might include more than one
1287 [PR] csect, and they don't have to be adjacent in
1288 terms of the space they occupy in memory. Thus, one
1289 single source file might get fragmented in the
1290 memory and gdb's file start and end address
1291 approach does not work! GCC (and I think xlc) seem
1292 to put all the code in the unnamed program csect. */
1294 if (last_csect_name
)
1297 /* If no misc. function recorded in the last
1298 seen csect, enter it as a function. This
1299 will take care of functions like strcmp()
1302 if (!misc_func_recorded
)
1305 RECORD_MINIMAL_SYMBOL
1306 (last_csect_name
, last_csect_val
,
1307 mst_text
, alloced
, last_csect_sec
,
1311 complete_symtab (filestring
, file_start_addr
);
1312 cur_src_end_addr
= file_end_addr
;
1313 end_symtab (file_end_addr
, 1, 0, objfile
,
1314 textsec
->target_index
);
1317 /* Give all csects for this source file the same
1319 start_symtab (filestring
, NULL
, (CORE_ADDR
)0);
1322 /* If this is the very first csect seen,
1323 basically `__start'. */
1326 first_object_file_end
1327 = cs
->c_value
+ CSECT_LEN (&main_aux
);
1331 file_start_addr
= cs
->c_value
;
1332 file_end_addr
= cs
->c_value
+ CSECT_LEN (&main_aux
);
1334 if (cs
->c_name
&& cs
->c_name
[0] == '.')
1336 last_csect_name
= cs
->c_name
;
1337 last_csect_val
= cs
->c_value
;
1338 last_csect_sec
= cs
->c_secnum
;
1341 misc_func_recorded
= 0;
1347 /* If the section is not a data description,
1348 ignore it. Note that uninitialized data will
1349 show up as XTY_CM/XMC_RW pair. */
1353 warning ("More than one xmc_tc0 symbol found.");
1354 toc_offset
= cs
->c_value
;
1358 #ifdef STATIC_NODEBUG_VARS
1359 /* We need to process these symbols if they are C_HIDEXT,
1360 for static variables in files compiled without -g. */
1361 if (cs
->c_sclass
== C_HIDEXT
)
1368 /* Ignore the symbol. */
1376 switch (CSECT_SCLAS (&main_aux
))
1379 /* a function entry point. */
1380 function_entry_point
:
1381 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1382 symname_alloced
, cs
->c_secnum
,
1385 fcn_line_offset
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1386 fcn_start_addr
= cs
->c_value
;
1388 /* save the function header info, which will be used
1389 when `.bf' is seen. */
1391 fcn_aux_saved
= main_aux
;
1395 /* If function has two auxent, then debugging information is
1396 already available for it. Process traceback table for
1397 functions with only one auxent. */
1399 if (cs
->c_naux
== 1)
1400 ptb
= retrieve_tracebackinfo (abfd
, textsec
, cs
);
1402 else if (cs
->c_naux
!= 2)
1404 static struct complaint msg
=
1405 {"Expected one or two auxents for function", 0, 0};
1409 /* If there is traceback info, create and add parameters
1412 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
))
1415 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1416 char *parmcode
= (char*) &ptb
->parminfo
;
1418 /* The link area is 0x18 bytes. */
1419 int parmvalue
= ptb
->framesize
+ 0x18;
1420 unsigned int ii
, mask
;
1422 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
)
1424 struct symbol
*parm
;
1426 if (ptb
->parminfo
& mask
)
1428 /* float or double */
1430 if (ptb
->parminfo
& mask
)
1434 (parm
, parmvalue
, builtin_type_double
,
1436 parmvalue
+= sizeof (double);
1442 (parm
, parmvalue
, builtin_type_float
,
1444 parmvalue
+= sizeof (float);
1449 static struct type
*intparm_type
;
1450 if (intparm_type
== NULL
)
1453 /* Create a type, which is a pointer
1454 type (a kludge to make it print
1455 in hex), but which has a name
1456 indicating we don't know the real
1462 TARGET_PTR_BIT
/ HOST_CHAR_BIT
,
1464 "<non-float parameter>",
1466 TYPE_TARGET_TYPE (intparm_type
) =
1473 parmvalue
+= sizeof (int);
1478 /* Fake this as a function. Needed in
1479 process_xcoff_symbol(). */
1483 (process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1484 pending_blocks
, cs
->c_value
,
1485 cs
->c_value
+ ptb
->fsize
, objfile
);
1490 /* shared library function trampoline code entry point. */
1492 /* record trampoline code entries as
1493 mst_solib_trampoline symbol. When we lookup mst
1494 symbols, we will choose mst_text over
1495 mst_solib_trampoline. */
1496 RECORD_MINIMAL_SYMBOL
1497 (cs
->c_name
, cs
->c_value
,
1498 mst_solib_trampoline
,
1499 symname_alloced
, cs
->c_secnum
, objfile
);
1503 /* The symbols often have the same names as debug symbols for
1504 functions, and confuse lookup_symbol. */
1508 /* xlc puts each variable in a separate csect, so we get
1509 an XTY_SD for each variable. But gcc puts several
1510 variables in a csect, so that each variable only gets
1511 an XTY_LD. We still need to record them. This will
1512 typically be XMC_RW; I suspect XMC_RO and XMC_BS might
1522 switch (cs
->c_sclass
)
1527 /* see if the last csect needs to be recorded. */
1529 if (last_csect_name
&& !misc_func_recorded
)
1532 /* If no misc. function recorded in the last seen csect, enter
1533 it as a function. This will take care of functions like
1534 strcmp() compiled by xlc. */
1537 RECORD_MINIMAL_SYMBOL
1538 (last_csect_name
, last_csect_val
,
1539 mst_text
, alloced
, last_csect_sec
, objfile
);
1542 /* c_value field contains symnum of next .file entry in table
1543 or symnum of first global after last .file. */
1545 next_file_symnum
= cs
->c_value
;
1547 /* Complete symbol table for last object file containing
1548 debugging information. */
1550 /* Whether or not there was a csect in the previous file, we
1551 have to call `end_stabs' and `start_stabs' to reset
1552 type_vector, line_vector, etc. structures. */
1554 complete_symtab (filestring
, file_start_addr
);
1555 cur_src_end_addr
= file_end_addr
;
1556 end_symtab (file_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1559 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1560 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1561 standard COFF way and put it in the auxent. We use the auxent if
1562 the symbol is ".file" and an auxent exists, otherwise use the symbol
1563 itself. Simple enough. */
1564 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1566 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1567 0, cs
->c_naux
, &main_aux
);
1568 filestring
= coff_getfilename (&main_aux
);
1571 filestring
= cs
->c_name
;
1574 start_symtab (filestring
, (char *)NULL
, (CORE_ADDR
)0);
1575 last_csect_name
= 0;
1577 /* reset file start and end addresses. A compilation unit with no text
1578 (only data) should have zero file boundaries. */
1579 file_start_addr
= file_end_addr
= 0;
1583 fcn_stab_saved
= *cs
;
1587 if (STREQ (cs
->c_name
, ".bf"))
1590 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1591 0, cs
->c_naux
, &main_aux
);
1593 within_function
= 1;
1595 mark_first_line (fcn_line_offset
, cs
->c_symnum
);
1597 new = push_context (0, fcn_start_addr
);
1599 new->name
= define_symbol
1600 (fcn_cs_saved
.c_value
, fcn_stab_saved
.c_name
, 0, 0, objfile
);
1601 if (new->name
!= NULL
)
1602 SYMBOL_SECTION (new->name
) = cs
->c_secnum
;
1604 else if (STREQ (cs
->c_name
, ".ef"))
1607 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1608 0, cs
->c_naux
, &main_aux
);
1610 /* The value of .ef is the address of epilogue code;
1611 not useful for gdb. */
1612 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1613 contains number of lines to '}' */
1615 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1616 new = pop_context ();
1617 if (context_stack_depth
!= 0)
1619 invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1622 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1624 fcn_cs_saved
.c_value
+
1625 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
1626 within_function
= 0;
1631 /* Begin static block. */
1633 struct internal_syment symbol
;
1635 read_symbol (&symbol
, cs
->c_value
);
1636 static_block_base
= symbol
.n_value
;
1637 static_block_section
= symbol
.n_scnum
;
1642 /* End of static block. */
1643 static_block_base
= 0;
1644 static_block_section
= -1;
1654 ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
1662 /* This is wrong. These symbols are XMC_TC, which means that
1663 the value of the symbol is the address of the TOC entry, not
1664 the address of the variable itself. */
1666 #ifdef STATIC_NODEBUG_VARS
1668 /* This is the only place that static variables show up in files
1669 compiled without -g. External variables also have a C_EXT,
1670 so that is why we record everything as mst_file_* here. */
1671 enum minimal_symbol_type ms_type
;
1675 sec
= cs_to_section (cs
, objfile
);
1676 tmpaddr
= cs
->c_value
;
1681 case SECT_OFF_RODATA
:
1682 ms_type
= mst_file_text
;
1685 ms_type
= mst_file_data
;
1688 ms_type
= mst_file_bss
;
1691 ms_type
= mst_unknown
;
1694 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, ms_type
,
1695 symname_alloced
, cs
->c_secnum
, objfile
);
1697 #endif /* STATIC_NODEBUG_VARS */
1701 /* beginning of include file */
1702 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1703 order. Thus, when wee see them, we might not know enough info
1704 to process them. Thus, we'll be saving them into a table
1705 (inclTable) and postpone their processing. */
1707 record_include_begin (cs
);
1711 /* End of include file. */
1712 /* See the comment after case C_BINCL. */
1713 record_include_end (cs
);
1717 if (STREQ (cs
->c_name
, ".bb"))
1720 new = push_context (depth
, cs
->c_value
);
1722 else if (STREQ (cs
->c_name
, ".eb"))
1724 new = pop_context ();
1725 if (depth
!= new->depth
)
1727 Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1731 if (local_symbols
&& context_stack_depth
> 0)
1733 /* Make a block for the local symbols within. */
1734 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1735 new->start_addr
, cs
->c_value
, objfile
);
1737 local_symbols
= new->locals
;
1742 process_xcoff_symbol (cs
, objfile
);
1747 if (last_source_file
)
1749 end_symtab (cur_src_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1754 current_objfile
= NULL
;
1756 /* Record the toc offset value of this symbol table into ldinfo structure.
1757 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1758 this information would be file auxiliary header. */
1760 #ifndef FAKING_RS6000
1761 xcoff_add_toc_to_loadinfo (toc_offset
);
1765 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1766 (SYMBOL2) = (struct symbol *) \
1767 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1768 *(SYMBOL2) = *(SYMBOL1);
1771 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1772 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1775 static struct type
*func_symbol_type
;
1776 static struct type
*var_symbol_type
;
1778 /* process one xcoff symbol. */
1780 static struct symbol
*
1781 process_xcoff_symbol (cs
, objfile
)
1782 register struct coff_symbol
*cs
;
1783 struct objfile
*objfile
;
1785 struct symbol onesymbol
;
1786 register struct symbol
*sym
= &onesymbol
;
1787 struct symbol
*sym2
= NULL
;
1789 char *name
, *pp
, *qq
;
1790 int struct_and_type_combined
;
1797 memset (sym
, '\0', sizeof (struct symbol
));
1799 /* default assumptions */
1800 SYMBOL_VALUE (sym
) = cs
->c_value
;
1801 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1802 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1804 if (ISFCN (cs
->c_type
))
1806 /* At this point, we don't know the type of the function. This
1807 will be patched with the type from its stab entry later on in
1808 patch_block_stabs (), unless the file was compiled without -g. */
1810 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1811 SYMBOL_TYPE (sym
) = func_symbol_type
;
1813 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1814 SYMBOL_DUP (sym
, sym2
);
1816 if (cs
->c_sclass
== C_EXT
)
1817 add_symbol_to_list (sym2
, &global_symbols
);
1818 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1819 add_symbol_to_list (sym2
, &file_symbols
);
1823 /* In case we can't figure out the type, provide default. */
1824 SYMBOL_TYPE (sym
) = var_symbol_type
;
1826 switch (cs
->c_sclass
)
1830 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1831 add_stab_to_list (name
, &global_stabs
);
1833 add_stab_to_list (name
, &file_stabs
);
1838 add_stab_to_list (name
, &global_stabs
);
1842 common_block_start (cs
->c_name
, objfile
);
1846 common_block_end (objfile
);
1850 complain (&storclass_complaint
, cs
->c_sclass
);
1858 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1861 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1867 /* For xlc (not GCC), the 'V' symbol descriptor is used for
1868 all statics and we need to distinguish file-scope versus
1869 function-scope using within_function. We do this by
1870 changing the string we pass to define_symbol to use 'S'
1871 where we need to, which is not necessarily super-clean,
1872 but seems workable enough. */
1874 if (*name
== ':' || (pp
= (char *) strchr(name
, ':')) == NULL
)
1878 if (*pp
== 'V' && !within_function
)
1880 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1883 SYMBOL_VALUE (sym
) += static_block_base
;
1884 SYMBOL_SECTION (sym
) = static_block_section
;
1889 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, N_LSYM
, objfile
);
1892 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1897 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1898 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1899 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1900 SYMBOL_DUP (sym
, sym2
);
1901 add_symbol_to_list (sym2
, &local_symbols
);
1905 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1906 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1907 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1908 SYMBOL_DUP (sym
, sym2
);
1909 add_symbol_to_list (sym2
, &global_symbols
);
1913 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1914 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1915 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1916 SYMBOL_DUP (sym
, sym2
);
1918 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1922 printf_unfiltered ("ERROR! C_REG is not fully implemented!\n");
1923 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1924 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1925 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1926 SYMBOL_DUP (sym
, sym2
);
1927 add_symbol_to_list (sym2
, &local_symbols
);
1931 pp
= (char*) strchr (name
, ':');
1934 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1936 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1941 complain (&rsym_complaint
, name
);
1949 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1950 only the last component of the name. Result is in static storage and
1951 is only good for temporary use. */
1954 coff_getfilename (aux_entry
)
1955 union internal_auxent
*aux_entry
;
1957 static char buffer
[BUFSIZ
];
1958 register char *temp
;
1961 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1962 strcpy (buffer
, strtbl
+ aux_entry
->x_file
.x_n
.x_offset
);
1965 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1966 buffer
[FILNMLEN
] = '\0';
1970 /* FIXME: We should not be throwing away the information about what
1971 directory. It should go into dirname of the symtab, or some such
1973 if ((temp
= strrchr (result
, '/')) != NULL
)
1978 /* Set *SYMBOL to symbol number symno in symtbl. */
1980 read_symbol (symbol
, symno
)
1981 struct internal_syment
*symbol
;
1984 if (symno
< 0 || symno
>= symtbl_num_syms
)
1986 static struct complaint msg
=
1987 {"Invalid symbol offset", 0, 0};
1989 symbol
->n_value
= 0;
1990 symbol
->n_scnum
= -1;
1993 bfd_coff_swap_sym_in (symfile_bfd
, symtbl
+ (symno
*local_symesz
), symbol
);
1996 /* Get value corresponding to symbol number symno in symtbl. */
1999 read_symbol_nvalue (symno
)
2002 struct internal_syment symbol
[1];
2004 read_symbol (symbol
, symno
);
2005 return symbol
->n_value
;
2009 /* Find the address of the function corresponding to symno, where
2010 symno is the symbol pointed to by the linetable. */
2013 read_symbol_lineno (symno
)
2016 struct internal_syment symbol
[1];
2017 union internal_auxent main_aux
[1];
2019 /* Note that just searching for a short distance (e.g. 50 symbols)
2020 is not enough, at least in the following case.
2023 [many .stabx entries]
2024 [a few functions, referring to foo]
2028 What happens here is that the assembler moves the .stabx entries
2029 to right before the ".bf" for foo, but the symbol for "foo" is before
2030 all the stabx entries. See PR gdb/2222. */
2031 while (symno
< symtbl_num_syms
) {
2032 bfd_coff_swap_sym_in (symfile_bfd
,
2033 symtbl
+ (symno
*local_symesz
), symbol
);
2034 if (symbol
->n_sclass
== C_FCN
&& STREQ (symbol
->n_name
, ".bf"))
2036 symno
+= symbol
->n_numaux
+1;
2039 complain (&bf_notfound_complaint
);
2043 /* take aux entry and return its lineno */
2045 bfd_coff_swap_aux_in (symfile_bfd
, symtbl
+(symno
*local_symesz
),
2046 symbol
->n_type
, symbol
->n_sclass
,
2047 0, symbol
->n_numaux
, main_aux
);
2049 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
2052 /* Support for line number handling */
2054 /* This function is called for every section; it finds the outer limits
2055 * of the line table (minimum and maximum file offset) so that the
2056 * mainline code can read the whole thing for efficiency.
2059 find_linenos(abfd
, asect
, vpinfo
)
2064 struct coff_symfile_info
*info
;
2066 file_ptr offset
, maxoff
;
2068 count
= asect
->lineno_count
;
2070 if (!STREQ (asect
->name
, ".text") || count
== 0)
2073 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
2074 info
= (struct coff_symfile_info
*)vpinfo
;
2075 offset
= asect
->line_filepos
;
2076 maxoff
= offset
+ size
;
2078 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
2079 info
->min_lineno_offset
= offset
;
2081 if (maxoff
> info
->max_lineno_offset
)
2082 info
->max_lineno_offset
= maxoff
;
2086 /* Read in all the line numbers for fast lookups later. Leave them in
2087 external (unswapped) format in memory; we'll swap them as we enter
2088 them into GDB's data structures. */
2091 init_lineno (abfd
, offset
, size
)
2100 if (bfd_seek(abfd
, offset
, L_SET
) < 0)
2103 linetab
= (char *) xmalloc(size
);
2105 val
= bfd_read(linetab
, 1, size
, abfd
);
2109 linetab_offset
= offset
;
2110 linetab_size
= size
;
2123 xcoff_new_init (objfile
)
2124 struct objfile
*objfile
;
2129 /* xcoff_symfile_init()
2130 is the xcoff-specific initialization routine for reading symbols.
2131 It is passed an objfile which contains, among other things,
2132 the BFD for the file whose symbols are being read, and a slot for
2133 a pointer to "private data" which we fill with cookies and other
2134 treats for xcoff_symfile_read().
2136 We will only be called if this is an XCOFF or XCOFF-like file.
2137 BFD handles figuring out the format of the file, and code in symfile.c
2138 uses BFD's determination to vector to us.
2140 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
2143 xcoff_symfile_init (objfile
)
2144 struct objfile
*objfile
;
2146 bfd
*abfd
= objfile
->obfd
;
2148 /* Allocate struct to keep track of the symfile */
2149 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
2150 sizeof (struct coff_symfile_info
));
2151 init_entry_point_info (objfile
);
2154 /* Perform any local cleanups required when we are done with a particular
2155 objfile. I.E, we are in the process of discarding all symbol information
2156 for an objfile, freeing up all memory held for it, and unlinking the
2157 objfile struct from the global list of known objfiles. */
2160 xcoff_symfile_finish (objfile
)
2161 struct objfile
*objfile
;
2163 if (objfile
-> sym_private
!= NULL
)
2165 mfree (objfile
-> md
, objfile
-> sym_private
);
2168 /* Start with a fresh include table for the next objfile. */
2175 inclIndx
= inclLength
= inclDepth
= 0;
2180 init_stringtab(abfd
, offset
, objfile
)
2183 struct objfile
*objfile
;
2187 unsigned char lengthbuf
[4];
2189 if (bfd_seek(abfd
, offset
, L_SET
) < 0)
2192 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
2193 length
= bfd_h_get_32(abfd
, lengthbuf
);
2195 /* If no string table is needed, then the file may end immediately
2196 after the symbols. Just return with `strtbl' set to null. */
2198 if (val
!= sizeof length
|| length
< sizeof length
)
2201 /* Allocate string table from symbol_obstack. We will need this table
2202 as long as we have its symbol table around. */
2204 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
2208 memcpy(strtbl
, &length
, sizeof length
);
2209 if (length
== sizeof length
)
2212 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
2214 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
2221 init_debugsection(abfd
)
2224 register sec_ptr secp
;
2225 bfd_size_type length
;
2232 secp
= bfd_get_section_by_name(abfd
, ".debug");
2236 if (!(length
= bfd_section_size(abfd
, secp
)))
2239 debugsec
= (char *) xmalloc ((unsigned)length
);
2240 if (debugsec
== NULL
)
2243 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
2244 printf_unfiltered ("Can't read .debug section from symbol file\n");
2259 /* xcoff version of symbol file read. */
2262 xcoff_symfile_read (objfile
, section_offset
, mainline
)
2263 struct objfile
*objfile
;
2264 struct section_offsets
*section_offset
;
2267 int num_symbols
; /* # of symbols */
2268 file_ptr symtab_offset
; /* symbol table and */
2269 file_ptr stringtab_offset
; /* string table file offsets */
2272 struct coff_symfile_info
*info
;
2274 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2276 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2277 symfile_bfd
= abfd
= objfile
->obfd
;
2278 name
= objfile
->name
;
2280 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2281 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2282 stringtab_offset
= symtab_offset
+
2283 num_symbols
* coff_data(abfd
)->local_symesz
;
2285 info
->min_lineno_offset
= 0;
2286 info
->max_lineno_offset
= 0;
2287 bfd_map_over_sections (abfd
, find_linenos
, info
);
2289 /* FIXME! This stuff should move into symfile_init */
2290 if (info
->min_lineno_offset
!= 0
2291 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
2293 /* only read in the line # table if one exists */
2294 make_cleanup (free_linetab
, 0);
2295 val
= init_lineno(abfd
, info
->min_lineno_offset
,
2296 (int) (info
->max_lineno_offset
- info
->min_lineno_offset
));
2299 error("\"%s\": error reading line numbers\n", name
);
2302 if (num_symbols
> 0)
2304 val
= init_stringtab(abfd
, stringtab_offset
, objfile
);
2306 error ("\"%s\": can't get string table", name
);
2309 if (init_debugsection(abfd
) < 0) {
2310 error ("Error reading .debug section of `%s'\n", name
);
2314 /* Position to read the symbol table. Do not read it all at once. */
2315 val
= bfd_seek(abfd
, symtab_offset
, L_SET
);
2317 perror_with_name(name
);
2319 if (bfd_tell(abfd
) != symtab_offset
)
2322 init_minimal_symbol_collection ();
2323 make_cleanup (discard_minimal_symbols
, 0);
2325 #ifndef FAKING_RS6000
2326 /* Initialize load info structure. */
2328 xcoff_init_loadinfo ();
2331 /* Now that the executable file is positioned at symbol table,
2332 process it and define symbols accordingly. */
2334 read_xcoff_symtab(objfile
, num_symbols
);
2336 /* Free debug section. */
2337 free_debugsection ();
2339 /* Sort symbols alphabetically within each block. */
2342 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2344 sort_symtab_syms (s
);
2348 /* Install any minimal symbols that have been collected as the current
2349 minimal symbols for this objfile. */
2351 install_minimal_symbols (objfile
);
2353 do_cleanups (back_to
);
2356 /* XCOFF-specific parsing routine for section offsets. */
2358 static int largest_section
;
2361 note_one_section (abfd
, asect
, ptr
)
2366 if (asect
->target_index
> largest_section
)
2367 largest_section
= asect
->target_index
;
2371 struct section_offsets
*
2372 xcoff_symfile_offsets (objfile
, addr
)
2373 struct objfile
*objfile
;
2376 struct section_offsets
*section_offsets
;
2379 largest_section
= 0;
2380 bfd_map_over_sections (objfile
->obfd
, note_one_section
, NULL
);
2381 objfile
->num_sections
= largest_section
+ 1;
2382 section_offsets
= (struct section_offsets
*)
2384 (&objfile
-> psymbol_obstack
,
2385 sizeof (struct section_offsets
)
2386 + sizeof (section_offsets
->offsets
) * (objfile
->num_sections
));
2388 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2389 of the .text section. This strikes me as wrong--whether the
2390 offset to be applied to symbol reading is relative to the start
2391 address of the section depends on the symbol format. In any
2392 event, this whole "addr" concept is pretty broken (it doesn't
2393 handle any section but .text sensibly), so just ignore the addr
2394 parameter and use 0. That matches the fact that xcoff_symfile_read
2395 ignores the section_offsets). */
2396 for (i
= 0; i
< objfile
->num_sections
; i
++)
2397 ANOFFSET (section_offsets
, i
) = 0;
2399 return section_offsets
;
2402 /* Register our ability to parse symbols for xcoff BFD files. */
2404 static struct sym_fns xcoff_sym_fns
=
2407 /* Because the bfd uses coff_flavour, we need to specially kludge
2408 the flavour. FIXME: coff and xcoff and fundamentally similar
2409 except for debug format, and we should see if we can merge this
2410 file with coffread.c. For example, the extra storage classes
2411 used for stabs could presumably be recognized in any COFF file. */
2413 (enum bfd_flavour
)-1,
2415 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2416 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2417 xcoff_symfile_read
, /* sym_read: read a symbol file into symtab */
2418 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2419 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2420 NULL
/* next: pointer to next struct sym_fns */
2424 _initialize_xcoffread ()
2426 add_symtab_fns(&xcoff_sym_fns
);
2428 /* Initialize symbol template later used for arguments. Its other
2429 fields are zero, or are filled in later. */
2430 SYMBOL_NAME (&parmsym
) = "";
2431 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym
, language_c
);
2432 SYMBOL_NAMESPACE (&parmsym
) = VAR_NAMESPACE
;
2433 SYMBOL_CLASS (&parmsym
) = LOC_ARG
;
2435 func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
2436 "<function, no debug info>", NULL
);
2437 TYPE_TARGET_TYPE (func_symbol_type
) = builtin_type_int
;
2439 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
2440 "<variable, no debug info>", NULL
);