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