1 /* DWARF debugging format support for GDB.
2 Copyright (C) 1991, 1992 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support. Portions based on dbxread.c,
4 mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 FIXME: Figure out how to get the frame pointer register number in the
25 execution environment of the target. Remove R_FP kludge
27 FIXME: Add generation of dependencies list to partial symtab code.
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. :-)
53 #include "libbfd.h" /* FIXME Secret Internal BFD stuff (bfd_read) */
54 #include "elf/dwarf.h"
58 #ifdef MAINTENANCE /* Define to 1 to compile in some maintenance stuff */
59 #define SQUAWK(stuff) dwarfwarn stuff
64 #ifndef R_FP /* FIXME */
65 #define R_FP 14 /* Kludge to get frame pointer register number */
68 typedef unsigned int DIE_REF; /* Reference to a DIE */
71 #define GCC_PRODUCER "GNU C "
74 #ifndef GPLUS_PRODUCER
75 #define GPLUS_PRODUCER "GNU C++ "
79 #define LCC_PRODUCER "NCR C/C++ "
82 #ifndef CFRONT_PRODUCER
83 #define CFRONT_PRODUCER "CFRONT " /* A wild a** guess... */
86 #define STREQ(a,b) (strcmp(a,b)==0)
87 #define STREQN(a,b,n) (strncmp(a,b,n)==0)
89 /* Flags to target_to_host() that tell whether or not the data object is
90 expected to be signed. Used, for example, when fetching a signed
91 integer in the target environment which is used as a signed integer
92 in the host environment, and the two environments have different sized
93 ints. In this case, *somebody* has to sign extend the smaller sized
96 #define GET_UNSIGNED 0 /* No sign extension required */
97 #define GET_SIGNED 1 /* Sign extension required */
99 /* Defines for things which are specified in the document "DWARF Debugging
100 Information Format" published by UNIX International, Programming Languages
101 SIG. These defines are based on revision 1.0.0, Jan 20, 1992. */
103 #define SIZEOF_DIE_LENGTH 4
104 #define SIZEOF_DIE_TAG 2
105 #define SIZEOF_ATTRIBUTE 2
106 #define SIZEOF_FORMAT_SPECIFIER 1
107 #define SIZEOF_FMT_FT 2
108 #define SIZEOF_LINETBL_LENGTH 4
109 #define SIZEOF_LINETBL_LINENO 4
110 #define SIZEOF_LINETBL_STMT 2
111 #define SIZEOF_LINETBL_DELTA 4
112 #define SIZEOF_LOC_ATOM_CODE 1
114 #define FORM_FROM_ATTR(attr) ((attr) & 0xF) /* Implicitly specified */
116 /* Macros that return the sizes of various types of data in the target
119 FIXME: Currently these are just compile time constants (as they are in
120 other parts of gdb as well). They need to be able to get the right size
121 either from the bfd or possibly from the DWARF info. It would be nice if
122 the DWARF producer inserted DIES that describe the fundamental types in
123 the target environment into the DWARF info, similar to the way dbx stabs
124 producers produce information about their fundamental types. */
126 #define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
127 #define TARGET_FT_LONG_SIZE(objfile) (TARGET_LONG_BIT / TARGET_CHAR_BIT)
129 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
130 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
131 However, the Issue 2 DWARF specification from AT&T defines it as
132 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
133 For backwards compatibility with the AT&T compiler produced executables
134 we define AT_short_element_list for this variant. */
136 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
138 /* External variables referenced. */
140 extern int info_verbose; /* From main.c; nonzero => verbose */
141 extern char *warning_pre_print; /* From utils.c */
143 /* The DWARF debugging information consists of two major pieces,
144 one is a block of DWARF Information Entries (DIE's) and the other
145 is a line number table. The "struct dieinfo" structure contains
146 the information for a single DIE, the one currently being processed.
148 In order to make it easier to randomly access the attribute fields
149 of the current DIE, which are specifically unordered within the DIE,
150 each DIE is scanned and an instance of the "struct dieinfo"
151 structure is initialized.
153 Initialization is done in two levels. The first, done by basicdieinfo(),
154 just initializes those fields that are vital to deciding whether or not
155 to use this DIE, how to skip past it, etc. The second, done by the
156 function completedieinfo(), fills in the rest of the information.
158 Attributes which have block forms are not interpreted at the time
159 the DIE is scanned, instead we just save pointers to the start
160 of their value fields.
162 Some fields have a flag <name>_p that is set when the value of the
163 field is valid (I.E. we found a matching attribute in the DIE). Since
164 we may want to test for the presence of some attributes in the DIE,
165 such as AT_low_pc, without restricting the values of the field,
166 we need someway to note that we found such an attribute.
173 char * die; /* Pointer to the raw DIE data */
174 unsigned long die_length; /* Length of the raw DIE data */
175 DIE_REF die_ref; /* Offset of this DIE */
176 unsigned short die_tag; /* Tag for this DIE */
177 unsigned long at_padding;
178 unsigned long at_sibling;
181 unsigned short at_fund_type;
182 BLOCK * at_mod_fund_type;
183 unsigned long at_user_def_type;
184 BLOCK * at_mod_u_d_type;
185 unsigned short at_ordering;
186 BLOCK * at_subscr_data;
187 unsigned long at_byte_size;
188 unsigned short at_bit_offset;
189 unsigned long at_bit_size;
190 BLOCK * at_element_list;
191 unsigned long at_stmt_list;
192 unsigned long at_low_pc;
193 unsigned long at_high_pc;
194 unsigned long at_language;
195 unsigned long at_member;
196 unsigned long at_discr;
197 BLOCK * at_discr_value;
198 BLOCK * at_string_length;
201 unsigned long at_start_scope;
202 unsigned long at_stride_size;
203 unsigned long at_src_info;
204 char * at_prototyped;
205 unsigned int has_at_low_pc:1;
206 unsigned int has_at_stmt_list:1;
207 unsigned int has_at_byte_size:1;
208 unsigned int short_element_list:1;
211 static int diecount; /* Approximate count of dies for compilation unit */
212 static struct dieinfo *curdie; /* For warnings and such */
214 static char *dbbase; /* Base pointer to dwarf info */
215 static int dbroff; /* Relative offset from start of .debug section */
216 static char *lnbase; /* Base pointer to line section */
217 static int isreg; /* Kludge to identify register variables */
218 static int offreg; /* Kludge to identify basereg references */
220 /* This value is added to each symbol value. FIXME: Generalize to
221 the section_offsets structure used by dbxread. */
222 static CORE_ADDR baseaddr; /* Add to each symbol value */
224 /* The section offsets used in the current psymtab or symtab. FIXME,
225 only used to pass one value (baseaddr) at the moment. */
226 static struct section_offsets *base_section_offsets;
228 /* Each partial symbol table entry contains a pointer to private data for the
229 read_symtab() function to use when expanding a partial symbol table entry
230 to a full symbol table entry. For DWARF debugging info, this data is
231 contained in the following structure and macros are provided for easy
232 access to the members given a pointer to a partial symbol table entry.
234 dbfoff Always the absolute file offset to the start of the ".debug"
235 section for the file containing the DIE's being accessed.
237 dbroff Relative offset from the start of the ".debug" access to the
238 first DIE to be accessed. When building the partial symbol
239 table, this value will be zero since we are accessing the
240 entire ".debug" section. When expanding a partial symbol
241 table entry, this value will be the offset to the first
242 DIE for the compilation unit containing the symbol that
243 triggers the expansion.
245 dblength The size of the chunk of DIE's being examined, in bytes.
247 lnfoff The absolute file offset to the line table fragment. Ignored
248 when building partial symbol tables, but used when expanding
249 them, and contains the absolute file offset to the fragment
250 of the ".line" section containing the line numbers for the
251 current compilation unit.
255 int dbfoff; /* Absolute file offset to start of .debug section */
256 int dbroff; /* Relative offset from start of .debug section */
257 int dblength; /* Size of the chunk of DIE's being examined */
258 int lnfoff; /* Absolute file offset to line table fragment */
261 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
262 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
263 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
264 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
266 /* The generic symbol table building routines have separate lists for
267 file scope symbols and all all other scopes (local scopes). So
268 we need to select the right one to pass to add_symbol_to_list().
269 We do it by keeping a pointer to the correct list in list_in_scope.
271 FIXME: The original dwarf code just treated the file scope as the first
272 local scope, and all other local scopes as nested local scopes, and worked
273 fine. Check to see if we really need to distinguish these in buildsym.c */
275 struct pending **list_in_scope = &file_symbols;
277 /* DIES which have user defined types or modified user defined types refer to
278 other DIES for the type information. Thus we need to associate the offset
279 of a DIE for a user defined type with a pointer to the type information.
281 Originally this was done using a simple but expensive algorithm, with an
282 array of unsorted structures, each containing an offset/type-pointer pair.
283 This array was scanned linearly each time a lookup was done. The result
284 was that gdb was spending over half it's startup time munging through this
285 array of pointers looking for a structure that had the right offset member.
287 The second attempt used the same array of structures, but the array was
288 sorted using qsort each time a new offset/type was recorded, and a binary
289 search was used to find the type pointer for a given DIE offset. This was
290 even slower, due to the overhead of sorting the array each time a new
291 offset/type pair was entered.
293 The third attempt uses a fixed size array of type pointers, indexed by a
294 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
295 we can divide any DIE offset by 4 to obtain a unique index into this fixed
296 size array. Since each element is a 4 byte pointer, it takes exactly as
297 much memory to hold this array as to hold the DWARF info for a given
298 compilation unit. But it gets freed as soon as we are done with it. */
300 static struct type **utypes; /* Pointer to array of user type pointers */
301 static int numutypes; /* Max number of user type pointers */
303 /* Forward declarations of static functions so we don't have to worry
304 about ordering within this file. */
307 attribute_size PARAMS ((unsigned int));
310 target_to_host PARAMS ((char *, int, int, struct objfile *));
313 add_enum_psymbol PARAMS ((struct dieinfo *, struct objfile *));
316 handle_producer PARAMS ((char *));
319 read_file_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
322 read_func_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
325 read_lexical_block_scope PARAMS ((struct dieinfo *, char *, char *,
332 scan_partial_symbols PARAMS ((char *, char *, struct objfile *));
335 scan_compilation_units PARAMS ((char *, char *, char *, unsigned int,
336 unsigned int, struct objfile *));
339 add_partial_symbol PARAMS ((struct dieinfo *, struct objfile *));
342 init_psymbol_list PARAMS ((struct objfile *, int));
345 basicdieinfo PARAMS ((struct dieinfo *, char *, struct objfile *));
348 completedieinfo PARAMS ((struct dieinfo *, struct objfile *));
351 dwarf_psymtab_to_symtab PARAMS ((struct partial_symtab *));
354 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
356 static struct symtab *
357 read_ofile_symtab PARAMS ((struct partial_symtab *));
360 process_dies PARAMS ((char *, char *, struct objfile *));
363 read_structure_scope PARAMS ((struct dieinfo *, char *, char *,
367 decode_array_element_type PARAMS ((char *));
370 decode_subscr_data PARAMS ((char *, char *));
373 dwarf_read_array_type PARAMS ((struct dieinfo *));
376 read_tag_pointer_type PARAMS ((struct dieinfo *dip));
379 read_subroutine_type PARAMS ((struct dieinfo *, char *, char *));
382 read_enumeration PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
385 struct_type PARAMS ((struct dieinfo *, char *, char *, struct objfile *));
388 enum_type PARAMS ((struct dieinfo *, struct objfile *));
391 decode_line_numbers PARAMS ((char *));
394 decode_die_type PARAMS ((struct dieinfo *));
397 decode_mod_fund_type PARAMS ((char *));
400 decode_mod_u_d_type PARAMS ((char *));
403 decode_modified_type PARAMS ((char *, unsigned int, int));
406 decode_fund_type PARAMS ((unsigned int));
409 create_name PARAMS ((char *, struct obstack *));
412 lookup_utype PARAMS ((DIE_REF));
415 alloc_utype PARAMS ((DIE_REF, struct type *));
417 static struct symbol *
418 new_symbol PARAMS ((struct dieinfo *, struct objfile *));
421 locval PARAMS ((char *));
424 record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type,
431 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
435 void dwarf_build_psymtabs (int desc, char *filename,
436 struct section_offsets *section_offsets,
437 int mainline, unsigned int dbfoff, unsigned int dbsize,
438 unsigned int lnoffset, unsigned int lnsize,
439 struct objfile *objfile)
443 This function is called upon to build partial symtabs from files
444 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
446 It is passed a file descriptor for an open file containing the DIES
447 and line number information, the corresponding filename for that
448 file, a base address for relocating the symbols, a flag indicating
449 whether or not this debugging information is from a "main symbol
450 table" rather than a shared library or dynamically linked file,
451 and file offset/size pairs for the DIE information and line number
461 dwarf_build_psymtabs (desc, filename, section_offsets, mainline, dbfoff, dbsize,
462 lnoffset, lnsize, objfile)
465 struct section_offsets *section_offsets;
469 unsigned int lnoffset;
471 struct objfile *objfile;
473 struct cleanup *back_to;
475 current_objfile = objfile;
476 dbbase = xmalloc (dbsize);
478 if ((lseek (desc, dbfoff, 0) != dbfoff) ||
479 (read (desc, dbbase, dbsize) != dbsize))
482 error ("can't read DWARF data from '%s'", filename);
484 back_to = make_cleanup (free, dbbase);
486 /* If we are reinitializing, or if we have never loaded syms yet, init.
487 Since we have no idea how many DIES we are looking at, we just guess
488 some arbitrary value. */
490 if (mainline || objfile -> global_psymbols.size == 0 ||
491 objfile -> static_psymbols.size == 0)
493 init_psymbol_list (objfile, 1024);
496 /* Save the relocation factor where everybody can see it. */
498 base_section_offsets = section_offsets;
499 baseaddr = ANOFFSET (section_offsets, 0);
501 /* Follow the compilation unit sibling chain, building a partial symbol
502 table entry for each one. Save enough information about each compilation
503 unit to locate the full DWARF information later. */
505 scan_compilation_units (filename, dbbase, dbbase + dbsize,
506 dbfoff, lnoffset, objfile);
508 do_cleanups (back_to);
509 current_objfile = NULL;
517 record_minimal_symbol -- add entry to gdb's minimal symbol table
521 static void record_minimal_symbol (char *name, CORE_ADDR address,
522 enum minimal_symbol_type ms_type,
523 struct objfile *objfile)
527 Given a pointer to the name of a symbol that should be added to the
528 minimal symbol table, and the address associated with that
529 symbol, records this information for later use in building the
530 minimal symbol table.
535 record_minimal_symbol (name, address, ms_type, objfile)
538 enum minimal_symbol_type ms_type;
539 struct objfile *objfile;
541 name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
542 prim_record_minimal_symbol (name, address, ms_type);
549 dwarfwarn -- issue a DWARF related warning
553 Issue warnings about DWARF related things that aren't serious enough
554 to warrant aborting with an error, but should not be ignored either.
555 This includes things like detectable corruption in DIE's, missing
556 DIE's, unimplemented features, etc.
558 In general, running across tags or attributes that we don't recognize
559 is not considered to be a problem and we should not issue warnings
564 We mostly follow the example of the error() routine, but without
565 returning to command level. It is arguable about whether warnings
566 should be issued at all, and if so, where they should go (stdout or
569 We assume that curdie is valid and contains at least the basic
570 information for the DIE where the problem was noticed.
581 fmt = va_arg (ap, char *);
583 fprintf (stderr, "warning: DWARF ref 0x%x: ", curdie -> die_ref);
584 if (curdie -> at_name)
586 fprintf (stderr, "'%s': ", curdie -> at_name);
588 vfprintf (stderr, fmt, ap);
589 fprintf (stderr, "\n");
598 read_lexical_block_scope -- process all dies in a lexical block
602 static void read_lexical_block_scope (struct dieinfo *dip,
603 char *thisdie, char *enddie)
607 Process all the DIES contained within a lexical block scope.
608 Start a new scope, process the dies, and then close the scope.
613 read_lexical_block_scope (dip, thisdie, enddie, objfile)
617 struct objfile *objfile;
619 register struct context_stack *new;
621 push_context (0, dip -> at_low_pc);
622 process_dies (thisdie + dip -> die_length, enddie, objfile);
623 new = pop_context ();
624 if (local_symbols != NULL)
626 finish_block (0, &local_symbols, new -> old_blocks, new -> start_addr,
627 dip -> at_high_pc, objfile);
629 local_symbols = new -> locals;
636 lookup_utype -- look up a user defined type from die reference
640 static type *lookup_utype (DIE_REF die_ref)
644 Given a DIE reference, lookup the user defined type associated with
645 that DIE, if it has been registered already. If not registered, then
646 return NULL. Alloc_utype() can be called to register an empty
647 type for this reference, which will be filled in later when the
648 actual referenced DIE is processed.
652 lookup_utype (die_ref)
655 struct type *type = NULL;
658 utypeidx = (die_ref - dbroff) / 4;
659 if ((utypeidx < 0) || (utypeidx >= numutypes))
661 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", die_ref);
665 type = *(utypes + utypeidx);
675 alloc_utype -- add a user defined type for die reference
679 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
683 Given a die reference DIE_REF, and a possible pointer to a user
684 defined type UTYPEP, register that this reference has a user
685 defined type and either use the specified type in UTYPEP or
686 make a new empty type that will be filled in later.
688 We should only be called after calling lookup_utype() to verify that
689 there is not currently a type registered for DIE_REF.
693 alloc_utype (die_ref, utypep)
700 utypeidx = (die_ref - dbroff) / 4;
701 typep = utypes + utypeidx;
702 if ((utypeidx < 0) || (utypeidx >= numutypes))
704 utypep = lookup_fundamental_type (current_objfile, FT_INTEGER);
705 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", die_ref);
707 else if (*typep != NULL)
710 SQUAWK (("internal error: dup user type allocation"));
716 utypep = alloc_type (current_objfile);
727 decode_die_type -- return a type for a specified die
731 static struct type *decode_die_type (struct dieinfo *dip)
735 Given a pointer to a die information structure DIP, decode the
736 type of the die and return a pointer to the decoded type. All
737 dies without specific types default to type int.
741 decode_die_type (dip)
744 struct type *type = NULL;
746 if (dip -> at_fund_type != 0)
748 type = decode_fund_type (dip -> at_fund_type);
750 else if (dip -> at_mod_fund_type != NULL)
752 type = decode_mod_fund_type (dip -> at_mod_fund_type);
754 else if (dip -> at_user_def_type)
756 if ((type = lookup_utype (dip -> at_user_def_type)) == NULL)
758 type = alloc_utype (dip -> at_user_def_type, NULL);
761 else if (dip -> at_mod_u_d_type)
763 type = decode_mod_u_d_type (dip -> at_mod_u_d_type);
767 type = lookup_fundamental_type (current_objfile, FT_INTEGER);
776 struct_type -- compute and return the type for a struct or union
780 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
781 char *enddie, struct objfile *objfile)
785 Given pointer to a die information structure for a die which
786 defines a union or structure (and MUST define one or the other),
787 and pointers to the raw die data that define the range of dies which
788 define the members, compute and return the user defined type for the
793 struct_type (dip, thisdie, enddie, objfile)
797 struct objfile *objfile;
801 struct nextfield *next;
804 struct nextfield *list = NULL;
805 struct nextfield *new;
813 if ((type = lookup_utype (dip -> die_ref)) == NULL)
815 /* No forward references created an empty type, so install one now */
816 type = alloc_utype (dip -> die_ref, NULL);
818 INIT_CPLUS_SPECIFIC(type);
819 switch (dip -> die_tag)
821 case TAG_structure_type:
822 TYPE_CODE (type) = TYPE_CODE_STRUCT;
826 TYPE_CODE (type) = TYPE_CODE_UNION;
830 /* Should never happen */
831 TYPE_CODE (type) = TYPE_CODE_UNDEF;
833 SQUAWK (("missing structure or union tag"));
836 /* Some compilers try to be helpful by inventing "fake" names for
837 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
838 Thanks, but no thanks... */
839 if (dip -> at_name != NULL
840 && *dip -> at_name != '~'
841 && *dip -> at_name != '.')
843 TYPE_NAME (type) = obconcat (&objfile -> type_obstack,
844 tpart1, " ", dip -> at_name);
846 /* Use whatever size is known. Zero is a valid size. We might however
847 wish to check has_at_byte_size to make sure that some byte size was
848 given explicitly, but DWARF doesn't specify that explicit sizes of
849 zero have to present, so complaining about missing sizes should
850 probably not be the default. */
851 TYPE_LENGTH (type) = dip -> at_byte_size;
852 thisdie += dip -> die_length;
853 while (thisdie < enddie)
855 basicdieinfo (&mbr, thisdie, objfile);
856 completedieinfo (&mbr, objfile);
857 if (mbr.die_length <= SIZEOF_DIE_LENGTH)
861 else if (mbr.at_sibling != 0)
863 nextdie = dbbase + mbr.at_sibling - dbroff;
867 nextdie = thisdie + mbr.die_length;
872 /* Get space to record the next field's data. */
873 new = (struct nextfield *) alloca (sizeof (struct nextfield));
878 obsavestring (mbr.at_name, strlen (mbr.at_name),
879 &objfile -> type_obstack);
880 list -> field.type = decode_die_type (&mbr);
881 list -> field.bitpos = 8 * locval (mbr.at_location);
882 /* Handle bit fields. */
883 list -> field.bitsize = mbr.at_bit_size;
885 /* For big endian bits, the at_bit_offset gives the additional
886 bit offset from the MSB of the containing anonymous object to
887 the MSB of the field. We don't have to do anything special
888 since we don't need to know the size of the anonymous object. */
889 list -> field.bitpos += mbr.at_bit_offset;
891 /* For little endian bits, we need to have a non-zero at_bit_size,
892 so that we know we are in fact dealing with a bitfield. Compute
893 the bit offset to the MSB of the anonymous object, subtract off
894 the number of bits from the MSB of the field to the MSB of the
895 object, and then subtract off the number of bits of the field
896 itself. The result is the bit offset of the LSB of the field. */
897 if (mbr.at_bit_size > 0)
899 if (mbr.has_at_byte_size)
901 /* The size of the anonymous object containing the bit field
902 is explicit, so use the indicated size (in bytes). */
903 anonymous_size = mbr.at_byte_size;
907 /* The size of the anonymous object containing the bit field
908 matches the size of an object of the bit field's type.
909 DWARF allows at_byte_size to be left out in such cases,
910 as a debug information size optimization. */
911 anonymous_size = TYPE_LENGTH (list -> field.type);
913 list -> field.bitpos +=
914 anonymous_size * 8 - mbr.at_bit_offset - mbr.at_bit_size;
920 process_dies (thisdie, nextdie, objfile);
925 /* Now create the vector of fields, and record how big it is. We may
926 not even have any fields, if this DIE was generated due to a reference
927 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
928 set, which clues gdb in to the fact that it needs to search elsewhere
929 for the full structure definition. */
932 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
936 TYPE_NFIELDS (type) = nfields;
937 TYPE_FIELDS (type) = (struct field *)
938 obstack_alloc (&objfile -> type_obstack,
939 sizeof (struct field) * nfields);
940 /* Copy the saved-up fields into the field vector. */
941 for (n = nfields; list; list = list -> next)
943 TYPE_FIELD (type, --n) = list -> field;
953 read_structure_scope -- process all dies within struct or union
957 static void read_structure_scope (struct dieinfo *dip,
958 char *thisdie, char *enddie, struct objfile *objfile)
962 Called when we find the DIE that starts a structure or union
963 scope (definition) to process all dies that define the members
964 of the structure or union. DIP is a pointer to the die info
965 struct for the DIE that names the structure or union.
969 Note that we need to call struct_type regardless of whether or not
970 the DIE has an at_name attribute, since it might be an anonymous
971 structure or union. This gets the type entered into our set of
974 However, if the structure is incomplete (an opaque struct/union)
975 then suppress creating a symbol table entry for it since gdb only
976 wants to find the one with the complete definition. Note that if
977 it is complete, we just call new_symbol, which does it's own
978 checking about whether the struct/union is anonymous or not (and
979 suppresses creating a symbol table entry itself).
984 read_structure_scope (dip, thisdie, enddie, objfile)
988 struct objfile *objfile;
993 type = struct_type (dip, thisdie, enddie, objfile);
994 if (!(TYPE_FLAGS (type) & TYPE_FLAG_STUB))
996 if ((sym = new_symbol (dip, objfile)) != NULL)
998 SYMBOL_TYPE (sym) = type;
1007 decode_array_element_type -- decode type of the array elements
1011 static struct type *decode_array_element_type (char *scan, char *end)
1015 As the last step in decoding the array subscript information for an
1016 array DIE, we need to decode the type of the array elements. We are
1017 passed a pointer to this last part of the subscript information and
1018 must return the appropriate type. If the type attribute is not
1019 recognized, just warn about the problem and return type int.
1022 static struct type *
1023 decode_array_element_type (scan)
1028 unsigned short attribute;
1029 unsigned short fundtype;
1032 attribute = target_to_host (scan, SIZEOF_ATTRIBUTE, GET_UNSIGNED,
1034 scan += SIZEOF_ATTRIBUTE;
1035 if ((nbytes = attribute_size (attribute)) == -1)
1037 SQUAWK (("bad array element type attribute 0x%x", attribute));
1038 typep = lookup_fundamental_type (current_objfile, FT_INTEGER);
1045 fundtype = target_to_host (scan, nbytes, GET_UNSIGNED,
1047 typep = decode_fund_type (fundtype);
1049 case AT_mod_fund_type:
1050 typep = decode_mod_fund_type (scan);
1052 case AT_user_def_type:
1053 die_ref = target_to_host (scan, nbytes, GET_UNSIGNED,
1055 if ((typep = lookup_utype (die_ref)) == NULL)
1057 typep = alloc_utype (die_ref, NULL);
1060 case AT_mod_u_d_type:
1061 typep = decode_mod_u_d_type (scan);
1064 SQUAWK (("bad array element type attribute 0x%x", attribute));
1065 typep = lookup_fundamental_type (current_objfile, FT_INTEGER);
1076 decode_subscr_data -- decode array subscript and element type data
1080 static struct type *decode_subscr_data (char *scan, char *end)
1084 The array subscripts and the data type of the elements of an
1085 array are described by a list of data items, stored as a block
1086 of contiguous bytes. There is a data item describing each array
1087 dimension, and a final data item describing the element type.
1088 The data items are ordered the same as their appearance in the
1089 source (I.E. leftmost dimension first, next to leftmost second,
1092 We are passed a pointer to the start of the block of bytes
1093 containing the data items, and a pointer to the first byte past
1094 the data. This function decodes the data and returns a type.
1097 FIXME: This code only implements the forms currently used
1098 by the AT&T and GNU C compilers.
1100 The end pointer is supplied for error checking, maybe we should
1104 static struct type *
1105 decode_subscr_data (scan, end)
1109 struct type *typep = NULL;
1110 struct type *nexttype;
1111 unsigned int format;
1112 unsigned short fundtype;
1113 unsigned long lowbound;
1114 unsigned long highbound;
1117 format = target_to_host (scan, SIZEOF_FORMAT_SPECIFIER, GET_UNSIGNED,
1119 scan += SIZEOF_FORMAT_SPECIFIER;
1123 typep = decode_array_element_type (scan);
1126 fundtype = target_to_host (scan, SIZEOF_FMT_FT, GET_UNSIGNED,
1128 scan += SIZEOF_FMT_FT;
1129 if (fundtype != FT_integer && fundtype != FT_signed_integer
1130 && fundtype != FT_unsigned_integer)
1132 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1137 nbytes = TARGET_FT_LONG_SIZE (current_objfile);
1138 lowbound = target_to_host (scan, nbytes, GET_UNSIGNED,
1141 highbound = target_to_host (scan, nbytes, GET_UNSIGNED,
1144 nexttype = decode_subscr_data (scan, end);
1145 if (nexttype != NULL)
1147 typep = alloc_type (current_objfile);
1148 TYPE_CODE (typep) = TYPE_CODE_ARRAY;
1149 TYPE_LENGTH (typep) = TYPE_LENGTH (nexttype);
1150 TYPE_LENGTH (typep) *= (highbound - lowbound) + 1;
1151 TYPE_TARGET_TYPE (typep) = nexttype;
1162 SQUAWK (("array subscript format 0x%x not handled yet", format));
1165 SQUAWK (("unknown array subscript format %x", format));
1175 dwarf_read_array_type -- read TAG_array_type DIE
1179 static void dwarf_read_array_type (struct dieinfo *dip)
1183 Extract all information from a TAG_array_type DIE and add to
1184 the user defined type vector.
1188 dwarf_read_array_type (dip)
1189 struct dieinfo *dip;
1195 unsigned short blocksz;
1198 if (dip -> at_ordering != ORD_row_major)
1200 /* FIXME: Can gdb even handle column major arrays? */
1201 SQUAWK (("array not row major; not handled correctly"));
1203 if ((sub = dip -> at_subscr_data) != NULL)
1205 nbytes = attribute_size (AT_subscr_data);
1206 blocksz = target_to_host (sub, nbytes, GET_UNSIGNED, current_objfile);
1207 subend = sub + nbytes + blocksz;
1209 type = decode_subscr_data (sub, subend);
1212 if ((utype = lookup_utype (dip -> die_ref)) == NULL)
1214 utype = alloc_utype (dip -> die_ref, NULL);
1216 TYPE_CODE (utype) = TYPE_CODE_ARRAY;
1217 TYPE_TARGET_TYPE (utype) =
1218 lookup_fundamental_type (current_objfile, FT_INTEGER);
1219 TYPE_LENGTH (utype) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype));
1223 if ((utype = lookup_utype (dip -> die_ref)) == NULL)
1225 alloc_utype (dip -> die_ref, type);
1229 TYPE_CODE (utype) = TYPE_CODE_ARRAY;
1230 TYPE_LENGTH (utype) = TYPE_LENGTH (type);
1231 TYPE_TARGET_TYPE (utype) = TYPE_TARGET_TYPE (type);
1241 read_tag_pointer_type -- read TAG_pointer_type DIE
1245 static void read_tag_pointer_type (struct dieinfo *dip)
1249 Extract all information from a TAG_pointer_type DIE and add to
1250 the user defined type vector.
1254 read_tag_pointer_type (dip)
1255 struct dieinfo *dip;
1260 type = decode_die_type (dip);
1261 if ((utype = lookup_utype (dip -> die_ref)) == NULL)
1263 utype = lookup_pointer_type (type);
1264 alloc_utype (dip -> die_ref, utype);
1268 TYPE_TARGET_TYPE (utype) = type;
1269 TYPE_POINTER_TYPE (type) = utype;
1271 /* We assume the machine has only one representation for pointers! */
1272 /* FIXME: This confuses host<->target data representations, and is a
1273 poor assumption besides. */
1275 TYPE_LENGTH (utype) = sizeof (char *);
1276 TYPE_CODE (utype) = TYPE_CODE_PTR;
1284 read_subroutine_type -- process TAG_subroutine_type dies
1288 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1293 Handle DIES due to C code like:
1296 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1302 The parameter DIES are currently ignored. See if gdb has a way to
1303 include this info in it's type system, and decode them if so. Is
1304 this what the type structure's "arg_types" field is for? (FIXME)
1308 read_subroutine_type (dip, thisdie, enddie)
1309 struct dieinfo *dip;
1313 struct type *type; /* Type that this function returns */
1314 struct type *ftype; /* Function that returns above type */
1316 /* Decode the type that this subroutine returns */
1318 type = decode_die_type (dip);
1320 /* Check to see if we already have a partially constructed user
1321 defined type for this DIE, from a forward reference. */
1323 if ((ftype = lookup_utype (dip -> die_ref)) == NULL)
1325 /* This is the first reference to one of these types. Make
1326 a new one and place it in the user defined types. */
1327 ftype = lookup_function_type (type);
1328 alloc_utype (dip -> die_ref, ftype);
1332 /* We have an existing partially constructed type, so bash it
1333 into the correct type. */
1334 TYPE_TARGET_TYPE (ftype) = type;
1335 TYPE_FUNCTION_TYPE (type) = ftype;
1336 TYPE_LENGTH (ftype) = 1;
1337 TYPE_CODE (ftype) = TYPE_CODE_FUNC;
1345 read_enumeration -- process dies which define an enumeration
1349 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1350 char *enddie, struct objfile *objfile)
1354 Given a pointer to a die which begins an enumeration, process all
1355 the dies that define the members of the enumeration.
1359 Note that we need to call enum_type regardless of whether or not we
1360 have a symbol, since we might have an enum without a tag name (thus
1361 no symbol for the tagname).
1365 read_enumeration (dip, thisdie, enddie, objfile)
1366 struct dieinfo *dip;
1369 struct objfile *objfile;
1374 type = enum_type (dip, objfile);
1375 if ((sym = new_symbol (dip, objfile)) != NULL)
1377 SYMBOL_TYPE (sym) = type;
1385 enum_type -- decode and return a type for an enumeration
1389 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1393 Given a pointer to a die information structure for the die which
1394 starts an enumeration, process all the dies that define the members
1395 of the enumeration and return a type pointer for the enumeration.
1397 At the same time, for each member of the enumeration, create a
1398 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1399 and give it the type of the enumeration itself.
1403 Note that the DWARF specification explicitly mandates that enum
1404 constants occur in reverse order from the source program order,
1405 for "consistency" and because this ordering is easier for many
1406 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1407 Entries). Because gdb wants to see the enum members in program
1408 source order, we have to ensure that the order gets reversed while
1409 we are processing them.
1412 static struct type *
1413 enum_type (dip, objfile)
1414 struct dieinfo *dip;
1415 struct objfile *objfile;
1419 struct nextfield *next;
1422 struct nextfield *list = NULL;
1423 struct nextfield *new;
1428 unsigned short blocksz;
1432 if ((type = lookup_utype (dip -> die_ref)) == NULL)
1434 /* No forward references created an empty type, so install one now */
1435 type = alloc_utype (dip -> die_ref, NULL);
1437 TYPE_CODE (type) = TYPE_CODE_ENUM;
1438 /* Some compilers try to be helpful by inventing "fake" names for
1439 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1440 Thanks, but no thanks... */
1441 if (dip -> at_name != NULL
1442 && *dip -> at_name != '~'
1443 && *dip -> at_name != '.')
1445 TYPE_NAME (type) = obconcat (&objfile -> type_obstack, "enum",
1446 " ", dip -> at_name);
1448 if (dip -> at_byte_size != 0)
1450 TYPE_LENGTH (type) = dip -> at_byte_size;
1452 if ((scan = dip -> at_element_list) != NULL)
1454 if (dip -> short_element_list)
1456 nbytes = attribute_size (AT_short_element_list);
1460 nbytes = attribute_size (AT_element_list);
1462 blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
1463 listend = scan + nbytes + blocksz;
1465 while (scan < listend)
1467 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1470 list -> field.type = NULL;
1471 list -> field.bitsize = 0;
1472 list -> field.bitpos =
1473 target_to_host (scan, TARGET_FT_LONG_SIZE (objfile), GET_SIGNED,
1475 scan += TARGET_FT_LONG_SIZE (objfile);
1476 list -> field.name = obsavestring (scan, strlen (scan),
1477 &objfile -> type_obstack);
1478 scan += strlen (scan) + 1;
1480 /* Handcraft a new symbol for this enum member. */
1481 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1482 sizeof (struct symbol));
1483 memset (sym, 0, sizeof (struct symbol));
1484 SYMBOL_NAME (sym) = create_name (list -> field.name,
1485 &objfile->symbol_obstack);
1486 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1487 SYMBOL_CLASS (sym) = LOC_CONST;
1488 SYMBOL_TYPE (sym) = type;
1489 SYMBOL_VALUE (sym) = list -> field.bitpos;
1490 add_symbol_to_list (sym, list_in_scope);
1492 /* Now create the vector of fields, and record how big it is. This is
1493 where we reverse the order, by pulling the members off the list in
1494 reverse order from how they were inserted. If we have no fields
1495 (this is apparently possible in C++) then skip building a field
1499 TYPE_NFIELDS (type) = nfields;
1500 TYPE_FIELDS (type) = (struct field *)
1501 obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) * nfields);
1502 /* Copy the saved-up fields into the field vector. */
1503 for (n = 0; (n < nfields) && (list != NULL); list = list -> next)
1505 TYPE_FIELD (type, n++) = list -> field;
1516 read_func_scope -- process all dies within a function scope
1520 Process all dies within a given function scope. We are passed
1521 a die information structure pointer DIP for the die which
1522 starts the function scope, and pointers into the raw die data
1523 that define the dies within the function scope.
1525 For now, we ignore lexical block scopes within the function.
1526 The problem is that AT&T cc does not define a DWARF lexical
1527 block scope for the function itself, while gcc defines a
1528 lexical block scope for the function. We need to think about
1529 how to handle this difference, or if it is even a problem.
1534 read_func_scope (dip, thisdie, enddie, objfile)
1535 struct dieinfo *dip;
1538 struct objfile *objfile;
1540 register struct context_stack *new;
1542 if (objfile -> ei.entry_point >= dip -> at_low_pc &&
1543 objfile -> ei.entry_point < dip -> at_high_pc)
1545 objfile -> ei.entry_func_lowpc = dip -> at_low_pc;
1546 objfile -> ei.entry_func_highpc = dip -> at_high_pc;
1548 if (STREQ (dip -> at_name, "main")) /* FIXME: hardwired name */
1550 objfile -> ei.main_func_lowpc = dip -> at_low_pc;
1551 objfile -> ei.main_func_highpc = dip -> at_high_pc;
1553 new = push_context (0, dip -> at_low_pc);
1554 new -> name = new_symbol (dip, objfile);
1555 list_in_scope = &local_symbols;
1556 process_dies (thisdie + dip -> die_length, enddie, objfile);
1557 new = pop_context ();
1558 /* Make a block for the local symbols within. */
1559 finish_block (new -> name, &local_symbols, new -> old_blocks,
1560 new -> start_addr, dip -> at_high_pc, objfile);
1561 list_in_scope = &file_symbols;
1569 handle_producer -- process the AT_producer attribute
1573 Perform any operations that depend on finding a particular
1574 AT_producer attribute.
1579 handle_producer (producer)
1583 /* If this compilation unit was compiled with g++ or gcc, then set the
1584 processing_gcc_compilation flag. */
1586 processing_gcc_compilation =
1587 STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER))
1588 || STREQN (producer, GCC_PRODUCER, strlen (GCC_PRODUCER));
1590 /* Select a demangling style if we can identify the producer and if
1591 the current style is auto. We leave the current style alone if it
1592 is not auto. We also leave the demangling style alone if we find a
1593 gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
1595 #if 1 /* Works, but is experimental. -fnf */
1596 if (current_demangling_style == auto_demangling)
1598 if (STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)))
1600 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1602 else if (STREQN (producer, LCC_PRODUCER, strlen (LCC_PRODUCER)))
1604 set_demangling_style (LUCID_DEMANGLING_STYLE_STRING);
1606 else if (STREQN (producer, CFRONT_PRODUCER, strlen (CFRONT_PRODUCER)))
1608 set_demangling_style (CFRONT_DEMANGLING_STYLE_STRING);
1619 read_file_scope -- process all dies within a file scope
1623 Process all dies within a given file scope. We are passed a
1624 pointer to the die information structure for the die which
1625 starts the file scope, and pointers into the raw die data which
1626 mark the range of dies within the file scope.
1628 When the partial symbol table is built, the file offset for the line
1629 number table for each compilation unit is saved in the partial symbol
1630 table entry for that compilation unit. As the symbols for each
1631 compilation unit are read, the line number table is read into memory
1632 and the variable lnbase is set to point to it. Thus all we have to
1633 do is use lnbase to access the line number table for the current
1638 read_file_scope (dip, thisdie, enddie, objfile)
1639 struct dieinfo *dip;
1642 struct objfile *objfile;
1644 struct cleanup *back_to;
1645 struct symtab *symtab;
1647 if (objfile -> ei.entry_point >= dip -> at_low_pc &&
1648 objfile -> ei.entry_point < dip -> at_high_pc)
1650 objfile -> ei.entry_file_lowpc = dip -> at_low_pc;
1651 objfile -> ei.entry_file_highpc = dip -> at_high_pc;
1653 if (dip -> at_producer != NULL)
1655 handle_producer (dip -> at_producer);
1657 numutypes = (enddie - thisdie) / 4;
1658 utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *));
1659 back_to = make_cleanup (free, utypes);
1660 memset (utypes, 0, numutypes * sizeof (struct type *));
1661 start_symtab (dip -> at_name, dip -> at_comp_dir, dip -> at_low_pc);
1662 decode_line_numbers (lnbase);
1663 process_dies (thisdie + dip -> die_length, enddie, objfile);
1664 symtab = end_symtab (dip -> at_high_pc, 0, 0, objfile);
1665 /* FIXME: The following may need to be expanded for other languages */
1666 switch (dip -> at_language)
1670 symtab -> language = language_c;
1672 case LANG_C_PLUS_PLUS:
1673 symtab -> language = language_cplus;
1678 do_cleanups (back_to);
1687 process_dies -- process a range of DWARF Information Entries
1691 static void process_dies (char *thisdie, char *enddie,
1692 struct objfile *objfile)
1696 Process all DIE's in a specified range. May be (and almost
1697 certainly will be) called recursively.
1701 process_dies (thisdie, enddie, objfile)
1704 struct objfile *objfile;
1709 while (thisdie < enddie)
1711 basicdieinfo (&di, thisdie, objfile);
1712 if (di.die_length < SIZEOF_DIE_LENGTH)
1716 else if (di.die_tag == TAG_padding)
1718 nextdie = thisdie + di.die_length;
1722 completedieinfo (&di, objfile);
1723 if (di.at_sibling != 0)
1725 nextdie = dbbase + di.at_sibling - dbroff;
1729 nextdie = thisdie + di.die_length;
1733 case TAG_compile_unit:
1734 read_file_scope (&di, thisdie, nextdie, objfile);
1736 case TAG_global_subroutine:
1737 case TAG_subroutine:
1738 if (di.has_at_low_pc)
1740 read_func_scope (&di, thisdie, nextdie, objfile);
1743 case TAG_lexical_block:
1744 read_lexical_block_scope (&di, thisdie, nextdie, objfile);
1746 case TAG_structure_type:
1747 case TAG_union_type:
1748 read_structure_scope (&di, thisdie, nextdie, objfile);
1750 case TAG_enumeration_type:
1751 read_enumeration (&di, thisdie, nextdie, objfile);
1753 case TAG_subroutine_type:
1754 read_subroutine_type (&di, thisdie, nextdie);
1756 case TAG_array_type:
1757 dwarf_read_array_type (&di);
1759 case TAG_pointer_type:
1760 read_tag_pointer_type (&di);
1763 new_symbol (&di, objfile);
1775 decode_line_numbers -- decode a line number table fragment
1779 static void decode_line_numbers (char *tblscan, char *tblend,
1780 long length, long base, long line, long pc)
1784 Translate the DWARF line number information to gdb form.
1786 The ".line" section contains one or more line number tables, one for
1787 each ".line" section from the objects that were linked.
1789 The AT_stmt_list attribute for each TAG_source_file entry in the
1790 ".debug" section contains the offset into the ".line" section for the
1791 start of the table for that file.
1793 The table itself has the following structure:
1795 <table length><base address><source statement entry>
1796 4 bytes 4 bytes 10 bytes
1798 The table length is the total size of the table, including the 4 bytes
1799 for the length information.
1801 The base address is the address of the first instruction generated
1802 for the source file.
1804 Each source statement entry has the following structure:
1806 <line number><statement position><address delta>
1807 4 bytes 2 bytes 4 bytes
1809 The line number is relative to the start of the file, starting with
1812 The statement position either -1 (0xFFFF) or the number of characters
1813 from the beginning of the line to the beginning of the statement.
1815 The address delta is the difference between the base address and
1816 the address of the first instruction for the statement.
1818 Note that we must copy the bytes from the packed table to our local
1819 variables before attempting to use them, to avoid alignment problems
1820 on some machines, particularly RISC processors.
1824 Does gdb expect the line numbers to be sorted? They are now by
1825 chance/luck, but are not required to be. (FIXME)
1827 The line with number 0 is unused, gdb apparently can discover the
1828 span of the last line some other way. How? (FIXME)
1832 decode_line_numbers (linetable)
1837 unsigned long length;
1842 if (linetable != NULL)
1844 tblscan = tblend = linetable;
1845 length = target_to_host (tblscan, SIZEOF_LINETBL_LENGTH, GET_UNSIGNED,
1847 tblscan += SIZEOF_LINETBL_LENGTH;
1849 base = target_to_host (tblscan, TARGET_FT_POINTER_SIZE (objfile),
1850 GET_UNSIGNED, current_objfile);
1851 tblscan += TARGET_FT_POINTER_SIZE (objfile);
1853 while (tblscan < tblend)
1855 line = target_to_host (tblscan, SIZEOF_LINETBL_LINENO, GET_UNSIGNED,
1857 tblscan += SIZEOF_LINETBL_LINENO + SIZEOF_LINETBL_STMT;
1858 pc = target_to_host (tblscan, SIZEOF_LINETBL_DELTA, GET_UNSIGNED,
1860 tblscan += SIZEOF_LINETBL_DELTA;
1864 record_line (current_subfile, line, pc);
1874 locval -- compute the value of a location attribute
1878 static int locval (char *loc)
1882 Given pointer to a string of bytes that define a location, compute
1883 the location and return the value.
1885 When computing values involving the current value of the frame pointer,
1886 the value zero is used, which results in a value relative to the frame
1887 pointer, rather than the absolute value. This is what GDB wants
1890 When the result is a register number, the global isreg flag is set,
1891 otherwise it is cleared. This is a kludge until we figure out a better
1892 way to handle the problem. Gdb's design does not mesh well with the
1893 DWARF notion of a location computing interpreter, which is a shame
1894 because the flexibility goes unused.
1898 Note that stack[0] is unused except as a default error return.
1899 Note that stack overflow is not yet handled.
1906 unsigned short nbytes;
1907 unsigned short locsize;
1908 auto long stack[64];
1915 nbytes = attribute_size (AT_location);
1916 locsize = target_to_host (loc, nbytes, GET_UNSIGNED, current_objfile);
1918 end = loc + locsize;
1923 loc_value_size = TARGET_FT_LONG_SIZE (current_objfile);
1926 loc_atom_code = target_to_host (loc, SIZEOF_LOC_ATOM_CODE, GET_UNSIGNED,
1928 loc += SIZEOF_LOC_ATOM_CODE;
1929 switch (loc_atom_code)
1936 /* push register (number) */
1937 stack[++stacki] = target_to_host (loc, loc_value_size,
1938 GET_UNSIGNED, current_objfile);
1939 loc += loc_value_size;
1943 /* push value of register (number) */
1944 /* Actually, we compute the value as if register has 0 */
1946 regno = target_to_host (loc, loc_value_size, GET_UNSIGNED,
1948 loc += loc_value_size;
1951 stack[++stacki] = 0;
1955 stack[++stacki] = 0;
1956 SQUAWK (("BASEREG %d not handled!", regno));
1960 /* push address (relocated address) */
1961 stack[++stacki] = target_to_host (loc, loc_value_size,
1962 GET_UNSIGNED, current_objfile);
1963 loc += loc_value_size;
1966 /* push constant (number) FIXME: signed or unsigned! */
1967 stack[++stacki] = target_to_host (loc, loc_value_size,
1968 GET_SIGNED, current_objfile);
1969 loc += loc_value_size;
1972 /* pop, deref and push 2 bytes (as a long) */
1973 SQUAWK (("OP_DEREF2 address 0x%x not handled", stack[stacki]));
1975 case OP_DEREF4: /* pop, deref and push 4 bytes (as a long) */
1976 SQUAWK (("OP_DEREF4 address 0x%x not handled", stack[stacki]));
1978 case OP_ADD: /* pop top 2 items, add, push result */
1979 stack[stacki - 1] += stack[stacki];
1984 return (stack[stacki]);
1991 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1995 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1999 When expanding a partial symbol table entry to a full symbol table
2000 entry, this is the function that gets called to read in the symbols
2001 for the compilation unit.
2003 Returns a pointer to the newly constructed symtab (which is now
2004 the new first one on the objfile's symtab list).
2007 static struct symtab *
2008 read_ofile_symtab (pst)
2009 struct partial_symtab *pst;
2011 struct cleanup *back_to;
2012 unsigned long lnsize;
2015 char lnsizedata[SIZEOF_LINETBL_LENGTH];
2017 abfd = pst -> objfile -> obfd;
2018 current_objfile = pst -> objfile;
2020 /* Allocate a buffer for the entire chunk of DIE's for this compilation
2021 unit, seek to the location in the file, and read in all the DIE's. */
2024 dbbase = xmalloc (DBLENGTH(pst));
2025 dbroff = DBROFF(pst);
2026 foffset = DBFOFF(pst) + dbroff;
2027 base_section_offsets = pst->section_offsets;
2028 baseaddr = ANOFFSET (pst->section_offsets, 0);
2029 if (bfd_seek (abfd, foffset, 0) ||
2030 (bfd_read (dbbase, DBLENGTH(pst), 1, abfd) != DBLENGTH(pst)))
2033 error ("can't read DWARF data");
2035 back_to = make_cleanup (free, dbbase);
2037 /* If there is a line number table associated with this compilation unit
2038 then read the size of this fragment in bytes, from the fragment itself.
2039 Allocate a buffer for the fragment and read it in for future
2045 if (bfd_seek (abfd, LNFOFF (pst), 0) ||
2046 (bfd_read ((PTR) lnsizedata, sizeof (lnsizedata), 1, abfd) !=
2047 sizeof (lnsizedata)))
2049 error ("can't read DWARF line number table size");
2051 lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH,
2052 GET_UNSIGNED, pst -> objfile);
2053 lnbase = xmalloc (lnsize);
2054 if (bfd_seek (abfd, LNFOFF (pst), 0) ||
2055 (bfd_read (lnbase, lnsize, 1, abfd) != lnsize))
2058 error ("can't read DWARF line numbers");
2060 make_cleanup (free, lnbase);
2063 process_dies (dbbase, dbbase + DBLENGTH(pst), pst -> objfile);
2064 do_cleanups (back_to);
2065 current_objfile = NULL;
2066 return (pst -> objfile -> symtabs);
2073 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
2077 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
2081 Called once for each partial symbol table entry that needs to be
2082 expanded into a full symbol table entry.
2087 psymtab_to_symtab_1 (pst)
2088 struct partial_symtab *pst;
2091 struct cleanup *old_chain;
2097 warning ("psymtab for %s already read in. Shouldn't happen.",
2102 /* Read in all partial symtabs on which this one is dependent */
2103 for (i = 0; i < pst -> number_of_dependencies; i++)
2105 if (!pst -> dependencies[i] -> readin)
2107 /* Inform about additional files that need to be read in. */
2110 fputs_filtered (" ", stdout);
2112 fputs_filtered ("and ", stdout);
2114 printf_filtered ("%s...",
2115 pst -> dependencies[i] -> filename);
2117 fflush (stdout); /* Flush output */
2119 psymtab_to_symtab_1 (pst -> dependencies[i]);
2122 if (DBLENGTH (pst)) /* Otherwise it's a dummy */
2125 old_chain = make_cleanup (really_free_pendings, 0);
2126 pst -> symtab = read_ofile_symtab (pst);
2129 printf_filtered ("%d DIE's, sorting...", diecount);
2133 sort_symtab_syms (pst -> symtab);
2134 do_cleanups (old_chain);
2145 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2149 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2153 This is the DWARF support entry point for building a full symbol
2154 table entry from a partial symbol table entry. We are passed a
2155 pointer to the partial symbol table entry that needs to be expanded.
2160 dwarf_psymtab_to_symtab (pst)
2161 struct partial_symtab *pst;
2168 warning ("psymtab for %s already read in. Shouldn't happen.",
2173 if (DBLENGTH (pst) || pst -> number_of_dependencies)
2175 /* Print the message now, before starting serious work, to avoid
2176 disconcerting pauses. */
2179 printf_filtered ("Reading in symbols for %s...",
2184 psymtab_to_symtab_1 (pst);
2186 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2187 we need to do an equivalent or is this something peculiar to
2189 Match with global symbols. This only needs to be done once,
2190 after all of the symtabs and dependencies have been read in.
2192 scan_file_globals (pst -> objfile);
2195 /* Finish up the verbose info message. */
2198 printf_filtered ("done.\n");
2210 init_psymbol_list -- initialize storage for partial symbols
2214 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2218 Initializes storage for all of the partial symbols that will be
2219 created by dwarf_build_psymtabs and subsidiaries.
2223 init_psymbol_list (objfile, total_symbols)
2224 struct objfile *objfile;
2227 /* Free any previously allocated psymbol lists. */
2229 if (objfile -> global_psymbols.list)
2231 mfree (objfile -> md, (PTR)objfile -> global_psymbols.list);
2233 if (objfile -> static_psymbols.list)
2235 mfree (objfile -> md, (PTR)objfile -> static_psymbols.list);
2238 /* Current best guess is that there are approximately a twentieth
2239 of the total symbols (in a debugging file) are global or static
2242 objfile -> global_psymbols.size = total_symbols / 10;
2243 objfile -> static_psymbols.size = total_symbols / 10;
2244 objfile -> global_psymbols.next =
2245 objfile -> global_psymbols.list = (struct partial_symbol *)
2246 xmmalloc (objfile -> md, objfile -> global_psymbols.size
2247 * sizeof (struct partial_symbol));
2248 objfile -> static_psymbols.next =
2249 objfile -> static_psymbols.list = (struct partial_symbol *)
2250 xmmalloc (objfile -> md, objfile -> static_psymbols.size
2251 * sizeof (struct partial_symbol));
2258 add_enum_psymbol -- add enumeration members to partial symbol table
2262 Given pointer to a DIE that is known to be for an enumeration,
2263 extract the symbolic names of the enumeration members and add
2264 partial symbols for them.
2268 add_enum_psymbol (dip, objfile)
2269 struct dieinfo *dip;
2270 struct objfile *objfile;
2274 unsigned short blocksz;
2277 if ((scan = dip -> at_element_list) != NULL)
2279 if (dip -> short_element_list)
2281 nbytes = attribute_size (AT_short_element_list);
2285 nbytes = attribute_size (AT_element_list);
2287 blocksz = target_to_host (scan, nbytes, GET_UNSIGNED, objfile);
2289 listend = scan + blocksz;
2290 while (scan < listend)
2292 scan += TARGET_FT_LONG_SIZE (objfile);
2293 ADD_PSYMBOL_TO_LIST (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST,
2294 objfile -> static_psymbols, 0);
2295 scan += strlen (scan) + 1;
2304 add_partial_symbol -- add symbol to partial symbol table
2308 Given a DIE, if it is one of the types that we want to
2309 add to a partial symbol table, finish filling in the die info
2310 and then add a partial symbol table entry for it.
2315 add_partial_symbol (dip, objfile)
2316 struct dieinfo *dip;
2317 struct objfile *objfile;
2319 switch (dip -> die_tag)
2321 case TAG_global_subroutine:
2322 record_minimal_symbol (dip -> at_name, dip -> at_low_pc, mst_text,
2324 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2325 VAR_NAMESPACE, LOC_BLOCK,
2326 objfile -> global_psymbols,
2329 case TAG_global_variable:
2330 record_minimal_symbol (dip -> at_name, locval (dip -> at_location),
2332 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2333 VAR_NAMESPACE, LOC_STATIC,
2334 objfile -> global_psymbols,
2337 case TAG_subroutine:
2338 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2339 VAR_NAMESPACE, LOC_BLOCK,
2340 objfile -> static_psymbols,
2343 case TAG_local_variable:
2344 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2345 VAR_NAMESPACE, LOC_STATIC,
2346 objfile -> static_psymbols,
2350 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2351 VAR_NAMESPACE, LOC_TYPEDEF,
2352 objfile -> static_psymbols,
2355 case TAG_structure_type:
2356 case TAG_union_type:
2357 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2358 STRUCT_NAMESPACE, LOC_TYPEDEF,
2359 objfile -> static_psymbols,
2362 case TAG_enumeration_type:
2365 ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
2366 STRUCT_NAMESPACE, LOC_TYPEDEF,
2367 objfile -> static_psymbols,
2370 add_enum_psymbol (dip, objfile);
2379 scan_partial_symbols -- scan DIE's within a single compilation unit
2383 Process the DIE's within a single compilation unit, looking for
2384 interesting DIE's that contribute to the partial symbol table entry
2385 for this compilation unit. Since we cannot follow any sibling
2386 chains without reading the complete DIE info for every DIE,
2387 it is probably faster to just sequentially check each one to
2388 see if it is one of the types we are interested in, and if so,
2389 then extract all the attributes info and generate a partial
2394 Don't attempt to add anonymous structures or unions since they have
2395 no name. Anonymous enumerations however are processed, because we
2396 want to extract their member names (the check for a tag name is
2399 Also, for variables and subroutines, check that this is the place
2400 where the actual definition occurs, rather than just a reference
2405 scan_partial_symbols (thisdie, enddie, objfile)
2408 struct objfile *objfile;
2413 while (thisdie < enddie)
2415 basicdieinfo (&di, thisdie, objfile);
2416 if (di.die_length < SIZEOF_DIE_LENGTH)
2422 nextdie = thisdie + di.die_length;
2423 /* To avoid getting complete die information for every die, we
2424 only do it (below) for the cases we are interested in. */
2427 case TAG_global_subroutine:
2428 case TAG_subroutine:
2429 case TAG_global_variable:
2430 case TAG_local_variable:
2431 completedieinfo (&di, objfile);
2432 if (di.at_name && (di.has_at_low_pc || di.at_location))
2434 add_partial_symbol (&di, objfile);
2438 case TAG_structure_type:
2439 case TAG_union_type:
2440 completedieinfo (&di, objfile);
2443 add_partial_symbol (&di, objfile);
2446 case TAG_enumeration_type:
2447 completedieinfo (&di, objfile);
2448 add_partial_symbol (&di, objfile);
2460 scan_compilation_units -- build a psymtab entry for each compilation
2464 This is the top level dwarf parsing routine for building partial
2467 It scans from the beginning of the DWARF table looking for the first
2468 TAG_compile_unit DIE, and then follows the sibling chain to locate
2469 each additional TAG_compile_unit DIE.
2471 For each TAG_compile_unit DIE it creates a partial symtab structure,
2472 calls a subordinate routine to collect all the compilation unit's
2473 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2474 new partial symtab structure into the partial symbol table. It also
2475 records the appropriate information in the partial symbol table entry
2476 to allow the chunk of DIE's and line number table for this compilation
2477 unit to be located and re-read later, to generate a complete symbol
2478 table entry for the compilation unit.
2480 Thus it effectively partitions up a chunk of DIE's for multiple
2481 compilation units into smaller DIE chunks and line number tables,
2482 and associates them with a partial symbol table entry.
2486 If any compilation unit has no line number table associated with
2487 it for some reason (a missing at_stmt_list attribute, rather than
2488 just one with a value of zero, which is valid) then we ensure that
2489 the recorded file offset is zero so that the routine which later
2490 reads line number table fragments knows that there is no fragment
2500 scan_compilation_units (filename, thisdie, enddie, dbfoff, lnoffset, objfile)
2504 unsigned int dbfoff;
2505 unsigned int lnoffset;
2506 struct objfile *objfile;
2510 struct partial_symtab *pst;
2515 while (thisdie < enddie)
2517 basicdieinfo (&di, thisdie, objfile);
2518 if (di.die_length < SIZEOF_DIE_LENGTH)
2522 else if (di.die_tag != TAG_compile_unit)
2524 nextdie = thisdie + di.die_length;
2528 completedieinfo (&di, objfile);
2529 if (di.at_sibling != 0)
2531 nextdie = dbbase + di.at_sibling - dbroff;
2535 nextdie = thisdie + di.die_length;
2537 curoff = thisdie - dbbase;
2538 culength = nextdie - thisdie;
2539 curlnoffset = di.has_at_stmt_list ? lnoffset + di.at_stmt_list : 0;
2541 /* First allocate a new partial symbol table structure */
2543 pst = start_psymtab_common (objfile, base_section_offsets, di.at_name,
2545 objfile -> global_psymbols.next,
2546 objfile -> static_psymbols.next);
2548 pst -> texthigh = di.at_high_pc;
2549 pst -> read_symtab_private = (char *)
2550 obstack_alloc (&objfile -> psymbol_obstack,
2551 sizeof (struct dwfinfo));
2552 DBFOFF (pst) = dbfoff;
2553 DBROFF (pst) = curoff;
2554 DBLENGTH (pst) = culength;
2555 LNFOFF (pst) = curlnoffset;
2556 pst -> read_symtab = dwarf_psymtab_to_symtab;
2558 /* Now look for partial symbols */
2560 scan_partial_symbols (thisdie + di.die_length, nextdie, objfile);
2562 pst -> n_global_syms = objfile -> global_psymbols.next -
2563 (objfile -> global_psymbols.list + pst -> globals_offset);
2564 pst -> n_static_syms = objfile -> static_psymbols.next -
2565 (objfile -> static_psymbols.list + pst -> statics_offset);
2566 sort_pst_symbols (pst);
2567 /* If there is already a psymtab or symtab for a file of this name,
2568 remove it. (If there is a symtab, more drastic things also
2569 happen.) This happens in VxWorks. */
2570 free_named_symtabs (pst -> filename);
2580 new_symbol -- make a symbol table entry for a new symbol
2584 static struct symbol *new_symbol (struct dieinfo *dip,
2585 struct objfile *objfile)
2589 Given a pointer to a DWARF information entry, figure out if we need
2590 to make a symbol table entry for it, and if so, create a new entry
2591 and return a pointer to it.
2594 static struct symbol *
2595 new_symbol (dip, objfile)
2596 struct dieinfo *dip;
2597 struct objfile *objfile;
2599 struct symbol *sym = NULL;
2601 if (dip -> at_name != NULL)
2603 sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack,
2604 sizeof (struct symbol));
2605 memset (sym, 0, sizeof (struct symbol));
2606 SYMBOL_NAME (sym) = create_name (dip -> at_name, &objfile->symbol_obstack);
2607 /* default assumptions */
2608 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2609 SYMBOL_CLASS (sym) = LOC_STATIC;
2610 SYMBOL_TYPE (sym) = decode_die_type (dip);
2611 switch (dip -> die_tag)
2614 SYMBOL_VALUE (sym) = dip -> at_low_pc;
2615 SYMBOL_CLASS (sym) = LOC_LABEL;
2617 case TAG_global_subroutine:
2618 case TAG_subroutine:
2619 SYMBOL_VALUE (sym) = dip -> at_low_pc;
2620 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
2621 SYMBOL_CLASS (sym) = LOC_BLOCK;
2622 if (dip -> die_tag == TAG_global_subroutine)
2624 add_symbol_to_list (sym, &global_symbols);
2628 add_symbol_to_list (sym, list_in_scope);
2631 case TAG_global_variable:
2632 if (dip -> at_location != NULL)
2634 SYMBOL_VALUE (sym) = locval (dip -> at_location);
2635 add_symbol_to_list (sym, &global_symbols);
2636 SYMBOL_CLASS (sym) = LOC_STATIC;
2637 SYMBOL_VALUE (sym) += baseaddr;
2640 case TAG_local_variable:
2641 if (dip -> at_location != NULL)
2643 SYMBOL_VALUE (sym) = locval (dip -> at_location);
2644 add_symbol_to_list (sym, list_in_scope);
2647 SYMBOL_CLASS (sym) = LOC_REGISTER;
2651 SYMBOL_CLASS (sym) = LOC_LOCAL;
2655 SYMBOL_CLASS (sym) = LOC_STATIC;
2656 SYMBOL_VALUE (sym) += baseaddr;
2660 case TAG_formal_parameter:
2661 if (dip -> at_location != NULL)
2663 SYMBOL_VALUE (sym) = locval (dip -> at_location);
2665 add_symbol_to_list (sym, list_in_scope);
2668 SYMBOL_CLASS (sym) = LOC_REGPARM;
2672 SYMBOL_CLASS (sym) = LOC_ARG;
2675 case TAG_unspecified_parameters:
2676 /* From varargs functions; gdb doesn't seem to have any interest in
2677 this information, so just ignore it for now. (FIXME?) */
2679 case TAG_structure_type:
2680 case TAG_union_type:
2681 case TAG_enumeration_type:
2682 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2683 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2684 add_symbol_to_list (sym, list_in_scope);
2687 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2688 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2689 add_symbol_to_list (sym, list_in_scope);
2692 /* Not a tag we recognize. Hopefully we aren't processing trash
2693 data, but since we must specifically ignore things we don't
2694 recognize, there is nothing else we should do at this point. */
2705 decode_mod_fund_type -- decode a modified fundamental type
2709 static struct type *decode_mod_fund_type (char *typedata)
2713 Decode a block of data containing a modified fundamental
2714 type specification. TYPEDATA is a pointer to the block,
2715 which starts with a length containing the size of the rest
2716 of the block. At the end of the block is a fundmental type
2717 code value that gives the fundamental type. Everything
2718 in between are type modifiers.
2720 We simply compute the number of modifiers and call the general
2721 function decode_modified_type to do the actual work.
2724 static struct type *
2725 decode_mod_fund_type (typedata)
2728 struct type *typep = NULL;
2729 unsigned short modcount;
2732 /* Get the total size of the block, exclusive of the size itself */
2734 nbytes = attribute_size (AT_mod_fund_type);
2735 modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
2738 /* Deduct the size of the fundamental type bytes at the end of the block. */
2740 modcount -= attribute_size (AT_fund_type);
2742 /* Now do the actual decoding */
2744 typep = decode_modified_type (typedata, modcount, AT_mod_fund_type);
2752 decode_mod_u_d_type -- decode a modified user defined type
2756 static struct type *decode_mod_u_d_type (char *typedata)
2760 Decode a block of data containing a modified user defined
2761 type specification. TYPEDATA is a pointer to the block,
2762 which consists of a two byte length, containing the size
2763 of the rest of the block. At the end of the block is a
2764 four byte value that gives a reference to a user defined type.
2765 Everything in between are type modifiers.
2767 We simply compute the number of modifiers and call the general
2768 function decode_modified_type to do the actual work.
2771 static struct type *
2772 decode_mod_u_d_type (typedata)
2775 struct type *typep = NULL;
2776 unsigned short modcount;
2779 /* Get the total size of the block, exclusive of the size itself */
2781 nbytes = attribute_size (AT_mod_u_d_type);
2782 modcount = target_to_host (typedata, nbytes, GET_UNSIGNED, current_objfile);
2785 /* Deduct the size of the reference type bytes at the end of the block. */
2787 modcount -= attribute_size (AT_user_def_type);
2789 /* Now do the actual decoding */
2791 typep = decode_modified_type (typedata, modcount, AT_mod_u_d_type);
2799 decode_modified_type -- decode modified user or fundamental type
2803 static struct type *decode_modified_type (char *modifiers,
2804 unsigned short modcount, int mtype)
2808 Decode a modified type, either a modified fundamental type or
2809 a modified user defined type. MODIFIERS is a pointer to the
2810 block of bytes that define MODCOUNT modifiers. Immediately
2811 following the last modifier is a short containing the fundamental
2812 type or a long containing the reference to the user defined
2813 type. Which one is determined by MTYPE, which is either
2814 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2815 type we are generating.
2817 We call ourself recursively to generate each modified type,`
2818 until MODCOUNT reaches zero, at which point we have consumed
2819 all the modifiers and generate either the fundamental type or
2820 user defined type. When the recursion unwinds, each modifier
2821 is applied in turn to generate the full modified type.
2825 If we find a modifier that we don't recognize, and it is not one
2826 of those reserved for application specific use, then we issue a
2827 warning and simply ignore the modifier.
2831 We currently ignore MOD_const and MOD_volatile. (FIXME)
2835 static struct type *
2836 decode_modified_type (modifiers, modcount, mtype)
2838 unsigned int modcount;
2841 struct type *typep = NULL;
2842 unsigned short fundtype;
2851 case AT_mod_fund_type:
2852 nbytes = attribute_size (AT_fund_type);
2853 fundtype = target_to_host (modifiers, nbytes, GET_UNSIGNED,
2855 typep = decode_fund_type (fundtype);
2857 case AT_mod_u_d_type:
2858 nbytes = attribute_size (AT_user_def_type);
2859 die_ref = target_to_host (modifiers, nbytes, GET_UNSIGNED,
2861 if ((typep = lookup_utype (die_ref)) == NULL)
2863 typep = alloc_utype (die_ref, NULL);
2867 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype));
2868 typep = lookup_fundamental_type (current_objfile, FT_INTEGER);
2874 modifier = *modifiers++;
2875 typep = decode_modified_type (modifiers, --modcount, mtype);
2878 case MOD_pointer_to:
2879 typep = lookup_pointer_type (typep);
2881 case MOD_reference_to:
2882 typep = lookup_reference_type (typep);
2885 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2888 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2891 if (!(MOD_lo_user <= (unsigned char) modifier
2892 && (unsigned char) modifier <= MOD_hi_user))
2894 SQUAWK (("unknown type modifier %u",
2895 (unsigned char) modifier));
2907 decode_fund_type -- translate basic DWARF type to gdb base type
2911 Given an integer that is one of the fundamental DWARF types,
2912 translate it to one of the basic internal gdb types and return
2913 a pointer to the appropriate gdb type (a "struct type *").
2917 If we encounter a fundamental type that we are unprepared to
2918 deal with, and it is not in the range of those types defined
2919 as application specific types, then we issue a warning and
2920 treat the type as an "int".
2923 static struct type *
2924 decode_fund_type (fundtype)
2925 unsigned int fundtype;
2927 struct type *typep = NULL;
2933 typep = lookup_fundamental_type (current_objfile, FT_VOID);
2936 case FT_boolean: /* Was FT_set in AT&T version */
2937 typep = lookup_fundamental_type (current_objfile, FT_BOOLEAN);
2940 case FT_pointer: /* (void *) */
2941 typep = lookup_fundamental_type (current_objfile, FT_VOID);
2942 typep = lookup_pointer_type (typep);
2946 typep = lookup_fundamental_type (current_objfile, FT_CHAR);
2949 case FT_signed_char:
2950 typep = lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR);
2953 case FT_unsigned_char:
2954 typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
2958 typep = lookup_fundamental_type (current_objfile, FT_SHORT);
2961 case FT_signed_short:
2962 typep = lookup_fundamental_type (current_objfile, FT_SIGNED_SHORT);
2965 case FT_unsigned_short:
2966 typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
2970 typep = lookup_fundamental_type (current_objfile, FT_INTEGER);
2973 case FT_signed_integer:
2974 typep = lookup_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
2977 case FT_unsigned_integer:
2978 typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
2982 typep = lookup_fundamental_type (current_objfile, FT_LONG);
2985 case FT_signed_long:
2986 typep = lookup_fundamental_type (current_objfile, FT_SIGNED_LONG);
2989 case FT_unsigned_long:
2990 typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
2994 typep = lookup_fundamental_type (current_objfile, FT_LONG_LONG);
2997 case FT_signed_long_long:
2998 typep = lookup_fundamental_type (current_objfile, FT_SIGNED_LONG_LONG);
3001 case FT_unsigned_long_long:
3002 typep = lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG);
3006 typep = lookup_fundamental_type (current_objfile, FT_FLOAT);
3009 case FT_dbl_prec_float:
3010 typep = lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
3013 case FT_ext_prec_float:
3014 typep = lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
3018 typep = lookup_fundamental_type (current_objfile, FT_COMPLEX);
3021 case FT_dbl_prec_complex:
3022 typep = lookup_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
3025 case FT_ext_prec_complex:
3026 typep = lookup_fundamental_type (current_objfile, FT_EXT_PREC_COMPLEX);
3031 if ((typep == NULL) && !(FT_lo_user <= fundtype && fundtype <= FT_hi_user))
3033 SQUAWK (("unexpected fundamental type 0x%x", fundtype));
3034 typep = lookup_fundamental_type (current_objfile, FT_VOID);
3044 create_name -- allocate a fresh copy of a string on an obstack
3048 Given a pointer to a string and a pointer to an obstack, allocates
3049 a fresh copy of the string on the specified obstack.
3054 create_name (name, obstackp)
3056 struct obstack *obstackp;
3061 length = strlen (name) + 1;
3062 newname = (char *) obstack_alloc (obstackp, length);
3063 strcpy (newname, name);
3071 basicdieinfo -- extract the minimal die info from raw die data
3075 void basicdieinfo (char *diep, struct dieinfo *dip,
3076 struct objfile *objfile)
3080 Given a pointer to raw DIE data, and a pointer to an instance of a
3081 die info structure, this function extracts the basic information
3082 from the DIE data required to continue processing this DIE, along
3083 with some bookkeeping information about the DIE.
3085 The information we absolutely must have includes the DIE tag,
3086 and the DIE length. If we need the sibling reference, then we
3087 will have to call completedieinfo() to process all the remaining
3090 Note that since there is no guarantee that the data is properly
3091 aligned in memory for the type of access required (indirection
3092 through anything other than a char pointer), and there is no
3093 guarantee that it is in the same byte order as the gdb host,
3094 we call a function which deals with both alignment and byte
3095 swapping issues. Possibly inefficient, but quite portable.
3097 We also take care of some other basic things at this point, such
3098 as ensuring that the instance of the die info structure starts
3099 out completely zero'd and that curdie is initialized for use
3100 in error reporting if we have a problem with the current die.
3104 All DIE's must have at least a valid length, thus the minimum
3105 DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the
3106 DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
3107 are forced to be TAG_padding DIES.
3109 Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
3110 that if a padding DIE is used for alignment and the amount needed is
3111 less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
3112 enough to align to the next alignment boundry.
3116 basicdieinfo (dip, diep, objfile)
3117 struct dieinfo *dip;
3119 struct objfile *objfile;
3122 memset (dip, 0, sizeof (struct dieinfo));
3124 dip -> die_ref = dbroff + (diep - dbbase);
3125 dip -> die_length = target_to_host (diep, SIZEOF_DIE_LENGTH, GET_UNSIGNED,
3127 if (dip -> die_length < SIZEOF_DIE_LENGTH)
3129 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip -> die_length);
3131 else if (dip -> die_length < (SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG))
3133 dip -> die_tag = TAG_padding;
3137 diep += SIZEOF_DIE_LENGTH;
3138 dip -> die_tag = target_to_host (diep, SIZEOF_DIE_TAG, GET_UNSIGNED,
3147 completedieinfo -- finish reading the information for a given DIE
3151 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3155 Given a pointer to an already partially initialized die info structure,
3156 scan the raw DIE data and finish filling in the die info structure
3157 from the various attributes found.
3159 Note that since there is no guarantee that the data is properly
3160 aligned in memory for the type of access required (indirection
3161 through anything other than a char pointer), and there is no
3162 guarantee that it is in the same byte order as the gdb host,
3163 we call a function which deals with both alignment and byte
3164 swapping issues. Possibly inefficient, but quite portable.
3168 Each time we are called, we increment the diecount variable, which
3169 keeps an approximate count of the number of dies processed for
3170 each compilation unit. This information is presented to the user
3171 if the info_verbose flag is set.
3176 completedieinfo (dip, objfile)
3177 struct dieinfo *dip;
3178 struct objfile *objfile;
3180 char *diep; /* Current pointer into raw DIE data */
3181 char *end; /* Terminate DIE scan here */
3182 unsigned short attr; /* Current attribute being scanned */
3183 unsigned short form; /* Form of the attribute */
3184 int nbytes; /* Size of next field to read */
3188 end = diep + dip -> die_length;
3189 diep += SIZEOF_DIE_LENGTH + SIZEOF_DIE_TAG;
3192 attr = target_to_host (diep, SIZEOF_ATTRIBUTE, GET_UNSIGNED, objfile);
3193 diep += SIZEOF_ATTRIBUTE;
3194 if ((nbytes = attribute_size (attr)) == -1)
3196 SQUAWK (("unknown attribute length, skipped remaining attributes"));;
3203 dip -> at_fund_type = target_to_host (diep, nbytes, GET_UNSIGNED,
3207 dip -> at_ordering = target_to_host (diep, nbytes, GET_UNSIGNED,
3211 dip -> at_bit_offset = target_to_host (diep, nbytes, GET_UNSIGNED,
3215 dip -> at_sibling = target_to_host (diep, nbytes, GET_UNSIGNED,
3219 dip -> at_stmt_list = target_to_host (diep, nbytes, GET_UNSIGNED,
3221 dip -> has_at_stmt_list = 1;
3224 dip -> at_low_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
3226 dip -> at_low_pc += baseaddr;
3227 dip -> has_at_low_pc = 1;
3230 dip -> at_high_pc = target_to_host (diep, nbytes, GET_UNSIGNED,
3232 dip -> at_high_pc += baseaddr;
3235 dip -> at_language = target_to_host (diep, nbytes, GET_UNSIGNED,
3238 case AT_user_def_type:
3239 dip -> at_user_def_type = target_to_host (diep, nbytes,
3240 GET_UNSIGNED, objfile);
3243 dip -> at_byte_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3245 dip -> has_at_byte_size = 1;
3248 dip -> at_bit_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3252 dip -> at_member = target_to_host (diep, nbytes, GET_UNSIGNED,
3256 dip -> at_discr = target_to_host (diep, nbytes, GET_UNSIGNED,
3260 dip -> at_location = diep;
3262 case AT_mod_fund_type:
3263 dip -> at_mod_fund_type = diep;
3265 case AT_subscr_data:
3266 dip -> at_subscr_data = diep;
3268 case AT_mod_u_d_type:
3269 dip -> at_mod_u_d_type = diep;
3271 case AT_element_list:
3272 dip -> at_element_list = diep;
3273 dip -> short_element_list = 0;
3275 case AT_short_element_list:
3276 dip -> at_element_list = diep;
3277 dip -> short_element_list = 1;
3279 case AT_discr_value:
3280 dip -> at_discr_value = diep;
3282 case AT_string_length:
3283 dip -> at_string_length = diep;
3286 dip -> at_name = diep;
3289 /* For now, ignore any "hostname:" portion, since gdb doesn't
3290 know how to deal with it. (FIXME). */
3291 dip -> at_comp_dir = strrchr (diep, ':');
3292 if (dip -> at_comp_dir != NULL)
3294 dip -> at_comp_dir++;
3298 dip -> at_comp_dir = diep;
3302 dip -> at_producer = diep;
3304 case AT_start_scope:
3305 dip -> at_start_scope = target_to_host (diep, nbytes, GET_UNSIGNED,
3308 case AT_stride_size:
3309 dip -> at_stride_size = target_to_host (diep, nbytes, GET_UNSIGNED,
3313 dip -> at_src_info = target_to_host (diep, nbytes, GET_UNSIGNED,
3317 dip -> at_prototyped = diep;
3320 /* Found an attribute that we are unprepared to handle. However
3321 it is specifically one of the design goals of DWARF that
3322 consumers should ignore unknown attributes. As long as the
3323 form is one that we recognize (so we know how to skip it),
3324 we can just ignore the unknown attribute. */
3327 form = FORM_FROM_ATTR (attr);
3341 diep += TARGET_FT_POINTER_SIZE (objfile);
3344 diep += 2 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
3347 diep += 4 + target_to_host (diep, nbytes, GET_UNSIGNED, objfile);
3350 diep += strlen (diep) + 1;
3353 SQUAWK (("unknown attribute form (0x%x)", form));
3354 SQUAWK (("unknown attribute length, skipped remaining attributes"));;
3365 target_to_host -- swap in target data to host
3369 target_to_host (char *from, int nbytes, int signextend,
3370 struct objfile *objfile)
3374 Given pointer to data in target format in FROM, a byte count for
3375 the size of the data in NBYTES, a flag indicating whether or not
3376 the data is signed in SIGNEXTEND, and a pointer to the current
3377 objfile in OBJFILE, convert the data to host format and return
3378 the converted value.
3382 FIXME: If we read data that is known to be signed, and expect to
3383 use it as signed data, then we need to explicitly sign extend the
3384 result until the bfd library is able to do this for us.
3388 static unsigned long
3389 target_to_host (from, nbytes, signextend, objfile)
3392 int signextend; /* FIXME: Unused */
3393 struct objfile *objfile;
3395 unsigned long rtnval;
3400 rtnval = bfd_get_64 (objfile -> obfd, (bfd_byte *) from);
3403 rtnval = bfd_get_32 (objfile -> obfd, (bfd_byte *) from);
3406 rtnval = bfd_get_16 (objfile -> obfd, (bfd_byte *) from);
3409 rtnval = bfd_get_8 (objfile -> obfd, (bfd_byte *) from);
3412 dwarfwarn ("no bfd support for %d byte data object", nbytes);
3423 attribute_size -- compute size of data for a DWARF attribute
3427 static int attribute_size (unsigned int attr)
3431 Given a DWARF attribute in ATTR, compute the size of the first
3432 piece of data associated with this attribute and return that
3435 Returns -1 for unrecognized attributes.
3440 attribute_size (attr)
3443 int nbytes; /* Size of next data for this attribute */
3444 unsigned short form; /* Form of the attribute */
3446 form = FORM_FROM_ATTR (attr);
3449 case FORM_STRING: /* A variable length field is next */
3452 case FORM_DATA2: /* Next 2 byte field is the data itself */
3453 case FORM_BLOCK2: /* Next 2 byte field is a block length */
3456 case FORM_DATA4: /* Next 4 byte field is the data itself */
3457 case FORM_BLOCK4: /* Next 4 byte field is a block length */
3458 case FORM_REF: /* Next 4 byte field is a DIE offset */
3461 case FORM_DATA8: /* Next 8 byte field is the data itself */
3464 case FORM_ADDR: /* Next field size is target sizeof(void *) */
3465 nbytes = TARGET_FT_POINTER_SIZE (objfile);
3468 SQUAWK (("unknown attribute form (0x%x)", form));