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. */
28 /* AIX COFF names have a preceeding dot `.' */
29 #define NAMES_HAVE_DOT 1
31 #include <sys/types.h>
36 #include <sys/param.h>
44 #include "internalcoff.h" /* FIXME, internal data from BFD */
45 #include "libcoff.h" /* FIXME, internal data from BFD */
46 #include "coff-rs6000.h" /* FIXME, raw file-format guts of xcoff */
50 static void enter_line_range ();
51 static struct symbol *process_xcoff_symbol ();
52 static int read_symbol_nvalue ();
53 static int read_symbol_lineno ();
56 /* Simplified internal version of coff symbol table information */
60 int c_symnum; /* symbol number of this entry */
61 int c_nsyms; /* 0 if syment only, 1 if syment + auxent */
68 /* The COFF line table, in raw form. */
69 static char *linetab = NULL; /* Its actual contents */
70 static long linetab_offset; /* Its offset in the file */
71 static unsigned long linetab_size; /* Its size */
73 /* last function's saved coff symbol `cs' */
75 static struct coff_symbol fcn_cs_saved;
77 static bfd *symfile_bfd;
79 /* Core address of start and end of text of current source file.
80 This is calculated from the first function seen after a C_FILE
83 static CORE_ADDR cur_src_start_addr;
84 static CORE_ADDR cur_src_end_addr;
86 /* Core address of the end of the first object file. */
88 static CORE_ADDR first_object_file_end;
90 /* pointer to the string table */
93 /* length of the string table */
94 static int strtbl_len;
96 /* pointer to debug section */
97 static char *debugsec;
99 /* pointer to the a.out symbol table */
102 /* initial symbol-table-debug-string vector length */
104 #define INITIAL_STABVECTOR_LENGTH 40
106 struct pending_stabs *global_stabs;
107 struct pending_stabs *file_stabs;
109 /* Nonzero if within a function (so symbols should be local,
110 if nothing says specifically). */
114 /* Local variables that hold the shift and mask values for the
115 COFF file that we are currently reading. These come back to us
116 from BFD, and are referenced by their macro names, as well as
117 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
118 macros from ../internalcoff.h . */
120 static unsigned local_n_btshft;
121 static unsigned local_n_tmask;
124 #define N_BTSHFT local_n_btshft
126 #define N_TMASK local_n_tmask
128 /* Local variables that hold the sizes in the file of various COFF structures.
129 (We only need to know this to read them from the file -- BFD will then
130 translate the data in them, into `internal_xxx' structs in the right
131 byte order, alignment, etc.) */
133 static unsigned local_symesz;
135 /* coff_symfile_init()
136 is the coff-specific initialization routine for reading symbols.
137 It is passed a struct sym_fns which contains, among other things,
138 the BFD for the file whose symbols are being read, and a slot for
139 a pointer to "private data" which we fill with cookies and other
140 treats for coff_symfile_read().
142 We will only be called if this is a COFF or COFF-like file.
143 BFD handles figuring out the format of the file, and code in symtab.c
144 uses BFD's determination to vector to us.
146 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
148 struct coff_symfile_info {
149 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
150 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
154 /* Call sort_syms to sort alphabetically
155 the symbols of each block of each symtab. */
158 compare_symbols (s1, s2)
159 struct symbol **s1, **s2;
161 /* Names that are less should come first. */
162 register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
166 /* For symbols of the same name, registers should come first. */
167 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
168 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
172 /* Sort a vector of symbols by their value. */
177 register struct symtab *s;
179 register struct blockvector *bv;
180 register struct block *b;
182 for (s = symtab_list; s; s = s->next)
184 bv = BLOCKVECTOR (s);
185 nbl = BLOCKVECTOR_NBLOCKS (bv);
186 for (i = 0; i < nbl; i++)
188 b = BLOCKVECTOR_BLOCK (bv, i);
189 if (BLOCK_SHOULD_SORT (b))
190 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
191 sizeof (struct symbol *), compare_symbols);
197 /* add a given stab string into given stab vector. */
200 add_stab_to_list (stabname, stabvector)
202 struct pending_stabs **stabvector;
204 if ( *stabvector == NULL) {
205 *stabvector = (struct pending_stabs *)
206 xmalloc (sizeof (struct pending_stabs) +
207 INITIAL_STABVECTOR_LENGTH * sizeof (char*));
208 (*stabvector)->count = 0;
209 (*stabvector)->length = INITIAL_STABVECTOR_LENGTH;
211 else if ((*stabvector)->count >= (*stabvector)->length) {
212 (*stabvector)->length += INITIAL_STABVECTOR_LENGTH;
213 *stabvector = (struct pending_stabs *)
214 xrealloc (*stabvector, sizeof (struct pending_stabs) +
215 (*stabvector)->length * sizeof (char*));
217 (*stabvector)->stab [(*stabvector)->count++] = stabname;
221 /* for all the stabs in a given stab vector, build appropriate types
222 and fix their symbols in given symbol vector. */
225 patch_block_stabs (symbols, stabs)
226 struct pending *symbols;
227 struct pending_stabs *stabs;
234 /* for all the stab entries, find their corresponding symbols and
235 patch their types! */
237 for (ii=0; ii < stabs->count; ++ii) {
238 char *name = stabs->stab[ii];
239 char *pp = (char*) index (name, ':');
240 struct symbol *sym = find_symbol_in_list (symbols, name, pp-name);
242 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
247 if (*(pp-1) == 'F' || *(pp-1) == 'f')
248 SYMBOL_TYPE (sym) = lookup_function_type (read_type (&pp));
250 SYMBOL_TYPE (sym) = read_type (&pp);
255 /* Enter a given range of lines into the line vector.
256 can be called in the following two ways:
257 enter_line_range (subfile, beginoffset, endoffset, 0, firstLine) or
258 enter_line_range (subfile, beginoffset, 0, endaddr, firstLine) */
261 enter_line_range (subfile, beginoffset, endoffset, endaddr, firstLine)
262 struct subfile *subfile; /* which sub-file to put line#s in */
263 unsigned beginoffset, endoffset; /* offsets to line table */
269 struct internal_lineno lptr;
270 unsigned local_linesz = coff_data (symfile_bfd)->local_linesz;
272 pp = &linetab [beginoffset - linetab_offset];
273 limit = endoffset ? &linetab [endoffset - linetab_offset]
274 : &linetab [linetab_size -1];
276 while (pp <= limit) {
278 /* Swap and align this lineno entry into lptr. */
279 bfd_coff_swap_lineno_in (symfile_bfd, pp, &lptr);
281 /* find the address this line represents */
283 lptr.l_addr.l_paddr : read_symbol_nvalue (symtbl, lptr.l_addr.l_symndx);
285 if (endaddr && addr >= endaddr)
288 if (lptr.l_lnno == 0) {
289 *firstLine = read_symbol_lineno (symtbl, lptr.l_addr.l_symndx);
293 record_line (subfile, *firstLine + lptr.l_lnno, addr);
300 /* Save the vital information for use when closing off the current file.
301 NAME is the file name the symbols came from, START_ADDR is the first
302 text address for the file, and SIZE is the number of bytes of text. */
304 #define complete_symtab(name, start_addr) { \
305 last_source_file = savestring (name, strlen (name)); \
306 cur_src_start_addr = start_addr; \
310 /* Refill the symbol table input buffer
311 and set the variables that control fetching entries from it.
312 Reports an error if no data available.
313 This function can read past the end of the symbol table
314 (into the string table) but this does no harm. */
316 /* Reading symbol table has to be fast! Keep the followings as macros, rather
319 #define RECORD_MISC_FUNCTION(NAME, ADDR, TYPE, ALLOCED) \
323 namestr = (NAME) + 1; \
325 namestr = obstack_copy0 (symbol_obstack, (NAME) + 1, strlen ((NAME)+1)); \
328 prim_record_misc_function (namestr, (ADDR), (TYPE)); \
329 last_recorded_fun = (ADDR); \
334 /* aixcoff has static blocks marked in `.bs', `.es' pairs. They cannot be
335 nested. At any given time, a symbol can only be in one static block.
336 This is the base address of current static block, zero if non exists. */
338 static int static_block_base = 0;
340 /* true if space for symbol name has been allocated. */
342 static int symname_alloced = 0;
344 /* read the whole symbol table of a given bfd. */
347 read_xcoff_symtab (objfile, nsyms)
348 struct objfile *objfile; /* Object file we're reading from */
349 int nsyms; /* # of symbols */
351 bfd *abfd = objfile->obfd;
352 /* char *symtbl; */ /* Raw symbol table base */
353 char *raw_symbol; /* Pointer into raw seething symbol table */
354 char *raw_auxptr; /* Pointer to first raw aux entry for sym */
355 struct internal_syment symbol[1];
356 union internal_auxent main_aux[1];
357 struct coff_symbol cs[1];
358 CORE_ADDR file_start_addr = 0;
359 CORE_ADDR file_end_addr = 0;
361 int next_file_symnum = -1;
362 int just_started = 1;
368 long fcn_line_offset;
371 /* fcn_cs_saved is global because process_xcoff_symbol needs it. */
372 union internal_auxent fcn_aux_saved;
373 struct context_stack *new;
375 char *filestring = " _start_ "; /* Name of the current file. */
376 char *last_seen_csect;
377 int last_recorded_fun = 0; /* last recorded fun. value */
379 /* Get the appropriate COFF "constants" related to the file we're handling. */
380 N_TMASK = coff_data (abfd)->local_n_tmask;
381 N_BTSHFT = coff_data (abfd)->local_n_btshft;
382 local_symesz = coff_data (abfd)->local_symesz;
384 last_source_file = 0;
386 last_recorded_fun = 0;
388 start_symtab (filestring, (char *)NULL, file_start_addr);
390 first_object_file_end = 0;
392 /* Allocate space for the entire symbol table at once, and read it
393 all in. The bfd is already positioned at the beginning of
396 size = coff_data (abfd)->local_symesz * nsyms;
397 symtbl = xmalloc (size);
399 val = bfd_read (symtbl, size, 1, abfd);
401 perror_with_name ("reading symbol table");
405 while (symnum < nsyms) {
407 QUIT; /* make this command interruptable. */
409 /* READ_ONE_SYMBOL (symbol, cs, symname_alloced); */
410 /* read one symbol into `cs' structure. After processing the whole symbol
411 table, only string table will be kept in memory, symbol table and debug
412 section of aixcoff will be freed. Thus we can mark symbols with names
413 in string table as `alloced'. */
417 /* Swap and align the symbol into a reasonable C structure. */
418 bfd_coff_swap_sym_in (abfd, raw_symbol, symbol);
420 cs->c_symnum = symnum;
421 cs->c_nsyms = symbol->n_numaux;
422 if (symbol->n_zeroes) {
424 /* We must use the original, unswapped, name here so the name field
425 pointed to by cs->c_name will persist throughout xcoffread. If
426 we use the new field, it gets overwritten for each symbol. */
427 cs->c_name = ((struct external_syment *)raw_symbol)->e.e_name;
428 } else if (symbol->n_sclass & 0x80) {
429 cs->c_name = debugsec + symbol->n_offset;
431 } else { /* in string table */
432 cs->c_name = strtbl + (int)symbol->n_offset;
435 cs->c_value = symbol->n_value;
436 cs->c_sclass = symbol->n_sclass & 0xff;
437 cs->c_secnum = symbol->n_scnum;
438 cs->c_type = (unsigned)symbol->n_type;
440 raw_symbol += coff_data (abfd)->local_symesz;
443 raw_auxptr = raw_symbol; /* Save addr of first aux entry */
445 /* Skip all the auxents associated with this symbol. */
446 for (ii = symbol->n_numaux; ii; --ii ) {
447 raw_symbol += coff_data (abfd)->local_auxesz;
452 /* if symbol name starts with ".$" or "$", ignore it. */
453 if (cs->c_name[0] == '$' || (cs->c_name[1] == '$' && cs->c_name[0] == '.'))
456 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE) {
457 if (last_source_file)
458 end_symtab (cur_src_end_addr, 1, 1, objfile);
460 start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0);
461 cur_src_end_addr = first_object_file_end;
462 /* done with all files, everything from here on is globals */
465 /* if explicitly specified as a function, treat is as one. */
466 if (ISFCN(cs->c_type) && cs->c_sclass != C_TPDEF) {
467 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
469 goto function_entry_point;
472 if ((cs->c_sclass == C_EXT || cs->c_sclass == C_HIDEXT) && cs->c_nsyms == 1)
474 /* dealing with a symbol with a csect entry. */
476 # define CSECT(PP) ((PP)->x_csect)
477 # define CSECT_LEN(PP) (CSECT(PP).x_scnlen)
478 # define CSECT_ALIGN(PP) (SMTYP_ALIGN(CSECT(PP).x_smtyp))
479 # define CSECT_SMTYP(PP) (SMTYP_SMTYP(CSECT(PP).x_smtyp))
480 # define CSECT_SCLAS(PP) (CSECT(PP).x_smclas)
482 /* Convert the auxent to something we can access. */
483 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
486 switch (CSECT_SMTYP (main_aux)) {
489 continue; /* ignore all external references. */
491 case XTY_SD : /* a section description. */
493 switch (CSECT_SCLAS (main_aux)) {
495 case XMC_PR : /* a `.text' csect. */
498 /* A program csect is seen.
500 We have to allocate one symbol table for each program csect. Normally
501 gdb prefers one symtab for each compilation unit (CU). In case of AIX, one
502 CU might include more than one prog csect, and they don't have to be
503 adjacent in terms of the space they occupy in memory. Thus, one single
504 CU might get fragmented in the memory and gdb's file start and end address
505 approach does not work! */
507 if (last_seen_csect) {
508 complete_symtab (filestring, file_start_addr);
509 cur_src_end_addr = file_end_addr;
510 end_symtab (file_end_addr, 1, 1, objfile);
511 start_symtab ((char *)NULL, (char *)NULL, (CORE_ADDR)0);
514 /* If this is the very first csect seen, basically `__start'. */
516 first_object_file_end = cs->c_value + CSECT_LEN (main_aux);
520 file_start_addr = cs->c_value;
521 file_end_addr = cs->c_value + CSECT_LEN (main_aux);
523 if (cs->c_name && cs->c_name[0] == '.') {
524 last_seen_csect = cs->c_name;
525 RECORD_MISC_FUNCTION (cs->c_name, cs->c_value, mf_text, symname_alloced);
533 /* If the section is not a data description, ignore it. Note that
534 uninitialized data will show up as XTY_CM/XMC_RW pair. */
537 #ifdef XCOFF_ADD_TOC_TO_LOADINFO
538 XCOFF_ADD_TOC_TO_LOADINFO (cs->c_value);
540 /* fall down to default case. */
542 case XMC_TC : /* ignore toc entries */
543 default : /* any other XMC_XXX */
547 break; /* switch CSECT_SCLAS() */
551 /* a function entry point. */
552 if (CSECT_SCLAS (main_aux) == XMC_PR) {
554 function_entry_point:
555 if (cs->c_value != last_recorded_fun)
556 RECORD_MISC_FUNCTION (cs->c_name, cs->c_value, mf_text,
559 fcn_line_offset = main_aux->x_sym.x_fcnary.x_fcn.x_lnnoptr;
560 fcn_start_addr = cs->c_value;
562 /* save the function header info, which will be used
563 when `.bf' is seen. */
565 fcn_aux_saved = *main_aux;
569 /* shared library function entry point. */
570 else if (CSECT_SCLAS (main_aux) == XMC_GL) {
571 if (last_recorded_fun != cs->c_value)
572 RECORD_MISC_FUNCTION (cs->c_name, cs->c_value, mf_text,
578 default : /* all other XTY_XXXs */
580 } /* switch CSECT_SMTYP() */
583 switch (cs->c_sclass) {
587 /* c_value field contains symnum of next .file entry in table
588 or symnum of first global after last .file. */
590 next_file_symnum = cs->c_value;
592 /* complete symbol table for last object file containing
593 debugging information. */
595 /* Whether or not there was a csect in the previous file, we have
596 to call `end_symtab' and `start_symtab' to reset type_vector,
597 line_vector, etc. structures. */
598 complete_symtab (filestring, file_start_addr);
599 cur_src_end_addr = file_end_addr;
600 end_symtab (file_end_addr, 1, 1, objfile);
601 start_symtab (cs->c_name, (char *)NULL, (CORE_ADDR)0);
604 /* reset file start and end addresses. A compilation unit with no text
605 (only data) should have zero file boundaries. */
606 file_start_addr = file_end_addr = 0;
608 filestring = cs->c_name;
613 if (strcmp (cs->c_name, ".bf") == 0) {
615 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
620 /* value contains address of first non-init type code */
621 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
622 contains line number of '{' } */
623 fcn_first_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
625 /* Linenos are now processed on a file-by-file, not fn-by-fn, basis.
627 /* mark_first_line (fcn_line_offset, cs->c_symnum); */
629 new = push_context (0, fcn_start_addr);
630 new->name = process_xcoff_symbol (&fcn_cs_saved);
632 else if (strcmp (cs->c_name, ".ef") == 0) {
634 bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass,
637 /* the value of .ef is the address of epilogue code;
638 not useful for gdb */
639 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
640 contains number of lines to '}' */
642 fcn_last_line = main_aux->x_sym.x_misc.x_lnsz.x_lnno;
644 enter_linenos (fcn_line_offset, fcn_first_line,
645 fcn_first_line + fcn_last_line);
648 new = pop_context ();
649 if (context_stack_depth != 0)
650 error ("invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
653 finish_block (new->name, &local_symbols, new->old_blocks,
655 fcn_cs_saved.c_value +
656 fcn_aux_saved.x_sym.x_misc.x_fsize);
661 case C_BSTAT : /* begin static block */
662 static_block_base = read_symbol_nvalue (symtbl, cs->c_value);
665 case C_ESTAT : /* end of static block */
666 static_block_base = 0;
669 case C_ARG : /* These are not implemented. */
675 printf ("ERROR: Unimplemented storage class: %d.\n", cs->c_sclass);
678 case C_HIDEXT : /* ignore these.. */
683 case C_BINCL : /* beginning of include file */
685 start_subfile (cs->c_name, (char *)0);
686 fcn_first_line = cs->c_value; /* Offset to first lineno of file */
689 case C_EINCL : /* end of include file */
690 fcn_last_line = cs->c_value; /* Offset to last line number */
692 enter_line_range (current_subfile, fcn_first_line, cs->c_value, 0,
695 start_subfile (pop_subfile (), (char *)0);
699 if (strcmp (cs->c_name, ".bb") == 0) {
701 new = push_context (depth, cs->c_value);
703 else if (strcmp (cs->c_name, ".eb") == 0) {
704 new = pop_context ();
705 if (depth != new->depth)
706 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
710 if (local_symbols && context_stack_depth > 0) {
711 /* Make a block for the local symbols within. */
712 finish_block (new->name, &local_symbols, new->old_blocks,
713 new->start_addr, cs->c_value);
715 local_symbols = new->locals;
720 (void) process_xcoff_symbol (cs);
726 if (last_source_file)
727 end_symtab (cur_src_end_addr, 1, 1, objfile);
732 #define SYMBOL_DUP(SYMBOL1, SYMBOL2) \
733 (SYMBOL2) = (struct symbol *) \
734 obstack_alloc (symbol_obstack, sizeof (struct symbol)); \
735 *(SYMBOL2) = *(SYMBOL1);
738 #define SYMNAME_ALLOC(NAME, ALLOCED) \
739 (ALLOCED) ? (NAME) : obstack_copy0 (symbol_obstack, (NAME), strlen (NAME));
743 /* process one xcoff symbol. */
745 static struct symbol *
746 process_xcoff_symbol (cs)
747 register struct coff_symbol *cs;
749 struct symbol onesymbol;
750 register struct symbol *sym = &onesymbol;
751 struct symbol *sym2 = NULL;
753 char *name, *pp, *qq;
759 bzero (sym, sizeof (struct symbol));
761 /* default assumptions */
762 SYMBOL_VALUE (sym) = cs->c_value;
763 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
765 if (ISFCN (cs->c_type)) {
767 /* At this point, we don't know the type of the function and assume it
768 is int. This will be patched with the type from its stab entry later
769 on in patch_block_stabs () */
771 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
772 SYMBOL_TYPE (sym) = lookup_function_type (builtin_type_int);
774 SYMBOL_CLASS (sym) = LOC_BLOCK;
775 SYMBOL_DUP (sym, sym2);
777 if (cs->c_sclass == C_EXT)
778 add_symbol_to_list (sym2, &global_symbols);
779 else if (cs->c_sclass == C_HIDEXT || cs->c_sclass == C_STAT)
780 add_symbol_to_list (sym2, &file_symbols);
785 /* in case we can't figure out the type, default is `int'. */
786 SYMBOL_TYPE (sym) = builtin_type_int;
788 switch (cs->c_sclass)
791 if (fcn_cs_saved.c_sclass == C_EXT)
792 add_stab_to_list (name, &global_stabs);
794 add_stab_to_list (name, &file_stabs);
797 case C_DECL: /* a type decleration?? */
798 qq = (char*) index (name, ':');
799 if (!qq) /* skip if there is no ':' */
803 ttype = SYMBOL_TYPE (sym) = read_type (&pp);
805 /* read_type() will return null if type (or tag) definition was
806 unnnecessarily duplicated. Also, if the symbol doesn't have a name,
807 there is no need to keep it in symbol table. */
809 if (!ttype || name == qq)
813 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
814 else if (qq[1] == 't')
815 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
817 printf ("ERROR: Unrecognized stab string.\n");
821 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
822 SYMBOL_NAME (sym) = obsavestring (name, qq-name);
824 if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE)
825 TYPE_NAME (ttype) = concat (
826 TYPE_CODE (ttype) == TYPE_CODE_UNION ? "union " :
827 TYPE_CODE (ttype) == TYPE_CODE_STRUCT? "struct " : "enum ",
828 SYMBOL_NAME (sym), NULL);
830 else if (!TYPE_NAME (ttype)) /* else, regular typedef. */
831 TYPE_NAME (ttype) = SYMBOL_NAME (sym);
833 SYMBOL_DUP (sym, sym2);
835 (sym2, within_function ? &local_symbols : &file_symbols);
839 add_stab_to_list (name, &global_stabs);
843 if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
845 SYMBOL_NAME (sym) = obsavestring (name, pp-name);
846 SYMBOL_CLASS (sym) = LOC_ARG;
848 SYMBOL_TYPE (sym) = read_type (&pp);
849 SYMBOL_DUP (sym, sym2);
850 add_symbol_to_list (sym2, &local_symbols);
854 if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
856 SYMBOL_NAME (sym) = obsavestring (name, pp-name);
857 SYMBOL_CLASS (sym) = LOC_STATIC;
858 SYMBOL_VALUE (sym) += static_block_base;
860 SYMBOL_TYPE (sym) = read_type (&pp);
861 SYMBOL_DUP (sym, sym2);
863 (sym2, within_function ? &local_symbols : &file_symbols);
867 if (*name == ':' || (pp = (char *) index (name, ':')) == NULL)
869 SYMBOL_NAME (sym) = obsavestring (name, pp-name);
870 SYMBOL_CLASS (sym) = LOC_LOCAL;
872 SYMBOL_TYPE (sym) = read_type (&pp);
873 SYMBOL_DUP (sym, sym2);
874 add_symbol_to_list (sym2, &local_symbols);
878 SYMBOL_CLASS (sym) = LOC_LOCAL;
879 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
880 SYMBOL_DUP (sym, sym2);
881 add_symbol_to_list (sym2, &local_symbols);
885 SYMBOL_CLASS (sym) = LOC_STATIC;
886 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
887 SYMBOL_DUP (sym, sym2);
888 add_symbol_to_list (sym2, &global_symbols);
892 SYMBOL_CLASS (sym) = LOC_STATIC;
893 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
894 SYMBOL_DUP (sym, sym2);
896 (sym2, within_function ? &local_symbols : &file_symbols);
900 printf ("ERROR! C_REG is not fully implemented!\n");
901 SYMBOL_CLASS (sym) = LOC_REGISTER;
902 SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
903 SYMBOL_DUP (sym, sym2);
904 add_symbol_to_list (sym2, &local_symbols);
908 pp = (char*) index (name, ':');
909 SYMBOL_CLASS (sym) = LOC_REGISTER;
910 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (cs->c_value);
912 SYMBOL_NAME (sym) = obsavestring (name, pp-name);
915 SYMBOL_TYPE (sym) = read_type (&pp);
918 /* else this is not a stab entry, suppose the type is either
919 `int' or `float', depending on the register class. */
921 SYMBOL_TYPE (sym) = (SYMBOL_VALUE (sym) < 32) ?
922 builtin_type_int : builtin_type_float;
924 SYMBOL_DUP (sym, sym2);
925 add_symbol_to_list (sym2, &local_symbols);
929 printf ("ERROR: Unexpected storage class: %d.\n", cs->c_sclass);
938 read_symbol_nvalue (symtable, symno)
942 struct internal_syment symbol[1];
944 bfd_coff_swap_sym_in (symfile_bfd, symtable + (symno*local_symesz), symbol);
945 return symbol->n_value;
950 read_symbol_lineno (symtable, symno)
954 struct internal_syment symbol[1];
955 union internal_auxent main_aux[1];
959 for (ii = 0; ii < 50; ii++) {
960 bfd_coff_swap_sym_in (symfile_bfd,
961 symtable + (symno*local_symesz), symbol);
962 if (symbol->n_sclass == C_FCN && 0 == strcmp (symbol->n_name, ".bf"))
964 symno += 1 + symbol->n_numaux+1;
967 printf ("GDB Error: `.bf' not found.\n");
971 /* take aux entry and return its lineno */
973 bfd_coff_swap_aux_in (symfile_bfd, symtable+(symno*local_symesz),
974 symbol->n_type, symbol->n_sclass, main_aux);
976 return main_aux->x_sym.x_misc.x_lnsz.x_lnno;
979 /* Support for line number handling */
981 /* This function is called for every section; it finds the outer limits
982 * of the line table (minimum and maximum file offset) so that the
983 * mainline code can read the whole thing for efficiency.
986 find_linenos(abfd, asect, vpinfo)
991 struct coff_symfile_info *info;
993 file_ptr offset, maxoff;
995 count = asect->lineno_count;
1000 size = count * coff_data (symfile_bfd)->local_linesz;
1001 info = (struct coff_symfile_info *)vpinfo;
1002 offset = asect->line_filepos;
1003 maxoff = offset + size;
1005 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
1006 info->min_lineno_offset = offset;
1008 if (maxoff > info->max_lineno_offset)
1009 info->max_lineno_offset = maxoff;
1013 /* Read in all the line numbers for fast lookups later. Leave them in
1014 external (unswapped) format in memory; we'll swap them as we enter
1015 them into GDB's data structures. */
1018 init_lineno (abfd, offset, size)
1025 if (bfd_seek(abfd, offset, 0) < 0)
1028 linetab = (char *) xmalloc(size);
1030 val = bfd_read(linetab, 1, size, abfd);
1034 linetab_offset = offset;
1035 linetab_size = size;
1036 make_cleanup(free, linetab); /* Be sure it gets de-allocated. */
1045 printf ("===STRING TABLE DUMP...\n\n");
1046 for ( ii=0; ii < strtbl_len; ++ii )
1047 printf ("%c", isprint (*(strtbl+ii)) ? *(strtbl+ii) : ' ');
1052 dump_linetable (ltb)
1053 struct linetable *ltb;
1056 for (ii=0; ii < ltb->nitems; ++ii)
1057 printf ("line: %d, addr: 0x%x\n", ltb->item[ii].line, ltb->item[ii].pc);
1064 printf ("0x%x: name: %s\n", typeP, typeP->name ? typeP->name : "(nil)");
1067 char *dump_namespace ();
1068 char *dump_addrclass ();
1074 printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n",
1075 pp->name, dump_namespace (pp->namespace),
1076 dump_addrclass (pp->class), pp->type,
1077 SYMBOL_CLASS(pp) == LOC_BLOCK ? BLOCK_START(SYMBOL_BLOCK_VALUE(pp))
1079 SYMBOL_CLASS(pp) == LOC_BLOCK ? BLOCK_END(SYMBOL_BLOCK_VALUE(pp)) : 0);
1087 static char *ns_name [] = {
1088 "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"};
1091 case UNDEF_NAMESPACE:
1093 case STRUCT_NAMESPACE:
1094 case LABEL_NAMESPACE:
1098 return "***ERROR***";
1104 int ac; /* address class */
1106 static char *ac_name [] = {
1133 case LOC_CONST_BYTES:
1135 return ac_name [ac];
1137 return "***ERROR***";
1145 printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp->startaddr, pp->endaddr);
1146 for (ii=0; ii < pp->nsyms; ++ii)
1147 dump_symbol (pp->sym[ii]);
1151 dump_blockvector (pp)
1152 struct blockvector *pp;
1155 for (ii=0; ii < pp->nblocks; ++ii)
1156 dump_block (pp->block [ii]);
1161 dump_last_symtab (pp)
1164 for ( ; pp; pp = pp->next) {
1165 if ( pp->next == 0 ) {
1166 printf ("SYMTAB NAME: %s\n", pp->filename);
1167 dump_blockvector (pp->blockvector);
1176 for ( ; pp; pp = pp->next) {
1177 printf ("SYMTAB NAME: %s\n", pp->filename ? pp->filename : "(nil)");
1178 /* if (pp->linetable)
1179 dump_linetable (pp->linetable); */
1180 dump_blockvector (pp->blockvector);
1185 dump_symtab_lines (pp)
1188 for ( ; pp; pp = pp->next) {
1189 printf ("SYMTAB NAME: %s\n", pp->filename ? pp->filename : "(nil)");
1191 dump_linetable (pp->linetable);
1192 /* dump_blockvector (pp->blockvector); */
1200 for (ii=0; ii < misc_function_count; ++ii)
1201 printf ("name: %s, addr: 0x%x\n",
1202 misc_function_vector[ii].name,
1203 misc_function_vector[ii].address);
1207 /* dbx allows the text of a symbol name to be continued into the
1208 next symbol name! When such a continuation is encountered
1209 (a \ at the end of the text of a name)
1210 call this function to get the continuation. */
1211 /* So far, I haven't seen this happenning xlc output. I doubt we'll need this
1214 #define next_symbol_text() \
1215 printf ("Gdb Error: symbol names on multiple lines not implemented.\n")
1218 /* xlc/dbx combination uses a set of builtin types, starting from -1. return
1219 the proper type node fora given builtin type #. */
1228 printf ("ERROR!, unknown built-in type!\n");
1232 read_type_number (pp, typenums);
1234 /* default types are defined in dbxstclass.h. */
1235 switch ( typenums[1] ) {
1237 return builtin_type_int;
1239 return builtin_type_char;
1241 return builtin_type_short;
1243 return builtin_type_long;
1245 return builtin_type_unsigned_char;
1247 return builtin_type_char; /* requires a builtin `signed char' */
1249 return builtin_type_unsigned_short;
1251 return builtin_type_unsigned_int;
1253 return builtin_type_unsigned_int;
1255 return builtin_type_unsigned_long;
1257 return builtin_type_void;
1259 return builtin_type_float;
1261 return builtin_type_double;
1263 return builtin_type_double; /* requires a builtin `long double' */
1265 return builtin_type_int; /* requires a builtin `integer' */
1267 return builtin_type_int; /* requires builtin `boolean' */
1269 return builtin_type_float; /* requires builtin `short real' */
1271 return builtin_type_float; /* requires builtin `real' */
1273 printf ("ERROR! Unknown builtin type -%d\n", typenums[1]);
1278 /* if we now nothing about a function but its address, make a function symbol
1279 out of it with the limited knowladge you have. This will be used when
1280 somebody refers to a function, which doesn't exist in the symbol table,
1281 but in misc_function_vector. */
1284 build_function_symbol (ind)
1287 struct symbol *sym =
1288 (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
1289 SYMBOL_NAME (sym) = misc_function_vector[ind].name;
1290 /* SYMBOL_VALUE (sym) = misc_function_vector[ind].address; */
1291 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1292 SYMBOL_CLASS (sym) = LOC_BLOCK;
1293 SYMBOL_TYPE (sym) = lookup_function_type (builtin_type_int);
1294 SYMBOL_BLOCK_VALUE (sym) = (struct block *)
1295 obstack_alloc (symbol_obstack, sizeof (struct block));
1296 BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) = misc_function_vector[ind].address;
1304 /* Nothin' to do. */
1308 aixcoff_symfile_init (sf)
1311 bfd *abfd = sf->sym_bfd;
1313 /* Allocate struct to keep track of the symfile */
1314 /* FIXME memory leak */
1315 sf->sym_private = xmalloc(sizeof (struct coff_symfile_info));
1318 * Save startup file's range of PC addresses to help
1319 * blockframe.c decide where the bottom of the stack is.
1321 if (bfd_get_file_flags(abfd) & EXEC_P) {
1322 entry_point = bfd_get_start_address(abfd);
1325 /* set the startup file to be an empty range. */
1326 startup_file_start = 0;
1327 startup_file_end = 0;
1333 init_stringtab(abfd, offset)
1339 unsigned char lengthbuf[4];
1341 if (bfd_seek(abfd, offset, 0) < 0)
1344 val = bfd_read((char *)lengthbuf, 1, sizeof lengthbuf, abfd);
1345 length = bfd_h_get_32(abfd, lengthbuf);
1347 /* If no string table is needed, then the file may end immediately
1348 after the symbols. Just return with `strtbl' set to null. */
1350 if (val != sizeof length || length < sizeof length)
1353 /* Allocate string table from symbol_obstack. We will need this table
1354 as long as we have its symbol table around. */
1356 strtbl = (char*) obstack_alloc (symbol_obstack, length);
1360 bcopy(&length, strtbl, sizeof length);
1361 if (length == sizeof length)
1364 val = bfd_read(strtbl + sizeof length, 1, length - sizeof length, abfd);
1366 if (val != length - sizeof length || strtbl[length - 1] != '\0')
1373 init_debugsection(abfd)
1376 register sec_ptr secp;
1377 bfd_size_type length;
1384 secp = bfd_get_section_by_name(abfd, ".debug");
1388 if (!(length = bfd_section_size(abfd, secp)))
1391 debugsec = (void *) xmalloc ((unsigned)length);
1392 if (debugsec == NULL)
1395 if (!bfd_get_section_contents(abfd, secp, debugsec, (file_ptr) 0, length)) {
1396 printf ("Can't read .debug section from symbol file\n");
1411 /* aixcoff version of symbol file read. */
1414 aixcoff_symfile_read (sf, addr, mainline)
1419 int num_symbols; /* # of symbols */
1420 int symtab_offset; /* symbol table and */
1421 int stringtab_offset; /* string table file offsets */
1424 struct coff_symfile_info *info = (void*) sf->sym_private;
1427 symfile_bfd = abfd = sf->objfile->obfd;
1428 name = sf->objfile->name;
1430 num_symbols = bfd_get_symcount (abfd); /* # of symbols */
1431 symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
1432 stringtab_offset = symtab_offset +
1433 num_symbols * coff_data(abfd)->local_symesz;
1435 info->min_lineno_offset = 0;
1436 info->max_lineno_offset = 0;
1437 bfd_map_over_sections (abfd, find_linenos, info);
1439 /* FIXME! This stuff should move into symfile_init */
1440 if (info->min_lineno_offset != 0
1441 && info->max_lineno_offset > info->min_lineno_offset) {
1443 /* only read in the line # table if one exists */
1444 val = init_lineno(abfd, info->min_lineno_offset,
1445 info->max_lineno_offset - info->min_lineno_offset);
1448 error("\"%s\": error reading line numbers\n", name);
1451 val = init_stringtab(abfd, stringtab_offset);
1453 error ("\"%s\": can't get string table", name);
1456 if (init_debugsection(abfd) < 0) {
1457 error ("Error reading .debug section of `%s'\n", name);
1460 /* Position to read the symbol table. Do not read it all at once. */
1461 val = bfd_seek(abfd, (long)symtab_offset, 0);
1463 perror_with_name(name);
1465 if (bfd_tell(abfd) != symtab_offset)
1468 init_misc_bunches ();
1469 make_cleanup(discard_misc_bunches, 0);
1471 #ifdef XCOFF_INIT_LOADINFO
1473 XCOFF_INIT_LOADINFO ();
1476 /* Now that the executable file is positioned at symbol table,
1477 process it and define symbols accordingly. */
1479 read_xcoff_symtab(sf->objfile, num_symbols);
1481 make_cleanup(free_debugsection, 0);
1483 /* Sort symbols alphabetically within each block. */
1486 /* Go over the misc functions and install them in vector. */
1487 condense_misc_bunches (!mainline);
1489 /* Make a default for file to list. */
1490 select_source_symtab (0);
1493 /* Register our ability to parse symbols for aixcoff BFD files. */
1495 static struct sym_fns aixcoff_sym_fns =
1497 "aixcoff-rs6000", 15,
1498 aixcoff_new_init, aixcoff_symfile_init,
1499 aixcoff_symfile_read,
1503 _initialize_xcoffread ()
1505 add_symtab_fns(&aixcoff_sym_fns);