]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
b44e9041 EZ |
2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
3 | 2004 | |
8e65ff28 | 4 | Free Software Foundation, Inc. |
c906108c SS |
5 | |
6 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
7 | Inc. with support from Florida State University (under contract | |
8 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
9 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
10 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
11 | support in dwarfread.c | |
12 | ||
c5aa993b | 13 | This file is part of GDB. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is free software; you can redistribute it and/or modify |
16 | it under the terms of the GNU General Public License as published by | |
17 | the Free Software Foundation; either version 2 of the License, or (at | |
18 | your option) any later version. | |
c906108c | 19 | |
c5aa993b JM |
20 | This program is distributed in the hope that it will be useful, but |
21 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
23 | General Public License for more details. | |
c906108c | 24 | |
c5aa993b JM |
25 | You should have received a copy of the GNU General Public License |
26 | along with this program; if not, write to the Free Software | |
27 | Foundation, Inc., 59 Temple Place - Suite 330, | |
28 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
29 | |
30 | #include "defs.h" | |
31 | #include "bfd.h" | |
c906108c SS |
32 | #include "symtab.h" |
33 | #include "gdbtypes.h" | |
c906108c SS |
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 */ |
2e276125 | 40 | #include "macrotab.h" |
c906108c SS |
41 | #include "language.h" |
42 | #include "complaints.h" | |
357e46e7 | 43 | #include "bcache.h" |
4c2df51b DJ |
44 | #include "dwarf2expr.h" |
45 | #include "dwarf2loc.h" | |
9219021c | 46 | #include "cp-support.h" |
72bf9492 | 47 | #include "hashtab.h" |
4c2df51b | 48 | |
c906108c SS |
49 | #include <fcntl.h> |
50 | #include "gdb_string.h" | |
4bdf3d34 | 51 | #include "gdb_assert.h" |
c906108c SS |
52 | #include <sys/types.h> |
53 | ||
d8151005 DJ |
54 | /* A note on memory usage for this file. |
55 | ||
56 | At the present time, this code reads the debug info sections into | |
57 | the objfile's objfile_obstack. A definite improvement for startup | |
58 | time, on platforms which do not emit relocations for debug | |
59 | sections, would be to use mmap instead. The object's complete | |
60 | debug information is loaded into memory, partly to simplify | |
61 | absolute DIE references. | |
62 | ||
63 | Whether using obstacks or mmap, the sections should remain loaded | |
64 | until the objfile is released, and pointers into the section data | |
65 | can be used for any other data associated to the objfile (symbol | |
66 | names, type names, location expressions to name a few). */ | |
67 | ||
88496bb5 MS |
68 | #ifndef DWARF2_REG_TO_REGNUM |
69 | #define DWARF2_REG_TO_REGNUM(REG) (REG) | |
70 | #endif | |
71 | ||
107d2387 | 72 | #if 0 |
357e46e7 | 73 | /* .debug_info header for a compilation unit |
c906108c SS |
74 | Because of alignment constraints, this structure has padding and cannot |
75 | be mapped directly onto the beginning of the .debug_info section. */ | |
76 | typedef struct comp_unit_header | |
77 | { | |
78 | unsigned int length; /* length of the .debug_info | |
79 | contribution */ | |
80 | unsigned short version; /* version number -- 2 for DWARF | |
81 | version 2 */ | |
82 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
83 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
84 | } | |
85 | _COMP_UNIT_HEADER; | |
86 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 87 | #endif |
c906108c SS |
88 | |
89 | /* .debug_pubnames header | |
90 | Because of alignment constraints, this structure has padding and cannot | |
91 | be mapped directly onto the beginning of the .debug_info section. */ | |
92 | typedef struct pubnames_header | |
93 | { | |
94 | unsigned int length; /* length of the .debug_pubnames | |
95 | contribution */ | |
96 | unsigned char version; /* version number -- 2 for DWARF | |
97 | version 2 */ | |
98 | unsigned int info_offset; /* offset into .debug_info section */ | |
99 | unsigned int info_size; /* byte size of .debug_info section | |
100 | portion */ | |
101 | } | |
102 | _PUBNAMES_HEADER; | |
103 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
104 | ||
105 | /* .debug_pubnames header | |
106 | Because of alignment constraints, this structure has padding and cannot | |
107 | be mapped directly onto the beginning of the .debug_info section. */ | |
108 | typedef struct aranges_header | |
109 | { | |
110 | unsigned int length; /* byte len of the .debug_aranges | |
111 | contribution */ | |
112 | unsigned short version; /* version number -- 2 for DWARF | |
113 | version 2 */ | |
114 | unsigned int info_offset; /* offset into .debug_info section */ | |
115 | unsigned char addr_size; /* byte size of an address */ | |
116 | unsigned char seg_size; /* byte size of segment descriptor */ | |
117 | } | |
118 | _ARANGES_HEADER; | |
119 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
120 | ||
121 | /* .debug_line statement program prologue | |
122 | Because of alignment constraints, this structure has padding and cannot | |
123 | be mapped directly onto the beginning of the .debug_info section. */ | |
124 | typedef struct statement_prologue | |
125 | { | |
126 | unsigned int total_length; /* byte length of the statement | |
127 | information */ | |
128 | unsigned short version; /* version number -- 2 for DWARF | |
129 | version 2 */ | |
130 | unsigned int prologue_length; /* # bytes between prologue & | |
131 | stmt program */ | |
132 | unsigned char minimum_instruction_length; /* byte size of | |
133 | smallest instr */ | |
134 | unsigned char default_is_stmt; /* initial value of is_stmt | |
135 | register */ | |
136 | char line_base; | |
137 | unsigned char line_range; | |
138 | unsigned char opcode_base; /* number assigned to first special | |
139 | opcode */ | |
140 | unsigned char *standard_opcode_lengths; | |
141 | } | |
142 | _STATEMENT_PROLOGUE; | |
143 | ||
6502dd73 DJ |
144 | static const struct objfile_data *dwarf2_objfile_data_key; |
145 | ||
146 | struct dwarf2_per_objfile | |
147 | { | |
148 | /* Sizes of debugging sections. */ | |
149 | unsigned int info_size; | |
150 | unsigned int abbrev_size; | |
151 | unsigned int line_size; | |
152 | unsigned int pubnames_size; | |
153 | unsigned int aranges_size; | |
154 | unsigned int loc_size; | |
155 | unsigned int macinfo_size; | |
156 | unsigned int str_size; | |
157 | unsigned int ranges_size; | |
158 | unsigned int frame_size; | |
159 | unsigned int eh_frame_size; | |
160 | ||
161 | /* Loaded data from the sections. */ | |
162 | char *info_buffer; | |
163 | char *abbrev_buffer; | |
164 | char *line_buffer; | |
165 | char *str_buffer; | |
166 | char *macinfo_buffer; | |
167 | char *ranges_buffer; | |
168 | char *loc_buffer; | |
169 | }; | |
170 | ||
171 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 172 | |
086df311 DJ |
173 | static asection *dwarf_info_section; |
174 | static asection *dwarf_abbrev_section; | |
175 | static asection *dwarf_line_section; | |
176 | static asection *dwarf_pubnames_section; | |
177 | static asection *dwarf_aranges_section; | |
178 | static asection *dwarf_loc_section; | |
179 | static asection *dwarf_macinfo_section; | |
180 | static asection *dwarf_str_section; | |
181 | static asection *dwarf_ranges_section; | |
182 | asection *dwarf_frame_section; | |
183 | asection *dwarf_eh_frame_section; | |
184 | ||
c906108c SS |
185 | /* names of the debugging sections */ |
186 | ||
187 | #define INFO_SECTION ".debug_info" | |
188 | #define ABBREV_SECTION ".debug_abbrev" | |
189 | #define LINE_SECTION ".debug_line" | |
190 | #define PUBNAMES_SECTION ".debug_pubnames" | |
191 | #define ARANGES_SECTION ".debug_aranges" | |
192 | #define LOC_SECTION ".debug_loc" | |
193 | #define MACINFO_SECTION ".debug_macinfo" | |
194 | #define STR_SECTION ".debug_str" | |
af34e669 | 195 | #define RANGES_SECTION ".debug_ranges" |
b6af0555 JS |
196 | #define FRAME_SECTION ".debug_frame" |
197 | #define EH_FRAME_SECTION ".eh_frame" | |
c906108c SS |
198 | |
199 | /* local data types */ | |
200 | ||
57349743 JB |
201 | /* We hold several abbreviation tables in memory at the same time. */ |
202 | #ifndef ABBREV_HASH_SIZE | |
203 | #define ABBREV_HASH_SIZE 121 | |
204 | #endif | |
205 | ||
107d2387 AC |
206 | /* The data in a compilation unit header, after target2host |
207 | translation, looks like this. */ | |
c906108c SS |
208 | struct comp_unit_head |
209 | { | |
613e1657 | 210 | unsigned long length; |
c906108c SS |
211 | short version; |
212 | unsigned int abbrev_offset; | |
213 | unsigned char addr_size; | |
107d2387 | 214 | unsigned char signed_addr_p; |
613e1657 KB |
215 | unsigned int offset_size; /* size of file offsets; either 4 or 8 */ |
216 | unsigned int initial_length_size; /* size of the length field; either | |
217 | 4 or 12 */ | |
57349743 JB |
218 | |
219 | /* Offset to the first byte of this compilation unit header in the | |
220 | * .debug_info section, for resolving relative reference dies. */ | |
221 | ||
222 | unsigned int offset; | |
223 | ||
224 | /* Pointer to this compilation unit header in the .debug_info | |
225 | * section */ | |
226 | ||
227 | char *cu_head_ptr; | |
228 | ||
229 | /* Pointer to the first die of this compilatio unit. This will | |
230 | * be the first byte following the compilation unit header. */ | |
231 | ||
232 | char *first_die_ptr; | |
233 | ||
234 | /* Pointer to the next compilation unit header in the program. */ | |
235 | ||
236 | struct comp_unit_head *next; | |
237 | ||
0d53c4c4 | 238 | /* Base address of this compilation unit. */ |
af34e669 | 239 | |
0d53c4c4 DJ |
240 | CORE_ADDR base_address; |
241 | ||
242 | /* Non-zero if base_address has been set. */ | |
243 | ||
244 | int base_known; | |
c906108c SS |
245 | }; |
246 | ||
e7c27a73 DJ |
247 | /* Internal state when decoding a particular compilation unit. */ |
248 | struct dwarf2_cu | |
249 | { | |
250 | /* The objfile containing this compilation unit. */ | |
251 | struct objfile *objfile; | |
252 | ||
253 | /* The header of the compilation unit. | |
254 | ||
255 | FIXME drow/2003-11-10: Some of the things from the comp_unit_head | |
f3dd6933 | 256 | should logically be moved to the dwarf2_cu structure. */ |
e7c27a73 | 257 | struct comp_unit_head header; |
e142c38c DJ |
258 | |
259 | struct function_range *first_fn, *last_fn, *cached_fn; | |
260 | ||
261 | /* The language we are debugging. */ | |
262 | enum language language; | |
263 | const struct language_defn *language_defn; | |
264 | ||
265 | /* The generic symbol table building routines have separate lists for | |
266 | file scope symbols and all all other scopes (local scopes). So | |
267 | we need to select the right one to pass to add_symbol_to_list(). | |
268 | We do it by keeping a pointer to the correct list in list_in_scope. | |
269 | ||
270 | FIXME: The original dwarf code just treated the file scope as the | |
271 | first local scope, and all other local scopes as nested local | |
272 | scopes, and worked fine. Check to see if we really need to | |
273 | distinguish these in buildsym.c. */ | |
274 | struct pending **list_in_scope; | |
275 | ||
276 | /* Maintain an array of referenced fundamental types for the current | |
277 | compilation unit being read. For DWARF version 1, we have to construct | |
278 | the fundamental types on the fly, since no information about the | |
279 | fundamental types is supplied. Each such fundamental type is created by | |
280 | calling a language dependent routine to create the type, and then a | |
281 | pointer to that type is then placed in the array at the index specified | |
282 | by it's FT_<TYPENAME> value. The array has a fixed size set by the | |
283 | FT_NUM_MEMBERS compile time constant, which is the number of predefined | |
284 | fundamental types gdb knows how to construct. */ | |
285 | struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ | |
f3dd6933 DJ |
286 | |
287 | /* DWARF abbreviation table associated with this compilation unit. */ | |
288 | struct abbrev_info **dwarf2_abbrevs; | |
289 | ||
290 | /* Storage for the abbrev table. */ | |
291 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
292 | |
293 | /* Hash table holding all the loaded partial DIEs. */ | |
294 | htab_t partial_dies; | |
295 | ||
296 | /* Storage for things with the same lifetime as this read-in compilation | |
297 | unit, including partial DIEs. */ | |
298 | struct obstack comp_unit_obstack; | |
299 | ||
300 | /* This flag will be set if this compilation unit includes any | |
301 | DW_TAG_namespace DIEs. If we know that there are explicit | |
302 | DIEs for namespaces, we don't need to try to infer them | |
303 | from mangled names. */ | |
304 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
305 | }; |
306 | ||
debd256d JB |
307 | /* The line number information for a compilation unit (found in the |
308 | .debug_line section) begins with a "statement program header", | |
309 | which contains the following information. */ | |
310 | struct line_header | |
311 | { | |
312 | unsigned int total_length; | |
313 | unsigned short version; | |
314 | unsigned int header_length; | |
315 | unsigned char minimum_instruction_length; | |
316 | unsigned char default_is_stmt; | |
317 | int line_base; | |
318 | unsigned char line_range; | |
319 | unsigned char opcode_base; | |
320 | ||
321 | /* standard_opcode_lengths[i] is the number of operands for the | |
322 | standard opcode whose value is i. This means that | |
323 | standard_opcode_lengths[0] is unused, and the last meaningful | |
324 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
325 | unsigned char *standard_opcode_lengths; | |
326 | ||
327 | /* The include_directories table. NOTE! These strings are not | |
328 | allocated with xmalloc; instead, they are pointers into | |
329 | debug_line_buffer. If you try to free them, `free' will get | |
330 | indigestion. */ | |
331 | unsigned int num_include_dirs, include_dirs_size; | |
332 | char **include_dirs; | |
333 | ||
334 | /* The file_names table. NOTE! These strings are not allocated | |
335 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
336 | Don't try to free them directly. */ | |
337 | unsigned int num_file_names, file_names_size; | |
338 | struct file_entry | |
c906108c | 339 | { |
debd256d JB |
340 | char *name; |
341 | unsigned int dir_index; | |
342 | unsigned int mod_time; | |
343 | unsigned int length; | |
344 | } *file_names; | |
345 | ||
346 | /* The start and end of the statement program following this | |
6502dd73 | 347 | header. These point into dwarf2_per_objfile->line_buffer. */ |
debd256d JB |
348 | char *statement_program_start, *statement_program_end; |
349 | }; | |
c906108c SS |
350 | |
351 | /* When we construct a partial symbol table entry we only | |
352 | need this much information. */ | |
353 | struct partial_die_info | |
354 | { | |
72bf9492 | 355 | /* Offset of this DIE. */ |
c906108c | 356 | unsigned int offset; |
72bf9492 DJ |
357 | |
358 | /* DWARF-2 tag for this DIE. */ | |
359 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
360 | ||
361 | /* Language code associated with this DIE. This is only used | |
362 | for the compilation unit DIE. */ | |
363 | unsigned int language : 8; | |
364 | ||
365 | /* Assorted flags describing the data found in this DIE. */ | |
366 | unsigned int has_children : 1; | |
367 | unsigned int is_external : 1; | |
368 | unsigned int is_declaration : 1; | |
369 | unsigned int has_type : 1; | |
370 | unsigned int has_specification : 1; | |
371 | unsigned int has_pc_info : 1; | |
372 | ||
373 | /* Flag set if the SCOPE field of this structure has been | |
374 | computed. */ | |
375 | unsigned int scope_set : 1; | |
376 | ||
377 | /* The name of this DIE. Normally the value of DW_AT_name, but | |
378 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
379 | other fashion. */ | |
c906108c | 380 | char *name; |
72bf9492 DJ |
381 | |
382 | /* The scope to prepend to our children. This is generally | |
383 | allocated on the comp_unit_obstack, so will disappear | |
384 | when this compilation unit leaves the cache. */ | |
385 | char *scope; | |
386 | ||
387 | /* The location description associated with this DIE, if any. */ | |
388 | struct dwarf_block *locdesc; | |
389 | ||
390 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
391 | CORE_ADDR lowpc; |
392 | CORE_ADDR highpc; | |
72bf9492 DJ |
393 | |
394 | /* Pointer into the info_buffer pointing at the target of | |
395 | DW_AT_sibling, if any. */ | |
c906108c | 396 | char *sibling; |
72bf9492 DJ |
397 | |
398 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
399 | DW_AT_specification (or DW_AT_abstract_origin or | |
400 | DW_AT_extension). */ | |
401 | unsigned int spec_offset; | |
402 | ||
403 | /* Pointers to this DIE's parent, first child, and next sibling, | |
404 | if any. */ | |
405 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
406 | }; |
407 | ||
408 | /* This data structure holds the information of an abbrev. */ | |
409 | struct abbrev_info | |
410 | { | |
411 | unsigned int number; /* number identifying abbrev */ | |
412 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
413 | unsigned short has_children; /* boolean */ |
414 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
415 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
416 | struct abbrev_info *next; /* next in chain */ | |
417 | }; | |
418 | ||
419 | struct attr_abbrev | |
420 | { | |
421 | enum dwarf_attribute name; | |
422 | enum dwarf_form form; | |
423 | }; | |
424 | ||
425 | /* This data structure holds a complete die structure. */ | |
426 | struct die_info | |
427 | { | |
c5aa993b | 428 | enum dwarf_tag tag; /* Tag indicating type of die */ |
c5aa993b JM |
429 | unsigned int abbrev; /* Abbrev number */ |
430 | unsigned int offset; /* Offset in .debug_info section */ | |
431 | unsigned int num_attrs; /* Number of attributes */ | |
432 | struct attribute *attrs; /* An array of attributes */ | |
433 | struct die_info *next_ref; /* Next die in ref hash table */ | |
78ba4af6 JB |
434 | |
435 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
436 | points to this die's parent; CHILD points to the first child of | |
437 | this node; and all the children of a given node are chained | |
438 | together via their SIBLING fields, terminated by a die whose | |
439 | tag is zero. */ | |
639d11d3 DC |
440 | struct die_info *child; /* Its first child, if any. */ |
441 | struct die_info *sibling; /* Its next sibling, if any. */ | |
442 | struct die_info *parent; /* Its parent, if any. */ | |
78ba4af6 | 443 | |
c5aa993b | 444 | struct type *type; /* Cached type information */ |
c906108c SS |
445 | }; |
446 | ||
447 | /* Attributes have a name and a value */ | |
448 | struct attribute | |
449 | { | |
450 | enum dwarf_attribute name; | |
451 | enum dwarf_form form; | |
452 | union | |
453 | { | |
454 | char *str; | |
455 | struct dwarf_block *blk; | |
ce5d95e1 JB |
456 | unsigned long unsnd; |
457 | long int snd; | |
c906108c SS |
458 | CORE_ADDR addr; |
459 | } | |
460 | u; | |
461 | }; | |
462 | ||
5fb290d7 DJ |
463 | struct function_range |
464 | { | |
465 | const char *name; | |
466 | CORE_ADDR lowpc, highpc; | |
467 | int seen_line; | |
468 | struct function_range *next; | |
469 | }; | |
470 | ||
c906108c SS |
471 | /* Get at parts of an attribute structure */ |
472 | ||
473 | #define DW_STRING(attr) ((attr)->u.str) | |
474 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
475 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
476 | #define DW_SND(attr) ((attr)->u.snd) | |
477 | #define DW_ADDR(attr) ((attr)->u.addr) | |
478 | ||
479 | /* Blocks are a bunch of untyped bytes. */ | |
480 | struct dwarf_block | |
481 | { | |
482 | unsigned int size; | |
483 | char *data; | |
484 | }; | |
485 | ||
c906108c SS |
486 | #ifndef ATTR_ALLOC_CHUNK |
487 | #define ATTR_ALLOC_CHUNK 4 | |
488 | #endif | |
489 | ||
c906108c SS |
490 | /* A hash table of die offsets for following references. */ |
491 | #ifndef REF_HASH_SIZE | |
492 | #define REF_HASH_SIZE 1021 | |
493 | #endif | |
494 | ||
495 | static struct die_info *die_ref_table[REF_HASH_SIZE]; | |
496 | ||
497 | /* Obstack for allocating temporary storage used during symbol reading. */ | |
498 | static struct obstack dwarf2_tmp_obstack; | |
499 | ||
c906108c SS |
500 | /* Allocate fields for structs, unions and enums in this size. */ |
501 | #ifndef DW_FIELD_ALLOC_CHUNK | |
502 | #define DW_FIELD_ALLOC_CHUNK 4 | |
503 | #endif | |
504 | ||
c906108c SS |
505 | /* A zeroed version of a partial die for initialization purposes. */ |
506 | static struct partial_die_info zeroed_partial_die; | |
507 | ||
7a292a7a SS |
508 | /* FIXME: decode_locdesc sets these variables to describe the location |
509 | to the caller. These ought to be a structure or something. If | |
510 | none of the flags are set, the object lives at the address returned | |
511 | by decode_locdesc. */ | |
512 | ||
7a292a7a SS |
513 | static int isreg; /* Object lives in register. |
514 | decode_locdesc's return value is | |
515 | the register number. */ | |
c906108c | 516 | |
c906108c | 517 | /* We put a pointer to this structure in the read_symtab_private field |
6502dd73 | 518 | of the psymtab. */ |
c906108c SS |
519 | |
520 | struct dwarf2_pinfo | |
c5aa993b | 521 | { |
6502dd73 | 522 | /* Offset in .debug_info for this compilation unit. */ |
c906108c | 523 | |
c5aa993b | 524 | unsigned long dwarf_info_offset; |
c5aa993b | 525 | }; |
c906108c SS |
526 | |
527 | #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private) | |
c906108c | 528 | #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset) |
c906108c | 529 | |
c906108c SS |
530 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
531 | but this would require a corresponding change in unpack_field_as_long | |
532 | and friends. */ | |
533 | static int bits_per_byte = 8; | |
534 | ||
535 | /* The routines that read and process dies for a C struct or C++ class | |
536 | pass lists of data member fields and lists of member function fields | |
537 | in an instance of a field_info structure, as defined below. */ | |
538 | struct field_info | |
c5aa993b JM |
539 | { |
540 | /* List of data member and baseclasses fields. */ | |
541 | struct nextfield | |
542 | { | |
543 | struct nextfield *next; | |
544 | int accessibility; | |
545 | int virtuality; | |
546 | struct field field; | |
547 | } | |
548 | *fields; | |
c906108c | 549 | |
c5aa993b JM |
550 | /* Number of fields. */ |
551 | int nfields; | |
c906108c | 552 | |
c5aa993b JM |
553 | /* Number of baseclasses. */ |
554 | int nbaseclasses; | |
c906108c | 555 | |
c5aa993b JM |
556 | /* Set if the accesibility of one of the fields is not public. */ |
557 | int non_public_fields; | |
c906108c | 558 | |
c5aa993b JM |
559 | /* Member function fields array, entries are allocated in the order they |
560 | are encountered in the object file. */ | |
561 | struct nextfnfield | |
562 | { | |
563 | struct nextfnfield *next; | |
564 | struct fn_field fnfield; | |
565 | } | |
566 | *fnfields; | |
c906108c | 567 | |
c5aa993b JM |
568 | /* Member function fieldlist array, contains name of possibly overloaded |
569 | member function, number of overloaded member functions and a pointer | |
570 | to the head of the member function field chain. */ | |
571 | struct fnfieldlist | |
572 | { | |
573 | char *name; | |
574 | int length; | |
575 | struct nextfnfield *head; | |
576 | } | |
577 | *fnfieldlists; | |
c906108c | 578 | |
c5aa993b JM |
579 | /* Number of entries in the fnfieldlists array. */ |
580 | int nfnfields; | |
581 | }; | |
c906108c | 582 | |
c906108c SS |
583 | /* Various complaints about symbol reading that don't abort the process */ |
584 | ||
4d3c2250 KB |
585 | static void |
586 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 587 | { |
4d3c2250 KB |
588 | complaint (&symfile_complaints, |
589 | "statement list doesn't fit in .debug_line section"); | |
590 | } | |
591 | ||
592 | static void | |
593 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 594 | { |
4d3c2250 KB |
595 | complaint (&symfile_complaints, "location expression too complex"); |
596 | } | |
597 | ||
4d3c2250 KB |
598 | static void |
599 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
600 | int arg3) | |
2e276125 | 601 | { |
4d3c2250 KB |
602 | complaint (&symfile_complaints, |
603 | "const value length mismatch for '%s', got %d, expected %d", arg1, | |
604 | arg2, arg3); | |
605 | } | |
606 | ||
607 | static void | |
608 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 609 | { |
4d3c2250 KB |
610 | complaint (&symfile_complaints, |
611 | "macro info runs off end of `.debug_macinfo' section"); | |
612 | } | |
613 | ||
614 | static void | |
615 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 616 | { |
4d3c2250 KB |
617 | complaint (&symfile_complaints, |
618 | "macro debug info contains a malformed macro definition:\n`%s'", | |
619 | arg1); | |
620 | } | |
621 | ||
622 | static void | |
623 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 624 | { |
4d3c2250 KB |
625 | complaint (&symfile_complaints, |
626 | "invalid attribute class or form for '%s' in '%s'", arg1, arg2); | |
627 | } | |
c906108c | 628 | |
c906108c SS |
629 | /* local function prototypes */ |
630 | ||
4efb68b1 | 631 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
632 | |
633 | #if 0 | |
a14ed312 | 634 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
635 | #endif |
636 | ||
a14ed312 | 637 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 638 | |
72bf9492 DJ |
639 | static void scan_partial_symbols (struct partial_die_info *, |
640 | CORE_ADDR *, CORE_ADDR *, | |
641 | struct dwarf2_cu *); | |
c906108c | 642 | |
72bf9492 DJ |
643 | static void add_partial_symbol (struct partial_die_info *, |
644 | struct dwarf2_cu *); | |
63d06c5c | 645 | |
72bf9492 | 646 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 647 | |
72bf9492 DJ |
648 | static void add_partial_namespace (struct partial_die_info *pdi, |
649 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
650 | struct dwarf2_cu *cu); | |
63d06c5c | 651 | |
72bf9492 DJ |
652 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
653 | struct dwarf2_cu *cu); | |
91c24f0a DC |
654 | |
655 | static char *locate_pdi_sibling (struct partial_die_info *orig_pdi, | |
656 | char *info_ptr, | |
657 | bfd *abfd, | |
e7c27a73 | 658 | struct dwarf2_cu *cu); |
91c24f0a | 659 | |
a14ed312 | 660 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 661 | |
a14ed312 | 662 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 663 | |
188dd5d6 | 664 | char *dwarf2_read_section (struct objfile *, asection *); |
c906108c | 665 | |
e7c27a73 | 666 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 667 | |
f3dd6933 | 668 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 669 | |
72bf9492 DJ |
670 | static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *); |
671 | ||
57349743 | 672 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 673 | struct dwarf2_cu *); |
c906108c | 674 | |
72bf9492 DJ |
675 | static struct partial_die_info *load_partial_dies (bfd *, char *, int, |
676 | struct dwarf2_cu *); | |
677 | ||
a14ed312 | 678 | static char *read_partial_die (struct partial_die_info *, |
72bf9492 | 679 | struct abbrev_info *abbrev, unsigned int, |
e7c27a73 | 680 | bfd *, char *, struct dwarf2_cu *); |
c906108c | 681 | |
72bf9492 DJ |
682 | static struct partial_die_info *find_partial_die (unsigned long, |
683 | struct dwarf2_cu *, | |
684 | struct dwarf2_cu **); | |
685 | ||
686 | static void fixup_partial_die (struct partial_die_info *, | |
687 | struct dwarf2_cu *); | |
688 | ||
107d2387 | 689 | static char *read_full_die (struct die_info **, bfd *, char *, |
e7c27a73 | 690 | struct dwarf2_cu *, int *); |
c906108c | 691 | |
a14ed312 | 692 | static char *read_attribute (struct attribute *, struct attr_abbrev *, |
e7c27a73 | 693 | bfd *, char *, struct dwarf2_cu *); |
c906108c | 694 | |
a8329558 | 695 | static char *read_attribute_value (struct attribute *, unsigned, |
e7c27a73 | 696 | bfd *, char *, struct dwarf2_cu *); |
a8329558 | 697 | |
a14ed312 | 698 | static unsigned int read_1_byte (bfd *, char *); |
c906108c | 699 | |
a14ed312 | 700 | static int read_1_signed_byte (bfd *, char *); |
c906108c | 701 | |
a14ed312 | 702 | static unsigned int read_2_bytes (bfd *, char *); |
c906108c | 703 | |
a14ed312 | 704 | static unsigned int read_4_bytes (bfd *, char *); |
c906108c | 705 | |
ce5d95e1 | 706 | static unsigned long read_8_bytes (bfd *, char *); |
c906108c | 707 | |
e7c27a73 | 708 | static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *, |
107d2387 | 709 | int *bytes_read); |
c906108c | 710 | |
613e1657 KB |
711 | static LONGEST read_initial_length (bfd *, char *, |
712 | struct comp_unit_head *, int *bytes_read); | |
713 | ||
714 | static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *, | |
715 | int *bytes_read); | |
716 | ||
a14ed312 | 717 | static char *read_n_bytes (bfd *, char *, unsigned int); |
c906108c | 718 | |
a14ed312 | 719 | static char *read_string (bfd *, char *, unsigned int *); |
c906108c | 720 | |
4bdf3d34 JJ |
721 | static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *, |
722 | unsigned int *); | |
723 | ||
ce5d95e1 | 724 | static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *); |
c906108c | 725 | |
ce5d95e1 | 726 | static long read_signed_leb128 (bfd *, char *, unsigned int *); |
c906108c | 727 | |
4bb7a0a7 DJ |
728 | static char *skip_leb128 (bfd *, char *); |
729 | ||
e142c38c | 730 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 731 | |
e142c38c DJ |
732 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
733 | struct dwarf2_cu *); | |
c906108c | 734 | |
05cf31d1 JB |
735 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
736 | struct dwarf2_cu *cu); | |
737 | ||
e142c38c | 738 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 739 | |
e142c38c DJ |
740 | static struct die_info *die_specification (struct die_info *die, |
741 | struct dwarf2_cu *); | |
63d06c5c | 742 | |
debd256d JB |
743 | static void free_line_header (struct line_header *lh); |
744 | ||
745 | static struct line_header *(dwarf_decode_line_header | |
746 | (unsigned int offset, | |
e7c27a73 | 747 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
748 | |
749 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
e7c27a73 | 750 | struct dwarf2_cu *); |
c906108c | 751 | |
a14ed312 | 752 | static void dwarf2_start_subfile (char *, char *); |
c906108c | 753 | |
a14ed312 | 754 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 755 | struct dwarf2_cu *); |
c906108c | 756 | |
a14ed312 | 757 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 758 | struct dwarf2_cu *); |
c906108c | 759 | |
2df3850c JM |
760 | static void dwarf2_const_value_data (struct attribute *attr, |
761 | struct symbol *sym, | |
762 | int bits); | |
763 | ||
e7c27a73 | 764 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 765 | |
e7c27a73 DJ |
766 | static struct type *die_containing_type (struct die_info *, |
767 | struct dwarf2_cu *); | |
c906108c SS |
768 | |
769 | #if 0 | |
a14ed312 | 770 | static struct type *type_at_offset (unsigned int, struct objfile *); |
c906108c SS |
771 | #endif |
772 | ||
e7c27a73 | 773 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 774 | |
e7c27a73 | 775 | static void read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 776 | |
086ed43d | 777 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c DC |
778 | |
779 | static char *typename_concat (const char *prefix, const char *suffix); | |
780 | ||
e7c27a73 | 781 | static void read_typedef (struct die_info *, struct dwarf2_cu *); |
c906108c | 782 | |
e7c27a73 | 783 | static void read_base_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 784 | |
a02abb62 JB |
785 | static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu); |
786 | ||
e7c27a73 | 787 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 788 | |
e7c27a73 | 789 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 790 | |
e7c27a73 | 791 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 792 | |
a14ed312 | 793 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 794 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 795 | |
fae299cd DC |
796 | static void get_scope_pc_bounds (struct die_info *, |
797 | CORE_ADDR *, CORE_ADDR *, | |
798 | struct dwarf2_cu *); | |
799 | ||
a14ed312 | 800 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 801 | struct dwarf2_cu *); |
c906108c | 802 | |
a14ed312 | 803 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 804 | struct type *, struct dwarf2_cu *); |
c906108c | 805 | |
a14ed312 | 806 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 807 | struct die_info *, struct type *, |
e7c27a73 | 808 | struct dwarf2_cu *); |
c906108c | 809 | |
a14ed312 | 810 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 811 | struct type *, struct dwarf2_cu *); |
c906108c | 812 | |
134d01f1 DJ |
813 | static void read_structure_type (struct die_info *, struct dwarf2_cu *); |
814 | ||
815 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); | |
c906108c | 816 | |
8176b9b8 DC |
817 | static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); |
818 | ||
e7c27a73 | 819 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 820 | |
e7c27a73 | 821 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 822 | |
38d518c9 | 823 | static const char *namespace_name (struct die_info *die, |
e142c38c | 824 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 825 | |
134d01f1 DJ |
826 | static void read_enumeration_type (struct die_info *, struct dwarf2_cu *); |
827 | ||
828 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); | |
c906108c | 829 | |
e7c27a73 | 830 | static struct type *dwarf_base_type (int, int, struct dwarf2_cu *); |
c906108c | 831 | |
e7c27a73 | 832 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 833 | |
e7c27a73 | 834 | static void read_array_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 835 | |
e7c27a73 | 836 | static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 837 | |
e7c27a73 DJ |
838 | static void read_tag_ptr_to_member_type (struct die_info *, |
839 | struct dwarf2_cu *); | |
c906108c | 840 | |
e7c27a73 | 841 | static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 842 | |
e7c27a73 | 843 | static void read_tag_const_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 844 | |
e7c27a73 | 845 | static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 846 | |
e7c27a73 | 847 | static void read_tag_string_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 848 | |
e7c27a73 | 849 | static void read_subroutine_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 850 | |
e7c27a73 | 851 | static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *); |
c906108c | 852 | |
639d11d3 | 853 | static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd, |
e7c27a73 | 854 | struct dwarf2_cu *, |
639d11d3 DC |
855 | char **new_info_ptr, |
856 | struct die_info *parent); | |
857 | ||
858 | static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd, | |
e7c27a73 | 859 | struct dwarf2_cu *, |
639d11d3 DC |
860 | char **new_info_ptr, |
861 | struct die_info *parent); | |
862 | ||
a14ed312 | 863 | static void free_die_list (struct die_info *); |
c906108c | 864 | |
74b7792f AC |
865 | static struct cleanup *make_cleanup_free_die_list (struct die_info *); |
866 | ||
e7c27a73 | 867 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 868 | |
e142c38c | 869 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 870 | |
e142c38c | 871 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 872 | |
e142c38c DJ |
873 | static struct die_info *dwarf2_extension (struct die_info *die, |
874 | struct dwarf2_cu *); | |
9219021c | 875 | |
a14ed312 | 876 | static char *dwarf_tag_name (unsigned int); |
c906108c | 877 | |
a14ed312 | 878 | static char *dwarf_attr_name (unsigned int); |
c906108c | 879 | |
a14ed312 | 880 | static char *dwarf_form_name (unsigned int); |
c906108c | 881 | |
a14ed312 | 882 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 883 | |
a14ed312 | 884 | static char *dwarf_bool_name (unsigned int); |
c906108c | 885 | |
a14ed312 | 886 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
887 | |
888 | #if 0 | |
a14ed312 | 889 | static char *dwarf_cfi_name (unsigned int); |
c906108c | 890 | |
a14ed312 | 891 | struct die_info *copy_die (struct die_info *); |
c906108c SS |
892 | #endif |
893 | ||
f9aca02d | 894 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 895 | |
f9aca02d | 896 | static void dump_die (struct die_info *); |
c906108c | 897 | |
f9aca02d | 898 | static void dump_die_list (struct die_info *); |
c906108c | 899 | |
f9aca02d | 900 | static void store_in_ref_table (unsigned int, struct die_info *); |
c906108c | 901 | |
7f0e3f52 | 902 | static void dwarf2_empty_hash_tables (void); |
c906108c | 903 | |
e142c38c DJ |
904 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *, |
905 | struct dwarf2_cu *); | |
c906108c | 906 | |
a02abb62 JB |
907 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
908 | ||
f9aca02d | 909 | static struct die_info *follow_die_ref (unsigned int); |
c906108c | 910 | |
e142c38c DJ |
911 | static struct type *dwarf2_fundamental_type (struct objfile *, int, |
912 | struct dwarf2_cu *); | |
c906108c SS |
913 | |
914 | /* memory allocation interface */ | |
915 | ||
4efb68b1 | 916 | static void dwarf2_free_tmp_obstack (void *); |
c906108c | 917 | |
a14ed312 | 918 | static struct dwarf_block *dwarf_alloc_block (void); |
c906108c | 919 | |
f3dd6933 | 920 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 921 | |
a14ed312 | 922 | static struct die_info *dwarf_alloc_die (void); |
c906108c | 923 | |
e142c38c | 924 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 925 | |
e142c38c DJ |
926 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
927 | struct dwarf2_cu *); | |
5fb290d7 | 928 | |
2e276125 | 929 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 930 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 931 | |
8e19ed76 PS |
932 | static int attr_form_is_block (struct attribute *); |
933 | ||
4c2df51b DJ |
934 | static void |
935 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 936 | struct dwarf2_cu *cu); |
4c2df51b | 937 | |
4bb7a0a7 DJ |
938 | static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev, |
939 | struct dwarf2_cu *cu); | |
940 | ||
72bf9492 DJ |
941 | static void free_stack_comp_unit (void *); |
942 | ||
943 | static void *hashtab_obstack_allocate (void *data, size_t size, size_t count); | |
944 | ||
945 | static void dummy_obstack_deallocate (void *object, void *data); | |
946 | ||
947 | static hashval_t partial_die_hash (const void *item); | |
948 | ||
949 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
950 | ||
c906108c SS |
951 | /* Try to locate the sections we need for DWARF 2 debugging |
952 | information and return true if we have enough to do something. */ | |
953 | ||
954 | int | |
6502dd73 | 955 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 956 | { |
6502dd73 DJ |
957 | struct dwarf2_per_objfile *data; |
958 | ||
959 | /* Initialize per-objfile state. */ | |
960 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
961 | memset (data, 0, sizeof (*data)); | |
962 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
963 | dwarf2_per_objfile = data; | |
964 | ||
188dd5d6 DJ |
965 | dwarf_info_section = 0; |
966 | dwarf_abbrev_section = 0; | |
967 | dwarf_line_section = 0; | |
968 | dwarf_str_section = 0; | |
969 | dwarf_macinfo_section = 0; | |
970 | dwarf_frame_section = 0; | |
971 | dwarf_eh_frame_section = 0; | |
972 | dwarf_ranges_section = 0; | |
973 | dwarf_loc_section = 0; | |
af34e669 | 974 | |
6502dd73 | 975 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
188dd5d6 | 976 | return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); |
c906108c SS |
977 | } |
978 | ||
979 | /* This function is mapped across the sections and remembers the | |
980 | offset and size of each of the debugging sections we are interested | |
981 | in. */ | |
982 | ||
983 | static void | |
4efb68b1 | 984 | dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr) |
c906108c | 985 | { |
6314a349 | 986 | if (strcmp (sectp->name, INFO_SECTION) == 0) |
c906108c | 987 | { |
6502dd73 | 988 | dwarf2_per_objfile->info_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 989 | dwarf_info_section = sectp; |
c906108c | 990 | } |
6314a349 | 991 | else if (strcmp (sectp->name, ABBREV_SECTION) == 0) |
c906108c | 992 | { |
6502dd73 | 993 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 994 | dwarf_abbrev_section = sectp; |
c906108c | 995 | } |
6314a349 | 996 | else if (strcmp (sectp->name, LINE_SECTION) == 0) |
c906108c | 997 | { |
6502dd73 | 998 | dwarf2_per_objfile->line_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 999 | dwarf_line_section = sectp; |
c906108c | 1000 | } |
6314a349 | 1001 | else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0) |
c906108c | 1002 | { |
6502dd73 | 1003 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1004 | dwarf_pubnames_section = sectp; |
c906108c | 1005 | } |
6314a349 | 1006 | else if (strcmp (sectp->name, ARANGES_SECTION) == 0) |
c906108c | 1007 | { |
6502dd73 | 1008 | dwarf2_per_objfile->aranges_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1009 | dwarf_aranges_section = sectp; |
c906108c | 1010 | } |
6314a349 | 1011 | else if (strcmp (sectp->name, LOC_SECTION) == 0) |
c906108c | 1012 | { |
6502dd73 | 1013 | dwarf2_per_objfile->loc_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1014 | dwarf_loc_section = sectp; |
c906108c | 1015 | } |
6314a349 | 1016 | else if (strcmp (sectp->name, MACINFO_SECTION) == 0) |
c906108c | 1017 | { |
6502dd73 | 1018 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size_before_reloc (sectp); |
0cf824c9 | 1019 | dwarf_macinfo_section = sectp; |
c906108c | 1020 | } |
6314a349 | 1021 | else if (strcmp (sectp->name, STR_SECTION) == 0) |
c906108c | 1022 | { |
6502dd73 | 1023 | dwarf2_per_objfile->str_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1024 | dwarf_str_section = sectp; |
c906108c | 1025 | } |
6314a349 | 1026 | else if (strcmp (sectp->name, FRAME_SECTION) == 0) |
b6af0555 | 1027 | { |
6502dd73 | 1028 | dwarf2_per_objfile->frame_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1029 | dwarf_frame_section = sectp; |
b6af0555 | 1030 | } |
6314a349 | 1031 | else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0) |
b6af0555 | 1032 | { |
3799ccc6 EZ |
1033 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1034 | if (aflag & SEC_HAS_CONTENTS) | |
1035 | { | |
6502dd73 | 1036 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size_before_reloc (sectp); |
3799ccc6 EZ |
1037 | dwarf_eh_frame_section = sectp; |
1038 | } | |
b6af0555 | 1039 | } |
6314a349 | 1040 | else if (strcmp (sectp->name, RANGES_SECTION) == 0) |
af34e669 | 1041 | { |
6502dd73 | 1042 | dwarf2_per_objfile->ranges_size = bfd_get_section_size_before_reloc (sectp); |
6f10aeb1 | 1043 | dwarf_ranges_section = sectp; |
af34e669 | 1044 | } |
c906108c SS |
1045 | } |
1046 | ||
1047 | /* Build a partial symbol table. */ | |
1048 | ||
1049 | void | |
fba45db2 | 1050 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
c906108c | 1051 | { |
c906108c SS |
1052 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
1053 | ||
6502dd73 DJ |
1054 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); |
1055 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |
188dd5d6 DJ |
1056 | |
1057 | if (dwarf_line_section) | |
6502dd73 | 1058 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); |
41ff2da1 | 1059 | else |
6502dd73 | 1060 | dwarf2_per_objfile->line_buffer = NULL; |
c906108c | 1061 | |
188dd5d6 | 1062 | if (dwarf_str_section) |
6502dd73 | 1063 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); |
4bdf3d34 | 1064 | else |
6502dd73 | 1065 | dwarf2_per_objfile->str_buffer = NULL; |
4bdf3d34 | 1066 | |
188dd5d6 | 1067 | if (dwarf_macinfo_section) |
6502dd73 | 1068 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, |
086df311 | 1069 | dwarf_macinfo_section); |
2e276125 | 1070 | else |
6502dd73 | 1071 | dwarf2_per_objfile->macinfo_buffer = NULL; |
2e276125 | 1072 | |
188dd5d6 | 1073 | if (dwarf_ranges_section) |
6502dd73 | 1074 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); |
af34e669 | 1075 | else |
6502dd73 | 1076 | dwarf2_per_objfile->ranges_buffer = NULL; |
af34e669 | 1077 | |
188dd5d6 | 1078 | if (dwarf_loc_section) |
6502dd73 | 1079 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); |
0d53c4c4 | 1080 | else |
6502dd73 | 1081 | dwarf2_per_objfile->loc_buffer = NULL; |
0d53c4c4 | 1082 | |
ef96bde8 EZ |
1083 | if (mainline |
1084 | || (objfile->global_psymbols.size == 0 | |
1085 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1086 | { |
1087 | init_psymbol_list (objfile, 1024); | |
1088 | } | |
1089 | ||
1090 | #if 0 | |
1091 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1092 | { | |
d4f3574e | 1093 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1094 | .debug_pubnames sections */ |
1095 | ||
d4f3574e | 1096 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1097 | } |
1098 | else | |
1099 | #endif | |
1100 | /* only test this case for now */ | |
c5aa993b | 1101 | { |
c906108c | 1102 | /* In this case we have to work a bit harder */ |
d4f3574e | 1103 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1104 | } |
1105 | } | |
1106 | ||
1107 | #if 0 | |
1108 | /* Build the partial symbol table from the information in the | |
1109 | .debug_pubnames and .debug_aranges sections. */ | |
1110 | ||
1111 | static void | |
fba45db2 | 1112 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1113 | { |
1114 | bfd *abfd = objfile->obfd; | |
1115 | char *aranges_buffer, *pubnames_buffer; | |
1116 | char *aranges_ptr, *pubnames_ptr; | |
1117 | unsigned int entry_length, version, info_offset, info_size; | |
1118 | ||
1119 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1120 | dwarf_pubnames_section); |
c906108c | 1121 | pubnames_ptr = pubnames_buffer; |
6502dd73 | 1122 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) |
c906108c | 1123 | { |
613e1657 KB |
1124 | struct comp_unit_head cu_header; |
1125 | int bytes_read; | |
1126 | ||
1127 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, | |
1128 | &bytes_read); | |
1129 | pubnames_ptr += bytes_read; | |
c906108c SS |
1130 | version = read_1_byte (abfd, pubnames_ptr); |
1131 | pubnames_ptr += 1; | |
1132 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1133 | pubnames_ptr += 4; | |
1134 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1135 | pubnames_ptr += 4; | |
1136 | } | |
1137 | ||
1138 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1139 | dwarf_aranges_section); |
c906108c SS |
1140 | |
1141 | } | |
1142 | #endif | |
1143 | ||
107d2387 AC |
1144 | /* Read in the comp unit header information from the debug_info at |
1145 | info_ptr. */ | |
1146 | ||
1147 | static char * | |
1148 | read_comp_unit_head (struct comp_unit_head *cu_header, | |
1149 | char *info_ptr, bfd *abfd) | |
1150 | { | |
1151 | int signed_addr; | |
613e1657 KB |
1152 | int bytes_read; |
1153 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, | |
1154 | &bytes_read); | |
1155 | info_ptr += bytes_read; | |
107d2387 AC |
1156 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1157 | info_ptr += 2; | |
613e1657 KB |
1158 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
1159 | &bytes_read); | |
1160 | info_ptr += bytes_read; | |
107d2387 AC |
1161 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1162 | info_ptr += 1; | |
1163 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1164 | if (signed_addr < 0) | |
8e65ff28 AC |
1165 | internal_error (__FILE__, __LINE__, |
1166 | "read_comp_unit_head: dwarf from non elf file"); | |
107d2387 AC |
1167 | cu_header->signed_addr_p = signed_addr; |
1168 | return info_ptr; | |
1169 | } | |
1170 | ||
72bf9492 DJ |
1171 | static char * |
1172 | partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr, | |
1173 | bfd *abfd) | |
1174 | { | |
1175 | char *beg_of_comp_unit = info_ptr; | |
1176 | ||
1177 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1178 | ||
1179 | if (header->version != 2) | |
1180 | error ("Dwarf Error: wrong version in compilation unit header " | |
1181 | "(is %d, should be %d) [in module %s]", header->version, | |
1182 | 2, bfd_get_filename (abfd)); | |
1183 | ||
1184 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |
1185 | error ("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
1186 | "(offset 0x%lx + 6) [in module %s]", | |
1187 | (long) header->abbrev_offset, | |
1188 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1189 | bfd_get_filename (abfd)); | |
1190 | ||
1191 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
1192 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
1193 | error ("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
1194 | "(offset 0x%lx + 0) [in module %s]", | |
1195 | (long) header->length, | |
1196 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1197 | bfd_get_filename (abfd)); | |
1198 | ||
1199 | return info_ptr; | |
1200 | } | |
1201 | ||
c906108c SS |
1202 | /* Build the partial symbol table by doing a quick pass through the |
1203 | .debug_info and .debug_abbrev sections. */ | |
1204 | ||
1205 | static void | |
fba45db2 | 1206 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1207 | { |
1208 | /* Instead of reading this into a big buffer, we should probably use | |
1209 | mmap() on architectures that support it. (FIXME) */ | |
1210 | bfd *abfd = objfile->obfd; | |
72bf9492 | 1211 | char *info_ptr; |
c906108c | 1212 | char *beg_of_comp_unit; |
c906108c SS |
1213 | struct partial_die_info comp_unit_die; |
1214 | struct partial_symtab *pst; | |
1215 | struct cleanup *back_to; | |
e142c38c | 1216 | CORE_ADDR lowpc, highpc, baseaddr; |
c906108c | 1217 | |
6502dd73 | 1218 | info_ptr = dwarf2_per_objfile->info_buffer; |
c906108c | 1219 | |
9e84cbde JB |
1220 | /* We use dwarf2_tmp_obstack for objects that don't need to survive |
1221 | the partial symbol scan, like attribute values. | |
1222 | ||
1223 | We could reduce our peak memory consumption during partial symbol | |
1224 | table construction by freeing stuff from this obstack more often | |
1225 | --- say, after processing each compilation unit, or each die --- | |
1226 | but it turns out that this saves almost nothing. For an | |
1227 | executable with 11Mb of Dwarf 2 data, I found about 64k allocated | |
1228 | on dwarf2_tmp_obstack. Some investigation showed: | |
1229 | ||
1230 | 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*, | |
1231 | DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are | |
1232 | all fixed-length values not requiring dynamic allocation. | |
1233 | ||
1234 | 2) 30% of the attributes used the form DW_FORM_string. For | |
1235 | DW_FORM_string, read_attribute simply hands back a pointer to | |
6502dd73 | 1236 | the null-terminated string in info_buffer, so no dynamic |
9e84cbde JB |
1237 | allocation is needed there either. |
1238 | ||
1239 | 3) The remaining 1% of the attributes all used DW_FORM_block1. | |
1240 | 75% of those were DW_AT_frame_base location lists for | |
1241 | functions; the rest were DW_AT_location attributes, probably | |
1242 | for the global variables. | |
1243 | ||
1244 | Anyway, what this all means is that the memory the dwarf2 | |
1245 | reader uses as temporary space reading partial symbols is about | |
1246 | 0.5% as much as we use for dwarf_*_buffer. That's noise. */ | |
1247 | ||
c906108c SS |
1248 | obstack_init (&dwarf2_tmp_obstack); |
1249 | back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); | |
1250 | ||
6502dd73 | 1251 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1252 | length, only the individual functions to extract them (like |
72bf9492 | 1253 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1254 | the buffer is large enough to hold another complete object. |
1255 | ||
6502dd73 DJ |
1256 | At the moment, they don't actually check that. If .debug_info |
1257 | holds just one extra byte after the last compilation unit's dies, | |
1258 | then read_comp_unit_head will happily read off the end of the | |
1259 | buffer. read_partial_die is similarly casual. Those functions | |
1260 | should be fixed. | |
af703f96 JB |
1261 | |
1262 | For this loop condition, simply checking whether there's any data | |
1263 | left at all should be sufficient. */ | |
6502dd73 DJ |
1264 | while (info_ptr < (dwarf2_per_objfile->info_buffer |
1265 | + dwarf2_per_objfile->info_size)) | |
c906108c | 1266 | { |
f3dd6933 | 1267 | struct cleanup *back_to_inner; |
e7c27a73 | 1268 | struct dwarf2_cu cu; |
72bf9492 DJ |
1269 | struct abbrev_info *abbrev; |
1270 | unsigned int bytes_read; | |
1271 | struct dwarf2_per_cu_data *this_cu; | |
1272 | ||
c906108c | 1273 | beg_of_comp_unit = info_ptr; |
c906108c | 1274 | |
72bf9492 DJ |
1275 | memset (&cu, 0, sizeof (cu)); |
1276 | ||
1277 | obstack_init (&cu.comp_unit_obstack); | |
1278 | ||
1279 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1280 | ||
e7c27a73 | 1281 | cu.objfile = objfile; |
72bf9492 | 1282 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1283 | |
57349743 | 1284 | /* Complete the cu_header */ |
6502dd73 | 1285 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
e7c27a73 DJ |
1286 | cu.header.first_die_ptr = info_ptr; |
1287 | cu.header.cu_head_ptr = beg_of_comp_unit; | |
57349743 | 1288 | |
e142c38c DJ |
1289 | cu.list_in_scope = &file_symbols; |
1290 | ||
72bf9492 DJ |
1291 | cu.partial_dies = NULL; |
1292 | ||
c906108c | 1293 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1294 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1295 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c SS |
1296 | |
1297 | /* Read the compilation unit die */ | |
72bf9492 DJ |
1298 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1299 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1300 | abfd, info_ptr, &cu); | |
c906108c SS |
1301 | |
1302 | /* Set the language we're debugging */ | |
e142c38c | 1303 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1304 | |
1305 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1306 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1307 | comp_unit_die.name ? comp_unit_die.name : "", |
c906108c SS |
1308 | comp_unit_die.lowpc, |
1309 | objfile->global_psymbols.next, | |
1310 | objfile->static_psymbols.next); | |
1311 | ||
1312 | pst->read_symtab_private = (char *) | |
8b92e4d5 | 1313 | obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo)); |
6502dd73 | 1314 | DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
613e1657 | 1315 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1316 | |
1317 | /* Store the function that reads in the rest of the symbol table */ | |
1318 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1319 | ||
1320 | /* Check if comp unit has_children. | |
1321 | If so, read the rest of the partial symbols from this comp unit. | |
1322 | If not, there's no more debug_info for this comp unit. */ | |
1323 | if (comp_unit_die.has_children) | |
1324 | { | |
72bf9492 DJ |
1325 | struct partial_die_info *first_die; |
1326 | ||
91c24f0a DC |
1327 | lowpc = ((CORE_ADDR) -1); |
1328 | highpc = ((CORE_ADDR) 0); | |
1329 | ||
72bf9492 DJ |
1330 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1331 | ||
1332 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |
c906108c | 1333 | |
91c24f0a DC |
1334 | /* If we didn't find a lowpc, set it to highpc to avoid |
1335 | complaints from `maint check'. */ | |
1336 | if (lowpc == ((CORE_ADDR) -1)) | |
1337 | lowpc = highpc; | |
72bf9492 | 1338 | |
c906108c SS |
1339 | /* If the compilation unit didn't have an explicit address range, |
1340 | then use the information extracted from its child dies. */ | |
0b010bcc | 1341 | if (! comp_unit_die.has_pc_info) |
c906108c | 1342 | { |
c5aa993b | 1343 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1344 | comp_unit_die.highpc = highpc; |
1345 | } | |
1346 | } | |
c5aa993b | 1347 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1348 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1349 | ||
1350 | pst->n_global_syms = objfile->global_psymbols.next - | |
1351 | (objfile->global_psymbols.list + pst->globals_offset); | |
1352 | pst->n_static_syms = objfile->static_psymbols.next - | |
1353 | (objfile->static_psymbols.list + pst->statics_offset); | |
1354 | sort_pst_symbols (pst); | |
1355 | ||
1356 | /* If there is already a psymtab or symtab for a file of this | |
1357 | name, remove it. (If there is a symtab, more drastic things | |
1358 | also happen.) This happens in VxWorks. */ | |
1359 | free_named_symtabs (pst->filename); | |
1360 | ||
72bf9492 | 1361 | info_ptr = beg_of_comp_unit + cu.header.length |
e7c27a73 | 1362 | + cu.header.initial_length_size; |
f3dd6933 DJ |
1363 | |
1364 | do_cleanups (back_to_inner); | |
c906108c SS |
1365 | } |
1366 | do_cleanups (back_to); | |
1367 | } | |
1368 | ||
72bf9492 DJ |
1369 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. |
1370 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |
1371 | in CU. */ | |
c906108c | 1372 | |
72bf9492 DJ |
1373 | static void |
1374 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
1375 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |
c906108c | 1376 | { |
e7c27a73 | 1377 | struct objfile *objfile = cu->objfile; |
c906108c | 1378 | bfd *abfd = objfile->obfd; |
72bf9492 | 1379 | struct partial_die_info *pdi; |
c906108c | 1380 | |
91c24f0a DC |
1381 | /* Now, march along the PDI's, descending into ones which have |
1382 | interesting children but skipping the children of the other ones, | |
1383 | until we reach the end of the compilation unit. */ | |
c906108c | 1384 | |
72bf9492 | 1385 | pdi = first_die; |
91c24f0a | 1386 | |
72bf9492 DJ |
1387 | while (pdi != NULL) |
1388 | { | |
1389 | fixup_partial_die (pdi, cu); | |
c906108c | 1390 | |
91c24f0a DC |
1391 | /* Anonymous namespaces have no name but have interesting |
1392 | children, so we need to look at them. Ditto for anonymous | |
1393 | enums. */ | |
933c6fe4 | 1394 | |
72bf9492 DJ |
1395 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1396 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1397 | { |
72bf9492 | 1398 | switch (pdi->tag) |
c906108c SS |
1399 | { |
1400 | case DW_TAG_subprogram: | |
72bf9492 | 1401 | if (pdi->has_pc_info) |
c906108c | 1402 | { |
72bf9492 | 1403 | if (pdi->lowpc < *lowpc) |
c906108c | 1404 | { |
72bf9492 | 1405 | *lowpc = pdi->lowpc; |
c906108c | 1406 | } |
72bf9492 | 1407 | if (pdi->highpc > *highpc) |
c906108c | 1408 | { |
72bf9492 | 1409 | *highpc = pdi->highpc; |
c906108c | 1410 | } |
72bf9492 | 1411 | if (!pdi->is_declaration) |
c906108c | 1412 | { |
72bf9492 | 1413 | add_partial_symbol (pdi, cu); |
c906108c SS |
1414 | } |
1415 | } | |
1416 | break; | |
1417 | case DW_TAG_variable: | |
1418 | case DW_TAG_typedef: | |
91c24f0a | 1419 | case DW_TAG_union_type: |
72bf9492 | 1420 | if (!pdi->is_declaration) |
63d06c5c | 1421 | { |
72bf9492 | 1422 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1423 | } |
1424 | break; | |
c906108c SS |
1425 | case DW_TAG_class_type: |
1426 | case DW_TAG_structure_type: | |
72bf9492 | 1427 | if (!pdi->is_declaration) |
c906108c | 1428 | { |
72bf9492 | 1429 | add_partial_symbol (pdi, cu); |
c906108c SS |
1430 | } |
1431 | break; | |
91c24f0a | 1432 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1433 | if (!pdi->is_declaration) |
1434 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1435 | break; |
1436 | case DW_TAG_base_type: | |
a02abb62 | 1437 | case DW_TAG_subrange_type: |
c906108c | 1438 | /* File scope base type definitions are added to the partial |
c5aa993b | 1439 | symbol table. */ |
72bf9492 | 1440 | add_partial_symbol (pdi, cu); |
c906108c | 1441 | break; |
d9fa45fe | 1442 | case DW_TAG_namespace: |
72bf9492 | 1443 | add_partial_namespace (pdi, lowpc, highpc, cu); |
91c24f0a | 1444 | break; |
c906108c SS |
1445 | default: |
1446 | break; | |
1447 | } | |
1448 | } | |
1449 | ||
72bf9492 DJ |
1450 | /* If the die has a sibling, skip to the sibling. */ |
1451 | ||
1452 | pdi = pdi->die_sibling; | |
1453 | } | |
1454 | } | |
1455 | ||
1456 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1457 | |
72bf9492 DJ |
1458 | Normally, this is simple. For C++, the parent DIE's fully scoped |
1459 | name is concatenated with "::" and the partial DIE's name. | |
1460 | Enumerators are an exception; they use the scope of their parent | |
1461 | enumeration type, i.e. the name of the enumeration type is not | |
1462 | prepended to the enumerator. | |
91c24f0a | 1463 | |
72bf9492 DJ |
1464 | There are two complexities. One is DW_AT_specification; in this |
1465 | case "parent" means the parent of the target of the specification, | |
1466 | instead of the direct parent of the DIE. The other is compilers | |
1467 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1468 | the fully qualified name of structure types from their members' | |
1469 | linkage names. This must be done using the DIE's children rather | |
1470 | than the children of any DW_AT_specification target. We only need | |
1471 | to do this for structures at the top level, i.e. if the target of | |
1472 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
1473 | have a parent. */ | |
1474 | ||
1475 | /* Compute the scope prefix associated with PDI's parent, in | |
1476 | compilation unit CU. The result will be allocated on CU's | |
1477 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
1478 | field. NULL is returned if no prefix is necessary. */ | |
1479 | static char * | |
1480 | partial_die_parent_scope (struct partial_die_info *pdi, | |
1481 | struct dwarf2_cu *cu) | |
1482 | { | |
1483 | char *grandparent_scope; | |
1484 | struct partial_die_info *parent, *real_pdi; | |
1485 | struct dwarf2_cu *spec_cu; | |
91c24f0a | 1486 | |
72bf9492 DJ |
1487 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
1488 | then this means the parent of the specification DIE. */ | |
1489 | ||
1490 | real_pdi = pdi; | |
1491 | spec_cu = cu; | |
1492 | while (real_pdi->has_specification) | |
1493 | real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu); | |
1494 | ||
1495 | parent = real_pdi->die_parent; | |
1496 | if (parent == NULL) | |
1497 | return NULL; | |
1498 | ||
1499 | if (parent->scope_set) | |
1500 | return parent->scope; | |
1501 | ||
1502 | fixup_partial_die (parent, cu); | |
1503 | ||
1504 | grandparent_scope = partial_die_parent_scope (parent, spec_cu); | |
1505 | ||
1506 | if (parent->tag == DW_TAG_namespace | |
1507 | || parent->tag == DW_TAG_structure_type | |
1508 | || parent->tag == DW_TAG_class_type | |
1509 | || parent->tag == DW_TAG_union_type) | |
1510 | { | |
1511 | if (grandparent_scope == NULL) | |
1512 | parent->scope = parent->name; | |
1513 | else | |
1514 | parent->scope = obconcat (&cu->comp_unit_obstack, grandparent_scope, | |
1515 | "::", parent->name); | |
1516 | } | |
1517 | else if (parent->tag == DW_TAG_enumeration_type) | |
1518 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
1519 | parent->scope = grandparent_scope; | |
1520 | else | |
1521 | { | |
1522 | /* FIXME drow/2004-04-01: What should we be doing with | |
1523 | function-local names? For partial symbols, we should probably be | |
1524 | ignoring them. */ | |
1525 | complaint (&symfile_complaints, | |
1526 | "unhandled containing DIE tag %d for DIE at %d", | |
1527 | parent->tag, pdi->offset); | |
1528 | parent->scope = grandparent_scope; | |
c906108c SS |
1529 | } |
1530 | ||
72bf9492 DJ |
1531 | parent->scope_set = 1; |
1532 | return parent->scope; | |
1533 | } | |
1534 | ||
1535 | /* Return the fully scoped name associated with PDI, from compilation unit | |
1536 | CU. The result will be allocated with malloc. */ | |
1537 | static char * | |
1538 | partial_die_full_name (struct partial_die_info *pdi, | |
1539 | struct dwarf2_cu *cu) | |
1540 | { | |
1541 | char *parent_scope; | |
1542 | ||
1543 | parent_scope = partial_die_parent_scope (pdi, cu); | |
1544 | if (parent_scope == NULL) | |
1545 | return NULL; | |
1546 | else | |
1547 | return concat (parent_scope, "::", pdi->name, NULL); | |
c906108c SS |
1548 | } |
1549 | ||
1550 | static void | |
72bf9492 | 1551 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 1552 | { |
e7c27a73 | 1553 | struct objfile *objfile = cu->objfile; |
c906108c | 1554 | CORE_ADDR addr = 0; |
72bf9492 DJ |
1555 | char *actual_name; |
1556 | const char *my_prefix; | |
5c4e30ca | 1557 | const struct partial_symbol *psym = NULL; |
e142c38c | 1558 | CORE_ADDR baseaddr; |
72bf9492 | 1559 | int built_actual_name = 0; |
e142c38c DJ |
1560 | |
1561 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 1562 | |
72bf9492 DJ |
1563 | actual_name = NULL; |
1564 | ||
1565 | if (pdi_needs_namespace (pdi->tag)) | |
63d06c5c | 1566 | { |
72bf9492 DJ |
1567 | actual_name = partial_die_full_name (pdi, cu); |
1568 | if (actual_name) | |
1569 | built_actual_name = 1; | |
63d06c5c DC |
1570 | } |
1571 | ||
72bf9492 DJ |
1572 | if (actual_name == NULL) |
1573 | actual_name = pdi->name; | |
1574 | ||
c906108c SS |
1575 | switch (pdi->tag) |
1576 | { | |
1577 | case DW_TAG_subprogram: | |
1578 | if (pdi->is_external) | |
1579 | { | |
38d518c9 | 1580 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1581 | mst_text, objfile); */ |
38d518c9 | 1582 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1583 | VAR_DOMAIN, LOC_BLOCK, |
1584 | &objfile->global_psymbols, | |
1585 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1586 | cu->language, objfile); |
c906108c SS |
1587 | } |
1588 | else | |
1589 | { | |
38d518c9 | 1590 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1591 | mst_file_text, objfile); */ |
38d518c9 | 1592 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1593 | VAR_DOMAIN, LOC_BLOCK, |
1594 | &objfile->static_psymbols, | |
1595 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1596 | cu->language, objfile); |
c906108c SS |
1597 | } |
1598 | break; | |
1599 | case DW_TAG_variable: | |
1600 | if (pdi->is_external) | |
1601 | { | |
1602 | /* Global Variable. | |
1603 | Don't enter into the minimal symbol tables as there is | |
1604 | a minimal symbol table entry from the ELF symbols already. | |
1605 | Enter into partial symbol table if it has a location | |
1606 | descriptor or a type. | |
1607 | If the location descriptor is missing, new_symbol will create | |
1608 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
1609 | be determined from the minimal symbol table whenever the variable | |
1610 | is referenced. | |
1611 | The address for the partial symbol table entry is not | |
1612 | used by GDB, but it comes in handy for debugging partial symbol | |
1613 | table building. */ | |
1614 | ||
1615 | if (pdi->locdesc) | |
e7c27a73 | 1616 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 1617 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 1618 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1619 | VAR_DOMAIN, LOC_STATIC, |
1620 | &objfile->global_psymbols, | |
1621 | 0, addr + baseaddr, | |
e142c38c | 1622 | cu->language, objfile); |
c906108c SS |
1623 | } |
1624 | else | |
1625 | { | |
1626 | /* Static Variable. Skip symbols without location descriptors. */ | |
1627 | if (pdi->locdesc == NULL) | |
1628 | return; | |
e7c27a73 | 1629 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 1630 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 1631 | mst_file_data, objfile); */ |
38d518c9 | 1632 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1633 | VAR_DOMAIN, LOC_STATIC, |
1634 | &objfile->static_psymbols, | |
1635 | 0, addr + baseaddr, | |
e142c38c | 1636 | cu->language, objfile); |
c906108c SS |
1637 | } |
1638 | break; | |
1639 | case DW_TAG_typedef: | |
1640 | case DW_TAG_base_type: | |
a02abb62 | 1641 | case DW_TAG_subrange_type: |
38d518c9 | 1642 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1643 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 1644 | &objfile->static_psymbols, |
e142c38c | 1645 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 1646 | break; |
72bf9492 DJ |
1647 | case DW_TAG_namespace: |
1648 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
1649 | VAR_DOMAIN, LOC_TYPEDEF, | |
1650 | &objfile->global_psymbols, | |
1651 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
1652 | break; | |
c906108c SS |
1653 | case DW_TAG_class_type: |
1654 | case DW_TAG_structure_type: | |
1655 | case DW_TAG_union_type: | |
1656 | case DW_TAG_enumeration_type: | |
1657 | /* Skip aggregate types without children, these are external | |
c5aa993b | 1658 | references. */ |
63d06c5c DC |
1659 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
1660 | static vs. global. */ | |
c906108c SS |
1661 | if (pdi->has_children == 0) |
1662 | return; | |
38d518c9 | 1663 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1664 | STRUCT_DOMAIN, LOC_TYPEDEF, |
e142c38c | 1665 | cu->language == language_cplus |
63d06c5c DC |
1666 | ? &objfile->global_psymbols |
1667 | : &objfile->static_psymbols, | |
e142c38c | 1668 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 1669 | |
e142c38c | 1670 | if (cu->language == language_cplus) |
c906108c SS |
1671 | { |
1672 | /* For C++, these implicitly act as typedefs as well. */ | |
38d518c9 | 1673 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1674 | VAR_DOMAIN, LOC_TYPEDEF, |
63d06c5c | 1675 | &objfile->global_psymbols, |
e142c38c | 1676 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
1677 | } |
1678 | break; | |
1679 | case DW_TAG_enumerator: | |
38d518c9 | 1680 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1681 | VAR_DOMAIN, LOC_CONST, |
e142c38c | 1682 | cu->language == language_cplus |
f6fe98ef DJ |
1683 | ? &objfile->global_psymbols |
1684 | : &objfile->static_psymbols, | |
e142c38c | 1685 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
1686 | break; |
1687 | default: | |
1688 | break; | |
1689 | } | |
5c4e30ca DC |
1690 | |
1691 | /* Check to see if we should scan the name for possible namespace | |
1692 | info. Only do this if this is C++, if we don't have namespace | |
1693 | debugging info in the file, if the psym is of an appropriate type | |
1694 | (otherwise we'll have psym == NULL), and if we actually had a | |
1695 | mangled name to begin with. */ | |
1696 | ||
72bf9492 DJ |
1697 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
1698 | cases which do not set PSYM above? */ | |
1699 | ||
e142c38c | 1700 | if (cu->language == language_cplus |
72bf9492 | 1701 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
1702 | && psym != NULL |
1703 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
1704 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
1705 | objfile); | |
72bf9492 DJ |
1706 | |
1707 | if (built_actual_name) | |
1708 | xfree (actual_name); | |
c906108c SS |
1709 | } |
1710 | ||
72bf9492 DJ |
1711 | /* Determine whether a die of type TAG living in a C++ class or |
1712 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
1713 | name listed in the die. */ |
1714 | ||
1715 | static int | |
72bf9492 | 1716 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 1717 | { |
63d06c5c DC |
1718 | switch (tag) |
1719 | { | |
72bf9492 | 1720 | case DW_TAG_namespace: |
63d06c5c DC |
1721 | case DW_TAG_typedef: |
1722 | case DW_TAG_class_type: | |
1723 | case DW_TAG_structure_type: | |
1724 | case DW_TAG_union_type: | |
1725 | case DW_TAG_enumeration_type: | |
1726 | case DW_TAG_enumerator: | |
1727 | return 1; | |
1728 | default: | |
1729 | return 0; | |
1730 | } | |
1731 | } | |
1732 | ||
5c4e30ca DC |
1733 | /* Read a partial die corresponding to a namespace; also, add a symbol |
1734 | corresponding to that namespace to the symbol table. NAMESPACE is | |
1735 | the name of the enclosing namespace. */ | |
91c24f0a | 1736 | |
72bf9492 DJ |
1737 | static void |
1738 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 1739 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 1740 | struct dwarf2_cu *cu) |
91c24f0a | 1741 | { |
e7c27a73 | 1742 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 1743 | |
72bf9492 | 1744 | /* Add a symbol for the namespace. */ |
e7c27a73 | 1745 | |
72bf9492 | 1746 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
1747 | |
1748 | /* Now scan partial symbols in that namespace. */ | |
1749 | ||
91c24f0a | 1750 | if (pdi->has_children) |
72bf9492 | 1751 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
1752 | } |
1753 | ||
72bf9492 DJ |
1754 | /* See if we can figure out if the class lives in a namespace. We do |
1755 | this by looking for a member function; its demangled name will | |
1756 | contain namespace info, if there is any. */ | |
63d06c5c | 1757 | |
72bf9492 DJ |
1758 | static void |
1759 | guess_structure_name (struct partial_die_info *struct_pdi, | |
1760 | struct dwarf2_cu *cu) | |
63d06c5c | 1761 | { |
e142c38c | 1762 | if (cu->language == language_cplus |
72bf9492 | 1763 | && cu->has_namespace_info == 0 |
63d06c5c DC |
1764 | && struct_pdi->has_children) |
1765 | { | |
63d06c5c DC |
1766 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
1767 | what template types look like, because the demangler | |
1768 | frequently doesn't give the same name as the debug info. We | |
1769 | could fix this by only using the demangled name to get the | |
134d01f1 | 1770 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 1771 | |
72bf9492 DJ |
1772 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
1773 | struct partial_die_info *real_pdi; | |
1774 | struct dwarf2_cu *spec_cu; | |
5d51ca54 | 1775 | |
72bf9492 DJ |
1776 | /* If this DIE (this DIE's specification, if any) has a parent, then |
1777 | we should not do this. We'll prepend the parent's fully qualified | |
1778 | name when we create the partial symbol. */ | |
5d51ca54 | 1779 | |
72bf9492 DJ |
1780 | real_pdi = struct_pdi; |
1781 | spec_cu = cu; | |
1782 | while (real_pdi->has_specification) | |
1783 | real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu); | |
63d06c5c | 1784 | |
72bf9492 DJ |
1785 | if (real_pdi->die_parent != NULL) |
1786 | return; | |
63d06c5c | 1787 | |
72bf9492 DJ |
1788 | while (child_pdi != NULL) |
1789 | { | |
1790 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 1791 | { |
72bf9492 DJ |
1792 | char *actual_class_name |
1793 | = class_name_from_physname (child_pdi->name); | |
63d06c5c | 1794 | if (actual_class_name != NULL) |
72bf9492 DJ |
1795 | { |
1796 | struct_pdi->name | |
1797 | = obsavestring (actual_class_name, | |
1798 | strlen (actual_class_name), | |
1799 | &cu->comp_unit_obstack); | |
1800 | xfree (actual_class_name); | |
1801 | } | |
63d06c5c DC |
1802 | break; |
1803 | } | |
72bf9492 DJ |
1804 | |
1805 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
1806 | } |
1807 | } | |
63d06c5c DC |
1808 | } |
1809 | ||
91c24f0a DC |
1810 | /* Read a partial die corresponding to an enumeration type. */ |
1811 | ||
72bf9492 DJ |
1812 | static void |
1813 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
1814 | struct dwarf2_cu *cu) | |
91c24f0a | 1815 | { |
e7c27a73 | 1816 | struct objfile *objfile = cu->objfile; |
91c24f0a | 1817 | bfd *abfd = objfile->obfd; |
72bf9492 | 1818 | struct partial_die_info *pdi; |
91c24f0a DC |
1819 | |
1820 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
1821 | add_partial_symbol (enum_pdi, cu); |
1822 | ||
1823 | pdi = enum_pdi->die_child; | |
1824 | while (pdi) | |
91c24f0a | 1825 | { |
72bf9492 | 1826 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
91c24f0a DC |
1827 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); |
1828 | else | |
72bf9492 DJ |
1829 | add_partial_symbol (pdi, cu); |
1830 | pdi = pdi->die_sibling; | |
91c24f0a | 1831 | } |
91c24f0a DC |
1832 | } |
1833 | ||
4bb7a0a7 DJ |
1834 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
1835 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
1836 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
1837 | the initial number. */ | |
1838 | ||
1839 | static struct abbrev_info * | |
1840 | peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu) | |
1841 | { | |
1842 | bfd *abfd = cu->objfile->obfd; | |
1843 | unsigned int abbrev_number; | |
1844 | struct abbrev_info *abbrev; | |
1845 | ||
1846 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
1847 | ||
1848 | if (abbrev_number == 0) | |
1849 | return NULL; | |
1850 | ||
1851 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
1852 | if (!abbrev) | |
1853 | { | |
1854 | error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number, | |
1855 | bfd_get_filename (abfd)); | |
1856 | } | |
1857 | ||
1858 | return abbrev; | |
1859 | } | |
1860 | ||
1861 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
1862 | pointer to the end of a series of DIEs, terminated by an empty | |
1863 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
1864 | ||
1865 | static char * | |
1866 | skip_children (char *info_ptr, struct dwarf2_cu *cu) | |
1867 | { | |
1868 | struct abbrev_info *abbrev; | |
1869 | unsigned int bytes_read; | |
1870 | ||
1871 | while (1) | |
1872 | { | |
1873 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1874 | if (abbrev == NULL) | |
1875 | return info_ptr + bytes_read; | |
1876 | else | |
1877 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
1878 | } | |
1879 | } | |
1880 | ||
1881 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
1882 | should point just after the initial uleb128 of a DIE, and the | |
1883 | abbrev corresponding to that skipped uleb128 should be passed in | |
1884 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
1885 | children. */ | |
1886 | ||
1887 | static char * | |
1888 | skip_one_die (char *info_ptr, struct abbrev_info *abbrev, | |
1889 | struct dwarf2_cu *cu) | |
1890 | { | |
1891 | unsigned int bytes_read; | |
1892 | struct attribute attr; | |
1893 | bfd *abfd = cu->objfile->obfd; | |
1894 | unsigned int form, i; | |
1895 | ||
1896 | for (i = 0; i < abbrev->num_attrs; i++) | |
1897 | { | |
1898 | /* The only abbrev we care about is DW_AT_sibling. */ | |
1899 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
1900 | { | |
1901 | read_attribute (&attr, &abbrev->attrs[i], | |
1902 | abfd, info_ptr, cu); | |
1903 | if (attr.form == DW_FORM_ref_addr) | |
1904 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); | |
1905 | else | |
6502dd73 DJ |
1906 | return dwarf2_per_objfile->info_buffer |
1907 | + dwarf2_get_ref_die_offset (&attr, cu); | |
4bb7a0a7 DJ |
1908 | } |
1909 | ||
1910 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
1911 | form = abbrev->attrs[i].form; | |
1912 | skip_attribute: | |
1913 | switch (form) | |
1914 | { | |
1915 | case DW_FORM_addr: | |
1916 | case DW_FORM_ref_addr: | |
1917 | info_ptr += cu->header.addr_size; | |
1918 | break; | |
1919 | case DW_FORM_data1: | |
1920 | case DW_FORM_ref1: | |
1921 | case DW_FORM_flag: | |
1922 | info_ptr += 1; | |
1923 | break; | |
1924 | case DW_FORM_data2: | |
1925 | case DW_FORM_ref2: | |
1926 | info_ptr += 2; | |
1927 | break; | |
1928 | case DW_FORM_data4: | |
1929 | case DW_FORM_ref4: | |
1930 | info_ptr += 4; | |
1931 | break; | |
1932 | case DW_FORM_data8: | |
1933 | case DW_FORM_ref8: | |
1934 | info_ptr += 8; | |
1935 | break; | |
1936 | case DW_FORM_string: | |
1937 | read_string (abfd, info_ptr, &bytes_read); | |
1938 | info_ptr += bytes_read; | |
1939 | break; | |
1940 | case DW_FORM_strp: | |
1941 | info_ptr += cu->header.offset_size; | |
1942 | break; | |
1943 | case DW_FORM_block: | |
1944 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
1945 | info_ptr += bytes_read; | |
1946 | break; | |
1947 | case DW_FORM_block1: | |
1948 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
1949 | break; | |
1950 | case DW_FORM_block2: | |
1951 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
1952 | break; | |
1953 | case DW_FORM_block4: | |
1954 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
1955 | break; | |
1956 | case DW_FORM_sdata: | |
1957 | case DW_FORM_udata: | |
1958 | case DW_FORM_ref_udata: | |
1959 | info_ptr = skip_leb128 (abfd, info_ptr); | |
1960 | break; | |
1961 | case DW_FORM_indirect: | |
1962 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
1963 | info_ptr += bytes_read; | |
1964 | /* We need to continue parsing from here, so just go back to | |
1965 | the top. */ | |
1966 | goto skip_attribute; | |
1967 | ||
1968 | default: | |
1969 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", | |
1970 | dwarf_form_name (form), | |
1971 | bfd_get_filename (abfd)); | |
1972 | } | |
1973 | } | |
1974 | ||
1975 | if (abbrev->has_children) | |
1976 | return skip_children (info_ptr, cu); | |
1977 | else | |
1978 | return info_ptr; | |
1979 | } | |
1980 | ||
1981 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
1982 | the next DIE after ORIG_PDI. */ | |
91c24f0a DC |
1983 | |
1984 | static char * | |
1985 | locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr, | |
e7c27a73 | 1986 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
1987 | { |
1988 | /* Do we know the sibling already? */ | |
72bf9492 | 1989 | |
91c24f0a DC |
1990 | if (orig_pdi->sibling) |
1991 | return orig_pdi->sibling; | |
1992 | ||
1993 | /* Are there any children to deal with? */ | |
1994 | ||
1995 | if (!orig_pdi->has_children) | |
1996 | return info_ptr; | |
1997 | ||
4bb7a0a7 | 1998 | /* Skip the children the long way. */ |
91c24f0a | 1999 | |
4bb7a0a7 | 2000 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2001 | } |
2002 | ||
c906108c SS |
2003 | /* Expand this partial symbol table into a full symbol table. */ |
2004 | ||
2005 | static void | |
fba45db2 | 2006 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2007 | { |
2008 | /* FIXME: This is barely more than a stub. */ | |
2009 | if (pst != NULL) | |
2010 | { | |
2011 | if (pst->readin) | |
2012 | { | |
2013 | warning ("bug: psymtab for %s is already read in.", pst->filename); | |
2014 | } | |
2015 | else | |
2016 | { | |
2017 | if (info_verbose) | |
2018 | { | |
2019 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
2020 | gdb_flush (gdb_stdout); | |
2021 | } | |
2022 | ||
2023 | psymtab_to_symtab_1 (pst); | |
2024 | ||
2025 | /* Finish up the debug error message. */ | |
2026 | if (info_verbose) | |
2027 | printf_filtered ("done.\n"); | |
2028 | } | |
2029 | } | |
2030 | } | |
2031 | ||
2032 | static void | |
fba45db2 | 2033 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c SS |
2034 | { |
2035 | struct objfile *objfile = pst->objfile; | |
2036 | bfd *abfd = objfile->obfd; | |
e7c27a73 | 2037 | struct dwarf2_cu cu; |
c906108c SS |
2038 | struct die_info *dies; |
2039 | unsigned long offset; | |
2040 | CORE_ADDR lowpc, highpc; | |
2041 | struct die_info *child_die; | |
2042 | char *info_ptr; | |
2043 | struct symtab *symtab; | |
2044 | struct cleanup *back_to; | |
0d53c4c4 | 2045 | struct attribute *attr; |
e142c38c | 2046 | CORE_ADDR baseaddr; |
c906108c | 2047 | |
6502dd73 DJ |
2048 | dwarf2_per_objfile = objfile_data (pst->objfile, dwarf2_objfile_data_key); |
2049 | ||
c906108c | 2050 | /* Set local variables from the partial symbol table info. */ |
c5aa993b | 2051 | offset = DWARF_INFO_OFFSET (pst); |
6502dd73 DJ |
2052 | |
2053 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
e142c38c | 2054 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 2055 | |
63d06c5c DC |
2056 | /* We're in the global namespace. */ |
2057 | processing_current_prefix = ""; | |
2058 | ||
c906108c SS |
2059 | obstack_init (&dwarf2_tmp_obstack); |
2060 | back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); | |
2061 | ||
2062 | buildsym_init (); | |
a0b3c4fd | 2063 | make_cleanup (really_free_pendings, NULL); |
c906108c | 2064 | |
e7c27a73 DJ |
2065 | cu.objfile = objfile; |
2066 | ||
c906108c | 2067 | /* read in the comp_unit header */ |
e7c27a73 | 2068 | info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd); |
c906108c SS |
2069 | |
2070 | /* Read the abbrevs for this compilation unit */ | |
e7c27a73 | 2071 | dwarf2_read_abbrevs (abfd, &cu); |
f3dd6933 | 2072 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 2073 | |
e142c38c DJ |
2074 | cu.header.offset = offset; |
2075 | ||
2076 | cu.list_in_scope = &file_symbols; | |
2077 | ||
e7c27a73 | 2078 | dies = read_comp_unit (info_ptr, abfd, &cu); |
c906108c | 2079 | |
74b7792f | 2080 | make_cleanup_free_die_list (dies); |
c906108c | 2081 | |
0d53c4c4 DJ |
2082 | /* Find the base address of the compilation unit for range lists and |
2083 | location lists. It will normally be specified by DW_AT_low_pc. | |
2084 | In DWARF-3 draft 4, the base address could be overridden by | |
2085 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2086 | compilation units with discontinuous ranges. */ | |
2087 | ||
e7c27a73 DJ |
2088 | cu.header.base_known = 0; |
2089 | cu.header.base_address = 0; | |
0d53c4c4 | 2090 | |
e142c38c | 2091 | attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu); |
0d53c4c4 DJ |
2092 | if (attr) |
2093 | { | |
e7c27a73 DJ |
2094 | cu.header.base_address = DW_ADDR (attr); |
2095 | cu.header.base_known = 1; | |
0d53c4c4 DJ |
2096 | } |
2097 | else | |
2098 | { | |
e142c38c | 2099 | attr = dwarf2_attr (dies, DW_AT_low_pc, &cu); |
0d53c4c4 DJ |
2100 | if (attr) |
2101 | { | |
e7c27a73 DJ |
2102 | cu.header.base_address = DW_ADDR (attr); |
2103 | cu.header.base_known = 1; | |
0d53c4c4 DJ |
2104 | } |
2105 | } | |
2106 | ||
c906108c | 2107 | /* Do line number decoding in read_file_scope () */ |
e7c27a73 | 2108 | process_die (dies, &cu); |
c906108c | 2109 | |
fae299cd DC |
2110 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2111 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2112 | it, by scanning the DIE's below the compilation unit. */ | |
2113 | get_scope_pc_bounds (dies, &lowpc, &highpc, &cu); | |
c906108c | 2114 | |
613e1657 | 2115 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2116 | |
2117 | /* Set symtab language to language from DW_AT_language. | |
2118 | If the compilation is from a C file generated by language preprocessors, | |
2119 | do not set the language if it was already deduced by start_subfile. */ | |
2120 | if (symtab != NULL | |
e142c38c | 2121 | && !(cu.language == language_c && symtab->language != language_c)) |
c906108c | 2122 | { |
e142c38c | 2123 | symtab->language = cu.language; |
c906108c SS |
2124 | } |
2125 | pst->symtab = symtab; | |
2126 | pst->readin = 1; | |
c906108c SS |
2127 | |
2128 | do_cleanups (back_to); | |
2129 | } | |
2130 | ||
2131 | /* Process a die and its children. */ | |
2132 | ||
2133 | static void | |
e7c27a73 | 2134 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2135 | { |
2136 | switch (die->tag) | |
2137 | { | |
2138 | case DW_TAG_padding: | |
2139 | break; | |
2140 | case DW_TAG_compile_unit: | |
e7c27a73 | 2141 | read_file_scope (die, cu); |
c906108c SS |
2142 | break; |
2143 | case DW_TAG_subprogram: | |
e7c27a73 DJ |
2144 | read_subroutine_type (die, cu); |
2145 | read_func_scope (die, cu); | |
c906108c SS |
2146 | break; |
2147 | case DW_TAG_inlined_subroutine: | |
2148 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2149 | They could be used to set breakpoints on all inlined instances |
2150 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2151 | break; |
2152 | case DW_TAG_lexical_block: | |
14898363 L |
2153 | case DW_TAG_try_block: |
2154 | case DW_TAG_catch_block: | |
e7c27a73 | 2155 | read_lexical_block_scope (die, cu); |
c906108c SS |
2156 | break; |
2157 | case DW_TAG_class_type: | |
2158 | case DW_TAG_structure_type: | |
2159 | case DW_TAG_union_type: | |
134d01f1 DJ |
2160 | read_structure_type (die, cu); |
2161 | process_structure_scope (die, cu); | |
c906108c SS |
2162 | break; |
2163 | case DW_TAG_enumeration_type: | |
134d01f1 DJ |
2164 | read_enumeration_type (die, cu); |
2165 | process_enumeration_scope (die, cu); | |
c906108c | 2166 | break; |
134d01f1 DJ |
2167 | |
2168 | /* FIXME drow/2004-03-14: These initialize die->type, but do not create | |
2169 | a symbol or process any children. Therefore it doesn't do anything | |
2170 | that won't be done on-demand by read_type_die. */ | |
c906108c | 2171 | case DW_TAG_subroutine_type: |
e7c27a73 | 2172 | read_subroutine_type (die, cu); |
c906108c SS |
2173 | break; |
2174 | case DW_TAG_array_type: | |
e7c27a73 | 2175 | read_array_type (die, cu); |
c906108c SS |
2176 | break; |
2177 | case DW_TAG_pointer_type: | |
e7c27a73 | 2178 | read_tag_pointer_type (die, cu); |
c906108c SS |
2179 | break; |
2180 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 2181 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
2182 | break; |
2183 | case DW_TAG_reference_type: | |
e7c27a73 | 2184 | read_tag_reference_type (die, cu); |
c906108c SS |
2185 | break; |
2186 | case DW_TAG_string_type: | |
e7c27a73 | 2187 | read_tag_string_type (die, cu); |
c906108c | 2188 | break; |
134d01f1 DJ |
2189 | /* END FIXME */ |
2190 | ||
c906108c | 2191 | case DW_TAG_base_type: |
e7c27a73 | 2192 | read_base_type (die, cu); |
134d01f1 DJ |
2193 | /* Add a typedef symbol for the type definition, if it has a |
2194 | DW_AT_name. */ | |
2195 | new_symbol (die, die->type, cu); | |
c906108c | 2196 | break; |
a02abb62 JB |
2197 | case DW_TAG_subrange_type: |
2198 | read_subrange_type (die, cu); | |
134d01f1 DJ |
2199 | /* Add a typedef symbol for the type definition, if it has a |
2200 | DW_AT_name. */ | |
2201 | new_symbol (die, die->type, cu); | |
a02abb62 | 2202 | break; |
c906108c | 2203 | case DW_TAG_common_block: |
e7c27a73 | 2204 | read_common_block (die, cu); |
c906108c SS |
2205 | break; |
2206 | case DW_TAG_common_inclusion: | |
2207 | break; | |
d9fa45fe | 2208 | case DW_TAG_namespace: |
63d06c5c | 2209 | processing_has_namespace_info = 1; |
e7c27a73 | 2210 | read_namespace (die, cu); |
d9fa45fe DC |
2211 | break; |
2212 | case DW_TAG_imported_declaration: | |
2213 | case DW_TAG_imported_module: | |
2214 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2215 | information contained in these. DW_TAG_imported_declaration | |
2216 | dies shouldn't have children; DW_TAG_imported_module dies | |
2217 | shouldn't in the C++ case, but conceivably could in the | |
2218 | Fortran case, so we'll have to replace this gdb_assert if | |
2219 | Fortran compilers start generating that info. */ | |
63d06c5c | 2220 | processing_has_namespace_info = 1; |
639d11d3 | 2221 | gdb_assert (die->child == NULL); |
d9fa45fe | 2222 | break; |
c906108c | 2223 | default: |
e7c27a73 | 2224 | new_symbol (die, NULL, cu); |
c906108c SS |
2225 | break; |
2226 | } | |
2227 | } | |
2228 | ||
5fb290d7 | 2229 | static void |
e142c38c | 2230 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2231 | { |
e142c38c | 2232 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2233 | } |
2234 | ||
c906108c | 2235 | static void |
e7c27a73 | 2236 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2237 | { |
e7c27a73 DJ |
2238 | struct objfile *objfile = cu->objfile; |
2239 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2240 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2241 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2242 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2243 | struct attribute *attr; | |
2244 | char *name = "<unknown>"; | |
2245 | char *comp_dir = NULL; | |
2246 | struct die_info *child_die; | |
2247 | bfd *abfd = objfile->obfd; | |
debd256d | 2248 | struct line_header *line_header = 0; |
e142c38c DJ |
2249 | CORE_ADDR baseaddr; |
2250 | ||
2251 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2252 | |
fae299cd | 2253 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2254 | |
2255 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2256 | from finish_block. */ | |
2acceee2 | 2257 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2258 | lowpc = highpc; |
2259 | lowpc += baseaddr; | |
2260 | highpc += baseaddr; | |
2261 | ||
e142c38c | 2262 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2263 | if (attr) |
2264 | { | |
2265 | name = DW_STRING (attr); | |
2266 | } | |
e142c38c | 2267 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c SS |
2268 | if (attr) |
2269 | { | |
2270 | comp_dir = DW_STRING (attr); | |
2271 | if (comp_dir) | |
2272 | { | |
2273 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2274 | directory, get rid of it. */ | |
2275 | char *cp = strchr (comp_dir, ':'); | |
2276 | ||
2277 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') | |
2278 | comp_dir = cp + 1; | |
2279 | } | |
2280 | } | |
2281 | ||
2282 | if (objfile->ei.entry_point >= lowpc && | |
2283 | objfile->ei.entry_point < highpc) | |
2284 | { | |
627b3ba2 AC |
2285 | objfile->ei.deprecated_entry_file_lowpc = lowpc; |
2286 | objfile->ei.deprecated_entry_file_highpc = highpc; | |
c906108c SS |
2287 | } |
2288 | ||
e142c38c | 2289 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2290 | if (attr) |
2291 | { | |
e142c38c | 2292 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2293 | } |
2294 | ||
2295 | /* We assume that we're processing GCC output. */ | |
2296 | processing_gcc_compilation = 2; | |
2297 | #if 0 | |
c5aa993b JM |
2298 | /* FIXME:Do something here. */ |
2299 | if (dip->at_producer != NULL) | |
c906108c SS |
2300 | { |
2301 | handle_producer (dip->at_producer); | |
2302 | } | |
2303 | #endif | |
2304 | ||
2305 | /* The compilation unit may be in a different language or objfile, | |
2306 | zero out all remembered fundamental types. */ | |
e142c38c | 2307 | memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); |
c906108c SS |
2308 | |
2309 | start_symtab (name, comp_dir, lowpc); | |
2310 | record_debugformat ("DWARF 2"); | |
2311 | ||
e142c38c | 2312 | initialize_cu_func_list (cu); |
c906108c SS |
2313 | |
2314 | /* Process all dies in compilation unit. */ | |
639d11d3 | 2315 | if (die->child != NULL) |
c906108c | 2316 | { |
639d11d3 | 2317 | child_die = die->child; |
c906108c SS |
2318 | while (child_die && child_die->tag) |
2319 | { | |
e7c27a73 | 2320 | process_die (child_die, cu); |
c906108c SS |
2321 | child_die = sibling_die (child_die); |
2322 | } | |
2323 | } | |
5fb290d7 DJ |
2324 | |
2325 | /* Decode line number information if present. */ | |
e142c38c | 2326 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2327 | if (attr) |
2328 | { | |
debd256d | 2329 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2330 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2331 | if (line_header) |
2332 | { | |
2333 | make_cleanup ((make_cleanup_ftype *) free_line_header, | |
2334 | (void *) line_header); | |
e7c27a73 | 2335 | dwarf_decode_lines (line_header, comp_dir, abfd, cu); |
debd256d | 2336 | } |
5fb290d7 | 2337 | } |
debd256d | 2338 | |
2e276125 JB |
2339 | /* Decode macro information, if present. Dwarf 2 macro information |
2340 | refers to information in the line number info statement program | |
2341 | header, so we can only read it if we've read the header | |
2342 | successfully. */ | |
e142c38c | 2343 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2344 | if (attr && line_header) |
2e276125 JB |
2345 | { |
2346 | unsigned int macro_offset = DW_UNSND (attr); | |
2347 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2348 | comp_dir, abfd, cu); |
2e276125 | 2349 | } |
debd256d | 2350 | do_cleanups (back_to); |
5fb290d7 DJ |
2351 | } |
2352 | ||
2353 | static void | |
e142c38c DJ |
2354 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2355 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2356 | { |
2357 | struct function_range *thisfn; | |
2358 | ||
2359 | thisfn = (struct function_range *) | |
2360 | obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range)); | |
2361 | thisfn->name = name; | |
2362 | thisfn->lowpc = lowpc; | |
2363 | thisfn->highpc = highpc; | |
2364 | thisfn->seen_line = 0; | |
2365 | thisfn->next = NULL; | |
2366 | ||
e142c38c DJ |
2367 | if (cu->last_fn == NULL) |
2368 | cu->first_fn = thisfn; | |
5fb290d7 | 2369 | else |
e142c38c | 2370 | cu->last_fn->next = thisfn; |
5fb290d7 | 2371 | |
e142c38c | 2372 | cu->last_fn = thisfn; |
c906108c SS |
2373 | } |
2374 | ||
2375 | static void | |
e7c27a73 | 2376 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2377 | { |
e7c27a73 | 2378 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2379 | struct context_stack *new; |
c906108c SS |
2380 | CORE_ADDR lowpc; |
2381 | CORE_ADDR highpc; | |
2382 | struct die_info *child_die; | |
2383 | struct attribute *attr; | |
2384 | char *name; | |
fdde2d81 DC |
2385 | const char *previous_prefix = processing_current_prefix; |
2386 | struct cleanup *back_to = NULL; | |
e142c38c | 2387 | CORE_ADDR baseaddr; |
c906108c | 2388 | |
e142c38c DJ |
2389 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2390 | ||
2391 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2392 | |
2393 | /* Ignore functions with missing or empty names and functions with | |
2394 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2395 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2396 | return; |
2397 | ||
086ed43d | 2398 | if (cu->language == language_cplus) |
fdde2d81 | 2399 | { |
086ed43d | 2400 | struct die_info *spec_die = die_specification (die, cu); |
fdde2d81 | 2401 | |
2a35147e JB |
2402 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2403 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2404 | given the code | |
2405 | ||
2406 | namespace N { | |
2407 | void foo() { | |
2408 | // Definition of N::foo. | |
2409 | } | |
2410 | } | |
2411 | ||
2412 | then we'll have a tree of DIEs like this: | |
2413 | ||
2414 | 1: DW_TAG_compile_unit | |
2415 | 2: DW_TAG_namespace // N | |
2416 | 3: DW_TAG_subprogram // declaration of N::foo | |
2417 | 4: DW_TAG_subprogram // definition of N::foo | |
2418 | DW_AT_specification // refers to die #3 | |
2419 | ||
2420 | Thus, when processing die #4, we have to pretend that we're | |
2421 | in the context of its DW_AT_specification, namely the contex | |
2422 | of die #3. */ | |
fdde2d81 DC |
2423 | |
2424 | if (spec_die != NULL) | |
2425 | { | |
e142c38c | 2426 | char *specification_prefix = determine_prefix (spec_die, cu); |
fdde2d81 DC |
2427 | processing_current_prefix = specification_prefix; |
2428 | back_to = make_cleanup (xfree, specification_prefix); | |
2429 | } | |
2430 | } | |
2431 | ||
c906108c SS |
2432 | lowpc += baseaddr; |
2433 | highpc += baseaddr; | |
2434 | ||
5fb290d7 | 2435 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 2436 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 2437 | |
c906108c SS |
2438 | if (objfile->ei.entry_point >= lowpc && |
2439 | objfile->ei.entry_point < highpc) | |
2440 | { | |
2441 | objfile->ei.entry_func_lowpc = lowpc; | |
2442 | objfile->ei.entry_func_highpc = highpc; | |
2443 | } | |
2444 | ||
c906108c | 2445 | new = push_context (0, lowpc); |
e7c27a73 | 2446 | new->name = new_symbol (die, die->type, cu); |
4c2df51b | 2447 | |
4cecd739 DJ |
2448 | /* If there is a location expression for DW_AT_frame_base, record |
2449 | it. */ | |
e142c38c | 2450 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 2451 | if (attr) |
c034e007 AC |
2452 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
2453 | expression is being recorded directly in the function's symbol | |
2454 | and not in a separate frame-base object. I guess this hack is | |
2455 | to avoid adding some sort of frame-base adjunct/annex to the | |
2456 | function's symbol :-(. The problem with doing this is that it | |
2457 | results in a function symbol with a location expression that | |
2458 | has nothing to do with the location of the function, ouch! The | |
2459 | relationship should be: a function's symbol has-a frame base; a | |
2460 | frame-base has-a location expression. */ | |
e7c27a73 | 2461 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 2462 | |
e142c38c | 2463 | cu->list_in_scope = &local_symbols; |
c906108c | 2464 | |
639d11d3 | 2465 | if (die->child != NULL) |
c906108c | 2466 | { |
639d11d3 | 2467 | child_die = die->child; |
c906108c SS |
2468 | while (child_die && child_die->tag) |
2469 | { | |
e7c27a73 | 2470 | process_die (child_die, cu); |
c906108c SS |
2471 | child_die = sibling_die (child_die); |
2472 | } | |
2473 | } | |
2474 | ||
2475 | new = pop_context (); | |
2476 | /* Make a block for the local symbols within. */ | |
2477 | finish_block (new->name, &local_symbols, new->old_blocks, | |
2478 | lowpc, highpc, objfile); | |
208d8187 JB |
2479 | |
2480 | /* In C++, we can have functions nested inside functions (e.g., when | |
2481 | a function declares a class that has methods). This means that | |
2482 | when we finish processing a function scope, we may need to go | |
2483 | back to building a containing block's symbol lists. */ | |
2484 | local_symbols = new->locals; | |
2485 | param_symbols = new->params; | |
2486 | ||
921e78cf JB |
2487 | /* If we've finished processing a top-level function, subsequent |
2488 | symbols go in the file symbol list. */ | |
2489 | if (outermost_context_p ()) | |
e142c38c | 2490 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
2491 | |
2492 | processing_current_prefix = previous_prefix; | |
2493 | if (back_to != NULL) | |
2494 | do_cleanups (back_to); | |
c906108c SS |
2495 | } |
2496 | ||
2497 | /* Process all the DIES contained within a lexical block scope. Start | |
2498 | a new scope, process the dies, and then close the scope. */ | |
2499 | ||
2500 | static void | |
e7c27a73 | 2501 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2502 | { |
e7c27a73 | 2503 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2504 | struct context_stack *new; |
c906108c SS |
2505 | CORE_ADDR lowpc, highpc; |
2506 | struct die_info *child_die; | |
e142c38c DJ |
2507 | CORE_ADDR baseaddr; |
2508 | ||
2509 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
2510 | |
2511 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
2512 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
2513 | as multiple lexical blocks? Handling children in a sane way would | |
2514 | be nasty. Might be easier to properly extend generic blocks to | |
2515 | describe ranges. */ | |
e7c27a73 | 2516 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2517 | return; |
2518 | lowpc += baseaddr; | |
2519 | highpc += baseaddr; | |
2520 | ||
2521 | push_context (0, lowpc); | |
639d11d3 | 2522 | if (die->child != NULL) |
c906108c | 2523 | { |
639d11d3 | 2524 | child_die = die->child; |
c906108c SS |
2525 | while (child_die && child_die->tag) |
2526 | { | |
e7c27a73 | 2527 | process_die (child_die, cu); |
c906108c SS |
2528 | child_die = sibling_die (child_die); |
2529 | } | |
2530 | } | |
2531 | new = pop_context (); | |
2532 | ||
2533 | if (local_symbols != NULL) | |
2534 | { | |
2535 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
2536 | highpc, objfile); | |
2537 | } | |
2538 | local_symbols = new->locals; | |
2539 | } | |
2540 | ||
af34e669 DJ |
2541 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
2542 | are present and valid, otherwise, return 0. Return -1 if the range is | |
2543 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 2544 | static int |
af34e669 | 2545 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 2546 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c | 2547 | { |
e7c27a73 DJ |
2548 | struct objfile *objfile = cu->objfile; |
2549 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 2550 | struct attribute *attr; |
af34e669 DJ |
2551 | bfd *obfd = objfile->obfd; |
2552 | CORE_ADDR low = 0; | |
2553 | CORE_ADDR high = 0; | |
2554 | int ret = 0; | |
c906108c | 2555 | |
e142c38c | 2556 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 2557 | if (attr) |
af34e669 DJ |
2558 | { |
2559 | high = DW_ADDR (attr); | |
e142c38c | 2560 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
2561 | if (attr) |
2562 | low = DW_ADDR (attr); | |
2563 | else | |
2564 | /* Found high w/o low attribute. */ | |
2565 | return 0; | |
2566 | ||
2567 | /* Found consecutive range of addresses. */ | |
2568 | ret = 1; | |
2569 | } | |
c906108c | 2570 | else |
af34e669 | 2571 | { |
e142c38c | 2572 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
2573 | if (attr != NULL) |
2574 | { | |
2575 | unsigned int addr_size = cu_header->addr_size; | |
2576 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
2577 | /* Value of the DW_AT_ranges attribute is the offset in the | |
a604369a | 2578 | .debug_ranges section. */ |
af34e669 DJ |
2579 | unsigned int offset = DW_UNSND (attr); |
2580 | /* Base address selection entry. */ | |
0d53c4c4 DJ |
2581 | CORE_ADDR base; |
2582 | int found_base; | |
af34e669 | 2583 | int dummy; |
af34e669 DJ |
2584 | char *buffer; |
2585 | CORE_ADDR marker; | |
2586 | int low_set; | |
2587 | ||
0d53c4c4 DJ |
2588 | found_base = cu_header->base_known; |
2589 | base = cu_header->base_address; | |
a604369a | 2590 | |
6502dd73 | 2591 | if (offset >= dwarf2_per_objfile->ranges_size) |
a604369a KB |
2592 | { |
2593 | complaint (&symfile_complaints, | |
2594 | "Offset %d out of bounds for DW_AT_ranges attribute", | |
2595 | offset); | |
2596 | return 0; | |
2597 | } | |
6502dd73 | 2598 | buffer = dwarf2_per_objfile->ranges_buffer + offset; |
af34e669 | 2599 | |
af34e669 | 2600 | /* Read in the largest possible address. */ |
e7c27a73 | 2601 | marker = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
2602 | if ((marker & mask) == mask) |
2603 | { | |
2604 | /* If we found the largest possible address, then | |
2605 | read the base address. */ | |
e7c27a73 | 2606 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
2607 | buffer += 2 * addr_size; |
2608 | offset += 2 * addr_size; | |
2609 | found_base = 1; | |
2610 | } | |
2611 | ||
2612 | low_set = 0; | |
2613 | ||
2614 | while (1) | |
2615 | { | |
2616 | CORE_ADDR range_beginning, range_end; | |
2617 | ||
e7c27a73 | 2618 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
af34e669 | 2619 | buffer += addr_size; |
e7c27a73 | 2620 | range_end = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
2621 | buffer += addr_size; |
2622 | offset += 2 * addr_size; | |
2623 | ||
2624 | /* An end of list marker is a pair of zero addresses. */ | |
2625 | if (range_beginning == 0 && range_end == 0) | |
2626 | /* Found the end of list entry. */ | |
2627 | break; | |
2628 | ||
2629 | /* Each base address selection entry is a pair of 2 values. | |
2630 | The first is the largest possible address, the second is | |
2631 | the base address. Check for a base address here. */ | |
2632 | if ((range_beginning & mask) == mask) | |
2633 | { | |
2634 | /* If we found the largest possible address, then | |
2635 | read the base address. */ | |
e7c27a73 | 2636 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
2637 | found_base = 1; |
2638 | continue; | |
2639 | } | |
2640 | ||
2641 | if (!found_base) | |
2642 | { | |
2643 | /* We have no valid base address for the ranges | |
2644 | data. */ | |
2645 | complaint (&symfile_complaints, | |
2646 | "Invalid .debug_ranges data (no base address)"); | |
2647 | return 0; | |
2648 | } | |
2649 | ||
8f05cde5 DJ |
2650 | range_beginning += base; |
2651 | range_end += base; | |
2652 | ||
af34e669 DJ |
2653 | /* FIXME: This is recording everything as a low-high |
2654 | segment of consecutive addresses. We should have a | |
2655 | data structure for discontiguous block ranges | |
2656 | instead. */ | |
2657 | if (! low_set) | |
2658 | { | |
2659 | low = range_beginning; | |
2660 | high = range_end; | |
2661 | low_set = 1; | |
2662 | } | |
2663 | else | |
2664 | { | |
2665 | if (range_beginning < low) | |
2666 | low = range_beginning; | |
2667 | if (range_end > high) | |
2668 | high = range_end; | |
2669 | } | |
2670 | } | |
2671 | ||
2672 | if (! low_set) | |
2673 | /* If the first entry is an end-of-list marker, the range | |
2674 | describes an empty scope, i.e. no instructions. */ | |
2675 | return 0; | |
2676 | ||
2677 | ret = -1; | |
2678 | } | |
2679 | } | |
c906108c SS |
2680 | |
2681 | if (high < low) | |
2682 | return 0; | |
2683 | ||
2684 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
2685 | eliminate duplicate copies of functions and vtables and such. | |
2686 | The linker will arbitrarily choose one and discard the others. | |
2687 | The AT_*_pc values for such functions refer to local labels in | |
2688 | these sections. If the section from that file was discarded, the | |
2689 | labels are not in the output, so the relocs get a value of 0. | |
2690 | If this is a discarded function, mark the pc bounds as invalid, | |
2691 | so that GDB will ignore it. */ | |
af34e669 | 2692 | if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0) |
c906108c SS |
2693 | return 0; |
2694 | ||
2695 | *lowpc = low; | |
2696 | *highpc = high; | |
af34e669 | 2697 | return ret; |
c906108c SS |
2698 | } |
2699 | ||
fae299cd DC |
2700 | /* Get the low and high pc's represented by the scope DIE, and store |
2701 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
2702 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
2703 | ||
2704 | static void | |
2705 | get_scope_pc_bounds (struct die_info *die, | |
2706 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
2707 | struct dwarf2_cu *cu) | |
2708 | { | |
2709 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
2710 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
2711 | CORE_ADDR current_low, current_high; | |
2712 | ||
2713 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
2714 | { | |
2715 | best_low = current_low; | |
2716 | best_high = current_high; | |
2717 | } | |
2718 | else | |
2719 | { | |
2720 | struct die_info *child = die->child; | |
2721 | ||
2722 | while (child && child->tag) | |
2723 | { | |
2724 | switch (child->tag) { | |
2725 | case DW_TAG_subprogram: | |
2726 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
2727 | { | |
2728 | best_low = min (best_low, current_low); | |
2729 | best_high = max (best_high, current_high); | |
2730 | } | |
2731 | break; | |
2732 | case DW_TAG_namespace: | |
2733 | /* FIXME: carlton/2004-01-16: Should we do this for | |
2734 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
2735 | that current GCC's always emit the DIEs corresponding | |
2736 | to definitions of methods of classes as children of a | |
2737 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
2738 | the DIEs giving the declarations, which could be | |
2739 | anywhere). But I don't see any reason why the | |
2740 | standards says that they have to be there. */ | |
2741 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
2742 | ||
2743 | if (current_low != ((CORE_ADDR) -1)) | |
2744 | { | |
2745 | best_low = min (best_low, current_low); | |
2746 | best_high = max (best_high, current_high); | |
2747 | } | |
2748 | break; | |
2749 | default: | |
2750 | /* Ignore. */ | |
2751 | break; | |
2752 | } | |
2753 | ||
2754 | child = sibling_die (child); | |
2755 | } | |
2756 | } | |
2757 | ||
2758 | *lowpc = best_low; | |
2759 | *highpc = best_high; | |
2760 | } | |
2761 | ||
c906108c SS |
2762 | /* Add an aggregate field to the field list. */ |
2763 | ||
2764 | static void | |
107d2387 | 2765 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
2766 | struct dwarf2_cu *cu) |
2767 | { | |
2768 | struct objfile *objfile = cu->objfile; | |
c906108c SS |
2769 | struct nextfield *new_field; |
2770 | struct attribute *attr; | |
2771 | struct field *fp; | |
2772 | char *fieldname = ""; | |
2773 | ||
2774 | /* Allocate a new field list entry and link it in. */ | |
2775 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 2776 | make_cleanup (xfree, new_field); |
c906108c SS |
2777 | memset (new_field, 0, sizeof (struct nextfield)); |
2778 | new_field->next = fip->fields; | |
2779 | fip->fields = new_field; | |
2780 | fip->nfields++; | |
2781 | ||
2782 | /* Handle accessibility and virtuality of field. | |
2783 | The default accessibility for members is public, the default | |
2784 | accessibility for inheritance is private. */ | |
2785 | if (die->tag != DW_TAG_inheritance) | |
2786 | new_field->accessibility = DW_ACCESS_public; | |
2787 | else | |
2788 | new_field->accessibility = DW_ACCESS_private; | |
2789 | new_field->virtuality = DW_VIRTUALITY_none; | |
2790 | ||
e142c38c | 2791 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
2792 | if (attr) |
2793 | new_field->accessibility = DW_UNSND (attr); | |
2794 | if (new_field->accessibility != DW_ACCESS_public) | |
2795 | fip->non_public_fields = 1; | |
e142c38c | 2796 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
2797 | if (attr) |
2798 | new_field->virtuality = DW_UNSND (attr); | |
2799 | ||
2800 | fp = &new_field->field; | |
a9a9bd0f | 2801 | |
e142c38c | 2802 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 2803 | { |
a9a9bd0f DC |
2804 | /* Data member other than a C++ static data member. */ |
2805 | ||
c906108c | 2806 | /* Get type of field. */ |
e7c27a73 | 2807 | fp->type = die_type (die, cu); |
c906108c | 2808 | |
01ad7f36 DJ |
2809 | FIELD_STATIC_KIND (*fp) = 0; |
2810 | ||
c906108c | 2811 | /* Get bit size of field (zero if none). */ |
e142c38c | 2812 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
2813 | if (attr) |
2814 | { | |
2815 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
2816 | } | |
2817 | else | |
2818 | { | |
2819 | FIELD_BITSIZE (*fp) = 0; | |
2820 | } | |
2821 | ||
2822 | /* Get bit offset of field. */ | |
e142c38c | 2823 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
2824 | if (attr) |
2825 | { | |
2826 | FIELD_BITPOS (*fp) = | |
e7c27a73 | 2827 | decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte; |
c906108c SS |
2828 | } |
2829 | else | |
2830 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 2831 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
2832 | if (attr) |
2833 | { | |
2834 | if (BITS_BIG_ENDIAN) | |
2835 | { | |
2836 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
2837 | additional bit offset from the MSB of the containing |
2838 | anonymous object to the MSB of the field. We don't | |
2839 | have to do anything special since we don't need to | |
2840 | know the size of the anonymous object. */ | |
c906108c SS |
2841 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
2842 | } | |
2843 | else | |
2844 | { | |
2845 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
2846 | MSB of the anonymous object, subtract off the number of |
2847 | bits from the MSB of the field to the MSB of the | |
2848 | object, and then subtract off the number of bits of | |
2849 | the field itself. The result is the bit offset of | |
2850 | the LSB of the field. */ | |
c906108c SS |
2851 | int anonymous_size; |
2852 | int bit_offset = DW_UNSND (attr); | |
2853 | ||
e142c38c | 2854 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
2855 | if (attr) |
2856 | { | |
2857 | /* The size of the anonymous object containing | |
2858 | the bit field is explicit, so use the | |
2859 | indicated size (in bytes). */ | |
2860 | anonymous_size = DW_UNSND (attr); | |
2861 | } | |
2862 | else | |
2863 | { | |
2864 | /* The size of the anonymous object containing | |
2865 | the bit field must be inferred from the type | |
2866 | attribute of the data member containing the | |
2867 | bit field. */ | |
2868 | anonymous_size = TYPE_LENGTH (fp->type); | |
2869 | } | |
2870 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
2871 | - bit_offset - FIELD_BITSIZE (*fp); | |
2872 | } | |
2873 | } | |
2874 | ||
2875 | /* Get name of field. */ | |
e142c38c | 2876 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2877 | if (attr && DW_STRING (attr)) |
2878 | fieldname = DW_STRING (attr); | |
d8151005 DJ |
2879 | |
2880 | /* The name is already allocated along with this objfile, so we don't | |
2881 | need to duplicate it for the type. */ | |
2882 | fp->name = fieldname; | |
c906108c SS |
2883 | |
2884 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 2885 | pointer or virtual base class pointer) to private. */ |
e142c38c | 2886 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
2887 | { |
2888 | new_field->accessibility = DW_ACCESS_private; | |
2889 | fip->non_public_fields = 1; | |
2890 | } | |
2891 | } | |
a9a9bd0f | 2892 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 2893 | { |
a9a9bd0f DC |
2894 | /* C++ static member. */ |
2895 | ||
2896 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
2897 | is a declaration, but all versions of G++ as of this writing | |
2898 | (so through at least 3.2.1) incorrectly generate | |
2899 | DW_TAG_variable tags. */ | |
2900 | ||
c906108c | 2901 | char *physname; |
c906108c | 2902 | |
a9a9bd0f | 2903 | /* Get name of field. */ |
e142c38c | 2904 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
2905 | if (attr && DW_STRING (attr)) |
2906 | fieldname = DW_STRING (attr); | |
2907 | else | |
c906108c SS |
2908 | return; |
2909 | ||
2df3850c | 2910 | /* Get physical name. */ |
e142c38c | 2911 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 2912 | |
d8151005 DJ |
2913 | /* The name is already allocated along with this objfile, so we don't |
2914 | need to duplicate it for the type. */ | |
2915 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 2916 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 2917 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
2918 | } |
2919 | else if (die->tag == DW_TAG_inheritance) | |
2920 | { | |
2921 | /* C++ base class field. */ | |
e142c38c | 2922 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 2923 | if (attr) |
e7c27a73 | 2924 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 2925 | * bits_per_byte); |
c906108c | 2926 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 2927 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 2928 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
2929 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
2930 | fip->nbaseclasses++; | |
2931 | } | |
2932 | } | |
2933 | ||
2934 | /* Create the vector of fields, and attach it to the type. */ | |
2935 | ||
2936 | static void | |
fba45db2 | 2937 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 2938 | struct dwarf2_cu *cu) |
c906108c SS |
2939 | { |
2940 | int nfields = fip->nfields; | |
2941 | ||
2942 | /* Record the field count, allocate space for the array of fields, | |
2943 | and create blank accessibility bitfields if necessary. */ | |
2944 | TYPE_NFIELDS (type) = nfields; | |
2945 | TYPE_FIELDS (type) = (struct field *) | |
2946 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
2947 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
2948 | ||
2949 | if (fip->non_public_fields) | |
2950 | { | |
2951 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
2952 | ||
2953 | TYPE_FIELD_PRIVATE_BITS (type) = | |
2954 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
2955 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
2956 | ||
2957 | TYPE_FIELD_PROTECTED_BITS (type) = | |
2958 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
2959 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
2960 | ||
2961 | TYPE_FIELD_IGNORE_BITS (type) = | |
2962 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
2963 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
2964 | } | |
2965 | ||
2966 | /* If the type has baseclasses, allocate and clear a bit vector for | |
2967 | TYPE_FIELD_VIRTUAL_BITS. */ | |
2968 | if (fip->nbaseclasses) | |
2969 | { | |
2970 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
2971 | char *pointer; | |
2972 | ||
2973 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
2974 | pointer = (char *) TYPE_ALLOC (type, num_bytes); | |
2975 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; | |
2976 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); | |
2977 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
2978 | } | |
2979 | ||
2980 | /* Copy the saved-up fields into the field vector. Start from the head | |
2981 | of the list, adding to the tail of the field array, so that they end | |
2982 | up in the same order in the array in which they were added to the list. */ | |
2983 | while (nfields-- > 0) | |
2984 | { | |
2985 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
2986 | switch (fip->fields->accessibility) | |
2987 | { | |
c5aa993b JM |
2988 | case DW_ACCESS_private: |
2989 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
2990 | break; | |
c906108c | 2991 | |
c5aa993b JM |
2992 | case DW_ACCESS_protected: |
2993 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
2994 | break; | |
c906108c | 2995 | |
c5aa993b JM |
2996 | case DW_ACCESS_public: |
2997 | break; | |
c906108c | 2998 | |
c5aa993b JM |
2999 | default: |
3000 | /* Unknown accessibility. Complain and treat it as public. */ | |
3001 | { | |
4d3c2250 KB |
3002 | complaint (&symfile_complaints, "unsupported accessibility %d", |
3003 | fip->fields->accessibility); | |
c5aa993b JM |
3004 | } |
3005 | break; | |
c906108c SS |
3006 | } |
3007 | if (nfields < fip->nbaseclasses) | |
3008 | { | |
3009 | switch (fip->fields->virtuality) | |
3010 | { | |
c5aa993b JM |
3011 | case DW_VIRTUALITY_virtual: |
3012 | case DW_VIRTUALITY_pure_virtual: | |
3013 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3014 | break; | |
c906108c SS |
3015 | } |
3016 | } | |
3017 | fip->fields = fip->fields->next; | |
3018 | } | |
3019 | } | |
3020 | ||
c906108c SS |
3021 | /* Add a member function to the proper fieldlist. */ |
3022 | ||
3023 | static void | |
107d2387 | 3024 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3025 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3026 | { |
e7c27a73 | 3027 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3028 | struct attribute *attr; |
3029 | struct fnfieldlist *flp; | |
3030 | int i; | |
3031 | struct fn_field *fnp; | |
3032 | char *fieldname; | |
3033 | char *physname; | |
3034 | struct nextfnfield *new_fnfield; | |
3035 | ||
2df3850c | 3036 | /* Get name of member function. */ |
e142c38c | 3037 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
3038 | if (attr && DW_STRING (attr)) |
3039 | fieldname = DW_STRING (attr); | |
c906108c | 3040 | else |
2df3850c | 3041 | return; |
c906108c | 3042 | |
2df3850c | 3043 | /* Get the mangled name. */ |
e142c38c | 3044 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3045 | |
3046 | /* Look up member function name in fieldlist. */ | |
3047 | for (i = 0; i < fip->nfnfields; i++) | |
3048 | { | |
27bfe10e | 3049 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3050 | break; |
3051 | } | |
3052 | ||
3053 | /* Create new list element if necessary. */ | |
3054 | if (i < fip->nfnfields) | |
3055 | flp = &fip->fnfieldlists[i]; | |
3056 | else | |
3057 | { | |
3058 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3059 | { | |
3060 | fip->fnfieldlists = (struct fnfieldlist *) | |
3061 | xrealloc (fip->fnfieldlists, | |
3062 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3063 | * sizeof (struct fnfieldlist)); |
c906108c | 3064 | if (fip->nfnfields == 0) |
c13c43fd | 3065 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3066 | } |
3067 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3068 | flp->name = fieldname; | |
3069 | flp->length = 0; | |
3070 | flp->head = NULL; | |
3071 | fip->nfnfields++; | |
3072 | } | |
3073 | ||
3074 | /* Create a new member function field and chain it to the field list | |
3075 | entry. */ | |
3076 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3077 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3078 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3079 | new_fnfield->next = flp->head; | |
3080 | flp->head = new_fnfield; | |
3081 | flp->length++; | |
3082 | ||
3083 | /* Fill in the member function field info. */ | |
3084 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3085 | /* The name is already allocated along with this objfile, so we don't |
3086 | need to duplicate it for the type. */ | |
3087 | fnp->physname = physname ? physname : ""; | |
c906108c SS |
3088 | fnp->type = alloc_type (objfile); |
3089 | if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) | |
3090 | { | |
c906108c | 3091 | int nparams = TYPE_NFIELDS (die->type); |
c906108c | 3092 | |
e26fb1d7 DC |
3093 | /* TYPE is the domain of this method, and DIE->TYPE is the type |
3094 | of the method itself (TYPE_CODE_METHOD). */ | |
3095 | smash_to_method_type (fnp->type, type, | |
ad2f7632 DJ |
3096 | TYPE_TARGET_TYPE (die->type), |
3097 | TYPE_FIELDS (die->type), | |
3098 | TYPE_NFIELDS (die->type), | |
3099 | TYPE_VARARGS (die->type)); | |
c906108c SS |
3100 | |
3101 | /* Handle static member functions. | |
c5aa993b JM |
3102 | Dwarf2 has no clean way to discern C++ static and non-static |
3103 | member functions. G++ helps GDB by marking the first | |
3104 | parameter for non-static member functions (which is the | |
3105 | this pointer) as artificial. We obtain this information | |
3106 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
c906108c SS |
3107 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) |
3108 | fnp->voffset = VOFFSET_STATIC; | |
3109 | } | |
3110 | else | |
4d3c2250 KB |
3111 | complaint (&symfile_complaints, "member function type missing for '%s'", |
3112 | physname); | |
c906108c SS |
3113 | |
3114 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3115 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3116 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3117 | |
3118 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3119 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3120 | ||
3121 | /* Get accessibility. */ | |
e142c38c | 3122 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3123 | if (attr) |
3124 | { | |
3125 | switch (DW_UNSND (attr)) | |
3126 | { | |
c5aa993b JM |
3127 | case DW_ACCESS_private: |
3128 | fnp->is_private = 1; | |
3129 | break; | |
3130 | case DW_ACCESS_protected: | |
3131 | fnp->is_protected = 1; | |
3132 | break; | |
c906108c SS |
3133 | } |
3134 | } | |
3135 | ||
b02dede2 | 3136 | /* Check for artificial methods. */ |
e142c38c | 3137 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3138 | if (attr && DW_UNSND (attr) != 0) |
3139 | fnp->is_artificial = 1; | |
3140 | ||
c906108c | 3141 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3142 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3143 | if (attr) |
8e19ed76 PS |
3144 | { |
3145 | /* Support the .debug_loc offsets */ | |
3146 | if (attr_form_is_block (attr)) | |
3147 | { | |
e7c27a73 | 3148 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 PS |
3149 | } |
3150 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3151 | { | |
4d3c2250 | 3152 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3153 | } |
3154 | else | |
3155 | { | |
4d3c2250 KB |
3156 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3157 | fieldname); | |
8e19ed76 PS |
3158 | } |
3159 | } | |
c906108c SS |
3160 | } |
3161 | ||
3162 | /* Create the vector of member function fields, and attach it to the type. */ | |
3163 | ||
3164 | static void | |
fba45db2 | 3165 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3166 | struct dwarf2_cu *cu) |
c906108c SS |
3167 | { |
3168 | struct fnfieldlist *flp; | |
3169 | int total_length = 0; | |
3170 | int i; | |
3171 | ||
3172 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3173 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3174 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3175 | ||
3176 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3177 | { | |
3178 | struct nextfnfield *nfp = flp->head; | |
3179 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3180 | int k; | |
3181 | ||
3182 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3183 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3184 | fn_flp->fn_fields = (struct fn_field *) | |
3185 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3186 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3187 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3188 | |
3189 | total_length += flp->length; | |
3190 | } | |
3191 | ||
3192 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3193 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3194 | } | |
3195 | ||
3196 | /* Called when we find the DIE that starts a structure or union scope | |
3197 | (definition) to process all dies that define the members of the | |
3198 | structure or union. | |
3199 | ||
3200 | NOTE: we need to call struct_type regardless of whether or not the | |
3201 | DIE has an at_name attribute, since it might be an anonymous | |
3202 | structure or union. This gets the type entered into our set of | |
3203 | user defined types. | |
3204 | ||
3205 | However, if the structure is incomplete (an opaque struct/union) | |
3206 | then suppress creating a symbol table entry for it since gdb only | |
3207 | wants to find the one with the complete definition. Note that if | |
3208 | it is complete, we just call new_symbol, which does it's own | |
3209 | checking about whether the struct/union is anonymous or not (and | |
3210 | suppresses creating a symbol table entry itself). */ | |
3211 | ||
3212 | static void | |
134d01f1 | 3213 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3214 | { |
e7c27a73 | 3215 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3216 | struct type *type; |
3217 | struct attribute *attr; | |
63d06c5c DC |
3218 | const char *previous_prefix = processing_current_prefix; |
3219 | struct cleanup *back_to = NULL; | |
c906108c | 3220 | |
134d01f1 DJ |
3221 | if (die->type) |
3222 | return; | |
3223 | ||
c906108c SS |
3224 | type = alloc_type (objfile); |
3225 | ||
3226 | INIT_CPLUS_SPECIFIC (type); | |
e142c38c | 3227 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3228 | if (attr && DW_STRING (attr)) |
3229 | { | |
e142c38c | 3230 | if (cu->language == language_cplus) |
63d06c5c | 3231 | { |
8176b9b8 DC |
3232 | char *new_prefix = determine_class_name (die, cu); |
3233 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
3234 | strlen (new_prefix), | |
3235 | &objfile->objfile_obstack); | |
3236 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
3237 | processing_current_prefix = new_prefix; |
3238 | } | |
3239 | else | |
3240 | { | |
d8151005 DJ |
3241 | /* The name is already allocated along with this objfile, so |
3242 | we don't need to duplicate it for the type. */ | |
8176b9b8 | 3243 | TYPE_TAG_NAME (type) = DW_STRING (attr); |
63d06c5c | 3244 | } |
c906108c SS |
3245 | } |
3246 | ||
3247 | if (die->tag == DW_TAG_structure_type) | |
3248 | { | |
3249 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
3250 | } | |
3251 | else if (die->tag == DW_TAG_union_type) | |
3252 | { | |
3253 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
3254 | } | |
3255 | else | |
3256 | { | |
3257 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 3258 | in gdbtypes.h. */ |
c906108c SS |
3259 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
3260 | } | |
3261 | ||
e142c38c | 3262 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3263 | if (attr) |
3264 | { | |
3265 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3266 | } | |
3267 | else | |
3268 | { | |
3269 | TYPE_LENGTH (type) = 0; | |
3270 | } | |
3271 | ||
dc718098 JB |
3272 | if (die_is_declaration (die, cu)) |
3273 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
3274 | ||
c906108c SS |
3275 | /* We need to add the type field to the die immediately so we don't |
3276 | infinitely recurse when dealing with pointers to the structure | |
3277 | type within the structure itself. */ | |
3278 | die->type = type; | |
3279 | ||
e142c38c | 3280 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
3281 | { |
3282 | struct field_info fi; | |
3283 | struct die_info *child_die; | |
3284 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
3285 | ||
3286 | memset (&fi, 0, sizeof (struct field_info)); | |
3287 | ||
639d11d3 | 3288 | child_die = die->child; |
c906108c SS |
3289 | |
3290 | while (child_die && child_die->tag) | |
3291 | { | |
a9a9bd0f DC |
3292 | if (child_die->tag == DW_TAG_member |
3293 | || child_die->tag == DW_TAG_variable) | |
c906108c | 3294 | { |
a9a9bd0f DC |
3295 | /* NOTE: carlton/2002-11-05: A C++ static data member |
3296 | should be a DW_TAG_member that is a declaration, but | |
3297 | all versions of G++ as of this writing (so through at | |
3298 | least 3.2.1) incorrectly generate DW_TAG_variable | |
3299 | tags for them instead. */ | |
e7c27a73 | 3300 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3301 | } |
8713b1b1 | 3302 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
3303 | { |
3304 | /* C++ member function. */ | |
134d01f1 | 3305 | read_type_die (child_die, cu); |
e7c27a73 | 3306 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
3307 | } |
3308 | else if (child_die->tag == DW_TAG_inheritance) | |
3309 | { | |
3310 | /* C++ base class field. */ | |
e7c27a73 | 3311 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3312 | } |
c906108c SS |
3313 | child_die = sibling_die (child_die); |
3314 | } | |
3315 | ||
3316 | /* Attach fields and member functions to the type. */ | |
3317 | if (fi.nfields) | |
e7c27a73 | 3318 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
3319 | if (fi.nfnfields) |
3320 | { | |
e7c27a73 | 3321 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 3322 | |
c5aa993b | 3323 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
3324 | class itself) which contains the vtable pointer for the current |
3325 | class from the DW_AT_containing_type attribute. */ | |
3326 | ||
e142c38c | 3327 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 3328 | { |
e7c27a73 | 3329 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
3330 | |
3331 | TYPE_VPTR_BASETYPE (type) = t; | |
3332 | if (type == t) | |
3333 | { | |
c5aa993b JM |
3334 | static const char vptr_name[] = |
3335 | {'_', 'v', 'p', 't', 'r', '\0'}; | |
c906108c SS |
3336 | int i; |
3337 | ||
3338 | /* Our own class provides vtbl ptr. */ | |
3339 | for (i = TYPE_NFIELDS (t) - 1; | |
3340 | i >= TYPE_N_BASECLASSES (t); | |
3341 | --i) | |
3342 | { | |
3343 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
3344 | ||
27bfe10e JB |
3345 | if ((strncmp (fieldname, vptr_name, |
3346 | strlen (vptr_name) - 1) | |
3347 | == 0) | |
c906108c SS |
3348 | && is_cplus_marker (fieldname[strlen (vptr_name)])) |
3349 | { | |
3350 | TYPE_VPTR_FIELDNO (type) = i; | |
3351 | break; | |
3352 | } | |
3353 | } | |
3354 | ||
3355 | /* Complain if virtual function table field not found. */ | |
3356 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 KB |
3357 | complaint (&symfile_complaints, |
3358 | "virtual function table pointer not found when defining class '%s'", | |
3359 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : | |
3360 | ""); | |
c906108c SS |
3361 | } |
3362 | else | |
3363 | { | |
3364 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
3365 | } | |
3366 | } | |
3367 | } | |
3368 | ||
c906108c SS |
3369 | do_cleanups (back_to); |
3370 | } | |
63d06c5c DC |
3371 | |
3372 | processing_current_prefix = previous_prefix; | |
3373 | if (back_to != NULL) | |
3374 | do_cleanups (back_to); | |
c906108c SS |
3375 | } |
3376 | ||
134d01f1 DJ |
3377 | static void |
3378 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3379 | { | |
3380 | struct objfile *objfile = cu->objfile; | |
3381 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 3382 | struct die_info *child_die = die->child; |
c906108c | 3383 | |
134d01f1 DJ |
3384 | if (TYPE_TAG_NAME (die->type) != NULL) |
3385 | processing_current_prefix = TYPE_TAG_NAME (die->type); | |
c906108c | 3386 | |
90aeadfc DC |
3387 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
3388 | snapshots) has been known to create a die giving a declaration | |
3389 | for a class that has, as a child, a die giving a definition for a | |
3390 | nested class. So we have to process our children even if the | |
3391 | current die is a declaration. Normally, of course, a declaration | |
3392 | won't have any children at all. */ | |
134d01f1 | 3393 | |
90aeadfc DC |
3394 | while (child_die != NULL && child_die->tag) |
3395 | { | |
3396 | if (child_die->tag == DW_TAG_member | |
3397 | || child_die->tag == DW_TAG_variable | |
3398 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 3399 | { |
90aeadfc | 3400 | /* Do nothing. */ |
134d01f1 | 3401 | } |
90aeadfc DC |
3402 | else |
3403 | process_die (child_die, cu); | |
134d01f1 | 3404 | |
90aeadfc | 3405 | child_die = sibling_die (child_die); |
134d01f1 DJ |
3406 | } |
3407 | ||
90aeadfc DC |
3408 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
3409 | new_symbol (die, die->type, cu); | |
3410 | ||
134d01f1 DJ |
3411 | processing_current_prefix = previous_prefix; |
3412 | } | |
3413 | ||
3414 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
3415 | complete the type's fields yet, or create any symbols. */ | |
c906108c SS |
3416 | |
3417 | static void | |
134d01f1 | 3418 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3419 | { |
e7c27a73 | 3420 | struct objfile *objfile = cu->objfile; |
c906108c | 3421 | struct type *type; |
c906108c | 3422 | struct attribute *attr; |
134d01f1 DJ |
3423 | |
3424 | if (die->type) | |
3425 | return; | |
c906108c SS |
3426 | |
3427 | type = alloc_type (objfile); | |
3428 | ||
3429 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
e142c38c | 3430 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3431 | if (attr && DW_STRING (attr)) |
3432 | { | |
d8151005 | 3433 | char *name = DW_STRING (attr); |
63d06c5c DC |
3434 | |
3435 | if (processing_has_namespace_info) | |
3436 | { | |
b99607ea | 3437 | TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
3438 | processing_current_prefix, |
3439 | processing_current_prefix[0] == '\0' | |
3440 | ? "" : "::", | |
3441 | name); | |
3442 | } | |
3443 | else | |
3444 | { | |
d8151005 DJ |
3445 | /* The name is already allocated along with this objfile, so |
3446 | we don't need to duplicate it for the type. */ | |
3447 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 3448 | } |
c906108c SS |
3449 | } |
3450 | ||
e142c38c | 3451 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3452 | if (attr) |
3453 | { | |
3454 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3455 | } | |
3456 | else | |
3457 | { | |
3458 | TYPE_LENGTH (type) = 0; | |
3459 | } | |
3460 | ||
134d01f1 DJ |
3461 | die->type = type; |
3462 | } | |
3463 | ||
8176b9b8 DC |
3464 | /* Determine the name of the type represented by DIE, which should be |
3465 | a named C++ compound type. Return the name in question; the caller | |
3466 | is responsible for xfree()'ing it. */ | |
3467 | ||
3468 | static char * | |
3469 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
3470 | { | |
3471 | struct cleanup *back_to = NULL; | |
3472 | struct die_info *spec_die = die_specification (die, cu); | |
3473 | char *new_prefix = NULL; | |
3474 | ||
3475 | /* If this is the definition of a class that is declared by another | |
3476 | die, then processing_current_prefix may not be accurate; see | |
3477 | read_func_scope for a similar example. */ | |
3478 | if (spec_die != NULL) | |
3479 | { | |
3480 | char *specification_prefix = determine_prefix (spec_die, cu); | |
3481 | processing_current_prefix = specification_prefix; | |
3482 | back_to = make_cleanup (xfree, specification_prefix); | |
3483 | } | |
3484 | ||
3485 | /* If we don't have namespace debug info, guess the name by trying | |
3486 | to demangle the names of members, just like we did in | |
72bf9492 | 3487 | guess_structure_name. */ |
8176b9b8 DC |
3488 | if (!processing_has_namespace_info) |
3489 | { | |
3490 | struct die_info *child; | |
3491 | ||
3492 | for (child = die->child; | |
3493 | child != NULL && child->tag != 0; | |
3494 | child = sibling_die (child)) | |
3495 | { | |
3496 | if (child->tag == DW_TAG_subprogram) | |
3497 | { | |
3498 | new_prefix = class_name_from_physname (dwarf2_linkage_name | |
3499 | (child, cu)); | |
3500 | ||
3501 | if (new_prefix != NULL) | |
3502 | break; | |
3503 | } | |
3504 | } | |
3505 | } | |
3506 | ||
3507 | if (new_prefix == NULL) | |
3508 | { | |
3509 | const char *name = dwarf2_name (die, cu); | |
3510 | new_prefix = typename_concat (processing_current_prefix, | |
3511 | name ? name : "<<anonymous>>"); | |
3512 | } | |
3513 | ||
3514 | if (back_to != NULL) | |
3515 | do_cleanups (back_to); | |
3516 | ||
3517 | return new_prefix; | |
3518 | } | |
3519 | ||
134d01f1 DJ |
3520 | /* Given a pointer to a die which begins an enumeration, process all |
3521 | the dies that define the members of the enumeration, and create the | |
3522 | symbol for the enumeration type. | |
3523 | ||
3524 | NOTE: We reverse the order of the element list. */ | |
3525 | ||
3526 | static void | |
3527 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3528 | { | |
3529 | struct objfile *objfile = cu->objfile; | |
3530 | struct die_info *child_die; | |
3531 | struct field *fields; | |
3532 | struct attribute *attr; | |
3533 | struct symbol *sym; | |
3534 | int num_fields; | |
3535 | int unsigned_enum = 1; | |
3536 | ||
c906108c SS |
3537 | num_fields = 0; |
3538 | fields = NULL; | |
639d11d3 | 3539 | if (die->child != NULL) |
c906108c | 3540 | { |
639d11d3 | 3541 | child_die = die->child; |
c906108c SS |
3542 | while (child_die && child_die->tag) |
3543 | { | |
3544 | if (child_die->tag != DW_TAG_enumerator) | |
3545 | { | |
e7c27a73 | 3546 | process_die (child_die, cu); |
c906108c SS |
3547 | } |
3548 | else | |
3549 | { | |
e142c38c | 3550 | attr = dwarf2_attr (child_die, DW_AT_name, cu); |
c906108c SS |
3551 | if (attr) |
3552 | { | |
134d01f1 | 3553 | sym = new_symbol (child_die, die->type, cu); |
c906108c SS |
3554 | if (SYMBOL_VALUE (sym) < 0) |
3555 | unsigned_enum = 0; | |
3556 | ||
3557 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3558 | { | |
3559 | fields = (struct field *) | |
3560 | xrealloc (fields, | |
3561 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3562 | * sizeof (struct field)); |
c906108c SS |
3563 | } |
3564 | ||
22abf04a | 3565 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
3566 | FIELD_TYPE (fields[num_fields]) = NULL; |
3567 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
3568 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 3569 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
3570 | |
3571 | num_fields++; | |
3572 | } | |
3573 | } | |
3574 | ||
3575 | child_die = sibling_die (child_die); | |
3576 | } | |
3577 | ||
3578 | if (num_fields) | |
3579 | { | |
134d01f1 DJ |
3580 | TYPE_NFIELDS (die->type) = num_fields; |
3581 | TYPE_FIELDS (die->type) = (struct field *) | |
3582 | TYPE_ALLOC (die->type, sizeof (struct field) * num_fields); | |
3583 | memcpy (TYPE_FIELDS (die->type), fields, | |
c906108c | 3584 | sizeof (struct field) * num_fields); |
b8c9b27d | 3585 | xfree (fields); |
c906108c SS |
3586 | } |
3587 | if (unsigned_enum) | |
134d01f1 | 3588 | TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 3589 | } |
134d01f1 DJ |
3590 | |
3591 | new_symbol (die, die->type, cu); | |
c906108c SS |
3592 | } |
3593 | ||
3594 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
3595 | the DIE's type field. For now, this only handles one dimensional | |
3596 | arrays. */ | |
3597 | ||
3598 | static void | |
e7c27a73 | 3599 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3600 | { |
e7c27a73 | 3601 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3602 | struct die_info *child_die; |
3603 | struct type *type = NULL; | |
3604 | struct type *element_type, *range_type, *index_type; | |
3605 | struct type **range_types = NULL; | |
3606 | struct attribute *attr; | |
3607 | int ndim = 0; | |
3608 | struct cleanup *back_to; | |
3609 | ||
3610 | /* Return if we've already decoded this type. */ | |
3611 | if (die->type) | |
3612 | { | |
3613 | return; | |
3614 | } | |
3615 | ||
e7c27a73 | 3616 | element_type = die_type (die, cu); |
c906108c SS |
3617 | |
3618 | /* Irix 6.2 native cc creates array types without children for | |
3619 | arrays with unspecified length. */ | |
639d11d3 | 3620 | if (die->child == NULL) |
c906108c | 3621 | { |
e142c38c | 3622 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c SS |
3623 | range_type = create_range_type (NULL, index_type, 0, -1); |
3624 | die->type = create_array_type (NULL, element_type, range_type); | |
3625 | return; | |
3626 | } | |
3627 | ||
3628 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 3629 | child_die = die->child; |
c906108c SS |
3630 | while (child_die && child_die->tag) |
3631 | { | |
3632 | if (child_die->tag == DW_TAG_subrange_type) | |
3633 | { | |
a02abb62 | 3634 | read_subrange_type (child_die, cu); |
c906108c | 3635 | |
a02abb62 JB |
3636 | if (child_die->type != NULL) |
3637 | { | |
3638 | /* The range type was succesfully read. Save it for | |
3639 | the array type creation. */ | |
3640 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
3641 | { | |
3642 | range_types = (struct type **) | |
3643 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
3644 | * sizeof (struct type *)); | |
3645 | if (ndim == 0) | |
3646 | make_cleanup (free_current_contents, &range_types); | |
3647 | } | |
3648 | range_types[ndim++] = child_die->type; | |
3649 | } | |
c906108c SS |
3650 | } |
3651 | child_die = sibling_die (child_die); | |
3652 | } | |
3653 | ||
3654 | /* Dwarf2 dimensions are output from left to right, create the | |
3655 | necessary array types in backwards order. */ | |
3656 | type = element_type; | |
3657 | while (ndim-- > 0) | |
3658 | type = create_array_type (NULL, type, range_types[ndim]); | |
3659 | ||
f5f8a009 EZ |
3660 | /* Understand Dwarf2 support for vector types (like they occur on |
3661 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
3662 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
3663 | custom vendor extension. The main difference between a regular | |
3664 | array and the vector variant is that vectors are passed by value | |
3665 | to functions. */ | |
e142c38c | 3666 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 EZ |
3667 | if (attr) |
3668 | TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; | |
3669 | ||
c906108c SS |
3670 | do_cleanups (back_to); |
3671 | ||
3672 | /* Install the type in the die. */ | |
3673 | die->type = type; | |
3674 | } | |
3675 | ||
3676 | /* First cut: install each common block member as a global variable. */ | |
3677 | ||
3678 | static void | |
e7c27a73 | 3679 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3680 | { |
3681 | struct die_info *child_die; | |
3682 | struct attribute *attr; | |
3683 | struct symbol *sym; | |
3684 | CORE_ADDR base = (CORE_ADDR) 0; | |
3685 | ||
e142c38c | 3686 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
3687 | if (attr) |
3688 | { | |
8e19ed76 PS |
3689 | /* Support the .debug_loc offsets */ |
3690 | if (attr_form_is_block (attr)) | |
3691 | { | |
e7c27a73 | 3692 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 PS |
3693 | } |
3694 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3695 | { | |
4d3c2250 | 3696 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3697 | } |
3698 | else | |
3699 | { | |
4d3c2250 KB |
3700 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
3701 | "common block member"); | |
8e19ed76 | 3702 | } |
c906108c | 3703 | } |
639d11d3 | 3704 | if (die->child != NULL) |
c906108c | 3705 | { |
639d11d3 | 3706 | child_die = die->child; |
c906108c SS |
3707 | while (child_die && child_die->tag) |
3708 | { | |
e7c27a73 | 3709 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 3710 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
3711 | if (attr) |
3712 | { | |
3713 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 3714 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
3715 | add_symbol_to_list (sym, &global_symbols); |
3716 | } | |
3717 | child_die = sibling_die (child_die); | |
3718 | } | |
3719 | } | |
3720 | } | |
3721 | ||
d9fa45fe DC |
3722 | /* Read a C++ namespace. */ |
3723 | ||
d9fa45fe | 3724 | static void |
e7c27a73 | 3725 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 3726 | { |
e7c27a73 | 3727 | struct objfile *objfile = cu->objfile; |
38d518c9 | 3728 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 3729 | const char *name; |
9219021c DC |
3730 | int is_anonymous; |
3731 | struct die_info *current_die; | |
3732 | ||
e142c38c | 3733 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
3734 | |
3735 | /* Now build the name of the current namespace. */ | |
3736 | ||
38d518c9 | 3737 | if (previous_prefix[0] == '\0') |
9219021c | 3738 | { |
38d518c9 | 3739 | processing_current_prefix = name; |
9219021c DC |
3740 | } |
3741 | else | |
3742 | { | |
38d518c9 | 3743 | /* We need temp_name around because processing_current_prefix |
9219021c | 3744 | is a const char *. */ |
38d518c9 | 3745 | char *temp_name = alloca (strlen (previous_prefix) |
9219021c | 3746 | + 2 + strlen(name) + 1); |
38d518c9 | 3747 | strcpy (temp_name, previous_prefix); |
9219021c DC |
3748 | strcat (temp_name, "::"); |
3749 | strcat (temp_name, name); | |
3750 | ||
38d518c9 | 3751 | processing_current_prefix = temp_name; |
9219021c DC |
3752 | } |
3753 | ||
5c4e30ca DC |
3754 | /* Add a symbol associated to this if we haven't seen the namespace |
3755 | before. Also, add a using directive if it's an anonymous | |
3756 | namespace. */ | |
9219021c | 3757 | |
e142c38c | 3758 | if (dwarf2_extension (die, cu) == NULL) |
5c4e30ca DC |
3759 | { |
3760 | struct type *type; | |
3761 | ||
3762 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
3763 | this cast will hopefully become unnecessary. */ | |
3764 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 3765 | (char *) processing_current_prefix, |
5c4e30ca DC |
3766 | objfile); |
3767 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
3768 | ||
e7c27a73 | 3769 | new_symbol (die, type, cu); |
8176b9b8 | 3770 | die->type = type; |
5c4e30ca DC |
3771 | |
3772 | if (is_anonymous) | |
38d518c9 EZ |
3773 | cp_add_using_directive (processing_current_prefix, |
3774 | strlen (previous_prefix), | |
3775 | strlen (processing_current_prefix)); | |
5c4e30ca | 3776 | } |
9219021c | 3777 | |
639d11d3 | 3778 | if (die->child != NULL) |
d9fa45fe | 3779 | { |
639d11d3 | 3780 | struct die_info *child_die = die->child; |
d9fa45fe DC |
3781 | |
3782 | while (child_die && child_die->tag) | |
3783 | { | |
e7c27a73 | 3784 | process_die (child_die, cu); |
d9fa45fe DC |
3785 | child_die = sibling_die (child_die); |
3786 | } | |
3787 | } | |
9219021c | 3788 | |
38d518c9 EZ |
3789 | processing_current_prefix = previous_prefix; |
3790 | } | |
3791 | ||
3792 | /* Return the name of the namespace represented by DIE. Set | |
3793 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
3794 | namespace. */ | |
3795 | ||
3796 | static const char * | |
e142c38c | 3797 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
3798 | { |
3799 | struct die_info *current_die; | |
3800 | const char *name = NULL; | |
3801 | ||
3802 | /* Loop through the extensions until we find a name. */ | |
3803 | ||
3804 | for (current_die = die; | |
3805 | current_die != NULL; | |
e142c38c | 3806 | current_die = dwarf2_extension (die, cu)) |
38d518c9 | 3807 | { |
e142c38c | 3808 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
3809 | if (name != NULL) |
3810 | break; | |
3811 | } | |
3812 | ||
3813 | /* Is it an anonymous namespace? */ | |
3814 | ||
3815 | *is_anonymous = (name == NULL); | |
3816 | if (*is_anonymous) | |
3817 | name = "(anonymous namespace)"; | |
3818 | ||
3819 | return name; | |
d9fa45fe DC |
3820 | } |
3821 | ||
c906108c SS |
3822 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
3823 | the user defined type vector. */ | |
3824 | ||
3825 | static void | |
e7c27a73 | 3826 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3827 | { |
e7c27a73 | 3828 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 3829 | struct type *type; |
8b2dbe47 KB |
3830 | struct attribute *attr_byte_size; |
3831 | struct attribute *attr_address_class; | |
3832 | int byte_size, addr_class; | |
c906108c SS |
3833 | |
3834 | if (die->type) | |
3835 | { | |
3836 | return; | |
3837 | } | |
3838 | ||
e7c27a73 | 3839 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 3840 | |
e142c38c | 3841 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
3842 | if (attr_byte_size) |
3843 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 3844 | else |
8b2dbe47 KB |
3845 | byte_size = cu_header->addr_size; |
3846 | ||
e142c38c | 3847 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
3848 | if (attr_address_class) |
3849 | addr_class = DW_UNSND (attr_address_class); | |
3850 | else | |
3851 | addr_class = DW_ADDR_none; | |
3852 | ||
3853 | /* If the pointer size or address class is different than the | |
3854 | default, create a type variant marked as such and set the | |
3855 | length accordingly. */ | |
3856 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 3857 | { |
8b2dbe47 KB |
3858 | if (ADDRESS_CLASS_TYPE_FLAGS_P ()) |
3859 | { | |
3860 | int type_flags; | |
3861 | ||
3862 | type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); | |
3863 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); | |
3864 | type = make_type_with_address_space (type, type_flags); | |
3865 | } | |
3866 | else if (TYPE_LENGTH (type) != byte_size) | |
3867 | { | |
4d3c2250 | 3868 | complaint (&symfile_complaints, "invalid pointer size %d", byte_size); |
8b2dbe47 KB |
3869 | } |
3870 | else { | |
3871 | /* Should we also complain about unhandled address classes? */ | |
3872 | } | |
c906108c | 3873 | } |
8b2dbe47 KB |
3874 | |
3875 | TYPE_LENGTH (type) = byte_size; | |
c906108c SS |
3876 | die->type = type; |
3877 | } | |
3878 | ||
3879 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
3880 | the user defined type vector. */ | |
3881 | ||
3882 | static void | |
e7c27a73 | 3883 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3884 | { |
e7c27a73 | 3885 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3886 | struct type *type; |
3887 | struct type *to_type; | |
3888 | struct type *domain; | |
3889 | ||
3890 | if (die->type) | |
3891 | { | |
3892 | return; | |
3893 | } | |
3894 | ||
3895 | type = alloc_type (objfile); | |
e7c27a73 DJ |
3896 | to_type = die_type (die, cu); |
3897 | domain = die_containing_type (die, cu); | |
c906108c SS |
3898 | smash_to_member_type (type, domain, to_type); |
3899 | ||
3900 | die->type = type; | |
3901 | } | |
3902 | ||
3903 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
3904 | the user defined type vector. */ | |
3905 | ||
3906 | static void | |
e7c27a73 | 3907 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3908 | { |
e7c27a73 | 3909 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
3910 | struct type *type; |
3911 | struct attribute *attr; | |
3912 | ||
3913 | if (die->type) | |
3914 | { | |
3915 | return; | |
3916 | } | |
3917 | ||
e7c27a73 | 3918 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 3919 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3920 | if (attr) |
3921 | { | |
3922 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3923 | } | |
3924 | else | |
3925 | { | |
107d2387 | 3926 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c SS |
3927 | } |
3928 | die->type = type; | |
3929 | } | |
3930 | ||
3931 | static void | |
e7c27a73 | 3932 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3933 | { |
090c42a4 JB |
3934 | struct type *base_type; |
3935 | ||
c906108c SS |
3936 | if (die->type) |
3937 | { | |
3938 | return; | |
3939 | } | |
3940 | ||
e7c27a73 | 3941 | base_type = die_type (die, cu); |
090c42a4 | 3942 | die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
c906108c SS |
3943 | } |
3944 | ||
3945 | static void | |
e7c27a73 | 3946 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3947 | { |
090c42a4 JB |
3948 | struct type *base_type; |
3949 | ||
c906108c SS |
3950 | if (die->type) |
3951 | { | |
3952 | return; | |
3953 | } | |
3954 | ||
e7c27a73 | 3955 | base_type = die_type (die, cu); |
090c42a4 | 3956 | die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
c906108c SS |
3957 | } |
3958 | ||
3959 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
3960 | the user defined type vector. It isn't really a user defined type, | |
3961 | but it behaves like one, with other DIE's using an AT_user_def_type | |
3962 | attribute to reference it. */ | |
3963 | ||
3964 | static void | |
e7c27a73 | 3965 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3966 | { |
e7c27a73 | 3967 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3968 | struct type *type, *range_type, *index_type, *char_type; |
3969 | struct attribute *attr; | |
3970 | unsigned int length; | |
3971 | ||
3972 | if (die->type) | |
3973 | { | |
3974 | return; | |
3975 | } | |
3976 | ||
e142c38c | 3977 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
3978 | if (attr) |
3979 | { | |
3980 | length = DW_UNSND (attr); | |
3981 | } | |
3982 | else | |
3983 | { | |
b21b22e0 | 3984 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 3985 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
3986 | if (attr) |
3987 | { | |
3988 | length = DW_UNSND (attr); | |
3989 | } | |
3990 | else | |
3991 | { | |
3992 | length = 1; | |
3993 | } | |
c906108c | 3994 | } |
e142c38c | 3995 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c | 3996 | range_type = create_range_type (NULL, index_type, 1, length); |
e142c38c | 3997 | if (cu->language == language_fortran) |
b21b22e0 PS |
3998 | { |
3999 | /* Need to create a unique string type for bounds | |
4000 | information */ | |
4001 | type = create_string_type (0, range_type); | |
4002 | } | |
4003 | else | |
4004 | { | |
e142c38c | 4005 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu); |
b21b22e0 PS |
4006 | type = create_string_type (char_type, range_type); |
4007 | } | |
c906108c SS |
4008 | die->type = type; |
4009 | } | |
4010 | ||
4011 | /* Handle DIES due to C code like: | |
4012 | ||
4013 | struct foo | |
c5aa993b JM |
4014 | { |
4015 | int (*funcp)(int a, long l); | |
4016 | int b; | |
4017 | }; | |
c906108c SS |
4018 | |
4019 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4020 | */ |
c906108c SS |
4021 | |
4022 | static void | |
e7c27a73 | 4023 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4024 | { |
4025 | struct type *type; /* Type that this function returns */ | |
4026 | struct type *ftype; /* Function that returns above type */ | |
4027 | struct attribute *attr; | |
4028 | ||
4029 | /* Decode the type that this subroutine returns */ | |
4030 | if (die->type) | |
4031 | { | |
4032 | return; | |
4033 | } | |
e7c27a73 | 4034 | type = die_type (die, cu); |
c906108c SS |
4035 | ftype = lookup_function_type (type); |
4036 | ||
4037 | /* All functions in C++ have prototypes. */ | |
e142c38c | 4038 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4039 | if ((attr && (DW_UNSND (attr) != 0)) |
e142c38c | 4040 | || cu->language == language_cplus) |
c906108c SS |
4041 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4042 | ||
639d11d3 | 4043 | if (die->child != NULL) |
c906108c SS |
4044 | { |
4045 | struct die_info *child_die; | |
4046 | int nparams = 0; | |
4047 | int iparams = 0; | |
4048 | ||
4049 | /* Count the number of parameters. | |
4050 | FIXME: GDB currently ignores vararg functions, but knows about | |
4051 | vararg member functions. */ | |
639d11d3 | 4052 | child_die = die->child; |
c906108c SS |
4053 | while (child_die && child_die->tag) |
4054 | { | |
4055 | if (child_die->tag == DW_TAG_formal_parameter) | |
4056 | nparams++; | |
4057 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4058 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4059 | child_die = sibling_die (child_die); | |
4060 | } | |
4061 | ||
4062 | /* Allocate storage for parameters and fill them in. */ | |
4063 | TYPE_NFIELDS (ftype) = nparams; | |
4064 | TYPE_FIELDS (ftype) = (struct field *) | |
4065 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); | |
4066 | ||
639d11d3 | 4067 | child_die = die->child; |
c906108c SS |
4068 | while (child_die && child_die->tag) |
4069 | { | |
4070 | if (child_die->tag == DW_TAG_formal_parameter) | |
4071 | { | |
4072 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4073 | member functions. G++ helps GDB by marking the first |
4074 | parameter for non-static member functions (which is the | |
4075 | this pointer) as artificial. We pass this information | |
4076 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4077 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4078 | if (attr) |
4079 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4080 | else | |
4081 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4082 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4083 | iparams++; |
4084 | } | |
4085 | child_die = sibling_die (child_die); | |
4086 | } | |
4087 | } | |
4088 | ||
4089 | die->type = ftype; | |
4090 | } | |
4091 | ||
4092 | static void | |
e7c27a73 | 4093 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4094 | { |
e7c27a73 | 4095 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4096 | struct attribute *attr; |
4097 | char *name = NULL; | |
c906108c SS |
4098 | |
4099 | if (!die->type) | |
4100 | { | |
e142c38c | 4101 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c | 4102 | if (attr && DW_STRING (attr)) |
2f038fcb FF |
4103 | { |
4104 | name = DW_STRING (attr); | |
4105 | } | |
4106 | die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile); | |
e7c27a73 | 4107 | TYPE_TARGET_TYPE (die->type) = die_type (die, cu); |
c906108c SS |
4108 | } |
4109 | } | |
4110 | ||
4111 | /* Find a representation of a given base type and install | |
4112 | it in the TYPE field of the die. */ | |
4113 | ||
4114 | static void | |
e7c27a73 | 4115 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4116 | { |
e7c27a73 | 4117 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4118 | struct type *type; |
4119 | struct attribute *attr; | |
4120 | int encoding = 0, size = 0; | |
4121 | ||
4122 | /* If we've already decoded this die, this is a no-op. */ | |
4123 | if (die->type) | |
4124 | { | |
4125 | return; | |
4126 | } | |
4127 | ||
e142c38c | 4128 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4129 | if (attr) |
4130 | { | |
4131 | encoding = DW_UNSND (attr); | |
4132 | } | |
e142c38c | 4133 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4134 | if (attr) |
4135 | { | |
4136 | size = DW_UNSND (attr); | |
4137 | } | |
e142c38c | 4138 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
4139 | if (attr && DW_STRING (attr)) |
4140 | { | |
4141 | enum type_code code = TYPE_CODE_INT; | |
f5ef7c67 | 4142 | int type_flags = 0; |
c906108c SS |
4143 | |
4144 | switch (encoding) | |
4145 | { | |
4146 | case DW_ATE_address: | |
4147 | /* Turn DW_ATE_address into a void * pointer. */ | |
4148 | code = TYPE_CODE_PTR; | |
f5ef7c67 | 4149 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4150 | break; |
4151 | case DW_ATE_boolean: | |
4152 | code = TYPE_CODE_BOOL; | |
f5ef7c67 | 4153 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4154 | break; |
4155 | case DW_ATE_complex_float: | |
4156 | code = TYPE_CODE_COMPLEX; | |
4157 | break; | |
4158 | case DW_ATE_float: | |
4159 | code = TYPE_CODE_FLT; | |
4160 | break; | |
4161 | case DW_ATE_signed: | |
4162 | case DW_ATE_signed_char: | |
4163 | break; | |
4164 | case DW_ATE_unsigned: | |
4165 | case DW_ATE_unsigned_char: | |
f5ef7c67 | 4166 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4167 | break; |
4168 | default: | |
4d3c2250 KB |
4169 | complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", |
4170 | dwarf_type_encoding_name (encoding)); | |
c906108c SS |
4171 | break; |
4172 | } | |
f5ef7c67 | 4173 | type = init_type (code, size, type_flags, DW_STRING (attr), objfile); |
c906108c | 4174 | if (encoding == DW_ATE_address) |
e142c38c DJ |
4175 | TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID, |
4176 | cu); | |
f65ca430 DJ |
4177 | else if (encoding == DW_ATE_complex_float) |
4178 | { | |
4179 | if (size == 32) | |
4180 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4181 | = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu); |
f65ca430 DJ |
4182 | else if (size == 16) |
4183 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4184 | = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
f65ca430 DJ |
4185 | else if (size == 8) |
4186 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4187 | = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
f65ca430 | 4188 | } |
c906108c SS |
4189 | } |
4190 | else | |
4191 | { | |
e7c27a73 | 4192 | type = dwarf_base_type (encoding, size, cu); |
c906108c SS |
4193 | } |
4194 | die->type = type; | |
4195 | } | |
4196 | ||
a02abb62 JB |
4197 | /* Read the given DW_AT_subrange DIE. */ |
4198 | ||
4199 | static void | |
4200 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) | |
4201 | { | |
4202 | struct type *base_type; | |
4203 | struct type *range_type; | |
4204 | struct attribute *attr; | |
4205 | int low = 0; | |
4206 | int high = -1; | |
4207 | ||
4208 | /* If we have already decoded this die, then nothing more to do. */ | |
4209 | if (die->type) | |
4210 | return; | |
4211 | ||
4212 | base_type = die_type (die, cu); | |
4213 | if (base_type == NULL) | |
4214 | { | |
4215 | complaint (&symfile_complaints, | |
4216 | "DW_AT_type missing from DW_TAG_subrange_type"); | |
4217 | return; | |
4218 | } | |
4219 | ||
4220 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
4221 | base_type = alloc_type (NULL); | |
4222 | ||
e142c38c | 4223 | if (cu->language == language_fortran) |
a02abb62 JB |
4224 | { |
4225 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
4226 | low = 1; | |
4227 | } | |
4228 | ||
e142c38c | 4229 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
4230 | if (attr) |
4231 | low = dwarf2_get_attr_constant_value (attr, 0); | |
4232 | ||
e142c38c | 4233 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
4234 | if (attr) |
4235 | { | |
4236 | if (attr->form == DW_FORM_block1) | |
4237 | { | |
4238 | /* GCC encodes arrays with unspecified or dynamic length | |
4239 | with a DW_FORM_block1 attribute. | |
4240 | FIXME: GDB does not yet know how to handle dynamic | |
4241 | arrays properly, treat them as arrays with unspecified | |
4242 | length for now. | |
4243 | ||
4244 | FIXME: jimb/2003-09-22: GDB does not really know | |
4245 | how to handle arrays of unspecified length | |
4246 | either; we just represent them as zero-length | |
4247 | arrays. Choose an appropriate upper bound given | |
4248 | the lower bound we've computed above. */ | |
4249 | high = low - 1; | |
4250 | } | |
4251 | else | |
4252 | high = dwarf2_get_attr_constant_value (attr, 1); | |
4253 | } | |
4254 | ||
4255 | range_type = create_range_type (NULL, base_type, low, high); | |
4256 | ||
e142c38c | 4257 | attr = dwarf2_attr (die, DW_AT_name, cu); |
a02abb62 JB |
4258 | if (attr && DW_STRING (attr)) |
4259 | TYPE_NAME (range_type) = DW_STRING (attr); | |
4260 | ||
e142c38c | 4261 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
4262 | if (attr) |
4263 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
4264 | ||
4265 | die->type = range_type; | |
4266 | } | |
4267 | ||
4268 | ||
c906108c SS |
4269 | /* Read a whole compilation unit into a linked list of dies. */ |
4270 | ||
f9aca02d | 4271 | static struct die_info * |
e7c27a73 | 4272 | read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4273 | { |
b3810801 | 4274 | /* Reset die reference table; we are |
7f0e3f52 AC |
4275 | building new ones now. */ |
4276 | dwarf2_empty_hash_tables (); | |
c906108c | 4277 | |
e7c27a73 | 4278 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
4279 | } |
4280 | ||
4281 | /* Read a single die and all its descendents. Set the die's sibling | |
4282 | field to NULL; set other fields in the die correctly, and set all | |
4283 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
4284 | location of the info_ptr after reading all of those dies. PARENT | |
4285 | is the parent of the die in question. */ | |
4286 | ||
4287 | static struct die_info * | |
4288 | read_die_and_children (char *info_ptr, bfd *abfd, | |
e7c27a73 | 4289 | struct dwarf2_cu *cu, |
639d11d3 DC |
4290 | char **new_info_ptr, |
4291 | struct die_info *parent) | |
4292 | { | |
4293 | struct die_info *die; | |
4294 | char *cur_ptr; | |
4295 | int has_children; | |
4296 | ||
e7c27a73 | 4297 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
639d11d3 DC |
4298 | store_in_ref_table (die->offset, die); |
4299 | ||
4300 | if (has_children) | |
4301 | { | |
e7c27a73 | 4302 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
4303 | new_info_ptr, die); |
4304 | } | |
4305 | else | |
4306 | { | |
4307 | die->child = NULL; | |
4308 | *new_info_ptr = cur_ptr; | |
4309 | } | |
4310 | ||
4311 | die->sibling = NULL; | |
4312 | die->parent = parent; | |
4313 | return die; | |
4314 | } | |
4315 | ||
4316 | /* Read a die, all of its descendents, and all of its siblings; set | |
4317 | all of the fields of all of the dies correctly. Arguments are as | |
4318 | in read_die_and_children. */ | |
4319 | ||
4320 | static struct die_info * | |
4321 | read_die_and_siblings (char *info_ptr, bfd *abfd, | |
e7c27a73 | 4322 | struct dwarf2_cu *cu, |
639d11d3 DC |
4323 | char **new_info_ptr, |
4324 | struct die_info *parent) | |
4325 | { | |
4326 | struct die_info *first_die, *last_sibling; | |
4327 | char *cur_ptr; | |
4328 | ||
c906108c | 4329 | cur_ptr = info_ptr; |
639d11d3 DC |
4330 | first_die = last_sibling = NULL; |
4331 | ||
4332 | while (1) | |
c906108c | 4333 | { |
639d11d3 | 4334 | struct die_info *die |
e7c27a73 | 4335 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 DC |
4336 | |
4337 | if (!first_die) | |
c906108c | 4338 | { |
639d11d3 | 4339 | first_die = die; |
c906108c | 4340 | } |
639d11d3 | 4341 | else |
c906108c | 4342 | { |
639d11d3 | 4343 | last_sibling->sibling = die; |
c906108c SS |
4344 | } |
4345 | ||
639d11d3 | 4346 | if (die->tag == 0) |
c906108c | 4347 | { |
639d11d3 DC |
4348 | *new_info_ptr = cur_ptr; |
4349 | return first_die; | |
c906108c SS |
4350 | } |
4351 | else | |
4352 | { | |
639d11d3 | 4353 | last_sibling = die; |
c906108c SS |
4354 | } |
4355 | } | |
c906108c SS |
4356 | } |
4357 | ||
4358 | /* Free a linked list of dies. */ | |
4359 | ||
4360 | static void | |
fba45db2 | 4361 | free_die_list (struct die_info *dies) |
c906108c SS |
4362 | { |
4363 | struct die_info *die, *next; | |
4364 | ||
4365 | die = dies; | |
4366 | while (die) | |
4367 | { | |
639d11d3 DC |
4368 | if (die->child != NULL) |
4369 | free_die_list (die->child); | |
4370 | next = die->sibling; | |
b8c9b27d KB |
4371 | xfree (die->attrs); |
4372 | xfree (die); | |
c906108c SS |
4373 | die = next; |
4374 | } | |
4375 | } | |
4376 | ||
74b7792f AC |
4377 | static void |
4378 | do_free_die_list_cleanup (void *dies) | |
4379 | { | |
4380 | free_die_list (dies); | |
4381 | } | |
4382 | ||
4383 | static struct cleanup * | |
4384 | make_cleanup_free_die_list (struct die_info *dies) | |
4385 | { | |
4386 | return make_cleanup (do_free_die_list_cleanup, dies); | |
4387 | } | |
4388 | ||
4389 | ||
c906108c | 4390 | /* Read the contents of the section at OFFSET and of size SIZE from the |
8b92e4d5 | 4391 | object file specified by OBJFILE into the objfile_obstack and return it. */ |
c906108c | 4392 | |
b6af0555 | 4393 | char * |
188dd5d6 | 4394 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
4395 | { |
4396 | bfd *abfd = objfile->obfd; | |
086df311 | 4397 | char *buf, *retbuf; |
188dd5d6 | 4398 | bfd_size_type size = bfd_get_section_size_before_reloc (sectp); |
c906108c SS |
4399 | |
4400 | if (size == 0) | |
4401 | return NULL; | |
4402 | ||
8b92e4d5 | 4403 | buf = (char *) obstack_alloc (&objfile->objfile_obstack, size); |
086df311 DJ |
4404 | retbuf |
4405 | = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); | |
4406 | if (retbuf != NULL) | |
4407 | return retbuf; | |
4408 | ||
188dd5d6 DJ |
4409 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
4410 | || bfd_bread (buf, size, abfd) != size) | |
4411 | error ("Dwarf Error: Can't read DWARF data from '%s'", | |
4412 | bfd_get_filename (abfd)); | |
4413 | ||
c906108c SS |
4414 | return buf; |
4415 | } | |
4416 | ||
4417 | /* In DWARF version 2, the description of the debugging information is | |
4418 | stored in a separate .debug_abbrev section. Before we read any | |
4419 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
4420 | in a hash table. This function also sets flags in CU describing |
4421 | the data found in the abbrev table. */ | |
c906108c SS |
4422 | |
4423 | static void | |
e7c27a73 | 4424 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4425 | { |
e7c27a73 | 4426 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4427 | char *abbrev_ptr; |
4428 | struct abbrev_info *cur_abbrev; | |
4429 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
4430 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
4431 | struct attr_abbrev *cur_attrs; |
4432 | unsigned int allocated_attrs; | |
c906108c | 4433 | |
57349743 | 4434 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
4435 | obstack_init (&cu->abbrev_obstack); |
4436 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
4437 | (ABBREV_HASH_SIZE | |
4438 | * sizeof (struct abbrev_info *))); | |
4439 | memset (cu->dwarf2_abbrevs, 0, | |
4440 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 4441 | |
6502dd73 | 4442 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
4443 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
4444 | abbrev_ptr += bytes_read; | |
4445 | ||
f3dd6933 DJ |
4446 | allocated_attrs = ATTR_ALLOC_CHUNK; |
4447 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
4448 | ||
c906108c SS |
4449 | /* loop until we reach an abbrev number of 0 */ |
4450 | while (abbrev_number) | |
4451 | { | |
f3dd6933 | 4452 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
4453 | |
4454 | /* read in abbrev header */ | |
4455 | cur_abbrev->number = abbrev_number; | |
4456 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4457 | abbrev_ptr += bytes_read; | |
4458 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
4459 | abbrev_ptr += 1; | |
4460 | ||
72bf9492 DJ |
4461 | if (cur_abbrev->tag == DW_TAG_namespace) |
4462 | cu->has_namespace_info = 1; | |
4463 | ||
c906108c SS |
4464 | /* now read in declarations */ |
4465 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4466 | abbrev_ptr += bytes_read; | |
4467 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4468 | abbrev_ptr += bytes_read; | |
4469 | while (abbrev_name) | |
4470 | { | |
f3dd6933 | 4471 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 4472 | { |
f3dd6933 DJ |
4473 | allocated_attrs += ATTR_ALLOC_CHUNK; |
4474 | cur_attrs | |
4475 | = xrealloc (cur_attrs, (allocated_attrs | |
4476 | * sizeof (struct attr_abbrev))); | |
c906108c | 4477 | } |
f3dd6933 DJ |
4478 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
4479 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
4480 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
4481 | abbrev_ptr += bytes_read; | |
4482 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4483 | abbrev_ptr += bytes_read; | |
4484 | } | |
4485 | ||
f3dd6933 DJ |
4486 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
4487 | (cur_abbrev->num_attrs | |
4488 | * sizeof (struct attr_abbrev))); | |
4489 | memcpy (cur_abbrev->attrs, cur_attrs, | |
4490 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
4491 | ||
c906108c | 4492 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
4493 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
4494 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
4495 | |
4496 | /* Get next abbreviation. | |
4497 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
4498 | always properly terminated with an abbrev number of 0. |
4499 | Exit loop if we encounter an abbreviation which we have | |
4500 | already read (which means we are about to read the abbreviations | |
4501 | for the next compile unit) or if the end of the abbreviation | |
4502 | table is reached. */ | |
6502dd73 DJ |
4503 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
4504 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
4505 | break; |
4506 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4507 | abbrev_ptr += bytes_read; | |
e7c27a73 | 4508 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
4509 | break; |
4510 | } | |
f3dd6933 DJ |
4511 | |
4512 | xfree (cur_attrs); | |
c906108c SS |
4513 | } |
4514 | ||
f3dd6933 | 4515 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 4516 | |
c906108c | 4517 | static void |
f3dd6933 | 4518 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 4519 | { |
f3dd6933 | 4520 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 4521 | |
f3dd6933 DJ |
4522 | obstack_free (&cu->abbrev_obstack, NULL); |
4523 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
4524 | } |
4525 | ||
4526 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
4527 | ||
4528 | static struct abbrev_info * | |
e7c27a73 | 4529 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
4530 | { |
4531 | unsigned int hash_number; | |
4532 | struct abbrev_info *abbrev; | |
4533 | ||
4534 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 4535 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
4536 | |
4537 | while (abbrev) | |
4538 | { | |
4539 | if (abbrev->number == number) | |
4540 | return abbrev; | |
4541 | else | |
4542 | abbrev = abbrev->next; | |
4543 | } | |
4544 | return NULL; | |
4545 | } | |
4546 | ||
72bf9492 DJ |
4547 | /* Returns nonzero if TAG represents a type that we might generate a partial |
4548 | symbol for. */ | |
4549 | ||
4550 | static int | |
4551 | is_type_tag_for_partial (int tag) | |
4552 | { | |
4553 | switch (tag) | |
4554 | { | |
4555 | #if 0 | |
4556 | /* Some types that would be reasonable to generate partial symbols for, | |
4557 | that we don't at present. */ | |
4558 | case DW_TAG_array_type: | |
4559 | case DW_TAG_file_type: | |
4560 | case DW_TAG_ptr_to_member_type: | |
4561 | case DW_TAG_set_type: | |
4562 | case DW_TAG_string_type: | |
4563 | case DW_TAG_subroutine_type: | |
4564 | #endif | |
4565 | case DW_TAG_base_type: | |
4566 | case DW_TAG_class_type: | |
4567 | case DW_TAG_enumeration_type: | |
4568 | case DW_TAG_structure_type: | |
4569 | case DW_TAG_subrange_type: | |
4570 | case DW_TAG_typedef: | |
4571 | case DW_TAG_union_type: | |
4572 | return 1; | |
4573 | default: | |
4574 | return 0; | |
4575 | } | |
4576 | } | |
4577 | ||
4578 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
4579 | ||
4580 | static struct partial_die_info * | |
4581 | load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab, | |
4582 | struct dwarf2_cu *cu) | |
4583 | { | |
4584 | struct partial_die_info *part_die; | |
4585 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
4586 | struct abbrev_info *abbrev; | |
4587 | unsigned int bytes_read; | |
4588 | ||
4589 | int nesting_level = 1; | |
4590 | ||
4591 | parent_die = NULL; | |
4592 | last_die = NULL; | |
4593 | ||
4594 | cu->partial_dies | |
4595 | = htab_create_alloc_ex (cu->header.length / 12, | |
4596 | partial_die_hash, | |
4597 | partial_die_eq, | |
4598 | NULL, | |
4599 | &cu->comp_unit_obstack, | |
4600 | hashtab_obstack_allocate, | |
4601 | dummy_obstack_deallocate); | |
4602 | ||
4603 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
4604 | sizeof (struct partial_die_info)); | |
4605 | ||
4606 | while (1) | |
4607 | { | |
4608 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4609 | ||
4610 | /* A NULL abbrev means the end of a series of children. */ | |
4611 | if (abbrev == NULL) | |
4612 | { | |
4613 | if (--nesting_level == 0) | |
4614 | { | |
4615 | /* PART_DIE was probably the last thing allocated on the | |
4616 | comp_unit_obstack, so we could call obstack_free | |
4617 | here. We don't do that because the waste is small, | |
4618 | and will be cleaned up when we're done with this | |
4619 | compilation unit. This way, we're also more robust | |
4620 | against other users of the comp_unit_obstack. */ | |
4621 | return first_die; | |
4622 | } | |
4623 | info_ptr += bytes_read; | |
4624 | last_die = parent_die; | |
4625 | parent_die = parent_die->die_parent; | |
4626 | continue; | |
4627 | } | |
4628 | ||
4629 | /* Check whether this DIE is interesting enough to save. */ | |
4630 | if (!is_type_tag_for_partial (abbrev->tag) | |
4631 | && abbrev->tag != DW_TAG_enumerator | |
4632 | && abbrev->tag != DW_TAG_subprogram | |
4633 | && abbrev->tag != DW_TAG_variable | |
4634 | && abbrev->tag != DW_TAG_namespace) | |
4635 | { | |
4636 | /* Otherwise we skip to the next sibling, if any. */ | |
4637 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
4638 | continue; | |
4639 | } | |
4640 | ||
4641 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
4642 | abfd, info_ptr, cu); | |
4643 | ||
4644 | /* This two-pass algorithm for processing partial symbols has a | |
4645 | high cost in cache pressure. Thus, handle some simple cases | |
4646 | here which cover the majority of C partial symbols. DIEs | |
4647 | which neither have specification tags in them, nor could have | |
4648 | specification tags elsewhere pointing at them, can simply be | |
4649 | processed and discarded. | |
4650 | ||
4651 | This segment is also optional; scan_partial_symbols and | |
4652 | add_partial_symbol will handle these DIEs if we chain | |
4653 | them in normally. When compilers which do not emit large | |
4654 | quantities of duplicate debug information are more common, | |
4655 | this code can probably be removed. */ | |
4656 | ||
4657 | /* Any complete simple types at the top level (pretty much all | |
4658 | of them, for a language without namespaces), can be processed | |
4659 | directly. */ | |
4660 | if (parent_die == NULL | |
4661 | && part_die->has_specification == 0 | |
4662 | && part_die->is_declaration == 0 | |
4663 | && (part_die->tag == DW_TAG_typedef | |
4664 | || part_die->tag == DW_TAG_base_type | |
4665 | || part_die->tag == DW_TAG_subrange_type)) | |
4666 | { | |
4667 | if (building_psymtab && part_die->name != NULL) | |
4668 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
4669 | VAR_DOMAIN, LOC_TYPEDEF, | |
4670 | &cu->objfile->static_psymbols, | |
4671 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
4672 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
4673 | continue; | |
4674 | } | |
4675 | ||
4676 | /* If we're at the second level, and we're an enumerator, and | |
4677 | our parent has no specification (meaning possibly lives in a | |
4678 | namespace elsewhere), then we can add the partial symbol now | |
4679 | instead of queueing it. */ | |
4680 | if (part_die->tag == DW_TAG_enumerator | |
4681 | && parent_die != NULL | |
4682 | && parent_die->die_parent == NULL | |
4683 | && parent_die->tag == DW_TAG_enumeration_type | |
4684 | && parent_die->has_specification == 0) | |
4685 | { | |
4686 | if (part_die->name == NULL) | |
4687 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); | |
4688 | else if (building_psymtab) | |
4689 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
4690 | VAR_DOMAIN, LOC_CONST, | |
4691 | cu->language == language_cplus | |
4692 | ? &cu->objfile->global_psymbols | |
4693 | : &cu->objfile->static_psymbols, | |
4694 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
4695 | ||
4696 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
4697 | continue; | |
4698 | } | |
4699 | ||
4700 | /* We'll save this DIE so link it in. */ | |
4701 | part_die->die_parent = parent_die; | |
4702 | part_die->die_sibling = NULL; | |
4703 | part_die->die_child = NULL; | |
4704 | ||
4705 | if (last_die && last_die == parent_die) | |
4706 | last_die->die_child = part_die; | |
4707 | else if (last_die) | |
4708 | last_die->die_sibling = part_die; | |
4709 | ||
4710 | last_die = part_die; | |
4711 | ||
4712 | if (first_die == NULL) | |
4713 | first_die = part_die; | |
4714 | ||
4715 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
4716 | find interesting need to be in the hash table, because we | |
4717 | also have the parent/sibling/child chains; only those that we | |
4718 | might refer to by offset later during partial symbol reading. | |
4719 | ||
4720 | For now this means things that might have be the target of a | |
4721 | DW_AT_specification, DW_AT_abstract_origin, or | |
4722 | DW_AT_extension. DW_AT_extension will refer only to | |
4723 | namespaces; DW_AT_abstract_origin refers to functions (and | |
4724 | many things under the function DIE, but we do not recurse | |
4725 | into function DIEs during partial symbol reading) and | |
4726 | possibly variables as well; DW_AT_specification refers to | |
4727 | declarations. Declarations ought to have the DW_AT_declaration | |
4728 | flag. It happens that GCC forgets to put it in sometimes, but | |
4729 | only for functions, not for types. | |
4730 | ||
4731 | Adding more things than necessary to the hash table is harmless | |
4732 | except for the performance cost. Adding too few will result in | |
4733 | internal errors in find_partial_die. */ | |
4734 | ||
4735 | if (abbrev->tag == DW_TAG_subprogram | |
4736 | || abbrev->tag == DW_TAG_variable | |
4737 | || abbrev->tag == DW_TAG_namespace | |
4738 | || part_die->is_declaration) | |
4739 | { | |
4740 | void **slot; | |
4741 | ||
4742 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
4743 | part_die->offset, INSERT); | |
4744 | *slot = part_die; | |
4745 | } | |
4746 | ||
4747 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
4748 | sizeof (struct partial_die_info)); | |
4749 | ||
4750 | /* For some DIEs we want to follow their children (if any). For C | |
4751 | we have no reason to follow the children of structures; for other | |
4752 | languages we have to, both so that we can get at method physnames | |
4753 | to infer fully qualified class names, and for DW_AT_specification. */ | |
4754 | if (last_die->has_children | |
4755 | && (last_die->tag == DW_TAG_namespace | |
4756 | || last_die->tag == DW_TAG_enumeration_type | |
4757 | || (cu->language != language_c | |
4758 | && (last_die->tag == DW_TAG_class_type | |
4759 | || last_die->tag == DW_TAG_structure_type | |
4760 | || last_die->tag == DW_TAG_union_type)))) | |
4761 | { | |
4762 | nesting_level++; | |
4763 | parent_die = last_die; | |
4764 | continue; | |
4765 | } | |
4766 | ||
4767 | /* Otherwise we skip to the next sibling, if any. */ | |
4768 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
4769 | ||
4770 | /* Back to the top, do it again. */ | |
4771 | } | |
4772 | } | |
4773 | ||
c906108c SS |
4774 | /* Read a minimal amount of information into the minimal die structure. */ |
4775 | ||
4776 | static char * | |
72bf9492 DJ |
4777 | read_partial_die (struct partial_die_info *part_die, |
4778 | struct abbrev_info *abbrev, | |
4779 | unsigned int abbrev_len, bfd *abfd, | |
e7c27a73 | 4780 | char *info_ptr, struct dwarf2_cu *cu) |
c906108c | 4781 | { |
72bf9492 | 4782 | unsigned int bytes_read, i; |
c906108c | 4783 | struct attribute attr; |
c5aa993b | 4784 | int has_low_pc_attr = 0; |
c906108c SS |
4785 | int has_high_pc_attr = 0; |
4786 | ||
72bf9492 | 4787 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 4788 | |
6502dd73 | 4789 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
4790 | |
4791 | info_ptr += abbrev_len; | |
4792 | ||
4793 | if (abbrev == NULL) | |
4794 | return info_ptr; | |
4795 | ||
c906108c SS |
4796 | part_die->tag = abbrev->tag; |
4797 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
4798 | |
4799 | for (i = 0; i < abbrev->num_attrs; ++i) | |
4800 | { | |
e7c27a73 | 4801 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
4802 | |
4803 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 4804 | partial symbol table. */ |
c906108c SS |
4805 | switch (attr.name) |
4806 | { | |
4807 | case DW_AT_name: | |
4808 | ||
4809 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
4810 | if (part_die->name == NULL) | |
4811 | part_die->name = DW_STRING (&attr); | |
4812 | break; | |
4813 | case DW_AT_MIPS_linkage_name: | |
4814 | part_die->name = DW_STRING (&attr); | |
4815 | break; | |
4816 | case DW_AT_low_pc: | |
4817 | has_low_pc_attr = 1; | |
4818 | part_die->lowpc = DW_ADDR (&attr); | |
4819 | break; | |
4820 | case DW_AT_high_pc: | |
4821 | has_high_pc_attr = 1; | |
4822 | part_die->highpc = DW_ADDR (&attr); | |
4823 | break; | |
4824 | case DW_AT_location: | |
8e19ed76 PS |
4825 | /* Support the .debug_loc offsets */ |
4826 | if (attr_form_is_block (&attr)) | |
4827 | { | |
4828 | part_die->locdesc = DW_BLOCK (&attr); | |
4829 | } | |
4830 | else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) | |
4831 | { | |
4d3c2250 | 4832 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4833 | } |
4834 | else | |
4835 | { | |
4d3c2250 KB |
4836 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4837 | "partial symbol information"); | |
8e19ed76 | 4838 | } |
c906108c SS |
4839 | break; |
4840 | case DW_AT_language: | |
4841 | part_die->language = DW_UNSND (&attr); | |
4842 | break; | |
4843 | case DW_AT_external: | |
4844 | part_die->is_external = DW_UNSND (&attr); | |
4845 | break; | |
4846 | case DW_AT_declaration: | |
4847 | part_die->is_declaration = DW_UNSND (&attr); | |
4848 | break; | |
4849 | case DW_AT_type: | |
4850 | part_die->has_type = 1; | |
4851 | break; | |
4852 | case DW_AT_abstract_origin: | |
4853 | case DW_AT_specification: | |
72bf9492 DJ |
4854 | case DW_AT_extension: |
4855 | part_die->has_specification = 1; | |
4856 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
4857 | break; |
4858 | case DW_AT_sibling: | |
4859 | /* Ignore absolute siblings, they might point outside of | |
4860 | the current compile unit. */ | |
4861 | if (attr.form == DW_FORM_ref_addr) | |
4d3c2250 | 4862 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); |
c906108c | 4863 | else |
6502dd73 DJ |
4864 | part_die->sibling = dwarf2_per_objfile->info_buffer |
4865 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
4866 | break; |
4867 | default: | |
4868 | break; | |
4869 | } | |
4870 | } | |
4871 | ||
c906108c SS |
4872 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
4873 | eliminate duplicate copies of functions and vtables and such. | |
4874 | The linker will arbitrarily choose one and discard the others. | |
4875 | The AT_*_pc values for such functions refer to local labels in | |
4876 | these sections. If the section from that file was discarded, the | |
4877 | labels are not in the output, so the relocs get a value of 0. | |
4878 | If this is a discarded function, mark the pc bounds as invalid, | |
4879 | so that GDB will ignore it. */ | |
4880 | if (has_low_pc_attr && has_high_pc_attr | |
4881 | && part_die->lowpc < part_die->highpc | |
4882 | && (part_die->lowpc != 0 | |
4883 | || (bfd_get_file_flags (abfd) & HAS_RELOC))) | |
0b010bcc | 4884 | part_die->has_pc_info = 1; |
c906108c SS |
4885 | return info_ptr; |
4886 | } | |
4887 | ||
72bf9492 DJ |
4888 | /* Find a cached partial DIE at OFFSET in CU. */ |
4889 | ||
4890 | static struct partial_die_info * | |
4891 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
4892 | { | |
4893 | struct partial_die_info *lookup_die = NULL; | |
4894 | struct partial_die_info part_die; | |
4895 | ||
4896 | part_die.offset = offset; | |
4897 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
4898 | ||
4899 | if (lookup_die == NULL) | |
4900 | internal_error (__FILE__, __LINE__, | |
4901 | "could not find partial DIE in cache\n"); | |
4902 | ||
4903 | return lookup_die; | |
4904 | } | |
4905 | ||
4906 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
4907 | ||
4908 | static struct partial_die_info * | |
4909 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu, | |
4910 | struct dwarf2_cu **target_cu) | |
4911 | { | |
4912 | struct dwarf2_per_cu_data *per_cu; | |
4913 | ||
4914 | if (offset >= cu->header.offset | |
4915 | && offset < cu->header.offset + cu->header.length) | |
4916 | { | |
4917 | *target_cu = cu; | |
4918 | return find_partial_die_in_comp_unit (offset, cu); | |
4919 | } | |
4920 | ||
4921 | internal_error (__FILE__, __LINE__, | |
4922 | "unsupported inter-compilation-unit reference"); | |
4923 | } | |
4924 | ||
4925 | /* Adjust PART_DIE before generating a symbol for it. This function | |
4926 | may set the is_external flag or change the DIE's name. */ | |
4927 | ||
4928 | static void | |
4929 | fixup_partial_die (struct partial_die_info *part_die, | |
4930 | struct dwarf2_cu *cu) | |
4931 | { | |
4932 | /* If we found a reference attribute and the DIE has no name, try | |
4933 | to find a name in the referred to DIE. */ | |
4934 | ||
4935 | if (part_die->name == NULL && part_die->has_specification) | |
4936 | { | |
4937 | struct partial_die_info *spec_die; | |
4938 | struct dwarf2_cu *spec_cu; | |
4939 | ||
4940 | spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu); | |
4941 | ||
4942 | fixup_partial_die (spec_die, spec_cu); | |
4943 | ||
4944 | if (spec_die->name) | |
4945 | { | |
4946 | part_die->name = spec_die->name; | |
4947 | ||
4948 | /* Copy DW_AT_external attribute if it is set. */ | |
4949 | if (spec_die->is_external) | |
4950 | part_die->is_external = spec_die->is_external; | |
4951 | } | |
4952 | } | |
4953 | ||
4954 | /* Set default names for some unnamed DIEs. */ | |
4955 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
4956 | || part_die->tag == DW_TAG_class_type)) | |
4957 | part_die->name = "(anonymous class)"; | |
4958 | ||
4959 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
4960 | part_die->name = "(anonymous namespace)"; | |
4961 | ||
4962 | if (part_die->tag == DW_TAG_structure_type | |
4963 | || part_die->tag == DW_TAG_class_type | |
4964 | || part_die->tag == DW_TAG_union_type) | |
4965 | guess_structure_name (part_die, cu); | |
4966 | } | |
4967 | ||
639d11d3 DC |
4968 | /* Read the die from the .debug_info section buffer. Set DIEP to |
4969 | point to a newly allocated die with its information, except for its | |
4970 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
4971 | whether the die has children or not. */ | |
c906108c SS |
4972 | |
4973 | static char * | |
107d2387 | 4974 | read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, |
e7c27a73 | 4975 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
4976 | { |
4977 | unsigned int abbrev_number, bytes_read, i, offset; | |
4978 | struct abbrev_info *abbrev; | |
4979 | struct die_info *die; | |
4980 | ||
6502dd73 | 4981 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
4982 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
4983 | info_ptr += bytes_read; | |
4984 | if (!abbrev_number) | |
4985 | { | |
4986 | die = dwarf_alloc_die (); | |
4987 | die->tag = 0; | |
4988 | die->abbrev = abbrev_number; | |
4989 | die->type = NULL; | |
4990 | *diep = die; | |
639d11d3 | 4991 | *has_children = 0; |
c906108c SS |
4992 | return info_ptr; |
4993 | } | |
4994 | ||
e7c27a73 | 4995 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
4996 | if (!abbrev) |
4997 | { | |
639d11d3 | 4998 | error ("Dwarf Error: could not find abbrev number %d [in module %s]", |
72bf9492 | 4999 | abbrev_number, |
639d11d3 | 5000 | bfd_get_filename (abfd)); |
c906108c SS |
5001 | } |
5002 | die = dwarf_alloc_die (); | |
5003 | die->offset = offset; | |
5004 | die->tag = abbrev->tag; | |
c906108c SS |
5005 | die->abbrev = abbrev_number; |
5006 | die->type = NULL; | |
5007 | ||
5008 | die->num_attrs = abbrev->num_attrs; | |
5009 | die->attrs = (struct attribute *) | |
5010 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
5011 | ||
5012 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5013 | { | |
5014 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
e7c27a73 | 5015 | abfd, info_ptr, cu); |
c906108c SS |
5016 | } |
5017 | ||
5018 | *diep = die; | |
639d11d3 | 5019 | *has_children = abbrev->has_children; |
c906108c SS |
5020 | return info_ptr; |
5021 | } | |
5022 | ||
a8329558 | 5023 | /* Read an attribute value described by an attribute form. */ |
c906108c SS |
5024 | |
5025 | static char * | |
a8329558 | 5026 | read_attribute_value (struct attribute *attr, unsigned form, |
e7c27a73 DJ |
5027 | bfd *abfd, char *info_ptr, |
5028 | struct dwarf2_cu *cu) | |
c906108c | 5029 | { |
e7c27a73 | 5030 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5031 | unsigned int bytes_read; |
5032 | struct dwarf_block *blk; | |
5033 | ||
a8329558 KW |
5034 | attr->form = form; |
5035 | switch (form) | |
c906108c SS |
5036 | { |
5037 | case DW_FORM_addr: | |
5038 | case DW_FORM_ref_addr: | |
e7c27a73 | 5039 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 5040 | info_ptr += bytes_read; |
c906108c SS |
5041 | break; |
5042 | case DW_FORM_block2: | |
5043 | blk = dwarf_alloc_block (); | |
5044 | blk->size = read_2_bytes (abfd, info_ptr); | |
5045 | info_ptr += 2; | |
5046 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5047 | info_ptr += blk->size; | |
5048 | DW_BLOCK (attr) = blk; | |
5049 | break; | |
5050 | case DW_FORM_block4: | |
5051 | blk = dwarf_alloc_block (); | |
5052 | blk->size = read_4_bytes (abfd, info_ptr); | |
5053 | info_ptr += 4; | |
5054 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5055 | info_ptr += blk->size; | |
5056 | DW_BLOCK (attr) = blk; | |
5057 | break; | |
5058 | case DW_FORM_data2: | |
5059 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5060 | info_ptr += 2; | |
5061 | break; | |
5062 | case DW_FORM_data4: | |
5063 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5064 | info_ptr += 4; | |
5065 | break; | |
5066 | case DW_FORM_data8: | |
5067 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5068 | info_ptr += 8; | |
5069 | break; | |
5070 | case DW_FORM_string: | |
5071 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
5072 | info_ptr += bytes_read; | |
5073 | break; | |
4bdf3d34 JJ |
5074 | case DW_FORM_strp: |
5075 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
5076 | &bytes_read); | |
5077 | info_ptr += bytes_read; | |
5078 | break; | |
c906108c SS |
5079 | case DW_FORM_block: |
5080 | blk = dwarf_alloc_block (); | |
5081 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5082 | info_ptr += bytes_read; | |
5083 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5084 | info_ptr += blk->size; | |
5085 | DW_BLOCK (attr) = blk; | |
5086 | break; | |
5087 | case DW_FORM_block1: | |
5088 | blk = dwarf_alloc_block (); | |
5089 | blk->size = read_1_byte (abfd, info_ptr); | |
5090 | info_ptr += 1; | |
5091 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5092 | info_ptr += blk->size; | |
5093 | DW_BLOCK (attr) = blk; | |
5094 | break; | |
5095 | case DW_FORM_data1: | |
5096 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5097 | info_ptr += 1; | |
5098 | break; | |
5099 | case DW_FORM_flag: | |
5100 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5101 | info_ptr += 1; | |
5102 | break; | |
5103 | case DW_FORM_sdata: | |
5104 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
5105 | info_ptr += bytes_read; | |
5106 | break; | |
5107 | case DW_FORM_udata: | |
5108 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5109 | info_ptr += bytes_read; | |
5110 | break; | |
5111 | case DW_FORM_ref1: | |
5112 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5113 | info_ptr += 1; | |
5114 | break; | |
5115 | case DW_FORM_ref2: | |
5116 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5117 | info_ptr += 2; | |
5118 | break; | |
5119 | case DW_FORM_ref4: | |
5120 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5121 | info_ptr += 4; | |
5122 | break; | |
613e1657 KB |
5123 | case DW_FORM_ref8: |
5124 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5125 | info_ptr += 8; | |
5126 | break; | |
c906108c SS |
5127 | case DW_FORM_ref_udata: |
5128 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5129 | info_ptr += bytes_read; | |
5130 | break; | |
c906108c | 5131 | case DW_FORM_indirect: |
a8329558 KW |
5132 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5133 | info_ptr += bytes_read; | |
e7c27a73 | 5134 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 5135 | break; |
c906108c | 5136 | default: |
659b0389 ML |
5137 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", |
5138 | dwarf_form_name (form), | |
5139 | bfd_get_filename (abfd)); | |
c906108c SS |
5140 | } |
5141 | return info_ptr; | |
5142 | } | |
5143 | ||
a8329558 KW |
5144 | /* Read an attribute described by an abbreviated attribute. */ |
5145 | ||
5146 | static char * | |
5147 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, | |
e7c27a73 | 5148 | bfd *abfd, char *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
5149 | { |
5150 | attr->name = abbrev->name; | |
e7c27a73 | 5151 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
5152 | } |
5153 | ||
c906108c SS |
5154 | /* read dwarf information from a buffer */ |
5155 | ||
5156 | static unsigned int | |
fba45db2 | 5157 | read_1_byte (bfd *abfd, char *buf) |
c906108c SS |
5158 | { |
5159 | return bfd_get_8 (abfd, (bfd_byte *) buf); | |
5160 | } | |
5161 | ||
5162 | static int | |
fba45db2 | 5163 | read_1_signed_byte (bfd *abfd, char *buf) |
c906108c SS |
5164 | { |
5165 | return bfd_get_signed_8 (abfd, (bfd_byte *) buf); | |
5166 | } | |
5167 | ||
5168 | static unsigned int | |
fba45db2 | 5169 | read_2_bytes (bfd *abfd, char *buf) |
c906108c SS |
5170 | { |
5171 | return bfd_get_16 (abfd, (bfd_byte *) buf); | |
5172 | } | |
5173 | ||
5174 | static int | |
fba45db2 | 5175 | read_2_signed_bytes (bfd *abfd, char *buf) |
c906108c SS |
5176 | { |
5177 | return bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
5178 | } | |
5179 | ||
5180 | static unsigned int | |
fba45db2 | 5181 | read_4_bytes (bfd *abfd, char *buf) |
c906108c SS |
5182 | { |
5183 | return bfd_get_32 (abfd, (bfd_byte *) buf); | |
5184 | } | |
5185 | ||
5186 | static int | |
fba45db2 | 5187 | read_4_signed_bytes (bfd *abfd, char *buf) |
c906108c SS |
5188 | { |
5189 | return bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
5190 | } | |
5191 | ||
ce5d95e1 | 5192 | static unsigned long |
fba45db2 | 5193 | read_8_bytes (bfd *abfd, char *buf) |
c906108c SS |
5194 | { |
5195 | return bfd_get_64 (abfd, (bfd_byte *) buf); | |
5196 | } | |
5197 | ||
5198 | static CORE_ADDR | |
e7c27a73 | 5199 | read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read) |
c906108c | 5200 | { |
e7c27a73 | 5201 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5202 | CORE_ADDR retval = 0; |
5203 | ||
107d2387 | 5204 | if (cu_header->signed_addr_p) |
c906108c | 5205 | { |
107d2387 AC |
5206 | switch (cu_header->addr_size) |
5207 | { | |
5208 | case 2: | |
5209 | retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
5210 | break; | |
5211 | case 4: | |
5212 | retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
5213 | break; | |
5214 | case 8: | |
5215 | retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf); | |
5216 | break; | |
5217 | default: | |
8e65ff28 | 5218 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5219 | "read_address: bad switch, signed [in module %s]", |
5220 | bfd_get_filename (abfd)); | |
107d2387 AC |
5221 | } |
5222 | } | |
5223 | else | |
5224 | { | |
5225 | switch (cu_header->addr_size) | |
5226 | { | |
5227 | case 2: | |
5228 | retval = bfd_get_16 (abfd, (bfd_byte *) buf); | |
5229 | break; | |
5230 | case 4: | |
5231 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5232 | break; | |
5233 | case 8: | |
5234 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5235 | break; | |
5236 | default: | |
8e65ff28 | 5237 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5238 | "read_address: bad switch, unsigned [in module %s]", |
5239 | bfd_get_filename (abfd)); | |
107d2387 | 5240 | } |
c906108c | 5241 | } |
64367e0a | 5242 | |
107d2387 AC |
5243 | *bytes_read = cu_header->addr_size; |
5244 | return retval; | |
c906108c SS |
5245 | } |
5246 | ||
f7ef9339 | 5247 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
5248 | specification allows the initial length to take up either 4 bytes |
5249 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
5250 | bytes describe the length and all offsets will be 8 bytes in length | |
5251 | instead of 4. | |
5252 | ||
f7ef9339 KB |
5253 | An older, non-standard 64-bit format is also handled by this |
5254 | function. The older format in question stores the initial length | |
5255 | as an 8-byte quantity without an escape value. Lengths greater | |
5256 | than 2^32 aren't very common which means that the initial 4 bytes | |
5257 | is almost always zero. Since a length value of zero doesn't make | |
5258 | sense for the 32-bit format, this initial zero can be considered to | |
5259 | be an escape value which indicates the presence of the older 64-bit | |
5260 | format. As written, the code can't detect (old format) lengths | |
5261 | greater than 4GB. If it becomes necessary to handle lengths somewhat | |
5262 | larger than 4GB, we could allow other small values (such as the | |
5263 | non-sensical values of 1, 2, and 3) to also be used as escape values | |
5264 | indicating the presence of the old format. | |
5265 | ||
613e1657 KB |
5266 | The value returned via bytes_read should be used to increment |
5267 | the relevant pointer after calling read_initial_length(). | |
5268 | ||
5269 | As a side effect, this function sets the fields initial_length_size | |
5270 | and offset_size in cu_header to the values appropriate for the | |
5271 | length field. (The format of the initial length field determines | |
5272 | the width of file offsets to be fetched later with fetch_offset().) | |
5273 | ||
5274 | [ Note: read_initial_length() and read_offset() are based on the | |
5275 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 5276 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
5277 | from: |
5278 | ||
f7ef9339 | 5279 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
5280 | |
5281 | This document is only a draft and is subject to change. (So beware.) | |
5282 | ||
f7ef9339 KB |
5283 | Details regarding the older, non-standard 64-bit format were |
5284 | determined empirically by examining 64-bit ELF files produced | |
5285 | by the SGI toolchain on an IRIX 6.5 machine. | |
5286 | ||
5287 | - Kevin, July 16, 2002 | |
613e1657 KB |
5288 | ] */ |
5289 | ||
5290 | static LONGEST | |
5291 | read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, | |
5292 | int *bytes_read) | |
5293 | { | |
5294 | LONGEST retval = 0; | |
5295 | ||
5296 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5297 | ||
5298 | if (retval == 0xffffffff) | |
5299 | { | |
5300 | retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4); | |
5301 | *bytes_read = 12; | |
5302 | if (cu_header != NULL) | |
5303 | { | |
5304 | cu_header->initial_length_size = 12; | |
5305 | cu_header->offset_size = 8; | |
5306 | } | |
5307 | } | |
f7ef9339 KB |
5308 | else if (retval == 0) |
5309 | { | |
5310 | /* Handle (non-standard) 64-bit DWARF2 formats such as that used | |
5311 | by IRIX. */ | |
5312 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5313 | *bytes_read = 8; | |
5314 | if (cu_header != NULL) | |
5315 | { | |
5316 | cu_header->initial_length_size = 8; | |
5317 | cu_header->offset_size = 8; | |
5318 | } | |
5319 | } | |
613e1657 KB |
5320 | else |
5321 | { | |
5322 | *bytes_read = 4; | |
5323 | if (cu_header != NULL) | |
5324 | { | |
5325 | cu_header->initial_length_size = 4; | |
5326 | cu_header->offset_size = 4; | |
5327 | } | |
5328 | } | |
5329 | ||
5330 | return retval; | |
5331 | } | |
5332 | ||
5333 | /* Read an offset from the data stream. The size of the offset is | |
5334 | given by cu_header->offset_size. */ | |
5335 | ||
5336 | static LONGEST | |
5337 | read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, | |
5338 | int *bytes_read) | |
5339 | { | |
5340 | LONGEST retval = 0; | |
5341 | ||
5342 | switch (cu_header->offset_size) | |
5343 | { | |
5344 | case 4: | |
5345 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5346 | *bytes_read = 4; | |
5347 | break; | |
5348 | case 8: | |
5349 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5350 | *bytes_read = 8; | |
5351 | break; | |
5352 | default: | |
8e65ff28 | 5353 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5354 | "read_offset: bad switch [in module %s]", |
5355 | bfd_get_filename (abfd)); | |
613e1657 KB |
5356 | } |
5357 | ||
5358 | return retval; | |
5359 | } | |
5360 | ||
c906108c | 5361 | static char * |
fba45db2 | 5362 | read_n_bytes (bfd *abfd, char *buf, unsigned int size) |
c906108c SS |
5363 | { |
5364 | /* If the size of a host char is 8 bits, we can return a pointer | |
5365 | to the buffer, otherwise we have to copy the data to a buffer | |
5366 | allocated on the temporary obstack. */ | |
4bdf3d34 | 5367 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 5368 | return buf; |
c906108c SS |
5369 | } |
5370 | ||
5371 | static char * | |
fba45db2 | 5372 | read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
5373 | { |
5374 | /* If the size of a host char is 8 bits, we can return a pointer | |
5375 | to the string, otherwise we have to copy the string to a buffer | |
5376 | allocated on the temporary obstack. */ | |
4bdf3d34 | 5377 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
5378 | if (*buf == '\0') |
5379 | { | |
5380 | *bytes_read_ptr = 1; | |
5381 | return NULL; | |
5382 | } | |
5383 | *bytes_read_ptr = strlen (buf) + 1; | |
5384 | return buf; | |
4bdf3d34 JJ |
5385 | } |
5386 | ||
5387 | static char * | |
5388 | read_indirect_string (bfd *abfd, char *buf, | |
5389 | const struct comp_unit_head *cu_header, | |
5390 | unsigned int *bytes_read_ptr) | |
5391 | { | |
5392 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
5393 | (int *) bytes_read_ptr); | |
c906108c | 5394 | |
6502dd73 | 5395 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 5396 | { |
659b0389 ML |
5397 | error ("DW_FORM_strp used without .debug_str section [in module %s]", |
5398 | bfd_get_filename (abfd)); | |
4bdf3d34 | 5399 | return NULL; |
c906108c | 5400 | } |
6502dd73 | 5401 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 5402 | { |
659b0389 ML |
5403 | error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", |
5404 | bfd_get_filename (abfd)); | |
c906108c SS |
5405 | return NULL; |
5406 | } | |
4bdf3d34 | 5407 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 5408 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 5409 | return NULL; |
6502dd73 | 5410 | return dwarf2_per_objfile->str_buffer + str_offset; |
c906108c SS |
5411 | } |
5412 | ||
ce5d95e1 | 5413 | static unsigned long |
fba45db2 | 5414 | read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c | 5415 | { |
ce5d95e1 JB |
5416 | unsigned long result; |
5417 | unsigned int num_read; | |
c906108c SS |
5418 | int i, shift; |
5419 | unsigned char byte; | |
5420 | ||
5421 | result = 0; | |
5422 | shift = 0; | |
5423 | num_read = 0; | |
5424 | i = 0; | |
5425 | while (1) | |
5426 | { | |
5427 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5428 | buf++; | |
5429 | num_read++; | |
ce5d95e1 | 5430 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
5431 | if ((byte & 128) == 0) |
5432 | { | |
5433 | break; | |
5434 | } | |
5435 | shift += 7; | |
5436 | } | |
5437 | *bytes_read_ptr = num_read; | |
5438 | return result; | |
5439 | } | |
5440 | ||
ce5d95e1 | 5441 | static long |
fba45db2 | 5442 | read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c | 5443 | { |
ce5d95e1 | 5444 | long result; |
c906108c SS |
5445 | int i, shift, size, num_read; |
5446 | unsigned char byte; | |
5447 | ||
5448 | result = 0; | |
5449 | shift = 0; | |
5450 | size = 32; | |
5451 | num_read = 0; | |
5452 | i = 0; | |
5453 | while (1) | |
5454 | { | |
5455 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5456 | buf++; | |
5457 | num_read++; | |
ce5d95e1 | 5458 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
5459 | shift += 7; |
5460 | if ((byte & 128) == 0) | |
5461 | { | |
5462 | break; | |
5463 | } | |
5464 | } | |
5465 | if ((shift < size) && (byte & 0x40)) | |
5466 | { | |
5467 | result |= -(1 << shift); | |
5468 | } | |
5469 | *bytes_read_ptr = num_read; | |
5470 | return result; | |
5471 | } | |
5472 | ||
4bb7a0a7 DJ |
5473 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
5474 | ||
5475 | static char * | |
5476 | skip_leb128 (bfd *abfd, char *buf) | |
5477 | { | |
5478 | int byte; | |
5479 | ||
5480 | while (1) | |
5481 | { | |
5482 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5483 | buf++; | |
5484 | if ((byte & 128) == 0) | |
5485 | return buf; | |
5486 | } | |
5487 | } | |
5488 | ||
c906108c | 5489 | static void |
e142c38c | 5490 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
5491 | { |
5492 | switch (lang) | |
5493 | { | |
5494 | case DW_LANG_C89: | |
5495 | case DW_LANG_C: | |
e142c38c | 5496 | cu->language = language_c; |
c906108c SS |
5497 | break; |
5498 | case DW_LANG_C_plus_plus: | |
e142c38c | 5499 | cu->language = language_cplus; |
c906108c SS |
5500 | break; |
5501 | case DW_LANG_Fortran77: | |
5502 | case DW_LANG_Fortran90: | |
b21b22e0 | 5503 | case DW_LANG_Fortran95: |
e142c38c | 5504 | cu->language = language_fortran; |
c906108c SS |
5505 | break; |
5506 | case DW_LANG_Mips_Assembler: | |
e142c38c | 5507 | cu->language = language_asm; |
c906108c | 5508 | break; |
bebd888e | 5509 | case DW_LANG_Java: |
e142c38c | 5510 | cu->language = language_java; |
bebd888e | 5511 | break; |
c906108c | 5512 | case DW_LANG_Ada83: |
8aaf0b47 | 5513 | case DW_LANG_Ada95: |
c906108c SS |
5514 | case DW_LANG_Cobol74: |
5515 | case DW_LANG_Cobol85: | |
5516 | case DW_LANG_Pascal83: | |
5517 | case DW_LANG_Modula2: | |
5518 | default: | |
e142c38c | 5519 | cu->language = language_minimal; |
c906108c SS |
5520 | break; |
5521 | } | |
e142c38c | 5522 | cu->language_defn = language_def (cu->language); |
c906108c SS |
5523 | } |
5524 | ||
5525 | /* Return the named attribute or NULL if not there. */ | |
5526 | ||
5527 | static struct attribute * | |
e142c38c | 5528 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
5529 | { |
5530 | unsigned int i; | |
5531 | struct attribute *spec = NULL; | |
5532 | ||
5533 | for (i = 0; i < die->num_attrs; ++i) | |
5534 | { | |
5535 | if (die->attrs[i].name == name) | |
5536 | { | |
5537 | return &die->attrs[i]; | |
5538 | } | |
5539 | if (die->attrs[i].name == DW_AT_specification | |
5540 | || die->attrs[i].name == DW_AT_abstract_origin) | |
5541 | spec = &die->attrs[i]; | |
5542 | } | |
5543 | if (spec) | |
5544 | { | |
5545 | struct die_info *ref_die = | |
e142c38c | 5546 | follow_die_ref (dwarf2_get_ref_die_offset (spec, cu)); |
c906108c SS |
5547 | |
5548 | if (ref_die) | |
e142c38c | 5549 | return dwarf2_attr (ref_die, name, cu); |
c906108c | 5550 | } |
c5aa993b | 5551 | |
c906108c SS |
5552 | return NULL; |
5553 | } | |
5554 | ||
05cf31d1 JB |
5555 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
5556 | and holds a non-zero value. This function should only be used for | |
5557 | DW_FORM_flag attributes. */ | |
5558 | ||
5559 | static int | |
5560 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
5561 | { | |
5562 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
5563 | ||
5564 | return (attr && DW_UNSND (attr)); | |
5565 | } | |
5566 | ||
3ca72b44 | 5567 | static int |
e142c38c | 5568 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 5569 | { |
05cf31d1 JB |
5570 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
5571 | which value is non-zero. However, we have to be careful with | |
5572 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
5573 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
5574 | end up accidently finding a declaration attribute that belongs | |
5575 | to a different DIE referenced by the specification attribute, | |
5576 | even though the given DIE does not have a declaration attribute. */ | |
5577 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
5578 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
5579 | } |
5580 | ||
63d06c5c DC |
5581 | /* Return the die giving the specification for DIE, if there is |
5582 | one. */ | |
5583 | ||
5584 | static struct die_info * | |
e142c38c | 5585 | die_specification (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 5586 | { |
e142c38c | 5587 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); |
63d06c5c DC |
5588 | |
5589 | if (spec_attr == NULL) | |
5590 | return NULL; | |
5591 | else | |
e142c38c | 5592 | return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu)); |
63d06c5c | 5593 | } |
c906108c | 5594 | |
debd256d JB |
5595 | /* Free the line_header structure *LH, and any arrays and strings it |
5596 | refers to. */ | |
5597 | static void | |
5598 | free_line_header (struct line_header *lh) | |
5599 | { | |
5600 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 5601 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
5602 | |
5603 | /* Remember that all the lh->file_names[i].name pointers are | |
5604 | pointers into debug_line_buffer, and don't need to be freed. */ | |
5605 | if (lh->file_names) | |
a8bc7b56 | 5606 | xfree (lh->file_names); |
debd256d JB |
5607 | |
5608 | /* Similarly for the include directory names. */ | |
5609 | if (lh->include_dirs) | |
a8bc7b56 | 5610 | xfree (lh->include_dirs); |
debd256d | 5611 | |
a8bc7b56 | 5612 | xfree (lh); |
debd256d JB |
5613 | } |
5614 | ||
5615 | ||
5616 | /* Add an entry to LH's include directory table. */ | |
5617 | static void | |
5618 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 5619 | { |
debd256d JB |
5620 | /* Grow the array if necessary. */ |
5621 | if (lh->include_dirs_size == 0) | |
c5aa993b | 5622 | { |
debd256d JB |
5623 | lh->include_dirs_size = 1; /* for testing */ |
5624 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
5625 | * sizeof (*lh->include_dirs)); | |
5626 | } | |
5627 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
5628 | { | |
5629 | lh->include_dirs_size *= 2; | |
5630 | lh->include_dirs = xrealloc (lh->include_dirs, | |
5631 | (lh->include_dirs_size | |
5632 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 5633 | } |
c906108c | 5634 | |
debd256d JB |
5635 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
5636 | } | |
5637 | ||
5638 | ||
5639 | /* Add an entry to LH's file name table. */ | |
5640 | static void | |
5641 | add_file_name (struct line_header *lh, | |
5642 | char *name, | |
5643 | unsigned int dir_index, | |
5644 | unsigned int mod_time, | |
5645 | unsigned int length) | |
5646 | { | |
5647 | struct file_entry *fe; | |
5648 | ||
5649 | /* Grow the array if necessary. */ | |
5650 | if (lh->file_names_size == 0) | |
5651 | { | |
5652 | lh->file_names_size = 1; /* for testing */ | |
5653 | lh->file_names = xmalloc (lh->file_names_size | |
5654 | * sizeof (*lh->file_names)); | |
5655 | } | |
5656 | else if (lh->num_file_names >= lh->file_names_size) | |
5657 | { | |
5658 | lh->file_names_size *= 2; | |
5659 | lh->file_names = xrealloc (lh->file_names, | |
5660 | (lh->file_names_size | |
5661 | * sizeof (*lh->file_names))); | |
5662 | } | |
5663 | ||
5664 | fe = &lh->file_names[lh->num_file_names++]; | |
5665 | fe->name = name; | |
5666 | fe->dir_index = dir_index; | |
5667 | fe->mod_time = mod_time; | |
5668 | fe->length = length; | |
5669 | } | |
5670 | ||
5671 | ||
5672 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
5673 | .debug_line, according to the endianness of ABFD. Return a pointer |
5674 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
5675 | |
5676 | NOTE: the strings in the include directory and file name tables of | |
5677 | the returned object point into debug_line_buffer, and must not be | |
5678 | freed. */ | |
5679 | static struct line_header * | |
5680 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 5681 | struct dwarf2_cu *cu) |
debd256d JB |
5682 | { |
5683 | struct cleanup *back_to; | |
5684 | struct line_header *lh; | |
5685 | char *line_ptr; | |
5686 | int bytes_read; | |
5687 | int i; | |
5688 | char *cur_dir, *cur_file; | |
5689 | ||
6502dd73 | 5690 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 5691 | { |
4d3c2250 | 5692 | complaint (&symfile_complaints, "missing .debug_line section"); |
debd256d JB |
5693 | return 0; |
5694 | } | |
5695 | ||
5696 | /* Make sure that at least there's room for the total_length field. That | |
5697 | could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 5698 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 5699 | { |
4d3c2250 | 5700 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
5701 | return 0; |
5702 | } | |
5703 | ||
5704 | lh = xmalloc (sizeof (*lh)); | |
5705 | memset (lh, 0, sizeof (*lh)); | |
5706 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
5707 | (void *) lh); | |
5708 | ||
6502dd73 | 5709 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d JB |
5710 | |
5711 | /* read in the header */ | |
5712 | lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read); | |
5713 | line_ptr += bytes_read; | |
6502dd73 DJ |
5714 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
5715 | + dwarf2_per_objfile->line_size)) | |
debd256d | 5716 | { |
4d3c2250 | 5717 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
5718 | return 0; |
5719 | } | |
5720 | lh->statement_program_end = line_ptr + lh->total_length; | |
5721 | lh->version = read_2_bytes (abfd, line_ptr); | |
5722 | line_ptr += 2; | |
e7c27a73 | 5723 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
5724 | line_ptr += bytes_read; |
5725 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
5726 | line_ptr += 1; | |
5727 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
5728 | line_ptr += 1; | |
5729 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
5730 | line_ptr += 1; | |
5731 | lh->line_range = read_1_byte (abfd, line_ptr); | |
5732 | line_ptr += 1; | |
5733 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
5734 | line_ptr += 1; | |
5735 | lh->standard_opcode_lengths | |
5736 | = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char)); | |
5737 | ||
5738 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
5739 | for (i = 1; i < lh->opcode_base; ++i) | |
5740 | { | |
5741 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
5742 | line_ptr += 1; | |
5743 | } | |
5744 | ||
5745 | /* Read directory table */ | |
5746 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
5747 | { | |
5748 | line_ptr += bytes_read; | |
5749 | add_include_dir (lh, cur_dir); | |
5750 | } | |
5751 | line_ptr += bytes_read; | |
5752 | ||
5753 | /* Read file name table */ | |
5754 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
5755 | { | |
5756 | unsigned int dir_index, mod_time, length; | |
5757 | ||
5758 | line_ptr += bytes_read; | |
5759 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5760 | line_ptr += bytes_read; | |
5761 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5762 | line_ptr += bytes_read; | |
5763 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5764 | line_ptr += bytes_read; | |
5765 | ||
5766 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
5767 | } | |
5768 | line_ptr += bytes_read; | |
5769 | lh->statement_program_start = line_ptr; | |
5770 | ||
6502dd73 DJ |
5771 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
5772 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 KB |
5773 | complaint (&symfile_complaints, |
5774 | "line number info header doesn't fit in `.debug_line' section"); | |
debd256d JB |
5775 | |
5776 | discard_cleanups (back_to); | |
5777 | return lh; | |
5778 | } | |
c906108c | 5779 | |
5fb290d7 DJ |
5780 | /* This function exists to work around a bug in certain compilers |
5781 | (particularly GCC 2.95), in which the first line number marker of a | |
5782 | function does not show up until after the prologue, right before | |
5783 | the second line number marker. This function shifts ADDRESS down | |
5784 | to the beginning of the function if necessary, and is called on | |
5785 | addresses passed to record_line. */ | |
5786 | ||
5787 | static CORE_ADDR | |
e142c38c | 5788 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
5789 | { |
5790 | struct function_range *fn; | |
5791 | ||
5792 | /* Find the function_range containing address. */ | |
e142c38c | 5793 | if (!cu->first_fn) |
5fb290d7 DJ |
5794 | return address; |
5795 | ||
e142c38c DJ |
5796 | if (!cu->cached_fn) |
5797 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 5798 | |
e142c38c | 5799 | fn = cu->cached_fn; |
5fb290d7 DJ |
5800 | while (fn) |
5801 | if (fn->lowpc <= address && fn->highpc > address) | |
5802 | goto found; | |
5803 | else | |
5804 | fn = fn->next; | |
5805 | ||
e142c38c DJ |
5806 | fn = cu->first_fn; |
5807 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
5808 | if (fn->lowpc <= address && fn->highpc > address) |
5809 | goto found; | |
5810 | else | |
5811 | fn = fn->next; | |
5812 | ||
5813 | return address; | |
5814 | ||
5815 | found: | |
5816 | if (fn->seen_line) | |
5817 | return address; | |
5818 | if (address != fn->lowpc) | |
4d3c2250 KB |
5819 | complaint (&symfile_complaints, |
5820 | "misplaced first line number at 0x%lx for '%s'", | |
5821 | (unsigned long) address, fn->name); | |
5fb290d7 DJ |
5822 | fn->seen_line = 1; |
5823 | return fn->lowpc; | |
5824 | } | |
5825 | ||
debd256d JB |
5826 | /* Decode the line number information for the compilation unit whose |
5827 | line number info is at OFFSET in the .debug_line section. | |
5828 | The compilation directory of the file is passed in COMP_DIR. */ | |
5829 | ||
c906108c | 5830 | static void |
debd256d | 5831 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
e7c27a73 | 5832 | struct dwarf2_cu *cu) |
c906108c SS |
5833 | { |
5834 | char *line_ptr; | |
5835 | char *line_end; | |
e7c27a73 | 5836 | unsigned int bytes_read; |
c906108c | 5837 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
5838 | CORE_ADDR baseaddr; |
5839 | struct objfile *objfile = cu->objfile; | |
5840 | ||
5841 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 5842 | |
debd256d JB |
5843 | line_ptr = lh->statement_program_start; |
5844 | line_end = lh->statement_program_end; | |
c906108c SS |
5845 | |
5846 | /* Read the statement sequences until there's nothing left. */ | |
5847 | while (line_ptr < line_end) | |
5848 | { | |
5849 | /* state machine registers */ | |
5850 | CORE_ADDR address = 0; | |
5851 | unsigned int file = 1; | |
5852 | unsigned int line = 1; | |
5853 | unsigned int column = 0; | |
debd256d | 5854 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
5855 | int basic_block = 0; |
5856 | int end_sequence = 0; | |
5857 | ||
5858 | /* Start a subfile for the current file of the state machine. */ | |
debd256d | 5859 | if (lh->num_file_names >= file) |
c906108c | 5860 | { |
debd256d JB |
5861 | /* lh->include_dirs and lh->file_names are 0-based, but the |
5862 | directory and file name numbers in the statement program | |
5863 | are 1-based. */ | |
5864 | struct file_entry *fe = &lh->file_names[file - 1]; | |
5865 | char *dir; | |
5866 | if (fe->dir_index) | |
5867 | dir = lh->include_dirs[fe->dir_index - 1]; | |
5868 | else | |
5869 | dir = comp_dir; | |
5870 | dwarf2_start_subfile (fe->name, dir); | |
c906108c SS |
5871 | } |
5872 | ||
5873 | /* Decode the table. */ | |
c5aa993b | 5874 | while (!end_sequence) |
c906108c SS |
5875 | { |
5876 | op_code = read_1_byte (abfd, line_ptr); | |
5877 | line_ptr += 1; | |
9aa1fe7e | 5878 | |
debd256d | 5879 | if (op_code >= lh->opcode_base) |
9aa1fe7e | 5880 | { /* Special operand. */ |
debd256d JB |
5881 | adj_opcode = op_code - lh->opcode_base; |
5882 | address += (adj_opcode / lh->line_range) | |
5883 | * lh->minimum_instruction_length; | |
5884 | line += lh->line_base + (adj_opcode % lh->line_range); | |
9aa1fe7e | 5885 | /* append row to matrix using current values */ |
ddf9f258 | 5886 | record_line (current_subfile, line, |
e142c38c | 5887 | check_cu_functions (address, cu)); |
9aa1fe7e GK |
5888 | basic_block = 1; |
5889 | } | |
5890 | else switch (op_code) | |
c906108c SS |
5891 | { |
5892 | case DW_LNS_extended_op: | |
5893 | line_ptr += 1; /* ignore length */ | |
5894 | extended_op = read_1_byte (abfd, line_ptr); | |
5895 | line_ptr += 1; | |
5896 | switch (extended_op) | |
5897 | { | |
5898 | case DW_LNE_end_sequence: | |
5899 | end_sequence = 1; | |
5fb290d7 | 5900 | record_line (current_subfile, 0, address); |
c906108c SS |
5901 | break; |
5902 | case DW_LNE_set_address: | |
e7c27a73 | 5903 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
5904 | line_ptr += bytes_read; |
5905 | address += baseaddr; | |
c906108c SS |
5906 | break; |
5907 | case DW_LNE_define_file: | |
debd256d JB |
5908 | { |
5909 | char *cur_file; | |
5910 | unsigned int dir_index, mod_time, length; | |
5911 | ||
5912 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
5913 | line_ptr += bytes_read; | |
5914 | dir_index = | |
5915 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5916 | line_ptr += bytes_read; | |
5917 | mod_time = | |
5918 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5919 | line_ptr += bytes_read; | |
5920 | length = | |
5921 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5922 | line_ptr += bytes_read; | |
5923 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
5924 | } | |
c906108c SS |
5925 | break; |
5926 | default: | |
4d3c2250 KB |
5927 | complaint (&symfile_complaints, |
5928 | "mangled .debug_line section"); | |
debd256d | 5929 | return; |
c906108c SS |
5930 | } |
5931 | break; | |
5932 | case DW_LNS_copy: | |
ddf9f258 | 5933 | record_line (current_subfile, line, |
e142c38c | 5934 | check_cu_functions (address, cu)); |
c906108c SS |
5935 | basic_block = 0; |
5936 | break; | |
5937 | case DW_LNS_advance_pc: | |
debd256d | 5938 | address += lh->minimum_instruction_length |
c906108c SS |
5939 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
5940 | line_ptr += bytes_read; | |
5941 | break; | |
5942 | case DW_LNS_advance_line: | |
5943 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
5944 | line_ptr += bytes_read; | |
5945 | break; | |
5946 | case DW_LNS_set_file: | |
debd256d JB |
5947 | { |
5948 | /* lh->include_dirs and lh->file_names are 0-based, | |
5949 | but the directory and file name numbers in the | |
5950 | statement program are 1-based. */ | |
5951 | struct file_entry *fe; | |
5952 | char *dir; | |
5953 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5954 | line_ptr += bytes_read; | |
5955 | fe = &lh->file_names[file - 1]; | |
5956 | if (fe->dir_index) | |
5957 | dir = lh->include_dirs[fe->dir_index - 1]; | |
5958 | else | |
5959 | dir = comp_dir; | |
5960 | dwarf2_start_subfile (fe->name, dir); | |
5961 | } | |
c906108c SS |
5962 | break; |
5963 | case DW_LNS_set_column: | |
5964 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5965 | line_ptr += bytes_read; | |
5966 | break; | |
5967 | case DW_LNS_negate_stmt: | |
5968 | is_stmt = (!is_stmt); | |
5969 | break; | |
5970 | case DW_LNS_set_basic_block: | |
5971 | basic_block = 1; | |
5972 | break; | |
c2c6d25f JM |
5973 | /* Add to the address register of the state machine the |
5974 | address increment value corresponding to special opcode | |
5975 | 255. Ie, this value is scaled by the minimum instruction | |
5976 | length since special opcode 255 would have scaled the | |
5977 | the increment. */ | |
c906108c | 5978 | case DW_LNS_const_add_pc: |
debd256d JB |
5979 | address += (lh->minimum_instruction_length |
5980 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
5981 | break; |
5982 | case DW_LNS_fixed_advance_pc: | |
5983 | address += read_2_bytes (abfd, line_ptr); | |
5984 | line_ptr += 2; | |
5985 | break; | |
9aa1fe7e GK |
5986 | default: |
5987 | { /* Unknown standard opcode, ignore it. */ | |
5988 | int i; | |
debd256d | 5989 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
5990 | { |
5991 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5992 | line_ptr += bytes_read; | |
5993 | } | |
5994 | } | |
c906108c SS |
5995 | } |
5996 | } | |
5997 | } | |
c906108c SS |
5998 | } |
5999 | ||
6000 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
6001 | DIRNAME the name of the source directory which contains FILENAME | |
6002 | or NULL if not known. | |
6003 | This routine tries to keep line numbers from identical absolute and | |
6004 | relative file names in a common subfile. | |
6005 | ||
6006 | Using the `list' example from the GDB testsuite, which resides in | |
6007 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
6008 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
6009 | ||
c5aa993b JM |
6010 | DW_AT_name: /srcdir/list0.c |
6011 | DW_AT_comp_dir: /compdir | |
357e46e7 | 6012 | files.files[0].name: list0.h |
c5aa993b | 6013 | files.files[0].dir: /srcdir |
357e46e7 | 6014 | files.files[1].name: list0.c |
c5aa993b | 6015 | files.files[1].dir: /srcdir |
c906108c SS |
6016 | |
6017 | The line number information for list0.c has to end up in a single | |
6018 | subfile, so that `break /srcdir/list0.c:1' works as expected. */ | |
6019 | ||
6020 | static void | |
fba45db2 | 6021 | dwarf2_start_subfile (char *filename, char *dirname) |
c906108c SS |
6022 | { |
6023 | /* If the filename isn't absolute, try to match an existing subfile | |
6024 | with the full pathname. */ | |
6025 | ||
d5166ae1 | 6026 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
c906108c SS |
6027 | { |
6028 | struct subfile *subfile; | |
6029 | char *fullname = concat (dirname, "/", filename, NULL); | |
6030 | ||
6031 | for (subfile = subfiles; subfile; subfile = subfile->next) | |
6032 | { | |
d5166ae1 | 6033 | if (FILENAME_CMP (subfile->name, fullname) == 0) |
c906108c SS |
6034 | { |
6035 | current_subfile = subfile; | |
b8c9b27d | 6036 | xfree (fullname); |
c906108c SS |
6037 | return; |
6038 | } | |
6039 | } | |
b8c9b27d | 6040 | xfree (fullname); |
c906108c SS |
6041 | } |
6042 | start_subfile (filename, dirname); | |
6043 | } | |
6044 | ||
4c2df51b DJ |
6045 | static void |
6046 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 6047 | struct dwarf2_cu *cu) |
4c2df51b | 6048 | { |
e7c27a73 DJ |
6049 | struct objfile *objfile = cu->objfile; |
6050 | struct comp_unit_head *cu_header = &cu->header; | |
6051 | ||
4c2df51b DJ |
6052 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
6053 | code here to turn a symbol with DW_AT_external and a | |
6054 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
6055 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
6056 | with some versions of binutils) where shared libraries could have | |
6057 | relocations against symbols in their debug information - the | |
6058 | minimal symbol would have the right address, but the debug info | |
6059 | would not. It's no longer necessary, because we will explicitly | |
6060 | apply relocations when we read in the debug information now. */ | |
6061 | ||
6062 | /* A DW_AT_location attribute with no contents indicates that a | |
6063 | variable has been optimized away. */ | |
6064 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
6065 | { | |
6066 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
6067 | return; | |
6068 | } | |
6069 | ||
6070 | /* Handle one degenerate form of location expression specially, to | |
6071 | preserve GDB's previous behavior when section offsets are | |
6072 | specified. If this is just a DW_OP_addr then mark this symbol | |
6073 | as LOC_STATIC. */ | |
6074 | ||
6075 | if (attr_form_is_block (attr) | |
6076 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
6077 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
6078 | { | |
6079 | int dummy; | |
6080 | ||
6081 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 6082 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
4c2df51b DJ |
6083 | fixup_symbol_section (sym, objfile); |
6084 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
6085 | SYMBOL_SECTION (sym)); | |
6086 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
6087 | return; | |
6088 | } | |
6089 | ||
6090 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
6091 | expression evaluator, and use LOC_COMPUTED only when necessary | |
6092 | (i.e. when the value of a register or memory location is | |
6093 | referenced, or a thread-local block, etc.). Then again, it might | |
6094 | not be worthwhile. I'm assuming that it isn't unless performance | |
6095 | or memory numbers show me otherwise. */ | |
6096 | ||
e7c27a73 | 6097 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
6098 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
6099 | } | |
6100 | ||
c906108c SS |
6101 | /* Given a pointer to a DWARF information entry, figure out if we need |
6102 | to make a symbol table entry for it, and if so, create a new entry | |
6103 | and return a pointer to it. | |
6104 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 6105 | used the passed type. */ |
c906108c SS |
6106 | |
6107 | static struct symbol * | |
e7c27a73 | 6108 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 6109 | { |
e7c27a73 | 6110 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6111 | struct symbol *sym = NULL; |
6112 | char *name; | |
6113 | struct attribute *attr = NULL; | |
6114 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
6115 | CORE_ADDR baseaddr; |
6116 | ||
6117 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6118 | |
5c4e30ca | 6119 | if (die->tag != DW_TAG_namespace) |
e142c38c | 6120 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
6121 | else |
6122 | name = TYPE_NAME (type); | |
6123 | ||
c906108c SS |
6124 | if (name) |
6125 | { | |
4a146b47 | 6126 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
6127 | sizeof (struct symbol)); |
6128 | OBJSTAT (objfile, n_syms++); | |
6129 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
6130 | |
6131 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 6132 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 6133 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
6134 | |
6135 | /* Default assumptions. | |
c5aa993b | 6136 | Use the passed type or decode it from the die. */ |
176620f1 | 6137 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
c906108c SS |
6138 | SYMBOL_CLASS (sym) = LOC_STATIC; |
6139 | if (type != NULL) | |
6140 | SYMBOL_TYPE (sym) = type; | |
6141 | else | |
e7c27a73 | 6142 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 6143 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
6144 | if (attr) |
6145 | { | |
6146 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
6147 | } | |
c906108c SS |
6148 | switch (die->tag) |
6149 | { | |
6150 | case DW_TAG_label: | |
e142c38c | 6151 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
6152 | if (attr) |
6153 | { | |
6154 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
6155 | } | |
6156 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
6157 | break; | |
6158 | case DW_TAG_subprogram: | |
6159 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
6160 | finish_block. */ | |
6161 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 6162 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
6163 | if (attr2 && (DW_UNSND (attr2) != 0)) |
6164 | { | |
6165 | add_symbol_to_list (sym, &global_symbols); | |
6166 | } | |
6167 | else | |
6168 | { | |
e142c38c | 6169 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6170 | } |
6171 | break; | |
6172 | case DW_TAG_variable: | |
6173 | /* Compilation with minimal debug info may result in variables | |
6174 | with missing type entries. Change the misleading `void' type | |
6175 | to something sensible. */ | |
6176 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
6177 | SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, | |
6178 | TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
6179 | "<variable, no debug info>", | |
6180 | objfile); | |
e142c38c | 6181 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6182 | if (attr) |
6183 | { | |
e7c27a73 | 6184 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 6185 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
6186 | if (attr2 && (DW_UNSND (attr2) != 0)) |
6187 | add_symbol_to_list (sym, &global_symbols); | |
6188 | else | |
e142c38c | 6189 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6190 | break; |
6191 | } | |
e142c38c | 6192 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6193 | if (attr) |
6194 | { | |
e7c27a73 | 6195 | var_decode_location (attr, sym, cu); |
e142c38c | 6196 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 6197 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 6198 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 6199 | else |
e142c38c | 6200 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6201 | } |
6202 | else | |
6203 | { | |
6204 | /* We do not know the address of this symbol. | |
c5aa993b JM |
6205 | If it is an external symbol and we have type information |
6206 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
6207 | The address of the variable will then be determined from | |
6208 | the minimal symbol table whenever the variable is | |
6209 | referenced. */ | |
e142c38c | 6210 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 6211 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 6212 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
6213 | { |
6214 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
6215 | add_symbol_to_list (sym, &global_symbols); | |
6216 | } | |
6217 | } | |
6218 | break; | |
6219 | case DW_TAG_formal_parameter: | |
e142c38c | 6220 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6221 | if (attr) |
6222 | { | |
e7c27a73 | 6223 | var_decode_location (attr, sym, cu); |
7cf6e574 DJ |
6224 | /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ |
6225 | if (SYMBOL_CLASS (sym) == LOC_COMPUTED) | |
6226 | SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; | |
c906108c | 6227 | } |
e142c38c | 6228 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6229 | if (attr) |
6230 | { | |
e7c27a73 | 6231 | dwarf2_const_value (attr, sym, cu); |
c906108c | 6232 | } |
e142c38c | 6233 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6234 | break; |
6235 | case DW_TAG_unspecified_parameters: | |
6236 | /* From varargs functions; gdb doesn't seem to have any | |
6237 | interest in this information, so just ignore it for now. | |
6238 | (FIXME?) */ | |
6239 | break; | |
6240 | case DW_TAG_class_type: | |
6241 | case DW_TAG_structure_type: | |
6242 | case DW_TAG_union_type: | |
6243 | case DW_TAG_enumeration_type: | |
6244 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 6245 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 6246 | |
63d06c5c DC |
6247 | /* Make sure that the symbol includes appropriate enclosing |
6248 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 6249 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
6250 | the type. */ |
6251 | ||
e142c38c | 6252 | if (cu->language == language_cplus) |
c906108c | 6253 | { |
63d06c5c DC |
6254 | struct type *type = SYMBOL_TYPE (sym); |
6255 | ||
6256 | if (TYPE_TAG_NAME (type) != NULL) | |
6257 | { | |
6258 | /* FIXME: carlton/2003-11-10: Should this use | |
6259 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
6260 | arises further down in this function.) */ |
6261 | /* The type's name is already allocated along with | |
6262 | this objfile, so we don't need to duplicate it | |
6263 | for the symbol. */ | |
6264 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 6265 | } |
c906108c | 6266 | } |
63d06c5c DC |
6267 | |
6268 | { | |
6269 | /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't | |
6270 | really ever be static objects: otherwise, if you try | |
6271 | to, say, break of a class's method and you're in a file | |
6272 | which doesn't mention that class, it won't work unless | |
6273 | the check for all static symbols in lookup_symbol_aux | |
6274 | saves you. See the OtherFileClass tests in | |
6275 | gdb.c++/namespace.exp. */ | |
6276 | ||
6277 | struct pending **list_to_add; | |
6278 | ||
e142c38c DJ |
6279 | list_to_add = (cu->list_in_scope == &file_symbols |
6280 | && cu->language == language_cplus | |
6281 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c DC |
6282 | |
6283 | add_symbol_to_list (sym, list_to_add); | |
6284 | ||
6285 | /* The semantics of C++ state that "struct foo { ... }" also | |
6286 | defines a typedef for "foo". Synthesize a typedef symbol so | |
6287 | that "ptype foo" works as expected. */ | |
e142c38c | 6288 | if (cu->language == language_cplus) |
63d06c5c DC |
6289 | { |
6290 | struct symbol *typedef_sym = (struct symbol *) | |
4a146b47 | 6291 | obstack_alloc (&objfile->objfile_obstack, |
63d06c5c DC |
6292 | sizeof (struct symbol)); |
6293 | *typedef_sym = *sym; | |
6294 | SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; | |
d8151005 DJ |
6295 | /* The symbol's name is already allocated along with |
6296 | this objfile, so we don't need to duplicate it for | |
6297 | the type. */ | |
63d06c5c | 6298 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
d8151005 | 6299 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym); |
63d06c5c DC |
6300 | add_symbol_to_list (typedef_sym, list_to_add); |
6301 | } | |
6302 | } | |
c906108c SS |
6303 | break; |
6304 | case DW_TAG_typedef: | |
63d06c5c DC |
6305 | if (processing_has_namespace_info |
6306 | && processing_current_prefix[0] != '\0') | |
6307 | { | |
4a146b47 | 6308 | SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
6309 | processing_current_prefix, |
6310 | "::", | |
6311 | name); | |
6312 | } | |
6313 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6314 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 6315 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 6316 | break; |
c906108c | 6317 | case DW_TAG_base_type: |
a02abb62 | 6318 | case DW_TAG_subrange_type: |
c906108c | 6319 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 6320 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 6321 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6322 | break; |
6323 | case DW_TAG_enumerator: | |
63d06c5c DC |
6324 | if (processing_has_namespace_info |
6325 | && processing_current_prefix[0] != '\0') | |
6326 | { | |
4a146b47 | 6327 | SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
6328 | processing_current_prefix, |
6329 | "::", | |
6330 | name); | |
6331 | } | |
e142c38c | 6332 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6333 | if (attr) |
6334 | { | |
e7c27a73 | 6335 | dwarf2_const_value (attr, sym, cu); |
c906108c | 6336 | } |
63d06c5c DC |
6337 | { |
6338 | /* NOTE: carlton/2003-11-10: See comment above in the | |
6339 | DW_TAG_class_type, etc. block. */ | |
6340 | ||
6341 | struct pending **list_to_add; | |
6342 | ||
e142c38c DJ |
6343 | list_to_add = (cu->list_in_scope == &file_symbols |
6344 | && cu->language == language_cplus | |
6345 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c DC |
6346 | |
6347 | add_symbol_to_list (sym, list_to_add); | |
6348 | } | |
c906108c | 6349 | break; |
5c4e30ca DC |
6350 | case DW_TAG_namespace: |
6351 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6352 | add_symbol_to_list (sym, &global_symbols); | |
6353 | break; | |
c906108c SS |
6354 | default: |
6355 | /* Not a tag we recognize. Hopefully we aren't processing | |
6356 | trash data, but since we must specifically ignore things | |
6357 | we don't recognize, there is nothing else we should do at | |
6358 | this point. */ | |
4d3c2250 KB |
6359 | complaint (&symfile_complaints, "unsupported tag: '%s'", |
6360 | dwarf_tag_name (die->tag)); | |
c906108c SS |
6361 | break; |
6362 | } | |
6363 | } | |
6364 | return (sym); | |
6365 | } | |
6366 | ||
6367 | /* Copy constant value from an attribute to a symbol. */ | |
6368 | ||
6369 | static void | |
107d2387 | 6370 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 6371 | struct dwarf2_cu *cu) |
c906108c | 6372 | { |
e7c27a73 DJ |
6373 | struct objfile *objfile = cu->objfile; |
6374 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
6375 | struct dwarf_block *blk; |
6376 | ||
6377 | switch (attr->form) | |
6378 | { | |
6379 | case DW_FORM_addr: | |
107d2387 | 6380 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 6381 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
6382 | cu_header->addr_size, |
6383 | TYPE_LENGTH (SYMBOL_TYPE | |
6384 | (sym))); | |
c906108c | 6385 | SYMBOL_VALUE_BYTES (sym) = (char *) |
4a146b47 | 6386 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
6387 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
6388 | it's body - store_unsigned_integer. */ | |
6389 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
6390 | DW_ADDR (attr)); | |
c906108c SS |
6391 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
6392 | break; | |
6393 | case DW_FORM_block1: | |
6394 | case DW_FORM_block2: | |
6395 | case DW_FORM_block4: | |
6396 | case DW_FORM_block: | |
6397 | blk = DW_BLOCK (attr); | |
6398 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 6399 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
6400 | blk->size, |
6401 | TYPE_LENGTH (SYMBOL_TYPE | |
6402 | (sym))); | |
c906108c | 6403 | SYMBOL_VALUE_BYTES (sym) = (char *) |
4a146b47 | 6404 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
6405 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
6406 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
6407 | break; | |
2df3850c JM |
6408 | |
6409 | /* The DW_AT_const_value attributes are supposed to carry the | |
6410 | symbol's value "represented as it would be on the target | |
6411 | architecture." By the time we get here, it's already been | |
6412 | converted to host endianness, so we just need to sign- or | |
6413 | zero-extend it as appropriate. */ | |
6414 | case DW_FORM_data1: | |
6415 | dwarf2_const_value_data (attr, sym, 8); | |
6416 | break; | |
c906108c | 6417 | case DW_FORM_data2: |
2df3850c JM |
6418 | dwarf2_const_value_data (attr, sym, 16); |
6419 | break; | |
c906108c | 6420 | case DW_FORM_data4: |
2df3850c JM |
6421 | dwarf2_const_value_data (attr, sym, 32); |
6422 | break; | |
c906108c | 6423 | case DW_FORM_data8: |
2df3850c JM |
6424 | dwarf2_const_value_data (attr, sym, 64); |
6425 | break; | |
6426 | ||
c906108c | 6427 | case DW_FORM_sdata: |
2df3850c JM |
6428 | SYMBOL_VALUE (sym) = DW_SND (attr); |
6429 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6430 | break; | |
6431 | ||
c906108c SS |
6432 | case DW_FORM_udata: |
6433 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
6434 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6435 | break; | |
2df3850c | 6436 | |
c906108c | 6437 | default: |
4d3c2250 KB |
6438 | complaint (&symfile_complaints, |
6439 | "unsupported const value attribute form: '%s'", | |
6440 | dwarf_form_name (attr->form)); | |
c906108c SS |
6441 | SYMBOL_VALUE (sym) = 0; |
6442 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6443 | break; | |
6444 | } | |
6445 | } | |
6446 | ||
2df3850c JM |
6447 | |
6448 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
6449 | or zero-extend it as appropriate for the symbol's type. */ | |
6450 | static void | |
6451 | dwarf2_const_value_data (struct attribute *attr, | |
6452 | struct symbol *sym, | |
6453 | int bits) | |
6454 | { | |
6455 | LONGEST l = DW_UNSND (attr); | |
6456 | ||
6457 | if (bits < sizeof (l) * 8) | |
6458 | { | |
6459 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
6460 | l &= ((LONGEST) 1 << bits) - 1; | |
6461 | else | |
bf9198f1 | 6462 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
6463 | } |
6464 | ||
6465 | SYMBOL_VALUE (sym) = l; | |
6466 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6467 | } | |
6468 | ||
6469 | ||
c906108c SS |
6470 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
6471 | ||
6472 | static struct type * | |
e7c27a73 | 6473 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6474 | { |
6475 | struct type *type; | |
6476 | struct attribute *type_attr; | |
6477 | struct die_info *type_die; | |
6478 | unsigned int ref; | |
6479 | ||
e142c38c | 6480 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
6481 | if (!type_attr) |
6482 | { | |
6483 | /* A missing DW_AT_type represents a void type. */ | |
e142c38c | 6484 | return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu); |
c906108c SS |
6485 | } |
6486 | else | |
6487 | { | |
e142c38c | 6488 | ref = dwarf2_get_ref_die_offset (type_attr, cu); |
c906108c SS |
6489 | type_die = follow_die_ref (ref); |
6490 | if (!type_die) | |
6491 | { | |
659b0389 | 6492 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", |
e7c27a73 | 6493 | ref, cu->objfile->name); |
c906108c SS |
6494 | return NULL; |
6495 | } | |
6496 | } | |
e7c27a73 | 6497 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
6498 | if (!type) |
6499 | { | |
6500 | dump_die (type_die); | |
659b0389 | 6501 | error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]", |
e7c27a73 | 6502 | cu->objfile->name); |
c906108c SS |
6503 | } |
6504 | return type; | |
6505 | } | |
6506 | ||
6507 | /* Return the containing type of the die in question using its | |
6508 | DW_AT_containing_type attribute. */ | |
6509 | ||
6510 | static struct type * | |
e7c27a73 | 6511 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6512 | { |
6513 | struct type *type = NULL; | |
6514 | struct attribute *type_attr; | |
6515 | struct die_info *type_die = NULL; | |
6516 | unsigned int ref; | |
6517 | ||
e142c38c | 6518 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
6519 | if (type_attr) |
6520 | { | |
e142c38c | 6521 | ref = dwarf2_get_ref_die_offset (type_attr, cu); |
c906108c SS |
6522 | type_die = follow_die_ref (ref); |
6523 | if (!type_die) | |
6524 | { | |
659b0389 | 6525 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref, |
e7c27a73 | 6526 | cu->objfile->name); |
c906108c SS |
6527 | return NULL; |
6528 | } | |
e7c27a73 | 6529 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
6530 | } |
6531 | if (!type) | |
6532 | { | |
6533 | if (type_die) | |
6534 | dump_die (type_die); | |
659b0389 | 6535 | error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]", |
e7c27a73 | 6536 | cu->objfile->name); |
c906108c SS |
6537 | } |
6538 | return type; | |
6539 | } | |
6540 | ||
6541 | #if 0 | |
6542 | static struct type * | |
e7c27a73 | 6543 | type_at_offset (unsigned int offset, struct dwarf2_cu *cu) |
c906108c SS |
6544 | { |
6545 | struct die_info *die; | |
6546 | struct type *type; | |
6547 | ||
6548 | die = follow_die_ref (offset); | |
6549 | if (!die) | |
6550 | { | |
6551 | error ("Dwarf Error: Cannot find type referent at offset %d.", offset); | |
6552 | return NULL; | |
6553 | } | |
e7c27a73 | 6554 | type = tag_type_to_type (die, cu); |
c906108c SS |
6555 | return type; |
6556 | } | |
6557 | #endif | |
6558 | ||
6559 | static struct type * | |
e7c27a73 | 6560 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6561 | { |
6562 | if (die->type) | |
6563 | { | |
6564 | return die->type; | |
6565 | } | |
6566 | else | |
6567 | { | |
e7c27a73 | 6568 | read_type_die (die, cu); |
c906108c SS |
6569 | if (!die->type) |
6570 | { | |
6571 | dump_die (die); | |
659b0389 | 6572 | error ("Dwarf Error: Cannot find type of die [in module %s]", |
e7c27a73 | 6573 | cu->objfile->name); |
c906108c SS |
6574 | } |
6575 | return die->type; | |
6576 | } | |
6577 | } | |
6578 | ||
6579 | static void | |
e7c27a73 | 6580 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6581 | { |
e142c38c | 6582 | char *prefix = determine_prefix (die, cu); |
63d06c5c DC |
6583 | const char *old_prefix = processing_current_prefix; |
6584 | struct cleanup *back_to = make_cleanup (xfree, prefix); | |
6585 | processing_current_prefix = prefix; | |
6586 | ||
c906108c SS |
6587 | switch (die->tag) |
6588 | { | |
6589 | case DW_TAG_class_type: | |
6590 | case DW_TAG_structure_type: | |
6591 | case DW_TAG_union_type: | |
134d01f1 | 6592 | read_structure_type (die, cu); |
c906108c SS |
6593 | break; |
6594 | case DW_TAG_enumeration_type: | |
134d01f1 | 6595 | read_enumeration_type (die, cu); |
c906108c SS |
6596 | break; |
6597 | case DW_TAG_subprogram: | |
6598 | case DW_TAG_subroutine_type: | |
e7c27a73 | 6599 | read_subroutine_type (die, cu); |
c906108c SS |
6600 | break; |
6601 | case DW_TAG_array_type: | |
e7c27a73 | 6602 | read_array_type (die, cu); |
c906108c SS |
6603 | break; |
6604 | case DW_TAG_pointer_type: | |
e7c27a73 | 6605 | read_tag_pointer_type (die, cu); |
c906108c SS |
6606 | break; |
6607 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 6608 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
6609 | break; |
6610 | case DW_TAG_reference_type: | |
e7c27a73 | 6611 | read_tag_reference_type (die, cu); |
c906108c SS |
6612 | break; |
6613 | case DW_TAG_const_type: | |
e7c27a73 | 6614 | read_tag_const_type (die, cu); |
c906108c SS |
6615 | break; |
6616 | case DW_TAG_volatile_type: | |
e7c27a73 | 6617 | read_tag_volatile_type (die, cu); |
c906108c SS |
6618 | break; |
6619 | case DW_TAG_string_type: | |
e7c27a73 | 6620 | read_tag_string_type (die, cu); |
c906108c SS |
6621 | break; |
6622 | case DW_TAG_typedef: | |
e7c27a73 | 6623 | read_typedef (die, cu); |
c906108c | 6624 | break; |
a02abb62 JB |
6625 | case DW_TAG_subrange_type: |
6626 | read_subrange_type (die, cu); | |
6627 | break; | |
c906108c | 6628 | case DW_TAG_base_type: |
e7c27a73 | 6629 | read_base_type (die, cu); |
c906108c SS |
6630 | break; |
6631 | default: | |
4d3c2250 KB |
6632 | complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'", |
6633 | dwarf_tag_name (die->tag)); | |
c906108c SS |
6634 | break; |
6635 | } | |
63d06c5c DC |
6636 | |
6637 | processing_current_prefix = old_prefix; | |
6638 | do_cleanups (back_to); | |
6639 | } | |
6640 | ||
fdde2d81 DC |
6641 | /* Return the name of the namespace/class that DIE is defined within, |
6642 | or "" if we can't tell. The caller should xfree the result. */ | |
6643 | ||
6644 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
6645 | therein) for an example of how to use this function to deal with | |
6646 | DW_AT_specification. */ | |
6647 | ||
6648 | static char * | |
e142c38c | 6649 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
6650 | { |
6651 | struct die_info *parent; | |
6652 | ||
e142c38c | 6653 | if (cu->language != language_cplus) |
63d06c5c DC |
6654 | return NULL; |
6655 | ||
6656 | parent = die->parent; | |
6657 | ||
6658 | if (parent == NULL) | |
6659 | { | |
8176b9b8 | 6660 | return xstrdup (""); |
63d06c5c DC |
6661 | } |
6662 | else | |
6663 | { | |
63d06c5c DC |
6664 | switch (parent->tag) { |
6665 | case DW_TAG_namespace: | |
6666 | { | |
8176b9b8 DC |
6667 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
6668 | before doing this check? */ | |
6669 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) | |
6670 | { | |
6671 | return xstrdup (TYPE_TAG_NAME (parent->type)); | |
6672 | } | |
6673 | else | |
6674 | { | |
6675 | int dummy; | |
6676 | char *parent_prefix = determine_prefix (parent, cu); | |
6677 | char *retval = typename_concat (parent_prefix, | |
6678 | namespace_name (parent, &dummy, | |
6679 | cu)); | |
6680 | xfree (parent_prefix); | |
6681 | return retval; | |
6682 | } | |
63d06c5c DC |
6683 | } |
6684 | break; | |
6685 | case DW_TAG_class_type: | |
6686 | case DW_TAG_structure_type: | |
6687 | { | |
8176b9b8 | 6688 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) |
63d06c5c | 6689 | { |
8176b9b8 | 6690 | return xstrdup (TYPE_TAG_NAME (parent->type)); |
63d06c5c DC |
6691 | } |
6692 | else | |
8176b9b8 DC |
6693 | { |
6694 | const char *old_prefix = processing_current_prefix; | |
6695 | char *new_prefix = determine_prefix (parent, cu); | |
6696 | char *retval; | |
6697 | ||
6698 | processing_current_prefix = new_prefix; | |
6699 | retval = determine_class_name (parent, cu); | |
6700 | processing_current_prefix = old_prefix; | |
6701 | ||
6702 | xfree (new_prefix); | |
6703 | return retval; | |
6704 | } | |
63d06c5c | 6705 | } |
63d06c5c | 6706 | default: |
8176b9b8 | 6707 | return determine_prefix (parent, cu); |
63d06c5c | 6708 | } |
63d06c5c DC |
6709 | } |
6710 | } | |
6711 | ||
6712 | /* Return a newly-allocated string formed by concatenating PREFIX, | |
6713 | "::", and SUFFIX, except that if PREFIX is NULL or the empty | |
6714 | string, just return a copy of SUFFIX. */ | |
6715 | ||
6716 | static char * | |
6717 | typename_concat (const char *prefix, const char *suffix) | |
6718 | { | |
6719 | if (prefix == NULL || prefix[0] == '\0') | |
6720 | return xstrdup (suffix); | |
6721 | else | |
6722 | { | |
6723 | char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1); | |
6724 | ||
6725 | strcpy (retval, prefix); | |
6726 | strcat (retval, "::"); | |
6727 | strcat (retval, suffix); | |
6728 | ||
6729 | return retval; | |
6730 | } | |
6731 | } | |
6732 | ||
c906108c | 6733 | static struct type * |
e7c27a73 | 6734 | dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu) |
c906108c | 6735 | { |
e7c27a73 DJ |
6736 | struct objfile *objfile = cu->objfile; |
6737 | ||
c906108c SS |
6738 | /* FIXME - this should not produce a new (struct type *) |
6739 | every time. It should cache base types. */ | |
6740 | struct type *type; | |
6741 | switch (encoding) | |
6742 | { | |
6743 | case DW_ATE_address: | |
e142c38c | 6744 | type = dwarf2_fundamental_type (objfile, FT_VOID, cu); |
c906108c SS |
6745 | return type; |
6746 | case DW_ATE_boolean: | |
e142c38c | 6747 | type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu); |
c906108c SS |
6748 | return type; |
6749 | case DW_ATE_complex_float: | |
6750 | if (size == 16) | |
6751 | { | |
e142c38c | 6752 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu); |
c906108c SS |
6753 | } |
6754 | else | |
6755 | { | |
e142c38c | 6756 | type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu); |
c906108c SS |
6757 | } |
6758 | return type; | |
6759 | case DW_ATE_float: | |
6760 | if (size == 8) | |
6761 | { | |
e142c38c | 6762 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
c906108c SS |
6763 | } |
6764 | else | |
6765 | { | |
e142c38c | 6766 | type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
c906108c SS |
6767 | } |
6768 | return type; | |
6769 | case DW_ATE_signed: | |
6770 | switch (size) | |
6771 | { | |
6772 | case 1: | |
e142c38c | 6773 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
6774 | break; |
6775 | case 2: | |
e142c38c | 6776 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu); |
c906108c SS |
6777 | break; |
6778 | default: | |
6779 | case 4: | |
e142c38c | 6780 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
6781 | break; |
6782 | } | |
6783 | return type; | |
6784 | case DW_ATE_signed_char: | |
e142c38c | 6785 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
6786 | return type; |
6787 | case DW_ATE_unsigned: | |
6788 | switch (size) | |
6789 | { | |
6790 | case 1: | |
e142c38c | 6791 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
6792 | break; |
6793 | case 2: | |
e142c38c | 6794 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu); |
c906108c SS |
6795 | break; |
6796 | default: | |
6797 | case 4: | |
e142c38c | 6798 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu); |
c906108c SS |
6799 | break; |
6800 | } | |
6801 | return type; | |
6802 | case DW_ATE_unsigned_char: | |
e142c38c | 6803 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
6804 | return type; |
6805 | default: | |
e142c38c | 6806 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
6807 | return type; |
6808 | } | |
6809 | } | |
6810 | ||
6811 | #if 0 | |
6812 | struct die_info * | |
fba45db2 | 6813 | copy_die (struct die_info *old_die) |
c906108c SS |
6814 | { |
6815 | struct die_info *new_die; | |
6816 | int i, num_attrs; | |
6817 | ||
6818 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
6819 | memset (new_die, 0, sizeof (struct die_info)); | |
6820 | ||
6821 | new_die->tag = old_die->tag; | |
6822 | new_die->has_children = old_die->has_children; | |
6823 | new_die->abbrev = old_die->abbrev; | |
6824 | new_die->offset = old_die->offset; | |
6825 | new_die->type = NULL; | |
6826 | ||
6827 | num_attrs = old_die->num_attrs; | |
6828 | new_die->num_attrs = num_attrs; | |
6829 | new_die->attrs = (struct attribute *) | |
6830 | xmalloc (num_attrs * sizeof (struct attribute)); | |
6831 | ||
6832 | for (i = 0; i < old_die->num_attrs; ++i) | |
6833 | { | |
6834 | new_die->attrs[i].name = old_die->attrs[i].name; | |
6835 | new_die->attrs[i].form = old_die->attrs[i].form; | |
6836 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
6837 | } | |
6838 | ||
6839 | new_die->next = NULL; | |
6840 | return new_die; | |
6841 | } | |
6842 | #endif | |
6843 | ||
6844 | /* Return sibling of die, NULL if no sibling. */ | |
6845 | ||
f9aca02d | 6846 | static struct die_info * |
fba45db2 | 6847 | sibling_die (struct die_info *die) |
c906108c | 6848 | { |
639d11d3 | 6849 | return die->sibling; |
c906108c SS |
6850 | } |
6851 | ||
6852 | /* Get linkage name of a die, return NULL if not found. */ | |
6853 | ||
6854 | static char * | |
e142c38c | 6855 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6856 | { |
6857 | struct attribute *attr; | |
6858 | ||
e142c38c | 6859 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
6860 | if (attr && DW_STRING (attr)) |
6861 | return DW_STRING (attr); | |
e142c38c | 6862 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
6863 | if (attr && DW_STRING (attr)) |
6864 | return DW_STRING (attr); | |
6865 | return NULL; | |
6866 | } | |
6867 | ||
9219021c DC |
6868 | /* Get name of a die, return NULL if not found. */ |
6869 | ||
6870 | static char * | |
e142c38c | 6871 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
6872 | { |
6873 | struct attribute *attr; | |
6874 | ||
e142c38c | 6875 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
6876 | if (attr && DW_STRING (attr)) |
6877 | return DW_STRING (attr); | |
6878 | return NULL; | |
6879 | } | |
6880 | ||
6881 | /* Return the die that this die in an extension of, or NULL if there | |
6882 | is none. */ | |
6883 | ||
6884 | static struct die_info * | |
e142c38c | 6885 | dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
6886 | { |
6887 | struct attribute *attr; | |
6888 | struct die_info *extension_die; | |
6889 | unsigned int ref; | |
6890 | ||
e142c38c | 6891 | attr = dwarf2_attr (die, DW_AT_extension, cu); |
9219021c DC |
6892 | if (attr == NULL) |
6893 | return NULL; | |
6894 | ||
e142c38c | 6895 | ref = dwarf2_get_ref_die_offset (attr, cu); |
9219021c DC |
6896 | extension_die = follow_die_ref (ref); |
6897 | if (!extension_die) | |
6898 | { | |
6899 | error ("Dwarf Error: Cannot find referent at offset %d.", ref); | |
6900 | } | |
6901 | ||
6902 | return extension_die; | |
6903 | } | |
6904 | ||
c906108c SS |
6905 | /* Convert a DIE tag into its string name. */ |
6906 | ||
6907 | static char * | |
aa1ee363 | 6908 | dwarf_tag_name (unsigned tag) |
c906108c SS |
6909 | { |
6910 | switch (tag) | |
6911 | { | |
6912 | case DW_TAG_padding: | |
6913 | return "DW_TAG_padding"; | |
6914 | case DW_TAG_array_type: | |
6915 | return "DW_TAG_array_type"; | |
6916 | case DW_TAG_class_type: | |
6917 | return "DW_TAG_class_type"; | |
6918 | case DW_TAG_entry_point: | |
6919 | return "DW_TAG_entry_point"; | |
6920 | case DW_TAG_enumeration_type: | |
6921 | return "DW_TAG_enumeration_type"; | |
6922 | case DW_TAG_formal_parameter: | |
6923 | return "DW_TAG_formal_parameter"; | |
6924 | case DW_TAG_imported_declaration: | |
6925 | return "DW_TAG_imported_declaration"; | |
6926 | case DW_TAG_label: | |
6927 | return "DW_TAG_label"; | |
6928 | case DW_TAG_lexical_block: | |
6929 | return "DW_TAG_lexical_block"; | |
6930 | case DW_TAG_member: | |
6931 | return "DW_TAG_member"; | |
6932 | case DW_TAG_pointer_type: | |
6933 | return "DW_TAG_pointer_type"; | |
6934 | case DW_TAG_reference_type: | |
6935 | return "DW_TAG_reference_type"; | |
6936 | case DW_TAG_compile_unit: | |
6937 | return "DW_TAG_compile_unit"; | |
6938 | case DW_TAG_string_type: | |
6939 | return "DW_TAG_string_type"; | |
6940 | case DW_TAG_structure_type: | |
6941 | return "DW_TAG_structure_type"; | |
6942 | case DW_TAG_subroutine_type: | |
6943 | return "DW_TAG_subroutine_type"; | |
6944 | case DW_TAG_typedef: | |
6945 | return "DW_TAG_typedef"; | |
6946 | case DW_TAG_union_type: | |
6947 | return "DW_TAG_union_type"; | |
6948 | case DW_TAG_unspecified_parameters: | |
6949 | return "DW_TAG_unspecified_parameters"; | |
6950 | case DW_TAG_variant: | |
6951 | return "DW_TAG_variant"; | |
6952 | case DW_TAG_common_block: | |
6953 | return "DW_TAG_common_block"; | |
6954 | case DW_TAG_common_inclusion: | |
6955 | return "DW_TAG_common_inclusion"; | |
6956 | case DW_TAG_inheritance: | |
6957 | return "DW_TAG_inheritance"; | |
6958 | case DW_TAG_inlined_subroutine: | |
6959 | return "DW_TAG_inlined_subroutine"; | |
6960 | case DW_TAG_module: | |
6961 | return "DW_TAG_module"; | |
6962 | case DW_TAG_ptr_to_member_type: | |
6963 | return "DW_TAG_ptr_to_member_type"; | |
6964 | case DW_TAG_set_type: | |
6965 | return "DW_TAG_set_type"; | |
6966 | case DW_TAG_subrange_type: | |
6967 | return "DW_TAG_subrange_type"; | |
6968 | case DW_TAG_with_stmt: | |
6969 | return "DW_TAG_with_stmt"; | |
6970 | case DW_TAG_access_declaration: | |
6971 | return "DW_TAG_access_declaration"; | |
6972 | case DW_TAG_base_type: | |
6973 | return "DW_TAG_base_type"; | |
6974 | case DW_TAG_catch_block: | |
6975 | return "DW_TAG_catch_block"; | |
6976 | case DW_TAG_const_type: | |
6977 | return "DW_TAG_const_type"; | |
6978 | case DW_TAG_constant: | |
6979 | return "DW_TAG_constant"; | |
6980 | case DW_TAG_enumerator: | |
6981 | return "DW_TAG_enumerator"; | |
6982 | case DW_TAG_file_type: | |
6983 | return "DW_TAG_file_type"; | |
6984 | case DW_TAG_friend: | |
6985 | return "DW_TAG_friend"; | |
6986 | case DW_TAG_namelist: | |
6987 | return "DW_TAG_namelist"; | |
6988 | case DW_TAG_namelist_item: | |
6989 | return "DW_TAG_namelist_item"; | |
6990 | case DW_TAG_packed_type: | |
6991 | return "DW_TAG_packed_type"; | |
6992 | case DW_TAG_subprogram: | |
6993 | return "DW_TAG_subprogram"; | |
6994 | case DW_TAG_template_type_param: | |
6995 | return "DW_TAG_template_type_param"; | |
6996 | case DW_TAG_template_value_param: | |
6997 | return "DW_TAG_template_value_param"; | |
6998 | case DW_TAG_thrown_type: | |
6999 | return "DW_TAG_thrown_type"; | |
7000 | case DW_TAG_try_block: | |
7001 | return "DW_TAG_try_block"; | |
7002 | case DW_TAG_variant_part: | |
7003 | return "DW_TAG_variant_part"; | |
7004 | case DW_TAG_variable: | |
7005 | return "DW_TAG_variable"; | |
7006 | case DW_TAG_volatile_type: | |
7007 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
7008 | case DW_TAG_dwarf_procedure: |
7009 | return "DW_TAG_dwarf_procedure"; | |
7010 | case DW_TAG_restrict_type: | |
7011 | return "DW_TAG_restrict_type"; | |
7012 | case DW_TAG_interface_type: | |
7013 | return "DW_TAG_interface_type"; | |
7014 | case DW_TAG_namespace: | |
7015 | return "DW_TAG_namespace"; | |
7016 | case DW_TAG_imported_module: | |
7017 | return "DW_TAG_imported_module"; | |
7018 | case DW_TAG_unspecified_type: | |
7019 | return "DW_TAG_unspecified_type"; | |
7020 | case DW_TAG_partial_unit: | |
7021 | return "DW_TAG_partial_unit"; | |
7022 | case DW_TAG_imported_unit: | |
7023 | return "DW_TAG_imported_unit"; | |
c906108c SS |
7024 | case DW_TAG_MIPS_loop: |
7025 | return "DW_TAG_MIPS_loop"; | |
7026 | case DW_TAG_format_label: | |
7027 | return "DW_TAG_format_label"; | |
7028 | case DW_TAG_function_template: | |
7029 | return "DW_TAG_function_template"; | |
7030 | case DW_TAG_class_template: | |
7031 | return "DW_TAG_class_template"; | |
7032 | default: | |
7033 | return "DW_TAG_<unknown>"; | |
7034 | } | |
7035 | } | |
7036 | ||
7037 | /* Convert a DWARF attribute code into its string name. */ | |
7038 | ||
7039 | static char * | |
aa1ee363 | 7040 | dwarf_attr_name (unsigned attr) |
c906108c SS |
7041 | { |
7042 | switch (attr) | |
7043 | { | |
7044 | case DW_AT_sibling: | |
7045 | return "DW_AT_sibling"; | |
7046 | case DW_AT_location: | |
7047 | return "DW_AT_location"; | |
7048 | case DW_AT_name: | |
7049 | return "DW_AT_name"; | |
7050 | case DW_AT_ordering: | |
7051 | return "DW_AT_ordering"; | |
7052 | case DW_AT_subscr_data: | |
7053 | return "DW_AT_subscr_data"; | |
7054 | case DW_AT_byte_size: | |
7055 | return "DW_AT_byte_size"; | |
7056 | case DW_AT_bit_offset: | |
7057 | return "DW_AT_bit_offset"; | |
7058 | case DW_AT_bit_size: | |
7059 | return "DW_AT_bit_size"; | |
7060 | case DW_AT_element_list: | |
7061 | return "DW_AT_element_list"; | |
7062 | case DW_AT_stmt_list: | |
7063 | return "DW_AT_stmt_list"; | |
7064 | case DW_AT_low_pc: | |
7065 | return "DW_AT_low_pc"; | |
7066 | case DW_AT_high_pc: | |
7067 | return "DW_AT_high_pc"; | |
7068 | case DW_AT_language: | |
7069 | return "DW_AT_language"; | |
7070 | case DW_AT_member: | |
7071 | return "DW_AT_member"; | |
7072 | case DW_AT_discr: | |
7073 | return "DW_AT_discr"; | |
7074 | case DW_AT_discr_value: | |
7075 | return "DW_AT_discr_value"; | |
7076 | case DW_AT_visibility: | |
7077 | return "DW_AT_visibility"; | |
7078 | case DW_AT_import: | |
7079 | return "DW_AT_import"; | |
7080 | case DW_AT_string_length: | |
7081 | return "DW_AT_string_length"; | |
7082 | case DW_AT_common_reference: | |
7083 | return "DW_AT_common_reference"; | |
7084 | case DW_AT_comp_dir: | |
7085 | return "DW_AT_comp_dir"; | |
7086 | case DW_AT_const_value: | |
7087 | return "DW_AT_const_value"; | |
7088 | case DW_AT_containing_type: | |
7089 | return "DW_AT_containing_type"; | |
7090 | case DW_AT_default_value: | |
7091 | return "DW_AT_default_value"; | |
7092 | case DW_AT_inline: | |
7093 | return "DW_AT_inline"; | |
7094 | case DW_AT_is_optional: | |
7095 | return "DW_AT_is_optional"; | |
7096 | case DW_AT_lower_bound: | |
7097 | return "DW_AT_lower_bound"; | |
7098 | case DW_AT_producer: | |
7099 | return "DW_AT_producer"; | |
7100 | case DW_AT_prototyped: | |
7101 | return "DW_AT_prototyped"; | |
7102 | case DW_AT_return_addr: | |
7103 | return "DW_AT_return_addr"; | |
7104 | case DW_AT_start_scope: | |
7105 | return "DW_AT_start_scope"; | |
7106 | case DW_AT_stride_size: | |
7107 | return "DW_AT_stride_size"; | |
7108 | case DW_AT_upper_bound: | |
7109 | return "DW_AT_upper_bound"; | |
7110 | case DW_AT_abstract_origin: | |
7111 | return "DW_AT_abstract_origin"; | |
7112 | case DW_AT_accessibility: | |
7113 | return "DW_AT_accessibility"; | |
7114 | case DW_AT_address_class: | |
7115 | return "DW_AT_address_class"; | |
7116 | case DW_AT_artificial: | |
7117 | return "DW_AT_artificial"; | |
7118 | case DW_AT_base_types: | |
7119 | return "DW_AT_base_types"; | |
7120 | case DW_AT_calling_convention: | |
7121 | return "DW_AT_calling_convention"; | |
7122 | case DW_AT_count: | |
7123 | return "DW_AT_count"; | |
7124 | case DW_AT_data_member_location: | |
7125 | return "DW_AT_data_member_location"; | |
7126 | case DW_AT_decl_column: | |
7127 | return "DW_AT_decl_column"; | |
7128 | case DW_AT_decl_file: | |
7129 | return "DW_AT_decl_file"; | |
7130 | case DW_AT_decl_line: | |
7131 | return "DW_AT_decl_line"; | |
7132 | case DW_AT_declaration: | |
7133 | return "DW_AT_declaration"; | |
7134 | case DW_AT_discr_list: | |
7135 | return "DW_AT_discr_list"; | |
7136 | case DW_AT_encoding: | |
7137 | return "DW_AT_encoding"; | |
7138 | case DW_AT_external: | |
7139 | return "DW_AT_external"; | |
7140 | case DW_AT_frame_base: | |
7141 | return "DW_AT_frame_base"; | |
7142 | case DW_AT_friend: | |
7143 | return "DW_AT_friend"; | |
7144 | case DW_AT_identifier_case: | |
7145 | return "DW_AT_identifier_case"; | |
7146 | case DW_AT_macro_info: | |
7147 | return "DW_AT_macro_info"; | |
7148 | case DW_AT_namelist_items: | |
7149 | return "DW_AT_namelist_items"; | |
7150 | case DW_AT_priority: | |
7151 | return "DW_AT_priority"; | |
7152 | case DW_AT_segment: | |
7153 | return "DW_AT_segment"; | |
7154 | case DW_AT_specification: | |
7155 | return "DW_AT_specification"; | |
7156 | case DW_AT_static_link: | |
7157 | return "DW_AT_static_link"; | |
7158 | case DW_AT_type: | |
7159 | return "DW_AT_type"; | |
7160 | case DW_AT_use_location: | |
7161 | return "DW_AT_use_location"; | |
7162 | case DW_AT_variable_parameter: | |
7163 | return "DW_AT_variable_parameter"; | |
7164 | case DW_AT_virtuality: | |
7165 | return "DW_AT_virtuality"; | |
7166 | case DW_AT_vtable_elem_location: | |
7167 | return "DW_AT_vtable_elem_location"; | |
d9fa45fe DC |
7168 | case DW_AT_allocated: |
7169 | return "DW_AT_allocated"; | |
7170 | case DW_AT_associated: | |
7171 | return "DW_AT_associated"; | |
7172 | case DW_AT_data_location: | |
7173 | return "DW_AT_data_location"; | |
7174 | case DW_AT_stride: | |
7175 | return "DW_AT_stride"; | |
7176 | case DW_AT_entry_pc: | |
7177 | return "DW_AT_entry_pc"; | |
7178 | case DW_AT_use_UTF8: | |
7179 | return "DW_AT_use_UTF8"; | |
7180 | case DW_AT_extension: | |
7181 | return "DW_AT_extension"; | |
7182 | case DW_AT_ranges: | |
7183 | return "DW_AT_ranges"; | |
7184 | case DW_AT_trampoline: | |
7185 | return "DW_AT_trampoline"; | |
7186 | case DW_AT_call_column: | |
7187 | return "DW_AT_call_column"; | |
7188 | case DW_AT_call_file: | |
7189 | return "DW_AT_call_file"; | |
7190 | case DW_AT_call_line: | |
7191 | return "DW_AT_call_line"; | |
c906108c SS |
7192 | #ifdef MIPS |
7193 | case DW_AT_MIPS_fde: | |
7194 | return "DW_AT_MIPS_fde"; | |
7195 | case DW_AT_MIPS_loop_begin: | |
7196 | return "DW_AT_MIPS_loop_begin"; | |
7197 | case DW_AT_MIPS_tail_loop_begin: | |
7198 | return "DW_AT_MIPS_tail_loop_begin"; | |
7199 | case DW_AT_MIPS_epilog_begin: | |
7200 | return "DW_AT_MIPS_epilog_begin"; | |
7201 | case DW_AT_MIPS_loop_unroll_factor: | |
7202 | return "DW_AT_MIPS_loop_unroll_factor"; | |
7203 | case DW_AT_MIPS_software_pipeline_depth: | |
7204 | return "DW_AT_MIPS_software_pipeline_depth"; | |
e0a4f5a1 | 7205 | #endif |
c906108c SS |
7206 | case DW_AT_MIPS_linkage_name: |
7207 | return "DW_AT_MIPS_linkage_name"; | |
c906108c SS |
7208 | |
7209 | case DW_AT_sf_names: | |
7210 | return "DW_AT_sf_names"; | |
7211 | case DW_AT_src_info: | |
7212 | return "DW_AT_src_info"; | |
7213 | case DW_AT_mac_info: | |
7214 | return "DW_AT_mac_info"; | |
7215 | case DW_AT_src_coords: | |
7216 | return "DW_AT_src_coords"; | |
7217 | case DW_AT_body_begin: | |
7218 | return "DW_AT_body_begin"; | |
7219 | case DW_AT_body_end: | |
7220 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
7221 | case DW_AT_GNU_vector: |
7222 | return "DW_AT_GNU_vector"; | |
c906108c SS |
7223 | default: |
7224 | return "DW_AT_<unknown>"; | |
7225 | } | |
7226 | } | |
7227 | ||
7228 | /* Convert a DWARF value form code into its string name. */ | |
7229 | ||
7230 | static char * | |
aa1ee363 | 7231 | dwarf_form_name (unsigned form) |
c906108c SS |
7232 | { |
7233 | switch (form) | |
7234 | { | |
7235 | case DW_FORM_addr: | |
7236 | return "DW_FORM_addr"; | |
7237 | case DW_FORM_block2: | |
7238 | return "DW_FORM_block2"; | |
7239 | case DW_FORM_block4: | |
7240 | return "DW_FORM_block4"; | |
7241 | case DW_FORM_data2: | |
7242 | return "DW_FORM_data2"; | |
7243 | case DW_FORM_data4: | |
7244 | return "DW_FORM_data4"; | |
7245 | case DW_FORM_data8: | |
7246 | return "DW_FORM_data8"; | |
7247 | case DW_FORM_string: | |
7248 | return "DW_FORM_string"; | |
7249 | case DW_FORM_block: | |
7250 | return "DW_FORM_block"; | |
7251 | case DW_FORM_block1: | |
7252 | return "DW_FORM_block1"; | |
7253 | case DW_FORM_data1: | |
7254 | return "DW_FORM_data1"; | |
7255 | case DW_FORM_flag: | |
7256 | return "DW_FORM_flag"; | |
7257 | case DW_FORM_sdata: | |
7258 | return "DW_FORM_sdata"; | |
7259 | case DW_FORM_strp: | |
7260 | return "DW_FORM_strp"; | |
7261 | case DW_FORM_udata: | |
7262 | return "DW_FORM_udata"; | |
7263 | case DW_FORM_ref_addr: | |
7264 | return "DW_FORM_ref_addr"; | |
7265 | case DW_FORM_ref1: | |
7266 | return "DW_FORM_ref1"; | |
7267 | case DW_FORM_ref2: | |
7268 | return "DW_FORM_ref2"; | |
7269 | case DW_FORM_ref4: | |
7270 | return "DW_FORM_ref4"; | |
7271 | case DW_FORM_ref8: | |
7272 | return "DW_FORM_ref8"; | |
7273 | case DW_FORM_ref_udata: | |
7274 | return "DW_FORM_ref_udata"; | |
7275 | case DW_FORM_indirect: | |
7276 | return "DW_FORM_indirect"; | |
7277 | default: | |
7278 | return "DW_FORM_<unknown>"; | |
7279 | } | |
7280 | } | |
7281 | ||
7282 | /* Convert a DWARF stack opcode into its string name. */ | |
7283 | ||
7284 | static char * | |
aa1ee363 | 7285 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
7286 | { |
7287 | switch (op) | |
7288 | { | |
7289 | case DW_OP_addr: | |
7290 | return "DW_OP_addr"; | |
7291 | case DW_OP_deref: | |
7292 | return "DW_OP_deref"; | |
7293 | case DW_OP_const1u: | |
7294 | return "DW_OP_const1u"; | |
7295 | case DW_OP_const1s: | |
7296 | return "DW_OP_const1s"; | |
7297 | case DW_OP_const2u: | |
7298 | return "DW_OP_const2u"; | |
7299 | case DW_OP_const2s: | |
7300 | return "DW_OP_const2s"; | |
7301 | case DW_OP_const4u: | |
7302 | return "DW_OP_const4u"; | |
7303 | case DW_OP_const4s: | |
7304 | return "DW_OP_const4s"; | |
7305 | case DW_OP_const8u: | |
7306 | return "DW_OP_const8u"; | |
7307 | case DW_OP_const8s: | |
7308 | return "DW_OP_const8s"; | |
7309 | case DW_OP_constu: | |
7310 | return "DW_OP_constu"; | |
7311 | case DW_OP_consts: | |
7312 | return "DW_OP_consts"; | |
7313 | case DW_OP_dup: | |
7314 | return "DW_OP_dup"; | |
7315 | case DW_OP_drop: | |
7316 | return "DW_OP_drop"; | |
7317 | case DW_OP_over: | |
7318 | return "DW_OP_over"; | |
7319 | case DW_OP_pick: | |
7320 | return "DW_OP_pick"; | |
7321 | case DW_OP_swap: | |
7322 | return "DW_OP_swap"; | |
7323 | case DW_OP_rot: | |
7324 | return "DW_OP_rot"; | |
7325 | case DW_OP_xderef: | |
7326 | return "DW_OP_xderef"; | |
7327 | case DW_OP_abs: | |
7328 | return "DW_OP_abs"; | |
7329 | case DW_OP_and: | |
7330 | return "DW_OP_and"; | |
7331 | case DW_OP_div: | |
7332 | return "DW_OP_div"; | |
7333 | case DW_OP_minus: | |
7334 | return "DW_OP_minus"; | |
7335 | case DW_OP_mod: | |
7336 | return "DW_OP_mod"; | |
7337 | case DW_OP_mul: | |
7338 | return "DW_OP_mul"; | |
7339 | case DW_OP_neg: | |
7340 | return "DW_OP_neg"; | |
7341 | case DW_OP_not: | |
7342 | return "DW_OP_not"; | |
7343 | case DW_OP_or: | |
7344 | return "DW_OP_or"; | |
7345 | case DW_OP_plus: | |
7346 | return "DW_OP_plus"; | |
7347 | case DW_OP_plus_uconst: | |
7348 | return "DW_OP_plus_uconst"; | |
7349 | case DW_OP_shl: | |
7350 | return "DW_OP_shl"; | |
7351 | case DW_OP_shr: | |
7352 | return "DW_OP_shr"; | |
7353 | case DW_OP_shra: | |
7354 | return "DW_OP_shra"; | |
7355 | case DW_OP_xor: | |
7356 | return "DW_OP_xor"; | |
7357 | case DW_OP_bra: | |
7358 | return "DW_OP_bra"; | |
7359 | case DW_OP_eq: | |
7360 | return "DW_OP_eq"; | |
7361 | case DW_OP_ge: | |
7362 | return "DW_OP_ge"; | |
7363 | case DW_OP_gt: | |
7364 | return "DW_OP_gt"; | |
7365 | case DW_OP_le: | |
7366 | return "DW_OP_le"; | |
7367 | case DW_OP_lt: | |
7368 | return "DW_OP_lt"; | |
7369 | case DW_OP_ne: | |
7370 | return "DW_OP_ne"; | |
7371 | case DW_OP_skip: | |
7372 | return "DW_OP_skip"; | |
7373 | case DW_OP_lit0: | |
7374 | return "DW_OP_lit0"; | |
7375 | case DW_OP_lit1: | |
7376 | return "DW_OP_lit1"; | |
7377 | case DW_OP_lit2: | |
7378 | return "DW_OP_lit2"; | |
7379 | case DW_OP_lit3: | |
7380 | return "DW_OP_lit3"; | |
7381 | case DW_OP_lit4: | |
7382 | return "DW_OP_lit4"; | |
7383 | case DW_OP_lit5: | |
7384 | return "DW_OP_lit5"; | |
7385 | case DW_OP_lit6: | |
7386 | return "DW_OP_lit6"; | |
7387 | case DW_OP_lit7: | |
7388 | return "DW_OP_lit7"; | |
7389 | case DW_OP_lit8: | |
7390 | return "DW_OP_lit8"; | |
7391 | case DW_OP_lit9: | |
7392 | return "DW_OP_lit9"; | |
7393 | case DW_OP_lit10: | |
7394 | return "DW_OP_lit10"; | |
7395 | case DW_OP_lit11: | |
7396 | return "DW_OP_lit11"; | |
7397 | case DW_OP_lit12: | |
7398 | return "DW_OP_lit12"; | |
7399 | case DW_OP_lit13: | |
7400 | return "DW_OP_lit13"; | |
7401 | case DW_OP_lit14: | |
7402 | return "DW_OP_lit14"; | |
7403 | case DW_OP_lit15: | |
7404 | return "DW_OP_lit15"; | |
7405 | case DW_OP_lit16: | |
7406 | return "DW_OP_lit16"; | |
7407 | case DW_OP_lit17: | |
7408 | return "DW_OP_lit17"; | |
7409 | case DW_OP_lit18: | |
7410 | return "DW_OP_lit18"; | |
7411 | case DW_OP_lit19: | |
7412 | return "DW_OP_lit19"; | |
7413 | case DW_OP_lit20: | |
7414 | return "DW_OP_lit20"; | |
7415 | case DW_OP_lit21: | |
7416 | return "DW_OP_lit21"; | |
7417 | case DW_OP_lit22: | |
7418 | return "DW_OP_lit22"; | |
7419 | case DW_OP_lit23: | |
7420 | return "DW_OP_lit23"; | |
7421 | case DW_OP_lit24: | |
7422 | return "DW_OP_lit24"; | |
7423 | case DW_OP_lit25: | |
7424 | return "DW_OP_lit25"; | |
7425 | case DW_OP_lit26: | |
7426 | return "DW_OP_lit26"; | |
7427 | case DW_OP_lit27: | |
7428 | return "DW_OP_lit27"; | |
7429 | case DW_OP_lit28: | |
7430 | return "DW_OP_lit28"; | |
7431 | case DW_OP_lit29: | |
7432 | return "DW_OP_lit29"; | |
7433 | case DW_OP_lit30: | |
7434 | return "DW_OP_lit30"; | |
7435 | case DW_OP_lit31: | |
7436 | return "DW_OP_lit31"; | |
7437 | case DW_OP_reg0: | |
7438 | return "DW_OP_reg0"; | |
7439 | case DW_OP_reg1: | |
7440 | return "DW_OP_reg1"; | |
7441 | case DW_OP_reg2: | |
7442 | return "DW_OP_reg2"; | |
7443 | case DW_OP_reg3: | |
7444 | return "DW_OP_reg3"; | |
7445 | case DW_OP_reg4: | |
7446 | return "DW_OP_reg4"; | |
7447 | case DW_OP_reg5: | |
7448 | return "DW_OP_reg5"; | |
7449 | case DW_OP_reg6: | |
7450 | return "DW_OP_reg6"; | |
7451 | case DW_OP_reg7: | |
7452 | return "DW_OP_reg7"; | |
7453 | case DW_OP_reg8: | |
7454 | return "DW_OP_reg8"; | |
7455 | case DW_OP_reg9: | |
7456 | return "DW_OP_reg9"; | |
7457 | case DW_OP_reg10: | |
7458 | return "DW_OP_reg10"; | |
7459 | case DW_OP_reg11: | |
7460 | return "DW_OP_reg11"; | |
7461 | case DW_OP_reg12: | |
7462 | return "DW_OP_reg12"; | |
7463 | case DW_OP_reg13: | |
7464 | return "DW_OP_reg13"; | |
7465 | case DW_OP_reg14: | |
7466 | return "DW_OP_reg14"; | |
7467 | case DW_OP_reg15: | |
7468 | return "DW_OP_reg15"; | |
7469 | case DW_OP_reg16: | |
7470 | return "DW_OP_reg16"; | |
7471 | case DW_OP_reg17: | |
7472 | return "DW_OP_reg17"; | |
7473 | case DW_OP_reg18: | |
7474 | return "DW_OP_reg18"; | |
7475 | case DW_OP_reg19: | |
7476 | return "DW_OP_reg19"; | |
7477 | case DW_OP_reg20: | |
7478 | return "DW_OP_reg20"; | |
7479 | case DW_OP_reg21: | |
7480 | return "DW_OP_reg21"; | |
7481 | case DW_OP_reg22: | |
7482 | return "DW_OP_reg22"; | |
7483 | case DW_OP_reg23: | |
7484 | return "DW_OP_reg23"; | |
7485 | case DW_OP_reg24: | |
7486 | return "DW_OP_reg24"; | |
7487 | case DW_OP_reg25: | |
7488 | return "DW_OP_reg25"; | |
7489 | case DW_OP_reg26: | |
7490 | return "DW_OP_reg26"; | |
7491 | case DW_OP_reg27: | |
7492 | return "DW_OP_reg27"; | |
7493 | case DW_OP_reg28: | |
7494 | return "DW_OP_reg28"; | |
7495 | case DW_OP_reg29: | |
7496 | return "DW_OP_reg29"; | |
7497 | case DW_OP_reg30: | |
7498 | return "DW_OP_reg30"; | |
7499 | case DW_OP_reg31: | |
7500 | return "DW_OP_reg31"; | |
7501 | case DW_OP_breg0: | |
7502 | return "DW_OP_breg0"; | |
7503 | case DW_OP_breg1: | |
7504 | return "DW_OP_breg1"; | |
7505 | case DW_OP_breg2: | |
7506 | return "DW_OP_breg2"; | |
7507 | case DW_OP_breg3: | |
7508 | return "DW_OP_breg3"; | |
7509 | case DW_OP_breg4: | |
7510 | return "DW_OP_breg4"; | |
7511 | case DW_OP_breg5: | |
7512 | return "DW_OP_breg5"; | |
7513 | case DW_OP_breg6: | |
7514 | return "DW_OP_breg6"; | |
7515 | case DW_OP_breg7: | |
7516 | return "DW_OP_breg7"; | |
7517 | case DW_OP_breg8: | |
7518 | return "DW_OP_breg8"; | |
7519 | case DW_OP_breg9: | |
7520 | return "DW_OP_breg9"; | |
7521 | case DW_OP_breg10: | |
7522 | return "DW_OP_breg10"; | |
7523 | case DW_OP_breg11: | |
7524 | return "DW_OP_breg11"; | |
7525 | case DW_OP_breg12: | |
7526 | return "DW_OP_breg12"; | |
7527 | case DW_OP_breg13: | |
7528 | return "DW_OP_breg13"; | |
7529 | case DW_OP_breg14: | |
7530 | return "DW_OP_breg14"; | |
7531 | case DW_OP_breg15: | |
7532 | return "DW_OP_breg15"; | |
7533 | case DW_OP_breg16: | |
7534 | return "DW_OP_breg16"; | |
7535 | case DW_OP_breg17: | |
7536 | return "DW_OP_breg17"; | |
7537 | case DW_OP_breg18: | |
7538 | return "DW_OP_breg18"; | |
7539 | case DW_OP_breg19: | |
7540 | return "DW_OP_breg19"; | |
7541 | case DW_OP_breg20: | |
7542 | return "DW_OP_breg20"; | |
7543 | case DW_OP_breg21: | |
7544 | return "DW_OP_breg21"; | |
7545 | case DW_OP_breg22: | |
7546 | return "DW_OP_breg22"; | |
7547 | case DW_OP_breg23: | |
7548 | return "DW_OP_breg23"; | |
7549 | case DW_OP_breg24: | |
7550 | return "DW_OP_breg24"; | |
7551 | case DW_OP_breg25: | |
7552 | return "DW_OP_breg25"; | |
7553 | case DW_OP_breg26: | |
7554 | return "DW_OP_breg26"; | |
7555 | case DW_OP_breg27: | |
7556 | return "DW_OP_breg27"; | |
7557 | case DW_OP_breg28: | |
7558 | return "DW_OP_breg28"; | |
7559 | case DW_OP_breg29: | |
7560 | return "DW_OP_breg29"; | |
7561 | case DW_OP_breg30: | |
7562 | return "DW_OP_breg30"; | |
7563 | case DW_OP_breg31: | |
7564 | return "DW_OP_breg31"; | |
7565 | case DW_OP_regx: | |
7566 | return "DW_OP_regx"; | |
7567 | case DW_OP_fbreg: | |
7568 | return "DW_OP_fbreg"; | |
7569 | case DW_OP_bregx: | |
7570 | return "DW_OP_bregx"; | |
7571 | case DW_OP_piece: | |
7572 | return "DW_OP_piece"; | |
7573 | case DW_OP_deref_size: | |
7574 | return "DW_OP_deref_size"; | |
7575 | case DW_OP_xderef_size: | |
7576 | return "DW_OP_xderef_size"; | |
7577 | case DW_OP_nop: | |
7578 | return "DW_OP_nop"; | |
ed348acc EZ |
7579 | /* DWARF 3 extensions. */ |
7580 | case DW_OP_push_object_address: | |
7581 | return "DW_OP_push_object_address"; | |
7582 | case DW_OP_call2: | |
7583 | return "DW_OP_call2"; | |
7584 | case DW_OP_call4: | |
7585 | return "DW_OP_call4"; | |
7586 | case DW_OP_call_ref: | |
7587 | return "DW_OP_call_ref"; | |
7588 | /* GNU extensions. */ | |
7589 | case DW_OP_GNU_push_tls_address: | |
7590 | return "DW_OP_GNU_push_tls_address"; | |
c906108c SS |
7591 | default: |
7592 | return "OP_<unknown>"; | |
7593 | } | |
7594 | } | |
7595 | ||
7596 | static char * | |
fba45db2 | 7597 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
7598 | { |
7599 | if (mybool) | |
7600 | return "TRUE"; | |
7601 | else | |
7602 | return "FALSE"; | |
7603 | } | |
7604 | ||
7605 | /* Convert a DWARF type code into its string name. */ | |
7606 | ||
7607 | static char * | |
aa1ee363 | 7608 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
7609 | { |
7610 | switch (enc) | |
7611 | { | |
7612 | case DW_ATE_address: | |
7613 | return "DW_ATE_address"; | |
7614 | case DW_ATE_boolean: | |
7615 | return "DW_ATE_boolean"; | |
7616 | case DW_ATE_complex_float: | |
7617 | return "DW_ATE_complex_float"; | |
7618 | case DW_ATE_float: | |
7619 | return "DW_ATE_float"; | |
7620 | case DW_ATE_signed: | |
7621 | return "DW_ATE_signed"; | |
7622 | case DW_ATE_signed_char: | |
7623 | return "DW_ATE_signed_char"; | |
7624 | case DW_ATE_unsigned: | |
7625 | return "DW_ATE_unsigned"; | |
7626 | case DW_ATE_unsigned_char: | |
7627 | return "DW_ATE_unsigned_char"; | |
d9fa45fe DC |
7628 | case DW_ATE_imaginary_float: |
7629 | return "DW_ATE_imaginary_float"; | |
c906108c SS |
7630 | default: |
7631 | return "DW_ATE_<unknown>"; | |
7632 | } | |
7633 | } | |
7634 | ||
7635 | /* Convert a DWARF call frame info operation to its string name. */ | |
7636 | ||
7637 | #if 0 | |
7638 | static char * | |
aa1ee363 | 7639 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
7640 | { |
7641 | switch (cfi_opc) | |
7642 | { | |
7643 | case DW_CFA_advance_loc: | |
7644 | return "DW_CFA_advance_loc"; | |
7645 | case DW_CFA_offset: | |
7646 | return "DW_CFA_offset"; | |
7647 | case DW_CFA_restore: | |
7648 | return "DW_CFA_restore"; | |
7649 | case DW_CFA_nop: | |
7650 | return "DW_CFA_nop"; | |
7651 | case DW_CFA_set_loc: | |
7652 | return "DW_CFA_set_loc"; | |
7653 | case DW_CFA_advance_loc1: | |
7654 | return "DW_CFA_advance_loc1"; | |
7655 | case DW_CFA_advance_loc2: | |
7656 | return "DW_CFA_advance_loc2"; | |
7657 | case DW_CFA_advance_loc4: | |
7658 | return "DW_CFA_advance_loc4"; | |
7659 | case DW_CFA_offset_extended: | |
7660 | return "DW_CFA_offset_extended"; | |
7661 | case DW_CFA_restore_extended: | |
7662 | return "DW_CFA_restore_extended"; | |
7663 | case DW_CFA_undefined: | |
7664 | return "DW_CFA_undefined"; | |
7665 | case DW_CFA_same_value: | |
7666 | return "DW_CFA_same_value"; | |
7667 | case DW_CFA_register: | |
7668 | return "DW_CFA_register"; | |
7669 | case DW_CFA_remember_state: | |
7670 | return "DW_CFA_remember_state"; | |
7671 | case DW_CFA_restore_state: | |
7672 | return "DW_CFA_restore_state"; | |
7673 | case DW_CFA_def_cfa: | |
7674 | return "DW_CFA_def_cfa"; | |
7675 | case DW_CFA_def_cfa_register: | |
7676 | return "DW_CFA_def_cfa_register"; | |
7677 | case DW_CFA_def_cfa_offset: | |
7678 | return "DW_CFA_def_cfa_offset"; | |
985cb1a3 JM |
7679 | |
7680 | /* DWARF 3 */ | |
7681 | case DW_CFA_def_cfa_expression: | |
7682 | return "DW_CFA_def_cfa_expression"; | |
7683 | case DW_CFA_expression: | |
7684 | return "DW_CFA_expression"; | |
7685 | case DW_CFA_offset_extended_sf: | |
7686 | return "DW_CFA_offset_extended_sf"; | |
7687 | case DW_CFA_def_cfa_sf: | |
7688 | return "DW_CFA_def_cfa_sf"; | |
7689 | case DW_CFA_def_cfa_offset_sf: | |
7690 | return "DW_CFA_def_cfa_offset_sf"; | |
7691 | ||
c906108c SS |
7692 | /* SGI/MIPS specific */ |
7693 | case DW_CFA_MIPS_advance_loc8: | |
7694 | return "DW_CFA_MIPS_advance_loc8"; | |
985cb1a3 JM |
7695 | |
7696 | /* GNU extensions */ | |
7697 | case DW_CFA_GNU_window_save: | |
7698 | return "DW_CFA_GNU_window_save"; | |
7699 | case DW_CFA_GNU_args_size: | |
7700 | return "DW_CFA_GNU_args_size"; | |
7701 | case DW_CFA_GNU_negative_offset_extended: | |
7702 | return "DW_CFA_GNU_negative_offset_extended"; | |
7703 | ||
c906108c SS |
7704 | default: |
7705 | return "DW_CFA_<unknown>"; | |
7706 | } | |
7707 | } | |
7708 | #endif | |
7709 | ||
f9aca02d | 7710 | static void |
fba45db2 | 7711 | dump_die (struct die_info *die) |
c906108c SS |
7712 | { |
7713 | unsigned int i; | |
7714 | ||
48cd0caa | 7715 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 7716 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 7717 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 7718 | dwarf_bool_name (die->child != NULL)); |
c906108c | 7719 | |
48cd0caa | 7720 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
7721 | for (i = 0; i < die->num_attrs; ++i) |
7722 | { | |
48cd0caa | 7723 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
7724 | dwarf_attr_name (die->attrs[i].name), |
7725 | dwarf_form_name (die->attrs[i].form)); | |
7726 | switch (die->attrs[i].form) | |
7727 | { | |
7728 | case DW_FORM_ref_addr: | |
7729 | case DW_FORM_addr: | |
48cd0caa | 7730 | fprintf_unfiltered (gdb_stderr, "address: "); |
c906108c SS |
7731 | print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); |
7732 | break; | |
7733 | case DW_FORM_block2: | |
7734 | case DW_FORM_block4: | |
7735 | case DW_FORM_block: | |
7736 | case DW_FORM_block1: | |
48cd0caa | 7737 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c SS |
7738 | break; |
7739 | case DW_FORM_data1: | |
7740 | case DW_FORM_data2: | |
7741 | case DW_FORM_data4: | |
ce5d95e1 | 7742 | case DW_FORM_data8: |
c906108c SS |
7743 | case DW_FORM_ref1: |
7744 | case DW_FORM_ref2: | |
7745 | case DW_FORM_ref4: | |
7746 | case DW_FORM_udata: | |
7747 | case DW_FORM_sdata: | |
48cd0caa | 7748 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
7749 | break; |
7750 | case DW_FORM_string: | |
4bdf3d34 | 7751 | case DW_FORM_strp: |
48cd0caa | 7752 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 7753 | DW_STRING (&die->attrs[i]) |
c5aa993b | 7754 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
7755 | break; |
7756 | case DW_FORM_flag: | |
7757 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 7758 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 7759 | else |
48cd0caa | 7760 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 7761 | break; |
a8329558 KW |
7762 | case DW_FORM_indirect: |
7763 | /* the reader will have reduced the indirect form to | |
7764 | the "base form" so this form should not occur */ | |
48cd0caa | 7765 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 7766 | break; |
c906108c | 7767 | default: |
48cd0caa | 7768 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 7769 | die->attrs[i].form); |
c906108c | 7770 | } |
48cd0caa | 7771 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
7772 | } |
7773 | } | |
7774 | ||
f9aca02d | 7775 | static void |
fba45db2 | 7776 | dump_die_list (struct die_info *die) |
c906108c SS |
7777 | { |
7778 | while (die) | |
7779 | { | |
7780 | dump_die (die); | |
639d11d3 DC |
7781 | if (die->child != NULL) |
7782 | dump_die_list (die->child); | |
7783 | if (die->sibling != NULL) | |
7784 | dump_die_list (die->sibling); | |
c906108c SS |
7785 | } |
7786 | } | |
7787 | ||
f9aca02d | 7788 | static void |
fba45db2 | 7789 | store_in_ref_table (unsigned int offset, struct die_info *die) |
c906108c SS |
7790 | { |
7791 | int h; | |
7792 | struct die_info *old; | |
7793 | ||
7794 | h = (offset % REF_HASH_SIZE); | |
7795 | old = die_ref_table[h]; | |
7796 | die->next_ref = old; | |
7797 | die_ref_table[h] = die; | |
7798 | } | |
7799 | ||
7800 | ||
7801 | static void | |
fba45db2 | 7802 | dwarf2_empty_hash_tables (void) |
c906108c SS |
7803 | { |
7804 | memset (die_ref_table, 0, sizeof (die_ref_table)); | |
7805 | } | |
7806 | ||
7807 | static unsigned int | |
e142c38c | 7808 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
7809 | { |
7810 | unsigned int result = 0; | |
7811 | ||
7812 | switch (attr->form) | |
7813 | { | |
7814 | case DW_FORM_ref_addr: | |
7815 | result = DW_ADDR (attr); | |
7816 | break; | |
7817 | case DW_FORM_ref1: | |
7818 | case DW_FORM_ref2: | |
7819 | case DW_FORM_ref4: | |
613e1657 | 7820 | case DW_FORM_ref8: |
c906108c | 7821 | case DW_FORM_ref_udata: |
e142c38c | 7822 | result = cu->header.offset + DW_UNSND (attr); |
c906108c SS |
7823 | break; |
7824 | default: | |
4d3c2250 KB |
7825 | complaint (&symfile_complaints, |
7826 | "unsupported die ref attribute form: '%s'", | |
7827 | dwarf_form_name (attr->form)); | |
c906108c SS |
7828 | } |
7829 | return result; | |
7830 | } | |
7831 | ||
a02abb62 JB |
7832 | /* Return the constant value held by the given attribute. Return -1 |
7833 | if the value held by the attribute is not constant. */ | |
7834 | ||
7835 | static int | |
7836 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
7837 | { | |
7838 | if (attr->form == DW_FORM_sdata) | |
7839 | return DW_SND (attr); | |
7840 | else if (attr->form == DW_FORM_udata | |
7841 | || attr->form == DW_FORM_data1 | |
7842 | || attr->form == DW_FORM_data2 | |
7843 | || attr->form == DW_FORM_data4 | |
7844 | || attr->form == DW_FORM_data8) | |
7845 | return DW_UNSND (attr); | |
7846 | else | |
7847 | { | |
7848 | complaint (&symfile_complaints, "Attribute value is not a constant (%s)", | |
7849 | dwarf_form_name (attr->form)); | |
7850 | return default_value; | |
7851 | } | |
7852 | } | |
7853 | ||
f9aca02d | 7854 | static struct die_info * |
fba45db2 | 7855 | follow_die_ref (unsigned int offset) |
c906108c SS |
7856 | { |
7857 | struct die_info *die; | |
7858 | int h; | |
7859 | ||
7860 | h = (offset % REF_HASH_SIZE); | |
7861 | die = die_ref_table[h]; | |
7862 | while (die) | |
7863 | { | |
7864 | if (die->offset == offset) | |
7865 | { | |
7866 | return die; | |
7867 | } | |
7868 | die = die->next_ref; | |
7869 | } | |
7870 | return NULL; | |
7871 | } | |
7872 | ||
7873 | static struct type * | |
e142c38c DJ |
7874 | dwarf2_fundamental_type (struct objfile *objfile, int typeid, |
7875 | struct dwarf2_cu *cu) | |
c906108c SS |
7876 | { |
7877 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
7878 | { | |
659b0389 ML |
7879 | error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]", |
7880 | typeid, objfile->name); | |
c906108c SS |
7881 | } |
7882 | ||
7883 | /* Look for this particular type in the fundamental type vector. If | |
7884 | one is not found, create and install one appropriate for the | |
7885 | current language and the current target machine. */ | |
7886 | ||
e142c38c | 7887 | if (cu->ftypes[typeid] == NULL) |
c906108c | 7888 | { |
e142c38c | 7889 | cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid); |
c906108c SS |
7890 | } |
7891 | ||
e142c38c | 7892 | return (cu->ftypes[typeid]); |
c906108c SS |
7893 | } |
7894 | ||
7895 | /* Decode simple location descriptions. | |
7896 | Given a pointer to a dwarf block that defines a location, compute | |
7897 | the location and return the value. | |
7898 | ||
4cecd739 DJ |
7899 | NOTE drow/2003-11-18: This function is called in two situations |
7900 | now: for the address of static or global variables (partial symbols | |
7901 | only) and for offsets into structures which are expected to be | |
7902 | (more or less) constant. The partial symbol case should go away, | |
7903 | and only the constant case should remain. That will let this | |
7904 | function complain more accurately. A few special modes are allowed | |
7905 | without complaint for global variables (for instance, global | |
7906 | register values and thread-local values). | |
c906108c SS |
7907 | |
7908 | A location description containing no operations indicates that the | |
4cecd739 | 7909 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
7910 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
7911 | callers will only want a very basic result and this can become a | |
7912 | complaint. | |
c906108c SS |
7913 | |
7914 | When the result is a register number, the global isreg flag is set, | |
7915 | otherwise it is cleared. | |
7916 | ||
c906108c SS |
7917 | Note that stack[0] is unused except as a default error return. |
7918 | Note that stack overflow is not yet handled. */ | |
7919 | ||
7920 | static CORE_ADDR | |
e7c27a73 | 7921 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 7922 | { |
e7c27a73 DJ |
7923 | struct objfile *objfile = cu->objfile; |
7924 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7925 | int i; |
7926 | int size = blk->size; | |
7927 | char *data = blk->data; | |
7928 | CORE_ADDR stack[64]; | |
7929 | int stacki; | |
7930 | unsigned int bytes_read, unsnd; | |
7931 | unsigned char op; | |
7932 | ||
7933 | i = 0; | |
7934 | stacki = 0; | |
7935 | stack[stacki] = 0; | |
7936 | isreg = 0; | |
c906108c SS |
7937 | |
7938 | while (i < size) | |
7939 | { | |
c906108c SS |
7940 | op = data[i++]; |
7941 | switch (op) | |
7942 | { | |
f1bea926 JM |
7943 | case DW_OP_lit0: |
7944 | case DW_OP_lit1: | |
7945 | case DW_OP_lit2: | |
7946 | case DW_OP_lit3: | |
7947 | case DW_OP_lit4: | |
7948 | case DW_OP_lit5: | |
7949 | case DW_OP_lit6: | |
7950 | case DW_OP_lit7: | |
7951 | case DW_OP_lit8: | |
7952 | case DW_OP_lit9: | |
7953 | case DW_OP_lit10: | |
7954 | case DW_OP_lit11: | |
7955 | case DW_OP_lit12: | |
7956 | case DW_OP_lit13: | |
7957 | case DW_OP_lit14: | |
7958 | case DW_OP_lit15: | |
7959 | case DW_OP_lit16: | |
7960 | case DW_OP_lit17: | |
7961 | case DW_OP_lit18: | |
7962 | case DW_OP_lit19: | |
7963 | case DW_OP_lit20: | |
7964 | case DW_OP_lit21: | |
7965 | case DW_OP_lit22: | |
7966 | case DW_OP_lit23: | |
7967 | case DW_OP_lit24: | |
7968 | case DW_OP_lit25: | |
7969 | case DW_OP_lit26: | |
7970 | case DW_OP_lit27: | |
7971 | case DW_OP_lit28: | |
7972 | case DW_OP_lit29: | |
7973 | case DW_OP_lit30: | |
7974 | case DW_OP_lit31: | |
7975 | stack[++stacki] = op - DW_OP_lit0; | |
7976 | break; | |
7977 | ||
c906108c SS |
7978 | case DW_OP_reg0: |
7979 | case DW_OP_reg1: | |
7980 | case DW_OP_reg2: | |
7981 | case DW_OP_reg3: | |
7982 | case DW_OP_reg4: | |
7983 | case DW_OP_reg5: | |
7984 | case DW_OP_reg6: | |
7985 | case DW_OP_reg7: | |
7986 | case DW_OP_reg8: | |
7987 | case DW_OP_reg9: | |
7988 | case DW_OP_reg10: | |
7989 | case DW_OP_reg11: | |
7990 | case DW_OP_reg12: | |
7991 | case DW_OP_reg13: | |
7992 | case DW_OP_reg14: | |
7993 | case DW_OP_reg15: | |
7994 | case DW_OP_reg16: | |
7995 | case DW_OP_reg17: | |
7996 | case DW_OP_reg18: | |
7997 | case DW_OP_reg19: | |
7998 | case DW_OP_reg20: | |
7999 | case DW_OP_reg21: | |
8000 | case DW_OP_reg22: | |
8001 | case DW_OP_reg23: | |
8002 | case DW_OP_reg24: | |
8003 | case DW_OP_reg25: | |
8004 | case DW_OP_reg26: | |
8005 | case DW_OP_reg27: | |
8006 | case DW_OP_reg28: | |
8007 | case DW_OP_reg29: | |
8008 | case DW_OP_reg30: | |
8009 | case DW_OP_reg31: | |
8010 | isreg = 1; | |
8011 | stack[++stacki] = op - DW_OP_reg0; | |
4cecd739 DJ |
8012 | if (i < size) |
8013 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
8014 | break; |
8015 | ||
8016 | case DW_OP_regx: | |
8017 | isreg = 1; | |
8018 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
8019 | i += bytes_read; | |
c906108c | 8020 | stack[++stacki] = unsnd; |
4cecd739 DJ |
8021 | if (i < size) |
8022 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
8023 | break; |
8024 | ||
8025 | case DW_OP_addr: | |
107d2387 | 8026 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 8027 | cu, &bytes_read); |
107d2387 | 8028 | i += bytes_read; |
c906108c SS |
8029 | break; |
8030 | ||
8031 | case DW_OP_const1u: | |
8032 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
8033 | i += 1; | |
8034 | break; | |
8035 | ||
8036 | case DW_OP_const1s: | |
8037 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
8038 | i += 1; | |
8039 | break; | |
8040 | ||
8041 | case DW_OP_const2u: | |
8042 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
8043 | i += 2; | |
8044 | break; | |
8045 | ||
8046 | case DW_OP_const2s: | |
8047 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
8048 | i += 2; | |
8049 | break; | |
8050 | ||
8051 | case DW_OP_const4u: | |
8052 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
8053 | i += 4; | |
8054 | break; | |
8055 | ||
8056 | case DW_OP_const4s: | |
8057 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
8058 | i += 4; | |
8059 | break; | |
8060 | ||
8061 | case DW_OP_constu: | |
8062 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 8063 | &bytes_read); |
c906108c SS |
8064 | i += bytes_read; |
8065 | break; | |
8066 | ||
8067 | case DW_OP_consts: | |
8068 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
8069 | i += bytes_read; | |
8070 | break; | |
8071 | ||
f1bea926 JM |
8072 | case DW_OP_dup: |
8073 | stack[stacki + 1] = stack[stacki]; | |
8074 | stacki++; | |
8075 | break; | |
8076 | ||
c906108c SS |
8077 | case DW_OP_plus: |
8078 | stack[stacki - 1] += stack[stacki]; | |
8079 | stacki--; | |
8080 | break; | |
8081 | ||
8082 | case DW_OP_plus_uconst: | |
8083 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
8084 | i += bytes_read; | |
8085 | break; | |
8086 | ||
8087 | case DW_OP_minus: | |
f1bea926 | 8088 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
8089 | stacki--; |
8090 | break; | |
8091 | ||
7a292a7a | 8092 | case DW_OP_deref: |
7a292a7a | 8093 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
8094 | this using GDB's address_class enum. This is valid for partial |
8095 | global symbols, although the variable's address will be bogus | |
8096 | in the psymtab. */ | |
7a292a7a | 8097 | if (i < size) |
4d3c2250 | 8098 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
8099 | break; |
8100 | ||
9d774e44 | 8101 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
8102 | /* The top of the stack has the offset from the beginning |
8103 | of the thread control block at which the variable is located. */ | |
8104 | /* Nothing should follow this operator, so the top of stack would | |
8105 | be returned. */ | |
4cecd739 DJ |
8106 | /* This is valid for partial global symbols, but the variable's |
8107 | address will be bogus in the psymtab. */ | |
9d774e44 | 8108 | if (i < size) |
4d3c2250 | 8109 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
8110 | break; |
8111 | ||
c906108c | 8112 | default: |
4d3c2250 KB |
8113 | complaint (&symfile_complaints, "unsupported stack op: '%s'", |
8114 | dwarf_stack_op_name (op)); | |
c906108c SS |
8115 | return (stack[stacki]); |
8116 | } | |
8117 | } | |
8118 | return (stack[stacki]); | |
8119 | } | |
8120 | ||
8121 | /* memory allocation interface */ | |
8122 | ||
c906108c | 8123 | static void |
4efb68b1 | 8124 | dwarf2_free_tmp_obstack (void *ignore) |
c906108c SS |
8125 | { |
8126 | obstack_free (&dwarf2_tmp_obstack, NULL); | |
8127 | } | |
8128 | ||
8129 | static struct dwarf_block * | |
fba45db2 | 8130 | dwarf_alloc_block (void) |
c906108c SS |
8131 | { |
8132 | struct dwarf_block *blk; | |
8133 | ||
8134 | blk = (struct dwarf_block *) | |
8135 | obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block)); | |
8136 | return (blk); | |
8137 | } | |
8138 | ||
8139 | static struct abbrev_info * | |
f3dd6933 | 8140 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
8141 | { |
8142 | struct abbrev_info *abbrev; | |
8143 | ||
f3dd6933 DJ |
8144 | abbrev = (struct abbrev_info *) |
8145 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
8146 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
8147 | return (abbrev); | |
8148 | } | |
8149 | ||
8150 | static struct die_info * | |
fba45db2 | 8151 | dwarf_alloc_die (void) |
c906108c SS |
8152 | { |
8153 | struct die_info *die; | |
8154 | ||
8155 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
8156 | memset (die, 0, sizeof (struct die_info)); | |
8157 | return (die); | |
8158 | } | |
2e276125 JB |
8159 | |
8160 | \f | |
8161 | /* Macro support. */ | |
8162 | ||
8163 | ||
8164 | /* Return the full name of file number I in *LH's file name table. | |
8165 | Use COMP_DIR as the name of the current directory of the | |
8166 | compilation. The result is allocated using xmalloc; the caller is | |
8167 | responsible for freeing it. */ | |
8168 | static char * | |
8169 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
8170 | { | |
8171 | struct file_entry *fe = &lh->file_names[file - 1]; | |
8172 | ||
8173 | if (IS_ABSOLUTE_PATH (fe->name)) | |
8174 | return xstrdup (fe->name); | |
8175 | else | |
8176 | { | |
8177 | const char *dir; | |
8178 | int dir_len; | |
8179 | char *full_name; | |
8180 | ||
8181 | if (fe->dir_index) | |
8182 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8183 | else | |
8184 | dir = comp_dir; | |
8185 | ||
8186 | if (dir) | |
8187 | { | |
8188 | dir_len = strlen (dir); | |
8189 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
8190 | strcpy (full_name, dir); | |
8191 | full_name[dir_len] = '/'; | |
8192 | strcpy (full_name + dir_len + 1, fe->name); | |
8193 | return full_name; | |
8194 | } | |
8195 | else | |
8196 | return xstrdup (fe->name); | |
8197 | } | |
8198 | } | |
8199 | ||
8200 | ||
8201 | static struct macro_source_file * | |
8202 | macro_start_file (int file, int line, | |
8203 | struct macro_source_file *current_file, | |
8204 | const char *comp_dir, | |
8205 | struct line_header *lh, struct objfile *objfile) | |
8206 | { | |
8207 | /* The full name of this source file. */ | |
8208 | char *full_name = file_full_name (file, lh, comp_dir); | |
8209 | ||
8210 | /* We don't create a macro table for this compilation unit | |
8211 | at all until we actually get a filename. */ | |
8212 | if (! pending_macros) | |
4a146b47 | 8213 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 8214 | objfile->macro_cache); |
2e276125 JB |
8215 | |
8216 | if (! current_file) | |
8217 | /* If we have no current file, then this must be the start_file | |
8218 | directive for the compilation unit's main source file. */ | |
8219 | current_file = macro_set_main (pending_macros, full_name); | |
8220 | else | |
8221 | current_file = macro_include (current_file, line, full_name); | |
8222 | ||
8223 | xfree (full_name); | |
8224 | ||
8225 | return current_file; | |
8226 | } | |
8227 | ||
8228 | ||
8229 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
8230 | followed by a null byte. */ | |
8231 | static char * | |
8232 | copy_string (const char *buf, int len) | |
8233 | { | |
8234 | char *s = xmalloc (len + 1); | |
8235 | memcpy (s, buf, len); | |
8236 | s[len] = '\0'; | |
8237 | ||
8238 | return s; | |
8239 | } | |
8240 | ||
8241 | ||
8242 | static const char * | |
8243 | consume_improper_spaces (const char *p, const char *body) | |
8244 | { | |
8245 | if (*p == ' ') | |
8246 | { | |
4d3c2250 KB |
8247 | complaint (&symfile_complaints, |
8248 | "macro definition contains spaces in formal argument list:\n`%s'", | |
8249 | body); | |
2e276125 JB |
8250 | |
8251 | while (*p == ' ') | |
8252 | p++; | |
8253 | } | |
8254 | ||
8255 | return p; | |
8256 | } | |
8257 | ||
8258 | ||
8259 | static void | |
8260 | parse_macro_definition (struct macro_source_file *file, int line, | |
8261 | const char *body) | |
8262 | { | |
8263 | const char *p; | |
8264 | ||
8265 | /* The body string takes one of two forms. For object-like macro | |
8266 | definitions, it should be: | |
8267 | ||
8268 | <macro name> " " <definition> | |
8269 | ||
8270 | For function-like macro definitions, it should be: | |
8271 | ||
8272 | <macro name> "() " <definition> | |
8273 | or | |
8274 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
8275 | ||
8276 | Spaces may appear only where explicitly indicated, and in the | |
8277 | <definition>. | |
8278 | ||
8279 | The Dwarf 2 spec says that an object-like macro's name is always | |
8280 | followed by a space, but versions of GCC around March 2002 omit | |
8281 | the space when the macro's definition is the empty string. | |
8282 | ||
8283 | The Dwarf 2 spec says that there should be no spaces between the | |
8284 | formal arguments in a function-like macro's formal argument list, | |
8285 | but versions of GCC around March 2002 include spaces after the | |
8286 | commas. */ | |
8287 | ||
8288 | ||
8289 | /* Find the extent of the macro name. The macro name is terminated | |
8290 | by either a space or null character (for an object-like macro) or | |
8291 | an opening paren (for a function-like macro). */ | |
8292 | for (p = body; *p; p++) | |
8293 | if (*p == ' ' || *p == '(') | |
8294 | break; | |
8295 | ||
8296 | if (*p == ' ' || *p == '\0') | |
8297 | { | |
8298 | /* It's an object-like macro. */ | |
8299 | int name_len = p - body; | |
8300 | char *name = copy_string (body, name_len); | |
8301 | const char *replacement; | |
8302 | ||
8303 | if (*p == ' ') | |
8304 | replacement = body + name_len + 1; | |
8305 | else | |
8306 | { | |
4d3c2250 | 8307 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8308 | replacement = body + name_len; |
8309 | } | |
8310 | ||
8311 | macro_define_object (file, line, name, replacement); | |
8312 | ||
8313 | xfree (name); | |
8314 | } | |
8315 | else if (*p == '(') | |
8316 | { | |
8317 | /* It's a function-like macro. */ | |
8318 | char *name = copy_string (body, p - body); | |
8319 | int argc = 0; | |
8320 | int argv_size = 1; | |
8321 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
8322 | ||
8323 | p++; | |
8324 | ||
8325 | p = consume_improper_spaces (p, body); | |
8326 | ||
8327 | /* Parse the formal argument list. */ | |
8328 | while (*p && *p != ')') | |
8329 | { | |
8330 | /* Find the extent of the current argument name. */ | |
8331 | const char *arg_start = p; | |
8332 | ||
8333 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
8334 | p++; | |
8335 | ||
8336 | if (! *p || p == arg_start) | |
4d3c2250 | 8337 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8338 | else |
8339 | { | |
8340 | /* Make sure argv has room for the new argument. */ | |
8341 | if (argc >= argv_size) | |
8342 | { | |
8343 | argv_size *= 2; | |
8344 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
8345 | } | |
8346 | ||
8347 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
8348 | } | |
8349 | ||
8350 | p = consume_improper_spaces (p, body); | |
8351 | ||
8352 | /* Consume the comma, if present. */ | |
8353 | if (*p == ',') | |
8354 | { | |
8355 | p++; | |
8356 | ||
8357 | p = consume_improper_spaces (p, body); | |
8358 | } | |
8359 | } | |
8360 | ||
8361 | if (*p == ')') | |
8362 | { | |
8363 | p++; | |
8364 | ||
8365 | if (*p == ' ') | |
8366 | /* Perfectly formed definition, no complaints. */ | |
8367 | macro_define_function (file, line, name, | |
8368 | argc, (const char **) argv, | |
8369 | p + 1); | |
8370 | else if (*p == '\0') | |
8371 | { | |
8372 | /* Complain, but do define it. */ | |
4d3c2250 | 8373 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8374 | macro_define_function (file, line, name, |
8375 | argc, (const char **) argv, | |
8376 | p); | |
8377 | } | |
8378 | else | |
8379 | /* Just complain. */ | |
4d3c2250 | 8380 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8381 | } |
8382 | else | |
8383 | /* Just complain. */ | |
4d3c2250 | 8384 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8385 | |
8386 | xfree (name); | |
8387 | { | |
8388 | int i; | |
8389 | ||
8390 | for (i = 0; i < argc; i++) | |
8391 | xfree (argv[i]); | |
8392 | } | |
8393 | xfree (argv); | |
8394 | } | |
8395 | else | |
4d3c2250 | 8396 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8397 | } |
8398 | ||
8399 | ||
8400 | static void | |
8401 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
8402 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 8403 | struct dwarf2_cu *cu) |
2e276125 JB |
8404 | { |
8405 | char *mac_ptr, *mac_end; | |
8406 | struct macro_source_file *current_file = 0; | |
8407 | ||
6502dd73 | 8408 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 8409 | { |
4d3c2250 | 8410 | complaint (&symfile_complaints, "missing .debug_macinfo section"); |
2e276125 JB |
8411 | return; |
8412 | } | |
8413 | ||
6502dd73 DJ |
8414 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
8415 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
8416 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
8417 | |
8418 | for (;;) | |
8419 | { | |
8420 | enum dwarf_macinfo_record_type macinfo_type; | |
8421 | ||
8422 | /* Do we at least have room for a macinfo type byte? */ | |
8423 | if (mac_ptr >= mac_end) | |
8424 | { | |
4d3c2250 | 8425 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
8426 | return; |
8427 | } | |
8428 | ||
8429 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
8430 | mac_ptr++; | |
8431 | ||
8432 | switch (macinfo_type) | |
8433 | { | |
8434 | /* A zero macinfo type indicates the end of the macro | |
8435 | information. */ | |
8436 | case 0: | |
8437 | return; | |
8438 | ||
8439 | case DW_MACINFO_define: | |
8440 | case DW_MACINFO_undef: | |
8441 | { | |
8442 | int bytes_read; | |
8443 | int line; | |
8444 | char *body; | |
8445 | ||
8446 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8447 | mac_ptr += bytes_read; | |
8448 | body = read_string (abfd, mac_ptr, &bytes_read); | |
8449 | mac_ptr += bytes_read; | |
8450 | ||
8451 | if (! current_file) | |
4d3c2250 KB |
8452 | complaint (&symfile_complaints, |
8453 | "debug info gives macro %s outside of any file: %s", | |
8454 | macinfo_type == | |
8455 | DW_MACINFO_define ? "definition" : macinfo_type == | |
8456 | DW_MACINFO_undef ? "undefinition" : | |
8457 | "something-or-other", body); | |
2e276125 JB |
8458 | else |
8459 | { | |
8460 | if (macinfo_type == DW_MACINFO_define) | |
8461 | parse_macro_definition (current_file, line, body); | |
8462 | else if (macinfo_type == DW_MACINFO_undef) | |
8463 | macro_undef (current_file, line, body); | |
8464 | } | |
8465 | } | |
8466 | break; | |
8467 | ||
8468 | case DW_MACINFO_start_file: | |
8469 | { | |
8470 | int bytes_read; | |
8471 | int line, file; | |
8472 | ||
8473 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8474 | mac_ptr += bytes_read; | |
8475 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8476 | mac_ptr += bytes_read; | |
8477 | ||
8478 | current_file = macro_start_file (file, line, | |
8479 | current_file, comp_dir, | |
e7c27a73 | 8480 | lh, cu->objfile); |
2e276125 JB |
8481 | } |
8482 | break; | |
8483 | ||
8484 | case DW_MACINFO_end_file: | |
8485 | if (! current_file) | |
4d3c2250 KB |
8486 | complaint (&symfile_complaints, |
8487 | "macro debug info has an unmatched `close_file' directive"); | |
2e276125 JB |
8488 | else |
8489 | { | |
8490 | current_file = current_file->included_by; | |
8491 | if (! current_file) | |
8492 | { | |
8493 | enum dwarf_macinfo_record_type next_type; | |
8494 | ||
8495 | /* GCC circa March 2002 doesn't produce the zero | |
8496 | type byte marking the end of the compilation | |
8497 | unit. Complain if it's not there, but exit no | |
8498 | matter what. */ | |
8499 | ||
8500 | /* Do we at least have room for a macinfo type byte? */ | |
8501 | if (mac_ptr >= mac_end) | |
8502 | { | |
4d3c2250 | 8503 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
8504 | return; |
8505 | } | |
8506 | ||
8507 | /* We don't increment mac_ptr here, so this is just | |
8508 | a look-ahead. */ | |
8509 | next_type = read_1_byte (abfd, mac_ptr); | |
8510 | if (next_type != 0) | |
4d3c2250 KB |
8511 | complaint (&symfile_complaints, |
8512 | "no terminating 0-type entry for macros in `.debug_macinfo' section"); | |
2e276125 JB |
8513 | |
8514 | return; | |
8515 | } | |
8516 | } | |
8517 | break; | |
8518 | ||
8519 | case DW_MACINFO_vendor_ext: | |
8520 | { | |
8521 | int bytes_read; | |
8522 | int constant; | |
8523 | char *string; | |
8524 | ||
8525 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8526 | mac_ptr += bytes_read; | |
8527 | string = read_string (abfd, mac_ptr, &bytes_read); | |
8528 | mac_ptr += bytes_read; | |
8529 | ||
8530 | /* We don't recognize any vendor extensions. */ | |
8531 | } | |
8532 | break; | |
8533 | } | |
8534 | } | |
8535 | } | |
8e19ed76 PS |
8536 | |
8537 | /* Check if the attribute's form is a DW_FORM_block* | |
8538 | if so return true else false. */ | |
8539 | static int | |
8540 | attr_form_is_block (struct attribute *attr) | |
8541 | { | |
8542 | return (attr == NULL ? 0 : | |
8543 | attr->form == DW_FORM_block1 | |
8544 | || attr->form == DW_FORM_block2 | |
8545 | || attr->form == DW_FORM_block4 | |
8546 | || attr->form == DW_FORM_block); | |
8547 | } | |
4c2df51b DJ |
8548 | |
8549 | static void | |
8550 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8551 | struct dwarf2_cu *cu) |
4c2df51b | 8552 | { |
0d53c4c4 | 8553 | if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
4c2df51b | 8554 | { |
0d53c4c4 | 8555 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 8556 | |
4a146b47 | 8557 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 8558 | sizeof (struct dwarf2_loclist_baton)); |
e7c27a73 | 8559 | baton->objfile = cu->objfile; |
4c2df51b | 8560 | |
0d53c4c4 DJ |
8561 | /* We don't know how long the location list is, but make sure we |
8562 | don't run off the edge of the section. */ | |
6502dd73 DJ |
8563 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
8564 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
8565 | baton->base_address = cu->header.base_address; |
8566 | if (cu->header.base_known == 0) | |
0d53c4c4 DJ |
8567 | complaint (&symfile_complaints, |
8568 | "Location list used without specifying the CU base address."); | |
4c2df51b | 8569 | |
a67af2b9 | 8570 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
8571 | SYMBOL_LOCATION_BATON (sym) = baton; |
8572 | } | |
8573 | else | |
8574 | { | |
8575 | struct dwarf2_locexpr_baton *baton; | |
8576 | ||
4a146b47 | 8577 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 8578 | sizeof (struct dwarf2_locexpr_baton)); |
e7c27a73 | 8579 | baton->objfile = cu->objfile; |
0d53c4c4 DJ |
8580 | |
8581 | if (attr_form_is_block (attr)) | |
8582 | { | |
8583 | /* Note that we're just copying the block's data pointer | |
8584 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
8585 | info_buffer for SYM's objfile; right now we never release |
8586 | that buffer, but when we do clean up properly this may | |
8587 | need to change. */ | |
0d53c4c4 DJ |
8588 | baton->size = DW_BLOCK (attr)->size; |
8589 | baton->data = DW_BLOCK (attr)->data; | |
8590 | } | |
8591 | else | |
8592 | { | |
8593 | dwarf2_invalid_attrib_class_complaint ("location description", | |
8594 | SYMBOL_NATURAL_NAME (sym)); | |
8595 | baton->size = 0; | |
8596 | baton->data = NULL; | |
8597 | } | |
8598 | ||
a67af2b9 | 8599 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
8600 | SYMBOL_LOCATION_BATON (sym) = baton; |
8601 | } | |
4c2df51b | 8602 | } |
6502dd73 | 8603 | |
72bf9492 DJ |
8604 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
8605 | when we're finished with it. We can't free the pointer itself, but | |
8606 | release any associated storage. | |
8607 | ||
8608 | Only used during partial symbol parsing. */ | |
8609 | ||
8610 | static void | |
8611 | free_stack_comp_unit (void *data) | |
8612 | { | |
8613 | struct dwarf2_cu *cu = data; | |
8614 | ||
8615 | obstack_free (&cu->comp_unit_obstack, NULL); | |
8616 | cu->partial_dies = NULL; | |
8617 | } | |
8618 | ||
8619 | /* Allocation function for the libiberty hash table which uses an | |
8620 | obstack. */ | |
8621 | ||
8622 | static void * | |
8623 | hashtab_obstack_allocate (void *data, size_t size, size_t count) | |
8624 | { | |
8625 | unsigned int total = size * count; | |
8626 | void *ptr = obstack_alloc ((struct obstack *) data, total); | |
8627 | memset (ptr, 0, total); | |
8628 | return ptr; | |
8629 | } | |
8630 | ||
8631 | /* Trivial deallocation function for the libiberty splay tree and hash | |
8632 | table - don't deallocate anything. Rely on later deletion of the | |
8633 | obstack. */ | |
8634 | ||
8635 | static void | |
8636 | dummy_obstack_deallocate (void *object, void *data) | |
8637 | { | |
8638 | return; | |
8639 | } | |
8640 | ||
8641 | /* Trivial hash function for partial_die_info: the hash value of a DIE | |
8642 | is its offset in .debug_info for this objfile. */ | |
8643 | ||
8644 | static hashval_t | |
8645 | partial_die_hash (const void *item) | |
8646 | { | |
8647 | const struct partial_die_info *part_die = item; | |
8648 | return part_die->offset; | |
8649 | } | |
8650 | ||
8651 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
8652 | are equal if they have the same offset. */ | |
8653 | ||
8654 | static int | |
8655 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
8656 | { | |
8657 | const struct partial_die_info *part_die_lhs = item_lhs; | |
8658 | const struct partial_die_info *part_die_rhs = item_rhs; | |
8659 | return part_die_lhs->offset == part_die_rhs->offset; | |
8660 | } | |
8661 | ||
6502dd73 DJ |
8662 | void _initialize_dwarf2_read (void); |
8663 | ||
8664 | void | |
8665 | _initialize_dwarf2_read (void) | |
8666 | { | |
8667 | dwarf2_objfile_data_key = register_objfile_data (); | |
8668 | } |