1 /* Read AIXcoff symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3 Derived from coffread.c, dbxread.c, and a lot of hacking.
4 Contributed by IBM Corporation.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* Native only: Need struct tbtable in <sys/debug.h>. */
29 /* AIX COFF names have a preceeding dot `.' */
30 #define NAMES_HAVE_DOT 1
32 #include <sys/types.h>
37 #include <sys/param.h>
42 /*#include <linenum.h>*/
43 #include <sys/debug.h>
50 #include "coff/internal.h" /* FIXME, internal data from BFD */
51 #include "libcoff.h" /* FIXME, internal data from BFD */
52 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
54 /* Simplified internal version of coff symbol table information */
58 int c_symnum
; /* symbol number of this entry */
59 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
66 /* The COFF line table, in raw form. */
67 static char *linetab
= NULL
; /* Its actual contents */
68 static long linetab_offset
; /* Its offset in the file */
69 static unsigned long linetab_size
; /* Its size */
71 /* last function's saved coff symbol `cs' */
73 static struct coff_symbol fcn_cs_saved
;
75 static bfd
*symfile_bfd
;
77 /* Core address of start and end of text of current source file.
78 This is calculated from the first function seen after a C_FILE
82 static CORE_ADDR cur_src_end_addr
;
84 /* Core address of the end of the first object file. */
86 static CORE_ADDR first_object_file_end
;
88 /* pointer to the string table */
91 /* length of the string table */
92 static int strtbl_len
;
94 /* pointer to debug section */
95 static char *debugsec
;
97 /* pointer to the a.out symbol table */
100 /* initial symbol-table-debug-string vector length */
102 #define INITIAL_STABVECTOR_LENGTH 40
104 struct pending_stabs
*global_stabs
;
107 /* Nonzero if within a function (so symbols should be local,
108 if nothing says specifically). */
112 /* Local variables that hold the shift and mask values for the
113 COFF file that we are currently reading. These come back to us
114 from BFD, and are referenced by their macro names, as well as
115 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
116 macros from ../internalcoff.h . */
118 static unsigned local_n_btshft
;
119 static unsigned local_n_tmask
;
122 #define N_BTSHFT local_n_btshft
124 #define N_TMASK local_n_tmask
126 /* Local variables that hold the sizes in the file of various COFF structures.
127 (We only need to know this to read them from the file -- BFD will then
128 translate the data in them, into `internal_xxx' structs in the right
129 byte order, alignment, etc.) */
131 static unsigned local_symesz
;
134 /* coff_symfile_init()
135 is the coff-specific initialization routine for reading symbols.
136 It is passed a struct sym_fns which contains, among other things,
137 the BFD for the file whose symbols are being read, and a slot for
138 a pointer to "private data" which we fill with cookies and other
139 treats for coff_symfile_read().
141 We will only be called if this is a COFF or COFF-like file.
142 BFD handles figuring out the format of the file, and code in symtab.c
143 uses BFD's determination to vector to us.
145 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
147 struct coff_symfile_info
{
148 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
149 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
154 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
155 CORE_ADDR
, CORE_ADDR
, unsigned *));
158 aixcoff_symfile_read
PARAMS ((struct sym_fns
*, CORE_ADDR
, int));
161 free_debugsection
PARAMS ((void));
164 init_debugsection
PARAMS ((bfd
*));
167 init_stringtab
PARAMS ((bfd
*, long, struct objfile
*));
170 aixcoff_symfile_init
PARAMS ((struct sym_fns
*));
173 aixcoff_new_init
PARAMS ((void));
176 init_lineno
PARAMS ((bfd
*, long, int));
179 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
182 read_symbol_lineno
PARAMS ((char *, int));
185 read_symbol_nvalue
PARAMS ((char *, int));
187 static struct symbol
*
188 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
191 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
194 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
197 sort_syms
PARAMS ((void));
200 compare_symbols
PARAMS ((const void *, const void *));
202 /* Call sort_syms to sort alphabetically
203 the symbols of each block of each symtab. */
206 compare_symbols (s1p
, s2p
)
210 /* Names that are less should come first. */
211 register struct symbol
**s1
= (struct symbol
**) s1p
;
212 register struct symbol
**s2
= (struct symbol
**) s2p
;
213 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
217 /* For symbols of the same name, registers should come first. */
218 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
219 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
223 /* Sort a vector of symbols by their value. */
228 register struct symtab
*s
;
229 register struct objfile
*objfile
;
231 register struct blockvector
*bv
;
232 register struct block
*b
;
234 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
236 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
238 bv
= BLOCKVECTOR (s
);
239 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
240 for (i
= 0; i
< nbl
; i
++)
242 b
= BLOCKVECTOR_BLOCK (bv
, i
);
243 if (BLOCK_SHOULD_SORT (b
))
245 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
246 sizeof (struct symbol
*), compare_symbols
);
254 /* add a given stab string into given stab vector. */
257 add_stab_to_list (stabname
, stabvector
)
259 struct pending_stabs
**stabvector
;
261 if ( *stabvector
== NULL
) {
262 *stabvector
= (struct pending_stabs
*)
263 xmalloc (sizeof (struct pending_stabs
) +
264 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
265 (*stabvector
)->count
= 0;
266 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
268 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
269 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
270 *stabvector
= (struct pending_stabs
*)
271 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
272 (*stabvector
)->length
* sizeof (char*));
274 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
279 /* for all the stabs in a given stab vector, build appropriate types
280 and fix their symbols in given symbol vector. */
283 patch_block_stabs (symbols
, stabs
)
284 struct pending
*symbols
;
285 struct pending_stabs
*stabs
;
292 /* for all the stab entries, find their corresponding symbols and
293 patch their types! */
295 for (ii
=0; ii
< stabs
->count
; ++ii
) {
296 char *name
= stabs
->stab
[ii
];
297 char *pp
= (char*) index (name
, ':');
298 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
301 /* printf ("ERROR! stab symbol not found!\n"); /* FIXME */
302 /* The above is a false alarm. There are cases the we can have
303 a stab, without its symbol. xlc generates this for the extern
304 definitions in inner blocks. */
309 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
310 SYMBOL_TYPE (sym
) = lookup_function_type (read_type (&pp
));
312 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
319 /* compare line table entry addresses. */
322 compare_lte (lte1
, lte2
)
323 struct linetable_entry
*lte1
, *lte2
;
325 return lte1
->pc
- lte2
->pc
;
328 /* Give a line table with function entries are marked, arrange its functions
329 in assending order and strip off function entry markers and return it in
330 a newly created table. If the old one is good enough, return the old one. */
332 static struct linetable
*
333 arrange_linetable (oldLineTb
)
334 struct linetable
*oldLineTb
; /* old linetable */
337 newline
, /* new line count */
338 function_count
; /* # of functions */
340 struct linetable_entry
*fentry
; /* function entry vector */
341 int fentry_size
; /* # of function entries */
342 struct linetable
*newLineTb
; /* new line table */
344 #define NUM_OF_FUNCTIONS 20
346 fentry_size
= NUM_OF_FUNCTIONS
;
347 fentry
= (struct linetable_entry
*)
348 malloc (fentry_size
* sizeof (struct linetable_entry
));
350 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
352 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
354 if (function_count
>= fentry_size
) { /* make sure you have room. */
356 fentry
= (struct linetable_entry
*)
357 realloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
359 fentry
[function_count
].line
= ii
;
360 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
365 if (function_count
== 0) {
369 else if (function_count
> 1)
370 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
372 /* allocate a new line table. */
373 newLineTb
= (struct linetable
*) malloc (sizeof (struct linetable
) +
374 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
376 /* if line table does not start with a function beginning, copy up until
380 if (oldLineTb
->item
[0].line
!= 0)
382 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
383 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
385 /* Now copy function lines one by one. */
387 for (ii
=0; ii
< function_count
; ++ii
) {
388 for (jj
= fentry
[ii
].line
+ 1;
389 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
391 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
394 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
400 /* We try to detect the beginning of a compilation unit. That info will
401 be used as an entry in line number recording routines (enter_line_range) */
403 static unsigned first_fun_line_offset
;
404 static unsigned first_fun_bf
;
406 #define mark_first_line(OFFSET, SYMNUM) \
407 if (!first_fun_line_offset) { \
408 first_fun_line_offset = OFFSET; \
409 first_fun_bf = SYMNUM; \
413 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
414 following `IncludeChain'. At the end of each symtab (end_symtab),
415 we will determine if we should create additional symtab's to
416 represent if (the include files. */
419 typedef struct _inclTable
{
420 char *name
; /* include filename */
421 int begin
, end
; /* offsets to the line table */
422 struct subfile
*subfile
;
423 unsigned funStartLine
; /* start line # of its function */
426 #define INITIAL_INCLUDE_TABLE_LENGTH 20
427 static InclTable
*inclTable
; /* global include table */
428 static int inclIndx
; /* last entry to table */
429 static int inclLength
; /* table length */
430 static int inclDepth
; /* nested include depth */
434 record_include_begin (cs
)
435 struct coff_symbol
*cs
;
437 /* In aixcoff, we assume include files cannot be nested (not in .c files
438 of course, but in corresponding .s files.) */
441 fatal ("aix internal: pending include file exists.");
445 /* allocate an include file, or make room for the new entry */
446 if (inclLength
== 0) {
447 inclTable
= (InclTable
*)
448 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
449 bzero (inclTable
, sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
450 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
453 else if (inclIndx
>= inclLength
) {
454 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
455 inclTable
= (InclTable
*)
456 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
457 bzero (inclTable
+inclLength
-INITIAL_INCLUDE_TABLE_LENGTH
,
458 sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
461 inclTable
[inclIndx
].name
= cs
->c_name
;
462 inclTable
[inclIndx
].begin
= cs
->c_value
;
467 record_include_end (cs
)
468 struct coff_symbol
*cs
;
473 fatal ("aix internal: Mismatch C_BINCL/C_EINCL pair found.");
475 pTbl
= &inclTable
[inclIndx
];
476 pTbl
->end
= cs
->c_value
;
487 if (inclTable
&& inclLength
)
488 for (ii
=0; ii
< inclIndx
; ++ii
)
489 printf ("name: %s, begin: 0x%x, end: 0x%x\n",
490 inclTable
[ii
].name
, inclTable
[ii
].begin
, inclTable
[ii
].end
);
494 /* given the start and end addresses of a compilation unit (or a csect, at times)
495 process its lines and create appropriate line vectors. */
498 process_linenos (start
, end
)
499 CORE_ADDR start
, end
;
504 struct subfile main_subfile
; /* subfile structure for the main
507 /* in the main source file, any time we see a function entry, we reset
508 this variable to function's absolute starting line number. All the
509 following line numbers in the function are relative to this, and
510 we record absolute line numbers in record_line(). */
512 int main_source_baseline
= 0;
518 if (!(offset
= first_fun_line_offset
))
519 goto return_after_cleanup
;
521 bzero (&main_subfile
, sizeof (main_subfile
));
522 first_fun_line_offset
= 0;
525 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
526 &main_source_baseline
);
528 /* else, there was source with line numbers in include files */
531 main_source_baseline
= 0;
532 for (ii
=0; ii
< inclIndx
; ++ii
) {
534 struct subfile
*tmpSubfile
;
536 /* if there is main file source before include file, enter it. */
537 if (offset
< inclTable
[ii
].begin
) {
539 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
, start
, 0,
540 &main_source_baseline
);
543 /* Have a new subfile for the include file */
545 tmpSubfile
= inclTable
[ii
].subfile
= (struct subfile
*)
546 xmalloc (sizeof (struct subfile
));
548 bzero (tmpSubfile
, sizeof (struct subfile
));
549 firstLine
= &(inclTable
[ii
].funStartLine
);
551 /* enter include file's lines now. */
552 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
553 inclTable
[ii
].end
, start
, 0, firstLine
);
555 offset
= inclTable
[ii
].end
+ LINESZ
;
558 /* all the include files' line have been processed at this point. Now,
559 enter remaining lines of the main file, if any left. */
560 if (offset
< (linetab_offset
+ linetab_size
+ 1 - LINESZ
)) {
561 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
562 &main_source_baseline
);
566 /* Process main file's line numbers. */
567 if (main_subfile
.line_vector
) {
568 struct linetable
*lineTb
, *lv
;
570 lv
= main_subfile
.line_vector
;
572 /* Line numbers are not necessarily ordered. xlc compilation will
573 put static function to the end. */
575 lineTb
= arrange_linetable (lv
);
577 current_subfile
->line_vector
= (struct linetable
*)
578 xrealloc (lv
, (sizeof (struct linetable
)
579 + lv
->nitems
* sizeof (struct linetable_entry
)));
584 current_subfile
->line_vector
= lineTb
;
587 current_subfile
->line_vector_length
=
588 current_subfile
->line_vector
->nitems
;
591 /* Now, process included files' line numbers. */
593 for (ii
=0; ii
< inclIndx
; ++ii
) {
595 if ( (inclTable
[ii
].subfile
)->line_vector
) { /* Useless if!!! FIXMEmgo */
596 struct linetable
*lineTb
, *lv
;
598 lv
= (inclTable
[ii
].subfile
)->line_vector
;
600 /* Line numbers are not necessarily ordered. xlc compilation will
601 put static function to the end. */
603 lineTb
= arrange_linetable (lv
);
607 /* For the same include file, we might want to have more than one subfile.
608 This happens if we have something like:
616 while foo.h including code in it. (stupid but possible)
617 Since start_subfile() looks at the name and uses an existing one if finds,
618 we need to provide a fake name and fool it. */
620 /* start_subfile (inclTable[ii].name, (char*)0); */
621 start_subfile (" ?", (char*)0);
622 current_subfile
->name
=
623 obsavestring (inclTable
[ii
].name
, strlen (inclTable
[ii
].name
),
624 ¤t_objfile
->symbol_obstack
);
627 current_subfile
->line_vector
= (struct linetable
*)
628 xrealloc (lv
, (sizeof (struct linetable
)
629 + lv
->nitems
* sizeof (struct linetable_entry
)));
634 current_subfile
->line_vector
= lineTb
;
637 current_subfile
->line_vector_length
=
638 current_subfile
->line_vector
->nitems
;
639 start_subfile (pop_subfile (), (char*)0);
644 /* I am not sure this logic is correct. There might be no lines in the
645 main file, whereas there are some in included ones. FIXMEibm */
646 current_subfile
->line_vector
= NULL
;
648 return_after_cleanup
:
650 /* We don't want to keep alloc/free'ing the global include file table. */
653 /* start with a fresh subfile structure for the next file. */
654 bzero (&main_subfile
, sizeof (struct subfile
));
658 aix_process_linenos ()
660 /* process line numbers and enter them into line vector */
661 process_linenos (last_source_start_addr
, cur_src_end_addr
);
665 /* Enter a given range of lines into the line vector.
666 can be called in the following two ways:
667 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
668 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine) */
671 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
, firstLine
)
672 struct subfile
*subfile
;
673 unsigned beginoffset
, endoffset
; /* offsets to line table */
674 CORE_ADDR startaddr
, endaddr
;
680 /* Do Byte swapping, if needed. FIXME! */
681 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
682 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
683 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
685 pp
= &linetab
[beginoffset
- linetab_offset
];
686 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
687 : &linetab
[linetab_size
-1];
689 while (pp
<= limit
) {
691 /* find the address this line represents */
692 addr
= P_LINENO(pp
) ?
693 P_LINEADDR(pp
) : read_symbol_nvalue (symtbl
, P_LINESYM(pp
));
695 if (addr
< startaddr
|| (endaddr
&& addr
> endaddr
))
698 if (P_LINENO(pp
) == 0) {
699 *firstLine
= read_symbol_lineno (symtbl
, P_LINESYM(pp
));
700 record_line (subfile
, 0, addr
);
704 record_line (subfile
, *firstLine
+ P_LINENO(pp
), addr
);
711 int fsize
; /* file size */
712 int fixedparms
; /* number of fixed parms */
713 int floatparms
; /* number of float parms */
714 unsigned int parminfo
; /* parameter info.
715 See /usr/include/sys/debug.h
716 tbtable_ext.parminfo */
717 int framesize
; /* function frame size */
721 /* Given a function symbol, return its traceback information. */
724 retrieve_tracebackinfo (abfd
, textsec
, cs
)
727 struct coff_symbol
*cs
;
729 #define TBTABLE_BUFSIZ 2000
730 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
733 static TracebackInfo tbInfo
;
736 static char buffer
[TBTABLE_BUFSIZ
];
739 int bytesread
=0; /* total # of bytes read so far */
740 int bufferbytes
; /* number of bytes in the buffer */
742 int functionstart
= cs
->c_value
- textsec
->vma
;
744 bzero (&tbInfo
, sizeof (tbInfo
));
746 /* keep reading blocks of data from the text section, until finding a zero
747 word and a traceback table. */
749 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
750 (file_ptr
)(functionstart
+ bytesread
),
752 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
)) ?
753 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
))))
755 bytesread
+= bufferbytes
;
756 pinsn
= (int*) buffer
;
758 /* if this is the first time we filled the buffer, retrieve function
761 if (bytesread
== bufferbytes
) {
763 /* skip over unrelated instructions */
765 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
767 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
769 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
771 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
775 int tmp
= (*pinsn
>> 16) & 0xffff;
777 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
778 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
781 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
782 (tmp
== 0x9001)) /* st r0, NUM(r1) */
784 /* else, could not find a frame size. */
788 } while (++pinsn
&& *pinsn
);
790 if (!tbInfo
.framesize
)
794 /* look for a zero word. */
796 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
799 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
804 /* function size is the amount of bytes we have skipped so far. */
805 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
809 /* if we don't have the whole traceback table in the buffer, re-read
812 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
814 /* In case if we are *very* close to the end of the text section
815 and cannot read properly from that point on, abort by returning
817 Handle this case more graciously -- FIXME */
819 if (!bfd_get_section_contents (
820 abfd
, textsec
, buffer
,
821 (file_ptr
)(functionstart
+
822 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
823 { printf ("Abnormal return!..\n"); return NULL
; }
825 ptb
= (struct tbtable
*)buffer
;
828 ptb
= (struct tbtable
*)pinsn
;
830 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
831 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
832 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
840 /* Given a function symbol, return a pointer to its traceback table. */
843 retrieve_traceback (abfd
, textsec
, cs
, size
)
846 struct coff_symbol
*cs
;
847 int *size
; /* return function size */
849 #define TBTABLE_BUFSIZ 2000
850 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
853 static char buffer
[TBTABLE_BUFSIZ
];
856 int bytesread
=0; /* total # of bytes read so far */
857 int bufferbytes
; /* number of bytes in the buffer */
859 int functionstart
= cs
->c_value
- textsec
->filepos
+ textsec
->vma
;
862 /* keep reading blocks of data from the text section, until finding a zero
863 word and a traceback table. */
865 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
866 (file_ptr
)(functionstart
+ bytesread
),
868 (TBTABLE_BUFSIZ
< (textsec
->size
- functionstart
- bytesread
)) ?
869 TBTABLE_BUFSIZ
: (textsec
->size
- functionstart
- bytesread
))))
871 bytesread
+= bufferbytes
;
872 pinsn
= (int*) buffer
;
874 /* look for a zero word. */
876 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
879 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
884 /* function size is the amount of bytes we have skipped so far. */
885 *size
= bytesread
- (buffer
+ bufferbytes
- pinsn
);
889 /* if we don't have the whole traceback table in the buffer, re-read
892 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
894 /* In case if we are *very* close to the end of the text section
895 and cannot read properly from that point on, abort for now.
896 Handle this case more graciously -- FIXME */
898 if (!bfd_get_section_contents (
899 abfd
, textsec
, buffer
,
900 (file_ptr
)(functionstart
+
901 bytesread
- (buffer
+ bufferbytes
- pinsn
)),MIN_TBTABSIZ
))
902 /* abort (); */ { printf ("abort!!!\n"); return NULL
; }
904 return (struct tbtable
*)buffer
;
907 return (struct tbtable
*)pinsn
;
917 /* Save the vital information for use when closing off the current file.
918 NAME is the file name the symbols came from, START_ADDR is the first
919 text address for the file, and SIZE is the number of bytes of text. */
921 #define complete_symtab(name, start_addr) { \
922 last_source_file = savestring (name, strlen (name)); \
923 last_source_start_addr = start_addr; \
927 /* Refill the symbol table input buffer
928 and set the variables that control fetching entries from it.
929 Reports an error if no data available.
930 This function can read past the end of the symbol table
931 (into the string table) but this does no harm. */
933 /* Reading symbol table has to be fast! Keep the followings as macros, rather
936 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \
940 namestr = (NAME) + 1; \
942 namestr = obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
945 prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \
946 misc_func_recorded = 1; \
950 /* A parameter template, used by ADD_PARM_TO_PENDING. */
952 static struct symbol parmsym
= { /* default parameter symbol */
954 VAR_NAMESPACE
, /* namespace */
961 /* Add a parameter to a given pending symbol list. */
963 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
965 PARM = (struct symbol *) \
966 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
968 SYMBOL_TYPE (PARM) = PTYPE; \
969 SYMBOL_VALUE (PARM) = VALUE; \
970 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
974 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
975 nested. At any given time, a symbol can only be in one static block.
976 This is the base address of current static block, zero if non exists. */
978 static int static_block_base
= 0;
980 /* true if space for symbol name has been allocated. */
982 static int symname_alloced
= 0;
984 /* read the whole symbol table of a given bfd. */
987 read_xcoff_symtab (objfile
, nsyms
)
988 struct objfile
*objfile
; /* Object file we're reading from */
989 int nsyms
; /* # of symbols */
991 bfd
*abfd
= objfile
->obfd
;
992 char *raw_symbol
; /* Pointer into raw seething symbol table */
993 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
994 sec_ptr textsec
; /* Pointer to text section */
995 TracebackInfo
*ptb
; /* Pointer to traceback table */
997 struct internal_syment symbol
[1];
998 union internal_auxent main_aux
[1];
999 struct coff_symbol cs
[1];
1000 CORE_ADDR file_start_addr
= 0;
1001 CORE_ADDR file_end_addr
= 0;
1003 int next_file_symnum
= -1;
1004 int just_started
= 1;
1009 long fcn_line_offset
;
1012 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1013 union internal_auxent fcn_aux_saved
;
1014 struct type
*fcn_type_saved
= NULL
;
1015 struct context_stack
*new;
1017 char *filestring
= " _start_ "; /* Name of the current file. */
1019 char *last_csect_name
; /* last seen csect's name and value */
1020 CORE_ADDR last_csect_val
;
1021 int misc_func_recorded
; /* true if any misc. function */
1023 current_objfile
= objfile
;
1025 /* Get the appropriate COFF "constants" related to the file we're handling. */
1026 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
1027 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
1028 local_symesz
= coff_data (abfd
)->local_symesz
;
1030 last_source_file
= 0;
1031 last_csect_name
= 0;
1033 misc_func_recorded
= 0;
1035 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1037 first_object_file_end
= 0;
1039 /* Allocate space for the entire symbol table at once, and read it
1040 all in. The bfd is already positioned at the beginning of
1041 the symbol table. */
1043 size
= coff_data (abfd
)->local_symesz
* nsyms
;
1044 symtbl
= xmalloc (size
);
1046 val
= bfd_read (symtbl
, size
, 1, abfd
);
1048 perror_with_name ("reading symbol table");
1050 raw_symbol
= symtbl
;
1052 textsec
= bfd_get_section_by_name (abfd
, ".text");
1054 printf ("Unable to locate text section!\n");
1057 while (symnum
< nsyms
) {
1059 QUIT
; /* make this command interruptable. */
1061 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1062 /* read one symbol into `cs' structure. After processing the whole symbol
1063 table, only string table will be kept in memory, symbol table and debug
1064 section of aixcoff will be freed. Thus we can mark symbols with names
1065 in string table as `alloced'. */
1069 /* Swap and align the symbol into a reasonable C structure. */
1070 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1072 cs
->c_symnum
= symnum
;
1073 cs
->c_nsyms
= symbol
->n_numaux
;
1074 if (symbol
->n_zeroes
) {
1075 symname_alloced
= 0;
1076 /* We must use the original, unswapped, name here so the name field
1077 pointed to by cs->c_name will persist throughout xcoffread. If
1078 we use the new field, it gets overwritten for each symbol. */
1079 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1080 } else if (symbol
->n_sclass
& 0x80) {
1081 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1082 symname_alloced
= 0;
1083 } else { /* in string table */
1084 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1085 symname_alloced
= 1;
1087 cs
->c_value
= symbol
->n_value
;
1088 cs
->c_sclass
= symbol
->n_sclass
& 0xff;
1089 cs
->c_secnum
= symbol
->n_scnum
;
1090 cs
->c_type
= (unsigned)symbol
->n_type
;
1092 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1095 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
1097 /* Skip all the auxents associated with this symbol. */
1098 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
1099 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1104 /* if symbol name starts with ".$" or "$", ignore it. */
1105 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1108 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
1109 if (last_source_file
)
1110 end_symtab (cur_src_end_addr
, 1, 0, objfile
);
1112 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1113 cur_src_end_addr
= first_object_file_end
;
1114 /* done with all files, everything from here on is globals */
1117 /* if explicitly specified as a function, treat is as one. */
1118 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
1119 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1121 goto function_entry_point
;
1124 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
1126 /* dealing with a symbol with a csect entry. */
1128 # define CSECT(PP) ((PP)->x_csect)
1129 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1130 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1131 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1132 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1134 /* Convert the auxent to something we can access. */
1135 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1138 switch (CSECT_SMTYP (main_aux
)) {
1141 continue; /* ignore all external references. */
1143 case XTY_SD
: /* a section description. */
1145 switch (CSECT_SCLAS (main_aux
)) {
1147 case XMC_PR
: /* a `.text' csect. */
1150 /* A program csect is seen.
1152 We have to allocate one symbol table for each program csect. Normally
1153 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
1154 CU might include more than one prog csect, and they don't have to be
1155 adjacent in terms of the space they occupy in memory. Thus, one single
1156 CU might get fragmented in the memory and gdb's file start and end address
1157 approach does not work! */
1159 if (last_csect_name
) {
1161 /* if no misc. function recorded in the last seen csect, enter
1162 it as a function. This will take care of functions like
1163 strcmp() compiled by xlc. */
1165 if (!misc_func_recorded
) {
1167 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1172 complete_symtab (filestring
, file_start_addr
);
1173 cur_src_end_addr
= file_end_addr
;
1174 end_symtab (file_end_addr
, 1, 0, objfile
);
1175 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
1178 /* If this is the very first csect seen, basically `__start'. */
1180 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
1184 file_start_addr
= cs
->c_value
;
1185 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
1187 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
1188 last_csect_name
= cs
->c_name
;
1189 last_csect_val
= cs
->c_value
;
1192 misc_func_recorded
= 0;
1198 /* If the section is not a data description, ignore it. Note that
1199 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1202 #ifdef XCOFF_ADD_TOC_TO_LOADINFO
1203 XCOFF_ADD_TOC_TO_LOADINFO (cs
->c_value
);
1205 /* fall down to default case. */
1207 case XMC_TC
: /* ignore toc entries */
1208 default : /* any other XMC_XXX */
1212 break; /* switch CSECT_SCLAS() */
1216 /* a function entry point. */
1217 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
1219 function_entry_point
:
1220 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1223 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1224 fcn_start_addr
= cs
->c_value
;
1226 /* save the function header info, which will be used
1227 when `.bf' is seen. */
1229 fcn_aux_saved
= *main_aux
;
1234 /* If function has two auxent, then debugging information is
1235 already available for it. Process traceback table for
1236 functions with only one auxent. */
1238 if (cs
->c_nsyms
== 1)
1239 ptb
= retrieve_tracebackinfo (abfd
, textsec
, cs
);
1241 else if (cs
->c_nsyms
!= 2)
1244 /* If there is traceback info, create and add parameters for it. */
1246 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
)) {
1248 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1249 char *parmcode
= (char*) &ptb
->parminfo
;
1250 int parmvalue
= ptb
->framesize
+ 0x18; /* sizeof(LINK AREA) == 0x18 */
1251 unsigned int ii
, mask
;
1253 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
) {
1254 struct symbol
*parm
;
1256 if (ptb
->parminfo
& mask
) { /* float or double */
1258 if (ptb
->parminfo
& mask
) { /* double parm */
1260 (parm
, parmvalue
, builtin_type_double
, local_symbols
);
1261 parmvalue
+= sizeof (double);
1263 else { /* float parm */
1265 (parm
, parmvalue
, builtin_type_float
, local_symbols
);
1266 parmvalue
+= sizeof (float);
1269 else { /* fixed parm, use (int*) for hex rep. */
1270 ADD_PARM_TO_PENDING (parm
, parmvalue
,
1271 lookup_pointer_type (builtin_type_int
),
1273 parmvalue
+= sizeof (int);
1278 /* Fake this as a function. Needed in process_xcoff_symbol() */
1281 finish_block(process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1282 pending_blocks
, cs
->c_value
,
1283 cs
->c_value
+ ptb
->fsize
, objfile
);
1287 /* shared library function trampoline code entry point. */
1288 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
1289 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1295 default : /* all other XTY_XXXs */
1297 } /* switch CSECT_SMTYP() */ }
1299 switch (cs
->c_sclass
) {
1303 /* see if the last csect needs to be recorded. */
1305 if (last_csect_name
&& !misc_func_recorded
) {
1307 /* if no misc. function recorded in the last seen csect, enter
1308 it as a function. This will take care of functions like
1309 strcmp() compiled by xlc. */
1312 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1316 /* c_value field contains symnum of next .file entry in table
1317 or symnum of first global after last .file. */
1319 next_file_symnum
= cs
->c_value
;
1321 /* complete symbol table for last object file containing
1322 debugging information. */
1324 /* Whether or not there was a csect in the previous file, we have
1325 to call `end_symtab' and `start_symtab' to reset type_vector,
1326 line_vector, etc. structures. */
1328 complete_symtab (filestring
, file_start_addr
);
1329 cur_src_end_addr
= file_end_addr
;
1330 end_symtab (file_end_addr
, 1, 0, objfile
);
1331 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
1332 last_csect_name
= 0;
1334 /* reset file start and end addresses. A compilation unit with no text
1335 (only data) should have zero file boundaries. */
1336 file_start_addr
= file_end_addr
= 0;
1338 filestring
= cs
->c_name
;
1344 /* For a function stab, just save its type in `fcn_type_saved', and leave
1345 it for the `.bf' processing. */
1347 char *pp
= (char*) index (cs
->c_name
, ':');
1349 if (!pp
|| ( *(pp
+1) != 'F' && *(pp
+1) != 'f'))
1350 fatal ("Unrecognized stab");
1354 fatal ("Unprocessed function type");
1356 fcn_type_saved
= lookup_function_type (read_type (&pp
, objfile
));
1362 if (strcmp (cs
->c_name
, ".bf") == 0) {
1364 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1367 within_function
= 1;
1369 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
1370 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
1374 1) xlc (IBM's native c compiler) postpones static function code
1375 emission to the end of a compilation unit. This way it can
1376 determine if those functions (statics) are needed or not, and
1377 can do some garbage collection (I think). This makes line
1378 numbers and corresponding addresses unordered, and we end up
1379 with a line table like:
1396 and that breaks gdb's binary search on line numbers, if the
1397 above table is not sorted on line numbers. And that sort
1398 should be on function based, since gcc can emit line numbers
1401 10 0x100 - for the init/test part of a for stmt.
1404 10 0x400 - for the increment part of a for stmt.
1406 arrange_linenos() will do this sorting.
1409 2) aix symbol table might look like:
1411 c_file // beginning of a new file
1412 .bi // beginning of include file
1413 .ei // end of include file
1417 basically, .bi/.ei pairs do not necessarily encapsulate
1418 their scope. They need to be recorded, and processed later
1419 on when we come the end of the compilation unit.
1420 Include table (inclTable) and process_linenos() handle
1423 mark_first_line (fcn_line_offset
, cs
->c_symnum
);
1425 new = push_context (0, fcn_start_addr
);
1426 new->name
= process_xcoff_symbol (&fcn_cs_saved
, objfile
);
1428 /* Between a function symbol and `.bf', there always will be a function
1429 stab. We save function type when processing that stab. */
1431 if (fcn_type_saved
== NULL
) {
1432 printf ("Unknown function type: symbol 0x%x\n", cs
->c_symnum
);
1433 SYMBOL_TYPE (new->name
) = lookup_function_type (builtin_type_int
);
1436 SYMBOL_TYPE (new->name
) = fcn_type_saved
;
1437 fcn_type_saved
= NULL
;
1440 else if (strcmp (cs
->c_name
, ".ef") == 0) {
1442 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1445 /* the value of .ef is the address of epilogue code;
1446 not useful for gdb */
1447 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1448 contains number of lines to '}' */
1450 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1451 new = pop_context ();
1452 if (context_stack_depth
!= 0)
1453 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1456 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1458 fcn_cs_saved
.c_value
+
1459 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
1460 within_function
= 0;
1464 case C_BSTAT
: /* begin static block */
1465 static_block_base
= read_symbol_nvalue (symtbl
, cs
->c_value
);
1468 case C_ESTAT
: /* end of static block */
1469 static_block_base
= 0;
1472 case C_ARG
: /* These are not implemented. */
1478 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
1481 case C_HIDEXT
: /* ignore these.. */
1486 case C_BINCL
: /* beginning of include file */
1488 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1489 order. Thus, when wee see them, we might not know enough info
1490 to process them. Thus, we'll be saving them into a table
1491 (inclTable) and postpone their processing. */
1493 record_include_begin (cs
);
1496 case C_EINCL
: /* end of include file */
1497 /* see the comment after case C_BINCL. */
1498 record_include_end (cs
);
1502 if (strcmp (cs
->c_name
, ".bb") == 0) {
1504 new = push_context (depth
, cs
->c_value
);
1506 else if (strcmp (cs
->c_name
, ".eb") == 0) {
1507 new = pop_context ();
1508 if (depth
!= new->depth
)
1509 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1513 if (local_symbols
&& context_stack_depth
> 0) {
1514 /* Make a block for the local symbols within. */
1515 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1516 new->start_addr
, cs
->c_value
, objfile
);
1518 local_symbols
= new->locals
;
1523 (void) process_xcoff_symbol (cs
, objfile
);
1529 if (last_source_file
)
1530 end_symtab (cur_src_end_addr
, 1, 0, objfile
);
1533 current_objfile
= NULL
;
1536 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1537 (SYMBOL2) = (struct symbol *) \
1538 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1539 *(SYMBOL2) = *(SYMBOL1);
1542 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1543 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1546 /* process one xcoff symbol. */
1548 static struct symbol
*
1549 process_xcoff_symbol (cs
, objfile
)
1550 register struct coff_symbol
*cs
;
1551 struct objfile
*objfile
;
1553 struct symbol onesymbol
;
1554 register struct symbol
*sym
= &onesymbol
;
1555 struct symbol
*sym2
= NULL
;
1557 char *name
, *pp
, *qq
;
1558 int struct_and_type_combined
;
1565 bzero (sym
, sizeof (struct symbol
));
1567 /* default assumptions */
1568 SYMBOL_VALUE (sym
) = cs
->c_value
;
1569 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1571 if (ISFCN (cs
->c_type
)) {
1573 /* At this point, we don't know the type of the function and assume it
1574 is int. This will be patched with the type from its stab entry later
1575 on in patch_block_stabs () */
1577 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1578 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (objfile
, FT_INTEGER
));
1580 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1581 SYMBOL_DUP (sym
, sym2
);
1583 if (cs
->c_sclass
== C_EXT
)
1584 add_symbol_to_list (sym2
, &global_symbols
);
1585 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1586 add_symbol_to_list (sym2
, &file_symbols
);
1591 /* in case we can't figure out the type, default is `int'. */
1592 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
1594 switch (cs
->c_sclass
)
1598 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1599 add_stab_to_list (name
, &global_stabs
);
1601 add_stab_to_list (name
, &file_stabs
);
1605 case C_DECL
: /* a type decleration?? */
1606 qq
= (char*) strchr (name
, ':');
1607 if (!qq
) /* skip if there is no ':' */
1610 nameless
= (qq
== name
);
1612 struct_and_type_combined
= (qq
[1] == 'T' && qq
[2] == 't');
1613 pp
= qq
+ (struct_and_type_combined
? 3 : 2);
1616 /* To handle GNU C++ typename abbreviation, we need to be able to fill
1617 in a type's name as soon as space for that type is allocated. */
1619 if (struct_and_type_combined
&& name
!= qq
) {
1622 struct type
*tmp_type
;
1625 read_type_number (&tmp_pp
, typenums
);
1626 tmp_type
= dbx_alloc_type (typenums
);
1628 if (tmp_type
&& !TYPE_NAME (tmp_type
) && !nameless
)
1629 TYPE_NAME (tmp_type
) = SYMBOL_NAME (sym
) =
1630 obsavestring (name
, qq
-name
);
1632 ttype
= SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1634 /* read_type() will return null if type (or tag) definition was
1635 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
1636 there is no need to keep it in symbol table. */
1637 /* The above argument no longer valid. read_type() never returns NULL. */
1642 /* if there is no name for this typedef, you don't have to keep its
1643 symbol, since nobody could ask for it. Otherwise, build a symbol
1644 and add it into symbol_list. */
1648 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1649 else if (qq
[1] == 't')
1650 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1652 printf ("ERROR: Unrecognized stab string.\n");
1656 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1657 if (!SYMBOL_NAME (sym
))
1658 SYMBOL_NAME (sym
) = obsavestring (name
, qq
-name
,
1659 &objfile
->symbol_obstack
);
1661 SYMBOL_DUP (sym
, sym2
);
1663 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1665 /* For a combination of struct and type, add one more symbol
1668 if (struct_and_type_combined
) {
1669 SYMBOL_DUP (sym
, sym2
);
1670 SYMBOL_NAMESPACE (sym2
) = VAR_NAMESPACE
;
1672 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1676 /* assign a name to the type node. */
1678 if (!nameless
&& (!TYPE_NAME (ttype
) || *(TYPE_NAME (ttype
)) == '\0')) {
1679 if (struct_and_type_combined
)
1680 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
1682 /* else if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE) */
1683 else if (qq
[1] == 'T') /* struct namespace */
1684 TYPE_NAME (ttype
) = concat (
1685 TYPE_CODE (ttype
) == TYPE_CODE_UNION
? "union " :
1686 TYPE_CODE (ttype
) == TYPE_CODE_STRUCT
? "struct " : "enum ",
1687 SYMBOL_NAME (sym
), NULL
);
1693 add_stab_to_list (name
, &global_stabs
);
1698 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1700 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1701 SYMBOL_CLASS (sym
) = (cs
->c_sclass
== C_PSYM
) ? LOC_ARG
: LOC_REGPARM
;
1703 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1704 SYMBOL_DUP (sym
, sym2
);
1705 add_symbol_to_list (sym2
, &local_symbols
);
1709 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1711 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1712 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1713 SYMBOL_VALUE (sym
) += static_block_base
;
1715 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1716 SYMBOL_DUP (sym
, sym2
);
1718 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1722 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1724 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1725 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1727 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1728 SYMBOL_DUP (sym
, sym2
);
1729 add_symbol_to_list (sym2
, &local_symbols
);
1733 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1734 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1735 SYMBOL_DUP (sym
, sym2
);
1736 add_symbol_to_list (sym2
, &local_symbols
);
1740 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1741 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1742 SYMBOL_DUP (sym
, sym2
);
1743 add_symbol_to_list (sym2
, &global_symbols
);
1747 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1748 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1749 SYMBOL_DUP (sym
, sym2
);
1751 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1755 printf ("ERROR! C_REG is not fully implemented!\n");
1756 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1757 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1758 SYMBOL_DUP (sym
, sym2
);
1759 add_symbol_to_list (sym2
, &local_symbols
);
1763 pp
= (char*) strchr (name
, ':');
1764 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1765 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (cs
->c_value
);
1767 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1770 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1773 /* else this is not a stab entry, suppose the type is either
1774 `int' or `float', depending on the register class. */
1776 SYMBOL_TYPE (sym
) = (SYMBOL_VALUE (sym
) < 32)
1777 ? lookup_fundamental_type (objfile
, FT_INTEGER
)
1778 : lookup_fundamental_type (objfile
, FT_FLOAT
);
1780 SYMBOL_DUP (sym
, sym2
);
1781 add_symbol_to_list (sym2
, &local_symbols
);
1785 printf ("ERROR: Unexpected storage class: %d.\n", cs
->c_sclass
);
1794 read_symbol_nvalue (symtable
, symno
)
1798 struct internal_syment symbol
[1];
1800 bfd_coff_swap_sym_in (symfile_bfd
, symtable
+ (symno
*local_symesz
), symbol
);
1801 return symbol
->n_value
;
1806 read_symbol_lineno (symtable
, symno
)
1810 struct internal_syment symbol
[1];
1811 union internal_auxent main_aux
[1];
1815 for (ii
= 0; ii
< 50; ii
++) {
1816 bfd_coff_swap_sym_in (symfile_bfd
,
1817 symtable
+ (symno
*local_symesz
), symbol
);
1818 if (symbol
->n_sclass
== C_FCN
&& 0 == strcmp (symbol
->n_name
, ".bf"))
1820 symno
+= symbol
->n_numaux
+1;
1823 printf ("GDB Error: `.bf' not found.\n");
1827 /* take aux entry and return its lineno */
1829 bfd_coff_swap_aux_in (symfile_bfd
, symtable
+(symno
*local_symesz
),
1830 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
1832 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1835 /* Support for line number handling */
1837 /* This function is called for every section; it finds the outer limits
1838 * of the line table (minimum and maximum file offset) so that the
1839 * mainline code can read the whole thing for efficiency.
1842 find_linenos(abfd
, asect
, vpinfo
)
1847 struct coff_symfile_info
*info
;
1849 file_ptr offset
, maxoff
;
1851 count
= asect
->lineno_count
;
1853 if (strcmp (asect
->name
, ".text") || count
== 0)
1856 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1857 info
= (struct coff_symfile_info
*)vpinfo
;
1858 offset
= asect
->line_filepos
;
1859 maxoff
= offset
+ size
;
1861 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1862 info
->min_lineno_offset
= offset
;
1864 if (maxoff
> info
->max_lineno_offset
)
1865 info
->max_lineno_offset
= maxoff
;
1869 /* Read in all the line numbers for fast lookups later. Leave them in
1870 external (unswapped) format in memory; we'll swap them as we enter
1871 them into GDB's data structures. */
1874 init_lineno (abfd
, offset
, size
)
1881 if (bfd_seek(abfd
, offset
, 0) < 0)
1884 linetab
= (char *) xmalloc(size
);
1886 val
= bfd_read(linetab
, 1, size
, abfd
);
1890 linetab_offset
= offset
;
1891 linetab_size
= size
;
1892 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1896 /* dbx allows the text of a symbol name to be continued into the
1897 next symbol name! When such a continuation is encountered
1898 (a \ at the end of the text of a name)
1899 call this function to get the continuation. */
1900 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1903 #undef next_symbol_text
1904 #define next_symbol_text() \
1905 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1908 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
1909 the proper type node fora given builtin type #. */
1918 printf ("ERROR!, unknown built-in type!\n");
1922 read_type_number (pp
, typenums
);
1924 /* default types are defined in dbxstclass.h. */
1925 switch ( typenums
[1] ) {
1927 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1929 return lookup_fundamental_type (current_objfile
, FT_CHAR
);
1931 return lookup_fundamental_type (current_objfile
, FT_SHORT
);
1933 return lookup_fundamental_type (current_objfile
, FT_LONG
);
1935 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
1937 return lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
1939 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
1941 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1943 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1945 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
1947 return lookup_fundamental_type (current_objfile
, FT_VOID
);
1949 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1951 return lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
1953 return lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
1955 /* requires a builtin `integer' */
1956 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1958 return lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
1960 /* requires builtin `short real' */
1961 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1963 /* requires builtin `real' */
1964 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1966 printf ("ERROR! Unknown builtin type -%d\n", typenums
[1]);
1971 #if 0 /* Seems to be unused, don't bother converting from old misc function
1972 vector usage to new minimal symbol tables. FIXME: Delete this? */
1974 /* if we now nothing about a function but its address, make a function symbol
1975 out of it with the limited knowladge you have. This will be used when
1976 somebody refers to a function, which doesn't exist in the symbol table,
1977 but is in the minimal symbol table. */
1980 build_function_symbol (ind
, objfile
)
1982 struct objfile
*objfile
;
1984 struct symbol
*sym
=
1985 (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1986 SYMBOL_NAME (sym
) = misc_function_vector
[ind
].name
;
1987 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1988 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1989 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1990 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (current_objfile
, FT_INTEGER
));
1991 SYMBOL_BLOCK_VALUE (sym
) = (struct block
*)
1992 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct block
));
1993 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) = misc_function_vector
[ind
].address
;
2002 /* This routine is executed once per executable. We should start with a
2003 fresh include table per executable. */
2009 inclIndx
= inclLength
= inclDepth
= NULL
;
2013 aixcoff_symfile_init (sf
)
2016 bfd
*abfd
= sf
->sym_bfd
;
2018 /* Allocate struct to keep track of the symfile */
2019 /* FIXME memory leak */
2020 sf
->sym_private
= xmalloc(sizeof (struct coff_symfile_info
));
2023 * Save startup file's range of PC addresses to help
2024 * blockframe.c decide where the bottom of the stack is.
2026 if (bfd_get_file_flags(abfd
) & EXEC_P
) {
2027 entry_point
= bfd_get_start_address(abfd
);
2030 /* set the startup file to be an empty range. */
2031 startup_file_start
= 0;
2032 startup_file_end
= 0;
2038 init_stringtab(abfd
, offset
, objfile
)
2041 struct objfile
*objfile
;
2045 unsigned char lengthbuf
[4];
2047 if (bfd_seek(abfd
, offset
, 0) < 0)
2050 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
2051 length
= bfd_h_get_32(abfd
, lengthbuf
);
2053 /* If no string table is needed, then the file may end immediately
2054 after the symbols. Just return with `strtbl' set to null. */
2056 if (val
!= sizeof length
|| length
< sizeof length
)
2059 /* Allocate string table from symbol_obstack. We will need this table
2060 as long as we have its symbol table around. */
2062 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
2066 bcopy(&length
, strtbl
, sizeof length
);
2067 if (length
== sizeof length
)
2070 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
2072 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
2079 init_debugsection(abfd
)
2082 register sec_ptr secp
;
2083 bfd_size_type length
;
2090 secp
= bfd_get_section_by_name(abfd
, ".debug");
2094 if (!(length
= bfd_section_size(abfd
, secp
)))
2097 debugsec
= (char *) xmalloc ((unsigned)length
);
2098 if (debugsec
== NULL
)
2101 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
2102 printf ("Can't read .debug section from symbol file\n");
2117 /* aixcoff version of symbol file read. */
2120 aixcoff_symfile_read (sf
, addr
, mainline
)
2125 int num_symbols
; /* # of symbols */
2126 int symtab_offset
; /* symbol table and */
2127 int stringtab_offset
; /* string table file offsets */
2130 struct coff_symfile_info
*info
= (void*) sf
->sym_private
;
2133 symfile_bfd
= abfd
= sf
->objfile
->obfd
;
2134 name
= sf
->objfile
->name
;
2136 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2137 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2138 stringtab_offset
= symtab_offset
+
2139 num_symbols
* coff_data(abfd
)->local_symesz
;
2141 info
->min_lineno_offset
= 0;
2142 info
->max_lineno_offset
= 0;
2143 bfd_map_over_sections (abfd
, find_linenos
, info
);
2145 /* FIXME! This stuff should move into symfile_init */
2146 if (info
->min_lineno_offset
!= 0
2147 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
2149 /* only read in the line # table if one exists */
2150 val
= init_lineno(abfd
, info
->min_lineno_offset
,
2151 info
->max_lineno_offset
- info
->min_lineno_offset
);
2154 error("\"%s\": error reading line numbers\n", name
);
2157 val
= init_stringtab(abfd
, stringtab_offset
, sf
->objfile
);
2159 error ("\"%s\": can't get string table", name
);
2162 if (init_debugsection(abfd
) < 0) {
2163 error ("Error reading .debug section of `%s'\n", name
);
2166 /* Position to read the symbol table. Do not read it all at once. */
2167 val
= bfd_seek(abfd
, (long)symtab_offset
, 0);
2169 perror_with_name(name
);
2171 if (bfd_tell(abfd
) != symtab_offset
)
2174 init_minimal_symbol_collection ();
2175 make_cleanup (discard_minimal_symbols
, 0);
2177 #ifdef XCOFF_INIT_LOADINFO
2179 XCOFF_INIT_LOADINFO ();
2182 /* Now that the executable file is positioned at symbol table,
2183 process it and define symbols accordingly. */
2185 read_xcoff_symtab(sf
->objfile
, num_symbols
);
2187 make_cleanup (free_debugsection
, 0);
2189 /* Sort symbols alphabetically within each block. */
2192 /* Install any minimal symbols that have been collected as the current
2193 minimal symbols for this objfile. */
2195 install_minimal_symbols (sf
-> objfile
);
2197 /* Make a default for file to list. */
2198 select_source_symtab (0);
2201 /* Register our ability to parse symbols for aixcoff BFD files. */
2203 static struct sym_fns aixcoff_sym_fns
=
2205 "aixcoff-rs6000", 15,
2206 aixcoff_new_init
, aixcoff_symfile_init
,
2207 aixcoff_symfile_read
,
2211 _initialize_xcoffread ()
2213 add_symtab_fns(&aixcoff_sym_fns
);
2217 /* In order to handle forward type references, we needed to have this old
2218 routine. Try printing the type of member `p' in the following structure
2219 in a dbx environment.
2227 /* Smash TYPE to be a type of pointers to TO_TYPE.
2228 If TO_TYPE is not permanent and has no pointer-type yet,
2229 record TYPE as its pointer-type. */
2232 smash_to_pointer_type (type
, to_type
)
2233 struct type
*type
, *to_type
;
2235 int type_permanent
= (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
);
2237 bzero (type
, sizeof (struct type
));
2238 TYPE_TARGET_TYPE (type
) = to_type
;
2239 /* We assume the machine has only one representation for pointers! */
2240 TYPE_LENGTH (type
) = sizeof (char *);
2241 TYPE_CODE (type
) = TYPE_CODE_PTR
;
2243 /* ??? TYPE_TARGET_TYPE and TYPE_MAIN_VARIANT are the same. You can't do
2244 this. It will break the target type!!!
2245 TYPE_MAIN_VARIANT (type) = type;
2249 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2251 if (TYPE_POINTER_TYPE (to_type
) == 0
2252 && (!(TYPE_FLAGS (to_type
) & TYPE_FLAG_PERM
)
2255 TYPE_POINTER_TYPE (to_type
) = type
;
2265 fatal ("internals eror: builtin_type called!");
2267 #endif /* IBM6000 */