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. */
26 /* Native only: Need struct tbtable in <sys/debug.h>. */
28 /* AIX COFF names have a preceeding dot `.' */
29 #define NAMES_HAVE_DOT 1
31 #include <sys/types.h>
36 #include <sys/param.h>
41 /*#include <linenum.h>*/
42 #include <sys/debug.h>
49 #include "coff/internal.h" /* FIXME, internal data from BFD */
50 #include "libcoff.h" /* FIXME, internal data from BFD */
51 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
53 /* Simplified internal version of coff symbol table information */
57 int c_symnum
; /* symbol number of this entry */
58 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
65 /* The COFF line table, in raw form. */
66 static char *linetab
= NULL
; /* Its actual contents */
67 static long linetab_offset
; /* Its offset in the file */
68 static unsigned long linetab_size
; /* Its size */
70 /* last function's saved coff symbol `cs' */
72 static struct coff_symbol fcn_cs_saved
;
74 static bfd
*symfile_bfd
;
76 /* Core address of start and end of text of current source file.
77 This is calculated from the first function seen after a C_FILE
81 static CORE_ADDR cur_src_end_addr
;
83 /* Core address of the end of the first object file. */
85 static CORE_ADDR first_object_file_end
;
87 /* pointer to the string table */
90 /* length of the string table */
91 static int strtbl_len
;
93 /* pointer to debug section */
94 static char *debugsec
;
96 /* pointer to the a.out symbol table */
99 /* initial symbol-table-debug-string vector length */
101 #define INITIAL_STABVECTOR_LENGTH 40
103 struct pending_stabs
*global_stabs
;
106 /* Nonzero if within a function (so symbols should be local,
107 if nothing says specifically). */
111 /* Local variables that hold the shift and mask values for the
112 COFF file that we are currently reading. These come back to us
113 from BFD, and are referenced by their macro names, as well as
114 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
115 macros from ../internalcoff.h . */
117 static unsigned local_n_btshft
;
118 static unsigned local_n_tmask
;
121 #define N_BTSHFT local_n_btshft
123 #define N_TMASK local_n_tmask
125 /* Local variables that hold the sizes in the file of various COFF structures.
126 (We only need to know this to read them from the file -- BFD will then
127 translate the data in them, into `internal_xxx' structs in the right
128 byte order, alignment, etc.) */
130 static unsigned local_symesz
;
133 /* coff_symfile_init()
134 is the coff-specific initialization routine for reading symbols.
135 It is passed a struct sym_fns which contains, among other things,
136 the BFD for the file whose symbols are being read, and a slot for
137 a pointer to "private data" which we fill with cookies and other
138 treats for coff_symfile_read().
140 We will only be called if this is a COFF or COFF-like file.
141 BFD handles figuring out the format of the file, and code in symtab.c
142 uses BFD's determination to vector to us.
144 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
146 struct coff_symfile_info
{
147 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
148 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
153 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned,
154 CORE_ADDR
, CORE_ADDR
, unsigned *));
157 aixcoff_symfile_read
PARAMS ((struct sym_fns
*, CORE_ADDR
, int));
160 free_debugsection
PARAMS ((void));
163 init_debugsection
PARAMS ((bfd
*));
166 init_stringtab
PARAMS ((bfd
*, long, struct objfile
*));
169 aixcoff_symfile_init
PARAMS ((struct sym_fns
*));
172 aixcoff_new_init
PARAMS ((void));
175 init_lineno
PARAMS ((bfd
*, long, int));
178 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
181 read_symbol_lineno
PARAMS ((char *, int));
184 read_symbol_nvalue
PARAMS ((char *, int));
186 static struct symbol
*
187 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
190 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
193 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
196 sort_syms
PARAMS ((void));
199 compare_symbols
PARAMS ((const void *, const void *));
201 /* Call sort_syms to sort alphabetically
202 the symbols of each block of each symtab. */
205 compare_symbols (s1p
, s2p
)
209 /* Names that are less should come first. */
210 register struct symbol
**s1
= (struct symbol
**) s1p
;
211 register struct symbol
**s2
= (struct symbol
**) s2p
;
212 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
216 /* For symbols of the same name, registers should come first. */
217 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
218 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
222 /* Sort a vector of symbols by their value. */
227 register struct symtab
*s
;
228 register struct objfile
*objfile
;
230 register struct blockvector
*bv
;
231 register struct block
*b
;
233 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
235 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
237 bv
= BLOCKVECTOR (s
);
238 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
239 for (i
= 0; i
< nbl
; i
++)
241 b
= BLOCKVECTOR_BLOCK (bv
, i
);
242 if (BLOCK_SHOULD_SORT (b
))
244 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
245 sizeof (struct symbol
*), compare_symbols
);
253 /* add a given stab string into given stab vector. */
256 add_stab_to_list (stabname
, stabvector
)
258 struct pending_stabs
**stabvector
;
260 if ( *stabvector
== NULL
) {
261 *stabvector
= (struct pending_stabs
*)
262 xmalloc (sizeof (struct pending_stabs
) +
263 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
264 (*stabvector
)->count
= 0;
265 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
267 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
268 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
269 *stabvector
= (struct pending_stabs
*)
270 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
271 (*stabvector
)->length
* sizeof (char*));
273 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
278 /* for all the stabs in a given stab vector, build appropriate types
279 and fix their symbols in given symbol vector. */
282 patch_block_stabs (symbols
, stabs
)
283 struct pending
*symbols
;
284 struct pending_stabs
*stabs
;
291 /* for all the stab entries, find their corresponding symbols and
292 patch their types! */
294 for (ii
=0; ii
< stabs
->count
; ++ii
) {
295 char *name
= stabs
->stab
[ii
];
296 char *pp
= (char*) index (name
, ':');
297 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
300 /* printf ("ERROR! stab symbol not found!\n"); /* FIXME */
301 /* The above is a false alarm. There are cases the we can have
302 a stab, without its symbol. xlc generates this for the extern
303 definitions in inner blocks. */
308 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
309 SYMBOL_TYPE (sym
) = lookup_function_type (read_type (&pp
));
311 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
318 /* compare line table entry addresses. */
321 compare_lte (lte1
, lte2
)
322 struct linetable_entry
*lte1
, *lte2
;
324 return lte1
->pc
- lte2
->pc
;
327 /* Give a line table with function entries are marked, arrange its functions
328 in assending order and strip off function entry markers and return it in
329 a newly created table. If the old one is good enough, return the old one. */
331 static struct linetable
*
332 arrange_linetable (oldLineTb
)
333 struct linetable
*oldLineTb
; /* old linetable */
336 newline
, /* new line count */
337 function_count
; /* # of functions */
339 struct linetable_entry
*fentry
; /* function entry vector */
340 int fentry_size
; /* # of function entries */
341 struct linetable
*newLineTb
; /* new line table */
343 #define NUM_OF_FUNCTIONS 20
345 fentry_size
= NUM_OF_FUNCTIONS
;
346 fentry
= (struct linetable_entry
*)
347 malloc (fentry_size
* sizeof (struct linetable_entry
));
349 for (function_count
=0, ii
=0; ii
<oldLineTb
->nitems
; ++ii
) {
351 if (oldLineTb
->item
[ii
].line
== 0) { /* function entry found. */
353 if (function_count
>= fentry_size
) { /* make sure you have room. */
355 fentry
= (struct linetable_entry
*)
356 realloc (fentry
, fentry_size
* sizeof (struct linetable_entry
));
358 fentry
[function_count
].line
= ii
;
359 fentry
[function_count
].pc
= oldLineTb
->item
[ii
].pc
;
364 if (function_count
== 0) {
368 else if (function_count
> 1)
369 qsort (fentry
, function_count
, sizeof(struct linetable_entry
), compare_lte
);
371 /* allocate a new line table. */
372 newLineTb
= (struct linetable
*) malloc (sizeof (struct linetable
) +
373 (oldLineTb
->nitems
- function_count
) * sizeof (struct linetable_entry
));
375 /* if line table does not start with a function beginning, copy up until
379 if (oldLineTb
->item
[0].line
!= 0)
381 newline
< oldLineTb
->nitems
&& oldLineTb
->item
[newline
].line
; ++newline
)
382 newLineTb
->item
[newline
] = oldLineTb
->item
[newline
];
384 /* Now copy function lines one by one. */
386 for (ii
=0; ii
< function_count
; ++ii
) {
387 for (jj
= fentry
[ii
].line
+ 1;
388 jj
< oldLineTb
->nitems
&& oldLineTb
->item
[jj
].line
!= 0;
390 newLineTb
->item
[newline
] = oldLineTb
->item
[jj
];
393 newLineTb
->nitems
= oldLineTb
->nitems
- function_count
;
399 /* We try to detect the beginning of a compilation unit. That info will
400 be used as an entry in line number recording routines (enter_line_range) */
402 static unsigned first_fun_line_offset
;
403 static unsigned first_fun_bf
;
405 #define mark_first_line(OFFSET, SYMNUM) \
406 if (!first_fun_line_offset) { \
407 first_fun_line_offset = OFFSET; \
408 first_fun_bf = SYMNUM; \
412 /* include file support: C_BINCL/C_EINCL pairs will be kept in the
413 following `IncludeChain'. At the end of each symtab (end_symtab),
414 we will determine if we should create additional symtab's to
415 represent if (the include files. */
418 typedef struct _inclTable
{
419 char *name
; /* include filename */
420 int begin
, end
; /* offsets to the line table */
421 struct subfile
*subfile
;
422 unsigned funStartLine
; /* start line # of its function */
425 #define INITIAL_INCLUDE_TABLE_LENGTH 20
426 static InclTable
*inclTable
; /* global include table */
427 static int inclIndx
; /* last entry to table */
428 static int inclLength
; /* table length */
429 static int inclDepth
; /* nested include depth */
433 record_include_begin (cs
)
434 struct coff_symbol
*cs
;
436 /* In aixcoff, we assume include files cannot be nested (not in .c files
437 of course, but in corresponding .s files.) */
440 fatal ("aix internal: pending include file exists.");
444 /* allocate an include file, or make room for the new entry */
445 if (inclLength
== 0) {
446 inclTable
= (InclTable
*)
447 xmalloc (sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
448 bzero (inclTable
, sizeof (InclTable
) * INITIAL_INCLUDE_TABLE_LENGTH
);
449 inclLength
= INITIAL_INCLUDE_TABLE_LENGTH
;
452 else if (inclIndx
>= inclLength
) {
453 inclLength
+= INITIAL_INCLUDE_TABLE_LENGTH
;
454 inclTable
= (InclTable
*)
455 xrealloc (inclTable
, sizeof (InclTable
) * inclLength
);
456 bzero (inclTable
+inclLength
-INITIAL_INCLUDE_TABLE_LENGTH
,
457 sizeof (InclTable
)*INITIAL_INCLUDE_TABLE_LENGTH
);
460 inclTable
[inclIndx
].name
= cs
->c_name
;
461 inclTable
[inclIndx
].begin
= cs
->c_value
;
466 record_include_end (cs
)
467 struct coff_symbol
*cs
;
472 fatal ("aix internal: Mismatch C_BINCL/C_EINCL pair found.");
474 pTbl
= &inclTable
[inclIndx
];
475 pTbl
->end
= cs
->c_value
;
486 if (inclTable
&& inclLength
)
487 for (ii
=0; ii
< inclIndx
; ++ii
)
488 printf ("name: %s, begin: 0x%x, end: 0x%x\n",
489 inclTable
[ii
].name
, inclTable
[ii
].begin
, inclTable
[ii
].end
);
493 /* given the start and end addresses of a compilation unit (or a csect, at times)
494 process its lines and create appropriate line vectors. */
497 process_linenos (start
, end
)
498 CORE_ADDR start
, end
;
503 struct subfile main_subfile
; /* subfile structure for the main
506 /* in the main source file, any time we see a function entry, we reset
507 this variable to function's absolute starting line number. All the
508 following line numbers in the function are relative to this, and
509 we record absolute line numbers in record_line(). */
511 int main_source_baseline
= 0;
517 if (!(offset
= first_fun_line_offset
))
518 goto return_after_cleanup
;
520 bzero (&main_subfile
, sizeof (main_subfile
));
521 first_fun_line_offset
= 0;
524 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
525 &main_source_baseline
);
527 /* else, there was source with line numbers in include files */
530 main_source_baseline
= 0;
531 for (ii
=0; ii
< inclIndx
; ++ii
) {
533 struct subfile
*tmpSubfile
;
535 /* if there is main file source before include file, enter it. */
536 if (offset
< inclTable
[ii
].begin
) {
538 (&main_subfile
, offset
, inclTable
[ii
].begin
- LINESZ
, start
, 0,
539 &main_source_baseline
);
542 /* Have a new subfile for the include file */
544 tmpSubfile
= inclTable
[ii
].subfile
= (struct subfile
*)
545 xmalloc (sizeof (struct subfile
));
547 bzero (tmpSubfile
, sizeof (struct subfile
));
548 firstLine
= &(inclTable
[ii
].funStartLine
);
550 /* enter include file's lines now. */
551 enter_line_range (tmpSubfile
, inclTable
[ii
].begin
,
552 inclTable
[ii
].end
, start
, 0, firstLine
);
554 offset
= inclTable
[ii
].end
+ LINESZ
;
557 /* all the include files' line have been processed at this point. Now,
558 enter remaining lines of the main file, if any left. */
559 if (offset
< (linetab_offset
+ linetab_size
+ 1 - LINESZ
)) {
560 enter_line_range (&main_subfile
, offset
, 0, start
, end
,
561 &main_source_baseline
);
565 /* Process main file's line numbers. */
566 if (main_subfile
.line_vector
) {
567 struct linetable
*lineTb
, *lv
;
569 lv
= main_subfile
.line_vector
;
571 /* Line numbers are not necessarily ordered. xlc compilation will
572 put static function to the end. */
574 lineTb
= arrange_linetable (lv
);
576 current_subfile
->line_vector
= (struct linetable
*)
577 xrealloc (lv
, (sizeof (struct linetable
)
578 + lv
->nitems
* sizeof (struct linetable_entry
)));
583 current_subfile
->line_vector
= lineTb
;
586 current_subfile
->line_vector_length
=
587 current_subfile
->line_vector
->nitems
;
590 /* Now, process included files' line numbers. */
592 for (ii
=0; ii
< inclIndx
; ++ii
) {
594 if ( (inclTable
[ii
].subfile
)->line_vector
) { /* Useless if!!! FIXMEmgo */
595 struct linetable
*lineTb
, *lv
;
597 lv
= (inclTable
[ii
].subfile
)->line_vector
;
599 /* Line numbers are not necessarily ordered. xlc compilation will
600 put static function to the end. */
602 lineTb
= arrange_linetable (lv
);
606 /* For the same include file, we might want to have more than one subfile.
607 This happens if we have something like:
615 while foo.h including code in it. (stupid but possible)
616 Since start_subfile() looks at the name and uses an existing one if finds,
617 we need to provide a fake name and fool it. */
619 /* start_subfile (inclTable[ii].name, (char*)0); */
620 start_subfile (" ?", (char*)0);
621 current_subfile
->name
=
622 obsavestring (inclTable
[ii
].name
, strlen (inclTable
[ii
].name
),
623 ¤t_objfile
->symbol_obstack
);
626 current_subfile
->line_vector
= (struct linetable
*)
627 xrealloc (lv
, (sizeof (struct linetable
)
628 + lv
->nitems
* sizeof (struct linetable_entry
)));
633 current_subfile
->line_vector
= lineTb
;
636 current_subfile
->line_vector_length
=
637 current_subfile
->line_vector
->nitems
;
638 start_subfile (pop_subfile (), (char*)0);
643 /* I am not sure this logic is correct. There might be no lines in the
644 main file, whereas there are some in included ones. FIXMEibm */
645 current_subfile
->line_vector
= NULL
;
647 return_after_cleanup
:
649 /* We don't want to keep alloc/free'ing the global include file table. */
652 /* start with a fresh subfile structure for the next file. */
653 bzero (&main_subfile
, sizeof (struct subfile
));
657 aix_process_linenos ()
659 /* process line numbers and enter them into line vector */
660 process_linenos (last_source_start_addr
, cur_src_end_addr
);
664 /* Enter a given range of lines into the line vector.
665 can be called in the following two ways:
666 enter_line_range (subfile, beginoffset, endoffset, startaddr, 0, firstLine) or
667 enter_line_range (subfile, beginoffset, 0, startaddr, endaddr, firstLine) */
670 enter_line_range (subfile
, beginoffset
, endoffset
, startaddr
, endaddr
, firstLine
)
671 struct subfile
*subfile
;
672 unsigned beginoffset
, endoffset
; /* offsets to line table */
673 CORE_ADDR startaddr
, endaddr
;
679 /* Do Byte swapping, if needed. FIXME! */
680 #define P_LINENO(PP) (*(unsigned short*)((struct external_lineno*)(PP))->l_lnno)
681 #define P_LINEADDR(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_paddr)
682 #define P_LINESYM(PP) (*(long*)((struct external_lineno*)(PP))->l_addr.l_symndx)
684 pp
= &linetab
[beginoffset
- linetab_offset
];
685 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
686 : &linetab
[linetab_size
-1];
688 while (pp
<= limit
) {
690 /* find the address this line represents */
691 addr
= P_LINENO(pp
) ?
692 P_LINEADDR(pp
) : read_symbol_nvalue (symtbl
, P_LINESYM(pp
));
694 if (addr
< startaddr
|| (endaddr
&& addr
> endaddr
))
697 if (P_LINENO(pp
) == 0) {
698 *firstLine
= read_symbol_lineno (symtbl
, P_LINESYM(pp
));
699 record_line (subfile
, 0, addr
);
703 record_line (subfile
, *firstLine
+ P_LINENO(pp
), addr
);
710 int fsize
; /* file size */
711 int fixedparms
; /* number of fixed parms */
712 int floatparms
; /* number of float parms */
713 unsigned int parminfo
; /* parameter info.
714 See /usr/include/sys/debug.h
715 tbtable_ext.parminfo */
716 int framesize
; /* function frame size */
720 /* Given a function symbol, return its traceback information. */
723 retrieve_tracebackinfo (abfd
, textsec
, cs
)
726 struct coff_symbol
*cs
;
728 #define TBTABLE_BUFSIZ 2000
729 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
732 static TracebackInfo tbInfo
;
735 static char buffer
[TBTABLE_BUFSIZ
];
738 int bytesread
=0; /* total # of bytes read so far */
739 int bufferbytes
; /* number of bytes in the buffer */
741 int functionstart
= cs
->c_value
- textsec
->vma
;
743 bzero (&tbInfo
, sizeof (tbInfo
));
745 /* keep reading blocks of data from the text section, until finding a zero
746 word and a traceback table. */
748 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
749 (file_ptr
)(functionstart
+ bytesread
),
751 (TBTABLE_BUFSIZ
< (textsec
->_raw_size
- functionstart
- bytesread
)) ?
752 TBTABLE_BUFSIZ
: (textsec
->_raw_size
- functionstart
- bytesread
))))
754 bytesread
+= bufferbytes
;
755 pinsn
= (int*) buffer
;
757 /* if this is the first time we filled the buffer, retrieve function
760 if (bytesread
== bufferbytes
) {
762 /* skip over unrelated instructions */
764 if (*pinsn
== 0x7c0802a6) /* mflr r0 */
766 if ((*pinsn
& 0xfc00003e) == 0x7c000026) /* mfcr Rx */
768 if ((*pinsn
& 0xfc000000) == 0x48000000) /* bl foo, save fprs */
770 if ((*pinsn
& 0xfc1f0000) == 0xbc010000) /* stm Rx, NUM(r1) */
774 int tmp
= (*pinsn
>> 16) & 0xffff;
776 if (tmp
== 0x9421) { /* stu r1, NUM(r1) */
777 tbInfo
.framesize
= 0x10000 - (*pinsn
& 0xffff);
780 else if ((*pinsn
== 0x93e1fffc) || /* st r31,-4(r1) */
781 (tmp
== 0x9001)) /* st r0, NUM(r1) */
783 /* else, could not find a frame size. */
787 } while (++pinsn
&& *pinsn
);
789 if (!tbInfo
.framesize
)
793 /* look for a zero word. */
795 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
798 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
803 /* function size is the amount of bytes we have skipped so far. */
804 tbInfo
.fsize
= bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
);
808 /* if we don't have the whole traceback table in the buffer, re-read
811 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
813 /* In case if we are *very* close to the end of the text section
814 and cannot read properly from that point on, abort by returning
816 Handle this case more graciously -- FIXME */
818 if (!bfd_get_section_contents (
819 abfd
, textsec
, buffer
,
820 (file_ptr
)(functionstart
+
821 bytesread
- (buffer
+ bufferbytes
- (char*)pinsn
)),MIN_TBTABSIZ
))
822 { printf ("Abnormal return!..\n"); return NULL
; }
824 ptb
= (struct tbtable
*)buffer
;
827 ptb
= (struct tbtable
*)pinsn
;
829 tbInfo
.fixedparms
= ptb
->tb
.fixedparms
;
830 tbInfo
.floatparms
= ptb
->tb
.floatparms
;
831 tbInfo
.parminfo
= ptb
->tb_ext
.parminfo
;
839 /* Given a function symbol, return a pointer to its traceback table. */
842 retrieve_traceback (abfd
, textsec
, cs
, size
)
845 struct coff_symbol
*cs
;
846 int *size
; /* return function size */
848 #define TBTABLE_BUFSIZ 2000
849 #define MIN_TBTABSIZ 50 /* minimum buffer size to hold a
852 static char buffer
[TBTABLE_BUFSIZ
];
855 int bytesread
=0; /* total # of bytes read so far */
856 int bufferbytes
; /* number of bytes in the buffer */
858 int functionstart
= cs
->c_value
- textsec
->filepos
+ textsec
->vma
;
861 /* keep reading blocks of data from the text section, until finding a zero
862 word and a traceback table. */
864 while (bfd_get_section_contents (abfd
, textsec
, buffer
,
865 (file_ptr
)(functionstart
+ bytesread
),
867 (TBTABLE_BUFSIZ
< (textsec
->size
- functionstart
- bytesread
)) ?
868 TBTABLE_BUFSIZ
: (textsec
->size
- functionstart
- bytesread
))))
870 bytesread
+= bufferbytes
;
871 pinsn
= (int*) buffer
;
873 /* look for a zero word. */
875 while (*pinsn
&& (pinsn
< (int*)(buffer
+ bufferbytes
- sizeof(int))))
878 if (pinsn
>= (int*)(buffer
+ bufferbytes
))
883 /* function size is the amount of bytes we have skipped so far. */
884 *size
= bytesread
- (buffer
+ bufferbytes
- pinsn
);
888 /* if we don't have the whole traceback table in the buffer, re-read
891 if ((char*)pinsn
> (buffer
+ bufferbytes
- MIN_TBTABSIZ
)) {
893 /* In case if we are *very* close to the end of the text section
894 and cannot read properly from that point on, abort for now.
895 Handle this case more graciously -- FIXME */
897 if (!bfd_get_section_contents (
898 abfd
, textsec
, buffer
,
899 (file_ptr
)(functionstart
+
900 bytesread
- (buffer
+ bufferbytes
- pinsn
)),MIN_TBTABSIZ
))
901 /* abort (); */ { printf ("abort!!!\n"); return NULL
; }
903 return (struct tbtable
*)buffer
;
906 return (struct tbtable
*)pinsn
;
916 /* Save the vital information for use when closing off the current file.
917 NAME is the file name the symbols came from, START_ADDR is the first
918 text address for the file, and SIZE is the number of bytes of text. */
920 #define complete_symtab(name, start_addr) { \
921 last_source_file = savestring (name, strlen (name)); \
922 last_source_start_addr = start_addr; \
926 /* Refill the symbol table input buffer
927 and set the variables that control fetching entries from it.
928 Reports an error if no data available.
929 This function can read past the end of the symbol table
930 (into the string table) but this does no harm. */
932 /* Reading symbol table has to be fast! Keep the followings as macros, rather
935 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \
939 namestr = (NAME) + 1; \
941 namestr = obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
944 prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \
945 misc_func_recorded = 1; \
949 /* A parameter template, used by ADD_PARM_TO_PENDING. */
951 static struct symbol parmsym
= { /* default parameter symbol */
953 VAR_NAMESPACE
, /* namespace */
960 /* Add a parameter to a given pending symbol list. */
962 #define ADD_PARM_TO_PENDING(PARM, VALUE, PTYPE, PENDING_SYMBOLS) \
964 PARM = (struct symbol *) \
965 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
967 SYMBOL_TYPE (PARM) = PTYPE; \
968 SYMBOL_VALUE (PARM) = VALUE; \
969 add_symbol_to_list (PARM, &PENDING_SYMBOLS); \
973 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
974 nested. At any given time, a symbol can only be in one static block.
975 This is the base address of current static block, zero if non exists. */
977 static int static_block_base
= 0;
979 /* true if space for symbol name has been allocated. */
981 static int symname_alloced
= 0;
983 /* read the whole symbol table of a given bfd. */
986 read_xcoff_symtab (objfile
, nsyms
)
987 struct objfile
*objfile
; /* Object file we're reading from */
988 int nsyms
; /* # of symbols */
990 bfd
*abfd
= objfile
->obfd
;
991 char *raw_symbol
; /* Pointer into raw seething symbol table */
992 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
993 sec_ptr textsec
; /* Pointer to text section */
994 TracebackInfo
*ptb
; /* Pointer to traceback table */
996 struct internal_syment symbol
[1];
997 union internal_auxent main_aux
[1];
998 struct coff_symbol cs
[1];
999 CORE_ADDR file_start_addr
= 0;
1000 CORE_ADDR file_end_addr
= 0;
1002 int next_file_symnum
= -1;
1003 int just_started
= 1;
1008 long fcn_line_offset
;
1011 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
1012 union internal_auxent fcn_aux_saved
;
1013 struct type
*fcn_type_saved
= NULL
;
1014 struct context_stack
*new;
1016 char *filestring
= " _start_ "; /* Name of the current file. */
1018 char *last_csect_name
; /* last seen csect's name and value */
1019 CORE_ADDR last_csect_val
;
1020 int misc_func_recorded
; /* true if any misc. function */
1022 current_objfile
= objfile
;
1024 /* Get the appropriate COFF "constants" related to the file we're handling. */
1025 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
1026 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
1027 local_symesz
= coff_data (abfd
)->local_symesz
;
1029 last_source_file
= 0;
1030 last_csect_name
= 0;
1032 misc_func_recorded
= 0;
1034 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
1036 first_object_file_end
= 0;
1038 /* Allocate space for the entire symbol table at once, and read it
1039 all in. The bfd is already positioned at the beginning of
1040 the symbol table. */
1042 size
= coff_data (abfd
)->local_symesz
* nsyms
;
1043 symtbl
= xmalloc (size
);
1045 val
= bfd_read (symtbl
, size
, 1, abfd
);
1047 perror_with_name ("reading symbol table");
1049 raw_symbol
= symtbl
;
1051 textsec
= bfd_get_section_by_name (abfd
, ".text");
1053 printf ("Unable to locate text section!\n");
1056 while (symnum
< nsyms
) {
1058 QUIT
; /* make this command interruptable. */
1060 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
1061 /* read one symbol into `cs' structure. After processing the whole symbol
1062 table, only string table will be kept in memory, symbol table and debug
1063 section of aixcoff will be freed. Thus we can mark symbols with names
1064 in string table as `alloced'. */
1068 /* Swap and align the symbol into a reasonable C structure. */
1069 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
1071 cs
->c_symnum
= symnum
;
1072 cs
->c_nsyms
= symbol
->n_numaux
;
1073 if (symbol
->n_zeroes
) {
1074 symname_alloced
= 0;
1075 /* We must use the original, unswapped, name here so the name field
1076 pointed to by cs->c_name will persist throughout xcoffread. If
1077 we use the new field, it gets overwritten for each symbol. */
1078 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
1079 } else if (symbol
->n_sclass
& 0x80) {
1080 cs
->c_name
= debugsec
+ symbol
->n_offset
;
1081 symname_alloced
= 0;
1082 } else { /* in string table */
1083 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
1084 symname_alloced
= 1;
1086 cs
->c_value
= symbol
->n_value
;
1087 cs
->c_sclass
= symbol
->n_sclass
& 0xff;
1088 cs
->c_secnum
= symbol
->n_scnum
;
1089 cs
->c_type
= (unsigned)symbol
->n_type
;
1091 raw_symbol
+= coff_data (abfd
)->local_symesz
;
1094 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
1096 /* Skip all the auxents associated with this symbol. */
1097 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
1098 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
1103 /* if symbol name starts with ".$" or "$", ignore it. */
1104 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
1107 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
1108 if (last_source_file
)
1109 end_symtab (cur_src_end_addr
, 1, 0, objfile
);
1111 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
1112 cur_src_end_addr
= first_object_file_end
;
1113 /* done with all files, everything from here on is globals */
1116 /* if explicitly specified as a function, treat is as one. */
1117 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
1118 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1120 goto function_entry_point
;
1123 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
1125 /* dealing with a symbol with a csect entry. */
1127 # define CSECT(PP) ((PP)->x_csect)
1128 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
1129 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
1130 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
1131 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
1133 /* Convert the auxent to something we can access. */
1134 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1137 switch (CSECT_SMTYP (main_aux
)) {
1140 continue; /* ignore all external references. */
1142 case XTY_SD
: /* a section description. */
1144 switch (CSECT_SCLAS (main_aux
)) {
1146 case XMC_PR
: /* a `.text' csect. */
1149 /* A program csect is seen.
1151 We have to allocate one symbol table for each program csect. Normally
1152 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
1153 CU might include more than one prog csect, and they don't have to be
1154 adjacent in terms of the space they occupy in memory. Thus, one single
1155 CU might get fragmented in the memory and gdb's file start and end address
1156 approach does not work! */
1158 if (last_csect_name
) {
1160 /* if no misc. function recorded in the last seen csect, enter
1161 it as a function. This will take care of functions like
1162 strcmp() compiled by xlc. */
1164 if (!misc_func_recorded
) {
1166 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1171 complete_symtab (filestring
, file_start_addr
);
1172 cur_src_end_addr
= file_end_addr
;
1173 end_symtab (file_end_addr
, 1, 0, objfile
);
1174 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
1177 /* If this is the very first csect seen, basically `__start'. */
1179 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
1183 file_start_addr
= cs
->c_value
;
1184 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
1186 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
1187 last_csect_name
= cs
->c_name
;
1188 last_csect_val
= cs
->c_value
;
1191 misc_func_recorded
= 0;
1197 /* If the section is not a data description, ignore it. Note that
1198 uninitialized data will show up as XTY_CM/XMC_RW pair. */
1201 #ifdef XCOFF_ADD_TOC_TO_LOADINFO
1202 XCOFF_ADD_TOC_TO_LOADINFO (cs
->c_value
);
1204 /* fall down to default case. */
1206 case XMC_TC
: /* ignore toc entries */
1207 default : /* any other XMC_XXX */
1211 break; /* switch CSECT_SCLAS() */
1215 /* a function entry point. */
1216 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
1218 function_entry_point
:
1219 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
1222 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1223 fcn_start_addr
= cs
->c_value
;
1225 /* save the function header info, which will be used
1226 when `.bf' is seen. */
1228 fcn_aux_saved
= *main_aux
;
1233 /* If function has two auxent, then debugging information is
1234 already available for it. Process traceback table for
1235 functions with only one auxent. */
1237 if (cs
->c_nsyms
== 1)
1238 ptb
= retrieve_tracebackinfo (abfd
, textsec
, cs
);
1240 else if (cs
->c_nsyms
!= 2)
1243 /* If there is traceback info, create and add parameters for it. */
1245 if (ptb
&& (ptb
->fixedparms
|| ptb
->floatparms
)) {
1247 int parmcnt
= ptb
->fixedparms
+ ptb
->floatparms
;
1248 char *parmcode
= (char*) &ptb
->parminfo
;
1249 int parmvalue
= ptb
->framesize
+ 0x18; /* sizeof(LINK AREA) == 0x18 */
1250 unsigned int ii
, mask
;
1252 for (ii
=0, mask
= 0x80000000; ii
<parmcnt
; ++ii
) {
1253 struct symbol
*parm
;
1255 if (ptb
->parminfo
& mask
) { /* float or double */
1257 if (ptb
->parminfo
& mask
) { /* double parm */
1259 (parm
, parmvalue
, builtin_type_double
, local_symbols
);
1260 parmvalue
+= sizeof (double);
1262 else { /* float parm */
1264 (parm
, parmvalue
, builtin_type_float
, local_symbols
);
1265 parmvalue
+= sizeof (float);
1268 else { /* fixed parm, use (int*) for hex rep. */
1269 ADD_PARM_TO_PENDING (parm
, parmvalue
,
1270 lookup_pointer_type (builtin_type_int
),
1272 parmvalue
+= sizeof (int);
1277 /* Fake this as a function. Needed in process_xcoff_symbol() */
1280 finish_block(process_xcoff_symbol (cs
, objfile
), &local_symbols
,
1281 pending_blocks
, cs
->c_value
,
1282 cs
->c_value
+ ptb
->fsize
, objfile
);
1286 /* shared library function trampoline code entry point. */
1287 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
1289 /* record trampoline code entries as mst_unknown symbol. When we
1290 lookup mst symbols, we will choose mst_text over mst_unknown. */
1292 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_unknown
,
1298 default : /* all other XTY_XXXs */
1300 } /* switch CSECT_SMTYP() */ }
1302 switch (cs
->c_sclass
) {
1306 /* see if the last csect needs to be recorded. */
1308 if (last_csect_name
&& !misc_func_recorded
) {
1310 /* if no misc. function recorded in the last seen csect, enter
1311 it as a function. This will take care of functions like
1312 strcmp() compiled by xlc. */
1315 RECORD_MINIMAL_SYMBOL (last_csect_name
, last_csect_val
,
1319 /* c_value field contains symnum of next .file entry in table
1320 or symnum of first global after last .file. */
1322 next_file_symnum
= cs
->c_value
;
1324 /* complete symbol table for last object file containing
1325 debugging information. */
1327 /* Whether or not there was a csect in the previous file, we have
1328 to call `end_symtab' and `start_symtab' to reset type_vector,
1329 line_vector, etc. structures. */
1331 complete_symtab (filestring
, file_start_addr
);
1332 cur_src_end_addr
= file_end_addr
;
1333 end_symtab (file_end_addr
, 1, 0, objfile
);
1334 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
1335 last_csect_name
= 0;
1337 /* reset file start and end addresses. A compilation unit with no text
1338 (only data) should have zero file boundaries. */
1339 file_start_addr
= file_end_addr
= 0;
1341 filestring
= cs
->c_name
;
1347 /* For a function stab, just save its type in `fcn_type_saved', and leave
1348 it for the `.bf' processing. */
1350 char *pp
= (char*) index (cs
->c_name
, ':');
1352 if (!pp
|| ( *(pp
+1) != 'F' && *(pp
+1) != 'f'))
1353 fatal ("Unrecognized stab");
1357 fatal ("Unprocessed function type");
1359 fcn_type_saved
= lookup_function_type (read_type (&pp
, objfile
));
1365 if (strcmp (cs
->c_name
, ".bf") == 0) {
1367 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1370 within_function
= 1;
1372 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
1373 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
1377 1) xlc (IBM's native c compiler) postpones static function code
1378 emission to the end of a compilation unit. This way it can
1379 determine if those functions (statics) are needed or not, and
1380 can do some garbage collection (I think). This makes line
1381 numbers and corresponding addresses unordered, and we end up
1382 with a line table like:
1399 and that breaks gdb's binary search on line numbers, if the
1400 above table is not sorted on line numbers. And that sort
1401 should be on function based, since gcc can emit line numbers
1404 10 0x100 - for the init/test part of a for stmt.
1407 10 0x400 - for the increment part of a for stmt.
1409 arrange_linenos() will do this sorting.
1412 2) aix symbol table might look like:
1414 c_file // beginning of a new file
1415 .bi // beginning of include file
1416 .ei // end of include file
1420 basically, .bi/.ei pairs do not necessarily encapsulate
1421 their scope. They need to be recorded, and processed later
1422 on when we come the end of the compilation unit.
1423 Include table (inclTable) and process_linenos() handle
1426 mark_first_line (fcn_line_offset
, cs
->c_symnum
);
1428 new = push_context (0, fcn_start_addr
);
1429 new->name
= process_xcoff_symbol (&fcn_cs_saved
, objfile
);
1431 /* Between a function symbol and `.bf', there always will be a function
1432 stab. We save function type when processing that stab. */
1434 if (fcn_type_saved
== NULL
) {
1435 printf ("Unknown function type: symbol 0x%x\n", cs
->c_symnum
);
1436 SYMBOL_TYPE (new->name
) = lookup_function_type (builtin_type_int
);
1439 SYMBOL_TYPE (new->name
) = fcn_type_saved
;
1440 fcn_type_saved
= NULL
;
1443 else if (strcmp (cs
->c_name
, ".ef") == 0) {
1445 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
1448 /* the value of .ef is the address of epilogue code;
1449 not useful for gdb */
1450 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1451 contains number of lines to '}' */
1453 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1454 new = pop_context ();
1455 if (context_stack_depth
!= 0)
1456 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1459 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1461 fcn_cs_saved
.c_value
+
1462 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
1463 within_function
= 0;
1467 case C_BSTAT
: /* begin static block */
1468 static_block_base
= read_symbol_nvalue (symtbl
, cs
->c_value
);
1471 case C_ESTAT
: /* end of static block */
1472 static_block_base
= 0;
1475 case C_ARG
: /* These are not implemented. */
1481 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
1484 case C_HIDEXT
: /* ignore these.. */
1489 case C_BINCL
: /* beginning of include file */
1491 /* In xlc output, C_BINCL/C_EINCL pair doesn't show up in sorted
1492 order. Thus, when wee see them, we might not know enough info
1493 to process them. Thus, we'll be saving them into a table
1494 (inclTable) and postpone their processing. */
1496 record_include_begin (cs
);
1499 case C_EINCL
: /* end of include file */
1500 /* see the comment after case C_BINCL. */
1501 record_include_end (cs
);
1505 if (strcmp (cs
->c_name
, ".bb") == 0) {
1507 new = push_context (depth
, cs
->c_value
);
1509 else if (strcmp (cs
->c_name
, ".eb") == 0) {
1510 new = pop_context ();
1511 if (depth
!= new->depth
)
1512 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1516 if (local_symbols
&& context_stack_depth
> 0) {
1517 /* Make a block for the local symbols within. */
1518 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1519 new->start_addr
, cs
->c_value
, objfile
);
1521 local_symbols
= new->locals
;
1526 (void) process_xcoff_symbol (cs
, objfile
);
1532 if (last_source_file
)
1533 end_symtab (cur_src_end_addr
, 1, 0, objfile
);
1536 current_objfile
= NULL
;
1539 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
1540 (SYMBOL2) = (struct symbol *) \
1541 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
1542 *(SYMBOL2) = *(SYMBOL1);
1545 #define SYMNAME_ALLOC(NAME, ALLOCED) \
1546 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
1549 /* process one xcoff symbol. */
1551 static struct symbol
*
1552 process_xcoff_symbol (cs
, objfile
)
1553 register struct coff_symbol
*cs
;
1554 struct objfile
*objfile
;
1556 struct symbol onesymbol
;
1557 register struct symbol
*sym
= &onesymbol
;
1558 struct symbol
*sym2
= NULL
;
1560 char *name
, *pp
, *qq
;
1561 int struct_and_type_combined
;
1568 bzero (sym
, sizeof (struct symbol
));
1570 /* default assumptions */
1571 SYMBOL_VALUE (sym
) = cs
->c_value
;
1572 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1574 if (ISFCN (cs
->c_type
)) {
1576 /* At this point, we don't know the type of the function and assume it
1577 is int. This will be patched with the type from its stab entry later
1578 on in patch_block_stabs () */
1580 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1581 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (objfile
, FT_INTEGER
));
1583 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1584 SYMBOL_DUP (sym
, sym2
);
1586 if (cs
->c_sclass
== C_EXT
)
1587 add_symbol_to_list (sym2
, &global_symbols
);
1588 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
1589 add_symbol_to_list (sym2
, &file_symbols
);
1594 /* in case we can't figure out the type, default is `int'. */
1595 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
1597 switch (cs
->c_sclass
)
1601 if (fcn_cs_saved
.c_sclass
== C_EXT
)
1602 add_stab_to_list (name
, &global_stabs
);
1604 add_stab_to_list (name
, &file_stabs
);
1608 case C_DECL
: /* a type decleration?? */
1609 qq
= (char*) strchr (name
, ':');
1610 if (!qq
) /* skip if there is no ':' */
1613 nameless
= (qq
== name
);
1615 struct_and_type_combined
= (qq
[1] == 'T' && qq
[2] == 't');
1616 pp
= qq
+ (struct_and_type_combined
? 3 : 2);
1619 /* To handle GNU C++ typename abbreviation, we need to be able to fill
1620 in a type's name as soon as space for that type is allocated. */
1622 if (struct_and_type_combined
&& name
!= qq
) {
1625 struct type
*tmp_type
;
1628 read_type_number (&tmp_pp
, typenums
);
1629 tmp_type
= dbx_alloc_type (typenums
, objfile
);
1631 if (tmp_type
&& !TYPE_NAME (tmp_type
) && !nameless
)
1632 TYPE_NAME (tmp_type
) = SYMBOL_NAME (sym
) =
1633 obsavestring (name
, qq
-name
,
1634 &objfile
->symbol_obstack
);
1636 ttype
= SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1638 /* read_type() will return null if type (or tag) definition was
1639 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
1640 there is no need to keep it in symbol table. */
1641 /* The above argument no longer valid. read_type() never returns NULL. */
1646 /* if there is no name for this typedef, you don't have to keep its
1647 symbol, since nobody could ask for it. Otherwise, build a symbol
1648 and add it into symbol_list. */
1652 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1653 else if (qq
[1] == 't')
1654 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1656 printf ("ERROR: Unrecognized stab string.\n");
1660 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1661 if (!SYMBOL_NAME (sym
))
1662 SYMBOL_NAME (sym
) = obsavestring (name
, qq
-name
,
1663 &objfile
->symbol_obstack
);
1665 SYMBOL_DUP (sym
, sym2
);
1667 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1669 /* For a combination of struct and type, add one more symbol
1672 if (struct_and_type_combined
) {
1673 SYMBOL_DUP (sym
, sym2
);
1674 SYMBOL_NAMESPACE (sym2
) = VAR_NAMESPACE
;
1676 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1680 /* assign a name to the type node. */
1682 if (!nameless
&& (!TYPE_NAME (ttype
) || *(TYPE_NAME (ttype
)) == '\0')) {
1683 if (struct_and_type_combined
)
1684 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
1686 /* else if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE) */
1687 else if (qq
[1] == 'T') /* struct namespace */
1688 TYPE_NAME (ttype
) = concat (
1689 TYPE_CODE (ttype
) == TYPE_CODE_UNION
? "union " :
1690 TYPE_CODE (ttype
) == TYPE_CODE_STRUCT
? "struct " : "enum ",
1691 SYMBOL_NAME (sym
), NULL
);
1697 add_stab_to_list (name
, &global_stabs
);
1702 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1704 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1705 SYMBOL_CLASS (sym
) = (cs
->c_sclass
== C_PSYM
) ? LOC_ARG
: LOC_REGPARM
;
1707 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1708 SYMBOL_DUP (sym
, sym2
);
1709 add_symbol_to_list (sym2
, &local_symbols
);
1713 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1715 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1716 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1717 SYMBOL_VALUE (sym
) += static_block_base
;
1719 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1720 SYMBOL_DUP (sym
, sym2
);
1722 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1726 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
1728 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1729 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1731 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1732 SYMBOL_DUP (sym
, sym2
);
1733 add_symbol_to_list (sym2
, &local_symbols
);
1737 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1738 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1739 SYMBOL_DUP (sym
, sym2
);
1740 add_symbol_to_list (sym2
, &local_symbols
);
1744 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1745 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1746 SYMBOL_DUP (sym
, sym2
);
1747 add_symbol_to_list (sym2
, &global_symbols
);
1751 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1752 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1753 SYMBOL_DUP (sym
, sym2
);
1755 (sym2
, within_function
? &local_symbols
: &file_symbols
);
1759 printf ("ERROR! C_REG is not fully implemented!\n");
1760 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1761 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
1762 SYMBOL_DUP (sym
, sym2
);
1763 add_symbol_to_list (sym2
, &local_symbols
);
1767 pp
= (char*) strchr (name
, ':');
1768 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1769 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (cs
->c_value
);
1771 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
1774 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
1777 /* else this is not a stab entry, suppose the type is either
1778 `int' or `float', depending on the register class. */
1780 SYMBOL_TYPE (sym
) = (SYMBOL_VALUE (sym
) < 32)
1781 ? lookup_fundamental_type (objfile
, FT_INTEGER
)
1782 : lookup_fundamental_type (objfile
, FT_FLOAT
);
1784 SYMBOL_DUP (sym
, sym2
);
1785 add_symbol_to_list (sym2
, &local_symbols
);
1789 printf ("ERROR: Unexpected storage class: %d.\n", cs
->c_sclass
);
1798 read_symbol_nvalue (symtable
, symno
)
1802 struct internal_syment symbol
[1];
1804 bfd_coff_swap_sym_in (symfile_bfd
, symtable
+ (symno
*local_symesz
), symbol
);
1805 return symbol
->n_value
;
1810 read_symbol_lineno (symtable
, symno
)
1814 struct internal_syment symbol
[1];
1815 union internal_auxent main_aux
[1];
1819 for (ii
= 0; ii
< 50; ii
++) {
1820 bfd_coff_swap_sym_in (symfile_bfd
,
1821 symtable
+ (symno
*local_symesz
), symbol
);
1822 if (symbol
->n_sclass
== C_FCN
&& 0 == strcmp (symbol
->n_name
, ".bf"))
1824 symno
+= symbol
->n_numaux
+1;
1827 printf ("GDB Error: `.bf' not found.\n");
1831 /* take aux entry and return its lineno */
1833 bfd_coff_swap_aux_in (symfile_bfd
, symtable
+(symno
*local_symesz
),
1834 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
1836 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1839 /* Support for line number handling */
1841 /* This function is called for every section; it finds the outer limits
1842 * of the line table (minimum and maximum file offset) so that the
1843 * mainline code can read the whole thing for efficiency.
1846 find_linenos(abfd
, asect
, vpinfo
)
1851 struct coff_symfile_info
*info
;
1853 file_ptr offset
, maxoff
;
1855 count
= asect
->lineno_count
;
1857 if (strcmp (asect
->name
, ".text") || count
== 0)
1860 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1861 info
= (struct coff_symfile_info
*)vpinfo
;
1862 offset
= asect
->line_filepos
;
1863 maxoff
= offset
+ size
;
1865 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1866 info
->min_lineno_offset
= offset
;
1868 if (maxoff
> info
->max_lineno_offset
)
1869 info
->max_lineno_offset
= maxoff
;
1873 /* Read in all the line numbers for fast lookups later. Leave them in
1874 external (unswapped) format in memory; we'll swap them as we enter
1875 them into GDB's data structures. */
1878 init_lineno (abfd
, offset
, size
)
1885 if (bfd_seek(abfd
, offset
, 0) < 0)
1888 linetab
= (char *) xmalloc(size
);
1890 val
= bfd_read(linetab
, 1, size
, abfd
);
1894 linetab_offset
= offset
;
1895 linetab_size
= size
;
1896 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1900 /* dbx allows the text of a symbol name to be continued into the
1901 next symbol name! When such a continuation is encountered
1902 (a \ at the end of the text of a name)
1903 call this function to get the continuation. */
1904 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1907 #undef next_symbol_text
1908 #define next_symbol_text() \
1909 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1912 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
1913 the proper type node fora given builtin type #. */
1922 printf ("ERROR!, unknown built-in type!\n");
1926 read_type_number (pp
, typenums
);
1928 /* default types are defined in dbxstclass.h. */
1929 switch ( typenums
[1] ) {
1931 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1933 return lookup_fundamental_type (current_objfile
, FT_CHAR
);
1935 return lookup_fundamental_type (current_objfile
, FT_SHORT
);
1937 return lookup_fundamental_type (current_objfile
, FT_LONG
);
1939 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
1941 return lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
1943 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
1945 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1947 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1949 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
1951 return lookup_fundamental_type (current_objfile
, FT_VOID
);
1953 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1955 return lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
1957 return lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
1959 /* requires a builtin `integer' */
1960 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1962 return lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
1964 /* requires builtin `short real' */
1965 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1967 /* requires builtin `real' */
1968 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1970 printf ("ERROR! Unknown builtin type -%d\n", typenums
[1]);
1975 #if 0 /* Seems to be unused, don't bother converting from old misc function
1976 vector usage to new minimal symbol tables. FIXME: Delete this? */
1978 /* if we now nothing about a function but its address, make a function symbol
1979 out of it with the limited knowladge you have. This will be used when
1980 somebody refers to a function, which doesn't exist in the symbol table,
1981 but is in the minimal symbol table. */
1984 build_function_symbol (ind
, objfile
)
1986 struct objfile
*objfile
;
1988 struct symbol
*sym
=
1989 (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1990 SYMBOL_NAME (sym
) = misc_function_vector
[ind
].name
;
1991 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1992 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1993 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1994 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (current_objfile
, FT_INTEGER
));
1995 SYMBOL_BLOCK_VALUE (sym
) = (struct block
*)
1996 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct block
));
1997 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) = misc_function_vector
[ind
].address
;
2006 /* This routine is executed once per executable. We should start with a
2007 fresh include table per executable. */
2013 inclIndx
= inclLength
= inclDepth
= NULL
;
2017 aixcoff_symfile_init (sf
)
2020 bfd
*abfd
= sf
->sym_bfd
;
2022 /* Allocate struct to keep track of the symfile */
2023 /* FIXME memory leak */
2024 sf
->sym_private
= xmalloc(sizeof (struct coff_symfile_info
));
2027 * Save startup file's range of PC addresses to help
2028 * blockframe.c decide where the bottom of the stack is.
2030 if (bfd_get_file_flags(abfd
) & EXEC_P
) {
2031 entry_point
= bfd_get_start_address(abfd
);
2034 /* set the startup file to be an empty range. */
2035 startup_file_start
= 0;
2036 startup_file_end
= 0;
2042 init_stringtab(abfd
, offset
, objfile
)
2045 struct objfile
*objfile
;
2049 unsigned char lengthbuf
[4];
2051 if (bfd_seek(abfd
, offset
, 0) < 0)
2054 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
2055 length
= bfd_h_get_32(abfd
, lengthbuf
);
2057 /* If no string table is needed, then the file may end immediately
2058 after the symbols. Just return with `strtbl' set to null. */
2060 if (val
!= sizeof length
|| length
< sizeof length
)
2063 /* Allocate string table from symbol_obstack. We will need this table
2064 as long as we have its symbol table around. */
2066 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
2070 bcopy(&length
, strtbl
, sizeof length
);
2071 if (length
== sizeof length
)
2074 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
2076 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
2083 init_debugsection(abfd
)
2086 register sec_ptr secp
;
2087 bfd_size_type length
;
2094 secp
= bfd_get_section_by_name(abfd
, ".debug");
2098 if (!(length
= bfd_section_size(abfd
, secp
)))
2101 debugsec
= (char *) xmalloc ((unsigned)length
);
2102 if (debugsec
== NULL
)
2105 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
2106 printf ("Can't read .debug section from symbol file\n");
2121 /* aixcoff version of symbol file read. */
2124 aixcoff_symfile_read (sf
, addr
, mainline
)
2129 int num_symbols
; /* # of symbols */
2130 int symtab_offset
; /* symbol table and */
2131 int stringtab_offset
; /* string table file offsets */
2134 struct coff_symfile_info
*info
= (void*) sf
->sym_private
;
2137 symfile_bfd
= abfd
= sf
->objfile
->obfd
;
2138 name
= sf
->objfile
->name
;
2140 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
2141 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
2142 stringtab_offset
= symtab_offset
+
2143 num_symbols
* coff_data(abfd
)->local_symesz
;
2145 info
->min_lineno_offset
= 0;
2146 info
->max_lineno_offset
= 0;
2147 bfd_map_over_sections (abfd
, find_linenos
, info
);
2149 /* FIXME! This stuff should move into symfile_init */
2150 if (info
->min_lineno_offset
!= 0
2151 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
2153 /* only read in the line # table if one exists */
2154 val
= init_lineno(abfd
, info
->min_lineno_offset
,
2155 info
->max_lineno_offset
- info
->min_lineno_offset
);
2158 error("\"%s\": error reading line numbers\n", name
);
2161 val
= init_stringtab(abfd
, stringtab_offset
, sf
->objfile
);
2163 error ("\"%s\": can't get string table", name
);
2166 if (init_debugsection(abfd
) < 0) {
2167 error ("Error reading .debug section of `%s'\n", name
);
2170 /* Position to read the symbol table. Do not read it all at once. */
2171 val
= bfd_seek(abfd
, (long)symtab_offset
, 0);
2173 perror_with_name(name
);
2175 if (bfd_tell(abfd
) != symtab_offset
)
2178 init_minimal_symbol_collection ();
2179 make_cleanup (discard_minimal_symbols
, 0);
2181 #ifdef XCOFF_INIT_LOADINFO
2183 XCOFF_INIT_LOADINFO ();
2186 /* Now that the executable file is positioned at symbol table,
2187 process it and define symbols accordingly. */
2189 read_xcoff_symtab(sf
->objfile
, num_symbols
);
2191 make_cleanup (free_debugsection
, 0);
2193 /* Sort symbols alphabetically within each block. */
2196 /* Install any minimal symbols that have been collected as the current
2197 minimal symbols for this objfile. */
2199 install_minimal_symbols (sf
-> objfile
);
2201 /* Make a default for file to list. */
2202 select_source_symtab (0);
2205 /* Register our ability to parse symbols for aixcoff BFD files. */
2207 static struct sym_fns aixcoff_sym_fns
=
2209 "aixcoff-rs6000", 15,
2210 aixcoff_new_init
, aixcoff_symfile_init
,
2211 aixcoff_symfile_read
,
2215 _initialize_xcoffread ()
2217 add_symtab_fns(&aixcoff_sym_fns
);
2221 /* In order to handle forward type references, we needed to have this old
2222 routine. Try printing the type of member `p' in the following structure
2223 in a dbx environment.
2231 /* Smash TYPE to be a type of pointers to TO_TYPE.
2232 If TO_TYPE is not permanent and has no pointer-type yet,
2233 record TYPE as its pointer-type. */
2236 smash_to_pointer_type (type
, to_type
)
2237 struct type
*type
, *to_type
;
2239 int type_permanent
= (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
);
2241 bzero (type
, sizeof (struct type
));
2242 TYPE_TARGET_TYPE (type
) = to_type
;
2243 /* We assume the machine has only one representation for pointers! */
2244 TYPE_LENGTH (type
) = sizeof (char *);
2245 TYPE_CODE (type
) = TYPE_CODE_PTR
;
2247 /* ??? TYPE_TARGET_TYPE and TYPE_MAIN_VARIANT are the same. You can't do
2248 this. It will break the target type!!!
2249 TYPE_MAIN_VARIANT (type) = type;
2253 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2255 if (TYPE_POINTER_TYPE (to_type
) == 0
2256 && (!(TYPE_FLAGS (to_type
) & TYPE_FLAG_PERM
)
2259 TYPE_POINTER_TYPE (to_type
) = type
;
2269 fatal ("internals eror: builtin_type called!");
2271 #endif /* IBM6000 */
2276 #if defined (DEBUG) && defined (IBM6000) /* Needs both defined */
2281 printf ("===STRING TABLE DUMP...\n\n");
2282 for ( ii
=0; ii
< strtbl_len
; ++ii
)
2283 printf ("%c", isprint (*(strtbl
+ii
)) ? *(strtbl
+ii
) : ' ');
2288 dump_linetable (ltb
)
2289 struct linetable
*ltb
;
2292 for (ii
=0; ii
< ltb
->nitems
; ++ii
)
2293 printf ("line: %d, addr: 0x%x\n", ltb
->item
[ii
].line
, ltb
->item
[ii
].pc
);
2300 printf ("0x%x: name: %s\n", typeP
, typeP
->name
? typeP
->name
: "(nil)");
2303 char *dump_namespace ();
2304 char *dump_addrclass ();
2310 printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n",
2311 pp
->name
, dump_namespace (pp
->namespace),
2312 dump_addrclass (pp
->class), pp
->type
,
2313 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_START(SYMBOL_BLOCK_VALUE(pp
))
2315 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_END(SYMBOL_BLOCK_VALUE(pp
)) : 0);
2323 static char *ns_name
[] = {
2324 "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"};
2327 case UNDEF_NAMESPACE
:
2329 case STRUCT_NAMESPACE
:
2330 case LABEL_NAMESPACE
:
2334 return "***ERROR***";
2340 int ac
; /* address class */
2342 static char *ac_name
[] = {
2369 case LOC_CONST_BYTES
:
2371 return ac_name
[ac
];
2373 return "***ERROR***";
2381 printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp
->startaddr
, pp
->endaddr
);
2382 for (ii
=0; ii
< pp
->nsyms
; ++ii
)
2383 dump_symbol (pp
->sym
[ii
]);
2387 dump_blockvector (pp
)
2388 struct blockvector
*pp
;
2391 for (ii
=0; ii
< pp
->nblocks
; ++ii
)
2392 dump_block (pp
->block
[ii
]);
2397 dump_last_symtab (pp
)
2400 for ( ; pp
; pp
= pp
->next
) {
2401 if ( pp
->next
== 0 ) {
2402 printf ("SYMTAB NAME: %s\n", pp
->filename
);
2403 dump_blockvector (pp
->blockvector
);
2412 for ( ; pp
; pp
= pp
->next
) {
2413 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
2414 /* if (pp->linetable)
2415 dump_linetable (pp->linetable); */
2416 dump_blockvector (pp
->blockvector
);
2421 dump_symtab_lines (pp
)
2424 for ( ; pp
; pp
= pp
->next
) {
2425 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
2427 dump_linetable (pp
->linetable
);
2428 /* dump_blockvector (pp->blockvector); */
2437 for (ii
=0; ii
< of
->minimal_symbol_count
; ++ii
)
2438 printf ("name: %s, addr: 0x%x, info: 0x%x\n",
2439 of
->msymbols
[ii
].name
,
2440 of
->msymbols
[ii
].address
,
2441 of
->msymbols
[ii
].info
);