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"
57 #ifdef MAINTENANCE /* Define to 1 to compile in some maintenance stuff */
58 #define SQUAWK(stuff) dwarfwarn stuff
63 #ifndef R_FP /* FIXME */
64 #define R_FP 14 /* Kludge to get frame pointer register number */
67 typedef unsigned int DIE_REF
; /* Reference to a DIE */
70 #define GCC_PRODUCER "GNU C "
73 #define STREQ(a,b) (strcmp(a,b)==0)
74 #define STREQN(a,b,n) (strncmp(a,b,n)==0)
76 /* Flags to target_to_host() that tell whether or not the data object is
77 expected to be signed. Used, for example, when fetching a signed
78 integer in the target environment which is used as a signed integer
79 in the host environment, and the two environments have different sized
80 ints. In this case, *somebody* has to sign extend the smaller sized
83 #define GET_UNSIGNED 0 /* No sign extension required */
84 #define GET_SIGNED 1 /* Sign extension required */
86 /* Defines for things which are specified in the document "DWARF Debugging
87 Information Format" published by UNIX International, Programming Languages
88 SIG. These defines are based on revision 1.0.0, Jan 20, 1992. */
90 #define SIZEOF_DIE_LENGTH 4
91 #define SIZEOF_DIE_TAG 2
92 #define SIZEOF_ATTRIBUTE 2
93 #define SIZEOF_FORMAT_SPECIFIER 1
94 #define SIZEOF_FMT_FT 2
95 #define SIZEOF_LINETBL_LENGTH 4
96 #define SIZEOF_LINETBL_LINENO 4
97 #define SIZEOF_LINETBL_STMT 2
98 #define SIZEOF_LINETBL_DELTA 4
99 #define SIZEOF_LOC_ATOM_CODE 1
101 #define FORM_FROM_ATTR(attr) ((attr) & 0xF) /* Implicitly specified */
103 /* Macros that return the sizes of various types of data in the target
106 FIXME: Currently these are just compile time constants (as they are in
107 other parts of gdb as well). They need to be able to get the right size
108 either from the bfd or possibly from the DWARF info. It would be nice if
109 the DWARF producer inserted DIES that describe the fundamental types in
110 the target environment into the DWARF info, similar to the way dbx stabs
111 producers produce information about their fundamental types. */
113 #define TARGET_FT_POINTER_SIZE(objfile) (TARGET_PTR_BIT / TARGET_CHAR_BIT)
114 #define TARGET_FT_LONG_SIZE(objfile) (TARGET_LONG_BIT / TARGET_CHAR_BIT)
116 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
117 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
118 However, the Issue 2 DWARF specification from AT&T defines it as
119 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
120 For backwards compatibility with the AT&T compiler produced executables
121 we define AT_short_element_list for this variant. */
123 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
125 /* External variables referenced. */
127 extern int info_verbose
; /* From main.c; nonzero => verbose */
128 extern char *warning_pre_print
; /* From utils.c */
130 /* The DWARF debugging information consists of two major pieces,
131 one is a block of DWARF Information Entries (DIE's) and the other
132 is a line number table. The "struct dieinfo" structure contains
133 the information for a single DIE, the one currently being processed.
135 In order to make it easier to randomly access the attribute fields
136 of the current DIE, which are specifically unordered within the DIE,
137 each DIE is scanned and an instance of the "struct dieinfo"
138 structure is initialized.
140 Initialization is done in two levels. The first, done by basicdieinfo(),
141 just initializes those fields that are vital to deciding whether or not
142 to use this DIE, how to skip past it, etc. The second, done by the
143 function completedieinfo(), fills in the rest of the information.
145 Attributes which have block forms are not interpreted at the time
146 the DIE is scanned, instead we just save pointers to the start
147 of their value fields.
149 Some fields have a flag <name>_p that is set when the value of the
150 field is valid (I.E. we found a matching attribute in the DIE). Since
151 we may want to test for the presence of some attributes in the DIE,
152 such as AT_low_pc, without restricting the values of the field,
153 we need someway to note that we found such an attribute.
160 char * die
; /* Pointer to the raw DIE data */
161 unsigned long die_length
; /* Length of the raw DIE data */
162 DIE_REF die_ref
; /* Offset of this DIE */
163 unsigned short die_tag
; /* Tag for this DIE */
164 unsigned long at_padding
;
165 unsigned long at_sibling
;
168 unsigned short at_fund_type
;
169 BLOCK
* at_mod_fund_type
;
170 unsigned long at_user_def_type
;
171 BLOCK
* at_mod_u_d_type
;
172 unsigned short at_ordering
;
173 BLOCK
* at_subscr_data
;
174 unsigned long at_byte_size
;
175 unsigned short at_bit_offset
;
176 unsigned long at_bit_size
;
177 BLOCK
* at_element_list
;
178 unsigned long at_stmt_list
;
179 unsigned long at_low_pc
;
180 unsigned long at_high_pc
;
181 unsigned long at_language
;
182 unsigned long at_member
;
183 unsigned long at_discr
;
184 BLOCK
* at_discr_value
;
185 unsigned short at_visibility
;
186 unsigned long at_import
;
187 BLOCK
* at_string_length
;
190 unsigned long at_frame_base
;
191 unsigned long at_start_scope
;
192 unsigned long at_stride_size
;
193 unsigned long at_src_info
;
194 char * at_prototyped
;
195 unsigned int has_at_low_pc
:1;
196 unsigned int has_at_stmt_list
:1;
197 unsigned int short_element_list
:1;
200 static int diecount
; /* Approximate count of dies for compilation unit */
201 static struct dieinfo
*curdie
; /* For warnings and such */
203 static char *dbbase
; /* Base pointer to dwarf info */
204 static int dbroff
; /* Relative offset from start of .debug section */
205 static char *lnbase
; /* Base pointer to line section */
206 static int isreg
; /* Kludge to identify register variables */
207 static int offreg
; /* Kludge to identify basereg references */
209 /* This value is added to each symbol value. FIXME: Generalize to
210 the section_offsets structure used by dbxread. */
211 static CORE_ADDR baseaddr
; /* Add to each symbol value */
213 /* The section offsets used in the current psymtab or symtab. FIXME,
214 only used to pass one value (baseaddr) at the moment. */
215 static struct section_offsets
*base_section_offsets
;
217 /* Each partial symbol table entry contains a pointer to private data for the
218 read_symtab() function to use when expanding a partial symbol table entry
219 to a full symbol table entry. For DWARF debugging info, this data is
220 contained in the following structure and macros are provided for easy
221 access to the members given a pointer to a partial symbol table entry.
223 dbfoff Always the absolute file offset to the start of the ".debug"
224 section for the file containing the DIE's being accessed.
226 dbroff Relative offset from the start of the ".debug" access to the
227 first DIE to be accessed. When building the partial symbol
228 table, this value will be zero since we are accessing the
229 entire ".debug" section. When expanding a partial symbol
230 table entry, this value will be the offset to the first
231 DIE for the compilation unit containing the symbol that
232 triggers the expansion.
234 dblength The size of the chunk of DIE's being examined, in bytes.
236 lnfoff The absolute file offset to the line table fragment. Ignored
237 when building partial symbol tables, but used when expanding
238 them, and contains the absolute file offset to the fragment
239 of the ".line" section containing the line numbers for the
240 current compilation unit.
244 int dbfoff
; /* Absolute file offset to start of .debug section */
245 int dbroff
; /* Relative offset from start of .debug section */
246 int dblength
; /* Size of the chunk of DIE's being examined */
247 int lnfoff
; /* Absolute file offset to line table fragment */
250 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
251 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
252 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
253 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
255 /* The generic symbol table building routines have separate lists for
256 file scope symbols and all all other scopes (local scopes). So
257 we need to select the right one to pass to add_symbol_to_list().
258 We do it by keeping a pointer to the correct list in list_in_scope.
260 FIXME: The original dwarf code just treated the file scope as the first
261 local scope, and all other local scopes as nested local scopes, and worked
262 fine. Check to see if we really need to distinguish these in buildsym.c */
264 struct pending
**list_in_scope
= &file_symbols
;
266 /* DIES which have user defined types or modified user defined types refer to
267 other DIES for the type information. Thus we need to associate the offset
268 of a DIE for a user defined type with a pointer to the type information.
270 Originally this was done using a simple but expensive algorithm, with an
271 array of unsorted structures, each containing an offset/type-pointer pair.
272 This array was scanned linearly each time a lookup was done. The result
273 was that gdb was spending over half it's startup time munging through this
274 array of pointers looking for a structure that had the right offset member.
276 The second attempt used the same array of structures, but the array was
277 sorted using qsort each time a new offset/type was recorded, and a binary
278 search was used to find the type pointer for a given DIE offset. This was
279 even slower, due to the overhead of sorting the array each time a new
280 offset/type pair was entered.
282 The third attempt uses a fixed size array of type pointers, indexed by a
283 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
284 we can divide any DIE offset by 4 to obtain a unique index into this fixed
285 size array. Since each element is a 4 byte pointer, it takes exactly as
286 much memory to hold this array as to hold the DWARF info for a given
287 compilation unit. But it gets freed as soon as we are done with it. */
289 static struct type
**utypes
; /* Pointer to array of user type pointers */
290 static int numutypes
; /* Max number of user type pointers */
292 /* Forward declarations of static functions so we don't have to worry
293 about ordering within this file. */
296 attribute_size
PARAMS ((unsigned int));
299 target_to_host
PARAMS ((char *, int, int, struct objfile
*));
302 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
305 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
308 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
311 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
318 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
321 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
322 unsigned int, struct objfile
*));
325 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
328 init_psymbol_list
PARAMS ((struct objfile
*, int));
331 basicdieinfo
PARAMS ((struct dieinfo
*, char *, struct objfile
*));
334 completedieinfo
PARAMS ((struct dieinfo
*, struct objfile
*));
337 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
340 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
342 static struct symtab
*
343 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
346 process_dies
PARAMS ((char *, char *, struct objfile
*));
349 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
353 decode_array_element_type
PARAMS ((char *));
356 decode_subscr_data
PARAMS ((char *, char *));
359 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
362 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
365 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
368 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
371 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
374 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
377 decode_line_numbers
PARAMS ((char *));
380 decode_die_type
PARAMS ((struct dieinfo
*));
383 decode_mod_fund_type
PARAMS ((char *));
386 decode_mod_u_d_type
PARAMS ((char *));
389 decode_modified_type
PARAMS ((char *, unsigned int, int));
392 decode_fund_type
PARAMS ((unsigned int));
395 create_name
PARAMS ((char *, struct obstack
*));
398 lookup_utype
PARAMS ((DIE_REF
));
401 alloc_utype
PARAMS ((DIE_REF
, struct type
*));
403 static struct symbol
*
404 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
407 locval
PARAMS ((char *));
410 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
417 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
421 void dwarf_build_psymtabs (int desc, char *filename,
422 struct section_offsets *section_offsets,
423 int mainline, unsigned int dbfoff, unsigned int dbsize,
424 unsigned int lnoffset, unsigned int lnsize,
425 struct objfile *objfile)
429 This function is called upon to build partial symtabs from files
430 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
432 It is passed a file descriptor for an open file containing the DIES
433 and line number information, the corresponding filename for that
434 file, a base address for relocating the symbols, a flag indicating
435 whether or not this debugging information is from a "main symbol
436 table" rather than a shared library or dynamically linked file,
437 and file offset/size pairs for the DIE information and line number
447 dwarf_build_psymtabs (desc
, filename
, section_offsets
, mainline
, dbfoff
, dbsize
,
448 lnoffset
, lnsize
, objfile
)
451 struct section_offsets
*section_offsets
;
455 unsigned int lnoffset
;
457 struct objfile
*objfile
;
459 struct cleanup
*back_to
;
461 current_objfile
= objfile
;
462 dbbase
= xmalloc (dbsize
);
464 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
465 (read (desc
, dbbase
, dbsize
) != dbsize
))
468 error ("can't read DWARF data from '%s'", filename
);
470 back_to
= make_cleanup (free
, dbbase
);
472 /* If we are reinitializing, or if we have never loaded syms yet, init.
473 Since we have no idea how many DIES we are looking at, we just guess
474 some arbitrary value. */
476 if (mainline
|| objfile
-> global_psymbols
.size
== 0 ||
477 objfile
-> static_psymbols
.size
== 0)
479 init_psymbol_list (objfile
, 1024);
482 /* Save the relocation factor where everybody can see it. */
484 base_section_offsets
= section_offsets
;
485 baseaddr
= ANOFFSET (section_offsets
, 0);
487 /* Follow the compilation unit sibling chain, building a partial symbol
488 table entry for each one. Save enough information about each compilation
489 unit to locate the full DWARF information later. */
491 scan_compilation_units (filename
, dbbase
, dbbase
+ dbsize
,
492 dbfoff
, lnoffset
, objfile
);
494 do_cleanups (back_to
);
495 current_objfile
= NULL
;
503 record_minimal_symbol -- add entry to gdb's minimal symbol table
507 static void record_minimal_symbol (char *name, CORE_ADDR address,
508 enum minimal_symbol_type ms_type,
509 struct objfile *objfile)
513 Given a pointer to the name of a symbol that should be added to the
514 minimal symbol table, and the address associated with that
515 symbol, records this information for later use in building the
516 minimal symbol table.
521 record_minimal_symbol (name
, address
, ms_type
, objfile
)
524 enum minimal_symbol_type ms_type
;
525 struct objfile
*objfile
;
527 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
528 prim_record_minimal_symbol (name
, address
, ms_type
);
535 dwarfwarn -- issue a DWARF related warning
539 Issue warnings about DWARF related things that aren't serious enough
540 to warrant aborting with an error, but should not be ignored either.
541 This includes things like detectable corruption in DIE's, missing
542 DIE's, unimplemented features, etc.
544 In general, running across tags or attributes that we don't recognize
545 is not considered to be a problem and we should not issue warnings
550 We mostly follow the example of the error() routine, but without
551 returning to command level. It is arguable about whether warnings
552 should be issued at all, and if so, where they should go (stdout or
555 We assume that curdie is valid and contains at least the basic
556 information for the DIE where the problem was noticed.
567 fmt
= va_arg (ap
, char *);
569 fprintf (stderr
, "warning: DWARF ref 0x%x: ", curdie
-> die_ref
);
570 if (curdie
-> at_name
)
572 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
574 vfprintf (stderr
, fmt
, ap
);
575 fprintf (stderr
, "\n");
584 read_lexical_block_scope -- process all dies in a lexical block
588 static void read_lexical_block_scope (struct dieinfo *dip,
589 char *thisdie, char *enddie)
593 Process all the DIES contained within a lexical block scope.
594 Start a new scope, process the dies, and then close the scope.
599 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
603 struct objfile
*objfile
;
605 register struct context_stack
*new;
607 push_context (0, dip
-> at_low_pc
);
608 process_dies (thisdie
+ dip
-> die_length
, enddie
, objfile
);
609 new = pop_context ();
610 if (local_symbols
!= NULL
)
612 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
613 dip
-> at_high_pc
, objfile
);
615 local_symbols
= new -> locals
;
622 lookup_utype -- look up a user defined type from die reference
626 static type *lookup_utype (DIE_REF die_ref)
630 Given a DIE reference, lookup the user defined type associated with
631 that DIE, if it has been registered already. If not registered, then
632 return NULL. Alloc_utype() can be called to register an empty
633 type for this reference, which will be filled in later when the
634 actual referenced DIE is processed.
638 lookup_utype (die_ref
)
641 struct type
*type
= NULL
;
644 utypeidx
= (die_ref
- dbroff
) / 4;
645 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
647 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", die_ref
);
651 type
= *(utypes
+ utypeidx
);
661 alloc_utype -- add a user defined type for die reference
665 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
669 Given a die reference DIE_REF, and a possible pointer to a user
670 defined type UTYPEP, register that this reference has a user
671 defined type and either use the specified type in UTYPEP or
672 make a new empty type that will be filled in later.
674 We should only be called after calling lookup_utype() to verify that
675 there is not currently a type registered for DIE_REF.
679 alloc_utype (die_ref
, utypep
)
686 utypeidx
= (die_ref
- dbroff
) / 4;
687 typep
= utypes
+ utypeidx
;
688 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
690 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
691 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", die_ref
);
693 else if (*typep
!= NULL
)
696 SQUAWK (("internal error: dup user type allocation"));
702 utypep
= (struct type
*)
703 obstack_alloc (¤t_objfile
-> type_obstack
,
704 sizeof (struct type
));
705 memset (utypep
, 0, sizeof (struct type
));
706 TYPE_OBJFILE (utypep
) = current_objfile
;
717 decode_die_type -- return a type for a specified die
721 static struct type *decode_die_type (struct dieinfo *dip)
725 Given a pointer to a die information structure DIP, decode the
726 type of the die and return a pointer to the decoded type. All
727 dies without specific types default to type int.
731 decode_die_type (dip
)
734 struct type
*type
= NULL
;
736 if (dip
-> at_fund_type
!= 0)
738 type
= decode_fund_type (dip
-> at_fund_type
);
740 else if (dip
-> at_mod_fund_type
!= NULL
)
742 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
744 else if (dip
-> at_user_def_type
)
746 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
748 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
751 else if (dip
-> at_mod_u_d_type
)
753 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
757 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
766 struct_type -- compute and return the type for a struct or union
770 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
771 char *enddie, struct objfile *objfile)
775 Given pointer to a die information structure for a die which
776 defines a union or structure (and MUST define one or the other),
777 and pointers to the raw die data that define the range of dies which
778 define the members, compute and return the user defined type for the
783 struct_type (dip
, thisdie
, enddie
, objfile
)
787 struct objfile
*objfile
;
791 struct nextfield
*next
;
794 struct nextfield
*list
= NULL
;
795 struct nextfield
*new;
802 if ((type
= lookup_utype (dip
-> die_ref
)) == NULL
)
804 /* No forward references created an empty type, so install one now */
805 type
= alloc_utype (dip
-> die_ref
, NULL
);
807 INIT_CPLUS_SPECIFIC(type
);
808 switch (dip
-> die_tag
)
810 case TAG_structure_type
:
811 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
815 TYPE_CODE (type
) = TYPE_CODE_UNION
;
819 /* Should never happen */
820 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
822 SQUAWK (("missing structure or union tag"));
825 /* Some compilers try to be helpful by inventing "fake" names for
826 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
827 Thanks, but no thanks... */
828 if (dip
-> at_name
!= NULL
829 && *dip
-> at_name
!= '~'
830 && *dip
-> at_name
!= '.')
832 TYPE_NAME (type
) = obconcat (&objfile
-> type_obstack
,
833 tpart1
, " ", dip
-> at_name
);
835 if (dip
-> at_byte_size
!= 0)
837 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
839 thisdie
+= dip
-> die_length
;
840 while (thisdie
< enddie
)
842 basicdieinfo (&mbr
, thisdie
, objfile
);
843 completedieinfo (&mbr
, objfile
);
844 if (mbr
.die_length
<= SIZEOF_DIE_LENGTH
)
848 else if (mbr
.at_sibling
!= 0)
850 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
854 nextdie
= thisdie
+ mbr
.die_length
;
859 /* Get space to record the next field's data. */
860 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
865 obsavestring (mbr
.at_name
, strlen (mbr
.at_name
),
866 &objfile
-> type_obstack
);
867 list
-> field
.type
= decode_die_type (&mbr
);
868 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
869 /* Handle bit fields. */
870 list
-> field
.bitsize
= mbr
.at_bit_size
;
872 /* For big endian bits, the at_bit_offset gives the additional
873 bit offset from the MSB of the containing anonymous object to
874 the MSB of the field. We don't have to do anything special
875 since we don't need to know the size of the anonymous object. */
876 list
-> field
.bitpos
+= mbr
.at_bit_offset
;
878 /* For little endian bits, we need to have a non-zero at_bit_size,
879 so that we know we are in fact dealing with a bitfield. Compute
880 the bit offset to the MSB of the anonymous object, subtract off
881 the number of bits from the MSB of the field to the MSB of the
882 object, and then subtract off the number of bits of the field
883 itself. The result is the bit offset of the LSB of the field. */
884 if (mbr
.at_bit_size
> 0)
886 list
-> field
.bitpos
+=
887 mbr
.at_byte_size
* 8 - mbr
.at_bit_offset
- mbr
.at_bit_size
;
893 process_dies (thisdie
, nextdie
, objfile
);
898 /* Now create the vector of fields, and record how big it is. We may
899 not even have any fields, if this DIE was generated due to a reference
900 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
901 set, which clues gdb in to the fact that it needs to search elsewhere
902 for the full structure definition. */
905 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
909 TYPE_NFIELDS (type
) = nfields
;
910 TYPE_FIELDS (type
) = (struct field
*)
911 obstack_alloc (&objfile
-> type_obstack
,
912 sizeof (struct field
) * nfields
);
913 /* Copy the saved-up fields into the field vector. */
914 for (n
= nfields
; list
; list
= list
-> next
)
916 TYPE_FIELD (type
, --n
) = list
-> field
;
926 read_structure_scope -- process all dies within struct or union
930 static void read_structure_scope (struct dieinfo *dip,
931 char *thisdie, char *enddie, struct objfile *objfile)
935 Called when we find the DIE that starts a structure or union
936 scope (definition) to process all dies that define the members
937 of the structure or union. DIP is a pointer to the die info
938 struct for the DIE that names the structure or union.
942 Note that we need to call struct_type regardless of whether or not
943 the DIE has an at_name attribute, since it might be an anonymous
944 structure or union. This gets the type entered into our set of
947 However, if the structure is incomplete (an opaque struct/union)
948 then suppress creating a symbol table entry for it since gdb only
949 wants to find the one with the complete definition. Note that if
950 it is complete, we just call new_symbol, which does it's own
951 checking about whether the struct/union is anonymous or not (and
952 suppresses creating a symbol table entry itself).
957 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
961 struct objfile
*objfile
;
966 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
967 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
969 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
971 SYMBOL_TYPE (sym
) = type
;
980 decode_array_element_type -- decode type of the array elements
984 static struct type *decode_array_element_type (char *scan, char *end)
988 As the last step in decoding the array subscript information for an
989 array DIE, we need to decode the type of the array elements. We are
990 passed a pointer to this last part of the subscript information and
991 must return the appropriate type. If the type attribute is not
992 recognized, just warn about the problem and return type int.
996 decode_array_element_type (scan
)
1001 unsigned short attribute
;
1002 unsigned short fundtype
;
1005 attribute
= target_to_host (scan
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
,
1007 scan
+= SIZEOF_ATTRIBUTE
;
1008 if ((nbytes
= attribute_size (attribute
)) == -1)
1010 SQUAWK (("bad array element type attribute 0x%x", attribute
));
1011 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1018 fundtype
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1020 typep
= decode_fund_type (fundtype
);
1022 case AT_mod_fund_type
:
1023 typep
= decode_mod_fund_type (scan
);
1025 case AT_user_def_type
:
1026 die_ref
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1028 if ((typep
= lookup_utype (die_ref
)) == NULL
)
1030 typep
= alloc_utype (die_ref
, NULL
);
1033 case AT_mod_u_d_type
:
1034 typep
= decode_mod_u_d_type (scan
);
1037 SQUAWK (("bad array element type attribute 0x%x", attribute
));
1038 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1049 decode_subscr_data -- decode array subscript and element type data
1053 static struct type *decode_subscr_data (char *scan, char *end)
1057 The array subscripts and the data type of the elements of an
1058 array are described by a list of data items, stored as a block
1059 of contiguous bytes. There is a data item describing each array
1060 dimension, and a final data item describing the element type.
1061 The data items are ordered the same as their appearance in the
1062 source (I.E. leftmost dimension first, next to leftmost second,
1065 We are passed a pointer to the start of the block of bytes
1066 containing the data items, and a pointer to the first byte past
1067 the data. This function decodes the data and returns a type.
1070 FIXME: This code only implements the forms currently used
1071 by the AT&T and GNU C compilers.
1073 The end pointer is supplied for error checking, maybe we should
1077 static struct type
*
1078 decode_subscr_data (scan
, end
)
1082 struct type
*typep
= NULL
;
1083 struct type
*nexttype
;
1084 unsigned int format
;
1085 unsigned short fundtype
;
1086 unsigned long lowbound
;
1087 unsigned long highbound
;
1090 format
= target_to_host (scan
, SIZEOF_FORMAT_SPECIFIER
, GET_UNSIGNED
,
1092 scan
+= SIZEOF_FORMAT_SPECIFIER
;
1096 typep
= decode_array_element_type (scan
);
1099 fundtype
= target_to_host (scan
, SIZEOF_FMT_FT
, GET_UNSIGNED
,
1101 scan
+= SIZEOF_FMT_FT
;
1102 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1103 && fundtype
!= FT_unsigned_integer
)
1105 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1110 nbytes
= TARGET_FT_LONG_SIZE (current_objfile
);
1111 lowbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1114 highbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1117 nexttype
= decode_subscr_data (scan
, end
);
1118 if (nexttype
!= NULL
)
1120 typep
= (struct type
*)
1121 obstack_alloc (¤t_objfile
-> type_obstack
,
1122 sizeof (struct type
));
1123 memset (typep
, 0, sizeof (struct type
));
1124 TYPE_OBJFILE (typep
) = current_objfile
;
1125 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1126 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1127 TYPE_LENGTH (typep
) *= (highbound
- lowbound
) + 1;
1128 TYPE_TARGET_TYPE (typep
) = nexttype
;
1139 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1142 SQUAWK (("unknown array subscript format %x", format
));
1152 dwarf_read_array_type -- read TAG_array_type DIE
1156 static void dwarf_read_array_type (struct dieinfo *dip)
1160 Extract all information from a TAG_array_type DIE and add to
1161 the user defined type vector.
1165 dwarf_read_array_type (dip
)
1166 struct dieinfo
*dip
;
1172 unsigned short blocksz
;
1175 if (dip
-> at_ordering
!= ORD_row_major
)
1177 /* FIXME: Can gdb even handle column major arrays? */
1178 SQUAWK (("array not row major; not handled correctly"));
1180 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1182 nbytes
= attribute_size (AT_subscr_data
);
1183 blocksz
= target_to_host (sub
, nbytes
, GET_UNSIGNED
, current_objfile
);
1184 subend
= sub
+ nbytes
+ blocksz
;
1186 type
= decode_subscr_data (sub
, subend
);
1189 if ((utype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1191 utype
= alloc_utype (dip
-> die_ref
, NULL
);
1193 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1194 TYPE_TARGET_TYPE (utype
) =
1195 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1196 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1200 if ((utype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1202 alloc_utype (dip
-> die_ref
, type
);
1206 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1207 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1208 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1218 read_tag_pointer_type -- read TAG_pointer_type DIE
1222 static void read_tag_pointer_type (struct dieinfo *dip)
1226 Extract all information from a TAG_pointer_type DIE and add to
1227 the user defined type vector.
1231 read_tag_pointer_type (dip
)
1232 struct dieinfo
*dip
;
1237 type
= decode_die_type (dip
);
1238 if ((utype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1240 utype
= lookup_pointer_type (type
);
1241 alloc_utype (dip
-> die_ref
, utype
);
1245 TYPE_TARGET_TYPE (utype
) = type
;
1246 TYPE_POINTER_TYPE (type
) = utype
;
1248 /* We assume the machine has only one representation for pointers! */
1249 /* FIXME: This confuses host<->target data representations, and is a
1250 poor assumption besides. */
1252 TYPE_LENGTH (utype
) = sizeof (char *);
1253 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1261 read_subroutine_type -- process TAG_subroutine_type dies
1265 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1270 Handle DIES due to C code like:
1273 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1279 The parameter DIES are currently ignored. See if gdb has a way to
1280 include this info in it's type system, and decode them if so. Is
1281 this what the type structure's "arg_types" field is for? (FIXME)
1285 read_subroutine_type (dip
, thisdie
, enddie
)
1286 struct dieinfo
*dip
;
1290 struct type
*type
; /* Type that this function returns */
1291 struct type
*ftype
; /* Function that returns above type */
1293 /* Decode the type that this subroutine returns */
1295 type
= decode_die_type (dip
);
1297 /* Check to see if we already have a partially constructed user
1298 defined type for this DIE, from a forward reference. */
1300 if ((ftype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1302 /* This is the first reference to one of these types. Make
1303 a new one and place it in the user defined types. */
1304 ftype
= lookup_function_type (type
);
1305 alloc_utype (dip
-> die_ref
, ftype
);
1309 /* We have an existing partially constructed type, so bash it
1310 into the correct type. */
1311 TYPE_TARGET_TYPE (ftype
) = type
;
1312 TYPE_FUNCTION_TYPE (type
) = ftype
;
1313 TYPE_LENGTH (ftype
) = 1;
1314 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1322 read_enumeration -- process dies which define an enumeration
1326 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1327 char *enddie, struct objfile *objfile)
1331 Given a pointer to a die which begins an enumeration, process all
1332 the dies that define the members of the enumeration.
1336 Note that we need to call enum_type regardless of whether or not we
1337 have a symbol, since we might have an enum without a tag name (thus
1338 no symbol for the tagname).
1342 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1343 struct dieinfo
*dip
;
1346 struct objfile
*objfile
;
1351 type
= enum_type (dip
, objfile
);
1352 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1354 SYMBOL_TYPE (sym
) = type
;
1362 enum_type -- decode and return a type for an enumeration
1366 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1370 Given a pointer to a die information structure for the die which
1371 starts an enumeration, process all the dies that define the members
1372 of the enumeration and return a type pointer for the enumeration.
1374 At the same time, for each member of the enumeration, create a
1375 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1376 and give it the type of the enumeration itself.
1380 Note that the DWARF specification explicitly mandates that enum
1381 constants occur in reverse order from the source program order,
1382 for "consistency" and because this ordering is easier for many
1383 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1384 Entries). Because gdb wants to see the enum members in program
1385 source order, we have to ensure that the order gets reversed while
1386 we are processing them.
1389 static struct type
*
1390 enum_type (dip
, objfile
)
1391 struct dieinfo
*dip
;
1392 struct objfile
*objfile
;
1396 struct nextfield
*next
;
1399 struct nextfield
*list
= NULL
;
1400 struct nextfield
*new;
1405 unsigned short blocksz
;
1409 if ((type
= lookup_utype (dip
-> die_ref
)) == NULL
)
1411 /* No forward references created an empty type, so install one now */
1412 type
= alloc_utype (dip
-> die_ref
, NULL
);
1414 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1415 /* Some compilers try to be helpful by inventing "fake" names for
1416 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1417 Thanks, but no thanks... */
1418 if (dip
-> at_name
!= NULL
1419 && *dip
-> at_name
!= '~'
1420 && *dip
-> at_name
!= '.')
1422 TYPE_NAME (type
) = obconcat (&objfile
-> type_obstack
, "enum",
1423 " ", dip
-> at_name
);
1425 if (dip
-> at_byte_size
!= 0)
1427 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1429 if ((scan
= dip
-> at_element_list
) != NULL
)
1431 if (dip
-> short_element_list
)
1433 nbytes
= attribute_size (AT_short_element_list
);
1437 nbytes
= attribute_size (AT_element_list
);
1439 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
1440 listend
= scan
+ nbytes
+ blocksz
;
1442 while (scan
< listend
)
1444 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1447 list
-> field
.type
= NULL
;
1448 list
-> field
.bitsize
= 0;
1449 list
-> field
.bitpos
=
1450 target_to_host (scan
, TARGET_FT_LONG_SIZE (objfile
), GET_SIGNED
,
1452 scan
+= TARGET_FT_LONG_SIZE (objfile
);
1453 list
-> field
.name
= obsavestring (scan
, strlen (scan
),
1454 &objfile
-> type_obstack
);
1455 scan
+= strlen (scan
) + 1;
1457 /* Handcraft a new symbol for this enum member. */
1458 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1459 sizeof (struct symbol
));
1460 memset (sym
, 0, sizeof (struct symbol
));
1461 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
,
1462 &objfile
->symbol_obstack
);
1463 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1464 SYMBOL_CLASS (sym
) = LOC_CONST
;
1465 SYMBOL_TYPE (sym
) = type
;
1466 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1467 add_symbol_to_list (sym
, list_in_scope
);
1469 /* Now create the vector of fields, and record how big it is. This is
1470 where we reverse the order, by pulling the members off the list in
1471 reverse order from how they were inserted. If we have no fields
1472 (this is apparently possible in C++) then skip building a field
1476 TYPE_NFIELDS (type
) = nfields
;
1477 TYPE_FIELDS (type
) = (struct field
*)
1478 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1479 /* Copy the saved-up fields into the field vector. */
1480 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1482 TYPE_FIELD (type
, n
++) = list
-> field
;
1493 read_func_scope -- process all dies within a function scope
1497 Process all dies within a given function scope. We are passed
1498 a die information structure pointer DIP for the die which
1499 starts the function scope, and pointers into the raw die data
1500 that define the dies within the function scope.
1502 For now, we ignore lexical block scopes within the function.
1503 The problem is that AT&T cc does not define a DWARF lexical
1504 block scope for the function itself, while gcc defines a
1505 lexical block scope for the function. We need to think about
1506 how to handle this difference, or if it is even a problem.
1511 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1512 struct dieinfo
*dip
;
1515 struct objfile
*objfile
;
1517 register struct context_stack
*new;
1519 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1520 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1522 objfile
-> ei
.entry_func_lowpc
= dip
-> at_low_pc
;
1523 objfile
-> ei
.entry_func_highpc
= dip
-> at_high_pc
;
1525 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1527 objfile
-> ei
.main_func_lowpc
= dip
-> at_low_pc
;
1528 objfile
-> ei
.main_func_highpc
= dip
-> at_high_pc
;
1530 new = push_context (0, dip
-> at_low_pc
);
1531 new -> name
= new_symbol (dip
, objfile
);
1532 list_in_scope
= &local_symbols
;
1533 process_dies (thisdie
+ dip
-> die_length
, enddie
, objfile
);
1534 new = pop_context ();
1535 /* Make a block for the local symbols within. */
1536 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1537 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1538 list_in_scope
= &file_symbols
;
1545 read_file_scope -- process all dies within a file scope
1549 Process all dies within a given file scope. We are passed a
1550 pointer to the die information structure for the die which
1551 starts the file scope, and pointers into the raw die data which
1552 mark the range of dies within the file scope.
1554 When the partial symbol table is built, the file offset for the line
1555 number table for each compilation unit is saved in the partial symbol
1556 table entry for that compilation unit. As the symbols for each
1557 compilation unit are read, the line number table is read into memory
1558 and the variable lnbase is set to point to it. Thus all we have to
1559 do is use lnbase to access the line number table for the current
1564 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1565 struct dieinfo
*dip
;
1568 struct objfile
*objfile
;
1570 struct cleanup
*back_to
;
1571 struct symtab
*symtab
;
1573 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1574 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1576 objfile
-> ei
.entry_file_lowpc
= dip
-> at_low_pc
;
1577 objfile
-> ei
.entry_file_highpc
= dip
-> at_high_pc
;
1579 if (dip
-> at_producer
!= NULL
)
1581 processing_gcc_compilation
=
1582 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1584 numutypes
= (enddie
- thisdie
) / 4;
1585 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1586 back_to
= make_cleanup (free
, utypes
);
1587 memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1588 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1589 decode_line_numbers (lnbase
);
1590 process_dies (thisdie
+ dip
-> die_length
, enddie
, objfile
);
1591 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1592 /* FIXME: The following may need to be expanded for other languages */
1593 switch (dip
-> at_language
)
1597 symtab
-> language
= language_c
;
1599 case LANG_C_PLUS_PLUS
:
1600 symtab
-> language
= language_cplus
;
1605 do_cleanups (back_to
);
1614 process_dies -- process a range of DWARF Information Entries
1618 static void process_dies (char *thisdie, char *enddie,
1619 struct objfile *objfile)
1623 Process all DIE's in a specified range. May be (and almost
1624 certainly will be) called recursively.
1628 process_dies (thisdie
, enddie
, objfile
)
1631 struct objfile
*objfile
;
1636 while (thisdie
< enddie
)
1638 basicdieinfo (&di
, thisdie
, objfile
);
1639 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
1643 else if (di
.die_tag
== TAG_padding
)
1645 nextdie
= thisdie
+ di
.die_length
;
1649 completedieinfo (&di
, objfile
);
1650 if (di
.at_sibling
!= 0)
1652 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1656 nextdie
= thisdie
+ di
.die_length
;
1660 case TAG_compile_unit
:
1661 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1663 case TAG_global_subroutine
:
1664 case TAG_subroutine
:
1665 if (di
.has_at_low_pc
)
1667 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1670 case TAG_lexical_block
:
1671 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1673 case TAG_structure_type
:
1674 case TAG_union_type
:
1675 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1677 case TAG_enumeration_type
:
1678 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1680 case TAG_subroutine_type
:
1681 read_subroutine_type (&di
, thisdie
, nextdie
);
1683 case TAG_array_type
:
1684 dwarf_read_array_type (&di
);
1686 case TAG_pointer_type
:
1687 read_tag_pointer_type (&di
);
1690 new_symbol (&di
, objfile
);
1702 decode_line_numbers -- decode a line number table fragment
1706 static void decode_line_numbers (char *tblscan, char *tblend,
1707 long length, long base, long line, long pc)
1711 Translate the DWARF line number information to gdb form.
1713 The ".line" section contains one or more line number tables, one for
1714 each ".line" section from the objects that were linked.
1716 The AT_stmt_list attribute for each TAG_source_file entry in the
1717 ".debug" section contains the offset into the ".line" section for the
1718 start of the table for that file.
1720 The table itself has the following structure:
1722 <table length><base address><source statement entry>
1723 4 bytes 4 bytes 10 bytes
1725 The table length is the total size of the table, including the 4 bytes
1726 for the length information.
1728 The base address is the address of the first instruction generated
1729 for the source file.
1731 Each source statement entry has the following structure:
1733 <line number><statement position><address delta>
1734 4 bytes 2 bytes 4 bytes
1736 The line number is relative to the start of the file, starting with
1739 The statement position either -1 (0xFFFF) or the number of characters
1740 from the beginning of the line to the beginning of the statement.
1742 The address delta is the difference between the base address and
1743 the address of the first instruction for the statement.
1745 Note that we must copy the bytes from the packed table to our local
1746 variables before attempting to use them, to avoid alignment problems
1747 on some machines, particularly RISC processors.
1751 Does gdb expect the line numbers to be sorted? They are now by
1752 chance/luck, but are not required to be. (FIXME)
1754 The line with number 0 is unused, gdb apparently can discover the
1755 span of the last line some other way. How? (FIXME)
1759 decode_line_numbers (linetable
)
1764 unsigned long length
;
1769 if (linetable
!= NULL
)
1771 tblscan
= tblend
= linetable
;
1772 length
= target_to_host (tblscan
, SIZEOF_LINETBL_LENGTH
, GET_UNSIGNED
,
1774 tblscan
+= SIZEOF_LINETBL_LENGTH
;
1776 base
= target_to_host (tblscan
, TARGET_FT_POINTER_SIZE (objfile
),
1777 GET_UNSIGNED
, current_objfile
);
1778 tblscan
+= TARGET_FT_POINTER_SIZE (objfile
);
1780 while (tblscan
< tblend
)
1782 line
= target_to_host (tblscan
, SIZEOF_LINETBL_LINENO
, GET_UNSIGNED
,
1784 tblscan
+= SIZEOF_LINETBL_LINENO
+ SIZEOF_LINETBL_STMT
;
1785 pc
= target_to_host (tblscan
, SIZEOF_LINETBL_DELTA
, GET_UNSIGNED
,
1787 tblscan
+= SIZEOF_LINETBL_DELTA
;
1791 record_line (current_subfile
, line
, pc
);
1801 locval -- compute the value of a location attribute
1805 static int locval (char *loc)
1809 Given pointer to a string of bytes that define a location, compute
1810 the location and return the value.
1812 When computing values involving the current value of the frame pointer,
1813 the value zero is used, which results in a value relative to the frame
1814 pointer, rather than the absolute value. This is what GDB wants
1817 When the result is a register number, the global isreg flag is set,
1818 otherwise it is cleared. This is a kludge until we figure out a better
1819 way to handle the problem. Gdb's design does not mesh well with the
1820 DWARF notion of a location computing interpreter, which is a shame
1821 because the flexibility goes unused.
1825 Note that stack[0] is unused except as a default error return.
1826 Note that stack overflow is not yet handled.
1833 unsigned short nbytes
;
1834 unsigned short locsize
;
1835 auto long stack
[64];
1842 nbytes
= attribute_size (AT_location
);
1843 locsize
= target_to_host (loc
, nbytes
, GET_UNSIGNED
, current_objfile
);
1845 end
= loc
+ locsize
;
1850 loc_value_size
= TARGET_FT_LONG_SIZE (current_objfile
);
1853 loc_atom_code
= target_to_host (loc
, SIZEOF_LOC_ATOM_CODE
, GET_UNSIGNED
,
1855 loc
+= SIZEOF_LOC_ATOM_CODE
;
1856 switch (loc_atom_code
)
1863 /* push register (number) */
1864 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
1865 GET_UNSIGNED
, current_objfile
);
1866 loc
+= loc_value_size
;
1870 /* push value of register (number) */
1871 /* Actually, we compute the value as if register has 0 */
1873 regno
= target_to_host (loc
, loc_value_size
, GET_UNSIGNED
,
1875 loc
+= loc_value_size
;
1878 stack
[++stacki
] = 0;
1882 stack
[++stacki
] = 0;
1883 SQUAWK (("BASEREG %d not handled!", regno
));
1887 /* push address (relocated address) */
1888 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
1889 GET_UNSIGNED
, current_objfile
);
1890 loc
+= loc_value_size
;
1893 /* push constant (number) FIXME: signed or unsigned! */
1894 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
1895 GET_SIGNED
, current_objfile
);
1896 loc
+= loc_value_size
;
1899 /* pop, deref and push 2 bytes (as a long) */
1900 SQUAWK (("OP_DEREF2 address 0x%x not handled", stack
[stacki
]));
1902 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1903 SQUAWK (("OP_DEREF4 address 0x%x not handled", stack
[stacki
]));
1905 case OP_ADD
: /* pop top 2 items, add, push result */
1906 stack
[stacki
- 1] += stack
[stacki
];
1911 return (stack
[stacki
]);
1918 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1922 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1926 When expanding a partial symbol table entry to a full symbol table
1927 entry, this is the function that gets called to read in the symbols
1928 for the compilation unit.
1930 Returns a pointer to the newly constructed symtab (which is now
1931 the new first one on the objfile's symtab list).
1934 static struct symtab
*
1935 read_ofile_symtab (pst
)
1936 struct partial_symtab
*pst
;
1938 struct cleanup
*back_to
;
1939 unsigned long lnsize
;
1942 char lnsizedata
[SIZEOF_LINETBL_LENGTH
];
1944 abfd
= pst
-> objfile
-> obfd
;
1945 current_objfile
= pst
-> objfile
;
1947 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1948 unit, seek to the location in the file, and read in all the DIE's. */
1951 dbbase
= xmalloc (DBLENGTH(pst
));
1952 dbroff
= DBROFF(pst
);
1953 foffset
= DBFOFF(pst
) + dbroff
;
1954 base_section_offsets
= pst
->section_offsets
;
1955 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1956 if (bfd_seek (abfd
, foffset
, 0) ||
1957 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1960 error ("can't read DWARF data");
1962 back_to
= make_cleanup (free
, dbbase
);
1964 /* If there is a line number table associated with this compilation unit
1965 then read the size of this fragment in bytes, from the fragment itself.
1966 Allocate a buffer for the fragment and read it in for future
1972 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1973 (bfd_read ((PTR
) lnsizedata
, sizeof (lnsizedata
), 1, abfd
) !=
1974 sizeof (lnsizedata
)))
1976 error ("can't read DWARF line number table size");
1978 lnsize
= target_to_host (lnsizedata
, SIZEOF_LINETBL_LENGTH
,
1979 GET_UNSIGNED
, pst
-> objfile
);
1980 lnbase
= xmalloc (lnsize
);
1981 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1982 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1985 error ("can't read DWARF line numbers");
1987 make_cleanup (free
, lnbase
);
1990 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1991 do_cleanups (back_to
);
1992 current_objfile
= NULL
;
1993 return (pst
-> objfile
-> symtabs
);
2000 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
2004 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
2008 Called once for each partial symbol table entry that needs to be
2009 expanded into a full symbol table entry.
2014 psymtab_to_symtab_1 (pst
)
2015 struct partial_symtab
*pst
;
2023 warning ("psymtab for %s already read in. Shouldn't happen.",
2028 /* Read in all partial symtabs on which this one is dependent */
2029 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
2031 if (!pst
-> dependencies
[i
] -> readin
)
2033 /* Inform about additional files that need to be read in. */
2036 fputs_filtered (" ", stdout
);
2038 fputs_filtered ("and ", stdout
);
2040 printf_filtered ("%s...",
2041 pst
-> dependencies
[i
] -> filename
);
2043 fflush (stdout
); /* Flush output */
2045 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
2048 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
2050 pst
-> symtab
= read_ofile_symtab (pst
);
2053 printf_filtered ("%d DIE's, sorting...", diecount
);
2057 sort_symtab_syms (pst
-> symtab
);
2068 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2072 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2076 This is the DWARF support entry point for building a full symbol
2077 table entry from a partial symbol table entry. We are passed a
2078 pointer to the partial symbol table entry that needs to be expanded.
2083 dwarf_psymtab_to_symtab (pst
)
2084 struct partial_symtab
*pst
;
2091 warning ("psymtab for %s already read in. Shouldn't happen.",
2096 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
2098 /* Print the message now, before starting serious work, to avoid
2099 disconcerting pauses. */
2102 printf_filtered ("Reading in symbols for %s...",
2107 psymtab_to_symtab_1 (pst
);
2109 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2110 we need to do an equivalent or is this something peculiar to
2112 Match with global symbols. This only needs to be done once,
2113 after all of the symtabs and dependencies have been read in.
2115 scan_file_globals (pst
-> objfile
);
2118 /* Finish up the verbose info message. */
2121 printf_filtered ("done.\n");
2133 init_psymbol_list -- initialize storage for partial symbols
2137 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2141 Initializes storage for all of the partial symbols that will be
2142 created by dwarf_build_psymtabs and subsidiaries.
2146 init_psymbol_list (objfile
, total_symbols
)
2147 struct objfile
*objfile
;
2150 /* Free any previously allocated psymbol lists. */
2152 if (objfile
-> global_psymbols
.list
)
2154 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
2156 if (objfile
-> static_psymbols
.list
)
2158 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
2161 /* Current best guess is that there are approximately a twentieth
2162 of the total symbols (in a debugging file) are global or static
2165 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2166 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2167 objfile
-> global_psymbols
.next
=
2168 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2169 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
2170 * sizeof (struct partial_symbol
));
2171 objfile
-> static_psymbols
.next
=
2172 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2173 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
2174 * sizeof (struct partial_symbol
));
2181 add_enum_psymbol -- add enumeration members to partial symbol table
2185 Given pointer to a DIE that is known to be for an enumeration,
2186 extract the symbolic names of the enumeration members and add
2187 partial symbols for them.
2191 add_enum_psymbol (dip
, objfile
)
2192 struct dieinfo
*dip
;
2193 struct objfile
*objfile
;
2197 unsigned short blocksz
;
2200 if ((scan
= dip
-> at_element_list
) != NULL
)
2202 if (dip
-> short_element_list
)
2204 nbytes
= attribute_size (AT_short_element_list
);
2208 nbytes
= attribute_size (AT_element_list
);
2210 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
2212 listend
= scan
+ blocksz
;
2213 while (scan
< listend
)
2215 scan
+= TARGET_FT_LONG_SIZE (objfile
);
2216 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2217 objfile
-> static_psymbols
, 0);
2218 scan
+= strlen (scan
) + 1;
2227 add_partial_symbol -- add symbol to partial symbol table
2231 Given a DIE, if it is one of the types that we want to
2232 add to a partial symbol table, finish filling in the die info
2233 and then add a partial symbol table entry for it.
2238 add_partial_symbol (dip
, objfile
)
2239 struct dieinfo
*dip
;
2240 struct objfile
*objfile
;
2242 switch (dip
-> die_tag
)
2244 case TAG_global_subroutine
:
2245 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2247 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2248 VAR_NAMESPACE
, LOC_BLOCK
,
2249 objfile
-> global_psymbols
,
2252 case TAG_global_variable
:
2253 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2255 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2256 VAR_NAMESPACE
, LOC_STATIC
,
2257 objfile
-> global_psymbols
,
2260 case TAG_subroutine
:
2261 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2262 VAR_NAMESPACE
, LOC_BLOCK
,
2263 objfile
-> static_psymbols
,
2266 case TAG_local_variable
:
2267 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2268 VAR_NAMESPACE
, LOC_STATIC
,
2269 objfile
-> static_psymbols
,
2273 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2274 VAR_NAMESPACE
, LOC_TYPEDEF
,
2275 objfile
-> static_psymbols
,
2278 case TAG_structure_type
:
2279 case TAG_union_type
:
2280 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2281 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2282 objfile
-> static_psymbols
,
2285 case TAG_enumeration_type
:
2288 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2289 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2290 objfile
-> static_psymbols
,
2293 add_enum_psymbol (dip
, objfile
);
2302 scan_partial_symbols -- scan DIE's within a single compilation unit
2306 Process the DIE's within a single compilation unit, looking for
2307 interesting DIE's that contribute to the partial symbol table entry
2308 for this compilation unit. Since we cannot follow any sibling
2309 chains without reading the complete DIE info for every DIE,
2310 it is probably faster to just sequentially check each one to
2311 see if it is one of the types we are interested in, and if so,
2312 then extract all the attributes info and generate a partial
2317 Don't attempt to add anonymous structures or unions since they have
2318 no name. Anonymous enumerations however are processed, because we
2319 want to extract their member names (the check for a tag name is
2322 Also, for variables and subroutines, check that this is the place
2323 where the actual definition occurs, rather than just a reference
2328 scan_partial_symbols (thisdie
, enddie
, objfile
)
2331 struct objfile
*objfile
;
2336 while (thisdie
< enddie
)
2338 basicdieinfo (&di
, thisdie
, objfile
);
2339 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2345 nextdie
= thisdie
+ di
.die_length
;
2346 /* To avoid getting complete die information for every die, we
2347 only do it (below) for the cases we are interested in. */
2350 case TAG_global_subroutine
:
2351 case TAG_subroutine
:
2352 case TAG_global_variable
:
2353 case TAG_local_variable
:
2354 completedieinfo (&di
, objfile
);
2355 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2357 add_partial_symbol (&di
, objfile
);
2361 case TAG_structure_type
:
2362 case TAG_union_type
:
2363 completedieinfo (&di
, objfile
);
2366 add_partial_symbol (&di
, objfile
);
2369 case TAG_enumeration_type
:
2370 completedieinfo (&di
, objfile
);
2371 add_partial_symbol (&di
, objfile
);
2383 scan_compilation_units -- build a psymtab entry for each compilation
2387 This is the top level dwarf parsing routine for building partial
2390 It scans from the beginning of the DWARF table looking for the first
2391 TAG_compile_unit DIE, and then follows the sibling chain to locate
2392 each additional TAG_compile_unit DIE.
2394 For each TAG_compile_unit DIE it creates a partial symtab structure,
2395 calls a subordinate routine to collect all the compilation unit's
2396 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2397 new partial symtab structure into the partial symbol table. It also
2398 records the appropriate information in the partial symbol table entry
2399 to allow the chunk of DIE's and line number table for this compilation
2400 unit to be located and re-read later, to generate a complete symbol
2401 table entry for the compilation unit.
2403 Thus it effectively partitions up a chunk of DIE's for multiple
2404 compilation units into smaller DIE chunks and line number tables,
2405 and associates them with a partial symbol table entry.
2409 If any compilation unit has no line number table associated with
2410 it for some reason (a missing at_stmt_list attribute, rather than
2411 just one with a value of zero, which is valid) then we ensure that
2412 the recorded file offset is zero so that the routine which later
2413 reads line number table fragments knows that there is no fragment
2423 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2427 unsigned int dbfoff
;
2428 unsigned int lnoffset
;
2429 struct objfile
*objfile
;
2433 struct partial_symtab
*pst
;
2438 while (thisdie
< enddie
)
2440 basicdieinfo (&di
, thisdie
, objfile
);
2441 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2445 else if (di
.die_tag
!= TAG_compile_unit
)
2447 nextdie
= thisdie
+ di
.die_length
;
2451 completedieinfo (&di
, objfile
);
2452 if (di
.at_sibling
!= 0)
2454 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2458 nextdie
= thisdie
+ di
.die_length
;
2460 curoff
= thisdie
- dbbase
;
2461 culength
= nextdie
- thisdie
;
2462 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2464 /* First allocate a new partial symbol table structure */
2466 pst
= start_psymtab_common (objfile
, base_section_offsets
, di
.at_name
,
2468 objfile
-> global_psymbols
.next
,
2469 objfile
-> static_psymbols
.next
);
2471 pst
-> texthigh
= di
.at_high_pc
;
2472 pst
-> read_symtab_private
= (char *)
2473 obstack_alloc (&objfile
-> psymbol_obstack
,
2474 sizeof (struct dwfinfo
));
2475 DBFOFF (pst
) = dbfoff
;
2476 DBROFF (pst
) = curoff
;
2477 DBLENGTH (pst
) = culength
;
2478 LNFOFF (pst
) = curlnoffset
;
2479 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2481 /* Now look for partial symbols */
2483 scan_partial_symbols (thisdie
+ di
.die_length
, nextdie
, objfile
);
2485 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2486 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2487 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2488 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2489 sort_pst_symbols (pst
);
2490 /* If there is already a psymtab or symtab for a file of this name,
2491 remove it. (If there is a symtab, more drastic things also
2492 happen.) This happens in VxWorks. */
2493 free_named_symtabs (pst
-> filename
);
2503 new_symbol -- make a symbol table entry for a new symbol
2507 static struct symbol *new_symbol (struct dieinfo *dip,
2508 struct objfile *objfile)
2512 Given a pointer to a DWARF information entry, figure out if we need
2513 to make a symbol table entry for it, and if so, create a new entry
2514 and return a pointer to it.
2517 static struct symbol
*
2518 new_symbol (dip
, objfile
)
2519 struct dieinfo
*dip
;
2520 struct objfile
*objfile
;
2522 struct symbol
*sym
= NULL
;
2524 if (dip
-> at_name
!= NULL
)
2526 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2527 sizeof (struct symbol
));
2528 memset (sym
, 0, sizeof (struct symbol
));
2529 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2530 /* default assumptions */
2531 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2532 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2533 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2534 switch (dip
-> die_tag
)
2537 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2538 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2540 case TAG_global_subroutine
:
2541 case TAG_subroutine
:
2542 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2543 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2544 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2545 if (dip
-> die_tag
== TAG_global_subroutine
)
2547 add_symbol_to_list (sym
, &global_symbols
);
2551 add_symbol_to_list (sym
, list_in_scope
);
2554 case TAG_global_variable
:
2555 if (dip
-> at_location
!= NULL
)
2557 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2558 add_symbol_to_list (sym
, &global_symbols
);
2559 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2560 SYMBOL_VALUE (sym
) += baseaddr
;
2563 case TAG_local_variable
:
2564 if (dip
-> at_location
!= NULL
)
2566 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2567 add_symbol_to_list (sym
, list_in_scope
);
2570 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2574 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2578 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2579 SYMBOL_VALUE (sym
) += baseaddr
;
2583 case TAG_formal_parameter
:
2584 if (dip
-> at_location
!= NULL
)
2586 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2588 add_symbol_to_list (sym
, list_in_scope
);
2591 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2595 SYMBOL_CLASS (sym
) = LOC_ARG
;
2598 case TAG_unspecified_parameters
:
2599 /* From varargs functions; gdb doesn't seem to have any interest in
2600 this information, so just ignore it for now. (FIXME?) */
2602 case TAG_structure_type
:
2603 case TAG_union_type
:
2604 case TAG_enumeration_type
:
2605 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2606 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2607 add_symbol_to_list (sym
, list_in_scope
);
2610 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2611 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2612 add_symbol_to_list (sym
, list_in_scope
);
2615 /* Not a tag we recognize. Hopefully we aren't processing trash
2616 data, but since we must specifically ignore things we don't
2617 recognize, there is nothing else we should do at this point. */
2628 decode_mod_fund_type -- decode a modified fundamental type
2632 static struct type *decode_mod_fund_type (char *typedata)
2636 Decode a block of data containing a modified fundamental
2637 type specification. TYPEDATA is a pointer to the block,
2638 which starts with a length containing the size of the rest
2639 of the block. At the end of the block is a fundmental type
2640 code value that gives the fundamental type. Everything
2641 in between are type modifiers.
2643 We simply compute the number of modifiers and call the general
2644 function decode_modified_type to do the actual work.
2647 static struct type
*
2648 decode_mod_fund_type (typedata
)
2651 struct type
*typep
= NULL
;
2652 unsigned short modcount
;
2655 /* Get the total size of the block, exclusive of the size itself */
2657 nbytes
= attribute_size (AT_mod_fund_type
);
2658 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
2661 /* Deduct the size of the fundamental type bytes at the end of the block. */
2663 modcount
-= attribute_size (AT_fund_type
);
2665 /* Now do the actual decoding */
2667 typep
= decode_modified_type (typedata
, modcount
, AT_mod_fund_type
);
2675 decode_mod_u_d_type -- decode a modified user defined type
2679 static struct type *decode_mod_u_d_type (char *typedata)
2683 Decode a block of data containing a modified user defined
2684 type specification. TYPEDATA is a pointer to the block,
2685 which consists of a two byte length, containing the size
2686 of the rest of the block. At the end of the block is a
2687 four byte value that gives a reference to a user defined type.
2688 Everything in between are type modifiers.
2690 We simply compute the number of modifiers and call the general
2691 function decode_modified_type to do the actual work.
2694 static struct type
*
2695 decode_mod_u_d_type (typedata
)
2698 struct type
*typep
= NULL
;
2699 unsigned short modcount
;
2702 /* Get the total size of the block, exclusive of the size itself */
2704 nbytes
= attribute_size (AT_mod_u_d_type
);
2705 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
2708 /* Deduct the size of the reference type bytes at the end of the block. */
2710 modcount
-= attribute_size (AT_user_def_type
);
2712 /* Now do the actual decoding */
2714 typep
= decode_modified_type (typedata
, modcount
, AT_mod_u_d_type
);
2722 decode_modified_type -- decode modified user or fundamental type
2726 static struct type *decode_modified_type (char *modifiers,
2727 unsigned short modcount, int mtype)
2731 Decode a modified type, either a modified fundamental type or
2732 a modified user defined type. MODIFIERS is a pointer to the
2733 block of bytes that define MODCOUNT modifiers. Immediately
2734 following the last modifier is a short containing the fundamental
2735 type or a long containing the reference to the user defined
2736 type. Which one is determined by MTYPE, which is either
2737 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2738 type we are generating.
2740 We call ourself recursively to generate each modified type,`
2741 until MODCOUNT reaches zero, at which point we have consumed
2742 all the modifiers and generate either the fundamental type or
2743 user defined type. When the recursion unwinds, each modifier
2744 is applied in turn to generate the full modified type.
2748 If we find a modifier that we don't recognize, and it is not one
2749 of those reserved for application specific use, then we issue a
2750 warning and simply ignore the modifier.
2754 We currently ignore MOD_const and MOD_volatile. (FIXME)
2758 static struct type
*
2759 decode_modified_type (modifiers
, modcount
, mtype
)
2761 unsigned int modcount
;
2764 struct type
*typep
= NULL
;
2765 unsigned short fundtype
;
2774 case AT_mod_fund_type
:
2775 nbytes
= attribute_size (AT_fund_type
);
2776 fundtype
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
2778 typep
= decode_fund_type (fundtype
);
2780 case AT_mod_u_d_type
:
2781 nbytes
= attribute_size (AT_user_def_type
);
2782 die_ref
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
2784 if ((typep
= lookup_utype (die_ref
)) == NULL
)
2786 typep
= alloc_utype (die_ref
, NULL
);
2790 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2791 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2797 modifier
= *modifiers
++;
2798 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2801 case MOD_pointer_to
:
2802 typep
= lookup_pointer_type (typep
);
2804 case MOD_reference_to
:
2805 typep
= lookup_reference_type (typep
);
2808 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2811 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2814 if (!(MOD_lo_user
<= (unsigned char) modifier
2815 && (unsigned char) modifier
<= MOD_hi_user
))
2817 SQUAWK (("unknown type modifier %u",
2818 (unsigned char) modifier
));
2830 decode_fund_type -- translate basic DWARF type to gdb base type
2834 Given an integer that is one of the fundamental DWARF types,
2835 translate it to one of the basic internal gdb types and return
2836 a pointer to the appropriate gdb type (a "struct type *").
2840 If we encounter a fundamental type that we are unprepared to
2841 deal with, and it is not in the range of those types defined
2842 as application specific types, then we issue a warning and
2843 treat the type as an "int".
2846 static struct type
*
2847 decode_fund_type (fundtype
)
2848 unsigned int fundtype
;
2850 struct type
*typep
= NULL
;
2856 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2859 case FT_boolean
: /* Was FT_set in AT&T version */
2860 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2863 case FT_pointer
: /* (void *) */
2864 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2865 typep
= lookup_pointer_type (typep
);
2869 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2872 case FT_signed_char
:
2873 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2876 case FT_unsigned_char
:
2877 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2881 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2884 case FT_signed_short
:
2885 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2888 case FT_unsigned_short
:
2889 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2893 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2896 case FT_signed_integer
:
2897 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2900 case FT_unsigned_integer
:
2901 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2905 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2908 case FT_signed_long
:
2909 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2912 case FT_unsigned_long
:
2913 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2917 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2920 case FT_signed_long_long
:
2921 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2924 case FT_unsigned_long_long
:
2925 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2929 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2932 case FT_dbl_prec_float
:
2933 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2936 case FT_ext_prec_float
:
2937 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2941 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2944 case FT_dbl_prec_complex
:
2945 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2948 case FT_ext_prec_complex
:
2949 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2954 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2956 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2957 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2967 create_name -- allocate a fresh copy of a string on an obstack
2971 Given a pointer to a string and a pointer to an obstack, allocates
2972 a fresh copy of the string on the specified obstack.
2977 create_name (name
, obstackp
)
2979 struct obstack
*obstackp
;
2984 length
= strlen (name
) + 1;
2985 newname
= (char *) obstack_alloc (obstackp
, length
);
2986 strcpy (newname
, name
);
2994 basicdieinfo -- extract the minimal die info from raw die data
2998 void basicdieinfo (char *diep, struct dieinfo *dip,
2999 struct objfile *objfile)
3003 Given a pointer to raw DIE data, and a pointer to an instance of a
3004 die info structure, this function extracts the basic information
3005 from the DIE data required to continue processing this DIE, along
3006 with some bookkeeping information about the DIE.
3008 The information we absolutely must have includes the DIE tag,
3009 and the DIE length. If we need the sibling reference, then we
3010 will have to call completedieinfo() to process all the remaining
3013 Note that since there is no guarantee that the data is properly
3014 aligned in memory for the type of access required (indirection
3015 through anything other than a char pointer), and there is no
3016 guarantee that it is in the same byte order as the gdb host,
3017 we call a function which deals with both alignment and byte
3018 swapping issues. Possibly inefficient, but quite portable.
3020 We also take care of some other basic things at this point, such
3021 as ensuring that the instance of the die info structure starts
3022 out completely zero'd and that curdie is initialized for use
3023 in error reporting if we have a problem with the current die.
3027 All DIE's must have at least a valid length, thus the minimum
3028 DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the
3029 DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
3030 are forced to be TAG_padding DIES.
3032 Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
3033 that if a padding DIE is used for alignment and the amount needed is
3034 less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
3035 enough to align to the next alignment boundry.
3039 basicdieinfo (dip
, diep
, objfile
)
3040 struct dieinfo
*dip
;
3042 struct objfile
*objfile
;
3045 memset (dip
, 0, sizeof (struct dieinfo
));
3047 dip
-> die_ref
= dbroff
+ (diep
- dbbase
);
3048 dip
-> die_length
= target_to_host (diep
, SIZEOF_DIE_LENGTH
, GET_UNSIGNED
,
3050 if (dip
-> die_length
< SIZEOF_DIE_LENGTH
)
3052 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> die_length
);
3054 else if (dip
-> die_length
< (SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
))
3056 dip
-> die_tag
= TAG_padding
;
3060 diep
+= SIZEOF_DIE_LENGTH
;
3061 dip
-> die_tag
= target_to_host (diep
, SIZEOF_DIE_TAG
, GET_UNSIGNED
,
3070 completedieinfo -- finish reading the information for a given DIE
3074 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3078 Given a pointer to an already partially initialized die info structure,
3079 scan the raw DIE data and finish filling in the die info structure
3080 from the various attributes found.
3082 Note that since there is no guarantee that the data is properly
3083 aligned in memory for the type of access required (indirection
3084 through anything other than a char pointer), and there is no
3085 guarantee that it is in the same byte order as the gdb host,
3086 we call a function which deals with both alignment and byte
3087 swapping issues. Possibly inefficient, but quite portable.
3091 Each time we are called, we increment the diecount variable, which
3092 keeps an approximate count of the number of dies processed for
3093 each compilation unit. This information is presented to the user
3094 if the info_verbose flag is set.
3099 completedieinfo (dip
, objfile
)
3100 struct dieinfo
*dip
;
3101 struct objfile
*objfile
;
3103 char *diep
; /* Current pointer into raw DIE data */
3104 char *end
; /* Terminate DIE scan here */
3105 unsigned short attr
; /* Current attribute being scanned */
3106 unsigned short form
; /* Form of the attribute */
3107 int nbytes
; /* Size of next field to read */
3111 end
= diep
+ dip
-> die_length
;
3112 diep
+= SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
;
3115 attr
= target_to_host (diep
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
, objfile
);
3116 diep
+= SIZEOF_ATTRIBUTE
;
3117 if ((nbytes
= attribute_size (attr
)) == -1)
3119 SQUAWK (("unknown attribute length, skipped remaining attributes"));;
3126 dip
-> at_fund_type
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3130 dip
-> at_ordering
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3134 dip
-> at_bit_offset
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3138 dip
-> at_visibility
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3142 dip
-> at_sibling
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3146 dip
-> at_stmt_list
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3148 dip
-> has_at_stmt_list
= 1;
3151 dip
-> at_low_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3153 dip
-> at_low_pc
+= baseaddr
;
3154 dip
-> has_at_low_pc
= 1;
3157 dip
-> at_high_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3159 dip
-> at_high_pc
+= baseaddr
;
3162 dip
-> at_language
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3165 case AT_user_def_type
:
3166 dip
-> at_user_def_type
= target_to_host (diep
, nbytes
,
3167 GET_UNSIGNED
, objfile
);
3170 dip
-> at_byte_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3174 dip
-> at_bit_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3178 dip
-> at_member
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3182 dip
-> at_discr
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3186 dip
-> at_import
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3190 dip
-> at_location
= diep
;
3192 case AT_mod_fund_type
:
3193 dip
-> at_mod_fund_type
= diep
;
3195 case AT_subscr_data
:
3196 dip
-> at_subscr_data
= diep
;
3198 case AT_mod_u_d_type
:
3199 dip
-> at_mod_u_d_type
= diep
;
3201 case AT_element_list
:
3202 dip
-> at_element_list
= diep
;
3203 dip
-> short_element_list
= 0;
3205 case AT_short_element_list
:
3206 dip
-> at_element_list
= diep
;
3207 dip
-> short_element_list
= 1;
3209 case AT_discr_value
:
3210 dip
-> at_discr_value
= diep
;
3212 case AT_string_length
:
3213 dip
-> at_string_length
= diep
;
3216 dip
-> at_name
= diep
;
3219 dip
-> at_comp_dir
= diep
;
3222 dip
-> at_producer
= diep
;
3225 dip
-> at_frame_base
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3228 case AT_start_scope
:
3229 dip
-> at_start_scope
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3232 case AT_stride_size
:
3233 dip
-> at_stride_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3237 dip
-> at_src_info
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3241 dip
-> at_prototyped
= diep
;
3244 /* Found an attribute that we are unprepared to handle. However
3245 it is specifically one of the design goals of DWARF that
3246 consumers should ignore unknown attributes. As long as the
3247 form is one that we recognize (so we know how to skip it),
3248 we can just ignore the unknown attribute. */
3251 form
= FORM_FROM_ATTR (attr
);
3265 diep
+= TARGET_FT_POINTER_SIZE (objfile
);
3268 diep
+= 2 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3271 diep
+= 4 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3274 diep
+= strlen (diep
) + 1;
3277 SQUAWK (("unknown attribute form (0x%x)", form
));
3278 SQUAWK (("unknown attribute length, skipped remaining attributes"));;
3289 target_to_host -- swap in target data to host
3293 target_to_host (char *from, int nbytes, int signextend,
3294 struct objfile *objfile)
3298 Given pointer to data in target format in FROM, a byte count for
3299 the size of the data in NBYTES, a flag indicating whether or not
3300 the data is signed in SIGNEXTEND, and a pointer to the current
3301 objfile in OBJFILE, convert the data to host format and return
3302 the converted value.
3306 FIXME: If we read data that is known to be signed, and expect to
3307 use it as signed data, then we need to explicitly sign extend the
3308 result until the bfd library is able to do this for us.
3312 static unsigned long
3313 target_to_host (from
, nbytes
, signextend
, objfile
)
3316 int signextend
; /* FIXME: Unused */
3317 struct objfile
*objfile
;
3319 unsigned long rtnval
;
3324 rtnval
= bfd_get_64 (objfile
-> obfd
, (bfd_byte
*) from
);
3327 rtnval
= bfd_get_32 (objfile
-> obfd
, (bfd_byte
*) from
);
3330 rtnval
= bfd_get_16 (objfile
-> obfd
, (bfd_byte
*) from
);
3333 rtnval
= bfd_get_8 (objfile
-> obfd
, (bfd_byte
*) from
);
3336 dwarfwarn ("no bfd support for %d byte data object", nbytes
);
3347 attribute_size -- compute size of data for a DWARF attribute
3351 static int attribute_size (unsigned int attr)
3355 Given a DWARF attribute in ATTR, compute the size of the first
3356 piece of data associated with this attribute and return that
3359 Returns -1 for unrecognized attributes.
3364 attribute_size (attr
)
3367 int nbytes
; /* Size of next data for this attribute */
3368 unsigned short form
; /* Form of the attribute */
3370 form
= FORM_FROM_ATTR (attr
);
3373 case FORM_STRING
: /* A variable length field is next */
3376 case FORM_DATA2
: /* Next 2 byte field is the data itself */
3377 case FORM_BLOCK2
: /* Next 2 byte field is a block length */
3380 case FORM_DATA4
: /* Next 4 byte field is the data itself */
3381 case FORM_BLOCK4
: /* Next 4 byte field is a block length */
3382 case FORM_REF
: /* Next 4 byte field is a DIE offset */
3385 case FORM_DATA8
: /* Next 8 byte field is the data itself */
3388 case FORM_ADDR
: /* Next field size is target sizeof(void *) */
3389 nbytes
= TARGET_FT_POINTER_SIZE (objfile
);
3392 SQUAWK (("unknown attribute form (0x%x)", form
));