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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* Read hp debug symbols and convert to internal format, for GDB.
2
   Copyright 1993, 1996 Free Software Foundation, Inc.
3
 
4
   This file is part of GDB.
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
 
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 59 Temple Place - Suite 330,
19
   Boston, MA 02111-1307, USA.
20
 
21
   Written by the Center for Software Science at the University of Utah
22
   and by Cygnus Support.  */
23
 
24
#include "defs.h"
25
#include "bfd.h"
26
#include "gdb_string.h"
27
#include "hp-symtab.h"
28
#include "syms.h"
29
#include "symtab.h"
30
#include "symfile.h"
31
#include "objfiles.h"
32
#include "buildsym.h"
33
#include "complaints.h"
34
#include "gdb-stabs.h"
35
#include "gdbtypes.h"
36
#include "demangle.h"
37
 
38
/* Private information attached to an objfile which we use to find
39
   and internalize the HP C debug symbols within that objfile.  */
40
 
41
struct hpread_symfile_info
42
  {
43
    /* The contents of each of the debug sections (there are 4 of them).  */
44
    char *gntt;
45
    char *lntt;
46
    char *slt;
47
    char *vt;
48
 
49
    /* We keep the size of the $VT$ section for range checking.  */
50
    unsigned int vt_size;
51
 
52
    /* Some routines still need to know the number of symbols in the
53
       main debug sections ($LNTT$ and $GNTT$). */
54
    unsigned int lntt_symcount;
55
    unsigned int gntt_symcount;
56
 
57
    /* To keep track of all the types we've processed.  */
58
    struct type **type_vector;
59
    int type_vector_length;
60
 
61
    /* Keeps track of the beginning of a range of source lines.  */
62
    sltpointer sl_index;
63
 
64
    /* Some state variables we'll need.  */
65
    int within_function;
66
 
67
    /* Keep track of the current function's address.  We may need to look
68
       up something based on this address.  */
69
    unsigned int current_function_value;
70
  };
71
 
72
/* Accessor macros to get at the fields.  */
73
#define HPUX_SYMFILE_INFO(o) \
74
  ((struct hpread_symfile_info *)((o)->sym_private))
75
#define GNTT(o)                 (HPUX_SYMFILE_INFO(o)->gntt)
76
#define LNTT(o)                 (HPUX_SYMFILE_INFO(o)->lntt)
77
#define SLT(o)                  (HPUX_SYMFILE_INFO(o)->slt)
78
#define VT(o)                   (HPUX_SYMFILE_INFO(o)->vt)
79
#define VT_SIZE(o)              (HPUX_SYMFILE_INFO(o)->vt_size)
80
#define LNTT_SYMCOUNT(o)        (HPUX_SYMFILE_INFO(o)->lntt_symcount)
81
#define GNTT_SYMCOUNT(o)        (HPUX_SYMFILE_INFO(o)->gntt_symcount)
82
#define TYPE_VECTOR(o)          (HPUX_SYMFILE_INFO(o)->type_vector)
83
#define TYPE_VECTOR_LENGTH(o)   (HPUX_SYMFILE_INFO(o)->type_vector_length)
84
#define SL_INDEX(o)             (HPUX_SYMFILE_INFO(o)->sl_index)
85
#define WITHIN_FUNCTION(o)      (HPUX_SYMFILE_INFO(o)->within_function)
86
#define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
87
 
88
/* Given the native debug symbol SYM, set NAMEP to the name associated
89
   with the debug symbol.  Note we may be called with a debug symbol which
90
   has no associated name, in that case we return an empty string.
91
 
92
   Also note we "know" that the name for any symbol is always in the
93
   same place.  Hence we don't have to conditionalize on the symbol type.  */
94
#define SET_NAMESTRING(SYM, NAMEP, OBJFILE) \
95
  if (! hpread_has_name ((SYM)->dblock.kind)) \
96
    *NAMEP = ""; \
97
  else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
98
    { \
99
      complain (&string_table_offset_complaint, (char *) symnum); \
100
      *NAMEP = ""; \
101
    } \
102
  else \
103
    *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
104
 
105
/* We put a pointer to this structure in the read_symtab_private field
106
   of the psymtab.  */
107
 
108
struct symloc
109
  {
110
    /* The offset within the file symbol table of first local symbol for
111
       this file.  */
112
 
113
    int ldsymoff;
114
 
115
    /* Length (in bytes) of the section of the symbol table devoted to
116
       this file's symbols (actually, the section bracketed may contain
117
       more than just this file's symbols).  If ldsymlen is 0, the only
118
       reason for this thing's existence is the dependency list.
119
       Nothing else will happen when it is read in.  */
120
 
121
    int ldsymlen;
122
  };
123
 
124
#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
125
#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
126
#define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
127
 
128
/* FIXME: Shouldn't this stuff be in a .h file somewhere?  */
129
/* Nonzero means give verbose info on gdb action.  */
130
extern int info_verbose;
131
 
132
/* Complaints about the symbols we have encountered.  */
133
extern struct complaint string_table_offset_complaint;
134
extern struct complaint lbrac_unmatched_complaint;
135
extern struct complaint lbrac_mismatch_complaint;
136
 
137
 
138
void hpread_symfile_init PARAMS ((struct objfile *));
139
 
140
static struct type *
141
  hpread_read_array_type PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
142
 
143
static struct type *hpread_alloc_type
144
  PARAMS ((dnttpointer, struct objfile *));
145
 
146
static struct type **hpread_lookup_type
147
  PARAMS ((dnttpointer, struct objfile *));
148
 
149
static struct type *hpread_read_enum_type
150
  PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
151
 
152
static struct type *hpread_read_set_type
153
  PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
154
 
155
static struct type *hpread_read_subrange_type
156
  PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
157
 
158
static struct type *hpread_read_struct_type
159
  PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
160
 
161
void hpread_build_psymtabs
162
  PARAMS ((struct objfile *, int));
163
 
164
void hpread_symfile_finish PARAMS ((struct objfile *));
165
 
166
static struct partial_symtab *hpread_start_psymtab
167
  PARAMS ((struct objfile *, char *, CORE_ADDR, int,
168
           struct partial_symbol **, struct partial_symbol **));
169
 
170
static struct partial_symtab *hpread_end_psymtab
171
  PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
172
           struct partial_symtab **, int));
173
 
174
static struct symtab *hpread_expand_symtab
175
  PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
176
           struct section_offsets *, char *));
177
 
178
static void hpread_process_one_debug_symbol
179
  PARAMS ((union dnttentry *, char *, struct section_offsets *,
180
           struct objfile *, CORE_ADDR, int, char *, int));
181
 
182
static sltpointer hpread_record_lines
183
  PARAMS ((struct subfile *, sltpointer, sltpointer,
184
           struct objfile *, CORE_ADDR));
185
 
186
static struct type *hpread_read_function_type
187
  PARAMS ((dnttpointer, union dnttentry *, struct objfile *));
188
 
189
static struct type *hpread_type_lookup
190
  PARAMS ((dnttpointer, struct objfile *));
191
 
192
static unsigned long hpread_get_depth
193
  PARAMS ((sltpointer, struct objfile *));
194
 
195
static unsigned long hpread_get_line
196
  PARAMS ((sltpointer, struct objfile *));
197
 
198
static CORE_ADDR hpread_get_location
199
  PARAMS ((sltpointer, struct objfile *));
200
 
201
static int hpread_type_translate PARAMS ((dnttpointer));
202
static unsigned long hpread_get_textlow PARAMS ((int, int, struct objfile *));
203
static union dnttentry *hpread_get_gntt PARAMS ((int, struct objfile *));
204
static union dnttentry *hpread_get_lntt PARAMS ((int, struct objfile *));
205
static union sltentry *hpread_get_slt PARAMS ((int, struct objfile *));
206
static void hpread_psymtab_to_symtab PARAMS ((struct partial_symtab *));
207
static void hpread_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
208
static int hpread_has_name PARAMS ((enum dntt_entry_type));
209
 
210
 
211
/* Initialization for reading native HP C debug symbols from OBJFILE.
212
 
213
   It's only purpose in life is to set up the symbol reader's private
214
   per-objfile data structures, and read in the raw contents of the debug
215
   sections (attaching pointers to the debug info into the private data
216
   structures).
217
 
218
   Since BFD doesn't know how to read debug symbols in a format-independent
219
   way (and may never do so...), we have to do it ourselves.  Note we may
220
   be called on a file without native HP C debugging symbols.
221
   FIXME, there should be a cleaner peephole into the BFD environment here.  */
222
 
223
void
224
hpread_symfile_init (objfile)
225
     struct objfile *objfile;
226
{
227
  asection *vt_section, *slt_section, *lntt_section, *gntt_section;
228
 
229
  /* Allocate struct to keep track of the symfile */
230
  objfile->sym_private = (PTR)
231
    xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
232
  memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
233
 
234
  /* We haven't read in any types yet.  */
235
  TYPE_VECTOR (objfile) = 0;
236
 
237
  /* Read in data from the $GNTT$ subspace.  */
238
  gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
239
  if (!gntt_section)
240
    return;
241
 
242
  GNTT (objfile)
243
    = obstack_alloc (&objfile->symbol_obstack,
244
                     bfd_section_size (objfile->obfd, gntt_section));
245
 
246
  bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
247
                         0, bfd_section_size (objfile->obfd, gntt_section));
248
 
249
  GNTT_SYMCOUNT (objfile)
