1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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.
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
26 #include "hpux-symtab.h"
32 #include "complaints.h"
33 #include "gdb-stabs.h"
36 /* Private information attached to an objfile which we use to find
37 and internalize the HP C debug symbols within that objfile. */
39 struct hpread_symfile_info
41 /* The contents of each of the debug sections (there are 4 of them). */
47 /* We keep the size of the $VT$ section for range checking. */
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
;
55 /* To keep track of all the types we've processed. */
56 struct type
**type_vector
;
57 int type_vector_length
;
59 /* Keeps track of the beginning of a range of source lines. */
62 /* Some state variables we'll need. */
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
;
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)
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.
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)) \
96 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
98 complain (&string_table_offset_complaint, (char *) symnum); \
102 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
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.
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).
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. */
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))
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
;
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
;
136 void hpread_symfile_init
PARAMS ((struct objfile
*));
138 static struct type
*hpread_alloc_type
139 PARAMS ((DNTTPOINTER
, struct objfile
*));
141 static struct type
**hpread_lookup_type
142 PARAMS ((DNTTPOINTER
, struct objfile
*));
144 static struct type
*hpread_read_enum_type
145 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
147 static struct type
*hpread_read_set_type
148 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
150 static struct type
*hpread_read_subrange_type
151 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
153 static struct type
*hpread_read_struct_type
154 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
156 void hpread_build_psymtabs
157 PARAMS ((struct objfile
*, struct section_offsets
*, int));
159 void hpread_symfile_finish
PARAMS ((struct objfile
*));
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
*));
165 static struct partial_symtab
*hpread_end_psymtab
166 PARAMS ((struct partial_symtab
*, char **, int, int, CORE_ADDR
,
167 struct partial_symtab
**, int));
169 static struct symtab
*hpread_expand_symtab
170 PARAMS ((struct objfile
*, int, int, CORE_ADDR
, int,
171 struct section_offsets
*, char *));
173 static void hpread_process_one_debug_symbol
174 PARAMS ((union dnttentry
*, char *, struct section_offsets
*,
175 struct objfile
*, CORE_ADDR
, int, char *, int));
177 static SLTPOINTER hpread_record_lines
178 PARAMS ((struct subfile
*, SLTPOINTER
, SLTPOINTER
, struct objfile
*));
180 static struct type
*hpread_read_function_type
181 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
183 static struct type
* hpread_type_lookup
184 PARAMS ((DNTTPOINTER
, struct objfile
*));
186 static unsigned long hpread_get_depth
187 PARAMS ((SLTPOINTER
, struct objfile
*));
189 static unsigned long hpread_get_line
190 PARAMS ((SLTPOINTER
, struct objfile
*));
192 static ADDRESS hpread_get_location
193 PARAMS ((SLTPOINTER
, struct objfile
*));
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
));
205 /* Initialization for reading native HP C debug symbols from OBJFILE.
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
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. */
218 hpread_symfile_init (objfile
)
219 struct objfile
*objfile
;
221 asection
*vt_section
, *slt_section
, *lntt_section
, *gntt_section
;
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
));
228 /* We haven't read in any types yet. */
229 TYPE_VECTOR (objfile
) = 0;
231 /* Read in data from the $GNTT$ subspace. */
232 gntt_section
= bfd_get_section_by_name (objfile
->obfd
, "$GNTT$");
237 = obstack_alloc (&objfile
->symbol_obstack
,
238 bfd_section_size (objfile
->obfd
, gntt_section
));
240 bfd_get_section_contents (objfile
->obfd
, gntt_section
, GNTT (objfile
),
241 0, bfd_section_size (objfile
->obfd
, gntt_section
));
243 GNTT_SYMCOUNT (objfile
)
244 = bfd_section_size (objfile
->obfd
, gntt_section
) / DNTTBLOCKSIZE
;
246 /* Read in data from the $LNTT$ subspace. Also keep track of the number
248 lntt_section
= bfd_get_section_by_name (objfile
->obfd
, "$LNTT$");
253 = obstack_alloc (&objfile
->symbol_obstack
,
254 bfd_section_size (objfile
->obfd
, lntt_section
));
256 bfd_get_section_contents (objfile
->obfd
, lntt_section
, LNTT (objfile
),
257 0, bfd_section_size (objfile
->obfd
, lntt_section
));
259 LNTT_SYMCOUNT (objfile
)
260 = bfd_section_size (objfile
->obfd
, lntt_section
) / DNTTBLOCKSIZE
;
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$");
269 obstack_alloc (&objfile
->symbol_obstack
,
270 bfd_section_size (objfile
->obfd
, slt_section
));
272 bfd_get_section_contents (objfile
->obfd
, slt_section
, SLT (objfile
),
273 0, bfd_section_size (objfile
->obfd
, slt_section
));
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$");
281 VT_SIZE (objfile
) = bfd_section_size (objfile
->obfd
, vt_section
);
284 (char *) obstack_alloc (&objfile
->symbol_obstack
,
287 bfd_get_section_contents (objfile
->obfd
, vt_section
, VT (objfile
),
288 0, VT_SIZE (objfile
));
291 /* Scan and build partial symbols for a symbol file.
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.
297 We assume hpread_symfile_init has been called to initialize the
298 symbol reader's private data structures.
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). */
306 hpread_build_psymtabs (objfile
, section_offsets
, mainline
)
307 struct objfile
*objfile
;
308 struct section_offsets
*section_offsets
;
312 int past_first_source_file
= 0;
313 struct cleanup
*old_chain
;
315 int hp_symnum
, symcount
, i
;
317 union dnttentry
*dn_bufp
;
323 /* Current partial symtab */
324 struct partial_symtab
*pst
;
326 /* List of current psymtab's include files */
327 char **psymtab_include_list
;
328 int includes_allocated
;
331 /* Index within current psymtab dependency list */
332 struct partial_symtab
**dependency_list
;
333 int dependencies_used
, dependencies_allocated
;
335 /* Just in case the stabs reader left turds lying around. */
337 make_cleanup (really_free_pendings
, 0);
339 pst
= (struct partial_symtab
*) 0;
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. */
345 includes_allocated
= 30;
347 psymtab_include_list
= (char **) alloca (includes_allocated
*
350 dependencies_allocated
= 30;
351 dependencies_used
= 0;
353 (struct partial_symtab
**) alloca (dependencies_allocated
*
354 sizeof (struct partial_symtab
*));
356 old_chain
= make_cleanup (free_objfile
, objfile
);
358 last_source_file
= 0;
360 /* Make two passes, one ofr the GNTT symbols, the other for the
362 for (i
= 0; i
< 1; i
++)
364 int within_function
= 0;
367 symcount
= GNTT_SYMCOUNT (objfile
);
369 symcount
= LNTT_SYMCOUNT (objfile
);
371 for (hp_symnum
= 0; hp_symnum
< symcount
; hp_symnum
++)
375 dn_bufp
= hpread_get_gntt (hp_symnum
, objfile
);
377 dn_bufp
= hpread_get_lntt (hp_symnum
, objfile
);
379 if (dn_bufp
->dblock
.extension
)
382 /* Only handle things which are necessary for minimal symbols.
383 everything else is ignored. */
384 switch (dn_bufp
->dblock
.kind
)
388 /* A source file of some kind. Note this may simply
389 be an included file. */
390 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
392 /* Check if this is the source file we are already working
394 if (pst
&& !strcmp (namestring
, pst
->filename
))
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"))
405 for (j
= 0; j
< includes_used
; j
++)
406 if (!strcmp (namestring
, psymtab_include_list
[j
]))
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
)
419 char **orig
= psymtab_include_list
;
421 psymtab_include_list
= (char **)
422 alloca ((includes_allocated
*= 2) *
424 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
425 includes_used
* sizeof (char *));
435 pst
->filename
= (char *)
436 obstack_alloc (&pst
->objfile
->psymbol_obstack
,
437 strlen (namestring
) + 1);
438 strcpy (pst
->filename
, namestring
);
445 /* This is a bonafide new source file.
446 End the current partial symtab and start a new one. */
448 if (pst
&& past_first_source_file
)
450 texthigh
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
451 hpread_end_psymtab (pst
, psymtab_include_list
,
453 hp_symnum
* DNTTBLOCKSIZE
, texthigh
,
454 dependency_list
, dependencies_used
);
455 pst
= (struct partial_symtab
*) 0;
457 dependencies_used
= 0;
460 past_first_source_file
= 1;
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
,
466 hp_symnum
* DNTTBLOCKSIZE
,
467 objfile
->global_psymbols
.next
,
468 objfile
->static_psymbols
.next
);
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
);
483 pst
= hpread_start_psymtab (objfile
, section_offsets
,
485 hp_symnum
* DNTTBLOCKSIZE
,
486 objfile
->global_psymbols
.next
,
487 objfile
->static_psymbols
.next
);
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
);
509 /* Scope block begin/end. We only care about function
510 and file blocks right now. */
511 if (dn_bufp
->dend
.endkind
== K_MODULE
)
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;
519 dependencies_used
= 0;
522 if (dn_bufp
->dend
.endkind
== K_FUNCTION
)
530 /* Variables, typedefs an the like. */
531 enum address_class storage
;
532 enum namespace namespace;
534 /* Don't add locals to the partial symbol table. */
536 && (dn_bufp
->dblock
.kind
== K_SVAR
537 || dn_bufp
->dblock
.kind
== K_DVAR
))
540 /* TAGDEFs go into the structure namespace. */
541 if (dn_bufp
->dblock
.kind
== K_TAGDEF
)
542 namespace = STRUCT_NAMESPACE
;
544 namespace = VAR_NAMESPACE
;
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
)
557 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
560 pst
= hpread_start_psymtab (objfile
, section_offsets
,
562 hp_symnum
* DNTTBLOCKSIZE
,
563 objfile
->global_psymbols
.next
,
564 objfile
->static_psymbols
.next
);
566 if (dn_bufp
->dsvar
.public)
568 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
570 objfile
->global_psymbols
,
571 dn_bufp
->dsvar
.location
,
572 language_unknown
, objfile
);
576 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
578 objfile
->static_psymbols
,
579 dn_bufp
->dsvar
.location
,
580 language_unknown
, objfile
);
586 /* Constants and members of enumerated types. */
587 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
590 pst
= hpread_start_psymtab (objfile
, section_offsets
,
592 hp_symnum
* DNTTBLOCKSIZE
,
593 objfile
->global_psymbols
.next
,
594 objfile
->static_psymbols
.next
);
596 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
597 VAR_NAMESPACE
, LOC_CONST
,
598 objfile
->static_psymbols
, 0,
599 language_unknown
, objfile
);
607 /* End any pending partial symbol table. */
610 hpread_end_psymtab (pst
, psymtab_include_list
, includes_used
,
611 hp_symnum
* DNTTBLOCKSIZE
, 0,
612 dependency_list
, dependencies_used
);
615 discard_cleanups (old_chain
);
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. */
624 hpread_symfile_finish (objfile
)
625 struct objfile
*objfile
;
627 if (objfile
->sym_private
!= NULL
)
629 mfree (objfile
->md
, objfile
->sym_private
);
634 /* The remaining functions are all for internal use only. */
636 /* Various small functions to get entries in the debug symbol sections. */
638 static union dnttentry
*
639 hpread_get_lntt (index
, objfile
)
641 struct objfile
*objfile
;
643 return (union dnttentry
*)&(LNTT (objfile
)[index
* DNTTBLOCKSIZE
]);
646 static union dnttentry
*
647 hpread_get_gntt (index
, objfile
)
649 struct objfile
*objfile
;
651 return (union dnttentry
*)&(GNTT (objfile
)[index
* DNTTBLOCKSIZE
]);
654 static union sltentry
*
655 hpread_get_slt (index
, objfile
)
657 struct objfile
*objfile
;
659 return (union sltentry
*)&(SLT (objfile
)[index
* SLTBLOCKSIZE
]);
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. */
668 hpread_get_textlow (global
, index
, objfile
)
671 struct objfile
*objfile
;
673 union dnttentry
*dn_bufp
;
674 struct minimal_symbol
*msymbol
;
676 /* Look for a K_FUNCTION symbol. */
680 dn_bufp
= hpread_get_gntt (index
++, objfile
);
682 dn_bufp
= hpread_get_lntt (index
++, objfile
);
683 } while (dn_bufp
->dblock
.kind
!= K_FUNCTION
684 && dn_bufp
->dblock
.kind
!= K_END
);
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
)
691 /* The minimal symbols are typically more accurate for some reason. */
692 msymbol
= lookup_minimal_symbol (dn_bufp
->dfunc
.name
+ VT (objfile
),
695 return SYMBOL_VALUE_ADDRESS (msymbol
);
697 return dn_bufp
->dfunc
.lowaddr
;
700 /* Get the nesting depth for the source line identified by INDEX. */
703 hpread_get_depth (index
, objfile
)
705 struct objfile
*objfile
;
707 union sltentry
*sl_bufp
;
709 sl_bufp
= hpread_get_slt (index
, objfile
);
710 return sl_bufp
->sspec
.backptr
.dnttp
.index
;
713 /* Get the source line number the the line identified by INDEX. */
716 hpread_get_line (index
, objfile
)
718 struct objfile
*objfile
;
720 union sltentry
*sl_bufp
;
722 sl_bufp
= hpread_get_slt (index
, objfile
);
723 return sl_bufp
->snorm
.line
;
727 hpread_get_location (index
, objfile
)
729 struct objfile
*objfile
;
731 union sltentry
*sl_bufp
;
734 /* code location of special sltentrys is determined from context */
735 sl_bufp
= hpread_get_slt (index
, objfile
);
737 if (sl_bufp
->snorm
.sltdesc
== SLT_END
)
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
;
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
;
754 /* Return 1 if an HP debug symbol of type KIND has a name associated with
755 it, else return 0. */
758 hpread_has_name (kind
)
802 /* Allocate and partially fill a partial symtab. It will be
803 completely filled at the end of the symbol list.
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
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
;
817 struct partial_symbol
*global_syms
;
818 struct partial_symbol
*static_syms
;
820 struct partial_symtab
*result
=
821 start_psymtab_common (objfile
, section_offsets
,
822 filename
, textlow
, global_syms
, static_syms
);
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
;
833 /* Close off the current usage of PST.
834 Returns PST or NULL if the partial symtab was empty and thrown away.
836 FIXME: List variables and peculiarities of same. */
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
;
844 int capping_symbol_offset
;
845 CORE_ADDR capping_text
;
846 struct partial_symtab
**dependency_list
;
847 int number_dependencies
;
850 struct objfile
*objfile
= pst
-> objfile
;
852 if (capping_symbol_offset
!= -1)
853 LDSYMLEN(pst
) = capping_symbol_offset
- LDSYMOFF(pst
);
854 pst
->texthigh
= capping_text
;
857 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
859 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
861 pst
->number_of_dependencies
= number_dependencies
;
862 if (number_dependencies
)
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
*));
871 pst
->dependencies
= 0;
873 for (i
= 0; i
< num_includes
; i
++)
875 struct partial_symtab
*subpst
=
876 allocate_psymtab (include_list
[i
], objfile
);
878 subpst
->section_offsets
= pst
->section_offsets
;
879 subpst
->read_symtab_private
=
880 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
881 sizeof (struct symloc
));
885 subpst
->texthigh
= 0;
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;
895 subpst
->globals_offset
=
896 subpst
->n_global_syms
=
897 subpst
->statics_offset
=
898 subpst
->n_static_syms
= 0;
902 subpst
->read_symtab
= pst
->read_symtab
;
905 sort_pst_symbols (pst
);
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
);
912 if (num_includes
== 0
913 && number_dependencies
== 0
914 && pst
->n_global_syms
== 0
915 && pst
->n_static_syms
== 0)
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
;
926 /* First, snip it out of the psymtab chain */
928 if (pst
->objfile
->psymtabs
== pst
)
929 pst
->objfile
->psymtabs
= pst
->next
;
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
;
935 /* Next, put it on a free list for recycling */
937 pst
->next
= pst
->objfile
->free_psymtabs
;
938 pst
->objfile
->free_psymtabs
= pst
;
940 /* Indicate that psymtab was thrown away. */
941 pst
= (struct partial_symtab
*)NULL
;
946 /* Do the dirty work of reading in the full symbol from a partial symbol
950 hpread_psymtab_to_symtab_1 (pst
)
951 struct partial_symtab
*pst
;
953 struct cleanup
*old_chain
;
956 /* Get out quick if passed junk. */
960 /* Complain if we've already read in this symbol table. */
963 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
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
)
972 /* Inform about additional files that need to be read in. */
975 fputs_filtered (" ", stdout
);
977 fputs_filtered ("and ", stdout
);
979 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
980 wrap_here (""); /* Flush output */
983 hpread_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
986 /* If it's real... */
989 /* Init stuff necessary for reading in symbols */
991 old_chain
= make_cleanup (really_free_pendings
, 0);
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
);
999 do_cleanups (old_chain
);
1005 /* Read in all of the symbols for a given psymtab for real.
1006 Be verbose about it if the user wants that. */
1009 hpread_psymtab_to_symtab (pst
)
1010 struct partial_symtab
*pst
;
1012 /* Get out quick if given junk. */
1019 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1024 if (LDSYMLEN (pst
) || pst
->number_of_dependencies
)
1026 /* Print the message now, before reading the string table,
1027 to avoid disconcerting pauses. */
1030 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1034 hpread_psymtab_to_symtab_1 (pst
);
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
);
1040 /* Finish up the debug error message. */
1042 printf_filtered ("done.\n");
1045 /* Read in a defined section of a specific object file's symbols.
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. */
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
;
1062 CORE_ADDR text_offset
;
1064 struct section_offsets
*section_offsets
;
1068 union dnttentry
*dn_bufp
;
1069 unsigned max_symnum
;
1071 int sym_index
= sym_offset
/ DNTTBLOCKSIZE
;
1073 current_objfile
= objfile
;
1076 last_source_file
= 0;
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);
1083 max_symnum
= sym_size
/ DNTTBLOCKSIZE
;
1085 /* Read in and process each debug symbol within the specified range. */
1087 symnum
< max_symnum
;
1090 QUIT
; /* Allow this to be interruptable */
1091 dn_bufp
= hpread_get_lntt (sym_index
+ symnum
, objfile
);
1093 if (dn_bufp
->dblock
.extension
)
1096 /* Yow! We call SET_NAMESTRING on things without names! */
1097 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
1099 hpread_process_one_debug_symbol (dn_bufp
, namestring
, section_offsets
,
1100 objfile
, text_offset
, text_size
,
1101 filename
, symnum
+ sym_index
);
1104 current_objfile
= NULL
;
1106 return end_symtab (text_offset
+ text_size
, 0, 0, objfile
, 0);
1110 /* Convert basic types from HP debug format into GDB internal format. */
1113 hpread_type_translate (typep
)
1116 if (!typep
.dntti
.immediate
)
1119 switch (typep
.dntti
.type
)
1122 case T_BOOLEAN_S300_COMPAT
:
1123 case T_BOOLEAN_VAX_COMPAT
:
1125 /* Ugh. No way to distinguish between signed and unsigned chars. */
1130 if (typep
.dntti
.bitlength
<= 8)
1132 if (typep
.dntti
.bitlength
<= 16)
1134 if (typep
.dntti
.bitlength
<= 32)
1136 return FT_LONG_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
;
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
;
1158 if (typep
.dntti
.bitlength
== 64)
1159 return FT_DBL_PREC_FLOAT
;
1160 if (typep
.dntti
.bitlength
== 128)
1161 return FT_EXT_PREC_FLOAT
;
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
;
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
:
1183 /* Return the type associated with the index found in HP_TYPE. */
1185 static struct type
**
1186 hpread_lookup_type (hp_type
, objfile
)
1187 DNTTPOINTER hp_type
;
1188 struct objfile
*objfile
;
1191 int index
= hp_type
.dnttp
.index
;
1193 if (hp_type
.dntti
.immediate
)
1196 if (index
< LNTT_SYMCOUNT (objfile
))
1198 if (index
>= TYPE_VECTOR_LENGTH (objfile
))
1200 old_len
= TYPE_VECTOR_LENGTH (objfile
);
1203 TYPE_VECTOR_LENGTH (objfile
) = 100;
1204 TYPE_VECTOR (objfile
) = (struct type
**)
1205 malloc (TYPE_VECTOR_LENGTH (objfile
) * sizeof (struct type
*));
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
*));
1216 return &TYPE_VECTOR (objfile
)[index
];
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. */
1226 static struct type
*
1227 hpread_alloc_type (hp_type
, objfile
)
1228 DNTTPOINTER hp_type
;
1229 struct objfile
*objfile
;
1231 struct type
**type_addr
;
1233 type_addr
= hpread_lookup_type (hp_type
, objfile
);
1234 if (*type_addr
== 0)
1235 *type_addr
= alloc_type (objfile
);
1237 TYPE_CPLUS_SPECIFIC (*type_addr
)
1238 = (struct cplus_struct_type
*) &cplus_struct_default
;
1242 /* Read a native enumerated type and return it in GDB internal form. */
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
;
1251 struct pending
**symlist
, *osyms
, *syms
;
1252 int o_nsyms
, nsyms
= 0;
1254 union dnttentry
*memp
;
1259 type
= hpread_alloc_type (hp_type
, objfile
);
1260 TYPE_LENGTH (type
) = 4;
1262 symlist
= &file_symbols
;
1264 o_nsyms
= osyms
? osyms
->nsyms
: 0;
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
)
1270 memp
= hpread_get_lntt (mem
.dnttp
.index
, objfile
);
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
);
1282 mem
= memp
->dmember
.nextmem
;
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
);
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.
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
)
1305 for (; j
< syms
->nsyms
; j
++, n
++)
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;
1321 /* Read and internalize a native function debug symbol. */
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
;
1329 struct type
*type
, *type1
;
1330 struct pending
**symlist
, *osyms
, *syms
;
1331 int o_nsyms
, nsyms
= 0;
1333 union dnttentry
*paramp
;
1338 param
= dn_bufp
->dfunc
.firstparam
;
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
)
1345 /* Nope, so read it in and store it away. */
1346 type1
= lookup_function_type (hpread_type_lookup (dn_bufp
->dfunc
.retval
,
1348 memcpy ((char *) type
, (char *) type1
, sizeof (struct type
));
1350 symlist
= &local_symbols
;
1352 o_nsyms
= osyms
? osyms
->nsyms
: 0;
1354 /* Now examine each parameter noting its type, location, and a
1355 wealth of other information. */
1356 while (param
.word
&& param
.word
!= DNTTNIL
)
1358 paramp
= hpread_get_lntt (param
.dnttp
.index
, objfile
);
1360 param
= paramp
->dfparam
.nextparam
;
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
;
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
;
1375 SYMBOL_CLASS (sym
) = LOC_ARG
;
1376 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1377 if (paramp
->dfparam
.copyparam
)
1379 SYMBOL_VALUE (sym
) = paramp
->dfparam
.location
;
1380 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1382 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
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
;
1389 SYMBOL_VALUE (sym
) = paramp
->dfparam
.location
;
1392 SYMBOL_TYPE (sym
) = hpread_type_lookup (paramp
->dfparam
.type
, objfile
);
1394 /* Add it to the list. */
1395 add_symbol_to_list (sym
, symlist
);
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
);
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
)
1416 for (; j
< syms
->nsyms
; j
++, n
++)
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;
1430 /* Read in and internalize a structure definition. */
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
;
1440 struct nextfield
*next
;
1445 struct nextfield
*list
= 0;
1446 struct nextfield
*new;
1449 union dnttentry
*fieldp
;
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
))
1457 /* Get the basic type correct. */
1458 if (dn_bufp
->dblock
.kind
== K_STRUCT
)
1460 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1461 TYPE_LENGTH (type
) = dn_bufp
->dstruct
.bitlength
/ 8;
1463 else if (dn_bufp
->dblock
.kind
== K_UNION
)
1465 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1466 TYPE_LENGTH (type
) = dn_bufp
->dunion
.bitlength
/ 8;
1472 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1474 /* Read in and internalize all the fields. */
1475 field
= dn_bufp
->dstruct
.firstfield
;
1476 while (field
.word
!= DNTTNIL
&& field
.dnttp
.extension
)
1478 fieldp
= hpread_get_lntt (field
.dnttp
.index
, objfile
);
1480 /* Get space to record the next field's data. */
1481 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
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
;
1490 list
->field
.bitsize
= 0;
1492 field
= fieldp
->dfield
.nextfield
;
1493 list
->field
.type
= hpread_type_lookup (fieldp
->dfield
.type
, objfile
);
1496 TYPE_NFIELDS (type
) = nfields
;
1497 TYPE_FIELDS (type
) = (struct field
*)
1498 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
) * nfields
);
1500 /* Copy the saved-up fields into the field vector. */
1501 for (n
= nfields
; list
; list
= list
->next
)
1504 TYPE_FIELD (type
, n
) = list
->field
;
1509 /* Read in and internalize a set debug symbol. */
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
;
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
)
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
,
1533 /* Read in and internalize an array debug symbol. */
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
;
1542 union dnttentry save
;
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
);
1549 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1551 /* values are not normalized. */
1552 if (!((dn_bufp
->darray
.arrayisbytes
&& dn_bufp
->darray
.elemisbytes
)
1553 || (!dn_bufp
->darray
.arrayisbytes
&& !dn_bufp
->darray
.elemisbytes
)))
1555 else if (dn_bufp
->darray
.arraylength
== 0x7fffffff)
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;
1563 TYPE_LENGTH (type
) = dn_bufp
->darray
.arraylength
/ 8;
1565 TYPE_NFIELDS (type
) = 1;
1566 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->darray
.elemtype
,
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
,
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
;
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
)
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
));
1597 if (dn_bufp
->dsubr
.dyn_low
)
1598 TYPE_FIELD_BITPOS (type
, 0) = 0;
1600 TYPE_FIELD_BITPOS (type
, 0) = dn_bufp
->dsubr
.lowbound
;
1602 if (dn_bufp
->dsubr
.dyn_high
)
1603 TYPE_FIELD_BITPOS (type
, 1) = -1;
1605 TYPE_FIELD_BITPOS (type
, 1) = dn_bufp
->dsubr
.highbound
;
1606 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->dsubr
.subtype
,
1611 static struct type
*
1612 hpread_type_lookup (hp_type
, objfile
)
1613 DNTTPOINTER hp_type
;
1614 struct objfile
*objfile
;
1616 union dnttentry
*dn_bufp
;
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
));
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
);
1626 return lookup_fundamental_type (objfile
, FT_VOID
);
1628 switch (dn_bufp
->dblock
.kind
)
1644 /* Opps. Something went very wrong. */
1645 return lookup_fundamental_type (objfile
, FT_VOID
);
1649 struct type
*structtype
= hpread_type_lookup (dn_bufp
->dtype
.type
,
1652 suffix
= VT (objfile
) + dn_bufp
->dtype
.name
;
1654 TYPE_CPLUS_SPECIFIC (structtype
)
1655 = (struct cplus_struct_type
*) &cplus_struct_default
;
1656 TYPE_NAME (structtype
) = suffix
;
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
,
1666 char *prefix
, *suffix
;
1667 suffix
= VT (objfile
) + dn_bufp
->dtype
.name
;
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
);
1676 if (dn_bufp
->dblock
.kind
== K_STRUCT
)
1678 else if (dn_bufp
->dblock
.kind
== K_UNION
)
1683 /* Build the correct 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
;
1691 TYPE_CPLUS_SPECIFIC (structtype
)
1692 = (struct cplus_struct_type
*) &cplus_struct_default
;
1697 return lookup_pointer_type (hpread_type_lookup (dn_bufp
->dptr
.pointsto
,
1700 return hpread_read_enum_type (hp_type
, dn_bufp
, objfile
);
1702 return lookup_fundamental_type (objfile
, FT_VOID
);
1704 return hpread_read_set_type (hp_type
, dn_bufp
, objfile
);
1706 return hpread_read_subrange_type (hp_type
, dn_bufp
, objfile
);
1708 return hpread_read_array_type (hp_type
, dn_bufp
, objfile
);
1711 return hpread_read_struct_type (hp_type
, dn_bufp
, objfile
);
1713 return hpread_type_lookup (dn_bufp
->dfield
.type
, objfile
);
1716 return lookup_fundamental_type (objfile
, FT_VOID
);
1718 return lookup_function_type (hpread_type_lookup (dn_bufp
->dfunctype
.retval
,
1725 return lookup_fundamental_type (objfile
, FT_VOID
);
1730 hpread_record_lines (subfile
, s_idx
, e_idx
, objfile
)
1731 struct subfile
*subfile
;
1732 SLTPOINTER s_idx
, e_idx
;
1733 struct objfile
*objfile
;
1735 union sltentry
*sl_bufp
;
1737 while (s_idx
<= e_idx
)
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
);
1749 /* Internalize one native debug symbol. */
1752 hpread_process_one_debug_symbol (dn_bufp
, name
, section_offsets
, objfile
,
1753 text_offset
, text_size
, filename
, index
)
1754 union dnttentry
*dn_bufp
;
1756 struct section_offsets
*section_offsets
;
1757 struct objfile
*objfile
;
1758 CORE_ADDR text_offset
;
1766 int offset
= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
1767 union dnttentry
*dn_temp
;
1768 DNTTPOINTER hp_type
;
1770 struct context_stack
*new;
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
;
1784 hp_type
.dnttp
.extension
= 1;
1785 hp_type
.dnttp
.immediate
= 0;
1786 hp_type
.dnttp
.global
= 0;
1787 hp_type
.dnttp
.index
= index
;
1789 type
= dn_bufp
->dblock
.kind
;
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. */
1800 valu
= text_offset
+ offset
; /* Relocate for dynamic loading */
1801 if (!last_source_file
)
1802 start_symtab (name
, NULL
, valu
);
1804 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1806 dn_bufp
->dsfile
.address
,
1808 start_subfile (name
, NULL
);
1812 /* No need to do anything with these K_MODULE symbols anymore. */
1817 /* A function or secondary entry point. */
1818 valu
= dn_bufp
->dfunc
.lowaddr
+ offset
;
1819 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1821 dn_bufp
->dfunc
.address
,
1824 WITHIN_FUNCTION (objfile
) = 1;
1825 CURRENT_FUNCTION_VALUE (objfile
) = valu
;
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
);
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
);
1837 add_symbol_to_list (sym
, &file_symbols
);
1840 /* Search forward to the next scope beginning. */
1841 while (dn_bufp
->dblock
.kind
!= K_BEGIN
)
1843 dn_bufp
= hpread_get_lntt (++index
, objfile
);
1844 if (dn_bufp
->dblock
.extension
)
1847 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1849 dn_bufp
->dbegin
.address
,
1851 SYMBOL_LINE (sym
) = hpread_get_line (dn_bufp
->dbegin
.address
, objfile
);
1852 record_line (current_subfile
, SYMBOL_LINE (sym
), valu
);
1856 /* Begin a new scope. */
1857 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1859 dn_bufp
->dbegin
.address
,
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
);
1869 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1871 dn_bufp
->dend
.address
+ 1,
1873 switch (dn_bufp
->dend
.endkind
)
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);
1882 /* Ending a function, well, ends the function's scope. */
1883 dn_temp
= hpread_get_lntt (dn_bufp
->dend
.beginscope
.dnttp
.index
,
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;
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
;
1909 SYMBOL_NAMESPACE (sym
) = LABEL_NAMESPACE
;
1912 /* Function parameters. */
1913 if (dn_bufp
->dfparam
.regparam
)
1914 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1916 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1917 if (dn_bufp
->dfparam
.copyparam
)
1919 SYMBOL_VALUE (sym
) = dn_bufp
->dfparam
.location
;
1920 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1922 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
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
);
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
);
1940 add_symbol_to_list (sym
, &file_symbols
);
1943 /* Dynamic variables. */
1944 if (dn_bufp
->ddvar
.regvar
)
1945 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1947 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1948 SYMBOL_VALUE (sym
) = dn_bufp
->ddvar
.location
;
1949 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1951 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
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
);
1959 add_symbol_to_list (sym
, &file_symbols
);
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
);
1971 add_symbol_to_list (sym
, &file_symbols
);
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
);
1981 add_symbol_to_list (sym
, &file_symbols
);
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
);
1993 add_symbol_to_list (sym
, &file_symbols
);
1996 SYMBOL_TYPE (sym
) = lookup_pointer_type (hpread_type_lookup
1997 (dn_bufp
->dptr
.pointsto
,
1999 add_symbol_to_list (sym
, &file_symbols
);
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
);
2009 SYMBOL_TYPE (sym
) = hpread_read_set_type (hp_type
, dn_bufp
, objfile
);
2010 add_symbol_to_list (sym
, &file_symbols
);
2013 SYMBOL_TYPE (sym
) = hpread_read_subrange_type (hp_type
, dn_bufp
,
2015 add_symbol_to_list (sym
, &file_symbols
);
2018 SYMBOL_TYPE (sym
) = hpread_read_array_type (hp_type
, dn_bufp
, objfile
);
2019 add_symbol_to_list (sym
, &file_symbols
);
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
);