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. :-)
66 #include "elf/dwarf.h"
69 #ifdef MAINTENANCE /* Define to 1 to compile in some maintenance stuff */
70 #define SQUAWK(stuff) dwarfwarn stuff
75 #ifndef R_FP /* FIXME */
76 #define R_FP 14 /* Kludge to get frame pointer register number */
79 typedef unsigned int DIEREF
; /* Reference to a DIE */
82 #define GCC_PRODUCER "GNU C "
85 #define STREQ(a,b) (strcmp(a,b)==0)
86 #define STREQN(a,b,n) (strncmp(a,b,n)==0)
88 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
89 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
90 However, the Issue 2 DWARF specification from AT&T defines it as
91 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
92 For backwards compatibility with the AT&T compiler produced executables
93 we define AT_short_element_list for this variant. */
95 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
97 /* External variables referenced. */
99 extern int info_verbose
; /* From main.c; nonzero => verbose */
100 extern char *warning_pre_print
; /* From utils.c */
102 /* The DWARF debugging information consists of two major pieces,
103 one is a block of DWARF Information Entries (DIE's) and the other
104 is a line number table. The "struct dieinfo" structure contains
105 the information for a single DIE, the one currently being processed.
107 In order to make it easier to randomly access the attribute fields
108 of the current DIE, which are specifically unordered within the DIE
109 each DIE is scanned and an instance of the "struct dieinfo"
110 structure is initialized.
112 Initialization is done in two levels. The first, done by basicdieinfo(),
113 just initializes those fields that are vital to deciding whether or not
114 to use this DIE, how to skip past it, etc. The second, done by the
115 function completedieinfo(), fills in the rest of the information.
117 Attributes which have block forms are not interpreted at the time
118 the DIE is scanned, instead we just save pointers to the start
119 of their value fields.
121 Some fields have a flag <name>_p that is set when the value of the
122 field is valid (I.E. we found a matching attribute in the DIE). Since
123 we may want to test for the presence of some attributes in the DIE,
124 such as AT_low_pc, without restricting the values of the field,
125 we need someway to note that we found such an attribute.
132 char * die
; /* Pointer to the raw DIE data */
133 long dielength
; /* Length of the raw DIE data */
134 DIEREF dieref
; /* Offset of this DIE */
135 short dietag
; /* Tag for this DIE */
140 unsigned short at_fund_type
;
141 BLOCK
* at_mod_fund_type
;
142 long at_user_def_type
;
143 BLOCK
* at_mod_u_d_type
;
145 BLOCK
* at_subscr_data
;
149 BLOCK
* at_element_list
;
156 BLOCK
* at_discr_value
;
159 BLOCK
* at_string_length
;
167 unsigned int has_at_low_pc
:1;
168 unsigned int has_at_stmt_list
:1;
169 unsigned int short_element_list
:1;
172 static int diecount
; /* Approximate count of dies for compilation unit */
173 static struct dieinfo
*curdie
; /* For warnings and such */
175 static char *dbbase
; /* Base pointer to dwarf info */
176 static int dbroff
; /* Relative offset from start of .debug section */
177 static char *lnbase
; /* Base pointer to line section */
178 static int isreg
; /* Kludge to identify register variables */
179 static int offreg
; /* Kludge to identify basereg references */
181 static CORE_ADDR baseaddr
; /* Add to each symbol value */
183 /* Each partial symbol table entry contains a pointer to private data for the
184 read_symtab() function to use when expanding a partial symbol table entry
185 to a full symbol table entry. For DWARF debugging info, this data is
186 contained in the following structure and macros are provided for easy
187 access to the members given a pointer to a partial symbol table entry.
189 dbfoff Always the absolute file offset to the start of the ".debug"
190 section for the file containing the DIE's being accessed.
192 dbroff Relative offset from the start of the ".debug" access to the
193 first DIE to be accessed. When building the partial symbol
194 table, this value will be zero since we are accessing the
195 entire ".debug" section. When expanding a partial symbol
196 table entry, this value will be the offset to the first
197 DIE for the compilation unit containing the symbol that
198 triggers the expansion.
200 dblength The size of the chunk of DIE's being examined, in bytes.
202 lnfoff The absolute file offset to the line table fragment. Ignored
203 when building partial symbol tables, but used when expanding
204 them, and contains the absolute file offset to the fragment
205 of the ".line" section containing the line numbers for the
206 current compilation unit.
210 int dbfoff
; /* Absolute file offset to start of .debug section */
211 int dbroff
; /* Relative offset from start of .debug section */
212 int dblength
; /* Size of the chunk of DIE's being examined */
213 int lnfoff
; /* Absolute file offset to line table fragment */
216 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
217 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
218 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
219 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
221 /* The generic symbol table building routines have separate lists for
222 file scope symbols and all all other scopes (local scopes). So
223 we need to select the right one to pass to add_symbol_to_list().
224 We do it by keeping a pointer to the correct list in list_in_scope.
226 FIXME: The original dwarf code just treated the file scope as the first
227 local scope, and all other local scopes as nested local scopes, and worked
228 fine. Check to see if we really need to distinguish these in buildsym.c */
230 struct pending
**list_in_scope
= &file_symbols
;
232 /* DIES which have user defined types or modified user defined types refer to
233 other DIES for the type information. Thus we need to associate the offset
234 of a DIE for a user defined type with a pointer to the type information.
236 Originally this was done using a simple but expensive algorithm, with an
237 array of unsorted structures, each containing an offset/type-pointer pair.
238 This array was scanned linearly each time a lookup was done. The result
239 was that gdb was spending over half it's startup time munging through this
240 array of pointers looking for a structure that had the right offset member.
242 The second attempt used the same array of structures, but the array was
243 sorted using qsort each time a new offset/type was recorded, and a binary
244 search was used to find the type pointer for a given DIE offset. This was
245 even slower, due to the overhead of sorting the array each time a new
246 offset/type pair was entered.
248 The third attempt uses a fixed size array of type pointers, indexed by a
249 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
250 we can divide any DIE offset by 4 to obtain a unique index into this fixed
251 size array. Since each element is a 4 byte pointer, it takes exactly as
252 much memory to hold this array as to hold the DWARF info for a given
253 compilation unit. But it gets freed as soon as we are done with it. */
255 static struct type
**utypes
; /* Pointer to array of user type pointers */
256 static int numutypes
; /* Max number of user type pointers */
258 /* Forward declarations of static functions so we don't have to worry
259 about ordering within this file. */
262 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
265 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
268 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
271 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
278 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
281 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
282 unsigned int, struct objfile
*));
285 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
288 init_psymbol_list
PARAMS ((struct objfile
*, int));
291 basicdieinfo
PARAMS ((struct dieinfo
*, char *));
294 completedieinfo
PARAMS ((struct dieinfo
*));
297 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
300 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
302 static struct symtab
*
303 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
306 process_dies
PARAMS ((char *, char *, struct objfile
*));
309 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
313 decode_array_element_type
PARAMS ((char *, char *));
316 decode_subscr_data
PARAMS ((char *, char *));
319 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
322 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
325 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
328 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
331 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
334 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
337 decode_line_numbers
PARAMS ((char *));
340 decode_die_type
PARAMS ((struct dieinfo
*));
343 decode_mod_fund_type
PARAMS ((char *));
346 decode_mod_u_d_type
PARAMS ((char *));
349 decode_modified_type
PARAMS ((unsigned char *, unsigned int, int));
352 decode_fund_type
PARAMS ((unsigned int));
355 create_name
PARAMS ((char *, struct obstack
*));
358 lookup_utype
PARAMS ((DIEREF
));
361 alloc_utype
PARAMS ((DIEREF
, struct type
*));
363 static struct symbol
*
364 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
367 locval
PARAMS ((char *));
370 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
377 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
381 void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr,
382 int mainline, unsigned int dbfoff, unsigned int dbsize,
383 unsigned int lnoffset, unsigned int lnsize,
384 struct objfile *objfile)
388 This function is called upon to build partial symtabs from files
389 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
391 It is passed a file descriptor for an open file containing the DIES
392 and line number information, the corresponding filename for that
393 file, a base address for relocating the symbols, a flag indicating
394 whether or not this debugging information is from a "main symbol
395 table" rather than a shared library or dynamically linked file,
396 and file offset/size pairs for the DIE information and line number
406 dwarf_build_psymtabs (desc
, filename
, addr
, mainline
, dbfoff
, dbsize
,
407 lnoffset
, lnsize
, objfile
)
414 unsigned int lnoffset
;
416 struct objfile
*objfile
;
418 struct cleanup
*back_to
;
420 dbbase
= xmalloc (dbsize
);
422 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
423 (read (desc
, dbbase
, dbsize
) != dbsize
))
426 error ("can't read DWARF data from '%s'", filename
);
428 back_to
= make_cleanup (free
, dbbase
);
430 /* If we are reinitializing, or if we have never loaded syms yet, init.
431 Since we have no idea how many DIES we are looking at, we just guess
432 some arbitrary value. */
434 if (mainline
|| objfile
->global_psymbols
.size
== 0 || objfile
->static_psymbols
.size
== 0)
436 init_psymbol_list (objfile
, 1024);
439 /* From this point on, we don't need to pass mainline around, so zap
440 baseaddr to zero if we don't need relocation. */
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
);
466 record_minimal_symbol -- add entry to gdb's minimal symbol table
470 static void record_minimal_symbol (char *name, CORE_ADDR address,
471 enum minimal_symbol_type ms_type,
472 struct objfile *objfile)
476 Given a pointer to the name of a symbol that should be added to the
477 minimal symbol table, and the address associated with that
478 symbol, records this information for later use in building the
479 minimal symbol table.
484 record_minimal_symbol (name
, address
, ms_type
, objfile
)
487 enum minimal_symbol_type ms_type
;
488 struct objfile
*objfile
;
490 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
491 prim_record_minimal_symbol (name
, address
, ms_type
);
498 dwarfwarn -- issue a DWARF related warning
502 Issue warnings about DWARF related things that aren't serious enough
503 to warrant aborting with an error, but should not be ignored either.
504 This includes things like detectable corruption in DIE's, missing
505 DIE's, unimplemented features, etc.
507 In general, running across tags or attributes that we don't recognize
508 is not considered to be a problem and we should not issue warnings
513 We mostly follow the example of the error() routine, but without
514 returning to command level. It is arguable about whether warnings
515 should be issued at all, and if so, where they should go (stdout or
518 We assume that curdie is valid and contains at least the basic
519 information for the DIE where the problem was noticed.
530 fmt
= va_arg (ap
, char *);
532 fprintf (stderr
, "warning: DWARF ref 0x%x: ", curdie
-> dieref
);
533 if (curdie
-> at_name
)
535 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
537 vfprintf (stderr
, fmt
, ap
);
538 fprintf (stderr
, "\n");
547 read_lexical_block_scope -- process all dies in a lexical block
551 static void read_lexical_block_scope (struct dieinfo *dip,
552 char *thisdie, char *enddie)
556 Process all the DIES contained within a lexical block scope.
557 Start a new scope, process the dies, and then close the scope.
562 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
566 struct objfile
*objfile
;
568 register struct context_stack
*new;
570 (void) push_context (0, dip
-> at_low_pc
);
571 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
572 new = pop_context ();
573 if (local_symbols
!= NULL
)
575 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
576 dip
-> at_high_pc
, objfile
);
578 local_symbols
= new -> locals
;
585 lookup_utype -- look up a user defined type from die reference
589 static type *lookup_utype (DIEREF dieref)
593 Given a DIE reference, lookup the user defined type associated with
594 that DIE, if it has been registered already. If not registered, then
595 return NULL. Alloc_utype() can be called to register an empty
596 type for this reference, which will be filled in later when the
597 actual referenced DIE is processed.
601 lookup_utype (dieref
)
604 struct type
*type
= NULL
;
607 utypeidx
= (dieref
- dbroff
) / 4;
608 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
610 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
614 type
= *(utypes
+ utypeidx
);
624 alloc_utype -- add a user defined type for die reference
628 static type *alloc_utype (DIEREF dieref, struct type *utypep)
632 Given a die reference DIEREF, and a possible pointer to a user
633 defined type UTYPEP, register that this reference has a user
634 defined type and either use the specified type in UTYPEP or
635 make a new empty type that will be filled in later.
637 We should only be called after calling lookup_utype() to verify that
638 there is not currently a type registered for DIEREF.
642 alloc_utype (dieref
, utypep
)
649 utypeidx
= (dieref
- dbroff
) / 4;
650 typep
= utypes
+ utypeidx
;
651 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
653 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
654 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
656 else if (*typep
!= NULL
)
659 SQUAWK (("internal error: dup user type allocation"));
665 utypep
= (struct type
*)
666 obstack_alloc (¤t_objfile
-> type_obstack
,
667 sizeof (struct type
));
668 (void) memset (utypep
, 0, sizeof (struct type
));
669 TYPE_OBJFILE (utypep
) = current_objfile
;
680 decode_die_type -- return a type for a specified die
684 static struct type *decode_die_type (struct dieinfo *dip)
688 Given a pointer to a die information structure DIP, decode the
689 type of the die and return a pointer to the decoded type. All
690 dies without specific types default to type int.
694 decode_die_type (dip
)
697 struct type
*type
= NULL
;
699 if (dip
-> at_fund_type
!= 0)
701 type
= decode_fund_type (dip
-> at_fund_type
);
703 else if (dip
-> at_mod_fund_type
!= NULL
)
705 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
707 else if (dip
-> at_user_def_type
)
709 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
711 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
714 else if (dip
-> at_mod_u_d_type
)
716 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
720 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
729 struct_type -- compute and return the type for a struct or union
733 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
734 char *enddie, struct objfile *objfile)
738 Given pointer to a die information structure for a die which
739 defines a union or structure (and MUST define one or the other),
740 and pointers to the raw die data that define the range of dies which
741 define the members, compute and return the user defined type for the
746 struct_type (dip
, thisdie
, enddie
, objfile
)
750 struct objfile
*objfile
;
754 struct nextfield
*next
;
757 struct nextfield
*list
= NULL
;
758 struct nextfield
*new;
765 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
767 /* No forward references created an empty type, so install one now */
768 type
= alloc_utype (dip
-> dieref
, NULL
);
770 INIT_CPLUS_SPECIFIC(type
);
771 switch (dip
-> dietag
)
773 case TAG_structure_type
:
774 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
778 TYPE_CODE (type
) = TYPE_CODE_UNION
;
782 /* Should never happen */
783 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
785 SQUAWK (("missing structure or union tag"));
788 /* Some compilers try to be helpful by inventing "fake" names for
789 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
790 Thanks, but no thanks... */
791 if (dip
-> at_name
!= NULL
792 && *dip
-> at_name
!= '~'
793 && *dip
-> at_name
!= '.')
795 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
,
796 tpart1
, " ", dip
-> at_name
);
798 if (dip
-> at_byte_size
!= 0)
800 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
802 thisdie
+= dip
-> dielength
;
803 while (thisdie
< enddie
)
805 basicdieinfo (&mbr
, thisdie
);
806 completedieinfo (&mbr
);
807 if (mbr
.dielength
<= sizeof (long))
811 else if (mbr
.at_sibling
!= 0)
813 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
817 nextdie
= thisdie
+ mbr
.dielength
;
822 /* Get space to record the next field's data. */
823 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
827 list
-> field
.name
= savestring (mbr
.at_name
, strlen (mbr
.at_name
));
828 list
-> field
.type
= decode_die_type (&mbr
);
829 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
830 list
-> field
.bitsize
= 0;
834 process_dies (thisdie
, nextdie
, objfile
);
839 /* Now create the vector of fields, and record how big it is. We may
840 not even have any fields, if this DIE was generated due to a reference
841 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
842 set, which clues gdb in to the fact that it needs to search elsewhere
843 for the full structure definition. */
846 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
850 TYPE_NFIELDS (type
) = nfields
;
851 TYPE_FIELDS (type
) = (struct field
*)
852 obstack_alloc (¤t_objfile
-> type_obstack
,
853 sizeof (struct field
) * nfields
);
854 /* Copy the saved-up fields into the field vector. */
855 for (n
= nfields
; list
; list
= list
-> next
)
857 TYPE_FIELD (type
, --n
) = list
-> field
;
867 read_structure_scope -- process all dies within struct or union
871 static void read_structure_scope (struct dieinfo *dip,
872 char *thisdie, char *enddie, struct objfile *objfile)
876 Called when we find the DIE that starts a structure or union
877 scope (definition) to process all dies that define the members
878 of the structure or union. DIP is a pointer to the die info
879 struct for the DIE that names the structure or union.
883 Note that we need to call struct_type regardless of whether or not
884 the DIE has an at_name attribute, since it might be an anonymous
885 structure or union. This gets the type entered into our set of
888 However, if the structure is incomplete (an opaque struct/union)
889 then suppress creating a symbol table entry for it since gdb only
890 wants to find the one with the complete definition. Note that if
891 it is complete, we just call new_symbol, which does it's own
892 checking about whether the struct/union is anonymous or not (and
893 suppresses creating a symbol table entry itself).
898 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
902 struct objfile
*objfile
;
907 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
908 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
910 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
912 SYMBOL_TYPE (sym
) = type
;
921 decode_array_element_type -- decode type of the array elements
925 static struct type *decode_array_element_type (char *scan, char *end)
929 As the last step in decoding the array subscript information for an
930 array DIE, we need to decode the type of the array elements. We are
931 passed a pointer to this last part of the subscript information and
932 must return the appropriate type. If the type attribute is not
933 recognized, just warn about the problem and return type int.
937 decode_array_element_type (scan
, end
)
944 unsigned short fundtype
;
946 (void) memcpy (&attribute
, scan
, sizeof (short));
947 scan
+= sizeof (short);
951 (void) memcpy (&fundtype
, scan
, sizeof (short));
952 typep
= decode_fund_type (fundtype
);
954 case AT_mod_fund_type
:
955 typep
= decode_mod_fund_type (scan
);
957 case AT_user_def_type
:
958 (void) memcpy (&dieref
, scan
, sizeof (DIEREF
));
959 if ((typep
= lookup_utype (dieref
)) == NULL
)
961 typep
= alloc_utype (dieref
, NULL
);
964 case AT_mod_u_d_type
:
965 typep
= decode_mod_u_d_type (scan
);
968 SQUAWK (("bad array element type attribute 0x%x", attribute
));
969 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
979 decode_subscr_data -- decode array subscript and element type data
983 static struct type *decode_subscr_data (char *scan, char *end)
987 The array subscripts and the data type of the elements of an
988 array are described by a list of data items, stored as a block
989 of contiguous bytes. There is a data item describing each array
990 dimension, and a final data item describing the element type.
991 The data items are ordered the same as their appearance in the
992 source (I.E. leftmost dimension first, next to leftmost second,
995 We are passed a pointer to the start of the block of bytes
996 containing the data items, and a pointer to the first byte past
997 the data. This function decodes the data and returns a type.
1000 FIXME: This code only implements the forms currently used
1001 by the AT&T and GNU C compilers.
1003 The end pointer is supplied for error checking, maybe we should
1007 static struct type
*
1008 decode_subscr_data (scan
, end
)
1012 struct type
*typep
= NULL
;
1013 struct type
*nexttype
;
1023 typep
= decode_array_element_type (scan
, end
);
1026 (void) memcpy (&fundtype
, scan
, sizeof (short));
1027 scan
+= sizeof (short);
1028 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1029 && fundtype
!= FT_unsigned_integer
)
1031 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1036 (void) memcpy (&lowbound
, scan
, sizeof (long));
1037 scan
+= sizeof (long);
1038 (void) memcpy (&highbound
, scan
, sizeof (long));
1039 scan
+= sizeof (long);
1040 nexttype
= decode_subscr_data (scan
, end
);
1041 if (nexttype
!= NULL
)
1043 typep
= (struct type
*)
1044 obstack_alloc (¤t_objfile
-> type_obstack
,
1045 sizeof (struct type
));
1046 (void) memset (typep
, 0, sizeof (struct type
));
1047 TYPE_OBJFILE (typep
) = current_objfile
;
1048 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1049 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1050 TYPE_LENGTH (typep
) *= lowbound
+ highbound
+ 1;
1051 TYPE_TARGET_TYPE (typep
) = nexttype
;
1062 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1065 SQUAWK (("unknown array subscript format %x", format
));
1075 dwarf_read_array_type -- read TAG_array_type DIE
1079 static void dwarf_read_array_type (struct dieinfo *dip)
1083 Extract all information from a TAG_array_type DIE and add to
1084 the user defined type vector.
1088 dwarf_read_array_type (dip
)
1089 struct dieinfo
*dip
;
1097 if (dip
-> at_ordering
!= ORD_row_major
)
1099 /* FIXME: Can gdb even handle column major arrays? */
1100 SQUAWK (("array not row major; not handled correctly"));
1102 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1104 (void) memcpy (&temp
, sub
, sizeof (short));
1105 subend
= sub
+ sizeof (short) + temp
;
1106 sub
+= sizeof (short);
1107 type
= decode_subscr_data (sub
, subend
);
1110 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1112 utype
= alloc_utype (dip
-> dieref
, NULL
);
1114 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1115 TYPE_TARGET_TYPE (utype
) =
1116 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1117 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1121 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1123 (void) alloc_utype (dip
-> dieref
, type
);
1127 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1128 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1129 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1139 read_tag_pointer_type -- read TAG_pointer_type DIE
1143 static void read_tag_pointer_type (struct dieinfo *dip)
1147 Extract all information from a TAG_pointer_type DIE and add to
1148 the user defined type vector.
1152 read_tag_pointer_type (dip
)
1153 struct dieinfo
*dip
;
1158 type
= decode_die_type (dip
);
1159 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1161 utype
= lookup_pointer_type (type
);
1162 (void) alloc_utype (dip
-> dieref
, utype
);
1166 TYPE_TARGET_TYPE (utype
) = type
;
1167 TYPE_POINTER_TYPE (type
) = utype
;
1169 /* We assume the machine has only one representation for pointers! */
1170 /* FIXME: This confuses host<->target data representations, and is a
1171 poor assumption besides. */
1173 TYPE_LENGTH (utype
) = sizeof (char *);
1174 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1182 read_subroutine_type -- process TAG_subroutine_type dies
1186 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1191 Handle DIES due to C code like:
1194 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1200 The parameter DIES are currently ignored. See if gdb has a way to
1201 include this info in it's type system, and decode them if so. Is
1202 this what the type structure's "arg_types" field is for? (FIXME)
1206 read_subroutine_type (dip
, thisdie
, enddie
)
1207 struct dieinfo
*dip
;
1211 struct type
*type
; /* Type that this function returns */
1212 struct type
*ftype
; /* Function that returns above type */
1214 /* Decode the type that this subroutine returns */
1216 type
= decode_die_type (dip
);
1218 /* Check to see if we already have a partially constructed user
1219 defined type for this DIE, from a forward reference. */
1221 if ((ftype
= lookup_utype (dip
-> dieref
)) == NULL
)
1223 /* This is the first reference to one of these types. Make
1224 a new one and place it in the user defined types. */
1225 ftype
= lookup_function_type (type
);
1226 (void) alloc_utype (dip
-> dieref
, ftype
);
1230 /* We have an existing partially constructed type, so bash it
1231 into the correct type. */
1232 TYPE_TARGET_TYPE (ftype
) = type
;
1233 TYPE_FUNCTION_TYPE (type
) = ftype
;
1234 TYPE_LENGTH (ftype
) = 1;
1235 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1243 read_enumeration -- process dies which define an enumeration
1247 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1248 char *enddie, struct objfile *objfile)
1252 Given a pointer to a die which begins an enumeration, process all
1253 the dies that define the members of the enumeration.
1257 Note that we need to call enum_type regardless of whether or not we
1258 have a symbol, since we might have an enum without a tag name (thus
1259 no symbol for the tagname).
1263 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1264 struct dieinfo
*dip
;
1267 struct objfile
*objfile
;
1272 type
= enum_type (dip
, objfile
);
1273 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1275 SYMBOL_TYPE (sym
) = type
;
1283 enum_type -- decode and return a type for an enumeration
1287 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1291 Given a pointer to a die information structure for the die which
1292 starts an enumeration, process all the dies that define the members
1293 of the enumeration and return a type pointer for the enumeration.
1295 At the same time, for each member of the enumeration, create a
1296 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1297 and give it the type of the enumeration itself.
1301 Note that the DWARF specification explicitly mandates that enum
1302 constants occur in reverse order from the source program order,
1303 for "consistency" and because this ordering is easier for many
1304 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1305 Entries). Because gdb wants to see the enum members in program
1306 source order, we have to ensure that the order gets reversed while
1307 we are processing them.
1310 static struct type
*
1311 enum_type (dip
, objfile
)
1312 struct dieinfo
*dip
;
1313 struct objfile
*objfile
;
1317 struct nextfield
*next
;
1320 struct nextfield
*list
= NULL
;
1321 struct nextfield
*new;
1330 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
1332 /* No forward references created an empty type, so install one now */
1333 type
= alloc_utype (dip
-> dieref
, NULL
);
1335 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1336 /* Some compilers try to be helpful by inventing "fake" names for
1337 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1338 Thanks, but no thanks... */
1339 if (dip
-> at_name
!= NULL
1340 && *dip
-> at_name
!= '~'
1341 && *dip
-> at_name
!= '.')
1343 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
, "enum",
1344 " ", dip
-> at_name
);
1346 if (dip
-> at_byte_size
!= 0)
1348 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1350 if ((scan
= dip
-> at_element_list
) != NULL
)
1352 if (dip
-> short_element_list
)
1354 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
1355 listend
= scan
+ stemp
+ sizeof (stemp
);
1356 scan
+= sizeof (stemp
);
1360 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
1361 listend
= scan
+ ltemp
+ sizeof (ltemp
);
1362 scan
+= sizeof (ltemp
);
1364 while (scan
< listend
)
1366 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1369 list
-> field
.type
= NULL
;
1370 list
-> field
.bitsize
= 0;
1371 (void) memcpy (&list
-> field
.bitpos
, scan
, sizeof (long));
1372 scan
+= sizeof (long);
1373 list
-> field
.name
= savestring (scan
, strlen (scan
));
1374 scan
+= strlen (scan
) + 1;
1376 /* Handcraft a new symbol for this enum member. */
1377 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1378 sizeof (struct symbol
));
1379 (void) memset (sym
, 0, sizeof (struct symbol
));
1380 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
, &objfile
->symbol_obstack
);
1381 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1382 SYMBOL_CLASS (sym
) = LOC_CONST
;
1383 SYMBOL_TYPE (sym
) = type
;
1384 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1385 add_symbol_to_list (sym
, list_in_scope
);
1387 /* Now create the vector of fields, and record how big it is. This is
1388 where we reverse the order, by pulling the members of the list in
1389 reverse order from how they were inserted. If we have no fields
1390 (this is apparently possible in C++) then skip building a field
1394 TYPE_NFIELDS (type
) = nfields
;
1395 TYPE_FIELDS (type
) = (struct field
*)
1396 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1397 /* Copy the saved-up fields into the field vector. */
1398 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1400 TYPE_FIELD (type
, n
++) = list
-> field
;
1411 read_func_scope -- process all dies within a function scope
1415 Process all dies within a given function scope. We are passed
1416 a die information structure pointer DIP for the die which
1417 starts the function scope, and pointers into the raw die data
1418 that define the dies within the function scope.
1420 For now, we ignore lexical block scopes within the function.
1421 The problem is that AT&T cc does not define a DWARF lexical
1422 block scope for the function itself, while gcc defines a
1423 lexical block scope for the function. We need to think about
1424 how to handle this difference, or if it is even a problem.
1429 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1430 struct dieinfo
*dip
;
1433 struct objfile
*objfile
;
1435 register struct context_stack
*new;
1437 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1438 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1440 objfile
-> ei
.entry_func_lowpc
= dip
-> at_low_pc
;
1441 objfile
-> ei
.entry_func_highpc
= dip
-> at_high_pc
;
1443 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1445 objfile
-> ei
.main_func_lowpc
= dip
-> at_low_pc
;
1446 objfile
-> ei
.main_func_highpc
= dip
-> at_high_pc
;
1448 new = push_context (0, dip
-> at_low_pc
);
1449 new -> name
= new_symbol (dip
, objfile
);
1450 list_in_scope
= &local_symbols
;
1451 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1452 new = pop_context ();
1453 /* Make a block for the local symbols within. */
1454 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1455 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1456 list_in_scope
= &file_symbols
;
1463 read_file_scope -- process all dies within a file scope
1467 Process all dies within a given file scope. We are passed a
1468 pointer to the die information structure for the die which
1469 starts the file scope, and pointers into the raw die data which
1470 mark the range of dies within the file scope.
1472 When the partial symbol table is built, the file offset for the line
1473 number table for each compilation unit is saved in the partial symbol
1474 table entry for that compilation unit. As the symbols for each
1475 compilation unit are read, the line number table is read into memory
1476 and the variable lnbase is set to point to it. Thus all we have to
1477 do is use lnbase to access the line number table for the current
1482 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1483 struct dieinfo
*dip
;
1486 struct objfile
*objfile
;
1488 struct cleanup
*back_to
;
1489 struct symtab
*symtab
;
1491 if (objfile
-> ei
.entry_point
>= dip
-> at_low_pc
&&
1492 objfile
-> ei
.entry_point
< dip
-> at_high_pc
)
1494 objfile
-> ei
.entry_file_lowpc
= dip
-> at_low_pc
;
1495 objfile
-> ei
.entry_file_highpc
= dip
-> at_high_pc
;
1497 if (dip
-> at_producer
!= NULL
)
1499 processing_gcc_compilation
=
1500 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1502 numutypes
= (enddie
- thisdie
) / 4;
1503 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1504 back_to
= make_cleanup (free
, utypes
);
1505 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1506 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1507 decode_line_numbers (lnbase
);
1508 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1509 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1510 /* FIXME: The following may need to be expanded for other languages */
1511 switch (dip
-> at_language
)
1515 symtab
-> language
= language_c
;
1517 case LANG_C_PLUS_PLUS
:
1518 symtab
-> language
= language_cplus
;
1523 do_cleanups (back_to
);
1532 process_dies -- process a range of DWARF Information Entries
1536 static void process_dies (char *thisdie, char *enddie,
1537 struct objfile *objfile)
1541 Process all DIE's in a specified range. May be (and almost
1542 certainly will be) called recursively.
1546 process_dies (thisdie
, enddie
, objfile
)
1549 struct objfile
*objfile
;
1554 while (thisdie
< enddie
)
1556 basicdieinfo (&di
, thisdie
);
1557 if (di
.dielength
< sizeof (long))
1561 else if (di
.dietag
== TAG_padding
)
1563 nextdie
= thisdie
+ di
.dielength
;
1567 completedieinfo (&di
);
1568 if (di
.at_sibling
!= 0)
1570 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1574 nextdie
= thisdie
+ di
.dielength
;
1578 case TAG_compile_unit
:
1579 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1581 case TAG_global_subroutine
:
1582 case TAG_subroutine
:
1583 if (di
.has_at_low_pc
)
1585 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1588 case TAG_lexical_block
:
1589 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1591 case TAG_structure_type
:
1592 case TAG_union_type
:
1593 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1595 case TAG_enumeration_type
:
1596 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1598 case TAG_subroutine_type
:
1599 read_subroutine_type (&di
, thisdie
, nextdie
);
1601 case TAG_array_type
:
1602 dwarf_read_array_type (&di
);
1604 case TAG_pointer_type
:
1605 read_tag_pointer_type (&di
);
1608 (void) new_symbol (&di
, objfile
);
1620 decode_line_numbers -- decode a line number table fragment
1624 static void decode_line_numbers (char *tblscan, char *tblend,
1625 long length, long base, long line, long pc)
1629 Translate the DWARF line number information to gdb form.
1631 The ".line" section contains one or more line number tables, one for
1632 each ".line" section from the objects that were linked.
1634 The AT_stmt_list attribute for each TAG_source_file entry in the
1635 ".debug" section contains the offset into the ".line" section for the
1636 start of the table for that file.
1638 The table itself has the following structure:
1640 <table length><base address><source statement entry>
1641 4 bytes 4 bytes 10 bytes
1643 The table length is the total size of the table, including the 4 bytes
1644 for the length information.
1646 The base address is the address of the first instruction generated
1647 for the source file.
1649 Each source statement entry has the following structure:
1651 <line number><statement position><address delta>
1652 4 bytes 2 bytes 4 bytes
1654 The line number is relative to the start of the file, starting with
1657 The statement position either -1 (0xFFFF) or the number of characters
1658 from the beginning of the line to the beginning of the statement.
1660 The address delta is the difference between the base address and
1661 the address of the first instruction for the statement.
1663 Note that we must copy the bytes from the packed table to our local
1664 variables before attempting to use them, to avoid alignment problems
1665 on some machines, particularly RISC processors.
1669 Does gdb expect the line numbers to be sorted? They are now by
1670 chance/luck, but are not required to be. (FIXME)
1672 The line with number 0 is unused, gdb apparently can discover the
1673 span of the last line some other way. How? (FIXME)
1677 decode_line_numbers (linetable
)
1687 if (linetable
!= NULL
)
1689 tblscan
= tblend
= linetable
;
1690 (void) memcpy (&length
, tblscan
, sizeof (long));
1691 tblscan
+= sizeof (long);
1693 (void) memcpy (&base
, tblscan
, sizeof (long));
1695 tblscan
+= sizeof (long);
1696 while (tblscan
< tblend
)
1698 (void) memcpy (&line
, tblscan
, sizeof (long));
1699 tblscan
+= sizeof (long) + sizeof (short);
1700 (void) memcpy (&pc
, tblscan
, sizeof (long));
1701 tblscan
+= sizeof (long);
1705 record_line (current_subfile
, line
, pc
);
1715 locval -- compute the value of a location attribute
1719 static int locval (char *loc)
1723 Given pointer to a string of bytes that define a location, compute
1724 the location and return the value.
1726 When computing values involving the current value of the frame pointer,
1727 the value zero is used, which results in a value relative to the frame
1728 pointer, rather than the absolute value. This is what GDB wants
1731 When the result is a register number, the global isreg flag is set,
1732 otherwise it is cleared. This is a kludge until we figure out a better
1733 way to handle the problem. Gdb's design does not mesh well with the
1734 DWARF notion of a location computing interpreter, which is a shame
1735 because the flexibility goes unused.
1739 Note that stack[0] is unused except as a default error return.
1740 Note that stack overflow is not yet handled.
1747 unsigned short nbytes
;
1753 (void) memcpy (&nbytes
, loc
, sizeof (short));
1754 end
= loc
+ sizeof (short) + nbytes
;
1759 for (loc
+= sizeof (short); loc
< end
; loc
+= sizeof (long))
1767 /* push register (number) */
1768 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1772 /* push value of register (number) */
1773 /* Actually, we compute the value as if register has 0 */
1775 (void) memcpy (®no
, loc
, sizeof (long));
1778 stack
[++stacki
] = 0;
1782 stack
[++stacki
] = 0;
1783 SQUAWK (("BASEREG %d not handled!", regno
));
1787 /* push address (relocated address) */
1788 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1791 /* push constant (number) */
1792 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1795 /* pop, deref and push 2 bytes (as a long) */
1796 SQUAWK (("OP_DEREF2 address %#x not handled", stack
[stacki
]));
1798 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1799 SQUAWK (("OP_DEREF4 address %#x not handled", stack
[stacki
]));
1801 case OP_ADD
: /* pop top 2 items, add, push result */
1802 stack
[stacki
- 1] += stack
[stacki
];
1807 return (stack
[stacki
]);
1814 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1818 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1822 When expanding a partial symbol table entry to a full symbol table
1823 entry, this is the function that gets called to read in the symbols
1824 for the compilation unit.
1826 Returns a pointer to the newly constructed symtab (which is now
1827 the new first one on the objfile's symtab list).
1830 static struct symtab
*
1831 read_ofile_symtab (pst
)
1832 struct partial_symtab
*pst
;
1834 struct cleanup
*back_to
;
1839 abfd
= pst
-> objfile
-> obfd
;
1840 current_objfile
= pst
-> objfile
;
1842 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1843 unit, seek to the location in the file, and read in all the DIE's. */
1846 dbbase
= xmalloc (DBLENGTH(pst
));
1847 dbroff
= DBROFF(pst
);
1848 foffset
= DBFOFF(pst
) + dbroff
;
1849 baseaddr
= pst
-> addr
;
1850 if (bfd_seek (abfd
, foffset
, 0) ||
1851 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1854 error ("can't read DWARF data");
1856 back_to
= make_cleanup (free
, dbbase
);
1858 /* If there is a line number table associated with this compilation unit
1859 then read the first long word from the line number table fragment, which
1860 contains the size of the fragment in bytes (including the long word
1861 itself). Allocate a buffer for the fragment and read it in for future
1867 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1868 (bfd_read (&lnsize
, sizeof(long), 1, abfd
) != sizeof(long)))
1870 error ("can't read DWARF line number table size");
1872 lnbase
= xmalloc (lnsize
);
1873 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1874 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1877 error ("can't read DWARF line numbers");
1879 make_cleanup (free
, lnbase
);
1882 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1883 do_cleanups (back_to
);
1884 current_objfile
= NULL
;
1885 return (pst
-> objfile
-> symtabs
);
1892 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1896 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1900 Called once for each partial symbol table entry that needs to be
1901 expanded into a full symbol table entry.
1906 psymtab_to_symtab_1 (pst
)
1907 struct partial_symtab
*pst
;
1915 warning ("psymtab for %s already read in. Shouldn't happen.",
1920 /* Read in all partial symtabs on which this one is dependent */
1921 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
1923 if (!pst
-> dependencies
[i
] -> readin
)
1925 /* Inform about additional files that need to be read in. */
1928 fputs_filtered (" ", stdout
);
1930 fputs_filtered ("and ", stdout
);
1932 printf_filtered ("%s...",
1933 pst
-> dependencies
[i
] -> filename
);
1935 fflush (stdout
); /* Flush output */
1937 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
1940 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
1942 pst
-> symtab
= read_ofile_symtab (pst
);
1945 printf_filtered ("%d DIE's, sorting...", diecount
);
1949 sort_symtab_syms (pst
-> symtab
);
1960 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
1964 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
1968 This is the DWARF support entry point for building a full symbol
1969 table entry from a partial symbol table entry. We are passed a
1970 pointer to the partial symbol table entry that needs to be expanded.
1975 dwarf_psymtab_to_symtab (pst
)
1976 struct partial_symtab
*pst
;
1983 warning ("psymtab for %s already read in. Shouldn't happen.",
1988 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
1990 /* Print the message now, before starting serious work, to avoid
1991 disconcerting pauses. */
1994 printf_filtered ("Reading in symbols for %s...",
1999 psymtab_to_symtab_1 (pst
);
2001 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2002 we need to do an equivalent or is this something peculiar to
2004 Match with global symbols. This only needs to be done once,
2005 after all of the symtabs and dependencies have been read in.
2007 scan_file_globals (pst
-> objfile
);
2010 /* Finish up the verbose info message. */
2013 printf_filtered ("done.\n");
2025 init_psymbol_list -- initialize storage for partial symbols
2029 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2033 Initializes storage for all of the partial symbols that will be
2034 created by dwarf_build_psymtabs and subsidiaries.
2038 init_psymbol_list (objfile
, total_symbols
)
2039 struct objfile
*objfile
;
2042 /* Free any previously allocated psymbol lists. */
2044 if (objfile
-> global_psymbols
.list
)
2046 mfree (objfile
-> md
, objfile
-> global_psymbols
.list
);
2048 if (objfile
-> static_psymbols
.list
)
2050 mfree (objfile
-> md
, objfile
-> static_psymbols
.list
);
2053 /* Current best guess is that there are approximately a twentieth
2054 of the total symbols (in a debugging file) are global or static
2057 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2058 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2059 objfile
-> global_psymbols
.next
=
2060 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2061 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
2062 * sizeof (struct partial_symbol
));
2063 objfile
-> static_psymbols
.next
=
2064 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2065 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
2066 * sizeof (struct partial_symbol
));
2073 add_enum_psymbol -- add enumeration members to partial symbol table
2077 Given pointer to a DIE that is known to be for an enumeration,
2078 extract the symbolic names of the enumeration members and add
2079 partial symbols for them.
2083 add_enum_psymbol (dip
, objfile
)
2084 struct dieinfo
*dip
;
2085 struct objfile
*objfile
;
2092 if ((scan
= dip
-> at_element_list
) != NULL
)
2094 if (dip
-> short_element_list
)
2096 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
2097 listend
= scan
+ stemp
+ sizeof (stemp
);
2098 scan
+= sizeof (stemp
);
2102 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
2103 listend
= scan
+ ltemp
+ sizeof (ltemp
);
2104 scan
+= sizeof (ltemp
);
2106 while (scan
< listend
)
2108 scan
+= sizeof (long);
2109 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2110 objfile
-> static_psymbols
, 0);
2111 scan
+= strlen (scan
) + 1;
2120 add_partial_symbol -- add symbol to partial symbol table
2124 Given a DIE, if it is one of the types that we want to
2125 add to a partial symbol table, finish filling in the die info
2126 and then add a partial symbol table entry for it.
2131 add_partial_symbol (dip
, objfile
)
2132 struct dieinfo
*dip
;
2133 struct objfile
*objfile
;
2135 switch (dip
-> dietag
)
2137 case TAG_global_subroutine
:
2138 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2140 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2141 VAR_NAMESPACE
, LOC_BLOCK
,
2142 objfile
-> global_psymbols
,
2145 case TAG_global_variable
:
2146 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2148 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2149 VAR_NAMESPACE
, LOC_STATIC
,
2150 objfile
-> global_psymbols
,
2153 case TAG_subroutine
:
2154 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2155 VAR_NAMESPACE
, LOC_BLOCK
,
2156 objfile
-> static_psymbols
,
2159 case TAG_local_variable
:
2160 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2161 VAR_NAMESPACE
, LOC_STATIC
,
2162 objfile
-> static_psymbols
,
2166 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2167 VAR_NAMESPACE
, LOC_TYPEDEF
,
2168 objfile
-> static_psymbols
,
2171 case TAG_structure_type
:
2172 case TAG_union_type
:
2173 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2174 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2175 objfile
-> static_psymbols
,
2178 case TAG_enumeration_type
:
2181 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2182 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2183 objfile
-> static_psymbols
,
2186 add_enum_psymbol (dip
, objfile
);
2195 scan_partial_symbols -- scan DIE's within a single compilation unit
2199 Process the DIE's within a single compilation unit, looking for
2200 interesting DIE's that contribute to the partial symbol table entry
2201 for this compilation unit. Since we cannot follow any sibling
2202 chains without reading the complete DIE info for every DIE,
2203 it is probably faster to just sequentially check each one to
2204 see if it is one of the types we are interested in, and if so,
2205 then extract all the attributes info and generate a partial
2210 Don't attempt to add anonymous structures or unions since they have
2211 no name. Anonymous enumerations however are processed, because we
2212 want to extract their member names (the check for a tag name is
2215 Also, for variables and subroutines, check that this is the place
2216 where the actual definition occurs, rather than just a reference
2221 scan_partial_symbols (thisdie
, enddie
, objfile
)
2224 struct objfile
*objfile
;
2229 while (thisdie
< enddie
)
2231 basicdieinfo (&di
, thisdie
);
2232 if (di
.dielength
< sizeof (long))
2238 nextdie
= thisdie
+ di
.dielength
;
2239 /* To avoid getting complete die information for every die, we
2240 only do it (below) for the cases we are interested in. */
2243 case TAG_global_subroutine
:
2244 case TAG_subroutine
:
2245 case TAG_global_variable
:
2246 case TAG_local_variable
:
2247 completedieinfo (&di
);
2248 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2250 add_partial_symbol (&di
, objfile
);
2254 case TAG_structure_type
:
2255 case TAG_union_type
:
2256 completedieinfo (&di
);
2259 add_partial_symbol (&di
, objfile
);
2262 case TAG_enumeration_type
:
2263 completedieinfo (&di
);
2264 add_partial_symbol (&di
, objfile
);
2276 scan_compilation_units -- build a psymtab entry for each compilation
2280 This is the top level dwarf parsing routine for building partial
2283 It scans from the beginning of the DWARF table looking for the first
2284 TAG_compile_unit DIE, and then follows the sibling chain to locate
2285 each additional TAG_compile_unit DIE.
2287 For each TAG_compile_unit DIE it creates a partial symtab structure,
2288 calls a subordinate routine to collect all the compilation unit's
2289 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2290 new partial symtab structure into the partial symbol table. It also
2291 records the appropriate information in the partial symbol table entry
2292 to allow the chunk of DIE's and line number table for this compilation
2293 unit to be located and re-read later, to generate a complete symbol
2294 table entry for the compilation unit.
2296 Thus it effectively partitions up a chunk of DIE's for multiple
2297 compilation units into smaller DIE chunks and line number tables,
2298 and associates them with a partial symbol table entry.
2302 If any compilation unit has no line number table associated with
2303 it for some reason (a missing at_stmt_list attribute, rather than
2304 just one with a value of zero, which is valid) then we ensure that
2305 the recorded file offset is zero so that the routine which later
2306 reads line number table fragments knows that there is no fragment
2316 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2320 unsigned int dbfoff
;
2321 unsigned int lnoffset
;
2322 struct objfile
*objfile
;
2326 struct partial_symtab
*pst
;
2331 while (thisdie
< enddie
)
2333 basicdieinfo (&di
, thisdie
);
2334 if (di
.dielength
< sizeof (long))
2338 else if (di
.dietag
!= TAG_compile_unit
)
2340 nextdie
= thisdie
+ di
.dielength
;
2344 completedieinfo (&di
);
2345 if (di
.at_sibling
!= 0)
2347 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2351 nextdie
= thisdie
+ di
.dielength
;
2353 curoff
= thisdie
- dbbase
;
2354 culength
= nextdie
- thisdie
;
2355 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2357 /* First allocate a new partial symbol table structure */
2359 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2361 objfile
-> global_psymbols
.next
,
2362 objfile
-> static_psymbols
.next
);
2364 pst
-> texthigh
= di
.at_high_pc
;
2365 pst
-> read_symtab_private
= (char *)
2366 obstack_alloc (&objfile
-> psymbol_obstack
,
2367 sizeof (struct dwfinfo
));
2368 DBFOFF (pst
) = dbfoff
;
2369 DBROFF (pst
) = curoff
;
2370 DBLENGTH (pst
) = culength
;
2371 LNFOFF (pst
) = curlnoffset
;
2372 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2374 /* Now look for partial symbols */
2376 scan_partial_symbols (thisdie
+ di
.dielength
, nextdie
, objfile
);
2378 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2379 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2380 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2381 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2382 sort_pst_symbols (pst
);
2383 /* If there is already a psymtab or symtab for a file of this name,
2384 remove it. (If there is a symtab, more drastic things also
2385 happen.) This happens in VxWorks. */
2386 free_named_symtabs (pst
-> filename
);
2396 new_symbol -- make a symbol table entry for a new symbol
2400 static struct symbol *new_symbol (struct dieinfo *dip,
2401 struct objfile *objfile)
2405 Given a pointer to a DWARF information entry, figure out if we need
2406 to make a symbol table entry for it, and if so, create a new entry
2407 and return a pointer to it.
2410 static struct symbol
*
2411 new_symbol (dip
, objfile
)
2412 struct dieinfo
*dip
;
2413 struct objfile
*objfile
;
2415 struct symbol
*sym
= NULL
;
2417 if (dip
-> at_name
!= NULL
)
2419 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2420 sizeof (struct symbol
));
2421 (void) memset (sym
, 0, sizeof (struct symbol
));
2422 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2423 /* default assumptions */
2424 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2425 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2426 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2427 switch (dip
-> dietag
)
2430 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2431 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2433 case TAG_global_subroutine
:
2434 case TAG_subroutine
:
2435 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2436 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2437 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2438 if (dip
-> dietag
== TAG_global_subroutine
)
2440 add_symbol_to_list (sym
, &global_symbols
);
2444 add_symbol_to_list (sym
, list_in_scope
);
2447 case TAG_global_variable
:
2448 if (dip
-> at_location
!= NULL
)
2450 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2451 add_symbol_to_list (sym
, &global_symbols
);
2452 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2453 SYMBOL_VALUE (sym
) += baseaddr
;
2456 case TAG_local_variable
:
2457 if (dip
-> at_location
!= NULL
)
2459 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2460 add_symbol_to_list (sym
, list_in_scope
);
2463 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2467 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2471 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2472 SYMBOL_VALUE (sym
) += baseaddr
;
2476 case TAG_formal_parameter
:
2477 if (dip
-> at_location
!= NULL
)
2479 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2481 add_symbol_to_list (sym
, list_in_scope
);
2484 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2488 SYMBOL_CLASS (sym
) = LOC_ARG
;
2491 case TAG_unspecified_parameters
:
2492 /* From varargs functions; gdb doesn't seem to have any interest in
2493 this information, so just ignore it for now. (FIXME?) */
2495 case TAG_structure_type
:
2496 case TAG_union_type
:
2497 case TAG_enumeration_type
:
2498 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2499 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2500 add_symbol_to_list (sym
, list_in_scope
);
2503 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2504 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2505 add_symbol_to_list (sym
, list_in_scope
);
2508 /* Not a tag we recognize. Hopefully we aren't processing trash
2509 data, but since we must specifically ignore things we don't
2510 recognize, there is nothing else we should do at this point. */
2521 decode_mod_fund_type -- decode a modified fundamental type
2525 static struct type *decode_mod_fund_type (char *typedata)
2529 Decode a block of data containing a modified fundamental
2530 type specification. TYPEDATA is a pointer to the block,
2531 which consists of a two byte length, containing the size
2532 of the rest of the block. At the end of the block is a
2533 two byte value that gives the fundamental type. Everything
2534 in between are type modifiers.
2536 We simply compute the number of modifiers and call the general
2537 function decode_modified_type to do the actual work.
2540 static struct type
*
2541 decode_mod_fund_type (typedata
)
2544 struct type
*typep
= NULL
;
2545 unsigned short modcount
;
2546 unsigned char *modifiers
;
2548 /* Get the total size of the block, exclusive of the size itself */
2549 (void) memcpy (&modcount
, typedata
, sizeof (short));
2550 /* Deduct the size of the fundamental type bytes at the end of the block. */
2551 modcount
-= sizeof (short);
2552 /* Skip over the two size bytes at the beginning of the block. */
2553 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2554 /* Now do the actual decoding */
2555 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_fund_type
);
2563 decode_mod_u_d_type -- decode a modified user defined type
2567 static struct type *decode_mod_u_d_type (char *typedata)
2571 Decode a block of data containing a modified user defined
2572 type specification. TYPEDATA is a pointer to the block,
2573 which consists of a two byte length, containing the size
2574 of the rest of the block. At the end of the block is a
2575 four byte value that gives a reference to a user defined type.
2576 Everything in between are type modifiers.
2578 We simply compute the number of modifiers and call the general
2579 function decode_modified_type to do the actual work.
2582 static struct type
*
2583 decode_mod_u_d_type (typedata
)
2586 struct type
*typep
= NULL
;
2587 unsigned short modcount
;
2588 unsigned char *modifiers
;
2590 /* Get the total size of the block, exclusive of the size itself */
2591 (void) memcpy (&modcount
, typedata
, sizeof (short));
2592 /* Deduct the size of the reference type bytes at the end of the block. */
2593 modcount
-= sizeof (long);
2594 /* Skip over the two size bytes at the beginning of the block. */
2595 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2596 /* Now do the actual decoding */
2597 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_u_d_type
);
2605 decode_modified_type -- decode modified user or fundamental type
2609 static struct type *decode_modified_type (unsigned char *modifiers,
2610 unsigned short modcount, int mtype)
2614 Decode a modified type, either a modified fundamental type or
2615 a modified user defined type. MODIFIERS is a pointer to the
2616 block of bytes that define MODCOUNT modifiers. Immediately
2617 following the last modifier is a short containing the fundamental
2618 type or a long containing the reference to the user defined
2619 type. Which one is determined by MTYPE, which is either
2620 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2621 type we are generating.
2623 We call ourself recursively to generate each modified type,`
2624 until MODCOUNT reaches zero, at which point we have consumed
2625 all the modifiers and generate either the fundamental type or
2626 user defined type. When the recursion unwinds, each modifier
2627 is applied in turn to generate the full modified type.
2631 If we find a modifier that we don't recognize, and it is not one
2632 of those reserved for application specific use, then we issue a
2633 warning and simply ignore the modifier.
2637 We currently ignore MOD_const and MOD_volatile. (FIXME)
2641 static struct type
*
2642 decode_modified_type (modifiers
, modcount
, mtype
)
2643 unsigned char *modifiers
;
2644 unsigned int modcount
;
2647 struct type
*typep
= NULL
;
2648 unsigned short fundtype
;
2650 unsigned char modifier
;
2656 case AT_mod_fund_type
:
2657 (void) memcpy (&fundtype
, modifiers
, sizeof (short));
2658 typep
= decode_fund_type (fundtype
);
2660 case AT_mod_u_d_type
:
2661 (void) memcpy (&dieref
, modifiers
, sizeof (DIEREF
));
2662 if ((typep
= lookup_utype (dieref
)) == NULL
)
2664 typep
= alloc_utype (dieref
, NULL
);
2668 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2669 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2675 modifier
= *modifiers
++;
2676 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2679 case MOD_pointer_to
:
2680 typep
= lookup_pointer_type (typep
);
2682 case MOD_reference_to
:
2683 typep
= lookup_reference_type (typep
);
2686 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2689 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2692 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2694 SQUAWK (("unknown type modifier %u", modifier
));
2706 decode_fund_type -- translate basic DWARF type to gdb base type
2710 Given an integer that is one of the fundamental DWARF types,
2711 translate it to one of the basic internal gdb types and return
2712 a pointer to the appropriate gdb type (a "struct type *").
2716 If we encounter a fundamental type that we are unprepared to
2717 deal with, and it is not in the range of those types defined
2718 as application specific types, then we issue a warning and
2719 treat the type as an "int".
2722 static struct type
*
2723 decode_fund_type (fundtype
)
2724 unsigned int fundtype
;
2726 struct type
*typep
= NULL
;
2732 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2735 case FT_boolean
: /* Was FT_set in AT&T version */
2736 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2739 case FT_pointer
: /* (void *) */
2740 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2741 typep
= lookup_pointer_type (typep
);
2745 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2748 case FT_signed_char
:
2749 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2752 case FT_unsigned_char
:
2753 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2757 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2760 case FT_signed_short
:
2761 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2764 case FT_unsigned_short
:
2765 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2769 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2772 case FT_signed_integer
:
2773 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2776 case FT_unsigned_integer
:
2777 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2781 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2784 case FT_signed_long
:
2785 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2788 case FT_unsigned_long
:
2789 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2793 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2796 case FT_signed_long_long
:
2797 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2800 case FT_unsigned_long_long
:
2801 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2805 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2808 case FT_dbl_prec_float
:
2809 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2812 case FT_ext_prec_float
:
2813 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2817 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2820 case FT_dbl_prec_complex
:
2821 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2824 case FT_ext_prec_complex
:
2825 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2830 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2832 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2833 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2843 create_name -- allocate a fresh copy of a string on an obstack
2847 Given a pointer to a string and a pointer to an obstack, allocates
2848 a fresh copy of the string on the specified obstack.
2853 create_name (name
, obstackp
)
2855 struct obstack
*obstackp
;
2860 length
= strlen (name
) + 1;
2861 newname
= (char *) obstack_alloc (obstackp
, length
);
2862 (void) strcpy (newname
, name
);
2870 basicdieinfo -- extract the minimal die info from raw die data
2874 void basicdieinfo (char *diep, struct dieinfo *dip)
2878 Given a pointer to raw DIE data, and a pointer to an instance of a
2879 die info structure, this function extracts the basic information
2880 from the DIE data required to continue processing this DIE, along
2881 with some bookkeeping information about the DIE.
2883 The information we absolutely must have includes the DIE tag,
2884 and the DIE length. If we need the sibling reference, then we
2885 will have to call completedieinfo() to process all the remaining
2888 Note that since there is no guarantee that the data is properly
2889 aligned in memory for the type of access required (indirection
2890 through anything other than a char pointer), we use memcpy to
2891 shuffle data items larger than a char. Possibly inefficient, but
2894 We also take care of some other basic things at this point, such
2895 as ensuring that the instance of the die info structure starts
2896 out completely zero'd and that curdie is initialized for use
2897 in error reporting if we have a problem with the current die.
2901 All DIE's must have at least a valid length, thus the minimum
2902 DIE size is sizeof (long). In order to have a valid tag, the
2903 DIE size must be at least sizeof (short) larger, otherwise they
2904 are forced to be TAG_padding DIES.
2906 Padding DIES must be at least sizeof(long) in length, implying that
2907 if a padding DIE is used for alignment and the amount needed is less
2908 than sizeof(long) then the padding DIE has to be big enough to align
2909 to the next alignment boundry.
2913 basicdieinfo (dip
, diep
)
2914 struct dieinfo
*dip
;
2918 (void) memset (dip
, 0, sizeof (struct dieinfo
));
2920 dip
-> dieref
= dbroff
+ (diep
- dbbase
);
2921 (void) memcpy (&dip
-> dielength
, diep
, sizeof (long));
2922 if (dip
-> dielength
< sizeof (long))
2924 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> dielength
);
2926 else if (dip
-> dielength
< (sizeof (long) + sizeof (short)))
2928 dip
-> dietag
= TAG_padding
;
2932 (void) memcpy (&dip
-> dietag
, diep
+ sizeof (long), sizeof (short));
2940 completedieinfo -- finish reading the information for a given DIE
2944 void completedieinfo (struct dieinfo *dip)
2948 Given a pointer to an already partially initialized die info structure,
2949 scan the raw DIE data and finish filling in the die info structure
2950 from the various attributes found.
2952 Note that since there is no guarantee that the data is properly
2953 aligned in memory for the type of access required (indirection
2954 through anything other than a char pointer), we use memcpy to
2955 shuffle data items larger than a char. Possibly inefficient, but
2960 Each time we are called, we increment the diecount variable, which
2961 keeps an approximate count of the number of dies processed for
2962 each compilation unit. This information is presented to the user
2963 if the info_verbose flag is set.
2968 completedieinfo (dip
)
2969 struct dieinfo
*dip
;
2971 char *diep
; /* Current pointer into raw DIE data */
2972 char *end
; /* Terminate DIE scan here */
2973 unsigned short attr
; /* Current attribute being scanned */
2974 unsigned short form
; /* Form of the attribute */
2975 short block2sz
; /* Size of a block2 attribute field */
2976 long block4sz
; /* Size of a block4 attribute field */
2980 end
= diep
+ dip
-> dielength
;
2981 diep
+= sizeof (long) + sizeof (short);
2984 (void) memcpy (&attr
, diep
, sizeof (short));
2985 diep
+= sizeof (short);
2989 (void) memcpy (&dip
-> at_fund_type
, diep
, sizeof (short));
2992 (void) memcpy (&dip
-> at_ordering
, diep
, sizeof (short));
2995 (void) memcpy (&dip
-> at_bit_offset
, diep
, sizeof (short));
2998 (void) memcpy (&dip
-> at_visibility
, diep
, sizeof (short));
3001 (void) memcpy (&dip
-> at_sibling
, diep
, sizeof (long));
3004 (void) memcpy (&dip
-> at_stmt_list
, diep
, sizeof (long));
3005 dip
-> has_at_stmt_list
= 1;
3008 (void) memcpy (&dip
-> at_low_pc
, diep
, sizeof (long));
3009 dip
-> at_low_pc
+= baseaddr
;
3010 dip
-> has_at_low_pc
= 1;
3013 (void) memcpy (&dip
-> at_high_pc
, diep
, sizeof (long));
3014 dip
-> at_high_pc
+= baseaddr
;
3017 (void) memcpy (&dip
-> at_language
, diep
, sizeof (long));
3019 case AT_user_def_type
:
3020 (void) memcpy (&dip
-> at_user_def_type
, diep
, sizeof (long));
3023 (void) memcpy (&dip
-> at_byte_size
, diep
, sizeof (long));
3026 (void) memcpy (&dip
-> at_bit_size
, diep
, sizeof (long));
3029 (void) memcpy (&dip
-> at_member
, diep
, sizeof (long));
3032 (void) memcpy (&dip
-> at_discr
, diep
, sizeof (long));
3035 (void) memcpy (&dip
-> at_import
, diep
, sizeof (long));
3038 dip
-> at_location
= diep
;
3040 case AT_mod_fund_type
:
3041 dip
-> at_mod_fund_type
= diep
;
3043 case AT_subscr_data
:
3044 dip
-> at_subscr_data
= diep
;
3046 case AT_mod_u_d_type
:
3047 dip
-> at_mod_u_d_type
= diep
;
3049 case AT_element_list
:
3050 dip
-> at_element_list
= diep
;
3051 dip
-> short_element_list
= 0;
3053 case AT_short_element_list
:
3054 dip
-> at_element_list
= diep
;
3055 dip
-> short_element_list
= 1;
3057 case AT_discr_value
:
3058 dip
-> at_discr_value
= diep
;
3060 case AT_string_length
:
3061 dip
-> at_string_length
= diep
;
3064 dip
-> at_name
= diep
;
3067 dip
-> at_comp_dir
= diep
;
3070 dip
-> at_producer
= diep
;
3073 (void) memcpy (&dip
-> at_frame_base
, diep
, sizeof (long));
3075 case AT_start_scope
:
3076 (void) memcpy (&dip
-> at_start_scope
, diep
, sizeof (long));
3078 case AT_stride_size
:
3079 (void) memcpy (&dip
-> at_stride_size
, diep
, sizeof (long));
3082 (void) memcpy (&dip
-> at_src_info
, diep
, sizeof (long));
3085 (void) memcpy (&dip
-> at_prototyped
, diep
, sizeof (short));
3088 /* Found an attribute that we are unprepared to handle. However
3089 it is specifically one of the design goals of DWARF that
3090 consumers should ignore unknown attributes. As long as the
3091 form is one that we recognize (so we know how to skip it),
3092 we can just ignore the unknown attribute. */
3099 diep
+= sizeof (short);
3102 diep
+= sizeof (long);
3105 diep
+= 8 * sizeof (char); /* sizeof (long long) ? */
3109 diep
+= sizeof (long);
3112 (void) memcpy (&block2sz
, diep
, sizeof (short));
3113 block2sz
+= sizeof (short);
3117 (void) memcpy (&block4sz
, diep
, sizeof (long));
3118 block4sz
+= sizeof (long);
3122 diep
+= strlen (diep
) + 1;
3125 SQUAWK (("unknown attribute form (0x%x), skipped rest", form
));