250
    = bfd_section_size (objfile->obfd, gntt_section)
251
    / sizeof (struct dntt_type_block);
252
 
253
  /* Read in data from the $LNTT$ subspace.   Also keep track of the number
254
     of LNTT symbols.  */
255
  lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
256
  if (!lntt_section)
257
    return;
258
 
259
  LNTT (objfile)
260
    = obstack_alloc (&objfile->symbol_obstack,
261
                     bfd_section_size (objfile->obfd, lntt_section));
262
 
263
  bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
264
                         0, bfd_section_size (objfile->obfd, lntt_section));
265
 
266
  LNTT_SYMCOUNT (objfile)
267
    = bfd_section_size (objfile->obfd, lntt_section)
268
    / sizeof (struct dntt_type_block);
269
 
270
  /* Read in data from the $SLT$ subspace.  $SLT$ contains information
271
     on source line numbers.  */
272
  slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
273
  if (!slt_section)
274
    return;
275
 
276
  SLT (objfile) =
277
    obstack_alloc (&objfile->symbol_obstack,
278
                   bfd_section_size (objfile->obfd, slt_section));
279
 
280
  bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
281
                          0, bfd_section_size (objfile->obfd, slt_section));
282
 
283
  /* Read in data from the $VT$ subspace.  $VT$ contains things like
284
     names and constants.  Keep track of the number of symbols in the VT.  */
285
  vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
286
  if (!vt_section)
287
    return;
288
 
289
  VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
290
 
291
  VT (objfile) =
292
    (char *) obstack_alloc (&objfile->symbol_obstack,
293
                            VT_SIZE (objfile));
294
 
295
  bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
296
                            0, VT_SIZE (objfile));
297
}
298
 
299
/* Scan and build partial symbols for a symbol file.
300
 
301
   The minimal symbol table (either SOM or HP a.out) has already been
302
   read in; all we need to do is setup partial symbols based on the
303
   native debugging information.
304
 
305
   We assume hpread_symfile_init has been called to initialize the
306
   symbol reader's private data structures.
307
 
308
   MAINLINE is true if we are reading the main symbol
309
   table (as opposed to a shared lib or dynamically loaded file).  */
310
 
311
void
312
hpread_build_psymtabs (objfile, mainline)
313
     struct objfile *objfile;
314
     int mainline;
315
{
316
  char *namestring;
317
  int past_first_source_file = 0;
318
  struct cleanup *old_chain;
319
 
320
  int hp_symnum, symcount, i;
321
 
322
  union dnttentry *dn_bufp;
323
  unsigned long valu;
324
  char *p;
325
  int texthigh = 0;
326
  int have_name = 0;
327
 
328
  /* Current partial symtab */
329
  struct partial_symtab *pst;
330
 
331
  /* List of current psymtab's include files */
332
  char **psymtab_include_list;
333
  int includes_allocated;
334
  int includes_used;
335
 
336
  /* Index within current psymtab dependency list */
337
  struct partial_symtab **dependency_list;
338
  int dependencies_used, dependencies_allocated;
339
 
340
  /* Just in case the stabs reader left turds lying around.  */
341
  free_pending_blocks ();
342
  make_cleanup (really_free_pendings, 0);
343
 
344
  pst = (struct partial_symtab *) 0;
345
 
346
  /* We shouldn't use alloca, instead use malloc/free.  Doing so avoids
347
     a number of problems with cross compilation and creating useless holes
348
     in the stack when we have to allocate new entries.  FIXME.  */
349
 
350
  includes_allocated = 30;
351
  includes_used = 0;
352
  psymtab_include_list = (char **) alloca (includes_allocated *
353
                                           sizeof (char *));
354
 
355
  dependencies_allocated = 30;
356
  dependencies_used = 0;
357
  dependency_list =
358
    (struct partial_symtab **) alloca (dependencies_allocated *
359
                                       sizeof (struct partial_symtab *));
360
 
361
  old_chain = make_cleanup (free_objfile, objfile);
362
 
363
  last_source_file = 0;
364
 
365
  /* Make two passes, one ofr the GNTT symbols, the other for the
366
     LNTT symbols.  */
367
  for (i = 0; i < 1; i++)
368
    {
369
      int within_function = 0;
370
 
371
      if (i)
372
        symcount = GNTT_SYMCOUNT (objfile);
373
      else
374
        symcount = LNTT_SYMCOUNT (objfile);
375
 
376
      for (hp_symnum = 0; hp_symnum < symcount; hp_symnum++)
377
        {
378
          QUIT;
379
          if (i)
380
            dn_bufp = hpread_get_gntt (hp_symnum, objfile);
381
          else
382
            dn_bufp = hpread_get_lntt (hp_symnum, objfile);
383
 
384
          if (dn_bufp->dblock.extension)
385
            continue;
386
 
387
          /* Only handle things which are necessary for minimal symbols.
388
             everything else is ignored.  */
389
          switch (dn_bufp->dblock.kind)
390
            {
391
            case DNTT_TYPE_SRCFILE:
392
              {
393
                /* A source file of some kind.  Note this may simply
394
                   be an included file.  */
395
                SET_NAMESTRING (dn_bufp, &namestring, objfile);
396
 
397
                /* Check if this is the source file we are already working
398
                   with.  */
399
                if (pst && !strcmp (namestring, pst->filename))
400
                  continue;
401
 
402
                /* Check if this is an include file, if so check if we have
403
                   already seen it.  Add it to the include list */
404
                p = strrchr (namestring, '.');
405
                if (!strcmp (p, ".h"))
406
                  {
407
                    int j, found;
408
 
409
                    found = 0;
410
                    for (j = 0; j < includes_used; j++)
411
                      if (!strcmp (namestring, psymtab_include_list[j]))
412
                        {
413
                          found = 1;
414
                          break;
415
                        }
416
                    if (found)
417
                      continue;
418
 
419
                    /* Add it to the list of includes seen so far and
420
                       allocate more include space if necessary.  */
421
                    psymtab_include_list[includes_used++] = namestring;
422
                    if (includes_used >= includes_allocated)
423
                      {
424
                        char **orig = psymtab_include_list;
425
 
426
                        psymtab_include_list = (char **)
427
                          alloca ((includes_allocated *= 2) *
428
                                  sizeof (char *));
429
                        memcpy ((PTR) psymtab_include_list, (PTR) orig,
430
                                includes_used * sizeof (char *));
431
                      }
432
                    continue;
433
                  }
434
 
435
 
436
                if (pst)
437
                  {
438
                    if (!have_name)
439
                      {
440
                        pst->filename = (char *)
441
                          obstack_alloc (&pst->objfile->psymbol_obstack,
442
                                         strlen (namestring) + 1);
443
                        strcpy (pst->filename, namestring);
444
                        have_name = 1;
445
                        continue;
446
                      }
447
                    continue;
448
                  }
449
 
450
                /* This is a bonafide new source file.
451
                   End the current partial symtab and start a new one.  */
452
 
453
                if (pst && past_first_source_file)
454
                  {
455
                    hpread_end_psymtab (pst, psymtab_include_list,
456
                                        includes_used,
457
                                        (hp_symnum
458
                                         * sizeof (struct dntt_type_block)),
459
                                        texthigh,
460
                                        dependency_list, dependencies_used);
461
                    pst = (struct partial_symtab *) 0;
462
                    includes_used = 0;
463
                    dependencies_used = 0;
464
                  }
465
                else
466
                  past_first_source_file = 1;
467
 
468
                valu = hpread_get_textlow (i, hp_symnum, objfile);
469
                valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
470
                pst = hpread_start_psymtab (objfile,
471
                                            namestring, valu,
472
                                            (hp_symnum
473
                                         * sizeof (struct dntt_type_block)),
474
                                            objfile->global_psymbols.next,
475
                                            objfile->static_psymbols.next);
476
                texthigh = valu;
477
                have_name = 1;
478
                continue;
479
              }
480
 
481
            case DNTT_TYPE_MODULE:
482
              /* A source file.  It's still unclear to me what the
483
                 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
484
                 is supposed to be.  */
485
              SET_NAMESTRING (dn_bufp, &namestring, objfile);
486
              valu = hpread_get_textlow (i, hp_symnum, objfile);
487
              valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
488
              if (!pst)
489
                {
490
                  pst = hpread_start_psymtab (objfile,
491
                                              namestring, valu,
492
                                              (hp_symnum
493
                                         * sizeof (struct dntt_type_block)),
494
                                              objfile->global_psymbols.next,
495
                                              objfile->static_psymbols.next);
496
                  texthigh = valu;
497
                  have_name = 0;
498
                }
499
              continue;
500
            case DNTT_TYPE_FUNCTION:
501
            case DNTT_TYPE_ENTRY:
502
              /* The beginning of a function.  DNTT_TYPE_ENTRY may also denote
503
                 a secondary entry point.  */
504
              valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets,
505
                                                       SECT_OFF_TEXT);
506
              if (valu > texthigh)
507
                texthigh = valu;
508
              valu = dn_bufp->dfunc.lowaddr +
509
                ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
510
              SET_NAMESTRING (dn_bufp, &namestring, objfile);
511
              add_psymbol_to_list (namestring, strlen (namestring),
512
                                   VAR_NAMESPACE, LOC_BLOCK,
513
                                   &objfile->static_psymbols, valu,
514
                                   0, language_unknown, objfile);
515
              within_function = 1;
516
              continue;
517
            case DNTT_TYPE_BEGIN:
518
            case DNTT_TYPE_END:
519
              /* Scope block begin/end.  We only care about function
520
                 and file blocks right now.  */
521
              if (dn_bufp->dend.endkind == DNTT_TYPE_MODULE)
522
                {
523
                  hpread_end_psymtab (pst, psymtab_include_list, includes_used,
524
                                      (hp_symnum
525
                                       * sizeof (struct dntt_type_block)),
526
                                      texthigh,
527
                                      dependency_list, dependencies_used);
528
                  pst = (struct partial_symtab *) 0;
529
                  includes_used = 0;
530
                  dependencies_used = 0;
531
                  have_name = 0;
532
                }
533
              if (dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION)
534
                within_function = 0;
535
              continue;
536
            case DNTT_TYPE_SVAR:
537
            case DNTT_TYPE_DVAR:
538
            case DNTT_TYPE_TYPEDEF:
539
            case DNTT_TYPE_TAGDEF:
540
              {
541
                /* Variables, typedefs an the like.  */
542
                enum address_class storage;
543
                namespace_enum namespace;
544
 
545
                /* Don't add locals to the partial symbol table.  */
546
                if (within_function
547
                    && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
548
                        || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
549
                  continue;
550
 
551
                /* TAGDEFs go into the structure namespace.  */
552
                if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
553
                  namespace = STRUCT_NAMESPACE;
554
                else
555
                  namespace = VAR_NAMESPACE;
556
 
557
                /* What kind of "storage" does this use?  */
558
                if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
559
                  storage = LOC_STATIC;
560
                else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
561
                         && dn_bufp->ddvar.regvar)
562
                  storage = LOC_REGISTER;
563
                else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
564
                  storage = LOC_LOCAL;
565
                else
566
                  storage = LOC_UNDEF;
567
 
568
                SET_NAMESTRING (dn_bufp, &namestring, objfile);
569
                if (!pst)
570
                  {
571
                    pst = hpread_start_psymtab (objfile,
572
                                                "globals", 0,
573
                                                (hp_symnum
574
                                         * sizeof (struct dntt_type_block)),
575
                                              objfile->global_psymbols.next,
576
                                             objfile->static_psymbols.next);
577
                  }
578
                if (dn_bufp->dsvar.global)
579
                  {
580
                    add_psymbol_to_list (namestring, strlen (namestring),
581
                                         namespace, storage,
582
                                         &objfile->global_psymbols,
583
                                         dn_bufp->dsvar.location,
584
                                         0, language_unknown, objfile);
585
                  }
586
                else
587
                  {
588
                    add_psymbol_to_list (namestring, strlen (namestring),
589
                                         namespace, storage,
590
                                         &objfile->static_psymbols,
591
                                         dn_bufp->dsvar.location,
592
                                         0, language_unknown, objfile);
593
                  }
594
                continue;
595
              }
596
            case DNTT_TYPE_MEMENUM:
597
            case DNTT_TYPE_CONST:
598
              /* Constants and members of enumerated types.  */
599
              SET_NAMESTRING (dn_bufp, &namestring, objfile);
600
              if (!pst)
601
                {
602
                  pst = hpread_start_psymtab (objfile,
603
                                              "globals", 0,
604
                                              (hp_symnum
605
                                         * sizeof (struct dntt_type_block)),
606
                                              objfile->global_psymbols.next,
607
                                              objfile->static_psymbols.next);
608
                }
609
              add_psymbol_to_list (namestring, strlen (namestring),
610
                                   VAR_NAMESPACE, LOC_CONST,
611
                                   &objfile->static_psymbols, 0,
612
                                   0, language_unknown, objfile);
613
              continue;
614
            default:
615
              continue;
616
            }
617
        }
618
    }
