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
;
1164 type
= decode_die_type (dip
);
1165 if ((utype
= lookup_utype (dip
-> dieref
)) == NULL
)
1167 utype
= lookup_pointer_type (type
);
1168 (void) alloc_utype (dip
-> dieref
, utype
);
1172 TYPE_TARGET_TYPE (utype
) = type
;
1173 TYPE_POINTER_TYPE (type
) = utype
;
1175 /* We assume the machine has only one representation for pointers! */
1176 /* FIXME: This confuses host<->target data representations, and is a
1177 poor assumption besides. */
1179 TYPE_LENGTH (utype
) = sizeof (char *);
1180 TYPE_CODE (utype
) = TYPE_CODE_PTR
;
1188 read_subroutine_type -- process TAG_subroutine_type dies
1192 static void read_subroutine_type (struct dieinfo *dip, char thisdie,
1197 Handle DIES due to C code like:
1200 int (*funcp)(int a, long l); (Generates TAG_subroutine_type DIE)
1206 The parameter DIES are currently ignored. See if gdb has a way to
1207 include this info in it's type system, and decode them if so. Is
1208 this what the type structure's "arg_types" field is for? (FIXME)
1212 read_subroutine_type (dip
, thisdie
, enddie
)
1213 struct dieinfo
*dip
;
1217 struct type
*type
; /* Type that this function returns */
1218 struct type
*ftype
; /* Function that returns above type */
1220 /* Decode the type that this subroutine returns */
1222 type
= decode_die_type (dip
);
1224 /* Check to see if we already have a partially constructed user
1225 defined type for this DIE, from a forward reference. */
1227 if ((ftype
= lookup_utype (dip
-> dieref
)) == NULL
)
1229 /* This is the first reference to one of these types. Make
1230 a new one and place it in the user defined types. */
1231 ftype
= lookup_function_type (type
);
1232 (void) alloc_utype (dip
-> dieref
, ftype
);
1236 /* We have an existing partially constructed type, so bash it
1237 into the correct type. */
1238 TYPE_TARGET_TYPE (ftype
) = type
;
1239 TYPE_FUNCTION_TYPE (type
) = ftype
;
1240 TYPE_LENGTH (ftype
) = 1;
1241 TYPE_CODE (ftype
) = TYPE_CODE_FUNC
;
1249 read_enumeration -- process dies which define an enumeration
1253 static void read_enumeration (struct dieinfo *dip, char *thisdie,
1254 char *enddie, struct objfile *objfile)
1258 Given a pointer to a die which begins an enumeration, process all
1259 the dies that define the members of the enumeration.
1263 Note that we need to call enum_type regardless of whether or not we
1264 have a symbol, since we might have an enum without a tag name (thus
1265 no symbol for the tagname).
1269 read_enumeration (dip
, thisdie
, enddie
, objfile
)
1270 struct dieinfo
*dip
;
1273 struct objfile
*objfile
;
1278 type
= enum_type (dip
, objfile
);
1279 if ((sym
= new_symbol (dip
, objfile
)) != NULL
)
1281 SYMBOL_TYPE (sym
) = type
;
1289 enum_type -- decode and return a type for an enumeration
1293 static type *enum_type (struct dieinfo *dip, struct objfile *objfile)
1297 Given a pointer to a die information structure for the die which
1298 starts an enumeration, process all the dies that define the members
1299 of the enumeration and return a type pointer for the enumeration.
1301 At the same time, for each member of the enumeration, create a
1302 symbol for it with namespace VAR_NAMESPACE and class LOC_CONST,
1303 and give it the type of the enumeration itself.
1307 Note that the DWARF specification explicitly mandates that enum
1308 constants occur in reverse order from the source program order,
1309 for "consistency" and because this ordering is easier for many
1310 compilers to generate. (Draft 6, sec 3.8.5, Enumeration type
1311 Entries). Because gdb wants to see the enum members in program
1312 source order, we have to ensure that the order gets reversed while
1313 we are processing them.
1316 static struct type
*
1317 enum_type (dip
, objfile
)
1318 struct dieinfo
*dip
;
1319 struct objfile
*objfile
;
1323 struct nextfield
*next
;
1326 struct nextfield
*list
= NULL
;
1327 struct nextfield
*new;
1336 if ((type
= lookup_utype (dip
-> dieref
)) == NULL
)
1338 /* No forward references created an empty type, so install one now */
1339 type
= alloc_utype (dip
-> dieref
, NULL
);
1341 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1342 /* Some compilers try to be helpful by inventing "fake" names for
1343 anonymous enums, structures, and unions, like "~0fake" or ".0fake".
1344 Thanks, but no thanks... */
1345 if (dip
-> at_name
!= NULL
1346 && *dip
-> at_name
!= '~'
1347 && *dip
-> at_name
!= '.')
1349 TYPE_NAME (type
) = obconcat (¤t_objfile
-> type_obstack
, "enum",
1350 " ", dip
-> at_name
);
1352 if (dip
-> at_byte_size
!= 0)
1354 TYPE_LENGTH (type
) = dip
-> at_byte_size
;
1356 if ((scan
= dip
-> at_element_list
) != NULL
)
1358 if (dip
-> short_element_list
)
1360 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
1361 listend
= scan
+ stemp
+ sizeof (stemp
);
1362 scan
+= sizeof (stemp
);
1366 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
1367 listend
= scan
+ ltemp
+ sizeof (ltemp
);
1368 scan
+= sizeof (ltemp
);
1370 while (scan
< listend
)
1372 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1375 list
-> field
.type
= NULL
;
1376 list
-> field
.bitsize
= 0;
1377 (void) memcpy (&list
-> field
.bitpos
, scan
, sizeof (long));
1378 scan
+= sizeof (long);
1379 list
-> field
.name
= savestring (scan
, strlen (scan
));
1380 scan
+= strlen (scan
) + 1;
1382 /* Handcraft a new symbol for this enum member. */
1383 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
1384 sizeof (struct symbol
));
1385 (void) memset (sym
, 0, sizeof (struct symbol
));
1386 SYMBOL_NAME (sym
) = create_name (list
-> field
.name
, &objfile
->symbol_obstack
);
1387 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1388 SYMBOL_CLASS (sym
) = LOC_CONST
;
1389 SYMBOL_TYPE (sym
) = type
;
1390 SYMBOL_VALUE (sym
) = list
-> field
.bitpos
;
1391 add_symbol_to_list (sym
, list_in_scope
);
1393 /* Now create the vector of fields, and record how big it is. This is
1394 where we reverse the order, by pulling the members of the list in
1395 reverse order from how they were inserted. If we have no fields
1396 (this is apparently possible in C++) then skip building a field
1400 TYPE_NFIELDS (type
) = nfields
;
1401 TYPE_FIELDS (type
) = (struct field
*)
1402 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct field
) * nfields
);
1403 /* Copy the saved-up fields into the field vector. */
1404 for (n
= 0; (n
< nfields
) && (list
!= NULL
); list
= list
-> next
)
1406 TYPE_FIELD (type
, n
++) = list
-> field
;
1417 read_func_scope -- process all dies within a function scope
1421 Process all dies within a given function scope. We are passed
1422 a die information structure pointer DIP for the die which
1423 starts the function scope, and pointers into the raw die data
1424 that define the dies within the function scope.
1426 For now, we ignore lexical block scopes within the function.
1427 The problem is that AT&T cc does not define a DWARF lexical
1428 block scope for the function itself, while gcc defines a
1429 lexical block scope for the function. We need to think about
1430 how to handle this difference, or if it is even a problem.
1435 read_func_scope (dip
, thisdie
, enddie
, objfile
)
1436 struct dieinfo
*dip
;
1439 struct objfile
*objfile
;
1441 register struct context_stack
*new;
1443 if (entry_point
>= dip
-> at_low_pc
&& entry_point
< dip
-> at_high_pc
)
1445 entry_scope_lowpc
= dip
-> at_low_pc
;
1446 entry_scope_highpc
= dip
-> at_high_pc
;
1448 if (STREQ (dip
-> at_name
, "main")) /* FIXME: hardwired name */
1450 main_scope_lowpc
= dip
-> at_low_pc
;
1451 main_scope_highpc
= dip
-> at_high_pc
;
1453 new = push_context (0, dip
-> at_low_pc
);
1454 new -> name
= new_symbol (dip
, objfile
);
1455 list_in_scope
= &local_symbols
;
1456 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1457 new = pop_context ();
1458 /* Make a block for the local symbols within. */
1459 finish_block (new -> name
, &local_symbols
, new -> old_blocks
,
1460 new -> start_addr
, dip
-> at_high_pc
, objfile
);
1461 list_in_scope
= &file_symbols
;
1468 read_file_scope -- process all dies within a file scope
1472 Process all dies within a given file scope. We are passed a
1473 pointer to the die information structure for the die which
1474 starts the file scope, and pointers into the raw die data which
1475 mark the range of dies within the file scope.
1477 When the partial symbol table is built, the file offset for the line
1478 number table for each compilation unit is saved in the partial symbol
1479 table entry for that compilation unit. As the symbols for each
1480 compilation unit are read, the line number table is read into memory
1481 and the variable lnbase is set to point to it. Thus all we have to
1482 do is use lnbase to access the line number table for the current
1487 read_file_scope (dip
, thisdie
, enddie
, objfile
)
1488 struct dieinfo
*dip
;
1491 struct objfile
*objfile
;
1493 struct cleanup
*back_to
;
1494 struct symtab
*symtab
;
1496 if (entry_point
>= dip
-> at_low_pc
&& entry_point
< dip
-> at_high_pc
)
1498 startup_file_start
= dip
-> at_low_pc
;
1499 startup_file_end
= dip
-> at_high_pc
;
1501 if (dip
-> at_producer
!= NULL
)
1503 processing_gcc_compilation
=
1504 STREQN (dip
-> at_producer
, GCC_PRODUCER
, strlen (GCC_PRODUCER
));
1506 numutypes
= (enddie
- thisdie
) / 4;
1507 utypes
= (struct type
**) xmalloc (numutypes
* sizeof (struct type
*));
1508 back_to
= make_cleanup (free
, utypes
);
1509 (void) memset (utypes
, 0, numutypes
* sizeof (struct type
*));
1510 start_symtab (dip
-> at_name
, NULL
, dip
-> at_low_pc
);
1511 decode_line_numbers (lnbase
);
1512 process_dies (thisdie
+ dip
-> dielength
, enddie
, objfile
);
1513 symtab
= end_symtab (dip
-> at_high_pc
, 0, 0, objfile
);
1514 /* FIXME: The following may need to be expanded for other languages */
1515 switch (dip
-> at_language
)
1519 symtab
-> language
= language_c
;
1521 case LANG_C_PLUS_PLUS
:
1522 symtab
-> language
= language_cplus
;
1527 do_cleanups (back_to
);
1536 process_dies -- process a range of DWARF Information Entries
1540 static void process_dies (char *thisdie, char *enddie,
1541 struct objfile *objfile)
1545 Process all DIE's in a specified range. May be (and almost
1546 certainly will be) called recursively.
1550 process_dies (thisdie
, enddie
, objfile
)
1553 struct objfile
*objfile
;
1558 while (thisdie
< enddie
)
1560 basicdieinfo (&di
, thisdie
);
1561 if (di
.dielength
< sizeof (long))
1565 else if (di
.dietag
== TAG_padding
)
1567 nextdie
= thisdie
+ di
.dielength
;
1571 completedieinfo (&di
);
1572 if (di
.at_sibling
!= 0)
1574 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
1578 nextdie
= thisdie
+ di
.dielength
;
1582 case TAG_compile_unit
:
1583 read_file_scope (&di
, thisdie
, nextdie
, objfile
);
1585 case TAG_global_subroutine
:
1586 case TAG_subroutine
:
1587 if (di
.has_at_low_pc
)
1589 read_func_scope (&di
, thisdie
, nextdie
, objfile
);
1592 case TAG_lexical_block
:
1593 read_lexical_block_scope (&di
, thisdie
, nextdie
, objfile
);
1595 case TAG_structure_type
:
1596 case TAG_union_type
:
1597 read_structure_scope (&di
, thisdie
, nextdie
, objfile
);
1599 case TAG_enumeration_type
:
1600 read_enumeration (&di
, thisdie
, nextdie
, objfile
);
1602 case TAG_subroutine_type
:
1603 read_subroutine_type (&di
, thisdie
, nextdie
);
1605 case TAG_array_type
:
1606 dwarf_read_array_type (&di
);
1608 case TAG_pointer_type
:
1609 read_tag_pointer_type (&di
);
1612 (void) new_symbol (&di
, objfile
);
1624 decode_line_numbers -- decode a line number table fragment
1628 static void decode_line_numbers (char *tblscan, char *tblend,
1629 long length, long base, long line, long pc)
1633 Translate the DWARF line number information to gdb form.
1635 The ".line" section contains one or more line number tables, one for
1636 each ".line" section from the objects that were linked.
1638 The AT_stmt_list attribute for each TAG_source_file entry in the
1639 ".debug" section contains the offset into the ".line" section for the
1640 start of the table for that file.
1642 The table itself has the following structure:
1644 <table length><base address><source statement entry>
1645 4 bytes 4 bytes 10 bytes
1647 The table length is the total size of the table, including the 4 bytes
1648 for the length information.
1650 The base address is the address of the first instruction generated
1651 for the source file.
1653 Each source statement entry has the following structure:
1655 <line number><statement position><address delta>
1656 4 bytes 2 bytes 4 bytes
1658 The line number is relative to the start of the file, starting with
1661 The statement position either -1 (0xFFFF) or the number of characters
1662 from the beginning of the line to the beginning of the statement.
1664 The address delta is the difference between the base address and
1665 the address of the first instruction for the statement.
1667 Note that we must copy the bytes from the packed table to our local
1668 variables before attempting to use them, to avoid alignment problems
1669 on some machines, particularly RISC processors.
1673 Does gdb expect the line numbers to be sorted? They are now by
1674 chance/luck, but are not required to be. (FIXME)
1676 The line with number 0 is unused, gdb apparently can discover the
1677 span of the last line some other way. How? (FIXME)
1681 decode_line_numbers (linetable
)
1691 if (linetable
!= NULL
)
1693 tblscan
= tblend
= linetable
;
1694 (void) memcpy (&length
, tblscan
, sizeof (long));
1695 tblscan
+= sizeof (long);
1697 (void) memcpy (&base
, tblscan
, sizeof (long));
1699 tblscan
+= sizeof (long);
1700 while (tblscan
< tblend
)
1702 (void) memcpy (&line
, tblscan
, sizeof (long));
1703 tblscan
+= sizeof (long) + sizeof (short);
1704 (void) memcpy (&pc
, tblscan
, sizeof (long));
1705 tblscan
+= sizeof (long);
1709 record_line (current_subfile
, line
, pc
);
1719 locval -- compute the value of a location attribute
1723 static int locval (char *loc)
1727 Given pointer to a string of bytes that define a location, compute
1728 the location and return the value.
1730 When computing values involving the current value of the frame pointer,
1731 the value zero is used, which results in a value relative to the frame
1732 pointer, rather than the absolute value. This is what GDB wants
1735 When the result is a register number, the global isreg flag is set,
1736 otherwise it is cleared. This is a kludge until we figure out a better
1737 way to handle the problem. Gdb's design does not mesh well with the
1738 DWARF notion of a location computing interpreter, which is a shame
1739 because the flexibility goes unused.
1743 Note that stack[0] is unused except as a default error return.
1744 Note that stack overflow is not yet handled.
1751 unsigned short nbytes
;
1757 (void) memcpy (&nbytes
, loc
, sizeof (short));
1758 end
= loc
+ sizeof (short) + nbytes
;
1763 for (loc
+= sizeof (short); loc
< end
; loc
+= sizeof (long))
1771 /* push register (number) */
1772 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1776 /* push value of register (number) */
1777 /* Actually, we compute the value as if register has 0 */
1779 (void) memcpy (®no
, loc
, sizeof (long));
1782 stack
[++stacki
] = 0;
1786 stack
[++stacki
] = 0;
1787 SQUAWK (("BASEREG %d not handled!", regno
));
1791 /* push address (relocated address) */
1792 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1795 /* push constant (number) */
1796 (void) memcpy (&stack
[++stacki
], loc
, sizeof (long));
1799 /* pop, deref and push 2 bytes (as a long) */
1800 SQUAWK (("OP_DEREF2 address %#x not handled", stack
[stacki
]));
1802 case OP_DEREF4
: /* pop, deref and push 4 bytes (as a long) */
1803 SQUAWK (("OP_DEREF4 address %#x not handled", stack
[stacki
]));
1805 case OP_ADD
: /* pop top 2 items, add, push result */
1806 stack
[stacki
- 1] += stack
[stacki
];
1811 return (stack
[stacki
]);
1818 read_ofile_symtab -- build a full symtab entry from chunk of DIE's
1822 static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
1826 When expanding a partial symbol table entry to a full symbol table
1827 entry, this is the function that gets called to read in the symbols
1828 for the compilation unit.
1830 Returns a pointer to the newly constructed symtab (which is now
1831 the new first one on the objfile's symtab list).
1834 static struct symtab
*
1835 read_ofile_symtab (pst
)
1836 struct partial_symtab
*pst
;
1838 struct cleanup
*back_to
;
1843 abfd
= pst
-> objfile
-> obfd
;
1844 current_objfile
= pst
-> objfile
;
1846 /* Allocate a buffer for the entire chunk of DIE's for this compilation
1847 unit, seek to the location in the file, and read in all the DIE's. */
1850 dbbase
= xmalloc (DBLENGTH(pst
));
1851 dbroff
= DBROFF(pst
);
1852 foffset
= DBFOFF(pst
) + dbroff
;
1853 baseaddr
= pst
-> addr
;
1854 if (bfd_seek (abfd
, foffset
, 0) ||
1855 (bfd_read (dbbase
, DBLENGTH(pst
), 1, abfd
) != DBLENGTH(pst
)))
1858 error ("can't read DWARF data");
1860 back_to
= make_cleanup (free
, dbbase
);
1862 /* If there is a line number table associated with this compilation unit
1863 then read the first long word from the line number table fragment, which
1864 contains the size of the fragment in bytes (including the long word
1865 itself). Allocate a buffer for the fragment and read it in for future
1871 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1872 (bfd_read (&lnsize
, sizeof(long), 1, abfd
) != sizeof(long)))
1874 error ("can't read DWARF line number table size");
1876 lnbase
= xmalloc (lnsize
);
1877 if (bfd_seek (abfd
, LNFOFF (pst
), 0) ||
1878 (bfd_read (lnbase
, lnsize
, 1, abfd
) != lnsize
))
1881 error ("can't read DWARF line numbers");
1883 make_cleanup (free
, lnbase
);
1886 process_dies (dbbase
, dbbase
+ DBLENGTH(pst
), pst
-> objfile
);
1887 do_cleanups (back_to
);
1888 current_objfile
= NULL
;
1889 return (pst
-> objfile
-> symtabs
);
1896 psymtab_to_symtab_1 -- do grunt work for building a full symtab entry
1900 static void psymtab_to_symtab_1 (struct partial_symtab *pst)
1904 Called once for each partial symbol table entry that needs to be
1905 expanded into a full symbol table entry.
1910 psymtab_to_symtab_1 (pst
)
1911 struct partial_symtab
*pst
;
1919 warning ("Psymtab for %s already read in. Shouldn't happen.",
1924 /* Read in all partial symtabs on which this one is dependent */
1925 for (i
= 0; i
< pst
-> number_of_dependencies
; i
++)
1927 if (!pst
-> dependencies
[i
] -> readin
)
1929 /* Inform about additional files that need to be read in. */
1932 fputs_filtered (" ", stdout
);
1934 fputs_filtered ("and ", stdout
);
1936 printf_filtered ("%s...",
1937 pst
-> dependencies
[i
] -> filename
);
1939 fflush (stdout
); /* Flush output */
1941 psymtab_to_symtab_1 (pst
-> dependencies
[i
]);
1944 if (DBLENGTH (pst
)) /* Otherwise it's a dummy */
1946 pst
-> symtab
= read_ofile_symtab (pst
);
1949 printf_filtered ("%d DIE's, sorting...", diecount
);
1953 sort_symtab_syms (pst
-> symtab
);
1964 dwarf_psymtab_to_symtab -- build a full symtab entry from partial one
1968 static void dwarf_psymtab_to_symtab (struct partial_symtab *pst)
1972 This is the DWARF support entry point for building a full symbol
1973 table entry from a partial symbol table entry. We are passed a
1974 pointer to the partial symbol table entry that needs to be expanded.
1979 dwarf_psymtab_to_symtab (pst
)
1980 struct partial_symtab
*pst
;
1987 warning ("Psymtab for %s already read in. Shouldn't happen.",
1992 if (DBLENGTH (pst
) || pst
-> number_of_dependencies
)
1994 /* Print the message now, before starting serious work, to avoid
1995 disconcerting pauses. */
1998 printf_filtered ("Reading in symbols for %s...",
2003 psymtab_to_symtab_1 (pst
);
2005 #if 0 /* FIXME: Check to see what dbxread is doing here and see if
2006 we need to do an equivalent or is this something peculiar to
2008 Match with global symbols. This only needs to be done once,
2009 after all of the symtabs and dependencies have been read in.
2011 scan_file_globals (pst
-> objfile
);
2014 /* Finish up the verbose info message. */
2017 printf_filtered ("done.\n");
2029 init_psymbol_list -- initialize storage for partial symbols
2033 static void init_psymbol_list (struct objfile *objfile, int total_symbols)
2037 Initializes storage for all of the partial symbols that will be
2038 created by dwarf_build_psymtabs and subsidiaries.
2042 init_psymbol_list (objfile
, total_symbols
)
2043 struct objfile
*objfile
;
2046 /* Free any previously allocated psymbol lists. */
2048 if (objfile
-> global_psymbols
.list
)
2050 (*objfile
-> free
) (objfile
-> global_psymbols
.list
);
2052 if (objfile
-> static_psymbols
.list
)
2054 (*objfile
-> free
) (objfile
-> static_psymbols
.list
);
2057 /* Current best guess is that there are approximately a twentieth
2058 of the total symbols (in a debugging file) are global or static
2061 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
2062 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
2063 objfile
-> global_psymbols
.next
=
2064 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
2065 (*objfile
-> xmalloc
) (objfile
-> global_psymbols
.size
2066 * sizeof (struct partial_symbol
));
2067 objfile
-> static_psymbols
.next
=
2068 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
2069 (*objfile
-> xmalloc
) (objfile
-> static_psymbols
.size
2070 * sizeof (struct partial_symbol
));
2077 add_enum_psymbol -- add enumeration members to partial symbol table
2081 Given pointer to a DIE that is known to be for an enumeration,
2082 extract the symbolic names of the enumeration members and add
2083 partial symbols for them.
2087 add_enum_psymbol (dip
, objfile
)
2088 struct dieinfo
*dip
;
2089 struct objfile
*objfile
;
2096 if ((scan
= dip
-> at_element_list
) != NULL
)
2098 if (dip
-> short_element_list
)
2100 (void) memcpy (&stemp
, scan
, sizeof (stemp
));
2101 listend
= scan
+ stemp
+ sizeof (stemp
);
2102 scan
+= sizeof (stemp
);
2106 (void) memcpy (<emp
, scan
, sizeof (ltemp
));
2107 listend
= scan
+ ltemp
+ sizeof (ltemp
);
2108 scan
+= sizeof (ltemp
);
2110 while (scan
< listend
)
2112 scan
+= sizeof (long);
2113 ADD_PSYMBOL_TO_LIST (scan
, strlen (scan
), VAR_NAMESPACE
, LOC_CONST
,
2114 objfile
-> static_psymbols
, 0);
2115 scan
+= strlen (scan
) + 1;
2124 add_partial_symbol -- add symbol to partial symbol table
2128 Given a DIE, if it is one of the types that we want to
2129 add to a partial symbol table, finish filling in the die info
2130 and then add a partial symbol table entry for it.
2135 add_partial_symbol (dip
, objfile
)
2136 struct dieinfo
*dip
;
2137 struct objfile
*objfile
;
2139 switch (dip
-> dietag
)
2141 case TAG_global_subroutine
:
2142 record_minimal_symbol (dip
-> at_name
, dip
-> at_low_pc
, mst_text
,
2144 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2145 VAR_NAMESPACE
, LOC_BLOCK
,
2146 objfile
-> global_psymbols
,
2149 case TAG_global_variable
:
2150 record_minimal_symbol (dip
-> at_name
, locval (dip
-> at_location
),
2152 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2153 VAR_NAMESPACE
, LOC_STATIC
,
2154 objfile
-> global_psymbols
,
2157 case TAG_subroutine
:
2158 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2159 VAR_NAMESPACE
, LOC_BLOCK
,
2160 objfile
-> static_psymbols
,
2163 case TAG_local_variable
:
2164 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2165 VAR_NAMESPACE
, LOC_STATIC
,
2166 objfile
-> static_psymbols
,
2170 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2171 VAR_NAMESPACE
, LOC_TYPEDEF
,
2172 objfile
-> static_psymbols
,
2175 case TAG_structure_type
:
2176 case TAG_union_type
:
2177 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2178 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2179 objfile
-> static_psymbols
,
2182 case TAG_enumeration_type
:
2185 ADD_PSYMBOL_TO_LIST (dip
-> at_name
, strlen (dip
-> at_name
),
2186 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2187 objfile
-> static_psymbols
,
2190 add_enum_psymbol (dip
, objfile
);
2199 scan_partial_symbols -- scan DIE's within a single compilation unit
2203 Process the DIE's within a single compilation unit, looking for
2204 interesting DIE's that contribute to the partial symbol table entry
2205 for this compilation unit. Since we cannot follow any sibling
2206 chains without reading the complete DIE info for every DIE,
2207 it is probably faster to just sequentially check each one to
2208 see if it is one of the types we are interested in, and if so,
2209 then extract all the attributes info and generate a partial
2214 Don't attempt to add anonymous structures or unions since they have
2215 no name. Anonymous enumerations however are processed, because we
2216 want to extract their member names (the check for a tag name is
2219 Also, for variables and subroutines, check that this is the place
2220 where the actual definition occurs, rather than just a reference
2225 scan_partial_symbols (thisdie
, enddie
, objfile
)
2228 struct objfile
*objfile
;
2233 while (thisdie
< enddie
)
2235 basicdieinfo (&di
, thisdie
);
2236 if (di
.dielength
< sizeof (long))
2242 nextdie
= thisdie
+ di
.dielength
;
2243 /* To avoid getting complete die information for every die, we
2244 only do it (below) for the cases we are interested in. */
2247 case TAG_global_subroutine
:
2248 case TAG_subroutine
:
2249 case TAG_global_variable
:
2250 case TAG_local_variable
:
2251 completedieinfo (&di
);
2252 if (di
.at_name
&& (di
.has_at_low_pc
|| di
.at_location
))
2254 add_partial_symbol (&di
, objfile
);
2258 case TAG_structure_type
:
2259 case TAG_union_type
:
2260 completedieinfo (&di
);
2263 add_partial_symbol (&di
, objfile
);
2266 case TAG_enumeration_type
:
2267 completedieinfo (&di
);
2268 add_partial_symbol (&di
, objfile
);
2280 scan_compilation_units -- build a psymtab entry for each compilation
2284 This is the top level dwarf parsing routine for building partial
2287 It scans from the beginning of the DWARF table looking for the first
2288 TAG_compile_unit DIE, and then follows the sibling chain to locate
2289 each additional TAG_compile_unit DIE.
2291 For each TAG_compile_unit DIE it creates a partial symtab structure,
2292 calls a subordinate routine to collect all the compilation unit's
2293 global DIE's, file scope DIEs, typedef DIEs, etc, and then links the
2294 new partial symtab structure into the partial symbol table. It also
2295 records the appropriate information in the partial symbol table entry
2296 to allow the chunk of DIE's and line number table for this compilation
2297 unit to be located and re-read later, to generate a complete symbol
2298 table entry for the compilation unit.
2300 Thus it effectively partitions up a chunk of DIE's for multiple
2301 compilation units into smaller DIE chunks and line number tables,
2302 and associates them with a partial symbol table entry.
2306 If any compilation unit has no line number table associated with
2307 it for some reason (a missing at_stmt_list attribute, rather than
2308 just one with a value of zero, which is valid) then we ensure that
2309 the recorded file offset is zero so that the routine which later
2310 reads line number table fragments knows that there is no fragment
2320 scan_compilation_units (filename
, thisdie
, enddie
, dbfoff
, lnoffset
, objfile
)
2324 unsigned int dbfoff
;
2325 unsigned int lnoffset
;
2326 struct objfile
*objfile
;
2330 struct partial_symtab
*pst
;
2335 while (thisdie
< enddie
)
2337 basicdieinfo (&di
, thisdie
);
2338 if (di
.dielength
< sizeof (long))
2342 else if (di
.dietag
!= TAG_compile_unit
)
2344 nextdie
= thisdie
+ di
.dielength
;
2348 completedieinfo (&di
);
2349 if (di
.at_sibling
!= 0)
2351 nextdie
= dbbase
+ di
.at_sibling
- dbroff
;
2355 nextdie
= thisdie
+ di
.dielength
;
2357 curoff
= thisdie
- dbbase
;
2358 culength
= nextdie
- thisdie
;
2359 curlnoffset
= di
.has_at_stmt_list
? lnoffset
+ di
.at_stmt_list
: 0;
2361 /* First allocate a new partial symbol table structure */
2363 pst
= start_psymtab_common (objfile
, baseaddr
, di
.at_name
,
2365 objfile
-> global_psymbols
.next
,
2366 objfile
-> static_psymbols
.next
);
2368 pst
-> texthigh
= di
.at_high_pc
;
2369 pst
-> read_symtab_private
= (char *)
2370 obstack_alloc (&objfile
-> psymbol_obstack
,
2371 sizeof (struct dwfinfo
));
2372 DBFOFF (pst
) = dbfoff
;
2373 DBROFF (pst
) = curoff
;
2374 DBLENGTH (pst
) = culength
;
2375 LNFOFF (pst
) = curlnoffset
;
2376 pst
-> read_symtab
= dwarf_psymtab_to_symtab
;
2378 /* Now look for partial symbols */
2380 scan_partial_symbols (thisdie
+ di
.dielength
, nextdie
, objfile
);
2382 pst
-> n_global_syms
= objfile
-> global_psymbols
.next
-
2383 (objfile
-> global_psymbols
.list
+ pst
-> globals_offset
);
2384 pst
-> n_static_syms
= objfile
-> static_psymbols
.next
-
2385 (objfile
-> static_psymbols
.list
+ pst
-> statics_offset
);
2386 sort_pst_symbols (pst
);
2387 /* If there is already a psymtab or symtab for a file of this name,
2388 remove it. (If there is a symtab, more drastic things also
2389 happen.) This happens in VxWorks. */
2390 free_named_symtabs (pst
-> filename
);
2400 new_symbol -- make a symbol table entry for a new symbol
2404 static struct symbol *new_symbol (struct dieinfo *dip,
2405 struct objfile *objfile)
2409 Given a pointer to a DWARF information entry, figure out if we need
2410 to make a symbol table entry for it, and if so, create a new entry
2411 and return a pointer to it.
2414 static struct symbol
*
2415 new_symbol (dip
, objfile
)
2416 struct dieinfo
*dip
;
2417 struct objfile
*objfile
;
2419 struct symbol
*sym
= NULL
;
2421 if (dip
-> at_name
!= NULL
)
2423 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
,
2424 sizeof (struct symbol
));
2425 (void) memset (sym
, 0, sizeof (struct symbol
));
2426 SYMBOL_NAME (sym
) = create_name (dip
-> at_name
, &objfile
->symbol_obstack
);
2427 /* default assumptions */
2428 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2429 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2430 SYMBOL_TYPE (sym
) = decode_die_type (dip
);
2431 switch (dip
-> dietag
)
2434 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2435 SYMBOL_CLASS (sym
) = LOC_LABEL
;
2437 case TAG_global_subroutine
:
2438 case TAG_subroutine
:
2439 SYMBOL_VALUE (sym
) = dip
-> at_low_pc
;
2440 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
2441 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
2442 if (dip
-> dietag
== TAG_global_subroutine
)
2444 add_symbol_to_list (sym
, &global_symbols
);
2448 add_symbol_to_list (sym
, list_in_scope
);
2451 case TAG_global_variable
:
2452 if (dip
-> at_location
!= NULL
)
2454 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2455 add_symbol_to_list (sym
, &global_symbols
);
2456 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2457 SYMBOL_VALUE (sym
) += baseaddr
;
2460 case TAG_local_variable
:
2461 if (dip
-> at_location
!= NULL
)
2463 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2464 add_symbol_to_list (sym
, list_in_scope
);
2467 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2471 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2475 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2476 SYMBOL_VALUE (sym
) += baseaddr
;
2480 case TAG_formal_parameter
:
2481 if (dip
-> at_location
!= NULL
)
2483 SYMBOL_VALUE (sym
) = locval (dip
-> at_location
);
2485 add_symbol_to_list (sym
, list_in_scope
);
2488 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
2492 SYMBOL_CLASS (sym
) = LOC_ARG
;
2495 case TAG_unspecified_parameters
:
2496 /* From varargs functions; gdb doesn't seem to have any interest in
2497 this information, so just ignore it for now. (FIXME?) */
2499 case TAG_structure_type
:
2500 case TAG_union_type
:
2501 case TAG_enumeration_type
:
2502 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2503 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2504 add_symbol_to_list (sym
, list_in_scope
);
2507 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2508 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2509 add_symbol_to_list (sym
, list_in_scope
);
2512 /* Not a tag we recognize. Hopefully we aren't processing trash
2513 data, but since we must specifically ignore things we don't
2514 recognize, there is nothing else we should do at this point. */
2525 decode_mod_fund_type -- decode a modified fundamental type
2529 static struct type *decode_mod_fund_type (char *typedata)
2533 Decode a block of data containing a modified fundamental
2534 type specification. TYPEDATA is a pointer to the block,
2535 which consists of a two byte length, containing the size
2536 of the rest of the block. At the end of the block is a
2537 two byte value that gives the fundamental type. Everything
2538 in between are type modifiers.
2540 We simply compute the number of modifiers and call the general
2541 function decode_modified_type to do the actual work.
2544 static struct type
*
2545 decode_mod_fund_type (typedata
)
2548 struct type
*typep
= NULL
;
2549 unsigned short modcount
;
2550 unsigned char *modifiers
;
2552 /* Get the total size of the block, exclusive of the size itself */
2553 (void) memcpy (&modcount
, typedata
, sizeof (short));
2554 /* Deduct the size of the fundamental type bytes at the end of the block. */
2555 modcount
-= sizeof (short);
2556 /* Skip over the two size bytes at the beginning of the block. */
2557 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2558 /* Now do the actual decoding */
2559 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_fund_type
);
2567 decode_mod_u_d_type -- decode a modified user defined type
2571 static struct type *decode_mod_u_d_type (char *typedata)
2575 Decode a block of data containing a modified user defined
2576 type specification. TYPEDATA is a pointer to the block,
2577 which consists of a two byte length, containing the size
2578 of the rest of the block. At the end of the block is a
2579 four byte value that gives a reference to a user defined type.
2580 Everything in between are type modifiers.
2582 We simply compute the number of modifiers and call the general
2583 function decode_modified_type to do the actual work.
2586 static struct type
*
2587 decode_mod_u_d_type (typedata
)
2590 struct type
*typep
= NULL
;
2591 unsigned short modcount
;
2592 unsigned char *modifiers
;
2594 /* Get the total size of the block, exclusive of the size itself */
2595 (void) memcpy (&modcount
, typedata
, sizeof (short));
2596 /* Deduct the size of the reference type bytes at the end of the block. */
2597 modcount
-= sizeof (long);
2598 /* Skip over the two size bytes at the beginning of the block. */
2599 modifiers
= (unsigned char *) typedata
+ sizeof (short);
2600 /* Now do the actual decoding */
2601 typep
= decode_modified_type (modifiers
, modcount
, AT_mod_u_d_type
);
2609 decode_modified_type -- decode modified user or fundamental type
2613 static struct type *decode_modified_type (unsigned char *modifiers,
2614 unsigned short modcount, int mtype)
2618 Decode a modified type, either a modified fundamental type or
2619 a modified user defined type. MODIFIERS is a pointer to the
2620 block of bytes that define MODCOUNT modifiers. Immediately
2621 following the last modifier is a short containing the fundamental
2622 type or a long containing the reference to the user defined
2623 type. Which one is determined by MTYPE, which is either
2624 AT_mod_fund_type or AT_mod_u_d_type to indicate what modified
2625 type we are generating.
2627 We call ourself recursively to generate each modified type,`
2628 until MODCOUNT reaches zero, at which point we have consumed
2629 all the modifiers and generate either the fundamental type or
2630 user defined type. When the recursion unwinds, each modifier
2631 is applied in turn to generate the full modified type.
2635 If we find a modifier that we don't recognize, and it is not one
2636 of those reserved for application specific use, then we issue a
2637 warning and simply ignore the modifier.
2641 We currently ignore MOD_const and MOD_volatile. (FIXME)
2645 static struct type
*
2646 decode_modified_type (modifiers
, modcount
, mtype
)
2647 unsigned char *modifiers
;
2648 unsigned int modcount
;
2651 struct type
*typep
= NULL
;
2652 unsigned short fundtype
;
2654 unsigned char modifier
;
2660 case AT_mod_fund_type
:
2661 (void) memcpy (&fundtype
, modifiers
, sizeof (short));
2662 typep
= decode_fund_type (fundtype
);
2664 case AT_mod_u_d_type
:
2665 (void) memcpy (&dieref
, modifiers
, sizeof (DIEREF
));
2666 if ((typep
= lookup_utype (dieref
)) == NULL
)
2668 typep
= alloc_utype (dieref
, NULL
);
2672 SQUAWK (("botched modified type decoding (mtype 0x%x)", mtype
));
2673 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2679 modifier
= *modifiers
++;
2680 typep
= decode_modified_type (modifiers
, --modcount
, mtype
);
2683 case MOD_pointer_to
:
2684 typep
= lookup_pointer_type (typep
);
2686 case MOD_reference_to
:
2687 typep
= lookup_reference_type (typep
);
2690 SQUAWK (("type modifier 'const' ignored")); /* FIXME */
2693 SQUAWK (("type modifier 'volatile' ignored")); /* FIXME */
2696 if (!(MOD_lo_user
<= modifier
&& modifier
<= MOD_hi_user
))
2698 SQUAWK (("unknown type modifier %u", modifier
));
2710 decode_fund_type -- translate basic DWARF type to gdb base type
2714 Given an integer that is one of the fundamental DWARF types,
2715 translate it to one of the basic internal gdb types and return
2716 a pointer to the appropriate gdb type (a "struct type *").
2720 If we encounter a fundamental type that we are unprepared to
2721 deal with, and it is not in the range of those types defined
2722 as application specific types, then we issue a warning and
2723 treat the type as an "int".
2726 static struct type
*
2727 decode_fund_type (fundtype
)
2728 unsigned int fundtype
;
2730 struct type
*typep
= NULL
;
2736 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2739 case FT_boolean
: /* Was FT_set in AT&T version */
2740 typep
= lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
2743 case FT_pointer
: /* (void *) */
2744 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2745 typep
= lookup_pointer_type (typep
);
2749 typep
= lookup_fundamental_type (current_objfile
, FT_CHAR
);
2752 case FT_signed_char
:
2753 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
2756 case FT_unsigned_char
:
2757 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
2761 typep
= lookup_fundamental_type (current_objfile
, FT_SHORT
);
2764 case FT_signed_short
:
2765 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_SHORT
);
2768 case FT_unsigned_short
:
2769 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
2773 typep
= lookup_fundamental_type (current_objfile
, FT_INTEGER
);
2776 case FT_signed_integer
:
2777 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_INTEGER
);
2780 case FT_unsigned_integer
:
2781 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
2785 typep
= lookup_fundamental_type (current_objfile
, FT_LONG
);
2788 case FT_signed_long
:
2789 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG
);
2792 case FT_unsigned_long
:
2793 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
2797 typep
= lookup_fundamental_type (current_objfile
, FT_LONG_LONG
);
2800 case FT_signed_long_long
:
2801 typep
= lookup_fundamental_type (current_objfile
, FT_SIGNED_LONG_LONG
);
2804 case FT_unsigned_long_long
:
2805 typep
= lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG_LONG
);
2809 typep
= lookup_fundamental_type (current_objfile
, FT_FLOAT
);
2812 case FT_dbl_prec_float
:
2813 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
2816 case FT_ext_prec_float
:
2817 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
2821 typep
= lookup_fundamental_type (current_objfile
, FT_COMPLEX
);
2824 case FT_dbl_prec_complex
:
2825 typep
= lookup_fundamental_type (current_objfile
, FT_DBL_PREC_COMPLEX
);
2828 case FT_ext_prec_complex
:
2829 typep
= lookup_fundamental_type (current_objfile
, FT_EXT_PREC_COMPLEX
);
2834 if ((typep
== NULL
) && !(FT_lo_user
<= fundtype
&& fundtype
<= FT_hi_user
))
2836 SQUAWK (("unexpected fundamental type 0x%x", fundtype
));
2837 typep
= lookup_fundamental_type (current_objfile
, FT_VOID
);
2847 create_name -- allocate a fresh copy of a string on an obstack
2851 Given a pointer to a string and a pointer to an obstack, allocates
2852 a fresh copy of the string on the specified obstack.
2857 create_name (name
, obstackp
)
2859 struct obstack
*obstackp
;
2864 length
= strlen (name
) + 1;
2865 newname
= (char *) obstack_alloc (obstackp
, length
);
2866 (void) strcpy (newname
, name
);
2874 basicdieinfo -- extract the minimal die info from raw die data
2878 void basicdieinfo (char *diep, struct dieinfo *dip)
2882 Given a pointer to raw DIE data, and a pointer to an instance of a
2883 die info structure, this function extracts the basic information
2884 from the DIE data required to continue processing this DIE, along
2885 with some bookkeeping information about the DIE.
2887 The information we absolutely must have includes the DIE tag,
2888 and the DIE length. If we need the sibling reference, then we
2889 will have to call completedieinfo() to process all the remaining
2892 Note that since there is no guarantee that the data is properly
2893 aligned in memory for the type of access required (indirection
2894 through anything other than a char pointer), we use memcpy to
2895 shuffle data items larger than a char. Possibly inefficient, but
2898 We also take care of some other basic things at this point, such
2899 as ensuring that the instance of the die info structure starts
2900 out completely zero'd and that curdie is initialized for use
2901 in error reporting if we have a problem with the current die.
2905 All DIE's must have at least a valid length, thus the minimum
2906 DIE size is sizeof (long). In order to have a valid tag, the
2907 DIE size must be at least sizeof (short) larger, otherwise they
2908 are forced to be TAG_padding DIES.
2910 Padding DIES must be at least sizeof(long) in length, implying that
2911 if a padding DIE is used for alignment and the amount needed is less
2912 than sizeof(long) then the padding DIE has to be big enough to align
2913 to the next alignment boundry.
2917 basicdieinfo (dip
, diep
)
2918 struct dieinfo
*dip
;
2922 (void) memset (dip
, 0, sizeof (struct dieinfo
));
2924 dip
-> dieref
= dbroff
+ (diep
- dbbase
);
2925 (void) memcpy (&dip
-> dielength
, diep
, sizeof (long));
2926 if (dip
-> dielength
< sizeof (long))
2928 dwarfwarn ("malformed DIE, bad length (%d bytes)", dip
-> dielength
);
2930 else if (dip
-> dielength
< (sizeof (long) + sizeof (short)))
2932 dip
-> dietag
= TAG_padding
;
2936 (void) memcpy (&dip
-> dietag
, diep
+ sizeof (long), sizeof (short));
2944 completedieinfo -- finish reading the information for a given DIE
2948 void completedieinfo (struct dieinfo *dip)
2952 Given a pointer to an already partially initialized die info structure,
2953 scan the raw DIE data and finish filling in the die info structure
2954 from the various attributes found.
2956 Note that since there is no guarantee that the data is properly
2957 aligned in memory for the type of access required (indirection
2958 through anything other than a char pointer), we use memcpy to
2959 shuffle data items larger than a char. Possibly inefficient, but
2964 Each time we are called, we increment the diecount variable, which
2965 keeps an approximate count of the number of dies processed for
2966 each compilation unit. This information is presented to the user
2967 if the info_verbose flag is set.
2972 completedieinfo (dip
)
2973 struct dieinfo
*dip
;
2975 char *diep
; /* Current pointer into raw DIE data */
2976 char *end
; /* Terminate DIE scan here */
2977 unsigned short attr
; /* Current attribute being scanned */
2978 unsigned short form
; /* Form of the attribute */
2979 short block2sz
; /* Size of a block2 attribute field */
2980 long block4sz
; /* Size of a block4 attribute field */
2984 end
= diep
+ dip
-> dielength
;
2985 diep
+= sizeof (long) + sizeof (short);
2988 (void) memcpy (&attr
, diep
, sizeof (short));
2989 diep
+= sizeof (short);
2993 (void) memcpy (&dip
-> at_fund_type
, diep
, sizeof (short));
2996 (void) memcpy (&dip
-> at_ordering
, diep
, sizeof (short));
2999 (void) memcpy (&dip
-> at_bit_offset
, diep
, sizeof (short));
3002 (void) memcpy (&dip
-> at_visibility
, diep
, sizeof (short));
3005 (void) memcpy (&dip
-> at_sibling
, diep
, sizeof (long));
3008 (void) memcpy (&dip
-> at_stmt_list
, diep
, sizeof (long));
3009 dip
-> has_at_stmt_list
= 1;
3012 (void) memcpy (&dip
-> at_low_pc
, diep
, sizeof (long));
3013 dip
-> at_low_pc
+= baseaddr
;
3014 dip
-> has_at_low_pc
= 1;
3017 (void) memcpy (&dip
-> at_high_pc
, diep
, sizeof (long));
3018 dip
-> at_high_pc
+= baseaddr
;
3021 (void) memcpy (&dip
-> at_language
, diep
, sizeof (long));
3023 case AT_user_def_type
:
3024 (void) memcpy (&dip
-> at_user_def_type
, diep
, sizeof (long));
3027 (void) memcpy (&dip
-> at_byte_size
, diep
, sizeof (long));
3030 (void) memcpy (&dip
-> at_bit_size
, diep
, sizeof (long));
3033 (void) memcpy (&dip
-> at_member
, diep
, sizeof (long));
3036 (void) memcpy (&dip
-> at_discr
, diep
, sizeof (long));
3039 (void) memcpy (&dip
-> at_import
, diep
, sizeof (long));
3042 dip
-> at_location
= diep
;
3044 case AT_mod_fund_type
:
3045 dip
-> at_mod_fund_type
= diep
;
3047 case AT_subscr_data
:
3048 dip
-> at_subscr_data
= diep
;
3050 case AT_mod_u_d_type
:
3051 dip
-> at_mod_u_d_type
= diep
;
3053 case AT_element_list
:
3054 dip
-> at_element_list
= diep
;
3055 dip
-> short_element_list
= 0;
3057 case AT_short_element_list
:
3058 dip
-> at_element_list
= diep
;
3059 dip
-> short_element_list
= 1;
3061 case AT_discr_value
:
3062 dip
-> at_discr_value
= diep
;
3064 case AT_string_length
:
3065 dip
-> at_string_length
= diep
;
3068 dip
-> at_name
= diep
;
3071 dip
-> at_comp_dir
= diep
;
3074 dip
-> at_producer
= diep
;
3077 (void) memcpy (&dip
-> at_frame_base
, diep
, sizeof (long));
3079 case AT_start_scope
:
3080 (void) memcpy (&dip
-> at_start_scope
, diep
, sizeof (long));
3082 case AT_stride_size
:
3083 (void) memcpy (&dip
-> at_stride_size
, diep
, sizeof (long));
3086 (void) memcpy (&dip
-> at_src_info
, diep
, sizeof (long));
3089 (void) memcpy (&dip
-> at_prototyped
, diep
, sizeof (short));
3092 /* Found an attribute that we are unprepared to handle. However
3093 it is specifically one of the design goals of DWARF that
3094 consumers should ignore unknown attributes. As long as the
3095 form is one that we recognize (so we know how to skip it),
3096 we can just ignore the unknown attribute. */
3103 diep
+= sizeof (short);
3106 diep
+= sizeof (long);
3109 diep
+= 8 * sizeof (char); /* sizeof (long long) ? */
3113 diep
+= sizeof (long);
3116 (void) memcpy (&block2sz
, diep
, sizeof (short));
3117 block2sz
+= sizeof (short);
3121 (void) memcpy (&block4sz
, diep
, sizeof (long));
3122 block4sz
+= sizeof (long);
3126 diep
+= strlen (diep
) + 1;
3129 SQUAWK (("unknown attribute form (0x%x), skipped rest", form
));