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