619
 
620
  /* End any pending partial symbol table.  */
621
  if (pst)
622
    {
623
      hpread_end_psymtab (pst, psymtab_include_list, includes_used,
624
                          hp_symnum * sizeof (struct dntt_type_block),
625
                          0, dependency_list, dependencies_used);
626
    }
627
 
628
  discard_cleanups (old_chain);
629
}
630
 
631
/* Perform any local cleanups required when we are done with a particular
632
   objfile.  I.E, we are in the process of discarding all symbol information
633
   for an objfile, freeing up all memory held for it, and unlinking the
634
   objfile struct from the global list of known objfiles. */
635
 
636
void
637
hpread_symfile_finish (objfile)
638
     struct objfile *objfile;
639
{
640
  if (objfile->sym_private != NULL)
641
    {
642
      mfree (objfile->md, objfile->sym_private);
643
    }
644
}
645
 
646
 
647
/* The remaining functions are all for internal use only.  */
648
 
649
/* Various small functions to get entries in the debug symbol sections.  */
650
 
651
static union dnttentry *
652
hpread_get_lntt (index, objfile)
653
     int index;
654
     struct objfile *objfile;
655
{
656
  return (union dnttentry *)
657
    &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
658
}
659
 
660
static union dnttentry *
661
hpread_get_gntt (index, objfile)
662
     int index;
663
     struct objfile *objfile;
664
{
665
  return (union dnttentry *)
666
    &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
667
}
668
 
669
static union sltentry *
670
hpread_get_slt (index, objfile)
671
     int index;
672
     struct objfile *objfile;
673
{
674
  return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
675
}
676
 
677
/* Get the low address associated with some symbol (typically the start
678
   of a particular source file or module).  Since that information is not
679
   stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
680
   the existance of DNTT_TYPE_FUNCTION symbols.  */
681
 
682
static unsigned long
683
hpread_get_textlow (global, index, objfile)
684
     int global;
685
     int index;
686
     struct objfile *objfile;
687
{
688
  union dnttentry *dn_bufp;
689
  struct minimal_symbol *msymbol;
690
 
691
  /* Look for a DNTT_TYPE_FUNCTION symbol.  */
692
  do
693
    {
694
      if (global)
695
        dn_bufp = hpread_get_gntt (index++, objfile);
696
      else
697
        dn_bufp = hpread_get_lntt (index++, objfile);
698
    }
699
  while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
700
         && dn_bufp->dblock.kind != DNTT_TYPE_END);
701
 
702
  /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION.  This
703
     might happen when a sourcefile has no functions.  */
704
  if (dn_bufp->dblock.kind == DNTT_TYPE_END)
705
    return 0;
706
 
707
  /* The minimal symbols are typically more accurate for some reason.  */
708
  msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
709
                                   objfile);
710
  if (msymbol)
711
    return SYMBOL_VALUE_ADDRESS (msymbol);
712
  else
713
    return dn_bufp->dfunc.lowaddr;
714
}
715
 
716
/* Get the nesting depth for the source line identified by INDEX.  */
717
 
718
static unsigned long
719
hpread_get_depth (index, objfile)
720
     sltpointer index;
721
     struct objfile *objfile;
722
{
723
  union sltentry *sl_bufp;
724
 
725
  sl_bufp = hpread_get_slt (index, objfile);
726
  return sl_bufp->sspec.backptr.dnttp.index;
727
}
728
 
729
/* Get the source line number the the line identified by INDEX.  */
730
 
731
static unsigned long
732
hpread_get_line (index, objfile)
733
     sltpointer index;
734
     struct objfile *objfile;
735
{
736
  union sltentry *sl_bufp;
737
 
738
  sl_bufp = hpread_get_slt (index, objfile);
739
  return sl_bufp->snorm.line;
740
}
741
 
742
static CORE_ADDR
743
hpread_get_location (index, objfile)
744
     sltpointer index;
745
     struct objfile *objfile;
746
{
747
  union sltentry *sl_bufp;
748
  int i;
749
 
750
  /* code location of special sltentrys is determined from context */
751
  sl_bufp = hpread_get_slt (index, objfile);
752
 
753
  if (sl_bufp->snorm.sltdesc == SLT_END)
754
    {
755
      /* find previous normal sltentry and get address */
756
      for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
757
                   (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
758
        sl_bufp = hpread_get_slt (index - i, objfile);
759
      return sl_bufp->snorm.address;
760
    }
761
 
762
  /* find next normal sltentry and get address */
763
  for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) &&
764
               (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++)
765
    sl_bufp = hpread_get_slt (index + i, objfile);
766
  return sl_bufp->snorm.address;
767
}
768
 
769
 
770
/* Return 1 if an HP debug symbol of type KIND has a name associated with
771
   it, else return 0.  */
772
 
773
static int
774
hpread_has_name (kind)
775
     enum dntt_entry_type kind;
776
{
777
  switch (kind)
778
    {
779
    case DNTT_TYPE_SRCFILE:
780
    case DNTT_TYPE_MODULE:
781
    case DNTT_TYPE_FUNCTION:
782
    case DNTT_TYPE_ENTRY:
783
    case DNTT_TYPE_IMPORT:
784
    case DNTT_TYPE_LABEL:
785
    case DNTT_TYPE_FPARAM:
786
    case DNTT_TYPE_SVAR:
787
    case DNTT_TYPE_DVAR:
788
    case DNTT_TYPE_CONST:
789
    case DNTT_TYPE_TYPEDEF:
790
    case DNTT_TYPE_TAGDEF:
791
    case DNTT_TYPE_MEMENUM:
792
    case DNTT_TYPE_FIELD:
793
    case DNTT_TYPE_SA:
794
      return 1;
795
 
796
    case DNTT_TYPE_BEGIN:
797
    case DNTT_TYPE_END:
798
    case DNTT_TYPE_WITH:
799
    case DNTT_TYPE_COMMON:
800
    case DNTT_TYPE_POINTER:
801
    case DNTT_TYPE_ENUM:
802
    case DNTT_TYPE_SET:
803
    case DNTT_TYPE_SUBRANGE:
804
    case DNTT_TYPE_ARRAY:
805
    case DNTT_TYPE_STRUCT:
806
    case DNTT_TYPE_UNION:
807
    case DNTT_TYPE_VARIANT:
808
    case DNTT_TYPE_FILE:
809
    case DNTT_TYPE_FUNCTYPE:
810
    case DNTT_TYPE_COBSTRUCT:
811
    case DNTT_TYPE_XREF:
812
    case DNTT_TYPE_MACRO:
813
    default:
814
      return 0;
815
    }
816
}
817
 
