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