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 /* AIX COFF names have a preceeding dot `.' */
27 #define NAMES_HAVE_DOT 1
29 #include <sys/types.h>
34 #include <sys/param.h>
42 #include "coff/internal.h" /* FIXME, internal data from BFD */
43 #include "libcoff.h" /* FIXME, internal data from BFD */
44 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
48 static void enter_line_range ();
49 static struct symbol
*process_xcoff_symbol ();
50 static int read_symbol_nvalue ();
51 static int read_symbol_lineno ();
54 /* Simplified internal version of coff symbol table information */
58 int c_symnum
; /* symbol number of this entry */
59 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
66 /* The COFF line table, in raw form. */
67 static char *linetab
= NULL
; /* Its actual contents */
68 static long linetab_offset
; /* Its offset in the file */
69 static unsigned long linetab_size
; /* Its size */
71 /* last function's saved coff symbol `cs' */
73 static struct coff_symbol fcn_cs_saved
;
75 static bfd
*symfile_bfd
;
77 /* Core address of start and end of text of current source file.
78 This is calculated from the first function seen after a C_FILE
81 static CORE_ADDR cur_src_start_addr
;
82 static CORE_ADDR cur_src_end_addr
;
84 /* Core address of the end of the first object file. */
86 static CORE_ADDR first_object_file_end
;
88 /* pointer to the string table */
91 /* length of the string table */
92 static int strtbl_len
;
94 /* pointer to debug section */
95 static char *debugsec
;
97 /* pointer to the a.out symbol table */
100 /* initial symbol-table-debug-string vector length */
102 #define INITIAL_STABVECTOR_LENGTH 40
104 struct pending_stabs
*global_stabs
;
105 struct pending_stabs
*file_stabs
;
107 /* Nonzero if within a function (so symbols should be local,
108 if nothing says specifically). */
112 /* Local variables that hold the shift and mask values for the
113 COFF file that we are currently reading. These come back to us
114 from BFD, and are referenced by their macro names, as well as
115 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
116 macros from ../internalcoff.h . */
118 static unsigned local_n_btshft
;
119 static unsigned local_n_tmask
;
122 #define N_BTSHFT local_n_btshft
124 #define N_TMASK local_n_tmask
126 /* Local variables that hold the sizes in the file of various COFF structures.
127 (We only need to know this to read them from the file -- BFD will then
128 translate the data in them, into `internal_xxx' structs in the right
129 byte order, alignment, etc.) */
131 static unsigned local_symesz
;
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 */
152 /* Call sort_syms to sort alphabetically
153 the symbols of each block of each symtab. */
156 compare_symbols (s1
, s2
)
157 struct symbol
**s1
, **s2
;
159 /* Names that are less should come first. */
160 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
164 /* For symbols of the same name, registers should come first. */
165 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
166 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
170 /* Sort a vector of symbols by their value. */
175 register struct symtab
*s
;
177 register struct blockvector
*bv
;
178 register struct block
*b
;
180 for (s
= symtab_list
; s
; s
= s
->next
)
182 bv
= BLOCKVECTOR (s
);
183 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
184 for (i
= 0; i
< nbl
; i
++)
186 b
= BLOCKVECTOR_BLOCK (bv
, i
);
187 if (BLOCK_SHOULD_SORT (b
))
188 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
189 sizeof (struct symbol
*), compare_symbols
);
195 /* add a given stab string into given stab vector. */
198 add_stab_to_list (stabname
, stabvector
)
200 struct pending_stabs
**stabvector
;
202 if ( *stabvector
== NULL
) {
203 *stabvector
= (struct pending_stabs
*)
204 xmalloc (sizeof (struct pending_stabs
) +
205 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
206 (*stabvector
)->count
= 0;
207 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
209 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
210 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
211 *stabvector
= (struct pending_stabs
*)
212 xrealloc (*stabvector
, sizeof (struct pending_stabs
) +
213 (*stabvector
)->length
* sizeof (char*));
215 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
219 /* for all the stabs in a given stab vector, build appropriate types
220 and fix their symbols in given symbol vector. */
223 patch_block_stabs (symbols
, stabs
)
224 struct pending
*symbols
;
225 struct pending_stabs
*stabs
;
232 /* for all the stab entries, find their corresponding symbols and
233 patch their types! */
235 for (ii
=0; ii
< stabs
->count
; ++ii
) {
236 char *name
= stabs
->stab
[ii
];
237 char *pp
= (char*) index (name
, ':');
238 struct symbol
*sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
240 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
245 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
246 SYMBOL_TYPE (sym
) = lookup_function_type (read_type (&pp
));
248 SYMBOL_TYPE (sym
) = read_type (&pp
);
253 /* Enter a given range of lines into the line vector.
254 can be called in the following two ways:
255 enter_line_range (subfile, beginoffset, endoffset, 0, firstLine) or
256 enter_line_range (subfile, beginoffset, 0, endaddr, firstLine) */
259 enter_line_range (subfile
, beginoffset
, endoffset
, endaddr
, firstLine
)
260 struct subfile
*subfile
; /* which sub-file to put line#s in */
261 unsigned beginoffset
, endoffset
; /* offsets to line table */
267 struct internal_lineno lptr
;
268 unsigned local_linesz
= coff_data (symfile_bfd
)->local_linesz
;
270 pp
= &linetab
[beginoffset
- linetab_offset
];
271 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
272 : &linetab
[linetab_size
-1];
274 while (pp
<= limit
) {
276 /* Swap and align this lineno entry into lptr. */
277 bfd_coff_swap_lineno_in (symfile_bfd
, pp
, &lptr
);
279 /* find the address this line represents */
281 lptr
.l_addr
.l_paddr
: read_symbol_nvalue (symtbl
, lptr
.l_addr
.l_symndx
);
283 if (endaddr
&& addr
>= endaddr
)
286 if (lptr
.l_lnno
== 0) {
287 *firstLine
= read_symbol_lineno (symtbl
, lptr
.l_addr
.l_symndx
);
291 record_line (subfile
, *firstLine
+ lptr
.l_lnno
, addr
);
298 /* Save the vital information for use when closing off the current file.
299 NAME is the file name the symbols came from, START_ADDR is the first
300 text address for the file, and SIZE is the number of bytes of text. */
302 #define complete_symtab(name, start_addr) { \
303 last_source_file = savestring (name, strlen (name)); \
304 cur_src_start_addr = start_addr; \
308 /* Refill the symbol table input buffer
309 and set the variables that control fetching entries from it.
310 Reports an error if no data available.
311 This function can read past the end of the symbol table
312 (into the string table) but this does no harm. */
314 /* Reading symbol table has to be fast! Keep the followings as macros, rather
317 #define RECORD_MISC_FUNCTION(NAME, ADDR, TYPE, ALLOCED) \
321 namestr = (NAME) + 1; \
323 namestr = obstack_copy0 (symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
326 prim_record_misc_function (namestr, (ADDR), (TYPE)); \
327 last_recorded_fun = (ADDR); \
332 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
333 nested. At any given time, a symbol can only be in one static block.
334 This is the base address of current static block, zero if non exists. */
336 static int static_block_base
= 0;
338 /* true if space for symbol name has been allocated. */
340 static int symname_alloced
= 0;
342 /* read the whole symbol table of a given bfd. */
345 read_xcoff_symtab (objfile
, nsyms
)
346 struct objfile
*objfile
; /* Object file we're reading from */
347 int nsyms
; /* # of symbols */
349 bfd
*abfd
= objfile
->obfd
;
350 /* char *symtbl; */ /* Raw symbol table base */
351 char *raw_symbol
; /* Pointer into raw seething symbol table */
352 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
353 struct internal_syment symbol
[1];
354 union internal_auxent main_aux
[1];
355 struct coff_symbol cs
[1];
356 CORE_ADDR file_start_addr
= 0;
357 CORE_ADDR file_end_addr
= 0;
359 int next_file_symnum
= -1;
360 int just_started
= 1;
366 long fcn_line_offset
;
369 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
370 union internal_auxent fcn_aux_saved
;
371 struct context_stack
*new;
373 char *filestring
= " _start_ "; /* Name of the current file. */
374 char *last_seen_csect
;
375 int last_recorded_fun
= 0; /* last recorded fun. value */
377 /* Get the appropriate COFF "constants" related to the file we're handling. */
378 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
379 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
380 local_symesz
= coff_data (abfd
)->local_symesz
;
382 last_source_file
= 0;
384 last_recorded_fun
= 0;
386 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
388 first_object_file_end
= 0;
390 /* Allocate space for the entire symbol table at once, and read it
391 all in. The bfd is already positioned at the beginning of
394 size
= coff_data (abfd
)->local_symesz
* nsyms
;
395 symtbl
= xmalloc (size
);
397 val
= bfd_read (symtbl
, size
, 1, abfd
);
399 perror_with_name ("reading symbol table");
403 while (symnum
< nsyms
) {
405 QUIT
; /* make this command interruptable. */
407 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
408 /* read one symbol into `cs' structure. After processing the whole symbol
409 table, only string table will be kept in memory, symbol table and debug
410 section of aixcoff will be freed. Thus we can mark symbols with names
411 in string table as `alloced'. */
415 /* Swap and align the symbol into a reasonable C structure. */
416 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
418 cs
->c_symnum
= symnum
;
419 cs
->c_nsyms
= symbol
->n_numaux
;
420 if (symbol
->n_zeroes
) {
422 /* We must use the original, unswapped, name here so the name field
423 pointed to by cs->c_name will persist throughout xcoffread. If
424 we use the new field, it gets overwritten for each symbol. */
425 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
426 } else if (symbol
->n_sclass
& 0x80) {
427 cs
->c_name
= debugsec
+ symbol
->n_offset
;
429 } else { /* in string table */
430 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
433 cs
->c_value
= symbol
->n_value
;
434 cs
->c_sclass
= symbol
->n_sclass
& 0xff;
435 cs
->c_secnum
= symbol
->n_scnum
;
436 cs
->c_type
= (unsigned)symbol
->n_type
;
438 raw_symbol
+= coff_data (abfd
)->local_symesz
;
441 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
443 /* Skip all the auxents associated with this symbol. */
444 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
445 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
450 /* if symbol name starts with ".$" or "$", ignore it. */
451 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
454 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
455 if (last_source_file
)
456 end_symtab (cur_src_end_addr
, 1, 1, objfile
);
458 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
459 cur_src_end_addr
= first_object_file_end
;
460 /* done with all files, everything from here on is globals */
463 /* if explicitly specified as a function, treat is as one. */
464 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
465 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
467 goto function_entry_point
;
470 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
472 /* dealing with a symbol with a csect entry. */
474 # define CSECT(PP) ((PP)->x_csect)
475 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
476 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
477 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
478 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
480 /* Convert the auxent to something we can access. */
481 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
484 switch (CSECT_SMTYP (main_aux
)) {
487 continue; /* ignore all external references. */
489 case XTY_SD
: /* a section description. */
491 switch (CSECT_SCLAS (main_aux
)) {
493 case XMC_PR
: /* a `.text' csect. */
496 /* A program csect is seen.
498 We have to allocate one symbol table for each program csect. Normally
499 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
500 CU might include more than one prog csect, and they don't have to be
501 adjacent in terms of the space they occupy in memory. Thus, one single
502 CU might get fragmented in the memory and gdb's file start and end address
503 approach does not work! */
505 if (last_seen_csect
) {
506 complete_symtab (filestring
, file_start_addr
);
507 cur_src_end_addr
= file_end_addr
;
508 end_symtab (file_end_addr
, 1, 1, objfile
);
509 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
512 /* If this is the very first csect seen, basically `__start'. */
514 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
518 file_start_addr
= cs
->c_value
;
519 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
521 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
522 last_seen_csect
= cs
->c_name
;
523 RECORD_MISC_FUNCTION (cs
->c_name
, cs
->c_value
, mf_text
, symname_alloced
);
531 /* If the section is not a data description, ignore it. Note that
532 uninitialized data will show up as XTY_CM/XMC_RW pair. */
535 #ifdef XCOFF_ADD_TOC_TO_LOADINFO
536 XCOFF_ADD_TOC_TO_LOADINFO (cs
->c_value
);
538 /* fall down to default case. */
540 case XMC_TC
: /* ignore toc entries */
541 default : /* any other XMC_XXX */
545 break; /* switch CSECT_SCLAS() */
549 /* a function entry point. */
550 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
552 function_entry_point
:
553 if (cs
->c_value
!= last_recorded_fun
)
554 RECORD_MISC_FUNCTION (cs
->c_name
, cs
->c_value
, mf_text
,
557 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
558 fcn_start_addr
= cs
->c_value
;
560 /* save the function header info, which will be used
561 when `.bf' is seen. */
563 fcn_aux_saved
= *main_aux
;
567 /* shared library function entry point. */
568 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
569 if (last_recorded_fun
!= cs
->c_value
)
570 RECORD_MISC_FUNCTION (cs
->c_name
, cs
->c_value
, mf_text
,
576 default : /* all other XTY_XXXs */
578 } /* switch CSECT_SMTYP() */
581 switch (cs
->c_sclass
) {
585 /* c_value field contains symnum of next .file entry in table
586 or symnum of first global after last .file. */
588 next_file_symnum
= cs
->c_value
;
590 /* complete symbol table for last object file containing
591 debugging information. */
593 /* Whether or not there was a csect in the previous file, we have
594 to call `end_symtab' and `start_symtab' to reset type_vector,
595 line_vector, etc. structures. */
596 complete_symtab (filestring
, file_start_addr
);
597 cur_src_end_addr
= file_end_addr
;
598 end_symtab (file_end_addr
, 1, 1, objfile
);
599 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
602 /* reset file start and end addresses. A compilation unit with no text
603 (only data) should have zero file boundaries. */
604 file_start_addr
= file_end_addr
= 0;
606 filestring
= cs
->c_name
;
611 if (strcmp (cs
->c_name
, ".bf") == 0) {
613 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
618 /* value contains address of first non-init type code */
619 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
620 contains line number of '{' } */
621 fcn_first_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
623 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
624 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
625 /* mark_first_line (fcn_line_offset, cs->c_symnum); */
627 new = push_context (0, fcn_start_addr
);
628 new->name
= process_xcoff_symbol (&fcn_cs_saved
);
630 else if (strcmp (cs
->c_name
, ".ef") == 0) {
632 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
635 /* the value of .ef is the address of epilogue code;
636 not useful for gdb */
637 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
638 contains number of lines to '}' */
640 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
642 enter_linenos (fcn_line_offset
, fcn_first_line
,
643 fcn_first_line
+ fcn_last_line
);
646 new = pop_context ();
647 if (context_stack_depth
!= 0)
648 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
651 finish_block (new->name
, &local_symbols
, new->old_blocks
,
653 fcn_cs_saved
.c_value
+
654 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
);
659 case C_BSTAT
: /* begin static block */
660 static_block_base
= read_symbol_nvalue (symtbl
, cs
->c_value
);
663 case C_ESTAT
: /* end of static block */
664 static_block_base
= 0;
667 case C_ARG
: /* These are not implemented. */
673 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
676 case C_HIDEXT
: /* ignore these.. */
681 case C_BINCL
: /* beginning of include file */
683 start_subfile (cs
->c_name
, (char *)0);
684 fcn_first_line
= cs
->c_value
; /* Offset to first lineno of file */
687 case C_EINCL
: /* end of include file */
688 fcn_last_line
= cs
->c_value
; /* Offset to last line number */
690 enter_line_range (current_subfile
, fcn_first_line
, cs
->c_value
, 0,
693 start_subfile (pop_subfile (), (char *)0);
697 if (strcmp (cs
->c_name
, ".bb") == 0) {
699 new = push_context (depth
, cs
->c_value
);
701 else if (strcmp (cs
->c_name
, ".eb") == 0) {
702 new = pop_context ();
703 if (depth
!= new->depth
)
704 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
708 if (local_symbols
&& context_stack_depth
> 0) {
709 /* Make a block for the local symbols within. */
710 finish_block (new->name
, &local_symbols
, new->old_blocks
,
711 new->start_addr
, cs
->c_value
);
713 local_symbols
= new->locals
;
718 (void) process_xcoff_symbol (cs
);
724 if (last_source_file
)
725 end_symtab (cur_src_end_addr
, 1, 1, objfile
);
730 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
731 (SYMBOL2) = (struct symbol *) \
732 obstack_alloc (symbol_obstack, sizeof (struct symbol)); \
733 *(SYMBOL2) = *(SYMBOL1);
736 #define SYMNAME_ALLOC(NAME, ALLOCED) \
737 (ALLOCED) ? (NAME) : obstack_copy0 (symbol_obstack, (NAME), strlen (NAME));
741 /* process one xcoff symbol. */
743 static struct symbol
*
744 process_xcoff_symbol (cs
)
745 register struct coff_symbol
*cs
;
747 struct symbol onesymbol
;
748 register struct symbol
*sym
= &onesymbol
;
749 struct symbol
*sym2
= NULL
;
751 char *name
, *pp
, *qq
;
757 bzero (sym
, sizeof (struct symbol
));
759 /* default assumptions */
760 SYMBOL_VALUE (sym
) = cs
->c_value
;
761 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
763 if (ISFCN (cs
->c_type
)) {
765 /* At this point, we don't know the type of the function and assume it
766 is int. This will be patched with the type from its stab entry later
767 on in patch_block_stabs () */
769 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
770 SYMBOL_TYPE (sym
) = lookup_function_type (builtin_type_int
);
772 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
773 SYMBOL_DUP (sym
, sym2
);
775 if (cs
->c_sclass
== C_EXT
)
776 add_symbol_to_list (sym2
, &global_symbols
);
777 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
778 add_symbol_to_list (sym2
, &file_symbols
);
783 /* in case we can't figure out the type, default is `int'. */
784 SYMBOL_TYPE (sym
) = builtin_type_int
;
786 switch (cs
->c_sclass
)
789 if (fcn_cs_saved
.c_sclass
== C_EXT
)
790 add_stab_to_list (name
, &global_stabs
);
792 add_stab_to_list (name
, &file_stabs
);
795 case C_DECL
: /* a type decleration?? */
796 qq
= (char*) index (name
, ':');
797 if (!qq
) /* skip if there is no ':' */
801 ttype
= SYMBOL_TYPE (sym
) = read_type (&pp
);
803 /* read_type() will return null if type (or tag) definition was
804 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
805 there is no need to keep it in symbol table. */
807 if (!ttype
|| name
== qq
)
811 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
812 else if (qq
[1] == 't')
813 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
815 printf ("ERROR: Unrecognized stab string.\n");
819 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
820 SYMBOL_NAME (sym
) = obsavestring (name
, qq
-name
);
822 if (SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
)
823 TYPE_NAME (ttype
) = concat (
824 TYPE_CODE (ttype
) == TYPE_CODE_UNION
? "union " :
825 TYPE_CODE (ttype
) == TYPE_CODE_STRUCT
? "struct " : "enum ",
826 SYMBOL_NAME (sym
), NULL
);
828 else if (!TYPE_NAME (ttype
)) /* else, regular typedef. */
829 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
831 SYMBOL_DUP (sym
, sym2
);
833 (sym2
, within_function
? &local_symbols
: &file_symbols
);
837 add_stab_to_list (name
, &global_stabs
);
841 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
843 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
844 SYMBOL_CLASS (sym
) = LOC_ARG
;
846 SYMBOL_TYPE (sym
) = read_type (&pp
);
847 SYMBOL_DUP (sym
, sym2
);
848 add_symbol_to_list (sym2
, &local_symbols
);
852 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
854 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
855 SYMBOL_CLASS (sym
) = LOC_STATIC
;
856 SYMBOL_VALUE (sym
) += static_block_base
;
858 SYMBOL_TYPE (sym
) = read_type (&pp
);
859 SYMBOL_DUP (sym
, sym2
);
861 (sym2
, within_function
? &local_symbols
: &file_symbols
);
865 if (*name
== ':' || (pp
= (char *) index (name
, ':')) == NULL
)
867 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
868 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
870 SYMBOL_TYPE (sym
) = read_type (&pp
);
871 SYMBOL_DUP (sym
, sym2
);
872 add_symbol_to_list (sym2
, &local_symbols
);
876 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
877 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
878 SYMBOL_DUP (sym
, sym2
);
879 add_symbol_to_list (sym2
, &local_symbols
);
883 SYMBOL_CLASS (sym
) = LOC_STATIC
;
884 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
885 SYMBOL_DUP (sym
, sym2
);
886 add_symbol_to_list (sym2
, &global_symbols
);
890 SYMBOL_CLASS (sym
) = LOC_STATIC
;
891 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
892 SYMBOL_DUP (sym
, sym2
);
894 (sym2
, within_function
? &local_symbols
: &file_symbols
);
898 printf ("ERROR! C_REG is not fully implemented!\n");
899 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
900 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
901 SYMBOL_DUP (sym
, sym2
);
902 add_symbol_to_list (sym2
, &local_symbols
);
906 pp
= (char*) index (name
, ':');
907 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
908 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (cs
->c_value
);
910 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
);
913 SYMBOL_TYPE (sym
) = read_type (&pp
);
916 /* else this is not a stab entry, suppose the type is either
917 `int' or `float', depending on the register class. */
919 SYMBOL_TYPE (sym
) = (SYMBOL_VALUE (sym
) < 32) ?
920 builtin_type_int
: builtin_type_float
;
922 SYMBOL_DUP (sym
, sym2
);
923 add_symbol_to_list (sym2
, &local_symbols
);
927 printf ("ERROR: Unexpected storage class: %d.\n", cs
->c_sclass
);
936 read_symbol_nvalue (symtable
, symno
)
940 struct internal_syment symbol
[1];
942 bfd_coff_swap_sym_in (symfile_bfd
, symtable
+ (symno
*local_symesz
), symbol
);
943 return symbol
->n_value
;
948 read_symbol_lineno (symtable
, symno
)
952 struct internal_syment symbol
[1];
953 union internal_auxent main_aux
[1];
957 for (ii
= 0; ii
< 50; ii
++) {
958 bfd_coff_swap_sym_in (symfile_bfd
,
959 symtable
+ (symno
*local_symesz
), symbol
);
960 if (symbol
->n_sclass
== C_FCN
&& 0 == strcmp (symbol
->n_name
, ".bf"))
962 symno
+= 1 + symbol
->n_numaux
+1;
965 printf ("GDB Error: `.bf' not found.\n");
969 /* take aux entry and return its lineno */
971 bfd_coff_swap_aux_in (symfile_bfd
, symtable
+(symno
*local_symesz
),
972 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
974 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
977 /* Support for line number handling */
979 /* This function is called for every section; it finds the outer limits
980 * of the line table (minimum and maximum file offset) so that the
981 * mainline code can read the whole thing for efficiency.
984 find_linenos(abfd
, asect
, vpinfo
)
989 struct coff_symfile_info
*info
;
991 file_ptr offset
, maxoff
;
993 count
= asect
->lineno_count
;
998 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
999 info
= (struct coff_symfile_info
*)vpinfo
;
1000 offset
= asect
->line_filepos
;
1001 maxoff
= offset
+ size
;
1003 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1004 info
->min_lineno_offset
= offset
;
1006 if (maxoff
> info
->max_lineno_offset
)
1007 info
->max_lineno_offset
= maxoff
;
1011 /* Read in all the line numbers for fast lookups later. Leave them in
1012 external (unswapped) format in memory; we'll swap them as we enter
1013 them into GDB's data structures. */
1016 init_lineno (abfd
, offset
, size
)
1023 if (bfd_seek(abfd
, offset
, 0) < 0)
1026 linetab
= (char *) xmalloc(size
);
1028 val
= bfd_read(linetab
, 1, size
, abfd
);
1032 linetab_offset
= offset
;
1033 linetab_size
= size
;
1034 make_cleanup(free
, linetab
); /* Be sure it gets de-allocated. */
1043 printf ("===STRING TABLE DUMP...\n\n");
1044 for ( ii
=0; ii
< strtbl_len
; ++ii
)
1045 printf ("%c", isprint (*(strtbl
+ii
)) ? *(strtbl
+ii
) : ' ');
1050 dump_linetable (ltb
)
1051 struct linetable
*ltb
;
1054 for (ii
=0; ii
< ltb
->nitems
; ++ii
)
1055 printf ("line: %d, addr: 0x%x\n", ltb
->item
[ii
].line
, ltb
->item
[ii
].pc
);
1062 printf ("0x%x: name: %s\n", typeP
, typeP
->name
? typeP
->name
: "(nil)");
1065 char *dump_namespace ();
1066 char *dump_addrclass ();
1072 printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n",
1073 pp
->name
, dump_namespace (pp
->namespace),
1074 dump_addrclass (pp
->class), pp
->type
,
1075 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_START(SYMBOL_BLOCK_VALUE(pp
))
1077 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_END(SYMBOL_BLOCK_VALUE(pp
)) : 0);
1085 static char *ns_name
[] = {
1086 "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"};
1089 case UNDEF_NAMESPACE
:
1091 case STRUCT_NAMESPACE
:
1092 case LABEL_NAMESPACE
:
1096 return "***ERROR***";
1102 int ac
; /* address class */
1104 static char *ac_name
[] = {
1131 case LOC_CONST_BYTES
:
1133 return ac_name
[ac
];
1135 return "***ERROR***";
1143 printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp
->startaddr
, pp
->endaddr
);
1144 for (ii
=0; ii
< pp
->nsyms
; ++ii
)
1145 dump_symbol (pp
->sym
[ii
]);
1149 dump_blockvector (pp
)
1150 struct blockvector
*pp
;
1153 for (ii
=0; ii
< pp
->nblocks
; ++ii
)
1154 dump_block (pp
->block
[ii
]);
1159 dump_last_symtab (pp
)
1162 for ( ; pp
; pp
= pp
->next
) {
1163 if ( pp
->next
== 0 ) {
1164 printf ("SYMTAB NAME: %s\n", pp
->filename
);
1165 dump_blockvector (pp
->blockvector
);
1174 for ( ; pp
; pp
= pp
->next
) {
1175 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
1176 /* if (pp->linetable)
1177 dump_linetable (pp->linetable); */
1178 dump_blockvector (pp
->blockvector
);
1183 dump_symtab_lines (pp
)
1186 for ( ; pp
; pp
= pp
->next
) {
1187 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
1189 dump_linetable (pp
->linetable
);
1190 /* dump_blockvector (pp->blockvector); */
1198 for (ii
=0; ii
< misc_function_count
; ++ii
)
1199 printf ("name: %s, addr: 0x%x\n",
1200 misc_function_vector
[ii
].name
,
1201 misc_function_vector
[ii
].address
);
1205 /* dbx allows the text of a symbol name to be continued into the
1206 next symbol name! When such a continuation is encountered
1207 (a \ at the end of the text of a name)
1208 call this function to get the continuation. */
1209 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1212 #define next_symbol_text() \
1213 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1216 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
1217 the proper type node fora given builtin type #. */
1226 printf ("ERROR!, unknown built-in type!\n");
1230 read_type_number (pp
, typenums
);
1232 /* default types are defined in dbxstclass.h. */
1233 switch ( typenums
[1] ) {
1235 return builtin_type_int
;
1237 return builtin_type_char
;
1239 return builtin_type_short
;
1241 return builtin_type_long
;
1243 return builtin_type_unsigned_char
;
1245 return builtin_type_char
; /* requires a builtin `signed char' */
1247 return builtin_type_unsigned_short
;
1249 return builtin_type_unsigned_int
;
1251 return builtin_type_unsigned_int
;
1253 return builtin_type_unsigned_long
;
1255 return builtin_type_void
;
1257 return builtin_type_float
;
1259 return builtin_type_double
;
1261 return builtin_type_double
; /* requires a builtin `long double' */
1263 return builtin_type_int
; /* requires a builtin `integer' */
1265 return builtin_type_int
; /* requires builtin `boolean' */
1267 return builtin_type_float
; /* requires builtin `short real' */
1269 return builtin_type_float
; /* requires builtin `real' */
1271 printf ("ERROR! Unknown builtin type -%d\n", typenums
[1]);
1276 /* if we now nothing about a function but its address, make a function symbol
1277 out of it with the limited knowladge you have. This will be used when
1278 somebody refers to a function, which doesn't exist in the symbol table,
1279 but in misc_function_vector. */
1282 build_function_symbol (ind
)
1285 struct symbol
*sym
=
1286 (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1287 SYMBOL_NAME (sym
) = misc_function_vector
[ind
].name
;
1288 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1289 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1290 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1291 SYMBOL_TYPE (sym
) = lookup_function_type (builtin_type_int
);
1292 SYMBOL_BLOCK_VALUE (sym
) = (struct block
*)
1293 obstack_alloc (symbol_obstack
, sizeof (struct block
));
1294 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) = misc_function_vector
[ind
].address
;
1302 /* Nothin' to do. */
1306 aixcoff_symfile_init (sf
)
1309 bfd
*abfd
= sf
->sym_bfd
;
1311 /* Allocate struct to keep track of the symfile */
1312 /* FIXME memory leak */
1313 sf
->sym_private
= xmalloc(sizeof (struct coff_symfile_info
));
1316 * Save startup file's range of PC addresses to help
1317 * blockframe.c decide where the bottom of the stack is.
1319 if (bfd_get_file_flags(abfd
) & EXEC_P
) {
1320 entry_point
= bfd_get_start_address(abfd
);
1323 /* set the startup file to be an empty range. */
1324 startup_file_start
= 0;
1325 startup_file_end
= 0;
1331 init_stringtab(abfd
, offset
)
1337 unsigned char lengthbuf
[4];
1339 if (bfd_seek(abfd
, offset
, 0) < 0)
1342 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1343 length
= bfd_h_get_32(abfd
, lengthbuf
);
1345 /* If no string table is needed, then the file may end immediately
1346 after the symbols. Just return with `strtbl' set to null. */
1348 if (val
!= sizeof length
|| length
< sizeof length
)
1351 /* Allocate string table from symbol_obstack. We will need this table
1352 as long as we have its symbol table around. */
1354 strtbl
= (char*) obstack_alloc (symbol_obstack
, length
);
1358 bcopy(&length
, strtbl
, sizeof length
);
1359 if (length
== sizeof length
)
1362 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
1364 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
1371 init_debugsection(abfd
)
1374 register sec_ptr secp
;
1375 bfd_size_type length
;
1382 secp
= bfd_get_section_by_name(abfd
, ".debug");
1386 if (!(length
= bfd_section_size(abfd
, secp
)))
1389 debugsec
= (void *) xmalloc ((unsigned)length
);
1390 if (debugsec
== NULL
)
1393 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
1394 printf ("Can't read .debug section from symbol file\n");
1409 /* aixcoff version of symbol file read. */
1412 aixcoff_symfile_read (sf
, addr
, mainline
)
1417 int num_symbols
; /* # of symbols */
1418 int symtab_offset
; /* symbol table and */
1419 int stringtab_offset
; /* string table file offsets */
1422 struct coff_symfile_info
*info
= (void*) sf
->sym_private
;
1425 symfile_bfd
= abfd
= sf
->objfile
->obfd
;
1426 name
= sf
->objfile
->name
;
1428 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
1429 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
1430 stringtab_offset
= symtab_offset
+
1431 num_symbols
* coff_data(abfd
)->local_symesz
;
1433 info
->min_lineno_offset
= 0;
1434 info
->max_lineno_offset
= 0;
1435 bfd_map_over_sections (abfd
, find_linenos
, info
);
1437 /* FIXME! This stuff should move into symfile_init */
1438 if (info
->min_lineno_offset
!= 0
1439 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
1441 /* only read in the line # table if one exists */
1442 val
= init_lineno(abfd
, info
->min_lineno_offset
,
1443 info
->max_lineno_offset
- info
->min_lineno_offset
);
1446 error("\"%s\": error reading line numbers\n", name
);
1449 val
= init_stringtab(abfd
, stringtab_offset
);
1451 error ("\"%s\": can't get string table", name
);
1454 if (init_debugsection(abfd
) < 0) {
1455 error ("Error reading .debug section of `%s'\n", name
);
1458 /* Position to read the symbol table. Do not read it all at once. */
1459 val
= bfd_seek(abfd
, (long)symtab_offset
, 0);
1461 perror_with_name(name
);
1463 if (bfd_tell(abfd
) != symtab_offset
)
1466 init_misc_bunches ();
1467 make_cleanup(discard_misc_bunches
, 0);
1469 #ifdef XCOFF_INIT_LOADINFO
1471 XCOFF_INIT_LOADINFO ();
1474 /* Now that the executable file is positioned at symbol table,
1475 process it and define symbols accordingly. */
1477 read_xcoff_symtab(sf
->objfile
, num_symbols
);
1479 make_cleanup(free_debugsection
, 0);
1481 /* Sort symbols alphabetically within each block. */
1484 /* Go over the misc functions and install them in vector. */
1485 condense_misc_bunches (!mainline
);
1487 /* Make a default for file to list. */
1488 select_source_symtab (0);
1491 /* Register our ability to parse symbols for aixcoff BFD files. */
1493 static struct sym_fns aixcoff_sym_fns
=
1495 "aixcoff-rs6000", 15,
1496 aixcoff_new_init
, aixcoff_symfile_init
,
1497 aixcoff_symfile_read
,
1501 _initialize_xcoffread ()
1503 add_symtab_fns(&aixcoff_sym_fns
);