818
/* Allocate and partially fill a partial symtab.  It will be
819
   completely filled at the end of the symbol list.
820
 
821
   SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
822
   is the address relative to which its symbols are (incremental) or 0
823
   (normal). */
824
 
825
static struct partial_symtab *
826
hpread_start_psymtab (objfile, filename, textlow, ldsymoff, global_syms,
827
                      static_syms)
828
     struct objfile *objfile;
829
     char *filename;
830
     CORE_ADDR textlow;
831
     int ldsymoff;
832
     struct partial_symbol **global_syms;
833
     struct partial_symbol **static_syms;
834
{
835
  struct partial_symtab *result =
836
  start_psymtab_common (objfile, section_offsets,
837
                        filename, textlow, global_syms, static_syms);
838
 
839
  result->read_symtab_private = (char *)
840
    obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
841
  LDSYMOFF (result) = ldsymoff;
842
  result->read_symtab = hpread_psymtab_to_symtab;
843
 
844
  return result;
845
}
846
 
847
 
848
/* Close off the current usage of PST.
849
   Returns PST or NULL if the partial symtab was empty and thrown away.
850
 
851
   FIXME:  List variables and peculiarities of same.  */
852
 
853
static struct partial_symtab *
854
hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
855
                    capping_text, dependency_list, number_dependencies)
856
     struct partial_symtab *pst;
857
     char **include_list;
858
     int num_includes;
859
     int capping_symbol_offset;
860
     CORE_ADDR capping_text;
861
     struct partial_symtab **dependency_list;
862
     int number_dependencies;
863
{
864
  int i;
865
  struct objfile *objfile = pst->objfile;
866
 
867
  if (capping_symbol_offset != -1)
868
    LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
869
  pst->texthigh = capping_text;
870
 
871
  pst->n_global_syms =
872
    objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
873
  pst->n_static_syms =
874
    objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
875
 
876
  pst->number_of_dependencies = number_dependencies;
877
  if (number_dependencies)
878
    {
879
      pst->dependencies = (struct partial_symtab **)
880
        obstack_alloc (&objfile->psymbol_obstack,
881
                    number_dependencies * sizeof (struct partial_symtab *));
882
      memcpy (pst->dependencies, dependency_list,
883
              number_dependencies * sizeof (struct partial_symtab *));
884
    }
885
  else
886
    pst->dependencies = 0;
887
 
888
  for (i = 0; i < num_includes; i++)
889
    {
890
      struct partial_symtab *subpst =
891
      allocate_psymtab (include_list[i], objfile);
892
 
893
      subpst->section_offsets = pst->section_offsets;
894
      subpst->read_symtab_private =
895
        (char *) obstack_alloc (&objfile->psymbol_obstack,
896
                                sizeof (struct symloc));
897
      LDSYMOFF (subpst) =
898
        LDSYMLEN (subpst) =
899
        subpst->textlow =
900
        subpst->texthigh = 0;
901
 
902
      /* We could save slight bits of space by only making one of these,
903
         shared by the entire set of include files.  FIXME-someday.  */
904
      subpst->dependencies = (struct partial_symtab **)
905
        obstack_alloc (&objfile->psymbol_obstack,
906
                       sizeof (struct partial_symtab *));
907
      subpst->dependencies[0] = pst;
908
      subpst->number_of_dependencies = 1;
909
 
910
      subpst->globals_offset =
911
        subpst->n_global_syms =
912
        subpst->statics_offset =
913
        subpst->n_static_syms = 0;
914
 
915
      subpst->readin = 0;
916
      subpst->symtab = 0;
917
      subpst->read_symtab = pst->read_symtab;
918
    }
919
 
920
  sort_pst_symbols (pst);
921
 
922
  /* If there is already a psymtab or symtab for a file of this name, remove it.
923
     (If there is a symtab, more drastic things also happen.)
924
     This happens in VxWorks.  */
925
  free_named_symtabs (pst->filename);
926
 
927
  if (num_includes == 0
928
      && number_dependencies == 0
929
      && pst->n_global_syms == 0
930
      && pst->n_static_syms == 0)
931
    {
932
      /* Throw away this psymtab, it's empty.  We can't deallocate it, since
933
         it is on the obstack, but we can forget to chain it on the list.  */
934
      /* Empty psymtabs happen as a result of header files which don't have
935
         any symbols in them.  There can be a lot of them.  But this check
936
         is wrong, in that a psymtab with N_SLINE entries but nothing else
937
         is not empty, but we don't realize that.  Fixing that without slowing
938
         things down might be tricky.  */
939
 
940
      discard_psymtab (pst);
941
 
942
      /* Indicate that psymtab was thrown away.  */
943
      pst = (struct partial_symtab *) NULL;
944
    }
945
  return pst;
946
}
947
 
948
/* Do the dirty work of reading in the full symbol from a partial symbol
949
   table.  */
950
 
951
static void
952
hpread_psymtab_to_symtab_1 (pst)
953
     struct partial_symtab *pst;
954
{
955
  struct cleanup *old_chain;
956
  int i;
957
 
958
  /* Get out quick if passed junk.  */
959
  if (!pst)
960
    return;
961
 
962
  /* Complain if we've already read in this symbol table.  */
963
  if (pst->readin)
964
    {
965
      fprintf (stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
966
               pst->filename);
967
      return;
968
    }
969
 
970
  /* Read in all partial symtabs on which this one is dependent */
971
  for (i = 0; i < pst->number_of_dependencies; i++)
972
    if (!pst->dependencies[i]->readin)
973
      {
974
        /* Inform about additional files that need to be read in.  */
975
        if (info_verbose)
976
          {
977
            fputs_filtered (" ", gdb_stdout);
978
            wrap_here ("");
979
            fputs_filtered ("and ", gdb_stdout);
980
            wrap_here ("");
981
            printf_filtered ("%s...", pst->dependencies[i]->filename);
982
            wrap_here ("");     /* Flush output */
983
            gdb_flush (gdb_stdout);
984
          }
985
        hpread_psymtab_to_symtab_1 (pst->dependencies[i]);
986
      }
987
 
988
  /* If it's real...  */
989
  if (LDSYMLEN (pst))
990
    {
991
      /* Init stuff necessary for reading in symbols */
992
      buildsym_init ();
993
      old_chain = make_cleanup (really_free_pendings, 0);
994
 
995
      pst->symtab =
996
        hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst),
997
                              pst->textlow, pst->texthigh - pst->textlow,
998
                              pst->section_offsets, pst->filename);
999
      sort_symtab_syms (pst->symtab);
1000
 
1001
      do_cleanups (old_chain);
1002
    }
1003
 
1004
  pst->readin = 1;
1005
}
1006
 
1007
/* Read in all of the symbols for a given psymtab for real.
1008
   Be verbose about it if the user wants that.  */
1009
 
1010
static void
1011
hpread_psymtab_to_symtab (pst)
1012
     struct partial_symtab *pst;
1013
{
1014
  /* Get out quick if given junk.  */
1015
  if (!pst)
1016
    return;
1017
 
1018
  /* Sanity check.  */
1019
  if (pst->readin)
1020
    {
1021
      fprintf (stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1022
               pst->filename);
1023
      return;
1024
    }
1025
 
1026
  if (LDSYMLEN (pst) || pst->number_of_dependencies)
1027
    {
1028
      /* Print the message now, before reading the string table,
1029
         to avoid disconcerting pauses.  */
1030
      if (info_verbose)
1031
        {
1032
          printf_filtered ("Reading in symbols for %s...", pst->filename);
1033
          gdb_flush (gdb_stdout);
1034
        }
1035
 
1036
      hpread_psymtab_to_symtab_1 (pst);
1037
 
1038
      /* Match with global symbols.  This only needs to be done once,
1039
         after all of the symtabs and dependencies have been read in.   */
1040
      scan_file_globals (pst->objfile);
1041
 
1042
      /* Finish up the debug error message.  */
1043
      if (info_verbose)
1044
        printf_filtered ("done.\n");
1045
    }
1046
}
1047
/* Read in a defined section of a specific object file's symbols.
1048
 
1049
   DESC is the file descriptor for the file, positioned at the
1050
   beginning of the symtab
1051
   SYM_OFFSET is the offset within the file of
1052
   the beginning of the symbols we want to read
1053
   SYM_SIZE is the size of the symbol info to read in.
1054
   TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1055
   TEXT_SIZE is the size of the text segment read in.
1056
   SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1057
 
1058
static struct symtab *
1059
hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
1060
                      section_offsets, filename)
1061
     struct objfile *objfile;
1062
     int sym_offset;
1063
     int sym_size;
1064
     CORE_ADDR text_offset;
1065
     int text_size;
1066
     struct section_offsets *section_offsets;
1067
     char *filename;
1068
{
1069
  char *namestring;
1070
  union dnttentry *dn_bufp;
1071
  unsigned max_symnum;
1072
 
1073
  int sym_index = sym_offset / sizeof (struct dntt_type_block);
1074
 
1075
  current_objfile = objfile;
1076
  subfile_stack = 0;
1077
 
1078
  last_source_file = 0;
1079
 
1080
  dn_bufp = hpread_get_lntt (sym_index, objfile);
1081
  if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) ||
1082
        (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE)))
1083
    {
1084
      start_symtab ("globals", NULL, 0);
1085
      record_debugformat ("HP");
1086
    }
1087
 
1088
  max_symnum = sym_size / sizeof (struct dntt_type_block);
1089
 
1090
  /* Read in and process each debug symbol within the specified range.  */
