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