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 (struct objfile *);
140 static struct type *hpread_read_array_type (dnttpointer, union dnttentry *,
143 static struct type *hpread_alloc_type (dnttpointer, struct objfile *);
145 static struct type **hpread_lookup_type (dnttpointer, struct objfile *);
147 static struct type *hpread_read_enum_type
148 (dnttpointer, union dnttentry *, struct objfile *);
150 static struct type *hpread_read_set_type
151 (dnttpointer, union dnttentry *, struct objfile *);
153 static struct type *hpread_read_subrange_type
154 (dnttpointer, union dnttentry *, struct objfile *);
156 static struct type *hpread_read_struct_type
157 (dnttpointer, union dnttentry *, struct objfile *);
159 void hpread_build_psymtabs (struct objfile *, int);
161 void hpread_symfile_finish (struct objfile *);
163 static struct partial_symtab *hpread_start_psymtab
164 (struct objfile *, char *, CORE_ADDR, int,
165 struct partial_symbol **, struct partial_symbol **);
167 static struct partial_symtab *hpread_end_psymtab
168 (struct partial_symtab *, char **, int, int, CORE_ADDR,
169 struct partial_symtab **, int);
171 static struct symtab *hpread_expand_symtab
172 (struct objfile *, int, int, CORE_ADDR, int,
173 struct section_offsets *, char *);
175 static void hpread_process_one_debug_symbol
176 (union dnttentry *, char *, struct section_offsets *,
177 struct objfile *, CORE_ADDR, int, char *, int);
179 static sltpointer hpread_record_lines
180 (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR);
182 static struct type *hpread_read_function_type
183 (dnttpointer, union dnttentry *, struct objfile *);
185 static struct type *hpread_type_lookup (dnttpointer, struct objfile *);
187 static unsigned long hpread_get_depth (sltpointer, struct objfile *);
189 static unsigned long hpread_get_line (sltpointer, struct objfile *);
191 static CORE_ADDR hpread_get_location (sltpointer, struct objfile *);
193 static int hpread_type_translate (dnttpointer);
194 static unsigned long hpread_get_textlow (int, int, struct objfile *);
195 static union dnttentry *hpread_get_gntt (int, struct objfile *);
196 static union dnttentry *hpread_get_lntt (int, struct objfile *);
197 static union sltentry *hpread_get_slt (int, struct objfile *);
198 static void hpread_psymtab_to_symtab (struct partial_symtab *);
199 static void hpread_psymtab_to_symtab_1 (struct partial_symtab *);
200 static int hpread_has_name (enum dntt_entry_type);
203 /* Initialization for reading native HP C debug symbols from OBJFILE.
205 It's only purpose in life is to set up the symbol reader's private
206 per-objfile data structures, and read in the raw contents of the debug
207 sections (attaching pointers to the debug info into the private data
210 Since BFD doesn't know how to read debug symbols in a format-independent
211 way (and may never do so...), we have to do it ourselves. Note we may
212 be called on a file without native HP C debugging symbols.
213 FIXME, there should be a cleaner peephole into the BFD environment here. */
216 hpread_symfile_init (objfile)
217 struct objfile *objfile;
219 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
221 /* Allocate struct to keep track of the symfile */
222 objfile->sym_private = (PTR)
223 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
224 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
226 /* We haven't read in any types yet. */
227 TYPE_VECTOR (objfile) = 0;
229 /* Read in data from the $GNTT$ subspace. */
230 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
235 = obstack_alloc (&objfile->symbol_obstack,
236 bfd_section_size (objfile->obfd, gntt_section));
238 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
239 0, bfd_section_size (objfile->obfd, gntt_section));
241 GNTT_SYMCOUNT (objfile)
242 = bfd_section_size (objfile->obfd, gntt_section)
243 / sizeof (struct dntt_type_block);
245 /* Read in data from the $LNTT$ subspace. Also keep track of the number
247 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
252 = obstack_alloc (&objfile->symbol_obstack,
253 bfd_section_size (objfile->obfd, lntt_section));
255 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
256 0, bfd_section_size (objfile->obfd, lntt_section));
258 LNTT_SYMCOUNT (objfile)
259 = bfd_section_size (objfile->obfd, lntt_section)
260 / sizeof (struct dntt_type_block);
262 /* Read in data from the $SLT$ subspace. $SLT$ contains information
263 on source line numbers. */
264 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
269 obstack_alloc (&objfile->symbol_obstack,
270 bfd_section_size (objfile->obfd, slt_section));
272 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
273 0, bfd_section_size (objfile->obfd, slt_section));
275 /* Read in data from the $VT$ subspace. $VT$ contains things like
276 names and constants. Keep track of the number of symbols in the VT. */
277 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
281 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
284 (char *) obstack_alloc (&objfile->symbol_obstack,
287 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
288 0, VT_SIZE (objfile));
291 /* Scan and build partial symbols for a symbol file.
293 The minimal symbol table (either SOM or HP a.out) has already been
294 read in; all we need to do is setup partial symbols based on the
295 native debugging information.
297 We assume hpread_symfile_init has been called to initialize the
298 symbol reader's private data structures.
300 MAINLINE is true if we are reading the main symbol
301 table (as opposed to a shared lib or dynamically loaded file). */
304 hpread_build_psymtabs (objfile, mainline)
305 struct objfile *objfile;
309 int past_first_source_file = 0;
310 struct cleanup *old_chain;
312 int hp_symnum, symcount, i;
314 union dnttentry *dn_bufp;
320 /* Current partial symtab */
321 struct partial_symtab *pst;
323 /* List of current psymtab's include files */
324 char **psymtab_include_list;
325 int includes_allocated;
328 /* Index within current psymtab dependency list */
329 struct partial_symtab **dependency_list;
330 int dependencies_used, dependencies_allocated;
332 /* Just in case the stabs reader left turds lying around. */
333 free_pending_blocks ();
334 make_cleanup (really_free_pendings, 0);
336 pst = (struct partial_symtab *) 0;
338 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
339 a number of problems with cross compilation and creating useless holes
340 in the stack when we have to allocate new entries. FIXME. */
342 includes_allocated = 30;
344 psymtab_include_list = (char **) alloca (includes_allocated *
347 dependencies_allocated = 30;
348 dependencies_used = 0;
350 (struct partial_symtab **) alloca (dependencies_allocated *
351 sizeof (struct partial_symtab *));
353 old_chain = make_cleanup_free_objfile (objfile);
355 last_source_file = 0;
357 /* Make two passes, one ofr the GNTT symbols, the other for the
359 for (i = 0; i < 1; i++)
361 int within_function = 0;
364 symcount = GNTT_SYMCOUNT (objfile);
366 symcount = LNTT_SYMCOUNT (objfile);
368 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
372 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
374 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
376 if (dn_bufp->dblock.extension)
379 /* Only handle things which are necessary for minimal symbols.
380 everything else is ignored. */
381 switch (dn_bufp->dblock.kind)
383 case DNTT_TYPE_SRCFILE:
385 /* A source file of some kind. Note this may simply
386 be an included file. */
387 SET_NAMESTRING (dn_bufp, &namestring, objfile);
389 /* Check if this is the source file we are already working
391 if (pst && !strcmp (namestring, pst->filename))
394 /* Check if this is an include file, if so check if we have
395 already seen it. Add it to the include list */
396 p = strrchr (namestring, '.');
397 if (!strcmp (p, ".h"))
402 for (j = 0; j < includes_used; j++)
403 if (!strcmp (namestring, psymtab_include_list[j]))
411 /* Add it to the list of includes seen so far and
412 allocate more include space if necessary. */
413 psymtab_include_list[includes_used++] = namestring;
414 if (includes_used >= includes_allocated)
416 char **orig = psymtab_include_list;
418 psymtab_include_list = (char **)
419 alloca ((includes_allocated *= 2) *
421 memcpy ((PTR) psymtab_include_list, (PTR) orig,
422 includes_used * sizeof (char *));
432 pst->filename = (char *)
433 obstack_alloc (&pst->objfile->psymbol_obstack,
434 strlen (namestring) + 1);
435 strcpy (pst->filename, namestring);
442 /* This is a bonafide new source file.
443 End the current partial symtab and start a new one. */
445 if (pst && past_first_source_file)
447 hpread_end_psymtab (pst, psymtab_include_list,
450 * sizeof (struct dntt_type_block)),
452 dependency_list, dependencies_used);
453 pst = (struct partial_symtab *) 0;
455 dependencies_used = 0;
458 past_first_source_file = 1;
460 valu = hpread_get_textlow (i, hp_symnum, objfile);
461 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
462 pst = hpread_start_psymtab (objfile,
465 * sizeof (struct dntt_type_block)),
466 objfile->global_psymbols.next,
467 objfile->static_psymbols.next);
473 case DNTT_TYPE_MODULE:
474 /* A source file. It's still unclear to me what the
475 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
476 is supposed to be. */
477 SET_NAMESTRING (dn_bufp, &namestring, objfile);
478 valu = hpread_get_textlow (i, hp_symnum, objfile);
479 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
482 pst = hpread_start_psymtab (objfile,
485 * sizeof (struct dntt_type_block)),
486 objfile->global_psymbols.next,
487 objfile->static_psymbols.next);
492 case DNTT_TYPE_FUNCTION:
493 case DNTT_TYPE_ENTRY:
494 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
495 a secondary entry point. */
496 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
497 SECT_OFF_TEXT (objfile));
500 valu = dn_bufp->dfunc.lowaddr +
501 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
502 SET_NAMESTRING (dn_bufp, &namestring, objfile);
503 add_psymbol_to_list (namestring, strlen (namestring),
504 VAR_NAMESPACE, LOC_BLOCK,
505 &objfile->static_psymbols, valu,
506 0, language_unknown, objfile);
509 case DNTT_TYPE_BEGIN:
511 /* Scope block begin/end. We only care about function
512 and file blocks right now. */
513 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
515 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
517 * sizeof (struct dntt_type_block)),
519 dependency_list, dependencies_used);
520 pst = (struct partial_symtab *) 0;
522 dependencies_used = 0;
525 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
530 case DNTT_TYPE_TYPEDEF:
531 case DNTT_TYPE_TAGDEF:
533 /* Variables, typedefs an the like. */
534 enum address_class storage;
535 namespace_enum namespace;
537 /* Don't add locals to the partial symbol table. */
539 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
540 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
543 /* TAGDEFs go into the structure namespace. */
544 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
545 namespace = STRUCT_NAMESPACE;
547 namespace = VAR_NAMESPACE;
549 /* What kind of "storage" does this use? */
550 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
551 storage = LOC_STATIC;
552 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
553 && dn_bufp->ddvar.regvar)
554 storage = LOC_REGISTER;
555 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
560 SET_NAMESTRING (dn_bufp, &namestring, objfile);
563 pst = hpread_start_psymtab (objfile,
566 * sizeof (struct dntt_type_block)),
567 objfile->global_psymbols.next,
568 objfile->static_psymbols.next);
570 if (dn_bufp->dsvar.global)
572 add_psymbol_to_list (namestring, strlen (namestring),
574 &objfile->global_psymbols,
575 dn_bufp->dsvar.location,
576 0, language_unknown, objfile);
580 add_psymbol_to_list (namestring, strlen (namestring),
582 &objfile->static_psymbols,
583 dn_bufp->dsvar.location,
584 0, language_unknown, objfile);
588 case DNTT_TYPE_MEMENUM:
589 case DNTT_TYPE_CONST:
590 /* Constants and members of enumerated types. */
591 SET_NAMESTRING (dn_bufp, &namestring, objfile);
594 pst = hpread_start_psymtab (objfile,
597 * sizeof (struct dntt_type_block)),
598 objfile->global_psymbols.next,
599 objfile->static_psymbols.next);
601 add_psymbol_to_list (namestring, strlen (namestring),
602 VAR_NAMESPACE, LOC_CONST,
603 &objfile->static_psymbols, 0,
604 0, language_unknown, objfile);
612 /* End any pending partial symbol table. */
615 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
616 hp_symnum * sizeof (struct dntt_type_block),
617 0, dependency_list, dependencies_used);
620 discard_cleanups (old_chain);
623 /* Perform any local cleanups required when we are done with a particular
624 objfile. I.E, we are in the process of discarding all symbol information
625 for an objfile, freeing up all memory held for it, and unlinking the
626 objfile struct from the global list of known objfiles. */
629 hpread_symfile_finish (objfile)
630 struct objfile *objfile;
632 if (objfile->sym_private != NULL)
634 mfree (objfile->md, objfile->sym_private);
639 /* The remaining functions are all for internal use only. */
641 /* Various small functions to get entries in the debug symbol sections. */
643 static union dnttentry *
644 hpread_get_lntt (index, objfile)
646 struct objfile *objfile;
648 return (union dnttentry *)
649 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
652 static union dnttentry *
653 hpread_get_gntt (index, objfile)
655 struct objfile *objfile;
657 return (union dnttentry *)
658 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
661 static union sltentry *
662 hpread_get_slt (index, objfile)
664 struct objfile *objfile;
666 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
669 /* Get the low address associated with some symbol (typically the start
670 of a particular source file or module). Since that information is not
671 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
672 the existance of DNTT_TYPE_FUNCTION symbols. */
675 hpread_get_textlow (global, index, objfile)
678 struct objfile *objfile;
680 union dnttentry *dn_bufp;
681 struct minimal_symbol *msymbol;
683 /* Look for a DNTT_TYPE_FUNCTION symbol. */
687 dn_bufp = hpread_get_gntt (index++, objfile);
689 dn_bufp = hpread_get_lntt (index++, objfile);
691 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
692 && dn_bufp->dblock.kind != DNTT_TYPE_END);
694 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
695 might happen when a sourcefile has no functions. */
696 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
699 /* The minimal symbols are typically more accurate for some reason. */
700 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
703 return SYMBOL_VALUE_ADDRESS (msymbol);
705 return dn_bufp->dfunc.lowaddr;
708 /* Get the nesting depth for the source line identified by INDEX. */
711 hpread_get_depth (index, objfile)
713 struct objfile *objfile;
715 union sltentry *sl_bufp;
717 sl_bufp = hpread_get_slt (index, objfile);
718 return sl_bufp->sspec.backptr.dnttp.index;
721 /* Get the source line number the the line identified by INDEX. */
724 hpread_get_line (index, objfile)
726 struct objfile *objfile;
728 union sltentry *sl_bufp;
730 sl_bufp = hpread_get_slt (index, objfile);
731 return sl_bufp->snorm.line;
735 hpread_get_location (index, objfile)
737 struct objfile *objfile;
739 union sltentry *sl_bufp;
742 /* code location of special sltentrys is determined from context */
743 sl_bufp = hpread_get_slt (index, objfile);
745 if (sl_bufp->snorm.sltdesc == SLT_END)
747 /* find previous normal sltentry and get address */
748 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
749 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
750 sl_bufp = hpread_get_slt (index - i, objfile);
751 return sl_bufp->snorm.address;
754 /* find next normal sltentry and get address */
755 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
756 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
757 sl_bufp = hpread_get_slt (index + i, objfile);
758 return sl_bufp->snorm.address;
762 /* Return 1 if an HP debug symbol of type KIND has a name associated with
763 it, else return 0. */
766 hpread_has_name (kind)
767 enum dntt_entry_type kind;
771 case DNTT_TYPE_SRCFILE:
772 case DNTT_TYPE_MODULE:
773 case DNTT_TYPE_FUNCTION:
774 case DNTT_TYPE_ENTRY:
775 case DNTT_TYPE_IMPORT:
776 case DNTT_TYPE_LABEL:
777 case DNTT_TYPE_FPARAM:
780 case DNTT_TYPE_CONST:
781 case DNTT_TYPE_TYPEDEF:
782 case DNTT_TYPE_TAGDEF:
783 case DNTT_TYPE_MEMENUM:
784 case DNTT_TYPE_FIELD:
788 case DNTT_TYPE_BEGIN:
791 case DNTT_TYPE_COMMON:
792 case DNTT_TYPE_POINTER:
795 case DNTT_TYPE_SUBRANGE:
796 case DNTT_TYPE_ARRAY:
797 case DNTT_TYPE_STRUCT:
798 case DNTT_TYPE_UNION:
799 case DNTT_TYPE_VARIANT:
801 case DNTT_TYPE_FUNCTYPE:
802 case DNTT_TYPE_COBSTRUCT:
804 case DNTT_TYPE_MACRO:
810 /* Allocate and partially fill a partial symtab. It will be
811 completely filled at the end of the symbol list.
813 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
814 is the address relative to which its symbols are (incremental) or 0
817 static struct partial_symtab *
818 hpread_start_psymtab (objfile, filename, textlow, ldsymoff, global_syms,
820 struct objfile *objfile;
824 struct partial_symbol **global_syms;
825 struct partial_symbol **static_syms;
827 struct partial_symtab *result =
828 start_psymtab_common (objfile, section_offsets,
829 filename, textlow, global_syms, static_syms);
831 result->read_symtab_private = (char *)
832 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
833 LDSYMOFF (result) = ldsymoff;
834 result->read_symtab = hpread_psymtab_to_symtab;
840 /* Close off the current usage of PST.
841 Returns PST or NULL if the partial symtab was empty and thrown away.
843 FIXME: List variables and peculiarities of same. */
845 static struct partial_symtab *
846 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
847 capping_text, dependency_list, number_dependencies)
848 struct partial_symtab *pst;
851 int capping_symbol_offset;
852 CORE_ADDR capping_text;
853 struct partial_symtab **dependency_list;
854 int number_dependencies;
857 struct objfile *objfile = pst->objfile;
859 if (capping_symbol_offset != -1)
860 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
861 pst->texthigh = capping_text;
864 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
866 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
868 pst->number_of_dependencies = number_dependencies;
869 if (number_dependencies)
871 pst->dependencies = (struct partial_symtab **)
872 obstack_alloc (&objfile->psymbol_obstack,
873 number_dependencies * sizeof (struct partial_symtab *));
874 memcpy (pst->dependencies, dependency_list,
875 number_dependencies * sizeof (struct partial_symtab *));
878 pst->dependencies = 0;
880 for (i = 0; i < num_includes; i++)
882 struct partial_symtab *subpst =
883 allocate_psymtab (include_list[i], objfile);
885 subpst->section_offsets = pst->section_offsets;
886 subpst->read_symtab_private =
887 (char *) obstack_alloc (&objfile->psymbol_obstack,
888 sizeof (struct symloc));
892 subpst->texthigh = 0;
894 /* We could save slight bits of space by only making one of these,
895 shared by the entire set of include files. FIXME-someday. */
896 subpst->dependencies = (struct partial_symtab **)
897 obstack_alloc (&objfile->psymbol_obstack,
898 sizeof (struct partial_symtab *));
899 subpst->dependencies[0] = pst;
900 subpst->number_of_dependencies = 1;
902 subpst->globals_offset =
903 subpst->n_global_syms =
904 subpst->statics_offset =
905 subpst->n_static_syms = 0;
909 subpst->read_symtab = pst->read_symtab;
912 sort_pst_symbols (pst);
914 /* If there is already a psymtab or symtab for a file of this name, remove it.
915 (If there is a symtab, more drastic things also happen.)
916 This happens in VxWorks. */
917 free_named_symtabs (pst->filename);
919 if (num_includes == 0
920 && number_dependencies == 0
921 && pst->n_global_syms == 0
922 && pst->n_static_syms == 0)
924 /* Throw away this psymtab, it's empty. We can't deallocate it, since
925 it is on the obstack, but we can forget to chain it on the list. */
926 /* Empty psymtabs happen as a result of header files which don't have
927 any symbols in them. There can be a lot of them. But this check
928 is wrong, in that a psymtab with N_SLINE entries but nothing else
929 is not empty, but we don't realize that. Fixing that without slowing
930 things down might be tricky. */
932 discard_psymtab (pst);
934 /* Indicate that psymtab was thrown away. */
935 pst = (struct partial_symtab *) NULL;
940 /* Do the dirty work of reading in the full symbol from a partial symbol
944 hpread_psymtab_to_symtab_1 (pst)
945 struct partial_symtab *pst;
947 struct cleanup *old_chain;
950 /* Get out quick if passed junk. */
954 /* Complain if we've already read in this symbol table. */
957 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
962 /* Read in all partial symtabs on which this one is dependent */
963 for (i = 0; i < pst->number_of_dependencies; i++)
964 if (!pst->dependencies[i]->readin)
966 /* Inform about additional files that need to be read in. */
969 fputs_filtered (" ", gdb_stdout);
971 fputs_filtered ("and ", gdb_stdout);
973 printf_filtered ("%s...", pst->dependencies[i]->filename);
974 wrap_here (""); /* Flush output */
975 gdb_flush (gdb_stdout);
977 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
980 /* If it's real... */
983 /* Init stuff necessary for reading in symbols */
985 old_chain = make_cleanup (really_free_pendings, 0);
988 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
989 pst->textlow, pst->texthigh - pst->textlow,
990 pst->section_offsets, pst->filename);
991 sort_symtab_syms (pst->symtab);
993 do_cleanups (old_chain);
999 /* Read in all of the symbols for a given psymtab for real.
1000 Be verbose about it if the user wants that. */
1003 hpread_psymtab_to_symtab (pst)
1004 struct partial_symtab *pst;
1006 /* Get out quick if given junk. */
1013 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1018 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1020 /* Print the message now, before reading the string table,
1021 to avoid disconcerting pauses. */
1024 printf_filtered ("Reading in symbols for %s...", pst->filename);
1025 gdb_flush (gdb_stdout);
1028 hpread_psymtab_to_symtab_1 (pst);
1030 /* Match with global symbols. This only needs to be done once,
1031 after all of the symtabs and dependencies have been read in. */
1032 scan_file_globals (pst->objfile);
1034 /* Finish up the debug error message. */
1036 printf_filtered ("done.\n");
1039 /* Read in a defined section of a specific object file's symbols.
1041 DESC is the file descriptor for the file, positioned at the
1042 beginning of the symtab
1043 SYM_OFFSET is the offset within the file of
1044 the beginning of the symbols we want to read
1045 SYM_SIZE is the size of the symbol info to read in.
1046 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1047 TEXT_SIZE is the size of the text segment read in.
1048 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1050 static struct symtab *
1051 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1052 section_offsets, filename)
1053 struct objfile *objfile;
1056 CORE_ADDR text_offset;
1058 struct section_offsets *section_offsets;
1062 union dnttentry *dn_bufp;
1063 unsigned max_symnum;
1065 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1067 current_objfile = objfile;
1070 last_source_file = 0;
1072 dn_bufp = hpread_get_lntt (sym_index, objfile);
1073 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1074 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1076 start_symtab ("globals", NULL, 0);
1077 record_debugformat ("HP");
1080 max_symnum = sym_size / sizeof (struct dntt_type_block);
1082 /* Read in and process each debug symbol within the specified range. */
1084 symnum < max_symnum;
1087 QUIT; /* Allow this to be interruptable */
1088 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1090 if (dn_bufp->dblock.extension)
1093 /* Yow! We call SET_NAMESTRING on things without names! */
1094 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1096 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1097 objfile, text_offset, text_size,
1098 filename, symnum + sym_index);
1101 current_objfile = NULL;
1103 return end_symtab (text_offset + text_size, objfile, 0);
1107 /* Convert basic types from HP debug format into GDB internal format. */
1110 hpread_type_translate (typep)
1113 if (!typep.dntti.immediate)
1116 switch (typep.dntti.type)
1118 case HP_TYPE_BOOLEAN:
1119 case HP_TYPE_BOOLEAN_S300_COMPAT:
1120 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1122 /* Ugh. No way to distinguish between signed and unsigned chars. */
1124 case HP_TYPE_WIDE_CHAR:
1127 if (typep.dntti.bitlength <= 8)
1129 if (typep.dntti.bitlength <= 16)
1131 if (typep.dntti.bitlength <= 32)
1133 return FT_LONG_LONG;
1136 case HP_TYPE_UNSIGNED_LONG:
1137 if (typep.dntti.bitlength <= 8)
1138 return FT_UNSIGNED_CHAR;
1139 if (typep.dntti.bitlength <= 16)
1140 return FT_UNSIGNED_SHORT;
1141 if (typep.dntti.bitlength <= 32)
1142 return FT_UNSIGNED_LONG;
1143 return FT_UNSIGNED_LONG_LONG;
1144 case HP_TYPE_UNSIGNED_INT:
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_INTEGER;
1151 return FT_UNSIGNED_LONG_LONG;
1153 case HP_TYPE_REAL_3000:
1154 case HP_TYPE_DOUBLE:
1155 if (typep.dntti.bitlength == 64)
1156 return FT_DBL_PREC_FLOAT;
1157 if (typep.dntti.bitlength == 128)
1158 return FT_EXT_PREC_FLOAT;
1160 case HP_TYPE_COMPLEX:
1161 case HP_TYPE_COMPLEXS3000:
1162 if (typep.dntti.bitlength == 128)
1163 return FT_DBL_PREC_COMPLEX;
1164 if (typep.dntti.bitlength == 192)
1165 return FT_EXT_PREC_COMPLEX;
1167 case HP_TYPE_STRING200:
1168 case HP_TYPE_LONGSTRING200:
1169 case HP_TYPE_FTN_STRING_SPEC:
1170 case HP_TYPE_MOD_STRING_SPEC:
1171 case HP_TYPE_MOD_STRING_3000:
1172 case HP_TYPE_FTN_STRING_S300_COMPAT:
1173 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1180 /* Return the type associated with the index found in HP_TYPE. */
1182 static struct type **
1183 hpread_lookup_type (hp_type, objfile)
1184 dnttpointer hp_type;
1185 struct objfile *objfile;
1188 int index = hp_type.dnttp.index;
1190 if (hp_type.dntti.immediate)
1193 if (index < LNTT_SYMCOUNT (objfile))
1195 if (index >= TYPE_VECTOR_LENGTH (objfile))
1197 old_len = TYPE_VECTOR_LENGTH (objfile);
1200 TYPE_VECTOR_LENGTH (objfile) = 100;
1201 TYPE_VECTOR (objfile) = (struct type **)
1202 xmmalloc (objfile->md,
1203 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1205 while (index >= TYPE_VECTOR_LENGTH (objfile))
1206 TYPE_VECTOR_LENGTH (objfile) *= 2;
1207 TYPE_VECTOR (objfile) = (struct type **)
1208 xmrealloc (objfile->md,
1209 (char *) TYPE_VECTOR (objfile),
1210 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1211 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1212 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1213 sizeof (struct type *));
1215 return &TYPE_VECTOR (objfile)[index];
1221 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1222 Note we'll just return the address of a GDB internal type if we already
1223 have it lying around. */
1225 static struct type *
1226 hpread_alloc_type (hp_type, objfile)
1227 dnttpointer hp_type;
1228 struct objfile *objfile;
1230 struct type **type_addr;
1232 type_addr = hpread_lookup_type (hp_type, objfile);
1233 if (*type_addr == 0)
1234 *type_addr = alloc_type (objfile);
1236 TYPE_CPLUS_SPECIFIC (*type_addr)
1237 = (struct cplus_struct_type *) &cplus_struct_default;
1241 /* Read a native enumerated type and return it in GDB internal form. */
1243 static struct type *
1244 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1245 dnttpointer hp_type;
1246 union dnttentry *dn_bufp;
1247 struct objfile *objfile;
1250 struct pending **symlist, *osyms, *syms;
1251 int o_nsyms, nsyms = 0;
1253 union dnttentry *memp;
1258 type = hpread_alloc_type (hp_type, objfile);
1259 TYPE_LENGTH (type) = 4;
1261 symlist = &file_symbols;
1263 o_nsyms = osyms ? osyms->nsyms : 0;
1265 /* Get a name for each member and add it to our list of members. */
1266 mem = dn_bufp->denum.firstmem;
1267 while (mem.dnttp.extension && mem.word != DNTTNIL)
1269 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1271 name = VT (objfile) + memp->dmember.name;
1272 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1273 sizeof (struct symbol));
1274 memset (sym, 0, sizeof (struct symbol));
1275 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1276 &objfile->symbol_obstack);
1277 SYMBOL_CLASS (sym) = LOC_CONST;
1278 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1279 SYMBOL_VALUE (sym) = memp->dmember.value;
1280 add_symbol_to_list (sym, symlist);
1282 mem = memp->dmember.nextmem;
1285 /* Now that we know more about the enum, fill in more info. */
1286 TYPE_CODE (type) = TYPE_CODE_ENUM;
1287 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1288 TYPE_NFIELDS (type) = nsyms;
1289 TYPE_FIELDS (type) = (struct field *)
1290 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1292 /* Find the symbols for the members and put them into the type.
1293 The symbols can be found in the symlist that we put them on
1294 to cause them to be defined. osyms contains the old value
1295 of that symlist; everything up to there was defined by us.
1297 Note that we preserve the order of the enum constants, so
1298 that in something like "enum {FOO, LAST_THING=FOO}" we print
1299 FOO, not LAST_THING. */
1300 for (syms = *symlist, n = 0; syms; syms = syms->next)
1305 for (; j < syms->nsyms; j++, n++)
1307 struct symbol *xsym = syms->symbol[j];
1308 SYMBOL_TYPE (xsym) = type;
1309 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1310 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1311 TYPE_FIELD_BITSIZE (type, n) = 0;
1320 /* Read and internalize a native function debug symbol. */
1322 static struct type *
1323 hpread_read_function_type (hp_type, dn_bufp, objfile)
1324 dnttpointer hp_type;
1325 union dnttentry *dn_bufp;
1326 struct objfile *objfile;
1328 struct type *type, *type1;
1329 struct pending **symlist, *osyms, *syms;
1330 int o_nsyms, nsyms = 0;
1332 union dnttentry *paramp;
1337 param = dn_bufp->dfunc.firstparam;
1339 /* See if we've already read in this type. */
1340 type = hpread_alloc_type (hp_type, objfile);
1341 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1344 /* Nope, so read it in and store it away. */
1345 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1347 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1349 symlist = &local_symbols;
1351 o_nsyms = osyms ? osyms->nsyms : 0;
1353 /* Now examine each parameter noting its type, location, and a
1354 wealth of other information. */
1355 while (param.word && param.word != DNTTNIL)
1357 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1359 param = paramp->dfparam.nextparam;
1362 name = VT (objfile) + paramp->dfparam.name;
1363 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1364 sizeof (struct symbol));
1365 (void) memset (sym, 0, sizeof (struct symbol));
1366 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1367 &objfile->symbol_obstack);
1369 /* Figure out where it lives. */
1370 if (paramp->dfparam.regparam)
1371 SYMBOL_CLASS (sym) = LOC_REGPARM;
1372 else if (paramp->dfparam.indirect)
1373 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1375 SYMBOL_CLASS (sym) = LOC_ARG;
1376 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1377 if (paramp->dfparam.copyparam)
1379 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1380 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1382 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1384 /* This is likely a pass-by-invisible reference parameter,
1385 Hack on the symbol class to make GDB happy. */
1386 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1389 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1392 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1394 /* Add it to the list. */
1395 add_symbol_to_list (sym, symlist);
1398 /* Note how many parameters we found. */
1399 TYPE_NFIELDS (type) = nsyms;
1400 TYPE_FIELDS (type) = (struct field *)
1401 obstack_alloc (&objfile->type_obstack,
1402 sizeof (struct field) * nsyms);
1404 /* Find the symbols for the values and put them into the type.
1405 The symbols can be found in the symlist that we put them on
1406 to cause them to be defined. osyms contains the old value
1407 of that symlist; everything up to there was defined by us. */
1408 /* Note that we preserve the order of the parameters, so
1409 that in something like "enum {FOO, LAST_THING=FOO}" we print
1410 FOO, not LAST_THING. */
1411 for (syms = *symlist, n = 0; syms; syms = syms->next)
1416 for (; j < syms->nsyms; j++, n++)
1418 struct symbol *xsym = syms->symbol[j];
1419 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1420 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1421 TYPE_FIELD_BITPOS (type, n) = n;
1422 TYPE_FIELD_BITSIZE (type, n) = 0;
1430 /* Read in and internalize a structure definition. */
1432 static struct type *
1433 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1434 dnttpointer hp_type;
1435 union dnttentry *dn_bufp;
1436 struct objfile *objfile;
1440 struct nextfield *next;
1445 struct nextfield *list = 0;
1446 struct nextfield *new;
1449 union dnttentry *fieldp;
1451 /* Is it something we've already dealt with? */
1452 type = hpread_alloc_type (hp_type, objfile);
1453 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1454 (TYPE_CODE (type) == TYPE_CODE_UNION))
1457 /* Get the basic type correct. */
1458 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1460 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1461 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1463 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1465 TYPE_CODE (type) = TYPE_CODE_UNION;
1466 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1472 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1474 /* Read in and internalize all the fields. */
1475 field = dn_bufp->dstruct.firstfield;
1476 while (field.word != DNTTNIL && field.dnttp.extension)
1478 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1480 /* Get space to record the next field's data. */
1481 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1485 list->field.name = VT (objfile) + fieldp->dfield.name;
1486 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1487 if (fieldp->dfield.bitlength % 8)
1488 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1490 FIELD_BITSIZE (list->field) = 0;
1492 field = fieldp->dfield.nextfield;
1493 FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1497 TYPE_NFIELDS (type) = nfields;
1498 TYPE_FIELDS (type) = (struct field *)
1499 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1501 /* Copy the saved-up fields into the field vector. */
1502 for (n = nfields; list; list = list->next)
1505 TYPE_FIELD (type, n) = list->field;
1510 /* Read in and internalize a set debug symbol. */
1512 static struct type *
1513 hpread_read_set_type (hp_type, dn_bufp, objfile)
1514 dnttpointer hp_type;
1515 union dnttentry *dn_bufp;
1516 struct objfile *objfile;
1520 /* See if it's something we've already deal with. */
1521 type = hpread_alloc_type (hp_type, objfile);
1522 if (TYPE_CODE (type) == TYPE_CODE_SET)
1525 /* Nope. Fill in the appropriate fields. */
1526 TYPE_CODE (type) = TYPE_CODE_SET;
1527 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1528 TYPE_NFIELDS (type) = 0;
1529 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1534 /* Read in and internalize an array debug symbol. */
1536 static struct type *
1537 hpread_read_array_type (hp_type, dn_bufp, objfile)
1538 dnttpointer hp_type;
1539 union dnttentry *dn_bufp;
1540 struct objfile *objfile;
1543 union dnttentry save;
1546 /* Why no check here? Because it kept us from properly determining
1547 the size of the array! */
1548 type = hpread_alloc_type (hp_type, objfile);
1550 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1552 /* values are not normalized. */
1553 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1554 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1556 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1558 /* The HP debug format represents char foo[]; as an array with
1559 length 0x7fffffff. Internally GDB wants to represent this
1560 as an array of length zero. */
1561 TYPE_LENGTH (type) = 0;
1564 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1566 TYPE_NFIELDS (type) = 1;
1567 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1570 TYPE_FIELDS (type) = (struct field *)
1571 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1572 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1577 /* Read in and internalize a subrange debug symbol. */
1578 static struct type *
1579 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1580 dnttpointer hp_type;
1581 union dnttentry *dn_bufp;
1582 struct objfile *objfile;
1586 /* Is it something we've already dealt with. */
1587 type = hpread_alloc_type (hp_type, objfile);
1588 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1591 /* Nope, internalize it. */
1592 TYPE_CODE (type) = TYPE_CODE_RANGE;
1593 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1594 TYPE_NFIELDS (type) = 2;
1596 = (struct field *) obstack_alloc (&objfile->type_obstack,
1597 2 * sizeof (struct field));
1599 if (dn_bufp->dsubr.dyn_low)
1600 TYPE_FIELD_BITPOS (type, 0) = 0;
1602 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1604 if (dn_bufp->dsubr.dyn_high)
1605 TYPE_FIELD_BITPOS (type, 1) = -1;
1607 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1608 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1613 static struct type *
1614 hpread_type_lookup (hp_type, objfile)
1615 dnttpointer hp_type;
1616 struct objfile *objfile;
1618 union dnttentry *dn_bufp;
1620 /* First see if it's a simple builtin type. */
1621 if (hp_type.dntti.immediate)
1622 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1624 /* Not a builtin type. We'll have to read it in. */
1625 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1626 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1628 return lookup_fundamental_type (objfile, FT_VOID);
1630 switch (dn_bufp->dblock.kind)
1632 case DNTT_TYPE_SRCFILE:
1633 case DNTT_TYPE_MODULE:
1634 case DNTT_TYPE_FUNCTION:
1635 case DNTT_TYPE_ENTRY:
1636 case DNTT_TYPE_BEGIN:
1638 case DNTT_TYPE_IMPORT:
1639 case DNTT_TYPE_LABEL:
1640 case DNTT_TYPE_WITH:
1641 case DNTT_TYPE_COMMON:
1642 case DNTT_TYPE_FPARAM:
1643 case DNTT_TYPE_SVAR:
1644 case DNTT_TYPE_DVAR:
1645 case DNTT_TYPE_CONST:
1646 /* Opps. Something went very wrong. */
1647 return lookup_fundamental_type (objfile, FT_VOID);
1649 case DNTT_TYPE_TYPEDEF:
1651 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1654 suffix = VT (objfile) + dn_bufp->dtype.name;
1656 TYPE_CPLUS_SPECIFIC (structtype)
1657 = (struct cplus_struct_type *) &cplus_struct_default;
1658 TYPE_NAME (structtype) = suffix;
1662 case DNTT_TYPE_TAGDEF:
1664 /* Just a little different from above. We have to tack on
1665 an identifier of some kind (struct, union, enum, etc). */
1666 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1668 char *prefix, *suffix;
1669 suffix = VT (objfile) + dn_bufp->dtype.name;
1671 /* Lookup the next type in the list. It should be a structure,
1672 union, or enum type. We will need to attach that to our name. */
1673 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1674 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1678 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1680 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1685 /* Build the correct name. */
1687 = (char *) obstack_alloc (&objfile->type_obstack,
1688 strlen (prefix) + strlen (suffix) + 1);
1689 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1690 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1691 TYPE_TAG_NAME (structtype) = suffix;
1693 TYPE_CPLUS_SPECIFIC (structtype)
1694 = (struct cplus_struct_type *) &cplus_struct_default;
1698 case DNTT_TYPE_POINTER:
1699 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1701 case DNTT_TYPE_ENUM:
1702 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1703 case DNTT_TYPE_MEMENUM:
1704 return lookup_fundamental_type (objfile, FT_VOID);
1706 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1707 case DNTT_TYPE_SUBRANGE:
1708 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1709 case DNTT_TYPE_ARRAY:
1710 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1711 case DNTT_TYPE_STRUCT:
1712 case DNTT_TYPE_UNION:
1713 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1714 case DNTT_TYPE_FIELD:
1715 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1716 case DNTT_TYPE_VARIANT:
1717 case DNTT_TYPE_FILE:
1718 return lookup_fundamental_type (objfile, FT_VOID);
1719 case DNTT_TYPE_FUNCTYPE:
1720 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1722 case DNTT_TYPE_COBSTRUCT:
1723 case DNTT_TYPE_XREF:
1725 case DNTT_TYPE_MACRO:
1727 return lookup_fundamental_type (objfile, FT_VOID);
1732 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1733 struct subfile *subfile;
1734 sltpointer s_idx, e_idx;
1735 struct objfile *objfile;
1738 union sltentry *sl_bufp;
1740 while (s_idx <= e_idx)
1742 sl_bufp = hpread_get_slt (s_idx, objfile);
1743 /* Only record "normal" entries in the SLT. */
1744 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1745 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1746 record_line (subfile, sl_bufp->snorm.line,
1747 sl_bufp->snorm.address + offset);
1753 /* Internalize one native debug symbol. */
1756 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1757 text_offset, text_size, filename, index)
1758 union dnttentry *dn_bufp;
1760 struct section_offsets *section_offsets;
1761 struct objfile *objfile;
1762 CORE_ADDR text_offset;
1770 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1771 union dnttentry *dn_temp;
1772 dnttpointer hp_type;
1774 struct context_stack *new;
1776 /* Allocate one GDB debug symbol and fill in some default values. */
1777 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1778 sizeof (struct symbol));
1779 memset (sym, 0, sizeof (struct symbol));
1780 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1781 SYMBOL_LANGUAGE (sym) = language_auto;
1782 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1783 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1784 SYMBOL_LINE (sym) = 0;
1785 SYMBOL_VALUE (sym) = 0;
1786 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1788 hp_type.dnttp.extension = 1;
1789 hp_type.dnttp.immediate = 0;
1790 hp_type.dnttp.global = 0;
1791 hp_type.dnttp.index = index;
1793 type = dn_bufp->dblock.kind;
1797 case DNTT_TYPE_SRCFILE:
1798 /* This type of symbol indicates from which source file or include file
1799 the following data comes. If there are no modules it also may
1800 indicate the start of a new source file, in which case we must
1801 finish the symbol table of the previous source file
1802 (if any) and start accumulating a new symbol table. */
1805 if (!last_source_file)
1807 start_symtab (name, NULL, valu);
1808 record_debugformat ("HP");
1809 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1813 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1815 dn_bufp->dsfile.address,
1818 start_subfile (name, NULL);
1821 case DNTT_TYPE_MODULE:
1822 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1825 case DNTT_TYPE_FUNCTION:
1826 case DNTT_TYPE_ENTRY:
1827 /* A function or secondary entry point. */
1828 valu = dn_bufp->dfunc.lowaddr + offset;
1829 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1831 dn_bufp->dfunc.address,
1834 WITHIN_FUNCTION (objfile) = 1;
1835 CURRENT_FUNCTION_VALUE (objfile) = valu;
1837 /* Stack must be empty now. */
1838 if (context_stack_depth != 0)
1839 complain (&lbrac_unmatched_complaint, (char *) symnum);
1840 new = push_context (0, valu);
1842 SYMBOL_CLASS (sym) = LOC_BLOCK;
1843 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1844 if (dn_bufp->dfunc.global)
1845 add_symbol_to_list (sym, &global_symbols);
1847 add_symbol_to_list (sym, &file_symbols);
1850 /* Search forward to the next scope beginning. */
1851 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1853 dn_bufp = hpread_get_lntt (++index, objfile);
1854 if (dn_bufp->dblock.extension)
1857 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1859 dn_bufp->dbegin.address,
1861 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1862 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1865 case DNTT_TYPE_BEGIN:
1866 /* Begin a new scope. */
1867 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1869 dn_bufp->dbegin.address,
1871 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1872 valu += offset; /* Relocate for dynamic loading */
1873 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1874 new = push_context (desc, valu);
1879 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1881 dn_bufp->dend.address + 1,
1883 switch (dn_bufp->dend.endkind)
1885 case DNTT_TYPE_MODULE:
1886 /* Ending a module ends the symbol table for that module. */
1887 valu = text_offset + text_size + offset;
1888 (void) end_symtab (valu, objfile, 0);
1891 case DNTT_TYPE_FUNCTION:
1892 /* Ending a function, well, ends the function's scope. */
1893 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1895 valu = dn_temp->dfunc.hiaddr + offset;
1896 new = pop_context ();
1897 /* Make a block for the local symbols within. */
1898 finish_block (new->name, &local_symbols, new->old_blocks,
1899 new->start_addr, valu, objfile);
1900 WITHIN_FUNCTION (objfile) = 0;
1902 case DNTT_TYPE_BEGIN:
1903 /* Just ending a local scope. */
1904 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1905 /* Why in the hell is this needed? */
1906 valu += offset + 9; /* Relocate for dynamic loading */
1907 new = pop_context ();
1908 desc = dn_bufp->dend.beginscope.dnttp.index;
1909 if (desc != new->depth)
1910 complain (&lbrac_mismatch_complaint, (char *) symnum);
1911 /* Make a block for the local symbols within. */
1912 finish_block (new->name, &local_symbols, new->old_blocks,
1913 new->start_addr, valu, objfile);
1914 local_symbols = new->locals;
1918 case DNTT_TYPE_LABEL:
1919 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1921 case DNTT_TYPE_FPARAM:
1922 /* Function parameters. */
1923 if (dn_bufp->dfparam.regparam)
1924 SYMBOL_CLASS (sym) = LOC_REGISTER;
1926 SYMBOL_CLASS (sym) = LOC_LOCAL;
1927 if (dn_bufp->dfparam.copyparam)
1929 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1930 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1932 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1936 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1937 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1938 add_symbol_to_list (sym, &local_symbols);
1940 case DNTT_TYPE_SVAR:
1941 /* Static variables. */
1942 SYMBOL_CLASS (sym) = LOC_STATIC;
1943 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1944 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1945 if (dn_bufp->dsvar.global)
1946 add_symbol_to_list (sym, &global_symbols);
1947 else if (WITHIN_FUNCTION (objfile))
1948 add_symbol_to_list (sym, &local_symbols);
1950 add_symbol_to_list (sym, &file_symbols);
1952 case DNTT_TYPE_DVAR:
1953 /* Dynamic variables. */
1954 if (dn_bufp->ddvar.regvar)
1955 SYMBOL_CLASS (sym) = LOC_REGISTER;
1957 SYMBOL_CLASS (sym) = LOC_LOCAL;
1958 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1959 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1961 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1963 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1964 if (dn_bufp->ddvar.global)
1965 add_symbol_to_list (sym, &global_symbols);
1966 else if (WITHIN_FUNCTION (objfile))
1967 add_symbol_to_list (sym, &local_symbols);
1969 add_symbol_to_list (sym, &file_symbols);
1971 case DNTT_TYPE_CONST:
1972 /* A constant (pascal?). */
1973 SYMBOL_CLASS (sym) = LOC_CONST;
1974 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1975 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1976 if (dn_bufp->dconst.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_TYPEDEF:
1984 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1985 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1986 if (dn_bufp->dtype.global)
1987 add_symbol_to_list (sym, &global_symbols);
1988 else if (WITHIN_FUNCTION (objfile))
1989 add_symbol_to_list (sym, &local_symbols);
1991 add_symbol_to_list (sym, &file_symbols);
1993 case DNTT_TYPE_TAGDEF:
1994 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1995 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1996 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1997 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
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_POINTER:
2006 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2007 (dn_bufp->dptr.pointsto,
2009 add_symbol_to_list (sym, &file_symbols);
2011 case DNTT_TYPE_ENUM:
2012 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2013 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2014 add_symbol_to_list (sym, &file_symbols);
2016 case DNTT_TYPE_MEMENUM:
2019 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2020 add_symbol_to_list (sym, &file_symbols);
2022 case DNTT_TYPE_SUBRANGE:
2023 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2025 add_symbol_to_list (sym, &file_symbols);
2027 case DNTT_TYPE_ARRAY:
2028 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2029 add_symbol_to_list (sym, &file_symbols);
2031 case DNTT_TYPE_STRUCT:
2032 case DNTT_TYPE_UNION:
2033 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2034 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2035 add_symbol_to_list (sym, &file_symbols);