1091
  for (symnum = 0;
1092
       symnum < max_symnum;
1093
       symnum++)
1094
    {
1095
      QUIT;                     /* Allow this to be interruptable */
1096
      dn_bufp = hpread_get_lntt (sym_index + symnum, objfile);
1097
 
1098
      if (dn_bufp->dblock.extension)
1099
        continue;
1100
 
1101
      /* Yow!  We call SET_NAMESTRING on things without names!  */
1102
      SET_NAMESTRING (dn_bufp, &namestring, objfile);
1103
 
1104
      hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets,
1105
                                       objfile, text_offset, text_size,
1106
                                       filename, symnum + sym_index);
1107
    }
1108
 
1109
  current_objfile = NULL;
1110
 
1111
  return end_symtab (text_offset + text_size, objfile, 0);
1112
}
1113
 
1114
 
1115
/* Convert basic types from HP debug format into GDB internal format.  */
1116
 
1117
static int
1118
hpread_type_translate (typep)
1119
     dnttpointer typep;
1120
{
1121
  if (!typep.dntti.immediate)
1122
    abort ();
1123
 
1124
  switch (typep.dntti.type)
1125
    {
1126
    case HP_TYPE_BOOLEAN:
1127
    case HP_TYPE_BOOLEAN_S300_COMPAT:
1128
    case HP_TYPE_BOOLEAN_VAX_COMPAT:
1129
      return FT_BOOLEAN;
1130
      /* Ugh.  No way to distinguish between signed and unsigned chars.  */
1131
    case HP_TYPE_CHAR:
1132
    case HP_TYPE_WIDE_CHAR:
1133
      return FT_CHAR;
1134
    case HP_TYPE_INT:
1135
      if (typep.dntti.bitlength <= 8)
1136
        return FT_CHAR;
1137
      if (typep.dntti.bitlength <= 16)
1138
        return FT_SHORT;
1139
      if (typep.dntti.bitlength <= 32)
1140
        return FT_INTEGER;
1141
      return FT_LONG_LONG;
1142
    case HP_TYPE_LONG:
1143
      return FT_LONG;
1144
    case HP_TYPE_UNSIGNED_LONG:
1145
      if (typep.dntti.bitlength <= 8)
1146
        return FT_UNSIGNED_CHAR;
1147
      if (typep.dntti.bitlength <= 16)
1148
        return FT_UNSIGNED_SHORT;
1149
      if (typep.dntti.bitlength <= 32)
1150
        return FT_UNSIGNED_LONG;
1151
      return FT_UNSIGNED_LONG_LONG;
1152
    case HP_TYPE_UNSIGNED_INT:
1153
      if (typep.dntti.bitlength <= 8)
1154
        return FT_UNSIGNED_CHAR;
1155
      if (typep.dntti.bitlength <= 16)
1156
        return FT_UNSIGNED_SHORT;
1157
      if (typep.dntti.bitlength <= 32)
1158
        return FT_UNSIGNED_INTEGER;
1159
      return FT_UNSIGNED_LONG_LONG;
1160
    case HP_TYPE_REAL:
1161
    case HP_TYPE_REAL_3000:
1162
    case HP_TYPE_DOUBLE:
1163
      if (typep.dntti.bitlength == 64)
1164
        return FT_DBL_PREC_FLOAT;
1165
      if (typep.dntti.bitlength == 128)
1166
        return FT_EXT_PREC_FLOAT;
1167
      return FT_FLOAT;
1168
    case HP_TYPE_COMPLEX:
1169
    case HP_TYPE_COMPLEXS3000:
1170
      if (typep.dntti.bitlength == 128)
1171
        return FT_DBL_PREC_COMPLEX;
1172
      if (typep.dntti.bitlength == 192)
1173
        return FT_EXT_PREC_COMPLEX;
1174
      return FT_COMPLEX;
1175
    case HP_TYPE_STRING200:
1176
    case HP_TYPE_LONGSTRING200:
1177
    case HP_TYPE_FTN_STRING_SPEC:
1178
    case HP_TYPE_MOD_STRING_SPEC:
1179
    case HP_TYPE_MOD_STRING_3000:
1180
    case HP_TYPE_FTN_STRING_S300_COMPAT:
1181
    case HP_TYPE_FTN_STRING_VAX_COMPAT:
1182
      return FT_STRING;
1183
    default:
1184
      abort ();
1185
    }
1186
}
1187
 
1188
/* Return the type associated with the index found in HP_TYPE.  */
1189
 
1190
static struct type **
1191
hpread_lookup_type (hp_type, objfile)
1192
     dnttpointer hp_type;
1193
     struct objfile *objfile;
1194
{
1195
  unsigned old_len;
1196
  int index = hp_type.dnttp.index;
1197
 
1198
  if (hp_type.dntti.immediate)
1199
    return NULL;
1200
 
1201
  if (index < LNTT_SYMCOUNT (objfile))
1202
    {
1203
      if (index >= TYPE_VECTOR_LENGTH (objfile))
1204
        {
1205
          old_len = TYPE_VECTOR_LENGTH (objfile);
1206
          if (old_len == 0)
1207
            {
1208
              TYPE_VECTOR_LENGTH (objfile) = 100;
1209
              TYPE_VECTOR (objfile) = (struct type **)
1210
                xmmalloc (objfile->md,
1211
                     TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1212
            }
1213
          while (index >= TYPE_VECTOR_LENGTH (objfile))
1214
            TYPE_VECTOR_LENGTH (objfile) *= 2;
1215
          TYPE_VECTOR (objfile) = (struct type **)
1216
            xmrealloc (objfile->md,
1217
                       (char *) TYPE_VECTOR (objfile),
1218
                   (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1219
          memset (&TYPE_VECTOR (objfile)[old_len], 0,
1220
                  (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1221
                  sizeof (struct type *));
1222
        }
1223
      return &TYPE_VECTOR (objfile)[index];
1224
    }
1225
  else
1226
    return NULL;
1227
}
1228
 
1229
/* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1230
   Note we'll just return the address of a GDB internal type if we already
1231
   have it lying around.  */
1232
 
1233
static struct type *
1234
hpread_alloc_type (hp_type, objfile)
1235
     dnttpointer hp_type;
1236
     struct objfile *objfile;
1237
{
1238
  struct type **type_addr;
1239
 
1240
  type_addr = hpread_lookup_type (hp_type, objfile);
1241
  if (*type_addr == 0)
1242
    *type_addr = alloc_type (objfile);
1243
 
1244
  TYPE_CPLUS_SPECIFIC (*type_addr)
1245
    = (struct cplus_struct_type *) &cplus_struct_default;
1246
  return *type_addr;
1247
}
1248
 
1249
/* Read a native enumerated type and return it in GDB internal form.  */
1250
 
1251
static struct type *
1252
hpread_read_enum_type (hp_type, dn_bufp, objfile)
1253
     dnttpointer hp_type;
1254
     union dnttentry *dn_bufp;
1255
     struct objfile *objfile;
1256
{
1257
  struct type *type;
1258
  struct pending **symlist, *osyms, *syms;
1259
  int o_nsyms, nsyms = 0;
1260
  dnttpointer mem;
1261
  union dnttentry *memp;
1262
  char *name;
1263
  long n;
1264
  struct symbol *sym;
1265
 
1266
  type = hpread_alloc_type (hp_type, objfile);
1267
  TYPE_LENGTH (type) = 4;
1268
 
1269
  symlist = &file_symbols;
1270
  osyms = *symlist;
1271
  o_nsyms = osyms ? osyms->nsyms : 0;
1272
 
1273
  /* Get a name for each member and add it to our list of members.  */
1274
  mem = dn_bufp->denum.firstmem;
1275
  while (mem.dnttp.extension && mem.word != DNTTNIL)
1276
    {
1277
      memp = hpread_get_lntt (mem.dnttp.index, objfile);
1278
 
1279
      name = VT (objfile) + memp->dmember.name;
1280
      sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1281
                                             sizeof (struct symbol));
1282
      memset (sym, 0, sizeof (struct symbol));
1283
      SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1284
                                        &objfile->symbol_obstack);
1285
      SYMBOL_CLASS (sym) = LOC_CONST;
1286
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1287
      SYMBOL_VALUE (sym) = memp->dmember.value;
1288
      add_symbol_to_list (sym, symlist);
1289
      nsyms++;
1290
      mem = memp->dmember.nextmem;
1291
    }
1292
 
1293
  /* Now that we know more about the enum, fill in more info.  */
1294
  TYPE_CODE (type) = TYPE_CODE_ENUM;
1295
  TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1296
  TYPE_NFIELDS (type) = nsyms;
1297
  TYPE_FIELDS (type) = (struct field *)
1298
    obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1299
 
1300
  /* Find the symbols for the members and put them into the type.
1301
     The symbols can be found in the symlist that we put them on
1302
     to cause them to be defined.  osyms contains the old value
1303
     of that symlist; everything up to there was defined by us.
1304
 
1305
     Note that we preserve the order of the enum constants, so
1306
     that in something like "enum {FOO, LAST_THING=FOO}" we print
1307
     FOO, not LAST_THING.  */
1308
  for (syms = *symlist, n = 0; syms; syms = syms->next)
1309
    {
1310
      int j = 0;
1311
      if (syms == osyms)
1312
        j = o_nsyms;
1313
      for (; j < syms->nsyms; j++, n++)
1314
        {
1315
          struct symbol *xsym = syms->symbol[j];
1316
          SYMBOL_TYPE (xsym) = type;
1317
          TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1318
          TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1319
          TYPE_FIELD_BITSIZE (type, n) = 0;
1320
        }
1321
      if (syms == osyms)
1322
        break;
1323
    }
1324
 
1325
  return type;
1326
}
1327
 
1328
/* Read and internalize a native function debug symbol.  */
1329
 
1330
static struct type *
1331
hpread_read_function_type (hp_type, dn_bufp, objfile)
1332
     dnttpointer hp_type;
1333
     union dnttentry *dn_bufp;
1334
     struct objfile *objfile;
1335
{
1336
  struct type *type, *type1;
1337
  struct pending **symlist, *osyms, *syms;
1338
  int o_nsyms, nsyms = 0;
1339
  dnttpointer param;
1340
  union dnttentry *paramp;
1341
  char *name;
1342
  long n;
1343
  struct symbol *sym;
1344
 
1345
  param = dn_bufp->dfunc.firstparam;
1346
 
1347
  /* See if we've already read in this type.  */
1348
  type = hpread_alloc_type (hp_type, objfile);
1349
  if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1350
    return type;
1351
 
1352
  /* Nope, so read it in and store it away.  */
1353
  type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1354
                                                    objfile));
1355
  memcpy ((char *) type, (char *) type1, sizeof (struct type));
1356
 
1357
  symlist = &local_symbols;
1358
  osyms = *symlist;
1359
  o_nsyms = osyms ? osyms->nsyms : 0;
1360
 
1361
  /* Now examine each parameter noting its type, location, and a
1362
     wealth of other information.  */
1363
  while (param.word && param.word != DNTTNIL)
1364
    {
1365
      paramp = hpread_get_lntt (param.dnttp.index, objfile);
1366
      nsyms++;
1367
      param = paramp->dfparam.nextparam;
1368
 
1369
      /* Get the name.  */
1370
      name = VT (objfile) + paramp->dfparam.name;
1371
      sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1372
                                             sizeof (struct symbol));
1373
      (void) memset (sym, 0, sizeof (struct symbol));
1374
      SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1375
                                        &objfile->symbol_obstack);
