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 (struct objfile *objfile)
218 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
220 /* Allocate struct to keep track of the symfile */
221 objfile->sym_private = (PTR)
222 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
223 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
225 /* We haven't read in any types yet. */
226 TYPE_VECTOR (objfile) = 0;
228 /* Read in data from the $GNTT$ subspace. */
229 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
234 = obstack_alloc (&objfile->symbol_obstack,
235 bfd_section_size (objfile->obfd, gntt_section));
237 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
238 0, bfd_section_size (objfile->obfd, gntt_section));
240 GNTT_SYMCOUNT (objfile)
241 = bfd_section_size (objfile->obfd, gntt_section)
242 / sizeof (struct dntt_type_block);
244 /* Read in data from the $LNTT$ subspace. Also keep track of the number
246 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
251 = obstack_alloc (&objfile->symbol_obstack,
252 bfd_section_size (objfile->obfd, lntt_section));
254 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
255 0, bfd_section_size (objfile->obfd, lntt_section));
257 LNTT_SYMCOUNT (objfile)
258 = bfd_section_size (objfile->obfd, lntt_section)
259 / sizeof (struct dntt_type_block);
261 /* Read in data from the $SLT$ subspace. $SLT$ contains information
262 on source line numbers. */
263 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
268 obstack_alloc (&objfile->symbol_obstack,
269 bfd_section_size (objfile->obfd, slt_section));
271 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
272 0, bfd_section_size (objfile->obfd, slt_section));
274 /* Read in data from the $VT$ subspace. $VT$ contains things like
275 names and constants. Keep track of the number of symbols in the VT. */
276 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
280 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
283 (char *) obstack_alloc (&objfile->symbol_obstack,
286 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
287 0, VT_SIZE (objfile));
290 /* Scan and build partial symbols for a symbol file.
292 The minimal symbol table (either SOM or HP a.out) has already been
293 read in; all we need to do is setup partial symbols based on the
294 native debugging information.
296 We assume hpread_symfile_init has been called to initialize the
297 symbol reader's private data structures.
299 MAINLINE is true if we are reading the main symbol
300 table (as opposed to a shared lib or dynamically loaded file). */
303 hpread_build_psymtabs (struct objfile *objfile, int mainline)
306 int past_first_source_file = 0;
307 struct cleanup *old_chain;
309 int hp_symnum, symcount, i;
311 union dnttentry *dn_bufp;
317 /* Current partial symtab */
318 struct partial_symtab *pst;
320 /* List of current psymtab's include files */
321 char **psymtab_include_list;
322 int includes_allocated;
325 /* Index within current psymtab dependency list */
326 struct partial_symtab **dependency_list;
327 int dependencies_used, dependencies_allocated;
329 /* Just in case the stabs reader left turds lying around. */
330 free_pending_blocks ();
331 make_cleanup (really_free_pendings, 0);
333 pst = (struct partial_symtab *) 0;
335 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
336 a number of problems with cross compilation and creating useless holes
337 in the stack when we have to allocate new entries. FIXME. */
339 includes_allocated = 30;
341 psymtab_include_list = (char **) alloca (includes_allocated *
344 dependencies_allocated = 30;
345 dependencies_used = 0;
347 (struct partial_symtab **) alloca (dependencies_allocated *
348 sizeof (struct partial_symtab *));
350 old_chain = make_cleanup_free_objfile (objfile);
352 last_source_file = 0;
354 /* Make two passes, one ofr the GNTT symbols, the other for the
356 for (i = 0; i < 1; i++)
358 int within_function = 0;
361 symcount = GNTT_SYMCOUNT (objfile);
363 symcount = LNTT_SYMCOUNT (objfile);
365 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
369 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
371 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
373 if (dn_bufp->dblock.extension)
376 /* Only handle things which are necessary for minimal symbols.
377 everything else is ignored. */
378 switch (dn_bufp->dblock.kind)
380 case DNTT_TYPE_SRCFILE:
382 /* A source file of some kind. Note this may simply
383 be an included file. */
384 SET_NAMESTRING (dn_bufp, &namestring, objfile);
386 /* Check if this is the source file we are already working
388 if (pst && !strcmp (namestring, pst->filename))
391 /* Check if this is an include file, if so check if we have
392 already seen it. Add it to the include list */
393 p = strrchr (namestring, '.');
394 if (!strcmp (p, ".h"))
399 for (j = 0; j < includes_used; j++)
400 if (!strcmp (namestring, psymtab_include_list[j]))
408 /* Add it to the list of includes seen so far and
409 allocate more include space if necessary. */
410 psymtab_include_list[includes_used++] = namestring;
411 if (includes_used >= includes_allocated)
413 char **orig = psymtab_include_list;
415 psymtab_include_list = (char **)
416 alloca ((includes_allocated *= 2) *
418 memcpy ((PTR) psymtab_include_list, (PTR) orig,
419 includes_used * sizeof (char *));
429 pst->filename = (char *)
430 obstack_alloc (&pst->objfile->psymbol_obstack,
431 strlen (namestring) + 1);
432 strcpy (pst->filename, namestring);
439 /* This is a bonafide new source file.
440 End the current partial symtab and start a new one. */
442 if (pst && past_first_source_file)
444 hpread_end_psymtab (pst, psymtab_include_list,
447 * sizeof (struct dntt_type_block)),
449 dependency_list, dependencies_used);
450 pst = (struct partial_symtab *) 0;
452 dependencies_used = 0;
455 past_first_source_file = 1;
457 valu = hpread_get_textlow (i, hp_symnum, objfile);
458 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
459 pst = hpread_start_psymtab (objfile,
462 * sizeof (struct dntt_type_block)),
463 objfile->global_psymbols.next,
464 objfile->static_psymbols.next);
470 case DNTT_TYPE_MODULE:
471 /* A source file. It's still unclear to me what the
472 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
473 is supposed to be. */
474 SET_NAMESTRING (dn_bufp, &namestring, objfile);
475 valu = hpread_get_textlow (i, hp_symnum, objfile);
476 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
479 pst = hpread_start_psymtab (objfile,
482 * sizeof (struct dntt_type_block)),
483 objfile->global_psymbols.next,
484 objfile->static_psymbols.next);
489 case DNTT_TYPE_FUNCTION:
490 case DNTT_TYPE_ENTRY:
491 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
492 a secondary entry point. */
493 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
494 SECT_OFF_TEXT (objfile));
497 valu = dn_bufp->dfunc.lowaddr +
498 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
499 SET_NAMESTRING (dn_bufp, &namestring, objfile);
500 add_psymbol_to_list (namestring, strlen (namestring),
501 VAR_NAMESPACE, LOC_BLOCK,
502 &objfile->static_psymbols, valu,
503 0, language_unknown, objfile);
506 case DNTT_TYPE_BEGIN:
508 /* Scope block begin/end. We only care about function
509 and file blocks right now. */
510 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
512 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
514 * sizeof (struct dntt_type_block)),
516 dependency_list, dependencies_used);
517 pst = (struct partial_symtab *) 0;
519 dependencies_used = 0;
522 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
527 case DNTT_TYPE_TYPEDEF:
528 case DNTT_TYPE_TAGDEF:
530 /* Variables, typedefs an the like. */
531 enum address_class storage;
532 namespace_enum namespace;
534 /* Don't add locals to the partial symbol table. */
536 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
537 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
540 /* TAGDEFs go into the structure namespace. */
541 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
542 namespace = STRUCT_NAMESPACE;
544 namespace = VAR_NAMESPACE;
546 /* What kind of "storage" does this use? */
547 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
548 storage = LOC_STATIC;
549 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
550 && dn_bufp->ddvar.regvar)
551 storage = LOC_REGISTER;
552 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
557 SET_NAMESTRING (dn_bufp, &namestring, objfile);
560 pst = hpread_start_psymtab (objfile,
563 * sizeof (struct dntt_type_block)),
564 objfile->global_psymbols.next,
565 objfile->static_psymbols.next);
567 if (dn_bufp->dsvar.global)
569 add_psymbol_to_list (namestring, strlen (namestring),
571 &objfile->global_psymbols,
572 dn_bufp->dsvar.location,
573 0, language_unknown, objfile);
577 add_psymbol_to_list (namestring, strlen (namestring),
579 &objfile->static_psymbols,
580 dn_bufp->dsvar.location,
581 0, language_unknown, objfile);
585 case DNTT_TYPE_MEMENUM:
586 case DNTT_TYPE_CONST:
587 /* Constants and members of enumerated types. */
588 SET_NAMESTRING (dn_bufp, &namestring, objfile);
591 pst = hpread_start_psymtab (objfile,
594 * sizeof (struct dntt_type_block)),
595 objfile->global_psymbols.next,
596 objfile->static_psymbols.next);
598 add_psymbol_to_list (namestring, strlen (namestring),
599 VAR_NAMESPACE, LOC_CONST,
600 &objfile->static_psymbols, 0,
601 0, language_unknown, objfile);
609 /* End any pending partial symbol table. */
612 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
613 hp_symnum * sizeof (struct dntt_type_block),
614 0, dependency_list, dependencies_used);
617 discard_cleanups (old_chain);
620 /* Perform any local cleanups required when we are done with a particular
621 objfile. I.E, we are in the process of discarding all symbol information
622 for an objfile, freeing up all memory held for it, and unlinking the
623 objfile struct from the global list of known objfiles. */
626 hpread_symfile_finish (struct objfile *objfile)
628 if (objfile->sym_private != NULL)
630 mfree (objfile->md, objfile->sym_private);
635 /* The remaining functions are all for internal use only. */
637 /* Various small functions to get entries in the debug symbol sections. */
639 static union dnttentry *
640 hpread_get_lntt (int index, struct objfile *objfile)
642 return (union dnttentry *)
643 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
646 static union dnttentry *
647 hpread_get_gntt (int index, struct objfile *objfile)
649 return (union dnttentry *)
650 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
653 static union sltentry *
654 hpread_get_slt (int index, struct objfile *objfile)
656 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
659 /* Get the low address associated with some symbol (typically the start
660 of a particular source file or module). Since that information is not
661 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
662 must infer it from the existence of DNTT_TYPE_FUNCTION symbols. */
665 hpread_get_textlow (int global, int index, struct objfile *objfile)
667 union dnttentry *dn_bufp;
668 struct minimal_symbol *msymbol;
670 /* Look for a DNTT_TYPE_FUNCTION symbol. */
674 dn_bufp = hpread_get_gntt (index++, objfile);
676 dn_bufp = hpread_get_lntt (index++, objfile);
678 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
679 && dn_bufp->dblock.kind != DNTT_TYPE_END);
681 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
682 might happen when a sourcefile has no functions. */
683 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
686 /* The minimal symbols are typically more accurate for some reason. */
687 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
690 return SYMBOL_VALUE_ADDRESS (msymbol);
692 return dn_bufp->dfunc.lowaddr;
695 /* Get the nesting depth for the source line identified by INDEX. */
698 hpread_get_depth (sltpointer index, struct objfile *objfile)
700 union sltentry *sl_bufp;
702 sl_bufp = hpread_get_slt (index, objfile);
703 return sl_bufp->sspec.backptr.dnttp.index;
706 /* Get the source line number the the line identified by INDEX. */
709 hpread_get_line (sltpointer index, struct objfile *objfile)
711 union sltentry *sl_bufp;
713 sl_bufp = hpread_get_slt (index, objfile);
714 return sl_bufp->snorm.line;
718 hpread_get_location (sltpointer index, struct objfile *objfile)
720 union sltentry *sl_bufp;
723 /* code location of special sltentrys is determined from context */
724 sl_bufp = hpread_get_slt (index, objfile);
726 if (sl_bufp->snorm.sltdesc == SLT_END)
728 /* find previous normal sltentry and get address */
729 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
730 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
731 sl_bufp = hpread_get_slt (index - i, objfile);
732 return sl_bufp->snorm.address;
735 /* find next normal sltentry and get address */
736 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
737 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
738 sl_bufp = hpread_get_slt (index + i, objfile);
739 return sl_bufp->snorm.address;
743 /* Return 1 if an HP debug symbol of type KIND has a name associated with
744 it, else return 0. */
747 hpread_has_name (enum dntt_entry_type kind)
751 case DNTT_TYPE_SRCFILE:
752 case DNTT_TYPE_MODULE:
753 case DNTT_TYPE_FUNCTION:
754 case DNTT_TYPE_ENTRY:
755 case DNTT_TYPE_IMPORT:
756 case DNTT_TYPE_LABEL:
757 case DNTT_TYPE_FPARAM:
760 case DNTT_TYPE_CONST:
761 case DNTT_TYPE_TYPEDEF:
762 case DNTT_TYPE_TAGDEF:
763 case DNTT_TYPE_MEMENUM:
764 case DNTT_TYPE_FIELD:
768 case DNTT_TYPE_BEGIN:
771 case DNTT_TYPE_COMMON:
772 case DNTT_TYPE_POINTER:
775 case DNTT_TYPE_SUBRANGE:
776 case DNTT_TYPE_ARRAY:
777 case DNTT_TYPE_STRUCT:
778 case DNTT_TYPE_UNION:
779 case DNTT_TYPE_VARIANT:
781 case DNTT_TYPE_FUNCTYPE:
782 case DNTT_TYPE_COBSTRUCT:
784 case DNTT_TYPE_MACRO:
790 /* Allocate and partially fill a partial symtab. It will be
791 completely filled at the end of the symbol list.
793 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
794 is the address relative to which its symbols are (incremental) or 0
797 static struct partial_symtab *
798 hpread_start_psymtab (struct objfile *objfile, char *filename,
799 CORE_ADDR textlow, int ldsymoff,
800 struct partial_symbol **global_syms,
801 struct partial_symbol **static_syms)
803 struct partial_symtab *result =
804 start_psymtab_common (objfile, section_offsets,
805 filename, textlow, global_syms, static_syms);
807 result->read_symtab_private = (char *)
808 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
809 LDSYMOFF (result) = ldsymoff;
810 result->read_symtab = hpread_psymtab_to_symtab;
816 /* Close off the current usage of PST.
817 Returns PST or NULL if the partial symtab was empty and thrown away.
819 FIXME: List variables and peculiarities of same. */
821 static struct partial_symtab *
822 hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
823 int num_includes, int capping_symbol_offset,
824 CORE_ADDR capping_text,
825 struct partial_symtab **dependency_list,
826 int number_dependencies)
829 struct objfile *objfile = pst->objfile;
831 if (capping_symbol_offset != -1)
832 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
833 pst->texthigh = capping_text;
836 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
838 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
840 pst->number_of_dependencies = number_dependencies;
841 if (number_dependencies)
843 pst->dependencies = (struct partial_symtab **)
844 obstack_alloc (&objfile->psymbol_obstack,
845 number_dependencies * sizeof (struct partial_symtab *));
846 memcpy (pst->dependencies, dependency_list,
847 number_dependencies * sizeof (struct partial_symtab *));
850 pst->dependencies = 0;
852 for (i = 0; i < num_includes; i++)
854 struct partial_symtab *subpst =
855 allocate_psymtab (include_list[i], objfile);
857 subpst->section_offsets = pst->section_offsets;
858 subpst->read_symtab_private =
859 (char *) obstack_alloc (&objfile->psymbol_obstack,
860 sizeof (struct symloc));
864 subpst->texthigh = 0;
866 /* We could save slight bits of space by only making one of these,
867 shared by the entire set of include files. FIXME-someday. */
868 subpst->dependencies = (struct partial_symtab **)
869 obstack_alloc (&objfile->psymbol_obstack,
870 sizeof (struct partial_symtab *));
871 subpst->dependencies[0] = pst;
872 subpst->number_of_dependencies = 1;
874 subpst->globals_offset =
875 subpst->n_global_syms =
876 subpst->statics_offset =
877 subpst->n_static_syms = 0;
881 subpst->read_symtab = pst->read_symtab;
884 sort_pst_symbols (pst);
886 /* If there is already a psymtab or symtab for a file of this name, remove it.
887 (If there is a symtab, more drastic things also happen.)
888 This happens in VxWorks. */
889 free_named_symtabs (pst->filename);
891 if (num_includes == 0
892 && number_dependencies == 0
893 && pst->n_global_syms == 0
894 && pst->n_static_syms == 0)
896 /* Throw away this psymtab, it's empty. We can't deallocate it, since
897 it is on the obstack, but we can forget to chain it on the list. */
898 /* Empty psymtabs happen as a result of header files which don't have
899 any symbols in them. There can be a lot of them. But this check
900 is wrong, in that a psymtab with N_SLINE entries but nothing else
901 is not empty, but we don't realize that. Fixing that without slowing
902 things down might be tricky. */
904 discard_psymtab (pst);
906 /* Indicate that psymtab was thrown away. */
907 pst = (struct partial_symtab *) NULL;
912 /* Do the dirty work of reading in the full symbol from a partial symbol
916 hpread_psymtab_to_symtab_1 (struct partial_symtab *pst)
918 struct cleanup *old_chain;
921 /* Get out quick if passed junk. */
925 /* Complain if we've already read in this symbol table. */
928 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
933 /* Read in all partial symtabs on which this one is dependent */
934 for (i = 0; i < pst->number_of_dependencies; i++)
935 if (!pst->dependencies[i]->readin)
937 /* Inform about additional files that need to be read in. */
940 fputs_filtered (" ", gdb_stdout);
942 fputs_filtered ("and ", gdb_stdout);
944 printf_filtered ("%s...", pst->dependencies[i]->filename);
945 wrap_here (""); /* Flush output */
946 gdb_flush (gdb_stdout);
948 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
951 /* If it's real... */
954 /* Init stuff necessary for reading in symbols */
956 old_chain = make_cleanup (really_free_pendings, 0);
959 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
960 pst->textlow, pst->texthigh - pst->textlow,
961 pst->section_offsets, pst->filename);
962 sort_symtab_syms (pst->symtab);
964 do_cleanups (old_chain);
970 /* Read in all of the symbols for a given psymtab for real.
971 Be verbose about it if the user wants that. */
974 hpread_psymtab_to_symtab (struct partial_symtab *pst)
976 /* Get out quick if given junk. */
983 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
988 if (LDSYMLEN (pst) || pst->number_of_dependencies)
990 /* Print the message now, before reading the string table,
991 to avoid disconcerting pauses. */
994 printf_filtered ("Reading in symbols for %s...", pst->filename);
995 gdb_flush (gdb_stdout);
998 hpread_psymtab_to_symtab_1 (pst);
1000 /* Match with global symbols. This only needs to be done once,
1001 after all of the symtabs and dependencies have been read in. */
1002 scan_file_globals (pst->objfile);
1004 /* Finish up the debug error message. */
1006 printf_filtered ("done.\n");
1009 /* Read in a defined section of a specific object file's symbols.
1011 DESC is the file descriptor for the file, positioned at the
1012 beginning of the symtab
1013 SYM_OFFSET is the offset within the file of
1014 the beginning of the symbols we want to read
1015 SYM_SIZE is the size of the symbol info to read in.
1016 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1017 TEXT_SIZE is the size of the text segment read in.
1018 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1020 static struct symtab *
1021 hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size,
1022 CORE_ADDR text_offset, int text_size,
1023 struct section_offsets *section_offsets, char *filename)
1026 union dnttentry *dn_bufp;
1027 unsigned max_symnum;
1029 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1031 current_objfile = objfile;
1034 last_source_file = 0;
1036 dn_bufp = hpread_get_lntt (sym_index, objfile);
1037 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1038 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1040 start_symtab ("globals", NULL, 0);
1041 record_debugformat ("HP");
1044 max_symnum = sym_size / sizeof (struct dntt_type_block);
1046 /* Read in and process each debug symbol within the specified range. */
1048 symnum < max_symnum;
1051 QUIT; /* Allow this to be interruptable */
1052 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1054 if (dn_bufp->dblock.extension)
1057 /* Yow! We call SET_NAMESTRING on things without names! */
1058 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1060 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1061 objfile, text_offset, text_size,
1062 filename, symnum + sym_index);
1065 current_objfile = NULL;
1067 return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
1071 /* Convert basic types from HP debug format into GDB internal format. */
1074 hpread_type_translate (dnttpointer typep)
1076 if (!typep.dntti.immediate)
1079 switch (typep.dntti.type)
1081 case HP_TYPE_BOOLEAN:
1082 case HP_TYPE_BOOLEAN_S300_COMPAT:
1083 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1085 /* Ugh. No way to distinguish between signed and unsigned chars. */
1087 case HP_TYPE_WIDE_CHAR:
1090 if (typep.dntti.bitlength <= 8)
1092 if (typep.dntti.bitlength <= 16)
1094 if (typep.dntti.bitlength <= 32)
1096 return FT_LONG_LONG;
1099 case HP_TYPE_UNSIGNED_LONG:
1100 if (typep.dntti.bitlength <= 8)
1101 return FT_UNSIGNED_CHAR;
1102 if (typep.dntti.bitlength <= 16)
1103 return FT_UNSIGNED_SHORT;
1104 if (typep.dntti.bitlength <= 32)
1105 return FT_UNSIGNED_LONG;
1106 return FT_UNSIGNED_LONG_LONG;
1107 case HP_TYPE_UNSIGNED_INT:
1108 if (typep.dntti.bitlength <= 8)
1109 return FT_UNSIGNED_CHAR;
1110 if (typep.dntti.bitlength <= 16)
1111 return FT_UNSIGNED_SHORT;
1112 if (typep.dntti.bitlength <= 32)
1113 return FT_UNSIGNED_INTEGER;
1114 return FT_UNSIGNED_LONG_LONG;
1116 case HP_TYPE_REAL_3000:
1117 case HP_TYPE_DOUBLE:
1118 if (typep.dntti.bitlength == 64)
1119 return FT_DBL_PREC_FLOAT;
1120 if (typep.dntti.bitlength == 128)
1121 return FT_EXT_PREC_FLOAT;
1123 case HP_TYPE_COMPLEX:
1124 case HP_TYPE_COMPLEXS3000:
1125 if (typep.dntti.bitlength == 128)
1126 return FT_DBL_PREC_COMPLEX;
1127 if (typep.dntti.bitlength == 192)
1128 return FT_EXT_PREC_COMPLEX;
1130 case HP_TYPE_STRING200:
1131 case HP_TYPE_LONGSTRING200:
1132 case HP_TYPE_FTN_STRING_SPEC:
1133 case HP_TYPE_MOD_STRING_SPEC:
1134 case HP_TYPE_MOD_STRING_3000:
1135 case HP_TYPE_FTN_STRING_S300_COMPAT:
1136 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1143 /* Return the type associated with the index found in HP_TYPE. */
1145 static struct type **
1146 hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile)
1149 int index = hp_type.dnttp.index;
1151 if (hp_type.dntti.immediate)
1154 if (index < LNTT_SYMCOUNT (objfile))
1156 if (index >= TYPE_VECTOR_LENGTH (objfile))
1158 old_len = TYPE_VECTOR_LENGTH (objfile);
1161 TYPE_VECTOR_LENGTH (objfile) = 100;
1162 TYPE_VECTOR (objfile) = (struct type **)
1163 xmmalloc (objfile->md,
1164 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1166 while (index >= TYPE_VECTOR_LENGTH (objfile))
1167 TYPE_VECTOR_LENGTH (objfile) *= 2;
1168 TYPE_VECTOR (objfile) = (struct type **)
1169 xmrealloc (objfile->md,
1170 (char *) TYPE_VECTOR (objfile),
1171 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1172 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1173 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1174 sizeof (struct type *));
1176 return &TYPE_VECTOR (objfile)[index];
1182 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1183 Note we'll just return the address of a GDB internal type if we already
1184 have it lying around. */
1186 static struct type *
1187 hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile)
1189 struct type **type_addr;
1191 type_addr = hpread_lookup_type (hp_type, objfile);
1192 if (*type_addr == 0)
1193 *type_addr = alloc_type (objfile);
1195 TYPE_CPLUS_SPECIFIC (*type_addr)
1196 = (struct cplus_struct_type *) &cplus_struct_default;
1200 /* Read a native enumerated type and return it in GDB internal form. */
1202 static struct type *
1203 hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1204 struct objfile *objfile)
1207 struct pending **symlist, *osyms, *syms;
1208 int o_nsyms, nsyms = 0;
1210 union dnttentry *memp;
1215 type = hpread_alloc_type (hp_type, objfile);
1216 TYPE_LENGTH (type) = 4;
1218 symlist = &file_symbols;
1220 o_nsyms = osyms ? osyms->nsyms : 0;
1222 /* Get a name for each member and add it to our list of members. */
1223 mem = dn_bufp->denum.firstmem;
1224 while (mem.dnttp.extension && mem.word != DNTTNIL)
1226 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1228 name = VT (objfile) + memp->dmember.name;
1229 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1230 sizeof (struct symbol));
1231 memset (sym, 0, sizeof (struct symbol));
1232 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1233 &objfile->symbol_obstack);
1234 SYMBOL_CLASS (sym) = LOC_CONST;
1235 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1236 SYMBOL_VALUE (sym) = memp->dmember.value;
1237 add_symbol_to_list (sym, symlist);
1239 mem = memp->dmember.nextmem;
1242 /* Now that we know more about the enum, fill in more info. */
1243 TYPE_CODE (type) = TYPE_CODE_ENUM;
1244 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1245 TYPE_NFIELDS (type) = nsyms;
1246 TYPE_FIELDS (type) = (struct field *)
1247 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1249 /* Find the symbols for the members and put them into the type.
1250 The symbols can be found in the symlist that we put them on
1251 to cause them to be defined. osyms contains the old value
1252 of that symlist; everything up to there was defined by us.
1254 Note that we preserve the order of the enum constants, so
1255 that in something like "enum {FOO, LAST_THING=FOO}" we print
1256 FOO, not LAST_THING. */
1257 for (syms = *symlist, n = 0; syms; syms = syms->next)
1262 for (; j < syms->nsyms; j++, n++)
1264 struct symbol *xsym = syms->symbol[j];
1265 SYMBOL_TYPE (xsym) = type;
1266 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1267 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1268 TYPE_FIELD_BITSIZE (type, n) = 0;
1277 /* Read and internalize a native function debug symbol. */
1279 static struct type *
1280 hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1281 struct objfile *objfile)
1283 struct type *type, *type1;
1284 struct pending **symlist, *osyms, *syms;
1285 int o_nsyms, nsyms = 0;
1287 union dnttentry *paramp;
1292 param = dn_bufp->dfunc.firstparam;
1294 /* See if we've already read in this type. */
1295 type = hpread_alloc_type (hp_type, objfile);
1296 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1299 /* Nope, so read it in and store it away. */
1300 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1302 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1304 symlist = &local_symbols;
1306 o_nsyms = osyms ? osyms->nsyms : 0;
1308 /* Now examine each parameter noting its type, location, and a
1309 wealth of other information. */
1310 while (param.word && param.word != DNTTNIL)
1312 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1314 param = paramp->dfparam.nextparam;
1317 name = VT (objfile) + paramp->dfparam.name;
1318 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1319 sizeof (struct symbol));
1320 (void) memset (sym, 0, sizeof (struct symbol));
1321 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1322 &objfile->symbol_obstack);
1324 /* Figure out where it lives. */
1325 if (paramp->dfparam.regparam)
1326 SYMBOL_CLASS (sym) = LOC_REGPARM;
1327 else if (paramp->dfparam.indirect)
1328 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1330 SYMBOL_CLASS (sym) = LOC_ARG;
1331 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1332 if (paramp->dfparam.copyparam)
1334 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1335 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1337 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1339 /* This is likely a pass-by-invisible reference parameter,
1340 Hack on the symbol class to make GDB happy. */
1341 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1344 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1347 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1349 /* Add it to the list. */
1350 add_symbol_to_list (sym, symlist);
1353 /* Note how many parameters we found. */
1354 TYPE_NFIELDS (type) = nsyms;
1355 TYPE_FIELDS (type) = (struct field *)
1356 obstack_alloc (&objfile->type_obstack,
1357 sizeof (struct field) * nsyms);
1359 /* Find the symbols for the values and put them into the type.
1360 The symbols can be found in the symlist that we put them on
1361 to cause them to be defined. osyms contains the old value
1362 of that symlist; everything up to there was defined by us. */
1363 /* Note that we preserve the order of the parameters, so
1364 that in something like "enum {FOO, LAST_THING=FOO}" we print
1365 FOO, not LAST_THING. */
1366 for (syms = *symlist, n = 0; syms; syms = syms->next)
1371 for (; j < syms->nsyms; j++, n++)
1373 struct symbol *xsym = syms->symbol[j];
1374 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1375 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1376 TYPE_FIELD_BITPOS (type, n) = n;
1377 TYPE_FIELD_BITSIZE (type, n) = 0;
1385 /* Read in and internalize a structure definition. */
1387 static struct type *
1388 hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1389 struct objfile *objfile)
1393 struct nextfield *next;
1398 struct nextfield *list = 0;
1399 struct nextfield *new;
1402 union dnttentry *fieldp;
1404 /* Is it something we've already dealt with? */
1405 type = hpread_alloc_type (hp_type, objfile);
1406 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1407 (TYPE_CODE (type) == TYPE_CODE_UNION))
1410 /* Get the basic type correct. */
1411 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1413 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1414 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1416 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1418 TYPE_CODE (type) = TYPE_CODE_UNION;
1419 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1425 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1427 /* Read in and internalize all the fields. */
1428 field = dn_bufp->dstruct.firstfield;
1429 while (field.word != DNTTNIL && field.dnttp.extension)
1431 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1433 /* Get space to record the next field's data. */
1434 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1438 list->field.name = VT (objfile) + fieldp->dfield.name;
1439 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1440 if (fieldp->dfield.bitlength % 8)
1441 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1443 FIELD_BITSIZE (list->field) = 0;
1445 field = fieldp->dfield.nextfield;
1446 FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1450 TYPE_NFIELDS (type) = nfields;
1451 TYPE_FIELDS (type) = (struct field *)
1452 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1454 /* Copy the saved-up fields into the field vector. */
1455 for (n = nfields; list; list = list->next)
1458 TYPE_FIELD (type, n) = list->field;
1463 /* Read in and internalize a set debug symbol. */
1465 static struct type *
1466 hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1467 struct objfile *objfile)
1471 /* See if it's something we've already deal with. */
1472 type = hpread_alloc_type (hp_type, objfile);
1473 if (TYPE_CODE (type) == TYPE_CODE_SET)
1476 /* Nope. Fill in the appropriate fields. */
1477 TYPE_CODE (type) = TYPE_CODE_SET;
1478 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1479 TYPE_NFIELDS (type) = 0;
1480 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1485 /* Read in and internalize an array debug symbol. */
1487 static struct type *
1488 hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1489 struct objfile *objfile)
1492 union dnttentry save;
1495 /* Why no check here? Because it kept us from properly determining
1496 the size of the array! */
1497 type = hpread_alloc_type (hp_type, objfile);
1499 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1501 /* values are not normalized. */
1502 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1503 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1505 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1507 /* The HP debug format represents char foo[]; as an array with
1508 length 0x7fffffff. Internally GDB wants to represent this
1509 as an array of length zero. */
1510 TYPE_LENGTH (type) = 0;
1513 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1515 TYPE_NFIELDS (type) = 1;
1516 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1519 TYPE_FIELDS (type) = (struct field *)
1520 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1521 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1526 /* Read in and internalize a subrange debug symbol. */
1527 static struct type *
1528 hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1529 struct objfile *objfile)
1533 /* Is it something we've already dealt with. */
1534 type = hpread_alloc_type (hp_type, objfile);
1535 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1538 /* Nope, internalize it. */
1539 TYPE_CODE (type) = TYPE_CODE_RANGE;
1540 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1541 TYPE_NFIELDS (type) = 2;
1543 = (struct field *) obstack_alloc (&objfile->type_obstack,
1544 2 * sizeof (struct field));
1546 if (dn_bufp->dsubr.dyn_low)
1547 TYPE_FIELD_BITPOS (type, 0) = 0;
1549 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1551 if (dn_bufp->dsubr.dyn_high)
1552 TYPE_FIELD_BITPOS (type, 1) = -1;
1554 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1555 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1560 static struct type *
1561 hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile)
1563 union dnttentry *dn_bufp;
1565 /* First see if it's a simple builtin type. */
1566 if (hp_type.dntti.immediate)
1567 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1569 /* Not a builtin type. We'll have to read it in. */
1570 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1571 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1573 return lookup_fundamental_type (objfile, FT_VOID);
1575 switch (dn_bufp->dblock.kind)
1577 case DNTT_TYPE_SRCFILE:
1578 case DNTT_TYPE_MODULE:
1579 case DNTT_TYPE_FUNCTION:
1580 case DNTT_TYPE_ENTRY:
1581 case DNTT_TYPE_BEGIN:
1583 case DNTT_TYPE_IMPORT:
1584 case DNTT_TYPE_LABEL:
1585 case DNTT_TYPE_WITH:
1586 case DNTT_TYPE_COMMON:
1587 case DNTT_TYPE_FPARAM:
1588 case DNTT_TYPE_SVAR:
1589 case DNTT_TYPE_DVAR:
1590 case DNTT_TYPE_CONST:
1591 /* Opps. Something went very wrong. */
1592 return lookup_fundamental_type (objfile, FT_VOID);
1594 case DNTT_TYPE_TYPEDEF:
1596 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1599 suffix = VT (objfile) + dn_bufp->dtype.name;
1601 TYPE_CPLUS_SPECIFIC (structtype)
1602 = (struct cplus_struct_type *) &cplus_struct_default;
1603 TYPE_NAME (structtype) = suffix;
1607 case DNTT_TYPE_TAGDEF:
1609 /* Just a little different from above. We have to tack on
1610 an identifier of some kind (struct, union, enum, etc). */
1611 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1613 char *prefix, *suffix;
1614 suffix = VT (objfile) + dn_bufp->dtype.name;
1616 /* Lookup the next type in the list. It should be a structure,
1617 union, or enum type. We will need to attach that to our name. */
1618 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1619 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1623 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1625 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1630 /* Build the correct name. */
1632 = (char *) obstack_alloc (&objfile->type_obstack,
1633 strlen (prefix) + strlen (suffix) + 1);
1634 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1635 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1636 TYPE_TAG_NAME (structtype) = suffix;
1638 TYPE_CPLUS_SPECIFIC (structtype)
1639 = (struct cplus_struct_type *) &cplus_struct_default;
1643 case DNTT_TYPE_POINTER:
1644 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1646 case DNTT_TYPE_ENUM:
1647 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1648 case DNTT_TYPE_MEMENUM:
1649 return lookup_fundamental_type (objfile, FT_VOID);
1651 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1652 case DNTT_TYPE_SUBRANGE:
1653 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1654 case DNTT_TYPE_ARRAY:
1655 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1656 case DNTT_TYPE_STRUCT:
1657 case DNTT_TYPE_UNION:
1658 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1659 case DNTT_TYPE_FIELD:
1660 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1661 case DNTT_TYPE_VARIANT:
1662 case DNTT_TYPE_FILE:
1663 return lookup_fundamental_type (objfile, FT_VOID);
1664 case DNTT_TYPE_FUNCTYPE:
1665 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1667 case DNTT_TYPE_COBSTRUCT:
1668 case DNTT_TYPE_XREF:
1670 case DNTT_TYPE_MACRO:
1672 return lookup_fundamental_type (objfile, FT_VOID);
1677 hpread_record_lines (struct subfile *subfile, sltpointer s_idx,
1678 sltpointer e_idx, struct objfile *objfile,
1681 union sltentry *sl_bufp;
1683 while (s_idx <= e_idx)
1685 sl_bufp = hpread_get_slt (s_idx, objfile);
1686 /* Only record "normal" entries in the SLT. */
1687 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1688 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1689 record_line (subfile, sl_bufp->snorm.line,
1690 sl_bufp->snorm.address + offset);
1696 /* Internalize one native debug symbol. */
1699 hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name,
1700 struct section_offsets *section_offsets,
1701 struct objfile *objfile, CORE_ADDR text_offset,
1702 int text_size, char *filename, int index)
1707 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1708 union dnttentry *dn_temp;
1709 dnttpointer hp_type;
1711 struct context_stack *new;
1713 /* Allocate one GDB debug symbol and fill in some default values. */
1714 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1715 sizeof (struct symbol));
1716 memset (sym, 0, sizeof (struct symbol));
1717 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1718 SYMBOL_LANGUAGE (sym) = language_auto;
1719 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1720 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1721 SYMBOL_LINE (sym) = 0;
1722 SYMBOL_VALUE (sym) = 0;
1723 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1725 hp_type.dnttp.extension = 1;
1726 hp_type.dnttp.immediate = 0;
1727 hp_type.dnttp.global = 0;
1728 hp_type.dnttp.index = index;
1730 type = dn_bufp->dblock.kind;
1734 case DNTT_TYPE_SRCFILE:
1735 /* This type of symbol indicates from which source file or include file
1736 the following data comes. If there are no modules it also may
1737 indicate the start of a new source file, in which case we must
1738 finish the symbol table of the previous source file
1739 (if any) and start accumulating a new symbol table. */
1742 if (!last_source_file)
1744 start_symtab (name, NULL, valu);
1745 record_debugformat ("HP");
1746 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1750 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1752 dn_bufp->dsfile.address,
1755 start_subfile (name, NULL);
1758 case DNTT_TYPE_MODULE:
1759 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1762 case DNTT_TYPE_FUNCTION:
1763 case DNTT_TYPE_ENTRY:
1764 /* A function or secondary entry point. */
1765 valu = dn_bufp->dfunc.lowaddr + offset;
1766 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1768 dn_bufp->dfunc.address,
1771 WITHIN_FUNCTION (objfile) = 1;
1772 CURRENT_FUNCTION_VALUE (objfile) = valu;
1774 /* Stack must be empty now. */
1775 if (context_stack_depth != 0)
1776 complain (&lbrac_unmatched_complaint, (char *) symnum);
1777 new = push_context (0, valu);
1779 SYMBOL_CLASS (sym) = LOC_BLOCK;
1780 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1781 if (dn_bufp->dfunc.global)
1782 add_symbol_to_list (sym, &global_symbols);
1784 add_symbol_to_list (sym, &file_symbols);
1787 /* Search forward to the next scope beginning. */
1788 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1790 dn_bufp = hpread_get_lntt (++index, objfile);
1791 if (dn_bufp->dblock.extension)
1794 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1796 dn_bufp->dbegin.address,
1798 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1799 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1802 case DNTT_TYPE_BEGIN:
1803 /* Begin a new scope. */
1804 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1806 dn_bufp->dbegin.address,
1808 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1809 valu += offset; /* Relocate for dynamic loading */
1810 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1811 new = push_context (desc, valu);
1816 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1818 dn_bufp->dend.address + 1,
1820 switch (dn_bufp->dend.endkind)
1822 case DNTT_TYPE_MODULE:
1823 /* Ending a module ends the symbol table for that module. */
1824 valu = text_offset + text_size + offset;
1825 (void) end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
1828 case DNTT_TYPE_FUNCTION:
1829 /* Ending a function, well, ends the function's scope. */
1830 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1832 valu = dn_temp->dfunc.hiaddr + offset;
1833 new = pop_context ();
1834 /* Make a block for the local symbols within. */
1835 finish_block (new->name, &local_symbols, new->old_blocks,
1836 new->start_addr, valu, objfile);
1837 WITHIN_FUNCTION (objfile) = 0;
1839 case DNTT_TYPE_BEGIN:
1840 /* Just ending a local scope. */
1841 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1842 /* Why in the hell is this needed? */
1843 valu += offset + 9; /* Relocate for dynamic loading */
1844 new = pop_context ();
1845 desc = dn_bufp->dend.beginscope.dnttp.index;
1846 if (desc != new->depth)
1847 complain (&lbrac_mismatch_complaint, (char *) symnum);
1848 /* Make a block for the local symbols within. */
1849 finish_block (new->name, &local_symbols, new->old_blocks,
1850 new->start_addr, valu, objfile);
1851 local_symbols = new->locals;
1855 case DNTT_TYPE_LABEL:
1856 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1858 case DNTT_TYPE_FPARAM:
1859 /* Function parameters. */
1860 if (dn_bufp->dfparam.regparam)
1861 SYMBOL_CLASS (sym) = LOC_REGISTER;
1863 SYMBOL_CLASS (sym) = LOC_LOCAL;
1864 if (dn_bufp->dfparam.copyparam)
1866 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1867 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1869 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1873 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1874 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1875 add_symbol_to_list (sym, &local_symbols);
1877 case DNTT_TYPE_SVAR:
1878 /* Static variables. */
1879 SYMBOL_CLASS (sym) = LOC_STATIC;
1880 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1881 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1882 if (dn_bufp->dsvar.global)
1883 add_symbol_to_list (sym, &global_symbols);
1884 else if (WITHIN_FUNCTION (objfile))
1885 add_symbol_to_list (sym, &local_symbols);
1887 add_symbol_to_list (sym, &file_symbols);
1889 case DNTT_TYPE_DVAR:
1890 /* Dynamic variables. */
1891 if (dn_bufp->ddvar.regvar)
1892 SYMBOL_CLASS (sym) = LOC_REGISTER;
1894 SYMBOL_CLASS (sym) = LOC_LOCAL;
1895 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1896 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1898 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1900 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1901 if (dn_bufp->ddvar.global)
1902 add_symbol_to_list (sym, &global_symbols);
1903 else if (WITHIN_FUNCTION (objfile))
1904 add_symbol_to_list (sym, &local_symbols);
1906 add_symbol_to_list (sym, &file_symbols);
1908 case DNTT_TYPE_CONST:
1909 /* A constant (pascal?). */
1910 SYMBOL_CLASS (sym) = LOC_CONST;
1911 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1912 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1913 if (dn_bufp->dconst.global)
1914 add_symbol_to_list (sym, &global_symbols);
1915 else if (WITHIN_FUNCTION (objfile))
1916 add_symbol_to_list (sym, &local_symbols);
1918 add_symbol_to_list (sym, &file_symbols);
1920 case DNTT_TYPE_TYPEDEF:
1921 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1922 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1923 if (dn_bufp->dtype.global)
1924 add_symbol_to_list (sym, &global_symbols);
1925 else if (WITHIN_FUNCTION (objfile))
1926 add_symbol_to_list (sym, &local_symbols);
1928 add_symbol_to_list (sym, &file_symbols);
1930 case DNTT_TYPE_TAGDEF:
1931 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1932 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1933 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1934 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
1935 if (dn_bufp->dtype.global)
1936 add_symbol_to_list (sym, &global_symbols);
1937 else if (WITHIN_FUNCTION (objfile))
1938 add_symbol_to_list (sym, &local_symbols);
1940 add_symbol_to_list (sym, &file_symbols);
1942 case DNTT_TYPE_POINTER:
1943 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
1944 (dn_bufp->dptr.pointsto,
1946 add_symbol_to_list (sym, &file_symbols);
1948 case DNTT_TYPE_ENUM:
1949 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1950 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
1951 add_symbol_to_list (sym, &file_symbols);
1953 case DNTT_TYPE_MEMENUM:
1956 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
1957 add_symbol_to_list (sym, &file_symbols);
1959 case DNTT_TYPE_SUBRANGE:
1960 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
1962 add_symbol_to_list (sym, &file_symbols);
1964 case DNTT_TYPE_ARRAY:
1965 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
1966 add_symbol_to_list (sym, &file_symbols);
1968 case DNTT_TYPE_STRUCT:
1969 case DNTT_TYPE_UNION:
1970 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1971 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
1972 add_symbol_to_list (sym, &file_symbols);