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