1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Written by the Center for Software Science at the University of Utah
23 and by Cygnus Support. */
27 #include "gdb_string.h"
28 #include "hp-symtab.h"
34 #include "complaints.h"
35 #include "gdb-stabs.h"
39 /* Private information attached to an objfile which we use to find
40 and internalize the HP C debug symbols within that objfile. */
42 struct hpread_symfile_info
44 /* The contents of each of the debug sections (there are 4 of them). */
50 /* We keep the size of the $VT$ section for range checking. */
53 /* Some routines still need to know the number of symbols in the
54 main debug sections ($LNTT$ and $GNTT$). */
55 unsigned int lntt_symcount
;
56 unsigned int gntt_symcount
;
58 /* To keep track of all the types we've processed. */
59 struct type
**type_vector
;
60 int type_vector_length
;
62 /* Keeps track of the beginning of a range of source lines. */
65 /* Some state variables we'll need. */
68 /* Keep track of the current function's address. We may need to look
69 up something based on this address. */
70 unsigned int current_function_value
;
73 /* Accessor macros to get at the fields. */
74 #define HPUX_SYMFILE_INFO(o) \
75 ((struct hpread_symfile_info *)((o)->sym_private))
76 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
77 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
78 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
79 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
80 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
81 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
82 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
83 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
84 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
85 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
86 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
87 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
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.
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)) \
98 else if (((unsigned)(SYM)->dsfile.name) >= VT_SIZE (OBJFILE)) \
100 complain (&string_table_offset_complaint, (char *) symnum); \
104 *NAMEP = (SYM)->dsfile.name + VT (OBJFILE)
106 /* We put a pointer to this structure in the read_symtab_private field
111 /* The offset within the file symbol table of first local symbol for
116 /* Length (in bytes) of the section of the symbol table devoted to
117 this file's symbols (actually, the section bracketed may contain
118 more than just this file's symbols). If ldsymlen is 0, the only
119 reason for this thing's existence is the dependency list.
120 Nothing else will happen when it is read in. */
125 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
126 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
127 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
129 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
130 /* Nonzero means give verbose info on gdb action. */
131 extern int info_verbose
;
133 /* Complaints about the symbols we have encountered. */
134 extern struct complaint string_table_offset_complaint
;
135 extern struct complaint lbrac_unmatched_complaint
;
136 extern struct complaint lbrac_mismatch_complaint
;
139 void hpread_symfile_init (struct objfile
*);
141 static struct type
*hpread_read_array_type (dnttpointer
, union dnttentry
*,
144 static struct type
*hpread_alloc_type (dnttpointer
, struct objfile
*);
146 static struct type
**hpread_lookup_type (dnttpointer
, struct objfile
*);
148 static struct type
*hpread_read_enum_type
149 (dnttpointer
, union dnttentry
*, struct objfile
*);
151 static struct type
*hpread_read_set_type
152 (dnttpointer
, union dnttentry
*, struct objfile
*);
154 static struct type
*hpread_read_subrange_type
155 (dnttpointer
, union dnttentry
*, struct objfile
*);
157 static struct type
*hpread_read_struct_type
158 (dnttpointer
, union dnttentry
*, struct objfile
*);
160 void hpread_build_psymtabs (struct objfile
*, int);
162 void hpread_symfile_finish (struct objfile
*);
164 static struct partial_symtab
*hpread_start_psymtab
165 (struct objfile
*, char *, CORE_ADDR
, int,
166 struct partial_symbol
**, struct partial_symbol
**);
168 static struct partial_symtab
*hpread_end_psymtab
169 (struct partial_symtab
*, char **, int, int, CORE_ADDR
,
170 struct partial_symtab
**, int);
172 static struct symtab
*hpread_expand_symtab
173 (struct objfile
*, int, int, CORE_ADDR
, int,
174 struct section_offsets
*, char *);
176 static void hpread_process_one_debug_symbol
177 (union dnttentry
*, char *, struct section_offsets
*,
178 struct objfile
*, CORE_ADDR
, int, char *, int);
180 static sltpointer hpread_record_lines
181 (struct subfile
*, sltpointer
, sltpointer
, struct objfile
*, CORE_ADDR
);
183 static struct type
*hpread_read_function_type
184 (dnttpointer
, union dnttentry
*, struct objfile
*);
186 static struct type
*hpread_type_lookup (dnttpointer
, struct objfile
*);
188 static unsigned long hpread_get_depth (sltpointer
, struct objfile
*);
190 static unsigned long hpread_get_line (sltpointer
, struct objfile
*);
192 static CORE_ADDR
hpread_get_location (sltpointer
, struct objfile
*);
194 static int hpread_type_translate (dnttpointer
);
195 static unsigned long hpread_get_textlow (int, int, struct objfile
*);
196 static union dnttentry
*hpread_get_gntt (int, struct objfile
*);
197 static union dnttentry
*hpread_get_lntt (int, struct objfile
*);
198 static union sltentry
*hpread_get_slt (int, struct objfile
*);
199 static void hpread_psymtab_to_symtab (struct partial_symtab
*);
200 static void hpread_psymtab_to_symtab_1 (struct partial_symtab
*);
201 static int hpread_has_name (enum dntt_entry_type
);
204 /* Initialization for reading native HP C debug symbols from OBJFILE.
206 It's only purpose in life is to set up the symbol reader's private
207 per-objfile data structures, and read in the raw contents of the debug
208 sections (attaching pointers to the debug info into the private data
211 Since BFD doesn't know how to read debug symbols in a format-independent
212 way (and may never do so...), we have to do it ourselves. Note we may
213 be called on a file without native HP C debugging symbols.
214 FIXME, there should be a cleaner peephole into the BFD environment here. */
217 hpread_symfile_init (struct objfile
*objfile
)
219 asection
*vt_section
, *slt_section
, *lntt_section
, *gntt_section
;
221 /* Allocate struct to keep track of the symfile */
222 objfile
->sym_private
= (PTR
)
223 xmmalloc (objfile
->md
, sizeof (struct hpread_symfile_info
));
224 memset (objfile
->sym_private
, 0, sizeof (struct hpread_symfile_info
));
226 /* We haven't read in any types yet. */
227 TYPE_VECTOR (objfile
) = 0;
229 /* Read in data from the $GNTT$ subspace. */
230 gntt_section
= bfd_get_section_by_name (objfile
->obfd
, "$GNTT$");
235 = obstack_alloc (&objfile
->symbol_obstack
,
236 bfd_section_size (objfile
->obfd
, gntt_section
));
238 bfd_get_section_contents (objfile
->obfd
, gntt_section
, GNTT (objfile
),
239 0, bfd_section_size (objfile
->obfd
, gntt_section
));
241 GNTT_SYMCOUNT (objfile
)
242 = bfd_section_size (objfile
->obfd
, gntt_section
)
243 / sizeof (struct dntt_type_block
);
245 /* Read in data from the $LNTT$ subspace. Also keep track of the number
247 lntt_section
= bfd_get_section_by_name (objfile
->obfd
, "$LNTT$");
252 = obstack_alloc (&objfile
->symbol_obstack
,
253 bfd_section_size (objfile
->obfd
, lntt_section
));
255 bfd_get_section_contents (objfile
->obfd
, lntt_section
, LNTT (objfile
),
256 0, bfd_section_size (objfile
->obfd
, lntt_section
));
258 LNTT_SYMCOUNT (objfile
)
259 = bfd_section_size (objfile
->obfd
, lntt_section
)
260 / sizeof (struct dntt_type_block
);
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 MAINLINE is true if we are reading the main symbol
301 table (as opposed to a shared lib or dynamically loaded file). */
304 hpread_build_psymtabs (struct objfile
*objfile
, int mainline
)
307 int past_first_source_file
= 0;
308 struct cleanup
*old_chain
;
310 int hp_symnum
, symcount
, i
;
312 union dnttentry
*dn_bufp
;
318 /* Current partial symtab */
319 struct partial_symtab
*pst
;
321 /* List of current psymtab's include files */
322 char **psymtab_include_list
;
323 int includes_allocated
;
326 /* Index within current psymtab dependency list */
327 struct partial_symtab
**dependency_list
;
328 int dependencies_used
, dependencies_allocated
;
330 /* Just in case the stabs reader left turds lying around. */
331 free_pending_blocks ();
332 make_cleanup (really_free_pendings
, 0);
334 pst
= (struct partial_symtab
*) 0;
336 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
337 a number of problems with cross compilation and creating useless holes
338 in the stack when we have to allocate new entries. FIXME. */
340 includes_allocated
= 30;
342 psymtab_include_list
= (char **) alloca (includes_allocated
*
345 dependencies_allocated
= 30;
346 dependencies_used
= 0;
348 (struct partial_symtab
**) alloca (dependencies_allocated
*
349 sizeof (struct partial_symtab
*));
351 old_chain
= make_cleanup_free_objfile (objfile
);
353 last_source_file
= 0;
355 /* Make two passes, one ofr the GNTT symbols, the other for the
357 for (i
= 0; i
< 1; i
++)
359 int within_function
= 0;
362 symcount
= GNTT_SYMCOUNT (objfile
);
364 symcount
= LNTT_SYMCOUNT (objfile
);
366 for (hp_symnum
= 0; hp_symnum
< symcount
; hp_symnum
++)
370 dn_bufp
= hpread_get_gntt (hp_symnum
, objfile
);
372 dn_bufp
= hpread_get_lntt (hp_symnum
, objfile
);
374 if (dn_bufp
->dblock
.extension
)
377 /* Only handle things which are necessary for minimal symbols.
378 everything else is ignored. */
379 switch (dn_bufp
->dblock
.kind
)
381 case DNTT_TYPE_SRCFILE
:
383 /* A source file of some kind. Note this may simply
384 be an included file. */
385 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
387 /* Check if this is the source file we are already working
389 if (pst
&& !strcmp (namestring
, pst
->filename
))
392 /* Check if this is an include file, if so check if we have
393 already seen it. Add it to the include list */
394 p
= strrchr (namestring
, '.');
395 if (!strcmp (p
, ".h"))
400 for (j
= 0; j
< includes_used
; j
++)
401 if (!strcmp (namestring
, psymtab_include_list
[j
]))
409 /* Add it to the list of includes seen so far and
410 allocate more include space if necessary. */
411 psymtab_include_list
[includes_used
++] = namestring
;
412 if (includes_used
>= includes_allocated
)
414 char **orig
= psymtab_include_list
;
416 psymtab_include_list
= (char **)
417 alloca ((includes_allocated
*= 2) *
419 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
420 includes_used
* sizeof (char *));
430 pst
->filename
= (char *)
431 obstack_alloc (&pst
->objfile
->psymbol_obstack
,
432 strlen (namestring
) + 1);
433 strcpy (pst
->filename
, namestring
);
440 /* This is a bonafide new source file.
441 End the current partial symtab and start a new one. */
443 if (pst
&& past_first_source_file
)
445 hpread_end_psymtab (pst
, psymtab_include_list
,
448 * sizeof (struct dntt_type_block
)),
450 dependency_list
, dependencies_used
);
451 pst
= (struct partial_symtab
*) 0;
453 dependencies_used
= 0;
456 past_first_source_file
= 1;
458 valu
= hpread_get_textlow (i
, hp_symnum
, objfile
);
459 valu
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
460 pst
= hpread_start_psymtab (objfile
,
463 * sizeof (struct dntt_type_block
)),
464 objfile
->global_psymbols
.next
,
465 objfile
->static_psymbols
.next
);
471 case DNTT_TYPE_MODULE
:
472 /* A source file. It's still unclear to me what the
473 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
474 is supposed to be. */
475 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
476 valu
= hpread_get_textlow (i
, hp_symnum
, objfile
);
477 valu
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
480 pst
= hpread_start_psymtab (objfile
,
483 * sizeof (struct dntt_type_block
)),
484 objfile
->global_psymbols
.next
,
485 objfile
->static_psymbols
.next
);
490 case DNTT_TYPE_FUNCTION
:
491 case DNTT_TYPE_ENTRY
:
492 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
493 a secondary entry point. */
494 valu
= dn_bufp
->dfunc
.hiaddr
+ ANOFFSET (objfile
->section_offsets
,
495 SECT_OFF_TEXT (objfile
));
498 valu
= dn_bufp
->dfunc
.lowaddr
+
499 ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
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 0, language_unknown
, objfile
);
507 case DNTT_TYPE_BEGIN
:
509 /* Scope block begin/end. We only care about function
510 and file blocks right now. */
511 if (dn_bufp
->dend
.endkind
== DNTT_TYPE_MODULE
)
513 hpread_end_psymtab (pst
, psymtab_include_list
, includes_used
,
515 * sizeof (struct dntt_type_block
)),
517 dependency_list
, dependencies_used
);
518 pst
= (struct partial_symtab
*) 0;
520 dependencies_used
= 0;
523 if (dn_bufp
->dend
.endkind
== DNTT_TYPE_FUNCTION
)
528 case DNTT_TYPE_TYPEDEF
:
529 case DNTT_TYPE_TAGDEF
:
531 /* Variables, typedefs an the like. */
532 enum address_class storage
;
533 namespace_enum
namespace;
535 /* Don't add locals to the partial symbol table. */
537 && (dn_bufp
->dblock
.kind
== DNTT_TYPE_SVAR
538 || dn_bufp
->dblock
.kind
== DNTT_TYPE_DVAR
))
541 /* TAGDEFs go into the structure namespace. */
542 if (dn_bufp
->dblock
.kind
== DNTT_TYPE_TAGDEF
)
543 namespace = STRUCT_NAMESPACE
;
545 namespace = VAR_NAMESPACE
;
547 /* What kind of "storage" does this use? */
548 if (dn_bufp
->dblock
.kind
== DNTT_TYPE_SVAR
)
549 storage
= LOC_STATIC
;
550 else if (dn_bufp
->dblock
.kind
== DNTT_TYPE_DVAR
551 && dn_bufp
->ddvar
.regvar
)
552 storage
= LOC_REGISTER
;
553 else if (dn_bufp
->dblock
.kind
== DNTT_TYPE_DVAR
)
558 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
561 pst
= hpread_start_psymtab (objfile
,
564 * sizeof (struct dntt_type_block
)),
565 objfile
->global_psymbols
.next
,
566 objfile
->static_psymbols
.next
);
568 if (dn_bufp
->dsvar
.global
)
570 add_psymbol_to_list (namestring
, strlen (namestring
),
572 &objfile
->global_psymbols
,
573 dn_bufp
->dsvar
.location
,
574 0, language_unknown
, objfile
);
578 add_psymbol_to_list (namestring
, strlen (namestring
),
580 &objfile
->static_psymbols
,
581 dn_bufp
->dsvar
.location
,
582 0, language_unknown
, objfile
);
586 case DNTT_TYPE_MEMENUM
:
587 case DNTT_TYPE_CONST
:
588 /* Constants and members of enumerated types. */
589 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
592 pst
= hpread_start_psymtab (objfile
,
595 * sizeof (struct dntt_type_block
)),
596 objfile
->global_psymbols
.next
,
597 objfile
->static_psymbols
.next
);
599 add_psymbol_to_list (namestring
, strlen (namestring
),
600 VAR_NAMESPACE
, LOC_CONST
,
601 &objfile
->static_psymbols
, 0,
602 0, language_unknown
, objfile
);
610 /* End any pending partial symbol table. */
613 hpread_end_psymtab (pst
, psymtab_include_list
, includes_used
,
614 hp_symnum
* sizeof (struct dntt_type_block
),
615 0, dependency_list
, dependencies_used
);
618 discard_cleanups (old_chain
);
621 /* Perform any local cleanups required when we are done with a particular
622 objfile. I.E, we are in the process of discarding all symbol information
623 for an objfile, freeing up all memory held for it, and unlinking the
624 objfile struct from the global list of known objfiles. */
627 hpread_symfile_finish (struct objfile
*objfile
)
629 if (objfile
->sym_private
!= NULL
)
631 mfree (objfile
->md
, objfile
->sym_private
);
636 /* The remaining functions are all for internal use only. */
638 /* Various small functions to get entries in the debug symbol sections. */
640 static union dnttentry
*
641 hpread_get_lntt (int index
, struct objfile
*objfile
)
643 return (union dnttentry
*)
644 &(LNTT (objfile
)[(index
* sizeof (struct dntt_type_block
))]);
647 static union dnttentry
*
648 hpread_get_gntt (int index
, struct objfile
*objfile
)
650 return (union dnttentry
*)
651 &(GNTT (objfile
)[(index
* sizeof (struct dntt_type_block
))]);
654 static union sltentry
*
655 hpread_get_slt (int index
, struct objfile
*objfile
)
657 return (union sltentry
*) &(SLT (objfile
)[index
* sizeof (union sltentry
)]);
660 /* Get the low address associated with some symbol (typically the start
661 of a particular source file or module). Since that information is not
662 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we
663 must infer it from the existence of DNTT_TYPE_FUNCTION symbols. */
666 hpread_get_textlow (int global
, int index
, struct objfile
*objfile
)
668 union dnttentry
*dn_bufp
;
669 struct minimal_symbol
*msymbol
;
671 /* Look for a DNTT_TYPE_FUNCTION symbol. */
675 dn_bufp
= hpread_get_gntt (index
++, objfile
);
677 dn_bufp
= hpread_get_lntt (index
++, objfile
);
679 while (dn_bufp
->dblock
.kind
!= DNTT_TYPE_FUNCTION
680 && dn_bufp
->dblock
.kind
!= DNTT_TYPE_END
);
682 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
683 might happen when a sourcefile has no functions. */
684 if (dn_bufp
->dblock
.kind
== DNTT_TYPE_END
)
687 /* The minimal symbols are typically more accurate for some reason. */
688 msymbol
= lookup_minimal_symbol (dn_bufp
->dfunc
.name
+ VT (objfile
), NULL
,
691 return SYMBOL_VALUE_ADDRESS (msymbol
);
693 return dn_bufp
->dfunc
.lowaddr
;
696 /* Get the nesting depth for the source line identified by INDEX. */
699 hpread_get_depth (sltpointer index
, struct objfile
*objfile
)
701 union sltentry
*sl_bufp
;
703 sl_bufp
= hpread_get_slt (index
, objfile
);
704 return sl_bufp
->sspec
.backptr
.dnttp
.index
;
707 /* Get the source line number the the line identified by INDEX. */
710 hpread_get_line (sltpointer index
, struct objfile
*objfile
)
712 union sltentry
*sl_bufp
;
714 sl_bufp
= hpread_get_slt (index
, objfile
);
715 return sl_bufp
->snorm
.line
;
719 hpread_get_location (sltpointer index
, struct objfile
*objfile
)
721 union sltentry
*sl_bufp
;
724 /* code location of special sltentrys is determined from context */
725 sl_bufp
= hpread_get_slt (index
, objfile
);
727 if (sl_bufp
->snorm
.sltdesc
== SLT_END
)
729 /* find previous normal sltentry and get address */
730 for (i
= 0; ((sl_bufp
->snorm
.sltdesc
!= SLT_NORMAL
) &&
731 (sl_bufp
->snorm
.sltdesc
!= SLT_EXIT
)); i
++)
732 sl_bufp
= hpread_get_slt (index
- i
, objfile
);
733 return sl_bufp
->snorm
.address
;
736 /* find next normal sltentry and get address */
737 for (i
= 0; ((sl_bufp
->snorm
.sltdesc
!= SLT_NORMAL
) &&
738 (sl_bufp
->snorm
.sltdesc
!= SLT_EXIT
)); i
++)
739 sl_bufp
= hpread_get_slt (index
+ i
, objfile
);
740 return sl_bufp
->snorm
.address
;
744 /* Return 1 if an HP debug symbol of type KIND has a name associated with
745 it, else return 0. */
748 hpread_has_name (enum dntt_entry_type kind
)
752 case DNTT_TYPE_SRCFILE
:
753 case DNTT_TYPE_MODULE
:
754 case DNTT_TYPE_FUNCTION
:
755 case DNTT_TYPE_ENTRY
:
756 case DNTT_TYPE_IMPORT
:
757 case DNTT_TYPE_LABEL
:
758 case DNTT_TYPE_FPARAM
:
761 case DNTT_TYPE_CONST
:
762 case DNTT_TYPE_TYPEDEF
:
763 case DNTT_TYPE_TAGDEF
:
764 case DNTT_TYPE_MEMENUM
:
765 case DNTT_TYPE_FIELD
:
769 case DNTT_TYPE_BEGIN
:
772 case DNTT_TYPE_COMMON
:
773 case DNTT_TYPE_POINTER
:
776 case DNTT_TYPE_SUBRANGE
:
777 case DNTT_TYPE_ARRAY
:
778 case DNTT_TYPE_STRUCT
:
779 case DNTT_TYPE_UNION
:
780 case DNTT_TYPE_VARIANT
:
782 case DNTT_TYPE_FUNCTYPE
:
783 case DNTT_TYPE_COBSTRUCT
:
785 case DNTT_TYPE_MACRO
:
791 /* Allocate and partially fill a partial symtab. It will be
792 completely filled at the end of the symbol list.
794 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
795 is the address relative to which its symbols are (incremental) or 0
798 static struct partial_symtab
*
799 hpread_start_psymtab (struct objfile
*objfile
, char *filename
,
800 CORE_ADDR textlow
, int ldsymoff
,
801 struct partial_symbol
**global_syms
,
802 struct partial_symbol
**static_syms
)
804 struct partial_symtab
*result
=
805 start_psymtab_common (objfile
, section_offsets
,
806 filename
, textlow
, global_syms
, static_syms
);
808 result
->read_symtab_private
= (char *)
809 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
810 LDSYMOFF (result
) = ldsymoff
;
811 result
->read_symtab
= hpread_psymtab_to_symtab
;
817 /* Close off the current usage of PST.
818 Returns PST or NULL if the partial symtab was empty and thrown away.
820 FIXME: List variables and peculiarities of same. */
822 static struct partial_symtab
*
823 hpread_end_psymtab (struct partial_symtab
*pst
, char **include_list
,
824 int num_includes
, int capping_symbol_offset
,
825 CORE_ADDR capping_text
,
826 struct partial_symtab
**dependency_list
,
827 int number_dependencies
)
830 struct objfile
*objfile
= pst
->objfile
;
832 if (capping_symbol_offset
!= -1)
833 LDSYMLEN (pst
) = capping_symbol_offset
- LDSYMOFF (pst
);
834 pst
->texthigh
= capping_text
;
837 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
839 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
841 pst
->number_of_dependencies
= number_dependencies
;
842 if (number_dependencies
)
844 pst
->dependencies
= (struct partial_symtab
**)
845 obstack_alloc (&objfile
->psymbol_obstack
,
846 number_dependencies
* sizeof (struct partial_symtab
*));
847 memcpy (pst
->dependencies
, dependency_list
,
848 number_dependencies
* sizeof (struct partial_symtab
*));
851 pst
->dependencies
= 0;
853 for (i
= 0; i
< num_includes
; i
++)
855 struct partial_symtab
*subpst
=
856 allocate_psymtab (include_list
[i
], objfile
);
858 subpst
->section_offsets
= pst
->section_offsets
;
859 subpst
->read_symtab_private
=
860 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
861 sizeof (struct symloc
));
865 subpst
->texthigh
= 0;
867 /* We could save slight bits of space by only making one of these,
868 shared by the entire set of include files. FIXME-someday. */
869 subpst
->dependencies
= (struct partial_symtab
**)
870 obstack_alloc (&objfile
->psymbol_obstack
,
871 sizeof (struct partial_symtab
*));
872 subpst
->dependencies
[0] = pst
;
873 subpst
->number_of_dependencies
= 1;
875 subpst
->globals_offset
=
876 subpst
->n_global_syms
=
877 subpst
->statics_offset
=
878 subpst
->n_static_syms
= 0;
882 subpst
->read_symtab
= pst
->read_symtab
;
885 sort_pst_symbols (pst
);
887 /* If there is already a psymtab or symtab for a file of this name, remove it.
888 (If there is a symtab, more drastic things also happen.)
889 This happens in VxWorks. */
890 free_named_symtabs (pst
->filename
);
892 if (num_includes
== 0
893 && number_dependencies
== 0
894 && pst
->n_global_syms
== 0
895 && pst
->n_static_syms
== 0)
897 /* Throw away this psymtab, it's empty. We can't deallocate it, since
898 it is on the obstack, but we can forget to chain it on the list. */
899 /* Empty psymtabs happen as a result of header files which don't have
900 any symbols in them. There can be a lot of them. But this check
901 is wrong, in that a psymtab with N_SLINE entries but nothing else
902 is not empty, but we don't realize that. Fixing that without slowing
903 things down might be tricky. */
905 discard_psymtab (pst
);
907 /* Indicate that psymtab was thrown away. */
908 pst
= (struct partial_symtab
*) NULL
;
913 /* Do the dirty work of reading in the full symbol from a partial symbol
917 hpread_psymtab_to_symtab_1 (struct partial_symtab
*pst
)
919 struct cleanup
*old_chain
;
922 /* Get out quick if passed junk. */
926 /* Complain if we've already read in this symbol table. */
929 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
934 /* Read in all partial symtabs on which this one is dependent */
935 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
936 if (!pst
->dependencies
[i
]->readin
)
938 /* Inform about additional files that need to be read in. */
941 fputs_filtered (" ", gdb_stdout
);
943 fputs_filtered ("and ", gdb_stdout
);
945 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
946 wrap_here (""); /* Flush output */
947 gdb_flush (gdb_stdout
);
949 hpread_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
952 /* If it's real... */
955 /* Init stuff necessary for reading in symbols */
957 old_chain
= make_cleanup (really_free_pendings
, 0);
960 hpread_expand_symtab (pst
->objfile
, LDSYMOFF (pst
), LDSYMLEN (pst
),
961 pst
->textlow
, pst
->texthigh
- pst
->textlow
,
962 pst
->section_offsets
, pst
->filename
);
963 sort_symtab_syms (pst
->symtab
);
965 do_cleanups (old_chain
);
971 /* Read in all of the symbols for a given psymtab for real.
972 Be verbose about it if the user wants that. */
975 hpread_psymtab_to_symtab (struct partial_symtab
*pst
)
977 /* Get out quick if given junk. */
984 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
989 if (LDSYMLEN (pst
) || pst
->number_of_dependencies
)
991 /* Print the message now, before reading the string table,
992 to avoid disconcerting pauses. */
995 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
996 gdb_flush (gdb_stdout
);
999 hpread_psymtab_to_symtab_1 (pst
);
1001 /* Match with global symbols. This only needs to be done once,
1002 after all of the symtabs and dependencies have been read in. */
1003 scan_file_globals (pst
->objfile
);
1005 /* Finish up the debug error message. */
1007 printf_filtered ("done.\n");
1010 /* Read in a defined section of a specific object file's symbols.
1012 DESC is the file descriptor for the file, positioned at the
1013 beginning of the symtab
1014 SYM_OFFSET is the offset within the file of
1015 the beginning of the symbols we want to read
1016 SYM_SIZE is the size of the symbol info to read in.
1017 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1018 TEXT_SIZE is the size of the text segment read in.
1019 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1021 static struct symtab
*
1022 hpread_expand_symtab (struct objfile
*objfile
, int sym_offset
, int sym_size
,
1023 CORE_ADDR text_offset
, int text_size
,
1024 struct section_offsets
*section_offsets
, char *filename
)
1027 union dnttentry
*dn_bufp
;
1028 unsigned max_symnum
;
1030 int sym_index
= sym_offset
/ sizeof (struct dntt_type_block
);
1032 current_objfile
= objfile
;
1035 last_source_file
= 0;
1037 dn_bufp
= hpread_get_lntt (sym_index
, objfile
);
1038 if (!((dn_bufp
->dblock
.kind
== (unsigned char) DNTT_TYPE_SRCFILE
) ||
1039 (dn_bufp
->dblock
.kind
== (unsigned char) DNTT_TYPE_MODULE
)))
1041 start_symtab ("globals", NULL
, 0);
1042 record_debugformat ("HP");
1045 max_symnum
= sym_size
/ sizeof (struct dntt_type_block
);
1047 /* Read in and process each debug symbol within the specified range. */
1049 symnum
< max_symnum
;
1052 QUIT
; /* Allow this to be interruptable */
1053 dn_bufp
= hpread_get_lntt (sym_index
+ symnum
, objfile
);
1055 if (dn_bufp
->dblock
.extension
)
1058 /* Yow! We call SET_NAMESTRING on things without names! */
1059 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
1061 hpread_process_one_debug_symbol (dn_bufp
, namestring
, section_offsets
,
1062 objfile
, text_offset
, text_size
,
1063 filename
, symnum
+ sym_index
);
1066 current_objfile
= NULL
;
1068 return end_symtab (text_offset
+ text_size
, objfile
, SECT_OFF_TEXT (objfile
));
1072 /* Convert basic types from HP debug format into GDB internal format. */
1075 hpread_type_translate (dnttpointer typep
)
1077 if (!typep
.dntti
.immediate
)
1078 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1080 switch (typep
.dntti
.type
)
1082 case HP_TYPE_BOOLEAN
:
1083 case HP_TYPE_BOOLEAN_S300_COMPAT
:
1084 case HP_TYPE_BOOLEAN_VAX_COMPAT
:
1086 /* Ugh. No way to distinguish between signed and unsigned chars. */
1088 case HP_TYPE_WIDE_CHAR
:
1091 if (typep
.dntti
.bitlength
<= 8)
1093 if (typep
.dntti
.bitlength
<= 16)
1095 if (typep
.dntti
.bitlength
<= 32)
1097 return FT_LONG_LONG
;
1100 case HP_TYPE_UNSIGNED_LONG
:
1101 if (typep
.dntti
.bitlength
<= 8)
1102 return FT_UNSIGNED_CHAR
;
1103 if (typep
.dntti
.bitlength
<= 16)
1104 return FT_UNSIGNED_SHORT
;
1105 if (typep
.dntti
.bitlength
<= 32)
1106 return FT_UNSIGNED_LONG
;
1107 return FT_UNSIGNED_LONG_LONG
;
1108 case HP_TYPE_UNSIGNED_INT
:
1109 if (typep
.dntti
.bitlength
<= 8)
1110 return FT_UNSIGNED_CHAR
;
1111 if (typep
.dntti
.bitlength
<= 16)
1112 return FT_UNSIGNED_SHORT
;
1113 if (typep
.dntti
.bitlength
<= 32)
1114 return FT_UNSIGNED_INTEGER
;
1115 return FT_UNSIGNED_LONG_LONG
;
1117 case HP_TYPE_REAL_3000
:
1118 case HP_TYPE_DOUBLE
:
1119 if (typep
.dntti
.bitlength
== 64)
1120 return FT_DBL_PREC_FLOAT
;
1121 if (typep
.dntti
.bitlength
== 128)
1122 return FT_EXT_PREC_FLOAT
;
1124 case HP_TYPE_COMPLEX
:
1125 case HP_TYPE_COMPLEXS3000
:
1126 if (typep
.dntti
.bitlength
== 128)
1127 return FT_DBL_PREC_COMPLEX
;
1128 if (typep
.dntti
.bitlength
== 192)
1129 return FT_EXT_PREC_COMPLEX
;
1131 case HP_TYPE_STRING200
:
1132 case HP_TYPE_LONGSTRING200
:
1133 case HP_TYPE_FTN_STRING_SPEC
:
1134 case HP_TYPE_MOD_STRING_SPEC
:
1135 case HP_TYPE_MOD_STRING_3000
:
1136 case HP_TYPE_FTN_STRING_S300_COMPAT
:
1137 case HP_TYPE_FTN_STRING_VAX_COMPAT
:
1140 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1144 /* Return the type associated with the index found in HP_TYPE. */
1146 static struct type
**
1147 hpread_lookup_type (dnttpointer hp_type
, struct objfile
*objfile
)
1150 int index
= hp_type
.dnttp
.index
;
1152 if (hp_type
.dntti
.immediate
)
1155 if (index
< LNTT_SYMCOUNT (objfile
))
1157 if (index
>= TYPE_VECTOR_LENGTH (objfile
))
1159 old_len
= TYPE_VECTOR_LENGTH (objfile
);
1162 TYPE_VECTOR_LENGTH (objfile
) = 100;
1163 TYPE_VECTOR (objfile
) = (struct type
**)
1164 xmmalloc (objfile
->md
,
1165 TYPE_VECTOR_LENGTH (objfile
) * sizeof (struct type
*));
1167 while (index
>= TYPE_VECTOR_LENGTH (objfile
))
1168 TYPE_VECTOR_LENGTH (objfile
) *= 2;
1169 TYPE_VECTOR (objfile
) = (struct type
**)
1170 xmrealloc (objfile
->md
,
1171 (char *) TYPE_VECTOR (objfile
),
1172 (TYPE_VECTOR_LENGTH (objfile
) * sizeof (struct type
*)));
1173 memset (&TYPE_VECTOR (objfile
)[old_len
], 0,
1174 (TYPE_VECTOR_LENGTH (objfile
) - old_len
) *
1175 sizeof (struct type
*));
1177 return &TYPE_VECTOR (objfile
)[index
];
1183 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1184 Note we'll just return the address of a GDB internal type if we already
1185 have it lying around. */
1187 static struct type
*
1188 hpread_alloc_type (dnttpointer hp_type
, struct objfile
*objfile
)
1190 struct type
**type_addr
;
1192 type_addr
= hpread_lookup_type (hp_type
, objfile
);
1193 if (*type_addr
== 0)
1194 *type_addr
= alloc_type (objfile
);
1196 TYPE_CPLUS_SPECIFIC (*type_addr
)
1197 = (struct cplus_struct_type
*) &cplus_struct_default
;
1201 /* Read a native enumerated type and return it in GDB internal form. */
1203 static struct type
*
1204 hpread_read_enum_type (dnttpointer hp_type
, union dnttentry
*dn_bufp
,
1205 struct objfile
*objfile
)
1208 struct pending
**symlist
, *osyms
, *syms
;
1209 int o_nsyms
, nsyms
= 0;
1211 union dnttentry
*memp
;
1216 type
= hpread_alloc_type (hp_type
, objfile
);
1217 TYPE_LENGTH (type
) = 4;
1219 symlist
= &file_symbols
;
1221 o_nsyms
= osyms
? osyms
->nsyms
: 0;
1223 /* Get a name for each member and add it to our list of members. */
1224 mem
= dn_bufp
->denum
.firstmem
;
1225 while (mem
.dnttp
.extension
&& mem
.word
!= DNTTNIL
)
1227 memp
= hpread_get_lntt (mem
.dnttp
.index
, objfile
);
1229 name
= VT (objfile
) + memp
->dmember
.name
;
1230 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1231 sizeof (struct symbol
));
1232 memset (sym
, 0, sizeof (struct symbol
));
1233 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
1234 &objfile
->symbol_obstack
);
1235 SYMBOL_CLASS (sym
) = LOC_CONST
;
1236 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1237 SYMBOL_VALUE (sym
) = memp
->dmember
.value
;
1238 add_symbol_to_list (sym
, symlist
);
1240 mem
= memp
->dmember
.nextmem
;
1243 /* Now that we know more about the enum, fill in more info. */
1244 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1245 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1246 TYPE_NFIELDS (type
) = nsyms
;
1247 TYPE_FIELDS (type
) = (struct field
*)
1248 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
) * nsyms
);
1250 /* Find the symbols for the members and put them into the type.
1251 The symbols can be found in the symlist that we put them on
1252 to cause them to be defined. osyms contains the old value
1253 of that symlist; everything up to there was defined by us.
1255 Note that we preserve the order of the enum constants, so
1256 that in something like "enum {FOO, LAST_THING=FOO}" we print
1257 FOO, not LAST_THING. */
1258 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
1263 for (; j
< syms
->nsyms
; j
++, n
++)
1265 struct symbol
*xsym
= syms
->symbol
[j
];
1266 SYMBOL_TYPE (xsym
) = type
;
1267 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
1268 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
1269 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1278 /* Read and internalize a native function debug symbol. */
1280 static struct type
*
1281 hpread_read_function_type (dnttpointer hp_type
, union dnttentry
*dn_bufp
,
1282 struct objfile
*objfile
)
1284 struct type
*type
, *type1
;
1285 struct pending
**symlist
, *osyms
, *syms
;
1286 int o_nsyms
, nsyms
= 0;
1288 union dnttentry
*paramp
;
1293 param
= dn_bufp
->dfunc
.firstparam
;
1295 /* See if we've already read in this type. */
1296 type
= hpread_alloc_type (hp_type
, objfile
);
1297 if (TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1300 /* Nope, so read it in and store it away. */
1301 type1
= lookup_function_type (hpread_type_lookup (dn_bufp
->dfunc
.retval
,
1303 memcpy ((char *) type
, (char *) type1
, sizeof (struct type
));
1305 symlist
= &local_symbols
;
1307 o_nsyms
= osyms
? osyms
->nsyms
: 0;
1309 /* Now examine each parameter noting its type, location, and a
1310 wealth of other information. */
1311 while (param
.word
&& param
.word
!= DNTTNIL
)
1313 paramp
= hpread_get_lntt (param
.dnttp
.index
, objfile
);
1315 param
= paramp
->dfparam
.nextparam
;
1318 name
= VT (objfile
) + paramp
->dfparam
.name
;
1319 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1320 sizeof (struct symbol
));
1321 (void) memset (sym
, 0, sizeof (struct symbol
));
1322 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
1323 &objfile
->symbol_obstack
);
1325 /* Figure out where it lives. */
1326 if (paramp
->dfparam
.regparam
)
1327 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1328 else if (paramp
->dfparam
.indirect
)
1329 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1331 SYMBOL_CLASS (sym
) = LOC_ARG
;
1332 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1333 if (paramp
->dfparam
.copyparam
)
1335 SYMBOL_VALUE (sym
) = paramp
->dfparam
.location
;
1336 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1338 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
1340 /* This is likely a pass-by-invisible reference parameter,
1341 Hack on the symbol class to make GDB happy. */
1342 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1345 SYMBOL_VALUE (sym
) = paramp
->dfparam
.location
;
1348 SYMBOL_TYPE (sym
) = hpread_type_lookup (paramp
->dfparam
.type
, objfile
);
1350 /* Add it to the list. */
1351 add_symbol_to_list (sym
, symlist
);
1354 /* Note how many parameters we found. */
1355 TYPE_NFIELDS (type
) = nsyms
;
1356 TYPE_FIELDS (type
) = (struct field
*)
1357 obstack_alloc (&objfile
->type_obstack
,
1358 sizeof (struct field
) * nsyms
);
1360 /* Find the symbols for the values and put them into the type.
1361 The symbols can be found in the symlist that we put them on
1362 to cause them to be defined. osyms contains the old value
1363 of that symlist; everything up to there was defined by us. */
1364 /* Note that we preserve the order of the parameters, so
1365 that in something like "enum {FOO, LAST_THING=FOO}" we print
1366 FOO, not LAST_THING. */
1367 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
1372 for (; j
< syms
->nsyms
; j
++, n
++)
1374 struct symbol
*xsym
= syms
->symbol
[j
];
1375 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
1376 TYPE_FIELD_TYPE (type
, n
) = SYMBOL_TYPE (xsym
);
1377 TYPE_FIELD_BITPOS (type
, n
) = n
;
1378 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1386 /* Read in and internalize a structure definition. */
1388 static struct type
*
1389 hpread_read_struct_type (dnttpointer hp_type
, union dnttentry
*dn_bufp
,
1390 struct objfile
*objfile
)
1394 struct nextfield
*next
;
1399 struct nextfield
*list
= 0;
1400 struct nextfield
*new;
1403 union dnttentry
*fieldp
;
1405 /* Is it something we've already dealt with? */
1406 type
= hpread_alloc_type (hp_type
, objfile
);
1407 if ((TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
1408 (TYPE_CODE (type
) == TYPE_CODE_UNION
))
1411 /* Get the basic type correct. */
1412 if (dn_bufp
->dblock
.kind
== DNTT_TYPE_STRUCT
)
1414 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1415 TYPE_LENGTH (type
) = dn_bufp
->dstruct
.bitlength
/ 8;
1417 else if (dn_bufp
->dblock
.kind
== DNTT_TYPE_UNION
)
1419 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1420 TYPE_LENGTH (type
) = dn_bufp
->dunion
.bitlength
/ 8;
1426 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1428 /* Read in and internalize all the fields. */
1429 field
= dn_bufp
->dstruct
.firstfield
;
1430 while (field
.word
!= DNTTNIL
&& field
.dnttp
.extension
)
1432 fieldp
= hpread_get_lntt (field
.dnttp
.index
, objfile
);
1434 /* Get space to record the next field's data. */
1435 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1439 list
->field
.name
= VT (objfile
) + fieldp
->dfield
.name
;
1440 FIELD_BITPOS (list
->field
) = fieldp
->dfield
.bitoffset
;
1441 if (fieldp
->dfield
.bitlength
% 8)
1442 FIELD_BITSIZE (list
->field
) = fieldp
->dfield
.bitlength
;
1444 FIELD_BITSIZE (list
->field
) = 0;
1446 field
= fieldp
->dfield
.nextfield
;
1447 FIELD_TYPE (list
->field
) = hpread_type_lookup (fieldp
->dfield
.type
,
1451 TYPE_NFIELDS (type
) = nfields
;
1452 TYPE_FIELDS (type
) = (struct field
*)
1453 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
) * nfields
);
1455 /* Copy the saved-up fields into the field vector. */
1456 for (n
= nfields
; list
; list
= list
->next
)
1459 TYPE_FIELD (type
, n
) = list
->field
;
1464 /* Read in and internalize a set debug symbol. */
1466 static struct type
*
1467 hpread_read_set_type (dnttpointer hp_type
, union dnttentry
*dn_bufp
,
1468 struct objfile
*objfile
)
1472 /* See if it's something we've already deal with. */
1473 type
= hpread_alloc_type (hp_type
, objfile
);
1474 if (TYPE_CODE (type
) == TYPE_CODE_SET
)
1477 /* Nope. Fill in the appropriate fields. */
1478 TYPE_CODE (type
) = TYPE_CODE_SET
;
1479 TYPE_LENGTH (type
) = dn_bufp
->dset
.bitlength
/ 8;
1480 TYPE_NFIELDS (type
) = 0;
1481 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->dset
.subtype
,
1486 /* Read in and internalize an array debug symbol. */
1488 static struct type
*
1489 hpread_read_array_type (dnttpointer hp_type
, union dnttentry
*dn_bufp
,
1490 struct objfile
*objfile
)
1493 union dnttentry save
;
1496 /* Why no check here? Because it kept us from properly determining
1497 the size of the array! */
1498 type
= hpread_alloc_type (hp_type
, objfile
);
1500 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1502 /* values are not normalized. */
1503 if (!((dn_bufp
->darray
.arrayisbytes
&& dn_bufp
->darray
.elemisbytes
)
1504 || (!dn_bufp
->darray
.arrayisbytes
&& !dn_bufp
->darray
.elemisbytes
)))
1505 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1506 else if (dn_bufp
->darray
.arraylength
== 0x7fffffff)
1508 /* The HP debug format represents char foo[]; as an array with
1509 length 0x7fffffff. Internally GDB wants to represent this
1510 as an array of length zero. */
1511 TYPE_LENGTH (type
) = 0;
1514 TYPE_LENGTH (type
) = dn_bufp
->darray
.arraylength
/ 8;
1516 TYPE_NFIELDS (type
) = 1;
1517 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->darray
.elemtype
,
1520 TYPE_FIELDS (type
) = (struct field
*)
1521 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
));
1522 TYPE_FIELD_TYPE (type
, 0) = hpread_type_lookup (dn_bufp
->darray
.indextype
,
1527 /* Read in and internalize a subrange debug symbol. */
1528 static struct type
*
1529 hpread_read_subrange_type (dnttpointer hp_type
, union dnttentry
*dn_bufp
,
1530 struct objfile
*objfile
)
1534 /* Is it something we've already dealt with. */
1535 type
= hpread_alloc_type (hp_type
, objfile
);
1536 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1539 /* Nope, internalize it. */
1540 TYPE_CODE (type
) = TYPE_CODE_RANGE
;
1541 TYPE_LENGTH (type
) = dn_bufp
->dsubr
.bitlength
/ 8;
1542 TYPE_NFIELDS (type
) = 2;
1544 = (struct field
*) obstack_alloc (&objfile
->type_obstack
,
1545 2 * sizeof (struct field
));
1547 if (dn_bufp
->dsubr
.dyn_low
)
1548 TYPE_FIELD_BITPOS (type
, 0) = 0;
1550 TYPE_FIELD_BITPOS (type
, 0) = dn_bufp
->dsubr
.lowbound
;
1552 if (dn_bufp
->dsubr
.dyn_high
)
1553 TYPE_FIELD_BITPOS (type
, 1) = -1;
1555 TYPE_FIELD_BITPOS (type
, 1) = dn_bufp
->dsubr
.highbound
;
1556 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->dsubr
.subtype
,
1561 static struct type
*
1562 hpread_type_lookup (dnttpointer hp_type
, struct objfile
*objfile
)
1564 union dnttentry
*dn_bufp
;
1566 /* First see if it's a simple builtin type. */
1567 if (hp_type
.dntti
.immediate
)
1568 return lookup_fundamental_type (objfile
, hpread_type_translate (hp_type
));
1570 /* Not a builtin type. We'll have to read it in. */
1571 if (hp_type
.dnttp
.index
< LNTT_SYMCOUNT (objfile
))
1572 dn_bufp
= hpread_get_lntt (hp_type
.dnttp
.index
, objfile
);
1574 return lookup_fundamental_type (objfile
, FT_VOID
);
1576 switch (dn_bufp
->dblock
.kind
)
1578 case DNTT_TYPE_SRCFILE
:
1579 case DNTT_TYPE_MODULE
:
1580 case DNTT_TYPE_FUNCTION
:
1581 case DNTT_TYPE_ENTRY
:
1582 case DNTT_TYPE_BEGIN
:
1584 case DNTT_TYPE_IMPORT
:
1585 case DNTT_TYPE_LABEL
:
1586 case DNTT_TYPE_WITH
:
1587 case DNTT_TYPE_COMMON
:
1588 case DNTT_TYPE_FPARAM
:
1589 case DNTT_TYPE_SVAR
:
1590 case DNTT_TYPE_DVAR
:
1591 case DNTT_TYPE_CONST
:
1592 /* Opps. Something went very wrong. */
1593 return lookup_fundamental_type (objfile
, FT_VOID
);
1595 case DNTT_TYPE_TYPEDEF
:
1597 struct type
*structtype
= hpread_type_lookup (dn_bufp
->dtype
.type
,
1600 suffix
= VT (objfile
) + dn_bufp
->dtype
.name
;
1602 TYPE_CPLUS_SPECIFIC (structtype
)
1603 = (struct cplus_struct_type
*) &cplus_struct_default
;
1604 TYPE_NAME (structtype
) = suffix
;
1608 case DNTT_TYPE_TAGDEF
:
1610 /* Just a little different from above. We have to tack on
1611 an identifier of some kind (struct, union, enum, etc). */
1612 struct type
*structtype
= hpread_type_lookup (dn_bufp
->dtype
.type
,
1614 char *prefix
, *suffix
;
1615 suffix
= VT (objfile
) + dn_bufp
->dtype
.name
;
1617 /* Lookup the next type in the list. It should be a structure,
1618 union, or enum type. We will need to attach that to our name. */
1619 if (dn_bufp
->dtype
.type
.dnttp
.index
< LNTT_SYMCOUNT (objfile
))
1620 dn_bufp
= hpread_get_lntt (dn_bufp
->dtype
.type
.dnttp
.index
, objfile
);
1622 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1624 if (dn_bufp
->dblock
.kind
== DNTT_TYPE_STRUCT
)
1626 else if (dn_bufp
->dblock
.kind
== DNTT_TYPE_UNION
)
1631 /* Build the correct name. */
1633 = (char *) obstack_alloc (&objfile
->type_obstack
,
1634 strlen (prefix
) + strlen (suffix
) + 1);
1635 TYPE_NAME (structtype
) = strcpy (TYPE_NAME (structtype
), prefix
);
1636 TYPE_NAME (structtype
) = strcat (TYPE_NAME (structtype
), suffix
);
1637 TYPE_TAG_NAME (structtype
) = suffix
;
1639 TYPE_CPLUS_SPECIFIC (structtype
)
1640 = (struct cplus_struct_type
*) &cplus_struct_default
;
1644 case DNTT_TYPE_POINTER
:
1645 return lookup_pointer_type (hpread_type_lookup (dn_bufp
->dptr
.pointsto
,
1647 case DNTT_TYPE_ENUM
:
1648 return hpread_read_enum_type (hp_type
, dn_bufp
, objfile
);
1649 case DNTT_TYPE_MEMENUM
:
1650 return lookup_fundamental_type (objfile
, FT_VOID
);
1652 return hpread_read_set_type (hp_type
, dn_bufp
, objfile
);
1653 case DNTT_TYPE_SUBRANGE
:
1654 return hpread_read_subrange_type (hp_type
, dn_bufp
, objfile
);
1655 case DNTT_TYPE_ARRAY
:
1656 return hpread_read_array_type (hp_type
, dn_bufp
, objfile
);
1657 case DNTT_TYPE_STRUCT
:
1658 case DNTT_TYPE_UNION
:
1659 return hpread_read_struct_type (hp_type
, dn_bufp
, objfile
);
1660 case DNTT_TYPE_FIELD
:
1661 return hpread_type_lookup (dn_bufp
->dfield
.type
, objfile
);
1662 case DNTT_TYPE_VARIANT
:
1663 case DNTT_TYPE_FILE
:
1664 return lookup_fundamental_type (objfile
, FT_VOID
);
1665 case DNTT_TYPE_FUNCTYPE
:
1666 return lookup_function_type (hpread_type_lookup (dn_bufp
->dfunctype
.retval
,
1668 case DNTT_TYPE_COBSTRUCT
:
1669 case DNTT_TYPE_XREF
:
1671 case DNTT_TYPE_MACRO
:
1673 return lookup_fundamental_type (objfile
, FT_VOID
);
1678 hpread_record_lines (struct subfile
*subfile
, sltpointer s_idx
,
1679 sltpointer e_idx
, struct objfile
*objfile
,
1682 union sltentry
*sl_bufp
;
1684 while (s_idx
<= e_idx
)
1686 sl_bufp
= hpread_get_slt (s_idx
, objfile
);
1687 /* Only record "normal" entries in the SLT. */
1688 if (sl_bufp
->snorm
.sltdesc
== SLT_NORMAL
1689 || sl_bufp
->snorm
.sltdesc
== SLT_EXIT
)
1690 record_line (subfile
, sl_bufp
->snorm
.line
,
1691 sl_bufp
->snorm
.address
+ offset
);
1697 /* Internalize one native debug symbol. */
1700 hpread_process_one_debug_symbol (union dnttentry
*dn_bufp
, char *name
,
1701 struct section_offsets
*section_offsets
,
1702 struct objfile
*objfile
, CORE_ADDR text_offset
,
1703 int text_size
, char *filename
, int index
)
1708 int offset
= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
1709 union dnttentry
*dn_temp
;
1710 dnttpointer hp_type
;
1712 struct context_stack
*new;
1714 /* Allocate one GDB debug symbol and fill in some default values. */
1715 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1716 sizeof (struct symbol
));
1717 memset (sym
, 0, sizeof (struct symbol
));
1718 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
), &objfile
->symbol_obstack
);
1719 SYMBOL_LANGUAGE (sym
) = language_auto
;
1720 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1721 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1722 SYMBOL_LINE (sym
) = 0;
1723 SYMBOL_VALUE (sym
) = 0;
1724 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1726 hp_type
.dnttp
.extension
= 1;
1727 hp_type
.dnttp
.immediate
= 0;
1728 hp_type
.dnttp
.global
= 0;
1729 hp_type
.dnttp
.index
= index
;
1731 type
= dn_bufp
->dblock
.kind
;
1735 case DNTT_TYPE_SRCFILE
:
1736 /* This type of symbol indicates from which source file or include file
1737 the following data comes. If there are no modules it also may
1738 indicate the start of a new source file, in which case we must
1739 finish the symbol table of the previous source file
1740 (if any) and start accumulating a new symbol table. */
1743 if (!last_source_file
)
1745 start_symtab (name
, NULL
, valu
);
1746 record_debugformat ("HP");
1747 SL_INDEX (objfile
) = dn_bufp
->dsfile
.address
;
1751 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1753 dn_bufp
->dsfile
.address
,
1756 start_subfile (name
, NULL
);
1759 case DNTT_TYPE_MODULE
:
1760 /* No need to do anything with these DNTT_TYPE_MODULE symbols anymore. */
1763 case DNTT_TYPE_FUNCTION
:
1764 case DNTT_TYPE_ENTRY
:
1765 /* A function or secondary entry point. */
1766 valu
= dn_bufp
->dfunc
.lowaddr
+ offset
;
1767 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1769 dn_bufp
->dfunc
.address
,
1772 WITHIN_FUNCTION (objfile
) = 1;
1773 CURRENT_FUNCTION_VALUE (objfile
) = valu
;
1775 /* Stack must be empty now. */
1776 if (context_stack_depth
!= 0)
1777 complain (&lbrac_unmatched_complaint
, (char *) symnum
);
1778 new = push_context (0, valu
);
1780 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1781 SYMBOL_TYPE (sym
) = hpread_read_function_type (hp_type
, dn_bufp
, objfile
);
1782 if (dn_bufp
->dfunc
.global
)
1783 add_symbol_to_list (sym
, &global_symbols
);
1785 add_symbol_to_list (sym
, &file_symbols
);
1788 /* Search forward to the next scope beginning. */
1789 while (dn_bufp
->dblock
.kind
!= DNTT_TYPE_BEGIN
)
1791 dn_bufp
= hpread_get_lntt (++index
, objfile
);
1792 if (dn_bufp
->dblock
.extension
)
1795 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1797 dn_bufp
->dbegin
.address
,
1799 SYMBOL_LINE (sym
) = hpread_get_line (dn_bufp
->dbegin
.address
, objfile
);
1800 record_line (current_subfile
, SYMBOL_LINE (sym
), valu
);
1803 case DNTT_TYPE_BEGIN
:
1804 /* Begin a new scope. */
1805 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1807 dn_bufp
->dbegin
.address
,
1809 valu
= hpread_get_location (dn_bufp
->dbegin
.address
, objfile
);
1810 valu
+= offset
; /* Relocate for dynamic loading */
1811 desc
= hpread_get_depth (dn_bufp
->dbegin
.address
, objfile
);
1812 new = push_context (desc
, valu
);
1817 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1819 dn_bufp
->dend
.address
+ 1,
1821 switch (dn_bufp
->dend
.endkind
)
1823 case DNTT_TYPE_MODULE
:
1824 /* Ending a module ends the symbol table for that module. */
1825 valu
= text_offset
+ text_size
+ offset
;
1826 (void) end_symtab (valu
, objfile
, SECT_OFF_TEXT (objfile
));
1829 case DNTT_TYPE_FUNCTION
:
1830 /* Ending a function, well, ends the function's scope. */
1831 dn_temp
= hpread_get_lntt (dn_bufp
->dend
.beginscope
.dnttp
.index
,
1833 valu
= dn_temp
->dfunc
.hiaddr
+ offset
;
1834 new = pop_context ();
1835 /* Make a block for the local symbols within. */
1836 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1837 new->start_addr
, valu
, objfile
);
1838 WITHIN_FUNCTION (objfile
) = 0;
1840 case DNTT_TYPE_BEGIN
:
1841 /* Just ending a local scope. */
1842 valu
= hpread_get_location (dn_bufp
->dend
.address
, objfile
);
1843 /* Why in the hell is this needed? */
1844 valu
+= offset
+ 9; /* Relocate for dynamic loading */
1845 new = pop_context ();
1846 desc
= dn_bufp
->dend
.beginscope
.dnttp
.index
;
1847 if (desc
!= new->depth
)
1848 complain (&lbrac_mismatch_complaint
, (char *) symnum
);
1849 /* Make a block for the local symbols within. */
1850 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1851 new->start_addr
, valu
, objfile
);
1852 local_symbols
= new->locals
;
1856 case DNTT_TYPE_LABEL
:
1857 SYMBOL_NAMESPACE (sym
) = LABEL_NAMESPACE
;
1859 case DNTT_TYPE_FPARAM
:
1860 /* Function parameters. */
1861 if (dn_bufp
->dfparam
.regparam
)
1862 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1864 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1865 if (dn_bufp
->dfparam
.copyparam
)
1867 SYMBOL_VALUE (sym
) = dn_bufp
->dfparam
.location
;
1868 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1870 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
1874 SYMBOL_VALUE (sym
) = dn_bufp
->dfparam
.location
;
1875 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dfparam
.type
, objfile
);
1876 add_symbol_to_list (sym
, &local_symbols
);
1878 case DNTT_TYPE_SVAR
:
1879 /* Static variables. */
1880 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1881 SYMBOL_VALUE_ADDRESS (sym
) = dn_bufp
->dsvar
.location
;
1882 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dsvar
.type
, objfile
);
1883 if (dn_bufp
->dsvar
.global
)
1884 add_symbol_to_list (sym
, &global_symbols
);
1885 else if (WITHIN_FUNCTION (objfile
))
1886 add_symbol_to_list (sym
, &local_symbols
);
1888 add_symbol_to_list (sym
, &file_symbols
);
1890 case DNTT_TYPE_DVAR
:
1891 /* Dynamic variables. */
1892 if (dn_bufp
->ddvar
.regvar
)
1893 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1895 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1896 SYMBOL_VALUE (sym
) = dn_bufp
->ddvar
.location
;
1897 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1899 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
1901 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->ddvar
.type
, objfile
);
1902 if (dn_bufp
->ddvar
.global
)
1903 add_symbol_to_list (sym
, &global_symbols
);
1904 else if (WITHIN_FUNCTION (objfile
))
1905 add_symbol_to_list (sym
, &local_symbols
);
1907 add_symbol_to_list (sym
, &file_symbols
);
1909 case DNTT_TYPE_CONST
:
1910 /* A constant (pascal?). */
1911 SYMBOL_CLASS (sym
) = LOC_CONST
;
1912 SYMBOL_VALUE (sym
) = dn_bufp
->dconst
.location
;
1913 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dconst
.type
, objfile
);
1914 if (dn_bufp
->dconst
.global
)
1915 add_symbol_to_list (sym
, &global_symbols
);
1916 else if (WITHIN_FUNCTION (objfile
))
1917 add_symbol_to_list (sym
, &local_symbols
);
1919 add_symbol_to_list (sym
, &file_symbols
);
1921 case DNTT_TYPE_TYPEDEF
:
1922 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1923 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dtype
.type
, objfile
);
1924 if (dn_bufp
->dtype
.global
)
1925 add_symbol_to_list (sym
, &global_symbols
);
1926 else if (WITHIN_FUNCTION (objfile
))
1927 add_symbol_to_list (sym
, &local_symbols
);
1929 add_symbol_to_list (sym
, &file_symbols
);
1931 case DNTT_TYPE_TAGDEF
:
1932 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1933 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dtype
.type
, objfile
);
1934 TYPE_NAME (sym
->type
) = SYMBOL_NAME (sym
);
1935 TYPE_TAG_NAME (sym
->type
) = SYMBOL_NAME (sym
);
1936 if (dn_bufp
->dtype
.global
)
1937 add_symbol_to_list (sym
, &global_symbols
);
1938 else if (WITHIN_FUNCTION (objfile
))
1939 add_symbol_to_list (sym
, &local_symbols
);
1941 add_symbol_to_list (sym
, &file_symbols
);
1943 case DNTT_TYPE_POINTER
:
1944 SYMBOL_TYPE (sym
) = lookup_pointer_type (hpread_type_lookup
1945 (dn_bufp
->dptr
.pointsto
,
1947 add_symbol_to_list (sym
, &file_symbols
);
1949 case DNTT_TYPE_ENUM
:
1950 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1951 SYMBOL_TYPE (sym
) = hpread_read_enum_type (hp_type
, dn_bufp
, objfile
);
1952 add_symbol_to_list (sym
, &file_symbols
);
1954 case DNTT_TYPE_MEMENUM
:
1957 SYMBOL_TYPE (sym
) = hpread_read_set_type (hp_type
, dn_bufp
, objfile
);
1958 add_symbol_to_list (sym
, &file_symbols
);
1960 case DNTT_TYPE_SUBRANGE
:
1961 SYMBOL_TYPE (sym
) = hpread_read_subrange_type (hp_type
, dn_bufp
,
1963 add_symbol_to_list (sym
, &file_symbols
);
1965 case DNTT_TYPE_ARRAY
:
1966 SYMBOL_TYPE (sym
) = hpread_read_array_type (hp_type
, dn_bufp
, objfile
);
1967 add_symbol_to_list (sym
, &file_symbols
);
1969 case DNTT_TYPE_STRUCT
:
1970 case DNTT_TYPE_UNION
:
1971 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1972 SYMBOL_TYPE (sym
) = hpread_read_struct_type (hp_type
, dn_bufp
, objfile
);
1973 add_symbol_to_list (sym
, &file_symbols
);