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. */
66 /* Keep track of the current function's address. We may need to look
67 up something based on this address. */
68 unsigned int current_function_value
;
72 /* Accessor macros to get at the fields. */
73 #define HPUX_SYMFILE_INFO(o) \
74 ((struct hpread_symfile_info *)((o)->sym_private))
75 #define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt)
76 #define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt)
77 #define SLT(o) (HPUX_SYMFILE_INFO(o)->slt)
78 #define VT(o) (HPUX_SYMFILE_INFO(o)->vt)
79 #define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size)
80 #define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount)
81 #define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount)
82 #define TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->type_vector)
83 #define TYPE_VECTOR_LENGTH(o) (HPUX_SYMFILE_INFO(o)->type_vector_length)
84 #define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index)
85 #define HAVE_MODULE(o) (HPUX_SYMFILE_INFO(o)->have_module)
86 #define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function)
87 #define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value)
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 /* Each partial symbol table entry contains a pointer to private data for the
107 read_symtab() function to use when expanding a partial symbol table entry
108 to a full symbol table entry.
110 For hpuxread this structure contains the offset within the file symbol table
111 of first local symbol for this file, and length (in bytes) of the section
112 of the symbol table devoted to this file's symbols (actually, the section
113 bracketed may contain more than just this file's symbols).
115 If ldsymlen is 0, the only reason for this thing's existence is the
116 dependency list. Nothing else will happen when it is read in. */
118 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
119 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
120 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
128 /* FIXME: Shouldn't this stuff be in a .h file somewhere? */
129 /* Nonzero means give verbose info on gdb action. */
130 extern int info_verbose
;
132 /* Complaints about the symbols we have encountered. */
133 extern struct complaint string_table_offset_complaint
;
134 extern struct complaint lbrac_unmatched_complaint
;
135 extern struct complaint lbrac_mismatch_complaint
;
138 void hpread_symfile_init
PARAMS ((struct objfile
*));
140 static struct type
*hpread_alloc_type
141 PARAMS ((DNTTPOINTER
, struct objfile
*));
143 static struct type
**hpread_lookup_type
144 PARAMS ((DNTTPOINTER
, struct objfile
*));
146 static struct type
*hpread_read_enum_type
147 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
149 static struct type
*hpread_read_set_type
150 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
152 static struct type
*hpread_read_subrange_type
153 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
155 static struct type
*hpread_read_struct_type
156 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
158 void hpread_build_psymtabs
159 PARAMS ((struct objfile
*, struct section_offsets
*, int));
161 void hpread_symfile_finish
PARAMS ((struct objfile
*));
163 static struct partial_symtab
*hpread_start_psymtab
164 PARAMS ((struct objfile
*, struct section_offsets
*, char *, CORE_ADDR
, int,
165 struct partial_symbol
*, struct partial_symbol
*));
167 static struct partial_symtab
*hpread_end_psymtab
168 PARAMS ((struct partial_symtab
*, char **, int, int, CORE_ADDR
,
169 struct partial_symtab
**, int));
171 static struct symtab
*hpread_expand_symtab
172 PARAMS ((struct objfile
*, int, int, CORE_ADDR
, int,
173 struct section_offsets
*, char *));
175 static void hpread_process_one_debug_symbol
176 PARAMS ((union dnttentry
*, char *, struct section_offsets
*,
177 struct objfile
*, CORE_ADDR
, int, char *, int));
179 static SLTPOINTER hpread_record_lines
180 PARAMS ((struct subfile
*, SLTPOINTER
, SLTPOINTER
, struct objfile
*));
182 static struct type
*hpread_read_function_type
183 PARAMS ((DNTTPOINTER
, union dnttentry
*, struct objfile
*));
185 static struct type
* hpread_type_lookup
186 PARAMS ((DNTTPOINTER
, struct objfile
*));
188 static unsigned long hpread_get_depth
189 PARAMS ((SLTPOINTER
, struct objfile
*));
191 static unsigned long hpread_get_line
192 PARAMS ((SLTPOINTER
, struct objfile
*));
194 static ADDRESS hpread_get_location
195 PARAMS ((SLTPOINTER
, struct objfile
*));
197 static int hpread_type_translate
PARAMS ((DNTTPOINTER
));
198 static unsigned long hpread_get_textlow
PARAMS ((int, int, struct objfile
*));
199 static union dnttentry
*hpread_get_gntt
PARAMS ((int, struct objfile
*));
200 static union dnttentry
*hpread_get_lntt
PARAMS ((int, struct objfile
*));
201 static union sltentry
*hpread_get_slt
PARAMS ((int, struct objfile
*));
202 static void hpread_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
203 static void hpread_psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
204 static int hpread_has_name
PARAMS ((KINDTYPE
));
207 /* Initialization for reading native HP C debug symbols from OBJFILE.
209 It's only purpose in life is to set up the symbol reader's private
210 per-objfile data structures, and read in the raw contents of the debug
211 sections (attaching pointers to the debug info into the private data
214 Since BFD doesn't know how to read debug symbols in a format-independent
215 way (and may never do so...), we have to do it ourselves. Note we may
216 be called on a file without native HP C debugging symbols.
217 FIXME, there should be a cleaner peephole into the BFD environment here. */
220 hpread_symfile_init (objfile
)
221 struct objfile
*objfile
;
223 asection
*vt_section
, *slt_section
, *lntt_section
, *gntt_section
;
225 /* Allocate struct to keep track of the symfile */
226 objfile
->sym_private
= (PTR
)
227 xmmalloc (objfile
->md
, sizeof (struct hpread_symfile_info
));
228 memset (objfile
->sym_private
, 0, sizeof (struct hpread_symfile_info
));
230 /* We haven't read in any types yet. */
231 TYPE_VECTOR (objfile
) = 0;
233 /* Read in data from the $GNTT$ subspace. */
234 gntt_section
= bfd_get_section_by_name (objfile
->obfd
, "$GNTT$");
239 = obstack_alloc (&objfile
->symbol_obstack
,
240 bfd_section_size (objfile
->obfd
, gntt_section
));
242 bfd_get_section_contents (objfile
->obfd
, gntt_section
, GNTT (objfile
),
243 0, bfd_section_size (objfile
->obfd
, gntt_section
));
245 GNTT_SYMCOUNT (objfile
)
246 = bfd_section_size (objfile
->obfd
, gntt_section
) / DNTTBLOCKSIZE
;
248 /* Read in data from the $LNTT$ subspace. Also keep track of the number
250 lntt_section
= bfd_get_section_by_name (objfile
->obfd
, "$LNTT$");
255 = obstack_alloc (&objfile
->symbol_obstack
,
256 bfd_section_size (objfile
->obfd
, lntt_section
));
258 bfd_get_section_contents (objfile
->obfd
, lntt_section
, LNTT (objfile
),
259 0, bfd_section_size (objfile
->obfd
, lntt_section
));
261 LNTT_SYMCOUNT (objfile
)
262 = bfd_section_size (objfile
->obfd
, lntt_section
) / DNTTBLOCKSIZE
;
264 /* Read in data from the $SLT$ subspace. $SLT$ contains information
265 on source line numbers. */
266 slt_section
= bfd_get_section_by_name (objfile
->obfd
, "$SLT$");
271 obstack_alloc (&objfile
->symbol_obstack
,
272 bfd_section_size (objfile
->obfd
, slt_section
));
274 bfd_get_section_contents (objfile
->obfd
, slt_section
, SLT (objfile
),
275 0, bfd_section_size (objfile
->obfd
, slt_section
));
277 /* Read in data from the $VT$ subspace. $VT$ contains things like
278 names and constants. Keep track of the number of symbols in the VT. */
279 vt_section
= bfd_get_section_by_name (objfile
->obfd
, "$VT$");
283 VT_SIZE (objfile
) = bfd_section_size (objfile
->obfd
, vt_section
);
286 (char *) obstack_alloc (&objfile
->symbol_obstack
,
289 bfd_get_section_contents (objfile
->obfd
, vt_section
, VT (objfile
),
290 0, VT_SIZE (objfile
));
293 /* Scan and build partial symbols for a symbol file.
295 The minimal symbol table (either SOM or HP a.out) has already been
296 read in; all we need to do is setup partial symbols based on the
297 native debugging information.
299 We assume hpread_symfile_init has been called to initialize the
300 symbol reader's private data structures.
302 SECTION_OFFSETS contains offsets relative to which the symbols in the
303 various sections are (depending where the sections were actually loaded).
304 MAINLINE is true if we are reading the main symbol
305 table (as opposed to a shared lib or dynamically loaded file). */
308 hpread_build_psymtabs (objfile
, section_offsets
, mainline
)
309 struct objfile
*objfile
;
310 struct section_offsets
*section_offsets
;
314 int past_first_source_file
= 0;
315 struct cleanup
*old_chain
;
317 int hp_symnum
, symcount
, i
;
319 union dnttentry
*dn_bufp
;
325 /* Current partial symtab */
326 struct partial_symtab
*pst
;
328 /* List of current psymtab's include files */
329 char **psymtab_include_list
;
330 int includes_allocated
;
333 /* Index within current psymtab dependency list */
334 struct partial_symtab
**dependency_list
;
335 int dependencies_used
, dependencies_allocated
;
337 /* Just in case the stabs reader left turds lying around. */
339 make_cleanup (really_free_pendings
, 0);
341 pst
= (struct partial_symtab
*) 0;
343 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
344 a number of problems with cross compilation and creating useless holes
345 in the stack when we have to allocate new entries. FIXME. */
347 includes_allocated
= 30;
349 psymtab_include_list
= (char **) alloca (includes_allocated
*
352 dependencies_allocated
= 30;
353 dependencies_used
= 0;
355 (struct partial_symtab
**) alloca (dependencies_allocated
*
356 sizeof (struct partial_symtab
*));
358 old_chain
= make_cleanup (free_objfile
, objfile
);
360 last_source_file
= 0;
362 /* Make two passes, one ofr the GNTT symbols, the other for the
364 for (i
= 0; i
< 1; i
++)
366 int within_function
= 0;
369 symcount
= GNTT_SYMCOUNT (objfile
);
371 symcount
= LNTT_SYMCOUNT (objfile
);
373 for (hp_symnum
= 0; hp_symnum
< symcount
; hp_symnum
++)
377 dn_bufp
= hpread_get_gntt (hp_symnum
, objfile
);
379 dn_bufp
= hpread_get_lntt (hp_symnum
, objfile
);
381 if (dn_bufp
->dblock
.extension
)
384 /* Only handle things which are necessary for minimal symbols.
385 everything else is ignored. */
386 switch (dn_bufp
->dblock
.kind
)
390 /* A source file of some kind. Note this may simply
391 be an included file. */
392 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
394 /* Check if this is the source file we are already working
396 if (pst
&& !strcmp (namestring
, pst
->filename
))
399 /* Check if this is an include file, if so check if we have
400 already seen it. Add it to the include list */
401 p
= strrchr (namestring
, '.');
402 if (!strcmp (p
, ".h"))
407 for (j
= 0; j
< includes_used
; j
++)
408 if (!strcmp (namestring
, psymtab_include_list
[j
]))
416 /* Add it to the list of includes seen so far and
417 allocate more include space if necessary. */
418 psymtab_include_list
[includes_used
++] = namestring
;
419 if (includes_used
>= includes_allocated
)
421 char **orig
= psymtab_include_list
;
423 psymtab_include_list
= (char **)
424 alloca ((includes_allocated
*= 2) *
426 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
427 includes_used
* sizeof (char *));
433 if (HAVE_MODULE (objfile
))
438 (char *) obstack_alloc (&pst
->objfile
->psymbol_obstack
, strlen (namestring
) + 1);
439 strcpy (pst
->filename
, namestring
);
446 /* This is a bonafide new source file.
447 End the current partial symtab and start a new one. */
449 if (pst
&& past_first_source_file
)
451 texthigh
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
452 hpread_end_psymtab (pst
, psymtab_include_list
,
454 hp_symnum
* DNTTBLOCKSIZE
, texthigh
,
455 dependency_list
, dependencies_used
);
456 pst
= (struct partial_symtab
*) 0;
458 dependencies_used
= 0;
461 past_first_source_file
= 1;
463 valu
= hpread_get_textlow (i
, hp_symnum
, objfile
);
464 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
465 pst
= hpread_start_psymtab (objfile
, section_offsets
,
467 hp_symnum
* DNTTBLOCKSIZE
,
468 objfile
->global_psymbols
.next
,
469 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
);
481 pst
= hpread_start_psymtab (objfile
, section_offsets
,
483 hp_symnum
* DNTTBLOCKSIZE
,
484 objfile
->global_psymbols
.next
,
485 objfile
->static_psymbols
.next
);
487 HAVE_MODULE (objfile
) = 1;
492 /* The beginning of a function. K_ENTRY may also denote
493 a secondary entry point. */
494 valu
= dn_bufp
->dfunc
.lowaddr
+
495 ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
496 if (dn_bufp
->dfunc
.hiaddr
> texthigh
)
497 texthigh
= dn_bufp
->dfunc
.hiaddr
;
498 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
499 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
500 VAR_NAMESPACE
, LOC_BLOCK
,
501 objfile
->static_psymbols
, valu
,
502 language_unknown
, objfile
);
507 /* Scope block begin/end. We only care about function
508 and file blocks right now. */
509 if (dn_bufp
->dend
.endkind
== K_MODULE
)
511 texthigh
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
512 hpread_end_psymtab (pst
, psymtab_include_list
, includes_used
,
513 hp_symnum
* DNTTBLOCKSIZE
, texthigh
,
514 dependency_list
, dependencies_used
);
515 pst
= (struct partial_symtab
*) 0;
517 dependencies_used
= 0;
518 HAVE_MODULE (objfile
) = 0;
521 if (dn_bufp
->dend
.endkind
== K_FUNCTION
)
529 /* Variables, typedefs an the like. */
530 enum address_class storage
;
531 enum namespace namespace;
533 /* Don't add locals to the partial symbol table. */
535 && (dn_bufp
->dblock
.kind
== K_SVAR
536 || dn_bufp
->dblock
.kind
== K_DVAR
))
539 /* TAGDEFs go into the structure namespace. */
540 if (dn_bufp
->dblock
.kind
== K_TAGDEF
)
541 namespace = STRUCT_NAMESPACE
;
543 namespace = VAR_NAMESPACE
;
545 /* What kind of "storage" does this use? */
546 if (dn_bufp
->dblock
.kind
== K_SVAR
)
547 storage
= LOC_STATIC
;
548 else if (dn_bufp
->dblock
.kind
== K_DVAR
549 && dn_bufp
->ddvar
.regvar
)
550 storage
= LOC_REGISTER
;
551 else if (dn_bufp
->dblock
.kind
== K_DVAR
)
556 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
559 pst
= hpread_start_psymtab (objfile
, section_offsets
,
561 hp_symnum
* DNTTBLOCKSIZE
,
562 objfile
->global_psymbols
.next
,
563 objfile
->static_psymbols
.next
);
565 if (dn_bufp
->dsvar
.public)
567 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
569 objfile
->global_psymbols
,
570 dn_bufp
->dsvar
.location
,
571 language_unknown
, objfile
);
575 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
577 objfile
->static_psymbols
,
578 dn_bufp
->dsvar
.location
,
579 language_unknown
, objfile
);
585 /* Constants and members of enumerated types. */
586 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
589 pst
= hpread_start_psymtab (objfile
, section_offsets
,
591 hp_symnum
* DNTTBLOCKSIZE
,
592 objfile
->global_psymbols
.next
,
593 objfile
->static_psymbols
.next
);
595 ADD_PSYMBOL_TO_LIST (namestring
, strlen (namestring
),
596 VAR_NAMESPACE
, LOC_CONST
,
597 objfile
->static_psymbols
, 0,
598 language_unknown
, objfile
);
606 /* End any pending partial symbol table. */
609 hpread_end_psymtab (pst
, psymtab_include_list
, includes_used
,
610 hp_symnum
* DNTTBLOCKSIZE
, 0,
611 dependency_list
, dependencies_used
);
614 discard_cleanups (old_chain
);
617 /* Perform any local cleanups required when we are done with a particular
618 objfile. I.E, we are in the process of discarding all symbol information
619 for an objfile, freeing up all memory held for it, and unlinking the
620 objfile struct from the global list of known objfiles. */
623 hpread_symfile_finish (objfile
)
624 struct objfile
*objfile
;
626 if (objfile
->sym_private
!= NULL
)
628 mfree (objfile
->md
, objfile
->sym_private
);
633 /* The remaining functions are all for internal use only. */
635 /* Various small functions to get entries in the debug symbol sections. */
637 static union dnttentry
*
638 hpread_get_lntt (index
, objfile
)
640 struct objfile
*objfile
;
642 return (union dnttentry
*)&(LNTT (objfile
)[index
* DNTTBLOCKSIZE
]);
645 static union dnttentry
*
646 hpread_get_gntt (index
, objfile
)
648 struct objfile
*objfile
;
650 return (union dnttentry
*)&(GNTT (objfile
)[index
* DNTTBLOCKSIZE
]);
653 static union sltentry
*
654 hpread_get_slt (index
, objfile
)
656 struct objfile
*objfile
;
658 return (union sltentry
*)&(SLT (objfile
)[index
* SLTBLOCKSIZE
]);
661 /* Get the low address associated with some symbol (typically the start
662 of a particular source file or module). Since that information is not
663 stored as part of the K_MODULE or K_SRCFILE symbol we must infer it from
664 the existance of K_FUNCTION symbols. */
667 hpread_get_textlow (global
, index
, objfile
)
670 struct objfile
*objfile
;
672 union dnttentry
*dn_bufp
;
673 struct minimal_symbol
*msymbol
;
675 /* Look for a K_FUNCTION symbol. */
679 dn_bufp
= hpread_get_gntt (index
++, objfile
);
681 dn_bufp
= hpread_get_lntt (index
++, objfile
);
682 } while (dn_bufp
->dblock
.kind
!= K_FUNCTION
683 && dn_bufp
->dblock
.kind
!= K_END
);
685 /* Avoid going past a K_END when looking for a K_FUNCTION. This
686 might happen when a sourcefile has no functions. */
687 if (dn_bufp
->dblock
.kind
== K_END
)
690 /* The minimal symbols are typically more accurate for some reason. */
691 msymbol
= lookup_minimal_symbol (dn_bufp
->dfunc
.name
+ VT (objfile
),
694 return SYMBOL_VALUE_ADDRESS (msymbol
);
696 return dn_bufp
->dfunc
.lowaddr
;
699 /* Get the nesting depth for the source line identified by INDEX. */
702 hpread_get_depth (index
, objfile
)
704 struct objfile
*objfile
;
706 union sltentry
*sl_bufp
;
708 sl_bufp
= hpread_get_slt (index
, objfile
);
709 return sl_bufp
->sspec
.backptr
.dnttp
.index
;
712 /* Get the source line number the the line identified by INDEX. */
715 hpread_get_line (index
, objfile
)
717 struct objfile
*objfile
;
719 union sltentry
*sl_bufp
;
721 sl_bufp
= hpread_get_slt (index
, objfile
);
722 return sl_bufp
->snorm
.line
;
726 hpread_get_location (index
, objfile
)
728 struct objfile
*objfile
;
730 union sltentry
*sl_bufp
;
733 /* code location of special sltentrys is determined from context */
734 sl_bufp
= hpread_get_slt (index
, objfile
);
736 if (sl_bufp
->snorm
.sltdesc
== SLT_END
)
738 /* find previous normal sltentry and get address */
739 for (i
= 0; ((sl_bufp
->snorm
.sltdesc
!= SLT_NORMAL
) &&
740 (sl_bufp
->snorm
.sltdesc
!= SLT_EXIT
)); i
++)
741 sl_bufp
= hpread_get_slt (index
- i
, objfile
);
742 return sl_bufp
->snorm
.address
;
745 /* find next normal sltentry and get address */
746 for (i
= 0; ((sl_bufp
->snorm
.sltdesc
!= SLT_NORMAL
) &&
747 (sl_bufp
->snorm
.sltdesc
!= SLT_EXIT
)); i
++)
748 sl_bufp
= hpread_get_slt (index
+ i
, objfile
);
749 return sl_bufp
->snorm
.address
;
753 /* Return 1 if an HP debug symbol of type KIND has a name associated with
754 it, else return 0. */
757 hpread_has_name (kind
)
801 /* Allocate and partially fill a partial symtab. It will be
802 completely filled at the end of the symbol list.
804 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
805 is the address relative to which its symbols are (incremental) or 0
808 static struct partial_symtab
*
809 hpread_start_psymtab (objfile
, section_offsets
,
810 filename
, textlow
, ldsymoff
, global_syms
, static_syms
)
811 struct objfile
*objfile
;
812 struct section_offsets
*section_offsets
;
816 struct partial_symbol
*global_syms
;
817 struct partial_symbol
*static_syms
;
819 struct partial_symtab
*result
=
820 start_psymtab_common (objfile
, section_offsets
,
821 filename
, textlow
, global_syms
, static_syms
);
823 result
->read_symtab_private
= (char *)
824 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
825 LDSYMOFF (result
) = ldsymoff
;
826 result
->read_symtab
= hpread_psymtab_to_symtab
;
832 /* Close off the current usage of PST.
833 Returns PST or NULL if the partial symtab was empty and thrown away.
835 FIXME: List variables and peculiarities of same. */
837 static struct partial_symtab
*
838 hpread_end_psymtab (pst
, include_list
, num_includes
, capping_symbol_offset
,
839 capping_text
, dependency_list
, number_dependencies
)
840 struct partial_symtab
*pst
;
843 int capping_symbol_offset
;
844 CORE_ADDR capping_text
;
845 struct partial_symtab
**dependency_list
;
846 int number_dependencies
;
849 struct objfile
*objfile
= pst
-> objfile
;
851 if (capping_symbol_offset
!= -1)
852 LDSYMLEN(pst
) = capping_symbol_offset
- LDSYMOFF(pst
);
853 pst
->texthigh
= capping_text
;
856 objfile
->global_psymbols
.next
- (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
858 objfile
->static_psymbols
.next
- (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
860 pst
->number_of_dependencies
= number_dependencies
;
861 if (number_dependencies
)
863 pst
->dependencies
= (struct partial_symtab
**)
864 obstack_alloc (&objfile
->psymbol_obstack
,
865 number_dependencies
* sizeof (struct partial_symtab
*));
866 memcpy (pst
->dependencies
, dependency_list
,
867 number_dependencies
* sizeof (struct partial_symtab
*));
870 pst
->dependencies
= 0;
872 for (i
= 0; i
< num_includes
; i
++)
874 struct partial_symtab
*subpst
=
875 allocate_psymtab (include_list
[i
], objfile
);
877 subpst
->section_offsets
= pst
->section_offsets
;
878 subpst
->read_symtab_private
=
879 (char *) obstack_alloc (&objfile
->psymbol_obstack
,
880 sizeof (struct symloc
));
884 subpst
->texthigh
= 0;
886 /* We could save slight bits of space by only making one of these,
887 shared by the entire set of include files. FIXME-someday. */
888 subpst
->dependencies
= (struct partial_symtab
**)
889 obstack_alloc (&objfile
->psymbol_obstack
,
890 sizeof (struct partial_symtab
*));
891 subpst
->dependencies
[0] = pst
;
892 subpst
->number_of_dependencies
= 1;
894 subpst
->globals_offset
=
895 subpst
->n_global_syms
=
896 subpst
->statics_offset
=
897 subpst
->n_static_syms
= 0;
901 subpst
->read_symtab
= pst
->read_symtab
;
904 sort_pst_symbols (pst
);
906 /* If there is already a psymtab or symtab for a file of this name, remove it.
907 (If there is a symtab, more drastic things also happen.)
908 This happens in VxWorks. */
909 free_named_symtabs (pst
->filename
);
911 if (num_includes
== 0
912 && number_dependencies
== 0
913 && pst
->n_global_syms
== 0
914 && pst
->n_static_syms
== 0)
916 /* Throw away this psymtab, it's empty. We can't deallocate it, since
917 it is on the obstack, but we can forget to chain it on the list. */
918 /* Empty psymtabs happen as a result of header files which don't have
919 any symbols in them. There can be a lot of them. But this check
920 is wrong, in that a psymtab with N_SLINE entries but nothing else
921 is not empty, but we don't realize that. Fixing that without slowing
922 things down might be tricky. */
923 struct partial_symtab
*prev_pst
;
925 /* First, snip it out of the psymtab chain */
927 if (pst
->objfile
->psymtabs
== pst
)
928 pst
->objfile
->psymtabs
= pst
->next
;
930 for (prev_pst
= pst
->objfile
->psymtabs
; prev_pst
; prev_pst
= pst
->next
)
931 if (prev_pst
->next
== pst
)
932 prev_pst
->next
= pst
->next
;
934 /* Next, put it on a free list for recycling */
936 pst
->next
= pst
->objfile
->free_psymtabs
;
937 pst
->objfile
->free_psymtabs
= pst
;
939 /* Indicate that psymtab was thrown away. */
940 pst
= (struct partial_symtab
*)NULL
;
945 /* Do the dirty work of reading in the full symbol from a partial symbol
949 hpread_psymtab_to_symtab_1 (pst
)
950 struct partial_symtab
*pst
;
952 struct cleanup
*old_chain
;
955 /* Get out quick if passed junk. */
959 /* Complain if we've already read in this symbol table. */
962 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
967 /* Read in all partial symtabs on which this one is dependent */
968 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
969 if (!pst
->dependencies
[i
]->readin
)
971 /* Inform about additional files that need to be read in. */
974 fputs_filtered (" ", stdout
);
976 fputs_filtered ("and ", stdout
);
978 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
979 wrap_here (""); /* Flush output */
982 hpread_psymtab_to_symtab_1 (pst
->dependencies
[i
]);
985 /* If it's real... */
988 /* Init stuff necessary for reading in symbols */
990 old_chain
= make_cleanup (really_free_pendings
, 0);
993 hpread_expand_symtab (pst
->objfile
, LDSYMOFF (pst
), LDSYMLEN (pst
),
994 pst
->textlow
, pst
->texthigh
- pst
->textlow
,
995 pst
->section_offsets
, pst
->filename
);
996 sort_symtab_syms (pst
->symtab
);
998 do_cleanups (old_chain
);
1004 /* Read in all of the symbols for a given psymtab for real.
1005 Be verbose about it if the user wants that. */
1008 hpread_psymtab_to_symtab (pst
)
1009 struct partial_symtab
*pst
;
1011 /* Get out quick if given junk. */
1018 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
1023 if (LDSYMLEN (pst
) || pst
->number_of_dependencies
)
1025 /* Print the message now, before reading the string table,
1026 to avoid disconcerting pauses. */
1029 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1033 hpread_psymtab_to_symtab_1 (pst
);
1035 /* Match with global symbols. This only needs to be done once,
1036 after all of the symtabs and dependencies have been read in. */
1037 scan_file_globals (pst
->objfile
);
1039 /* Finish up the debug error message. */
1041 printf_filtered ("done.\n");
1044 /* Read in a defined section of a specific object file's symbols.
1046 DESC is the file descriptor for the file, positioned at the
1047 beginning of the symtab
1048 SYM_OFFSET is the offset within the file of
1049 the beginning of the symbols we want to read
1050 SYM_SIZE is the size of the symbol info to read in.
1051 TEXT_OFFSET is the beginning of the text segment we are reading symbols for
1052 TEXT_SIZE is the size of the text segment read in.
1053 SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
1055 static struct symtab
*
1056 hpread_expand_symtab (objfile
, sym_offset
, sym_size
, text_offset
, text_size
,
1057 section_offsets
, filename
)
1058 struct objfile
*objfile
;
1061 CORE_ADDR text_offset
;
1063 struct section_offsets
*section_offsets
;
1067 union dnttentry
*dn_bufp
;
1068 unsigned max_symnum
;
1070 int sym_index
= sym_offset
/ DNTTBLOCKSIZE
;
1072 current_objfile
= objfile
;
1075 last_source_file
= 0;
1077 dn_bufp
= hpread_get_lntt (sym_index
, objfile
);
1078 if (!((dn_bufp
->dblock
.kind
== (unsigned char) K_SRCFILE
) ||
1079 (dn_bufp
->dblock
.kind
== (unsigned char) K_MODULE
)))
1080 start_symtab ("globals", NULL
, 0);
1082 max_symnum
= sym_size
/ DNTTBLOCKSIZE
;
1084 /* Read in and process each debug symbol within the specified range. */
1086 symnum
< max_symnum
;
1089 QUIT
; /* Allow this to be interruptable */
1090 dn_bufp
= hpread_get_lntt (sym_index
+ symnum
, objfile
);
1092 if (dn_bufp
->dblock
.extension
)
1095 /* Yow! We call SET_NAMESTRING on things without names! */
1096 SET_NAMESTRING (dn_bufp
, &namestring
, objfile
);
1098 hpread_process_one_debug_symbol (dn_bufp
, namestring
, section_offsets
,
1099 objfile
, text_offset
, text_size
,
1100 filename
, symnum
+ sym_index
);
1103 current_objfile
= NULL
;
1105 return end_symtab (text_offset
+ text_size
, 0, 0, objfile
, 0);
1109 /* Convert basic types from HP debug format into GDB internal format. */
1112 hpread_type_translate (typep
)
1115 if (!typep
.dntti
.immediate
)
1118 switch (typep
.dntti
.type
)
1121 case T_BOOLEAN_S300_COMPAT
:
1122 case T_BOOLEAN_VAX_COMPAT
:
1124 /* Ugh. No way to distinguish between signed and unsigned chars. */
1129 if (typep
.dntti
.bitlength
<= 8)
1131 if (typep
.dntti
.bitlength
<= 16)
1133 if (typep
.dntti
.bitlength
<= 32)
1135 return FT_LONG_LONG
;
1139 return FT_UNSIGNED_LONG
;
1141 if (typep
.dntti
.bitlength
<= 8)
1142 return FT_UNSIGNED_CHAR
;
1143 if (typep
.dntti
.bitlength
<= 16)
1144 return FT_UNSIGNED_SHORT
;
1145 if (typep
.dntti
.bitlength
<= 32)
1146 return FT_UNSIGNED_INTEGER
;
1147 return FT_UNSIGNED_LONG_LONG
;
1151 if (typep
.dntti
.bitlength
== 64)
1152 return FT_DBL_PREC_FLOAT
;
1153 if (typep
.dntti
.bitlength
== 128)
1154 return FT_EXT_PREC_FLOAT
;
1157 case T_COMPLEXS3000
:
1158 if (typep
.dntti
.bitlength
== 128)
1159 return FT_DBL_PREC_COMPLEX
;
1160 if (typep
.dntti
.bitlength
== 192)
1161 return FT_EXT_PREC_COMPLEX
;
1164 case T_LONGSTRING200
:
1165 case T_FTN_STRING_SPEC
:
1166 case T_MOD_STRING_SPEC
:
1167 case T_MOD_STRING_3000
:
1168 case T_FTN_STRING_S300_COMPAT
:
1169 case T_FTN_STRING_VAX_COMPAT
:
1176 /* Return the type associated with the index found in HP_TYPE. */
1178 static struct type
**
1179 hpread_lookup_type (hp_type
, objfile
)
1180 DNTTPOINTER hp_type
;
1181 struct objfile
*objfile
;
1184 int index
= hp_type
.dnttp
.index
;
1186 if (hp_type
.dntti
.immediate
)
1189 if (index
< LNTT_SYMCOUNT (objfile
))
1191 if (index
>= TYPE_VECTOR_LENGTH (objfile
))
1193 old_len
= TYPE_VECTOR_LENGTH (objfile
);
1196 TYPE_VECTOR_LENGTH (objfile
) = 100;
1197 TYPE_VECTOR (objfile
) = (struct type
**)
1198 malloc (TYPE_VECTOR_LENGTH (objfile
) * sizeof (struct type
*));
1200 while (index
>= TYPE_VECTOR_LENGTH (objfile
))
1201 TYPE_VECTOR_LENGTH (objfile
) *= 2;
1202 TYPE_VECTOR (objfile
) = (struct type
**)
1203 xrealloc ((char *) TYPE_VECTOR (objfile
),
1204 (TYPE_VECTOR_LENGTH (objfile
) * sizeof (struct type
*)));
1205 memset (&TYPE_VECTOR (objfile
)[old_len
], 0,
1206 (TYPE_VECTOR_LENGTH (objfile
) - old_len
) *
1207 sizeof (struct type
*));
1209 return &TYPE_VECTOR (objfile
)[index
];
1215 /* Possibly allocate a GDB internal type so we can internalize HP_TYPE.
1216 Note we'll just return the address of a GDB internal type if we already
1217 have it lying around. */
1219 static struct type
*
1220 hpread_alloc_type (hp_type
, objfile
)
1221 DNTTPOINTER hp_type
;
1222 struct objfile
*objfile
;
1224 struct type
**type_addr
;
1226 type_addr
= hpread_lookup_type (hp_type
, objfile
);
1227 if (*type_addr
== 0)
1228 *type_addr
= alloc_type (objfile
);
1230 TYPE_CPLUS_SPECIFIC (*type_addr
)
1231 = (struct cplus_struct_type
*) &cplus_struct_default
;
1235 /* Read a native enumerated type and return it in GDB internal form. */
1237 static struct type
*
1238 hpread_read_enum_type (hp_type
, dn_bufp
, objfile
)
1239 DNTTPOINTER hp_type
;
1240 union dnttentry
*dn_bufp
;
1241 struct objfile
*objfile
;
1244 struct pending
**symlist
, *osyms
, *syms
;
1245 int o_nsyms
, nsyms
= 0;
1247 union dnttentry
*memp
;
1252 type
= hpread_alloc_type (hp_type
, objfile
);
1253 TYPE_LENGTH (type
) = 4;
1255 symlist
= &file_symbols
;
1257 o_nsyms
= osyms
? osyms
->nsyms
: 0;
1259 /* Get a name for each member and add it to our list of members. */
1260 mem
= dn_bufp
->denum
.firstmem
;
1261 while (mem
.dnttp
.extension
&& mem
.word
!= DNTTNIL
)
1263 memp
= hpread_get_lntt (mem
.dnttp
.index
, objfile
);
1265 name
= VT (objfile
) + memp
->dmember
.name
;
1266 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1267 sizeof (struct symbol
));
1268 memset (sym
, 0, sizeof (struct symbol
));
1269 SYMBOL_NAME (sym
) = name
;
1270 SYMBOL_CLASS (sym
) = LOC_CONST
;
1271 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1272 SYMBOL_VALUE (sym
) = memp
->dmember
.value
;
1273 add_symbol_to_list (sym
, symlist
);
1275 mem
= memp
->dmember
.nextmem
;
1278 /* Now that we know more about the enum, fill in more info. */
1279 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1280 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1281 TYPE_NFIELDS (type
) = nsyms
;
1282 TYPE_FIELDS (type
) = (struct field
*)
1283 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
) * nsyms
);
1285 /* Find the symbols for the members and put them into the type.
1286 The symbols can be found in the symlist that we put them on
1287 to cause them to be defined. osyms contains the old value
1288 of that symlist; everything up to there was defined by us.
1290 Note that we preserve the order of the enum constants, so
1291 that in something like "enum {FOO, LAST_THING=FOO}" we print
1292 FOO, not LAST_THING. */
1293 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
1298 for (; j
< syms
->nsyms
; j
++, n
++)
1300 struct symbol
*xsym
= syms
->symbol
[j
];
1301 SYMBOL_TYPE (xsym
) = type
;
1302 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
1303 TYPE_FIELD_VALUE (type
, n
) = 0;
1304 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
1305 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1314 /* Read and internalize a native function debug symbol. */
1316 static struct type
*
1317 hpread_read_function_type (hp_type
, dn_bufp
, objfile
)
1318 DNTTPOINTER hp_type
;
1319 union dnttentry
*dn_bufp
;
1320 struct objfile
*objfile
;
1322 struct type
*type
, *type1
;
1323 struct pending
**symlist
, *osyms
, *syms
;
1324 int o_nsyms
, nsyms
= 0;
1326 union dnttentry
*paramp
;
1331 param
= dn_bufp
->dfunc
.firstparam
;
1333 /* See if we've already read in this type. */
1334 type
= hpread_alloc_type (hp_type
, objfile
);
1335 if (TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1338 /* Nope, so read it in and store it away. */
1339 type1
= lookup_function_type (hpread_type_lookup (dn_bufp
->dfunc
.retval
,
1341 memcpy ((char *) type
, (char *) type1
, sizeof (struct type
));
1343 symlist
= &local_symbols
;
1345 o_nsyms
= osyms
? osyms
->nsyms
: 0;
1347 /* Now examine each parameter noting its type, location, and a
1348 wealth of other information. */
1349 while (param
.word
&& param
.word
!= DNTTNIL
)
1351 paramp
= hpread_get_lntt (param
.dnttp
.index
, objfile
);
1353 param
= paramp
->dfparam
.nextparam
;
1356 name
= VT (objfile
) + paramp
->dfparam
.name
;
1357 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1358 sizeof (struct symbol
));
1359 (void) memset (sym
, 0, sizeof (struct symbol
));
1360 SYMBOL_NAME (sym
) = name
;
1362 /* Figure out where it lives. */
1363 if (paramp
->dfparam
.regparam
)
1364 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1365 else if (paramp
->dfparam
.indirect
)
1366 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1368 SYMBOL_CLASS (sym
) = LOC_ARG
;
1369 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1370 if (paramp
->dfparam
.copyparam
)
1372 SYMBOL_VALUE (sym
) = paramp
->dfparam
.location
;
1373 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1375 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
1377 /* This is likely a pass-by-invisible reference parameter,
1378 Hack on the symbol class to make GDB happy. */
1379 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1382 SYMBOL_VALUE (sym
) = paramp
->dfparam
.location
;
1385 SYMBOL_TYPE (sym
) = hpread_type_lookup (paramp
->dfparam
.type
, objfile
);
1387 /* Add it to the list. */
1388 add_symbol_to_list (sym
, symlist
);
1391 /* Note how many parameters we found. */
1392 TYPE_NFIELDS (type
) = nsyms
;
1393 TYPE_FIELDS (type
) = (struct field
*)
1394 obstack_alloc (&objfile
->type_obstack
,
1395 sizeof (struct field
) * nsyms
);
1397 /* Find the symbols for the values and put them into the type.
1398 The symbols can be found in the symlist that we put them on
1399 to cause them to be defined. osyms contains the old value
1400 of that symlist; everything up to there was defined by us. */
1401 /* Note that we preserve the order of the parameters, so
1402 that in something like "enum {FOO, LAST_THING=FOO}" we print
1403 FOO, not LAST_THING. */
1404 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
1409 for (; j
< syms
->nsyms
; j
++, n
++)
1411 struct symbol
*xsym
= syms
->symbol
[j
];
1412 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
1413 TYPE_FIELD_TYPE (type
, n
) = SYMBOL_TYPE (xsym
);
1414 TYPE_FIELD_BITPOS (type
, n
) = n
;
1415 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1423 /* Read in and internalize a structure definition. */
1425 static struct type
*
1426 hpread_read_struct_type (hp_type
, dn_bufp
, objfile
)
1427 DNTTPOINTER hp_type
;
1428 union dnttentry
*dn_bufp
;
1429 struct objfile
*objfile
;
1433 struct nextfield
*next
;
1438 struct nextfield
*list
= 0;
1439 struct nextfield
*new;
1442 union dnttentry
*fieldp
;
1444 /* Is it something we've already dealt with? */
1445 type
= hpread_alloc_type (hp_type
, objfile
);
1446 if ((TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
1447 (TYPE_CODE (type
) == TYPE_CODE_UNION
))
1450 /* Get the basic type correct. */
1451 if (dn_bufp
->dblock
.kind
== K_STRUCT
)
1453 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1454 TYPE_LENGTH (type
) = dn_bufp
->dstruct
.bitlength
/ 8;
1456 else if (dn_bufp
->dblock
.kind
== K_UNION
)
1458 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1459 TYPE_LENGTH (type
) = dn_bufp
->dunion
.bitlength
/ 8;
1465 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1467 /* Read in and internalize all the fields. */
1468 field
= dn_bufp
->dstruct
.firstfield
;
1469 while (field
.word
!= DNTTNIL
&& field
.dnttp
.extension
)
1471 fieldp
= hpread_get_lntt (field
.dnttp
.index
, objfile
);
1473 /* Get space to record the next field's data. */
1474 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1478 list
->field
.name
= VT (objfile
) + fieldp
->dfield
.name
;
1479 list
->field
.bitpos
= fieldp
->dfield
.bitoffset
;
1480 if (fieldp
->dfield
.bitlength
% 8)
1481 list
->field
.bitsize
= fieldp
->dfield
.bitlength
;
1483 list
->field
.bitsize
= 0;
1485 field
= fieldp
->dfield
.nextfield
;
1486 list
->field
.type
= hpread_type_lookup (fieldp
->dfield
.type
, objfile
);
1489 TYPE_NFIELDS (type
) = nfields
;
1490 TYPE_FIELDS (type
) = (struct field
*)
1491 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
) * nfields
);
1493 /* Copy the saved-up fields into the field vector. */
1494 for (n
= nfields
; list
; list
= list
->next
)
1497 TYPE_FIELD (type
, n
) = list
->field
;
1502 /* Read in and internalize a set debug symbol. */
1504 static struct type
*
1505 hpread_read_set_type (hp_type
, dn_bufp
, objfile
)
1506 DNTTPOINTER hp_type
;
1507 union dnttentry
*dn_bufp
;
1508 struct objfile
*objfile
;
1512 /* See if it's something we've already deal with. */
1513 type
= hpread_alloc_type (hp_type
, objfile
);
1514 if (TYPE_CODE (type
) == TYPE_CODE_SET
)
1517 /* Nope. Fill in the appropriate fields. */
1518 TYPE_CODE (type
) = TYPE_CODE_SET
;
1519 TYPE_LENGTH (type
) = dn_bufp
->dset
.bitlength
/ 8;
1520 TYPE_NFIELDS (type
) = 0;
1521 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->dset
.subtype
,
1526 /* Read in and internalize an array debug symbol. */
1528 static struct type
*
1529 hpread_read_array_type (hp_type
, dn_bufp
, objfile
)
1530 DNTTPOINTER hp_type
;
1531 union dnttentry
*dn_bufp
;
1532 struct objfile
*objfile
;
1535 union dnttentry save
;
1538 /* Why no check here? Because it kept us from properly determining
1539 the size of the array! */
1540 type
= hpread_alloc_type (hp_type
, objfile
);
1542 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1544 /* values are not normalized. */
1545 if (!((dn_bufp
->darray
.arrayisbytes
&& dn_bufp
->darray
.elemisbytes
)
1546 || (!dn_bufp
->darray
.arrayisbytes
&& !dn_bufp
->darray
.elemisbytes
)))
1548 else if (dn_bufp
->darray
.arraylength
== 0x7fffffff)
1550 /* The HP debug format represents char foo[]; as an array with
1551 length 0x7fffffff. Internally GDB wants to represent this
1552 as a pointer. Ugh. */
1553 TYPE_CODE (type
) = TYPE_CODE_PTR
;
1554 TYPE_LENGTH (type
) = 4;
1557 TYPE_LENGTH (type
) = dn_bufp
->darray
.arraylength
/ 8;
1559 TYPE_NFIELDS (type
) = 1;
1560 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->darray
.elemtype
,
1563 TYPE_FIELDS (type
) = (struct field
*)
1564 obstack_alloc (&objfile
->type_obstack
, sizeof (struct field
));
1565 TYPE_FIELD_TYPE (type
, 0) = hpread_type_lookup (dn_bufp
->darray
.indextype
,
1570 /* Read in and internalize a subrange debug symbol. */
1571 static struct type
*
1572 hpread_read_subrange_type (hp_type
, dn_bufp
, objfile
)
1573 DNTTPOINTER hp_type
;
1574 union dnttentry
*dn_bufp
;
1575 struct objfile
*objfile
;
1579 /* Is it something we've already dealt with. */
1580 type
= hpread_alloc_type (hp_type
, objfile
);
1581 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1584 /* Nope, internalize it. */
1585 TYPE_CODE (type
) = TYPE_CODE_RANGE
;
1586 TYPE_LENGTH (type
) = dn_bufp
->dsubr
.bitlength
/ 8;
1587 TYPE_NFIELDS (type
) = 2;
1588 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc
1589 (&objfile
->type_obstack
, 2 * sizeof (struct field
));
1591 if (dn_bufp
->dsubr
.dyn_low
)
1592 TYPE_FIELD_BITPOS (type
, 0) = 0;
1594 TYPE_FIELD_BITPOS (type
, 0) = dn_bufp
->dsubr
.lowbound
;
1596 if (dn_bufp
->dsubr
.dyn_high
)
1597 TYPE_FIELD_BITPOS (type
, 1) = -1;
1599 TYPE_FIELD_BITPOS (type
, 1) = dn_bufp
->dsubr
.highbound
;
1600 TYPE_TARGET_TYPE (type
) = hpread_type_lookup (dn_bufp
->dsubr
.subtype
,
1605 static struct type
*
1606 hpread_type_lookup (hp_type
, objfile
)
1607 DNTTPOINTER hp_type
;
1608 struct objfile
*objfile
;
1610 union dnttentry
*dn_bufp
;
1612 /* First see if it's a simple builtin type. */
1613 if (hp_type
.dntti
.immediate
)
1614 return lookup_fundamental_type (objfile
, hpread_type_translate (hp_type
));
1616 /* Not a builtin type. We'll have to read it in. */
1617 if (hp_type
.dnttp
.index
< LNTT_SYMCOUNT (objfile
))
1618 dn_bufp
= hpread_get_lntt (hp_type
.dnttp
.index
, objfile
);
1620 return lookup_fundamental_type (objfile
, FT_VOID
);
1622 switch (dn_bufp
->dblock
.kind
)
1638 /* Opps. Something went very wrong. */
1639 return lookup_fundamental_type (objfile
, FT_VOID
);
1643 struct type
*structtype
= hpread_type_lookup (dn_bufp
->dtype
.type
,
1646 suffix
= VT (objfile
) + dn_bufp
->dtype
.name
;
1648 TYPE_CPLUS_SPECIFIC (structtype
)
1649 = (struct cplus_struct_type
*) &cplus_struct_default
;
1650 TYPE_NAME (structtype
) = suffix
;
1656 /* Just a little different from above. We have to tack on
1657 an identifier of some kind (struct, union, enum, etc). */
1658 struct type
*structtype
= hpread_type_lookup (dn_bufp
->dtype
.type
,
1660 char *prefix
, *suffix
;
1661 suffix
= VT (objfile
) + dn_bufp
->dtype
.name
;
1663 /* Lookup the next type in the list. It should be a structure,
1664 union, or enum type. We will need to attach that to our name. */
1665 if (dn_bufp
->dtype
.type
.dnttp
.index
< LNTT_SYMCOUNT (objfile
))
1666 dn_bufp
= hpread_get_lntt (dn_bufp
->dtype
.type
.dnttp
.index
, objfile
);
1670 if (dn_bufp
->dblock
.kind
== K_STRUCT
)
1672 else if (dn_bufp
->dblock
.kind
== K_UNION
)
1677 /* Build the correct name. */
1679 = (char *) obstack_alloc (&objfile
->type_obstack
,
1680 strlen (prefix
) + strlen (suffix
) + 1);
1681 TYPE_NAME (structtype
) = strcpy (TYPE_NAME (structtype
), prefix
);
1682 TYPE_NAME (structtype
) = strcat (TYPE_NAME (structtype
), suffix
);
1683 TYPE_TAG_NAME (structtype
) = suffix
;
1685 TYPE_CPLUS_SPECIFIC (structtype
)
1686 = (struct cplus_struct_type
*) &cplus_struct_default
;
1691 return lookup_pointer_type (hpread_type_lookup (dn_bufp
->dptr
.pointsto
,
1694 return hpread_read_enum_type (hp_type
, dn_bufp
, objfile
);
1696 return lookup_fundamental_type (objfile
, FT_VOID
);
1698 return hpread_read_set_type (hp_type
, dn_bufp
, objfile
);
1700 return hpread_read_subrange_type (hp_type
, dn_bufp
, objfile
);
1702 return hpread_read_array_type (hp_type
, dn_bufp
, objfile
);
1705 return hpread_read_struct_type (hp_type
, dn_bufp
, objfile
);
1707 return hpread_type_lookup (dn_bufp
->dfield
.type
, objfile
);
1710 return lookup_fundamental_type (objfile
, FT_VOID
);
1712 return lookup_function_type (hpread_type_lookup (dn_bufp
->dfunctype
.retval
,
1719 return lookup_fundamental_type (objfile
, FT_VOID
);
1724 hpread_record_lines (subfile
, s_idx
, e_idx
, objfile
)
1725 struct subfile
*subfile
;
1726 SLTPOINTER s_idx
, e_idx
;
1727 struct objfile
*objfile
;
1729 union sltentry
*sl_bufp
;
1731 while (s_idx
<= e_idx
)
1733 sl_bufp
= hpread_get_slt (s_idx
, objfile
);
1734 /* Only record "normal" entries in the SLT. */
1735 if (sl_bufp
->snorm
.sltdesc
== SLT_NORMAL
1736 || sl_bufp
->snorm
.sltdesc
== SLT_EXIT
)
1737 record_line (subfile
, sl_bufp
->snorm
.line
, sl_bufp
->snorm
.address
);
1743 /* Internalize one native debug symbol. */
1746 hpread_process_one_debug_symbol (dn_bufp
, name
, section_offsets
, objfile
,
1747 text_offset
, text_size
, filename
, index
)
1748 union dnttentry
*dn_bufp
;
1750 struct section_offsets
*section_offsets
;
1751 struct objfile
*objfile
;
1752 CORE_ADDR text_offset
;
1760 int offset
= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
1761 union dnttentry
*dn_temp
;
1762 DNTTPOINTER hp_type
;
1764 struct context_stack
*new;
1767 /* Allocate one GDB debug symbol and fill in some default values. */
1768 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1769 sizeof (struct symbol
));
1770 memset (sym
, 0, sizeof (struct symbol
));
1771 SYMBOL_NAME (sym
) = name
;
1772 SYMBOL_LANGUAGE (sym
) = language_auto
;
1773 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1774 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1775 SYMBOL_LINE (sym
) = 0;
1776 SYMBOL_VALUE (sym
) = 0;
1777 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1779 hp_type
.dnttp
.extension
= 1;
1780 hp_type
.dnttp
.immediate
= 0;
1781 hp_type
.dnttp
.global
= 0;
1782 hp_type
.dnttp
.index
= index
;
1784 type
= dn_bufp
->dblock
.kind
;
1789 /* This type of symbol indicates from which source file or include file
1790 the following data comes. If there are no modules it also may
1791 indicate the start of a new source file, in which case we must
1792 finish the symbol table of the previous source file
1793 (if any) and start accumulating a new symbol table. */
1795 valu
= text_offset
+ offset
; /* Relocate for dynamic loading */
1796 p
= strrchr (name
, '.');
1797 if (!strcmp (p
, ".h") || HAVE_MODULE (objfile
)
1798 || (last_source_file
&& !strcmp (name
, last_source_file
)))
1800 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1802 dn_bufp
->dsfile
.address
,
1804 start_subfile (name
, NULL
);
1808 if (last_source_file
)
1810 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1812 dn_bufp
->dsfile
.address
,
1814 end_symtab (valu
+ text_size
, 0, 0, objfile
, 0);
1817 SL_INDEX (objfile
) = dn_bufp
->dsfile
.address
;
1818 start_symtab (name
, NULL
, valu
);
1822 /* This kind of symbol indicates the start of a module or C source
1824 valu
= text_offset
+ offset
; /* Relocate for dynamic loading */
1825 SL_INDEX (objfile
) = dn_bufp
->dmodule
.address
;
1826 start_symtab (filename
, NULL
, valu
);
1831 /* A function or secondary entry point. */
1832 valu
= dn_bufp
->dfunc
.lowaddr
+ offset
;
1833 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1835 dn_bufp
->dfunc
.address
,
1838 WITHIN_FUNCTION (objfile
) = 1;
1839 CURRENT_FUNCTION_VALUE (objfile
) = valu
;
1841 /* Stack must be empty now. */
1842 if (context_stack_depth
!= 0)
1843 complain (&lbrac_unmatched_complaint
, (char *) symnum
);
1844 new = push_context (0, valu
);
1846 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1847 SYMBOL_TYPE (sym
) = hpread_read_function_type (hp_type
, dn_bufp
, objfile
);
1848 if (dn_bufp
->dfunc
.public)
1849 add_symbol_to_list (sym
, &global_symbols
);
1851 add_symbol_to_list (sym
, &file_symbols
);
1854 /* Search forward to the next scope beginning. */
1855 while (dn_bufp
->dblock
.kind
!= K_BEGIN
)
1857 dn_bufp
= hpread_get_lntt (++index
, objfile
);
1858 if (dn_bufp
->dblock
.extension
)
1861 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1863 dn_bufp
->dbegin
.address
,
1865 SYMBOL_LINE (sym
) = hpread_get_line (dn_bufp
->dbegin
.address
, objfile
);
1866 record_line (current_subfile
, SYMBOL_LINE (sym
), valu
);
1870 /* Begin a new scope. */
1871 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1873 dn_bufp
->dbegin
.address
,
1875 valu
= hpread_get_location (dn_bufp
->dbegin
.address
, objfile
);
1876 valu
+= offset
; /* Relocate for dynamic loading */
1877 desc
= hpread_get_depth (dn_bufp
->dbegin
.address
, objfile
);
1878 new = push_context (desc
, valu
);
1883 SL_INDEX (objfile
) = hpread_record_lines (current_subfile
,
1885 dn_bufp
->dend
.address
+ 1,
1887 switch (dn_bufp
->dend
.endkind
)
1890 /* Ending a module ends the symbol table for that module. */
1891 valu
= text_offset
+ text_size
+ offset
;
1892 (void) end_symtab (valu
, 0, 0, objfile
, 0);
1896 /* Ending a function, well, ends the function's scope. */
1897 dn_temp
= hpread_get_lntt (dn_bufp
->dend
.beginscope
.dnttp
.index
,
1899 valu
= dn_temp
->dfunc
.hiaddr
+ offset
;
1900 new = pop_context ();
1901 /* Make a block for the local symbols within. */
1902 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1903 new->start_addr
, valu
, objfile
);
1904 WITHIN_FUNCTION (objfile
) = 0;
1907 /* Just ending a local scope. */
1908 valu
= hpread_get_location (dn_bufp
->dend
.address
, objfile
);
1909 /* Why in the hell is this needed? */
1910 valu
+= offset
+ 9; /* Relocate for dynamic loading */
1911 new = pop_context ();
1912 desc
= dn_bufp
->dend
.beginscope
.dnttp
.index
;
1913 if (desc
!= new->depth
)
1914 complain (&lbrac_mismatch_complaint
, (char *) symnum
);
1915 /* Make a block for the local symbols within. */
1916 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1917 new->start_addr
, valu
, objfile
);
1918 local_symbols
= new->locals
;
1923 SYMBOL_NAMESPACE (sym
) = LABEL_NAMESPACE
;
1926 /* Function parameters. */
1927 if (dn_bufp
->dfparam
.regparam
)
1928 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1930 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1931 if (dn_bufp
->dfparam
.copyparam
)
1933 SYMBOL_VALUE (sym
) = dn_bufp
->dfparam
.location
;
1934 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1936 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
1940 SYMBOL_VALUE (sym
) = dn_bufp
->dfparam
.location
;
1941 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dfparam
.type
, objfile
);
1942 add_symbol_to_list (sym
, &local_symbols
);
1945 /* Static variables. */
1946 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1947 SYMBOL_VALUE_ADDRESS (sym
) = dn_bufp
->dsvar
.location
;
1948 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dsvar
.type
, objfile
);
1949 if (dn_bufp
->dsvar
.public)
1950 add_symbol_to_list (sym
, &global_symbols
);
1951 else if (WITHIN_FUNCTION (objfile
))
1952 add_symbol_to_list (sym
, &local_symbols
);
1954 add_symbol_to_list (sym
, &file_symbols
);
1957 /* Dynamic variables. */
1958 if (dn_bufp
->ddvar
.regvar
)
1959 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1961 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1962 SYMBOL_VALUE (sym
) = dn_bufp
->ddvar
.location
;
1963 #ifdef HPREAD_ADJUST_STACK_ADDRESS
1965 += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile
));
1967 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->ddvar
.type
, objfile
);
1968 if (dn_bufp
->ddvar
.public)
1969 add_symbol_to_list (sym
, &global_symbols
);
1970 else if (WITHIN_FUNCTION (objfile
))
1971 add_symbol_to_list (sym
, &local_symbols
);
1973 add_symbol_to_list (sym
, &file_symbols
);
1976 /* A constant (pascal?). */
1977 SYMBOL_CLASS (sym
) = LOC_CONST
;
1978 SYMBOL_VALUE (sym
) = dn_bufp
->dconst
.location
;
1979 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dconst
.type
, objfile
);
1980 if (dn_bufp
->dconst
.public)
1981 add_symbol_to_list (sym
, &global_symbols
);
1982 else if (WITHIN_FUNCTION (objfile
))
1983 add_symbol_to_list (sym
, &local_symbols
);
1985 add_symbol_to_list (sym
, &file_symbols
);
1988 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1989 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dtype
.type
, objfile
);
1990 if (dn_bufp
->dtype
.public)
1991 add_symbol_to_list (sym
, &global_symbols
);
1992 else if (WITHIN_FUNCTION (objfile
))
1993 add_symbol_to_list (sym
, &local_symbols
);
1995 add_symbol_to_list (sym
, &file_symbols
);
1998 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1999 SYMBOL_TYPE (sym
) = hpread_type_lookup (dn_bufp
->dtype
.type
, objfile
);
2000 TYPE_NAME (sym
->type
) = SYMBOL_NAME (sym
);
2001 TYPE_TAG_NAME (sym
->type
) = SYMBOL_NAME (sym
);
2002 if (dn_bufp
->dtype
.public)
2003 add_symbol_to_list (sym
, &global_symbols
);
2004 else if (WITHIN_FUNCTION (objfile
))
2005 add_symbol_to_list (sym
, &local_symbols
);
2007 add_symbol_to_list (sym
, &file_symbols
);
2010 SYMBOL_TYPE (sym
) = lookup_pointer_type (hpread_type_lookup
2011 (dn_bufp
->dptr
.pointsto
,
2013 add_symbol_to_list (sym
, &file_symbols
);
2016 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2017 SYMBOL_TYPE (sym
) = hpread_read_enum_type (hp_type
, dn_bufp
, objfile
);
2018 add_symbol_to_list (sym
, &file_symbols
);
2023 SYMBOL_TYPE (sym
) = hpread_read_set_type (hp_type
, dn_bufp
, objfile
);
2024 add_symbol_to_list (sym
, &file_symbols
);
2027 SYMBOL_TYPE (sym
) = hpread_read_subrange_type (hp_type
, dn_bufp
,
2029 add_symbol_to_list (sym
, &file_symbols
);
2032 SYMBOL_TYPE (sym
) = hpread_read_array_type (hp_type
, dn_bufp
, objfile
);
2033 add_symbol_to_list (sym
, &file_symbols
);
2037 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2038 SYMBOL_TYPE (sym
) = hpread_read_struct_type (hp_type
, dn_bufp
, objfile
);
2039 add_symbol_to_list (sym
, &file_symbols
);