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 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
91 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
92 However, the Issue 2 DWARF specification from AT&T defines it as
93 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
94 For backwards compatibility with the AT&T compiler produced executables
95 we define AT_short_element_list for this variant. */
97 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
99 /* External variables referenced. */
101 extern int info_verbose
; /* From main.c; nonzero => verbose */
102 extern char *warning_pre_print
; /* From utils.c */
104 /* The DWARF debugging information consists of two major pieces,
105 one is a block of DWARF Information Entries (DIE's) and the other
106 is a line number table. The "struct dieinfo" structure contains
107 the information for a single DIE, the one currently being processed.
109 In order to make it easier to randomly access the attribute fields
110 of the current DIE, which are specifically unordered within the DIE
111 each DIE is scanned and an instance of the "struct dieinfo"
112 structure is initialized.
114 Initialization is done in two levels. The first, done by basicdieinfo(),
115 just initializes those fields that are vital to deciding whether or not
116 to use this DIE, how to skip past it, etc. The second, done by the
117 function completedieinfo(), fills in the rest of the information.
119 Attributes which have block forms are not interpreted at the time
120 the DIE is scanned, instead we just save pointers to the start
121 of their value fields.
123 Some fields have a flag <name>_p that is set when the value of the
124 field is valid (I.E. we found a matching attribute in the DIE). Since
125 we may want to test for the presence of some attributes in the DIE,
126 such as AT_low_pc, without restricting the values of the field,
127 we need someway to note that we found such an attribute.
134 char * die
; /* Pointer to the raw DIE data */
135 long dielength
; /* Length of the raw DIE data */
136 DIEREF dieref
; /* Offset of this DIE */
137 short dietag
; /* Tag for this DIE */
142 unsigned short at_fund_type
;
143 BLOCK
* at_mod_fund_type
;
144 long at_user_def_type
;
145 BLOCK
* at_mod_u_d_type
;
147 BLOCK
* at_subscr_data
;
151 BLOCK
* at_element_list
;
158 BLOCK
* at_discr_value
;
161 BLOCK
* at_string_length
;
169 unsigned int has_at_low_pc
:1;
170 unsigned int has_at_stmt_list
:1;
171 unsigned int short_element_list
:1;
174 static int diecount
; /* Approximate count of dies for compilation unit */
175 static struct dieinfo
*curdie
; /* For warnings and such */
177 static char *dbbase
; /* Base pointer to dwarf info */
178 static int dbroff
; /* Relative offset from start of .debug section */
179 static char *lnbase
; /* Base pointer to line section */
180 static int isreg
; /* Kludge to identify register variables */
181 static int offreg
; /* Kludge to identify basereg references */
183 static CORE_ADDR baseaddr
; /* Add to each symbol value */
185 /* Each partial symbol table entry contains a pointer to private data for the
186 read_symtab() function to use when expanding a partial symbol table entry
187 to a full symbol table entry. For DWARF debugging info, this data is
188 contained in the following structure and macros are provided for easy
189 access to the members given a pointer to a partial symbol table entry.
191 dbfoff Always the absolute file offset to the start of the ".debug"
192 section for the file containing the DIE's being accessed.
194 dbroff Relative offset from the start of the ".debug" access to the
195 first DIE to be accessed. When building the partial symbol
196 table, this value will be zero since we are accessing the
197 entire ".debug" section. When expanding a partial symbol
198 table entry, this value will be the offset to the first
199 DIE for the compilation unit containing the symbol that
200 triggers the expansion.
202 dblength The size of the chunk of DIE's being examined, in bytes.
204 lnfoff The absolute file offset to the line table fragment. Ignored
205 when building partial symbol tables, but used when expanding
206 them, and contains the absolute file offset to the fragment
207 of the ".line" section containing the line numbers for the
208 current compilation unit.
212 int dbfoff
; /* Absolute file offset to start of .debug section */
213 int dbroff
; /* Relative offset from start of .debug section */
214 int dblength
; /* Size of the chunk of DIE's being examined */
215 int lnfoff
; /* Absolute file offset to line table fragment */
218 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
219 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
220 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
221 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
223 /* The generic symbol table building routines have separate lists for
224 file scope symbols and all all other scopes (local scopes). So
225 we need to select the right one to pass to add_symbol_to_list().
226 We do it by keeping a pointer to the correct list in list_in_scope.
228 FIXME: The original dwarf code just treated the file scope as the first
229 local scope, and all other local scopes as nested local scopes, and worked
230 fine. Check to see if we really need to distinguish these in buildsym.c */
232 struct pending
**list_in_scope
= &file_symbols
;
234 /* DIES which have user defined types or modified user defined types refer to
235 other DIES for the type information. Thus we need to associate the offset
236 of a DIE for a user defined type with a pointer to the type information.
238 Originally this was done using a simple but expensive algorithm, with an
239 array of unsorted structures, each containing an offset/type-pointer pair.
240 This array was scanned linearly each time a lookup was done. The result
241 was that gdb was spending over half it's startup time munging through this
242 array of pointers looking for a structure that had the right offset member.
244 The second attempt used the same array of structures, but the array was
245 sorted using qsort each time a new offset/type was recorded, and a binary
246 search was used to find the type pointer for a given DIE offset. This was
247 even slower, due to the overhead of sorting the array each time a new
248 offset/type pair was entered.
250 The third attempt uses a fixed size array of type pointers, indexed by a
251 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
252 we can divide any DIE offset by 4 to obtain a unique index into this fixed
253 size array. Since each element is a 4 byte pointer, it takes exactly as
254 much memory to hold this array as to hold the DWARF info for a given
255 compilation unit. But it gets freed as soon as we are done with it. */
257 static struct type
**utypes
; /* Pointer to array of user type pointers */
258 static int numutypes
; /* Max number of user type pointers */
260 /* Forward declarations of static functions so we don't have to worry
261 about ordering within this file. */
264 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
267 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
270 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
273 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
280 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
283 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
284 unsigned int, struct objfile
*));
287 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
290 init_psymbol_list
PARAMS ((struct objfile
*, int));
293 basicdieinfo
PARAMS ((struct dieinfo
*, char *));
296 completedieinfo
PARAMS ((struct dieinfo
*));
299 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
302 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
304 static struct symtab
*
305 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
308 process_dies
PARAMS ((char *, char *, struct objfile
*));
311 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
315 decode_array_element_type
PARAMS ((char *));
318 decode_subscr_data
PARAMS ((char *, char *));
321 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
324 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
327 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
330 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
333 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
336 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
339 decode_line_numbers
PARAMS ((char *));
342 decode_die_type
PARAMS ((struct dieinfo
*));
345 decode_mod_fund_type
PARAMS ((char *));
348 decode_mod_u_d_type
PARAMS ((char *));
351 decode_modified_type
PARAMS ((unsigned char *, unsigned int, int));
354 decode_fund_type
PARAMS ((unsigned int));
357 create_name
PARAMS ((char *, struct obstack
*));
360 lookup_utype
PARAMS ((DIEREF
));
363 alloc_utype
PARAMS ((DIEREF
, struct type
*));
365 static struct symbol
*
366 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
369 locval
PARAMS ((char *));
372 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
379 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
383 void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr,
384 int mainline, unsigned int dbfoff, unsigned int dbsize,
385 unsigned int lnoffset, unsigned int lnsize,
386 struct objfile *objfile)
390 This function is called upon to build partial symtabs from files
391 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
393 It is passed a file descriptor for an open file containing the DIES
394 and line number information, the corresponding filename for that
395 file, a base address for relocating the symbols, a flag indicating
396 whether or not this debugging information is from a "main symbol
397 table" rather than a shared library or dynamically linked file,
398 and file offset/size pairs for the DIE information and line number
408 dwarf_build_psymtabs (desc
, filename
, addr
, mainline
, dbfoff
, dbsize
,
409 lnoffset
, lnsize
, objfile
)
416 unsigned int lnoffset
;
418 struct objfile
*objfile
;
420 struct cleanup
*back_to
;
422 dbbase
= xmalloc (dbsize
);
424 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
425 (read (desc
, dbbase
, dbsize
) != dbsize
))
428 error ("can't read DWARF data from '%s'", filename
);
430 back_to
= make_cleanup (free
, dbbase
);
432 /* If we are reinitializing, or if we have never loaded syms yet, init.
433 Since we have no idea how many DIES we are looking at, we just guess
434 some arbitrary value. */
436 if (mainline
|| objfile
->global_psymbols
.size
== 0 || objfile
->static_psymbols
.size
== 0)
438 init_psymbol_list (objfile
, 1024);
441 /* Save the relocation factor where everybody can see it. */
445 /* Follow the compilation unit sibling chain, building a partial symbol
446 table entry for each one. Save enough information about each compilation
447 unit to locate the full DWARF information later. */
449 scan_compilation_units (filename
, dbbase
, dbbase
+ dbsize
,
450 dbfoff
, lnoffset
, objfile
);
452 do_cleanups (back_to
);
460 record_minimal_symbol -- add entry to gdb's minimal symbol table
464 static void record_minimal_symbol (char *name, CORE_ADDR address,
465 enum minimal_symbol_type ms_type,
466 struct objfile *objfile)
470 Given a pointer to the name of a symbol that should be added to the
471 minimal symbol table, and the address associated with that
472 symbol, records this information for later use in building the
473 minimal symbol table.
478 record_minimal_symbol (name
, address
, ms_type
, objfile
)
481 enum minimal_symbol_type ms_type
;
482 struct objfile
*objfile
;
484 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
485 prim_record_minimal_symbol (name
, address
, ms_type
);
492 dwarfwarn -- issue a DWARF related warning
496 Issue warnings about DWARF related things that aren't serious enough
497 to warrant aborting with an error, but should not be ignored either.
498 This includes things like detectable corruption in DIE's, missing
499 DIE's, unimplemented features, etc.
501 In general, running across tags or attributes that we don't recognize
502 is not considered to be a problem and we should not issue warnings
507 We mostly follow the example of the error() routine, but without
508 returning to command level. It is arguable about whether warnings
509 should be issued at all, and if so, where they should go (stdout or
512 We assume that curdie is valid and contains at least the basic
513 information for the DIE where the problem was noticed.
524 fmt
= va_arg (ap
, char *);
526 fprintf (stderr
, "warning: DWARF ref 0x%x: ", curdie
-> dieref
);
527 if (curdie
-> at_name
)
529 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
531 vfprintf (stderr
, fmt
, ap
);
532 fprintf (stderr
, "\n");
541 read_lexical_block_scope -- process all dies in a lexical block
545 static void read_lexical_block_scope (struct dieinfo *dip,
546 char *thisdie, char *enddie)
550 Process all the DIES contained within a lexical block scope.
551 Start a new scope, process the dies, and then close the scope.
556 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
560 struct objfile
*objfile
;
562 register struct context_stack
*new;
564 (void) push_context (0, dip
-> at_low_pc
);
565 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
566 new = pop_context ();
567 if (local_symbols
!= NULL
)
569 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
570 dip
-> at_high_pc
, objfile
);
572 local_symbols
= new -> locals
;
579 lookup_utype -- look up a user defined type from die reference
583 static type *lookup_utype (DIEREF dieref)
587 Given a DIE reference, lookup the user defined type associated with
588 that DIE, if it has been registered already. If not registered, then
589 return NULL. Alloc_utype() can be called to register an empty
590 type for this reference, which will be filled in later when the
591 actual referenced DIE is processed.
595 lookup_utype (dieref
)
598 struct type
*type
= NULL
;
601 utypeidx
= (dieref
- dbroff
) / 4;
602 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
604 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
608 type
= *(utypes
+ utypeidx
);
618 alloc_utype -- add a user defined type for die reference
622 static type *alloc_utype (DIEREF dieref, struct type *utypep)
626 Given a die reference DIEREF, and a possible pointer to a user
627 defined type UTYPEP, register that this reference has a user
628 defined type and either use the specified type in UTYPEP or
629 make a new empty type that will be filled in later.
631 We should only be called after calling lookup_utype() to verify that
632 there is not currently a type registered for DIEREF.
636 alloc_utype (dieref
, utypep
)
643 utypeidx
= (dieref
- dbroff
) / 4;
644 typep
= utypes
+ utypeidx
;
645 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
647 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
648 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
650 else if (*typep
!= NULL
)
653 SQUAWK (("internal error: dup user type allocation"));
659 utypep
= (struct type
*)
660 obstack_alloc (¤t_objfile
-> type_obstack
,
661 sizeof (struct type
));
662 (void) memset (utypep
, 0, sizeof (struct type
));
663 TYPE_OBJFILE (utypep
) = current_objfile
;
674 decode_die_type -- return a type for a specified die
678 static struct type *decode_die_type (struct dieinfo *dip)
682 Given a pointer to a die information structure DIP, decode the
683 type of the die and return a pointer to the decoded type. All
684 dies without specific types default to type int.
688 decode_die_type (dip
)
691 struct type
*type
= NULL
;
693 if (dip
-> at_fund_type
!= 0)
695 type
= decode_fund_type (dip
-> at_fund_type
);
697 else if (dip
-> at_mod_fund_type
!= NULL
)
699 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
701 else if (dip
-> at_user_def_type
)
703 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
705 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
708 else if (dip
-> at_mod_u_d_type
)
710 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
714 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
723 struct_type -- compute and return the type for a struct or union
727 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
728 char *enddie, struct objfile *objfile)
732 Given pointer to a die information structure for a die which
733 defines a union or structure (and MUST define one or the other),
734 and pointers to the raw die data that define the range of dies which
735 define the members, compute and return the user defined type for the
740 struct_type (dip
, thisdie
, enddie
, objfile
)
744 struct objfile
*objfile
;
748 struct nextfield
*next
;
751 struct nextfield
*list
= NULL
;
752 struct nextfield
*new;
759 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
761 /* No forward references created an empty type, so install one now */
762 type
= alloc_utype (dip
-> dieref
, NULL
);
764 INIT_CPLUS_SPECIFIC(type
);
765 switch (dip
-> dietag
)
767 case TAG_structure_type
:
768 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
772 TYPE_CODE (type
) = TYPE_CODE_UNION
;
776 /* Should never happen */
777 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
779 SQUAWK (("missing structure or union tag"));
782 /* Some compilers try to be helpful by inventing "fake" names for
783 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
784 Thanks, but no thanks... */
785 if (dip
-> at_name
!= NULL
786 && *dip
-> at_name
!= '~'
787 && *dip
-> at_name
!= '.')
789 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
,
790 tpart1
, " ", dip
-> at_name
);
792 if (dip
-> at_byte_size
!= 0)
794 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
796 thisdie
+= dip
-> dielength
;
797 while (thisdie
< enddie
)
799 basicdieinfo (&mbr
, thisdie
);
800 completedieinfo (&mbr
);
801 if (mbr
.dielength
<= sizeof (long))
805 else if (mbr
.at_sibling
!= 0)
807 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
811 nextdie
= thisdie
+ mbr
.dielength
;
816 /* Get space to record the next field's data. */
817 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
821 list
-> field
.name
= savestring (mbr
.at_name
, strlen (mbr
.at_name
));
822 list
-> field
.type
= decode_die_type (&mbr
);
823 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
824 list
-> field
.bitsize
= 0;
828 process_dies (thisdie
, nextdie
, objfile
);
833 /* Now create the vector of fields, and record how big it is. We may
834 not even have any fields, if this DIE was generated due to a reference
835 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
836 set, which clues gdb in to the fact that it needs to search elsewhere
837 for the full structure definition. */
840 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
844 TYPE_NFIELDS (type
) = nfields
;
845 TYPE_FIELDS (type
) = (struct field
*)
846 obstack_alloc (¤t_objfile
-> type_obstack
,
847 sizeof (struct field
) * nfields
);
848 /* Copy the saved-up fields into the field vector. */
849 for (n
= nfields
; list
; list
= list
-> next
)
851 TYPE_FIELD (type
, --n
) = list
-> field
;
861 read_structure_scope -- process all dies within struct or union
865 static void read_structure_scope (struct dieinfo *dip,
866 char *thisdie, char *enddie, struct objfile *objfile)
870 Called when we find the DIE that starts a structure or union
871 scope (definition) to process all dies that define the members
872 of the structure or union. DIP is a pointer to the die info
873 struct for the DIE that names the structure or union.
877 Note that we need to call struct_type regardless of whether or not
878 the DIE has an at_name attribute, since it might be an anonymous
879 structure or union. This gets the type entered into our set of
882 However, if the structure is incomplete (an opaque struct/union)
883 then suppress creating a symbol table entry for it since gdb only
884 wants to find the one with the complete definition. Note that if
885 it is complete, we just call new_symbol, which does it's own
886 checking about whether the struct/union is anonymous or not (and
887 suppresses creating a symbol table entry itself).
892 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
896 struct objfile
*objfile
;
901 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
902 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
904 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
906 SYMBOL_TYPE (sym
) = type
;
915 decode_array_element_type -- decode type of the array elements
919 static struct type *decode_array_element_type (char *scan, char *end)
923 As the last step in decoding the array subscript information for an
924 array DIE, we need to decode the type of the array elements. We are
925 passed a pointer to this last part of the subscript information and
926 must return the appropriate type. If the type attribute is not
927 recognized, just warn about the problem and return type int.
931 decode_array_element_type (scan
)
937 unsigned short fundtype
;
939 /* FIXME, does this confuse the host and target sizeof's? --gnu */
940 (void) memcpy (&attribute
, scan
, sizeof (short));
941 scan
+= sizeof (short);
945 (void) memcpy (&fundtype
, scan
, sizeof (short));
946 typep
= decode_fund_type (fundtype
);
948 case AT_mod_fund_type
:
949 typep
= decode_mod_fund_type (scan
);
951 case AT_user_def_type
:
952 (void) memcpy (&dieref
, scan
, sizeof (DIEREF
));
953 if ((typep
= lookup_utype (dieref
)) == NULL
)
955 typep
= alloc_utype (dieref
, NULL
);
958 case AT_mod_u_d_type
:
959 typep
= decode_mod_u_d_type (scan
);
962 SQUAWK (("bad array element type attribute 0x%x", attribute
));
963 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
973 decode_subscr_data -- decode array subscript and element type data
977 static struct type *decode_subscr_data (char *scan, char *end)
981 The array subscripts and the data type of the elements of an
982 array are described by a list of data items, stored as a block
983 of contiguous bytes. There is a data item describing each array
984 dimension, and a final data item describing the element type.
985 The data items are ordered the same as their appearance in the
986 source (I.E. leftmost dimension first, next to leftmost second,
989 We are passed a pointer to the start of the block of bytes
990 containing the data items, and a pointer to the first byte past
991 the data. This function decodes the data and returns a type.
994 FIXME: This code only implements the forms currently used
995 by the AT&T and GNU C compilers.
997 The end pointer is supplied for error checking, maybe we should
1001 static struct type
*
1002 decode_subscr_data (scan
, end
)
1006 struct type
*typep
= NULL
;
1007 struct type
*nexttype
;
1017 typep
= decode_array_element_type (scan
);
1020 (void) memcpy (&fundtype
, scan
, sizeof (short));
1021 scan
+= sizeof (short);
1022 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1023 && fundtype
!= FT_unsigned_integer
)
1025 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1030 (void) memcpy (&lowbound
, scan
, sizeof (long));
1031 scan
+= sizeof (long);
1032 (void) memcpy (&highbound
, scan
, sizeof (long));
1033 scan
+= sizeof (long);
1034 nexttype
= decode_subscr_data (scan
, end
);
1035 if (nexttype
!= NULL
)
1037 typep
= (struct type
*)
1038 obstack_alloc (¤t_objfile
-> type_obstack
,
1039 sizeof (struct type
));
1040 (void) memset (typep
, 0, sizeof (struct type
));
1041 TYPE_OBJFILE (typep
) = current_objfile
;
1042 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1043 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1044 TYPE_LENGTH (typep
) *= lowbound
+ highbound
+ 1;
1045 TYPE_TARGET_TYPE (typep
) = nexttype
;
1056 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1059 SQUAWK (("unknown array subscript format %x", format
));
1069 dwarf_read_array_type -- read TAG_array_type DIE
1073 static void dwarf_read_array_type (struct dieinfo *dip)
1077 Extract all information from a TAG_array_type DIE and add to
1078 the user defined type vector.
1082 dwarf_read_array_type (dip
)
1083 struct dieinfo
*dip
;
1091 if (dip
-> at_ordering
!= ORD_row_major
)
1093 /* FIXME: Can gdb even handle column major arrays? */
1094 SQUAWK (("array not row major; not handled correctly"));
1096 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1098 (void) memcpy (&temp
, sub
, sizeof (short));
1099 subend
= sub
+ sizeof (short) + temp
;
1100 sub
+= sizeof (short);
1101 type
= decode_subscr_data (sub
, subend
);
1104 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1106 utype
= alloc_utype (dip
-> dieref
, NULL
);
1108 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1109 TYPE_TARGET_TYPE (utype
) =
1110 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1111 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1115 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1117 (void) alloc_utype (dip
-> dieref
, type
);
1121 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1122 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1123 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1133 read_tag_pointer_type -- read TAG_pointer_type DIE
1137 static void read_tag_pointer_type (struct dieinfo *dip)
1141 Extract all information from a TAG_pointer_type DIE and add to
1142 the user defined type vector.
1146 read_tag_pointer_type (dip
)
1147 struct dieinfo
*dip
;
1152 type
= decode_die_type (dip
);
1153 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1155 utype
= lookup_pointer_type (type
);
1156 (void) alloc_utype (dip
-> dieref
, utype
);
1160 TYPE_TARGET_TYPE (utype
) = type
;
1161 TYPE_POINTER_TYPE (type
) = utype
;
1163 /* We assume the machine has only one representation for pointers! */
1164 /* FIXME: This confuses host<->target data representations, and is a
1165 poor assumption besides. */
1167 TYPE_LENGTH (utype
) = sizeof (char *);
1168 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1176 read_subroutine_type -- process TAG_subroutine_type dies
1180 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1185 Handle DIES due to C code like:
1188 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1194 The parameter DIES are currently ignored. See if gdb has a way to
1195 include this info in it's type system, and decode them if so. Is
1196 this what the type structure's "arg_types" field is for? (FIXME)
1200 read_subroutine_type (dip
, thisdie
, enddie
)
1201 struct dieinfo
*dip
;
1205 struct type
*type
; /* Type that this function returns */
1206 struct type
*ftype
; /* Function that returns above type */
1208 /* Decode the type that this subroutine returns */
1210 type
= decode_die_type (dip
);
1212 /* Check to see if we already have a partially constructed user
1213 defined type for this DIE, from a forward reference. */
1215 if ((ftype
= lookup_utype (dip
-> dieref
)) == NULL
)
1217 /* This is the first reference to one of these types. Make
1218 a new one and place it in the user defined types. */
1219 ftype
= lookup_function_type (type
);
1220 (void) alloc_utype (dip
-> dieref
, ftype
);
1224 /* We have an existing partially constructed type, so bash it
1225 into the correct type. */
1226 TYPE_TARGET_TYPE (ftype
) = type
;
1227 TYPE_FUNCTION_TYPE (type
) = ftype
;
1228 TYPE_LENGTH (ftype
) = 1;
1229 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1237 read_enumeration -- process dies which define an enumeration
1241 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1242 char *enddie, struct objfile *objfile)
1246 Given a pointer to a die which begins an enumeration, process all
1247 the dies that define the members of the enumeration.
1251 Note that we need to call enum_type regardless of whether or not we
1252 have a symbol, since we might have an enum without a tag name (thus
1253 no symbol for the tagname).
1257 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1258 struct dieinfo
*dip
;
1261 struct objfile
*objfile
;
1266 type
= enum_type (dip
, objfile
);
1267 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1269 SYMBOL_TYPE (sym
) = type
;
1277 enum_type -- decode and return a type for an enumeration
1281 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1285 Given a pointer to a die information structure for the die which
1286 starts an enumeration, process all the dies that define the members
1287 of the enumeration and return a type pointer for the enumeration.
1289 At the same time, for each member of the enumeration, create a
1290 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1291 and give it the type of the enumeration itself.
1295 Note that the DWARF specification explicitly mandates that enum
1296 constants occur in reverse order from the source program order,
1297 for "consistency" and because this ordering is easier for many
1298 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1299 Entries). Because gdb wants to see the enum members in program
1300 source order, we have to ensure that the order gets reversed while
1301 we are processing them.
1304 static struct type
*
1305 enum_type (dip
, objfile
)
1306 struct dieinfo
*dip
;
1307 struct objfile
*objfile
;
1311 struct nextfield
*next
;
1314 struct nextfield
*list
= NULL
;
1315 struct nextfield
*new;
1324 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
1326 /* No forward references created an empty type, so install one now */
1327 type
= alloc_utype (dip
-> dieref
, NULL
);
1329 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1330 /* Some compilers try to be helpful by inventing "fake" names for
1331 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1332 Thanks, but no thanks... */
1333 if (dip
-> at_name
!= NULL
1334 && *dip
-> at_name
!= '~'
1335 && *dip
-> at_name
!= '.')
1337 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
, "enum",
1338 " ", dip
-> at_name
);
1340 if (dip
-> at_byte_size
!= 0)
1342 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1344 if ((scan
= dip
-> at_element_list
) != NULL
)
1346 if (dip
-> short_element_list
)
1348 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
1349 listend
= scan
+ stemp
+ sizeof (stemp
);
1350 scan
+= sizeof (stemp
);
1354 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
1355 listend
= scan
+ ltemp
+ sizeof (ltemp
);
1356 scan
+= sizeof (ltemp
);
1358 while (scan
< listend
)
1360 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1363 list
-> field
.type
= NULL
;
1364 list
-> field
.bitsize
= 0;
1365 (void) memcpy (&list
-> field
.bitpos
, scan
, sizeof (long));
1366 scan
+= sizeof (long);
1367 list
-> field
.name
= savestring (scan
, strlen (scan
));
1368 scan
+= strlen (scan
) + 1;
1370 /* Handcraft a new symbol for this enum member. */
1371 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1372 sizeof (struct symbol
));
1373 (void) memset (sym
, 0, sizeof (struct symbol
));
1374 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
, &objfile
->symbol_obstack
);
1375 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1376 SYMBOL_CLASS (sym
) = LOC_CONST
;
1377 SYMBOL_TYPE (sym
) = type
;
1378 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1379 add_symbol_to_list (sym
, list_in_scope
);
1381 /* Now create the vector of fields, and record how big it is. This is
1382 where we reverse the order, by pulling the members of the list in
1383 reverse order from how they were inserted. If we have no fields
1384 (this is apparently possible in C++) then skip building a field
1388 TYPE_NFIELDS (type
) = nfields
;
1389 TYPE_FIELDS (type
) = (struct field
*)
1390 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1391 /* Copy the saved-up fields into the field vector. */
1392 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1394 TYPE_FIELD (type
, n
++) = list
-> field
;
1405 read_func_scope -- process all dies within a function scope
1409 Process all dies within a given function scope. We are passed
1410 a die information structure pointer DIP for the die which
1411 starts the function scope, and pointers into the raw die data
1412 that define the dies within the function scope.
1414 For now, we ignore lexical block scopes within the function.
1415 The problem is that AT&T cc does not define a DWARF lexical
1416 block scope for the function itself, while gcc defines a
1417 lexical block scope for the function. We need to think about
1418 how to handle this difference, or if it is even a problem.
1423 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1424 struct dieinfo
*dip
;
1427 struct objfile
*objfile
;
1429 register struct context_stack
*new;
1431 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1432 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1434 objfile
-> ei
.entry_func_lowpc
= dip
-> at_low_pc
;
1435 objfile
-> ei
.entry_func_highpc
= dip
-> at_high_pc
;
1437 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1439 objfile
-> ei
.main_func_lowpc
= dip
-> at_low_pc
;
1440 objfile
-> ei
.main_func_highpc
= dip
-> at_high_pc
;
1442 new = push_context (0, dip
-> at_low_pc
);
1443 new -> name
= new_symbol (dip
, objfile
);
1444 list_in_scope
= &local_symbols
;
1445 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1446 new = pop_context ();
1447 /* Make a block for the local symbols within. */
1448 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1449 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1450 list_in_scope
= &file_symbols
;
1457 read_file_scope -- process all dies within a file scope
1461 Process all dies within a given file scope. We are passed a
1462 pointer to the die information structure for the die which
1463 starts the file scope, and pointers into the raw die data which
1464 mark the range of dies within the file scope.
1466 When the partial symbol table is built, the file offset for the line
1467 number table for each compilation unit is saved in the partial symbol
1468 table entry for that compilation unit. As the symbols for each
1469 compilation unit are read, the line number table is read into memory
1470 and the variable lnbase is set to point to it. Thus all we have to
1471 do is use lnbase to access the line number table for the current
1476 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1477 struct dieinfo
*dip
;
1480 struct objfile
*objfile
;
1482 struct cleanup
*back_to
;
1483 struct symtab
*symtab
;
1485 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1486 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1488 objfile
-> ei
.entry_file_lowpc
= dip
-> at_low_pc
;
1489 objfile
-> ei
.entry_file_highpc
= dip
-> at_high_pc
;
1491 if (dip
-> at_producer
!= NULL
)
1493 processing_gcc_compilation
=
1494 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1496 numutypes
= (enddie
- thisdie
) / 4;
1497 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1498 back_to
= make_cleanup (free
, utypes
);
1499 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1500 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1501 decode_line_numbers (lnbase
);
1502 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1503 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1504 /* FIXME: The following may need to be expanded for other languages */
1505 switch (dip
-> at_language
)
1509 symtab
-> language
= language_c
;
1511 case LANG_C_PLUS_PLUS
:
1512 symtab
-> language
= language_cplus
;
1517 do_cleanups (back_to
);
1526 process_dies -- process a range of DWARF Information Entries
1530 static void process_dies (char *thisdie, char *enddie,
1531 struct objfile *objfile)
1535 Process all DIE's in a specified range. May be (and almost
1536 certainly will be) called recursively.
1540 process_dies (thisdie
, enddie
, objfile
)
1543 struct objfile
*objfile
;
1548 while (thisdie
< enddie
)
1550 basicdieinfo (&di
, thisdie
);
1551 if (di
.dielength
< sizeof (long))
1555 else if (di
.dietag
== TAG_padding
)
1557 nextdie
= thisdie
+ di
.dielength
;
1561 completedieinfo (&di
);
1562 if (di
.at_sibling
!= 0)
1564 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1568 nextdie
= thisdie
+ di
.dielength
;
1572 case TAG_compile_unit
:
1573 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1575 case TAG_global_subroutine
:
1576 case TAG_subroutine
:
1577 if (di
.has_at_low_pc
)
1579 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1582 case TAG_lexical_block
:
1583 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1585 case TAG_structure_type
:
1586 case TAG_union_type
:
1587 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1589 case TAG_enumeration_type
:
1590 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1592 case TAG_subroutine_type
:
1593 read_subroutine_type (&di
, thisdie
, nextdie
);
1595 case TAG_array_type
:
1596 dwarf_read_array_type (&di
);
1598 case TAG_pointer_type
:
1599 read_tag_pointer_type (&di
);
1602 (void) new_symbol (&di
, objfile
);
1614 decode_line_numbers -- decode a line number table fragment
1618 static void decode_line_numbers (char *tblscan, char *tblend,
1619 long length, long base, long line, long pc)
1623 Translate the DWARF line number information to gdb form.
1625 The ".line" section contains one or more line number tables, one for
1626 each ".line" section from the objects that were linked.
1628 The AT_stmt_list attribute for each TAG_source_file entry in the
1629 ".debug" section contains the offset into the ".line" section for the
1630 start of the table for that file.
1632 The table itself has the following structure:
1634 <table length><base address><source statement entry>
1635 4 bytes 4 bytes 10 bytes
1637 The table length is the total size of the table, including the 4 bytes
1638 for the length information.
1640 The base address is the address of the first instruction generated
1641 for the source file.
1643 Each source statement entry has the following structure:
1645 <line number><statement position><address delta>
1646 4 bytes 2 bytes 4 bytes
1648 The line number is relative to the start of the file, starting with
1651 The statement position either -1 (0xFFFF) or the number of characters
1652 from the beginning of the line to the beginning of the statement.
1654 The address delta is the difference between the base address and
1655 the address of the first instruction for the statement.
1657 Note that we must copy the bytes from the packed table to our local
1658 variables before attempting to use them, to avoid alignment problems
1659 on some machines, particularly RISC processors.
1663 Does gdb expect the line numbers to be sorted? They are now by
1664 chance/luck, but are not required to be. (FIXME)
1666 The line with number 0 is unused, gdb apparently can discover the
1667 span of the last line some other way. How? (FIXME)
1671 decode_line_numbers (linetable
)
1681 if (linetable
!= NULL
)
1683 tblscan
= tblend
= linetable
;
1684 (void) memcpy (&length
, tblscan
, sizeof (long));
1685 tblscan
+= sizeof (long);
1687 (void) memcpy (&base
, tblscan
, sizeof (long));
1689 tblscan
+= sizeof (long);
1690 while (tblscan
< tblend
)
1692 (void) memcpy (&line
, tblscan
, sizeof (long));
1693 tblscan
+= sizeof (long) + sizeof (short);
1694 (void) memcpy (&pc
, tblscan
, sizeof (long));
1695 tblscan
+= sizeof (long);
1699 record_line (current_subfile
, line
, pc
);
1709 locval -- compute the value of a location attribute
1713 static int locval (char *loc)
1717 Given pointer to a string of bytes that define a location, compute
1718 the location and return the value.
1720 When computing values involving the current value of the frame pointer,
1721 the value zero is used, which results in a value relative to the frame
1722 pointer, rather than the absolute value. This is what GDB wants
1725 When the result is a register number, the global isreg flag is set,
1726 otherwise it is cleared. This is a kludge until we figure out a better
1727 way to handle the problem. Gdb's design does not mesh well with the
1728 DWARF notion of a location computing interpreter, which is a shame
1729 because the flexibility goes unused.
1733 Note that stack[0] is unused except as a default error return.
1734 Note that stack overflow is not yet handled.
1741 unsigned short nbytes
;
1747 (void) memcpy (&nbytes
, loc
, sizeof (short));
1748 end
= loc
+ sizeof (short) + nbytes
;
1753 for (loc
+= sizeof (short); loc
< end
; loc
+= sizeof (long))
1761 /* push register (number) */
1762 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1766 /* push value of register (number) */
1767 /* Actually, we compute the value as if register has 0 */
1769 (void) memcpy (®no
, loc
, sizeof (long));
1772 stack
[++stacki
] = 0;
1776 stack
[++stacki
] = 0;
1777 SQUAWK (("BASEREG %d not handled!", regno
));
1781 /* push address (relocated address) */
1782 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1785 /* push constant (number) */
1786 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1789 /* pop, deref and push 2 bytes (as a long) */
1790 SQUAWK (("OP_DEREF2 address %#x not handled", stack
[stacki
]));
1792 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1793 SQUAWK (("OP_DEREF4 address %#x not handled", stack
[stacki
]));
1795 case OP_ADD
: /* pop top 2 items, add, push result */
1796 stack
[stacki
- 1] += stack
[stacki
];
1801 return (stack
[stacki
]);
1808 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1812 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1816 When expanding a partial symbol table entry to a full symbol table
1817 entry, this is the function that gets called to read in the symbols
1818 for the compilation unit.
1820 Returns a pointer to the newly constructed symtab (which is now
1821 the new first one on the objfile's symtab list).
1824 static struct symtab
*
1825 read_ofile_symtab (pst
)
1826 struct partial_symtab
*pst
;
1828 struct cleanup
*back_to
;
1833 abfd
= pst
-> objfile
-> obfd
;
1834 current_objfile
= pst
-> objfile
;
1836 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1837 unit, seek to the location in the file, and read in all the DIE's. */
1840 dbbase
= xmalloc (DBLENGTH(pst
));
1841 dbroff
= DBROFF(pst
);
1842 foffset
= DBFOFF(pst
) + dbroff
;
1843 baseaddr
= pst
-> addr
;
1844 if (bfd_seek (abfd
, foffset
, 0) ||
1845 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1848 error ("can't read DWARF data");
1850 back_to
= make_cleanup (free
, dbbase
);
1852 /* If there is a line number table associated with this compilation unit
1853 then read the first long word from the line number table fragment, which
1854 contains the size of the fragment in bytes (including the long word
1855 itself). Allocate a buffer for the fragment and read it in for future
1861 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1862 (bfd_read ((PTR
)&lnsize
, sizeof(long), 1, abfd
) != sizeof(long)))
1864 error ("can't read DWARF line number table size");
1866 lnbase
= xmalloc (lnsize
);
1867 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1868 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1871 error ("can't read DWARF line numbers");
1873 make_cleanup (free
, lnbase
);
1876 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1877 do_cleanups (back_to
);
1878 current_objfile
= NULL
;
1879 return (pst
-> objfile
-> symtabs
);
1886 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1890 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1894 Called once for each partial symbol table entry that needs to be
1895 expanded into a full symbol table entry.
1900 psymtab_to_symtab_1 (pst
)
1901 struct partial_symtab
*pst
;
1909 warning ("psymtab for %s already read in. Shouldn't happen.",
1914 /* Read in all partial symtabs on which this one is dependent */
1915 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
1917 if (!pst
-> dependencies
[i
] -> readin
)
1919 /* Inform about additional files that need to be read in. */
1922 fputs_filtered (" ", stdout
);
1924 fputs_filtered ("and ", stdout
);
1926 printf_filtered ("%s...",
1927 pst
-> dependencies
[i
] -> filename
);
1929 fflush (stdout
); /* Flush output */
1931 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
1934 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
1936 pst
-> symtab
= read_ofile_symtab (pst
);
1939 printf_filtered ("%d DIE's, sorting...", diecount
);
1943 sort_symtab_syms (pst
-> symtab
);
1954 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
1958 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
1962 This is the DWARF support entry point for building a full symbol
1963 table entry from a partial symbol table entry. We are passed a
1964 pointer to the partial symbol table entry that needs to be expanded.
1969 dwarf_psymtab_to_symtab (pst
)
1970 struct partial_symtab
*pst
;
1977 warning ("psymtab for %s already read in. Shouldn't happen.",
1982 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
1984 /* Print the message now, before starting serious work, to avoid
1985 disconcerting pauses. */
1988 printf_filtered ("Reading in symbols for %s...",
1993 psymtab_to_symtab_1 (pst
);
1995 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
1996 we need to do an equivalent or is this something peculiar to
1998 Match with global symbols. This only needs to be done once,
1999 after all of the symtabs and dependencies have been read in.
2001 scan_file_globals (pst
-> objfile
);
2004 /* Finish up the verbose info message. */
2007 printf_filtered ("done.\n");
2019 init_psymbol_list -- initialize storage for partial symbols
2023 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2027 Initializes storage for all of the partial symbols that will be
2028 created by dwarf_build_psymtabs and subsidiaries.
2032 init_psymbol_list (objfile
, total_symbols
)
2033 struct objfile
*objfile
;
2036 /* Free any previously allocated psymbol lists. */
2038 if (objfile
-> global_psymbols
.list
)
2040 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
2042 if (objfile
-> static_psymbols
.list
)
2044 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
2047 /* Current best guess is that there are approximately a twentieth
2048 of the total symbols (in a debugging file) are global or static
2051 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2052 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2053 objfile
-> global_psymbols
.next
=
2054 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2055 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
2056 * sizeof (struct partial_symbol
));
2057 objfile
-> static_psymbols
.next
=
2058 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2059 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
2060 * sizeof (struct partial_symbol
));
2067 add_enum_psymbol -- add enumeration members to partial symbol table
2071 Given pointer to a DIE that is known to be for an enumeration,
2072 extract the symbolic names of the enumeration members and add
2073 partial symbols for them.
2077 add_enum_psymbol (dip
, objfile
)
2078 struct dieinfo
*dip
;
2079 struct objfile
*objfile
;
2086 if ((scan
= dip
-> at_element_list
) != NULL
)
2088 if (dip
-> short_element_list
)
2090 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
2091 listend
= scan
+ stemp
+ sizeof (stemp
);
2092 scan
+= sizeof (stemp
);
2096 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
2097 listend
= scan
+ ltemp
+ sizeof (ltemp
);
2098 scan
+= sizeof (ltemp
);
2100 while (scan
< listend
)
2102 scan
+= sizeof (long);
2103 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2104 objfile
-> static_psymbols
, 0);
2105 scan
+= strlen (scan
) + 1;
2114 add_partial_symbol -- add symbol to partial symbol table
2118 Given a DIE, if it is one of the types that we want to
2119 add to a partial symbol table, finish filling in the die info
2120 and then add a partial symbol table entry for it.
2125 add_partial_symbol (dip
, objfile
)
2126 struct dieinfo
*dip
;
2127 struct objfile
*objfile
;
2129 switch (dip
-> dietag
)
2131 case TAG_global_subroutine
:
2132 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2134 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2135 VAR_NAMESPACE
, LOC_BLOCK
,
2136 objfile
-> global_psymbols
,
2139 case TAG_global_variable
:
2140 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2142 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2143 VAR_NAMESPACE
, LOC_STATIC
,
2144 objfile
-> global_psymbols
,
2147 case TAG_subroutine
:
2148 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2149 VAR_NAMESPACE
, LOC_BLOCK
,
2150 objfile
-> static_psymbols
,
2153 case TAG_local_variable
:
2154 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2155 VAR_NAMESPACE
, LOC_STATIC
,
2156 objfile
-> static_psymbols
,
2160 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2161 VAR_NAMESPACE
, LOC_TYPEDEF
,
2162 objfile
-> static_psymbols
,
2165 case TAG_structure_type
:
2166 case TAG_union_type
:
2167 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2168 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2169 objfile
-> static_psymbols
,
2172 case TAG_enumeration_type
:
2175 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2176 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2177 objfile
-> static_psymbols
,
2180 add_enum_psymbol (dip
, objfile
);
2189 scan_partial_symbols -- scan DIE's within a single compilation unit
2193 Process the DIE's within a single compilation unit, looking for
2194 interesting DIE's that contribute to the partial symbol table entry
2195 for this compilation unit. Since we cannot follow any sibling
2196 chains without reading the complete DIE info for every DIE,
2197 it is probably faster to just sequentially check each one to
2198 see if it is one of the types we are interested in, and if so,
2199 then extract all the attributes info and generate a partial
2204 Don't attempt to add anonymous structures or unions since they have
2205 no name. Anonymous enumerations however are processed, because we
2206 want to extract their member names (the check for a tag name is
2209 Also, for variables and subroutines, check that this is the place
2210 where the actual definition occurs, rather than just a reference
2215 scan_partial_symbols (thisdie
, enddie
, objfile
)
2218 struct objfile
*objfile
;
2223 while (thisdie
< enddie
)
2225 basicdieinfo (&di
, thisdie
);
2226 if (di
.dielength
< sizeof (long))
2232 nextdie
= thisdie
+ di
.dielength
;
2233 /* To avoid getting complete die information for every die, we
2234 only do it (below) for the cases we are interested in. */
2237 case TAG_global_subroutine
:
2238 case TAG_subroutine
:
2239 case TAG_global_variable
:
2240 case TAG_local_variable
:
2241 completedieinfo (&di
);
2242 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2244 add_partial_symbol (&di
, objfile
);
2248 case TAG_structure_type
:
2249 case TAG_union_type
:
2250 completedieinfo (&di
);
2253 add_partial_symbol (&di
, objfile
);
2256 case TAG_enumeration_type
:
2257 completedieinfo (&di
);
2258 add_partial_symbol (&di
, objfile
);
2270 scan_compilation_units -- build a psymtab entry for each compilation
2274 This is the top level dwarf parsing routine for building partial
2277 It scans from the beginning of the DWARF table looking for the first
2278 TAG_compile_unit DIE, and then follows the sibling chain to locate
2279 each additional TAG_compile_unit DIE.
2281 For each TAG_compile_unit DIE it creates a partial symtab structure,
2282 calls a subordinate routine to collect all the compilation unit's
2283 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2284 new partial symtab structure into the partial symbol table. It also
2285 records the appropriate information in the partial symbol table entry
2286 to allow the chunk of DIE's and line number table for this compilation
2287 unit to be located and re-read later, to generate a complete symbol
2288 table entry for the compilation unit.
2290 Thus it effectively partitions up a chunk of DIE's for multiple
2291 compilation units into smaller DIE chunks and line number tables,
2292 and associates them with a partial symbol table entry.
2296 If any compilation unit has no line number table associated with
2297 it for some reason (a missing at_stmt_list attribute, rather than
2298 just one with a value of zero, which is valid) then we ensure that
2299 the recorded file offset is zero so that the routine which later
2300 reads line number table fragments knows that there is no fragment
2310 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2314 unsigned int dbfoff
;
2315 unsigned int lnoffset
;
2316 struct objfile
*objfile
;
2320 struct partial_symtab
*pst
;
2325 while (thisdie
< enddie
)
2327 basicdieinfo (&di
, thisdie
);
2328 if (di
.dielength
< sizeof (long))
2332 else if (di
.dietag
!= TAG_compile_unit
)
2334 nextdie
= thisdie
+ di
.dielength
;
2338 completedieinfo (&di
);
2339 if (di
.at_sibling
!= 0)
2341 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2345 nextdie
= thisdie
+ di
.dielength
;
2347 curoff
= thisdie
- dbbase
;
2348 culength
= nextdie
- thisdie
;
2349 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2351 /* First allocate a new partial symbol table structure */
2353 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2355 objfile
-> global_psymbols
.next
,
2356 objfile
-> static_psymbols
.next
);
2358 pst
-> texthigh
= di
.at_high_pc
;
2359 pst
-> read_symtab_private
= (char *)
2360 obstack_alloc (&objfile
-> psymbol_obstack
,
2361 sizeof (struct dwfinfo
));
2362 DBFOFF (pst
) = dbfoff
;
2363 DBROFF (pst
) = curoff
;
2364 DBLENGTH (pst
) = culength
;
2365 LNFOFF (pst
) = curlnoffset
;
2366 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2368 /* Now look for partial symbols */
2370 scan_partial_symbols (thisdie
+ di
.dielength
, nextdie
, objfile
);
2372 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2373 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2374 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2375 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2376 sort_pst_symbols (pst
);
2377 /* If there is already a psymtab or symtab for a file of this name,
2378 remove it. (If there is a symtab, more drastic things also
2379 happen.) This happens in VxWorks. */
2380 free_named_symtabs (pst
-> filename
);
2390 new_symbol -- make a symbol table entry for a new symbol
2394 static struct symbol *new_symbol (struct dieinfo *dip,
2395 struct objfile *objfile)
2399 Given a pointer to a DWARF information entry, figure out if we need
2400 to make a symbol table entry for it, and if so, create a new entry
2401 and return a pointer to it.
2404 static struct symbol
*
2405 new_symbol (dip
, objfile
)
2406 struct dieinfo
*dip
;
2407 struct objfile
*objfile
;
2409 struct symbol
*sym
= NULL
;
2411 if (dip
-> at_name
!= NULL
)
2413 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2414 sizeof (struct symbol
));
2415 (void) memset (sym
, 0, sizeof (struct symbol
));
2416 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2417 /* default assumptions */
2418 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2419 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2420 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2421 switch (dip
-> dietag
)
2424 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2425 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2427 case TAG_global_subroutine
:
2428 case TAG_subroutine
:
2429 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2430 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2431 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2432 if (dip
-> dietag
== TAG_global_subroutine
)
2434 add_symbol_to_list (sym
, &global_symbols
);
2438 add_symbol_to_list (sym
, list_in_scope
);
2441 case TAG_global_variable
:
2442 if (dip
-> at_location
!= NULL
)
2444 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2445 add_symbol_to_list (sym
, &global_symbols
);
2446 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2447 SYMBOL_VALUE (sym
) += baseaddr
;
2450 case TAG_local_variable
:
2451 if (dip
-> at_location
!= NULL
)
2453 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2454 add_symbol_to_list (sym
, list_in_scope
);
2457 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2461 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2465 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2466 SYMBOL_VALUE (sym
) += baseaddr
;
2470 case TAG_formal_parameter
:
2471 if (dip
-> at_location
!= NULL
)
2473 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2475 add_symbol_to_list (sym
, list_in_scope
);
2478 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2482 SYMBOL_CLASS (sym
) = LOC_ARG
;
2485 case TAG_unspecified_parameters
:
2486 /* From varargs functions; gdb doesn't seem to have any interest in
2487 this information, so just ignore it for now. (FIXME?) */
2489 case TAG_structure_type
:
2490 case TAG_union_type
:
2491 case TAG_enumeration_type
:
2492 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2493 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2494 add_symbol_to_list (sym
, list_in_scope
);
2497 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2498 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2499 add_symbol_to_list (sym
, list_in_scope
);
2502 /* Not a tag we recognize. Hopefully we aren't processing trash
2503 data, but since we must specifically ignore things we don't
2504 recognize, there is nothing else we should do at this point. */
2515 decode_mod_fund_type -- decode a modified fundamental type
2519 static struct type *decode_mod_fund_type (char *typedata)
2523 Decode a block of data containing a modified fundamental
2524 type specification. TYPEDATA is a pointer to the block,
2525 which consists of a two byte length, containing the size
2526 of the rest of the block. At the end of the block is a
2527 two byte value that gives the fundamental type. Everything
2528 in between are type modifiers.
2530 We simply compute the number of modifiers and call the general
2531 function decode_modified_type to do the actual work.
2534 static struct type
*
2535 decode_mod_fund_type (typedata
)
2538 struct type
*typep
= NULL
;
2539 unsigned short modcount
;
2540 unsigned char *modifiers
;
2542 /* Get the total size of the block, exclusive of the size itself */
2543 (void) memcpy (&modcount
, typedata
, sizeof (short));
2544 /* Deduct the size of the fundamental type bytes at the end of the block. */
2545 modcount
-= sizeof (short);
2546 /* Skip over the two size bytes at the beginning of the block. */
2547 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2548 /* Now do the actual decoding */
2549 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_fund_type
);
2557 decode_mod_u_d_type -- decode a modified user defined type
2561 static struct type *decode_mod_u_d_type (char *typedata)
2565 Decode a block of data containing a modified user defined
2566 type specification. TYPEDATA is a pointer to the block,
2567 which consists of a two byte length, containing the size
2568 of the rest of the block. At the end of the block is a
2569 four byte value that gives a reference to a user defined type.
2570 Everything in between are type modifiers.
2572 We simply compute the number of modifiers and call the general
2573 function decode_modified_type to do the actual work.
2576 static struct type
*
2577 decode_mod_u_d_type (typedata
)
2580 struct type
*typep
= NULL
;
2581 unsigned short modcount
;
2582 unsigned char *modifiers
;
2584 /* Get the total size of the block, exclusive of the size itself */
2585 (void) memcpy (&modcount
, typedata
, sizeof (short));
2586 /* Deduct the size of the reference type bytes at the end of the block. */
2587 modcount
-= sizeof (long);
2588 /* Skip over the two size bytes at the beginning of the block. */
2589 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2590 /* Now do the actual decoding */
2591 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_u_d_type
);
2599 decode_modified_type -- decode modified user or fundamental type
2603 static struct type *decode_modified_type (unsigned char *modifiers,
2604 unsigned short modcount, int mtype)
2608 Decode a modified type, either a modified fundamental type or
2609 a modified user defined type. MODIFIERS is a pointer to the
2610 block of bytes that define MODCOUNT modifiers. Immediately
2611 following the last modifier is a short containing the fundamental
2612 type or a long containing the reference to the user defined
2613 type. Which one is determined by MTYPE, which is either
2614 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2615 type we are generating.
2617 We call ourself recursively to generate each modified type,`
2618 until MODCOUNT reaches zero, at which point we have consumed
2619 all the modifiers and generate either the fundamental type or
2620 user defined type. When the recursion unwinds, each modifier
2621 is applied in turn to generate the full modified type.
2625 If we find a modifier that we don't recognize, and it is not one
2626 of those reserved for application specific use, then we issue a
2627 warning and simply ignore the modifier.
2631 We currently ignore MOD_const and MOD_volatile. (FIXME)
2635 static struct type
*
2636 decode_modified_type (modifiers
, modcount
, mtype
)
2637 unsigned char *modifiers
;
2638 unsigned int modcount
;
2641 struct type
*typep
= NULL
;
2642 unsigned short fundtype
;
2644 unsigned char modifier
;
2650 case AT_mod_fund_type
:
2651 (void) memcpy (&fundtype
, modifiers
, sizeof (short));
2652 typep
= decode_fund_type (fundtype
);
2654 case AT_mod_u_d_type
:
2655 (void) memcpy (&dieref
, modifiers
, sizeof (DIEREF
));
2656 if ((typep
= lookup_utype (dieref
)) == NULL
)
2658 typep
= alloc_utype (dieref
, NULL
);
2662 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2663 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2669 modifier
= *modifiers
++;
2670 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2673 case MOD_pointer_to
:
2674 typep
= lookup_pointer_type (typep
);
2676 case MOD_reference_to
:
2677 typep
= lookup_reference_type (typep
);
2680 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2683 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2686 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2688 SQUAWK (("unknown type modifier %u", modifier
));
2700 decode_fund_type -- translate basic DWARF type to gdb base type
2704 Given an integer that is one of the fundamental DWARF types,
2705 translate it to one of the basic internal gdb types and return
2706 a pointer to the appropriate gdb type (a "struct type *").
2710 If we encounter a fundamental type that we are unprepared to
2711 deal with, and it is not in the range of those types defined
2712 as application specific types, then we issue a warning and
2713 treat the type as an "int".
2716 static struct type
*
2717 decode_fund_type (fundtype
)
2718 unsigned int fundtype
;
2720 struct type
*typep
= NULL
;
2726 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2729 case FT_boolean
: /* Was FT_set in AT&T version */
2730 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2733 case FT_pointer
: /* (void *) */
2734 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2735 typep
= lookup_pointer_type (typep
);
2739 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2742 case FT_signed_char
:
2743 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2746 case FT_unsigned_char
:
2747 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2751 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2754 case FT_signed_short
:
2755 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2758 case FT_unsigned_short
:
2759 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2763 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2766 case FT_signed_integer
:
2767 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2770 case FT_unsigned_integer
:
2771 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2775 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2778 case FT_signed_long
:
2779 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2782 case FT_unsigned_long
:
2783 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2787 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2790 case FT_signed_long_long
:
2791 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2794 case FT_unsigned_long_long
:
2795 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2799 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2802 case FT_dbl_prec_float
:
2803 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2806 case FT_ext_prec_float
:
2807 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2811 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2814 case FT_dbl_prec_complex
:
2815 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2818 case FT_ext_prec_complex
:
2819 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2824 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2826 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2827 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2837 create_name -- allocate a fresh copy of a string on an obstack
2841 Given a pointer to a string and a pointer to an obstack, allocates
2842 a fresh copy of the string on the specified obstack.
2847 create_name (name
, obstackp
)
2849 struct obstack
*obstackp
;
2854 length
= strlen (name
) + 1;
2855 newname
= (char *) obstack_alloc (obstackp
, length
);
2856 (void) strcpy (newname
, name
);
2864 basicdieinfo -- extract the minimal die info from raw die data
2868 void basicdieinfo (char *diep, struct dieinfo *dip)
2872 Given a pointer to raw DIE data, and a pointer to an instance of a
2873 die info structure, this function extracts the basic information
2874 from the DIE data required to continue processing this DIE, along
2875 with some bookkeeping information about the DIE.
2877 The information we absolutely must have includes the DIE tag,
2878 and the DIE length. If we need the sibling reference, then we
2879 will have to call completedieinfo() to process all the remaining
2882 Note that since there is no guarantee that the data is properly
2883 aligned in memory for the type of access required (indirection
2884 through anything other than a char pointer), we use memcpy to
2885 shuffle data items larger than a char. Possibly inefficient, but
2888 We also take care of some other basic things at this point, such
2889 as ensuring that the instance of the die info structure starts
2890 out completely zero'd and that curdie is initialized for use
2891 in error reporting if we have a problem with the current die.
2895 All DIE's must have at least a valid length, thus the minimum
2896 DIE size is sizeof (long). In order to have a valid tag, the
2897 DIE size must be at least sizeof (short) larger, otherwise they
2898 are forced to be TAG_padding DIES.
2900 Padding DIES must be at least sizeof(long) in length, implying that
2901 if a padding DIE is used for alignment and the amount needed is less
2902 than sizeof(long) then the padding DIE has to be big enough to align
2903 to the next alignment boundry.
2907 basicdieinfo (dip
, diep
)
2908 struct dieinfo
*dip
;
2912 (void) memset (dip
, 0, sizeof (struct dieinfo
));
2914 dip
-> dieref
= dbroff
+ (diep
- dbbase
);
2915 (void) memcpy (&dip
-> dielength
, diep
, sizeof (long));
2916 if (dip
-> dielength
< sizeof (long))
2918 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> dielength
);
2920 else if (dip
-> dielength
< (sizeof (long) + sizeof (short)))
2922 dip
-> dietag
= TAG_padding
;
2926 (void) memcpy (&dip
-> dietag
, diep
+ sizeof (long), sizeof (short));
2934 completedieinfo -- finish reading the information for a given DIE
2938 void completedieinfo (struct dieinfo *dip)
2942 Given a pointer to an already partially initialized die info structure,
2943 scan the raw DIE data and finish filling in the die info structure
2944 from the various attributes found.
2946 Note that since there is no guarantee that the data is properly
2947 aligned in memory for the type of access required (indirection
2948 through anything other than a char pointer), we use memcpy to
2949 shuffle data items larger than a char. Possibly inefficient, but
2954 Each time we are called, we increment the diecount variable, which
2955 keeps an approximate count of the number of dies processed for
2956 each compilation unit. This information is presented to the user
2957 if the info_verbose flag is set.
2962 completedieinfo (dip
)
2963 struct dieinfo
*dip
;
2965 char *diep
; /* Current pointer into raw DIE data */
2966 char *end
; /* Terminate DIE scan here */
2967 unsigned short attr
; /* Current attribute being scanned */
2968 unsigned short form
; /* Form of the attribute */
2969 short block2sz
; /* Size of a block2 attribute field */
2970 long block4sz
; /* Size of a block4 attribute field */
2974 end
= diep
+ dip
-> dielength
;
2975 diep
+= sizeof (long) + sizeof (short);
2978 (void) memcpy (&attr
, diep
, sizeof (short));
2979 diep
+= sizeof (short);
2983 (void) memcpy (&dip
-> at_fund_type
, diep
, sizeof (short));
2986 (void) memcpy (&dip
-> at_ordering
, diep
, sizeof (short));
2989 (void) memcpy (&dip
-> at_bit_offset
, diep
, sizeof (short));
2992 (void) memcpy (&dip
-> at_visibility
, diep
, sizeof (short));
2995 (void) memcpy (&dip
-> at_sibling
, diep
, sizeof (long));
2998 (void) memcpy (&dip
-> at_stmt_list
, diep
, sizeof (long));
2999 dip
-> has_at_stmt_list
= 1;
3002 (void) memcpy (&dip
-> at_low_pc
, diep
, sizeof (long));
3003 dip
-> at_low_pc
+= baseaddr
;
3004 dip
-> has_at_low_pc
= 1;
3007 (void) memcpy (&dip
-> at_high_pc
, diep
, sizeof (long));
3008 dip
-> at_high_pc
+= baseaddr
;
3011 (void) memcpy (&dip
-> at_language
, diep
, sizeof (long));
3013 case AT_user_def_type
:
3014 (void) memcpy (&dip
-> at_user_def_type
, diep
, sizeof (long));
3017 (void) memcpy (&dip
-> at_byte_size
, diep
, sizeof (long));
3020 (void) memcpy (&dip
-> at_bit_size
, diep
, sizeof (long));
3023 (void) memcpy (&dip
-> at_member
, diep
, sizeof (long));
3026 (void) memcpy (&dip
-> at_discr
, diep
, sizeof (long));
3029 (void) memcpy (&dip
-> at_import
, diep
, sizeof (long));
3032 dip
-> at_location
= diep
;
3034 case AT_mod_fund_type
:
3035 dip
-> at_mod_fund_type
= diep
;
3037 case AT_subscr_data
:
3038 dip
-> at_subscr_data
= diep
;
3040 case AT_mod_u_d_type
:
3041 dip
-> at_mod_u_d_type
= diep
;
3043 case AT_element_list
:
3044 dip
-> at_element_list
= diep
;
3045 dip
-> short_element_list
= 0;
3047 case AT_short_element_list
:
3048 dip
-> at_element_list
= diep
;
3049 dip
-> short_element_list
= 1;
3051 case AT_discr_value
:
3052 dip
-> at_discr_value
= diep
;
3054 case AT_string_length
:
3055 dip
-> at_string_length
= diep
;
3058 dip
-> at_name
= diep
;
3061 dip
-> at_comp_dir
= diep
;
3064 dip
-> at_producer
= diep
;
3067 (void) memcpy (&dip
-> at_frame_base
, diep
, sizeof (long));
3069 case AT_start_scope
:
3070 (void) memcpy (&dip
-> at_start_scope
, diep
, sizeof (long));
3072 case AT_stride_size
:
3073 (void) memcpy (&dip
-> at_stride_size
, diep
, sizeof (long));
3076 (void) memcpy (&dip
-> at_src_info
, diep
, sizeof (long));
3079 (void) memcpy (&dip
-> at_prototyped
, diep
, sizeof (short));
3082 /* Found an attribute that we are unprepared to handle. However
3083 it is specifically one of the design goals of DWARF that
3084 consumers should ignore unknown attributes. As long as the
3085 form is one that we recognize (so we know how to skip it),
3086 we can just ignore the unknown attribute. */
3093 diep
+= sizeof (short);
3096 diep
+= sizeof (long);
3099 diep
+= 8 * sizeof (char); /* sizeof (long long) ? */
3103 diep
+= sizeof (long);
3106 (void) memcpy (&block2sz
, diep
, sizeof (short));
3107 block2sz
+= sizeof (short);
3111 (void) memcpy (&block4sz
, diep
, sizeof (long));
3112 block4sz
+= sizeof (long);
3116 diep
+= strlen (diep
) + 1;
3119 SQUAWK (("unknown attribute form (0x%x), skipped rest", form
));