1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
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 /* Each partial symbol table entry contains a pointer to private data for the
104 read_symtab() function to use when expanding a partial symbol table entry
105 to a full symbol table entry.
107 For hpuxread this structure contains the offset within the file symbol table
108 of first local symbol for this file, and length (in bytes) of the section
109 of the symbol table devoted to this file's symbols (actually, the section
110 bracketed may contain more than just this file's symbols).
112 If ldsymlen is 0, the only reason for this thing's existence is the
113 dependency list. Nothing else will happen when it is read in. */
115 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
116 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
117 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
125 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
126 /* Nonzero means give verbose info on gdb action. */
127 extern int info_verbose;
129 /* Complaints about the symbols we have encountered. */
130 extern struct complaint string_table_offset_complaint;
131 extern struct complaint lbrac_unmatched_complaint;
132 extern struct complaint lbrac_mismatch_complaint;
135 void hpread_symfile_init PARAMS ((struct objfile *));
137 static struct type *hpread_alloc_type
138 PARAMS ((dnttpointer, struct objfile *));
140 static struct type **hpread_lookup_type
141 PARAMS ((dnttpointer, struct objfile *));
143 static struct type *hpread_read_enum_type
144 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
146 static struct type *hpread_read_set_type
147 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
149 static struct type *hpread_read_subrange_type
150 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
152 static struct type *hpread_read_struct_type
153 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
155 void hpread_build_psymtabs
156 PARAMS ((struct objfile *, struct section_offsets *, int));
158 void hpread_symfile_finish PARAMS ((struct objfile *));
160 static struct partial_symtab *hpread_start_psymtab
161 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
162 struct partial_symbol *, struct partial_symbol *));
164 static struct partial_symtab *hpread_end_psymtab
165 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
166 struct partial_symtab **, int));
168 static struct symtab *hpread_expand_symtab
169 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
170 struct section_offsets *, char *));
172 static void hpread_process_one_debug_symbol
173 PARAMS ((union dnttentry *, char *, struct section_offsets *,
174 struct objfile *, CORE_ADDR, int, char *, int));
176 static sltpointer hpread_record_lines
177 PARAMS ((struct subfile *, sltpointer, sltpointer,
178 struct objfile *, CORE_ADDR));
180 static struct type *hpread_read_function_type
181 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
183 static struct type * hpread_type_lookup
184 PARAMS ((dnttpointer, struct objfile *));
186 static unsigned long hpread_get_depth
187 PARAMS ((sltpointer, struct objfile *));
189 static unsigned long hpread_get_line
190 PARAMS ((sltpointer, struct objfile *));
192 static CORE_ADDR hpread_get_location
193 PARAMS ((sltpointer, struct objfile *));
195 static int hpread_type_translate PARAMS ((dnttpointer));
196 static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
197 static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
198 static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
199 static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
200 static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
201 static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
202 static int hpread_has_name PARAMS ((enum dntt_entry_type));
205 /* Initialization for reading native HP C debug symbols from OBJFILE.
207 It's only purpose in life is to set up the symbol reader's private
208 per-objfile data structures, and read in the raw contents of the debug
209 sections (attaching pointers to the debug info into the private data
212 Since BFD doesn't know how to read debug symbols in a format-independent
213 way (and may never do so...), we have to do it ourselves. Note we may
214 be called on a file without native HP C debugging symbols.
215 FIXME, there should be a cleaner peephole into the BFD environment here. */
218 hpread_symfile_init (objfile)
219 struct objfile *objfile;
221 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
223 /* Allocate struct to keep track of the symfile */
224 objfile->sym_private = (PTR)
225 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
226 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
228 /* We haven't read in any types yet. */
229 TYPE_VECTOR (objfile) = 0;
231 /* Read in data from the $GNTT$ subspace. */
232 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
237 = obstack_alloc (&objfile->symbol_obstack,
238 bfd_section_size (objfile->obfd, gntt_section));
240 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
241 0, bfd_section_size (objfile->obfd, gntt_section));
243 GNTT_SYMCOUNT (objfile)
244 = bfd_section_size (objfile->obfd, gntt_section)
245 / sizeof (struct dntt_type_block);
247 /* Read in data from the $LNTT$ subspace. Also keep track of the number
249 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
254 = obstack_alloc (&objfile->symbol_obstack,
255 bfd_section_size (objfile->obfd, lntt_section));
257 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
258 0, bfd_section_size (objfile->obfd, lntt_section));
260 LNTT_SYMCOUNT (objfile)
261 = bfd_section_size (objfile->obfd, lntt_section)
262 / sizeof (struct dntt_type_block);
264 /* Read in data from the $SLT$ subspace. $SLT$ contains information
265 on source line numbers. */
266 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
271 obstack_alloc (&objfile->symbol_obstack,
272 bfd_section_size (objfile->obfd, slt_section));
274 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
275 0, bfd_section_size (objfile->obfd, slt_section));
277 /* Read in data from the $VT$ subspace. $VT$ contains things like
278 names and constants. Keep track of the number of symbols in the VT. */
279 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
283 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
286 (char *) obstack_alloc (&objfile->symbol_obstack,
289 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
290 0, VT_SIZE (objfile));
293 /* Scan and build partial symbols for a symbol file.
295 The minimal symbol table (either SOM or HP a.out) has already been
296 read in; all we need to do is setup partial symbols based on the
297 native debugging information.
299 We assume hpread_symfile_init has been called to initialize the
300 symbol reader's private data structures.
302 SECTION_OFFSETS contains offsets relative to which the symbols in the
303 various sections are (depending where the sections were actually loaded).
304 MAINLINE is true if we are reading the main symbol
305 table (as opposed to a shared lib or dynamically loaded file). */
308 hpread_build_psymtabs (objfile, section_offsets, mainline)
309 struct objfile *objfile;
310 struct section_offsets *section_offsets;
314 int past_first_source_file = 0;
315 struct cleanup *old_chain;
317 int hp_symnum, symcount, i;
319 union dnttentry *dn_bufp;
325 /* Current partial symtab */
326 struct partial_symtab *pst;
328 /* List of current psymtab's include files */
329 char **psymtab_include_list;
330 int includes_allocated;
333 /* Index within current psymtab dependency list */
334 struct partial_symtab **dependency_list;
335 int dependencies_used, dependencies_allocated;
337 /* Just in case the stabs reader left turds lying around. */
339 make_cleanup (really_free_pendings, 0);
341 pst = (struct partial_symtab *) 0;
343 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
344 a number of problems with cross compilation and creating useless holes
345 in the stack when we have to allocate new entries. FIXME. */
347 includes_allocated = 30;
349 psymtab_include_list = (char **) alloca (includes_allocated *
352 dependencies_allocated = 30;
353 dependencies_used = 0;
355 (struct partial_symtab **) alloca (dependencies_allocated *
356 sizeof (struct partial_symtab *));
358 old_chain = make_cleanup (free_objfile, objfile);
360 last_source_file = 0;
362 /* Make two passes, one ofr the GNTT symbols, the other for the
364 for (i = 0; i < 1; i++)
366 int within_function = 0;
369 symcount = GNTT_SYMCOUNT (objfile);
371 symcount = LNTT_SYMCOUNT (objfile);
373 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
377 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
379 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
381 if (dn_bufp->dblock.extension)
384 /* Only handle things which are necessary for minimal symbols.
385 everything else is ignored. */
386 switch (dn_bufp->dblock.kind)
388 case DNTT_TYPE_SRCFILE:
390 /* A source file of some kind. Note this may simply
391 be an included file. */
392 SET_NAMESTRING (dn_bufp, &namestring, objfile);
394 /* Check if this is the source file we are already working
396 if (pst && !strcmp (namestring, pst->filename))
399 /* Check if this is an include file, if so check if we have
400 already seen it. Add it to the include list */
401 p = strrchr (namestring, '.');
402 if (!strcmp (p, ".h"))
407 for (j = 0; j < includes_used; j++)
408 if (!strcmp (namestring, psymtab_include_list[j]))
416 /* Add it to the list of includes seen so far and
417 allocate more include space if necessary. */
418 psymtab_include_list[includes_used++] = namestring;
419 if (includes_used >= includes_allocated)
421 char **orig = psymtab_include_list;
423 psymtab_include_list = (char **)
424 alloca ((includes_allocated *= 2) *
426 memcpy ((PTR) psymtab_include_list, (PTR) orig,
427 includes_used * sizeof (char *));
437 pst->filename = (char *)
438 obstack_alloc (&pst->objfile->psymbol_obstack,
439 strlen (namestring) + 1);
440 strcpy (pst->filename, namestring);
447 /* This is a bonafide new source file.
448 End the current partial symtab and start a new one. */
450 if (pst && past_first_source_file)
452 hpread_end_psymtab (pst, psymtab_include_list,
455 * sizeof (struct dntt_type_block)),
457 dependency_list, dependencies_used);
458 pst = (struct partial_symtab *) 0;
460 dependencies_used = 0;
463 past_first_source_file = 1;
465 valu = hpread_get_textlow (i, hp_symnum, objfile);
466 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
467 pst = hpread_start_psymtab (objfile, section_offsets,
470 * sizeof (struct dntt_type_block)),
471 objfile->global_psymbols.next,
472 objfile->static_psymbols.next);
478 case DNTT_TYPE_MODULE:
479 /* A source file. It's still unclear to me what the
480 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
481 is supposed to be. */
482 SET_NAMESTRING (dn_bufp, &namestring, objfile);
483 valu = hpread_get_textlow (i, hp_symnum, objfile);
484 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
487 pst = hpread_start_psymtab (objfile, section_offsets,
490 * sizeof (struct dntt_type_block)),
491 objfile->global_psymbols.next,
492 objfile->static_psymbols.next);
497 case DNTT_TYPE_FUNCTION:
498 case DNTT_TYPE_ENTRY:
499 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
500 a secondary entry point. */
501 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
505 valu = dn_bufp->dfunc.lowaddr +
506 ANOFFSET (section_offsets, SECT_OFF_TEXT);
507 SET_NAMESTRING (dn_bufp, &namestring, objfile);
508 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
509 VAR_NAMESPACE, LOC_BLOCK,
510 objfile->static_psymbols, valu,
511 language_unknown, objfile);
514 case DNTT_TYPE_BEGIN:
516 /* Scope block begin/end. We only care about function
517 and file blocks right now. */
518 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
520 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
522 * sizeof (struct dntt_type_block)),
524 dependency_list, dependencies_used);
525 pst = (struct partial_symtab *) 0;
527 dependencies_used = 0;
530 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
535 case DNTT_TYPE_TYPEDEF:
536 case DNTT_TYPE_TAGDEF:
538 /* Variables, typedefs an the like. */
539 enum address_class storage;
540 enum namespace namespace;
542 /* Don't add locals to the partial symbol table. */
544 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
545 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
548 /* TAGDEFs go into the structure namespace. */
549 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
550 namespace = STRUCT_NAMESPACE;
552 namespace = VAR_NAMESPACE;
554 /* What kind of "storage" does this use? */
555 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
556 storage = LOC_STATIC;
557 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
558 && dn_bufp->ddvar.regvar)
559 storage = LOC_REGISTER;
560 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
565 SET_NAMESTRING (dn_bufp, &namestring, objfile);
568 pst = hpread_start_psymtab (objfile, section_offsets,
571 * sizeof (struct dntt_type_block)),
572 objfile->global_psymbols.next,
573 objfile->static_psymbols.next);
575 if (dn_bufp->dsvar.global)
577 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
579 objfile->global_psymbols,
580 dn_bufp->dsvar.location,
581 language_unknown, objfile);
585 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
587 objfile->static_psymbols,
588 dn_bufp->dsvar.location,
589 language_unknown, objfile);
593 case DNTT_TYPE_MEMENUM:
594 case DNTT_TYPE_CONST:
595 /* Constants and members of enumerated types. */
596 SET_NAMESTRING (dn_bufp, &namestring, objfile);
599 pst = hpread_start_psymtab (objfile, section_offsets,
602 * sizeof (struct dntt_type_block)),
603 objfile->global_psymbols.next,
604 objfile->static_psymbols.next);
606 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
607 VAR_NAMESPACE, LOC_CONST,
608 objfile->static_psymbols, 0,
609 language_unknown, objfile);
617 /* End any pending partial symbol table. */
620 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
621 hp_symnum * sizeof (struct dntt_type_block),
622 0, dependency_list, dependencies_used);
625 discard_cleanups (old_chain);
628 /* Perform any local cleanups required when we are done with a particular
629 objfile. I.E, we are in the process of discarding all symbol information
630 for an objfile, freeing up all memory held for it, and unlinking the
631 objfile struct from the global list of known objfiles. */
634 hpread_symfile_finish (objfile)
635 struct objfile *objfile;
637 if (objfile->sym_private != NULL)
639 mfree (objfile->md, objfile->sym_private);
644 /* The remaining functions are all for internal use only. */
646 /* Various small functions to get entries in the debug symbol sections. */
648 static union dnttentry *
649 hpread_get_lntt (index, objfile)
651 struct objfile *objfile;
653 return (union dnttentry *)
654 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
657 static union dnttentry *
658 hpread_get_gntt (index, objfile)
660 struct objfile *objfile;
662 return (union dnttentry *)
663 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
666 static union sltentry *
667 hpread_get_slt (index, objfile)
669 struct objfile *objfile;
671 return (union sltentry *)&(SLT (objfile)[index * sizeof (union sltentry)]);
674 /* Get the low address associated with some symbol (typically the start
675 of a particular source file or module). Since that information is not
676 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
677 the existance of DNTT_TYPE_FUNCTION symbols. */
680 hpread_get_textlow (global, index, objfile)
683 struct objfile *objfile;
685 union dnttentry *dn_bufp;
686 struct minimal_symbol *msymbol;
688 /* Look for a DNTT_TYPE_FUNCTION symbol. */
692 dn_bufp = hpread_get_gntt (index++, objfile);
694 dn_bufp = hpread_get_lntt (index++, objfile);
695 } while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
696 && dn_bufp->dblock.kind != DNTT_TYPE_END);
698 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
699 might happen when a sourcefile has no functions. */
700 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
703 /* The minimal symbols are typically more accurate for some reason. */
704 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
707 return SYMBOL_VALUE_ADDRESS (msymbol);
709 return dn_bufp->dfunc.lowaddr;
712 /* Get the nesting depth for the source line identified by INDEX. */
715 hpread_get_depth (index, objfile)
717 struct objfile *objfile;
719 union sltentry *sl_bufp;
721 sl_bufp = hpread_get_slt (index, objfile);
722 return sl_bufp->sspec.backptr.dnttp.index;
725 /* Get the source line number the the line identified by INDEX. */
728 hpread_get_line (index, objfile)
730 struct objfile *objfile;
732 union sltentry *sl_bufp;
734 sl_bufp = hpread_get_slt (index, objfile);
735 return sl_bufp->snorm.line;
739 hpread_get_location (index, objfile)
741 struct objfile *objfile;
743 union sltentry *sl_bufp;
746 /* code location of special sltentrys is determined from context */
747 sl_bufp = hpread_get_slt (index, objfile);
749 if (sl_bufp->snorm.sltdesc == SLT_END)
751 /* find previous normal sltentry and get address */
752 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
753 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
754 sl_bufp = hpread_get_slt (index - i, objfile);
755 return sl_bufp->snorm.address;
758 /* find next normal sltentry and get address */
759 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
760 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
761 sl_bufp = hpread_get_slt (index + i, objfile);
762 return sl_bufp->snorm.address;
766 /* Return 1 if an HP debug symbol of type KIND has a name associated with
767 it, else return 0. */
770 hpread_has_name (kind)
771 enum dntt_entry_type kind;
775 case DNTT_TYPE_SRCFILE:
776 case DNTT_TYPE_MODULE:
777 case DNTT_TYPE_FUNCTION:
778 case DNTT_TYPE_ENTRY:
779 case DNTT_TYPE_IMPORT:
780 case DNTT_TYPE_LABEL:
781 case DNTT_TYPE_FPARAM:
784 case DNTT_TYPE_CONST:
785 case DNTT_TYPE_TYPEDEF:
786 case DNTT_TYPE_TAGDEF:
787 case DNTT_TYPE_MEMENUM:
788 case DNTT_TYPE_FIELD:
792 case DNTT_TYPE_BEGIN:
795 case DNTT_TYPE_COMMON:
796 case DNTT_TYPE_POINTER:
799 case DNTT_TYPE_SUBRANGE:
800 case DNTT_TYPE_ARRAY:
801 case DNTT_TYPE_STRUCT:
802 case DNTT_TYPE_UNION:
803 case DNTT_TYPE_VARIANT:
805 case DNTT_TYPE_FUNCTYPE:
806 case DNTT_TYPE_COBSTRUCT:
808 case DNTT_TYPE_MACRO:
814 /* Allocate and partially fill a partial symtab. It will be
815 completely filled at the end of the symbol list.
817 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
818 is the address relative to which its symbols are (incremental) or 0
821 static struct partial_symtab *
822 hpread_start_psymtab (objfile, section_offsets,
823 filename, textlow, ldsymoff, global_syms, static_syms)
824 struct objfile *objfile;
825 struct section_offsets *section_offsets;
829 struct partial_symbol *global_syms;
830 struct partial_symbol *static_syms;
832 struct partial_symtab *result =
833 start_psymtab_common (objfile, section_offsets,
834 filename, textlow, global_syms, static_syms);
836 result->read_symtab_private = (char *)
837 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
838 LDSYMOFF (result) = ldsymoff;
839 result->read_symtab = hpread_psymtab_to_symtab;
845 /* Close off the current usage of PST.
846 Returns PST or NULL if the partial symtab was empty and thrown away.
848 FIXME: List variables and peculiarities of same. */
850 static struct partial_symtab *
851 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
852 capping_text, dependency_list, number_dependencies)
853 struct partial_symtab *pst;
856 int capping_symbol_offset;
857 CORE_ADDR capping_text;
858 struct partial_symtab **dependency_list;
859 int number_dependencies;
862 struct objfile *objfile = pst -> objfile;
864 if (capping_symbol_offset != -1)
865 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
866 pst->texthigh = capping_text;
869 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
871 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
873 pst->number_of_dependencies = number_dependencies;
874 if (number_dependencies)
876 pst->dependencies = (struct partial_symtab **)
877 obstack_alloc (&objfile->psymbol_obstack,
878 number_dependencies * sizeof (struct partial_symtab *));
879 memcpy (pst->dependencies, dependency_list,
880 number_dependencies * sizeof (struct partial_symtab *));
883 pst->dependencies = 0;
885 for (i = 0; i < num_includes; i++)
887 struct partial_symtab *subpst =
888 allocate_psymtab (include_list[i], objfile);
890 subpst->section_offsets = pst->section_offsets;
891 subpst->read_symtab_private =
892 (char *) obstack_alloc (&objfile->psymbol_obstack,
893 sizeof (struct symloc));
897 subpst->texthigh = 0;
899 /* We could save slight bits of space by only making one of these,
900 shared by the entire set of include files. FIXME-someday. */
901 subpst->dependencies = (struct partial_symtab **)
902 obstack_alloc (&objfile->psymbol_obstack,
903 sizeof (struct partial_symtab *));
904 subpst->dependencies[0] = pst;
905 subpst->number_of_dependencies = 1;
907 subpst->globals_offset =
908 subpst->n_global_syms =
909 subpst->statics_offset =
910 subpst->n_static_syms = 0;
914 subpst->read_symtab = pst->read_symtab;
917 sort_pst_symbols (pst);
919 /* If there is already a psymtab or symtab for a file of this name, remove it.
920 (If there is a symtab, more drastic things also happen.)
921 This happens in VxWorks. */
922 free_named_symtabs (pst->filename);
924 if (num_includes == 0
925 && number_dependencies == 0
926 && pst->n_global_syms == 0
927 && pst->n_static_syms == 0)
929 /* Throw away this psymtab, it's empty. We can't deallocate it, since
930 it is on the obstack, but we can forget to chain it on the list. */
931 /* Empty psymtabs happen as a result of header files which don't have
932 any symbols in them. There can be a lot of them. But this check
933 is wrong, in that a psymtab with N_SLINE entries but nothing else
934 is not empty, but we don't realize that. Fixing that without slowing
935 things down might be tricky. */
936 struct partial_symtab *prev_pst;
938 /* First, snip it out of the psymtab chain */
940 if (pst->objfile->psymtabs == pst)
941 pst->objfile->psymtabs = pst->next;
943 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
944 if (prev_pst->next == pst)
945 prev_pst->next = pst->next;
947 /* Next, put it on a free list for recycling */
949 pst->next = pst->objfile->free_psymtabs;
950 pst->objfile->free_psymtabs = pst;
952 /* Indicate that psymtab was thrown away. */
953 pst = (struct partial_symtab *)NULL;
958 /* Do the dirty work of reading in the full symbol from a partial symbol
962 hpread_psymtab_to_symtab_1 (pst)
963 struct partial_symtab *pst;
965 struct cleanup *old_chain;
968 /* Get out quick if passed junk. */
972 /* Complain if we've already read in this symbol table. */
975 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
980 /* Read in all partial symtabs on which this one is dependent */
981 for (i = 0; i < pst->number_of_dependencies; i++)
982 if (!pst->dependencies[i]->readin)
984 /* Inform about additional files that need to be read in. */
987 fputs_filtered (" ", stdout);
989 fputs_filtered ("and ", stdout);
991 printf_filtered ("%s...", pst->dependencies[i]->filename);
992 wrap_here (""); /* Flush output */
995 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
998 /* If it's real... */
1001 /* Init stuff necessary for reading in symbols */
1003 old_chain = make_cleanup (really_free_pendings, 0);
1006 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1007 pst->textlow, pst->texthigh - pst->textlow,
1008 pst->section_offsets, pst->filename);
1009 sort_symtab_syms (pst->symtab);
1011 do_cleanups (old_chain);
1017 /* Read in all of the symbols for a given psymtab for real.
1018 Be verbose about it if the user wants that. */
1021 hpread_psymtab_to_symtab (pst)
1022 struct partial_symtab *pst;
1024 /* Get out quick if given junk. */
1031 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1036 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1038 /* Print the message now, before reading the string table,
1039 to avoid disconcerting pauses. */
1042 printf_filtered ("Reading in symbols for %s...", pst->filename);
1046 hpread_psymtab_to_symtab_1 (pst);
1048 /* Match with global symbols. This only needs to be done once,
1049 after all of the symtabs and dependencies have been read in. */
1050 scan_file_globals (pst->objfile);
1052 /* Finish up the debug error message. */
1054 printf_filtered ("done.\n");
1057 /* Read in a defined section of a specific object file's symbols.
1059 DESC is the file descriptor for the file, positioned at the
1060 beginning of the symtab
1061 SYM_OFFSET is the offset within the file of
1062 the beginning of the symbols we want to read
1063 SYM_SIZE is the size of the symbol info to read in.
1064 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1065 TEXT_SIZE is the size of the text segment read in.
1066 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1068 static struct symtab *
1069 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1070 section_offsets, filename)
1071 struct objfile *objfile;
1074 CORE_ADDR text_offset;
1076 struct section_offsets *section_offsets;
1080 union dnttentry *dn_bufp;
1081 unsigned max_symnum;
1083 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1085 current_objfile = objfile;
1088 last_source_file = 0;
1090 dn_bufp = hpread_get_lntt (sym_index, objfile);
1091 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1092 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1093 start_symtab ("globals", NULL, 0);
1095 max_symnum = sym_size / sizeof (struct dntt_type_block);
1097 /* Read in and process each debug symbol within the specified range. */
1099 symnum < max_symnum;
1102 QUIT; /* Allow this to be interruptable */
1103 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1105 if (dn_bufp->dblock.extension)
1108 /* Yow! We call SET_NAMESTRING on things without names! */
1109 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1111 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1112 objfile, text_offset, text_size,
1113 filename, symnum + sym_index);
1116 current_objfile = NULL;
1118 return end_symtab (text_offset + text_size, 0, 0, objfile, 0);
1122 /* Convert basic types from HP debug format into GDB internal format. */
1125 hpread_type_translate (typep)
1128 if (!typep.dntti.immediate)
1131 switch (typep.dntti.type)
1133 case HP_TYPE_BOOLEAN:
1134 case HP_TYPE_BOOLEAN_S300_COMPAT:
1135 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1137 /* Ugh. No way to distinguish between signed and unsigned chars. */
1139 case HP_TYPE_WIDE_CHAR:
1142 if (typep.dntti.bitlength <= 8)
1144 if (typep.dntti.bitlength <= 16)
1146 if (typep.dntti.bitlength <= 32)
1148 return FT_LONG_LONG;
1151 case HP_TYPE_UNSIGNED_LONG:
1152 if (typep.dntti.bitlength <= 8)
1153 return FT_UNSIGNED_CHAR;
1154 if (typep.dntti.bitlength <= 16)
1155 return FT_UNSIGNED_SHORT;
1156 if (typep.dntti.bitlength <= 32)
1157 return FT_UNSIGNED_LONG;
1158 return FT_UNSIGNED_LONG_LONG;
1159 case HP_TYPE_UNSIGNED_INT:
1160 if (typep.dntti.bitlength <= 8)
1161 return FT_UNSIGNED_CHAR;
1162 if (typep.dntti.bitlength <= 16)
1163 return FT_UNSIGNED_SHORT;
1164 if (typep.dntti.bitlength <= 32)
1165 return FT_UNSIGNED_INTEGER;
1166 return FT_UNSIGNED_LONG_LONG;
1168 case HP_TYPE_REAL_3000:
1169 case HP_TYPE_DOUBLE:
1170 if (typep.dntti.bitlength == 64)
1171 return FT_DBL_PREC_FLOAT;
1172 if (typep.dntti.bitlength == 128)
1173 return FT_EXT_PREC_FLOAT;
1175 case HP_TYPE_COMPLEX:
1176 case HP_TYPE_COMPLEXS3000:
1177 if (typep.dntti.bitlength == 128)
1178 return FT_DBL_PREC_COMPLEX;
1179 if (typep.dntti.bitlength == 192)
1180 return FT_EXT_PREC_COMPLEX;
1182 case HP_TYPE_STRING200:
1183 case HP_TYPE_LONGSTRING200:
1184 case HP_TYPE_FTN_STRING_SPEC:
1185 case HP_TYPE_MOD_STRING_SPEC:
1186 case HP_TYPE_MOD_STRING_3000:
1187 case HP_TYPE_FTN_STRING_S300_COMPAT:
1188 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1195 /* Return the type associated with the index found in HP_TYPE. */
1197 static struct type **
1198 hpread_lookup_type (hp_type, objfile)
1199 dnttpointer hp_type;
1200 struct objfile *objfile;
1203 int index = hp_type.dnttp.index;
1205 if (hp_type.dntti.immediate)
1208 if (index < LNTT_SYMCOUNT (objfile))
1210 if (index >= TYPE_VECTOR_LENGTH (objfile))
1212 old_len = TYPE_VECTOR_LENGTH (objfile);
1215 TYPE_VECTOR_LENGTH (objfile) = 100;
1216 TYPE_VECTOR (objfile) = (struct type **)
1217 malloc (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1219 while (index >= TYPE_VECTOR_LENGTH (objfile))
1220 TYPE_VECTOR_LENGTH (objfile) *= 2;
1221 TYPE_VECTOR (objfile) = (struct type **)
1222 xrealloc ((char *) TYPE_VECTOR (objfile),
1223 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1224 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1225 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1226 sizeof (struct type *));
1228 return &TYPE_VECTOR (objfile)[index];
1234 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1235 Note we'll just return the address of a GDB internal type if we already
1236 have it lying around. */
1238 static struct type *
1239 hpread_alloc_type (hp_type, objfile)
1240 dnttpointer hp_type;
1241 struct objfile *objfile;
1243 struct type **type_addr;
1245 type_addr = hpread_lookup_type (hp_type, objfile);
1246 if (*type_addr == 0)
1247 *type_addr = alloc_type (objfile);
1249 TYPE_CPLUS_SPECIFIC (*type_addr)
1250 = (struct cplus_struct_type *) &cplus_struct_default;
1254 /* Read a native enumerated type and return it in GDB internal form. */
1256 static struct type *
1257 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1258 dnttpointer hp_type;
1259 union dnttentry *dn_bufp;
1260 struct objfile *objfile;
1263 struct pending **symlist, *osyms, *syms;
1264 int o_nsyms, nsyms = 0;
1266 union dnttentry *memp;
1271 type = hpread_alloc_type (hp_type, objfile);
1272 TYPE_LENGTH (type) = 4;
1274 symlist = &file_symbols;
1276 o_nsyms = osyms ? osyms->nsyms : 0;
1278 /* Get a name for each member and add it to our list of members. */
1279 mem = dn_bufp->denum.firstmem;
1280 while (mem.dnttp.extension && mem.word != DNTTNIL)
1282 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1284 name = VT (objfile) + memp->dmember.name;
1285 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1286 sizeof (struct symbol));
1287 memset (sym, 0, sizeof (struct symbol));
1288 SYMBOL_NAME (sym) = name;
1289 SYMBOL_CLASS (sym) = LOC_CONST;
1290 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1291 SYMBOL_VALUE (sym) = memp->dmember.value;
1292 add_symbol_to_list (sym, symlist);
1294 mem = memp->dmember.nextmem;
1297 /* Now that we know more about the enum, fill in more info. */
1298 TYPE_CODE (type) = TYPE_CODE_ENUM;
1299 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1300 TYPE_NFIELDS (type) = nsyms;
1301 TYPE_FIELDS (type) = (struct field *)
1302 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1304 /* Find the symbols for the members and put them into the type.
1305 The symbols can be found in the symlist that we put them on
1306 to cause them to be defined. osyms contains the old value
1307 of that symlist; everything up to there was defined by us.
1309 Note that we preserve the order of the enum constants, so
1310 that in something like "enum {FOO, LAST_THING=FOO}" we print
1311 FOO, not LAST_THING. */
1312 for (syms = *symlist, n = 0; syms; syms = syms->next)
1317 for (; j < syms->nsyms; j++, n++)
1319 struct symbol *xsym = syms->symbol[j];
1320 SYMBOL_TYPE (xsym) = type;
1321 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1322 TYPE_FIELD_VALUE (type, n) = 0;
1323 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1324 TYPE_FIELD_BITSIZE (type, n) = 0;
1333 /* Read and internalize a native function debug symbol. */
1335 static struct type *
1336 hpread_read_function_type (hp_type, dn_bufp, objfile)
1337 dnttpointer hp_type;
1338 union dnttentry *dn_bufp;
1339 struct objfile *objfile;
1341 struct type *type, *type1;
1342 struct pending **symlist, *osyms, *syms;
1343 int o_nsyms, nsyms = 0;
1345 union dnttentry *paramp;
1350 param = dn_bufp->dfunc.firstparam;
1352 /* See if we've already read in this type. */
1353 type = hpread_alloc_type (hp_type, objfile);
1354 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1357 /* Nope, so read it in and store it away. */
1358 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1360 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1362 symlist = &local_symbols;
1364 o_nsyms = osyms ? osyms->nsyms : 0;
1366 /* Now examine each parameter noting its type, location, and a
1367 wealth of other information. */
1368 while (param.word && param.word != DNTTNIL)
1370 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1372 param = paramp->dfparam.nextparam;
1375 name = VT (objfile) + paramp->dfparam.name;
1376 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1377 sizeof (struct symbol));
1378 (void) memset (sym, 0, sizeof (struct symbol));
1379 SYMBOL_NAME (sym) = name;
1381 /* Figure out where it lives. */
1382 if (paramp->dfparam.regparam)
1383 SYMBOL_CLASS (sym) = LOC_REGPARM;
1384 else if (paramp->dfparam.indirect)
1385 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1387 SYMBOL_CLASS (sym) = LOC_ARG;
1388 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1389 if (paramp->dfparam.copyparam)
1391 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1392 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1394 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1396 /* This is likely a pass-by-invisible reference parameter,
1397 Hack on the symbol class to make GDB happy. */
1398 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1401 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1404 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1406 /* Add it to the list. */
1407 add_symbol_to_list (sym, symlist);
1410 /* Note how many parameters we found. */
1411 TYPE_NFIELDS (type) = nsyms;
1412 TYPE_FIELDS (type) = (struct field *)
1413 obstack_alloc (&objfile->type_obstack,
1414 sizeof (struct field) * nsyms);
1416 /* Find the symbols for the values and put them into the type.
1417 The symbols can be found in the symlist that we put them on
1418 to cause them to be defined. osyms contains the old value
1419 of that symlist; everything up to there was defined by us. */
1420 /* Note that we preserve the order of the parameters, so
1421 that in something like "enum {FOO, LAST_THING=FOO}" we print
1422 FOO, not LAST_THING. */
1423 for (syms = *symlist, n = 0; syms; syms = syms->next)
1428 for (; j < syms->nsyms; j++, n++)
1430 struct symbol *xsym = syms->symbol[j];
1431 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1432 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1433 TYPE_FIELD_BITPOS (type, n) = n;
1434 TYPE_FIELD_BITSIZE (type, n) = 0;
1442 /* Read in and internalize a structure definition. */
1444 static struct type *
1445 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1446 dnttpointer hp_type;
1447 union dnttentry *dn_bufp;
1448 struct objfile *objfile;
1452 struct nextfield *next;
1457 struct nextfield *list = 0;
1458 struct nextfield *new;
1461 union dnttentry *fieldp;
1463 /* Is it something we've already dealt with? */
1464 type = hpread_alloc_type (hp_type, objfile);
1465 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1466 (TYPE_CODE (type) == TYPE_CODE_UNION))
1469 /* Get the basic type correct. */
1470 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1472 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1473 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1475 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1477 TYPE_CODE (type) = TYPE_CODE_UNION;
1478 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1484 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1486 /* Read in and internalize all the fields. */
1487 field = dn_bufp->dstruct.firstfield;
1488 while (field.word != DNTTNIL && field.dnttp.extension)
1490 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1492 /* Get space to record the next field's data. */
1493 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1497 list->field.name = VT (objfile) + fieldp->dfield.name;
1498 list->field.bitpos = fieldp->dfield.bitoffset;
1499 if (fieldp->dfield.bitlength % 8)
1500 list->field.bitsize = fieldp->dfield.bitlength;
1502 list->field.bitsize = 0;
1504 field = fieldp->dfield.nextfield;
1505 list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
1508 TYPE_NFIELDS (type) = nfields;
1509 TYPE_FIELDS (type) = (struct field *)
1510 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1512 /* Copy the saved-up fields into the field vector. */
1513 for (n = nfields; list; list = list->next)
1516 TYPE_FIELD (type, n) = list->field;
1521 /* Read in and internalize a set debug symbol. */
1523 static struct type *
1524 hpread_read_set_type (hp_type, dn_bufp, objfile)
1525 dnttpointer hp_type;
1526 union dnttentry *dn_bufp;
1527 struct objfile *objfile;
1531 /* See if it's something we've already deal with. */
1532 type = hpread_alloc_type (hp_type, objfile);
1533 if (TYPE_CODE (type) == TYPE_CODE_SET)
1536 /* Nope. Fill in the appropriate fields. */
1537 TYPE_CODE (type) = TYPE_CODE_SET;
1538 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1539 TYPE_NFIELDS (type) = 0;
1540 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1545 /* Read in and internalize an array debug symbol. */
1547 static struct type *
1548 hpread_read_array_type (hp_type, dn_bufp, objfile)
1549 dnttpointer hp_type;
1550 union dnttentry *dn_bufp;
1551 struct objfile *objfile;
1554 union dnttentry save;
1557 /* Why no check here? Because it kept us from properly determining
1558 the size of the array! */
1559 type = hpread_alloc_type (hp_type, objfile);
1561 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1563 /* values are not normalized. */
1564 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1565 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1567 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1569 /* The HP debug format represents char foo[]; as an array with
1570 length 0x7fffffff. Internally GDB wants to represent this
1571 as an array of length zero. */
1572 TYPE_LENGTH (type) = 0;
1575 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1577 TYPE_NFIELDS (type) = 1;
1578 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1581 TYPE_FIELDS (type) = (struct field *)
1582 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1583 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1588 /* Read in and internalize a subrange debug symbol. */
1589 static struct type *
1590 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1591 dnttpointer hp_type;
1592 union dnttentry *dn_bufp;
1593 struct objfile *objfile;
1597 /* Is it something we've already dealt with. */
1598 type = hpread_alloc_type (hp_type, objfile);
1599 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1602 /* Nope, internalize it. */
1603 TYPE_CODE (type) = TYPE_CODE_RANGE;
1604 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1605 TYPE_NFIELDS (type) = 2;
1607 = (struct field *) obstack_alloc (&objfile->type_obstack,
1608 2 * sizeof (struct field));
1610 if (dn_bufp->dsubr.dyn_low)
1611 TYPE_FIELD_BITPOS (type, 0) = 0;
1613 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1615 if (dn_bufp->dsubr.dyn_high)
1616 TYPE_FIELD_BITPOS (type, 1) = -1;
1618 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1619 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1624 static struct type *
1625 hpread_type_lookup (hp_type, objfile)
1626 dnttpointer hp_type;
1627 struct objfile *objfile;
1629 union dnttentry *dn_bufp;
1631 /* First see if it's a simple builtin type. */
1632 if (hp_type.dntti.immediate)
1633 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1635 /* Not a builtin type. We'll have to read it in. */
1636 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1637 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1639 return lookup_fundamental_type (objfile, FT_VOID);
1641 switch (dn_bufp->dblock.kind)
1643 case DNTT_TYPE_SRCFILE:
1644 case DNTT_TYPE_MODULE:
1645 case DNTT_TYPE_FUNCTION:
1646 case DNTT_TYPE_ENTRY:
1647 case DNTT_TYPE_BEGIN:
1649 case DNTT_TYPE_IMPORT:
1650 case DNTT_TYPE_LABEL:
1651 case DNTT_TYPE_WITH:
1652 case DNTT_TYPE_COMMON:
1653 case DNTT_TYPE_FPARAM:
1654 case DNTT_TYPE_SVAR:
1655 case DNTT_TYPE_DVAR:
1656 case DNTT_TYPE_CONST:
1657 /* Opps. Something went very wrong. */
1658 return lookup_fundamental_type (objfile, FT_VOID);
1660 case DNTT_TYPE_TYPEDEF:
1662 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1665 suffix = VT (objfile) + dn_bufp->dtype.name;
1667 TYPE_CPLUS_SPECIFIC (structtype)
1668 = (struct cplus_struct_type *) &cplus_struct_default;
1669 TYPE_NAME (structtype) = suffix;
1673 case DNTT_TYPE_TAGDEF:
1675 /* Just a little different from above. We have to tack on
1676 an identifier of some kind (struct, union, enum, etc). */
1677 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1679 char *prefix, *suffix;
1680 suffix = VT (objfile) + dn_bufp->dtype.name;
1682 /* Lookup the next type in the list. It should be a structure,
1683 union, or enum type. We will need to attach that to our name. */
1684 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1685 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1689 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1691 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1696 /* Build the correct name. */
1698 = (char *) obstack_alloc (&objfile->type_obstack,
1699 strlen (prefix) + strlen (suffix) + 1);
1700 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1701 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1702 TYPE_TAG_NAME (structtype) = suffix;
1704 TYPE_CPLUS_SPECIFIC (structtype)
1705 = (struct cplus_struct_type *) &cplus_struct_default;
1709 case DNTT_TYPE_POINTER:
1710 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1712 case DNTT_TYPE_ENUM:
1713 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1714 case DNTT_TYPE_MEMENUM:
1715 return lookup_fundamental_type (objfile, FT_VOID);
1717 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1718 case DNTT_TYPE_SUBRANGE:
1719 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1720 case DNTT_TYPE_ARRAY:
1721 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1722 case DNTT_TYPE_STRUCT:
1723 case DNTT_TYPE_UNION:
1724 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1725 case DNTT_TYPE_FIELD:
1726 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1727 case DNTT_TYPE_VARIANT:
1728 case DNTT_TYPE_FILE:
1729 return lookup_fundamental_type (objfile, FT_VOID);
1730 case DNTT_TYPE_FUNCTYPE:
1731 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1733 case DNTT_TYPE_COBSTRUCT:
1734 case DNTT_TYPE_XREF:
1736 case DNTT_TYPE_MACRO:
1738 return lookup_fundamental_type (objfile, FT_VOID);
1743 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1744 struct subfile *subfile;
1745 sltpointer s_idx, e_idx;
1746 struct objfile *objfile;
1749 union sltentry *sl_bufp;
1751 while (s_idx <= e_idx)
1753 sl_bufp = hpread_get_slt (s_idx, objfile);
1754 /* Only record "normal" entries in the SLT. */
1755 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1756 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1757 record_line (subfile, sl_bufp->snorm.line,
1758 sl_bufp->snorm.address + offset);
1764 /* Internalize one native debug symbol. */
1767 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1768 text_offset, text_size, filename, index)
1769 union dnttentry *dn_bufp;
1771 struct section_offsets *section_offsets;
1772 struct objfile *objfile;
1773 CORE_ADDR text_offset;
1781 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1782 union dnttentry *dn_temp;
1783 dnttpointer hp_type;
1785 struct context_stack *new;
1787 /* Allocate one GDB debug symbol and fill in some default values. */
1788 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1789 sizeof (struct symbol));
1790 memset (sym, 0, sizeof (struct symbol));
1791 SYMBOL_NAME (sym) = name;
1792 SYMBOL_LANGUAGE (sym) = language_auto;
1793 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1794 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1795 SYMBOL_LINE (sym) = 0;
1796 SYMBOL_VALUE (sym) = 0;
1797 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1799 hp_type.dnttp.extension = 1;
1800 hp_type.dnttp.immediate = 0;
1801 hp_type.dnttp.global = 0;
1802 hp_type.dnttp.index = index;
1804 type = dn_bufp->dblock.kind;
1808 case DNTT_TYPE_SRCFILE:
1809 /* This type of symbol indicates from which source file or include file
1810 the following data comes. If there are no modules it also may
1811 indicate the start of a new source file, in which case we must
1812 finish the symbol table of the previous source file
1813 (if any) and start accumulating a new symbol table. */
1816 if (!last_source_file)
1818 start_symtab (name, NULL, valu);
1819 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1823 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1825 dn_bufp->dsfile.address,
1828 start_subfile (name, NULL);
1831 case DNTT_TYPE_MODULE:
1832 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1835 case DNTT_TYPE_FUNCTION:
1836 case DNTT_TYPE_ENTRY:
1837 /* A function or secondary entry point. */
1838 valu = dn_bufp->dfunc.lowaddr + offset;
1839 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1841 dn_bufp->dfunc.address,
1844 WITHIN_FUNCTION (objfile) = 1;
1845 CURRENT_FUNCTION_VALUE (objfile) = valu;
1847 /* Stack must be empty now. */
1848 if (context_stack_depth != 0)
1849 complain (&lbrac_unmatched_complaint, (char *) symnum);
1850 new = push_context (0, valu);
1852 SYMBOL_CLASS (sym) = LOC_BLOCK;
1853 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1854 if (dn_bufp->dfunc.global)
1855 add_symbol_to_list (sym, &global_symbols);
1857 add_symbol_to_list (sym, &file_symbols);
1860 /* Search forward to the next scope beginning. */
1861 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1863 dn_bufp = hpread_get_lntt (++index, objfile);
1864 if (dn_bufp->dblock.extension)
1867 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1869 dn_bufp->dbegin.address,
1871 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1872 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1875 case DNTT_TYPE_BEGIN:
1876 /* Begin a new scope. */
1877 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1879 dn_bufp->dbegin.address,
1881 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1882 valu += offset; /* Relocate for dynamic loading */
1883 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1884 new = push_context (desc, valu);
1889 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1891 dn_bufp->dend.address + 1,
1893 switch (dn_bufp->dend.endkind)
1895 case DNTT_TYPE_MODULE:
1896 /* Ending a module ends the symbol table for that module. */
1897 valu = text_offset + text_size + offset;
1898 (void) end_symtab (valu, 0, 0, objfile, 0);
1901 case DNTT_TYPE_FUNCTION:
1902 /* Ending a function, well, ends the function's scope. */
1903 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1905 valu = dn_temp->dfunc.hiaddr + offset;
1906 new = pop_context ();
1907 /* Make a block for the local symbols within. */
1908 finish_block (new->name, &local_symbols, new->old_blocks,
1909 new->start_addr, valu, objfile);
1910 WITHIN_FUNCTION (objfile) = 0;
1912 case DNTT_TYPE_BEGIN:
1913 /* Just ending a local scope. */
1914 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1915 /* Why in the hell is this needed? */
1916 valu += offset + 9; /* Relocate for dynamic loading */
1917 new = pop_context ();
1918 desc = dn_bufp->dend.beginscope.dnttp.index;
1919 if (desc != new->depth)
1920 complain (&lbrac_mismatch_complaint, (char *) symnum);
1921 /* Make a block for the local symbols within. */
1922 finish_block (new->name, &local_symbols, new->old_blocks,
1923 new->start_addr, valu, objfile);
1924 local_symbols = new->locals;
1928 case DNTT_TYPE_LABEL:
1929 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1931 case DNTT_TYPE_FPARAM:
1932 /* Function parameters. */
1933 if (dn_bufp->dfparam.regparam)
1934 SYMBOL_CLASS (sym) = LOC_REGISTER;
1936 SYMBOL_CLASS (sym) = LOC_LOCAL;
1937 if (dn_bufp->dfparam.copyparam)
1939 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1940 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1942 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1946 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1947 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1948 add_symbol_to_list (sym, &local_symbols);
1950 case DNTT_TYPE_SVAR:
1951 /* Static variables. */
1952 SYMBOL_CLASS (sym) = LOC_STATIC;
1953 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1954 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1955 if (dn_bufp->dsvar.global)
1956 add_symbol_to_list (sym, &global_symbols);
1957 else if (WITHIN_FUNCTION (objfile))
1958 add_symbol_to_list (sym, &local_symbols);
1960 add_symbol_to_list (sym, &file_symbols);
1962 case DNTT_TYPE_DVAR:
1963 /* Dynamic variables. */
1964 if (dn_bufp->ddvar.regvar)
1965 SYMBOL_CLASS (sym) = LOC_REGISTER;
1967 SYMBOL_CLASS (sym) = LOC_LOCAL;
1968 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1969 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1971 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1973 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1974 if (dn_bufp->ddvar.global)
1975 add_symbol_to_list (sym, &global_symbols);
1976 else if (WITHIN_FUNCTION (objfile))
1977 add_symbol_to_list (sym, &local_symbols);
1979 add_symbol_to_list (sym, &file_symbols);
1981 case DNTT_TYPE_CONST:
1982 /* A constant (pascal?). */
1983 SYMBOL_CLASS (sym) = LOC_CONST;
1984 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1985 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1986 if (dn_bufp->dconst.global)
1987 add_symbol_to_list (sym, &global_symbols);
1988 else if (WITHIN_FUNCTION (objfile))
1989 add_symbol_to_list (sym, &local_symbols);
1991 add_symbol_to_list (sym, &file_symbols);
1993 case DNTT_TYPE_TYPEDEF:
1994 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1995 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1996 if (dn_bufp->dtype.global)
1997 add_symbol_to_list (sym, &global_symbols);
1998 else if (WITHIN_FUNCTION (objfile))
1999 add_symbol_to_list (sym, &local_symbols);
2001 add_symbol_to_list (sym, &file_symbols);
2003 case DNTT_TYPE_TAGDEF:
2004 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2005 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2006 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2007 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2008 if (dn_bufp->dtype.global)
2009 add_symbol_to_list (sym, &global_symbols);
2010 else if (WITHIN_FUNCTION (objfile))
2011 add_symbol_to_list (sym, &local_symbols);
2013 add_symbol_to_list (sym, &file_symbols);
2015 case DNTT_TYPE_POINTER:
2016 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2017 (dn_bufp->dptr.pointsto,
2019 add_symbol_to_list (sym, &file_symbols);
2021 case DNTT_TYPE_ENUM:
2022 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2023 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2024 add_symbol_to_list (sym, &file_symbols);
2026 case DNTT_TYPE_MEMENUM:
2029 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2030 add_symbol_to_list (sym, &file_symbols);
2032 case DNTT_TYPE_SUBRANGE:
2033 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2035 add_symbol_to_list (sym, &file_symbols);
2037 case DNTT_TYPE_ARRAY:
2038 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2039 add_symbol_to_list (sym, &file_symbols);
2041 case DNTT_TYPE_STRUCT:
2042 case DNTT_TYPE_UNION:
2043 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2044 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2045 add_symbol_to_list (sym, &file_symbols);