1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
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>
44 #include "coff/internal.h" /* FIXME, internal data from BFD */
45 #include "libcoff.h" /* FIXME, internal data from BFD */
46 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
53 #include "stabsread.h"
54 #include "complaints.h"
56 /* For interface with stabsread.c. */
57 #include "aout/stab_gnu.h"
59 /* Simplified internal version of coff symbol table information */
63 int c_symnum
; /* symbol number of this entry */
64 int c_naux
; /* 0 if syment only, 1 if syment + auxent */
66 unsigned char c_sclass
;
71 /* The COFF line table, in raw form. */
72 static char *linetab
= NULL
; /* Its actual contents */
73 static long linetab_offset
; /* Its offset in the file */
74 static unsigned long linetab_size
; /* Its size */
76 /* last function's saved coff symbol `cs' */
78 static struct coff_symbol fcn_cs_saved
;
80 static bfd
*symfile_bfd
;
82 /* Core address of start and end of text of current source file.
83 This is calculated from the first function seen after a C_FILE
87 static CORE_ADDR cur_src_end_addr
;
89 /* Core address of the end of the first object file. */
91 static CORE_ADDR first_object_file_end
;
93 /* pointer to the string table */
96 /* length of the string table */
97 static int strtbl_len
;
99 /* pointer to debug section */
100 static char *debugsec
;
102 /* pointer to the a.out symbol table */
105 /* Number of symbols in symtbl. */
106 static int symtbl_num_syms
;
108 /* initial symbol-table-debug-string vector length */
110 #define INITIAL_STABVECTOR_LENGTH 40
112 /* Nonzero if within a function (so symbols should be local,
113 if nothing says specifically). */
117 /* Local variables that hold the shift and mask values for the
118 COFF file that we are currently reading. These come back to us
119 from BFD, and are referenced by their macro names, as well as
120 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
121 macros from ../internalcoff.h . */
123 static unsigned local_n_btshft
;
124 static unsigned local_n_tmask
;
127 #define N_BTSHFT local_n_btshft
129 #define N_TMASK local_n_tmask
131 /* Local variables that hold the sizes in the file of various COFF structures.
132 (We only need to know this to read them from the file -- BFD will then
133 translate the data in them, into `internal_xxx' structs in the right
134 byte order, alignment, etc.) */
136 static unsigned local_symesz
;
138 struct coff_symfile_info
{
139 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
140 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
143 static struct complaint rsym_complaint
=
144 {"Non-stab C_RSYM `%s' needs special handling", 0, 0};
146 static struct complaint storclass_complaint
=
147 {"Unexpected storage class: %d", 0, 0};
149 static struct complaint bf_notfound_complaint
=
150 {"line numbers off, `.bf' symbol not found", 0, 0};
153 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
154 CORE_ADDR
, CORE_ADDR
, unsigned *));
157 free_debugsection
PARAMS ((void));
160 init_debugsection
PARAMS ((bfd
*));
163 init_stringtab
PARAMS ((bfd
*, file_ptr
, struct objfile
*));
166 xcoff_symfile_init
PARAMS ((struct objfile
*));
169 xcoff_new_init
PARAMS ((struct objfile
*));
172 xcoff_symfile_read
PARAMS ((struct objfile
*, struct section_offsets
*, int));
175 xcoff_symfile_finish
PARAMS ((struct objfile
*));
177 static struct section_offsets
*
178 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
181 init_lineno
PARAMS ((bfd
*, file_ptr
, int));
184 free_linetab
PARAMS ((void));
187 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
190 read_symbol
PARAMS ((struct internal_syment
*, int));
193 read_symbol_lineno
PARAMS ((int));
196 read_symbol_nvalue
PARAMS ((int));
198 static struct symbol
*
199 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
202 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
205 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
207 /* add a given stab string into given stab vector. */
210 add_stab_to_list (stabname
, stabvector
)
212 struct pending_stabs
**stabvector
;
214 if ( *stabvector
== NULL
) {
215 *stabvector
= (struct pending_stabs
*)
216 xmalloc (sizeof (struct pending_stabs
) +
217 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
218 (*stabvector
)->count
= 0;
219 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
221 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
222 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
223 *stabvector
= (struct pending_stabs
*)
224 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
225 (*stabvector
)->length
* sizeof (char*));
227 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
230 /* Linenos are processed on a file-by-file basis.
234 1) xlc (IBM's native c compiler) postpones static function code
235 emission to the end of a compilation unit. This way it can
236 determine if those functions (statics) are needed or not, and
237 can do some garbage collection (I think). This makes line
238 numbers and corresponding addresses unordered, and we end up
239 with a line table like:
256 and that breaks gdb's binary search on line numbers, if the
257 above table is not sorted on line numbers. And that sort
258 should be on function based, since gcc can emit line numbers
261 10 0x100 - for the init/test part of a for stmt.
264 10 0x400 - for the increment part of a for stmt.
266 arrange_linetable() will do this sorting.
268 2) aix symbol table might look like:
270 c_file // beginning of a new file
271 .bi // beginning of include file
272 .ei // end of include file
276 basically, .bi/.ei pairs do not necessarily encapsulate
277 their scope. They need to be recorded, and processed later
278 on when we come the end of the compilation unit.
279 Include table (inclTable) and process_linenos() handle
282 /* compare line table entry addresses. */
285 compare_lte (lte1
, lte2
)
286 struct linetable_entry
*lte1
, *lte2
;
288 return lte1
->pc
- lte2
->pc
;
291 /* Give a line table with function entries are marked, arrange its functions
292 in assending order and strip off function entry markers and return it in
293 a newly created table. If the old one is good enough, return the old one. */
294 /* FIXME: I think all this stuff can be replaced by just passing
295 sort_linevec = 1 to end_symtab. */
297 static struct linetable
*
298 arrange_linetable (oldLineTb
)
299 struct linetable
*oldLineTb
; /* old linetable */
302 newline
, /* new line count */
303 function_count
; /* # of functions */
305 struct linetable_entry
*fentry
; /* function entry vector */
306 int fentry_size
; /* # of function entries */
307 struct linetable
*newLineTb
; /* new line table */
309 #define NUM_OF_FUNCTIONS 20
311 fentry_size
= NUM_OF_FUNCTIONS
;
312 fentry
= (struct linetable_entry
*)
313 xmalloc (fentry_size
* sizeof (struct linetable_entry
));
315 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
317 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
319 if (function_count
>= fentry_size
) { /* make sure you have room. */
321 fentry
= (struct linetable_entry
*)
322 xrealloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
324 fentry
[function_count
].line
= ii
;
325 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
330 if (function_count
== 0) {
334 else if (function_count
> 1)
335 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
337 /* allocate a new line table. */
338 newLineTb
= (struct linetable
*)
340 (sizeof (struct linetable
) +
341 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
343 /* if line table does not start with a function beginning, copy up until
347 if (oldLineTb
->item
[0].line
!= 0)
349 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
350 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
352 /* Now copy function lines one by one. */
354 for (ii
=0; ii
< function_count
; ++ii
) {
355 for (jj
= fentry
[ii
].line
+ 1;
356 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
358 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
361 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
367 /* We try to detect the beginning of a compilation unit. That info will
368 be used as an entry in line number recording routines (enter_line_range) */
370 static unsigned first_fun_line_offset
;
371 static unsigned first_fun_bf
;
373 #define mark_first_line(OFFSET, SYMNUM) \
374 if (!first_fun_line_offset) { \
375 first_fun_line_offset = OFFSET; \
376 first_fun_bf = SYMNUM; \
380 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
381 following `IncludeChain'. At the end of each symtab (end_symtab),
382 we will determine if we should create additional symtab's to
383 represent if (the include files. */
386 typedef struct _inclTable
{
387 char *name
; /* include filename */
389 /* Offsets to the line table. end points to the last entry which is
390 part of this include file. */
393 struct subfile
*subfile
;
394 unsigned funStartLine
; /* start line # of its function */
397 #define INITIAL_INCLUDE_TABLE_LENGTH 20
398 static InclTable
*inclTable
; /* global include table */
399 static int inclIndx
; /* last entry to table */
400 static int inclLength
; /* table length */
401 static int inclDepth
; /* nested include depth */
403 static void allocate_include_entry
PARAMS ((void));
406 record_include_begin (cs
)
407 struct coff_symbol
*cs
;
411 /* In xcoff, we assume include files cannot be nested (not in .c files
412 of course, but in corresponding .s files.). */
414 /* This can happen with old versions of GCC.
415 GCC 2.3.3-930426 does not exhibit this on a test case which
416 a user said produced the message for him. */
417 static struct complaint msg
= {"Nested C_BINCL symbols", 0, 0};
422 allocate_include_entry ();
424 inclTable
[inclIndx
].name
= cs
->c_name
;
425 inclTable
[inclIndx
].begin
= cs
->c_value
;
429 record_include_end (cs
)
430 struct coff_symbol
*cs
;
436 static struct complaint msg
= {"Mismatched C_BINCL/C_EINCL pair", 0, 0};
440 allocate_include_entry ();
442 pTbl
= &inclTable
[inclIndx
];
443 pTbl
->end
= cs
->c_value
;
450 allocate_include_entry ()
452 if (inclTable
== NULL
)
454 inclTable
= (InclTable
*)
455 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
457 '\0', sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
458 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
461 else if (inclIndx
>= inclLength
)
463 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
464 inclTable
= (InclTable
*)
465 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
466 memset (inclTable
+ inclLength
- INITIAL_INCLUDE_TABLE_LENGTH
,
467 '\0', sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
471 /* given the start and end addresses of a compilation unit (or a csect,
472 at times) process its lines and create appropriate line vectors. */
475 process_linenos (start
, end
)
476 CORE_ADDR start
, end
;
481 struct subfile main_subfile
; /* subfile structure for the main
484 /* in the main source file, any time we see a function entry, we reset
485 this variable to function's absolute starting line number. All the
486 following line numbers in the function are relative to this, and
487 we record absolute line numbers in record_line(). */
489 int main_source_baseline
= 0;
495 if (!(offset
= first_fun_line_offset
))
496 goto return_after_cleanup
;
498 memset (&main_subfile
, '\0', sizeof (main_subfile
));
499 first_fun_line_offset
= 0;
502 /* All source lines were in the main source file. None in include files. */
504 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
505 &main_source_baseline
);
507 /* else, there was source with line numbers in include files */
510 main_source_baseline
= 0;
511 for (ii
=0; ii
< inclIndx
; ++ii
) {
513 struct subfile
*tmpSubfile
;
515 /* if there is main file source before include file, enter it. */
516 if (offset
< inclTable
[ii
].begin
) {
518 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
, start
, 0,
519 &main_source_baseline
);
522 /* Have a new subfile for the include file */
524 tmpSubfile
= inclTable
[ii
].subfile
= (struct subfile
*)
525 xmalloc (sizeof (struct subfile
));
527 memset (tmpSubfile
, '\0', sizeof (struct subfile
));
528 firstLine
= &(inclTable
[ii
].funStartLine
);
530 /* enter include file's lines now. */
531 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
532 inclTable
[ii
].end
, start
, 0, firstLine
);
534 offset
= inclTable
[ii
].end
+ LINESZ
;
537 /* all the include files' line have been processed at this point. Now,
538 enter remaining lines of the main file, if any left. */
539 if (offset
< (linetab_offset
+ linetab_size
+ 1 - LINESZ
)) {
540 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
541 &main_source_baseline
);
545 /* Process main file's line numbers. */
546 if (main_subfile
.line_vector
) {
547 struct linetable
*lineTb
, *lv
;
549 lv
= main_subfile
.line_vector
;
551 /* Line numbers are not necessarily ordered. xlc compilation will
552 put static function to the end. */
554 lineTb
= arrange_linetable (lv
);
556 current_subfile
->line_vector
= (struct linetable
*)
557 xrealloc (lv
, (sizeof (struct linetable
)
558 + lv
->nitems
* sizeof (struct linetable_entry
)));
563 current_subfile
->line_vector
= lineTb
;
566 current_subfile
->line_vector_length
=
567 current_subfile
->line_vector
->nitems
;
570 /* Now, process included files' line numbers. */
572 for (ii
=0; ii
< inclIndx
; ++ii
) {
574 if ( (inclTable
[ii
].subfile
)->line_vector
) { /* Useless if!!! FIXMEmgo */
575 struct linetable
*lineTb
, *lv
;
577 lv
= (inclTable
[ii
].subfile
)->line_vector
;
579 /* Line numbers are not necessarily ordered. xlc compilation will
580 put static function to the end. */
582 lineTb
= arrange_linetable (lv
);
586 /* For the same include file, we might want to have more than one subfile.
587 This happens if we have something like:
595 while foo.h including code in it. (stupid but possible)
596 Since start_subfile() looks at the name and uses an existing one if finds,
597 we need to provide a fake name and fool it. */
599 /* start_subfile (inclTable[ii].name, (char*)0); */
600 start_subfile (" ?", (char*)0);
601 free (current_subfile
->name
);
602 current_subfile
->name
= strdup (inclTable
[ii
].name
);
605 current_subfile
->line_vector
= (struct linetable
*)
606 xrealloc (lv
, (sizeof (struct linetable
)
607 + lv
->nitems
* sizeof (struct linetable_entry
)));
612 current_subfile
->line_vector
= lineTb
;
615 current_subfile
->line_vector_length
=
616 current_subfile
->line_vector
->nitems
;
617 start_subfile (pop_subfile (), (char*)0);
621 return_after_cleanup
:
623 /* We don't want to keep alloc/free'ing the global include file table. */
626 /* start with a fresh subfile structure for the next file. */
627 memset (&main_subfile
, '\0', sizeof (struct subfile
));
631 aix_process_linenos ()
633 /* process line numbers and enter them into line vector */
634 process_linenos (last_source_start_addr
, cur_src_end_addr
);
638 /* Enter a given range of lines into the line vector.
639 can be called in the following two ways:
640 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
641 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine)
643 endoffset points to the last line table entry that we should pay
647 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
, firstLine
)
648 struct subfile
*subfile
;
649 unsigned beginoffset
, endoffset
; /* offsets to line table */
650 CORE_ADDR startaddr
, endaddr
;
656 /* Do Byte swapping, if needed. FIXME! */
657 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
658 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
659 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
661 pp
= &linetab
[beginoffset
- linetab_offset
];
662 if (endoffset
!= 0 && endoffset
- linetab_offset
>= linetab_size
)
664 static struct complaint msg
=
665 {"Bad line table offset in C_EINCL directive", 0, 0};
669 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
670 : &linetab
[linetab_size
-1];
672 while (pp
<= limit
) {
674 /* find the address this line represents */
675 addr
= P_LINENO(pp
) ?
676 P_LINEADDR(pp
) : read_symbol_nvalue (P_LINESYM(pp
));
678 if (addr
< startaddr
|| (endaddr
&& addr
>= endaddr
))
681 if (P_LINENO(pp
) == 0) {
682 *firstLine
= read_symbol_lineno (P_LINESYM(pp
));
683 record_line (subfile
, 0, addr
);
687 record_line (subfile
, *firstLine
+ P_LINENO(pp
), addr
);
694 int fsize
; /* file size */
695 int fixedparms
; /* number of fixed parms */
696 int floatparms
; /* number of float parms */
697 unsigned int parminfo
; /* parameter info.
698 See /usr/include/sys/debug.h
699 tbtable_ext.parminfo */
700 int framesize
; /* function frame size */
704 /* Given a function symbol, return its traceback information. */
707 retrieve_tracebackinfo (abfd
, textsec
, cs
)
710 struct coff_symbol
*cs
;
712 #define TBTABLE_BUFSIZ 2000
714 static TracebackInfo tbInfo
;
717 static char buffer
[TBTABLE_BUFSIZ
];
720 int bytesread
=0; /* total # of bytes read so far */
721 int bufferbytes
; /* number of bytes in the buffer */
723 int functionstart
= cs
->c_value
- textsec
->vma
;
725 memset (&tbInfo
, '\0', sizeof (tbInfo
));
727 /* keep reading blocks of data from the text section, until finding a zero
728 word and a traceback table. */
730 /* Note: The logical thing way to write this code would be to assign
731 to bufferbytes within the while condition. But that triggers a
732 compiler (xlc in AIX 3.2) bug, so simplify it... */
734 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
735 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
737 && (bfd_get_section_contents
738 (abfd
, textsec
, buffer
,
739 (file_ptr
)(functionstart
+ bytesread
), bufferbytes
)))
741 bytesread
+= bufferbytes
;
742 pinsn
= (int*) buffer
;
744 /* if this is the first time we filled the buffer, retrieve function
747 if (bytesread
== bufferbytes
) {
749 /* skip over unrelated instructions */
751 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
753 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
755 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
757 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
761 int tmp
= (*pinsn
>> 16) & 0xffff;
763 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
764 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
767 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
768 (tmp
== 0x9001)) /* st r0, NUM(r1) */
770 /* else, could not find a frame size. */
774 } while (++pinsn
&& *pinsn
);
776 if (!tbInfo
.framesize
)
781 /* look for a zero word. */
783 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
786 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
791 /* function size is the amount of bytes we have skipped so far. */
792 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
796 /* if we don't have the whole traceback table in the buffer, re-read
799 /* This is how much to read to get the traceback table.
800 8 bytes of the traceback table are always present, plus we
802 #define MIN_TBTABSIZ 12
804 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
806 /* In case if we are *very* close to the end of the text section
807 and cannot read properly from that point on, abort by returning
810 This could happen if the traceback table is only 8 bytes,
811 but we try to read 12 bytes of it.
812 Handle this case more graciously -- FIXME */
814 if (!bfd_get_section_contents (
815 abfd
, textsec
, buffer
,
816 (file_ptr
)(functionstart
+
817 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
818 { printf_unfiltered ("Abnormal return!..\n"); return NULL
; }
820 ptb
= (struct tbtable
*)buffer
;
823 ptb
= (struct tbtable
*)pinsn
;
825 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
826 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
827 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
831 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
) ?
832 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
));
838 /* Given a function symbol, return a pointer to its traceback table. */
841 retrieve_traceback (abfd
, textsec
, cs
, size
)
844 struct coff_symbol
*cs
;
845 int *size
; /* return function size */
847 #define TBTABLE_BUFSIZ 2000
848 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
851 static char buffer
[TBTABLE_BUFSIZ
];
854 int bytesread
=0; /* total # of bytes read so far */
855 int bufferbytes
; /* number of bytes in the buffer */
857 int functionstart
= cs
->c_value
- textsec
->filepos
+ textsec
->vma
;
860 /* keep reading blocks of data from the text section, until finding a zero
861 word and a traceback table. */
863 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
864 (file_ptr
)(functionstart
+ bytesread
),
866 (TBTABLE_BUFSIZ
< (textsec
->size
- functionstart
- bytesread
)) ?
867 TBTABLE_BUFSIZ
: (textsec
->size
- functionstart
- bytesread
))))
869 bytesread
+= bufferbytes
;
870 pinsn
= (int*) buffer
;
872 /* look for a zero word. */
874 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
877 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
882 /* function size is the amount of bytes we have skipped so far. */
883 *size
= bytesread
- (buffer
+ bufferbytes
- pinsn
);
887 /* if we don't have the whole traceback table in the buffer, re-read
890 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
892 /* In case if we are *very* close to the end of the text section
893 and cannot read properly from that point on, abort for now.
894 Handle this case more graciously -- FIXME */
896 if (!bfd_get_section_contents (
897 abfd
, textsec
, buffer
,
898 (file_ptr
)(functionstart
+
899 bytesread
- (buffer
+ bufferbytes
- pinsn
)),MIN_TBTABSIZ
))
900 /* abort (); */ { printf_unfiltered ("abort!!!\n"); return NULL
; }
902 return (struct tbtable
*)buffer
;
905 return (struct tbtable
*)pinsn
;
915 /* Save the vital information for use when closing off the current file.
916 NAME is the file name the symbols came from, START_ADDR is the first
917 text address for the file, and SIZE is the number of bytes of text. */
919 #define complete_symtab(name, start_addr) { \
920 last_source_file = savestring (name, strlen (name)); \
921 last_source_start_addr = start_addr; \
925 /* Refill the symbol table input buffer
926 and set the variables that control fetching entries from it.
927 Reports an error if no data available.
928 This function can read past the end of the symbol table
929 (into the string table) but this does no harm. */
931 /* Reading symbol table has to be fast! Keep the followings as macros, rather
934 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED, SECTION, OBJFILE) \
938 namestr = (NAME) + 1; \
941 obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
944 prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \
945 (char *)NULL, (SECTION), (OBJFILE)); \
946 misc_func_recorded = 1; \
950 /* A parameter template, used by ADD_PARM_TO_PENDING. It is initialized
951 in our initializer function at the bottom of the file, to avoid
952 dependencies on the exact "struct symbol" format. */
954 static struct symbol parmsym
;
956 /* Add a parameter to a given pending symbol list. */
958 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
960 PARM = (struct symbol *) \
961 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
963 SYMBOL_TYPE (PARM) = PTYPE; \
964 SYMBOL_VALUE (PARM) = VALUE; \
965 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
969 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
970 nested. At any given time, a symbol can only be in one static block.
971 This is the base address of current static block, zero if non exists. */
973 static int static_block_base
= 0;
975 /* Section number for the current static block. */
977 static int static_block_section
= -1;
979 /* true if space for symbol name has been allocated. */
981 static int symname_alloced
= 0;
983 /* Next symbol to read. Pointer into raw seething symbol table. */
985 static char *raw_symbol
;
987 /* This is the function which stabsread.c calls to get symbol
990 xcoff_next_symbol_text ()
992 struct internal_syment symbol
;
993 static struct complaint msg
=
994 {"Unexpected symbol continuation", 0, 0};
997 bfd_coff_swap_sym_in (current_objfile
->obfd
, raw_symbol
, &symbol
);
1002 /* Return something which points to '\0' and hope the symbol reading
1003 code does something reasonable. */
1006 else if (symbol
.n_sclass
& 0x80)
1008 retval
= debugsec
+ symbol
.n_offset
;
1009 raw_symbol
+= coff_data (current_objfile
->obfd
)->local_symesz
;
1016 /* Return something which points to '\0' and hope the symbol reading
1017 code does something reasonable. */
1023 /* read the whole symbol table of a given bfd. */
1026 read_xcoff_symtab (objfile
, nsyms
)
1027 struct objfile
*objfile
; /* Object file we're reading from */
1028 int nsyms
; /* # of symbols */
1030 bfd
*abfd
= objfile
->obfd
;
1031 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
1032 sec_ptr textsec
; /* Pointer to text section */
1033 TracebackInfo
*ptb
; /* Pointer to traceback table */
1035 struct internal_syment symbol
[1];
1036 union internal_auxent main_aux
;
1037 struct coff_symbol cs
[1];
1038 CORE_ADDR file_start_addr
= 0;
1039 CORE_ADDR file_end_addr
= 0;
1041 int next_file_symnum
= -1;
1042 int just_started
= 1;
1044 int toc_offset
= 0; /* toc offset value in data section. */
1048 long fcn_line_offset
;
1051 struct coff_symbol fcn_stab_saved
;
1053 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1054 union internal_auxent fcn_aux_saved
;
1055 struct type
*fcn_type_saved
= NULL
;
1056 struct context_stack
*new;
1058 char *filestring
= " _start_ "; /* Name of the current file. */
1060 char *last_csect_name
; /* last seen csect's name and value */
1061 CORE_ADDR last_csect_val
;
1063 int misc_func_recorded
; /* true if any misc. function */
1065 current_objfile
= objfile
;
1067 /* Get the appropriate COFF "constants" related to the file we're handling. */
1068 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
1069 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
1070 local_symesz
= coff_data (abfd
)->local_symesz
;
1072 last_source_file
= NULL
;
1073 last_csect_name
= 0;
1075 misc_func_recorded
= 0;
1078 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1080 first_object_file_end
= 0;
1082 /* Allocate space for the entire symbol table at once, and read it
1083 all in. The bfd is already positioned at the beginning of
1084 the symbol table. */
1086 size
= coff_data (abfd
)->local_symesz
* nsyms
;
1087 symtbl
= xmalloc (size
);
1088 symtbl_num_syms
= nsyms
;
1090 val
= bfd_read (symtbl
, size
, 1, abfd
);
1092 perror_with_name ("reading symbol table");
1094 raw_symbol
= symtbl
;
1096 textsec
= bfd_get_section_by_name (abfd
, ".text");
1098 printf_unfiltered ("Unable to locate text section!\n");
1101 next_symbol_text_func
= xcoff_next_symbol_text
;
1103 while (symnum
< nsyms
) {
1105 QUIT
; /* make this command interruptable. */
1107 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1108 /* read one symbol into `cs' structure. After processing the whole symbol
1109 table, only string table will be kept in memory, symbol table and debug
1110 section of xcoff will be freed. Thus we can mark symbols with names
1111 in string table as `alloced'. */
1115 /* Swap and align the symbol into a reasonable C structure. */
1116 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1118 cs
->c_symnum
= symnum
;
1119 cs
->c_naux
= symbol
->n_numaux
;
1120 if (symbol
->n_zeroes
) {
1121 symname_alloced
= 0;
1122 /* We must use the original, unswapped, name here so the name field
1123 pointed to by cs->c_name will persist throughout xcoffread. If
1124 we use the new field, it gets overwritten for each symbol. */
1125 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1126 /* If it's exactly E_SYMNMLEN characters long it isn't
1128 if (cs
->c_name
[E_SYMNMLEN
- 1] != '\0')
1131 p
= obstack_alloc (&objfile
->symbol_obstack
, E_SYMNMLEN
+ 1);
1132 strncpy (p
, cs
->c_name
, E_SYMNMLEN
);
1133 p
[E_SYMNMLEN
] = '\0';
1135 symname_alloced
= 1;
1137 } else if (symbol
->n_sclass
& 0x80) {
1138 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1139 symname_alloced
= 0;
1140 } else { /* in string table */
1141 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1142 symname_alloced
= 1;
1144 cs
->c_value
= symbol
->n_value
;
1145 cs
->c_sclass
= symbol
->n_sclass
;
1146 cs
->c_secnum
= symbol
->n_scnum
;
1147 cs
->c_type
= (unsigned)symbol
->n_type
;
1149 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1152 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
1154 /* Skip all the auxents associated with this symbol. */
1155 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
1156 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1161 /* if symbol name starts with ".$" or "$", ignore it. */
1162 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1165 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
1166 if (last_source_file
)
1168 end_symtab (cur_src_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1173 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1174 cur_src_end_addr
= first_object_file_end
;
1175 /* done with all files, everything from here on is globals */
1178 /* if explicitly specified as a function, treat is as one. */
1179 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
1180 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1181 0, cs
->c_naux
, &main_aux
);
1182 goto function_entry_point
;
1185 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_naux
== 1)
1187 /* dealing with a symbol with a csect entry. */
1189 # define CSECT(PP) ((PP)->x_csect)
1190 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen.l)
1191 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1192 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1193 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1195 /* Convert the auxent to something we can access. */
1196 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1197 0, cs
->c_naux
, &main_aux
);
1199 switch (CSECT_SMTYP (&main_aux
)) {
1202 continue; /* ignore all external references. */
1204 case XTY_SD
: /* a section description. */
1206 switch (CSECT_SCLAS (&main_aux
)) {
1208 case XMC_PR
: /* a `.text' csect. */
1211 /* A program csect is seen. We have to allocate one
1212 symbol table for each program csect. Normally gdb
1213 prefers one symtab for each source file. In case
1214 of AIX, one source file might include more than one
1215 [PR] csect, and they don't have to be adjacent in
1216 terms of the space they occupy in memory. Thus, one
1217 single source file might get fragmented in the
1218 memory and gdb's file start and end address
1219 approach does not work! GCC (and I think xlc) seem
1220 to put all the code in the unnamed program csect. */
1222 if (last_csect_name
) {
1224 /* if no misc. function recorded in the last seen csect, enter
1225 it as a function. This will take care of functions like
1226 strcmp() compiled by xlc. */
1228 if (!misc_func_recorded
) {
1230 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1231 mst_text
, alloced
, last_csect_sec
,
1236 complete_symtab (filestring
, file_start_addr
);
1237 cur_src_end_addr
= file_end_addr
;
1238 end_symtab (file_end_addr
, 1, 0, objfile
,
1239 textsec
->target_index
);
1242 /* Give all csects for this source file the same
1244 start_symtab (filestring
, (char *)NULL
, (CORE_ADDR
)0);
1247 /* If this is the very first csect seen, basically `__start'. */
1249 first_object_file_end
= cs
->c_value
+ CSECT_LEN (&main_aux
);
1253 file_start_addr
= cs
->c_value
;
1254 file_end_addr
= cs
->c_value
+ CSECT_LEN (&main_aux
);
1256 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
1257 last_csect_name
= cs
->c_name
;
1258 last_csect_val
= cs
->c_value
;
1259 last_csect_sec
= cs
->c_secnum
;
1262 misc_func_recorded
= 0;
1268 /* If the section is not a data description, ignore it. Note that
1269 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1273 warning ("More than one xmc_tc0 symbol found.");
1274 toc_offset
= cs
->c_value
;
1277 case XMC_TC
: /* ignore toc entries */
1278 default : /* any other XMC_XXX */
1282 break; /* switch CSECT_SCLAS() */
1286 switch (CSECT_SCLAS (&main_aux
))
1289 /* a function entry point. */
1290 function_entry_point
:
1291 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1292 symname_alloced
, cs
->c_secnum
, objfile
);
1294 fcn_line_offset
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1295 fcn_start_addr
= cs
->c_value
;
1297 /* save the function header info, which will be used
1298 when `.bf' is seen. */
1300 fcn_aux_saved
= main_aux
;
1305 /* If function has two auxent, then debugging information is
1306 already available for it. Process traceback table for
1307 functions with only one auxent. */
1309 if (cs
->c_naux
== 1)
1310 ptb
= retrieve_tracebackinfo (abfd
, textsec
, cs
);
1312 else if (cs
->c_naux
!= 2)
1314 static struct complaint msg
=
1315 {"Expected one or two auxents for function", 0, 0};
1319 /* If there is traceback info, create and add parameters for it. */
1321 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
)) {
1323 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1324 char *parmcode
= (char*) &ptb
->parminfo
;
1325 int parmvalue
= ptb
->framesize
+ 0x18; /* sizeof(LINK AREA) == 0x18 */
1326 unsigned int ii
, mask
;
1328 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
) {
1329 struct symbol
*parm
;
1331 if (ptb
->parminfo
& mask
) { /* float or double */
1333 if (ptb
->parminfo
& mask
) { /* double parm */
1335 (parm
, parmvalue
, builtin_type_double
, local_symbols
);
1336 parmvalue
+= sizeof (double);
1338 else { /* float parm */
1340 (parm
, parmvalue
, builtin_type_float
, local_symbols
);
1341 parmvalue
+= sizeof (float);
1344 else { /* fixed parm, use (int*) for hex rep. */
1345 ADD_PARM_TO_PENDING (parm
, parmvalue
,
1346 lookup_pointer_type (builtin_type_int
),
1348 parmvalue
+= sizeof (int);
1353 /* Fake this as a function. Needed in process_xcoff_symbol() */
1356 finish_block(process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1357 pending_blocks
, cs
->c_value
,
1358 cs
->c_value
+ ptb
->fsize
, objfile
);
1363 /* shared library function trampoline code entry point. */
1365 /* record trampoline code entries as mst_solib_trampoline symbol.
1366 When we lookup mst symbols, we will choose mst_text over
1367 mst_solib_trampoline. */
1368 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
,
1369 mst_solib_trampoline
,
1370 symname_alloced
, cs
->c_secnum
, objfile
);
1374 /* The symbols often have the same names as debug symbols for
1375 functions, and confuse lookup_symbol. */
1379 /* xlc puts each variable in a separate csect, so we get
1380 an XTY_SD for each variable. But gcc puts several
1381 variables in a csect, so that each variable only gets
1382 an XTY_LD. We still need to record them. This will
1383 typically be XMC_RW; I suspect XMC_RO and XMC_BS might
1388 default : /* all other XTY_XXXs */
1390 } /* switch CSECT_SMTYP() */ }
1392 switch (cs
->c_sclass
) {
1396 /* see if the last csect needs to be recorded. */
1398 if (last_csect_name
&& !misc_func_recorded
) {
1400 /* if no misc. function recorded in the last seen csect, enter
1401 it as a function. This will take care of functions like
1402 strcmp() compiled by xlc. */
1405 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1406 mst_text
, alloced
, last_csect_sec
, objfile
);
1409 /* c_value field contains symnum of next .file entry in table
1410 or symnum of first global after last .file. */
1412 next_file_symnum
= cs
->c_value
;
1414 /* complete symbol table for last object file containing
1415 debugging information. */
1417 /* Whether or not there was a csect in the previous file, we have to call
1418 `end_stabs' and `start_stabs' to reset type_vector,
1419 line_vector, etc. structures. */
1421 complete_symtab (filestring
, file_start_addr
);
1422 cur_src_end_addr
= file_end_addr
;
1423 end_symtab (file_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1426 /* XCOFF, according to the AIX 3.2 documentation, puts the filename
1427 in cs->c_name. But xlc 1.3.0.2 has decided to do things the
1428 standard COFF way and put it in the auxent. We use the auxent if
1429 the symbol is ".file" and an auxent exists, otherwise use the symbol
1430 itself. Simple enough. */
1431 if (!strcmp (cs
->c_name
, ".file") && cs
->c_naux
> 0)
1433 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1434 0, cs
->c_naux
, &main_aux
);
1435 filestring
= coff_getfilename (&main_aux
);
1438 filestring
= cs
->c_name
;
1441 start_symtab (filestring
, (char *)NULL
, (CORE_ADDR
)0);
1442 last_csect_name
= 0;
1444 /* reset file start and end addresses. A compilation unit with no text
1445 (only data) should have zero file boundaries. */
1446 file_start_addr
= file_end_addr
= 0;
1451 fcn_stab_saved
= *cs
;
1456 if (STREQ (cs
->c_name
, ".bf")) {
1458 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1459 0, cs
->c_naux
, &main_aux
);
1461 within_function
= 1;
1463 mark_first_line (fcn_line_offset
, cs
->c_symnum
);
1465 new = push_context (0, fcn_start_addr
);
1467 new->name
= define_symbol
1468 (fcn_cs_saved
.c_value
, fcn_stab_saved
.c_name
, 0, 0, objfile
);
1469 if (new->name
!= NULL
)
1470 SYMBOL_SECTION (new->name
) = cs
->c_secnum
;
1472 else if (STREQ (cs
->c_name
, ".ef")) {
1474 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1475 0, cs
->c_naux
, &main_aux
);
1477 /* the value of .ef is the address of epilogue code;
1478 not useful for gdb */
1479 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1480 contains number of lines to '}' */
1482 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1483 new = pop_context ();
1484 if (context_stack_depth
!= 0)
1485 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1488 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1490 fcn_cs_saved
.c_value
+
1491 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
1492 within_function
= 0;
1496 case C_BSTAT
: /* begin static block */
1498 struct internal_syment symbol
;
1500 read_symbol (&symbol
, cs
->c_value
);
1501 static_block_base
= symbol
.n_value
;
1502 static_block_section
= symbol
.n_scnum
;
1506 case C_ESTAT
: /* end of static block */
1507 static_block_base
= 0;
1508 static_block_section
= -1;
1511 case C_ARG
: /* These are not implemented. */
1517 printf_unfiltered ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
1520 case C_HIDEXT
: /* ignore these.. */
1525 case C_BINCL
: /* beginning of include file */
1527 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1528 order. Thus, when wee see them, we might not know enough info
1529 to process them. Thus, we'll be saving them into a table
1530 (inclTable) and postpone their processing. */
1532 record_include_begin (cs
);
1535 case C_EINCL
: /* end of include file */
1536 /* see the comment after case C_BINCL. */
1537 record_include_end (cs
);
1541 if (STREQ (cs
->c_name
, ".bb")) {
1543 new = push_context (depth
, cs
->c_value
);
1545 else if (STREQ (cs
->c_name
, ".eb")) {
1546 new = pop_context ();
1547 if (depth
!= new->depth
)
1548 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1552 if (local_symbols
&& context_stack_depth
> 0) {
1553 /* Make a block for the local symbols within. */
1554 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1555 new->start_addr
, cs
->c_value
, objfile
);
1557 local_symbols
= new->locals
;
1562 process_xcoff_symbol (cs
, objfile
);
1568 if (last_source_file
)
1570 end_symtab (cur_src_end_addr
, 1, 0, objfile
, textsec
->target_index
);
1575 current_objfile
= NULL
;
1577 /* Record the toc offset value of this symbol table into ldinfo structure.
1578 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1579 this information would be file auxiliary header. */
1581 #ifndef FAKING_RS6000
1582 xcoff_add_toc_to_loadinfo (toc_offset
);
1586 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1587 (SYMBOL2) = (struct symbol *) \
1588 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1589 *(SYMBOL2) = *(SYMBOL1);
1592 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1593 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1596 /* process one xcoff symbol. */
1598 static struct symbol
*
1599 process_xcoff_symbol (cs
, objfile
)
1600 register struct coff_symbol
*cs
;
1601 struct objfile
*objfile
;
1603 struct symbol onesymbol
;
1604 register struct symbol
*sym
= &onesymbol
;
1605 struct symbol
*sym2
= NULL
;
1607 char *name
, *pp
, *qq
;
1608 int struct_and_type_combined
;
1615 memset (sym
, '\0', sizeof (struct symbol
));
1617 /* default assumptions */
1618 SYMBOL_VALUE (sym
) = cs
->c_value
;
1619 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1620 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1622 if (ISFCN (cs
->c_type
)) {
1624 /* At this point, we don't know the type of the function and assume it
1625 is int. This will be patched with the type from its stab entry later
1626 on in patch_block_stabs () */
1628 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1629 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (objfile
, FT_INTEGER
));
1631 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1632 SYMBOL_DUP (sym
, sym2
);
1634 if (cs
->c_sclass
== C_EXT
)
1635 add_symbol_to_list (sym2
, &global_symbols
);
1636 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1637 add_symbol_to_list (sym2
, &file_symbols
);
1642 /* in case we can't figure out the type, default is `int'. */
1643 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
1645 switch (cs
->c_sclass
)
1649 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1650 add_stab_to_list (name
, &global_stabs
);
1652 add_stab_to_list (name
, &file_stabs
);
1657 add_stab_to_list (name
, &global_stabs
);
1661 common_block_start (cs
->c_name
, objfile
);
1665 common_block_end (objfile
);
1669 complain (&storclass_complaint
, cs
->c_sclass
);
1677 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1680 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1686 /* For xlc (not GCC), the 'V' symbol descriptor is used for all
1687 statics and we need to distinguish file-scope versus function-scope
1688 using within_function. We do this by changing the string we pass
1689 to define_symbol to use 'S' where we need to, which is not necessarily
1690 super-clean, but seems workable enough. */
1692 if (*name
== ':' || (pp
= (char *) strchr(name
, ':')) == NULL
)
1696 if (*pp
== 'V' && !within_function
)
1698 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1701 SYMBOL_VALUE (sym
) += static_block_base
;
1702 SYMBOL_SECTION (sym
) = static_block_section
;
1707 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, N_LSYM
, objfile
);
1710 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1715 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1716 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1717 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1718 SYMBOL_DUP (sym
, sym2
);
1719 add_symbol_to_list (sym2
, &local_symbols
);
1723 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1724 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1725 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1726 SYMBOL_DUP (sym
, sym2
);
1727 add_symbol_to_list (sym2
, &global_symbols
);
1731 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1732 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1733 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1734 SYMBOL_DUP (sym
, sym2
);
1736 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1740 printf_unfiltered ("ERROR! C_REG is not fully implemented!\n");
1741 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1742 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1743 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1744 SYMBOL_DUP (sym
, sym2
);
1745 add_symbol_to_list (sym2
, &local_symbols
);
1749 pp
= (char*) strchr (name
, ':');
1751 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1753 SYMBOL_SECTION (sym
) = cs
->c_secnum
;
1757 complain (&rsym_complaint
, name
);
1765 /* Set *SYMBOL to symbol number symno in symtbl. */
1767 read_symbol (symbol
, symno
)
1768 struct internal_syment
*symbol
;
1771 if (symno
< 0 || symno
>= symtbl_num_syms
)
1773 static struct complaint msg
=
1774 {"Invalid symbol offset", 0, 0};
1776 symbol
->n_value
= 0;
1777 symbol
->n_scnum
= -1;
1780 bfd_coff_swap_sym_in (symfile_bfd
, symtbl
+ (symno
*local_symesz
), symbol
);
1783 /* Get value corresponding to symbol number symno in symtbl. */
1786 read_symbol_nvalue (symno
)
1789 struct internal_syment symbol
[1];
1791 read_symbol (symbol
, symno
);
1792 return symbol
->n_value
;
1796 /* Find the address of the function corresponding to symno, where
1797 symno is the symbol pointed to by the linetable. */
1800 read_symbol_lineno (symno
)
1803 struct internal_syment symbol
[1];
1804 union internal_auxent main_aux
[1];
1806 /* Note that just searching for a short distance (e.g. 50 symbols)
1807 is not enough, at least in the following case.
1810 [many .stabx entries]
1811 [a few functions, referring to foo]
1815 What happens here is that the assembler moves the .stabx entries
1816 to right before the ".bf" for foo, but the symbol for "foo" is before
1817 all the stabx entries. See PR gdb/2222. */
1818 while (symno
< symtbl_num_syms
) {
1819 bfd_coff_swap_sym_in (symfile_bfd
,
1820 symtbl
+ (symno
*local_symesz
), symbol
);
1821 if (symbol
->n_sclass
== C_FCN
&& STREQ (symbol
->n_name
, ".bf"))
1823 symno
+= symbol
->n_numaux
+1;
1826 complain (&bf_notfound_complaint
);
1830 /* take aux entry and return its lineno */
1832 bfd_coff_swap_aux_in (symfile_bfd
, symtbl
+(symno
*local_symesz
),
1833 symbol
->n_type
, symbol
->n_sclass
,
1834 0, symbol
->n_numaux
, main_aux
);
1836 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1839 /* Support for line number handling */
1841 /* This function is called for every section; it finds the outer limits
1842 * of the line table (minimum and maximum file offset) so that the
1843 * mainline code can read the whole thing for efficiency.
1846 find_linenos(abfd
, asect
, vpinfo
)
1851 struct coff_symfile_info
*info
;
1853 file_ptr offset
, maxoff
;
1855 count
= asect
->lineno_count
;
1857 if (!STREQ (asect
->name
, ".text") || count
== 0)
1860 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1861 info
= (struct coff_symfile_info
*)vpinfo
;
1862 offset
= asect
->line_filepos
;
1863 maxoff
= offset
+ size
;
1865 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1866 info
->min_lineno_offset
= offset
;
1868 if (maxoff
> info
->max_lineno_offset
)
1869 info
->max_lineno_offset
= maxoff
;
1873 /* Read in all the line numbers for fast lookups later. Leave them in
1874 external (unswapped) format in memory; we'll swap them as we enter
1875 them into GDB's data structures. */
1878 init_lineno (abfd
, offset
, size
)
1887 if (bfd_seek(abfd
, offset
, L_SET
) < 0)
1890 linetab
= (char *) xmalloc(size
);
1892 val
= bfd_read(linetab
, 1, size
, abfd
);
1896 linetab_offset
= offset
;
1897 linetab_size
= size
;
1910 xcoff_new_init (objfile
)
1911 struct objfile
*objfile
;
1916 /* xcoff_symfile_init()
1917 is the xcoff-specific initialization routine for reading symbols.
1918 It is passed an objfile which contains, among other things,
1919 the BFD for the file whose symbols are being read, and a slot for
1920 a pointer to "private data" which we fill with cookies and other
1921 treats for xcoff_symfile_read().
1923 We will only be called if this is an XCOFF or XCOFF-like file.
1924 BFD handles figuring out the format of the file, and code in symfile.c
1925 uses BFD's determination to vector to us.
1927 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
1930 xcoff_symfile_init (objfile
)
1931 struct objfile
*objfile
;
1933 bfd
*abfd
= objfile
->obfd
;
1935 /* Allocate struct to keep track of the symfile */
1936 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
1937 sizeof (struct coff_symfile_info
));
1938 init_entry_point_info (objfile
);
1941 /* Perform any local cleanups required when we are done with a particular
1942 objfile. I.E, we are in the process of discarding all symbol information
1943 for an objfile, freeing up all memory held for it, and unlinking the
1944 objfile struct from the global list of known objfiles. */
1947 xcoff_symfile_finish (objfile
)
1948 struct objfile
*objfile
;
1950 if (objfile
-> sym_private
!= NULL
)
1952 mfree (objfile
-> md
, objfile
-> sym_private
);
1955 /* Start with a fresh include table for the next objfile. */
1962 inclIndx
= inclLength
= inclDepth
= 0;
1967 init_stringtab(abfd
, offset
, objfile
)
1970 struct objfile
*objfile
;
1974 unsigned char lengthbuf
[4];
1976 if (bfd_seek(abfd
, offset
, L_SET
) < 0)
1979 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1980 length
= bfd_h_get_32(abfd
, lengthbuf
);
1982 /* If no string table is needed, then the file may end immediately
1983 after the symbols. Just return with `strtbl' set to null. */
1985 if (val
!= sizeof length
|| length
< sizeof length
)
1988 /* Allocate string table from symbol_obstack. We will need this table
1989 as long as we have its symbol table around. */
1991 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
1995 memcpy(strtbl
, &length
, sizeof length
);
1996 if (length
== sizeof length
)
1999 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
2001 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
2008 init_debugsection(abfd
)
2011 register sec_ptr secp
;
2012 bfd_size_type length
;
2019 secp
= bfd_get_section_by_name(abfd
, ".debug");
2023 if (!(length
= bfd_section_size(abfd
, secp
)))
2026 debugsec
= (char *) xmalloc ((unsigned)length
);
2027 if (debugsec
== NULL
)
2030 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
2031 printf_unfiltered ("Can't read .debug section from symbol file\n");
2046 /* xcoff version of symbol file read. */
2049 xcoff_symfile_read (objfile
, section_offset
, mainline
)
2050 struct objfile
*objfile
;
2051 struct section_offsets
*section_offset
;
2054 int num_symbols
; /* # of symbols */
2055 file_ptr symtab_offset
; /* symbol table and */
2056 file_ptr stringtab_offset
; /* string table file offsets */
2059 struct coff_symfile_info
*info
;
2061 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2063 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2064 symfile_bfd
= abfd
= objfile
->obfd
;
2065 name
= objfile
->name
;
2067 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2068 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2069 stringtab_offset
= symtab_offset
+
2070 num_symbols
* coff_data(abfd
)->local_symesz
;
2072 info
->min_lineno_offset
= 0;
2073 info
->max_lineno_offset
= 0;
2074 bfd_map_over_sections (abfd
, find_linenos
, info
);
2076 /* FIXME! This stuff should move into symfile_init */
2077 if (info
->min_lineno_offset
!= 0
2078 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
2080 /* only read in the line # table if one exists */
2081 make_cleanup (free_linetab
, 0);
2082 val
= init_lineno(abfd
, info
->min_lineno_offset
,
2083 (int) (info
->max_lineno_offset
- info
->min_lineno_offset
));
2086 error("\"%s\": error reading line numbers\n", name
);
2089 if (num_symbols
> 0)
2091 val
= init_stringtab(abfd
, stringtab_offset
, objfile
);
2093 error ("\"%s\": can't get string table", name
);
2096 if (init_debugsection(abfd
) < 0) {
2097 error ("Error reading .debug section of `%s'\n", name
);
2101 /* Position to read the symbol table. Do not read it all at once. */
2102 val
= bfd_seek(abfd
, symtab_offset
, L_SET
);
2104 perror_with_name(name
);
2106 if (bfd_tell(abfd
) != symtab_offset
)
2109 init_minimal_symbol_collection ();
2110 make_cleanup (discard_minimal_symbols
, 0);
2112 #ifndef FAKING_RS6000
2113 /* Initialize load info structure. */
2115 xcoff_init_loadinfo ();
2118 /* Now that the executable file is positioned at symbol table,
2119 process it and define symbols accordingly. */
2121 read_xcoff_symtab(objfile
, num_symbols
);
2123 /* Free debug section. */
2124 free_debugsection ();
2126 /* Sort symbols alphabetically within each block. */
2129 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2131 sort_symtab_syms (s
);
2135 /* Install any minimal symbols that have been collected as the current
2136 minimal symbols for this objfile. */
2138 install_minimal_symbols (objfile
);
2140 do_cleanups (back_to
);
2143 /* XCOFF-specific parsing routine for section offsets. */
2145 static int largest_section
;
2148 note_one_section (abfd
, asect
, ptr
)
2153 if (asect
->target_index
> largest_section
)
2154 largest_section
= asect
->target_index
;
2158 struct section_offsets
*
2159 xcoff_symfile_offsets (objfile
, addr
)
2160 struct objfile
*objfile
;
2163 struct section_offsets
*section_offsets
;
2166 largest_section
= 0;
2167 bfd_map_over_sections (objfile
->obfd
, note_one_section
, NULL
);
2168 objfile
->num_sections
= largest_section
+ 1;
2169 section_offsets
= (struct section_offsets
*)
2171 (&objfile
-> psymbol_obstack
,
2172 sizeof (struct section_offsets
)
2173 + sizeof (section_offsets
->offsets
) * (objfile
->num_sections
));
2175 /* syms_from_objfile kindly subtracts from addr the bfd_section_vma
2176 of the .text section. This strikes me as wrong--whether the
2177 offset to be applied to symbol reading is relative to the start
2178 address of the section depends on the symbol format. In any
2179 event, this whole "addr" concept is pretty broken (it doesn't
2180 handle any section but .text sensibly), so just ignore the addr
2181 parameter and use 0. That matches the fact that xcoff_symfile_read
2182 ignores the section_offsets). */
2183 for (i
= 0; i
< objfile
->num_sections
; i
++)
2184 ANOFFSET (section_offsets
, i
) = 0;
2186 return section_offsets
;
2189 /* Register our ability to parse symbols for xcoff BFD files. */
2191 static struct sym_fns xcoff_sym_fns
=
2194 /* Because the bfd uses coff_flavour, we need to specially kludge
2195 the flavour. FIXME: coff and xcoff and fundamentally similar
2196 except for debug format, and we should see if we can merge this
2197 file with coffread.c. For example, the extra storage classes
2198 used for stabs could presumably be recognized in any COFF file. */
2200 (enum bfd_flavour
)-1,
2202 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2203 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2204 xcoff_symfile_read
, /* sym_read: read a symbol file into symtab */
2205 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2206 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2207 NULL
/* next: pointer to next struct sym_fns */
2211 _initialize_xcoffread ()
2213 add_symtab_fns(&xcoff_sym_fns
);
2215 /* Initialize symbol template later used for arguments. */
2216 SYMBOL_NAME (&parmsym
) = "";
2217 SYMBOL_INIT_LANGUAGE_SPECIFIC (&parmsym
, language_c
);
2218 SYMBOL_NAMESPACE (&parmsym
) = VAR_NAMESPACE
;
2219 SYMBOL_CLASS (&parmsym
) = LOC_ARG
;
2220 /* Its other fields are zero, or are filled in later. */