1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
26 #include "hp-symtab.h"
32 #include "complaints.h"
33 #include "gdb-stabs.h"
36 /* Private information attached to an objfile which we use to find
37 and internalize the HP C debug symbols within that objfile. */
39 struct hpread_symfile_info
41 /* The contents of each of the debug sections (there are 4 of them). */
47 /* We keep the size of the $VT$ section for range checking. */
50 /* Some routines still need to know the number of symbols in the
51 main debug sections ($LNTT$ and $GNTT$). */
52 unsigned int lntt_symcount;
53 unsigned int gntt_symcount;
55 /* To keep track of all the types we've processed. */
56 struct type **type_vector;
57 int type_vector_length;
59 /* Keeps track of the beginning of a range of source lines. */
62 /* Some state variables we'll need. */
65 /* Keep track of the current function's address. We may need to look
66 up something based on this address. */
67 unsigned int current_function_value;
70 /* Accessor macros to get at the fields. */
71 #define HPUX_SYMFILE_INFO(o) \
72 ((struct hpread_symfile_info *)((o)->sym_private))
73 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
74 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
75 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
76 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
77 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
78 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
79 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
80 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
81 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
82 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
83 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
84 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
86 /* Given the native debug symbol SYM, set NAMEP to the name associated
87 with the debug symbol. Note we may be called with a debug symbol which
88 has no associated name, in that case we return an empty string.
90 Also note we "know" that the name for any symbol is always in the
91 same place. Hence we don't have to conditionalize on the symbol type. */
92 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
93 if (! hpread_has_name ((SYM)->dblock.kind)) \
95 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
97 complain (&string_table_offset_complaint, (char *) symnum); \
101 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
103 /* Each partial symbol table entry contains a pointer to private data for the
104 read_symtab() function to use when expanding a partial symbol table entry
105 to a full symbol table entry.
107 For hpuxread this structure contains the offset within the file symbol table
108 of first local symbol for this file, and length (in bytes) of the section
109 of the symbol table devoted to this file's symbols (actually, the section
110 bracketed may contain more than just this file's symbols).
112 If ldsymlen is 0, the only reason for this thing's existence is the
113 dependency list. Nothing else will happen when it is read in. */
115 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
116 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
117 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
125 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
126 /* Nonzero means give verbose info on gdb action. */
127 extern int info_verbose;
129 /* Complaints about the symbols we have encountered. */
130 extern struct complaint string_table_offset_complaint;
131 extern struct complaint lbrac_unmatched_complaint;
132 extern struct complaint lbrac_mismatch_complaint;
135 void hpread_symfile_init PARAMS ((struct objfile *));
137 static struct type *hpread_alloc_type
138 PARAMS ((dnttpointer, struct objfile *));
140 static struct type **hpread_lookup_type
141 PARAMS ((dnttpointer, struct objfile *));
143 static struct type *hpread_read_enum_type
144 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
146 static struct type *hpread_read_set_type
147 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
149 static struct type *hpread_read_subrange_type
150 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
152 static struct type *hpread_read_struct_type
153 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
155 void hpread_build_psymtabs
156 PARAMS ((struct objfile *, struct section_offsets *, int));
158 void hpread_symfile_finish PARAMS ((struct objfile *));
160 static struct partial_symtab *hpread_start_psymtab
161 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
162 struct partial_symbol *, struct partial_symbol *));
164 static struct partial_symtab *hpread_end_psymtab
165 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
166 struct partial_symtab **, int));
168 static struct symtab *hpread_expand_symtab
169 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
170 struct section_offsets *, char *));
172 static void hpread_process_one_debug_symbol
173 PARAMS ((union dnttentry *, char *, struct section_offsets *,
174 struct objfile *, CORE_ADDR, int, char *, int));
176 static sltpointer hpread_record_lines
177 PARAMS ((struct subfile *, sltpointer, sltpointer, struct objfile *));
179 static struct type *hpread_read_function_type
180 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
182 static struct type * hpread_type_lookup
183 PARAMS ((dnttpointer, struct objfile *));
185 static unsigned long hpread_get_depth
186 PARAMS ((sltpointer, struct objfile *));
188 static unsigned long hpread_get_line
189 PARAMS ((sltpointer, struct objfile *));
191 static CORE_ADDR hpread_get_location
192 PARAMS ((sltpointer, struct objfile *));
194 static int hpread_type_translate PARAMS ((dnttpointer));
195 static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
196 static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
197 static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
198 static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
199 static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
200 static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
201 static int hpread_has_name PARAMS ((enum dntt_entry_type));
204 /* Initialization for reading native HP C debug symbols from OBJFILE.
206 It's only purpose in life is to set up the symbol reader's private
207 per-objfile data structures, and read in the raw contents of the debug
208 sections (attaching pointers to the debug info into the private data
211 Since BFD doesn't know how to read debug symbols in a format-independent
212 way (and may never do so...), we have to do it ourselves. Note we may
213 be called on a file without native HP C debugging symbols.
214 FIXME, there should be a cleaner peephole into the BFD environment here. */
217 hpread_symfile_init (objfile)
218 struct objfile *objfile;
220 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
222 /* Allocate struct to keep track of the symfile */
223 objfile->sym_private = (PTR)
224 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
225 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
227 /* We haven't read in any types yet. */
228 TYPE_VECTOR (objfile) = 0;
230 /* Read in data from the $GNTT$ subspace. */
231 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
236 = obstack_alloc (&objfile->symbol_obstack,
237 bfd_section_size (objfile->obfd, gntt_section));
239 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
240 0, bfd_section_size (objfile->obfd, gntt_section));
242 GNTT_SYMCOUNT (objfile)
243 = bfd_section_size (objfile->obfd, gntt_section)
244 / sizeof (struct dntt_type_block);
246 /* Read in data from the $LNTT$ subspace. Also keep track of the number
248 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
253 = obstack_alloc (&objfile->symbol_obstack,
254 bfd_section_size (objfile->obfd, lntt_section));
256 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
257 0, bfd_section_size (objfile->obfd, lntt_section));
259 LNTT_SYMCOUNT (objfile)
260 = bfd_section_size (objfile->obfd, lntt_section)
261 / sizeof (struct dntt_type_block);
263 /* Read in data from the $SLT$ subspace. $SLT$ contains information
264 on source line numbers. */
265 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
270 obstack_alloc (&objfile->symbol_obstack,
271 bfd_section_size (objfile->obfd, slt_section));
273 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
274 0, bfd_section_size (objfile->obfd, slt_section));
276 /* Read in data from the $VT$ subspace. $VT$ contains things like
277 names and constants. Keep track of the number of symbols in the VT. */
278 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
282 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
285 (char *) obstack_alloc (&objfile->symbol_obstack,
288 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
289 0, VT_SIZE (objfile));
292 /* Scan and build partial symbols for a symbol file.
294 The minimal symbol table (either SOM or HP a.out) has already been
295 read in; all we need to do is setup partial symbols based on the
296 native debugging information.
298 We assume hpread_symfile_init has been called to initialize the
299 symbol reader's private data structures.
301 SECTION_OFFSETS contains offsets relative to which the symbols in the
302 various sections are (depending where the sections were actually loaded).
303 MAINLINE is true if we are reading the main symbol
304 table (as opposed to a shared lib or dynamically loaded file). */
307 hpread_build_psymtabs (objfile, section_offsets, mainline)
308 struct objfile *objfile;
309 struct section_offsets *section_offsets;
313 int past_first_source_file = 0;
314 struct cleanup *old_chain;
316 int hp_symnum, symcount, i;
318 union dnttentry *dn_bufp;
324 /* Current partial symtab */
325 struct partial_symtab *pst;
327 /* List of current psymtab's include files */
328 char **psymtab_include_list;
329 int includes_allocated;
332 /* Index within current psymtab dependency list */
333 struct partial_symtab **dependency_list;
334 int dependencies_used, dependencies_allocated;
336 /* Just in case the stabs reader left turds lying around. */
338 make_cleanup (really_free_pendings, 0);
340 pst = (struct partial_symtab *) 0;
342 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
343 a number of problems with cross compilation and creating useless holes
344 in the stack when we have to allocate new entries. FIXME. */
346 includes_allocated = 30;
348 psymtab_include_list = (char **) alloca (includes_allocated *
351 dependencies_allocated = 30;
352 dependencies_used = 0;
354 (struct partial_symtab **) alloca (dependencies_allocated *
355 sizeof (struct partial_symtab *));
357 old_chain = make_cleanup (free_objfile, objfile);
359 last_source_file = 0;
361 /* Make two passes, one ofr the GNTT symbols, the other for the
363 for (i = 0; i < 1; i++)
365 int within_function = 0;
368 symcount = GNTT_SYMCOUNT (objfile);
370 symcount = LNTT_SYMCOUNT (objfile);
372 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
376 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
378 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
380 if (dn_bufp->dblock.extension)
383 /* Only handle things which are necessary for minimal symbols.
384 everything else is ignored. */
385 switch (dn_bufp->dblock.kind)
387 case DNTT_TYPE_SRCFILE:
389 /* A source file of some kind. Note this may simply
390 be an included file. */
391 SET_NAMESTRING (dn_bufp, &namestring, objfile);
393 /* Check if this is the source file we are already working
395 if (pst && !strcmp (namestring, pst->filename))
398 /* Check if this is an include file, if so check if we have
399 already seen it. Add it to the include list */
400 p = strrchr (namestring, '.');
401 if (!strcmp (p, ".h"))
406 for (j = 0; j < includes_used; j++)
407 if (!strcmp (namestring, psymtab_include_list[j]))
415 /* Add it to the list of includes seen so far and
416 allocate more include space if necessary. */
417 psymtab_include_list[includes_used++] = namestring;
418 if (includes_used >= includes_allocated)
420 char **orig = psymtab_include_list;
422 psymtab_include_list = (char **)
423 alloca ((includes_allocated *= 2) *
425 memcpy ((PTR) psymtab_include_list, (PTR) orig,
426 includes_used * sizeof (char *));
436 pst->filename = (char *)
437 obstack_alloc (&pst->objfile->psymbol_obstack,
438 strlen (namestring) + 1);
439 strcpy (pst->filename, namestring);
446 /* This is a bonafide new source file.
447 End the current partial symtab and start a new one. */
449 if (pst && past_first_source_file)
451 texthigh += ANOFFSET (section_offsets, SECT_OFF_TEXT);
452 hpread_end_psymtab (pst, psymtab_include_list,
455 * sizeof (struct dntt_type_block)),
457 dependency_list, dependencies_used);
458 pst = (struct partial_symtab *) 0;
460 dependencies_used = 0;
463 past_first_source_file = 1;
465 valu = hpread_get_textlow (i, hp_symnum, objfile);
466 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
467 pst = hpread_start_psymtab (objfile, section_offsets,
470 * sizeof (struct dntt_type_block)),
471 objfile->global_psymbols.next,
472 objfile->static_psymbols.next);
478 case DNTT_TYPE_MODULE:
479 /* A source file. It's still unclear to me what the
480 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
481 is supposed to be. */
482 SET_NAMESTRING (dn_bufp, &namestring, objfile);
483 valu = hpread_get_textlow (i, hp_symnum, objfile);
484 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
487 pst = hpread_start_psymtab (objfile, section_offsets,
490 * sizeof (struct dntt_type_block)),
491 objfile->global_psymbols.next,
492 objfile->static_psymbols.next);
497 case DNTT_TYPE_FUNCTION:
498 case DNTT_TYPE_ENTRY:
499 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
500 a secondary entry point. */
501 valu = dn_bufp->dfunc.lowaddr +
502 ANOFFSET (section_offsets, SECT_OFF_TEXT);
503 if (dn_bufp->dfunc.hiaddr > texthigh)
504 texthigh = dn_bufp->dfunc.hiaddr;
505 SET_NAMESTRING (dn_bufp, &namestring, objfile);
506 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
507 VAR_NAMESPACE, LOC_BLOCK,
508 objfile->static_psymbols, valu,
509 language_unknown, objfile);
512 case DNTT_TYPE_BEGIN:
514 /* Scope block begin/end. We only care about function
515 and file blocks right now. */
516 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
518 texthigh += ANOFFSET (section_offsets, SECT_OFF_TEXT);
519 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
521 * sizeof (struct dntt_type_block)),
523 dependency_list, dependencies_used);
524 pst = (struct partial_symtab *) 0;
526 dependencies_used = 0;
529 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
534 case DNTT_TYPE_TYPEDEF:
535 case DNTT_TYPE_TAGDEF:
537 /* Variables, typedefs an the like. */
538 enum address_class storage;
539 enum namespace namespace;
541 /* Don't add locals to the partial symbol table. */
543 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
544 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
547 /* TAGDEFs go into the structure namespace. */
548 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
549 namespace = STRUCT_NAMESPACE;
551 namespace = VAR_NAMESPACE;
553 /* What kind of "storage" does this use? */
554 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
555 storage = LOC_STATIC;
556 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
557 && dn_bufp->ddvar.regvar)
558 storage = LOC_REGISTER;
559 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
564 SET_NAMESTRING (dn_bufp, &namestring, objfile);
567 pst = hpread_start_psymtab (objfile, section_offsets,
570 * sizeof (struct dntt_type_block)),
571 objfile->global_psymbols.next,
572 objfile->static_psymbols.next);
574 if (dn_bufp->dsvar.global)
576 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
578 objfile->global_psymbols,
579 dn_bufp->dsvar.location,
580 language_unknown, objfile);
584 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
586 objfile->static_psymbols,
587 dn_bufp->dsvar.location,
588 language_unknown, objfile);
592 case DNTT_TYPE_MEMENUM:
593 case DNTT_TYPE_CONST:
594 /* Constants and members of enumerated types. */
595 SET_NAMESTRING (dn_bufp, &namestring, objfile);
598 pst = hpread_start_psymtab (objfile, section_offsets,
601 * sizeof (struct dntt_type_block)),
602 objfile->global_psymbols.next,
603 objfile->static_psymbols.next);
605 ADD_PSYMBOL_TO_LIST (namestring, strlen (namestring),
606 VAR_NAMESPACE, LOC_CONST,
607 objfile->static_psymbols, 0,
608 language_unknown, objfile);
616 /* End any pending partial symbol table. */
619 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
620 hp_symnum * sizeof (struct dntt_type_block),
621 0, dependency_list, dependencies_used);
624 discard_cleanups (old_chain);
627 /* Perform any local cleanups required when we are done with a particular
628 objfile. I.E, we are in the process of discarding all symbol information
629 for an objfile, freeing up all memory held for it, and unlinking the
630 objfile struct from the global list of known objfiles. */
633 hpread_symfile_finish (objfile)
634 struct objfile *objfile;
636 if (objfile->sym_private != NULL)
638 mfree (objfile->md, objfile->sym_private);
643 /* The remaining functions are all for internal use only. */
645 /* Various small functions to get entries in the debug symbol sections. */
647 static union dnttentry *
648 hpread_get_lntt (index, objfile)
650 struct objfile *objfile;
652 return (union dnttentry *)
653 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
656 static union dnttentry *
657 hpread_get_gntt (index, objfile)
659 struct objfile *objfile;
661 return (union dnttentry *)
662 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
665 static union sltentry *
666 hpread_get_slt (index, objfile)
668 struct objfile *objfile;
670 return (union sltentry *)&(SLT (objfile)[index * sizeof (union sltentry)]);
673 /* Get the low address associated with some symbol (typically the start
674 of a particular source file or module). Since that information is not
675 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
676 the existance of DNTT_TYPE_FUNCTION symbols. */
679 hpread_get_textlow (global, index, objfile)
682 struct objfile *objfile;
684 union dnttentry *dn_bufp;
685 struct minimal_symbol *msymbol;
687 /* Look for a DNTT_TYPE_FUNCTION symbol. */
691 dn_bufp = hpread_get_gntt (index++, objfile);
693 dn_bufp = hpread_get_lntt (index++, objfile);
694 } while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
695 && dn_bufp->dblock.kind != DNTT_TYPE_END);
697 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
698 might happen when a sourcefile has no functions. */
699 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
702 /* The minimal symbols are typically more accurate for some reason. */
703 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile),
706 return SYMBOL_VALUE_ADDRESS (msymbol);
708 return dn_bufp->dfunc.lowaddr;
711 /* Get the nesting depth for the source line identified by INDEX. */
714 hpread_get_depth (index, objfile)
716 struct objfile *objfile;
718 union sltentry *sl_bufp;
720 sl_bufp = hpread_get_slt (index, objfile);
721 return sl_bufp->sspec.backptr.dnttp.index;
724 /* Get the source line number the the line identified by INDEX. */
727 hpread_get_line (index, objfile)
729 struct objfile *objfile;
731 union sltentry *sl_bufp;
733 sl_bufp = hpread_get_slt (index, objfile);
734 return sl_bufp->snorm.line;
738 hpread_get_location (index, objfile)
740 struct objfile *objfile;
742 union sltentry *sl_bufp;
745 /* code location of special sltentrys is determined from context */
746 sl_bufp = hpread_get_slt (index, objfile);
748 if (sl_bufp->snorm.sltdesc == SLT_END)
750 /* find previous normal sltentry and get address */
751 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
752 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
753 sl_bufp = hpread_get_slt (index - i, objfile);
754 return sl_bufp->snorm.address;
757 /* find next normal sltentry and get address */
758 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
759 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
760 sl_bufp = hpread_get_slt (index + i, objfile);
761 return sl_bufp->snorm.address;
765 /* Return 1 if an HP debug symbol of type KIND has a name associated with
766 it, else return 0. */
769 hpread_has_name (kind)
770 enum dntt_entry_type kind;
774 case DNTT_TYPE_SRCFILE:
775 case DNTT_TYPE_MODULE:
776 case DNTT_TYPE_FUNCTION:
777 case DNTT_TYPE_ENTRY:
778 case DNTT_TYPE_IMPORT:
779 case DNTT_TYPE_LABEL:
780 case DNTT_TYPE_FPARAM:
783 case DNTT_TYPE_CONST:
784 case DNTT_TYPE_TYPEDEF:
785 case DNTT_TYPE_TAGDEF:
786 case DNTT_TYPE_MEMENUM:
787 case DNTT_TYPE_FIELD:
791 case DNTT_TYPE_BEGIN:
794 case DNTT_TYPE_COMMON:
795 case DNTT_TYPE_POINTER:
798 case DNTT_TYPE_SUBRANGE:
799 case DNTT_TYPE_ARRAY:
800 case DNTT_TYPE_STRUCT:
801 case DNTT_TYPE_UNION:
802 case DNTT_TYPE_VARIANT:
804 case DNTT_TYPE_FUNCTYPE:
805 case DNTT_TYPE_COBSTRUCT:
807 case DNTT_TYPE_MACRO:
813 /* Allocate and partially fill a partial symtab. It will be
814 completely filled at the end of the symbol list.
816 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
817 is the address relative to which its symbols are (incremental) or 0
820 static struct partial_symtab *
821 hpread_start_psymtab (objfile, section_offsets,
822 filename, textlow, ldsymoff, global_syms, static_syms)
823 struct objfile *objfile;
824 struct section_offsets *section_offsets;
828 struct partial_symbol *global_syms;
829 struct partial_symbol *static_syms;
831 struct partial_symtab *result =
832 start_psymtab_common (objfile, section_offsets,
833 filename, textlow, global_syms, static_syms);
835 result->read_symtab_private = (char *)
836 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
837 LDSYMOFF (result) = ldsymoff;
838 result->read_symtab = hpread_psymtab_to_symtab;
844 /* Close off the current usage of PST.
845 Returns PST or NULL if the partial symtab was empty and thrown away.
847 FIXME: List variables and peculiarities of same. */
849 static struct partial_symtab *
850 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
851 capping_text, dependency_list, number_dependencies)
852 struct partial_symtab *pst;
855 int capping_symbol_offset;
856 CORE_ADDR capping_text;
857 struct partial_symtab **dependency_list;
858 int number_dependencies;
861 struct objfile *objfile = pst -> objfile;
863 if (capping_symbol_offset != -1)
864 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
865 pst->texthigh = capping_text;
868 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
870 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
872 pst->number_of_dependencies = number_dependencies;
873 if (number_dependencies)
875 pst->dependencies = (struct partial_symtab **)
876 obstack_alloc (&objfile->psymbol_obstack,
877 number_dependencies * sizeof (struct partial_symtab *));
878 memcpy (pst->dependencies, dependency_list,
879 number_dependencies * sizeof (struct partial_symtab *));
882 pst->dependencies = 0;
884 for (i = 0; i < num_includes; i++)
886 struct partial_symtab *subpst =
887 allocate_psymtab (include_list[i], objfile);
889 subpst->section_offsets = pst->section_offsets;
890 subpst->read_symtab_private =
891 (char *) obstack_alloc (&objfile->psymbol_obstack,
892 sizeof (struct symloc));
896 subpst->texthigh = 0;
898 /* We could save slight bits of space by only making one of these,
899 shared by the entire set of include files. FIXME-someday. */
900 subpst->dependencies = (struct partial_symtab **)
901 obstack_alloc (&objfile->psymbol_obstack,
902 sizeof (struct partial_symtab *));
903 subpst->dependencies[0] = pst;
904 subpst->number_of_dependencies = 1;
906 subpst->globals_offset =
907 subpst->n_global_syms =
908 subpst->statics_offset =
909 subpst->n_static_syms = 0;
913 subpst->read_symtab = pst->read_symtab;
916 sort_pst_symbols (pst);
918 /* If there is already a psymtab or symtab for a file of this name, remove it.
919 (If there is a symtab, more drastic things also happen.)
920 This happens in VxWorks. */
921 free_named_symtabs (pst->filename);
923 if (num_includes == 0
924 && number_dependencies == 0
925 && pst->n_global_syms == 0
926 && pst->n_static_syms == 0)
928 /* Throw away this psymtab, it's empty. We can't deallocate it, since
929 it is on the obstack, but we can forget to chain it on the list. */
930 /* Empty psymtabs happen as a result of header files which don't have
931 any symbols in them. There can be a lot of them. But this check
932 is wrong, in that a psymtab with N_SLINE entries but nothing else
933 is not empty, but we don't realize that. Fixing that without slowing
934 things down might be tricky. */
935 struct partial_symtab *prev_pst;
937 /* First, snip it out of the psymtab chain */
939 if (pst->objfile->psymtabs == pst)
940 pst->objfile->psymtabs = pst->next;
942 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
943 if (prev_pst->next == pst)
944 prev_pst->next = pst->next;
946 /* Next, put it on a free list for recycling */
948 pst->next = pst->objfile->free_psymtabs;
949 pst->objfile->free_psymtabs = pst;
951 /* Indicate that psymtab was thrown away. */
952 pst = (struct partial_symtab *)NULL;
957 /* Do the dirty work of reading in the full symbol from a partial symbol
961 hpread_psymtab_to_symtab_1 (pst)
962 struct partial_symtab *pst;
964 struct cleanup *old_chain;
967 /* Get out quick if passed junk. */
971 /* Complain if we've already read in this symbol table. */
974 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
979 /* Read in all partial symtabs on which this one is dependent */
980 for (i = 0; i < pst->number_of_dependencies; i++)
981 if (!pst->dependencies[i]->readin)
983 /* Inform about additional files that need to be read in. */
986 fputs_filtered (" ", stdout);
988 fputs_filtered ("and ", stdout);
990 printf_filtered ("%s...", pst->dependencies[i]->filename);
991 wrap_here (""); /* Flush output */
994 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
997 /* If it's real... */
1000 /* Init stuff necessary for reading in symbols */
1002 old_chain = make_cleanup (really_free_pendings, 0);
1005 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1006 pst->textlow, pst->texthigh - pst->textlow,
1007 pst->section_offsets, pst->filename);
1008 sort_symtab_syms (pst->symtab);
1010 do_cleanups (old_chain);
1016 /* Read in all of the symbols for a given psymtab for real.
1017 Be verbose about it if the user wants that. */
1020 hpread_psymtab_to_symtab (pst)
1021 struct partial_symtab *pst;
1023 /* Get out quick if given junk. */
1030 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1035 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1037 /* Print the message now, before reading the string table,
1038 to avoid disconcerting pauses. */
1041 printf_filtered ("Reading in symbols for %s...", pst->filename);
1045 hpread_psymtab_to_symtab_1 (pst);
1047 /* Match with global symbols. This only needs to be done once,
1048 after all of the symtabs and dependencies have been read in. */
1049 scan_file_globals (pst->objfile);
1051 /* Finish up the debug error message. */
1053 printf_filtered ("done.\n");
1056 /* Read in a defined section of a specific object file's symbols.
1058 DESC is the file descriptor for the file, positioned at the
1059 beginning of the symtab
1060 SYM_OFFSET is the offset within the file of
1061 the beginning of the symbols we want to read
1062 SYM_SIZE is the size of the symbol info to read in.
1063 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1064 TEXT_SIZE is the size of the text segment read in.
1065 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1067 static struct symtab *
1068 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1069 section_offsets, filename)
1070 struct objfile *objfile;
1073 CORE_ADDR text_offset;
1075 struct section_offsets *section_offsets;
1079 union dnttentry *dn_bufp;
1080 unsigned max_symnum;
1082 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1084 current_objfile = objfile;
1087 last_source_file = 0;
1089 dn_bufp = hpread_get_lntt (sym_index, objfile);
1090 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1091 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1092 start_symtab ("globals", NULL, 0);
1094 max_symnum = sym_size / sizeof (struct dntt_type_block);
1096 /* Read in and process each debug symbol within the specified range. */
1098 symnum < max_symnum;
1101 QUIT; /* Allow this to be interruptable */
1102 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1104 if (dn_bufp->dblock.extension)
1107 /* Yow! We call SET_NAMESTRING on things without names! */
1108 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1110 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1111 objfile, text_offset, text_size,
1112 filename, symnum + sym_index);
1115 current_objfile = NULL;
1117 return end_symtab (text_offset + text_size, 0, 0, objfile, 0);
1121 /* Convert basic types from HP debug format into GDB internal format. */
1124 hpread_type_translate (typep)
1127 if (!typep.dntti.immediate)
1130 switch (typep.dntti.type)
1132 case HP_TYPE_BOOLEAN:
1133 case HP_TYPE_BOOLEAN_S300_COMPAT:
1134 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1136 /* Ugh. No way to distinguish between signed and unsigned chars. */
1138 case HP_TYPE_WIDE_CHAR:
1141 if (typep.dntti.bitlength <= 8)
1143 if (typep.dntti.bitlength <= 16)
1145 if (typep.dntti.bitlength <= 32)
1147 return FT_LONG_LONG;
1150 case HP_TYPE_UNSIGNED_LONG:
1151 if (typep.dntti.bitlength <= 8)
1152 return FT_UNSIGNED_CHAR;
1153 if (typep.dntti.bitlength <= 16)
1154 return FT_UNSIGNED_SHORT;
1155 if (typep.dntti.bitlength <= 32)
1156 return FT_UNSIGNED_LONG;
1157 return FT_UNSIGNED_LONG_LONG;
1158 case HP_TYPE_UNSIGNED_INT:
1159 if (typep.dntti.bitlength <= 8)
1160 return FT_UNSIGNED_CHAR;
1161 if (typep.dntti.bitlength <= 16)
1162 return FT_UNSIGNED_SHORT;
1163 if (typep.dntti.bitlength <= 32)
1164 return FT_UNSIGNED_INTEGER;
1165 return FT_UNSIGNED_LONG_LONG;
1167 case HP_TYPE_REAL_3000:
1168 case HP_TYPE_DOUBLE:
1169 if (typep.dntti.bitlength == 64)
1170 return FT_DBL_PREC_FLOAT;
1171 if (typep.dntti.bitlength == 128)
1172 return FT_EXT_PREC_FLOAT;
1174 case HP_TYPE_COMPLEX:
1175 case HP_TYPE_COMPLEXS3000:
1176 if (typep.dntti.bitlength == 128)
1177 return FT_DBL_PREC_COMPLEX;
1178 if (typep.dntti.bitlength == 192)
1179 return FT_EXT_PREC_COMPLEX;
1181 case HP_TYPE_STRING200:
1182 case HP_TYPE_LONGSTRING200:
1183 case HP_TYPE_FTN_STRING_SPEC:
1184 case HP_TYPE_MOD_STRING_SPEC:
1185 case HP_TYPE_MOD_STRING_3000:
1186 case HP_TYPE_FTN_STRING_S300_COMPAT:
1187 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1194 /* Return the type associated with the index found in HP_TYPE. */
1196 static struct type **
1197 hpread_lookup_type (hp_type, objfile)
1198 dnttpointer hp_type;
1199 struct objfile *objfile;
1202 int index = hp_type.dnttp.index;
1204 if (hp_type.dntti.immediate)
1207 if (index < LNTT_SYMCOUNT (objfile))
1209 if (index >= TYPE_VECTOR_LENGTH (objfile))
1211 old_len = TYPE_VECTOR_LENGTH (objfile);
1214 TYPE_VECTOR_LENGTH (objfile) = 100;
1215 TYPE_VECTOR (objfile) = (struct type **)
1216 malloc (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1218 while (index >= TYPE_VECTOR_LENGTH (objfile))
1219 TYPE_VECTOR_LENGTH (objfile) *= 2;
1220 TYPE_VECTOR (objfile) = (struct type **)
1221 xrealloc ((char *) TYPE_VECTOR (objfile),
1222 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1223 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1224 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1225 sizeof (struct type *));
1227 return &TYPE_VECTOR (objfile)[index];
1233 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1234 Note we'll just return the address of a GDB internal type if we already
1235 have it lying around. */
1237 static struct type *
1238 hpread_alloc_type (hp_type, objfile)
1239 dnttpointer hp_type;
1240 struct objfile *objfile;
1242 struct type **type_addr;
1244 type_addr = hpread_lookup_type (hp_type, objfile);
1245 if (*type_addr == 0)
1246 *type_addr = alloc_type (objfile);
1248 TYPE_CPLUS_SPECIFIC (*type_addr)
1249 = (struct cplus_struct_type *) &cplus_struct_default;
1253 /* Read a native enumerated type and return it in GDB internal form. */
1255 static struct type *
1256 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1257 dnttpointer hp_type;
1258 union dnttentry *dn_bufp;
1259 struct objfile *objfile;
1262 struct pending **symlist, *osyms, *syms;
1263 int o_nsyms, nsyms = 0;
1265 union dnttentry *memp;
1270 type = hpread_alloc_type (hp_type, objfile);
1271 TYPE_LENGTH (type) = 4;
1273 symlist = &file_symbols;
1275 o_nsyms = osyms ? osyms->nsyms : 0;
1277 /* Get a name for each member and add it to our list of members. */
1278 mem = dn_bufp->denum.firstmem;
1279 while (mem.dnttp.extension && mem.word != DNTTNIL)
1281 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1283 name = VT (objfile) + memp->dmember.name;
1284 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1285 sizeof (struct symbol));
1286 memset (sym, 0, sizeof (struct symbol));
1287 SYMBOL_NAME (sym) = name;
1288 SYMBOL_CLASS (sym) = LOC_CONST;
1289 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1290 SYMBOL_VALUE (sym) = memp->dmember.value;
1291 add_symbol_to_list (sym, symlist);
1293 mem = memp->dmember.nextmem;
1296 /* Now that we know more about the enum, fill in more info. */
1297 TYPE_CODE (type) = TYPE_CODE_ENUM;
1298 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1299 TYPE_NFIELDS (type) = nsyms;
1300 TYPE_FIELDS (type) = (struct field *)
1301 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1303 /* Find the symbols for the members and put them into the type.
1304 The symbols can be found in the symlist that we put them on
1305 to cause them to be defined. osyms contains the old value
1306 of that symlist; everything up to there was defined by us.
1308 Note that we preserve the order of the enum constants, so
1309 that in something like "enum {FOO, LAST_THING=FOO}" we print
1310 FOO, not LAST_THING. */
1311 for (syms = *symlist, n = 0; syms; syms = syms->next)
1316 for (; j < syms->nsyms; j++, n++)
1318 struct symbol *xsym = syms->symbol[j];
1319 SYMBOL_TYPE (xsym) = type;
1320 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1321 TYPE_FIELD_VALUE (type, n) = 0;
1322 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1323 TYPE_FIELD_BITSIZE (type, n) = 0;
1332 /* Read and internalize a native function debug symbol. */
1334 static struct type *
1335 hpread_read_function_type (hp_type, dn_bufp, objfile)
1336 dnttpointer hp_type;
1337 union dnttentry *dn_bufp;
1338 struct objfile *objfile;
1340 struct type *type, *type1;
1341 struct pending **symlist, *osyms, *syms;
1342 int o_nsyms, nsyms = 0;
1344 union dnttentry *paramp;
1349 param = dn_bufp->dfunc.firstparam;
1351 /* See if we've already read in this type. */
1352 type = hpread_alloc_type (hp_type, objfile);
1353 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1356 /* Nope, so read it in and store it away. */
1357 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1359 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1361 symlist = &local_symbols;
1363 o_nsyms = osyms ? osyms->nsyms : 0;
1365 /* Now examine each parameter noting its type, location, and a
1366 wealth of other information. */
1367 while (param.word && param.word != DNTTNIL)
1369 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1371 param = paramp->dfparam.nextparam;
1374 name = VT (objfile) + paramp->dfparam.name;
1375 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1376 sizeof (struct symbol));
1377 (void) memset (sym, 0, sizeof (struct symbol));
1378 SYMBOL_NAME (sym) = name;
1380 /* Figure out where it lives. */
1381 if (paramp->dfparam.regparam)
1382 SYMBOL_CLASS (sym) = LOC_REGPARM;
1383 else if (paramp->dfparam.indirect)
1384 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1386 SYMBOL_CLASS (sym) = LOC_ARG;
1387 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1388 if (paramp->dfparam.copyparam)
1390 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1391 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1393 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1395 /* This is likely a pass-by-invisible reference parameter,
1396 Hack on the symbol class to make GDB happy. */
1397 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1400 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1403 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1405 /* Add it to the list. */
1406 add_symbol_to_list (sym, symlist);
1409 /* Note how many parameters we found. */
1410 TYPE_NFIELDS (type) = nsyms;
1411 TYPE_FIELDS (type) = (struct field *)
1412 obstack_alloc (&objfile->type_obstack,
1413 sizeof (struct field) * nsyms);
1415 /* Find the symbols for the values and put them into the type.
1416 The symbols can be found in the symlist that we put them on
1417 to cause them to be defined. osyms contains the old value
1418 of that symlist; everything up to there was defined by us. */
1419 /* Note that we preserve the order of the parameters, so
1420 that in something like "enum {FOO, LAST_THING=FOO}" we print
1421 FOO, not LAST_THING. */
1422 for (syms = *symlist, n = 0; syms; syms = syms->next)
1427 for (; j < syms->nsyms; j++, n++)
1429 struct symbol *xsym = syms->symbol[j];
1430 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1431 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1432 TYPE_FIELD_BITPOS (type, n) = n;
1433 TYPE_FIELD_BITSIZE (type, n) = 0;
1441 /* Read in and internalize a structure definition. */
1443 static struct type *
1444 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1445 dnttpointer hp_type;
1446 union dnttentry *dn_bufp;
1447 struct objfile *objfile;
1451 struct nextfield *next;
1456 struct nextfield *list = 0;
1457 struct nextfield *new;
1460 union dnttentry *fieldp;
1462 /* Is it something we've already dealt with? */
1463 type = hpread_alloc_type (hp_type, objfile);
1464 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1465 (TYPE_CODE (type) == TYPE_CODE_UNION))
1468 /* Get the basic type correct. */
1469 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1471 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1472 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1474 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1476 TYPE_CODE (type) = TYPE_CODE_UNION;
1477 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1483 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1485 /* Read in and internalize all the fields. */
1486 field = dn_bufp->dstruct.firstfield;
1487 while (field.word != DNTTNIL && field.dnttp.extension)
1489 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1491 /* Get space to record the next field's data. */
1492 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1496 list->field.name = VT (objfile) + fieldp->dfield.name;
1497 list->field.bitpos = fieldp->dfield.bitoffset;
1498 if (fieldp->dfield.bitlength % 8)
1499 list->field.bitsize = fieldp->dfield.bitlength;
1501 list->field.bitsize = 0;
1503 field = fieldp->dfield.nextfield;
1504 list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
1507 TYPE_NFIELDS (type) = nfields;
1508 TYPE_FIELDS (type) = (struct field *)
1509 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1511 /* Copy the saved-up fields into the field vector. */
1512 for (n = nfields; list; list = list->next)
1515 TYPE_FIELD (type, n) = list->field;
1520 /* Read in and internalize a set debug symbol. */
1522 static struct type *
1523 hpread_read_set_type (hp_type, dn_bufp, objfile)
1524 dnttpointer hp_type;
1525 union dnttentry *dn_bufp;
1526 struct objfile *objfile;
1530 /* See if it's something we've already deal with. */
1531 type = hpread_alloc_type (hp_type, objfile);
1532 if (TYPE_CODE (type) == TYPE_CODE_SET)
1535 /* Nope. Fill in the appropriate fields. */
1536 TYPE_CODE (type) = TYPE_CODE_SET;
1537 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1538 TYPE_NFIELDS (type) = 0;
1539 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1544 /* Read in and internalize an array debug symbol. */
1546 static struct type *
1547 hpread_read_array_type (hp_type, dn_bufp, objfile)
1548 dnttpointer hp_type;
1549 union dnttentry *dn_bufp;
1550 struct objfile *objfile;
1553 union dnttentry save;
1556 /* Why no check here? Because it kept us from properly determining
1557 the size of the array! */
1558 type = hpread_alloc_type (hp_type, objfile);
1560 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1562 /* values are not normalized. */
1563 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1564 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1566 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1568 /* The HP debug format represents char foo[]; as an array with
1569 length 0x7fffffff. Internally GDB wants to represent this
1570 as an array of length zero. */
1571 TYPE_LENGTH (type) = 0;
1574 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1576 TYPE_NFIELDS (type) = 1;
1577 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1580 TYPE_FIELDS (type) = (struct field *)
1581 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1582 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1587 /* Read in and internalize a subrange debug symbol. */
1588 static struct type *
1589 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1590 dnttpointer hp_type;
1591 union dnttentry *dn_bufp;
1592 struct objfile *objfile;
1596 /* Is it something we've already dealt with. */
1597 type = hpread_alloc_type (hp_type, objfile);
1598 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1601 /* Nope, internalize it. */
1602 TYPE_CODE (type) = TYPE_CODE_RANGE;
1603 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1604 TYPE_NFIELDS (type) = 2;
1605 TYPE_FIELDS (type) = (struct field *) obstack_alloc
1606 (&objfile->type_obstack, 2 * sizeof (struct field));
1608 if (dn_bufp->dsubr.dyn_low)
1609 TYPE_FIELD_BITPOS (type, 0) = 0;
1611 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1613 if (dn_bufp->dsubr.dyn_high)
1614 TYPE_FIELD_BITPOS (type, 1) = -1;
1616 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1617 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1622 static struct type *
1623 hpread_type_lookup (hp_type, objfile)
1624 dnttpointer hp_type;
1625 struct objfile *objfile;
1627 union dnttentry *dn_bufp;
1629 /* First see if it's a simple builtin type. */
1630 if (hp_type.dntti.immediate)
1631 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1633 /* Not a builtin type. We'll have to read it in. */
1634 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1635 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1637 return lookup_fundamental_type (objfile, FT_VOID);
1639 switch (dn_bufp->dblock.kind)
1641 case DNTT_TYPE_SRCFILE:
1642 case DNTT_TYPE_MODULE:
1643 case DNTT_TYPE_FUNCTION:
1644 case DNTT_TYPE_ENTRY:
1645 case DNTT_TYPE_BEGIN:
1647 case DNTT_TYPE_IMPORT:
1648 case DNTT_TYPE_LABEL:
1649 case DNTT_TYPE_WITH:
1650 case DNTT_TYPE_COMMON:
1651 case DNTT_TYPE_FPARAM:
1652 case DNTT_TYPE_SVAR:
1653 case DNTT_TYPE_DVAR:
1654 case DNTT_TYPE_CONST:
1655 /* Opps. Something went very wrong. */
1656 return lookup_fundamental_type (objfile, FT_VOID);
1658 case DNTT_TYPE_TYPEDEF:
1660 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1663 suffix = VT (objfile) + dn_bufp->dtype.name;
1665 TYPE_CPLUS_SPECIFIC (structtype)
1666 = (struct cplus_struct_type *) &cplus_struct_default;
1667 TYPE_NAME (structtype) = suffix;
1671 case DNTT_TYPE_TAGDEF:
1673 /* Just a little different from above. We have to tack on
1674 an identifier of some kind (struct, union, enum, etc). */
1675 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1677 char *prefix, *suffix;
1678 suffix = VT (objfile) + dn_bufp->dtype.name;
1680 /* Lookup the next type in the list. It should be a structure,
1681 union, or enum type. We will need to attach that to our name. */
1682 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1683 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1687 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1689 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1694 /* Build the correct name. */
1696 = (char *) obstack_alloc (&objfile->type_obstack,
1697 strlen (prefix) + strlen (suffix) + 1);
1698 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1699 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1700 TYPE_TAG_NAME (structtype) = suffix;
1702 TYPE_CPLUS_SPECIFIC (structtype)
1703 = (struct cplus_struct_type *) &cplus_struct_default;
1707 case DNTT_TYPE_POINTER:
1708 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1710 case DNTT_TYPE_ENUM:
1711 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1712 case DNTT_TYPE_MEMENUM:
1713 return lookup_fundamental_type (objfile, FT_VOID);
1715 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1716 case DNTT_TYPE_SUBRANGE:
1717 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1718 case DNTT_TYPE_ARRAY:
1719 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1720 case DNTT_TYPE_STRUCT:
1721 case DNTT_TYPE_UNION:
1722 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1723 case DNTT_TYPE_FIELD:
1724 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1725 case DNTT_TYPE_VARIANT:
1726 case DNTT_TYPE_FILE:
1727 return lookup_fundamental_type (objfile, FT_VOID);
1728 case DNTT_TYPE_FUNCTYPE:
1729 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1731 case DNTT_TYPE_COBSTRUCT:
1732 case DNTT_TYPE_XREF:
1734 case DNTT_TYPE_MACRO:
1736 return lookup_fundamental_type (objfile, FT_VOID);
1741 hpread_record_lines (subfile, s_idx, e_idx, objfile)
1742 struct subfile *subfile;
1743 sltpointer s_idx, e_idx;
1744 struct objfile *objfile;
1746 union sltentry *sl_bufp;
1748 while (s_idx <= e_idx)
1750 sl_bufp = hpread_get_slt (s_idx, objfile);
1751 /* Only record "normal" entries in the SLT. */
1752 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1753 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1754 record_line (subfile, sl_bufp->snorm.line, sl_bufp->snorm.address);
1760 /* Internalize one native debug symbol. */
1763 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1764 text_offset, text_size, filename, index)
1765 union dnttentry *dn_bufp;
1767 struct section_offsets *section_offsets;
1768 struct objfile *objfile;
1769 CORE_ADDR text_offset;
1777 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1778 union dnttentry *dn_temp;
1779 dnttpointer hp_type;
1781 struct context_stack *new;
1783 /* Allocate one GDB debug symbol and fill in some default values. */
1784 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1785 sizeof (struct symbol));
1786 memset (sym, 0, sizeof (struct symbol));
1787 SYMBOL_NAME (sym) = name;
1788 SYMBOL_LANGUAGE (sym) = language_auto;
1789 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1790 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1791 SYMBOL_LINE (sym) = 0;
1792 SYMBOL_VALUE (sym) = 0;
1793 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1795 hp_type.dnttp.extension = 1;
1796 hp_type.dnttp.immediate = 0;
1797 hp_type.dnttp.global = 0;
1798 hp_type.dnttp.index = index;
1800 type = dn_bufp->dblock.kind;
1804 case DNTT_TYPE_SRCFILE:
1805 /* This type of symbol indicates from which source file or include file
1806 the following data comes. If there are no modules it also may
1807 indicate the start of a new source file, in which case we must
1808 finish the symbol table of the previous source file
1809 (if any) and start accumulating a new symbol table. */
1811 valu = text_offset + offset; /* Relocate for dynamic loading */
1812 if (!last_source_file)
1813 start_symtab (name, NULL, valu);
1815 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1817 dn_bufp->dsfile.address,
1819 start_subfile (name, NULL);
1822 case DNTT_TYPE_MODULE:
1823 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1826 case DNTT_TYPE_FUNCTION:
1827 case DNTT_TYPE_ENTRY:
1828 /* A function or secondary entry point. */
1829 valu = dn_bufp->dfunc.lowaddr + offset;
1830 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1832 dn_bufp->dfunc.address,
1835 WITHIN_FUNCTION (objfile) = 1;
1836 CURRENT_FUNCTION_VALUE (objfile) = valu;
1838 /* Stack must be empty now. */
1839 if (context_stack_depth != 0)
1840 complain (&lbrac_unmatched_complaint, (char *) symnum);
1841 new = push_context (0, valu);
1843 SYMBOL_CLASS (sym) = LOC_BLOCK;
1844 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1845 if (dn_bufp->dfunc.global)
1846 add_symbol_to_list (sym, &global_symbols);
1848 add_symbol_to_list (sym, &file_symbols);
1851 /* Search forward to the next scope beginning. */
1852 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1854 dn_bufp = hpread_get_lntt (++index, objfile);
1855 if (dn_bufp->dblock.extension)
1858 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1860 dn_bufp->dbegin.address,
1862 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1863 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1866 case DNTT_TYPE_BEGIN:
1867 /* Begin a new scope. */
1868 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1870 dn_bufp->dbegin.address,
1872 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1873 valu += offset; /* Relocate for dynamic loading */
1874 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1875 new = push_context (desc, valu);
1880 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1882 dn_bufp->dend.address + 1,
1884 switch (dn_bufp->dend.endkind)
1886 case DNTT_TYPE_MODULE:
1887 /* Ending a module ends the symbol table for that module. */
1888 valu = text_offset + text_size + offset;
1889 (void) end_symtab (valu, 0, 0, objfile, 0);
1892 case DNTT_TYPE_FUNCTION:
1893 /* Ending a function, well, ends the function's scope. */
1894 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1896 valu = dn_temp->dfunc.hiaddr + offset;
1897 new = pop_context ();
1898 /* Make a block for the local symbols within. */
1899 finish_block (new->name, &local_symbols, new->old_blocks,
1900 new->start_addr, valu, objfile);
1901 WITHIN_FUNCTION (objfile) = 0;
1903 case DNTT_TYPE_BEGIN:
1904 /* Just ending a local scope. */
1905 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1906 /* Why in the hell is this needed? */
1907 valu += offset + 9; /* Relocate for dynamic loading */
1908 new = pop_context ();
1909 desc = dn_bufp->dend.beginscope.dnttp.index;
1910 if (desc != new->depth)
1911 complain (&lbrac_mismatch_complaint, (char *) symnum);
1912 /* Make a block for the local symbols within. */
1913 finish_block (new->name, &local_symbols, new->old_blocks,
1914 new->start_addr, valu, objfile);
1915 local_symbols = new->locals;
1919 case DNTT_TYPE_LABEL:
1920 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1922 case DNTT_TYPE_FPARAM:
1923 /* Function parameters. */
1924 if (dn_bufp->dfparam.regparam)
1925 SYMBOL_CLASS (sym) = LOC_REGISTER;
1927 SYMBOL_CLASS (sym) = LOC_LOCAL;
1928 if (dn_bufp->dfparam.copyparam)
1930 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1931 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1933 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1937 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1938 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1939 add_symbol_to_list (sym, &local_symbols);
1941 case DNTT_TYPE_SVAR:
1942 /* Static variables. */
1943 SYMBOL_CLASS (sym) = LOC_STATIC;
1944 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1945 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1946 if (dn_bufp->dsvar.global)
1947 add_symbol_to_list (sym, &global_symbols);
1948 else if (WITHIN_FUNCTION (objfile))
1949 add_symbol_to_list (sym, &local_symbols);
1951 add_symbol_to_list (sym, &file_symbols);
1953 case DNTT_TYPE_DVAR:
1954 /* Dynamic variables. */
1955 if (dn_bufp->ddvar.regvar)
1956 SYMBOL_CLASS (sym) = LOC_REGISTER;
1958 SYMBOL_CLASS (sym) = LOC_LOCAL;
1959 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1960 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1962 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1964 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1965 if (dn_bufp->ddvar.global)
1966 add_symbol_to_list (sym, &global_symbols);
1967 else if (WITHIN_FUNCTION (objfile))
1968 add_symbol_to_list (sym, &local_symbols);
1970 add_symbol_to_list (sym, &file_symbols);
1972 case DNTT_TYPE_CONST:
1973 /* A constant (pascal?). */
1974 SYMBOL_CLASS (sym) = LOC_CONST;
1975 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1976 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1977 if (dn_bufp->dconst.global)
1978 add_symbol_to_list (sym, &global_symbols);
1979 else if (WITHIN_FUNCTION (objfile))
1980 add_symbol_to_list (sym, &local_symbols);
1982 add_symbol_to_list (sym, &file_symbols);
1984 case DNTT_TYPE_TYPEDEF:
1985 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1986 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1987 if (dn_bufp->dtype.global)
1988 add_symbol_to_list (sym, &global_symbols);
1989 else if (WITHIN_FUNCTION (objfile))
1990 add_symbol_to_list (sym, &local_symbols);
1992 add_symbol_to_list (sym, &file_symbols);
1994 case DNTT_TYPE_TAGDEF:
1995 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1996 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1997 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1998 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
1999 if (dn_bufp->dtype.global)
2000 add_symbol_to_list (sym, &global_symbols);
2001 else if (WITHIN_FUNCTION (objfile))
2002 add_symbol_to_list (sym, &local_symbols);
2004 add_symbol_to_list (sym, &file_symbols);
2006 case DNTT_TYPE_POINTER:
2007 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2008 (dn_bufp->dptr.pointsto,
2010 add_symbol_to_list (sym, &file_symbols);
2012 case DNTT_TYPE_ENUM:
2013 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2014 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2015 add_symbol_to_list (sym, &file_symbols);
2017 case DNTT_TYPE_MEMENUM:
2020 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2021 add_symbol_to_list (sym, &file_symbols);
2023 case DNTT_TYPE_SUBRANGE:
2024 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2026 add_symbol_to_list (sym, &file_symbols);
2028 case DNTT_TYPE_ARRAY:
2029 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2030 add_symbol_to_list (sym, &file_symbols);
2032 case DNTT_TYPE_STRUCT:
2033 case DNTT_TYPE_UNION:
2034 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2035 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2036 add_symbol_to_list (sym, &file_symbols);