1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3 Free Software Foundation, Inc.
4 Derived from coffread.c, dbxread.c, and a lot of hacking.
5 Contributed by IBM Corporation.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Native only: Need struct tbtable in <sys/debug.h> from host, and
24 need xcoff_add_toc_to_loadinfo in rs6000-tdep.c from target.
25 need xcoff_init_loadinfo ditto.
26 However, if you grab <sys/debug.h> and make it available on your
27 host, and define FAKING_RS6000, then this code will compile. */
32 #include <sys/types.h>
37 #include <sys/param.h>
42 #include <sys/debug.h>
49 #include "stabsread.h"
50 #include "complaints.h"
52 #include "coff/internal.h" /* FIXME, internal data from BFD */
53 #include "libcoff.h" /* FIXME, internal data from BFD */
54 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
56 /* For interface with stabsread.c. */
57 #include "aout/stab_gnu.h"
59 /* Define this if you want gdb to ignore typdef stabs. This was needed for
60 one of Transarc, to reduce the size of the symbol table. Types won't be
61 recognized, but tag names will be. */
63 /* #define NO_TYPEDEFS 1 */
65 /* Simplified internal version of coff symbol table information */
69 int c_symnum
; /* symbol number of this entry */
70 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
72 unsigned char c_sclass
;
77 /* The COFF line table, in raw form. */
78 static char *linetab
= NULL
; /* Its actual contents */
79 static long linetab_offset
; /* Its offset in the file */
80 static unsigned long linetab_size
; /* Its size */
82 /* last function's saved coff symbol `cs' */
84 static struct coff_symbol fcn_cs_saved
;
86 static bfd
*symfile_bfd
;
88 /* Core address of start and end of text of current source file.
89 This is calculated from the first function seen after a C_FILE
93 static CORE_ADDR cur_src_end_addr
;
95 /* Core address of the end of the first object file. */
97 static CORE_ADDR first_object_file_end
;
99 /* pointer to the string table */
102 /* length of the string table */
103 static int strtbl_len
;
105 /* pointer to debug section */
106 static char *debugsec
;
108 /* pointer to the a.out symbol table */
111 /* Number of symbols in symtbl. */
112 static int symtbl_num_syms
;
114 /* initial symbol-table-debug-string vector length */
116 #define INITIAL_STABVECTOR_LENGTH 40
118 /* Nonzero if within a function (so symbols should be local,
119 if nothing says specifically). */
123 /* Local variables that hold the shift and mask values for the
124 COFF file that we are currently reading. These come back to us
125 from BFD, and are referenced by their macro names, as well as
126 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
127 macros from ../internalcoff.h . */
129 static unsigned local_n_btshft
;
130 static unsigned local_n_tmask
;
133 #define N_BTSHFT local_n_btshft
135 #define N_TMASK local_n_tmask
137 /* Local variables that hold the sizes in the file of various COFF structures.
138 (We only need to know this to read them from the file -- BFD will then
139 translate the data in them, into `internal_xxx' structs in the right
140 byte order, alignment, etc.) */
142 static unsigned local_symesz
;
144 struct coff_symfile_info
{
145 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
146 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
149 static struct complaint rsym_complaint
=
150 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
152 static struct complaint storclass_complaint
=
153 {"Unexpected storage class: %d", 0, 0};
155 static struct complaint bf_notfound_complaint
=
156 {"line numbers off, `.bf' symbol not found", 0, 0};
159 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
160 CORE_ADDR
, CORE_ADDR
, unsigned *));
163 free_debugsection
PARAMS ((void));
166 init_debugsection
PARAMS ((bfd
*));
169 init_stringtab
PARAMS ((bfd
*, file_ptr
, struct objfile
*));
172 xcoff_symfile_init
PARAMS ((struct objfile
*));
175 xcoff_new_init
PARAMS ((struct objfile
*));
178 struct section_offset
;
182 xcoff_symfile_read
PARAMS ((struct objfile
*, struct section_offset
*, int));
185 xcoff_symfile_finish
PARAMS ((struct objfile
*));
187 static struct section_offsets
*
188 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
191 init_lineno
PARAMS ((bfd
*, file_ptr
, int));
194 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
197 read_symbol
PARAMS ((struct internal_syment
*, int));
200 read_symbol_lineno
PARAMS ((int));
203 read_symbol_nvalue
PARAMS ((int));
205 static struct symbol
*
206 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
209 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
212 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
214 /* add a given stab string into given stab vector. */
217 add_stab_to_list (stabname
, stabvector
)
219 struct pending_stabs
**stabvector
;
221 if ( *stabvector
== NULL
) {
222 *stabvector
= (struct pending_stabs
*)
223 xmalloc (sizeof (struct pending_stabs
) +
224 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
225 (*stabvector
)->count
= 0;
226 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
228 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
229 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
230 *stabvector
= (struct pending_stabs
*)
231 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
232 (*stabvector
)->length
* sizeof (char*));
234 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
237 /* Linenos are processed on a file-by-file basis.
241 1) xlc (IBM's native c compiler) postpones static function code
242 emission to the end of a compilation unit. This way it can
243 determine if those functions (statics) are needed or not, and
244 can do some garbage collection (I think). This makes line
245 numbers and corresponding addresses unordered, and we end up
246 with a line table like:
263 and that breaks gdb's binary search on line numbers, if the
264 above table is not sorted on line numbers. And that sort
265 should be on function based, since gcc can emit line numbers
268 10 0x100 - for the init/test part of a for stmt.
271 10 0x400 - for the increment part of a for stmt.
273 arrange_linetable() will do this sorting.
275 2) aix symbol table might look like:
277 c_file // beginning of a new file
278 .bi // beginning of include file
279 .ei // end of include file
283 basically, .bi/.ei pairs do not necessarily encapsulate
284 their scope. They need to be recorded, and processed later
285 on when we come the end of the compilation unit.
286 Include table (inclTable) and process_linenos() handle
289 /* compare line table entry addresses. */
292 compare_lte (lte1
, lte2
)
293 struct linetable_entry
*lte1
, *lte2
;
295 return lte1
->pc
- lte2
->pc
;
298 /* Give a line table with function entries are marked, arrange its functions
299 in assending order and strip off function entry markers and return it in
300 a newly created table. If the old one is good enough, return the old one. */
302 static struct linetable
*
303 arrange_linetable (oldLineTb
)
304 struct linetable
*oldLineTb
; /* old linetable */
307 newline
, /* new line count */
308 function_count
; /* # of functions */
310 struct linetable_entry
*fentry
; /* function entry vector */
311 int fentry_size
; /* # of function entries */
312 struct linetable
*newLineTb
; /* new line table */
314 #define NUM_OF_FUNCTIONS 20
316 fentry_size
= NUM_OF_FUNCTIONS
;
317 fentry
= (struct linetable_entry
*)
318 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
320 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
322 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
324 if (function_count
>= fentry_size
) { /* make sure you have room. */
326 fentry
= (struct linetable_entry
*)
327 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
329 fentry
[function_count
].line
= ii
;
330 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
335 if (function_count
== 0) {
339 else if (function_count
> 1)
340 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
342 /* allocate a new line table. */
343 newLineTb
= (struct linetable
*)
345 (sizeof (struct linetable
) +
346 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
348 /* if line table does not start with a function beginning, copy up until
352 if (oldLineTb
->item
[0].line
!= 0)
354 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
355 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
357 /* Now copy function lines one by one. */
359 for (ii
=0; ii
< function_count
; ++ii
) {
360 for (jj
= fentry
[ii
].line
+ 1;
361 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
363 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
366 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
372 /* We try to detect the beginning of a compilation unit. That info will
373 be used as an entry in line number recording routines (enter_line_range) */
375 static unsigned first_fun_line_offset
;
376 static unsigned first_fun_bf
;
378 #define mark_first_line(OFFSET, SYMNUM) \
379 if (!first_fun_line_offset) { \
380 first_fun_line_offset = OFFSET; \
381 first_fun_bf = SYMNUM; \
385 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
386 following `IncludeChain'. At the end of each symtab (end_symtab),
387 we will determine if we should create additional symtab's to
388 represent if (the include files. */
391 typedef struct _inclTable
{
392 char *name
; /* include filename */
394 /* Offsets to the line table. end points to the last entry which is
395 part of this include file. */
398 struct subfile
*subfile
;
399 unsigned funStartLine
; /* start line # of its function */
402 #define INITIAL_INCLUDE_TABLE_LENGTH 20
403 static InclTable
*inclTable
; /* global include table */
404 static int inclIndx
; /* last entry to table */
405 static int inclLength
; /* table length */
406 static int inclDepth
; /* nested include depth */
410 record_include_begin (cs
)
411 struct coff_symbol
*cs
;
415 /* In xcoff, we assume include files cannot be nested (not in .c files
416 of course, but in corresponding .s files.). */
418 /* This can happen with old versions of GCC.
419 GCC 2.3.3-930426 does not exhibit this on a test case which
420 a user said produced the message for him. */
421 static struct complaint msg
= {"Nested C_BINCL symbols", 0, 0};
426 /* allocate an include file, or make room for the new entry */
427 if (inclLength
== 0) {
428 inclTable
= (InclTable
*)
429 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
430 bzero (inclTable
, sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
431 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
434 else if (inclIndx
>= inclLength
) {
435 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
436 inclTable
= (InclTable
*)
437 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
438 bzero (inclTable
+inclLength
-INITIAL_INCLUDE_TABLE_LENGTH
,
439 sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
442 inclTable
[inclIndx
].name
= cs
->c_name
;
443 inclTable
[inclIndx
].begin
= cs
->c_value
;
448 record_include_end (cs
)
449 struct coff_symbol
*cs
;
455 static struct complaint msg
= {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
459 pTbl
= &inclTable
[inclIndx
];
460 pTbl
->end
= cs
->c_value
;
467 /* given the start and end addresses of a compilation unit (or a csect, at times)
468 process its lines and create appropriate line vectors. */
471 process_linenos (start
, end
)
472 CORE_ADDR start
, end
;
477 struct subfile main_subfile
; /* subfile structure for the main
480 /* in the main source file, any time we see a function entry, we reset
481 this variable to function's absolute starting line number. All the
482 following line numbers in the function are relative to this, and
483 we record absolute line numbers in record_line(). */
485 int main_source_baseline
= 0;
491 if (!(offset
= first_fun_line_offset
))
492 goto return_after_cleanup
;
494 bzero (&main_subfile
, sizeof (main_subfile
));
495 first_fun_line_offset
= 0;
498 /* All source lines were in the main source file. None in include files. */
500 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
501 &main_source_baseline
);
503 /* else, there was source with line numbers in include files */
506 main_source_baseline
= 0;
507 for (ii
=0; ii
< inclIndx
; ++ii
) {
509 struct subfile
*tmpSubfile
;
511 /* if there is main file source before include file, enter it. */
512 if (offset
< inclTable
[ii
].begin
) {
514 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
, start
, 0,
515 &main_source_baseline
);
518 /* Have a new subfile for the include file */
520 tmpSubfile
= inclTable
[ii
].subfile
= (struct subfile
*)
521 xmalloc (sizeof (struct subfile
));
523 bzero (tmpSubfile
, sizeof (struct subfile
));
524 firstLine
= &(inclTable
[ii
].funStartLine
);
526 /* enter include file's lines now. */
527 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
528 inclTable
[ii
].end
, start
, 0, firstLine
);
530 offset
= inclTable
[ii
].end
+ LINESZ
;
533 /* all the include files' line have been processed at this point. Now,
534 enter remaining lines of the main file, if any left. */
535 if (offset
< (linetab_offset
+ linetab_size
+ 1 - LINESZ
)) {
536 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
537 &main_source_baseline
);
541 /* Process main file's line numbers. */
542 if (main_subfile
.line_vector
) {
543 struct linetable
*lineTb
, *lv
;
545 lv
= main_subfile
.line_vector
;
547 /* Line numbers are not necessarily ordered. xlc compilation will
548 put static function to the end. */
550 lineTb
= arrange_linetable (lv
);
552 current_subfile
->line_vector
= (struct linetable
*)
553 xrealloc (lv
, (sizeof (struct linetable
)
554 + lv
->nitems
* sizeof (struct linetable_entry
)));
559 current_subfile
->line_vector
= lineTb
;
562 current_subfile
->line_vector_length
=
563 current_subfile
->line_vector
->nitems
;
566 /* Now, process included files' line numbers. */
568 for (ii
=0; ii
< inclIndx
; ++ii
) {
570 if ( (inclTable
[ii
].subfile
)->line_vector
) { /* Useless if!!! FIXMEmgo */
571 struct linetable
*lineTb
, *lv
;
573 lv
= (inclTable
[ii
].subfile
)->line_vector
;
575 /* Line numbers are not necessarily ordered. xlc compilation will
576 put static function to the end. */
578 lineTb
= arrange_linetable (lv
);
582 /* For the same include file, we might want to have more than one subfile.
583 This happens if we have something like:
591 while foo.h including code in it. (stupid but possible)
592 Since start_subfile() looks at the name and uses an existing one if finds,
593 we need to provide a fake name and fool it. */
595 /* start_subfile (inclTable[ii].name, (char*)0); */
596 start_subfile (" ?", (char*)0);
597 free (current_subfile
->name
);
598 current_subfile
->name
= strdup (inclTable
[ii
].name
);
601 current_subfile
->line_vector
= (struct linetable
*)
602 xrealloc (lv
, (sizeof (struct linetable
)
603 + lv
->nitems
* sizeof (struct linetable_entry
)));
608 current_subfile
->line_vector
= lineTb
;
611 current_subfile
->line_vector_length
=
612 current_subfile
->line_vector
->nitems
;
613 start_subfile (pop_subfile (), (char*)0);
617 return_after_cleanup
:
619 /* We don't want to keep alloc/free'ing the global include file table. */
622 /* start with a fresh subfile structure for the next file. */
623 bzero (&main_subfile
, sizeof (struct subfile
));
627 aix_process_linenos ()
629 /* process line numbers and enter them into line vector */
630 process_linenos (last_source_start_addr
, cur_src_end_addr
);
634 /* Enter a given range of lines into the line vector.
635 can be called in the following two ways:
636 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
637 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
639 endoffset points to the last line table entry that we should pay
643 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
, firstLine
)
644 struct subfile
*subfile
;
645 unsigned beginoffset
, endoffset
; /* offsets to line table */
646 CORE_ADDR startaddr
, endaddr
;
652 /* Do Byte swapping, if needed. FIXME! */
653 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
654 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
655 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
657 pp
= &linetab
[beginoffset
- linetab_offset
];
658 if (endoffset
!= 0 && endoffset
- linetab_offset
>= linetab_size
)
660 static struct complaint msg
=
661 {"Bad line table offset in C_EINCL directive", 0, 0};
665 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
666 : &linetab
[linetab_size
-1];
668 while (pp
<= limit
) {
670 /* find the address this line represents */
671 addr
= P_LINENO(pp
) ?
672 P_LINEADDR(pp
) : read_symbol_nvalue (P_LINESYM(pp
));
674 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
677 if (P_LINENO(pp
) == 0) {
678 *firstLine
= read_symbol_lineno (P_LINESYM(pp
));
679 record_line (subfile
, 0, addr
);
683 record_line (subfile
, *firstLine
+ P_LINENO(pp
), addr
);
690 int fsize
; /* file size */
691 int fixedparms
; /* number of fixed parms */
692 int floatparms
; /* number of float parms */
693 unsigned int parminfo
; /* parameter info.
694 See /usr/include/sys/debug.h
695 tbtable_ext.parminfo */
696 int framesize
; /* function frame size */
700 /* Given a function symbol, return its traceback information. */
703 retrieve_tracebackinfo (abfd
, textsec
, cs
)
706 struct coff_symbol
*cs
;
708 #define TBTABLE_BUFSIZ 2000
710 static TracebackInfo tbInfo
;
713 static char buffer
[TBTABLE_BUFSIZ
];
716 int bytesread
=0; /* total # of bytes read so far */
717 int bufferbytes
; /* number of bytes in the buffer */
719 int functionstart
= cs
->c_value
- textsec
->vma
;
721 bzero (&tbInfo
, sizeof (tbInfo
));
723 /* keep reading blocks of data from the text section, until finding a zero
724 word and a traceback table. */
726 /* Note: The logical thing way to write this code would be to assign
727 to bufferbytes within the while condition. But that triggers a
728 compiler (xlc in AIX 3.2) bug, so simplify it... */
730 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
731 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
733 && (bfd_get_section_contents
734 (abfd
, textsec
, buffer
,
735 (file_ptr
)(functionstart
+ bytesread
), bufferbytes
)))
737 bytesread
+= bufferbytes
;
738 pinsn
= (int*) buffer
;
740 /* if this is the first time we filled the buffer, retrieve function
743 if (bytesread
== bufferbytes
) {
745 /* skip over unrelated instructions */
747 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
749 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
751 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
753 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
757 int tmp
= (*pinsn
>> 16) & 0xffff;
759 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
760 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
763 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
764 (tmp
== 0x9001)) /* st r0, NUM(r1) */
766 /* else, could not find a frame size. */
770 } while (++pinsn
&& *pinsn
);
772 if (!tbInfo
.framesize
)
777 /* look for a zero word. */
779 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
782 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
787 /* function size is the amount of bytes we have skipped so far. */
788 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
792 /* if we don't have the whole traceback table in the buffer, re-read
795 /* This is how much to read to get the traceback table.
796 8 bytes of the traceback table are always present, plus we
798 #define MIN_TBTABSIZ 12
800 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
802 /* In case if we are *very* close to the end of the text section
803 and cannot read properly from that point on, abort by returning
806 This could happen if the traceback table is only 8 bytes,
807 but we try to read 12 bytes of it.
808 Handle this case more graciously -- FIXME */
810 if (!bfd_get_section_contents (
811 abfd
, textsec
, buffer
,
812 (file_ptr
)(functionstart
+
813 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
814 { printf ("Abnormal return!..\n"); return NULL
; }
816 ptb
= (struct tbtable
*)buffer
;
819 ptb
= (struct tbtable
*)pinsn
;
821 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
822 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
823 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
827 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
828 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
834 /* Given a function symbol, return a pointer to its traceback table. */
837 retrieve_traceback (abfd
, textsec
, cs
, size
)
840 struct coff_symbol
*cs
;
841 int *size
; /* return function size */
843 #define TBTABLE_BUFSIZ 2000
844 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
847 static char buffer
[TBTABLE_BUFSIZ
];
850 int bytesread
=0; /* total # of bytes read so far */
851 int bufferbytes
; /* number of bytes in the buffer */
853 int functionstart
= cs
->c_value
- textsec
->filepos
+ textsec
->vma
;
856 /* keep reading blocks of data from the text section, until finding a zero
857 word and a traceback table. */
859 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
860 (file_ptr
)(functionstart
+ bytesread
),
862 (TBTABLE_BUFSIZ
< (textsec
->size
- functionstart
- bytesread
)) ?
863 TBTABLE_BUFSIZ
: (textsec
->size
- functionstart
- bytesread
))))
865 bytesread
+= bufferbytes
;
866 pinsn
= (int*) buffer
;
868 /* look for a zero word. */
870 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
873 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
878 /* function size is the amount of bytes we have skipped so far. */
879 *size
= bytesread
- (buffer
+ bufferbytes
- pinsn
);
883 /* if we don't have the whole traceback table in the buffer, re-read
886 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
888 /* In case if we are *very* close to the end of the text section
889 and cannot read properly from that point on, abort for now.
890 Handle this case more graciously -- FIXME */
892 if (!bfd_get_section_contents (
893 abfd
, textsec
, buffer
,
894 (file_ptr
)(functionstart
+
895 bytesread
- (buffer
+ bufferbytes
- pinsn
)),MIN_TBTABSIZ
))
896 /* abort (); */ { printf ("abort!!!\n"); return NULL
; }
898 return (struct tbtable
*)buffer
;
901 return (struct tbtable
*)pinsn
;
911 /* Save the vital information for use when closing off the current file.
912 NAME is the file name the symbols came from, START_ADDR is the first
913 text address for the file, and SIZE is the number of bytes of text. */
915 #define complete_symtab(name, start_addr) { \
916 last_source_file = savestring (name, strlen (name)); \
917 last_source_start_addr = start_addr; \
921 /* Refill the symbol table input buffer
922 and set the variables that control fetching entries from it.
923 Reports an error if no data available.
924 This function can read past the end of the symbol table
925 (into the string table) but this does no harm. */
927 /* Reading symbol table has to be fast! Keep the followings as macros, rather
930 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION) \
934 namestr = (NAME) + 1; \
937 obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
940 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
941 (char *)NULL, (SECTION)); \
942 misc_func_recorded = 1; \
946 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
947 in our initializer function at the bottom of the file, to avoid
948 dependencies on the exact "struct symbol" format. */
950 static struct symbol parmsym
;
952 /* Add a parameter to a given pending symbol list. */
954 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
956 PARM = (struct symbol *) \
957 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
959 SYMBOL_TYPE (PARM) = PTYPE; \
960 SYMBOL_VALUE (PARM) = VALUE; \
961 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
965 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
966 nested. At any given time, a symbol can only be in one static block.
967 This is the base address of current static block, zero if non exists. */
969 static int static_block_base
= 0;
971 /* Section number for the current static block. */
973 static int static_block_section
= -1;
975 /* true if space for symbol name has been allocated. */
977 static int symname_alloced
= 0;
979 /* read the whole symbol table of a given bfd. */
982 read_xcoff_symtab (objfile
, nsyms
)
983 struct objfile
*objfile
; /* Object file we're reading from */
984 int nsyms
; /* # of symbols */
986 bfd
*abfd
= objfile
->obfd
;
987 char *raw_symbol
; /* Pointer into raw seething symbol table */
988 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
989 sec_ptr textsec
; /* Pointer to text section */
990 TracebackInfo
*ptb
; /* Pointer to traceback table */
992 struct internal_syment symbol
[1];
993 union internal_auxent main_aux
[1];
994 struct coff_symbol cs
[1];
995 CORE_ADDR file_start_addr
= 0;
996 CORE_ADDR file_end_addr
= 0;
998 int next_file_symnum
= -1;
999 int just_started
= 1;
1001 int toc_offset
= 0; /* toc offset value in data section. */
1005 long fcn_line_offset
;
1008 struct coff_symbol fcn_stab_saved
;
1010 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1011 union internal_auxent fcn_aux_saved
;
1012 struct type
*fcn_type_saved
= NULL
;
1013 struct context_stack
*new;
1015 char *filestring
= " _start_ "; /* Name of the current file. */
1017 char *last_csect_name
; /* last seen csect's name and value */
1018 CORE_ADDR last_csect_val
;
1020 int misc_func_recorded
; /* true if any misc. function */
1022 current_objfile
= objfile
;
1024 /* Get the appropriate COFF "constants" related to the file we're handling. */
1025 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
1026 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
1027 local_symesz
= coff_data (abfd
)->local_symesz
;
1029 last_source_file
= NULL
;
1030 last_csect_name
= 0;
1032 misc_func_recorded
= 0;
1035 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1037 first_object_file_end
= 0;
1039 /* Allocate space for the entire symbol table at once, and read it
1040 all in. The bfd is already positioned at the beginning of
1041 the symbol table. */
1043 size
= coff_data (abfd
)->local_symesz
* nsyms
;
1044 symtbl
= xmalloc (size
);
1045 symtbl_num_syms
= nsyms
;
1047 val
= bfd_read (symtbl
, size
, 1, abfd
);
1049 perror_with_name ("reading symbol table");
1051 raw_symbol
= symtbl
;
1053 textsec
= bfd_get_section_by_name (abfd
, ".text");
1055 printf ("Unable to locate text section!\n");
1058 while (symnum
< nsyms
) {
1060 QUIT
; /* make this command interruptable. */
1062 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1063 /* read one symbol into `cs' structure. After processing the whole symbol
1064 table, only string table will be kept in memory, symbol table and debug
1065 section of xcoff will be freed. Thus we can mark symbols with names
1066 in string table as `alloced'. */
1070 /* Swap and align the symbol into a reasonable C structure. */
1071 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1073 cs
->c_symnum
= symnum
;
1074 cs
->c_nsyms
= symbol
->n_numaux
;
1075 if (symbol
->n_zeroes
) {
1076 symname_alloced
= 0;
1077 /* We must use the original, unswapped, name here so the name field
1078 pointed to by cs->c_name will persist throughout xcoffread. If
1079 we use the new field, it gets overwritten for each symbol. */
1080 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1081 /* If it's exactly E_SYMNMLEN characters long it isn't
1083 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1086 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1087 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1088 p
[E_SYMNMLEN
] = '\0';
1090 symname_alloced
= 1;
1092 } else if (symbol
->n_sclass
& 0x80) {
1093 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1094 symname_alloced
= 0;
1095 } else { /* in string table */
1096 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1097 symname_alloced
= 1;
1099 cs
->c_value
= symbol
->n_value
;
1100 cs
->c_sclass
= symbol
->n_sclass
;
1101 cs
->c_secnum
= symbol
->n_scnum
;
1102 cs
->c_type
= (unsigned)symbol
->n_type
;
1104 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1107 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
1109 /* Skip all the auxents associated with this symbol. */
1110 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
1111 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1116 /* if symbol name starts with ".$" or "$", ignore it. */
1117 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1120 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
1121 if (last_source_file
)
1123 end_symtab (cur_src_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1128 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1129 cur_src_end_addr
= first_object_file_end
;
1130 /* done with all files, everything from here on is globals */
1133 /* if explicitly specified as a function, treat is as one. */
1134 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
1135 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1137 goto function_entry_point
;
1140 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
1142 /* dealing with a symbol with a csect entry. */
1144 # define CSECT(PP) ((PP)->x_csect)
1145 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1146 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1147 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1148 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1150 /* Convert the auxent to something we can access. */
1151 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1154 switch (CSECT_SMTYP (main_aux
)) {
1157 continue; /* ignore all external references. */
1159 case XTY_SD
: /* a section description. */
1161 switch (CSECT_SCLAS (main_aux
)) {
1163 case XMC_PR
: /* a `.text' csect. */
1166 /* A program csect is seen.
1168 We have to allocate one symbol table for each program csect. Normally
1169 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
1170 CU might include more than one prog csect, and they don't have to be
1171 adjacent in terms of the space they occupy in memory. Thus, one single
1172 CU might get fragmented in the memory and gdb's file start and end address
1173 approach does not work! */
1175 if (last_csect_name
) {
1177 /* if no misc. function recorded in the last seen csect, enter
1178 it as a function. This will take care of functions like
1179 strcmp() compiled by xlc. */
1181 if (!misc_func_recorded
) {
1183 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1184 mst_text
, alloced
, last_csect_sec
);
1188 complete_symtab (filestring
, file_start_addr
);
1189 cur_src_end_addr
= file_end_addr
;
1190 end_symtab (file_end_addr
, 1, 0, objfile
,
1191 textsec
->target_index
);
1194 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
1197 /* If this is the very first csect seen, basically `__start'. */
1199 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
1203 file_start_addr
= cs
->c_value
;
1204 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
1206 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
1207 last_csect_name
= cs
->c_name
;
1208 last_csect_val
= cs
->c_value
;
1209 last_csect_sec
= cs
->c_secnum
;
1212 misc_func_recorded
= 0;
1218 /* If the section is not a data description, ignore it. Note that
1219 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1223 warning ("More than one xmc_tc0 symbol found.");
1224 toc_offset
= cs
->c_value
;
1227 case XMC_TC
: /* ignore toc entries */
1228 default : /* any other XMC_XXX */
1232 break; /* switch CSECT_SCLAS() */
1236 /* a function entry point. */
1237 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
1239 function_entry_point
:
1240 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1241 symname_alloced
, cs
->c_secnum
);
1243 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1244 fcn_start_addr
= cs
->c_value
;
1246 /* save the function header info, which will be used
1247 when `.bf' is seen. */
1249 fcn_aux_saved
= *main_aux
;
1254 /* If function has two auxent, then debugging information is
1255 already available for it. Process traceback table for
1256 functions with only one auxent. */
1258 if (cs
->c_nsyms
== 1)
1259 ptb
= retrieve_tracebackinfo (abfd
, textsec
, cs
);
1261 else if (cs
->c_nsyms
!= 2)
1264 /* If there is traceback info, create and add parameters for it. */
1266 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
)) {
1268 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1269 char *parmcode
= (char*) &ptb
->parminfo
;
1270 int parmvalue
= ptb
->framesize
+ 0x18; /* sizeof(LINK AREA) == 0x18 */
1271 unsigned int ii
, mask
;
1273 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
) {
1274 struct symbol
*parm
;
1276 if (ptb
->parminfo
& mask
) { /* float or double */
1278 if (ptb
->parminfo
& mask
) { /* double parm */
1280 (parm
, parmvalue
, builtin_type_double
, local_symbols
);
1281 parmvalue
+= sizeof (double);
1283 else { /* float parm */
1285 (parm
, parmvalue
, builtin_type_float
, local_symbols
);
1286 parmvalue
+= sizeof (float);
1289 else { /* fixed parm, use (int*) for hex rep. */
1290 ADD_PARM_TO_PENDING (parm
, parmvalue
,
1291 lookup_pointer_type (builtin_type_int
),
1293 parmvalue
+= sizeof (int);
1298 /* Fake this as a function. Needed in process_xcoff_symbol() */
1301 finish_block(process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1302 pending_blocks
, cs
->c_value
,
1303 cs
->c_value
+ ptb
->fsize
, objfile
);
1307 /* shared library function trampoline code entry point. */
1308 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
1310 /* record trampoline code entries as mst_unknown symbol. When we
1311 lookup mst symbols, we will choose mst_text over mst_unknown. */
1314 /* After the implementation of incremental loading of shared
1315 libraries, we don't want to access trampoline entries. This
1316 approach has a consequence of the necessity to bring the whole
1317 shared library at first, in order do anything with it (putting
1318 breakpoints, using malloc, etc). On the other side, this is
1319 consistient with gdb's behaviour on a SUN platform. */
1321 /* Trying to prefer *real* function entry over its trampoline,
1322 by assigning `mst_unknown' type to trampoline entries fails.
1323 Gdb treats those entries as chars. FIXME. */
1325 /* Recording this entry is necessary. Single stepping relies on
1326 this vector to get an idea about function address boundaries. */
1328 prim_record_minimal_symbol_and_info
1329 ("<trampoline>", cs
->c_value
, mst_unknown
,
1330 (char *)NULL
, cs
->c_secnum
);
1333 /* record trampoline code entries as mst_unknown symbol. When we
1334 lookup mst symbols, we will choose mst_text over mst_unknown. */
1336 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_unknown
,
1343 default : /* all other XTY_XXXs */
1345 } /* switch CSECT_SMTYP() */ }
1347 switch (cs
->c_sclass
) {
1351 /* see if the last csect needs to be recorded. */
1353 if (last_csect_name
&& !misc_func_recorded
) {
1355 /* if no misc. function recorded in the last seen csect, enter
1356 it as a function. This will take care of functions like
1357 strcmp() compiled by xlc. */
1360 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1361 mst_text
, alloced
, last_csect_sec
);
1364 /* c_value field contains symnum of next .file entry in table
1365 or symnum of first global after last .file. */
1367 next_file_symnum
= cs
->c_value
;
1369 /* complete symbol table for last object file containing
1370 debugging information. */
1372 /* Whether or not there was a csect in the previous file, we have to call
1373 `end_stabs' and `start_stabs' to reset type_vector,
1374 line_vector, etc. structures. */
1376 complete_symtab (filestring
, file_start_addr
);
1377 cur_src_end_addr
= file_end_addr
;
1378 end_symtab (file_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1381 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
1382 last_csect_name
= 0;
1384 /* reset file start and end addresses. A compilation unit with no text
1385 (only data) should have zero file boundaries. */
1386 file_start_addr
= file_end_addr
= 0;
1388 filestring
= cs
->c_name
;
1393 fcn_stab_saved
= *cs
;
1398 if (STREQ (cs
->c_name
, ".bf")) {
1400 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1403 within_function
= 1;
1405 mark_first_line (fcn_line_offset
, cs
->c_symnum
);
1407 new = push_context (0, fcn_start_addr
);
1409 new->name
= define_symbol
1410 (fcn_cs_saved
.c_value
, fcn_stab_saved
.c_name
, 0, 0, objfile
);
1411 if (new->name
!= NULL
)
1412 SYMBOL_SECTION (new->name
) = cs
->c_secnum
;
1414 else if (STREQ (cs
->c_name
, ".ef")) {
1416 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1419 /* the value of .ef is the address of epilogue code;
1420 not useful for gdb */
1421 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1422 contains number of lines to '}' */
1424 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1425 new = pop_context ();
1426 if (context_stack_depth
!= 0)
1427 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1430 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1432 fcn_cs_saved
.c_value
+
1433 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
1434 within_function
= 0;
1438 case C_BSTAT
: /* begin static block */
1440 struct internal_syment symbol
;
1442 read_symbol (&symbol
, cs
->c_value
);
1443 static_block_base
= symbol
.n_value
;
1444 static_block_section
= symbol
.n_scnum
;
1448 case C_ESTAT
: /* end of static block */
1449 static_block_base
= 0;
1450 static_block_section
= -1;
1453 case C_ARG
: /* These are not implemented. */
1459 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
1462 case C_HIDEXT
: /* ignore these.. */
1467 case C_BINCL
: /* beginning of include file */
1469 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1470 order. Thus, when wee see them, we might not know enough info
1471 to process them. Thus, we'll be saving them into a table
1472 (inclTable) and postpone their processing. */
1474 record_include_begin (cs
);
1477 case C_EINCL
: /* end of include file */
1478 /* see the comment after case C_BINCL. */
1479 record_include_end (cs
);
1483 if (STREQ (cs
->c_name
, ".bb")) {
1485 new = push_context (depth
, cs
->c_value
);
1487 else if (STREQ (cs
->c_name
, ".eb")) {
1488 new = pop_context ();
1489 if (depth
!= new->depth
)
1490 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1494 if (local_symbols
&& context_stack_depth
> 0) {
1495 /* Make a block for the local symbols within. */
1496 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1497 new->start_addr
, cs
->c_value
, objfile
);
1499 local_symbols
= new->locals
;
1504 process_xcoff_symbol (cs
, objfile
);
1510 if (last_source_file
)
1512 end_symtab (cur_src_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1517 current_objfile
= NULL
;
1519 /* Record the toc offset value of this symbol table into ldinfo structure.
1520 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1521 this information would be file auxiliary header. */
1523 #ifndef FAKING_RS6000
1524 xcoff_add_toc_to_loadinfo (toc_offset
);
1528 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1529 (SYMBOL2) = (struct symbol *) \
1530 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1531 *(SYMBOL2) = *(SYMBOL1);
1534 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1535 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1538 /* process one xcoff symbol. */
1540 static struct symbol
*
1541 process_xcoff_symbol (cs
, objfile
)
1542 register struct coff_symbol
*cs
;
1543 struct objfile
*objfile
;
1545 struct symbol onesymbol
;
1546 register struct symbol
*sym
= &onesymbol
;
1547 struct symbol
*sym2
= NULL
;
1549 char *name
, *pp
, *qq
;
1550 int struct_and_type_combined
;
1557 bzero (sym
, sizeof (struct symbol
));
1559 /* default assumptions */
1560 SYMBOL_VALUE (sym
) = cs
->c_value
;
1561 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1562 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1564 if (ISFCN (cs
->c_type
)) {
1566 /* At this point, we don't know the type of the function and assume it
1567 is int. This will be patched with the type from its stab entry later
1568 on in patch_block_stabs () */
1570 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1571 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (objfile
, FT_INTEGER
));
1573 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1574 SYMBOL_DUP (sym
, sym2
);
1576 if (cs
->c_sclass
== C_EXT
)
1577 add_symbol_to_list (sym2
, &global_symbols
);
1578 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1579 add_symbol_to_list (sym2
, &file_symbols
);
1584 /* in case we can't figure out the type, default is `int'. */
1585 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
1587 switch (cs
->c_sclass
)
1591 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1592 add_stab_to_list (name
, &global_stabs
);
1594 add_stab_to_list (name
, &file_stabs
);
1598 case C_DECL
: /* a type decleration?? */
1600 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1602 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1606 add_stab_to_list (name
, &global_stabs
);
1612 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1615 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1621 /* If we are going to use Sun dbx's define_symbol(), we need to
1622 massage our stab string a little. Change 'V' type to 'S' to be
1623 comparible with Sun. */
1624 /* FIXME: I believe this is to avoid a Sun-specific hack somewhere.
1625 Needs more investigation. */
1627 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
1631 if (*pp
== 'V') *pp
= 'S';
1632 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1635 SYMBOL_VALUE (sym
) += static_block_base
;
1636 SYMBOL_SECTION (sym
) = static_block_section
;
1641 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, N_LSYM
, objfile
);
1644 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1649 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1650 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1651 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1652 SYMBOL_DUP (sym
, sym2
);
1653 add_symbol_to_list (sym2
, &local_symbols
);
1657 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1658 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1659 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1660 SYMBOL_DUP (sym
, sym2
);
1661 add_symbol_to_list (sym2
, &global_symbols
);
1665 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1666 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1667 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1668 SYMBOL_DUP (sym
, sym2
);
1670 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1674 printf ("ERROR! C_REG is not fully implemented!\n");
1675 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1676 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1677 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1678 SYMBOL_DUP (sym
, sym2
);
1679 add_symbol_to_list (sym2
, &local_symbols
);
1683 pp
= (char*) strchr (name
, ':');
1685 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1687 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1691 complain (&rsym_complaint
, name
);
1696 complain (&storclass_complaint
, cs
->c_sclass
);
1703 /* Set *SYMBOL to symbol number symno in symtbl. */
1705 read_symbol (symbol
, symno
)
1706 struct internal_syment
*symbol
;
1709 if (symno
< 0 || symno
>= symtbl_num_syms
)
1711 static struct complaint msg
=
1712 {"Invalid symbol offset", 0, 0};
1714 symbol
->n_value
= 0;
1715 symbol
->n_scnum
= -1;
1718 bfd_coff_swap_sym_in (symfile_bfd
, symtbl
+ (symno
*local_symesz
), symbol
);
1721 /* Get value corresponding to symbol number symno in symtbl. */
1724 read_symbol_nvalue (symno
)
1727 struct internal_syment symbol
[1];
1729 read_symbol (symbol
, symno
);
1730 return symbol
->n_value
;
1734 /* Find the address of the function corresponding to symno, where
1735 symno is the symbol pointed to by the linetable. */
1738 read_symbol_lineno (symno
)
1741 struct internal_syment symbol
[1];
1742 union internal_auxent main_aux
[1];
1744 /* Note that just searching for a short distance (e.g. 50 symbols)
1745 is not enough, at least in the following case.
1748 [many .stabx entries]
1749 [a few functions, referring to foo]
1753 What happens here is that the assembler moves the .stabx entries
1754 to right before the ".bf" for foo, but the symbol for "foo" is before
1755 all the stabx entries. See PR gdb/2222. */
1756 while (symno
< symtbl_num_syms
) {
1757 bfd_coff_swap_sym_in (symfile_bfd
,
1758 symtbl
+ (symno
*local_symesz
), symbol
);
1759 if (symbol
->n_sclass
== C_FCN
&& STREQ (symbol
->n_name
, ".bf"))
1761 symno
+= symbol
->n_numaux
+1;
1764 complain (&bf_notfound_complaint
);
1768 /* take aux entry and return its lineno */
1770 bfd_coff_swap_aux_in (symfile_bfd
, symtbl
+(symno
*local_symesz
),
1771 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
1773 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1776 /* Support for line number handling */
1778 /* This function is called for every section; it finds the outer limits
1779 * of the line table (minimum and maximum file offset) so that the
1780 * mainline code can read the whole thing for efficiency.
1783 find_linenos(abfd
, asect
, vpinfo
)
1788 struct coff_symfile_info
*info
;
1790 file_ptr offset
, maxoff
;
1792 count
= asect
->lineno_count
;
1794 if (!STREQ (asect
->name
, ".text") || count
== 0)
1797 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1798 info
= (struct coff_symfile_info
*)vpinfo
;
1799 offset
= asect
->line_filepos
;
1800 maxoff
= offset
+ size
;
1802 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1803 info
->min_lineno_offset
= offset
;
1805 if (maxoff
> info
->max_lineno_offset
)
1806 info
->max_lineno_offset
= maxoff
;
1810 /* Read in all the line numbers for fast lookups later. Leave them in
1811 external (unswapped) format in memory; we'll swap them as we enter
1812 them into GDB's data structures. */
1815 init_lineno (abfd
, offset
, size
)
1822 if (bfd_seek(abfd
, offset
, L_SET
) < 0)
1825 linetab
= (char *) xmalloc(size
);
1827 val
= bfd_read(linetab
, 1, size
, abfd
);
1831 linetab_offset
= offset
;
1832 linetab_size
= size
;
1833 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1837 /* dbx allows the text of a symbol name to be continued into the
1838 next symbol name! When such a continuation is encountered
1839 (a \ at the end of the text of a name)
1840 call this function to get the continuation. */
1841 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1844 #undef next_symbol_text
1845 #define next_symbol_text() \
1846 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1850 xcoff_new_init (objfile
)
1851 struct objfile
*objfile
;
1856 /* xcoff_symfile_init()
1857 is the xcoff-specific initialization routine for reading symbols.
1858 It is passed an objfile which contains, among other things,
1859 the BFD for the file whose symbols are being read, and a slot for
1860 a pointer to "private data" which we fill with cookies and other
1861 treats for xcoff_symfile_read().
1863 We will only be called if this is an XCOFF or XCOFF-like file.
1864 BFD handles figuring out the format of the file, and code in symfile.c
1865 uses BFD's determination to vector to us.
1867 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
1870 xcoff_symfile_init (objfile
)
1871 struct objfile
*objfile
;
1873 bfd
*abfd
= objfile
->obfd
;
1875 /* Allocate struct to keep track of the symfile */
1876 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
1877 sizeof (struct coff_symfile_info
));
1878 init_entry_point_info (objfile
);
1881 /* Perform any local cleanups required when we are done with a particular
1882 objfile. I.E, we are in the process of discarding all symbol information
1883 for an objfile, freeing up all memory held for it, and unlinking the
1884 objfile struct from the global list of known objfiles. */
1887 xcoff_symfile_finish (objfile
)
1888 struct objfile
*objfile
;
1890 if (objfile
-> sym_private
!= NULL
)
1892 mfree (objfile
-> md
, objfile
-> sym_private
);
1895 /* Start with a fresh include table for the next objfile. */
1902 inclIndx
= inclLength
= inclDepth
= 0;
1907 init_stringtab(abfd
, offset
, objfile
)
1910 struct objfile
*objfile
;
1914 unsigned char lengthbuf
[4];
1916 if (bfd_seek(abfd
, offset
, L_SET
) < 0)
1919 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1920 length
= bfd_h_get_32(abfd
, lengthbuf
);
1922 /* If no string table is needed, then the file may end immediately
1923 after the symbols. Just return with `strtbl' set to null. */
1925 if (val
!= sizeof length
|| length
< sizeof length
)
1928 /* Allocate string table from symbol_obstack. We will need this table
1929 as long as we have its symbol table around. */
1931 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
1935 bcopy(&length
, strtbl
, sizeof length
);
1936 if (length
== sizeof length
)
1939 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
1941 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
1948 init_debugsection(abfd
)
1951 register sec_ptr secp
;
1952 bfd_size_type length
;
1959 secp
= bfd_get_section_by_name(abfd
, ".debug");
1963 if (!(length
= bfd_section_size(abfd
, secp
)))
1966 debugsec
= (char *) xmalloc ((unsigned)length
);
1967 if (debugsec
== NULL
)
1970 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
1971 printf ("Can't read .debug section from symbol file\n");
1986 /* xcoff version of symbol file read. */
1989 xcoff_symfile_read (objfile
, section_offset
, mainline
)
1990 struct objfile
*objfile
;
1991 struct section_offset
*section_offset
;
1994 int num_symbols
; /* # of symbols */
1995 file_ptr symtab_offset
; /* symbol table and */
1996 file_ptr stringtab_offset
; /* string table file offsets */
1999 struct coff_symfile_info
*info
;
2002 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2003 symfile_bfd
= abfd
= objfile
->obfd
;
2004 name
= objfile
->name
;
2006 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2007 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2008 stringtab_offset
= symtab_offset
+
2009 num_symbols
* coff_data(abfd
)->local_symesz
;
2011 info
->min_lineno_offset
= 0;
2012 info
->max_lineno_offset
= 0;
2013 bfd_map_over_sections (abfd
, find_linenos
, info
);
2015 /* FIXME! This stuff should move into symfile_init */
2016 if (info
->min_lineno_offset
!= 0
2017 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
2019 /* only read in the line # table if one exists */
2020 val
= init_lineno(abfd
, info
->min_lineno_offset
,
2021 (int) (info
->max_lineno_offset
- info
->min_lineno_offset
));
2024 error("\"%s\": error reading line numbers\n", name
);
2027 if (num_symbols
> 0)
2029 val
= init_stringtab(abfd
, stringtab_offset
, objfile
);
2031 error ("\"%s\": can't get string table", name
);
2034 if (init_debugsection(abfd
) < 0) {
2035 error ("Error reading .debug section of `%s'\n", name
);
2039 /* Position to read the symbol table. Do not read it all at once. */
2040 val
= bfd_seek(abfd
, symtab_offset
, L_SET
);
2042 perror_with_name(name
);
2044 if (bfd_tell(abfd
) != symtab_offset
)
2047 init_minimal_symbol_collection ();
2048 make_cleanup (discard_minimal_symbols
, 0);
2050 #ifndef FAKING_RS6000
2051 /* Initialize load info structure. */
2053 xcoff_init_loadinfo ();
2056 /* Now that the executable file is positioned at symbol table,
2057 process it and define symbols accordingly. */
2059 read_xcoff_symtab(objfile
, num_symbols
);
2061 /* Free debug section. */
2062 free_debugsection ();
2064 /* Sort symbols alphabetically within each block. */
2065 sort_all_symtab_syms ();
2067 /* Install any minimal symbols that have been collected as the current
2068 minimal symbols for this objfile. */
2070 install_minimal_symbols (objfile
);
2073 /* XCOFF-specific parsing routine for section offsets. */
2075 static int largest_section
;
2078 note_one_section (abfd
, asect
, ptr
)
2083 if (asect
->target_index
> largest_section
)
2084 largest_section
= asect
->target_index
;
2088 struct section_offsets
*
2089 xcoff_symfile_offsets (objfile
, addr
)
2090 struct objfile
*objfile
;
2093 struct section_offsets
*section_offsets
;
2096 largest_section
= 0;
2097 bfd_map_over_sections (objfile
->obfd
, note_one_section
, NULL
);
2098 objfile
->num_sections
= largest_section
+ 1;
2099 section_offsets
= (struct section_offsets
*)
2101 (&objfile
-> psymbol_obstack
,
2102 sizeof (struct section_offsets
)
2103 + sizeof (section_offsets
->offsets
) * (objfile
->num_sections
));
2105 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2106 of the .text section. This strikes me as wrong--whether the
2107 offset to be applied to symbol reading is relative to the start
2108 address of the section depends on the symbol format. In any
2109 event, this whole "addr" concept is pretty broken (it doesn't
2110 handle any section but .text sensibly), so just ignore the addr
2111 parameter and use 0. That matches the fact that xcoff_symfile_read
2112 ignores the section_offsets). */
2113 for (i
= 0; i
< objfile
->num_sections
; i
++)
2114 ANOFFSET (section_offsets
, i
) = 0;
2116 return section_offsets
;
2118 /* Register our ability to parse symbols for xcoff BFD files. */
2120 static struct sym_fns xcoff_sym_fns
=
2122 "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */
2123 15, /* sym_namelen: number of significant sym_name chars */
2124 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2125 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2126 xcoff_symfile_read
, /* sym_read: read a symbol file into symtab */
2127 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2128 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2129 NULL
/* next: pointer to next struct sym_fns */
2133 _initialize_xcoffread ()
2135 add_symtab_fns(&xcoff_sym_fns
);
2137 /* Initialize symbol template later used for arguments. */
2138 SYMBOL_NAME (&parmsym
) = "";
2139 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym
, language_c
);
2140 SYMBOL_NAMESPACE (&parmsym
) = VAR_NAMESPACE
;
2141 SYMBOL_CLASS (&parmsym
) = LOC_ARG
;
2142 /* Its other fields are zero, or are filled in later. */