1376
 
1377
      /* Figure out where it lives.  */
1378
      if (paramp->dfparam.regparam)
1379
        SYMBOL_CLASS (sym) = LOC_REGPARM;
1380
      else if (paramp->dfparam.indirect)
1381
        SYMBOL_CLASS (sym) = LOC_REF_ARG;
1382
      else
1383
        SYMBOL_CLASS (sym) = LOC_ARG;
1384
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1385
      if (paramp->dfparam.copyparam)
1386
        {
1387
          SYMBOL_VALUE (sym) = paramp->dfparam.location;
1388
#ifdef HPREAD_ADJUST_STACK_ADDRESS
1389
          SYMBOL_VALUE (sym)
1390
            += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1391
#endif
1392
          /* This is likely a pass-by-invisible reference parameter,
1393
             Hack on the symbol class to make GDB happy.  */
1394
          SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1395
        }
1396
      else
1397
        SYMBOL_VALUE (sym) = paramp->dfparam.location;
1398
 
1399
      /* Get its type.  */
1400
      SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1401
 
1402
      /* Add it to the list.  */
1403
      add_symbol_to_list (sym, symlist);
1404
    }
1405
 
1406
  /* Note how many parameters we found.  */
1407
  TYPE_NFIELDS (type) = nsyms;
1408
  TYPE_FIELDS (type) = (struct field *)
1409
    obstack_alloc (&objfile->type_obstack,
1410
                   sizeof (struct field) * nsyms);
1411
 
1412
  /* Find the symbols for the values and put them into the type.
1413
     The symbols can be found in the symlist that we put them on
1414
     to cause them to be defined.  osyms contains the old value
1415
     of that symlist; everything up to there was defined by us.  */
1416
  /* Note that we preserve the order of the parameters, so
1417
     that in something like "enum {FOO, LAST_THING=FOO}" we print
1418
     FOO, not LAST_THING.  */
1419
  for (syms = *symlist, n = 0; syms; syms = syms->next)
1420
    {
1421
      int j = 0;
1422
      if (syms == osyms)
1423
        j = o_nsyms;
1424
      for (; j < syms->nsyms; j++, n++)
1425
        {
1426
          struct symbol *xsym = syms->symbol[j];
1427
          TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1428
          TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1429
          TYPE_FIELD_BITPOS (type, n) = n;
1430
          TYPE_FIELD_BITSIZE (type, n) = 0;
1431
        }
1432
      if (syms == osyms)
1433
        break;
1434
    }
1435
  return type;
1436
}
1437
 
1438
/* Read in and internalize a structure definition.  */
1439
 
1440
static struct type *
1441
hpread_read_struct_type (hp_type, dn_bufp, objfile)
1442
     dnttpointer hp_type;
1443
     union dnttentry *dn_bufp;
1444
     struct objfile *objfile;
1445
{
1446
  struct nextfield
1447
    {
1448
      struct nextfield *next;
1449
      struct field field;
1450
    };
1451
 
1452
  struct type *type;
1453
  struct nextfield *list = 0;
1454
  struct nextfield *new;
1455
  int n, nfields = 0;
1456
  dnttpointer field;
1457
  union dnttentry *fieldp;
1458
 
1459
  /* Is it something we've already dealt with?  */
1460
  type = hpread_alloc_type (hp_type, objfile);
1461
  if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1462
      (TYPE_CODE (type) == TYPE_CODE_UNION))
1463
    return type;
1464
 
1465
  /* Get the basic type correct.  */
1466
  if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1467
    {
1468
      TYPE_CODE (type) = TYPE_CODE_STRUCT;
1469
      TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1470
    }
1471
  else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1472
    {
1473
      TYPE_CODE (type) = TYPE_CODE_UNION;
1474
      TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1475
    }
1476
  else
1477
    return type;
1478
 
1479
 
1480
  TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1481
 
1482
  /* Read in and internalize all the fields.  */
1483
  field = dn_bufp->dstruct.firstfield;
1484
  while (field.word != DNTTNIL && field.dnttp.extension)
1485
    {
1486
      fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1487
 
1488
      /* Get space to record the next field's data.  */
1489
      new = (struct nextfield *) alloca (sizeof (struct nextfield));
1490
      new->next = list;
1491
      list = new;
1492
 
1493
      list->field.name = VT (objfile) + fieldp->dfield.name;
1494
      FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset;
1495
      if (fieldp->dfield.bitlength % 8)
1496
        FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength;
1497
      else
1498
        FIELD_BITSIZE (list->field) = 0;
1499
      nfields++;
1500
      field = fieldp->dfield.nextfield;
1501
      FIELD_TYPE (list->field) = hpread_type_lookup (fieldp->dfield.type,
1502
                                                     objfile);
1503
    }
1504
 
1505
  TYPE_NFIELDS (type) = nfields;
1506
  TYPE_FIELDS (type) = (struct field *)
1507
    obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1508
 
1509
  /* Copy the saved-up fields into the field vector.  */
1510
  for (n = nfields; list; list = list->next)
1511
    {
1512
      n -= 1;
1513
      TYPE_FIELD (type, n) = list->field;
1514
    }
1515
  return type;
1516
}
1517
 
1518
/* Read in and internalize a set debug symbol.  */
1519
 
1520
static struct type *
1521
hpread_read_set_type (hp_type, dn_bufp, objfile)
1522
     dnttpointer hp_type;
1523
     union dnttentry *dn_bufp;
1524
     struct objfile *objfile;
1525
{
1526
  struct type *type;
1527
 
1528
  /* See if it's something we've already deal with.  */
1529
  type = hpread_alloc_type (hp_type, objfile);
1530
  if (TYPE_CODE (type) == TYPE_CODE_SET)
1531
    return type;
1532
 
1533
  /* Nope.  Fill in the appropriate fields.  */
1534
  TYPE_CODE (type) = TYPE_CODE_SET;
1535
  TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1536
  TYPE_NFIELDS (type) = 0;
1537
  TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1538
                                                objfile);
1539
  return type;
1540
}
1541
 
1542
/* Read in and internalize an array debug symbol.  */
1543
 
1544
static struct type *
1545
hpread_read_array_type (hp_type, dn_bufp, objfile)
1546
     dnttpointer hp_type;
1547
     union dnttentry *dn_bufp;
1548
     struct objfile *objfile;
