* corelow.c, exec.c, inftarg.c, m3-nat.c, op50-rom.c, procfs.c,
[deliverable/binutils-gdb.git] / gdb / hpread.c
1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
22
23 #include "defs.h"
24 #include "bfd.h"
25 #include <string.h>
26 #include "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 an array of length zero. */
1560 TYPE_LENGTH (type) = 0;
1561 }
1562 else
1563 TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8;
1564
1565 TYPE_NFIELDS (type) = 1;
1566 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype,
1567 objfile);
1568 dn_bufp = &save;
1569 TYPE_FIELDS (type) = (struct field *)
1570 obstack_alloc (&objfile->type_obstack, sizeof (struct field));
1571 TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype,
1572 objfile);
1573 return type;
1574 }
1575
1576 /* Read in and internalize a subrange debug symbol. */
1577 static struct type *
1578 hpread_read_subrange_type (hp_type, dn_bufp, objfile)
1579 DNTTPOINTER hp_type;
1580 union dnttentry *dn_bufp;
1581 struct objfile *objfile;
1582 {
1583 struct type *type;
1584
1585 /* Is it something we've already dealt with. */
1586 type = hpread_alloc_type (hp_type, objfile);
1587 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1588 return type;
1589
1590 /* Nope, internalize it. */
1591 TYPE_CODE (type) = TYPE_CODE_RANGE;
1592 TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8;
1593 TYPE_NFIELDS (type) = 2;
1594 TYPE_FIELDS (type) = (struct field *) obstack_alloc
1595 (&objfile->type_obstack, 2 * sizeof (struct field));
1596
1597 if (dn_bufp->dsubr.dyn_low)
1598 TYPE_FIELD_BITPOS (type, 0) = 0;
1599 else
1600 TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound;
1601
1602 if (dn_bufp->dsubr.dyn_high)
1603 TYPE_FIELD_BITPOS (type, 1) = -1;
1604 else
1605 TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound;
1606 TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype,
1607 objfile);
1608 return type;
1609 }
1610
1611 static struct type *
1612 hpread_type_lookup (hp_type, objfile)
1613 DNTTPOINTER hp_type;
1614 struct objfile *objfile;
1615 {
1616 union dnttentry *dn_bufp;
1617
1618 /* First see if it's a simple builtin type. */
1619 if (hp_type.dntti.immediate)
1620 return lookup_fundamental_type (objfile, hpread_type_translate (hp_type));
1621
1622 /* Not a builtin type. We'll have to read it in. */
1623 if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile))
1624 dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile);
1625 else
1626 return lookup_fundamental_type (objfile, FT_VOID);
1627
1628 switch (dn_bufp->dblock.kind)
1629 {
1630 case K_SRCFILE:
1631 case K_MODULE:
1632 case K_FUNCTION:
1633 case K_ENTRY:
1634 case K_BEGIN:
1635 case K_END:
1636 case K_IMPORT:
1637 case K_LABEL:
1638 case K_WITH:
1639 case K_COMMON:
1640 case K_FPARAM:
1641 case K_SVAR:
1642 case K_DVAR:
1643 case K_CONST:
1644 /* Opps. Something went very wrong. */
1645 return lookup_fundamental_type (objfile, FT_VOID);
1646
1647 case K_TYPEDEF:
1648 {
1649 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1650 objfile);
1651 char *suffix;
1652 suffix = VT (objfile) + dn_bufp->dtype.name;
1653
1654 TYPE_CPLUS_SPECIFIC (structtype)
1655 = (struct cplus_struct_type *) &cplus_struct_default;
1656 TYPE_NAME (structtype) = suffix;
1657 return structtype;
1658 }
1659
1660 case K_TAGDEF:
1661 {
1662 /* Just a little different from above. We have to tack on
1663 an identifier of some kind (struct, union, enum, etc). */
1664 struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type,
1665 objfile);
1666 char *prefix, *suffix;
1667 suffix = VT (objfile) + dn_bufp->dtype.name;
1668
1669 /* Lookup the next type in the list. It should be a structure,
1670 union, or enum type. We will need to attach that to our name. */
1671 if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
1672 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
1673 else
1674 abort ();
1675
1676 if (dn_bufp->dblock.kind == K_STRUCT)
1677 prefix = "struct ";
1678 else if (dn_bufp->dblock.kind == K_UNION)
1679 prefix = "union ";
1680 else
1681 prefix = "enum ";
1682
1683 /* Build the correct name. */
1684 structtype->name
1685 = (char *) obstack_alloc (&objfile->type_obstack,
1686 strlen (prefix) + strlen (suffix) + 1);
1687 TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix);
1688 TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix);
1689 TYPE_TAG_NAME (structtype) = suffix;
1690
1691 TYPE_CPLUS_SPECIFIC (structtype)
1692 = (struct cplus_struct_type *) &cplus_struct_default;
1693
1694 return structtype;
1695 }
1696 case K_POINTER:
1697 return lookup_pointer_type (hpread_type_lookup (dn_bufp->dptr.pointsto,
1698 objfile));
1699 case K_ENUM:
1700 return hpread_read_enum_type (hp_type, dn_bufp, objfile);
1701 case K_MEMENUM:
1702 return lookup_fundamental_type (objfile, FT_VOID);
1703 case K_SET:
1704 return hpread_read_set_type (hp_type, dn_bufp, objfile);
1705 case K_SUBRANGE:
1706 return hpread_read_subrange_type (hp_type, dn_bufp, objfile);
1707 case K_ARRAY:
1708 return hpread_read_array_type (hp_type, dn_bufp, objfile);
1709 case K_STRUCT:
1710 case K_UNION:
1711 return hpread_read_struct_type (hp_type, dn_bufp, objfile);
1712 case K_FIELD:
1713 return hpread_type_lookup (dn_bufp->dfield.type, objfile);
1714 case K_VARIANT:
1715 case K_FILE:
1716 return lookup_fundamental_type (objfile, FT_VOID);
1717 case K_FUNCTYPE:
1718 return lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval,
1719 objfile));
1720 case K_COBSTRUCT:
1721 case K_XREF:
1722 case K_SA:
1723 case K_MACRO:
1724 default:
1725 return lookup_fundamental_type (objfile, FT_VOID);
1726 }
1727 }
1728
1729 static SLTPOINTER
1730 hpread_record_lines (subfile, s_idx, e_idx, objfile)
1731 struct subfile *subfile;
1732 SLTPOINTER s_idx, e_idx;
1733 struct objfile *objfile;
1734 {
1735 union sltentry *sl_bufp;
1736
1737 while (s_idx <= e_idx)
1738 {
1739 sl_bufp = hpread_get_slt (s_idx, objfile);
1740 /* Only record "normal" entries in the SLT. */
1741 if (sl_bufp->snorm.sltdesc == SLT_NORMAL
1742 || sl_bufp->snorm.sltdesc == SLT_EXIT)
1743 record_line (subfile, sl_bufp->snorm.line, sl_bufp->snorm.address);
1744 s_idx++;
1745 }
1746 return e_idx;
1747 }
1748
1749 /* Internalize one native debug symbol. */
1750
1751 static void
1752 hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile,
1753 text_offset, text_size, filename, index)
1754 union dnttentry *dn_bufp;
1755 char *name;
1756 struct section_offsets *section_offsets;
1757 struct objfile *objfile;
1758 CORE_ADDR text_offset;
1759 int text_size;
1760 char *filename;
1761 int index;
1762 {
1763 unsigned long desc;
1764 int type;
1765 CORE_ADDR valu;
1766 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
1767 union dnttentry *dn_temp;
1768 DNTTPOINTER hp_type;
1769 struct symbol *sym;
1770 struct context_stack *new;
1771
1772 /* Allocate one GDB debug symbol and fill in some default values. */
1773 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1774 sizeof (struct symbol));
1775 memset (sym, 0, sizeof (struct symbol));
1776 SYMBOL_NAME (sym) = name;
1777 SYMBOL_LANGUAGE (sym) = language_auto;
1778 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1779 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1780 SYMBOL_LINE (sym) = 0;
1781 SYMBOL_VALUE (sym) = 0;
1782 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1783
1784 hp_type.dnttp.extension = 1;
1785 hp_type.dnttp.immediate = 0;
1786 hp_type.dnttp.global = 0;
1787 hp_type.dnttp.index = index;
1788
1789 type = dn_bufp->dblock.kind;
1790
1791 switch (type)
1792 {
1793 case K_SRCFILE:
1794 /* This type of symbol indicates from which source file or include file
1795 the following data comes. If there are no modules it also may
1796 indicate the start of a new source file, in which case we must
1797 finish the symbol table of the previous source file
1798 (if any) and start accumulating a new symbol table. */
1799
1800 valu = text_offset + offset; /* Relocate for dynamic loading */
1801 if (!last_source_file)
1802 start_symtab (name, NULL, valu);
1803
1804 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1805 SL_INDEX (objfile),
1806 dn_bufp->dsfile.address,
1807 objfile);
1808 start_subfile (name, NULL);
1809 break;
1810
1811 case K_MODULE:
1812 /* No need to do anything with these K_MODULE symbols anymore. */
1813 break;
1814
1815 case K_FUNCTION:
1816 case K_ENTRY:
1817 /* A function or secondary entry point. */
1818 valu = dn_bufp->dfunc.lowaddr + offset;
1819 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1820 SL_INDEX (objfile),
1821 dn_bufp->dfunc.address,
1822 objfile);
1823
1824 WITHIN_FUNCTION (objfile) = 1;
1825 CURRENT_FUNCTION_VALUE (objfile) = valu;
1826
1827 /* Stack must be empty now. */
1828 if (context_stack_depth != 0)
1829 complain (&lbrac_unmatched_complaint, (char *) symnum);
1830 new = push_context (0, valu);
1831
1832 SYMBOL_CLASS (sym) = LOC_BLOCK;
1833 SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile);
1834 if (dn_bufp->dfunc.public)
1835 add_symbol_to_list (sym, &global_symbols);
1836 else
1837 add_symbol_to_list (sym, &file_symbols);
1838 new->name = sym;
1839
1840 /* Search forward to the next scope beginning. */
1841 while (dn_bufp->dblock.kind != K_BEGIN)
1842 {
1843 dn_bufp = hpread_get_lntt (++index, objfile);
1844 if (dn_bufp->dblock.extension)
1845 continue;
1846 }
1847 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1848 SL_INDEX (objfile),
1849 dn_bufp->dbegin.address,
1850 objfile);
1851 SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile);
1852 record_line (current_subfile, SYMBOL_LINE (sym), valu);
1853 break;
1854
1855 case K_BEGIN:
1856 /* Begin a new scope. */
1857 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1858 SL_INDEX (objfile),
1859 dn_bufp->dbegin.address,
1860 objfile);
1861 valu = hpread_get_location (dn_bufp->dbegin.address, objfile);
1862 valu += offset; /* Relocate for dynamic loading */
1863 desc = hpread_get_depth (dn_bufp->dbegin.address, objfile);
1864 new = push_context (desc, valu);
1865 break;
1866
1867 case K_END:
1868 /* End a scope. */
1869 SL_INDEX (objfile) = hpread_record_lines (current_subfile,
1870 SL_INDEX (objfile),
1871 dn_bufp->dend.address + 1,
1872 objfile);
1873 switch (dn_bufp->dend.endkind)
1874 {
1875 case K_MODULE:
1876 /* Ending a module ends the symbol table for that module. */
1877 valu = text_offset + text_size + offset;
1878 (void) end_symtab (valu, 0, 0, objfile, 0);
1879 break;
1880
1881 case K_FUNCTION:
1882 /* Ending a function, well, ends the function's scope. */
1883 dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index,
1884 objfile);
1885 valu = dn_temp->dfunc.hiaddr + offset;
1886 new = pop_context ();
1887 /* Make a block for the local symbols within. */
1888 finish_block (new->name, &local_symbols, new->old_blocks,
1889 new->start_addr, valu, objfile);
1890 WITHIN_FUNCTION (objfile) = 0;
1891 break;
1892 case K_BEGIN:
1893 /* Just ending a local scope. */
1894 valu = hpread_get_location (dn_bufp->dend.address, objfile);
1895 /* Why in the hell is this needed? */
1896 valu += offset + 9; /* Relocate for dynamic loading */
1897 new = pop_context ();
1898 desc = dn_bufp->dend.beginscope.dnttp.index;
1899 if (desc != new->depth)
1900 complain (&lbrac_mismatch_complaint, (char *) symnum);
1901 /* Make a block for the local symbols within. */
1902 finish_block (new->name, &local_symbols, new->old_blocks,
1903 new->start_addr, valu, objfile);
1904 local_symbols = new->locals;
1905 break;
1906 }
1907 break;
1908 case K_LABEL:
1909 SYMBOL_NAMESPACE (sym) = LABEL_NAMESPACE;
1910 break;
1911 case K_FPARAM:
1912 /* Function parameters. */
1913 if (dn_bufp->dfparam.regparam)
1914 SYMBOL_CLASS (sym) = LOC_REGISTER;
1915 else
1916 SYMBOL_CLASS (sym) = LOC_LOCAL;
1917 if (dn_bufp->dfparam.copyparam)
1918 {
1919 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1920 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1921 SYMBOL_VALUE (sym)
1922 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1923 #endif
1924 }
1925 else
1926 SYMBOL_VALUE (sym) = dn_bufp->dfparam.location;
1927 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile);
1928 add_symbol_to_list (sym, &local_symbols);
1929 break;
1930 case K_SVAR:
1931 /* Static variables. */
1932 SYMBOL_CLASS (sym) = LOC_STATIC;
1933 SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location;
1934 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile);
1935 if (dn_bufp->dsvar.public)
1936 add_symbol_to_list (sym, &global_symbols);
1937 else if (WITHIN_FUNCTION (objfile))
1938 add_symbol_to_list (sym, &local_symbols);
1939 else
1940 add_symbol_to_list (sym, &file_symbols);
1941 break;
1942 case K_DVAR:
1943 /* Dynamic variables. */
1944 if (dn_bufp->ddvar.regvar)
1945 SYMBOL_CLASS (sym) = LOC_REGISTER;
1946 else
1947 SYMBOL_CLASS (sym) = LOC_LOCAL;
1948 SYMBOL_VALUE (sym) = dn_bufp->ddvar.location;
1949 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1950 SYMBOL_VALUE (sym)
1951 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile));
1952 #endif
1953 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile);
1954 if (dn_bufp->ddvar.public)
1955 add_symbol_to_list (sym, &global_symbols);
1956 else if (WITHIN_FUNCTION (objfile))
1957 add_symbol_to_list (sym, &local_symbols);
1958 else
1959 add_symbol_to_list (sym, &file_symbols);
1960 break;
1961 case K_CONST:
1962 /* A constant (pascal?). */
1963 SYMBOL_CLASS (sym) = LOC_CONST;
1964 SYMBOL_VALUE (sym) = dn_bufp->dconst.location;
1965 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile);
1966 if (dn_bufp->dconst.public)
1967 add_symbol_to_list (sym, &global_symbols);
1968 else if (WITHIN_FUNCTION (objfile))
1969 add_symbol_to_list (sym, &local_symbols);
1970 else
1971 add_symbol_to_list (sym, &file_symbols);
1972 break;
1973 case K_TYPEDEF:
1974 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1975 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1976 if (dn_bufp->dtype.public)
1977 add_symbol_to_list (sym, &global_symbols);
1978 else if (WITHIN_FUNCTION (objfile))
1979 add_symbol_to_list (sym, &local_symbols);
1980 else
1981 add_symbol_to_list (sym, &file_symbols);
1982 break;
1983 case K_TAGDEF:
1984 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1985 SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile);
1986 TYPE_NAME (sym->type) = SYMBOL_NAME (sym);
1987 TYPE_TAG_NAME (sym->type) = SYMBOL_NAME (sym);
1988 if (dn_bufp->dtype.public)
1989 add_symbol_to_list (sym, &global_symbols);
1990 else if (WITHIN_FUNCTION (objfile))
1991 add_symbol_to_list (sym, &local_symbols);
1992 else
1993 add_symbol_to_list (sym, &file_symbols);
1994 break;
1995 case K_POINTER:
1996 SYMBOL_TYPE (sym) = lookup_pointer_type (hpread_type_lookup
1997 (dn_bufp->dptr.pointsto,
1998 objfile));
1999 add_symbol_to_list (sym, &file_symbols);
2000 break;
2001 case K_ENUM:
2002 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2003 SYMBOL_TYPE (sym) = hpread_read_enum_type (hp_type, dn_bufp, objfile);
2004 add_symbol_to_list (sym, &file_symbols);
2005 break;
2006 case K_MEMENUM:
2007 break;
2008 case K_SET:
2009 SYMBOL_TYPE (sym) = hpread_read_set_type (hp_type, dn_bufp, objfile);
2010 add_symbol_to_list (sym, &file_symbols);
2011 break;
2012 case K_SUBRANGE:
2013 SYMBOL_TYPE (sym) = hpread_read_subrange_type (hp_type, dn_bufp,
2014 objfile);
2015 add_symbol_to_list (sym, &file_symbols);
2016 break;
2017 case K_ARRAY:
2018 SYMBOL_TYPE (sym) = hpread_read_array_type (hp_type, dn_bufp, objfile);
2019 add_symbol_to_list (sym, &file_symbols);
2020 break;
2021 case K_STRUCT:
2022 case K_UNION:
2023 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2024 SYMBOL_TYPE (sym) = hpread_read_struct_type (hp_type, dn_bufp, objfile);
2025 add_symbol_to_list (sym, &file_symbols);
2026 break;
2027 default:
2028 break;
2029 }
2030 }
This page took 0.071271 seconds and 4 git commands to generate.