1 /* DWARF debugging format support for GDB.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
5 Written by Fred Fish at Cygnus Support. Portions based on dbxread.c,
6 mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 FIXME: Do we need to generate dependencies in partial symtabs?
27 (Perhaps we don't need to).
29 FIXME: Resolve minor differences between what information we put in the
30 partial symbol table and what dbxread puts in. For example, we don't yet
31 put enum constants there. And dbxread seems to invent a lot of typedefs
32 we never see. Use the new printpsym command to see the partial symbol table
35 FIXME: Figure out a better way to tell gdb about the name of the function
36 contain the user's entry point (I.E. main())
38 FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
39 other things to work on, if you get bored. :-)
48 #include "elf/dwarf.h"
51 #include "expression.h" /* Needed for enum exp_opcode in language.h, sigh... */
53 #include "complaints.h"
56 #include "gdb_string.h"
58 /* Some macros to provide DIE info for complaints. */
60 #define DIE_ID (curdie!=NULL ? curdie->die_ref : 0)
61 #define DIE_NAME (curdie!=NULL && curdie->at_name!=NULL) ? curdie->at_name : ""
63 /* Complaints that can be issued during DWARF debug info reading. */
66 bad_die_ref_complaint (int arg1
, const char *arg2
, int arg3
)
68 complaint (&symfile_complaints
,
69 "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit",
74 unknown_attribute_form_complaint (int arg1
, const char *arg2
, int arg3
)
76 complaint (&symfile_complaints
,
77 "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", arg1
, arg2
,
82 dup_user_type_definition_complaint (int arg1
, const char *arg2
)
84 complaint (&symfile_complaints
,
85 "DIE @ 0x%x \"%s\", internal error: duplicate user type definition",
90 bad_array_element_type_complaint (int arg1
, const char *arg2
, int arg3
)
92 complaint (&symfile_complaints
,
93 "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", arg1
,
97 typedef unsigned int DIE_REF
; /* Reference to a DIE */
100 #define GCC_PRODUCER "GNU C "
103 #ifndef GPLUS_PRODUCER
104 #define GPLUS_PRODUCER "GNU C++ "
108 #define LCC_PRODUCER "NCR C/C++"
111 /* OBSOLETE #ifndef CHILL_PRODUCER */
112 /* OBSOLETE #define CHILL_PRODUCER "GNU Chill " */
113 /* OBSOLETE #endif */
115 /* Flags to target_to_host() that tell whether or not the data object is
116 expected to be signed. Used, for example, when fetching a signed
117 integer in the target environment which is used as a signed integer
118 in the host environment, and the two environments have different sized
119 ints. In this case, *somebody* has to sign extend the smaller sized
122 #define GET_UNSIGNED 0 /* No sign extension required */
123 #define GET_SIGNED 1 /* Sign extension required */
125 /* Defines for things which are specified in the document "DWARF Debugging
126 Information Format" published by UNIX International, Programming Languages
127 SIG. These defines are based on revision 1.0.0, Jan 20, 1992. */
129 #define SIZEOF_DIE_LENGTH 4
130 #define SIZEOF_DIE_TAG 2
131 #define SIZEOF_ATTRIBUTE 2
132 #define SIZEOF_FORMAT_SPECIFIER 1
133 #define SIZEOF_FMT_FT 2
134 #define SIZEOF_LINETBL_LENGTH 4
135 #define SIZEOF_LINETBL_LINENO 4
136 #define SIZEOF_LINETBL_STMT 2
137 #define SIZEOF_LINETBL_DELTA 4
138 #define SIZEOF_LOC_ATOM_CODE 1
140 #define FORM_FROM_ATTR(attr) ((attr) & 0xF) /* Implicitly specified */
142 /* Macros that return the sizes of various types of data in the target
145 FIXME: Currently these are just compile time constants (as they are in
146 other parts of gdb as well). They need to be able to get the right size
147 either from the bfd or possibly from the DWARF info. It would be nice if
148 the DWARF producer inserted DIES that describe the fundamental types in
149 the target environment into the DWARF info, similar to the way dbx stabs
150 producers produce information about their fundamental types. */
152 #define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
153 #define TARGET_FT_LONG_SIZE(objfile) (TARGET_LONG_BIT / TARGET_CHAR_BIT)
155 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
156 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
157 However, the Issue 2 DWARF specification from AT&T defines it as
158 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
159 For backwards compatibility with the AT&T compiler produced executables
160 we define AT_short_element_list for this variant. */
162 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
164 /* The DWARF debugging information consists of two major pieces,
165 one is a block of DWARF Information Entries (DIE's) and the other
166 is a line number table. The "struct dieinfo" structure contains
167 the information for a single DIE, the one currently being processed.
169 In order to make it easier to randomly access the attribute fields
170 of the current DIE, which are specifically unordered within the DIE,
171 each DIE is scanned and an instance of the "struct dieinfo"
172 structure is initialized.
174 Initialization is done in two levels. The first, done by basicdieinfo(),
175 just initializes those fields that are vital to deciding whether or not
176 to use this DIE, how to skip past it, etc. The second, done by the
177 function completedieinfo(), fills in the rest of the information.
179 Attributes which have block forms are not interpreted at the time
180 the DIE is scanned, instead we just save pointers to the start
181 of their value fields.
183 Some fields have a flag <name>_p that is set when the value of the
184 field is valid (I.E. we found a matching attribute in the DIE). Since
185 we may want to test for the presence of some attributes in the DIE,
186 such as AT_low_pc, without restricting the values of the field,
187 we need someway to note that we found such an attribute.
195 char *die
; /* Pointer to the raw DIE data */
196 unsigned long die_length
; /* Length of the raw DIE data */
197 DIE_REF die_ref
; /* Offset of this DIE */
198 unsigned short die_tag
; /* Tag for this DIE */
199 unsigned long at_padding
;
200 unsigned long at_sibling
;
203 unsigned short at_fund_type
;
204 BLOCK
*at_mod_fund_type
;
205 unsigned long at_user_def_type
;
206 BLOCK
*at_mod_u_d_type
;
207 unsigned short at_ordering
;
208 BLOCK
*at_subscr_data
;
209 unsigned long at_byte_size
;
210 unsigned short at_bit_offset
;
211 unsigned long at_bit_size
;
212 BLOCK
*at_element_list
;
213 unsigned long at_stmt_list
;
215 CORE_ADDR at_high_pc
;
216 unsigned long at_language
;
217 unsigned long at_member
;
218 unsigned long at_discr
;
219 BLOCK
*at_discr_value
;
220 BLOCK
*at_string_length
;
223 unsigned long at_start_scope
;
224 unsigned long at_stride_size
;
225 unsigned long at_src_info
;
227 unsigned int has_at_low_pc
:1;
228 unsigned int has_at_stmt_list
:1;
229 unsigned int has_at_byte_size
:1;
230 unsigned int short_element_list
:1;
232 /* Kludge to identify register variables */
236 /* Kludge to identify optimized out variables */
238 unsigned int optimized_out
;
240 /* Kludge to identify basereg references.
241 Nonzero if we have an offset relative to a basereg. */
245 /* Kludge to identify which base register is it relative to. */
247 unsigned int basereg
;
250 static int diecount
; /* Approximate count of dies for compilation unit */
251 static struct dieinfo
*curdie
; /* For warnings and such */
253 static char *dbbase
; /* Base pointer to dwarf info */
254 static int dbsize
; /* Size of dwarf info in bytes */
255 static int dbroff
; /* Relative offset from start of .debug section */
256 static char *lnbase
; /* Base pointer to line section */
258 /* This value is added to each symbol value. FIXME: Generalize to
259 the section_offsets structure used by dbxread (once this is done,
260 pass the appropriate section number to end_symtab). */
261 static CORE_ADDR baseaddr
; /* Add to each symbol value */
263 /* The section offsets used in the current psymtab or symtab. FIXME,
264 only used to pass one value (baseaddr) at the moment. */
265 static struct section_offsets
*base_section_offsets
;
267 /* We put a pointer to this structure in the read_symtab_private field
272 /* Always the absolute file offset to the start of the ".debug"
273 section for the file containing the DIE's being accessed. */
275 /* Relative offset from the start of the ".debug" section to the
276 first DIE to be accessed. When building the partial symbol
277 table, this value will be zero since we are accessing the
278 entire ".debug" section. When expanding a partial symbol
279 table entry, this value will be the offset to the first
280 DIE for the compilation unit containing the symbol that
281 triggers the expansion. */
283 /* The size of the chunk of DIE's being examined, in bytes. */
285 /* The absolute file offset to the line table fragment. Ignored
286 when building partial symbol tables, but used when expanding
287 them, and contains the absolute file offset to the fragment
288 of the ".line" section containing the line numbers for the
289 current compilation unit. */
293 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
294 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
295 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
296 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
298 /* The generic symbol table building routines have separate lists for
299 file scope symbols and all all other scopes (local scopes). So
300 we need to select the right one to pass to add_symbol_to_list().
301 We do it by keeping a pointer to the correct list in list_in_scope.
303 FIXME: The original dwarf code just treated the file scope as the first
304 local scope, and all other local scopes as nested local scopes, and worked
305 fine. Check to see if we really need to distinguish these in buildsym.c */
307 struct pending
**list_in_scope
= &file_symbols
;
309 /* DIES which have user defined types or modified user defined types refer to
310 other DIES for the type information. Thus we need to associate the offset
311 of a DIE for a user defined type with a pointer to the type information.
313 Originally this was done using a simple but expensive algorithm, with an
314 array of unsorted structures, each containing an offset/type-pointer pair.
315 This array was scanned linearly each time a lookup was done. The result
316 was that gdb was spending over half it's startup time munging through this
317 array of pointers looking for a structure that had the right offset member.
319 The second attempt used the same array of structures, but the array was
320 sorted using qsort each time a new offset/type was recorded, and a binary
321 search was used to find the type pointer for a given DIE offset. This was
322 even slower, due to the overhead of sorting the array each time a new
323 offset/type pair was entered.
325 The third attempt uses a fixed size array of type pointers, indexed by a
326 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
327 we can divide any DIE offset by 4 to obtain a unique index into this fixed
328 size array. Since each element is a 4 byte pointer, it takes exactly as
329 much memory to hold this array as to hold the DWARF info for a given
330 compilation unit. But it gets freed as soon as we are done with it.
331 This has worked well in practice, as a reasonable tradeoff between memory
332 consumption and speed, without having to resort to much more complicated
335 static struct type
**utypes
; /* Pointer to array of user type pointers */
336 static int numutypes
; /* Max number of user type pointers */
338 /* Maintain an array of referenced fundamental types for the current
339 compilation unit being read. For DWARF version 1, we have to construct
340 the fundamental types on the fly, since no information about the
341 fundamental types is supplied. Each such fundamental type is created by
342 calling a language dependent routine to create the type, and then a
343 pointer to that type is then placed in the array at the index specified
344 by it's FT_<TYPENAME> value. The array has a fixed size set by the
345 FT_NUM_MEMBERS compile time constant, which is the number of predefined
346 fundamental types gdb knows how to construct. */
348 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
350 /* Record the language for the compilation unit which is currently being
351 processed. We know it once we have seen the TAG_compile_unit DIE,
352 and we need it while processing the DIE's for that compilation unit.
353 It is eventually saved in the symtab structure, but we don't finalize
354 the symtab struct until we have processed all the DIE's for the
355 compilation unit. We also need to get and save a pointer to the
356 language struct for this language, so we can call the language
357 dependent routines for doing things such as creating fundamental
360 static enum language cu_language
;
361 static const struct language_defn
*cu_language_defn
;
363 /* Forward declarations of static functions so we don't have to worry
364 about ordering within this file. */
366 static void free_utypes (PTR
);
368 static int attribute_size (unsigned int);
370 static CORE_ADDR
target_to_host (char *, int, int, struct objfile
*);
372 static void add_enum_psymbol (struct dieinfo
*, struct objfile
*);
374 static void handle_producer (char *);
377 read_file_scope (struct dieinfo
*, char *, char *, struct objfile
*);
380 read_func_scope (struct dieinfo
*, char *, char *, struct objfile
*);
383 read_lexical_block_scope (struct dieinfo
*, char *, char *, struct objfile
*);
385 static void scan_partial_symbols (char *, char *, struct objfile
*);
388 scan_compilation_units (char *, char *, file_ptr
, file_ptr
, struct objfile
*);
390 static void add_partial_symbol (struct dieinfo
*, struct objfile
*);
392 static void basicdieinfo (struct dieinfo
*, char *, struct objfile
*);
394 static void completedieinfo (struct dieinfo
*, struct objfile
*);
396 static void dwarf_psymtab_to_symtab (struct partial_symtab
*);
398 static void psymtab_to_symtab_1 (struct partial_symtab
*);
400 static void read_ofile_symtab (struct partial_symtab
*);
402 static void process_dies (char *, char *, struct objfile
*);
405 read_structure_scope (struct dieinfo
*, char *, char *, struct objfile
*);
407 static struct type
*decode_array_element_type (char *);
409 static struct type
*decode_subscript_data_item (char *, char *);
411 static void dwarf_read_array_type (struct dieinfo
*);
413 static void read_tag_pointer_type (struct dieinfo
*dip
);
415 static void read_tag_string_type (struct dieinfo
*dip
);
417 static void read_subroutine_type (struct dieinfo
*, char *, char *);
420 read_enumeration (struct dieinfo
*, char *, char *, struct objfile
*);
422 static struct type
*struct_type (struct dieinfo
*, char *, char *,
425 static struct type
*enum_type (struct dieinfo
*, struct objfile
*);
427 static void decode_line_numbers (char *);
429 static struct type
*decode_die_type (struct dieinfo
*);
431 static struct type
*decode_mod_fund_type (char *);
433 static struct type
*decode_mod_u_d_type (char *);
435 static struct type
*decode_modified_type (char *, unsigned int, int);
437 static struct type
*decode_fund_type (unsigned int);
439 static char *create_name (char *, struct obstack
*);
441 static struct type
*lookup_utype (DIE_REF
);
443 static struct type
*alloc_utype (DIE_REF
, struct type
*);
445 static struct symbol
*new_symbol (struct dieinfo
*, struct objfile
*);
448 synthesize_typedef (struct dieinfo
*, struct objfile
*, struct type
*);
450 static int locval (struct dieinfo
*);
452 static void set_cu_language (struct dieinfo
*);
454 static struct type
*dwarf_fundamental_type (struct objfile
*, int);
461 dwarf_fundamental_type -- lookup or create a fundamental type
466 dwarf_fundamental_type (struct objfile *objfile, int typeid)
470 DWARF version 1 doesn't supply any fundamental type information,
471 so gdb has to construct such types. It has a fixed number of
472 fundamental types that it knows how to construct, which is the
473 union of all types that it knows how to construct for all languages
474 that it knows about. These are enumerated in gdbtypes.h.
476 As an example, assume we find a DIE that references a DWARF
477 fundamental type of FT_integer. We first look in the ftypes
478 array to see if we already have such a type, indexed by the
479 gdb internal value of FT_INTEGER. If so, we simply return a
480 pointer to that type. If not, then we ask an appropriate
481 language dependent routine to create a type FT_INTEGER, using
482 defaults reasonable for the current target machine, and install
483 that type in ftypes for future reference.
487 Pointer to a fundamental type.
492 dwarf_fundamental_type (struct objfile
*objfile
, int typeid)
494 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
496 error ("internal error - invalid fundamental type id %d", typeid);
499 /* Look for this particular type in the fundamental type vector. If one is
500 not found, create and install one appropriate for the current language
501 and the current target machine. */
503 if (ftypes
[typeid] == NULL
)
505 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
508 return (ftypes
[typeid]);
515 set_cu_language -- set local copy of language for compilation unit
520 set_cu_language (struct dieinfo *dip)
524 Decode the language attribute for a compilation unit DIE and
525 remember what the language was. We use this at various times
526 when processing DIE's for a given compilation unit.
535 set_cu_language (struct dieinfo
*dip
)
537 switch (dip
->at_language
)
541 cu_language
= language_c
;
543 case LANG_C_PLUS_PLUS
:
544 cu_language
= language_cplus
;
546 /* OBSOLETE case LANG_CHILL: */
547 /* OBSOLETE cu_language = language_chill; */
548 /* OBSOLETE break; */
550 cu_language
= language_m2
;
554 cu_language
= language_fortran
;
560 /* We don't know anything special about these yet. */
561 cu_language
= language_unknown
;
564 /* If no at_language, try to deduce one from the filename */
565 cu_language
= deduce_language_from_filename (dip
->at_name
);
568 cu_language_defn
= language_def (cu_language
);
575 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
579 void dwarf_build_psymtabs (struct objfile *objfile,
580 int mainline, file_ptr dbfoff, unsigned int dbfsize,
581 file_ptr lnoffset, unsigned int lnsize)
585 This function is called upon to build partial symtabs from files
586 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
588 It is passed a bfd* containing the DIES
589 and line number information, the corresponding filename for that
590 file, a base address for relocating the symbols, a flag indicating
591 whether or not this debugging information is from a "main symbol
592 table" rather than a shared library or dynamically linked file,
593 and file offset/size pairs for the DIE information and line number
603 dwarf_build_psymtabs (struct objfile
*objfile
, int mainline
, file_ptr dbfoff
,
604 unsigned int dbfsize
, file_ptr lnoffset
,
607 bfd
*abfd
= objfile
->obfd
;
608 struct cleanup
*back_to
;
610 current_objfile
= objfile
;
612 dbbase
= xmalloc (dbsize
);
614 if ((bfd_seek (abfd
, dbfoff
, SEEK_SET
) != 0) ||
615 (bfd_bread (dbbase
, dbsize
, abfd
) != dbsize
))
618 error ("can't read DWARF data from '%s'", bfd_get_filename (abfd
));
620 back_to
= make_cleanup (xfree
, dbbase
);
622 /* If we are reinitializing, or if we have never loaded syms yet, init.
623 Since we have no idea how many DIES we are looking at, we just guess
624 some arbitrary value. */
627 || (objfile
->global_psymbols
.size
== 0
628 && objfile
->static_psymbols
.size
== 0))
630 init_psymbol_list (objfile
, 1024);
633 /* Save the relocation factor where everybody can see it. */
635 base_section_offsets
= objfile
->section_offsets
;
636 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
638 /* Follow the compilation unit sibling chain, building a partial symbol
639 table entry for each one. Save enough information about each compilation
640 unit to locate the full DWARF information later. */
642 scan_compilation_units (dbbase
, dbbase
+ dbsize
, dbfoff
, lnoffset
, objfile
);
644 do_cleanups (back_to
);
645 current_objfile
= NULL
;
652 read_lexical_block_scope -- process all dies in a lexical block
656 static void read_lexical_block_scope (struct dieinfo *dip,
657 char *thisdie, char *enddie)
661 Process all the DIES contained within a lexical block scope.
662 Start a new scope, process the dies, and then close the scope.
667 read_lexical_block_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
668 struct objfile
*objfile
)
670 register struct context_stack
*new;
672 push_context (0, dip
->at_low_pc
);
673 process_dies (thisdie
+ dip
->die_length
, enddie
, objfile
);
674 new = pop_context ();
675 if (local_symbols
!= NULL
)
677 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
678 dip
->at_high_pc
, objfile
);
680 local_symbols
= new->locals
;
687 lookup_utype -- look up a user defined type from die reference
691 static type *lookup_utype (DIE_REF die_ref)
695 Given a DIE reference, lookup the user defined type associated with
696 that DIE, if it has been registered already. If not registered, then
697 return NULL. Alloc_utype() can be called to register an empty
698 type for this reference, which will be filled in later when the
699 actual referenced DIE is processed.
703 lookup_utype (DIE_REF die_ref
)
705 struct type
*type
= NULL
;
708 utypeidx
= (die_ref
- dbroff
) / 4;
709 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
711 bad_die_ref_complaint (DIE_ID
, DIE_NAME
, die_ref
);
715 type
= *(utypes
+ utypeidx
);
725 alloc_utype -- add a user defined type for die reference
729 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
733 Given a die reference DIE_REF, and a possible pointer to a user
734 defined type UTYPEP, register that this reference has a user
735 defined type and either use the specified type in UTYPEP or
736 make a new empty type that will be filled in later.
738 We should only be called after calling lookup_utype() to verify that
739 there is not currently a type registered for DIE_REF.
743 alloc_utype (DIE_REF die_ref
, struct type
*utypep
)
748 utypeidx
= (die_ref
- dbroff
) / 4;
749 typep
= utypes
+ utypeidx
;
750 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
752 utypep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
753 bad_die_ref_complaint (DIE_ID
, DIE_NAME
, die_ref
);
755 else if (*typep
!= NULL
)
758 complaint (&symfile_complaints
,
759 "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation",
766 utypep
= alloc_type (current_objfile
);
777 free_utypes -- free the utypes array and reset pointer & count
781 static void free_utypes (PTR dummy)
785 Called via do_cleanups to free the utypes array, reset the pointer to NULL,
786 and set numutypes back to zero. This ensures that the utypes does not get
787 referenced after being freed.
791 free_utypes (PTR dummy
)
803 decode_die_type -- return a type for a specified die
807 static struct type *decode_die_type (struct dieinfo *dip)
811 Given a pointer to a die information structure DIP, decode the
812 type of the die and return a pointer to the decoded type. All
813 dies without specific types default to type int.
817 decode_die_type (struct dieinfo
*dip
)
819 struct type
*type
= NULL
;
821 if (dip
->at_fund_type
!= 0)
823 type
= decode_fund_type (dip
->at_fund_type
);
825 else if (dip
->at_mod_fund_type
!= NULL
)
827 type
= decode_mod_fund_type (dip
->at_mod_fund_type
);
829 else if (dip
->at_user_def_type
)
831 if ((type
= lookup_utype (dip
->at_user_def_type
)) == NULL
)
833 type
= alloc_utype (dip
->at_user_def_type
, NULL
);
836 else if (dip
->at_mod_u_d_type
)
838 type
= decode_mod_u_d_type (dip
->at_mod_u_d_type
);
842 type
= dwarf_fundamental_type (current_objfile
, FT_VOID
);
851 struct_type -- compute and return the type for a struct or union
855 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
856 char *enddie, struct objfile *objfile)
860 Given pointer to a die information structure for a die which
861 defines a union or structure (and MUST define one or the other),
862 and pointers to the raw die data that define the range of dies which
863 define the members, compute and return the user defined type for the
868 struct_type (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
869 struct objfile
*objfile
)
874 struct nextfield
*next
;
877 struct nextfield
*list
= NULL
;
878 struct nextfield
*new;
885 if ((type
= lookup_utype (dip
->die_ref
)) == NULL
)
887 /* No forward references created an empty type, so install one now */
888 type
= alloc_utype (dip
->die_ref
, NULL
);
890 INIT_CPLUS_SPECIFIC (type
);
891 switch (dip
->die_tag
)
894 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
896 case TAG_structure_type
:
897 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
900 TYPE_CODE (type
) = TYPE_CODE_UNION
;
903 /* Should never happen */
904 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
905 complaint (&symfile_complaints
,
906 "DIE @ 0x%x \"%s\", missing class, structure, or union tag",
910 /* Some compilers try to be helpful by inventing "fake" names for
911 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
912 Thanks, but no thanks... */
913 if (dip
->at_name
!= NULL
914 && *dip
->at_name
!= '~'
915 && *dip
->at_name
!= '.')
917 TYPE_TAG_NAME (type
) = obconcat (&objfile
->type_obstack
,
918 "", "", dip
->at_name
);
920 /* Use whatever size is known. Zero is a valid size. We might however
921 wish to check has_at_byte_size to make sure that some byte size was
922 given explicitly, but DWARF doesn't specify that explicit sizes of
923 zero have to present, so complaining about missing sizes should
924 probably not be the default. */
925 TYPE_LENGTH (type
) = dip
->at_byte_size
;
926 thisdie
+= dip
->die_length
;
927 while (thisdie
< enddie
)
929 basicdieinfo (&mbr
, thisdie
, objfile
);
930 completedieinfo (&mbr
, objfile
);
931 if (mbr
.die_length
<= SIZEOF_DIE_LENGTH
)
935 else if (mbr
.at_sibling
!= 0)
937 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
941 nextdie
= thisdie
+ mbr
.die_length
;
946 /* Get space to record the next field's data. */
947 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
952 obsavestring (mbr
.at_name
, strlen (mbr
.at_name
),
953 &objfile
->type_obstack
);
954 FIELD_TYPE (list
->field
) = decode_die_type (&mbr
);
955 FIELD_BITPOS (list
->field
) = 8 * locval (&mbr
);
956 FIELD_STATIC_KIND (list
->field
) = 0;
957 /* Handle bit fields. */
958 FIELD_BITSIZE (list
->field
) = mbr
.at_bit_size
;
961 /* For big endian bits, the at_bit_offset gives the
962 additional bit offset from the MSB of the containing
963 anonymous object to the MSB of the field. We don't
964 have to do anything special since we don't need to
965 know the size of the anonymous object. */
966 FIELD_BITPOS (list
->field
) += mbr
.at_bit_offset
;
970 /* For little endian bits, we need to have a non-zero
971 at_bit_size, so that we know we are in fact dealing
972 with a bitfield. Compute the bit offset to the MSB
973 of the anonymous object, subtract off the number of
974 bits from the MSB of the field to the MSB of the
975 object, and then subtract off the number of bits of
976 the field itself. The result is the bit offset of
977 the LSB of the field. */
978 if (mbr
.at_bit_size
> 0)
980 if (mbr
.has_at_byte_size
)
982 /* The size of the anonymous object containing
983 the bit field is explicit, so use the
984 indicated size (in bytes). */
985 anonymous_size
= mbr
.at_byte_size
;
989 /* The size of the anonymous object containing
990 the bit field matches the size of an object
991 of the bit field's type. DWARF allows
992 at_byte_size to be left out in such cases, as
993 a debug information size optimization. */
994 anonymous_size
= TYPE_LENGTH (list
->field
.type
);
996 FIELD_BITPOS (list
->field
) +=
997 anonymous_size
* 8 - mbr
.at_bit_offset
- mbr
.at_bit_size
;
1003 process_dies (thisdie
, nextdie
, objfile
);
1008 /* Now create the vector of fields, and record how big it is. We may
1009 not even have any fields, if this DIE was generated due to a reference
1010 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
1011 set, which clues gdb in to the fact that it needs to search elsewhere
1012 for the full structure definition. */
1015 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1019 TYPE_NFIELDS (type
) = nfields
;
1020 TYPE_FIELDS (type
) = (struct field
*)
1021 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1022 /* Copy the saved-up fields into the field vector. */
1023 for (n
= nfields
; list
; list
= list
->next
)
1025 TYPE_FIELD (type
, --n
) = list
->field
;
1035 read_structure_scope -- process all dies within struct or union
1039 static void read_structure_scope (struct dieinfo *dip,
1040 char *thisdie, char *enddie, struct objfile *objfile)
1044 Called when we find the DIE that starts a structure or union
1045 scope (definition) to process all dies that define the members
1046 of the structure or union. DIP is a pointer to the die info
1047 struct for the DIE that names the structure or union.
1051 Note that we need to call struct_type regardless of whether or not
1052 the DIE has an at_name attribute, since it might be an anonymous
1053 structure or union. This gets the type entered into our set of
1056 However, if the structure is incomplete (an opaque struct/union)
1057 then suppress creating a symbol table entry for it since gdb only
1058 wants to find the one with the complete definition. Note that if
1059 it is complete, we just call new_symbol, which does it's own
1060 checking about whether the struct/union is anonymous or not (and
1061 suppresses creating a symbol table entry itself).
1066 read_structure_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1067 struct objfile
*objfile
)
1072 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
1073 if (!TYPE_STUB (type
))
1075 sym
= new_symbol (dip
, objfile
);
1078 SYMBOL_TYPE (sym
) = type
;
1079 if (cu_language
== language_cplus
)
1081 synthesize_typedef (dip
, objfile
, type
);
1091 decode_array_element_type -- decode type of the array elements
1095 static struct type *decode_array_element_type (char *scan, char *end)
1099 As the last step in decoding the array subscript information for an
1100 array DIE, we need to decode the type of the array elements. We are
1101 passed a pointer to this last part of the subscript information and
1102 must return the appropriate type. If the type attribute is not
1103 recognized, just warn about the problem and return type int.
1106 static struct type
*
1107 decode_array_element_type (char *scan
)
1111 unsigned short attribute
;
1112 unsigned short fundtype
;
1115 attribute
= target_to_host (scan
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
,
1117 scan
+= SIZEOF_ATTRIBUTE
;
1118 if ((nbytes
= attribute_size (attribute
)) == -1)
1120 bad_array_element_type_complaint (DIE_ID
, DIE_NAME
, attribute
);
1121 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1128 fundtype
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1130 typep
= decode_fund_type (fundtype
);
1132 case AT_mod_fund_type
:
1133 typep
= decode_mod_fund_type (scan
);
1135 case AT_user_def_type
:
1136 die_ref
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1138 if ((typep
= lookup_utype (die_ref
)) == NULL
)
1140 typep
= alloc_utype (die_ref
, NULL
);
1143 case AT_mod_u_d_type
:
1144 typep
= decode_mod_u_d_type (scan
);
1147 bad_array_element_type_complaint (DIE_ID
, DIE_NAME
, attribute
);
1148 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1159 decode_subscript_data_item -- decode array subscript item
1163 static struct type *
1164 decode_subscript_data_item (char *scan, char *end)
1168 The array subscripts and the data type of the elements of an
1169 array are described by a list of data items, stored as a block
1170 of contiguous bytes. There is a data item describing each array
1171 dimension, and a final data item describing the element type.
1172 The data items are ordered the same as their appearance in the
1173 source (I.E. leftmost dimension first, next to leftmost second,
1176 The data items describing each array dimension consist of four
1177 parts: (1) a format specifier, (2) type type of the subscript
1178 index, (3) a description of the low bound of the array dimension,
1179 and (4) a description of the high bound of the array dimension.
1181 The last data item is the description of the type of each of
1184 We are passed a pointer to the start of the block of bytes
1185 containing the remaining data items, and a pointer to the first
1186 byte past the data. This function recursively decodes the
1187 remaining data items and returns a type.
1189 If we somehow fail to decode some data, we complain about it
1190 and return a type "array of int".
1193 FIXME: This code only implements the forms currently used
1194 by the AT&T and GNU C compilers.
1196 The end pointer is supplied for error checking, maybe we should
1200 static struct type
*
1201 decode_subscript_data_item (char *scan
, char *end
)
1203 struct type
*typep
= NULL
; /* Array type we are building */
1204 struct type
*nexttype
; /* Type of each element (may be array) */
1205 struct type
*indextype
; /* Type of this index */
1206 struct type
*rangetype
;
1207 unsigned int format
;
1208 unsigned short fundtype
;
1209 unsigned long lowbound
;
1210 unsigned long highbound
;
1213 format
= target_to_host (scan
, SIZEOF_FORMAT_SPECIFIER
, GET_UNSIGNED
,
1215 scan
+= SIZEOF_FORMAT_SPECIFIER
;
1219 typep
= decode_array_element_type (scan
);
1222 fundtype
= target_to_host (scan
, SIZEOF_FMT_FT
, GET_UNSIGNED
,
1224 indextype
= decode_fund_type (fundtype
);
1225 scan
+= SIZEOF_FMT_FT
;
1226 nbytes
= TARGET_FT_LONG_SIZE (current_objfile
);
1227 lowbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, current_objfile
);
1229 highbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, current_objfile
);
1231 nexttype
= decode_subscript_data_item (scan
, end
);
1232 if (nexttype
== NULL
)
1234 /* Munged subscript data or other problem, fake it. */
1235 complaint (&symfile_complaints
,
1236 "DIE @ 0x%x \"%s\", can't decode subscript data items",
1238 nexttype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1240 rangetype
= create_range_type ((struct type
*) NULL
, indextype
,
1241 lowbound
, highbound
);
1242 typep
= create_array_type ((struct type
*) NULL
, nexttype
, rangetype
);
1251 complaint (&symfile_complaints
,
1252 "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet",
1253 DIE_ID
, DIE_NAME
, format
);
1254 nexttype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1255 rangetype
= create_range_type ((struct type
*) NULL
, nexttype
, 0, 0);
1256 typep
= create_array_type ((struct type
*) NULL
, nexttype
, rangetype
);
1259 complaint (&symfile_complaints
,
1260 "DIE @ 0x%x \"%s\", unknown array subscript format %x", DIE_ID
,
1262 nexttype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1263 rangetype
= create_range_type ((struct type
*) NULL
, nexttype
, 0, 0);
1264 typep
= create_array_type ((struct type
*) NULL
, nexttype
, rangetype
);
1274 dwarf_read_array_type -- read TAG_array_type DIE
1278 static void dwarf_read_array_type (struct dieinfo *dip)
1282 Extract all information from a TAG_array_type DIE and add to
1283 the user defined type vector.
1287 dwarf_read_array_type (struct dieinfo
*dip
)
1293 unsigned short blocksz
;
1296 if (dip
->at_ordering
!= ORD_row_major
)
1298 /* FIXME: Can gdb even handle column major arrays? */
1299 complaint (&symfile_complaints
,
1300 "DIE @ 0x%x \"%s\", array not row major; not handled correctly",
1303 if ((sub
= dip
->at_subscr_data
) != NULL
)
1305 nbytes
= attribute_size (AT_subscr_data
);
1306 blocksz
= target_to_host (sub
, nbytes
, GET_UNSIGNED
, current_objfile
);
1307 subend
= sub
+ nbytes
+ blocksz
;
1309 type
= decode_subscript_data_item (sub
, subend
);
1310 if ((utype
= lookup_utype (dip
->die_ref
)) == NULL
)
1312 /* Install user defined type that has not been referenced yet. */
1313 alloc_utype (dip
->die_ref
, type
);
1315 else if (TYPE_CODE (utype
) == TYPE_CODE_UNDEF
)
1317 /* Ick! A forward ref has already generated a blank type in our
1318 slot, and this type probably already has things pointing to it
1319 (which is what caused it to be created in the first place).
1320 If it's just a place holder we can plop our fully defined type
1321 on top of it. We can't recover the space allocated for our
1322 new type since it might be on an obstack, but we could reuse
1323 it if we kept a list of them, but it might not be worth it
1329 /* Double ick! Not only is a type already in our slot, but
1330 someone has decorated it. Complain and leave it alone. */
1331 dup_user_type_definition_complaint (DIE_ID
, DIE_NAME
);
1340 read_tag_pointer_type -- read TAG_pointer_type DIE
1344 static void read_tag_pointer_type (struct dieinfo *dip)
1348 Extract all information from a TAG_pointer_type DIE and add to
1349 the user defined type vector.
1353 read_tag_pointer_type (struct dieinfo
*dip
)
1358 type
= decode_die_type (dip
);
1359 if ((utype
= lookup_utype (dip
->die_ref
)) == NULL
)
1361 utype
= lookup_pointer_type (type
);
1362 alloc_utype (dip
->die_ref
, utype
);
1366 TYPE_TARGET_TYPE (utype
) = type
;
1367 TYPE_POINTER_TYPE (type
) = utype
;
1369 /* We assume the machine has only one representation for pointers! */
1370 /* FIXME: Possably a poor assumption */
1371 TYPE_LENGTH (utype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
1372 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1380 read_tag_string_type -- read TAG_string_type DIE
1384 static void read_tag_string_type (struct dieinfo *dip)
1388 Extract all information from a TAG_string_type DIE and add to
1389 the user defined type vector. It isn't really a user defined
1390 type, but it behaves like one, with other DIE's using an
1391 AT_user_def_type attribute to reference it.
1395 read_tag_string_type (struct dieinfo
*dip
)
1398 struct type
*indextype
;
1399 struct type
*rangetype
;
1400 unsigned long lowbound
= 0;
1401 unsigned long highbound
;
1403 if (dip
->has_at_byte_size
)
1405 /* A fixed bounds string */
1406 highbound
= dip
->at_byte_size
- 1;
1410 /* A varying length string. Stub for now. (FIXME) */
1413 indextype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1414 rangetype
= create_range_type ((struct type
*) NULL
, indextype
, lowbound
,
1417 utype
= lookup_utype (dip
->die_ref
);
1420 /* No type defined, go ahead and create a blank one to use. */
1421 utype
= alloc_utype (dip
->die_ref
, (struct type
*) NULL
);
1425 /* Already a type in our slot due to a forward reference. Make sure it
1426 is a blank one. If not, complain and leave it alone. */
1427 if (TYPE_CODE (utype
) != TYPE_CODE_UNDEF
)
1429 dup_user_type_definition_complaint (DIE_ID
, DIE_NAME
);
1434 /* Create the string type using the blank type we either found or created. */
1435 utype
= create_string_type (utype
, rangetype
);
1442 read_subroutine_type -- process TAG_subroutine_type dies
1446 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1451 Handle DIES due to C code like:
1454 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1460 The parameter DIES are currently ignored. See if gdb has a way to
1461 include this info in it's type system, and decode them if so. Is
1462 this what the type structure's "arg_types" field is for? (FIXME)
1466 read_subroutine_type (struct dieinfo
*dip
, char *thisdie
, char *enddie
)
1468 struct type
*type
; /* Type that this function returns */
1469 struct type
*ftype
; /* Function that returns above type */
1471 /* Decode the type that this subroutine returns */
1473 type
= decode_die_type (dip
);
1475 /* Check to see if we already have a partially constructed user
1476 defined type for this DIE, from a forward reference. */
1478 if ((ftype
= lookup_utype (dip
->die_ref
)) == NULL
)
1480 /* This is the first reference to one of these types. Make
1481 a new one and place it in the user defined types. */
1482 ftype
= lookup_function_type (type
);
1483 alloc_utype (dip
->die_ref
, ftype
);
1485 else if (TYPE_CODE (ftype
) == TYPE_CODE_UNDEF
)
1487 /* We have an existing partially constructed type, so bash it
1488 into the correct type. */
1489 TYPE_TARGET_TYPE (ftype
) = type
;
1490 TYPE_LENGTH (ftype
) = 1;
1491 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1495 dup_user_type_definition_complaint (DIE_ID
, DIE_NAME
);
1503 read_enumeration -- process dies which define an enumeration
1507 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1508 char *enddie, struct objfile *objfile)
1512 Given a pointer to a die which begins an enumeration, process all
1513 the dies that define the members of the enumeration.
1517 Note that we need to call enum_type regardless of whether or not we
1518 have a symbol, since we might have an enum without a tag name (thus
1519 no symbol for the tagname).
1523 read_enumeration (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1524 struct objfile
*objfile
)
1529 type
= enum_type (dip
, objfile
);
1530 sym
= new_symbol (dip
, objfile
);
1533 SYMBOL_TYPE (sym
) = type
;
1534 if (cu_language
== language_cplus
)
1536 synthesize_typedef (dip
, objfile
, type
);
1545 enum_type -- decode and return a type for an enumeration
1549 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1553 Given a pointer to a die information structure for the die which
1554 starts an enumeration, process all the dies that define the members
1555 of the enumeration and return a type pointer for the enumeration.
1557 At the same time, for each member of the enumeration, create a
1558 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1559 and give it the type of the enumeration itself.
1563 Note that the DWARF specification explicitly mandates that enum
1564 constants occur in reverse order from the source program order,
1565 for "consistency" and because this ordering is easier for many
1566 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1567 Entries). Because gdb wants to see the enum members in program
1568 source order, we have to ensure that the order gets reversed while
1569 we are processing them.
1572 static struct type
*
1573 enum_type (struct dieinfo
*dip
, struct objfile
*objfile
)
1578 struct nextfield
*next
;
1581 struct nextfield
*list
= NULL
;
1582 struct nextfield
*new;
1587 unsigned short blocksz
;
1590 int unsigned_enum
= 1;
1592 if ((type
= lookup_utype (dip
->die_ref
)) == NULL
)
1594 /* No forward references created an empty type, so install one now */
1595 type
= alloc_utype (dip
->die_ref
, NULL
);
1597 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1598 /* Some compilers try to be helpful by inventing "fake" names for
1599 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1600 Thanks, but no thanks... */
1601 if (dip
->at_name
!= NULL
1602 && *dip
->at_name
!= '~'
1603 && *dip
->at_name
!= '.')
1605 TYPE_TAG_NAME (type
) = obconcat (&objfile
->type_obstack
,
1606 "", "", dip
->at_name
);
1608 if (dip
->at_byte_size
!= 0)
1610 TYPE_LENGTH (type
) = dip
->at_byte_size
;
1612 if ((scan
= dip
->at_element_list
) != NULL
)
1614 if (dip
->short_element_list
)
1616 nbytes
= attribute_size (AT_short_element_list
);
1620 nbytes
= attribute_size (AT_element_list
);
1622 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
1623 listend
= scan
+ nbytes
+ blocksz
;
1625 while (scan
< listend
)
1627 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1630 FIELD_TYPE (list
->field
) = NULL
;
1631 FIELD_BITSIZE (list
->field
) = 0;
1632 FIELD_STATIC_KIND (list
->field
) = 0;
1633 FIELD_BITPOS (list
->field
) =
1634 target_to_host (scan
, TARGET_FT_LONG_SIZE (objfile
), GET_SIGNED
,
1636 scan
+= TARGET_FT_LONG_SIZE (objfile
);
1637 list
->field
.name
= obsavestring (scan
, strlen (scan
),
1638 &objfile
->type_obstack
);
1639 scan
+= strlen (scan
) + 1;
1641 /* Handcraft a new symbol for this enum member. */
1642 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1643 sizeof (struct symbol
));
1644 memset (sym
, 0, sizeof (struct symbol
));
1645 SYMBOL_NAME (sym
) = create_name (list
->field
.name
,
1646 &objfile
->symbol_obstack
);
1647 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym
, cu_language
);
1648 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1649 SYMBOL_CLASS (sym
) = LOC_CONST
;
1650 SYMBOL_TYPE (sym
) = type
;
1651 SYMBOL_VALUE (sym
) = FIELD_BITPOS (list
->field
);
1652 if (SYMBOL_VALUE (sym
) < 0)
1654 add_symbol_to_list (sym
, list_in_scope
);
1656 /* Now create the vector of fields, and record how big it is. This is
1657 where we reverse the order, by pulling the members off the list in
1658 reverse order from how they were inserted. If we have no fields
1659 (this is apparently possible in C++) then skip building a field
1664 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
1665 TYPE_NFIELDS (type
) = nfields
;
1666 TYPE_FIELDS (type
) = (struct field
*)
1667 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1668 /* Copy the saved-up fields into the field vector. */
1669 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
->next
)
1671 TYPE_FIELD (type
, n
++) = list
->field
;
1682 read_func_scope -- process all dies within a function scope
1686 Process all dies within a given function scope. We are passed
1687 a die information structure pointer DIP for the die which
1688 starts the function scope, and pointers into the raw die data
1689 that define the dies within the function scope.
1691 For now, we ignore lexical block scopes within the function.
1692 The problem is that AT&T cc does not define a DWARF lexical
1693 block scope for the function itself, while gcc defines a
1694 lexical block scope for the function. We need to think about
1695 how to handle this difference, or if it is even a problem.
1700 read_func_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1701 struct objfile
*objfile
)
1703 register struct context_stack
*new;
1705 /* AT_name is absent if the function is described with an
1706 AT_abstract_origin tag.
1707 Ignore the function description for now to avoid GDB core dumps.
1708 FIXME: Add code to handle AT_abstract_origin tags properly. */
1709 if (dip
->at_name
== NULL
)
1711 complaint (&symfile_complaints
, "DIE @ 0x%x, AT_name tag missing",
1716 if (objfile
->ei
.entry_point
>= dip
->at_low_pc
&&
1717 objfile
->ei
.entry_point
< dip
->at_high_pc
)
1719 objfile
->ei
.entry_func_lowpc
= dip
->at_low_pc
;
1720 objfile
->ei
.entry_func_highpc
= dip
->at_high_pc
;
1722 new = push_context (0, dip
->at_low_pc
);
1723 new->name
= new_symbol (dip
, objfile
);
1724 list_in_scope
= &local_symbols
;
1725 process_dies (thisdie
+ dip
->die_length
, enddie
, objfile
);
1726 new = pop_context ();
1727 /* Make a block for the local symbols within. */
1728 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1729 new->start_addr
, dip
->at_high_pc
, objfile
);
1730 list_in_scope
= &file_symbols
;
1738 handle_producer -- process the AT_producer attribute
1742 Perform any operations that depend on finding a particular
1743 AT_producer attribute.
1748 handle_producer (char *producer
)
1751 /* If this compilation unit was compiled with g++ or gcc, then set the
1752 processing_gcc_compilation flag. */
1754 if (STREQN (producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
)))
1756 char version
= producer
[strlen (GCC_PRODUCER
)];
1757 processing_gcc_compilation
= (version
== '2' ? 2 : 1);
1761 processing_gcc_compilation
=
1762 STREQN (producer
, GPLUS_PRODUCER
, strlen (GPLUS_PRODUCER
));
1763 /* OBSOLETE || STREQN (producer, CHILL_PRODUCER, strlen (CHILL_PRODUCER)); */
1766 /* Select a demangling style if we can identify the producer and if
1767 the current style is auto. We leave the current style alone if it
1768 is not auto. We also leave the demangling style alone if we find a
1769 gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
1771 if (AUTO_DEMANGLING
)
1773 if (STREQN (producer
, GPLUS_PRODUCER
, strlen (GPLUS_PRODUCER
)))
1776 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
1777 know whether it will use the old style or v3 mangling. */
1778 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
1781 else if (STREQN (producer
, LCC_PRODUCER
, strlen (LCC_PRODUCER
)))
1783 set_demangling_style (LUCID_DEMANGLING_STYLE_STRING
);
1793 read_file_scope -- process all dies within a file scope
1797 Process all dies within a given file scope. We are passed a
1798 pointer to the die information structure for the die which
1799 starts the file scope, and pointers into the raw die data which
1800 mark the range of dies within the file scope.
1802 When the partial symbol table is built, the file offset for the line
1803 number table for each compilation unit is saved in the partial symbol
1804 table entry for that compilation unit. As the symbols for each
1805 compilation unit are read, the line number table is read into memory
1806 and the variable lnbase is set to point to it. Thus all we have to
1807 do is use lnbase to access the line number table for the current
1812 read_file_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1813 struct objfile
*objfile
)
1815 struct cleanup
*back_to
;
1816 struct symtab
*symtab
;
1818 if (objfile
->ei
.entry_point
>= dip
->at_low_pc
&&
1819 objfile
->ei
.entry_point
< dip
->at_high_pc
)
1821 objfile
->ei
.entry_file_lowpc
= dip
->at_low_pc
;
1822 objfile
->ei
.entry_file_highpc
= dip
->at_high_pc
;
1824 set_cu_language (dip
);
1825 if (dip
->at_producer
!= NULL
)
1827 handle_producer (dip
->at_producer
);
1829 numutypes
= (enddie
- thisdie
) / 4;
1830 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1831 back_to
= make_cleanup (free_utypes
, NULL
);
1832 memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1833 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1834 start_symtab (dip
->at_name
, dip
->at_comp_dir
, dip
->at_low_pc
);
1835 record_debugformat ("DWARF 1");
1836 decode_line_numbers (lnbase
);
1837 process_dies (thisdie
+ dip
->die_length
, enddie
, objfile
);
1839 symtab
= end_symtab (dip
->at_high_pc
, objfile
, 0);
1842 symtab
->language
= cu_language
;
1844 do_cleanups (back_to
);
1851 process_dies -- process a range of DWARF Information Entries
1855 static void process_dies (char *thisdie, char *enddie,
1856 struct objfile *objfile)
1860 Process all DIE's in a specified range. May be (and almost
1861 certainly will be) called recursively.
1865 process_dies (char *thisdie
, char *enddie
, struct objfile
*objfile
)
1870 while (thisdie
< enddie
)
1872 basicdieinfo (&di
, thisdie
, objfile
);
1873 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
1877 else if (di
.die_tag
== TAG_padding
)
1879 nextdie
= thisdie
+ di
.die_length
;
1883 completedieinfo (&di
, objfile
);
1884 if (di
.at_sibling
!= 0)
1886 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1890 nextdie
= thisdie
+ di
.die_length
;
1892 /* I think that these are always text, not data, addresses. */
1893 di
.at_low_pc
= SMASH_TEXT_ADDRESS (di
.at_low_pc
);
1894 di
.at_high_pc
= SMASH_TEXT_ADDRESS (di
.at_high_pc
);
1897 case TAG_compile_unit
:
1898 /* Skip Tag_compile_unit if we are already inside a compilation
1899 unit, we are unable to handle nested compilation units
1900 properly (FIXME). */
1901 if (current_subfile
== NULL
)
1902 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1904 nextdie
= thisdie
+ di
.die_length
;
1906 case TAG_global_subroutine
:
1907 case TAG_subroutine
:
1908 if (di
.has_at_low_pc
)
1910 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1913 case TAG_lexical_block
:
1914 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1916 case TAG_class_type
:
1917 case TAG_structure_type
:
1918 case TAG_union_type
:
1919 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1921 case TAG_enumeration_type
:
1922 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1924 case TAG_subroutine_type
:
1925 read_subroutine_type (&di
, thisdie
, nextdie
);
1927 case TAG_array_type
:
1928 dwarf_read_array_type (&di
);
1930 case TAG_pointer_type
:
1931 read_tag_pointer_type (&di
);
1933 case TAG_string_type
:
1934 read_tag_string_type (&di
);
1937 new_symbol (&di
, objfile
);
1949 decode_line_numbers -- decode a line number table fragment
1953 static void decode_line_numbers (char *tblscan, char *tblend,
1954 long length, long base, long line, long pc)
1958 Translate the DWARF line number information to gdb form.
1960 The ".line" section contains one or more line number tables, one for
1961 each ".line" section from the objects that were linked.
1963 The AT_stmt_list attribute for each TAG_source_file entry in the
1964 ".debug" section contains the offset into the ".line" section for the
1965 start of the table for that file.
1967 The table itself has the following structure:
1969 <table length><base address><source statement entry>
1970 4 bytes 4 bytes 10 bytes
1972 The table length is the total size of the table, including the 4 bytes
1973 for the length information.
1975 The base address is the address of the first instruction generated
1976 for the source file.
1978 Each source statement entry has the following structure:
1980 <line number><statement position><address delta>
1981 4 bytes 2 bytes 4 bytes
1983 The line number is relative to the start of the file, starting with
1986 The statement position either -1 (0xFFFF) or the number of characters
1987 from the beginning of the line to the beginning of the statement.
1989 The address delta is the difference between the base address and
1990 the address of the first instruction for the statement.
1992 Note that we must copy the bytes from the packed table to our local
1993 variables before attempting to use them, to avoid alignment problems
1994 on some machines, particularly RISC processors.
1998 Does gdb expect the line numbers to be sorted? They are now by
1999 chance/luck, but are not required to be. (FIXME)
2001 The line with number 0 is unused, gdb apparently can discover the
2002 span of the last line some other way. How? (FIXME)
2006 decode_line_numbers (char *linetable
)
2010 unsigned long length
;
2015 if (linetable
!= NULL
)
2017 tblscan
= tblend
= linetable
;
2018 length
= target_to_host (tblscan
, SIZEOF_LINETBL_LENGTH
, GET_UNSIGNED
,
2020 tblscan
+= SIZEOF_LINETBL_LENGTH
;
2022 base
= target_to_host (tblscan
, TARGET_FT_POINTER_SIZE (objfile
),
2023 GET_UNSIGNED
, current_objfile
);
2024 tblscan
+= TARGET_FT_POINTER_SIZE (objfile
);
2026 while (tblscan
< tblend
)
2028 line
= target_to_host (tblscan
, SIZEOF_LINETBL_LINENO
, GET_UNSIGNED
,
2030 tblscan
+= SIZEOF_LINETBL_LINENO
+ SIZEOF_LINETBL_STMT
;
2031 pc
= target_to_host (tblscan
, SIZEOF_LINETBL_DELTA
, GET_UNSIGNED
,
2033 tblscan
+= SIZEOF_LINETBL_DELTA
;
2037 record_line (current_subfile
, line
, pc
);
2047 locval -- compute the value of a location attribute
2051 static int locval (struct dieinfo *dip)
2055 Given pointer to a string of bytes that define a location, compute
2056 the location and return the value.
2057 A location description containing no atoms indicates that the
2058 object is optimized out. The optimized_out flag is set for those,
2059 the return value is meaningless.
2061 When computing values involving the current value of the frame pointer,
2062 the value zero is used, which results in a value relative to the frame
2063 pointer, rather than the absolute value. This is what GDB wants
2066 When the result is a register number, the isreg flag is set, otherwise
2067 it is cleared. This is a kludge until we figure out a better
2068 way to handle the problem. Gdb's design does not mesh well with the
2069 DWARF notion of a location computing interpreter, which is a shame
2070 because the flexibility goes unused.
2074 Note that stack[0] is unused except as a default error return.
2075 Note that stack overflow is not yet handled.
2079 locval (struct dieinfo
*dip
)
2081 unsigned short nbytes
;
2082 unsigned short locsize
;
2083 auto long stack
[64];
2090 loc
= dip
->at_location
;
2091 nbytes
= attribute_size (AT_location
);
2092 locsize
= target_to_host (loc
, nbytes
, GET_UNSIGNED
, current_objfile
);
2094 end
= loc
+ locsize
;
2099 dip
->optimized_out
= 1;
2100 loc_value_size
= TARGET_FT_LONG_SIZE (current_objfile
);
2103 dip
->optimized_out
= 0;
2104 loc_atom_code
= target_to_host (loc
, SIZEOF_LOC_ATOM_CODE
, GET_UNSIGNED
,
2106 loc
+= SIZEOF_LOC_ATOM_CODE
;
2107 switch (loc_atom_code
)
2114 /* push register (number) */
2116 = DWARF_REG_TO_REGNUM (target_to_host (loc
, loc_value_size
,
2119 loc
+= loc_value_size
;
2123 /* push value of register (number) */
2124 /* Actually, we compute the value as if register has 0, so the
2125 value ends up being the offset from that register. */
2127 dip
->basereg
= target_to_host (loc
, loc_value_size
, GET_UNSIGNED
,
2129 loc
+= loc_value_size
;
2130 stack
[++stacki
] = 0;
2133 /* push address (relocated address) */
2134 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
2135 GET_UNSIGNED
, current_objfile
);
2136 loc
+= loc_value_size
;
2139 /* push constant (number) FIXME: signed or unsigned! */
2140 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
2141 GET_SIGNED
, current_objfile
);
2142 loc
+= loc_value_size
;
2145 /* pop, deref and push 2 bytes (as a long) */
2146 complaint (&symfile_complaints
,
2147 "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%lx not handled",
2148 DIE_ID
, DIE_NAME
, stack
[stacki
]);
2150 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
2151 complaint (&symfile_complaints
,
2152 "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%lx not handled",
2153 DIE_ID
, DIE_NAME
, stack
[stacki
]);
2155 case OP_ADD
: /* pop top 2 items, add, push result */
2156 stack
[stacki
- 1] += stack
[stacki
];
2161 return (stack
[stacki
]);
2168 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
2172 static void read_ofile_symtab (struct partial_symtab *pst)
2176 When expanding a partial symbol table entry to a full symbol table
2177 entry, this is the function that gets called to read in the symbols
2178 for the compilation unit. A pointer to the newly constructed symtab,
2179 which is now the new first one on the objfile's symtab list, is
2180 stashed in the partial symbol table entry.
2184 read_ofile_symtab (struct partial_symtab
*pst
)
2186 struct cleanup
*back_to
;
2187 unsigned long lnsize
;
2190 char lnsizedata
[SIZEOF_LINETBL_LENGTH
];
2192 abfd
= pst
->objfile
->obfd
;
2193 current_objfile
= pst
->objfile
;
2195 /* Allocate a buffer for the entire chunk of DIE's for this compilation
2196 unit, seek to the location in the file, and read in all the DIE's. */
2199 dbsize
= DBLENGTH (pst
);
2200 dbbase
= xmalloc (dbsize
);
2201 dbroff
= DBROFF (pst
);
2202 foffset
= DBFOFF (pst
) + dbroff
;
2203 base_section_offsets
= pst
->section_offsets
;
2204 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
2205 if (bfd_seek (abfd
, foffset
, SEEK_SET
) ||
2206 (bfd_bread (dbbase
, dbsize
, abfd
) != dbsize
))
2209 error ("can't read DWARF data");
2211 back_to
= make_cleanup (xfree
, dbbase
);
2213 /* If there is a line number table associated with this compilation unit
2214 then read the size of this fragment in bytes, from the fragment itself.
2215 Allocate a buffer for the fragment and read it in for future
2221 if (bfd_seek (abfd
, LNFOFF (pst
), SEEK_SET
) ||
2222 (bfd_bread ((PTR
) lnsizedata
, sizeof (lnsizedata
), abfd
)
2223 != sizeof (lnsizedata
)))
2225 error ("can't read DWARF line number table size");
2227 lnsize
= target_to_host (lnsizedata
, SIZEOF_LINETBL_LENGTH
,
2228 GET_UNSIGNED
, pst
->objfile
);
2229 lnbase
= xmalloc (lnsize
);
2230 if (bfd_seek (abfd
, LNFOFF (pst
), SEEK_SET
) ||
2231 (bfd_bread (lnbase
, lnsize
, abfd
) != lnsize
))
2234 error ("can't read DWARF line numbers");
2236 make_cleanup (xfree
, lnbase
);
2239 process_dies (dbbase
, dbbase
+ dbsize
, pst
->objfile
);
2240 do_cleanups (back_to
);
2241 current_objfile
= NULL
;
2242 pst
->symtab
= pst
->objfile
->symtabs
;
2249 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
2253 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
2257 Called once for each partial symbol table entry that needs to be
2258 expanded into a full symbol table entry.
2263 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2266 struct cleanup
*old_chain
;
2272 warning ("psymtab for %s already read in. Shouldn't happen.",
2277 /* Read in all partial symtabs on which this one is dependent */
2278 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2280 if (!pst
->dependencies
[i
]->readin
)
2282 /* Inform about additional files that need to be read in. */
2285 fputs_filtered (" ", gdb_stdout
);
2287 fputs_filtered ("and ", gdb_stdout
);
2289 printf_filtered ("%s...",
2290 pst
->dependencies
[i
]->filename
);
2292 gdb_flush (gdb_stdout
); /* Flush output */
2294 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2297 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
2300 old_chain
= make_cleanup (really_free_pendings
, 0);
2301 read_ofile_symtab (pst
);
2304 printf_filtered ("%d DIE's, sorting...", diecount
);
2306 gdb_flush (gdb_stdout
);
2308 sort_symtab_syms (pst
->symtab
);
2309 do_cleanups (old_chain
);
2320 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2324 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2328 This is the DWARF support entry point for building a full symbol
2329 table entry from a partial symbol table entry. We are passed a
2330 pointer to the partial symbol table entry that needs to be expanded.
2335 dwarf_psymtab_to_symtab (struct partial_symtab
*pst
)
2342 warning ("psymtab for %s already read in. Shouldn't happen.",
2347 if (DBLENGTH (pst
) || pst
->number_of_dependencies
)
2349 /* Print the message now, before starting serious work, to avoid
2350 disconcerting pauses. */
2353 printf_filtered ("Reading in symbols for %s...",
2355 gdb_flush (gdb_stdout
);
2358 psymtab_to_symtab_1 (pst
);
2360 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2361 we need to do an equivalent or is this something peculiar to
2363 Match with global symbols. This only needs to be done once,
2364 after all of the symtabs and dependencies have been read in.
2366 scan_file_globals (pst
->objfile
);
2369 /* Finish up the verbose info message. */
2372 printf_filtered ("done.\n");
2373 gdb_flush (gdb_stdout
);
2384 add_enum_psymbol -- add enumeration members to partial symbol table
2388 Given pointer to a DIE that is known to be for an enumeration,
2389 extract the symbolic names of the enumeration members and add
2390 partial symbols for them.
2394 add_enum_psymbol (struct dieinfo
*dip
, struct objfile
*objfile
)
2398 unsigned short blocksz
;
2401 if ((scan
= dip
->at_element_list
) != NULL
)
2403 if (dip
->short_element_list
)
2405 nbytes
= attribute_size (AT_short_element_list
);
2409 nbytes
= attribute_size (AT_element_list
);
2411 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
2413 listend
= scan
+ blocksz
;
2414 while (scan
< listend
)
2416 scan
+= TARGET_FT_LONG_SIZE (objfile
);
2417 add_psymbol_to_list (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2418 &objfile
->static_psymbols
, 0, 0, cu_language
,
2420 scan
+= strlen (scan
) + 1;
2429 add_partial_symbol -- add symbol to partial symbol table
2433 Given a DIE, if it is one of the types that we want to
2434 add to a partial symbol table, finish filling in the die info
2435 and then add a partial symbol table entry for it.
2439 The caller must ensure that the DIE has a valid name attribute.
2443 add_partial_symbol (struct dieinfo
*dip
, struct objfile
*objfile
)
2445 switch (dip
->die_tag
)
2447 case TAG_global_subroutine
:
2448 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2449 VAR_NAMESPACE
, LOC_BLOCK
,
2450 &objfile
->global_psymbols
,
2451 0, dip
->at_low_pc
, cu_language
, objfile
);
2453 case TAG_global_variable
:
2454 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2455 VAR_NAMESPACE
, LOC_STATIC
,
2456 &objfile
->global_psymbols
,
2457 0, 0, cu_language
, objfile
);
2459 case TAG_subroutine
:
2460 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2461 VAR_NAMESPACE
, LOC_BLOCK
,
2462 &objfile
->static_psymbols
,
2463 0, dip
->at_low_pc
, cu_language
, objfile
);
2465 case TAG_local_variable
:
2466 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2467 VAR_NAMESPACE
, LOC_STATIC
,
2468 &objfile
->static_psymbols
,
2469 0, 0, cu_language
, objfile
);
2472 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2473 VAR_NAMESPACE
, LOC_TYPEDEF
,
2474 &objfile
->static_psymbols
,
2475 0, 0, cu_language
, objfile
);
2477 case TAG_class_type
:
2478 case TAG_structure_type
:
2479 case TAG_union_type
:
2480 case TAG_enumeration_type
:
2481 /* Do not add opaque aggregate definitions to the psymtab. */
2482 if (!dip
->has_at_byte_size
)
2484 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2485 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2486 &objfile
->static_psymbols
,
2487 0, 0, cu_language
, objfile
);
2488 if (cu_language
== language_cplus
)
2490 /* For C++, these implicitly act as typedefs as well. */
2491 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2492 VAR_NAMESPACE
, LOC_TYPEDEF
,
2493 &objfile
->static_psymbols
,
2494 0, 0, cu_language
, objfile
);
2504 scan_partial_symbols -- scan DIE's within a single compilation unit
2508 Process the DIE's within a single compilation unit, looking for
2509 interesting DIE's that contribute to the partial symbol table entry
2510 for this compilation unit.
2514 There are some DIE's that may appear both at file scope and within
2515 the scope of a function. We are only interested in the ones at file
2516 scope, and the only way to tell them apart is to keep track of the
2517 scope. For example, consider the test case:
2522 for which the relevant DWARF segment has the structure:
2525 0x23 global subrtn sibling 0x9b
2527 fund_type FT_integer
2532 0x23 local var sibling 0x97
2534 fund_type FT_integer
2535 location OP_BASEREG 0xe
2542 0x1d local var sibling 0xb8
2544 fund_type FT_integer
2545 location OP_ADDR 0x800025dc
2550 We want to include the symbol 'i' in the partial symbol table, but
2551 not the symbol 'j'. In essence, we want to skip all the dies within
2552 the scope of a TAG_global_subroutine DIE.
2554 Don't attempt to add anonymous structures or unions since they have
2555 no name. Anonymous enumerations however are processed, because we
2556 want to extract their member names (the check for a tag name is
2559 Also, for variables and subroutines, check that this is the place
2560 where the actual definition occurs, rather than just a reference
2568 scan_partial_symbols (char *thisdie
, char *enddie
, struct objfile
*objfile
)
2574 while (thisdie
< enddie
)
2576 basicdieinfo (&di
, thisdie
, objfile
);
2577 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2583 nextdie
= thisdie
+ di
.die_length
;
2584 /* To avoid getting complete die information for every die, we
2585 only do it (below) for the cases we are interested in. */
2588 case TAG_global_subroutine
:
2589 case TAG_subroutine
:
2590 completedieinfo (&di
, objfile
);
2591 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2593 add_partial_symbol (&di
, objfile
);
2594 /* If there is a sibling attribute, adjust the nextdie
2595 pointer to skip the entire scope of the subroutine.
2596 Apply some sanity checking to make sure we don't
2597 overrun or underrun the range of remaining DIE's */
2598 if (di
.at_sibling
!= 0)
2600 temp
= dbbase
+ di
.at_sibling
- dbroff
;
2601 if ((temp
< thisdie
) || (temp
>= enddie
))
2603 bad_die_ref_complaint (DIE_ID
, DIE_NAME
,
2613 case TAG_global_variable
:
2614 case TAG_local_variable
:
2615 completedieinfo (&di
, objfile
);
2616 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2618 add_partial_symbol (&di
, objfile
);
2622 case TAG_class_type
:
2623 case TAG_structure_type
:
2624 case TAG_union_type
:
2625 completedieinfo (&di
, objfile
);
2628 add_partial_symbol (&di
, objfile
);
2631 case TAG_enumeration_type
:
2632 completedieinfo (&di
, objfile
);
2635 add_partial_symbol (&di
, objfile
);
2637 add_enum_psymbol (&di
, objfile
);
2649 scan_compilation_units -- build a psymtab entry for each compilation
2653 This is the top level dwarf parsing routine for building partial
2656 It scans from the beginning of the DWARF table looking for the first
2657 TAG_compile_unit DIE, and then follows the sibling chain to locate
2658 each additional TAG_compile_unit DIE.
2660 For each TAG_compile_unit DIE it creates a partial symtab structure,
2661 calls a subordinate routine to collect all the compilation unit's
2662 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2663 new partial symtab structure into the partial symbol table. It also
2664 records the appropriate information in the partial symbol table entry
2665 to allow the chunk of DIE's and line number table for this compilation
2666 unit to be located and re-read later, to generate a complete symbol
2667 table entry for the compilation unit.
2669 Thus it effectively partitions up a chunk of DIE's for multiple
2670 compilation units into smaller DIE chunks and line number tables,
2671 and associates them with a partial symbol table entry.
2675 If any compilation unit has no line number table associated with
2676 it for some reason (a missing at_stmt_list attribute, rather than
2677 just one with a value of zero, which is valid) then we ensure that
2678 the recorded file offset is zero so that the routine which later
2679 reads line number table fragments knows that there is no fragment
2689 scan_compilation_units (char *thisdie
, char *enddie
, file_ptr dbfoff
,
2690 file_ptr lnoffset
, struct objfile
*objfile
)
2694 struct partial_symtab
*pst
;
2697 file_ptr curlnoffset
;
2699 while (thisdie
< enddie
)
2701 basicdieinfo (&di
, thisdie
, objfile
);
2702 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2706 else if (di
.die_tag
!= TAG_compile_unit
)
2708 nextdie
= thisdie
+ di
.die_length
;
2712 completedieinfo (&di
, objfile
);
2713 set_cu_language (&di
);
2714 if (di
.at_sibling
!= 0)
2716 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2720 nextdie
= thisdie
+ di
.die_length
;
2722 curoff
= thisdie
- dbbase
;
2723 culength
= nextdie
- thisdie
;
2724 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2726 /* First allocate a new partial symbol table structure */
2728 pst
= start_psymtab_common (objfile
, base_section_offsets
,
2729 di
.at_name
, di
.at_low_pc
,
2730 objfile
->global_psymbols
.next
,
2731 objfile
->static_psymbols
.next
);
2733 pst
->texthigh
= di
.at_high_pc
;
2734 pst
->read_symtab_private
= (char *)
2735 obstack_alloc (&objfile
->psymbol_obstack
,
2736 sizeof (struct dwfinfo
));
2737 DBFOFF (pst
) = dbfoff
;
2738 DBROFF (pst
) = curoff
;
2739 DBLENGTH (pst
) = culength
;
2740 LNFOFF (pst
) = curlnoffset
;
2741 pst
->read_symtab
= dwarf_psymtab_to_symtab
;
2743 /* Now look for partial symbols */
2745 scan_partial_symbols (thisdie
+ di
.die_length
, nextdie
, objfile
);
2747 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2748 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2749 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2750 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2751 sort_pst_symbols (pst
);
2752 /* If there is already a psymtab or symtab for a file of this name,
2753 remove it. (If there is a symtab, more drastic things also
2754 happen.) This happens in VxWorks. */
2755 free_named_symtabs (pst
->filename
);
2765 new_symbol -- make a symbol table entry for a new symbol
2769 static struct symbol *new_symbol (struct dieinfo *dip,
2770 struct objfile *objfile)
2774 Given a pointer to a DWARF information entry, figure out if we need
2775 to make a symbol table entry for it, and if so, create a new entry
2776 and return a pointer to it.
2779 static struct symbol
*
2780 new_symbol (struct dieinfo
*dip
, struct objfile
*objfile
)
2782 struct symbol
*sym
= NULL
;
2784 if (dip
->at_name
!= NULL
)
2786 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
2787 sizeof (struct symbol
));
2788 OBJSTAT (objfile
, n_syms
++);
2789 memset (sym
, 0, sizeof (struct symbol
));
2790 SYMBOL_NAME (sym
) = create_name (dip
->at_name
,
2791 &objfile
->symbol_obstack
);
2792 /* default assumptions */
2793 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2794 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2795 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2797 /* If this symbol is from a C++ compilation, then attempt to cache the
2798 demangled form for future reference. This is a typical time versus
2799 space tradeoff, that was decided in favor of time because it sped up
2800 C++ symbol lookups by a factor of about 20. */
2802 SYMBOL_LANGUAGE (sym
) = cu_language
;
2803 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
2804 switch (dip
->die_tag
)
2807 SYMBOL_VALUE_ADDRESS (sym
) = dip
->at_low_pc
;
2808 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2810 case TAG_global_subroutine
:
2811 case TAG_subroutine
:
2812 SYMBOL_VALUE_ADDRESS (sym
) = dip
->at_low_pc
;
2813 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2814 if (dip
->at_prototyped
)
2815 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
2816 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2817 if (dip
->die_tag
== TAG_global_subroutine
)
2819 add_symbol_to_list (sym
, &global_symbols
);
2823 add_symbol_to_list (sym
, list_in_scope
);
2826 case TAG_global_variable
:
2827 if (dip
->at_location
!= NULL
)
2829 SYMBOL_VALUE_ADDRESS (sym
) = locval (dip
);
2830 add_symbol_to_list (sym
, &global_symbols
);
2831 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2832 SYMBOL_VALUE (sym
) += baseaddr
;
2835 case TAG_local_variable
:
2836 if (dip
->at_location
!= NULL
)
2838 int loc
= locval (dip
);
2839 if (dip
->optimized_out
)
2841 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
2843 else if (dip
->isreg
)
2845 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2847 else if (dip
->offreg
)
2849 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
2850 SYMBOL_BASEREG (sym
) = dip
->basereg
;
2854 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2855 SYMBOL_VALUE (sym
) += baseaddr
;
2857 if (SYMBOL_CLASS (sym
) == LOC_STATIC
)
2859 /* LOC_STATIC address class MUST use SYMBOL_VALUE_ADDRESS,
2860 which may store to a bigger location than SYMBOL_VALUE. */
2861 SYMBOL_VALUE_ADDRESS (sym
) = loc
;
2865 SYMBOL_VALUE (sym
) = loc
;
2867 add_symbol_to_list (sym
, list_in_scope
);
2870 case TAG_formal_parameter
:
2871 if (dip
->at_location
!= NULL
)
2873 SYMBOL_VALUE (sym
) = locval (dip
);
2875 add_symbol_to_list (sym
, list_in_scope
);
2878 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2880 else if (dip
->offreg
)
2882 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
2883 SYMBOL_BASEREG (sym
) = dip
->basereg
;
2887 SYMBOL_CLASS (sym
) = LOC_ARG
;
2890 case TAG_unspecified_parameters
:
2891 /* From varargs functions; gdb doesn't seem to have any interest in
2892 this information, so just ignore it for now. (FIXME?) */
2894 case TAG_class_type
:
2895 case TAG_structure_type
:
2896 case TAG_union_type
:
2897 case TAG_enumeration_type
:
2898 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2899 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2900 add_symbol_to_list (sym
, list_in_scope
);
2903 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2904 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2905 add_symbol_to_list (sym
, list_in_scope
);
2908 /* Not a tag we recognize. Hopefully we aren't processing trash
2909 data, but since we must specifically ignore things we don't
2910 recognize, there is nothing else we should do at this point. */
2921 synthesize_typedef -- make a symbol table entry for a "fake" typedef
2925 static void synthesize_typedef (struct dieinfo *dip,
2926 struct objfile *objfile,
2931 Given a pointer to a DWARF information entry, synthesize a typedef
2932 for the name in the DIE, using the specified type.
2934 This is used for C++ class, structs, unions, and enumerations to
2935 set up the tag name as a type.
2940 synthesize_typedef (struct dieinfo
*dip
, struct objfile
*objfile
,
2943 struct symbol
*sym
= NULL
;
2945 if (dip
->at_name
!= NULL
)
2947 sym
= (struct symbol
*)
2948 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2949 OBJSTAT (objfile
, n_syms
++);
2950 memset (sym
, 0, sizeof (struct symbol
));
2951 SYMBOL_NAME (sym
) = create_name (dip
->at_name
,
2952 &objfile
->symbol_obstack
);
2953 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym
, cu_language
);
2954 SYMBOL_TYPE (sym
) = type
;
2955 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2956 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2957 add_symbol_to_list (sym
, list_in_scope
);
2965 decode_mod_fund_type -- decode a modified fundamental type
2969 static struct type *decode_mod_fund_type (char *typedata)
2973 Decode a block of data containing a modified fundamental
2974 type specification. TYPEDATA is a pointer to the block,
2975 which starts with a length containing the size of the rest
2976 of the block. At the end of the block is a fundmental type
2977 code value that gives the fundamental type. Everything
2978 in between are type modifiers.
2980 We simply compute the number of modifiers and call the general
2981 function decode_modified_type to do the actual work.
2984 static struct type
*
2985 decode_mod_fund_type (char *typedata
)
2987 struct type
*typep
= NULL
;
2988 unsigned short modcount
;
2991 /* Get the total size of the block, exclusive of the size itself */
2993 nbytes
= attribute_size (AT_mod_fund_type
);
2994 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
2997 /* Deduct the size of the fundamental type bytes at the end of the block. */
2999 modcount
-= attribute_size (AT_fund_type
);
3001 /* Now do the actual decoding */
3003 typep
= decode_modified_type (typedata
, modcount
, AT_mod_fund_type
);
3011 decode_mod_u_d_type -- decode a modified user defined type
3015 static struct type *decode_mod_u_d_type (char *typedata)
3019 Decode a block of data containing a modified user defined
3020 type specification. TYPEDATA is a pointer to the block,
3021 which consists of a two byte length, containing the size
3022 of the rest of the block. At the end of the block is a
3023 four byte value that gives a reference to a user defined type.
3024 Everything in between are type modifiers.
3026 We simply compute the number of modifiers and call the general
3027 function decode_modified_type to do the actual work.
3030 static struct type
*
3031 decode_mod_u_d_type (char *typedata
)
3033 struct type
*typep
= NULL
;
3034 unsigned short modcount
;
3037 /* Get the total size of the block, exclusive of the size itself */
3039 nbytes
= attribute_size (AT_mod_u_d_type
);
3040 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
3043 /* Deduct the size of the reference type bytes at the end of the block. */
3045 modcount
-= attribute_size (AT_user_def_type
);
3047 /* Now do the actual decoding */
3049 typep
= decode_modified_type (typedata
, modcount
, AT_mod_u_d_type
);
3057 decode_modified_type -- decode modified user or fundamental type
3061 static struct type *decode_modified_type (char *modifiers,
3062 unsigned short modcount, int mtype)
3066 Decode a modified type, either a modified fundamental type or
3067 a modified user defined type. MODIFIERS is a pointer to the
3068 block of bytes that define MODCOUNT modifiers. Immediately
3069 following the last modifier is a short containing the fundamental
3070 type or a long containing the reference to the user defined
3071 type. Which one is determined by MTYPE, which is either
3072 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
3073 type we are generating.
3075 We call ourself recursively to generate each modified type,`
3076 until MODCOUNT reaches zero, at which point we have consumed
3077 all the modifiers and generate either the fundamental type or
3078 user defined type. When the recursion unwinds, each modifier
3079 is applied in turn to generate the full modified type.
3083 If we find a modifier that we don't recognize, and it is not one
3084 of those reserved for application specific use, then we issue a
3085 warning and simply ignore the modifier.
3089 We currently ignore MOD_const and MOD_volatile. (FIXME)
3093 static struct type
*
3094 decode_modified_type (char *modifiers
, unsigned int modcount
, int mtype
)
3096 struct type
*typep
= NULL
;
3097 unsigned short fundtype
;
3106 case AT_mod_fund_type
:
3107 nbytes
= attribute_size (AT_fund_type
);
3108 fundtype
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
3110 typep
= decode_fund_type (fundtype
);
3112 case AT_mod_u_d_type
:
3113 nbytes
= attribute_size (AT_user_def_type
);
3114 die_ref
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
3116 if ((typep
= lookup_utype (die_ref
)) == NULL
)
3118 typep
= alloc_utype (die_ref
, NULL
);
3122 complaint (&symfile_complaints
,
3123 "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)",
3124 DIE_ID
, DIE_NAME
, mtype
);
3125 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
3131 modifier
= *modifiers
++;
3132 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
3135 case MOD_pointer_to
:
3136 typep
= lookup_pointer_type (typep
);
3138 case MOD_reference_to
:
3139 typep
= lookup_reference_type (typep
);
3142 complaint (&symfile_complaints
,
3143 "DIE @ 0x%x \"%s\", type modifier 'const' ignored", DIE_ID
,
3144 DIE_NAME
); /* FIXME */
3147 complaint (&symfile_complaints
,
3148 "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored",
3149 DIE_ID
, DIE_NAME
); /* FIXME */
3152 if (!(MOD_lo_user
<= (unsigned char) modifier
3153 && (unsigned char) modifier
<= MOD_hi_user
))
3155 complaint (&symfile_complaints
,
3156 "DIE @ 0x%x \"%s\", unknown type modifier %u", DIE_ID
,
3157 DIE_NAME
, modifier
);
3169 decode_fund_type -- translate basic DWARF type to gdb base type
3173 Given an integer that is one of the fundamental DWARF types,
3174 translate it to one of the basic internal gdb types and return
3175 a pointer to the appropriate gdb type (a "struct type *").
3179 For robustness, if we are asked to translate a fundamental
3180 type that we are unprepared to deal with, we return int so
3181 callers can always depend upon a valid type being returned,
3182 and so gdb may at least do something reasonable by default.
3183 If the type is not in the range of those types defined as
3184 application specific types, we also issue a warning.
3187 static struct type
*
3188 decode_fund_type (unsigned int fundtype
)
3190 struct type
*typep
= NULL
;
3196 typep
= dwarf_fundamental_type (current_objfile
, FT_VOID
);
3199 case FT_boolean
: /* Was FT_set in AT&T version */
3200 typep
= dwarf_fundamental_type (current_objfile
, FT_BOOLEAN
);
3203 case FT_pointer
: /* (void *) */
3204 typep
= dwarf_fundamental_type (current_objfile
, FT_VOID
);
3205 typep
= lookup_pointer_type (typep
);
3209 typep
= dwarf_fundamental_type (current_objfile
, FT_CHAR
);
3212 case FT_signed_char
:
3213 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
3216 case FT_unsigned_char
:
3217 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
3221 typep
= dwarf_fundamental_type (current_objfile
, FT_SHORT
);
3224 case FT_signed_short
:
3225 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
3228 case FT_unsigned_short
:
3229 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
3233 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
3236 case FT_signed_integer
:
3237 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
3240 case FT_unsigned_integer
:
3241 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
3245 typep
= dwarf_fundamental_type (current_objfile
, FT_LONG
);
3248 case FT_signed_long
:
3249 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
3252 case FT_unsigned_long
:
3253 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
3257 typep
= dwarf_fundamental_type (current_objfile
, FT_LONG_LONG
);
3260 case FT_signed_long_long
:
3261 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
3264 case FT_unsigned_long_long
:
3265 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
3269 typep
= dwarf_fundamental_type (current_objfile
, FT_FLOAT
);
3272 case FT_dbl_prec_float
:
3273 typep
= dwarf_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
3276 case FT_ext_prec_float
:
3277 typep
= dwarf_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
3281 typep
= dwarf_fundamental_type (current_objfile
, FT_COMPLEX
);
3284 case FT_dbl_prec_complex
:
3285 typep
= dwarf_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
3288 case FT_ext_prec_complex
:
3289 typep
= dwarf_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
3296 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
3297 if (!(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
3299 complaint (&symfile_complaints
,
3300 "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x",
3301 DIE_ID
, DIE_NAME
, fundtype
);
3312 create_name -- allocate a fresh copy of a string on an obstack
3316 Given a pointer to a string and a pointer to an obstack, allocates
3317 a fresh copy of the string on the specified obstack.
3322 create_name (char *name
, struct obstack
*obstackp
)
3327 length
= strlen (name
) + 1;
3328 newname
= (char *) obstack_alloc (obstackp
, length
);
3329 strcpy (newname
, name
);
3337 basicdieinfo -- extract the minimal die info from raw die data
3341 void basicdieinfo (char *diep, struct dieinfo *dip,
3342 struct objfile *objfile)
3346 Given a pointer to raw DIE data, and a pointer to an instance of a
3347 die info structure, this function extracts the basic information
3348 from the DIE data required to continue processing this DIE, along
3349 with some bookkeeping information about the DIE.
3351 The information we absolutely must have includes the DIE tag,
3352 and the DIE length. If we need the sibling reference, then we
3353 will have to call completedieinfo() to process all the remaining
3356 Note that since there is no guarantee that the data is properly
3357 aligned in memory for the type of access required (indirection
3358 through anything other than a char pointer), and there is no
3359 guarantee that it is in the same byte order as the gdb host,
3360 we call a function which deals with both alignment and byte
3361 swapping issues. Possibly inefficient, but quite portable.
3363 We also take care of some other basic things at this point, such
3364 as ensuring that the instance of the die info structure starts
3365 out completely zero'd and that curdie is initialized for use
3366 in error reporting if we have a problem with the current die.
3370 All DIE's must have at least a valid length, thus the minimum
3371 DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the
3372 DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
3373 are forced to be TAG_padding DIES.
3375 Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
3376 that if a padding DIE is used for alignment and the amount needed is
3377 less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
3378 enough to align to the next alignment boundry.
3380 We do some basic sanity checking here, such as verifying that the
3381 length of the die would not cause it to overrun the recorded end of
3382 the buffer holding the DIE info. If we find a DIE that is either
3383 too small or too large, we force it's length to zero which should
3384 cause the caller to take appropriate action.
3388 basicdieinfo (struct dieinfo
*dip
, char *diep
, struct objfile
*objfile
)
3391 memset (dip
, 0, sizeof (struct dieinfo
));
3393 dip
->die_ref
= dbroff
+ (diep
- dbbase
);
3394 dip
->die_length
= target_to_host (diep
, SIZEOF_DIE_LENGTH
, GET_UNSIGNED
,
3396 if ((dip
->die_length
< SIZEOF_DIE_LENGTH
) ||
3397 ((diep
+ dip
->die_length
) > (dbbase
+ dbsize
)))
3399 complaint (&symfile_complaints
,
3400 "DIE @ 0x%x \"%s\", malformed DIE, bad length (%ld bytes)",
3401 DIE_ID
, DIE_NAME
, dip
->die_length
);
3402 dip
->die_length
= 0;
3404 else if (dip
->die_length
< (SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
))
3406 dip
->die_tag
= TAG_padding
;
3410 diep
+= SIZEOF_DIE_LENGTH
;
3411 dip
->die_tag
= target_to_host (diep
, SIZEOF_DIE_TAG
, GET_UNSIGNED
,
3420 completedieinfo -- finish reading the information for a given DIE
3424 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3428 Given a pointer to an already partially initialized die info structure,
3429 scan the raw DIE data and finish filling in the die info structure
3430 from the various attributes found.
3432 Note that since there is no guarantee that the data is properly
3433 aligned in memory for the type of access required (indirection
3434 through anything other than a char pointer), and there is no
3435 guarantee that it is in the same byte order as the gdb host,
3436 we call a function which deals with both alignment and byte
3437 swapping issues. Possibly inefficient, but quite portable.
3441 Each time we are called, we increment the diecount variable, which
3442 keeps an approximate count of the number of dies processed for
3443 each compilation unit. This information is presented to the user
3444 if the info_verbose flag is set.
3449 completedieinfo (struct dieinfo
*dip
, struct objfile
*objfile
)
3451 char *diep
; /* Current pointer into raw DIE data */
3452 char *end
; /* Terminate DIE scan here */
3453 unsigned short attr
; /* Current attribute being scanned */
3454 unsigned short form
; /* Form of the attribute */
3455 int nbytes
; /* Size of next field to read */
3459 end
= diep
+ dip
->die_length
;
3460 diep
+= SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
;
3463 attr
= target_to_host (diep
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
, objfile
);
3464 diep
+= SIZEOF_ATTRIBUTE
;
3465 if ((nbytes
= attribute_size (attr
)) == -1)
3467 complaint (&symfile_complaints
,
3468 "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes",
3476 dip
->at_fund_type
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3480 dip
->at_ordering
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3484 dip
->at_bit_offset
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3488 dip
->at_sibling
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3492 dip
->at_stmt_list
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3494 dip
->has_at_stmt_list
= 1;
3497 dip
->at_low_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3499 dip
->at_low_pc
+= baseaddr
;
3500 dip
->has_at_low_pc
= 1;
3503 dip
->at_high_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3505 dip
->at_high_pc
+= baseaddr
;
3508 dip
->at_language
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3511 case AT_user_def_type
:
3512 dip
->at_user_def_type
= target_to_host (diep
, nbytes
,
3513 GET_UNSIGNED
, objfile
);
3516 dip
->at_byte_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3518 dip
->has_at_byte_size
= 1;
3521 dip
->at_bit_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3525 dip
->at_member
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3529 dip
->at_discr
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3533 dip
->at_location
= diep
;
3535 case AT_mod_fund_type
:
3536 dip
->at_mod_fund_type
= diep
;
3538 case AT_subscr_data
:
3539 dip
->at_subscr_data
= diep
;
3541 case AT_mod_u_d_type
:
3542 dip
->at_mod_u_d_type
= diep
;
3544 case AT_element_list
:
3545 dip
->at_element_list
= diep
;
3546 dip
->short_element_list
= 0;
3548 case AT_short_element_list
:
3549 dip
->at_element_list
= diep
;
3550 dip
->short_element_list
= 1;
3552 case AT_discr_value
:
3553 dip
->at_discr_value
= diep
;
3555 case AT_string_length
:
3556 dip
->at_string_length
= diep
;
3559 dip
->at_name
= diep
;
3562 /* For now, ignore any "hostname:" portion, since gdb doesn't
3563 know how to deal with it. (FIXME). */
3564 dip
->at_comp_dir
= strrchr (diep
, ':');
3565 if (dip
->at_comp_dir
!= NULL
)
3571 dip
->at_comp_dir
= diep
;
3575 dip
->at_producer
= diep
;
3577 case AT_start_scope
:
3578 dip
->at_start_scope
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3581 case AT_stride_size
:
3582 dip
->at_stride_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3586 dip
->at_src_info
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3590 dip
->at_prototyped
= diep
;
3593 /* Found an attribute that we are unprepared to handle. However
3594 it is specifically one of the design goals of DWARF that
3595 consumers should ignore unknown attributes. As long as the
3596 form is one that we recognize (so we know how to skip it),
3597 we can just ignore the unknown attribute. */
3600 form
= FORM_FROM_ATTR (attr
);
3614 diep
+= TARGET_FT_POINTER_SIZE (objfile
);
3617 diep
+= 2 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3620 diep
+= 4 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3623 diep
+= strlen (diep
) + 1;
3626 unknown_attribute_form_complaint (DIE_ID
, DIE_NAME
, form
);
3637 target_to_host -- swap in target data to host
3641 target_to_host (char *from, int nbytes, int signextend,
3642 struct objfile *objfile)
3646 Given pointer to data in target format in FROM, a byte count for
3647 the size of the data in NBYTES, a flag indicating whether or not
3648 the data is signed in SIGNEXTEND, and a pointer to the current
3649 objfile in OBJFILE, convert the data to host format and return
3650 the converted value.
3654 FIXME: If we read data that is known to be signed, and expect to
3655 use it as signed data, then we need to explicitly sign extend the
3656 result until the bfd library is able to do this for us.
3658 FIXME: Would a 32 bit target ever need an 8 byte result?
3663 target_to_host (char *from
, int nbytes
, int signextend
, /* FIXME: Unused */
3664 struct objfile
*objfile
)
3671 rtnval
= bfd_get_64 (objfile
->obfd
, (bfd_byte
*) from
);
3674 rtnval
= bfd_get_32 (objfile
->obfd
, (bfd_byte
*) from
);
3677 rtnval
= bfd_get_16 (objfile
->obfd
, (bfd_byte
*) from
);
3680 rtnval
= bfd_get_8 (objfile
->obfd
, (bfd_byte
*) from
);
3683 complaint (&symfile_complaints
,
3684 "DIE @ 0x%x \"%s\", no bfd support for %d byte data object",
3685 DIE_ID
, DIE_NAME
, nbytes
);
3696 attribute_size -- compute size of data for a DWARF attribute
3700 static int attribute_size (unsigned int attr)
3704 Given a DWARF attribute in ATTR, compute the size of the first
3705 piece of data associated with this attribute and return that
3708 Returns -1 for unrecognized attributes.
3713 attribute_size (unsigned int attr
)
3715 int nbytes
; /* Size of next data for this attribute */
3716 unsigned short form
; /* Form of the attribute */
3718 form
= FORM_FROM_ATTR (attr
);
3721 case FORM_STRING
: /* A variable length field is next */
3724 case FORM_DATA2
: /* Next 2 byte field is the data itself */
3725 case FORM_BLOCK2
: /* Next 2 byte field is a block length */
3728 case FORM_DATA4
: /* Next 4 byte field is the data itself */
3729 case FORM_BLOCK4
: /* Next 4 byte field is a block length */
3730 case FORM_REF
: /* Next 4 byte field is a DIE offset */
3733 case FORM_DATA8
: /* Next 8 byte field is the data itself */
3736 case FORM_ADDR
: /* Next field size is target sizeof(void *) */
3737 nbytes
= TARGET_FT_POINTER_SIZE (objfile
);
3740 unknown_attribute_form_complaint (DIE_ID
, DIE_NAME
, form
);