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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [hpread.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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