OSDN Git Service

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