1 /* DWARF debugging format support for GDB.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
5 Written by Fred Fish at Cygnus Support. Portions based on dbxread.c,
6 mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 FIXME: Do we need to generate dependencies in partial symtabs?
27 (Perhaps we don't need to).
29 FIXME: Resolve minor differences between what information we put in the
30 partial symbol table and what dbxread puts in. For example, we don't yet
31 put enum constants there. And dbxread seems to invent a lot of typedefs
32 we never see. Use the new printpsym command to see the partial symbol table
35 FIXME: Figure out a better way to tell gdb about the name of the function
36 contain the user's entry point (I.E. main())
38 FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
39 other things to work on, if you get bored. :-)
48 #include "elf/dwarf.h"
51 #include "expression.h" /* Needed for enum exp_opcode in language.h, sigh... */
53 #include "complaints.h"
56 #include "gdb_string.h"
58 /* Some macros to provide DIE info for complaints. */
60 #define DIE_ID (curdie!=NULL ? curdie->die_ref : 0)
61 #define DIE_NAME (curdie!=NULL && curdie->at_name!=NULL) ? curdie->at_name : ""
63 /* Complaints that can be issued during DWARF debug info reading. */
66 bad_die_ref_complaint (int arg1, const char *arg2, int arg3)
68 complaint (&symfile_complaints,
69 "DIE @ 0x%x \"%s\", reference to DIE (0x%x) outside compilation unit",
74 unknown_attribute_form_complaint (int arg1, const char *arg2, int arg3)
76 complaint (&symfile_complaints,
77 "DIE @ 0x%x \"%s\", unknown attribute form (0x%x)", arg1, arg2,
82 dup_user_type_definition_complaint (int arg1, const char *arg2)
84 complaint (&symfile_complaints,
85 "DIE @ 0x%x \"%s\", internal error: duplicate user type definition",
90 bad_array_element_type_complaint (int arg1, const char *arg2, int arg3)
92 complaint (&symfile_complaints,
93 "DIE @ 0x%x \"%s\", bad array element type attribute 0x%x", arg1,
97 typedef unsigned int DIE_REF; /* Reference to a DIE */
100 #define GCC_PRODUCER "GNU C "
103 #ifndef GPLUS_PRODUCER
104 #define GPLUS_PRODUCER "GNU C++ "
108 #define LCC_PRODUCER "NCR C/C++"
111 /* Flags to target_to_host() that tell whether or not the data object is
112 expected to be signed. Used, for example, when fetching a signed
113 integer in the target environment which is used as a signed integer
114 in the host environment, and the two environments have different sized
115 ints. In this case, *somebody* has to sign extend the smaller sized
118 #define GET_UNSIGNED 0 /* No sign extension required */
119 #define GET_SIGNED 1 /* Sign extension required */
121 /* Defines for things which are specified in the document "DWARF Debugging
122 Information Format" published by UNIX International, Programming Languages
123 SIG. These defines are based on revision 1.0.0, Jan 20, 1992. */
125 #define SIZEOF_DIE_LENGTH 4
126 #define SIZEOF_DIE_TAG 2
127 #define SIZEOF_ATTRIBUTE 2
128 #define SIZEOF_FORMAT_SPECIFIER 1
129 #define SIZEOF_FMT_FT 2
130 #define SIZEOF_LINETBL_LENGTH 4
131 #define SIZEOF_LINETBL_LINENO 4
132 #define SIZEOF_LINETBL_STMT 2
133 #define SIZEOF_LINETBL_DELTA 4
134 #define SIZEOF_LOC_ATOM_CODE 1
136 #define FORM_FROM_ATTR(attr) ((attr) & 0xF) /* Implicitly specified */
138 /* Macros that return the sizes of various types of data in the target
141 FIXME: Currently these are just compile time constants (as they are in
142 other parts of gdb as well). They need to be able to get the right size
143 either from the bfd or possibly from the DWARF info. It would be nice if
144 the DWARF producer inserted DIES that describe the fundamental types in
145 the target environment into the DWARF info, similar to the way dbx stabs
146 producers produce information about their fundamental types. */
148 #define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
149 #define TARGET_FT_LONG_SIZE(objfile) (TARGET_LONG_BIT / TARGET_CHAR_BIT)
151 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
152 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
153 However, the Issue 2 DWARF specification from AT&T defines it as
154 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
155 For backwards compatibility with the AT&T compiler produced executables
156 we define AT_short_element_list for this variant. */
158 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
160 /* The DWARF debugging information consists of two major pieces,
161 one is a block of DWARF Information Entries (DIE's) and the other
162 is a line number table. The "struct dieinfo" structure contains
163 the information for a single DIE, the one currently being processed.
165 In order to make it easier to randomly access the attribute fields
166 of the current DIE, which are specifically unordered within the DIE,
167 each DIE is scanned and an instance of the "struct dieinfo"
168 structure is initialized.
170 Initialization is done in two levels. The first, done by basicdieinfo(),
171 just initializes those fields that are vital to deciding whether or not
172 to use this DIE, how to skip past it, etc. The second, done by the
173 function completedieinfo(), fills in the rest of the information.
175 Attributes which have block forms are not interpreted at the time
176 the DIE is scanned, instead we just save pointers to the start
177 of their value fields.
179 Some fields have a flag <name>_p that is set when the value of the
180 field is valid (I.E. we found a matching attribute in the DIE). Since
181 we may want to test for the presence of some attributes in the DIE,
182 such as AT_low_pc, without restricting the values of the field,
183 we need someway to note that we found such an attribute.
191 char *die; /* Pointer to the raw DIE data */
192 unsigned long die_length; /* Length of the raw DIE data */
193 DIE_REF die_ref; /* Offset of this DIE */
194 unsigned short die_tag; /* Tag for this DIE */
195 unsigned long at_padding;
196 unsigned long at_sibling;
199 unsigned short at_fund_type;
200 BLOCK *at_mod_fund_type;
201 unsigned long at_user_def_type;
202 BLOCK *at_mod_u_d_type;
203 unsigned short at_ordering;
204 BLOCK *at_subscr_data;
205 unsigned long at_byte_size;
206 unsigned short at_bit_offset;
207 unsigned long at_bit_size;
208 BLOCK *at_element_list;
209 unsigned long at_stmt_list;
211 CORE_ADDR at_high_pc;
212 unsigned long at_language;
213 unsigned long at_member;
214 unsigned long at_discr;
215 BLOCK *at_discr_value;
216 BLOCK *at_string_length;
219 unsigned long at_start_scope;
220 unsigned long at_stride_size;
221 unsigned long at_src_info;
223 unsigned int has_at_low_pc:1;
224 unsigned int has_at_stmt_list:1;
225 unsigned int has_at_byte_size:1;
226 unsigned int short_element_list:1;
228 /* Kludge to identify register variables */
232 /* Kludge to identify optimized out variables */
234 unsigned int optimized_out;
236 /* Kludge to identify basereg references.
237 Nonzero if we have an offset relative to a basereg. */
241 /* Kludge to identify which base register is it relative to. */
243 unsigned int basereg;
246 static int diecount; /* Approximate count of dies for compilation unit */
247 static struct dieinfo *curdie; /* For warnings and such */
249 static char *dbbase; /* Base pointer to dwarf info */
250 static int dbsize; /* Size of dwarf info in bytes */
251 static int dbroff; /* Relative offset from start of .debug section */
252 static char *lnbase; /* Base pointer to line section */
254 /* This value is added to each symbol value. FIXME: Generalize to
255 the section_offsets structure used by dbxread (once this is done,
256 pass the appropriate section number to end_symtab). */
257 static CORE_ADDR baseaddr; /* Add to each symbol value */
259 /* The section offsets used in the current psymtab or symtab. FIXME,
260 only used to pass one value (baseaddr) at the moment. */
261 static struct section_offsets *base_section_offsets;
263 /* We put a pointer to this structure in the read_symtab_private field
268 /* Always the absolute file offset to the start of the ".debug"
269 section for the file containing the DIE's being accessed. */
271 /* Relative offset from the start of the ".debug" section to the
272 first DIE to be accessed. When building the partial symbol
273 table, this value will be zero since we are accessing the
274 entire ".debug" section. When expanding a partial symbol
275 table entry, this value will be the offset to the first
276 DIE for the compilation unit containing the symbol that
277 triggers the expansion. */
279 /* The size of the chunk of DIE's being examined, in bytes. */
281 /* The absolute file offset to the line table fragment. Ignored
282 when building partial symbol tables, but used when expanding
283 them, and contains the absolute file offset to the fragment
284 of the ".line" section containing the line numbers for the
285 current compilation unit. */
289 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
290 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
291 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
292 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
294 /* The generic symbol table building routines have separate lists for
295 file scope symbols and all all other scopes (local scopes). So
296 we need to select the right one to pass to add_symbol_to_list().
297 We do it by keeping a pointer to the correct list in list_in_scope.
299 FIXME: The original dwarf code just treated the file scope as the first
300 local scope, and all other local scopes as nested local scopes, and worked
301 fine. Check to see if we really need to distinguish these in buildsym.c */
303 struct pending **list_in_scope = &file_symbols;
305 /* DIES which have user defined types or modified user defined types refer to
306 other DIES for the type information. Thus we need to associate the offset
307 of a DIE for a user defined type with a pointer to the type information.
309 Originally this was done using a simple but expensive algorithm, with an
310 array of unsorted structures, each containing an offset/type-pointer pair.
311 This array was scanned linearly each time a lookup was done. The result
312 was that gdb was spending over half it's startup time munging through this
313 array of pointers looking for a structure that had the right offset member.
315 The second attempt used the same array of structures, but the array was
316 sorted using qsort each time a new offset/type was recorded, and a binary
317 search was used to find the type pointer for a given DIE offset. This was
318 even slower, due to the overhead of sorting the array each time a new
319 offset/type pair was entered.
321 The third attempt uses a fixed size array of type pointers, indexed by a
322 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
323 we can divide any DIE offset by 4 to obtain a unique index into this fixed
324 size array. Since each element is a 4 byte pointer, it takes exactly as
325 much memory to hold this array as to hold the DWARF info for a given
326 compilation unit. But it gets freed as soon as we are done with it.
327 This has worked well in practice, as a reasonable tradeoff between memory
328 consumption and speed, without having to resort to much more complicated
331 static struct type **utypes; /* Pointer to array of user type pointers */
332 static int numutypes; /* Max number of user type pointers */
334 /* Maintain an array of referenced fundamental types for the current
335 compilation unit being read. For DWARF version 1, we have to construct
336 the fundamental types on the fly, since no information about the
337 fundamental types is supplied. Each such fundamental type is created by
338 calling a language dependent routine to create the type, and then a
339 pointer to that type is then placed in the array at the index specified
340 by it's FT_<TYPENAME> value. The array has a fixed size set by the
341 FT_NUM_MEMBERS compile time constant, which is the number of predefined
342 fundamental types gdb knows how to construct. */
344 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
346 /* Record the language for the compilation unit which is currently being
347 processed. We know it once we have seen the TAG_compile_unit DIE,
348 and we need it while processing the DIE's for that compilation unit.
349 It is eventually saved in the symtab structure, but we don't finalize
350 the symtab struct until we have processed all the DIE's for the
351 compilation unit. We also need to get and save a pointer to the
352 language struct for this language, so we can call the language
353 dependent routines for doing things such as creating fundamental
356 static enum language cu_language;
357 static const struct language_defn *cu_language_defn;
359 /* Forward declarations of static functions so we don't have to worry
360 about ordering within this file. */
362 static void free_utypes (PTR);
364 static int attribute_size (unsigned int);
366 static CORE_ADDR target_to_host (char *, int, int, struct objfile *);
368 static void add_enum_psymbol (struct dieinfo *, struct objfile *);
370 static void handle_producer (char *);
373 read_file_scope (struct dieinfo *, char *, char *, struct objfile *);
376 read_func_scope (struct dieinfo *, char *, char *, struct objfile *);
379 read_lexical_block_scope (struct dieinfo *, char *, char *, struct objfile *);
381 static void scan_partial_symbols (char *, char *, struct objfile *);
384 scan_compilation_units (char *, char *, file_ptr, file_ptr, struct objfile *);
386 static void add_partial_symbol (struct dieinfo *, struct objfile *);
388 static void basicdieinfo (struct dieinfo *, char *, struct objfile *);
390 static void completedieinfo (struct dieinfo *, struct objfile *);
392 static void dwarf_psymtab_to_symtab (struct partial_symtab *);
394 static void psymtab_to_symtab_1 (struct partial_symtab *);
396 static void read_ofile_symtab (struct partial_symtab *);
398 static void process_dies (char *, char *, struct objfile *);
401 read_structure_scope (struct dieinfo *, char *, char *, struct objfile *);
403 static struct type *decode_array_element_type (char *);
405 static struct type *decode_subscript_data_item (char *, char *);
407 static void dwarf_read_array_type (struct dieinfo *);
409 static void read_tag_pointer_type (struct dieinfo *dip);
411 static void read_tag_string_type (struct dieinfo *dip);
413 static void read_subroutine_type (struct dieinfo *, char *, char *);
416 read_enumeration (struct dieinfo *, char *, char *, struct objfile *);
418 static struct type *struct_type (struct dieinfo *, char *, char *,
421 static struct type *enum_type (struct dieinfo *, struct objfile *);
423 static void decode_line_numbers (char *);
425 static struct type *decode_die_type (struct dieinfo *);
427 static struct type *decode_mod_fund_type (char *);
429 static struct type *decode_mod_u_d_type (char *);
431 static struct type *decode_modified_type (char *, unsigned int, int);
433 static struct type *decode_fund_type (unsigned int);
435 static char *create_name (char *, struct obstack *);
437 static struct type *lookup_utype (DIE_REF);
439 static struct type *alloc_utype (DIE_REF, struct type *);
441 static struct symbol *new_symbol (struct dieinfo *, struct objfile *);
444 synthesize_typedef (struct dieinfo *, struct objfile *, struct type *);
446 static int locval (struct dieinfo *);
448 static void set_cu_language (struct dieinfo *);
450 static struct type *dwarf_fundamental_type (struct objfile *, int);
457 dwarf_fundamental_type -- lookup or create a fundamental type
462 dwarf_fundamental_type (struct objfile *objfile, int typeid)
466 DWARF version 1 doesn't supply any fundamental type information,
467 so gdb has to construct such types. It has a fixed number of
468 fundamental types that it knows how to construct, which is the
469 union of all types that it knows how to construct for all languages
470 that it knows about. These are enumerated in gdbtypes.h.
472 As an example, assume we find a DIE that references a DWARF
473 fundamental type of FT_integer. We first look in the ftypes
474 array to see if we already have such a type, indexed by the
475 gdb internal value of FT_INTEGER. If so, we simply return a
476 pointer to that type. If not, then we ask an appropriate
477 language dependent routine to create a type FT_INTEGER, using
478 defaults reasonable for the current target machine, and install
479 that type in ftypes for future reference.
483 Pointer to a fundamental type.
488 dwarf_fundamental_type (struct objfile *objfile, int typeid)
490 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
492 error ("internal error - invalid fundamental type id %d", typeid);
495 /* Look for this particular type in the fundamental type vector. If one is
496 not found, create and install one appropriate for the current language
497 and the current target machine. */
499 if (ftypes[typeid] == NULL)
501 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
504 return (ftypes[typeid]);
511 set_cu_language -- set local copy of language for compilation unit
516 set_cu_language (struct dieinfo *dip)
520 Decode the language attribute for a compilation unit DIE and
521 remember what the language was. We use this at various times
522 when processing DIE's for a given compilation unit.
531 set_cu_language (struct dieinfo *dip)
533 switch (dip->at_language)
537 cu_language = language_c;
539 case LANG_C_PLUS_PLUS:
540 cu_language = language_cplus;
543 cu_language = language_m2;
547 cu_language = language_fortran;
553 /* We don't know anything special about these yet. */
554 cu_language = language_unknown;
557 /* If no at_language, try to deduce one from the filename */
558 cu_language = deduce_language_from_filename (dip->at_name);
561 cu_language_defn = language_def (cu_language);
568 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
572 void dwarf_build_psymtabs (struct objfile *objfile,
573 int mainline, file_ptr dbfoff, unsigned int dbfsize,
574 file_ptr lnoffset, unsigned int lnsize)
578 This function is called upon to build partial symtabs from files
579 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
581 It is passed a bfd* containing the DIES
582 and line number information, the corresponding filename for that
583 file, a base address for relocating the symbols, a flag indicating
584 whether or not this debugging information is from a "main symbol
585 table" rather than a shared library or dynamically linked file,
586 and file offset/size pairs for the DIE information and line number
596 dwarf_build_psymtabs (struct objfile *objfile, int mainline, file_ptr dbfoff,
597 unsigned int dbfsize, file_ptr lnoffset,
600 bfd *abfd = objfile->obfd;
601 struct cleanup *back_to;
603 current_objfile = objfile;
605 dbbase = xmalloc (dbsize);
607 if ((bfd_seek (abfd, dbfoff, SEEK_SET) != 0) ||
608 (bfd_bread (dbbase, dbsize, abfd) != dbsize))
611 error ("can't read DWARF data from '%s'", bfd_get_filename (abfd));
613 back_to = make_cleanup (xfree, dbbase);
615 /* If we are reinitializing, or if we have never loaded syms yet, init.
616 Since we have no idea how many DIES we are looking at, we just guess
617 some arbitrary value. */
620 || (objfile->global_psymbols.size == 0
621 && objfile->static_psymbols.size == 0))
623 init_psymbol_list (objfile, 1024);
626 /* Save the relocation factor where everybody can see it. */
628 base_section_offsets = objfile->section_offsets;
629 baseaddr = ANOFFSET (objfile->section_offsets, 0);
631 /* Follow the compilation unit sibling chain, building a partial symbol
632 table entry for each one. Save enough information about each compilation
633 unit to locate the full DWARF information later. */
635 scan_compilation_units (dbbase, dbbase + dbsize, dbfoff, lnoffset, objfile);
637 do_cleanups (back_to);
638 current_objfile = NULL;
645 read_lexical_block_scope -- process all dies in a lexical block
649 static void read_lexical_block_scope (struct dieinfo *dip,
650 char *thisdie, char *enddie)
654 Process all the DIES contained within a lexical block scope.
655 Start a new scope, process the dies, and then close the scope.
660 read_lexical_block_scope (struct dieinfo *dip, char *thisdie, char *enddie,
661 struct objfile *objfile)
663 register struct context_stack *new;
665 push_context (0, dip->at_low_pc);
666 process_dies (thisdie + dip->die_length, enddie, objfile);
667 new = pop_context ();
668 if (local_symbols != NULL)
670 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
671 dip->at_high_pc, objfile);
673 local_symbols = new->locals;
680 lookup_utype -- look up a user defined type from die reference
684 static type *lookup_utype (DIE_REF die_ref)
688 Given a DIE reference, lookup the user defined type associated with
689 that DIE, if it has been registered already. If not registered, then
690 return NULL. Alloc_utype() can be called to register an empty
691 type for this reference, which will be filled in later when the
692 actual referenced DIE is processed.
696 lookup_utype (DIE_REF die_ref)
698 struct type *type = NULL;
701 utypeidx = (die_ref - dbroff) / 4;
702 if ((utypeidx < 0) || (utypeidx >= numutypes))
704 bad_die_ref_complaint (DIE_ID, DIE_NAME, die_ref);
708 type = *(utypes + utypeidx);
718 alloc_utype -- add a user defined type for die reference
722 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
726 Given a die reference DIE_REF, and a possible pointer to a user
727 defined type UTYPEP, register that this reference has a user
728 defined type and either use the specified type in UTYPEP or
729 make a new empty type that will be filled in later.
731 We should only be called after calling lookup_utype() to verify that
732 there is not currently a type registered for DIE_REF.
736 alloc_utype (DIE_REF die_ref, struct type *utypep)
741 utypeidx = (die_ref - dbroff) / 4;
742 typep = utypes + utypeidx;
743 if ((utypeidx < 0) || (utypeidx >= numutypes))
745 utypep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
746 bad_die_ref_complaint (DIE_ID, DIE_NAME, die_ref);
748 else if (*typep != NULL)
751 complaint (&symfile_complaints,
752 "DIE @ 0x%x \"%s\", internal error: duplicate user type allocation",
759 utypep = alloc_type (current_objfile);
770 free_utypes -- free the utypes array and reset pointer & count
774 static void free_utypes (PTR dummy)
778 Called via do_cleanups to free the utypes array, reset the pointer to NULL,
779 and set numutypes back to zero. This ensures that the utypes does not get
780 referenced after being freed.
784 free_utypes (PTR dummy)
796 decode_die_type -- return a type for a specified die
800 static struct type *decode_die_type (struct dieinfo *dip)
804 Given a pointer to a die information structure DIP, decode the
805 type of the die and return a pointer to the decoded type. All
806 dies without specific types default to type int.
810 decode_die_type (struct dieinfo *dip)
812 struct type *type = NULL;
814 if (dip->at_fund_type != 0)
816 type = decode_fund_type (dip->at_fund_type);
818 else if (dip->at_mod_fund_type != NULL)
820 type = decode_mod_fund_type (dip->at_mod_fund_type);
822 else if (dip->at_user_def_type)
824 if ((type = lookup_utype (dip->at_user_def_type)) == NULL)
826 type = alloc_utype (dip->at_user_def_type, NULL);
829 else if (dip->at_mod_u_d_type)
831 type = decode_mod_u_d_type (dip->at_mod_u_d_type);
835 type = dwarf_fundamental_type (current_objfile, FT_VOID);
844 struct_type -- compute and return the type for a struct or union
848 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
849 char *enddie, struct objfile *objfile)
853 Given pointer to a die information structure for a die which
854 defines a union or structure (and MUST define one or the other),
855 and pointers to the raw die data that define the range of dies which
856 define the members, compute and return the user defined type for the
861 struct_type (struct dieinfo *dip, char *thisdie, char *enddie,
862 struct objfile *objfile)
867 struct nextfield *next;
870 struct nextfield *list = NULL;
871 struct nextfield *new;
878 if ((type = lookup_utype (dip->die_ref)) == NULL)
880 /* No forward references created an empty type, so install one now */
881 type = alloc_utype (dip->die_ref, NULL);
883 INIT_CPLUS_SPECIFIC (type);
884 switch (dip->die_tag)
887 TYPE_CODE (type) = TYPE_CODE_CLASS;
889 case TAG_structure_type:
890 TYPE_CODE (type) = TYPE_CODE_STRUCT;
893 TYPE_CODE (type) = TYPE_CODE_UNION;
896 /* Should never happen */
897 TYPE_CODE (type) = TYPE_CODE_UNDEF;
898 complaint (&symfile_complaints,
899 "DIE @ 0x%x \"%s\", missing class, structure, or union tag",
903 /* Some compilers try to be helpful by inventing "fake" names for
904 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
905 Thanks, but no thanks... */
906 if (dip->at_name != NULL
907 && *dip->at_name != '~'
908 && *dip->at_name != '.')
910 TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
911 "", "", dip->at_name);
913 /* Use whatever size is known. Zero is a valid size. We might however
914 wish to check has_at_byte_size to make sure that some byte size was
915 given explicitly, but DWARF doesn't specify that explicit sizes of
916 zero have to present, so complaining about missing sizes should
917 probably not be the default. */
918 TYPE_LENGTH (type) = dip->at_byte_size;
919 thisdie += dip->die_length;
920 while (thisdie < enddie)
922 basicdieinfo (&mbr, thisdie, objfile);
923 completedieinfo (&mbr, objfile);
924 if (mbr.die_length <= SIZEOF_DIE_LENGTH)
928 else if (mbr.at_sibling != 0)
930 nextdie = dbbase + mbr.at_sibling - dbroff;
934 nextdie = thisdie + mbr.die_length;
939 /* Get space to record the next field's data. */
940 new = (struct nextfield *) alloca (sizeof (struct nextfield));
945 obsavestring (mbr.at_name, strlen (mbr.at_name),
946 &objfile->type_obstack);
947 FIELD_TYPE (list->field) = decode_die_type (&mbr);
948 FIELD_BITPOS (list->field) = 8 * locval (&mbr);
949 FIELD_STATIC_KIND (list->field) = 0;
950 /* Handle bit fields. */
951 FIELD_BITSIZE (list->field) = mbr.at_bit_size;
954 /* For big endian bits, the at_bit_offset gives the
955 additional bit offset from the MSB of the containing
956 anonymous object to the MSB of the field. We don't
957 have to do anything special since we don't need to
958 know the size of the anonymous object. */
959 FIELD_BITPOS (list->field) += mbr.at_bit_offset;
963 /* For little endian bits, we need to have a non-zero
964 at_bit_size, so that we know we are in fact dealing
965 with a bitfield. Compute the bit offset to the MSB
966 of the anonymous object, subtract off the number of
967 bits from the MSB of the field to the MSB of the
968 object, and then subtract off the number of bits of
969 the field itself. The result is the bit offset of
970 the LSB of the field. */
971 if (mbr.at_bit_size > 0)
973 if (mbr.has_at_byte_size)
975 /* The size of the anonymous object containing
976 the bit field is explicit, so use the
977 indicated size (in bytes). */
978 anonymous_size = mbr.at_byte_size;
982 /* The size of the anonymous object containing
983 the bit field matches the size of an object
984 of the bit field's type. DWARF allows
985 at_byte_size to be left out in such cases, as
986 a debug information size optimization. */
987 anonymous_size = TYPE_LENGTH (list->field.type);
989 FIELD_BITPOS (list->field) +=
990 anonymous_size * 8 - mbr.at_bit_offset - mbr.at_bit_size;
996 process_dies (thisdie, nextdie, objfile);
1001 /* Now create the vector of fields, and record how big it is. We may
1002 not even have any fields, if this DIE was generated due to a reference
1003 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
1004 set, which clues gdb in to the fact that it needs to search elsewhere
1005 for the full structure definition. */
1008 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1012 TYPE_NFIELDS (type) = nfields;
1013 TYPE_FIELDS (type) = (struct field *)
1014 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1015 /* Copy the saved-up fields into the field vector. */
1016 for (n = nfields; list; list = list->next)
1018 TYPE_FIELD (type, --n) = list->field;
1028 read_structure_scope -- process all dies within struct or union
1032 static void read_structure_scope (struct dieinfo *dip,
1033 char *thisdie, char *enddie, struct objfile *objfile)
1037 Called when we find the DIE that starts a structure or union
1038 scope (definition) to process all dies that define the members
1039 of the structure or union. DIP is a pointer to the die info
1040 struct for the DIE that names the structure or union.
1044 Note that we need to call struct_type regardless of whether or not
1045 the DIE has an at_name attribute, since it might be an anonymous
1046 structure or union. This gets the type entered into our set of
1049 However, if the structure is incomplete (an opaque struct/union)
1050 then suppress creating a symbol table entry for it since gdb only
1051 wants to find the one with the complete definition. Note that if
1052 it is complete, we just call new_symbol, which does it's own
1053 checking about whether the struct/union is anonymous or not (and
1054 suppresses creating a symbol table entry itself).
1059 read_structure_scope (struct dieinfo *dip, char *thisdie, char *enddie,
1060 struct objfile *objfile)
1065 type = struct_type (dip, thisdie, enddie, objfile);
1066 if (!TYPE_STUB (type))
1068 sym = new_symbol (dip, objfile);
1071 SYMBOL_TYPE (sym) = type;
1072 if (cu_language == language_cplus)
1074 synthesize_typedef (dip, objfile, type);
1084 decode_array_element_type -- decode type of the array elements
1088 static struct type *decode_array_element_type (char *scan, char *end)
1092 As the last step in decoding the array subscript information for an
1093 array DIE, we need to decode the type of the array elements. We are
1094 passed a pointer to this last part of the subscript information and
1095 must return the appropriate type. If the type attribute is not
1096 recognized, just warn about the problem and return type int.
1099 static struct type *
1100 decode_array_element_type (char *scan)
1104 unsigned short attribute;
1105 unsigned short fundtype;
1108 attribute = target_to_host (scan, SIZEOF_ATTRIBUTE, GET_UNSIGNED,
1110 scan += SIZEOF_ATTRIBUTE;
1111 if ((nbytes = attribute_size (attribute)) == -1)
1113 bad_array_element_type_complaint (DIE_ID, DIE_NAME, attribute);
1114 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1121 fundtype = target_to_host (scan, nbytes, GET_UNSIGNED,
1123 typep = decode_fund_type (fundtype);
1125 case AT_mod_fund_type:
1126 typep = decode_mod_fund_type (scan);
1128 case AT_user_def_type:
1129 die_ref = target_to_host (scan, nbytes, GET_UNSIGNED,
1131 if ((typep = lookup_utype (die_ref)) == NULL)
1133 typep = alloc_utype (die_ref, NULL);
1136 case AT_mod_u_d_type:
1137 typep = decode_mod_u_d_type (scan);
1140 bad_array_element_type_complaint (DIE_ID, DIE_NAME, attribute);
1141 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1152 decode_subscript_data_item -- decode array subscript item
1156 static struct type *
1157 decode_subscript_data_item (char *scan, char *end)
1161 The array subscripts and the data type of the elements of an
1162 array are described by a list of data items, stored as a block
1163 of contiguous bytes. There is a data item describing each array
1164 dimension, and a final data item describing the element type.
1165 The data items are ordered the same as their appearance in the
1166 source (I.E. leftmost dimension first, next to leftmost second,
1169 The data items describing each array dimension consist of four
1170 parts: (1) a format specifier, (2) type type of the subscript
1171 index, (3) a description of the low bound of the array dimension,
1172 and (4) a description of the high bound of the array dimension.
1174 The last data item is the description of the type of each of
1177 We are passed a pointer to the start of the block of bytes
1178 containing the remaining data items, and a pointer to the first
1179 byte past the data. This function recursively decodes the
1180 remaining data items and returns a type.
1182 If we somehow fail to decode some data, we complain about it
1183 and return a type "array of int".
1186 FIXME: This code only implements the forms currently used
1187 by the AT&T and GNU C compilers.
1189 The end pointer is supplied for error checking, maybe we should
1193 static struct type *
1194 decode_subscript_data_item (char *scan, char *end)
1196 struct type *typep = NULL; /* Array type we are building */
1197 struct type *nexttype; /* Type of each element (may be array) */
1198 struct type *indextype; /* Type of this index */
1199 struct type *rangetype;
1200 unsigned int format;
1201 unsigned short fundtype;
1202 unsigned long lowbound;
1203 unsigned long highbound;
1206 format = target_to_host (scan, SIZEOF_FORMAT_SPECIFIER, GET_UNSIGNED,
1208 scan += SIZEOF_FORMAT_SPECIFIER;
1212 typep = decode_array_element_type (scan);
1215 fundtype = target_to_host (scan, SIZEOF_FMT_FT, GET_UNSIGNED,
1217 indextype = decode_fund_type (fundtype);
1218 scan += SIZEOF_FMT_FT;
1219 nbytes = TARGET_FT_LONG_SIZE (current_objfile);
1220 lowbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile);
1222 highbound = target_to_host (scan, nbytes, GET_UNSIGNED, current_objfile);
1224 nexttype = decode_subscript_data_item (scan, end);
1225 if (nexttype == NULL)
1227 /* Munged subscript data or other problem, fake it. */
1228 complaint (&symfile_complaints,
1229 "DIE @ 0x%x \"%s\", can't decode subscript data items",
1231 nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1233 rangetype = create_range_type ((struct type *) NULL, indextype,
1234 lowbound, highbound);
1235 typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
1244 complaint (&symfile_complaints,
1245 "DIE @ 0x%x \"%s\", array subscript format 0x%x not handled yet",
1246 DIE_ID, DIE_NAME, format);
1247 nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1248 rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0);
1249 typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
1252 complaint (&symfile_complaints,
1253 "DIE @ 0x%x \"%s\", unknown array subscript format %x", DIE_ID,
1255 nexttype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1256 rangetype = create_range_type ((struct type *) NULL, nexttype, 0, 0);
1257 typep = create_array_type ((struct type *) NULL, nexttype, rangetype);
1267 dwarf_read_array_type -- read TAG_array_type DIE
1271 static void dwarf_read_array_type (struct dieinfo *dip)
1275 Extract all information from a TAG_array_type DIE and add to
1276 the user defined type vector.
1280 dwarf_read_array_type (struct dieinfo *dip)
1286 unsigned short blocksz;
1289 if (dip->at_ordering != ORD_row_major)
1291 /* FIXME: Can gdb even handle column major arrays? */
1292 complaint (&symfile_complaints,
1293 "DIE @ 0x%x \"%s\", array not row major; not handled correctly",
1296 if ((sub = dip->at_subscr_data) != NULL)
1298 nbytes = attribute_size (AT_subscr_data);
1299 blocksz = target_to_host (sub, nbytes, GET_UNSIGNED, current_objfile);
1300 subend = sub + nbytes + blocksz;
1302 type = decode_subscript_data_item (sub, subend);
1303 if ((utype = lookup_utype (dip->die_ref)) == NULL)
1305 /* Install user defined type that has not been referenced yet. */
1306 alloc_utype (dip->die_ref, type);
1308 else if (TYPE_CODE (utype) == TYPE_CODE_UNDEF)
1310 /* Ick! A forward ref has already generated a blank type in our
1311 slot, and this type probably already has things pointing to it
1312 (which is what caused it to be created in the first place).
1313 If it's just a place holder we can plop our fully defined type
1314 on top of it. We can't recover the space allocated for our
1315 new type since it might be on an obstack, but we could reuse
1316 it if we kept a list of them, but it might not be worth it
1322 /* Double ick! Not only is a type already in our slot, but
1323 someone has decorated it. Complain and leave it alone. */
1324 dup_user_type_definition_complaint (DIE_ID, DIE_NAME);
1333 read_tag_pointer_type -- read TAG_pointer_type DIE
1337 static void read_tag_pointer_type (struct dieinfo *dip)
1341 Extract all information from a TAG_pointer_type DIE and add to
1342 the user defined type vector.
1346 read_tag_pointer_type (struct dieinfo *dip)
1351 type = decode_die_type (dip);
1352 if ((utype = lookup_utype (dip->die_ref)) == NULL)
1354 utype = lookup_pointer_type (type);
1355 alloc_utype (dip->die_ref, utype);
1359 TYPE_TARGET_TYPE (utype) = type;
1360 TYPE_POINTER_TYPE (type) = utype;
1362 /* We assume the machine has only one representation for pointers! */
1363 /* FIXME: Possably a poor assumption */
1364 TYPE_LENGTH (utype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
1365 TYPE_CODE (utype) = TYPE_CODE_PTR;
1373 read_tag_string_type -- read TAG_string_type DIE
1377 static void read_tag_string_type (struct dieinfo *dip)
1381 Extract all information from a TAG_string_type DIE and add to
1382 the user defined type vector. It isn't really a user defined
1383 type, but it behaves like one, with other DIE's using an
1384 AT_user_def_type attribute to reference it.
1388 read_tag_string_type (struct dieinfo *dip)
1391 struct type *indextype;
1392 struct type *rangetype;
1393 unsigned long lowbound = 0;
1394 unsigned long highbound;
1396 if (dip->has_at_byte_size)
1398 /* A fixed bounds string */
1399 highbound = dip->at_byte_size - 1;
1403 /* A varying length string. Stub for now. (FIXME) */
1406 indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
1407 rangetype = create_range_type ((struct type *) NULL, indextype, lowbound,
1410 utype = lookup_utype (dip->die_ref);
1413 /* No type defined, go ahead and create a blank one to use. */
1414 utype = alloc_utype (dip->die_ref, (struct type *) NULL);
1418 /* Already a type in our slot due to a forward reference. Make sure it
1419 is a blank one. If not, complain and leave it alone. */
1420 if (TYPE_CODE (utype) != TYPE_CODE_UNDEF)
1422 dup_user_type_definition_complaint (DIE_ID, DIE_NAME);
1427 /* Create the string type using the blank type we either found or created. */
1428 utype = create_string_type (utype, rangetype);
1435 read_subroutine_type -- process TAG_subroutine_type dies
1439 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1444 Handle DIES due to C code like:
1447 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1453 The parameter DIES are currently ignored. See if gdb has a way to
1454 include this info in it's type system, and decode them if so. Is
1455 this what the type structure's "arg_types" field is for? (FIXME)
1459 read_subroutine_type (struct dieinfo *dip, char *thisdie, char *enddie)
1461 struct type *type; /* Type that this function returns */
1462 struct type *ftype; /* Function that returns above type */
1464 /* Decode the type that this subroutine returns */
1466 type = decode_die_type (dip);
1468 /* Check to see if we already have a partially constructed user
1469 defined type for this DIE, from a forward reference. */
1471 if ((ftype = lookup_utype (dip->die_ref)) == NULL)
1473 /* This is the first reference to one of these types. Make
1474 a new one and place it in the user defined types. */
1475 ftype = lookup_function_type (type);
1476 alloc_utype (dip->die_ref, ftype);
1478 else if (TYPE_CODE (ftype) == TYPE_CODE_UNDEF)
1480 /* We have an existing partially constructed type, so bash it
1481 into the correct type. */
1482 TYPE_TARGET_TYPE (ftype) = type;
1483 TYPE_LENGTH (ftype) = 1;
1484 TYPE_CODE (ftype) = TYPE_CODE_FUNC;
1488 dup_user_type_definition_complaint (DIE_ID, DIE_NAME);
1496 read_enumeration -- process dies which define an enumeration
1500 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1501 char *enddie, struct objfile *objfile)
1505 Given a pointer to a die which begins an enumeration, process all
1506 the dies that define the members of the enumeration.
1510 Note that we need to call enum_type regardless of whether or not we
1511 have a symbol, since we might have an enum without a tag name (thus
1512 no symbol for the tagname).
1516 read_enumeration (struct dieinfo *dip, char *thisdie, char *enddie,
1517 struct objfile *objfile)
1522 type = enum_type (dip, objfile);
1523 sym = new_symbol (dip, objfile);
1526 SYMBOL_TYPE (sym) = type;
1527 if (cu_language == language_cplus)
1529 synthesize_typedef (dip, objfile, type);
1538 enum_type -- decode and return a type for an enumeration
1542 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1546 Given a pointer to a die information structure for the die which
1547 starts an enumeration, process all the dies that define the members
1548 of the enumeration and return a type pointer for the enumeration.
1550 At the same time, for each member of the enumeration, create a
1551 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1552 and give it the type of the enumeration itself.
1556 Note that the DWARF specification explicitly mandates that enum
1557 constants occur in reverse order from the source program order,
1558 for "consistency" and because this ordering is easier for many
1559 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1560 Entries). Because gdb wants to see the enum members in program
1561 source order, we have to ensure that the order gets reversed while
1562 we are processing them.
1565 static struct type *
1566 enum_type (struct dieinfo *dip, struct objfile *objfile)
1571 struct nextfield *next;
1574 struct nextfield *list = NULL;
1575 struct nextfield *new;
1580 unsigned short blocksz;
1583 int unsigned_enum = 1;
1585 if ((type = lookup_utype (dip->die_ref)) == NULL)
1587 /* No forward references created an empty type, so install one now */
1588 type = alloc_utype (dip->die_ref, NULL);
1590 TYPE_CODE (type) = TYPE_CODE_ENUM;
1591 /* Some compilers try to be helpful by inventing "fake" names for
1592 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1593 Thanks, but no thanks... */
1594 if (dip->at_name != NULL
1595 && *dip->at_name != '~'
1596 && *dip->at_name != '.')
1598 TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
1599 "", "", dip->at_name);
1601 if (dip->at_byte_size != 0)
1603 TYPE_LENGTH (type) = dip->at_byte_size;
1605 if ((scan = dip->at_element_list) != NULL)
1607 if (dip->short_element_list)
1609 nbytes = attribute_size (AT_short_element_list);
1613 nbytes = attribute_size (AT_element_list);
1615 blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
1616 listend = scan + nbytes + blocksz;
1618 while (scan < listend)
1620 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1623 FIELD_TYPE (list->field) = NULL;
1624 FIELD_BITSIZE (list->field) = 0;
1625 FIELD_STATIC_KIND (list->field) = 0;
1626 FIELD_BITPOS (list->field) =
1627 target_to_host (scan, TARGET_FT_LONG_SIZE (objfile), GET_SIGNED,
1629 scan += TARGET_FT_LONG_SIZE (objfile);
1630 list->field.name = obsavestring (scan, strlen (scan),
1631 &objfile->type_obstack);
1632 scan += strlen (scan) + 1;
1634 /* Handcraft a new symbol for this enum member. */
1635 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1636 sizeof (struct symbol));
1637 memset (sym, 0, sizeof (struct symbol));
1638 SYMBOL_NAME (sym) = create_name (list->field.name,
1639 &objfile->symbol_obstack);
1640 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
1641 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1642 SYMBOL_CLASS (sym) = LOC_CONST;
1643 SYMBOL_TYPE (sym) = type;
1644 SYMBOL_VALUE (sym) = FIELD_BITPOS (list->field);
1645 if (SYMBOL_VALUE (sym) < 0)
1647 add_symbol_to_list (sym, list_in_scope);
1649 /* Now create the vector of fields, and record how big it is. This is
1650 where we reverse the order, by pulling the members off the list in
1651 reverse order from how they were inserted. If we have no fields
1652 (this is apparently possible in C++) then skip building a field
1657 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1658 TYPE_NFIELDS (type) = nfields;
1659 TYPE_FIELDS (type) = (struct field *)
1660 obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) * nfields);
1661 /* Copy the saved-up fields into the field vector. */
1662 for (n = 0; (n < nfields) && (list != NULL); list = list->next)
1664 TYPE_FIELD (type, n++) = list->field;
1675 read_func_scope -- process all dies within a function scope
1679 Process all dies within a given function scope. We are passed
1680 a die information structure pointer DIP for the die which
1681 starts the function scope, and pointers into the raw die data
1682 that define the dies within the function scope.
1684 For now, we ignore lexical block scopes within the function.
1685 The problem is that AT&T cc does not define a DWARF lexical
1686 block scope for the function itself, while gcc defines a
1687 lexical block scope for the function. We need to think about
1688 how to handle this difference, or if it is even a problem.
1693 read_func_scope (struct dieinfo *dip, char *thisdie, char *enddie,
1694 struct objfile *objfile)
1696 register struct context_stack *new;
1698 /* AT_name is absent if the function is described with an
1699 AT_abstract_origin tag.
1700 Ignore the function description for now to avoid GDB core dumps.
1701 FIXME: Add code to handle AT_abstract_origin tags properly. */
1702 if (dip->at_name == NULL)
1704 complaint (&symfile_complaints, "DIE @ 0x%x, AT_name tag missing",
1709 if (objfile->ei.entry_point >= dip->at_low_pc &&
1710 objfile->ei.entry_point < dip->at_high_pc)
1712 objfile->ei.entry_func_lowpc = dip->at_low_pc;
1713 objfile->ei.entry_func_highpc = dip->at_high_pc;
1715 new = push_context (0, dip->at_low_pc);
1716 new->name = new_symbol (dip, objfile);
1717 list_in_scope = &local_symbols;
1718 process_dies (thisdie + dip->die_length, enddie, objfile);
1719 new = pop_context ();
1720 /* Make a block for the local symbols within. */
1721 finish_block (new->name, &local_symbols, new->old_blocks,
1722 new->start_addr, dip->at_high_pc, objfile);
1723 list_in_scope = &file_symbols;
1731 handle_producer -- process the AT_producer attribute
1735 Perform any operations that depend on finding a particular
1736 AT_producer attribute.
1741 handle_producer (char *producer)
1744 /* If this compilation unit was compiled with g++ or gcc, then set the
1745 processing_gcc_compilation flag. */
1747 if (STREQN (producer, GCC_PRODUCER, strlen (GCC_PRODUCER)))
1749 char version = producer[strlen (GCC_PRODUCER)];
1750 processing_gcc_compilation = (version == '2' ? 2 : 1);
1754 processing_gcc_compilation =
1755 STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER));
1758 /* Select a demangling style if we can identify the producer and if
1759 the current style is auto. We leave the current style alone if it
1760 is not auto. We also leave the demangling style alone if we find a
1761 gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
1763 if (AUTO_DEMANGLING)
1765 if (STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)))
1768 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
1769 know whether it will use the old style or v3 mangling. */
1770 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1773 else if (STREQN (producer, LCC_PRODUCER, strlen (LCC_PRODUCER)))
1775 set_demangling_style (LUCID_DEMANGLING_STYLE_STRING);
1785 read_file_scope -- process all dies within a file scope
1789 Process all dies within a given file scope. We are passed a
1790 pointer to the die information structure for the die which
1791 starts the file scope, and pointers into the raw die data which
1792 mark the range of dies within the file scope.
1794 When the partial symbol table is built, the file offset for the line
1795 number table for each compilation unit is saved in the partial symbol
1796 table entry for that compilation unit. As the symbols for each
1797 compilation unit are read, the line number table is read into memory
1798 and the variable lnbase is set to point to it. Thus all we have to
1799 do is use lnbase to access the line number table for the current
1804 read_file_scope (struct dieinfo *dip, char *thisdie, char *enddie,
1805 struct objfile *objfile)
1807 struct cleanup *back_to;
1808 struct symtab *symtab;
1810 if (objfile->ei.entry_point >= dip->at_low_pc &&
1811 objfile->ei.entry_point < dip->at_high_pc)
1813 objfile->ei.entry_file_lowpc = dip->at_low_pc;
1814 objfile->ei.entry_file_highpc = dip->at_high_pc;
1816 set_cu_language (dip);
1817 if (dip->at_producer != NULL)
1819 handle_producer (dip->at_producer);
1821 numutypes = (enddie - thisdie) / 4;
1822 utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *));
1823 back_to = make_cleanup (free_utypes, NULL);
1824 memset (utypes, 0, numutypes * sizeof (struct type *));
1825 memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
1826 start_symtab (dip->at_name, dip->at_comp_dir, dip->at_low_pc);
1827 record_debugformat ("DWARF 1");
1828 decode_line_numbers (lnbase);
1829 process_dies (thisdie + dip->die_length, enddie, objfile);
1831 symtab = end_symtab (dip->at_high_pc, objfile, 0);
1834 symtab->language = cu_language;
1836 do_cleanups (back_to);
1843 process_dies -- process a range of DWARF Information Entries
1847 static void process_dies (char *thisdie, char *enddie,
1848 struct objfile *objfile)
1852 Process all DIE's in a specified range. May be (and almost
1853 certainly will be) called recursively.
1857 process_dies (char *thisdie, char *enddie, struct objfile *objfile)
1862 while (thisdie < enddie)
1864 basicdieinfo (&di, thisdie, objfile);
1865 if (di.die_length < SIZEOF_DIE_LENGTH)
1869 else if (di.die_tag == TAG_padding)
1871 nextdie = thisdie + di.die_length;
1875 completedieinfo (&di, objfile);
1876 if (di.at_sibling != 0)
1878 nextdie = dbbase + di.at_sibling - dbroff;
1882 nextdie = thisdie + di.die_length;
1884 /* I think that these are always text, not data, addresses. */
1885 di.at_low_pc = SMASH_TEXT_ADDRESS (di.at_low_pc);
1886 di.at_high_pc = SMASH_TEXT_ADDRESS (di.at_high_pc);
1889 case TAG_compile_unit:
1890 /* Skip Tag_compile_unit if we are already inside a compilation
1891 unit, we are unable to handle nested compilation units
1892 properly (FIXME). */
1893 if (current_subfile == NULL)
1894 read_file_scope (&di, thisdie, nextdie, objfile);
1896 nextdie = thisdie + di.die_length;
1898 case TAG_global_subroutine:
1899 case TAG_subroutine:
1900 if (di.has_at_low_pc)
1902 read_func_scope (&di, thisdie, nextdie, objfile);
1905 case TAG_lexical_block:
1906 read_lexical_block_scope (&di, thisdie, nextdie, objfile);
1908 case TAG_class_type:
1909 case TAG_structure_type:
1910 case TAG_union_type:
1911 read_structure_scope (&di, thisdie, nextdie, objfile);
1913 case TAG_enumeration_type:
1914 read_enumeration (&di, thisdie, nextdie, objfile);
1916 case TAG_subroutine_type:
1917 read_subroutine_type (&di, thisdie, nextdie);
1919 case TAG_array_type:
1920 dwarf_read_array_type (&di);
1922 case TAG_pointer_type:
1923 read_tag_pointer_type (&di);
1925 case TAG_string_type:
1926 read_tag_string_type (&di);
1929 new_symbol (&di, objfile);
1941 decode_line_numbers -- decode a line number table fragment
1945 static void decode_line_numbers (char *tblscan, char *tblend,
1946 long length, long base, long line, long pc)
1950 Translate the DWARF line number information to gdb form.
1952 The ".line" section contains one or more line number tables, one for
1953 each ".line" section from the objects that were linked.
1955 The AT_stmt_list attribute for each TAG_source_file entry in the
1956 ".debug" section contains the offset into the ".line" section for the
1957 start of the table for that file.
1959 The table itself has the following structure:
1961 <table length><base address><source statement entry>
1962 4 bytes 4 bytes 10 bytes
1964 The table length is the total size of the table, including the 4 bytes
1965 for the length information.
1967 The base address is the address of the first instruction generated
1968 for the source file.
1970 Each source statement entry has the following structure:
1972 <line number><statement position><address delta>
1973 4 bytes 2 bytes 4 bytes
1975 The line number is relative to the start of the file, starting with
1978 The statement position either -1 (0xFFFF) or the number of characters
1979 from the beginning of the line to the beginning of the statement.
1981 The address delta is the difference between the base address and
1982 the address of the first instruction for the statement.
1984 Note that we must copy the bytes from the packed table to our local
1985 variables before attempting to use them, to avoid alignment problems
1986 on some machines, particularly RISC processors.
1990 Does gdb expect the line numbers to be sorted? They are now by
1991 chance/luck, but are not required to be. (FIXME)
1993 The line with number 0 is unused, gdb apparently can discover the
1994 span of the last line some other way. How? (FIXME)
1998 decode_line_numbers (char *linetable)
2002 unsigned long length;
2007 if (linetable != NULL)
2009 tblscan = tblend = linetable;
2010 length = target_to_host (tblscan, SIZEOF_LINETBL_LENGTH, GET_UNSIGNED,
2012 tblscan += SIZEOF_LINETBL_LENGTH;
2014 base = target_to_host (tblscan, TARGET_FT_POINTER_SIZE (objfile),
2015 GET_UNSIGNED, current_objfile);
2016 tblscan += TARGET_FT_POINTER_SIZE (objfile);
2018 while (tblscan < tblend)
2020 line = target_to_host (tblscan, SIZEOF_LINETBL_LINENO, GET_UNSIGNED,
2022 tblscan += SIZEOF_LINETBL_LINENO + SIZEOF_LINETBL_STMT;
2023 pc = target_to_host (tblscan, SIZEOF_LINETBL_DELTA, GET_UNSIGNED,
2025 tblscan += SIZEOF_LINETBL_DELTA;
2029 record_line (current_subfile, line, pc);
2039 locval -- compute the value of a location attribute
2043 static int locval (struct dieinfo *dip)
2047 Given pointer to a string of bytes that define a location, compute
2048 the location and return the value.
2049 A location description containing no atoms indicates that the
2050 object is optimized out. The optimized_out flag is set for those,
2051 the return value is meaningless.
2053 When computing values involving the current value of the frame pointer,
2054 the value zero is used, which results in a value relative to the frame
2055 pointer, rather than the absolute value. This is what GDB wants
2058 When the result is a register number, the isreg flag is set, otherwise
2059 it is cleared. This is a kludge until we figure out a better
2060 way to handle the problem. Gdb's design does not mesh well with the
2061 DWARF notion of a location computing interpreter, which is a shame
2062 because the flexibility goes unused.
2066 Note that stack[0] is unused except as a default error return.
2067 Note that stack overflow is not yet handled.
2071 locval (struct dieinfo *dip)
2073 unsigned short nbytes;
2074 unsigned short locsize;
2075 auto long stack[64];
2082 loc = dip->at_location;
2083 nbytes = attribute_size (AT_location);
2084 locsize = target_to_host (loc, nbytes, GET_UNSIGNED, current_objfile);
2086 end = loc + locsize;
2091 dip->optimized_out = 1;
2092 loc_value_size = TARGET_FT_LONG_SIZE (current_objfile);
2095 dip->optimized_out = 0;
2096 loc_atom_code = target_to_host (loc, SIZEOF_LOC_ATOM_CODE, GET_UNSIGNED,
2098 loc += SIZEOF_LOC_ATOM_CODE;
2099 switch (loc_atom_code)
2106 /* push register (number) */
2108 = DWARF_REG_TO_REGNUM (target_to_host (loc, loc_value_size,
2111 loc += loc_value_size;
2115 /* push value of register (number) */
2116 /* Actually, we compute the value as if register has 0, so the
2117 value ends up being the offset from that register. */
2119 dip->basereg = target_to_host (loc, loc_value_size, GET_UNSIGNED,
2121 loc += loc_value_size;
2122 stack[++stacki] = 0;
2125 /* push address (relocated address) */
2126 stack[++stacki] = target_to_host (loc, loc_value_size,
2127 GET_UNSIGNED, current_objfile);
2128 loc += loc_value_size;
2131 /* push constant (number) FIXME: signed or unsigned! */
2132 stack[++stacki] = target_to_host (loc, loc_value_size,
2133 GET_SIGNED, current_objfile);
2134 loc += loc_value_size;
2137 /* pop, deref and push 2 bytes (as a long) */
2138 complaint (&symfile_complaints,
2139 "DIE @ 0x%x \"%s\", OP_DEREF2 address 0x%lx not handled",
2140 DIE_ID, DIE_NAME, stack[stacki]);
2142 case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */
2143 complaint (&symfile_complaints,
2144 "DIE @ 0x%x \"%s\", OP_DEREF4 address 0x%lx not handled",
2145 DIE_ID, DIE_NAME, stack[stacki]);
2147 case OP_ADD: /* pop top 2 items, add, push result */
2148 stack[stacki - 1] += stack[stacki];
2153 return (stack[stacki]);
2160 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
2164 static void read_ofile_symtab (struct partial_symtab *pst)
2168 When expanding a partial symbol table entry to a full symbol table
2169 entry, this is the function that gets called to read in the symbols
2170 for the compilation unit. A pointer to the newly constructed symtab,
2171 which is now the new first one on the objfile's symtab list, is
2172 stashed in the partial symbol table entry.
2176 read_ofile_symtab (struct partial_symtab *pst)
2178 struct cleanup *back_to;
2179 unsigned long lnsize;
2182 char lnsizedata[SIZEOF_LINETBL_LENGTH];
2184 abfd = pst->objfile->obfd;
2185 current_objfile = pst->objfile;
2187 /* Allocate a buffer for the entire chunk of DIE's for this compilation
2188 unit, seek to the location in the file, and read in all the DIE's. */
2191 dbsize = DBLENGTH (pst);
2192 dbbase = xmalloc (dbsize);
2193 dbroff = DBROFF (pst);
2194 foffset = DBFOFF (pst) + dbroff;
2195 base_section_offsets = pst->section_offsets;
2196 baseaddr = ANOFFSET (pst->section_offsets, 0);
2197 if (bfd_seek (abfd, foffset, SEEK_SET) ||
2198 (bfd_bread (dbbase, dbsize, abfd) != dbsize))
2201 error ("can't read DWARF data");
2203 back_to = make_cleanup (xfree, dbbase);
2205 /* If there is a line number table associated with this compilation unit
2206 then read the size of this fragment in bytes, from the fragment itself.
2207 Allocate a buffer for the fragment and read it in for future
2213 if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
2214 (bfd_bread ((PTR) lnsizedata, sizeof (lnsizedata), abfd)
2215 != sizeof (lnsizedata)))
2217 error ("can't read DWARF line number table size");
2219 lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH,
2220 GET_UNSIGNED, pst->objfile);
2221 lnbase = xmalloc (lnsize);
2222 if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
2223 (bfd_bread (lnbase, lnsize, abfd) != lnsize))
2226 error ("can't read DWARF line numbers");
2228 make_cleanup (xfree, lnbase);
2231 process_dies (dbbase, dbbase + dbsize, pst->objfile);
2232 do_cleanups (back_to);
2233 current_objfile = NULL;
2234 pst->symtab = pst->objfile->symtabs;
2241 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
2245 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
2249 Called once for each partial symbol table entry that needs to be
2250 expanded into a full symbol table entry.
2255 psymtab_to_symtab_1 (struct partial_symtab *pst)
2258 struct cleanup *old_chain;
2264 warning ("psymtab for %s already read in. Shouldn't happen.",
2269 /* Read in all partial symtabs on which this one is dependent */
2270 for (i = 0; i < pst->number_of_dependencies; i++)
2272 if (!pst->dependencies[i]->readin)
2274 /* Inform about additional files that need to be read in. */
2277 fputs_filtered (" ", gdb_stdout);
2279 fputs_filtered ("and ", gdb_stdout);
2281 printf_filtered ("%s...",
2282 pst->dependencies[i]->filename);
2284 gdb_flush (gdb_stdout); /* Flush output */
2286 psymtab_to_symtab_1 (pst->dependencies[i]);
2289 if (DBLENGTH (pst)) /* Otherwise it's a dummy */
2292 old_chain = make_cleanup (really_free_pendings, 0);
2293 read_ofile_symtab (pst);
2296 printf_filtered ("%d DIE's, sorting...", diecount);
2298 gdb_flush (gdb_stdout);
2300 sort_symtab_syms (pst->symtab);
2301 do_cleanups (old_chain);
2312 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2316 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2320 This is the DWARF support entry point for building a full symbol
2321 table entry from a partial symbol table entry. We are passed a
2322 pointer to the partial symbol table entry that needs to be expanded.
2327 dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2334 warning ("psymtab for %s already read in. Shouldn't happen.",
2339 if (DBLENGTH (pst) || pst->number_of_dependencies)
2341 /* Print the message now, before starting serious work, to avoid
2342 disconcerting pauses. */
2345 printf_filtered ("Reading in symbols for %s...",
2347 gdb_flush (gdb_stdout);
2350 psymtab_to_symtab_1 (pst);
2352 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2353 we need to do an equivalent or is this something peculiar to
2355 Match with global symbols. This only needs to be done once,
2356 after all of the symtabs and dependencies have been read in.
2358 scan_file_globals (pst->objfile);
2361 /* Finish up the verbose info message. */
2364 printf_filtered ("done.\n");
2365 gdb_flush (gdb_stdout);
2376 add_enum_psymbol -- add enumeration members to partial symbol table
2380 Given pointer to a DIE that is known to be for an enumeration,
2381 extract the symbolic names of the enumeration members and add
2382 partial symbols for them.
2386 add_enum_psymbol (struct dieinfo *dip, struct objfile *objfile)
2390 unsigned short blocksz;
2393 if ((scan = dip->at_element_list) != NULL)
2395 if (dip->short_element_list)
2397 nbytes = attribute_size (AT_short_element_list);
2401 nbytes = attribute_size (AT_element_list);
2403 blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
2405 listend = scan + blocksz;
2406 while (scan < listend)
2408 scan += TARGET_FT_LONG_SIZE (objfile);
2409 add_psymbol_to_list (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST,
2410 &objfile->static_psymbols, 0, 0, cu_language,
2412 scan += strlen (scan) + 1;
2421 add_partial_symbol -- add symbol to partial symbol table
2425 Given a DIE, if it is one of the types that we want to
2426 add to a partial symbol table, finish filling in the die info
2427 and then add a partial symbol table entry for it.
2431 The caller must ensure that the DIE has a valid name attribute.
2435 add_partial_symbol (struct dieinfo *dip, struct objfile *objfile)
2437 switch (dip->die_tag)
2439 case TAG_global_subroutine:
2440 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2441 VAR_NAMESPACE, LOC_BLOCK,
2442 &objfile->global_psymbols,
2443 0, dip->at_low_pc, cu_language, objfile);
2445 case TAG_global_variable:
2446 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2447 VAR_NAMESPACE, LOC_STATIC,
2448 &objfile->global_psymbols,
2449 0, 0, cu_language, objfile);
2451 case TAG_subroutine:
2452 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2453 VAR_NAMESPACE, LOC_BLOCK,
2454 &objfile->static_psymbols,
2455 0, dip->at_low_pc, cu_language, objfile);
2457 case TAG_local_variable:
2458 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2459 VAR_NAMESPACE, LOC_STATIC,
2460 &objfile->static_psymbols,
2461 0, 0, cu_language, objfile);
2464 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2465 VAR_NAMESPACE, LOC_TYPEDEF,
2466 &objfile->static_psymbols,
2467 0, 0, cu_language, objfile);
2469 case TAG_class_type:
2470 case TAG_structure_type:
2471 case TAG_union_type:
2472 case TAG_enumeration_type:
2473 /* Do not add opaque aggregate definitions to the psymtab. */
2474 if (!dip->has_at_byte_size)
2476 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2477 STRUCT_NAMESPACE, LOC_TYPEDEF,
2478 &objfile->static_psymbols,
2479 0, 0, cu_language, objfile);
2480 if (cu_language == language_cplus)
2482 /* For C++, these implicitly act as typedefs as well. */
2483 add_psymbol_to_list (dip->at_name, strlen (dip->at_name),
2484 VAR_NAMESPACE, LOC_TYPEDEF,
2485 &objfile->static_psymbols,
2486 0, 0, cu_language, objfile);
2496 scan_partial_symbols -- scan DIE's within a single compilation unit
2500 Process the DIE's within a single compilation unit, looking for
2501 interesting DIE's that contribute to the partial symbol table entry
2502 for this compilation unit.
2506 There are some DIE's that may appear both at file scope and within
2507 the scope of a function. We are only interested in the ones at file
2508 scope, and the only way to tell them apart is to keep track of the
2509 scope. For example, consider the test case:
2514 for which the relevant DWARF segment has the structure:
2517 0x23 global subrtn sibling 0x9b
2519 fund_type FT_integer
2524 0x23 local var sibling 0x97
2526 fund_type FT_integer
2527 location OP_BASEREG 0xe
2534 0x1d local var sibling 0xb8
2536 fund_type FT_integer
2537 location OP_ADDR 0x800025dc
2542 We want to include the symbol 'i' in the partial symbol table, but
2543 not the symbol 'j'. In essence, we want to skip all the dies within
2544 the scope of a TAG_global_subroutine DIE.
2546 Don't attempt to add anonymous structures or unions since they have
2547 no name. Anonymous enumerations however are processed, because we
2548 want to extract their member names (the check for a tag name is
2551 Also, for variables and subroutines, check that this is the place
2552 where the actual definition occurs, rather than just a reference
2560 scan_partial_symbols (char *thisdie, char *enddie, struct objfile *objfile)
2566 while (thisdie < enddie)
2568 basicdieinfo (&di, thisdie, objfile);
2569 if (di.die_length < SIZEOF_DIE_LENGTH)
2575 nextdie = thisdie + di.die_length;
2576 /* To avoid getting complete die information for every die, we
2577 only do it (below) for the cases we are interested in. */
2580 case TAG_global_subroutine:
2581 case TAG_subroutine:
2582 completedieinfo (&di, objfile);
2583 if (di.at_name && (di.has_at_low_pc || di.at_location))
2585 add_partial_symbol (&di, objfile);
2586 /* If there is a sibling attribute, adjust the nextdie
2587 pointer to skip the entire scope of the subroutine.
2588 Apply some sanity checking to make sure we don't
2589 overrun or underrun the range of remaining DIE's */
2590 if (di.at_sibling != 0)
2592 temp = dbbase + di.at_sibling - dbroff;
2593 if ((temp < thisdie) || (temp >= enddie))
2595 bad_die_ref_complaint (DIE_ID, DIE_NAME,
2605 case TAG_global_variable:
2606 case TAG_local_variable:
2607 completedieinfo (&di, objfile);
2608 if (di.at_name && (di.has_at_low_pc || di.at_location))
2610 add_partial_symbol (&di, objfile);
2614 case TAG_class_type:
2615 case TAG_structure_type:
2616 case TAG_union_type:
2617 completedieinfo (&di, objfile);
2620 add_partial_symbol (&di, objfile);
2623 case TAG_enumeration_type:
2624 completedieinfo (&di, objfile);
2627 add_partial_symbol (&di, objfile);
2629 add_enum_psymbol (&di, objfile);
2641 scan_compilation_units -- build a psymtab entry for each compilation
2645 This is the top level dwarf parsing routine for building partial
2648 It scans from the beginning of the DWARF table looking for the first
2649 TAG_compile_unit DIE, and then follows the sibling chain to locate
2650 each additional TAG_compile_unit DIE.
2652 For each TAG_compile_unit DIE it creates a partial symtab structure,
2653 calls a subordinate routine to collect all the compilation unit's
2654 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2655 new partial symtab structure into the partial symbol table. It also
2656 records the appropriate information in the partial symbol table entry
2657 to allow the chunk of DIE's and line number table for this compilation
2658 unit to be located and re-read later, to generate a complete symbol
2659 table entry for the compilation unit.
2661 Thus it effectively partitions up a chunk of DIE's for multiple
2662 compilation units into smaller DIE chunks and line number tables,
2663 and associates them with a partial symbol table entry.
2667 If any compilation unit has no line number table associated with
2668 it for some reason (a missing at_stmt_list attribute, rather than
2669 just one with a value of zero, which is valid) then we ensure that
2670 the recorded file offset is zero so that the routine which later
2671 reads line number table fragments knows that there is no fragment
2681 scan_compilation_units (char *thisdie, char *enddie, file_ptr dbfoff,
2682 file_ptr lnoffset, struct objfile *objfile)
2686 struct partial_symtab *pst;
2689 file_ptr curlnoffset;
2691 while (thisdie < enddie)
2693 basicdieinfo (&di, thisdie, objfile);
2694 if (di.die_length < SIZEOF_DIE_LENGTH)
2698 else if (di.die_tag != TAG_compile_unit)
2700 nextdie = thisdie + di.die_length;
2704 completedieinfo (&di, objfile);
2705 set_cu_language (&di);
2706 if (di.at_sibling != 0)
2708 nextdie = dbbase + di.at_sibling - dbroff;
2712 nextdie = thisdie + di.die_length;
2714 curoff = thisdie - dbbase;
2715 culength = nextdie - thisdie;
2716 curlnoffset = di.has_at_stmt_list ? lnoffset + di.at_stmt_list : 0;
2718 /* First allocate a new partial symbol table structure */
2720 pst = start_psymtab_common (objfile, base_section_offsets,
2721 di.at_name, di.at_low_pc,
2722 objfile->global_psymbols.next,
2723 objfile->static_psymbols.next);
2725 pst->texthigh = di.at_high_pc;
2726 pst->read_symtab_private = (char *)
2727 obstack_alloc (&objfile->psymbol_obstack,
2728 sizeof (struct dwfinfo));
2729 DBFOFF (pst) = dbfoff;
2730 DBROFF (pst) = curoff;
2731 DBLENGTH (pst) = culength;
2732 LNFOFF (pst) = curlnoffset;
2733 pst->read_symtab = dwarf_psymtab_to_symtab;
2735 /* Now look for partial symbols */
2737 scan_partial_symbols (thisdie + di.die_length, nextdie, objfile);
2739 pst->n_global_syms = objfile->global_psymbols.next -
2740 (objfile->global_psymbols.list + pst->globals_offset);
2741 pst->n_static_syms = objfile->static_psymbols.next -
2742 (objfile->static_psymbols.list + pst->statics_offset);
2743 sort_pst_symbols (pst);
2744 /* If there is already a psymtab or symtab for a file of this name,
2745 remove it. (If there is a symtab, more drastic things also
2746 happen.) This happens in VxWorks. */
2747 free_named_symtabs (pst->filename);
2757 new_symbol -- make a symbol table entry for a new symbol
2761 static struct symbol *new_symbol (struct dieinfo *dip,
2762 struct objfile *objfile)
2766 Given a pointer to a DWARF information entry, figure out if we need
2767 to make a symbol table entry for it, and if so, create a new entry
2768 and return a pointer to it.
2771 static struct symbol *
2772 new_symbol (struct dieinfo *dip, struct objfile *objfile)
2774 struct symbol *sym = NULL;
2776 if (dip->at_name != NULL)
2778 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
2779 sizeof (struct symbol));
2780 OBJSTAT (objfile, n_syms++);
2781 memset (sym, 0, sizeof (struct symbol));
2782 SYMBOL_NAME (sym) = create_name (dip->at_name,
2783 &objfile->symbol_obstack);
2784 /* default assumptions */
2785 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2786 SYMBOL_CLASS (sym) = LOC_STATIC;
2787 SYMBOL_TYPE (sym) = decode_die_type (dip);
2789 /* If this symbol is from a C++ compilation, then attempt to cache the
2790 demangled form for future reference. This is a typical time versus
2791 space tradeoff, that was decided in favor of time because it sped up
2792 C++ symbol lookups by a factor of about 20. */
2794 SYMBOL_LANGUAGE (sym) = cu_language;
2795 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
2796 switch (dip->die_tag)
2799 SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
2800 SYMBOL_CLASS (sym) = LOC_LABEL;
2802 case TAG_global_subroutine:
2803 case TAG_subroutine:
2804 SYMBOL_VALUE_ADDRESS (sym) = dip->at_low_pc;
2805 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
2806 if (dip->at_prototyped)
2807 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
2808 SYMBOL_CLASS (sym) = LOC_BLOCK;
2809 if (dip->die_tag == TAG_global_subroutine)
2811 add_symbol_to_list (sym, &global_symbols);
2815 add_symbol_to_list (sym, list_in_scope);
2818 case TAG_global_variable:
2819 if (dip->at_location != NULL)
2821 SYMBOL_VALUE_ADDRESS (sym) = locval (dip);
2822 add_symbol_to_list (sym, &global_symbols);
2823 SYMBOL_CLASS (sym) = LOC_STATIC;
2824 SYMBOL_VALUE (sym) += baseaddr;
2827 case TAG_local_variable:
2828 if (dip->at_location != NULL)
2830 int loc = locval (dip);
2831 if (dip->optimized_out)
2833 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
2835 else if (dip->isreg)
2837 SYMBOL_CLASS (sym) = LOC_REGISTER;
2839 else if (dip->offreg)
2841 SYMBOL_CLASS (sym) = LOC_BASEREG;
2842 SYMBOL_BASEREG (sym) = dip->basereg;
2846 SYMBOL_CLASS (sym) = LOC_STATIC;
2847 SYMBOL_VALUE (sym) += baseaddr;
2849 if (SYMBOL_CLASS (sym) == LOC_STATIC)
2851 /* LOC_STATIC address class MUST use SYMBOL_VALUE_ADDRESS,
2852 which may store to a bigger location than SYMBOL_VALUE. */
2853 SYMBOL_VALUE_ADDRESS (sym) = loc;
2857 SYMBOL_VALUE (sym) = loc;
2859 add_symbol_to_list (sym, list_in_scope);
2862 case TAG_formal_parameter:
2863 if (dip->at_location != NULL)
2865 SYMBOL_VALUE (sym) = locval (dip);
2867 add_symbol_to_list (sym, list_in_scope);
2870 SYMBOL_CLASS (sym) = LOC_REGPARM;
2872 else if (dip->offreg)
2874 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
2875 SYMBOL_BASEREG (sym) = dip->basereg;
2879 SYMBOL_CLASS (sym) = LOC_ARG;
2882 case TAG_unspecified_parameters:
2883 /* From varargs functions; gdb doesn't seem to have any interest in
2884 this information, so just ignore it for now. (FIXME?) */
2886 case TAG_class_type:
2887 case TAG_structure_type:
2888 case TAG_union_type:
2889 case TAG_enumeration_type:
2890 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2891 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2892 add_symbol_to_list (sym, list_in_scope);
2895 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2896 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2897 add_symbol_to_list (sym, list_in_scope);
2900 /* Not a tag we recognize. Hopefully we aren't processing trash
2901 data, but since we must specifically ignore things we don't
2902 recognize, there is nothing else we should do at this point. */
2913 synthesize_typedef -- make a symbol table entry for a "fake" typedef
2917 static void synthesize_typedef (struct dieinfo *dip,
2918 struct objfile *objfile,
2923 Given a pointer to a DWARF information entry, synthesize a typedef
2924 for the name in the DIE, using the specified type.
2926 This is used for C++ class, structs, unions, and enumerations to
2927 set up the tag name as a type.
2932 synthesize_typedef (struct dieinfo *dip, struct objfile *objfile,
2935 struct symbol *sym = NULL;
2937 if (dip->at_name != NULL)
2939 sym = (struct symbol *)
2940 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2941 OBJSTAT (objfile, n_syms++);
2942 memset (sym, 0, sizeof (struct symbol));
2943 SYMBOL_NAME (sym) = create_name (dip->at_name,
2944 &objfile->symbol_obstack);
2945 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
2946 SYMBOL_TYPE (sym) = type;
2947 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2948 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2949 add_symbol_to_list (sym, list_in_scope);
2957 decode_mod_fund_type -- decode a modified fundamental type
2961 static struct type *decode_mod_fund_type (char *typedata)
2965 Decode a block of data containing a modified fundamental
2966 type specification. TYPEDATA is a pointer to the block,
2967 which starts with a length containing the size of the rest
2968 of the block. At the end of the block is a fundmental type
2969 code value that gives the fundamental type. Everything
2970 in between are type modifiers.
2972 We simply compute the number of modifiers and call the general
2973 function decode_modified_type to do the actual work.
2976 static struct type *
2977 decode_mod_fund_type (char *typedata)
2979 struct type *typep = NULL;
2980 unsigned short modcount;
2983 /* Get the total size of the block, exclusive of the size itself */
2985 nbytes = attribute_size (AT_mod_fund_type);
2986 modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
2989 /* Deduct the size of the fundamental type bytes at the end of the block. */
2991 modcount -= attribute_size (AT_fund_type);
2993 /* Now do the actual decoding */
2995 typep = decode_modified_type (typedata, modcount, AT_mod_fund_type);
3003 decode_mod_u_d_type -- decode a modified user defined type
3007 static struct type *decode_mod_u_d_type (char *typedata)
3011 Decode a block of data containing a modified user defined
3012 type specification. TYPEDATA is a pointer to the block,
3013 which consists of a two byte length, containing the size
3014 of the rest of the block. At the end of the block is a
3015 four byte value that gives a reference to a user defined type.
3016 Everything in between are type modifiers.
3018 We simply compute the number of modifiers and call the general
3019 function decode_modified_type to do the actual work.
3022 static struct type *
3023 decode_mod_u_d_type (char *typedata)
3025 struct type *typep = NULL;
3026 unsigned short modcount;
3029 /* Get the total size of the block, exclusive of the size itself */
3031 nbytes = attribute_size (AT_mod_u_d_type);
3032 modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
3035 /* Deduct the size of the reference type bytes at the end of the block. */
3037 modcount -= attribute_size (AT_user_def_type);
3039 /* Now do the actual decoding */
3041 typep = decode_modified_type (typedata, modcount, AT_mod_u_d_type);
3049 decode_modified_type -- decode modified user or fundamental type
3053 static struct type *decode_modified_type (char *modifiers,
3054 unsigned short modcount, int mtype)
3058 Decode a modified type, either a modified fundamental type or
3059 a modified user defined type. MODIFIERS is a pointer to the
3060 block of bytes that define MODCOUNT modifiers. Immediately
3061 following the last modifier is a short containing the fundamental
3062 type or a long containing the reference to the user defined
3063 type. Which one is determined by MTYPE, which is either
3064 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
3065 type we are generating.
3067 We call ourself recursively to generate each modified type,`
3068 until MODCOUNT reaches zero, at which point we have consumed
3069 all the modifiers and generate either the fundamental type or
3070 user defined type. When the recursion unwinds, each modifier
3071 is applied in turn to generate the full modified type.
3075 If we find a modifier that we don't recognize, and it is not one
3076 of those reserved for application specific use, then we issue a
3077 warning and simply ignore the modifier.
3081 We currently ignore MOD_const and MOD_volatile. (FIXME)
3085 static struct type *
3086 decode_modified_type (char *modifiers, unsigned int modcount, int mtype)
3088 struct type *typep = NULL;
3089 unsigned short fundtype;
3098 case AT_mod_fund_type:
3099 nbytes = attribute_size (AT_fund_type);
3100 fundtype = target_to_host (modifiers, nbytes, GET_UNSIGNED,
3102 typep = decode_fund_type (fundtype);
3104 case AT_mod_u_d_type:
3105 nbytes = attribute_size (AT_user_def_type);
3106 die_ref = target_to_host (modifiers, nbytes, GET_UNSIGNED,
3108 if ((typep = lookup_utype (die_ref)) == NULL)
3110 typep = alloc_utype (die_ref, NULL);
3114 complaint (&symfile_complaints,
3115 "DIE @ 0x%x \"%s\", botched modified type decoding (mtype 0x%x)",
3116 DIE_ID, DIE_NAME, mtype);
3117 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
3123 modifier = *modifiers++;
3124 typep = decode_modified_type (modifiers, --modcount, mtype);
3127 case MOD_pointer_to:
3128 typep = lookup_pointer_type (typep);
3130 case MOD_reference_to:
3131 typep = lookup_reference_type (typep);
3134 complaint (&symfile_complaints,
3135 "DIE @ 0x%x \"%s\", type modifier 'const' ignored", DIE_ID,
3136 DIE_NAME); /* FIXME */
3139 complaint (&symfile_complaints,
3140 "DIE @ 0x%x \"%s\", type modifier 'volatile' ignored",
3141 DIE_ID, DIE_NAME); /* FIXME */
3144 if (!(MOD_lo_user <= (unsigned char) modifier
3145 && (unsigned char) modifier <= MOD_hi_user))
3147 complaint (&symfile_complaints,
3148 "DIE @ 0x%x \"%s\", unknown type modifier %u", DIE_ID,
3149 DIE_NAME, modifier);
3161 decode_fund_type -- translate basic DWARF type to gdb base type
3165 Given an integer that is one of the fundamental DWARF types,
3166 translate it to one of the basic internal gdb types and return
3167 a pointer to the appropriate gdb type (a "struct type *").
3171 For robustness, if we are asked to translate a fundamental
3172 type that we are unprepared to deal with, we return int so
3173 callers can always depend upon a valid type being returned,
3174 and so gdb may at least do something reasonable by default.
3175 If the type is not in the range of those types defined as
3176 application specific types, we also issue a warning.
3179 static struct type *
3180 decode_fund_type (unsigned int fundtype)
3182 struct type *typep = NULL;
3188 typep = dwarf_fundamental_type (current_objfile, FT_VOID);
3191 case FT_boolean: /* Was FT_set in AT&T version */
3192 typep = dwarf_fundamental_type (current_objfile, FT_BOOLEAN);
3195 case FT_pointer: /* (void *) */
3196 typep = dwarf_fundamental_type (current_objfile, FT_VOID);
3197 typep = lookup_pointer_type (typep);
3201 typep = dwarf_fundamental_type (current_objfile, FT_CHAR);
3204 case FT_signed_char:
3205 typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3208 case FT_unsigned_char:
3209 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3213 typep = dwarf_fundamental_type (current_objfile, FT_SHORT);
3216 case FT_signed_short:
3217 typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_SHORT);
3220 case FT_unsigned_short:
3221 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
3225 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
3228 case FT_signed_integer:
3229 typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3232 case FT_unsigned_integer:
3233 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
3237 typep = dwarf_fundamental_type (current_objfile, FT_LONG);
3240 case FT_signed_long:
3241 typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG);
3244 case FT_unsigned_long:
3245 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
3249 typep = dwarf_fundamental_type (current_objfile, FT_LONG_LONG);
3252 case FT_signed_long_long:
3253 typep = dwarf_fundamental_type (current_objfile, FT_SIGNED_LONG_LONG);
3256 case FT_unsigned_long_long:
3257 typep = dwarf_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG);
3261 typep = dwarf_fundamental_type (current_objfile, FT_FLOAT);
3264 case FT_dbl_prec_float:
3265 typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
3268 case FT_ext_prec_float:
3269 typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
3273 typep = dwarf_fundamental_type (current_objfile, FT_COMPLEX);
3276 case FT_dbl_prec_complex:
3277 typep = dwarf_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
3280 case FT_ext_prec_complex:
3281 typep = dwarf_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX);
3288 typep = dwarf_fundamental_type (current_objfile, FT_INTEGER);
3289 if (!(FT_lo_user <= fundtype && fundtype <= FT_hi_user))
3291 complaint (&symfile_complaints,
3292 "DIE @ 0x%x \"%s\", unexpected fundamental type 0x%x",
3293 DIE_ID, DIE_NAME, fundtype);
3304 create_name -- allocate a fresh copy of a string on an obstack
3308 Given a pointer to a string and a pointer to an obstack, allocates
3309 a fresh copy of the string on the specified obstack.
3314 create_name (char *name, struct obstack *obstackp)
3319 length = strlen (name) + 1;
3320 newname = (char *) obstack_alloc (obstackp, length);
3321 strcpy (newname, name);
3329 basicdieinfo -- extract the minimal die info from raw die data
3333 void basicdieinfo (char *diep, struct dieinfo *dip,
3334 struct objfile *objfile)
3338 Given a pointer to raw DIE data, and a pointer to an instance of a
3339 die info structure, this function extracts the basic information
3340 from the DIE data required to continue processing this DIE, along
3341 with some bookkeeping information about the DIE.
3343 The information we absolutely must have includes the DIE tag,
3344 and the DIE length. If we need the sibling reference, then we
3345 will have to call completedieinfo() to process all the remaining
3348 Note that since there is no guarantee that the data is properly
3349 aligned in memory for the type of access required (indirection
3350 through anything other than a char pointer), and there is no
3351 guarantee that it is in the same byte order as the gdb host,
3352 we call a function which deals with both alignment and byte
3353 swapping issues. Possibly inefficient, but quite portable.
3355 We also take care of some other basic things at this point, such
3356 as ensuring that the instance of the die info structure starts
3357 out completely zero'd and that curdie is initialized for use
3358 in error reporting if we have a problem with the current die.
3362 All DIE's must have at least a valid length, thus the minimum
3363 DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the
3364 DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
3365 are forced to be TAG_padding DIES.
3367 Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
3368 that if a padding DIE is used for alignment and the amount needed is
3369 less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
3370 enough to align to the next alignment boundry.
3372 We do some basic sanity checking here, such as verifying that the
3373 length of the die would not cause it to overrun the recorded end of
3374 the buffer holding the DIE info. If we find a DIE that is either
3375 too small or too large, we force it's length to zero which should
3376 cause the caller to take appropriate action.
3380 basicdieinfo (struct dieinfo *dip, char *diep, struct objfile *objfile)
3383 memset (dip, 0, sizeof (struct dieinfo));
3385 dip->die_ref = dbroff + (diep - dbbase);
3386 dip->die_length = target_to_host (diep, SIZEOF_DIE_LENGTH, GET_UNSIGNED,
3388 if ((dip->die_length < SIZEOF_DIE_LENGTH) ||
3389 ((diep + dip->die_length) > (dbbase + dbsize)))
3391 complaint (&symfile_complaints,
3392 "DIE @ 0x%x \"%s\", malformed DIE, bad length (%ld bytes)",
3393 DIE_ID, DIE_NAME, dip->die_length);
3394 dip->die_length = 0;
3396 else if (dip->die_length < (SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG))
3398 dip->die_tag = TAG_padding;
3402 diep += SIZEOF_DIE_LENGTH;
3403 dip->die_tag = target_to_host (diep, SIZEOF_DIE_TAG, GET_UNSIGNED,
3412 completedieinfo -- finish reading the information for a given DIE
3416 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3420 Given a pointer to an already partially initialized die info structure,
3421 scan the raw DIE data and finish filling in the die info structure
3422 from the various attributes found.
3424 Note that since there is no guarantee that the data is properly
3425 aligned in memory for the type of access required (indirection
3426 through anything other than a char pointer), and there is no
3427 guarantee that it is in the same byte order as the gdb host,
3428 we call a function which deals with both alignment and byte
3429 swapping issues. Possibly inefficient, but quite portable.
3433 Each time we are called, we increment the diecount variable, which
3434 keeps an approximate count of the number of dies processed for
3435 each compilation unit. This information is presented to the user
3436 if the info_verbose flag is set.
3441 completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3443 char *diep; /* Current pointer into raw DIE data */
3444 char *end; /* Terminate DIE scan here */
3445 unsigned short attr; /* Current attribute being scanned */
3446 unsigned short form; /* Form of the attribute */
3447 int nbytes; /* Size of next field to read */
3451 end = diep + dip->die_length;
3452 diep += SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG;
3455 attr = target_to_host (diep, SIZEOF_ATTRIBUTE, GET_UNSIGNED, objfile);
3456 diep += SIZEOF_ATTRIBUTE;
3457 if ((nbytes = attribute_size (attr)) == -1)
3459 complaint (&symfile_complaints,
3460 "DIE @ 0x%x \"%s\", unknown attribute length, skipped remaining attributes",
3468 dip->at_fund_type = target_to_host (diep, nbytes, GET_UNSIGNED,
3472 dip->at_ordering = target_to_host (diep, nbytes, GET_UNSIGNED,
3476 dip->at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED,
3480 dip->at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED,
3484 dip->at_stmt_list = target_to_host (diep, nbytes, GET_UNSIGNED,
3486 dip->has_at_stmt_list = 1;
3489 dip->at_low_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
3491 dip->at_low_pc += baseaddr;
3492 dip->has_at_low_pc = 1;
3495 dip->at_high_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
3497 dip->at_high_pc += baseaddr;
3500 dip->at_language = target_to_host (diep, nbytes, GET_UNSIGNED,
3503 case AT_user_def_type:
3504 dip->at_user_def_type = target_to_host (diep, nbytes,
3505 GET_UNSIGNED, objfile);
3508 dip->at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3510 dip->has_at_byte_size = 1;
3513 dip->at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3517 dip->at_member = target_to_host (diep, nbytes, GET_UNSIGNED,
3521 dip->at_discr = target_to_host (diep, nbytes, GET_UNSIGNED,
3525 dip->at_location = diep;
3527 case AT_mod_fund_type:
3528 dip->at_mod_fund_type = diep;
3530 case AT_subscr_data:
3531 dip->at_subscr_data = diep;
3533 case AT_mod_u_d_type:
3534 dip->at_mod_u_d_type = diep;
3536 case AT_element_list:
3537 dip->at_element_list = diep;
3538 dip->short_element_list = 0;
3540 case AT_short_element_list:
3541 dip->at_element_list = diep;
3542 dip->short_element_list = 1;
3544 case AT_discr_value:
3545 dip->at_discr_value = diep;
3547 case AT_string_length:
3548 dip->at_string_length = diep;
3551 dip->at_name = diep;
3554 /* For now, ignore any "hostname:" portion, since gdb doesn't
3555 know how to deal with it. (FIXME). */
3556 dip->at_comp_dir = strrchr (diep, ':');
3557 if (dip->at_comp_dir != NULL)
3563 dip->at_comp_dir = diep;
3567 dip->at_producer = diep;
3569 case AT_start_scope:
3570 dip->at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED,
3573 case AT_stride_size:
3574 dip->at_stride_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3578 dip->at_src_info = target_to_host (diep, nbytes, GET_UNSIGNED,
3582 dip->at_prototyped = diep;
3585 /* Found an attribute that we are unprepared to handle. However
3586 it is specifically one of the design goals of DWARF that
3587 consumers should ignore unknown attributes. As long as the
3588 form is one that we recognize (so we know how to skip it),
3589 we can just ignore the unknown attribute. */
3592 form = FORM_FROM_ATTR (attr);
3606 diep += TARGET_FT_POINTER_SIZE (objfile);
3609 diep += 2 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
3612 diep += 4 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
3615 diep += strlen (diep) + 1;
3618 unknown_attribute_form_complaint (DIE_ID, DIE_NAME, form);
3629 target_to_host -- swap in target data to host
3633 target_to_host (char *from, int nbytes, int signextend,
3634 struct objfile *objfile)
3638 Given pointer to data in target format in FROM, a byte count for
3639 the size of the data in NBYTES, a flag indicating whether or not
3640 the data is signed in SIGNEXTEND, and a pointer to the current
3641 objfile in OBJFILE, convert the data to host format and return
3642 the converted value.
3646 FIXME: If we read data that is known to be signed, and expect to
3647 use it as signed data, then we need to explicitly sign extend the
3648 result until the bfd library is able to do this for us.
3650 FIXME: Would a 32 bit target ever need an 8 byte result?
3655 target_to_host (char *from, int nbytes, int signextend, /* FIXME: Unused */
3656 struct objfile *objfile)
3663 rtnval = bfd_get_64 (objfile->obfd, (bfd_byte *) from);
3666 rtnval = bfd_get_32 (objfile->obfd, (bfd_byte *) from);
3669 rtnval = bfd_get_16 (objfile->obfd, (bfd_byte *) from);
3672 rtnval = bfd_get_8 (objfile->obfd, (bfd_byte *) from);
3675 complaint (&symfile_complaints,
3676 "DIE @ 0x%x \"%s\", no bfd support for %d byte data object",
3677 DIE_ID, DIE_NAME, nbytes);
3688 attribute_size -- compute size of data for a DWARF attribute
3692 static int attribute_size (unsigned int attr)
3696 Given a DWARF attribute in ATTR, compute the size of the first
3697 piece of data associated with this attribute and return that
3700 Returns -1 for unrecognized attributes.
3705 attribute_size (unsigned int attr)
3707 int nbytes; /* Size of next data for this attribute */
3708 unsigned short form; /* Form of the attribute */
3710 form = FORM_FROM_ATTR (attr);
3713 case FORM_STRING: /* A variable length field is next */
3716 case FORM_DATA2: /* Next 2 byte field is the data itself */
3717 case FORM_BLOCK2: /* Next 2 byte field is a block length */
3720 case FORM_DATA4: /* Next 4 byte field is the data itself */
3721 case FORM_BLOCK4: /* Next 4 byte field is a block length */
3722 case FORM_REF: /* Next 4 byte field is a DIE offset */
3725 case FORM_DATA8: /* Next 8 byte field is the data itself */
3728 case FORM_ADDR: /* Next field size is target sizeof(void *) */
3729 nbytes = TARGET_FT_POINTER_SIZE (objfile);
3732 unknown_attribute_form_complaint (DIE_ID, DIE_NAME, form);