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