1549
{
1550
  struct type *type;
1551
  union dnttentry save;
1552
  save = *dn_bufp;
1553
 
1554
  /* Why no check here?  Because it kept us from properly determining
1555
     the size of the array!  */
1556
  type = hpread_alloc_type (hp_type, objfile);
1557
 
1558
  TYPE_CODE (type) = TYPE_CODE_ARRAY;
1559
 
1560
  /* values are not normalized.  */
1561
  if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1562
        || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1563
    abort ();
1564
  else if (dn_bufp->darray.arraylength == 0x7fffffff)
1565
    {
1566
      /* The HP debug format represents char foo[]; as an array with
1567
         length 0x7fffffff.  Internally GDB wants to represent this
1568
         as an array of length zero.  */
1569
      TYPE_LENGTH (type) = 0;
1570
    }
1571
  else
1572
    TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1573
 
1574
  TYPE_NFIELDS (type) = 1;
1575
  TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1576
                                                objfile);
1577
  dn_bufp = &save;
1578
  TYPE_FIELDS (type) = (struct field *)
1579
    obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1580
  TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1581
                                                  objfile);
1582
  return type;
1583
}
1584
 
1585
/* Read in and internalize a subrange debug symbol.  */
1586
static struct type *
1587
hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1588
     dnttpointer hp_type;
1589
     union dnttentry *dn_bufp;
1590
     struct objfile *objfile;
1591
{
1592
  struct type *type;
1593
 
1594
  /* Is it something we've already dealt with.  */
1595
  type = hpread_alloc_type (hp_type, objfile);
1596
  if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1597
    return type;
1598
 
1599
  /* Nope, internalize it.  */
1600
  TYPE_CODE (type) = TYPE_CODE_RANGE;
1601
  TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1602
  TYPE_NFIELDS (type) = 2;
1603
  TYPE_FIELDS (type)
1604
    = (struct field *) obstack_alloc (&objfile->type_obstack,
1605
                                      2 * sizeof (struct field));
1606
 
1607
  if (dn_bufp->dsubr.dyn_low)
1608
    TYPE_FIELD_BITPOS (type, 0) = 0;
1609
  else
1610
    TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1611
 
1612
  if (dn_bufp->dsubr.dyn_high)
1613
    TYPE_FIELD_BITPOS (type, 1) = -1;
1614
  else
1615
    TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1616
  TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1617
                                                objfile);
1618
  return type;
1619
}
1620
 
1621
static struct type *
1622
hpread_type_lookup (hp_type, objfile)
1623
     dnttpointer hp_type;
1624
     struct objfile *objfile;
1625
{
1626
  union dnttentry *dn_bufp;
1627
 
1628
  /* First see if it's a simple builtin type.  */
1629
  if (hp_type.dntti.immediate)
1630
    return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1631
 
1632
  /* Not a builtin type.  We'll have to read it in.  */
1633
  if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1634
    dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1635
  else
1636
    return lookup_fundamental_type (objfile, FT_VOID);
1637
 
1638
  switch (dn_bufp->dblock.kind)
1639
    {
1640
    case DNTT_TYPE_SRCFILE:
1641
    case DNTT_TYPE_MODULE:
1642
    case DNTT_TYPE_FUNCTION:
1643
    case DNTT_TYPE_ENTRY:
1644
    case DNTT_TYPE_BEGIN:
1645
    case DNTT_TYPE_END:
1646
    case DNTT_TYPE_IMPORT:
1647
    case DNTT_TYPE_LABEL:
1648
    case DNTT_TYPE_WITH:
1649
    case DNTT_TYPE_COMMON:
1650
    case DNTT_TYPE_FPARAM:
1651
    case DNTT_TYPE_SVAR:
1652
    case DNTT_TYPE_DVAR:
1653
    case DNTT_TYPE_CONST:
1654
      /* Opps.  Something went very wrong.  */
1655
      return lookup_fundamental_type (objfile, FT_VOID);
1656
 
1657
    case DNTT_TYPE_TYPEDEF:
1658
      {
1659
        struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1660
                                                      objfile);
1661
        char *suffix;
1662
        suffix = VT (objfile) + dn_bufp->dtype.name;
1663
 
1664
        TYPE_CPLUS_SPECIFIC (structtype)
1665
          = (struct cplus_struct_type *) &cplus_struct_default;
1666
        TYPE_NAME (structtype) = suffix;
1667
        return structtype;
1668
      }
1669
 
1670
    case DNTT_TYPE_TAGDEF:
1671
      {
1672
        /* Just a little different from above.  We have to tack on
1673
           an identifier of some kind (struct, union, enum, etc).  */
1674
        struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1675
                                                      objfile);
1676
        char *prefix, *suffix;
1677
        suffix = VT (objfile) + dn_bufp->dtype.name;
1678
 
1679
        /* Lookup the next type in the list.  It should be a structure,
1680
           union, or enum type.  We will need to attach that to our name.  */
1681
        if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1682
          dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1683
        else
1684
          abort ();
1685
 
1686
        if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT)
1687
          prefix = "struct ";
1688
        else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION)
1689
          prefix = "union ";
1690
        else
1691
          prefix = "enum ";
1692
 
1693
        /* Build the correct name.  */
1694
        structtype->name
1695
          = (char *) obstack_alloc (&objfile->type_obstack,
1696
                                    strlen (prefix) + strlen (suffix) + 1);
1697
        TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1698
        TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1699
        TYPE_TAG_NAME (structtype) = suffix;
1700
 
1701
        TYPE_CPLUS_SPECIFIC (structtype)
1702
          = (struct cplus_struct_type *) &cplus_struct_default;
1703
 
1704
        return structtype;
1705
      }
1706
    case DNTT_TYPE_POINTER:
1707
      return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1708
                                                      objfile));
1709
    case DNTT_TYPE_ENUM:
1710
      return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1711
    case DNTT_TYPE_MEMENUM:
1712
      return lookup_fundamental_type (objfile, FT_VOID);
1713
    case DNTT_TYPE_SET:
1714
      return hpread_read_set_type (hp_type, dn_bufp, objfile);
1715
    case DNTT_TYPE_SUBRANGE:
1716
      return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1717
    case DNTT_TYPE_ARRAY:
1718
      return hpread_read_array_type (hp_type, dn_bufp, objfile);
1719
    case DNTT_TYPE_STRUCT:
1720
    case DNTT_TYPE_UNION:
1721
      return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1722
    case DNTT_TYPE_FIELD:
1723
      return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1724
    case DNTT_TYPE_VARIANT:
1725
    case DNTT_TYPE_FILE:
1726
      return lookup_fundamental_type (objfile, FT_VOID);
1727
    case DNTT_TYPE_FUNCTYPE:
1728
      return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1729
                                                       objfile));
1730
    case DNTT_TYPE_COBSTRUCT:
1731
    case DNTT_TYPE_XREF:
1732
    case DNTT_TYPE_SA:
1733
    case DNTT_TYPE_MACRO:
1734
    default:
1735
      return lookup_fundamental_type (objfile, FT_VOID);
1736
    }
1737
}
1738
 
1739
static sltpointer
1740
hpread_record_lines (subfile, s_idx, e_idx, objfile, offset)
1741
     struct subfile *subfile;
1742
     sltpointer s_idx, e_idx;
1743
     struct objfile *objfile;
1744
     CORE_ADDR offset;
1745
{
1746
  union sltentry *sl_bufp;
1747
 
1748
  while (s_idx <= e_idx)
1749
    {
1750
      sl_bufp = hpread_get_slt (s_idx, objfile);
1751
      /* Only record "normal" entries in the SLT.  */
1752
      if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1753
          || sl_bufp->snorm.sltdesc == SLT_EXIT)
1754
        record_line (subfile, sl_bufp->snorm.line,
1755
                     sl_bufp->snorm.address + offset);
1756
      s_idx++;
1757
    }
1758
  return e_idx;
1759
}
1760
 
1761
/* Internalize one native debug symbol.  */
1762
 
1763
static void
1764
hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1765
                                 text_offset, text_size, filename, index)
1766
     union dnttentry *dn_bufp;
1767
     char *name;
1768
     struct section_offsets *section_offsets;
1769
     struct objfile *objfile;
1770
     CORE_ADDR text_offset;
1771
     int text_size;
1772
     char *filename;
1773
     int index;
1774
{
1775
  unsigned long desc;
1776
  int type;
1777
  CORE_ADDR valu;
1778
  int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1779
  union dnttentry *dn_temp;
1780
  dnttpointer hp_type;
1781
  struct symbol *sym;
1782
  struct context_stack *new;
1783
 
1784
  /* Allocate one GDB debug symbol and fill in some default values.  */
1785
  sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1786
                                         sizeof (struct symbol));
1787
  memset (sym, 0, sizeof (struct symbol));
1788
  SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->symbol_obstack);
1789
  SYMBOL_LANGUAGE (sym) = language_auto;
1790
  SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1791
  SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1792
  SYMBOL_LINE (sym) = 0;
1793
  SYMBOL_VALUE (sym) = 0;
1794
  SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1795
 
1796
  hp_type.dnttp.extension = 1;
1797
  hp_type.dnttp.immediate = 0;
1798
  hp_type.dnttp.global = 0;
1799
  hp_type.dnttp.index = index;
1800
 
1801
  type = dn_bufp->dblock.kind;
1802
 
1803
  switch (type)
