1 /* Read AIX xcoff symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
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. */
26 #if defined(IBM6000_HOST) && defined(IBM6000_TARGET)
27 /* Native only: Need struct tbtable in <sys/debug.h> from host, and
28 need xcoff_add_toc_to_loadinfo in rs6000-tdep.c from target. */
30 /* AIX XCOFF names have a preceeding dot `.' */
31 #define NAMES_HAVE_DOT 1
33 #include <sys/types.h>
38 #include <sys/param.h>
43 #include <sys/debug.h>
50 #include "stabsread.h"
51 #include "gdb-stabs.h"
53 #include "coff/internal.h" /* FIXME, internal data from BFD */
54 #include "libcoff.h" /* FIXME, internal data from BFD */
55 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
58 /* Define this if you want gdb use the old xcoff symbol processing. This
59 way it won't use common `define_symbol()' function and Sun dbx stab
60 string grammar. And likely it won't be able to do G++ debugging. */
62 /* #define NO_DEFINE_SYMBOL 1 */
64 /* Define this if you want gdb to ignore typdef stabs. This was needed for
65 one of Transarc, to reduce the size of the symbol table. Types won't be
66 recognized, but tag names will be. */
68 /* #define NO_TYPEDEFS 1 */
70 /* Simplified internal version of coff symbol table information */
74 int c_symnum
; /* symbol number of this entry */
75 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
82 /* The COFF line table, in raw form. */
83 static char *linetab
= NULL
; /* Its actual contents */
84 static long linetab_offset
; /* Its offset in the file */
85 static unsigned long linetab_size
; /* Its size */
87 /* last function's saved coff symbol `cs' */
89 static struct coff_symbol fcn_cs_saved
;
91 static bfd
*symfile_bfd
;
93 /* Core address of start and end of text of current source file.
94 This is calculated from the first function seen after a C_FILE
98 static CORE_ADDR cur_src_end_addr
;
100 /* Core address of the end of the first object file. */
102 static CORE_ADDR first_object_file_end
;
104 /* pointer to the string table */
107 /* length of the string table */
108 static int strtbl_len
;
110 /* pointer to debug section */
111 static char *debugsec
;
113 /* pointer to the a.out symbol table */
116 /* initial symbol-table-debug-string vector length */
118 #define INITIAL_STABVECTOR_LENGTH 40
120 /* Nonzero if within a function (so symbols should be local,
121 if nothing says specifically). */
125 /* Local variables that hold the shift and mask values for the
126 COFF file that we are currently reading. These come back to us
127 from BFD, and are referenced by their macro names, as well as
128 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
129 macros from ../internalcoff.h . */
131 static unsigned local_n_btshft
;
132 static unsigned local_n_tmask
;
135 #define N_BTSHFT local_n_btshft
137 #define N_TMASK local_n_tmask
139 /* Local variables that hold the sizes in the file of various COFF structures.
140 (We only need to know this to read them from the file -- BFD will then
141 translate the data in them, into `internal_xxx' structs in the right
142 byte order, alignment, etc.) */
144 static unsigned local_symesz
;
147 /* coff_symfile_init()
148 is the coff-specific initialization routine for reading symbols.
149 It is passed a struct sym_fns which contains, among other things,
150 the BFD for the file whose symbols are being read, and a slot for
151 a pointer to "private data" which we fill with cookies and other
152 treats for coff_symfile_read().
154 We will only be called if this is a COFF or COFF-like file.
155 BFD handles figuring out the format of the file, and code in symtab.c
156 uses BFD's determination to vector to us.
158 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
160 struct coff_symfile_info
{
161 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
162 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
167 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
168 CORE_ADDR
, CORE_ADDR
, unsigned *));
171 free_debugsection
PARAMS ((void));
174 init_debugsection
PARAMS ((bfd
*));
177 init_stringtab
PARAMS ((bfd
*, long, struct objfile
*));
180 xcoff_symfile_init
PARAMS ((struct objfile
*));
183 xcoff_new_init
PARAMS ((struct objfile
*));
185 struct section_offset
;
188 xcoff_symfile_read
PARAMS ((struct objfile
*, struct section_offset
*, int));
191 xcoff_symfile_finish
PARAMS ((struct objfile
*));
193 static struct section_offsets
*
194 xcoff_symfile_offsets
PARAMS ((struct objfile
*, CORE_ADDR
));
197 init_lineno
PARAMS ((bfd
*, long, int));
200 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
203 read_symbol_lineno
PARAMS ((char *, int));
206 read_symbol_nvalue
PARAMS ((char *, int));
208 static struct symbol
*
209 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
212 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
215 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
218 sort_syms
PARAMS ((void));
221 compare_symbols
PARAMS ((const void *, const void *));
223 /* Call sort_syms to sort alphabetically
224 the symbols of each block of each symtab. */
227 compare_symbols (s1p
, s2p
)
231 /* Names that are less should come first. */
232 register struct symbol
**s1
= (struct symbol
**) s1p
;
233 register struct symbol
**s2
= (struct symbol
**) s2p
;
234 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
238 /* For symbols of the same name, registers should come first. */
239 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
240 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
244 /* Sort a vector of symbols by their value. */
249 register struct symtab
*s
;
250 register struct objfile
*objfile
;
252 register struct blockvector
*bv
;
253 register struct block
*b
;
255 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
257 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
259 bv
= BLOCKVECTOR (s
);
260 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
261 for (i
= 0; i
< nbl
; i
++)
263 b
= BLOCKVECTOR_BLOCK (bv
, i
);
264 if (BLOCK_SHOULD_SORT (b
))
266 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
267 sizeof (struct symbol
*), compare_symbols
);
275 /* add a given stab string into given stab vector. */
278 add_stab_to_list (stabname
, stabvector
)
280 struct pending_stabs
**stabvector
;
282 if ( *stabvector
== NULL
) {
283 *stabvector
= (struct pending_stabs
*)
284 xmalloc (sizeof (struct pending_stabs
) +
285 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
286 (*stabvector
)->count
= 0;
287 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
289 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
290 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
291 *stabvector
= (struct pending_stabs
*)
292 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
293 (*stabvector
)->length
* sizeof (char*));
295 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
300 /* for all the stabs in a given stab vector, build appropriate types
301 and fix their symbols in given symbol vector. */
304 patch_block_stabs (symbols
, stabs
)
305 struct pending
*symbols
;
306 struct pending_stabs
*stabs
;
313 /* for all the stab entries, find their corresponding symbols and
314 patch their types! */
316 for (ii
=0; ii
< stabs
->count
; ++ii
) {
317 char *name
= stabs
->stab
[ii
];
318 char *pp
= (char*) index (name
, ':');
319 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
322 /* printf ("ERROR! stab symbol not found!\n"); */ /* FIXME */
323 /* The above is a false alarm. There are cases the we can have
324 a stab, without its symbol. xlc generates this for the extern
325 definitions in inner blocks. */
330 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
331 SYMBOL_TYPE (sym
) = lookup_function_type (read_type (&pp
));
333 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
340 /* compare line table entry addresses. */
343 compare_lte (lte1
, lte2
)
344 struct linetable_entry
*lte1
, *lte2
;
346 return lte1
->pc
- lte2
->pc
;
349 /* Give a line table with function entries are marked, arrange its functions
350 in assending order and strip off function entry markers and return it in
351 a newly created table. If the old one is good enough, return the old one. */
353 static struct linetable
*
354 arrange_linetable (oldLineTb
)
355 struct linetable
*oldLineTb
; /* old linetable */
358 newline
, /* new line count */
359 function_count
; /* # of functions */
361 struct linetable_entry
*fentry
; /* function entry vector */
362 int fentry_size
; /* # of function entries */
363 struct linetable
*newLineTb
; /* new line table */
365 #define NUM_OF_FUNCTIONS 20
367 fentry_size
= NUM_OF_FUNCTIONS
;
368 fentry
= (struct linetable_entry
*)
369 malloc (fentry_size
* sizeof (struct linetable_entry
));
371 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
373 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
375 if (function_count
>= fentry_size
) { /* make sure you have room. */
377 fentry
= (struct linetable_entry
*)
378 realloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
380 fentry
[function_count
].line
= ii
;
381 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
386 if (function_count
== 0) {
390 else if (function_count
> 1)
391 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
393 /* allocate a new line table. */
394 newLineTb
= (struct linetable
*) malloc (sizeof (struct linetable
) +
395 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
397 /* if line table does not start with a function beginning, copy up until
401 if (oldLineTb
->item
[0].line
!= 0)
403 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
404 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
406 /* Now copy function lines one by one. */
408 for (ii
=0; ii
< function_count
; ++ii
) {
409 for (jj
= fentry
[ii
].line
+ 1;
410 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
412 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
415 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
421 /* We try to detect the beginning of a compilation unit. That info will
422 be used as an entry in line number recording routines (enter_line_range) */
424 static unsigned first_fun_line_offset
;
425 static unsigned first_fun_bf
;
427 #define mark_first_line(OFFSET, SYMNUM) \
428 if (!first_fun_line_offset) { \
429 first_fun_line_offset = OFFSET; \
430 first_fun_bf = SYMNUM; \
434 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
435 following `IncludeChain'. At the end of each symtab (end_symtab),
436 we will determine if we should create additional symtab's to
437 represent if (the include files. */
440 typedef struct _inclTable
{
441 char *name
; /* include filename */
442 int begin
, end
; /* offsets to the line table */
443 struct subfile
*subfile
;
444 unsigned funStartLine
; /* start line # of its function */
447 #define INITIAL_INCLUDE_TABLE_LENGTH 20
448 static InclTable
*inclTable
; /* global include table */
449 static int inclIndx
; /* last entry to table */
450 static int inclLength
; /* table length */
451 static int inclDepth
; /* nested include depth */
455 record_include_begin (cs
)
456 struct coff_symbol
*cs
;
458 /* In xcoff, we assume include files cannot be nested (not in .c files
459 of course, but in corresponding .s files.) */
462 fatal ("xcoff internal: pending include file exists.");
466 /* allocate an include file, or make room for the new entry */
467 if (inclLength
== 0) {
468 inclTable
= (InclTable
*)
469 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
470 bzero (inclTable
, sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
471 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
474 else if (inclIndx
>= inclLength
) {
475 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
476 inclTable
= (InclTable
*)
477 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
478 bzero (inclTable
+inclLength
-INITIAL_INCLUDE_TABLE_LENGTH
,
479 sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
482 inclTable
[inclIndx
].name
= cs
->c_name
;
483 inclTable
[inclIndx
].begin
= cs
->c_value
;
488 record_include_end (cs
)
489 struct coff_symbol
*cs
;
494 fatal ("xcoff internal: Mismatch C_BINCL/C_EINCL pair found.");
496 pTbl
= &inclTable
[inclIndx
];
497 pTbl
->end
= cs
->c_value
;
504 /* given the start and end addresses of a compilation unit (or a csect, at times)
505 process its lines and create appropriate line vectors. */
508 process_linenos (start
, end
)
509 CORE_ADDR start
, end
;
514 struct subfile main_subfile
; /* subfile structure for the main
517 /* in the main source file, any time we see a function entry, we reset
518 this variable to function's absolute starting line number. All the
519 following line numbers in the function are relative to this, and
520 we record absolute line numbers in record_line(). */
522 int main_source_baseline
= 0;
528 if (!(offset
= first_fun_line_offset
))
529 goto return_after_cleanup
;
531 bzero (&main_subfile
, sizeof (main_subfile
));
532 first_fun_line_offset
= 0;
535 /* All source lines were in the main source file. None in include files. */
537 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
538 &main_source_baseline
);
540 /* else, there was source with line numbers in include files */
543 main_source_baseline
= 0;
544 for (ii
=0; ii
< inclIndx
; ++ii
) {
546 struct subfile
*tmpSubfile
;
548 /* if there is main file source before include file, enter it. */
549 if (offset
< inclTable
[ii
].begin
) {
551 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
, start
, 0,
552 &main_source_baseline
);
555 /* Have a new subfile for the include file */
557 tmpSubfile
= inclTable
[ii
].subfile
= (struct subfile
*)
558 xmalloc (sizeof (struct subfile
));
560 bzero (tmpSubfile
, sizeof (struct subfile
));
561 firstLine
= &(inclTable
[ii
].funStartLine
);
563 /* enter include file's lines now. */
564 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
565 inclTable
[ii
].end
, start
, 0, firstLine
);
567 offset
= inclTable
[ii
].end
+ LINESZ
;
570 /* all the include files' line have been processed at this point. Now,
571 enter remaining lines of the main file, if any left. */
572 if (offset
< (linetab_offset
+ linetab_size
+ 1 - LINESZ
)) {
573 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
574 &main_source_baseline
);
578 /* Process main file's line numbers. */
579 if (main_subfile
.line_vector
) {
580 struct linetable
*lineTb
, *lv
;
582 lv
= main_subfile
.line_vector
;
584 /* Line numbers are not necessarily ordered. xlc compilation will
585 put static function to the end. */
587 lineTb
= arrange_linetable (lv
);
589 current_subfile
->line_vector
= (struct linetable
*)
590 xrealloc (lv
, (sizeof (struct linetable
)
591 + lv
->nitems
* sizeof (struct linetable_entry
)));
596 current_subfile
->line_vector
= lineTb
;
599 current_subfile
->line_vector_length
=
600 current_subfile
->line_vector
->nitems
;
603 /* Now, process included files' line numbers. */
605 for (ii
=0; ii
< inclIndx
; ++ii
) {
607 if ( (inclTable
[ii
].subfile
)->line_vector
) { /* Useless if!!! FIXMEmgo */
608 struct linetable
*lineTb
, *lv
;
610 lv
= (inclTable
[ii
].subfile
)->line_vector
;
612 /* Line numbers are not necessarily ordered. xlc compilation will
613 put static function to the end. */
615 lineTb
= arrange_linetable (lv
);
619 /* For the same include file, we might want to have more than one subfile.
620 This happens if we have something like:
628 while foo.h including code in it. (stupid but possible)
629 Since start_subfile() looks at the name and uses an existing one if finds,
630 we need to provide a fake name and fool it. */
632 /* start_subfile (inclTable[ii].name, (char*)0); */
633 start_subfile (" ?", (char*)0);
634 current_subfile
->name
=
635 obsavestring (inclTable
[ii
].name
, strlen (inclTable
[ii
].name
),
636 ¤t_objfile
->symbol_obstack
);
639 current_subfile
->line_vector
= (struct linetable
*)
640 xrealloc (lv
, (sizeof (struct linetable
)
641 + lv
->nitems
* sizeof (struct linetable_entry
)));
646 current_subfile
->line_vector
= lineTb
;
649 current_subfile
->line_vector_length
=
650 current_subfile
->line_vector
->nitems
;
651 start_subfile (pop_subfile (), (char*)0);
655 return_after_cleanup
:
657 /* We don't want to keep alloc/free'ing the global include file table. */
660 /* start with a fresh subfile structure for the next file. */
661 bzero (&main_subfile
, sizeof (struct subfile
));
665 aix_process_linenos ()
667 /* process line numbers and enter them into line vector */
668 process_linenos (last_source_start_addr
, cur_src_end_addr
);
672 /* Enter a given range of lines into the line vector.
673 can be called in the following two ways:
674 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
675 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine) */
678 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
, firstLine
)
679 struct subfile
*subfile
;
680 unsigned beginoffset
, endoffset
; /* offsets to line table */
681 CORE_ADDR startaddr
, endaddr
;
687 /* Do Byte swapping, if needed. FIXME! */
688 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
689 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
690 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
692 pp
= &linetab
[beginoffset
- linetab_offset
];
693 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
694 : &linetab
[linetab_size
-1];
696 while (pp
<= limit
) {
698 /* find the address this line represents */
699 addr
= P_LINENO(pp
) ?
700 P_LINEADDR(pp
) : read_symbol_nvalue (symtbl
, P_LINESYM(pp
));
702 if (addr
< startaddr
|| (endaddr
&& addr
> endaddr
))
705 if (P_LINENO(pp
) == 0) {
706 *firstLine
= read_symbol_lineno (symtbl
, P_LINESYM(pp
));
707 record_line (subfile
, 0, addr
);
711 record_line (subfile
, *firstLine
+ P_LINENO(pp
), addr
);
718 int fsize
; /* file size */
719 int fixedparms
; /* number of fixed parms */
720 int floatparms
; /* number of float parms */
721 unsigned int parminfo
; /* parameter info.
722 See /usr/include/sys/debug.h
723 tbtable_ext.parminfo */
724 int framesize
; /* function frame size */
728 /* Given a function symbol, return its traceback information. */
731 retrieve_tracebackinfo (abfd
, textsec
, cs
)
734 struct coff_symbol
*cs
;
736 #define TBTABLE_BUFSIZ 2000
737 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
740 static TracebackInfo tbInfo
;
743 static char buffer
[TBTABLE_BUFSIZ
];
746 int bytesread
=0; /* total # of bytes read so far */
747 int bufferbytes
; /* number of bytes in the buffer */
749 int functionstart
= cs
->c_value
- textsec
->vma
;
751 bzero (&tbInfo
, sizeof (tbInfo
));
753 /* keep reading blocks of data from the text section, until finding a zero
754 word and a traceback table. */
758 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
)) ?
759 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
))
761 && bfd_get_section_contents (abfd
, textsec
, buffer
,
762 (file_ptr
)(functionstart
+ bytesread
), bufferbytes
))
764 bytesread
+= bufferbytes
;
765 pinsn
= (int*) buffer
;
767 /* if this is the first time we filled the buffer, retrieve function
770 if (bytesread
== bufferbytes
) {
772 /* skip over unrelated instructions */
774 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
776 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
778 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
780 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
784 int tmp
= (*pinsn
>> 16) & 0xffff;
786 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
787 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
790 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
791 (tmp
== 0x9001)) /* st r0, NUM(r1) */
793 /* else, could not find a frame size. */
797 } while (++pinsn
&& *pinsn
);
799 if (!tbInfo
.framesize
)
803 /* look for a zero word. */
805 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
808 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
813 /* function size is the amount of bytes we have skipped so far. */
814 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
818 /* if we don't have the whole traceback table in the buffer, re-read
821 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
823 /* In case if we are *very* close to the end of the text section
824 and cannot read properly from that point on, abort by returning
826 Handle this case more graciously -- FIXME */
828 if (!bfd_get_section_contents (
829 abfd
, textsec
, buffer
,
830 (file_ptr
)(functionstart
+
831 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
832 { printf ("Abnormal return!..\n"); return NULL
; }
834 ptb
= (struct tbtable
*)buffer
;
837 ptb
= (struct tbtable
*)pinsn
;
839 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
840 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
841 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
849 /* Given a function symbol, return a pointer to its traceback table. */
852 retrieve_traceback (abfd
, textsec
, cs
, size
)
855 struct coff_symbol
*cs
;
856 int *size
; /* return function size */
858 #define TBTABLE_BUFSIZ 2000
859 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
862 static char buffer
[TBTABLE_BUFSIZ
];
865 int bytesread
=0; /* total # of bytes read so far */
866 int bufferbytes
; /* number of bytes in the buffer */
868 int functionstart
= cs
->c_value
- textsec
->filepos
+ textsec
->vma
;
871 /* keep reading blocks of data from the text section, until finding a zero
872 word and a traceback table. */
874 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
875 (file_ptr
)(functionstart
+ bytesread
),
877 (TBTABLE_BUFSIZ
< (textsec
->size
- functionstart
- bytesread
)) ?
878 TBTABLE_BUFSIZ
: (textsec
->size
- functionstart
- bytesread
))))
880 bytesread
+= bufferbytes
;
881 pinsn
= (int*) buffer
;
883 /* look for a zero word. */
885 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
888 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
893 /* function size is the amount of bytes we have skipped so far. */
894 *size
= bytesread
- (buffer
+ bufferbytes
- pinsn
);
898 /* if we don't have the whole traceback table in the buffer, re-read
901 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
903 /* In case if we are *very* close to the end of the text section
904 and cannot read properly from that point on, abort for now.
905 Handle this case more graciously -- FIXME */
907 if (!bfd_get_section_contents (
908 abfd
, textsec
, buffer
,
909 (file_ptr
)(functionstart
+
910 bytesread
- (buffer
+ bufferbytes
- pinsn
)),MIN_TBTABSIZ
))
911 /* abort (); */ { printf ("abort!!!\n"); return NULL
; }
913 return (struct tbtable
*)buffer
;
916 return (struct tbtable
*)pinsn
;
926 /* Save the vital information for use when closing off the current file.
927 NAME is the file name the symbols came from, START_ADDR is the first
928 text address for the file, and SIZE is the number of bytes of text. */
930 #define complete_symtab(name, start_addr) { \
931 last_source_file = savestring (name, strlen (name)); \
932 last_source_start_addr = start_addr; \
936 /* Refill the symbol table input buffer
937 and set the variables that control fetching entries from it.
938 Reports an error if no data available.
939 This function can read past the end of the symbol table
940 (into the string table) but this does no harm. */
942 /* Reading symbol table has to be fast! Keep the followings as macros, rather
945 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \
949 namestr = (NAME) + 1; \
952 obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
955 prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \
956 misc_func_recorded = 1; \
960 /* A parameter template, used by ADD_PARM_TO_PENDING. */
962 static struct symbol parmsym
= { /* default parameter symbol */
964 VAR_NAMESPACE
, /* namespace */
971 /* Add a parameter to a given pending symbol list. */
973 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
975 PARM = (struct symbol *) \
976 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
978 SYMBOL_TYPE (PARM) = PTYPE; \
979 SYMBOL_VALUE (PARM) = VALUE; \
980 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
984 /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
985 nested. At any given time, a symbol can only be in one static block.
986 This is the base address of current static block, zero if non exists. */
988 static int static_block_base
= 0;
990 /* true if space for symbol name has been allocated. */
992 static int symname_alloced
= 0;
994 /* read the whole symbol table of a given bfd. */
997 read_xcoff_symtab (objfile
, nsyms
)
998 struct objfile
*objfile
; /* Object file we're reading from */
999 int nsyms
; /* # of symbols */
1001 bfd
*abfd
= objfile
->obfd
;
1002 char *raw_symbol
; /* Pointer into raw seething symbol table */
1003 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
1004 sec_ptr textsec
; /* Pointer to text section */
1005 TracebackInfo
*ptb
; /* Pointer to traceback table */
1007 struct internal_syment symbol
[1];
1008 union internal_auxent main_aux
[1];
1009 struct coff_symbol cs
[1];
1010 CORE_ADDR file_start_addr
= 0;
1011 CORE_ADDR file_end_addr
= 0;
1013 int next_file_symnum
= -1;
1014 int just_started
= 1;
1016 int toc_offset
= 0; /* toc offset value in data section. */
1020 long fcn_line_offset
;
1023 struct coff_symbol fcn_stab_saved
;
1025 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1026 union internal_auxent fcn_aux_saved
;
1027 struct type
*fcn_type_saved
= NULL
;
1028 struct context_stack
*new;
1030 char *filestring
= " _start_ "; /* Name of the current file. */
1032 char *last_csect_name
; /* last seen csect's name and value */
1033 CORE_ADDR last_csect_val
;
1034 int misc_func_recorded
; /* true if any misc. function */
1036 current_objfile
= objfile
;
1038 /* Get the appropriate COFF "constants" related to the file we're handling. */
1039 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
1040 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
1041 local_symesz
= coff_data (abfd
)->local_symesz
;
1043 last_source_file
= NULL
;
1044 last_csect_name
= 0;
1046 misc_func_recorded
= 0;
1049 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1051 first_object_file_end
= 0;
1053 /* Allocate space for the entire symbol table at once, and read it
1054 all in. The bfd is already positioned at the beginning of
1055 the symbol table. */
1057 size
= coff_data (abfd
)->local_symesz
* nsyms
;
1058 symtbl
= xmalloc (size
);
1060 val
= bfd_read (symtbl
, size
, 1, abfd
);
1062 perror_with_name ("reading symbol table");
1064 raw_symbol
= symtbl
;
1066 textsec
= bfd_get_section_by_name (abfd
, ".text");
1068 printf ("Unable to locate text section!\n");
1071 while (symnum
< nsyms
) {
1073 QUIT
; /* make this command interruptable. */
1075 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1076 /* read one symbol into `cs' structure. After processing the whole symbol
1077 table, only string table will be kept in memory, symbol table and debug
1078 section of xcoff will be freed. Thus we can mark symbols with names
1079 in string table as `alloced'. */
1083 /* Swap and align the symbol into a reasonable C structure. */
1084 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1086 cs
->c_symnum
= symnum
;
1087 cs
->c_nsyms
= symbol
->n_numaux
;
1088 if (symbol
->n_zeroes
) {
1089 symname_alloced
= 0;
1090 /* We must use the original, unswapped, name here so the name field
1091 pointed to by cs->c_name will persist throughout xcoffread. If
1092 we use the new field, it gets overwritten for each symbol. */
1093 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1094 } else if (symbol
->n_sclass
& 0x80) {
1095 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1096 symname_alloced
= 0;
1097 } else { /* in string table */
1098 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1099 symname_alloced
= 1;
1101 cs
->c_value
= symbol
->n_value
;
1102 /* n_sclass is signed (FIXME), so we had better not mask off any
1103 high bits it contains, since the values we will be comparing
1104 it to are also signed (FIXME). Defined in <coff/internal.h>.
1105 At this point (3Jun92, gnu@cygnus.com) I think the fix is to
1106 make the fields and values unsigned chars, but changing the next
1107 line is a simple patch late in the release cycle, for now. */
1108 cs
->c_sclass
= symbol
->n_sclass
/* & 0xff */;
1109 cs
->c_secnum
= symbol
->n_scnum
;
1110 cs
->c_type
= (unsigned)symbol
->n_type
;
1112 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1115 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
1117 /* Skip all the auxents associated with this symbol. */
1118 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
1119 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1124 /* if symbol name starts with ".$" or "$", ignore it. */
1125 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1128 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
1129 if (last_source_file
)
1131 end_symtab (cur_src_end_addr
, 1, 0, objfile
);
1136 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1137 cur_src_end_addr
= first_object_file_end
;
1138 /* done with all files, everything from here on is globals */
1141 /* if explicitly specified as a function, treat is as one. */
1142 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
1143 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1145 goto function_entry_point
;
1148 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
1150 /* dealing with a symbol with a csect entry. */
1152 # define CSECT(PP) ((PP)->x_csect)
1153 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1154 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1155 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1156 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1158 /* Convert the auxent to something we can access. */
1159 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1162 switch (CSECT_SMTYP (main_aux
)) {
1165 continue; /* ignore all external references. */
1167 case XTY_SD
: /* a section description. */
1169 switch (CSECT_SCLAS (main_aux
)) {
1171 case XMC_PR
: /* a `.text' csect. */
1174 /* A program csect is seen.
1176 We have to allocate one symbol table for each program csect. Normally
1177 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
1178 CU might include more than one prog csect, and they don't have to be
1179 adjacent in terms of the space they occupy in memory. Thus, one single
1180 CU might get fragmented in the memory and gdb's file start and end address
1181 approach does not work! */
1183 if (last_csect_name
) {
1185 /* if no misc. function recorded in the last seen csect, enter
1186 it as a function. This will take care of functions like
1187 strcmp() compiled by xlc. */
1189 if (!misc_func_recorded
) {
1191 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1196 complete_symtab (filestring
, file_start_addr
);
1197 cur_src_end_addr
= file_end_addr
;
1198 end_symtab (file_end_addr
, 1, 0, objfile
);
1201 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
1204 /* If this is the very first csect seen, basically `__start'. */
1206 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
1210 file_start_addr
= cs
->c_value
;
1211 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
1213 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
1214 last_csect_name
= cs
->c_name
;
1215 last_csect_val
= cs
->c_value
;
1218 misc_func_recorded
= 0;
1224 /* If the section is not a data description, ignore it. Note that
1225 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1229 warning ("More than one xmc_tc0 symbol found.");
1230 toc_offset
= cs
->c_value
;
1233 case XMC_TC
: /* ignore toc entries */
1234 default : /* any other XMC_XXX */
1238 break; /* switch CSECT_SCLAS() */
1242 /* a function entry point. */
1243 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
1245 function_entry_point
:
1246 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1249 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1250 fcn_start_addr
= cs
->c_value
;
1252 /* save the function header info, which will be used
1253 when `.bf' is seen. */
1255 fcn_aux_saved
= *main_aux
;
1260 /* If function has two auxent, then debugging information is
1261 already available for it. Process traceback table for
1262 functions with only one auxent. */
1264 if (cs
->c_nsyms
== 1)
1265 ptb
= retrieve_tracebackinfo (abfd
, textsec
, cs
);
1267 else if (cs
->c_nsyms
!= 2)
1270 /* If there is traceback info, create and add parameters for it. */
1272 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
)) {
1274 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1275 char *parmcode
= (char*) &ptb
->parminfo
;
1276 int parmvalue
= ptb
->framesize
+ 0x18; /* sizeof(LINK AREA) == 0x18 */
1277 unsigned int ii
, mask
;
1279 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
) {
1280 struct symbol
*parm
;
1282 if (ptb
->parminfo
& mask
) { /* float or double */
1284 if (ptb
->parminfo
& mask
) { /* double parm */
1286 (parm
, parmvalue
, builtin_type_double
, local_symbols
);
1287 parmvalue
+= sizeof (double);
1289 else { /* float parm */
1291 (parm
, parmvalue
, builtin_type_float
, local_symbols
);
1292 parmvalue
+= sizeof (float);
1295 else { /* fixed parm, use (int*) for hex rep. */
1296 ADD_PARM_TO_PENDING (parm
, parmvalue
,
1297 lookup_pointer_type (builtin_type_int
),
1299 parmvalue
+= sizeof (int);
1304 /* Fake this as a function. Needed in process_xcoff_symbol() */
1307 finish_block(process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1308 pending_blocks
, cs
->c_value
,
1309 cs
->c_value
+ ptb
->fsize
, objfile
);
1313 /* shared library function trampoline code entry point. */
1314 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
1316 /* record trampoline code entries as mst_unknown symbol. When we
1317 lookup mst symbols, we will choose mst_text over mst_unknown. */
1320 /* After the implementation of incremental loading of shared
1321 libraries, we don't want to access trampoline entries. This
1322 approach has a consequence of the necessity to bring the whole
1323 shared library at first, in order do anything with it (putting
1324 breakpoints, using malloc, etc). On the other side, this is
1325 consistient with gdb's behaviour on a SUN platform. */
1327 /* Trying to prefer *real* function entry over its trampoline,
1328 by assigning `mst_unknown' type to trampoline entries fails.
1329 Gdb treats those entries as chars. FIXME. */
1331 /* Recording this entry is necessary. Single stepping relies on
1332 this vector to get an idea about function address boundaries. */
1334 prim_record_minimal_symbol (0, cs
->c_value
, mst_unknown
);
1337 /* record trampoline code entries as mst_unknown symbol. When we
1338 lookup mst symbols, we will choose mst_text over mst_unknown. */
1340 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_unknown
,
1347 default : /* all other XTY_XXXs */
1349 } /* switch CSECT_SMTYP() */ }
1351 switch (cs
->c_sclass
) {
1355 /* see if the last csect needs to be recorded. */
1357 if (last_csect_name
&& !misc_func_recorded
) {
1359 /* if no misc. function recorded in the last seen csect, enter
1360 it as a function. This will take care of functions like
1361 strcmp() compiled by xlc. */
1364 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1368 /* c_value field contains symnum of next .file entry in table
1369 or symnum of first global after last .file. */
1371 next_file_symnum
= cs
->c_value
;
1373 /* complete symbol table for last object file containing
1374 debugging information. */
1376 /* Whether or not there was a csect in the previous file, we have to call
1377 `end_stabs' and `start_stabs' to reset type_vector,
1378 line_vector, etc. structures. */
1380 complete_symtab (filestring
, file_start_addr
);
1381 cur_src_end_addr
= file_end_addr
;
1382 end_symtab (file_end_addr
, 1, 0, objfile
);
1385 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
1386 last_csect_name
= 0;
1388 /* reset file start and end addresses. A compilation unit with no text
1389 (only data) should have zero file boundaries. */
1390 file_start_addr
= file_end_addr
= 0;
1392 filestring
= cs
->c_name
;
1398 #ifdef NO_DEFINE_SYMBOL
1399 /* For a function stab, just save its type in `fcn_type_saved', and leave
1400 it for the `.bf' processing. */
1402 char *pp
= (char*) index (cs
->c_name
, ':');
1404 if (!pp
|| ( *(pp
+1) != 'F' && *(pp
+1) != 'f'))
1405 fatal ("Unrecognized stab");
1409 fatal ("Unprocessed function type");
1411 fcn_type_saved
= lookup_function_type (read_type (&pp
, objfile
));
1414 fcn_stab_saved
= *cs
;
1420 if (strcmp (cs
->c_name
, ".bf") == 0) {
1422 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1425 within_function
= 1;
1427 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
1428 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
1432 1) xlc (IBM's native c compiler) postpones static function code
1433 emission to the end of a compilation unit. This way it can
1434 determine if those functions (statics) are needed or not, and
1435 can do some garbage collection (I think). This makes line
1436 numbers and corresponding addresses unordered, and we end up
1437 with a line table like:
1454 and that breaks gdb's binary search on line numbers, if the
1455 above table is not sorted on line numbers. And that sort
1456 should be on function based, since gcc can emit line numbers
1459 10 0x100 - for the init/test part of a for stmt.
1462 10 0x400 - for the increment part of a for stmt.
1464 arrange_linenos() will do this sorting.
1467 2) aix symbol table might look like:
1469 c_file // beginning of a new file
1470 .bi // beginning of include file
1471 .ei // end of include file
1475 basically, .bi/.ei pairs do not necessarily encapsulate
1476 their scope. They need to be recorded, and processed later
1477 on when we come the end of the compilation unit.
1478 Include table (inclTable) and process_linenos() handle
1481 mark_first_line (fcn_line_offset
, cs
->c_symnum
);
1483 new = push_context (0, fcn_start_addr
);
1485 #ifdef NO_DEFINE_SYMBOL
1486 new->name
= process_xcoff_symbol (&fcn_cs_saved
, objfile
);
1488 /* Between a function symbol and `.bf', there always will be a function
1489 stab. We save function type when processing that stab. */
1491 if (fcn_type_saved
== NULL
) {
1492 printf ("Unknown function type: symbol 0x%x\n", cs
->c_symnum
);
1493 SYMBOL_TYPE (new->name
) = lookup_function_type (builtin_type_int
);
1496 SYMBOL_TYPE (new->name
) = fcn_type_saved
;
1497 fcn_type_saved
= NULL
;
1500 new->name
= define_symbol
1501 (fcn_cs_saved
.c_value
, fcn_stab_saved
.c_name
, 0, 0, objfile
);
1504 else if (strcmp (cs
->c_name
, ".ef") == 0) {
1506 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1509 /* the value of .ef is the address of epilogue code;
1510 not useful for gdb */
1511 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1512 contains number of lines to '}' */
1514 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1515 new = pop_context ();
1516 if (context_stack_depth
!= 0)
1517 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1520 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1522 fcn_cs_saved
.c_value
+
1523 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
1524 within_function
= 0;
1528 case C_BSTAT
: /* begin static block */
1529 static_block_base
= read_symbol_nvalue (symtbl
, cs
->c_value
);
1532 case C_ESTAT
: /* end of static block */
1533 static_block_base
= 0;
1536 case C_ARG
: /* These are not implemented. */
1542 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
1545 case C_HIDEXT
: /* ignore these.. */
1550 case C_BINCL
: /* beginning of include file */
1552 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1553 order. Thus, when wee see them, we might not know enough info
1554 to process them. Thus, we'll be saving them into a table
1555 (inclTable) and postpone their processing. */
1557 record_include_begin (cs
);
1560 case C_EINCL
: /* end of include file */
1561 /* see the comment after case C_BINCL. */
1562 record_include_end (cs
);
1566 if (strcmp (cs
->c_name
, ".bb") == 0) {
1568 new = push_context (depth
, cs
->c_value
);
1570 else if (strcmp (cs
->c_name
, ".eb") == 0) {
1571 new = pop_context ();
1572 if (depth
!= new->depth
)
1573 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1577 if (local_symbols
&& context_stack_depth
> 0) {
1578 /* Make a block for the local symbols within. */
1579 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1580 new->start_addr
, cs
->c_value
, objfile
);
1582 local_symbols
= new->locals
;
1587 process_xcoff_symbol (cs
, objfile
);
1593 if (last_source_file
)
1595 end_symtab (cur_src_end_addr
, 1, 0, objfile
);
1600 current_objfile
= NULL
;
1602 /* Record the toc offset value of this symbol table into ldinfo structure.
1603 If no XMC_TC0 is found, toc_offset should be zero. Another place to obtain
1604 this information would be file auxiliary header. */
1606 xcoff_add_toc_to_loadinfo (toc_offset
);
1609 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1610 (SYMBOL2) = (struct symbol *) \
1611 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1612 *(SYMBOL2) = *(SYMBOL1);
1615 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1616 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1619 /* process one xcoff symbol. */
1621 static struct symbol
*
1622 process_xcoff_symbol (cs
, objfile
)
1623 register struct coff_symbol
*cs
;
1624 struct objfile
*objfile
;
1626 struct symbol onesymbol
;
1627 register struct symbol
*sym
= &onesymbol
;
1628 struct symbol
*sym2
= NULL
;
1630 char *name
, *pp
, *qq
;
1631 int struct_and_type_combined
;
1638 bzero (sym
, sizeof (struct symbol
));
1640 /* default assumptions */
1641 SYMBOL_VALUE (sym
) = cs
->c_value
;
1642 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1644 if (ISFCN (cs
->c_type
)) {
1646 /* At this point, we don't know the type of the function and assume it
1647 is int. This will be patched with the type from its stab entry later
1648 on in patch_block_stabs () */
1650 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1651 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (objfile
, FT_INTEGER
));
1653 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1654 SYMBOL_DUP (sym
, sym2
);
1656 if (cs
->c_sclass
== C_EXT
)
1657 add_symbol_to_list (sym2
, &global_symbols
);
1658 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1659 add_symbol_to_list (sym2
, &file_symbols
);
1664 /* in case we can't figure out the type, default is `int'. */
1665 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
1667 switch (cs
->c_sclass
)
1671 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1672 add_stab_to_list (name
, &global_stabs
);
1674 add_stab_to_list (name
, &file_stabs
);
1678 case C_DECL
: /* a type decleration?? */
1680 #if defined(NO_TYPEDEFS) || defined(NO_DEFINE_SYMBOL)
1681 qq
= (char*) strchr (name
, ':');
1682 if (!qq
) /* skip if there is no ':' */
1685 nameless
= (qq
== name
);
1687 struct_and_type_combined
= (qq
[1] == 'T' && qq
[2] == 't');
1688 pp
= qq
+ (struct_and_type_combined
? 3 : 2);
1691 /* To handle GNU C++ typename abbreviation, we need to be able to fill
1692 in a type's name as soon as space for that type is allocated. */
1694 if (struct_and_type_combined
&& name
!= qq
) {
1697 struct type
*tmp_type
;
1700 read_type_number (&tmp_pp
, typenums
);
1701 tmp_type
= dbx_alloc_type (typenums
, objfile
);
1703 if (tmp_type
&& !TYPE_NAME (tmp_type
) && !nameless
)
1704 TYPE_NAME (tmp_type
) = SYMBOL_NAME (sym
) =
1705 obsavestring (name
, qq
-name
,
1706 &objfile
->symbol_obstack
);
1708 ttype
= SYMBOL_TYPE (sym
) = read_type (&pp
);
1710 /* if there is no name for this typedef, you don't have to keep its
1711 symbol, since nobody could ask for it. Otherwise, build a symbol
1712 and add it into symbol_list. */
1718 /* Transarc wants to eliminate type definitions from the symbol table.
1719 Limited debugging capabilities, but faster symbol table processing
1720 and less memory usage. Note that tag definitions (starting with
1721 'T') will remain intact. */
1723 if (qq
[1] != 'T' && (!TYPE_NAME (ttype
) || *(TYPE_NAME (ttype
)) == '\0')) {
1725 if (SYMBOL_NAME (sym
))
1726 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
1728 TYPE_NAME (ttype
) = obsavestring (name
, qq
-name
);
1733 #endif /* !NO_TYPEDEFS */
1735 /* read_type() will return null if type (or tag) definition was
1736 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
1737 there is no need to keep it in symbol table. */
1738 /* The above argument no longer valid. read_type() never returns NULL. */
1743 /* if there is no name for this typedef, you don't have to keep its
1744 symbol, since nobody could ask for it. Otherwise, build a symbol
1745 and add it into symbol_list. */
1748 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1749 else if (qq
[1] == 't')
1750 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1752 warning ("Unrecognized stab string.\n");
1756 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1757 if (!SYMBOL_NAME (sym
))
1758 SYMBOL_NAME (sym
) = obsavestring (name
, qq
-name
);
1760 SYMBOL_DUP (sym
, sym2
);
1762 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1764 /* For a combination of struct and type, add one more symbol
1767 if (struct_and_type_combined
) {
1768 SYMBOL_DUP (sym
, sym2
);
1769 SYMBOL_NAMESPACE (sym2
) = VAR_NAMESPACE
;
1771 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1774 /* assign a name to the type node. */
1776 if (!TYPE_NAME (ttype
) || *(TYPE_NAME (ttype
)) == '\0') {
1777 if (struct_and_type_combined
)
1778 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
1779 else if (qq
[1] == 'T') /* struct namespace */
1780 TYPE_NAME (ttype
) = concat (
1781 TYPE_CODE (ttype
) == TYPE_CODE_UNION
? "union " :
1782 TYPE_CODE (ttype
) == TYPE_CODE_STRUCT
? "struct " : "enum ",
1783 SYMBOL_NAME (sym
), NULL
);
1787 #else /* !NO_DEFINE_SYMBOL */
1788 return define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1792 add_stab_to_list (name
, &global_stabs
);
1798 #ifdef NO_DEFINE_SYMBOL
1799 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1801 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1802 SYMBOL_CLASS (sym
) = (cs
->c_sclass
== C_PSYM
) ? LOC_ARG
: LOC_REGPARM
;
1804 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1805 SYMBOL_DUP (sym
, sym2
);
1806 add_symbol_to_list (sym2
, &local_symbols
);
1809 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1810 SYMBOL_CLASS (sym
) = (cs
->c_sclass
== C_PSYM
) ? LOC_ARG
: LOC_REGPARM
;
1816 #ifdef NO_DEFINE_SYMBOL
1817 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1819 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1820 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1821 SYMBOL_VALUE (sym
) += static_block_base
;
1823 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1824 SYMBOL_DUP (sym
, sym2
);
1826 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1829 /* If we are going to use Sun dbx's define_symbol(), we need to
1830 massage our stab string a little. Change 'V' type to 'S' to be
1831 comparible with Sun. */
1833 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
1837 if (*pp
== 'V') *pp
= 'S';
1838 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1839 SYMBOL_VALUE (sym
) += static_block_base
;
1844 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1846 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1847 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1849 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1850 SYMBOL_DUP (sym
, sym2
);
1851 add_symbol_to_list (sym2
, &local_symbols
);
1855 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1856 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1857 SYMBOL_DUP (sym
, sym2
);
1858 add_symbol_to_list (sym2
, &local_symbols
);
1862 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1863 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1864 SYMBOL_DUP (sym
, sym2
);
1865 add_symbol_to_list (sym2
, &global_symbols
);
1869 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1870 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1871 SYMBOL_DUP (sym
, sym2
);
1873 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1877 printf ("ERROR! C_REG is not fully implemented!\n");
1878 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1879 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1880 SYMBOL_DUP (sym
, sym2
);
1881 add_symbol_to_list (sym2
, &local_symbols
);
1886 #ifdef NO_DEFINE_SYMBOL
1887 pp
= (char*) strchr (name
, ':');
1888 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1889 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (cs
->c_value
);
1891 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1894 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1897 /* else this is not a stab entry, suppose the type is either
1898 `int' or `float', depending on the register class. */
1900 SYMBOL_TYPE (sym
) = (SYMBOL_VALUE (sym
) < 32)
1901 ? lookup_fundamental_type (objfile
, FT_INTEGER
)
1902 : lookup_fundamental_type (objfile
, FT_FLOAT
);
1904 SYMBOL_DUP (sym
, sym2
);
1905 add_symbol_to_list (sym2
, &local_symbols
);
1909 sym
= define_symbol (cs
->c_value
, cs
->c_name
, 0, 0, objfile
);
1913 warning ("A non-stab C_RSYM needs special handling.");
1919 warning ("Unexpected storage class: %d.", cs
->c_sclass
);
1928 read_symbol_nvalue (symtable
, symno
)
1932 struct internal_syment symbol
[1];
1934 bfd_coff_swap_sym_in (symfile_bfd
, symtable
+ (symno
*local_symesz
), symbol
);
1935 return symbol
->n_value
;
1940 read_symbol_lineno (symtable
, symno
)
1944 struct internal_syment symbol
[1];
1945 union internal_auxent main_aux
[1];
1949 for (ii
= 0; ii
< 50; ii
++) {
1950 bfd_coff_swap_sym_in (symfile_bfd
,
1951 symtable
+ (symno
*local_symesz
), symbol
);
1952 if (symbol
->n_sclass
== C_FCN
&& 0 == strcmp (symbol
->n_name
, ".bf"))
1954 symno
+= symbol
->n_numaux
+1;
1957 printf ("GDB Error: `.bf' not found.\n");
1961 /* take aux entry and return its lineno */
1963 bfd_coff_swap_aux_in (symfile_bfd
, symtable
+(symno
*local_symesz
),
1964 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
1966 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1969 /* Support for line number handling */
1971 /* This function is called for every section; it finds the outer limits
1972 * of the line table (minimum and maximum file offset) so that the
1973 * mainline code can read the whole thing for efficiency.
1976 find_linenos(abfd
, asect
, vpinfo
)
1981 struct coff_symfile_info
*info
;
1983 file_ptr offset
, maxoff
;
1985 count
= asect
->lineno_count
;
1987 if (strcmp (asect
->name
, ".text") || count
== 0)
1990 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1991 info
= (struct coff_symfile_info
*)vpinfo
;
1992 offset
= asect
->line_filepos
;
1993 maxoff
= offset
+ size
;
1995 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1996 info
->min_lineno_offset
= offset
;
1998 if (maxoff
> info
->max_lineno_offset
)
1999 info
->max_lineno_offset
= maxoff
;
2003 /* Read in all the line numbers for fast lookups later. Leave them in
2004 external (unswapped) format in memory; we'll swap them as we enter
2005 them into GDB's data structures. */
2008 init_lineno (abfd
, offset
, size
)
2015 if (bfd_seek(abfd
, offset
, 0) < 0)
2018 linetab
= (char *) xmalloc(size
);
2020 val
= bfd_read(linetab
, 1, size
, abfd
);
2024 linetab_offset
= offset
;
2025 linetab_size
= size
;
2026 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
2030 /* dbx allows the text of a symbol name to be continued into the
2031 next symbol name! When such a continuation is encountered
2032 (a \ at the end of the text of a name)
2033 call this function to get the continuation. */
2034 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
2037 #undef next_symbol_text
2038 #define next_symbol_text() \
2039 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
2042 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
2043 the proper type node fora given builtin type #. */
2052 printf ("ERROR!, unknown built-in type!\n");
2056 read_type_number (pp
, typenums
);
2058 /* default types are defined in dbxstclass.h. */
2059 switch ( typenums
[1] ) {
2061 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2063 return lookup_fundamental_type (current_objfile
, FT_CHAR
);
2065 return lookup_fundamental_type (current_objfile
, FT_SHORT
);
2067 return lookup_fundamental_type (current_objfile
, FT_LONG
);
2069 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2071 return lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2073 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2075 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2077 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2079 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2081 return lookup_fundamental_type (current_objfile
, FT_VOID
);
2083 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2085 return lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2087 return lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2089 /* requires a builtin `integer' */
2090 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2092 return lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2094 /* requires builtin `short real' */
2095 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2097 /* requires builtin `real' */
2098 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2100 printf ("ERROR! Unknown builtin type -%d\n", typenums
[1]);
2106 xcoff_new_init (objfile
)
2107 struct objfile
*objfile
;
2112 xcoff_symfile_init (objfile
)
2113 struct objfile
*objfile
;
2115 bfd
*abfd
= objfile
->obfd
;
2117 /* Allocate struct to keep track of the symfile */
2118 objfile
-> sym_private
= xmmalloc (objfile
-> md
,
2119 sizeof (struct coff_symfile_info
));
2120 init_entry_point_info (objfile
);
2123 /* Perform any local cleanups required when we are done with a particular
2124 objfile. I.E, we are in the process of discarding all symbol information
2125 for an objfile, freeing up all memory held for it, and unlinking the
2126 objfile struct from the global list of known objfiles. */
2129 xcoff_symfile_finish (objfile
)
2130 struct objfile
*objfile
;
2132 if (objfile
-> sym_private
!= NULL
)
2134 mfree (objfile
-> md
, objfile
-> sym_private
);
2137 /* Start with a fresh include table for the next objfile. */
2144 inclIndx
= inclLength
= inclDepth
= 0;
2149 init_stringtab(abfd
, offset
, objfile
)
2152 struct objfile
*objfile
;
2156 unsigned char lengthbuf
[4];
2158 if (bfd_seek(abfd
, offset
, 0) < 0)
2161 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
2162 length
= bfd_h_get_32(abfd
, lengthbuf
);
2164 /* If no string table is needed, then the file may end immediately
2165 after the symbols. Just return with `strtbl' set to null. */
2167 if (val
!= sizeof length
|| length
< sizeof length
)
2170 /* Allocate string table from symbol_obstack. We will need this table
2171 as long as we have its symbol table around. */
2173 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
2177 bcopy(&length
, strtbl
, sizeof length
);
2178 if (length
== sizeof length
)
2181 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
2183 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
2190 init_debugsection(abfd
)
2193 register sec_ptr secp
;
2194 bfd_size_type length
;
2201 secp
= bfd_get_section_by_name(abfd
, ".debug");
2205 if (!(length
= bfd_section_size(abfd
, secp
)))
2208 debugsec
= (char *) xmalloc ((unsigned)length
);
2209 if (debugsec
== NULL
)
2212 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
2213 printf ("Can't read .debug section from symbol file\n");
2228 /* xcoff version of symbol file read. */
2231 xcoff_symfile_read (objfile
, section_offset
, mainline
)
2232 struct objfile
*objfile
;
2233 struct section_offset
*section_offset
;
2236 int num_symbols
; /* # of symbols */
2237 int symtab_offset
; /* symbol table and */
2238 int stringtab_offset
; /* string table file offsets */
2241 struct coff_symfile_info
*info
;
2244 info
= (struct coff_symfile_info
*) objfile
-> sym_private
;
2245 symfile_bfd
= abfd
= objfile
->obfd
;
2246 name
= objfile
->name
;
2248 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2249 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2250 stringtab_offset
= symtab_offset
+
2251 num_symbols
* coff_data(abfd
)->local_symesz
;
2253 info
->min_lineno_offset
= 0;
2254 info
->max_lineno_offset
= 0;
2255 bfd_map_over_sections (abfd
, find_linenos
, info
);
2257 /* FIXME! This stuff should move into symfile_init */
2258 if (info
->min_lineno_offset
!= 0
2259 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
2261 /* only read in the line # table if one exists */
2262 val
= init_lineno(abfd
, info
->min_lineno_offset
,
2263 info
->max_lineno_offset
- info
->min_lineno_offset
);
2266 error("\"%s\": error reading line numbers\n", name
);
2269 val
= init_stringtab(abfd
, stringtab_offset
, objfile
);
2271 error ("\"%s\": can't get string table", name
);
2274 if (init_debugsection(abfd
) < 0) {
2275 error ("Error reading .debug section of `%s'\n", name
);
2278 /* Position to read the symbol table. Do not read it all at once. */
2279 val
= bfd_seek(abfd
, (long)symtab_offset
, 0);
2281 perror_with_name(name
);
2283 if (bfd_tell(abfd
) != symtab_offset
)
2286 init_minimal_symbol_collection ();
2287 make_cleanup (discard_minimal_symbols
, 0);
2289 /* Initialize load info structure. */
2291 xcoff_init_loadinfo ();
2293 /* Now that the executable file is positioned at symbol table,
2294 process it and define symbols accordingly. */
2296 read_xcoff_symtab(objfile
, num_symbols
);
2298 /* Free debug section. */
2299 free_debugsection ();
2301 /* Sort symbols alphabetically within each block. */
2304 /* Install any minimal symbols that have been collected as the current
2305 minimal symbols for this objfile. */
2307 install_minimal_symbols (objfile
);
2309 /* Make a default for file to list. */
2310 select_source_symtab (0);
2313 /* XCOFF-specific parsing routine for section offsets.
2314 Plain and simple for now. */
2317 struct section_offsets
*
2318 xcoff_symfile_offsets (objfile
, addr
)
2319 struct objfile
*objfile
;
2322 struct section_offsets
*section_offsets
;
2325 section_offsets
= (struct section_offsets
*)
2326 obstack_alloc (&objfile
-> psymbol_obstack
,
2327 sizeof (struct section_offsets
) +
2328 sizeof (section_offsets
->offsets
) * (SECT_OFF_MAX
-1));
2330 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
2331 ANOFFSET (section_offsets
, i
) = addr
;
2333 return section_offsets
;
2335 /* Register our ability to parse symbols for xcoff BFD files. */
2337 static struct sym_fns xcoff_sym_fns
=
2339 "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */
2340 15, /* sym_namelen: number of significant sym_name chars */
2341 xcoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2342 xcoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
2343 xcoff_symfile_read
, /* sym_read: read a symbol file into symtab */
2344 xcoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
2345 xcoff_symfile_offsets
, /* sym_offsets: xlate offsets ext->int form */
2346 NULL
/* next: pointer to next struct sym_fns */
2350 _initialize_xcoffread ()
2352 add_symtab_fns(&xcoff_sym_fns
);
2355 #else /* IBM6000_HOST */
2357 builtin_type (ignore
)
2360 fatal ("GDB internal error: builtin_type called on non-RS/6000!");
2362 #endif /* IBM6000_HOST */