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 /* AIX COFF names have a preceeding dot `.' */
28 #define NAMES_HAVE_DOT 1
30 #include <sys/types.h>
35 #include <sys/param.h>
43 #include "internalcoff.h" /* FIXME, internal data from BFD */
44 #include "libcoff.h" /* FIXME, internal data from BFD */
45 #include "coff-rs6000.h" /* FIXME, raw file-format guts of xcoff */
49 static void enter_line_range ();
50 static struct symbol
*process_xcoff_symbol ();
51 static int read_symbol_nvalue ();
52 static int read_symbol_lineno ();
55 /* Simplified internal version of coff symbol table information */
59 int c_symnum
; /* symbol number of this entry */
60 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
67 /* The COFF line table, in raw form. */
68 static char *linetab
= NULL
; /* Its actual contents */
69 static long linetab_offset
; /* Its offset in the file */
70 static unsigned long linetab_size
; /* Its size */
72 /* last function's saved coff symbol `cs' */
74 static struct coff_symbol fcn_cs_saved
;
76 static bfd
*symfile_bfd
;
78 /* Core address of start and end of text of current source file.
79 This is calculated from the first function seen after a C_FILE
82 static CORE_ADDR cur_src_start_addr
;
83 static CORE_ADDR cur_src_end_addr
;
85 /* Core address of the end of the first object file. */
87 static CORE_ADDR first_object_file_end
;
89 /* pointer to the string table */
92 /* length of the string table */
93 static int strtbl_len
;
95 /* pointer to debug section */
96 static char *debugsec
;
98 /* pointer to the a.out symbol table */
101 /* initial symbol-table-debug-string vector length */
103 #define INITIAL_STABVECTOR_LENGTH 40
105 struct pending_stabs
*global_stabs
;
106 struct pending_stabs
*file_stabs
;
108 /* Nonzero if within a function (so symbols should be local,
109 if nothing says specifically). */
113 /* Local variables that hold the shift and mask values for the
114 COFF file that we are currently reading. These come back to us
115 from BFD, and are referenced by their macro names, as well as
116 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
117 macros from ../internalcoff.h . */
119 static unsigned local_n_btshft
;
120 static unsigned local_n_tmask
;
123 #define N_BTSHFT local_n_btshft
125 #define N_TMASK local_n_tmask
127 /* Local variables that hold the sizes in the file of various COFF structures.
128 (We only need to know this to read them from the file -- BFD will then
129 translate the data in them, into `internal_xxx' structs in the right
130 byte order, alignment, etc.) */
132 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 */
153 /* Call sort_syms to sort alphabetically
154 the symbols of each block of each symtab. */
157 compare_symbols (s1
, s2
)
158 struct symbol
**s1
, **s2
;
160 /* Names that are less should come first. */
161 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
165 /* For symbols of the same name, registers should come first. */
166 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
167 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
171 /* Sort a vector of symbols by their value. */
176 register struct symtab
*s
;
178 register struct blockvector
*bv
;
179 register struct block
*b
;
181 for (s
= symtab_list
; s
; s
= s
->next
)
183 bv
= BLOCKVECTOR (s
);
184 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
185 for (i
= 0; i
< nbl
; i
++)
187 b
= BLOCKVECTOR_BLOCK (bv
, i
);
188 if (BLOCK_SHOULD_SORT (b
))
189 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
190 sizeof (struct symbol
*), compare_symbols
);
196 /* add a given stab string into given stab vector. */
199 add_stab_to_list (stabname
, stabvector
)
201 struct pending_stabs
**stabvector
;
203 if ( *stabvector
== NULL
) {
204 *stabvector
= (struct pending_stabs
*)
205 xmalloc (sizeof (struct pending_stabs
) +
206 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
207 (*stabvector
)->count
= 0;
208 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
210 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
211 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
212 *stabvector
= (struct pending_stabs
*)
213 xrealloc (*stabvector
, sizeof (struct pending_stabs
) +
214 (*stabvector
)->length
* sizeof (char*));
216 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
220 /* for all the stabs in a given stab vector, build appropriate types
221 and fix their symbols in given symbol vector. */
224 patch_block_stabs (symbols
, stabs
)
225 struct pending
*symbols
;
226 struct pending_stabs
*stabs
;
233 /* for all the stab entries, find their corresponding symbols and
234 patch their types! */
236 for (ii
=0; ii
< stabs
->count
; ++ii
) {
237 char *name
= stabs
->stab
[ii
];
238 char *pp
= (char*) index (name
, ':');
239 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
241 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
246 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
247 SYMBOL_TYPE (sym
) = lookup_function_type (read_type (&pp
));
249 SYMBOL_TYPE (sym
) = read_type (&pp
);
254 /* Enter a given range of lines into the line vector.
255 can be called in the following two ways:
256 enter_line_range (subfile, beginoffset, endoffset, 0, firstLine) or
257 enter_line_range (subfile, beginoffset, 0, endaddr, firstLine) */
260 enter_line_range (subfile
, beginoffset
, endoffset
, endaddr
, firstLine
)
261 struct subfile
*subfile
; /* which sub-file to put line#s in */
262 unsigned beginoffset
, endoffset
; /* offsets to line table */
268 struct internal_lineno lptr
;
269 unsigned local_linesz
= coff_data (symfile_bfd
)->local_linesz
;
271 pp
= &linetab
[beginoffset
- linetab_offset
];
272 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
273 : &linetab
[linetab_size
-1];
275 while (pp
<= limit
) {
277 /* Swap and align this lineno entry into lptr. */
278 bfd_coff_swap_lineno_in (symfile_bfd
, pp
, &lptr
);
280 /* find the address this line represents */
282 lptr
.l_addr
.l_paddr
: read_symbol_nvalue (symtbl
, lptr
.l_addr
.l_symndx
);
284 if (endaddr
&& addr
>= endaddr
)
287 if (lptr
.l_lnno
== 0) {
288 *firstLine
= read_symbol_lineno (symtbl
, lptr
.l_addr
.l_symndx
);
292 record_line (subfile
, *firstLine
+ lptr
.l_lnno
, addr
);
299 /* Save the vital information for use when closing off the current file.
300 NAME is the file name the symbols came from, START_ADDR is the first
301 text address for the file, and SIZE is the number of bytes of text. */
303 #define complete_symtab(name, start_addr) { \
304 last_source_file = savestring (name, strlen (name)); \
305 cur_src_start_addr = start_addr; \
309 /* Refill the symbol table input buffer
310 and set the variables that control fetching entries from it.
311 Reports an error if no data available.
312 This function can read past the end of the symbol table
313 (into the string table) but this does no harm. */
315 /* Reading symbol table has to be fast! Keep the followings as macros, rather
318 #define RECORD_MISC_FUNCTION(NAME, ADDR, TYPE, ALLOCED) \
322 namestr = (NAME) + 1; \
324 namestr = obstack_copy0 (symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
327 prim_record_misc_function (namestr, (ADDR), (TYPE)); \
328 last_recorded_fun = (ADDR); \
333 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
334 nested. At any given time, a symbol can only be in one static block.
335 This is the base address of current static block, zero if non exists. */
337 static int static_block_base
= 0;
339 /* true if space for symbol name has been allocated. */
341 static int symname_alloced
= 0;
343 /* read the whole symbol table of a given bfd. */
346 read_xcoff_symtab (objfile
, nsyms
)
347 struct objfile
*objfile
; /* Object file we're reading from */
348 int nsyms
; /* # of symbols */
350 bfd
*abfd
= objfile
->obfd
;
351 /* char *symtbl; */ /* Raw symbol table base */
352 char *raw_symbol
; /* Pointer into raw seething symbol table */
353 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
354 struct internal_syment symbol
[1];
355 union internal_auxent main_aux
[1];
356 struct coff_symbol cs
[1];
357 CORE_ADDR file_start_addr
= 0;
358 CORE_ADDR file_end_addr
= 0;
360 int next_file_symnum
= -1;
361 int just_started
= 1;
367 long fcn_line_offset
;
370 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
371 union internal_auxent fcn_aux_saved
;
372 struct context_stack
*new;
374 char *filestring
= " _start_ "; /* Name of the current file. */
375 char *last_seen_csect
;
376 int last_recorded_fun
= 0; /* last recorded fun. value */
378 /* Get the appropriate COFF "constants" related to the file we're handling. */
379 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
380 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
381 local_symesz
= coff_data (abfd
)->local_symesz
;
383 last_source_file
= 0;
385 last_recorded_fun
= 0;
387 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
389 first_object_file_end
= 0;
391 /* Allocate space for the entire symbol table at once, and read it
392 all in. The bfd is already positioned at the beginning of
395 size
= coff_data (abfd
)->local_symesz
* nsyms
;
396 symtbl
= xmalloc (size
);
398 val
= bfd_read (symtbl
, size
, 1, abfd
);
400 perror_with_name ("reading symbol table");
404 while (symnum
< nsyms
) {
406 QUIT
; /* make this command interruptable. */
408 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
409 /* read one symbol into `cs' structure. After processing the whole symbol
410 table, only string table will be kept in memory, symbol table and debug
411 section of aixcoff will be freed. Thus we can mark symbols with names
412 in string table as `alloced'. */
416 /* Swap and align the symbol into a reasonable C structure. */
417 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
419 cs
->c_symnum
= symnum
;
420 cs
->c_nsyms
= symbol
->n_numaux
;
421 if (symbol
->n_zeroes
) {
423 /* We must use the original, unswapped, name here so the name field
424 pointed to by cs->c_name will persist throughout xcoffread. If
425 we use the new field, it gets overwritten for each symbol. */
426 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
427 } else if (symbol
->n_sclass
& 0x80) {
428 cs
->c_name
= debugsec
+ symbol
->n_offset
;
430 } else { /* in string table */
431 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
434 cs
->c_value
= symbol
->n_value
;
435 cs
->c_sclass
= symbol
->n_sclass
& 0xff;
436 cs
->c_secnum
= symbol
->n_scnum
;
437 cs
->c_type
= (unsigned)symbol
->n_type
;
439 raw_symbol
+= coff_data (abfd
)->local_symesz
;
442 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
444 /* Skip all the auxents associated with this symbol. */
445 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
446 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
451 /* if symbol name starts with ".$" or "$", ignore it. */
452 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
455 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
456 if (last_source_file
)
457 end_symtab (cur_src_end_addr
, 1, 1, objfile
);
459 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
460 cur_src_end_addr
= first_object_file_end
;
461 /* done with all files, everything from here on is globals */
464 /* if explicitly specified as a function, treat is as one. */
465 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
466 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
468 goto function_entry_point
;
471 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
473 /* dealing with a symbol with a csect entry. */
475 # define CSECT(PP) ((PP)->x_csect)
476 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
477 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
478 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
479 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
481 /* Convert the auxent to something we can access. */
482 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
485 switch (CSECT_SMTYP (main_aux
)) {
488 continue; /* ignore all external references. */
490 case XTY_SD
: /* a section description. */
492 switch (CSECT_SCLAS (main_aux
)) {
494 case XMC_PR
: /* a `.text' csect. */
497 /* A program csect is seen.
499 We have to allocate one symbol table for each program csect. Normally
500 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
501 CU might include more than one prog csect, and they don't have to be
502 adjacent in terms of the space they occupy in memory. Thus, one single
503 CU might get fragmented in the memory and gdb's file start and end address
504 approach does not work! */
506 if (last_seen_csect
) {
507 complete_symtab (filestring
, file_start_addr
);
508 cur_src_end_addr
= file_end_addr
;
509 end_symtab (file_end_addr
, 1, 1, objfile
);
510 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
513 /* If this is the very first csect seen, basically `__start'. */
515 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
519 file_start_addr
= cs
->c_value
;
520 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
522 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
523 last_seen_csect
= cs
->c_name
;
524 RECORD_MISC_FUNCTION (cs
->c_name
, cs
->c_value
, mf_text
, symname_alloced
);
532 /* If the section is not a data description, ignore it. Note that
533 uninitialized data will show up as XTY_CM/XMC_RW pair. */
536 #ifdef XCOFF_ADD_TOC_TO_LOADINFO
537 XCOFF_ADD_TOC_TO_LOADINFO (cs
->c_value
);
539 /* fall down to default case. */
541 case XMC_TC
: /* ignore toc entries */
542 default : /* any other XMC_XXX */
546 break; /* switch CSECT_SCLAS() */
550 /* a function entry point. */
551 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
553 function_entry_point
:
554 if (cs
->c_value
!= last_recorded_fun
)
555 RECORD_MISC_FUNCTION (cs
->c_name
, cs
->c_value
, mf_text
,
558 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
559 fcn_start_addr
= cs
->c_value
;
561 /* save the function header info, which will be used
562 when `.bf' is seen. */
564 fcn_aux_saved
= *main_aux
;
568 /* shared library function entry point. */
569 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
570 if (last_recorded_fun
!= cs
->c_value
)
571 RECORD_MISC_FUNCTION (cs
->c_name
, cs
->c_value
, mf_text
,
577 default : /* all other XTY_XXXs */
579 } /* switch CSECT_SMTYP() */
582 switch (cs
->c_sclass
) {
586 /* c_value field contains symnum of next .file entry in table
587 or symnum of first global after last .file. */
589 next_file_symnum
= cs
->c_value
;
591 /* complete symbol table for last object file containing
592 debugging information. */
594 /* Whether or not there was a csect in the previous file, we have
595 to call `end_symtab' and `start_symtab' to reset type_vector,
596 line_vector, etc. structures. */
597 complete_symtab (filestring
, file_start_addr
);
598 cur_src_end_addr
= file_end_addr
;
599 end_symtab (file_end_addr
, 1, 1, objfile
);
600 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
603 /* reset file start and end addresses. A compilation unit with no text
604 (only data) should have zero file boundaries. */
605 file_start_addr
= file_end_addr
= 0;
607 filestring
= cs
->c_name
;
612 if (strcmp (cs
->c_name
, ".bf") == 0) {
614 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
619 /* value contains address of first non-init type code */
620 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
621 contains line number of '{' } */
622 fcn_first_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
624 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
625 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
626 /* mark_first_line (fcn_line_offset, cs->c_symnum); */
628 new = push_context (0, fcn_start_addr
);
629 new->name
= process_xcoff_symbol (&fcn_cs_saved
);
631 else if (strcmp (cs
->c_name
, ".ef") == 0) {
633 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
636 /* the value of .ef is the address of epilogue code;
637 not useful for gdb */
638 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
639 contains number of lines to '}' */
641 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
643 enter_linenos (fcn_line_offset
, fcn_first_line
,
644 fcn_first_line
+ fcn_last_line
);
647 new = pop_context ();
648 if (context_stack_depth
!= 0)
649 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
652 finish_block (new->name
, &local_symbols
, new->old_blocks
,
654 fcn_cs_saved
.c_value
+
655 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
);
660 case C_BSTAT
: /* begin static block */
661 static_block_base
= read_symbol_nvalue (symtbl
, cs
->c_value
);
664 case C_ESTAT
: /* end of static block */
665 static_block_base
= 0;
668 case C_ARG
: /* These are not implemented. */
674 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
677 case C_HIDEXT
: /* ignore these.. */
682 case C_BINCL
: /* beginning of include file */
684 start_subfile (cs
->c_name
, (char *)0);
685 fcn_first_line
= cs
->c_value
; /* Offset to first lineno of file */
688 case C_EINCL
: /* end of include file */
689 fcn_last_line
= cs
->c_value
; /* Offset to last line number */
691 enter_line_range (current_subfile
, fcn_first_line
, cs
->c_value
, 0,
694 start_subfile (pop_subfile (), (char *)0);
698 if (strcmp (cs
->c_name
, ".bb") == 0) {
700 new = push_context (depth
, cs
->c_value
);
702 else if (strcmp (cs
->c_name
, ".eb") == 0) {
703 new = pop_context ();
704 if (depth
!= new->depth
)
705 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
709 if (local_symbols
&& context_stack_depth
> 0) {
710 /* Make a block for the local symbols within. */
711 finish_block (new->name
, &local_symbols
, new->old_blocks
,
712 new->start_addr
, cs
->c_value
);
714 local_symbols
= new->locals
;
719 (void) process_xcoff_symbol (cs
);
725 if (last_source_file
)
726 end_symtab (cur_src_end_addr
, 1, 1, objfile
);
731 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
732 (SYMBOL2) = (struct symbol *) \
733 obstack_alloc (symbol_obstack, sizeof (struct symbol)); \
734 *(SYMBOL2) = *(SYMBOL1);
737 #define SYMNAME_ALLOC(NAME, ALLOCED) \
738 (ALLOCED) ? (NAME) : obstack_copy0 (symbol_obstack, (NAME), strlen (NAME));
742 /* process one xcoff symbol. */
744 static struct symbol
*
745 process_xcoff_symbol (cs
)
746 register struct coff_symbol
*cs
;
748 struct symbol onesymbol
;
749 register struct symbol
*sym
= &onesymbol
;
750 struct symbol
*sym2
= NULL
;
752 char *name
, *pp
, *qq
;
758 bzero (sym
, sizeof (struct symbol
));
760 /* default assumptions */
761 SYMBOL_VALUE (sym
) = cs
->c_value
;
762 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
764 if (ISFCN (cs
->c_type
)) {
766 /* At this point, we don't know the type of the function and assume it
767 is int. This will be patched with the type from its stab entry later
768 on in patch_block_stabs () */
770 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
771 SYMBOL_TYPE (sym
) = lookup_function_type (builtin_type_int
);
773 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
774 SYMBOL_DUP (sym
, sym2
);
776 if (cs
->c_sclass
== C_EXT
)
777 add_symbol_to_list (sym2
, &global_symbols
);
778 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
779 add_symbol_to_list (sym2
, &file_symbols
);
784 /* in case we can't figure out the type, default is `int'. */
785 SYMBOL_TYPE (sym
) = builtin_type_int
;
787 switch (cs
->c_sclass
)
790 if (fcn_cs_saved
.c_sclass
== C_EXT
)
791 add_stab_to_list (name
, &global_stabs
);
793 add_stab_to_list (name
, &file_stabs
);
796 case C_DECL
: /* a type decleration?? */
797 qq
= (char*) index (name
, ':');
798 if (!qq
) /* skip if there is no ':' */
802 ttype
= SYMBOL_TYPE (sym
) = read_type (&pp
);
804 /* read_type() will return null if type (or tag) definition was
805 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
806 there is no need to keep it in symbol table. */
808 if (!ttype
|| name
== qq
)
812 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
813 else if (qq
[1] == 't')
814 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
816 printf ("ERROR: Unrecognized stab string.\n");
820 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
821 SYMBOL_NAME (sym
) = obsavestring (name
, qq
-name
);
823 if (SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
)
824 TYPE_NAME (ttype
) = concat (
825 TYPE_CODE (ttype
) == TYPE_CODE_UNION
? "union " :
826 TYPE_CODE (ttype
) == TYPE_CODE_STRUCT
? "struct " : "enum ",
827 SYMBOL_NAME (sym
), NULL
);
829 else if (!TYPE_NAME (ttype
)) /* else, regular typedef. */
830 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
832 SYMBOL_DUP (sym
, sym2
);
834 (sym2
, within_function
? &local_symbols
: &file_symbols
);
838 add_stab_to_list (name
, &global_stabs
);
842 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
844 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
845 SYMBOL_CLASS (sym
) = LOC_ARG
;
847 SYMBOL_TYPE (sym
) = read_type (&pp
);
848 SYMBOL_DUP (sym
, sym2
);
849 add_symbol_to_list (sym2
, &local_symbols
);
853 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
855 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
856 SYMBOL_CLASS (sym
) = LOC_STATIC
;
857 SYMBOL_VALUE (sym
) += static_block_base
;
859 SYMBOL_TYPE (sym
) = read_type (&pp
);
860 SYMBOL_DUP (sym
, sym2
);
862 (sym2
, within_function
? &local_symbols
: &file_symbols
);
866 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
868 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
869 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
871 SYMBOL_TYPE (sym
) = read_type (&pp
);
872 SYMBOL_DUP (sym
, sym2
);
873 add_symbol_to_list (sym2
, &local_symbols
);
877 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
878 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
879 SYMBOL_DUP (sym
, sym2
);
880 add_symbol_to_list (sym2
, &local_symbols
);
884 SYMBOL_CLASS (sym
) = LOC_STATIC
;
885 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
886 SYMBOL_DUP (sym
, sym2
);
887 add_symbol_to_list (sym2
, &global_symbols
);
891 SYMBOL_CLASS (sym
) = LOC_STATIC
;
892 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
893 SYMBOL_DUP (sym
, sym2
);
895 (sym2
, within_function
? &local_symbols
: &file_symbols
);
899 printf ("ERROR! C_REG is not fully implemented!\n");
900 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
901 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
902 SYMBOL_DUP (sym
, sym2
);
903 add_symbol_to_list (sym2
, &local_symbols
);
907 pp
= (char*) index (name
, ':');
908 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
909 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (cs
->c_value
);
911 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
914 SYMBOL_TYPE (sym
) = read_type (&pp
);
917 /* else this is not a stab entry, suppose the type is either
918 `int' or `float', depending on the register class. */
920 SYMBOL_TYPE (sym
) = (SYMBOL_VALUE (sym
) < 32) ?
921 builtin_type_int
: builtin_type_float
;
923 SYMBOL_DUP (sym
, sym2
);
924 add_symbol_to_list (sym2
, &local_symbols
);
928 printf ("ERROR: Unexpected storage class: %d.\n", cs
->c_sclass
);
937 read_symbol_nvalue (symtable
, symno
)
941 struct internal_syment symbol
[1];
943 bfd_coff_swap_sym_in (symfile_bfd
, symtable
+ (symno
*local_symesz
), symbol
);
944 return symbol
->n_value
;
949 read_symbol_lineno (symtable
, symno
)
953 struct internal_syment symbol
[1];
954 union internal_auxent main_aux
[1];
958 for (ii
= 0; ii
< 50; ii
++) {
959 bfd_coff_swap_sym_in (symfile_bfd
,
960 symtable
+ (symno
*local_symesz
), symbol
);
961 if (symbol
->n_sclass
== C_FCN
&& 0 == strcmp (symbol
->n_name
, ".bf"))
963 symno
+= 1 + symbol
->n_numaux
+1;
966 printf ("GDB Error: `.bf' not found.\n");
970 /* take aux entry and return its lineno */
972 bfd_coff_swap_aux_in (symfile_bfd
, symtable
+(symno
*local_symesz
),
973 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
975 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
978 /* Support for line number handling */
980 /* This function is called for every section; it finds the outer limits
981 * of the line table (minimum and maximum file offset) so that the
982 * mainline code can read the whole thing for efficiency.
985 find_linenos(abfd
, asect
, vpinfo
)
990 struct coff_symfile_info
*info
;
992 file_ptr offset
, maxoff
;
994 count
= asect
->lineno_count
;
999 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1000 info
= (struct coff_symfile_info
*)vpinfo
;
1001 offset
= asect
->line_filepos
;
1002 maxoff
= offset
+ size
;
1004 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1005 info
->min_lineno_offset
= offset
;
1007 if (maxoff
> info
->max_lineno_offset
)
1008 info
->max_lineno_offset
= maxoff
;
1012 /* Read in all the line numbers for fast lookups later. Leave them in
1013 external (unswapped) format in memory; we'll swap them as we enter
1014 them into GDB's data structures. */
1017 init_lineno (abfd
, offset
, size
)
1024 if (bfd_seek(abfd
, offset
, 0) < 0)
1027 linetab
= (char *) xmalloc(size
);
1029 val
= bfd_read(linetab
, 1, size
, abfd
);
1033 linetab_offset
= offset
;
1034 linetab_size
= size
;
1035 make_cleanup(free
, linetab
); /* Be sure it gets de-allocated. */
1044 printf ("===STRING TABLE DUMP...\n\n");
1045 for ( ii
=0; ii
< strtbl_len
; ++ii
)
1046 printf ("%c", isprint (*(strtbl
+ii
)) ? *(strtbl
+ii
) : ' ');
1051 dump_linetable (ltb
)
1052 struct linetable
*ltb
;
1055 for (ii
=0; ii
< ltb
->nitems
; ++ii
)
1056 printf ("line: %d, addr: 0x%x\n", ltb
->item
[ii
].line
, ltb
->item
[ii
].pc
);
1063 printf ("0x%x: name: %s\n", typeP
, typeP
->name
? typeP
->name
: "(nil)");
1066 char *dump_namespace ();
1067 char *dump_addrclass ();
1073 printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n",
1074 pp
->name
, dump_namespace (pp
->namespace),
1075 dump_addrclass (pp
->class), pp
->type
,
1076 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_START(SYMBOL_BLOCK_VALUE(pp
))
1078 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_END(SYMBOL_BLOCK_VALUE(pp
)) : 0);
1086 static char *ns_name
[] = {
1087 "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"};
1090 case UNDEF_NAMESPACE
:
1092 case STRUCT_NAMESPACE
:
1093 case LABEL_NAMESPACE
:
1097 return "***ERROR***";
1103 int ac
; /* address class */
1105 static char *ac_name
[] = {
1132 case LOC_CONST_BYTES
:
1134 return ac_name
[ac
];
1136 return "***ERROR***";
1144 printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp
->startaddr
, pp
->endaddr
);
1145 for (ii
=0; ii
< pp
->nsyms
; ++ii
)
1146 dump_symbol (pp
->sym
[ii
]);
1150 dump_blockvector (pp
)
1151 struct blockvector
*pp
;
1154 for (ii
=0; ii
< pp
->nblocks
; ++ii
)
1155 dump_block (pp
->block
[ii
]);
1160 dump_last_symtab (pp
)
1163 for ( ; pp
; pp
= pp
->next
) {
1164 if ( pp
->next
== 0 ) {
1165 printf ("SYMTAB NAME: %s\n", pp
->filename
);
1166 dump_blockvector (pp
->blockvector
);
1175 for ( ; pp
; pp
= pp
->next
) {
1176 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
1177 /* if (pp->linetable)
1178 dump_linetable (pp->linetable); */
1179 dump_blockvector (pp
->blockvector
);
1184 dump_symtab_lines (pp
)
1187 for ( ; pp
; pp
= pp
->next
) {
1188 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
1190 dump_linetable (pp
->linetable
);
1191 /* dump_blockvector (pp->blockvector); */
1199 for (ii
=0; ii
< misc_function_count
; ++ii
)
1200 printf ("name: %s, addr: 0x%x\n",
1201 misc_function_vector
[ii
].name
,
1202 misc_function_vector
[ii
].address
);
1206 /* dbx allows the text of a symbol name to be continued into the
1207 next symbol name! When such a continuation is encountered
1208 (a \ at the end of the text of a name)
1209 call this function to get the continuation. */
1210 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1213 #define next_symbol_text() \
1214 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1217 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
1218 the proper type node fora given builtin type #. */
1227 printf ("ERROR!, unknown built-in type!\n");
1231 read_type_number (pp
, typenums
);
1233 /* default types are defined in dbxstclass.h. */
1234 switch ( typenums
[1] ) {
1236 return builtin_type_int
;
1238 return builtin_type_char
;
1240 return builtin_type_short
;
1242 return builtin_type_long
;
1244 return builtin_type_unsigned_char
;
1246 return builtin_type_char
; /* requires a builtin `signed char' */
1248 return builtin_type_unsigned_short
;
1250 return builtin_type_unsigned_int
;
1252 return builtin_type_unsigned_int
;
1254 return builtin_type_unsigned_long
;
1256 return builtin_type_void
;
1258 return builtin_type_float
;
1260 return builtin_type_double
;
1262 return builtin_type_double
; /* requires a builtin `long double' */
1264 return builtin_type_int
; /* requires a builtin `integer' */
1266 return builtin_type_int
; /* requires builtin `boolean' */
1268 return builtin_type_float
; /* requires builtin `short real' */
1270 return builtin_type_float
; /* requires builtin `real' */
1272 printf ("ERROR! Unknown builtin type -%d\n", typenums
[1]);
1277 /* if we now nothing about a function but its address, make a function symbol
1278 out of it with the limited knowladge you have. This will be used when
1279 somebody refers to a function, which doesn't exist in the symbol table,
1280 but in misc_function_vector. */
1283 build_function_symbol (ind
)
1286 struct symbol
*sym
=
1287 (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1288 SYMBOL_NAME (sym
) = misc_function_vector
[ind
].name
;
1289 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1290 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1291 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1292 SYMBOL_TYPE (sym
) = lookup_function_type (builtin_type_int
);
1293 SYMBOL_BLOCK_VALUE (sym
) = (struct block
*)
1294 obstack_alloc (symbol_obstack
, sizeof (struct block
));
1295 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) = misc_function_vector
[ind
].address
;
1303 /* Nothin' to do. */
1307 aixcoff_symfile_init (sf
)
1310 bfd
*abfd
= sf
->sym_bfd
;
1312 /* Allocate struct to keep track of the symfile */
1313 /* FIXME memory leak */
1314 sf
->sym_private
= xmalloc(sizeof (struct coff_symfile_info
));
1317 * Save startup file's range of PC addresses to help
1318 * blockframe.c decide where the bottom of the stack is.
1320 if (bfd_get_file_flags(abfd
) & EXEC_P
) {
1321 entry_point
= bfd_get_start_address(abfd
);
1324 /* set the startup file to be an empty range. */
1325 startup_file_start
= 0;
1326 startup_file_end
= 0;
1332 init_stringtab(abfd
, offset
)
1338 unsigned char lengthbuf
[4];
1340 if (bfd_seek(abfd
, offset
, 0) < 0)
1343 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1344 length
= bfd_h_get_32(abfd
, lengthbuf
);
1346 /* If no string table is needed, then the file may end immediately
1347 after the symbols. Just return with `strtbl' set to null. */
1349 if (val
!= sizeof length
|| length
< sizeof length
)
1352 /* Allocate string table from symbol_obstack. We will need this table
1353 as long as we have its symbol table around. */
1355 strtbl
= (char*) obstack_alloc (symbol_obstack
, length
);
1359 bcopy(&length
, strtbl
, sizeof length
);
1360 if (length
== sizeof length
)
1363 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
1365 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
1372 init_debugsection(abfd
)
1375 register sec_ptr secp
;
1376 bfd_size_type length
;
1383 secp
= bfd_get_section_by_name(abfd
, ".debug");
1387 if (!(length
= bfd_section_size(abfd
, secp
)))
1390 debugsec
= (void *) xmalloc ((unsigned)length
);
1391 if (debugsec
== NULL
)
1394 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
1395 printf ("Can't read .debug section from symbol file\n");
1410 /* aixcoff version of symbol file read. */
1413 aixcoff_symfile_read (sf
, addr
, mainline
)
1418 int num_symbols
; /* # of symbols */
1419 int symtab_offset
; /* symbol table and */
1420 int stringtab_offset
; /* string table file offsets */
1423 struct coff_symfile_info
*info
= (void*) sf
->sym_private
;
1426 symfile_bfd
= abfd
= sf
->objfile
->obfd
;
1427 name
= sf
->objfile
->name
;
1429 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
1430 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
1431 stringtab_offset
= symtab_offset
+
1432 num_symbols
* coff_data(abfd
)->local_symesz
;
1434 info
->min_lineno_offset
= 0;
1435 info
->max_lineno_offset
= 0;
1436 bfd_map_over_sections (abfd
, find_linenos
, info
);
1438 /* FIXME! This stuff should move into symfile_init */
1439 if (info
->min_lineno_offset
!= 0
1440 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
1442 /* only read in the line # table if one exists */
1443 val
= init_lineno(abfd
, info
->min_lineno_offset
,
1444 info
->max_lineno_offset
- info
->min_lineno_offset
);
1447 error("\"%s\": error reading line numbers\n", name
);
1450 val
= init_stringtab(abfd
, stringtab_offset
);
1452 error ("\"%s\": can't get string table", name
);
1455 if (init_debugsection(abfd
) < 0) {
1456 error ("Error reading .debug section of `%s'\n", name
);
1459 /* Position to read the symbol table. Do not read it all at once. */
1460 val
= bfd_seek(abfd
, (long)symtab_offset
, 0);
1462 perror_with_name(name
);
1464 if (bfd_tell(abfd
) != symtab_offset
)
1467 init_misc_bunches ();
1468 make_cleanup(discard_misc_bunches
, 0);
1470 #ifdef XCOFF_INIT_LOADINFO
1472 XCOFF_INIT_LOADINFO ();
1475 /* Now that the executable file is positioned at symbol table,
1476 process it and define symbols accordingly. */
1478 read_xcoff_symtab(sf
->objfile
, num_symbols
);
1480 make_cleanup(free_debugsection
, 0);
1482 /* Sort symbols alphabetically within each block. */
1485 /* Go over the misc functions and install them in vector. */
1486 condense_misc_bunches (!mainline
);
1488 /* Make a default for file to list. */
1489 select_source_symtab (0);
1492 /* Register our ability to parse symbols for aixcoff BFD files. */
1494 static struct sym_fns aixcoff_sym_fns
=
1496 "aixcoff-rs6000", 15,
1497 aixcoff_new_init
, aixcoff_symfile_init
,
1498 aixcoff_symfile_read
,
1502 _initialize_xcoffread ()
1504 add_symtab_fns(&aixcoff_sym_fns
);