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>
45 #include "coff/internal.h" /* FIXME, internal data from BFD */
46 #include "libcoff.h" /* FIXME, internal data from BFD */
47 #include "coff/rs6000.h" /* FIXME, raw file-format guts of xcoff */
49 /* Simplified internal version of coff symbol table information */
53 int c_symnum
; /* symbol number of this entry */
54 int c_nsyms
; /* 0 if syment only, 1 if syment + auxent */
61 /* The COFF line table, in raw form. */
62 static char *linetab
= NULL
; /* Its actual contents */
63 static long linetab_offset
; /* Its offset in the file */
64 static unsigned long linetab_size
; /* Its size */
66 /* last function's saved coff symbol `cs' */
68 static struct coff_symbol fcn_cs_saved
;
70 static bfd
*symfile_bfd
;
72 /* Core address of start and end of text of current source file.
73 This is calculated from the first function seen after a C_FILE
76 static CORE_ADDR cur_src_start_addr
;
77 static CORE_ADDR cur_src_end_addr
;
79 /* Core address of the end of the first object file. */
81 static CORE_ADDR first_object_file_end
;
83 /* pointer to the string table */
86 /* length of the string table */
87 static int strtbl_len
;
89 /* pointer to debug section */
90 static char *debugsec
;
92 /* pointer to the a.out symbol table */
95 /* initial symbol-table-debug-string vector length */
97 #define INITIAL_STABVECTOR_LENGTH 40
99 struct pending_stabs
*global_stabs
;
100 struct pending_stabs
*file_stabs
;
102 /* Nonzero if within a function (so symbols should be local,
103 if nothing says specifically). */
107 /* Local variables that hold the shift and mask values for the
108 COFF file that we are currently reading. These come back to us
109 from BFD, and are referenced by their macro names, as well as
110 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
111 macros from ../internalcoff.h . */
113 static unsigned local_n_btshft
;
114 static unsigned local_n_tmask
;
117 #define N_BTSHFT local_n_btshft
119 #define N_TMASK local_n_tmask
121 /* Local variables that hold the sizes in the file of various COFF structures.
122 (We only need to know this to read them from the file -- BFD will then
123 translate the data in them, into `internal_xxx' structs in the right
124 byte order, alignment, etc.) */
126 static unsigned local_symesz
;
128 /* coff_symfile_init()
129 is the coff-specific initialization routine for reading symbols.
130 It is passed a struct sym_fns which contains, among other things,
131 the BFD for the file whose symbols are being read, and a slot for
132 a pointer to "private data" which we fill with cookies and other
133 treats for coff_symfile_read().
135 We will only be called if this is a COFF or COFF-like file.
136 BFD handles figuring out the format of the file, and code in symtab.c
137 uses BFD's determination to vector to us.
139 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
141 struct coff_symfile_info
{
142 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
143 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
148 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned, CORE_ADDR
,
152 aixcoff_symfile_read
PARAMS ((struct sym_fns
*, CORE_ADDR
, int));
155 free_debugsection
PARAMS ((void));
158 init_debugsection
PARAMS ((bfd
*));
161 init_stringtab
PARAMS ((bfd
*, long, struct objfile
*));
164 aixcoff_symfile_init
PARAMS ((struct sym_fns
*));
167 aixcoff_new_init
PARAMS ((void));
170 dump_minimal_symbols
PARAMS ((struct objfile
*));
173 dump_symtab_lines
PARAMS ((struct symtab
*));
176 dump_symtabs
PARAMS ((struct symtab
*));
179 dump_last_symtab
PARAMS ((struct symtab
*));
182 dump_blockvector
PARAMS ((struct blockvector
*));
185 dump_block
PARAMS ((struct block
*));
188 dump_addrclass
PARAMS ((int));
191 dump_namespace
PARAMS ((int));
194 dump_symbol
PARAMS ((struct symbol
*));
197 dump_type
PARAMS ((struct type
*));
200 dump_linetable
PARAMS ((struct linetable
*));
203 dump_strtbl
PARAMS ((void));
206 init_lineno
PARAMS ((bfd
*, long, int));
209 find_linenos
PARAMS ((bfd
*, sec_ptr
, PTR
));
212 read_symbol_lineno
PARAMS ((char *, int));
215 read_symbol_nvalue
PARAMS ((char *, int));
217 static struct symbol
*
218 process_xcoff_symbol
PARAMS ((struct coff_symbol
*, struct objfile
*));
221 read_xcoff_symtab
PARAMS ((struct objfile
*, int));
224 enter_line_range
PARAMS ((struct subfile
*, unsigned, unsigned, CORE_ADDR
,
228 add_stab_to_list
PARAMS ((char *, struct pending_stabs
**));
231 sort_syms
PARAMS ((void));
234 compare_symbols
PARAMS ((const void *, const void *));
236 /* Call sort_syms to sort alphabetically
237 the symbols of each block of each symtab. */
240 compare_symbols (s1p
, s2p
)
244 /* Names that are less should come first. */
245 register struct symbol
**s1
= (struct symbol
**) s1p
;
246 register struct symbol
**s2
= (struct symbol
**) s2p
;
247 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
251 /* For symbols of the same name, registers should come first. */
252 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
253 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
257 /* Sort a vector of symbols by their value. */
262 register struct symtab
*s
;
263 register struct objfile
*objfile
;
265 register struct blockvector
*bv
;
266 register struct block
*b
;
268 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
270 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
272 bv
= BLOCKVECTOR (s
);
273 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
274 for (i
= 0; i
< nbl
; i
++)
276 b
= BLOCKVECTOR_BLOCK (bv
, i
);
277 if (BLOCK_SHOULD_SORT (b
))
279 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
280 sizeof (struct symbol
*), compare_symbols
);
288 /* add a given stab string into given stab vector. */
291 add_stab_to_list (stabname
, stabvector
)
293 struct pending_stabs
**stabvector
;
295 if ( *stabvector
== NULL
) {
296 *stabvector
= (struct pending_stabs
*)
297 xmalloc (sizeof (struct pending_stabs
) +
298 INITIAL_STABVECTOR_LENGTH
* sizeof (char*));
299 (*stabvector
)->count
= 0;
300 (*stabvector
)->length
= INITIAL_STABVECTOR_LENGTH
;
302 else if ((*stabvector
)->count
>= (*stabvector
)->length
) {
303 (*stabvector
)->length
+= INITIAL_STABVECTOR_LENGTH
;
304 *stabvector
= (struct pending_stabs
*)
305 xrealloc ((char *) *stabvector
, sizeof (struct pending_stabs
) +
306 (*stabvector
)->length
* sizeof (char*));
308 (*stabvector
)->stab
[(*stabvector
)->count
++] = stabname
;
312 /* Enter a given range of lines into the line vector.
313 can be called in the following two ways:
314 enter_line_range (subfile, beginoffset, endoffset, 0, firstLine) or
315 enter_line_range (subfile, beginoffset, 0, endaddr, firstLine) */
318 enter_line_range (subfile
, beginoffset
, endoffset
, endaddr
, firstLine
)
319 struct subfile
*subfile
; /* which sub-file to put line#s in */
320 unsigned beginoffset
, endoffset
; /* offsets to line table */
326 struct internal_lineno lptr
;
327 unsigned local_linesz
= coff_data (symfile_bfd
)->local_linesz
;
329 pp
= &linetab
[beginoffset
- linetab_offset
];
330 limit
= endoffset
? &linetab
[endoffset
- linetab_offset
]
331 : &linetab
[linetab_size
-1];
333 while (pp
<= limit
) {
335 /* Swap and align this lineno entry into lptr. */
336 bfd_coff_swap_lineno_in (symfile_bfd
, pp
, &lptr
);
338 /* find the address this line represents */
340 lptr
.l_addr
.l_paddr
: read_symbol_nvalue (symtbl
, lptr
.l_addr
.l_symndx
);
342 if (endaddr
&& addr
>= endaddr
)
345 if (lptr
.l_lnno
== 0) {
346 *firstLine
= read_symbol_lineno (symtbl
, lptr
.l_addr
.l_symndx
);
350 record_line (subfile
, *firstLine
+ lptr
.l_lnno
, addr
);
357 /* Save the vital information for use when closing off the current file.
358 NAME is the file name the symbols came from, START_ADDR is the first
359 text address for the file, and SIZE is the number of bytes of text. */
361 #define complete_symtab(name, start_addr) { \
362 last_source_file = savestring (name, strlen (name)); \
363 cur_src_start_addr = start_addr; \
367 /* Refill the symbol table input buffer
368 and set the variables that control fetching entries from it.
369 Reports an error if no data available.
370 This function can read past the end of the symbol table
371 (into the string table) but this does no harm. */
373 /* Reading symbol table has to be fast! Keep the followings as macros, rather
376 #define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, ALLOCED) \
380 namestr = (NAME) + 1; \
382 namestr = obstack_copy0 (&objfile->symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
385 prim_record_minimal_symbol (namestr, (ADDR), (TYPE)); \
386 last_recorded_fun = (ADDR); \
391 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
392 nested. At any given time, a symbol can only be in one static block.
393 This is the base address of current static block, zero if non exists. */
395 static int static_block_base
= 0;
397 /* true if space for symbol name has been allocated. */
399 static int symname_alloced
= 0;
401 /* read the whole symbol table of a given bfd. */
404 read_xcoff_symtab (objfile
, nsyms
)
405 struct objfile
*objfile
; /* Object file we're reading from */
406 int nsyms
; /* # of symbols */
408 bfd
*abfd
= objfile
->obfd
;
409 /* char *symtbl; */ /* Raw symbol table base */
410 char *raw_symbol
; /* Pointer into raw seething symbol table */
411 char *raw_auxptr
; /* Pointer to first raw aux entry for sym */
412 struct internal_syment symbol
[1];
413 union internal_auxent main_aux
[1];
414 struct coff_symbol cs
[1];
415 CORE_ADDR file_start_addr
= 0;
416 CORE_ADDR file_end_addr
= 0;
418 int next_file_symnum
= -1;
419 int just_started
= 1;
425 long fcn_line_offset
;
428 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
429 union internal_auxent fcn_aux_saved
;
430 struct context_stack
*new;
432 char *filestring
= " _start_ "; /* Name of the current file. */
433 char *last_seen_csect
;
434 int last_recorded_fun
= 0; /* last recorded fun. value */
436 current_objfile
= objfile
;
438 /* Get the appropriate COFF "constants" related to the file we're handling. */
439 N_TMASK
= coff_data (abfd
)->local_n_tmask
;
440 N_BTSHFT
= coff_data (abfd
)->local_n_btshft
;
441 local_symesz
= coff_data (abfd
)->local_symesz
;
443 last_source_file
= 0;
445 last_recorded_fun
= 0;
447 start_symtab (filestring
, (char *)NULL
, file_start_addr
);
449 first_object_file_end
= 0;
451 /* Allocate space for the entire symbol table at once, and read it
452 all in. The bfd is already positioned at the beginning of
455 size
= coff_data (abfd
)->local_symesz
* nsyms
;
456 symtbl
= xmalloc (size
);
458 val
= bfd_read (symtbl
, size
, 1, abfd
);
460 perror_with_name ("reading symbol table");
464 while (symnum
< nsyms
) {
466 QUIT
; /* make this command interruptable. */
468 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
469 /* read one symbol into `cs' structure. After processing the whole symbol
470 table, only string table will be kept in memory, symbol table and debug
471 section of aixcoff will be freed. Thus we can mark symbols with names
472 in string table as `alloced'. */
476 /* Swap and align the symbol into a reasonable C structure. */
477 bfd_coff_swap_sym_in (abfd
, raw_symbol
, symbol
);
479 cs
->c_symnum
= symnum
;
480 cs
->c_nsyms
= symbol
->n_numaux
;
481 if (symbol
->n_zeroes
) {
483 /* We must use the original, unswapped, name here so the name field
484 pointed to by cs->c_name will persist throughout xcoffread. If
485 we use the new field, it gets overwritten for each symbol. */
486 cs
->c_name
= ((struct external_syment
*)raw_symbol
)->e
.e_name
;
487 } else if (symbol
->n_sclass
& 0x80) {
488 cs
->c_name
= debugsec
+ symbol
->n_offset
;
490 } else { /* in string table */
491 cs
->c_name
= strtbl
+ (int)symbol
->n_offset
;
494 cs
->c_value
= symbol
->n_value
;
495 cs
->c_sclass
= symbol
->n_sclass
& 0xff;
496 cs
->c_secnum
= symbol
->n_scnum
;
497 cs
->c_type
= (unsigned)symbol
->n_type
;
499 raw_symbol
+= coff_data (abfd
)->local_symesz
;
502 raw_auxptr
= raw_symbol
; /* Save addr of first aux entry */
504 /* Skip all the auxents associated with this symbol. */
505 for (ii
= symbol
->n_numaux
; ii
; --ii
) {
506 raw_symbol
+= coff_data (abfd
)->local_auxesz
;
511 /* if symbol name starts with ".$" or "$", ignore it. */
512 if (cs
->c_name
[0] == '$' || (cs
->c_name
[1] == '$' && cs
->c_name
[0] == '.'))
515 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
) {
516 if (last_source_file
)
517 end_symtab (cur_src_end_addr
, 1, 1, objfile
);
519 start_symtab ("_globals_", (char *)NULL
, (CORE_ADDR
)0);
520 cur_src_end_addr
= first_object_file_end
;
521 /* done with all files, everything from here on is globals */
524 /* if explicitly specified as a function, treat is as one. */
525 if (ISFCN(cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
) {
526 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
528 goto function_entry_point
;
531 if ((cs
->c_sclass
== C_EXT
|| cs
->c_sclass
== C_HIDEXT
) && cs
->c_nsyms
== 1)
533 /* dealing with a symbol with a csect entry. */
535 # define CSECT(PP) ((PP)->x_csect)
536 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
537 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
538 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
539 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
541 /* Convert the auxent to something we can access. */
542 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
545 switch (CSECT_SMTYP (main_aux
)) {
548 continue; /* ignore all external references. */
550 case XTY_SD
: /* a section description. */
552 switch (CSECT_SCLAS (main_aux
)) {
554 case XMC_PR
: /* a `.text' csect. */
557 /* A program csect is seen.
559 We have to allocate one symbol table for each program csect. Normally
560 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
561 CU might include more than one prog csect, and they don't have to be
562 adjacent in terms of the space they occupy in memory. Thus, one single
563 CU might get fragmented in the memory and gdb's file start and end address
564 approach does not work! */
566 if (last_seen_csect
) {
567 complete_symtab (filestring
, file_start_addr
);
568 cur_src_end_addr
= file_end_addr
;
569 end_symtab (file_end_addr
, 1, 1, objfile
);
570 start_symtab ((char *)NULL
, (char *)NULL
, (CORE_ADDR
)0);
573 /* If this is the very first csect seen, basically `__start'. */
575 first_object_file_end
= cs
->c_value
+ CSECT_LEN (main_aux
);
579 file_start_addr
= cs
->c_value
;
580 file_end_addr
= cs
->c_value
+ CSECT_LEN (main_aux
);
582 if (cs
->c_name
&& cs
->c_name
[0] == '.') {
583 last_seen_csect
= cs
->c_name
;
584 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
, symname_alloced
);
592 /* If the section is not a data description, ignore it. Note that
593 uninitialized data will show up as XTY_CM/XMC_RW pair. */
596 #ifdef XCOFF_ADD_TOC_TO_LOADINFO
597 XCOFF_ADD_TOC_TO_LOADINFO (cs
->c_value
);
599 /* fall down to default case. */
601 case XMC_TC
: /* ignore toc entries */
602 default : /* any other XMC_XXX */
606 break; /* switch CSECT_SCLAS() */
610 /* a function entry point. */
611 if (CSECT_SCLAS (main_aux
) == XMC_PR
) {
613 function_entry_point
:
614 if (cs
->c_value
!= last_recorded_fun
)
615 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
618 fcn_line_offset
= main_aux
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
619 fcn_start_addr
= cs
->c_value
;
621 /* save the function header info, which will be used
622 when `.bf' is seen. */
624 fcn_aux_saved
= *main_aux
;
628 /* shared library function entry point. */
629 else if (CSECT_SCLAS (main_aux
) == XMC_GL
) {
630 if (last_recorded_fun
!= cs
->c_value
)
631 RECORD_MINIMAL_SYMBOL (cs
->c_name
, cs
->c_value
, mst_text
,
637 default : /* all other XTY_XXXs */
639 } /* switch CSECT_SMTYP() */
642 switch (cs
->c_sclass
) {
646 /* c_value field contains symnum of next .file entry in table
647 or symnum of first global after last .file. */
649 next_file_symnum
= cs
->c_value
;
651 /* complete symbol table for last object file containing
652 debugging information. */
654 /* Whether or not there was a csect in the previous file, we have
655 to call `end_symtab' and `start_symtab' to reset type_vector,
656 line_vector, etc. structures. */
657 complete_symtab (filestring
, file_start_addr
);
658 cur_src_end_addr
= file_end_addr
;
659 end_symtab (file_end_addr
, 1, 1, objfile
);
660 start_symtab (cs
->c_name
, (char *)NULL
, (CORE_ADDR
)0);
663 /* reset file start and end addresses. A compilation unit with no text
664 (only data) should have zero file boundaries. */
665 file_start_addr
= file_end_addr
= 0;
667 filestring
= cs
->c_name
;
672 if (strcmp (cs
->c_name
, ".bf") == 0) {
674 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
679 /* value contains address of first non-init type code */
680 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
681 contains line number of '{' } */
682 fcn_first_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
684 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
685 Metin did it, I'm not sure why. FIXME. -- gnu@cygnus.com */
686 /* mark_first_line (fcn_line_offset, cs->c_symnum); */
688 new = push_context (0, fcn_start_addr
);
689 new->name
= process_xcoff_symbol (&fcn_cs_saved
, objfile
);
691 else if (strcmp (cs
->c_name
, ".ef") == 0) {
693 bfd_coff_swap_aux_in (abfd
, raw_auxptr
, cs
->c_type
, cs
->c_sclass
,
696 /* the value of .ef is the address of epilogue code;
697 not useful for gdb */
698 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
699 contains number of lines to '}' */
701 fcn_last_line
= main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
703 enter_linenos (fcn_line_offset
, fcn_first_line
,
704 fcn_first_line
+ fcn_last_line
);
707 new = pop_context ();
708 if (context_stack_depth
!= 0)
709 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
712 finish_block (new->name
, &local_symbols
, new->old_blocks
,
714 fcn_cs_saved
.c_value
+
715 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
, objfile
);
720 case C_BSTAT
: /* begin static block */
721 static_block_base
= read_symbol_nvalue (symtbl
, cs
->c_value
);
724 case C_ESTAT
: /* end of static block */
725 static_block_base
= 0;
728 case C_ARG
: /* These are not implemented. */
734 printf ("ERROR: Unimplemented storage class: %d.\n", cs
->c_sclass
);
737 case C_HIDEXT
: /* ignore these.. */
742 case C_BINCL
: /* beginning of include file */
744 start_subfile (cs
->c_name
, (char *)0);
745 fcn_first_line
= cs
->c_value
; /* Offset to first lineno of file */
748 case C_EINCL
: /* end of include file */
749 fcn_last_line
= cs
->c_value
; /* Offset to last line number */
751 enter_line_range (current_subfile
, fcn_first_line
, cs
->c_value
, 0,
752 (unsigned *) &dummy
);
754 start_subfile (pop_subfile (), (char *)0);
758 if (strcmp (cs
->c_name
, ".bb") == 0) {
760 new = push_context (depth
, cs
->c_value
);
762 else if (strcmp (cs
->c_name
, ".eb") == 0) {
763 new = pop_context ();
764 if (depth
!= new->depth
)
765 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
769 if (local_symbols
&& context_stack_depth
> 0) {
770 /* Make a block for the local symbols within. */
771 finish_block (new->name
, &local_symbols
, new->old_blocks
,
772 new->start_addr
, cs
->c_value
, objfile
);
774 local_symbols
= new->locals
;
779 (void) process_xcoff_symbol (cs
, objfile
);
785 if (last_source_file
)
786 end_symtab (cur_src_end_addr
, 1, 1, objfile
);
789 current_objfile
= NULL
;
792 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
793 (SYMBOL2) = (struct symbol *) \
794 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); \
795 *(SYMBOL2) = *(SYMBOL1);
798 #define SYMNAME_ALLOC(NAME, ALLOCED) \
799 (ALLOCED) ? (NAME) : obstack_copy0 (&objfile->symbol_obstack, (NAME), strlen (NAME));
803 /* process one xcoff symbol. */
805 static struct symbol
*
806 process_xcoff_symbol (cs
, objfile
)
807 register struct coff_symbol
*cs
;
808 struct objfile
*objfile
;
810 struct symbol onesymbol
;
811 register struct symbol
*sym
= &onesymbol
;
812 struct symbol
*sym2
= NULL
;
814 char *name
, *pp
, *qq
;
820 bzero (sym
, sizeof (struct symbol
));
822 /* default assumptions */
823 SYMBOL_VALUE (sym
) = cs
->c_value
;
824 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
826 if (ISFCN (cs
->c_type
)) {
828 /* At this point, we don't know the type of the function and assume it
829 is int. This will be patched with the type from its stab entry later
830 on in patch_block_stabs () */
832 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
833 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (current_objfile
, FT_INTEGER
));
835 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
836 SYMBOL_DUP (sym
, sym2
);
838 if (cs
->c_sclass
== C_EXT
)
839 add_symbol_to_list (sym2
, &global_symbols
);
840 else if (cs
->c_sclass
== C_HIDEXT
|| cs
->c_sclass
== C_STAT
)
841 add_symbol_to_list (sym2
, &file_symbols
);
846 /* in case we can't figure out the type, default is `int'. */
847 SYMBOL_TYPE (sym
) = lookup_fundamental_type (current_objfile
, FT_INTEGER
);
849 switch (cs
->c_sclass
)
852 if (fcn_cs_saved
.c_sclass
== C_EXT
)
853 add_stab_to_list (name
, &global_stabs
);
855 add_stab_to_list (name
, &file_stabs
);
858 case C_DECL
: /* a type decleration?? */
859 qq
= (char*) strchr (name
, ':');
860 if (!qq
) /* skip if there is no ':' */
864 ttype
= SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
866 /* read_type() will return null if type (or tag) definition was
867 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
868 there is no need to keep it in symbol table. */
870 if (!ttype
|| name
== qq
)
874 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
875 else if (qq
[1] == 't')
876 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
878 printf ("ERROR: Unrecognized stab string.\n");
882 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
883 SYMBOL_NAME (sym
) = obsavestring (name
, qq
-name
, &objfile
->symbol_obstack
);
885 if (SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
)
886 TYPE_NAME (ttype
) = concat (
887 TYPE_CODE (ttype
) == TYPE_CODE_UNION
? "union " :
888 TYPE_CODE (ttype
) == TYPE_CODE_STRUCT
? "struct " : "enum ",
889 SYMBOL_NAME (sym
), NULL
);
891 else if (!TYPE_NAME (ttype
)) /* else, regular typedef. */
892 TYPE_NAME (ttype
) = SYMBOL_NAME (sym
);
894 SYMBOL_DUP (sym
, sym2
);
896 (sym2
, within_function
? &local_symbols
: &file_symbols
);
900 add_stab_to_list (name
, &global_stabs
);
904 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
906 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
907 SYMBOL_CLASS (sym
) = LOC_ARG
;
909 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
910 SYMBOL_DUP (sym
, sym2
);
911 add_symbol_to_list (sym2
, &local_symbols
);
915 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
917 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
918 SYMBOL_CLASS (sym
) = LOC_STATIC
;
919 SYMBOL_VALUE (sym
) += static_block_base
;
921 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
922 SYMBOL_DUP (sym
, sym2
);
924 (sym2
, within_function
? &local_symbols
: &file_symbols
);
928 if (*name
== ':' || (pp
= (char *) strchr (name
, ':')) == NULL
)
930 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
931 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
933 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
934 SYMBOL_DUP (sym
, sym2
);
935 add_symbol_to_list (sym2
, &local_symbols
);
939 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
940 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
941 SYMBOL_DUP (sym
, sym2
);
942 add_symbol_to_list (sym2
, &local_symbols
);
946 SYMBOL_CLASS (sym
) = LOC_STATIC
;
947 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
948 SYMBOL_DUP (sym
, sym2
);
949 add_symbol_to_list (sym2
, &global_symbols
);
953 SYMBOL_CLASS (sym
) = LOC_STATIC
;
954 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
955 SYMBOL_DUP (sym
, sym2
);
957 (sym2
, within_function
? &local_symbols
: &file_symbols
);
961 printf ("ERROR! C_REG is not fully implemented!\n");
962 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
963 SYMBOL_NAME (sym
) = SYMNAME_ALLOC (name
, symname_alloced
);
964 SYMBOL_DUP (sym
, sym2
);
965 add_symbol_to_list (sym2
, &local_symbols
);
969 pp
= (char*) strchr (name
, ':');
970 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
971 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (cs
->c_value
);
973 SYMBOL_NAME (sym
) = obsavestring (name
, pp
-name
, &objfile
-> symbol_obstack
);
976 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
979 /* else this is not a stab entry, suppose the type is either
980 `int' or `float', depending on the register class. */
982 SYMBOL_TYPE (sym
) = (SYMBOL_VALUE (sym
) < 32)
983 ? lookup_fundamental_type (current_objfile
, FT_INTEGER
)
984 : lookup_fundamental_type (current_objfile
, FT_FLOAT
);
986 SYMBOL_DUP (sym
, sym2
);
987 add_symbol_to_list (sym2
, &local_symbols
);
991 printf ("ERROR: Unexpected storage class: %d.\n", cs
->c_sclass
);
1000 read_symbol_nvalue (symtable
, symno
)
1004 struct internal_syment symbol
[1];
1006 bfd_coff_swap_sym_in (symfile_bfd
, symtable
+ (symno
*local_symesz
), symbol
);
1007 return symbol
->n_value
;
1012 read_symbol_lineno (symtable
, symno
)
1016 struct internal_syment symbol
[1];
1017 union internal_auxent main_aux
[1];
1021 for (ii
= 0; ii
< 50; ii
++) {
1022 bfd_coff_swap_sym_in (symfile_bfd
,
1023 symtable
+ (symno
*local_symesz
), symbol
);
1024 if (symbol
->n_sclass
== C_FCN
&& 0 == strcmp (symbol
->n_name
, ".bf"))
1026 symno
+= symbol
->n_numaux
+1;
1029 printf ("GDB Error: `.bf' not found.\n");
1033 /* take aux entry and return its lineno */
1035 bfd_coff_swap_aux_in (symfile_bfd
, symtable
+(symno
*local_symesz
),
1036 symbol
->n_type
, symbol
->n_sclass
, main_aux
);
1038 return main_aux
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
1041 /* Support for line number handling */
1043 /* This function is called for every section; it finds the outer limits
1044 * of the line table (minimum and maximum file offset) so that the
1045 * mainline code can read the whole thing for efficiency.
1048 find_linenos(abfd
, asect
, vpinfo
)
1053 struct coff_symfile_info
*info
;
1055 file_ptr offset
, maxoff
;
1057 count
= asect
->lineno_count
;
1062 size
= count
* coff_data (symfile_bfd
)->local_linesz
;
1063 info
= (struct coff_symfile_info
*)vpinfo
;
1064 offset
= asect
->line_filepos
;
1065 maxoff
= offset
+ size
;
1067 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
1068 info
->min_lineno_offset
= offset
;
1070 if (maxoff
> info
->max_lineno_offset
)
1071 info
->max_lineno_offset
= maxoff
;
1075 /* Read in all the line numbers for fast lookups later. Leave them in
1076 external (unswapped) format in memory; we'll swap them as we enter
1077 them into GDB's data structures. */
1080 init_lineno (abfd
, offset
, size
)
1087 if (bfd_seek(abfd
, offset
, 0) < 0)
1090 linetab
= (char *) xmalloc(size
);
1092 val
= bfd_read(linetab
, 1, size
, abfd
);
1096 linetab_offset
= offset
;
1097 linetab_size
= size
;
1098 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1107 printf ("===STRING TABLE DUMP...\n\n");
1108 for ( ii
=0; ii
< strtbl_len
; ++ii
)
1109 printf ("%c", isprint (*(strtbl
+ii
)) ? *(strtbl
+ii
) : ' ');
1114 dump_linetable (ltb
)
1115 struct linetable
*ltb
;
1118 for (ii
=0; ii
< ltb
->nitems
; ++ii
)
1119 printf ("line: %d, addr: 0x%x\n", ltb
->item
[ii
].line
, ltb
->item
[ii
].pc
);
1126 printf ("0x%x: name: %s\n", typeP
, typeP
->name
? typeP
->name
: "(nil)");
1133 printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n",
1134 pp
->name
, dump_namespace (pp
->namespace),
1135 dump_addrclass (pp
->class), pp
->type
,
1136 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_START(SYMBOL_BLOCK_VALUE(pp
))
1138 SYMBOL_CLASS(pp
) == LOC_BLOCK
? BLOCK_END(SYMBOL_BLOCK_VALUE(pp
)) : 0);
1145 static char *ns_name
[] = {
1146 "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"};
1149 case UNDEF_NAMESPACE
:
1151 case STRUCT_NAMESPACE
:
1152 case LABEL_NAMESPACE
:
1156 return "***ERROR***";
1161 int ac
; /* address class */
1163 static char *ac_name
[] = {
1190 case LOC_CONST_BYTES
:
1192 return ac_name
[ac
];
1194 return "***ERROR***";
1202 printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp
->startaddr
, pp
->endaddr
);
1203 for (ii
=0; ii
< pp
->nsyms
; ++ii
)
1204 dump_symbol (pp
->sym
[ii
]);
1208 dump_blockvector (pp
)
1209 struct blockvector
*pp
;
1212 for (ii
=0; ii
< pp
->nblocks
; ++ii
)
1213 dump_block (pp
->block
[ii
]);
1217 dump_last_symtab (pp
)
1220 for ( ; pp
; pp
= pp
->next
) {
1221 if ( pp
->next
== 0 ) {
1222 printf ("SYMTAB NAME: %s\n", pp
->filename
);
1223 dump_blockvector (pp
->blockvector
);
1232 for ( ; pp
; pp
= pp
->next
) {
1233 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
1234 /* if (pp->linetable)
1235 dump_linetable (pp->linetable); */
1236 dump_blockvector (pp
->blockvector
);
1241 dump_symtab_lines (pp
)
1244 for ( ; pp
; pp
= pp
->next
) {
1245 printf ("SYMTAB NAME: %s\n", pp
->filename
? pp
->filename
: "(nil)");
1247 dump_linetable (pp
->linetable
);
1248 /* dump_blockvector (pp->blockvector); */
1253 dump_minimal_symbols (objfile
)
1254 struct objfile
*objfile
;
1256 struct minimal_symbol
*msymbol
;
1258 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
1260 printf ("name: %s, addr: 0x%x\n", msymbol
-> name
, msymbol
-> address
);
1265 /* dbx allows the text of a symbol name to be continued into the
1266 next symbol name! When such a continuation is encountered
1267 (a \ at the end of the text of a name)
1268 call this function to get the continuation. */
1269 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1272 #undef next_symbol_text
1273 #define next_symbol_text() \
1274 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1277 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
1278 the proper type node fora given builtin type #. */
1287 printf ("ERROR!, unknown built-in type!\n");
1291 read_type_number (pp
, typenums
);
1293 /* default types are defined in dbxstclass.h. */
1294 switch ( typenums
[1] ) {
1296 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1298 return lookup_fundamental_type (current_objfile
, FT_CHAR
);
1300 return lookup_fundamental_type (current_objfile
, FT_SHORT
);
1302 return lookup_fundamental_type (current_objfile
, FT_LONG
);
1304 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
1306 return lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
1308 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
1310 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1312 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1314 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
1316 return lookup_fundamental_type (current_objfile
, FT_VOID
);
1318 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1320 return lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
1322 return lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
1324 /* requires a builtin `integer' */
1325 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1327 return lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
1329 /* requires builtin `short real' */
1330 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1332 /* requires builtin `real' */
1333 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1335 printf ("ERROR! Unknown builtin type -%d\n", typenums
[1]);
1340 #if 0 /* Seems to be unused, don't bother converting from old misc function
1341 vector usage to new minimal symbol tables. FIXME: Delete this? */
1343 /* if we now nothing about a function but its address, make a function symbol
1344 out of it with the limited knowladge you have. This will be used when
1345 somebody refers to a function, which doesn't exist in the symbol table,
1346 but is in the minimal symbol table. */
1349 build_function_symbol (ind
, objfile
)
1351 struct objfile
*objfile
;
1353 struct symbol
*sym
=
1354 (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1355 SYMBOL_NAME (sym
) = misc_function_vector
[ind
].name
;
1356 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1357 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1358 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1359 SYMBOL_TYPE (sym
) = lookup_function_type (lookup_fundamental_type (current_objfile
, FT_INTEGER
));
1360 SYMBOL_BLOCK_VALUE (sym
) = (struct block
*)
1361 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct block
));
1362 BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) = misc_function_vector
[ind
].address
;
1371 /* Nothin' to do. */
1375 aixcoff_symfile_init (sf
)
1378 bfd
*abfd
= sf
->sym_bfd
;
1380 /* Allocate struct to keep track of the symfile */
1381 /* FIXME memory leak */
1382 sf
->sym_private
= xmalloc(sizeof (struct coff_symfile_info
));
1385 * Save startup file's range of PC addresses to help
1386 * blockframe.c decide where the bottom of the stack is.
1388 if (bfd_get_file_flags(abfd
) & EXEC_P
) {
1389 entry_point
= bfd_get_start_address(abfd
);
1392 /* set the startup file to be an empty range. */
1393 startup_file_start
= 0;
1394 startup_file_end
= 0;
1400 init_stringtab(abfd
, offset
, objfile
)
1403 struct objfile
*objfile
;
1407 unsigned char lengthbuf
[4];
1409 if (bfd_seek(abfd
, offset
, 0) < 0)
1412 val
= bfd_read((char *)lengthbuf
, 1, sizeof lengthbuf
, abfd
);
1413 length
= bfd_h_get_32(abfd
, lengthbuf
);
1415 /* If no string table is needed, then the file may end immediately
1416 after the symbols. Just return with `strtbl' set to null. */
1418 if (val
!= sizeof length
|| length
< sizeof length
)
1421 /* Allocate string table from symbol_obstack. We will need this table
1422 as long as we have its symbol table around. */
1424 strtbl
= (char*) obstack_alloc (&objfile
->symbol_obstack
, length
);
1428 bcopy(&length
, strtbl
, sizeof length
);
1429 if (length
== sizeof length
)
1432 val
= bfd_read(strtbl
+ sizeof length
, 1, length
- sizeof length
, abfd
);
1434 if (val
!= length
- sizeof length
|| strtbl
[length
- 1] != '\0')
1441 init_debugsection(abfd
)
1444 register sec_ptr secp
;
1445 bfd_size_type length
;
1452 secp
= bfd_get_section_by_name(abfd
, ".debug");
1456 if (!(length
= bfd_section_size(abfd
, secp
)))
1459 debugsec
= (char *) xmalloc ((unsigned)length
);
1460 if (debugsec
== NULL
)
1463 if (!bfd_get_section_contents(abfd
, secp
, debugsec
, (file_ptr
) 0, length
)) {
1464 printf ("Can't read .debug section from symbol file\n");
1479 /* aixcoff version of symbol file read. */
1482 aixcoff_symfile_read (sf
, addr
, mainline
)
1487 int num_symbols
; /* # of symbols */
1488 int symtab_offset
; /* symbol table and */
1489 int stringtab_offset
; /* string table file offsets */
1492 struct coff_symfile_info
*info
= (void*) sf
->sym_private
;
1495 symfile_bfd
= abfd
= sf
->objfile
->obfd
;
1496 name
= sf
->objfile
->name
;
1498 num_symbols
= bfd_get_symcount (abfd
); /* # of symbols */
1499 symtab_offset
= obj_sym_filepos (abfd
); /* symbol table file offset */
1500 stringtab_offset
= symtab_offset
+
1501 num_symbols
* coff_data(abfd
)->local_symesz
;
1503 info
->min_lineno_offset
= 0;
1504 info
->max_lineno_offset
= 0;
1505 bfd_map_over_sections (abfd
, find_linenos
, info
);
1507 /* FIXME! This stuff should move into symfile_init */
1508 if (info
->min_lineno_offset
!= 0
1509 && info
->max_lineno_offset
> info
->min_lineno_offset
) {
1511 /* only read in the line # table if one exists */
1512 val
= init_lineno(abfd
, info
->min_lineno_offset
,
1513 info
->max_lineno_offset
- info
->min_lineno_offset
);
1516 error("\"%s\": error reading line numbers\n", name
);
1519 val
= init_stringtab(abfd
, stringtab_offset
, sf
->objfile
);
1521 error ("\"%s\": can't get string table", name
);
1524 if (init_debugsection(abfd
) < 0) {
1525 error ("Error reading .debug section of `%s'\n", name
);
1528 /* Position to read the symbol table. Do not read it all at once. */
1529 val
= bfd_seek(abfd
, (long)symtab_offset
, 0);
1531 perror_with_name(name
);
1533 if (bfd_tell(abfd
) != symtab_offset
)
1536 init_minimal_symbol_collection ();
1537 make_cleanup (discard_minimal_symbols
, 0);
1539 #ifdef XCOFF_INIT_LOADINFO
1541 XCOFF_INIT_LOADINFO ();
1544 /* Now that the executable file is positioned at symbol table,
1545 process it and define symbols accordingly. */
1547 read_xcoff_symtab(sf
->objfile
, num_symbols
);
1549 make_cleanup (free_debugsection
, 0);
1551 /* Sort symbols alphabetically within each block. */
1554 /* Install any minimal symbols that have been collected as the current
1555 minimal symbols for this objfile. */
1557 install_minimal_symbols (!mainline
, sf
-> objfile
);
1559 /* Make a default for file to list. */
1560 select_source_symtab (0);
1563 /* Register our ability to parse symbols for aixcoff BFD files. */
1565 static struct sym_fns aixcoff_sym_fns
=
1567 "aixcoff-rs6000", 15,
1568 aixcoff_new_init
, aixcoff_symfile_init
,
1569 aixcoff_symfile_read
,
1573 _initialize_xcoffread ()
1575 add_symtab_fns(&aixcoff_sym_fns
);