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