1804
    {
1805
    case DNTT_TYPE_SRCFILE:
1806
      /* This type of symbol indicates from which source file or include file
1807
         the following data comes. If there are no modules it also may
1808
         indicate the start of a new source file, in which case we must
1809
         finish the symbol table of the previous source file
1810
         (if any) and start accumulating a new symbol table.  */
1811
 
1812
      valu = text_offset;
1813
      if (!last_source_file)
1814
        {
1815
          start_symtab (name, NULL, valu);
1816
          record_debugformat ("HP");
1817
          SL_INDEX (objfile) = dn_bufp->dsfile.address;
1818
        }
1819
      else
1820
        {
1821
          SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1822
                                                    SL_INDEX (objfile),
1823
                                                    dn_bufp->dsfile.address,
1824
                                                    objfile, offset);
1825
        }
1826
      start_subfile (name, NULL);
1827
      break;
1828
 
1829
    case DNTT_TYPE_MODULE:
1830
      /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore.  */
1831
      break;
1832
 
1833
    case DNTT_TYPE_FUNCTION:
1834
    case DNTT_TYPE_ENTRY:
1835
      /* A function or secondary entry point.  */
1836
      valu = dn_bufp->dfunc.lowaddr + offset;
1837
      SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1838
                                                SL_INDEX (objfile),
1839
                                                dn_bufp->dfunc.address,
1840
                                                objfile, offset);
1841
 
1842
      WITHIN_FUNCTION (objfile) = 1;
1843
      CURRENT_FUNCTION_VALUE (objfile) = valu;
1844
 
1845
      /* Stack must be empty now.  */
1846
      if (context_stack_depth != 0)
1847
        complain (&lbrac_unmatched_complaint, (char *) symnum);
1848
      new = push_context (0, valu);
1849
 
1850
      SYMBOL_CLASS (sym) = LOC_BLOCK;
1851
      SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1852
      if (dn_bufp->dfunc.global)
1853
        add_symbol_to_list (sym, &global_symbols);
1854
      else
1855
        add_symbol_to_list (sym, &file_symbols);
1856
      new->name = sym;
1857
 
1858
      /* Search forward to the next scope beginning.  */
1859
      while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN)
1860
        {
1861
          dn_bufp = hpread_get_lntt (++index, objfile);
1862
          if (dn_bufp->dblock.extension)
1863
            continue;
1864
        }
1865
      SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1866
                                                SL_INDEX (objfile),
1867
                                                dn_bufp->dbegin.address,
1868
                                                objfile, offset);
1869
      SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1870
      record_line (current_subfile, SYMBOL_LINE (sym), valu);
1871
      break;
1872
 
1873
    case DNTT_TYPE_BEGIN:
1874
      /* Begin a new scope.  */
1875
      SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1876
                                                SL_INDEX (objfile),
1877
                                                dn_bufp->dbegin.address,
1878
                                                objfile, offset);
1879
      valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1880
      valu += offset;           /* Relocate for dynamic loading */
1881
      desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1882
      new = push_context (desc, valu);
1883
      break;
1884
 
1885
    case DNTT_TYPE_END:
1886
      /* End a scope.  */
1887
      SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1888
                                                SL_INDEX (objfile),
1889
                                                dn_bufp->dend.address + 1,
1890
                                                objfile, offset);
1891
      switch (dn_bufp->dend.endkind)
1892
        {
1893
        case DNTT_TYPE_MODULE:
1894
          /* Ending a module ends the symbol table for that module.  */
1895
          valu = text_offset + text_size + offset;
1896
          (void) end_symtab (valu, objfile, 0);
1897
          break;
1898
 
1899
        case DNTT_TYPE_FUNCTION:
1900
          /* Ending a function, well, ends the function's scope.  */
1901
          dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1902
                                     objfile);
1903
          valu = dn_temp->dfunc.hiaddr + offset;
1904
          new = pop_context ();
1905
          /* Make a block for the local symbols within.  */
1906
          finish_block (new->name, &local_symbols, new->old_blocks,
1907
                        new->start_addr, valu, objfile);
1908
          WITHIN_FUNCTION (objfile) = 0;
1909
          break;
1910
        case DNTT_TYPE_BEGIN:
1911
          /* Just ending a local scope.  */
1912
          valu = hpread_get_location (dn_bufp->dend.address, objfile);
1913
          /* Why in the hell is this needed?  */
1914
          valu += offset + 9;   /* Relocate for dynamic loading */
1915
          new = pop_context ();
1916
          desc = dn_bufp->dend.beginscope.dnttp.index;
1917
          if (desc != new->depth)
1918
            complain (&lbrac_mismatch_complaint, (char *) symnum);
1919
          /* Make a block for the local symbols within.  */
1920
          finish_block (new->name, &local_symbols, new->old_blocks,
1921
                        new->start_addr, valu, objfile);
1922
          local_symbols = new->locals;
1923
          break;
1924
        }
1925
      break;
1926
    case DNTT_TYPE_LABEL:
1927
      SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1928
      break;
1929
    case DNTT_TYPE_FPARAM:
1930
      /* Function parameters.  */
1931
      if (dn_bufp->dfparam.regparam)
1932
        SYMBOL_CLASS (sym) = LOC_REGISTER;
1933
      else
1934
        SYMBOL_CLASS (sym) = LOC_LOCAL;
1935
      if (dn_bufp->dfparam.copyparam)
1936
        {
1937
          SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1938
#ifdef HPREAD_ADJUST_STACK_ADDRESS
1939
          SYMBOL_VALUE (sym)
1940
            += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1941
#endif
1942
        }
1943
      else
1944
        SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1945
      SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1946
      add_symbol_to_list (sym, &local_symbols);
1947
      break;
1948
    case DNTT_TYPE_SVAR:
1949
      /* Static variables.  */
1950
      SYMBOL_CLASS (sym) = LOC_STATIC;
1951
      SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1952
      SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1953
      if (dn_bufp->dsvar.global)
1954
        add_symbol_to_list (sym, &global_symbols);
1955
      else if (WITHIN_FUNCTION (objfile))
1956
        add_symbol_to_list (sym, &local_symbols);
1957
      else
1958
        add_symbol_to_list (sym, &file_symbols);
1959
      break;
1960
    case DNTT_TYPE_DVAR:
1961
      /* Dynamic variables.  */
1962
      if (dn_bufp->ddvar.regvar)
1963
        SYMBOL_CLASS (sym) = LOC_REGISTER;
1964
      else
1965
        SYMBOL_CLASS (sym) = LOC_LOCAL;
1966
      SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1967
#ifdef HPREAD_ADJUST_STACK_ADDRESS
1968
      SYMBOL_VALUE (sym)
1969
        += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1970
#endif
1971
      SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1972
      if (dn_bufp->ddvar.global)
1973
        add_symbol_to_list (sym, &global_symbols);
1974
      else if (WITHIN_FUNCTION (objfile))
1975
        add_symbol_to_list (sym, &local_symbols);
1976
      else
1977
        add_symbol_to_list (sym, &file_symbols);
1978
      break;
1979
    case DNTT_TYPE_CONST:
1980
      /* A constant (pascal?).  */
1981
      SYMBOL_CLASS (sym) = LOC_CONST;
1982
      SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1983
      SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1984
      if (dn_bufp->dconst.global)
1985
        add_symbol_to_list (sym, &global_symbols);
1986
      else if (WITHIN_FUNCTION (objfile))
1987
        add_symbol_to_list (sym, &local_symbols);
1988
      else
1989
        add_symbol_to_list (sym, &file_symbols);
1990
      break;
1991
    case DNTT_TYPE_TYPEDEF:
1992
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1993
      SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1994
      if (dn_bufp->dtype.global)
1995
        add_symbol_to_list (sym, &global_symbols);
1996
      else if (WITHIN_FUNCTION (objfile))
1997
        add_symbol_to_list (sym, &local_symbols);
1998
      else
1999
        add_symbol_to_list (sym, &file_symbols);
2000
      break;
2001
    case DNTT_TYPE_TAGDEF:
2002
      SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2003
      SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
2004
      TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
2005
      TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
2006
      if (dn_bufp->dtype.global)
2007
        add_symbol_to_list (sym, &global_symbols);
2008
      else if (WITHIN_FUNCTION (objfile))
2009
        add_symbol_to_list (sym, &local_symbols);
2010
      else
2011
        add_symbol_to_list (sym, &file_symbols);
2012
      break;
2013
    case DNTT_TYPE_POINTER:
2014
      SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
2015
                                               (dn_bufp->dptr.pointsto,
2016
                                                objfile));
2017
      add_symbol_to_list (sym, &file_symbols);
2018
      break;
2019
    case DNTT_TYPE_ENUM:
2020
      SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2021
      SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2022
      add_symbol_to_list (sym, &file_symbols);
2023
      break;
2024
    case DNTT_TYPE_MEMENUM:
2025
      break;
2026
    case DNTT_TYPE_SET:
2027
      SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2028
      add_symbol_to_list (sym, &file_symbols);
2029
      break;
2030
    case DNTT_TYPE_SUBRANGE:
2031
      SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2032
                                                     objfile);
2033
      add_symbol_to_list (sym, &file_symbols);
2034
      break;
2035
    case DNTT_TYPE_ARRAY:
2036
      SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2037
      add_symbol_to_list (sym, &file_symbols);
2038
      break;
2039
    case DNTT_TYPE_STRUCT:
2040
    case DNTT_TYPE_UNION:
2041
      SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2042
      SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2043
      add_symbol_to_list (sym, &file_symbols);
2044
      break;
2045
    default:
2046
      break;
2047
    }
2048
}

powered by: WebSVN 2.1.0

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