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