* hpread.c (struct hpread_symfile_info): Delete have_module field
[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 return FT_UNSIGNED_LONG;
1141 case T_UNS_INT:
1142 if (typep.dntti.bitlength <= 8)
1143 return FT_UNSIGNED_CHAR;
1144 if (typep.dntti.bitlength <= 16)
1145 return FT_UNSIGNED_SHORT;
1146 if (typep.dntti.bitlength <= 32)
1147 return FT_UNSIGNED_INTEGER;
1148 return FT_UNSIGNED_LONG_LONG;
1149 case T_REAL:
1150 case T_REAL_3000:
1151 case T_DOUBLE:
1152 if (typep.dntti.bitlength == 64)
1153 return FT_DBL_PREC_FLOAT;
1154 if (typep.dntti.bitlength == 128)
1155 return FT_EXT_PREC_FLOAT;
1156 return FT_FLOAT;
1157 case T_COMPLEX:
1158 case T_COMPLEXS3000:
1159 if (typep.dntti.bitlength == 128)
1160 return FT_DBL_PREC_COMPLEX;
1161 if (typep.dntti.bitlength == 192)
1162 return FT_EXT_PREC_COMPLEX;
1163 return FT_COMPLEX;
1164 case T_STRING200:
1165 case T_LONGSTRING200:
1166 case T_FTN_STRING_SPEC:
1167 case T_MOD_STRING_SPEC:
1168 case T_MOD_STRING_3000:
1169 case T_FTN_STRING_S300_COMPAT:
1170 case T_FTN_STRING_VAX_COMPAT:
1171 return FT_STRING;
1172 default:
1173 abort ();
1174 }
1175 }
1176
1177 /* Return the type associated with the index found in HP_TYPE. */
1178
1179 static struct type **
1180 hpread_lookup_type (hp_type, objfile)
1181 DNTTPOINTER hp_type;
1182 struct objfile *objfile;
1183 {
1184 unsigned old_len;
1185 int index = hp_type.dnttp.index;
1186
1187 if (hp_type.dntti.immediate)
1188 return NULL;
1189
1190 if (index < LNTT_SYMCOUNT (objfile))
1191 {
1192 if (index >= TYPE_VECTOR_LENGTH (objfile))
1193 {
1194 old_len = TYPE_VECTOR_LENGTH (objfile);
1195 if (old_len == 0)
1196 {
1197 TYPE_VECTOR_LENGTH (objfile) = 100;
1198 TYPE_VECTOR (objfile) = (struct type **)
1199 malloc (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *));
1200 }
1201 while (index >= TYPE_VECTOR_LENGTH (objfile))
1202 TYPE_VECTOR_LENGTH (objfile) *= 2;
1203 TYPE_VECTOR (objfile) = (struct type **)
1204 xrealloc ((char *) TYPE_VECTOR (objfile),
1205 (TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)));
1206 memset (&TYPE_VECTOR (objfile)[old_len], 0,
1207 (TYPE_VECTOR_LENGTH (objfile) - old_len) *
1208 sizeof (struct type *));
1209 }
1210 return &TYPE_VECTOR (objfile)[index];
1211 }
1212 else
1213 return NULL;
1214 }
1215
1216 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1217 Note we'll just return the address of a GDB internal type if we already
1218 have it lying around. */
1219
1220 static struct type *
1221 hpread_alloc_type (hp_type, objfile)
1222 DNTTPOINTER hp_type;
1223 struct objfile *objfile;
1224 {
1225 struct type **type_addr;
1226
1227 type_addr = hpread_lookup_type (hp_type, objfile);
1228 if (*type_addr == 0)
1229 *type_addr = alloc_type (objfile);
1230
1231 TYPE_CPLUS_SPECIFIC (*type_addr)
1232 = (struct cplus_struct_type *) &cplus_struct_default;
1233 return *type_addr;
1234 }
1235
1236 /* Read a native enumerated type and return it in GDB internal form. */
1237
1238 static struct type *
1239 hpread_read_enum_type (hp_type, dn_bufp, objfile)
1240 DNTTPOINTER hp_type;
1241 union dnttentry *dn_bufp;
1242 struct objfile *objfile;
1243 {
1244 struct type *type;
1245 struct pending **symlist, *osyms, *syms;
1246 int o_nsyms, nsyms = 0;
1247 DNTTPOINTER mem;
1248 union dnttentry *memp;
1249 char *name;
1250 long n;
1251 struct symbol *sym;
1252
1253 type = hpread_alloc_type (hp_type, objfile);
1254 TYPE_LENGTH (type) = 4;
1255
1256 symlist = &file_symbols;
1257 osyms = *symlist;
1258 o_nsyms = osyms ? osyms->nsyms : 0;
1259
1260 /* Get a name for each member and add it to our list of members. */
1261 mem = dn_bufp->denum.firstmem;
1262 while (mem.dnttp.extension && mem.word != DNTTNIL)
1263 {
1264 memp = hpread_get_lntt (mem.dnttp.index, objfile);
1265
1266 name = VT (objfile) + memp->dmember.name;
1267 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1268 sizeof (struct symbol));
1269 memset (sym, 0, sizeof (struct symbol));
1270 SYMBOL_NAME (sym) = name;
1271 SYMBOL_CLASS (sym) = LOC_CONST;
1272 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1273 SYMBOL_VALUE (sym) = memp->dmember.value;
1274 add_symbol_to_list (sym, symlist);
1275 nsyms++;
1276 mem = memp->dmember.nextmem;
1277 }
1278
1279 /* Now that we know more about the enum, fill in more info. */
1280 TYPE_CODE (type) = TYPE_CODE_ENUM;
1281 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1282 TYPE_NFIELDS (type) = nsyms;
1283 TYPE_FIELDS (type) = (struct field *)
1284 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nsyms);
1285
1286 /* Find the symbols for the members and put them into the type.
1287 The symbols can be found in the symlist that we put them on
1288 to cause them to be defined. osyms contains the old value
1289 of that symlist; everything up to there was defined by us.
1290
1291 Note that we preserve the order of the enum constants, so
1292 that in something like "enum {FOO, LAST_THING=FOO}" we print
1293 FOO, not LAST_THING. */
1294 for (syms = *symlist, n = 0; syms; syms = syms->next)
1295 {
1296 int j = 0;
1297 if (syms == osyms)
1298 j = o_nsyms;
1299 for (; j < syms->nsyms; j++, n++)
1300 {
1301 struct symbol *xsym = syms->symbol[j];
1302 SYMBOL_TYPE (xsym) = type;
1303 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1304 TYPE_FIELD_VALUE (type, n) = 0;
1305 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1306 TYPE_FIELD_BITSIZE (type, n) = 0;
1307 }
1308 if (syms == osyms)
1309 break;
1310 }
1311
1312 return type;
1313 }
1314
1315 /* Read and internalize a native function debug symbol. */
1316
1317 static struct type *
1318 hpread_read_function_type (hp_type, dn_bufp, objfile)
1319 DNTTPOINTER hp_type;
1320 union dnttentry *dn_bufp;
1321 struct objfile *objfile;
1322 {
1323 struct type *type, *type1;
1324 struct pending **symlist, *osyms, *syms;
1325 int o_nsyms, nsyms = 0;
1326 DNTTPOINTER param;
1327 union dnttentry *paramp;
1328 char *name;
1329 long n;
1330 struct symbol *sym;
1331
1332 param = dn_bufp->dfunc.firstparam;
1333
1334 /* See if we've already read in this type. */
1335 type = hpread_alloc_type (hp_type, objfile);
1336 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
1337 return type;
1338
1339 /* Nope, so read it in and store it away. */
1340 type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval,
1341 objfile));
1342 memcpy ((char *) type, (char *) type1, sizeof (struct type));
1343
1344 symlist = &local_symbols;
1345 osyms = *symlist;
1346 o_nsyms = osyms ? osyms->nsyms : 0;
1347
1348 /* Now examine each parameter noting its type, location, and a
1349 wealth of other information. */
1350 while (param.word && param.word != DNTTNIL)
1351 {
1352 paramp = hpread_get_lntt (param.dnttp.index, objfile);
1353 nsyms++;
1354 param = paramp->dfparam.nextparam;
1355
1356 /* Get the name. */
1357 name = VT (objfile) + paramp->dfparam.name;
1358 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1359 sizeof (struct symbol));
1360 (void) memset (sym, 0, sizeof (struct symbol));
1361 SYMBOL_NAME (sym) = name;
1362
1363 /* Figure out where it lives. */
1364 if (paramp->dfparam.regparam)
1365 SYMBOL_CLASS (sym) = LOC_REGPARM;
1366 else if (paramp->dfparam.indirect)
1367 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1368 else
1369 SYMBOL_CLASS (sym) = LOC_ARG;
1370 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1371 if (paramp->dfparam.copyparam)
1372 {
1373 SYMBOL_VALUE (sym) = paramp->dfparam.location ;
1374 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1375 SYMBOL_VALUE (sym)
1376 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1377 #endif
1378 /* This is likely a pass-by-invisible reference parameter,
1379 Hack on the symbol class to make GDB happy. */
1380 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1381 }
1382 else
1383 SYMBOL_VALUE (sym) = paramp->dfparam.location;
1384
1385 /* Get its type. */
1386 SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile);
1387
1388 /* Add it to the list. */
1389 add_symbol_to_list (sym, symlist);
1390 }
1391
1392 /* Note how many parameters we found. */
1393 TYPE_NFIELDS (type) = nsyms;
1394 TYPE_FIELDS (type) = (struct field *)
1395 obstack_alloc (&objfile->type_obstack,
1396 sizeof (struct field) * nsyms);
1397
1398 /* Find the symbols for the values and put them into the type.
1399 The symbols can be found in the symlist that we put them on
1400 to cause them to be defined. osyms contains the old value
1401 of that symlist; everything up to there was defined by us. */
1402 /* Note that we preserve the order of the parameters, so
1403 that in something like "enum {FOO, LAST_THING=FOO}" we print
1404 FOO, not LAST_THING. */
1405 for (syms = *symlist, n = 0; syms; syms = syms->next)
1406 {
1407 int j = 0;
1408 if (syms == osyms)
1409 j = o_nsyms;
1410 for (; j < syms->nsyms; j++, n++)
1411 {
1412 struct symbol *xsym = syms->symbol[j];
1413 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1414 TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym);
1415 TYPE_FIELD_BITPOS (type, n) = n;
1416 TYPE_FIELD_BITSIZE (type, n) = 0;
1417 }
1418 if (syms == osyms)
1419 break;
1420 }
1421 return type;
1422 }
1423
1424 /* Read in and internalize a structure definition. */
1425
1426 static struct type *
1427 hpread_read_struct_type (hp_type, dn_bufp, objfile)
1428 DNTTPOINTER hp_type;
1429 union dnttentry *dn_bufp;
1430 struct objfile *objfile;
1431 {
1432 struct nextfield
1433 {
1434 struct nextfield *next;
1435 struct field field;
1436 };
1437
1438 struct type *type;
1439 struct nextfield *list = 0;
1440 struct nextfield *new;
1441 int n, nfields = 0;
1442 DNTTPOINTER field;
1443 union dnttentry *fieldp;
1444
1445 /* Is it something we've already dealt with? */
1446 type = hpread_alloc_type (hp_type, objfile);
1447 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
1448 (TYPE_CODE (type) == TYPE_CODE_UNION))
1449 return type;
1450
1451 /* Get the basic type correct. */
1452 if (dn_bufp->dblock.kind == K_STRUCT)
1453 {
1454 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1455 TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8;
1456 }
1457 else if (dn_bufp->dblock.kind == K_UNION)
1458 {
1459 TYPE_CODE (type) = TYPE_CODE_UNION;
1460 TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8;
1461 }
1462 else
1463 return type;
1464
1465
1466 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1467
1468 /* Read in and internalize all the fields. */
1469 field = dn_bufp->dstruct.firstfield;
1470 while (field.word != DNTTNIL && field.dnttp.extension)
1471 {
1472 fieldp = hpread_get_lntt (field.dnttp.index, objfile);
1473
1474 /* Get space to record the next field's data. */
1475 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1476 new->next = list;
1477 list = new;
1478
1479 list->field.name = VT (objfile) + fieldp->dfield.name;
1480 list->field.bitpos = fieldp->dfield.bitoffset;
1481 if (fieldp->dfield.bitlength % 8)
1482 list->field.bitsize = fieldp->dfield.bitlength;
1483 else
1484 list->field.bitsize = 0;
1485 nfields++;
1486 field = fieldp->dfield.nextfield;
1487 list->field.type = hpread_type_lookup (fieldp->dfield.type, objfile);
1488 }
1489
1490 TYPE_NFIELDS (type) = nfields;
1491 TYPE_FIELDS (type) = (struct field *)
1492 obstack_alloc (&objfile->type_obstack, sizeof (struct field) * nfields);
1493
1494 /* Copy the saved-up fields into the field vector. */
1495 for (n = nfields; list; list = list->next)
1496 {
1497 n -= 1;
1498 TYPE_FIELD (type, n) = list->field;
1499 }
1500 return type;
1501 }
1502
1503 /* Read in and internalize a set debug symbol. */
1504
1505 static struct type *
1506 hpread_read_set_type (hp_type, dn_bufp, objfile)
1507 DNTTPOINTER hp_type;
1508 union dnttentry *dn_bufp;
1509 struct objfile *objfile;
1510 {
1511 struct type *type;
1512
1513 /* See if it's something we've already deal with. */
1514 type = hpread_alloc_type (hp_type, objfile);
1515 if (TYPE_CODE (type) == TYPE_CODE_SET)
1516 return type;
1517
1518 /* Nope. Fill in the appropriate fields. */
1519 TYPE_CODE (type) = TYPE_CODE_SET;
1520 TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8;
1521 TYPE_NFIELDS (type) = 0;
1522 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype,
1523 objfile);
1524 return type;
1525 }
1526
1527 /* Read in and internalize an array debug symbol. */
1528
1529 static struct type *
1530 hpread_read_array_type (hp_type, dn_bufp, objfile)
1531 DNTTPOINTER hp_type;
1532 union dnttentry *dn_bufp;
1533 struct objfile *objfile;
1534 {
1535 struct type *type;
1536 union dnttentry save;
1537 save = *dn_bufp;
1538
1539 /* Why no check here? Because it kept us from properly determining
1540 the size of the array! */
1541 type = hpread_alloc_type (hp_type, objfile);
1542
1543 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1544
1545 /* values are not normalized. */
1546 if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes)
1547 || (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes)))
1548 abort ();
1549 else if (dn_bufp->darray.arraylength == 0x7fffffff)
1550 {
1551 /* The HP debug format represents char foo[]; as an array with
1552 length 0x7fffffff. Internally GDB wants to represent this
1553 as a pointer. Ugh. */
1554 TYPE_CODE (type) = TYPE_CODE_PTR;
1555 TYPE_LENGTH (type) = 4;
1556 }
1557 else
1558 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1559
1560 TYPE_NFIELDS (type) = 1;
1561 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1562 objfile);
1563 dn_bufp = &save;
1564 TYPE_FIELDS (type) = (struct field *)
1565 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1566 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1567 objfile);
1568 return type;
1569 }
1570
1571 /* Read in and internalize a subrange debug symbol. */
1572 static struct type *
1573 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1574 DNTTPOINTER hp_type;
1575 union dnttentry *dn_bufp;
1576 struct objfile *objfile;
1577 {
1578 struct type *type;
1579
1580 /* Is it something we've already dealt with. */
1581 type = hpread_alloc_type (hp_type, objfile);
1582 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1583 return type;
1584
1585 /* Nope, internalize it. */
1586 TYPE_CODE (type) = TYPE_CODE_RANGE;
1587 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1588 TYPE_NFIELDS (type) = 2;
1589 TYPE_FIELDS (type) = (struct field *) obstack_alloc
1590 (&objfile->type_obstack, 2 * sizeof (struct field));
1591
1592 if (dn_bufp->dsubr.dyn_low)
1593 TYPE_FIELD_BITPOS (type, 0) = 0;
1594 else
1595 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1596
1597 if (dn_bufp->dsubr.dyn_high)
1598 TYPE_FIELD_BITPOS (type, 1) = -1;
1599 else
1600 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1601 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1602 objfile);
1603 return type;
1604 }
1605
1606 static struct type *
1607 hpread_type_lookup (hp_type, objfile)
1608 DNTTPOINTER hp_type;
1609 struct objfile *objfile;
1610 {
1611 union dnttentry *dn_bufp;
1612
1613 /* First see if it's a simple builtin type. */
1614 if (hp_type.dntti.immediate)
1615 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1616
1617 /* Not a builtin type. We'll have to read it in. */
1618 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1619 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1620 else
1621 return lookup_fundamental_type (objfile, FT_VOID);
1622
1623 switch (dn_bufp->dblock.kind)
1624 {
1625 case K_SRCFILE:
1626 case K_MODULE:
1627 case K_FUNCTION:
1628 case K_ENTRY:
1629 case K_BEGIN:
1630 case K_END:
1631 case K_IMPORT:
1632 case K_LABEL:
1633 case K_WITH:
1634 case K_COMMON:
1635 case K_FPARAM:
1636 case K_SVAR:
1637 case K_DVAR:
1638 case K_CONST:
1639 /* Opps. Something went very wrong. */
1640 return lookup_fundamental_type (objfile, FT_VOID);
1641
1642 case K_TYPEDEF:
1643 {
1644 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1645 objfile);
1646 char *suffix;
1647 suffix = VT (objfile) + dn_bufp->dtype.name;
1648
1649 TYPE_CPLUS_SPECIFIC (structtype)
1650 = (struct cplus_struct_type *) &cplus_struct_default;
1651 TYPE_NAME (structtype) = suffix;
1652 return structtype;
1653 }
1654
1655 case K_TAGDEF:
1656 {
1657 /* Just a little different from above. We have to tack on
1658 an identifier of some kind (struct, union, enum, etc). */
1659 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1660 objfile);
1661 char *prefix, *suffix;
1662 suffix = VT (objfile) + dn_bufp->dtype.name;
1663
1664 /* Lookup the next type in the list. It should be a structure,
1665 union, or enum type. We will need to attach that to our name. */
1666 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1667 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1668 else
1669 abort ();
1670
1671 if (dn_bufp->dblock.kind == K_STRUCT)
1672 prefix = "struct ";
1673 else if (dn_bufp->dblock.kind == K_UNION)
1674 prefix = "union ";
1675 else
1676 prefix = "enum ";
1677
1678 /* Build the correct name. */
1679 structtype->name
1680 = (char *) obstack_alloc (&objfile->type_obstack,
1681 strlen (prefix) + strlen (suffix) + 1);
1682 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1683 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1684 TYPE_TAG_NAME (structtype) = suffix;
1685
1686 TYPE_CPLUS_SPECIFIC (structtype)
1687 = (struct cplus_struct_type *) &cplus_struct_default;
1688
1689 return structtype;
1690 }
1691 case K_POINTER:
1692 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1693 objfile));
1694 case K_ENUM:
1695 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1696 case K_MEMENUM:
1697 return lookup_fundamental_type (objfile, FT_VOID);
1698 case K_SET:
1699 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1700 case K_SUBRANGE:
1701 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1702 case K_ARRAY:
1703 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1704 case K_STRUCT:
1705 case K_UNION:
1706 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1707 case K_FIELD:
1708 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1709 case K_VARIANT:
1710 case K_FILE:
1711 return lookup_fundamental_type (objfile, FT_VOID);
1712 case K_FUNCTYPE:
1713 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1714 objfile));
1715 case K_COBSTRUCT:
1716 case K_XREF:
1717 case K_SA:
1718 case K_MACRO:
1719 default:
1720 return lookup_fundamental_type (objfile, FT_VOID);
1721 }
1722 }
1723
1724 static SLTPOINTER
1725 hpread_record_lines (subfile, s_idx, e_idx, objfile)
1726 struct subfile *subfile;
1727 SLTPOINTER s_idx, e_idx;
1728 struct objfile *objfile;
1729 {
1730 union sltentry *sl_bufp;
1731
1732 while (s_idx <= e_idx)
1733 {
1734 sl_bufp = hpread_get_slt (s_idx, objfile);
1735 /* Only record "normal" entries in the SLT. */
1736 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1737 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1738 record_line (subfile, sl_bufp->snorm.line, sl_bufp->snorm.address);
1739 s_idx++;
1740 }
1741 return e_idx;
1742 }
1743
1744 /* Internalize one native debug symbol. */
1745
1746 static void
1747 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1748 text_offset, text_size, filename, index)
1749 union dnttentry *dn_bufp;
1750 char *name;
1751 struct section_offsets *section_offsets;
1752 struct objfile *objfile;
1753 CORE_ADDR text_offset;
1754 int text_size;
1755 char *filename;
1756 int index;
1757 {
1758 unsigned long desc;
1759 int type;
1760 CORE_ADDR valu;
1761 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1762 union dnttentry *dn_temp;
1763 DNTTPOINTER hp_type;
1764 struct symbol *sym;
1765 struct context_stack *new;
1766
1767 /* Allocate one GDB debug symbol and fill in some default values. */
1768 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1769 sizeof (struct symbol));
1770 memset (sym, 0, sizeof (struct symbol));
1771 SYMBOL_NAME (sym) = name;
1772 SYMBOL_LANGUAGE (sym) = language_auto;
1773 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1774 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1775 SYMBOL_LINE (sym) = 0;
1776 SYMBOL_VALUE (sym) = 0;
1777 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1778
1779 hp_type.dnttp.extension = 1;
1780 hp_type.dnttp.immediate = 0;
1781 hp_type.dnttp.global = 0;
1782 hp_type.dnttp.index = index;
1783
1784 type = dn_bufp->dblock.kind;
1785
1786 switch (type)
1787 {
1788 case K_SRCFILE:
1789 /* This type of symbol indicates from which source file or include file
1790 the following data comes. If there are no modules it also may
1791 indicate the start of a new source file, in which case we must
1792 finish the symbol table of the previous source file
1793 (if any) and start accumulating a new symbol table. */
1794
1795 valu = text_offset + offset; /* Relocate for dynamic loading */
1796 if (!last_source_file)
1797 start_symtab (name, NULL, valu);
1798
1799 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1800 SL_INDEX (objfile),
1801 dn_bufp->dsfile.address,
1802 objfile);
1803 start_subfile (name, NULL);
1804 break;
1805
1806 case K_MODULE:
1807 /* No need to do anything with these K_MODULE symbols anymore. */
1808 break;
1809
1810 case K_FUNCTION:
1811 case K_ENTRY:
1812 /* A function or secondary entry point. */
1813 valu = dn_bufp->dfunc.lowaddr + offset;
1814 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1815 SL_INDEX (objfile),
1816 dn_bufp->dfunc.address,
1817 objfile);
1818
1819 WITHIN_FUNCTION (objfile) = 1;
1820 CURRENT_FUNCTION_VALUE (objfile) = valu;
1821
1822 /* Stack must be empty now. */
1823 if (context_stack_depth != 0)
1824 complain (&lbrac_unmatched_complaint, (char *) symnum);
1825 new = push_context (0, valu);
1826
1827 SYMBOL_CLASS (sym) = LOC_BLOCK;
1828 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1829 if (dn_bufp->dfunc.public)
1830 add_symbol_to_list (sym, &global_symbols);
1831 else
1832 add_symbol_to_list (sym, &file_symbols);
1833 new->name = sym;
1834
1835 /* Search forward to the next scope beginning. */
1836 while (dn_bufp->dblock.kind != K_BEGIN)
1837 {
1838 dn_bufp = hpread_get_lntt (++index, objfile);
1839 if (dn_bufp->dblock.extension)
1840 continue;
1841 }
1842 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1843 SL_INDEX (objfile),
1844 dn_bufp->dbegin.address,
1845 objfile);
1846 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1847 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1848 break;
1849
1850 case K_BEGIN:
1851 /* Begin a new scope. */
1852 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1853 SL_INDEX (objfile),
1854 dn_bufp->dbegin.address,
1855 objfile);
1856 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1857 valu += offset; /* Relocate for dynamic loading */
1858 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1859 new = push_context (desc, valu);
1860 break;
1861
1862 case K_END:
1863 /* End a scope. */
1864 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1865 SL_INDEX (objfile),
1866 dn_bufp->dend.address + 1,
1867 objfile);
1868 switch (dn_bufp->dend.endkind)
1869 {
1870 case K_MODULE:
1871 /* Ending a module ends the symbol table for that module. */
1872 valu = text_offset + text_size + offset;
1873 (void) end_symtab (valu, 0, 0, objfile, 0);
1874 break;
1875
1876 case K_FUNCTION:
1877 /* Ending a function, well, ends the function's scope. */
1878 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1879 objfile);
1880 valu = dn_temp->dfunc.hiaddr + offset;
1881 new = pop_context ();
1882 /* Make a block for the local symbols within. */
1883 finish_block (new->name, &local_symbols, new->old_blocks,
1884 new->start_addr, valu, objfile);
1885 WITHIN_FUNCTION (objfile) = 0;
1886 break;
1887 case K_BEGIN:
1888 /* Just ending a local scope. */
1889 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1890 /* Why in the hell is this needed? */
1891 valu += offset + 9; /* Relocate for dynamic loading */
1892 new = pop_context ();
1893 desc = dn_bufp->dend.beginscope.dnttp.index;
1894 if (desc != new->depth)
1895 complain (&lbrac_mismatch_complaint, (char *) symnum);
1896 /* Make a block for the local symbols within. */
1897 finish_block (new->name, &local_symbols, new->old_blocks,
1898 new->start_addr, valu, objfile);
1899 local_symbols = new->locals;
1900 break;
1901 }
1902 break;
1903 case K_LABEL:
1904 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1905 break;
1906 case K_FPARAM:
1907 /* Function parameters. */
1908 if (dn_bufp->dfparam.regparam)
1909 SYMBOL_CLASS (sym) = LOC_REGISTER;
1910 else
1911 SYMBOL_CLASS (sym) = LOC_LOCAL;
1912 if (dn_bufp->dfparam.copyparam)
1913 {
1914 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1915 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1916 SYMBOL_VALUE (sym)
1917 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1918 #endif
1919 }
1920 else
1921 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1922 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1923 add_symbol_to_list (sym, &local_symbols);
1924 break;
1925 case K_SVAR:
1926 /* Static variables. */
1927 SYMBOL_CLASS (sym) = LOC_STATIC;
1928 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1929 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1930 if (dn_bufp->dsvar.public)
1931 add_symbol_to_list (sym, &global_symbols);
1932 else if (WITHIN_FUNCTION (objfile))
1933 add_symbol_to_list (sym, &local_symbols);
1934 else
1935 add_symbol_to_list (sym, &file_symbols);
1936 break;
1937 case K_DVAR:
1938 /* Dynamic variables. */
1939 if (dn_bufp->ddvar.regvar)
1940 SYMBOL_CLASS (sym) = LOC_REGISTER;
1941 else
1942 SYMBOL_CLASS (sym) = LOC_LOCAL;
1943 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1944 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1945 SYMBOL_VALUE (sym)
1946 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1947 #endif
1948 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1949 if (dn_bufp->ddvar.public)
1950 add_symbol_to_list (sym, &global_symbols);
1951 else if (WITHIN_FUNCTION (objfile))
1952 add_symbol_to_list (sym, &local_symbols);
1953 else
1954 add_symbol_to_list (sym, &file_symbols);
1955 break;
1956 case K_CONST:
1957 /* A constant (pascal?). */
1958 SYMBOL_CLASS (sym) = LOC_CONST;
1959 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1960 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1961 if (dn_bufp->dconst.public)
1962 add_symbol_to_list (sym, &global_symbols);
1963 else if (WITHIN_FUNCTION (objfile))
1964 add_symbol_to_list (sym, &local_symbols);
1965 else
1966 add_symbol_to_list (sym, &file_symbols);
1967 break;
1968 case K_TYPEDEF:
1969 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1970 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1971 if (dn_bufp->dtype.public)
1972 add_symbol_to_list (sym, &global_symbols);
1973 else if (WITHIN_FUNCTION (objfile))
1974 add_symbol_to_list (sym, &local_symbols);
1975 else
1976 add_symbol_to_list (sym, &file_symbols);
1977 break;
1978 case K_TAGDEF:
1979 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1980 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1981 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1982 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
1983 if (dn_bufp->dtype.public)
1984 add_symbol_to_list (sym, &global_symbols);
1985 else if (WITHIN_FUNCTION (objfile))
1986 add_symbol_to_list (sym, &local_symbols);
1987 else
1988 add_symbol_to_list (sym, &file_symbols);
1989 break;
1990 case K_POINTER:
1991 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
1992 (dn_bufp->dptr.pointsto,
1993 objfile));
1994 add_symbol_to_list (sym, &file_symbols);
1995 break;
1996 case K_ENUM:
1997 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1998 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
1999 add_symbol_to_list (sym, &file_symbols);
2000 break;
2001 case K_MEMENUM:
2002 break;
2003 case K_SET:
2004 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2005 add_symbol_to_list (sym, &file_symbols);
2006 break;
2007 case K_SUBRANGE:
2008 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2009 objfile);
2010 add_symbol_to_list (sym, &file_symbols);
2011 break;
2012 case K_ARRAY:
2013 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2014 add_symbol_to_list (sym, &file_symbols);
2015 break;
2016 case K_STRUCT:
2017 case K_UNION:
2018 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2019 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2020 add_symbol_to_list (sym, &file_symbols);
2021 break;
2022 default:
2023 break;
2024 }
2025 }