1 /* DWARF debugging format support for GDB.
3 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 Written by Fred Fish at Cygnus Support. Portions based on dbxread.c,
7 mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 FIXME: Do we need to generate dependencies in partial symtabs?
28 (Perhaps we don't need to).
30 FIXME: Resolve minor differences between what information we put in the
31 partial symbol table and what dbxread puts in. For example, we don't yet
32 put enum constants there. And dbxread seems to invent a lot of typedefs
33 we never see. Use the new printpsym command to see the partial symbol table
36 FIXME: Figure out a better way to tell gdb about the name of the function
37 contain the user's entry point (I.E. main())
39 FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
40 other things to work on, if you get bored. :-)
49 #include "elf/dwarf.h"
52 #include "expression.h" /* Needed for enum exp_opcode in language.h, sigh... */
54 #include "complaints.h"
57 #include "gdb_string.h"
59 /* Some macros to provide DIE info for complaints. */
61 #define DIE_ID (curdie!=NULL ? curdie->die_ref : 0)
62 #define DIE_NAME (curdie!=NULL && curdie->at_name!=NULL) ? curdie->at_name : ""
64 /* Complaints that can be issued during DWARF debug info reading. */
67 bad_die_ref_complaint (int arg1
, const char *arg2
, int arg3
)
69 complaint (&symfile_complaints
,
70 "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit",
75 unknown_attribute_form_complaint (int arg1
, const char *arg2
, int arg3
)
77 complaint (&symfile_complaints
,
78 "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", arg1
, arg2
,
83 dup_user_type_definition_complaint (int arg1
, const char *arg2
)
85 complaint (&symfile_complaints
,
86 "DIE @ 0x%x \"%s\", internal error: duplicate user type definition",
91 bad_array_element_type_complaint (int arg1
, const char *arg2
, int arg3
)
93 complaint (&symfile_complaints
,
94 "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", arg1
,
98 typedef unsigned int DIE_REF
; /* Reference to a DIE */
101 #define GCC_PRODUCER "GNU C "
104 #ifndef GPLUS_PRODUCER
105 #define GPLUS_PRODUCER "GNU C++ "
109 #define LCC_PRODUCER "NCR C/C++"
112 /* Flags to target_to_host() that tell whether or not the data object is
113 expected to be signed. Used, for example, when fetching a signed
114 integer in the target environment which is used as a signed integer
115 in the host environment, and the two environments have different sized
116 ints. In this case, *somebody* has to sign extend the smaller sized
119 #define GET_UNSIGNED 0 /* No sign extension required */
120 #define GET_SIGNED 1 /* Sign extension required */
122 /* Defines for things which are specified in the document "DWARF Debugging
123 Information Format" published by UNIX International, Programming Languages
124 SIG. These defines are based on revision 1.0.0, Jan 20, 1992. */
126 #define SIZEOF_DIE_LENGTH 4
127 #define SIZEOF_DIE_TAG 2
128 #define SIZEOF_ATTRIBUTE 2
129 #define SIZEOF_FORMAT_SPECIFIER 1
130 #define SIZEOF_FMT_FT 2
131 #define SIZEOF_LINETBL_LENGTH 4
132 #define SIZEOF_LINETBL_LINENO 4
133 #define SIZEOF_LINETBL_STMT 2
134 #define SIZEOF_LINETBL_DELTA 4
135 #define SIZEOF_LOC_ATOM_CODE 1
137 #define FORM_FROM_ATTR(attr) ((attr) & 0xF) /* Implicitly specified */
139 /* Macros that return the sizes of various types of data in the target
142 FIXME: Currently these are just compile time constants (as they are in
143 other parts of gdb as well). They need to be able to get the right size
144 either from the bfd or possibly from the DWARF info. It would be nice if
145 the DWARF producer inserted DIES that describe the fundamental types in
146 the target environment into the DWARF info, similar to the way dbx stabs
147 producers produce information about their fundamental types. */
149 #define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
150 #define TARGET_FT_LONG_SIZE(objfile) (TARGET_LONG_BIT / TARGET_CHAR_BIT)
152 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
153 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
154 However, the Issue 2 DWARF specification from AT&T defines it as
155 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
156 For backwards compatibility with the AT&T compiler produced executables
157 we define AT_short_element_list for this variant. */
159 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
161 /* The DWARF debugging information consists of two major pieces,
162 one is a block of DWARF Information Entries (DIE's) and the other
163 is a line number table. The "struct dieinfo" structure contains
164 the information for a single DIE, the one currently being processed.
166 In order to make it easier to randomly access the attribute fields
167 of the current DIE, which are specifically unordered within the DIE,
168 each DIE is scanned and an instance of the "struct dieinfo"
169 structure is initialized.
171 Initialization is done in two levels. The first, done by basicdieinfo(),
172 just initializes those fields that are vital to deciding whether or not
173 to use this DIE, how to skip past it, etc. The second, done by the
174 function completedieinfo(), fills in the rest of the information.
176 Attributes which have block forms are not interpreted at the time
177 the DIE is scanned, instead we just save pointers to the start
178 of their value fields.
180 Some fields have a flag <name>_p that is set when the value of the
181 field is valid (I.E. we found a matching attribute in the DIE). Since
182 we may want to test for the presence of some attributes in the DIE,
183 such as AT_low_pc, without restricting the values of the field,
184 we need someway to note that we found such an attribute.
192 char *die
; /* Pointer to the raw DIE data */
193 unsigned long die_length
; /* Length of the raw DIE data */
194 DIE_REF die_ref
; /* Offset of this DIE */
195 unsigned short die_tag
; /* Tag for this DIE */
196 unsigned long at_padding
;
197 unsigned long at_sibling
;
200 unsigned short at_fund_type
;
201 BLOCK
*at_mod_fund_type
;
202 unsigned long at_user_def_type
;
203 BLOCK
*at_mod_u_d_type
;
204 unsigned short at_ordering
;
205 BLOCK
*at_subscr_data
;
206 unsigned long at_byte_size
;
207 unsigned short at_bit_offset
;
208 unsigned long at_bit_size
;
209 BLOCK
*at_element_list
;
210 unsigned long at_stmt_list
;
212 CORE_ADDR at_high_pc
;
213 unsigned long at_language
;
214 unsigned long at_member
;
215 unsigned long at_discr
;
216 BLOCK
*at_discr_value
;
217 BLOCK
*at_string_length
;
220 unsigned long at_start_scope
;
221 unsigned long at_stride_size
;
222 unsigned long at_src_info
;
224 unsigned int has_at_low_pc
:1;
225 unsigned int has_at_stmt_list
:1;
226 unsigned int has_at_byte_size
:1;
227 unsigned int short_element_list
:1;
229 /* Kludge to identify register variables */
233 /* Kludge to identify optimized out variables */
235 unsigned int optimized_out
;
237 /* Kludge to identify basereg references.
238 Nonzero if we have an offset relative to a basereg. */
242 /* Kludge to identify which base register is it relative to. */
244 unsigned int basereg
;
247 static int diecount
; /* Approximate count of dies for compilation unit */
248 static struct dieinfo
*curdie
; /* For warnings and such */
250 static char *dbbase
; /* Base pointer to dwarf info */
251 static int dbsize
; /* Size of dwarf info in bytes */
252 static int dbroff
; /* Relative offset from start of .debug section */
253 static char *lnbase
; /* Base pointer to line section */
255 /* This value is added to each symbol value. FIXME: Generalize to
256 the section_offsets structure used by dbxread (once this is done,
257 pass the appropriate section number to end_symtab). */
258 static CORE_ADDR baseaddr
; /* Add to each symbol value */
260 /* The section offsets used in the current psymtab or symtab. FIXME,
261 only used to pass one value (baseaddr) at the moment. */
262 static struct section_offsets
*base_section_offsets
;
264 /* We put a pointer to this structure in the read_symtab_private field
269 /* Always the absolute file offset to the start of the ".debug"
270 section for the file containing the DIE's being accessed. */
272 /* Relative offset from the start of the ".debug" section to the
273 first DIE to be accessed. When building the partial symbol
274 table, this value will be zero since we are accessing the
275 entire ".debug" section. When expanding a partial symbol
276 table entry, this value will be the offset to the first
277 DIE for the compilation unit containing the symbol that
278 triggers the expansion. */
280 /* The size of the chunk of DIE's being examined, in bytes. */
282 /* The absolute file offset to the line table fragment. Ignored
283 when building partial symbol tables, but used when expanding
284 them, and contains the absolute file offset to the fragment
285 of the ".line" section containing the line numbers for the
286 current compilation unit. */
290 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
291 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
292 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
293 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
295 /* The generic symbol table building routines have separate lists for
296 file scope symbols and all all other scopes (local scopes). So
297 we need to select the right one to pass to add_symbol_to_list().
298 We do it by keeping a pointer to the correct list in list_in_scope.
300 FIXME: The original dwarf code just treated the file scope as the first
301 local scope, and all other local scopes as nested local scopes, and worked
302 fine. Check to see if we really need to distinguish these in buildsym.c */
304 struct pending
**list_in_scope
= &file_symbols
;
306 /* DIES which have user defined types or modified user defined types refer to
307 other DIES for the type information. Thus we need to associate the offset
308 of a DIE for a user defined type with a pointer to the type information.
310 Originally this was done using a simple but expensive algorithm, with an
311 array of unsorted structures, each containing an offset/type-pointer pair.
312 This array was scanned linearly each time a lookup was done. The result
313 was that gdb was spending over half it's startup time munging through this
314 array of pointers looking for a structure that had the right offset member.
316 The second attempt used the same array of structures, but the array was
317 sorted using qsort each time a new offset/type was recorded, and a binary
318 search was used to find the type pointer for a given DIE offset. This was
319 even slower, due to the overhead of sorting the array each time a new
320 offset/type pair was entered.
322 The third attempt uses a fixed size array of type pointers, indexed by a
323 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
324 we can divide any DIE offset by 4 to obtain a unique index into this fixed
325 size array. Since each element is a 4 byte pointer, it takes exactly as
326 much memory to hold this array as to hold the DWARF info for a given
327 compilation unit. But it gets freed as soon as we are done with it.
328 This has worked well in practice, as a reasonable tradeoff between memory
329 consumption and speed, without having to resort to much more complicated
332 static struct type
**utypes
; /* Pointer to array of user type pointers */
333 static int numutypes
; /* Max number of user type pointers */
335 /* Maintain an array of referenced fundamental types for the current
336 compilation unit being read. For DWARF version 1, we have to construct
337 the fundamental types on the fly, since no information about the
338 fundamental types is supplied. Each such fundamental type is created by
339 calling a language dependent routine to create the type, and then a
340 pointer to that type is then placed in the array at the index specified
341 by it's FT_<TYPENAME> value. The array has a fixed size set by the
342 FT_NUM_MEMBERS compile time constant, which is the number of predefined
343 fundamental types gdb knows how to construct. */
345 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
347 /* Record the language for the compilation unit which is currently being
348 processed. We know it once we have seen the TAG_compile_unit DIE,
349 and we need it while processing the DIE's for that compilation unit.
350 It is eventually saved in the symtab structure, but we don't finalize
351 the symtab struct until we have processed all the DIE's for the
352 compilation unit. We also need to get and save a pointer to the
353 language struct for this language, so we can call the language
354 dependent routines for doing things such as creating fundamental
357 static enum language cu_language
;
358 static const struct language_defn
*cu_language_defn
;
360 /* Forward declarations of static functions so we don't have to worry
361 about ordering within this file. */
363 static void free_utypes (void *);
365 static int attribute_size (unsigned int);
367 static CORE_ADDR
target_to_host (char *, int, int, struct objfile
*);
369 static void add_enum_psymbol (struct dieinfo
*, struct objfile
*);
371 static void handle_producer (char *);
373 static void read_file_scope (struct dieinfo
*, char *, char *,
376 static void read_func_scope (struct dieinfo
*, char *, char *,
379 static void read_lexical_block_scope (struct dieinfo
*, char *, char *,
382 static void scan_partial_symbols (char *, char *, struct objfile
*);
384 static void scan_compilation_units (char *, char *, file_ptr
, file_ptr
,
387 static void add_partial_symbol (struct dieinfo
*, struct objfile
*);
389 static void basicdieinfo (struct dieinfo
*, char *, struct objfile
*);
391 static void completedieinfo (struct dieinfo
*, struct objfile
*);
393 static void dwarf_psymtab_to_symtab (struct partial_symtab
*);
395 static void psymtab_to_symtab_1 (struct partial_symtab
*);
397 static void read_ofile_symtab (struct partial_symtab
*);
399 static void process_dies (char *, char *, struct objfile
*);
401 static void read_structure_scope (struct dieinfo
*, char *, char *,
404 static struct type
*decode_array_element_type (char *);
406 static struct type
*decode_subscript_data_item (char *, char *);
408 static void dwarf_read_array_type (struct dieinfo
*);
410 static void read_tag_pointer_type (struct dieinfo
*dip
);
412 static void read_tag_string_type (struct dieinfo
*dip
);
414 static void read_subroutine_type (struct dieinfo
*, char *, char *);
416 static void read_enumeration (struct dieinfo
*, char *, char *,
419 static struct type
*struct_type (struct dieinfo
*, char *, char *,
422 static struct type
*enum_type (struct dieinfo
*, struct objfile
*);
424 static void decode_line_numbers (char *);
426 static struct type
*decode_die_type (struct dieinfo
*);
428 static struct type
*decode_mod_fund_type (char *);
430 static struct type
*decode_mod_u_d_type (char *);
432 static struct type
*decode_modified_type (char *, unsigned int, int);
434 static struct type
*decode_fund_type (unsigned int);
436 static char *create_name (char *, struct obstack
*);
438 static struct type
*lookup_utype (DIE_REF
);
440 static struct type
*alloc_utype (DIE_REF
, struct type
*);
442 static struct symbol
*new_symbol (struct dieinfo
*, struct objfile
*);
444 static void synthesize_typedef (struct dieinfo
*, struct objfile
*,
447 static int locval (struct dieinfo
*);
449 static void set_cu_language (struct dieinfo
*);
451 static struct type
*dwarf_fundamental_type (struct objfile
*, int);
458 dwarf_fundamental_type -- lookup or create a fundamental type
463 dwarf_fundamental_type (struct objfile *objfile, int typeid)
467 DWARF version 1 doesn't supply any fundamental type information,
468 so gdb has to construct such types. It has a fixed number of
469 fundamental types that it knows how to construct, which is the
470 union of all types that it knows how to construct for all languages
471 that it knows about. These are enumerated in gdbtypes.h.
473 As an example, assume we find a DIE that references a DWARF
474 fundamental type of FT_integer. We first look in the ftypes
475 array to see if we already have such a type, indexed by the
476 gdb internal value of FT_INTEGER. If so, we simply return a
477 pointer to that type. If not, then we ask an appropriate
478 language dependent routine to create a type FT_INTEGER, using
479 defaults reasonable for the current target machine, and install
480 that type in ftypes for future reference.
484 Pointer to a fundamental type.
489 dwarf_fundamental_type (struct objfile
*objfile
, int typeid)
491 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
493 error ("internal error - invalid fundamental type id %d", typeid);
496 /* Look for this particular type in the fundamental type vector. If one is
497 not found, create and install one appropriate for the current language
498 and the current target machine. */
500 if (ftypes
[typeid] == NULL
)
502 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
505 return (ftypes
[typeid]);
512 set_cu_language -- set local copy of language for compilation unit
517 set_cu_language (struct dieinfo *dip)
521 Decode the language attribute for a compilation unit DIE and
522 remember what the language was. We use this at various times
523 when processing DIE's for a given compilation unit.
532 set_cu_language (struct dieinfo
*dip
)
534 switch (dip
->at_language
)
538 cu_language
= language_c
;
540 case LANG_C_PLUS_PLUS
:
541 cu_language
= language_cplus
;
544 cu_language
= language_m2
;
548 cu_language
= language_fortran
;
554 /* We don't know anything special about these yet. */
555 cu_language
= language_unknown
;
558 /* If no at_language, try to deduce one from the filename */
559 cu_language
= deduce_language_from_filename (dip
->at_name
);
562 cu_language_defn
= language_def (cu_language
);
569 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
573 void dwarf_build_psymtabs (struct objfile *objfile,
574 int mainline, file_ptr dbfoff, unsigned int dbfsize,
575 file_ptr lnoffset, unsigned int lnsize)
579 This function is called upon to build partial symtabs from files
580 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
582 It is passed a bfd* containing the DIES
583 and line number information, the corresponding filename for that
584 file, a base address for relocating the symbols, a flag indicating
585 whether or not this debugging information is from a "main symbol
586 table" rather than a shared library or dynamically linked file,
587 and file offset/size pairs for the DIE information and line number
597 dwarf_build_psymtabs (struct objfile
*objfile
, int mainline
, file_ptr dbfoff
,
598 unsigned int dbfsize
, file_ptr lnoffset
,
601 bfd
*abfd
= objfile
->obfd
;
602 struct cleanup
*back_to
;
604 current_objfile
= objfile
;
606 dbbase
= xmalloc (dbsize
);
608 if ((bfd_seek (abfd
, dbfoff
, SEEK_SET
) != 0) ||
609 (bfd_bread (dbbase
, dbsize
, abfd
) != dbsize
))
612 error ("can't read DWARF data from '%s'", bfd_get_filename (abfd
));
614 back_to
= make_cleanup (xfree
, dbbase
);
616 /* If we are reinitializing, or if we have never loaded syms yet, init.
617 Since we have no idea how many DIES we are looking at, we just guess
618 some arbitrary value. */
621 || (objfile
->global_psymbols
.size
== 0
622 && objfile
->static_psymbols
.size
== 0))
624 init_psymbol_list (objfile
, 1024);
627 /* Save the relocation factor where everybody can see it. */
629 base_section_offsets
= objfile
->section_offsets
;
630 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
632 /* Follow the compilation unit sibling chain, building a partial symbol
633 table entry for each one. Save enough information about each compilation
634 unit to locate the full DWARF information later. */
636 scan_compilation_units (dbbase
, dbbase
+ dbsize
, dbfoff
, lnoffset
, objfile
);
638 do_cleanups (back_to
);
639 current_objfile
= NULL
;
646 read_lexical_block_scope -- process all dies in a lexical block
650 static void read_lexical_block_scope (struct dieinfo *dip,
651 char *thisdie, char *enddie)
655 Process all the DIES contained within a lexical block scope.
656 Start a new scope, process the dies, and then close the scope.
661 read_lexical_block_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
662 struct objfile
*objfile
)
664 register struct context_stack
*new;
666 push_context (0, dip
->at_low_pc
);
667 process_dies (thisdie
+ dip
->die_length
, enddie
, objfile
);
668 new = pop_context ();
669 if (local_symbols
!= NULL
)
671 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
672 dip
->at_high_pc
, objfile
);
674 local_symbols
= new->locals
;
681 lookup_utype -- look up a user defined type from die reference
685 static type *lookup_utype (DIE_REF die_ref)
689 Given a DIE reference, lookup the user defined type associated with
690 that DIE, if it has been registered already. If not registered, then
691 return NULL. Alloc_utype() can be called to register an empty
692 type for this reference, which will be filled in later when the
693 actual referenced DIE is processed.
697 lookup_utype (DIE_REF die_ref
)
699 struct type
*type
= NULL
;
702 utypeidx
= (die_ref
- dbroff
) / 4;
703 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
705 bad_die_ref_complaint (DIE_ID
, DIE_NAME
, die_ref
);
709 type
= *(utypes
+ utypeidx
);
719 alloc_utype -- add a user defined type for die reference
723 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
727 Given a die reference DIE_REF, and a possible pointer to a user
728 defined type UTYPEP, register that this reference has a user
729 defined type and either use the specified type in UTYPEP or
730 make a new empty type that will be filled in later.
732 We should only be called after calling lookup_utype() to verify that
733 there is not currently a type registered for DIE_REF.
737 alloc_utype (DIE_REF die_ref
, struct type
*utypep
)
742 utypeidx
= (die_ref
- dbroff
) / 4;
743 typep
= utypes
+ utypeidx
;
744 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
746 utypep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
747 bad_die_ref_complaint (DIE_ID
, DIE_NAME
, die_ref
);
749 else if (*typep
!= NULL
)
752 complaint (&symfile_complaints
,
753 "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation",
760 utypep
= alloc_type (current_objfile
);
771 free_utypes -- free the utypes array and reset pointer & count
775 static void free_utypes (void *dummy)
779 Called via do_cleanups to free the utypes array, reset the pointer to NULL,
780 and set numutypes back to zero. This ensures that the utypes does not get
781 referenced after being freed.
785 free_utypes (void *dummy
)
797 decode_die_type -- return a type for a specified die
801 static struct type *decode_die_type (struct dieinfo *dip)
805 Given a pointer to a die information structure DIP, decode the
806 type of the die and return a pointer to the decoded type. All
807 dies without specific types default to type int.
811 decode_die_type (struct dieinfo
*dip
)
813 struct type
*type
= NULL
;
815 if (dip
->at_fund_type
!= 0)
817 type
= decode_fund_type (dip
->at_fund_type
);
819 else if (dip
->at_mod_fund_type
!= NULL
)
821 type
= decode_mod_fund_type (dip
->at_mod_fund_type
);
823 else if (dip
->at_user_def_type
)
825 if ((type
= lookup_utype (dip
->at_user_def_type
)) == NULL
)
827 type
= alloc_utype (dip
->at_user_def_type
, NULL
);
830 else if (dip
->at_mod_u_d_type
)
832 type
= decode_mod_u_d_type (dip
->at_mod_u_d_type
);
836 type
= dwarf_fundamental_type (current_objfile
, FT_VOID
);
845 struct_type -- compute and return the type for a struct or union
849 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
850 char *enddie, struct objfile *objfile)
854 Given pointer to a die information structure for a die which
855 defines a union or structure (and MUST define one or the other),
856 and pointers to the raw die data that define the range of dies which
857 define the members, compute and return the user defined type for the
862 struct_type (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
863 struct objfile
*objfile
)
868 struct nextfield
*next
;
871 struct nextfield
*list
= NULL
;
872 struct nextfield
*new;
879 if ((type
= lookup_utype (dip
->die_ref
)) == NULL
)
881 /* No forward references created an empty type, so install one now */
882 type
= alloc_utype (dip
->die_ref
, NULL
);
884 INIT_CPLUS_SPECIFIC (type
);
885 switch (dip
->die_tag
)
888 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
890 case TAG_structure_type
:
891 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
894 TYPE_CODE (type
) = TYPE_CODE_UNION
;
897 /* Should never happen */
898 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
899 complaint (&symfile_complaints
,
900 "DIE @ 0x%x \"%s\", missing class, structure, or union tag",
904 /* Some compilers try to be helpful by inventing "fake" names for
905 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
906 Thanks, but no thanks... */
907 if (dip
->at_name
!= NULL
908 && *dip
->at_name
!= '~'
909 && *dip
->at_name
!= '.')
911 TYPE_TAG_NAME (type
) = obconcat (&objfile
->type_obstack
,
912 "", "", dip
->at_name
);
914 /* Use whatever size is known. Zero is a valid size. We might however
915 wish to check has_at_byte_size to make sure that some byte size was
916 given explicitly, but DWARF doesn't specify that explicit sizes of
917 zero have to present, so complaining about missing sizes should
918 probably not be the default. */
919 TYPE_LENGTH (type
) = dip
->at_byte_size
;
920 thisdie
+= dip
->die_length
;
921 while (thisdie
< enddie
)
923 basicdieinfo (&mbr
, thisdie
, objfile
);
924 completedieinfo (&mbr
, objfile
);
925 if (mbr
.die_length
<= SIZEOF_DIE_LENGTH
)
929 else if (mbr
.at_sibling
!= 0)
931 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
935 nextdie
= thisdie
+ mbr
.die_length
;
940 /* Get space to record the next field's data. */
941 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
946 obsavestring (mbr
.at_name
, strlen (mbr
.at_name
),
947 &objfile
->type_obstack
);
948 FIELD_TYPE (list
->field
) = decode_die_type (&mbr
);
949 FIELD_BITPOS (list
->field
) = 8 * locval (&mbr
);
950 FIELD_STATIC_KIND (list
->field
) = 0;
951 /* Handle bit fields. */
952 FIELD_BITSIZE (list
->field
) = mbr
.at_bit_size
;
955 /* For big endian bits, the at_bit_offset gives the
956 additional bit offset from the MSB of the containing
957 anonymous object to the MSB of the field. We don't
958 have to do anything special since we don't need to
959 know the size of the anonymous object. */
960 FIELD_BITPOS (list
->field
) += mbr
.at_bit_offset
;
964 /* For little endian bits, we need to have a non-zero
965 at_bit_size, so that we know we are in fact dealing
966 with a bitfield. Compute the bit offset to the MSB
967 of the anonymous object, subtract off the number of
968 bits from the MSB of the field to the MSB of the
969 object, and then subtract off the number of bits of
970 the field itself. The result is the bit offset of
971 the LSB of the field. */
972 if (mbr
.at_bit_size
> 0)
974 if (mbr
.has_at_byte_size
)
976 /* The size of the anonymous object containing
977 the bit field is explicit, so use the
978 indicated size (in bytes). */
979 anonymous_size
= mbr
.at_byte_size
;
983 /* The size of the anonymous object containing
984 the bit field matches the size of an object
985 of the bit field's type. DWARF allows
986 at_byte_size to be left out in such cases, as
987 a debug information size optimization. */
988 anonymous_size
= TYPE_LENGTH (list
->field
.type
);
990 FIELD_BITPOS (list
->field
) +=
991 anonymous_size
* 8 - mbr
.at_bit_offset
- mbr
.at_bit_size
;
997 process_dies (thisdie
, nextdie
, objfile
);
1002 /* Now create the vector of fields, and record how big it is. We may
1003 not even have any fields, if this DIE was generated due to a reference
1004 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
1005 set, which clues gdb in to the fact that it needs to search elsewhere
1006 for the full structure definition. */
1009 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1013 TYPE_NFIELDS (type
) = nfields
;
1014 TYPE_FIELDS (type
) = (struct field
*)
1015 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1016 /* Copy the saved-up fields into the field vector. */
1017 for (n
= nfields
; list
; list
= list
->next
)
1019 TYPE_FIELD (type
, --n
) = list
->field
;
1029 read_structure_scope -- process all dies within struct or union
1033 static void read_structure_scope (struct dieinfo *dip,
1034 char *thisdie, char *enddie, struct objfile *objfile)
1038 Called when we find the DIE that starts a structure or union
1039 scope (definition) to process all dies that define the members
1040 of the structure or union. DIP is a pointer to the die info
1041 struct for the DIE that names the structure or union.
1045 Note that we need to call struct_type regardless of whether or not
1046 the DIE has an at_name attribute, since it might be an anonymous
1047 structure or union. This gets the type entered into our set of
1050 However, if the structure is incomplete (an opaque struct/union)
1051 then suppress creating a symbol table entry for it since gdb only
1052 wants to find the one with the complete definition. Note that if
1053 it is complete, we just call new_symbol, which does it's own
1054 checking about whether the struct/union is anonymous or not (and
1055 suppresses creating a symbol table entry itself).
1060 read_structure_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1061 struct objfile
*objfile
)
1066 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
1067 if (!TYPE_STUB (type
))
1069 sym
= new_symbol (dip
, objfile
);
1072 SYMBOL_TYPE (sym
) = type
;
1073 if (cu_language
== language_cplus
)
1075 synthesize_typedef (dip
, objfile
, type
);
1085 decode_array_element_type -- decode type of the array elements
1089 static struct type *decode_array_element_type (char *scan, char *end)
1093 As the last step in decoding the array subscript information for an
1094 array DIE, we need to decode the type of the array elements. We are
1095 passed a pointer to this last part of the subscript information and
1096 must return the appropriate type. If the type attribute is not
1097 recognized, just warn about the problem and return type int.
1100 static struct type
*
1101 decode_array_element_type (char *scan
)
1105 unsigned short attribute
;
1106 unsigned short fundtype
;
1109 attribute
= target_to_host (scan
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
,
1111 scan
+= SIZEOF_ATTRIBUTE
;
1112 if ((nbytes
= attribute_size (attribute
)) == -1)
1114 bad_array_element_type_complaint (DIE_ID
, DIE_NAME
, attribute
);
1115 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1122 fundtype
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1124 typep
= decode_fund_type (fundtype
);
1126 case AT_mod_fund_type
:
1127 typep
= decode_mod_fund_type (scan
);
1129 case AT_user_def_type
:
1130 die_ref
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1132 if ((typep
= lookup_utype (die_ref
)) == NULL
)
1134 typep
= alloc_utype (die_ref
, NULL
);
1137 case AT_mod_u_d_type
:
1138 typep
= decode_mod_u_d_type (scan
);
1141 bad_array_element_type_complaint (DIE_ID
, DIE_NAME
, attribute
);
1142 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1153 decode_subscript_data_item -- decode array subscript item
1157 static struct type *
1158 decode_subscript_data_item (char *scan, char *end)
1162 The array subscripts and the data type of the elements of an
1163 array are described by a list of data items, stored as a block
1164 of contiguous bytes. There is a data item describing each array
1165 dimension, and a final data item describing the element type.
1166 The data items are ordered the same as their appearance in the
1167 source (I.E. leftmost dimension first, next to leftmost second,
1170 The data items describing each array dimension consist of four
1171 parts: (1) a format specifier, (2) type type of the subscript
1172 index, (3) a description of the low bound of the array dimension,
1173 and (4) a description of the high bound of the array dimension.
1175 The last data item is the description of the type of each of
1178 We are passed a pointer to the start of the block of bytes
1179 containing the remaining data items, and a pointer to the first
1180 byte past the data. This function recursively decodes the
1181 remaining data items and returns a type.
1183 If we somehow fail to decode some data, we complain about it
1184 and return a type "array of int".
1187 FIXME: This code only implements the forms currently used
1188 by the AT&T and GNU C compilers.
1190 The end pointer is supplied for error checking, maybe we should
1194 static struct type
*
1195 decode_subscript_data_item (char *scan
, char *end
)
1197 struct type
*typep
= NULL
; /* Array type we are building */
1198 struct type
*nexttype
; /* Type of each element (may be array) */
1199 struct type
*indextype
; /* Type of this index */
1200 struct type
*rangetype
;
1201 unsigned int format
;
1202 unsigned short fundtype
;
1203 unsigned long lowbound
;
1204 unsigned long highbound
;
1207 format
= target_to_host (scan
, SIZEOF_FORMAT_SPECIFIER
, GET_UNSIGNED
,
1209 scan
+= SIZEOF_FORMAT_SPECIFIER
;
1213 typep
= decode_array_element_type (scan
);
1216 fundtype
= target_to_host (scan
, SIZEOF_FMT_FT
, GET_UNSIGNED
,
1218 indextype
= decode_fund_type (fundtype
);
1219 scan
+= SIZEOF_FMT_FT
;
1220 nbytes
= TARGET_FT_LONG_SIZE (current_objfile
);
1221 lowbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, current_objfile
);
1223 highbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, current_objfile
);
1225 nexttype
= decode_subscript_data_item (scan
, end
);
1226 if (nexttype
== NULL
)
1228 /* Munged subscript data or other problem, fake it. */
1229 complaint (&symfile_complaints
,
1230 "DIE @ 0x%x \"%s\", can't decode subscript data items",
1232 nexttype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1234 rangetype
= create_range_type ((struct type
*) NULL
, indextype
,
1235 lowbound
, highbound
);
1236 typep
= create_array_type ((struct type
*) NULL
, nexttype
, rangetype
);
1245 complaint (&symfile_complaints
,
1246 "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet",
1247 DIE_ID
, DIE_NAME
, format
);
1248 nexttype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1249 rangetype
= create_range_type ((struct type
*) NULL
, nexttype
, 0, 0);
1250 typep
= create_array_type ((struct type
*) NULL
, nexttype
, rangetype
);
1253 complaint (&symfile_complaints
,
1254 "DIE @ 0x%x \"%s\", unknown array subscript format %x", DIE_ID
,
1256 nexttype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1257 rangetype
= create_range_type ((struct type
*) NULL
, nexttype
, 0, 0);
1258 typep
= create_array_type ((struct type
*) NULL
, nexttype
, rangetype
);
1268 dwarf_read_array_type -- read TAG_array_type DIE
1272 static void dwarf_read_array_type (struct dieinfo *dip)
1276 Extract all information from a TAG_array_type DIE and add to
1277 the user defined type vector.
1281 dwarf_read_array_type (struct dieinfo
*dip
)
1287 unsigned short blocksz
;
1290 if (dip
->at_ordering
!= ORD_row_major
)
1292 /* FIXME: Can gdb even handle column major arrays? */
1293 complaint (&symfile_complaints
,
1294 "DIE @ 0x%x \"%s\", array not row major; not handled correctly",
1297 if ((sub
= dip
->at_subscr_data
) != NULL
)
1299 nbytes
= attribute_size (AT_subscr_data
);
1300 blocksz
= target_to_host (sub
, nbytes
, GET_UNSIGNED
, current_objfile
);
1301 subend
= sub
+ nbytes
+ blocksz
;
1303 type
= decode_subscript_data_item (sub
, subend
);
1304 if ((utype
= lookup_utype (dip
->die_ref
)) == NULL
)
1306 /* Install user defined type that has not been referenced yet. */
1307 alloc_utype (dip
->die_ref
, type
);
1309 else if (TYPE_CODE (utype
) == TYPE_CODE_UNDEF
)
1311 /* Ick! A forward ref has already generated a blank type in our
1312 slot, and this type probably already has things pointing to it
1313 (which is what caused it to be created in the first place).
1314 If it's just a place holder we can plop our fully defined type
1315 on top of it. We can't recover the space allocated for our
1316 new type since it might be on an obstack, but we could reuse
1317 it if we kept a list of them, but it might not be worth it
1323 /* Double ick! Not only is a type already in our slot, but
1324 someone has decorated it. Complain and leave it alone. */
1325 dup_user_type_definition_complaint (DIE_ID
, DIE_NAME
);
1334 read_tag_pointer_type -- read TAG_pointer_type DIE
1338 static void read_tag_pointer_type (struct dieinfo *dip)
1342 Extract all information from a TAG_pointer_type DIE and add to
1343 the user defined type vector.
1347 read_tag_pointer_type (struct dieinfo
*dip
)
1352 type
= decode_die_type (dip
);
1353 if ((utype
= lookup_utype (dip
->die_ref
)) == NULL
)
1355 utype
= lookup_pointer_type (type
);
1356 alloc_utype (dip
->die_ref
, utype
);
1360 TYPE_TARGET_TYPE (utype
) = type
;
1361 TYPE_POINTER_TYPE (type
) = utype
;
1363 /* We assume the machine has only one representation for pointers! */
1364 /* FIXME: Possably a poor assumption */
1365 TYPE_LENGTH (utype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
1366 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1374 read_tag_string_type -- read TAG_string_type DIE
1378 static void read_tag_string_type (struct dieinfo *dip)
1382 Extract all information from a TAG_string_type DIE and add to
1383 the user defined type vector. It isn't really a user defined
1384 type, but it behaves like one, with other DIE's using an
1385 AT_user_def_type attribute to reference it.
1389 read_tag_string_type (struct dieinfo
*dip
)
1392 struct type
*indextype
;
1393 struct type
*rangetype
;
1394 unsigned long lowbound
= 0;
1395 unsigned long highbound
;
1397 if (dip
->has_at_byte_size
)
1399 /* A fixed bounds string */
1400 highbound
= dip
->at_byte_size
- 1;
1404 /* A varying length string. Stub for now. (FIXME) */
1407 indextype
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
1408 rangetype
= create_range_type ((struct type
*) NULL
, indextype
, lowbound
,
1411 utype
= lookup_utype (dip
->die_ref
);
1414 /* No type defined, go ahead and create a blank one to use. */
1415 utype
= alloc_utype (dip
->die_ref
, (struct type
*) NULL
);
1419 /* Already a type in our slot due to a forward reference. Make sure it
1420 is a blank one. If not, complain and leave it alone. */
1421 if (TYPE_CODE (utype
) != TYPE_CODE_UNDEF
)
1423 dup_user_type_definition_complaint (DIE_ID
, DIE_NAME
);
1428 /* Create the string type using the blank type we either found or created. */
1429 utype
= create_string_type (utype
, rangetype
);
1436 read_subroutine_type -- process TAG_subroutine_type dies
1440 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1445 Handle DIES due to C code like:
1448 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1454 The parameter DIES are currently ignored. See if gdb has a way to
1455 include this info in it's type system, and decode them if so. Is
1456 this what the type structure's "arg_types" field is for? (FIXME)
1460 read_subroutine_type (struct dieinfo
*dip
, char *thisdie
, char *enddie
)
1462 struct type
*type
; /* Type that this function returns */
1463 struct type
*ftype
; /* Function that returns above type */
1465 /* Decode the type that this subroutine returns */
1467 type
= decode_die_type (dip
);
1469 /* Check to see if we already have a partially constructed user
1470 defined type for this DIE, from a forward reference. */
1472 if ((ftype
= lookup_utype (dip
->die_ref
)) == NULL
)
1474 /* This is the first reference to one of these types. Make
1475 a new one and place it in the user defined types. */
1476 ftype
= lookup_function_type (type
);
1477 alloc_utype (dip
->die_ref
, ftype
);
1479 else if (TYPE_CODE (ftype
) == TYPE_CODE_UNDEF
)
1481 /* We have an existing partially constructed type, so bash it
1482 into the correct type. */
1483 TYPE_TARGET_TYPE (ftype
) = type
;
1484 TYPE_LENGTH (ftype
) = 1;
1485 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1489 dup_user_type_definition_complaint (DIE_ID
, DIE_NAME
);
1497 read_enumeration -- process dies which define an enumeration
1501 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1502 char *enddie, struct objfile *objfile)
1506 Given a pointer to a die which begins an enumeration, process all
1507 the dies that define the members of the enumeration.
1511 Note that we need to call enum_type regardless of whether or not we
1512 have a symbol, since we might have an enum without a tag name (thus
1513 no symbol for the tagname).
1517 read_enumeration (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1518 struct objfile
*objfile
)
1523 type
= enum_type (dip
, objfile
);
1524 sym
= new_symbol (dip
, objfile
);
1527 SYMBOL_TYPE (sym
) = type
;
1528 if (cu_language
== language_cplus
)
1530 synthesize_typedef (dip
, objfile
, type
);
1539 enum_type -- decode and return a type for an enumeration
1543 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1547 Given a pointer to a die information structure for the die which
1548 starts an enumeration, process all the dies that define the members
1549 of the enumeration and return a type pointer for the enumeration.
1551 At the same time, for each member of the enumeration, create a
1552 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1553 and give it the type of the enumeration itself.
1557 Note that the DWARF specification explicitly mandates that enum
1558 constants occur in reverse order from the source program order,
1559 for "consistency" and because this ordering is easier for many
1560 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1561 Entries). Because gdb wants to see the enum members in program
1562 source order, we have to ensure that the order gets reversed while
1563 we are processing them.
1566 static struct type
*
1567 enum_type (struct dieinfo
*dip
, struct objfile
*objfile
)
1572 struct nextfield
*next
;
1575 struct nextfield
*list
= NULL
;
1576 struct nextfield
*new;
1581 unsigned short blocksz
;
1584 int unsigned_enum
= 1;
1586 if ((type
= lookup_utype (dip
->die_ref
)) == NULL
)
1588 /* No forward references created an empty type, so install one now */
1589 type
= alloc_utype (dip
->die_ref
, NULL
);
1591 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1592 /* Some compilers try to be helpful by inventing "fake" names for
1593 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1594 Thanks, but no thanks... */
1595 if (dip
->at_name
!= NULL
1596 && *dip
->at_name
!= '~'
1597 && *dip
->at_name
!= '.')
1599 TYPE_TAG_NAME (type
) = obconcat (&objfile
->type_obstack
,
1600 "", "", dip
->at_name
);
1602 if (dip
->at_byte_size
!= 0)
1604 TYPE_LENGTH (type
) = dip
->at_byte_size
;
1606 if ((scan
= dip
->at_element_list
) != NULL
)
1608 if (dip
->short_element_list
)
1610 nbytes
= attribute_size (AT_short_element_list
);
1614 nbytes
= attribute_size (AT_element_list
);
1616 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
1617 listend
= scan
+ nbytes
+ blocksz
;
1619 while (scan
< listend
)
1621 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1624 FIELD_TYPE (list
->field
) = NULL
;
1625 FIELD_BITSIZE (list
->field
) = 0;
1626 FIELD_STATIC_KIND (list
->field
) = 0;
1627 FIELD_BITPOS (list
->field
) =
1628 target_to_host (scan
, TARGET_FT_LONG_SIZE (objfile
), GET_SIGNED
,
1630 scan
+= TARGET_FT_LONG_SIZE (objfile
);
1631 list
->field
.name
= obsavestring (scan
, strlen (scan
),
1632 &objfile
->type_obstack
);
1633 scan
+= strlen (scan
) + 1;
1635 /* Handcraft a new symbol for this enum member. */
1636 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1637 sizeof (struct symbol
));
1638 memset (sym
, 0, sizeof (struct symbol
));
1639 SYMBOL_NAME (sym
) = create_name (list
->field
.name
,
1640 &objfile
->symbol_obstack
);
1641 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym
, cu_language
);
1642 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1643 SYMBOL_CLASS (sym
) = LOC_CONST
;
1644 SYMBOL_TYPE (sym
) = type
;
1645 SYMBOL_VALUE (sym
) = FIELD_BITPOS (list
->field
);
1646 if (SYMBOL_VALUE (sym
) < 0)
1648 add_symbol_to_list (sym
, list_in_scope
);
1650 /* Now create the vector of fields, and record how big it is. This is
1651 where we reverse the order, by pulling the members off the list in
1652 reverse order from how they were inserted. If we have no fields
1653 (this is apparently possible in C++) then skip building a field
1658 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
1659 TYPE_NFIELDS (type
) = nfields
;
1660 TYPE_FIELDS (type
) = (struct field
*)
1661 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1662 /* Copy the saved-up fields into the field vector. */
1663 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
->next
)
1665 TYPE_FIELD (type
, n
++) = list
->field
;
1676 read_func_scope -- process all dies within a function scope
1680 Process all dies within a given function scope. We are passed
1681 a die information structure pointer DIP for the die which
1682 starts the function scope, and pointers into the raw die data
1683 that define the dies within the function scope.
1685 For now, we ignore lexical block scopes within the function.
1686 The problem is that AT&T cc does not define a DWARF lexical
1687 block scope for the function itself, while gcc defines a
1688 lexical block scope for the function. We need to think about
1689 how to handle this difference, or if it is even a problem.
1694 read_func_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1695 struct objfile
*objfile
)
1697 register struct context_stack
*new;
1699 /* AT_name is absent if the function is described with an
1700 AT_abstract_origin tag.
1701 Ignore the function description for now to avoid GDB core dumps.
1702 FIXME: Add code to handle AT_abstract_origin tags properly. */
1703 if (dip
->at_name
== NULL
)
1705 complaint (&symfile_complaints
, "DIE @ 0x%x, AT_name tag missing",
1710 if (objfile
->ei
.entry_point
>= dip
->at_low_pc
&&
1711 objfile
->ei
.entry_point
< dip
->at_high_pc
)
1713 objfile
->ei
.entry_func_lowpc
= dip
->at_low_pc
;
1714 objfile
->ei
.entry_func_highpc
= dip
->at_high_pc
;
1716 new = push_context (0, dip
->at_low_pc
);
1717 new->name
= new_symbol (dip
, objfile
);
1718 list_in_scope
= &local_symbols
;
1719 process_dies (thisdie
+ dip
->die_length
, enddie
, objfile
);
1720 new = pop_context ();
1721 /* Make a block for the local symbols within. */
1722 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1723 new->start_addr
, dip
->at_high_pc
, objfile
);
1724 list_in_scope
= &file_symbols
;
1732 handle_producer -- process the AT_producer attribute
1736 Perform any operations that depend on finding a particular
1737 AT_producer attribute.
1742 handle_producer (char *producer
)
1745 /* If this compilation unit was compiled with g++ or gcc, then set the
1746 processing_gcc_compilation flag. */
1748 if (STREQN (producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
)))
1750 char version
= producer
[strlen (GCC_PRODUCER
)];
1751 processing_gcc_compilation
= (version
== '2' ? 2 : 1);
1755 processing_gcc_compilation
=
1756 STREQN (producer
, GPLUS_PRODUCER
, strlen (GPLUS_PRODUCER
));
1759 /* Select a demangling style if we can identify the producer and if
1760 the current style is auto. We leave the current style alone if it
1761 is not auto. We also leave the demangling style alone if we find a
1762 gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
1764 if (AUTO_DEMANGLING
)
1766 if (STREQN (producer
, GPLUS_PRODUCER
, strlen (GPLUS_PRODUCER
)))
1769 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
1770 know whether it will use the old style or v3 mangling. */
1771 set_demangling_style (GNU_DEMANGLING_STYLE_STRING
);
1774 else if (STREQN (producer
, LCC_PRODUCER
, strlen (LCC_PRODUCER
)))
1776 set_demangling_style (LUCID_DEMANGLING_STYLE_STRING
);
1786 read_file_scope -- process all dies within a file scope
1790 Process all dies within a given file scope. We are passed a
1791 pointer to the die information structure for the die which
1792 starts the file scope, and pointers into the raw die data which
1793 mark the range of dies within the file scope.
1795 When the partial symbol table is built, the file offset for the line
1796 number table for each compilation unit is saved in the partial symbol
1797 table entry for that compilation unit. As the symbols for each
1798 compilation unit are read, the line number table is read into memory
1799 and the variable lnbase is set to point to it. Thus all we have to
1800 do is use lnbase to access the line number table for the current
1805 read_file_scope (struct dieinfo
*dip
, char *thisdie
, char *enddie
,
1806 struct objfile
*objfile
)
1808 struct cleanup
*back_to
;
1809 struct symtab
*symtab
;
1811 if (objfile
->ei
.entry_point
>= dip
->at_low_pc
&&
1812 objfile
->ei
.entry_point
< dip
->at_high_pc
)
1814 objfile
->ei
.entry_file_lowpc
= dip
->at_low_pc
;
1815 objfile
->ei
.entry_file_highpc
= dip
->at_high_pc
;
1817 set_cu_language (dip
);
1818 if (dip
->at_producer
!= NULL
)
1820 handle_producer (dip
->at_producer
);
1822 numutypes
= (enddie
- thisdie
) / 4;
1823 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1824 back_to
= make_cleanup (free_utypes
, NULL
);
1825 memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1826 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1827 start_symtab (dip
->at_name
, dip
->at_comp_dir
, dip
->at_low_pc
);
1828 record_debugformat ("DWARF 1");
1829 decode_line_numbers (lnbase
);
1830 process_dies (thisdie
+ dip
->die_length
, enddie
, objfile
);
1832 symtab
= end_symtab (dip
->at_high_pc
, objfile
, 0);
1835 symtab
->language
= cu_language
;
1837 do_cleanups (back_to
);
1844 process_dies -- process a range of DWARF Information Entries
1848 static void process_dies (char *thisdie, char *enddie,
1849 struct objfile *objfile)
1853 Process all DIE's in a specified range. May be (and almost
1854 certainly will be) called recursively.
1858 process_dies (char *thisdie
, char *enddie
, struct objfile
*objfile
)
1863 while (thisdie
< enddie
)
1865 basicdieinfo (&di
, thisdie
, objfile
);
1866 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
1870 else if (di
.die_tag
== TAG_padding
)
1872 nextdie
= thisdie
+ di
.die_length
;
1876 completedieinfo (&di
, objfile
);
1877 if (di
.at_sibling
!= 0)
1879 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1883 nextdie
= thisdie
+ di
.die_length
;
1885 /* I think that these are always text, not data, addresses. */
1886 di
.at_low_pc
= SMASH_TEXT_ADDRESS (di
.at_low_pc
);
1887 di
.at_high_pc
= SMASH_TEXT_ADDRESS (di
.at_high_pc
);
1890 case TAG_compile_unit
:
1891 /* Skip Tag_compile_unit if we are already inside a compilation
1892 unit, we are unable to handle nested compilation units
1893 properly (FIXME). */
1894 if (current_subfile
== NULL
)
1895 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1897 nextdie
= thisdie
+ di
.die_length
;
1899 case TAG_global_subroutine
:
1900 case TAG_subroutine
:
1901 if (di
.has_at_low_pc
)
1903 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1906 case TAG_lexical_block
:
1907 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1909 case TAG_class_type
:
1910 case TAG_structure_type
:
1911 case TAG_union_type
:
1912 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1914 case TAG_enumeration_type
:
1915 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1917 case TAG_subroutine_type
:
1918 read_subroutine_type (&di
, thisdie
, nextdie
);
1920 case TAG_array_type
:
1921 dwarf_read_array_type (&di
);
1923 case TAG_pointer_type
:
1924 read_tag_pointer_type (&di
);
1926 case TAG_string_type
:
1927 read_tag_string_type (&di
);
1930 new_symbol (&di
, objfile
);
1942 decode_line_numbers -- decode a line number table fragment
1946 static void decode_line_numbers (char *tblscan, char *tblend,
1947 long length, long base, long line, long pc)
1951 Translate the DWARF line number information to gdb form.
1953 The ".line" section contains one or more line number tables, one for
1954 each ".line" section from the objects that were linked.
1956 The AT_stmt_list attribute for each TAG_source_file entry in the
1957 ".debug" section contains the offset into the ".line" section for the
1958 start of the table for that file.
1960 The table itself has the following structure:
1962 <table length><base address><source statement entry>
1963 4 bytes 4 bytes 10 bytes
1965 The table length is the total size of the table, including the 4 bytes
1966 for the length information.
1968 The base address is the address of the first instruction generated
1969 for the source file.
1971 Each source statement entry has the following structure:
1973 <line number><statement position><address delta>
1974 4 bytes 2 bytes 4 bytes
1976 The line number is relative to the start of the file, starting with
1979 The statement position either -1 (0xFFFF) or the number of characters
1980 from the beginning of the line to the beginning of the statement.
1982 The address delta is the difference between the base address and
1983 the address of the first instruction for the statement.
1985 Note that we must copy the bytes from the packed table to our local
1986 variables before attempting to use them, to avoid alignment problems
1987 on some machines, particularly RISC processors.
1991 Does gdb expect the line numbers to be sorted? They are now by
1992 chance/luck, but are not required to be. (FIXME)
1994 The line with number 0 is unused, gdb apparently can discover the
1995 span of the last line some other way. How? (FIXME)
1999 decode_line_numbers (char *linetable
)
2003 unsigned long length
;
2008 if (linetable
!= NULL
)
2010 tblscan
= tblend
= linetable
;
2011 length
= target_to_host (tblscan
, SIZEOF_LINETBL_LENGTH
, GET_UNSIGNED
,
2013 tblscan
+= SIZEOF_LINETBL_LENGTH
;
2015 base
= target_to_host (tblscan
, TARGET_FT_POINTER_SIZE (objfile
),
2016 GET_UNSIGNED
, current_objfile
);
2017 tblscan
+= TARGET_FT_POINTER_SIZE (objfile
);
2019 while (tblscan
< tblend
)
2021 line
= target_to_host (tblscan
, SIZEOF_LINETBL_LINENO
, GET_UNSIGNED
,
2023 tblscan
+= SIZEOF_LINETBL_LINENO
+ SIZEOF_LINETBL_STMT
;
2024 pc
= target_to_host (tblscan
, SIZEOF_LINETBL_DELTA
, GET_UNSIGNED
,
2026 tblscan
+= SIZEOF_LINETBL_DELTA
;
2030 record_line (current_subfile
, line
, pc
);
2040 locval -- compute the value of a location attribute
2044 static int locval (struct dieinfo *dip)
2048 Given pointer to a string of bytes that define a location, compute
2049 the location and return the value.
2050 A location description containing no atoms indicates that the
2051 object is optimized out. The optimized_out flag is set for those,
2052 the return value is meaningless.
2054 When computing values involving the current value of the frame pointer,
2055 the value zero is used, which results in a value relative to the frame
2056 pointer, rather than the absolute value. This is what GDB wants
2059 When the result is a register number, the isreg flag is set, otherwise
2060 it is cleared. This is a kludge until we figure out a better
2061 way to handle the problem. Gdb's design does not mesh well with the
2062 DWARF notion of a location computing interpreter, which is a shame
2063 because the flexibility goes unused.
2067 Note that stack[0] is unused except as a default error return.
2068 Note that stack overflow is not yet handled.
2072 locval (struct dieinfo
*dip
)
2074 unsigned short nbytes
;
2075 unsigned short locsize
;
2076 auto long stack
[64];
2083 loc
= dip
->at_location
;
2084 nbytes
= attribute_size (AT_location
);
2085 locsize
= target_to_host (loc
, nbytes
, GET_UNSIGNED
, current_objfile
);
2087 end
= loc
+ locsize
;
2092 dip
->optimized_out
= 1;
2093 loc_value_size
= TARGET_FT_LONG_SIZE (current_objfile
);
2096 dip
->optimized_out
= 0;
2097 loc_atom_code
= target_to_host (loc
, SIZEOF_LOC_ATOM_CODE
, GET_UNSIGNED
,
2099 loc
+= SIZEOF_LOC_ATOM_CODE
;
2100 switch (loc_atom_code
)
2107 /* push register (number) */
2109 = DWARF_REG_TO_REGNUM (target_to_host (loc
, loc_value_size
,
2112 loc
+= loc_value_size
;
2116 /* push value of register (number) */
2117 /* Actually, we compute the value as if register has 0, so the
2118 value ends up being the offset from that register. */
2120 dip
->basereg
= target_to_host (loc
, loc_value_size
, GET_UNSIGNED
,
2122 loc
+= loc_value_size
;
2123 stack
[++stacki
] = 0;
2126 /* push address (relocated address) */
2127 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
2128 GET_UNSIGNED
, current_objfile
);
2129 loc
+= loc_value_size
;
2132 /* push constant (number) FIXME: signed or unsigned! */
2133 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
2134 GET_SIGNED
, current_objfile
);
2135 loc
+= loc_value_size
;
2138 /* pop, deref and push 2 bytes (as a long) */
2139 complaint (&symfile_complaints
,
2140 "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%lx not handled",
2141 DIE_ID
, DIE_NAME
, stack
[stacki
]);
2143 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
2144 complaint (&symfile_complaints
,
2145 "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%lx not handled",
2146 DIE_ID
, DIE_NAME
, stack
[stacki
]);
2148 case OP_ADD
: /* pop top 2 items, add, push result */
2149 stack
[stacki
- 1] += stack
[stacki
];
2154 return (stack
[stacki
]);
2161 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
2165 static void read_ofile_symtab (struct partial_symtab *pst)
2169 When expanding a partial symbol table entry to a full symbol table
2170 entry, this is the function that gets called to read in the symbols
2171 for the compilation unit. A pointer to the newly constructed symtab,
2172 which is now the new first one on the objfile's symtab list, is
2173 stashed in the partial symbol table entry.
2177 read_ofile_symtab (struct partial_symtab
*pst
)
2179 struct cleanup
*back_to
;
2180 unsigned long lnsize
;
2183 char lnsizedata
[SIZEOF_LINETBL_LENGTH
];
2185 abfd
= pst
->objfile
->obfd
;
2186 current_objfile
= pst
->objfile
;
2188 /* Allocate a buffer for the entire chunk of DIE's for this compilation
2189 unit, seek to the location in the file, and read in all the DIE's. */
2192 dbsize
= DBLENGTH (pst
);
2193 dbbase
= xmalloc (dbsize
);
2194 dbroff
= DBROFF (pst
);
2195 foffset
= DBFOFF (pst
) + dbroff
;
2196 base_section_offsets
= pst
->section_offsets
;
2197 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
2198 if (bfd_seek (abfd
, foffset
, SEEK_SET
) ||
2199 (bfd_bread (dbbase
, dbsize
, abfd
) != dbsize
))
2202 error ("can't read DWARF data");
2204 back_to
= make_cleanup (xfree
, dbbase
);
2206 /* If there is a line number table associated with this compilation unit
2207 then read the size of this fragment in bytes, from the fragment itself.
2208 Allocate a buffer for the fragment and read it in for future
2214 if (bfd_seek (abfd
, LNFOFF (pst
), SEEK_SET
) ||
2215 (bfd_bread (lnsizedata
, sizeof (lnsizedata
), abfd
)
2216 != sizeof (lnsizedata
)))
2218 error ("can't read DWARF line number table size");
2220 lnsize
= target_to_host (lnsizedata
, SIZEOF_LINETBL_LENGTH
,
2221 GET_UNSIGNED
, pst
->objfile
);
2222 lnbase
= xmalloc (lnsize
);
2223 if (bfd_seek (abfd
, LNFOFF (pst
), SEEK_SET
) ||
2224 (bfd_bread (lnbase
, lnsize
, abfd
) != lnsize
))
2227 error ("can't read DWARF line numbers");
2229 make_cleanup (xfree
, lnbase
);
2232 process_dies (dbbase
, dbbase
+ dbsize
, pst
->objfile
);
2233 do_cleanups (back_to
);
2234 current_objfile
= NULL
;
2235 pst
->symtab
= pst
->objfile
->symtabs
;
2242 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
2246 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
2250 Called once for each partial symbol table entry that needs to be
2251 expanded into a full symbol table entry.
2256 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2259 struct cleanup
*old_chain
;
2265 warning ("psymtab for %s already read in. Shouldn't happen.",
2270 /* Read in all partial symtabs on which this one is dependent */
2271 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2273 if (!pst
->dependencies
[i
]->readin
)
2275 /* Inform about additional files that need to be read in. */
2278 fputs_filtered (" ", gdb_stdout
);
2280 fputs_filtered ("and ", gdb_stdout
);
2282 printf_filtered ("%s...",
2283 pst
->dependencies
[i
]->filename
);
2285 gdb_flush (gdb_stdout
); /* Flush output */
2287 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2290 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
2293 old_chain
= make_cleanup (really_free_pendings
, 0);
2294 read_ofile_symtab (pst
);
2297 printf_filtered ("%d DIE's, sorting...", diecount
);
2299 gdb_flush (gdb_stdout
);
2301 sort_symtab_syms (pst
->symtab
);
2302 do_cleanups (old_chain
);
2313 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2317 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2321 This is the DWARF support entry point for building a full symbol
2322 table entry from a partial symbol table entry. We are passed a
2323 pointer to the partial symbol table entry that needs to be expanded.
2328 dwarf_psymtab_to_symtab (struct partial_symtab
*pst
)
2335 warning ("psymtab for %s already read in. Shouldn't happen.",
2340 if (DBLENGTH (pst
) || pst
->number_of_dependencies
)
2342 /* Print the message now, before starting serious work, to avoid
2343 disconcerting pauses. */
2346 printf_filtered ("Reading in symbols for %s...",
2348 gdb_flush (gdb_stdout
);
2351 psymtab_to_symtab_1 (pst
);
2353 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2354 we need to do an equivalent or is this something peculiar to
2356 Match with global symbols. This only needs to be done once,
2357 after all of the symtabs and dependencies have been read in.
2359 scan_file_globals (pst
->objfile
);
2362 /* Finish up the verbose info message. */
2365 printf_filtered ("done.\n");
2366 gdb_flush (gdb_stdout
);
2377 add_enum_psymbol -- add enumeration members to partial symbol table
2381 Given pointer to a DIE that is known to be for an enumeration,
2382 extract the symbolic names of the enumeration members and add
2383 partial symbols for them.
2387 add_enum_psymbol (struct dieinfo
*dip
, struct objfile
*objfile
)
2391 unsigned short blocksz
;
2394 if ((scan
= dip
->at_element_list
) != NULL
)
2396 if (dip
->short_element_list
)
2398 nbytes
= attribute_size (AT_short_element_list
);
2402 nbytes
= attribute_size (AT_element_list
);
2404 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
2406 listend
= scan
+ blocksz
;
2407 while (scan
< listend
)
2409 scan
+= TARGET_FT_LONG_SIZE (objfile
);
2410 add_psymbol_to_list (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2411 &objfile
->static_psymbols
, 0, 0, cu_language
,
2413 scan
+= strlen (scan
) + 1;
2422 add_partial_symbol -- add symbol to partial symbol table
2426 Given a DIE, if it is one of the types that we want to
2427 add to a partial symbol table, finish filling in the die info
2428 and then add a partial symbol table entry for it.
2432 The caller must ensure that the DIE has a valid name attribute.
2436 add_partial_symbol (struct dieinfo
*dip
, struct objfile
*objfile
)
2438 switch (dip
->die_tag
)
2440 case TAG_global_subroutine
:
2441 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2442 VAR_NAMESPACE
, LOC_BLOCK
,
2443 &objfile
->global_psymbols
,
2444 0, dip
->at_low_pc
, cu_language
, objfile
);
2446 case TAG_global_variable
:
2447 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2448 VAR_NAMESPACE
, LOC_STATIC
,
2449 &objfile
->global_psymbols
,
2450 0, 0, cu_language
, objfile
);
2452 case TAG_subroutine
:
2453 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2454 VAR_NAMESPACE
, LOC_BLOCK
,
2455 &objfile
->static_psymbols
,
2456 0, dip
->at_low_pc
, cu_language
, objfile
);
2458 case TAG_local_variable
:
2459 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2460 VAR_NAMESPACE
, LOC_STATIC
,
2461 &objfile
->static_psymbols
,
2462 0, 0, cu_language
, objfile
);
2465 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2466 VAR_NAMESPACE
, LOC_TYPEDEF
,
2467 &objfile
->static_psymbols
,
2468 0, 0, cu_language
, objfile
);
2470 case TAG_class_type
:
2471 case TAG_structure_type
:
2472 case TAG_union_type
:
2473 case TAG_enumeration_type
:
2474 /* Do not add opaque aggregate definitions to the psymtab. */
2475 if (!dip
->has_at_byte_size
)
2477 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2478 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2479 &objfile
->static_psymbols
,
2480 0, 0, cu_language
, objfile
);
2481 if (cu_language
== language_cplus
)
2483 /* For C++, these implicitly act as typedefs as well. */
2484 add_psymbol_to_list (dip
->at_name
, strlen (dip
->at_name
),
2485 VAR_NAMESPACE
, LOC_TYPEDEF
,
2486 &objfile
->static_psymbols
,
2487 0, 0, cu_language
, objfile
);
2497 scan_partial_symbols -- scan DIE's within a single compilation unit
2501 Process the DIE's within a single compilation unit, looking for
2502 interesting DIE's that contribute to the partial symbol table entry
2503 for this compilation unit.
2507 There are some DIE's that may appear both at file scope and within
2508 the scope of a function. We are only interested in the ones at file
2509 scope, and the only way to tell them apart is to keep track of the
2510 scope. For example, consider the test case:
2515 for which the relevant DWARF segment has the structure:
2518 0x23 global subrtn sibling 0x9b
2520 fund_type FT_integer
2525 0x23 local var sibling 0x97
2527 fund_type FT_integer
2528 location OP_BASEREG 0xe
2535 0x1d local var sibling 0xb8
2537 fund_type FT_integer
2538 location OP_ADDR 0x800025dc
2543 We want to include the symbol 'i' in the partial symbol table, but
2544 not the symbol 'j'. In essence, we want to skip all the dies within
2545 the scope of a TAG_global_subroutine DIE.
2547 Don't attempt to add anonymous structures or unions since they have
2548 no name. Anonymous enumerations however are processed, because we
2549 want to extract their member names (the check for a tag name is
2552 Also, for variables and subroutines, check that this is the place
2553 where the actual definition occurs, rather than just a reference
2561 scan_partial_symbols (char *thisdie
, char *enddie
, struct objfile
*objfile
)
2567 while (thisdie
< enddie
)
2569 basicdieinfo (&di
, thisdie
, objfile
);
2570 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2576 nextdie
= thisdie
+ di
.die_length
;
2577 /* To avoid getting complete die information for every die, we
2578 only do it (below) for the cases we are interested in. */
2581 case TAG_global_subroutine
:
2582 case TAG_subroutine
:
2583 completedieinfo (&di
, objfile
);
2584 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2586 add_partial_symbol (&di
, objfile
);
2587 /* If there is a sibling attribute, adjust the nextdie
2588 pointer to skip the entire scope of the subroutine.
2589 Apply some sanity checking to make sure we don't
2590 overrun or underrun the range of remaining DIE's */
2591 if (di
.at_sibling
!= 0)
2593 temp
= dbbase
+ di
.at_sibling
- dbroff
;
2594 if ((temp
< thisdie
) || (temp
>= enddie
))
2596 bad_die_ref_complaint (DIE_ID
, DIE_NAME
,
2606 case TAG_global_variable
:
2607 case TAG_local_variable
:
2608 completedieinfo (&di
, objfile
);
2609 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2611 add_partial_symbol (&di
, objfile
);
2615 case TAG_class_type
:
2616 case TAG_structure_type
:
2617 case TAG_union_type
:
2618 completedieinfo (&di
, objfile
);
2621 add_partial_symbol (&di
, objfile
);
2624 case TAG_enumeration_type
:
2625 completedieinfo (&di
, objfile
);
2628 add_partial_symbol (&di
, objfile
);
2630 add_enum_psymbol (&di
, objfile
);
2642 scan_compilation_units -- build a psymtab entry for each compilation
2646 This is the top level dwarf parsing routine for building partial
2649 It scans from the beginning of the DWARF table looking for the first
2650 TAG_compile_unit DIE, and then follows the sibling chain to locate
2651 each additional TAG_compile_unit DIE.
2653 For each TAG_compile_unit DIE it creates a partial symtab structure,
2654 calls a subordinate routine to collect all the compilation unit's
2655 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2656 new partial symtab structure into the partial symbol table. It also
2657 records the appropriate information in the partial symbol table entry
2658 to allow the chunk of DIE's and line number table for this compilation
2659 unit to be located and re-read later, to generate a complete symbol
2660 table entry for the compilation unit.
2662 Thus it effectively partitions up a chunk of DIE's for multiple
2663 compilation units into smaller DIE chunks and line number tables,
2664 and associates them with a partial symbol table entry.
2668 If any compilation unit has no line number table associated with
2669 it for some reason (a missing at_stmt_list attribute, rather than
2670 just one with a value of zero, which is valid) then we ensure that
2671 the recorded file offset is zero so that the routine which later
2672 reads line number table fragments knows that there is no fragment
2682 scan_compilation_units (char *thisdie
, char *enddie
, file_ptr dbfoff
,
2683 file_ptr lnoffset
, struct objfile
*objfile
)
2687 struct partial_symtab
*pst
;
2690 file_ptr curlnoffset
;
2692 while (thisdie
< enddie
)
2694 basicdieinfo (&di
, thisdie
, objfile
);
2695 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2699 else if (di
.die_tag
!= TAG_compile_unit
)
2701 nextdie
= thisdie
+ di
.die_length
;
2705 completedieinfo (&di
, objfile
);
2706 set_cu_language (&di
);
2707 if (di
.at_sibling
!= 0)
2709 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2713 nextdie
= thisdie
+ di
.die_length
;
2715 curoff
= thisdie
- dbbase
;
2716 culength
= nextdie
- thisdie
;
2717 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2719 /* First allocate a new partial symbol table structure */
2721 pst
= start_psymtab_common (objfile
, base_section_offsets
,
2722 di
.at_name
, di
.at_low_pc
,
2723 objfile
->global_psymbols
.next
,
2724 objfile
->static_psymbols
.next
);
2726 pst
->texthigh
= di
.at_high_pc
;
2727 pst
->read_symtab_private
= (char *)
2728 obstack_alloc (&objfile
->psymbol_obstack
,
2729 sizeof (struct dwfinfo
));
2730 DBFOFF (pst
) = dbfoff
;
2731 DBROFF (pst
) = curoff
;
2732 DBLENGTH (pst
) = culength
;
2733 LNFOFF (pst
) = curlnoffset
;
2734 pst
->read_symtab
= dwarf_psymtab_to_symtab
;
2736 /* Now look for partial symbols */
2738 scan_partial_symbols (thisdie
+ di
.die_length
, nextdie
, objfile
);
2740 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2741 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2742 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2743 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2744 sort_pst_symbols (pst
);
2745 /* If there is already a psymtab or symtab for a file of this name,
2746 remove it. (If there is a symtab, more drastic things also
2747 happen.) This happens in VxWorks. */
2748 free_named_symtabs (pst
->filename
);
2758 new_symbol -- make a symbol table entry for a new symbol
2762 static struct symbol *new_symbol (struct dieinfo *dip,
2763 struct objfile *objfile)
2767 Given a pointer to a DWARF information entry, figure out if we need
2768 to make a symbol table entry for it, and if so, create a new entry
2769 and return a pointer to it.
2772 static struct symbol
*
2773 new_symbol (struct dieinfo
*dip
, struct objfile
*objfile
)
2775 struct symbol
*sym
= NULL
;
2777 if (dip
->at_name
!= NULL
)
2779 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
2780 sizeof (struct symbol
));
2781 OBJSTAT (objfile
, n_syms
++);
2782 memset (sym
, 0, sizeof (struct symbol
));
2783 /* default assumptions */
2784 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2785 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2786 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2788 /* If this symbol is from a C++ compilation, then attempt to cache the
2789 demangled form for future reference. This is a typical time versus
2790 space tradeoff, that was decided in favor of time because it sped up
2791 C++ symbol lookups by a factor of about 20. */
2793 SYMBOL_LANGUAGE (sym
) = cu_language
;
2794 SYMBOL_SET_NAMES (sym
, dip
->at_name
, strlen (dip
->at_name
), objfile
);
2795 switch (dip
->die_tag
)
2798 SYMBOL_VALUE_ADDRESS (sym
) = dip
->at_low_pc
;
2799 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2801 case TAG_global_subroutine
:
2802 case TAG_subroutine
:
2803 SYMBOL_VALUE_ADDRESS (sym
) = dip
->at_low_pc
;
2804 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2805 if (dip
->at_prototyped
)
2806 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
2807 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2808 if (dip
->die_tag
== TAG_global_subroutine
)
2810 add_symbol_to_list (sym
, &global_symbols
);
2814 add_symbol_to_list (sym
, list_in_scope
);
2817 case TAG_global_variable
:
2818 if (dip
->at_location
!= NULL
)
2820 SYMBOL_VALUE_ADDRESS (sym
) = locval (dip
);
2821 add_symbol_to_list (sym
, &global_symbols
);
2822 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2823 SYMBOL_VALUE (sym
) += baseaddr
;
2826 case TAG_local_variable
:
2827 if (dip
->at_location
!= NULL
)
2829 int loc
= locval (dip
);
2830 if (dip
->optimized_out
)
2832 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
2834 else if (dip
->isreg
)
2836 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2838 else if (dip
->offreg
)
2840 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
2841 SYMBOL_BASEREG (sym
) = dip
->basereg
;
2845 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2846 SYMBOL_VALUE (sym
) += baseaddr
;
2848 if (SYMBOL_CLASS (sym
) == LOC_STATIC
)
2850 /* LOC_STATIC address class MUST use SYMBOL_VALUE_ADDRESS,
2851 which may store to a bigger location than SYMBOL_VALUE. */
2852 SYMBOL_VALUE_ADDRESS (sym
) = loc
;
2856 SYMBOL_VALUE (sym
) = loc
;
2858 add_symbol_to_list (sym
, list_in_scope
);
2861 case TAG_formal_parameter
:
2862 if (dip
->at_location
!= NULL
)
2864 SYMBOL_VALUE (sym
) = locval (dip
);
2866 add_symbol_to_list (sym
, list_in_scope
);
2869 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2871 else if (dip
->offreg
)
2873 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
2874 SYMBOL_BASEREG (sym
) = dip
->basereg
;
2878 SYMBOL_CLASS (sym
) = LOC_ARG
;
2881 case TAG_unspecified_parameters
:
2882 /* From varargs functions; gdb doesn't seem to have any interest in
2883 this information, so just ignore it for now. (FIXME?) */
2885 case TAG_class_type
:
2886 case TAG_structure_type
:
2887 case TAG_union_type
:
2888 case TAG_enumeration_type
:
2889 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2890 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2891 add_symbol_to_list (sym
, list_in_scope
);
2894 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2895 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2896 add_symbol_to_list (sym
, list_in_scope
);
2899 /* Not a tag we recognize. Hopefully we aren't processing trash
2900 data, but since we must specifically ignore things we don't
2901 recognize, there is nothing else we should do at this point. */
2912 synthesize_typedef -- make a symbol table entry for a "fake" typedef
2916 static void synthesize_typedef (struct dieinfo *dip,
2917 struct objfile *objfile,
2922 Given a pointer to a DWARF information entry, synthesize a typedef
2923 for the name in the DIE, using the specified type.
2925 This is used for C++ class, structs, unions, and enumerations to
2926 set up the tag name as a type.
2931 synthesize_typedef (struct dieinfo
*dip
, struct objfile
*objfile
,
2934 struct symbol
*sym
= NULL
;
2936 if (dip
->at_name
!= NULL
)
2938 sym
= (struct symbol
*)
2939 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2940 OBJSTAT (objfile
, n_syms
++);
2941 memset (sym
, 0, sizeof (struct symbol
));
2942 SYMBOL_NAME (sym
) = create_name (dip
->at_name
,
2943 &objfile
->symbol_obstack
);
2944 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym
, cu_language
);
2945 SYMBOL_TYPE (sym
) = type
;
2946 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2947 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2948 add_symbol_to_list (sym
, list_in_scope
);
2956 decode_mod_fund_type -- decode a modified fundamental type
2960 static struct type *decode_mod_fund_type (char *typedata)
2964 Decode a block of data containing a modified fundamental
2965 type specification. TYPEDATA is a pointer to the block,
2966 which starts with a length containing the size of the rest
2967 of the block. At the end of the block is a fundmental type
2968 code value that gives the fundamental type. Everything
2969 in between are type modifiers.
2971 We simply compute the number of modifiers and call the general
2972 function decode_modified_type to do the actual work.
2975 static struct type
*
2976 decode_mod_fund_type (char *typedata
)
2978 struct type
*typep
= NULL
;
2979 unsigned short modcount
;
2982 /* Get the total size of the block, exclusive of the size itself */
2984 nbytes
= attribute_size (AT_mod_fund_type
);
2985 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
2988 /* Deduct the size of the fundamental type bytes at the end of the block. */
2990 modcount
-= attribute_size (AT_fund_type
);
2992 /* Now do the actual decoding */
2994 typep
= decode_modified_type (typedata
, modcount
, AT_mod_fund_type
);
3002 decode_mod_u_d_type -- decode a modified user defined type
3006 static struct type *decode_mod_u_d_type (char *typedata)
3010 Decode a block of data containing a modified user defined
3011 type specification. TYPEDATA is a pointer to the block,
3012 which consists of a two byte length, containing the size
3013 of the rest of the block. At the end of the block is a
3014 four byte value that gives a reference to a user defined type.
3015 Everything in between are type modifiers.
3017 We simply compute the number of modifiers and call the general
3018 function decode_modified_type to do the actual work.
3021 static struct type
*
3022 decode_mod_u_d_type (char *typedata
)
3024 struct type
*typep
= NULL
;
3025 unsigned short modcount
;
3028 /* Get the total size of the block, exclusive of the size itself */
3030 nbytes
= attribute_size (AT_mod_u_d_type
);
3031 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
3034 /* Deduct the size of the reference type bytes at the end of the block. */
3036 modcount
-= attribute_size (AT_user_def_type
);
3038 /* Now do the actual decoding */
3040 typep
= decode_modified_type (typedata
, modcount
, AT_mod_u_d_type
);
3048 decode_modified_type -- decode modified user or fundamental type
3052 static struct type *decode_modified_type (char *modifiers,
3053 unsigned short modcount, int mtype)
3057 Decode a modified type, either a modified fundamental type or
3058 a modified user defined type. MODIFIERS is a pointer to the
3059 block of bytes that define MODCOUNT modifiers. Immediately
3060 following the last modifier is a short containing the fundamental
3061 type or a long containing the reference to the user defined
3062 type. Which one is determined by MTYPE, which is either
3063 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
3064 type we are generating.
3066 We call ourself recursively to generate each modified type,`
3067 until MODCOUNT reaches zero, at which point we have consumed
3068 all the modifiers and generate either the fundamental type or
3069 user defined type. When the recursion unwinds, each modifier
3070 is applied in turn to generate the full modified type.
3074 If we find a modifier that we don't recognize, and it is not one
3075 of those reserved for application specific use, then we issue a
3076 warning and simply ignore the modifier.
3080 We currently ignore MOD_const and MOD_volatile. (FIXME)
3084 static struct type
*
3085 decode_modified_type (char *modifiers
, unsigned int modcount
, int mtype
)
3087 struct type
*typep
= NULL
;
3088 unsigned short fundtype
;
3097 case AT_mod_fund_type
:
3098 nbytes
= attribute_size (AT_fund_type
);
3099 fundtype
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
3101 typep
= decode_fund_type (fundtype
);
3103 case AT_mod_u_d_type
:
3104 nbytes
= attribute_size (AT_user_def_type
);
3105 die_ref
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
3107 if ((typep
= lookup_utype (die_ref
)) == NULL
)
3109 typep
= alloc_utype (die_ref
, NULL
);
3113 complaint (&symfile_complaints
,
3114 "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)",
3115 DIE_ID
, DIE_NAME
, mtype
);
3116 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
3122 modifier
= *modifiers
++;
3123 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
3126 case MOD_pointer_to
:
3127 typep
= lookup_pointer_type (typep
);
3129 case MOD_reference_to
:
3130 typep
= lookup_reference_type (typep
);
3133 complaint (&symfile_complaints
,
3134 "DIE @ 0x%x \"%s\", type modifier 'const' ignored", DIE_ID
,
3135 DIE_NAME
); /* FIXME */
3138 complaint (&symfile_complaints
,
3139 "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored",
3140 DIE_ID
, DIE_NAME
); /* FIXME */
3143 if (!(MOD_lo_user
<= (unsigned char) modifier
3144 && (unsigned char) modifier
<= MOD_hi_user
))
3146 complaint (&symfile_complaints
,
3147 "DIE @ 0x%x \"%s\", unknown type modifier %u", DIE_ID
,
3148 DIE_NAME
, modifier
);
3160 decode_fund_type -- translate basic DWARF type to gdb base type
3164 Given an integer that is one of the fundamental DWARF types,
3165 translate it to one of the basic internal gdb types and return
3166 a pointer to the appropriate gdb type (a "struct type *").
3170 For robustness, if we are asked to translate a fundamental
3171 type that we are unprepared to deal with, we return int so
3172 callers can always depend upon a valid type being returned,
3173 and so gdb may at least do something reasonable by default.
3174 If the type is not in the range of those types defined as
3175 application specific types, we also issue a warning.
3178 static struct type
*
3179 decode_fund_type (unsigned int fundtype
)
3181 struct type
*typep
= NULL
;
3187 typep
= dwarf_fundamental_type (current_objfile
, FT_VOID
);
3190 case FT_boolean
: /* Was FT_set in AT&T version */
3191 typep
= dwarf_fundamental_type (current_objfile
, FT_BOOLEAN
);
3194 case FT_pointer
: /* (void *) */
3195 typep
= dwarf_fundamental_type (current_objfile
, FT_VOID
);
3196 typep
= lookup_pointer_type (typep
);
3200 typep
= dwarf_fundamental_type (current_objfile
, FT_CHAR
);
3203 case FT_signed_char
:
3204 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
3207 case FT_unsigned_char
:
3208 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
3212 typep
= dwarf_fundamental_type (current_objfile
, FT_SHORT
);
3215 case FT_signed_short
:
3216 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
3219 case FT_unsigned_short
:
3220 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
3224 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
3227 case FT_signed_integer
:
3228 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
3231 case FT_unsigned_integer
:
3232 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
3236 typep
= dwarf_fundamental_type (current_objfile
, FT_LONG
);
3239 case FT_signed_long
:
3240 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
3243 case FT_unsigned_long
:
3244 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
3248 typep
= dwarf_fundamental_type (current_objfile
, FT_LONG_LONG
);
3251 case FT_signed_long_long
:
3252 typep
= dwarf_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
3255 case FT_unsigned_long_long
:
3256 typep
= dwarf_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
3260 typep
= dwarf_fundamental_type (current_objfile
, FT_FLOAT
);
3263 case FT_dbl_prec_float
:
3264 typep
= dwarf_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
3267 case FT_ext_prec_float
:
3268 typep
= dwarf_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
3272 typep
= dwarf_fundamental_type (current_objfile
, FT_COMPLEX
);
3275 case FT_dbl_prec_complex
:
3276 typep
= dwarf_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
3279 case FT_ext_prec_complex
:
3280 typep
= dwarf_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
3287 typep
= dwarf_fundamental_type (current_objfile
, FT_INTEGER
);
3288 if (!(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
3290 complaint (&symfile_complaints
,
3291 "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x",
3292 DIE_ID
, DIE_NAME
, fundtype
);
3303 create_name -- allocate a fresh copy of a string on an obstack
3307 Given a pointer to a string and a pointer to an obstack, allocates
3308 a fresh copy of the string on the specified obstack.
3313 create_name (char *name
, struct obstack
*obstackp
)
3318 length
= strlen (name
) + 1;
3319 newname
= (char *) obstack_alloc (obstackp
, length
);
3320 strcpy (newname
, name
);
3328 basicdieinfo -- extract the minimal die info from raw die data
3332 void basicdieinfo (char *diep, struct dieinfo *dip,
3333 struct objfile *objfile)
3337 Given a pointer to raw DIE data, and a pointer to an instance of a
3338 die info structure, this function extracts the basic information
3339 from the DIE data required to continue processing this DIE, along
3340 with some bookkeeping information about the DIE.
3342 The information we absolutely must have includes the DIE tag,
3343 and the DIE length. If we need the sibling reference, then we
3344 will have to call completedieinfo() to process all the remaining
3347 Note that since there is no guarantee that the data is properly
3348 aligned in memory for the type of access required (indirection
3349 through anything other than a char pointer), and there is no
3350 guarantee that it is in the same byte order as the gdb host,
3351 we call a function which deals with both alignment and byte
3352 swapping issues. Possibly inefficient, but quite portable.
3354 We also take care of some other basic things at this point, such
3355 as ensuring that the instance of the die info structure starts
3356 out completely zero'd and that curdie is initialized for use
3357 in error reporting if we have a problem with the current die.
3361 All DIE's must have at least a valid length, thus the minimum
3362 DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the
3363 DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
3364 are forced to be TAG_padding DIES.
3366 Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
3367 that if a padding DIE is used for alignment and the amount needed is
3368 less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
3369 enough to align to the next alignment boundry.
3371 We do some basic sanity checking here, such as verifying that the
3372 length of the die would not cause it to overrun the recorded end of
3373 the buffer holding the DIE info. If we find a DIE that is either
3374 too small or too large, we force it's length to zero which should
3375 cause the caller to take appropriate action.
3379 basicdieinfo (struct dieinfo
*dip
, char *diep
, struct objfile
*objfile
)
3382 memset (dip
, 0, sizeof (struct dieinfo
));
3384 dip
->die_ref
= dbroff
+ (diep
- dbbase
);
3385 dip
->die_length
= target_to_host (diep
, SIZEOF_DIE_LENGTH
, GET_UNSIGNED
,
3387 if ((dip
->die_length
< SIZEOF_DIE_LENGTH
) ||
3388 ((diep
+ dip
->die_length
) > (dbbase
+ dbsize
)))
3390 complaint (&symfile_complaints
,
3391 "DIE @ 0x%x \"%s\", malformed DIE, bad length (%ld bytes)",
3392 DIE_ID
, DIE_NAME
, dip
->die_length
);
3393 dip
->die_length
= 0;
3395 else if (dip
->die_length
< (SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
))
3397 dip
->die_tag
= TAG_padding
;
3401 diep
+= SIZEOF_DIE_LENGTH
;
3402 dip
->die_tag
= target_to_host (diep
, SIZEOF_DIE_TAG
, GET_UNSIGNED
,
3411 completedieinfo -- finish reading the information for a given DIE
3415 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3419 Given a pointer to an already partially initialized die info structure,
3420 scan the raw DIE data and finish filling in the die info structure
3421 from the various attributes found.
3423 Note that since there is no guarantee that the data is properly
3424 aligned in memory for the type of access required (indirection
3425 through anything other than a char pointer), and there is no
3426 guarantee that it is in the same byte order as the gdb host,
3427 we call a function which deals with both alignment and byte
3428 swapping issues. Possibly inefficient, but quite portable.
3432 Each time we are called, we increment the diecount variable, which
3433 keeps an approximate count of the number of dies processed for
3434 each compilation unit. This information is presented to the user
3435 if the info_verbose flag is set.
3440 completedieinfo (struct dieinfo
*dip
, struct objfile
*objfile
)
3442 char *diep
; /* Current pointer into raw DIE data */
3443 char *end
; /* Terminate DIE scan here */
3444 unsigned short attr
; /* Current attribute being scanned */
3445 unsigned short form
; /* Form of the attribute */
3446 int nbytes
; /* Size of next field to read */
3450 end
= diep
+ dip
->die_length
;
3451 diep
+= SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
;
3454 attr
= target_to_host (diep
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
, objfile
);
3455 diep
+= SIZEOF_ATTRIBUTE
;
3456 if ((nbytes
= attribute_size (attr
)) == -1)
3458 complaint (&symfile_complaints
,
3459 "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes",
3467 dip
->at_fund_type
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3471 dip
->at_ordering
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3475 dip
->at_bit_offset
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3479 dip
->at_sibling
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3483 dip
->at_stmt_list
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3485 dip
->has_at_stmt_list
= 1;
3488 dip
->at_low_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3490 dip
->at_low_pc
+= baseaddr
;
3491 dip
->has_at_low_pc
= 1;
3494 dip
->at_high_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3496 dip
->at_high_pc
+= baseaddr
;
3499 dip
->at_language
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3502 case AT_user_def_type
:
3503 dip
->at_user_def_type
= target_to_host (diep
, nbytes
,
3504 GET_UNSIGNED
, objfile
);
3507 dip
->at_byte_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3509 dip
->has_at_byte_size
= 1;
3512 dip
->at_bit_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3516 dip
->at_member
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3520 dip
->at_discr
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3524 dip
->at_location
= diep
;
3526 case AT_mod_fund_type
:
3527 dip
->at_mod_fund_type
= diep
;
3529 case AT_subscr_data
:
3530 dip
->at_subscr_data
= diep
;
3532 case AT_mod_u_d_type
:
3533 dip
->at_mod_u_d_type
= diep
;
3535 case AT_element_list
:
3536 dip
->at_element_list
= diep
;
3537 dip
->short_element_list
= 0;
3539 case AT_short_element_list
:
3540 dip
->at_element_list
= diep
;
3541 dip
->short_element_list
= 1;
3543 case AT_discr_value
:
3544 dip
->at_discr_value
= diep
;
3546 case AT_string_length
:
3547 dip
->at_string_length
= diep
;
3550 dip
->at_name
= diep
;
3553 /* For now, ignore any "hostname:" portion, since gdb doesn't
3554 know how to deal with it. (FIXME). */
3555 dip
->at_comp_dir
= strrchr (diep
, ':');
3556 if (dip
->at_comp_dir
!= NULL
)
3562 dip
->at_comp_dir
= diep
;
3566 dip
->at_producer
= diep
;
3568 case AT_start_scope
:
3569 dip
->at_start_scope
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3572 case AT_stride_size
:
3573 dip
->at_stride_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3577 dip
->at_src_info
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3581 dip
->at_prototyped
= diep
;
3584 /* Found an attribute that we are unprepared to handle. However
3585 it is specifically one of the design goals of DWARF that
3586 consumers should ignore unknown attributes. As long as the
3587 form is one that we recognize (so we know how to skip it),
3588 we can just ignore the unknown attribute. */
3591 form
= FORM_FROM_ATTR (attr
);
3605 diep
+= TARGET_FT_POINTER_SIZE (objfile
);
3608 diep
+= 2 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3611 diep
+= 4 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3614 diep
+= strlen (diep
) + 1;
3617 unknown_attribute_form_complaint (DIE_ID
, DIE_NAME
, form
);
3628 target_to_host -- swap in target data to host
3632 target_to_host (char *from, int nbytes, int signextend,
3633 struct objfile *objfile)
3637 Given pointer to data in target format in FROM, a byte count for
3638 the size of the data in NBYTES, a flag indicating whether or not
3639 the data is signed in SIGNEXTEND, and a pointer to the current
3640 objfile in OBJFILE, convert the data to host format and return
3641 the converted value.
3645 FIXME: If we read data that is known to be signed, and expect to
3646 use it as signed data, then we need to explicitly sign extend the
3647 result until the bfd library is able to do this for us.
3649 FIXME: Would a 32 bit target ever need an 8 byte result?
3654 target_to_host (char *from
, int nbytes
, int signextend
, /* FIXME: Unused */
3655 struct objfile
*objfile
)
3662 rtnval
= bfd_get_64 (objfile
->obfd
, (bfd_byte
*) from
);
3665 rtnval
= bfd_get_32 (objfile
->obfd
, (bfd_byte
*) from
);
3668 rtnval
= bfd_get_16 (objfile
->obfd
, (bfd_byte
*) from
);
3671 rtnval
= bfd_get_8 (objfile
->obfd
, (bfd_byte
*) from
);
3674 complaint (&symfile_complaints
,
3675 "DIE @ 0x%x \"%s\", no bfd support for %d byte data object",
3676 DIE_ID
, DIE_NAME
, nbytes
);
3687 attribute_size -- compute size of data for a DWARF attribute
3691 static int attribute_size (unsigned int attr)
3695 Given a DWARF attribute in ATTR, compute the size of the first
3696 piece of data associated with this attribute and return that
3699 Returns -1 for unrecognized attributes.
3704 attribute_size (unsigned int attr
)
3706 int nbytes
; /* Size of next data for this attribute */
3707 unsigned short form
; /* Form of the attribute */
3709 form
= FORM_FROM_ATTR (attr
);
3712 case FORM_STRING
: /* A variable length field is next */
3715 case FORM_DATA2
: /* Next 2 byte field is the data itself */
3716 case FORM_BLOCK2
: /* Next 2 byte field is a block length */
3719 case FORM_DATA4
: /* Next 4 byte field is the data itself */
3720 case FORM_BLOCK4
: /* Next 4 byte field is a block length */
3721 case FORM_REF
: /* Next 4 byte field is a DIE offset */
3724 case FORM_DATA8
: /* Next 8 byte field is the data itself */
3727 case FORM_ADDR
: /* Next field size is target sizeof(void *) */
3728 nbytes
= TARGET_FT_POINTER_SIZE (objfile
);
3731 unknown_attribute_form_complaint (DIE_ID
, DIE_NAME
, form
);