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