1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993, 1996 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
25 #include "gdb_string.h"
26 #include "hp-symtab.h"
32 #include "complaints.h"
33 #include "gdb-stabs.h"
36 /* Private information attached to an objfile which we use to find
37 and internalize the HP C debug symbols within that objfile. */
39 struct hpread_symfile_info
41 /* The contents of each of the debug sections (there are 4 of them). */
47 /* We keep the size of the $VT$ section for range checking. */
50 /* Some routines still need to know the number of symbols in the
51 main debug sections ($LNTT$ and $GNTT$). */
52 unsigned int lntt_symcount;
53 unsigned int gntt_symcount;
55 /* To keep track of all the types we've processed. */
56 struct type **type_vector;
57 int type_vector_length;
59 /* Keeps track of the beginning of a range of source lines. */
62 /* Some state variables we'll need. */
65 /* Keep track of the current function's address. We may need to look
66 up something based on this address. */
67 unsigned int current_function_value;
70 /* Accessor macros to get at the fields. */
71 #define HPUX_SYMFILE_INFO(o) \
72 ((struct hpread_symfile_info *)((o)->sym_private))
73 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
74 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
75 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
76 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
77 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
78 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
79 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
80 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
81 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
82 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
83 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
84 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
86 /* Given the native debug symbol SYM, set NAMEP to the name associated
87 with the debug symbol. Note we may be called with a debug symbol which
88 has no associated name, in that case we return an empty string.
90 Also note we "know" that the name for any symbol is always in the
91 same place. Hence we don't have to conditionalize on the symbol type. */
92 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
93 if (! hpread_has_name ((SYM)->dblock.kind)) \
95 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
97 complain (&string_table_offset_complaint, (char *) symnum); \
101 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
103 /* We put a pointer to this structure in the read_symtab_private field
108 /* The offset within the file symbol table of first local symbol for
113 /* Length (in bytes) of the section of the symbol table devoted to
114 this file's symbols (actually, the section bracketed may contain
115 more than just this file's symbols). If ldsymlen is 0, the only
116 reason for this thing's existence is the dependency list.
117 Nothing else will happen when it is read in. */
122 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
123 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
124 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
126 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
127 /* Nonzero means give verbose info on gdb action. */
128 extern int info_verbose;
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 PARAMS ((struct objfile *));
138 static struct type *hpread_alloc_type
139 PARAMS ((dnttpointer, struct objfile *));
141 static struct type **hpread_lookup_type
142 PARAMS ((dnttpointer, struct objfile *));
144 static struct type *hpread_read_enum_type
145 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
147 static struct type *hpread_read_set_type
148 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
150 static struct type *hpread_read_subrange_type
151 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
153 static struct type *hpread_read_struct_type
154 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
156 void hpread_build_psymtabs
157 PARAMS ((struct objfile *, struct section_offsets *, int));
159 void hpread_symfile_finish PARAMS ((struct objfile *));
161 static struct partial_symtab *hpread_start_psymtab
162 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
163 struct partial_symbol *, struct partial_symbol *));
165 static struct partial_symtab *hpread_end_psymtab
166 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
167 struct partial_symtab **, int));
169 static struct symtab *hpread_expand_symtab
170 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
171 struct section_offsets *, char *));
173 static void hpread_process_one_debug_symbol
174 PARAMS ((union dnttentry *, char *, struct section_offsets *,
175 struct objfile *, CORE_ADDR, int, char *, int));
177 static sltpointer hpread_record_lines
178 PARAMS ((struct subfile *, sltpointer, sltpointer,
179 struct objfile *, CORE_ADDR));
181 static struct type *hpread_read_function_type
182 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
184 static struct type * hpread_type_lookup
185 PARAMS ((dnttpointer, struct objfile *));
187 static unsigned long hpread_get_depth
188 PARAMS ((sltpointer, struct objfile *));
190 static unsigned long hpread_get_line
191 PARAMS ((sltpointer, struct objfile *));
193 static CORE_ADDR hpread_get_location
194 PARAMS ((sltpointer, struct objfile *));
196 static int hpread_type_translate PARAMS ((dnttpointer));
197 static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
198 static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
199 static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
200 static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
201 static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
202 static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
203 static int hpread_has_name PARAMS ((enum dntt_entry_type));
206 /* Initialization for reading native HP C debug symbols from OBJFILE.
208 It's only purpose in life is to set up the symbol reader's private
209 per-objfile data structures, and read in the raw contents of the debug
210 sections (attaching pointers to the debug info into the private data
213 Since BFD doesn't know how to read debug symbols in a format-independent
214 way (and may never do so...), we have to do it ourselves. Note we may
215 be called on a file without native HP C debugging symbols.
216 FIXME, there should be a cleaner peephole into the BFD environment here. */
219 hpread_symfile_init (objfile)
220 struct objfile *objfile;
222 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
224 /* Allocate struct to keep track of the symfile */
225 objfile->sym_private = (PTR)
226 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
227 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
229 /* We haven't read in any types yet. */
230 TYPE_VECTOR (objfile) = 0;
232 /* Read in data from the $GNTT$ subspace. */
233 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
238 = obstack_alloc (&objfile->symbol_obstack,
239 bfd_section_size (objfile->obfd, gntt_section));
241 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
242 0, bfd_section_size (objfile->obfd, gntt_section));
244 GNTT_SYMCOUNT (objfile)
245 = bfd_section_size (objfile->obfd, gntt_section)
246 / sizeof (struct dntt_type_block);
248 /* Read in data from the $LNTT$ subspace. Also keep track of the number
250 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
255 = obstack_alloc (&objfile->symbol_obstack,
256 bfd_section_size (objfile->obfd, lntt_section));
258 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
259 0, bfd_section_size (objfile->obfd, lntt_section));
261 LNTT_SYMCOUNT (objfile)
262 = bfd_section_size (objfile->obfd, lntt_section)
263 / sizeof (struct dntt_type_block);
265 /* Read in data from the $SLT$ subspace. $SLT$ contains information
266 on source line numbers. */
267 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
272 obstack_alloc (&objfile->symbol_obstack,
273 bfd_section_size (objfile->obfd, slt_section));
275 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
276 0, bfd_section_size (objfile->obfd, slt_section));
278 /* Read in data from the $VT$ subspace. $VT$ contains things like
279 names and constants. Keep track of the number of symbols in the VT. */
280 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
284 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
287 (char *) obstack_alloc (&objfile->symbol_obstack,
290 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
291 0, VT_SIZE (objfile));
294 /* Scan and build partial symbols for a symbol file.
296 The minimal symbol table (either SOM or HP a.out) has already been
297 read in; all we need to do is setup partial symbols based on the
298 native debugging information.
300 We assume hpread_symfile_init has been called to initialize the
301 symbol reader's private data structures.
303 SECTION_OFFSETS contains offsets relative to which the symbols in the
304 various sections are (depending where the sections were actually loaded).
305 MAINLINE is true if we are reading the main symbol
306 table (as opposed to a shared lib or dynamically loaded file). */
309 hpread_build_psymtabs (objfile, section_offsets, mainline)
310 struct objfile *objfile;
311 struct section_offsets *section_offsets;
315 int past_first_source_file = 0;
316 struct cleanup *old_chain;
318 int hp_symnum, symcount, i;
320 union dnttentry *dn_bufp;
326 /* Current partial symtab */
327 struct partial_symtab *pst;
329 /* List of current psymtab's include files */
330 char **psymtab_include_list;
331 int includes_allocated;
334 /* Index within current psymtab dependency list */
335 struct partial_symtab **dependency_list;
336 int dependencies_used, dependencies_allocated;
338 /* Just in case the stabs reader left turds lying around. */
340 make_cleanup (really_free_pendings, 0);
342 pst = (struct partial_symtab *) 0;
344 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
345 a number of problems with cross compilation and creating useless holes
346 in the stack when we have to allocate new entries. FIXME. */
348 includes_allocated = 30;
350 psymtab_include_list = (char **) alloca (includes_allocated *
353 dependencies_allocated = 30;
354 dependencies_used = 0;
356 (struct partial_symtab **) alloca (dependencies_allocated *
357 sizeof (struct partial_symtab *));
359 old_chain = make_cleanup (free_objfile, objfile);
361 last_source_file = 0;
363 /* Make two passes, one ofr the GNTT symbols, the other for the
365 for (i = 0; i < 1; i++)
367 int within_function = 0;
370 symcount = GNTT_SYMCOUNT (objfile);
372 symcount = LNTT_SYMCOUNT (objfile);
374 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
378 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
380 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
382 if (dn_bufp->dblock.extension)
385 /* Only handle things which are necessary for minimal symbols.
386 everything else is ignored. */
387 switch (dn_bufp->dblock.kind)
389 case DNTT_TYPE_SRCFILE:
391 /* A source file of some kind. Note this may simply
392 be an included file. */
393 SET_NAMESTRING (dn_bufp, &namestring, objfile);
395 /* Check if this is the source file we are already working
397 if (pst && !strcmp (namestring, pst->filename))
400 /* Check if this is an include file, if so check if we have
401 already seen it. Add it to the include list */
402 p = strrchr (namestring, '.');
403 if (!strcmp (p, ".h"))
408 for (j = 0; j < includes_used; j++)
409 if (!strcmp (namestring, psymtab_include_list[j]))
417 /* Add it to the list of includes seen so far and
418 allocate more include space if necessary. */
419 psymtab_include_list[includes_used++] = namestring;
420 if (includes_used >= includes_allocated)
422 char **orig = psymtab_include_list;
424 psymtab_include_list = (char **)
425 alloca ((includes_allocated *= 2) *
427 memcpy ((PTR) psymtab_include_list, (PTR) orig,
428 includes_used * sizeof (char *));
438 pst->filename = (char *)
439 obstack_alloc (&pst->objfile->psymbol_obstack,
440 strlen (namestring) + 1);
441 strcpy (pst->filename, namestring);
448 /* This is a bonafide new source file.
449 End the current partial symtab and start a new one. */
451 if (pst && past_first_source_file)
453 hpread_end_psymtab (pst, psymtab_include_list,
456 * sizeof (struct dntt_type_block)),
458 dependency_list, dependencies_used);
459 pst = (struct partial_symtab *) 0;
461 dependencies_used = 0;
464 past_first_source_file = 1;
466 valu = hpread_get_textlow (i, hp_symnum, objfile);
467 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
468 pst = hpread_start_psymtab (objfile, section_offsets,
471 * sizeof (struct dntt_type_block)),
472 objfile->global_psymbols.next,
473 objfile->static_psymbols.next);
479 case DNTT_TYPE_MODULE:
480 /* A source file. It's still unclear to me what the
481 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
482 is supposed to be. */
483 SET_NAMESTRING (dn_bufp, &namestring, objfile);
484 valu = hpread_get_textlow (i, hp_symnum, objfile);
485 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
488 pst = hpread_start_psymtab (objfile, section_offsets,
491 * sizeof (struct dntt_type_block)),
492 objfile->global_psymbols.next,
493 objfile->static_psymbols.next);
498 case DNTT_TYPE_FUNCTION:
499 case DNTT_TYPE_ENTRY:
500 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
501 a secondary entry point. */
502 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
506 valu = dn_bufp->dfunc.lowaddr +
507 ANOFFSET (section_offsets, SECT_OFF_TEXT);
508 SET_NAMESTRING (dn_bufp, &namestring, objfile);
509 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
510 VAR_NAMESPACE, LOC_BLOCK,
511 objfile->static_psymbols, valu,
512 language_unknown, objfile);
515 case DNTT_TYPE_BEGIN:
517 /* Scope block begin/end. We only care about function
518 and file blocks right now. */
519 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
521 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
523 * sizeof (struct dntt_type_block)),
525 dependency_list, dependencies_used);
526 pst = (struct partial_symtab *) 0;
528 dependencies_used = 0;
531 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
536 case DNTT_TYPE_TYPEDEF:
537 case DNTT_TYPE_TAGDEF:
539 /* Variables, typedefs an the like. */
540 enum address_class storage;
541 namespace_enum namespace;
543 /* Don't add locals to the partial symbol table. */
545 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
546 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
549 /* TAGDEFs go into the structure namespace. */
550 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
551 namespace = STRUCT_NAMESPACE;
553 namespace = VAR_NAMESPACE;
555 /* What kind of "storage" does this use? */
556 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
557 storage = LOC_STATIC;
558 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
559 && dn_bufp->ddvar.regvar)
560 storage = LOC_REGISTER;
561 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
566 SET_NAMESTRING (dn_bufp, &namestring, objfile);
569 pst = hpread_start_psymtab (objfile, section_offsets,
572 * sizeof (struct dntt_type_block)),
573 objfile->global_psymbols.next,
574 objfile->static_psymbols.next);
576 if (dn_bufp->dsvar.global)
578 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
580 objfile->global_psymbols,
581 dn_bufp->dsvar.location,
582 language_unknown, objfile);
586 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
588 objfile->static_psymbols,
589 dn_bufp->dsvar.location,
590 language_unknown, objfile);
594 case DNTT_TYPE_MEMENUM:
595 case DNTT_TYPE_CONST:
596 /* Constants and members of enumerated types. */
597 SET_NAMESTRING (dn_bufp, &namestring, objfile);
600 pst = hpread_start_psymtab (objfile, section_offsets,
603 * sizeof (struct dntt_type_block)),
604 objfile->global_psymbols.next,
605 objfile->static_psymbols.next);
607 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
608 VAR_NAMESPACE, LOC_CONST,
609 objfile->static_psymbols, 0,
610 language_unknown, objfile);
618 /* End any pending partial symbol table. */
621 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
622 hp_symnum * sizeof (struct dntt_type_block),
623 0, dependency_list, dependencies_used);
626 discard_cleanups (old_chain);
629 /* Perform any local cleanups required when we are done with a particular
630 objfile. I.E, we are in the process of discarding all symbol information
631 for an objfile, freeing up all memory held for it, and unlinking the
632 objfile struct from the global list of known objfiles. */
635 hpread_symfile_finish (objfile)
636 struct objfile *objfile;
638 if (objfile->sym_private != NULL)
640 mfree (objfile->md, objfile->sym_private);
645 /* The remaining functions are all for internal use only. */
647 /* Various small functions to get entries in the debug symbol sections. */
649 static union dnttentry *
650 hpread_get_lntt (index, objfile)
652 struct objfile *objfile;
654 return (union dnttentry *)
655 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
658 static union dnttentry *
659 hpread_get_gntt (index, objfile)
661 struct objfile *objfile;
663 return (union dnttentry *)
664 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
667 static union sltentry *
668 hpread_get_slt (index, objfile)
670 struct objfile *objfile;
672 return (union sltentry *)&(SLT (objfile)[index * sizeof (union sltentry)]);
675 /* Get the low address associated with some symbol (typically the start
676 of a particular source file or module). Since that information is not
677 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
678 the existance of DNTT_TYPE_FUNCTION symbols. */
681 hpread_get_textlow (global, index, objfile)
684 struct objfile *objfile;
686 union dnttentry *dn_bufp;
687 struct minimal_symbol *msymbol;
689 /* Look for a DNTT_TYPE_FUNCTION symbol. */
693 dn_bufp = hpread_get_gntt (index++, objfile);
695 dn_bufp = hpread_get_lntt (index++, objfile);
696 } while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
697 && dn_bufp->dblock.kind != DNTT_TYPE_END);
699 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
700 might happen when a sourcefile has no functions. */
701 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
704 /* The minimal symbols are typically more accurate for some reason. */
705 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
708 return SYMBOL_VALUE_ADDRESS (msymbol);
710 return dn_bufp->dfunc.lowaddr;
713 /* Get the nesting depth for the source line identified by INDEX. */
716 hpread_get_depth (index, objfile)
718 struct objfile *objfile;
720 union sltentry *sl_bufp;
722 sl_bufp = hpread_get_slt (index, objfile);
723 return sl_bufp->sspec.backptr.dnttp.index;
726 /* Get the source line number the the line identified by INDEX. */
729 hpread_get_line (index, objfile)
731 struct objfile *objfile;
733 union sltentry *sl_bufp;
735 sl_bufp = hpread_get_slt (index, objfile);
736 return sl_bufp->snorm.line;
740 hpread_get_location (index, objfile)
742 struct objfile *objfile;
744 union sltentry *sl_bufp;
747 /* code location of special sltentrys is determined from context */
748 sl_bufp = hpread_get_slt (index, objfile);
750 if (sl_bufp->snorm.sltdesc == SLT_END)
752 /* find previous normal sltentry and get address */
753 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
754 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
755 sl_bufp = hpread_get_slt (index - i, objfile);
756 return sl_bufp->snorm.address;
759 /* find next normal sltentry and get address */
760 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
761 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
762 sl_bufp = hpread_get_slt (index + i, objfile);
763 return sl_bufp->snorm.address;
767 /* Return 1 if an HP debug symbol of type KIND has a name associated with
768 it, else return 0. */
771 hpread_has_name (kind)
772 enum dntt_entry_type kind;
776 case DNTT_TYPE_SRCFILE:
777 case DNTT_TYPE_MODULE:
778 case DNTT_TYPE_FUNCTION:
779 case DNTT_TYPE_ENTRY:
780 case DNTT_TYPE_IMPORT:
781 case DNTT_TYPE_LABEL:
782 case DNTT_TYPE_FPARAM:
785 case DNTT_TYPE_CONST:
786 case DNTT_TYPE_TYPEDEF:
787 case DNTT_TYPE_TAGDEF:
788 case DNTT_TYPE_MEMENUM:
789 case DNTT_TYPE_FIELD:
793 case DNTT_TYPE_BEGIN:
796 case DNTT_TYPE_COMMON:
797 case DNTT_TYPE_POINTER:
800 case DNTT_TYPE_SUBRANGE:
801 case DNTT_TYPE_ARRAY:
802 case DNTT_TYPE_STRUCT:
803 case DNTT_TYPE_UNION:
804 case DNTT_TYPE_VARIANT:
806 case DNTT_TYPE_FUNCTYPE:
807 case DNTT_TYPE_COBSTRUCT:
809 case DNTT_TYPE_MACRO:
815 /* Allocate and partially fill a partial symtab. It will be
816 completely filled at the end of the symbol list.
818 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
819 is the address relative to which its symbols are (incremental) or 0
822 static struct partial_symtab *
823 hpread_start_psymtab (objfile, section_offsets,
824 filename, textlow, ldsymoff, global_syms, static_syms)
825 struct objfile *objfile;
826 struct section_offsets *section_offsets;
830 struct partial_symbol *global_syms;
831 struct partial_symbol *static_syms;
833 struct partial_symtab *result =
834 start_psymtab_common (objfile, section_offsets,
835 filename, textlow, global_syms, static_syms);
837 result->read_symtab_private = (char *)
838 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
839 LDSYMOFF (result) = ldsymoff;
840 result->read_symtab = hpread_psymtab_to_symtab;
846 /* Close off the current usage of PST.
847 Returns PST or NULL if the partial symtab was empty and thrown away.
849 FIXME: List variables and peculiarities of same. */
851 static struct partial_symtab *
852 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
853 capping_text, dependency_list, number_dependencies)
854 struct partial_symtab *pst;
857 int capping_symbol_offset;
858 CORE_ADDR capping_text;
859 struct partial_symtab **dependency_list;
860 int number_dependencies;
863 struct objfile *objfile = pst -> objfile;
865 if (capping_symbol_offset != -1)
866 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
867 pst->texthigh = capping_text;
870 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
872 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
874 pst->number_of_dependencies = number_dependencies;
875 if (number_dependencies)
877 pst->dependencies = (struct partial_symtab **)
878 obstack_alloc (&objfile->psymbol_obstack,
879 number_dependencies * sizeof (struct partial_symtab *));
880 memcpy (pst->dependencies, dependency_list,
881 number_dependencies * sizeof (struct partial_symtab *));
884 pst->dependencies = 0;
886 for (i = 0; i < num_includes; i++)
888 struct partial_symtab *subpst =
889 allocate_psymtab (include_list[i], objfile);
891 subpst->section_offsets = pst->section_offsets;
892 subpst->read_symtab_private =
893 (char *) obstack_alloc (&objfile->psymbol_obstack,
894 sizeof (struct symloc));
898 subpst->texthigh = 0;
900 /* We could save slight bits of space by only making one of these,
901 shared by the entire set of include files. FIXME-someday. */
902 subpst->dependencies = (struct partial_symtab **)
903 obstack_alloc (&objfile->psymbol_obstack,
904 sizeof (struct partial_symtab *));
905 subpst->dependencies[0] = pst;
906 subpst->number_of_dependencies = 1;
908 subpst->globals_offset =
909 subpst->n_global_syms =
910 subpst->statics_offset =
911 subpst->n_static_syms = 0;
915 subpst->read_symtab = pst->read_symtab;
918 sort_pst_symbols (pst);
920 /* If there is already a psymtab or symtab for a file of this name, remove it.
921 (If there is a symtab, more drastic things also happen.)
922 This happens in VxWorks. */
923 free_named_symtabs (pst->filename);
925 if (num_includes == 0
926 && number_dependencies == 0
927 && pst->n_global_syms == 0
928 && pst->n_static_syms == 0)
930 /* Throw away this psymtab, it's empty. We can't deallocate it, since
931 it is on the obstack, but we can forget to chain it on the list. */
932 /* Empty psymtabs happen as a result of header files which don't have
933 any symbols in them. There can be a lot of them. But this check
934 is wrong, in that a psymtab with N_SLINE entries but nothing else
935 is not empty, but we don't realize that. Fixing that without slowing
936 things down might be tricky. */
937 struct partial_symtab *prev_pst;
939 /* First, snip it out of the psymtab chain */
941 if (pst->objfile->psymtabs == pst)
942 pst->objfile->psymtabs = pst->next;
944 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
945 if (prev_pst->next == pst)
946 prev_pst->next = pst->next;
948 /* Next, put it on a free list for recycling */
950 pst->next = pst->objfile->free_psymtabs;
951 pst->objfile->free_psymtabs = pst;
953 /* Indicate that psymtab was thrown away. */
954 pst = (struct partial_symtab *)NULL;
959 /* Do the dirty work of reading in the full symbol from a partial symbol
963 hpread_psymtab_to_symtab_1 (pst)
964 struct partial_symtab *pst;
966 struct cleanup *old_chain;
969 /* Get out quick if passed junk. */
973 /* Complain if we've already read in this symbol table. */
976 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
981 /* Read in all partial symtabs on which this one is dependent */
982 for (i = 0; i < pst->number_of_dependencies; i++)
983 if (!pst->dependencies[i]->readin)
985 /* Inform about additional files that need to be read in. */
988 fputs_filtered (" ", stdout);
990 fputs_filtered ("and ", stdout);
992 printf_filtered ("%s...", pst->dependencies[i]->filename);
993 wrap_here (""); /* Flush output */
996 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
999 /* If it's real... */
1002 /* Init stuff necessary for reading in symbols */
1004 old_chain = make_cleanup (really_free_pendings, 0);
1007 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1008 pst->textlow, pst->texthigh - pst->textlow,
1009 pst->section_offsets, pst->filename);
1010 sort_symtab_syms (pst->symtab);
1012 do_cleanups (old_chain);
1018 /* Read in all of the symbols for a given psymtab for real.
1019 Be verbose about it if the user wants that. */
1022 hpread_psymtab_to_symtab (pst)
1023 struct partial_symtab *pst;
1025 /* Get out quick if given junk. */
1032 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1037 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1039 /* Print the message now, before reading the string table,
1040 to avoid disconcerting pauses. */
1043 printf_filtered ("Reading in symbols for %s...", pst->filename);
1047 hpread_psymtab_to_symtab_1 (pst);
1049 /* Match with global symbols. This only needs to be done once,
1050 after all of the symtabs and dependencies have been read in. */
1051 scan_file_globals (pst->objfile);
1053 /* Finish up the debug error message. */
1055 printf_filtered ("done.\n");
1058 /* Read in a defined section of a specific object file's symbols.
1060 DESC is the file descriptor for the file, positioned at the
1061 beginning of the symtab
1062 SYM_OFFSET is the offset within the file of
1063 the beginning of the symbols we want to read
1064 SYM_SIZE is the size of the symbol info to read in.
1065 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1066 TEXT_SIZE is the size of the text segment read in.
1067 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1069 static struct symtab *
1070 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1071 section_offsets, filename)
1072 struct objfile *objfile;
1075 CORE_ADDR text_offset;
1077 struct section_offsets *section_offsets;
1081 union dnttentry *dn_bufp;
1082 unsigned max_symnum;
1084 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1086 current_objfile = objfile;
1089 last_source_file = 0;
1091 dn_bufp = hpread_get_lntt (sym_index, objfile);
1092 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1093 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1094 start_symtab ("globals", NULL, 0);
1096 max_symnum = sym_size / sizeof (struct dntt_type_block);
1098 /* Read in and process each debug symbol within the specified range. */
1100 symnum < max_symnum;
1103 QUIT; /* Allow this to be interruptable */
1104 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1106 if (dn_bufp->dblock.extension)
1109 /* Yow! We call SET_NAMESTRING on things without names! */
1110 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1112 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1113 objfile, text_offset, text_size,
1114 filename, symnum + sym_index);
1117 current_objfile = NULL;
1119 return end_symtab (text_offset + text_size, objfile, 0);
1123 /* Convert basic types from HP debug format into GDB internal format. */
1126 hpread_type_translate (typep)
1129 if (!typep.dntti.immediate)
1132 switch (typep.dntti.type)
1134 case HP_TYPE_BOOLEAN:
1135 case HP_TYPE_BOOLEAN_S300_COMPAT:
1136 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1138 /* Ugh. No way to distinguish between signed and unsigned chars. */
1140 case HP_TYPE_WIDE_CHAR:
1143 if (typep.dntti.bitlength <= 8)
1145 if (typep.dntti.bitlength <= 16)
1147 if (typep.dntti.bitlength <= 32)
1149 return FT_LONG_LONG;
1152 case HP_TYPE_UNSIGNED_LONG:
1153 if (typep.dntti.bitlength <= 8)
1154 return FT_UNSIGNED_CHAR;
1155 if (typep.dntti.bitlength <= 16)
1156 return FT_UNSIGNED_SHORT;
1157 if (typep.dntti.bitlength <= 32)
1158 return FT_UNSIGNED_LONG;
1159 return FT_UNSIGNED_LONG_LONG;
1160 case HP_TYPE_UNSIGNED_INT:
1161 if (typep.dntti.bitlength <= 8)
1162 return FT_UNSIGNED_CHAR;
1163 if (typep.dntti.bitlength <= 16)
1164 return FT_UNSIGNED_SHORT;
1165 if (typep.dntti.bitlength <= 32)
1166 return FT_UNSIGNED_INTEGER;
1167 return FT_UNSIGNED_LONG_LONG;
1169 case HP_TYPE_REAL_3000:
1170 case HP_TYPE_DOUBLE:
1171 if (typep.dntti.bitlength == 64)
1172 return FT_DBL_PREC_FLOAT;
1173 if (typep.dntti.bitlength == 128)
1174 return FT_EXT_PREC_FLOAT;
1176 case HP_TYPE_COMPLEX:
1177 case HP_TYPE_COMPLEXS3000:
1178 if (typep.dntti.bitlength == 128)
1179 return FT_DBL_PREC_COMPLEX;
1180 if (typep.dntti.bitlength == 192)
1181 return FT_EXT_PREC_COMPLEX;
1183 case HP_TYPE_STRING200:
1184 case HP_TYPE_LONGSTRING200:
1185 case HP_TYPE_FTN_STRING_SPEC:
1186 case HP_TYPE_MOD_STRING_SPEC:
1187 case HP_TYPE_MOD_STRING_3000:
1188 case HP_TYPE_FTN_STRING_S300_COMPAT:
1189 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1196 /* Return the type associated with the index found in HP_TYPE. */
1198 static struct type **
1199 hpread_lookup_type (hp_type, objfile)
1200 dnttpointer hp_type;
1201 struct objfile *objfile;
1204 int index = hp_type.dnttp.index;
1206 if (hp_type.dntti.immediate)
1209 if (index < LNTT_SYMCOUNT (objfile))
1211 if (index >= TYPE_VECTOR_LENGTH (objfile))
1213 old_len = TYPE_VECTOR_LENGTH (objfile);
1216 TYPE_VECTOR_LENGTH (objfile) = 100;
1217 TYPE_VECTOR (objfile) = (struct type **)
1218 malloc (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1220 while (index >= TYPE_VECTOR_LENGTH (objfile))
1221 TYPE_VECTOR_LENGTH (objfile) *= 2;
1222 TYPE_VECTOR (objfile) = (struct type **)
1223 xrealloc ((char *) TYPE_VECTOR (objfile),
1224 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1225 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1226 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1227 sizeof (struct type *));
1229 return &TYPE_VECTOR (objfile)[index];
1235 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1236 Note we'll just return the address of a GDB internal type if we already
1237 have it lying around. */
1239 static struct type *
1240 hpread_alloc_type (hp_type, objfile)
1241 dnttpointer hp_type;
1242 struct objfile *objfile;
1244 struct type **type_addr;
1246 type_addr = hpread_lookup_type (hp_type, objfile);
1247 if (*type_addr == 0)
1248 *type_addr = alloc_type (objfile);
1250 TYPE_CPLUS_SPECIFIC (*type_addr)
1251 = (struct cplus_struct_type *) &cplus_struct_default;
1255 /* Read a native enumerated type and return it in GDB internal form. */
1257 static struct type *
1258 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1259 dnttpointer hp_type;
1260 union dnttentry *dn_bufp;
1261 struct objfile *objfile;
1264 struct pending **symlist, *osyms, *syms;
1265 int o_nsyms, nsyms = 0;
1267 union dnttentry *memp;
1272 type = hpread_alloc_type (hp_type, objfile);
1273 TYPE_LENGTH (type) = 4;
1275 symlist = &file_symbols;
1277 o_nsyms = osyms ? osyms->nsyms : 0;
1279 /* Get a name for each member and add it to our list of members. */
1280 mem = dn_bufp->denum.firstmem;
1281 while (mem.dnttp.extension && mem.word != DNTTNIL)
1283 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1285 name = VT (objfile) + memp->dmember.name;
1286 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1287 sizeof (struct symbol));
1288 memset (sym, 0, sizeof (struct symbol));
1289 SYMBOL_NAME (sym) = name;
1290 SYMBOL_CLASS (sym) = LOC_CONST;
1291 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1292 SYMBOL_VALUE (sym) = memp->dmember.value;
1293 add_symbol_to_list (sym, symlist);
1295 mem = memp->dmember.nextmem;
1298 /* Now that we know more about the enum, fill in more info. */
1299 TYPE_CODE (type) = TYPE_CODE_ENUM;
1300 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1301 TYPE_NFIELDS (type) = nsyms;
1302 TYPE_FIELDS (type) = (struct field *)
1303 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1305 /* Find the symbols for the members and put them into the type.
1306 The symbols can be found in the symlist that we put them on
1307 to cause them to be defined. osyms contains the old value
1308 of that symlist; everything up to there was defined by us.
1310 Note that we preserve the order of the enum constants, so
1311 that in something like "enum {FOO, LAST_THING=FOO}" we print
1312 FOO, not LAST_THING. */
1313 for (syms = *symlist, n = 0; syms; syms = syms->next)
1318 for (; j < syms->nsyms; j++, n++)
1320 struct symbol *xsym = syms->symbol[j];
1321 SYMBOL_TYPE (xsym) = type;
1322 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1323 TYPE_FIELD_VALUE (type, n) = 0;
1324 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1325 TYPE_FIELD_BITSIZE (type, n) = 0;
1334 /* Read and internalize a native function debug symbol. */
1336 static struct type *
1337 hpread_read_function_type (hp_type, dn_bufp, objfile)
1338 dnttpointer hp_type;
1339 union dnttentry *dn_bufp;
1340 struct objfile *objfile;
1342 struct type *type, *type1;
1343 struct pending **symlist, *osyms, *syms;
1344 int o_nsyms, nsyms = 0;
1346 union dnttentry *paramp;
1351 param = dn_bufp->dfunc.firstparam;
1353 /* See if we've already read in this type. */
1354 type = hpread_alloc_type (hp_type, objfile);
1355 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1358 /* Nope, so read it in and store it away. */
1359 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1361 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1363 symlist = &local_symbols;
1365 o_nsyms = osyms ? osyms->nsyms : 0;
1367 /* Now examine each parameter noting its type, location, and a
1368 wealth of other information. */
1369 while (param.word && param.word != DNTTNIL)
1371 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1373 param = paramp->dfparam.nextparam;
1376 name = VT (objfile) + paramp->dfparam.name;
1377 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1378 sizeof (struct symbol));
1379 (void) memset (sym, 0, sizeof (struct symbol));
1380 SYMBOL_NAME (sym) = name;
1382 /* Figure out where it lives. */
1383 if (paramp->dfparam.regparam)
1384 SYMBOL_CLASS (sym) = LOC_REGPARM;
1385 else if (paramp->dfparam.indirect)
1386 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1388 SYMBOL_CLASS (sym) = LOC_ARG;
1389 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1390 if (paramp->dfparam.copyparam)
1392 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1393 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1395 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1397 /* This is likely a pass-by-invisible reference parameter,
1398 Hack on the symbol class to make GDB happy. */
1399 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1402 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1405 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1407 /* Add it to the list. */
1408 add_symbol_to_list (sym, symlist);
1411 /* Note how many parameters we found. */
1412 TYPE_NFIELDS (type) = nsyms;
1413 TYPE_FIELDS (type) = (struct field *)
1414 obstack_alloc (&objfile->type_obstack,
1415 sizeof (struct field) * nsyms);
1417 /* Find the symbols for the values and put them into the type.
1418 The symbols can be found in the symlist that we put them on
1419 to cause them to be defined. osyms contains the old value
1420 of that symlist; everything up to there was defined by us. */
1421 /* Note that we preserve the order of the parameters, so
1422 that in something like "enum {FOO, LAST_THING=FOO}" we print
1423 FOO, not LAST_THING. */
1424 for (syms = *symlist, n = 0; syms; syms = syms->next)
1429 for (; j < syms->nsyms; j++, n++)
1431 struct symbol *xsym = syms->symbol[j];
1432 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1433 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1434 TYPE_FIELD_BITPOS (type, n) = n;
1435 TYPE_FIELD_BITSIZE (type, n) = 0;
1443 /* Read in and internalize a structure definition. */
1445 static struct type *
1446 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1447 dnttpointer hp_type;
1448 union dnttentry *dn_bufp;
1449 struct objfile *objfile;
1453 struct nextfield *next;
1458 struct nextfield *list = 0;
1459 struct nextfield *new;
1462 union dnttentry *fieldp;
1464 /* Is it something we've already dealt with? */
1465 type = hpread_alloc_type (hp_type, objfile);
1466 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1467 (TYPE_CODE (type) == TYPE_CODE_UNION))
1470 /* Get the basic type correct. */
1471 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1473 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1474 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1476 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1478 TYPE_CODE (type) = TYPE_CODE_UNION;
1479 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1485 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1487 /* Read in and internalize all the fields. */
1488 field = dn_bufp->dstruct.firstfield;
1489 while (field.word != DNTTNIL && field.dnttp.extension)
1491 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1493 /* Get space to record the next field's data. */
1494 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1498 list->field.name = VT (objfile) + fieldp->dfield.name;
1499 list->field.bitpos = fieldp->dfield.bitoffset;
1500 if (fieldp->dfield.bitlength % 8)
1501 list->field.bitsize = fieldp->dfield.bitlength;
1503 list->field.bitsize = 0;
1505 field = fieldp->dfield.nextfield;
1506 list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
1509 TYPE_NFIELDS (type) = nfields;
1510 TYPE_FIELDS (type) = (struct field *)
1511 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1513 /* Copy the saved-up fields into the field vector. */
1514 for (n = nfields; list; list = list->next)
1517 TYPE_FIELD (type, n) = list->field;
1522 /* Read in and internalize a set debug symbol. */
1524 static struct type *
1525 hpread_read_set_type (hp_type, dn_bufp, objfile)
1526 dnttpointer hp_type;
1527 union dnttentry *dn_bufp;
1528 struct objfile *objfile;
1532 /* See if it's something we've already deal with. */
1533 type = hpread_alloc_type (hp_type, objfile);
1534 if (TYPE_CODE (type) == TYPE_CODE_SET)
1537 /* Nope. Fill in the appropriate fields. */
1538 TYPE_CODE (type) = TYPE_CODE_SET;
1539 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1540 TYPE_NFIELDS (type) = 0;
1541 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1546 /* Read in and internalize an array debug symbol. */
1548 static struct type *
1549 hpread_read_array_type (hp_type, dn_bufp, objfile)
1550 dnttpointer hp_type;
1551 union dnttentry *dn_bufp;
1552 struct objfile *objfile;
1555 union dnttentry save;
1558 /* Why no check here? Because it kept us from properly determining
1559 the size of the array! */
1560 type = hpread_alloc_type (hp_type, objfile);
1562 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1564 /* values are not normalized. */
1565 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1566 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1568 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1570 /* The HP debug format represents char foo[]; as an array with
1571 length 0x7fffffff. Internally GDB wants to represent this
1572 as an array of length zero. */
1573 TYPE_LENGTH (type) = 0;
1576 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1578 TYPE_NFIELDS (type) = 1;
1579 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1582 TYPE_FIELDS (type) = (struct field *)
1583 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1584 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1589 /* Read in and internalize a subrange debug symbol. */
1590 static struct type *
1591 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1592 dnttpointer hp_type;
1593 union dnttentry *dn_bufp;
1594 struct objfile *objfile;
1598 /* Is it something we've already dealt with. */
1599 type = hpread_alloc_type (hp_type, objfile);
1600 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1603 /* Nope, internalize it. */
1604 TYPE_CODE (type) = TYPE_CODE_RANGE;
1605 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1606 TYPE_NFIELDS (type) = 2;
1608 = (struct field *) obstack_alloc (&objfile->type_obstack,
1609 2 * sizeof (struct field));
1611 if (dn_bufp->dsubr.dyn_low)
1612 TYPE_FIELD_BITPOS (type, 0) = 0;
1614 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1616 if (dn_bufp->dsubr.dyn_high)
1617 TYPE_FIELD_BITPOS (type, 1) = -1;
1619 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1620 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1625 static struct type *
1626 hpread_type_lookup (hp_type, objfile)
1627 dnttpointer hp_type;
1628 struct objfile *objfile;
1630 union dnttentry *dn_bufp;
1632 /* First see if it's a simple builtin type. */
1633 if (hp_type.dntti.immediate)
1634 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1636 /* Not a builtin type. We'll have to read it in. */
1637 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1638 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1640 return lookup_fundamental_type (objfile, FT_VOID);
1642 switch (dn_bufp->dblock.kind)
1644 case DNTT_TYPE_SRCFILE:
1645 case DNTT_TYPE_MODULE:
1646 case DNTT_TYPE_FUNCTION:
1647 case DNTT_TYPE_ENTRY:
1648 case DNTT_TYPE_BEGIN:
1650 case DNTT_TYPE_IMPORT:
1651 case DNTT_TYPE_LABEL:
1652 case DNTT_TYPE_WITH:
1653 case DNTT_TYPE_COMMON:
1654 case DNTT_TYPE_FPARAM:
1655 case DNTT_TYPE_SVAR:
1656 case DNTT_TYPE_DVAR:
1657 case DNTT_TYPE_CONST:
1658 /* Opps. Something went very wrong. */
1659 return lookup_fundamental_type (objfile, FT_VOID);
1661 case DNTT_TYPE_TYPEDEF:
1663 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1666 suffix = VT (objfile) + dn_bufp->dtype.name;
1668 TYPE_CPLUS_SPECIFIC (structtype)
1669 = (struct cplus_struct_type *) &cplus_struct_default;
1670 TYPE_NAME (structtype) = suffix;
1674 case DNTT_TYPE_TAGDEF:
1676 /* Just a little different from above. We have to tack on
1677 an identifier of some kind (struct, union, enum, etc). */
1678 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1680 char *prefix, *suffix;
1681 suffix = VT (objfile) + dn_bufp->dtype.name;
1683 /* Lookup the next type in the list. It should be a structure,
1684 union, or enum type. We will need to attach that to our name. */
1685 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1686 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1690 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1692 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1697 /* Build the correct name. */
1699 = (char *) obstack_alloc (&objfile->type_obstack,
1700 strlen (prefix) + strlen (suffix) + 1);
1701 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1702 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1703 TYPE_TAG_NAME (structtype) = suffix;
1705 TYPE_CPLUS_SPECIFIC (structtype)
1706 = (struct cplus_struct_type *) &cplus_struct_default;
1710 case DNTT_TYPE_POINTER:
1711 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1713 case DNTT_TYPE_ENUM:
1714 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1715 case DNTT_TYPE_MEMENUM:
1716 return lookup_fundamental_type (objfile, FT_VOID);
1718 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1719 case DNTT_TYPE_SUBRANGE:
1720 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1721 case DNTT_TYPE_ARRAY:
1722 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1723 case DNTT_TYPE_STRUCT:
1724 case DNTT_TYPE_UNION:
1725 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1726 case DNTT_TYPE_FIELD:
1727 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1728 case DNTT_TYPE_VARIANT:
1729 case DNTT_TYPE_FILE:
1730 return lookup_fundamental_type (objfile, FT_VOID);
1731 case DNTT_TYPE_FUNCTYPE:
1732 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1734 case DNTT_TYPE_COBSTRUCT:
1735 case DNTT_TYPE_XREF:
1737 case DNTT_TYPE_MACRO:
1739 return lookup_fundamental_type (objfile, FT_VOID);
1744 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1745 struct subfile *subfile;
1746 sltpointer s_idx, e_idx;
1747 struct objfile *objfile;
1750 union sltentry *sl_bufp;
1752 while (s_idx <= e_idx)
1754 sl_bufp = hpread_get_slt (s_idx, objfile);
1755 /* Only record "normal" entries in the SLT. */
1756 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1757 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1758 record_line (subfile, sl_bufp->snorm.line,
1759 sl_bufp->snorm.address + offset);
1765 /* Internalize one native debug symbol. */
1768 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1769 text_offset, text_size, filename, index)
1770 union dnttentry *dn_bufp;
1772 struct section_offsets *section_offsets;
1773 struct objfile *objfile;
1774 CORE_ADDR text_offset;
1782 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1783 union dnttentry *dn_temp;
1784 dnttpointer hp_type;
1786 struct context_stack *new;
1788 /* Allocate one GDB debug symbol and fill in some default values. */
1789 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1790 sizeof (struct symbol));
1791 memset (sym, 0, sizeof (struct symbol));
1792 SYMBOL_NAME (sym) = name;
1793 SYMBOL_LANGUAGE (sym) = language_auto;
1794 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1795 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1796 SYMBOL_LINE (sym) = 0;
1797 SYMBOL_VALUE (sym) = 0;
1798 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1800 hp_type.dnttp.extension = 1;
1801 hp_type.dnttp.immediate = 0;
1802 hp_type.dnttp.global = 0;
1803 hp_type.dnttp.index = index;
1805 type = dn_bufp->dblock.kind;
1809 case DNTT_TYPE_SRCFILE:
1810 /* This type of symbol indicates from which source file or include file
1811 the following data comes. If there are no modules it also may
1812 indicate the start of a new source file, in which case we must
1813 finish the symbol table of the previous source file
1814 (if any) and start accumulating a new symbol table. */
1817 if (!last_source_file)
1819 start_symtab (name, NULL, valu);
1820 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1824 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1826 dn_bufp->dsfile.address,
1829 start_subfile (name, NULL);
1832 case DNTT_TYPE_MODULE:
1833 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1836 case DNTT_TYPE_FUNCTION:
1837 case DNTT_TYPE_ENTRY:
1838 /* A function or secondary entry point. */
1839 valu = dn_bufp->dfunc.lowaddr + offset;
1840 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1842 dn_bufp->dfunc.address,
1845 WITHIN_FUNCTION (objfile) = 1;
1846 CURRENT_FUNCTION_VALUE (objfile) = valu;
1848 /* Stack must be empty now. */
1849 if (context_stack_depth != 0)
1850 complain (&lbrac_unmatched_complaint, (char *) symnum);
1851 new = push_context (0, valu);
1853 SYMBOL_CLASS (sym) = LOC_BLOCK;
1854 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1855 if (dn_bufp->dfunc.global)
1856 add_symbol_to_list (sym, &global_symbols);
1858 add_symbol_to_list (sym, &file_symbols);
1861 /* Search forward to the next scope beginning. */
1862 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1864 dn_bufp = hpread_get_lntt (++index, objfile);
1865 if (dn_bufp->dblock.extension)
1868 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1870 dn_bufp->dbegin.address,
1872 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1873 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1876 case DNTT_TYPE_BEGIN:
1877 /* Begin a new scope. */
1878 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1880 dn_bufp->dbegin.address,
1882 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1883 valu += offset; /* Relocate for dynamic loading */
1884 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1885 new = push_context (desc, valu);
1890 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1892 dn_bufp->dend.address + 1,
1894 switch (dn_bufp->dend.endkind)
1896 case DNTT_TYPE_MODULE:
1897 /* Ending a module ends the symbol table for that module. */
1898 valu = text_offset + text_size + offset;
1899 (void) end_symtab (valu, objfile, 0);
1902 case DNTT_TYPE_FUNCTION:
1903 /* Ending a function, well, ends the function's scope. */
1904 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1906 valu = dn_temp->dfunc.hiaddr + offset;
1907 new = pop_context ();
1908 /* Make a block for the local symbols within. */
1909 finish_block (new->name, &local_symbols, new->old_blocks,
1910 new->start_addr, valu, objfile);
1911 WITHIN_FUNCTION (objfile) = 0;
1913 case DNTT_TYPE_BEGIN:
1914 /* Just ending a local scope. */
1915 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1916 /* Why in the hell is this needed? */
1917 valu += offset + 9; /* Relocate for dynamic loading */
1918 new = pop_context ();
1919 desc = dn_bufp->dend.beginscope.dnttp.index;
1920 if (desc != new->depth)
1921 complain (&lbrac_mismatch_complaint, (char *) symnum);
1922 /* Make a block for the local symbols within. */
1923 finish_block (new->name, &local_symbols, new->old_blocks,
1924 new->start_addr, valu, objfile);
1925 local_symbols = new->locals;
1929 case DNTT_TYPE_LABEL:
1930 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1932 case DNTT_TYPE_FPARAM:
1933 /* Function parameters. */
1934 if (dn_bufp->dfparam.regparam)
1935 SYMBOL_CLASS (sym) = LOC_REGISTER;
1937 SYMBOL_CLASS (sym) = LOC_LOCAL;
1938 if (dn_bufp->dfparam.copyparam)
1940 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1941 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1943 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1947 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1948 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1949 add_symbol_to_list (sym, &local_symbols);
1951 case DNTT_TYPE_SVAR:
1952 /* Static variables. */
1953 SYMBOL_CLASS (sym) = LOC_STATIC;
1954 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1955 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1956 if (dn_bufp->dsvar.global)
1957 add_symbol_to_list (sym, &global_symbols);
1958 else if (WITHIN_FUNCTION (objfile))
1959 add_symbol_to_list (sym, &local_symbols);
1961 add_symbol_to_list (sym, &file_symbols);
1963 case DNTT_TYPE_DVAR:
1964 /* Dynamic variables. */
1965 if (dn_bufp->ddvar.regvar)
1966 SYMBOL_CLASS (sym) = LOC_REGISTER;
1968 SYMBOL_CLASS (sym) = LOC_LOCAL;
1969 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1970 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1972 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1974 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1975 if (dn_bufp->ddvar.global)
1976 add_symbol_to_list (sym, &global_symbols);
1977 else if (WITHIN_FUNCTION (objfile))
1978 add_symbol_to_list (sym, &local_symbols);
1980 add_symbol_to_list (sym, &file_symbols);
1982 case DNTT_TYPE_CONST:
1983 /* A constant (pascal?). */
1984 SYMBOL_CLASS (sym) = LOC_CONST;
1985 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1986 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1987 if (dn_bufp->dconst.global)
1988 add_symbol_to_list (sym, &global_symbols);
1989 else if (WITHIN_FUNCTION (objfile))
1990 add_symbol_to_list (sym, &local_symbols);
1992 add_symbol_to_list (sym, &file_symbols);
1994 case DNTT_TYPE_TYPEDEF:
1995 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1996 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1997 if (dn_bufp->dtype.global)
1998 add_symbol_to_list (sym, &global_symbols);
1999 else if (WITHIN_FUNCTION (objfile))
2000 add_symbol_to_list (sym, &local_symbols);
2002 add_symbol_to_list (sym, &file_symbols);
2004 case DNTT_TYPE_TAGDEF:
2005 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2006 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2007 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2008 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2009 if (dn_bufp->dtype.global)
2010 add_symbol_to_list (sym, &global_symbols);
2011 else if (WITHIN_FUNCTION (objfile))
2012 add_symbol_to_list (sym, &local_symbols);
2014 add_symbol_to_list (sym, &file_symbols);
2016 case DNTT_TYPE_POINTER:
2017 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2018 (dn_bufp->dptr.pointsto,
2020 add_symbol_to_list (sym, &file_symbols);
2022 case DNTT_TYPE_ENUM:
2023 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2024 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2025 add_symbol_to_list (sym, &file_symbols);
2027 case DNTT_TYPE_MEMENUM:
2030 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2031 add_symbol_to_list (sym, &file_symbols);
2033 case DNTT_TYPE_SUBRANGE:
2034 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2036 add_symbol_to_list (sym, &file_symbols);
2038 case DNTT_TYPE_ARRAY:
2039 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2040 add_symbol_to_list (sym, &file_symbols);
2042 case DNTT_TYPE_STRUCT:
2043 case DNTT_TYPE_UNION:
2044 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2045 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2046 add_symbol_to_list (sym, &file_symbols);