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"
37 /* Private information attached to an objfile which we use to find
38 and internalize the HP C debug symbols within that objfile. */
40 struct hpread_symfile_info
42 /* The contents of each of the debug sections (there are 4 of them). */
48 /* We keep the size of the $VT$ section for range checking. */
51 /* Some routines still need to know the number of symbols in the
52 main debug sections ($LNTT$ and $GNTT$). */
53 unsigned int lntt_symcount;
54 unsigned int gntt_symcount;
56 /* To keep track of all the types we've processed. */
57 struct type **type_vector;
58 int type_vector_length;
60 /* Keeps track of the beginning of a range of source lines. */
63 /* Some state variables we'll need. */
66 /* Keep track of the current function's address. We may need to look
67 up something based on this address. */
68 unsigned int current_function_value;
71 /* Accessor macros to get at the fields. */
72 #define HPUX_SYMFILE_INFO(o) \
73 ((struct hpread_symfile_info *)((o)->sym_private))
74 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
75 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
76 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
77 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
78 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
79 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
80 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
81 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
82 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
83 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
84 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
85 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
87 /* Given the native debug symbol SYM, set NAMEP to the name associated
88 with the debug symbol. Note we may be called with a debug symbol which
89 has no associated name, in that case we return an empty string.
91 Also note we "know" that the name for any symbol is always in the
92 same place. Hence we don't have to conditionalize on the symbol type. */
93 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
94 if (! hpread_has_name ((SYM)->dblock.kind)) \
96 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
98 complain (&string_table_offset_complaint, (char *) symnum); \
102 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
104 /* We put a pointer to this structure in the read_symtab_private field
109 /* The offset within the file symbol table of first local symbol for
114 /* Length (in bytes) of the section of the symbol table devoted to
115 this file's symbols (actually, the section bracketed may contain
116 more than just this file's symbols). If ldsymlen is 0, the only
117 reason for this thing's existence is the dependency list.
118 Nothing else will happen when it is read in. */
123 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
124 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
125 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
127 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
128 /* Nonzero means give verbose info on gdb action. */
129 extern int info_verbose;
131 /* Complaints about the symbols we have encountered. */
132 extern struct complaint string_table_offset_complaint;
133 extern struct complaint lbrac_unmatched_complaint;
134 extern struct complaint lbrac_mismatch_complaint;
137 void hpread_symfile_init PARAMS ((struct objfile *));
139 static struct type *hpread_alloc_type
140 PARAMS ((dnttpointer, struct objfile *));
142 static struct type **hpread_lookup_type
143 PARAMS ((dnttpointer, struct objfile *));
145 static struct type *hpread_read_enum_type
146 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
148 static struct type *hpread_read_set_type
149 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
151 static struct type *hpread_read_subrange_type
152 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
154 static struct type *hpread_read_struct_type
155 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
157 void hpread_build_psymtabs
158 PARAMS ((struct objfile *, struct section_offsets *, int));
160 void hpread_symfile_finish PARAMS ((struct objfile *));
162 static struct partial_symtab *hpread_start_psymtab
163 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
164 struct partial_symbol **, struct partial_symbol **));
166 static struct partial_symtab *hpread_end_psymtab
167 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
168 struct partial_symtab **, int));
170 static struct symtab *hpread_expand_symtab
171 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
172 struct section_offsets *, char *));
174 static void hpread_process_one_debug_symbol
175 PARAMS ((union dnttentry *, char *, struct section_offsets *,
176 struct objfile *, CORE_ADDR, int, char *, int));
178 static sltpointer hpread_record_lines
179 PARAMS ((struct subfile *, sltpointer, sltpointer,
180 struct objfile *, CORE_ADDR));
182 static struct type *hpread_read_function_type
183 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
185 static struct type * hpread_type_lookup
186 PARAMS ((dnttpointer, struct objfile *));
188 static unsigned long hpread_get_depth
189 PARAMS ((sltpointer, struct objfile *));
191 static unsigned long hpread_get_line
192 PARAMS ((sltpointer, struct objfile *));
194 static CORE_ADDR hpread_get_location
195 PARAMS ((sltpointer, struct objfile *));
197 static int hpread_type_translate PARAMS ((dnttpointer));
198 static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
199 static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
200 static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
201 static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
202 static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
203 static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
204 static int hpread_has_name PARAMS ((enum dntt_entry_type));
207 /* Initialization for reading native HP C debug symbols from OBJFILE.
209 It's only purpose in life is to set up the symbol reader's private
210 per-objfile data structures, and read in the raw contents of the debug
211 sections (attaching pointers to the debug info into the private data
214 Since BFD doesn't know how to read debug symbols in a format-independent
215 way (and may never do so...), we have to do it ourselves. Note we may
216 be called on a file without native HP C debugging symbols.
217 FIXME, there should be a cleaner peephole into the BFD environment here. */
220 hpread_symfile_init (objfile)
221 struct objfile *objfile;
223 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
225 /* Allocate struct to keep track of the symfile */
226 objfile->sym_private = (PTR)
227 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
228 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
230 /* We haven't read in any types yet. */
231 TYPE_VECTOR (objfile) = 0;
233 /* Read in data from the $GNTT$ subspace. */
234 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
239 = obstack_alloc (&objfile->symbol_obstack,
240 bfd_section_size (objfile->obfd, gntt_section));
242 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
243 0, bfd_section_size (objfile->obfd, gntt_section));
245 GNTT_SYMCOUNT (objfile)
246 = bfd_section_size (objfile->obfd, gntt_section)
247 / sizeof (struct dntt_type_block);
249 /* Read in data from the $LNTT$ subspace. Also keep track of the number
251 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
256 = obstack_alloc (&objfile->symbol_obstack,
257 bfd_section_size (objfile->obfd, lntt_section));
259 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
260 0, bfd_section_size (objfile->obfd, lntt_section));
262 LNTT_SYMCOUNT (objfile)
263 = bfd_section_size (objfile->obfd, lntt_section)
264 / sizeof (struct dntt_type_block);
266 /* Read in data from the $SLT$ subspace. $SLT$ contains information
267 on source line numbers. */
268 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
273 obstack_alloc (&objfile->symbol_obstack,
274 bfd_section_size (objfile->obfd, slt_section));
276 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
277 0, bfd_section_size (objfile->obfd, slt_section));
279 /* Read in data from the $VT$ subspace. $VT$ contains things like
280 names and constants. Keep track of the number of symbols in the VT. */
281 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
285 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
288 (char *) obstack_alloc (&objfile->symbol_obstack,
291 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
292 0, VT_SIZE (objfile));
295 /* Scan and build partial symbols for a symbol file.
297 The minimal symbol table (either SOM or HP a.out) has already been
298 read in; all we need to do is setup partial symbols based on the
299 native debugging information.
301 We assume hpread_symfile_init has been called to initialize the
302 symbol reader's private data structures.
304 SECTION_OFFSETS contains offsets relative to which the symbols in the
305 various sections are (depending where the sections were actually loaded).
306 MAINLINE is true if we are reading the main symbol
307 table (as opposed to a shared lib or dynamically loaded file). */
310 hpread_build_psymtabs (objfile, section_offsets, mainline)
311 struct objfile *objfile;
312 struct section_offsets *section_offsets;
316 int past_first_source_file = 0;
317 struct cleanup *old_chain;
319 int hp_symnum, symcount, i;
321 union dnttentry *dn_bufp;
327 /* Current partial symtab */
328 struct partial_symtab *pst;
330 /* List of current psymtab's include files */
331 char **psymtab_include_list;
332 int includes_allocated;
335 /* Index within current psymtab dependency list */
336 struct partial_symtab **dependency_list;
337 int dependencies_used, dependencies_allocated;
339 /* Just in case the stabs reader left turds lying around. */
341 make_cleanup (really_free_pendings, 0);
343 pst = (struct partial_symtab *) 0;
345 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
346 a number of problems with cross compilation and creating useless holes
347 in the stack when we have to allocate new entries. FIXME. */
349 includes_allocated = 30;
351 psymtab_include_list = (char **) alloca (includes_allocated *
354 dependencies_allocated = 30;
355 dependencies_used = 0;
357 (struct partial_symtab **) alloca (dependencies_allocated *
358 sizeof (struct partial_symtab *));
360 old_chain = make_cleanup (free_objfile, objfile);
362 last_source_file = 0;
364 /* Make two passes, one ofr the GNTT symbols, the other for the
366 for (i = 0; i < 1; i++)
368 int within_function = 0;
371 symcount = GNTT_SYMCOUNT (objfile);
373 symcount = LNTT_SYMCOUNT (objfile);
375 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
379 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
381 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
383 if (dn_bufp->dblock.extension)
386 /* Only handle things which are necessary for minimal symbols.
387 everything else is ignored. */
388 switch (dn_bufp->dblock.kind)
390 case DNTT_TYPE_SRCFILE:
392 /* A source file of some kind. Note this may simply
393 be an included file. */
394 SET_NAMESTRING (dn_bufp, &namestring, objfile);
396 /* Check if this is the source file we are already working
398 if (pst && !strcmp (namestring, pst->filename))
401 /* Check if this is an include file, if so check if we have
402 already seen it. Add it to the include list */
403 p = strrchr (namestring, '.');
404 if (!strcmp (p, ".h"))
409 for (j = 0; j < includes_used; j++)
410 if (!strcmp (namestring, psymtab_include_list[j]))
418 /* Add it to the list of includes seen so far and
419 allocate more include space if necessary. */
420 psymtab_include_list[includes_used++] = namestring;
421 if (includes_used >= includes_allocated)
423 char **orig = psymtab_include_list;
425 psymtab_include_list = (char **)
426 alloca ((includes_allocated *= 2) *
428 memcpy ((PTR) psymtab_include_list, (PTR) orig,
429 includes_used * sizeof (char *));
439 pst->filename = (char *)
440 obstack_alloc (&pst->objfile->psymbol_obstack,
441 strlen (namestring) + 1);
442 strcpy (pst->filename, namestring);
449 /* This is a bonafide new source file.
450 End the current partial symtab and start a new one. */
452 if (pst && past_first_source_file)
454 hpread_end_psymtab (pst, psymtab_include_list,
457 * sizeof (struct dntt_type_block)),
459 dependency_list, dependencies_used);
460 pst = (struct partial_symtab *) 0;
462 dependencies_used = 0;
465 past_first_source_file = 1;
467 valu = hpread_get_textlow (i, hp_symnum, objfile);
468 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
469 pst = hpread_start_psymtab (objfile, section_offsets,
472 * sizeof (struct dntt_type_block)),
473 objfile->global_psymbols.next,
474 objfile->static_psymbols.next);
480 case DNTT_TYPE_MODULE:
481 /* A source file. It's still unclear to me what the
482 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
483 is supposed to be. */
484 SET_NAMESTRING (dn_bufp, &namestring, objfile);
485 valu = hpread_get_textlow (i, hp_symnum, objfile);
486 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
489 pst = hpread_start_psymtab (objfile, section_offsets,
492 * sizeof (struct dntt_type_block)),
493 objfile->global_psymbols.next,
494 objfile->static_psymbols.next);
499 case DNTT_TYPE_FUNCTION:
500 case DNTT_TYPE_ENTRY:
501 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
502 a secondary entry point. */
503 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
507 valu = dn_bufp->dfunc.lowaddr +
508 ANOFFSET (section_offsets, SECT_OFF_TEXT);
509 SET_NAMESTRING (dn_bufp, &namestring, objfile);
510 add_psymbol_to_list (namestring, strlen (namestring),
511 VAR_NAMESPACE, LOC_BLOCK,
512 &objfile->static_psymbols, valu,
513 0, language_unknown, objfile);
516 case DNTT_TYPE_BEGIN:
518 /* Scope block begin/end. We only care about function
519 and file blocks right now. */
520 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
522 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
524 * sizeof (struct dntt_type_block)),
526 dependency_list, dependencies_used);
527 pst = (struct partial_symtab *) 0;
529 dependencies_used = 0;
532 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
537 case DNTT_TYPE_TYPEDEF:
538 case DNTT_TYPE_TAGDEF:
540 /* Variables, typedefs an the like. */
541 enum address_class storage;
542 namespace_enum namespace;
544 /* Don't add locals to the partial symbol table. */
546 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
547 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
550 /* TAGDEFs go into the structure namespace. */
551 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
552 namespace = STRUCT_NAMESPACE;
554 namespace = VAR_NAMESPACE;
556 /* What kind of "storage" does this use? */
557 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
558 storage = LOC_STATIC;
559 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
560 && dn_bufp->ddvar.regvar)
561 storage = LOC_REGISTER;
562 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
567 SET_NAMESTRING (dn_bufp, &namestring, objfile);
570 pst = hpread_start_psymtab (objfile, section_offsets,
573 * sizeof (struct dntt_type_block)),
574 objfile->global_psymbols.next,
575 objfile->static_psymbols.next);
577 if (dn_bufp->dsvar.global)
579 add_psymbol_to_list (namestring, strlen (namestring),
581 &objfile->global_psymbols,
582 dn_bufp->dsvar.location,
583 0, language_unknown, objfile);
587 add_psymbol_to_list (namestring, strlen (namestring),
589 &objfile->static_psymbols,
590 dn_bufp->dsvar.location,
591 0, language_unknown, objfile);
595 case DNTT_TYPE_MEMENUM:
596 case DNTT_TYPE_CONST:
597 /* Constants and members of enumerated types. */
598 SET_NAMESTRING (dn_bufp, &namestring, objfile);
601 pst = hpread_start_psymtab (objfile, section_offsets,
604 * sizeof (struct dntt_type_block)),
605 objfile->global_psymbols.next,
606 objfile->static_psymbols.next);
608 add_psymbol_to_list (namestring, strlen (namestring),
609 VAR_NAMESPACE, LOC_CONST,
610 &objfile->static_psymbols, 0,
611 0, language_unknown, objfile);
619 /* End any pending partial symbol table. */
622 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
623 hp_symnum * sizeof (struct dntt_type_block),
624 0, dependency_list, dependencies_used);
627 discard_cleanups (old_chain);
630 /* Perform any local cleanups required when we are done with a particular
631 objfile. I.E, we are in the process of discarding all symbol information
632 for an objfile, freeing up all memory held for it, and unlinking the
633 objfile struct from the global list of known objfiles. */
636 hpread_symfile_finish (objfile)
637 struct objfile *objfile;
639 if (objfile->sym_private != NULL)
641 mfree (objfile->md, objfile->sym_private);
646 /* The remaining functions are all for internal use only. */
648 /* Various small functions to get entries in the debug symbol sections. */
650 static union dnttentry *
651 hpread_get_lntt (index, objfile)
653 struct objfile *objfile;
655 return (union dnttentry *)
656 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
659 static union dnttentry *
660 hpread_get_gntt (index, objfile)
662 struct objfile *objfile;
664 return (union dnttentry *)
665 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
668 static union sltentry *
669 hpread_get_slt (index, objfile)
671 struct objfile *objfile;
673 return (union sltentry *)&(SLT (objfile)[index * sizeof (union sltentry)]);
676 /* Get the low address associated with some symbol (typically the start
677 of a particular source file or module). Since that information is not
678 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
679 the existance of DNTT_TYPE_FUNCTION symbols. */
682 hpread_get_textlow (global, index, objfile)
685 struct objfile *objfile;
687 union dnttentry *dn_bufp;
688 struct minimal_symbol *msymbol;
690 /* Look for a DNTT_TYPE_FUNCTION symbol. */
694 dn_bufp = hpread_get_gntt (index++, objfile);
696 dn_bufp = hpread_get_lntt (index++, objfile);
697 } while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
698 && dn_bufp->dblock.kind != DNTT_TYPE_END);
700 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
701 might happen when a sourcefile has no functions. */
702 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
705 /* The minimal symbols are typically more accurate for some reason. */
706 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
709 return SYMBOL_VALUE_ADDRESS (msymbol);
711 return dn_bufp->dfunc.lowaddr;
714 /* Get the nesting depth for the source line identified by INDEX. */
717 hpread_get_depth (index, objfile)
719 struct objfile *objfile;
721 union sltentry *sl_bufp;
723 sl_bufp = hpread_get_slt (index, objfile);
724 return sl_bufp->sspec.backptr.dnttp.index;
727 /* Get the source line number the the line identified by INDEX. */
730 hpread_get_line (index, objfile)
732 struct objfile *objfile;
734 union sltentry *sl_bufp;
736 sl_bufp = hpread_get_slt (index, objfile);
737 return sl_bufp->snorm.line;
741 hpread_get_location (index, objfile)
743 struct objfile *objfile;
745 union sltentry *sl_bufp;
748 /* code location of special sltentrys is determined from context */
749 sl_bufp = hpread_get_slt (index, objfile);
751 if (sl_bufp->snorm.sltdesc == SLT_END)
753 /* find previous normal sltentry and get address */
754 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
755 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
756 sl_bufp = hpread_get_slt (index - i, objfile);
757 return sl_bufp->snorm.address;
760 /* find next normal sltentry and get address */
761 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
762 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
763 sl_bufp = hpread_get_slt (index + i, objfile);
764 return sl_bufp->snorm.address;
768 /* Return 1 if an HP debug symbol of type KIND has a name associated with
769 it, else return 0. */
772 hpread_has_name (kind)
773 enum dntt_entry_type kind;
777 case DNTT_TYPE_SRCFILE:
778 case DNTT_TYPE_MODULE:
779 case DNTT_TYPE_FUNCTION:
780 case DNTT_TYPE_ENTRY:
781 case DNTT_TYPE_IMPORT:
782 case DNTT_TYPE_LABEL:
783 case DNTT_TYPE_FPARAM:
786 case DNTT_TYPE_CONST:
787 case DNTT_TYPE_TYPEDEF:
788 case DNTT_TYPE_TAGDEF:
789 case DNTT_TYPE_MEMENUM:
790 case DNTT_TYPE_FIELD:
794 case DNTT_TYPE_BEGIN:
797 case DNTT_TYPE_COMMON:
798 case DNTT_TYPE_POINTER:
801 case DNTT_TYPE_SUBRANGE:
802 case DNTT_TYPE_ARRAY:
803 case DNTT_TYPE_STRUCT:
804 case DNTT_TYPE_UNION:
805 case DNTT_TYPE_VARIANT:
807 case DNTT_TYPE_FUNCTYPE:
808 case DNTT_TYPE_COBSTRUCT:
810 case DNTT_TYPE_MACRO:
816 /* Allocate and partially fill a partial symtab. It will be
817 completely filled at the end of the symbol list.
819 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
820 is the address relative to which its symbols are (incremental) or 0
823 static struct partial_symtab *
824 hpread_start_psymtab (objfile, section_offsets,
825 filename, textlow, ldsymoff, global_syms, static_syms)
826 struct objfile *objfile;
827 struct section_offsets *section_offsets;
831 struct partial_symbol **global_syms;
832 struct partial_symbol **static_syms;
834 struct partial_symtab *result =
835 start_psymtab_common (objfile, section_offsets,
836 filename, textlow, global_syms, static_syms);
838 result->read_symtab_private = (char *)
839 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
840 LDSYMOFF (result) = ldsymoff;
841 result->read_symtab = hpread_psymtab_to_symtab;
847 /* Close off the current usage of PST.
848 Returns PST or NULL if the partial symtab was empty and thrown away.
850 FIXME: List variables and peculiarities of same. */
852 static struct partial_symtab *
853 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
854 capping_text, dependency_list, number_dependencies)
855 struct partial_symtab *pst;
858 int capping_symbol_offset;
859 CORE_ADDR capping_text;
860 struct partial_symtab **dependency_list;
861 int number_dependencies;
864 struct objfile *objfile = pst -> objfile;
866 if (capping_symbol_offset != -1)
867 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
868 pst->texthigh = capping_text;
871 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
873 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
875 pst->number_of_dependencies = number_dependencies;
876 if (number_dependencies)
878 pst->dependencies = (struct partial_symtab **)
879 obstack_alloc (&objfile->psymbol_obstack,
880 number_dependencies * sizeof (struct partial_symtab *));
881 memcpy (pst->dependencies, dependency_list,
882 number_dependencies * sizeof (struct partial_symtab *));
885 pst->dependencies = 0;
887 for (i = 0; i < num_includes; i++)
889 struct partial_symtab *subpst =
890 allocate_psymtab (include_list[i], objfile);
892 subpst->section_offsets = pst->section_offsets;
893 subpst->read_symtab_private =
894 (char *) obstack_alloc (&objfile->psymbol_obstack,
895 sizeof (struct symloc));
899 subpst->texthigh = 0;
901 /* We could save slight bits of space by only making one of these,
902 shared by the entire set of include files. FIXME-someday. */
903 subpst->dependencies = (struct partial_symtab **)
904 obstack_alloc (&objfile->psymbol_obstack,
905 sizeof (struct partial_symtab *));
906 subpst->dependencies[0] = pst;
907 subpst->number_of_dependencies = 1;
909 subpst->globals_offset =
910 subpst->n_global_syms =
911 subpst->statics_offset =
912 subpst->n_static_syms = 0;
916 subpst->read_symtab = pst->read_symtab;
919 sort_pst_symbols (pst);
921 /* If there is already a psymtab or symtab for a file of this name, remove it.
922 (If there is a symtab, more drastic things also happen.)
923 This happens in VxWorks. */
924 free_named_symtabs (pst->filename);
926 if (num_includes == 0
927 && number_dependencies == 0
928 && pst->n_global_syms == 0
929 && pst->n_static_syms == 0)
931 /* Throw away this psymtab, it's empty. We can't deallocate it, since
932 it is on the obstack, but we can forget to chain it on the list. */
933 /* Empty psymtabs happen as a result of header files which don't have
934 any symbols in them. There can be a lot of them. But this check
935 is wrong, in that a psymtab with N_SLINE entries but nothing else
936 is not empty, but we don't realize that. Fixing that without slowing
937 things down might be tricky. */
938 struct partial_symtab *prev_pst;
940 /* First, snip it out of the psymtab chain */
942 if (pst->objfile->psymtabs == pst)
943 pst->objfile->psymtabs = pst->next;
945 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
946 if (prev_pst->next == pst)
947 prev_pst->next = pst->next;
949 /* Next, put it on a free list for recycling */
951 pst->next = pst->objfile->free_psymtabs;
952 pst->objfile->free_psymtabs = pst;
954 /* Indicate that psymtab was thrown away. */
955 pst = (struct partial_symtab *)NULL;
960 /* Do the dirty work of reading in the full symbol from a partial symbol
964 hpread_psymtab_to_symtab_1 (pst)
965 struct partial_symtab *pst;
967 struct cleanup *old_chain;
970 /* Get out quick if passed junk. */
974 /* Complain if we've already read in this symbol table. */
977 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
982 /* Read in all partial symtabs on which this one is dependent */
983 for (i = 0; i < pst->number_of_dependencies; i++)
984 if (!pst->dependencies[i]->readin)
986 /* Inform about additional files that need to be read in. */
989 fputs_filtered (" ", stdout);
991 fputs_filtered ("and ", stdout);
993 printf_filtered ("%s...", pst->dependencies[i]->filename);
994 wrap_here (""); /* Flush output */
997 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
1000 /* If it's real... */
1003 /* Init stuff necessary for reading in symbols */
1005 old_chain = make_cleanup (really_free_pendings, 0);
1008 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1009 pst->textlow, pst->texthigh - pst->textlow,
1010 pst->section_offsets, pst->filename);
1011 sort_symtab_syms (pst->symtab);
1013 do_cleanups (old_chain);
1019 /* Read in all of the symbols for a given psymtab for real.
1020 Be verbose about it if the user wants that. */
1023 hpread_psymtab_to_symtab (pst)
1024 struct partial_symtab *pst;
1026 /* Get out quick if given junk. */
1033 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1038 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1040 /* Print the message now, before reading the string table,
1041 to avoid disconcerting pauses. */
1044 printf_filtered ("Reading in symbols for %s...", pst->filename);
1048 hpread_psymtab_to_symtab_1 (pst);
1050 /* Match with global symbols. This only needs to be done once,
1051 after all of the symtabs and dependencies have been read in. */
1052 scan_file_globals (pst->objfile);
1054 /* Finish up the debug error message. */
1056 printf_filtered ("done.\n");
1059 /* Read in a defined section of a specific object file's symbols.
1061 DESC is the file descriptor for the file, positioned at the
1062 beginning of the symtab
1063 SYM_OFFSET is the offset within the file of
1064 the beginning of the symbols we want to read
1065 SYM_SIZE is the size of the symbol info to read in.
1066 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1067 TEXT_SIZE is the size of the text segment read in.
1068 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1070 static struct symtab *
1071 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1072 section_offsets, filename)
1073 struct objfile *objfile;
1076 CORE_ADDR text_offset;
1078 struct section_offsets *section_offsets;
1082 union dnttentry *dn_bufp;
1083 unsigned max_symnum;
1085 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1087 current_objfile = objfile;
1090 last_source_file = 0;
1092 dn_bufp = hpread_get_lntt (sym_index, objfile);
1093 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1094 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1095 start_symtab ("globals", NULL, 0);
1097 max_symnum = sym_size / sizeof (struct dntt_type_block);
1099 /* Read in and process each debug symbol within the specified range. */
1101 symnum < max_symnum;
1104 QUIT; /* Allow this to be interruptable */
1105 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1107 if (dn_bufp->dblock.extension)
1110 /* Yow! We call SET_NAMESTRING on things without names! */
1111 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1113 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1114 objfile, text_offset, text_size,
1115 filename, symnum + sym_index);
1118 current_objfile = NULL;
1120 return end_symtab (text_offset + text_size, objfile, 0);
1124 /* Convert basic types from HP debug format into GDB internal format. */
1127 hpread_type_translate (typep)
1130 if (!typep.dntti.immediate)
1133 switch (typep.dntti.type)
1135 case HP_TYPE_BOOLEAN:
1136 case HP_TYPE_BOOLEAN_S300_COMPAT:
1137 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1139 /* Ugh. No way to distinguish between signed and unsigned chars. */
1141 case HP_TYPE_WIDE_CHAR:
1144 if (typep.dntti.bitlength <= 8)
1146 if (typep.dntti.bitlength <= 16)
1148 if (typep.dntti.bitlength <= 32)
1150 return FT_LONG_LONG;
1153 case HP_TYPE_UNSIGNED_LONG:
1154 if (typep.dntti.bitlength <= 8)
1155 return FT_UNSIGNED_CHAR;
1156 if (typep.dntti.bitlength <= 16)
1157 return FT_UNSIGNED_SHORT;
1158 if (typep.dntti.bitlength <= 32)
1159 return FT_UNSIGNED_LONG;
1160 return FT_UNSIGNED_LONG_LONG;
1161 case HP_TYPE_UNSIGNED_INT:
1162 if (typep.dntti.bitlength <= 8)
1163 return FT_UNSIGNED_CHAR;
1164 if (typep.dntti.bitlength <= 16)
1165 return FT_UNSIGNED_SHORT;
1166 if (typep.dntti.bitlength <= 32)
1167 return FT_UNSIGNED_INTEGER;
1168 return FT_UNSIGNED_LONG_LONG;
1170 case HP_TYPE_REAL_3000:
1171 case HP_TYPE_DOUBLE:
1172 if (typep.dntti.bitlength == 64)
1173 return FT_DBL_PREC_FLOAT;
1174 if (typep.dntti.bitlength == 128)
1175 return FT_EXT_PREC_FLOAT;
1177 case HP_TYPE_COMPLEX:
1178 case HP_TYPE_COMPLEXS3000:
1179 if (typep.dntti.bitlength == 128)
1180 return FT_DBL_PREC_COMPLEX;
1181 if (typep.dntti.bitlength == 192)
1182 return FT_EXT_PREC_COMPLEX;
1184 case HP_TYPE_STRING200:
1185 case HP_TYPE_LONGSTRING200:
1186 case HP_TYPE_FTN_STRING_SPEC:
1187 case HP_TYPE_MOD_STRING_SPEC:
1188 case HP_TYPE_MOD_STRING_3000:
1189 case HP_TYPE_FTN_STRING_S300_COMPAT:
1190 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1197 /* Return the type associated with the index found in HP_TYPE. */
1199 static struct type **
1200 hpread_lookup_type (hp_type, objfile)
1201 dnttpointer hp_type;
1202 struct objfile *objfile;
1205 int index = hp_type.dnttp.index;
1207 if (hp_type.dntti.immediate)
1210 if (index < LNTT_SYMCOUNT (objfile))
1212 if (index >= TYPE_VECTOR_LENGTH (objfile))
1214 old_len = TYPE_VECTOR_LENGTH (objfile);
1217 TYPE_VECTOR_LENGTH (objfile) = 100;
1218 TYPE_VECTOR (objfile) = (struct type **)
1219 xmmalloc (objfile -> md,
1220 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1222 while (index >= TYPE_VECTOR_LENGTH (objfile))
1223 TYPE_VECTOR_LENGTH (objfile) *= 2;
1224 TYPE_VECTOR (objfile) = (struct type **)
1225 xmrealloc (objfile -> md,
1226 (char *) TYPE_VECTOR (objfile),
1227 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1228 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1229 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1230 sizeof (struct type *));
1232 return &TYPE_VECTOR (objfile)[index];
1238 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1239 Note we'll just return the address of a GDB internal type if we already
1240 have it lying around. */
1242 static struct type *
1243 hpread_alloc_type (hp_type, objfile)
1244 dnttpointer hp_type;
1245 struct objfile *objfile;
1247 struct type **type_addr;
1249 type_addr = hpread_lookup_type (hp_type, objfile);
1250 if (*type_addr == 0)
1251 *type_addr = alloc_type (objfile);
1253 TYPE_CPLUS_SPECIFIC (*type_addr)
1254 = (struct cplus_struct_type *) &cplus_struct_default;
1258 /* Read a native enumerated type and return it in GDB internal form. */
1260 static struct type *
1261 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1262 dnttpointer hp_type;
1263 union dnttentry *dn_bufp;
1264 struct objfile *objfile;
1267 struct pending **symlist, *osyms, *syms;
1268 int o_nsyms, nsyms = 0;
1270 union dnttentry *memp;
1275 type = hpread_alloc_type (hp_type, objfile);
1276 TYPE_LENGTH (type) = 4;
1278 symlist = &file_symbols;
1280 o_nsyms = osyms ? osyms->nsyms : 0;
1282 /* Get a name for each member and add it to our list of members. */
1283 mem = dn_bufp->denum.firstmem;
1284 while (mem.dnttp.extension && mem.word != DNTTNIL)
1286 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1288 name = VT (objfile) + memp->dmember.name;
1289 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1290 sizeof (struct symbol));
1291 memset (sym, 0, sizeof (struct symbol));
1292 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1293 &objfile->symbol_obstack);
1294 SYMBOL_CLASS (sym) = LOC_CONST;
1295 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1296 SYMBOL_VALUE (sym) = memp->dmember.value;
1297 add_symbol_to_list (sym, symlist);
1299 mem = memp->dmember.nextmem;
1302 /* Now that we know more about the enum, fill in more info. */
1303 TYPE_CODE (type) = TYPE_CODE_ENUM;
1304 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1305 TYPE_NFIELDS (type) = nsyms;
1306 TYPE_FIELDS (type) = (struct field *)
1307 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1309 /* Find the symbols for the members and put them into the type.
1310 The symbols can be found in the symlist that we put them on
1311 to cause them to be defined. osyms contains the old value
1312 of that symlist; everything up to there was defined by us.
1314 Note that we preserve the order of the enum constants, so
1315 that in something like "enum {FOO, LAST_THING=FOO}" we print
1316 FOO, not LAST_THING. */
1317 for (syms = *symlist, n = 0; syms; syms = syms->next)
1322 for (; j < syms->nsyms; j++, n++)
1324 struct symbol *xsym = syms->symbol[j];
1325 SYMBOL_TYPE (xsym) = type;
1326 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1327 TYPE_FIELD_VALUE (type, n) = 0;
1328 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1329 TYPE_FIELD_BITSIZE (type, n) = 0;
1338 /* Read and internalize a native function debug symbol. */
1340 static struct type *
1341 hpread_read_function_type (hp_type, dn_bufp, objfile)
1342 dnttpointer hp_type;
1343 union dnttentry *dn_bufp;
1344 struct objfile *objfile;
1346 struct type *type, *type1;
1347 struct pending **symlist, *osyms, *syms;
1348 int o_nsyms, nsyms = 0;
1350 union dnttentry *paramp;
1355 param = dn_bufp->dfunc.firstparam;
1357 /* See if we've already read in this type. */
1358 type = hpread_alloc_type (hp_type, objfile);
1359 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1362 /* Nope, so read it in and store it away. */
1363 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1365 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1367 symlist = &local_symbols;
1369 o_nsyms = osyms ? osyms->nsyms : 0;
1371 /* Now examine each parameter noting its type, location, and a
1372 wealth of other information. */
1373 while (param.word && param.word != DNTTNIL)
1375 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1377 param = paramp->dfparam.nextparam;
1380 name = VT (objfile) + paramp->dfparam.name;
1381 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1382 sizeof (struct symbol));
1383 (void) memset (sym, 0, sizeof (struct symbol));
1384 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1385 &objfile->symbol_obstack);
1387 /* Figure out where it lives. */
1388 if (paramp->dfparam.regparam)
1389 SYMBOL_CLASS (sym) = LOC_REGPARM;
1390 else if (paramp->dfparam.indirect)
1391 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1393 SYMBOL_CLASS (sym) = LOC_ARG;
1394 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1395 if (paramp->dfparam.copyparam)
1397 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1398 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1400 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1402 /* This is likely a pass-by-invisible reference parameter,
1403 Hack on the symbol class to make GDB happy. */
1404 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1407 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1410 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1412 /* Add it to the list. */
1413 add_symbol_to_list (sym, symlist);
1416 /* Note how many parameters we found. */
1417 TYPE_NFIELDS (type) = nsyms;
1418 TYPE_FIELDS (type) = (struct field *)
1419 obstack_alloc (&objfile->type_obstack,
1420 sizeof (struct field) * nsyms);
1422 /* Find the symbols for the values and put them into the type.
1423 The symbols can be found in the symlist that we put them on
1424 to cause them to be defined. osyms contains the old value
1425 of that symlist; everything up to there was defined by us. */
1426 /* Note that we preserve the order of the parameters, so
1427 that in something like "enum {FOO, LAST_THING=FOO}" we print
1428 FOO, not LAST_THING. */
1429 for (syms = *symlist, n = 0; syms; syms = syms->next)
1434 for (; j < syms->nsyms; j++, n++)
1436 struct symbol *xsym = syms->symbol[j];
1437 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1438 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1439 TYPE_FIELD_BITPOS (type, n) = n;
1440 TYPE_FIELD_BITSIZE (type, n) = 0;
1448 /* Read in and internalize a structure definition. */
1450 static struct type *
1451 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1452 dnttpointer hp_type;
1453 union dnttentry *dn_bufp;
1454 struct objfile *objfile;
1458 struct nextfield *next;
1463 struct nextfield *list = 0;
1464 struct nextfield *new;
1467 union dnttentry *fieldp;
1469 /* Is it something we've already dealt with? */
1470 type = hpread_alloc_type (hp_type, objfile);
1471 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1472 (TYPE_CODE (type) == TYPE_CODE_UNION))
1475 /* Get the basic type correct. */
1476 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1478 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1479 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1481 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1483 TYPE_CODE (type) = TYPE_CODE_UNION;
1484 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1490 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1492 /* Read in and internalize all the fields. */
1493 field = dn_bufp->dstruct.firstfield;
1494 while (field.word != DNTTNIL && field.dnttp.extension)
1496 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1498 /* Get space to record the next field's data. */
1499 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1503 list->field.name = VT (objfile) + fieldp->dfield.name;
1504 list->field.bitpos = fieldp->dfield.bitoffset;
1505 if (fieldp->dfield.bitlength % 8)
1506 list->field.bitsize = fieldp->dfield.bitlength;
1508 list->field.bitsize = 0;
1510 field = fieldp->dfield.nextfield;
1511 list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
1514 TYPE_NFIELDS (type) = nfields;
1515 TYPE_FIELDS (type) = (struct field *)
1516 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1518 /* Copy the saved-up fields into the field vector. */
1519 for (n = nfields; list; list = list->next)
1522 TYPE_FIELD (type, n) = list->field;
1527 /* Read in and internalize a set debug symbol. */
1529 static struct type *
1530 hpread_read_set_type (hp_type, dn_bufp, objfile)
1531 dnttpointer hp_type;
1532 union dnttentry *dn_bufp;
1533 struct objfile *objfile;
1537 /* See if it's something we've already deal with. */
1538 type = hpread_alloc_type (hp_type, objfile);
1539 if (TYPE_CODE (type) == TYPE_CODE_SET)
1542 /* Nope. Fill in the appropriate fields. */
1543 TYPE_CODE (type) = TYPE_CODE_SET;
1544 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1545 TYPE_NFIELDS (type) = 0;
1546 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1551 /* Read in and internalize an array debug symbol. */
1553 static struct type *
1554 hpread_read_array_type (hp_type, dn_bufp, objfile)
1555 dnttpointer hp_type;
1556 union dnttentry *dn_bufp;
1557 struct objfile *objfile;
1560 union dnttentry save;
1563 /* Why no check here? Because it kept us from properly determining
1564 the size of the array! */
1565 type = hpread_alloc_type (hp_type, objfile);
1567 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1569 /* values are not normalized. */
1570 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1571 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1573 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1575 /* The HP debug format represents char foo[]; as an array with
1576 length 0x7fffffff. Internally GDB wants to represent this
1577 as an array of length zero. */
1578 TYPE_LENGTH (type) = 0;
1581 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1583 TYPE_NFIELDS (type) = 1;
1584 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1587 TYPE_FIELDS (type) = (struct field *)
1588 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1589 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1594 /* Read in and internalize a subrange debug symbol. */
1595 static struct type *
1596 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1597 dnttpointer hp_type;
1598 union dnttentry *dn_bufp;
1599 struct objfile *objfile;
1603 /* Is it something we've already dealt with. */
1604 type = hpread_alloc_type (hp_type, objfile);
1605 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1608 /* Nope, internalize it. */
1609 TYPE_CODE (type) = TYPE_CODE_RANGE;
1610 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1611 TYPE_NFIELDS (type) = 2;
1613 = (struct field *) obstack_alloc (&objfile->type_obstack,
1614 2 * sizeof (struct field));
1616 if (dn_bufp->dsubr.dyn_low)
1617 TYPE_FIELD_BITPOS (type, 0) = 0;
1619 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1621 if (dn_bufp->dsubr.dyn_high)
1622 TYPE_FIELD_BITPOS (type, 1) = -1;
1624 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1625 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1630 static struct type *
1631 hpread_type_lookup (hp_type, objfile)
1632 dnttpointer hp_type;
1633 struct objfile *objfile;
1635 union dnttentry *dn_bufp;
1637 /* First see if it's a simple builtin type. */
1638 if (hp_type.dntti.immediate)
1639 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1641 /* Not a builtin type. We'll have to read it in. */
1642 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1643 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1645 return lookup_fundamental_type (objfile, FT_VOID);
1647 switch (dn_bufp->dblock.kind)
1649 case DNTT_TYPE_SRCFILE:
1650 case DNTT_TYPE_MODULE:
1651 case DNTT_TYPE_FUNCTION:
1652 case DNTT_TYPE_ENTRY:
1653 case DNTT_TYPE_BEGIN:
1655 case DNTT_TYPE_IMPORT:
1656 case DNTT_TYPE_LABEL:
1657 case DNTT_TYPE_WITH:
1658 case DNTT_TYPE_COMMON:
1659 case DNTT_TYPE_FPARAM:
1660 case DNTT_TYPE_SVAR:
1661 case DNTT_TYPE_DVAR:
1662 case DNTT_TYPE_CONST:
1663 /* Opps. Something went very wrong. */
1664 return lookup_fundamental_type (objfile, FT_VOID);
1666 case DNTT_TYPE_TYPEDEF:
1668 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1671 suffix = VT (objfile) + dn_bufp->dtype.name;
1673 TYPE_CPLUS_SPECIFIC (structtype)
1674 = (struct cplus_struct_type *) &cplus_struct_default;
1675 TYPE_NAME (structtype) = suffix;
1679 case DNTT_TYPE_TAGDEF:
1681 /* Just a little different from above. We have to tack on
1682 an identifier of some kind (struct, union, enum, etc). */
1683 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1685 char *prefix, *suffix;
1686 suffix = VT (objfile) + dn_bufp->dtype.name;
1688 /* Lookup the next type in the list. It should be a structure,
1689 union, or enum type. We will need to attach that to our name. */
1690 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1691 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1695 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1697 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1702 /* Build the correct name. */
1704 = (char *) obstack_alloc (&objfile->type_obstack,
1705 strlen (prefix) + strlen (suffix) + 1);
1706 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1707 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1708 TYPE_TAG_NAME (structtype) = suffix;
1710 TYPE_CPLUS_SPECIFIC (structtype)
1711 = (struct cplus_struct_type *) &cplus_struct_default;
1715 case DNTT_TYPE_POINTER:
1716 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1718 case DNTT_TYPE_ENUM:
1719 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1720 case DNTT_TYPE_MEMENUM:
1721 return lookup_fundamental_type (objfile, FT_VOID);
1723 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1724 case DNTT_TYPE_SUBRANGE:
1725 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1726 case DNTT_TYPE_ARRAY:
1727 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1728 case DNTT_TYPE_STRUCT:
1729 case DNTT_TYPE_UNION:
1730 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1731 case DNTT_TYPE_FIELD:
1732 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1733 case DNTT_TYPE_VARIANT:
1734 case DNTT_TYPE_FILE:
1735 return lookup_fundamental_type (objfile, FT_VOID);
1736 case DNTT_TYPE_FUNCTYPE:
1737 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1739 case DNTT_TYPE_COBSTRUCT:
1740 case DNTT_TYPE_XREF:
1742 case DNTT_TYPE_MACRO:
1744 return lookup_fundamental_type (objfile, FT_VOID);
1749 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1750 struct subfile *subfile;
1751 sltpointer s_idx, e_idx;
1752 struct objfile *objfile;
1755 union sltentry *sl_bufp;
1757 while (s_idx <= e_idx)
1759 sl_bufp = hpread_get_slt (s_idx, objfile);
1760 /* Only record "normal" entries in the SLT. */
1761 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1762 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1763 record_line (subfile, sl_bufp->snorm.line,
1764 sl_bufp->snorm.address + offset);
1770 /* Internalize one native debug symbol. */
1773 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1774 text_offset, text_size, filename, index)
1775 union dnttentry *dn_bufp;
1777 struct section_offsets *section_offsets;
1778 struct objfile *objfile;
1779 CORE_ADDR text_offset;
1787 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1788 union dnttentry *dn_temp;
1789 dnttpointer hp_type;
1791 struct context_stack *new;
1793 /* Allocate one GDB debug symbol and fill in some default values. */
1794 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1795 sizeof (struct symbol));
1796 memset (sym, 0, sizeof (struct symbol));
1797 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1798 SYMBOL_LANGUAGE (sym) = language_auto;
1799 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1800 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1801 SYMBOL_LINE (sym) = 0;
1802 SYMBOL_VALUE (sym) = 0;
1803 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1805 hp_type.dnttp.extension = 1;
1806 hp_type.dnttp.immediate = 0;
1807 hp_type.dnttp.global = 0;
1808 hp_type.dnttp.index = index;
1810 type = dn_bufp->dblock.kind;
1814 case DNTT_TYPE_SRCFILE:
1815 /* This type of symbol indicates from which source file or include file
1816 the following data comes. If there are no modules it also may
1817 indicate the start of a new source file, in which case we must
1818 finish the symbol table of the previous source file
1819 (if any) and start accumulating a new symbol table. */
1822 if (!last_source_file)
1824 start_symtab (name, NULL, valu);
1825 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1829 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1831 dn_bufp->dsfile.address,
1834 start_subfile (name, NULL);
1837 case DNTT_TYPE_MODULE:
1838 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1841 case DNTT_TYPE_FUNCTION:
1842 case DNTT_TYPE_ENTRY:
1843 /* A function or secondary entry point. */
1844 valu = dn_bufp->dfunc.lowaddr + offset;
1845 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1847 dn_bufp->dfunc.address,
1850 WITHIN_FUNCTION (objfile) = 1;
1851 CURRENT_FUNCTION_VALUE (objfile) = valu;
1853 /* Stack must be empty now. */
1854 if (context_stack_depth != 0)
1855 complain (&lbrac_unmatched_complaint, (char *) symnum);
1856 new = push_context (0, valu);
1858 SYMBOL_CLASS (sym) = LOC_BLOCK;
1859 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1860 if (dn_bufp->dfunc.global)
1861 add_symbol_to_list (sym, &global_symbols);
1863 add_symbol_to_list (sym, &file_symbols);
1866 /* Search forward to the next scope beginning. */
1867 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1869 dn_bufp = hpread_get_lntt (++index, objfile);
1870 if (dn_bufp->dblock.extension)
1873 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1875 dn_bufp->dbegin.address,
1877 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1878 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1881 case DNTT_TYPE_BEGIN:
1882 /* Begin a new scope. */
1883 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1885 dn_bufp->dbegin.address,
1887 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1888 valu += offset; /* Relocate for dynamic loading */
1889 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1890 new = push_context (desc, valu);
1895 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1897 dn_bufp->dend.address + 1,
1899 switch (dn_bufp->dend.endkind)
1901 case DNTT_TYPE_MODULE:
1902 /* Ending a module ends the symbol table for that module. */
1903 valu = text_offset + text_size + offset;
1904 (void) end_symtab (valu, objfile, 0);
1907 case DNTT_TYPE_FUNCTION:
1908 /* Ending a function, well, ends the function's scope. */
1909 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1911 valu = dn_temp->dfunc.hiaddr + offset;
1912 new = pop_context ();
1913 /* Make a block for the local symbols within. */
1914 finish_block (new->name, &local_symbols, new->old_blocks,
1915 new->start_addr, valu, objfile);
1916 WITHIN_FUNCTION (objfile) = 0;
1918 case DNTT_TYPE_BEGIN:
1919 /* Just ending a local scope. */
1920 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1921 /* Why in the hell is this needed? */
1922 valu += offset + 9; /* Relocate for dynamic loading */
1923 new = pop_context ();
1924 desc = dn_bufp->dend.beginscope.dnttp.index;
1925 if (desc != new->depth)
1926 complain (&lbrac_mismatch_complaint, (char *) symnum);
1927 /* Make a block for the local symbols within. */
1928 finish_block (new->name, &local_symbols, new->old_blocks,
1929 new->start_addr, valu, objfile);
1930 local_symbols = new->locals;
1934 case DNTT_TYPE_LABEL:
1935 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1937 case DNTT_TYPE_FPARAM:
1938 /* Function parameters. */
1939 if (dn_bufp->dfparam.regparam)
1940 SYMBOL_CLASS (sym) = LOC_REGISTER;
1942 SYMBOL_CLASS (sym) = LOC_LOCAL;
1943 if (dn_bufp->dfparam.copyparam)
1945 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1946 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1948 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1952 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1953 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1954 add_symbol_to_list (sym, &local_symbols);
1956 case DNTT_TYPE_SVAR:
1957 /* Static variables. */
1958 SYMBOL_CLASS (sym) = LOC_STATIC;
1959 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1960 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1961 if (dn_bufp->dsvar.global)
1962 add_symbol_to_list (sym, &global_symbols);
1963 else if (WITHIN_FUNCTION (objfile))
1964 add_symbol_to_list (sym, &local_symbols);
1966 add_symbol_to_list (sym, &file_symbols);
1968 case DNTT_TYPE_DVAR:
1969 /* Dynamic variables. */
1970 if (dn_bufp->ddvar.regvar)
1971 SYMBOL_CLASS (sym) = LOC_REGISTER;
1973 SYMBOL_CLASS (sym) = LOC_LOCAL;
1974 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1975 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1977 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1979 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1980 if (dn_bufp->ddvar.global)
1981 add_symbol_to_list (sym, &global_symbols);
1982 else if (WITHIN_FUNCTION (objfile))
1983 add_symbol_to_list (sym, &local_symbols);
1985 add_symbol_to_list (sym, &file_symbols);
1987 case DNTT_TYPE_CONST:
1988 /* A constant (pascal?). */
1989 SYMBOL_CLASS (sym) = LOC_CONST;
1990 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1991 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1992 if (dn_bufp->dconst.global)
1993 add_symbol_to_list (sym, &global_symbols);
1994 else if (WITHIN_FUNCTION (objfile))
1995 add_symbol_to_list (sym, &local_symbols);
1997 add_symbol_to_list (sym, &file_symbols);
1999 case DNTT_TYPE_TYPEDEF:
2000 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2001 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2002 if (dn_bufp->dtype.global)
2003 add_symbol_to_list (sym, &global_symbols);
2004 else if (WITHIN_FUNCTION (objfile))
2005 add_symbol_to_list (sym, &local_symbols);
2007 add_symbol_to_list (sym, &file_symbols);
2009 case DNTT_TYPE_TAGDEF:
2010 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2011 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2012 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2013 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2014 if (dn_bufp->dtype.global)
2015 add_symbol_to_list (sym, &global_symbols);
2016 else if (WITHIN_FUNCTION (objfile))
2017 add_symbol_to_list (sym, &local_symbols);
2019 add_symbol_to_list (sym, &file_symbols);
2021 case DNTT_TYPE_POINTER:
2022 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2023 (dn_bufp->dptr.pointsto,
2025 add_symbol_to_list (sym, &file_symbols);
2027 case DNTT_TYPE_ENUM:
2028 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2029 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2030 add_symbol_to_list (sym, &file_symbols);
2032 case DNTT_TYPE_MEMENUM:
2035 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2036 add_symbol_to_list (sym, &file_symbols);
2038 case DNTT_TYPE_SUBRANGE:
2039 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2041 add_symbol_to_list (sym, &file_symbols);
2043 case DNTT_TYPE_ARRAY:
2044 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2045 add_symbol_to_list (sym, &file_symbols);
2047 case DNTT_TYPE_STRUCT:
2048 case DNTT_TYPE_UNION:
2049 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2050 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2051 add_symbol_to_list (sym, &file_symbols);