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