]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* DWARF 2 debugging format support for GDB. |
2 | Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. | |
3 | ||
4 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
5 | Inc. with support from Florida State University (under contract | |
6 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
7 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
8 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
9 | support in dwarfread.c | |
10 | ||
c5aa993b | 11 | This file is part of GDB. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is free software; you can redistribute it and/or modify |
14 | it under the terms of the GNU General Public License as published by | |
15 | the Free Software Foundation; either version 2 of the License, or (at | |
16 | your option) any later version. | |
c906108c | 17 | |
c5aa993b JM |
18 | This program is distributed in the hope that it will be useful, but |
19 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | General Public License for more details. | |
c906108c | 22 | |
c5aa993b JM |
23 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software | |
25 | Foundation, Inc., 59 Temple Place - Suite 330, | |
26 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
27 | |
28 | #include "defs.h" | |
29 | #include "bfd.h" | |
30 | #include "elf-bfd.h" | |
31 | #include "symtab.h" | |
32 | #include "gdbtypes.h" | |
33 | #include "symfile.h" | |
34 | #include "objfiles.h" | |
35 | #include "elf/dwarf2.h" | |
36 | #include "buildsym.h" | |
37 | #include "demangle.h" | |
38 | #include "expression.h" | |
39 | #include "language.h" | |
40 | #include "complaints.h" | |
41 | ||
42 | #include <fcntl.h> | |
43 | #include "gdb_string.h" | |
44 | #include <sys/types.h> | |
45 | ||
46 | /* .debug_info header for a compilation unit | |
47 | Because of alignment constraints, this structure has padding and cannot | |
48 | be mapped directly onto the beginning of the .debug_info section. */ | |
49 | typedef struct comp_unit_header | |
50 | { | |
51 | unsigned int length; /* length of the .debug_info | |
52 | contribution */ | |
53 | unsigned short version; /* version number -- 2 for DWARF | |
54 | version 2 */ | |
55 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
56 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
57 | } | |
58 | _COMP_UNIT_HEADER; | |
59 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
60 | ||
61 | /* .debug_pubnames header | |
62 | Because of alignment constraints, this structure has padding and cannot | |
63 | be mapped directly onto the beginning of the .debug_info section. */ | |
64 | typedef struct pubnames_header | |
65 | { | |
66 | unsigned int length; /* length of the .debug_pubnames | |
67 | contribution */ | |
68 | unsigned char version; /* version number -- 2 for DWARF | |
69 | version 2 */ | |
70 | unsigned int info_offset; /* offset into .debug_info section */ | |
71 | unsigned int info_size; /* byte size of .debug_info section | |
72 | portion */ | |
73 | } | |
74 | _PUBNAMES_HEADER; | |
75 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
76 | ||
77 | /* .debug_pubnames header | |
78 | Because of alignment constraints, this structure has padding and cannot | |
79 | be mapped directly onto the beginning of the .debug_info section. */ | |
80 | typedef struct aranges_header | |
81 | { | |
82 | unsigned int length; /* byte len of the .debug_aranges | |
83 | contribution */ | |
84 | unsigned short version; /* version number -- 2 for DWARF | |
85 | version 2 */ | |
86 | unsigned int info_offset; /* offset into .debug_info section */ | |
87 | unsigned char addr_size; /* byte size of an address */ | |
88 | unsigned char seg_size; /* byte size of segment descriptor */ | |
89 | } | |
90 | _ARANGES_HEADER; | |
91 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
92 | ||
93 | /* .debug_line statement program prologue | |
94 | Because of alignment constraints, this structure has padding and cannot | |
95 | be mapped directly onto the beginning of the .debug_info section. */ | |
96 | typedef struct statement_prologue | |
97 | { | |
98 | unsigned int total_length; /* byte length of the statement | |
99 | information */ | |
100 | unsigned short version; /* version number -- 2 for DWARF | |
101 | version 2 */ | |
102 | unsigned int prologue_length; /* # bytes between prologue & | |
103 | stmt program */ | |
104 | unsigned char minimum_instruction_length; /* byte size of | |
105 | smallest instr */ | |
106 | unsigned char default_is_stmt; /* initial value of is_stmt | |
107 | register */ | |
108 | char line_base; | |
109 | unsigned char line_range; | |
110 | unsigned char opcode_base; /* number assigned to first special | |
111 | opcode */ | |
112 | unsigned char *standard_opcode_lengths; | |
113 | } | |
114 | _STATEMENT_PROLOGUE; | |
115 | ||
116 | /* offsets and sizes of debugging sections */ | |
117 | ||
118 | static file_ptr dwarf_info_offset; | |
119 | static file_ptr dwarf_abbrev_offset; | |
120 | static file_ptr dwarf_line_offset; | |
121 | static file_ptr dwarf_pubnames_offset; | |
122 | static file_ptr dwarf_aranges_offset; | |
123 | static file_ptr dwarf_loc_offset; | |
124 | static file_ptr dwarf_macinfo_offset; | |
125 | static file_ptr dwarf_str_offset; | |
126 | ||
127 | static unsigned int dwarf_info_size; | |
128 | static unsigned int dwarf_abbrev_size; | |
129 | static unsigned int dwarf_line_size; | |
130 | static unsigned int dwarf_pubnames_size; | |
131 | static unsigned int dwarf_aranges_size; | |
132 | static unsigned int dwarf_loc_size; | |
133 | static unsigned int dwarf_macinfo_size; | |
134 | static unsigned int dwarf_str_size; | |
135 | ||
136 | /* names of the debugging sections */ | |
137 | ||
138 | #define INFO_SECTION ".debug_info" | |
139 | #define ABBREV_SECTION ".debug_abbrev" | |
140 | #define LINE_SECTION ".debug_line" | |
141 | #define PUBNAMES_SECTION ".debug_pubnames" | |
142 | #define ARANGES_SECTION ".debug_aranges" | |
143 | #define LOC_SECTION ".debug_loc" | |
144 | #define MACINFO_SECTION ".debug_macinfo" | |
145 | #define STR_SECTION ".debug_str" | |
146 | ||
147 | /* local data types */ | |
148 | ||
149 | /* The data in a compilation unit header looks like this. */ | |
150 | struct comp_unit_head | |
151 | { | |
152 | unsigned int length; | |
153 | short version; | |
154 | unsigned int abbrev_offset; | |
155 | unsigned char addr_size; | |
156 | }; | |
157 | ||
158 | /* The data in the .debug_line statement prologue looks like this. */ | |
159 | struct line_head | |
160 | { | |
161 | unsigned int total_length; | |
162 | unsigned short version; | |
163 | unsigned int prologue_length; | |
164 | unsigned char minimum_instruction_length; | |
165 | unsigned char default_is_stmt; | |
166 | int line_base; | |
167 | unsigned char line_range; | |
168 | unsigned char opcode_base; | |
169 | unsigned char *standard_opcode_lengths; | |
170 | }; | |
171 | ||
172 | /* When we construct a partial symbol table entry we only | |
173 | need this much information. */ | |
174 | struct partial_die_info | |
175 | { | |
176 | enum dwarf_tag tag; | |
177 | unsigned char has_children; | |
178 | unsigned char is_external; | |
179 | unsigned char is_declaration; | |
180 | unsigned char has_type; | |
181 | unsigned int offset; | |
182 | unsigned int abbrev; | |
183 | char *name; | |
184 | CORE_ADDR lowpc; | |
185 | CORE_ADDR highpc; | |
186 | struct dwarf_block *locdesc; | |
187 | unsigned int language; | |
188 | char *sibling; | |
189 | }; | |
190 | ||
191 | /* This data structure holds the information of an abbrev. */ | |
192 | struct abbrev_info | |
193 | { | |
194 | unsigned int number; /* number identifying abbrev */ | |
195 | enum dwarf_tag tag; /* dwarf tag */ | |
196 | int has_children; /* boolean */ | |
197 | unsigned int num_attrs; /* number of attributes */ | |
198 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ | |
199 | struct abbrev_info *next; /* next in chain */ | |
200 | }; | |
201 | ||
202 | struct attr_abbrev | |
203 | { | |
204 | enum dwarf_attribute name; | |
205 | enum dwarf_form form; | |
206 | }; | |
207 | ||
208 | /* This data structure holds a complete die structure. */ | |
209 | struct die_info | |
210 | { | |
c5aa993b JM |
211 | enum dwarf_tag tag; /* Tag indicating type of die */ |
212 | unsigned short has_children; /* Does the die have children */ | |
213 | unsigned int abbrev; /* Abbrev number */ | |
214 | unsigned int offset; /* Offset in .debug_info section */ | |
215 | unsigned int num_attrs; /* Number of attributes */ | |
216 | struct attribute *attrs; /* An array of attributes */ | |
217 | struct die_info *next_ref; /* Next die in ref hash table */ | |
218 | struct die_info *next; /* Next die in linked list */ | |
219 | struct type *type; /* Cached type information */ | |
c906108c SS |
220 | }; |
221 | ||
222 | /* Attributes have a name and a value */ | |
223 | struct attribute | |
224 | { | |
225 | enum dwarf_attribute name; | |
226 | enum dwarf_form form; | |
227 | union | |
228 | { | |
229 | char *str; | |
230 | struct dwarf_block *blk; | |
231 | unsigned int unsnd; | |
232 | int snd; | |
233 | CORE_ADDR addr; | |
234 | } | |
235 | u; | |
236 | }; | |
237 | ||
238 | /* Get at parts of an attribute structure */ | |
239 | ||
240 | #define DW_STRING(attr) ((attr)->u.str) | |
241 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
242 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
243 | #define DW_SND(attr) ((attr)->u.snd) | |
244 | #define DW_ADDR(attr) ((attr)->u.addr) | |
245 | ||
246 | /* Blocks are a bunch of untyped bytes. */ | |
247 | struct dwarf_block | |
248 | { | |
249 | unsigned int size; | |
250 | char *data; | |
251 | }; | |
252 | ||
253 | /* We only hold one compilation unit's abbrevs in | |
254 | memory at any one time. */ | |
255 | #ifndef ABBREV_HASH_SIZE | |
256 | #define ABBREV_HASH_SIZE 121 | |
257 | #endif | |
258 | #ifndef ATTR_ALLOC_CHUNK | |
259 | #define ATTR_ALLOC_CHUNK 4 | |
260 | #endif | |
261 | ||
262 | static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE]; | |
263 | ||
264 | /* A hash table of die offsets for following references. */ | |
265 | #ifndef REF_HASH_SIZE | |
266 | #define REF_HASH_SIZE 1021 | |
267 | #endif | |
268 | ||
269 | static struct die_info *die_ref_table[REF_HASH_SIZE]; | |
270 | ||
271 | /* Obstack for allocating temporary storage used during symbol reading. */ | |
272 | static struct obstack dwarf2_tmp_obstack; | |
273 | ||
274 | /* Offset to the first byte of the current compilation unit header, | |
275 | for resolving relative reference dies. */ | |
276 | static unsigned int cu_header_offset; | |
277 | ||
278 | /* Allocate fields for structs, unions and enums in this size. */ | |
279 | #ifndef DW_FIELD_ALLOC_CHUNK | |
280 | #define DW_FIELD_ALLOC_CHUNK 4 | |
281 | #endif | |
282 | ||
283 | /* The language we are debugging. */ | |
284 | static enum language cu_language; | |
285 | static const struct language_defn *cu_language_defn; | |
286 | ||
287 | /* Actually data from the sections. */ | |
288 | static char *dwarf_info_buffer; | |
289 | static char *dwarf_abbrev_buffer; | |
290 | static char *dwarf_line_buffer; | |
291 | ||
292 | /* A zeroed version of a partial die for initialization purposes. */ | |
293 | static struct partial_die_info zeroed_partial_die; | |
294 | ||
295 | /* The generic symbol table building routines have separate lists for | |
296 | file scope symbols and all all other scopes (local scopes). So | |
297 | we need to select the right one to pass to add_symbol_to_list(). | |
298 | We do it by keeping a pointer to the correct list in list_in_scope. | |
299 | ||
300 | FIXME: The original dwarf code just treated the file scope as the first | |
301 | local scope, and all other local scopes as nested local scopes, and worked | |
302 | fine. Check to see if we really need to distinguish these | |
303 | in buildsym.c. */ | |
304 | static struct pending **list_in_scope = &file_symbols; | |
305 | ||
7a292a7a SS |
306 | /* FIXME: decode_locdesc sets these variables to describe the location |
307 | to the caller. These ought to be a structure or something. If | |
308 | none of the flags are set, the object lives at the address returned | |
309 | by decode_locdesc. */ | |
310 | ||
311 | static int optimized_out; /* No ops in location in expression, | |
312 | so object was optimized out. */ | |
313 | static int isreg; /* Object lives in register. | |
314 | decode_locdesc's return value is | |
315 | the register number. */ | |
316 | static int offreg; /* Object's address is the sum of the | |
317 | register specified by basereg, plus | |
318 | the offset returned. */ | |
c5aa993b | 319 | static int basereg; /* See `offreg'. */ |
7a292a7a SS |
320 | static int isderef; /* Value described by flags above is |
321 | the address of a pointer to the object. */ | |
322 | static int islocal; /* Variable is at the returned offset | |
323 | from the frame start, but there's | |
324 | no identified frame pointer for | |
325 | this function, so we can't say | |
326 | which register it's relative to; | |
327 | use LOC_LOCAL. */ | |
c906108c SS |
328 | |
329 | /* DW_AT_frame_base values for the current function. | |
330 | frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it | |
331 | contains the register number for the frame register. | |
332 | frame_base_offset is the offset from the frame register to the | |
333 | virtual stack frame. */ | |
334 | static int frame_base_reg; | |
335 | static CORE_ADDR frame_base_offset; | |
336 | ||
337 | /* This value is added to each symbol value. FIXME: Generalize to | |
338 | the section_offsets structure used by dbxread (once this is done, | |
339 | pass the appropriate section number to end_symtab). */ | |
340 | static CORE_ADDR baseaddr; /* Add to each symbol value */ | |
341 | ||
342 | /* We put a pointer to this structure in the read_symtab_private field | |
343 | of the psymtab. | |
344 | The complete dwarf information for an objfile is kept in the | |
345 | psymbol_obstack, so that absolute die references can be handled. | |
346 | Most of the information in this structure is related to an entire | |
347 | object file and could be passed via the sym_private field of the objfile. | |
348 | It is however conceivable that dwarf2 might not be the only type | |
349 | of symbols read from an object file. */ | |
350 | ||
351 | struct dwarf2_pinfo | |
c5aa993b JM |
352 | { |
353 | /* Pointer to start of dwarf info buffer for the objfile. */ | |
c906108c | 354 | |
c5aa993b | 355 | char *dwarf_info_buffer; |
c906108c | 356 | |
c5aa993b | 357 | /* Offset in dwarf_info_buffer for this compilation unit. */ |
c906108c | 358 | |
c5aa993b | 359 | unsigned long dwarf_info_offset; |
c906108c | 360 | |
c5aa993b | 361 | /* Pointer to start of dwarf abbreviation buffer for the objfile. */ |
c906108c | 362 | |
c5aa993b | 363 | char *dwarf_abbrev_buffer; |
c906108c | 364 | |
c5aa993b | 365 | /* Size of dwarf abbreviation section for the objfile. */ |
c906108c | 366 | |
c5aa993b | 367 | unsigned int dwarf_abbrev_size; |
c906108c | 368 | |
c5aa993b | 369 | /* Pointer to start of dwarf line buffer for the objfile. */ |
c906108c | 370 | |
c5aa993b JM |
371 | char *dwarf_line_buffer; |
372 | }; | |
c906108c SS |
373 | |
374 | #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private) | |
375 | #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer) | |
376 | #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset) | |
377 | #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer) | |
378 | #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size) | |
379 | #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer) | |
380 | ||
381 | /* Maintain an array of referenced fundamental types for the current | |
382 | compilation unit being read. For DWARF version 1, we have to construct | |
383 | the fundamental types on the fly, since no information about the | |
384 | fundamental types is supplied. Each such fundamental type is created by | |
385 | calling a language dependent routine to create the type, and then a | |
386 | pointer to that type is then placed in the array at the index specified | |
387 | by it's FT_<TYPENAME> value. The array has a fixed size set by the | |
388 | FT_NUM_MEMBERS compile time constant, which is the number of predefined | |
389 | fundamental types gdb knows how to construct. */ | |
390 | static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ | |
391 | ||
392 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, | |
393 | but this would require a corresponding change in unpack_field_as_long | |
394 | and friends. */ | |
395 | static int bits_per_byte = 8; | |
396 | ||
397 | /* The routines that read and process dies for a C struct or C++ class | |
398 | pass lists of data member fields and lists of member function fields | |
399 | in an instance of a field_info structure, as defined below. */ | |
400 | struct field_info | |
c5aa993b JM |
401 | { |
402 | /* List of data member and baseclasses fields. */ | |
403 | struct nextfield | |
404 | { | |
405 | struct nextfield *next; | |
406 | int accessibility; | |
407 | int virtuality; | |
408 | struct field field; | |
409 | } | |
410 | *fields; | |
c906108c | 411 | |
c5aa993b JM |
412 | /* Number of fields. */ |
413 | int nfields; | |
c906108c | 414 | |
c5aa993b JM |
415 | /* Number of baseclasses. */ |
416 | int nbaseclasses; | |
c906108c | 417 | |
c5aa993b JM |
418 | /* Set if the accesibility of one of the fields is not public. */ |
419 | int non_public_fields; | |
c906108c | 420 | |
c5aa993b JM |
421 | /* Member function fields array, entries are allocated in the order they |
422 | are encountered in the object file. */ | |
423 | struct nextfnfield | |
424 | { | |
425 | struct nextfnfield *next; | |
426 | struct fn_field fnfield; | |
427 | } | |
428 | *fnfields; | |
c906108c | 429 | |
c5aa993b JM |
430 | /* Member function fieldlist array, contains name of possibly overloaded |
431 | member function, number of overloaded member functions and a pointer | |
432 | to the head of the member function field chain. */ | |
433 | struct fnfieldlist | |
434 | { | |
435 | char *name; | |
436 | int length; | |
437 | struct nextfnfield *head; | |
438 | } | |
439 | *fnfieldlists; | |
c906108c | 440 | |
c5aa993b JM |
441 | /* Number of entries in the fnfieldlists array. */ |
442 | int nfnfields; | |
443 | }; | |
c906108c SS |
444 | |
445 | /* FIXME: Kludge to mark a varargs function type for C++ member function | |
446 | argument processing. */ | |
447 | #define TYPE_FLAG_VARARGS (1 << 10) | |
448 | ||
449 | /* Dwarf2 has no clean way to discern C++ static and non-static member | |
450 | functions. G++ helps GDB by marking the first parameter for non-static | |
451 | member functions (which is the this pointer) as artificial. | |
452 | We pass this information between dwarf2_add_member_fn and | |
453 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
454 | #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS | |
455 | ||
456 | /* Various complaints about symbol reading that don't abort the process */ | |
457 | ||
458 | static struct complaint dwarf2_const_ignored = | |
459 | { | |
460 | "type qualifier 'const' ignored", 0, 0 | |
461 | }; | |
462 | static struct complaint dwarf2_volatile_ignored = | |
463 | { | |
464 | "type qualifier 'volatile' ignored", 0, 0 | |
465 | }; | |
466 | static struct complaint dwarf2_non_const_array_bound_ignored = | |
467 | { | |
468 | "non-constant array bounds form '%s' ignored", 0, 0 | |
469 | }; | |
470 | static struct complaint dwarf2_missing_line_number_section = | |
471 | { | |
472 | "missing .debug_line section", 0, 0 | |
473 | }; | |
474 | static struct complaint dwarf2_mangled_line_number_section = | |
475 | { | |
476 | "mangled .debug_line section", 0, 0 | |
477 | }; | |
478 | static struct complaint dwarf2_unsupported_die_ref_attr = | |
479 | { | |
480 | "unsupported die ref attribute form: '%s'", 0, 0 | |
481 | }; | |
482 | static struct complaint dwarf2_unsupported_stack_op = | |
483 | { | |
484 | "unsupported stack op: '%s'", 0, 0 | |
485 | }; | |
7a292a7a SS |
486 | static struct complaint dwarf2_complex_location_expr = |
487 | { | |
488 | "location expression too complex", 0, 0 | |
489 | }; | |
c906108c SS |
490 | static struct complaint dwarf2_unsupported_tag = |
491 | { | |
492 | "unsupported tag: '%s'", 0, 0 | |
493 | }; | |
494 | static struct complaint dwarf2_unsupported_at_encoding = | |
495 | { | |
496 | "unsupported DW_AT_encoding: '%s'", 0, 0 | |
497 | }; | |
498 | static struct complaint dwarf2_unsupported_at_frame_base = | |
499 | { | |
500 | "unsupported DW_AT_frame_base for function '%s'", 0, 0 | |
501 | }; | |
502 | static struct complaint dwarf2_unexpected_tag = | |
503 | { | |
504 | "unexepected tag in read_type_die: '%s'", 0, 0 | |
505 | }; | |
506 | static struct complaint dwarf2_missing_at_frame_base = | |
507 | { | |
508 | "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0 | |
509 | }; | |
510 | static struct complaint dwarf2_bad_static_member_name = | |
511 | { | |
512 | "unrecognized static data member name '%s'", 0, 0 | |
513 | }; | |
514 | static struct complaint dwarf2_unsupported_accessibility = | |
515 | { | |
516 | "unsupported accessibility %d", 0, 0 | |
517 | }; | |
518 | static struct complaint dwarf2_bad_member_name_complaint = | |
519 | { | |
520 | "cannot extract member name from '%s'", 0, 0 | |
521 | }; | |
522 | static struct complaint dwarf2_missing_member_fn_type_complaint = | |
523 | { | |
524 | "member function type missing for '%s'", 0, 0 | |
525 | }; | |
526 | static struct complaint dwarf2_vtbl_not_found_complaint = | |
527 | { | |
528 | "virtual function table pointer not found when defining class '%s'", 0, 0 | |
529 | }; | |
530 | static struct complaint dwarf2_absolute_sibling_complaint = | |
531 | { | |
532 | "ignoring absolute DW_AT_sibling", 0, 0 | |
533 | }; | |
534 | static struct complaint dwarf2_const_value_length_mismatch = | |
535 | { | |
536 | "const value length mismatch for '%s', got %d, expected %d", 0, 0 | |
537 | }; | |
538 | static struct complaint dwarf2_unsupported_const_value_attr = | |
539 | { | |
540 | "unsupported const value attribute form: '%s'", 0, 0 | |
541 | }; | |
542 | ||
543 | /* Remember the addr_size read from the dwarf. | |
544 | If a target expects to link compilation units with differing address | |
545 | sizes, gdb needs to be sure that the appropriate size is here for | |
546 | whatever scope is currently getting read. */ | |
547 | static int address_size; | |
548 | ||
549 | /* Some elf32 object file formats while linked for a 32 bit address | |
550 | space contain debug information that has assumed 64 bit | |
551 | addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the | |
552 | symbol table contains 32bit address values while its .debug_info | |
553 | section contains 64 bit address values. | |
554 | ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in | |
555 | the ADDRESS_SIZE bytes read from the file */ | |
556 | static int address_significant_size; | |
557 | ||
558 | /* Externals references. */ | |
559 | extern int info_verbose; /* From main.c; nonzero => verbose */ | |
560 | ||
561 | /* local function prototypes */ | |
562 | ||
563 | static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR)); | |
564 | ||
565 | #if 0 | |
d4f3574e | 566 | static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *, int)); |
c906108c SS |
567 | #endif |
568 | ||
d4f3574e | 569 | static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *, int)); |
c906108c SS |
570 | |
571 | static char *scan_partial_symbols PARAMS ((char *, struct objfile *, | |
572 | CORE_ADDR *, CORE_ADDR *)); | |
573 | ||
574 | static void add_partial_symbol PARAMS ((struct partial_die_info *, | |
575 | struct objfile *)); | |
576 | ||
577 | static void dwarf2_psymtab_to_symtab PARAMS ((struct partial_symtab *)); | |
578 | ||
579 | static void psymtab_to_symtab_1 PARAMS ((struct partial_symtab *)); | |
580 | ||
581 | static char *dwarf2_read_section PARAMS ((struct objfile *, file_ptr, | |
582 | unsigned int)); | |
583 | ||
584 | static void dwarf2_read_abbrevs PARAMS ((bfd *, unsigned int)); | |
585 | ||
586 | static void dwarf2_empty_abbrev_table PARAMS ((PTR)); | |
587 | ||
588 | static struct abbrev_info *dwarf2_lookup_abbrev PARAMS ((unsigned int)); | |
589 | ||
590 | static char *read_partial_die PARAMS ((struct partial_die_info *, | |
591 | bfd *, char *, int *)); | |
592 | ||
593 | static char *read_full_die PARAMS ((struct die_info **, bfd *, char *)); | |
594 | ||
595 | static char *read_attribute PARAMS ((struct attribute *, struct attr_abbrev *, | |
596 | bfd *, char *)); | |
597 | ||
598 | static unsigned int read_1_byte PARAMS ((bfd *, char *)); | |
599 | ||
600 | static int read_1_signed_byte PARAMS ((bfd *, char *)); | |
601 | ||
602 | static unsigned int read_2_bytes PARAMS ((bfd *, char *)); | |
603 | ||
604 | static unsigned int read_4_bytes PARAMS ((bfd *, char *)); | |
605 | ||
606 | static unsigned int read_8_bytes PARAMS ((bfd *, char *)); | |
607 | ||
608 | static CORE_ADDR read_address PARAMS ((bfd *, char *)); | |
609 | ||
610 | static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int)); | |
611 | ||
612 | static char *read_string PARAMS ((bfd *, char *, unsigned int *)); | |
613 | ||
614 | static unsigned int read_unsigned_leb128 PARAMS ((bfd *, char *, | |
615 | unsigned int *)); | |
616 | ||
617 | static int read_signed_leb128 PARAMS ((bfd *, char *, unsigned int *)); | |
618 | ||
619 | static void set_cu_language PARAMS ((unsigned int)); | |
620 | ||
621 | static struct attribute *dwarf_attr PARAMS ((struct die_info *, | |
622 | unsigned int)); | |
623 | ||
624 | static void dwarf_decode_lines PARAMS ((unsigned int, char *, bfd *)); | |
625 | ||
626 | static void dwarf2_start_subfile PARAMS ((char *, char *)); | |
627 | ||
628 | static struct symbol *new_symbol PARAMS ((struct die_info *, struct type *, | |
629 | struct objfile *)); | |
630 | ||
631 | static void dwarf2_const_value PARAMS ((struct attribute *, struct symbol *, | |
632 | struct objfile *)); | |
633 | ||
634 | static struct type *die_type PARAMS ((struct die_info *, struct objfile *)); | |
635 | ||
636 | static struct type *die_containing_type PARAMS ((struct die_info *, | |
637 | struct objfile *)); | |
638 | ||
639 | #if 0 | |
640 | static struct type *type_at_offset PARAMS ((unsigned int, struct objfile *)); | |
641 | #endif | |
642 | ||
643 | static struct type *tag_type_to_type PARAMS ((struct die_info *, | |
644 | struct objfile *)); | |
645 | ||
646 | static void read_type_die PARAMS ((struct die_info *, struct objfile *)); | |
647 | ||
648 | static void read_typedef PARAMS ((struct die_info *, struct objfile *)); | |
649 | ||
650 | static void read_base_type PARAMS ((struct die_info *, struct objfile *)); | |
651 | ||
652 | static void read_file_scope PARAMS ((struct die_info *, struct objfile *)); | |
653 | ||
654 | static void read_func_scope PARAMS ((struct die_info *, struct objfile *)); | |
655 | ||
656 | static void read_lexical_block_scope PARAMS ((struct die_info *, | |
657 | struct objfile *)); | |
658 | ||
659 | static int dwarf2_get_pc_bounds PARAMS ((struct die_info *, | |
660 | CORE_ADDR *, CORE_ADDR *, | |
661 | struct objfile *)); | |
662 | ||
663 | static void dwarf2_add_field PARAMS ((struct field_info *, struct die_info *, | |
664 | struct objfile *)); | |
665 | ||
666 | static void dwarf2_attach_fields_to_type PARAMS ((struct field_info *, | |
c5aa993b | 667 | struct type *, |
c906108c SS |
668 | struct objfile *)); |
669 | ||
670 | static char *skip_member_fn_name PARAMS ((char *)); | |
671 | ||
672 | static void dwarf2_add_member_fn PARAMS ((struct field_info *, | |
673 | struct die_info *, struct type *, | |
c5aa993b | 674 | struct objfile * objfile)); |
c906108c SS |
675 | |
676 | static void dwarf2_attach_fn_fields_to_type PARAMS ((struct field_info *, | |
677 | struct type *, | |
678 | struct objfile *)); | |
679 | ||
680 | static void read_structure_scope PARAMS ((struct die_info *, struct objfile *)); | |
681 | ||
682 | static void read_common_block PARAMS ((struct die_info *, struct objfile *)); | |
683 | ||
684 | static void read_enumeration PARAMS ((struct die_info *, struct objfile *)); | |
685 | ||
686 | static struct type *dwarf_base_type PARAMS ((int, int, struct objfile *)); | |
687 | ||
688 | static CORE_ADDR decode_locdesc PARAMS ((struct dwarf_block *, | |
689 | struct objfile *)); | |
690 | ||
691 | static void read_array_type PARAMS ((struct die_info *, struct objfile *)); | |
692 | ||
693 | static void read_tag_pointer_type PARAMS ((struct die_info *, | |
694 | struct objfile *)); | |
695 | ||
696 | static void read_tag_ptr_to_member_type PARAMS ((struct die_info *, | |
697 | struct objfile *)); | |
698 | ||
699 | static void read_tag_reference_type PARAMS ((struct die_info *, | |
700 | struct objfile *)); | |
701 | ||
702 | static void read_tag_const_type PARAMS ((struct die_info *, struct objfile *)); | |
703 | ||
704 | static void read_tag_volatile_type PARAMS ((struct die_info *, | |
705 | struct objfile *)); | |
706 | ||
707 | static void read_tag_string_type PARAMS ((struct die_info *, | |
708 | struct objfile *)); | |
709 | ||
710 | static void read_subroutine_type PARAMS ((struct die_info *, | |
711 | struct objfile *)); | |
712 | ||
713 | struct die_info *read_comp_unit PARAMS ((char *, bfd *)); | |
714 | ||
715 | static void free_die_list PARAMS ((struct die_info *)); | |
716 | ||
717 | static void process_die PARAMS ((struct die_info *, struct objfile *)); | |
718 | ||
719 | static char *dwarf2_linkage_name PARAMS ((struct die_info *)); | |
720 | ||
721 | static char *dwarf_tag_name PARAMS ((unsigned int)); | |
722 | ||
723 | static char *dwarf_attr_name PARAMS ((unsigned int)); | |
724 | ||
725 | static char *dwarf_form_name PARAMS ((unsigned int)); | |
726 | ||
727 | static char *dwarf_stack_op_name PARAMS ((unsigned int)); | |
728 | ||
729 | static char *dwarf_bool_name PARAMS ((unsigned int)); | |
730 | ||
731 | static char *dwarf_type_encoding_name PARAMS ((unsigned int)); | |
732 | ||
733 | #if 0 | |
734 | static char *dwarf_cfi_name PARAMS ((unsigned int)); | |
735 | ||
736 | struct die_info *copy_die PARAMS ((struct die_info *)); | |
737 | #endif | |
738 | ||
739 | struct die_info *sibling_die PARAMS ((struct die_info *)); | |
740 | ||
741 | void dump_die PARAMS ((struct die_info *)); | |
742 | ||
743 | void dump_die_list PARAMS ((struct die_info *)); | |
744 | ||
745 | void store_in_ref_table PARAMS ((unsigned int, struct die_info *)); | |
746 | ||
747 | static void dwarf2_empty_die_ref_table PARAMS ((void)); | |
748 | ||
749 | static unsigned int dwarf2_get_ref_die_offset PARAMS ((struct attribute *)); | |
750 | ||
751 | struct die_info *follow_die_ref PARAMS ((unsigned int)); | |
752 | ||
753 | static struct type *dwarf2_fundamental_type PARAMS ((struct objfile *, int)); | |
754 | ||
755 | /* memory allocation interface */ | |
756 | ||
757 | static void dwarf2_free_tmp_obstack PARAMS ((PTR)); | |
758 | ||
759 | static struct dwarf_block *dwarf_alloc_block PARAMS ((void)); | |
760 | ||
761 | static struct abbrev_info *dwarf_alloc_abbrev PARAMS ((void)); | |
762 | ||
763 | static struct die_info *dwarf_alloc_die PARAMS ((void)); | |
764 | ||
765 | /* Try to locate the sections we need for DWARF 2 debugging | |
766 | information and return true if we have enough to do something. */ | |
767 | ||
768 | int | |
769 | dwarf2_has_info (abfd) | |
770 | bfd *abfd; | |
771 | { | |
772 | dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0; | |
773 | bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL); | |
774 | if (dwarf_info_offset && dwarf_abbrev_offset) | |
775 | { | |
776 | return 1; | |
777 | } | |
778 | else | |
779 | { | |
780 | return 0; | |
781 | } | |
782 | } | |
783 | ||
784 | /* This function is mapped across the sections and remembers the | |
785 | offset and size of each of the debugging sections we are interested | |
786 | in. */ | |
787 | ||
788 | static void | |
789 | dwarf2_locate_sections (ignore_abfd, sectp, ignore_ptr) | |
790 | bfd *ignore_abfd; | |
791 | asection *sectp; | |
792 | PTR ignore_ptr; | |
793 | { | |
794 | if (STREQ (sectp->name, INFO_SECTION)) | |
795 | { | |
796 | dwarf_info_offset = sectp->filepos; | |
797 | dwarf_info_size = bfd_get_section_size_before_reloc (sectp); | |
798 | } | |
799 | else if (STREQ (sectp->name, ABBREV_SECTION)) | |
800 | { | |
801 | dwarf_abbrev_offset = sectp->filepos; | |
802 | dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp); | |
803 | } | |
804 | else if (STREQ (sectp->name, LINE_SECTION)) | |
805 | { | |
806 | dwarf_line_offset = sectp->filepos; | |
807 | dwarf_line_size = bfd_get_section_size_before_reloc (sectp); | |
808 | } | |
809 | else if (STREQ (sectp->name, PUBNAMES_SECTION)) | |
810 | { | |
811 | dwarf_pubnames_offset = sectp->filepos; | |
812 | dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp); | |
813 | } | |
814 | else if (STREQ (sectp->name, ARANGES_SECTION)) | |
815 | { | |
816 | dwarf_aranges_offset = sectp->filepos; | |
817 | dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp); | |
818 | } | |
819 | else if (STREQ (sectp->name, LOC_SECTION)) | |
820 | { | |
821 | dwarf_loc_offset = sectp->filepos; | |
822 | dwarf_loc_size = bfd_get_section_size_before_reloc (sectp); | |
823 | } | |
824 | else if (STREQ (sectp->name, MACINFO_SECTION)) | |
825 | { | |
826 | dwarf_macinfo_offset = sectp->filepos; | |
827 | dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp); | |
828 | } | |
829 | else if (STREQ (sectp->name, STR_SECTION)) | |
830 | { | |
831 | dwarf_str_offset = sectp->filepos; | |
832 | dwarf_str_size = bfd_get_section_size_before_reloc (sectp); | |
833 | } | |
834 | } | |
835 | ||
836 | /* Build a partial symbol table. */ | |
837 | ||
838 | void | |
d4f3574e | 839 | dwarf2_build_psymtabs (objfile, mainline) |
c5aa993b | 840 | struct objfile *objfile; |
c5aa993b | 841 | int mainline; |
c906108c SS |
842 | { |
843 | ||
844 | /* We definitely need the .debug_info and .debug_abbrev sections */ | |
845 | ||
846 | dwarf_info_buffer = dwarf2_read_section (objfile, | |
847 | dwarf_info_offset, | |
848 | dwarf_info_size); | |
849 | dwarf_abbrev_buffer = dwarf2_read_section (objfile, | |
850 | dwarf_abbrev_offset, | |
851 | dwarf_abbrev_size); | |
852 | dwarf_line_buffer = dwarf2_read_section (objfile, | |
853 | dwarf_line_offset, | |
854 | dwarf_line_size); | |
855 | ||
856 | if (mainline || objfile->global_psymbols.size == 0 || | |
857 | objfile->static_psymbols.size == 0) | |
858 | { | |
859 | init_psymbol_list (objfile, 1024); | |
860 | } | |
861 | ||
862 | #if 0 | |
863 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
864 | { | |
d4f3574e | 865 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
866 | .debug_pubnames sections */ |
867 | ||
d4f3574e | 868 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
869 | } |
870 | else | |
871 | #endif | |
872 | /* only test this case for now */ | |
c5aa993b | 873 | { |
c906108c | 874 | /* In this case we have to work a bit harder */ |
d4f3574e | 875 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
876 | } |
877 | } | |
878 | ||
879 | #if 0 | |
880 | /* Build the partial symbol table from the information in the | |
881 | .debug_pubnames and .debug_aranges sections. */ | |
882 | ||
883 | static void | |
d4f3574e | 884 | dwarf2_build_psymtabs_easy (objfile, mainline) |
c906108c | 885 | struct objfile *objfile; |
c906108c SS |
886 | int mainline; |
887 | { | |
888 | bfd *abfd = objfile->obfd; | |
889 | char *aranges_buffer, *pubnames_buffer; | |
890 | char *aranges_ptr, *pubnames_ptr; | |
891 | unsigned int entry_length, version, info_offset, info_size; | |
892 | ||
893 | pubnames_buffer = dwarf2_read_section (objfile, | |
894 | dwarf_pubnames_offset, | |
895 | dwarf_pubnames_size); | |
896 | pubnames_ptr = pubnames_buffer; | |
897 | while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size) | |
898 | { | |
899 | entry_length = read_4_bytes (abfd, pubnames_ptr); | |
900 | pubnames_ptr += 4; | |
901 | version = read_1_byte (abfd, pubnames_ptr); | |
902 | pubnames_ptr += 1; | |
903 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
904 | pubnames_ptr += 4; | |
905 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
906 | pubnames_ptr += 4; | |
907 | } | |
908 | ||
909 | aranges_buffer = dwarf2_read_section (objfile, | |
910 | dwarf_aranges_offset, | |
911 | dwarf_aranges_size); | |
912 | ||
913 | } | |
914 | #endif | |
915 | ||
916 | /* Build the partial symbol table by doing a quick pass through the | |
917 | .debug_info and .debug_abbrev sections. */ | |
918 | ||
919 | static void | |
d4f3574e | 920 | dwarf2_build_psymtabs_hard (objfile, mainline) |
c906108c | 921 | struct objfile *objfile; |
c906108c SS |
922 | int mainline; |
923 | { | |
924 | /* Instead of reading this into a big buffer, we should probably use | |
925 | mmap() on architectures that support it. (FIXME) */ | |
926 | bfd *abfd = objfile->obfd; | |
927 | char *info_ptr, *abbrev_ptr; | |
928 | char *beg_of_comp_unit; | |
929 | struct comp_unit_head cu_header; | |
930 | struct partial_die_info comp_unit_die; | |
931 | struct partial_symtab *pst; | |
932 | struct cleanup *back_to; | |
933 | int comp_unit_has_pc_info; | |
934 | CORE_ADDR lowpc, highpc; | |
935 | ||
936 | /* Number of bytes of any addresses that are signficant */ | |
937 | address_significant_size = get_elf_backend_data (abfd)->s->arch_size / 8; | |
938 | ||
939 | info_ptr = dwarf_info_buffer; | |
940 | abbrev_ptr = dwarf_abbrev_buffer; | |
941 | ||
942 | obstack_init (&dwarf2_tmp_obstack); | |
943 | back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); | |
944 | ||
945 | while ((unsigned int) (info_ptr - dwarf_info_buffer) | |
c5aa993b | 946 | + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size) |
c906108c SS |
947 | { |
948 | beg_of_comp_unit = info_ptr; | |
949 | cu_header.length = read_4_bytes (abfd, info_ptr); | |
950 | info_ptr += 4; | |
951 | cu_header.version = read_2_bytes (abfd, info_ptr); | |
952 | info_ptr += 2; | |
953 | cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr); | |
954 | info_ptr += 4; | |
955 | cu_header.addr_size = read_1_byte (abfd, info_ptr); | |
956 | info_ptr += 1; | |
957 | address_size = cu_header.addr_size; | |
958 | ||
959 | if (cu_header.version != 2) | |
960 | { | |
961 | error ("Dwarf Error: wrong version in compilation unit header."); | |
962 | return; | |
963 | } | |
964 | if (cu_header.abbrev_offset >= dwarf_abbrev_size) | |
965 | { | |
966 | error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).", | |
967 | (long) cu_header.abbrev_offset, | |
968 | (long) (beg_of_comp_unit - dwarf_info_buffer)); | |
969 | return; | |
970 | } | |
971 | if (beg_of_comp_unit + cu_header.length + 4 | |
972 | > dwarf_info_buffer + dwarf_info_size) | |
973 | { | |
974 | error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).", | |
975 | (long) cu_header.length, | |
976 | (long) (beg_of_comp_unit - dwarf_info_buffer)); | |
977 | return; | |
978 | } | |
979 | if (address_size < address_significant_size) | |
980 | { | |
981 | error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).", | |
982 | (long) cu_header.addr_size, | |
983 | (long) (beg_of_comp_unit - dwarf_info_buffer)); | |
984 | } | |
985 | ||
986 | /* Read the abbrevs for this compilation unit into a table */ | |
987 | dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset); | |
988 | make_cleanup (dwarf2_empty_abbrev_table, NULL); | |
989 | ||
990 | /* Read the compilation unit die */ | |
991 | info_ptr = read_partial_die (&comp_unit_die, abfd, | |
992 | info_ptr, &comp_unit_has_pc_info); | |
993 | ||
994 | /* Set the language we're debugging */ | |
995 | set_cu_language (comp_unit_die.language); | |
996 | ||
997 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 998 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 999 | comp_unit_die.name ? comp_unit_die.name : "", |
c906108c SS |
1000 | comp_unit_die.lowpc, |
1001 | objfile->global_psymbols.next, | |
1002 | objfile->static_psymbols.next); | |
1003 | ||
1004 | pst->read_symtab_private = (char *) | |
1005 | obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo)); | |
1006 | cu_header_offset = beg_of_comp_unit - dwarf_info_buffer; | |
c5aa993b JM |
1007 | DWARF_INFO_BUFFER (pst) = dwarf_info_buffer; |
1008 | DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer; | |
1009 | DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer; | |
1010 | DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size; | |
1011 | DWARF_LINE_BUFFER (pst) = dwarf_line_buffer; | |
d4f3574e | 1012 | baseaddr = ANOFFSET (objfile->section_offsets, 0); |
c906108c SS |
1013 | |
1014 | /* Store the function that reads in the rest of the symbol table */ | |
1015 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1016 | ||
1017 | /* Check if comp unit has_children. | |
1018 | If so, read the rest of the partial symbols from this comp unit. | |
1019 | If not, there's no more debug_info for this comp unit. */ | |
1020 | if (comp_unit_die.has_children) | |
1021 | { | |
1022 | info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc); | |
1023 | ||
1024 | /* If the compilation unit didn't have an explicit address range, | |
1025 | then use the information extracted from its child dies. */ | |
1026 | if (!comp_unit_has_pc_info) | |
1027 | { | |
c5aa993b | 1028 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1029 | comp_unit_die.highpc = highpc; |
1030 | } | |
1031 | } | |
c5aa993b | 1032 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1033 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1034 | ||
1035 | pst->n_global_syms = objfile->global_psymbols.next - | |
1036 | (objfile->global_psymbols.list + pst->globals_offset); | |
1037 | pst->n_static_syms = objfile->static_psymbols.next - | |
1038 | (objfile->static_psymbols.list + pst->statics_offset); | |
1039 | sort_pst_symbols (pst); | |
1040 | ||
1041 | /* If there is already a psymtab or symtab for a file of this | |
1042 | name, remove it. (If there is a symtab, more drastic things | |
1043 | also happen.) This happens in VxWorks. */ | |
1044 | free_named_symtabs (pst->filename); | |
1045 | ||
1046 | info_ptr = beg_of_comp_unit + cu_header.length + 4; | |
1047 | } | |
1048 | do_cleanups (back_to); | |
1049 | } | |
1050 | ||
1051 | /* Read in all interesting dies to the end of the compilation unit. */ | |
1052 | ||
1053 | static char * | |
1054 | scan_partial_symbols (info_ptr, objfile, lowpc, highpc) | |
1055 | char *info_ptr; | |
1056 | struct objfile *objfile; | |
1057 | CORE_ADDR *lowpc; | |
1058 | CORE_ADDR *highpc; | |
1059 | { | |
1060 | bfd *abfd = objfile->obfd; | |
1061 | struct partial_die_info pdi; | |
1062 | ||
1063 | /* This function is called after we've read in the comp_unit_die in | |
1064 | order to read its children. We start the nesting level at 1 since | |
1065 | we have pushed 1 level down in order to read the comp unit's children. | |
1066 | The comp unit itself is at level 0, so we stop reading when we pop | |
1067 | back to that level. */ | |
1068 | ||
1069 | int nesting_level = 1; | |
1070 | int has_pc_info; | |
c5aa993b JM |
1071 | |
1072 | *lowpc = ((CORE_ADDR) - 1); | |
c906108c SS |
1073 | *highpc = ((CORE_ADDR) 0); |
1074 | ||
1075 | while (nesting_level) | |
1076 | { | |
1077 | info_ptr = read_partial_die (&pdi, abfd, info_ptr, &has_pc_info); | |
1078 | ||
1079 | if (pdi.name) | |
1080 | { | |
1081 | switch (pdi.tag) | |
1082 | { | |
1083 | case DW_TAG_subprogram: | |
1084 | if (has_pc_info) | |
1085 | { | |
1086 | if (pdi.lowpc < *lowpc) | |
1087 | { | |
1088 | *lowpc = pdi.lowpc; | |
1089 | } | |
1090 | if (pdi.highpc > *highpc) | |
1091 | { | |
1092 | *highpc = pdi.highpc; | |
1093 | } | |
1094 | if ((pdi.is_external || nesting_level == 1) | |
1095 | && !pdi.is_declaration) | |
1096 | { | |
1097 | add_partial_symbol (&pdi, objfile); | |
1098 | } | |
1099 | } | |
1100 | break; | |
1101 | case DW_TAG_variable: | |
1102 | case DW_TAG_typedef: | |
1103 | case DW_TAG_class_type: | |
1104 | case DW_TAG_structure_type: | |
1105 | case DW_TAG_union_type: | |
1106 | case DW_TAG_enumeration_type: | |
1107 | if ((pdi.is_external || nesting_level == 1) | |
1108 | && !pdi.is_declaration) | |
1109 | { | |
1110 | add_partial_symbol (&pdi, objfile); | |
1111 | } | |
1112 | break; | |
1113 | case DW_TAG_enumerator: | |
1114 | /* File scope enumerators are added to the partial symbol | |
c5aa993b | 1115 | table. */ |
c906108c SS |
1116 | if (nesting_level == 2) |
1117 | add_partial_symbol (&pdi, objfile); | |
1118 | break; | |
1119 | case DW_TAG_base_type: | |
1120 | /* File scope base type definitions are added to the partial | |
c5aa993b | 1121 | symbol table. */ |
c906108c SS |
1122 | if (nesting_level == 1) |
1123 | add_partial_symbol (&pdi, objfile); | |
1124 | break; | |
1125 | default: | |
1126 | break; | |
1127 | } | |
1128 | } | |
1129 | ||
1130 | /* If the die has a sibling, skip to the sibling. | |
c5aa993b JM |
1131 | Do not skip enumeration types, we want to record their |
1132 | enumerators. */ | |
c906108c SS |
1133 | if (pdi.sibling && pdi.tag != DW_TAG_enumeration_type) |
1134 | { | |
1135 | info_ptr = pdi.sibling; | |
1136 | } | |
1137 | else if (pdi.has_children) | |
1138 | { | |
1139 | /* Die has children, but the optional DW_AT_sibling attribute | |
1140 | is missing. */ | |
1141 | nesting_level++; | |
1142 | } | |
1143 | ||
1144 | if (pdi.tag == 0) | |
1145 | { | |
1146 | nesting_level--; | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
1151 | from `maint check'. */ | |
c5aa993b | 1152 | if (*lowpc == ((CORE_ADDR) - 1)) |
c906108c SS |
1153 | *lowpc = *highpc; |
1154 | return info_ptr; | |
1155 | } | |
1156 | ||
1157 | static void | |
1158 | add_partial_symbol (pdi, objfile) | |
1159 | struct partial_die_info *pdi; | |
1160 | struct objfile *objfile; | |
1161 | { | |
1162 | CORE_ADDR addr = 0; | |
1163 | ||
1164 | switch (pdi->tag) | |
1165 | { | |
1166 | case DW_TAG_subprogram: | |
1167 | if (pdi->is_external) | |
1168 | { | |
1169 | /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr, | |
c5aa993b | 1170 | mst_text, objfile); */ |
c906108c SS |
1171 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
1172 | VAR_NAMESPACE, LOC_BLOCK, | |
1173 | &objfile->global_psymbols, | |
c5aa993b | 1174 | 0, pdi->lowpc + baseaddr, cu_language, objfile); |
c906108c SS |
1175 | } |
1176 | else | |
1177 | { | |
1178 | /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr, | |
c5aa993b | 1179 | mst_file_text, objfile); */ |
c906108c SS |
1180 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
1181 | VAR_NAMESPACE, LOC_BLOCK, | |
1182 | &objfile->static_psymbols, | |
c5aa993b | 1183 | 0, pdi->lowpc + baseaddr, cu_language, objfile); |
c906108c SS |
1184 | } |
1185 | break; | |
1186 | case DW_TAG_variable: | |
1187 | if (pdi->is_external) | |
1188 | { | |
1189 | /* Global Variable. | |
1190 | Don't enter into the minimal symbol tables as there is | |
1191 | a minimal symbol table entry from the ELF symbols already. | |
1192 | Enter into partial symbol table if it has a location | |
1193 | descriptor or a type. | |
1194 | If the location descriptor is missing, new_symbol will create | |
1195 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
1196 | be determined from the minimal symbol table whenever the variable | |
1197 | is referenced. | |
1198 | The address for the partial symbol table entry is not | |
1199 | used by GDB, but it comes in handy for debugging partial symbol | |
1200 | table building. */ | |
1201 | ||
1202 | if (pdi->locdesc) | |
1203 | addr = decode_locdesc (pdi->locdesc, objfile); | |
1204 | if (pdi->locdesc || pdi->has_type) | |
1205 | add_psymbol_to_list (pdi->name, strlen (pdi->name), | |
1206 | VAR_NAMESPACE, LOC_STATIC, | |
1207 | &objfile->global_psymbols, | |
1208 | 0, addr + baseaddr, cu_language, objfile); | |
1209 | } | |
1210 | else | |
1211 | { | |
1212 | /* Static Variable. Skip symbols without location descriptors. */ | |
1213 | if (pdi->locdesc == NULL) | |
1214 | return; | |
1215 | addr = decode_locdesc (pdi->locdesc, objfile); | |
1216 | /*prim_record_minimal_symbol (pdi->name, addr + baseaddr, | |
c5aa993b | 1217 | mst_file_data, objfile); */ |
c906108c SS |
1218 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
1219 | VAR_NAMESPACE, LOC_STATIC, | |
1220 | &objfile->static_psymbols, | |
1221 | 0, addr + baseaddr, cu_language, objfile); | |
1222 | } | |
1223 | break; | |
1224 | case DW_TAG_typedef: | |
1225 | case DW_TAG_base_type: | |
1226 | add_psymbol_to_list (pdi->name, strlen (pdi->name), | |
1227 | VAR_NAMESPACE, LOC_TYPEDEF, | |
1228 | &objfile->static_psymbols, | |
1229 | 0, (CORE_ADDR) 0, cu_language, objfile); | |
1230 | break; | |
1231 | case DW_TAG_class_type: | |
1232 | case DW_TAG_structure_type: | |
1233 | case DW_TAG_union_type: | |
1234 | case DW_TAG_enumeration_type: | |
1235 | /* Skip aggregate types without children, these are external | |
c5aa993b | 1236 | references. */ |
c906108c SS |
1237 | if (pdi->has_children == 0) |
1238 | return; | |
1239 | add_psymbol_to_list (pdi->name, strlen (pdi->name), | |
1240 | STRUCT_NAMESPACE, LOC_TYPEDEF, | |
1241 | &objfile->static_psymbols, | |
1242 | 0, (CORE_ADDR) 0, cu_language, objfile); | |
1243 | ||
1244 | if (cu_language == language_cplus) | |
1245 | { | |
1246 | /* For C++, these implicitly act as typedefs as well. */ | |
1247 | add_psymbol_to_list (pdi->name, strlen (pdi->name), | |
1248 | VAR_NAMESPACE, LOC_TYPEDEF, | |
1249 | &objfile->static_psymbols, | |
1250 | 0, (CORE_ADDR) 0, cu_language, objfile); | |
1251 | } | |
1252 | break; | |
1253 | case DW_TAG_enumerator: | |
1254 | add_psymbol_to_list (pdi->name, strlen (pdi->name), | |
1255 | VAR_NAMESPACE, LOC_CONST, | |
1256 | &objfile->static_psymbols, | |
1257 | 0, (CORE_ADDR) 0, cu_language, objfile); | |
1258 | break; | |
1259 | default: | |
1260 | break; | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | /* Expand this partial symbol table into a full symbol table. */ | |
1265 | ||
1266 | static void | |
1267 | dwarf2_psymtab_to_symtab (pst) | |
1268 | struct partial_symtab *pst; | |
1269 | { | |
1270 | /* FIXME: This is barely more than a stub. */ | |
1271 | if (pst != NULL) | |
1272 | { | |
1273 | if (pst->readin) | |
1274 | { | |
1275 | warning ("bug: psymtab for %s is already read in.", pst->filename); | |
1276 | } | |
1277 | else | |
1278 | { | |
1279 | if (info_verbose) | |
1280 | { | |
1281 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
1282 | gdb_flush (gdb_stdout); | |
1283 | } | |
1284 | ||
1285 | psymtab_to_symtab_1 (pst); | |
1286 | ||
1287 | /* Finish up the debug error message. */ | |
1288 | if (info_verbose) | |
1289 | printf_filtered ("done.\n"); | |
1290 | } | |
1291 | } | |
1292 | } | |
1293 | ||
1294 | static void | |
1295 | psymtab_to_symtab_1 (pst) | |
1296 | struct partial_symtab *pst; | |
1297 | { | |
1298 | struct objfile *objfile = pst->objfile; | |
1299 | bfd *abfd = objfile->obfd; | |
1300 | struct comp_unit_head cu_header; | |
1301 | struct die_info *dies; | |
1302 | unsigned long offset; | |
1303 | CORE_ADDR lowpc, highpc; | |
1304 | struct die_info *child_die; | |
1305 | char *info_ptr; | |
1306 | struct symtab *symtab; | |
1307 | struct cleanup *back_to; | |
1308 | ||
1309 | /* Set local variables from the partial symbol table info. */ | |
c5aa993b JM |
1310 | offset = DWARF_INFO_OFFSET (pst); |
1311 | dwarf_info_buffer = DWARF_INFO_BUFFER (pst); | |
1312 | dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst); | |
1313 | dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst); | |
1314 | dwarf_line_buffer = DWARF_LINE_BUFFER (pst); | |
c906108c SS |
1315 | baseaddr = ANOFFSET (pst->section_offsets, 0); |
1316 | cu_header_offset = offset; | |
1317 | info_ptr = dwarf_info_buffer + offset; | |
1318 | ||
1319 | obstack_init (&dwarf2_tmp_obstack); | |
1320 | back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); | |
1321 | ||
1322 | buildsym_init (); | |
a0b3c4fd | 1323 | make_cleanup (really_free_pendings, NULL); |
c906108c SS |
1324 | |
1325 | /* read in the comp_unit header */ | |
1326 | cu_header.length = read_4_bytes (abfd, info_ptr); | |
1327 | info_ptr += 4; | |
1328 | cu_header.version = read_2_bytes (abfd, info_ptr); | |
1329 | info_ptr += 2; | |
1330 | cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr); | |
1331 | info_ptr += 4; | |
1332 | cu_header.addr_size = read_1_byte (abfd, info_ptr); | |
1333 | info_ptr += 1; | |
1334 | ||
1335 | /* Read the abbrevs for this compilation unit */ | |
1336 | dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset); | |
1337 | make_cleanup (dwarf2_empty_abbrev_table, NULL); | |
1338 | ||
1339 | dies = read_comp_unit (info_ptr, abfd); | |
1340 | ||
1341 | make_cleanup ((make_cleanup_func) free_die_list, dies); | |
1342 | ||
1343 | /* Do line number decoding in read_file_scope () */ | |
1344 | process_die (dies, objfile); | |
1345 | ||
1346 | if (!dwarf2_get_pc_bounds (dies, &lowpc, &highpc, objfile)) | |
1347 | { | |
1348 | /* Some compilers don't define a DW_AT_high_pc attribute for | |
c5aa993b JM |
1349 | the compilation unit. If the DW_AT_high_pc is missing, |
1350 | synthesize it, by scanning the DIE's below the compilation unit. */ | |
c906108c SS |
1351 | highpc = 0; |
1352 | if (dies->has_children) | |
1353 | { | |
1354 | child_die = dies->next; | |
1355 | while (child_die && child_die->tag) | |
1356 | { | |
1357 | if (child_die->tag == DW_TAG_subprogram) | |
1358 | { | |
1359 | CORE_ADDR low, high; | |
1360 | ||
1361 | if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile)) | |
1362 | { | |
1363 | highpc = max (highpc, high); | |
1364 | } | |
1365 | } | |
1366 | child_die = sibling_die (child_die); | |
1367 | } | |
1368 | } | |
1369 | } | |
1370 | symtab = end_symtab (highpc + baseaddr, objfile, 0); | |
1371 | ||
1372 | /* Set symtab language to language from DW_AT_language. | |
1373 | If the compilation is from a C file generated by language preprocessors, | |
1374 | do not set the language if it was already deduced by start_subfile. */ | |
1375 | if (symtab != NULL | |
1376 | && !(cu_language == language_c && symtab->language != language_c)) | |
1377 | { | |
1378 | symtab->language = cu_language; | |
1379 | } | |
1380 | pst->symtab = symtab; | |
1381 | pst->readin = 1; | |
1382 | sort_symtab_syms (pst->symtab); | |
1383 | ||
1384 | do_cleanups (back_to); | |
1385 | } | |
1386 | ||
1387 | /* Process a die and its children. */ | |
1388 | ||
1389 | static void | |
1390 | process_die (die, objfile) | |
1391 | struct die_info *die; | |
1392 | struct objfile *objfile; | |
1393 | { | |
1394 | switch (die->tag) | |
1395 | { | |
1396 | case DW_TAG_padding: | |
1397 | break; | |
1398 | case DW_TAG_compile_unit: | |
1399 | read_file_scope (die, objfile); | |
1400 | break; | |
1401 | case DW_TAG_subprogram: | |
1402 | read_subroutine_type (die, objfile); | |
1403 | read_func_scope (die, objfile); | |
1404 | break; | |
1405 | case DW_TAG_inlined_subroutine: | |
1406 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
1407 | They could be used to set breakpoints on all inlined instances |
1408 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
1409 | break; |
1410 | case DW_TAG_lexical_block: | |
1411 | read_lexical_block_scope (die, objfile); | |
1412 | break; | |
1413 | case DW_TAG_class_type: | |
1414 | case DW_TAG_structure_type: | |
1415 | case DW_TAG_union_type: | |
1416 | read_structure_scope (die, objfile); | |
1417 | break; | |
1418 | case DW_TAG_enumeration_type: | |
1419 | read_enumeration (die, objfile); | |
1420 | break; | |
1421 | case DW_TAG_subroutine_type: | |
1422 | read_subroutine_type (die, objfile); | |
1423 | break; | |
1424 | case DW_TAG_array_type: | |
1425 | read_array_type (die, objfile); | |
1426 | break; | |
1427 | case DW_TAG_pointer_type: | |
1428 | read_tag_pointer_type (die, objfile); | |
1429 | break; | |
1430 | case DW_TAG_ptr_to_member_type: | |
1431 | read_tag_ptr_to_member_type (die, objfile); | |
1432 | break; | |
1433 | case DW_TAG_reference_type: | |
1434 | read_tag_reference_type (die, objfile); | |
1435 | break; | |
1436 | case DW_TAG_string_type: | |
1437 | read_tag_string_type (die, objfile); | |
1438 | break; | |
1439 | case DW_TAG_base_type: | |
1440 | read_base_type (die, objfile); | |
1441 | if (dwarf_attr (die, DW_AT_name)) | |
1442 | { | |
1443 | /* Add a typedef symbol for the base type definition. */ | |
1444 | new_symbol (die, die->type, objfile); | |
1445 | } | |
1446 | break; | |
1447 | case DW_TAG_common_block: | |
1448 | read_common_block (die, objfile); | |
1449 | break; | |
1450 | case DW_TAG_common_inclusion: | |
1451 | break; | |
1452 | default: | |
1453 | new_symbol (die, NULL, objfile); | |
1454 | break; | |
1455 | } | |
1456 | } | |
1457 | ||
1458 | static void | |
1459 | read_file_scope (die, objfile) | |
1460 | struct die_info *die; | |
1461 | struct objfile *objfile; | |
1462 | { | |
1463 | unsigned int line_offset = 0; | |
c5aa993b | 1464 | CORE_ADDR lowpc = ((CORE_ADDR) - 1); |
c906108c SS |
1465 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
1466 | struct attribute *attr; | |
1467 | char *name = "<unknown>"; | |
1468 | char *comp_dir = NULL; | |
1469 | struct die_info *child_die; | |
1470 | bfd *abfd = objfile->obfd; | |
1471 | ||
1472 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile)) | |
1473 | { | |
1474 | if (die->has_children) | |
1475 | { | |
1476 | child_die = die->next; | |
1477 | while (child_die && child_die->tag) | |
1478 | { | |
1479 | if (child_die->tag == DW_TAG_subprogram) | |
1480 | { | |
1481 | CORE_ADDR low, high; | |
1482 | ||
1483 | if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile)) | |
1484 | { | |
1485 | lowpc = min (lowpc, low); | |
1486 | highpc = max (highpc, high); | |
1487 | } | |
1488 | } | |
1489 | child_die = sibling_die (child_die); | |
1490 | } | |
1491 | } | |
1492 | } | |
1493 | ||
1494 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
1495 | from finish_block. */ | |
c5aa993b | 1496 | if (lowpc == ((CORE_ADDR) - 1)) |
c906108c SS |
1497 | lowpc = highpc; |
1498 | lowpc += baseaddr; | |
1499 | highpc += baseaddr; | |
1500 | ||
1501 | attr = dwarf_attr (die, DW_AT_name); | |
1502 | if (attr) | |
1503 | { | |
1504 | name = DW_STRING (attr); | |
1505 | } | |
1506 | attr = dwarf_attr (die, DW_AT_comp_dir); | |
1507 | if (attr) | |
1508 | { | |
1509 | comp_dir = DW_STRING (attr); | |
1510 | if (comp_dir) | |
1511 | { | |
1512 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
1513 | directory, get rid of it. */ | |
1514 | char *cp = strchr (comp_dir, ':'); | |
1515 | ||
1516 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') | |
1517 | comp_dir = cp + 1; | |
1518 | } | |
1519 | } | |
1520 | ||
1521 | if (objfile->ei.entry_point >= lowpc && | |
1522 | objfile->ei.entry_point < highpc) | |
1523 | { | |
1524 | objfile->ei.entry_file_lowpc = lowpc; | |
1525 | objfile->ei.entry_file_highpc = highpc; | |
1526 | } | |
1527 | ||
1528 | attr = dwarf_attr (die, DW_AT_language); | |
1529 | if (attr) | |
1530 | { | |
1531 | set_cu_language (DW_UNSND (attr)); | |
1532 | } | |
1533 | ||
1534 | /* We assume that we're processing GCC output. */ | |
1535 | processing_gcc_compilation = 2; | |
1536 | #if 0 | |
c5aa993b JM |
1537 | /* FIXME:Do something here. */ |
1538 | if (dip->at_producer != NULL) | |
c906108c SS |
1539 | { |
1540 | handle_producer (dip->at_producer); | |
1541 | } | |
1542 | #endif | |
1543 | ||
1544 | /* The compilation unit may be in a different language or objfile, | |
1545 | zero out all remembered fundamental types. */ | |
1546 | memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); | |
1547 | ||
1548 | start_symtab (name, comp_dir, lowpc); | |
1549 | record_debugformat ("DWARF 2"); | |
1550 | ||
1551 | /* Decode line number information if present. */ | |
1552 | attr = dwarf_attr (die, DW_AT_stmt_list); | |
1553 | if (attr) | |
1554 | { | |
1555 | line_offset = DW_UNSND (attr); | |
1556 | dwarf_decode_lines (line_offset, comp_dir, abfd); | |
1557 | } | |
1558 | ||
1559 | /* Process all dies in compilation unit. */ | |
1560 | if (die->has_children) | |
1561 | { | |
1562 | child_die = die->next; | |
1563 | while (child_die && child_die->tag) | |
1564 | { | |
1565 | process_die (child_die, objfile); | |
1566 | child_die = sibling_die (child_die); | |
1567 | } | |
1568 | } | |
1569 | } | |
1570 | ||
1571 | static void | |
1572 | read_func_scope (die, objfile) | |
1573 | struct die_info *die; | |
1574 | struct objfile *objfile; | |
1575 | { | |
1576 | register struct context_stack *new; | |
1577 | CORE_ADDR lowpc; | |
1578 | CORE_ADDR highpc; | |
1579 | struct die_info *child_die; | |
1580 | struct attribute *attr; | |
1581 | char *name; | |
1582 | ||
1583 | name = dwarf2_linkage_name (die); | |
1584 | ||
1585 | /* Ignore functions with missing or empty names and functions with | |
1586 | missing or invalid low and high pc attributes. */ | |
1587 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile)) | |
1588 | return; | |
1589 | ||
1590 | lowpc += baseaddr; | |
1591 | highpc += baseaddr; | |
1592 | ||
1593 | if (objfile->ei.entry_point >= lowpc && | |
1594 | objfile->ei.entry_point < highpc) | |
1595 | { | |
1596 | objfile->ei.entry_func_lowpc = lowpc; | |
1597 | objfile->ei.entry_func_highpc = highpc; | |
1598 | } | |
1599 | ||
1600 | if (STREQ (name, "main")) /* FIXME: hardwired name */ | |
1601 | { | |
1602 | objfile->ei.main_func_lowpc = lowpc; | |
1603 | objfile->ei.main_func_highpc = highpc; | |
1604 | } | |
1605 | ||
1606 | /* Decode DW_AT_frame_base location descriptor if present, keep result | |
1607 | for DW_OP_fbreg operands in decode_locdesc. */ | |
1608 | frame_base_reg = -1; | |
1609 | frame_base_offset = 0; | |
1610 | attr = dwarf_attr (die, DW_AT_frame_base); | |
1611 | if (attr) | |
1612 | { | |
1613 | CORE_ADDR addr = decode_locdesc (DW_BLOCK (attr), objfile); | |
7a292a7a SS |
1614 | if (isderef) |
1615 | complain (&dwarf2_unsupported_at_frame_base, name); | |
1616 | else if (isreg) | |
c906108c SS |
1617 | frame_base_reg = addr; |
1618 | else if (offreg) | |
1619 | { | |
1620 | frame_base_reg = basereg; | |
1621 | frame_base_offset = addr; | |
1622 | } | |
1623 | else | |
1624 | complain (&dwarf2_unsupported_at_frame_base, name); | |
1625 | } | |
1626 | ||
1627 | new = push_context (0, lowpc); | |
1628 | new->name = new_symbol (die, die->type, objfile); | |
1629 | list_in_scope = &local_symbols; | |
1630 | ||
1631 | if (die->has_children) | |
1632 | { | |
1633 | child_die = die->next; | |
1634 | while (child_die && child_die->tag) | |
1635 | { | |
1636 | process_die (child_die, objfile); | |
1637 | child_die = sibling_die (child_die); | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | new = pop_context (); | |
1642 | /* Make a block for the local symbols within. */ | |
1643 | finish_block (new->name, &local_symbols, new->old_blocks, | |
1644 | lowpc, highpc, objfile); | |
1645 | list_in_scope = &file_symbols; | |
1646 | } | |
1647 | ||
1648 | /* Process all the DIES contained within a lexical block scope. Start | |
1649 | a new scope, process the dies, and then close the scope. */ | |
1650 | ||
1651 | static void | |
1652 | read_lexical_block_scope (die, objfile) | |
1653 | struct die_info *die; | |
1654 | struct objfile *objfile; | |
1655 | { | |
1656 | register struct context_stack *new; | |
1657 | CORE_ADDR lowpc, highpc; | |
1658 | struct die_info *child_die; | |
1659 | ||
1660 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
1661 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile)) | |
1662 | return; | |
1663 | lowpc += baseaddr; | |
1664 | highpc += baseaddr; | |
1665 | ||
1666 | push_context (0, lowpc); | |
1667 | if (die->has_children) | |
1668 | { | |
1669 | child_die = die->next; | |
1670 | while (child_die && child_die->tag) | |
1671 | { | |
1672 | process_die (child_die, objfile); | |
1673 | child_die = sibling_die (child_die); | |
1674 | } | |
1675 | } | |
1676 | new = pop_context (); | |
1677 | ||
1678 | if (local_symbols != NULL) | |
1679 | { | |
1680 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
1681 | highpc, objfile); | |
1682 | } | |
1683 | local_symbols = new->locals; | |
1684 | } | |
1685 | ||
1686 | /* Get low and high pc attributes from a die. | |
1687 | Return 1 if the attributes are present and valid, otherwise, return 0. */ | |
1688 | ||
1689 | static int | |
1690 | dwarf2_get_pc_bounds (die, lowpc, highpc, objfile) | |
1691 | struct die_info *die; | |
1692 | CORE_ADDR *lowpc; | |
1693 | CORE_ADDR *highpc; | |
1694 | struct objfile *objfile; | |
1695 | { | |
1696 | struct attribute *attr; | |
1697 | CORE_ADDR low; | |
1698 | CORE_ADDR high; | |
1699 | ||
1700 | attr = dwarf_attr (die, DW_AT_low_pc); | |
1701 | if (attr) | |
1702 | low = DW_ADDR (attr); | |
1703 | else | |
1704 | return 0; | |
1705 | attr = dwarf_attr (die, DW_AT_high_pc); | |
1706 | if (attr) | |
1707 | high = DW_ADDR (attr); | |
1708 | else | |
1709 | return 0; | |
1710 | ||
1711 | if (high < low) | |
1712 | return 0; | |
1713 | ||
1714 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
1715 | eliminate duplicate copies of functions and vtables and such. | |
1716 | The linker will arbitrarily choose one and discard the others. | |
1717 | The AT_*_pc values for such functions refer to local labels in | |
1718 | these sections. If the section from that file was discarded, the | |
1719 | labels are not in the output, so the relocs get a value of 0. | |
1720 | If this is a discarded function, mark the pc bounds as invalid, | |
1721 | so that GDB will ignore it. */ | |
1722 | if (low == 0 && (bfd_get_file_flags (objfile->obfd) & HAS_RELOC) == 0) | |
1723 | return 0; | |
1724 | ||
1725 | *lowpc = low; | |
1726 | *highpc = high; | |
1727 | return 1; | |
1728 | } | |
1729 | ||
1730 | /* Add an aggregate field to the field list. */ | |
1731 | ||
1732 | static void | |
1733 | dwarf2_add_field (fip, die, objfile) | |
1734 | struct field_info *fip; | |
1735 | struct die_info *die; | |
1736 | struct objfile *objfile; | |
1737 | { | |
1738 | struct nextfield *new_field; | |
1739 | struct attribute *attr; | |
1740 | struct field *fp; | |
1741 | char *fieldname = ""; | |
1742 | ||
1743 | /* Allocate a new field list entry and link it in. */ | |
1744 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
1745 | make_cleanup (free, new_field); | |
1746 | memset (new_field, 0, sizeof (struct nextfield)); | |
1747 | new_field->next = fip->fields; | |
1748 | fip->fields = new_field; | |
1749 | fip->nfields++; | |
1750 | ||
1751 | /* Handle accessibility and virtuality of field. | |
1752 | The default accessibility for members is public, the default | |
1753 | accessibility for inheritance is private. */ | |
1754 | if (die->tag != DW_TAG_inheritance) | |
1755 | new_field->accessibility = DW_ACCESS_public; | |
1756 | else | |
1757 | new_field->accessibility = DW_ACCESS_private; | |
1758 | new_field->virtuality = DW_VIRTUALITY_none; | |
1759 | ||
1760 | attr = dwarf_attr (die, DW_AT_accessibility); | |
1761 | if (attr) | |
1762 | new_field->accessibility = DW_UNSND (attr); | |
1763 | if (new_field->accessibility != DW_ACCESS_public) | |
1764 | fip->non_public_fields = 1; | |
1765 | attr = dwarf_attr (die, DW_AT_virtuality); | |
1766 | if (attr) | |
1767 | new_field->virtuality = DW_UNSND (attr); | |
1768 | ||
1769 | fp = &new_field->field; | |
1770 | if (die->tag == DW_TAG_member) | |
1771 | { | |
1772 | /* Get type of field. */ | |
1773 | fp->type = die_type (die, objfile); | |
1774 | ||
1775 | /* Get bit size of field (zero if none). */ | |
1776 | attr = dwarf_attr (die, DW_AT_bit_size); | |
1777 | if (attr) | |
1778 | { | |
1779 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
1780 | } | |
1781 | else | |
1782 | { | |
1783 | FIELD_BITSIZE (*fp) = 0; | |
1784 | } | |
1785 | ||
1786 | /* Get bit offset of field. */ | |
1787 | attr = dwarf_attr (die, DW_AT_data_member_location); | |
1788 | if (attr) | |
1789 | { | |
1790 | FIELD_BITPOS (*fp) = | |
1791 | decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte; | |
1792 | } | |
1793 | else | |
1794 | FIELD_BITPOS (*fp) = 0; | |
1795 | attr = dwarf_attr (die, DW_AT_bit_offset); | |
1796 | if (attr) | |
1797 | { | |
1798 | if (BITS_BIG_ENDIAN) | |
1799 | { | |
1800 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
1801 | additional bit offset from the MSB of the containing |
1802 | anonymous object to the MSB of the field. We don't | |
1803 | have to do anything special since we don't need to | |
1804 | know the size of the anonymous object. */ | |
c906108c SS |
1805 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
1806 | } | |
1807 | else | |
1808 | { | |
1809 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
1810 | MSB of the anonymous object, subtract off the number of |
1811 | bits from the MSB of the field to the MSB of the | |
1812 | object, and then subtract off the number of bits of | |
1813 | the field itself. The result is the bit offset of | |
1814 | the LSB of the field. */ | |
c906108c SS |
1815 | int anonymous_size; |
1816 | int bit_offset = DW_UNSND (attr); | |
1817 | ||
1818 | attr = dwarf_attr (die, DW_AT_byte_size); | |
1819 | if (attr) | |
1820 | { | |
1821 | /* The size of the anonymous object containing | |
1822 | the bit field is explicit, so use the | |
1823 | indicated size (in bytes). */ | |
1824 | anonymous_size = DW_UNSND (attr); | |
1825 | } | |
1826 | else | |
1827 | { | |
1828 | /* The size of the anonymous object containing | |
1829 | the bit field must be inferred from the type | |
1830 | attribute of the data member containing the | |
1831 | bit field. */ | |
1832 | anonymous_size = TYPE_LENGTH (fp->type); | |
1833 | } | |
1834 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
1835 | - bit_offset - FIELD_BITSIZE (*fp); | |
1836 | } | |
1837 | } | |
1838 | ||
1839 | /* Get name of field. */ | |
1840 | attr = dwarf_attr (die, DW_AT_name); | |
1841 | if (attr && DW_STRING (attr)) | |
1842 | fieldname = DW_STRING (attr); | |
1843 | fp->name = obsavestring (fieldname, strlen (fieldname), | |
1844 | &objfile->type_obstack); | |
1845 | ||
1846 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 1847 | pointer or virtual base class pointer) to private. */ |
c906108c SS |
1848 | if (dwarf_attr (die, DW_AT_artificial)) |
1849 | { | |
1850 | new_field->accessibility = DW_ACCESS_private; | |
1851 | fip->non_public_fields = 1; | |
1852 | } | |
1853 | } | |
1854 | else if (die->tag == DW_TAG_variable) | |
1855 | { | |
1856 | char *physname; | |
1857 | char *cp; | |
1858 | ||
1859 | /* C++ static member. | |
c5aa993b | 1860 | Get physical name, extract field name from physical name. */ |
c906108c SS |
1861 | physname = dwarf2_linkage_name (die); |
1862 | if (physname == NULL) | |
1863 | return; | |
1864 | ||
1865 | cp = physname; | |
1866 | while (*cp && !is_cplus_marker (*cp)) | |
1867 | cp++; | |
1868 | if (*cp) | |
1869 | fieldname = cp + 1; | |
1870 | if (*fieldname == '\0') | |
1871 | { | |
1872 | complain (&dwarf2_bad_static_member_name, physname); | |
1873 | } | |
1874 | ||
1875 | SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname), | |
c5aa993b | 1876 | &objfile->type_obstack)); |
c906108c SS |
1877 | FIELD_TYPE (*fp) = die_type (die, objfile); |
1878 | FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname), | |
c5aa993b | 1879 | &objfile->type_obstack); |
c906108c SS |
1880 | } |
1881 | else if (die->tag == DW_TAG_inheritance) | |
1882 | { | |
1883 | /* C++ base class field. */ | |
1884 | attr = dwarf_attr (die, DW_AT_data_member_location); | |
1885 | if (attr) | |
1886 | FIELD_BITPOS (*fp) = decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte; | |
1887 | FIELD_BITSIZE (*fp) = 0; | |
1888 | FIELD_TYPE (*fp) = die_type (die, objfile); | |
1889 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); | |
1890 | fip->nbaseclasses++; | |
1891 | } | |
1892 | } | |
1893 | ||
1894 | /* Create the vector of fields, and attach it to the type. */ | |
1895 | ||
1896 | static void | |
1897 | dwarf2_attach_fields_to_type (fip, type, objfile) | |
1898 | struct field_info *fip; | |
1899 | struct type *type; | |
1900 | struct objfile *objfile; | |
1901 | { | |
1902 | int nfields = fip->nfields; | |
1903 | ||
1904 | /* Record the field count, allocate space for the array of fields, | |
1905 | and create blank accessibility bitfields if necessary. */ | |
1906 | TYPE_NFIELDS (type) = nfields; | |
1907 | TYPE_FIELDS (type) = (struct field *) | |
1908 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
1909 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
1910 | ||
1911 | if (fip->non_public_fields) | |
1912 | { | |
1913 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
1914 | ||
1915 | TYPE_FIELD_PRIVATE_BITS (type) = | |
1916 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1917 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
1918 | ||
1919 | TYPE_FIELD_PROTECTED_BITS (type) = | |
1920 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1921 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
1922 | ||
1923 | TYPE_FIELD_IGNORE_BITS (type) = | |
1924 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
1925 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
1926 | } | |
1927 | ||
1928 | /* If the type has baseclasses, allocate and clear a bit vector for | |
1929 | TYPE_FIELD_VIRTUAL_BITS. */ | |
1930 | if (fip->nbaseclasses) | |
1931 | { | |
1932 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
1933 | char *pointer; | |
1934 | ||
1935 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
1936 | pointer = (char *) TYPE_ALLOC (type, num_bytes); | |
1937 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; | |
1938 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); | |
1939 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
1940 | } | |
1941 | ||
1942 | /* Copy the saved-up fields into the field vector. Start from the head | |
1943 | of the list, adding to the tail of the field array, so that they end | |
1944 | up in the same order in the array in which they were added to the list. */ | |
1945 | while (nfields-- > 0) | |
1946 | { | |
1947 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
1948 | switch (fip->fields->accessibility) | |
1949 | { | |
c5aa993b JM |
1950 | case DW_ACCESS_private: |
1951 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
1952 | break; | |
c906108c | 1953 | |
c5aa993b JM |
1954 | case DW_ACCESS_protected: |
1955 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
1956 | break; | |
c906108c | 1957 | |
c5aa993b JM |
1958 | case DW_ACCESS_public: |
1959 | break; | |
c906108c | 1960 | |
c5aa993b JM |
1961 | default: |
1962 | /* Unknown accessibility. Complain and treat it as public. */ | |
1963 | { | |
1964 | complain (&dwarf2_unsupported_accessibility, | |
1965 | fip->fields->accessibility); | |
1966 | } | |
1967 | break; | |
c906108c SS |
1968 | } |
1969 | if (nfields < fip->nbaseclasses) | |
1970 | { | |
1971 | switch (fip->fields->virtuality) | |
1972 | { | |
c5aa993b JM |
1973 | case DW_VIRTUALITY_virtual: |
1974 | case DW_VIRTUALITY_pure_virtual: | |
1975 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
1976 | break; | |
c906108c SS |
1977 | } |
1978 | } | |
1979 | fip->fields = fip->fields->next; | |
1980 | } | |
1981 | } | |
1982 | ||
1983 | /* Skip to the end of a member function name in a mangled name. */ | |
1984 | ||
1985 | static char * | |
1986 | skip_member_fn_name (physname) | |
1987 | char *physname; | |
1988 | { | |
1989 | char *endname = physname; | |
1990 | ||
1991 | /* Skip over leading underscores. */ | |
1992 | while (*endname == '_') | |
1993 | endname++; | |
1994 | ||
1995 | /* Find two succesive underscores. */ | |
1996 | do | |
1997 | endname = strchr (endname, '_'); | |
1998 | while (endname != NULL && *++endname != '_'); | |
1999 | ||
2000 | if (endname == NULL) | |
2001 | { | |
2002 | complain (&dwarf2_bad_member_name_complaint, physname); | |
2003 | endname = physname; | |
2004 | } | |
2005 | else | |
2006 | { | |
2007 | /* Take care of trailing underscores. */ | |
2008 | if (endname[1] != '_') | |
c5aa993b | 2009 | endname--; |
c906108c SS |
2010 | } |
2011 | return endname; | |
2012 | } | |
2013 | ||
2014 | /* Add a member function to the proper fieldlist. */ | |
2015 | ||
2016 | static void | |
2017 | dwarf2_add_member_fn (fip, die, type, objfile) | |
2018 | struct field_info *fip; | |
2019 | struct die_info *die; | |
2020 | struct type *type; | |
2021 | struct objfile *objfile; | |
2022 | { | |
2023 | struct attribute *attr; | |
2024 | struct fnfieldlist *flp; | |
2025 | int i; | |
2026 | struct fn_field *fnp; | |
2027 | char *fieldname; | |
2028 | char *physname; | |
2029 | struct nextfnfield *new_fnfield; | |
2030 | ||
2031 | /* Extract member function name from mangled name. */ | |
2032 | physname = dwarf2_linkage_name (die); | |
2033 | if (physname == NULL) | |
2034 | return; | |
2035 | if ((physname[0] == '_' && physname[1] == '_' | |
c5aa993b | 2036 | && strchr ("0123456789Qt", physname[2])) |
c906108c SS |
2037 | || DESTRUCTOR_PREFIX_P (physname)) |
2038 | { | |
2039 | /* Constructor and destructor field names are set to the name | |
c5aa993b JM |
2040 | of the class, but without template parameter lists. |
2041 | The name might be missing for anonymous aggregates. */ | |
c906108c SS |
2042 | if (TYPE_TAG_NAME (type)) |
2043 | { | |
2044 | char *p = strchr (TYPE_TAG_NAME (type), '<'); | |
2045 | ||
2046 | if (p == NULL) | |
2047 | fieldname = TYPE_TAG_NAME (type); | |
2048 | else | |
2049 | fieldname = obsavestring (TYPE_TAG_NAME (type), | |
2050 | p - TYPE_TAG_NAME (type), | |
2051 | &objfile->type_obstack); | |
2052 | } | |
2053 | else | |
2054 | { | |
2055 | char *anon_name = ""; | |
2056 | fieldname = obsavestring (anon_name, strlen (anon_name), | |
2057 | &objfile->type_obstack); | |
2058 | } | |
2059 | } | |
2060 | else | |
2061 | { | |
2062 | char *endname = skip_member_fn_name (physname); | |
2063 | ||
2064 | /* Ignore member function if we were unable not extract the member | |
c5aa993b | 2065 | function name. */ |
c906108c SS |
2066 | if (endname == physname) |
2067 | return; | |
2068 | fieldname = obsavestring (physname, endname - physname, | |
2069 | &objfile->type_obstack); | |
2070 | } | |
2071 | ||
2072 | /* Look up member function name in fieldlist. */ | |
2073 | for (i = 0; i < fip->nfnfields; i++) | |
2074 | { | |
2075 | if (STREQ (fip->fnfieldlists[i].name, fieldname)) | |
2076 | break; | |
2077 | } | |
2078 | ||
2079 | /* Create new list element if necessary. */ | |
2080 | if (i < fip->nfnfields) | |
2081 | flp = &fip->fnfieldlists[i]; | |
2082 | else | |
2083 | { | |
2084 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
2085 | { | |
2086 | fip->fnfieldlists = (struct fnfieldlist *) | |
2087 | xrealloc (fip->fnfieldlists, | |
2088 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 2089 | * sizeof (struct fnfieldlist)); |
c906108c | 2090 | if (fip->nfnfields == 0) |
c5aa993b JM |
2091 | make_cleanup ((make_cleanup_func) free_current_contents, |
2092 | &fip->fnfieldlists); | |
c906108c SS |
2093 | } |
2094 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
2095 | flp->name = fieldname; | |
2096 | flp->length = 0; | |
2097 | flp->head = NULL; | |
2098 | fip->nfnfields++; | |
2099 | } | |
2100 | ||
2101 | /* Create a new member function field and chain it to the field list | |
2102 | entry. */ | |
2103 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
2104 | make_cleanup (free, new_fnfield); | |
2105 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); | |
2106 | new_fnfield->next = flp->head; | |
2107 | flp->head = new_fnfield; | |
2108 | flp->length++; | |
2109 | ||
2110 | /* Fill in the member function field info. */ | |
2111 | fnp = &new_fnfield->fnfield; | |
2112 | fnp->physname = obsavestring (physname, strlen (physname), | |
2113 | &objfile->type_obstack); | |
2114 | fnp->type = alloc_type (objfile); | |
2115 | if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) | |
2116 | { | |
2117 | struct type *return_type = TYPE_TARGET_TYPE (die->type); | |
2118 | struct type **arg_types; | |
2119 | int nparams = TYPE_NFIELDS (die->type); | |
2120 | int iparams; | |
2121 | ||
2122 | /* Copy argument types from the subroutine type. */ | |
2123 | arg_types = (struct type **) | |
2124 | TYPE_ALLOC (fnp->type, (nparams + 1) * sizeof (struct type *)); | |
2125 | for (iparams = 0; iparams < nparams; iparams++) | |
2126 | arg_types[iparams] = TYPE_FIELD_TYPE (die->type, iparams); | |
2127 | ||
2128 | /* Set last entry in argument type vector. */ | |
2129 | if (TYPE_FLAGS (die->type) & TYPE_FLAG_VARARGS) | |
2130 | arg_types[nparams] = NULL; | |
2131 | else | |
2132 | arg_types[nparams] = dwarf2_fundamental_type (objfile, FT_VOID); | |
2133 | ||
2134 | smash_to_method_type (fnp->type, type, return_type, arg_types); | |
2135 | ||
2136 | /* Handle static member functions. | |
c5aa993b JM |
2137 | Dwarf2 has no clean way to discern C++ static and non-static |
2138 | member functions. G++ helps GDB by marking the first | |
2139 | parameter for non-static member functions (which is the | |
2140 | this pointer) as artificial. We obtain this information | |
2141 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
c906108c SS |
2142 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) |
2143 | fnp->voffset = VOFFSET_STATIC; | |
2144 | } | |
2145 | else | |
2146 | complain (&dwarf2_missing_member_fn_type_complaint, physname); | |
2147 | ||
2148 | /* Get fcontext from DW_AT_containing_type if present. */ | |
2149 | if (dwarf_attr (die, DW_AT_containing_type) != NULL) | |
2150 | fnp->fcontext = die_containing_type (die, objfile); | |
2151 | ||
2152 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
2153 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
2154 | ||
2155 | /* Get accessibility. */ | |
2156 | attr = dwarf_attr (die, DW_AT_accessibility); | |
2157 | if (attr) | |
2158 | { | |
2159 | switch (DW_UNSND (attr)) | |
2160 | { | |
c5aa993b JM |
2161 | case DW_ACCESS_private: |
2162 | fnp->is_private = 1; | |
2163 | break; | |
2164 | case DW_ACCESS_protected: | |
2165 | fnp->is_protected = 1; | |
2166 | break; | |
c906108c SS |
2167 | } |
2168 | } | |
2169 | ||
2170 | /* Get index in virtual function table if it is a virtual member function. */ | |
2171 | attr = dwarf_attr (die, DW_AT_vtable_elem_location); | |
2172 | if (attr) | |
2173 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), objfile) + 2; | |
2174 | } | |
2175 | ||
2176 | /* Create the vector of member function fields, and attach it to the type. */ | |
2177 | ||
2178 | static void | |
2179 | dwarf2_attach_fn_fields_to_type (fip, type, objfile) | |
2180 | struct field_info *fip; | |
2181 | struct type *type; | |
2182 | struct objfile *objfile; | |
2183 | { | |
2184 | struct fnfieldlist *flp; | |
2185 | int total_length = 0; | |
2186 | int i; | |
2187 | ||
2188 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
2189 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
2190 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
2191 | ||
2192 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
2193 | { | |
2194 | struct nextfnfield *nfp = flp->head; | |
2195 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
2196 | int k; | |
2197 | ||
2198 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
2199 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
2200 | fn_flp->fn_fields = (struct fn_field *) | |
2201 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
2202 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 2203 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
2204 | |
2205 | total_length += flp->length; | |
2206 | } | |
2207 | ||
2208 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
2209 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
2210 | } | |
2211 | ||
2212 | /* Called when we find the DIE that starts a structure or union scope | |
2213 | (definition) to process all dies that define the members of the | |
2214 | structure or union. | |
2215 | ||
2216 | NOTE: we need to call struct_type regardless of whether or not the | |
2217 | DIE has an at_name attribute, since it might be an anonymous | |
2218 | structure or union. This gets the type entered into our set of | |
2219 | user defined types. | |
2220 | ||
2221 | However, if the structure is incomplete (an opaque struct/union) | |
2222 | then suppress creating a symbol table entry for it since gdb only | |
2223 | wants to find the one with the complete definition. Note that if | |
2224 | it is complete, we just call new_symbol, which does it's own | |
2225 | checking about whether the struct/union is anonymous or not (and | |
2226 | suppresses creating a symbol table entry itself). */ | |
2227 | ||
2228 | static void | |
2229 | read_structure_scope (die, objfile) | |
2230 | struct die_info *die; | |
2231 | struct objfile *objfile; | |
2232 | { | |
2233 | struct type *type; | |
2234 | struct attribute *attr; | |
2235 | ||
2236 | type = alloc_type (objfile); | |
2237 | ||
2238 | INIT_CPLUS_SPECIFIC (type); | |
2239 | attr = dwarf_attr (die, DW_AT_name); | |
2240 | if (attr && DW_STRING (attr)) | |
2241 | { | |
2242 | TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr), | |
2243 | strlen (DW_STRING (attr)), | |
2244 | &objfile->type_obstack); | |
2245 | } | |
2246 | ||
2247 | if (die->tag == DW_TAG_structure_type) | |
2248 | { | |
2249 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
2250 | } | |
2251 | else if (die->tag == DW_TAG_union_type) | |
2252 | { | |
2253 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
2254 | } | |
2255 | else | |
2256 | { | |
2257 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 2258 | in gdbtypes.h. */ |
c906108c SS |
2259 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
2260 | } | |
2261 | ||
2262 | attr = dwarf_attr (die, DW_AT_byte_size); | |
2263 | if (attr) | |
2264 | { | |
2265 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
2266 | } | |
2267 | else | |
2268 | { | |
2269 | TYPE_LENGTH (type) = 0; | |
2270 | } | |
2271 | ||
2272 | /* We need to add the type field to the die immediately so we don't | |
2273 | infinitely recurse when dealing with pointers to the structure | |
2274 | type within the structure itself. */ | |
2275 | die->type = type; | |
2276 | ||
2277 | if (die->has_children) | |
2278 | { | |
2279 | struct field_info fi; | |
2280 | struct die_info *child_die; | |
2281 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
2282 | ||
2283 | memset (&fi, 0, sizeof (struct field_info)); | |
2284 | ||
2285 | child_die = die->next; | |
2286 | ||
2287 | while (child_die && child_die->tag) | |
2288 | { | |
2289 | if (child_die->tag == DW_TAG_member) | |
2290 | { | |
2291 | dwarf2_add_field (&fi, child_die, objfile); | |
2292 | } | |
2293 | else if (child_die->tag == DW_TAG_variable) | |
2294 | { | |
2295 | /* C++ static member. */ | |
2296 | dwarf2_add_field (&fi, child_die, objfile); | |
2297 | } | |
2298 | else if (child_die->tag == DW_TAG_subprogram) | |
2299 | { | |
2300 | /* C++ member function. */ | |
2301 | process_die (child_die, objfile); | |
2302 | dwarf2_add_member_fn (&fi, child_die, type, objfile); | |
2303 | } | |
2304 | else if (child_die->tag == DW_TAG_inheritance) | |
2305 | { | |
2306 | /* C++ base class field. */ | |
2307 | dwarf2_add_field (&fi, child_die, objfile); | |
2308 | } | |
2309 | else | |
2310 | { | |
2311 | process_die (child_die, objfile); | |
2312 | } | |
2313 | child_die = sibling_die (child_die); | |
2314 | } | |
2315 | ||
2316 | /* Attach fields and member functions to the type. */ | |
2317 | if (fi.nfields) | |
2318 | dwarf2_attach_fields_to_type (&fi, type, objfile); | |
2319 | if (fi.nfnfields) | |
2320 | { | |
2321 | dwarf2_attach_fn_fields_to_type (&fi, type, objfile); | |
2322 | ||
c5aa993b | 2323 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
2324 | class itself) which contains the vtable pointer for the current |
2325 | class from the DW_AT_containing_type attribute. */ | |
2326 | ||
2327 | if (dwarf_attr (die, DW_AT_containing_type) != NULL) | |
2328 | { | |
2329 | struct type *t = die_containing_type (die, objfile); | |
2330 | ||
2331 | TYPE_VPTR_BASETYPE (type) = t; | |
2332 | if (type == t) | |
2333 | { | |
c5aa993b JM |
2334 | static const char vptr_name[] = |
2335 | {'_', 'v', 'p', 't', 'r', '\0'}; | |
c906108c SS |
2336 | int i; |
2337 | ||
2338 | /* Our own class provides vtbl ptr. */ | |
2339 | for (i = TYPE_NFIELDS (t) - 1; | |
2340 | i >= TYPE_N_BASECLASSES (t); | |
2341 | --i) | |
2342 | { | |
2343 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
2344 | ||
2345 | if (STREQN (fieldname, vptr_name, strlen (vptr_name) - 1) | |
2346 | && is_cplus_marker (fieldname[strlen (vptr_name)])) | |
2347 | { | |
2348 | TYPE_VPTR_FIELDNO (type) = i; | |
2349 | break; | |
2350 | } | |
2351 | } | |
2352 | ||
2353 | /* Complain if virtual function table field not found. */ | |
2354 | if (i < TYPE_N_BASECLASSES (t)) | |
2355 | complain (&dwarf2_vtbl_not_found_complaint, | |
c5aa993b | 2356 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : ""); |
c906108c SS |
2357 | } |
2358 | else | |
2359 | { | |
2360 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
2361 | } | |
2362 | } | |
2363 | } | |
2364 | ||
2365 | new_symbol (die, type, objfile); | |
2366 | ||
2367 | do_cleanups (back_to); | |
2368 | } | |
2369 | else | |
2370 | { | |
2371 | /* No children, must be stub. */ | |
2372 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
2373 | } | |
2374 | ||
2375 | die->type = type; | |
2376 | } | |
2377 | ||
2378 | /* Given a pointer to a die which begins an enumeration, process all | |
2379 | the dies that define the members of the enumeration. | |
2380 | ||
2381 | This will be much nicer in draft 6 of the DWARF spec when our | |
2382 | members will be dies instead squished into the DW_AT_element_list | |
2383 | attribute. | |
2384 | ||
2385 | NOTE: We reverse the order of the element list. */ | |
2386 | ||
2387 | static void | |
2388 | read_enumeration (die, objfile) | |
2389 | struct die_info *die; | |
2390 | struct objfile *objfile; | |
2391 | { | |
2392 | struct die_info *child_die; | |
2393 | struct type *type; | |
2394 | struct field *fields; | |
2395 | struct attribute *attr; | |
2396 | struct symbol *sym; | |
2397 | int num_fields; | |
2398 | int unsigned_enum = 1; | |
2399 | ||
2400 | type = alloc_type (objfile); | |
2401 | ||
2402 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
2403 | attr = dwarf_attr (die, DW_AT_name); | |
2404 | if (attr && DW_STRING (attr)) | |
2405 | { | |
2406 | TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr), | |
2407 | strlen (DW_STRING (attr)), | |
2408 | &objfile->type_obstack); | |
2409 | } | |
2410 | ||
2411 | attr = dwarf_attr (die, DW_AT_byte_size); | |
2412 | if (attr) | |
2413 | { | |
2414 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
2415 | } | |
2416 | else | |
2417 | { | |
2418 | TYPE_LENGTH (type) = 0; | |
2419 | } | |
2420 | ||
2421 | num_fields = 0; | |
2422 | fields = NULL; | |
2423 | if (die->has_children) | |
2424 | { | |
2425 | child_die = die->next; | |
2426 | while (child_die && child_die->tag) | |
2427 | { | |
2428 | if (child_die->tag != DW_TAG_enumerator) | |
2429 | { | |
2430 | process_die (child_die, objfile); | |
2431 | } | |
2432 | else | |
2433 | { | |
2434 | attr = dwarf_attr (child_die, DW_AT_name); | |
2435 | if (attr) | |
2436 | { | |
2437 | sym = new_symbol (child_die, type, objfile); | |
2438 | if (SYMBOL_VALUE (sym) < 0) | |
2439 | unsigned_enum = 0; | |
2440 | ||
2441 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
2442 | { | |
2443 | fields = (struct field *) | |
2444 | xrealloc (fields, | |
2445 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 2446 | * sizeof (struct field)); |
c906108c SS |
2447 | } |
2448 | ||
2449 | FIELD_NAME (fields[num_fields]) = SYMBOL_NAME (sym); | |
2450 | FIELD_TYPE (fields[num_fields]) = NULL; | |
2451 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
2452 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
2453 | ||
2454 | num_fields++; | |
2455 | } | |
2456 | } | |
2457 | ||
2458 | child_die = sibling_die (child_die); | |
2459 | } | |
2460 | ||
2461 | if (num_fields) | |
2462 | { | |
2463 | TYPE_NFIELDS (type) = num_fields; | |
2464 | TYPE_FIELDS (type) = (struct field *) | |
2465 | TYPE_ALLOC (type, sizeof (struct field) * num_fields); | |
2466 | memcpy (TYPE_FIELDS (type), fields, | |
2467 | sizeof (struct field) * num_fields); | |
2468 | free (fields); | |
2469 | } | |
2470 | if (unsigned_enum) | |
2471 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; | |
2472 | } | |
2473 | die->type = type; | |
2474 | new_symbol (die, type, objfile); | |
2475 | } | |
2476 | ||
2477 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
2478 | the DIE's type field. For now, this only handles one dimensional | |
2479 | arrays. */ | |
2480 | ||
2481 | static void | |
2482 | read_array_type (die, objfile) | |
2483 | struct die_info *die; | |
2484 | struct objfile *objfile; | |
2485 | { | |
2486 | struct die_info *child_die; | |
2487 | struct type *type = NULL; | |
2488 | struct type *element_type, *range_type, *index_type; | |
2489 | struct type **range_types = NULL; | |
2490 | struct attribute *attr; | |
2491 | int ndim = 0; | |
2492 | struct cleanup *back_to; | |
2493 | ||
2494 | /* Return if we've already decoded this type. */ | |
2495 | if (die->type) | |
2496 | { | |
2497 | return; | |
2498 | } | |
2499 | ||
2500 | element_type = die_type (die, objfile); | |
2501 | ||
2502 | /* Irix 6.2 native cc creates array types without children for | |
2503 | arrays with unspecified length. */ | |
2504 | if (die->has_children == 0) | |
2505 | { | |
2506 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER); | |
2507 | range_type = create_range_type (NULL, index_type, 0, -1); | |
2508 | die->type = create_array_type (NULL, element_type, range_type); | |
2509 | return; | |
2510 | } | |
2511 | ||
2512 | back_to = make_cleanup (null_cleanup, NULL); | |
2513 | child_die = die->next; | |
2514 | while (child_die && child_die->tag) | |
2515 | { | |
2516 | if (child_die->tag == DW_TAG_subrange_type) | |
2517 | { | |
2518 | unsigned int low, high; | |
2519 | ||
2520 | /* Default bounds to an array with unspecified length. */ | |
2521 | low = 0; | |
2522 | high = -1; | |
2523 | if (cu_language == language_fortran) | |
2524 | { | |
2525 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
2526 | low = 1; | |
2527 | } | |
2528 | ||
2529 | index_type = die_type (child_die, objfile); | |
2530 | attr = dwarf_attr (child_die, DW_AT_lower_bound); | |
2531 | if (attr) | |
2532 | { | |
2533 | if (attr->form == DW_FORM_sdata) | |
2534 | { | |
2535 | low = DW_SND (attr); | |
2536 | } | |
2537 | else if (attr->form == DW_FORM_udata | |
c5aa993b JM |
2538 | || attr->form == DW_FORM_data1 |
2539 | || attr->form == DW_FORM_data2 | |
2540 | || attr->form == DW_FORM_data4) | |
c906108c SS |
2541 | { |
2542 | low = DW_UNSND (attr); | |
2543 | } | |
2544 | else | |
2545 | { | |
2546 | complain (&dwarf2_non_const_array_bound_ignored, | |
2547 | dwarf_form_name (attr->form)); | |
2548 | #ifdef FORTRAN_HACK | |
2549 | die->type = lookup_pointer_type (element_type); | |
2550 | return; | |
2551 | #else | |
2552 | low = 0; | |
2553 | #endif | |
2554 | } | |
2555 | } | |
2556 | attr = dwarf_attr (child_die, DW_AT_upper_bound); | |
2557 | if (attr) | |
2558 | { | |
2559 | if (attr->form == DW_FORM_sdata) | |
2560 | { | |
2561 | high = DW_SND (attr); | |
2562 | } | |
2563 | else if (attr->form == DW_FORM_udata | |
c5aa993b JM |
2564 | || attr->form == DW_FORM_data1 |
2565 | || attr->form == DW_FORM_data2 | |
2566 | || attr->form == DW_FORM_data4) | |
c906108c SS |
2567 | { |
2568 | high = DW_UNSND (attr); | |
2569 | } | |
2570 | else if (attr->form == DW_FORM_block1) | |
2571 | { | |
2572 | /* GCC encodes arrays with unspecified or dynamic length | |
2573 | with a DW_FORM_block1 attribute. | |
2574 | FIXME: GDB does not yet know how to handle dynamic | |
2575 | arrays properly, treat them as arrays with unspecified | |
2576 | length for now. */ | |
2577 | high = -1; | |
2578 | } | |
2579 | else | |
2580 | { | |
2581 | complain (&dwarf2_non_const_array_bound_ignored, | |
2582 | dwarf_form_name (attr->form)); | |
2583 | #ifdef FORTRAN_HACK | |
2584 | die->type = lookup_pointer_type (element_type); | |
2585 | return; | |
2586 | #else | |
2587 | high = 1; | |
2588 | #endif | |
2589 | } | |
2590 | } | |
2591 | ||
2592 | /* Create a range type and save it for array type creation. */ | |
2593 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
2594 | { | |
2595 | range_types = (struct type **) | |
2596 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 2597 | * sizeof (struct type *)); |
c906108c | 2598 | if (ndim == 0) |
c5aa993b JM |
2599 | make_cleanup ((make_cleanup_func) free_current_contents, |
2600 | &range_types); | |
c906108c SS |
2601 | } |
2602 | range_types[ndim++] = create_range_type (NULL, index_type, low, high); | |
2603 | } | |
2604 | child_die = sibling_die (child_die); | |
2605 | } | |
2606 | ||
2607 | /* Dwarf2 dimensions are output from left to right, create the | |
2608 | necessary array types in backwards order. */ | |
2609 | type = element_type; | |
2610 | while (ndim-- > 0) | |
2611 | type = create_array_type (NULL, type, range_types[ndim]); | |
2612 | ||
2613 | do_cleanups (back_to); | |
2614 | ||
2615 | /* Install the type in the die. */ | |
2616 | die->type = type; | |
2617 | } | |
2618 | ||
2619 | /* First cut: install each common block member as a global variable. */ | |
2620 | ||
2621 | static void | |
2622 | read_common_block (die, objfile) | |
2623 | struct die_info *die; | |
2624 | struct objfile *objfile; | |
2625 | { | |
2626 | struct die_info *child_die; | |
2627 | struct attribute *attr; | |
2628 | struct symbol *sym; | |
2629 | CORE_ADDR base = (CORE_ADDR) 0; | |
2630 | ||
2631 | attr = dwarf_attr (die, DW_AT_location); | |
2632 | if (attr) | |
2633 | { | |
2634 | base = decode_locdesc (DW_BLOCK (attr), objfile); | |
2635 | } | |
2636 | if (die->has_children) | |
2637 | { | |
2638 | child_die = die->next; | |
2639 | while (child_die && child_die->tag) | |
2640 | { | |
2641 | sym = new_symbol (child_die, NULL, objfile); | |
2642 | attr = dwarf_attr (child_die, DW_AT_data_member_location); | |
2643 | if (attr) | |
2644 | { | |
2645 | SYMBOL_VALUE_ADDRESS (sym) = | |
2646 | base + decode_locdesc (DW_BLOCK (attr), objfile); | |
2647 | add_symbol_to_list (sym, &global_symbols); | |
2648 | } | |
2649 | child_die = sibling_die (child_die); | |
2650 | } | |
2651 | } | |
2652 | } | |
2653 | ||
2654 | /* Extract all information from a DW_TAG_pointer_type DIE and add to | |
2655 | the user defined type vector. */ | |
2656 | ||
2657 | static void | |
2658 | read_tag_pointer_type (die, objfile) | |
2659 | struct die_info *die; | |
2660 | struct objfile *objfile; | |
2661 | { | |
2662 | struct type *type; | |
2663 | struct attribute *attr; | |
2664 | ||
2665 | if (die->type) | |
2666 | { | |
2667 | return; | |
2668 | } | |
2669 | ||
2670 | type = lookup_pointer_type (die_type (die, objfile)); | |
2671 | attr = dwarf_attr (die, DW_AT_byte_size); | |
2672 | if (attr) | |
2673 | { | |
2674 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
2675 | } | |
2676 | else | |
2677 | { | |
2678 | TYPE_LENGTH (type) = address_size; | |
2679 | } | |
2680 | die->type = type; | |
2681 | } | |
2682 | ||
2683 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
2684 | the user defined type vector. */ | |
2685 | ||
2686 | static void | |
2687 | read_tag_ptr_to_member_type (die, objfile) | |
2688 | struct die_info *die; | |
2689 | struct objfile *objfile; | |
2690 | { | |
2691 | struct type *type; | |
2692 | struct type *to_type; | |
2693 | struct type *domain; | |
2694 | ||
2695 | if (die->type) | |
2696 | { | |
2697 | return; | |
2698 | } | |
2699 | ||
2700 | type = alloc_type (objfile); | |
2701 | to_type = die_type (die, objfile); | |
2702 | domain = die_containing_type (die, objfile); | |
2703 | smash_to_member_type (type, domain, to_type); | |
2704 | ||
2705 | die->type = type; | |
2706 | } | |
2707 | ||
2708 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
2709 | the user defined type vector. */ | |
2710 | ||
2711 | static void | |
2712 | read_tag_reference_type (die, objfile) | |
2713 | struct die_info *die; | |
2714 | struct objfile *objfile; | |
2715 | { | |
2716 | struct type *type; | |
2717 | struct attribute *attr; | |
2718 | ||
2719 | if (die->type) | |
2720 | { | |
2721 | return; | |
2722 | } | |
2723 | ||
2724 | type = lookup_reference_type (die_type (die, objfile)); | |
2725 | attr = dwarf_attr (die, DW_AT_byte_size); | |
2726 | if (attr) | |
2727 | { | |
2728 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
2729 | } | |
2730 | else | |
2731 | { | |
2732 | TYPE_LENGTH (type) = address_size; | |
2733 | } | |
2734 | die->type = type; | |
2735 | } | |
2736 | ||
2737 | static void | |
2738 | read_tag_const_type (die, objfile) | |
2739 | struct die_info *die; | |
2740 | struct objfile *objfile; | |
2741 | { | |
2742 | if (die->type) | |
2743 | { | |
2744 | return; | |
2745 | } | |
2746 | ||
2747 | complain (&dwarf2_const_ignored); | |
2748 | die->type = die_type (die, objfile); | |
2749 | } | |
2750 | ||
2751 | static void | |
2752 | read_tag_volatile_type (die, objfile) | |
2753 | struct die_info *die; | |
2754 | struct objfile *objfile; | |
2755 | { | |
2756 | if (die->type) | |
2757 | { | |
2758 | return; | |
2759 | } | |
2760 | ||
2761 | complain (&dwarf2_volatile_ignored); | |
2762 | die->type = die_type (die, objfile); | |
2763 | } | |
2764 | ||
2765 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
2766 | the user defined type vector. It isn't really a user defined type, | |
2767 | but it behaves like one, with other DIE's using an AT_user_def_type | |
2768 | attribute to reference it. */ | |
2769 | ||
2770 | static void | |
2771 | read_tag_string_type (die, objfile) | |
2772 | struct die_info *die; | |
2773 | struct objfile *objfile; | |
2774 | { | |
2775 | struct type *type, *range_type, *index_type, *char_type; | |
2776 | struct attribute *attr; | |
2777 | unsigned int length; | |
2778 | ||
2779 | if (die->type) | |
2780 | { | |
2781 | return; | |
2782 | } | |
2783 | ||
2784 | attr = dwarf_attr (die, DW_AT_string_length); | |
2785 | if (attr) | |
2786 | { | |
2787 | length = DW_UNSND (attr); | |
2788 | } | |
2789 | else | |
2790 | { | |
2791 | length = 1; | |
2792 | } | |
2793 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER); | |
2794 | range_type = create_range_type (NULL, index_type, 1, length); | |
2795 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR); | |
2796 | type = create_string_type (char_type, range_type); | |
2797 | die->type = type; | |
2798 | } | |
2799 | ||
2800 | /* Handle DIES due to C code like: | |
2801 | ||
2802 | struct foo | |
c5aa993b JM |
2803 | { |
2804 | int (*funcp)(int a, long l); | |
2805 | int b; | |
2806 | }; | |
c906108c SS |
2807 | |
2808 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 2809 | */ |
c906108c SS |
2810 | |
2811 | static void | |
2812 | read_subroutine_type (die, objfile) | |
2813 | struct die_info *die; | |
2814 | struct objfile *objfile; | |
2815 | { | |
2816 | struct type *type; /* Type that this function returns */ | |
2817 | struct type *ftype; /* Function that returns above type */ | |
2818 | struct attribute *attr; | |
2819 | ||
2820 | /* Decode the type that this subroutine returns */ | |
2821 | if (die->type) | |
2822 | { | |
2823 | return; | |
2824 | } | |
2825 | type = die_type (die, objfile); | |
2826 | ftype = lookup_function_type (type); | |
2827 | ||
2828 | /* All functions in C++ have prototypes. */ | |
2829 | attr = dwarf_attr (die, DW_AT_prototyped); | |
2830 | if ((attr && (DW_UNSND (attr) != 0)) | |
2831 | || cu_language == language_cplus) | |
2832 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; | |
2833 | ||
2834 | if (die->has_children) | |
2835 | { | |
2836 | struct die_info *child_die; | |
2837 | int nparams = 0; | |
2838 | int iparams = 0; | |
2839 | ||
2840 | /* Count the number of parameters. | |
2841 | FIXME: GDB currently ignores vararg functions, but knows about | |
2842 | vararg member functions. */ | |
2843 | child_die = die->next; | |
2844 | while (child_die && child_die->tag) | |
2845 | { | |
2846 | if (child_die->tag == DW_TAG_formal_parameter) | |
2847 | nparams++; | |
2848 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
2849 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
2850 | child_die = sibling_die (child_die); | |
2851 | } | |
2852 | ||
2853 | /* Allocate storage for parameters and fill them in. */ | |
2854 | TYPE_NFIELDS (ftype) = nparams; | |
2855 | TYPE_FIELDS (ftype) = (struct field *) | |
2856 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); | |
2857 | ||
2858 | child_die = die->next; | |
2859 | while (child_die && child_die->tag) | |
2860 | { | |
2861 | if (child_die->tag == DW_TAG_formal_parameter) | |
2862 | { | |
2863 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
2864 | member functions. G++ helps GDB by marking the first |
2865 | parameter for non-static member functions (which is the | |
2866 | this pointer) as artificial. We pass this information | |
2867 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
c906108c SS |
2868 | attr = dwarf_attr (child_die, DW_AT_artificial); |
2869 | if (attr) | |
2870 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
2871 | else | |
2872 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
2873 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, objfile); | |
2874 | iparams++; | |
2875 | } | |
2876 | child_die = sibling_die (child_die); | |
2877 | } | |
2878 | } | |
2879 | ||
2880 | die->type = ftype; | |
2881 | } | |
2882 | ||
2883 | static void | |
2884 | read_typedef (die, objfile) | |
2885 | struct die_info *die; | |
2886 | struct objfile *objfile; | |
2887 | { | |
2888 | struct type *type; | |
2889 | ||
2890 | if (!die->type) | |
2891 | { | |
2892 | struct attribute *attr; | |
2893 | struct type *xtype; | |
2894 | ||
2895 | xtype = die_type (die, objfile); | |
2896 | ||
2897 | type = alloc_type (objfile); | |
2898 | TYPE_CODE (type) = TYPE_CODE_TYPEDEF; | |
2899 | TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB; | |
2900 | TYPE_TARGET_TYPE (type) = xtype; | |
2901 | attr = dwarf_attr (die, DW_AT_name); | |
2902 | if (attr && DW_STRING (attr)) | |
2903 | TYPE_NAME (type) = obsavestring (DW_STRING (attr), | |
2904 | strlen (DW_STRING (attr)), | |
2905 | &objfile->type_obstack); | |
2906 | ||
2907 | die->type = type; | |
2908 | } | |
2909 | } | |
2910 | ||
2911 | /* Find a representation of a given base type and install | |
2912 | it in the TYPE field of the die. */ | |
2913 | ||
2914 | static void | |
2915 | read_base_type (die, objfile) | |
2916 | struct die_info *die; | |
2917 | struct objfile *objfile; | |
2918 | { | |
2919 | struct type *type; | |
2920 | struct attribute *attr; | |
2921 | int encoding = 0, size = 0; | |
2922 | ||
2923 | /* If we've already decoded this die, this is a no-op. */ | |
2924 | if (die->type) | |
2925 | { | |
2926 | return; | |
2927 | } | |
2928 | ||
2929 | attr = dwarf_attr (die, DW_AT_encoding); | |
2930 | if (attr) | |
2931 | { | |
2932 | encoding = DW_UNSND (attr); | |
2933 | } | |
2934 | attr = dwarf_attr (die, DW_AT_byte_size); | |
2935 | if (attr) | |
2936 | { | |
2937 | size = DW_UNSND (attr); | |
2938 | } | |
2939 | attr = dwarf_attr (die, DW_AT_name); | |
2940 | if (attr && DW_STRING (attr)) | |
2941 | { | |
2942 | enum type_code code = TYPE_CODE_INT; | |
2943 | int is_unsigned = 0; | |
2944 | ||
2945 | switch (encoding) | |
2946 | { | |
2947 | case DW_ATE_address: | |
2948 | /* Turn DW_ATE_address into a void * pointer. */ | |
2949 | code = TYPE_CODE_PTR; | |
2950 | is_unsigned = 1; | |
2951 | break; | |
2952 | case DW_ATE_boolean: | |
2953 | code = TYPE_CODE_BOOL; | |
2954 | is_unsigned = 1; | |
2955 | break; | |
2956 | case DW_ATE_complex_float: | |
2957 | code = TYPE_CODE_COMPLEX; | |
2958 | break; | |
2959 | case DW_ATE_float: | |
2960 | code = TYPE_CODE_FLT; | |
2961 | break; | |
2962 | case DW_ATE_signed: | |
2963 | case DW_ATE_signed_char: | |
2964 | break; | |
2965 | case DW_ATE_unsigned: | |
2966 | case DW_ATE_unsigned_char: | |
2967 | is_unsigned = 1; | |
2968 | break; | |
2969 | default: | |
2970 | complain (&dwarf2_unsupported_at_encoding, | |
2971 | dwarf_type_encoding_name (encoding)); | |
2972 | break; | |
2973 | } | |
2974 | type = init_type (code, size, is_unsigned, DW_STRING (attr), objfile); | |
2975 | if (encoding == DW_ATE_address) | |
2976 | TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID); | |
2977 | } | |
2978 | else | |
2979 | { | |
2980 | type = dwarf_base_type (encoding, size, objfile); | |
2981 | } | |
2982 | die->type = type; | |
2983 | } | |
2984 | ||
2985 | /* Read a whole compilation unit into a linked list of dies. */ | |
2986 | ||
2987 | struct die_info * | |
2988 | read_comp_unit (info_ptr, abfd) | |
c5aa993b JM |
2989 | char *info_ptr; |
2990 | bfd *abfd; | |
c906108c SS |
2991 | { |
2992 | struct die_info *first_die, *last_die, *die; | |
2993 | char *cur_ptr; | |
2994 | int nesting_level; | |
2995 | ||
2996 | /* Reset die reference table, we are building a new one now. */ | |
2997 | dwarf2_empty_die_ref_table (); | |
2998 | ||
2999 | cur_ptr = info_ptr; | |
3000 | nesting_level = 0; | |
3001 | first_die = last_die = NULL; | |
3002 | do | |
3003 | { | |
3004 | cur_ptr = read_full_die (&die, abfd, cur_ptr); | |
3005 | if (die->has_children) | |
3006 | { | |
3007 | nesting_level++; | |
3008 | } | |
3009 | if (die->tag == 0) | |
3010 | { | |
3011 | nesting_level--; | |
3012 | } | |
3013 | ||
3014 | die->next = NULL; | |
3015 | ||
3016 | /* Enter die in reference hash table */ | |
3017 | store_in_ref_table (die->offset, die); | |
3018 | ||
3019 | if (!first_die) | |
3020 | { | |
3021 | first_die = last_die = die; | |
3022 | } | |
3023 | else | |
3024 | { | |
3025 | last_die->next = die; | |
3026 | last_die = die; | |
3027 | } | |
3028 | } | |
3029 | while (nesting_level > 0); | |
3030 | return first_die; | |
3031 | } | |
3032 | ||
3033 | /* Free a linked list of dies. */ | |
3034 | ||
3035 | static void | |
3036 | free_die_list (dies) | |
3037 | struct die_info *dies; | |
3038 | { | |
3039 | struct die_info *die, *next; | |
3040 | ||
3041 | die = dies; | |
3042 | while (die) | |
3043 | { | |
3044 | next = die->next; | |
3045 | free (die->attrs); | |
3046 | free (die); | |
3047 | die = next; | |
3048 | } | |
3049 | } | |
3050 | ||
3051 | /* Read the contents of the section at OFFSET and of size SIZE from the | |
3052 | object file specified by OBJFILE into the psymbol_obstack and return it. */ | |
3053 | ||
3054 | static char * | |
3055 | dwarf2_read_section (objfile, offset, size) | |
3056 | struct objfile *objfile; | |
3057 | file_ptr offset; | |
3058 | unsigned int size; | |
3059 | { | |
3060 | bfd *abfd = objfile->obfd; | |
3061 | char *buf; | |
3062 | ||
3063 | if (size == 0) | |
3064 | return NULL; | |
3065 | ||
3066 | buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size); | |
3067 | if ((bfd_seek (abfd, offset, SEEK_SET) != 0) || | |
3068 | (bfd_read (buf, size, 1, abfd) != size)) | |
3069 | { | |
3070 | buf = NULL; | |
3071 | error ("Dwarf Error: Can't read DWARF data from '%s'", | |
c5aa993b | 3072 | bfd_get_filename (abfd)); |
c906108c SS |
3073 | } |
3074 | return buf; | |
3075 | } | |
3076 | ||
3077 | /* In DWARF version 2, the description of the debugging information is | |
3078 | stored in a separate .debug_abbrev section. Before we read any | |
3079 | dies from a section we read in all abbreviations and install them | |
3080 | in a hash table. */ | |
3081 | ||
3082 | static void | |
3083 | dwarf2_read_abbrevs (abfd, offset) | |
c5aa993b | 3084 | bfd *abfd; |
c906108c SS |
3085 | unsigned int offset; |
3086 | { | |
3087 | char *abbrev_ptr; | |
3088 | struct abbrev_info *cur_abbrev; | |
3089 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
3090 | unsigned int abbrev_form, hash_number; | |
3091 | ||
3092 | /* empty the table */ | |
3093 | dwarf2_empty_abbrev_table (NULL); | |
3094 | ||
3095 | abbrev_ptr = dwarf_abbrev_buffer + offset; | |
3096 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3097 | abbrev_ptr += bytes_read; | |
3098 | ||
3099 | /* loop until we reach an abbrev number of 0 */ | |
3100 | while (abbrev_number) | |
3101 | { | |
3102 | cur_abbrev = dwarf_alloc_abbrev (); | |
3103 | ||
3104 | /* read in abbrev header */ | |
3105 | cur_abbrev->number = abbrev_number; | |
3106 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3107 | abbrev_ptr += bytes_read; | |
3108 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
3109 | abbrev_ptr += 1; | |
3110 | ||
3111 | /* now read in declarations */ | |
3112 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3113 | abbrev_ptr += bytes_read; | |
3114 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3115 | abbrev_ptr += bytes_read; | |
3116 | while (abbrev_name) | |
3117 | { | |
3118 | if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0) | |
3119 | { | |
3120 | cur_abbrev->attrs = (struct attr_abbrev *) | |
3121 | xrealloc (cur_abbrev->attrs, | |
3122 | (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK) | |
c5aa993b | 3123 | * sizeof (struct attr_abbrev)); |
c906108c SS |
3124 | } |
3125 | cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name; | |
3126 | cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
3127 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3128 | abbrev_ptr += bytes_read; | |
3129 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3130 | abbrev_ptr += bytes_read; | |
3131 | } | |
3132 | ||
3133 | hash_number = abbrev_number % ABBREV_HASH_SIZE; | |
3134 | cur_abbrev->next = dwarf2_abbrevs[hash_number]; | |
3135 | dwarf2_abbrevs[hash_number] = cur_abbrev; | |
3136 | ||
3137 | /* Get next abbreviation. | |
3138 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
3139 | always properly terminated with an abbrev number of 0. |
3140 | Exit loop if we encounter an abbreviation which we have | |
3141 | already read (which means we are about to read the abbreviations | |
3142 | for the next compile unit) or if the end of the abbreviation | |
3143 | table is reached. */ | |
c906108c | 3144 | if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer) |
c5aa993b | 3145 | >= dwarf_abbrev_size) |
c906108c SS |
3146 | break; |
3147 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
3148 | abbrev_ptr += bytes_read; | |
3149 | if (dwarf2_lookup_abbrev (abbrev_number) != NULL) | |
3150 | break; | |
3151 | } | |
3152 | } | |
3153 | ||
3154 | /* Empty the abbrev table for a new compilation unit. */ | |
3155 | ||
3156 | /* ARGSUSED */ | |
3157 | static void | |
3158 | dwarf2_empty_abbrev_table (ignore) | |
3159 | PTR ignore; | |
3160 | { | |
3161 | int i; | |
3162 | struct abbrev_info *abbrev, *next; | |
3163 | ||
3164 | for (i = 0; i < ABBREV_HASH_SIZE; ++i) | |
3165 | { | |
3166 | next = NULL; | |
3167 | abbrev = dwarf2_abbrevs[i]; | |
3168 | while (abbrev) | |
3169 | { | |
3170 | next = abbrev->next; | |
3171 | free (abbrev->attrs); | |
3172 | free (abbrev); | |
3173 | abbrev = next; | |
3174 | } | |
3175 | dwarf2_abbrevs[i] = NULL; | |
3176 | } | |
3177 | } | |
3178 | ||
3179 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
3180 | ||
3181 | static struct abbrev_info * | |
3182 | dwarf2_lookup_abbrev (number) | |
3183 | unsigned int number; | |
3184 | { | |
3185 | unsigned int hash_number; | |
3186 | struct abbrev_info *abbrev; | |
3187 | ||
3188 | hash_number = number % ABBREV_HASH_SIZE; | |
3189 | abbrev = dwarf2_abbrevs[hash_number]; | |
3190 | ||
3191 | while (abbrev) | |
3192 | { | |
3193 | if (abbrev->number == number) | |
3194 | return abbrev; | |
3195 | else | |
3196 | abbrev = abbrev->next; | |
3197 | } | |
3198 | return NULL; | |
3199 | } | |
3200 | ||
3201 | /* Read a minimal amount of information into the minimal die structure. */ | |
3202 | ||
3203 | static char * | |
3204 | read_partial_die (part_die, abfd, info_ptr, has_pc_info) | |
3205 | struct partial_die_info *part_die; | |
c5aa993b | 3206 | bfd *abfd; |
c906108c SS |
3207 | char *info_ptr; |
3208 | int *has_pc_info; | |
3209 | { | |
3210 | unsigned int abbrev_number, bytes_read, i; | |
3211 | struct abbrev_info *abbrev; | |
3212 | struct attribute attr; | |
3213 | struct attribute spec_attr; | |
3214 | int found_spec_attr = 0; | |
c5aa993b | 3215 | int has_low_pc_attr = 0; |
c906108c SS |
3216 | int has_high_pc_attr = 0; |
3217 | ||
3218 | *part_die = zeroed_partial_die; | |
3219 | *has_pc_info = 0; | |
3220 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3221 | info_ptr += bytes_read; | |
3222 | if (!abbrev_number) | |
3223 | return info_ptr; | |
3224 | ||
3225 | abbrev = dwarf2_lookup_abbrev (abbrev_number); | |
3226 | if (!abbrev) | |
3227 | { | |
3228 | error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number); | |
3229 | } | |
3230 | part_die->offset = info_ptr - dwarf_info_buffer; | |
3231 | part_die->tag = abbrev->tag; | |
3232 | part_die->has_children = abbrev->has_children; | |
3233 | part_die->abbrev = abbrev_number; | |
3234 | ||
3235 | for (i = 0; i < abbrev->num_attrs; ++i) | |
3236 | { | |
3237 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr); | |
3238 | ||
3239 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 3240 | partial symbol table. */ |
c906108c SS |
3241 | switch (attr.name) |
3242 | { | |
3243 | case DW_AT_name: | |
3244 | ||
3245 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
3246 | if (part_die->name == NULL) | |
3247 | part_die->name = DW_STRING (&attr); | |
3248 | break; | |
3249 | case DW_AT_MIPS_linkage_name: | |
3250 | part_die->name = DW_STRING (&attr); | |
3251 | break; | |
3252 | case DW_AT_low_pc: | |
3253 | has_low_pc_attr = 1; | |
3254 | part_die->lowpc = DW_ADDR (&attr); | |
3255 | break; | |
3256 | case DW_AT_high_pc: | |
3257 | has_high_pc_attr = 1; | |
3258 | part_die->highpc = DW_ADDR (&attr); | |
3259 | break; | |
3260 | case DW_AT_location: | |
3261 | part_die->locdesc = DW_BLOCK (&attr); | |
3262 | break; | |
3263 | case DW_AT_language: | |
3264 | part_die->language = DW_UNSND (&attr); | |
3265 | break; | |
3266 | case DW_AT_external: | |
3267 | part_die->is_external = DW_UNSND (&attr); | |
3268 | break; | |
3269 | case DW_AT_declaration: | |
3270 | part_die->is_declaration = DW_UNSND (&attr); | |
3271 | break; | |
3272 | case DW_AT_type: | |
3273 | part_die->has_type = 1; | |
3274 | break; | |
3275 | case DW_AT_abstract_origin: | |
3276 | case DW_AT_specification: | |
3277 | found_spec_attr = 1; | |
3278 | spec_attr = attr; | |
3279 | break; | |
3280 | case DW_AT_sibling: | |
3281 | /* Ignore absolute siblings, they might point outside of | |
3282 | the current compile unit. */ | |
3283 | if (attr.form == DW_FORM_ref_addr) | |
c5aa993b | 3284 | complain (&dwarf2_absolute_sibling_complaint); |
c906108c SS |
3285 | else |
3286 | part_die->sibling = | |
3287 | dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr); | |
3288 | break; | |
3289 | default: | |
3290 | break; | |
3291 | } | |
3292 | } | |
3293 | ||
3294 | /* If we found a reference attribute and the die has no name, try | |
3295 | to find a name in the referred to die. */ | |
3296 | ||
3297 | if (found_spec_attr && part_die->name == NULL) | |
3298 | { | |
3299 | struct partial_die_info spec_die; | |
3300 | char *spec_ptr; | |
3301 | int dummy; | |
3302 | ||
3303 | spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr); | |
3304 | read_partial_die (&spec_die, abfd, spec_ptr, &dummy); | |
3305 | if (spec_die.name) | |
3306 | { | |
3307 | part_die->name = spec_die.name; | |
3308 | ||
3309 | /* Copy DW_AT_external attribute if it is set. */ | |
3310 | if (spec_die.is_external) | |
3311 | part_die->is_external = spec_die.is_external; | |
3312 | } | |
3313 | } | |
3314 | ||
3315 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3316 | eliminate duplicate copies of functions and vtables and such. | |
3317 | The linker will arbitrarily choose one and discard the others. | |
3318 | The AT_*_pc values for such functions refer to local labels in | |
3319 | these sections. If the section from that file was discarded, the | |
3320 | labels are not in the output, so the relocs get a value of 0. | |
3321 | If this is a discarded function, mark the pc bounds as invalid, | |
3322 | so that GDB will ignore it. */ | |
3323 | if (has_low_pc_attr && has_high_pc_attr | |
3324 | && part_die->lowpc < part_die->highpc | |
3325 | && (part_die->lowpc != 0 | |
3326 | || (bfd_get_file_flags (abfd) & HAS_RELOC))) | |
3327 | *has_pc_info = 1; | |
3328 | return info_ptr; | |
3329 | } | |
3330 | ||
3331 | /* Read the die from the .debug_info section buffer. And set diep to | |
3332 | point to a newly allocated die with its information. */ | |
3333 | ||
3334 | static char * | |
3335 | read_full_die (diep, abfd, info_ptr) | |
3336 | struct die_info **diep; | |
3337 | bfd *abfd; | |
3338 | char *info_ptr; | |
3339 | { | |
3340 | unsigned int abbrev_number, bytes_read, i, offset; | |
3341 | struct abbrev_info *abbrev; | |
3342 | struct die_info *die; | |
3343 | ||
3344 | offset = info_ptr - dwarf_info_buffer; | |
3345 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3346 | info_ptr += bytes_read; | |
3347 | if (!abbrev_number) | |
3348 | { | |
3349 | die = dwarf_alloc_die (); | |
3350 | die->tag = 0; | |
3351 | die->abbrev = abbrev_number; | |
3352 | die->type = NULL; | |
3353 | *diep = die; | |
3354 | return info_ptr; | |
3355 | } | |
3356 | ||
3357 | abbrev = dwarf2_lookup_abbrev (abbrev_number); | |
3358 | if (!abbrev) | |
3359 | { | |
3360 | error ("Dwarf Error: could not find abbrev number %d.", abbrev_number); | |
3361 | } | |
3362 | die = dwarf_alloc_die (); | |
3363 | die->offset = offset; | |
3364 | die->tag = abbrev->tag; | |
3365 | die->has_children = abbrev->has_children; | |
3366 | die->abbrev = abbrev_number; | |
3367 | die->type = NULL; | |
3368 | ||
3369 | die->num_attrs = abbrev->num_attrs; | |
3370 | die->attrs = (struct attribute *) | |
3371 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
3372 | ||
3373 | for (i = 0; i < abbrev->num_attrs; ++i) | |
3374 | { | |
3375 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
3376 | abfd, info_ptr); | |
3377 | } | |
3378 | ||
3379 | *diep = die; | |
3380 | return info_ptr; | |
3381 | } | |
3382 | ||
3383 | /* Read an attribute described by an abbreviated attribute. */ | |
3384 | ||
3385 | static char * | |
3386 | read_attribute (attr, abbrev, abfd, info_ptr) | |
3387 | struct attribute *attr; | |
3388 | struct attr_abbrev *abbrev; | |
3389 | bfd *abfd; | |
3390 | char *info_ptr; | |
3391 | { | |
3392 | unsigned int bytes_read; | |
3393 | struct dwarf_block *blk; | |
3394 | ||
3395 | attr->name = abbrev->name; | |
3396 | attr->form = abbrev->form; | |
3397 | switch (abbrev->form) | |
3398 | { | |
3399 | case DW_FORM_addr: | |
3400 | case DW_FORM_ref_addr: | |
3401 | DW_ADDR (attr) = read_address (abfd, info_ptr); | |
3402 | info_ptr += address_size; | |
3403 | break; | |
3404 | case DW_FORM_block2: | |
3405 | blk = dwarf_alloc_block (); | |
3406 | blk->size = read_2_bytes (abfd, info_ptr); | |
3407 | info_ptr += 2; | |
3408 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
3409 | info_ptr += blk->size; | |
3410 | DW_BLOCK (attr) = blk; | |
3411 | break; | |
3412 | case DW_FORM_block4: | |
3413 | blk = dwarf_alloc_block (); | |
3414 | blk->size = read_4_bytes (abfd, info_ptr); | |
3415 | info_ptr += 4; | |
3416 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
3417 | info_ptr += blk->size; | |
3418 | DW_BLOCK (attr) = blk; | |
3419 | break; | |
3420 | case DW_FORM_data2: | |
3421 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
3422 | info_ptr += 2; | |
3423 | break; | |
3424 | case DW_FORM_data4: | |
3425 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
3426 | info_ptr += 4; | |
3427 | break; | |
3428 | case DW_FORM_data8: | |
3429 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
3430 | info_ptr += 8; | |
3431 | break; | |
3432 | case DW_FORM_string: | |
3433 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
3434 | info_ptr += bytes_read; | |
3435 | break; | |
3436 | case DW_FORM_block: | |
3437 | blk = dwarf_alloc_block (); | |
3438 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3439 | info_ptr += bytes_read; | |
3440 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
3441 | info_ptr += blk->size; | |
3442 | DW_BLOCK (attr) = blk; | |
3443 | break; | |
3444 | case DW_FORM_block1: | |
3445 | blk = dwarf_alloc_block (); | |
3446 | blk->size = read_1_byte (abfd, info_ptr); | |
3447 | info_ptr += 1; | |
3448 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
3449 | info_ptr += blk->size; | |
3450 | DW_BLOCK (attr) = blk; | |
3451 | break; | |
3452 | case DW_FORM_data1: | |
3453 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
3454 | info_ptr += 1; | |
3455 | break; | |
3456 | case DW_FORM_flag: | |
3457 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
3458 | info_ptr += 1; | |
3459 | break; | |
3460 | case DW_FORM_sdata: | |
3461 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
3462 | info_ptr += bytes_read; | |
3463 | break; | |
3464 | case DW_FORM_udata: | |
3465 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3466 | info_ptr += bytes_read; | |
3467 | break; | |
3468 | case DW_FORM_ref1: | |
3469 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
3470 | info_ptr += 1; | |
3471 | break; | |
3472 | case DW_FORM_ref2: | |
3473 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
3474 | info_ptr += 2; | |
3475 | break; | |
3476 | case DW_FORM_ref4: | |
3477 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
3478 | info_ptr += 4; | |
3479 | break; | |
3480 | case DW_FORM_ref_udata: | |
3481 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3482 | info_ptr += bytes_read; | |
3483 | break; | |
3484 | case DW_FORM_strp: | |
3485 | case DW_FORM_indirect: | |
3486 | default: | |
3487 | error ("Dwarf Error: Cannot handle %s in DWARF reader.", | |
3488 | dwarf_form_name (abbrev->form)); | |
3489 | } | |
3490 | return info_ptr; | |
3491 | } | |
3492 | ||
3493 | /* read dwarf information from a buffer */ | |
3494 | ||
3495 | static unsigned int | |
3496 | read_1_byte (abfd, buf) | |
3497 | bfd *abfd; | |
3498 | char *buf; | |
3499 | { | |
3500 | return bfd_get_8 (abfd, (bfd_byte *) buf); | |
3501 | } | |
3502 | ||
3503 | static int | |
3504 | read_1_signed_byte (abfd, buf) | |
3505 | bfd *abfd; | |
3506 | char *buf; | |
3507 | { | |
3508 | return bfd_get_signed_8 (abfd, (bfd_byte *) buf); | |
3509 | } | |
3510 | ||
3511 | static unsigned int | |
3512 | read_2_bytes (abfd, buf) | |
3513 | bfd *abfd; | |
3514 | char *buf; | |
3515 | { | |
3516 | return bfd_get_16 (abfd, (bfd_byte *) buf); | |
3517 | } | |
3518 | ||
3519 | static int | |
3520 | read_2_signed_bytes (abfd, buf) | |
3521 | bfd *abfd; | |
3522 | char *buf; | |
3523 | { | |
3524 | return bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
3525 | } | |
3526 | ||
3527 | static unsigned int | |
3528 | read_4_bytes (abfd, buf) | |
3529 | bfd *abfd; | |
3530 | char *buf; | |
3531 | { | |
3532 | return bfd_get_32 (abfd, (bfd_byte *) buf); | |
3533 | } | |
3534 | ||
3535 | static int | |
3536 | read_4_signed_bytes (abfd, buf) | |
3537 | bfd *abfd; | |
3538 | char *buf; | |
3539 | { | |
3540 | return bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
3541 | } | |
3542 | ||
3543 | static unsigned int | |
3544 | read_8_bytes (abfd, buf) | |
3545 | bfd *abfd; | |
3546 | char *buf; | |
3547 | { | |
3548 | return bfd_get_64 (abfd, (bfd_byte *) buf); | |
3549 | } | |
3550 | ||
3551 | static CORE_ADDR | |
3552 | read_address (abfd, buf) | |
3553 | bfd *abfd; | |
3554 | char *buf; | |
3555 | { | |
3556 | CORE_ADDR retval = 0; | |
3557 | ||
3558 | switch (address_size) | |
3559 | { | |
3560 | case 4: | |
3561 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
3562 | break; | |
3563 | case 8: | |
3564 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
3565 | break; | |
3566 | default: | |
3567 | /* *THE* alternative is 8, right? */ | |
3568 | abort (); | |
3569 | } | |
3570 | /* If the address being read is larger than the address that is | |
3571 | applicable for the object file format then mask it down to the | |
3572 | correct size. Take care to avoid unnecessary shift or shift | |
3573 | overflow */ | |
3574 | if (address_size > address_significant_size | |
3575 | && address_significant_size < sizeof (CORE_ADDR)) | |
3576 | { | |
3577 | CORE_ADDR mask = ((CORE_ADDR) 0) - 1; | |
3578 | retval &= ~(mask << (address_significant_size * 8)); | |
3579 | } | |
3580 | return retval; | |
3581 | } | |
3582 | ||
3583 | static char * | |
3584 | read_n_bytes (abfd, buf, size) | |
c5aa993b | 3585 | bfd *abfd; |
c906108c SS |
3586 | char *buf; |
3587 | unsigned int size; | |
3588 | { | |
3589 | /* If the size of a host char is 8 bits, we can return a pointer | |
3590 | to the buffer, otherwise we have to copy the data to a buffer | |
3591 | allocated on the temporary obstack. */ | |
3592 | #if HOST_CHAR_BIT == 8 | |
3593 | return buf; | |
3594 | #else | |
3595 | char *ret; | |
3596 | unsigned int i; | |
3597 | ||
3598 | ret = obstack_alloc (&dwarf2_tmp_obstack, size); | |
3599 | for (i = 0; i < size; ++i) | |
3600 | { | |
3601 | ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf); | |
3602 | buf++; | |
3603 | } | |
3604 | return ret; | |
3605 | #endif | |
3606 | } | |
3607 | ||
3608 | static char * | |
3609 | read_string (abfd, buf, bytes_read_ptr) | |
3610 | bfd *abfd; | |
3611 | char *buf; | |
3612 | unsigned int *bytes_read_ptr; | |
3613 | { | |
3614 | /* If the size of a host char is 8 bits, we can return a pointer | |
3615 | to the string, otherwise we have to copy the string to a buffer | |
3616 | allocated on the temporary obstack. */ | |
3617 | #if HOST_CHAR_BIT == 8 | |
3618 | if (*buf == '\0') | |
3619 | { | |
3620 | *bytes_read_ptr = 1; | |
3621 | return NULL; | |
3622 | } | |
3623 | *bytes_read_ptr = strlen (buf) + 1; | |
3624 | return buf; | |
3625 | #else | |
3626 | int byte; | |
3627 | unsigned int i = 0; | |
3628 | ||
3629 | while ((byte = bfd_get_8 (abfd, (bfd_byte *) buf)) != 0) | |
3630 | { | |
3631 | obstack_1grow (&dwarf2_tmp_obstack, byte); | |
3632 | i++; | |
3633 | buf++; | |
3634 | } | |
3635 | if (i == 0) | |
3636 | { | |
3637 | *bytes_read_ptr = 1; | |
3638 | return NULL; | |
3639 | } | |
3640 | obstack_1grow (&dwarf2_tmp_obstack, '\0'); | |
3641 | *bytes_read_ptr = i + 1; | |
3642 | return obstack_finish (&dwarf2_tmp_obstack); | |
3643 | #endif | |
3644 | } | |
3645 | ||
3646 | static unsigned int | |
3647 | read_unsigned_leb128 (abfd, buf, bytes_read_ptr) | |
3648 | bfd *abfd; | |
3649 | char *buf; | |
3650 | unsigned int *bytes_read_ptr; | |
3651 | { | |
3652 | unsigned int result, num_read; | |
3653 | int i, shift; | |
3654 | unsigned char byte; | |
3655 | ||
3656 | result = 0; | |
3657 | shift = 0; | |
3658 | num_read = 0; | |
3659 | i = 0; | |
3660 | while (1) | |
3661 | { | |
3662 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
3663 | buf++; | |
3664 | num_read++; | |
3665 | result |= ((byte & 127) << shift); | |
3666 | if ((byte & 128) == 0) | |
3667 | { | |
3668 | break; | |
3669 | } | |
3670 | shift += 7; | |
3671 | } | |
3672 | *bytes_read_ptr = num_read; | |
3673 | return result; | |
3674 | } | |
3675 | ||
3676 | static int | |
3677 | read_signed_leb128 (abfd, buf, bytes_read_ptr) | |
3678 | bfd *abfd; | |
3679 | char *buf; | |
3680 | unsigned int *bytes_read_ptr; | |
3681 | { | |
3682 | int result; | |
3683 | int i, shift, size, num_read; | |
3684 | unsigned char byte; | |
3685 | ||
3686 | result = 0; | |
3687 | shift = 0; | |
3688 | size = 32; | |
3689 | num_read = 0; | |
3690 | i = 0; | |
3691 | while (1) | |
3692 | { | |
3693 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
3694 | buf++; | |
3695 | num_read++; | |
3696 | result |= ((byte & 127) << shift); | |
3697 | shift += 7; | |
3698 | if ((byte & 128) == 0) | |
3699 | { | |
3700 | break; | |
3701 | } | |
3702 | } | |
3703 | if ((shift < size) && (byte & 0x40)) | |
3704 | { | |
3705 | result |= -(1 << shift); | |
3706 | } | |
3707 | *bytes_read_ptr = num_read; | |
3708 | return result; | |
3709 | } | |
3710 | ||
3711 | static void | |
3712 | set_cu_language (lang) | |
3713 | unsigned int lang; | |
3714 | { | |
3715 | switch (lang) | |
3716 | { | |
3717 | case DW_LANG_C89: | |
3718 | case DW_LANG_C: | |
3719 | cu_language = language_c; | |
3720 | break; | |
3721 | case DW_LANG_C_plus_plus: | |
3722 | cu_language = language_cplus; | |
3723 | break; | |
3724 | case DW_LANG_Fortran77: | |
3725 | case DW_LANG_Fortran90: | |
3726 | cu_language = language_fortran; | |
3727 | break; | |
3728 | case DW_LANG_Mips_Assembler: | |
3729 | cu_language = language_asm; | |
3730 | break; | |
3731 | case DW_LANG_Ada83: | |
3732 | case DW_LANG_Cobol74: | |
3733 | case DW_LANG_Cobol85: | |
3734 | case DW_LANG_Pascal83: | |
3735 | case DW_LANG_Modula2: | |
3736 | default: | |
3737 | cu_language = language_unknown; | |
3738 | break; | |
3739 | } | |
3740 | cu_language_defn = language_def (cu_language); | |
3741 | } | |
3742 | ||
3743 | /* Return the named attribute or NULL if not there. */ | |
3744 | ||
3745 | static struct attribute * | |
3746 | dwarf_attr (die, name) | |
3747 | struct die_info *die; | |
3748 | unsigned int name; | |
3749 | { | |
3750 | unsigned int i; | |
3751 | struct attribute *spec = NULL; | |
3752 | ||
3753 | for (i = 0; i < die->num_attrs; ++i) | |
3754 | { | |
3755 | if (die->attrs[i].name == name) | |
3756 | { | |
3757 | return &die->attrs[i]; | |
3758 | } | |
3759 | if (die->attrs[i].name == DW_AT_specification | |
3760 | || die->attrs[i].name == DW_AT_abstract_origin) | |
3761 | spec = &die->attrs[i]; | |
3762 | } | |
3763 | if (spec) | |
3764 | { | |
3765 | struct die_info *ref_die = | |
c5aa993b | 3766 | follow_die_ref (dwarf2_get_ref_die_offset (spec)); |
c906108c SS |
3767 | |
3768 | if (ref_die) | |
3769 | return dwarf_attr (ref_die, name); | |
3770 | } | |
c5aa993b | 3771 | |
c906108c SS |
3772 | return NULL; |
3773 | } | |
3774 | ||
3775 | /* Decode the line number information for the compilation unit whose | |
3776 | line number info is at OFFSET in the .debug_line section. | |
3777 | The compilation directory of the file is passed in COMP_DIR. */ | |
3778 | ||
3779 | struct filenames | |
3780 | { | |
3781 | unsigned int num_files; | |
3782 | struct fileinfo | |
c5aa993b JM |
3783 | { |
3784 | char *name; | |
3785 | unsigned int dir; | |
3786 | unsigned int time; | |
3787 | unsigned int size; | |
3788 | } | |
3789 | *files; | |
c906108c SS |
3790 | }; |
3791 | ||
3792 | struct directories | |
c5aa993b JM |
3793 | { |
3794 | unsigned int num_dirs; | |
3795 | char **dirs; | |
3796 | }; | |
c906108c SS |
3797 | |
3798 | static void | |
3799 | dwarf_decode_lines (offset, comp_dir, abfd) | |
3800 | unsigned int offset; | |
3801 | char *comp_dir; | |
3802 | bfd *abfd; | |
3803 | { | |
3804 | char *line_ptr; | |
3805 | char *line_end; | |
3806 | struct line_head lh; | |
3807 | struct cleanup *back_to; | |
3808 | unsigned int i, bytes_read; | |
3809 | char *cur_file, *cur_dir; | |
3810 | unsigned char op_code, extended_op, adj_opcode; | |
3811 | ||
3812 | #define FILE_ALLOC_CHUNK 5 | |
3813 | #define DIR_ALLOC_CHUNK 5 | |
3814 | ||
3815 | struct filenames files; | |
3816 | struct directories dirs; | |
3817 | ||
3818 | if (dwarf_line_buffer == NULL) | |
3819 | { | |
3820 | complain (&dwarf2_missing_line_number_section); | |
3821 | return; | |
3822 | } | |
3823 | ||
3824 | files.num_files = 0; | |
3825 | files.files = NULL; | |
3826 | ||
3827 | dirs.num_dirs = 0; | |
3828 | dirs.dirs = NULL; | |
3829 | ||
3830 | line_ptr = dwarf_line_buffer + offset; | |
3831 | ||
3832 | /* read in the prologue */ | |
3833 | lh.total_length = read_4_bytes (abfd, line_ptr); | |
3834 | line_ptr += 4; | |
3835 | line_end = line_ptr + lh.total_length; | |
3836 | lh.version = read_2_bytes (abfd, line_ptr); | |
3837 | line_ptr += 2; | |
3838 | lh.prologue_length = read_4_bytes (abfd, line_ptr); | |
3839 | line_ptr += 4; | |
3840 | lh.minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
3841 | line_ptr += 1; | |
3842 | lh.default_is_stmt = read_1_byte (abfd, line_ptr); | |
3843 | line_ptr += 1; | |
3844 | lh.line_base = read_1_signed_byte (abfd, line_ptr); | |
3845 | line_ptr += 1; | |
3846 | lh.line_range = read_1_byte (abfd, line_ptr); | |
3847 | line_ptr += 1; | |
3848 | lh.opcode_base = read_1_byte (abfd, line_ptr); | |
3849 | line_ptr += 1; | |
3850 | lh.standard_opcode_lengths = (unsigned char *) | |
3851 | xmalloc (lh.opcode_base * sizeof (unsigned char)); | |
c5aa993b JM |
3852 | back_to = make_cleanup ((make_cleanup_func) free_current_contents, |
3853 | &lh.standard_opcode_lengths); | |
c906108c SS |
3854 | |
3855 | lh.standard_opcode_lengths[0] = 1; | |
3856 | for (i = 1; i < lh.opcode_base; ++i) | |
3857 | { | |
3858 | lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
3859 | line_ptr += 1; | |
3860 | } | |
3861 | ||
3862 | /* Read directory table */ | |
3863 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
3864 | { | |
3865 | line_ptr += bytes_read; | |
3866 | if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0) | |
3867 | { | |
3868 | dirs.dirs = (char **) | |
3869 | xrealloc (dirs.dirs, | |
3870 | (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *)); | |
3871 | if (dirs.num_dirs == 0) | |
3872 | make_cleanup ((make_cleanup_func) free_current_contents, &dirs.dirs); | |
3873 | } | |
3874 | dirs.dirs[dirs.num_dirs++] = cur_dir; | |
3875 | } | |
3876 | line_ptr += bytes_read; | |
3877 | ||
3878 | /* Read file name table */ | |
3879 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
3880 | { | |
3881 | line_ptr += bytes_read; | |
3882 | if ((files.num_files % FILE_ALLOC_CHUNK) == 0) | |
3883 | { | |
3884 | files.files = (struct fileinfo *) | |
3885 | xrealloc (files.files, | |
3886 | (files.num_files + FILE_ALLOC_CHUNK) | |
c5aa993b | 3887 | * sizeof (struct fileinfo)); |
c906108c | 3888 | if (files.num_files == 0) |
c5aa993b JM |
3889 | make_cleanup ((make_cleanup_func) free_current_contents, |
3890 | &files.files); | |
c906108c SS |
3891 | } |
3892 | files.files[files.num_files].name = cur_file; | |
3893 | files.files[files.num_files].dir = | |
3894 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3895 | line_ptr += bytes_read; | |
3896 | files.files[files.num_files].time = | |
3897 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3898 | line_ptr += bytes_read; | |
3899 | files.files[files.num_files].size = | |
3900 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3901 | line_ptr += bytes_read; | |
3902 | files.num_files++; | |
3903 | } | |
3904 | line_ptr += bytes_read; | |
3905 | ||
3906 | /* Read the statement sequences until there's nothing left. */ | |
3907 | while (line_ptr < line_end) | |
3908 | { | |
3909 | /* state machine registers */ | |
3910 | CORE_ADDR address = 0; | |
3911 | unsigned int file = 1; | |
3912 | unsigned int line = 1; | |
3913 | unsigned int column = 0; | |
3914 | int is_stmt = lh.default_is_stmt; | |
3915 | int basic_block = 0; | |
3916 | int end_sequence = 0; | |
3917 | ||
3918 | /* Start a subfile for the current file of the state machine. */ | |
3919 | if (files.num_files >= file) | |
3920 | { | |
3921 | /* The file and directory tables are 0 based, the references | |
3922 | are 1 based. */ | |
3923 | dwarf2_start_subfile (files.files[file - 1].name, | |
3924 | (files.files[file - 1].dir | |
3925 | ? dirs.dirs[files.files[file - 1].dir - 1] | |
3926 | : comp_dir)); | |
3927 | } | |
3928 | ||
3929 | /* Decode the table. */ | |
c5aa993b | 3930 | while (!end_sequence) |
c906108c SS |
3931 | { |
3932 | op_code = read_1_byte (abfd, line_ptr); | |
3933 | line_ptr += 1; | |
3934 | switch (op_code) | |
3935 | { | |
3936 | case DW_LNS_extended_op: | |
3937 | line_ptr += 1; /* ignore length */ | |
3938 | extended_op = read_1_byte (abfd, line_ptr); | |
3939 | line_ptr += 1; | |
3940 | switch (extended_op) | |
3941 | { | |
3942 | case DW_LNE_end_sequence: | |
3943 | end_sequence = 1; | |
7a292a7a SS |
3944 | /* Don't call record_line here. The end_sequence |
3945 | instruction provides the address of the first byte | |
3946 | *after* the last line in the sequence; it's not the | |
3947 | address of any real source line. However, the GDB | |
3948 | linetable structure only records the starts of lines, | |
3949 | not the ends. This is a weakness of GDB. */ | |
c906108c SS |
3950 | break; |
3951 | case DW_LNE_set_address: | |
3952 | address = read_address (abfd, line_ptr) + baseaddr; | |
3953 | line_ptr += address_size; | |
3954 | break; | |
3955 | case DW_LNE_define_file: | |
3956 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
3957 | line_ptr += bytes_read; | |
3958 | if ((files.num_files % FILE_ALLOC_CHUNK) == 0) | |
3959 | { | |
3960 | files.files = (struct fileinfo *) | |
3961 | xrealloc (files.files, | |
3962 | (files.num_files + FILE_ALLOC_CHUNK) | |
c5aa993b | 3963 | * sizeof (struct fileinfo)); |
c906108c | 3964 | if (files.num_files == 0) |
c5aa993b JM |
3965 | make_cleanup ((make_cleanup_func) free_current_contents, |
3966 | &files.files); | |
c906108c SS |
3967 | } |
3968 | files.files[files.num_files].name = cur_file; | |
3969 | files.files[files.num_files].dir = | |
3970 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3971 | line_ptr += bytes_read; | |
3972 | files.files[files.num_files].time = | |
3973 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3974 | line_ptr += bytes_read; | |
3975 | files.files[files.num_files].size = | |
3976 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3977 | line_ptr += bytes_read; | |
3978 | files.num_files++; | |
3979 | break; | |
3980 | default: | |
3981 | complain (&dwarf2_mangled_line_number_section); | |
3982 | goto done; | |
3983 | } | |
3984 | break; | |
3985 | case DW_LNS_copy: | |
3986 | record_line (current_subfile, line, address); | |
3987 | basic_block = 0; | |
3988 | break; | |
3989 | case DW_LNS_advance_pc: | |
3990 | address += lh.minimum_instruction_length | |
3991 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
3992 | line_ptr += bytes_read; | |
3993 | break; | |
3994 | case DW_LNS_advance_line: | |
3995 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
3996 | line_ptr += bytes_read; | |
3997 | break; | |
3998 | case DW_LNS_set_file: | |
3999 | /* The file and directory tables are 0 based, the references | |
c5aa993b | 4000 | are 1 based. */ |
c906108c SS |
4001 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
4002 | line_ptr += bytes_read; | |
4003 | dwarf2_start_subfile | |
4004 | (files.files[file - 1].name, | |
4005 | (files.files[file - 1].dir | |
4006 | ? dirs.dirs[files.files[file - 1].dir - 1] | |
4007 | : comp_dir)); | |
4008 | break; | |
4009 | case DW_LNS_set_column: | |
4010 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
4011 | line_ptr += bytes_read; | |
4012 | break; | |
4013 | case DW_LNS_negate_stmt: | |
4014 | is_stmt = (!is_stmt); | |
4015 | break; | |
4016 | case DW_LNS_set_basic_block: | |
4017 | basic_block = 1; | |
4018 | break; | |
4019 | case DW_LNS_const_add_pc: | |
4020 | address += (255 - lh.opcode_base) / lh.line_range; | |
4021 | break; | |
4022 | case DW_LNS_fixed_advance_pc: | |
4023 | address += read_2_bytes (abfd, line_ptr); | |
4024 | line_ptr += 2; | |
4025 | break; | |
4026 | default: /* special operand */ | |
4027 | adj_opcode = op_code - lh.opcode_base; | |
4028 | address += (adj_opcode / lh.line_range) | |
4029 | * lh.minimum_instruction_length; | |
4030 | line += lh.line_base + (adj_opcode % lh.line_range); | |
4031 | /* append row to matrix using current values */ | |
4032 | record_line (current_subfile, line, address); | |
4033 | basic_block = 1; | |
4034 | } | |
4035 | } | |
4036 | } | |
4037 | done: | |
4038 | do_cleanups (back_to); | |
4039 | } | |
4040 | ||
4041 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
4042 | DIRNAME the name of the source directory which contains FILENAME | |
4043 | or NULL if not known. | |
4044 | This routine tries to keep line numbers from identical absolute and | |
4045 | relative file names in a common subfile. | |
4046 | ||
4047 | Using the `list' example from the GDB testsuite, which resides in | |
4048 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
4049 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
4050 | ||
c5aa993b JM |
4051 | DW_AT_name: /srcdir/list0.c |
4052 | DW_AT_comp_dir: /compdir | |
4053 | files.files[0].name: list0.h | |
4054 | files.files[0].dir: /srcdir | |
4055 | files.files[1].name: list0.c | |
4056 | files.files[1].dir: /srcdir | |
c906108c SS |
4057 | |
4058 | The line number information for list0.c has to end up in a single | |
4059 | subfile, so that `break /srcdir/list0.c:1' works as expected. */ | |
4060 | ||
4061 | static void | |
4062 | dwarf2_start_subfile (filename, dirname) | |
4063 | char *filename; | |
4064 | char *dirname; | |
4065 | { | |
4066 | /* If the filename isn't absolute, try to match an existing subfile | |
4067 | with the full pathname. */ | |
4068 | ||
4069 | if (*filename != '/' && dirname != NULL) | |
4070 | { | |
4071 | struct subfile *subfile; | |
4072 | char *fullname = concat (dirname, "/", filename, NULL); | |
4073 | ||
4074 | for (subfile = subfiles; subfile; subfile = subfile->next) | |
4075 | { | |
4076 | if (STREQ (subfile->name, fullname)) | |
4077 | { | |
4078 | current_subfile = subfile; | |
4079 | free (fullname); | |
4080 | return; | |
4081 | } | |
4082 | } | |
4083 | free (fullname); | |
4084 | } | |
4085 | start_subfile (filename, dirname); | |
4086 | } | |
4087 | ||
4088 | /* Given a pointer to a DWARF information entry, figure out if we need | |
4089 | to make a symbol table entry for it, and if so, create a new entry | |
4090 | and return a pointer to it. | |
4091 | If TYPE is NULL, determine symbol type from the die, otherwise | |
4092 | used the passed type. | |
c5aa993b | 4093 | */ |
c906108c SS |
4094 | |
4095 | static struct symbol * | |
4096 | new_symbol (die, type, objfile) | |
4097 | struct die_info *die; | |
4098 | struct type *type; | |
4099 | struct objfile *objfile; | |
4100 | { | |
4101 | struct symbol *sym = NULL; | |
4102 | char *name; | |
4103 | struct attribute *attr = NULL; | |
4104 | struct attribute *attr2 = NULL; | |
4105 | CORE_ADDR addr; | |
4106 | ||
4107 | name = dwarf2_linkage_name (die); | |
4108 | if (name) | |
4109 | { | |
4110 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, | |
4111 | sizeof (struct symbol)); | |
4112 | OBJSTAT (objfile, n_syms++); | |
4113 | memset (sym, 0, sizeof (struct symbol)); | |
4114 | SYMBOL_NAME (sym) = obsavestring (name, strlen (name), | |
4115 | &objfile->symbol_obstack); | |
4116 | ||
4117 | /* Default assumptions. | |
c5aa993b | 4118 | Use the passed type or decode it from the die. */ |
c906108c SS |
4119 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
4120 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
4121 | if (type != NULL) | |
4122 | SYMBOL_TYPE (sym) = type; | |
4123 | else | |
4124 | SYMBOL_TYPE (sym) = die_type (die, objfile); | |
4125 | attr = dwarf_attr (die, DW_AT_decl_line); | |
4126 | if (attr) | |
4127 | { | |
4128 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
4129 | } | |
4130 | ||
4131 | /* If this symbol is from a C++ compilation, then attempt to | |
4132 | cache the demangled form for future reference. This is a | |
4133 | typical time versus space tradeoff, that was decided in favor | |
4134 | of time because it sped up C++ symbol lookups by a factor of | |
4135 | about 20. */ | |
4136 | ||
4137 | SYMBOL_LANGUAGE (sym) = cu_language; | |
4138 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); | |
4139 | switch (die->tag) | |
4140 | { | |
4141 | case DW_TAG_label: | |
4142 | attr = dwarf_attr (die, DW_AT_low_pc); | |
4143 | if (attr) | |
4144 | { | |
4145 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
4146 | } | |
4147 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
4148 | break; | |
4149 | case DW_TAG_subprogram: | |
4150 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
4151 | finish_block. */ | |
4152 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
4153 | attr2 = dwarf_attr (die, DW_AT_external); | |
4154 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
4155 | { | |
4156 | add_symbol_to_list (sym, &global_symbols); | |
4157 | } | |
4158 | else | |
4159 | { | |
4160 | add_symbol_to_list (sym, list_in_scope); | |
4161 | } | |
4162 | break; | |
4163 | case DW_TAG_variable: | |
4164 | /* Compilation with minimal debug info may result in variables | |
4165 | with missing type entries. Change the misleading `void' type | |
4166 | to something sensible. */ | |
4167 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
4168 | SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, | |
4169 | TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
4170 | "<variable, no debug info>", | |
4171 | objfile); | |
4172 | attr = dwarf_attr (die, DW_AT_const_value); | |
4173 | if (attr) | |
4174 | { | |
4175 | dwarf2_const_value (attr, sym, objfile); | |
4176 | attr2 = dwarf_attr (die, DW_AT_external); | |
4177 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
4178 | add_symbol_to_list (sym, &global_symbols); | |
4179 | else | |
4180 | add_symbol_to_list (sym, list_in_scope); | |
4181 | break; | |
4182 | } | |
4183 | attr = dwarf_attr (die, DW_AT_location); | |
4184 | if (attr) | |
4185 | { | |
4186 | attr2 = dwarf_attr (die, DW_AT_external); | |
4187 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
4188 | { | |
4189 | SYMBOL_VALUE_ADDRESS (sym) = | |
4190 | decode_locdesc (DW_BLOCK (attr), objfile); | |
4191 | add_symbol_to_list (sym, &global_symbols); | |
4192 | ||
c5aa993b | 4193 | /* In shared libraries the address of the variable |
c906108c SS |
4194 | in the location descriptor might still be relocatable, |
4195 | so its value could be zero. | |
4196 | Enter the symbol as a LOC_UNRESOLVED symbol, if its | |
4197 | value is zero, the address of the variable will then | |
4198 | be determined from the minimal symbol table whenever | |
4199 | the variable is referenced. */ | |
4200 | if (SYMBOL_VALUE_ADDRESS (sym)) | |
4201 | { | |
4202 | SYMBOL_VALUE_ADDRESS (sym) += baseaddr; | |
4203 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
4204 | } | |
4205 | else | |
4206 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
4207 | } | |
4208 | else | |
4209 | { | |
4210 | SYMBOL_VALUE (sym) = addr = | |
4211 | decode_locdesc (DW_BLOCK (attr), objfile); | |
4212 | add_symbol_to_list (sym, list_in_scope); | |
4213 | if (optimized_out) | |
4214 | { | |
4215 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
4216 | } | |
4217 | else if (isreg) | |
4218 | { | |
4219 | SYMBOL_CLASS (sym) = LOC_REGISTER; | |
4220 | } | |
4221 | else if (offreg) | |
4222 | { | |
4223 | SYMBOL_CLASS (sym) = LOC_BASEREG; | |
4224 | SYMBOL_BASEREG (sym) = basereg; | |
4225 | } | |
4226 | else if (islocal) | |
4227 | { | |
4228 | SYMBOL_CLASS (sym) = LOC_LOCAL; | |
4229 | } | |
4230 | else | |
4231 | { | |
4232 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
4233 | SYMBOL_VALUE_ADDRESS (sym) = addr + baseaddr; | |
4234 | } | |
4235 | } | |
4236 | } | |
4237 | else | |
4238 | { | |
4239 | /* We do not know the address of this symbol. | |
c5aa993b JM |
4240 | If it is an external symbol and we have type information |
4241 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
4242 | The address of the variable will then be determined from | |
4243 | the minimal symbol table whenever the variable is | |
4244 | referenced. */ | |
c906108c SS |
4245 | attr2 = dwarf_attr (die, DW_AT_external); |
4246 | if (attr2 && (DW_UNSND (attr2) != 0) | |
4247 | && dwarf_attr (die, DW_AT_type) != NULL) | |
4248 | { | |
4249 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
4250 | add_symbol_to_list (sym, &global_symbols); | |
4251 | } | |
4252 | } | |
4253 | break; | |
4254 | case DW_TAG_formal_parameter: | |
4255 | attr = dwarf_attr (die, DW_AT_location); | |
4256 | if (attr) | |
4257 | { | |
4258 | SYMBOL_VALUE (sym) = decode_locdesc (DW_BLOCK (attr), objfile); | |
4259 | if (isreg) | |
4260 | { | |
4261 | SYMBOL_CLASS (sym) = LOC_REGPARM; | |
4262 | } | |
4263 | else if (offreg) | |
4264 | { | |
7a292a7a SS |
4265 | if (isderef) |
4266 | { | |
4267 | if (basereg != frame_base_reg) | |
4268 | complain (&dwarf2_complex_location_expr); | |
4269 | SYMBOL_CLASS (sym) = LOC_REF_ARG; | |
4270 | } | |
4271 | else | |
4272 | { | |
4273 | SYMBOL_CLASS (sym) = LOC_BASEREG_ARG; | |
4274 | SYMBOL_BASEREG (sym) = basereg; | |
4275 | } | |
c906108c SS |
4276 | } |
4277 | else | |
4278 | { | |
4279 | SYMBOL_CLASS (sym) = LOC_ARG; | |
4280 | } | |
4281 | } | |
4282 | attr = dwarf_attr (die, DW_AT_const_value); | |
4283 | if (attr) | |
4284 | { | |
4285 | dwarf2_const_value (attr, sym, objfile); | |
4286 | } | |
4287 | add_symbol_to_list (sym, list_in_scope); | |
4288 | break; | |
4289 | case DW_TAG_unspecified_parameters: | |
4290 | /* From varargs functions; gdb doesn't seem to have any | |
4291 | interest in this information, so just ignore it for now. | |
4292 | (FIXME?) */ | |
4293 | break; | |
4294 | case DW_TAG_class_type: | |
4295 | case DW_TAG_structure_type: | |
4296 | case DW_TAG_union_type: | |
4297 | case DW_TAG_enumeration_type: | |
4298 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
4299 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
4300 | add_symbol_to_list (sym, list_in_scope); | |
4301 | ||
4302 | /* The semantics of C++ state that "struct foo { ... }" also | |
4303 | defines a typedef for "foo". Synthesize a typedef symbol so | |
4304 | that "ptype foo" works as expected. */ | |
4305 | if (cu_language == language_cplus) | |
4306 | { | |
4307 | struct symbol *typedef_sym = (struct symbol *) | |
c5aa993b JM |
4308 | obstack_alloc (&objfile->symbol_obstack, |
4309 | sizeof (struct symbol)); | |
c906108c SS |
4310 | *typedef_sym = *sym; |
4311 | SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; | |
4312 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
4313 | TYPE_NAME (SYMBOL_TYPE (sym)) = | |
4314 | obsavestring (SYMBOL_NAME (sym), | |
4315 | strlen (SYMBOL_NAME (sym)), | |
4316 | &objfile->type_obstack); | |
4317 | add_symbol_to_list (typedef_sym, list_in_scope); | |
4318 | } | |
4319 | break; | |
4320 | case DW_TAG_typedef: | |
4321 | case DW_TAG_base_type: | |
4322 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
4323 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; | |
4324 | add_symbol_to_list (sym, list_in_scope); | |
4325 | break; | |
4326 | case DW_TAG_enumerator: | |
4327 | attr = dwarf_attr (die, DW_AT_const_value); | |
4328 | if (attr) | |
4329 | { | |
4330 | dwarf2_const_value (attr, sym, objfile); | |
4331 | } | |
4332 | add_symbol_to_list (sym, list_in_scope); | |
4333 | break; | |
4334 | default: | |
4335 | /* Not a tag we recognize. Hopefully we aren't processing | |
4336 | trash data, but since we must specifically ignore things | |
4337 | we don't recognize, there is nothing else we should do at | |
4338 | this point. */ | |
4339 | complain (&dwarf2_unsupported_tag, dwarf_tag_name (die->tag)); | |
4340 | break; | |
4341 | } | |
4342 | } | |
4343 | return (sym); | |
4344 | } | |
4345 | ||
4346 | /* Copy constant value from an attribute to a symbol. */ | |
4347 | ||
4348 | static void | |
4349 | dwarf2_const_value (attr, sym, objfile) | |
4350 | struct attribute *attr; | |
4351 | struct symbol *sym; | |
4352 | struct objfile *objfile; | |
4353 | { | |
4354 | struct dwarf_block *blk; | |
4355 | ||
4356 | switch (attr->form) | |
4357 | { | |
4358 | case DW_FORM_addr: | |
4359 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != (unsigned int) address_size) | |
4360 | complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym), | |
4361 | address_size, TYPE_LENGTH (SYMBOL_TYPE (sym))); | |
4362 | SYMBOL_VALUE_BYTES (sym) = (char *) | |
4363 | obstack_alloc (&objfile->symbol_obstack, address_size); | |
4364 | store_address (SYMBOL_VALUE_BYTES (sym), address_size, DW_ADDR (attr)); | |
4365 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
4366 | break; | |
4367 | case DW_FORM_block1: | |
4368 | case DW_FORM_block2: | |
4369 | case DW_FORM_block4: | |
4370 | case DW_FORM_block: | |
4371 | blk = DW_BLOCK (attr); | |
4372 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
4373 | complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym), | |
4374 | blk->size, TYPE_LENGTH (SYMBOL_TYPE (sym))); | |
4375 | SYMBOL_VALUE_BYTES (sym) = (char *) | |
4376 | obstack_alloc (&objfile->symbol_obstack, blk->size); | |
4377 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); | |
4378 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
4379 | break; | |
4380 | case DW_FORM_data2: | |
4381 | case DW_FORM_data4: | |
4382 | case DW_FORM_data8: | |
4383 | case DW_FORM_data1: | |
4384 | case DW_FORM_sdata: | |
4385 | case DW_FORM_udata: | |
4386 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
4387 | SYMBOL_CLASS (sym) = LOC_CONST; | |
4388 | break; | |
4389 | default: | |
4390 | complain (&dwarf2_unsupported_const_value_attr, | |
4391 | dwarf_form_name (attr->form)); | |
4392 | SYMBOL_VALUE (sym) = 0; | |
4393 | SYMBOL_CLASS (sym) = LOC_CONST; | |
4394 | break; | |
4395 | } | |
4396 | } | |
4397 | ||
4398 | /* Return the type of the die in question using its DW_AT_type attribute. */ | |
4399 | ||
4400 | static struct type * | |
4401 | die_type (die, objfile) | |
4402 | struct die_info *die; | |
4403 | struct objfile *objfile; | |
4404 | { | |
4405 | struct type *type; | |
4406 | struct attribute *type_attr; | |
4407 | struct die_info *type_die; | |
4408 | unsigned int ref; | |
4409 | ||
4410 | type_attr = dwarf_attr (die, DW_AT_type); | |
4411 | if (!type_attr) | |
4412 | { | |
4413 | /* A missing DW_AT_type represents a void type. */ | |
4414 | return dwarf2_fundamental_type (objfile, FT_VOID); | |
4415 | } | |
4416 | else | |
4417 | { | |
4418 | ref = dwarf2_get_ref_die_offset (type_attr); | |
4419 | type_die = follow_die_ref (ref); | |
4420 | if (!type_die) | |
4421 | { | |
4422 | error ("Dwarf Error: Cannot find referent at offset %d.", ref); | |
4423 | return NULL; | |
4424 | } | |
4425 | } | |
4426 | type = tag_type_to_type (type_die, objfile); | |
4427 | if (!type) | |
4428 | { | |
4429 | dump_die (type_die); | |
4430 | error ("Dwarf Error: Problem turning type die at offset into gdb type."); | |
4431 | } | |
4432 | return type; | |
4433 | } | |
4434 | ||
4435 | /* Return the containing type of the die in question using its | |
4436 | DW_AT_containing_type attribute. */ | |
4437 | ||
4438 | static struct type * | |
4439 | die_containing_type (die, objfile) | |
4440 | struct die_info *die; | |
4441 | struct objfile *objfile; | |
4442 | { | |
4443 | struct type *type = NULL; | |
4444 | struct attribute *type_attr; | |
4445 | struct die_info *type_die = NULL; | |
4446 | unsigned int ref; | |
4447 | ||
4448 | type_attr = dwarf_attr (die, DW_AT_containing_type); | |
4449 | if (type_attr) | |
4450 | { | |
4451 | ref = dwarf2_get_ref_die_offset (type_attr); | |
4452 | type_die = follow_die_ref (ref); | |
4453 | if (!type_die) | |
4454 | { | |
4455 | error ("Dwarf Error: Cannot find referent at offset %d.", ref); | |
4456 | return NULL; | |
4457 | } | |
4458 | type = tag_type_to_type (type_die, objfile); | |
4459 | } | |
4460 | if (!type) | |
4461 | { | |
4462 | if (type_die) | |
4463 | dump_die (type_die); | |
4464 | error ("Dwarf Error: Problem turning containing type into gdb type."); | |
4465 | } | |
4466 | return type; | |
4467 | } | |
4468 | ||
4469 | #if 0 | |
4470 | static struct type * | |
4471 | type_at_offset (offset, objfile) | |
4472 | unsigned int offset; | |
4473 | struct objfile *objfile; | |
4474 | { | |
4475 | struct die_info *die; | |
4476 | struct type *type; | |
4477 | ||
4478 | die = follow_die_ref (offset); | |
4479 | if (!die) | |
4480 | { | |
4481 | error ("Dwarf Error: Cannot find type referent at offset %d.", offset); | |
4482 | return NULL; | |
4483 | } | |
4484 | type = tag_type_to_type (die, objfile); | |
4485 | return type; | |
4486 | } | |
4487 | #endif | |
4488 | ||
4489 | static struct type * | |
4490 | tag_type_to_type (die, objfile) | |
4491 | struct die_info *die; | |
4492 | struct objfile *objfile; | |
4493 | { | |
4494 | if (die->type) | |
4495 | { | |
4496 | return die->type; | |
4497 | } | |
4498 | else | |
4499 | { | |
4500 | read_type_die (die, objfile); | |
4501 | if (!die->type) | |
4502 | { | |
4503 | dump_die (die); | |
4504 | error ("Dwarf Error: Cannot find type of die."); | |
4505 | } | |
4506 | return die->type; | |
4507 | } | |
4508 | } | |
4509 | ||
4510 | static void | |
4511 | read_type_die (die, objfile) | |
4512 | struct die_info *die; | |
4513 | struct objfile *objfile; | |
4514 | { | |
4515 | switch (die->tag) | |
4516 | { | |
4517 | case DW_TAG_class_type: | |
4518 | case DW_TAG_structure_type: | |
4519 | case DW_TAG_union_type: | |
4520 | read_structure_scope (die, objfile); | |
4521 | break; | |
4522 | case DW_TAG_enumeration_type: | |
4523 | read_enumeration (die, objfile); | |
4524 | break; | |
4525 | case DW_TAG_subprogram: | |
4526 | case DW_TAG_subroutine_type: | |
4527 | read_subroutine_type (die, objfile); | |
4528 | break; | |
4529 | case DW_TAG_array_type: | |
4530 | read_array_type (die, objfile); | |
4531 | break; | |
4532 | case DW_TAG_pointer_type: | |
4533 | read_tag_pointer_type (die, objfile); | |
4534 | break; | |
4535 | case DW_TAG_ptr_to_member_type: | |
4536 | read_tag_ptr_to_member_type (die, objfile); | |
4537 | break; | |
4538 | case DW_TAG_reference_type: | |
4539 | read_tag_reference_type (die, objfile); | |
4540 | break; | |
4541 | case DW_TAG_const_type: | |
4542 | read_tag_const_type (die, objfile); | |
4543 | break; | |
4544 | case DW_TAG_volatile_type: | |
4545 | read_tag_volatile_type (die, objfile); | |
4546 | break; | |
4547 | case DW_TAG_string_type: | |
4548 | read_tag_string_type (die, objfile); | |
4549 | break; | |
4550 | case DW_TAG_typedef: | |
4551 | read_typedef (die, objfile); | |
4552 | break; | |
4553 | case DW_TAG_base_type: | |
4554 | read_base_type (die, objfile); | |
4555 | break; | |
4556 | default: | |
4557 | complain (&dwarf2_unexpected_tag, dwarf_tag_name (die->tag)); | |
4558 | break; | |
4559 | } | |
4560 | } | |
4561 | ||
4562 | static struct type * | |
4563 | dwarf_base_type (encoding, size, objfile) | |
4564 | int encoding; | |
4565 | int size; | |
4566 | struct objfile *objfile; | |
4567 | { | |
4568 | /* FIXME - this should not produce a new (struct type *) | |
4569 | every time. It should cache base types. */ | |
4570 | struct type *type; | |
4571 | switch (encoding) | |
4572 | { | |
4573 | case DW_ATE_address: | |
4574 | type = dwarf2_fundamental_type (objfile, FT_VOID); | |
4575 | return type; | |
4576 | case DW_ATE_boolean: | |
4577 | type = dwarf2_fundamental_type (objfile, FT_BOOLEAN); | |
4578 | return type; | |
4579 | case DW_ATE_complex_float: | |
4580 | if (size == 16) | |
4581 | { | |
4582 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX); | |
4583 | } | |
4584 | else | |
4585 | { | |
4586 | type = dwarf2_fundamental_type (objfile, FT_COMPLEX); | |
4587 | } | |
4588 | return type; | |
4589 | case DW_ATE_float: | |
4590 | if (size == 8) | |
4591 | { | |
4592 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT); | |
4593 | } | |
4594 | else | |
4595 | { | |
4596 | type = dwarf2_fundamental_type (objfile, FT_FLOAT); | |
4597 | } | |
4598 | return type; | |
4599 | case DW_ATE_signed: | |
4600 | switch (size) | |
4601 | { | |
4602 | case 1: | |
4603 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR); | |
4604 | break; | |
4605 | case 2: | |
4606 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT); | |
4607 | break; | |
4608 | default: | |
4609 | case 4: | |
4610 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER); | |
4611 | break; | |
4612 | } | |
4613 | return type; | |
4614 | case DW_ATE_signed_char: | |
4615 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR); | |
4616 | return type; | |
4617 | case DW_ATE_unsigned: | |
4618 | switch (size) | |
4619 | { | |
4620 | case 1: | |
4621 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR); | |
4622 | break; | |
4623 | case 2: | |
4624 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT); | |
4625 | break; | |
4626 | default: | |
4627 | case 4: | |
4628 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER); | |
4629 | break; | |
4630 | } | |
4631 | return type; | |
4632 | case DW_ATE_unsigned_char: | |
4633 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR); | |
4634 | return type; | |
4635 | default: | |
4636 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER); | |
4637 | return type; | |
4638 | } | |
4639 | } | |
4640 | ||
4641 | #if 0 | |
4642 | struct die_info * | |
4643 | copy_die (old_die) | |
4644 | struct die_info *old_die; | |
4645 | { | |
4646 | struct die_info *new_die; | |
4647 | int i, num_attrs; | |
4648 | ||
4649 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
4650 | memset (new_die, 0, sizeof (struct die_info)); | |
4651 | ||
4652 | new_die->tag = old_die->tag; | |
4653 | new_die->has_children = old_die->has_children; | |
4654 | new_die->abbrev = old_die->abbrev; | |
4655 | new_die->offset = old_die->offset; | |
4656 | new_die->type = NULL; | |
4657 | ||
4658 | num_attrs = old_die->num_attrs; | |
4659 | new_die->num_attrs = num_attrs; | |
4660 | new_die->attrs = (struct attribute *) | |
4661 | xmalloc (num_attrs * sizeof (struct attribute)); | |
4662 | ||
4663 | for (i = 0; i < old_die->num_attrs; ++i) | |
4664 | { | |
4665 | new_die->attrs[i].name = old_die->attrs[i].name; | |
4666 | new_die->attrs[i].form = old_die->attrs[i].form; | |
4667 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
4668 | } | |
4669 | ||
4670 | new_die->next = NULL; | |
4671 | return new_die; | |
4672 | } | |
4673 | #endif | |
4674 | ||
4675 | /* Return sibling of die, NULL if no sibling. */ | |
4676 | ||
4677 | struct die_info * | |
4678 | sibling_die (die) | |
4679 | struct die_info *die; | |
4680 | { | |
4681 | int nesting_level = 0; | |
4682 | ||
4683 | if (!die->has_children) | |
4684 | { | |
4685 | if (die->next && (die->next->tag == 0)) | |
4686 | { | |
4687 | return NULL; | |
4688 | } | |
4689 | else | |
4690 | { | |
4691 | return die->next; | |
4692 | } | |
4693 | } | |
4694 | else | |
4695 | { | |
4696 | do | |
4697 | { | |
4698 | if (die->has_children) | |
4699 | { | |
4700 | nesting_level++; | |
4701 | } | |
4702 | if (die->tag == 0) | |
4703 | { | |
4704 | nesting_level--; | |
4705 | } | |
4706 | die = die->next; | |
4707 | } | |
4708 | while (nesting_level); | |
4709 | if (die && (die->tag == 0)) | |
4710 | { | |
4711 | return NULL; | |
4712 | } | |
4713 | else | |
4714 | { | |
4715 | return die; | |
4716 | } | |
4717 | } | |
4718 | } | |
4719 | ||
4720 | /* Get linkage name of a die, return NULL if not found. */ | |
4721 | ||
4722 | static char * | |
4723 | dwarf2_linkage_name (die) | |
4724 | struct die_info *die; | |
4725 | { | |
4726 | struct attribute *attr; | |
4727 | ||
4728 | attr = dwarf_attr (die, DW_AT_MIPS_linkage_name); | |
4729 | if (attr && DW_STRING (attr)) | |
4730 | return DW_STRING (attr); | |
4731 | attr = dwarf_attr (die, DW_AT_name); | |
4732 | if (attr && DW_STRING (attr)) | |
4733 | return DW_STRING (attr); | |
4734 | return NULL; | |
4735 | } | |
4736 | ||
4737 | /* Convert a DIE tag into its string name. */ | |
4738 | ||
4739 | static char * | |
4740 | dwarf_tag_name (tag) | |
4741 | register unsigned tag; | |
4742 | { | |
4743 | switch (tag) | |
4744 | { | |
4745 | case DW_TAG_padding: | |
4746 | return "DW_TAG_padding"; | |
4747 | case DW_TAG_array_type: | |
4748 | return "DW_TAG_array_type"; | |
4749 | case DW_TAG_class_type: | |
4750 | return "DW_TAG_class_type"; | |
4751 | case DW_TAG_entry_point: | |
4752 | return "DW_TAG_entry_point"; | |
4753 | case DW_TAG_enumeration_type: | |
4754 | return "DW_TAG_enumeration_type"; | |
4755 | case DW_TAG_formal_parameter: | |
4756 | return "DW_TAG_formal_parameter"; | |
4757 | case DW_TAG_imported_declaration: | |
4758 | return "DW_TAG_imported_declaration"; | |
4759 | case DW_TAG_label: | |
4760 | return "DW_TAG_label"; | |
4761 | case DW_TAG_lexical_block: | |
4762 | return "DW_TAG_lexical_block"; | |
4763 | case DW_TAG_member: | |
4764 | return "DW_TAG_member"; | |
4765 | case DW_TAG_pointer_type: | |
4766 | return "DW_TAG_pointer_type"; | |
4767 | case DW_TAG_reference_type: | |
4768 | return "DW_TAG_reference_type"; | |
4769 | case DW_TAG_compile_unit: | |
4770 | return "DW_TAG_compile_unit"; | |
4771 | case DW_TAG_string_type: | |
4772 | return "DW_TAG_string_type"; | |
4773 | case DW_TAG_structure_type: | |
4774 | return "DW_TAG_structure_type"; | |
4775 | case DW_TAG_subroutine_type: | |
4776 | return "DW_TAG_subroutine_type"; | |
4777 | case DW_TAG_typedef: | |
4778 | return "DW_TAG_typedef"; | |
4779 | case DW_TAG_union_type: | |
4780 | return "DW_TAG_union_type"; | |
4781 | case DW_TAG_unspecified_parameters: | |
4782 | return "DW_TAG_unspecified_parameters"; | |
4783 | case DW_TAG_variant: | |
4784 | return "DW_TAG_variant"; | |
4785 | case DW_TAG_common_block: | |
4786 | return "DW_TAG_common_block"; | |
4787 | case DW_TAG_common_inclusion: | |
4788 | return "DW_TAG_common_inclusion"; | |
4789 | case DW_TAG_inheritance: | |
4790 | return "DW_TAG_inheritance"; | |
4791 | case DW_TAG_inlined_subroutine: | |
4792 | return "DW_TAG_inlined_subroutine"; | |
4793 | case DW_TAG_module: | |
4794 | return "DW_TAG_module"; | |
4795 | case DW_TAG_ptr_to_member_type: | |
4796 | return "DW_TAG_ptr_to_member_type"; | |
4797 | case DW_TAG_set_type: | |
4798 | return "DW_TAG_set_type"; | |
4799 | case DW_TAG_subrange_type: | |
4800 | return "DW_TAG_subrange_type"; | |
4801 | case DW_TAG_with_stmt: | |
4802 | return "DW_TAG_with_stmt"; | |
4803 | case DW_TAG_access_declaration: | |
4804 | return "DW_TAG_access_declaration"; | |
4805 | case DW_TAG_base_type: | |
4806 | return "DW_TAG_base_type"; | |
4807 | case DW_TAG_catch_block: | |
4808 | return "DW_TAG_catch_block"; | |
4809 | case DW_TAG_const_type: | |
4810 | return "DW_TAG_const_type"; | |
4811 | case DW_TAG_constant: | |
4812 | return "DW_TAG_constant"; | |
4813 | case DW_TAG_enumerator: | |
4814 | return "DW_TAG_enumerator"; | |
4815 | case DW_TAG_file_type: | |
4816 | return "DW_TAG_file_type"; | |
4817 | case DW_TAG_friend: | |
4818 | return "DW_TAG_friend"; | |
4819 | case DW_TAG_namelist: | |
4820 | return "DW_TAG_namelist"; | |
4821 | case DW_TAG_namelist_item: | |
4822 | return "DW_TAG_namelist_item"; | |
4823 | case DW_TAG_packed_type: | |
4824 | return "DW_TAG_packed_type"; | |
4825 | case DW_TAG_subprogram: | |
4826 | return "DW_TAG_subprogram"; | |
4827 | case DW_TAG_template_type_param: | |
4828 | return "DW_TAG_template_type_param"; | |
4829 | case DW_TAG_template_value_param: | |
4830 | return "DW_TAG_template_value_param"; | |
4831 | case DW_TAG_thrown_type: | |
4832 | return "DW_TAG_thrown_type"; | |
4833 | case DW_TAG_try_block: | |
4834 | return "DW_TAG_try_block"; | |
4835 | case DW_TAG_variant_part: | |
4836 | return "DW_TAG_variant_part"; | |
4837 | case DW_TAG_variable: | |
4838 | return "DW_TAG_variable"; | |
4839 | case DW_TAG_volatile_type: | |
4840 | return "DW_TAG_volatile_type"; | |
4841 | case DW_TAG_MIPS_loop: | |
4842 | return "DW_TAG_MIPS_loop"; | |
4843 | case DW_TAG_format_label: | |
4844 | return "DW_TAG_format_label"; | |
4845 | case DW_TAG_function_template: | |
4846 | return "DW_TAG_function_template"; | |
4847 | case DW_TAG_class_template: | |
4848 | return "DW_TAG_class_template"; | |
4849 | default: | |
4850 | return "DW_TAG_<unknown>"; | |
4851 | } | |
4852 | } | |
4853 | ||
4854 | /* Convert a DWARF attribute code into its string name. */ | |
4855 | ||
4856 | static char * | |
4857 | dwarf_attr_name (attr) | |
4858 | register unsigned attr; | |
4859 | { | |
4860 | switch (attr) | |
4861 | { | |
4862 | case DW_AT_sibling: | |
4863 | return "DW_AT_sibling"; | |
4864 | case DW_AT_location: | |
4865 | return "DW_AT_location"; | |
4866 | case DW_AT_name: | |
4867 | return "DW_AT_name"; | |
4868 | case DW_AT_ordering: | |
4869 | return "DW_AT_ordering"; | |
4870 | case DW_AT_subscr_data: | |
4871 | return "DW_AT_subscr_data"; | |
4872 | case DW_AT_byte_size: | |
4873 | return "DW_AT_byte_size"; | |
4874 | case DW_AT_bit_offset: | |
4875 | return "DW_AT_bit_offset"; | |
4876 | case DW_AT_bit_size: | |
4877 | return "DW_AT_bit_size"; | |
4878 | case DW_AT_element_list: | |
4879 | return "DW_AT_element_list"; | |
4880 | case DW_AT_stmt_list: | |
4881 | return "DW_AT_stmt_list"; | |
4882 | case DW_AT_low_pc: | |
4883 | return "DW_AT_low_pc"; | |
4884 | case DW_AT_high_pc: | |
4885 | return "DW_AT_high_pc"; | |
4886 | case DW_AT_language: | |
4887 | return "DW_AT_language"; | |
4888 | case DW_AT_member: | |
4889 | return "DW_AT_member"; | |
4890 | case DW_AT_discr: | |
4891 | return "DW_AT_discr"; | |
4892 | case DW_AT_discr_value: | |
4893 | return "DW_AT_discr_value"; | |
4894 | case DW_AT_visibility: | |
4895 | return "DW_AT_visibility"; | |
4896 | case DW_AT_import: | |
4897 | return "DW_AT_import"; | |
4898 | case DW_AT_string_length: | |
4899 | return "DW_AT_string_length"; | |
4900 | case DW_AT_common_reference: | |
4901 | return "DW_AT_common_reference"; | |
4902 | case DW_AT_comp_dir: | |
4903 | return "DW_AT_comp_dir"; | |
4904 | case DW_AT_const_value: | |
4905 | return "DW_AT_const_value"; | |
4906 | case DW_AT_containing_type: | |
4907 | return "DW_AT_containing_type"; | |
4908 | case DW_AT_default_value: | |
4909 | return "DW_AT_default_value"; | |
4910 | case DW_AT_inline: | |
4911 | return "DW_AT_inline"; | |
4912 | case DW_AT_is_optional: | |
4913 | return "DW_AT_is_optional"; | |
4914 | case DW_AT_lower_bound: | |
4915 | return "DW_AT_lower_bound"; | |
4916 | case DW_AT_producer: | |
4917 | return "DW_AT_producer"; | |
4918 | case DW_AT_prototyped: | |
4919 | return "DW_AT_prototyped"; | |
4920 | case DW_AT_return_addr: | |
4921 | return "DW_AT_return_addr"; | |
4922 | case DW_AT_start_scope: | |
4923 | return "DW_AT_start_scope"; | |
4924 | case DW_AT_stride_size: | |
4925 | return "DW_AT_stride_size"; | |
4926 | case DW_AT_upper_bound: | |
4927 | return "DW_AT_upper_bound"; | |
4928 | case DW_AT_abstract_origin: | |
4929 | return "DW_AT_abstract_origin"; | |
4930 | case DW_AT_accessibility: | |
4931 | return "DW_AT_accessibility"; | |
4932 | case DW_AT_address_class: | |
4933 | return "DW_AT_address_class"; | |
4934 | case DW_AT_artificial: | |
4935 | return "DW_AT_artificial"; | |
4936 | case DW_AT_base_types: | |
4937 | return "DW_AT_base_types"; | |
4938 | case DW_AT_calling_convention: | |
4939 | return "DW_AT_calling_convention"; | |
4940 | case DW_AT_count: | |
4941 | return "DW_AT_count"; | |
4942 | case DW_AT_data_member_location: | |
4943 | return "DW_AT_data_member_location"; | |
4944 | case DW_AT_decl_column: | |
4945 | return "DW_AT_decl_column"; | |
4946 | case DW_AT_decl_file: | |
4947 | return "DW_AT_decl_file"; | |
4948 | case DW_AT_decl_line: | |
4949 | return "DW_AT_decl_line"; | |
4950 | case DW_AT_declaration: | |
4951 | return "DW_AT_declaration"; | |
4952 | case DW_AT_discr_list: | |
4953 | return "DW_AT_discr_list"; | |
4954 | case DW_AT_encoding: | |
4955 | return "DW_AT_encoding"; | |
4956 | case DW_AT_external: | |
4957 | return "DW_AT_external"; | |
4958 | case DW_AT_frame_base: | |
4959 | return "DW_AT_frame_base"; | |
4960 | case DW_AT_friend: | |
4961 | return "DW_AT_friend"; | |
4962 | case DW_AT_identifier_case: | |
4963 | return "DW_AT_identifier_case"; | |
4964 | case DW_AT_macro_info: | |
4965 | return "DW_AT_macro_info"; | |
4966 | case DW_AT_namelist_items: | |
4967 | return "DW_AT_namelist_items"; | |
4968 | case DW_AT_priority: | |
4969 | return "DW_AT_priority"; | |
4970 | case DW_AT_segment: | |
4971 | return "DW_AT_segment"; | |
4972 | case DW_AT_specification: | |
4973 | return "DW_AT_specification"; | |
4974 | case DW_AT_static_link: | |
4975 | return "DW_AT_static_link"; | |
4976 | case DW_AT_type: | |
4977 | return "DW_AT_type"; | |
4978 | case DW_AT_use_location: | |
4979 | return "DW_AT_use_location"; | |
4980 | case DW_AT_variable_parameter: | |
4981 | return "DW_AT_variable_parameter"; | |
4982 | case DW_AT_virtuality: | |
4983 | return "DW_AT_virtuality"; | |
4984 | case DW_AT_vtable_elem_location: | |
4985 | return "DW_AT_vtable_elem_location"; | |
4986 | ||
4987 | #ifdef MIPS | |
4988 | case DW_AT_MIPS_fde: | |
4989 | return "DW_AT_MIPS_fde"; | |
4990 | case DW_AT_MIPS_loop_begin: | |
4991 | return "DW_AT_MIPS_loop_begin"; | |
4992 | case DW_AT_MIPS_tail_loop_begin: | |
4993 | return "DW_AT_MIPS_tail_loop_begin"; | |
4994 | case DW_AT_MIPS_epilog_begin: | |
4995 | return "DW_AT_MIPS_epilog_begin"; | |
4996 | case DW_AT_MIPS_loop_unroll_factor: | |
4997 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4998 | case DW_AT_MIPS_software_pipeline_depth: | |
4999 | return "DW_AT_MIPS_software_pipeline_depth"; | |
5000 | case DW_AT_MIPS_linkage_name: | |
5001 | return "DW_AT_MIPS_linkage_name"; | |
5002 | #endif | |
5003 | ||
5004 | case DW_AT_sf_names: | |
5005 | return "DW_AT_sf_names"; | |
5006 | case DW_AT_src_info: | |
5007 | return "DW_AT_src_info"; | |
5008 | case DW_AT_mac_info: | |
5009 | return "DW_AT_mac_info"; | |
5010 | case DW_AT_src_coords: | |
5011 | return "DW_AT_src_coords"; | |
5012 | case DW_AT_body_begin: | |
5013 | return "DW_AT_body_begin"; | |
5014 | case DW_AT_body_end: | |
5015 | return "DW_AT_body_end"; | |
5016 | default: | |
5017 | return "DW_AT_<unknown>"; | |
5018 | } | |
5019 | } | |
5020 | ||
5021 | /* Convert a DWARF value form code into its string name. */ | |
5022 | ||
5023 | static char * | |
5024 | dwarf_form_name (form) | |
5025 | register unsigned form; | |
5026 | { | |
5027 | switch (form) | |
5028 | { | |
5029 | case DW_FORM_addr: | |
5030 | return "DW_FORM_addr"; | |
5031 | case DW_FORM_block2: | |
5032 | return "DW_FORM_block2"; | |
5033 | case DW_FORM_block4: | |
5034 | return "DW_FORM_block4"; | |
5035 | case DW_FORM_data2: | |
5036 | return "DW_FORM_data2"; | |
5037 | case DW_FORM_data4: | |
5038 | return "DW_FORM_data4"; | |
5039 | case DW_FORM_data8: | |
5040 | return "DW_FORM_data8"; | |
5041 | case DW_FORM_string: | |
5042 | return "DW_FORM_string"; | |
5043 | case DW_FORM_block: | |
5044 | return "DW_FORM_block"; | |
5045 | case DW_FORM_block1: | |
5046 | return "DW_FORM_block1"; | |
5047 | case DW_FORM_data1: | |
5048 | return "DW_FORM_data1"; | |
5049 | case DW_FORM_flag: | |
5050 | return "DW_FORM_flag"; | |
5051 | case DW_FORM_sdata: | |
5052 | return "DW_FORM_sdata"; | |
5053 | case DW_FORM_strp: | |
5054 | return "DW_FORM_strp"; | |
5055 | case DW_FORM_udata: | |
5056 | return "DW_FORM_udata"; | |
5057 | case DW_FORM_ref_addr: | |
5058 | return "DW_FORM_ref_addr"; | |
5059 | case DW_FORM_ref1: | |
5060 | return "DW_FORM_ref1"; | |
5061 | case DW_FORM_ref2: | |
5062 | return "DW_FORM_ref2"; | |
5063 | case DW_FORM_ref4: | |
5064 | return "DW_FORM_ref4"; | |
5065 | case DW_FORM_ref8: | |
5066 | return "DW_FORM_ref8"; | |
5067 | case DW_FORM_ref_udata: | |
5068 | return "DW_FORM_ref_udata"; | |
5069 | case DW_FORM_indirect: | |
5070 | return "DW_FORM_indirect"; | |
5071 | default: | |
5072 | return "DW_FORM_<unknown>"; | |
5073 | } | |
5074 | } | |
5075 | ||
5076 | /* Convert a DWARF stack opcode into its string name. */ | |
5077 | ||
5078 | static char * | |
5079 | dwarf_stack_op_name (op) | |
5080 | register unsigned op; | |
5081 | { | |
5082 | switch (op) | |
5083 | { | |
5084 | case DW_OP_addr: | |
5085 | return "DW_OP_addr"; | |
5086 | case DW_OP_deref: | |
5087 | return "DW_OP_deref"; | |
5088 | case DW_OP_const1u: | |
5089 | return "DW_OP_const1u"; | |
5090 | case DW_OP_const1s: | |
5091 | return "DW_OP_const1s"; | |
5092 | case DW_OP_const2u: | |
5093 | return "DW_OP_const2u"; | |
5094 | case DW_OP_const2s: | |
5095 | return "DW_OP_const2s"; | |
5096 | case DW_OP_const4u: | |
5097 | return "DW_OP_const4u"; | |
5098 | case DW_OP_const4s: | |
5099 | return "DW_OP_const4s"; | |
5100 | case DW_OP_const8u: | |
5101 | return "DW_OP_const8u"; | |
5102 | case DW_OP_const8s: | |
5103 | return "DW_OP_const8s"; | |
5104 | case DW_OP_constu: | |
5105 | return "DW_OP_constu"; | |
5106 | case DW_OP_consts: | |
5107 | return "DW_OP_consts"; | |
5108 | case DW_OP_dup: | |
5109 | return "DW_OP_dup"; | |
5110 | case DW_OP_drop: | |
5111 | return "DW_OP_drop"; | |
5112 | case DW_OP_over: | |
5113 | return "DW_OP_over"; | |
5114 | case DW_OP_pick: | |
5115 | return "DW_OP_pick"; | |
5116 | case DW_OP_swap: | |
5117 | return "DW_OP_swap"; | |
5118 | case DW_OP_rot: | |
5119 | return "DW_OP_rot"; | |
5120 | case DW_OP_xderef: | |
5121 | return "DW_OP_xderef"; | |
5122 | case DW_OP_abs: | |
5123 | return "DW_OP_abs"; | |
5124 | case DW_OP_and: | |
5125 | return "DW_OP_and"; | |
5126 | case DW_OP_div: | |
5127 | return "DW_OP_div"; | |
5128 | case DW_OP_minus: | |
5129 | return "DW_OP_minus"; | |
5130 | case DW_OP_mod: | |
5131 | return "DW_OP_mod"; | |
5132 | case DW_OP_mul: | |
5133 | return "DW_OP_mul"; | |
5134 | case DW_OP_neg: | |
5135 | return "DW_OP_neg"; | |
5136 | case DW_OP_not: | |
5137 | return "DW_OP_not"; | |
5138 | case DW_OP_or: | |
5139 | return "DW_OP_or"; | |
5140 | case DW_OP_plus: | |
5141 | return "DW_OP_plus"; | |
5142 | case DW_OP_plus_uconst: | |
5143 | return "DW_OP_plus_uconst"; | |
5144 | case DW_OP_shl: | |
5145 | return "DW_OP_shl"; | |
5146 | case DW_OP_shr: | |
5147 | return "DW_OP_shr"; | |
5148 | case DW_OP_shra: | |
5149 | return "DW_OP_shra"; | |
5150 | case DW_OP_xor: | |
5151 | return "DW_OP_xor"; | |
5152 | case DW_OP_bra: | |
5153 | return "DW_OP_bra"; | |
5154 | case DW_OP_eq: | |
5155 | return "DW_OP_eq"; | |
5156 | case DW_OP_ge: | |
5157 | return "DW_OP_ge"; | |
5158 | case DW_OP_gt: | |
5159 | return "DW_OP_gt"; | |
5160 | case DW_OP_le: | |
5161 | return "DW_OP_le"; | |
5162 | case DW_OP_lt: | |
5163 | return "DW_OP_lt"; | |
5164 | case DW_OP_ne: | |
5165 | return "DW_OP_ne"; | |
5166 | case DW_OP_skip: | |
5167 | return "DW_OP_skip"; | |
5168 | case DW_OP_lit0: | |
5169 | return "DW_OP_lit0"; | |
5170 | case DW_OP_lit1: | |
5171 | return "DW_OP_lit1"; | |
5172 | case DW_OP_lit2: | |
5173 | return "DW_OP_lit2"; | |
5174 | case DW_OP_lit3: | |
5175 | return "DW_OP_lit3"; | |
5176 | case DW_OP_lit4: | |
5177 | return "DW_OP_lit4"; | |
5178 | case DW_OP_lit5: | |
5179 | return "DW_OP_lit5"; | |
5180 | case DW_OP_lit6: | |
5181 | return "DW_OP_lit6"; | |
5182 | case DW_OP_lit7: | |
5183 | return "DW_OP_lit7"; | |
5184 | case DW_OP_lit8: | |
5185 | return "DW_OP_lit8"; | |
5186 | case DW_OP_lit9: | |
5187 | return "DW_OP_lit9"; | |
5188 | case DW_OP_lit10: | |
5189 | return "DW_OP_lit10"; | |
5190 | case DW_OP_lit11: | |
5191 | return "DW_OP_lit11"; | |
5192 | case DW_OP_lit12: | |
5193 | return "DW_OP_lit12"; | |
5194 | case DW_OP_lit13: | |
5195 | return "DW_OP_lit13"; | |
5196 | case DW_OP_lit14: | |
5197 | return "DW_OP_lit14"; | |
5198 | case DW_OP_lit15: | |
5199 | return "DW_OP_lit15"; | |
5200 | case DW_OP_lit16: | |
5201 | return "DW_OP_lit16"; | |
5202 | case DW_OP_lit17: | |
5203 | return "DW_OP_lit17"; | |
5204 | case DW_OP_lit18: | |
5205 | return "DW_OP_lit18"; | |
5206 | case DW_OP_lit19: | |
5207 | return "DW_OP_lit19"; | |
5208 | case DW_OP_lit20: | |
5209 | return "DW_OP_lit20"; | |
5210 | case DW_OP_lit21: | |
5211 | return "DW_OP_lit21"; | |
5212 | case DW_OP_lit22: | |
5213 | return "DW_OP_lit22"; | |
5214 | case DW_OP_lit23: | |
5215 | return "DW_OP_lit23"; | |
5216 | case DW_OP_lit24: | |
5217 | return "DW_OP_lit24"; | |
5218 | case DW_OP_lit25: | |
5219 | return "DW_OP_lit25"; | |
5220 | case DW_OP_lit26: | |
5221 | return "DW_OP_lit26"; | |
5222 | case DW_OP_lit27: | |
5223 | return "DW_OP_lit27"; | |
5224 | case DW_OP_lit28: | |
5225 | return "DW_OP_lit28"; | |
5226 | case DW_OP_lit29: | |
5227 | return "DW_OP_lit29"; | |
5228 | case DW_OP_lit30: | |
5229 | return "DW_OP_lit30"; | |
5230 | case DW_OP_lit31: | |
5231 | return "DW_OP_lit31"; | |
5232 | case DW_OP_reg0: | |
5233 | return "DW_OP_reg0"; | |
5234 | case DW_OP_reg1: | |
5235 | return "DW_OP_reg1"; | |
5236 | case DW_OP_reg2: | |
5237 | return "DW_OP_reg2"; | |
5238 | case DW_OP_reg3: | |
5239 | return "DW_OP_reg3"; | |
5240 | case DW_OP_reg4: | |
5241 | return "DW_OP_reg4"; | |
5242 | case DW_OP_reg5: | |
5243 | return "DW_OP_reg5"; | |
5244 | case DW_OP_reg6: | |
5245 | return "DW_OP_reg6"; | |
5246 | case DW_OP_reg7: | |
5247 | return "DW_OP_reg7"; | |
5248 | case DW_OP_reg8: | |
5249 | return "DW_OP_reg8"; | |
5250 | case DW_OP_reg9: | |
5251 | return "DW_OP_reg9"; | |
5252 | case DW_OP_reg10: | |
5253 | return "DW_OP_reg10"; | |
5254 | case DW_OP_reg11: | |
5255 | return "DW_OP_reg11"; | |
5256 | case DW_OP_reg12: | |
5257 | return "DW_OP_reg12"; | |
5258 | case DW_OP_reg13: | |
5259 | return "DW_OP_reg13"; | |
5260 | case DW_OP_reg14: | |
5261 | return "DW_OP_reg14"; | |
5262 | case DW_OP_reg15: | |
5263 | return "DW_OP_reg15"; | |
5264 | case DW_OP_reg16: | |
5265 | return "DW_OP_reg16"; | |
5266 | case DW_OP_reg17: | |
5267 | return "DW_OP_reg17"; | |
5268 | case DW_OP_reg18: | |
5269 | return "DW_OP_reg18"; | |
5270 | case DW_OP_reg19: | |
5271 | return "DW_OP_reg19"; | |
5272 | case DW_OP_reg20: | |
5273 | return "DW_OP_reg20"; | |
5274 | case DW_OP_reg21: | |
5275 | return "DW_OP_reg21"; | |
5276 | case DW_OP_reg22: | |
5277 | return "DW_OP_reg22"; | |
5278 | case DW_OP_reg23: | |
5279 | return "DW_OP_reg23"; | |
5280 | case DW_OP_reg24: | |
5281 | return "DW_OP_reg24"; | |
5282 | case DW_OP_reg25: | |
5283 | return "DW_OP_reg25"; | |
5284 | case DW_OP_reg26: | |
5285 | return "DW_OP_reg26"; | |
5286 | case DW_OP_reg27: | |
5287 | return "DW_OP_reg27"; | |
5288 | case DW_OP_reg28: | |
5289 | return "DW_OP_reg28"; | |
5290 | case DW_OP_reg29: | |
5291 | return "DW_OP_reg29"; | |
5292 | case DW_OP_reg30: | |
5293 | return "DW_OP_reg30"; | |
5294 | case DW_OP_reg31: | |
5295 | return "DW_OP_reg31"; | |
5296 | case DW_OP_breg0: | |
5297 | return "DW_OP_breg0"; | |
5298 | case DW_OP_breg1: | |
5299 | return "DW_OP_breg1"; | |
5300 | case DW_OP_breg2: | |
5301 | return "DW_OP_breg2"; | |
5302 | case DW_OP_breg3: | |
5303 | return "DW_OP_breg3"; | |
5304 | case DW_OP_breg4: | |
5305 | return "DW_OP_breg4"; | |
5306 | case DW_OP_breg5: | |
5307 | return "DW_OP_breg5"; | |
5308 | case DW_OP_breg6: | |
5309 | return "DW_OP_breg6"; | |
5310 | case DW_OP_breg7: | |
5311 | return "DW_OP_breg7"; | |
5312 | case DW_OP_breg8: | |
5313 | return "DW_OP_breg8"; | |
5314 | case DW_OP_breg9: | |
5315 | return "DW_OP_breg9"; | |
5316 | case DW_OP_breg10: | |
5317 | return "DW_OP_breg10"; | |
5318 | case DW_OP_breg11: | |
5319 | return "DW_OP_breg11"; | |
5320 | case DW_OP_breg12: | |
5321 | return "DW_OP_breg12"; | |
5322 | case DW_OP_breg13: | |
5323 | return "DW_OP_breg13"; | |
5324 | case DW_OP_breg14: | |
5325 | return "DW_OP_breg14"; | |
5326 | case DW_OP_breg15: | |
5327 | return "DW_OP_breg15"; | |
5328 | case DW_OP_breg16: | |
5329 | return "DW_OP_breg16"; | |
5330 | case DW_OP_breg17: | |
5331 | return "DW_OP_breg17"; | |
5332 | case DW_OP_breg18: | |
5333 | return "DW_OP_breg18"; | |
5334 | case DW_OP_breg19: | |
5335 | return "DW_OP_breg19"; | |
5336 | case DW_OP_breg20: | |
5337 | return "DW_OP_breg20"; | |
5338 | case DW_OP_breg21: | |
5339 | return "DW_OP_breg21"; | |
5340 | case DW_OP_breg22: | |
5341 | return "DW_OP_breg22"; | |
5342 | case DW_OP_breg23: | |
5343 | return "DW_OP_breg23"; | |
5344 | case DW_OP_breg24: | |
5345 | return "DW_OP_breg24"; | |
5346 | case DW_OP_breg25: | |
5347 | return "DW_OP_breg25"; | |
5348 | case DW_OP_breg26: | |
5349 | return "DW_OP_breg26"; | |
5350 | case DW_OP_breg27: | |
5351 | return "DW_OP_breg27"; | |
5352 | case DW_OP_breg28: | |
5353 | return "DW_OP_breg28"; | |
5354 | case DW_OP_breg29: | |
5355 | return "DW_OP_breg29"; | |
5356 | case DW_OP_breg30: | |
5357 | return "DW_OP_breg30"; | |
5358 | case DW_OP_breg31: | |
5359 | return "DW_OP_breg31"; | |
5360 | case DW_OP_regx: | |
5361 | return "DW_OP_regx"; | |
5362 | case DW_OP_fbreg: | |
5363 | return "DW_OP_fbreg"; | |
5364 | case DW_OP_bregx: | |
5365 | return "DW_OP_bregx"; | |
5366 | case DW_OP_piece: | |
5367 | return "DW_OP_piece"; | |
5368 | case DW_OP_deref_size: | |
5369 | return "DW_OP_deref_size"; | |
5370 | case DW_OP_xderef_size: | |
5371 | return "DW_OP_xderef_size"; | |
5372 | case DW_OP_nop: | |
5373 | return "DW_OP_nop"; | |
5374 | default: | |
5375 | return "OP_<unknown>"; | |
5376 | } | |
5377 | } | |
5378 | ||
5379 | static char * | |
5380 | dwarf_bool_name (mybool) | |
5381 | unsigned mybool; | |
5382 | { | |
5383 | if (mybool) | |
5384 | return "TRUE"; | |
5385 | else | |
5386 | return "FALSE"; | |
5387 | } | |
5388 | ||
5389 | /* Convert a DWARF type code into its string name. */ | |
5390 | ||
5391 | static char * | |
5392 | dwarf_type_encoding_name (enc) | |
5393 | register unsigned enc; | |
5394 | { | |
5395 | switch (enc) | |
5396 | { | |
5397 | case DW_ATE_address: | |
5398 | return "DW_ATE_address"; | |
5399 | case DW_ATE_boolean: | |
5400 | return "DW_ATE_boolean"; | |
5401 | case DW_ATE_complex_float: | |
5402 | return "DW_ATE_complex_float"; | |
5403 | case DW_ATE_float: | |
5404 | return "DW_ATE_float"; | |
5405 | case DW_ATE_signed: | |
5406 | return "DW_ATE_signed"; | |
5407 | case DW_ATE_signed_char: | |
5408 | return "DW_ATE_signed_char"; | |
5409 | case DW_ATE_unsigned: | |
5410 | return "DW_ATE_unsigned"; | |
5411 | case DW_ATE_unsigned_char: | |
5412 | return "DW_ATE_unsigned_char"; | |
5413 | default: | |
5414 | return "DW_ATE_<unknown>"; | |
5415 | } | |
5416 | } | |
5417 | ||
5418 | /* Convert a DWARF call frame info operation to its string name. */ | |
5419 | ||
5420 | #if 0 | |
5421 | static char * | |
5422 | dwarf_cfi_name (cfi_opc) | |
5423 | register unsigned cfi_opc; | |
5424 | { | |
5425 | switch (cfi_opc) | |
5426 | { | |
5427 | case DW_CFA_advance_loc: | |
5428 | return "DW_CFA_advance_loc"; | |
5429 | case DW_CFA_offset: | |
5430 | return "DW_CFA_offset"; | |
5431 | case DW_CFA_restore: | |
5432 | return "DW_CFA_restore"; | |
5433 | case DW_CFA_nop: | |
5434 | return "DW_CFA_nop"; | |
5435 | case DW_CFA_set_loc: | |
5436 | return "DW_CFA_set_loc"; | |
5437 | case DW_CFA_advance_loc1: | |
5438 | return "DW_CFA_advance_loc1"; | |
5439 | case DW_CFA_advance_loc2: | |
5440 | return "DW_CFA_advance_loc2"; | |
5441 | case DW_CFA_advance_loc4: | |
5442 | return "DW_CFA_advance_loc4"; | |
5443 | case DW_CFA_offset_extended: | |
5444 | return "DW_CFA_offset_extended"; | |
5445 | case DW_CFA_restore_extended: | |
5446 | return "DW_CFA_restore_extended"; | |
5447 | case DW_CFA_undefined: | |
5448 | return "DW_CFA_undefined"; | |
5449 | case DW_CFA_same_value: | |
5450 | return "DW_CFA_same_value"; | |
5451 | case DW_CFA_register: | |
5452 | return "DW_CFA_register"; | |
5453 | case DW_CFA_remember_state: | |
5454 | return "DW_CFA_remember_state"; | |
5455 | case DW_CFA_restore_state: | |
5456 | return "DW_CFA_restore_state"; | |
5457 | case DW_CFA_def_cfa: | |
5458 | return "DW_CFA_def_cfa"; | |
5459 | case DW_CFA_def_cfa_register: | |
5460 | return "DW_CFA_def_cfa_register"; | |
5461 | case DW_CFA_def_cfa_offset: | |
5462 | return "DW_CFA_def_cfa_offset"; | |
5463 | /* SGI/MIPS specific */ | |
5464 | case DW_CFA_MIPS_advance_loc8: | |
5465 | return "DW_CFA_MIPS_advance_loc8"; | |
5466 | default: | |
5467 | return "DW_CFA_<unknown>"; | |
5468 | } | |
5469 | } | |
5470 | #endif | |
5471 | ||
5472 | void | |
5473 | dump_die (die) | |
5474 | struct die_info *die; | |
5475 | { | |
5476 | unsigned int i; | |
5477 | ||
5478 | fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n", | |
5479 | dwarf_tag_name (die->tag), die->abbrev, die->offset); | |
5480 | fprintf (stderr, "\thas children: %s\n", | |
5481 | dwarf_bool_name (die->has_children)); | |
5482 | ||
5483 | fprintf (stderr, "\tattributes:\n"); | |
5484 | for (i = 0; i < die->num_attrs; ++i) | |
5485 | { | |
5486 | fprintf (stderr, "\t\t%s (%s) ", | |
5487 | dwarf_attr_name (die->attrs[i].name), | |
5488 | dwarf_form_name (die->attrs[i].form)); | |
5489 | switch (die->attrs[i].form) | |
5490 | { | |
5491 | case DW_FORM_ref_addr: | |
5492 | case DW_FORM_addr: | |
5493 | fprintf (stderr, "address: "); | |
5494 | print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); | |
5495 | break; | |
5496 | case DW_FORM_block2: | |
5497 | case DW_FORM_block4: | |
5498 | case DW_FORM_block: | |
5499 | case DW_FORM_block1: | |
5500 | fprintf (stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); | |
5501 | break; | |
5502 | case DW_FORM_data1: | |
5503 | case DW_FORM_data2: | |
5504 | case DW_FORM_data4: | |
5505 | case DW_FORM_ref1: | |
5506 | case DW_FORM_ref2: | |
5507 | case DW_FORM_ref4: | |
5508 | case DW_FORM_udata: | |
5509 | case DW_FORM_sdata: | |
5510 | fprintf (stderr, "constant: %d", DW_UNSND (&die->attrs[i])); | |
5511 | break; | |
5512 | case DW_FORM_string: | |
5513 | fprintf (stderr, "string: \"%s\"", | |
5514 | DW_STRING (&die->attrs[i]) | |
c5aa993b | 5515 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
5516 | break; |
5517 | case DW_FORM_flag: | |
5518 | if (DW_UNSND (&die->attrs[i])) | |
5519 | fprintf (stderr, "flag: TRUE"); | |
5520 | else | |
5521 | fprintf (stderr, "flag: FALSE"); | |
5522 | break; | |
5523 | case DW_FORM_strp: /* we do not support separate string | |
5524 | section yet */ | |
5525 | case DW_FORM_indirect: /* we do not handle indirect yet */ | |
5526 | case DW_FORM_data8: /* we do not have 64 bit quantities */ | |
5527 | default: | |
5528 | fprintf (stderr, "unsupported attribute form: %d.", | |
c5aa993b | 5529 | die->attrs[i].form); |
c906108c SS |
5530 | } |
5531 | fprintf (stderr, "\n"); | |
5532 | } | |
5533 | } | |
5534 | ||
5535 | void | |
5536 | dump_die_list (die) | |
5537 | struct die_info *die; | |
5538 | { | |
5539 | while (die) | |
5540 | { | |
5541 | dump_die (die); | |
5542 | die = die->next; | |
5543 | } | |
5544 | } | |
5545 | ||
5546 | void | |
5547 | store_in_ref_table (offset, die) | |
5548 | unsigned int offset; | |
5549 | struct die_info *die; | |
5550 | { | |
5551 | int h; | |
5552 | struct die_info *old; | |
5553 | ||
5554 | h = (offset % REF_HASH_SIZE); | |
5555 | old = die_ref_table[h]; | |
5556 | die->next_ref = old; | |
5557 | die_ref_table[h] = die; | |
5558 | } | |
5559 | ||
5560 | ||
5561 | static void | |
5562 | dwarf2_empty_die_ref_table () | |
5563 | { | |
5564 | memset (die_ref_table, 0, sizeof (die_ref_table)); | |
5565 | } | |
5566 | ||
5567 | static unsigned int | |
5568 | dwarf2_get_ref_die_offset (attr) | |
5569 | struct attribute *attr; | |
5570 | { | |
5571 | unsigned int result = 0; | |
5572 | ||
5573 | switch (attr->form) | |
5574 | { | |
5575 | case DW_FORM_ref_addr: | |
5576 | result = DW_ADDR (attr); | |
5577 | break; | |
5578 | case DW_FORM_ref1: | |
5579 | case DW_FORM_ref2: | |
5580 | case DW_FORM_ref4: | |
5581 | case DW_FORM_ref_udata: | |
5582 | result = cu_header_offset + DW_UNSND (attr); | |
5583 | break; | |
5584 | default: | |
5585 | complain (&dwarf2_unsupported_die_ref_attr, dwarf_form_name (attr->form)); | |
5586 | } | |
5587 | return result; | |
5588 | } | |
5589 | ||
5590 | struct die_info * | |
5591 | follow_die_ref (offset) | |
5592 | unsigned int offset; | |
5593 | { | |
5594 | struct die_info *die; | |
5595 | int h; | |
5596 | ||
5597 | h = (offset % REF_HASH_SIZE); | |
5598 | die = die_ref_table[h]; | |
5599 | while (die) | |
5600 | { | |
5601 | if (die->offset == offset) | |
5602 | { | |
5603 | return die; | |
5604 | } | |
5605 | die = die->next_ref; | |
5606 | } | |
5607 | return NULL; | |
5608 | } | |
5609 | ||
5610 | static struct type * | |
5611 | dwarf2_fundamental_type (objfile, typeid) | |
5612 | struct objfile *objfile; | |
5613 | int typeid; | |
5614 | { | |
5615 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
5616 | { | |
5617 | error ("Dwarf Error: internal error - invalid fundamental type id %d.", | |
5618 | typeid); | |
5619 | } | |
5620 | ||
5621 | /* Look for this particular type in the fundamental type vector. If | |
5622 | one is not found, create and install one appropriate for the | |
5623 | current language and the current target machine. */ | |
5624 | ||
5625 | if (ftypes[typeid] == NULL) | |
5626 | { | |
5627 | ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid); | |
5628 | } | |
5629 | ||
5630 | return (ftypes[typeid]); | |
5631 | } | |
5632 | ||
5633 | /* Decode simple location descriptions. | |
5634 | Given a pointer to a dwarf block that defines a location, compute | |
5635 | the location and return the value. | |
5636 | ||
5637 | FIXME: This is a kludge until we figure out a better | |
5638 | way to handle the location descriptions. | |
5639 | Gdb's design does not mesh well with the DWARF2 notion of a location | |
5640 | computing interpreter, which is a shame because the flexibility goes unused. | |
5641 | FIXME: Implement more operations as necessary. | |
5642 | ||
5643 | A location description containing no operations indicates that the | |
5644 | object is optimized out. The global optimized_out flag is set for | |
5645 | those, the return value is meaningless. | |
5646 | ||
5647 | When the result is a register number, the global isreg flag is set, | |
5648 | otherwise it is cleared. | |
5649 | ||
5650 | When the result is a base register offset, the global offreg flag is set | |
5651 | and the register number is returned in basereg, otherwise it is cleared. | |
5652 | ||
5653 | When the DW_OP_fbreg operation is encountered without a corresponding | |
5654 | DW_AT_frame_base attribute, the global islocal flag is set. | |
5655 | Hopefully the machine dependent code knows how to set up a virtual | |
5656 | frame pointer for the local references. | |
c5aa993b | 5657 | |
c906108c SS |
5658 | Note that stack[0] is unused except as a default error return. |
5659 | Note that stack overflow is not yet handled. */ | |
5660 | ||
5661 | static CORE_ADDR | |
5662 | decode_locdesc (blk, objfile) | |
5663 | struct dwarf_block *blk; | |
5664 | struct objfile *objfile; | |
5665 | { | |
5666 | int i; | |
5667 | int size = blk->size; | |
5668 | char *data = blk->data; | |
5669 | CORE_ADDR stack[64]; | |
5670 | int stacki; | |
5671 | unsigned int bytes_read, unsnd; | |
5672 | unsigned char op; | |
5673 | ||
5674 | i = 0; | |
5675 | stacki = 0; | |
5676 | stack[stacki] = 0; | |
5677 | isreg = 0; | |
5678 | offreg = 0; | |
7a292a7a | 5679 | isderef = 0; |
c906108c SS |
5680 | islocal = 0; |
5681 | optimized_out = 1; | |
5682 | ||
5683 | while (i < size) | |
5684 | { | |
5685 | optimized_out = 0; | |
5686 | op = data[i++]; | |
5687 | switch (op) | |
5688 | { | |
5689 | case DW_OP_reg0: | |
5690 | case DW_OP_reg1: | |
5691 | case DW_OP_reg2: | |
5692 | case DW_OP_reg3: | |
5693 | case DW_OP_reg4: | |
5694 | case DW_OP_reg5: | |
5695 | case DW_OP_reg6: | |
5696 | case DW_OP_reg7: | |
5697 | case DW_OP_reg8: | |
5698 | case DW_OP_reg9: | |
5699 | case DW_OP_reg10: | |
5700 | case DW_OP_reg11: | |
5701 | case DW_OP_reg12: | |
5702 | case DW_OP_reg13: | |
5703 | case DW_OP_reg14: | |
5704 | case DW_OP_reg15: | |
5705 | case DW_OP_reg16: | |
5706 | case DW_OP_reg17: | |
5707 | case DW_OP_reg18: | |
5708 | case DW_OP_reg19: | |
5709 | case DW_OP_reg20: | |
5710 | case DW_OP_reg21: | |
5711 | case DW_OP_reg22: | |
5712 | case DW_OP_reg23: | |
5713 | case DW_OP_reg24: | |
5714 | case DW_OP_reg25: | |
5715 | case DW_OP_reg26: | |
5716 | case DW_OP_reg27: | |
5717 | case DW_OP_reg28: | |
5718 | case DW_OP_reg29: | |
5719 | case DW_OP_reg30: | |
5720 | case DW_OP_reg31: | |
5721 | isreg = 1; | |
5722 | stack[++stacki] = op - DW_OP_reg0; | |
5723 | break; | |
5724 | ||
5725 | case DW_OP_regx: | |
5726 | isreg = 1; | |
5727 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
5728 | i += bytes_read; | |
5729 | #if defined(HARRIS_TARGET) && defined(_M88K) | |
5730 | /* The Harris 88110 gdb ports have long kept their special reg | |
5731 | numbers between their gp-regs and their x-regs. This is | |
5732 | not how our dwarf is generated. Punt. */ | |
5733 | unsnd += 6; | |
5734 | #endif | |
5735 | stack[++stacki] = unsnd; | |
5736 | break; | |
5737 | ||
5738 | case DW_OP_breg0: | |
5739 | case DW_OP_breg1: | |
5740 | case DW_OP_breg2: | |
5741 | case DW_OP_breg3: | |
5742 | case DW_OP_breg4: | |
5743 | case DW_OP_breg5: | |
5744 | case DW_OP_breg6: | |
5745 | case DW_OP_breg7: | |
5746 | case DW_OP_breg8: | |
5747 | case DW_OP_breg9: | |
5748 | case DW_OP_breg10: | |
5749 | case DW_OP_breg11: | |
5750 | case DW_OP_breg12: | |
5751 | case DW_OP_breg13: | |
5752 | case DW_OP_breg14: | |
5753 | case DW_OP_breg15: | |
5754 | case DW_OP_breg16: | |
5755 | case DW_OP_breg17: | |
5756 | case DW_OP_breg18: | |
5757 | case DW_OP_breg19: | |
5758 | case DW_OP_breg20: | |
5759 | case DW_OP_breg21: | |
5760 | case DW_OP_breg22: | |
5761 | case DW_OP_breg23: | |
5762 | case DW_OP_breg24: | |
5763 | case DW_OP_breg25: | |
5764 | case DW_OP_breg26: | |
5765 | case DW_OP_breg27: | |
5766 | case DW_OP_breg28: | |
5767 | case DW_OP_breg29: | |
5768 | case DW_OP_breg30: | |
5769 | case DW_OP_breg31: | |
5770 | offreg = 1; | |
5771 | basereg = op - DW_OP_breg0; | |
5772 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
5773 | i += bytes_read; | |
5774 | break; | |
5775 | ||
5776 | case DW_OP_fbreg: | |
5777 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
5778 | i += bytes_read; | |
5779 | if (frame_base_reg >= 0) | |
5780 | { | |
5781 | offreg = 1; | |
5782 | basereg = frame_base_reg; | |
5783 | stack[stacki] += frame_base_offset; | |
5784 | } | |
5785 | else | |
5786 | { | |
5787 | complain (&dwarf2_missing_at_frame_base); | |
5788 | islocal = 1; | |
5789 | } | |
5790 | break; | |
5791 | ||
5792 | case DW_OP_addr: | |
5793 | stack[++stacki] = read_address (objfile->obfd, &data[i]); | |
5794 | i += address_size; | |
5795 | break; | |
5796 | ||
5797 | case DW_OP_const1u: | |
5798 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
5799 | i += 1; | |
5800 | break; | |
5801 | ||
5802 | case DW_OP_const1s: | |
5803 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
5804 | i += 1; | |
5805 | break; | |
5806 | ||
5807 | case DW_OP_const2u: | |
5808 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
5809 | i += 2; | |
5810 | break; | |
5811 | ||
5812 | case DW_OP_const2s: | |
5813 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
5814 | i += 2; | |
5815 | break; | |
5816 | ||
5817 | case DW_OP_const4u: | |
5818 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
5819 | i += 4; | |
5820 | break; | |
5821 | ||
5822 | case DW_OP_const4s: | |
5823 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
5824 | i += 4; | |
5825 | break; | |
5826 | ||
5827 | case DW_OP_constu: | |
5828 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 5829 | &bytes_read); |
c906108c SS |
5830 | i += bytes_read; |
5831 | break; | |
5832 | ||
5833 | case DW_OP_consts: | |
5834 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
5835 | i += bytes_read; | |
5836 | break; | |
5837 | ||
5838 | case DW_OP_plus: | |
5839 | stack[stacki - 1] += stack[stacki]; | |
5840 | stacki--; | |
5841 | break; | |
5842 | ||
5843 | case DW_OP_plus_uconst: | |
5844 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
5845 | i += bytes_read; | |
5846 | break; | |
5847 | ||
5848 | case DW_OP_minus: | |
5849 | stack[stacki - 1] = stack[stacki] - stack[stacki - 1]; | |
5850 | stacki--; | |
5851 | break; | |
5852 | ||
7a292a7a SS |
5853 | case DW_OP_deref: |
5854 | isderef = 1; | |
5855 | /* If we're not the last op, then we definitely can't encode | |
c5aa993b | 5856 | this using GDB's address_class enum. */ |
7a292a7a SS |
5857 | if (i < size) |
5858 | complain (&dwarf2_complex_location_expr); | |
5859 | break; | |
5860 | ||
c906108c | 5861 | default: |
c5aa993b | 5862 | complain (&dwarf2_unsupported_stack_op, dwarf_stack_op_name (op)); |
c906108c SS |
5863 | return (stack[stacki]); |
5864 | } | |
5865 | } | |
5866 | return (stack[stacki]); | |
5867 | } | |
5868 | ||
5869 | /* memory allocation interface */ | |
5870 | ||
5871 | /* ARGSUSED */ | |
5872 | static void | |
5873 | dwarf2_free_tmp_obstack (ignore) | |
5874 | PTR ignore; | |
5875 | { | |
5876 | obstack_free (&dwarf2_tmp_obstack, NULL); | |
5877 | } | |
5878 | ||
5879 | static struct dwarf_block * | |
5880 | dwarf_alloc_block () | |
5881 | { | |
5882 | struct dwarf_block *blk; | |
5883 | ||
5884 | blk = (struct dwarf_block *) | |
5885 | obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block)); | |
5886 | return (blk); | |
5887 | } | |
5888 | ||
5889 | static struct abbrev_info * | |
5890 | dwarf_alloc_abbrev () | |
5891 | { | |
5892 | struct abbrev_info *abbrev; | |
5893 | ||
5894 | abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info)); | |
5895 | memset (abbrev, 0, sizeof (struct abbrev_info)); | |
5896 | return (abbrev); | |
5897 | } | |
5898 | ||
5899 | static struct die_info * | |
5900 | dwarf_alloc_die () | |
5901 | { | |
5902 | struct die_info *die; | |
5903 | ||
5904 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
5905 | memset (die, 0, sizeof (struct die_info)); | |
5906 | return (die); | |
5907 | } |