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: Currently we ignore host/target byte ordering and integer size
30 differences. Should remap data from external form to an internal form
31 before trying to use it.
33 FIXME: Resolve minor differences between what information we put in the
34 partial symbol table and what dbxread puts in. For example, we don't yet
35 put enum constants there. And dbxread seems to invent a lot of typedefs
36 we never see. Use the new printpsym command to see the partial symbol table
39 FIXME: Figure out a better way to tell gdb about the name of the function
40 contain the user's entry point (I.E. main())
42 FIXME: The current DWARF specification has a very strong bias towards
43 machines with 32-bit integers, as it assumes that many attributes of the
44 program (such as an address) will fit in such an integer. There are many
45 references in the spec to things that are 2, 4, or 8 bytes long. Given that
46 we will probably run into problems on machines where some of these assumptions
47 are invalid (64-bit ints for example), we don't bother at this time to try to
48 make this code more flexible and just use shorts, ints, and longs (and their
49 sizes) where it seems appropriate. I.E. we use a short int to hold DWARF
50 tags, and assume that the tag size in the file is the same as sizeof(short).
52 FIXME: See other FIXME's and "ifdef 0" scattered throughout the code for
53 other things to work on, if you get bored. :-)
67 #include "libbfd.h" /* FIXME Secret Internal BFD stuff (bfd_read) */
68 #include "elf/dwarf.h"
71 #ifdef MAINTENANCE /* Define to 1 to compile in some maintenance stuff */
72 #define SQUAWK(stuff) dwarfwarn stuff
77 #ifndef R_FP /* FIXME */
78 #define R_FP 14 /* Kludge to get frame pointer register number */
81 typedef unsigned int DIEREF
; /* Reference to a DIE */
84 #define GCC_PRODUCER "GNU C "
87 #define STREQ(a,b) (strcmp(a,b)==0)
88 #define STREQN(a,b,n) (strncmp(a,b,n)==0)
90 #define SWAPIN(to,from,objfile) swapin((char *)&(to),from,sizeof(to),objfile)
92 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
93 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
94 However, the Issue 2 DWARF specification from AT&T defines it as
95 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
96 For backwards compatibility with the AT&T compiler produced executables
97 we define AT_short_element_list for this variant. */
99 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
101 /* External variables referenced. */
103 extern int info_verbose
; /* From main.c; nonzero => verbose */
104 extern char *warning_pre_print
; /* From utils.c */
106 /* The DWARF debugging information consists of two major pieces,
107 one is a block of DWARF Information Entries (DIE's) and the other
108 is a line number table. The "struct dieinfo" structure contains
109 the information for a single DIE, the one currently being processed.
111 In order to make it easier to randomly access the attribute fields
112 of the current DIE, which are specifically unordered within the DIE
113 each DIE is scanned and an instance of the "struct dieinfo"
114 structure is initialized.
116 Initialization is done in two levels. The first, done by basicdieinfo(),
117 just initializes those fields that are vital to deciding whether or not
118 to use this DIE, how to skip past it, etc. The second, done by the
119 function completedieinfo(), fills in the rest of the information.
121 Attributes which have block forms are not interpreted at the time
122 the DIE is scanned, instead we just save pointers to the start
123 of their value fields.
125 Some fields have a flag <name>_p that is set when the value of the
126 field is valid (I.E. we found a matching attribute in the DIE). Since
127 we may want to test for the presence of some attributes in the DIE,
128 such as AT_low_pc, without restricting the values of the field,
129 we need someway to note that we found such an attribute.
136 char * die
; /* Pointer to the raw DIE data */
137 long dielength
; /* Length of the raw DIE data */
138 DIEREF dieref
; /* Offset of this DIE */
139 short dietag
; /* Tag for this DIE */
144 unsigned short at_fund_type
;
145 BLOCK
* at_mod_fund_type
;
146 long at_user_def_type
;
147 BLOCK
* at_mod_u_d_type
;
149 BLOCK
* at_subscr_data
;
153 BLOCK
* at_element_list
;
160 BLOCK
* at_discr_value
;
163 BLOCK
* at_string_length
;
171 unsigned int has_at_low_pc
:1;
172 unsigned int has_at_stmt_list
:1;
173 unsigned int short_element_list
:1;
176 static int diecount
; /* Approximate count of dies for compilation unit */
177 static struct dieinfo
*curdie
; /* For warnings and such */
179 static char *dbbase
; /* Base pointer to dwarf info */
180 static int dbroff
; /* Relative offset from start of .debug section */
181 static char *lnbase
; /* Base pointer to line section */
182 static int isreg
; /* Kludge to identify register variables */
183 static int offreg
; /* Kludge to identify basereg references */
185 static CORE_ADDR baseaddr
; /* Add to each symbol value */
187 /* Each partial symbol table entry contains a pointer to private data for the
188 read_symtab() function to use when expanding a partial symbol table entry
189 to a full symbol table entry. For DWARF debugging info, this data is
190 contained in the following structure and macros are provided for easy
191 access to the members given a pointer to a partial symbol table entry.
193 dbfoff Always the absolute file offset to the start of the ".debug"
194 section for the file containing the DIE's being accessed.
196 dbroff Relative offset from the start of the ".debug" access to the
197 first DIE to be accessed. When building the partial symbol
198 table, this value will be zero since we are accessing the
199 entire ".debug" section. When expanding a partial symbol
200 table entry, this value will be the offset to the first
201 DIE for the compilation unit containing the symbol that
202 triggers the expansion.
204 dblength The size of the chunk of DIE's being examined, in bytes.
206 lnfoff The absolute file offset to the line table fragment. Ignored
207 when building partial symbol tables, but used when expanding
208 them, and contains the absolute file offset to the fragment
209 of the ".line" section containing the line numbers for the
210 current compilation unit.
214 int dbfoff
; /* Absolute file offset to start of .debug section */
215 int dbroff
; /* Relative offset from start of .debug section */
216 int dblength
; /* Size of the chunk of DIE's being examined */
217 int lnfoff
; /* Absolute file offset to line table fragment */
220 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
221 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
222 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
223 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
225 /* The generic symbol table building routines have separate lists for
226 file scope symbols and all all other scopes (local scopes). So
227 we need to select the right one to pass to add_symbol_to_list().
228 We do it by keeping a pointer to the correct list in list_in_scope.
230 FIXME: The original dwarf code just treated the file scope as the first
231 local scope, and all other local scopes as nested local scopes, and worked
232 fine. Check to see if we really need to distinguish these in buildsym.c */
234 struct pending
**list_in_scope
= &file_symbols
;
236 /* DIES which have user defined types or modified user defined types refer to
237 other DIES for the type information. Thus we need to associate the offset
238 of a DIE for a user defined type with a pointer to the type information.
240 Originally this was done using a simple but expensive algorithm, with an
241 array of unsorted structures, each containing an offset/type-pointer pair.
242 This array was scanned linearly each time a lookup was done. The result
243 was that gdb was spending over half it's startup time munging through this
244 array of pointers looking for a structure that had the right offset member.
246 The second attempt used the same array of structures, but the array was
247 sorted using qsort each time a new offset/type was recorded, and a binary
248 search was used to find the type pointer for a given DIE offset. This was
249 even slower, due to the overhead of sorting the array each time a new
250 offset/type pair was entered.
252 The third attempt uses a fixed size array of type pointers, indexed by a
253 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
254 we can divide any DIE offset by 4 to obtain a unique index into this fixed
255 size array. Since each element is a 4 byte pointer, it takes exactly as
256 much memory to hold this array as to hold the DWARF info for a given
257 compilation unit. But it gets freed as soon as we are done with it. */
259 static struct type
**utypes
; /* Pointer to array of user type pointers */
260 static int numutypes
; /* Max number of user type pointers */
262 /* Forward declarations of static functions so we don't have to worry
263 about ordering within this file. */
266 swapin
PARAMS ((char *, char *, int, struct objfile
*));
269 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
272 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
275 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
278 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
285 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
288 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
289 unsigned int, struct objfile
*));
292 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
295 init_psymbol_list
PARAMS ((struct objfile
*, int));
298 basicdieinfo
PARAMS ((struct dieinfo
*, char *, struct objfile
*));
301 completedieinfo
PARAMS ((struct dieinfo
*, struct objfile
*));
304 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
307 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
309 static struct symtab
*
310 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
313 process_dies
PARAMS ((char *, char *, struct objfile
*));
316 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
320 decode_array_element_type
PARAMS ((char *));
323 decode_subscr_data
PARAMS ((char *, char *));
326 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
329 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
332 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
335 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
338 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
341 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
344 decode_line_numbers
PARAMS ((char *));
347 decode_die_type
PARAMS ((struct dieinfo
*));
350 decode_mod_fund_type
PARAMS ((char *));
353 decode_mod_u_d_type
PARAMS ((char *));
356 decode_modified_type
PARAMS ((unsigned char *, unsigned int, int));
359 decode_fund_type
PARAMS ((unsigned int));
362 create_name
PARAMS ((char *, struct obstack
*));
365 lookup_utype
PARAMS ((DIEREF
));
368 alloc_utype
PARAMS ((DIEREF
, struct type
*));
370 static struct symbol
*
371 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
374 locval
PARAMS ((char *));
377 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
384 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
388 void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr,
389 int mainline, unsigned int dbfoff, unsigned int dbsize,
390 unsigned int lnoffset, unsigned int lnsize,
391 struct objfile *objfile)
395 This function is called upon to build partial symtabs from files
396 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
398 It is passed a file descriptor for an open file containing the DIES
399 and line number information, the corresponding filename for that
400 file, a base address for relocating the symbols, a flag indicating
401 whether or not this debugging information is from a "main symbol
402 table" rather than a shared library or dynamically linked file,
403 and file offset/size pairs for the DIE information and line number
413 dwarf_build_psymtabs (desc
, filename
, addr
, mainline
, dbfoff
, dbsize
,
414 lnoffset
, lnsize
, objfile
)
421 unsigned int lnoffset
;
423 struct objfile
*objfile
;
425 struct cleanup
*back_to
;
427 current_objfile
= objfile
;
428 dbbase
= xmalloc (dbsize
);
430 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
431 (read (desc
, dbbase
, dbsize
) != dbsize
))
434 error ("can't read DWARF data from '%s'", filename
);
436 back_to
= make_cleanup (free
, dbbase
);
438 /* If we are reinitializing, or if we have never loaded syms yet, init.
439 Since we have no idea how many DIES we are looking at, we just guess
440 some arbitrary value. */
442 if (mainline
|| objfile
->global_psymbols
.size
== 0 || objfile
->static_psymbols
.size
== 0)
444 init_psymbol_list (objfile
, 1024);
447 /* Save the relocation factor where everybody can see it. */
451 /* Follow the compilation unit sibling chain, building a partial symbol
452 table entry for each one. Save enough information about each compilation
453 unit to locate the full DWARF information later. */
455 scan_compilation_units (filename
, dbbase
, dbbase
+ dbsize
,
456 dbfoff
, lnoffset
, objfile
);
458 do_cleanups (back_to
);
459 current_objfile
= NULL
;
467 record_minimal_symbol -- add entry to gdb's minimal symbol table
471 static void record_minimal_symbol (char *name, CORE_ADDR address,
472 enum minimal_symbol_type ms_type,
473 struct objfile *objfile)
477 Given a pointer to the name of a symbol that should be added to the
478 minimal symbol table, and the address associated with that
479 symbol, records this information for later use in building the
480 minimal symbol table.
485 record_minimal_symbol (name
, address
, ms_type
, objfile
)
488 enum minimal_symbol_type ms_type
;
489 struct objfile
*objfile
;
491 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
492 prim_record_minimal_symbol (name
, address
, ms_type
);
499 dwarfwarn -- issue a DWARF related warning
503 Issue warnings about DWARF related things that aren't serious enough
504 to warrant aborting with an error, but should not be ignored either.
505 This includes things like detectable corruption in DIE's, missing
506 DIE's, unimplemented features, etc.
508 In general, running across tags or attributes that we don't recognize
509 is not considered to be a problem and we should not issue warnings
514 We mostly follow the example of the error() routine, but without
515 returning to command level. It is arguable about whether warnings
516 should be issued at all, and if so, where they should go (stdout or
519 We assume that curdie is valid and contains at least the basic
520 information for the DIE where the problem was noticed.
531 fmt
= va_arg (ap
, char *);
533 fprintf (stderr
, "warning: DWARF ref 0x%x: ", curdie
-> dieref
);
534 if (curdie
-> at_name
)
536 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
538 vfprintf (stderr
, fmt
, ap
);
539 fprintf (stderr
, "\n");
548 read_lexical_block_scope -- process all dies in a lexical block
552 static void read_lexical_block_scope (struct dieinfo *dip,
553 char *thisdie, char *enddie)
557 Process all the DIES contained within a lexical block scope.
558 Start a new scope, process the dies, and then close the scope.
563 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
567 struct objfile
*objfile
;
569 register struct context_stack
*new;
571 (void) push_context (0, dip
-> at_low_pc
);
572 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
573 new = pop_context ();
574 if (local_symbols
!= NULL
)
576 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
577 dip
-> at_high_pc
, objfile
);
579 local_symbols
= new -> locals
;
586 lookup_utype -- look up a user defined type from die reference
590 static type *lookup_utype (DIEREF dieref)
594 Given a DIE reference, lookup the user defined type associated with
595 that DIE, if it has been registered already. If not registered, then
596 return NULL. Alloc_utype() can be called to register an empty
597 type for this reference, which will be filled in later when the
598 actual referenced DIE is processed.
602 lookup_utype (dieref
)
605 struct type
*type
= NULL
;
608 utypeidx
= (dieref
- dbroff
) / 4;
609 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
611 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
615 type
= *(utypes
+ utypeidx
);
625 alloc_utype -- add a user defined type for die reference
629 static type *alloc_utype (DIEREF dieref, struct type *utypep)
633 Given a die reference DIEREF, and a possible pointer to a user
634 defined type UTYPEP, register that this reference has a user
635 defined type and either use the specified type in UTYPEP or
636 make a new empty type that will be filled in later.
638 We should only be called after calling lookup_utype() to verify that
639 there is not currently a type registered for DIEREF.
643 alloc_utype (dieref
, utypep
)
650 utypeidx
= (dieref
- dbroff
) / 4;
651 typep
= utypes
+ utypeidx
;
652 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
654 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
655 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
657 else if (*typep
!= NULL
)
660 SQUAWK (("internal error: dup user type allocation"));
666 utypep
= (struct type
*)
667 obstack_alloc (¤t_objfile
-> type_obstack
,
668 sizeof (struct type
));
669 (void) memset (utypep
, 0, sizeof (struct type
));
670 TYPE_OBJFILE (utypep
) = current_objfile
;
681 decode_die_type -- return a type for a specified die
685 static struct type *decode_die_type (struct dieinfo *dip)
689 Given a pointer to a die information structure DIP, decode the
690 type of the die and return a pointer to the decoded type. All
691 dies without specific types default to type int.
695 decode_die_type (dip
)
698 struct type
*type
= NULL
;
700 if (dip
-> at_fund_type
!= 0)
702 type
= decode_fund_type (dip
-> at_fund_type
);
704 else if (dip
-> at_mod_fund_type
!= NULL
)
706 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
708 else if (dip
-> at_user_def_type
)
710 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
712 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
715 else if (dip
-> at_mod_u_d_type
)
717 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
721 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
730 struct_type -- compute and return the type for a struct or union
734 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
735 char *enddie, struct objfile *objfile)
739 Given pointer to a die information structure for a die which
740 defines a union or structure (and MUST define one or the other),
741 and pointers to the raw die data that define the range of dies which
742 define the members, compute and return the user defined type for the
747 struct_type (dip
, thisdie
, enddie
, objfile
)
751 struct objfile
*objfile
;
755 struct nextfield
*next
;
758 struct nextfield
*list
= NULL
;
759 struct nextfield
*new;
766 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
768 /* No forward references created an empty type, so install one now */
769 type
= alloc_utype (dip
-> dieref
, NULL
);
771 INIT_CPLUS_SPECIFIC(type
);
772 switch (dip
-> dietag
)
774 case TAG_structure_type
:
775 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
779 TYPE_CODE (type
) = TYPE_CODE_UNION
;
783 /* Should never happen */
784 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
786 SQUAWK (("missing structure or union tag"));
789 /* Some compilers try to be helpful by inventing "fake" names for
790 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
791 Thanks, but no thanks... */
792 if (dip
-> at_name
!= NULL
793 && *dip
-> at_name
!= '~'
794 && *dip
-> at_name
!= '.')
796 TYPE_NAME (type
) = obconcat (&objfile
-> type_obstack
,
797 tpart1
, " ", dip
-> at_name
);
799 if (dip
-> at_byte_size
!= 0)
801 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
803 thisdie
+= dip
-> dielength
;
804 while (thisdie
< enddie
)
806 basicdieinfo (&mbr
, thisdie
, objfile
);
807 completedieinfo (&mbr
, objfile
);
808 if (mbr
.dielength
<= sizeof (long))
812 else if (mbr
.at_sibling
!= 0)
814 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
818 nextdie
= thisdie
+ mbr
.dielength
;
823 /* Get space to record the next field's data. */
824 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
828 list
-> field
.name
= savestring (mbr
.at_name
, strlen (mbr
.at_name
));
829 list
-> field
.type
= decode_die_type (&mbr
);
830 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
831 list
-> field
.bitsize
= 0;
835 process_dies (thisdie
, nextdie
, objfile
);
840 /* Now create the vector of fields, and record how big it is. We may
841 not even have any fields, if this DIE was generated due to a reference
842 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
843 set, which clues gdb in to the fact that it needs to search elsewhere
844 for the full structure definition. */
847 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
851 TYPE_NFIELDS (type
) = nfields
;
852 TYPE_FIELDS (type
) = (struct field
*)
853 obstack_alloc (&objfile
-> type_obstack
,
854 sizeof (struct field
) * nfields
);
855 /* Copy the saved-up fields into the field vector. */
856 for (n
= nfields
; list
; list
= list
-> next
)
858 TYPE_FIELD (type
, --n
) = list
-> field
;
868 read_structure_scope -- process all dies within struct or union
872 static void read_structure_scope (struct dieinfo *dip,
873 char *thisdie, char *enddie, struct objfile *objfile)
877 Called when we find the DIE that starts a structure or union
878 scope (definition) to process all dies that define the members
879 of the structure or union. DIP is a pointer to the die info
880 struct for the DIE that names the structure or union.
884 Note that we need to call struct_type regardless of whether or not
885 the DIE has an at_name attribute, since it might be an anonymous
886 structure or union. This gets the type entered into our set of
889 However, if the structure is incomplete (an opaque struct/union)
890 then suppress creating a symbol table entry for it since gdb only
891 wants to find the one with the complete definition. Note that if
892 it is complete, we just call new_symbol, which does it's own
893 checking about whether the struct/union is anonymous or not (and
894 suppresses creating a symbol table entry itself).
899 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
903 struct objfile
*objfile
;
908 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
909 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
911 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
913 SYMBOL_TYPE (sym
) = type
;
922 decode_array_element_type -- decode type of the array elements
926 static struct type *decode_array_element_type (char *scan, char *end)
930 As the last step in decoding the array subscript information for an
931 array DIE, we need to decode the type of the array elements. We are
932 passed a pointer to this last part of the subscript information and
933 must return the appropriate type. If the type attribute is not
934 recognized, just warn about the problem and return type int.
938 decode_array_element_type (scan
)
944 unsigned short fundtype
;
946 /* FIXME, does this confuse the host and target sizeof's? --gnu */
947 SWAPIN (attribute
, scan
, current_objfile
);
948 scan
+= sizeof (short);
952 SWAPIN (fundtype
, scan
, current_objfile
);
953 typep
= decode_fund_type (fundtype
);
955 case AT_mod_fund_type
:
956 typep
= decode_mod_fund_type (scan
);
958 case AT_user_def_type
:
959 SWAPIN (dieref
, scan
, current_objfile
);
960 if ((typep
= lookup_utype (dieref
)) == NULL
)
962 typep
= alloc_utype (dieref
, NULL
);
965 case AT_mod_u_d_type
:
966 typep
= decode_mod_u_d_type (scan
);
969 SQUAWK (("bad array element type attribute 0x%x", attribute
));
970 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
980 decode_subscr_data -- decode array subscript and element type data
984 static struct type *decode_subscr_data (char *scan, char *end)
988 The array subscripts and the data type of the elements of an
989 array are described by a list of data items, stored as a block
990 of contiguous bytes. There is a data item describing each array
991 dimension, and a final data item describing the element type.
992 The data items are ordered the same as their appearance in the
993 source (I.E. leftmost dimension first, next to leftmost second,
996 We are passed a pointer to the start of the block of bytes
997 containing the data items, and a pointer to the first byte past
998 the data. This function decodes the data and returns a type.
1001 FIXME: This code only implements the forms currently used
1002 by the AT&T and GNU C compilers.
1004 The end pointer is supplied for error checking, maybe we should
1008 static struct type
*
1009 decode_subscr_data (scan
, end
)
1013 struct type
*typep
= NULL
;
1014 struct type
*nexttype
;
1024 typep
= decode_array_element_type (scan
);
1027 SWAPIN (fundtype
, scan
, current_objfile
);
1028 scan
+= sizeof (short);
1029 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1030 && fundtype
!= FT_unsigned_integer
)
1032 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1037 SWAPIN (lowbound
, scan
, current_objfile
);
1038 scan
+= sizeof (long);
1039 SWAPIN (highbound
, scan
, current_objfile
);
1040 scan
+= sizeof (long);
1041 nexttype
= decode_subscr_data (scan
, end
);
1042 if (nexttype
!= NULL
)
1044 typep
= (struct type
*)
1045 obstack_alloc (¤t_objfile
-> type_obstack
,
1046 sizeof (struct type
));
1047 (void) memset (typep
, 0, sizeof (struct type
));
1048 TYPE_OBJFILE (typep
) = current_objfile
;
1049 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1050 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1051 TYPE_LENGTH (typep
) *= lowbound
+ highbound
+ 1;
1052 TYPE_TARGET_TYPE (typep
) = nexttype
;
1063 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1066 SQUAWK (("unknown array subscript format %x", format
));
1076 dwarf_read_array_type -- read TAG_array_type DIE
1080 static void dwarf_read_array_type (struct dieinfo *dip)
1084 Extract all information from a TAG_array_type DIE and add to
1085 the user defined type vector.
1089 dwarf_read_array_type (dip
)
1090 struct dieinfo
*dip
;
1098 if (dip
-> at_ordering
!= ORD_row_major
)
1100 /* FIXME: Can gdb even handle column major arrays? */
1101 SQUAWK (("array not row major; not handled correctly"));
1103 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1105 SWAPIN (temp
, sub
, current_objfile
);
1106 subend
= sub
+ sizeof (short) + temp
;
1107 sub
+= sizeof (short);
1108 type
= decode_subscr_data (sub
, subend
);
1111 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1113 utype
= alloc_utype (dip
-> dieref
, NULL
);
1115 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1116 TYPE_TARGET_TYPE (utype
) =
1117 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1118 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1122 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1124 (void) alloc_utype (dip
-> dieref
, type
);
1128 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1129 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1130 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1140 read_tag_pointer_type -- read TAG_pointer_type DIE
1144 static void read_tag_pointer_type (struct dieinfo *dip)
1148 Extract all information from a TAG_pointer_type DIE and add to
1149 the user defined type vector.
1153 read_tag_pointer_type (dip
)
1154 struct dieinfo
*dip
;
1159 type
= decode_die_type (dip
);
1160 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1162 utype
= lookup_pointer_type (type
);
1163 (void) alloc_utype (dip
-> dieref
, utype
);
1167 TYPE_TARGET_TYPE (utype
) = type
;
1168 TYPE_POINTER_TYPE (type
) = utype
;
1170 /* We assume the machine has only one representation for pointers! */
1171 /* FIXME: This confuses host<->target data representations, and is a
1172 poor assumption besides. */
1174 TYPE_LENGTH (utype
) = sizeof (char *);
1175 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1183 read_subroutine_type -- process TAG_subroutine_type dies
1187 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1192 Handle DIES due to C code like:
1195 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1201 The parameter DIES are currently ignored. See if gdb has a way to
1202 include this info in it's type system, and decode them if so. Is
1203 this what the type structure's "arg_types" field is for? (FIXME)
1207 read_subroutine_type (dip
, thisdie
, enddie
)
1208 struct dieinfo
*dip
;
1212 struct type
*type
; /* Type that this function returns */
1213 struct type
*ftype
; /* Function that returns above type */
1215 /* Decode the type that this subroutine returns */
1217 type
= decode_die_type (dip
);
1219 /* Check to see if we already have a partially constructed user
1220 defined type for this DIE, from a forward reference. */
1222 if ((ftype
= lookup_utype (dip
-> dieref
)) == NULL
)
1224 /* This is the first reference to one of these types. Make
1225 a new one and place it in the user defined types. */
1226 ftype
= lookup_function_type (type
);
1227 (void) alloc_utype (dip
-> dieref
, ftype
);
1231 /* We have an existing partially constructed type, so bash it
1232 into the correct type. */
1233 TYPE_TARGET_TYPE (ftype
) = type
;
1234 TYPE_FUNCTION_TYPE (type
) = ftype
;
1235 TYPE_LENGTH (ftype
) = 1;
1236 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1244 read_enumeration -- process dies which define an enumeration
1248 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1249 char *enddie, struct objfile *objfile)
1253 Given a pointer to a die which begins an enumeration, process all
1254 the dies that define the members of the enumeration.
1258 Note that we need to call enum_type regardless of whether or not we
1259 have a symbol, since we might have an enum without a tag name (thus
1260 no symbol for the tagname).
1264 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1265 struct dieinfo
*dip
;
1268 struct objfile
*objfile
;
1273 type
= enum_type (dip
, objfile
);
1274 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1276 SYMBOL_TYPE (sym
) = type
;
1284 enum_type -- decode and return a type for an enumeration
1288 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1292 Given a pointer to a die information structure for the die which
1293 starts an enumeration, process all the dies that define the members
1294 of the enumeration and return a type pointer for the enumeration.
1296 At the same time, for each member of the enumeration, create a
1297 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1298 and give it the type of the enumeration itself.
1302 Note that the DWARF specification explicitly mandates that enum
1303 constants occur in reverse order from the source program order,
1304 for "consistency" and because this ordering is easier for many
1305 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1306 Entries). Because gdb wants to see the enum members in program
1307 source order, we have to ensure that the order gets reversed while
1308 we are processing them.
1311 static struct type
*
1312 enum_type (dip
, objfile
)
1313 struct dieinfo
*dip
;
1314 struct objfile
*objfile
;
1318 struct nextfield
*next
;
1321 struct nextfield
*list
= NULL
;
1322 struct nextfield
*new;
1331 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
1333 /* No forward references created an empty type, so install one now */
1334 type
= alloc_utype (dip
-> dieref
, NULL
);
1336 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1337 /* Some compilers try to be helpful by inventing "fake" names for
1338 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1339 Thanks, but no thanks... */
1340 if (dip
-> at_name
!= NULL
1341 && *dip
-> at_name
!= '~'
1342 && *dip
-> at_name
!= '.')
1344 TYPE_NAME (type
) = obconcat (&objfile
-> type_obstack
, "enum",
1345 " ", dip
-> at_name
);
1347 if (dip
-> at_byte_size
!= 0)
1349 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1351 if ((scan
= dip
-> at_element_list
) != NULL
)
1353 if (dip
-> short_element_list
)
1355 SWAPIN (stemp
, scan
, objfile
);
1356 listend
= scan
+ stemp
+ sizeof (stemp
);
1357 scan
+= sizeof (stemp
);
1361 SWAPIN (ltemp
, scan
, objfile
);
1362 listend
= scan
+ ltemp
+ sizeof (ltemp
);
1363 scan
+= sizeof (ltemp
);
1365 while (scan
< listend
)
1367 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1370 list
-> field
.type
= NULL
;
1371 list
-> field
.bitsize
= 0;
1372 SWAPIN (list
-> field
.bitpos
, scan
, objfile
);
1373 scan
+= sizeof (long);
1374 list
-> field
.name
= savestring (scan
, strlen (scan
));
1375 scan
+= strlen (scan
) + 1;
1377 /* Handcraft a new symbol for this enum member. */
1378 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1379 sizeof (struct symbol
));
1380 (void) memset (sym
, 0, sizeof (struct symbol
));
1381 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
, &objfile
->symbol_obstack
);
1382 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1383 SYMBOL_CLASS (sym
) = LOC_CONST
;
1384 SYMBOL_TYPE (sym
) = type
;
1385 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1386 add_symbol_to_list (sym
, list_in_scope
);
1388 /* Now create the vector of fields, and record how big it is. This is
1389 where we reverse the order, by pulling the members of the list in
1390 reverse order from how they were inserted. If we have no fields
1391 (this is apparently possible in C++) then skip building a field
1395 TYPE_NFIELDS (type
) = nfields
;
1396 TYPE_FIELDS (type
) = (struct field
*)
1397 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1398 /* Copy the saved-up fields into the field vector. */
1399 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1401 TYPE_FIELD (type
, n
++) = list
-> field
;
1412 read_func_scope -- process all dies within a function scope
1416 Process all dies within a given function scope. We are passed
1417 a die information structure pointer DIP for the die which
1418 starts the function scope, and pointers into the raw die data
1419 that define the dies within the function scope.
1421 For now, we ignore lexical block scopes within the function.
1422 The problem is that AT&T cc does not define a DWARF lexical
1423 block scope for the function itself, while gcc defines a
1424 lexical block scope for the function. We need to think about
1425 how to handle this difference, or if it is even a problem.
1430 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1431 struct dieinfo
*dip
;
1434 struct objfile
*objfile
;
1436 register struct context_stack
*new;
1438 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1439 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1441 objfile
-> ei
.entry_func_lowpc
= dip
-> at_low_pc
;
1442 objfile
-> ei
.entry_func_highpc
= dip
-> at_high_pc
;
1444 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1446 objfile
-> ei
.main_func_lowpc
= dip
-> at_low_pc
;
1447 objfile
-> ei
.main_func_highpc
= dip
-> at_high_pc
;
1449 new = push_context (0, dip
-> at_low_pc
);
1450 new -> name
= new_symbol (dip
, objfile
);
1451 list_in_scope
= &local_symbols
;
1452 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1453 new = pop_context ();
1454 /* Make a block for the local symbols within. */
1455 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1456 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1457 list_in_scope
= &file_symbols
;
1464 read_file_scope -- process all dies within a file scope
1468 Process all dies within a given file scope. We are passed a
1469 pointer to the die information structure for the die which
1470 starts the file scope, and pointers into the raw die data which
1471 mark the range of dies within the file scope.
1473 When the partial symbol table is built, the file offset for the line
1474 number table for each compilation unit is saved in the partial symbol
1475 table entry for that compilation unit. As the symbols for each
1476 compilation unit are read, the line number table is read into memory
1477 and the variable lnbase is set to point to it. Thus all we have to
1478 do is use lnbase to access the line number table for the current
1483 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1484 struct dieinfo
*dip
;
1487 struct objfile
*objfile
;
1489 struct cleanup
*back_to
;
1490 struct symtab
*symtab
;
1492 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1493 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1495 objfile
-> ei
.entry_file_lowpc
= dip
-> at_low_pc
;
1496 objfile
-> ei
.entry_file_highpc
= dip
-> at_high_pc
;
1498 if (dip
-> at_producer
!= NULL
)
1500 processing_gcc_compilation
=
1501 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1503 numutypes
= (enddie
- thisdie
) / 4;
1504 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1505 back_to
= make_cleanup (free
, utypes
);
1506 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1507 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1508 decode_line_numbers (lnbase
);
1509 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1510 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1511 /* FIXME: The following may need to be expanded for other languages */
1512 switch (dip
-> at_language
)
1516 symtab
-> language
= language_c
;
1518 case LANG_C_PLUS_PLUS
:
1519 symtab
-> language
= language_cplus
;
1524 do_cleanups (back_to
);
1533 process_dies -- process a range of DWARF Information Entries
1537 static void process_dies (char *thisdie, char *enddie,
1538 struct objfile *objfile)
1542 Process all DIE's in a specified range. May be (and almost
1543 certainly will be) called recursively.
1547 process_dies (thisdie
, enddie
, objfile
)
1550 struct objfile
*objfile
;
1555 while (thisdie
< enddie
)
1557 basicdieinfo (&di
, thisdie
, objfile
);
1558 if (di
.dielength
< sizeof (long))
1562 else if (di
.dietag
== TAG_padding
)
1564 nextdie
= thisdie
+ di
.dielength
;
1568 completedieinfo (&di
, objfile
);
1569 if (di
.at_sibling
!= 0)
1571 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1575 nextdie
= thisdie
+ di
.dielength
;
1579 case TAG_compile_unit
:
1580 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1582 case TAG_global_subroutine
:
1583 case TAG_subroutine
:
1584 if (di
.has_at_low_pc
)
1586 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1589 case TAG_lexical_block
:
1590 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1592 case TAG_structure_type
:
1593 case TAG_union_type
:
1594 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1596 case TAG_enumeration_type
:
1597 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1599 case TAG_subroutine_type
:
1600 read_subroutine_type (&di
, thisdie
, nextdie
);
1602 case TAG_array_type
:
1603 dwarf_read_array_type (&di
);
1605 case TAG_pointer_type
:
1606 read_tag_pointer_type (&di
);
1609 (void) new_symbol (&di
, objfile
);
1621 decode_line_numbers -- decode a line number table fragment
1625 static void decode_line_numbers (char *tblscan, char *tblend,
1626 long length, long base, long line, long pc)
1630 Translate the DWARF line number information to gdb form.
1632 The ".line" section contains one or more line number tables, one for
1633 each ".line" section from the objects that were linked.
1635 The AT_stmt_list attribute for each TAG_source_file entry in the
1636 ".debug" section contains the offset into the ".line" section for the
1637 start of the table for that file.
1639 The table itself has the following structure:
1641 <table length><base address><source statement entry>
1642 4 bytes 4 bytes 10 bytes
1644 The table length is the total size of the table, including the 4 bytes
1645 for the length information.
1647 The base address is the address of the first instruction generated
1648 for the source file.
1650 Each source statement entry has the following structure:
1652 <line number><statement position><address delta>
1653 4 bytes 2 bytes 4 bytes
1655 The line number is relative to the start of the file, starting with
1658 The statement position either -1 (0xFFFF) or the number of characters
1659 from the beginning of the line to the beginning of the statement.
1661 The address delta is the difference between the base address and
1662 the address of the first instruction for the statement.
1664 Note that we must copy the bytes from the packed table to our local
1665 variables before attempting to use them, to avoid alignment problems
1666 on some machines, particularly RISC processors.
1670 Does gdb expect the line numbers to be sorted? They are now by
1671 chance/luck, but are not required to be. (FIXME)
1673 The line with number 0 is unused, gdb apparently can discover the
1674 span of the last line some other way. How? (FIXME)
1678 decode_line_numbers (linetable
)
1688 if (linetable
!= NULL
)
1690 tblscan
= tblend
= linetable
;
1691 SWAPIN (length
, tblscan
, current_objfile
);
1692 tblscan
+= sizeof (long);
1694 SWAPIN (base
, tblscan
, current_objfile
);
1696 tblscan
+= sizeof (long);
1697 while (tblscan
< tblend
)
1699 SWAPIN (line
, tblscan
, current_objfile
);
1700 tblscan
+= sizeof (long) + sizeof (short);
1701 SWAPIN (pc
, tblscan
, current_objfile
);
1702 tblscan
+= sizeof (long);
1706 record_line (current_subfile
, line
, pc
);
1716 locval -- compute the value of a location attribute
1720 static int locval (char *loc)
1724 Given pointer to a string of bytes that define a location, compute
1725 the location and return the value.
1727 When computing values involving the current value of the frame pointer,
1728 the value zero is used, which results in a value relative to the frame
1729 pointer, rather than the absolute value. This is what GDB wants
1732 When the result is a register number, the global isreg flag is set,
1733 otherwise it is cleared. This is a kludge until we figure out a better
1734 way to handle the problem. Gdb's design does not mesh well with the
1735 DWARF notion of a location computing interpreter, which is a shame
1736 because the flexibility goes unused.
1740 Note that stack[0] is unused except as a default error return.
1741 Note that stack overflow is not yet handled.
1748 unsigned short nbytes
;
1754 SWAPIN (nbytes
, loc
, current_objfile
);
1755 end
= loc
+ sizeof (short) + nbytes
;
1760 for (loc
+= sizeof (short); loc
< end
; loc
+= sizeof (long))
1768 /* push register (number) */
1770 SWAPIN (stack
[stacki
], loc
, current_objfile
);
1774 /* push value of register (number) */
1775 /* Actually, we compute the value as if register has 0 */
1777 SWAPIN (regno
, loc
, current_objfile
);
1780 stack
[++stacki
] = 0;
1784 stack
[++stacki
] = 0;
1785 SQUAWK (("BASEREG %d not handled!", regno
));
1789 /* push address (relocated address) */
1791 SWAPIN (stack
[stacki
], loc
, current_objfile
);
1794 /* push constant (number) */
1796 SWAPIN (stack
[stacki
], loc
, current_objfile
);
1799 /* pop, deref and push 2 bytes (as a long) */
1800 SQUAWK (("OP_DEREF2 address %#x not handled", stack
[stacki
]));
1802 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1803 SQUAWK (("OP_DEREF4 address %#x not handled", stack
[stacki
]));
1805 case OP_ADD
: /* pop top 2 items, add, push result */
1806 stack
[stacki
- 1] += stack
[stacki
];
1811 return (stack
[stacki
]);
1818 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1822 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1826 When expanding a partial symbol table entry to a full symbol table
1827 entry, this is the function that gets called to read in the symbols
1828 for the compilation unit.
1830 Returns a pointer to the newly constructed symtab (which is now
1831 the new first one on the objfile's symtab list).
1834 static struct symtab
*
1835 read_ofile_symtab (pst
)
1836 struct partial_symtab
*pst
;
1838 struct cleanup
*back_to
;
1843 abfd
= pst
-> objfile
-> obfd
;
1844 current_objfile
= pst
-> objfile
;
1846 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1847 unit, seek to the location in the file, and read in all the DIE's. */
1850 dbbase
= xmalloc (DBLENGTH(pst
));
1851 dbroff
= DBROFF(pst
);
1852 foffset
= DBFOFF(pst
) + dbroff
;
1853 baseaddr
= pst
-> addr
;
1854 if (bfd_seek (abfd
, foffset
, 0) ||
1855 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1858 error ("can't read DWARF data");
1860 back_to
= make_cleanup (free
, dbbase
);
1862 /* If there is a line number table associated with this compilation unit
1863 then read the first long word from the line number table fragment, which
1864 contains the size of the fragment in bytes (including the long word
1865 itself). Allocate a buffer for the fragment and read it in for future
1871 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1872 (bfd_read ((PTR
)&lnsize
, sizeof(long), 1, abfd
) != sizeof(long)))
1874 error ("can't read DWARF line number table size");
1876 lnsize
= bfd_h_get_32 (abfd
, (unsigned char *) &lnsize
);
1877 lnbase
= xmalloc (lnsize
);
1878 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1879 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1882 error ("can't read DWARF line numbers");
1884 make_cleanup (free
, lnbase
);
1887 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1888 do_cleanups (back_to
);
1889 current_objfile
= NULL
;
1890 return (pst
-> objfile
-> symtabs
);
1897 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1901 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1905 Called once for each partial symbol table entry that needs to be
1906 expanded into a full symbol table entry.
1911 psymtab_to_symtab_1 (pst
)
1912 struct partial_symtab
*pst
;
1920 warning ("psymtab for %s already read in. Shouldn't happen.",
1925 /* Read in all partial symtabs on which this one is dependent */
1926 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
1928 if (!pst
-> dependencies
[i
] -> readin
)
1930 /* Inform about additional files that need to be read in. */
1933 fputs_filtered (" ", stdout
);
1935 fputs_filtered ("and ", stdout
);
1937 printf_filtered ("%s...",
1938 pst
-> dependencies
[i
] -> filename
);
1940 fflush (stdout
); /* Flush output */
1942 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
1945 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
1947 pst
-> symtab
= read_ofile_symtab (pst
);
1950 printf_filtered ("%d DIE's, sorting...", diecount
);
1954 sort_symtab_syms (pst
-> symtab
);
1965 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
1969 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
1973 This is the DWARF support entry point for building a full symbol
1974 table entry from a partial symbol table entry. We are passed a
1975 pointer to the partial symbol table entry that needs to be expanded.
1980 dwarf_psymtab_to_symtab (pst
)
1981 struct partial_symtab
*pst
;
1988 warning ("psymtab for %s already read in. Shouldn't happen.",
1993 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
1995 /* Print the message now, before starting serious work, to avoid
1996 disconcerting pauses. */
1999 printf_filtered ("Reading in symbols for %s...",
2004 psymtab_to_symtab_1 (pst
);
2006 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2007 we need to do an equivalent or is this something peculiar to
2009 Match with global symbols. This only needs to be done once,
2010 after all of the symtabs and dependencies have been read in.
2012 scan_file_globals (pst
-> objfile
);
2015 /* Finish up the verbose info message. */
2018 printf_filtered ("done.\n");
2030 init_psymbol_list -- initialize storage for partial symbols
2034 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2038 Initializes storage for all of the partial symbols that will be
2039 created by dwarf_build_psymtabs and subsidiaries.
2043 init_psymbol_list (objfile
, total_symbols
)
2044 struct objfile
*objfile
;
2047 /* Free any previously allocated psymbol lists. */
2049 if (objfile
-> global_psymbols
.list
)
2051 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
2053 if (objfile
-> static_psymbols
.list
)
2055 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
2058 /* Current best guess is that there are approximately a twentieth
2059 of the total symbols (in a debugging file) are global or static
2062 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2063 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2064 objfile
-> global_psymbols
.next
=
2065 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2066 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
2067 * sizeof (struct partial_symbol
));
2068 objfile
-> static_psymbols
.next
=
2069 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2070 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
2071 * sizeof (struct partial_symbol
));
2078 add_enum_psymbol -- add enumeration members to partial symbol table
2082 Given pointer to a DIE that is known to be for an enumeration,
2083 extract the symbolic names of the enumeration members and add
2084 partial symbols for them.
2088 add_enum_psymbol (dip
, objfile
)
2089 struct dieinfo
*dip
;
2090 struct objfile
*objfile
;
2097 if ((scan
= dip
-> at_element_list
) != NULL
)
2099 if (dip
-> short_element_list
)
2101 SWAPIN (stemp
, scan
, objfile
);
2102 listend
= scan
+ stemp
+ sizeof (stemp
);
2103 scan
+= sizeof (stemp
);
2107 SWAPIN (ltemp
, scan
, objfile
);
2108 listend
= scan
+ ltemp
+ sizeof (ltemp
);
2109 scan
+= sizeof (ltemp
);
2111 while (scan
< listend
)
2113 scan
+= sizeof (long);
2114 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2115 objfile
-> static_psymbols
, 0);
2116 scan
+= strlen (scan
) + 1;
2125 add_partial_symbol -- add symbol to partial symbol table
2129 Given a DIE, if it is one of the types that we want to
2130 add to a partial symbol table, finish filling in the die info
2131 and then add a partial symbol table entry for it.
2136 add_partial_symbol (dip
, objfile
)
2137 struct dieinfo
*dip
;
2138 struct objfile
*objfile
;
2140 switch (dip
-> dietag
)
2142 case TAG_global_subroutine
:
2143 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2145 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2146 VAR_NAMESPACE
, LOC_BLOCK
,
2147 objfile
-> global_psymbols
,
2150 case TAG_global_variable
:
2151 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2153 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2154 VAR_NAMESPACE
, LOC_STATIC
,
2155 objfile
-> global_psymbols
,
2158 case TAG_subroutine
:
2159 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2160 VAR_NAMESPACE
, LOC_BLOCK
,
2161 objfile
-> static_psymbols
,
2164 case TAG_local_variable
:
2165 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2166 VAR_NAMESPACE
, LOC_STATIC
,
2167 objfile
-> static_psymbols
,
2171 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2172 VAR_NAMESPACE
, LOC_TYPEDEF
,
2173 objfile
-> static_psymbols
,
2176 case TAG_structure_type
:
2177 case TAG_union_type
:
2178 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2179 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2180 objfile
-> static_psymbols
,
2183 case TAG_enumeration_type
:
2186 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2187 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2188 objfile
-> static_psymbols
,
2191 add_enum_psymbol (dip
, objfile
);
2200 scan_partial_symbols -- scan DIE's within a single compilation unit
2204 Process the DIE's within a single compilation unit, looking for
2205 interesting DIE's that contribute to the partial symbol table entry
2206 for this compilation unit. Since we cannot follow any sibling
2207 chains without reading the complete DIE info for every DIE,
2208 it is probably faster to just sequentially check each one to
2209 see if it is one of the types we are interested in, and if so,
2210 then extract all the attributes info and generate a partial
2215 Don't attempt to add anonymous structures or unions since they have
2216 no name. Anonymous enumerations however are processed, because we
2217 want to extract their member names (the check for a tag name is
2220 Also, for variables and subroutines, check that this is the place
2221 where the actual definition occurs, rather than just a reference
2226 scan_partial_symbols (thisdie
, enddie
, objfile
)
2229 struct objfile
*objfile
;
2234 while (thisdie
< enddie
)
2236 basicdieinfo (&di
, thisdie
, objfile
);
2237 if (di
.dielength
< sizeof (long))
2243 nextdie
= thisdie
+ di
.dielength
;
2244 /* To avoid getting complete die information for every die, we
2245 only do it (below) for the cases we are interested in. */
2248 case TAG_global_subroutine
:
2249 case TAG_subroutine
:
2250 case TAG_global_variable
:
2251 case TAG_local_variable
:
2252 completedieinfo (&di
, objfile
);
2253 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2255 add_partial_symbol (&di
, objfile
);
2259 case TAG_structure_type
:
2260 case TAG_union_type
:
2261 completedieinfo (&di
, objfile
);
2264 add_partial_symbol (&di
, objfile
);
2267 case TAG_enumeration_type
:
2268 completedieinfo (&di
, objfile
);
2269 add_partial_symbol (&di
, objfile
);
2281 scan_compilation_units -- build a psymtab entry for each compilation
2285 This is the top level dwarf parsing routine for building partial
2288 It scans from the beginning of the DWARF table looking for the first
2289 TAG_compile_unit DIE, and then follows the sibling chain to locate
2290 each additional TAG_compile_unit DIE.
2292 For each TAG_compile_unit DIE it creates a partial symtab structure,
2293 calls a subordinate routine to collect all the compilation unit's
2294 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2295 new partial symtab structure into the partial symbol table. It also
2296 records the appropriate information in the partial symbol table entry
2297 to allow the chunk of DIE's and line number table for this compilation
2298 unit to be located and re-read later, to generate a complete symbol
2299 table entry for the compilation unit.
2301 Thus it effectively partitions up a chunk of DIE's for multiple
2302 compilation units into smaller DIE chunks and line number tables,
2303 and associates them with a partial symbol table entry.
2307 If any compilation unit has no line number table associated with
2308 it for some reason (a missing at_stmt_list attribute, rather than
2309 just one with a value of zero, which is valid) then we ensure that
2310 the recorded file offset is zero so that the routine which later
2311 reads line number table fragments knows that there is no fragment
2321 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2325 unsigned int dbfoff
;
2326 unsigned int lnoffset
;
2327 struct objfile
*objfile
;
2331 struct partial_symtab
*pst
;
2336 while (thisdie
< enddie
)
2338 basicdieinfo (&di
, thisdie
, objfile
);
2339 if (di
.dielength
< sizeof (long))
2343 else if (di
.dietag
!= TAG_compile_unit
)
2345 nextdie
= thisdie
+ di
.dielength
;
2349 completedieinfo (&di
, objfile
);
2350 if (di
.at_sibling
!= 0)
2352 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2356 nextdie
= thisdie
+ di
.dielength
;
2358 curoff
= thisdie
- dbbase
;
2359 culength
= nextdie
- thisdie
;
2360 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2362 /* First allocate a new partial symbol table structure */
2364 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2366 objfile
-> global_psymbols
.next
,
2367 objfile
-> static_psymbols
.next
);
2369 pst
-> texthigh
= di
.at_high_pc
;
2370 pst
-> read_symtab_private
= (char *)
2371 obstack_alloc (&objfile
-> psymbol_obstack
,
2372 sizeof (struct dwfinfo
));
2373 DBFOFF (pst
) = dbfoff
;
2374 DBROFF (pst
) = curoff
;
2375 DBLENGTH (pst
) = culength
;
2376 LNFOFF (pst
) = curlnoffset
;
2377 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2379 /* Now look for partial symbols */
2381 scan_partial_symbols (thisdie
+ di
.dielength
, nextdie
, objfile
);
2383 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2384 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2385 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2386 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2387 sort_pst_symbols (pst
);
2388 /* If there is already a psymtab or symtab for a file of this name,
2389 remove it. (If there is a symtab, more drastic things also
2390 happen.) This happens in VxWorks. */
2391 free_named_symtabs (pst
-> filename
);
2401 new_symbol -- make a symbol table entry for a new symbol
2405 static struct symbol *new_symbol (struct dieinfo *dip,
2406 struct objfile *objfile)
2410 Given a pointer to a DWARF information entry, figure out if we need
2411 to make a symbol table entry for it, and if so, create a new entry
2412 and return a pointer to it.
2415 static struct symbol
*
2416 new_symbol (dip
, objfile
)
2417 struct dieinfo
*dip
;
2418 struct objfile
*objfile
;
2420 struct symbol
*sym
= NULL
;
2422 if (dip
-> at_name
!= NULL
)
2424 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2425 sizeof (struct symbol
));
2426 (void) memset (sym
, 0, sizeof (struct symbol
));
2427 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2428 /* default assumptions */
2429 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2430 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2431 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2432 switch (dip
-> dietag
)
2435 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2436 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2438 case TAG_global_subroutine
:
2439 case TAG_subroutine
:
2440 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2441 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2442 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2443 if (dip
-> dietag
== TAG_global_subroutine
)
2445 add_symbol_to_list (sym
, &global_symbols
);
2449 add_symbol_to_list (sym
, list_in_scope
);
2452 case TAG_global_variable
:
2453 if (dip
-> at_location
!= NULL
)
2455 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2456 add_symbol_to_list (sym
, &global_symbols
);
2457 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2458 SYMBOL_VALUE (sym
) += baseaddr
;
2461 case TAG_local_variable
:
2462 if (dip
-> at_location
!= NULL
)
2464 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2465 add_symbol_to_list (sym
, list_in_scope
);
2468 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2472 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2476 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2477 SYMBOL_VALUE (sym
) += baseaddr
;
2481 case TAG_formal_parameter
:
2482 if (dip
-> at_location
!= NULL
)
2484 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2486 add_symbol_to_list (sym
, list_in_scope
);
2489 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2493 SYMBOL_CLASS (sym
) = LOC_ARG
;
2496 case TAG_unspecified_parameters
:
2497 /* From varargs functions; gdb doesn't seem to have any interest in
2498 this information, so just ignore it for now. (FIXME?) */
2500 case TAG_structure_type
:
2501 case TAG_union_type
:
2502 case TAG_enumeration_type
:
2503 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2504 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2505 add_symbol_to_list (sym
, list_in_scope
);
2508 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2509 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2510 add_symbol_to_list (sym
, list_in_scope
);
2513 /* Not a tag we recognize. Hopefully we aren't processing trash
2514 data, but since we must specifically ignore things we don't
2515 recognize, there is nothing else we should do at this point. */
2526 decode_mod_fund_type -- decode a modified fundamental type
2530 static struct type *decode_mod_fund_type (char *typedata)
2534 Decode a block of data containing a modified fundamental
2535 type specification. TYPEDATA is a pointer to the block,
2536 which consists of a two byte length, containing the size
2537 of the rest of the block. At the end of the block is a
2538 two byte value that gives the fundamental type. Everything
2539 in between are type modifiers.
2541 We simply compute the number of modifiers and call the general
2542 function decode_modified_type to do the actual work.
2545 static struct type
*
2546 decode_mod_fund_type (typedata
)
2549 struct type
*typep
= NULL
;
2550 unsigned short modcount
;
2551 unsigned char *modifiers
;
2553 /* Get the total size of the block, exclusive of the size itself */
2554 SWAPIN (modcount
, typedata
, current_objfile
);
2555 /* Deduct the size of the fundamental type bytes at the end of the block. */
2556 modcount
-= sizeof (short);
2557 /* Skip over the two size bytes at the beginning of the block. */
2558 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2559 /* Now do the actual decoding */
2560 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_fund_type
);
2568 decode_mod_u_d_type -- decode a modified user defined type
2572 static struct type *decode_mod_u_d_type (char *typedata)
2576 Decode a block of data containing a modified user defined
2577 type specification. TYPEDATA is a pointer to the block,
2578 which consists of a two byte length, containing the size
2579 of the rest of the block. At the end of the block is a
2580 four byte value that gives a reference to a user defined type.
2581 Everything in between are type modifiers.
2583 We simply compute the number of modifiers and call the general
2584 function decode_modified_type to do the actual work.
2587 static struct type
*
2588 decode_mod_u_d_type (typedata
)
2591 struct type
*typep
= NULL
;
2592 unsigned short modcount
;
2593 unsigned char *modifiers
;
2595 /* Get the total size of the block, exclusive of the size itself */
2596 SWAPIN (modcount
, typedata
, current_objfile
);
2597 /* Deduct the size of the reference type bytes at the end of the block. */
2598 modcount
-= sizeof (long);
2599 /* Skip over the two size bytes at the beginning of the block. */
2600 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2601 /* Now do the actual decoding */
2602 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_u_d_type
);
2610 decode_modified_type -- decode modified user or fundamental type
2614 static struct type *decode_modified_type (unsigned char *modifiers,
2615 unsigned short modcount, int mtype)
2619 Decode a modified type, either a modified fundamental type or
2620 a modified user defined type. MODIFIERS is a pointer to the
2621 block of bytes that define MODCOUNT modifiers. Immediately
2622 following the last modifier is a short containing the fundamental
2623 type or a long containing the reference to the user defined
2624 type. Which one is determined by MTYPE, which is either
2625 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2626 type we are generating.
2628 We call ourself recursively to generate each modified type,`
2629 until MODCOUNT reaches zero, at which point we have consumed
2630 all the modifiers and generate either the fundamental type or
2631 user defined type. When the recursion unwinds, each modifier
2632 is applied in turn to generate the full modified type.
2636 If we find a modifier that we don't recognize, and it is not one
2637 of those reserved for application specific use, then we issue a
2638 warning and simply ignore the modifier.
2642 We currently ignore MOD_const and MOD_volatile. (FIXME)
2646 static struct type
*
2647 decode_modified_type (modifiers
, modcount
, mtype
)
2648 unsigned char *modifiers
;
2649 unsigned int modcount
;
2652 struct type
*typep
= NULL
;
2653 unsigned short fundtype
;
2655 unsigned char modifier
;
2661 case AT_mod_fund_type
:
2662 SWAPIN (fundtype
, modifiers
, current_objfile
);
2663 typep
= decode_fund_type (fundtype
);
2665 case AT_mod_u_d_type
:
2666 SWAPIN (dieref
, modifiers
, current_objfile
);
2667 if ((typep
= lookup_utype (dieref
)) == NULL
)
2669 typep
= alloc_utype (dieref
, NULL
);
2673 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2674 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2680 modifier
= *modifiers
++;
2681 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2684 case MOD_pointer_to
:
2685 typep
= lookup_pointer_type (typep
);
2687 case MOD_reference_to
:
2688 typep
= lookup_reference_type (typep
);
2691 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2694 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2697 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2699 SQUAWK (("unknown type modifier %u", modifier
));
2711 decode_fund_type -- translate basic DWARF type to gdb base type
2715 Given an integer that is one of the fundamental DWARF types,
2716 translate it to one of the basic internal gdb types and return
2717 a pointer to the appropriate gdb type (a "struct type *").
2721 If we encounter a fundamental type that we are unprepared to
2722 deal with, and it is not in the range of those types defined
2723 as application specific types, then we issue a warning and
2724 treat the type as an "int".
2727 static struct type
*
2728 decode_fund_type (fundtype
)
2729 unsigned int fundtype
;
2731 struct type
*typep
= NULL
;
2737 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2740 case FT_boolean
: /* Was FT_set in AT&T version */
2741 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2744 case FT_pointer
: /* (void *) */
2745 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2746 typep
= lookup_pointer_type (typep
);
2750 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2753 case FT_signed_char
:
2754 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2757 case FT_unsigned_char
:
2758 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2762 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2765 case FT_signed_short
:
2766 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2769 case FT_unsigned_short
:
2770 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2774 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2777 case FT_signed_integer
:
2778 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2781 case FT_unsigned_integer
:
2782 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2786 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2789 case FT_signed_long
:
2790 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2793 case FT_unsigned_long
:
2794 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2798 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2801 case FT_signed_long_long
:
2802 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2805 case FT_unsigned_long_long
:
2806 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2810 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2813 case FT_dbl_prec_float
:
2814 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2817 case FT_ext_prec_float
:
2818 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2822 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2825 case FT_dbl_prec_complex
:
2826 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2829 case FT_ext_prec_complex
:
2830 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2835 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2837 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2838 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2848 create_name -- allocate a fresh copy of a string on an obstack
2852 Given a pointer to a string and a pointer to an obstack, allocates
2853 a fresh copy of the string on the specified obstack.
2858 create_name (name
, obstackp
)
2860 struct obstack
*obstackp
;
2865 length
= strlen (name
) + 1;
2866 newname
= (char *) obstack_alloc (obstackp
, length
);
2867 (void) strcpy (newname
, name
);
2875 basicdieinfo -- extract the minimal die info from raw die data
2879 void basicdieinfo (char *diep, struct dieinfo *dip,
2880 struct objfile *objfile)
2884 Given a pointer to raw DIE data, and a pointer to an instance of a
2885 die info structure, this function extracts the basic information
2886 from the DIE data required to continue processing this DIE, along
2887 with some bookkeeping information about the DIE.
2889 The information we absolutely must have includes the DIE tag,
2890 and the DIE length. If we need the sibling reference, then we
2891 will have to call completedieinfo() to process all the remaining
2894 Note that since there is no guarantee that the data is properly
2895 aligned in memory for the type of access required (indirection
2896 through anything other than a char pointer), and there is no
2897 guarantee that it is in the same byte order as the gdb host,
2898 we call a function which deals with both alignment and byte
2899 swapping issues. Possibly inefficient, but quite portable.
2901 We also take care of some other basic things at this point, such
2902 as ensuring that the instance of the die info structure starts
2903 out completely zero'd and that curdie is initialized for use
2904 in error reporting if we have a problem with the current die.
2908 All DIE's must have at least a valid length, thus the minimum
2909 DIE size is sizeof (long). In order to have a valid tag, the
2910 DIE size must be at least sizeof (short) larger, otherwise they
2911 are forced to be TAG_padding DIES.
2913 Padding DIES must be at least sizeof(long) in length, implying that
2914 if a padding DIE is used for alignment and the amount needed is less
2915 than sizeof(long) then the padding DIE has to be big enough to align
2916 to the next alignment boundry.
2920 basicdieinfo (dip
, diep
, objfile
)
2921 struct dieinfo
*dip
;
2923 struct objfile
*objfile
;
2926 (void) memset (dip
, 0, sizeof (struct dieinfo
));
2928 dip
-> dieref
= dbroff
+ (diep
- dbbase
);
2929 SWAPIN (dip
-> dielength
, diep
, objfile
);
2930 if (dip
-> dielength
< sizeof (long))
2932 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> dielength
);
2934 else if (dip
-> dielength
< (sizeof (long) + sizeof (short)))
2936 dip
-> dietag
= TAG_padding
;
2940 SWAPIN (dip
-> dietag
, diep
+ sizeof (long), objfile
);
2948 completedieinfo -- finish reading the information for a given DIE
2952 void completedieinfo (struct dieinfo *dip, struct objfile *objfile)
2956 Given a pointer to an already partially initialized die info structure,
2957 scan the raw DIE data and finish filling in the die info structure
2958 from the various attributes found.
2960 Note that since there is no guarantee that the data is properly
2961 aligned in memory for the type of access required (indirection
2962 through anything other than a char pointer), and there is no
2963 guarantee that it is in the same byte order as the gdb host,
2964 we call a function which deals with both alignment and byte
2965 swapping issues. Possibly inefficient, but quite portable.
2969 Each time we are called, we increment the diecount variable, which
2970 keeps an approximate count of the number of dies processed for
2971 each compilation unit. This information is presented to the user
2972 if the info_verbose flag is set.
2977 completedieinfo (dip
, objfile
)
2978 struct dieinfo
*dip
;
2979 struct objfile
*objfile
;
2981 char *diep
; /* Current pointer into raw DIE data */
2982 char *end
; /* Terminate DIE scan here */
2983 unsigned short attr
; /* Current attribute being scanned */
2984 unsigned short form
; /* Form of the attribute */
2985 short block2sz
; /* Size of a block2 attribute field */
2986 long block4sz
; /* Size of a block4 attribute field */
2990 end
= diep
+ dip
-> dielength
;
2991 diep
+= sizeof (long) + sizeof (short);
2994 SWAPIN (attr
, diep
, objfile
);
2995 diep
+= sizeof (short);
2999 SWAPIN (dip
-> at_fund_type
, diep
, objfile
);
3002 SWAPIN (dip
-> at_ordering
, diep
, objfile
);
3005 SWAPIN (dip
-> at_bit_offset
, diep
, objfile
);
3008 SWAPIN (dip
-> at_visibility
, diep
, objfile
);
3011 SWAPIN (dip
-> at_sibling
, diep
, objfile
);
3014 SWAPIN (dip
-> at_stmt_list
, diep
, objfile
);
3015 dip
-> has_at_stmt_list
= 1;
3018 SWAPIN (dip
-> at_low_pc
, diep
, objfile
);
3019 dip
-> at_low_pc
+= baseaddr
;
3020 dip
-> has_at_low_pc
= 1;
3023 SWAPIN (dip
-> at_high_pc
, diep
, objfile
);
3024 dip
-> at_high_pc
+= baseaddr
;
3027 SWAPIN (dip
-> at_language
, diep
, objfile
);
3029 case AT_user_def_type
:
3030 SWAPIN (dip
-> at_user_def_type
, diep
, objfile
);
3033 SWAPIN (dip
-> at_byte_size
, diep
, objfile
);
3036 SWAPIN (dip
-> at_bit_size
, diep
, objfile
);
3039 SWAPIN (dip
-> at_member
, diep
, objfile
);
3042 SWAPIN (dip
-> at_discr
, diep
, objfile
);
3045 SWAPIN (dip
-> at_import
, diep
, objfile
);
3048 dip
-> at_location
= diep
;
3050 case AT_mod_fund_type
:
3051 dip
-> at_mod_fund_type
= diep
;
3053 case AT_subscr_data
:
3054 dip
-> at_subscr_data
= diep
;
3056 case AT_mod_u_d_type
:
3057 dip
-> at_mod_u_d_type
= diep
;
3059 case AT_element_list
:
3060 dip
-> at_element_list
= diep
;
3061 dip
-> short_element_list
= 0;
3063 case AT_short_element_list
:
3064 dip
-> at_element_list
= diep
;
3065 dip
-> short_element_list
= 1;
3067 case AT_discr_value
:
3068 dip
-> at_discr_value
= diep
;
3070 case AT_string_length
:
3071 dip
-> at_string_length
= diep
;
3074 dip
-> at_name
= diep
;
3077 dip
-> at_comp_dir
= diep
;
3080 dip
-> at_producer
= diep
;
3083 SWAPIN (dip
-> at_frame_base
, diep
, objfile
);
3085 case AT_start_scope
:
3086 SWAPIN (dip
-> at_start_scope
, diep
, objfile
);
3088 case AT_stride_size
:
3089 SWAPIN (dip
-> at_stride_size
, diep
, objfile
);
3092 SWAPIN (dip
-> at_src_info
, diep
, objfile
);
3095 SWAPIN (dip
-> at_prototyped
, diep
, objfile
);
3098 /* Found an attribute that we are unprepared to handle. However
3099 it is specifically one of the design goals of DWARF that
3100 consumers should ignore unknown attributes. As long as the
3101 form is one that we recognize (so we know how to skip it),
3102 we can just ignore the unknown attribute. */
3109 diep
+= sizeof (short);
3112 diep
+= sizeof (long);
3115 diep
+= 8 * sizeof (char); /* sizeof (long long) ? */
3119 diep
+= sizeof (long);
3122 SWAPIN (block2sz
, diep
, objfile
);
3123 block2sz
+= sizeof (short);
3127 SWAPIN (block4sz
, diep
, objfile
);
3128 block4sz
+= sizeof (long);
3132 diep
+= strlen (diep
) + 1;
3135 SQUAWK (("unknown attribute form (0x%x), skipped rest", form
));
3144 swapin (to
, from
, nbytes
, objfile
)
3148 struct objfile
*objfile
;
3153 #if defined (LONG_LONG)
3156 bfd_h_get_64 (objfile
-> obfd
, (unsigned char *) from
);
3160 *(long *)to
= bfd_h_get_32 (objfile
-> obfd
, (unsigned char *) from
);
3163 *(short *)to
= bfd_h_get_16 (objfile
-> obfd
, (unsigned char *) from
);
3166 *to
= bfd_h_get_8 (objfile
-> obfd
, (unsigned char *) from
);
3169 /* For objects bigger than we know how to swap in, just copy
3170 them without any swapping. We should probably warn about this.
3172 (void) memcpy (to
, from
, nbytes
);