OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [hp-symtab-read.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.