]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/hp-symtab-read.c
import gdb-1999-07-07 post reformat
[thirdparty/binutils-gdb.git] / gdb / hp-symtab-read.c
CommitLineData
c906108c
SS
1/* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993, 1996 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
c5aa993b
JM
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
c906108c
SS
20
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support. */
23
24/* Common include for hp-symtab-read.c and hp-psymtab-read.c.
25 * Note this has nested includes for a bunch of stuff.
26 */
27#include "defs.h"
28#include "symtab.h"
29#include "gdbtypes.h"
30#include "hpread.h"
31#include "demangle.h"
32#include "complaints.h"
c906108c
SS
33\f
34
35
c5aa993b
JM
36
37static struct complaint hpread_unhandled_end_common_complaint =
c906108c
SS
38{
39 "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON/DNTT_TYPE_END.\n", 0, 0
40};
41
c5aa993b 42static struct complaint hpread_unhandled_type_complaint =
c906108c
SS
43{
44 "hpread_type_translate: unhandled type code.", 0, 0
45};
46
c5aa993b 47static struct complaint hpread_struct_complaint =
c906108c
SS
48{
49 "hpread_read_struct_type: expected SVAR type...", 0, 0
50};
51
52static struct complaint hpread_array_complaint =
53{
54 "error in hpread_array_type.", 0, 0
55};
56
c5aa993b 57static struct complaint hpread_type_lookup_complaint =
c906108c
SS
58{
59 "error in hpread_type_lookup().", 0, 0
60};
61
62
c5aa993b 63static struct complaint hpread_unexpected_end_complaint =
c906108c
SS
64{
65 "internal error in hp-symtab-read.c: Unexpected DNTT_TYPE_END kind.", 0, 0
66};
67
c5aa993b 68static struct complaint hpread_tagdef_complaint =
c906108c
SS
69{
70 "error processing class tagdef", 0, 0
71};
72
c5aa993b 73static struct complaint hpread_unhandled_common_complaint =
c906108c
SS
74{
75 "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON.", 0, 0
76};
77
c5aa993b 78static struct complaint hpread_unhandled_blockdata_complaint =
c906108c
SS
79{
80 "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_BLOCKDATA.", 0, 0
81};
82
83
84/* Forward procedure declarations */
85
86static unsigned long hpread_get_scope_start
87 PARAMS ((sltpointer, struct objfile *));
88
89static unsigned long hpread_get_line
90 PARAMS ((sltpointer, struct objfile *));
91
92static CORE_ADDR hpread_get_location
93 PARAMS ((sltpointer, struct objfile *));
94
c5aa993b 95static void hpread_psymtab_to_symtab_1
c906108c
SS
96 PARAMS ((struct partial_symtab *));
97
c5aa993b 98void hpread_psymtab_to_symtab
c906108c
SS
99 PARAMS ((struct partial_symtab *));
100
101static struct symtab *hpread_expand_symtab
102 PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
103 struct section_offsets *, char *));
104
c5aa993b 105static int hpread_type_translate
c906108c
SS
106 PARAMS ((dnttpointer));
107
108static struct type **hpread_lookup_type
109 PARAMS ((dnttpointer, struct objfile *));
110
111static struct type *hpread_alloc_type
112 PARAMS ((dnttpointer, struct objfile *));
113
114static struct type *hpread_read_enum_type
115 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
116
117static struct type *hpread_read_function_type
118 PARAMS ((dnttpointer, union dnttentry *, struct objfile *, int));
119
120static struct type *hpread_read_doc_function_type
121 PARAMS ((dnttpointer, union dnttentry *, struct objfile *, int));
122
123static struct type *hpread_read_struct_type
124 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
125
126static struct type *hpread_get_nth_template_arg
127 PARAMS ((struct objfile *, int));
128
c5aa993b 129static struct type *hpread_read_templ_arg_type
c906108c
SS
130 PARAMS ((dnttpointer, union dnttentry *, struct objfile *, char *));
131
132static struct type *hpread_read_set_type
133 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
134
c5aa993b
JM
135static struct type *hpread_read_array_type
136 PARAMS ((dnttpointer, union dnttentry * dn_bufp, struct objfile * objfile));
c906108c
SS
137
138static struct type *hpread_read_subrange_type
139 PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
140
c5aa993b 141static struct type *hpread_type_lookup
c906108c
SS
142 PARAMS ((dnttpointer, struct objfile *));
143
144static sltpointer hpread_record_lines
145 PARAMS ((struct subfile *, sltpointer, sltpointer,
146 struct objfile *, CORE_ADDR));
147
148static void hpread_process_one_debug_symbol
149 PARAMS ((union dnttentry *, char *, struct section_offsets *,
c5aa993b 150 struct objfile *, CORE_ADDR, int, char *, int, int *));
c906108c
SS
151
152static int hpread_get_scope_depth
153 PARAMS ((union dnttentry *, struct objfile *, int));
154
c5aa993b 155static void fix_static_member_physnames
c906108c
SS
156 PARAMS ((struct type *, char *, struct objfile *));
157
158static void fixup_class_method_type
159 PARAMS ((struct type *, struct type *, struct objfile *));
160
161static void hpread_adjust_bitoffsets PARAMS ((struct type *, int));
162
163static dnttpointer hpread_get_next_skip_over_anon_unions
164 PARAMS ((int, dnttpointer, union dnttentry **, struct objfile *));
165
166/* Global to indicate presence of HP-compiled objects,
167 in particular, SOM executable file with SOM debug info
c5aa993b 168 Defined in symtab.c, used in hppa-tdep.c. */
c906108c
SS
169extern int hp_som_som_object_present;
170
171/* Static used to indicate a class type that requires a
172 fix-up of one of its method types */
c5aa993b 173static struct type *fixup_class = NULL;
c906108c
SS
174
175/* Static used to indicate the method type that is to be
176 used to fix-up the type for fixup_class */
c5aa993b 177static struct type *fixup_method = NULL;
c906108c
SS
178\f
179
c5aa993b 180
c906108c
SS
181/* Get the nesting depth for the source line identified by INDEX. */
182
183static unsigned long
184hpread_get_scope_start (index, objfile)
185 sltpointer index;
186 struct objfile *objfile;
187{
188 union sltentry *sl_bufp;
189
190 sl_bufp = hpread_get_slt (index, objfile);
191 return sl_bufp->sspec.backptr.dnttp.index;
192}
193
194/* Get the source line number the the line identified by INDEX. */
195
196static unsigned long
197hpread_get_line (index, objfile)
198 sltpointer index;
199 struct objfile *objfile;
200{
201 union sltentry *sl_bufp;
202
203 sl_bufp = hpread_get_slt (index, objfile);
204 return sl_bufp->snorm.line;
205}
206
207/* Find the code address associated with a given sltpointer */
208
209static CORE_ADDR
210hpread_get_location (index, objfile)
211 sltpointer index;
212 struct objfile *objfile;
213{
214 union sltentry *sl_bufp;
215 int i;
216
217 /* code location of special sltentrys is determined from context */
218 sl_bufp = hpread_get_slt (index, objfile);
219
220 if (sl_bufp->snorm.sltdesc == SLT_END)
221 {
222 /* find previous normal sltentry and get address */
223 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
c5aa993b 224 (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
c906108c
SS
225 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
226 sl_bufp = hpread_get_slt (index - i, objfile);
227 if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
c5aa993b 228 return sl_bufp->snormoff.address;
c906108c 229 else
c5aa993b 230 return sl_bufp->snorm.address;
c906108c
SS
231 }
232
233 /* find next normal sltentry and get address */
234 for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
235 (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) &&
c5aa993b 236 (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
c906108c 237 sl_bufp = hpread_get_slt (index + i, objfile);
c5aa993b
JM
238 if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
239 return sl_bufp->snormoff.address;
240 else
241 return sl_bufp->snorm.address;
c906108c
SS
242}
243\f
244
245/* Return 1 if an HP debug symbol of type KIND has a name associated with
246 * it, else return 0. (This function is not currently used, but I'll
247 * leave it here in case it proves useful later on. - RT).
248 */
249
250int
251hpread_has_name (kind)
252 enum dntt_entry_type kind;
253{
254 switch (kind)
255 {
256 case DNTT_TYPE_SRCFILE:
257 case DNTT_TYPE_MODULE:
258 case DNTT_TYPE_FUNCTION:
259 case DNTT_TYPE_DOC_FUNCTION:
260 case DNTT_TYPE_ENTRY:
261 case DNTT_TYPE_IMPORT:
262 case DNTT_TYPE_LABEL:
263 case DNTT_TYPE_FPARAM:
264 case DNTT_TYPE_SVAR:
265 case DNTT_TYPE_DVAR:
266 case DNTT_TYPE_CONST:
267 case DNTT_TYPE_TYPEDEF:
268 case DNTT_TYPE_TAGDEF:
269 case DNTT_TYPE_MEMENUM:
270 case DNTT_TYPE_FIELD:
271 case DNTT_TYPE_SA:
272 case DNTT_TYPE_BLOCKDATA:
273 case DNTT_TYPE_MEMFUNC:
274 case DNTT_TYPE_DOC_MEMFUNC:
275 return 1;
276
277 case DNTT_TYPE_BEGIN:
278 case DNTT_TYPE_END:
279 case DNTT_TYPE_POINTER:
280 case DNTT_TYPE_ENUM:
281 case DNTT_TYPE_SET:
282 case DNTT_TYPE_ARRAY:
283 case DNTT_TYPE_STRUCT:
284 case DNTT_TYPE_UNION:
285 case DNTT_TYPE_VARIANT:
286 case DNTT_TYPE_FILE:
287 case DNTT_TYPE_FUNCTYPE:
288 case DNTT_TYPE_SUBRANGE:
289 case DNTT_TYPE_WITH:
290 case DNTT_TYPE_COMMON:
291 case DNTT_TYPE_COBSTRUCT:
292 case DNTT_TYPE_XREF:
293 case DNTT_TYPE_MACRO:
294 case DNTT_TYPE_CLASS_SCOPE:
295 case DNTT_TYPE_REFERENCE:
296 case DNTT_TYPE_PTRMEM:
297 case DNTT_TYPE_PTRMEMFUNC:
298 case DNTT_TYPE_CLASS:
299 case DNTT_TYPE_GENFIELD:
300 case DNTT_TYPE_VFUNC:
301 case DNTT_TYPE_MEMACCESS:
302 case DNTT_TYPE_INHERITANCE:
303 case DNTT_TYPE_FRIEND_CLASS:
304 case DNTT_TYPE_FRIEND_FUNC:
c5aa993b 305 case DNTT_TYPE_MODIFIER:
c906108c
SS
306 case DNTT_TYPE_OBJECT_ID:
307 case DNTT_TYPE_TEMPLATE:
308 case DNTT_TYPE_TEMPLATE_ARG:
309 case DNTT_TYPE_FUNC_TEMPLATE:
310 case DNTT_TYPE_LINK:
c5aa993b
JM
311 /* DNTT_TYPE_DYN_ARRAY_DESC ? */
312 /* DNTT_TYPE_DESC_SUBRANGE ? */
313 /* DNTT_TYPE_BEGIN_EXT ? */
314 /* DNTT_TYPE_INLN ? */
315 /* DNTT_TYPE_INLN_LIST ? */
316 /* DNTT_TYPE_ALIAS ? */
c906108c
SS
317 default:
318 return 0;
319 }
320}
321
322/* Do the dirty work of reading in the full symbol from a partial symbol
323 table. */
324
325static void
326hpread_psymtab_to_symtab_1 (pst)
327 struct partial_symtab *pst;
328{
329 struct cleanup *old_chain;
330 int i;
331
332 /* Get out quick if passed junk. */
333 if (!pst)
334 return;
335
336 /* Complain if we've already read in this symbol table. */
337 if (pst->readin)
338 {
339 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
340 pst->filename);
341 return;
342 }
343
344 /* Read in all partial symtabs on which this one is dependent */
345 for (i = 0; i < pst->number_of_dependencies; i++)
346 if (!pst->dependencies[i]->readin)
347 {
348 /* Inform about additional files that need to be read in. */
349 if (info_verbose)
350 {
351 fputs_filtered (" ", gdb_stdout);
352 wrap_here ("");
353 fputs_filtered ("and ", gdb_stdout);
354 wrap_here ("");
355 printf_filtered ("%s...", pst->dependencies[i]->filename);
356 wrap_here (""); /* Flush output */
357 gdb_flush (gdb_stdout);
358 }
359 hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
360 }
361
362 /* If it's real... */
363 if (LDSYMLEN (pst))
364 {
365 /* Init stuff necessary for reading in symbols */
366 buildsym_init ();
367 old_chain = make_cleanup (really_free_pendings, 0);
368
369 pst->symtab =
370 hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
371 pst->textlow, pst->texthigh - pst->textlow,
372 pst->section_offsets, pst->filename);
373 sort_symtab_syms (pst->symtab);
374
375 do_cleanups (old_chain);
376 }
377
378 pst->readin = 1;
379}
380
381/* Read in all of the symbols for a given psymtab for real.
382 Be verbose about it if the user wants that. */
383
384void
385hpread_psymtab_to_symtab (pst)
386 struct partial_symtab *pst;
387{
388 /* Get out quick if given junk. */
389 if (!pst)
390 return;
391
392 /* Sanity check. */
393 if (pst->readin)
394 {
395 fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
396 pst->filename);
397 return;
398 }
399
400 /* elz: setting the flag to indicate that the code of the target
401 was compiled using an HP compiler (aCC, cc)
402 the processing_acc_compilation variable is declared in the
403 file buildsym.h, the HP_COMPILED_TARGET is defined to be equal
c5aa993b 404 to 3 in the file tm_hppa.h */
c906108c
SS
405
406 processing_gcc_compilation = 0;
407
408 if (LDSYMLEN (pst) || pst->number_of_dependencies)
409 {
410 /* Print the message now, before reading the string table,
411 to avoid disconcerting pauses. */
412 if (info_verbose)
413 {
414 printf_filtered ("Reading in symbols for %s...", pst->filename);
415 gdb_flush (gdb_stdout);
416 }
417
418 hpread_psymtab_to_symtab_1 (pst);
419
420 /* Match with global symbols. This only needs to be done once,
421 after all of the symtabs and dependencies have been read in. */
422 scan_file_globals (pst->objfile);
423
424 /* Finish up the debug error message. */
425 if (info_verbose)
426 printf_filtered ("done.\n");
427 }
428}
429
430/* Read in a defined section of a specific object file's symbols.
431
432 DESC is the file descriptor for the file, positioned at the
433 beginning of the symtab
434 SYM_OFFSET is the offset within the file of
435 the beginning of the symbols we want to read
436 SYM_SIZE is the size of the symbol info to read in.
437 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
438 TEXT_SIZE is the size of the text segment read in.
439 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
440
441static struct symtab *
442hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
443 section_offsets, filename)
444 struct objfile *objfile;
445 int sym_offset;
446 int sym_size;
447 CORE_ADDR text_offset;
448 int text_size;
449 struct section_offsets *section_offsets;
450 char *filename;
451{
c5aa993b 452 char *namestring;
c906108c 453 union dnttentry *dn_bufp;
c5aa993b
JM
454 unsigned max_symnum;
455 int at_module_boundary = 0;
456 /* 1 => at end, -1 => at beginning */
c906108c
SS
457
458 int sym_index = sym_offset / sizeof (struct dntt_type_block);
459
460 current_objfile = objfile;
461 subfile_stack = 0;
462
463 last_source_file = 0;
464
465 /* Demangling style -- if EDG style already set, don't change it,
c5aa993b
JM
466 as HP style causes some problems with the KAI EDG compiler */
467 if (current_demangling_style != edg_demangling)
468 {
469 /* Otherwise, ensure that we are using HP style demangling */
470 set_demangling_style (HP_DEMANGLING_STYLE_STRING);
471 }
c906108c
SS
472
473 dn_bufp = hpread_get_lntt (sym_index, objfile);
474 if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
475 (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
476 {
477 start_symtab ("globals", NULL, 0);
478 record_debugformat ("HP");
479 }
480
481 /* The psymtab builder (hp-psymtab-read.c) is the one that
482 * determined the "sym_size" argument (i.e. how many DNTT symbols
483 * are in this symtab), which we use to compute "max_symnum"
484 * (point in DNTT to which we read).
485 *
486 * Perhaps this should be changed so that
487 * process_one_debug_symbol() "knows" when
488 * to stop reading (based on reading from the MODULE to the matching
489 * END), and take out this reliance on a #-syms being passed in...
490 * (I'm worried about the reliability of this number). But I'll
491 * leave it as-is, for now. - RT
492 *
493 * The change above has been made. I've left the "for" loop control
494 * in to prepare for backing this out again. -JB
495 */
496 max_symnum = sym_size / sizeof (struct dntt_type_block);
c5aa993b 497 /* No reason to multiply on pst side and divide on sym side... FIXME */
c906108c
SS
498
499 /* Read in and process each debug symbol within the specified range.
500 */
501 for (symnum = 0;
c5aa993b 502 symnum < max_symnum;
c906108c
SS
503 symnum++)
504 {
505 QUIT; /* Allow this to be interruptable */
506 dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
507
508 if (dn_bufp->dblock.extension)
509 continue;
510
511 /* Yow! We call SET_NAMESTRING on things without names! */
512 SET_NAMESTRING (dn_bufp, &namestring, objfile);
513
514 hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
515 objfile, text_offset, text_size,
516 filename, symnum + sym_index,
c5aa993b
JM
517 &at_module_boundary
518 );
519
c906108c
SS
520 /* OLD COMMENTS: This routine is only called for psts. All psts
521 * correspond to MODULES. If we ever do lazy-reading of globals
522 * from the LNTT, then there will be a pst which ends when the
523 * LNTT ends, and not at an END MODULE entry. Then we'll have
524 * to re-visit this break.
525
526 if( at_end_of_module )
c5aa993b 527 break;
c906108c
SS
528
529 */
530
531 /* We no longer break out of the loop when we reach the end of a
532 module. The reason is that with CTTI, the compiler can generate
533 function symbols (for template function instantiations) which are not
534 in any module; typically they show up beyond a module's end, and
535 before the next module's start. We include them in the current
536 module. However, we still don't trust the MAX_SYMNUM value from
537 the psymtab, so we break out if we enter a new module. */
538
539 if (at_module_boundary == -1)
c5aa993b 540 break;
c906108c
SS
541 }
542
543 current_objfile = NULL;
c5aa993b
JM
544 hp_som_som_object_present = 1; /* Indicate we've processed an HP SOM SOM file */
545
c906108c
SS
546 return end_symtab (text_offset + text_size, objfile, 0);
547}
548\f
549
550
551
552/* Convert basic types from HP debug format into GDB internal format. */
553
554static int
555hpread_type_translate (typep)
556 dnttpointer typep;
557{
c5aa993b
JM
558 if (!typep.dntti.immediate)
559 {
560 error ("error in hpread_type_translate\n.");
561 return;
562 }
c906108c
SS
563
564 switch (typep.dntti.type)
565 {
566 case HP_TYPE_BOOLEAN:
567 case HP_TYPE_BOOLEAN_S300_COMPAT:
568 case HP_TYPE_BOOLEAN_VAX_COMPAT:
569 return FT_BOOLEAN;
c5aa993b
JM
570 case HP_TYPE_CHAR: /* C signed char, C++ plain char */
571
c906108c
SS
572 case HP_TYPE_WIDE_CHAR:
573 return FT_CHAR;
574 case HP_TYPE_INT:
575 if (typep.dntti.bitlength <= 8)
c5aa993b 576 return FT_SIGNED_CHAR; /* C++ signed char */
c906108c
SS
577 if (typep.dntti.bitlength <= 16)
578 return FT_SHORT;
579 if (typep.dntti.bitlength <= 32)
580 return FT_INTEGER;
581 return FT_LONG_LONG;
582 case HP_TYPE_LONG:
583 if (typep.dntti.bitlength <= 8)
c5aa993b 584 return FT_SIGNED_CHAR; /* C++ signed char. */
c906108c
SS
585 return FT_LONG;
586 case HP_TYPE_UNSIGNED_LONG:
587 if (typep.dntti.bitlength <= 8)
c5aa993b 588 return FT_UNSIGNED_CHAR; /* C/C++ unsigned char */
c906108c
SS
589 if (typep.dntti.bitlength <= 16)
590 return FT_UNSIGNED_SHORT;
591 if (typep.dntti.bitlength <= 32)
592 return FT_UNSIGNED_LONG;
593 return FT_UNSIGNED_LONG_LONG;
594 case HP_TYPE_UNSIGNED_INT:
595 if (typep.dntti.bitlength <= 8)
596 return FT_UNSIGNED_CHAR;
597 if (typep.dntti.bitlength <= 16)
598 return FT_UNSIGNED_SHORT;
599 if (typep.dntti.bitlength <= 32)
600 return FT_UNSIGNED_INTEGER;
601 return FT_UNSIGNED_LONG_LONG;
602 case HP_TYPE_REAL:
603 case HP_TYPE_REAL_3000:
604 case HP_TYPE_DOUBLE:
605 if (typep.dntti.bitlength == 64)
606 return FT_DBL_PREC_FLOAT;
607 if (typep.dntti.bitlength == 128)
608 return FT_EXT_PREC_FLOAT;
609 return FT_FLOAT;
610 case HP_TYPE_COMPLEX:
611 case HP_TYPE_COMPLEXS3000:
612 if (typep.dntti.bitlength == 128)
613 return FT_DBL_PREC_COMPLEX;
614 if (typep.dntti.bitlength == 192)
615 return FT_EXT_PREC_COMPLEX;
616 return FT_COMPLEX;
617 case HP_TYPE_VOID:
618 return FT_VOID;
619 case HP_TYPE_STRING200:
620 case HP_TYPE_LONGSTRING200:
621 case HP_TYPE_FTN_STRING_SPEC:
622 case HP_TYPE_MOD_STRING_SPEC:
623 case HP_TYPE_MOD_STRING_3000:
624 case HP_TYPE_FTN_STRING_S300_COMPAT:
625 case HP_TYPE_FTN_STRING_VAX_COMPAT:
626 return FT_STRING;
627 case HP_TYPE_TEMPLATE_ARG:
628 return FT_TEMPLATE_ARG;
629 case HP_TYPE_TEXT:
630 case HP_TYPE_FLABEL:
631 case HP_TYPE_PACKED_DECIMAL:
c5aa993b 632 case HP_TYPE_ANYPOINTER:
c906108c 633 case HP_TYPE_GLOBAL_ANYPOINTER:
c5aa993b 634 case HP_TYPE_LOCAL_ANYPOINTER:
c906108c
SS
635 default:
636 warning ("hpread_type_translate: unhandled type code.\n");
637 return FT_VOID;
638 }
639}
640
641/* Given a position in the DNTT, return a pointer to the
642 * already-built "struct type" (if any), for the type defined
643 * at that position.
644 */
645
646static struct type **
647hpread_lookup_type (hp_type, objfile)
648 dnttpointer hp_type;
649 struct objfile *objfile;
650{
651 unsigned old_len;
652 int index = hp_type.dnttp.index;
653 int size_changed = 0;
654
655 /* The immediate flag indicates this doesn't actually point to
656 * a type DNTT.
657 */
658 if (hp_type.dntti.immediate)
659 return NULL;
660
661 /* For each objfile, we maintain a "type vector".
662 * This an array of "struct type *"'s with one pointer per DNTT index.
663 * Given a DNTT index, we look in this array to see if we have
664 * already processed this DNTT and if it is a type definition.
665 * If so, then we can locate a pointer to the already-built
666 * "struct type", and not build it again.
667 *
668 * The need for this arises because our DNTT-walking code wanders
669 * around. In particular, it will encounter the same type multiple
670 * times (once for each object of that type). We don't want to
671 * built multiple "struct type"'s for the same thing.
672 *
673 * Having said this, I should point out that this type-vector is
674 * an expensive way to keep track of this. If most DNTT entries are
675 * 3 words, the type-vector will be 1/3 the size of the DNTT itself.
676 * Alternative solutions:
677 * - Keep a compressed or hashed table. Less memory, but more expensive
678 * to search and update.
679 * - (Suggested by JB): Overwrite the DNTT entry itself
680 * with the info. Create a new type code "ALREADY_BUILT", and modify
681 * the DNTT to have that type code and point to the already-built entry.
682 * -RT
683 */
684
685 if (index < LNTT_SYMCOUNT (objfile))
686 {
687 if (index >= TYPE_VECTOR_LENGTH (objfile))
688 {
689 old_len = TYPE_VECTOR_LENGTH (objfile);
690
c5aa993b 691 /* See if we need to allocate a type-vector. */
c906108c
SS
692 if (old_len == 0)
693 {
c5aa993b 694 TYPE_VECTOR_LENGTH (objfile) = LNTT_SYMCOUNT (objfile) + GNTT_SYMCOUNT (objfile);
c906108c
SS
695 TYPE_VECTOR (objfile) = (struct type **)
696 xmmalloc (objfile->md, TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
697 memset (&TYPE_VECTOR (objfile)[old_len], 0,
c5aa993b
JM
698 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
699 sizeof (struct type *));
c906108c
SS
700 }
701
c5aa993b
JM
702 /* See if we need to resize type-vector. With my change to
703 * initially allocate a correct-size type-vector, this code
704 * should no longer trigger.
705 */
706 while (index >= TYPE_VECTOR_LENGTH (objfile))
707 {
708 TYPE_VECTOR_LENGTH (objfile) *= 2;
709 size_changed = 1;
710 }
711 if (size_changed)
712 {
713 TYPE_VECTOR (objfile) = (struct type **)
714 xmrealloc (objfile->md,
715 (char *) TYPE_VECTOR (objfile),
716 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
c906108c
SS
717
718 memset (&TYPE_VECTOR (objfile)[old_len], 0,
c5aa993b
JM
719 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
720 sizeof (struct type *));
721 }
c906108c
SS
722
723 }
724 return &TYPE_VECTOR (objfile)[index];
725 }
726 else
727 return NULL;
728}
729
730/* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
731 Note we'll just return the address of a GDB internal type if we already
732 have it lying around. */
733
734static struct type *
735hpread_alloc_type (hp_type, objfile)
736 dnttpointer hp_type;
737 struct objfile *objfile;
738{
739 struct type **type_addr;
740
741 type_addr = hpread_lookup_type (hp_type, objfile);
c5aa993b
JM
742 if (*type_addr == 0)
743 {
744 *type_addr = alloc_type (objfile);
c906108c 745
c5aa993b
JM
746 /* A hack - if we really are a C++ class symbol, then this default
747 * will get overriden later on.
748 */
749 TYPE_CPLUS_SPECIFIC (*type_addr)
750 = (struct cplus_struct_type *) &cplus_struct_default;
751 }
c906108c
SS
752
753 return *type_addr;
754}
755
756/* Read a native enumerated type and return it in GDB internal form. */
757
758static struct type *
759hpread_read_enum_type (hp_type, dn_bufp, objfile)
760 dnttpointer hp_type;
761 union dnttentry *dn_bufp;
762 struct objfile *objfile;
763{
764 struct type *type;
765 struct pending **symlist, *osyms, *syms;
766 struct pending *local_list = NULL;
767 int o_nsyms, nsyms = 0;
768 dnttpointer mem;
769 union dnttentry *memp;
770 char *name;
771 long n;
772 struct symbol *sym;
773
774 /* Allocate a GDB type. If we've already read in this enum type,
775 * it'll return the already built GDB type, so stop here.
776 * (Note: I added this check, to conform with what's done for
777 * struct, union, class.
778 * I assume this is OK. - RT)
779 */
780 type = hpread_alloc_type (hp_type, objfile);
781 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
782 return type;
783
784 /* HP C supports "sized enums", where a specifier such as "short" or
785 "char" can be used to get enums of different sizes. So don't assume
786 an enum is always 4 bytes long. pai/1997-08-21 */
787 TYPE_LENGTH (type) = dn_bufp->denum.bitlength / 8;
788
789 symlist = &file_symbols;
790 osyms = *symlist;
791 o_nsyms = osyms ? osyms->nsyms : 0;
792
793 /* Get a name for each member and add it to our list of members.
794 * The list of "mem" SOM records we are walking should all be
795 * SOM type DNTT_TYPE_MEMENUM (not checked).
796 */
797 mem = dn_bufp->denum.firstmem;
798 while (mem.word && mem.word != DNTTNIL)
799 {
800 memp = hpread_get_lntt (mem.dnttp.index, objfile);
801
802 name = VT (objfile) + memp->dmember.name;
803 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
804 sizeof (struct symbol));
805 memset (sym, 0, sizeof (struct symbol));
c5aa993b 806 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
c906108c
SS
807 &objfile->symbol_obstack);
808 SYMBOL_CLASS (sym) = LOC_CONST;
809 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
810 SYMBOL_VALUE (sym) = memp->dmember.value;
811 add_symbol_to_list (sym, symlist);
812 nsyms++;
813 mem = memp->dmember.nextmem;
814 }
815
816 /* Now that we know more about the enum, fill in more info. */
817 TYPE_CODE (type) = TYPE_CODE_ENUM;
818 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
819 TYPE_NFIELDS (type) = nsyms;
820 TYPE_FIELDS (type) = (struct field *)
821 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
822
823 /* Find the symbols for the members and put them into the type.
824 The symbols can be found in the symlist that we put them on
825 to cause them to be defined. osyms contains the old value
826 of that symlist; everything up to there was defined by us.
827
828 Note that we preserve the order of the enum constants, so
829 that in something like "enum {FOO, LAST_THING=FOO}" we print
830 FOO, not LAST_THING. */
831 for (syms = *symlist, n = 0; syms; syms = syms->next)
832 {
833 int j = 0;
834 if (syms == osyms)
835 j = o_nsyms;
836 for (; j < syms->nsyms; j++, n++)
837 {
838 struct symbol *xsym = syms->symbol[j];
839 SYMBOL_TYPE (xsym) = type;
840 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
841 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
842 TYPE_FIELD_BITSIZE (type, n) = 0;
843 }
844 if (syms == osyms)
845 break;
846 }
847
848 return type;
849}
850
851/* Read and internalize a native function debug symbol. */
852
853static struct type *
854hpread_read_function_type (hp_type, dn_bufp, objfile, newblock)
855 dnttpointer hp_type;
856 union dnttentry *dn_bufp;
857 struct objfile *objfile;
858 int newblock;
859{
860 struct type *type, *type1;
861 struct pending *syms;
862 struct pending *local_list = NULL;
863 int nsyms = 0;
864 dnttpointer param;
865 union dnttentry *paramp;
866 char *name;
867 long n;
868 struct symbol *sym;
869 int record_args = 1;
870
871 /* See if we've already read in this type. */
872 type = hpread_alloc_type (hp_type, objfile);
873 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
874 {
c5aa993b 875 record_args = 0; /* already read in, don't modify type */
c906108c
SS
876 }
877 else
878 {
879 /* Nope, so read it in and store it away. */
880 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
c5aa993b
JM
881 dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
882 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
883 objfile));
c906108c 884 else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
c5aa993b
JM
885 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
886 objfile));
887 else /* expect DNTT_TYPE_FUNC_TEMPLATE */
888 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc_template.retval,
889 objfile));
c906108c 890 memcpy ((char *) type, (char *) type1, sizeof (struct type));
c5aa993b
JM
891
892 /* Mark it -- in the middle of processing */
c906108c
SS
893 TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
894 }
895
896 /* Now examine each parameter noting its type, location, and a
897 wealth of other information. */
898 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION ||
899 dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC)
900 param = dn_bufp->dfunc.firstparam;
901 else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE)
902 param = dn_bufp->dfunctype.firstparam;
c5aa993b 903 else /* expect DNTT_TYPE_FUNC_TEMPLATE */
c906108c
SS
904 param = dn_bufp->dfunc_template.firstparam;
905 while (param.word && param.word != DNTTNIL)
906 {
907 paramp = hpread_get_lntt (param.dnttp.index, objfile);
908 nsyms++;
909 param = paramp->dfparam.nextparam;
910
911 /* Get the name. */
912 name = VT (objfile) + paramp->dfparam.name;
913 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
914 sizeof (struct symbol));
915 (void) memset (sym, 0, sizeof (struct symbol));
916 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
917 &objfile->symbol_obstack);
918
919 /* Figure out where it lives. */
920 if (paramp->dfparam.regparam)
921 SYMBOL_CLASS (sym) = LOC_REGPARM;
922 else if (paramp->dfparam.indirect)
923 SYMBOL_CLASS (sym) = LOC_REF_ARG;
924 else
925 SYMBOL_CLASS (sym) = LOC_ARG;
926 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
927 if (paramp->dfparam.copyparam)
928 {
c5aa993b 929 SYMBOL_VALUE (sym) = paramp->dfparam.location;
c906108c
SS
930#ifdef HPREAD_ADJUST_STACK_ADDRESS
931 SYMBOL_VALUE (sym)
932 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
933#endif
934 /* This is likely a pass-by-invisible reference parameter,
935 Hack on the symbol class to make GDB happy. */
c5aa993b
JM
936 /* ??rehrauer: This appears to be broken w/r/t to passing
937 C values of type float and struct. Perhaps this ought
938 to be highighted as a special case, but for now, just
939 allowing these to be LOC_ARGs seems to work fine.
940 */
c906108c
SS
941#if 0
942 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
943#endif
944 }
945 else
946 SYMBOL_VALUE (sym) = paramp->dfparam.location;
947
948 /* Get its type. */
949 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
950 /* Add it to the symbol list. */
951 /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
952 * called on FPARAM symbols from the process_one_debug_symbol()
953 * level... so parameters are getting added twice! (this shows
954 * up in the symbol dump you get from "maint print symbols ...").
955 * Note 2 (RT) I took out the processing of FPARAM from the
956 * process_one_debug_symbol() level, so at the moment parameters are only
957 * being processed here. This seems to have no ill effect.
958 */
959 /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
960 each fparam on the local_symbols list from here. Now we use the
961 local_list to which fparams are added below, and set the param_symbols
c5aa993b 962 global to point to that at the end of this routine. */
c906108c
SS
963 /* elz: I added this new list of symbols which is local to the function.
964 this list is the one which is actually used to build the type for the
965 function rather than the gloabal list pointed to by symlist.
966 Using a global list to keep track of the parameters is wrong, because
967 this function is called recursively if one parameter happend to be
968 a function itself with more parameters in it. Adding parameters to the
969 same global symbol list would not work!
970 Actually it did work in case of cc compiled programs where you do
c5aa993b 971 not check the parameter lists of the arguments. */
c906108c
SS
972 add_symbol_to_list (sym, &local_list);
973
974 }
975
976 /* If type was read in earlier, don't bother with modifying
c5aa993b 977 the type struct */
c906108c
SS
978 if (!record_args)
979 goto finish;
c5aa993b 980
c906108c
SS
981 /* Note how many parameters we found. */
982 TYPE_NFIELDS (type) = nsyms;
983 TYPE_FIELDS (type) = (struct field *)
984 obstack_alloc (&objfile->type_obstack,
985 sizeof (struct field) * nsyms);
986
987 /* Find the symbols for the parameters and
988 use them to fill parameter-type information into the function-type.
989 The parameter symbols can be found in the local_list that we just put them on. */
990 /* Note that we preserve the order of the parameters, so
991 that in something like "enum {FOO, LAST_THING=FOO}" we print
992 FOO, not LAST_THING. */
c5aa993b 993
c906108c
SS
994 /* get the parameters types from the local list not the global list
995 so that the type can be correctly constructed for functions which
996 have function as parameters */
997 for (syms = local_list, n = 0; syms; syms = syms->next)
998 {
999 int j = 0;
c5aa993b 1000 for (j = 0; j < syms->nsyms; j++, n++)
c906108c
SS
1001 {
1002 struct symbol *xsym = syms->symbol[j];
1003 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1004 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1005 TYPE_FIELD_BITPOS (type, n) = n;
1006 TYPE_FIELD_BITSIZE (type, n) = 0;
1007 }
1008 }
c5aa993b 1009 /* Mark it as having been processed */
c906108c
SS
1010 TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
1011
1012 /* Check whether we need to fix-up a class type with this function's type */
1013 if (fixup_class && (fixup_method == type))
1014 {
1015 fixup_class_method_type (fixup_class, fixup_method, objfile);
1016 fixup_class = NULL;
1017 fixup_method = NULL;
1018 }
1019
1020 /* Set the param list of this level of the context stack
1021 to our local list. Do this only if this function was
1022 called for creating a new block, and not if it was called
1023 simply to get the function type. This prevents recursive
1024 invocations from trashing param_symbols. */
c5aa993b 1025finish:
c906108c
SS
1026 if (newblock)
1027 param_symbols = local_list;
c5aa993b
JM
1028
1029 return type;
c906108c
SS
1030}
1031
1032
1033/* Read and internalize a native DOC function debug symbol. */
1034/* This is almost identical to hpread_read_function_type(), except
1035 * for references to dn_bufp->ddocfunc instead of db_bufp->dfunc.
1036 * Since debug information for DOC functions is more likely to be
1037 * volatile, please leave it this way.
1038 */
1039static struct type *
1040hpread_read_doc_function_type (hp_type, dn_bufp, objfile, newblock)
1041 dnttpointer hp_type;
1042 union dnttentry *dn_bufp;
1043 struct objfile *objfile;
1044 int newblock;
1045{
1046 struct type *type, *type1;
1047 struct pending *syms;
1048 struct pending *local_list = NULL;
1049 int nsyms = 0;
1050 dnttpointer param;
1051 union dnttentry *paramp;
1052 char *name;
1053 long n;
1054 struct symbol *sym;
1055 int record_args = 1;
1056
1057 /* See if we've already read in this type. */
1058 type = hpread_alloc_type (hp_type, objfile);
1059 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1060 {
c5aa993b 1061 record_args = 0; /* already read in, don't modify type */
c906108c
SS
1062 }
1063 else
1064 {
1065 /* Nope, so read it in and store it away. */
1066 if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
c5aa993b
JM
1067 dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
1068 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->ddocfunc.retval,
1069 objfile));
c906108c 1070 memcpy ((char *) type, (char *) type1, sizeof (struct type));
c5aa993b
JM
1071
1072 /* Mark it -- in the middle of processing */
c906108c
SS
1073 TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
1074 }
1075
1076 /* Now examine each parameter noting its type, location, and a
1077 wealth of other information. */
1078 if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION ||
1079 dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)
1080 param = dn_bufp->ddocfunc.firstparam;
1081 while (param.word && param.word != DNTTNIL)
1082 {
1083 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1084 nsyms++;
1085 param = paramp->dfparam.nextparam;
1086
1087 /* Get the name. */
1088 name = VT (objfile) + paramp->dfparam.name;
1089 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1090 sizeof (struct symbol));
1091 (void) memset (sym, 0, sizeof (struct symbol));
1092 SYMBOL_NAME (sym) = name;
1093
1094 /* Figure out where it lives. */
1095 if (paramp->dfparam.regparam)
1096 SYMBOL_CLASS (sym) = LOC_REGPARM;
1097 else if (paramp->dfparam.indirect)
1098 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1099 else
1100 SYMBOL_CLASS (sym) = LOC_ARG;
1101 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1102 if (paramp->dfparam.copyparam)
1103 {
c5aa993b 1104 SYMBOL_VALUE (sym) = paramp->dfparam.location;
c906108c
SS
1105#ifdef HPREAD_ADJUST_STACK_ADDRESS
1106 SYMBOL_VALUE (sym)
1107 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1108#endif
1109 /* This is likely a pass-by-invisible reference parameter,
1110 Hack on the symbol class to make GDB happy. */
c5aa993b
JM
1111 /* ??rehrauer: This appears to be broken w/r/t to passing
1112 C values of type float and struct. Perhaps this ought
1113 to be highighted as a special case, but for now, just
1114 allowing these to be LOC_ARGs seems to work fine.
1115 */
c906108c
SS
1116#if 0
1117 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1118#endif
1119 }
1120 else
1121 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1122
1123 /* Get its type. */
1124 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1125 /* Add it to the symbol list. */
1126 /* Note 1 (RT) At the moment, add_symbol_to_list() is also being
1127 * called on FPARAM symbols from the process_one_debug_symbol()
1128 * level... so parameters are getting added twice! (this shows
1129 * up in the symbol dump you get from "maint print symbols ...").
1130 * Note 2 (RT) I took out the processing of FPARAM from the
1131 * process_one_debug_symbol() level, so at the moment parameters are only
1132 * being processed here. This seems to have no ill effect.
1133 */
1134 /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put
1135 each fparam on the local_symbols list from here. Now we use the
1136 local_list to which fparams are added below, and set the param_symbols
c5aa993b
JM
1137 global to point to that at the end of this routine. */
1138
c906108c
SS
1139 /* elz: I added this new list of symbols which is local to the function.
1140 this list is the one which is actually used to build the type for the
1141 function rather than the gloabal list pointed to by symlist.
1142 Using a global list to keep track of the parameters is wrong, because
1143 this function is called recursively if one parameter happend to be
1144 a function itself with more parameters in it. Adding parameters to the
1145 same global symbol list would not work!
1146 Actually it did work in case of cc compiled programs where you do not check the
1147 parameter lists of the arguments. */
1148 add_symbol_to_list (sym, &local_list);
1149 }
1150
1151 /* If type was read in earlier, don't bother with modifying
c5aa993b 1152 the type struct */
c906108c
SS
1153 if (!record_args)
1154 goto finish;
c5aa993b 1155
c906108c
SS
1156 /* Note how many parameters we found. */
1157 TYPE_NFIELDS (type) = nsyms;
1158 TYPE_FIELDS (type) = (struct field *)
1159 obstack_alloc (&objfile->type_obstack,
c5aa993b 1160 sizeof (struct field) * nsyms);
c906108c
SS
1161
1162 /* Find the symbols for the parameters and
1163 use them to fill parameter-type information into the function-type.
1164 The parameter symbols can be found in the local_list that we just put them on. */
1165 /* Note that we preserve the order of the parameters, so
1166 that in something like "enum {FOO, LAST_THING=FOO}" we print
1167 FOO, not LAST_THING. */
c5aa993b 1168
c906108c
SS
1169 /* get the parameters types from the local list not the global list
1170 so that the type can be correctly constructed for functions which
1171 have function as parameters
c5aa993b 1172 */
c906108c
SS
1173 for (syms = local_list, n = 0; syms; syms = syms->next)
1174 {
1175 int j = 0;
1176 for (j = 0; j < syms->nsyms; j++, n++)
c5aa993b
JM
1177 {
1178 struct symbol *xsym = syms->symbol[j];
1179 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1180 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1181 TYPE_FIELD_BITPOS (type, n) = n;
1182 TYPE_FIELD_BITSIZE (type, n) = 0;
1183 }
c906108c 1184 }
c5aa993b
JM
1185
1186 /* Mark it as having been processed */
c906108c
SS
1187 TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE);
1188
1189 /* Check whether we need to fix-up a class type with this function's type */
1190 if (fixup_class && (fixup_method == type))
1191 {
1192 fixup_class_method_type (fixup_class, fixup_method, objfile);
1193 fixup_class = NULL;
1194 fixup_method = NULL;
1195 }
1196
1197 /* Set the param list of this level of the context stack
1198 to our local list. Do this only if this function was
1199 called for creating a new block, and not if it was called
1200 simply to get the function type. This prevents recursive
1201 invocations from trashing param_symbols. */
c5aa993b 1202finish:
c906108c
SS
1203 if (newblock)
1204 param_symbols = local_list;
c5aa993b 1205
c906108c
SS
1206 return type;
1207}
1208
1209
1210
1211/* A file-level variable which keeps track of the current-template
1212 * being processed. Set in hpread_read_struct_type() while processing
1213 * a template type. Referred to in hpread_get_nth_templ_arg().
1214 * Yes, this is a kludge, but it arises from the kludge that already
1215 * exists in symtab.h, namely the fact that they encode
1216 * "template argument n" with fundamental type FT_TEMPLATE_ARG and
1217 * bitlength n. This means that deep in processing fundamental types
1218 * I need to ask the question "what template am I in the middle of?".
1219 * The alternative to stuffing a global would be to pass an argument
1220 * down the chain of calls just for this purpose.
1221 *
1222 * There may be problems handling nested templates... tough.
1223 */
c5aa993b 1224static struct type *current_template = NULL;
c906108c
SS
1225
1226/* Read in and internalize a structure definition.
1227 * This same routine is called for struct, union, and class types.
1228 * Also called for templates, since they build a very similar
1229 * type entry as for class types.
1230 */
1231
1232static struct type *
1233hpread_read_struct_type (hp_type, dn_bufp, objfile)
1234 dnttpointer hp_type;
1235 union dnttentry *dn_bufp;
1236 struct objfile *objfile;
1237{
1238 /* The data members get linked together into a list of struct nextfield's */
1239 struct nextfield
1240 {
1241 struct nextfield *next;
1242 struct field field;
c5aa993b
JM
1243 unsigned char attributes; /* store visibility and virtuality info */
1244#define ATTR_VIRTUAL 1
1245#define ATTR_PRIVATE 2
1246#define ATTR_PROTECT 3
c906108c
SS
1247 };
1248
1249
1250 /* The methods get linked together into a list of struct next_fn_field's */
1251 struct next_fn_field
1252 {
1253 struct next_fn_field *next;
1254 struct fn_fieldlist field;
1255 struct fn_field fn_field;
1256 int num_fn_fields;
c5aa993b 1257 };
c906108c
SS
1258
1259 /* The template args get linked together into a list of struct next_template's */
1260 struct next_template
1261 {
1262 struct next_template *next;
1263 struct template_arg arg;
1264 };
1265
1266 /* The template instantiations get linked together into a list of these... */
c5aa993b 1267 struct next_instantiation
c906108c 1268 {
c5aa993b
JM
1269 struct next_instantiation *next;
1270 struct type *t;
c906108c
SS
1271 };
1272
1273 struct type *type;
1274 struct type *baseclass;
1275 struct type *memtype;
1276 struct nextfield *list = 0, *tmp_list = 0;
1277 struct next_fn_field *fn_list = 0;
1278 struct next_fn_field *fn_p;
1279 struct next_template *t_new, *t_list = 0;
1280 struct nextfield *new;
1281 struct next_fn_field *fn_new;
1282 struct next_instantiation *i_new, *i_list = 0;
1283 int n, nfields = 0, n_fn_fields = 0, n_fn_fields_total = 0;
1284 int n_base_classes = 0, n_templ_args = 0;
1285 int ninstantiations = 0;
1286 dnttpointer field, fn_field, parent;
1287 union dnttentry *fieldp, *fn_fieldp, *parentp;
1288 int i;
1289 int static_member = 0;
1290 int const_member = 0;
1291 int volatile_member = 0;
1292 unsigned long vtbl_offset;
1293 int need_bitvectors = 0;
c5aa993b
JM
1294 char *method_name = NULL;
1295 char *method_alias = NULL;
1296
c906108c
SS
1297
1298 /* Is it something we've already dealt with? */
1299 type = hpread_alloc_type (hp_type, objfile);
1300 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1301 (TYPE_CODE (type) == TYPE_CODE_UNION) ||
1302 (TYPE_CODE (type) == TYPE_CODE_CLASS) ||
1303 (TYPE_CODE (type) == TYPE_CODE_TEMPLATE))
c5aa993b 1304 return type;
c906108c
SS
1305
1306 /* Get the basic type correct. */
1307 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1308 {
1309 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1310 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1311 }
1312 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1313 {
1314 TYPE_CODE (type) = TYPE_CODE_UNION;
1315 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1316 }
1317 else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
1318 {
c5aa993b 1319 TYPE_CODE (type) = TYPE_CODE_CLASS;
c906108c
SS
1320 TYPE_LENGTH (type) = dn_bufp->dclass.bitlength / 8;
1321
1322 /* Overrides the TYPE_CPLUS_SPECIFIC(type) with allocated memory
1323 * rather than &cplus_struct_default.
1324 */
c5aa993b 1325 allocate_cplus_struct_type (type);
c906108c
SS
1326
1327 /* Fill in declared-type.
1328 * (The C++ compiler will emit TYPE_CODE_CLASS
1329 * for all 3 of "class", "struct"
1330 * "union", and we have to look at the "class_decl" field if we
1331 * want to know how it was really declared)
1332 */
1333 /* (0==class, 1==union, 2==struct) */
c5aa993b 1334 TYPE_DECLARED_TYPE (type) = dn_bufp->dclass.class_decl;
c906108c
SS
1335 }
1336 else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
1337 {
1338 /* Get the basic type correct. */
c5aa993b
JM
1339 TYPE_CODE (type) = TYPE_CODE_TEMPLATE;
1340 allocate_cplus_struct_type (type);
1341 TYPE_DECLARED_TYPE (type) = DECLARED_TYPE_TEMPLATE;
c906108c
SS
1342 }
1343 else
1344 return type;
1345
1346
1347 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1348
1349 /* For classes, read the parent list.
1350 * Question (RT): Do we need to do this for templates also?
1351 */
c5aa993b
JM
1352 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
1353 {
c906108c 1354
c5aa993b
JM
1355 /* First read the parent-list (classes from which we derive fields) */
1356 parent = dn_bufp->dclass.parentlist;
1357 while (parent.word && parent.word != DNTTNIL)
1358 {
1359 parentp = hpread_get_lntt (parent.dnttp.index, objfile);
c906108c 1360
c5aa993b 1361 /* "parentp" should point to a DNTT_TYPE_INHERITANCE record */
c906108c 1362
c5aa993b
JM
1363 /* Get space to record the next field/data-member. */
1364 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1365 new->next = list;
1366 list = new;
c906108c 1367
c5aa993b 1368 FIELD_BITSIZE (list->field) = 0;
c906108c 1369
c5aa993b
JM
1370 /* The "classname" field is actually a DNTT pointer to the base class */
1371 baseclass = hpread_type_lookup (parentp->dinheritance.classname,
1372 objfile);
1373 FIELD_TYPE (list->field) = baseclass;
c906108c 1374
c5aa993b 1375 list->field.name = type_name_no_tag (FIELD_TYPE (list->field));
c906108c 1376
c5aa993b 1377 list->attributes = 0;
c906108c 1378
c5aa993b
JM
1379 /* Check for virtuality of base, and set the
1380 * offset of the base subobject within the object.
1381 * (Offset set to -1 for virtual bases (for now).)
1382 */
1383 if (parentp->dinheritance.Virtual)
1384 {
1385 B_SET (&(list->attributes), ATTR_VIRTUAL);
1386 parentp->dinheritance.offset = -1;
1387 }
1388 else
1389 FIELD_BITPOS (list->field) = parentp->dinheritance.offset;
1390
1391 /* Check visibility */
1392 switch (parentp->dinheritance.visibility)
1393 {
1394 case 1:
1395 B_SET (&(list->attributes), ATTR_PROTECT);
1396 break;
1397 case 2:
1398 B_SET (&(list->attributes), ATTR_PRIVATE);
1399 break;
1400 }
1401
1402 n_base_classes++;
1403 nfields++;
1404
1405 parent = parentp->dinheritance.next;
1406 }
c906108c 1407 }
c906108c
SS
1408
1409 /* For templates, read the template argument list.
1410 * This must be done before processing the member list, because
1411 * the member list may refer back to this. E.g.:
1412 * template <class T1, class T2> class q2 {
1413 * public:
1414 * T1 a;
1415 * T2 b;
1416 * };
1417 * We need to read the argument list "T1", "T2" first.
1418 */
c5aa993b
JM
1419 if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
1420 {
1421 /* Kludge alert: This stuffs a global "current_template" which
1422 * is referred to by hpread_get_nth_templ_arg(). The global
1423 * is cleared at the end of this routine.
1424 */
1425 current_template = type;
c906108c 1426
c5aa993b
JM
1427 /* Read in the argument list */
1428 field = dn_bufp->dtemplate.arglist;
1429 while (field.word && field.word != DNTTNIL)
1430 {
1431 /* Get this template argument */
1432 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1433 if (fieldp->dblock.kind != DNTT_TYPE_TEMPLATE_ARG)
1434 {
1435 warning ("Invalid debug info: Template argument entry is of wrong kind");
1436 break;
1437 }
1438 /* Bump the count */
1439 n_templ_args++;
1440 /* Allocate and fill in a struct next_template */
1441 t_new = (struct next_template *) alloca (sizeof (struct next_template));
1442 t_new->next = t_list;
1443 t_list = t_new;
1444 t_list->arg.name = VT (objfile) + fieldp->dtempl_arg.name;
1445 t_list->arg.type = hpread_read_templ_arg_type (field, fieldp,
1446 objfile, t_list->arg.name);
1447 /* Walk to the next template argument */
1448 field = fieldp->dtempl_arg.nextarg;
1449 }
c906108c 1450 }
c906108c 1451
c5aa993b 1452 TYPE_NTEMPLATE_ARGS (type) = n_templ_args;
c906108c
SS
1453
1454 if (n_templ_args > 0)
c5aa993b 1455 TYPE_TEMPLATE_ARGS (type) = (struct template_arg *)
c906108c
SS
1456 obstack_alloc (&objfile->type_obstack, sizeof (struct template_arg) * n_templ_args);
1457 for (n = n_templ_args; t_list; t_list = t_list->next)
1458 {
1459 n -= 1;
c5aa993b 1460 TYPE_TEMPLATE_ARG (type, n) = t_list->arg;
c906108c
SS
1461 }
1462
1463 /* Next read in and internalize all the fields/members. */
1464 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1465 field = dn_bufp->dstruct.firstfield;
1466 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1467 field = dn_bufp->dunion.firstfield;
1468 else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
1469 field = dn_bufp->dclass.memberlist;
1470 else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
1471 field = dn_bufp->dtemplate.memberlist;
1472 else
1473 field.word = DNTTNIL;
1474
1475 while (field.word && field.word != DNTTNIL)
1476 {
1477 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1478
1479 /* At this point "fieldp" may point to either a DNTT_TYPE_FIELD
1480 * or a DNTT_TYPE_GENFIELD record.
1481 */
1482 vtbl_offset = 0;
1483 static_member = 0;
1484 const_member = 0;
1485 volatile_member = 0;
c5aa993b
JM
1486
1487 if (fieldp->dblock.kind == DNTT_TYPE_GENFIELD)
1488 {
1489
1490 /* The type will be GENFIELD if the field is a method or
1491 * a static member (or some other cases -- see below)
1492 */
1493
1494 /* Follow a link to get to the record for the field. */
1495 fn_field = fieldp->dgenfield.field;
1496 fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
1497
1498 /* Virtual funcs are indicated by a VFUNC which points to the
1499 * real entry
1500 */
1501 if (fn_fieldp->dblock.kind == DNTT_TYPE_VFUNC)
1502 {
1503 vtbl_offset = fn_fieldp->dvfunc.vtbl_offset;
1504 fn_field = fn_fieldp->dvfunc.funcptr;
1505 fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
1506 }
1507
1508 /* A function's entry may be preceded by a modifier which
1509 * labels it static/constant/volatile.
1510 */
1511 if (fn_fieldp->dblock.kind == DNTT_TYPE_MODIFIER)
1512 {
1513 static_member = fn_fieldp->dmodifier.m_static;
1514 const_member = fn_fieldp->dmodifier.m_const;
1515 volatile_member = fn_fieldp->dmodifier.m_volatile;
1516 fn_field = fn_fieldp->dmodifier.type;
1517 fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile);
1518 }
1519
1520 /* Check whether we have a method */
1521 if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
1522 (fn_fieldp->dblock.kind == DNTT_TYPE_FUNCTION) ||
1523 (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) ||
1524 (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_FUNCTION))
1525 {
1526 /* Method found */
1527
1528 short ix = 0;
1529
1530 /* Look up function type of method */
1531 memtype = hpread_type_lookup (fn_field, objfile);
1532
1533 /* Methods can be seen before classes in the SOM records.
1534 If we are processing this class because it's a parameter of a
1535 method, at this point the method's type is actually incomplete;
1536 we'll have to fix it up later; mark the class for this. */
1537
1538 if (TYPE_INCOMPLETE (memtype))
1539 {
1540 TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE;
1541 if (fixup_class)
1542 warning ("Two classes to fix up for method?? Type information may be incorrect for some classes.");
1543 if (fixup_method)
1544 warning ("Two methods to be fixed up at once?? Type information may be incorrect for some classes.");
1545 fixup_class = type; /* remember this class has to be fixed up */
1546 fixup_method = memtype; /* remember the method type to be used in fixup */
1547 }
1548
1549 /* HP aCC generates operator names without the "operator" keyword, and
1550 generates null strings as names for operators that are
1551 user-defined type conversions to basic types (e.g. operator int ()).
1552 So try to reconstruct name as best as possible. */
1553
1554 method_name = (char *) (VT (objfile) + fn_fieldp->dfunc.name);
1555 method_alias = (char *) (VT (objfile) + fn_fieldp->dfunc.alias);
1556
1557 if (!method_name || /* no name */
1558 !*method_name || /* or null name */
1559 cplus_mangle_opname (method_name, DMGL_ANSI)) /* or name is an operator like "<" */
1560 {
1561 char *tmp_name = cplus_demangle (method_alias, DMGL_ANSI);
1562 char *op_string = strstr (tmp_name, "operator");
1563 method_name = xmalloc (strlen (op_string) + 1); /* don't overwrite VT! */
1564 strcpy (method_name, op_string);
1565 }
1566
1567 /* First check if a method of the same name has already been seen. */
1568 fn_p = fn_list;
1569 while (fn_p)
1570 {
1571 if (STREQ (fn_p->field.name, method_name))
1572 break;
1573 fn_p = fn_p->next;
1574 }
1575
1576 /* If no such method was found, allocate a new entry in the list */
1577 if (!fn_p)
1578 {
1579 /* Get space to record this member function */
1580 /* Note: alloca used; this will disappear on routine exit */
1581 fn_new = (struct next_fn_field *) alloca (sizeof (struct next_fn_field));
1582 fn_new->next = fn_list;
1583 fn_list = fn_new;
1584
1585 /* Fill in the fields of the struct nextfield */
1586
1587 /* Record the (unmangled) method name */
1588 fn_list->field.name = method_name;
1589 /* Initial space for overloaded methods */
1590 /* Note: xmalloc is used; this will persist after this routine exits */
1591 fn_list->field.fn_fields = (struct fn_field *) xmalloc (5 * (sizeof (struct fn_field)));
1592 fn_list->field.length = 1; /* Init # of overloaded instances */
1593 fn_list->num_fn_fields = 5; /* # of entries for which space allocated */
1594 fn_p = fn_list;
1595 ix = 0; /* array index for fn_field */
1596 /* Bump the total count of the distinctly named methods */
1597 n_fn_fields++;
1598 }
1599 else
1600 /* Another overloaded instance of an already seen method name */
1601 {
1602 if (++(fn_p->field.length) > fn_p->num_fn_fields)
1603 {
1604 /* Increase space allocated for overloaded instances */
1605 fn_p->field.fn_fields
1606 = (struct fn_field *) xrealloc (fn_p->field.fn_fields,
1607 (fn_p->num_fn_fields + 5) * sizeof (struct fn_field));
1608 fn_p->num_fn_fields += 5;
1609 }
1610 ix = fn_p->field.length - 1; /* array index for fn_field */
1611 }
1612
1613 /* "physname" is intended to be the name of this overloaded instance. */
1614 if ((fn_fieldp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
1615 method_alias &&
1616 *method_alias) /* not a null string */
1617 fn_p->field.fn_fields[ix].physname = method_alias;
1618 else
1619 fn_p->field.fn_fields[ix].physname = method_name;
1620 /* What's expected here is the function type */
1621 /* But mark it as NULL if the method was incompletely processed
1622 We'll fix this up later when the method is fully processed */
1623 if (TYPE_INCOMPLETE (memtype))
1624 {
1625 fn_p->field.fn_fields[ix].type = NULL;
1626 fn_p->field.fn_fields[ix].args = NULL;
1627 }
1628 else
1629 {
1630 fn_p->field.fn_fields[ix].type = memtype;
1631
1632 /* The argument list */
1633 fn_p->field.fn_fields[ix].type->type_specific.arg_types =
1634 (struct type **) obstack_alloc (&objfile->type_obstack,
1635 sizeof (struct type *) * (memtype->nfields + 1));
1636 for (i = 0; i < memtype->nfields; i++)
1637 fn_p->field.fn_fields[ix].type->type_specific.arg_types[i] = memtype->fields[i].type;
1638 /* void termination */
1639 fn_p->field.fn_fields[ix].type->type_specific.arg_types[memtype->nfields] = builtin_type_void;
1640
1641 /* pai: It's not clear why this args field has to be set. Perhaps
1642 * it should be eliminated entirely. */
1643 fn_p->field.fn_fields[ix].args =
1644 (struct type **) obstack_alloc (&objfile->type_obstack,
1645 sizeof (struct type *) * (memtype->nfields + 1));
1646 for (i = 0; i < memtype->nfields; i++)
1647 fn_p->field.fn_fields[ix].args[i] = memtype->fields[i].type;
1648 /* null-terminated, unlike arg_types above e */
1649 fn_p->field.fn_fields[ix].args[memtype->nfields] = NULL;
1650 }
1651 /* For virtual functions, fill in the voffset field with the
1652 * virtual table offset. (This is just copied over from the
1653 * SOM record; not sure if it is what GDB expects here...).
1654 * But if the function is a static method, set it to 1.
1655 *
1656 * Note that we have to add 1 because 1 indicates a static
1657 * method, and 0 indicates a non-static, non-virtual method */
1658
1659 if (static_member)
1660 fn_p->field.fn_fields[ix].voffset = VOFFSET_STATIC;
1661 else
1662 fn_p->field.fn_fields[ix].voffset = vtbl_offset ? vtbl_offset + 1 : 0;
1663
1664 /* Also fill in the fcontext field with the current
1665 * class. (The latter isn't quite right: should be the baseclass
1666 * that defines the virtual function... Note we do have
1667 * a variable "baseclass" that we could stuff into the fcontext
1668 * field, but "baseclass" isn't necessarily right either,
1669 * since the virtual function could have been defined more
1670 * than one level up).
1671 */
1672
1673 if (vtbl_offset != 0)
1674 fn_p->field.fn_fields[ix].fcontext = type;
1675 else
1676 fn_p->field.fn_fields[ix].fcontext = NULL;
1677
1678 /* Other random fields pertaining to this method */
1679 fn_p->field.fn_fields[ix].is_const = const_member;
1680 fn_p->field.fn_fields[ix].is_volatile = volatile_member; /* ?? */
1681 switch (fieldp->dgenfield.visibility)
1682 {
1683 case 1:
1684 fn_p->field.fn_fields[ix].is_protected = 1;
1685 fn_p->field.fn_fields[ix].is_private = 0;
1686 break;
1687 case 2:
1688 fn_p->field.fn_fields[ix].is_protected = 0;
1689 fn_p->field.fn_fields[ix].is_private = 1;
1690 break;
1691 default: /* public */
1692 fn_p->field.fn_fields[ix].is_protected = 0;
1693 fn_p->field.fn_fields[ix].is_private = 0;
1694 }
1695 fn_p->field.fn_fields[ix].is_stub = 0;
1696
1697 /* HP aCC emits both MEMFUNC and FUNCTION entries for a method;
1698 if the class points to the FUNCTION, there is usually separate
1699 code for the method; but if we have a MEMFUNC, the method has
1700 been inlined (and there is usually no FUNCTION entry)
1701 FIXME Not sure if this test is accurate. pai/1997-08-22 */
1702 if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) ||
1703 (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC))
1704 fn_p->field.fn_fields[ix].is_inlined = 1;
1705 else
1706 fn_p->field.fn_fields[ix].is_inlined = 0;
1707
1708 fn_p->field.fn_fields[ix].dummy = 0;
1709
1710 /* Bump the total count of the member functions */
1711 n_fn_fields_total++;
1712
1713 }
1714 else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
1715 {
1716 /* This case is for static data members of classes */
1717
1718 /* pai:: FIXME -- check that "staticmem" bit is set */
1719
1720 /* Get space to record this static member */
1721 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1722 new->next = list;
1723 list = new;
1724
1725 list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
1726 FIELD_BITSIZE (list->field) = -1; /* indicates static member */
1727 SET_FIELD_PHYSNAME (list->field, 0); /* initialize to empty */
1728 memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
1729
1730 FIELD_TYPE (list->field) = memtype;
1731 list->attributes = 0;
1732 switch (fieldp->dgenfield.visibility)
1733 {
1734 case 1:
1735 B_SET (&(list->attributes), ATTR_PROTECT);
1736 break;
1737 case 2:
1738 B_SET (&(list->attributes), ATTR_PRIVATE);
1739 break;
1740 }
1741 nfields++;
1742 }
1743
1744 else if (fn_fieldp->dblock.kind == DNTT_TYPE_FIELD)
1745 {
1746 /* FIELDs follow GENFIELDs for fields of anonymous unions.
1747 Code below is replicated from the case for FIELDs further
1748 below, except that fieldp is replaced by fn_fieldp */
1749 if (!fn_fieldp->dfield.a_union)
1750 warning ("Debug info inconsistent: FIELD of anonymous union doesn't have a_union bit set");
1751 /* Get space to record the next field/data-member. */
1752 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1753 new->next = list;
1754 list = new;
1755
1756 list->field.name = VT (objfile) + fn_fieldp->dfield.name;
1757 FIELD_BITPOS (list->field) = fn_fieldp->dfield.bitoffset;
1758 if (fn_fieldp->dfield.bitlength % 8)
1759 list->field.bitsize = fn_fieldp->dfield.bitlength;
1760 else
1761 list->field.bitsize = 0;
1762
1763 memtype = hpread_type_lookup (fn_fieldp->dfield.type, objfile);
1764 list->field.type = memtype;
1765 list->attributes = 0;
1766 switch (fn_fieldp->dfield.visibility)
1767 {
1768 case 1:
1769 B_SET (&(list->attributes), ATTR_PROTECT);
1770 break;
1771 case 2:
1772 B_SET (&(list->attributes), ATTR_PRIVATE);
1773 break;
1774 }
1775 nfields++;
1776 }
1777 else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR)
1778 {
1779 /* Field of anonymous union; union is not inside a class */
1780 if (!fn_fieldp->dsvar.a_union)
1781 warning ("Debug info inconsistent: SVAR field in anonymous union doesn't have a_union bit set");
1782 /* Get space to record the next field/data-member. */
1783 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1784 new->next = list;
1785 list = new;
1786
1787 list->field.name = VT (objfile) + fn_fieldp->dsvar.name;
1788 FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */
1789 FIELD_BITSIZE (list->field) = 0; /* use length from type */
1790 memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile);
1791 list->field.type = memtype;
1792 list->attributes = 0;
1793 /* No info to set visibility -- always public */
1794 nfields++;
1795 }
1796 else if (fn_fieldp->dblock.kind == DNTT_TYPE_DVAR)
1797 {
1798 /* Field of anonymous union; union is not inside a class */
1799 if (!fn_fieldp->ddvar.a_union)
1800 warning ("Debug info inconsistent: DVAR field in anonymous union doesn't have a_union bit set");
1801 /* Get space to record the next field/data-member. */
1802 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1803 new->next = list;
1804 list = new;
1805
1806 list->field.name = VT (objfile) + fn_fieldp->ddvar.name;
1807 FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */
1808 FIELD_BITSIZE (list->field) = 0; /* use length from type */
1809 memtype = hpread_type_lookup (fn_fieldp->ddvar.type, objfile);
1810 list->field.type = memtype;
1811 list->attributes = 0;
1812 /* No info to set visibility -- always public */
1813 nfields++;
1814 }
c906108c 1815 else
c5aa993b
JM
1816 { /* Not a method, nor a static data member, nor an anon union field */
1817
1818 /* This case is for miscellaneous type entries (local enums,
1819 local function templates, etc.) that can be present
1820 inside a class. */
1821
1822 /* Enums -- will be handled by other code that takes care
1823 of DNTT_TYPE_ENUM; here we see only DNTT_TYPE_MEMENUM so
1824 it's not clear we could have handled them here at all. */
1825 /* FUNC_TEMPLATE: is handled by other code (??). */
1826 /* MEMACCESS: modified access for inherited member. Not
1827 sure what to do with this, ignoriing it at present. */
1828
1829 /* What other entries can appear following a GENFIELD which
1830 we do not handle above? (MODIFIER, VFUNC handled above.) */
1831
1832 if ((fn_fieldp->dblock.kind != DNTT_TYPE_MEMACCESS) &&
1833 (fn_fieldp->dblock.kind != DNTT_TYPE_MEMENUM) &&
1834 (fn_fieldp->dblock.kind != DNTT_TYPE_FUNC_TEMPLATE))
1835 warning ("Internal error: Unexpected debug record kind %d found following DNTT_GENFIELD",
1836 fn_fieldp->dblock.kind);
1837 }
1838 /* walk to the next FIELD or GENFIELD */
1839 field = fieldp->dgenfield.nextfield;
1840
1841 }
1842 else if (fieldp->dblock.kind == DNTT_TYPE_FIELD)
1843 {
1844
1845 /* Ordinary structure/union/class field */
1846 struct type *anon_union_type;
1847
1848 /* Get space to record the next field/data-member. */
1849 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1850 new->next = list;
1851 list = new;
1852
1853 list->field.name = VT (objfile) + fieldp->dfield.name;
1854
1855
1856 /* A FIELD by itself (without a GENFIELD) can also be a static member */
1857 if (fieldp->dfield.staticmem)
1858 {
1859 FIELD_BITPOS (list->field) = -1;
c906108c 1860 FIELD_BITSIZE (list->field) = 0;
c5aa993b
JM
1861 }
1862 else
1863 /* Non-static data member */
1864 {
1865 FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1866 if (fieldp->dfield.bitlength % 8)
1867 FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1868 else
1869 FIELD_BITSIZE (list->field) = 0;
1870 }
1871
1872 memtype = hpread_type_lookup (fieldp->dfield.type, objfile);
1873 FIELD_TYPE (list->field) = memtype;
1874 list->attributes = 0;
1875 switch (fieldp->dfield.visibility)
1876 {
1877 case 1:
1878 B_SET (&(list->attributes), ATTR_PROTECT);
1879 break;
1880 case 2:
1881 B_SET (&(list->attributes), ATTR_PRIVATE);
1882 break;
1883 }
1884 nfields++;
1885
1886
1887 /* Note 1: First, we have to check if the current field is an anonymous
1888 union. If it is, then *its* fields are threaded along in the
1889 nextfield chain. :-( This was supposed to help debuggers, but is
1890 really just a nuisance since we deal with anonymous unions anyway by
1891 checking that the name is null. So anyway, we skip over the fields
1892 of the anonymous union. pai/1997-08-22 */
1893 /* Note 2: In addition, the bitoffsets for the fields of the anon union
1894 are relative to the enclosing struct, *NOT* relative to the anon
1895 union! This is an even bigger nuisance -- we have to go in and munge
1896 the anon union's type information appropriately. pai/1997-08-22 */
1897
1898 /* Both tasks noted above are done by a separate function. This takes us
1899 to the next FIELD or GENFIELD, skipping anon unions, and recursively
1900 processing intermediate types. */
1901 field = hpread_get_next_skip_over_anon_unions (1, field, &fieldp, objfile);
1902
1903 }
1904 else
1905 {
1906 /* neither field nor genfield ?? is this possible?? */
1907 /* pai:: FIXME walk to the next -- how? */
1908 warning ("Internal error: unexpected DNTT kind %d encountered as field of struct");
1909 warning ("Skipping remaining fields of struct");
1910 break; /* get out of loop of fields */
1911 }
c906108c
SS
1912 }
1913
1914 /* If it's a template, read in the instantiation list */
c5aa993b
JM
1915 if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
1916 {
1917 ninstantiations = 0;
1918 field = dn_bufp->dtemplate.expansions;
1919 while (field.word && field.word != DNTTNIL)
1920 {
1921 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1922
1923 /* The expansions or nextexp should point to a tagdef */
1924 if (fieldp->dblock.kind != DNTT_TYPE_TAGDEF)
1925 break;
1926
1927 i_new = (struct next_instantiation *) alloca (sizeof (struct next_instantiation));
1928 i_new->next = i_list;
1929 i_list = i_new;
1930 i_list->t = hpread_type_lookup (field, objfile);
1931 ninstantiations++;
1932
1933 /* And the "type" field of that should point to a class */
1934 field = fieldp->dtag.type;
1935 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1936 if (fieldp->dblock.kind != DNTT_TYPE_CLASS)
1937 break;
1938
1939 /* Get the next expansion */
1940 field = fieldp->dclass.nextexp;
1941 }
c906108c 1942 }
c5aa993b
JM
1943 TYPE_NINSTANTIATIONS (type) = ninstantiations;
1944 if (ninstantiations > 0)
1945 TYPE_INSTANTIATIONS (type) = (struct type **)
c906108c
SS
1946 obstack_alloc (&objfile->type_obstack, sizeof (struct type *) * ninstantiations);
1947 for (n = ninstantiations; i_list; i_list = i_list->next)
1948 {
1949 n -= 1;
c5aa993b 1950 TYPE_INSTANTIATION (type, n) = i_list->t;
c906108c
SS
1951 }
1952
1953
1954 /* Copy the field-list to GDB's symbol table */
1955 TYPE_NFIELDS (type) = nfields;
1956 TYPE_N_BASECLASSES (type) = n_base_classes;
1957 TYPE_FIELDS (type) = (struct field *)
1958 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1959 /* Copy the saved-up fields into the field vector. */
1960 for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
1961 {
1962 n -= 1;
1963 TYPE_FIELD (type, n) = tmp_list->field;
1964 }
1965
1966 /* Copy the "function-field-list" (i.e., the list of member
1967 * functions in the class) to GDB's symbol table
1968 */
1969 TYPE_NFN_FIELDS (type) = n_fn_fields;
1970 TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total;
c5aa993b 1971 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
c906108c
SS
1972 obstack_alloc (&objfile->type_obstack, sizeof (struct fn_fieldlist) * n_fn_fields);
1973 for (n = n_fn_fields; fn_list; fn_list = fn_list->next)
1974 {
1975 n -= 1;
c5aa993b 1976 TYPE_FN_FIELDLIST (type, n) = fn_list->field;
c906108c
SS
1977 }
1978
1979 /* pai:: FIXME -- perhaps each bitvector should be created individually */
1980 for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next)
1981 {
1982 n -= 1;
1983 if (tmp_list->attributes)
c5aa993b
JM
1984 {
1985 need_bitvectors = 1;
1986 break;
1987 }
c906108c
SS
1988 }
1989
1990 if (need_bitvectors)
1991 {
c5aa993b 1992 /* pai:: this step probably redundant */
c906108c
SS
1993 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1994
1995 TYPE_FIELD_VIRTUAL_BITS (type) =
1996 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1997 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), nfields);
1998
1999 TYPE_FIELD_PRIVATE_BITS (type) =
2000 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2001 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
c5aa993b 2002
c906108c
SS
2003 TYPE_FIELD_PROTECTED_BITS (type) =
2004 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2005 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2006
2007 /* this field vector isn't actually used with HP aCC */
2008 TYPE_FIELD_IGNORE_BITS (type) =
2009 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2010 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2011
2012 while (nfields-- > 0)
c5aa993b
JM
2013 {
2014 if (B_TST (&(list->attributes), ATTR_VIRTUAL))
2015 SET_TYPE_FIELD_VIRTUAL (type, nfields);
2016 if (B_TST (&(list->attributes), ATTR_PRIVATE))
2017 SET_TYPE_FIELD_PRIVATE (type, nfields);
2018 if (B_TST (&(list->attributes), ATTR_PROTECT))
2019 SET_TYPE_FIELD_PROTECTED (type, nfields);
2020
2021 list = list->next;
2022 }
c906108c
SS
2023 }
2024 else
2025 {
c5aa993b
JM
2026 TYPE_FIELD_VIRTUAL_BITS (type) = NULL;
2027 TYPE_FIELD_PROTECTED_BITS (type) = NULL;
2028 TYPE_FIELD_PRIVATE_BITS (type) = NULL;
c906108c 2029 }
c5aa993b
JM
2030
2031 if (has_vtable (type))
c906108c
SS
2032 {
2033 /* Allocate space for class runtime information */
c5aa993b 2034 TYPE_RUNTIME_PTR (type) = (struct runtime_info *) xmalloc (sizeof (struct runtime_info));
c906108c 2035 /* Set flag for vtable */
c5aa993b 2036 TYPE_VTABLE (type) = 1;
c906108c 2037 /* The first non-virtual base class with a vtable. */
c5aa993b 2038 TYPE_PRIMARY_BASE (type) = primary_base_class (type);
c906108c 2039 /* The virtual base list. */
c5aa993b 2040 TYPE_VIRTUAL_BASE_LIST (type) = virtual_base_list (type);
c906108c
SS
2041 }
2042 else
c5aa993b 2043 TYPE_RUNTIME_PTR (type) = NULL;
c906108c
SS
2044
2045 /* If this is a local type (C++ - declared inside a function), record file name & line # */
c5aa993b 2046 if (hpread_get_scope_depth (dn_bufp, objfile, 1 /* no need for real depth */ ))
c906108c
SS
2047 {
2048 TYPE_LOCALTYPE_PTR (type) = (struct local_type_info *) xmalloc (sizeof (struct local_type_info));
2049 TYPE_LOCALTYPE_FILE (type) = (char *) xmalloc (strlen (current_subfile->name) + 1);
2050 strcpy (TYPE_LOCALTYPE_FILE (type), current_subfile->name);
2051 if (current_subfile->line_vector && (current_subfile->line_vector->nitems > 0))
c5aa993b 2052 TYPE_LOCALTYPE_LINE (type) = current_subfile->line_vector->item[current_subfile->line_vector->nitems - 1].line;
c906108c 2053 else
c5aa993b 2054 TYPE_LOCALTYPE_LINE (type) = 0;
c906108c
SS
2055 }
2056 else
2057 TYPE_LOCALTYPE_PTR (type) = NULL;
2058
2059 /* Clear the global saying what template we are in the middle of processing */
2060 current_template = NULL;
2061
2062 return type;
2063}
2064
2065/* Adjust the physnames for each static member of a struct
2066 or class type to be something like "A::x"; then various
2067 other pieces of code that do a lookup_symbol on the phyname
2068 work correctly.
2069 TYPE is a pointer to the struct/class type
2070 NAME is a char * (string) which is the class/struct name
c5aa993b 2071 Void return */
c906108c
SS
2072
2073static void
2074fix_static_member_physnames (type, class_name, objfile)
c5aa993b
JM
2075 struct type *type;
2076 char *class_name;
2077 struct objfile *objfile;
c906108c
SS
2078{
2079 int i;
2080
c5aa993b 2081 /* We fix the member names only for classes or structs */
c906108c
SS
2082 if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
2083 return;
2084
c5aa993b 2085 for (i = 0; i < TYPE_NFIELDS (type); i++)
c906108c
SS
2086 if (TYPE_FIELD_STATIC (type, i))
2087 {
c5aa993b
JM
2088 if (TYPE_FIELD_STATIC_PHYSNAME (type, i))
2089 return; /* physnames are already set */
2090
2091 SET_FIELD_PHYSNAME (type->fields[i],
2092 obstack_alloc (&objfile->type_obstack,
2093 strlen (class_name) + strlen (TYPE_FIELD_NAME (type, i)) + 3));
2094 strcpy (TYPE_FIELD_STATIC_PHYSNAME (type, i), class_name);
2095 strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), "::");
2096 strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), TYPE_FIELD_NAME (type, i));
c906108c
SS
2097 }
2098}
2099
2100/* Fix-up the type structure for a CLASS so that the type entry
2101 * for a method (previously marked with a null type in hpread_read_struct_type()
2102 * is set correctly to METHOD.
2103 * OBJFILE is as for other such functions.
c5aa993b
JM
2104 * Void return. */
2105
c906108c
SS
2106static void
2107fixup_class_method_type (class, method, objfile)
c5aa993b
JM
2108 struct type *class;
2109 struct type *method;
2110 struct objfile *objfile;
c906108c
SS
2111{
2112 int i, j, k;
2113
2114 if (!class || !method || !objfile)
2115 return;
2116
2117 /* Only for types that have methods */
2118 if ((TYPE_CODE (class) != TYPE_CODE_CLASS) &&
2119 (TYPE_CODE (class) != TYPE_CODE_UNION))
2120 return;
2121
c5aa993b 2122 /* Loop over all methods and find the one marked with a NULL type */
c906108c
SS
2123 for (i = 0; i < TYPE_NFN_FIELDS (class); i++)
2124 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (class, i); j++)
2125 if (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) == NULL)
c5aa993b
JM
2126 {
2127 /* Set the method type */
2128 TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) = method;
2129 /* The argument list */
2130 (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j))->type_specific.arg_types
2131 = (struct type **) obstack_alloc (&objfile->type_obstack,
2132 sizeof (struct type *) * (method->nfields + 1));
2133 for (k = 0; k < method->nfields; k++)
2134 (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j))->type_specific.arg_types[k] = method->fields[k].type;
2135 /* void termination */
2136 (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j))->type_specific.arg_types[method->nfields] = builtin_type_void;
2137
2138 /* pai: It's not clear why this args field has to be set. Perhaps
2139 * it should be eliminated entirely. */
2140 (TYPE_FN_FIELD (TYPE_FN_FIELDLIST1 (class, i), j)).args
2141 = (struct type **) obstack_alloc (&objfile->type_obstack,
2142 sizeof (struct type *) * (method->nfields + 1));
2143 for (k = 0; k < method->nfields; k++)
2144 (TYPE_FN_FIELD (TYPE_FN_FIELDLIST1 (class, i), j)).args[k] = method->fields[k].type;
2145 /* null-terminated, unlike arg_types above */
2146 (TYPE_FN_FIELD (TYPE_FN_FIELDLIST1 (class, i), j)).args[method->nfields] = NULL;
2147
2148 /* Break out of both loops -- only one method to fix up in a class */
2149 goto finish;
2150 }
c906108c
SS
2151
2152finish:
c5aa993b 2153 TYPE_FLAGS (class) &= ~TYPE_FLAG_INCOMPLETE;
c906108c
SS
2154}
2155
2156
2157/* If we're in the middle of processing a template, get a pointer
2158 * to the Nth template argument.
2159 * An example may make this clearer:
2160 * template <class T1, class T2> class q2 {
2161 * public:
2162 * T1 a;
2163 * T2 b;
2164 * };
2165 * The type for "a" will be "first template arg" and
2166 * the type for "b" will be "second template arg".
2167 * We need to look these up in order to fill in "a" and "b"'s type.
2168 * This is called from hpread_type_lookup().
2169 */
c5aa993b
JM
2170static struct type *
2171hpread_get_nth_template_arg (objfile, n)
c906108c
SS
2172 struct objfile *objfile;
2173 int n;
2174{
c5aa993b
JM
2175 if (current_template != NULL)
2176 return TYPE_TEMPLATE_ARG (current_template, n).type;
2177 else
2178 return lookup_fundamental_type (objfile, FT_TEMPLATE_ARG);
c906108c
SS
2179}
2180
2181/* Read in and internalize a TEMPL_ARG (template arg) symbol. */
2182
2183static struct type *
2184hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name)
2185 dnttpointer hp_type;
2186 union dnttentry *dn_bufp;
2187 struct objfile *objfile;
c5aa993b 2188 char *name;
c906108c
SS
2189{
2190 struct type *type;
2191
2192 /* See if it's something we've already deal with. */
2193 type = hpread_alloc_type (hp_type, objfile);
2194 if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE_ARG)
2195 return type;
2196
2197 /* Nope. Fill in the appropriate fields. */
2198 TYPE_CODE (type) = TYPE_CODE_TEMPLATE_ARG;
2199 TYPE_LENGTH (type) = 0;
2200 TYPE_NFIELDS (type) = 0;
2201 TYPE_NAME (type) = name;
2202 return type;
2203}
2204
2205/* Read in and internalize a set debug symbol. */
2206
2207static struct type *
2208hpread_read_set_type (hp_type, dn_bufp, objfile)
2209 dnttpointer hp_type;
2210 union dnttentry *dn_bufp;
2211 struct objfile *objfile;
2212{
2213 struct type *type;
2214
2215 /* See if it's something we've already deal with. */
2216 type = hpread_alloc_type (hp_type, objfile);
2217 if (TYPE_CODE (type) == TYPE_CODE_SET)
2218 return type;
2219
2220 /* Nope. Fill in the appropriate fields. */
2221 TYPE_CODE (type) = TYPE_CODE_SET;
2222 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
2223 TYPE_NFIELDS (type) = 0;
2224 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
2225 objfile);
2226 return type;
2227}
2228
2229/* Read in and internalize an array debug symbol. */
2230
2231static struct type *
2232hpread_read_array_type (hp_type, dn_bufp, objfile)
2233 dnttpointer hp_type;
2234 union dnttentry *dn_bufp;
2235 struct objfile *objfile;
2236{
2237 struct type *type;
c5aa993b 2238
c906108c
SS
2239 /* Allocate an array type symbol.
2240 * Why no check for already-read here, like in the other
2241 * hpread_read_xxx_type routines? Because it kept us
2242 * from properly determining the size of the array!
2243 */
2244 type = hpread_alloc_type (hp_type, objfile);
2245
2246 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2247
2248 /* Although the hp-symtab.h does not *require* this to be the case,
2249 * GDB is assuming that "arrayisbytes" and "elemisbytes" be consistent.
2250 * I.e., express both array-length and element-length in bits,
2251 * or express both array-length and element-length in bytes.
2252 */
2253 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes) ||
c5aa993b
JM
2254 (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
2255 {
2256 warning ("error in hpread_array_type.\n");
2257 return;
2258 }
2259 else if (dn_bufp->darray.arraylength == 0x7fffffff)
2260 {
2261 /* The HP debug format represents char foo[]; as an array with
2262 * length 0x7fffffff. Internally GDB wants to represent this
2263 * as an array of length zero.
2264 */
2265 TYPE_LENGTH (type) = 0;
2266 }
2267 else if (dn_bufp->darray.arrayisbytes)
c906108c 2268 TYPE_LENGTH (type) = dn_bufp->darray.arraylength;
c5aa993b 2269 else /* arraylength is in bits */
c906108c
SS
2270 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
2271
2272 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
2273 objfile);
2274
2275 /* The one "field" is used to store the subscript type */
2276 /* Since C and C++ multi-dimensional arrays are simply represented
2277 * as: array of array of ..., we only need one subscript-type
2278 * per array. This subscript type is typically a subrange of integer.
2279 * If this gets extended to support languages like Pascal, then
2280 * we need to fix this to represent multi-dimensional arrays properly.
2281 */
2282 TYPE_NFIELDS (type) = 1;
2283 TYPE_FIELDS (type) = (struct field *)
2284 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
2285 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
2286 objfile);
2287 return type;
2288}
2289
2290/* Read in and internalize a subrange debug symbol. */
2291static struct type *
2292hpread_read_subrange_type (hp_type, dn_bufp, objfile)
2293 dnttpointer hp_type;
2294 union dnttentry *dn_bufp;
2295 struct objfile *objfile;
2296{
2297 struct type *type;
2298
2299 /* Is it something we've already dealt with. */
2300 type = hpread_alloc_type (hp_type, objfile);
2301 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
2302 return type;
2303
2304 /* Nope, internalize it. */
2305 TYPE_CODE (type) = TYPE_CODE_RANGE;
2306 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
2307 TYPE_NFIELDS (type) = 2;
2308 TYPE_FIELDS (type)
2309 = (struct field *) obstack_alloc (&objfile->type_obstack,
2310 2 * sizeof (struct field));
2311
2312 if (dn_bufp->dsubr.dyn_low)
2313 TYPE_FIELD_BITPOS (type, 0) = 0;
2314 else
2315 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
2316
2317 if (dn_bufp->dsubr.dyn_high)
2318 TYPE_FIELD_BITPOS (type, 1) = -1;
2319 else
2320 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
2321 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
2322 objfile);
2323 return type;
2324}
2325
2326/* struct type * hpread_type_lookup(hp_type, objfile)
2327 * Arguments:
2328 * hp_type: A pointer into the DNTT specifying what type we
2329 * are about to "look up"., or else [for fundamental types
2330 * like int, float, ...] an "immediate" structure describing
2331 * the type.
2332 * objfile: ?
2333 * Return value: A pointer to a "struct type" (representation of a
2334 * type in GDB's internal symbol table - see gdbtypes.h)
2335 * Routine description:
2336 * There are a variety of places when scanning the DNTT when we
2337 * need to interpret a "type" field. The simplest and most basic
2338 * example is when we're processing the symbol table record
2339 * for a data symbol (a SVAR or DVAR record). That has
2340 * a "type" field specifying the type of the data symbol. That
2341 * "type" field is either an "immediate" type specification (for the
2342 * fundamental types) or a DNTT pointer (for more complicated types).
2343 * For the more complicated types, we may or may not have already
2344 * processed the pointed-to type. (Multiple data symbols can of course
2345 * share the same type).
2346 * The job of hpread_type_lookup() is to process this "type" field.
2347 * Most of the real work is done in subroutines. Here we interpret
2348 * the immediate flag. If not immediate, chase the DNTT pointer to
2349 * find our way to the SOM record describing the type, switch on
2350 * the SOM kind, and then call an appropriate subroutine depending
2351 * on what kind of type we are constructing. (e.g., an array type,
2352 * a struct/class type, etc).
2353 */
2354static struct type *
2355hpread_type_lookup (hp_type, objfile)
2356 dnttpointer hp_type;
2357 struct objfile *objfile;
2358{
2359 union dnttentry *dn_bufp;
c5aa993b 2360 struct type *tmp_type;
c906108c
SS
2361
2362 /* First see if it's a simple builtin type. */
2363 if (hp_type.dntti.immediate)
2364 /* If this is a template argument, the argument number is
2365 * encoded in the bitlength. All other cases, just return
2366 * GDB's representation of this fundamental type.
2367 */
2368 if (hp_type.dntti.type == HP_TYPE_TEMPLATE_ARG)
c5aa993b 2369 return hpread_get_nth_template_arg (objfile, hp_type.dntti.bitlength);
c906108c
SS
2370 else
2371 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
2372
2373 /* Not a builtin type. We'll have to read it in. */
2374 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
2375 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
2376 else
2377 /* This is a fancy way of returning NULL */
2378 return lookup_fundamental_type (objfile, FT_VOID);
2379
2380 switch (dn_bufp->dblock.kind)
2381 {
2382 case DNTT_TYPE_SRCFILE:
2383 case DNTT_TYPE_MODULE:
2384 case DNTT_TYPE_ENTRY:
2385 case DNTT_TYPE_BEGIN:
2386 case DNTT_TYPE_END:
2387 case DNTT_TYPE_IMPORT:
2388 case DNTT_TYPE_LABEL:
2389 case DNTT_TYPE_FPARAM:
2390 case DNTT_TYPE_SVAR:
2391 case DNTT_TYPE_DVAR:
2392 case DNTT_TYPE_CONST:
2393 case DNTT_TYPE_MEMENUM:
2394 case DNTT_TYPE_VARIANT:
2395 case DNTT_TYPE_FILE:
2396 case DNTT_TYPE_WITH:
2397 case DNTT_TYPE_COMMON:
2398 case DNTT_TYPE_COBSTRUCT:
2399 case DNTT_TYPE_XREF:
2400 case DNTT_TYPE_SA:
2401 case DNTT_TYPE_MACRO:
2402 case DNTT_TYPE_BLOCKDATA:
2403 case DNTT_TYPE_CLASS_SCOPE:
2404 case DNTT_TYPE_MEMACCESS:
2405 case DNTT_TYPE_INHERITANCE:
2406 case DNTT_TYPE_OBJECT_ID:
2407 case DNTT_TYPE_FRIEND_CLASS:
2408 case DNTT_TYPE_FRIEND_FUNC:
2409 /* These are not types - something went wrong. */
2410 /* This is a fancy way of returning NULL */
2411 return lookup_fundamental_type (objfile, FT_VOID);
2412
2413 case DNTT_TYPE_FUNCTION:
2414 /* We wind up here when dealing with class member functions
2415 * (called from hpread_read_struct_type(), i.e. when processing
2416 * the class definition itself).
2417 */
2418 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
2419
2420 case DNTT_TYPE_DOC_FUNCTION:
2421 return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
2422
2423 case DNTT_TYPE_TYPEDEF:
2424 {
c5aa993b 2425 /* A typedef - chase it down by making a recursive call */
c906108c
SS
2426 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
2427 objfile);
2428
c5aa993b
JM
2429 /* The following came from the base hpread.c that we inherited.
2430 * It is WRONG so I have commented it out. - RT
2431 *...
2432
2433 char *suffix;
2434 suffix = VT (objfile) + dn_bufp->dtype.name;
2435 TYPE_NAME (structtype) = suffix;
2436
2437 * ... further explanation ....
2438 *
2439 * What we have here is a typedef pointing to a typedef.
2440 * E.g.,
2441 * typedef int foo;
2442 * typedef foo fum;
2443 *
2444 * What we desire to build is (these are pictures
2445 * of "struct type"'s):
2446 *
2447 * +---------+ +----------+ +------------+
2448 * | typedef | | typedef | | fund. type |
2449 * | type| -> | type| -> | |
2450 * | "fum" | | "foo" | | "int" |
2451 * +---------+ +----------+ +------------+
2452 *
2453 * What this commented-out code is doing is smashing the
2454 * name of pointed-to-type to be the same as the pointed-from
2455 * type. So we wind up with something like:
2456 *
2457 * +---------+ +----------+ +------------+
2458 * | typedef | | typedef | | fund. type |
2459 * | type| -> | type| -> | |
2460 * | "fum" | | "fum" | | "fum" |
2461 * +---------+ +----------+ +------------+
2462 *
2463 */
c906108c
SS
2464
2465 return structtype;
2466 }
2467
2468 case DNTT_TYPE_TAGDEF:
c5aa993b 2469 {
c906108c
SS
2470 /* Just a little different from above. We have to tack on
2471 * an identifier of some kind (struct, union, enum, class, etc).
c5aa993b 2472 */
c906108c
SS
2473 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
2474 objfile);
2475 char *prefix, *suffix;
2476 suffix = VT (objfile) + dn_bufp->dtype.name;
2477
2478 /* Lookup the next type in the list. It should be a structure,
2479 * union, class, enum, or template type.
c5aa993b
JM
2480 * We will need to attach that to our name.
2481 */
c906108c
SS
2482 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2483 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
c5aa993b
JM
2484 else
2485 {
2486 complain (&hpread_type_lookup_complaint);
2487 return;
2488 }
2489
2490 if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
2491 {
c906108c 2492 prefix = "struct ";
c5aa993b
JM
2493 }
2494 else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
2495 {
2496 prefix = "union ";
2497 }
2498 else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS)
2499 {
2500 /* Further field for CLASS saying how it was really declared */
2501 /* 0==class, 1==union, 2==struct */
2502 if (dn_bufp->dclass.class_decl == 0)
2503 prefix = "class ";
2504 else if (dn_bufp->dclass.class_decl == 1)
2505 prefix = "union ";
2506 else if (dn_bufp->dclass.class_decl == 2)
2507 prefix = "struct ";
2508 else
2509 prefix = "";
2510 }
2511 else if (dn_bufp->dblock.kind == DNTT_TYPE_ENUM)
2512 {
2513 prefix = "enum ";
2514 }
2515 else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2516 {
2517 prefix = "template ";
2518 }
2519 else
2520 {
2521 prefix = "";
2522 }
c906108c
SS
2523
2524 /* Build the correct name. */
2525 structtype->name
2526 = (char *) obstack_alloc (&objfile->type_obstack,
2527 strlen (prefix) + strlen (suffix) + 1);
2528 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
2529 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
2530 TYPE_TAG_NAME (structtype) = suffix;
2531
c5aa993b
JM
2532 /* For classes/structs, we have to set the static member "physnames"
2533 to point to strings like "Class::Member" */
2534 if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT)
2535 fix_static_member_physnames (structtype, suffix, objfile);
c906108c
SS
2536
2537 return structtype;
2538 }
2539
2540 case DNTT_TYPE_POINTER:
2541 /* Pointer type - call a routine in gdbtypes.c that constructs
2542 * the appropriate GDB type.
2543 */
2544 return make_pointer_type (
c5aa993b
JM
2545 hpread_type_lookup (dn_bufp->dptr.pointsto,
2546 objfile),
2547 NULL);
c906108c
SS
2548
2549 case DNTT_TYPE_REFERENCE:
2550 /* C++ reference type - call a routine in gdbtypes.c that constructs
2551 * the appropriate GDB type.
2552 */
2553 return make_reference_type (
c5aa993b
JM
2554 hpread_type_lookup (dn_bufp->dreference.pointsto,
2555 objfile),
2556 NULL);
2557
c906108c
SS
2558 case DNTT_TYPE_ENUM:
2559 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
2560 case DNTT_TYPE_SET:
2561 return hpread_read_set_type (hp_type, dn_bufp, objfile);
2562 case DNTT_TYPE_SUBRANGE:
2563 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
2564 case DNTT_TYPE_ARRAY:
2565 return hpread_read_array_type (hp_type, dn_bufp, objfile);
2566 case DNTT_TYPE_STRUCT:
2567 case DNTT_TYPE_UNION:
2568 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
2569 case DNTT_TYPE_FIELD:
2570 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
2571
2572 case DNTT_TYPE_FUNCTYPE:
2573 /* Here we want to read the function SOMs and return a
2574 * type for it. We get here, for instance, when processing
2575 * pointer-to-function type.
2576 */
2577 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
2578
2579 case DNTT_TYPE_PTRMEM:
2580 /* Declares a C++ pointer-to-data-member type.
2581 * The "pointsto" field defines the class,
2582 * while the "memtype" field defines the pointed-to-type.
2583 */
2584 {
c5aa993b
JM
2585 struct type *ptrmemtype;
2586 struct type *class_type;
2587 struct type *memtype;
2588 memtype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
2589 objfile),
2590 class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
2591 objfile),
2592 ptrmemtype = alloc_type (objfile);
2593 smash_to_member_type (ptrmemtype, class_type, memtype);
2594 return make_pointer_type (ptrmemtype, NULL);
c906108c
SS
2595 }
2596 break;
2597
2598 case DNTT_TYPE_PTRMEMFUNC:
2599 /* Defines a C++ pointer-to-function-member type.
2600 * The "pointsto" field defines the class,
2601 * while the "memtype" field defines the pointed-to-type.
2602 */
2603 {
c5aa993b
JM
2604 struct type *ptrmemtype;
2605 struct type *class_type;
2606 struct type *functype;
2607 struct type *retvaltype;
2608 int nargs;
2609 int i;
2610 struct type **args_type;
2611 class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto,
2612 objfile);
2613 functype = hpread_type_lookup (dn_bufp->dptrmem.memtype,
2614 objfile);
2615 retvaltype = TYPE_TARGET_TYPE (functype);
2616 nargs = TYPE_NFIELDS (functype);
2617 args_type = (struct type **) xmalloc ((nargs + 1) * sizeof (struct type *));
2618 for (i = 0; i < nargs; i++)
2619 {
2620 args_type[i] = TYPE_FIELD_TYPE (functype, i);
2621 }
2622 args_type[nargs] = NULL;
2623 ptrmemtype = alloc_type (objfile);
2624 smash_to_method_type (ptrmemtype, class_type, retvaltype, args_type);
2625 return make_pointer_type (ptrmemtype, NULL);
c906108c
SS
2626 }
2627 break;
2628
c5aa993b 2629 case DNTT_TYPE_CLASS:
c906108c
SS
2630 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
2631
2632 case DNTT_TYPE_GENFIELD:
2633 /* Chase pointer from GENFIELD to FIELD, and make recursive
2634 * call on that.
2635 */
2636 return hpread_type_lookup (dn_bufp->dgenfield.field, objfile);
2637
2638 case DNTT_TYPE_VFUNC:
2639 /* C++ virtual function.
2640 * We get here in the course of processing a class type which
2641 * contains virtual functions. Just go through another level
2642 * of indirection to get to the pointed-to function SOM.
2643 */
2644 return hpread_type_lookup (dn_bufp->dvfunc.funcptr, objfile);
2645
2646 case DNTT_TYPE_MODIFIER:
2647 /* Check the modifiers and then just make a recursive call on
2648 * the "type" pointed to by the modifier DNTT.
2649 *
2650 * pai:: FIXME -- do we ever want to handle "m_duplicate" and
2651 * "m_void" modifiers? Is static_flag really needed here?
2652 * (m_static used for methods of classes, elsewhere).
2653 */
c5aa993b
JM
2654 tmp_type = make_cv_type (dn_bufp->dmodifier.m_const,
2655 dn_bufp->dmodifier.m_volatile,
2656 hpread_type_lookup (dn_bufp->dmodifier.type, objfile),
2657 0);
c906108c 2658 return tmp_type;
c5aa993b 2659
c906108c
SS
2660
2661 case DNTT_TYPE_MEMFUNC:
2662 /* Member function. Treat like a function.
2663 * I think we get here in the course of processing a
2664 * pointer-to-member-function type...
2665 */
2666 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
2667
2668 case DNTT_TYPE_DOC_MEMFUNC:
2669 return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0);
2670
2671 case DNTT_TYPE_TEMPLATE:
2672 /* Template - sort of the header for a template definition,
2673 * which like a class, points to a member list and also points
2674 * to a TEMPLATE_ARG list of type-arguments.
2675 */
2676 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
2677
2678 case DNTT_TYPE_TEMPLATE_ARG:
2679 {
c5aa993b
JM
2680 char *name;
2681 /* The TEMPLATE record points to an argument list of
2682 * TEMPLATE_ARG records, each of which describes one
2683 * of the type-arguments.
2684 */
2685 name = VT (objfile) + dn_bufp->dtempl_arg.name;
2686 return hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name);
c906108c
SS
2687 }
2688
2689 case DNTT_TYPE_FUNC_TEMPLATE:
2690 /* We wind up here when processing a TEMPLATE type,
2691 * if the template has member function(s).
2692 * Treat it like a FUNCTION.
2693 */
2694 return hpread_read_function_type (hp_type, dn_bufp, objfile, 0);
2695
2696 case DNTT_TYPE_LINK:
2697 /* The LINK record is used to link up templates with instantiations.
2698 * There is no type associated with the LINK record per se.
2699 */
2700 return lookup_fundamental_type (objfile, FT_VOID);
2701
c5aa993b
JM
2702 /* Also not yet handled... */
2703 /* case DNTT_TYPE_DYN_ARRAY_DESC: */
2704 /* case DNTT_TYPE_DESC_SUBRANGE: */
2705 /* case DNTT_TYPE_BEGIN_EXT: */
2706 /* case DNTT_TYPE_INLN: */
2707 /* case DNTT_TYPE_INLN_LIST: */
2708 /* case DNTT_TYPE_ALIAS: */
c906108c
SS
2709 default:
2710 /* A fancy way of returning NULL */
2711 return lookup_fundamental_type (objfile, FT_VOID);
2712 }
2713}
2714
2715static sltpointer
2716hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
2717 struct subfile *subfile;
2718 sltpointer s_idx, e_idx;
2719 struct objfile *objfile;
2720 CORE_ADDR offset;
2721{
2722 union sltentry *sl_bufp;
2723
2724 while (s_idx <= e_idx)
2725 {
2726 sl_bufp = hpread_get_slt (s_idx, objfile);
2727 /* Only record "normal" entries in the SLT. */
2728 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
2729 || sl_bufp->snorm.sltdesc == SLT_EXIT)
2730 record_line (subfile, sl_bufp->snorm.line,
2731 sl_bufp->snorm.address + offset);
2732 else if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET)
2733 record_line (subfile, sl_bufp->snormoff.line,
2734 sl_bufp->snormoff.address + offset);
2735 s_idx++;
2736 }
2737 return e_idx;
2738}
2739
2740/* Given a function "f" which is a member of a class, find
2741 * the classname that it is a member of. Used to construct
2742 * the name (e.g., "c::f") which GDB will put in the
2743 * "demangled name" field of the function's symbol.
2744 * Called from hpread_process_one_debug_symbol()
2745 * If "f" is not a member function, return NULL.
2746 */
c5aa993b
JM
2747char *
2748class_of (functype)
2749 struct type *functype;
c906108c 2750{
c5aa993b
JM
2751 struct type *first_param_type;
2752 char *first_param_name;
2753 struct type *pointed_to_type;
2754 char *class_name;
c906108c
SS
2755
2756 /* Check that the function has a first argument "this",
2757 * and that "this" is a pointer to a class. If not,
2758 * functype is not a member function, so return NULL.
2759 */
c5aa993b 2760 if (TYPE_NFIELDS (functype) == 0)
c906108c
SS
2761 return NULL;
2762 first_param_name = TYPE_FIELD_NAME (functype, 0);
2763 if (first_param_name == NULL)
c5aa993b
JM
2764 return NULL; /* paranoia */
2765 if (strcmp (first_param_name, "this"))
c906108c
SS
2766 return NULL;
2767 first_param_type = TYPE_FIELD_TYPE (functype, 0);
2768 if (first_param_type == NULL)
c5aa993b
JM
2769 return NULL; /* paranoia */
2770 if (TYPE_CODE (first_param_type) != TYPE_CODE_PTR)
c906108c
SS
2771 return NULL;
2772
2773 /* Get the thing that "this" points to, check that
2774 * it's a class, and get its class name.
2775 */
c5aa993b
JM
2776 pointed_to_type = TYPE_TARGET_TYPE (first_param_type);
2777 if (pointed_to_type == NULL)
2778 return NULL; /* paranoia */
2779 if (TYPE_CODE (pointed_to_type) != TYPE_CODE_CLASS)
c906108c 2780 return NULL;
c5aa993b 2781 class_name = TYPE_NAME (pointed_to_type);
c906108c 2782 if (class_name == NULL)
c5aa993b 2783 return NULL; /* paranoia */
c906108c
SS
2784
2785 /* The class name may be of the form "class c", in which case
2786 * we want to strip off the leading "class ".
2787 */
c5aa993b 2788 if (strncmp (class_name, "class ", 6) == 0)
c906108c
SS
2789 class_name += 6;
2790
2791 return class_name;
2792}
2793
2794/* Internalize one native debug symbol.
2795 * Called in a loop from hpread_expand_symtab().
2796 * Arguments:
2797 * dn_bufp:
2798 * name:
2799 * section_offsets:
2800 * objfile:
2801 * text_offset:
2802 * text_size:
2803 * filename:
c5aa993b 2804 * index: Index of this symbol
c906108c
SS
2805 * at_module_boundary_p Pointer to boolean flag to control caller's loop.
2806 */
2807
2808static void
2809hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
2810 text_offset, text_size, filename,
c5aa993b
JM
2811 index, at_module_boundary_p
2812)
c906108c
SS
2813 union dnttentry *dn_bufp;
2814 char *name;
2815 struct section_offsets *section_offsets;
2816 struct objfile *objfile;
2817 CORE_ADDR text_offset;
c5aa993b
JM
2818 int text_size;
2819 char *filename;
2820 int index;
2821 int *at_module_boundary_p;
c906108c
SS
2822{
2823 unsigned long desc;
2824 int type;
2825 CORE_ADDR valu;
2826 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
2827 int data_offset = ANOFFSET (section_offsets, SECT_OFF_DATA);
2828 union dnttentry *dn_temp;
2829 dnttpointer hp_type;
2830 struct symbol *sym;
2831 struct context_stack *new;
c5aa993b
JM
2832 char *class_scope_name;
2833 extern int is_in_import_list (); /* in somread.c */
2834
c906108c
SS
2835 /* Allocate one GDB debug symbol and fill in some default values. */
2836 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
2837 sizeof (struct symbol));
2838 memset (sym, 0, sizeof (struct symbol));
2839 SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
2840 SYMBOL_LANGUAGE (sym) = language_auto;
2841 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2842 SYMBOL_LINE (sym) = 0;
2843 SYMBOL_VALUE (sym) = 0;
2844 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2845
2846 /* Just a trick in case the SOM debug symbol is a type definition.
2847 * There are routines that are set up to build a GDB type symbol, given
2848 * a SOM dnttpointer. So we set up a dummy SOM dnttpointer "hp_type".
2849 * This allows us to call those same routines.
2850 */
2851 hp_type.dnttp.extension = 1;
2852 hp_type.dnttp.immediate = 0;
2853 hp_type.dnttp.global = 0;
2854 hp_type.dnttp.index = index;
2855
2856 /* This "type" is the type of SOM record.
2857 * Switch on SOM type.
2858 */
2859 type = dn_bufp->dblock.kind;
2860 switch (type)
2861 {
2862 case DNTT_TYPE_SRCFILE:
2863 /* This type of symbol indicates from which source file or
2864 * include file any following data comes. It may indicate:
2865 *
2866 * o The start of an entirely new source file (and thus
2867 * a new module)
2868 *
2869 * o The start of a different source file due to #include
2870 *
2871 * o The end of an include file and the return to the original
2872 * file. Thus if "foo.c" includes "bar.h", we see first
2873 * a SRCFILE for foo.c, then one for bar.h, and then one for
2874 * foo.c again.
2875 *
2876 * If it indicates the start of a new module then we must
2877 * finish the symbol table of the previous module
2878 * (if any) and start accumulating a new symbol table.
2879 */
2880
2881 valu = text_offset;
c5aa993b
JM
2882 if (!last_source_file)
2883 {
2884 /*
2885 * A note on "last_source_file": this is a char* pointing
2886 * to the actual file name. "start_symtab" sets it,
2887 * "end_symtab" clears it.
2888 *
2889 * So if "last_source_file" is NULL, then either this is
2890 * the first record we are looking at, or a previous call
2891 * to "end_symtab()" was made to close out the previous
2892 * module. Since we're now quitting the scan loop when we
2893 * see a MODULE END record, we should never get here, except
2894 * in the case that we're not using the quick look-up tables
2895 * and have to use the old system as a fall-back.
2896 */
c906108c
SS
2897 start_symtab (name, NULL, valu);
2898 record_debugformat ("HP");
2899 SL_INDEX (objfile) = dn_bufp->dsfile.address;
c5aa993b 2900 }
c906108c 2901
c5aa993b
JM
2902 else
2903 {
2904 /* Either a new include file, or a SRCFILE record
2905 * saying we are back in the main source (or out of
2906 * a nested include file) again.
2907 */
c906108c
SS
2908 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
2909 SL_INDEX (objfile),
2910 dn_bufp->dsfile.address,
2911 objfile, offset);
c5aa993b 2912 }
c906108c
SS
2913
2914 /* A note on "start_subfile". This routine will check
2915 * the name we pass it and look for an existing subfile
2916 * of that name. There's thus only one sub-file for the
2917 * actual source (e.g. for "foo.c" in foo.c), despite the
2918 * fact that we'll see lots of SRCFILE entries for foo.c
2919 * inside foo.c.
2920 */
2921 start_subfile (name, NULL);
2922 break;
c5aa993b 2923
c906108c
SS
2924 case DNTT_TYPE_MODULE:
2925 /*
2926 * We no longer ignore DNTT_TYPE_MODULE symbols. The module
2927 * represents the meaningful semantic structure of a compilation
2928 * unit. We expect to start the psymtab-to-symtab expansion
2929 * looking at a MODULE entry, and to end it at the corresponding
2930 * END MODULE entry.
2931 *
2932 *--Begin outdated comments
2933 *
2934 * This record signifies the start of a new source module
2935 * In C/C++ there is no explicit "module" construct in the language,
2936 * but each compilation unit is implicitly a module and they
2937 * do emit the DNTT_TYPE_MODULE records.
2938 * The end of the module is marked by a matching DNTT_TYPE_END record.
2939 *
2940 * The reason GDB gets away with ignoring the DNTT_TYPE_MODULE record
2941 * is it notices the DNTT_TYPE_END record for the previous
2942 * module (see comments under DNTT_TYPE_END case), and then treats
2943 * the next DNTT_TYPE_SRCFILE record as if it were the module-start record.
2944 * (i.e., it makes a start_symtab() call).
2945 * This scheme seems a little convoluted, but I'll leave it
2946 * alone on the principle "if it ain't broke don't fix
2947 * it". (RT).
2948 *
2949 *-- End outdated comments
2950 */
2951
2952 valu = text_offset;
c5aa993b 2953 if (!last_source_file)
c906108c 2954 {
c5aa993b
JM
2955 /* Start of a new module. We know this because "last_source_file"
2956 * is NULL, which can only happen the first time or if we just
2957 * made a call to end_symtab() to close out the previous module.
2958 */
c906108c
SS
2959 start_symtab (name, NULL, valu);
2960 SL_INDEX (objfile) = dn_bufp->dmodule.address;
2961 }
2962 else
2963 {
c5aa993b
JM
2964 /* This really shouldn't happen if we're using the quick
2965 * look-up tables, as it would mean we'd scanned past an
2966 * END MODULE entry. But if we're not using the tables,
2967 * we started the module on the SRCFILE entry, so it's ok.
2968 * For now, accept this.
2969 */
2970 /* warning( "Error expanding psymtab, missed module end, found entry for %s",
2971 * name );
2972 */
2973 *at_module_boundary_p = -1;
c906108c
SS
2974 }
2975
2976 start_subfile (name, NULL);
2977 break;
2978
2979 case DNTT_TYPE_FUNCTION:
2980 case DNTT_TYPE_ENTRY:
2981 /* A function or secondary entry point. */
2982 valu = dn_bufp->dfunc.lowaddr + offset;
2983
2984 /* Record lines up to this point. */
2985 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
2986 SL_INDEX (objfile),
2987 dn_bufp->dfunc.address,
2988 objfile, offset);
c5aa993b 2989
c906108c
SS
2990 WITHIN_FUNCTION (objfile) = 1;
2991 CURRENT_FUNCTION_VALUE (objfile) = valu;
2992
2993 /* Stack must be empty now. */
2994 if (context_stack_depth != 0)
2995 complain (&lbrac_unmatched_complaint, (char *) symnum);
2996 new = push_context (0, valu);
2997
2998 /* Built a type for the function. This includes processing
2999 * the symbol records for the function parameters.
3000 */
3001 SYMBOL_CLASS (sym) = LOC_BLOCK;
3002 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1);
3003
3004 /* The "SYMBOL_NAME" field is expected to be the mangled name
3005 * (if any), which we get from the "alias" field of the SOM record
3006 * if that exists.
3007 */
c5aa993b
JM
3008 if ((dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
3009 dn_bufp->dfunc.alias && /* has an alias */
3010 *(char *) (VT (objfile) + dn_bufp->dfunc.alias)) /* not a null string */
3011 SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias;
c906108c 3012 else
c5aa993b 3013 SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
c906108c
SS
3014
3015 /* Special hack to get around HP compilers' insistence on
3016 * reporting "main" as "_MAIN_" for C/C++ */
3017 if ((strcmp (SYMBOL_NAME (sym), "_MAIN_") == 0) &&
c5aa993b
JM
3018 (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0))
3019 SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name;
3020
c906108c
SS
3021 /* The SYMBOL_CPLUS_DEMANGLED_NAME field is expected to
3022 * be the demangled name.
3023 */
3024 if (dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
3025 {
c5aa993b
JM
3026 /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
3027 * calling the demangler in libiberty (cplus_demangle()) to
3028 * do the job. This generally does the job, even though
3029 * it's intended for the GNU compiler and not the aCC compiler
3030 * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
3031 * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
3032 * Generally, we don't want params when we display
3033 * a demangled name, but when I took out the DMGL_PARAMS,
3034 * some things broke, so I'm leaving it in here, and
3035 * working around the issue in stack.c. - RT
3036 */
3037 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
3038 if ((SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->dfunc.alias) &&
3039 (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
3040 {
3041
3042 /* Well, the symbol name is mangled, but the
3043 * demangler in libiberty failed so the demangled
3044 * field is still NULL. Try to
3045 * do the job ourselves based on the "name" field
3046 * in the SOM record. A complication here is that
3047 * the name field contains only the function name
3048 * (like "f"), whereas we want the class qualification
3049 * (as in "c::f"). Try to reconstruct that.
3050 */
3051 char *basename;
3052 char *classname;
3053 char *dem_name;
3054 basename = VT (objfile) + dn_bufp->dfunc.name;
3055 classname = class_of (SYMBOL_TYPE (sym));
3056 if (classname)
3057 {
3058 dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
3059 strcpy (dem_name, classname);
3060 strcat (dem_name, "::");
3061 strcat (dem_name, basename);
3062 SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
3063 SYMBOL_LANGUAGE (sym) = language_cplus;
3064 }
3065 }
3066 }
3067
c906108c
SS
3068 /* Add the function symbol to the list of symbols in this blockvector */
3069 if (dn_bufp->dfunc.global)
3070 add_symbol_to_list (sym, &global_symbols);
3071 else
3072 add_symbol_to_list (sym, &file_symbols);
3073 new->name = sym;
3074
3075 /* Search forward to the next BEGIN and also read
3076 * in the line info up to that point.
3077 * Not sure why this is needed.
3078 * In HP FORTRAN this code is harmful since there
3079 * may not be a BEGIN after the FUNCTION.
3080 * So I made it C/C++ specific. - RT
3081 */
3082 if (dn_bufp->dfunc.language == HP_LANGUAGE_C ||
c5aa993b
JM
3083 dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS)
3084 {
3085 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
3086 {
3087 dn_bufp = hpread_get_lntt (++index, objfile);
3088 if (dn_bufp->dblock.extension)
3089 continue;
3090 }
3091 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
3092 SL_INDEX (objfile),
3093 dn_bufp->dbegin.address,
3094 objfile, offset);
3095 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
3096 }
c906108c
SS
3097 record_line (current_subfile, SYMBOL_LINE (sym), valu);
3098 break;
3099
3100 case DNTT_TYPE_DOC_FUNCTION:
3101 valu = dn_bufp->ddocfunc.lowaddr + offset;
3102
3103 /* Record lines up to this point. */
3104 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
3105 SL_INDEX (objfile),
3106 dn_bufp->ddocfunc.address,
3107 objfile, offset);
c5aa993b 3108
c906108c
SS
3109 WITHIN_FUNCTION (objfile) = 1;
3110 CURRENT_FUNCTION_VALUE (objfile) = valu;
3111 /* Stack must be empty now. */
3112 if (context_stack_depth != 0)
3113 complain (&lbrac_unmatched_complaint, (char *) symnum);
3114 new = push_context (0, valu);
3115
3116 /* Built a type for the function. This includes processing
3117 * the symbol records for the function parameters.
3118 */
3119 SYMBOL_CLASS (sym) = LOC_BLOCK;
3120 SYMBOL_TYPE (sym) = hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 1);
3121
3122 /* The "SYMBOL_NAME" field is expected to be the mangled name
3123 * (if any), which we get from the "alias" field of the SOM record
3124 * if that exists.
3125 */
c5aa993b
JM
3126 if ((dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) &&
3127 dn_bufp->ddocfunc.alias && /* has an alias */
3128 *(char *) (VT (objfile) + dn_bufp->ddocfunc.alias)) /* not a null string */
3129 SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.alias;
c906108c 3130 else
c5aa993b 3131 SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
c906108c
SS
3132
3133 /* Special hack to get around HP compilers' insistence on
3134 * reporting "main" as "_MAIN_" for C/C++ */
3135 if ((strcmp (SYMBOL_NAME (sym), "_MAIN_") == 0) &&
c5aa993b
JM
3136 (strcmp (VT (objfile) + dn_bufp->ddocfunc.name, "main") == 0))
3137 SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name;
3138
3139 if (dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
3140 {
3141
3142 /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up
3143 * calling the demangler in libiberty (cplus_demangle()) to
3144 * do the job. This generally does the job, even though
3145 * it's intended for the GNU compiler and not the aCC compiler
3146 * Note that SYMBOL_INIT_DEMANGLED_NAME calls the
3147 * demangler with arguments DMGL_PARAMS | DMGL_ANSI.
3148 * Generally, we don't want params when we display
3149 * a demangled name, but when I took out the DMGL_PARAMS,
3150 * some things broke, so I'm leaving it in here, and
3151 * working around the issue in stack.c. - RT
3152 */
3153 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
3154
3155 if ((SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->ddocfunc.alias) &&
3156 (!SYMBOL_CPLUS_DEMANGLED_NAME (sym)))
3157 {
3158
3159 /* Well, the symbol name is mangled, but the
3160 * demangler in libiberty failed so the demangled
3161 * field is still NULL. Try to
3162 * do the job ourselves based on the "name" field
3163 * in the SOM record. A complication here is that
3164 * the name field contains only the function name
3165 * (like "f"), whereas we want the class qualification
3166 * (as in "c::f"). Try to reconstruct that.
3167 */
3168 char *basename;
3169 char *classname;
3170 char *dem_name;
3171 basename = VT (objfile) + dn_bufp->ddocfunc.name;
3172 classname = class_of (SYMBOL_TYPE (sym));
3173 if (classname)
3174 {
3175 dem_name = xmalloc (strlen (basename) + strlen (classname) + 3);
3176 strcpy (dem_name, classname);
3177 strcat (dem_name, "::");
3178 strcat (dem_name, basename);
3179 SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name;
3180 SYMBOL_LANGUAGE (sym) = language_cplus;
3181 }
3182 }
3183 }
c906108c
SS
3184
3185 /* Add the function symbol to the list of symbols in this blockvector */
3186 if (dn_bufp->ddocfunc.global)
3187 add_symbol_to_list (sym, &global_symbols);
3188 else
3189 add_symbol_to_list (sym, &file_symbols);
3190 new->name = sym;
3191
3192 /* Search forward to the next BEGIN and also read
3193 * in the line info up to that point.
3194 * Not sure why this is needed.
3195 * In HP FORTRAN this code is harmful since there
3196 * may not be a BEGIN after the FUNCTION.
3197 * So I made it C/C++ specific. - RT
3198 */
3199 if (dn_bufp->ddocfunc.language == HP_LANGUAGE_C ||
c5aa993b
JM
3200 dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS)
3201 {
3202 while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
3203 {
3204 dn_bufp = hpread_get_lntt (++index, objfile);
3205 if (dn_bufp->dblock.extension)
3206 continue;
3207 }
3208 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
3209 SL_INDEX (objfile),
3210 dn_bufp->dbegin.address,
3211 objfile, offset);
3212 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
3213 }
c906108c
SS
3214 record_line (current_subfile, SYMBOL_LINE (sym), valu);
3215 break;
3216
3217 case DNTT_TYPE_BEGIN:
3218 /* Begin a new scope. */
c5aa993b
JM
3219 if (context_stack_depth == 1 /* this means we're at function level */ &&
3220 context_stack[0].name != NULL /* this means it's a function */ &&
3221 context_stack[0].depth == 0 /* this means it's the first BEGIN
3222 we've seen after the FUNCTION */
3223 )
3224 {
3225 /* This is the first BEGIN after a FUNCTION.
3226 * We ignore this one, since HP compilers always insert
3227 * at least one BEGIN, i.e. it's:
3228 *
3229 * FUNCTION
3230 * argument symbols
3231 * BEGIN
3232 * local symbols
3233 * (possibly nested BEGIN ... END's if there are inner { } blocks)
3234 * END
3235 * END
3236 *
3237 * By ignoring this first BEGIN, the local symbols get treated
3238 * as belonging to the function scope, and "print func::local_sym"
3239 * works (which is what we want).
3240 */
3241
3242 /* All we do here is increase the depth count associated with
3243 * the FUNCTION entry in the context stack. This ensures that
3244 * the next BEGIN we see (if any), representing a real nested { }
3245 * block, will get processed.
3246 */
3247
3248 context_stack[0].depth++;
3249
3250 }
3251 else
3252 {
3253
3254 /* Record lines up to this SLT pointer. */
3255 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
3256 SL_INDEX (objfile),
3257 dn_bufp->dbegin.address,
3258 objfile, offset);
3259 /* Calculate start address of new scope */
3260 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
3261 valu += offset; /* Relocate for dynamic loading */
3262 /* We use the scope start DNTT index as nesting depth identifier! */
3263 desc = hpread_get_scope_start (dn_bufp->dbegin.address, objfile);
3264 new = push_context (desc, valu);
3265 }
c906108c
SS
3266 break;
3267
3268 case DNTT_TYPE_END:
3269 /* End a scope. */
3270
3271 /* Valid end kinds are:
3272 * MODULE
3273 * FUNCTION
3274 * WITH
3275 * COMMON
3276 * BEGIN
3277 * CLASS_SCOPE
3278 */
3279
3280 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
3281 SL_INDEX (objfile),
3282 dn_bufp->dend.address,
3283 objfile, offset);
3284 switch (dn_bufp->dend.endkind)
3285 {
3286 case DNTT_TYPE_MODULE:
3287 /* Ending a module ends the symbol table for that module.
c5aa993b
JM
3288 * Calling end_symtab() has the side effect of clearing the
3289 * last_source_file pointer, which in turn signals
3290 * process_one_debug_symbol() to treat the next DNTT_TYPE_SRCFILE
3291 * record as a module-begin.
3292 */
c906108c
SS
3293 valu = text_offset + text_size + offset;
3294
c5aa993b
JM
3295 /* Tell our caller that we're done with expanding the
3296 * debug information for a module.
3297 */
3298 *at_module_boundary_p = 1;
3299
3300 /* Don't do this, as our caller will do it!
c906108c 3301
c5aa993b
JM
3302 * (void) end_symtab (valu, objfile, 0);
3303 */
c906108c
SS
3304 break;
3305
3306 case DNTT_TYPE_FUNCTION:
3307 /* Ending a function, well, ends the function's scope. */
3308 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
3309 objfile);
3310 valu = dn_temp->dfunc.hiaddr + offset;
c5aa993b
JM
3311 /* Insert func params into local list */
3312 merge_symbol_lists (&param_symbols, &local_symbols);
c906108c
SS
3313 new = pop_context ();
3314 /* Make a block for the local symbols within. */
3315 finish_block (new->name, &local_symbols, new->old_blocks,
3316 new->start_addr, valu, objfile);
c5aa993b
JM
3317 WITHIN_FUNCTION (objfile) = 0; /* This may have to change for Pascal */
3318 local_symbols = new->locals;
3319 param_symbols = new->params;
c906108c
SS
3320 break;
3321
3322 case DNTT_TYPE_BEGIN:
c5aa993b
JM
3323 if (context_stack_depth == 1 &&
3324 context_stack[0].name != NULL &&
3325 context_stack[0].depth == 1)
3326 {
3327 /* This is the END corresponding to the
3328 * BEGIN which we ignored - see DNTT_TYPE_BEGIN case above.
3329 */
3330 context_stack[0].depth--;
3331 }
3332 else
3333 {
3334 /* Ending a local scope. */
3335 valu = hpread_get_location (dn_bufp->dend.address, objfile);
3336 /* Why in the hell is this needed? */
3337 valu += offset + 9; /* Relocate for dynamic loading */
3338 new = pop_context ();
3339 desc = dn_bufp->dend.beginscope.dnttp.index;
3340 if (desc != new->depth)
3341 complain (&lbrac_mismatch_complaint, (char *) symnum);
3342
3343 /* Make a block for the local symbols within. */
3344 finish_block (new->name, &local_symbols, new->old_blocks,
3345 new->start_addr, valu, objfile);
3346 local_symbols = new->locals;
3347 param_symbols = new->params;
3348 }
c906108c
SS
3349 break;
3350
c5aa993b
JM
3351 case DNTT_TYPE_WITH:
3352 /* Since we ignore the DNTT_TYPE_WITH that starts the scope,
3353 * we can ignore the DNTT_TYPE_END that ends it.
3354 */
c906108c
SS
3355 break;
3356
c5aa993b
JM
3357 case DNTT_TYPE_COMMON:
3358 /* End a FORTRAN common block. We don't currently handle these */
3359 complain (&hpread_unhandled_end_common_complaint);
c906108c
SS
3360 break;
3361
c5aa993b 3362 case DNTT_TYPE_CLASS_SCOPE:
c906108c 3363
c5aa993b
JM
3364 /* pai: FIXME Not handling nested classes for now -- must
3365 * maintain a stack */
3366 class_scope_name = NULL;
c906108c
SS
3367
3368#if 0
c5aa993b 3369 /* End a class scope */
c906108c
SS
3370 valu = hpread_get_location (dn_bufp->dend.address, objfile);
3371 /* Why in the hell is this needed? */
3372 valu += offset + 9; /* Relocate for dynamic loading */
3373 new = pop_context ();
3374 desc = dn_bufp->dend.beginscope.dnttp.index;
3375 if (desc != new->depth)
3376 complain (&lbrac_mismatch_complaint, (char *) symnum);
3377 /* Make a block for the local symbols within. */
3378 finish_block (new->name, &local_symbols, new->old_blocks,
3379 new->start_addr, valu, objfile);
3380 local_symbols = new->locals;
3381 param_symbols = new->params;
3382#endif
3383 break;
3384
c5aa993b
JM
3385 default:
3386 complain (&hpread_unexpected_end_complaint);
3387 break;
c906108c
SS
3388 }
3389 break;
3390
c5aa993b 3391 /* DNTT_TYPE_IMPORT is not handled */
c906108c
SS
3392
3393 case DNTT_TYPE_LABEL:
3394 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
3395 break;
3396
3397 case DNTT_TYPE_FPARAM:
3398 /* Function parameters. */
3399 /* Note 1: This code was present in the 4.16 sources, and then
3400 removed, because fparams are handled in
3401 hpread_read_function_type(). However, while fparam symbols
3402 are indeed handled twice, this code here cannot be removed
3403 because then they don't get added to the local symbol list of
3404 the function's code block, which leads to a failure to look
3405 up locals, "this"-relative member names, etc. So I've put
3406 this code back in. pai/1997-07-21 */
3407 /* Note 2: To fix a defect, we stopped adding FPARAMS to local_symbols
3408 in hpread_read_function_type(), so FPARAMS had to be handled
3409 here. I changed the location to be the appropriate argument
3410 kinds rather than LOC_LOCAL. pai/1997-08-08 */
3411 /* Note 3: Well, the fix in Note 2 above broke argument printing
3412 in traceback frames, and further it makes assumptions about the
3413 order of the FPARAM entries from HP compilers (cc and aCC in particular
3414 generate them in reverse orders -- fixing one breaks for the other).
3415 So I've added code in hpread_read_function_type() to add fparams
3416 to a param_symbols list for the current context level. These are
3417 then merged into local_symbols when a function end is reached.
c5aa993b
JM
3418 pai/1997-08-11 */
3419
3420 break; /* do nothing; handled in hpread_read_function_type() */
3421
3422#if 0 /* Old code */
c906108c 3423 if (dn_bufp->dfparam.regparam)
c5aa993b 3424 SYMBOL_CLASS (sym) = LOC_REGISTER;
c906108c
SS
3425 else if (dn_bufp->dfparam.indirect)
3426 SYMBOL_CLASS (sym) = LOC_REF_ARG;
3427 else
3428 SYMBOL_CLASS (sym) = LOC_ARG;
3429 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3430 if (dn_bufp->dfparam.copyparam)
c5aa993b
JM
3431 {
3432 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
c906108c 3433#ifdef HPREAD_ADJUST_STACK_ADDRESS
c5aa993b
JM
3434 SYMBOL_VALUE (sym)
3435 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
c906108c 3436#endif
c5aa993b 3437 }
c906108c 3438 else
c5aa993b 3439 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
c906108c
SS
3440 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
3441 add_symbol_to_list (sym, &fparam_symbols);
3442 break;
3443#endif
3444
3445 case DNTT_TYPE_SVAR:
3446 /* Static variables. */
c5aa993b 3447 SYMBOL_CLASS (sym) = LOC_STATIC;
c906108c
SS
3448
3449 /* Note: There is a case that arises with globals in shared
3450 * libraries where we need to set the address to LOC_INDIRECT.
3451 * This case is if you have a global "g" in one library, and
3452 * it is referenced "extern <type> g;" in another library.
3453 * If we're processing the symbols for the referencing library,
3454 * we'll see a global "g", but in this case the address given
3455 * in the symbol table contains a pointer to the real "g".
3456 * We use the storage class LOC_INDIRECT to indicate this. RT
3457 */
c5aa993b
JM
3458 if (is_in_import_list (SYMBOL_NAME (sym), objfile))
3459 SYMBOL_CLASS (sym) = LOC_INDIRECT;
c906108c
SS
3460
3461 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + data_offset;
3462 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
3463
3464 if (dn_bufp->dsvar.global)
3465 add_symbol_to_list (sym, &global_symbols);
c5aa993b 3466
c906108c
SS
3467 else if (WITHIN_FUNCTION (objfile))
3468 add_symbol_to_list (sym, &local_symbols);
c5aa993b 3469
c906108c
SS
3470 else
3471 add_symbol_to_list (sym, &file_symbols);
3472
3473 if (dn_bufp->dsvar.thread_specific)
c5aa993b
JM
3474 {
3475 /* Thread-local variable.
3476 */
3477 SYMBOL_CLASS (sym) = LOC_THREAD_LOCAL_STATIC;
3478 SYMBOL_BASEREG (sym) = CR27_REGNUM;
3479
3480 if (objfile->flags & OBJF_SHARED)
3481 {
3482 /*
3483 * This variable is not only thread local but
3484 * in a shared library.
3485 *
3486 * Alas, the shared lib structures are private
3487 * to "somsolib.c". But C lets us point to one.
3488 */
3489 struct so_list *so;
3490
3491 if (objfile->obj_private == NULL)
3492 error ("Internal error in reading shared library information.");
3493
3494 so = ((obj_private_data_t *) (objfile->obj_private))->so_info;
3495 if (so == NULL)
3496 error ("Internal error in reading shared library information.");
3497
3498 /* Thread-locals in shared libraries do NOT have the
3499 * standard offset ("data_offset"), so we re-calculate
3500 * where to look for this variable, using a call-back
3501 * to interpret the private shared-library data.
3502 */
3503 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location +
3504 so_lib_thread_start_addr (so);
3505 }
3506 }
c906108c
SS
3507 break;
3508
3509 case DNTT_TYPE_DVAR:
3510 /* Dynamic variables. */
3511 if (dn_bufp->ddvar.regvar)
3512 SYMBOL_CLASS (sym) = LOC_REGISTER;
3513 else
3514 SYMBOL_CLASS (sym) = LOC_LOCAL;
c5aa993b 3515
c906108c
SS
3516 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
3517#ifdef HPREAD_ADJUST_STACK_ADDRESS
3518 SYMBOL_VALUE (sym)
3519 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
3520#endif
3521 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
3522 if (dn_bufp->ddvar.global)
3523 add_symbol_to_list (sym, &global_symbols);
3524 else if (WITHIN_FUNCTION (objfile))
3525 add_symbol_to_list (sym, &local_symbols);
3526 else
3527 add_symbol_to_list (sym, &file_symbols);
3528 break;
3529
3530 case DNTT_TYPE_CONST:
3531 /* A constant (pascal?). */
3532 SYMBOL_CLASS (sym) = LOC_CONST;
3533 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
3534 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
3535 if (dn_bufp->dconst.global)
3536 add_symbol_to_list (sym, &global_symbols);
3537 else if (WITHIN_FUNCTION (objfile))
3538 add_symbol_to_list (sym, &local_symbols);
3539 else
3540 add_symbol_to_list (sym, &file_symbols);
3541 break;
3542
3543 case DNTT_TYPE_TYPEDEF:
3544 /* A typedef. We do want to process these, since a name is
3545 * added to the namespace for the typedef'ed name.
3546 */
3547 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3548 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
3549 if (dn_bufp->dtype.global)
3550 add_symbol_to_list (sym, &global_symbols);
3551 else if (WITHIN_FUNCTION (objfile))
3552 add_symbol_to_list (sym, &local_symbols);
3553 else
3554 add_symbol_to_list (sym, &file_symbols);
3555 break;
3556
3557 case DNTT_TYPE_TAGDEF:
3558 {
c5aa993b
JM
3559 int global = dn_bufp->dtag.global;
3560 /* Structure, union, enum, template, or class tag definition */
3561 /* We do want to process these, since a name is
3562 * added to the namespace for the tag name (and if C++ class,
3563 * for the typename also).
3564 */
3565 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
3566
3567 /* The tag contains in its "type" field a pointer to the
3568 * DNTT_TYPE_STRUCT, DNTT_TYPE_UNION, DNTT_TYPE_ENUM,
3569 * DNTT_TYPE_CLASS or DNTT_TYPE_TEMPLATE
3570 * record that actually defines the type.
3571 */
3572 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
3573 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
3574 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
3575 if (dn_bufp->dtag.global)
3576 add_symbol_to_list (sym, &global_symbols);
3577 else if (WITHIN_FUNCTION (objfile))
3578 add_symbol_to_list (sym, &local_symbols);
3579 else
3580 add_symbol_to_list (sym, &file_symbols);
3581
3582 /* If this is a C++ class, then we additionally
3583 * need to define a typedef for the
3584 * class type. E.g., so that the name "c" becomes visible as
3585 * a type name when the user says "class c { ... }".
3586 * In order to figure this out, we need to chase down the "type"
3587 * field to get to the DNTT_TYPE_CLASS record.
3588 *
3589 * We also add the typename for ENUM. Though this isn't
3590 * strictly correct, it is necessary because of the debug info
3591 * generated by the aCC compiler, in which we cannot
3592 * distinguish between:
3593 * enum e { ... };
3594 * and
3595 * typedef enum { ... } e;
3596 * I.e., the compiler emits the same debug info for the above
3597 * two cases, in both cases "e" appearing as a tagdef.
3598 * Therefore go ahead and generate the typename so that
3599 * "ptype e" will work in the above cases.
3600 *
3601 * We also add the typename for TEMPLATE, so as to allow "ptype t"
3602 * when "t" is a template name.
3603 */
3604 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
3605 dn_bufp = hpread_get_lntt (dn_bufp->dtag.type.dnttp.index, objfile);
3606 else
3607 {
3608 complain (&hpread_tagdef_complaint);
3609 return;
3610 }
3611 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
3612 dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
3613 dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
3614 {
3615 struct symbol *newsym;
3616
3617 newsym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
3618 sizeof (struct symbol));
3619 memset (newsym, 0, sizeof (struct symbol));
3620 SYMBOL_NAME (newsym) = name;
3621 SYMBOL_LANGUAGE (newsym) = language_auto;
3622 SYMBOL_NAMESPACE (newsym) = VAR_NAMESPACE;
3623 SYMBOL_LINE (newsym) = 0;
3624 SYMBOL_VALUE (newsym) = 0;
3625 SYMBOL_CLASS (newsym) = LOC_TYPEDEF;
3626 SYMBOL_TYPE (newsym) = sym->type;
3627 if (global)
3628 add_symbol_to_list (newsym, &global_symbols);
3629 else if (WITHIN_FUNCTION (objfile))
3630 add_symbol_to_list (newsym, &local_symbols);
3631 else
3632 add_symbol_to_list (newsym, &file_symbols);
3633 }
c906108c
SS
3634 }
3635 break;
3636
3637 case DNTT_TYPE_POINTER:
3638 /* Declares a pointer type. Should not be necessary to do anything
3639 * with the type at this level; these are processed
3640 * at the hpread_type_lookup() level.
3641 */
3642 break;
3643
3644 case DNTT_TYPE_ENUM:
3645 /* Declares an enum type. Should not be necessary to do anything
3646 * with the type at this level; these are processed
3647 * at the hpread_type_lookup() level.
3648 */
3649 break;
3650
3651 case DNTT_TYPE_MEMENUM:
3652 /* Member of enum */
3653 /* Ignored at this level, but hpread_read_enum_type() will take
3654 * care of walking the list of enumeration members.
3655 */
3656 break;
3657
3658 case DNTT_TYPE_SET:
3659 /* Declares a set type. Should not be necessary to do anything
3660 * with the type at this level; these are processed
3661 * at the hpread_type_lookup() level.
3662 */
3663 break;
3664
3665 case DNTT_TYPE_SUBRANGE:
3666 /* Declares a subrange type. Should not be necessary to do anything
3667 * with the type at this level; these are processed
3668 * at the hpread_type_lookup() level.
3669 */
3670 break;
3671
3672 case DNTT_TYPE_ARRAY:
3673 /* Declares an array type. Should not be necessary to do anything
3674 * with the type at this level; these are processed
3675 * at the hpread_type_lookup() level.
3676 */
3677 break;
3678
3679 case DNTT_TYPE_STRUCT:
3680 case DNTT_TYPE_UNION:
3681 /* Declares an struct/union type.
3682 * Should not be necessary to do anything
3683 * with the type at this level; these are processed
3684 * at the hpread_type_lookup() level.
3685 */
3686 break;
3687
3688 case DNTT_TYPE_FIELD:
3689 /* Structure/union/class field */
3690 /* Ignored at this level, but hpread_read_struct_type() will take
3691 * care of walking the list of structure/union/class members.
3692 */
3693 break;
3694
c5aa993b 3695 /* DNTT_TYPE_VARIANT is not handled by GDB */
c906108c 3696
c5aa993b 3697 /* DNTT_TYPE_FILE is not handled by GDB */
c906108c
SS
3698
3699 case DNTT_TYPE_FUNCTYPE:
3700 /* Function type */
3701 /* Ignored at this level, handled within hpread_type_lookup() */
3702 break;
3703
3704 case DNTT_TYPE_WITH:
3705 /* This is emitted within methods to indicate "with <class>"
3706 * scoping rules (i.e., indicate that the class data members
3707 * are directly visible).
3708 * However, since GDB already infers this by looking at the
3709 * "this" argument, interpreting the DNTT_TYPE_WITH
3710 * symbol record is unnecessary.
3711 */
3712 break;
3713
3714 case DNTT_TYPE_COMMON:
3715 /* FORTRAN common. Not yet handled. */
3716 complain (&hpread_unhandled_common_complaint);
3717 break;
3718
c5aa993b
JM
3719 /* DNTT_TYPE_COBSTRUCT is not handled by GDB. */
3720 /* DNTT_TYPE_XREF is not handled by GDB. */
3721 /* DNTT_TYPE_SA is not handled by GDB. */
3722 /* DNTT_TYPE_MACRO is not handled by GDB */
c906108c
SS
3723
3724 case DNTT_TYPE_BLOCKDATA:
3725 /* Not sure what this is - part of FORTRAN support maybe?
3726 * Anyway, not yet handled.
3727 */
3728 complain (&hpread_unhandled_blockdata_complaint);
3729 break;
3730
3731 case DNTT_TYPE_CLASS_SCOPE:
3732
3733
3734
3735 /* The compiler brackets member functions with a CLASS_SCOPE/END
3736 * pair of records, presumably to put them in a different scope
3737 * from the module scope where they are normally defined.
3738 * E.g., in the situation:
3739 * void f() { ... }
3740 * void c::f() { ...}
3741 * The member function "c::f" will be bracketed by a CLASS_SCOPE/END.
3742 * This causes "break f" at the module level to pick the
3743 * the file-level function f(), not the member function
3744 * (which needs to be referenced via "break c::f").
3745 *
3746 * Here we record the class name to generate the demangled names of
3747 * member functions later.
3748 *
3749 * FIXME Not being used now for anything -- cplus_demangle seems
3750 * enough for getting the class-qualified names of functions. We
3751 * may need this for handling nested classes and types. */
3752
3753 /* pai: FIXME Not handling nested classes for now -- need to
3754 * maintain a stack */
3755
3756 dn_temp = hpread_get_lntt (dn_bufp->dclass_scope.type.dnttp.index, objfile);
3757 if (dn_temp->dblock.kind == DNTT_TYPE_TAGDEF)
c5aa993b 3758 class_scope_name = VT (objfile) + dn_temp->dtag.name;
c906108c 3759 else
c5aa993b 3760 class_scope_name = NULL;
c906108c
SS
3761
3762#if 0
3763
3764 /* Begin a new scope. */
3765 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
3766 SL_INDEX (objfile),
c5aa993b 3767 dn_bufp->dclass_scope.address,
c906108c
SS
3768 objfile, offset);
3769 valu = hpread_get_location (dn_bufp->dclass_scope.address, objfile);
3770 valu += offset; /* Relocate for dynamic loading */
3771 desc = hpread_get_scope_start (dn_bufp->dclass_scope.address, objfile);
3772 /* We use the scope start DNTT index as the nesting depth identifier! */
3773 new = push_context (desc, valu);
3774#endif
3775 break;
3776
3777 case DNTT_TYPE_REFERENCE:
3778 /* Declares a C++ reference type. Should not be necessary to do anything
3779 * with the type at this level; these are processed
3780 * at the hpread_type_lookup() level.
3781 */
3782 break;
3783
3784 case DNTT_TYPE_PTRMEM:
3785 /* Declares a C++ pointer-to-data-member type. This does not
3786 * need to be handled at this level; being a type description it
3787 * is instead handled at the hpread_type_lookup() level.
3788 */
3789 break;
3790
3791 case DNTT_TYPE_PTRMEMFUNC:
3792 /* Declares a C++ pointer-to-function-member type. This does not
3793 * need to be handled at this level; being a type description it
3794 * is instead handled at the hpread_type_lookup() level.
3795 */
3796 break;
3797
3798 case DNTT_TYPE_CLASS:
3799 /* Declares a class type.
3800 * Should not be necessary to do anything
3801 * with the type at this level; these are processed
3802 * at the hpread_type_lookup() level.
3803 */
3804 break;
3805
3806 case DNTT_TYPE_GENFIELD:
3807 /* I believe this is used for class member functions */
3808 /* Ignored at this level, but hpread_read_struct_type() will take
3809 * care of walking the list of class members.
3810 */
3811 break;
3812
3813 case DNTT_TYPE_VFUNC:
3814 /* Virtual function */
3815 /* This does not have to be handled at this level; handled in
3816 * the course of processing class symbols.
3817 */
3818 break;
3819
3820 case DNTT_TYPE_MEMACCESS:
3821 /* DDE ignores this symbol table record.
3822 * It has something to do with "modified access" to class members.
3823 * I'll assume we can safely ignore it too.
3824 */
3825 break;
3826
3827 case DNTT_TYPE_INHERITANCE:
3828 /* These don't have to be handled here, since they are handled
3829 * within hpread_read_struct_type() in the process of constructing
3830 * a class type.
3831 */
3832 break;
3833
3834 case DNTT_TYPE_FRIEND_CLASS:
3835 case DNTT_TYPE_FRIEND_FUNC:
3836 /* These can safely be ignored, as GDB doesn't need this
3837 * info. DDE only uses it in "describe". We may later want
3838 * to extend GDB's "ptype" to give this info, but for now
3839 * it seems safe enough to ignore it.
c5aa993b 3840 */
c906108c
SS
3841 break;
3842
3843 case DNTT_TYPE_MODIFIER:
3844 /* Intended to supply "modified access" to a type */
3845 /* From the way DDE handles this, it looks like it always
3846 * modifies a type. Therefore it is safe to ignore it at this
3847 * level, and handle it in hpread_type_lookup().
3848 */
3849 break;
3850
3851 case DNTT_TYPE_OBJECT_ID:
3852 /* Just ignore this - that's all DDE does */
3853 break;
3854
3855 case DNTT_TYPE_MEMFUNC:
3856 /* Member function */
3857 /* This does not have to be handled at this level; handled in
3858 * the course of processing class symbols.
3859 */
3860 break;
3861
3862 case DNTT_TYPE_DOC_MEMFUNC:
3863 /* Member function */
3864 /* This does not have to be handled at this level; handled in
3865 * the course of processing class symbols.
3866 */
3867 break;
3868
3869 case DNTT_TYPE_TEMPLATE:
3870 /* Template - sort of the header for a template definition,
3871 * which like a class, points to a member list and also points
3872 * to a TEMPLATE_ARG list of type-arguments.
3873 * We do not need to process TEMPLATE records at this level though.
3874 */
3875 break;
3876
3877 case DNTT_TYPE_TEMPLATE_ARG:
3878 /* The TEMPLATE record points to an argument list of
3879 * TEMPLATE_ARG records, each of which describes one
3880 * of the type-arguments.
3881 * We do not need to process TEMPLATE_ARG records at this level though.
3882 */
3883 break;
3884
3885 case DNTT_TYPE_FUNC_TEMPLATE:
3886 /* This will get emitted for member functions of templates.
3887 * But we don't need to process this record at this level though,
3888 * we will process it in the course of processing a TEMPLATE
3889 * record.
3890 */
3891 break;
3892
3893 case DNTT_TYPE_LINK:
3894 /* The LINK record is used to link up templates with instantiations. */
3895 /* It is not clear why this is needed, and furthermore aCC does
3896 * not appear to generate this, so I think we can safely ignore it. - RT
3897 */
3898 break;
3899
c5aa993b
JM
3900 /* DNTT_TYPE_DYN_ARRAY_DESC is not handled by GDB */
3901 /* DNTT_TYPE_DESC_SUBRANGE is not handled by GDB */
3902 /* DNTT_TYPE_BEGIN_EXT is not handled by GDB */
3903 /* DNTT_TYPE_INLN is not handled by GDB */
3904 /* DNTT_TYPE_INLN_LIST is not handled by GDB */
3905 /* DNTT_TYPE_ALIAS is not handled by GDB */
c906108c
SS
3906
3907 default:
3908 break;
3909 }
3910}
3911
3912/* Get nesting depth for a DNTT entry.
3913 * DN_BUFP points to a DNTT entry.
3914 * OBJFILE is the object file.
3915 * REPORT_NESTED is a flag; if 0, real nesting depth is
3916 * reported, if it is 1, the function simply returns a
3917 * non-zero value if the nesting depth is anything > 0.
3918 *
3919 * Return value is an integer. 0 => not a local type / name
3920 * positive return => type or name is local to some
3921 * block or function.
c5aa993b 3922 */
c906108c
SS
3923
3924
3925/* elz: ATTENTION: FIXME: NOTE: WARNING!!!!
3926 this function now returns 0 right away. It was taking too much time
3927 at start up. Now, though, the local types are not handled correctly.
c5aa993b 3928 */
c906108c
SS
3929
3930
3931static int
3932hpread_get_scope_depth (dn_bufp, objfile, report_nested)
c5aa993b
JM
3933 union dnttentry *dn_bufp;
3934 struct objfile *objfile;
3935 int report_nested;
c906108c
SS
3936{
3937 register int index;
c5aa993b 3938 register union dnttentry *dn_tmp;
c906108c
SS
3939 register short depth = 0;
3940/****************************/
3941 return 0;
3942/****************************/
3943
3944 index = (((char *) dn_bufp) - LNTT (objfile)) / (sizeof (struct dntt_type_block));
c5aa993b 3945
c906108c
SS
3946 while (--index >= 0)
3947 {
3948 dn_tmp = hpread_get_lntt (index, objfile);
3949 switch (dn_tmp->dblock.kind)
c5aa993b
JM
3950 {
3951 case DNTT_TYPE_MODULE:
3952 return depth;
3953 case DNTT_TYPE_END:
3954 /* index is signed int; dnttp.index is 29-bit unsigned int! */
3955 index = (int) dn_tmp->dend.beginscope.dnttp.index;
3956 break;
3957 case DNTT_TYPE_BEGIN:
3958 case DNTT_TYPE_FUNCTION:
3959 case DNTT_TYPE_DOC_FUNCTION:
3960 case DNTT_TYPE_WITH:
3961 case DNTT_TYPE_COMMON:
3962 case DNTT_TYPE_CLASS_SCOPE:
3963 depth++;
3964 if (report_nested)
3965 return 1;
3966 break;
3967 default:
3968 break;
3969 }
c906108c
SS
3970 }
3971 return depth;
3972}
3973
3974/* Adjust the bitoffsets for all fields of an anonymous union of
3975 type TYPE by negative BITS. This handles HP aCC's hideous habit
3976 of giving members of anonymous unions bit offsets relative to the
c5aa993b 3977 enclosing structure instead of relative to the union itself. */
c906108c
SS
3978
3979static void
3980hpread_adjust_bitoffsets (type, bits)
c5aa993b
JM
3981 struct type *type;
3982 int bits;
c906108c
SS
3983{
3984 register int i;
3985
3986 /* This is done only for unions; caller had better check that
c5aa993b 3987 it is an anonymous one. */
c906108c
SS
3988 if (TYPE_CODE (type) != TYPE_CODE_UNION)
3989 return;
3990
3991 /* Adjust each field; since this is a union, there are no base
3992 classes. Also no static membes. Also, no need for recursion as
3993 the members of this union if themeselves structs or unions, have
3994 the correct bitoffsets; if an anonymous union is a member of this
3995 anonymous union, the code in hpread_read_struct_type() will
3996 adjust for that. */
3997
3998 for (i = 0; i < TYPE_NFIELDS (type); i++)
3999 TYPE_FIELD_BITPOS (type, i) -= bits;
4000}
4001
4002/* Because of quirks in HP compilers' treatment of anonymous unions inside
4003 classes, we have to chase through a chain of threaded FIELD entries.
4004 If we encounter an anonymous union in the chain, we must recursively skip over
4005 that too.
4006
4007 This function does a "next" in the chain of FIELD entries, but transparently
4008 skips over anonymous unions' fields (recursively).
c5aa993b 4009
c906108c
SS
4010 Inputs are the number of times to do "next" at the top level, the dnttpointer
4011 (FIELD) and entry pointer (FIELDP) for the dntt record corresponding to it,
4012 and the ubiquitous objfile parameter. (Note: FIELDP is a **.) Return value
4013 is a dnttpointer for the new field after all the skipped ones */
4014
4015static dnttpointer
4016hpread_get_next_skip_over_anon_unions (skip_fields, field, fieldp, objfile)
c5aa993b
JM
4017 int skip_fields;
4018 dnttpointer field;
4019 union dnttentry **fieldp;
4020 struct objfile *objfile;
c906108c 4021{
c5aa993b 4022 struct type *anon_type;
c906108c
SS
4023 register int i;
4024 int bitoffset;
c5aa993b 4025 char *name;
c906108c 4026
c5aa993b 4027 for (i = 0; i < skip_fields; i++)
c906108c
SS
4028 {
4029 /* Get type of item we're looking at now; recursively processes the types
4030 of these intermediate items we skip over, so they aren't lost. */
4031 anon_type = hpread_type_lookup ((*fieldp)->dfield.type, objfile);
4032 anon_type = CHECK_TYPEDEF (anon_type);
4033 bitoffset = (*fieldp)->dfield.bitoffset;
4034 name = VT (objfile) + (*fieldp)->dfield.name;
c5aa993b 4035 /* First skip over one item to avoid stack death on recursion */
c906108c
SS
4036 field = (*fieldp)->dfield.nextfield;
4037 *fieldp = hpread_get_lntt (field.dnttp.index, objfile);
4038 /* Do we have another anonymous union? If so, adjust the bitoffsets
4039 of its members and skip over its members. */
4040 if ((TYPE_CODE (anon_type) == TYPE_CODE_UNION) &&
c5aa993b
JM
4041 (!name || STREQ (name, "")))
4042 {
4043 hpread_adjust_bitoffsets (anon_type, bitoffset);
4044 field = hpread_get_next_skip_over_anon_unions (TYPE_NFIELDS (anon_type), field, fieldp, objfile);
4045 }
c906108c
SS
4046 }
4047 return field;
4048}