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,
19 Boston, MA 02111-1307, USA.
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support. */
26 #include "gdb_string.h"
27 #include "hp-symtab.h"
33 #include "complaints.h"
34 #include "gdb-stabs.h"
38 /* Private information attached to an objfile which we use to find
39 and internalize the HP C debug symbols within that objfile. */
41 struct hpread_symfile_info
43 /* The contents of each of the debug sections (there are 4 of them). */
49 /* We keep the size of the $VT$ section for range checking. */
52 /* Some routines still need to know the number of symbols in the
53 main debug sections ($LNTT$ and $GNTT$). */
54 unsigned int lntt_symcount;
55 unsigned int gntt_symcount;
57 /* To keep track of all the types we've processed. */
58 struct type **type_vector;
59 int type_vector_length;
61 /* Keeps track of the beginning of a range of source lines. */
64 /* Some state variables we'll need. */
67 /* Keep track of the current function's address. We may need to look
68 up something based on this address. */
69 unsigned int current_function_value;
72 /* Accessor macros to get at the fields. */
73 #define HPUX_SYMFILE_INFO(o) \
74 ((struct hpread_symfile_info *)((o)->sym_private))
75 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
76 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
77 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
78 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
79 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
80 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
81 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
82 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
83 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
84 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
85 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
86 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
88 /* Given the native debug symbol SYM, set NAMEP to the name associated
89 with the debug symbol. Note we may be called with a debug symbol which
90 has no associated name, in that case we return an empty string.
92 Also note we "know" that the name for any symbol is always in the
93 same place. Hence we don't have to conditionalize on the symbol type. */
94 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
95 if (! hpread_has_name ((SYM)->dblock.kind)) \
97 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
99 complain (&string_table_offset_complaint, (char *) symnum); \
103 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
105 /* We put a pointer to this structure in the read_symtab_private field
110 /* The offset within the file symbol table of first local symbol for
115 /* Length (in bytes) of the section of the symbol table devoted to
116 this file's symbols (actually, the section bracketed may contain
117 more than just this file's symbols). If ldsymlen is 0, the only
118 reason for this thing's existence is the dependency list.
119 Nothing else will happen when it is read in. */
124 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
125 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
126 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
128 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
129 /* Nonzero means give verbose info on gdb action. */
130 extern int info_verbose;
132 /* Complaints about the symbols we have encountered. */
133 extern struct complaint string_table_offset_complaint;
134 extern struct complaint lbrac_unmatched_complaint;
135 extern struct complaint lbrac_mismatch_complaint;
138 void hpread_symfile_init PARAMS ((struct objfile *));
141 hpread_read_array_type PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
143 static struct type *hpread_alloc_type
144 PARAMS ((dnttpointer, struct objfile *));
146 static struct type **hpread_lookup_type
147 PARAMS ((dnttpointer, struct objfile *));
149 static struct type *hpread_read_enum_type
150 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
152 static struct type *hpread_read_set_type
153 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
155 static struct type *hpread_read_subrange_type
156 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
158 static struct type *hpread_read_struct_type
159 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
161 void hpread_build_psymtabs
162 PARAMS ((struct objfile *, struct section_offsets *, int));
164 void hpread_symfile_finish PARAMS ((struct objfile *));
166 static struct partial_symtab *hpread_start_psymtab
167 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
168 struct partial_symbol **, struct partial_symbol **));
170 static struct partial_symtab *hpread_end_psymtab
171 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
172 struct partial_symtab **, int));
174 static struct symtab *hpread_expand_symtab
175 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
176 struct section_offsets *, char *));
178 static void hpread_process_one_debug_symbol
179 PARAMS ((union dnttentry *, char *, struct section_offsets *,
180 struct objfile *, CORE_ADDR, int, char *, int));
182 static sltpointer hpread_record_lines
183 PARAMS ((struct subfile *, sltpointer, sltpointer,
184 struct objfile *, CORE_ADDR));
186 static struct type *hpread_read_function_type
187 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
189 static struct type *hpread_type_lookup
190 PARAMS ((dnttpointer, struct objfile *));
192 static unsigned long hpread_get_depth
193 PARAMS ((sltpointer, struct objfile *));
195 static unsigned long hpread_get_line
196 PARAMS ((sltpointer, struct objfile *));
198 static CORE_ADDR hpread_get_location
199 PARAMS ((sltpointer, struct objfile *));
201 static int hpread_type_translate PARAMS ((dnttpointer));
202 static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
203 static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
204 static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
205 static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
206 static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
207 static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
208 static int hpread_has_name PARAMS ((enum dntt_entry_type));
211 /* Initialization for reading native HP C debug symbols from OBJFILE.
213 It's only purpose in life is to set up the symbol reader's private
214 per-objfile data structures, and read in the raw contents of the debug
215 sections (attaching pointers to the debug info into the private data
218 Since BFD doesn't know how to read debug symbols in a format-independent
219 way (and may never do so...), we have to do it ourselves. Note we may
220 be called on a file without native HP C debugging symbols.
221 FIXME, there should be a cleaner peephole into the BFD environment here. */
224 hpread_symfile_init (objfile)
225 struct objfile *objfile;
227 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
229 /* Allocate struct to keep track of the symfile */
230 objfile->sym_private = (PTR)
231 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
232 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
234 /* We haven't read in any types yet. */
235 TYPE_VECTOR (objfile) = 0;
237 /* Read in data from the $GNTT$ subspace. */
238 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
243 = obstack_alloc (&objfile->symbol_obstack,
244 bfd_section_size (objfile->obfd, gntt_section));
246 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
247 0, bfd_section_size (objfile->obfd, gntt_section));
249 GNTT_SYMCOUNT (objfile)
250 = bfd_section_size (objfile->obfd, gntt_section)
251 / sizeof (struct dntt_type_block);
253 /* Read in data from the $LNTT$ subspace. Also keep track of the number
255 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
260 = obstack_alloc (&objfile->symbol_obstack,
261 bfd_section_size (objfile->obfd, lntt_section));
263 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
264 0, bfd_section_size (objfile->obfd, lntt_section));
266 LNTT_SYMCOUNT (objfile)
267 = bfd_section_size (objfile->obfd, lntt_section)
268 / sizeof (struct dntt_type_block);
270 /* Read in data from the $SLT$ subspace. $SLT$ contains information
271 on source line numbers. */
272 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
277 obstack_alloc (&objfile->symbol_obstack,
278 bfd_section_size (objfile->obfd, slt_section));
280 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
281 0, bfd_section_size (objfile->obfd, slt_section));
283 /* Read in data from the $VT$ subspace. $VT$ contains things like
284 names and constants. Keep track of the number of symbols in the VT. */
285 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
289 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
292 (char *) obstack_alloc (&objfile->symbol_obstack,
295 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
296 0, VT_SIZE (objfile));
299 /* Scan and build partial symbols for a symbol file.
301 The minimal symbol table (either SOM or HP a.out) has already been
302 read in; all we need to do is setup partial symbols based on the
303 native debugging information.
305 We assume hpread_symfile_init has been called to initialize the
306 symbol reader's private data structures.
308 SECTION_OFFSETS contains offsets relative to which the symbols in the
309 various sections are (depending where the sections were actually loaded).
310 MAINLINE is true if we are reading the main symbol
311 table (as opposed to a shared lib or dynamically loaded file). */
314 hpread_build_psymtabs (objfile, section_offsets, mainline)
315 struct objfile *objfile;
316 struct section_offsets *section_offsets;
320 int past_first_source_file = 0;
321 struct cleanup *old_chain;
323 int hp_symnum, symcount, i;
325 union dnttentry *dn_bufp;
331 /* Current partial symtab */
332 struct partial_symtab *pst;
334 /* List of current psymtab's include files */
335 char **psymtab_include_list;
336 int includes_allocated;
339 /* Index within current psymtab dependency list */
340 struct partial_symtab **dependency_list;
341 int dependencies_used, dependencies_allocated;
343 /* Just in case the stabs reader left turds lying around. */
344 free_pending_blocks ();
345 make_cleanup (really_free_pendings, 0);
347 pst = (struct partial_symtab *) 0;
349 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
350 a number of problems with cross compilation and creating useless holes
351 in the stack when we have to allocate new entries. FIXME. */
353 includes_allocated = 30;
355 psymtab_include_list = (char **) alloca (includes_allocated *
358 dependencies_allocated = 30;
359 dependencies_used = 0;
361 (struct partial_symtab **) alloca (dependencies_allocated *
362 sizeof (struct partial_symtab *));
364 old_chain = make_cleanup (free_objfile, objfile);
366 last_source_file = 0;
368 /* Make two passes, one ofr the GNTT symbols, the other for the
370 for (i = 0; i < 1; i++)
372 int within_function = 0;
375 symcount = GNTT_SYMCOUNT (objfile);
377 symcount = LNTT_SYMCOUNT (objfile);
379 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
383 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
385 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
387 if (dn_bufp->dblock.extension)
390 /* Only handle things which are necessary for minimal symbols.
391 everything else is ignored. */
392 switch (dn_bufp->dblock.kind)
394 case DNTT_TYPE_SRCFILE:
396 /* A source file of some kind. Note this may simply
397 be an included file. */
398 SET_NAMESTRING (dn_bufp, &namestring, objfile);
400 /* Check if this is the source file we are already working
402 if (pst && !strcmp (namestring, pst->filename))
405 /* Check if this is an include file, if so check if we have
406 already seen it. Add it to the include list */
407 p = strrchr (namestring, '.');
408 if (!strcmp (p, ".h"))
413 for (j = 0; j < includes_used; j++)
414 if (!strcmp (namestring, psymtab_include_list[j]))
422 /* Add it to the list of includes seen so far and
423 allocate more include space if necessary. */
424 psymtab_include_list[includes_used++] = namestring;
425 if (includes_used >= includes_allocated)
427 char **orig = psymtab_include_list;
429 psymtab_include_list = (char **)
430 alloca ((includes_allocated *= 2) *
432 memcpy ((PTR) psymtab_include_list, (PTR) orig,
433 includes_used * sizeof (char *));
443 pst->filename = (char *)
444 obstack_alloc (&pst->objfile->psymbol_obstack,
445 strlen (namestring) + 1);
446 strcpy (pst->filename, namestring);
453 /* This is a bonafide new source file.
454 End the current partial symtab and start a new one. */
456 if (pst && past_first_source_file)
458 hpread_end_psymtab (pst, psymtab_include_list,
461 * sizeof (struct dntt_type_block)),
463 dependency_list, dependencies_used);
464 pst = (struct partial_symtab *) 0;
466 dependencies_used = 0;
469 past_first_source_file = 1;
471 valu = hpread_get_textlow (i, hp_symnum, objfile);
472 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
473 pst = hpread_start_psymtab (objfile, section_offsets,
476 * sizeof (struct dntt_type_block)),
477 objfile->global_psymbols.next,
478 objfile->static_psymbols.next);
484 case DNTT_TYPE_MODULE:
485 /* A source file. It's still unclear to me what the
486 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
487 is supposed to be. */
488 SET_NAMESTRING (dn_bufp, &namestring, objfile);
489 valu = hpread_get_textlow (i, hp_symnum, objfile);
490 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
493 pst = hpread_start_psymtab (objfile, section_offsets,
496 * sizeof (struct dntt_type_block)),
497 objfile->global_psymbols.next,
498 objfile->static_psymbols.next);
503 case DNTT_TYPE_FUNCTION:
504 case DNTT_TYPE_ENTRY:
505 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
506 a secondary entry point. */
507 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
511 valu = dn_bufp->dfunc.lowaddr +
512 ANOFFSET (section_offsets, SECT_OFF_TEXT);
513 SET_NAMESTRING (dn_bufp, &namestring, objfile);
514 add_psymbol_to_list (namestring, strlen (namestring),
515 VAR_NAMESPACE, LOC_BLOCK,
516 &objfile->static_psymbols, valu,
517 0, language_unknown, objfile);
520 case DNTT_TYPE_BEGIN:
522 /* Scope block begin/end. We only care about function
523 and file blocks right now. */
524 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
526 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
528 * sizeof (struct dntt_type_block)),
530 dependency_list, dependencies_used);
531 pst = (struct partial_symtab *) 0;
533 dependencies_used = 0;
536 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
541 case DNTT_TYPE_TYPEDEF:
542 case DNTT_TYPE_TAGDEF:
544 /* Variables, typedefs an the like. */
545 enum address_class storage;
546 namespace_enum namespace;
548 /* Don't add locals to the partial symbol table. */
550 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
551 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
554 /* TAGDEFs go into the structure namespace. */
555 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
556 namespace = STRUCT_NAMESPACE;
558 namespace = VAR_NAMESPACE;
560 /* What kind of "storage" does this use? */
561 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
562 storage = LOC_STATIC;
563 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
564 && dn_bufp->ddvar.regvar)
565 storage = LOC_REGISTER;
566 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
571 SET_NAMESTRING (dn_bufp, &namestring, objfile);
574 pst = hpread_start_psymtab (objfile, section_offsets,
577 * sizeof (struct dntt_type_block)),
578 objfile->global_psymbols.next,
579 objfile->static_psymbols.next);
581 if (dn_bufp->dsvar.global)
583 add_psymbol_to_list (namestring, strlen (namestring),
585 &objfile->global_psymbols,
586 dn_bufp->dsvar.location,
587 0, language_unknown, objfile);
591 add_psymbol_to_list (namestring, strlen (namestring),
593 &objfile->static_psymbols,
594 dn_bufp->dsvar.location,
595 0, language_unknown, objfile);
599 case DNTT_TYPE_MEMENUM:
600 case DNTT_TYPE_CONST:
601 /* Constants and members of enumerated types. */
602 SET_NAMESTRING (dn_bufp, &namestring, objfile);
605 pst = hpread_start_psymtab (objfile, section_offsets,
608 * sizeof (struct dntt_type_block)),
609 objfile->global_psymbols.next,
610 objfile->static_psymbols.next);
612 add_psymbol_to_list (namestring, strlen (namestring),
613 VAR_NAMESPACE, LOC_CONST,
614 &objfile->static_psymbols, 0,
615 0, language_unknown, objfile);
623 /* End any pending partial symbol table. */
626 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
627 hp_symnum * sizeof (struct dntt_type_block),
628 0, dependency_list, dependencies_used);
631 discard_cleanups (old_chain);
634 /* Perform any local cleanups required when we are done with a particular
635 objfile. I.E, we are in the process of discarding all symbol information
636 for an objfile, freeing up all memory held for it, and unlinking the
637 objfile struct from the global list of known objfiles. */
640 hpread_symfile_finish (objfile)
641 struct objfile *objfile;
643 if (objfile->sym_private != NULL)
645 mfree (objfile->md, objfile->sym_private);
650 /* The remaining functions are all for internal use only. */
652 /* Various small functions to get entries in the debug symbol sections. */
654 static union dnttentry *
655 hpread_get_lntt (index, objfile)
657 struct objfile *objfile;
659 return (union dnttentry *)
660 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
663 static union dnttentry *
664 hpread_get_gntt (index, objfile)
666 struct objfile *objfile;
668 return (union dnttentry *)
669 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
672 static union sltentry *
673 hpread_get_slt (index, objfile)
675 struct objfile *objfile;
677 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
680 /* Get the low address associated with some symbol (typically the start
681 of a particular source file or module). Since that information is not
682 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
683 the existance of DNTT_TYPE_FUNCTION symbols. */
686 hpread_get_textlow (global, index, objfile)
689 struct objfile *objfile;
691 union dnttentry *dn_bufp;
692 struct minimal_symbol *msymbol;
694 /* Look for a DNTT_TYPE_FUNCTION symbol. */
698 dn_bufp = hpread_get_gntt (index++, objfile);
700 dn_bufp = hpread_get_lntt (index++, objfile);
702 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
703 && dn_bufp->dblock.kind != DNTT_TYPE_END);
705 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
706 might happen when a sourcefile has no functions. */
707 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
710 /* The minimal symbols are typically more accurate for some reason. */
711 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
714 return SYMBOL_VALUE_ADDRESS (msymbol);
716 return dn_bufp->dfunc.lowaddr;
719 /* Get the nesting depth for the source line identified by INDEX. */
722 hpread_get_depth (index, objfile)
724 struct objfile *objfile;
726 union sltentry *sl_bufp;
728 sl_bufp = hpread_get_slt (index, objfile);
729 return sl_bufp->sspec.backptr.dnttp.index;
732 /* Get the source line number the the line identified by INDEX. */
735 hpread_get_line (index, objfile)
737 struct objfile *objfile;
739 union sltentry *sl_bufp;
741 sl_bufp = hpread_get_slt (index, objfile);
742 return sl_bufp->snorm.line;
746 hpread_get_location (index, objfile)
748 struct objfile *objfile;
750 union sltentry *sl_bufp;
753 /* code location of special sltentrys is determined from context */
754 sl_bufp = hpread_get_slt (index, objfile);
756 if (sl_bufp->snorm.sltdesc == SLT_END)
758 /* find previous 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;
765 /* find next normal sltentry and get address */
766 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
767 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
768 sl_bufp = hpread_get_slt (index + i, objfile);
769 return sl_bufp->snorm.address;
773 /* Return 1 if an HP debug symbol of type KIND has a name associated with
774 it, else return 0. */
777 hpread_has_name (kind)
778 enum dntt_entry_type kind;
782 case DNTT_TYPE_SRCFILE:
783 case DNTT_TYPE_MODULE:
784 case DNTT_TYPE_FUNCTION:
785 case DNTT_TYPE_ENTRY:
786 case DNTT_TYPE_IMPORT:
787 case DNTT_TYPE_LABEL:
788 case DNTT_TYPE_FPARAM:
791 case DNTT_TYPE_CONST:
792 case DNTT_TYPE_TYPEDEF:
793 case DNTT_TYPE_TAGDEF:
794 case DNTT_TYPE_MEMENUM:
795 case DNTT_TYPE_FIELD:
799 case DNTT_TYPE_BEGIN:
802 case DNTT_TYPE_COMMON:
803 case DNTT_TYPE_POINTER:
806 case DNTT_TYPE_SUBRANGE:
807 case DNTT_TYPE_ARRAY:
808 case DNTT_TYPE_STRUCT:
809 case DNTT_TYPE_UNION:
810 case DNTT_TYPE_VARIANT:
812 case DNTT_TYPE_FUNCTYPE:
813 case DNTT_TYPE_COBSTRUCT:
815 case DNTT_TYPE_MACRO:
821 /* Allocate and partially fill a partial symtab. It will be
822 completely filled at the end of the symbol list.
824 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
825 is the address relative to which its symbols are (incremental) or 0
828 static struct partial_symtab *
829 hpread_start_psymtab (objfile, section_offsets,
830 filename, textlow, ldsymoff, global_syms, static_syms)
831 struct objfile *objfile;
832 struct section_offsets *section_offsets;
836 struct partial_symbol **global_syms;
837 struct partial_symbol **static_syms;
839 struct partial_symtab *result =
840 start_psymtab_common (objfile, section_offsets,
841 filename, textlow, global_syms, static_syms);
843 result->read_symtab_private = (char *)
844 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
845 LDSYMOFF (result) = ldsymoff;
846 result->read_symtab = hpread_psymtab_to_symtab;
852 /* Close off the current usage of PST.
853 Returns PST or NULL if the partial symtab was empty and thrown away.
855 FIXME: List variables and peculiarities of same. */
857 static struct partial_symtab *
858 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
859 capping_text, dependency_list, number_dependencies)
860 struct partial_symtab *pst;
863 int capping_symbol_offset;
864 CORE_ADDR capping_text;
865 struct partial_symtab **dependency_list;
866 int number_dependencies;
869 struct objfile *objfile = pst->objfile;
871 if (capping_symbol_offset != -1)
872 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
873 pst->texthigh = capping_text;
876 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
878 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
880 pst->number_of_dependencies = number_dependencies;
881 if (number_dependencies)
883 pst->dependencies = (struct partial_symtab **)
884 obstack_alloc (&objfile->psymbol_obstack,
885 number_dependencies * sizeof (struct partial_symtab *));
886 memcpy (pst->dependencies, dependency_list,
887 number_dependencies * sizeof (struct partial_symtab *));
890 pst->dependencies = 0;
892 for (i = 0; i < num_includes; i++)
894 struct partial_symtab *subpst =
895 allocate_psymtab (include_list[i], objfile);
897 subpst->section_offsets = pst->section_offsets;
898 subpst->read_symtab_private =
899 (char *) obstack_alloc (&objfile->psymbol_obstack,
900 sizeof (struct symloc));
904 subpst->texthigh = 0;
906 /* We could save slight bits of space by only making one of these,
907 shared by the entire set of include files. FIXME-someday. */
908 subpst->dependencies = (struct partial_symtab **)
909 obstack_alloc (&objfile->psymbol_obstack,
910 sizeof (struct partial_symtab *));
911 subpst->dependencies[0] = pst;
912 subpst->number_of_dependencies = 1;
914 subpst->globals_offset =
915 subpst->n_global_syms =
916 subpst->statics_offset =
917 subpst->n_static_syms = 0;
921 subpst->read_symtab = pst->read_symtab;
924 sort_pst_symbols (pst);
926 /* If there is already a psymtab or symtab for a file of this name, remove it.
927 (If there is a symtab, more drastic things also happen.)
928 This happens in VxWorks. */
929 free_named_symtabs (pst->filename);
931 if (num_includes == 0
932 && number_dependencies == 0
933 && pst->n_global_syms == 0
934 && pst->n_static_syms == 0)
936 /* Throw away this psymtab, it's empty. We can't deallocate it, since
937 it is on the obstack, but we can forget to chain it on the list. */
938 /* Empty psymtabs happen as a result of header files which don't have
939 any symbols in them. There can be a lot of them. But this check
940 is wrong, in that a psymtab with N_SLINE entries but nothing else
941 is not empty, but we don't realize that. Fixing that without slowing
942 things down might be tricky. */
944 discard_psymtab (pst);
946 /* Indicate that psymtab was thrown away. */
947 pst = (struct partial_symtab *) NULL;
952 /* Do the dirty work of reading in the full symbol from a partial symbol
956 hpread_psymtab_to_symtab_1 (pst)
957 struct partial_symtab *pst;
959 struct cleanup *old_chain;
962 /* Get out quick if passed junk. */
966 /* Complain if we've already read in this symbol table. */
969 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
974 /* Read in all partial symtabs on which this one is dependent */
975 for (i = 0; i < pst->number_of_dependencies; i++)
976 if (!pst->dependencies[i]->readin)
978 /* Inform about additional files that need to be read in. */
981 fputs_filtered (" ", gdb_stdout);
983 fputs_filtered ("and ", gdb_stdout);
985 printf_filtered ("%s...", pst->dependencies[i]->filename);
986 wrap_here (""); /* Flush output */
987 gdb_flush (gdb_stdout);
989 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
992 /* If it's real... */
995 /* Init stuff necessary for reading in symbols */
997 old_chain = make_cleanup (really_free_pendings, 0);
1000 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1001 pst->textlow, pst->texthigh - pst->textlow,
1002 pst->section_offsets, pst->filename);
1003 sort_symtab_syms (pst->symtab);
1005 do_cleanups (old_chain);
1011 /* Read in all of the symbols for a given psymtab for real.
1012 Be verbose about it if the user wants that. */
1015 hpread_psymtab_to_symtab (pst)
1016 struct partial_symtab *pst;
1018 /* Get out quick if given junk. */
1025 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1030 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1032 /* Print the message now, before reading the string table,
1033 to avoid disconcerting pauses. */
1036 printf_filtered ("Reading in symbols for %s...", pst->filename);
1037 gdb_flush (gdb_stdout);
1040 hpread_psymtab_to_symtab_1 (pst);
1042 /* Match with global symbols. This only needs to be done once,
1043 after all of the symtabs and dependencies have been read in. */
1044 scan_file_globals (pst->objfile);
1046 /* Finish up the debug error message. */
1048 printf_filtered ("done.\n");
1051 /* Read in a defined section of a specific object file's symbols.
1053 DESC is the file descriptor for the file, positioned at the
1054 beginning of the symtab
1055 SYM_OFFSET is the offset within the file of
1056 the beginning of the symbols we want to read
1057 SYM_SIZE is the size of the symbol info to read in.
1058 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1059 TEXT_SIZE is the size of the text segment read in.
1060 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1062 static struct symtab *
1063 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1064 section_offsets, filename)
1065 struct objfile *objfile;
1068 CORE_ADDR text_offset;
1070 struct section_offsets *section_offsets;
1074 union dnttentry *dn_bufp;
1075 unsigned max_symnum;
1077 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1079 current_objfile = objfile;
1082 last_source_file = 0;
1084 dn_bufp = hpread_get_lntt (sym_index, objfile);
1085 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1086 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1088 start_symtab ("globals", NULL, 0);
1089 record_debugformat ("HP");
1092 max_symnum = sym_size / sizeof (struct dntt_type_block);
1094 /* Read in and process each debug symbol within the specified range. */
1096 symnum < max_symnum;
1099 QUIT; /* Allow this to be interruptable */
1100 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1102 if (dn_bufp->dblock.extension)
1105 /* Yow! We call SET_NAMESTRING on things without names! */
1106 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1108 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1109 objfile, text_offset, text_size,
1110 filename, symnum + sym_index);
1113 current_objfile = NULL;
1115 return end_symtab (text_offset + text_size, objfile, 0);
1119 /* Convert basic types from HP debug format into GDB internal format. */
1122 hpread_type_translate (typep)
1125 if (!typep.dntti.immediate)
1128 switch (typep.dntti.type)
1130 case HP_TYPE_BOOLEAN:
1131 case HP_TYPE_BOOLEAN_S300_COMPAT:
1132 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1134 /* Ugh. No way to distinguish between signed and unsigned chars. */
1136 case HP_TYPE_WIDE_CHAR:
1139 if (typep.dntti.bitlength <= 8)
1141 if (typep.dntti.bitlength <= 16)
1143 if (typep.dntti.bitlength <= 32)
1145 return FT_LONG_LONG;
1148 case HP_TYPE_UNSIGNED_LONG:
1149 if (typep.dntti.bitlength <= 8)
1150 return FT_UNSIGNED_CHAR;
1151 if (typep.dntti.bitlength <= 16)
1152 return FT_UNSIGNED_SHORT;
1153 if (typep.dntti.bitlength <= 32)
1154 return FT_UNSIGNED_LONG;
1155 return FT_UNSIGNED_LONG_LONG;
1156 case HP_TYPE_UNSIGNED_INT:
1157 if (typep.dntti.bitlength <= 8)
1158 return FT_UNSIGNED_CHAR;
1159 if (typep.dntti.bitlength <= 16)
1160 return FT_UNSIGNED_SHORT;
1161 if (typep.dntti.bitlength <= 32)
1162 return FT_UNSIGNED_INTEGER;
1163 return FT_UNSIGNED_LONG_LONG;
1165 case HP_TYPE_REAL_3000:
1166 case HP_TYPE_DOUBLE:
1167 if (typep.dntti.bitlength == 64)
1168 return FT_DBL_PREC_FLOAT;
1169 if (typep.dntti.bitlength == 128)
1170 return FT_EXT_PREC_FLOAT;
1172 case HP_TYPE_COMPLEX:
1173 case HP_TYPE_COMPLEXS3000:
1174 if (typep.dntti.bitlength == 128)
1175 return FT_DBL_PREC_COMPLEX;
1176 if (typep.dntti.bitlength == 192)
1177 return FT_EXT_PREC_COMPLEX;
1179 case HP_TYPE_STRING200:
1180 case HP_TYPE_LONGSTRING200:
1181 case HP_TYPE_FTN_STRING_SPEC:
1182 case HP_TYPE_MOD_STRING_SPEC:
1183 case HP_TYPE_MOD_STRING_3000:
1184 case HP_TYPE_FTN_STRING_S300_COMPAT:
1185 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1192 /* Return the type associated with the index found in HP_TYPE. */
1194 static struct type **
1195 hpread_lookup_type (hp_type, objfile)
1196 dnttpointer hp_type;
1197 struct objfile *objfile;
1200 int index = hp_type.dnttp.index;
1202 if (hp_type.dntti.immediate)
1205 if (index < LNTT_SYMCOUNT (objfile))
1207 if (index >= TYPE_VECTOR_LENGTH (objfile))
1209 old_len = TYPE_VECTOR_LENGTH (objfile);
1212 TYPE_VECTOR_LENGTH (objfile) = 100;
1213 TYPE_VECTOR (objfile) = (struct type **)
1214 xmmalloc (objfile->md,
1215 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1217 while (index >= TYPE_VECTOR_LENGTH (objfile))
1218 TYPE_VECTOR_LENGTH (objfile) *= 2;
1219 TYPE_VECTOR (objfile) = (struct type **)
1220 xmrealloc (objfile->md,
1221 (char *) TYPE_VECTOR (objfile),
1222 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1223 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1224 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1225 sizeof (struct type *));
1227 return &TYPE_VECTOR (objfile)[index];
1233 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1234 Note we'll just return the address of a GDB internal type if we already
1235 have it lying around. */
1237 static struct type *
1238 hpread_alloc_type (hp_type, objfile)
1239 dnttpointer hp_type;
1240 struct objfile *objfile;
1242 struct type **type_addr;
1244 type_addr = hpread_lookup_type (hp_type, objfile);
1245 if (*type_addr == 0)
1246 *type_addr = alloc_type (objfile);
1248 TYPE_CPLUS_SPECIFIC (*type_addr)
1249 = (struct cplus_struct_type *) &cplus_struct_default;
1253 /* Read a native enumerated type and return it in GDB internal form. */
1255 static struct type *
1256 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1257 dnttpointer hp_type;
1258 union dnttentry *dn_bufp;
1259 struct objfile *objfile;
1262 struct pending **symlist, *osyms, *syms;
1263 int o_nsyms, nsyms = 0;
1265 union dnttentry *memp;
1270 type = hpread_alloc_type (hp_type, objfile);
1271 TYPE_LENGTH (type) = 4;
1273 symlist = &file_symbols;
1275 o_nsyms = osyms ? osyms->nsyms : 0;
1277 /* Get a name for each member and add it to our list of members. */
1278 mem = dn_bufp->denum.firstmem;
1279 while (mem.dnttp.extension && mem.word != DNTTNIL)
1281 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1283 name = VT (objfile) + memp->dmember.name;
1284 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1285 sizeof (struct symbol));
1286 memset (sym, 0, sizeof (struct symbol));
1287 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1288 &objfile->symbol_obstack);
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_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1323 TYPE_FIELD_BITSIZE (type, n) = 0;
1332 /* Read and internalize a native function debug symbol. */
1334 static struct type *
1335 hpread_read_function_type (hp_type, dn_bufp, objfile)
1336 dnttpointer hp_type;
1337 union dnttentry *dn_bufp;
1338 struct objfile *objfile;
1340 struct type *type, *type1;
1341 struct pending **symlist, *osyms, *syms;
1342 int o_nsyms, nsyms = 0;
1344 union dnttentry *paramp;
1349 param = dn_bufp->dfunc.firstparam;
1351 /* See if we've already read in this type. */
1352 type = hpread_alloc_type (hp_type, objfile);
1353 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1356 /* Nope, so read it in and store it away. */
1357 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1359 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1361 symlist = &local_symbols;
1363 o_nsyms = osyms ? osyms->nsyms : 0;
1365 /* Now examine each parameter noting its type, location, and a
1366 wealth of other information. */
1367 while (param.word && param.word != DNTTNIL)
1369 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1371 param = paramp->dfparam.nextparam;
1374 name = VT (objfile) + paramp->dfparam.name;
1375 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1376 sizeof (struct symbol));
1377 (void) memset (sym, 0, sizeof (struct symbol));
1378 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1379 &objfile->symbol_obstack);
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 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1499 if (fieldp->dfield.bitlength % 8)
1500 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1502 FIELD_BITSIZE (list->field) = 0;
1504 field = fieldp->dfield.nextfield;
1505 FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1509 TYPE_NFIELDS (type) = nfields;
1510 TYPE_FIELDS (type) = (struct field *)
1511 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1513 /* Copy the saved-up fields into the field vector. */
1514 for (n = nfields; list; list = list->next)
1517 TYPE_FIELD (type, n) = list->field;
1522 /* Read in and internalize a set debug symbol. */
1524 static struct type *
1525 hpread_read_set_type (hp_type, dn_bufp, objfile)
1526 dnttpointer hp_type;
1527 union dnttentry *dn_bufp;
1528 struct objfile *objfile;
1532 /* See if it's something we've already deal with. */
1533 type = hpread_alloc_type (hp_type, objfile);
1534 if (TYPE_CODE (type) == TYPE_CODE_SET)
1537 /* Nope. Fill in the appropriate fields. */
1538 TYPE_CODE (type) = TYPE_CODE_SET;
1539 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1540 TYPE_NFIELDS (type) = 0;
1541 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1546 /* Read in and internalize an array debug symbol. */
1548 static struct type *
1549 hpread_read_array_type (hp_type, dn_bufp, objfile)
1550 dnttpointer hp_type;
1551 union dnttentry *dn_bufp;
1552 struct objfile *objfile;
1555 union dnttentry save;
1558 /* Why no check here? Because it kept us from properly determining
1559 the size of the array! */
1560 type = hpread_alloc_type (hp_type, objfile);
1562 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1564 /* values are not normalized. */
1565 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1566 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1568 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1570 /* The HP debug format represents char foo[]; as an array with
1571 length 0x7fffffff. Internally GDB wants to represent this
1572 as an array of length zero. */
1573 TYPE_LENGTH (type) = 0;
1576 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1578 TYPE_NFIELDS (type) = 1;
1579 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1582 TYPE_FIELDS (type) = (struct field *)
1583 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1584 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1589 /* Read in and internalize a subrange debug symbol. */
1590 static struct type *
1591 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1592 dnttpointer hp_type;
1593 union dnttentry *dn_bufp;
1594 struct objfile *objfile;
1598 /* Is it something we've already dealt with. */
1599 type = hpread_alloc_type (hp_type, objfile);
1600 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1603 /* Nope, internalize it. */
1604 TYPE_CODE (type) = TYPE_CODE_RANGE;
1605 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1606 TYPE_NFIELDS (type) = 2;
1608 = (struct field *) obstack_alloc (&objfile->type_obstack,
1609 2 * sizeof (struct field));
1611 if (dn_bufp->dsubr.dyn_low)
1612 TYPE_FIELD_BITPOS (type, 0) = 0;
1614 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1616 if (dn_bufp->dsubr.dyn_high)
1617 TYPE_FIELD_BITPOS (type, 1) = -1;
1619 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1620 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1625 static struct type *
1626 hpread_type_lookup (hp_type, objfile)
1627 dnttpointer hp_type;
1628 struct objfile *objfile;
1630 union dnttentry *dn_bufp;
1632 /* First see if it's a simple builtin type. */
1633 if (hp_type.dntti.immediate)
1634 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1636 /* Not a builtin type. We'll have to read it in. */
1637 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1638 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1640 return lookup_fundamental_type (objfile, FT_VOID);
1642 switch (dn_bufp->dblock.kind)
1644 case DNTT_TYPE_SRCFILE:
1645 case DNTT_TYPE_MODULE:
1646 case DNTT_TYPE_FUNCTION:
1647 case DNTT_TYPE_ENTRY:
1648 case DNTT_TYPE_BEGIN:
1650 case DNTT_TYPE_IMPORT:
1651 case DNTT_TYPE_LABEL:
1652 case DNTT_TYPE_WITH:
1653 case DNTT_TYPE_COMMON:
1654 case DNTT_TYPE_FPARAM:
1655 case DNTT_TYPE_SVAR:
1656 case DNTT_TYPE_DVAR:
1657 case DNTT_TYPE_CONST:
1658 /* Opps. Something went very wrong. */
1659 return lookup_fundamental_type (objfile, FT_VOID);
1661 case DNTT_TYPE_TYPEDEF:
1663 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1666 suffix = VT (objfile) + dn_bufp->dtype.name;
1668 TYPE_CPLUS_SPECIFIC (structtype)
1669 = (struct cplus_struct_type *) &cplus_struct_default;
1670 TYPE_NAME (structtype) = suffix;
1674 case DNTT_TYPE_TAGDEF:
1676 /* Just a little different from above. We have to tack on
1677 an identifier of some kind (struct, union, enum, etc). */
1678 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1680 char *prefix, *suffix;
1681 suffix = VT (objfile) + dn_bufp->dtype.name;
1683 /* Lookup the next type in the list. It should be a structure,
1684 union, or enum type. We will need to attach that to our name. */
1685 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1686 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1690 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1692 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1697 /* Build the correct name. */
1699 = (char *) obstack_alloc (&objfile->type_obstack,
1700 strlen (prefix) + strlen (suffix) + 1);
1701 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1702 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1703 TYPE_TAG_NAME (structtype) = suffix;
1705 TYPE_CPLUS_SPECIFIC (structtype)
1706 = (struct cplus_struct_type *) &cplus_struct_default;
1710 case DNTT_TYPE_POINTER:
1711 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1713 case DNTT_TYPE_ENUM:
1714 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1715 case DNTT_TYPE_MEMENUM:
1716 return lookup_fundamental_type (objfile, FT_VOID);
1718 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1719 case DNTT_TYPE_SUBRANGE:
1720 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1721 case DNTT_TYPE_ARRAY:
1722 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1723 case DNTT_TYPE_STRUCT:
1724 case DNTT_TYPE_UNION:
1725 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1726 case DNTT_TYPE_FIELD:
1727 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1728 case DNTT_TYPE_VARIANT:
1729 case DNTT_TYPE_FILE:
1730 return lookup_fundamental_type (objfile, FT_VOID);
1731 case DNTT_TYPE_FUNCTYPE:
1732 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1734 case DNTT_TYPE_COBSTRUCT:
1735 case DNTT_TYPE_XREF:
1737 case DNTT_TYPE_MACRO:
1739 return lookup_fundamental_type (objfile, FT_VOID);
1744 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1745 struct subfile *subfile;
1746 sltpointer s_idx, e_idx;
1747 struct objfile *objfile;
1750 union sltentry *sl_bufp;
1752 while (s_idx <= e_idx)
1754 sl_bufp = hpread_get_slt (s_idx, objfile);
1755 /* Only record "normal" entries in the SLT. */
1756 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1757 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1758 record_line (subfile, sl_bufp->snorm.line,
1759 sl_bufp->snorm.address + offset);
1765 /* Internalize one native debug symbol. */
1768 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1769 text_offset, text_size, filename, index)
1770 union dnttentry *dn_bufp;
1772 struct section_offsets *section_offsets;
1773 struct objfile *objfile;
1774 CORE_ADDR text_offset;
1782 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1783 union dnttentry *dn_temp;
1784 dnttpointer hp_type;
1786 struct context_stack *new;
1788 /* Allocate one GDB debug symbol and fill in some default values. */
1789 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1790 sizeof (struct symbol));
1791 memset (sym, 0, sizeof (struct symbol));
1792 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1793 SYMBOL_LANGUAGE (sym) = language_auto;
1794 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1795 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1796 SYMBOL_LINE (sym) = 0;
1797 SYMBOL_VALUE (sym) = 0;
1798 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1800 hp_type.dnttp.extension = 1;
1801 hp_type.dnttp.immediate = 0;
1802 hp_type.dnttp.global = 0;
1803 hp_type.dnttp.index = index;
1805 type = dn_bufp->dblock.kind;
1809 case DNTT_TYPE_SRCFILE:
1810 /* This type of symbol indicates from which source file or include file
1811 the following data comes. If there are no modules it also may
1812 indicate the start of a new source file, in which case we must
1813 finish the symbol table of the previous source file
1814 (if any) and start accumulating a new symbol table. */
1817 if (!last_source_file)
1819 start_symtab (name, NULL, valu);
1820 record_debugformat ("HP");
1821 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1825 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1827 dn_bufp->dsfile.address,
1830 start_subfile (name, NULL);
1833 case DNTT_TYPE_MODULE:
1834 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1837 case DNTT_TYPE_FUNCTION:
1838 case DNTT_TYPE_ENTRY:
1839 /* A function or secondary entry point. */
1840 valu = dn_bufp->dfunc.lowaddr + offset;
1841 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1843 dn_bufp->dfunc.address,
1846 WITHIN_FUNCTION (objfile) = 1;
1847 CURRENT_FUNCTION_VALUE (objfile) = valu;
1849 /* Stack must be empty now. */
1850 if (context_stack_depth != 0)
1851 complain (&lbrac_unmatched_complaint, (char *) symnum);
1852 new = push_context (0, valu);
1854 SYMBOL_CLASS (sym) = LOC_BLOCK;
1855 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1856 if (dn_bufp->dfunc.global)
1857 add_symbol_to_list (sym, &global_symbols);
1859 add_symbol_to_list (sym, &file_symbols);
1862 /* Search forward to the next scope beginning. */
1863 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1865 dn_bufp = hpread_get_lntt (++index, objfile);
1866 if (dn_bufp->dblock.extension)
1869 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1871 dn_bufp->dbegin.address,
1873 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1874 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1877 case DNTT_TYPE_BEGIN:
1878 /* Begin a new scope. */
1879 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1881 dn_bufp->dbegin.address,
1883 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1884 valu += offset; /* Relocate for dynamic loading */
1885 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1886 new = push_context (desc, valu);
1891 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1893 dn_bufp->dend.address + 1,
1895 switch (dn_bufp->dend.endkind)
1897 case DNTT_TYPE_MODULE:
1898 /* Ending a module ends the symbol table for that module. */
1899 valu = text_offset + text_size + offset;
1900 (void) end_symtab (valu, objfile, 0);
1903 case DNTT_TYPE_FUNCTION:
1904 /* Ending a function, well, ends the function's scope. */
1905 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1907 valu = dn_temp->dfunc.hiaddr + offset;
1908 new = pop_context ();
1909 /* Make a block for the local symbols within. */
1910 finish_block (new->name, &local_symbols, new->old_blocks,
1911 new->start_addr, valu, objfile);
1912 WITHIN_FUNCTION (objfile) = 0;
1914 case DNTT_TYPE_BEGIN:
1915 /* Just ending a local scope. */
1916 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1917 /* Why in the hell is this needed? */
1918 valu += offset + 9; /* Relocate for dynamic loading */
1919 new = pop_context ();
1920 desc = dn_bufp->dend.beginscope.dnttp.index;
1921 if (desc != new->depth)
1922 complain (&lbrac_mismatch_complaint, (char *) symnum);
1923 /* Make a block for the local symbols within. */
1924 finish_block (new->name, &local_symbols, new->old_blocks,
1925 new->start_addr, valu, objfile);
1926 local_symbols = new->locals;
1930 case DNTT_TYPE_LABEL:
1931 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1933 case DNTT_TYPE_FPARAM:
1934 /* Function parameters. */
1935 if (dn_bufp->dfparam.regparam)
1936 SYMBOL_CLASS (sym) = LOC_REGISTER;
1938 SYMBOL_CLASS (sym) = LOC_LOCAL;
1939 if (dn_bufp->dfparam.copyparam)
1941 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1942 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1944 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1948 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1949 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1950 add_symbol_to_list (sym, &local_symbols);
1952 case DNTT_TYPE_SVAR:
1953 /* Static variables. */
1954 SYMBOL_CLASS (sym) = LOC_STATIC;
1955 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1956 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1957 if (dn_bufp->dsvar.global)
1958 add_symbol_to_list (sym, &global_symbols);
1959 else if (WITHIN_FUNCTION (objfile))
1960 add_symbol_to_list (sym, &local_symbols);
1962 add_symbol_to_list (sym, &file_symbols);
1964 case DNTT_TYPE_DVAR:
1965 /* Dynamic variables. */
1966 if (dn_bufp->ddvar.regvar)
1967 SYMBOL_CLASS (sym) = LOC_REGISTER;
1969 SYMBOL_CLASS (sym) = LOC_LOCAL;
1970 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1971 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1973 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1975 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1976 if (dn_bufp->ddvar.global)
1977 add_symbol_to_list (sym, &global_symbols);
1978 else if (WITHIN_FUNCTION (objfile))
1979 add_symbol_to_list (sym, &local_symbols);
1981 add_symbol_to_list (sym, &file_symbols);
1983 case DNTT_TYPE_CONST:
1984 /* A constant (pascal?). */
1985 SYMBOL_CLASS (sym) = LOC_CONST;
1986 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1987 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1988 if (dn_bufp->dconst.global)
1989 add_symbol_to_list (sym, &global_symbols);
1990 else if (WITHIN_FUNCTION (objfile))
1991 add_symbol_to_list (sym, &local_symbols);
1993 add_symbol_to_list (sym, &file_symbols);
1995 case DNTT_TYPE_TYPEDEF:
1996 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1997 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1998 if (dn_bufp->dtype.global)
1999 add_symbol_to_list (sym, &global_symbols);
2000 else if (WITHIN_FUNCTION (objfile))
2001 add_symbol_to_list (sym, &local_symbols);
2003 add_symbol_to_list (sym, &file_symbols);
2005 case DNTT_TYPE_TAGDEF:
2006 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2007 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2008 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2009 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2010 if (dn_bufp->dtype.global)
2011 add_symbol_to_list (sym, &global_symbols);
2012 else if (WITHIN_FUNCTION (objfile))
2013 add_symbol_to_list (sym, &local_symbols);
2015 add_symbol_to_list (sym, &file_symbols);
2017 case DNTT_TYPE_POINTER:
2018 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2019 (dn_bufp->dptr.pointsto,
2021 add_symbol_to_list (sym, &file_symbols);
2023 case DNTT_TYPE_ENUM:
2024 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2025 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2026 add_symbol_to_list (sym, &file_symbols);
2028 case DNTT_TYPE_MEMENUM:
2031 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2032 add_symbol_to_list (sym, &file_symbols);
2034 case DNTT_TYPE_SUBRANGE:
2035 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2037 add_symbol_to_list (sym, &file_symbols);
2039 case DNTT_TYPE_ARRAY:
2040 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2041 add_symbol_to_list (sym, &file_symbols);
2043 case DNTT_TYPE_STRUCT:
2044 case DNTT_TYPE_UNION:
2045 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2046 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2047 add_symbol_to_list (sym, &file_symbols);