Change defn of LOCAL_LABEL_PREFIX to ""
[external/binutils.git] / gdb / hpread.c
1 /* Read hp debug symbols and convert to internal format, for GDB.
2    Copyright 1993, 1996 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
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.
10
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.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.
20
21    Written by the Center for Software Science at the University of Utah
22    and by Cygnus Support.  */
23
24 #include "defs.h"
25 #include "bfd.h"
26 #include "gdb_string.h"
27 #include "hp-symtab.h"
28 #include "syms.h"
29 #include "symtab.h"
30 #include "symfile.h"
31 #include "objfiles.h"
32 #include "buildsym.h"
33 #include "complaints.h"
34 #include "gdb-stabs.h"
35 #include "gdbtypes.h"
36 #include "demangle.h"
37
38 /* Private information attached to an objfile which we use to find
39    and internalize the HP C debug symbols within that objfile.  */
40
41 struct hpread_symfile_info
42   {
43     /* The contents of each of the debug sections (there are 4 of them).  */
44     char *gntt;
45     char *lntt;
46     char *slt;
47     char *vt;
48
49     /* We keep the size of the $VT$ section for range checking.  */
50     unsigned int vt_size;
51
52     /* Some routines still need to know the number of symbols in the
53        main debug sections ($LNTT$ and $GNTT$). */
54     unsigned int lntt_symcount;
55     unsigned int gntt_symcount;
56
57     /* To keep track of all the types we've processed.  */
58     struct type **type_vector;
59     int type_vector_length;
60
61     /* Keeps track of the beginning of a range of source lines.  */
62     sltpointer sl_index;
63
64     /* Some state variables we'll need.  */
65     int within_function;
66
67     /* Keep track of the current function's address.  We may need to look
68        up something based on this address.  */
69     unsigned int current_function_value;
70   };
71
72 /* Accessor macros to get at the fields.  */
73 #define HPUX_SYMFILE_INFO(o) \
74   ((struct hpread_symfile_info *)((o)->sym_private))
75 #define GNTT(o)                 (HPUX_SYMFILE_INFO(o)->gntt)
76 #define LNTT(o)                 (HPUX_SYMFILE_INFO(o)->lntt)
77 #define SLT(o)                  (HPUX_SYMFILE_INFO(o)->slt)
78 #define VT(o)                   (HPUX_SYMFILE_INFO(o)->vt)
79 #define VT_SIZE(o)              (HPUX_SYMFILE_INFO(o)->vt_size)
80 #define LNTT_SYMCOUNT(o)        (HPUX_SYMFILE_INFO(o)->lntt_symcount)
81 #define GNTT_SYMCOUNT(o)        (HPUX_SYMFILE_INFO(o)->gntt_symcount)
82 #define TYPE_VECTOR(o)          (HPUX_SYMFILE_INFO(o)->type_vector)
83 #define TYPE_VECTOR_LENGTH(o)   (HPUX_SYMFILE_INFO(o)->type_vector_length)
84 #define SL_INDEX(o)             (HPUX_SYMFILE_INFO(o)->sl_index)
85 #define WITHIN_FUNCTION(o)      (HPUX_SYMFILE_INFO(o)->within_function)
86 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
87
88 /* Given the native debug symbol SYM, set NAMEP to the name associated
89    with the debug symbol.  Note we may be called with a debug symbol which
90    has no associated name, in that case we return an empty string.
91
92    Also note we "know" that the name for any symbol is always in the
93    same place.  Hence we don't have to conditionalize on the symbol type.  */
94 #define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
95   if (! hpread_has_name ((SYM)->dblock.kind)) \
96     *NAMEP = ""; \
97   else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
98     { \
99       complain (&string_table_offset_complaint, (char *) symnum); \
100       *NAMEP = ""; \
101     } \
102   else \
103     *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
104 \f
105 /* We put a pointer to this structure in the read_symtab_private field
106    of the psymtab.  */
107
108 struct symloc
109   {
110     /* The offset within the file symbol table of first local symbol for
111        this file.  */
112
113     int ldsymoff;
114
115     /* Length (in bytes) of the section of the symbol table devoted to
116        this file's symbols (actually, the section bracketed may contain
117        more than just this file's symbols).  If ldsymlen is 0, the only
118        reason for this thing's existence is the dependency list.
119        Nothing else will happen when it is read in.  */
120
121     int ldsymlen;
122   };
123
124 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
125 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
126 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
127 \f
128 /* FIXME: Shouldn't this stuff be in a .h file somewhere?  */
129 /* Nonzero means give verbose info on gdb action.  */
130 extern int info_verbose;
131
132 /* Complaints about the symbols we have encountered.  */
133 extern struct complaint string_table_offset_complaint;
134 extern struct complaint lbrac_unmatched_complaint;
135 extern struct complaint lbrac_mismatch_complaint;
136 \f
137
138 void hpread_symfile_init (struct objfile *);
139
140 static struct type *hpread_read_array_type (dnttpointer, union dnttentry *,
141                                             struct objfile *);
142
143 static struct type *hpread_alloc_type (dnttpointer, struct objfile *);
144
145 static struct type **hpread_lookup_type (dnttpointer, struct objfile *);
146
147 static struct type *hpread_read_enum_type
148   (dnttpointer, union dnttentry *, struct objfile *);
149
150 static struct type *hpread_read_set_type
151   (dnttpointer, union dnttentry *, struct objfile *);
152
153 static struct type *hpread_read_subrange_type
154   (dnttpointer, union dnttentry *, struct objfile *);
155
156 static struct type *hpread_read_struct_type
157   (dnttpointer, union dnttentry *, struct objfile *);
158
159 void hpread_build_psymtabs (struct objfile *, int);
160
161 void hpread_symfile_finish (struct objfile *);
162
163 static struct partial_symtab *hpread_start_psymtab
164   (struct objfile *, char *, CORE_ADDR, int,
165    struct partial_symbol **, struct partial_symbol **);
166
167 static struct partial_symtab *hpread_end_psymtab
168   (struct partial_symtab *, char **, int, int, CORE_ADDR,
169    struct partial_symtab **, int);
170
171 static struct symtab *hpread_expand_symtab
172   (struct objfile *, int, int, CORE_ADDR, int,
173    struct section_offsets *, char *);
174
175 static void hpread_process_one_debug_symbol
176   (union dnttentry *, char *, struct section_offsets *,
177    struct objfile *, CORE_ADDR, int, char *, int);
178
179 static sltpointer hpread_record_lines
180   (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR);
181
182 static struct type *hpread_read_function_type
183   (dnttpointer, union dnttentry *, struct objfile *);
184
185 static struct type *hpread_type_lookup (dnttpointer, struct objfile *);
186
187 static unsigned long hpread_get_depth (sltpointer, struct objfile *);
188
189 static unsigned long hpread_get_line (sltpointer, struct objfile *);
190
191 static CORE_ADDR hpread_get_location (sltpointer, struct objfile *);
192
193 static int hpread_type_translate (dnttpointer);
194 static unsigned long hpread_get_textlow (int, int, struct objfile *);
195 static union dnttentry *hpread_get_gntt (int, struct objfile *);
196 static union dnttentry *hpread_get_lntt (int, struct objfile *);
197 static union sltentry *hpread_get_slt (int, struct objfile *);
198 static void hpread_psymtab_to_symtab (struct partial_symtab *);
199 static void hpread_psymtab_to_symtab_1 (struct partial_symtab *);
200 static int hpread_has_name (enum dntt_entry_type);
201 \f
202
203 /* Initialization for reading native HP C debug symbols from OBJFILE.
204
205    It's only purpose in life is to set up the symbol reader's private
206    per-objfile data structures, and read in the raw contents of the debug
207    sections (attaching pointers to the debug info into the private data
208    structures).
209
210    Since BFD doesn't know how to read debug symbols in a format-independent
211    way (and may never do so...), we have to do it ourselves.  Note we may
212    be called on a file without native HP C debugging symbols.
213    FIXME, there should be a cleaner peephole into the BFD environment here.  */
214
215 void
216 hpread_symfile_init (struct objfile *objfile)
217 {
218   asection *vt_section, *slt_section, *lntt_section, *gntt_section;
219
220   /* Allocate struct to keep track of the symfile */
221   objfile->sym_private = (PTR)
222     xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
223   memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
224
225   /* We haven't read in any types yet.  */
226   TYPE_VECTOR (objfile) = 0;
227
228   /* Read in data from the $GNTT$ subspace.  */
229   gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
230   if (!gntt_section)
231     return;
232
233   GNTT (objfile)
234     = obstack_alloc (&objfile->symbol_obstack,
235                      bfd_section_size (objfile->obfd, gntt_section));
236
237   bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
238                          0, bfd_section_size (objfile->obfd, gntt_section));
239
240   GNTT_SYMCOUNT (objfile)
241     = bfd_section_size (objfile->obfd, gntt_section)
242     / sizeof (struct dntt_type_block);
243
244   /* Read in data from the $LNTT$ subspace.   Also keep track of the number
245      of LNTT symbols.  */
246   lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
247   if (!lntt_section)
248     return;
249
250   LNTT (objfile)
251     = obstack_alloc (&objfile->symbol_obstack,
252                      bfd_section_size (objfile->obfd, lntt_section));
253
254   bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
255                          0, bfd_section_size (objfile->obfd, lntt_section));
256
257   LNTT_SYMCOUNT (objfile)
258     = bfd_section_size (objfile->obfd, lntt_section)
259     / sizeof (struct dntt_type_block);
260
261   /* Read in data from the $SLT$ subspace.  $SLT$ contains information
262      on source line numbers.  */
263   slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
264   if (!slt_section)
265     return;
266
267   SLT (objfile) =
268     obstack_alloc (&objfile->symbol_obstack,
269                    bfd_section_size (objfile->obfd, slt_section));
270
271   bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
272                           0, bfd_section_size (objfile->obfd, slt_section));
273
274   /* Read in data from the $VT$ subspace.  $VT$ contains things like
275      names and constants.  Keep track of the number of symbols in the VT.  */
276   vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
277   if (!vt_section)
278     return;
279
280   VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
281
282   VT (objfile) =
283     (char *) obstack_alloc (&objfile->symbol_obstack,
284                             VT_SIZE (objfile));
285
286   bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
287                             0, VT_SIZE (objfile));
288 }
289
290 /* Scan and build partial symbols for a symbol file.
291
292    The minimal symbol table (either SOM or HP a.out) has already been
293    read in; all we need to do is setup partial symbols based on the
294    native debugging information.
295
296    We assume hpread_symfile_init has been called to initialize the
297    symbol reader's private data structures.
298
299    MAINLINE is true if we are reading the main symbol
300    table (as opposed to a shared lib or dynamically loaded file).  */
301
302 void
303 hpread_build_psymtabs (struct objfile *objfile, int mainline)
304 {
305   char *namestring;
306   int past_first_source_file = 0;
307   struct cleanup *old_chain;
308
309   int hp_symnum, symcount, i;
310
311   union dnttentry *dn_bufp;
312   unsigned long valu;
313   char *p;
314   int texthigh = 0;
315   int have_name = 0;
316
317   /* Current partial symtab */
318   struct partial_symtab *pst;
319
320   /* List of current psymtab's include files */
321   char **psymtab_include_list;
322   int includes_allocated;
323   int includes_used;
324
325   /* Index within current psymtab dependency list */
326   struct partial_symtab **dependency_list;
327   int dependencies_used, dependencies_allocated;
328
329   /* Just in case the stabs reader left turds lying around.  */
330   free_pending_blocks ();
331   make_cleanup (really_free_pendings, 0);
332
333   pst = (struct partial_symtab *) 0;
334
335   /* We shouldn't use alloca, instead use malloc/free.  Doing so avoids
336      a number of problems with cross compilation and creating useless holes
337      in the stack when we have to allocate new entries.  FIXME.  */
338
339   includes_allocated = 30;
340   includes_used = 0;
341   psymtab_include_list = (char **) alloca (includes_allocated *
342                                            sizeof (char *));
343
344   dependencies_allocated = 30;
345   dependencies_used = 0;
346   dependency_list =
347     (struct partial_symtab **) alloca (dependencies_allocated *
348                                        sizeof (struct partial_symtab *));
349
350   old_chain = make_cleanup_free_objfile (objfile);
351
352   last_source_file = 0;
353
354   /* Make two passes, one ofr the GNTT symbols, the other for the
355      LNTT symbols.  */
356   for (i = 0; i < 1; i++)
357     {
358       int within_function = 0;
359
360       if (i)
361         symcount = GNTT_SYMCOUNT (objfile);
362       else
363         symcount = LNTT_SYMCOUNT (objfile);
364
365       for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
366         {
367           QUIT;
368           if (i)
369             dn_bufp = hpread_get_gntt (hp_symnum, objfile);
370           else
371             dn_bufp = hpread_get_lntt (hp_symnum, objfile);
372
373           if (dn_bufp->dblock.extension)
374             continue;
375
376           /* Only handle things which are necessary for minimal symbols.
377              everything else is ignored.  */
378           switch (dn_bufp->dblock.kind)
379             {
380             case DNTT_TYPE_SRCFILE:
381               {
382                 /* A source file of some kind.  Note this may simply
383                    be an included file.  */
384                 SET_NAMESTRING (dn_bufp, &namestring, objfile);
385
386                 /* Check if this is the source file we are already working
387                    with.  */
388                 if (pst && !strcmp (namestring, pst->filename))
389                   continue;
390
391                 /* Check if this is an include file, if so check if we have
392                    already seen it.  Add it to the include list */
393                 p = strrchr (namestring, '.');
394                 if (!strcmp (p, ".h"))
395                   {
396                     int j, found;
397
398                     found = 0;
399                     for (j = 0; j < includes_used; j++)
400                       if (!strcmp (namestring, psymtab_include_list[j]))
401                         {
402                           found = 1;
403                           break;
404                         }
405                     if (found)
406                       continue;
407
408                     /* Add it to the list of includes seen so far and
409                        allocate more include space if necessary.  */
410                     psymtab_include_list[includes_used++] = namestring;
411                     if (includes_used >= includes_allocated)
412                       {
413                         char **orig = psymtab_include_list;
414
415                         psymtab_include_list = (char **)
416                           alloca ((includes_allocated *= 2) *
417                                   sizeof (char *));
418                         memcpy ((PTR) psymtab_include_list, (PTR) orig,
419                                 includes_used * sizeof (char *));
420                       }
421                     continue;
422                   }
423
424
425                 if (pst)
426                   {
427                     if (!have_name)
428                       {
429                         pst->filename = (char *)
430                           obstack_alloc (&pst->objfile->psymbol_obstack,
431                                          strlen (namestring) + 1);
432                         strcpy (pst->filename, namestring);
433                         have_name = 1;
434                         continue;
435                       }
436                     continue;
437                   }
438
439                 /* This is a bonafide new source file.
440                    End the current partial symtab and start a new one.  */
441
442                 if (pst && past_first_source_file)
443                   {
444                     hpread_end_psymtab (pst, psymtab_include_list,
445                                         includes_used,
446                                         (hp_symnum
447                                          * sizeof (struct dntt_type_block)),
448                                         texthigh,
449                                         dependency_list, dependencies_used);
450                     pst = (struct partial_symtab *) 0;
451                     includes_used = 0;
452                     dependencies_used = 0;
453                   }
454                 else
455                   past_first_source_file = 1;
456
457                 valu = hpread_get_textlow (i, hp_symnum, objfile);
458                 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
459                 pst = hpread_start_psymtab (objfile,
460                                             namestring, valu,
461                                             (hp_symnum
462                                          * sizeof (struct dntt_type_block)),
463                                             objfile->global_psymbols.next,
464                                             objfile->static_psymbols.next);
465                 texthigh = valu;
466                 have_name = 1;
467                 continue;
468               }
469
470             case DNTT_TYPE_MODULE:
471               /* A source file.  It's still unclear to me what the
472                  real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
473                  is supposed to be.  */
474               SET_NAMESTRING (dn_bufp, &namestring, objfile);
475               valu = hpread_get_textlow (i, hp_symnum, objfile);
476               valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
477               if (!pst)
478                 {
479                   pst = hpread_start_psymtab (objfile,
480                                               namestring, valu,
481                                               (hp_symnum
482                                          * sizeof (struct dntt_type_block)),
483                                               objfile->global_psymbols.next,
484                                               objfile->static_psymbols.next);
485                   texthigh = valu;
486                   have_name = 0;
487                 }
488               continue;
489             case DNTT_TYPE_FUNCTION:
490             case DNTT_TYPE_ENTRY:
491               /* The beginning of a function.  DNTT_TYPE_ENTRY may also denote
492                  a secondary entry point.  */
493               valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
494                                                        SECT_OFF_TEXT (objfile));
495               if (valu > texthigh)
496                 texthigh = valu;
497               valu = dn_bufp->dfunc.lowaddr +
498                 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
499               SET_NAMESTRING (dn_bufp, &namestring, objfile);
500               add_psymbol_to_list (namestring, strlen (namestring),
501                                    VAR_NAMESPACE, LOC_BLOCK,
502                                    &objfile->static_psymbols, valu,
503                                    0, language_unknown, objfile);
504               within_function = 1;
505               continue;
506             case DNTT_TYPE_BEGIN:
507             case DNTT_TYPE_END:
508               /* Scope block begin/end.  We only care about function
509                  and file blocks right now.  */
510               if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
511                 {
512                   hpread_end_psymtab (pst, psymtab_include_list, includes_used,
513                                       (hp_symnum
514                                        * sizeof (struct dntt_type_block)),
515                                       texthigh,
516                                       dependency_list, dependencies_used);
517                   pst = (struct partial_symtab *) 0;
518                   includes_used = 0;
519                   dependencies_used = 0;
520                   have_name = 0;
521                 }
522               if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
523                 within_function = 0;
524               continue;
525             case DNTT_TYPE_SVAR:
526             case DNTT_TYPE_DVAR:
527             case DNTT_TYPE_TYPEDEF:
528             case DNTT_TYPE_TAGDEF:
529               {
530                 /* Variables, typedefs an the like.  */
531                 enum address_class storage;
532                 namespace_enum namespace;
533
534                 /* Don't add locals to the partial symbol table.  */
535                 if (within_function
536                     && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
537                         || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
538                   continue;
539
540                 /* TAGDEFs go into the structure namespace.  */
541                 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
542                   namespace = STRUCT_NAMESPACE;
543                 else
544                   namespace = VAR_NAMESPACE;
545
546                 /* What kind of "storage" does this use?  */
547                 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
548                   storage = LOC_STATIC;
549                 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
550                          && dn_bufp->ddvar.regvar)
551                   storage = LOC_REGISTER;
552                 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
553                   storage = LOC_LOCAL;
554                 else
555                   storage = LOC_UNDEF;
556
557                 SET_NAMESTRING (dn_bufp, &namestring, objfile);
558                 if (!pst)
559                   {
560                     pst = hpread_start_psymtab (objfile,
561                                                 "globals", 0,
562                                                 (hp_symnum
563                                          * sizeof (struct dntt_type_block)),
564                                               objfile->global_psymbols.next,
565                                              objfile->static_psymbols.next);
566                   }
567                 if (dn_bufp->dsvar.global)
568                   {
569                     add_psymbol_to_list (namestring, strlen (namestring),
570                                          namespace, storage,
571                                          &objfile->global_psymbols,
572                                          dn_bufp->dsvar.location,
573                                          0, language_unknown, objfile);
574                   }
575                 else
576                   {
577                     add_psymbol_to_list (namestring, strlen (namestring),
578                                          namespace, storage,
579                                          &objfile->static_psymbols,
580                                          dn_bufp->dsvar.location,
581                                          0, language_unknown, objfile);
582                   }
583                 continue;
584               }
585             case DNTT_TYPE_MEMENUM:
586             case DNTT_TYPE_CONST:
587               /* Constants and members of enumerated types.  */
588               SET_NAMESTRING (dn_bufp, &namestring, objfile);
589               if (!pst)
590                 {
591                   pst = hpread_start_psymtab (objfile,
592                                               "globals", 0,
593                                               (hp_symnum
594                                          * sizeof (struct dntt_type_block)),
595                                               objfile->global_psymbols.next,
596                                               objfile->static_psymbols.next);
597                 }
598               add_psymbol_to_list (namestring, strlen (namestring),
599                                    VAR_NAMESPACE, LOC_CONST,
600                                    &objfile->static_psymbols, 0,
601                                    0, language_unknown, objfile);
602               continue;
603             default:
604               continue;
605             }
606         }
607     }
608
609   /* End any pending partial symbol table.  */
610   if (pst)
611     {
612       hpread_end_psymtab (pst, psymtab_include_list, includes_used,
613                           hp_symnum * sizeof (struct dntt_type_block),
614                           0, dependency_list, dependencies_used);
615     }
616
617   discard_cleanups (old_chain);
618 }
619
620 /* Perform any local cleanups required when we are done with a particular
621    objfile.  I.E, we are in the process of discarding all symbol information
622    for an objfile, freeing up all memory held for it, and unlinking the
623    objfile struct from the global list of known objfiles. */
624
625 void
626 hpread_symfile_finish (struct objfile *objfile)
627 {
628   if (objfile->sym_private != NULL)
629     {
630       mfree (objfile->md, objfile->sym_private);
631     }
632 }
633 \f
634
635 /* The remaining functions are all for internal use only.  */
636
637 /* Various small functions to get entries in the debug symbol sections.  */
638
639 static union dnttentry *
640 hpread_get_lntt (int index, struct objfile *objfile)
641 {
642   return (union dnttentry *)
643     &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
644 }
645
646 static union dnttentry *
647 hpread_get_gntt (int index, struct objfile *objfile)
648 {
649   return (union dnttentry *)
650     &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
651 }
652
653 static union sltentry *
654 hpread_get_slt (int index, struct objfile *objfile)
655 {
656   return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
657 }
658
659 /* Get the low address associated with some symbol (typically the start
660    of a particular source file or module).  Since that information is not
661    stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
662    must infer it from the existence of DNTT_TYPE_FUNCTION symbols.  */
663
664 static unsigned long
665 hpread_get_textlow (int global, int index, struct objfile *objfile)
666 {
667   union dnttentry *dn_bufp;
668   struct minimal_symbol *msymbol;
669
670   /* Look for a DNTT_TYPE_FUNCTION symbol.  */
671   do
672     {
673       if (global)
674         dn_bufp = hpread_get_gntt (index++, objfile);
675       else
676         dn_bufp = hpread_get_lntt (index++, objfile);
677     }
678   while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
679          && dn_bufp->dblock.kind != DNTT_TYPE_END);
680
681   /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION.  This
682      might happen when a sourcefile has no functions.  */
683   if (dn_bufp->dblock.kind == DNTT_TYPE_END)
684     return 0;
685
686   /* The minimal symbols are typically more accurate for some reason.  */
687   msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
688                                    objfile);
689   if (msymbol)
690     return SYMBOL_VALUE_ADDRESS (msymbol);
691   else
692     return dn_bufp->dfunc.lowaddr;
693 }
694
695 /* Get the nesting depth for the source line identified by INDEX.  */
696
697 static unsigned long
698 hpread_get_depth (sltpointer index, struct objfile *objfile)
699 {
700   union sltentry *sl_bufp;
701
702   sl_bufp = hpread_get_slt (index, objfile);
703   return sl_bufp->sspec.backptr.dnttp.index;
704 }
705
706 /* Get the source line number the the line identified by INDEX.  */
707
708 static unsigned long
709 hpread_get_line (sltpointer index, struct objfile *objfile)
710 {
711   union sltentry *sl_bufp;
712
713   sl_bufp = hpread_get_slt (index, objfile);
714   return sl_bufp->snorm.line;
715 }
716
717 static CORE_ADDR
718 hpread_get_location (sltpointer index, struct objfile *objfile)
719 {
720   union sltentry *sl_bufp;
721   int i;
722
723   /* code location of special sltentrys is determined from context */
724   sl_bufp = hpread_get_slt (index, objfile);
725
726   if (sl_bufp->snorm.sltdesc == SLT_END)
727     {
728       /* find previous normal sltentry and get address */
729       for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
730                    (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
731         sl_bufp = hpread_get_slt (index - i, objfile);
732       return sl_bufp->snorm.address;
733     }
734
735   /* find next normal sltentry and get address */
736   for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
737                (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
738     sl_bufp = hpread_get_slt (index + i, objfile);
739   return sl_bufp->snorm.address;
740 }
741 \f
742
743 /* Return 1 if an HP debug symbol of type KIND has a name associated with
744    it, else return 0.  */
745
746 static int
747 hpread_has_name (enum dntt_entry_type kind)
748 {
749   switch (kind)
750     {
751     case DNTT_TYPE_SRCFILE:
752     case DNTT_TYPE_MODULE:
753     case DNTT_TYPE_FUNCTION:
754     case DNTT_TYPE_ENTRY:
755     case DNTT_TYPE_IMPORT:
756     case DNTT_TYPE_LABEL:
757     case DNTT_TYPE_FPARAM:
758     case DNTT_TYPE_SVAR:
759     case DNTT_TYPE_DVAR:
760     case DNTT_TYPE_CONST:
761     case DNTT_TYPE_TYPEDEF:
762     case DNTT_TYPE_TAGDEF:
763     case DNTT_TYPE_MEMENUM:
764     case DNTT_TYPE_FIELD:
765     case DNTT_TYPE_SA:
766       return 1;
767
768     case DNTT_TYPE_BEGIN:
769     case DNTT_TYPE_END:
770     case DNTT_TYPE_WITH:
771     case DNTT_TYPE_COMMON:
772     case DNTT_TYPE_POINTER:
773     case DNTT_TYPE_ENUM:
774     case DNTT_TYPE_SET:
775     case DNTT_TYPE_SUBRANGE:
776     case DNTT_TYPE_ARRAY:
777     case DNTT_TYPE_STRUCT:
778     case DNTT_TYPE_UNION:
779     case DNTT_TYPE_VARIANT:
780     case DNTT_TYPE_FILE:
781     case DNTT_TYPE_FUNCTYPE:
782     case DNTT_TYPE_COBSTRUCT:
783     case DNTT_TYPE_XREF:
784     case DNTT_TYPE_MACRO:
785     default:
786       return 0;
787     }
788 }
789
790 /* Allocate and partially fill a partial symtab.  It will be
791    completely filled at the end of the symbol list.
792
793    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
794    is the address relative to which its symbols are (incremental) or 0
795    (normal). */
796
797 static struct partial_symtab *
798 hpread_start_psymtab (struct objfile *objfile, char *filename,
799                       CORE_ADDR textlow, int ldsymoff,
800                       struct partial_symbol **global_syms,
801                       struct partial_symbol **static_syms)
802 {
803   struct partial_symtab *result =
804   start_psymtab_common (objfile, section_offsets,
805                         filename, textlow, global_syms, static_syms);
806
807   result->read_symtab_private = (char *)
808     obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
809   LDSYMOFF (result) = ldsymoff;
810   result->read_symtab = hpread_psymtab_to_symtab;
811
812   return result;
813 }
814 \f
815
816 /* Close off the current usage of PST.  
817    Returns PST or NULL if the partial symtab was empty and thrown away.
818
819    FIXME:  List variables and peculiarities of same.  */
820
821 static struct partial_symtab *
822 hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
823                     int num_includes, int capping_symbol_offset,
824                     CORE_ADDR capping_text,
825                     struct partial_symtab **dependency_list,
826                     int number_dependencies)
827 {
828   int i;
829   struct objfile *objfile = pst->objfile;
830
831   if (capping_symbol_offset != -1)
832     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
833   pst->texthigh = capping_text;
834
835   pst->n_global_syms =
836     objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
837   pst->n_static_syms =
838     objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
839
840   pst->number_of_dependencies = number_dependencies;
841   if (number_dependencies)
842     {
843       pst->dependencies = (struct partial_symtab **)
844         obstack_alloc (&objfile->psymbol_obstack,
845                     number_dependencies * sizeof (struct partial_symtab *));
846       memcpy (pst->dependencies, dependency_list,
847               number_dependencies * sizeof (struct partial_symtab *));
848     }
849   else
850     pst->dependencies = 0;
851
852   for (i = 0; i < num_includes; i++)
853     {
854       struct partial_symtab *subpst =
855       allocate_psymtab (include_list[i], objfile);
856
857       subpst->section_offsets = pst->section_offsets;
858       subpst->read_symtab_private =
859         (char *) obstack_alloc (&objfile->psymbol_obstack,
860                                 sizeof (struct symloc));
861       LDSYMOFF (subpst) =
862         LDSYMLEN (subpst) =
863         subpst->textlow =
864         subpst->texthigh = 0;
865
866       /* We could save slight bits of space by only making one of these,
867          shared by the entire set of include files.  FIXME-someday.  */
868       subpst->dependencies = (struct partial_symtab **)
869         obstack_alloc (&objfile->psymbol_obstack,
870                        sizeof (struct partial_symtab *));
871       subpst->dependencies[0] = pst;
872       subpst->number_of_dependencies = 1;
873
874       subpst->globals_offset =
875         subpst->n_global_syms =
876         subpst->statics_offset =
877         subpst->n_static_syms = 0;
878
879       subpst->readin = 0;
880       subpst->symtab = 0;
881       subpst->read_symtab = pst->read_symtab;
882     }
883
884   sort_pst_symbols (pst);
885
886   /* If there is already a psymtab or symtab for a file of this name, remove it.
887      (If there is a symtab, more drastic things also happen.)
888      This happens in VxWorks.  */
889   free_named_symtabs (pst->filename);
890
891   if (num_includes == 0
892       && number_dependencies == 0
893       && pst->n_global_syms == 0
894       && pst->n_static_syms == 0)
895     {
896       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
897          it is on the obstack, but we can forget to chain it on the list.  */
898       /* Empty psymtabs happen as a result of header files which don't have
899          any symbols in them.  There can be a lot of them.  But this check
900          is wrong, in that a psymtab with N_SLINE entries but nothing else
901          is not empty, but we don't realize that.  Fixing that without slowing
902          things down might be tricky.  */
903
904       discard_psymtab (pst);
905
906       /* Indicate that psymtab was thrown away.  */
907       pst = (struct partial_symtab *) NULL;
908     }
909   return pst;
910 }
911 \f
912 /* Do the dirty work of reading in the full symbol from a partial symbol
913    table.  */
914
915 static void
916 hpread_psymtab_to_symtab_1 (struct partial_symtab *pst)
917 {
918   struct cleanup *old_chain;
919   int i;
920
921   /* Get out quick if passed junk.  */
922   if (!pst)
923     return;
924
925   /* Complain if we've already read in this symbol table.  */
926   if (pst->readin)
927     {
928       fprintf (stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
929                pst->filename);
930       return;
931     }
932
933   /* Read in all partial symtabs on which this one is dependent */
934   for (i = 0; i < pst->number_of_dependencies; i++)
935     if (!pst->dependencies[i]->readin)
936       {
937         /* Inform about additional files that need to be read in.  */
938         if (info_verbose)
939           {
940             fputs_filtered (" ", gdb_stdout);
941             wrap_here ("");
942             fputs_filtered ("and ", gdb_stdout);
943             wrap_here ("");
944             printf_filtered ("%s...", pst->dependencies[i]->filename);
945             wrap_here ("");     /* Flush output */
946             gdb_flush (gdb_stdout);
947           }
948         hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
949       }
950
951   /* If it's real...  */
952   if (LDSYMLEN (pst))
953     {
954       /* Init stuff necessary for reading in symbols */
955       buildsym_init ();
956       old_chain = make_cleanup (really_free_pendings, 0);
957
958       pst->symtab =
959         hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
960                               pst->textlow, pst->texthigh - pst->textlow,
961                               pst->section_offsets, pst->filename);
962       sort_symtab_syms (pst->symtab);
963
964       do_cleanups (old_chain);
965     }
966
967   pst->readin = 1;
968 }
969
970 /* Read in all of the symbols for a given psymtab for real.
971    Be verbose about it if the user wants that.  */
972
973 static void
974 hpread_psymtab_to_symtab (struct partial_symtab *pst)
975 {
976   /* Get out quick if given junk.  */
977   if (!pst)
978     return;
979
980   /* Sanity check.  */
981   if (pst->readin)
982     {
983       fprintf (stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
984                pst->filename);
985       return;
986     }
987
988   if (LDSYMLEN (pst) || pst->number_of_dependencies)
989     {
990       /* Print the message now, before reading the string table,
991          to avoid disconcerting pauses.  */
992       if (info_verbose)
993         {
994           printf_filtered ("Reading in symbols for %s...", pst->filename);
995           gdb_flush (gdb_stdout);
996         }
997
998       hpread_psymtab_to_symtab_1 (pst);
999
1000       /* Match with global symbols.  This only needs to be done once,
1001          after all of the symtabs and dependencies have been read in.   */
1002       scan_file_globals (pst->objfile);
1003
1004       /* Finish up the debug error message.  */
1005       if (info_verbose)
1006         printf_filtered ("done.\n");
1007     }
1008 }
1009 /* Read in a defined section of a specific object file's symbols.
1010
1011    DESC is the file descriptor for the file, positioned at the
1012    beginning of the symtab
1013    SYM_OFFSET is the offset within the file of
1014    the beginning of the symbols we want to read
1015    SYM_SIZE is the size of the symbol info to read in.
1016    TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1017    TEXT_SIZE is the size of the text segment read in.
1018    SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1019
1020 static struct symtab *
1021 hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size,
1022                       CORE_ADDR text_offset, int text_size,
1023                       struct section_offsets *section_offsets, char *filename)
1024 {
1025   char *namestring;
1026   union dnttentry *dn_bufp;
1027   unsigned max_symnum;
1028
1029   int sym_index = sym_offset / sizeof (struct dntt_type_block);
1030
1031   current_objfile = objfile;
1032   subfile_stack = 0;
1033
1034   last_source_file = 0;
1035
1036   dn_bufp = hpread_get_lntt (sym_index, objfile);
1037   if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1038         (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1039     {
1040       start_symtab ("globals", NULL, 0);
1041       record_debugformat ("HP");
1042     }
1043
1044   max_symnum = sym_size / sizeof (struct dntt_type_block);
1045
1046   /* Read in and process each debug symbol within the specified range.  */
1047   for (symnum = 0;
1048        symnum < max_symnum;
1049        symnum++)
1050     {
1051       QUIT;                     /* Allow this to be interruptable */
1052       dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1053
1054       if (dn_bufp->dblock.extension)
1055         continue;
1056
1057       /* Yow!  We call SET_NAMESTRING on things without names!  */
1058       SET_NAMESTRING (dn_bufp, &namestring, objfile);
1059
1060       hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1061                                        objfile, text_offset, text_size,
1062                                        filename, symnum + sym_index);
1063     }
1064
1065   current_objfile = NULL;
1066
1067   return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
1068 }
1069 \f
1070
1071 /* Convert basic types from HP debug format into GDB internal format.  */
1072
1073 static int
1074 hpread_type_translate (dnttpointer typep)
1075 {
1076   if (!typep.dntti.immediate)
1077     abort ();
1078
1079   switch (typep.dntti.type)
1080     {
1081     case HP_TYPE_BOOLEAN:
1082     case HP_TYPE_BOOLEAN_S300_COMPAT:
1083     case HP_TYPE_BOOLEAN_VAX_COMPAT:
1084       return FT_BOOLEAN;
1085       /* Ugh.  No way to distinguish between signed and unsigned chars.  */
1086     case HP_TYPE_CHAR:
1087     case HP_TYPE_WIDE_CHAR:
1088       return FT_CHAR;
1089     case HP_TYPE_INT:
1090       if (typep.dntti.bitlength <= 8)
1091         return FT_CHAR;
1092       if (typep.dntti.bitlength <= 16)
1093         return FT_SHORT;
1094       if (typep.dntti.bitlength <= 32)
1095         return FT_INTEGER;
1096       return FT_LONG_LONG;
1097     case HP_TYPE_LONG:
1098       return FT_LONG;
1099     case HP_TYPE_UNSIGNED_LONG:
1100       if (typep.dntti.bitlength <= 8)
1101         return FT_UNSIGNED_CHAR;
1102       if (typep.dntti.bitlength <= 16)
1103         return FT_UNSIGNED_SHORT;
1104       if (typep.dntti.bitlength <= 32)
1105         return FT_UNSIGNED_LONG;
1106       return FT_UNSIGNED_LONG_LONG;
1107     case HP_TYPE_UNSIGNED_INT:
1108       if (typep.dntti.bitlength <= 8)
1109         return FT_UNSIGNED_CHAR;
1110       if (typep.dntti.bitlength <= 16)
1111         return FT_UNSIGNED_SHORT;
1112       if (typep.dntti.bitlength <= 32)
1113         return FT_UNSIGNED_INTEGER;
1114       return FT_UNSIGNED_LONG_LONG;
1115     case HP_TYPE_REAL:
1116     case HP_TYPE_REAL_3000:
1117     case HP_TYPE_DOUBLE:
1118       if (typep.dntti.bitlength == 64)
1119         return FT_DBL_PREC_FLOAT;
1120       if (typep.dntti.bitlength == 128)
1121         return FT_EXT_PREC_FLOAT;
1122       return FT_FLOAT;
1123     case HP_TYPE_COMPLEX:
1124     case HP_TYPE_COMPLEXS3000:
1125       if (typep.dntti.bitlength == 128)
1126         return FT_DBL_PREC_COMPLEX;
1127       if (typep.dntti.bitlength == 192)
1128         return FT_EXT_PREC_COMPLEX;
1129       return FT_COMPLEX;
1130     case HP_TYPE_STRING200:
1131     case HP_TYPE_LONGSTRING200:
1132     case HP_TYPE_FTN_STRING_SPEC:
1133     case HP_TYPE_MOD_STRING_SPEC:
1134     case HP_TYPE_MOD_STRING_3000:
1135     case HP_TYPE_FTN_STRING_S300_COMPAT:
1136     case HP_TYPE_FTN_STRING_VAX_COMPAT:
1137       return FT_STRING;
1138     default:
1139       abort ();
1140     }
1141 }
1142
1143 /* Return the type associated with the index found in HP_TYPE.  */
1144
1145 static struct type **
1146 hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile)
1147 {
1148   unsigned old_len;
1149   int index = hp_type.dnttp.index;
1150
1151   if (hp_type.dntti.immediate)
1152     return NULL;
1153
1154   if (index < LNTT_SYMCOUNT (objfile))
1155     {
1156       if (index >= TYPE_VECTOR_LENGTH (objfile))
1157         {
1158           old_len = TYPE_VECTOR_LENGTH (objfile);
1159           if (old_len == 0)
1160             {
1161               TYPE_VECTOR_LENGTH (objfile) = 100;
1162               TYPE_VECTOR (objfile) = (struct type **)
1163                 xmmalloc (objfile->md,
1164                      TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1165             }
1166           while (index >= TYPE_VECTOR_LENGTH (objfile))
1167             TYPE_VECTOR_LENGTH (objfile) *= 2;
1168           TYPE_VECTOR (objfile) = (struct type **)
1169             xmrealloc (objfile->md,
1170                        (char *) TYPE_VECTOR (objfile),
1171                    (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1172           memset (&TYPE_VECTOR (objfile)[old_len], 0,
1173                   (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1174                   sizeof (struct type *));
1175         }
1176       return &TYPE_VECTOR (objfile)[index];
1177     }
1178   else
1179     return NULL;
1180 }
1181
1182 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1183    Note we'll just return the address of a GDB internal type if we already
1184    have it lying around.  */
1185
1186 static struct type *
1187 hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile)
1188 {
1189   struct type **type_addr;
1190
1191   type_addr = hpread_lookup_type (hp_type, objfile);
1192   if (*type_addr == 0)
1193     *type_addr = alloc_type (objfile);
1194
1195   TYPE_CPLUS_SPECIFIC (*type_addr)
1196     = (struct cplus_struct_type *) &cplus_struct_default;
1197   return *type_addr;
1198 }
1199
1200 /* Read a native enumerated type and return it in GDB internal form.  */
1201
1202 static struct type *
1203 hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1204                        struct objfile *objfile)
1205 {
1206   struct type *type;
1207   struct pending **symlist, *osyms, *syms;
1208   int o_nsyms, nsyms = 0;
1209   dnttpointer mem;
1210   union dnttentry *memp;
1211   char *name;
1212   long n;
1213   struct symbol *sym;
1214
1215   type = hpread_alloc_type (hp_type, objfile);
1216   TYPE_LENGTH (type) = 4;
1217
1218   symlist = &file_symbols;
1219   osyms = *symlist;
1220   o_nsyms = osyms ? osyms->nsyms : 0;
1221
1222   /* Get a name for each member and add it to our list of members.  */
1223   mem = dn_bufp->denum.firstmem;
1224   while (mem.dnttp.extension && mem.word != DNTTNIL)
1225     {
1226       memp = hpread_get_lntt (mem.dnttp.index, objfile);
1227
1228       name = VT (objfile) + memp->dmember.name;
1229       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1230                                              sizeof (struct symbol));
1231       memset (sym, 0, sizeof (struct symbol));
1232       SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1233                                         &objfile->symbol_obstack);
1234       SYMBOL_CLASS (sym) = LOC_CONST;
1235       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1236       SYMBOL_VALUE (sym) = memp->dmember.value;
1237       add_symbol_to_list (sym, symlist);
1238       nsyms++;
1239       mem = memp->dmember.nextmem;
1240     }
1241
1242   /* Now that we know more about the enum, fill in more info.  */
1243   TYPE_CODE (type) = TYPE_CODE_ENUM;
1244   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1245   TYPE_NFIELDS (type) = nsyms;
1246   TYPE_FIELDS (type) = (struct field *)
1247     obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1248
1249   /* Find the symbols for the members and put them into the type.
1250      The symbols can be found in the symlist that we put them on
1251      to cause them to be defined.  osyms contains the old value
1252      of that symlist; everything up to there was defined by us.
1253
1254      Note that we preserve the order of the enum constants, so
1255      that in something like "enum {FOO, LAST_THING=FOO}" we print
1256      FOO, not LAST_THING.  */
1257   for (syms = *symlist, n = 0; syms; syms = syms->next)
1258     {
1259       int j = 0;
1260       if (syms == osyms)
1261         j = o_nsyms;
1262       for (; j < syms->nsyms; j++, n++)
1263         {
1264           struct symbol *xsym = syms->symbol[j];
1265           SYMBOL_TYPE (xsym) = type;
1266           TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1267           TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1268           TYPE_FIELD_BITSIZE (type, n) = 0;
1269         }
1270       if (syms == osyms)
1271         break;
1272     }
1273
1274   return type;
1275 }
1276
1277 /* Read and internalize a native function debug symbol.  */
1278
1279 static struct type *
1280 hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1281                            struct objfile *objfile)
1282 {
1283   struct type *type, *type1;
1284   struct pending **symlist, *osyms, *syms;
1285   int o_nsyms, nsyms = 0;
1286   dnttpointer param;
1287   union dnttentry *paramp;
1288   char *name;
1289   long n;
1290   struct symbol *sym;
1291
1292   param = dn_bufp->dfunc.firstparam;
1293
1294   /* See if we've already read in this type.  */
1295   type = hpread_alloc_type (hp_type, objfile);
1296   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1297     return type;
1298
1299   /* Nope, so read it in and store it away.  */
1300   type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1301                                                     objfile));
1302   memcpy ((char *) type, (char *) type1, sizeof (struct type));
1303
1304   symlist = &local_symbols;
1305   osyms = *symlist;
1306   o_nsyms = osyms ? osyms->nsyms : 0;
1307
1308   /* Now examine each parameter noting its type, location, and a
1309      wealth of other information.  */
1310   while (param.word && param.word != DNTTNIL)
1311     {
1312       paramp = hpread_get_lntt (param.dnttp.index, objfile);
1313       nsyms++;
1314       param = paramp->dfparam.nextparam;
1315
1316       /* Get the name.  */
1317       name = VT (objfile) + paramp->dfparam.name;
1318       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1319                                              sizeof (struct symbol));
1320       (void) memset (sym, 0, sizeof (struct symbol));
1321       SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1322                                         &objfile->symbol_obstack);
1323
1324       /* Figure out where it lives.  */
1325       if (paramp->dfparam.regparam)
1326         SYMBOL_CLASS (sym) = LOC_REGPARM;
1327       else if (paramp->dfparam.indirect)
1328         SYMBOL_CLASS (sym) = LOC_REF_ARG;
1329       else
1330         SYMBOL_CLASS (sym) = LOC_ARG;
1331       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1332       if (paramp->dfparam.copyparam)
1333         {
1334           SYMBOL_VALUE (sym) = paramp->dfparam.location;
1335 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1336           SYMBOL_VALUE (sym)
1337             += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1338 #endif
1339           /* This is likely a pass-by-invisible reference parameter,
1340              Hack on the symbol class to make GDB happy.  */
1341           SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1342         }
1343       else
1344         SYMBOL_VALUE (sym) = paramp->dfparam.location;
1345
1346       /* Get its type.  */
1347       SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1348
1349       /* Add it to the list.  */
1350       add_symbol_to_list (sym, symlist);
1351     }
1352
1353   /* Note how many parameters we found.  */
1354   TYPE_NFIELDS (type) = nsyms;
1355   TYPE_FIELDS (type) = (struct field *)
1356     obstack_alloc (&objfile->type_obstack,
1357                    sizeof (struct field) * nsyms);
1358
1359   /* Find the symbols for the values and put them into the type.
1360      The symbols can be found in the symlist that we put them on
1361      to cause them to be defined.  osyms contains the old value
1362      of that symlist; everything up to there was defined by us.  */
1363   /* Note that we preserve the order of the parameters, so
1364      that in something like "enum {FOO, LAST_THING=FOO}" we print
1365      FOO, not LAST_THING.  */
1366   for (syms = *symlist, n = 0; syms; syms = syms->next)
1367     {
1368       int j = 0;
1369       if (syms == osyms)
1370         j = o_nsyms;
1371       for (; j < syms->nsyms; j++, n++)
1372         {
1373           struct symbol *xsym = syms->symbol[j];
1374           TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1375           TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1376           TYPE_FIELD_BITPOS (type, n) = n;
1377           TYPE_FIELD_BITSIZE (type, n) = 0;
1378         }
1379       if (syms == osyms)
1380         break;
1381     }
1382   return type;
1383 }
1384
1385 /* Read in and internalize a structure definition.  */
1386
1387 static struct type *
1388 hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1389                          struct objfile *objfile)
1390 {
1391   struct nextfield
1392     {
1393       struct nextfield *next;
1394       struct field field;
1395     };
1396
1397   struct type *type;
1398   struct nextfield *list = 0;
1399   struct nextfield *new;
1400   int n, nfields = 0;
1401   dnttpointer field;
1402   union dnttentry *fieldp;
1403
1404   /* Is it something we've already dealt with?  */
1405   type = hpread_alloc_type (hp_type, objfile);
1406   if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1407       (TYPE_CODE (type) == TYPE_CODE_UNION))
1408     return type;
1409
1410   /* Get the basic type correct.  */
1411   if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1412     {
1413       TYPE_CODE (type) = TYPE_CODE_STRUCT;
1414       TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1415     }
1416   else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1417     {
1418       TYPE_CODE (type) = TYPE_CODE_UNION;
1419       TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1420     }
1421   else
1422     return type;
1423
1424
1425   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1426
1427   /* Read in and internalize all the fields.  */
1428   field = dn_bufp->dstruct.firstfield;
1429   while (field.word != DNTTNIL && field.dnttp.extension)
1430     {
1431       fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1432
1433       /* Get space to record the next field's data.  */
1434       new = (struct nextfield *) alloca (sizeof (struct nextfield));
1435       new->next = list;
1436       list = new;
1437
1438       list->field.name = VT (objfile) + fieldp->dfield.name;
1439       FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1440       if (fieldp->dfield.bitlength % 8)
1441         FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1442       else
1443         FIELD_BITSIZE (list->field) = 0;
1444       nfields++;
1445       field = fieldp->dfield.nextfield;
1446       FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1447                                                      objfile);
1448     }
1449
1450   TYPE_NFIELDS (type) = nfields;
1451   TYPE_FIELDS (type) = (struct field *)
1452     obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1453
1454   /* Copy the saved-up fields into the field vector.  */
1455   for (n = nfields; list; list = list->next)
1456     {
1457       n -= 1;
1458       TYPE_FIELD (type, n) = list->field;
1459     }
1460   return type;
1461 }
1462
1463 /* Read in and internalize a set debug symbol.  */
1464
1465 static struct type *
1466 hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1467                       struct objfile *objfile)
1468 {
1469   struct type *type;
1470
1471   /* See if it's something we've already deal with.  */
1472   type = hpread_alloc_type (hp_type, objfile);
1473   if (TYPE_CODE (type) == TYPE_CODE_SET)
1474     return type;
1475
1476   /* Nope.  Fill in the appropriate fields.  */
1477   TYPE_CODE (type) = TYPE_CODE_SET;
1478   TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1479   TYPE_NFIELDS (type) = 0;
1480   TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1481                                                 objfile);
1482   return type;
1483 }
1484
1485 /* Read in and internalize an array debug symbol.  */
1486
1487 static struct type *
1488 hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1489                         struct objfile *objfile)
1490 {
1491   struct type *type;
1492   union dnttentry save;
1493   save = *dn_bufp;
1494
1495   /* Why no check here?  Because it kept us from properly determining
1496      the size of the array!  */
1497   type = hpread_alloc_type (hp_type, objfile);
1498
1499   TYPE_CODE (type) = TYPE_CODE_ARRAY;
1500
1501   /* values are not normalized.  */
1502   if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1503         || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1504     abort ();
1505   else if (dn_bufp->darray.arraylength == 0x7fffffff)
1506     {
1507       /* The HP debug format represents char foo[]; as an array with
1508          length 0x7fffffff.  Internally GDB wants to represent this
1509          as an array of length zero.  */
1510       TYPE_LENGTH (type) = 0;
1511     }
1512   else
1513     TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1514
1515   TYPE_NFIELDS (type) = 1;
1516   TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1517                                                 objfile);
1518   dn_bufp = &save;
1519   TYPE_FIELDS (type) = (struct field *)
1520     obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1521   TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1522                                                   objfile);
1523   return type;
1524 }
1525
1526 /* Read in and internalize a subrange debug symbol.  */
1527 static struct type *
1528 hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp,
1529                            struct objfile *objfile)
1530 {
1531   struct type *type;
1532
1533   /* Is it something we've already dealt with.  */
1534   type = hpread_alloc_type (hp_type, objfile);
1535   if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1536     return type;
1537
1538   /* Nope, internalize it.  */
1539   TYPE_CODE (type) = TYPE_CODE_RANGE;
1540   TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1541   TYPE_NFIELDS (type) = 2;
1542   TYPE_FIELDS (type)
1543     = (struct field *) obstack_alloc (&objfile->type_obstack,
1544                                       2 * sizeof (struct field));
1545
1546   if (dn_bufp->dsubr.dyn_low)
1547     TYPE_FIELD_BITPOS (type, 0) = 0;
1548   else
1549     TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1550
1551   if (dn_bufp->dsubr.dyn_high)
1552     TYPE_FIELD_BITPOS (type, 1) = -1;
1553   else
1554     TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1555   TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1556                                                 objfile);
1557   return type;
1558 }
1559
1560 static struct type *
1561 hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile)
1562 {
1563   union dnttentry *dn_bufp;
1564
1565   /* First see if it's a simple builtin type.  */
1566   if (hp_type.dntti.immediate)
1567     return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1568
1569   /* Not a builtin type.  We'll have to read it in.  */
1570   if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1571     dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1572   else
1573     return lookup_fundamental_type (objfile, FT_VOID);
1574
1575   switch (dn_bufp->dblock.kind)
1576     {
1577     case DNTT_TYPE_SRCFILE:
1578     case DNTT_TYPE_MODULE:
1579     case DNTT_TYPE_FUNCTION:
1580     case DNTT_TYPE_ENTRY:
1581     case DNTT_TYPE_BEGIN:
1582     case DNTT_TYPE_END:
1583     case DNTT_TYPE_IMPORT:
1584     case DNTT_TYPE_LABEL:
1585     case DNTT_TYPE_WITH:
1586     case DNTT_TYPE_COMMON:
1587     case DNTT_TYPE_FPARAM:
1588     case DNTT_TYPE_SVAR:
1589     case DNTT_TYPE_DVAR:
1590     case DNTT_TYPE_CONST:
1591       /* Opps.  Something went very wrong.  */
1592       return lookup_fundamental_type (objfile, FT_VOID);
1593
1594     case DNTT_TYPE_TYPEDEF:
1595       {
1596         struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1597                                                       objfile);
1598         char *suffix;
1599         suffix = VT (objfile) + dn_bufp->dtype.name;
1600
1601         TYPE_CPLUS_SPECIFIC (structtype)
1602           = (struct cplus_struct_type *) &cplus_struct_default;
1603         TYPE_NAME (structtype) = suffix;
1604         return structtype;
1605       }
1606
1607     case DNTT_TYPE_TAGDEF:
1608       {
1609         /* Just a little different from above.  We have to tack on
1610            an identifier of some kind (struct, union, enum, etc).  */
1611         struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1612                                                       objfile);
1613         char *prefix, *suffix;
1614         suffix = VT (objfile) + dn_bufp->dtype.name;
1615
1616         /* Lookup the next type in the list.  It should be a structure,
1617            union, or enum type.  We will need to attach that to our name.  */
1618         if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1619           dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1620         else
1621           abort ();
1622
1623         if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1624           prefix = "struct ";
1625         else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1626           prefix = "union ";
1627         else
1628           prefix = "enum ";
1629
1630         /* Build the correct name.  */
1631         structtype->name
1632           = (char *) obstack_alloc (&objfile->type_obstack,
1633                                     strlen (prefix) + strlen (suffix) + 1);
1634         TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1635         TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1636         TYPE_TAG_NAME (structtype) = suffix;
1637
1638         TYPE_CPLUS_SPECIFIC (structtype)
1639           = (struct cplus_struct_type *) &cplus_struct_default;
1640
1641         return structtype;
1642       }
1643     case DNTT_TYPE_POINTER:
1644       return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1645                                                       objfile));
1646     case DNTT_TYPE_ENUM:
1647       return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1648     case DNTT_TYPE_MEMENUM:
1649       return lookup_fundamental_type (objfile, FT_VOID);
1650     case DNTT_TYPE_SET:
1651       return hpread_read_set_type (hp_type, dn_bufp, objfile);
1652     case DNTT_TYPE_SUBRANGE:
1653       return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1654     case DNTT_TYPE_ARRAY:
1655       return hpread_read_array_type (hp_type, dn_bufp, objfile);
1656     case DNTT_TYPE_STRUCT:
1657     case DNTT_TYPE_UNION:
1658       return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1659     case DNTT_TYPE_FIELD:
1660       return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1661     case DNTT_TYPE_VARIANT:
1662     case DNTT_TYPE_FILE:
1663       return lookup_fundamental_type (objfile, FT_VOID);
1664     case DNTT_TYPE_FUNCTYPE:
1665       return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1666                                                        objfile));
1667     case DNTT_TYPE_COBSTRUCT:
1668     case DNTT_TYPE_XREF:
1669     case DNTT_TYPE_SA:
1670     case DNTT_TYPE_MACRO:
1671     default:
1672       return lookup_fundamental_type (objfile, FT_VOID);
1673     }
1674 }
1675
1676 static sltpointer
1677 hpread_record_lines (struct subfile *subfile, sltpointer s_idx,
1678                      sltpointer e_idx, struct objfile *objfile,
1679                      CORE_ADDR offset)
1680 {
1681   union sltentry *sl_bufp;
1682
1683   while (s_idx <= e_idx)
1684     {
1685       sl_bufp = hpread_get_slt (s_idx, objfile);
1686       /* Only record "normal" entries in the SLT.  */
1687       if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1688           || sl_bufp->snorm.sltdesc == SLT_EXIT)
1689         record_line (subfile, sl_bufp->snorm.line,
1690                      sl_bufp->snorm.address + offset);
1691       s_idx++;
1692     }
1693   return e_idx;
1694 }
1695
1696 /* Internalize one native debug symbol.  */
1697
1698 static void
1699 hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name,
1700                                  struct section_offsets *section_offsets,
1701                                  struct objfile *objfile, CORE_ADDR text_offset,
1702                                  int text_size, char *filename, int index)
1703 {
1704   unsigned long desc;
1705   int type;
1706   CORE_ADDR valu;
1707   int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
1708   union dnttentry *dn_temp;
1709   dnttpointer hp_type;
1710   struct symbol *sym;
1711   struct context_stack *new;
1712
1713   /* Allocate one GDB debug symbol and fill in some default values.  */
1714   sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1715                                          sizeof (struct symbol));
1716   memset (sym, 0, sizeof (struct symbol));
1717   SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1718   SYMBOL_LANGUAGE (sym) = language_auto;
1719   SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1720   SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1721   SYMBOL_LINE (sym) = 0;
1722   SYMBOL_VALUE (sym) = 0;
1723   SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1724
1725   hp_type.dnttp.extension = 1;
1726   hp_type.dnttp.immediate = 0;
1727   hp_type.dnttp.global = 0;
1728   hp_type.dnttp.index = index;
1729
1730   type = dn_bufp->dblock.kind;
1731
1732   switch (type)
1733     {
1734     case DNTT_TYPE_SRCFILE:
1735       /* This type of symbol indicates from which source file or include file
1736          the following data comes. If there are no modules it also may
1737          indicate the start of a new source file, in which case we must
1738          finish the symbol table of the previous source file
1739          (if any) and start accumulating a new symbol table.  */
1740
1741       valu = text_offset;
1742       if (!last_source_file)
1743         {
1744           start_symtab (name, NULL, valu);
1745           record_debugformat ("HP");
1746           SL_INDEX (objfile) = dn_bufp->dsfile.address;
1747         }
1748       else
1749         {
1750           SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1751                                                     SL_INDEX (objfile),
1752                                                     dn_bufp->dsfile.address,
1753                                                     objfile, offset);
1754         }
1755       start_subfile (name, NULL);
1756       break;
1757
1758     case DNTT_TYPE_MODULE:
1759       /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore.  */
1760       break;
1761
1762     case DNTT_TYPE_FUNCTION:
1763     case DNTT_TYPE_ENTRY:
1764       /* A function or secondary entry point.  */
1765       valu = dn_bufp->dfunc.lowaddr + offset;
1766       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1767                                                 SL_INDEX (objfile),
1768                                                 dn_bufp->dfunc.address,
1769                                                 objfile, offset);
1770
1771       WITHIN_FUNCTION (objfile) = 1;
1772       CURRENT_FUNCTION_VALUE (objfile) = valu;
1773
1774       /* Stack must be empty now.  */
1775       if (context_stack_depth != 0)
1776         complain (&lbrac_unmatched_complaint, (char *) symnum);
1777       new = push_context (0, valu);
1778
1779       SYMBOL_CLASS (sym) = LOC_BLOCK;
1780       SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1781       if (dn_bufp->dfunc.global)
1782         add_symbol_to_list (sym, &global_symbols);
1783       else
1784         add_symbol_to_list (sym, &file_symbols);
1785       new->name = sym;
1786
1787       /* Search forward to the next scope beginning.  */
1788       while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1789         {
1790           dn_bufp = hpread_get_lntt (++index, objfile);
1791           if (dn_bufp->dblock.extension)
1792             continue;
1793         }
1794       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1795                                                 SL_INDEX (objfile),
1796                                                 dn_bufp->dbegin.address,
1797                                                 objfile, offset);
1798       SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1799       record_line (current_subfile, SYMBOL_LINE (sym), valu);
1800       break;
1801
1802     case DNTT_TYPE_BEGIN:
1803       /* Begin a new scope.  */
1804       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1805                                                 SL_INDEX (objfile),
1806                                                 dn_bufp->dbegin.address,
1807                                                 objfile, offset);
1808       valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1809       valu += offset;           /* Relocate for dynamic loading */
1810       desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1811       new = push_context (desc, valu);
1812       break;
1813
1814     case DNTT_TYPE_END:
1815       /* End a scope.  */
1816       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1817                                                 SL_INDEX (objfile),
1818                                                 dn_bufp->dend.address + 1,
1819                                                 objfile, offset);
1820       switch (dn_bufp->dend.endkind)
1821         {
1822         case DNTT_TYPE_MODULE:
1823           /* Ending a module ends the symbol table for that module.  */
1824           valu = text_offset + text_size + offset;
1825           (void) end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
1826           break;
1827
1828         case DNTT_TYPE_FUNCTION:
1829           /* Ending a function, well, ends the function's scope.  */
1830           dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1831                                      objfile);
1832           valu = dn_temp->dfunc.hiaddr + offset;
1833           new = pop_context ();
1834           /* Make a block for the local symbols within.  */
1835           finish_block (new->name, &local_symbols, new->old_blocks,
1836                         new->start_addr, valu, objfile);
1837           WITHIN_FUNCTION (objfile) = 0;
1838           break;
1839         case DNTT_TYPE_BEGIN:
1840           /* Just ending a local scope.  */
1841           valu = hpread_get_location (dn_bufp->dend.address, objfile);
1842           /* Why in the hell is this needed?  */
1843           valu += offset + 9;   /* Relocate for dynamic loading */
1844           new = pop_context ();
1845           desc = dn_bufp->dend.beginscope.dnttp.index;
1846           if (desc != new->depth)
1847             complain (&lbrac_mismatch_complaint, (char *) symnum);
1848           /* Make a block for the local symbols within.  */
1849           finish_block (new->name, &local_symbols, new->old_blocks,
1850                         new->start_addr, valu, objfile);
1851           local_symbols = new->locals;
1852           break;
1853         }
1854       break;
1855     case DNTT_TYPE_LABEL:
1856       SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1857       break;
1858     case DNTT_TYPE_FPARAM:
1859       /* Function parameters.  */
1860       if (dn_bufp->dfparam.regparam)
1861         SYMBOL_CLASS (sym) = LOC_REGISTER;
1862       else
1863         SYMBOL_CLASS (sym) = LOC_LOCAL;
1864       if (dn_bufp->dfparam.copyparam)
1865         {
1866           SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1867 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1868           SYMBOL_VALUE (sym)
1869             += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1870 #endif
1871         }
1872       else
1873         SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1874       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1875       add_symbol_to_list (sym, &local_symbols);
1876       break;
1877     case DNTT_TYPE_SVAR:
1878       /* Static variables.  */
1879       SYMBOL_CLASS (sym) = LOC_STATIC;
1880       SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1881       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1882       if (dn_bufp->dsvar.global)
1883         add_symbol_to_list (sym, &global_symbols);
1884       else if (WITHIN_FUNCTION (objfile))
1885         add_symbol_to_list (sym, &local_symbols);
1886       else
1887         add_symbol_to_list (sym, &file_symbols);
1888       break;
1889     case DNTT_TYPE_DVAR:
1890       /* Dynamic variables.  */
1891       if (dn_bufp->ddvar.regvar)
1892         SYMBOL_CLASS (sym) = LOC_REGISTER;
1893       else
1894         SYMBOL_CLASS (sym) = LOC_LOCAL;
1895       SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1896 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1897       SYMBOL_VALUE (sym)
1898         += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1899 #endif
1900       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1901       if (dn_bufp->ddvar.global)
1902         add_symbol_to_list (sym, &global_symbols);
1903       else if (WITHIN_FUNCTION (objfile))
1904         add_symbol_to_list (sym, &local_symbols);
1905       else
1906         add_symbol_to_list (sym, &file_symbols);
1907       break;
1908     case DNTT_TYPE_CONST:
1909       /* A constant (pascal?).  */
1910       SYMBOL_CLASS (sym) = LOC_CONST;
1911       SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1912       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1913       if (dn_bufp->dconst.global)
1914         add_symbol_to_list (sym, &global_symbols);
1915       else if (WITHIN_FUNCTION (objfile))
1916         add_symbol_to_list (sym, &local_symbols);
1917       else
1918         add_symbol_to_list (sym, &file_symbols);
1919       break;
1920     case DNTT_TYPE_TYPEDEF:
1921       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1922       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1923       if (dn_bufp->dtype.global)
1924         add_symbol_to_list (sym, &global_symbols);
1925       else if (WITHIN_FUNCTION (objfile))
1926         add_symbol_to_list (sym, &local_symbols);
1927       else
1928         add_symbol_to_list (sym, &file_symbols);
1929       break;
1930     case DNTT_TYPE_TAGDEF:
1931       SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1932       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1933       TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1934       TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
1935       if (dn_bufp->dtype.global)
1936         add_symbol_to_list (sym, &global_symbols);
1937       else if (WITHIN_FUNCTION (objfile))
1938         add_symbol_to_list (sym, &local_symbols);
1939       else
1940         add_symbol_to_list (sym, &file_symbols);
1941       break;
1942     case DNTT_TYPE_POINTER:
1943       SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
1944                                                (dn_bufp->dptr.pointsto,
1945                                                 objfile));
1946       add_symbol_to_list (sym, &file_symbols);
1947       break;
1948     case DNTT_TYPE_ENUM:
1949       SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1950       SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
1951       add_symbol_to_list (sym, &file_symbols);
1952       break;
1953     case DNTT_TYPE_MEMENUM:
1954       break;
1955     case DNTT_TYPE_SET:
1956       SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
1957       add_symbol_to_list (sym, &file_symbols);
1958       break;
1959     case DNTT_TYPE_SUBRANGE:
1960       SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
1961                                                      objfile);
1962       add_symbol_to_list (sym, &file_symbols);
1963       break;
1964     case DNTT_TYPE_ARRAY:
1965       SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
1966       add_symbol_to_list (sym, &file_symbols);
1967       break;
1968     case DNTT_TYPE_STRUCT:
1969     case DNTT_TYPE_UNION:
1970       SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1971       SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
1972       add_symbol_to_list (sym, &file_symbols);
1973       break;
1974     default:
1975       break;
1976     }
1977 }