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