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