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, Boston, MA 02111-1307, USA.
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
25 #include "gdb_string.h"
26 #include "hp-symtab.h"
32 #include "complaints.h"
33 #include "gdb-stabs.h"
37 /* Private information attached to an objfile which we use to find
38 and internalize the HP C debug symbols within that objfile. */
40 struct hpread_symfile_info
42 /* The contents of each of the debug sections (there are 4 of them). */
48 /* We keep the size of the $VT$ section for range checking. */
51 /* Some routines still need to know the number of symbols in the
52 main debug sections ($LNTT$ and $GNTT$). */
53 unsigned int lntt_symcount;
54 unsigned int gntt_symcount;
56 /* To keep track of all the types we've processed. */
57 struct type **type_vector;
58 int type_vector_length;
60 /* Keeps track of the beginning of a range of source lines. */
63 /* Some state variables we'll need. */
66 /* Keep track of the current function's address. We may need to look
67 up something based on this address. */
68 unsigned int current_function_value;
71 /* Accessor macros to get at the fields. */
72 #define HPUX_SYMFILE_INFO(o) \
73 ((struct hpread_symfile_info *)((o)->sym_private))
74 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
75 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
76 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
77 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
78 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
79 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
80 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
81 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
82 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
83 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
84 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
85 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
87 /* Given the native debug symbol SYM, set NAMEP to the name associated
88 with the debug symbol. Note we may be called with a debug symbol which
89 has no associated name, in that case we return an empty string.
91 Also note we "know" that the name for any symbol is always in the
92 same place. Hence we don't have to conditionalize on the symbol type. */
93 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
94 if (! hpread_has_name ((SYM)->dblock.kind)) \
96 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
98 complain (&string_table_offset_complaint, (char *) symnum); \
102 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
104 /* We put a pointer to this structure in the read_symtab_private field
109 /* The offset within the file symbol table of first local symbol for
114 /* Length (in bytes) of the section of the symbol table devoted to
115 this file's symbols (actually, the section bracketed may contain
116 more than just this file's symbols). If ldsymlen is 0, the only
117 reason for this thing's existence is the dependency list.
118 Nothing else will happen when it is read in. */
123 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
124 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
125 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
127 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
128 /* Nonzero means give verbose info on gdb action. */
129 extern int info_verbose;
131 /* Complaints about the symbols we have encountered. */
132 extern struct complaint string_table_offset_complaint;
133 extern struct complaint lbrac_unmatched_complaint;
134 extern struct complaint lbrac_mismatch_complaint;
137 void hpread_symfile_init PARAMS ((struct objfile *));
140 hpread_read_array_type PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
142 static struct type *hpread_alloc_type
143 PARAMS ((dnttpointer, struct objfile *));
145 static struct type **hpread_lookup_type
146 PARAMS ((dnttpointer, struct objfile *));
148 static struct type *hpread_read_enum_type
149 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
151 static struct type *hpread_read_set_type
152 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
154 static struct type *hpread_read_subrange_type
155 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
157 static struct type *hpread_read_struct_type
158 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
160 void hpread_build_psymtabs
161 PARAMS ((struct objfile *, struct section_offsets *, int));
163 void hpread_symfile_finish PARAMS ((struct objfile *));
165 static struct partial_symtab *hpread_start_psymtab
166 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
167 struct partial_symbol **, struct partial_symbol **));
169 static struct partial_symtab *hpread_end_psymtab
170 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
171 struct partial_symtab **, int));
173 static struct symtab *hpread_expand_symtab
174 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
175 struct section_offsets *, char *));
177 static void hpread_process_one_debug_symbol
178 PARAMS ((union dnttentry *, char *, struct section_offsets *,
179 struct objfile *, CORE_ADDR, int, char *, int));
181 static sltpointer hpread_record_lines
182 PARAMS ((struct subfile *, sltpointer, sltpointer,
183 struct objfile *, CORE_ADDR));
185 static struct type *hpread_read_function_type
186 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
188 static struct type * hpread_type_lookup
189 PARAMS ((dnttpointer, struct objfile *));
191 static unsigned long hpread_get_depth
192 PARAMS ((sltpointer, struct objfile *));
194 static unsigned long hpread_get_line
195 PARAMS ((sltpointer, struct objfile *));
197 static CORE_ADDR hpread_get_location
198 PARAMS ((sltpointer, struct objfile *));
200 static int hpread_type_translate PARAMS ((dnttpointer));
201 static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
202 static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
203 static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
204 static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
205 static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
206 static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
207 static int hpread_has_name PARAMS ((enum dntt_entry_type));
210 /* Initialization for reading native HP C debug symbols from OBJFILE.
212 It's only purpose in life is to set up the symbol reader's private
213 per-objfile data structures, and read in the raw contents of the debug
214 sections (attaching pointers to the debug info into the private data
217 Since BFD doesn't know how to read debug symbols in a format-independent
218 way (and may never do so...), we have to do it ourselves. Note we may
219 be called on a file without native HP C debugging symbols.
220 FIXME, there should be a cleaner peephole into the BFD environment here. */
223 hpread_symfile_init (objfile)
224 struct objfile *objfile;
226 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
228 /* Allocate struct to keep track of the symfile */
229 objfile->sym_private = (PTR)
230 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
231 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
233 /* We haven't read in any types yet. */
234 TYPE_VECTOR (objfile) = 0;
236 /* Read in data from the $GNTT$ subspace. */
237 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
242 = obstack_alloc (&objfile->symbol_obstack,
243 bfd_section_size (objfile->obfd, gntt_section));
245 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
246 0, bfd_section_size (objfile->obfd, gntt_section));
248 GNTT_SYMCOUNT (objfile)
249 = bfd_section_size (objfile->obfd, gntt_section)
250 / sizeof (struct dntt_type_block);
252 /* Read in data from the $LNTT$ subspace. Also keep track of the number
254 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
259 = obstack_alloc (&objfile->symbol_obstack,
260 bfd_section_size (objfile->obfd, lntt_section));
262 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
263 0, bfd_section_size (objfile->obfd, lntt_section));
265 LNTT_SYMCOUNT (objfile)
266 = bfd_section_size (objfile->obfd, lntt_section)
267 / sizeof (struct dntt_type_block);
269 /* Read in data from the $SLT$ subspace. $SLT$ contains information
270 on source line numbers. */
271 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
276 obstack_alloc (&objfile->symbol_obstack,
277 bfd_section_size (objfile->obfd, slt_section));
279 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
280 0, bfd_section_size (objfile->obfd, slt_section));
282 /* Read in data from the $VT$ subspace. $VT$ contains things like
283 names and constants. Keep track of the number of symbols in the VT. */
284 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
288 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
291 (char *) obstack_alloc (&objfile->symbol_obstack,
294 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
295 0, VT_SIZE (objfile));
298 /* Scan and build partial symbols for a symbol file.
300 The minimal symbol table (either SOM or HP a.out) has already been
301 read in; all we need to do is setup partial symbols based on the
302 native debugging information.
304 We assume hpread_symfile_init has been called to initialize the
305 symbol reader's private data structures.
307 SECTION_OFFSETS contains offsets relative to which the symbols in the
308 various sections are (depending where the sections were actually loaded).
309 MAINLINE is true if we are reading the main symbol
310 table (as opposed to a shared lib or dynamically loaded file). */
313 hpread_build_psymtabs (objfile, section_offsets, mainline)
314 struct objfile *objfile;
315 struct section_offsets *section_offsets;
319 int past_first_source_file = 0;
320 struct cleanup *old_chain;
322 int hp_symnum, symcount, i;
324 union dnttentry *dn_bufp;
330 /* Current partial symtab */
331 struct partial_symtab *pst;
333 /* List of current psymtab's include files */
334 char **psymtab_include_list;
335 int includes_allocated;
338 /* Index within current psymtab dependency list */
339 struct partial_symtab **dependency_list;
340 int dependencies_used, dependencies_allocated;
342 /* Just in case the stabs reader left turds lying around. */
344 make_cleanup (really_free_pendings, 0);
346 pst = (struct partial_symtab *) 0;
348 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
349 a number of problems with cross compilation and creating useless holes
350 in the stack when we have to allocate new entries. FIXME. */
352 includes_allocated = 30;
354 psymtab_include_list = (char **) alloca (includes_allocated *
357 dependencies_allocated = 30;
358 dependencies_used = 0;
360 (struct partial_symtab **) alloca (dependencies_allocated *
361 sizeof (struct partial_symtab *));
363 old_chain = make_cleanup (free_objfile, objfile);
365 last_source_file = 0;
367 /* Make two passes, one ofr the GNTT symbols, the other for the
369 for (i = 0; i < 1; i++)
371 int within_function = 0;
374 symcount = GNTT_SYMCOUNT (objfile);
376 symcount = LNTT_SYMCOUNT (objfile);
378 for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
382 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
384 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
386 if (dn_bufp->dblock.extension)
389 /* Only handle things which are necessary for minimal symbols.
390 everything else is ignored. */
391 switch (dn_bufp->dblock.kind)
393 case DNTT_TYPE_SRCFILE:
395 /* A source file of some kind. Note this may simply
396 be an included file. */
397 SET_NAMESTRING (dn_bufp, &namestring, objfile);
399 /* Check if this is the source file we are already working
401 if (pst && !strcmp (namestring, pst->filename))
404 /* Check if this is an include file, if so check if we have
405 already seen it. Add it to the include list */
406 p = strrchr (namestring, '.');
407 if (!strcmp (p, ".h"))
412 for (j = 0; j < includes_used; j++)
413 if (!strcmp (namestring, psymtab_include_list[j]))
421 /* Add it to the list of includes seen so far and
422 allocate more include space if necessary. */
423 psymtab_include_list[includes_used++] = namestring;
424 if (includes_used >= includes_allocated)
426 char **orig = psymtab_include_list;
428 psymtab_include_list = (char **)
429 alloca ((includes_allocated *= 2) *
431 memcpy ((PTR) psymtab_include_list, (PTR) orig,
432 includes_used * sizeof (char *));
442 pst->filename = (char *)
443 obstack_alloc (&pst->objfile->psymbol_obstack,
444 strlen (namestring) + 1);
445 strcpy (pst->filename, namestring);
452 /* This is a bonafide new source file.
453 End the current partial symtab and start a new one. */
455 if (pst && past_first_source_file)
457 hpread_end_psymtab (pst, psymtab_include_list,
460 * sizeof (struct dntt_type_block)),
462 dependency_list, dependencies_used);
463 pst = (struct partial_symtab *) 0;
465 dependencies_used = 0;
468 past_first_source_file = 1;
470 valu = hpread_get_textlow (i, hp_symnum, objfile);
471 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
472 pst = hpread_start_psymtab (objfile, section_offsets,
475 * sizeof (struct dntt_type_block)),
476 objfile->global_psymbols.next,
477 objfile->static_psymbols.next);
483 case DNTT_TYPE_MODULE:
484 /* A source file. It's still unclear to me what the
485 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
486 is supposed to be. */
487 SET_NAMESTRING (dn_bufp, &namestring, objfile);
488 valu = hpread_get_textlow (i, hp_symnum, objfile);
489 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
492 pst = hpread_start_psymtab (objfile, section_offsets,
495 * sizeof (struct dntt_type_block)),
496 objfile->global_psymbols.next,
497 objfile->static_psymbols.next);
502 case DNTT_TYPE_FUNCTION:
503 case DNTT_TYPE_ENTRY:
504 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
505 a secondary entry point. */
506 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
510 valu = dn_bufp->dfunc.lowaddr +
511 ANOFFSET (section_offsets, SECT_OFF_TEXT);
512 SET_NAMESTRING (dn_bufp, &namestring, objfile);
513 add_psymbol_to_list (namestring, strlen (namestring),
514 VAR_NAMESPACE, LOC_BLOCK,
515 &objfile->static_psymbols, valu,
516 0, language_unknown, objfile);
519 case DNTT_TYPE_BEGIN:
521 /* Scope block begin/end. We only care about function
522 and file blocks right now. */
523 if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
525 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
527 * sizeof (struct dntt_type_block)),
529 dependency_list, dependencies_used);
530 pst = (struct partial_symtab *) 0;
532 dependencies_used = 0;
535 if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
540 case DNTT_TYPE_TYPEDEF:
541 case DNTT_TYPE_TAGDEF:
543 /* Variables, typedefs an the like. */
544 enum address_class storage;
545 namespace_enum namespace;
547 /* Don't add locals to the partial symbol table. */
549 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
550 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
553 /* TAGDEFs go into the structure namespace. */
554 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
555 namespace = STRUCT_NAMESPACE;
557 namespace = VAR_NAMESPACE;
559 /* What kind of "storage" does this use? */
560 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
561 storage = LOC_STATIC;
562 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
563 && dn_bufp->ddvar.regvar)
564 storage = LOC_REGISTER;
565 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
570 SET_NAMESTRING (dn_bufp, &namestring, objfile);
573 pst = hpread_start_psymtab (objfile, section_offsets,
576 * sizeof (struct dntt_type_block)),
577 objfile->global_psymbols.next,
578 objfile->static_psymbols.next);
580 if (dn_bufp->dsvar.global)
582 add_psymbol_to_list (namestring, strlen (namestring),
584 &objfile->global_psymbols,
585 dn_bufp->dsvar.location,
586 0, language_unknown, objfile);
590 add_psymbol_to_list (namestring, strlen (namestring),
592 &objfile->static_psymbols,
593 dn_bufp->dsvar.location,
594 0, language_unknown, objfile);
598 case DNTT_TYPE_MEMENUM:
599 case DNTT_TYPE_CONST:
600 /* Constants and members of enumerated types. */
601 SET_NAMESTRING (dn_bufp, &namestring, objfile);
604 pst = hpread_start_psymtab (objfile, section_offsets,
607 * sizeof (struct dntt_type_block)),
608 objfile->global_psymbols.next,
609 objfile->static_psymbols.next);
611 add_psymbol_to_list (namestring, strlen (namestring),
612 VAR_NAMESPACE, LOC_CONST,
613 &objfile->static_psymbols, 0,
614 0, language_unknown, objfile);
622 /* End any pending partial symbol table. */
625 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
626 hp_symnum * sizeof (struct dntt_type_block),
627 0, dependency_list, dependencies_used);
630 discard_cleanups (old_chain);
633 /* Perform any local cleanups required when we are done with a particular
634 objfile. I.E, we are in the process of discarding all symbol information
635 for an objfile, freeing up all memory held for it, and unlinking the
636 objfile struct from the global list of known objfiles. */
639 hpread_symfile_finish (objfile)
640 struct objfile *objfile;
642 if (objfile->sym_private != NULL)
644 mfree (objfile->md, objfile->sym_private);
649 /* The remaining functions are all for internal use only. */
651 /* Various small functions to get entries in the debug symbol sections. */
653 static union dnttentry *
654 hpread_get_lntt (index, objfile)
656 struct objfile *objfile;
658 return (union dnttentry *)
659 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
662 static union dnttentry *
663 hpread_get_gntt (index, objfile)
665 struct objfile *objfile;
667 return (union dnttentry *)
668 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
671 static union sltentry *
672 hpread_get_slt (index, objfile)
674 struct objfile *objfile;
676 return (union sltentry *)&(SLT (objfile)[index * sizeof (union sltentry)]);
679 /* Get the low address associated with some symbol (typically the start
680 of a particular source file or module). Since that information is not
681 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
682 the existance of DNTT_TYPE_FUNCTION symbols. */
685 hpread_get_textlow (global, index, objfile)
688 struct objfile *objfile;
690 union dnttentry *dn_bufp;
691 struct minimal_symbol *msymbol;
693 /* Look for a DNTT_TYPE_FUNCTION symbol. */
697 dn_bufp = hpread_get_gntt (index++, objfile);
699 dn_bufp = hpread_get_lntt (index++, objfile);
700 } while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
701 && dn_bufp->dblock.kind != DNTT_TYPE_END);
703 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
704 might happen when a sourcefile has no functions. */
705 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
708 /* The minimal symbols are typically more accurate for some reason. */
709 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
712 return SYMBOL_VALUE_ADDRESS (msymbol);
714 return dn_bufp->dfunc.lowaddr;
717 /* Get the nesting depth for the source line identified by INDEX. */
720 hpread_get_depth (index, objfile)
722 struct objfile *objfile;
724 union sltentry *sl_bufp;
726 sl_bufp = hpread_get_slt (index, objfile);
727 return sl_bufp->sspec.backptr.dnttp.index;
730 /* Get the source line number the the line identified by INDEX. */
733 hpread_get_line (index, objfile)
735 struct objfile *objfile;
737 union sltentry *sl_bufp;
739 sl_bufp = hpread_get_slt (index, objfile);
740 return sl_bufp->snorm.line;
744 hpread_get_location (index, objfile)
746 struct objfile *objfile;
748 union sltentry *sl_bufp;
751 /* code location of special sltentrys is determined from context */
752 sl_bufp = hpread_get_slt (index, objfile);
754 if (sl_bufp->snorm.sltdesc == SLT_END)
756 /* find previous normal sltentry and get address */
757 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
758 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
759 sl_bufp = hpread_get_slt (index - i, objfile);
760 return sl_bufp->snorm.address;
763 /* find next normal sltentry and get address */
764 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
765 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
766 sl_bufp = hpread_get_slt (index + i, objfile);
767 return sl_bufp->snorm.address;
771 /* Return 1 if an HP debug symbol of type KIND has a name associated with
772 it, else return 0. */
775 hpread_has_name (kind)
776 enum dntt_entry_type kind;
780 case DNTT_TYPE_SRCFILE:
781 case DNTT_TYPE_MODULE:
782 case DNTT_TYPE_FUNCTION:
783 case DNTT_TYPE_ENTRY:
784 case DNTT_TYPE_IMPORT:
785 case DNTT_TYPE_LABEL:
786 case DNTT_TYPE_FPARAM:
789 case DNTT_TYPE_CONST:
790 case DNTT_TYPE_TYPEDEF:
791 case DNTT_TYPE_TAGDEF:
792 case DNTT_TYPE_MEMENUM:
793 case DNTT_TYPE_FIELD:
797 case DNTT_TYPE_BEGIN:
800 case DNTT_TYPE_COMMON:
801 case DNTT_TYPE_POINTER:
804 case DNTT_TYPE_SUBRANGE:
805 case DNTT_TYPE_ARRAY:
806 case DNTT_TYPE_STRUCT:
807 case DNTT_TYPE_UNION:
808 case DNTT_TYPE_VARIANT:
810 case DNTT_TYPE_FUNCTYPE:
811 case DNTT_TYPE_COBSTRUCT:
813 case DNTT_TYPE_MACRO:
819 /* Allocate and partially fill a partial symtab. It will be
820 completely filled at the end of the symbol list.
822 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
823 is the address relative to which its symbols are (incremental) or 0
826 static struct partial_symtab *
827 hpread_start_psymtab (objfile, section_offsets,
828 filename, textlow, ldsymoff, global_syms, static_syms)
829 struct objfile *objfile;
830 struct section_offsets *section_offsets;
834 struct partial_symbol **global_syms;
835 struct partial_symbol **static_syms;
837 struct partial_symtab *result =
838 start_psymtab_common (objfile, section_offsets,
839 filename, textlow, global_syms, static_syms);
841 result->read_symtab_private = (char *)
842 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
843 LDSYMOFF (result) = ldsymoff;
844 result->read_symtab = hpread_psymtab_to_symtab;
850 /* Close off the current usage of PST.
851 Returns PST or NULL if the partial symtab was empty and thrown away.
853 FIXME: List variables and peculiarities of same. */
855 static struct partial_symtab *
856 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
857 capping_text, dependency_list, number_dependencies)
858 struct partial_symtab *pst;
861 int capping_symbol_offset;
862 CORE_ADDR capping_text;
863 struct partial_symtab **dependency_list;
864 int number_dependencies;
867 struct objfile *objfile = pst -> objfile;
869 if (capping_symbol_offset != -1)
870 LDSYMLEN(pst) = capping_symbol_offset - LDSYMOFF(pst);
871 pst->texthigh = capping_text;
874 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
876 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
878 pst->number_of_dependencies = number_dependencies;
879 if (number_dependencies)
881 pst->dependencies = (struct partial_symtab **)
882 obstack_alloc (&objfile->psymbol_obstack,
883 number_dependencies * sizeof (struct partial_symtab *));
884 memcpy (pst->dependencies, dependency_list,
885 number_dependencies * sizeof (struct partial_symtab *));
888 pst->dependencies = 0;
890 for (i = 0; i < num_includes; i++)
892 struct partial_symtab *subpst =
893 allocate_psymtab (include_list[i], objfile);
895 subpst->section_offsets = pst->section_offsets;
896 subpst->read_symtab_private =
897 (char *) obstack_alloc (&objfile->psymbol_obstack,
898 sizeof (struct symloc));
902 subpst->texthigh = 0;
904 /* We could save slight bits of space by only making one of these,
905 shared by the entire set of include files. FIXME-someday. */
906 subpst->dependencies = (struct partial_symtab **)
907 obstack_alloc (&objfile->psymbol_obstack,
908 sizeof (struct partial_symtab *));
909 subpst->dependencies[0] = pst;
910 subpst->number_of_dependencies = 1;
912 subpst->globals_offset =
913 subpst->n_global_syms =
914 subpst->statics_offset =
915 subpst->n_static_syms = 0;
919 subpst->read_symtab = pst->read_symtab;
922 sort_pst_symbols (pst);
924 /* If there is already a psymtab or symtab for a file of this name, remove it.
925 (If there is a symtab, more drastic things also happen.)
926 This happens in VxWorks. */
927 free_named_symtabs (pst->filename);
929 if (num_includes == 0
930 && number_dependencies == 0
931 && pst->n_global_syms == 0
932 && pst->n_static_syms == 0)
934 /* Throw away this psymtab, it's empty. We can't deallocate it, since
935 it is on the obstack, but we can forget to chain it on the list. */
936 /* Empty psymtabs happen as a result of header files which don't have
937 any symbols in them. There can be a lot of them. But this check
938 is wrong, in that a psymtab with N_SLINE entries but nothing else
939 is not empty, but we don't realize that. Fixing that without slowing
940 things down might be tricky. */
941 struct partial_symtab *prev_pst;
943 /* First, snip it out of the psymtab chain */
945 if (pst->objfile->psymtabs == pst)
946 pst->objfile->psymtabs = pst->next;
948 for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
949 if (prev_pst->next == pst)
950 prev_pst->next = pst->next;
952 /* Next, put it on a free list for recycling */
954 pst->next = pst->objfile->free_psymtabs;
955 pst->objfile->free_psymtabs = pst;
957 /* Indicate that psymtab was thrown away. */
958 pst = (struct partial_symtab *)NULL;
963 /* Do the dirty work of reading in the full symbol from a partial symbol
967 hpread_psymtab_to_symtab_1 (pst)
968 struct partial_symtab *pst;
970 struct cleanup *old_chain;
973 /* Get out quick if passed junk. */
977 /* Complain if we've already read in this symbol table. */
980 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
985 /* Read in all partial symtabs on which this one is dependent */
986 for (i = 0; i < pst->number_of_dependencies; i++)
987 if (!pst->dependencies[i]->readin)
989 /* Inform about additional files that need to be read in. */
992 fputs_filtered (" ", stdout);
994 fputs_filtered ("and ", stdout);
996 printf_filtered ("%s...", pst->dependencies[i]->filename);
997 wrap_here (""); /* Flush output */
1000 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
1003 /* If it's real... */
1006 /* Init stuff necessary for reading in symbols */
1008 old_chain = make_cleanup (really_free_pendings, 0);
1011 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
1012 pst->textlow, pst->texthigh - pst->textlow,
1013 pst->section_offsets, pst->filename);
1014 sort_symtab_syms (pst->symtab);
1016 do_cleanups (old_chain);
1022 /* Read in all of the symbols for a given psymtab for real.
1023 Be verbose about it if the user wants that. */
1026 hpread_psymtab_to_symtab (pst)
1027 struct partial_symtab *pst;
1029 /* Get out quick if given junk. */
1036 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
1041 if (LDSYMLEN (pst) || pst->number_of_dependencies)
1043 /* Print the message now, before reading the string table,
1044 to avoid disconcerting pauses. */
1047 printf_filtered ("Reading in symbols for %s...", pst->filename);
1051 hpread_psymtab_to_symtab_1 (pst);
1053 /* Match with global symbols. This only needs to be done once,
1054 after all of the symtabs and dependencies have been read in. */
1055 scan_file_globals (pst->objfile);
1057 /* Finish up the debug error message. */
1059 printf_filtered ("done.\n");
1062 /* Read in a defined section of a specific object file's symbols.
1064 DESC is the file descriptor for the file, positioned at the
1065 beginning of the symtab
1066 SYM_OFFSET is the offset within the file of
1067 the beginning of the symbols we want to read
1068 SYM_SIZE is the size of the symbol info to read in.
1069 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1070 TEXT_SIZE is the size of the text segment read in.
1071 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1073 static struct symtab *
1074 hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1075 section_offsets, filename)
1076 struct objfile *objfile;
1079 CORE_ADDR text_offset;
1081 struct section_offsets *section_offsets;
1085 union dnttentry *dn_bufp;
1086 unsigned max_symnum;
1088 int sym_index = sym_offset / sizeof (struct dntt_type_block);
1090 current_objfile = objfile;
1093 last_source_file = 0;
1095 dn_bufp = hpread_get_lntt (sym_index, objfile);
1096 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1097 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1098 start_symtab ("globals", NULL, 0);
1100 max_symnum = sym_size / sizeof (struct dntt_type_block);
1102 /* Read in and process each debug symbol within the specified range. */
1104 symnum < max_symnum;
1107 QUIT; /* Allow this to be interruptable */
1108 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1110 if (dn_bufp->dblock.extension)
1113 /* Yow! We call SET_NAMESTRING on things without names! */
1114 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1116 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1117 objfile, text_offset, text_size,
1118 filename, symnum + sym_index);
1121 current_objfile = NULL;
1123 return end_symtab (text_offset + text_size, objfile, 0);
1127 /* Convert basic types from HP debug format into GDB internal format. */
1130 hpread_type_translate (typep)
1133 if (!typep.dntti.immediate)
1136 switch (typep.dntti.type)
1138 case HP_TYPE_BOOLEAN:
1139 case HP_TYPE_BOOLEAN_S300_COMPAT:
1140 case HP_TYPE_BOOLEAN_VAX_COMPAT:
1142 /* Ugh. No way to distinguish between signed and unsigned chars. */
1144 case HP_TYPE_WIDE_CHAR:
1147 if (typep.dntti.bitlength <= 8)
1149 if (typep.dntti.bitlength <= 16)
1151 if (typep.dntti.bitlength <= 32)
1153 return FT_LONG_LONG;
1156 case HP_TYPE_UNSIGNED_LONG:
1157 if (typep.dntti.bitlength <= 8)
1158 return FT_UNSIGNED_CHAR;
1159 if (typep.dntti.bitlength <= 16)
1160 return FT_UNSIGNED_SHORT;
1161 if (typep.dntti.bitlength <= 32)
1162 return FT_UNSIGNED_LONG;
1163 return FT_UNSIGNED_LONG_LONG;
1164 case HP_TYPE_UNSIGNED_INT:
1165 if (typep.dntti.bitlength <= 8)
1166 return FT_UNSIGNED_CHAR;
1167 if (typep.dntti.bitlength <= 16)
1168 return FT_UNSIGNED_SHORT;
1169 if (typep.dntti.bitlength <= 32)
1170 return FT_UNSIGNED_INTEGER;
1171 return FT_UNSIGNED_LONG_LONG;
1173 case HP_TYPE_REAL_3000:
1174 case HP_TYPE_DOUBLE:
1175 if (typep.dntti.bitlength == 64)
1176 return FT_DBL_PREC_FLOAT;
1177 if (typep.dntti.bitlength == 128)
1178 return FT_EXT_PREC_FLOAT;
1180 case HP_TYPE_COMPLEX:
1181 case HP_TYPE_COMPLEXS3000:
1182 if (typep.dntti.bitlength == 128)
1183 return FT_DBL_PREC_COMPLEX;
1184 if (typep.dntti.bitlength == 192)
1185 return FT_EXT_PREC_COMPLEX;
1187 case HP_TYPE_STRING200:
1188 case HP_TYPE_LONGSTRING200:
1189 case HP_TYPE_FTN_STRING_SPEC:
1190 case HP_TYPE_MOD_STRING_SPEC:
1191 case HP_TYPE_MOD_STRING_3000:
1192 case HP_TYPE_FTN_STRING_S300_COMPAT:
1193 case HP_TYPE_FTN_STRING_VAX_COMPAT:
1200 /* Return the type associated with the index found in HP_TYPE. */
1202 static struct type **
1203 hpread_lookup_type (hp_type, objfile)
1204 dnttpointer hp_type;
1205 struct objfile *objfile;
1208 int index = hp_type.dnttp.index;
1210 if (hp_type.dntti.immediate)
1213 if (index < LNTT_SYMCOUNT (objfile))
1215 if (index >= TYPE_VECTOR_LENGTH (objfile))
1217 old_len = TYPE_VECTOR_LENGTH (objfile);
1220 TYPE_VECTOR_LENGTH (objfile) = 100;
1221 TYPE_VECTOR (objfile) = (struct type **)
1222 xmmalloc (objfile -> md,
1223 TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1225 while (index >= TYPE_VECTOR_LENGTH (objfile))
1226 TYPE_VECTOR_LENGTH (objfile) *= 2;
1227 TYPE_VECTOR (objfile) = (struct type **)
1228 xmrealloc (objfile -> md,
1229 (char *) TYPE_VECTOR (objfile),
1230 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1231 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1232 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1233 sizeof (struct type *));
1235 return &TYPE_VECTOR (objfile)[index];
1241 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1242 Note we'll just return the address of a GDB internal type if we already
1243 have it lying around. */
1245 static struct type *
1246 hpread_alloc_type (hp_type, objfile)
1247 dnttpointer hp_type;
1248 struct objfile *objfile;
1250 struct type **type_addr;
1252 type_addr = hpread_lookup_type (hp_type, objfile);
1253 if (*type_addr == 0)
1254 *type_addr = alloc_type (objfile);
1256 TYPE_CPLUS_SPECIFIC (*type_addr)
1257 = (struct cplus_struct_type *) &cplus_struct_default;
1261 /* Read a native enumerated type and return it in GDB internal form. */
1263 static struct type *
1264 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1265 dnttpointer hp_type;
1266 union dnttentry *dn_bufp;
1267 struct objfile *objfile;
1270 struct pending **symlist, *osyms, *syms;
1271 int o_nsyms, nsyms = 0;
1273 union dnttentry *memp;
1278 type = hpread_alloc_type (hp_type, objfile);
1279 TYPE_LENGTH (type) = 4;
1281 symlist = &file_symbols;
1283 o_nsyms = osyms ? osyms->nsyms : 0;
1285 /* Get a name for each member and add it to our list of members. */
1286 mem = dn_bufp->denum.firstmem;
1287 while (mem.dnttp.extension && mem.word != DNTTNIL)
1289 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1291 name = VT (objfile) + memp->dmember.name;
1292 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1293 sizeof (struct symbol));
1294 memset (sym, 0, sizeof (struct symbol));
1295 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1296 &objfile->symbol_obstack);
1297 SYMBOL_CLASS (sym) = LOC_CONST;
1298 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1299 SYMBOL_VALUE (sym) = memp->dmember.value;
1300 add_symbol_to_list (sym, symlist);
1302 mem = memp->dmember.nextmem;
1305 /* Now that we know more about the enum, fill in more info. */
1306 TYPE_CODE (type) = TYPE_CODE_ENUM;
1307 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1308 TYPE_NFIELDS (type) = nsyms;
1309 TYPE_FIELDS (type) = (struct field *)
1310 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1312 /* Find the symbols for the members and put them into the type.
1313 The symbols can be found in the symlist that we put them on
1314 to cause them to be defined. osyms contains the old value
1315 of that symlist; everything up to there was defined by us.
1317 Note that we preserve the order of the enum constants, so
1318 that in something like "enum {FOO, LAST_THING=FOO}" we print
1319 FOO, not LAST_THING. */
1320 for (syms = *symlist, n = 0; syms; syms = syms->next)
1325 for (; j < syms->nsyms; j++, n++)
1327 struct symbol *xsym = syms->symbol[j];
1328 SYMBOL_TYPE (xsym) = type;
1329 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1330 TYPE_FIELD_VALUE (type, n) = 0;
1331 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1332 TYPE_FIELD_BITSIZE (type, n) = 0;
1341 /* Read and internalize a native function debug symbol. */
1343 static struct type *
1344 hpread_read_function_type (hp_type, dn_bufp, objfile)
1345 dnttpointer hp_type;
1346 union dnttentry *dn_bufp;
1347 struct objfile *objfile;
1349 struct type *type, *type1;
1350 struct pending **symlist, *osyms, *syms;
1351 int o_nsyms, nsyms = 0;
1353 union dnttentry *paramp;
1358 param = dn_bufp->dfunc.firstparam;
1360 /* See if we've already read in this type. */
1361 type = hpread_alloc_type (hp_type, objfile);
1362 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1365 /* Nope, so read it in and store it away. */
1366 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1368 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1370 symlist = &local_symbols;
1372 o_nsyms = osyms ? osyms->nsyms : 0;
1374 /* Now examine each parameter noting its type, location, and a
1375 wealth of other information. */
1376 while (param.word && param.word != DNTTNIL)
1378 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1380 param = paramp->dfparam.nextparam;
1383 name = VT (objfile) + paramp->dfparam.name;
1384 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1385 sizeof (struct symbol));
1386 (void) memset (sym, 0, sizeof (struct symbol));
1387 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1388 &objfile->symbol_obstack);
1390 /* Figure out where it lives. */
1391 if (paramp->dfparam.regparam)
1392 SYMBOL_CLASS (sym) = LOC_REGPARM;
1393 else if (paramp->dfparam.indirect)
1394 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1396 SYMBOL_CLASS (sym) = LOC_ARG;
1397 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1398 if (paramp->dfparam.copyparam)
1400 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1401 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1403 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1405 /* This is likely a pass-by-invisible reference parameter,
1406 Hack on the symbol class to make GDB happy. */
1407 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1410 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1413 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1415 /* Add it to the list. */
1416 add_symbol_to_list (sym, symlist);
1419 /* Note how many parameters we found. */
1420 TYPE_NFIELDS (type) = nsyms;
1421 TYPE_FIELDS (type) = (struct field *)
1422 obstack_alloc (&objfile->type_obstack,
1423 sizeof (struct field) * nsyms);
1425 /* Find the symbols for the values and put them into the type.
1426 The symbols can be found in the symlist that we put them on
1427 to cause them to be defined. osyms contains the old value
1428 of that symlist; everything up to there was defined by us. */
1429 /* Note that we preserve the order of the parameters, so
1430 that in something like "enum {FOO, LAST_THING=FOO}" we print
1431 FOO, not LAST_THING. */
1432 for (syms = *symlist, n = 0; syms; syms = syms->next)
1437 for (; j < syms->nsyms; j++, n++)
1439 struct symbol *xsym = syms->symbol[j];
1440 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1441 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1442 TYPE_FIELD_BITPOS (type, n) = n;
1443 TYPE_FIELD_BITSIZE (type, n) = 0;
1451 /* Read in and internalize a structure definition. */
1453 static struct type *
1454 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1455 dnttpointer hp_type;
1456 union dnttentry *dn_bufp;
1457 struct objfile *objfile;
1461 struct nextfield *next;
1466 struct nextfield *list = 0;
1467 struct nextfield *new;
1470 union dnttentry *fieldp;
1472 /* Is it something we've already dealt with? */
1473 type = hpread_alloc_type (hp_type, objfile);
1474 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1475 (TYPE_CODE (type) == TYPE_CODE_UNION))
1478 /* Get the basic type correct. */
1479 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1481 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1482 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1484 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1486 TYPE_CODE (type) = TYPE_CODE_UNION;
1487 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1493 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1495 /* Read in and internalize all the fields. */
1496 field = dn_bufp->dstruct.firstfield;
1497 while (field.word != DNTTNIL && field.dnttp.extension)
1499 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1501 /* Get space to record the next field's data. */
1502 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1506 list->field.name = VT (objfile) + fieldp->dfield.name;
1507 list->field.bitpos = fieldp->dfield.bitoffset;
1508 if (fieldp->dfield.bitlength % 8)
1509 list->field.bitsize = fieldp->dfield.bitlength;
1511 list->field.bitsize = 0;
1513 field = fieldp->dfield.nextfield;
1514 list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
1517 TYPE_NFIELDS (type) = nfields;
1518 TYPE_FIELDS (type) = (struct field *)
1519 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1521 /* Copy the saved-up fields into the field vector. */
1522 for (n = nfields; list; list = list->next)
1525 TYPE_FIELD (type, n) = list->field;
1530 /* Read in and internalize a set debug symbol. */
1532 static struct type *
1533 hpread_read_set_type (hp_type, dn_bufp, objfile)
1534 dnttpointer hp_type;
1535 union dnttentry *dn_bufp;
1536 struct objfile *objfile;
1540 /* See if it's something we've already deal with. */
1541 type = hpread_alloc_type (hp_type, objfile);
1542 if (TYPE_CODE (type) == TYPE_CODE_SET)
1545 /* Nope. Fill in the appropriate fields. */
1546 TYPE_CODE (type) = TYPE_CODE_SET;
1547 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1548 TYPE_NFIELDS (type) = 0;
1549 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1554 /* Read in and internalize an array debug symbol. */
1556 static struct type *
1557 hpread_read_array_type (hp_type, dn_bufp, objfile)
1558 dnttpointer hp_type;
1559 union dnttentry *dn_bufp;
1560 struct objfile *objfile;
1563 union dnttentry save;
1566 /* Why no check here? Because it kept us from properly determining
1567 the size of the array! */
1568 type = hpread_alloc_type (hp_type, objfile);
1570 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1572 /* values are not normalized. */
1573 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1574 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1576 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1578 /* The HP debug format represents char foo[]; as an array with
1579 length 0x7fffffff. Internally GDB wants to represent this
1580 as an array of length zero. */
1581 TYPE_LENGTH (type) = 0;
1584 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1586 TYPE_NFIELDS (type) = 1;
1587 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1590 TYPE_FIELDS (type) = (struct field *)
1591 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1592 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1597 /* Read in and internalize a subrange debug symbol. */
1598 static struct type *
1599 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1600 dnttpointer hp_type;
1601 union dnttentry *dn_bufp;
1602 struct objfile *objfile;
1606 /* Is it something we've already dealt with. */
1607 type = hpread_alloc_type (hp_type, objfile);
1608 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1611 /* Nope, internalize it. */
1612 TYPE_CODE (type) = TYPE_CODE_RANGE;
1613 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1614 TYPE_NFIELDS (type) = 2;
1616 = (struct field *) obstack_alloc (&objfile->type_obstack,
1617 2 * sizeof (struct field));
1619 if (dn_bufp->dsubr.dyn_low)
1620 TYPE_FIELD_BITPOS (type, 0) = 0;
1622 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1624 if (dn_bufp->dsubr.dyn_high)
1625 TYPE_FIELD_BITPOS (type, 1) = -1;
1627 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1628 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1633 static struct type *
1634 hpread_type_lookup (hp_type, objfile)
1635 dnttpointer hp_type;
1636 struct objfile *objfile;
1638 union dnttentry *dn_bufp;
1640 /* First see if it's a simple builtin type. */
1641 if (hp_type.dntti.immediate)
1642 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1644 /* Not a builtin type. We'll have to read it in. */
1645 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1646 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1648 return lookup_fundamental_type (objfile, FT_VOID);
1650 switch (dn_bufp->dblock.kind)
1652 case DNTT_TYPE_SRCFILE:
1653 case DNTT_TYPE_MODULE:
1654 case DNTT_TYPE_FUNCTION:
1655 case DNTT_TYPE_ENTRY:
1656 case DNTT_TYPE_BEGIN:
1658 case DNTT_TYPE_IMPORT:
1659 case DNTT_TYPE_LABEL:
1660 case DNTT_TYPE_WITH:
1661 case DNTT_TYPE_COMMON:
1662 case DNTT_TYPE_FPARAM:
1663 case DNTT_TYPE_SVAR:
1664 case DNTT_TYPE_DVAR:
1665 case DNTT_TYPE_CONST:
1666 /* Opps. Something went very wrong. */
1667 return lookup_fundamental_type (objfile, FT_VOID);
1669 case DNTT_TYPE_TYPEDEF:
1671 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1674 suffix = VT (objfile) + dn_bufp->dtype.name;
1676 TYPE_CPLUS_SPECIFIC (structtype)
1677 = (struct cplus_struct_type *) &cplus_struct_default;
1678 TYPE_NAME (structtype) = suffix;
1682 case DNTT_TYPE_TAGDEF:
1684 /* Just a little different from above. We have to tack on
1685 an identifier of some kind (struct, union, enum, etc). */
1686 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1688 char *prefix, *suffix;
1689 suffix = VT (objfile) + dn_bufp->dtype.name;
1691 /* Lookup the next type in the list. It should be a structure,
1692 union, or enum type. We will need to attach that to our name. */
1693 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1694 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1698 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1700 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1705 /* Build the correct name. */
1707 = (char *) obstack_alloc (&objfile->type_obstack,
1708 strlen (prefix) + strlen (suffix) + 1);
1709 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1710 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1711 TYPE_TAG_NAME (structtype) = suffix;
1713 TYPE_CPLUS_SPECIFIC (structtype)
1714 = (struct cplus_struct_type *) &cplus_struct_default;
1718 case DNTT_TYPE_POINTER:
1719 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1721 case DNTT_TYPE_ENUM:
1722 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1723 case DNTT_TYPE_MEMENUM:
1724 return lookup_fundamental_type (objfile, FT_VOID);
1726 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1727 case DNTT_TYPE_SUBRANGE:
1728 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1729 case DNTT_TYPE_ARRAY:
1730 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1731 case DNTT_TYPE_STRUCT:
1732 case DNTT_TYPE_UNION:
1733 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1734 case DNTT_TYPE_FIELD:
1735 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1736 case DNTT_TYPE_VARIANT:
1737 case DNTT_TYPE_FILE:
1738 return lookup_fundamental_type (objfile, FT_VOID);
1739 case DNTT_TYPE_FUNCTYPE:
1740 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1742 case DNTT_TYPE_COBSTRUCT:
1743 case DNTT_TYPE_XREF:
1745 case DNTT_TYPE_MACRO:
1747 return lookup_fundamental_type (objfile, FT_VOID);
1752 hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1753 struct subfile *subfile;
1754 sltpointer s_idx, e_idx;
1755 struct objfile *objfile;
1758 union sltentry *sl_bufp;
1760 while (s_idx <= e_idx)
1762 sl_bufp = hpread_get_slt (s_idx, objfile);
1763 /* Only record "normal" entries in the SLT. */
1764 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1765 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1766 record_line (subfile, sl_bufp->snorm.line,
1767 sl_bufp->snorm.address + offset);
1773 /* Internalize one native debug symbol. */
1776 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1777 text_offset, text_size, filename, index)
1778 union dnttentry *dn_bufp;
1780 struct section_offsets *section_offsets;
1781 struct objfile *objfile;
1782 CORE_ADDR text_offset;
1790 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1791 union dnttentry *dn_temp;
1792 dnttpointer hp_type;
1794 struct context_stack *new;
1796 /* Allocate one GDB debug symbol and fill in some default values. */
1797 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1798 sizeof (struct symbol));
1799 memset (sym, 0, sizeof (struct symbol));
1800 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1801 SYMBOL_LANGUAGE (sym) = language_auto;
1802 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1803 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1804 SYMBOL_LINE (sym) = 0;
1805 SYMBOL_VALUE (sym) = 0;
1806 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1808 hp_type.dnttp.extension = 1;
1809 hp_type.dnttp.immediate = 0;
1810 hp_type.dnttp.global = 0;
1811 hp_type.dnttp.index = index;
1813 type = dn_bufp->dblock.kind;
1817 case DNTT_TYPE_SRCFILE:
1818 /* This type of symbol indicates from which source file or include file
1819 the following data comes. If there are no modules it also may
1820 indicate the start of a new source file, in which case we must
1821 finish the symbol table of the previous source file
1822 (if any) and start accumulating a new symbol table. */
1825 if (!last_source_file)
1827 start_symtab (name, NULL, valu);
1828 SL_INDEX (objfile) = dn_bufp->dsfile.address;
1832 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1834 dn_bufp->dsfile.address,
1837 start_subfile (name, NULL);
1840 case DNTT_TYPE_MODULE:
1841 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1844 case DNTT_TYPE_FUNCTION:
1845 case DNTT_TYPE_ENTRY:
1846 /* A function or secondary entry point. */
1847 valu = dn_bufp->dfunc.lowaddr + offset;
1848 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1850 dn_bufp->dfunc.address,
1853 WITHIN_FUNCTION (objfile) = 1;
1854 CURRENT_FUNCTION_VALUE (objfile) = valu;
1856 /* Stack must be empty now. */
1857 if (context_stack_depth != 0)
1858 complain (&lbrac_unmatched_complaint, (char *) symnum);
1859 new = push_context (0, valu);
1861 SYMBOL_CLASS (sym) = LOC_BLOCK;
1862 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1863 if (dn_bufp->dfunc.global)
1864 add_symbol_to_list (sym, &global_symbols);
1866 add_symbol_to_list (sym, &file_symbols);
1869 /* Search forward to the next scope beginning. */
1870 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1872 dn_bufp = hpread_get_lntt (++index, objfile);
1873 if (dn_bufp->dblock.extension)
1876 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1878 dn_bufp->dbegin.address,
1880 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1881 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1884 case DNTT_TYPE_BEGIN:
1885 /* Begin a new scope. */
1886 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1888 dn_bufp->dbegin.address,
1890 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1891 valu += offset; /* Relocate for dynamic loading */
1892 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1893 new = push_context (desc, valu);
1898 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1900 dn_bufp->dend.address + 1,
1902 switch (dn_bufp->dend.endkind)
1904 case DNTT_TYPE_MODULE:
1905 /* Ending a module ends the symbol table for that module. */
1906 valu = text_offset + text_size + offset;
1907 (void) end_symtab (valu, objfile, 0);
1910 case DNTT_TYPE_FUNCTION:
1911 /* Ending a function, well, ends the function's scope. */
1912 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1914 valu = dn_temp->dfunc.hiaddr + offset;
1915 new = pop_context ();
1916 /* Make a block for the local symbols within. */
1917 finish_block (new->name, &local_symbols, new->old_blocks,
1918 new->start_addr, valu, objfile);
1919 WITHIN_FUNCTION (objfile) = 0;
1921 case DNTT_TYPE_BEGIN:
1922 /* Just ending a local scope. */
1923 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1924 /* Why in the hell is this needed? */
1925 valu += offset + 9; /* Relocate for dynamic loading */
1926 new = pop_context ();
1927 desc = dn_bufp->dend.beginscope.dnttp.index;
1928 if (desc != new->depth)
1929 complain (&lbrac_mismatch_complaint, (char *) symnum);
1930 /* Make a block for the local symbols within. */
1931 finish_block (new->name, &local_symbols, new->old_blocks,
1932 new->start_addr, valu, objfile);
1933 local_symbols = new->locals;
1937 case DNTT_TYPE_LABEL:
1938 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1940 case DNTT_TYPE_FPARAM:
1941 /* Function parameters. */
1942 if (dn_bufp->dfparam.regparam)
1943 SYMBOL_CLASS (sym) = LOC_REGISTER;
1945 SYMBOL_CLASS (sym) = LOC_LOCAL;
1946 if (dn_bufp->dfparam.copyparam)
1948 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1949 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1951 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1955 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1956 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1957 add_symbol_to_list (sym, &local_symbols);
1959 case DNTT_TYPE_SVAR:
1960 /* Static variables. */
1961 SYMBOL_CLASS (sym) = LOC_STATIC;
1962 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1963 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1964 if (dn_bufp->dsvar.global)
1965 add_symbol_to_list (sym, &global_symbols);
1966 else if (WITHIN_FUNCTION (objfile))
1967 add_symbol_to_list (sym, &local_symbols);
1969 add_symbol_to_list (sym, &file_symbols);
1971 case DNTT_TYPE_DVAR:
1972 /* Dynamic variables. */
1973 if (dn_bufp->ddvar.regvar)
1974 SYMBOL_CLASS (sym) = LOC_REGISTER;
1976 SYMBOL_CLASS (sym) = LOC_LOCAL;
1977 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1978 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1980 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1982 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1983 if (dn_bufp->ddvar.global)
1984 add_symbol_to_list (sym, &global_symbols);
1985 else if (WITHIN_FUNCTION (objfile))
1986 add_symbol_to_list (sym, &local_symbols);
1988 add_symbol_to_list (sym, &file_symbols);
1990 case DNTT_TYPE_CONST:
1991 /* A constant (pascal?). */
1992 SYMBOL_CLASS (sym) = LOC_CONST;
1993 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1994 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1995 if (dn_bufp->dconst.global)
1996 add_symbol_to_list (sym, &global_symbols);
1997 else if (WITHIN_FUNCTION (objfile))
1998 add_symbol_to_list (sym, &local_symbols);
2000 add_symbol_to_list (sym, &file_symbols);
2002 case DNTT_TYPE_TYPEDEF:
2003 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2004 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2005 if (dn_bufp->dtype.global)
2006 add_symbol_to_list (sym, &global_symbols);
2007 else if (WITHIN_FUNCTION (objfile))
2008 add_symbol_to_list (sym, &local_symbols);
2010 add_symbol_to_list (sym, &file_symbols);
2012 case DNTT_TYPE_TAGDEF:
2013 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2014 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2015 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2016 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2017 if (dn_bufp->dtype.global)
2018 add_symbol_to_list (sym, &global_symbols);
2019 else if (WITHIN_FUNCTION (objfile))
2020 add_symbol_to_list (sym, &local_symbols);
2022 add_symbol_to_list (sym, &file_symbols);
2024 case DNTT_TYPE_POINTER:
2025 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2026 (dn_bufp->dptr.pointsto,
2028 add_symbol_to_list (sym, &file_symbols);
2030 case DNTT_TYPE_ENUM:
2031 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2032 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2033 add_symbol_to_list (sym, &file_symbols);
2035 case DNTT_TYPE_MEMENUM:
2038 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2039 add_symbol_to_list (sym, &file_symbols);
2041 case DNTT_TYPE_SUBRANGE:
2042 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2044 add_symbol_to_list (sym, &file_symbols);
2046 case DNTT_TYPE_ARRAY:
2047 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2048 add_symbol_to_list (sym, &file_symbols);
2050 case DNTT_TYPE_STRUCT:
2051 case DNTT_TYPE_UNION:
2052 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2053 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2054 add_symbol_to_list (sym, &file_symbols);