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