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 static CORE_ADDR baseaddr
; /* Add to each symbol value */
211 /* Each partial symbol table entry contains a pointer to private data for the
212 read_symtab() function to use when expanding a partial symbol table entry
213 to a full symbol table entry. For DWARF debugging info, this data is
214 contained in the following structure and macros are provided for easy
215 access to the members given a pointer to a partial symbol table entry.
217 dbfoff Always the absolute file offset to the start of the ".debug"
218 section for the file containing the DIE's being accessed.
220 dbroff Relative offset from the start of the ".debug" access to the
221 first DIE to be accessed. When building the partial symbol
222 table, this value will be zero since we are accessing the
223 entire ".debug" section. When expanding a partial symbol
224 table entry, this value will be the offset to the first
225 DIE for the compilation unit containing the symbol that
226 triggers the expansion.
228 dblength The size of the chunk of DIE's being examined, in bytes.
230 lnfoff The absolute file offset to the line table fragment. Ignored
231 when building partial symbol tables, but used when expanding
232 them, and contains the absolute file offset to the fragment
233 of the ".line" section containing the line numbers for the
234 current compilation unit.
238 int dbfoff
; /* Absolute file offset to start of .debug section */
239 int dbroff
; /* Relative offset from start of .debug section */
240 int dblength
; /* Size of the chunk of DIE's being examined */
241 int lnfoff
; /* Absolute file offset to line table fragment */
244 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
245 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
246 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
247 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
249 /* The generic symbol table building routines have separate lists for
250 file scope symbols and all all other scopes (local scopes). So
251 we need to select the right one to pass to add_symbol_to_list().
252 We do it by keeping a pointer to the correct list in list_in_scope.
254 FIXME: The original dwarf code just treated the file scope as the first
255 local scope, and all other local scopes as nested local scopes, and worked
256 fine. Check to see if we really need to distinguish these in buildsym.c */
258 struct pending
**list_in_scope
= &file_symbols
;
260 /* DIES which have user defined types or modified user defined types refer to
261 other DIES for the type information. Thus we need to associate the offset
262 of a DIE for a user defined type with a pointer to the type information.
264 Originally this was done using a simple but expensive algorithm, with an
265 array of unsorted structures, each containing an offset/type-pointer pair.
266 This array was scanned linearly each time a lookup was done. The result
267 was that gdb was spending over half it's startup time munging through this
268 array of pointers looking for a structure that had the right offset member.
270 The second attempt used the same array of structures, but the array was
271 sorted using qsort each time a new offset/type was recorded, and a binary
272 search was used to find the type pointer for a given DIE offset. This was
273 even slower, due to the overhead of sorting the array each time a new
274 offset/type pair was entered.
276 The third attempt uses a fixed size array of type pointers, indexed by a
277 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
278 we can divide any DIE offset by 4 to obtain a unique index into this fixed
279 size array. Since each element is a 4 byte pointer, it takes exactly as
280 much memory to hold this array as to hold the DWARF info for a given
281 compilation unit. But it gets freed as soon as we are done with it. */
283 static struct type
**utypes
; /* Pointer to array of user type pointers */
284 static int numutypes
; /* Max number of user type pointers */
286 /* Forward declarations of static functions so we don't have to worry
287 about ordering within this file. */
290 attribute_size
PARAMS ((unsigned int));
293 target_to_host
PARAMS ((char *, int, int, struct objfile
*));
296 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
299 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
302 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
305 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
312 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
315 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
316 unsigned int, struct objfile
*));
319 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
322 init_psymbol_list
PARAMS ((struct objfile
*, int));
325 basicdieinfo
PARAMS ((struct dieinfo
*, char *, struct objfile
*));
328 completedieinfo
PARAMS ((struct dieinfo
*, struct objfile
*));
331 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
334 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
336 static struct symtab
*
337 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
340 process_dies
PARAMS ((char *, char *, struct objfile
*));
343 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
347 decode_array_element_type
PARAMS ((char *));
350 decode_subscr_data
PARAMS ((char *, char *));
353 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
356 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
359 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
362 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
365 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
368 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
371 decode_line_numbers
PARAMS ((char *));
374 decode_die_type
PARAMS ((struct dieinfo
*));
377 decode_mod_fund_type
PARAMS ((char *));
380 decode_mod_u_d_type
PARAMS ((char *));
383 decode_modified_type
PARAMS ((unsigned char *, unsigned int, int));
386 decode_fund_type
PARAMS ((unsigned int));
389 create_name
PARAMS ((char *, struct obstack
*));
392 lookup_utype
PARAMS ((DIE_REF
));
395 alloc_utype
PARAMS ((DIE_REF
, struct type
*));
397 static struct symbol
*
398 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
401 locval
PARAMS ((char *));
404 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
411 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
415 void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr,
416 int mainline, unsigned int dbfoff, unsigned int dbsize,
417 unsigned int lnoffset, unsigned int lnsize,
418 struct objfile *objfile)
422 This function is called upon to build partial symtabs from files
423 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
425 It is passed a file descriptor for an open file containing the DIES
426 and line number information, the corresponding filename for that
427 file, a base address for relocating the symbols, a flag indicating
428 whether or not this debugging information is from a "main symbol
429 table" rather than a shared library or dynamically linked file,
430 and file offset/size pairs for the DIE information and line number
440 dwarf_build_psymtabs (desc
, filename
, addr
, mainline
, dbfoff
, dbsize
,
441 lnoffset
, lnsize
, objfile
)
448 unsigned int lnoffset
;
450 struct objfile
*objfile
;
452 struct cleanup
*back_to
;
454 current_objfile
= objfile
;
455 dbbase
= xmalloc (dbsize
);
457 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
458 (read (desc
, dbbase
, dbsize
) != dbsize
))
461 error ("can't read DWARF data from '%s'", filename
);
463 back_to
= make_cleanup (free
, dbbase
);
465 /* If we are reinitializing, or if we have never loaded syms yet, init.
466 Since we have no idea how many DIES we are looking at, we just guess
467 some arbitrary value. */
469 if (mainline
|| objfile
-> global_psymbols
.size
== 0 ||
470 objfile
-> static_psymbols
.size
== 0)
472 init_psymbol_list (objfile
, 1024);
475 /* Save the relocation factor where everybody can see it. */
479 /* Follow the compilation unit sibling chain, building a partial symbol
480 table entry for each one. Save enough information about each compilation
481 unit to locate the full DWARF information later. */
483 scan_compilation_units (filename
, dbbase
, dbbase
+ dbsize
,
484 dbfoff
, lnoffset
, objfile
);
486 do_cleanups (back_to
);
487 current_objfile
= NULL
;
495 record_minimal_symbol -- add entry to gdb's minimal symbol table
499 static void record_minimal_symbol (char *name, CORE_ADDR address,
500 enum minimal_symbol_type ms_type,
501 struct objfile *objfile)
505 Given a pointer to the name of a symbol that should be added to the
506 minimal symbol table, and the address associated with that
507 symbol, records this information for later use in building the
508 minimal symbol table.
513 record_minimal_symbol (name
, address
, ms_type
, objfile
)
516 enum minimal_symbol_type ms_type
;
517 struct objfile
*objfile
;
519 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
520 prim_record_minimal_symbol (name
, address
, ms_type
);
527 dwarfwarn -- issue a DWARF related warning
531 Issue warnings about DWARF related things that aren't serious enough
532 to warrant aborting with an error, but should not be ignored either.
533 This includes things like detectable corruption in DIE's, missing
534 DIE's, unimplemented features, etc.
536 In general, running across tags or attributes that we don't recognize
537 is not considered to be a problem and we should not issue warnings
542 We mostly follow the example of the error() routine, but without
543 returning to command level. It is arguable about whether warnings
544 should be issued at all, and if so, where they should go (stdout or
547 We assume that curdie is valid and contains at least the basic
548 information for the DIE where the problem was noticed.
559 fmt
= va_arg (ap
, char *);
561 fprintf (stderr
, "warning: DWARF ref 0x%x: ", curdie
-> die_ref
);
562 if (curdie
-> at_name
)
564 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
566 vfprintf (stderr
, fmt
, ap
);
567 fprintf (stderr
, "\n");
576 read_lexical_block_scope -- process all dies in a lexical block
580 static void read_lexical_block_scope (struct dieinfo *dip,
581 char *thisdie, char *enddie)
585 Process all the DIES contained within a lexical block scope.
586 Start a new scope, process the dies, and then close the scope.
591 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
595 struct objfile
*objfile
;
597 register struct context_stack
*new;
599 (void) push_context (0, dip
-> at_low_pc
);
600 process_dies (thisdie
+ dip
-> die_length
, enddie
, objfile
);
601 new = pop_context ();
602 if (local_symbols
!= NULL
)
604 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
605 dip
-> at_high_pc
, objfile
);
607 local_symbols
= new -> locals
;
614 lookup_utype -- look up a user defined type from die reference
618 static type *lookup_utype (DIE_REF die_ref)
622 Given a DIE reference, lookup the user defined type associated with
623 that DIE, if it has been registered already. If not registered, then
624 return NULL. Alloc_utype() can be called to register an empty
625 type for this reference, which will be filled in later when the
626 actual referenced DIE is processed.
630 lookup_utype (die_ref
)
633 struct type
*type
= NULL
;
636 utypeidx
= (die_ref
- dbroff
) / 4;
637 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
639 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", die_ref
);
643 type
= *(utypes
+ utypeidx
);
653 alloc_utype -- add a user defined type for die reference
657 static type *alloc_utype (DIE_REF die_ref, struct type *utypep)
661 Given a die reference DIE_REF, and a possible pointer to a user
662 defined type UTYPEP, register that this reference has a user
663 defined type and either use the specified type in UTYPEP or
664 make a new empty type that will be filled in later.
666 We should only be called after calling lookup_utype() to verify that
667 there is not currently a type registered for DIE_REF.
671 alloc_utype (die_ref
, utypep
)
678 utypeidx
= (die_ref
- dbroff
) / 4;
679 typep
= utypes
+ utypeidx
;
680 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
682 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
683 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", die_ref
);
685 else if (*typep
!= NULL
)
688 SQUAWK (("internal error: dup user type allocation"));
694 utypep
= (struct type
*)
695 obstack_alloc (¤t_objfile
-> type_obstack
,
696 sizeof (struct type
));
697 (void) memset (utypep
, 0, sizeof (struct type
));
698 TYPE_OBJFILE (utypep
) = current_objfile
;
709 decode_die_type -- return a type for a specified die
713 static struct type *decode_die_type (struct dieinfo *dip)
717 Given a pointer to a die information structure DIP, decode the
718 type of the die and return a pointer to the decoded type. All
719 dies without specific types default to type int.
723 decode_die_type (dip
)
726 struct type
*type
= NULL
;
728 if (dip
-> at_fund_type
!= 0)
730 type
= decode_fund_type (dip
-> at_fund_type
);
732 else if (dip
-> at_mod_fund_type
!= NULL
)
734 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
736 else if (dip
-> at_user_def_type
)
738 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
740 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
743 else if (dip
-> at_mod_u_d_type
)
745 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
749 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
758 struct_type -- compute and return the type for a struct or union
762 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
763 char *enddie, struct objfile *objfile)
767 Given pointer to a die information structure for a die which
768 defines a union or structure (and MUST define one or the other),
769 and pointers to the raw die data that define the range of dies which
770 define the members, compute and return the user defined type for the
775 struct_type (dip
, thisdie
, enddie
, objfile
)
779 struct objfile
*objfile
;
783 struct nextfield
*next
;
786 struct nextfield
*list
= NULL
;
787 struct nextfield
*new;
794 if ((type
= lookup_utype (dip
-> die_ref
)) == NULL
)
796 /* No forward references created an empty type, so install one now */
797 type
= alloc_utype (dip
-> die_ref
, NULL
);
799 INIT_CPLUS_SPECIFIC(type
);
800 switch (dip
-> die_tag
)
802 case TAG_structure_type
:
803 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
807 TYPE_CODE (type
) = TYPE_CODE_UNION
;
811 /* Should never happen */
812 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
814 SQUAWK (("missing structure or union tag"));
817 /* Some compilers try to be helpful by inventing "fake" names for
818 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
819 Thanks, but no thanks... */
820 if (dip
-> at_name
!= NULL
821 && *dip
-> at_name
!= '~'
822 && *dip
-> at_name
!= '.')
824 TYPE_NAME (type
) = obconcat (&objfile
-> type_obstack
,
825 tpart1
, " ", dip
-> at_name
);
827 if (dip
-> at_byte_size
!= 0)
829 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
831 thisdie
+= dip
-> die_length
;
832 while (thisdie
< enddie
)
834 basicdieinfo (&mbr
, thisdie
, objfile
);
835 completedieinfo (&mbr
, objfile
);
836 if (mbr
.die_length
<= SIZEOF_DIE_LENGTH
)
840 else if (mbr
.at_sibling
!= 0)
842 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
846 nextdie
= thisdie
+ mbr
.die_length
;
851 /* Get space to record the next field's data. */
852 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
856 list
-> field
.name
= savestring (mbr
.at_name
, strlen (mbr
.at_name
));
857 list
-> field
.type
= decode_die_type (&mbr
);
858 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
859 /* Handle bit fields. */
860 list
-> field
.bitsize
= mbr
.at_bit_size
;
862 /* For big endian bits, the at_bit_offset gives the additional
863 bit offset from the MSB of the containing anonymous object to
864 the MSB of the field. We don't have to do anything special
865 since we don't need to know the size of the anonymous object. */
866 list
-> field
.bitpos
+= mbr
.at_bit_offset
;
868 /* For little endian bits, we need to have a non-zero at_bit_size,
869 so that we know we are in fact dealing with a bitfield. Compute
870 the bit offset to the MSB of the anonymous object, subtract off
871 the number of bits from the MSB of the field to the MSB of the
872 object, and then subtract off the number of bits of the field
873 itself. The result is the bit offset of the LSB of the field. */
874 if (mbr
.at_bit_size
> 0)
876 list
-> field
.bitpos
+=
877 mbr
.at_byte_size
* 8 - mbr
.at_bit_offset
- mbr
.at_bit_size
;
883 process_dies (thisdie
, nextdie
, objfile
);
888 /* Now create the vector of fields, and record how big it is. We may
889 not even have any fields, if this DIE was generated due to a reference
890 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
891 set, which clues gdb in to the fact that it needs to search elsewhere
892 for the full structure definition. */
895 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
899 TYPE_NFIELDS (type
) = nfields
;
900 TYPE_FIELDS (type
) = (struct field
*)
901 obstack_alloc (&objfile
-> type_obstack
,
902 sizeof (struct field
) * nfields
);
903 /* Copy the saved-up fields into the field vector. */
904 for (n
= nfields
; list
; list
= list
-> next
)
906 TYPE_FIELD (type
, --n
) = list
-> field
;
916 read_structure_scope -- process all dies within struct or union
920 static void read_structure_scope (struct dieinfo *dip,
921 char *thisdie, char *enddie, struct objfile *objfile)
925 Called when we find the DIE that starts a structure or union
926 scope (definition) to process all dies that define the members
927 of the structure or union. DIP is a pointer to the die info
928 struct for the DIE that names the structure or union.
932 Note that we need to call struct_type regardless of whether or not
933 the DIE has an at_name attribute, since it might be an anonymous
934 structure or union. This gets the type entered into our set of
937 However, if the structure is incomplete (an opaque struct/union)
938 then suppress creating a symbol table entry for it since gdb only
939 wants to find the one with the complete definition. Note that if
940 it is complete, we just call new_symbol, which does it's own
941 checking about whether the struct/union is anonymous or not (and
942 suppresses creating a symbol table entry itself).
947 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
951 struct objfile
*objfile
;
956 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
957 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
959 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
961 SYMBOL_TYPE (sym
) = type
;
970 decode_array_element_type -- decode type of the array elements
974 static struct type *decode_array_element_type (char *scan, char *end)
978 As the last step in decoding the array subscript information for an
979 array DIE, we need to decode the type of the array elements. We are
980 passed a pointer to this last part of the subscript information and
981 must return the appropriate type. If the type attribute is not
982 recognized, just warn about the problem and return type int.
986 decode_array_element_type (scan
)
991 unsigned short attribute
;
992 unsigned short fundtype
;
995 attribute
= target_to_host (scan
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
,
997 scan
+= SIZEOF_ATTRIBUTE
;
998 if ((nbytes
= attribute_size (attribute
)) == -1)
1000 SQUAWK (("bad array element type attribute 0x%x", attribute
));
1001 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1008 fundtype
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1010 typep
= decode_fund_type (fundtype
);
1012 case AT_mod_fund_type
:
1013 typep
= decode_mod_fund_type (scan
);
1015 case AT_user_def_type
:
1016 die_ref
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1018 if ((typep
= lookup_utype (die_ref
)) == NULL
)
1020 typep
= alloc_utype (die_ref
, NULL
);
1023 case AT_mod_u_d_type
:
1024 typep
= decode_mod_u_d_type (scan
);
1027 SQUAWK (("bad array element type attribute 0x%x", attribute
));
1028 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1039 decode_subscr_data -- decode array subscript and element type data
1043 static struct type *decode_subscr_data (char *scan, char *end)
1047 The array subscripts and the data type of the elements of an
1048 array are described by a list of data items, stored as a block
1049 of contiguous bytes. There is a data item describing each array
1050 dimension, and a final data item describing the element type.
1051 The data items are ordered the same as their appearance in the
1052 source (I.E. leftmost dimension first, next to leftmost second,
1055 We are passed a pointer to the start of the block of bytes
1056 containing the data items, and a pointer to the first byte past
1057 the data. This function decodes the data and returns a type.
1060 FIXME: This code only implements the forms currently used
1061 by the AT&T and GNU C compilers.
1063 The end pointer is supplied for error checking, maybe we should
1067 static struct type
*
1068 decode_subscr_data (scan
, end
)
1072 struct type
*typep
= NULL
;
1073 struct type
*nexttype
;
1074 unsigned int format
;
1075 unsigned short fundtype
;
1076 unsigned long lowbound
;
1077 unsigned long highbound
;
1080 format
= target_to_host (scan
, SIZEOF_FORMAT_SPECIFIER
, GET_UNSIGNED
,
1082 scan
+= SIZEOF_FORMAT_SPECIFIER
;
1086 typep
= decode_array_element_type (scan
);
1089 fundtype
= target_to_host (scan
, SIZEOF_FMT_FT
, GET_UNSIGNED
,
1091 scan
+= SIZEOF_FMT_FT
;
1092 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1093 && fundtype
!= FT_unsigned_integer
)
1095 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1100 nbytes
= TARGET_FT_LONG_SIZE (current_objfile
);
1101 lowbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1104 highbound
= target_to_host (scan
, nbytes
, GET_UNSIGNED
,
1107 nexttype
= decode_subscr_data (scan
, end
);
1108 if (nexttype
!= NULL
)
1110 typep
= (struct type
*)
1111 obstack_alloc (¤t_objfile
-> type_obstack
,
1112 sizeof (struct type
));
1113 (void) memset (typep
, 0, sizeof (struct type
));
1114 TYPE_OBJFILE (typep
) = current_objfile
;
1115 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1116 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1117 TYPE_LENGTH (typep
) *= lowbound
+ highbound
+ 1;
1118 TYPE_TARGET_TYPE (typep
) = nexttype
;
1129 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1132 SQUAWK (("unknown array subscript format %x", format
));
1142 dwarf_read_array_type -- read TAG_array_type DIE
1146 static void dwarf_read_array_type (struct dieinfo *dip)
1150 Extract all information from a TAG_array_type DIE and add to
1151 the user defined type vector.
1155 dwarf_read_array_type (dip
)
1156 struct dieinfo
*dip
;
1162 unsigned short blocksz
;
1165 if (dip
-> at_ordering
!= ORD_row_major
)
1167 /* FIXME: Can gdb even handle column major arrays? */
1168 SQUAWK (("array not row major; not handled correctly"));
1170 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1172 nbytes
= attribute_size (AT_subscr_data
);
1173 blocksz
= target_to_host (sub
, nbytes
, GET_UNSIGNED
, current_objfile
);
1174 subend
= sub
+ nbytes
+ blocksz
;
1176 type
= decode_subscr_data (sub
, subend
);
1179 if ((utype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1181 utype
= alloc_utype (dip
-> die_ref
, NULL
);
1183 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1184 TYPE_TARGET_TYPE (utype
) =
1185 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1186 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1190 if ((utype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1192 (void) alloc_utype (dip
-> die_ref
, type
);
1196 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1197 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1198 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1208 read_tag_pointer_type -- read TAG_pointer_type DIE
1212 static void read_tag_pointer_type (struct dieinfo *dip)
1216 Extract all information from a TAG_pointer_type DIE and add to
1217 the user defined type vector.
1221 read_tag_pointer_type (dip
)
1222 struct dieinfo
*dip
;
1227 type
= decode_die_type (dip
);
1228 if ((utype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1230 utype
= lookup_pointer_type (type
);
1231 (void) alloc_utype (dip
-> die_ref
, utype
);
1235 TYPE_TARGET_TYPE (utype
) = type
;
1236 TYPE_POINTER_TYPE (type
) = utype
;
1238 /* We assume the machine has only one representation for pointers! */
1239 /* FIXME: This confuses host<->target data representations, and is a
1240 poor assumption besides. */
1242 TYPE_LENGTH (utype
) = sizeof (char *);
1243 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1251 read_subroutine_type -- process TAG_subroutine_type dies
1255 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1260 Handle DIES due to C code like:
1263 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1269 The parameter DIES are currently ignored. See if gdb has a way to
1270 include this info in it's type system, and decode them if so. Is
1271 this what the type structure's "arg_types" field is for? (FIXME)
1275 read_subroutine_type (dip
, thisdie
, enddie
)
1276 struct dieinfo
*dip
;
1280 struct type
*type
; /* Type that this function returns */
1281 struct type
*ftype
; /* Function that returns above type */
1283 /* Decode the type that this subroutine returns */
1285 type
= decode_die_type (dip
);
1287 /* Check to see if we already have a partially constructed user
1288 defined type for this DIE, from a forward reference. */
1290 if ((ftype
= lookup_utype (dip
-> die_ref
)) == NULL
)
1292 /* This is the first reference to one of these types. Make
1293 a new one and place it in the user defined types. */
1294 ftype
= lookup_function_type (type
);
1295 (void) alloc_utype (dip
-> die_ref
, ftype
);
1299 /* We have an existing partially constructed type, so bash it
1300 into the correct type. */
1301 TYPE_TARGET_TYPE (ftype
) = type
;
1302 TYPE_FUNCTION_TYPE (type
) = ftype
;
1303 TYPE_LENGTH (ftype
) = 1;
1304 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1312 read_enumeration -- process dies which define an enumeration
1316 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1317 char *enddie, struct objfile *objfile)
1321 Given a pointer to a die which begins an enumeration, process all
1322 the dies that define the members of the enumeration.
1326 Note that we need to call enum_type regardless of whether or not we
1327 have a symbol, since we might have an enum without a tag name (thus
1328 no symbol for the tagname).
1332 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1333 struct dieinfo
*dip
;
1336 struct objfile
*objfile
;
1341 type
= enum_type (dip
, objfile
);
1342 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1344 SYMBOL_TYPE (sym
) = type
;
1352 enum_type -- decode and return a type for an enumeration
1356 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1360 Given a pointer to a die information structure for the die which
1361 starts an enumeration, process all the dies that define the members
1362 of the enumeration and return a type pointer for the enumeration.
1364 At the same time, for each member of the enumeration, create a
1365 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1366 and give it the type of the enumeration itself.
1370 Note that the DWARF specification explicitly mandates that enum
1371 constants occur in reverse order from the source program order,
1372 for "consistency" and because this ordering is easier for many
1373 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1374 Entries). Because gdb wants to see the enum members in program
1375 source order, we have to ensure that the order gets reversed while
1376 we are processing them.
1379 static struct type
*
1380 enum_type (dip
, objfile
)
1381 struct dieinfo
*dip
;
1382 struct objfile
*objfile
;
1386 struct nextfield
*next
;
1389 struct nextfield
*list
= NULL
;
1390 struct nextfield
*new;
1395 unsigned short blocksz
;
1399 if ((type
= lookup_utype (dip
-> die_ref
)) == NULL
)
1401 /* No forward references created an empty type, so install one now */
1402 type
= alloc_utype (dip
-> die_ref
, NULL
);
1404 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1405 /* Some compilers try to be helpful by inventing "fake" names for
1406 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1407 Thanks, but no thanks... */
1408 if (dip
-> at_name
!= NULL
1409 && *dip
-> at_name
!= '~'
1410 && *dip
-> at_name
!= '.')
1412 TYPE_NAME (type
) = obconcat (&objfile
-> type_obstack
, "enum",
1413 " ", dip
-> at_name
);
1415 if (dip
-> at_byte_size
!= 0)
1417 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1419 if ((scan
= dip
-> at_element_list
) != NULL
)
1421 if (dip
-> short_element_list
)
1423 nbytes
= attribute_size (AT_short_element_list
);
1427 nbytes
= attribute_size (AT_element_list
);
1429 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
1430 listend
= scan
+ nbytes
+ blocksz
;
1432 while (scan
< listend
)
1434 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1437 list
-> field
.type
= NULL
;
1438 list
-> field
.bitsize
= 0;
1439 list
-> field
.bitpos
=
1440 target_to_host (scan
, TARGET_FT_LONG_SIZE (objfile
), GET_SIGNED
,
1442 scan
+= TARGET_FT_LONG_SIZE (objfile
);
1443 list
-> field
.name
= savestring (scan
, strlen (scan
));
1444 scan
+= strlen (scan
) + 1;
1446 /* Handcraft a new symbol for this enum member. */
1447 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1448 sizeof (struct symbol
));
1449 (void) memset (sym
, 0, sizeof (struct symbol
));
1450 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
,
1451 &objfile
->symbol_obstack
);
1452 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1453 SYMBOL_CLASS (sym
) = LOC_CONST
;
1454 SYMBOL_TYPE (sym
) = type
;
1455 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1456 add_symbol_to_list (sym
, list_in_scope
);
1458 /* Now create the vector of fields, and record how big it is. This is
1459 where we reverse the order, by pulling the members of the list in
1460 reverse order from how they were inserted. If we have no fields
1461 (this is apparently possible in C++) then skip building a field
1465 TYPE_NFIELDS (type
) = nfields
;
1466 TYPE_FIELDS (type
) = (struct field
*)
1467 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1468 /* Copy the saved-up fields into the field vector. */
1469 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1471 TYPE_FIELD (type
, n
++) = list
-> field
;
1482 read_func_scope -- process all dies within a function scope
1486 Process all dies within a given function scope. We are passed
1487 a die information structure pointer DIP for the die which
1488 starts the function scope, and pointers into the raw die data
1489 that define the dies within the function scope.
1491 For now, we ignore lexical block scopes within the function.
1492 The problem is that AT&T cc does not define a DWARF lexical
1493 block scope for the function itself, while gcc defines a
1494 lexical block scope for the function. We need to think about
1495 how to handle this difference, or if it is even a problem.
1500 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1501 struct dieinfo
*dip
;
1504 struct objfile
*objfile
;
1506 register struct context_stack
*new;
1508 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1509 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1511 objfile
-> ei
.entry_func_lowpc
= dip
-> at_low_pc
;
1512 objfile
-> ei
.entry_func_highpc
= dip
-> at_high_pc
;
1514 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1516 objfile
-> ei
.main_func_lowpc
= dip
-> at_low_pc
;
1517 objfile
-> ei
.main_func_highpc
= dip
-> at_high_pc
;
1519 new = push_context (0, dip
-> at_low_pc
);
1520 new -> name
= new_symbol (dip
, objfile
);
1521 list_in_scope
= &local_symbols
;
1522 process_dies (thisdie
+ dip
-> die_length
, enddie
, objfile
);
1523 new = pop_context ();
1524 /* Make a block for the local symbols within. */
1525 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1526 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1527 list_in_scope
= &file_symbols
;
1534 read_file_scope -- process all dies within a file scope
1538 Process all dies within a given file scope. We are passed a
1539 pointer to the die information structure for the die which
1540 starts the file scope, and pointers into the raw die data which
1541 mark the range of dies within the file scope.
1543 When the partial symbol table is built, the file offset for the line
1544 number table for each compilation unit is saved in the partial symbol
1545 table entry for that compilation unit. As the symbols for each
1546 compilation unit are read, the line number table is read into memory
1547 and the variable lnbase is set to point to it. Thus all we have to
1548 do is use lnbase to access the line number table for the current
1553 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1554 struct dieinfo
*dip
;
1557 struct objfile
*objfile
;
1559 struct cleanup
*back_to
;
1560 struct symtab
*symtab
;
1562 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1563 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1565 objfile
-> ei
.entry_file_lowpc
= dip
-> at_low_pc
;
1566 objfile
-> ei
.entry_file_highpc
= dip
-> at_high_pc
;
1568 if (dip
-> at_producer
!= NULL
)
1570 processing_gcc_compilation
=
1571 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1573 numutypes
= (enddie
- thisdie
) / 4;
1574 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1575 back_to
= make_cleanup (free
, utypes
);
1576 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1577 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1578 decode_line_numbers (lnbase
);
1579 process_dies (thisdie
+ dip
-> die_length
, enddie
, objfile
);
1580 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1581 /* FIXME: The following may need to be expanded for other languages */
1582 switch (dip
-> at_language
)
1586 symtab
-> language
= language_c
;
1588 case LANG_C_PLUS_PLUS
:
1589 symtab
-> language
= language_cplus
;
1594 do_cleanups (back_to
);
1603 process_dies -- process a range of DWARF Information Entries
1607 static void process_dies (char *thisdie, char *enddie,
1608 struct objfile *objfile)
1612 Process all DIE's in a specified range. May be (and almost
1613 certainly will be) called recursively.
1617 process_dies (thisdie
, enddie
, objfile
)
1620 struct objfile
*objfile
;
1625 while (thisdie
< enddie
)
1627 basicdieinfo (&di
, thisdie
, objfile
);
1628 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
1632 else if (di
.die_tag
== TAG_padding
)
1634 nextdie
= thisdie
+ di
.die_length
;
1638 completedieinfo (&di
, objfile
);
1639 if (di
.at_sibling
!= 0)
1641 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1645 nextdie
= thisdie
+ di
.die_length
;
1649 case TAG_compile_unit
:
1650 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1652 case TAG_global_subroutine
:
1653 case TAG_subroutine
:
1654 if (di
.has_at_low_pc
)
1656 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1659 case TAG_lexical_block
:
1660 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1662 case TAG_structure_type
:
1663 case TAG_union_type
:
1664 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1666 case TAG_enumeration_type
:
1667 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1669 case TAG_subroutine_type
:
1670 read_subroutine_type (&di
, thisdie
, nextdie
);
1672 case TAG_array_type
:
1673 dwarf_read_array_type (&di
);
1675 case TAG_pointer_type
:
1676 read_tag_pointer_type (&di
);
1679 (void) new_symbol (&di
, objfile
);
1691 decode_line_numbers -- decode a line number table fragment
1695 static void decode_line_numbers (char *tblscan, char *tblend,
1696 long length, long base, long line, long pc)
1700 Translate the DWARF line number information to gdb form.
1702 The ".line" section contains one or more line number tables, one for
1703 each ".line" section from the objects that were linked.
1705 The AT_stmt_list attribute for each TAG_source_file entry in the
1706 ".debug" section contains the offset into the ".line" section for the
1707 start of the table for that file.
1709 The table itself has the following structure:
1711 <table length><base address><source statement entry>
1712 4 bytes 4 bytes 10 bytes
1714 The table length is the total size of the table, including the 4 bytes
1715 for the length information.
1717 The base address is the address of the first instruction generated
1718 for the source file.
1720 Each source statement entry has the following structure:
1722 <line number><statement position><address delta>
1723 4 bytes 2 bytes 4 bytes
1725 The line number is relative to the start of the file, starting with
1728 The statement position either -1 (0xFFFF) or the number of characters
1729 from the beginning of the line to the beginning of the statement.
1731 The address delta is the difference between the base address and
1732 the address of the first instruction for the statement.
1734 Note that we must copy the bytes from the packed table to our local
1735 variables before attempting to use them, to avoid alignment problems
1736 on some machines, particularly RISC processors.
1740 Does gdb expect the line numbers to be sorted? They are now by
1741 chance/luck, but are not required to be. (FIXME)
1743 The line with number 0 is unused, gdb apparently can discover the
1744 span of the last line some other way. How? (FIXME)
1748 decode_line_numbers (linetable
)
1753 unsigned long length
;
1758 if (linetable
!= NULL
)
1760 tblscan
= tblend
= linetable
;
1761 length
= target_to_host (tblscan
, SIZEOF_LINETBL_LENGTH
, GET_UNSIGNED
,
1763 tblscan
+= SIZEOF_LINETBL_LENGTH
;
1765 base
= target_to_host (tblscan
, TARGET_FT_POINTER_SIZE (objfile
),
1766 GET_UNSIGNED
, current_objfile
);
1767 tblscan
+= TARGET_FT_POINTER_SIZE (objfile
);
1769 while (tblscan
< tblend
)
1771 line
= target_to_host (tblscan
, SIZEOF_LINETBL_LINENO
, GET_UNSIGNED
,
1773 tblscan
+= SIZEOF_LINETBL_LINENO
+ SIZEOF_LINETBL_STMT
;
1774 pc
= target_to_host (tblscan
, SIZEOF_LINETBL_DELTA
, GET_UNSIGNED
,
1776 tblscan
+= SIZEOF_LINETBL_DELTA
;
1780 record_line (current_subfile
, line
, pc
);
1790 locval -- compute the value of a location attribute
1794 static int locval (char *loc)
1798 Given pointer to a string of bytes that define a location, compute
1799 the location and return the value.
1801 When computing values involving the current value of the frame pointer,
1802 the value zero is used, which results in a value relative to the frame
1803 pointer, rather than the absolute value. This is what GDB wants
1806 When the result is a register number, the global isreg flag is set,
1807 otherwise it is cleared. This is a kludge until we figure out a better
1808 way to handle the problem. Gdb's design does not mesh well with the
1809 DWARF notion of a location computing interpreter, which is a shame
1810 because the flexibility goes unused.
1814 Note that stack[0] is unused except as a default error return.
1815 Note that stack overflow is not yet handled.
1822 unsigned short nbytes
;
1823 unsigned short locsize
;
1824 auto long stack
[64];
1831 nbytes
= attribute_size (AT_location
);
1832 locsize
= target_to_host (loc
, nbytes
, GET_UNSIGNED
, current_objfile
);
1834 end
= loc
+ locsize
;
1839 loc_value_size
= TARGET_FT_LONG_SIZE (current_objfile
);
1842 loc_atom_code
= target_to_host (loc
, SIZEOF_LOC_ATOM_CODE
, GET_UNSIGNED
,
1844 loc
+= SIZEOF_LOC_ATOM_CODE
;
1845 switch (loc_atom_code
)
1852 /* push register (number) */
1853 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
1854 GET_UNSIGNED
, current_objfile
);
1855 loc
+= loc_value_size
;
1859 /* push value of register (number) */
1860 /* Actually, we compute the value as if register has 0 */
1862 regno
= target_to_host (loc
, loc_value_size
, GET_UNSIGNED
,
1864 loc
+= loc_value_size
;
1867 stack
[++stacki
] = 0;
1871 stack
[++stacki
] = 0;
1872 SQUAWK (("BASEREG %d not handled!", regno
));
1876 /* push address (relocated address) */
1877 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
1878 GET_UNSIGNED
, current_objfile
);
1879 loc
+= loc_value_size
;
1882 /* push constant (number) FIXME: signed or unsigned! */
1883 stack
[++stacki
] = target_to_host (loc
, loc_value_size
,
1884 GET_SIGNED
, current_objfile
);
1885 loc
+= loc_value_size
;
1888 /* pop, deref and push 2 bytes (as a long) */
1889 SQUAWK (("OP_DEREF2 address 0x%x not handled", stack
[stacki
]));
1891 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1892 SQUAWK (("OP_DEREF4 address 0x%x not handled", stack
[stacki
]));
1894 case OP_ADD
: /* pop top 2 items, add, push result */
1895 stack
[stacki
- 1] += stack
[stacki
];
1900 return (stack
[stacki
]);
1907 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1911 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1915 When expanding a partial symbol table entry to a full symbol table
1916 entry, this is the function that gets called to read in the symbols
1917 for the compilation unit.
1919 Returns a pointer to the newly constructed symtab (which is now
1920 the new first one on the objfile's symtab list).
1923 static struct symtab
*
1924 read_ofile_symtab (pst
)
1925 struct partial_symtab
*pst
;
1927 struct cleanup
*back_to
;
1928 unsigned long lnsize
;
1931 char lnsizedata
[SIZEOF_LINETBL_LENGTH
];
1933 abfd
= pst
-> objfile
-> obfd
;
1934 current_objfile
= pst
-> objfile
;
1936 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1937 unit, seek to the location in the file, and read in all the DIE's. */
1940 dbbase
= xmalloc (DBLENGTH(pst
));
1941 dbroff
= DBROFF(pst
);
1942 foffset
= DBFOFF(pst
) + dbroff
;
1943 baseaddr
= pst
-> addr
;
1944 if (bfd_seek (abfd
, foffset
, 0) ||
1945 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1948 error ("can't read DWARF data");
1950 back_to
= make_cleanup (free
, dbbase
);
1952 /* If there is a line number table associated with this compilation unit
1953 then read the size of this fragment in bytes, from the fragment itself.
1954 Allocate a buffer for the fragment and read it in for future
1960 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1961 (bfd_read ((PTR
) lnsizedata
, sizeof (lnsizedata
), 1, abfd
) !=
1962 sizeof (lnsizedata
)))
1964 error ("can't read DWARF line number table size");
1966 lnsize
= target_to_host (lnsizedata
, SIZEOF_LINETBL_LENGTH
,
1967 GET_UNSIGNED
, pst
-> objfile
);
1968 lnbase
= xmalloc (lnsize
);
1969 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1970 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1973 error ("can't read DWARF line numbers");
1975 make_cleanup (free
, lnbase
);
1978 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1979 do_cleanups (back_to
);
1980 current_objfile
= NULL
;
1981 return (pst
-> objfile
-> symtabs
);
1988 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1992 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1996 Called once for each partial symbol table entry that needs to be
1997 expanded into a full symbol table entry.
2002 psymtab_to_symtab_1 (pst
)
2003 struct partial_symtab
*pst
;
2011 warning ("psymtab for %s already read in. Shouldn't happen.",
2016 /* Read in all partial symtabs on which this one is dependent */
2017 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
2019 if (!pst
-> dependencies
[i
] -> readin
)
2021 /* Inform about additional files that need to be read in. */
2024 fputs_filtered (" ", stdout
);
2026 fputs_filtered ("and ", stdout
);
2028 printf_filtered ("%s...",
2029 pst
-> dependencies
[i
] -> filename
);
2031 fflush (stdout
); /* Flush output */
2033 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
2036 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
2038 pst
-> symtab
= read_ofile_symtab (pst
);
2041 printf_filtered ("%d DIE's, sorting...", diecount
);
2045 sort_symtab_syms (pst
-> symtab
);
2056 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
2060 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
2064 This is the DWARF support entry point for building a full symbol
2065 table entry from a partial symbol table entry. We are passed a
2066 pointer to the partial symbol table entry that needs to be expanded.
2071 dwarf_psymtab_to_symtab (pst
)
2072 struct partial_symtab
*pst
;
2079 warning ("psymtab for %s already read in. Shouldn't happen.",
2084 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
2086 /* Print the message now, before starting serious work, to avoid
2087 disconcerting pauses. */
2090 printf_filtered ("Reading in symbols for %s...",
2095 psymtab_to_symtab_1 (pst
);
2097 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2098 we need to do an equivalent or is this something peculiar to
2100 Match with global symbols. This only needs to be done once,
2101 after all of the symtabs and dependencies have been read in.
2103 scan_file_globals (pst
-> objfile
);
2106 /* Finish up the verbose info message. */
2109 printf_filtered ("done.\n");
2121 init_psymbol_list -- initialize storage for partial symbols
2125 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2129 Initializes storage for all of the partial symbols that will be
2130 created by dwarf_build_psymtabs and subsidiaries.
2134 init_psymbol_list (objfile
, total_symbols
)
2135 struct objfile
*objfile
;
2138 /* Free any previously allocated psymbol lists. */
2140 if (objfile
-> global_psymbols
.list
)
2142 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
2144 if (objfile
-> static_psymbols
.list
)
2146 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
2149 /* Current best guess is that there are approximately a twentieth
2150 of the total symbols (in a debugging file) are global or static
2153 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2154 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2155 objfile
-> global_psymbols
.next
=
2156 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2157 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
2158 * sizeof (struct partial_symbol
));
2159 objfile
-> static_psymbols
.next
=
2160 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2161 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
2162 * sizeof (struct partial_symbol
));
2169 add_enum_psymbol -- add enumeration members to partial symbol table
2173 Given pointer to a DIE that is known to be for an enumeration,
2174 extract the symbolic names of the enumeration members and add
2175 partial symbols for them.
2179 add_enum_psymbol (dip
, objfile
)
2180 struct dieinfo
*dip
;
2181 struct objfile
*objfile
;
2185 unsigned short blocksz
;
2188 if ((scan
= dip
-> at_element_list
) != NULL
)
2190 if (dip
-> short_element_list
)
2192 nbytes
= attribute_size (AT_short_element_list
);
2196 nbytes
= attribute_size (AT_element_list
);
2198 blocksz
= target_to_host (scan
, nbytes
, GET_UNSIGNED
, objfile
);
2200 listend
= scan
+ blocksz
;
2201 while (scan
< listend
)
2203 scan
+= TARGET_FT_LONG_SIZE (objfile
);
2204 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2205 objfile
-> static_psymbols
, 0);
2206 scan
+= strlen (scan
) + 1;
2215 add_partial_symbol -- add symbol to partial symbol table
2219 Given a DIE, if it is one of the types that we want to
2220 add to a partial symbol table, finish filling in the die info
2221 and then add a partial symbol table entry for it.
2226 add_partial_symbol (dip
, objfile
)
2227 struct dieinfo
*dip
;
2228 struct objfile
*objfile
;
2230 switch (dip
-> die_tag
)
2232 case TAG_global_subroutine
:
2233 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2235 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2236 VAR_NAMESPACE
, LOC_BLOCK
,
2237 objfile
-> global_psymbols
,
2240 case TAG_global_variable
:
2241 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2243 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2244 VAR_NAMESPACE
, LOC_STATIC
,
2245 objfile
-> global_psymbols
,
2248 case TAG_subroutine
:
2249 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2250 VAR_NAMESPACE
, LOC_BLOCK
,
2251 objfile
-> static_psymbols
,
2254 case TAG_local_variable
:
2255 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2256 VAR_NAMESPACE
, LOC_STATIC
,
2257 objfile
-> static_psymbols
,
2261 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2262 VAR_NAMESPACE
, LOC_TYPEDEF
,
2263 objfile
-> static_psymbols
,
2266 case TAG_structure_type
:
2267 case TAG_union_type
:
2268 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2269 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2270 objfile
-> static_psymbols
,
2273 case TAG_enumeration_type
:
2276 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2277 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2278 objfile
-> static_psymbols
,
2281 add_enum_psymbol (dip
, objfile
);
2290 scan_partial_symbols -- scan DIE's within a single compilation unit
2294 Process the DIE's within a single compilation unit, looking for
2295 interesting DIE's that contribute to the partial symbol table entry
2296 for this compilation unit. Since we cannot follow any sibling
2297 chains without reading the complete DIE info for every DIE,
2298 it is probably faster to just sequentially check each one to
2299 see if it is one of the types we are interested in, and if so,
2300 then extract all the attributes info and generate a partial
2305 Don't attempt to add anonymous structures or unions since they have
2306 no name. Anonymous enumerations however are processed, because we
2307 want to extract their member names (the check for a tag name is
2310 Also, for variables and subroutines, check that this is the place
2311 where the actual definition occurs, rather than just a reference
2316 scan_partial_symbols (thisdie
, enddie
, objfile
)
2319 struct objfile
*objfile
;
2324 while (thisdie
< enddie
)
2326 basicdieinfo (&di
, thisdie
, objfile
);
2327 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2333 nextdie
= thisdie
+ di
.die_length
;
2334 /* To avoid getting complete die information for every die, we
2335 only do it (below) for the cases we are interested in. */
2338 case TAG_global_subroutine
:
2339 case TAG_subroutine
:
2340 case TAG_global_variable
:
2341 case TAG_local_variable
:
2342 completedieinfo (&di
, objfile
);
2343 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2345 add_partial_symbol (&di
, objfile
);
2349 case TAG_structure_type
:
2350 case TAG_union_type
:
2351 completedieinfo (&di
, objfile
);
2354 add_partial_symbol (&di
, objfile
);
2357 case TAG_enumeration_type
:
2358 completedieinfo (&di
, objfile
);
2359 add_partial_symbol (&di
, objfile
);
2371 scan_compilation_units -- build a psymtab entry for each compilation
2375 This is the top level dwarf parsing routine for building partial
2378 It scans from the beginning of the DWARF table looking for the first
2379 TAG_compile_unit DIE, and then follows the sibling chain to locate
2380 each additional TAG_compile_unit DIE.
2382 For each TAG_compile_unit DIE it creates a partial symtab structure,
2383 calls a subordinate routine to collect all the compilation unit's
2384 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2385 new partial symtab structure into the partial symbol table. It also
2386 records the appropriate information in the partial symbol table entry
2387 to allow the chunk of DIE's and line number table for this compilation
2388 unit to be located and re-read later, to generate a complete symbol
2389 table entry for the compilation unit.
2391 Thus it effectively partitions up a chunk of DIE's for multiple
2392 compilation units into smaller DIE chunks and line number tables,
2393 and associates them with a partial symbol table entry.
2397 If any compilation unit has no line number table associated with
2398 it for some reason (a missing at_stmt_list attribute, rather than
2399 just one with a value of zero, which is valid) then we ensure that
2400 the recorded file offset is zero so that the routine which later
2401 reads line number table fragments knows that there is no fragment
2411 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2415 unsigned int dbfoff
;
2416 unsigned int lnoffset
;
2417 struct objfile
*objfile
;
2421 struct partial_symtab
*pst
;
2426 while (thisdie
< enddie
)
2428 basicdieinfo (&di
, thisdie
, objfile
);
2429 if (di
.die_length
< SIZEOF_DIE_LENGTH
)
2433 else if (di
.die_tag
!= TAG_compile_unit
)
2435 nextdie
= thisdie
+ di
.die_length
;
2439 completedieinfo (&di
, objfile
);
2440 if (di
.at_sibling
!= 0)
2442 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2446 nextdie
= thisdie
+ di
.die_length
;
2448 curoff
= thisdie
- dbbase
;
2449 culength
= nextdie
- thisdie
;
2450 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2452 /* First allocate a new partial symbol table structure */
2454 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2456 objfile
-> global_psymbols
.next
,
2457 objfile
-> static_psymbols
.next
);
2459 pst
-> texthigh
= di
.at_high_pc
;
2460 pst
-> read_symtab_private
= (char *)
2461 obstack_alloc (&objfile
-> psymbol_obstack
,
2462 sizeof (struct dwfinfo
));
2463 DBFOFF (pst
) = dbfoff
;
2464 DBROFF (pst
) = curoff
;
2465 DBLENGTH (pst
) = culength
;
2466 LNFOFF (pst
) = curlnoffset
;
2467 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2469 /* Now look for partial symbols */
2471 scan_partial_symbols (thisdie
+ di
.die_length
, nextdie
, objfile
);
2473 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2474 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2475 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2476 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2477 sort_pst_symbols (pst
);
2478 /* If there is already a psymtab or symtab for a file of this name,
2479 remove it. (If there is a symtab, more drastic things also
2480 happen.) This happens in VxWorks. */
2481 free_named_symtabs (pst
-> filename
);
2491 new_symbol -- make a symbol table entry for a new symbol
2495 static struct symbol *new_symbol (struct dieinfo *dip,
2496 struct objfile *objfile)
2500 Given a pointer to a DWARF information entry, figure out if we need
2501 to make a symbol table entry for it, and if so, create a new entry
2502 and return a pointer to it.
2505 static struct symbol
*
2506 new_symbol (dip
, objfile
)
2507 struct dieinfo
*dip
;
2508 struct objfile
*objfile
;
2510 struct symbol
*sym
= NULL
;
2512 if (dip
-> at_name
!= NULL
)
2514 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2515 sizeof (struct symbol
));
2516 (void) memset (sym
, 0, sizeof (struct symbol
));
2517 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2518 /* default assumptions */
2519 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2520 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2521 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2522 switch (dip
-> die_tag
)
2525 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2526 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2528 case TAG_global_subroutine
:
2529 case TAG_subroutine
:
2530 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2531 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2532 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2533 if (dip
-> die_tag
== TAG_global_subroutine
)
2535 add_symbol_to_list (sym
, &global_symbols
);
2539 add_symbol_to_list (sym
, list_in_scope
);
2542 case TAG_global_variable
:
2543 if (dip
-> at_location
!= NULL
)
2545 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2546 add_symbol_to_list (sym
, &global_symbols
);
2547 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2548 SYMBOL_VALUE (sym
) += baseaddr
;
2551 case TAG_local_variable
:
2552 if (dip
-> at_location
!= NULL
)
2554 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2555 add_symbol_to_list (sym
, list_in_scope
);
2558 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2562 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2566 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2567 SYMBOL_VALUE (sym
) += baseaddr
;
2571 case TAG_formal_parameter
:
2572 if (dip
-> at_location
!= NULL
)
2574 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2576 add_symbol_to_list (sym
, list_in_scope
);
2579 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2583 SYMBOL_CLASS (sym
) = LOC_ARG
;
2586 case TAG_unspecified_parameters
:
2587 /* From varargs functions; gdb doesn't seem to have any interest in
2588 this information, so just ignore it for now. (FIXME?) */
2590 case TAG_structure_type
:
2591 case TAG_union_type
:
2592 case TAG_enumeration_type
:
2593 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2594 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2595 add_symbol_to_list (sym
, list_in_scope
);
2598 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2599 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2600 add_symbol_to_list (sym
, list_in_scope
);
2603 /* Not a tag we recognize. Hopefully we aren't processing trash
2604 data, but since we must specifically ignore things we don't
2605 recognize, there is nothing else we should do at this point. */
2616 decode_mod_fund_type -- decode a modified fundamental type
2620 static struct type *decode_mod_fund_type (char *typedata)
2624 Decode a block of data containing a modified fundamental
2625 type specification. TYPEDATA is a pointer to the block,
2626 which starts with a length containing the size of the rest
2627 of the block. At the end of the block is a fundmental type
2628 code value that gives the fundamental type. Everything
2629 in between are type modifiers.
2631 We simply compute the number of modifiers and call the general
2632 function decode_modified_type to do the actual work.
2635 static struct type
*
2636 decode_mod_fund_type (typedata
)
2639 struct type
*typep
= NULL
;
2640 unsigned short modcount
;
2643 /* Get the total size of the block, exclusive of the size itself */
2645 nbytes
= attribute_size (AT_mod_fund_type
);
2646 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
2649 /* Deduct the size of the fundamental type bytes at the end of the block. */
2651 modcount
-= attribute_size (AT_fund_type
);
2653 /* Now do the actual decoding */
2655 typep
= decode_modified_type (typedata
, modcount
, AT_mod_fund_type
);
2663 decode_mod_u_d_type -- decode a modified user defined type
2667 static struct type *decode_mod_u_d_type (char *typedata)
2671 Decode a block of data containing a modified user defined
2672 type specification. TYPEDATA is a pointer to the block,
2673 which consists of a two byte length, containing the size
2674 of the rest of the block. At the end of the block is a
2675 four byte value that gives a reference to a user defined type.
2676 Everything in between are type modifiers.
2678 We simply compute the number of modifiers and call the general
2679 function decode_modified_type to do the actual work.
2682 static struct type
*
2683 decode_mod_u_d_type (typedata
)
2686 struct type
*typep
= NULL
;
2687 unsigned short modcount
;
2690 /* Get the total size of the block, exclusive of the size itself */
2692 nbytes
= attribute_size (AT_mod_u_d_type
);
2693 modcount
= target_to_host (typedata
, nbytes
, GET_UNSIGNED
, current_objfile
);
2696 /* Deduct the size of the reference type bytes at the end of the block. */
2698 modcount
-= attribute_size (AT_user_def_type
);
2700 /* Now do the actual decoding */
2702 typep
= decode_modified_type (typedata
, modcount
, AT_mod_u_d_type
);
2710 decode_modified_type -- decode modified user or fundamental type
2714 static struct type *decode_modified_type (unsigned char *modifiers,
2715 unsigned short modcount, int mtype)
2719 Decode a modified type, either a modified fundamental type or
2720 a modified user defined type. MODIFIERS is a pointer to the
2721 block of bytes that define MODCOUNT modifiers. Immediately
2722 following the last modifier is a short containing the fundamental
2723 type or a long containing the reference to the user defined
2724 type. Which one is determined by MTYPE, which is either
2725 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2726 type we are generating.
2728 We call ourself recursively to generate each modified type,`
2729 until MODCOUNT reaches zero, at which point we have consumed
2730 all the modifiers and generate either the fundamental type or
2731 user defined type. When the recursion unwinds, each modifier
2732 is applied in turn to generate the full modified type.
2736 If we find a modifier that we don't recognize, and it is not one
2737 of those reserved for application specific use, then we issue a
2738 warning and simply ignore the modifier.
2742 We currently ignore MOD_const and MOD_volatile. (FIXME)
2746 static struct type
*
2747 decode_modified_type (modifiers
, modcount
, mtype
)
2748 unsigned char *modifiers
;
2749 unsigned int modcount
;
2752 struct type
*typep
= NULL
;
2753 unsigned short fundtype
;
2755 unsigned char modifier
;
2762 case AT_mod_fund_type
:
2763 nbytes
= attribute_size (AT_fund_type
);
2764 fundtype
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
2766 typep
= decode_fund_type (fundtype
);
2768 case AT_mod_u_d_type
:
2769 nbytes
= attribute_size (AT_user_def_type
);
2770 die_ref
= target_to_host (modifiers
, nbytes
, GET_UNSIGNED
,
2772 if ((typep
= lookup_utype (die_ref
)) == NULL
)
2774 typep
= alloc_utype (die_ref
, NULL
);
2778 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2779 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2785 modifier
= *modifiers
++;
2786 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2789 case MOD_pointer_to
:
2790 typep
= lookup_pointer_type (typep
);
2792 case MOD_reference_to
:
2793 typep
= lookup_reference_type (typep
);
2796 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2799 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2802 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2804 SQUAWK (("unknown type modifier %u", modifier
));
2816 decode_fund_type -- translate basic DWARF type to gdb base type
2820 Given an integer that is one of the fundamental DWARF types,
2821 translate it to one of the basic internal gdb types and return
2822 a pointer to the appropriate gdb type (a "struct type *").
2826 If we encounter a fundamental type that we are unprepared to
2827 deal with, and it is not in the range of those types defined
2828 as application specific types, then we issue a warning and
2829 treat the type as an "int".
2832 static struct type
*
2833 decode_fund_type (fundtype
)
2834 unsigned int fundtype
;
2836 struct type
*typep
= NULL
;
2842 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2845 case FT_boolean
: /* Was FT_set in AT&T version */
2846 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2849 case FT_pointer
: /* (void *) */
2850 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2851 typep
= lookup_pointer_type (typep
);
2855 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2858 case FT_signed_char
:
2859 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2862 case FT_unsigned_char
:
2863 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2867 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2870 case FT_signed_short
:
2871 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2874 case FT_unsigned_short
:
2875 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2879 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2882 case FT_signed_integer
:
2883 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2886 case FT_unsigned_integer
:
2887 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2891 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2894 case FT_signed_long
:
2895 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2898 case FT_unsigned_long
:
2899 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2903 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2906 case FT_signed_long_long
:
2907 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2910 case FT_unsigned_long_long
:
2911 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2915 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2918 case FT_dbl_prec_float
:
2919 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2922 case FT_ext_prec_float
:
2923 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2927 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2930 case FT_dbl_prec_complex
:
2931 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2934 case FT_ext_prec_complex
:
2935 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2940 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2942 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2943 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2953 create_name -- allocate a fresh copy of a string on an obstack
2957 Given a pointer to a string and a pointer to an obstack, allocates
2958 a fresh copy of the string on the specified obstack.
2963 create_name (name
, obstackp
)
2965 struct obstack
*obstackp
;
2970 length
= strlen (name
) + 1;
2971 newname
= (char *) obstack_alloc (obstackp
, length
);
2972 (void) strcpy (newname
, name
);
2980 basicdieinfo -- extract the minimal die info from raw die data
2984 void basicdieinfo (char *diep, struct dieinfo *dip,
2985 struct objfile *objfile)
2989 Given a pointer to raw DIE data, and a pointer to an instance of a
2990 die info structure, this function extracts the basic information
2991 from the DIE data required to continue processing this DIE, along
2992 with some bookkeeping information about the DIE.
2994 The information we absolutely must have includes the DIE tag,
2995 and the DIE length. If we need the sibling reference, then we
2996 will have to call completedieinfo() to process all the remaining
2999 Note that since there is no guarantee that the data is properly
3000 aligned in memory for the type of access required (indirection
3001 through anything other than a char pointer), and there is no
3002 guarantee that it is in the same byte order as the gdb host,
3003 we call a function which deals with both alignment and byte
3004 swapping issues. Possibly inefficient, but quite portable.
3006 We also take care of some other basic things at this point, such
3007 as ensuring that the instance of the die info structure starts
3008 out completely zero'd and that curdie is initialized for use
3009 in error reporting if we have a problem with the current die.
3013 All DIE's must have at least a valid length, thus the minimum
3014 DIE size is SIZEOF_DIE_LENGTH. In order to have a valid tag, the
3015 DIE size must be at least SIZEOF_DIE_TAG larger, otherwise they
3016 are forced to be TAG_padding DIES.
3018 Padding DIES must be at least SIZEOF_DIE_LENGTH in length, implying
3019 that if a padding DIE is used for alignment and the amount needed is
3020 less than SIZEOF_DIE_LENGTH, then the padding DIE has to be big
3021 enough to align to the next alignment boundry.
3025 basicdieinfo (dip
, diep
, objfile
)
3026 struct dieinfo
*dip
;
3028 struct objfile
*objfile
;
3031 (void) memset (dip
, 0, sizeof (struct dieinfo
));
3033 dip
-> die_ref
= dbroff
+ (diep
- dbbase
);
3034 dip
-> die_length
= target_to_host (diep
, SIZEOF_DIE_LENGTH
, GET_UNSIGNED
,
3036 if (dip
-> die_length
< SIZEOF_DIE_LENGTH
)
3038 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> die_length
);
3040 else if (dip
-> die_length
< (SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
))
3042 dip
-> die_tag
= TAG_padding
;
3046 diep
+= SIZEOF_DIE_LENGTH
;
3047 dip
-> die_tag
= target_to_host (diep
, SIZEOF_DIE_TAG
, GET_UNSIGNED
,
3056 completedieinfo -- finish reading the information for a given DIE
3060 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
3064 Given a pointer to an already partially initialized die info structure,
3065 scan the raw DIE data and finish filling in the die info structure
3066 from the various attributes found.
3068 Note that since there is no guarantee that the data is properly
3069 aligned in memory for the type of access required (indirection
3070 through anything other than a char pointer), and there is no
3071 guarantee that it is in the same byte order as the gdb host,
3072 we call a function which deals with both alignment and byte
3073 swapping issues. Possibly inefficient, but quite portable.
3077 Each time we are called, we increment the diecount variable, which
3078 keeps an approximate count of the number of dies processed for
3079 each compilation unit. This information is presented to the user
3080 if the info_verbose flag is set.
3085 completedieinfo (dip
, objfile
)
3086 struct dieinfo
*dip
;
3087 struct objfile
*objfile
;
3089 char *diep
; /* Current pointer into raw DIE data */
3090 char *end
; /* Terminate DIE scan here */
3091 unsigned short attr
; /* Current attribute being scanned */
3092 unsigned short form
; /* Form of the attribute */
3093 int nbytes
; /* Size of next field to read */
3097 end
= diep
+ dip
-> die_length
;
3098 diep
+= SIZEOF_DIE_LENGTH
+ SIZEOF_DIE_TAG
;
3101 attr
= target_to_host (diep
, SIZEOF_ATTRIBUTE
, GET_UNSIGNED
, objfile
);
3102 diep
+= SIZEOF_ATTRIBUTE
;
3103 if ((nbytes
= attribute_size (attr
)) == -1)
3105 SQUAWK (("unknown attribute length, skipped remaining attributes"));;
3112 dip
-> at_fund_type
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3116 dip
-> at_ordering
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3120 dip
-> at_bit_offset
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3124 dip
-> at_visibility
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3128 dip
-> at_sibling
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3132 dip
-> at_stmt_list
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3134 dip
-> has_at_stmt_list
= 1;
3137 dip
-> at_low_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3139 dip
-> at_low_pc
+= baseaddr
;
3140 dip
-> has_at_low_pc
= 1;
3143 dip
-> at_high_pc
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3145 dip
-> at_high_pc
+= baseaddr
;
3148 dip
-> at_language
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3151 case AT_user_def_type
:
3152 dip
-> at_user_def_type
= target_to_host (diep
, nbytes
,
3153 GET_UNSIGNED
, objfile
);
3156 dip
-> at_byte_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3160 dip
-> at_bit_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3164 dip
-> at_member
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3168 dip
-> at_discr
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3172 dip
-> at_import
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3176 dip
-> at_location
= diep
;
3178 case AT_mod_fund_type
:
3179 dip
-> at_mod_fund_type
= diep
;
3181 case AT_subscr_data
:
3182 dip
-> at_subscr_data
= diep
;
3184 case AT_mod_u_d_type
:
3185 dip
-> at_mod_u_d_type
= diep
;
3187 case AT_element_list
:
3188 dip
-> at_element_list
= diep
;
3189 dip
-> short_element_list
= 0;
3191 case AT_short_element_list
:
3192 dip
-> at_element_list
= diep
;
3193 dip
-> short_element_list
= 1;
3195 case AT_discr_value
:
3196 dip
-> at_discr_value
= diep
;
3198 case AT_string_length
:
3199 dip
-> at_string_length
= diep
;
3202 dip
-> at_name
= diep
;
3205 dip
-> at_comp_dir
= diep
;
3208 dip
-> at_producer
= diep
;
3211 dip
-> at_frame_base
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3214 case AT_start_scope
:
3215 dip
-> at_start_scope
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3218 case AT_stride_size
:
3219 dip
-> at_stride_size
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3223 dip
-> at_src_info
= target_to_host (diep
, nbytes
, GET_UNSIGNED
,
3227 dip
-> at_prototyped
= diep
;
3230 /* Found an attribute that we are unprepared to handle. However
3231 it is specifically one of the design goals of DWARF that
3232 consumers should ignore unknown attributes. As long as the
3233 form is one that we recognize (so we know how to skip it),
3234 we can just ignore the unknown attribute. */
3237 form
= FORM_FROM_ATTR (attr
);
3251 diep
+= TARGET_FT_POINTER_SIZE (objfile
);
3254 diep
+= 2 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3257 diep
+= 4 + target_to_host (diep
, nbytes
, GET_UNSIGNED
, objfile
);
3260 diep
+= strlen (diep
) + 1;
3263 SQUAWK (("unknown attribute form (0x%x)", form
));
3264 SQUAWK (("unknown attribute length, skipped remaining attributes"));;
3275 target_to_host -- swap in target data to host
3279 target_to_host (char *from, int nbytes, int signextend,
3280 struct objfile *objfile)
3284 Given pointer to data in target format in FROM, a byte count for
3285 the size of the data in NBYTES, a flag indicating whether or not
3286 the data is signed in SIGNEXTEND, and a pointer to the current
3287 objfile in OBJFILE, convert the data to host format and return
3288 the converted value.
3292 FIXME: If we read data that is known to be signed, and expect to
3293 use it as signed data, then we need to explicitly sign extend the
3294 result until the bfd library is able to do this for us.
3298 static unsigned long
3299 target_to_host (from
, nbytes
, signextend
, objfile
)
3302 int signextend
; /* FIXME: Unused */
3303 struct objfile
*objfile
;
3305 unsigned long rtnval
;
3310 rtnval
= bfd_get_64 (objfile
-> obfd
, (bfd_byte
*) from
);
3313 rtnval
= bfd_get_32 (objfile
-> obfd
, (bfd_byte
*) from
);
3316 rtnval
= bfd_get_16 (objfile
-> obfd
, (bfd_byte
*) from
);
3319 rtnval
= bfd_get_8 (objfile
-> obfd
, (bfd_byte
*) from
);
3322 dwarfwarn ("no bfd support for %d byte data object", nbytes
);
3333 attribute_size -- compute size of data for a DWARF attribute
3337 static int attribute_size (unsigned int attr)
3341 Given a DWARF attribute in ATTR, compute the size of the first
3342 piece of data associated with this attribute and return that
3345 Returns -1 for unrecognized attributes.
3350 attribute_size (attr
)
3353 int nbytes
; /* Size of next data for this attribute */
3354 unsigned short form
; /* Form of the attribute */
3356 form
= FORM_FROM_ATTR (attr
);
3359 case FORM_STRING
: /* A variable length field is next */
3362 case FORM_DATA2
: /* Next 2 byte field is the data itself */
3363 case FORM_BLOCK2
: /* Next 2 byte field is a block length */
3366 case FORM_DATA4
: /* Next 4 byte field is the data itself */
3367 case FORM_BLOCK4
: /* Next 4 byte field is a block length */
3368 case FORM_REF
: /* Next 4 byte field is a DIE offset */
3371 case FORM_DATA8
: /* Next 8 byte field is the data itself */
3374 case FORM_ADDR
: /* Next field size is target sizeof(void *) */
3375 nbytes
= TARGET_FT_POINTER_SIZE (objfile
);
3378 SQUAWK (("unknown attribute form (0x%x)", form
));