2003-05-14 Elena Zannoni <ezannoni@redhat.com>
[external/binutils.git] / gdb / hpread.c
1 /* Read hp debug symbols and convert to internal format, for GDB.
2    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3    Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.
21
22    Written by the Center for Software Science at the University of Utah
23    and by Cygnus Support.  */
24
25 #include "defs.h"
26 #include "bfd.h"
27 #include "gdb_string.h"
28 #include "hp-symtab.h"
29 #include "syms.h"
30 #include "symtab.h"
31 #include "symfile.h"
32 #include "objfiles.h"
33 #include "buildsym.h"
34 #include "complaints.h"
35 #include "gdb-stabs.h"
36 #include "gdbtypes.h"
37 #include "demangle.h"
38 #include "somsolib.h"
39 #include "gdb_assert.h"
40
41 /* Private information attached to an objfile which we use to find
42    and internalize the HP C debug symbols within that objfile.  */
43
44 struct hpread_symfile_info
45   {
46     /* The contents of each of the debug sections (there are 4 of them).  */
47     char *gntt;
48     char *lntt;
49     char *slt;
50     char *vt;
51
52     /* We keep the size of the $VT$ section for range checking.  */
53     unsigned int vt_size;
54
55     /* Some routines still need to know the number of symbols in the
56        main debug sections ($LNTT$ and $GNTT$). */
57     unsigned int lntt_symcount;
58     unsigned int gntt_symcount;
59
60     /* To keep track of all the types we've processed.  */
61     struct type **dntt_type_vector;
62     int dntt_type_vector_length;
63
64     /* Keeps track of the beginning of a range of source lines.  */
65     sltpointer sl_index;
66
67     /* Some state variables we'll need.  */
68     int within_function;
69
70     /* Keep track of the current function's address.  We may need to look
71        up something based on this address.  */
72     unsigned int current_function_value;
73   };
74
75 /* Accessor macros to get at the fields.  */
76 #define HPUX_SYMFILE_INFO(o) \
77   ((struct hpread_symfile_info *)((o)->sym_private))
78 #define GNTT(o)                 (HPUX_SYMFILE_INFO(o)->gntt)
79 #define LNTT(o)                 (HPUX_SYMFILE_INFO(o)->lntt)
80 #define SLT(o)                  (HPUX_SYMFILE_INFO(o)->slt)
81 #define VT(o)                   (HPUX_SYMFILE_INFO(o)->vt)
82 #define VT_SIZE(o)              (HPUX_SYMFILE_INFO(o)->vt_size)
83 #define LNTT_SYMCOUNT(o)        (HPUX_SYMFILE_INFO(o)->lntt_symcount)
84 #define GNTT_SYMCOUNT(o)        (HPUX_SYMFILE_INFO(o)->gntt_symcount)
85 #define DNTT_TYPE_VECTOR(o)     (HPUX_SYMFILE_INFO(o)->dntt_type_vector)
86 #define DNTT_TYPE_VECTOR_LENGTH(o) \
87   (HPUX_SYMFILE_INFO(o)->dntt_type_vector_length)
88 #define SL_INDEX(o)             (HPUX_SYMFILE_INFO(o)->sl_index)
89 #define WITHIN_FUNCTION(o)      (HPUX_SYMFILE_INFO(o)->within_function)
90 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
91
92 \f
93 /* We put a pointer to this structure in the read_symtab_private field
94    of the psymtab.  */
95
96 struct symloc
97   {
98     /* The offset within the file symbol table of first local symbol for
99        this file.  */
100
101     int ldsymoff;
102
103     /* Length (in bytes) of the section of the symbol table devoted to
104        this file's symbols (actually, the section bracketed may contain
105        more than just this file's symbols).  If ldsymlen is 0, the only
106        reason for this thing's existence is the dependency list.
107        Nothing else will happen when it is read in.  */
108
109     int ldsymlen;
110   };
111
112 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
113 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
114 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
115 \f
116 /* Complaints about the symbols we have encountered.  */
117 static void
118 lbrac_unmatched_complaint (int arg1)
119 {
120   complaint (&symfile_complaints, "unmatched N_LBRAC before symtab pos %d",
121              arg1);
122 }
123
124 static void
125 lbrac_mismatch_complaint (int arg1)
126 {
127   complaint (&symfile_complaints,
128              "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1);
129 }
130
131 /* To generate dumping code, uncomment this define.  The dumping
132    itself is controlled by routine-local statics called "dumping". */
133 /* #define DUMPING         1 */
134
135 /* To use the quick look-up tables, uncomment this define. */
136 #define QUICK_LOOK_UP      1
137
138 /* To call PXDB to process un-processed files, uncomment this define. */
139 #define USE_PXDB           1
140
141 /* Forward procedure declarations */
142
143 static void set_namestring (union dnttentry *sym, char **namep,
144                             struct objfile *objfile);
145
146 void hpread_symfile_init (struct objfile *);
147
148 void do_pxdb (bfd *);
149
150 void hpread_build_psymtabs (struct objfile *, int);
151
152 void hpread_symfile_finish (struct objfile *);
153
154 static union dnttentry *hpread_get_gntt (int, struct objfile *);
155
156 static union dnttentry *hpread_get_lntt (int index, struct objfile *objfile);
157
158
159 static unsigned long hpread_get_textlow (int, int, struct objfile *, int);
160
161 static struct partial_symtab *hpread_start_psymtab
162   (struct objfile *, char *, CORE_ADDR, int,
163    struct partial_symbol **, struct partial_symbol **);
164
165 static struct partial_symtab *hpread_end_psymtab
166   (struct partial_symtab *, char **, int, int, CORE_ADDR,
167    struct partial_symtab **, int);
168
169 static unsigned long hpread_get_scope_start (sltpointer, struct objfile *);
170
171 static unsigned long hpread_get_line (sltpointer, struct objfile *);
172
173 static CORE_ADDR hpread_get_location (sltpointer, struct objfile *);
174
175 int hpread_has_name (enum dntt_entry_type kind);
176
177 static void hpread_psymtab_to_symtab_1 (struct partial_symtab *);
178
179 void hpread_psymtab_to_symtab (struct partial_symtab *);
180
181 static struct symtab *hpread_expand_symtab
182   (struct objfile *, int, int, CORE_ADDR, int,
183    struct section_offsets *, char *);
184
185 static int hpread_type_translate (dnttpointer);
186
187 static struct type **hpread_lookup_type (dnttpointer, struct objfile *);
188
189 static struct type *hpread_alloc_type (dnttpointer, struct objfile *);
190
191 static struct type *hpread_read_enum_type
192   (dnttpointer, union dnttentry *, struct objfile *);
193
194 static struct type *hpread_read_function_type
195   (dnttpointer, union dnttentry *, struct objfile *, int);
196
197 static struct type *hpread_read_doc_function_type
198   (dnttpointer, union dnttentry *, struct objfile *, int);
199
200 static struct type *hpread_read_struct_type
201   (dnttpointer, union dnttentry *, struct objfile *);
202
203 static struct type *hpread_get_nth_template_arg (struct objfile *, int);
204
205 static struct type *hpread_read_templ_arg_type
206   (dnttpointer, union dnttentry *, struct objfile *, char *);
207
208 static struct type *hpread_read_set_type
209   (dnttpointer, union dnttentry *, struct objfile *);
210
211 static struct type *hpread_read_array_type
212   (dnttpointer, union dnttentry *dn_bufp, struct objfile *objfile);
213
214 static struct type *hpread_read_subrange_type
215   (dnttpointer, union dnttentry *, struct objfile *);
216
217 static struct type *hpread_type_lookup (dnttpointer, struct objfile *);
218
219 static sltpointer hpread_record_lines
220   (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR);
221
222 static void hpread_process_one_debug_symbol
223   (union dnttentry *, char *, struct section_offsets *,
224    struct objfile *, CORE_ADDR, int, char *, int, int *);
225
226 static int hpread_get_scope_depth (union dnttentry *, struct objfile *, int);
227
228 static void fix_static_member_physnames
229   (struct type *, char *, struct objfile *);
230
231 static void fixup_class_method_type
232   (struct type *, struct type *, struct objfile *);
233
234 static void hpread_adjust_bitoffsets (struct type *, int);
235
236 static dnttpointer hpread_get_next_skip_over_anon_unions
237   (int, dnttpointer, union dnttentry **, struct objfile *);
238
239 \f
240 /* Global to indicate presence of HP-compiled objects,
241    in particular, SOM executable file with SOM debug info 
242    Defined in symtab.c, used in hppa-tdep.c. */
243 extern int hp_som_som_object_present;
244
245 /* Static used to indicate a class type that requires a
246    fix-up of one of its method types */
247 static struct type *fixup_class = NULL;
248
249 /* Static used to indicate the method type that is to be
250    used to fix-up the type for fixup_class */
251 static struct type *fixup_method = NULL;
252
253 #ifdef USE_PXDB
254
255 /* NOTE use of system files!  May not be portable. */
256
257 #define PXDB_SVR4 "/opt/langtools/bin/pxdb"
258 #define PXDB_BSD  "/usr/bin/pxdb"
259
260 #include <stdlib.h>
261 #include "gdb_string.h"
262
263 /* check for the existence of a file, given its full pathname */
264 int
265 file_exists (char *filename)
266 {
267   if (filename)
268     return (access (filename, F_OK) == 0);
269   return 0;
270 }
271
272
273 /* Translate from the "hp_language" enumeration in hp-symtab.h
274    used in the debug info to gdb's generic enumeration in defs.h. */
275 static enum language
276 trans_lang (enum hp_language in_lang)
277 {
278   if (in_lang == HP_LANGUAGE_C)
279     return language_c;
280
281   else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
282     return language_cplus;
283
284   else if (in_lang == HP_LANGUAGE_FORTRAN)
285     return language_fortran;
286
287   else
288     return language_unknown;
289 }
290
291 static char main_string[] = "main";
292 \f
293
294 /* Given the native debug symbol SYM, set NAMEP to the name associated
295    with the debug symbol.  Note we may be called with a debug symbol which
296    has no associated name, in that case we return an empty string.  */
297
298 static void
299 set_namestring (union dnttentry *sym, char **namep, struct objfile *objfile)
300 {
301   /* Note that we "know" that the name for any symbol is always in the same
302      place.  Hence we don't have to conditionalize on the symbol type.  */
303   if (! hpread_has_name (sym->dblock.kind))
304     *namep = "";
305   else if ((unsigned) sym->dsfile.name >= VT_SIZE (objfile))
306     {
307       complaint (&symfile_complaints, "bad string table offset in symbol %d",
308                  symnum);
309       *namep = "";
310     }
311   else
312     *namep = sym->dsfile.name + VT (objfile);
313 }
314
315 /* Call PXDB to process our file.
316
317    Approach copied from DDE's "dbgk_run_pxdb".  Note: we
318    don't check for BSD location of pxdb, nor for existence
319    of pxdb itself, etc.
320
321    NOTE: uses system function and string functions directly.
322
323    Return value: 1 if ok, 0 if not */
324 int
325 hpread_call_pxdb (const char *file_name)
326 {
327   char *p;
328   int status;
329   int retval;
330
331   if (file_exists (PXDB_SVR4))
332     {
333       p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
334       strcpy (p, PXDB_SVR4);
335       strcat (p, " ");
336       strcat (p, file_name);
337
338       warning ("File not processed by pxdb--about to process now.\n");
339       status = system (p);
340
341       retval = (status == 0);
342     }
343   else
344     {
345       warning ("pxdb not found at standard location: /opt/langtools/bin\ngdb will not be able to debug %s.\nPlease install pxdb at the above location and then restart gdb.\nYou can also run pxdb on %s with the command\n\"pxdb %s\" and then restart gdb.", file_name, file_name, file_name);
346
347       retval = 0;
348     }
349   return retval;
350 }                               /* hpread_call_pxdb */
351 \f
352
353 /* Return 1 if the file turns out to need pre-processing
354    by PXDB, and we have thus called PXDB to do this processing
355    and the file therefore needs to be re-loaded.  Otherwise
356    return 0. */
357 int
358 hpread_pxdb_needed (bfd *sym_bfd)
359 {
360   asection *pinfo_section, *debug_section, *header_section;
361   unsigned int do_pxdb;
362   char *buf;
363   bfd_size_type header_section_size;
364
365   unsigned long tmp;
366   unsigned int pxdbed;
367
368   header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
369   if (!header_section)
370     {
371       return 0;                 /* No header at all, can't recover... */
372     }
373
374   debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
375   pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
376
377   if (pinfo_section && !debug_section)
378     {
379       /* Debug info with DOC, has different header format. 
380          this only happens if the file was pxdbed and compiled optimized
381          otherwise the PINFO section is not there. */
382       header_section_size = bfd_section_size (objfile->obfd, header_section);
383
384       if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
385         {
386           buf = alloca (sizeof (DOC_info_PXDB_header));
387
388           if (!bfd_get_section_contents (sym_bfd,
389                                          header_section,
390                                          buf, 0,
391                                          header_section_size))
392             error ("bfd_get_section_contents\n");
393
394           tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
395           pxdbed = (tmp >> 31) & 0x1;
396
397           if (!pxdbed)
398             error ("file debug header info invalid\n");
399           do_pxdb = 0;
400         }
401
402       else
403         error ("invalid $HEADER$ size in executable \n");
404     }
405
406   else
407     {
408
409       /* this can be three different cases:
410          1. pxdbed and not doc
411          - DEBUG and HEADER sections are there
412          - header is PXDB_header type
413          - pxdbed flag is set to 1
414
415          2. not pxdbed and doc
416          - DEBUG and HEADER  sections are there
417          - header is DOC_info_header type
418          - pxdbed flag is set to 0
419
420          3. not pxdbed and not doc
421          - DEBUG and HEADER sections are there
422          - header is XDB_header type
423          - pxdbed flag is set to 0
424
425          NOTE: the pxdbed flag is meaningful also in the not
426          already pxdb processed version of the header,
427          because in case on non-already processed by pxdb files
428          that same bit in the header would be always zero.
429          Why? Because the bit is the leftmost bit of a word
430          which contains a 'length' which is always a positive value
431          so that bit is never set to 1 (otherwise it would be negative)
432
433          Given the above, we have two choices : either we ignore the
434          size of the header itself and just look at the pxdbed field,
435          or we check the size and then we (for safety and paranoia related
436          issues) check the bit.
437          The first solution is used by DDE, the second by PXDB itself.
438          I am using the second one here, because I already wrote it,
439          and it is the end of a long day.
440          Also, using the first approach would still involve size issues
441          because we need to read in the contents of the header section, and
442          give the correct amount of stuff we want to read to the
443          get_bfd_section_contents function.  */
444
445       /* decide which case depending on the size of the header section.
446          The size is as defined in hp-symtab.h  */
447
448       header_section_size = bfd_section_size (objfile->obfd, header_section);
449
450       if (header_section_size == (bfd_size_type) sizeof (PXDB_header))  /* pxdb and not doc */
451         {
452
453           buf = alloca (sizeof (PXDB_header));
454           if (!bfd_get_section_contents (sym_bfd,
455                                          header_section,
456                                          buf, 0,
457                                          header_section_size))
458             error ("bfd_get_section_contents\n");
459
460           tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
461           pxdbed = (tmp >> 31) & 0x1;
462
463           if (pxdbed)
464             do_pxdb = 0;
465           else
466             error ("file debug header invalid\n");
467         }
468       else                      /*not pxdbed and doc OR not pxdbed and non doc */
469         do_pxdb = 1;
470     }
471
472   if (do_pxdb)
473     {
474       return 1;
475     }
476   else
477     {
478       return 0;
479     }
480 }                               /* hpread_pxdb_needed */
481
482 #endif
483
484 /* Check whether the file needs to be preprocessed by pxdb. 
485    If so, call pxdb. */
486
487 void
488 do_pxdb (bfd *sym_bfd)
489 {
490   /* The following code is HP-specific.  The "right" way of
491      doing this is unknown, but we bet would involve a target-
492      specific pre-file-load check using a generic mechanism. */
493
494   /* This code will not be executed if the file is not in SOM
495      format (i.e. if compiled with gcc) */
496   if (hpread_pxdb_needed (sym_bfd))
497     {
498       /*This file has not been pre-processed. Preprocess now */
499
500       if (hpread_call_pxdb (sym_bfd->filename))
501         {
502           /* The call above has changed the on-disk file, 
503              we can close the file anyway, because the
504              symbols will be reread in when the target is run */
505           bfd_close (sym_bfd);
506         }
507     }
508 }
509 \f
510
511
512 #ifdef QUICK_LOOK_UP
513
514 /* Code to handle quick lookup-tables follows. */
515
516
517 /* Some useful macros */
518 #define VALID_FILE(i)   ((i) < pxdb_header_p->fd_entries)
519 #define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
520 #define VALID_PROC(i)   ((i) < pxdb_header_p->pd_entries)
521 #define VALID_CLASS(i)  ((i) < pxdb_header_p->cd_entries)
522
523 #define FILE_START(i)    (qFD[i].adrStart)
524 #define MODULE_START(i) (qMD[i].adrStart)
525 #define PROC_START(i)    (qPD[i].adrStart)
526
527 #define FILE_END(i)   (qFD[i].adrEnd)
528 #define MODULE_END(i) (qMD[i].adrEnd)
529 #define PROC_END(i)   (qPD[i].adrEnd)
530
531 #define FILE_ISYM(i)   (qFD[i].isym)
532 #define MODULE_ISYM(i) (qMD[i].isym)
533 #define PROC_ISYM(i)   (qPD[i].isym)
534
535 #define VALID_CURR_FILE    (curr_fd < pxdb_header_p->fd_entries)
536 #define VALID_CURR_MODULE  (curr_md < pxdb_header_p->md_entries)
537 #define VALID_CURR_PROC    (curr_pd < pxdb_header_p->pd_entries)
538 #define VALID_CURR_CLASS   (curr_cd < pxdb_header_p->cd_entries)
539
540 #define CURR_FILE_START     (qFD[curr_fd].adrStart)
541 #define CURR_MODULE_START   (qMD[curr_md].adrStart)
542 #define CURR_PROC_START     (qPD[curr_pd].adrStart)
543
544 #define CURR_FILE_END    (qFD[curr_fd].adrEnd)
545 #define CURR_MODULE_END  (qMD[curr_md].adrEnd)
546 #define CURR_PROC_END    (qPD[curr_pd].adrEnd)
547
548 #define CURR_FILE_ISYM    (qFD[curr_fd].isym)
549 #define CURR_MODULE_ISYM  (qMD[curr_md].isym)
550 #define CURR_PROC_ISYM    (qPD[curr_pd].isym)
551
552 #define TELL_OBJFILE                                      \
553             do {                                          \
554                if( !told_objfile ) {                      \
555                    told_objfile = 1;                      \
556                    warning ("\nIn object file \"%s\":\n", \
557                             objfile->name);               \
558                }                                          \
559             } while (0)
560 \f
561
562
563 /* Keeping track of the start/end symbol table (LNTT) indices of
564    psymtabs created so far */
565
566 typedef struct
567 {
568   int start;
569   int end;
570 }
571 pst_syms_struct;
572
573 static pst_syms_struct *pst_syms_array = 0;
574
575 static int pst_syms_count = 0;
576 static int pst_syms_size = 0;
577
578 /* used by the TELL_OBJFILE macro */
579 static int told_objfile = 0;
580
581 /* Set up psymtab symbol index stuff */
582 static void
583 init_pst_syms (void)
584 {
585   pst_syms_count = 0;
586   pst_syms_size = 20;
587   pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
588 }
589
590 /* Clean up psymtab symbol index stuff */
591 static void
592 clear_pst_syms (void)
593 {
594   pst_syms_count = 0;
595   pst_syms_size = 0;
596   xfree (pst_syms_array);
597   pst_syms_array = 0;
598 }
599
600 /* Add information about latest psymtab to symbol index table */
601 static void
602 record_pst_syms (int start_sym, int end_sym)
603 {
604   if (++pst_syms_count > pst_syms_size)
605     {
606       pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
607                               2 * pst_syms_size * sizeof (pst_syms_struct));
608       pst_syms_size *= 2;
609     }
610   pst_syms_array[pst_syms_count - 1].start = start_sym;
611   pst_syms_array[pst_syms_count - 1].end = end_sym;
612 }
613
614 /* Find a suitable symbol table index which can serve as the upper
615    bound of a psymtab that starts at INDEX
616
617    This scans backwards in the psymtab symbol index table to find a
618    "hole" in which the given index can fit.  This is a heuristic!!
619    We don't search the entire table to check for multiple holes,
620    we don't care about overlaps, etc. 
621
622    Return 0 => not found */
623 static int
624 find_next_pst_start (int index)
625 {
626   int i;
627
628   for (i = pst_syms_count - 1; i >= 0; i--)
629     if (pst_syms_array[i].end <= index)
630       return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
631
632   if (pst_syms_array[0].start > index)
633     return pst_syms_array[0].start - 1;
634
635   return 0;
636 }
637 \f
638
639
640 /* Utility functions to find the ending symbol index for a psymtab */
641
642 /* Find the next file entry that begins beyond INDEX, and return
643    its starting symbol index - 1.
644    QFD is the file table, CURR_FD is the file entry from where to start,
645    PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
646
647    Return 0 => not found */
648 static int
649 find_next_file_isym (int index, quick_file_entry *qFD, int curr_fd,
650                      PXDB_header_ptr pxdb_header_p)
651 {
652   while (VALID_CURR_FILE)
653     {
654       if (CURR_FILE_ISYM >= index)
655         return CURR_FILE_ISYM - 1;
656       curr_fd++;
657     }
658   return 0;
659 }
660
661 /* Find the next procedure entry that begins beyond INDEX, and return
662    its starting symbol index - 1.
663    QPD is the procedure table, CURR_PD is the proc entry from where to start,
664    PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
665
666    Return 0 => not found */
667 static int
668 find_next_proc_isym (int index, quick_procedure_entry *qPD, int curr_pd,
669                      PXDB_header_ptr pxdb_header_p)
670 {
671   while (VALID_CURR_PROC)
672     {
673       if (CURR_PROC_ISYM >= index)
674         return CURR_PROC_ISYM - 1;
675       curr_pd++;
676     }
677   return 0;
678 }
679
680 /* Find the next module entry that begins beyond INDEX, and return
681    its starting symbol index - 1.
682    QMD is the module table, CURR_MD is the modue entry from where to start,
683    PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
684
685    Return 0 => not found */
686 static int
687 find_next_module_isym (int index, quick_module_entry *qMD, int curr_md,
688                        PXDB_header_ptr pxdb_header_p)
689 {
690   while (VALID_CURR_MODULE)
691     {
692       if (CURR_MODULE_ISYM >= index)
693         return CURR_MODULE_ISYM - 1;
694       curr_md++;
695     }
696   return 0;
697 }
698
699 /* Scan and record partial symbols for all functions starting from index
700    pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
701    Other parameters are explained in comments below. */
702
703 /* This used to be inline in hpread_quick_traverse, but now that we do
704    essentially the same thing for two different cases (modules and
705    module-less files), it's better organized in a separate routine,
706    although it does take lots of arguments.  pai/1997-10-08
707    
708    CURR_PD_P is the pointer to the current proc index. QPD is the
709    procedure quick lookup table.  MAX_PROCS is the number of entries
710    in the proc. table.  START_ADR is the beginning of the code range
711    for the current psymtab.  end_adr is the end of the code range for
712    the current psymtab.  PST is the current psymtab.  VT_bits is
713    a pointer to the strings table of SOM debug space.  OBJFILE is
714    the current object file. */
715
716 static int
717 scan_procs (int *curr_pd_p, quick_procedure_entry *qPD, int max_procs,
718             CORE_ADDR start_adr, CORE_ADDR end_adr, struct partial_symtab *pst,
719             char *vt_bits, struct objfile *objfile)
720 {
721   union dnttentry *dn_bufp;
722   int symbol_count = 0;         /* Total number of symbols in this psymtab */
723   int curr_pd = *curr_pd_p;     /* Convenience variable -- avoid dereferencing pointer all the time */
724
725 #ifdef DUMPING
726   /* Turn this on for lots of debugging information in this routine */
727   static int dumping = 0;
728 #endif
729
730 #ifdef DUMPING
731   if (dumping)
732     {
733       printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
734     }
735 #endif
736
737   while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
738     {
739
740       char *rtn_name;           /* mangled name */
741       char *rtn_dem_name;       /* qualified demangled name */
742       char *class_name;
743       int class;
744
745       if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
746           vt_bits[(long) qPD[curr_pd].sbAlias])         /* not a null string */
747         {
748           /* Get mangled name for the procedure, and demangle it */
749           rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
750           rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
751         }
752       else
753         {
754           rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
755           rtn_dem_name = NULL;
756         }
757
758       /* Hack to get around HP C/C++ compilers' insistence on providing
759          "_MAIN_" as an alternate name for "main" */
760       if ((strcmp (rtn_name, "_MAIN_") == 0) &&
761           (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
762         rtn_dem_name = rtn_name = main_string;
763
764 #ifdef DUMPING
765       if (dumping)
766         {
767           printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
768         }
769 #endif
770
771       /* Check for module-spanning routines. */
772       if (CURR_PROC_END > end_adr)
773         {
774           TELL_OBJFILE;
775           warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
776         }
777
778       /* Add this routine symbol to the list in the objfile. 
779          Unfortunately we have to go to the LNTT to determine the
780          correct list to put it on. An alternative (which the
781          code used to do) would be to not check and always throw
782          it on the "static" list. But if we go that route, then
783          symbol_lookup() needs to be tweaked a bit to account
784          for the fact that the function might not be found on
785          the correct list in the psymtab. - RT */
786       dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
787       if (dn_bufp->dfunc.global)
788         add_psymbol_with_dem_name_to_list (rtn_name,
789                                            strlen (rtn_name),
790                                            rtn_dem_name,
791                                            strlen (rtn_dem_name),
792                                            VAR_DOMAIN,
793                                            LOC_BLOCK,   /* "I am a routine"        */
794                                            &objfile->global_psymbols,
795                                            (qPD[curr_pd].adrStart +     /* Starting address of rtn */
796                                  ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
797                                            0,   /* core addr?? */
798                       trans_lang ((enum hp_language) qPD[curr_pd].language),
799                                            objfile);
800       else
801         add_psymbol_with_dem_name_to_list (rtn_name,
802                                            strlen (rtn_name),
803                                            rtn_dem_name,
804                                            strlen (rtn_dem_name),
805                                            VAR_DOMAIN,
806                                            LOC_BLOCK,   /* "I am a routine"        */
807                                            &objfile->static_psymbols,
808                                            (qPD[curr_pd].adrStart +     /* Starting address of rtn */
809                                  ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))),
810                                            0,   /* core addr?? */
811                       trans_lang ((enum hp_language) qPD[curr_pd].language),
812                                            objfile);
813
814       symbol_count++;
815       *curr_pd_p = ++curr_pd;   /* bump up count & reflect in caller */
816     }                           /* loop over procedures */
817
818 #ifdef DUMPING
819   if (dumping)
820     {
821       if (symbol_count == 0)
822         printf ("Scan_procs: no symbols found!\n");
823     }
824 #endif
825
826   return symbol_count;
827 }
828
829
830 /* Traverse the quick look-up tables, building a set of psymtabs.
831
832    This constructs a psymtab for modules and files in the quick lookup
833    tables.
834
835    Mostly, modules correspond to compilation units, so we try to
836    create psymtabs that correspond to modules; however, in some cases
837    a file can result in a compiled object which does not have a module
838    entry for it, so in such cases we create a psymtab for the file.  */
839
840 int
841 hpread_quick_traverse (struct objfile *objfile, char *gntt_bits,
842                        char *vt_bits, PXDB_header_ptr pxdb_header_p)
843 {
844   struct partial_symtab *pst;
845
846   char *addr;
847
848   quick_procedure_entry *qPD;
849   quick_file_entry *qFD;
850   quick_module_entry *qMD;
851   quick_class_entry *qCD;
852
853   int idx;
854   int i;
855   CORE_ADDR start_adr;          /* current psymtab's starting code addr   */
856   CORE_ADDR end_adr;            /* current psymtab's ending code addr     */
857   CORE_ADDR next_mod_adr;       /* next module's starting code addr    */
858   int curr_pd;                  /* current procedure */
859   int curr_fd;                  /* current file      */
860   int curr_md;                  /* current module    */
861   int start_sym;                /* current psymtab's starting symbol index */
862   int end_sym;                  /* current psymtab's ending symbol index   */
863   int max_LNTT_sym_index;
864   int syms_in_pst;
865   B_TYPE *class_entered;
866
867   struct partial_symbol **global_syms;  /* We'll be filling in the "global"   */
868   struct partial_symbol **static_syms;  /* and "static" tables in the objfile
869                                            as we go, so we need a pair of     
870                                            current pointers. */
871
872 #ifdef DUMPING
873   /* Turn this on for lots of debugging information in this routine.
874      You get a blow-by-blow account of quick lookup table reading */
875   static int dumping = 0;
876 #endif
877
878   pst = (struct partial_symtab *) 0;
879
880   /* Clear out some globals */
881   init_pst_syms ();
882   told_objfile = 0;
883
884   /* Demangling style -- if EDG style already set, don't change it,
885      as HP style causes some problems with the KAI EDG compiler */
886   if (current_demangling_style != edg_demangling)
887     {
888       /* Otherwise, ensure that we are using HP style demangling */
889       set_demangling_style (HP_DEMANGLING_STYLE_STRING);
890     }
891
892   /* First we need to find the starting points of the quick
893      look-up tables in the GNTT. */
894
895   addr = gntt_bits;
896
897   qPD = (quick_procedure_entry_ptr) addr;
898   addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
899
900 #ifdef DUMPING
901   if (dumping)
902     {
903       printf ("\n Printing routines as we see them\n");
904       for (i = 0; VALID_PROC (i); i++)
905         {
906           idx = (long) qPD[i].sbProc;
907           printf ("%s %x..%x\n", &vt_bits[idx],
908                   (int) PROC_START (i),
909                   (int) PROC_END (i));
910         }
911     }
912 #endif
913
914   qFD = (quick_file_entry_ptr) addr;
915   addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
916
917 #ifdef DUMPING
918   if (dumping)
919     {
920       printf ("\n Printing files as we see them\n");
921       for (i = 0; VALID_FILE (i); i++)
922         {
923           idx = (long) qFD[i].sbFile;
924           printf ("%s %x..%x\n", &vt_bits[idx],
925                   (int) FILE_START (i),
926                   (int) FILE_END (i));
927         }
928     }
929 #endif
930
931   qMD = (quick_module_entry_ptr) addr;
932   addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
933
934 #ifdef DUMPING
935   if (dumping)
936     {
937       printf ("\n Printing modules as we see them\n");
938       for (i = 0; i < pxdb_header_p->md_entries; i++)
939         {
940           idx = (long) qMD[i].sbMod;
941           printf ("%s\n", &vt_bits[idx]);
942         }
943     }
944 #endif
945
946   qCD = (quick_class_entry_ptr) addr;
947   addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
948
949 #ifdef DUMPING
950   if (dumping)
951     {
952       printf ("\n Printing classes as we see them\n");
953       for (i = 0; VALID_CLASS (i); i++)
954         {
955           idx = (long) qCD[i].sbClass;
956           printf ("%s\n", &vt_bits[idx]);
957         }
958
959       printf ("\n Done with dump, on to build!\n");
960     }
961 #endif
962
963   /* We need this index only while hp-symtab-read.c expects
964      a byte offset to the end of the LNTT entries for a given
965      psymtab.  Thus the need for it should go away someday.
966
967      When it goes away, then we won't have any need to load the
968      LNTT from the objfile at psymtab-time, and start-up will be
969      faster.  To make that work, we'll need some way to create
970      a null pst for the "globals" pseudo-module. */
971   max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
972
973   /* Scan the module descriptors and make a psymtab for each.
974
975      We know the MDs, FDs and the PDs are in order by starting
976      address.  We use that fact to traverse all three arrays in
977      parallel, knowing when the next PD is in a new file
978      and we need to create a new psymtab. */
979   curr_pd = 0;                  /* Current procedure entry */
980   curr_fd = 0;                  /* Current file entry */
981   curr_md = 0;                  /* Current module entry */
982
983   start_adr = 0;                /* Current psymtab code range */
984   end_adr = 0;
985
986   start_sym = 0;                /* Current psymtab symbol range */
987   end_sym = 0;
988
989   syms_in_pst = 0;              /* Symbol count for psymtab */
990
991   /* Psts actually just have pointers into the objfile's
992      symbol table, not their own symbol tables. */
993   global_syms = objfile->global_psymbols.list;
994   static_syms = objfile->static_psymbols.list;
995
996
997   /* First skip over pseudo-entries with address 0.  These represent inlined
998      routines and abstract (uninstantiated) template routines.
999      FIXME: These should be read in and available -- even if we can't set
1000      breakpoints, etc., there's some information that can be presented
1001      to the user. pai/1997-10-08  */
1002
1003   while (VALID_CURR_PROC && (CURR_PROC_START == 0))
1004     curr_pd++;
1005
1006   /* Loop over files, modules, and procedures in code address order. Each
1007      time we enter an iteration of this loop, curr_pd points to the first
1008      unprocessed procedure, curr_fd points to the first unprocessed file, and
1009      curr_md to the first unprocessed module.  Each iteration of this loop
1010      updates these as required -- any or all of them may be bumpd up
1011      each time around.  When we exit this loop, we are done with all files
1012      and modules in the tables -- there may still be some procedures, however.
1013
1014      Note: This code used to loop only over module entries, under the assumption
1015      that files can occur via inclusions and are thus unreliable, while a
1016      compiled object always corresponds to a module.  With CTTI in the HP aCC
1017      compiler, it turns out that compiled objects may have only files and no
1018      modules; so we have to loop over files and modules, creating psymtabs for
1019      either as appropriate.  Unfortunately there are some problems (notably:
1020      1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
1021      to the ending symbol indices of a module or a file) which make it quite hard
1022      to do this correctly.  Currently it uses a bunch of heuristics to start and
1023      end psymtabs; they seem to work well with most objects generated by aCC, but
1024      who knows when that will change...   */
1025
1026   while (VALID_CURR_FILE || VALID_CURR_MODULE)
1027     {
1028
1029       char *mod_name_string = NULL;
1030       char *full_name_string;
1031
1032       /* First check for modules like "version.c", which have no code
1033          in them but still have qMD entries.  They also have no qFD or
1034          qPD entries.  Their start address is -1 and their end address
1035          is 0.  */
1036       if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
1037         {
1038
1039           mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1040
1041 #ifdef DUMPING
1042           if (dumping)
1043             printf ("Module with data only %s\n", mod_name_string);
1044 #endif
1045
1046           /* We'll skip the rest (it makes error-checking easier), and
1047              just make an empty pst.  Right now empty psts are not put
1048              in the pst chain, so all this is for naught, but later it
1049              might help.  */
1050
1051           pst = hpread_start_psymtab (objfile,
1052                                       mod_name_string,
1053                                       CURR_MODULE_START,        /* Low text address: bogus! */
1054                        (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
1055           /* ldsymoff */
1056                                       global_syms,
1057                                       static_syms);
1058
1059           pst = hpread_end_psymtab (pst,
1060                                     NULL,       /* psymtab_include_list */
1061                                     0,  /* includes_used        */
1062                                   end_sym * sizeof (struct dntt_type_block),
1063           /* byte index in LNTT of end 
1064              = capping symbol offset  
1065              = LDSYMOFF of nextfile */
1066                                     0,  /* text high            */
1067                                     NULL,       /* dependency_list      */
1068                                     0);         /* dependencies_used    */
1069
1070           global_syms = objfile->global_psymbols.next;
1071           static_syms = objfile->static_psymbols.next;
1072
1073           curr_md++;
1074         }
1075       else if (VALID_CURR_MODULE &&
1076                ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
1077                 (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
1078         {
1079           TELL_OBJFILE;
1080           warning ("Module \"%s\" [0x%s] has non-standard addresses.  It starts at 0x%s, ends at 0x%s, and will be skipped.",
1081                    mod_name_string, paddr_nz (curr_md), paddr_nz (start_adr), paddr_nz (end_adr));
1082           /* On to next module */
1083           curr_md++;
1084         }
1085       else
1086         {
1087           /* First check if we are looking at a file with code in it
1088              that does not overlap the current module's code range */
1089
1090           if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
1091             {
1092
1093               /* Looking at file not corresponding to any module,
1094                  create a psymtab for it */
1095               full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1096               start_adr = CURR_FILE_START;
1097               end_adr = CURR_FILE_END;
1098               start_sym = CURR_FILE_ISYM;
1099
1100               /* Check if there are any procedures not handled until now, that
1101                  begin before the start address of this file, and if so, adjust
1102                  this module's start address to include them.  This handles routines that
1103                  are in between file or module ranges for some reason (probably
1104                  indicates a compiler bug */
1105
1106               if (CURR_PROC_START < start_adr)
1107                 {
1108                   TELL_OBJFILE;
1109                   warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1110                            &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1111                   start_adr = CURR_PROC_START;
1112                   if (CURR_PROC_ISYM < start_sym)
1113                     start_sym = CURR_PROC_ISYM;
1114                 }
1115
1116               /* Sometimes (compiler bug -- COBOL) the module end address is higher
1117                  than the start address of the next module, so check for that and
1118                  adjust accordingly */
1119
1120               if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1121                 {
1122                   TELL_OBJFILE;
1123                   warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1124                            full_name_string, curr_fd);
1125                   end_adr = FILE_START (curr_fd + 1) - 1;       /* Is -4 (or -8 for 64-bit) better? */
1126                 }
1127               if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
1128                 {
1129                   TELL_OBJFILE;
1130                   warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1131                            full_name_string, curr_fd);
1132                   end_adr = CURR_MODULE_START - 1;      /* Is -4 (or -8 for 64-bit) better? */
1133                 }
1134
1135
1136 #ifdef DUMPING
1137               if (dumping)
1138                 {
1139                   printf ("Make new psymtab for file %s (%x to %x).\n",
1140                           full_name_string, start_adr, end_adr);
1141                 }
1142 #endif
1143               /* Create the basic psymtab, connecting it in the list
1144                  for this objfile and pointing its symbol entries
1145                  to the current end of the symbol areas in the objfile.
1146
1147                  The "ldsymoff" parameter is the byte offset in the LNTT
1148                  of the first symbol in this file.  Some day we should
1149                  turn this into an index (fix in hp-symtab-read.c as well).
1150                  And it's not even the right byte offset, as we're using
1151                  the size of a union! FIXME!  */
1152               pst = hpread_start_psymtab (objfile,
1153                                           full_name_string,
1154                                           start_adr,    /* Low text address */
1155                               (start_sym * sizeof (struct dntt_type_block)),
1156               /* ldsymoff */
1157                                           global_syms,
1158                                           static_syms);
1159
1160               /* Set up to only enter each class referenced in this module once.  */
1161               class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
1162               B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1163
1164               /* Scan the procedure descriptors for procedures in the current
1165                  file, based on the starting addresses. */
1166
1167               syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1168                                         start_adr, end_adr, pst, vt_bits, objfile);
1169
1170               /* Get ending symbol offset */
1171
1172               end_sym = 0;
1173               /* First check for starting index before previous psymtab */
1174               if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1175                 {
1176                   end_sym = find_next_pst_start (start_sym);
1177                 }
1178               /* Look for next start index of a file or module, or procedure */
1179               if (!end_sym)
1180                 {
1181                   int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1182                   int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
1183                   int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1184
1185                   if (next_file_isym && next_module_isym)
1186                     {
1187                       /* pick lower of next file or module start index */
1188                       end_sym = min (next_file_isym, next_module_isym);
1189                     }
1190                   else
1191                     {
1192                       /* one of them is zero, pick the other */
1193                       end_sym = max (next_file_isym, next_module_isym);
1194                     }
1195
1196                   /* As a precaution, check next procedure index too */
1197                   if (!end_sym)
1198                     end_sym = next_proc_isym;
1199                   else
1200                     end_sym = min (end_sym, next_proc_isym);
1201                 }
1202
1203               /* Couldn't find procedure, file, or module, use globals as default */
1204               if (!end_sym)
1205                 end_sym = pxdb_header_p->globals;
1206
1207 #ifdef DUMPING
1208               if (dumping)
1209                 {
1210                   printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1211                 }
1212 #endif
1213
1214               pst = hpread_end_psymtab (pst,
1215                                         NULL,   /* psymtab_include_list */
1216                                         0,      /* includes_used        */
1217                                   end_sym * sizeof (struct dntt_type_block),
1218               /* byte index in LNTT of end 
1219                  = capping symbol offset   
1220                  = LDSYMOFF of nextfile */
1221                                         end_adr,        /* text high */
1222                                         NULL,   /* dependency_list */
1223                                         0);     /* dependencies_used */
1224
1225               record_pst_syms (start_sym, end_sym);
1226
1227               if (NULL == pst)
1228                 warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
1229
1230 #ifdef DUMPING
1231               if (dumping)
1232                 {
1233                   printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1234                           full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1235                 }
1236 #endif
1237               /* Prepare for the next psymtab. */
1238               global_syms = objfile->global_psymbols.next;
1239               static_syms = objfile->static_psymbols.next;
1240               xfree (class_entered);
1241
1242               curr_fd++;
1243             }                   /* Psymtab for file */
1244           else
1245             {
1246               /* We have a module for which we create a psymtab */
1247
1248               mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1249
1250               /* We will include the code ranges of any files that happen to
1251                  overlap with this module */
1252
1253               /* So, first pick the lower of the file's and module's start addresses */
1254               start_adr = CURR_MODULE_START;
1255               if (VALID_CURR_FILE)
1256                 {
1257                   if (CURR_FILE_START < CURR_MODULE_START)
1258                     {
1259                       TELL_OBJFILE;
1260                       warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1261                                &vt_bits[(long) qFD[curr_fd].sbFile],
1262                                curr_fd, mod_name_string);
1263
1264                       start_adr = CURR_FILE_START;
1265                     }
1266                 }
1267
1268               /* Also pick the lower of the file's and the module's start symbol indices */
1269               start_sym = CURR_MODULE_ISYM;
1270               if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1271                 start_sym = CURR_FILE_ISYM;
1272
1273               /* For the end address, we scan through the files till we find one
1274                  that overlaps the current module but ends beyond it; if no such file exists we
1275                  simply use the module's start address.  
1276                  (Note, if file entries themselves overlap
1277                  we take the longest overlapping extension beyond the end of the module...)
1278                  We assume that modules never overlap. */
1279
1280               end_adr = CURR_MODULE_END;
1281
1282               if (VALID_CURR_FILE)
1283                 {
1284                   while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1285                     {
1286
1287 #ifdef DUMPING
1288                       if (dumping)
1289                         printf ("Maybe skipping file %s which overlaps with module %s\n",
1290                                 &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1291 #endif
1292                       if (CURR_FILE_END > end_adr)
1293                         {
1294                           TELL_OBJFILE;
1295                           warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1296                                    &vt_bits[(long) qFD[curr_fd].sbFile],
1297                                    curr_fd, mod_name_string);
1298                           end_adr = CURR_FILE_END;
1299                         }
1300                       curr_fd++;
1301                     }
1302                   curr_fd--;    /* back up after going too far */
1303                 }
1304
1305               /* Sometimes (compiler bug -- COBOL) the module end address is higher
1306                  than the start address of the next module, so check for that and
1307                  adjust accordingly */
1308
1309               if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1310                 {
1311                   TELL_OBJFILE;
1312                   warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1313                            mod_name_string, curr_md);
1314                   end_adr = MODULE_START (curr_md + 1) - 1;     /* Is -4 (or -8 for 64-bit) better? */
1315                 }
1316               if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1317                 {
1318                   TELL_OBJFILE;
1319                   warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1320                            mod_name_string, curr_md);
1321                   end_adr = FILE_START (curr_fd + 1) - 1;       /* Is -4 (or -8 for 64-bit) better? */
1322                 }
1323
1324               /* Use one file to get the full name for the module.  This
1325                  situation can arise if there is executable code in a #include
1326                  file.  Each file with code in it gets a qFD.  Files which don't
1327                  contribute code don't get a qFD, even if they include files
1328                  which do, e.g.: 
1329
1330                  body.c:                    rtn.h:
1331                  int x;                     int main() {
1332                  #include "rtn.h"               return x;
1333                  }
1334
1335                  There will a qFD for "rtn.h",and a qMD for "body.c",
1336                  but no qMD for "rtn.h" or qFD for "body.c"!
1337
1338                  We pick the name of the last file to overlap with this
1339                  module.  C convention is to put include files first.  In a
1340                  perfect world, we could check names and use the file whose full
1341                  path name ends with the module name. */
1342
1343               if (VALID_CURR_FILE)
1344                 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1345               else
1346                 full_name_string = mod_name_string;
1347
1348               /* Check if there are any procedures not handled until now, that
1349                  begin before the start address we have now, and if so, adjust
1350                  this psymtab's start address to include them.  This handles routines that
1351                  are in between file or module ranges for some reason (probably
1352                  indicates a compiler bug */
1353
1354               if (CURR_PROC_START < start_adr)
1355                 {
1356                   TELL_OBJFILE;
1357                   warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1358                            &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1359                   start_adr = CURR_PROC_START;
1360                   if (CURR_PROC_ISYM < start_sym)
1361                     start_sym = CURR_PROC_ISYM;
1362                 }
1363
1364 #ifdef DUMPING
1365               if (dumping)
1366                 {
1367                   printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1368                      mod_name_string, start_adr, end_adr, full_name_string);
1369                 }
1370 #endif
1371               /* Create the basic psymtab, connecting it in the list
1372                  for this objfile and pointing its symbol entries
1373                  to the current end of the symbol areas in the objfile.
1374
1375                  The "ldsymoff" parameter is the byte offset in the LNTT
1376                  of the first symbol in this file.  Some day we should
1377                  turn this into an index (fix in hp-symtab-read.c as well).
1378                  And it's not even the right byte offset, as we're using
1379                  the size of a union! FIXME!  */
1380               pst = hpread_start_psymtab (objfile,
1381                                           full_name_string,
1382                                           start_adr,    /* Low text address */
1383                               (start_sym * sizeof (struct dntt_type_block)),
1384               /* ldsymoff */
1385                                           global_syms,
1386                                           static_syms);
1387
1388               /* Set up to only enter each class referenced in this module once.  */
1389               class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
1390               B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1391
1392               /* Scan the procedure descriptors for procedures in the current
1393                  module, based on the starting addresses. */
1394
1395               syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1396                                         start_adr, end_adr, pst, vt_bits, objfile);
1397
1398               /* Get ending symbol offset */
1399
1400               end_sym = 0;
1401               /* First check for starting index before previous psymtab */
1402               if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1403                 {
1404                   end_sym = find_next_pst_start (start_sym);
1405                 }
1406               /* Look for next start index of a file or module, or procedure */
1407               if (!end_sym)
1408                 {
1409                   int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1410                   int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1411                   int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1412
1413                   if (next_file_isym && next_module_isym)
1414                     {
1415                       /* pick lower of next file or module start index */
1416                       end_sym = min (next_file_isym, next_module_isym);
1417                     }
1418                   else
1419                     {
1420                       /* one of them is zero, pick the other */
1421                       end_sym = max (next_file_isym, next_module_isym);
1422                     }
1423
1424                   /* As a precaution, check next procedure index too */
1425                   if (!end_sym)
1426                     end_sym = next_proc_isym;
1427                   else
1428                     end_sym = min (end_sym, next_proc_isym);
1429                 }
1430
1431               /* Couldn't find procedure, file, or module, use globals as default */
1432               if (!end_sym)
1433                 end_sym = pxdb_header_p->globals;
1434
1435 #ifdef DUMPING
1436               if (dumping)
1437                 {
1438                   printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1439                 }
1440 #endif
1441
1442               pst = hpread_end_psymtab (pst,
1443                                         NULL,   /* psymtab_include_list */
1444                                         0,      /* includes_used        */
1445                                   end_sym * sizeof (struct dntt_type_block),
1446               /* byte index in LNTT of end 
1447                  = capping symbol offset   
1448                  = LDSYMOFF of nextfile */
1449                                         end_adr,        /* text high */
1450                                         NULL,   /* dependency_list      */
1451                                         0);     /* dependencies_used    */
1452
1453               record_pst_syms (start_sym, end_sym);
1454
1455               if (NULL == pst)
1456                 warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1457
1458 #ifdef DUMPING
1459               if (dumping)
1460                 {
1461                   printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1462                           mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1463                 }
1464 #endif
1465
1466               /* Prepare for the next psymtab. */
1467               global_syms = objfile->global_psymbols.next;
1468               static_syms = objfile->static_psymbols.next;
1469               xfree (class_entered);
1470
1471               curr_md++;
1472               curr_fd++;
1473             }                   /* psymtab for module */
1474         }                       /* psymtab for non-bogus file or module */
1475     }                           /* End of while loop over all files & modules */
1476
1477   /* There may be some routines after all files and modules -- these will get
1478      inserted in a separate new module of their own */
1479   if (VALID_CURR_PROC)
1480     {
1481       start_adr = CURR_PROC_START;
1482       end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1483       TELL_OBJFILE;
1484       warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1485 #ifdef DUMPING
1486       if (dumping)
1487         {
1488           printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1489                   curr_pd, start_adr, end_adr);
1490         }
1491 #endif
1492       pst = hpread_start_psymtab (objfile,
1493                                   "orphans",
1494                                   start_adr,    /* Low text address */
1495                          (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1496       /* ldsymoff */
1497                                   global_syms,
1498                                   static_syms);
1499
1500       scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1501                   start_adr, end_adr, pst, vt_bits, objfile);
1502
1503       pst = hpread_end_psymtab (pst,
1504                                 NULL,   /* psymtab_include_list */
1505                                 0,      /* includes_used */
1506                    pxdb_header_p->globals * sizeof (struct dntt_type_block),
1507       /* byte index in LNTT of end 
1508          = capping symbol offset   
1509          = LDSYMOFF of nextfile */
1510                                 end_adr,        /* text high  */
1511                                 NULL,   /* dependency_list */
1512                                 0);     /* dependencies_used */
1513     }
1514
1515
1516 #ifdef NEVER_NEVER
1517   /* Now build psts for non-module things (in the tail of
1518      the LNTT, after the last END MODULE entry).
1519
1520      If null psts were kept on the chain, this would be
1521      a solution.  FIXME */
1522   pst = hpread_start_psymtab (objfile,
1523                               "globals",
1524                               0,
1525                               (pxdb_header_p->globals
1526                                * sizeof (struct dntt_type_block)),
1527                               objfile->global_psymbols.next,
1528                               objfile->static_psymbols.next);
1529   hpread_end_psymtab (pst,
1530                       NULL, 0,
1531                       (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1532                       0,
1533                       NULL, 0);
1534 #endif
1535
1536   clear_pst_syms ();
1537
1538   return 1;
1539
1540 }                               /* End of hpread_quick_traverse. */
1541 \f
1542
1543 /* Get appropriate header, based on pxdb type. 
1544    Return value: 1 if ok, 0 if not */
1545 int
1546 hpread_get_header (struct objfile *objfile, PXDB_header_ptr pxdb_header_p)
1547 {
1548   asection *pinfo_section, *debug_section, *header_section;
1549
1550 #ifdef DUMPING
1551   /* Turn on for debugging information */
1552   static int dumping = 0;
1553 #endif
1554
1555   header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1556   if (!header_section)
1557     {
1558       /* We don't have either PINFO or DEBUG sections.  But
1559          stuff like "libc.sl" has no debug info.  There's no
1560          need to warn the user of this, as it may be ok. The
1561          caller will figure it out and issue any needed
1562          messages. */
1563 #ifdef DUMPING
1564       if (dumping)
1565         printf ("==No debug info at all for %s.\n", objfile->name);
1566 #endif
1567
1568       return 0;
1569     }
1570
1571   /* We would like either a $DEBUG$ or $PINFO$ section.
1572      Once we know which, we can understand the header
1573      data (which we have defined to suit the more common
1574      $DEBUG$ case). */
1575   debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1576   pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1577   if (debug_section)
1578     {
1579       /* The expected case: normal pxdb header. */
1580       bfd_get_section_contents (objfile->obfd, header_section,
1581                                 pxdb_header_p, 0, sizeof (PXDB_header));
1582
1583       if (!pxdb_header_p->pxdbed)
1584         {
1585           /* This shouldn't happen if we check in "symfile.c". */
1586           return 0;
1587         }                       /* DEBUG section */
1588     }
1589
1590   else if (pinfo_section)
1591     {
1592       /* The DOC case; we need to translate this into a
1593          regular header. */
1594       DOC_info_PXDB_header doc_header;
1595
1596 #ifdef DUMPING
1597       if (dumping)
1598         {
1599           printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1600         }
1601 #endif
1602
1603       bfd_get_section_contents (objfile->obfd,
1604                                 header_section,
1605                                 &doc_header, 0,
1606                                 sizeof (DOC_info_PXDB_header));
1607
1608       if (!doc_header.pxdbed)
1609         {
1610           /* This shouldn't happen if we check in "symfile.c". */
1611           warning ("File \"%s\" not processed by pxdb!", objfile->name);
1612           return 0;
1613         }
1614
1615       /* Copy relevent fields to standard header passed in. */
1616       pxdb_header_p->pd_entries = doc_header.pd_entries;
1617       pxdb_header_p->fd_entries = doc_header.fd_entries;
1618       pxdb_header_p->md_entries = doc_header.md_entries;
1619       pxdb_header_p->pxdbed = doc_header.pxdbed;
1620       pxdb_header_p->bighdr = doc_header.bighdr;
1621       pxdb_header_p->sa_header = doc_header.sa_header;
1622       pxdb_header_p->inlined = doc_header.inlined;
1623       pxdb_header_p->globals = doc_header.globals;
1624       pxdb_header_p->time = doc_header.time;
1625       pxdb_header_p->pg_entries = doc_header.pg_entries;
1626       pxdb_header_p->functions = doc_header.functions;
1627       pxdb_header_p->files = doc_header.files;
1628       pxdb_header_p->cd_entries = doc_header.cd_entries;
1629       pxdb_header_p->aa_entries = doc_header.aa_entries;
1630       pxdb_header_p->oi_entries = doc_header.oi_entries;
1631       pxdb_header_p->version = doc_header.version;
1632     }                           /* PINFO section */
1633
1634   else
1635     {
1636 #ifdef DUMPING
1637       if (dumping)
1638         printf ("==No debug info at all for %s.\n", objfile->name);
1639 #endif
1640
1641       return 0;
1642
1643     }
1644
1645   return 1;
1646 }                               /* End of hpread_get_header */
1647 #endif /* QUICK_LOOK_UP */
1648 \f
1649
1650 /* Initialization for reading native HP C debug symbols from OBJFILE.
1651
1652    Its only purpose in life is to set up the symbol reader's private
1653    per-objfile data structures, and read in the raw contents of the debug
1654    sections (attaching pointers to the debug info into the private data
1655    structures).
1656
1657    Since BFD doesn't know how to read debug symbols in a format-independent
1658    way (and may never do so...), we have to do it ourselves.  Note we may
1659    be called on a file without native HP C debugging symbols.
1660
1661    FIXME, there should be a cleaner peephole into the BFD environment
1662    here. */
1663 void
1664 hpread_symfile_init (struct objfile *objfile)
1665 {
1666   asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1667
1668   /* Allocate struct to keep track of the symfile */
1669   objfile->sym_private =
1670     xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
1671   memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1672
1673   /* We haven't read in any types yet.  */
1674   DNTT_TYPE_VECTOR (objfile) = 0;
1675
1676   /* Read in data from the $GNTT$ subspace.  */
1677   gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1678   if (!gntt_section)
1679     return;
1680
1681   GNTT (objfile)
1682     = obstack_alloc (&objfile->symbol_obstack,
1683                      bfd_section_size (objfile->obfd, gntt_section));
1684
1685   bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1686                          0, bfd_section_size (objfile->obfd, gntt_section));
1687
1688   GNTT_SYMCOUNT (objfile)
1689     = bfd_section_size (objfile->obfd, gntt_section)
1690     / sizeof (struct dntt_type_block);
1691
1692   /* Read in data from the $LNTT$ subspace.   Also keep track of the number
1693      of LNTT symbols.
1694
1695      FIXME: this could be moved into the psymtab-to-symtab expansion
1696      code, and save startup time.  At the moment this data is
1697      still used, though.  We'd need a way to tell hp-symtab-read.c
1698      whether or not to load the LNTT. */
1699   lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1700   if (!lntt_section)
1701     return;
1702
1703   LNTT (objfile)
1704     = obstack_alloc (&objfile->symbol_obstack,
1705                      bfd_section_size (objfile->obfd, lntt_section));
1706
1707   bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1708                          0, bfd_section_size (objfile->obfd, lntt_section));
1709
1710   LNTT_SYMCOUNT (objfile)
1711     = bfd_section_size (objfile->obfd, lntt_section)
1712     / sizeof (struct dntt_type_block);
1713
1714   /* Read in data from the $SLT$ subspace.  $SLT$ contains information
1715      on source line numbers.  */
1716   slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1717   if (!slt_section)
1718     return;
1719
1720   SLT (objfile) =
1721     obstack_alloc (&objfile->symbol_obstack,
1722                    bfd_section_size (objfile->obfd, slt_section));
1723
1724   bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1725                           0, bfd_section_size (objfile->obfd, slt_section));
1726
1727   /* Read in data from the $VT$ subspace.  $VT$ contains things like
1728      names and constants.  Keep track of the number of symbols in the VT.  */
1729   vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1730   if (!vt_section)
1731     return;
1732
1733   VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1734
1735   VT (objfile) =
1736     (char *) obstack_alloc (&objfile->symbol_obstack,
1737                             VT_SIZE (objfile));
1738
1739   bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1740                             0, VT_SIZE (objfile));
1741 }
1742
1743 /* Scan and build partial symbols for a symbol file.
1744
1745    The minimal symbol table (either SOM or HP a.out) has already been
1746    read in; all we need to do is setup partial symbols based on the
1747    native debugging information.
1748
1749    Note that the minimal table is produced by the linker, and has
1750    only global routines in it; the psymtab is based on compiler-
1751    generated debug information and has non-global
1752    routines in it as well as files and class information.
1753
1754    We assume hpread_symfile_init has been called to initialize the
1755    symbol reader's private data structures.
1756
1757    MAINLINE is true if we are reading the main symbol table (as
1758    opposed to a shared lib or dynamically loaded file). */
1759
1760 void
1761 hpread_build_psymtabs (struct objfile *objfile, int mainline)
1762 {
1763
1764 #ifdef DUMPING
1765   /* Turn this on to get debugging output. */
1766   static int dumping = 0;
1767 #endif
1768
1769   char *namestring;
1770   int past_first_source_file = 0;
1771   struct cleanup *old_chain;
1772
1773   int hp_symnum, symcount, i;
1774   int scan_start = 0;
1775
1776   union dnttentry *dn_bufp;
1777   unsigned long valu;
1778   char *p;
1779   int texthigh = 0;
1780   int have_name = 0;
1781
1782   /* Current partial symtab */
1783   struct partial_symtab *pst;
1784
1785   /* List of current psymtab's include files */
1786   char **psymtab_include_list;
1787   int includes_allocated;
1788   int includes_used;
1789
1790   /* Index within current psymtab dependency list */
1791   struct partial_symtab **dependency_list;
1792   int dependencies_used, dependencies_allocated;
1793
1794   /* Just in case the stabs reader left turds lying around.  */
1795   free_pending_blocks ();
1796   make_cleanup (really_free_pendings, 0);
1797
1798   pst = (struct partial_symtab *) 0;
1799
1800   /* We shouldn't use alloca, instead use malloc/free.  Doing so avoids
1801      a number of problems with cross compilation and creating useless holes
1802      in the stack when we have to allocate new entries.  FIXME.  */
1803
1804   includes_allocated = 30;
1805   includes_used = 0;
1806   psymtab_include_list = (char **) alloca (includes_allocated *
1807                                            sizeof (char *));
1808
1809   dependencies_allocated = 30;
1810   dependencies_used = 0;
1811   dependency_list =
1812     (struct partial_symtab **) alloca (dependencies_allocated *
1813                                        sizeof (struct partial_symtab *));
1814
1815   old_chain = make_cleanup_free_objfile (objfile);
1816
1817   last_source_file = 0;
1818
1819 #ifdef QUICK_LOOK_UP
1820   {
1821     /* Begin code for new-style loading of quick look-up tables. */
1822
1823     /* elz: this checks whether the file has beeen processed by pxdb.
1824        If not we would like to try to read the psymbols in
1825        anyway, but it turns out to be not so easy. So this could 
1826        actually be commented out, but I leave it in, just in case
1827        we decide to add support for non-pxdb-ed stuff in the future. */
1828     PXDB_header pxdb_header;
1829     int found_modules_in_program;
1830
1831     if (hpread_get_header (objfile, &pxdb_header))
1832       {
1833         /* Build a minimal table.  No types, no global variables,
1834            no include files.... */
1835 #ifdef DUMPING
1836         if (dumping)
1837           printf ("\nNew method for %s\n", objfile->name);
1838 #endif
1839
1840         /* elz: quick_traverse returns true if it found
1841            some modules in the main source file, other
1842            than those in end.c
1843            In C and C++, all the files have MODULES entries
1844            in the LNTT, and the quick table traverse is all 
1845            based on finding these MODULES entries. Without 
1846            those it cannot work. 
1847            It happens that F77 programs don't have MODULES
1848            so the quick traverse gets confused. F90 programs
1849            have modules, and the quick method still works.
1850            So, if modules (other than those in end.c) are
1851            not found we give up on the quick table stuff, 
1852            and fall back on the slower method  */
1853         found_modules_in_program = hpread_quick_traverse (objfile,
1854                                                           GNTT (objfile),
1855                                                           VT (objfile),
1856                                                           &pxdb_header);
1857
1858         discard_cleanups (old_chain);
1859
1860         /* Set up to scan the global section of the LNTT.
1861
1862            This field is not always correct: if there are
1863            no globals, it will point to the last record in
1864            the regular LNTT, which is usually an END MODULE.
1865
1866            Since it might happen that there could be a file
1867            with just one global record, there's no way to
1868            tell other than by looking at the record, so that's
1869            done below. */
1870         if (found_modules_in_program)
1871           scan_start = pxdb_header.globals;
1872       }
1873 #ifdef DUMPING
1874     else
1875       {
1876         if (dumping)
1877           printf ("\nGoing on to old method for %s\n", objfile->name);
1878       }
1879 #endif
1880   }
1881 #endif /* QUICK_LOOK_UP */
1882
1883   /* Make two passes, one over the GNTT symbols, the other for the
1884      LNTT symbols.
1885
1886      JB comment: above isn't true--they only make one pass, over
1887      the LNTT.  */
1888   for (i = 0; i < 1; i++)
1889     {
1890       int within_function = 0;
1891
1892       if (i)
1893         symcount = GNTT_SYMCOUNT (objfile);
1894       else
1895         symcount = LNTT_SYMCOUNT (objfile);
1896
1897
1898       for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1899         {
1900           QUIT;
1901           if (i)
1902             dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1903           else
1904             dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1905
1906           if (dn_bufp->dblock.extension)
1907             continue;
1908
1909           /* Only handle things which are necessary for minimal symbols.
1910              everything else is ignored.  */
1911           switch (dn_bufp->dblock.kind)
1912             {
1913             case DNTT_TYPE_SRCFILE:
1914               {
1915 #ifdef QUICK_LOOK_UP
1916                 if (scan_start == hp_symnum
1917                     && symcount == hp_symnum + 1)
1918                   {
1919                     /* If there are NO globals in an executable,
1920                        PXDB's index to the globals will point to
1921                        the last record in the file, which 
1922                        could be this record. (this happened for F77 libraries)
1923                        ignore it and be done! */
1924                     continue;
1925                   }
1926 #endif /* QUICK_LOOK_UP */
1927
1928                 /* A source file of some kind.  Note this may simply
1929                    be an included file.  */
1930                 set_namestring (dn_bufp, &namestring, objfile);
1931
1932                 /* Check if this is the source file we are already working
1933                    with.  */
1934                 if (pst && !strcmp (namestring, pst->filename))
1935                   continue;
1936
1937                 /* Check if this is an include file, if so check if we have
1938                    already seen it.  Add it to the include list */
1939                 p = strrchr (namestring, '.');
1940                 if (!strcmp (p, ".h"))
1941                   {
1942                     int j, found;
1943
1944                     found = 0;
1945                     for (j = 0; j < includes_used; j++)
1946                       if (!strcmp (namestring, psymtab_include_list[j]))
1947                         {
1948                           found = 1;
1949                           break;
1950                         }
1951                     if (found)
1952                       continue;
1953
1954                     /* Add it to the list of includes seen so far and
1955                        allocate more include space if necessary.  */
1956                     psymtab_include_list[includes_used++] = namestring;
1957                     if (includes_used >= includes_allocated)
1958                       {
1959                         char **orig = psymtab_include_list;
1960
1961                         psymtab_include_list = (char **)
1962                           alloca ((includes_allocated *= 2) *
1963                                   sizeof (char *));
1964                         memcpy (psymtab_include_list, orig,
1965                                 includes_used * sizeof (char *));
1966                       }
1967                     continue;
1968                   }
1969
1970                 if (pst)
1971                   {
1972                     if (!have_name)
1973                       {
1974                         pst->filename = (char *)
1975                           obstack_alloc (&pst->objfile->psymbol_obstack,
1976                                          strlen (namestring) + 1);
1977                         strcpy (pst->filename, namestring);
1978                         have_name = 1;
1979                         continue;
1980                       }
1981                     continue;
1982                   }
1983
1984                 /* This is a bonafide new source file.
1985                    End the current partial symtab and start a new one.  */
1986
1987                 if (pst && past_first_source_file)
1988                   {
1989                     hpread_end_psymtab (pst, psymtab_include_list,
1990                                         includes_used,
1991                                         (hp_symnum
1992                                          * sizeof (struct dntt_type_block)),
1993                                         texthigh,
1994                                         dependency_list, dependencies_used);
1995                     pst = (struct partial_symtab *) 0;
1996                     includes_used = 0;
1997                     dependencies_used = 0;
1998                   }
1999                 else
2000                   past_first_source_file = 1;
2001
2002                 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
2003                 valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2004                 pst = hpread_start_psymtab (objfile,
2005                                             namestring, valu,
2006                                             (hp_symnum
2007                                          * sizeof (struct dntt_type_block)),
2008                                             objfile->global_psymbols.next,
2009                                             objfile->static_psymbols.next);
2010                 texthigh = valu;
2011                 have_name = 1;
2012                 continue;
2013               }
2014
2015             case DNTT_TYPE_MODULE:
2016               /* A source file.  It's still unclear to me what the
2017                  real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
2018                  is supposed to be.  */
2019
2020               /* First end the previous psymtab */
2021               if (pst)
2022                 {
2023                   hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2024                                       ((hp_symnum - 1)
2025                                        * sizeof (struct dntt_type_block)),
2026                                       texthigh,
2027                                       dependency_list, dependencies_used);
2028                   pst = (struct partial_symtab *) 0;
2029                   includes_used = 0;
2030                   dependencies_used = 0;
2031                   have_name = 0;
2032                 }
2033
2034               /* Now begin a new module and a new psymtab for it */
2035               set_namestring (dn_bufp, &namestring, objfile);
2036               valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
2037               valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2038               if (!pst)
2039                 {
2040                   pst = hpread_start_psymtab (objfile,
2041                                               namestring, valu,
2042                                               (hp_symnum
2043                                          * sizeof (struct dntt_type_block)),
2044                                               objfile->global_psymbols.next,
2045                                               objfile->static_psymbols.next);
2046                   texthigh = valu;
2047                   have_name = 0;
2048                 }
2049               continue;
2050
2051             case DNTT_TYPE_FUNCTION:
2052             case DNTT_TYPE_ENTRY:
2053               /* The beginning of a function.  DNTT_TYPE_ENTRY may also denote
2054                  a secondary entry point.  */
2055               valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
2056                                                        SECT_OFF_TEXT (objfile));
2057               if (valu > texthigh)
2058                 texthigh = valu;
2059               valu = dn_bufp->dfunc.lowaddr +
2060                 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2061               set_namestring (dn_bufp, &namestring, objfile);
2062               if (dn_bufp->dfunc.global)
2063                 add_psymbol_to_list (namestring, strlen (namestring),
2064                                      VAR_DOMAIN, LOC_BLOCK,
2065                                      &objfile->global_psymbols, valu,
2066                                      0, language_unknown, objfile);
2067               else
2068                 add_psymbol_to_list (namestring, strlen (namestring),
2069                                      VAR_DOMAIN, LOC_BLOCK,
2070                                      &objfile->static_psymbols, valu,
2071                                      0, language_unknown, objfile);
2072               within_function = 1;
2073               continue;
2074
2075             case DNTT_TYPE_DOC_FUNCTION:
2076               valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (objfile->section_offsets,
2077                                                           SECT_OFF_TEXT (objfile));
2078               if (valu > texthigh)
2079                 texthigh = valu;
2080               valu = dn_bufp->ddocfunc.lowaddr +
2081                 ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2082               set_namestring (dn_bufp, &namestring, objfile);
2083               if (dn_bufp->ddocfunc.global)
2084                 add_psymbol_to_list (namestring, strlen (namestring),
2085                                      VAR_DOMAIN, LOC_BLOCK,
2086                                      &objfile->global_psymbols, valu,
2087                                      0, language_unknown, objfile);
2088               else
2089                 add_psymbol_to_list (namestring, strlen (namestring),
2090                                      VAR_DOMAIN, LOC_BLOCK,
2091                                      &objfile->static_psymbols, valu,
2092                                      0, language_unknown, objfile);
2093               within_function = 1;
2094               continue;
2095
2096             case DNTT_TYPE_BEGIN:
2097             case DNTT_TYPE_END:
2098               /* We don't check MODULE end here, because there can be
2099                  symbols beyond the module end which properly belong to the
2100                  current psymtab -- so we wait till the next MODULE start */
2101
2102
2103 #ifdef QUICK_LOOK_UP
2104               if (scan_start == hp_symnum
2105                   && symcount == hp_symnum + 1)
2106                 {
2107                   /* If there are NO globals in an executable,
2108                      PXDB's index to the globals will point to
2109                      the last record in the file, which is
2110                      probably an END MODULE, i.e. this record.
2111                      ignore it and be done! */
2112                   continue;
2113                 }
2114 #endif /* QUICK_LOOK_UP */
2115
2116               /* Scope block begin/end.  We only care about function
2117                  and file blocks right now.  */
2118
2119               if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
2120                   (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
2121                 within_function = 0;
2122               continue;
2123
2124             case DNTT_TYPE_SVAR:
2125             case DNTT_TYPE_DVAR:
2126             case DNTT_TYPE_TYPEDEF:
2127             case DNTT_TYPE_TAGDEF:
2128               {
2129                 /* Variables, typedefs an the like.  */
2130                 enum address_class storage;
2131                 domain_enum domain;
2132
2133                 /* Don't add locals to the partial symbol table.  */
2134                 if (within_function
2135                     && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
2136                         || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
2137                   continue;
2138
2139                 /* TAGDEFs go into the structure domain.  */
2140                 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
2141                   domain = STRUCT_DOMAIN;
2142                 else
2143                   domain = VAR_DOMAIN;
2144
2145                 /* What kind of "storage" does this use?  */
2146                 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
2147                   storage = LOC_STATIC;
2148                 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
2149                          && dn_bufp->ddvar.regvar)
2150                   storage = LOC_REGISTER;
2151                 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
2152                   storage = LOC_LOCAL;
2153                 else
2154                   storage = LOC_UNDEF;
2155
2156                 set_namestring (dn_bufp, &namestring, objfile);
2157                 if (!pst)
2158                   {
2159                     pst = hpread_start_psymtab (objfile,
2160                                                 "globals", 0,
2161                                                 (hp_symnum
2162                                          * sizeof (struct dntt_type_block)),
2163                                               objfile->global_psymbols.next,
2164                                              objfile->static_psymbols.next);
2165                   }
2166
2167                 /* Compute address of the data symbol */
2168                 valu = dn_bufp->dsvar.location;
2169                 /* Relocate in case it's in a shared library */
2170                 if (storage == LOC_STATIC)
2171                   valu += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2172
2173                 /* Luckily, dvar, svar, typedef, and tagdef all
2174                    have their "global" bit in the same place, so it works
2175                    (though it's bad programming practice) to reference
2176                    "dsvar.global" even though we may be looking at
2177                    any of the above four types. */
2178                 if (dn_bufp->dsvar.global)
2179                   {
2180                     add_psymbol_to_list (namestring, strlen (namestring),
2181                                          domain, storage,
2182                                          &objfile->global_psymbols,
2183                                          valu,
2184                                          0, language_unknown, objfile);
2185                   }
2186                 else
2187                   {
2188                     add_psymbol_to_list (namestring, strlen (namestring),
2189                                          domain, storage,
2190                                          &objfile->static_psymbols,
2191                                          valu,
2192                                          0, language_unknown, objfile);
2193                   }
2194
2195                 /* For TAGDEF's, the above code added the tagname to the
2196                    struct domain. This will cause tag "t" to be found
2197                    on a reference of the form "(struct t) x". But for
2198                    C++ classes, "t" will also be a typename, which we
2199                    want to find on a reference of the form "ptype t".
2200                    Therefore, we also add "t" to the var domain.
2201                    Do the same for enum's due to the way aCC generates
2202                    debug info for these (see more extended comment
2203                    in hp-symtab-read.c).
2204                    We do the same for templates, so that "ptype t"
2205                    where "t" is a template also works. */
2206                 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2207                   dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2208                   {
2209                     int global = dn_bufp->dtag.global;
2210                     /* Look ahead to see if it's a C++ class */
2211                     dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2212                     if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2213                         dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2214                         dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2215                       {
2216                         if (global)
2217                           {
2218                             add_psymbol_to_list (namestring, strlen (namestring),
2219                                                  VAR_DOMAIN, storage,
2220                                                  &objfile->global_psymbols,
2221                                                  dn_bufp->dsvar.location,
2222                                               0, language_unknown, objfile);
2223                           }
2224                         else
2225                           {
2226                             add_psymbol_to_list (namestring, strlen (namestring),
2227                                                  VAR_DOMAIN, storage,
2228                                                  &objfile->static_psymbols,
2229                                                  dn_bufp->dsvar.location,
2230                                               0, language_unknown, objfile);
2231                           }
2232                       }
2233                   }
2234               }
2235               continue;
2236
2237             case DNTT_TYPE_MEMENUM:
2238             case DNTT_TYPE_CONST:
2239               /* Constants and members of enumerated types.  */
2240               set_namestring (dn_bufp, &namestring, objfile);
2241               if (!pst)
2242                 {
2243                   pst = hpread_start_psymtab (objfile,
2244                                               "globals", 0,
2245                                               (hp_symnum
2246                                          * sizeof (struct dntt_type_block)),
2247                                               objfile->global_psymbols.next,
2248                                               objfile->static_psymbols.next);
2249                 }
2250               if (dn_bufp->dconst.global)
2251                 add_psymbol_to_list (namestring, strlen (namestring),
2252                                      VAR_DOMAIN, LOC_CONST,
2253                                      &objfile->global_psymbols, 0,
2254                                      0, language_unknown, objfile);
2255               else
2256                 add_psymbol_to_list (namestring, strlen (namestring),
2257                                      VAR_DOMAIN, LOC_CONST,
2258                                      &objfile->static_psymbols, 0,
2259                                      0, language_unknown, objfile);
2260               continue;
2261             default:
2262               continue;
2263             }
2264         }
2265     }
2266
2267   /* End any pending partial symbol table. */
2268   if (pst)
2269     {
2270       hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2271                           hp_symnum * sizeof (struct dntt_type_block),
2272                           0, dependency_list, dependencies_used);
2273     }
2274
2275   discard_cleanups (old_chain);
2276 }
2277
2278 /* Perform any local cleanups required when we are done with a particular
2279    objfile.  I.E, we are in the process of discarding all symbol information
2280    for an objfile, freeing up all memory held for it, and unlinking the
2281    objfile struct from the global list of known objfiles. */
2282
2283 void
2284 hpread_symfile_finish (struct objfile *objfile)
2285 {
2286   if (objfile->sym_private != NULL)
2287     {
2288       xmfree (objfile->md, objfile->sym_private);
2289     }
2290 }
2291 \f
2292
2293 /* The remaining functions are all for internal use only.  */
2294
2295 /* Various small functions to get entries in the debug symbol sections.  */
2296
2297 union dnttentry *
2298 hpread_get_lntt (int index, struct objfile *objfile)
2299 {
2300   return (union dnttentry *)
2301     &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2302 }
2303
2304 static union dnttentry *
2305 hpread_get_gntt (int index, struct objfile *objfile)
2306 {
2307   return (union dnttentry *)
2308     &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2309 }
2310
2311 union sltentry *
2312 hpread_get_slt (int index, struct objfile *objfile)
2313 {
2314   return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2315 }
2316
2317 /* Get the low address associated with some symbol (typically the start
2318    of a particular source file or module).  Since that information is not
2319    stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
2320    must infer it from the existence of DNTT_TYPE_FUNCTION symbols.  */
2321
2322 static unsigned long
2323 hpread_get_textlow (int global, int index, struct objfile *objfile,
2324                     int symcount)
2325 {
2326   union dnttentry *dn_bufp = NULL;
2327   struct minimal_symbol *msymbol;
2328
2329   /* Look for a DNTT_TYPE_FUNCTION symbol.  */
2330   if (index < symcount)         /* symcount is the number of symbols in */
2331     {                           /*   the dbinfo, LNTT table */
2332       do
2333         {
2334           if (global)
2335             dn_bufp = hpread_get_gntt (index++, objfile);
2336           else
2337             dn_bufp = hpread_get_lntt (index++, objfile);
2338         }
2339       while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2340              && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2341              && dn_bufp->dblock.kind != DNTT_TYPE_END
2342              && index < symcount);
2343     }
2344
2345   /* NOTE: cagney/2003-03-29: If !(index < symcount), dn_bufp is left
2346      undefined and that means that the test below is using a garbage
2347      pointer from the stack.  */
2348   gdb_assert (dn_bufp != NULL);
2349
2350   /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION.  This
2351      might happen when a sourcefile has no functions.  */
2352   if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2353     return 0;
2354
2355   /* Avoid going past the end of the LNTT file */
2356   if (index == symcount)
2357     return 0;
2358
2359   /* The minimal symbols are typically more accurate for some reason.  */
2360   if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2361     msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2362                                      objfile);
2363   else                          /* must be a DNTT_TYPE_DOC_FUNCTION */
2364     msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2365                                      objfile);
2366
2367   if (msymbol)
2368     return SYMBOL_VALUE_ADDRESS (msymbol);
2369   else
2370     return dn_bufp->dfunc.lowaddr;
2371 }
2372
2373 /* Allocate and partially fill a partial symtab.  It will be
2374    completely filled at the end of the symbol list.
2375
2376    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2377    is the address relative to which its symbols are (incremental) or 0
2378    (normal). */
2379
2380 static struct partial_symtab *
2381 hpread_start_psymtab (struct objfile *objfile, char *filename,
2382                       CORE_ADDR textlow, int ldsymoff,
2383                       struct partial_symbol **global_syms,
2384                       struct partial_symbol **static_syms)
2385 {
2386   int offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2387   extern void hpread_psymtab_to_symtab ();
2388   struct partial_symtab *result =
2389   start_psymtab_common (objfile, objfile->section_offsets,
2390                         filename, textlow, global_syms, static_syms);
2391
2392   result->textlow += offset;
2393   result->read_symtab_private = (char *)
2394     obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2395   LDSYMOFF (result) = ldsymoff;
2396   result->read_symtab = hpread_psymtab_to_symtab;
2397
2398   return result;
2399 }
2400 \f
2401
2402 /* Close off the current usage of PST.  
2403    Returns PST or NULL if the partial symtab was empty and thrown away.
2404
2405    capping_symbol_offset  --Byte index in LNTT or GNTT of the
2406    last symbol processed during the build
2407    of the previous pst.
2408
2409    FIXME:  List variables and peculiarities of same.  */
2410
2411 static struct partial_symtab *
2412 hpread_end_psymtab (struct partial_symtab *pst, char **include_list,
2413                     int num_includes, int capping_symbol_offset,
2414                     CORE_ADDR capping_text,
2415                     struct partial_symtab **dependency_list,
2416                     int number_dependencies)
2417 {
2418   int i;
2419   struct objfile *objfile = pst->objfile;
2420   int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
2421
2422 #ifdef DUMPING
2423   /* Turn on to see what kind of a psymtab we've built. */
2424   static int dumping = 0;
2425 #endif
2426
2427   if (capping_symbol_offset != -1)
2428     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2429   else
2430     LDSYMLEN (pst) = 0;
2431   pst->texthigh = capping_text + offset;
2432
2433   pst->n_global_syms =
2434     objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2435   pst->n_static_syms =
2436     objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2437
2438 #ifdef DUMPING
2439   if (dumping)
2440     {
2441       printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2442               pst->filename,
2443               LDSYMOFF (pst),
2444               LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2445               LDSYMLEN (pst),
2446               LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2447               pst->n_global_syms, pst->n_static_syms);
2448     }
2449 #endif
2450
2451   pst->number_of_dependencies = number_dependencies;
2452   if (number_dependencies)
2453     {
2454       pst->dependencies = (struct partial_symtab **)
2455         obstack_alloc (&objfile->psymbol_obstack,
2456                     number_dependencies * sizeof (struct partial_symtab *));
2457       memcpy (pst->dependencies, dependency_list,
2458               number_dependencies * sizeof (struct partial_symtab *));
2459     }
2460   else
2461     pst->dependencies = 0;
2462
2463   for (i = 0; i < num_includes; i++)
2464     {
2465       struct partial_symtab *subpst =
2466       allocate_psymtab (include_list[i], objfile);
2467
2468       subpst->section_offsets = pst->section_offsets;
2469       subpst->read_symtab_private =
2470         (char *) obstack_alloc (&objfile->psymbol_obstack,
2471                                 sizeof (struct symloc));
2472       LDSYMOFF (subpst) =
2473         LDSYMLEN (subpst) =
2474         subpst->textlow =
2475         subpst->texthigh = 0;
2476
2477       /* We could save slight bits of space by only making one of these,
2478          shared by the entire set of include files.  FIXME-someday.  */
2479       subpst->dependencies = (struct partial_symtab **)
2480         obstack_alloc (&objfile->psymbol_obstack,
2481                        sizeof (struct partial_symtab *));
2482       subpst->dependencies[0] = pst;
2483       subpst->number_of_dependencies = 1;
2484
2485       subpst->globals_offset =
2486         subpst->n_global_syms =
2487         subpst->statics_offset =
2488         subpst->n_static_syms = 0;
2489
2490       subpst->readin = 0;
2491       subpst->symtab = 0;
2492       subpst->read_symtab = pst->read_symtab;
2493     }
2494
2495   sort_pst_symbols (pst);
2496
2497   /* If there is already a psymtab or symtab for a file of this name, remove it.
2498      (If there is a symtab, more drastic things also happen.)
2499      This happens in VxWorks.  */
2500   free_named_symtabs (pst->filename);
2501
2502   if (num_includes == 0
2503       && number_dependencies == 0
2504       && pst->n_global_syms == 0
2505       && pst->n_static_syms == 0)
2506     {
2507       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
2508          it is on the obstack, but we can forget to chain it on the list. 
2509          Empty psymtabs happen as a result of header files which don't have
2510          any symbols in them.  There can be a lot of them.  But this check
2511          is wrong, in that a psymtab with N_SLINE entries but nothing else
2512          is not empty, but we don't realize that.  Fixing that without slowing
2513          things down might be tricky.
2514          It's also wrong if we're using the quick look-up tables, as
2515          we can get empty psymtabs from modules with no routines in
2516          them. */
2517
2518       discard_psymtab (pst);
2519
2520       /* Indicate that psymtab was thrown away.  */
2521       pst = (struct partial_symtab *) NULL;
2522
2523     }
2524   return pst;
2525 }
2526
2527 \f
2528 /* Get the nesting depth for the source line identified by INDEX.  */
2529
2530 static unsigned long
2531 hpread_get_scope_start (sltpointer index, struct objfile *objfile)
2532 {
2533   union sltentry *sl_bufp;
2534
2535   sl_bufp = hpread_get_slt (index, objfile);
2536   return sl_bufp->sspec.backptr.dnttp.index;
2537 }
2538
2539 /* Get the source line number the the line identified by INDEX.  */
2540
2541 static unsigned long
2542 hpread_get_line (sltpointer index, struct objfile *objfile)
2543 {
2544   union sltentry *sl_bufp;
2545
2546   sl_bufp = hpread_get_slt (index, objfile);
2547   return sl_bufp->snorm.line;
2548 }
2549
2550 /* Find the code address associated with a given sltpointer */
2551
2552 static CORE_ADDR
2553 hpread_get_location (sltpointer index, struct objfile *objfile)
2554 {
2555   union sltentry *sl_bufp;
2556   int i;
2557
2558   /* code location of special sltentrys is determined from context */
2559   sl_bufp = hpread_get_slt (index, objfile);
2560
2561   if (sl_bufp->snorm.sltdesc == SLT_END)
2562     {
2563       /* find previous normal sltentry and get address */
2564       for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
2565                    (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
2566                    (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
2567         sl_bufp = hpread_get_slt (index - i, objfile);
2568       if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2569         return sl_bufp->snormoff.address;
2570       else
2571         return sl_bufp->snorm.address;
2572     }
2573
2574   /* find next normal sltentry and get address */
2575   for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
2576                (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
2577                (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
2578     sl_bufp = hpread_get_slt (index + i, objfile);
2579   if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2580     return sl_bufp->snormoff.address;
2581   else
2582     return sl_bufp->snorm.address;
2583 }
2584 \f
2585
2586 /* Return 1 if an HP debug symbol of type KIND has a name associated with
2587  * it, else return 0. (This function is not currently used, but I'll
2588  * leave it here in case it proves useful later on. - RT).
2589  */
2590
2591 int
2592 hpread_has_name (enum dntt_entry_type kind)
2593 {
2594   switch (kind)
2595     {
2596     case DNTT_TYPE_SRCFILE:
2597     case DNTT_TYPE_MODULE:
2598     case DNTT_TYPE_FUNCTION:
2599     case DNTT_TYPE_DOC_FUNCTION:
2600     case DNTT_TYPE_ENTRY:
2601     case DNTT_TYPE_IMPORT:
2602     case DNTT_TYPE_LABEL:
2603     case DNTT_TYPE_FPARAM:
2604     case DNTT_TYPE_SVAR:
2605     case DNTT_TYPE_DVAR:
2606     case DNTT_TYPE_CONST:
2607     case DNTT_TYPE_TYPEDEF:
2608     case DNTT_TYPE_TAGDEF:
2609     case DNTT_TYPE_MEMENUM:
2610     case DNTT_TYPE_FIELD:
2611     case DNTT_TYPE_SA:
2612     case DNTT_TYPE_BLOCKDATA:
2613     case DNTT_TYPE_MEMFUNC:
2614     case DNTT_TYPE_DOC_MEMFUNC:
2615       return 1;
2616
2617     case DNTT_TYPE_BEGIN:
2618     case DNTT_TYPE_END:
2619     case DNTT_TYPE_POINTER:
2620     case DNTT_TYPE_ENUM:
2621     case DNTT_TYPE_SET:
2622     case DNTT_TYPE_ARRAY:
2623     case DNTT_TYPE_STRUCT:
2624     case DNTT_TYPE_UNION:
2625     case DNTT_TYPE_VARIANT:
2626     case DNTT_TYPE_FILE:
2627     case DNTT_TYPE_FUNCTYPE:
2628     case DNTT_TYPE_SUBRANGE:
2629     case DNTT_TYPE_WITH:
2630     case DNTT_TYPE_COMMON:
2631     case DNTT_TYPE_COBSTRUCT:
2632     case DNTT_TYPE_XREF:
2633     case DNTT_TYPE_MACRO:
2634     case DNTT_TYPE_CLASS_SCOPE:
2635     case DNTT_TYPE_REFERENCE:
2636     case DNTT_TYPE_PTRMEM:
2637     case DNTT_TYPE_PTRMEMFUNC:
2638     case DNTT_TYPE_CLASS:
2639     case DNTT_TYPE_GENFIELD:
2640     case DNTT_TYPE_VFUNC:
2641     case DNTT_TYPE_MEMACCESS:
2642     case DNTT_TYPE_INHERITANCE:
2643     case DNTT_TYPE_FRIEND_CLASS:
2644     case DNTT_TYPE_FRIEND_FUNC:
2645     case DNTT_TYPE_MODIFIER:
2646     case DNTT_TYPE_OBJECT_ID:
2647     case DNTT_TYPE_TEMPLATE:
2648     case DNTT_TYPE_TEMPLATE_ARG:
2649     case DNTT_TYPE_FUNC_TEMPLATE:
2650     case DNTT_TYPE_LINK:
2651       /* DNTT_TYPE_DYN_ARRAY_DESC ? */
2652       /* DNTT_TYPE_DESC_SUBRANGE ? */
2653       /* DNTT_TYPE_BEGIN_EXT ? */
2654       /* DNTT_TYPE_INLN ? */
2655       /* DNTT_TYPE_INLN_LIST ? */
2656       /* DNTT_TYPE_ALIAS ? */
2657     default:
2658       return 0;
2659     }
2660 }
2661
2662 /* Do the dirty work of reading in the full symbol from a partial symbol
2663    table.  */
2664
2665 static void
2666 hpread_psymtab_to_symtab_1 (struct partial_symtab *pst)
2667 {
2668   struct cleanup *old_chain;
2669   int i;
2670
2671   /* Get out quick if passed junk.  */
2672   if (!pst)
2673     return;
2674
2675   /* Complain if we've already read in this symbol table.  */
2676   if (pst->readin)
2677     {
2678       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in."
2679                           "  Shouldn't happen.\n",
2680                           pst->filename);
2681       return;
2682     }
2683
2684   /* Read in all partial symtabs on which this one is dependent */
2685   for (i = 0; i < pst->number_of_dependencies; i++)
2686     if (!pst->dependencies[i]->readin)
2687       {
2688         /* Inform about additional files that need to be read in.  */
2689         if (info_verbose)
2690           {
2691             fputs_filtered (" ", gdb_stdout);
2692             wrap_here ("");
2693             fputs_filtered ("and ", gdb_stdout);
2694             wrap_here ("");
2695             printf_filtered ("%s...", pst->dependencies[i]->filename);
2696             wrap_here ("");     /* Flush output */
2697             gdb_flush (gdb_stdout);
2698           }
2699         hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
2700       }
2701
2702   /* If it's real...  */
2703   if (LDSYMLEN (pst))
2704     {
2705       /* Init stuff necessary for reading in symbols */
2706       buildsym_init ();
2707       old_chain = make_cleanup (really_free_pendings, 0);
2708
2709       pst->symtab =
2710         hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
2711                               pst->textlow, pst->texthigh - pst->textlow,
2712                               pst->section_offsets, pst->filename);
2713       sort_symtab_syms (pst->symtab);
2714
2715       do_cleanups (old_chain);
2716     }
2717
2718   pst->readin = 1;
2719 }
2720
2721 /* Read in all of the symbols for a given psymtab for real.
2722    Be verbose about it if the user wants that.  */
2723
2724 void
2725 hpread_psymtab_to_symtab (struct partial_symtab *pst)
2726 {
2727   /* Get out quick if given junk.  */
2728   if (!pst)
2729     return;
2730
2731   /* Sanity check.  */
2732   if (pst->readin)
2733     {
2734       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in."
2735                           "  Shouldn't happen.\n",
2736                           pst->filename);
2737       return;
2738     }
2739
2740   /* elz: setting the flag to indicate that the code of the target
2741      was compiled using an HP compiler (aCC, cc) 
2742      the processing_acc_compilation variable is declared in the 
2743      file buildsym.h, the HP_COMPILED_TARGET is defined to be equal
2744      to 3 in the file tm_hppa.h */
2745
2746   processing_gcc_compilation = 0;
2747
2748   if (LDSYMLEN (pst) || pst->number_of_dependencies)
2749     {
2750       /* Print the message now, before reading the string table,
2751          to avoid disconcerting pauses.  */
2752       if (info_verbose)
2753         {
2754           printf_filtered ("Reading in symbols for %s...", pst->filename);
2755           gdb_flush (gdb_stdout);
2756         }
2757
2758       hpread_psymtab_to_symtab_1 (pst);
2759
2760       /* Match with global symbols.  This only needs to be done once,
2761          after all of the symtabs and dependencies have been read in.   */
2762       scan_file_globals (pst->objfile);
2763
2764       /* Finish up the debug error message.  */
2765       if (info_verbose)
2766         printf_filtered ("done.\n");
2767     }
2768 }
2769
2770 /* Read in a defined section of a specific object file's symbols.
2771
2772    DESC is the file descriptor for the file, positioned at the
2773    beginning of the symtab
2774    SYM_OFFSET is the offset within the file of
2775    the beginning of the symbols we want to read
2776    SYM_SIZE is the size of the symbol info to read in.
2777    TEXT_OFFSET is the beginning of the text segment we are reading symbols for
2778    TEXT_SIZE is the size of the text segment read in.
2779    SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
2780
2781 static struct symtab *
2782 hpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size,
2783                       CORE_ADDR text_offset, int text_size,
2784                       struct section_offsets *section_offsets, char *filename)
2785 {
2786   char *namestring;
2787   union dnttentry *dn_bufp;
2788   unsigned max_symnum;
2789   int at_module_boundary = 0;
2790   /* 1 => at end, -1 => at beginning */
2791
2792   int sym_index = sym_offset / sizeof (struct dntt_type_block);
2793
2794   current_objfile = objfile;
2795   subfile_stack = 0;
2796
2797   last_source_file = 0;
2798
2799   /* Demangling style -- if EDG style already set, don't change it,
2800      as HP style causes some problems with the KAI EDG compiler */
2801   if (current_demangling_style != edg_demangling)
2802     {
2803       /* Otherwise, ensure that we are using HP style demangling */
2804       set_demangling_style (HP_DEMANGLING_STYLE_STRING);
2805     }
2806
2807   dn_bufp = hpread_get_lntt (sym_index, objfile);
2808   if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
2809         (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
2810     {
2811       start_symtab ("globals", NULL, 0);
2812       record_debugformat ("HP");
2813     }
2814
2815   /* The psymtab builder (hp-psymtab-read.c) is the one that
2816    * determined the "sym_size" argument (i.e. how many DNTT symbols
2817    * are in this symtab), which we use to compute "max_symnum"
2818    * (point in DNTT to which we read). 
2819    *
2820    * Perhaps this should be changed so that 
2821    * process_one_debug_symbol() "knows" when
2822    * to stop reading (based on reading from the MODULE to the matching
2823    * END), and take out this reliance on a #-syms being passed in...
2824    * (I'm worried about the reliability of this number). But I'll
2825    * leave it as-is, for now. - RT
2826    *
2827    * The change above has been made. I've left the "for" loop control
2828    * in to prepare for backing this out again. -JB
2829    */
2830   max_symnum = sym_size / sizeof (struct dntt_type_block);
2831   /* No reason to multiply on pst side and divide on sym side... FIXME */
2832
2833   /* Read in and process each debug symbol within the specified range.
2834    */
2835   for (symnum = 0;
2836        symnum < max_symnum;
2837        symnum++)
2838     {
2839       QUIT;                     /* Allow this to be interruptable */
2840       dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
2841
2842       if (dn_bufp->dblock.extension)
2843         continue;
2844
2845       /* Yow!  We call set_namestring on things without names!  */
2846       set_namestring (dn_bufp, &namestring, objfile);
2847
2848       hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
2849                                        objfile, text_offset, text_size,
2850                                        filename, symnum + sym_index,
2851                                        &at_module_boundary
2852         );
2853
2854       /* OLD COMMENTS: This routine is only called for psts.  All psts
2855        * correspond to MODULES.  If we ever do lazy-reading of globals
2856        * from the LNTT, then there will be a pst which ends when the
2857        * LNTT ends, and not at an END MODULE entry.  Then we'll have
2858        * to re-visit this break.  
2859
2860        if( at_end_of_module )
2861        break;
2862
2863        */
2864
2865       /* We no longer break out of the loop when we reach the end of a
2866          module. The reason is that with CTTI, the compiler can generate
2867          function symbols (for template function instantiations) which are not
2868          in any module; typically they show up beyond a module's end, and
2869          before the next module's start.  We include them in the current
2870          module.  However, we still don't trust the MAX_SYMNUM value from
2871          the psymtab, so we break out if we enter a new module. */
2872
2873       if (at_module_boundary == -1)
2874         break;
2875     }
2876
2877   current_objfile = NULL;
2878   hp_som_som_object_present = 1;        /* Indicate we've processed an HP SOM SOM file */
2879
2880   return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
2881 }
2882 \f
2883
2884
2885
2886 /* Convert basic types from HP debug format into GDB internal format.  */
2887
2888 static int
2889 hpread_type_translate (dnttpointer typep)
2890 {
2891   if (!typep.dntti.immediate)
2892     {
2893       error ("error in hpread_type_translate\n.");
2894       return FT_VOID;
2895     }
2896
2897   switch (typep.dntti.type)
2898     {
2899     case HP_TYPE_BOOLEAN:
2900     case HP_TYPE_BOOLEAN_S300_COMPAT:
2901     case HP_TYPE_BOOLEAN_VAX_COMPAT:
2902       return FT_BOOLEAN;
2903     case HP_TYPE_CHAR:          /* C signed char, C++ plain char */
2904
2905     case HP_TYPE_WIDE_CHAR:
2906       return FT_CHAR;
2907     case HP_TYPE_INT:
2908       if (typep.dntti.bitlength <= 8)
2909         return FT_SIGNED_CHAR;  /* C++ signed char */
2910       if (typep.dntti.bitlength <= 16)
2911         return FT_SHORT;
2912       if (typep.dntti.bitlength <= 32)
2913         return FT_INTEGER;
2914       return FT_LONG_LONG;
2915     case HP_TYPE_LONG:
2916       if (typep.dntti.bitlength <= 8)
2917         return FT_SIGNED_CHAR;  /* C++ signed char. */
2918       return FT_LONG;
2919     case HP_TYPE_UNSIGNED_LONG:
2920       if (typep.dntti.bitlength <= 8)
2921         return FT_UNSIGNED_CHAR;        /* C/C++ unsigned char */
2922       if (typep.dntti.bitlength <= 16)
2923         return FT_UNSIGNED_SHORT;
2924       if (typep.dntti.bitlength <= 32)
2925         return FT_UNSIGNED_LONG;
2926       return FT_UNSIGNED_LONG_LONG;
2927     case HP_TYPE_UNSIGNED_INT:
2928       if (typep.dntti.bitlength <= 8)
2929         return FT_UNSIGNED_CHAR;
2930       if (typep.dntti.bitlength <= 16)
2931         return FT_UNSIGNED_SHORT;
2932       if (typep.dntti.bitlength <= 32)
2933         return FT_UNSIGNED_INTEGER;
2934       return FT_UNSIGNED_LONG_LONG;
2935     case HP_TYPE_REAL:
2936     case HP_TYPE_REAL_3000:
2937     case HP_TYPE_DOUBLE:
2938       if (typep.dntti.bitlength == 64)
2939         return FT_DBL_PREC_FLOAT;
2940       if (typep.dntti.bitlength == 128)
2941         return FT_EXT_PREC_FLOAT;
2942       return FT_FLOAT;
2943     case HP_TYPE_COMPLEX:
2944     case HP_TYPE_COMPLEXS3000:
2945       if (typep.dntti.bitlength == 128)
2946         return FT_DBL_PREC_COMPLEX;
2947       if (typep.dntti.bitlength == 192)
2948         return FT_EXT_PREC_COMPLEX;
2949       return FT_COMPLEX;
2950     case HP_TYPE_VOID:
2951       return FT_VOID;
2952     case HP_TYPE_STRING200:
2953     case HP_TYPE_LONGSTRING200:
2954     case HP_TYPE_FTN_STRING_SPEC:
2955     case HP_TYPE_MOD_STRING_SPEC:
2956     case HP_TYPE_MOD_STRING_3000:
2957     case HP_TYPE_FTN_STRING_S300_COMPAT:
2958     case HP_TYPE_FTN_STRING_VAX_COMPAT:
2959       return FT_STRING;
2960     case HP_TYPE_TEMPLATE_ARG:
2961       return FT_TEMPLATE_ARG;
2962     case HP_TYPE_TEXT:
2963     case HP_TYPE_FLABEL:
2964     case HP_TYPE_PACKED_DECIMAL:
2965     case HP_TYPE_ANYPOINTER:
2966     case HP_TYPE_GLOBAL_ANYPOINTER:
2967     case HP_TYPE_LOCAL_ANYPOINTER:
2968     default:
2969       warning ("hpread_type_translate: unhandled type code.\n");
2970       return FT_VOID;
2971     }
2972 }
2973
2974 /* Given a position in the DNTT, return a pointer to the 
2975  * already-built "struct type" (if any), for the type defined 
2976  * at that position.
2977  */
2978
2979 static struct type **
2980 hpread_lookup_type (dnttpointer hp_type, struct objfile *objfile)
2981 {
2982   unsigned old_len;
2983   int index = hp_type.dnttp.index;
2984   int size_changed = 0;
2985
2986   /* The immediate flag indicates this doesn't actually point to
2987    * a type DNTT.
2988    */
2989   if (hp_type.dntti.immediate)
2990     return NULL;
2991
2992   /* For each objfile, we maintain a "type vector".
2993    * This an array of "struct type *"'s with one pointer per DNTT index.
2994    * Given a DNTT index, we look in this array to see if we have
2995    * already processed this DNTT and if it is a type definition.
2996    * If so, then we can locate a pointer to the already-built
2997    * "struct type", and not build it again.
2998    * 
2999    * The need for this arises because our DNTT-walking code wanders
3000    * around. In particular, it will encounter the same type multiple
3001    * times (once for each object of that type). We don't want to 
3002    * built multiple "struct type"'s for the same thing.
3003    *
3004    * Having said this, I should point out that this type-vector is
3005    * an expensive way to keep track of this. If most DNTT entries are 
3006    * 3 words, the type-vector will be 1/3 the size of the DNTT itself.
3007    * Alternative solutions:
3008    * - Keep a compressed or hashed table. Less memory, but more expensive
3009    *   to search and update.
3010    * - (Suggested by JB): Overwrite the DNTT entry itself
3011    *   with the info. Create a new type code "ALREADY_BUILT", and modify
3012    *   the DNTT to have that type code and point to the already-built entry.
3013    * -RT
3014    */
3015
3016   if (index < LNTT_SYMCOUNT (objfile))
3017     {
3018       if (index >= DNTT_TYPE_VECTOR_LENGTH (objfile))
3019         {
3020           old_len = DNTT_TYPE_VECTOR_LENGTH (objfile);
3021
3022           /* See if we need to allocate a type-vector. */
3023           if (old_len == 0)
3024             {
3025               DNTT_TYPE_VECTOR_LENGTH (objfile) = LNTT_SYMCOUNT (objfile) + GNTT_SYMCOUNT (objfile);
3026               DNTT_TYPE_VECTOR (objfile) = (struct type **)
3027                 xmmalloc (objfile->md, DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
3028               memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0,
3029                       (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) *
3030                       sizeof (struct type *));
3031             }
3032
3033           /* See if we need to resize type-vector. With my change to
3034            * initially allocate a correct-size type-vector, this code
3035            * should no longer trigger.
3036            */
3037           while (index >= DNTT_TYPE_VECTOR_LENGTH (objfile))
3038             {
3039               DNTT_TYPE_VECTOR_LENGTH (objfile) *= 2;
3040               size_changed = 1;
3041             }
3042           if (size_changed)
3043             {
3044               DNTT_TYPE_VECTOR (objfile) = (struct type **)
3045                 xmrealloc (objfile->md,
3046                            (char *) DNTT_TYPE_VECTOR (objfile),
3047                    (DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
3048
3049               memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0,
3050                       (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) *
3051                       sizeof (struct type *));
3052             }
3053
3054         }
3055       return &DNTT_TYPE_VECTOR (objfile)[index];
3056     }
3057   else
3058     return NULL;
3059 }
3060
3061 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
3062    Note we'll just return the address of a GDB internal type if we already
3063    have it lying around.  */
3064
3065 static struct type *
3066 hpread_alloc_type (dnttpointer hp_type, struct objfile *objfile)
3067 {
3068   struct type **type_addr;
3069
3070   type_addr = hpread_lookup_type (hp_type, objfile);
3071   if (*type_addr == 0)
3072     {
3073       *type_addr = alloc_type (objfile);
3074
3075       /* A hack - if we really are a C++ class symbol, then this default
3076        * will get overriden later on.
3077        */
3078       TYPE_CPLUS_SPECIFIC (*type_addr)
3079         = (struct cplus_struct_type *) &cplus_struct_default;
3080     }
3081
3082   return *type_addr;
3083 }
3084
3085 /* Read a native enumerated type and return it in GDB internal form.  */
3086
3087 static struct type *
3088 hpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3089                        struct objfile *objfile)
3090 {
3091   struct type *type;
3092   struct pending **symlist, *osyms, *syms;
3093   struct pending *local_list = NULL;
3094   int o_nsyms, nsyms = 0;
3095   dnttpointer mem;
3096   union dnttentry *memp;
3097   char *name;
3098   long n;
3099   struct symbol *sym;
3100
3101   /* Allocate a GDB type. If we've already read in this enum type,
3102    * it'll return the already built GDB type, so stop here.
3103    * (Note: I added this check, to conform with what's done for 
3104    *  struct, union, class.
3105    *  I assume this is OK. - RT)
3106    */
3107   type = hpread_alloc_type (hp_type, objfile);
3108   if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3109     return type;
3110
3111   /* HP C supports "sized enums", where a specifier such as "short" or
3112      "char" can be used to get enums of different sizes. So don't assume
3113      an enum is always 4 bytes long. pai/1997-08-21 */
3114   TYPE_LENGTH (type) = dn_bufp->denum.bitlength / 8;
3115
3116   symlist = &file_symbols;
3117   osyms = *symlist;
3118   o_nsyms = osyms ? osyms->nsyms : 0;
3119
3120   /* Get a name for each member and add it to our list of members.  
3121    * The list of "mem" SOM records we are walking should all be
3122    * SOM type DNTT_TYPE_MEMENUM (not checked).
3123    */
3124   mem = dn_bufp->denum.firstmem;
3125   while (mem.word && mem.word != DNTTNIL)
3126     {
3127       memp = hpread_get_lntt (mem.dnttp.index, objfile);
3128
3129       name = VT (objfile) + memp->dmember.name;
3130       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
3131                                              sizeof (struct symbol));
3132       memset (sym, 0, sizeof (struct symbol));
3133       DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
3134                                         &objfile->symbol_obstack);
3135       SYMBOL_CLASS (sym) = LOC_CONST;
3136       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3137       SYMBOL_VALUE (sym) = memp->dmember.value;
3138       add_symbol_to_list (sym, symlist);
3139       nsyms++;
3140       mem = memp->dmember.nextmem;
3141     }
3142
3143   /* Now that we know more about the enum, fill in more info.  */
3144   TYPE_CODE (type) = TYPE_CODE_ENUM;
3145   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3146   TYPE_NFIELDS (type) = nsyms;
3147   TYPE_FIELDS (type) = (struct field *)
3148     obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
3149
3150   /* Find the symbols for the members and put them into the type.
3151      The symbols can be found in the symlist that we put them on
3152      to cause them to be defined.  osyms contains the old value
3153      of that symlist; everything up to there was defined by us.
3154
3155      Note that we preserve the order of the enum constants, so
3156      that in something like "enum {FOO, LAST_THING=FOO}" we print
3157      FOO, not LAST_THING.  */
3158   for (syms = *symlist, n = 0; syms; syms = syms->next)
3159     {
3160       int j = 0;
3161       if (syms == osyms)
3162         j = o_nsyms;
3163       for (; j < syms->nsyms; j++, n++)
3164         {
3165           struct symbol *xsym = syms->symbol[j];
3166           SYMBOL_TYPE (xsym) = type;
3167           TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3168           TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3169           TYPE_FIELD_BITSIZE (type, n) = 0;
3170           TYPE_FIELD_STATIC_KIND (type, n) = 0;
3171         }
3172       if (syms == osyms)
3173         break;
3174     }
3175
3176   return type;
3177 }
3178
3179 /* Read and internalize a native function debug symbol.  */
3180
3181 static struct type *
3182 hpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3183                            struct objfile *objfile, int newblock)
3184 {
3185   struct type *type, *type1;
3186   struct pending *syms;
3187   struct pending *local_list = NULL;
3188   int nsyms = 0;
3189   dnttpointer param;
3190   union dnttentry *paramp;
3191   char *name;
3192   long n;
3193   struct symbol *sym;
3194   int record_args = 1;
3195
3196   /* See if we've already read in this type.  */
3197   type = hpread_alloc_type (hp_type, objfile);
3198   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
3199     {
3200       record_args = 0;          /* already read in, don't modify type */
3201     }
3202   else
3203     {
3204       /* Nope, so read it in and store it away.  */
3205       if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
3206           dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
3207         type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
3208                                                           objfile));
3209       else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
3210         type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
3211                                                           objfile));
3212       else                      /* expect DNTT_TYPE_FUNC_TEMPLATE */
3213         type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc_template.retval,
3214                                                           objfile));
3215       replace_type (type, type1);
3216
3217       /* Mark it -- in the middle of processing */
3218       TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3219     }
3220
3221   /* Now examine each parameter noting its type, location, and a
3222      wealth of other information.  */
3223   if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
3224       dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
3225     param = dn_bufp->dfunc.firstparam;
3226   else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
3227     param = dn_bufp->dfunctype.firstparam;
3228   else                          /* expect DNTT_TYPE_FUNC_TEMPLATE */
3229     param = dn_bufp->dfunc_template.firstparam;
3230   while (param.word && param.word != DNTTNIL)
3231     {
3232       paramp = hpread_get_lntt (param.dnttp.index, objfile);
3233       nsyms++;
3234       param = paramp->dfparam.nextparam;
3235
3236       /* Get the name.  */
3237       name = VT (objfile) + paramp->dfparam.name;
3238       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
3239                                              sizeof (struct symbol));
3240       (void) memset (sym, 0, sizeof (struct symbol));
3241       DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
3242                                         &objfile->symbol_obstack);
3243
3244       /* Figure out where it lives.  */
3245       if (paramp->dfparam.regparam)
3246         SYMBOL_CLASS (sym) = LOC_REGPARM;
3247       else if (paramp->dfparam.indirect)
3248         SYMBOL_CLASS (sym) = LOC_REF_ARG;
3249       else
3250         SYMBOL_CLASS (sym) = LOC_ARG;
3251       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3252       if (paramp->dfparam.copyparam)
3253         {
3254           SYMBOL_VALUE (sym) = paramp->dfparam.location;
3255 #ifdef HPREAD_ADJUST_STACK_ADDRESS
3256           SYMBOL_VALUE (sym)
3257             += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
3258 #endif
3259           /* This is likely a pass-by-invisible reference parameter,
3260              Hack on the symbol class to make GDB happy.  */
3261           /* ??rehrauer: This appears to be broken w/r/t to passing
3262              C values of type float and struct.  Perhaps this ought
3263              to be highighted as a special case, but for now, just
3264              allowing these to be LOC_ARGs seems to work fine.
3265            */
3266 #if 0
3267           SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
3268 #endif
3269         }
3270       else
3271         SYMBOL_VALUE (sym) = paramp->dfparam.location;
3272
3273       /* Get its type.  */
3274       SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
3275       /* Add it to the symbol list.  */
3276       /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
3277        * called on FPARAM symbols from the process_one_debug_symbol()
3278        * level... so parameters are getting added twice! (this shows
3279        * up in the symbol dump you get from "maint print symbols ...").
3280        * Note 2 (RT) I took out the processing of FPARAM from the 
3281        * process_one_debug_symbol() level, so at the moment parameters are only
3282        * being processed here. This seems to have no ill effect.
3283        */
3284       /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
3285          each fparam on the local_symbols list from here.  Now we use the
3286          local_list to which fparams are added below, and set the param_symbols
3287          global to point to that at the end of this routine. */
3288       /* elz: I added this new list of symbols which is local to the function.
3289          this list is the one which is actually used to build the type for the
3290          function rather than the gloabal list pointed to by symlist.
3291          Using a global list to keep track of the parameters is wrong, because 
3292          this function is called recursively if one parameter happend to be
3293          a function itself with more parameters in it. Adding parameters to the
3294          same global symbol list would not work!      
3295          Actually it did work in case of cc compiled programs where you do 
3296          not check the parameter lists of the arguments. */
3297       add_symbol_to_list (sym, &local_list);
3298
3299     }
3300
3301   /* If type was read in earlier, don't bother with modifying
3302      the type struct */
3303   if (!record_args)
3304     goto finish;
3305
3306   /* Note how many parameters we found.  */
3307   TYPE_NFIELDS (type) = nsyms;
3308   TYPE_FIELDS (type) = (struct field *)
3309     obstack_alloc (&objfile->type_obstack,
3310                    sizeof (struct field) * nsyms);
3311
3312   /* Find the symbols for the parameters and 
3313      use them to fill parameter-type information into the function-type.
3314      The parameter symbols can be found in the local_list that we just put them on. */
3315   /* Note that we preserve the order of the parameters, so
3316      that in something like "enum {FOO, LAST_THING=FOO}" we print
3317      FOO, not LAST_THING.  */
3318
3319   /* get the parameters types from the local list not the global list
3320      so that the type can be correctly constructed for functions which
3321      have function as parameters */
3322   for (syms = local_list, n = 0; syms; syms = syms->next)
3323     {
3324       int j = 0;
3325       for (j = 0; j < syms->nsyms; j++, n++)
3326         {
3327           struct symbol *xsym = syms->symbol[j];
3328           TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3329           TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
3330           TYPE_FIELD_ARTIFICIAL (type, n) = 0;
3331           TYPE_FIELD_BITSIZE (type, n) = 0;
3332           TYPE_FIELD_STATIC_KIND (type, n) = 0;
3333         }
3334     }
3335   /* Mark it as having been processed */
3336   TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
3337
3338   /* Check whether we need to fix-up a class type with this function's type */
3339   if (fixup_class && (fixup_method == type))
3340     {
3341       fixup_class_method_type (fixup_class, fixup_method, objfile);
3342       fixup_class = NULL;
3343       fixup_method = NULL;
3344     }
3345
3346   /* Set the param list of this level of the context stack
3347      to our local list.  Do this only if this function was
3348      called for creating a new block, and not if it was called
3349      simply to get the function type. This prevents recursive
3350      invocations from trashing param_symbols. */
3351 finish:
3352   if (newblock)
3353     param_symbols = local_list;
3354
3355   return type;
3356 }
3357
3358
3359 /* Read and internalize a native DOC function debug symbol.  */
3360 /* This is almost identical to hpread_read_function_type(), except
3361  * for references to dn_bufp->ddocfunc instead of db_bufp->dfunc.
3362  * Since debug information for DOC functions is more likely to be
3363  * volatile, please leave it this way.
3364  */
3365 static struct type *
3366 hpread_read_doc_function_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3367                                struct objfile *objfile, int newblock)
3368 {
3369   struct pending *syms;
3370   struct pending *local_list = NULL;
3371   int nsyms = 0;
3372   struct type *type;
3373   dnttpointer param;
3374   union dnttentry *paramp;
3375   char *name;
3376   long n;
3377   struct symbol *sym;
3378   int record_args = 1;
3379
3380   /* See if we've already read in this type.  */
3381   type = hpread_alloc_type (hp_type, objfile);
3382   if (TYPE_CODE (type) == TYPE_CODE_FUNC)
3383     {
3384       record_args = 0;          /* already read in, don't modify type */
3385     }
3386   else
3387     {
3388       struct type *type1 = NULL;
3389       /* Nope, so read it in and store it away.  */
3390       if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
3391           dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
3392         type1 = lookup_function_type (hpread_type_lookup (dn_bufp->ddocfunc.retval,
3393                                                           objfile));
3394       /* NOTE: cagney/2003-03-29: Oh, no not again.  TYPE1 is
3395          potentially left undefined here.  Assert it isn't and hope
3396          the assert never fails ...  */
3397       gdb_assert (type1 != NULL);
3398
3399       replace_type (type, type1);
3400
3401       /* Mark it -- in the middle of processing */
3402       TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3403     }
3404
3405   /* Now examine each parameter noting its type, location, and a
3406      wealth of other information.  */
3407   if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
3408       dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
3409     param = dn_bufp->ddocfunc.firstparam;
3410   while (param.word && param.word != DNTTNIL)
3411     {
3412       paramp = hpread_get_lntt (param.dnttp.index, objfile);
3413       nsyms++;
3414       param = paramp->dfparam.nextparam;
3415
3416       /* Get the name.  */
3417       name = VT (objfile) + paramp->dfparam.name;
3418       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
3419                                              sizeof (struct symbol));
3420       (void) memset (sym, 0, sizeof (struct symbol));
3421       DEPRECATED_SYMBOL_NAME (sym) = name;
3422
3423       /* Figure out where it lives.  */
3424       if (paramp->dfparam.regparam)
3425         SYMBOL_CLASS (sym) = LOC_REGPARM;
3426       else if (paramp->dfparam.indirect)
3427         SYMBOL_CLASS (sym) = LOC_REF_ARG;
3428       else
3429         SYMBOL_CLASS (sym) = LOC_ARG;
3430       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3431       if (paramp->dfparam.copyparam)
3432         {
3433           SYMBOL_VALUE (sym) = paramp->dfparam.location;
3434 #ifdef HPREAD_ADJUST_STACK_ADDRESS
3435           SYMBOL_VALUE (sym)
3436             += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
3437 #endif
3438           /* This is likely a pass-by-invisible reference parameter,
3439              Hack on the symbol class to make GDB happy.  */
3440           /* ??rehrauer: This appears to be broken w/r/t to passing
3441              C values of type float and struct.  Perhaps this ought
3442              to be highighted as a special case, but for now, just
3443              allowing these to be LOC_ARGs seems to work fine.
3444            */
3445 #if 0
3446           SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
3447 #endif
3448         }
3449       else
3450         SYMBOL_VALUE (sym) = paramp->dfparam.location;
3451
3452       /* Get its type.  */
3453       SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
3454       /* Add it to the symbol list.  */
3455       /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
3456        * called on FPARAM symbols from the process_one_debug_symbol()
3457        * level... so parameters are getting added twice! (this shows
3458        * up in the symbol dump you get from "maint print symbols ...").
3459        * Note 2 (RT) I took out the processing of FPARAM from the 
3460        * process_one_debug_symbol() level, so at the moment parameters are only
3461        * being processed here. This seems to have no ill effect.
3462        */
3463       /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
3464          each fparam on the local_symbols list from here.  Now we use the
3465          local_list to which fparams are added below, and set the param_symbols
3466          global to point to that at the end of this routine. */
3467
3468       /* elz: I added this new list of symbols which is local to the function.
3469          this list is the one which is actually used to build the type for the
3470          function rather than the gloabal list pointed to by symlist.
3471          Using a global list to keep track of the parameters is wrong, because 
3472          this function is called recursively if one parameter happend to be
3473          a function itself with more parameters in it. Adding parameters to the
3474          same global symbol list would not work!      
3475          Actually it did work in case of cc compiled programs where you do not check the
3476          parameter lists of the arguments.  */
3477       add_symbol_to_list (sym, &local_list);
3478     }
3479
3480   /* If type was read in earlier, don't bother with modifying
3481      the type struct */
3482   if (!record_args)
3483     goto finish;
3484
3485   /* Note how many parameters we found.  */
3486   TYPE_NFIELDS (type) = nsyms;
3487   TYPE_FIELDS (type) = (struct field *)
3488     obstack_alloc (&objfile->type_obstack,
3489                    sizeof (struct field) * nsyms);
3490
3491   /* Find the symbols for the parameters and 
3492      use them to fill parameter-type information into the function-type.
3493      The parameter symbols can be found in the local_list that we just put them on. */
3494   /* Note that we preserve the order of the parameters, so
3495      that in something like "enum {FOO, LAST_THING=FOO}" we print
3496      FOO, not LAST_THING.  */
3497
3498   /* get the parameters types from the local list not the global list
3499      so that the type can be correctly constructed for functions which
3500      have function as parameters
3501    */
3502   for (syms = local_list, n = 0; syms; syms = syms->next)
3503     {
3504       int j = 0;
3505       for (j = 0; j < syms->nsyms; j++, n++)
3506         {
3507           struct symbol *xsym = syms->symbol[j];
3508           TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym);
3509           TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
3510           TYPE_FIELD_ARTIFICIAL (type, n) = 0;
3511           TYPE_FIELD_BITSIZE (type, n) = 0;
3512           TYPE_FIELD_STATIC_KIND (type, n) = 0;
3513         }
3514     }
3515
3516   /* Mark it as having been processed */
3517   TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
3518
3519   /* Check whether we need to fix-up a class type with this function's type */
3520   if (fixup_class && (fixup_method == type))
3521     {
3522       fixup_class_method_type (fixup_class, fixup_method, objfile);
3523       fixup_class = NULL;
3524       fixup_method = NULL;
3525     }
3526
3527   /* Set the param list of this level of the context stack
3528      to our local list.  Do this only if this function was
3529      called for creating a new block, and not if it was called
3530      simply to get the function type. This prevents recursive
3531      invocations from trashing param_symbols. */
3532 finish:
3533   if (newblock)
3534     param_symbols = local_list;
3535
3536   return type;
3537 }
3538
3539
3540
3541 /* A file-level variable which keeps track of the current-template
3542  * being processed. Set in hpread_read_struct_type() while processing
3543  * a template type. Referred to in hpread_get_nth_templ_arg().
3544  * Yes, this is a kludge, but it arises from the kludge that already
3545  * exists in symtab.h, namely the fact that they encode
3546  * "template argument n" with fundamental type FT_TEMPLATE_ARG and
3547  * bitlength n. This means that deep in processing fundamental types
3548  * I need to ask the question "what template am I in the middle of?".
3549  * The alternative to stuffing a global would be to pass an argument
3550  * down the chain of calls just for this purpose.
3551  * 
3552  * There may be problems handling nested templates... tough.
3553  */
3554 static struct type *current_template = NULL;
3555
3556 /* Read in and internalize a structure definition.  
3557  * This same routine is called for struct, union, and class types.
3558  * Also called for templates, since they build a very similar
3559  * type entry as for class types.
3560  */
3561
3562 static struct type *
3563 hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp,
3564                          struct objfile *objfile)
3565 {
3566   /* The data members get linked together into a list of struct nextfield's */
3567   struct nextfield
3568     {
3569       struct nextfield *next;
3570       struct field field;
3571       unsigned char attributes; /* store visibility and virtuality info */
3572 #define ATTR_VIRTUAL 1
3573 #define ATTR_PRIVATE 2
3574 #define ATTR_PROTECT 3
3575     };
3576
3577
3578   /* The methods get linked together into a list of struct next_fn_field's */
3579   struct next_fn_field
3580     {
3581       struct next_fn_field *next;
3582       struct fn_fieldlist field;
3583       struct fn_field fn_field;
3584       int num_fn_fields;
3585     };
3586
3587   /* The template args get linked together into a list of struct next_template's */
3588   struct next_template
3589     {
3590       struct next_template *next;
3591       struct template_arg arg;
3592     };
3593
3594   /* The template instantiations get linked together into a list of these... */
3595   struct next_instantiation
3596     {
3597       struct next_instantiation *next;
3598       struct type *t;
3599     };
3600
3601   struct type *type;
3602   struct type *baseclass;
3603   struct type *memtype;
3604   struct nextfield *list = 0, *tmp_list = 0;
3605   struct next_fn_field *fn_list = 0;
3606   struct next_fn_field *fn_p;
3607   struct next_template *t_new, *t_list = 0;
3608   struct nextfield *new;
3609   struct next_fn_field *fn_new;
3610   struct next_instantiation *i_new, *i_list = 0;
3611   int n, nfields = 0, n_fn_fields = 0, n_fn_fields_total = 0;
3612   int n_base_classes = 0, n_templ_args = 0;
3613   int ninstantiations = 0;
3614   dnttpointer field, fn_field, parent;
3615   union dnttentry *fieldp, *fn_fieldp, *parentp;
3616   int i;
3617   int static_member = 0;
3618   int const_member = 0;
3619   int volatile_member = 0;
3620   unsigned long vtbl_offset;
3621   int need_bitvectors = 0;
3622   char *method_name = NULL;
3623   char *method_alias = NULL;
3624
3625
3626   /* Is it something we've already dealt with?  */
3627   type = hpread_alloc_type (hp_type, objfile);
3628   if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
3629       (TYPE_CODE (type) == TYPE_CODE_UNION) ||
3630       (TYPE_CODE (type) == TYPE_CODE_CLASS) ||
3631       (TYPE_CODE (type) == TYPE_CODE_TEMPLATE))
3632     return type;
3633
3634   /* Get the basic type correct.  */
3635   if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
3636     {
3637       TYPE_CODE (type) = TYPE_CODE_STRUCT;
3638       TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
3639     }
3640   else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
3641     {
3642       TYPE_CODE (type) = TYPE_CODE_UNION;
3643       TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
3644     }
3645   else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3646     {
3647       TYPE_CODE (type) = TYPE_CODE_CLASS;
3648       TYPE_LENGTH (type) = dn_bufp->dclass.bitlength / 8;
3649
3650       /* Overrides the TYPE_CPLUS_SPECIFIC(type) with allocated memory
3651        * rather than &cplus_struct_default.
3652        */
3653       allocate_cplus_struct_type (type);
3654
3655       /* Fill in declared-type.
3656        * (The C++ compiler will emit TYPE_CODE_CLASS 
3657        * for all 3 of "class", "struct"
3658        * "union", and we have to look at the "class_decl" field if we
3659        * want to know how it was really declared)
3660        */
3661       /* (0==class, 1==union, 2==struct) */
3662       TYPE_DECLARED_TYPE (type) = dn_bufp->dclass.class_decl;
3663     }
3664   else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3665     {
3666       /* Get the basic type correct.  */
3667       TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
3668       allocate_cplus_struct_type (type);
3669       TYPE_DECLARED_TYPE (type) = DECLARED_TYPE_TEMPLATE;
3670     }
3671   else
3672     return type;
3673
3674
3675   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3676
3677   /* For classes, read the parent list.
3678    * Question (RT): Do we need to do this for templates also?
3679    */
3680   if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3681     {
3682
3683       /* First read the parent-list (classes from which we derive fields) */
3684       parent = dn_bufp->dclass.parentlist;
3685       while (parent.word && parent.word != DNTTNIL)
3686         {
3687           parentp = hpread_get_lntt (parent.dnttp.index, objfile);
3688
3689           /* "parentp" should point to a DNTT_TYPE_INHERITANCE record */
3690
3691           /* Get space to record the next field/data-member. */
3692           new = (struct nextfield *) alloca (sizeof (struct nextfield));
3693           new->next = list;
3694           list = new;
3695
3696           FIELD_BITSIZE (list->field) = 0;
3697           FIELD_STATIC_KIND (list->field) = 0;
3698
3699           /* The "classname" field is actually a DNTT pointer to the base class */
3700           baseclass = hpread_type_lookup (parentp->dinheritance.classname,
3701                                           objfile);
3702           FIELD_TYPE (list->field) = baseclass;
3703
3704           list->field.name = type_name_no_tag (FIELD_TYPE (list->field));
3705
3706           list->attributes = 0;
3707
3708           /* Check for virtuality of base, and set the
3709            * offset of the base subobject within the object.
3710            * (Offset set to -1 for virtual bases (for now).)
3711            */
3712           if (parentp->dinheritance.Virtual)
3713             {
3714               B_SET (&(list->attributes), ATTR_VIRTUAL);
3715               parentp->dinheritance.offset = -1;
3716             }
3717           else
3718             FIELD_BITPOS (list->field) = parentp->dinheritance.offset;
3719
3720           /* Check visibility */
3721           switch (parentp->dinheritance.visibility)
3722             {
3723             case 1:
3724               B_SET (&(list->attributes), ATTR_PROTECT);
3725               break;
3726             case 2:
3727               B_SET (&(list->attributes), ATTR_PRIVATE);
3728               break;
3729             }
3730
3731           n_base_classes++;
3732           nfields++;
3733
3734           parent = parentp->dinheritance.next;
3735         }
3736     }
3737
3738   /* For templates, read the template argument list.
3739    * This must be done before processing the member list, because
3740    * the member list may refer back to this. E.g.:
3741    *   template <class T1, class T2> class q2 {
3742    *     public:
3743    *     T1 a;
3744    *     T2 b;
3745    *   };
3746    * We need to read the argument list "T1", "T2" first.
3747    */
3748   if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3749     {
3750       /* Kludge alert: This stuffs a global "current_template" which
3751        * is referred to by hpread_get_nth_templ_arg(). The global
3752        * is cleared at the end of this routine.
3753        */
3754       current_template = type;
3755
3756       /* Read in the argument list */
3757       field = dn_bufp->dtemplate.arglist;
3758       while (field.word && field.word != DNTTNIL)
3759         {
3760           /* Get this template argument */
3761           fieldp = hpread_get_lntt (field.dnttp.index, objfile);
3762           if (fieldp->dblock.kind != DNTT_TYPE_TEMPLATE_ARG)
3763             {
3764               warning ("Invalid debug info: Template argument entry is of wrong kind");
3765               break;
3766             }
3767           /* Bump the count */
3768           n_templ_args++;
3769           /* Allocate and fill in a struct next_template */
3770           t_new = (struct next_template *) alloca (sizeof (struct next_template));
3771           t_new->next = t_list;
3772           t_list = t_new;
3773           t_list->arg.name = VT (objfile) + fieldp->dtempl_arg.name;
3774           t_list->arg.type = hpread_read_templ_arg_type (field, fieldp,
3775                                                  objfile, t_list->arg.name);
3776           /* Walk to the next template argument */
3777           field = fieldp->dtempl_arg.nextarg;
3778         }
3779     }
3780
3781   TYPE_NTEMPLATE_ARGS (type) = n_templ_args;
3782
3783   if (n_templ_args > 0)
3784     TYPE_TEMPLATE_ARGS (type) = (struct template_arg *)
3785       obstack_alloc (&objfile->type_obstack, sizeof (struct template_arg) * n_templ_args);
3786   for (n = n_templ_args; t_list; t_list = t_list->next)
3787     {
3788       n -= 1;
3789       TYPE_TEMPLATE_ARG (type, n) = t_list->arg;
3790     }
3791
3792   /* Next read in and internalize all the fields/members.  */
3793   if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
3794     field = dn_bufp->dstruct.firstfield;
3795   else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
3796     field = dn_bufp->dunion.firstfield;
3797   else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
3798     field = dn_bufp->dclass.memberlist;
3799   else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3800     field = dn_bufp->dtemplate.memberlist;
3801   else
3802     field.word = DNTTNIL;
3803
3804   while (field.word && field.word != DNTTNIL)
3805     {
3806       fieldp = hpread_get_lntt (field.dnttp.index, objfile);
3807
3808       /* At this point "fieldp" may point to either a DNTT_TYPE_FIELD
3809        * or a DNTT_TYPE_GENFIELD record. 
3810        */
3811       vtbl_offset = 0;
3812       static_member = 0;
3813       const_member = 0;
3814       volatile_member = 0;
3815
3816       if (fieldp->dblock.kind == DNTT_TYPE_GENFIELD)
3817         {
3818
3819           /* The type will be GENFIELD if the field is a method or
3820            * a static member (or some other cases -- see below)
3821            */
3822
3823           /* Follow a link to get to the record for the field. */
3824           fn_field = fieldp->dgenfield.field;
3825           fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3826
3827           /* Virtual funcs are indicated by a VFUNC which points to the
3828            * real entry
3829            */
3830           if (fn_fieldp->dblock.kind == DNTT_TYPE_VFUNC)
3831             {
3832               vtbl_offset = fn_fieldp->dvfunc.vtbl_offset;
3833               fn_field = fn_fieldp->dvfunc.funcptr;
3834               fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3835             }
3836
3837           /* A function's entry may be preceded by a modifier which
3838            * labels it static/constant/volatile.
3839            */
3840           if (fn_fieldp->dblock.kind == DNTT_TYPE_MODIFIER)
3841             {
3842               static_member = fn_fieldp->dmodifier.m_static;
3843               const_member = fn_fieldp->dmodifier.m_const;
3844               volatile_member = fn_fieldp->dmodifier.m_volatile;
3845               fn_field = fn_fieldp->dmodifier.type;
3846               fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
3847             }
3848
3849           /* Check whether we have a method */
3850           if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
3851               (fn_fieldp->dblock.kind == DNTT_TYPE_FUNCTION) ||
3852               (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) ||
3853               (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_FUNCTION))
3854             {
3855               /* Method found */
3856
3857               short ix = 0;
3858
3859               /* Look up function type of method */
3860               memtype = hpread_type_lookup (fn_field, objfile);
3861
3862               /* Methods can be seen before classes in the SOM records.
3863                  If we are processing this class because it's a parameter of a
3864                  method, at this point the method's type is actually incomplete;
3865                  we'll have to fix it up later; mark the class for this. */
3866
3867               if (TYPE_INCOMPLETE (memtype))
3868                 {
3869                   TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
3870                   if (fixup_class)
3871                     warning ("Two classes to fix up for method??  Type information may be incorrect for some classes.");
3872                   if (fixup_method)
3873                     warning ("Two methods to be fixed up at once?? Type information may be incorrect for some classes.");
3874                   fixup_class = type;   /* remember this class has to be fixed up */
3875                   fixup_method = memtype;       /* remember the method type to be used in fixup */
3876                 }
3877
3878               /* HP aCC generates operator names without the "operator" keyword, and
3879                  generates null strings as names for operators that are 
3880                  user-defined type conversions to basic types (e.g. operator int ()).
3881                  So try to reconstruct name as best as possible. */
3882
3883               method_name = (char *) (VT (objfile) + fn_fieldp->dfunc.name);
3884               method_alias = (char *) (VT (objfile) + fn_fieldp->dfunc.alias);
3885
3886               if (!method_name ||       /* no name */
3887                   !*method_name ||      /* or null name */
3888                   cplus_mangle_opname (method_name, DMGL_ANSI))         /* or name is an operator like "<" */
3889                 {
3890                   char *tmp_name = cplus_demangle (method_alias, DMGL_ANSI);
3891                   char *op_string = strstr (tmp_name, "operator");
3892                   method_name = xmalloc (strlen (op_string) + 1);       /* don't overwrite VT! */
3893                   strcpy (method_name, op_string);
3894                 }
3895
3896               /* First check if a method of the same name has already been seen. */
3897               fn_p = fn_list;
3898               while (fn_p)
3899                 {
3900                   if (STREQ (fn_p->field.name, method_name))
3901                     break;
3902                   fn_p = fn_p->next;
3903                 }
3904
3905               /* If no such method was found, allocate a new entry in the list */
3906               if (!fn_p)
3907                 {
3908                   /* Get space to record this member function */
3909                   /* Note: alloca used; this will disappear on routine exit */
3910                   fn_new = (struct next_fn_field *) alloca (sizeof (struct next_fn_field));
3911                   fn_new->next = fn_list;
3912                   fn_list = fn_new;
3913
3914                   /* Fill in the fields of the struct nextfield */
3915
3916                   /* Record the (unmangled) method name */
3917                   fn_list->field.name = method_name;
3918                   /* Initial space for overloaded methods */
3919                   /* Note: xmalloc is used; this will persist after this routine exits */
3920                   fn_list->field.fn_fields = (struct fn_field *) xmalloc (5 * (sizeof (struct fn_field)));
3921                   fn_list->field.length = 1;    /* Init # of overloaded instances */
3922                   fn_list->num_fn_fields = 5;   /* # of entries for which space allocated */
3923                   fn_p = fn_list;
3924                   ix = 0;       /* array index for fn_field */
3925                   /* Bump the total count of the distinctly named methods */
3926                   n_fn_fields++;
3927                 }
3928               else
3929                 /* Another overloaded instance of an already seen method name */
3930                 {
3931                   if (++(fn_p->field.length) > fn_p->num_fn_fields)
3932                     {
3933                       /* Increase space allocated for overloaded instances */
3934                       fn_p->field.fn_fields
3935                         = (struct fn_field *) xrealloc (fn_p->field.fn_fields,
3936                       (fn_p->num_fn_fields + 5) * sizeof (struct fn_field));
3937                       fn_p->num_fn_fields += 5;
3938                     }
3939                   ix = fn_p->field.length - 1;  /* array index for fn_field */
3940                 }
3941
3942               /* "physname" is intended to be the name of this overloaded instance. */
3943               if ((fn_fieldp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
3944                   method_alias &&
3945                   *method_alias)        /* not a null string */
3946                 fn_p->field.fn_fields[ix].physname = method_alias;
3947               else
3948                 fn_p->field.fn_fields[ix].physname = method_name;
3949               /* What's expected here is the function type */
3950               /* But mark it as NULL if the method was incompletely processed
3951                  We'll fix this up later when the method is fully processed */
3952               if (TYPE_INCOMPLETE (memtype))
3953                 fn_p->field.fn_fields[ix].type = NULL;
3954               else
3955                 fn_p->field.fn_fields[ix].type = memtype;
3956
3957               /* For virtual functions, fill in the voffset field with the
3958                * virtual table offset. (This is just copied over from the
3959                * SOM record; not sure if it is what GDB expects here...).
3960                * But if the function is a static method, set it to 1.
3961                * 
3962                * Note that we have to add 1 because 1 indicates a static
3963                * method, and 0 indicates a non-static, non-virtual method */
3964
3965               if (static_member)
3966                 fn_p->field.fn_fields[ix].voffset = VOFFSET_STATIC;
3967               else
3968                 fn_p->field.fn_fields[ix].voffset = vtbl_offset ? vtbl_offset + 1 : 0;
3969
3970               /* Also fill in the fcontext field with the current
3971                * class. (The latter isn't quite right: should be the baseclass
3972                * that defines the virtual function... Note we do have
3973                * a variable "baseclass" that we could stuff into the fcontext
3974                * field, but "baseclass" isn't necessarily right either,
3975                * since the virtual function could have been defined more
3976                * than one level up).
3977                */
3978
3979               if (vtbl_offset != 0)
3980                 fn_p->field.fn_fields[ix].fcontext = type;
3981               else
3982                 fn_p->field.fn_fields[ix].fcontext = NULL;
3983
3984               /* Other random fields pertaining to this method */
3985               fn_p->field.fn_fields[ix].is_const = const_member;
3986               fn_p->field.fn_fields[ix].is_volatile = volatile_member;  /* ?? */
3987               switch (fieldp->dgenfield.visibility)
3988                 {
3989                 case 1:
3990                   fn_p->field.fn_fields[ix].is_protected = 1;
3991                   fn_p->field.fn_fields[ix].is_private = 0;
3992                   break;
3993                 case 2:
3994                   fn_p->field.fn_fields[ix].is_protected = 0;
3995                   fn_p->field.fn_fields[ix].is_private = 1;
3996                   break;
3997                 default:        /* public */
3998                   fn_p->field.fn_fields[ix].is_protected = 0;
3999                   fn_p->field.fn_fields[ix].is_private = 0;
4000                 }
4001               fn_p->field.fn_fields[ix].is_stub = 0;
4002
4003               /* HP aCC emits both MEMFUNC and FUNCTION entries for a method;
4004                  if the class points to the FUNCTION, there is usually separate
4005                  code for the method; but if we have a MEMFUNC, the method has
4006                  been inlined (and there is usually no FUNCTION entry)
4007                  FIXME Not sure if this test is accurate. pai/1997-08-22 */
4008               if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
4009                   (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC))
4010                 fn_p->field.fn_fields[ix].is_inlined = 1;
4011               else
4012                 fn_p->field.fn_fields[ix].is_inlined = 0;
4013
4014               fn_p->field.fn_fields[ix].dummy = 0;
4015
4016               /* Bump the total count of the member functions */
4017               n_fn_fields_total++;
4018
4019             }
4020           else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
4021             {
4022               /* This case is for static data members of classes */
4023
4024               /* pai:: FIXME -- check that "staticmem" bit is set */
4025
4026               /* Get space to record this static member */
4027               new = (struct nextfield *) alloca (sizeof (struct nextfield));
4028               new->next = list;
4029               list = new;
4030
4031               list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
4032               SET_FIELD_PHYSNAME (list->field, 0);      /* initialize to empty */
4033               memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
4034
4035               FIELD_TYPE (list->field) = memtype;
4036               list->attributes = 0;
4037               switch (fieldp->dgenfield.visibility)
4038                 {
4039                 case 1:
4040                   B_SET (&(list->attributes), ATTR_PROTECT);
4041                   break;
4042                 case 2:
4043                   B_SET (&(list->attributes), ATTR_PRIVATE);
4044                   break;
4045                 }
4046               nfields++;
4047             }
4048
4049           else if (fn_fieldp->dblock.kind == DNTT_TYPE_FIELD)
4050             {
4051               /* FIELDs follow GENFIELDs for fields of anonymous unions.
4052                  Code below is replicated from the case for FIELDs further
4053                  below, except that fieldp is replaced by fn_fieldp */
4054               if (!fn_fieldp->dfield.a_union)
4055                 warning ("Debug info inconsistent: FIELD of anonymous union doesn't have a_union bit set");
4056               /* Get space to record the next field/data-member. */
4057               new = (struct nextfield *) alloca (sizeof (struct nextfield));
4058               new->next = list;
4059               list = new;
4060
4061               list->field.name = VT (objfile) + fn_fieldp->dfield.name;
4062               FIELD_BITPOS (list->field) = fn_fieldp->dfield.bitoffset;
4063               if (fn_fieldp->dfield.bitlength % 8)
4064                 list->field.bitsize = fn_fieldp->dfield.bitlength;
4065               else
4066                 list->field.bitsize = 0;
4067
4068               memtype = hpread_type_lookup (fn_fieldp->dfield.type, objfile);
4069               list->field.type = memtype;
4070               list->attributes = 0;
4071               switch (fn_fieldp->dfield.visibility)
4072                 {
4073                 case 1:
4074                   B_SET (&(list->attributes), ATTR_PROTECT);
4075                   break;
4076                 case 2:
4077                   B_SET (&(list->attributes), ATTR_PRIVATE);
4078                   break;
4079                 }
4080               nfields++;
4081             }
4082           else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
4083             {
4084               /* Field of anonymous union; union is not inside a class */
4085               if (!fn_fieldp->dsvar.a_union)
4086                 warning ("Debug info inconsistent: SVAR field in anonymous union doesn't have a_union bit set");
4087               /* Get space to record the next field/data-member. */
4088               new = (struct nextfield *) alloca (sizeof (struct nextfield));
4089               new->next = list;
4090               list = new;
4091
4092               list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
4093               FIELD_BITPOS (list->field) = 0;   /* FIXME is this always true? */
4094               FIELD_BITSIZE (list->field) = 0;  /* use length from type */
4095               FIELD_STATIC_KIND (list->field) = 0;
4096               memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
4097               list->field.type = memtype;
4098               list->attributes = 0;
4099               /* No info to set visibility -- always public */
4100               nfields++;
4101             }
4102           else if (fn_fieldp->dblock.kind == DNTT_TYPE_DVAR)
4103             {
4104               /* Field of anonymous union; union is not inside a class */
4105               if (!fn_fieldp->ddvar.a_union)
4106                 warning ("Debug info inconsistent: DVAR field in anonymous union doesn't have a_union bit set");
4107               /* Get space to record the next field/data-member. */
4108               new = (struct nextfield *) alloca (sizeof (struct nextfield));
4109               new->next = list;
4110               list = new;
4111
4112               list->field.name = VT (objfile) + fn_fieldp->ddvar.name;
4113               FIELD_BITPOS (list->field) = 0;   /* FIXME is this always true? */
4114               FIELD_BITSIZE (list->field) = 0;  /* use length from type */
4115               FIELD_STATIC_KIND (list->field) = 0;
4116               memtype = hpread_type_lookup (fn_fieldp->ddvar.type, objfile);
4117               list->field.type = memtype;
4118               list->attributes = 0;
4119               /* No info to set visibility -- always public */
4120               nfields++;
4121             }
4122           else
4123             {                   /* Not a method, nor a static data member, nor an anon union field */
4124
4125               /* This case is for miscellaneous type entries (local enums,
4126                  local function templates, etc.) that can be present
4127                  inside a class. */
4128
4129               /* Enums -- will be handled by other code that takes care
4130                  of DNTT_TYPE_ENUM; here we see only DNTT_TYPE_MEMENUM so
4131                  it's not clear we could have handled them here at all. */
4132               /* FUNC_TEMPLATE: is handled by other code (?). */
4133               /* MEMACCESS: modified access for inherited member. Not
4134                  sure what to do with this, ignoriing it at present. */
4135
4136               /* What other entries can appear following a GENFIELD which
4137                  we do not handle above?  (MODIFIER, VFUNC handled above.) */
4138
4139               if ((fn_fieldp->dblock.kind != DNTT_TYPE_MEMACCESS) &&
4140                   (fn_fieldp->dblock.kind != DNTT_TYPE_MEMENUM) &&
4141                   (fn_fieldp->dblock.kind != DNTT_TYPE_FUNC_TEMPLATE))
4142                 warning ("Internal error: Unexpected debug record kind %d found following DNTT_GENFIELD",
4143                          fn_fieldp->dblock.kind);
4144             }
4145           /* walk to the next FIELD or GENFIELD */
4146           field = fieldp->dgenfield.nextfield;
4147
4148         }
4149       else if (fieldp->dblock.kind == DNTT_TYPE_FIELD)
4150         {
4151
4152           /* Ordinary structure/union/class field */
4153           struct type *anon_union_type;
4154
4155           /* Get space to record the next field/data-member. */
4156           new = (struct nextfield *) alloca (sizeof (struct nextfield));
4157           new->next = list;
4158           list = new;
4159
4160           list->field.name = VT (objfile) + fieldp->dfield.name;
4161
4162
4163           /* A FIELD by itself (without a GENFIELD) can also be a static member */
4164           FIELD_STATIC_KIND (list->field) = 0;
4165           if (fieldp->dfield.staticmem)
4166             {
4167               FIELD_BITPOS (list->field) = -1;
4168               FIELD_BITSIZE (list->field) = 0;
4169             }
4170           else
4171             /* Non-static data member */
4172             {
4173               FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
4174               if (fieldp->dfield.bitlength % 8)
4175                 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
4176               else
4177                 FIELD_BITSIZE (list->field) = 0;
4178             }
4179
4180           memtype = hpread_type_lookup (fieldp->dfield.type, objfile);
4181           FIELD_TYPE (list->field) = memtype;
4182           list->attributes = 0;
4183           switch (fieldp->dfield.visibility)
4184             {
4185             case 1:
4186               B_SET (&(list->attributes), ATTR_PROTECT);
4187               break;
4188             case 2:
4189               B_SET (&(list->attributes), ATTR_PRIVATE);
4190               break;
4191             }
4192           nfields++;
4193
4194
4195           /* Note 1: First, we have to check if the current field is an anonymous
4196              union. If it is, then *its* fields are threaded along in the
4197              nextfield chain. :-( This was supposed to help debuggers, but is
4198              really just a nuisance since we deal with anonymous unions anyway by
4199              checking that the name is null.  So anyway, we skip over the fields
4200              of the anonymous union. pai/1997-08-22 */
4201           /* Note 2: In addition, the bitoffsets for the fields of the anon union
4202              are relative to the enclosing struct, *NOT* relative to the anon
4203              union!  This is an even bigger nuisance -- we have to go in and munge
4204              the anon union's type information appropriately. pai/1997-08-22 */
4205
4206           /* Both tasks noted above are done by a separate function.  This takes us
4207              to the next FIELD or GENFIELD, skipping anon unions, and recursively
4208              processing intermediate types. */
4209           field = hpread_get_next_skip_over_anon_unions (1, field, &fieldp, objfile);
4210
4211         }
4212       else
4213         {
4214           /* neither field nor genfield ?? is this possible?? */
4215           /* pai:: FIXME walk to the next -- how? */
4216           warning ("Internal error: unexpected DNTT kind %d encountered as field of struct",
4217                    fieldp->dblock.kind);
4218           warning ("Skipping remaining fields of struct");
4219           break;                /* get out of loop of fields */
4220         }
4221     }
4222
4223   /* If it's a template, read in the instantiation list */
4224   if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
4225     {
4226       ninstantiations = 0;
4227       field = dn_bufp->dtemplate.expansions;
4228       while (field.word && field.word != DNTTNIL)
4229         {
4230           fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4231
4232           /* The expansions or nextexp should point to a tagdef */
4233           if (fieldp->dblock.kind != DNTT_TYPE_TAGDEF)
4234             break;
4235
4236           i_new = (struct next_instantiation *) alloca (sizeof (struct next_instantiation));
4237           i_new->next = i_list;
4238           i_list = i_new;
4239           i_list->t = hpread_type_lookup (field, objfile);
4240           ninstantiations++;
4241
4242           /* And the "type" field of that should point to a class */
4243           field = fieldp->dtag.type;
4244           fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4245           if (fieldp->dblock.kind != DNTT_TYPE_CLASS)
4246             break;
4247
4248           /* Get the next expansion */
4249           field = fieldp->dclass.nextexp;
4250         }
4251     }
4252   TYPE_NINSTANTIATIONS (type) = ninstantiations;
4253   if (ninstantiations > 0)
4254     TYPE_INSTANTIATIONS (type) = (struct type **)
4255       obstack_alloc (&objfile->type_obstack, sizeof (struct type *) * ninstantiations);
4256   for (n = ninstantiations; i_list; i_list = i_list->next)
4257     {
4258       n -= 1;
4259       TYPE_INSTANTIATION (type, n) = i_list->t;
4260     }
4261
4262
4263   /* Copy the field-list to GDB's symbol table */
4264   TYPE_NFIELDS (type) = nfields;
4265   TYPE_N_BASECLASSES (type) = n_base_classes;
4266   TYPE_FIELDS (type) = (struct field *)
4267     obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
4268   /* Copy the saved-up fields into the field vector.  */
4269   for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
4270     {
4271       n -= 1;
4272       TYPE_FIELD (type, n) = tmp_list->field;
4273     }
4274
4275   /* Copy the "function-field-list" (i.e., the list of member
4276    * functions in the class) to GDB's symbol table 
4277    */
4278   TYPE_NFN_FIELDS (type) = n_fn_fields;
4279   TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total;
4280   TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
4281     obstack_alloc (&objfile->type_obstack, sizeof (struct fn_fieldlist) * n_fn_fields);
4282   for (n = n_fn_fields; fn_list; fn_list = fn_list->next)
4283     {
4284       n -= 1;
4285       TYPE_FN_FIELDLIST (type, n) = fn_list->field;
4286     }
4287
4288   /* pai:: FIXME -- perhaps each bitvector should be created individually */
4289   for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
4290     {
4291       n -= 1;
4292       if (tmp_list->attributes)
4293         {
4294           need_bitvectors = 1;
4295           break;
4296         }
4297     }
4298
4299   if (need_bitvectors)
4300     {
4301       /* pai:: this step probably redundant */
4302       ALLOCATE_CPLUS_STRUCT_TYPE (type);
4303
4304       TYPE_FIELD_VIRTUAL_BITS (type) =
4305         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4306       B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), nfields);
4307
4308       TYPE_FIELD_PRIVATE_BITS (type) =
4309         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4310       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4311
4312       TYPE_FIELD_PROTECTED_BITS (type) =
4313         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4314       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4315
4316       /* this field vector isn't actually used with HP aCC */
4317       TYPE_FIELD_IGNORE_BITS (type) =
4318         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4319       B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4320
4321       while (nfields-- > 0)
4322         {
4323           if (B_TST (&(list->attributes), ATTR_VIRTUAL))
4324             SET_TYPE_FIELD_VIRTUAL (type, nfields);
4325           if (B_TST (&(list->attributes), ATTR_PRIVATE))
4326             SET_TYPE_FIELD_PRIVATE (type, nfields);
4327           if (B_TST (&(list->attributes), ATTR_PROTECT))
4328             SET_TYPE_FIELD_PROTECTED (type, nfields);
4329
4330           list = list->next;
4331         }
4332     }
4333   else
4334     {
4335       TYPE_FIELD_VIRTUAL_BITS (type) = NULL;
4336       TYPE_FIELD_PROTECTED_BITS (type) = NULL;
4337       TYPE_FIELD_PRIVATE_BITS (type) = NULL;
4338     }
4339
4340   if (has_vtable (type))
4341     {
4342       /* Allocate space for class runtime information */
4343       TYPE_RUNTIME_PTR (type) = (struct runtime_info *) xmalloc (sizeof (struct runtime_info));
4344       /* Set flag for vtable */
4345       TYPE_VTABLE (type) = 1;
4346       /* The first non-virtual base class with a vtable. */
4347       TYPE_PRIMARY_BASE (type) = primary_base_class (type);
4348       /* The virtual base list. */
4349       TYPE_VIRTUAL_BASE_LIST (type) = virtual_base_list (type);
4350     }
4351   else
4352     TYPE_RUNTIME_PTR (type) = NULL;
4353
4354   /* If this is a local type (C++ - declared inside a function), record file name & line # */
4355   if (hpread_get_scope_depth (dn_bufp, objfile, 1 /* no need for real depth */ ))
4356     {
4357       TYPE_LOCALTYPE_PTR (type) = (struct local_type_info *) xmalloc (sizeof (struct local_type_info));
4358       TYPE_LOCALTYPE_FILE (type) = (char *) xmalloc (strlen (current_subfile->name) + 1);
4359       strcpy (TYPE_LOCALTYPE_FILE (type), current_subfile->name);
4360       if (current_subfile->line_vector && (current_subfile->line_vector->nitems > 0))
4361         TYPE_LOCALTYPE_LINE (type) = current_subfile->line_vector->item[current_subfile->line_vector->nitems - 1].line;
4362       else
4363         TYPE_LOCALTYPE_LINE (type) = 0;
4364     }
4365   else
4366     TYPE_LOCALTYPE_PTR (type) = NULL;
4367
4368   /* Clear the global saying what template we are in the middle of processing */
4369   current_template = NULL;
4370
4371   return type;
4372 }
4373
4374 /* Adjust the physnames for each static member of a struct
4375    or class type to be something like "A::x"; then various
4376    other pieces of code that do a lookup_symbol on the phyname
4377    work correctly.
4378    TYPE is a pointer to the struct/class type
4379    NAME is a char * (string) which is the class/struct name
4380    Void return */
4381
4382 static void
4383 fix_static_member_physnames (struct type *type, char *class_name,
4384                              struct objfile *objfile)
4385 {
4386   int i;
4387
4388   /* We fix the member names only for classes or structs */
4389   if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
4390     return;
4391
4392   for (i = 0; i < TYPE_NFIELDS (type); i++)
4393     if (TYPE_FIELD_STATIC (type, i))
4394       {
4395         if (TYPE_FIELD_STATIC_PHYSNAME (type, i))
4396           return;               /* physnames are already set */
4397
4398         SET_FIELD_PHYSNAME (TYPE_FIELDS (type)[i],
4399                             obstack_alloc (&objfile->type_obstack,
4400              strlen (class_name) + strlen (TYPE_FIELD_NAME (type, i)) + 3));
4401         strcpy (TYPE_FIELD_STATIC_PHYSNAME (type, i), class_name);
4402         strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), "::");
4403         strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), TYPE_FIELD_NAME (type, i));
4404       }
4405 }
4406
4407 /* Fix-up the type structure for a CLASS so that the type entry
4408  * for a method (previously marked with a null type in hpread_read_struct_type()
4409  * is set correctly to METHOD.
4410  * OBJFILE is as for other such functions. 
4411  * Void return. */
4412
4413 static void
4414 fixup_class_method_type (struct type *class, struct type *method,
4415                          struct objfile *objfile)
4416 {
4417   int i, j, k;
4418
4419   if (!class || !method || !objfile)
4420     return;
4421
4422   /* Only for types that have methods */
4423   if ((TYPE_CODE (class) != TYPE_CODE_CLASS) &&
4424       (TYPE_CODE (class) != TYPE_CODE_UNION))
4425     return;
4426
4427   /* Loop over all methods and find the one marked with a NULL type */
4428   for (i = 0; i < TYPE_NFN_FIELDS (class); i++)
4429     for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (class, i); j++)
4430       if (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) == NULL)
4431         {
4432           /* Set the method type */
4433           TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) = method;
4434
4435           /* Break out of both loops -- only one method to fix up in a class */
4436           goto finish;
4437         }
4438
4439 finish:
4440   TYPE_FLAGS (class) &= ~TYPE_FLAG_INCOMPLETE;
4441 }
4442
4443
4444 /* If we're in the middle of processing a template, get a pointer
4445  * to the Nth template argument.
4446  * An example may make this clearer:
4447  *   template <class T1, class T2> class q2 {
4448  *     public:
4449  *     T1 a;
4450  *     T2 b;
4451  *   };
4452  * The type for "a" will be "first template arg" and
4453  * the type for "b" will be "second template arg".
4454  * We need to look these up in order to fill in "a" and "b"'s type.
4455  * This is called from hpread_type_lookup().
4456  */
4457 static struct type *
4458 hpread_get_nth_template_arg (struct objfile *objfile, int n)
4459 {
4460   if (current_template != NULL)
4461     return TYPE_TEMPLATE_ARG (current_template, n).type;
4462   else
4463     return lookup_fundamental_type (objfile, FT_TEMPLATE_ARG);
4464 }
4465
4466 /* Read in and internalize a TEMPL_ARG (template arg) symbol.  */
4467
4468 static struct type *
4469 hpread_read_templ_arg_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4470                             struct objfile *objfile, char *name)
4471 {
4472   struct type *type;
4473
4474   /* See if it's something we've already deal with.  */
4475   type = hpread_alloc_type (hp_type, objfile);
4476   if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE_ARG)
4477     return type;
4478
4479   /* Nope.  Fill in the appropriate fields.  */
4480   TYPE_CODE (type) = TYPE_CODE_TEMPLATE_ARG;
4481   TYPE_LENGTH (type) = 0;
4482   TYPE_NFIELDS (type) = 0;
4483   TYPE_NAME (type) = name;
4484   return type;
4485 }
4486
4487 /* Read in and internalize a set debug symbol.  */
4488
4489 static struct type *
4490 hpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4491                       struct objfile *objfile)
4492 {
4493   struct type *type;
4494
4495   /* See if it's something we've already deal with.  */
4496   type = hpread_alloc_type (hp_type, objfile);
4497   if (TYPE_CODE (type) == TYPE_CODE_SET)
4498     return type;
4499
4500   /* Nope.  Fill in the appropriate fields.  */
4501   TYPE_CODE (type) = TYPE_CODE_SET;
4502   TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
4503   TYPE_NFIELDS (type) = 0;
4504   TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
4505                                                 objfile);
4506   return type;
4507 }
4508
4509 /* Read in and internalize an array debug symbol.  */
4510
4511 static struct type *
4512 hpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4513                         struct objfile *objfile)
4514 {
4515   struct type *type;
4516
4517   /* Allocate an array type symbol.
4518    * Why no check for already-read here, like in the other
4519    * hpread_read_xxx_type routines?  Because it kept us 
4520    * from properly determining the size of the array!  
4521    */
4522   type = hpread_alloc_type (hp_type, objfile);
4523
4524   TYPE_CODE (type) = TYPE_CODE_ARRAY;
4525
4526   /* Although the hp-symtab.h does not *require* this to be the case,
4527    * GDB is assuming that "arrayisbytes" and "elemisbytes" be consistent.
4528    * I.e., express both array-length and element-length in bits,
4529    * or express both array-length and element-length in bytes.
4530    */
4531   if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes) ||
4532         (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
4533     {
4534       warning ("error in hpread_array_type.\n");
4535       return NULL;
4536     }
4537   else if (dn_bufp->darray.arraylength == 0x7fffffff)
4538     {
4539       /* The HP debug format represents char foo[]; as an array with
4540        * length 0x7fffffff.  Internally GDB wants to represent this
4541        *  as an array of length zero.  
4542        */
4543       TYPE_LENGTH (type) = 0;
4544     }
4545   else if (dn_bufp->darray.arrayisbytes)
4546     TYPE_LENGTH (type) = dn_bufp->darray.arraylength;
4547   else                          /* arraylength is in bits */
4548     TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
4549
4550   TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
4551                                                 objfile);
4552
4553   /* The one "field" is used to store the subscript type */
4554   /* Since C and C++ multi-dimensional arrays are simply represented
4555    * as: array of array of ..., we only need one subscript-type
4556    * per array. This subscript type is typically a subrange of integer.
4557    * If this gets extended to support languages like Pascal, then
4558    * we need to fix this to represent multi-dimensional arrays properly.
4559    */
4560   TYPE_NFIELDS (type) = 1;
4561   TYPE_FIELDS (type) = (struct field *)
4562     obstack_alloc (&objfile->type_obstack, sizeof (struct field));
4563   TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
4564                                                   objfile);
4565   return type;
4566 }
4567
4568 /* Read in and internalize a subrange debug symbol.  */
4569 static struct type *
4570 hpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp,
4571                            struct objfile *objfile)
4572 {
4573   struct type *type;
4574
4575   /* Is it something we've already dealt with.  */
4576   type = hpread_alloc_type (hp_type, objfile);
4577   if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4578     return type;
4579
4580   /* Nope, internalize it.  */
4581   TYPE_CODE (type) = TYPE_CODE_RANGE;
4582   TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
4583   TYPE_NFIELDS (type) = 2;
4584   TYPE_FIELDS (type)
4585     = (struct field *) obstack_alloc (&objfile->type_obstack,
4586                                       2 * sizeof (struct field));
4587
4588   if (dn_bufp->dsubr.dyn_low)
4589     TYPE_FIELD_BITPOS (type, 0) = 0;
4590   else
4591     TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
4592
4593   if (dn_bufp->dsubr.dyn_high)
4594     TYPE_FIELD_BITPOS (type, 1) = -1;
4595   else
4596     TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
4597   TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
4598                                                 objfile);
4599   return type;
4600 }
4601
4602 /* struct type * hpread_type_lookup(hp_type, objfile)
4603  *   Arguments:
4604  *     hp_type: A pointer into the DNTT specifying what type we
4605  *              are about to "look up"., or else [for fundamental types
4606  *              like int, float, ...] an "immediate" structure describing
4607  *              the type.
4608  *     objfile: ?
4609  *   Return value: A pointer to a "struct type" (representation of a
4610  *                 type in GDB's internal symbol table - see gdbtypes.h)
4611  *   Routine description:
4612  *     There are a variety of places when scanning the DNTT when we
4613  *     need to interpret a "type" field. The simplest and most basic 
4614  *     example is when we're processing the symbol table record
4615  *     for a data symbol (a SVAR or DVAR record). That has
4616  *     a "type" field specifying the type of the data symbol. That
4617  *     "type" field is either an "immediate" type specification (for the
4618  *     fundamental types) or a DNTT pointer (for more complicated types). 
4619  *     For the more complicated types, we may or may not have already
4620  *     processed the pointed-to type. (Multiple data symbols can of course
4621  *     share the same type).
4622  *     The job of hpread_type_lookup() is to process this "type" field.
4623  *     Most of the real work is done in subroutines. Here we interpret
4624  *     the immediate flag. If not immediate, chase the DNTT pointer to
4625  *     find our way to the SOM record describing the type, switch on
4626  *     the SOM kind, and then call an appropriate subroutine depending
4627  *     on what kind of type we are constructing. (e.g., an array type,
4628  *     a struct/class type, etc).
4629  */
4630 static struct type *
4631 hpread_type_lookup (dnttpointer hp_type, struct objfile *objfile)
4632 {
4633   union dnttentry *dn_bufp;
4634   struct type *tmp_type;
4635
4636   /* First see if it's a simple builtin type.  */
4637   if (hp_type.dntti.immediate)
4638     {
4639       /* If this is a template argument, the argument number is
4640        * encoded in the bitlength. All other cases, just return
4641        * GDB's representation of this fundamental type.
4642        */
4643       if (hp_type.dntti.type == HP_TYPE_TEMPLATE_ARG)
4644         return hpread_get_nth_template_arg (objfile, hp_type.dntti.bitlength);
4645       else
4646         return lookup_fundamental_type (objfile,
4647                                         hpread_type_translate (hp_type));
4648     }
4649
4650   /* Not a builtin type.  We'll have to read it in.  */
4651   if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
4652     dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
4653   else
4654     /* This is a fancy way of returning NULL */
4655     return lookup_fundamental_type (objfile, FT_VOID);
4656
4657   switch (dn_bufp->dblock.kind)
4658     {
4659     case DNTT_TYPE_SRCFILE:
4660     case DNTT_TYPE_MODULE:
4661     case DNTT_TYPE_ENTRY:
4662     case DNTT_TYPE_BEGIN:
4663     case DNTT_TYPE_END:
4664     case DNTT_TYPE_IMPORT:
4665     case DNTT_TYPE_LABEL:
4666     case DNTT_TYPE_FPARAM:
4667     case DNTT_TYPE_SVAR:
4668     case DNTT_TYPE_DVAR:
4669     case DNTT_TYPE_CONST:
4670     case DNTT_TYPE_MEMENUM:
4671     case DNTT_TYPE_VARIANT:
4672     case DNTT_TYPE_FILE:
4673     case DNTT_TYPE_WITH:
4674     case DNTT_TYPE_COMMON:
4675     case DNTT_TYPE_COBSTRUCT:
4676     case DNTT_TYPE_XREF:
4677     case DNTT_TYPE_SA:
4678     case DNTT_TYPE_MACRO:
4679     case DNTT_TYPE_BLOCKDATA:
4680     case DNTT_TYPE_CLASS_SCOPE:
4681     case DNTT_TYPE_MEMACCESS:
4682     case DNTT_TYPE_INHERITANCE:
4683     case DNTT_TYPE_OBJECT_ID:
4684     case DNTT_TYPE_FRIEND_CLASS:
4685     case DNTT_TYPE_FRIEND_FUNC:
4686       /* These are not types - something went wrong.  */
4687       /* This is a fancy way of returning NULL */
4688       return lookup_fundamental_type (objfile, FT_VOID);
4689
4690     case DNTT_TYPE_FUNCTION:
4691       /* We wind up here when dealing with class member functions 
4692        * (called from hpread_read_struct_type(), i.e. when processing
4693        * the class definition itself).
4694        */
4695       return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4696
4697     case DNTT_TYPE_DOC_FUNCTION:
4698       return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
4699
4700     case DNTT_TYPE_TYPEDEF:
4701       {
4702         /* A typedef - chase it down by making a recursive call */
4703         struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
4704                                                       objfile);
4705
4706         /* The following came from the base hpread.c that we inherited.
4707          * It is WRONG so I have commented it out. - RT
4708          *...
4709
4710          char *suffix;
4711          suffix = VT (objfile) + dn_bufp->dtype.name;
4712          TYPE_NAME (structtype) = suffix;
4713
4714          * ... further explanation ....
4715          *
4716          * What we have here is a typedef pointing to a typedef.
4717          * E.g.,
4718          * typedef int foo;
4719          * typedef foo fum;
4720          *
4721          * What we desire to build is (these are pictures
4722          * of "struct type"'s): 
4723          *
4724          *  +---------+     +----------+     +------------+
4725          *  | typedef |     | typedef  |     | fund. type |
4726          *  |     type| ->  |      type| ->  |            |
4727          *  | "fum"   |     | "foo"    |     | "int"      |
4728          *  +---------+     +----------+     +------------+
4729          *
4730          * What this commented-out code is doing is smashing the
4731          * name of pointed-to-type to be the same as the pointed-from
4732          * type. So we wind up with something like:
4733          *
4734          *  +---------+     +----------+     +------------+
4735          *  | typedef |     | typedef  |     | fund. type |
4736          *  |     type| ->  |      type| ->  |            |
4737          *  | "fum"   |     | "fum"    |     | "fum"      |
4738          *  +---------+     +----------+     +------------+
4739          * 
4740          */
4741
4742         return structtype;
4743       }
4744
4745     case DNTT_TYPE_TAGDEF:
4746       {
4747         /* Just a little different from above.  We have to tack on
4748          * an identifier of some kind (struct, union, enum, class, etc).  
4749          */
4750         struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
4751                                                       objfile);
4752         char *prefix, *suffix;
4753         suffix = VT (objfile) + dn_bufp->dtype.name;
4754
4755         /* Lookup the next type in the list.  It should be a structure,
4756          * union, class, enum, or template type.  
4757          * We will need to attach that to our name.  
4758          */
4759         if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
4760           dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
4761         else
4762           {
4763             complaint (&symfile_complaints, "error in hpread_type_lookup().");
4764             return NULL;
4765           }
4766
4767         if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
4768           {
4769             prefix = "struct ";
4770           }
4771         else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
4772           {
4773             prefix = "union ";
4774           }
4775         else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
4776           {
4777             /* Further field for CLASS saying how it was really declared */
4778             /* 0==class, 1==union, 2==struct */
4779             if (dn_bufp->dclass.class_decl == 0)
4780               prefix = "class ";
4781             else if (dn_bufp->dclass.class_decl == 1)
4782               prefix = "union ";
4783             else if (dn_bufp->dclass.class_decl == 2)
4784               prefix = "struct ";
4785             else
4786               prefix = "";
4787           }
4788         else if (dn_bufp->dblock.kind == DNTT_TYPE_ENUM)
4789           {
4790             prefix = "enum ";
4791           }
4792         else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
4793           {
4794             prefix = "template ";
4795           }
4796         else
4797           {
4798             prefix = "";
4799           }
4800
4801         /* Build the correct name.  */
4802         TYPE_NAME (structtype)
4803           = (char *) obstack_alloc (&objfile->type_obstack,
4804                                     strlen (prefix) + strlen (suffix) + 1);
4805         TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
4806         TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
4807         TYPE_TAG_NAME (structtype) = suffix;
4808
4809         /* For classes/structs, we have to set the static member "physnames"
4810            to point to strings like "Class::Member" */
4811         if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT)
4812           fix_static_member_physnames (structtype, suffix, objfile);
4813
4814         return structtype;
4815       }
4816
4817     case DNTT_TYPE_POINTER:
4818       /* Pointer type - call a routine in gdbtypes.c that constructs
4819        * the appropriate GDB type.
4820        */
4821       return make_pointer_type (
4822                                  hpread_type_lookup (dn_bufp->dptr.pointsto,
4823                                                      objfile),
4824                                  NULL);
4825
4826     case DNTT_TYPE_REFERENCE:
4827       /* C++ reference type - call a routine in gdbtypes.c that constructs
4828        * the appropriate GDB type.
4829        */
4830       return make_reference_type (
4831                            hpread_type_lookup (dn_bufp->dreference.pointsto,
4832                                                objfile),
4833                                    NULL);
4834
4835     case DNTT_TYPE_ENUM:
4836       return hpread_read_enum_type (hp_type, dn_bufp, objfile);
4837     case DNTT_TYPE_SET:
4838       return hpread_read_set_type (hp_type, dn_bufp, objfile);
4839     case DNTT_TYPE_SUBRANGE:
4840       return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
4841     case DNTT_TYPE_ARRAY:
4842       return hpread_read_array_type (hp_type, dn_bufp, objfile);
4843     case DNTT_TYPE_STRUCT:
4844     case DNTT_TYPE_UNION:
4845       return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4846     case DNTT_TYPE_FIELD:
4847       return hpread_type_lookup (dn_bufp->dfield.type, objfile);
4848
4849     case DNTT_TYPE_FUNCTYPE:
4850       /* Here we want to read the function SOMs and return a 
4851        * type for it. We get here, for instance, when processing
4852        * pointer-to-function type.
4853        */
4854       return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4855
4856     case DNTT_TYPE_PTRMEM:
4857       /* Declares a C++ pointer-to-data-member type. 
4858        * The "pointsto" field defines the class,
4859        * while the "memtype" field defines the pointed-to-type.
4860        */
4861       {
4862         struct type *ptrmemtype;
4863         struct type *class_type;
4864         struct type *memtype;
4865         memtype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
4866                                       objfile),
4867           class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
4868                                            objfile),
4869           ptrmemtype = alloc_type (objfile);
4870         smash_to_member_type (ptrmemtype, class_type, memtype);
4871         return make_pointer_type (ptrmemtype, NULL);
4872       }
4873       break;
4874
4875     case DNTT_TYPE_PTRMEMFUNC:
4876       /* Defines a C++ pointer-to-function-member type. 
4877        * The "pointsto" field defines the class,
4878        * while the "memtype" field defines the pointed-to-type.
4879        */
4880       {
4881         struct type *ptrmemtype;
4882         struct type *class_type;
4883         struct type *functype;
4884         struct type *retvaltype;
4885         int nargs;
4886         int i;
4887         class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
4888                                          objfile);
4889         functype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
4890                                        objfile);
4891         retvaltype = TYPE_TARGET_TYPE (functype);
4892         nargs = TYPE_NFIELDS (functype);
4893         ptrmemtype = alloc_type (objfile);
4894
4895         smash_to_method_type (ptrmemtype, class_type, retvaltype,
4896                               TYPE_FIELDS (functype),
4897                               TYPE_NFIELDS (functype),
4898                               0);
4899         return make_pointer_type (ptrmemtype, NULL);
4900       }
4901       break;
4902
4903     case DNTT_TYPE_CLASS:
4904       return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4905
4906     case DNTT_TYPE_GENFIELD:
4907       /* Chase pointer from GENFIELD to FIELD, and make recursive
4908        * call on that.
4909        */
4910       return hpread_type_lookup (dn_bufp->dgenfield.field, objfile);
4911
4912     case DNTT_TYPE_VFUNC:
4913       /* C++ virtual function.
4914        * We get here in the course of processing a class type which
4915        * contains virtual functions. Just go through another level
4916        * of indirection to get to the pointed-to function SOM.
4917        */
4918       return hpread_type_lookup (dn_bufp->dvfunc.funcptr, objfile);
4919
4920     case DNTT_TYPE_MODIFIER:
4921       /* Check the modifiers and then just make a recursive call on
4922        * the "type" pointed to by the modifier DNTT.
4923        * 
4924        * pai:: FIXME -- do we ever want to handle "m_duplicate" and
4925        * "m_void" modifiers?  Is static_flag really needed here?
4926        * (m_static used for methods of classes, elsewhere).
4927        */
4928       tmp_type = make_cv_type (dn_bufp->dmodifier.m_const,
4929                                dn_bufp->dmodifier.m_volatile,
4930                       hpread_type_lookup (dn_bufp->dmodifier.type, objfile),
4931                                0);
4932       return tmp_type;
4933
4934
4935     case DNTT_TYPE_MEMFUNC:
4936       /* Member function. Treat like a function.
4937        * I think we get here in the course of processing a 
4938        * pointer-to-member-function type...
4939        */
4940       return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4941
4942     case DNTT_TYPE_DOC_MEMFUNC:
4943       return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
4944
4945     case DNTT_TYPE_TEMPLATE:
4946       /* Template - sort of the header for a template definition,
4947        * which like a class, points to a member list and also points
4948        * to a TEMPLATE_ARG list of type-arguments.
4949        */
4950       return hpread_read_struct_type (hp_type, dn_bufp, objfile);
4951
4952     case DNTT_TYPE_TEMPLATE_ARG:
4953       {
4954         char *name;
4955         /* The TEMPLATE record points to an argument list of
4956          * TEMPLATE_ARG records, each of which describes one
4957          * of the type-arguments. 
4958          */
4959         name = VT (objfile) + dn_bufp->dtempl_arg.name;
4960         return hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name);
4961       }
4962
4963     case DNTT_TYPE_FUNC_TEMPLATE:
4964       /* We wind up here when processing a TEMPLATE type, 
4965        * if the template has member function(s).
4966        * Treat it like a FUNCTION.
4967        */
4968       return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
4969
4970     case DNTT_TYPE_LINK:
4971       /* The LINK record is used to link up templates with instantiations.
4972        * There is no type associated with the LINK record per se.
4973        */
4974       return lookup_fundamental_type (objfile, FT_VOID);
4975
4976       /* Also not yet handled... */
4977       /* case DNTT_TYPE_DYN_ARRAY_DESC: */
4978       /* case DNTT_TYPE_DESC_SUBRANGE: */
4979       /* case DNTT_TYPE_BEGIN_EXT: */
4980       /* case DNTT_TYPE_INLN: */
4981       /* case DNTT_TYPE_INLN_LIST: */
4982       /* case DNTT_TYPE_ALIAS: */
4983     default:
4984       /* A fancy way of returning NULL */
4985       return lookup_fundamental_type (objfile, FT_VOID);
4986     }
4987 }
4988
4989 static sltpointer
4990 hpread_record_lines (struct subfile *subfile, sltpointer s_idx,
4991                      sltpointer e_idx, struct objfile *objfile,
4992                      CORE_ADDR offset)
4993 {
4994   union sltentry *sl_bufp;
4995
4996   while (s_idx <= e_idx)
4997     {
4998       sl_bufp = hpread_get_slt (s_idx, objfile);
4999       /* Only record "normal" entries in the SLT.  */
5000       if (sl_bufp->snorm.sltdesc == SLT_NORMAL
5001           || sl_bufp->snorm.sltdesc == SLT_EXIT)
5002         record_line (subfile, sl_bufp->snorm.line,
5003                      sl_bufp->snorm.address + offset);
5004       else if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
5005         record_line (subfile, sl_bufp->snormoff.line,
5006                      sl_bufp->snormoff.address + offset);
5007       s_idx++;
5008     }
5009   return e_idx;
5010 }
5011
5012 /* Given a function "f" which is a member of a class, find
5013  * the classname that it is a member of. Used to construct
5014  * the name (e.g., "c::f") which GDB will put in the
5015  * "demangled name" field of the function's symbol.
5016  * Called from hpread_process_one_debug_symbol()
5017  * If "f" is not a member function, return NULL.
5018  */
5019 char *
5020 class_of (struct type *functype)
5021 {
5022   struct type *first_param_type;
5023   char *first_param_name;
5024   struct type *pointed_to_type;
5025   char *class_name;
5026
5027   /* Check that the function has a first argument "this",
5028    * and that "this" is a pointer to a class. If not,
5029    * functype is not a member function, so return NULL.
5030    */
5031   if (TYPE_NFIELDS (functype) == 0)
5032     return NULL;
5033   first_param_name = TYPE_FIELD_NAME (functype, 0);
5034   if (first_param_name == NULL)
5035     return NULL;                /* paranoia */
5036   if (strcmp (first_param_name, "this"))
5037     return NULL;
5038   first_param_type = TYPE_FIELD_TYPE (functype, 0);
5039   if (first_param_type == NULL)
5040     return NULL;                /* paranoia */
5041   if (TYPE_CODE (first_param_type) != TYPE_CODE_PTR)
5042     return NULL;
5043
5044   /* Get the thing that "this" points to, check that
5045    * it's a class, and get its class name.
5046    */
5047   pointed_to_type = TYPE_TARGET_TYPE (first_param_type);
5048   if (pointed_to_type == NULL)
5049     return NULL;                /* paranoia */
5050   if (TYPE_CODE (pointed_to_type) != TYPE_CODE_CLASS)
5051     return NULL;
5052   class_name = TYPE_NAME (pointed_to_type);
5053   if (class_name == NULL)
5054     return NULL;                /* paranoia */
5055
5056   /* The class name may be of the form "class c", in which case
5057    * we want to strip off the leading "class ".
5058    */
5059   if (strncmp (class_name, "class ", 6) == 0)
5060     class_name += 6;
5061
5062   return class_name;
5063 }
5064
5065 /* Internalize one native debug symbol. 
5066  * Called in a loop from hpread_expand_symtab(). 
5067  * Arguments:
5068  *   dn_bufp: 
5069  *   name: 
5070  *   section_offsets:
5071  *   objfile:
5072  *   text_offset: 
5073  *   text_size: 
5074  *   filename: 
5075  *   index:             Index of this symbol
5076  *   at_module_boundary_p Pointer to boolean flag to control caller's loop.
5077  */
5078
5079 static void
5080 hpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name,
5081                                  struct section_offsets *section_offsets,
5082                                  struct objfile *objfile, CORE_ADDR text_offset,
5083                                  int text_size, char *filename, int index,
5084                                  int *at_module_boundary_p)
5085 {
5086   unsigned long desc;
5087   int type;
5088   CORE_ADDR valu;
5089   int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
5090   int data_offset = ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
5091   union dnttentry *dn_temp;
5092   dnttpointer hp_type;
5093   struct symbol *sym;
5094   struct context_stack *new;
5095   char *class_scope_name;
5096
5097   /* Allocate one GDB debug symbol and fill in some default values. */
5098   sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
5099                                          sizeof (struct symbol));
5100   memset (sym, 0, sizeof (struct symbol));
5101   DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
5102   SYMBOL_LANGUAGE (sym) = language_auto;
5103   SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5104   SYMBOL_LINE (sym) = 0;
5105   SYMBOL_VALUE (sym) = 0;
5106   SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5107
5108   /* Just a trick in case the SOM debug symbol is a type definition.
5109    * There are routines that are set up to build a GDB type symbol, given
5110    * a SOM dnttpointer. So we set up a dummy SOM dnttpointer "hp_type".
5111    * This allows us to call those same routines.
5112    */
5113   hp_type.dnttp.extension = 1;
5114   hp_type.dnttp.immediate = 0;
5115   hp_type.dnttp.global = 0;
5116   hp_type.dnttp.index = index;
5117
5118   /* This "type" is the type of SOM record.
5119    * Switch on SOM type.
5120    */
5121   type = dn_bufp->dblock.kind;
5122   switch (type)
5123     {
5124     case DNTT_TYPE_SRCFILE:
5125       /* This type of symbol indicates from which source file or
5126        * include file any following data comes. It may indicate:
5127        *
5128        * o   The start of an entirely new source file (and thus
5129        *     a new module)
5130        *
5131        * o   The start of a different source file due to #include
5132        *
5133        * o   The end of an include file and the return to the original
5134        *     file. Thus if "foo.c" includes "bar.h", we see first
5135        *     a SRCFILE for foo.c, then one for bar.h, and then one for
5136        *     foo.c again.
5137        *
5138        * If it indicates the start of a new module then we must
5139        * finish the symbol table of the previous module 
5140        * (if any) and start accumulating a new symbol table.  
5141        */
5142
5143       valu = text_offset;
5144       if (!last_source_file)
5145         {
5146           /*
5147            * A note on "last_source_file": this is a char* pointing
5148            * to the actual file name.  "start_symtab" sets it,
5149            * "end_symtab" clears it.
5150            *
5151            * So if "last_source_file" is NULL, then either this is
5152            * the first record we are looking at, or a previous call
5153            * to "end_symtab()" was made to close out the previous
5154            * module.  Since we're now quitting the scan loop when we
5155            * see a MODULE END record, we should never get here, except
5156            * in the case that we're not using the quick look-up tables
5157            * and have to use the old system as a fall-back.
5158            */
5159           start_symtab (name, NULL, valu);
5160           record_debugformat ("HP");
5161           SL_INDEX (objfile) = dn_bufp->dsfile.address;
5162         }
5163
5164       else
5165         {
5166           /* Either a new include file, or a SRCFILE record
5167            * saying we are back in the main source (or out of
5168            * a nested include file) again.
5169            */
5170           SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5171                                                     SL_INDEX (objfile),
5172                                                     dn_bufp->dsfile.address,
5173                                                     objfile, offset);
5174         }
5175
5176       /* A note on "start_subfile".  This routine will check
5177        * the name we pass it and look for an existing subfile
5178        * of that name.  There's thus only one sub-file for the
5179        * actual source (e.g. for "foo.c" in foo.c), despite the
5180        * fact that we'll see lots of SRCFILE entries for foo.c
5181        * inside foo.c.
5182        */
5183       start_subfile (name, NULL);
5184       break;
5185
5186     case DNTT_TYPE_MODULE:
5187       /*
5188        * We no longer ignore DNTT_TYPE_MODULE symbols.  The module 
5189        * represents the meaningful semantic structure of a compilation
5190        * unit.  We expect to start the psymtab-to-symtab expansion
5191        * looking at a MODULE entry, and to end it at the corresponding
5192        * END MODULE entry.
5193        *
5194        *--Begin outdated comments
5195        * 
5196        * This record signifies the start of a new source module
5197        * In C/C++ there is no explicit "module" construct in the language,
5198        * but each compilation unit is implicitly a module and they
5199        * do emit the DNTT_TYPE_MODULE records.
5200        * The end of the module is marked by a matching DNTT_TYPE_END record.
5201        *
5202        * The reason GDB gets away with ignoring the DNTT_TYPE_MODULE record 
5203        * is it notices the DNTT_TYPE_END record for the previous 
5204        * module (see comments under DNTT_TYPE_END case), and then treats
5205        * the next DNTT_TYPE_SRCFILE record as if it were the module-start record.
5206        * (i.e., it makes a start_symtab() call).
5207        * This scheme seems a little convoluted, but I'll leave it 
5208        * alone on the principle "if it ain't broke don't fix
5209        * it". (RT).
5210        *
5211        *-- End outdated comments
5212        */
5213
5214       valu = text_offset;
5215       if (!last_source_file)
5216         {
5217           /* Start of a new module. We know this because "last_source_file"
5218            * is NULL, which can only happen the first time or if we just 
5219            * made a call to end_symtab() to close out the previous module.
5220            */
5221           start_symtab (name, NULL, valu);
5222           SL_INDEX (objfile) = dn_bufp->dmodule.address;
5223         }
5224       else
5225         {
5226           /* This really shouldn't happen if we're using the quick
5227            * look-up tables, as it would mean we'd scanned past an
5228            * END MODULE entry.  But if we're not using the tables,
5229            * we started the module on the SRCFILE entry, so it's ok.
5230            * For now, accept this.
5231            */
5232           /* warning( "Error expanding psymtab, missed module end, found entry for %s",
5233            *           name );
5234            */
5235           *at_module_boundary_p = -1;
5236         }
5237
5238       start_subfile (name, NULL);
5239       break;
5240
5241     case DNTT_TYPE_FUNCTION:
5242     case DNTT_TYPE_ENTRY:
5243       /* A function or secondary entry point.  */
5244       valu = dn_bufp->dfunc.lowaddr + offset;
5245
5246       /* Record lines up to this point. */
5247       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5248                                                 SL_INDEX (objfile),
5249                                                 dn_bufp->dfunc.address,
5250                                                 objfile, offset);
5251
5252       WITHIN_FUNCTION (objfile) = 1;
5253       CURRENT_FUNCTION_VALUE (objfile) = valu;
5254
5255       /* Stack must be empty now.  */
5256       if (context_stack_depth != 0)
5257         lbrac_unmatched_complaint (symnum);
5258       new = push_context (0, valu);
5259
5260       /* Built a type for the function. This includes processing
5261        * the symbol records for the function parameters.
5262        */
5263       SYMBOL_CLASS (sym) = LOC_BLOCK;
5264       SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1);
5265
5266       /* All functions in C++ have prototypes.  For C we don't have enough
5267          information in the debug info.  */
5268       if (SYMBOL_LANGUAGE (sym) == language_cplus)
5269         TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
5270
5271       /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name
5272        * (if any), which we get from the "alias" field of the SOM record
5273        * if that exists.
5274        */
5275       if ((dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
5276           dn_bufp->dfunc.alias &&       /* has an alias */
5277           *(char *) (VT (objfile) + dn_bufp->dfunc.alias))      /* not a null string */
5278         DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias;
5279       else
5280         DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
5281
5282       /* Special hack to get around HP compilers' insistence on
5283        * reporting "main" as "_MAIN_" for C/C++ */
5284       if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) &&
5285           (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0))
5286         DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
5287
5288       /* The SYMBOL_CPLUS_DEMANGLED_NAME field is expected to
5289        * be the demangled name.
5290        */
5291       if (dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
5292         {
5293           /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
5294            * calling the demangler in libiberty (cplus_demangle()) to
5295            * do the job. This generally does the job, even though
5296            * it's intended for the GNU compiler and not the aCC compiler
5297            * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
5298            * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
5299            * Generally, we don't want params when we display
5300            * a demangled name, but when I took out the DMGL_PARAMS,
5301            * some things broke, so I'm leaving it in here, and
5302            * working around the issue in stack.c. - RT
5303            */
5304           SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
5305           if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->dfunc.alias) &&
5306               (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
5307             {
5308
5309               /* Well, the symbol name is mangled, but the
5310                * demangler in libiberty failed so the demangled
5311                * field is still NULL. Try to
5312                * do the job ourselves based on the "name" field
5313                * in the SOM record. A complication here is that
5314                * the name field contains only the function name
5315                * (like "f"), whereas we want the class qualification
5316                * (as in "c::f"). Try to reconstruct that.
5317                */
5318               char *basename;
5319               char *classname;
5320               char *dem_name;
5321               basename = VT (objfile) + dn_bufp->dfunc.name;
5322               classname = class_of (SYMBOL_TYPE (sym));
5323               if (classname)
5324                 {
5325                   dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
5326                   strcpy (dem_name, classname);
5327                   strcat (dem_name, "::");
5328                   strcat (dem_name, basename);
5329                   SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
5330                   SYMBOL_LANGUAGE (sym) = language_cplus;
5331                 }
5332             }
5333         }
5334
5335       /* Add the function symbol to the list of symbols in this blockvector */
5336       if (dn_bufp->dfunc.global)
5337         add_symbol_to_list (sym, &global_symbols);
5338       else
5339         add_symbol_to_list (sym, &file_symbols);
5340       new->name = sym;
5341
5342       /* Search forward to the next BEGIN and also read
5343        * in the line info up to that point. 
5344        * Not sure why this is needed.
5345        * In HP FORTRAN this code is harmful since there   
5346        * may not be a BEGIN after the FUNCTION.
5347        * So I made it C/C++ specific. - RT
5348        */
5349       if (dn_bufp->dfunc.language == HP_LANGUAGE_C ||
5350           dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
5351         {
5352           while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
5353             {
5354               dn_bufp = hpread_get_lntt (++index, objfile);
5355               if (dn_bufp->dblock.extension)
5356                 continue;
5357             }
5358           SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5359                                                     SL_INDEX (objfile),
5360                                                     dn_bufp->dbegin.address,
5361                                                     objfile, offset);
5362           SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
5363         }
5364       record_line (current_subfile, SYMBOL_LINE (sym), valu);
5365       break;
5366
5367     case DNTT_TYPE_DOC_FUNCTION:
5368       valu = dn_bufp->ddocfunc.lowaddr + offset;
5369
5370       /* Record lines up to this point. */
5371       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5372                                                 SL_INDEX (objfile),
5373                                                 dn_bufp->ddocfunc.address,
5374                                                 objfile, offset);
5375
5376       WITHIN_FUNCTION (objfile) = 1;
5377       CURRENT_FUNCTION_VALUE (objfile) = valu;
5378       /* Stack must be empty now.  */
5379       if (context_stack_depth != 0)
5380         lbrac_unmatched_complaint (symnum);
5381       new = push_context (0, valu);
5382
5383       /* Built a type for the function. This includes processing
5384        * the symbol records for the function parameters.
5385        */
5386       SYMBOL_CLASS (sym) = LOC_BLOCK;
5387       SYMBOL_TYPE (sym) = hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 1);
5388
5389       /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name
5390        * (if any), which we get from the "alias" field of the SOM record
5391        * if that exists.
5392        */
5393       if ((dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
5394           dn_bufp->ddocfunc.alias &&    /* has an alias */
5395           *(char *) (VT (objfile) + dn_bufp->ddocfunc.alias))   /* not a null string */
5396         DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.alias;
5397       else
5398         DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
5399
5400       /* Special hack to get around HP compilers' insistence on
5401        * reporting "main" as "_MAIN_" for C/C++ */
5402       if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) &&
5403           (strcmp (VT (objfile) + dn_bufp->ddocfunc.name, "main") == 0))
5404         DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
5405
5406       if (dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
5407         {
5408
5409           /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
5410            * calling the demangler in libiberty (cplus_demangle()) to
5411            * do the job. This generally does the job, even though
5412            * it's intended for the GNU compiler and not the aCC compiler
5413            * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
5414            * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
5415            * Generally, we don't want params when we display
5416            * a demangled name, but when I took out the DMGL_PARAMS,
5417            * some things broke, so I'm leaving it in here, and
5418            * working around the issue in stack.c. - RT 
5419            */
5420           SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
5421
5422           if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->ddocfunc.alias) &&
5423               (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
5424             {
5425
5426               /* Well, the symbol name is mangled, but the
5427                * demangler in libiberty failed so the demangled
5428                * field is still NULL. Try to
5429                * do the job ourselves based on the "name" field
5430                * in the SOM record. A complication here is that
5431                * the name field contains only the function name
5432                * (like "f"), whereas we want the class qualification
5433                * (as in "c::f"). Try to reconstruct that.
5434                */
5435               char *basename;
5436               char *classname;
5437               char *dem_name;
5438               basename = VT (objfile) + dn_bufp->ddocfunc.name;
5439               classname = class_of (SYMBOL_TYPE (sym));
5440               if (classname)
5441                 {
5442                   dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
5443                   strcpy (dem_name, classname);
5444                   strcat (dem_name, "::");
5445                   strcat (dem_name, basename);
5446                   SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
5447                   SYMBOL_LANGUAGE (sym) = language_cplus;
5448                 }
5449             }
5450         }
5451
5452       /* Add the function symbol to the list of symbols in this blockvector */
5453       if (dn_bufp->ddocfunc.global)
5454         add_symbol_to_list (sym, &global_symbols);
5455       else
5456         add_symbol_to_list (sym, &file_symbols);
5457       new->name = sym;
5458
5459       /* Search forward to the next BEGIN and also read
5460        * in the line info up to that point. 
5461        * Not sure why this is needed.
5462        * In HP FORTRAN this code is harmful since there   
5463        * may not be a BEGIN after the FUNCTION.
5464        * So I made it C/C++ specific. - RT
5465        */
5466       if (dn_bufp->ddocfunc.language == HP_LANGUAGE_C ||
5467           dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
5468         {
5469           while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
5470             {
5471               dn_bufp = hpread_get_lntt (++index, objfile);
5472               if (dn_bufp->dblock.extension)
5473                 continue;
5474             }
5475           SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5476                                                     SL_INDEX (objfile),
5477                                                     dn_bufp->dbegin.address,
5478                                                     objfile, offset);
5479           SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
5480         }
5481       record_line (current_subfile, SYMBOL_LINE (sym), valu);
5482       break;
5483
5484     case DNTT_TYPE_BEGIN:
5485       /* Begin a new scope. */
5486       if (context_stack_depth == 1 /* this means we're at function level */  &&
5487           context_stack[0].name != NULL /* this means it's a function */  &&
5488           context_stack[0].depth == 0   /* this means it's the first BEGIN 
5489                                            we've seen after the FUNCTION */
5490         )
5491         {
5492           /* This is the first BEGIN after a FUNCTION.
5493            * We ignore this one, since HP compilers always insert
5494            * at least one BEGIN, i.e. it's:
5495            * 
5496            *     FUNCTION
5497            *     argument symbols
5498            *     BEGIN
5499            *     local symbols
5500            *        (possibly nested BEGIN ... END's if there are inner { } blocks)
5501            *     END
5502            *     END
5503            *
5504            * By ignoring this first BEGIN, the local symbols get treated
5505            * as belonging to the function scope, and "print func::local_sym"
5506            * works (which is what we want).
5507            */
5508
5509           /* All we do here is increase the depth count associated with
5510            * the FUNCTION entry in the context stack. This ensures that
5511            * the next BEGIN we see (if any), representing a real nested { }
5512            * block, will get processed.
5513            */
5514
5515           context_stack[0].depth++;
5516
5517         }
5518       else
5519         {
5520
5521           /* Record lines up to this SLT pointer. */
5522           SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5523                                                     SL_INDEX (objfile),
5524                                                     dn_bufp->dbegin.address,
5525                                                     objfile, offset);
5526           /* Calculate start address of new scope */
5527           valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
5528           valu += offset;       /* Relocate for dynamic loading */
5529           /* We use the scope start DNTT index as nesting depth identifier! */
5530           desc = hpread_get_scope_start (dn_bufp->dbegin.address, objfile);
5531           new = push_context (desc, valu);
5532         }
5533       break;
5534
5535     case DNTT_TYPE_END:
5536       /* End a scope.  */
5537
5538       /* Valid end kinds are:
5539        *  MODULE
5540        *  FUNCTION
5541        *  WITH
5542        *  COMMON
5543        *  BEGIN
5544        *  CLASS_SCOPE
5545        */
5546
5547       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
5548                                                 SL_INDEX (objfile),
5549                                                 dn_bufp->dend.address,
5550                                                 objfile, offset);
5551       switch (dn_bufp->dend.endkind)
5552         {
5553         case DNTT_TYPE_MODULE:
5554           /* Ending a module ends the symbol table for that module.  
5555            * Calling end_symtab() has the side effect of clearing the
5556            * last_source_file pointer, which in turn signals 
5557            * process_one_debug_symbol() to treat the next DNTT_TYPE_SRCFILE
5558            * record as a module-begin.
5559            */
5560           valu = text_offset + text_size + offset;
5561
5562           /* Tell our caller that we're done with expanding the
5563            * debug information for a module.
5564            */
5565           *at_module_boundary_p = 1;
5566
5567           /* Don't do this, as our caller will do it!
5568
5569            *      (void) end_symtab (valu, objfile, 0);
5570            */
5571           break;
5572
5573         case DNTT_TYPE_FUNCTION:
5574           /* Ending a function, well, ends the function's scope.  */
5575           dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
5576                                      objfile);
5577           valu = dn_temp->dfunc.hiaddr + offset;
5578           /* Insert func params into local list */
5579           merge_symbol_lists (&param_symbols, &local_symbols);
5580           new = pop_context ();
5581           /* Make a block for the local symbols within.  */
5582           finish_block (new->name, &local_symbols, new->old_blocks,
5583                         new->start_addr, valu, objfile);
5584           WITHIN_FUNCTION (objfile) = 0;        /* This may have to change for Pascal */
5585           local_symbols = new->locals;
5586           param_symbols = new->params;
5587           break;
5588
5589         case DNTT_TYPE_BEGIN:
5590           if (context_stack_depth == 1 &&
5591               context_stack[0].name != NULL &&
5592               context_stack[0].depth == 1)
5593             {
5594               /* This is the END corresponding to the
5595                * BEGIN which we ignored - see DNTT_TYPE_BEGIN case above.
5596                */
5597               context_stack[0].depth--;
5598             }
5599           else
5600             {
5601               /* Ending a local scope.  */
5602               valu = hpread_get_location (dn_bufp->dend.address, objfile);
5603               /* Why in the hell is this needed?  */
5604               valu += offset + 9;       /* Relocate for dynamic loading */
5605               new = pop_context ();
5606               desc = dn_bufp->dend.beginscope.dnttp.index;
5607               if (desc != new->depth)
5608                 lbrac_mismatch_complaint (symnum);
5609
5610               /* Make a block for the local symbols within.  */
5611               finish_block (new->name, &local_symbols, new->old_blocks,
5612                             new->start_addr, valu, objfile);
5613               local_symbols = new->locals;
5614               param_symbols = new->params;
5615             }
5616           break;
5617
5618         case DNTT_TYPE_WITH:
5619           /* Since we ignore the DNTT_TYPE_WITH that starts the scope,
5620            * we can ignore the DNTT_TYPE_END that ends it.
5621            */
5622           break;
5623
5624         case DNTT_TYPE_COMMON:
5625           /* End a FORTRAN common block. We don't currently handle these */
5626           complaint (&symfile_complaints,
5627                      "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON/DNTT_TYPE_END.\n");
5628           break;
5629
5630         case DNTT_TYPE_CLASS_SCOPE:
5631
5632           /* pai: FIXME Not handling nested classes for now -- must
5633              * maintain a stack */
5634           class_scope_name = NULL;
5635
5636 #if 0
5637           /* End a class scope */
5638           valu = hpread_get_location (dn_bufp->dend.address, objfile);
5639           /* Why in the hell is this needed?  */
5640           valu += offset + 9;   /* Relocate for dynamic loading */
5641           new = pop_context ();
5642           desc = dn_bufp->dend.beginscope.dnttp.index;
5643           if (desc != new->depth)
5644             lbrac_mismatch_complaint ((char *) symnum);
5645           /* Make a block for the local symbols within.  */
5646           finish_block (new->name, &local_symbols, new->old_blocks,
5647                         new->start_addr, valu, objfile);
5648           local_symbols = new->locals;
5649           param_symbols = new->params;
5650 #endif
5651           break;
5652
5653         default:
5654           complaint (&symfile_complaints,
5655                      "internal error in hp-symtab-read.c: Unexpected DNTT_TYPE_END kind.");
5656           break;
5657         }
5658       break;
5659
5660       /* DNTT_TYPE_IMPORT is not handled */
5661
5662     case DNTT_TYPE_LABEL:
5663       SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
5664       break;
5665
5666     case DNTT_TYPE_FPARAM:
5667       /* Function parameters.  */
5668       /* Note 1: This code was present in the 4.16 sources, and then
5669          removed, because fparams are handled in
5670          hpread_read_function_type().  However, while fparam symbols
5671          are indeed handled twice, this code here cannot be removed
5672          because then they don't get added to the local symbol list of
5673          the function's code block, which leads to a failure to look
5674          up locals, "this"-relative member names, etc.  So I've put
5675          this code back in. pai/1997-07-21 */
5676       /* Note 2: To fix a defect, we stopped adding FPARAMS to local_symbols
5677          in hpread_read_function_type(), so FPARAMS had to be handled
5678          here.  I changed the location to be the appropriate argument
5679          kinds rather than LOC_LOCAL. pai/1997-08-08 */
5680       /* Note 3: Well, the fix in Note 2 above broke argument printing
5681          in traceback frames, and further it makes assumptions about the
5682          order of the FPARAM entries from HP compilers (cc and aCC in particular
5683          generate them in reverse orders -- fixing one breaks for the other).
5684          So I've added code in hpread_read_function_type() to add fparams
5685          to a param_symbols list for the current context level.  These are
5686          then merged into local_symbols when a function end is reached.
5687          pai/1997-08-11 */
5688
5689       break;                    /* do nothing; handled in hpread_read_function_type() */
5690
5691 #if 0                           /* Old code */
5692       if (dn_bufp->dfparam.regparam)
5693         SYMBOL_CLASS (sym) = LOC_REGISTER;
5694       else if (dn_bufp->dfparam.indirect)
5695         SYMBOL_CLASS (sym) = LOC_REF_ARG;
5696       else
5697         SYMBOL_CLASS (sym) = LOC_ARG;
5698       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5699       if (dn_bufp->dfparam.copyparam)
5700         {
5701           SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
5702 #ifdef HPREAD_ADJUST_STACK_ADDRESS
5703           SYMBOL_VALUE (sym)
5704             += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
5705 #endif
5706         }
5707       else
5708         SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
5709       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
5710       add_symbol_to_list (sym, &fparam_symbols);
5711       break;
5712 #endif
5713
5714     case DNTT_TYPE_SVAR:
5715       /* Static variables.  */
5716       SYMBOL_CLASS (sym) = LOC_STATIC;
5717
5718       /* Note: There is a case that arises with globals in shared
5719        * libraries where we need to set the address to LOC_INDIRECT.
5720        * This case is if you have a global "g" in one library, and
5721        * it is referenced "extern <type> g;" in another library.
5722        * If we're processing the symbols for the referencing library,
5723        * we'll see a global "g", but in this case the address given
5724        * in the symbol table contains a pointer to the real "g".
5725        * We use the storage class LOC_INDIRECT to indicate this. RT
5726        */
5727       if (is_in_import_list (DEPRECATED_SYMBOL_NAME (sym), objfile))
5728         SYMBOL_CLASS (sym) = LOC_INDIRECT;
5729
5730       SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + data_offset;
5731       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
5732
5733       if (dn_bufp->dsvar.global)
5734         add_symbol_to_list (sym, &global_symbols);
5735
5736       else if (WITHIN_FUNCTION (objfile))
5737         add_symbol_to_list (sym, &local_symbols);
5738
5739       else
5740         add_symbol_to_list (sym, &file_symbols);
5741
5742       if (dn_bufp->dsvar.thread_specific)
5743         {
5744           /* Thread-local variable.
5745            */
5746           SYMBOL_CLASS (sym) = LOC_HP_THREAD_LOCAL_STATIC;
5747           SYMBOL_BASEREG (sym) = CR27_REGNUM;
5748
5749           if (objfile->flags & OBJF_SHARED)
5750             {
5751               /*
5752                * This variable is not only thread local but
5753                * in a shared library.
5754                *
5755                * Alas, the shared lib structures are private
5756                * to "somsolib.c".  But C lets us point to one.
5757                */
5758               struct so_list *so;
5759
5760               if (objfile->obj_private == NULL)
5761                 error ("Internal error in reading shared library information.");
5762
5763               so = ((obj_private_data_t *) (objfile->obj_private))->so_info;
5764               if (so == NULL)
5765                 error ("Internal error in reading shared library information.");
5766
5767               /* Thread-locals in shared libraries do NOT have the
5768                * standard offset ("data_offset"), so we re-calculate
5769                * where to look for this variable, using a call-back
5770                * to interpret the private shared-library data.
5771                */
5772               SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location +
5773                 so_lib_thread_start_addr (so);
5774             }
5775         }
5776       break;
5777
5778     case DNTT_TYPE_DVAR:
5779       /* Dynamic variables.  */
5780       if (dn_bufp->ddvar.regvar)
5781         SYMBOL_CLASS (sym) = LOC_REGISTER;
5782       else
5783         SYMBOL_CLASS (sym) = LOC_LOCAL;
5784
5785       SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
5786 #ifdef HPREAD_ADJUST_STACK_ADDRESS
5787       SYMBOL_VALUE (sym)
5788         += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
5789 #endif
5790       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
5791       if (dn_bufp->ddvar.global)
5792         add_symbol_to_list (sym, &global_symbols);
5793       else if (WITHIN_FUNCTION (objfile))
5794         add_symbol_to_list (sym, &local_symbols);
5795       else
5796         add_symbol_to_list (sym, &file_symbols);
5797       break;
5798
5799     case DNTT_TYPE_CONST:
5800       /* A constant (pascal?).  */
5801       SYMBOL_CLASS (sym) = LOC_CONST;
5802       SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
5803       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
5804       if (dn_bufp->dconst.global)
5805         add_symbol_to_list (sym, &global_symbols);
5806       else if (WITHIN_FUNCTION (objfile))
5807         add_symbol_to_list (sym, &local_symbols);
5808       else
5809         add_symbol_to_list (sym, &file_symbols);
5810       break;
5811
5812     case DNTT_TYPE_TYPEDEF:
5813       /* A typedef. We do want to process these, since a name is
5814        * added to the domain for the typedef'ed name.
5815        */
5816       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5817       SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
5818       if (dn_bufp->dtype.global)
5819         add_symbol_to_list (sym, &global_symbols);
5820       else if (WITHIN_FUNCTION (objfile))
5821         add_symbol_to_list (sym, &local_symbols);
5822       else
5823         add_symbol_to_list (sym, &file_symbols);
5824       break;
5825
5826     case DNTT_TYPE_TAGDEF:
5827       {
5828         int global = dn_bufp->dtag.global;
5829         /* Structure, union, enum, template, or class tag definition */
5830         /* We do want to process these, since a name is
5831          * added to the domain for the tag name (and if C++ class,
5832          * for the typename also).
5833          */
5834         SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5835
5836         /* The tag contains in its "type" field a pointer to the
5837          * DNTT_TYPE_STRUCT, DNTT_TYPE_UNION, DNTT_TYPE_ENUM, 
5838          * DNTT_TYPE_CLASS or DNTT_TYPE_TEMPLATE
5839          * record that actually defines the type.
5840          */
5841         SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
5842         TYPE_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym);
5843         TYPE_TAG_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym);
5844         if (dn_bufp->dtag.global)
5845           add_symbol_to_list (sym, &global_symbols);
5846         else if (WITHIN_FUNCTION (objfile))
5847           add_symbol_to_list (sym, &local_symbols);
5848         else
5849           add_symbol_to_list (sym, &file_symbols);
5850
5851         /* If this is a C++ class, then we additionally 
5852          * need to define a typedef for the
5853          * class type. E.g., so that the name "c" becomes visible as
5854          * a type name when the user says "class c { ... }".
5855          * In order to figure this out, we need to chase down the "type"
5856          * field to get to the DNTT_TYPE_CLASS record. 
5857          *
5858          * We also add the typename for ENUM. Though this isn't
5859          * strictly correct, it is necessary because of the debug info
5860          * generated by the aCC compiler, in which we cannot
5861          * distinguish between:
5862          *   enum e { ... };
5863          * and
5864          *   typedef enum { ... } e;
5865          * I.e., the compiler emits the same debug info for the above
5866          * two cases, in both cases "e" appearing as a tagdef.
5867          * Therefore go ahead and generate the typename so that
5868          * "ptype e" will work in the above cases.
5869          *
5870          * We also add the typename for TEMPLATE, so as to allow "ptype t"
5871          * when "t" is a template name. 
5872          */
5873         if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
5874           dn_bufp = hpread_get_lntt (dn_bufp->dtag.type.dnttp.index, objfile);
5875         else
5876           {
5877             complaint (&symfile_complaints, "error processing class tagdef");
5878             return;
5879           }
5880         if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
5881             dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
5882             dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
5883           {
5884             struct symbol *newsym;
5885
5886             newsym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
5887                                                     sizeof (struct symbol));
5888             memset (newsym, 0, sizeof (struct symbol));
5889             DEPRECATED_SYMBOL_NAME (newsym) = name;
5890             SYMBOL_LANGUAGE (newsym) = language_auto;
5891             SYMBOL_DOMAIN (newsym) = VAR_DOMAIN;
5892             SYMBOL_LINE (newsym) = 0;
5893             SYMBOL_VALUE (newsym) = 0;
5894             SYMBOL_CLASS (newsym) = LOC_TYPEDEF;
5895             SYMBOL_TYPE (newsym) = sym->type;
5896             if (global)
5897               add_symbol_to_list (newsym, &global_symbols);
5898             else if (WITHIN_FUNCTION (objfile))
5899               add_symbol_to_list (newsym, &local_symbols);
5900             else
5901               add_symbol_to_list (newsym, &file_symbols);
5902           }
5903       }
5904       break;
5905
5906     case DNTT_TYPE_POINTER:
5907       /* Declares a pointer type. Should not be necessary to do anything
5908        * with the type at this level; these are processed
5909        * at the hpread_type_lookup() level. 
5910        */
5911       break;
5912
5913     case DNTT_TYPE_ENUM:
5914       /* Declares an enum type. Should not be necessary to do anything
5915        * with the type at this level; these are processed
5916        * at the hpread_type_lookup() level. 
5917        */
5918       break;
5919
5920     case DNTT_TYPE_MEMENUM:
5921       /* Member of enum */
5922       /* Ignored at this level, but hpread_read_enum_type() will take
5923        * care of walking the list of enumeration members.
5924        */
5925       break;
5926
5927     case DNTT_TYPE_SET:
5928       /* Declares a set type. Should not be necessary to do anything
5929        * with the type at this level; these are processed
5930        * at the hpread_type_lookup() level. 
5931        */
5932       break;
5933
5934     case DNTT_TYPE_SUBRANGE:
5935       /* Declares a subrange type. Should not be necessary to do anything
5936        * with the type at this level; these are processed
5937        * at the hpread_type_lookup() level. 
5938        */
5939       break;
5940
5941     case DNTT_TYPE_ARRAY:
5942       /* Declares an array type. Should not be necessary to do anything
5943        * with the type at this level; these are processed
5944        * at the hpread_type_lookup() level. 
5945        */
5946       break;
5947
5948     case DNTT_TYPE_STRUCT:
5949     case DNTT_TYPE_UNION:
5950       /* Declares an struct/union type. 
5951        * Should not be necessary to do anything
5952        * with the type at this level; these are processed
5953        * at the hpread_type_lookup() level. 
5954        */
5955       break;
5956
5957     case DNTT_TYPE_FIELD:
5958       /* Structure/union/class field */
5959       /* Ignored at this level, but hpread_read_struct_type() will take
5960        * care of walking the list of structure/union/class members.
5961        */
5962       break;
5963
5964       /* DNTT_TYPE_VARIANT is not handled by GDB */
5965
5966       /* DNTT_TYPE_FILE is not handled by GDB */
5967
5968     case DNTT_TYPE_FUNCTYPE:
5969       /* Function type */
5970       /* Ignored at this level, handled within hpread_type_lookup() */
5971       break;
5972
5973     case DNTT_TYPE_WITH:
5974       /* This is emitted within methods to indicate "with <class>" 
5975        * scoping rules (i.e., indicate that the class data members
5976        * are directly visible).
5977        * However, since GDB already infers this by looking at the
5978        * "this" argument, interpreting the DNTT_TYPE_WITH 
5979        * symbol record is unnecessary.
5980        */
5981       break;
5982
5983     case DNTT_TYPE_COMMON:
5984       /* FORTRAN common. Not yet handled. */
5985       complaint (&symfile_complaints,
5986                  "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON.");
5987       break;
5988
5989       /* DNTT_TYPE_COBSTRUCT is not handled by GDB.  */
5990       /* DNTT_TYPE_XREF is not handled by GDB.  */
5991       /* DNTT_TYPE_SA is not handled by GDB.  */
5992       /* DNTT_TYPE_MACRO is not handled by GDB */
5993
5994     case DNTT_TYPE_BLOCKDATA:
5995       /* Not sure what this is - part of FORTRAN support maybe? 
5996        * Anyway, not yet handled.
5997        */
5998       complaint (&symfile_complaints,
5999                  "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_BLOCKDATA.");
6000       break;
6001
6002     case DNTT_TYPE_CLASS_SCOPE:
6003
6004
6005
6006       /* The compiler brackets member functions with a CLASS_SCOPE/END
6007        * pair of records, presumably to put them in a different scope
6008        * from the module scope where they are normally defined.
6009        * E.g., in the situation:
6010        *   void f() { ... }
6011        *   void c::f() { ...}
6012        * The member function "c::f" will be bracketed by a CLASS_SCOPE/END.
6013        * This causes "break f" at the module level to pick the
6014        * the file-level function f(), not the member function
6015        * (which needs to be referenced via "break c::f"). 
6016        * 
6017        * Here we record the class name to generate the demangled names of
6018        * member functions later.
6019        *
6020        * FIXME Not being used now for anything -- cplus_demangle seems
6021        * enough for getting the class-qualified names of functions. We
6022        * may need this for handling nested classes and types.  */
6023
6024       /* pai: FIXME Not handling nested classes for now -- need to
6025        * maintain a stack */
6026
6027       dn_temp = hpread_get_lntt (dn_bufp->dclass_scope.type.dnttp.index, objfile);
6028       if (dn_temp->dblock.kind == DNTT_TYPE_TAGDEF)
6029         class_scope_name = VT (objfile) + dn_temp->dtag.name;
6030       else
6031         class_scope_name = NULL;
6032
6033 #if 0
6034
6035       /* Begin a new scope.  */
6036       SL_INDEX (objfile) = hpread_record_lines (current_subfile,
6037                                                 SL_INDEX (objfile),
6038                                               dn_bufp->dclass_scope.address,
6039                                                 objfile, offset);
6040       valu = hpread_get_location (dn_bufp->dclass_scope.address, objfile);
6041       valu += offset;           /* Relocate for dynamic loading */
6042       desc = hpread_get_scope_start (dn_bufp->dclass_scope.address, objfile);
6043       /* We use the scope start DNTT index as the nesting depth identifier! */
6044       new = push_context (desc, valu);
6045 #endif
6046       break;
6047
6048     case DNTT_TYPE_REFERENCE:
6049       /* Declares a C++ reference type. Should not be necessary to do anything
6050        * with the type at this level; these are processed
6051        * at the hpread_type_lookup() level.
6052        */
6053       break;
6054
6055     case DNTT_TYPE_PTRMEM:
6056       /* Declares a C++ pointer-to-data-member type. This does not
6057        * need to be handled at this level; being a type description it
6058        * is instead handled at the hpread_type_lookup() level.
6059        */
6060       break;
6061
6062     case DNTT_TYPE_PTRMEMFUNC:
6063       /* Declares a C++ pointer-to-function-member type. This does not
6064        * need to be handled at this level; being a type description it
6065        * is instead handled at the hpread_type_lookup() level.
6066        */
6067       break;
6068
6069     case DNTT_TYPE_CLASS:
6070       /* Declares a class type. 
6071        * Should not be necessary to do anything
6072        * with the type at this level; these are processed
6073        * at the hpread_type_lookup() level. 
6074        */
6075       break;
6076
6077     case DNTT_TYPE_GENFIELD:
6078       /* I believe this is used for class member functions */
6079       /* Ignored at this level, but hpread_read_struct_type() will take
6080        * care of walking the list of class members.
6081        */
6082       break;
6083
6084     case DNTT_TYPE_VFUNC:
6085       /* Virtual function */
6086       /* This does not have to be handled at this level; handled in
6087        * the course of processing class symbols.
6088        */
6089       break;
6090
6091     case DNTT_TYPE_MEMACCESS:
6092       /* DDE ignores this symbol table record.
6093        * It has something to do with "modified access" to class members.
6094        * I'll assume we can safely ignore it too.
6095        */
6096       break;
6097
6098     case DNTT_TYPE_INHERITANCE:
6099       /* These don't have to be handled here, since they are handled
6100        * within hpread_read_struct_type() in the process of constructing
6101        * a class type.
6102        */
6103       break;
6104
6105     case DNTT_TYPE_FRIEND_CLASS:
6106     case DNTT_TYPE_FRIEND_FUNC:
6107       /* These can safely be ignored, as GDB doesn't need this
6108        * info. DDE only uses it in "describe". We may later want
6109        * to extend GDB's "ptype" to give this info, but for now
6110        * it seems safe enough to ignore it.
6111        */
6112       break;
6113
6114     case DNTT_TYPE_MODIFIER:
6115       /* Intended to supply "modified access" to a type */
6116       /* From the way DDE handles this, it looks like it always
6117        * modifies a type. Therefore it is safe to ignore it at this
6118        * level, and handle it in hpread_type_lookup().
6119        */
6120       break;
6121
6122     case DNTT_TYPE_OBJECT_ID:
6123       /* Just ignore this - that's all DDE does */
6124       break;
6125
6126     case DNTT_TYPE_MEMFUNC:
6127       /* Member function */
6128       /* This does not have to be handled at this level; handled in
6129        * the course of processing class symbols.
6130        */
6131       break;
6132
6133     case DNTT_TYPE_DOC_MEMFUNC:
6134       /* Member function */
6135       /* This does not have to be handled at this level; handled in
6136        * the course of processing class symbols.
6137        */
6138       break;
6139
6140     case DNTT_TYPE_TEMPLATE:
6141       /* Template - sort of the header for a template definition,
6142        * which like a class, points to a member list and also points
6143        * to a TEMPLATE_ARG list of type-arguments.
6144        * We do not need to process TEMPLATE records at this level though.
6145        */
6146       break;
6147
6148     case DNTT_TYPE_TEMPLATE_ARG:
6149       /* The TEMPLATE record points to an argument list of
6150        * TEMPLATE_ARG records, each of which describes one
6151        * of the type-arguments.
6152        * We do not need to process TEMPLATE_ARG records at this level though.
6153        */
6154       break;
6155
6156     case DNTT_TYPE_FUNC_TEMPLATE:
6157       /* This will get emitted for member functions of templates.
6158        * But we don't need to process this record at this level though,
6159        * we will process it in the course of processing a TEMPLATE
6160        * record.
6161        */
6162       break;
6163
6164     case DNTT_TYPE_LINK:
6165       /* The LINK record is used to link up templates with instantiations. */
6166       /* It is not clear why this is needed, and furthermore aCC does
6167        * not appear to generate this, so I think we can safely ignore it. - RT
6168        */
6169       break;
6170
6171       /* DNTT_TYPE_DYN_ARRAY_DESC is not handled by GDB */
6172       /* DNTT_TYPE_DESC_SUBRANGE is not handled by GDB */
6173       /* DNTT_TYPE_BEGIN_EXT is not handled by GDB */
6174       /* DNTT_TYPE_INLN is not handled by GDB */
6175       /* DNTT_TYPE_INLN_LIST is not handled by GDB */
6176       /* DNTT_TYPE_ALIAS is not handled by GDB */
6177
6178     default:
6179       break;
6180     }
6181 }
6182
6183 /* Get nesting depth for a DNTT entry.
6184  * DN_BUFP points to a DNTT entry.
6185  * OBJFILE is the object file.
6186  * REPORT_NESTED is a flag; if 0, real nesting depth is
6187  * reported, if it is 1, the function simply returns a 
6188  * non-zero value if the nesting depth is anything > 0.
6189  * 
6190  * Return value is an integer.  0 => not a local type / name
6191  * positive return => type or name is local to some 
6192  * block or function.
6193  */
6194
6195
6196 /* elz: ATTENTION: FIXME: NOTE: WARNING!!!!
6197    this function now returns 0 right away. It was taking too much time
6198    at start up. Now, though, the local types are not handled correctly.
6199  */
6200
6201
6202 static int
6203 hpread_get_scope_depth (union dnttentry *dn_bufp, struct objfile *objfile,
6204                         int report_nested)
6205 {
6206   register int index;
6207   register union dnttentry *dn_tmp;
6208   register short depth = 0;
6209 /****************************/
6210   return 0;
6211 /****************************/
6212
6213   index = (((char *) dn_bufp) - LNTT (objfile)) / (sizeof (struct dntt_type_block));
6214
6215   while (--index >= 0)
6216     {
6217       dn_tmp = hpread_get_lntt (index, objfile);
6218       switch (dn_tmp->dblock.kind)
6219         {
6220         case DNTT_TYPE_MODULE:
6221           return depth;
6222         case DNTT_TYPE_END:
6223           /* index is signed int; dnttp.index is 29-bit unsigned int! */
6224           index = (int) dn_tmp->dend.beginscope.dnttp.index;
6225           break;
6226         case DNTT_TYPE_BEGIN:
6227         case DNTT_TYPE_FUNCTION:
6228         case DNTT_TYPE_DOC_FUNCTION:
6229         case DNTT_TYPE_WITH:
6230         case DNTT_TYPE_COMMON:
6231         case DNTT_TYPE_CLASS_SCOPE:
6232           depth++;
6233           if (report_nested)
6234             return 1;
6235           break;
6236         default:
6237           break;
6238         }
6239     }
6240   return depth;
6241 }
6242
6243 /* Adjust the bitoffsets for all fields of an anonymous union of
6244    type TYPE by negative BITS.  This handles HP aCC's hideous habit
6245    of giving members of anonymous unions bit offsets relative to the
6246    enclosing structure instead of relative to the union itself. */
6247
6248 static void
6249 hpread_adjust_bitoffsets (struct type *type, int bits)
6250 {
6251   register int i;
6252
6253   /* This is done only for unions; caller had better check that
6254      it is an anonymous one. */
6255   if (TYPE_CODE (type) != TYPE_CODE_UNION)
6256     return;
6257
6258   /* Adjust each field; since this is a union, there are no base
6259      classes. Also no static membes.  Also, no need for recursion as
6260      the members of this union if themeselves structs or unions, have
6261      the correct bitoffsets; if an anonymous union is a member of this
6262      anonymous union, the code in hpread_read_struct_type() will
6263      adjust for that. */
6264
6265   for (i = 0; i < TYPE_NFIELDS (type); i++)
6266     TYPE_FIELD_BITPOS (type, i) -= bits;
6267 }
6268
6269 /* Because of quirks in HP compilers' treatment of anonymous unions inside
6270    classes, we have to chase through a chain of threaded FIELD entries.
6271    If we encounter an anonymous union in the chain, we must recursively skip over
6272    that too.
6273
6274    This function does a "next" in the chain of FIELD entries, but transparently
6275    skips over anonymous unions' fields (recursively).
6276
6277    Inputs are the number of times to do "next" at the top level, the dnttpointer
6278    (FIELD) and entry pointer (FIELDP) for the dntt record corresponding to it,
6279    and the ubiquitous objfile parameter. (Note: FIELDP is a **.)  Return value
6280    is a dnttpointer for the new field after all the skipped ones */
6281
6282 static dnttpointer
6283 hpread_get_next_skip_over_anon_unions (int skip_fields, dnttpointer field,
6284                                        union dnttentry **fieldp,
6285                                        struct objfile *objfile)
6286 {
6287   struct type *anon_type;
6288   register int i;
6289   int bitoffset;
6290   char *name;
6291
6292   for (i = 0; i < skip_fields; i++)
6293     {
6294       /* Get type of item we're looking at now; recursively processes the types
6295          of these intermediate items we skip over, so they aren't lost. */
6296       anon_type = hpread_type_lookup ((*fieldp)->dfield.type, objfile);
6297       anon_type = CHECK_TYPEDEF (anon_type);
6298       bitoffset = (*fieldp)->dfield.bitoffset;
6299       name = VT (objfile) + (*fieldp)->dfield.name;
6300       /* First skip over one item to avoid stack death on recursion */
6301       field = (*fieldp)->dfield.nextfield;
6302       *fieldp = hpread_get_lntt (field.dnttp.index, objfile);
6303       /* Do we have another anonymous union? If so, adjust the bitoffsets
6304          of its members and skip over its members. */
6305       if ((TYPE_CODE (anon_type) == TYPE_CODE_UNION) &&
6306           (!name || STREQ (name, "")))
6307         {
6308           hpread_adjust_bitoffsets (anon_type, bitoffset);
6309           field = hpread_get_next_skip_over_anon_unions (TYPE_NFIELDS (anon_type), field, fieldp, objfile);
6310         }
6311     }
6312   return field;
6313 }