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. :-)
65 #include "elf/dwarf.h"
68 #ifdef MAINTENANCE /* Define to 1 to compile in some maintenance stuff */
69 #define SQUAWK(stuff) dwarfwarn stuff
74 #ifndef R_FP /* FIXME */
75 #define R_FP 14 /* Kludge to get frame pointer register number */
78 typedef unsigned int DIEREF
; /* Reference to a DIE */
81 #define GCC_PRODUCER "GNU C "
84 #define STREQ(a,b) (strcmp(a,b)==0)
85 #define STREQN(a,b,n) (strncmp(a,b,n)==0)
87 /* The Amiga SVR4 header file <dwarf.h> defines AT_element_list as a
88 FORM_BLOCK2, and this is the value emitted by the AT&T compiler.
89 However, the Issue 2 DWARF specification from AT&T defines it as
90 a FORM_BLOCK4, as does the latest specification from UI/PLSIG.
91 For backwards compatibility with the AT&T compiler produced executables
92 we define AT_short_element_list for this variant. */
94 #define AT_short_element_list (0x00f0|FORM_BLOCK2)
96 /* External variables referenced. */
98 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
99 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
100 extern CORE_ADDR entry_scope_lowpc
; /* From blockframe.c */
101 extern CORE_ADDR entry_scope_highpc
; /* From blockframc.c */
102 extern CORE_ADDR main_scope_lowpc
; /* From blockframe.c */
103 extern CORE_ADDR main_scope_highpc
; /* From blockframc.c */
104 extern int info_verbose
; /* From main.c; nonzero => verbose */
107 /* The DWARF debugging information consists of two major pieces,
108 one is a block of DWARF Information Entries (DIE's) and the other
109 is a line number table. The "struct dieinfo" structure contains
110 the information for a single DIE, the one currently being processed.
112 In order to make it easier to randomly access the attribute fields
113 of the current DIE, which are specifically unordered within the DIE
114 each DIE is scanned and an instance of the "struct dieinfo"
115 structure is initialized.
117 Initialization is done in two levels. The first, done by basicdieinfo(),
118 just initializes those fields that are vital to deciding whether or not
119 to use this DIE, how to skip past it, etc. The second, done by the
120 function completedieinfo(), fills in the rest of the information.
122 Attributes which have block forms are not interpreted at the time
123 the DIE is scanned, instead we just save pointers to the start
124 of their value fields.
126 Some fields have a flag <name>_p that is set when the value of the
127 field is valid (I.E. we found a matching attribute in the DIE). Since
128 we may want to test for the presence of some attributes in the DIE,
129 such as AT_low_pc, without restricting the values of the field,
130 we need someway to note that we found such an attribute.
137 char * die
; /* Pointer to the raw DIE data */
138 long dielength
; /* Length of the raw DIE data */
139 DIEREF dieref
; /* Offset of this DIE */
140 short dietag
; /* Tag for this DIE */
145 unsigned short at_fund_type
;
146 BLOCK
* at_mod_fund_type
;
147 long at_user_def_type
;
148 BLOCK
* at_mod_u_d_type
;
150 BLOCK
* at_subscr_data
;
154 BLOCK
* at_element_list
;
161 BLOCK
* at_discr_value
;
164 BLOCK
* at_string_length
;
172 unsigned int has_at_low_pc
:1;
173 unsigned int has_at_stmt_list
:1;
174 unsigned int short_element_list
:1;
177 static int diecount
; /* Approximate count of dies for compilation unit */
178 static struct dieinfo
*curdie
; /* For warnings and such */
180 static char *dbbase
; /* Base pointer to dwarf info */
181 static int dbroff
; /* Relative offset from start of .debug section */
182 static char *lnbase
; /* Base pointer to line section */
183 static int isreg
; /* Kludge to identify register variables */
184 static int offreg
; /* Kludge to identify basereg references */
186 static CORE_ADDR baseaddr
; /* Add to each symbol value */
188 /* Each partial symbol table entry contains a pointer to private data for the
189 read_symtab() function to use when expanding a partial symbol table entry
190 to a full symbol table entry. For DWARF debugging info, this data is
191 contained in the following structure and macros are provided for easy
192 access to the members given a pointer to a partial symbol table entry.
194 dbfoff Always the absolute file offset to the start of the ".debug"
195 section for the file containing the DIE's being accessed.
197 dbroff Relative offset from the start of the ".debug" access to the
198 first DIE to be accessed. When building the partial symbol
199 table, this value will be zero since we are accessing the
200 entire ".debug" section. When expanding a partial symbol
201 table entry, this value will be the offset to the first
202 DIE for the compilation unit containing the symbol that
203 triggers the expansion.
205 dblength The size of the chunk of DIE's being examined, in bytes.
207 lnfoff The absolute file offset to the line table fragment. Ignored
208 when building partial symbol tables, but used when expanding
209 them, and contains the absolute file offset to the fragment
210 of the ".line" section containing the line numbers for the
211 current compilation unit.
215 int dbfoff
; /* Absolute file offset to start of .debug section */
216 int dbroff
; /* Relative offset from start of .debug section */
217 int dblength
; /* Size of the chunk of DIE's being examined */
218 int lnfoff
; /* Absolute file offset to line table fragment */
221 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
222 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
223 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
224 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
226 /* The generic symbol table building routines have separate lists for
227 file scope symbols and all all other scopes (local scopes). So
228 we need to select the right one to pass to add_symbol_to_list().
229 We do it by keeping a pointer to the correct list in list_in_scope.
231 FIXME: The original dwarf code just treated the file scope as the first
232 local scope, and all other local scopes as nested local scopes, and worked
233 fine. Check to see if we really need to distinguish these in buildsym.c */
235 struct pending
**list_in_scope
= &file_symbols
;
237 /* DIES which have user defined types or modified user defined types refer to
238 other DIES for the type information. Thus we need to associate the offset
239 of a DIE for a user defined type with a pointer to the type information.
241 Originally this was done using a simple but expensive algorithm, with an
242 array of unsorted structures, each containing an offset/type-pointer pair.
243 This array was scanned linearly each time a lookup was done. The result
244 was that gdb was spending over half it's startup time munging through this
245 array of pointers looking for a structure that had the right offset member.
247 The second attempt used the same array of structures, but the array was
248 sorted using qsort each time a new offset/type was recorded, and a binary
249 search was used to find the type pointer for a given DIE offset. This was
250 even slower, due to the overhead of sorting the array each time a new
251 offset/type pair was entered.
253 The third attempt uses a fixed size array of type pointers, indexed by a
254 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
255 we can divide any DIE offset by 4 to obtain a unique index into this fixed
256 size array. Since each element is a 4 byte pointer, it takes exactly as
257 much memory to hold this array as to hold the DWARF info for a given
258 compilation unit. But it gets freed as soon as we are done with it. */
260 static struct type
**utypes
; /* Pointer to array of user type pointers */
261 static int numutypes
; /* Max number of user type pointers */
263 /* Forward declarations of static functions so we don't have to worry
264 about ordering within this file. */
267 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
270 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
273 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
276 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
283 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
286 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
287 unsigned int, struct objfile
*));
290 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
293 init_psymbol_list
PARAMS ((struct objfile
*, int));
296 basicdieinfo
PARAMS ((struct dieinfo
*, char *));
299 completedieinfo
PARAMS ((struct dieinfo
*));
302 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
305 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
307 static struct symtab
*
308 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
311 process_dies
PARAMS ((char *, char *, struct objfile
*));
314 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
318 decode_array_element_type
PARAMS ((char *, char *));
321 decode_subscr_data
PARAMS ((char *, char *));
324 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
327 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
330 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
333 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
336 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
339 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
342 decode_line_numbers
PARAMS ((char *));
345 decode_die_type
PARAMS ((struct dieinfo
*));
348 decode_mod_fund_type
PARAMS ((char *));
351 decode_mod_u_d_type
PARAMS ((char *));
354 decode_modified_type
PARAMS ((unsigned char *, unsigned int, int));
357 decode_fund_type
PARAMS ((unsigned int));
360 create_name
PARAMS ((char *, struct obstack
*));
363 lookup_utype
PARAMS ((DIEREF
));
366 alloc_utype
PARAMS ((DIEREF
, struct type
*));
368 static struct symbol
*
369 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
372 locval
PARAMS ((char *));
375 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
382 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
386 void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr,
387 int mainline, unsigned int dbfoff, unsigned int dbsize,
388 unsigned int lnoffset, unsigned int lnsize,
389 struct objfile *objfile)
393 This function is called upon to build partial symtabs from files
394 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
396 It is passed a file descriptor for an open file containing the DIES
397 and line number information, the corresponding filename for that
398 file, a base address for relocating the symbols, a flag indicating
399 whether or not this debugging information is from a "main symbol
400 table" rather than a shared library or dynamically linked file,
401 and file offset/size pairs for the DIE information and line number
411 dwarf_build_psymtabs (desc
, filename
, addr
, mainline
, dbfoff
, dbsize
,
412 lnoffset
, lnsize
, objfile
)
419 unsigned int lnoffset
;
421 struct objfile
*objfile
;
423 struct cleanup
*back_to
;
425 dbbase
= xmalloc (dbsize
);
427 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
428 (read (desc
, dbbase
, dbsize
) != dbsize
))
431 error ("can't read DWARF data from '%s'", filename
);
433 back_to
= make_cleanup (free
, dbbase
);
435 /* If we are reinitializing, or if we have never loaded syms yet, init.
436 Since we have no idea how many DIES we are looking at, we just guess
437 some arbitrary value. */
439 if (mainline
|| objfile
->global_psymbols
.size
== 0 || objfile
->static_psymbols
.size
== 0)
441 init_psymbol_list (objfile
, 1024);
444 /* From this point on, we don't need to pass mainline around, so zap
445 baseaddr to zero if we don't need relocation. */
456 /* Follow the compilation unit sibling chain, building a partial symbol
457 table entry for each one. Save enough information about each compilation
458 unit to locate the full DWARF information later. */
460 scan_compilation_units (filename
, dbbase
, dbbase
+ dbsize
,
461 dbfoff
, lnoffset
, objfile
);
463 do_cleanups (back_to
);
471 record_minimal_symbol -- add entry to gdb's minimal symbol table
475 static void record_minimal_symbol (char *name, CORE_ADDR address,
476 enum minimal_symbol_type ms_type,
477 struct objfile *objfile)
481 Given a pointer to the name of a symbol that should be added to the
482 minimal symbol table, and the address associated with that
483 symbol, records this information for later use in building the
484 minimal symbol table.
489 record_minimal_symbol (name
, address
, ms_type
, objfile
)
492 enum minimal_symbol_type ms_type
;
493 struct objfile
*objfile
;
495 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
496 prim_record_minimal_symbol (name
, address
, ms_type
);
503 dwarfwarn -- issue a DWARF related warning
507 Issue warnings about DWARF related things that aren't serious enough
508 to warrant aborting with an error, but should not be ignored either.
509 This includes things like detectable corruption in DIE's, missing
510 DIE's, unimplemented features, etc.
512 In general, running across tags or attributes that we don't recognize
513 is not considered to be a problem and we should not issue warnings
518 We mostly follow the example of the error() routine, but without
519 returning to command level. It is arguable about whether warnings
520 should be issued at all, and if so, where they should go (stdout or
523 We assume that curdie is valid and contains at least the basic
524 information for the DIE where the problem was noticed.
535 fmt
= va_arg (ap
, char *);
537 fprintf (stderr
, "DWARF warning (ref 0x%x): ", curdie
-> dieref
);
538 if (curdie
-> at_name
)
540 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
542 vfprintf (stderr
, fmt
, ap
);
543 fprintf (stderr
, "\n");
552 read_lexical_block_scope -- process all dies in a lexical block
556 static void read_lexical_block_scope (struct dieinfo *dip,
557 char *thisdie, char *enddie)
561 Process all the DIES contained within a lexical block scope.
562 Start a new scope, process the dies, and then close the scope.
567 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
571 struct objfile
*objfile
;
573 register struct context_stack
*new;
575 (void) push_context (0, dip
-> at_low_pc
);
576 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
577 new = pop_context ();
578 if (local_symbols
!= NULL
)
580 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
581 dip
-> at_high_pc
, objfile
);
583 local_symbols
= new -> locals
;
590 lookup_utype -- look up a user defined type from die reference
594 static type *lookup_utype (DIEREF dieref)
598 Given a DIE reference, lookup the user defined type associated with
599 that DIE, if it has been registered already. If not registered, then
600 return NULL. Alloc_utype() can be called to register an empty
601 type for this reference, which will be filled in later when the
602 actual referenced DIE is processed.
606 lookup_utype (dieref
)
609 struct type
*type
= NULL
;
612 utypeidx
= (dieref
- dbroff
) / 4;
613 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
615 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
619 type
= *(utypes
+ utypeidx
);
629 alloc_utype -- add a user defined type for die reference
633 static type *alloc_utype (DIEREF dieref, struct type *utypep)
637 Given a die reference DIEREF, and a possible pointer to a user
638 defined type UTYPEP, register that this reference has a user
639 defined type and either use the specified type in UTYPEP or
640 make a new empty type that will be filled in later.
642 We should only be called after calling lookup_utype() to verify that
643 there is not currently a type registered for DIEREF.
647 alloc_utype (dieref
, utypep
)
654 utypeidx
= (dieref
- dbroff
) / 4;
655 typep
= utypes
+ utypeidx
;
656 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
658 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
659 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
661 else if (*typep
!= NULL
)
664 SQUAWK (("internal error: dup user type allocation"));
670 utypep
= (struct type
*)
671 obstack_alloc (¤t_objfile
-> type_obstack
,
672 sizeof (struct type
));
673 (void) memset (utypep
, 0, sizeof (struct type
));
674 TYPE_OBJFILE (utypep
) = current_objfile
;
685 decode_die_type -- return a type for a specified die
689 static struct type *decode_die_type (struct dieinfo *dip)
693 Given a pointer to a die information structure DIP, decode the
694 type of the die and return a pointer to the decoded type. All
695 dies without specific types default to type int.
699 decode_die_type (dip
)
702 struct type
*type
= NULL
;
704 if (dip
-> at_fund_type
!= 0)
706 type
= decode_fund_type (dip
-> at_fund_type
);
708 else if (dip
-> at_mod_fund_type
!= NULL
)
710 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
712 else if (dip
-> at_user_def_type
)
714 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
716 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
719 else if (dip
-> at_mod_u_d_type
)
721 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
725 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
734 struct_type -- compute and return the type for a struct or union
738 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
739 char *enddie, struct objfile *objfile)
743 Given pointer to a die information structure for a die which
744 defines a union or structure (and MUST define one or the other),
745 and pointers to the raw die data that define the range of dies which
746 define the members, compute and return the user defined type for the
751 struct_type (dip
, thisdie
, enddie
, objfile
)
755 struct objfile
*objfile
;
759 struct nextfield
*next
;
762 struct nextfield
*list
= NULL
;
763 struct nextfield
*new;
770 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
772 /* No forward references created an empty type, so install one now */
773 type
= alloc_utype (dip
-> dieref
, NULL
);
775 INIT_CPLUS_SPECIFIC(type
);
776 switch (dip
-> dietag
)
778 case TAG_structure_type
:
779 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
783 TYPE_CODE (type
) = TYPE_CODE_UNION
;
787 /* Should never happen */
788 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
790 SQUAWK (("missing structure or union tag"));
793 /* Some compilers try to be helpful by inventing "fake" names for
794 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
795 Thanks, but no thanks... */
796 if (dip
-> at_name
!= NULL
797 && *dip
-> at_name
!= '~'
798 && *dip
-> at_name
!= '.')
800 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
,
801 tpart1
, " ", dip
-> at_name
);
803 if (dip
-> at_byte_size
!= 0)
805 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
807 thisdie
+= dip
-> dielength
;
808 while (thisdie
< enddie
)
810 basicdieinfo (&mbr
, thisdie
);
811 completedieinfo (&mbr
);
812 if (mbr
.dielength
<= sizeof (long))
816 else if (mbr
.at_sibling
!= 0)
818 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
822 nextdie
= thisdie
+ mbr
.dielength
;
827 /* Get space to record the next field's data. */
828 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
832 list
-> field
.name
= savestring (mbr
.at_name
, strlen (mbr
.at_name
));
833 list
-> field
.type
= decode_die_type (&mbr
);
834 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
835 list
-> field
.bitsize
= 0;
839 process_dies (thisdie
, nextdie
, objfile
);
844 /* Now create the vector of fields, and record how big it is. We may
845 not even have any fields, if this DIE was generated due to a reference
846 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
847 set, which clues gdb in to the fact that it needs to search elsewhere
848 for the full structure definition. */
851 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
855 TYPE_NFIELDS (type
) = nfields
;
856 TYPE_FIELDS (type
) = (struct field
*)
857 obstack_alloc (¤t_objfile
-> type_obstack
,
858 sizeof (struct field
) * nfields
);
859 /* Copy the saved-up fields into the field vector. */
860 for (n
= nfields
; list
; list
= list
-> next
)
862 TYPE_FIELD (type
, --n
) = list
-> field
;
872 read_structure_scope -- process all dies within struct or union
876 static void read_structure_scope (struct dieinfo *dip,
877 char *thisdie, char *enddie, struct objfile *objfile)
881 Called when we find the DIE that starts a structure or union
882 scope (definition) to process all dies that define the members
883 of the structure or union. DIP is a pointer to the die info
884 struct for the DIE that names the structure or union.
888 Note that we need to call struct_type regardless of whether or not
889 the DIE has an at_name attribute, since it might be an anonymous
890 structure or union. This gets the type entered into our set of
893 However, if the structure is incomplete (an opaque struct/union)
894 then suppress creating a symbol table entry for it since gdb only
895 wants to find the one with the complete definition. Note that if
896 it is complete, we just call new_symbol, which does it's own
897 checking about whether the struct/union is anonymous or not (and
898 suppresses creating a symbol table entry itself).
903 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
907 struct objfile
*objfile
;
912 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
913 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
915 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
917 SYMBOL_TYPE (sym
) = type
;
926 decode_array_element_type -- decode type of the array elements
930 static struct type *decode_array_element_type (char *scan, char *end)
934 As the last step in decoding the array subscript information for an
935 array DIE, we need to decode the type of the array elements. We are
936 passed a pointer to this last part of the subscript information and
937 must return the appropriate type. If the type attribute is not
938 recognized, just warn about the problem and return type int.
942 decode_array_element_type (scan
, end
)
949 unsigned short fundtype
;
951 (void) memcpy (&attribute
, scan
, sizeof (short));
952 scan
+= sizeof (short);
956 (void) memcpy (&fundtype
, scan
, sizeof (short));
957 typep
= decode_fund_type (fundtype
);
959 case AT_mod_fund_type
:
960 typep
= decode_mod_fund_type (scan
);
962 case AT_user_def_type
:
963 (void) memcpy (&dieref
, scan
, sizeof (DIEREF
));
964 if ((typep
= lookup_utype (dieref
)) == NULL
)
966 typep
= alloc_utype (dieref
, NULL
);
969 case AT_mod_u_d_type
:
970 typep
= decode_mod_u_d_type (scan
);
973 SQUAWK (("bad array element type attribute 0x%x", attribute
));
974 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
984 decode_subscr_data -- decode array subscript and element type data
988 static struct type *decode_subscr_data (char *scan, char *end)
992 The array subscripts and the data type of the elements of an
993 array are described by a list of data items, stored as a block
994 of contiguous bytes. There is a data item describing each array
995 dimension, and a final data item describing the element type.
996 The data items are ordered the same as their appearance in the
997 source (I.E. leftmost dimension first, next to leftmost second,
1000 We are passed a pointer to the start of the block of bytes
1001 containing the data items, and a pointer to the first byte past
1002 the data. This function decodes the data and returns a type.
1005 FIXME: This code only implements the forms currently used
1006 by the AT&T and GNU C compilers.
1008 The end pointer is supplied for error checking, maybe we should
1012 static struct type
*
1013 decode_subscr_data (scan
, end
)
1017 struct type
*typep
= NULL
;
1018 struct type
*nexttype
;
1028 typep
= decode_array_element_type (scan
, end
);
1031 (void) memcpy (&fundtype
, scan
, sizeof (short));
1032 scan
+= sizeof (short);
1033 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1034 && fundtype
!= FT_unsigned_integer
)
1036 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1041 (void) memcpy (&lowbound
, scan
, sizeof (long));
1042 scan
+= sizeof (long);
1043 (void) memcpy (&highbound
, scan
, sizeof (long));
1044 scan
+= sizeof (long);
1045 nexttype
= decode_subscr_data (scan
, end
);
1046 if (nexttype
!= NULL
)
1048 typep
= (struct type
*)
1049 obstack_alloc (¤t_objfile
-> type_obstack
,
1050 sizeof (struct type
));
1051 (void) memset (typep
, 0, sizeof (struct type
));
1052 TYPE_OBJFILE (typep
) = current_objfile
;
1053 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1054 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1055 TYPE_LENGTH (typep
) *= lowbound
+ highbound
+ 1;
1056 TYPE_TARGET_TYPE (typep
) = nexttype
;
1067 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1070 SQUAWK (("unknown array subscript format %x", format
));
1080 dwarf_read_array_type -- read TAG_array_type DIE
1084 static void dwarf_read_array_type (struct dieinfo *dip)
1088 Extract all information from a TAG_array_type DIE and add to
1089 the user defined type vector.
1093 dwarf_read_array_type (dip
)
1094 struct dieinfo
*dip
;
1102 if (dip
-> at_ordering
!= ORD_row_major
)
1104 /* FIXME: Can gdb even handle column major arrays? */
1105 SQUAWK (("array not row major; not handled correctly"));
1107 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1109 (void) memcpy (&temp
, sub
, sizeof (short));
1110 subend
= sub
+ sizeof (short) + temp
;
1111 sub
+= sizeof (short);
1112 type
= decode_subscr_data (sub
, subend
);
1115 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1117 utype
= alloc_utype (dip
-> dieref
, NULL
);
1119 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1120 TYPE_TARGET_TYPE (utype
) =
1121 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1122 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1126 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1128 (void) alloc_utype (dip
-> dieref
, type
);
1132 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1133 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1134 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1144 read_tag_pointer_type -- read TAG_pointer_type DIE
1148 static void read_tag_pointer_type (struct dieinfo *dip)
1152 Extract all information from a TAG_pointer_type DIE and add to
1153 the user defined type vector.
1157 read_tag_pointer_type (dip
)
1158 struct dieinfo
*dip
;
1163 type
= decode_die_type (dip
);
1164 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1166 utype
= lookup_pointer_type (type
);
1167 (void) alloc_utype (dip
-> dieref
, utype
);
1171 TYPE_TARGET_TYPE (utype
) = type
;
1172 TYPE_POINTER_TYPE (type
) = utype
;
1174 /* We assume the machine has only one representation for pointers! */
1175 /* FIXME: This confuses host<->target data representations, and is a
1176 poor assumption besides. */
1178 TYPE_LENGTH (utype
) = sizeof (char *);
1179 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1187 read_subroutine_type -- process TAG_subroutine_type dies
1191 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1196 Handle DIES due to C code like:
1199 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1205 The parameter DIES are currently ignored. See if gdb has a way to
1206 include this info in it's type system, and decode them if so. Is
1207 this what the type structure's "arg_types" field is for? (FIXME)
1211 read_subroutine_type (dip
, thisdie
, enddie
)
1212 struct dieinfo
*dip
;
1216 struct type
*type
; /* Type that this function returns */
1217 struct type
*ftype
; /* Function that returns above type */
1219 /* Decode the type that this subroutine returns */
1221 type
= decode_die_type (dip
);
1223 /* Check to see if we already have a partially constructed user
1224 defined type for this DIE, from a forward reference. */
1226 if ((ftype
= lookup_utype (dip
-> dieref
)) == NULL
)
1228 /* This is the first reference to one of these types. Make
1229 a new one and place it in the user defined types. */
1230 ftype
= lookup_function_type (type
);
1231 (void) alloc_utype (dip
-> dieref
, ftype
);
1235 /* We have an existing partially constructed type, so bash it
1236 into the correct type. */
1237 TYPE_TARGET_TYPE (ftype
) = type
;
1238 TYPE_FUNCTION_TYPE (type
) = ftype
;
1239 TYPE_LENGTH (ftype
) = 1;
1240 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1248 read_enumeration -- process dies which define an enumeration
1252 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1253 char *enddie, struct objfile *objfile)
1257 Given a pointer to a die which begins an enumeration, process all
1258 the dies that define the members of the enumeration.
1262 Note that we need to call enum_type regardless of whether or not we
1263 have a symbol, since we might have an enum without a tag name (thus
1264 no symbol for the tagname).
1268 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1269 struct dieinfo
*dip
;
1272 struct objfile
*objfile
;
1277 type
= enum_type (dip
, objfile
);
1278 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1280 SYMBOL_TYPE (sym
) = type
;
1288 enum_type -- decode and return a type for an enumeration
1292 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1296 Given a pointer to a die information structure for the die which
1297 starts an enumeration, process all the dies that define the members
1298 of the enumeration and return a type pointer for the enumeration.
1300 At the same time, for each member of the enumeration, create a
1301 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1302 and give it the type of the enumeration itself.
1306 Note that the DWARF specification explicitly mandates that enum
1307 constants occur in reverse order from the source program order,
1308 for "consistency" and because this ordering is easier for many
1309 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1310 Entries). Because gdb wants to see the enum members in program
1311 source order, we have to ensure that the order gets reversed while
1312 we are processing them.
1315 static struct type
*
1316 enum_type (dip
, objfile
)
1317 struct dieinfo
*dip
;
1318 struct objfile
*objfile
;
1322 struct nextfield
*next
;
1325 struct nextfield
*list
= NULL
;
1326 struct nextfield
*new;
1335 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
1337 /* No forward references created an empty type, so install one now */
1338 type
= alloc_utype (dip
-> dieref
, NULL
);
1340 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1341 /* Some compilers try to be helpful by inventing "fake" names for
1342 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1343 Thanks, but no thanks... */
1344 if (dip
-> at_name
!= NULL
1345 && *dip
-> at_name
!= '~'
1346 && *dip
-> at_name
!= '.')
1348 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
, "enum",
1349 " ", dip
-> at_name
);
1351 if (dip
-> at_byte_size
!= 0)
1353 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1355 if ((scan
= dip
-> at_element_list
) != NULL
)
1357 if (dip
-> short_element_list
)
1359 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
1360 listend
= scan
+ stemp
+ sizeof (stemp
);
1361 scan
+= sizeof (stemp
);
1365 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
1366 listend
= scan
+ ltemp
+ sizeof (ltemp
);
1367 scan
+= sizeof (ltemp
);
1369 while (scan
< listend
)
1371 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1374 list
-> field
.type
= NULL
;
1375 list
-> field
.bitsize
= 0;
1376 (void) memcpy (&list
-> field
.bitpos
, scan
, sizeof (long));
1377 scan
+= sizeof (long);
1378 list
-> field
.name
= savestring (scan
, strlen (scan
));
1379 scan
+= strlen (scan
) + 1;
1381 /* Handcraft a new symbol for this enum member. */
1382 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1383 sizeof (struct symbol
));
1384 (void) memset (sym
, 0, sizeof (struct symbol
));
1385 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
, &objfile
->symbol_obstack
);
1386 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1387 SYMBOL_CLASS (sym
) = LOC_CONST
;
1388 SYMBOL_TYPE (sym
) = type
;
1389 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1390 add_symbol_to_list (sym
, list_in_scope
);
1392 /* Now create the vector of fields, and record how big it is. This is
1393 where we reverse the order, by pulling the members of the list in
1394 reverse order from how they were inserted. If we have no fields
1395 (this is apparently possible in C++) then skip building a field
1399 TYPE_NFIELDS (type
) = nfields
;
1400 TYPE_FIELDS (type
) = (struct field
*)
1401 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1402 /* Copy the saved-up fields into the field vector. */
1403 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1405 TYPE_FIELD (type
, n
++) = list
-> field
;
1416 read_func_scope -- process all dies within a function scope
1420 Process all dies within a given function scope. We are passed
1421 a die information structure pointer DIP for the die which
1422 starts the function scope, and pointers into the raw die data
1423 that define the dies within the function scope.
1425 For now, we ignore lexical block scopes within the function.
1426 The problem is that AT&T cc does not define a DWARF lexical
1427 block scope for the function itself, while gcc defines a
1428 lexical block scope for the function. We need to think about
1429 how to handle this difference, or if it is even a problem.
1434 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1435 struct dieinfo
*dip
;
1438 struct objfile
*objfile
;
1440 register struct context_stack
*new;
1442 if (entry_point
>= dip
-> at_low_pc
&& entry_point
< dip
-> at_high_pc
)
1444 entry_scope_lowpc
= dip
-> at_low_pc
;
1445 entry_scope_highpc
= dip
-> at_high_pc
;
1447 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1449 main_scope_lowpc
= dip
-> at_low_pc
;
1450 main_scope_highpc
= dip
-> at_high_pc
;
1452 new = push_context (0, dip
-> at_low_pc
);
1453 new -> name
= new_symbol (dip
, objfile
);
1454 list_in_scope
= &local_symbols
;
1455 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1456 new = pop_context ();
1457 /* Make a block for the local symbols within. */
1458 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1459 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1460 list_in_scope
= &file_symbols
;
1467 read_file_scope -- process all dies within a file scope
1471 Process all dies within a given file scope. We are passed a
1472 pointer to the die information structure for the die which
1473 starts the file scope, and pointers into the raw die data which
1474 mark the range of dies within the file scope.
1476 When the partial symbol table is built, the file offset for the line
1477 number table for each compilation unit is saved in the partial symbol
1478 table entry for that compilation unit. As the symbols for each
1479 compilation unit are read, the line number table is read into memory
1480 and the variable lnbase is set to point to it. Thus all we have to
1481 do is use lnbase to access the line number table for the current
1486 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1487 struct dieinfo
*dip
;
1490 struct objfile
*objfile
;
1492 struct cleanup
*back_to
;
1493 struct symtab
*symtab
;
1495 if (entry_point
>= dip
-> at_low_pc
&& entry_point
< dip
-> at_high_pc
)
1497 startup_file_start
= dip
-> at_low_pc
;
1498 startup_file_end
= dip
-> at_high_pc
;
1500 if (dip
-> at_producer
!= NULL
)
1502 processing_gcc_compilation
=
1503 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1505 numutypes
= (enddie
- thisdie
) / 4;
1506 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1507 back_to
= make_cleanup (free
, utypes
);
1508 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1509 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1510 decode_line_numbers (lnbase
);
1511 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1512 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1513 /* FIXME: The following may need to be expanded for other languages */
1514 switch (dip
-> at_language
)
1518 symtab
-> language
= language_c
;
1520 case LANG_C_PLUS_PLUS
:
1521 symtab
-> language
= language_cplus
;
1526 do_cleanups (back_to
);
1535 process_dies -- process a range of DWARF Information Entries
1539 static void process_dies (char *thisdie, char *enddie,
1540 struct objfile *objfile)
1544 Process all DIE's in a specified range. May be (and almost
1545 certainly will be) called recursively.
1549 process_dies (thisdie
, enddie
, objfile
)
1552 struct objfile
*objfile
;
1557 while (thisdie
< enddie
)
1559 basicdieinfo (&di
, thisdie
);
1560 if (di
.dielength
< sizeof (long))
1564 else if (di
.dietag
== TAG_padding
)
1566 nextdie
= thisdie
+ di
.dielength
;
1570 completedieinfo (&di
);
1571 if (di
.at_sibling
!= 0)
1573 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1577 nextdie
= thisdie
+ di
.dielength
;
1581 case TAG_compile_unit
:
1582 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1584 case TAG_global_subroutine
:
1585 case TAG_subroutine
:
1586 if (di
.has_at_low_pc
)
1588 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1591 case TAG_lexical_block
:
1592 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1594 case TAG_structure_type
:
1595 case TAG_union_type
:
1596 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1598 case TAG_enumeration_type
:
1599 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1601 case TAG_subroutine_type
:
1602 read_subroutine_type (&di
, thisdie
, nextdie
);
1604 case TAG_array_type
:
1605 dwarf_read_array_type (&di
);
1607 case TAG_pointer_type
:
1608 read_tag_pointer_type (&di
);
1611 (void) new_symbol (&di
, objfile
);
1623 decode_line_numbers -- decode a line number table fragment
1627 static void decode_line_numbers (char *tblscan, char *tblend,
1628 long length, long base, long line, long pc)
1632 Translate the DWARF line number information to gdb form.
1634 The ".line" section contains one or more line number tables, one for
1635 each ".line" section from the objects that were linked.
1637 The AT_stmt_list attribute for each TAG_source_file entry in the
1638 ".debug" section contains the offset into the ".line" section for the
1639 start of the table for that file.
1641 The table itself has the following structure:
1643 <table length><base address><source statement entry>
1644 4 bytes 4 bytes 10 bytes
1646 The table length is the total size of the table, including the 4 bytes
1647 for the length information.
1649 The base address is the address of the first instruction generated
1650 for the source file.
1652 Each source statement entry has the following structure:
1654 <line number><statement position><address delta>
1655 4 bytes 2 bytes 4 bytes
1657 The line number is relative to the start of the file, starting with
1660 The statement position either -1 (0xFFFF) or the number of characters
1661 from the beginning of the line to the beginning of the statement.
1663 The address delta is the difference between the base address and
1664 the address of the first instruction for the statement.
1666 Note that we must copy the bytes from the packed table to our local
1667 variables before attempting to use them, to avoid alignment problems
1668 on some machines, particularly RISC processors.
1672 Does gdb expect the line numbers to be sorted? They are now by
1673 chance/luck, but are not required to be. (FIXME)
1675 The line with number 0 is unused, gdb apparently can discover the
1676 span of the last line some other way. How? (FIXME)
1680 decode_line_numbers (linetable
)
1690 if (linetable
!= NULL
)
1692 tblscan
= tblend
= linetable
;
1693 (void) memcpy (&length
, tblscan
, sizeof (long));
1694 tblscan
+= sizeof (long);
1696 (void) memcpy (&base
, tblscan
, sizeof (long));
1698 tblscan
+= sizeof (long);
1699 while (tblscan
< tblend
)
1701 (void) memcpy (&line
, tblscan
, sizeof (long));
1702 tblscan
+= sizeof (long) + sizeof (short);
1703 (void) memcpy (&pc
, tblscan
, sizeof (long));
1704 tblscan
+= sizeof (long);
1708 record_line (current_subfile
, line
, pc
);
1718 locval -- compute the value of a location attribute
1722 static int locval (char *loc)
1726 Given pointer to a string of bytes that define a location, compute
1727 the location and return the value.
1729 When computing values involving the current value of the frame pointer,
1730 the value zero is used, which results in a value relative to the frame
1731 pointer, rather than the absolute value. This is what GDB wants
1734 When the result is a register number, the global isreg flag is set,
1735 otherwise it is cleared. This is a kludge until we figure out a better
1736 way to handle the problem. Gdb's design does not mesh well with the
1737 DWARF notion of a location computing interpreter, which is a shame
1738 because the flexibility goes unused.
1742 Note that stack[0] is unused except as a default error return.
1743 Note that stack overflow is not yet handled.
1750 unsigned short nbytes
;
1756 (void) memcpy (&nbytes
, loc
, sizeof (short));
1757 end
= loc
+ sizeof (short) + nbytes
;
1762 for (loc
+= sizeof (short); loc
< end
; loc
+= sizeof (long))
1770 /* push register (number) */
1771 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1775 /* push value of register (number) */
1776 /* Actually, we compute the value as if register has 0 */
1778 (void) memcpy (®no
, loc
, sizeof (long));
1781 stack
[++stacki
] = 0;
1785 stack
[++stacki
] = 0;
1786 SQUAWK (("BASEREG %d not handled!", regno
));
1790 /* push address (relocated address) */
1791 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1794 /* push constant (number) */
1795 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1798 /* pop, deref and push 2 bytes (as a long) */
1799 SQUAWK (("OP_DEREF2 address %#x not handled", stack
[stacki
]));
1801 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1802 SQUAWK (("OP_DEREF4 address %#x not handled", stack
[stacki
]));
1804 case OP_ADD
: /* pop top 2 items, add, push result */
1805 stack
[stacki
- 1] += stack
[stacki
];
1810 return (stack
[stacki
]);
1817 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1821 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1825 When expanding a partial symbol table entry to a full symbol table
1826 entry, this is the function that gets called to read in the symbols
1827 for the compilation unit.
1829 Returns a pointer to the newly constructed symtab (which is now
1830 the new first one on the objfile's symtab list).
1833 static struct symtab
*
1834 read_ofile_symtab (pst
)
1835 struct partial_symtab
*pst
;
1837 struct cleanup
*back_to
;
1842 abfd
= pst
-> objfile
-> obfd
;
1843 current_objfile
= pst
-> objfile
;
1845 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1846 unit, seek to the location in the file, and read in all the DIE's. */
1849 dbbase
= xmalloc (DBLENGTH(pst
));
1850 dbroff
= DBROFF(pst
);
1851 foffset
= DBFOFF(pst
) + dbroff
;
1852 baseaddr
= pst
-> addr
;
1853 if (bfd_seek (abfd
, foffset
, 0) ||
1854 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1857 error ("can't read DWARF data");
1859 back_to
= make_cleanup (free
, dbbase
);
1861 /* If there is a line number table associated with this compilation unit
1862 then read the first long word from the line number table fragment, which
1863 contains the size of the fragment in bytes (including the long word
1864 itself). Allocate a buffer for the fragment and read it in for future
1870 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1871 (bfd_read (&lnsize
, sizeof(long), 1, abfd
) != sizeof(long)))
1873 error ("can't read DWARF line number table size");
1875 lnbase
= xmalloc (lnsize
);
1876 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1877 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1880 error ("can't read DWARF line numbers");
1882 make_cleanup (free
, lnbase
);
1885 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1886 do_cleanups (back_to
);
1887 current_objfile
= NULL
;
1888 return (pst
-> objfile
-> symtabs
);
1895 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1899 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1903 Called once for each partial symbol table entry that needs to be
1904 expanded into a full symbol table entry.
1909 psymtab_to_symtab_1 (pst
)
1910 struct partial_symtab
*pst
;
1918 warning ("Psymtab for %s already read in. Shouldn't happen.",
1923 /* Read in all partial symtabs on which this one is dependent */
1924 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
1926 if (!pst
-> dependencies
[i
] -> readin
)
1928 /* Inform about additional files that need to be read in. */
1931 fputs_filtered (" ", stdout
);
1933 fputs_filtered ("and ", stdout
);
1935 printf_filtered ("%s...",
1936 pst
-> dependencies
[i
] -> filename
);
1938 fflush (stdout
); /* Flush output */
1940 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
1943 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
1945 pst
-> symtab
= read_ofile_symtab (pst
);
1948 printf_filtered ("%d DIE's, sorting...", diecount
);
1952 sort_symtab_syms (pst
-> symtab
);
1963 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
1967 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
1971 This is the DWARF support entry point for building a full symbol
1972 table entry from a partial symbol table entry. We are passed a
1973 pointer to the partial symbol table entry that needs to be expanded.
1978 dwarf_psymtab_to_symtab (pst
)
1979 struct partial_symtab
*pst
;
1986 warning ("Psymtab for %s already read in. Shouldn't happen.",
1991 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
1993 /* Print the message now, before starting serious work, to avoid
1994 disconcerting pauses. */
1997 printf_filtered ("Reading in symbols for %s...",
2002 psymtab_to_symtab_1 (pst
);
2004 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2005 we need to do an equivalent or is this something peculiar to
2007 Match with global symbols. This only needs to be done once,
2008 after all of the symtabs and dependencies have been read in.
2010 scan_file_globals (pst
-> objfile
);
2013 /* Finish up the verbose info message. */
2016 printf_filtered ("done.\n");
2028 init_psymbol_list -- initialize storage for partial symbols
2032 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2036 Initializes storage for all of the partial symbols that will be
2037 created by dwarf_build_psymtabs and subsidiaries.
2041 init_psymbol_list (objfile
, total_symbols
)
2042 struct objfile
*objfile
;
2045 /* Free any previously allocated psymbol lists. */
2047 if (objfile
-> global_psymbols
.list
)
2049 (*objfile
-> free
) (objfile
-> global_psymbols
.list
);
2051 if (objfile
-> static_psymbols
.list
)
2053 (*objfile
-> free
) (objfile
-> static_psymbols
.list
);
2056 /* Current best guess is that there are approximately a twentieth
2057 of the total symbols (in a debugging file) are global or static
2060 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2061 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2062 objfile
-> global_psymbols
.next
=
2063 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2064 (*objfile
-> xmalloc
) (objfile
-> global_psymbols
.size
2065 * sizeof (struct partial_symbol
));
2066 objfile
-> static_psymbols
.next
=
2067 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2068 (*objfile
-> xmalloc
) (objfile
-> static_psymbols
.size
2069 * sizeof (struct partial_symbol
));
2076 add_enum_psymbol -- add enumeration members to partial symbol table
2080 Given pointer to a DIE that is known to be for an enumeration,
2081 extract the symbolic names of the enumeration members and add
2082 partial symbols for them.
2086 add_enum_psymbol (dip
, objfile
)
2087 struct dieinfo
*dip
;
2088 struct objfile
*objfile
;
2095 if ((scan
= dip
-> at_element_list
) != NULL
)
2097 if (dip
-> short_element_list
)
2099 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
2100 listend
= scan
+ stemp
+ sizeof (stemp
);
2101 scan
+= sizeof (stemp
);
2105 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
2106 listend
= scan
+ ltemp
+ sizeof (ltemp
);
2107 scan
+= sizeof (ltemp
);
2109 while (scan
< listend
)
2111 scan
+= sizeof (long);
2112 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2113 objfile
-> static_psymbols
, 0);
2114 scan
+= strlen (scan
) + 1;
2123 add_partial_symbol -- add symbol to partial symbol table
2127 Given a DIE, if it is one of the types that we want to
2128 add to a partial symbol table, finish filling in the die info
2129 and then add a partial symbol table entry for it.
2134 add_partial_symbol (dip
, objfile
)
2135 struct dieinfo
*dip
;
2136 struct objfile
*objfile
;
2138 switch (dip
-> dietag
)
2140 case TAG_global_subroutine
:
2141 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2143 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2144 VAR_NAMESPACE
, LOC_BLOCK
,
2145 objfile
-> global_psymbols
,
2148 case TAG_global_variable
:
2149 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2151 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2152 VAR_NAMESPACE
, LOC_STATIC
,
2153 objfile
-> global_psymbols
,
2156 case TAG_subroutine
:
2157 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2158 VAR_NAMESPACE
, LOC_BLOCK
,
2159 objfile
-> static_psymbols
,
2162 case TAG_local_variable
:
2163 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2164 VAR_NAMESPACE
, LOC_STATIC
,
2165 objfile
-> static_psymbols
,
2169 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2170 VAR_NAMESPACE
, LOC_TYPEDEF
,
2171 objfile
-> static_psymbols
,
2174 case TAG_structure_type
:
2175 case TAG_union_type
:
2176 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2177 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2178 objfile
-> static_psymbols
,
2181 case TAG_enumeration_type
:
2184 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2185 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2186 objfile
-> static_psymbols
,
2189 add_enum_psymbol (dip
, objfile
);
2198 scan_partial_symbols -- scan DIE's within a single compilation unit
2202 Process the DIE's within a single compilation unit, looking for
2203 interesting DIE's that contribute to the partial symbol table entry
2204 for this compilation unit. Since we cannot follow any sibling
2205 chains without reading the complete DIE info for every DIE,
2206 it is probably faster to just sequentially check each one to
2207 see if it is one of the types we are interested in, and if so,
2208 then extract all the attributes info and generate a partial
2213 Don't attempt to add anonymous structures or unions since they have
2214 no name. Anonymous enumerations however are processed, because we
2215 want to extract their member names (the check for a tag name is
2218 Also, for variables and subroutines, check that this is the place
2219 where the actual definition occurs, rather than just a reference
2224 scan_partial_symbols (thisdie
, enddie
, objfile
)
2227 struct objfile
*objfile
;
2232 while (thisdie
< enddie
)
2234 basicdieinfo (&di
, thisdie
);
2235 if (di
.dielength
< sizeof (long))
2241 nextdie
= thisdie
+ di
.dielength
;
2242 /* To avoid getting complete die information for every die, we
2243 only do it (below) for the cases we are interested in. */
2246 case TAG_global_subroutine
:
2247 case TAG_subroutine
:
2248 case TAG_global_variable
:
2249 case TAG_local_variable
:
2250 completedieinfo (&di
);
2251 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2253 add_partial_symbol (&di
, objfile
);
2257 case TAG_structure_type
:
2258 case TAG_union_type
:
2259 completedieinfo (&di
);
2262 add_partial_symbol (&di
, objfile
);
2265 case TAG_enumeration_type
:
2266 completedieinfo (&di
);
2267 add_partial_symbol (&di
, objfile
);
2279 scan_compilation_units -- build a psymtab entry for each compilation
2283 This is the top level dwarf parsing routine for building partial
2286 It scans from the beginning of the DWARF table looking for the first
2287 TAG_compile_unit DIE, and then follows the sibling chain to locate
2288 each additional TAG_compile_unit DIE.
2290 For each TAG_compile_unit DIE it creates a partial symtab structure,
2291 calls a subordinate routine to collect all the compilation unit's
2292 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2293 new partial symtab structure into the partial symbol table. It also
2294 records the appropriate information in the partial symbol table entry
2295 to allow the chunk of DIE's and line number table for this compilation
2296 unit to be located and re-read later, to generate a complete symbol
2297 table entry for the compilation unit.
2299 Thus it effectively partitions up a chunk of DIE's for multiple
2300 compilation units into smaller DIE chunks and line number tables,
2301 and associates them with a partial symbol table entry.
2305 If any compilation unit has no line number table associated with
2306 it for some reason (a missing at_stmt_list attribute, rather than
2307 just one with a value of zero, which is valid) then we ensure that
2308 the recorded file offset is zero so that the routine which later
2309 reads line number table fragments knows that there is no fragment
2319 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2323 unsigned int dbfoff
;
2324 unsigned int lnoffset
;
2325 struct objfile
*objfile
;
2329 struct partial_symtab
*pst
;
2334 while (thisdie
< enddie
)
2336 basicdieinfo (&di
, thisdie
);
2337 if (di
.dielength
< sizeof (long))
2341 else if (di
.dietag
!= TAG_compile_unit
)
2343 nextdie
= thisdie
+ di
.dielength
;
2347 completedieinfo (&di
);
2348 if (di
.at_sibling
!= 0)
2350 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2354 nextdie
= thisdie
+ di
.dielength
;
2356 curoff
= thisdie
- dbbase
;
2357 culength
= nextdie
- thisdie
;
2358 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2360 /* First allocate a new partial symbol table structure */
2362 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2364 objfile
-> global_psymbols
.next
,
2365 objfile
-> static_psymbols
.next
);
2367 pst
-> texthigh
= di
.at_high_pc
;
2368 pst
-> read_symtab_private
= (char *)
2369 obstack_alloc (&objfile
-> psymbol_obstack
,
2370 sizeof (struct dwfinfo
));
2371 DBFOFF (pst
) = dbfoff
;
2372 DBROFF (pst
) = curoff
;
2373 DBLENGTH (pst
) = culength
;
2374 LNFOFF (pst
) = curlnoffset
;
2375 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2377 /* Now look for partial symbols */
2379 scan_partial_symbols (thisdie
+ di
.dielength
, nextdie
, objfile
);
2381 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2382 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2383 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2384 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2385 sort_pst_symbols (pst
);
2386 /* If there is already a psymtab or symtab for a file of this name,
2387 remove it. (If there is a symtab, more drastic things also
2388 happen.) This happens in VxWorks. */
2389 free_named_symtabs (pst
-> filename
);
2399 new_symbol -- make a symbol table entry for a new symbol
2403 static struct symbol *new_symbol (struct dieinfo *dip,
2404 struct objfile *objfile)
2408 Given a pointer to a DWARF information entry, figure out if we need
2409 to make a symbol table entry for it, and if so, create a new entry
2410 and return a pointer to it.
2413 static struct symbol
*
2414 new_symbol (dip
, objfile
)
2415 struct dieinfo
*dip
;
2416 struct objfile
*objfile
;
2418 struct symbol
*sym
= NULL
;
2420 if (dip
-> at_name
!= NULL
)
2422 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2423 sizeof (struct symbol
));
2424 (void) memset (sym
, 0, sizeof (struct symbol
));
2425 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2426 /* default assumptions */
2427 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2428 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2429 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2430 switch (dip
-> dietag
)
2433 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2434 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2436 case TAG_global_subroutine
:
2437 case TAG_subroutine
:
2438 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2439 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2440 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2441 if (dip
-> dietag
== TAG_global_subroutine
)
2443 add_symbol_to_list (sym
, &global_symbols
);
2447 add_symbol_to_list (sym
, list_in_scope
);
2450 case TAG_global_variable
:
2451 if (dip
-> at_location
!= NULL
)
2453 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2454 add_symbol_to_list (sym
, &global_symbols
);
2455 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2456 SYMBOL_VALUE (sym
) += baseaddr
;
2459 case TAG_local_variable
:
2460 if (dip
-> at_location
!= NULL
)
2462 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2463 add_symbol_to_list (sym
, list_in_scope
);
2466 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2470 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2474 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2475 SYMBOL_VALUE (sym
) += baseaddr
;
2479 case TAG_formal_parameter
:
2480 if (dip
-> at_location
!= NULL
)
2482 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2484 add_symbol_to_list (sym
, list_in_scope
);
2487 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2491 SYMBOL_CLASS (sym
) = LOC_ARG
;
2494 case TAG_unspecified_parameters
:
2495 /* From varargs functions; gdb doesn't seem to have any interest in
2496 this information, so just ignore it for now. (FIXME?) */
2498 case TAG_structure_type
:
2499 case TAG_union_type
:
2500 case TAG_enumeration_type
:
2501 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2502 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2503 add_symbol_to_list (sym
, list_in_scope
);
2506 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2507 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2508 add_symbol_to_list (sym
, list_in_scope
);
2511 /* Not a tag we recognize. Hopefully we aren't processing trash
2512 data, but since we must specifically ignore things we don't
2513 recognize, there is nothing else we should do at this point. */
2524 decode_mod_fund_type -- decode a modified fundamental type
2528 static struct type *decode_mod_fund_type (char *typedata)
2532 Decode a block of data containing a modified fundamental
2533 type specification. TYPEDATA is a pointer to the block,
2534 which consists of a two byte length, containing the size
2535 of the rest of the block. At the end of the block is a
2536 two byte value that gives the fundamental type. Everything
2537 in between are type modifiers.
2539 We simply compute the number of modifiers and call the general
2540 function decode_modified_type to do the actual work.
2543 static struct type
*
2544 decode_mod_fund_type (typedata
)
2547 struct type
*typep
= NULL
;
2548 unsigned short modcount
;
2549 unsigned char *modifiers
;
2551 /* Get the total size of the block, exclusive of the size itself */
2552 (void) memcpy (&modcount
, typedata
, sizeof (short));
2553 /* Deduct the size of the fundamental type bytes at the end of the block. */
2554 modcount
-= sizeof (short);
2555 /* Skip over the two size bytes at the beginning of the block. */
2556 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2557 /* Now do the actual decoding */
2558 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_fund_type
);
2566 decode_mod_u_d_type -- decode a modified user defined type
2570 static struct type *decode_mod_u_d_type (char *typedata)
2574 Decode a block of data containing a modified user defined
2575 type specification. TYPEDATA is a pointer to the block,
2576 which consists of a two byte length, containing the size
2577 of the rest of the block. At the end of the block is a
2578 four byte value that gives a reference to a user defined type.
2579 Everything in between are type modifiers.
2581 We simply compute the number of modifiers and call the general
2582 function decode_modified_type to do the actual work.
2585 static struct type
*
2586 decode_mod_u_d_type (typedata
)
2589 struct type
*typep
= NULL
;
2590 unsigned short modcount
;
2591 unsigned char *modifiers
;
2593 /* Get the total size of the block, exclusive of the size itself */
2594 (void) memcpy (&modcount
, typedata
, sizeof (short));
2595 /* Deduct the size of the reference type bytes at the end of the block. */
2596 modcount
-= sizeof (long);
2597 /* Skip over the two size bytes at the beginning of the block. */
2598 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2599 /* Now do the actual decoding */
2600 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_u_d_type
);
2608 decode_modified_type -- decode modified user or fundamental type
2612 static struct type *decode_modified_type (unsigned char *modifiers,
2613 unsigned short modcount, int mtype)
2617 Decode a modified type, either a modified fundamental type or
2618 a modified user defined type. MODIFIERS is a pointer to the
2619 block of bytes that define MODCOUNT modifiers. Immediately
2620 following the last modifier is a short containing the fundamental
2621 type or a long containing the reference to the user defined
2622 type. Which one is determined by MTYPE, which is either
2623 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2624 type we are generating.
2626 We call ourself recursively to generate each modified type,`
2627 until MODCOUNT reaches zero, at which point we have consumed
2628 all the modifiers and generate either the fundamental type or
2629 user defined type. When the recursion unwinds, each modifier
2630 is applied in turn to generate the full modified type.
2634 If we find a modifier that we don't recognize, and it is not one
2635 of those reserved for application specific use, then we issue a
2636 warning and simply ignore the modifier.
2640 We currently ignore MOD_const and MOD_volatile. (FIXME)
2644 static struct type
*
2645 decode_modified_type (modifiers
, modcount
, mtype
)
2646 unsigned char *modifiers
;
2647 unsigned int modcount
;
2650 struct type
*typep
= NULL
;
2651 unsigned short fundtype
;
2653 unsigned char modifier
;
2659 case AT_mod_fund_type
:
2660 (void) memcpy (&fundtype
, modifiers
, sizeof (short));
2661 typep
= decode_fund_type (fundtype
);
2663 case AT_mod_u_d_type
:
2664 (void) memcpy (&dieref
, modifiers
, sizeof (DIEREF
));
2665 if ((typep
= lookup_utype (dieref
)) == NULL
)
2667 typep
= alloc_utype (dieref
, NULL
);
2671 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2672 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2678 modifier
= *modifiers
++;
2679 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2682 case MOD_pointer_to
:
2683 typep
= lookup_pointer_type (typep
);
2685 case MOD_reference_to
:
2686 typep
= lookup_reference_type (typep
);
2689 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2692 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2695 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2697 SQUAWK (("unknown type modifier %u", modifier
));
2709 decode_fund_type -- translate basic DWARF type to gdb base type
2713 Given an integer that is one of the fundamental DWARF types,
2714 translate it to one of the basic internal gdb types and return
2715 a pointer to the appropriate gdb type (a "struct type *").
2719 If we encounter a fundamental type that we are unprepared to
2720 deal with, and it is not in the range of those types defined
2721 as application specific types, then we issue a warning and
2722 treat the type as an "int".
2725 static struct type
*
2726 decode_fund_type (fundtype
)
2727 unsigned int fundtype
;
2729 struct type
*typep
= NULL
;
2735 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2738 case FT_boolean
: /* Was FT_set in AT&T version */
2739 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2742 case FT_pointer
: /* (void *) */
2743 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2744 typep
= lookup_pointer_type (typep
);
2748 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2751 case FT_signed_char
:
2752 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2755 case FT_unsigned_char
:
2756 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2760 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2763 case FT_signed_short
:
2764 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2767 case FT_unsigned_short
:
2768 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2772 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2775 case FT_signed_integer
:
2776 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2779 case FT_unsigned_integer
:
2780 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2784 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2787 case FT_signed_long
:
2788 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2791 case FT_unsigned_long
:
2792 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2796 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2799 case FT_signed_long_long
:
2800 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2803 case FT_unsigned_long_long
:
2804 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2808 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2811 case FT_dbl_prec_float
:
2812 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2815 case FT_ext_prec_float
:
2816 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2820 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2823 case FT_dbl_prec_complex
:
2824 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2827 case FT_ext_prec_complex
:
2828 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2833 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2835 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2836 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2846 create_name -- allocate a fresh copy of a string on an obstack
2850 Given a pointer to a string and a pointer to an obstack, allocates
2851 a fresh copy of the string on the specified obstack.
2856 create_name (name
, obstackp
)
2858 struct obstack
*obstackp
;
2863 length
= strlen (name
) + 1;
2864 newname
= (char *) obstack_alloc (obstackp
, length
);
2865 (void) strcpy (newname
, name
);
2873 basicdieinfo -- extract the minimal die info from raw die data
2877 void basicdieinfo (char *diep, struct dieinfo *dip)
2881 Given a pointer to raw DIE data, and a pointer to an instance of a
2882 die info structure, this function extracts the basic information
2883 from the DIE data required to continue processing this DIE, along
2884 with some bookkeeping information about the DIE.
2886 The information we absolutely must have includes the DIE tag,
2887 and the DIE length. If we need the sibling reference, then we
2888 will have to call completedieinfo() to process all the remaining
2891 Note that since there is no guarantee that the data is properly
2892 aligned in memory for the type of access required (indirection
2893 through anything other than a char pointer), we use memcpy to
2894 shuffle data items larger than a char. Possibly inefficient, but
2897 We also take care of some other basic things at this point, such
2898 as ensuring that the instance of the die info structure starts
2899 out completely zero'd and that curdie is initialized for use
2900 in error reporting if we have a problem with the current die.
2904 All DIE's must have at least a valid length, thus the minimum
2905 DIE size is sizeof (long). In order to have a valid tag, the
2906 DIE size must be at least sizeof (short) larger, otherwise they
2907 are forced to be TAG_padding DIES.
2909 Padding DIES must be at least sizeof(long) in length, implying that
2910 if a padding DIE is used for alignment and the amount needed is less
2911 than sizeof(long) then the padding DIE has to be big enough to align
2912 to the next alignment boundry.
2916 basicdieinfo (dip
, diep
)
2917 struct dieinfo
*dip
;
2921 (void) memset (dip
, 0, sizeof (struct dieinfo
));
2923 dip
-> dieref
= dbroff
+ (diep
- dbbase
);
2924 (void) memcpy (&dip
-> dielength
, diep
, sizeof (long));
2925 if (dip
-> dielength
< sizeof (long))
2927 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> dielength
);
2929 else if (dip
-> dielength
< (sizeof (long) + sizeof (short)))
2931 dip
-> dietag
= TAG_padding
;
2935 (void) memcpy (&dip
-> dietag
, diep
+ sizeof (long), sizeof (short));
2943 completedieinfo -- finish reading the information for a given DIE
2947 void completedieinfo (struct dieinfo *dip)
2951 Given a pointer to an already partially initialized die info structure,
2952 scan the raw DIE data and finish filling in the die info structure
2953 from the various attributes found.
2955 Note that since there is no guarantee that the data is properly
2956 aligned in memory for the type of access required (indirection
2957 through anything other than a char pointer), we use memcpy to
2958 shuffle data items larger than a char. Possibly inefficient, but
2963 Each time we are called, we increment the diecount variable, which
2964 keeps an approximate count of the number of dies processed for
2965 each compilation unit. This information is presented to the user
2966 if the info_verbose flag is set.
2971 completedieinfo (dip
)
2972 struct dieinfo
*dip
;
2974 char *diep
; /* Current pointer into raw DIE data */
2975 char *end
; /* Terminate DIE scan here */
2976 unsigned short attr
; /* Current attribute being scanned */
2977 unsigned short form
; /* Form of the attribute */
2978 short block2sz
; /* Size of a block2 attribute field */
2979 long block4sz
; /* Size of a block4 attribute field */
2983 end
= diep
+ dip
-> dielength
;
2984 diep
+= sizeof (long) + sizeof (short);
2987 (void) memcpy (&attr
, diep
, sizeof (short));
2988 diep
+= sizeof (short);
2992 (void) memcpy (&dip
-> at_fund_type
, diep
, sizeof (short));
2995 (void) memcpy (&dip
-> at_ordering
, diep
, sizeof (short));
2998 (void) memcpy (&dip
-> at_bit_offset
, diep
, sizeof (short));
3001 (void) memcpy (&dip
-> at_visibility
, diep
, sizeof (short));
3004 (void) memcpy (&dip
-> at_sibling
, diep
, sizeof (long));
3007 (void) memcpy (&dip
-> at_stmt_list
, diep
, sizeof (long));
3008 dip
-> has_at_stmt_list
= 1;
3011 (void) memcpy (&dip
-> at_low_pc
, diep
, sizeof (long));
3012 dip
-> at_low_pc
+= baseaddr
;
3013 dip
-> has_at_low_pc
= 1;
3016 (void) memcpy (&dip
-> at_high_pc
, diep
, sizeof (long));
3017 dip
-> at_high_pc
+= baseaddr
;
3020 (void) memcpy (&dip
-> at_language
, diep
, sizeof (long));
3022 case AT_user_def_type
:
3023 (void) memcpy (&dip
-> at_user_def_type
, diep
, sizeof (long));
3026 (void) memcpy (&dip
-> at_byte_size
, diep
, sizeof (long));
3029 (void) memcpy (&dip
-> at_bit_size
, diep
, sizeof (long));
3032 (void) memcpy (&dip
-> at_member
, diep
, sizeof (long));
3035 (void) memcpy (&dip
-> at_discr
, diep
, sizeof (long));
3038 (void) memcpy (&dip
-> at_import
, diep
, sizeof (long));
3041 dip
-> at_location
= diep
;
3043 case AT_mod_fund_type
:
3044 dip
-> at_mod_fund_type
= diep
;
3046 case AT_subscr_data
:
3047 dip
-> at_subscr_data
= diep
;
3049 case AT_mod_u_d_type
:
3050 dip
-> at_mod_u_d_type
= diep
;
3052 case AT_element_list
:
3053 dip
-> at_element_list
= diep
;
3054 dip
-> short_element_list
= 0;
3056 case AT_short_element_list
:
3057 dip
-> at_element_list
= diep
;
3058 dip
-> short_element_list
= 1;
3060 case AT_discr_value
:
3061 dip
-> at_discr_value
= diep
;
3063 case AT_string_length
:
3064 dip
-> at_string_length
= diep
;
3067 dip
-> at_name
= diep
;
3070 dip
-> at_comp_dir
= diep
;
3073 dip
-> at_producer
= diep
;
3076 (void) memcpy (&dip
-> at_frame_base
, diep
, sizeof (long));
3078 case AT_start_scope
:
3079 (void) memcpy (&dip
-> at_start_scope
, diep
, sizeof (long));
3081 case AT_stride_size
:
3082 (void) memcpy (&dip
-> at_stride_size
, diep
, sizeof (long));
3085 (void) memcpy (&dip
-> at_src_info
, diep
, sizeof (long));
3088 (void) memcpy (&dip
-> at_prototyped
, diep
, sizeof (short));
3091 /* Found an attribute that we are unprepared to handle. However
3092 it is specifically one of the design goals of DWARF that
3093 consumers should ignore unknown attributes. As long as the
3094 form is one that we recognize (so we know how to skip it),
3095 we can just ignore the unknown attribute. */
3102 diep
+= sizeof (short);
3105 diep
+= sizeof (long);
3108 diep
+= 8 * sizeof (char); /* sizeof (long long) ? */
3112 diep
+= sizeof (long);
3115 (void) memcpy (&block2sz
, diep
, sizeof (short));
3116 block2sz
+= sizeof (short);
3120 (void) memcpy (&block4sz
, diep
, sizeof (long));
3121 block4sz
+= sizeof (long);
3125 diep
+= strlen (diep
) + 1;
3128 SQUAWK (("unknown attribute form (0x%x), skipped rest", form
));