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 CORE_ADDR startup_file_start
; /* From blockframe.c */
100 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
101 extern CORE_ADDR entry_scope_lowpc
; /* From blockframe.c */
102 extern CORE_ADDR entry_scope_highpc
; /* From blockframc.c */
103 extern CORE_ADDR main_scope_lowpc
; /* From blockframe.c */
104 extern CORE_ADDR main_scope_highpc
; /* From blockframc.c */
105 extern int info_verbose
; /* From main.c; nonzero => verbose */
108 /* The DWARF debugging information consists of two major pieces,
109 one is a block of DWARF Information Entries (DIE's) and the other
110 is a line number table. The "struct dieinfo" structure contains
111 the information for a single DIE, the one currently being processed.
113 In order to make it easier to randomly access the attribute fields
114 of the current DIE, which are specifically unordered within the DIE
115 each DIE is scanned and an instance of the "struct dieinfo"
116 structure is initialized.
118 Initialization is done in two levels. The first, done by basicdieinfo(),
119 just initializes those fields that are vital to deciding whether or not
120 to use this DIE, how to skip past it, etc. The second, done by the
121 function completedieinfo(), fills in the rest of the information.
123 Attributes which have block forms are not interpreted at the time
124 the DIE is scanned, instead we just save pointers to the start
125 of their value fields.
127 Some fields have a flag <name>_p that is set when the value of the
128 field is valid (I.E. we found a matching attribute in the DIE). Since
129 we may want to test for the presence of some attributes in the DIE,
130 such as AT_low_pc, without restricting the values of the field,
131 we need someway to note that we found such an attribute.
138 char * die
; /* Pointer to the raw DIE data */
139 long dielength
; /* Length of the raw DIE data */
140 DIEREF dieref
; /* Offset of this DIE */
141 short dietag
; /* Tag for this DIE */
146 unsigned short at_fund_type
;
147 BLOCK
* at_mod_fund_type
;
148 long at_user_def_type
;
149 BLOCK
* at_mod_u_d_type
;
151 BLOCK
* at_subscr_data
;
155 BLOCK
* at_element_list
;
162 BLOCK
* at_discr_value
;
165 BLOCK
* at_string_length
;
173 unsigned int has_at_low_pc
:1;
174 unsigned int has_at_stmt_list
:1;
175 unsigned int short_element_list
:1;
178 static int diecount
; /* Approximate count of dies for compilation unit */
179 static struct dieinfo
*curdie
; /* For warnings and such */
181 static char *dbbase
; /* Base pointer to dwarf info */
182 static int dbroff
; /* Relative offset from start of .debug section */
183 static char *lnbase
; /* Base pointer to line section */
184 static int isreg
; /* Kludge to identify register variables */
185 static int offreg
; /* Kludge to identify basereg references */
187 static CORE_ADDR baseaddr
; /* Add to each symbol value */
189 /* Each partial symbol table entry contains a pointer to private data for the
190 read_symtab() function to use when expanding a partial symbol table entry
191 to a full symbol table entry. For DWARF debugging info, this data is
192 contained in the following structure and macros are provided for easy
193 access to the members given a pointer to a partial symbol table entry.
195 dbfoff Always the absolute file offset to the start of the ".debug"
196 section for the file containing the DIE's being accessed.
198 dbroff Relative offset from the start of the ".debug" access to the
199 first DIE to be accessed. When building the partial symbol
200 table, this value will be zero since we are accessing the
201 entire ".debug" section. When expanding a partial symbol
202 table entry, this value will be the offset to the first
203 DIE for the compilation unit containing the symbol that
204 triggers the expansion.
206 dblength The size of the chunk of DIE's being examined, in bytes.
208 lnfoff The absolute file offset to the line table fragment. Ignored
209 when building partial symbol tables, but used when expanding
210 them, and contains the absolute file offset to the fragment
211 of the ".line" section containing the line numbers for the
212 current compilation unit.
216 int dbfoff
; /* Absolute file offset to start of .debug section */
217 int dbroff
; /* Relative offset from start of .debug section */
218 int dblength
; /* Size of the chunk of DIE's being examined */
219 int lnfoff
; /* Absolute file offset to line table fragment */
222 #define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
223 #define DBROFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbroff)
224 #define DBLENGTH(p) (((struct dwfinfo *)((p)->read_symtab_private))->dblength)
225 #define LNFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->lnfoff)
227 /* The generic symbol table building routines have separate lists for
228 file scope symbols and all all other scopes (local scopes). So
229 we need to select the right one to pass to add_symbol_to_list().
230 We do it by keeping a pointer to the correct list in list_in_scope.
232 FIXME: The original dwarf code just treated the file scope as the first
233 local scope, and all other local scopes as nested local scopes, and worked
234 fine. Check to see if we really need to distinguish these in buildsym.c */
236 struct pending
**list_in_scope
= &file_symbols
;
238 /* DIES which have user defined types or modified user defined types refer to
239 other DIES for the type information. Thus we need to associate the offset
240 of a DIE for a user defined type with a pointer to the type information.
242 Originally this was done using a simple but expensive algorithm, with an
243 array of unsorted structures, each containing an offset/type-pointer pair.
244 This array was scanned linearly each time a lookup was done. The result
245 was that gdb was spending over half it's startup time munging through this
246 array of pointers looking for a structure that had the right offset member.
248 The second attempt used the same array of structures, but the array was
249 sorted using qsort each time a new offset/type was recorded, and a binary
250 search was used to find the type pointer for a given DIE offset. This was
251 even slower, due to the overhead of sorting the array each time a new
252 offset/type pair was entered.
254 The third attempt uses a fixed size array of type pointers, indexed by a
255 value derived from the DIE offset. Since the minimum DIE size is 4 bytes,
256 we can divide any DIE offset by 4 to obtain a unique index into this fixed
257 size array. Since each element is a 4 byte pointer, it takes exactly as
258 much memory to hold this array as to hold the DWARF info for a given
259 compilation unit. But it gets freed as soon as we are done with it. */
261 static struct type
**utypes
; /* Pointer to array of user type pointers */
262 static int numutypes
; /* Max number of user type pointers */
264 /* Forward declarations of static functions so we don't have to worry
265 about ordering within this file. */
268 add_enum_psymbol
PARAMS ((struct dieinfo
*, struct objfile
*));
271 read_file_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
274 read_func_scope
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
277 read_lexical_block_scope
PARAMS ((struct dieinfo
*, char *, char *,
284 scan_partial_symbols
PARAMS ((char *, char *, struct objfile
*));
287 scan_compilation_units
PARAMS ((char *, char *, char *, unsigned int,
288 unsigned int, struct objfile
*));
291 add_partial_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
294 init_psymbol_list
PARAMS ((struct objfile
*, int));
297 basicdieinfo
PARAMS ((struct dieinfo
*, char *));
300 completedieinfo
PARAMS ((struct dieinfo
*));
303 dwarf_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
306 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
308 static struct symtab
*
309 read_ofile_symtab
PARAMS ((struct partial_symtab
*));
312 process_dies
PARAMS ((char *, char *, struct objfile
*));
315 read_structure_scope
PARAMS ((struct dieinfo
*, char *, char *,
319 decode_array_element_type
PARAMS ((char *, char *));
322 decode_subscr_data
PARAMS ((char *, char *));
325 dwarf_read_array_type
PARAMS ((struct dieinfo
*));
328 read_tag_pointer_type
PARAMS ((struct dieinfo
*dip
));
331 read_subroutine_type
PARAMS ((struct dieinfo
*, char *, char *));
334 read_enumeration
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
337 struct_type
PARAMS ((struct dieinfo
*, char *, char *, struct objfile
*));
340 enum_type
PARAMS ((struct dieinfo
*, struct objfile
*));
343 decode_line_numbers
PARAMS ((char *));
346 decode_die_type
PARAMS ((struct dieinfo
*));
349 decode_mod_fund_type
PARAMS ((char *));
352 decode_mod_u_d_type
PARAMS ((char *));
355 decode_modified_type
PARAMS ((unsigned char *, unsigned int, int));
358 decode_fund_type
PARAMS ((unsigned int));
361 create_name
PARAMS ((char *, struct obstack
*));
364 lookup_utype
PARAMS ((DIEREF
));
367 alloc_utype
PARAMS ((DIEREF
, struct type
*));
369 static struct symbol
*
370 new_symbol
PARAMS ((struct dieinfo
*, struct objfile
*));
373 locval
PARAMS ((char *));
376 record_minimal_symbol
PARAMS ((char *, CORE_ADDR
, enum minimal_symbol_type
,
383 dwarf_build_psymtabs -- build partial symtabs from DWARF debug info
387 void dwarf_build_psymtabs (int desc, char *filename, CORE_ADDR addr,
388 int mainline, unsigned int dbfoff, unsigned int dbsize,
389 unsigned int lnoffset, unsigned int lnsize,
390 struct objfile *objfile)
394 This function is called upon to build partial symtabs from files
395 containing DIE's (Dwarf Information Entries) and DWARF line numbers.
397 It is passed a file descriptor for an open file containing the DIES
398 and line number information, the corresponding filename for that
399 file, a base address for relocating the symbols, a flag indicating
400 whether or not this debugging information is from a "main symbol
401 table" rather than a shared library or dynamically linked file,
402 and file offset/size pairs for the DIE information and line number
412 dwarf_build_psymtabs (desc
, filename
, addr
, mainline
, dbfoff
, dbsize
,
413 lnoffset
, lnsize
, objfile
)
420 unsigned int lnoffset
;
422 struct objfile
*objfile
;
424 struct cleanup
*back_to
;
426 dbbase
= xmalloc (dbsize
);
428 if ((lseek (desc
, dbfoff
, 0) != dbfoff
) ||
429 (read (desc
, dbbase
, dbsize
) != dbsize
))
432 error ("can't read DWARF data from '%s'", filename
);
434 back_to
= make_cleanup (free
, dbbase
);
436 /* If we are reinitializing, or if we have never loaded syms yet, init.
437 Since we have no idea how many DIES we are looking at, we just guess
438 some arbitrary value. */
440 if (mainline
|| objfile
->global_psymbols
.size
== 0 || objfile
->static_psymbols
.size
== 0)
442 init_psymbol_list (objfile
, 1024);
445 /* From this point on, we don't need to pass mainline around, so zap
446 baseaddr to zero if we don't need relocation. */
457 /* Follow the compilation unit sibling chain, building a partial symbol
458 table entry for each one. Save enough information about each compilation
459 unit to locate the full DWARF information later. */
461 scan_compilation_units (filename
, dbbase
, dbbase
+ dbsize
,
462 dbfoff
, lnoffset
, objfile
);
464 do_cleanups (back_to
);
472 record_minimal_symbol -- add entry to gdb's minimal symbol table
476 static void record_minimal_symbol (char *name, CORE_ADDR address,
477 enum minimal_symbol_type ms_type,
478 struct objfile *objfile)
482 Given a pointer to the name of a symbol that should be added to the
483 minimal symbol table, and the address associated with that
484 symbol, records this information for later use in building the
485 minimal symbol table.
490 record_minimal_symbol (name
, address
, ms_type
, objfile
)
493 enum minimal_symbol_type ms_type
;
494 struct objfile
*objfile
;
496 name
= obsavestring (name
, strlen (name
), &objfile
-> symbol_obstack
);
497 prim_record_minimal_symbol (name
, address
, ms_type
);
504 dwarfwarn -- issue a DWARF related warning
508 Issue warnings about DWARF related things that aren't serious enough
509 to warrant aborting with an error, but should not be ignored either.
510 This includes things like detectable corruption in DIE's, missing
511 DIE's, unimplemented features, etc.
513 In general, running across tags or attributes that we don't recognize
514 is not considered to be a problem and we should not issue warnings
519 We mostly follow the example of the error() routine, but without
520 returning to command level. It is arguable about whether warnings
521 should be issued at all, and if so, where they should go (stdout or
524 We assume that curdie is valid and contains at least the basic
525 information for the DIE where the problem was noticed.
536 fmt
= va_arg (ap
, char *);
538 fprintf (stderr
, "DWARF warning (ref 0x%x): ", curdie
-> dieref
);
539 if (curdie
-> at_name
)
541 fprintf (stderr
, "'%s': ", curdie
-> at_name
);
543 vfprintf (stderr
, fmt
, ap
);
544 fprintf (stderr
, "\n");
553 read_lexical_block_scope -- process all dies in a lexical block
557 static void read_lexical_block_scope (struct dieinfo *dip,
558 char *thisdie, char *enddie)
562 Process all the DIES contained within a lexical block scope.
563 Start a new scope, process the dies, and then close the scope.
568 read_lexical_block_scope (dip
, thisdie
, enddie
, objfile
)
572 struct objfile
*objfile
;
574 register struct context_stack
*new;
576 (void) push_context (0, dip
-> at_low_pc
);
577 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
578 new = pop_context ();
579 if (local_symbols
!= NULL
)
581 finish_block (0, &local_symbols
, new -> old_blocks
, new -> start_addr
,
582 dip
-> at_high_pc
, objfile
);
584 local_symbols
= new -> locals
;
591 lookup_utype -- look up a user defined type from die reference
595 static type *lookup_utype (DIEREF dieref)
599 Given a DIE reference, lookup the user defined type associated with
600 that DIE, if it has been registered already. If not registered, then
601 return NULL. Alloc_utype() can be called to register an empty
602 type for this reference, which will be filled in later when the
603 actual referenced DIE is processed.
607 lookup_utype (dieref
)
610 struct type
*type
= NULL
;
613 utypeidx
= (dieref
- dbroff
) / 4;
614 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
616 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
620 type
= *(utypes
+ utypeidx
);
630 alloc_utype -- add a user defined type for die reference
634 static type *alloc_utype (DIEREF dieref, struct type *utypep)
638 Given a die reference DIEREF, and a possible pointer to a user
639 defined type UTYPEP, register that this reference has a user
640 defined type and either use the specified type in UTYPEP or
641 make a new empty type that will be filled in later.
643 We should only be called after calling lookup_utype() to verify that
644 there is not currently a type registered for DIEREF.
648 alloc_utype (dieref
, utypep
)
655 utypeidx
= (dieref
- dbroff
) / 4;
656 typep
= utypes
+ utypeidx
;
657 if ((utypeidx
< 0) || (utypeidx
>= numutypes
))
659 utypep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
660 dwarfwarn ("reference to DIE (0x%x) outside compilation unit", dieref
);
662 else if (*typep
!= NULL
)
665 SQUAWK (("internal error: dup user type allocation"));
671 utypep
= (struct type
*)
672 obstack_alloc (¤t_objfile
-> type_obstack
,
673 sizeof (struct type
));
674 (void) memset (utypep
, 0, sizeof (struct type
));
675 TYPE_OBJFILE (utypep
) = current_objfile
;
686 decode_die_type -- return a type for a specified die
690 static struct type *decode_die_type (struct dieinfo *dip)
694 Given a pointer to a die information structure DIP, decode the
695 type of the die and return a pointer to the decoded type. All
696 dies without specific types default to type int.
700 decode_die_type (dip
)
703 struct type
*type
= NULL
;
705 if (dip
-> at_fund_type
!= 0)
707 type
= decode_fund_type (dip
-> at_fund_type
);
709 else if (dip
-> at_mod_fund_type
!= NULL
)
711 type
= decode_mod_fund_type (dip
-> at_mod_fund_type
);
713 else if (dip
-> at_user_def_type
)
715 if ((type
= lookup_utype (dip
-> at_user_def_type
)) == NULL
)
717 type
= alloc_utype (dip
-> at_user_def_type
, NULL
);
720 else if (dip
-> at_mod_u_d_type
)
722 type
= decode_mod_u_d_type (dip
-> at_mod_u_d_type
);
726 type
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
735 struct_type -- compute and return the type for a struct or union
739 static struct type *struct_type (struct dieinfo *dip, char *thisdie,
740 char *enddie, struct objfile *objfile)
744 Given pointer to a die information structure for a die which
745 defines a union or structure (and MUST define one or the other),
746 and pointers to the raw die data that define the range of dies which
747 define the members, compute and return the user defined type for the
752 struct_type (dip
, thisdie
, enddie
, objfile
)
756 struct objfile
*objfile
;
760 struct nextfield
*next
;
763 struct nextfield
*list
= NULL
;
764 struct nextfield
*new;
771 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
773 /* No forward references created an empty type, so install one now */
774 type
= alloc_utype (dip
-> dieref
, NULL
);
776 INIT_CPLUS_SPECIFIC(type
);
777 switch (dip
-> dietag
)
779 case TAG_structure_type
:
780 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
784 TYPE_CODE (type
) = TYPE_CODE_UNION
;
788 /* Should never happen */
789 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
791 SQUAWK (("missing structure or union tag"));
794 /* Some compilers try to be helpful by inventing "fake" names for
795 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
796 Thanks, but no thanks... */
797 if (dip
-> at_name
!= NULL
798 && *dip
-> at_name
!= '~'
799 && *dip
-> at_name
!= '.')
801 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
,
802 tpart1
, " ", dip
-> at_name
);
804 if (dip
-> at_byte_size
!= 0)
806 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
808 thisdie
+= dip
-> dielength
;
809 while (thisdie
< enddie
)
811 basicdieinfo (&mbr
, thisdie
);
812 completedieinfo (&mbr
);
813 if (mbr
.dielength
<= sizeof (long))
817 else if (mbr
.at_sibling
!= 0)
819 nextdie
= dbbase
+ mbr
.at_sibling
- dbroff
;
823 nextdie
= thisdie
+ mbr
.dielength
;
828 /* Get space to record the next field's data. */
829 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
833 list
-> field
.name
= savestring (mbr
.at_name
, strlen (mbr
.at_name
));
834 list
-> field
.type
= decode_die_type (&mbr
);
835 list
-> field
.bitpos
= 8 * locval (mbr
.at_location
);
836 list
-> field
.bitsize
= 0;
840 process_dies (thisdie
, nextdie
, objfile
);
845 /* Now create the vector of fields, and record how big it is. We may
846 not even have any fields, if this DIE was generated due to a reference
847 to an anonymous structure or union. In this case, TYPE_FLAG_STUB is
848 set, which clues gdb in to the fact that it needs to search elsewhere
849 for the full structure definition. */
852 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
856 TYPE_NFIELDS (type
) = nfields
;
857 TYPE_FIELDS (type
) = (struct field
*)
858 obstack_alloc (¤t_objfile
-> type_obstack
,
859 sizeof (struct field
) * nfields
);
860 /* Copy the saved-up fields into the field vector. */
861 for (n
= nfields
; list
; list
= list
-> next
)
863 TYPE_FIELD (type
, --n
) = list
-> field
;
873 read_structure_scope -- process all dies within struct or union
877 static void read_structure_scope (struct dieinfo *dip,
878 char *thisdie, char *enddie, struct objfile *objfile)
882 Called when we find the DIE that starts a structure or union
883 scope (definition) to process all dies that define the members
884 of the structure or union. DIP is a pointer to the die info
885 struct for the DIE that names the structure or union.
889 Note that we need to call struct_type regardless of whether or not
890 the DIE has an at_name attribute, since it might be an anonymous
891 structure or union. This gets the type entered into our set of
894 However, if the structure is incomplete (an opaque struct/union)
895 then suppress creating a symbol table entry for it since gdb only
896 wants to find the one with the complete definition. Note that if
897 it is complete, we just call new_symbol, which does it's own
898 checking about whether the struct/union is anonymous or not (and
899 suppresses creating a symbol table entry itself).
904 read_structure_scope (dip
, thisdie
, enddie
, objfile
)
908 struct objfile
*objfile
;
913 type
= struct_type (dip
, thisdie
, enddie
, objfile
);
914 if (!(TYPE_FLAGS (type
) & TYPE_FLAG_STUB
))
916 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
918 SYMBOL_TYPE (sym
) = type
;
927 decode_array_element_type -- decode type of the array elements
931 static struct type *decode_array_element_type (char *scan, char *end)
935 As the last step in decoding the array subscript information for an
936 array DIE, we need to decode the type of the array elements. We are
937 passed a pointer to this last part of the subscript information and
938 must return the appropriate type. If the type attribute is not
939 recognized, just warn about the problem and return type int.
943 decode_array_element_type (scan
, end
)
950 unsigned short fundtype
;
952 (void) memcpy (&attribute
, scan
, sizeof (short));
953 scan
+= sizeof (short);
957 (void) memcpy (&fundtype
, scan
, sizeof (short));
958 typep
= decode_fund_type (fundtype
);
960 case AT_mod_fund_type
:
961 typep
= decode_mod_fund_type (scan
);
963 case AT_user_def_type
:
964 (void) memcpy (&dieref
, scan
, sizeof (DIEREF
));
965 if ((typep
= lookup_utype (dieref
)) == NULL
)
967 typep
= alloc_utype (dieref
, NULL
);
970 case AT_mod_u_d_type
:
971 typep
= decode_mod_u_d_type (scan
);
974 SQUAWK (("bad array element type attribute 0x%x", attribute
));
975 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
985 decode_subscr_data -- decode array subscript and element type data
989 static struct type *decode_subscr_data (char *scan, char *end)
993 The array subscripts and the data type of the elements of an
994 array are described by a list of data items, stored as a block
995 of contiguous bytes. There is a data item describing each array
996 dimension, and a final data item describing the element type.
997 The data items are ordered the same as their appearance in the
998 source (I.E. leftmost dimension first, next to leftmost second,
1001 We are passed a pointer to the start of the block of bytes
1002 containing the data items, and a pointer to the first byte past
1003 the data. This function decodes the data and returns a type.
1006 FIXME: This code only implements the forms currently used
1007 by the AT&T and GNU C compilers.
1009 The end pointer is supplied for error checking, maybe we should
1013 static struct type
*
1014 decode_subscr_data (scan
, end
)
1018 struct type
*typep
= NULL
;
1019 struct type
*nexttype
;
1029 typep
= decode_array_element_type (scan
, end
);
1032 (void) memcpy (&fundtype
, scan
, sizeof (short));
1033 scan
+= sizeof (short);
1034 if (fundtype
!= FT_integer
&& fundtype
!= FT_signed_integer
1035 && fundtype
!= FT_unsigned_integer
)
1037 SQUAWK (("array subscripts must be integral types, not type 0x%x",
1042 (void) memcpy (&lowbound
, scan
, sizeof (long));
1043 scan
+= sizeof (long);
1044 (void) memcpy (&highbound
, scan
, sizeof (long));
1045 scan
+= sizeof (long);
1046 nexttype
= decode_subscr_data (scan
, end
);
1047 if (nexttype
!= NULL
)
1049 typep
= (struct type
*)
1050 obstack_alloc (¤t_objfile
-> type_obstack
,
1051 sizeof (struct type
));
1052 (void) memset (typep
, 0, sizeof (struct type
));
1053 TYPE_OBJFILE (typep
) = current_objfile
;
1054 TYPE_CODE (typep
) = TYPE_CODE_ARRAY
;
1055 TYPE_LENGTH (typep
) = TYPE_LENGTH (nexttype
);
1056 TYPE_LENGTH (typep
) *= lowbound
+ highbound
+ 1;
1057 TYPE_TARGET_TYPE (typep
) = nexttype
;
1068 SQUAWK (("array subscript format 0x%x not handled yet", format
));
1071 SQUAWK (("unknown array subscript format %x", format
));
1081 dwarf_read_array_type -- read TAG_array_type DIE
1085 static void dwarf_read_array_type (struct dieinfo *dip)
1089 Extract all information from a TAG_array_type DIE and add to
1090 the user defined type vector.
1094 dwarf_read_array_type (dip
)
1095 struct dieinfo
*dip
;
1103 if (dip
-> at_ordering
!= ORD_row_major
)
1105 /* FIXME: Can gdb even handle column major arrays? */
1106 SQUAWK (("array not row major; not handled correctly"));
1108 if ((sub
= dip
-> at_subscr_data
) != NULL
)
1110 (void) memcpy (&temp
, sub
, sizeof (short));
1111 subend
= sub
+ sizeof (short) + temp
;
1112 sub
+= sizeof (short);
1113 type
= decode_subscr_data (sub
, subend
);
1116 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1118 utype
= alloc_utype (dip
-> dieref
, NULL
);
1120 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1121 TYPE_TARGET_TYPE (utype
) =
1122 lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1123 TYPE_LENGTH (utype
) = 1 * TYPE_LENGTH (TYPE_TARGET_TYPE (utype
));
1127 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1129 (void) alloc_utype (dip
-> dieref
, type
);
1133 TYPE_CODE (utype
) = TYPE_CODE_ARRAY
;
1134 TYPE_LENGTH (utype
) = TYPE_LENGTH (type
);
1135 TYPE_TARGET_TYPE (utype
) = TYPE_TARGET_TYPE (type
);
1145 read_tag_pointer_type -- read TAG_pointer_type DIE
1149 static void read_tag_pointer_type (struct dieinfo *dip)
1153 Extract all information from a TAG_pointer_type DIE and add to
1154 the user defined type vector.
1158 read_tag_pointer_type (dip
)
1159 struct dieinfo
*dip
;
1167 type
= decode_die_type (dip
);
1168 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1170 utype
= lookup_pointer_type (type
);
1171 (void) alloc_utype (dip
-> dieref
, utype
);
1175 TYPE_TARGET_TYPE (utype
) = type
;
1176 TYPE_POINTER_TYPE (type
) = utype
;
1178 /* We assume the machine has only one representation for pointers! */
1179 /* FIXME: This confuses host<->target data representations, and is a
1180 poor assumption besides. */
1182 TYPE_LENGTH (utype
) = sizeof (char *);
1183 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1191 read_subroutine_type -- process TAG_subroutine_type dies
1195 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1200 Handle DIES due to C code like:
1203 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1209 The parameter DIES are currently ignored. See if gdb has a way to
1210 include this info in it's type system, and decode them if so. Is
1211 this what the type structure's "arg_types" field is for? (FIXME)
1215 read_subroutine_type (dip
, thisdie
, enddie
)
1216 struct dieinfo
*dip
;
1220 struct type
*type
; /* Type that this function returns */
1221 struct type
*ftype
; /* Function that returns above type */
1223 /* Decode the type that this subroutine returns */
1225 type
= decode_die_type (dip
);
1227 /* Check to see if we already have a partially constructed user
1228 defined type for this DIE, from a forward reference. */
1230 if ((ftype
= lookup_utype (dip
-> dieref
)) == NULL
)
1232 /* This is the first reference to one of these types. Make
1233 a new one and place it in the user defined types. */
1234 ftype
= lookup_function_type (type
);
1235 (void) alloc_utype (dip
-> dieref
, ftype
);
1239 /* We have an existing partially constructed type, so bash it
1240 into the correct type. */
1241 TYPE_TARGET_TYPE (ftype
) = type
;
1242 TYPE_FUNCTION_TYPE (type
) = ftype
;
1243 TYPE_LENGTH (ftype
) = 1;
1244 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1252 read_enumeration -- process dies which define an enumeration
1256 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1257 char *enddie, struct objfile *objfile)
1261 Given a pointer to a die which begins an enumeration, process all
1262 the dies that define the members of the enumeration.
1266 Note that we need to call enum_type regardless of whether or not we
1267 have a symbol, since we might have an enum without a tag name (thus
1268 no symbol for the tagname).
1272 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1273 struct dieinfo
*dip
;
1276 struct objfile
*objfile
;
1281 type
= enum_type (dip
, objfile
);
1282 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1284 SYMBOL_TYPE (sym
) = type
;
1292 enum_type -- decode and return a type for an enumeration
1296 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1300 Given a pointer to a die information structure for the die which
1301 starts an enumeration, process all the dies that define the members
1302 of the enumeration and return a type pointer for the enumeration.
1304 At the same time, for each member of the enumeration, create a
1305 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1306 and give it the type of the enumeration itself.
1310 Note that the DWARF specification explicitly mandates that enum
1311 constants occur in reverse order from the source program order,
1312 for "consistency" and because this ordering is easier for many
1313 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1314 Entries). Because gdb wants to see the enum members in program
1315 source order, we have to ensure that the order gets reversed while
1316 we are processing them.
1319 static struct type
*
1320 enum_type (dip
, objfile
)
1321 struct dieinfo
*dip
;
1322 struct objfile
*objfile
;
1326 struct nextfield
*next
;
1329 struct nextfield
*list
= NULL
;
1330 struct nextfield
*new;
1339 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
1341 /* No forward references created an empty type, so install one now */
1342 type
= alloc_utype (dip
-> dieref
, NULL
);
1344 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1345 /* Some compilers try to be helpful by inventing "fake" names for
1346 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1347 Thanks, but no thanks... */
1348 if (dip
-> at_name
!= NULL
1349 && *dip
-> at_name
!= '~'
1350 && *dip
-> at_name
!= '.')
1352 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
, "enum",
1353 " ", dip
-> at_name
);
1355 if (dip
-> at_byte_size
!= 0)
1357 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1359 if ((scan
= dip
-> at_element_list
) != NULL
)
1361 if (dip
-> short_element_list
)
1363 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
1364 listend
= scan
+ stemp
+ sizeof (stemp
);
1365 scan
+= sizeof (stemp
);
1369 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
1370 listend
= scan
+ ltemp
+ sizeof (ltemp
);
1371 scan
+= sizeof (ltemp
);
1373 while (scan
< listend
)
1375 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1378 list
-> field
.type
= NULL
;
1379 list
-> field
.bitsize
= 0;
1380 (void) memcpy (&list
-> field
.bitpos
, scan
, sizeof (long));
1381 scan
+= sizeof (long);
1382 list
-> field
.name
= savestring (scan
, strlen (scan
));
1383 scan
+= strlen (scan
) + 1;
1385 /* Handcraft a new symbol for this enum member. */
1386 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1387 sizeof (struct symbol
));
1388 (void) memset (sym
, 0, sizeof (struct symbol
));
1389 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
, &objfile
->symbol_obstack
);
1390 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1391 SYMBOL_CLASS (sym
) = LOC_CONST
;
1392 SYMBOL_TYPE (sym
) = type
;
1393 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1394 add_symbol_to_list (sym
, list_in_scope
);
1396 /* Now create the vector of fields, and record how big it is. This is
1397 where we reverse the order, by pulling the members of the list in
1398 reverse order from how they were inserted. If we have no fields
1399 (this is apparently possible in C++) then skip building a field
1403 TYPE_NFIELDS (type
) = nfields
;
1404 TYPE_FIELDS (type
) = (struct field
*)
1405 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1406 /* Copy the saved-up fields into the field vector. */
1407 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1409 TYPE_FIELD (type
, n
++) = list
-> field
;
1420 read_func_scope -- process all dies within a function scope
1424 Process all dies within a given function scope. We are passed
1425 a die information structure pointer DIP for the die which
1426 starts the function scope, and pointers into the raw die data
1427 that define the dies within the function scope.
1429 For now, we ignore lexical block scopes within the function.
1430 The problem is that AT&T cc does not define a DWARF lexical
1431 block scope for the function itself, while gcc defines a
1432 lexical block scope for the function. We need to think about
1433 how to handle this difference, or if it is even a problem.
1438 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1439 struct dieinfo
*dip
;
1442 struct objfile
*objfile
;
1444 register struct context_stack
*new;
1446 if (entry_point
>= dip
-> at_low_pc
&& entry_point
< dip
-> at_high_pc
)
1448 entry_scope_lowpc
= dip
-> at_low_pc
;
1449 entry_scope_highpc
= dip
-> at_high_pc
;
1451 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1453 main_scope_lowpc
= dip
-> at_low_pc
;
1454 main_scope_highpc
= dip
-> at_high_pc
;
1456 new = push_context (0, dip
-> at_low_pc
);
1457 new -> name
= new_symbol (dip
, objfile
);
1458 list_in_scope
= &local_symbols
;
1459 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1460 new = pop_context ();
1461 /* Make a block for the local symbols within. */
1462 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1463 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1464 list_in_scope
= &file_symbols
;
1471 read_file_scope -- process all dies within a file scope
1475 Process all dies within a given file scope. We are passed a
1476 pointer to the die information structure for the die which
1477 starts the file scope, and pointers into the raw die data which
1478 mark the range of dies within the file scope.
1480 When the partial symbol table is built, the file offset for the line
1481 number table for each compilation unit is saved in the partial symbol
1482 table entry for that compilation unit. As the symbols for each
1483 compilation unit are read, the line number table is read into memory
1484 and the variable lnbase is set to point to it. Thus all we have to
1485 do is use lnbase to access the line number table for the current
1490 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1491 struct dieinfo
*dip
;
1494 struct objfile
*objfile
;
1496 struct cleanup
*back_to
;
1497 struct symtab
*symtab
;
1499 if (entry_point
>= dip
-> at_low_pc
&& entry_point
< dip
-> at_high_pc
)
1501 startup_file_start
= dip
-> at_low_pc
;
1502 startup_file_end
= dip
-> at_high_pc
;
1504 if (dip
-> at_producer
!= NULL
)
1506 processing_gcc_compilation
=
1507 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1509 numutypes
= (enddie
- thisdie
) / 4;
1510 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1511 back_to
= make_cleanup (free
, utypes
);
1512 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1513 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1514 decode_line_numbers (lnbase
);
1515 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1516 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1517 /* FIXME: The following may need to be expanded for other languages */
1518 switch (dip
-> at_language
)
1522 symtab
-> language
= language_c
;
1524 case LANG_C_PLUS_PLUS
:
1525 symtab
-> language
= language_cplus
;
1530 do_cleanups (back_to
);
1539 process_dies -- process a range of DWARF Information Entries
1543 static void process_dies (char *thisdie, char *enddie,
1544 struct objfile *objfile)
1548 Process all DIE's in a specified range. May be (and almost
1549 certainly will be) called recursively.
1553 process_dies (thisdie
, enddie
, objfile
)
1556 struct objfile
*objfile
;
1561 while (thisdie
< enddie
)
1563 basicdieinfo (&di
, thisdie
);
1564 if (di
.dielength
< sizeof (long))
1568 else if (di
.dietag
== TAG_padding
)
1570 nextdie
= thisdie
+ di
.dielength
;
1574 completedieinfo (&di
);
1575 if (di
.at_sibling
!= 0)
1577 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1581 nextdie
= thisdie
+ di
.dielength
;
1585 case TAG_compile_unit
:
1586 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1588 case TAG_global_subroutine
:
1589 case TAG_subroutine
:
1590 if (di
.has_at_low_pc
)
1592 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1595 case TAG_lexical_block
:
1596 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1598 case TAG_structure_type
:
1599 case TAG_union_type
:
1600 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1602 case TAG_enumeration_type
:
1603 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1605 case TAG_subroutine_type
:
1606 read_subroutine_type (&di
, thisdie
, nextdie
);
1608 case TAG_array_type
:
1609 dwarf_read_array_type (&di
);
1611 case TAG_pointer_type
:
1612 read_tag_pointer_type (&di
);
1615 (void) new_symbol (&di
, objfile
);
1627 decode_line_numbers -- decode a line number table fragment
1631 static void decode_line_numbers (char *tblscan, char *tblend,
1632 long length, long base, long line, long pc)
1636 Translate the DWARF line number information to gdb form.
1638 The ".line" section contains one or more line number tables, one for
1639 each ".line" section from the objects that were linked.
1641 The AT_stmt_list attribute for each TAG_source_file entry in the
1642 ".debug" section contains the offset into the ".line" section for the
1643 start of the table for that file.
1645 The table itself has the following structure:
1647 <table length><base address><source statement entry>
1648 4 bytes 4 bytes 10 bytes
1650 The table length is the total size of the table, including the 4 bytes
1651 for the length information.
1653 The base address is the address of the first instruction generated
1654 for the source file.
1656 Each source statement entry has the following structure:
1658 <line number><statement position><address delta>
1659 4 bytes 2 bytes 4 bytes
1661 The line number is relative to the start of the file, starting with
1664 The statement position either -1 (0xFFFF) or the number of characters
1665 from the beginning of the line to the beginning of the statement.
1667 The address delta is the difference between the base address and
1668 the address of the first instruction for the statement.
1670 Note that we must copy the bytes from the packed table to our local
1671 variables before attempting to use them, to avoid alignment problems
1672 on some machines, particularly RISC processors.
1676 Does gdb expect the line numbers to be sorted? They are now by
1677 chance/luck, but are not required to be. (FIXME)
1679 The line with number 0 is unused, gdb apparently can discover the
1680 span of the last line some other way. How? (FIXME)
1684 decode_line_numbers (linetable
)
1694 if (linetable
!= NULL
)
1696 tblscan
= tblend
= linetable
;
1697 (void) memcpy (&length
, tblscan
, sizeof (long));
1698 tblscan
+= sizeof (long);
1700 (void) memcpy (&base
, tblscan
, sizeof (long));
1702 tblscan
+= sizeof (long);
1703 while (tblscan
< tblend
)
1705 (void) memcpy (&line
, tblscan
, sizeof (long));
1706 tblscan
+= sizeof (long) + sizeof (short);
1707 (void) memcpy (&pc
, tblscan
, sizeof (long));
1708 tblscan
+= sizeof (long);
1712 record_line (current_subfile
, line
, pc
);
1722 locval -- compute the value of a location attribute
1726 static int locval (char *loc)
1730 Given pointer to a string of bytes that define a location, compute
1731 the location and return the value.
1733 When computing values involving the current value of the frame pointer,
1734 the value zero is used, which results in a value relative to the frame
1735 pointer, rather than the absolute value. This is what GDB wants
1738 When the result is a register number, the global isreg flag is set,
1739 otherwise it is cleared. This is a kludge until we figure out a better
1740 way to handle the problem. Gdb's design does not mesh well with the
1741 DWARF notion of a location computing interpreter, which is a shame
1742 because the flexibility goes unused.
1746 Note that stack[0] is unused except as a default error return.
1747 Note that stack overflow is not yet handled.
1754 unsigned short nbytes
;
1760 (void) memcpy (&nbytes
, loc
, sizeof (short));
1761 end
= loc
+ sizeof (short) + nbytes
;
1766 for (loc
+= sizeof (short); loc
< end
; loc
+= sizeof (long))
1774 /* push register (number) */
1775 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1779 /* push value of register (number) */
1780 /* Actually, we compute the value as if register has 0 */
1782 (void) memcpy (®no
, loc
, sizeof (long));
1785 stack
[++stacki
] = 0;
1789 stack
[++stacki
] = 0;
1790 SQUAWK (("BASEREG %d not handled!", regno
));
1794 /* push address (relocated address) */
1795 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1798 /* push constant (number) */
1799 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1802 /* pop, deref and push 2 bytes (as a long) */
1803 SQUAWK (("OP_DEREF2 address %#x not handled", stack
[stacki
]));
1805 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1806 SQUAWK (("OP_DEREF4 address %#x not handled", stack
[stacki
]));
1808 case OP_ADD
: /* pop top 2 items, add, push result */
1809 stack
[stacki
- 1] += stack
[stacki
];
1814 return (stack
[stacki
]);
1821 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1825 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1829 When expanding a partial symbol table entry to a full symbol table
1830 entry, this is the function that gets called to read in the symbols
1831 for the compilation unit.
1833 Returns a pointer to the newly constructed symtab (which is now
1834 the new first one on the objfile's symtab list).
1837 static struct symtab
*
1838 read_ofile_symtab (pst
)
1839 struct partial_symtab
*pst
;
1841 struct cleanup
*back_to
;
1846 abfd
= pst
-> objfile
-> obfd
;
1847 current_objfile
= pst
-> objfile
;
1849 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1850 unit, seek to the location in the file, and read in all the DIE's. */
1853 dbbase
= xmalloc (DBLENGTH(pst
));
1854 dbroff
= DBROFF(pst
);
1855 foffset
= DBFOFF(pst
) + dbroff
;
1856 baseaddr
= pst
-> addr
;
1857 if (bfd_seek (abfd
, foffset
, 0) ||
1858 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1861 error ("can't read DWARF data");
1863 back_to
= make_cleanup (free
, dbbase
);
1865 /* If there is a line number table associated with this compilation unit
1866 then read the first long word from the line number table fragment, which
1867 contains the size of the fragment in bytes (including the long word
1868 itself). Allocate a buffer for the fragment and read it in for future
1874 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1875 (bfd_read (&lnsize
, sizeof(long), 1, abfd
) != sizeof(long)))
1877 error ("can't read DWARF line number table size");
1879 lnbase
= xmalloc (lnsize
);
1880 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1881 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1884 error ("can't read DWARF line numbers");
1886 make_cleanup (free
, lnbase
);
1889 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1890 do_cleanups (back_to
);
1891 current_objfile
= NULL
;
1892 return (pst
-> objfile
-> symtabs
);
1899 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1903 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1907 Called once for each partial symbol table entry that needs to be
1908 expanded into a full symbol table entry.
1913 psymtab_to_symtab_1 (pst
)
1914 struct partial_symtab
*pst
;
1922 warning ("Psymtab for %s already read in. Shouldn't happen.",
1927 /* Read in all partial symtabs on which this one is dependent */
1928 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
1930 if (!pst
-> dependencies
[i
] -> readin
)
1932 /* Inform about additional files that need to be read in. */
1935 fputs_filtered (" ", stdout
);
1937 fputs_filtered ("and ", stdout
);
1939 printf_filtered ("%s...",
1940 pst
-> dependencies
[i
] -> filename
);
1942 fflush (stdout
); /* Flush output */
1944 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
1947 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
1949 pst
-> symtab
= read_ofile_symtab (pst
);
1952 printf_filtered ("%d DIE's, sorting...", diecount
);
1956 sort_symtab_syms (pst
-> symtab
);
1967 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
1971 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
1975 This is the DWARF support entry point for building a full symbol
1976 table entry from a partial symbol table entry. We are passed a
1977 pointer to the partial symbol table entry that needs to be expanded.
1982 dwarf_psymtab_to_symtab (pst
)
1983 struct partial_symtab
*pst
;
1990 warning ("Psymtab for %s already read in. Shouldn't happen.",
1995 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
1997 /* Print the message now, before starting serious work, to avoid
1998 disconcerting pauses. */
2001 printf_filtered ("Reading in symbols for %s...",
2006 psymtab_to_symtab_1 (pst
);
2008 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2009 we need to do an equivalent or is this something peculiar to
2011 Match with global symbols. This only needs to be done once,
2012 after all of the symtabs and dependencies have been read in.
2014 scan_file_globals (pst
-> objfile
);
2017 /* Finish up the verbose info message. */
2020 printf_filtered ("done.\n");
2032 init_psymbol_list -- initialize storage for partial symbols
2036 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2040 Initializes storage for all of the partial symbols that will be
2041 created by dwarf_build_psymtabs and subsidiaries.
2045 init_psymbol_list (objfile
, total_symbols
)
2046 struct objfile
*objfile
;
2049 /* Free any previously allocated psymbol lists. */
2051 if (objfile
-> global_psymbols
.list
)
2053 (*objfile
-> free
) (objfile
-> global_psymbols
.list
);
2055 if (objfile
-> static_psymbols
.list
)
2057 (*objfile
-> free
) (objfile
-> static_psymbols
.list
);
2060 /* Current best guess is that there are approximately a twentieth
2061 of the total symbols (in a debugging file) are global or static
2064 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2065 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2066 objfile
-> global_psymbols
.next
=
2067 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2068 (*objfile
-> xmalloc
) (objfile
-> global_psymbols
.size
2069 * sizeof (struct partial_symbol
));
2070 objfile
-> static_psymbols
.next
=
2071 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2072 (*objfile
-> xmalloc
) (objfile
-> static_psymbols
.size
2073 * sizeof (struct partial_symbol
));
2080 add_enum_psymbol -- add enumeration members to partial symbol table
2084 Given pointer to a DIE that is known to be for an enumeration,
2085 extract the symbolic names of the enumeration members and add
2086 partial symbols for them.
2090 add_enum_psymbol (dip
, objfile
)
2091 struct dieinfo
*dip
;
2092 struct objfile
*objfile
;
2099 if ((scan
= dip
-> at_element_list
) != NULL
)
2101 if (dip
-> short_element_list
)
2103 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
2104 listend
= scan
+ stemp
+ sizeof (stemp
);
2105 scan
+= sizeof (stemp
);
2109 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
2110 listend
= scan
+ ltemp
+ sizeof (ltemp
);
2111 scan
+= sizeof (ltemp
);
2113 while (scan
< listend
)
2115 scan
+= sizeof (long);
2116 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2117 objfile
-> static_psymbols
, 0);
2118 scan
+= strlen (scan
) + 1;
2127 add_partial_symbol -- add symbol to partial symbol table
2131 Given a DIE, if it is one of the types that we want to
2132 add to a partial symbol table, finish filling in the die info
2133 and then add a partial symbol table entry for it.
2138 add_partial_symbol (dip
, objfile
)
2139 struct dieinfo
*dip
;
2140 struct objfile
*objfile
;
2142 switch (dip
-> dietag
)
2144 case TAG_global_subroutine
:
2145 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2147 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2148 VAR_NAMESPACE
, LOC_BLOCK
,
2149 objfile
-> global_psymbols
,
2152 case TAG_global_variable
:
2153 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2155 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2156 VAR_NAMESPACE
, LOC_STATIC
,
2157 objfile
-> global_psymbols
,
2160 case TAG_subroutine
:
2161 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2162 VAR_NAMESPACE
, LOC_BLOCK
,
2163 objfile
-> static_psymbols
,
2166 case TAG_local_variable
:
2167 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2168 VAR_NAMESPACE
, LOC_STATIC
,
2169 objfile
-> static_psymbols
,
2173 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2174 VAR_NAMESPACE
, LOC_TYPEDEF
,
2175 objfile
-> static_psymbols
,
2178 case TAG_structure_type
:
2179 case TAG_union_type
:
2180 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2181 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2182 objfile
-> static_psymbols
,
2185 case TAG_enumeration_type
:
2188 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2189 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2190 objfile
-> static_psymbols
,
2193 add_enum_psymbol (dip
, objfile
);
2202 scan_partial_symbols -- scan DIE's within a single compilation unit
2206 Process the DIE's within a single compilation unit, looking for
2207 interesting DIE's that contribute to the partial symbol table entry
2208 for this compilation unit. Since we cannot follow any sibling
2209 chains without reading the complete DIE info for every DIE,
2210 it is probably faster to just sequentially check each one to
2211 see if it is one of the types we are interested in, and if so,
2212 then extract all the attributes info and generate a partial
2217 Don't attempt to add anonymous structures or unions since they have
2218 no name. Anonymous enumerations however are processed, because we
2219 want to extract their member names (the check for a tag name is
2222 Also, for variables and subroutines, check that this is the place
2223 where the actual definition occurs, rather than just a reference
2228 scan_partial_symbols (thisdie
, enddie
, objfile
)
2231 struct objfile
*objfile
;
2236 while (thisdie
< enddie
)
2238 basicdieinfo (&di
, thisdie
);
2239 if (di
.dielength
< sizeof (long))
2245 nextdie
= thisdie
+ di
.dielength
;
2246 /* To avoid getting complete die information for every die, we
2247 only do it (below) for the cases we are interested in. */
2250 case TAG_global_subroutine
:
2251 case TAG_subroutine
:
2252 case TAG_global_variable
:
2253 case TAG_local_variable
:
2254 completedieinfo (&di
);
2255 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2257 add_partial_symbol (&di
, objfile
);
2261 case TAG_structure_type
:
2262 case TAG_union_type
:
2263 completedieinfo (&di
);
2266 add_partial_symbol (&di
, objfile
);
2269 case TAG_enumeration_type
:
2270 completedieinfo (&di
);
2271 add_partial_symbol (&di
, objfile
);
2283 scan_compilation_units -- build a psymtab entry for each compilation
2287 This is the top level dwarf parsing routine for building partial
2290 It scans from the beginning of the DWARF table looking for the first
2291 TAG_compile_unit DIE, and then follows the sibling chain to locate
2292 each additional TAG_compile_unit DIE.
2294 For each TAG_compile_unit DIE it creates a partial symtab structure,
2295 calls a subordinate routine to collect all the compilation unit's
2296 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2297 new partial symtab structure into the partial symbol table. It also
2298 records the appropriate information in the partial symbol table entry
2299 to allow the chunk of DIE's and line number table for this compilation
2300 unit to be located and re-read later, to generate a complete symbol
2301 table entry for the compilation unit.
2303 Thus it effectively partitions up a chunk of DIE's for multiple
2304 compilation units into smaller DIE chunks and line number tables,
2305 and associates them with a partial symbol table entry.
2309 If any compilation unit has no line number table associated with
2310 it for some reason (a missing at_stmt_list attribute, rather than
2311 just one with a value of zero, which is valid) then we ensure that
2312 the recorded file offset is zero so that the routine which later
2313 reads line number table fragments knows that there is no fragment
2323 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2327 unsigned int dbfoff
;
2328 unsigned int lnoffset
;
2329 struct objfile
*objfile
;
2333 struct partial_symtab
*pst
;
2338 while (thisdie
< enddie
)
2340 basicdieinfo (&di
, thisdie
);
2341 if (di
.dielength
< sizeof (long))
2345 else if (di
.dietag
!= TAG_compile_unit
)
2347 nextdie
= thisdie
+ di
.dielength
;
2351 completedieinfo (&di
);
2352 if (di
.at_sibling
!= 0)
2354 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2358 nextdie
= thisdie
+ di
.dielength
;
2360 curoff
= thisdie
- dbbase
;
2361 culength
= nextdie
- thisdie
;
2362 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2364 /* First allocate a new partial symbol table structure */
2366 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2368 objfile
-> global_psymbols
.next
,
2369 objfile
-> static_psymbols
.next
);
2371 pst
-> texthigh
= di
.at_high_pc
;
2372 pst
-> read_symtab_private
= (char *)
2373 obstack_alloc (&objfile
-> psymbol_obstack
,
2374 sizeof (struct dwfinfo
));
2375 DBFOFF (pst
) = dbfoff
;
2376 DBROFF (pst
) = curoff
;
2377 DBLENGTH (pst
) = culength
;
2378 LNFOFF (pst
) = curlnoffset
;
2379 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2381 /* Now look for partial symbols */
2383 scan_partial_symbols (thisdie
+ di
.dielength
, nextdie
, objfile
);
2385 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2386 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2387 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2388 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2389 sort_pst_symbols (pst
);
2390 /* If there is already a psymtab or symtab for a file of this name,
2391 remove it. (If there is a symtab, more drastic things also
2392 happen.) This happens in VxWorks. */
2393 free_named_symtabs (pst
-> filename
);
2403 new_symbol -- make a symbol table entry for a new symbol
2407 static struct symbol *new_symbol (struct dieinfo *dip,
2408 struct objfile *objfile)
2412 Given a pointer to a DWARF information entry, figure out if we need
2413 to make a symbol table entry for it, and if so, create a new entry
2414 and return a pointer to it.
2417 static struct symbol
*
2418 new_symbol (dip
, objfile
)
2419 struct dieinfo
*dip
;
2420 struct objfile
*objfile
;
2422 struct symbol
*sym
= NULL
;
2424 if (dip
-> at_name
!= NULL
)
2426 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2427 sizeof (struct symbol
));
2428 (void) memset (sym
, 0, sizeof (struct symbol
));
2429 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2430 /* default assumptions */
2431 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2432 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2433 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2434 switch (dip
-> dietag
)
2437 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2438 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2440 case TAG_global_subroutine
:
2441 case TAG_subroutine
:
2442 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2443 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2444 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2445 if (dip
-> dietag
== TAG_global_subroutine
)
2447 add_symbol_to_list (sym
, &global_symbols
);
2451 add_symbol_to_list (sym
, list_in_scope
);
2454 case TAG_global_variable
:
2455 if (dip
-> at_location
!= NULL
)
2457 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2458 add_symbol_to_list (sym
, &global_symbols
);
2459 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2460 SYMBOL_VALUE (sym
) += baseaddr
;
2463 case TAG_local_variable
:
2464 if (dip
-> at_location
!= NULL
)
2466 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2467 add_symbol_to_list (sym
, list_in_scope
);
2470 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2474 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2478 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2479 SYMBOL_VALUE (sym
) += baseaddr
;
2483 case TAG_formal_parameter
:
2484 if (dip
-> at_location
!= NULL
)
2486 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2488 add_symbol_to_list (sym
, list_in_scope
);
2491 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2495 SYMBOL_CLASS (sym
) = LOC_ARG
;
2498 case TAG_unspecified_parameters
:
2499 /* From varargs functions; gdb doesn't seem to have any interest in
2500 this information, so just ignore it for now. (FIXME?) */
2502 case TAG_structure_type
:
2503 case TAG_union_type
:
2504 case TAG_enumeration_type
:
2505 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2506 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2507 add_symbol_to_list (sym
, list_in_scope
);
2510 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2511 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2512 add_symbol_to_list (sym
, list_in_scope
);
2515 /* Not a tag we recognize. Hopefully we aren't processing trash
2516 data, but since we must specifically ignore things we don't
2517 recognize, there is nothing else we should do at this point. */
2528 decode_mod_fund_type -- decode a modified fundamental type
2532 static struct type *decode_mod_fund_type (char *typedata)
2536 Decode a block of data containing a modified fundamental
2537 type specification. TYPEDATA is a pointer to the block,
2538 which consists of a two byte length, containing the size
2539 of the rest of the block. At the end of the block is a
2540 two byte value that gives the fundamental type. Everything
2541 in between are type modifiers.
2543 We simply compute the number of modifiers and call the general
2544 function decode_modified_type to do the actual work.
2547 static struct type
*
2548 decode_mod_fund_type (typedata
)
2551 struct type
*typep
= NULL
;
2552 unsigned short modcount
;
2553 unsigned char *modifiers
;
2555 /* Get the total size of the block, exclusive of the size itself */
2556 (void) memcpy (&modcount
, typedata
, sizeof (short));
2557 /* Deduct the size of the fundamental type bytes at the end of the block. */
2558 modcount
-= sizeof (short);
2559 /* Skip over the two size bytes at the beginning of the block. */
2560 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2561 /* Now do the actual decoding */
2562 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_fund_type
);
2570 decode_mod_u_d_type -- decode a modified user defined type
2574 static struct type *decode_mod_u_d_type (char *typedata)
2578 Decode a block of data containing a modified user defined
2579 type specification. TYPEDATA is a pointer to the block,
2580 which consists of a two byte length, containing the size
2581 of the rest of the block. At the end of the block is a
2582 four byte value that gives a reference to a user defined type.
2583 Everything in between are type modifiers.
2585 We simply compute the number of modifiers and call the general
2586 function decode_modified_type to do the actual work.
2589 static struct type
*
2590 decode_mod_u_d_type (typedata
)
2593 struct type
*typep
= NULL
;
2594 unsigned short modcount
;
2595 unsigned char *modifiers
;
2597 /* Get the total size of the block, exclusive of the size itself */
2598 (void) memcpy (&modcount
, typedata
, sizeof (short));
2599 /* Deduct the size of the reference type bytes at the end of the block. */
2600 modcount
-= sizeof (long);
2601 /* Skip over the two size bytes at the beginning of the block. */
2602 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2603 /* Now do the actual decoding */
2604 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_u_d_type
);
2612 decode_modified_type -- decode modified user or fundamental type
2616 static struct type *decode_modified_type (unsigned char *modifiers,
2617 unsigned short modcount, int mtype)
2621 Decode a modified type, either a modified fundamental type or
2622 a modified user defined type. MODIFIERS is a pointer to the
2623 block of bytes that define MODCOUNT modifiers. Immediately
2624 following the last modifier is a short containing the fundamental
2625 type or a long containing the reference to the user defined
2626 type. Which one is determined by MTYPE, which is either
2627 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2628 type we are generating.
2630 We call ourself recursively to generate each modified type,`
2631 until MODCOUNT reaches zero, at which point we have consumed
2632 all the modifiers and generate either the fundamental type or
2633 user defined type. When the recursion unwinds, each modifier
2634 is applied in turn to generate the full modified type.
2638 If we find a modifier that we don't recognize, and it is not one
2639 of those reserved for application specific use, then we issue a
2640 warning and simply ignore the modifier.
2644 We currently ignore MOD_const and MOD_volatile. (FIXME)
2648 static struct type
*
2649 decode_modified_type (modifiers
, modcount
, mtype
)
2650 unsigned char *modifiers
;
2651 unsigned int modcount
;
2654 struct type
*typep
= NULL
;
2655 unsigned short fundtype
;
2657 unsigned char modifier
;
2663 case AT_mod_fund_type
:
2664 (void) memcpy (&fundtype
, modifiers
, sizeof (short));
2665 typep
= decode_fund_type (fundtype
);
2667 case AT_mod_u_d_type
:
2668 (void) memcpy (&dieref
, modifiers
, sizeof (DIEREF
));
2669 if ((typep
= lookup_utype (dieref
)) == NULL
)
2671 typep
= alloc_utype (dieref
, NULL
);
2675 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2676 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2682 modifier
= *modifiers
++;
2683 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2686 case MOD_pointer_to
:
2687 typep
= lookup_pointer_type (typep
);
2689 case MOD_reference_to
:
2690 typep
= lookup_reference_type (typep
);
2693 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2696 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2699 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2701 SQUAWK (("unknown type modifier %u", modifier
));
2713 decode_fund_type -- translate basic DWARF type to gdb base type
2717 Given an integer that is one of the fundamental DWARF types,
2718 translate it to one of the basic internal gdb types and return
2719 a pointer to the appropriate gdb type (a "struct type *").
2723 If we encounter a fundamental type that we are unprepared to
2724 deal with, and it is not in the range of those types defined
2725 as application specific types, then we issue a warning and
2726 treat the type as an "int".
2729 static struct type
*
2730 decode_fund_type (fundtype
)
2731 unsigned int fundtype
;
2733 struct type
*typep
= NULL
;
2739 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2742 case FT_boolean
: /* Was FT_set in AT&T version */
2743 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2746 case FT_pointer
: /* (void *) */
2747 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2748 typep
= lookup_pointer_type (typep
);
2752 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2755 case FT_signed_char
:
2756 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2759 case FT_unsigned_char
:
2760 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2764 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2767 case FT_signed_short
:
2768 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2771 case FT_unsigned_short
:
2772 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2776 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2779 case FT_signed_integer
:
2780 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2783 case FT_unsigned_integer
:
2784 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2788 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2791 case FT_signed_long
:
2792 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2795 case FT_unsigned_long
:
2796 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2800 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2803 case FT_signed_long_long
:
2804 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2807 case FT_unsigned_long_long
:
2808 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2812 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2815 case FT_dbl_prec_float
:
2816 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2819 case FT_ext_prec_float
:
2820 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2824 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2827 case FT_dbl_prec_complex
:
2828 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2831 case FT_ext_prec_complex
:
2832 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2837 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2839 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2840 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2850 create_name -- allocate a fresh copy of a string on an obstack
2854 Given a pointer to a string and a pointer to an obstack, allocates
2855 a fresh copy of the string on the specified obstack.
2860 create_name (name
, obstackp
)
2862 struct obstack
*obstackp
;
2867 length
= strlen (name
) + 1;
2868 newname
= (char *) obstack_alloc (obstackp
, length
);
2869 (void) strcpy (newname
, name
);
2877 basicdieinfo -- extract the minimal die info from raw die data
2881 void basicdieinfo (char *diep, struct dieinfo *dip)
2885 Given a pointer to raw DIE data, and a pointer to an instance of a
2886 die info structure, this function extracts the basic information
2887 from the DIE data required to continue processing this DIE, along
2888 with some bookkeeping information about the DIE.
2890 The information we absolutely must have includes the DIE tag,
2891 and the DIE length. If we need the sibling reference, then we
2892 will have to call completedieinfo() to process all the remaining
2895 Note that since there is no guarantee that the data is properly
2896 aligned in memory for the type of access required (indirection
2897 through anything other than a char pointer), we use memcpy to
2898 shuffle data items larger than a char. Possibly inefficient, but
2901 We also take care of some other basic things at this point, such
2902 as ensuring that the instance of the die info structure starts
2903 out completely zero'd and that curdie is initialized for use
2904 in error reporting if we have a problem with the current die.
2908 All DIE's must have at least a valid length, thus the minimum
2909 DIE size is sizeof (long). In order to have a valid tag, the
2910 DIE size must be at least sizeof (short) larger, otherwise they
2911 are forced to be TAG_padding DIES.
2913 Padding DIES must be at least sizeof(long) in length, implying that
2914 if a padding DIE is used for alignment and the amount needed is less
2915 than sizeof(long) then the padding DIE has to be big enough to align
2916 to the next alignment boundry.
2920 basicdieinfo (dip
, diep
)
2921 struct dieinfo
*dip
;
2925 (void) memset (dip
, 0, sizeof (struct dieinfo
));
2927 dip
-> dieref
= dbroff
+ (diep
- dbbase
);
2928 (void) memcpy (&dip
-> dielength
, diep
, sizeof (long));
2929 if (dip
-> dielength
< sizeof (long))
2931 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> dielength
);
2933 else if (dip
-> dielength
< (sizeof (long) + sizeof (short)))
2935 dip
-> dietag
= TAG_padding
;
2939 (void) memcpy (&dip
-> dietag
, diep
+ sizeof (long), sizeof (short));
2947 completedieinfo -- finish reading the information for a given DIE
2951 void completedieinfo (struct dieinfo *dip)
2955 Given a pointer to an already partially initialized die info structure,
2956 scan the raw DIE data and finish filling in the die info structure
2957 from the various attributes found.
2959 Note that since there is no guarantee that the data is properly
2960 aligned in memory for the type of access required (indirection
2961 through anything other than a char pointer), we use memcpy to
2962 shuffle data items larger than a char. Possibly inefficient, but
2967 Each time we are called, we increment the diecount variable, which
2968 keeps an approximate count of the number of dies processed for
2969 each compilation unit. This information is presented to the user
2970 if the info_verbose flag is set.
2975 completedieinfo (dip
)
2976 struct dieinfo
*dip
;
2978 char *diep
; /* Current pointer into raw DIE data */
2979 char *end
; /* Terminate DIE scan here */
2980 unsigned short attr
; /* Current attribute being scanned */
2981 unsigned short form
; /* Form of the attribute */
2982 short block2sz
; /* Size of a block2 attribute field */
2983 long block4sz
; /* Size of a block4 attribute field */
2987 end
= diep
+ dip
-> dielength
;
2988 diep
+= sizeof (long) + sizeof (short);
2991 (void) memcpy (&attr
, diep
, sizeof (short));
2992 diep
+= sizeof (short);
2996 (void) memcpy (&dip
-> at_fund_type
, diep
, sizeof (short));
2999 (void) memcpy (&dip
-> at_ordering
, diep
, sizeof (short));
3002 (void) memcpy (&dip
-> at_bit_offset
, diep
, sizeof (short));
3005 (void) memcpy (&dip
-> at_visibility
, diep
, sizeof (short));
3008 (void) memcpy (&dip
-> at_sibling
, diep
, sizeof (long));
3011 (void) memcpy (&dip
-> at_stmt_list
, diep
, sizeof (long));
3012 dip
-> has_at_stmt_list
= 1;
3015 (void) memcpy (&dip
-> at_low_pc
, diep
, sizeof (long));
3016 dip
-> at_low_pc
+= baseaddr
;
3017 dip
-> has_at_low_pc
= 1;
3020 (void) memcpy (&dip
-> at_high_pc
, diep
, sizeof (long));
3021 dip
-> at_high_pc
+= baseaddr
;
3024 (void) memcpy (&dip
-> at_language
, diep
, sizeof (long));
3026 case AT_user_def_type
:
3027 (void) memcpy (&dip
-> at_user_def_type
, diep
, sizeof (long));
3030 (void) memcpy (&dip
-> at_byte_size
, diep
, sizeof (long));
3033 (void) memcpy (&dip
-> at_bit_size
, diep
, sizeof (long));
3036 (void) memcpy (&dip
-> at_member
, diep
, sizeof (long));
3039 (void) memcpy (&dip
-> at_discr
, diep
, sizeof (long));
3042 (void) memcpy (&dip
-> at_import
, diep
, sizeof (long));
3045 dip
-> at_location
= diep
;
3047 case AT_mod_fund_type
:
3048 dip
-> at_mod_fund_type
= diep
;
3050 case AT_subscr_data
:
3051 dip
-> at_subscr_data
= diep
;
3053 case AT_mod_u_d_type
:
3054 dip
-> at_mod_u_d_type
= diep
;
3056 case AT_element_list
:
3057 dip
-> at_element_list
= diep
;
3058 dip
-> short_element_list
= 0;
3060 case AT_short_element_list
:
3061 dip
-> at_element_list
= diep
;
3062 dip
-> short_element_list
= 1;
3064 case AT_discr_value
:
3065 dip
-> at_discr_value
= diep
;
3067 case AT_string_length
:
3068 dip
-> at_string_length
= diep
;
3071 dip
-> at_name
= diep
;
3074 dip
-> at_comp_dir
= diep
;
3077 dip
-> at_producer
= diep
;
3080 (void) memcpy (&dip
-> at_frame_base
, diep
, sizeof (long));
3082 case AT_start_scope
:
3083 (void) memcpy (&dip
-> at_start_scope
, diep
, sizeof (long));
3085 case AT_stride_size
:
3086 (void) memcpy (&dip
-> at_stride_size
, diep
, sizeof (long));
3089 (void) memcpy (&dip
-> at_src_info
, diep
, sizeof (long));
3092 (void) memcpy (&dip
-> at_prototyped
, diep
, sizeof (short));
3095 /* Found an attribute that we are unprepared to handle. However
3096 it is specifically one of the design goals of DWARF that
3097 consumers should ignore unknown attributes. As long as the
3098 form is one that we recognize (so we know how to skip it),
3099 we can just ignore the unknown attribute. */
3106 diep
+= sizeof (short);
3109 diep
+= sizeof (long);
3112 diep
+= 8 * sizeof (char); /* sizeof (long long) ? */
3116 diep
+= sizeof (long);
3119 (void) memcpy (&block2sz
, diep
, sizeof (short));
3120 block2sz
+= sizeof (short);
3124 (void) memcpy (&block4sz
, diep
, sizeof (long));
3125 block4sz
+= sizeof (long);
3129 diep
+= strlen (diep
) + 1;
3132 SQUAWK (("unknown attribute form (0x%x), skipped rest", form
));