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