1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Written by the Center for Software Science at the University of Utah
23 and by Cygnus Support. */
27 #include "gdb_string.h"
28 #include "hp-symtab.h"
34 #include "complaints.h"
35 #include "gdb-stabs.h"
39 /* Private information attached to an objfile which we use to find
40 and internalize the HP C debug symbols within that objfile. */
42 struct hpread_symfile_info
44 /* The contents of each of the debug sections (there are 4 of them). */
50 /* We keep the size of the $VT$ section for range checking. */
53 /* Some routines still need to know the number of symbols in the
54 main debug sections ($LNTT$ and $GNTT$). */
55 unsigned int lntt_symcount;
56 unsigned int gntt_symcount;
58 /* To keep track of all the types we've processed. */
59 struct type **type_vector;
60 int type_vector_length;
62 /* Keeps track of the beginning of a range of source lines. */
65 /* Some state variables we'll need. */
68 /* Keep track of the current function's address. We may need to look
69 up something based on this address. */
70 unsigned int current_function_value;
73 /* Accessor macros to get at the fields. */
74 #define HPUX_SYMFILE_INFO(o) \
75 ((struct hpread_symfile_info *)((o)->sym_private))
76 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
77 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
78 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
79 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
80 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
81 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
82 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
83 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
84 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
85 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
86 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
87 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
89 /* Given the native debug symbol SYM, set NAMEP to the name associated
90 with the debug symbol. Note we may be called with a debug symbol which
91 has no associated name, in that case we return an empty string.
93 Also note we "know" that the name for any symbol is always in the
94 same place. Hence we don't have to conditionalize on the symbol type. */
95 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
96 if (! hpread_has_name ((SYM)->dblock.kind)) \
98 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
100 complain (&string_table_offset_complaint, (char *) symnum); \
104 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
106 /* We put a pointer to this structure in the read_symtab_private field
111 /* The offset within the file symbol table of first local symbol for
116 /* Length (in bytes) of the section of the symbol table devoted to
117 this file's symbols (actually, the section bracketed may contain
118 more than just this file's symbols). If ldsymlen is 0, the only
119 reason for this thing's existence is the dependency list.
120 Nothing else will happen when it is read in. */
125 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
126 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
127 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
129 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
130 /* Complaints about the symbols we have encountered. */
131 extern struct complaint string_table_offset_complaint;
132 extern struct complaint lbrac_unmatched_complaint;
133 extern struct complaint lbrac_mismatch_complaint;
136 void hpread_symfile_init (struct objfile *);
138 static struct type *hpread_read_array_type (dnttpointer, union dnttentry *,
141 static struct type *hpread_alloc_type (dnttpointer, struct objfile *);
143 static struct type **hpread_lookup_type (dnttpointer, struct objfile *);
145 static struct type *hpread_read_enum_type
146 (dnttpointer, union dnttentry *, struct objfile *);
148 static struct type *hpread_read_set_type
149 (dnttpointer, union dnttentry *, struct objfile *);
151 static struct type *hpread_read_subrange_type
152 (dnttpointer, union dnttentry *, struct objfile *);
154 static struct type *hpread_read_struct_type
155 (dnttpointer, union dnttentry *, struct objfile *);
157 void hpread_build_psymtabs (struct objfile *, int);
159 void hpread_symfile_finish (struct objfile *);
161 static struct partial_symtab *hpread_start_psymtab
162 (struct objfile *, char *, CORE_ADDR, int,
163 struct partial_symbol **, struct partial_symbol **);
165 static struct partial_symtab *hpread_end_psymtab
166 (struct partial_symtab *, char **, int, int, CORE_ADDR,
167 struct partial_symtab **, int);
169 static struct symtab *hpread_expand_symtab
170 (struct objfile *, int, int, CORE_ADDR, int,
171 struct section_offsets *, char *);
173 static void hpread_process_one_debug_symbol
174 (union dnttentry *, char *, struct section_offsets *,
175 struct objfile *, CORE_ADDR, int, char *, int);
177 static sltpointer hpread_record_lines
178 (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR);
180 static struct type *hpread_read_function_type
181 (dnttpointer, union dnttentry *, struct objfile *);
183 static struct type *hpread_type_lookup (dnttpointer, struct objfile *);
185 static unsigned long hpread_get_depth (sltpointer, struct objfile *);
187 static unsigned long hpread_get_line (sltpointer, struct objfile *);
189 static CORE_ADDR hpread_get_location (sltpointer, struct objfile *);
191 static int hpread_type_translate (dnttpointer);
192 static unsigned long hpread_get_textlow (int, int, struct objfile *);
193 static union dnttentry *hpread_get_gntt (int, struct objfile *);
194 static union dnttentry *hpread_get_lntt (int, struct objfile *);
195 static union sltentry *hpread_get_slt (int, struct objfile *);
196 static void hpread_psymtab_to_symtab (struct partial_symtab *);
197 static void hpread_psymtab_to_symtab_1 (struct partial_symtab *);
198 static int hpread_has_name (enum dntt_entry_type);
201 /* Initialization for reading native HP C debug symbols from OBJFILE.
203 It's only purpose in life is to set up the symbol reader's private
204 per-objfile data structures, and read in the raw contents of the debug
205 sections (attaching pointers to the debug info into the private data
208 Since BFD doesn't know how to read debug symbols in a format-independent
209 way (and may never do so...), we have to do it ourselves. Note we may
210 be called on a file without native HP C debugging symbols.
211 FIXME, there should be a cleaner peephole into the BFD environment here. */
214 hpread_symfile_init (struct objfile *objfile)
216 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
218 /* Allocate struct to keep track of the symfile */
219 objfile->sym_private = (PTR)
220 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
221 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
223 /* We haven't read in any types yet. */
224 TYPE_VECTOR (objfile) = 0;
226 /* Read in data from the $GNTT$ subspace. */
227 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
232 = obstack_alloc (&objfile->symbol_obstack,
233 bfd_section_size (objfile->obfd, gntt_section));
235 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
236 0, bfd_section_size (objfile->obfd, gntt_section));
238 GNTT_SYMCOUNT (objfile)
239 = bfd_section_size (objfile->obfd, gntt_section)
240 / sizeof (struct dntt_type_block);
242 /* Read in data from the $LNTT$ subspace. Also keep track of the number
244 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
249 = obstack_alloc (&objfile->symbol_obstack,
250 bfd_section_size (objfile->obfd, lntt_section));
252 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
253 0, bfd_section_size (objfile->obfd, lntt_section));
255 LNTT_SYMCOUNT (objfile)
256 = bfd_section_size (objfile->obfd, lntt_section)
257 / sizeof (struct dntt_type_block);
259 /* Read in data from the $SLT$ subspace. $SLT$ contains information
260 on source line numbers. */
261 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
266 obstack_alloc (&objfile->symbol_obstack,
267 bfd_section_size (objfile->obfd, slt_section));
269 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
270 0, bfd_section_size (objfile->obfd, slt_section));
272 /* Read in data from the $VT$ subspace. $VT$ contains things like
273 names and constants. Keep track of the number of symbols in the VT. */
274 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
278 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
281 (char *) obstack_alloc (&objfile->symbol_obstack,
284 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
285 0, VT_SIZE (objfile));
288 /* Scan and build partial symbols for a symbol file.
290 The minimal symbol table (either SOM or HP a.out) has already been
291 read in; all we need to do is setup partial symbols based on the
292 native debugging information.
294 We assume hpread_symfile_init has been called to initialize the
295 symbol reader's private data structures.
297 MAINLINE is true if we are reading the main symbol
298 table (as opposed to a shared lib or dynamically loaded file). */
301 hpread_build_psymtabs (struct objfile *objfile, int mainline)
304 int past_first_source_file = 0;
305 struct cleanup *old_chain;
307 int hp_symnum, symcount, i;
309 union dnttentry *dn_bufp;
315 /* Current partial symtab */
316 struct partial_symtab *pst;
318 /* List of current psymtab's include files */
319 char **psymtab_include_list;
320 int includes_allocated;
323 /* Index within current psymtab dependency list */
324 struct partial_symtab **dependency_list;
325 int dependencies_used, dependencies_allocated;
327 /* Just in case the stabs reader left turds lying around. */
328 free_pending_blocks ();
329 make_cleanup (really_free_pendings, 0);
331 pst = (struct partial_symtab *) 0;
333 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
334 a number of problems with cross compilation and creating useless holes
335 in the stack when we have to allocate new entries. FIXME. */
337 includes_allocated = 30;
339 psymtab_include_list = (char **) alloca (includes_allocated *
342 dependencies_allocated = 30;
343 dependencies_used = 0;
345 (struct partial_symtab **) alloca (dependencies_allocated *
346 sizeof (struct partial_symtab *));
348 old_chain = make_cleanup_free_objfile (objfile);
350 last_source_file = 0;
352 /* Make two passes, one ofr the GNTT symbols, the other for the
354 for (i = 0; i < 1; i++)
356 int within_function = 0;
359 symcount = GNTT_SYMCOUNT (objfile);
361 symcount = LNTT_SYMCOUNT (objfile);
363 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
367 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
369 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
371 if (dn_bufp->dblock.extension)
374 /* Only handle things which are necessary for minimal symbols.
375 everything else is ignored. */
376 switch (dn_bufp->dblock.kind)
378 case DNTT_TYPE_SRCFILE:
380 /* A source file of some kind. Note this may simply
381 be an included file. */
382 SET_NAMESTRING (dn_bufp, &namestring, objfile);
384 /* Check if this is the source file we are already working
386 if (pst && !strcmp (namestring, pst->filename))
389 /* Check if this is an include file, if so check if we have
390 already seen it. Add it to the include list */
391 p = strrchr (namestring, '.');
392 if (!strcmp (p, ".h"))
397 for (j = 0; j < includes_used; j++)
398 if (!strcmp (namestring, psymtab_include_list[j]))
406 /* Add it to the list of includes seen so far and
407 allocate more include space if necessary. */
408 psymtab_include_list[includes_used++] = namestring;
409 if (includes_used >= includes_allocated)
411 char **orig = psymtab_include_list;
413 psymtab_include_list = (char **)
414 alloca ((includes_allocated *= 2) *
416 memcpy ((PTR) psymtab_include_list, (PTR) orig,
417 includes_used * sizeof (char *));
427 pst->filename = (char *)
428 obstack_alloc (&pst->objfile->psymbol_obstack,
429 strlen (namestring) + 1);
430 strcpy (pst->filename, namestring);
437 /* This is a bonafide new source file.
438 End the current partial symtab and start a new one. */
440 if (pst && past_first_source_file)
442 hpread_end_psymtab (pst, psymtab_include_list,
445 * sizeof (struct dntt_type_block)),
447 dependency_list, dependencies_used);
448 pst = (struct partial_symtab *) 0;
450 dependencies_used = 0;
453 past_first_source_file = 1;
455 valu = hpread_get_textlow (i, hp_symnum, objfile);
456 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
457 pst = hpread_start_psymtab (objfile,
460 * sizeof (struct dntt_type_block)),
461 objfile->global_psymbols.next,
462 objfile->static_psymbols.next);
468 case DNTT_TYPE_MODULE:
469 /* A source file. It's still unclear to me what the
470 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
471 is supposed to be. */
472 SET_NAMESTRING (dn_bufp, &namestring, objfile);
473 valu = hpread_get_textlow (i, hp_symnum, objfile);
474 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
477 pst = hpread_start_psymtab (objfile,
480 * sizeof (struct dntt_type_block)),
481 objfile->global_psymbols.next,
482 objfile->static_psymbols.next);
487 case DNTT_TYPE_FUNCTION:
488 case DNTT_TYPE_ENTRY:
489 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
490 a secondary entry point. */
491 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
492 SECT_OFF_TEXT (objfile));
495 valu = dn_bufp->dfunc.lowaddr +
496 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
497 SET_NAMESTRING (dn_bufp, &namestring, objfile);
498 add_psymbol_to_list (namestring, strlen (namestring),
499 VAR_NAMESPACE, LOC_BLOCK,
500 &objfile->static_psymbols, valu,
501 0, language_unknown, objfile);
504 case DNTT_TYPE_BEGIN:
506 /* Scope block begin/end. We only care about function
507 and file blocks right now. */
508 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
510 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
512 * sizeof (struct dntt_type_block)),
514 dependency_list, dependencies_used);
515 pst = (struct partial_symtab *) 0;
517 dependencies_used = 0;
520 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
525 case DNTT_TYPE_TYPEDEF:
526 case DNTT_TYPE_TAGDEF:
528 /* Variables, typedefs an the like. */
529 enum address_class storage;
530 namespace_enum namespace;
532 /* Don't add locals to the partial symbol table. */
534 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
535 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
538 /* TAGDEFs go into the structure namespace. */
539 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
540 namespace = STRUCT_NAMESPACE;
542 namespace = VAR_NAMESPACE;
544 /* What kind of "storage" does this use? */
545 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
546 storage = LOC_STATIC;
547 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
548 && dn_bufp->ddvar.regvar)
549 storage = LOC_REGISTER;
550 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
555 SET_NAMESTRING (dn_bufp, &namestring, objfile);
558 pst = hpread_start_psymtab (objfile,
561 * sizeof (struct dntt_type_block)),
562 objfile->global_psymbols.next,
563 objfile->static_psymbols.next);
565 if (dn_bufp->dsvar.global)
567 add_psymbol_to_list (namestring, strlen (namestring),
569 &objfile->global_psymbols,
570 dn_bufp->dsvar.location,
571 0, language_unknown, objfile);
575 add_psymbol_to_list (namestring, strlen (namestring),
577 &objfile->static_psymbols,
578 dn_bufp->dsvar.location,
579 0, language_unknown, objfile);
583 case DNTT_TYPE_MEMENUM:
584 case DNTT_TYPE_CONST:
585 /* Constants and members of enumerated types. */
586 SET_NAMESTRING (dn_bufp, &namestring, objfile);
589 pst = hpread_start_psymtab (objfile,
592 * sizeof (struct dntt_type_block)),
593 objfile->global_psymbols.next,
594 objfile->static_psymbols.next);
596 add_psymbol_to_list (namestring, strlen (namestring),
597 VAR_NAMESPACE, LOC_CONST,
598 &objfile->static_psymbols, 0,
599 0, language_unknown, objfile);
607 /* End any pending partial symbol table. */
610 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
611 hp_symnum * sizeof (struct dntt_type_block),
612 0, dependency_list, dependencies_used);
615 discard_cleanups (old_chain);
618 /* Perform any local cleanups required when we are done with a particular
619 objfile. I.E, we are in the process of discarding all symbol information
620 for an objfile, freeing up all memory held for it, and unlinking the
621 objfile struct from the global list of known objfiles. */
624 hpread_symfile_finish (struct objfile *objfile)
626 if (objfile->sym_private != NULL)
628 xmfree (objfile->md, objfile->sym_private);
633 /* The remaining functions are all for internal use only. */
635 /* Various small functions to get entries in the debug symbol sections. */
637 static union dnttentry *
638 hpread_get_lntt (int index, struct objfile *objfile)
640 return (union dnttentry *)
641 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
644 static union dnttentry *
645 hpread_get_gntt (int index, struct objfile *objfile)
647 return (union dnttentry *)
648 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
651 static union sltentry *
652 hpread_get_slt (int index, struct objfile *objfile)
654 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
657 /* Get the low address associated with some symbol (typically the start
658 of a particular source file or module). Since that information is not
659 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
660 must infer it from the existence of DNTT_TYPE_FUNCTION symbols. */
663 hpread_get_textlow (int global, int index, struct objfile *objfile)
665 union dnttentry *dn_bufp;
666 struct minimal_symbol *msymbol;
668 /* Look for a DNTT_TYPE_FUNCTION symbol. */
672 dn_bufp = hpread_get_gntt (index++, objfile);
674 dn_bufp = hpread_get_lntt (index++, objfile);
676 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
677 && dn_bufp->dblock.kind != DNTT_TYPE_END);
679 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
680 might happen when a sourcefile has no functions. */
681 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
684 /* The minimal symbols are typically more accurate for some reason. */
685 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
688 return SYMBOL_VALUE_ADDRESS (msymbol);
690 return dn_bufp->dfunc.lowaddr;
693 /* Get the nesting depth for the source line identified by INDEX. */
696 hpread_get_depth (sltpointer index, struct objfile *objfile)
698 union sltentry *sl_bufp;
700 sl_bufp = hpread_get_slt (index, objfile);
701 return sl_bufp->sspec.backptr.dnttp.index;
704 /* Get the source line number the the line identified by INDEX. */
707 hpread_get_line (sltpointer index, struct objfile *objfile)
709 union sltentry *sl_bufp;
711 sl_bufp = hpread_get_slt (index, objfile);
712 return sl_bufp->snorm.line;
716 hpread_get_location (sltpointer index, struct objfile *objfile)
718 union sltentry *sl_bufp;
721 /* code location of special sltentrys is determined from context */
722 sl_bufp = hpread_get_slt (index, objfile);
724 if (sl_bufp->snorm.sltdesc == SLT_END)
726 /* find previous normal sltentry and get address */
727 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
728 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
729 sl_bufp = hpread_get_slt (index - i, objfile);
730 return sl_bufp->snorm.address;
733 /* find next normal sltentry and get address */
734 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
735 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
736 sl_bufp = hpread_get_slt (index + i, objfile);
737 return sl_bufp->snorm.address;
741 /* Return 1 if an HP debug symbol of type KIND has a name associated with
742 it, else return 0. */
745 hpread_has_name (enum dntt_entry_type kind)
749 case DNTT_TYPE_SRCFILE:
750 case DNTT_TYPE_MODULE:
751 case DNTT_TYPE_FUNCTION:
752 case DNTT_TYPE_ENTRY:
753 case DNTT_TYPE_IMPORT:
754 case DNTT_TYPE_LABEL:
755 case DNTT_TYPE_FPARAM:
758 case DNTT_TYPE_CONST:
759 case DNTT_TYPE_TYPEDEF:
760 case DNTT_TYPE_TAGDEF:
761 case DNTT_TYPE_MEMENUM:
762 case DNTT_TYPE_FIELD:
766 case DNTT_TYPE_BEGIN:
769 case DNTT_TYPE_COMMON:
770 case DNTT_TYPE_POINTER:
773 case DNTT_TYPE_SUBRANGE:
774 case DNTT_TYPE_ARRAY:
775 case DNTT_TYPE_STRUCT:
776 case DNTT_TYPE_UNION:
777 case DNTT_TYPE_VARIANT:
779 case DNTT_TYPE_FUNCTYPE:
780 case DNTT_TYPE_COBSTRUCT:
782 case DNTT_TYPE_MACRO:
788 /* Allocate and partially fill a partial symtab. It will be
789 completely filled at the end of the symbol list.
791 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
792 is the address relative to which its symbols are (incremental) or 0
795 static struct partial_symtab *
796 hpread_start_psymtab (struct objfile *objfile, char *filename,
797 CORE_ADDR textlow, int ldsymoff,
798 struct partial_symbol **global_syms,
799 struct partial_symbol **static_syms)
801 struct partial_symtab *result =
802 start_psymtab_common (objfile, section_offsets,
803 filename, textlow, global_syms, static_syms);
805 result->read_symtab_private = (char *)
806 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
807 LDSYMOFF (result) = ldsymoff;
808 result->read_symtab = hpread_psymtab_to_symtab;
814 /* Close off the current usage of PST.
815 Returns PST or NULL if the partial symtab was empty and thrown away.
817 FIXME: List variables and peculiarities of same. */
819 static struct partial_symtab *
820 hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
821 int num_includes, int capping_symbol_offset,
822 CORE_ADDR capping_text,
823 struct partial_symtab **dependency_list,
824 int number_dependencies)
827 struct objfile *objfile = pst->objfile;
829 if (capping_symbol_offset != -1)
830 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
831 pst->texthigh = capping_text;
834 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
836 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
838 pst->number_of_dependencies = number_dependencies;
839 if (number_dependencies)
841 pst->dependencies = (struct partial_symtab **)
842 obstack_alloc (&objfile->psymbol_obstack,
843 number_dependencies * sizeof (struct partial_symtab *));
844 memcpy (pst->dependencies, dependency_list,
845 number_dependencies * sizeof (struct partial_symtab *));
848 pst->dependencies = 0;
850 for (i = 0; i < num_includes; i++)
852 struct partial_symtab *subpst =
853 allocate_psymtab (include_list[i], objfile);
855 subpst->section_offsets = pst->section_offsets;
856 subpst->read_symtab_private =
857 (char *) obstack_alloc (&objfile->psymbol_obstack,
858 sizeof (struct symloc));
862 subpst->texthigh = 0;
864 /* We could save slight bits of space by only making one of these,
865 shared by the entire set of include files. FIXME-someday. */
866 subpst->dependencies = (struct partial_symtab **)
867 obstack_alloc (&objfile->psymbol_obstack,
868 sizeof (struct partial_symtab *));
869 subpst->dependencies[0] = pst;
870 subpst->number_of_dependencies = 1;
872 subpst->globals_offset =
873 subpst->n_global_syms =
874 subpst->statics_offset =
875 subpst->n_static_syms = 0;
879 subpst->read_symtab = pst->read_symtab;
882 sort_pst_symbols (pst);
884 /* If there is already a psymtab or symtab for a file of this name, remove it.
885 (If there is a symtab, more drastic things also happen.)
886 This happens in VxWorks. */
887 free_named_symtabs (pst->filename);
889 if (num_includes == 0
890 && number_dependencies == 0
891 && pst->n_global_syms == 0
892 && pst->n_static_syms == 0)
894 /* Throw away this psymtab, it's empty. We can't deallocate it, since
895 it is on the obstack, but we can forget to chain it on the list. */
896 /* Empty psymtabs happen as a result of header files which don't have
897 any symbols in them. There can be a lot of them. But this check
898 is wrong, in that a psymtab with N_SLINE entries but nothing else
899 is not empty, but we don't realize that. Fixing that without slowing
900 things down might be tricky. */
902 discard_psymtab (pst);
904 /* Indicate that psymtab was thrown away. */
905 pst = (struct partial_symtab *) NULL;
910 /* Do the dirty work of reading in the full symbol from a partial symbol
914 hpread_psymtab_to_symtab_1 (struct partial_symtab *pst)
916 struct cleanup *old_chain;
919 /* Get out quick if passed junk. */
923 /* Complain if we've already read in this symbol table. */
926 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
931 /* Read in all partial symtabs on which this one is dependent */
932 for (i = 0; i < pst->number_of_dependencies; i++)
933 if (!pst->dependencies[i]->readin)
935 /* Inform about additional files that need to be read in. */
938 fputs_filtered (" ", gdb_stdout);
940 fputs_filtered ("and ", gdb_stdout);
942 printf_filtered ("%s...", pst->dependencies[i]->filename);
943 wrap_here (""); /* Flush output */
944 gdb_flush (gdb_stdout);
946 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
949 /* If it's real... */
952 /* Init stuff necessary for reading in symbols */
954 old_chain = make_cleanup (really_free_pendings, 0);
957 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
958 pst->textlow, pst->texthigh - pst->textlow,
959 pst->section_offsets, pst->filename);
960 sort_symtab_syms (pst->symtab);
962 do_cleanups (old_chain);
968 /* Read in all of the symbols for a given psymtab for real.
969 Be verbose about it if the user wants that. */
972 hpread_psymtab_to_symtab (struct partial_symtab *pst)
974 /* Get out quick if given junk. */
981 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
986 if (LDSYMLEN (pst) || pst->number_of_dependencies)
988 /* Print the message now, before reading the string table,
989 to avoid disconcerting pauses. */
992 printf_filtered ("Reading in symbols for %s...", pst->filename);
993 gdb_flush (gdb_stdout);
996 hpread_psymtab_to_symtab_1 (pst);
998 /* Match with global symbols. This only needs to be done once,
999 after all of the symtabs and dependencies have been read in. */
1000 scan_file_globals (pst->objfile);
1002 /* Finish up the debug error message. */
1004 printf_filtered ("done.\n");
1007 /* Read in a defined section of a specific object file's symbols.
1009 DESC is the file descriptor for the file, positioned at the
1010 beginning of the symtab
1011 SYM_OFFSET is the offset within the file of
1012 the beginning of the symbols we want to read
1013 SYM_SIZE is the size of the symbol info to read in.
1014 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1015 TEXT_SIZE is the size of the text segment read in.
1016 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1018 static struct symtab *
1019 hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size,
1020 CORE_ADDR text_offset, int text_size,
1021 struct section_offsets *section_offsets, char *filename)
1024 union dnttentry *dn_bufp;
1025 unsigned max_symnum;
1027 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1029 current_objfile = objfile;
1032 last_source_file = 0;
1034 dn_bufp = hpread_get_lntt (sym_index, objfile);
1035 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1036 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1038 start_symtab ("globals", NULL, 0);
1039 record_debugformat ("HP");
1042 max_symnum = sym_size / sizeof (struct dntt_type_block);
1044 /* Read in and process each debug symbol within the specified range. */
1046 symnum < max_symnum;
1049 QUIT; /* Allow this to be interruptable */
1050 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1052 if (dn_bufp->dblock.extension)
1055 /* Yow! We call SET_NAMESTRING on things without names! */
1056 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1058 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1059 objfile, text_offset, text_size,
1060 filename, symnum + sym_index);
1063 current_objfile = NULL;
1065 return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
1069 /* Convert basic types from HP debug format into GDB internal format. */
1072 hpread_type_translate (dnttpointer typep)
1074 if (!typep.dntti.immediate)
1075 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1077 switch (typep.dntti.type)
1079 case HP_TYPE_BOOLEAN:
1080 case HP_TYPE_BOOLEAN_S300_COMPAT:
1081 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1083 /* Ugh. No way to distinguish between signed and unsigned chars. */
1085 case HP_TYPE_WIDE_CHAR:
1088 if (typep.dntti.bitlength <= 8)
1090 if (typep.dntti.bitlength <= 16)
1092 if (typep.dntti.bitlength <= 32)
1094 return FT_LONG_LONG;
1097 case HP_TYPE_UNSIGNED_LONG:
1098 if (typep.dntti.bitlength <= 8)
1099 return FT_UNSIGNED_CHAR;
1100 if (typep.dntti.bitlength <= 16)
1101 return FT_UNSIGNED_SHORT;
1102 if (typep.dntti.bitlength <= 32)
1103 return FT_UNSIGNED_LONG;
1104 return FT_UNSIGNED_LONG_LONG;
1105 case HP_TYPE_UNSIGNED_INT:
1106 if (typep.dntti.bitlength <= 8)
1107 return FT_UNSIGNED_CHAR;
1108 if (typep.dntti.bitlength <= 16)
1109 return FT_UNSIGNED_SHORT;
1110 if (typep.dntti.bitlength <= 32)
1111 return FT_UNSIGNED_INTEGER;
1112 return FT_UNSIGNED_LONG_LONG;
1114 case HP_TYPE_REAL_3000:
1115 case HP_TYPE_DOUBLE:
1116 if (typep.dntti.bitlength == 64)
1117 return FT_DBL_PREC_FLOAT;
1118 if (typep.dntti.bitlength == 128)
1119 return FT_EXT_PREC_FLOAT;
1121 case HP_TYPE_COMPLEX:
1122 case HP_TYPE_COMPLEXS3000:
1123 if (typep.dntti.bitlength == 128)
1124 return FT_DBL_PREC_COMPLEX;
1125 if (typep.dntti.bitlength == 192)
1126 return FT_EXT_PREC_COMPLEX;
1128 case HP_TYPE_STRING200:
1129 case HP_TYPE_LONGSTRING200:
1130 case HP_TYPE_FTN_STRING_SPEC:
1131 case HP_TYPE_MOD_STRING_SPEC:
1132 case HP_TYPE_MOD_STRING_3000:
1133 case HP_TYPE_FTN_STRING_S300_COMPAT:
1134 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1137 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1141 /* Return the type associated with the index found in HP_TYPE. */
1143 static struct type **
1144 hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile)
1147 int index = hp_type.dnttp.index;
1149 if (hp_type.dntti.immediate)
1152 if (index < LNTT_SYMCOUNT (objfile))
1154 if (index >= TYPE_VECTOR_LENGTH (objfile))
1156 old_len = TYPE_VECTOR_LENGTH (objfile);
1159 TYPE_VECTOR_LENGTH (objfile) = 100;
1160 TYPE_VECTOR (objfile) = (struct type **)
1161 xmmalloc (objfile->md,
1162 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1164 while (index >= TYPE_VECTOR_LENGTH (objfile))
1165 TYPE_VECTOR_LENGTH (objfile) *= 2;
1166 TYPE_VECTOR (objfile) = (struct type **)
1167 xmrealloc (objfile->md,
1168 (char *) TYPE_VECTOR (objfile),
1169 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1170 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1171 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1172 sizeof (struct type *));
1174 return &TYPE_VECTOR (objfile)[index];
1180 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1181 Note we'll just return the address of a GDB internal type if we already
1182 have it lying around. */
1184 static struct type *
1185 hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile)
1187 struct type **type_addr;
1189 type_addr = hpread_lookup_type (hp_type, objfile);
1190 if (*type_addr == 0)
1191 *type_addr = alloc_type (objfile);
1193 TYPE_CPLUS_SPECIFIC (*type_addr)
1194 = (struct cplus_struct_type *) &cplus_struct_default;
1198 /* Read a native enumerated type and return it in GDB internal form. */
1200 static struct type *
1201 hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1202 struct objfile *objfile)
1205 struct pending **symlist, *osyms, *syms;
1206 int o_nsyms, nsyms = 0;
1208 union dnttentry *memp;
1213 type = hpread_alloc_type (hp_type, objfile);
1214 TYPE_LENGTH (type) = 4;
1216 symlist = &file_symbols;
1218 o_nsyms = osyms ? osyms->nsyms : 0;
1220 /* Get a name for each member and add it to our list of members. */
1221 mem = dn_bufp->denum.firstmem;
1222 while (mem.dnttp.extension && mem.word != DNTTNIL)
1224 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1226 name = VT (objfile) + memp->dmember.name;
1227 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1228 sizeof (struct symbol));
1229 memset (sym, 0, sizeof (struct symbol));
1230 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1231 &objfile->symbol_obstack);
1232 SYMBOL_CLASS (sym) = LOC_CONST;
1233 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1234 SYMBOL_VALUE (sym) = memp->dmember.value;
1235 add_symbol_to_list (sym, symlist);
1237 mem = memp->dmember.nextmem;
1240 /* Now that we know more about the enum, fill in more info. */
1241 TYPE_CODE (type) = TYPE_CODE_ENUM;
1242 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1243 TYPE_NFIELDS (type) = nsyms;
1244 TYPE_FIELDS (type) = (struct field *)
1245 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1247 /* Find the symbols for the members and put them into the type.
1248 The symbols can be found in the symlist that we put them on
1249 to cause them to be defined. osyms contains the old value
1250 of that symlist; everything up to there was defined by us.
1252 Note that we preserve the order of the enum constants, so
1253 that in something like "enum {FOO, LAST_THING=FOO}" we print
1254 FOO, not LAST_THING. */
1255 for (syms = *symlist, n = 0; syms; syms = syms->next)
1260 for (; j < syms->nsyms; j++, n++)
1262 struct symbol *xsym = syms->symbol[j];
1263 SYMBOL_TYPE (xsym) = type;
1264 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1265 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1266 TYPE_FIELD_BITSIZE (type, n) = 0;
1275 /* Read and internalize a native function debug symbol. */
1277 static struct type *
1278 hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1279 struct objfile *objfile)
1281 struct type *type, *type1;
1282 struct pending **symlist, *osyms, *syms;
1283 int o_nsyms, nsyms = 0;
1285 union dnttentry *paramp;
1290 param = dn_bufp->dfunc.firstparam;
1292 /* See if we've already read in this type. */
1293 type = hpread_alloc_type (hp_type, objfile);
1294 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1297 /* Nope, so read it in and store it away. */
1298 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1300 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1302 symlist = &local_symbols;
1304 o_nsyms = osyms ? osyms->nsyms : 0;
1306 /* Now examine each parameter noting its type, location, and a
1307 wealth of other information. */
1308 while (param.word && param.word != DNTTNIL)
1310 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1312 param = paramp->dfparam.nextparam;
1315 name = VT (objfile) + paramp->dfparam.name;
1316 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1317 sizeof (struct symbol));
1318 (void) memset (sym, 0, sizeof (struct symbol));
1319 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1320 &objfile->symbol_obstack);
1322 /* Figure out where it lives. */
1323 if (paramp->dfparam.regparam)
1324 SYMBOL_CLASS (sym) = LOC_REGPARM;
1325 else if (paramp->dfparam.indirect)
1326 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1328 SYMBOL_CLASS (sym) = LOC_ARG;
1329 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1330 if (paramp->dfparam.copyparam)
1332 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1333 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1335 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1337 /* This is likely a pass-by-invisible reference parameter,
1338 Hack on the symbol class to make GDB happy. */
1339 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1342 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1345 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1347 /* Add it to the list. */
1348 add_symbol_to_list (sym, symlist);
1351 /* Note how many parameters we found. */
1352 TYPE_NFIELDS (type) = nsyms;
1353 TYPE_FIELDS (type) = (struct field *)
1354 obstack_alloc (&objfile->type_obstack,
1355 sizeof (struct field) * nsyms);
1357 /* Find the symbols for the values and put them into the type.
1358 The symbols can be found in the symlist that we put them on
1359 to cause them to be defined. osyms contains the old value
1360 of that symlist; everything up to there was defined by us. */
1361 /* Note that we preserve the order of the parameters, so
1362 that in something like "enum {FOO, LAST_THING=FOO}" we print
1363 FOO, not LAST_THING. */
1364 for (syms = *symlist, n = 0; syms; syms = syms->next)
1369 for (; j < syms->nsyms; j++, n++)
1371 struct symbol *xsym = syms->symbol[j];
1372 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1373 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1374 TYPE_FIELD_BITPOS (type, n) = n;
1375 TYPE_FIELD_BITSIZE (type, n) = 0;
1383 /* Read in and internalize a structure definition. */
1385 static struct type *
1386 hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1387 struct objfile *objfile)
1391 struct nextfield *next;
1396 struct nextfield *list = 0;
1397 struct nextfield *new;
1400 union dnttentry *fieldp;
1402 /* Is it something we've already dealt with? */
1403 type = hpread_alloc_type (hp_type, objfile);
1404 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1405 (TYPE_CODE (type) == TYPE_CODE_UNION))
1408 /* Get the basic type correct. */
1409 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1411 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1412 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1414 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1416 TYPE_CODE (type) = TYPE_CODE_UNION;
1417 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1423 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1425 /* Read in and internalize all the fields. */
1426 field = dn_bufp->dstruct.firstfield;
1427 while (field.word != DNTTNIL && field.dnttp.extension)
1429 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1431 /* Get space to record the next field's data. */
1432 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1436 list->field.name = VT (objfile) + fieldp->dfield.name;
1437 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1438 if (fieldp->dfield.bitlength % 8)
1439 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1441 FIELD_BITSIZE (list->field) = 0;
1443 field = fieldp->dfield.nextfield;
1444 FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1448 TYPE_NFIELDS (type) = nfields;
1449 TYPE_FIELDS (type) = (struct field *)
1450 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1452 /* Copy the saved-up fields into the field vector. */
1453 for (n = nfields; list; list = list->next)
1456 TYPE_FIELD (type, n) = list->field;
1461 /* Read in and internalize a set debug symbol. */
1463 static struct type *
1464 hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1465 struct objfile *objfile)
1469 /* See if it's something we've already deal with. */
1470 type = hpread_alloc_type (hp_type, objfile);
1471 if (TYPE_CODE (type) == TYPE_CODE_SET)
1474 /* Nope. Fill in the appropriate fields. */
1475 TYPE_CODE (type) = TYPE_CODE_SET;
1476 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1477 TYPE_NFIELDS (type) = 0;
1478 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1483 /* Read in and internalize an array debug symbol. */
1485 static struct type *
1486 hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1487 struct objfile *objfile)
1490 union dnttentry save;
1493 /* Why no check here? Because it kept us from properly determining
1494 the size of the array! */
1495 type = hpread_alloc_type (hp_type, objfile);
1497 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1499 /* values are not normalized. */
1500 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1501 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1502 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1503 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1505 /* The HP debug format represents char foo[]; as an array with
1506 length 0x7fffffff. Internally GDB wants to represent this
1507 as an array of length zero. */
1508 TYPE_LENGTH (type) = 0;
1511 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1513 TYPE_NFIELDS (type) = 1;
1514 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1517 TYPE_FIELDS (type) = (struct field *)
1518 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1519 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1524 /* Read in and internalize a subrange debug symbol. */
1525 static struct type *
1526 hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1527 struct objfile *objfile)
1531 /* Is it something we've already dealt with. */
1532 type = hpread_alloc_type (hp_type, objfile);
1533 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1536 /* Nope, internalize it. */
1537 TYPE_CODE (type) = TYPE_CODE_RANGE;
1538 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1539 TYPE_NFIELDS (type) = 2;
1541 = (struct field *) obstack_alloc (&objfile->type_obstack,
1542 2 * sizeof (struct field));
1544 if (dn_bufp->dsubr.dyn_low)
1545 TYPE_FIELD_BITPOS (type, 0) = 0;
1547 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1549 if (dn_bufp->dsubr.dyn_high)
1550 TYPE_FIELD_BITPOS (type, 1) = -1;
1552 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1553 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1558 static struct type *
1559 hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile)
1561 union dnttentry *dn_bufp;
1563 /* First see if it's a simple builtin type. */
1564 if (hp_type.dntti.immediate)
1565 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1567 /* Not a builtin type. We'll have to read it in. */
1568 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1569 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1571 return lookup_fundamental_type (objfile, FT_VOID);
1573 switch (dn_bufp->dblock.kind)
1575 case DNTT_TYPE_SRCFILE:
1576 case DNTT_TYPE_MODULE:
1577 case DNTT_TYPE_FUNCTION:
1578 case DNTT_TYPE_ENTRY:
1579 case DNTT_TYPE_BEGIN:
1581 case DNTT_TYPE_IMPORT:
1582 case DNTT_TYPE_LABEL:
1583 case DNTT_TYPE_WITH:
1584 case DNTT_TYPE_COMMON:
1585 case DNTT_TYPE_FPARAM:
1586 case DNTT_TYPE_SVAR:
1587 case DNTT_TYPE_DVAR:
1588 case DNTT_TYPE_CONST:
1589 /* Opps. Something went very wrong. */
1590 return lookup_fundamental_type (objfile, FT_VOID);
1592 case DNTT_TYPE_TYPEDEF:
1594 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1597 suffix = VT (objfile) + dn_bufp->dtype.name;
1599 TYPE_CPLUS_SPECIFIC (structtype)
1600 = (struct cplus_struct_type *) &cplus_struct_default;
1601 TYPE_NAME (structtype) = suffix;
1605 case DNTT_TYPE_TAGDEF:
1607 /* Just a little different from above. We have to tack on
1608 an identifier of some kind (struct, union, enum, etc). */
1609 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1611 char *prefix, *suffix;
1612 suffix = VT (objfile) + dn_bufp->dtype.name;
1614 /* Lookup the next type in the list. It should be a structure,
1615 union, or enum type. We will need to attach that to our name. */
1616 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1617 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1619 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1621 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1623 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1628 /* Build the correct name. */
1630 = (char *) obstack_alloc (&objfile->type_obstack,
1631 strlen (prefix) + strlen (suffix) + 1);
1632 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1633 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1634 TYPE_TAG_NAME (structtype) = suffix;
1636 TYPE_CPLUS_SPECIFIC (structtype)
1637 = (struct cplus_struct_type *) &cplus_struct_default;
1641 case DNTT_TYPE_POINTER:
1642 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1644 case DNTT_TYPE_ENUM:
1645 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1646 case DNTT_TYPE_MEMENUM:
1647 return lookup_fundamental_type (objfile, FT_VOID);
1649 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1650 case DNTT_TYPE_SUBRANGE:
1651 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1652 case DNTT_TYPE_ARRAY:
1653 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1654 case DNTT_TYPE_STRUCT:
1655 case DNTT_TYPE_UNION:
1656 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1657 case DNTT_TYPE_FIELD:
1658 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1659 case DNTT_TYPE_VARIANT:
1660 case DNTT_TYPE_FILE:
1661 return lookup_fundamental_type (objfile, FT_VOID);
1662 case DNTT_TYPE_FUNCTYPE:
1663 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1665 case DNTT_TYPE_COBSTRUCT:
1666 case DNTT_TYPE_XREF:
1668 case DNTT_TYPE_MACRO:
1670 return lookup_fundamental_type (objfile, FT_VOID);
1675 hpread_record_lines (struct subfile *subfile, sltpointer s_idx,
1676 sltpointer e_idx, struct objfile *objfile,
1679 union sltentry *sl_bufp;
1681 while (s_idx <= e_idx)
1683 sl_bufp = hpread_get_slt (s_idx, objfile);
1684 /* Only record "normal" entries in the SLT. */
1685 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1686 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1687 record_line (subfile, sl_bufp->snorm.line,
1688 sl_bufp->snorm.address + offset);
1694 /* Internalize one native debug symbol. */
1697 hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name,
1698 struct section_offsets *section_offsets,
1699 struct objfile *objfile, CORE_ADDR text_offset,
1700 int text_size, char *filename, int index)
1705 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1706 union dnttentry *dn_temp;
1707 dnttpointer hp_type;
1709 struct context_stack *new;
1711 /* Allocate one GDB debug symbol and fill in some default values. */
1712 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1713 sizeof (struct symbol));
1714 memset (sym, 0, sizeof (struct symbol));
1715 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1716 SYMBOL_LANGUAGE (sym) = language_auto;
1717 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1718 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1719 SYMBOL_LINE (sym) = 0;
1720 SYMBOL_VALUE (sym) = 0;
1721 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1723 hp_type.dnttp.extension = 1;
1724 hp_type.dnttp.immediate = 0;
1725 hp_type.dnttp.global = 0;
1726 hp_type.dnttp.index = index;
1728 type = dn_bufp->dblock.kind;
1732 case DNTT_TYPE_SRCFILE:
1733 /* This type of symbol indicates from which source file or include file
1734 the following data comes. If there are no modules it also may
1735 indicate the start of a new source file, in which case we must
1736 finish the symbol table of the previous source file
1737 (if any) and start accumulating a new symbol table. */
1740 if (!last_source_file)
1742 start_symtab (name, NULL, valu);
1743 record_debugformat ("HP");
1744 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1748 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1750 dn_bufp->dsfile.address,
1753 start_subfile (name, NULL);
1756 case DNTT_TYPE_MODULE:
1757 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1760 case DNTT_TYPE_FUNCTION:
1761 case DNTT_TYPE_ENTRY:
1762 /* A function or secondary entry point. */
1763 valu = dn_bufp->dfunc.lowaddr + offset;
1764 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1766 dn_bufp->dfunc.address,
1769 WITHIN_FUNCTION (objfile) = 1;
1770 CURRENT_FUNCTION_VALUE (objfile) = valu;
1772 /* Stack must be empty now. */
1773 if (context_stack_depth != 0)
1774 complain (&lbrac_unmatched_complaint, (char *) symnum);
1775 new = push_context (0, valu);
1777 SYMBOL_CLASS (sym) = LOC_BLOCK;
1778 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1779 if (dn_bufp->dfunc.global)
1780 add_symbol_to_list (sym, &global_symbols);
1782 add_symbol_to_list (sym, &file_symbols);
1785 /* Search forward to the next scope beginning. */
1786 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1788 dn_bufp = hpread_get_lntt (++index, objfile);
1789 if (dn_bufp->dblock.extension)
1792 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1794 dn_bufp->dbegin.address,
1796 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1797 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1800 case DNTT_TYPE_BEGIN:
1801 /* Begin a new scope. */
1802 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1804 dn_bufp->dbegin.address,
1806 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1807 valu += offset; /* Relocate for dynamic loading */
1808 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1809 new = push_context (desc, valu);
1814 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1816 dn_bufp->dend.address + 1,
1818 switch (dn_bufp->dend.endkind)
1820 case DNTT_TYPE_MODULE:
1821 /* Ending a module ends the symbol table for that module. */
1822 valu = text_offset + text_size + offset;
1823 (void) end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
1826 case DNTT_TYPE_FUNCTION:
1827 /* Ending a function, well, ends the function's scope. */
1828 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1830 valu = dn_temp->dfunc.hiaddr + offset;
1831 new = pop_context ();
1832 /* Make a block for the local symbols within. */
1833 finish_block (new->name, &local_symbols, new->old_blocks,
1834 new->start_addr, valu, objfile);
1835 WITHIN_FUNCTION (objfile) = 0;
1837 case DNTT_TYPE_BEGIN:
1838 /* Just ending a local scope. */
1839 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1840 /* Why in the hell is this needed? */
1841 valu += offset + 9; /* Relocate for dynamic loading */
1842 new = pop_context ();
1843 desc = dn_bufp->dend.beginscope.dnttp.index;
1844 if (desc != new->depth)
1845 complain (&lbrac_mismatch_complaint, (char *) symnum);
1846 /* Make a block for the local symbols within. */
1847 finish_block (new->name, &local_symbols, new->old_blocks,
1848 new->start_addr, valu, objfile);
1849 local_symbols = new->locals;
1853 case DNTT_TYPE_LABEL:
1854 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1856 case DNTT_TYPE_FPARAM:
1857 /* Function parameters. */
1858 if (dn_bufp->dfparam.regparam)
1859 SYMBOL_CLASS (sym) = LOC_REGISTER;
1861 SYMBOL_CLASS (sym) = LOC_LOCAL;
1862 if (dn_bufp->dfparam.copyparam)
1864 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1865 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1867 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1871 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1872 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1873 add_symbol_to_list (sym, &local_symbols);
1875 case DNTT_TYPE_SVAR:
1876 /* Static variables. */
1877 SYMBOL_CLASS (sym) = LOC_STATIC;
1878 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1879 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1880 if (dn_bufp->dsvar.global)
1881 add_symbol_to_list (sym, &global_symbols);
1882 else if (WITHIN_FUNCTION (objfile))
1883 add_symbol_to_list (sym, &local_symbols);
1885 add_symbol_to_list (sym, &file_symbols);
1887 case DNTT_TYPE_DVAR:
1888 /* Dynamic variables. */
1889 if (dn_bufp->ddvar.regvar)
1890 SYMBOL_CLASS (sym) = LOC_REGISTER;
1892 SYMBOL_CLASS (sym) = LOC_LOCAL;
1893 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1894 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1896 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1898 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1899 if (dn_bufp->ddvar.global)
1900 add_symbol_to_list (sym, &global_symbols);
1901 else if (WITHIN_FUNCTION (objfile))
1902 add_symbol_to_list (sym, &local_symbols);
1904 add_symbol_to_list (sym, &file_symbols);
1906 case DNTT_TYPE_CONST:
1907 /* A constant (pascal?). */
1908 SYMBOL_CLASS (sym) = LOC_CONST;
1909 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1910 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1911 if (dn_bufp->dconst.global)
1912 add_symbol_to_list (sym, &global_symbols);
1913 else if (WITHIN_FUNCTION (objfile))
1914 add_symbol_to_list (sym, &local_symbols);
1916 add_symbol_to_list (sym, &file_symbols);
1918 case DNTT_TYPE_TYPEDEF:
1919 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1920 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1921 if (dn_bufp->dtype.global)
1922 add_symbol_to_list (sym, &global_symbols);
1923 else if (WITHIN_FUNCTION (objfile))
1924 add_symbol_to_list (sym, &local_symbols);
1926 add_symbol_to_list (sym, &file_symbols);
1928 case DNTT_TYPE_TAGDEF:
1929 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1930 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1931 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1932 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
1933 if (dn_bufp->dtype.global)
1934 add_symbol_to_list (sym, &global_symbols);
1935 else if (WITHIN_FUNCTION (objfile))
1936 add_symbol_to_list (sym, &local_symbols);
1938 add_symbol_to_list (sym, &file_symbols);
1940 case DNTT_TYPE_POINTER:
1941 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
1942 (dn_bufp->dptr.pointsto,
1944 add_symbol_to_list (sym, &file_symbols);
1946 case DNTT_TYPE_ENUM:
1947 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1948 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
1949 add_symbol_to_list (sym, &file_symbols);
1951 case DNTT_TYPE_MEMENUM:
1954 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
1955 add_symbol_to_list (sym, &file_symbols);
1957 case DNTT_TYPE_SUBRANGE:
1958 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
1960 add_symbol_to_list (sym, &file_symbols);
1962 case DNTT_TYPE_ARRAY:
1963 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
1964 add_symbol_to_list (sym, &file_symbols);
1966 case DNTT_TYPE_STRUCT:
1967 case DNTT_TYPE_UNION:
1968 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1969 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
1970 add_symbol_to_list (sym, &file_symbols);