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 *, int));
164 void hpread_symfile_finish PARAMS ((struct objfile *));
166 static struct partial_symtab *hpread_start_psymtab
167 PARAMS ((struct objfile *, 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 MAINLINE is true if we are reading the main symbol
309 table (as opposed to a shared lib or dynamically loaded file). */
312 hpread_build_psymtabs (objfile, mainline)
313 struct objfile *objfile;
317 int past_first_source_file = 0;
318 struct cleanup *old_chain;
320 int hp_symnum, symcount, i;
322 union dnttentry *dn_bufp;
328 /* Current partial symtab */
329 struct partial_symtab *pst;
331 /* List of current psymtab's include files */
332 char **psymtab_include_list;
333 int includes_allocated;
336 /* Index within current psymtab dependency list */
337 struct partial_symtab **dependency_list;
338 int dependencies_used, dependencies_allocated;
340 /* Just in case the stabs reader left turds lying around. */
341 free_pending_blocks ();
342 make_cleanup (really_free_pendings, 0);
344 pst = (struct partial_symtab *) 0;
346 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
347 a number of problems with cross compilation and creating useless holes
348 in the stack when we have to allocate new entries. FIXME. */
350 includes_allocated = 30;
352 psymtab_include_list = (char **) alloca (includes_allocated *
355 dependencies_allocated = 30;
356 dependencies_used = 0;
358 (struct partial_symtab **) alloca (dependencies_allocated *
359 sizeof (struct partial_symtab *));
361 old_chain = make_cleanup (free_objfile, objfile);
363 last_source_file = 0;
365 /* Make two passes, one ofr the GNTT symbols, the other for the
367 for (i = 0; i < 1; i++)
369 int within_function = 0;
372 symcount = GNTT_SYMCOUNT (objfile);
374 symcount = LNTT_SYMCOUNT (objfile);
376 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
380 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
382 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
384 if (dn_bufp->dblock.extension)
387 /* Only handle things which are necessary for minimal symbols.
388 everything else is ignored. */
389 switch (dn_bufp->dblock.kind)
391 case DNTT_TYPE_SRCFILE:
393 /* A source file of some kind. Note this may simply
394 be an included file. */
395 SET_NAMESTRING (dn_bufp, &namestring, objfile);
397 /* Check if this is the source file we are already working
399 if (pst && !strcmp (namestring, pst->filename))
402 /* Check if this is an include file, if so check if we have
403 already seen it. Add it to the include list */
404 p = strrchr (namestring, '.');
405 if (!strcmp (p, ".h"))
410 for (j = 0; j < includes_used; j++)
411 if (!strcmp (namestring, psymtab_include_list[j]))
419 /* Add it to the list of includes seen so far and
420 allocate more include space if necessary. */
421 psymtab_include_list[includes_used++] = namestring;
422 if (includes_used >= includes_allocated)
424 char **orig = psymtab_include_list;
426 psymtab_include_list = (char **)
427 alloca ((includes_allocated *= 2) *
429 memcpy ((PTR) psymtab_include_list, (PTR) orig,
430 includes_used * sizeof (char *));
440 pst->filename = (char *)
441 obstack_alloc (&pst->objfile->psymbol_obstack,
442 strlen (namestring) + 1);
443 strcpy (pst->filename, namestring);
450 /* This is a bonafide new source file.
451 End the current partial symtab and start a new one. */
453 if (pst && past_first_source_file)
455 hpread_end_psymtab (pst, psymtab_include_list,
458 * sizeof (struct dntt_type_block)),
460 dependency_list, dependencies_used);
461 pst = (struct partial_symtab *) 0;
463 dependencies_used = 0;
466 past_first_source_file = 1;
468 valu = hpread_get_textlow (i, hp_symnum, objfile);
469 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
470 pst = hpread_start_psymtab (objfile,
473 * sizeof (struct dntt_type_block)),
474 objfile->global_psymbols.next,
475 objfile->static_psymbols.next);
481 case DNTT_TYPE_MODULE:
482 /* A source file. It's still unclear to me what the
483 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
484 is supposed to be. */
485 SET_NAMESTRING (dn_bufp, &namestring, objfile);
486 valu = hpread_get_textlow (i, hp_symnum, objfile);
487 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
490 pst = hpread_start_psymtab (objfile,
493 * sizeof (struct dntt_type_block)),
494 objfile->global_psymbols.next,
495 objfile->static_psymbols.next);
500 case DNTT_TYPE_FUNCTION:
501 case DNTT_TYPE_ENTRY:
502 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
503 a secondary entry point. */
504 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
508 valu = dn_bufp->dfunc.lowaddr +
509 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
510 SET_NAMESTRING (dn_bufp, &namestring, objfile);
511 add_psymbol_to_list (namestring, strlen (namestring),
512 VAR_NAMESPACE, LOC_BLOCK,
513 &objfile->static_psymbols, valu,
514 0, language_unknown, objfile);
517 case DNTT_TYPE_BEGIN:
519 /* Scope block begin/end. We only care about function
520 and file blocks right now. */
521 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
523 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
525 * sizeof (struct dntt_type_block)),
527 dependency_list, dependencies_used);
528 pst = (struct partial_symtab *) 0;
530 dependencies_used = 0;
533 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
538 case DNTT_TYPE_TYPEDEF:
539 case DNTT_TYPE_TAGDEF:
541 /* Variables, typedefs an the like. */
542 enum address_class storage;
543 namespace_enum namespace;
545 /* Don't add locals to the partial symbol table. */
547 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
548 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
551 /* TAGDEFs go into the structure namespace. */
552 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
553 namespace = STRUCT_NAMESPACE;
555 namespace = VAR_NAMESPACE;
557 /* What kind of "storage" does this use? */
558 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
559 storage = LOC_STATIC;
560 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
561 && dn_bufp->ddvar.regvar)
562 storage = LOC_REGISTER;
563 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
568 SET_NAMESTRING (dn_bufp, &namestring, objfile);
571 pst = hpread_start_psymtab (objfile,
574 * sizeof (struct dntt_type_block)),
575 objfile->global_psymbols.next,
576 objfile->static_psymbols.next);
578 if (dn_bufp->dsvar.global)
580 add_psymbol_to_list (namestring, strlen (namestring),
582 &objfile->global_psymbols,
583 dn_bufp->dsvar.location,
584 0, language_unknown, objfile);
588 add_psymbol_to_list (namestring, strlen (namestring),
590 &objfile->static_psymbols,
591 dn_bufp->dsvar.location,
592 0, language_unknown, objfile);
596 case DNTT_TYPE_MEMENUM:
597 case DNTT_TYPE_CONST:
598 /* Constants and members of enumerated types. */
599 SET_NAMESTRING (dn_bufp, &namestring, objfile);
602 pst = hpread_start_psymtab (objfile,
605 * sizeof (struct dntt_type_block)),
606 objfile->global_psymbols.next,
607 objfile->static_psymbols.next);
609 add_psymbol_to_list (namestring, strlen (namestring),
610 VAR_NAMESPACE, LOC_CONST,
611 &objfile->static_psymbols, 0,
612 0, language_unknown, objfile);
620 /* End any pending partial symbol table. */
623 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
624 hp_symnum * sizeof (struct dntt_type_block),
625 0, dependency_list, dependencies_used);
628 discard_cleanups (old_chain);
631 /* Perform any local cleanups required when we are done with a particular
632 objfile. I.E, we are in the process of discarding all symbol information
633 for an objfile, freeing up all memory held for it, and unlinking the
634 objfile struct from the global list of known objfiles. */
637 hpread_symfile_finish (objfile)
638 struct objfile *objfile;
640 if (objfile->sym_private != NULL)
642 mfree (objfile->md, objfile->sym_private);
647 /* The remaining functions are all for internal use only. */
649 /* Various small functions to get entries in the debug symbol sections. */
651 static union dnttentry *
652 hpread_get_lntt (index, objfile)
654 struct objfile *objfile;
656 return (union dnttentry *)
657 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
660 static union dnttentry *
661 hpread_get_gntt (index, objfile)
663 struct objfile *objfile;
665 return (union dnttentry *)
666 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
669 static union sltentry *
670 hpread_get_slt (index, objfile)
672 struct objfile *objfile;
674 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
677 /* Get the low address associated with some symbol (typically the start
678 of a particular source file or module). Since that information is not
679 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
680 the existance of DNTT_TYPE_FUNCTION symbols. */
683 hpread_get_textlow (global, index, objfile)
686 struct objfile *objfile;
688 union dnttentry *dn_bufp;
689 struct minimal_symbol *msymbol;
691 /* Look for a DNTT_TYPE_FUNCTION symbol. */
695 dn_bufp = hpread_get_gntt (index++, objfile);
697 dn_bufp = hpread_get_lntt (index++, objfile);
699 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
700 && dn_bufp->dblock.kind != DNTT_TYPE_END);
702 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
703 might happen when a sourcefile has no functions. */
704 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
707 /* The minimal symbols are typically more accurate for some reason. */
708 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
711 return SYMBOL_VALUE_ADDRESS (msymbol);
713 return dn_bufp->dfunc.lowaddr;
716 /* Get the nesting depth for the source line identified by INDEX. */
719 hpread_get_depth (index, objfile)
721 struct objfile *objfile;
723 union sltentry *sl_bufp;
725 sl_bufp = hpread_get_slt (index, objfile);
726 return sl_bufp->sspec.backptr.dnttp.index;
729 /* Get the source line number the the line identified by INDEX. */
732 hpread_get_line (index, objfile)
734 struct objfile *objfile;
736 union sltentry *sl_bufp;
738 sl_bufp = hpread_get_slt (index, objfile);
739 return sl_bufp->snorm.line;
743 hpread_get_location (index, objfile)
745 struct objfile *objfile;
747 union sltentry *sl_bufp;
750 /* code location of special sltentrys is determined from context */
751 sl_bufp = hpread_get_slt (index, objfile);
753 if (sl_bufp->snorm.sltdesc == SLT_END)
755 /* find previous normal sltentry and get address */
756 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
757 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
758 sl_bufp = hpread_get_slt (index - i, objfile);
759 return sl_bufp->snorm.address;
762 /* find next normal sltentry and get address */
763 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
764 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
765 sl_bufp = hpread_get_slt (index + i, objfile);
766 return sl_bufp->snorm.address;
770 /* Return 1 if an HP debug symbol of type KIND has a name associated with
771 it, else return 0. */
774 hpread_has_name (kind)
775 enum dntt_entry_type kind;
779 case DNTT_TYPE_SRCFILE:
780 case DNTT_TYPE_MODULE:
781 case DNTT_TYPE_FUNCTION:
782 case DNTT_TYPE_ENTRY:
783 case DNTT_TYPE_IMPORT:
784 case DNTT_TYPE_LABEL:
785 case DNTT_TYPE_FPARAM:
788 case DNTT_TYPE_CONST:
789 case DNTT_TYPE_TYPEDEF:
790 case DNTT_TYPE_TAGDEF:
791 case DNTT_TYPE_MEMENUM:
792 case DNTT_TYPE_FIELD:
796 case DNTT_TYPE_BEGIN:
799 case DNTT_TYPE_COMMON:
800 case DNTT_TYPE_POINTER:
803 case DNTT_TYPE_SUBRANGE:
804 case DNTT_TYPE_ARRAY:
805 case DNTT_TYPE_STRUCT:
806 case DNTT_TYPE_UNION:
807 case DNTT_TYPE_VARIANT:
809 case DNTT_TYPE_FUNCTYPE:
810 case DNTT_TYPE_COBSTRUCT:
812 case DNTT_TYPE_MACRO:
818 /* Allocate and partially fill a partial symtab. It will be
819 completely filled at the end of the symbol list.
821 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
822 is the address relative to which its symbols are (incremental) or 0
825 static struct partial_symtab *
826 hpread_start_psymtab (objfile, filename, textlow, ldsymoff, global_syms,
828 struct objfile *objfile;
832 struct partial_symbol **global_syms;
833 struct partial_symbol **static_syms;
835 struct partial_symtab *result =
836 start_psymtab_common (objfile, section_offsets,
837 filename, textlow, global_syms, static_syms);
839 result->read_symtab_private = (char *)
840 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
841 LDSYMOFF (result) = ldsymoff;
842 result->read_symtab = hpread_psymtab_to_symtab;
848 /* Close off the current usage of PST.
849 Returns PST or NULL if the partial symtab was empty and thrown away.
851 FIXME: List variables and peculiarities of same. */
853 static struct partial_symtab *
854 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
855 capping_text, dependency_list, number_dependencies)
856 struct partial_symtab *pst;
859 int capping_symbol_offset;
860 CORE_ADDR capping_text;
861 struct partial_symtab **dependency_list;
862 int number_dependencies;
865 struct objfile *objfile = pst->objfile;
867 if (capping_symbol_offset != -1)
868 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
869 pst->texthigh = capping_text;
872 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
874 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
876 pst->number_of_dependencies = number_dependencies;
877 if (number_dependencies)
879 pst->dependencies = (struct partial_symtab **)
880 obstack_alloc (&objfile->psymbol_obstack,
881 number_dependencies * sizeof (struct partial_symtab *));
882 memcpy (pst->dependencies, dependency_list,
883 number_dependencies * sizeof (struct partial_symtab *));
886 pst->dependencies = 0;
888 for (i = 0; i < num_includes; i++)
890 struct partial_symtab *subpst =
891 allocate_psymtab (include_list[i], objfile);
893 subpst->section_offsets = pst->section_offsets;
894 subpst->read_symtab_private =
895 (char *) obstack_alloc (&objfile->psymbol_obstack,
896 sizeof (struct symloc));
900 subpst->texthigh = 0;
902 /* We could save slight bits of space by only making one of these,
903 shared by the entire set of include files. FIXME-someday. */
904 subpst->dependencies = (struct partial_symtab **)
905 obstack_alloc (&objfile->psymbol_obstack,
906 sizeof (struct partial_symtab *));
907 subpst->dependencies[0] = pst;
908 subpst->number_of_dependencies = 1;
910 subpst->globals_offset =
911 subpst->n_global_syms =
912 subpst->statics_offset =
913 subpst->n_static_syms = 0;
917 subpst->read_symtab = pst->read_symtab;
920 sort_pst_symbols (pst);
922 /* If there is already a psymtab or symtab for a file of this name, remove it.
923 (If there is a symtab, more drastic things also happen.)
924 This happens in VxWorks. */
925 free_named_symtabs (pst->filename);
927 if (num_includes == 0
928 && number_dependencies == 0
929 && pst->n_global_syms == 0
930 && pst->n_static_syms == 0)
932 /* Throw away this psymtab, it's empty. We can't deallocate it, since
933 it is on the obstack, but we can forget to chain it on the list. */
934 /* Empty psymtabs happen as a result of header files which don't have
935 any symbols in them. There can be a lot of them. But this check
936 is wrong, in that a psymtab with N_SLINE entries but nothing else
937 is not empty, but we don't realize that. Fixing that without slowing
938 things down might be tricky. */
940 discard_psymtab (pst);
942 /* Indicate that psymtab was thrown away. */
943 pst = (struct partial_symtab *) NULL;
948 /* Do the dirty work of reading in the full symbol from a partial symbol
952 hpread_psymtab_to_symtab_1 (pst)
953 struct partial_symtab *pst;
955 struct cleanup *old_chain;
958 /* Get out quick if passed junk. */
962 /* Complain if we've already read in this symbol table. */
965 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
970 /* Read in all partial symtabs on which this one is dependent */
971 for (i = 0; i < pst->number_of_dependencies; i++)
972 if (!pst->dependencies[i]->readin)
974 /* Inform about additional files that need to be read in. */
977 fputs_filtered (" ", gdb_stdout);
979 fputs_filtered ("and ", gdb_stdout);
981 printf_filtered ("%s...", pst->dependencies[i]->filename);
982 wrap_here (""); /* Flush output */
983 gdb_flush (gdb_stdout);
985 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
988 /* If it's real... */
991 /* Init stuff necessary for reading in symbols */
993 old_chain = make_cleanup (really_free_pendings, 0);
996 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
997 pst->textlow, pst->texthigh - pst->textlow,
998 pst->section_offsets, pst->filename);
999 sort_symtab_syms (pst->symtab);
1001 do_cleanups (old_chain);
1007 /* Read in all of the symbols for a given psymtab for real.
1008 Be verbose about it if the user wants that. */
1011 hpread_psymtab_to_symtab (pst)
1012 struct partial_symtab *pst;
1014 /* Get out quick if given junk. */
1021 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1026 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1028 /* Print the message now, before reading the string table,
1029 to avoid disconcerting pauses. */
1032 printf_filtered ("Reading in symbols for %s...", pst->filename);
1033 gdb_flush (gdb_stdout);
1036 hpread_psymtab_to_symtab_1 (pst);
1038 /* Match with global symbols. This only needs to be done once,
1039 after all of the symtabs and dependencies have been read in. */
1040 scan_file_globals (pst->objfile);
1042 /* Finish up the debug error message. */
1044 printf_filtered ("done.\n");
1047 /* Read in a defined section of a specific object file's symbols.
1049 DESC is the file descriptor for the file, positioned at the
1050 beginning of the symtab
1051 SYM_OFFSET is the offset within the file of
1052 the beginning of the symbols we want to read
1053 SYM_SIZE is the size of the symbol info to read in.
1054 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1055 TEXT_SIZE is the size of the text segment read in.
1056 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1058 static struct symtab *
1059 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1060 section_offsets, filename)
1061 struct objfile *objfile;
1064 CORE_ADDR text_offset;
1066 struct section_offsets *section_offsets;
1070 union dnttentry *dn_bufp;
1071 unsigned max_symnum;
1073 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1075 current_objfile = objfile;
1078 last_source_file = 0;
1080 dn_bufp = hpread_get_lntt (sym_index, objfile);
1081 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1082 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1084 start_symtab ("globals", NULL, 0);
1085 record_debugformat ("HP");
1088 max_symnum = sym_size / sizeof (struct dntt_type_block);
1090 /* Read in and process each debug symbol within the specified range. */
1092 symnum < max_symnum;
1095 QUIT; /* Allow this to be interruptable */
1096 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1098 if (dn_bufp->dblock.extension)
1101 /* Yow! We call SET_NAMESTRING on things without names! */
1102 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1104 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1105 objfile, text_offset, text_size,
1106 filename, symnum + sym_index);
1109 current_objfile = NULL;
1111 return end_symtab (text_offset + text_size, objfile, 0);
1115 /* Convert basic types from HP debug format into GDB internal format. */
1118 hpread_type_translate (typep)
1121 if (!typep.dntti.immediate)
1124 switch (typep.dntti.type)
1126 case HP_TYPE_BOOLEAN:
1127 case HP_TYPE_BOOLEAN_S300_COMPAT:
1128 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1130 /* Ugh. No way to distinguish between signed and unsigned chars. */
1132 case HP_TYPE_WIDE_CHAR:
1135 if (typep.dntti.bitlength <= 8)
1137 if (typep.dntti.bitlength <= 16)
1139 if (typep.dntti.bitlength <= 32)
1141 return FT_LONG_LONG;
1144 case HP_TYPE_UNSIGNED_LONG:
1145 if (typep.dntti.bitlength <= 8)
1146 return FT_UNSIGNED_CHAR;
1147 if (typep.dntti.bitlength <= 16)
1148 return FT_UNSIGNED_SHORT;
1149 if (typep.dntti.bitlength <= 32)
1150 return FT_UNSIGNED_LONG;
1151 return FT_UNSIGNED_LONG_LONG;
1152 case HP_TYPE_UNSIGNED_INT:
1153 if (typep.dntti.bitlength <= 8)
1154 return FT_UNSIGNED_CHAR;
1155 if (typep.dntti.bitlength <= 16)
1156 return FT_UNSIGNED_SHORT;
1157 if (typep.dntti.bitlength <= 32)
1158 return FT_UNSIGNED_INTEGER;
1159 return FT_UNSIGNED_LONG_LONG;
1161 case HP_TYPE_REAL_3000:
1162 case HP_TYPE_DOUBLE:
1163 if (typep.dntti.bitlength == 64)
1164 return FT_DBL_PREC_FLOAT;
1165 if (typep.dntti.bitlength == 128)
1166 return FT_EXT_PREC_FLOAT;
1168 case HP_TYPE_COMPLEX:
1169 case HP_TYPE_COMPLEXS3000:
1170 if (typep.dntti.bitlength == 128)
1171 return FT_DBL_PREC_COMPLEX;
1172 if (typep.dntti.bitlength == 192)
1173 return FT_EXT_PREC_COMPLEX;
1175 case HP_TYPE_STRING200:
1176 case HP_TYPE_LONGSTRING200:
1177 case HP_TYPE_FTN_STRING_SPEC:
1178 case HP_TYPE_MOD_STRING_SPEC:
1179 case HP_TYPE_MOD_STRING_3000:
1180 case HP_TYPE_FTN_STRING_S300_COMPAT:
1181 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1188 /* Return the type associated with the index found in HP_TYPE. */
1190 static struct type **
1191 hpread_lookup_type (hp_type, objfile)
1192 dnttpointer hp_type;
1193 struct objfile *objfile;
1196 int index = hp_type.dnttp.index;
1198 if (hp_type.dntti.immediate)
1201 if (index < LNTT_SYMCOUNT (objfile))
1203 if (index >= TYPE_VECTOR_LENGTH (objfile))
1205 old_len = TYPE_VECTOR_LENGTH (objfile);
1208 TYPE_VECTOR_LENGTH (objfile) = 100;
1209 TYPE_VECTOR (objfile) = (struct type **)
1210 xmmalloc (objfile->md,
1211 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1213 while (index >= TYPE_VECTOR_LENGTH (objfile))
1214 TYPE_VECTOR_LENGTH (objfile) *= 2;
1215 TYPE_VECTOR (objfile) = (struct type **)
1216 xmrealloc (objfile->md,
1217 (char *) TYPE_VECTOR (objfile),
1218 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1219 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1220 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1221 sizeof (struct type *));
1223 return &TYPE_VECTOR (objfile)[index];
1229 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1230 Note we'll just return the address of a GDB internal type if we already
1231 have it lying around. */
1233 static struct type *
1234 hpread_alloc_type (hp_type, objfile)
1235 dnttpointer hp_type;
1236 struct objfile *objfile;
1238 struct type **type_addr;
1240 type_addr = hpread_lookup_type (hp_type, objfile);
1241 if (*type_addr == 0)
1242 *type_addr = alloc_type (objfile);
1244 TYPE_CPLUS_SPECIFIC (*type_addr)
1245 = (struct cplus_struct_type *) &cplus_struct_default;
1249 /* Read a native enumerated type and return it in GDB internal form. */
1251 static struct type *
1252 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1253 dnttpointer hp_type;
1254 union dnttentry *dn_bufp;
1255 struct objfile *objfile;
1258 struct pending **symlist, *osyms, *syms;
1259 int o_nsyms, nsyms = 0;
1261 union dnttentry *memp;
1266 type = hpread_alloc_type (hp_type, objfile);
1267 TYPE_LENGTH (type) = 4;
1269 symlist = &file_symbols;
1271 o_nsyms = osyms ? osyms->nsyms : 0;
1273 /* Get a name for each member and add it to our list of members. */
1274 mem = dn_bufp->denum.firstmem;
1275 while (mem.dnttp.extension && mem.word != DNTTNIL)
1277 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1279 name = VT (objfile) + memp->dmember.name;
1280 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1281 sizeof (struct symbol));
1282 memset (sym, 0, sizeof (struct symbol));
1283 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1284 &objfile->symbol_obstack);
1285 SYMBOL_CLASS (sym) = LOC_CONST;
1286 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1287 SYMBOL_VALUE (sym) = memp->dmember.value;
1288 add_symbol_to_list (sym, symlist);
1290 mem = memp->dmember.nextmem;
1293 /* Now that we know more about the enum, fill in more info. */
1294 TYPE_CODE (type) = TYPE_CODE_ENUM;
1295 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1296 TYPE_NFIELDS (type) = nsyms;
1297 TYPE_FIELDS (type) = (struct field *)
1298 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1300 /* Find the symbols for the members and put them into the type.
1301 The symbols can be found in the symlist that we put them on
1302 to cause them to be defined. osyms contains the old value
1303 of that symlist; everything up to there was defined by us.
1305 Note that we preserve the order of the enum constants, so
1306 that in something like "enum {FOO, LAST_THING=FOO}" we print
1307 FOO, not LAST_THING. */
1308 for (syms = *symlist, n = 0; syms; syms = syms->next)
1313 for (; j < syms->nsyms; j++, n++)
1315 struct symbol *xsym = syms->symbol[j];
1316 SYMBOL_TYPE (xsym) = type;
1317 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1318 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1319 TYPE_FIELD_BITSIZE (type, n) = 0;
1328 /* Read and internalize a native function debug symbol. */
1330 static struct type *
1331 hpread_read_function_type (hp_type, dn_bufp, objfile)
1332 dnttpointer hp_type;
1333 union dnttentry *dn_bufp;
1334 struct objfile *objfile;
1336 struct type *type, *type1;
1337 struct pending **symlist, *osyms, *syms;
1338 int o_nsyms, nsyms = 0;
1340 union dnttentry *paramp;
1345 param = dn_bufp->dfunc.firstparam;
1347 /* See if we've already read in this type. */
1348 type = hpread_alloc_type (hp_type, objfile);
1349 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1352 /* Nope, so read it in and store it away. */
1353 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1355 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1357 symlist = &local_symbols;
1359 o_nsyms = osyms ? osyms->nsyms : 0;
1361 /* Now examine each parameter noting its type, location, and a
1362 wealth of other information. */
1363 while (param.word && param.word != DNTTNIL)
1365 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1367 param = paramp->dfparam.nextparam;
1370 name = VT (objfile) + paramp->dfparam.name;
1371 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1372 sizeof (struct symbol));
1373 (void) memset (sym, 0, sizeof (struct symbol));
1374 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1375 &objfile->symbol_obstack);
1377 /* Figure out where it lives. */
1378 if (paramp->dfparam.regparam)
1379 SYMBOL_CLASS (sym) = LOC_REGPARM;
1380 else if (paramp->dfparam.indirect)
1381 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1383 SYMBOL_CLASS (sym) = LOC_ARG;
1384 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1385 if (paramp->dfparam.copyparam)
1387 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1388 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1390 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1392 /* This is likely a pass-by-invisible reference parameter,
1393 Hack on the symbol class to make GDB happy. */
1394 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1397 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1400 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1402 /* Add it to the list. */
1403 add_symbol_to_list (sym, symlist);
1406 /* Note how many parameters we found. */
1407 TYPE_NFIELDS (type) = nsyms;
1408 TYPE_FIELDS (type) = (struct field *)
1409 obstack_alloc (&objfile->type_obstack,
1410 sizeof (struct field) * nsyms);
1412 /* Find the symbols for the values and put them into the type.
1413 The symbols can be found in the symlist that we put them on
1414 to cause them to be defined. osyms contains the old value
1415 of that symlist; everything up to there was defined by us. */
1416 /* Note that we preserve the order of the parameters, so
1417 that in something like "enum {FOO, LAST_THING=FOO}" we print
1418 FOO, not LAST_THING. */
1419 for (syms = *symlist, n = 0; syms; syms = syms->next)
1424 for (; j < syms->nsyms; j++, n++)
1426 struct symbol *xsym = syms->symbol[j];
1427 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1428 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1429 TYPE_FIELD_BITPOS (type, n) = n;
1430 TYPE_FIELD_BITSIZE (type, n) = 0;
1438 /* Read in and internalize a structure definition. */
1440 static struct type *
1441 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1442 dnttpointer hp_type;
1443 union dnttentry *dn_bufp;
1444 struct objfile *objfile;
1448 struct nextfield *next;
1453 struct nextfield *list = 0;
1454 struct nextfield *new;
1457 union dnttentry *fieldp;
1459 /* Is it something we've already dealt with? */
1460 type = hpread_alloc_type (hp_type, objfile);
1461 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1462 (TYPE_CODE (type) == TYPE_CODE_UNION))
1465 /* Get the basic type correct. */
1466 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1468 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1469 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1471 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1473 TYPE_CODE (type) = TYPE_CODE_UNION;
1474 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1480 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1482 /* Read in and internalize all the fields. */
1483 field = dn_bufp->dstruct.firstfield;
1484 while (field.word != DNTTNIL && field.dnttp.extension)
1486 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1488 /* Get space to record the next field's data. */
1489 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1493 list->field.name = VT (objfile) + fieldp->dfield.name;
1494 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1495 if (fieldp->dfield.bitlength % 8)
1496 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1498 FIELD_BITSIZE (list->field) = 0;
1500 field = fieldp->dfield.nextfield;
1501 FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1505 TYPE_NFIELDS (type) = nfields;
1506 TYPE_FIELDS (type) = (struct field *)
1507 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1509 /* Copy the saved-up fields into the field vector. */
1510 for (n = nfields; list; list = list->next)
1513 TYPE_FIELD (type, n) = list->field;
1518 /* Read in and internalize a set debug symbol. */
1520 static struct type *
1521 hpread_read_set_type (hp_type, dn_bufp, objfile)
1522 dnttpointer hp_type;
1523 union dnttentry *dn_bufp;
1524 struct objfile *objfile;
1528 /* See if it's something we've already deal with. */
1529 type = hpread_alloc_type (hp_type, objfile);
1530 if (TYPE_CODE (type) == TYPE_CODE_SET)
1533 /* Nope. Fill in the appropriate fields. */
1534 TYPE_CODE (type) = TYPE_CODE_SET;
1535 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1536 TYPE_NFIELDS (type) = 0;
1537 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1542 /* Read in and internalize an array debug symbol. */
1544 static struct type *
1545 hpread_read_array_type (hp_type, dn_bufp, objfile)
1546 dnttpointer hp_type;
1547 union dnttentry *dn_bufp;
1548 struct objfile *objfile;
1551 union dnttentry save;
1554 /* Why no check here? Because it kept us from properly determining
1555 the size of the array! */
1556 type = hpread_alloc_type (hp_type, objfile);
1558 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1560 /* values are not normalized. */
1561 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1562 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1564 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1566 /* The HP debug format represents char foo[]; as an array with
1567 length 0x7fffffff. Internally GDB wants to represent this
1568 as an array of length zero. */
1569 TYPE_LENGTH (type) = 0;
1572 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1574 TYPE_NFIELDS (type) = 1;
1575 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1578 TYPE_FIELDS (type) = (struct field *)
1579 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1580 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1585 /* Read in and internalize a subrange debug symbol. */
1586 static struct type *
1587 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1588 dnttpointer hp_type;
1589 union dnttentry *dn_bufp;
1590 struct objfile *objfile;
1594 /* Is it something we've already dealt with. */
1595 type = hpread_alloc_type (hp_type, objfile);
1596 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1599 /* Nope, internalize it. */
1600 TYPE_CODE (type) = TYPE_CODE_RANGE;
1601 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1602 TYPE_NFIELDS (type) = 2;
1604 = (struct field *) obstack_alloc (&objfile->type_obstack,
1605 2 * sizeof (struct field));
1607 if (dn_bufp->dsubr.dyn_low)
1608 TYPE_FIELD_BITPOS (type, 0) = 0;
1610 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1612 if (dn_bufp->dsubr.dyn_high)
1613 TYPE_FIELD_BITPOS (type, 1) = -1;
1615 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1616 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1621 static struct type *
1622 hpread_type_lookup (hp_type, objfile)
1623 dnttpointer hp_type;
1624 struct objfile *objfile;
1626 union dnttentry *dn_bufp;
1628 /* First see if it's a simple builtin type. */
1629 if (hp_type.dntti.immediate)
1630 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1632 /* Not a builtin type. We'll have to read it in. */
1633 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1634 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1636 return lookup_fundamental_type (objfile, FT_VOID);
1638 switch (dn_bufp->dblock.kind)
1640 case DNTT_TYPE_SRCFILE:
1641 case DNTT_TYPE_MODULE:
1642 case DNTT_TYPE_FUNCTION:
1643 case DNTT_TYPE_ENTRY:
1644 case DNTT_TYPE_BEGIN:
1646 case DNTT_TYPE_IMPORT:
1647 case DNTT_TYPE_LABEL:
1648 case DNTT_TYPE_WITH:
1649 case DNTT_TYPE_COMMON:
1650 case DNTT_TYPE_FPARAM:
1651 case DNTT_TYPE_SVAR:
1652 case DNTT_TYPE_DVAR:
1653 case DNTT_TYPE_CONST:
1654 /* Opps. Something went very wrong. */
1655 return lookup_fundamental_type (objfile, FT_VOID);
1657 case DNTT_TYPE_TYPEDEF:
1659 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1662 suffix = VT (objfile) + dn_bufp->dtype.name;
1664 TYPE_CPLUS_SPECIFIC (structtype)
1665 = (struct cplus_struct_type *) &cplus_struct_default;
1666 TYPE_NAME (structtype) = suffix;
1670 case DNTT_TYPE_TAGDEF:
1672 /* Just a little different from above. We have to tack on
1673 an identifier of some kind (struct, union, enum, etc). */
1674 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1676 char *prefix, *suffix;
1677 suffix = VT (objfile) + dn_bufp->dtype.name;
1679 /* Lookup the next type in the list. It should be a structure,
1680 union, or enum type. We will need to attach that to our name. */
1681 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1682 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1686 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1688 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1693 /* Build the correct name. */
1695 = (char *) obstack_alloc (&objfile->type_obstack,
1696 strlen (prefix) + strlen (suffix) + 1);
1697 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1698 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1699 TYPE_TAG_NAME (structtype) = suffix;
1701 TYPE_CPLUS_SPECIFIC (structtype)
1702 = (struct cplus_struct_type *) &cplus_struct_default;
1706 case DNTT_TYPE_POINTER:
1707 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1709 case DNTT_TYPE_ENUM:
1710 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1711 case DNTT_TYPE_MEMENUM:
1712 return lookup_fundamental_type (objfile, FT_VOID);
1714 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1715 case DNTT_TYPE_SUBRANGE:
1716 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1717 case DNTT_TYPE_ARRAY:
1718 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1719 case DNTT_TYPE_STRUCT:
1720 case DNTT_TYPE_UNION:
1721 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1722 case DNTT_TYPE_FIELD:
1723 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1724 case DNTT_TYPE_VARIANT:
1725 case DNTT_TYPE_FILE:
1726 return lookup_fundamental_type (objfile, FT_VOID);
1727 case DNTT_TYPE_FUNCTYPE:
1728 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1730 case DNTT_TYPE_COBSTRUCT:
1731 case DNTT_TYPE_XREF:
1733 case DNTT_TYPE_MACRO:
1735 return lookup_fundamental_type (objfile, FT_VOID);
1740 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1741 struct subfile *subfile;
1742 sltpointer s_idx, e_idx;
1743 struct objfile *objfile;
1746 union sltentry *sl_bufp;
1748 while (s_idx <= e_idx)
1750 sl_bufp = hpread_get_slt (s_idx, objfile);
1751 /* Only record "normal" entries in the SLT. */
1752 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1753 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1754 record_line (subfile, sl_bufp->snorm.line,
1755 sl_bufp->snorm.address + offset);
1761 /* Internalize one native debug symbol. */
1764 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1765 text_offset, text_size, filename, index)
1766 union dnttentry *dn_bufp;
1768 struct section_offsets *section_offsets;
1769 struct objfile *objfile;
1770 CORE_ADDR text_offset;
1778 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1779 union dnttentry *dn_temp;
1780 dnttpointer hp_type;
1782 struct context_stack *new;
1784 /* Allocate one GDB debug symbol and fill in some default values. */
1785 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1786 sizeof (struct symbol));
1787 memset (sym, 0, sizeof (struct symbol));
1788 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1789 SYMBOL_LANGUAGE (sym) = language_auto;
1790 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1791 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1792 SYMBOL_LINE (sym) = 0;
1793 SYMBOL_VALUE (sym) = 0;
1794 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1796 hp_type.dnttp.extension = 1;
1797 hp_type.dnttp.immediate = 0;
1798 hp_type.dnttp.global = 0;
1799 hp_type.dnttp.index = index;
1801 type = dn_bufp->dblock.kind;
1805 case DNTT_TYPE_SRCFILE:
1806 /* This type of symbol indicates from which source file or include file
1807 the following data comes. If there are no modules it also may
1808 indicate the start of a new source file, in which case we must
1809 finish the symbol table of the previous source file
1810 (if any) and start accumulating a new symbol table. */
1813 if (!last_source_file)
1815 start_symtab (name, NULL, valu);
1816 record_debugformat ("HP");
1817 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1821 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1823 dn_bufp->dsfile.address,
1826 start_subfile (name, NULL);
1829 case DNTT_TYPE_MODULE:
1830 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1833 case DNTT_TYPE_FUNCTION:
1834 case DNTT_TYPE_ENTRY:
1835 /* A function or secondary entry point. */
1836 valu = dn_bufp->dfunc.lowaddr + offset;
1837 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1839 dn_bufp->dfunc.address,
1842 WITHIN_FUNCTION (objfile) = 1;
1843 CURRENT_FUNCTION_VALUE (objfile) = valu;
1845 /* Stack must be empty now. */
1846 if (context_stack_depth != 0)
1847 complain (&lbrac_unmatched_complaint, (char *) symnum);
1848 new = push_context (0, valu);
1850 SYMBOL_CLASS (sym) = LOC_BLOCK;
1851 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1852 if (dn_bufp->dfunc.global)
1853 add_symbol_to_list (sym, &global_symbols);
1855 add_symbol_to_list (sym, &file_symbols);
1858 /* Search forward to the next scope beginning. */
1859 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1861 dn_bufp = hpread_get_lntt (++index, objfile);
1862 if (dn_bufp->dblock.extension)
1865 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1867 dn_bufp->dbegin.address,
1869 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1870 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1873 case DNTT_TYPE_BEGIN:
1874 /* Begin a new scope. */
1875 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1877 dn_bufp->dbegin.address,
1879 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1880 valu += offset; /* Relocate for dynamic loading */
1881 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1882 new = push_context (desc, valu);
1887 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1889 dn_bufp->dend.address + 1,
1891 switch (dn_bufp->dend.endkind)
1893 case DNTT_TYPE_MODULE:
1894 /* Ending a module ends the symbol table for that module. */
1895 valu = text_offset + text_size + offset;
1896 (void) end_symtab (valu, objfile, 0);
1899 case DNTT_TYPE_FUNCTION:
1900 /* Ending a function, well, ends the function's scope. */
1901 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1903 valu = dn_temp->dfunc.hiaddr + offset;
1904 new = pop_context ();
1905 /* Make a block for the local symbols within. */
1906 finish_block (new->name, &local_symbols, new->old_blocks,
1907 new->start_addr, valu, objfile);
1908 WITHIN_FUNCTION (objfile) = 0;
1910 case DNTT_TYPE_BEGIN:
1911 /* Just ending a local scope. */
1912 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1913 /* Why in the hell is this needed? */
1914 valu += offset + 9; /* Relocate for dynamic loading */
1915 new = pop_context ();
1916 desc = dn_bufp->dend.beginscope.dnttp.index;
1917 if (desc != new->depth)
1918 complain (&lbrac_mismatch_complaint, (char *) symnum);
1919 /* Make a block for the local symbols within. */
1920 finish_block (new->name, &local_symbols, new->old_blocks,
1921 new->start_addr, valu, objfile);
1922 local_symbols = new->locals;
1926 case DNTT_TYPE_LABEL:
1927 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1929 case DNTT_TYPE_FPARAM:
1930 /* Function parameters. */
1931 if (dn_bufp->dfparam.regparam)
1932 SYMBOL_CLASS (sym) = LOC_REGISTER;
1934 SYMBOL_CLASS (sym) = LOC_LOCAL;
1935 if (dn_bufp->dfparam.copyparam)
1937 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1938 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1940 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1944 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1945 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1946 add_symbol_to_list (sym, &local_symbols);
1948 case DNTT_TYPE_SVAR:
1949 /* Static variables. */
1950 SYMBOL_CLASS (sym) = LOC_STATIC;
1951 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1952 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1953 if (dn_bufp->dsvar.global)
1954 add_symbol_to_list (sym, &global_symbols);
1955 else if (WITHIN_FUNCTION (objfile))
1956 add_symbol_to_list (sym, &local_symbols);
1958 add_symbol_to_list (sym, &file_symbols);
1960 case DNTT_TYPE_DVAR:
1961 /* Dynamic variables. */
1962 if (dn_bufp->ddvar.regvar)
1963 SYMBOL_CLASS (sym) = LOC_REGISTER;
1965 SYMBOL_CLASS (sym) = LOC_LOCAL;
1966 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1967 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1969 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1971 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1972 if (dn_bufp->ddvar.global)
1973 add_symbol_to_list (sym, &global_symbols);
1974 else if (WITHIN_FUNCTION (objfile))
1975 add_symbol_to_list (sym, &local_symbols);
1977 add_symbol_to_list (sym, &file_symbols);
1979 case DNTT_TYPE_CONST:
1980 /* A constant (pascal?). */
1981 SYMBOL_CLASS (sym) = LOC_CONST;
1982 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1983 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1984 if (dn_bufp->dconst.global)
1985 add_symbol_to_list (sym, &global_symbols);
1986 else if (WITHIN_FUNCTION (objfile))
1987 add_symbol_to_list (sym, &local_symbols);
1989 add_symbol_to_list (sym, &file_symbols);
1991 case DNTT_TYPE_TYPEDEF:
1992 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1993 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1994 if (dn_bufp->dtype.global)
1995 add_symbol_to_list (sym, &global_symbols);
1996 else if (WITHIN_FUNCTION (objfile))
1997 add_symbol_to_list (sym, &local_symbols);
1999 add_symbol_to_list (sym, &file_symbols);
2001 case DNTT_TYPE_TAGDEF:
2002 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2003 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2004 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2005 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2006 if (dn_bufp->dtype.global)
2007 add_symbol_to_list (sym, &global_symbols);
2008 else if (WITHIN_FUNCTION (objfile))
2009 add_symbol_to_list (sym, &local_symbols);
2011 add_symbol_to_list (sym, &file_symbols);
2013 case DNTT_TYPE_POINTER:
2014 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2015 (dn_bufp->dptr.pointsto,
2017 add_symbol_to_list (sym, &file_symbols);
2019 case DNTT_TYPE_ENUM:
2020 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2021 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2022 add_symbol_to_list (sym, &file_symbols);
2024 case DNTT_TYPE_MEMENUM:
2027 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2028 add_symbol_to_list (sym, &file_symbols);
2030 case DNTT_TYPE_SUBRANGE:
2031 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2033 add_symbol_to_list (sym, &file_symbols);
2035 case DNTT_TYPE_ARRAY:
2036 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2037 add_symbol_to_list (sym, &file_symbols);
2039 case DNTT_TYPE_STRUCT:
2040 case DNTT_TYPE_UNION:
2041 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2042 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2043 add_symbol_to_list (sym, &file_symbols);