Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
6aba47ca | 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
4c38e0a4 | 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
0fb0cc75 | 5 | Free Software Foundation, Inc. |
c906108c SS |
6 | |
7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
8 | Inc. with support from Florida State University (under contract | |
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 12 | support. |
c906108c | 13 | |
c5aa993b | 14 | This file is part of GDB. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
18 | the Free Software Foundation; either version 3 of the License, or |
19 | (at your option) any later version. | |
c906108c | 20 | |
a9762ec7 JB |
21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
c906108c | 25 | |
c5aa993b | 26 | You should have received a copy of the GNU General Public License |
a9762ec7 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
28 | |
29 | #include "defs.h" | |
30 | #include "bfd.h" | |
c906108c SS |
31 | #include "symtab.h" |
32 | #include "gdbtypes.h" | |
c906108c | 33 | #include "objfiles.h" |
fa8f86ff | 34 | #include "dwarf2.h" |
c906108c SS |
35 | #include "buildsym.h" |
36 | #include "demangle.h" | |
37 | #include "expression.h" | |
d5166ae1 | 38 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 39 | #include "macrotab.h" |
c906108c SS |
40 | #include "language.h" |
41 | #include "complaints.h" | |
357e46e7 | 42 | #include "bcache.h" |
4c2df51b DJ |
43 | #include "dwarf2expr.h" |
44 | #include "dwarf2loc.h" | |
9219021c | 45 | #include "cp-support.h" |
72bf9492 | 46 | #include "hashtab.h" |
ae038cb0 DJ |
47 | #include "command.h" |
48 | #include "gdbcmd.h" | |
edb3359d | 49 | #include "block.h" |
ff013f42 | 50 | #include "addrmap.h" |
94af9270 KS |
51 | #include "typeprint.h" |
52 | #include "jv-lang.h" | |
ccefe4c4 | 53 | #include "psympriv.h" |
4c2df51b | 54 | |
c906108c SS |
55 | #include <fcntl.h> |
56 | #include "gdb_string.h" | |
4bdf3d34 | 57 | #include "gdb_assert.h" |
c906108c | 58 | #include <sys/types.h> |
233a11ab CS |
59 | #ifdef HAVE_ZLIB_H |
60 | #include <zlib.h> | |
61 | #endif | |
dce234bc PP |
62 | #ifdef HAVE_MMAP |
63 | #include <sys/mman.h> | |
85d9bd0e TT |
64 | #ifndef MAP_FAILED |
65 | #define MAP_FAILED ((void *) -1) | |
66 | #endif | |
dce234bc | 67 | #endif |
d8151005 | 68 | |
107d2387 | 69 | #if 0 |
357e46e7 | 70 | /* .debug_info header for a compilation unit |
c906108c SS |
71 | Because of alignment constraints, this structure has padding and cannot |
72 | be mapped directly onto the beginning of the .debug_info section. */ | |
73 | typedef struct comp_unit_header | |
74 | { | |
75 | unsigned int length; /* length of the .debug_info | |
76 | contribution */ | |
77 | unsigned short version; /* version number -- 2 for DWARF | |
78 | version 2 */ | |
79 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
80 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
81 | } | |
82 | _COMP_UNIT_HEADER; | |
83 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 84 | #endif |
c906108c | 85 | |
c906108c SS |
86 | /* .debug_line statement program prologue |
87 | Because of alignment constraints, this structure has padding and cannot | |
88 | be mapped directly onto the beginning of the .debug_info section. */ | |
89 | typedef struct statement_prologue | |
90 | { | |
91 | unsigned int total_length; /* byte length of the statement | |
92 | information */ | |
93 | unsigned short version; /* version number -- 2 for DWARF | |
94 | version 2 */ | |
95 | unsigned int prologue_length; /* # bytes between prologue & | |
96 | stmt program */ | |
97 | unsigned char minimum_instruction_length; /* byte size of | |
98 | smallest instr */ | |
99 | unsigned char default_is_stmt; /* initial value of is_stmt | |
100 | register */ | |
101 | char line_base; | |
102 | unsigned char line_range; | |
103 | unsigned char opcode_base; /* number assigned to first special | |
104 | opcode */ | |
105 | unsigned char *standard_opcode_lengths; | |
106 | } | |
107 | _STATEMENT_PROLOGUE; | |
108 | ||
d97bc12b DE |
109 | /* When non-zero, dump DIEs after they are read in. */ |
110 | static int dwarf2_die_debug = 0; | |
111 | ||
dce234bc PP |
112 | static int pagesize; |
113 | ||
df8a16a1 DJ |
114 | /* When set, the file that we're processing is known to have debugging |
115 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
116 | but later versions do. */ | |
117 | ||
118 | static int processing_has_namespace_info; | |
119 | ||
6502dd73 DJ |
120 | static const struct objfile_data *dwarf2_objfile_data_key; |
121 | ||
dce234bc PP |
122 | struct dwarf2_section_info |
123 | { | |
124 | asection *asection; | |
125 | gdb_byte *buffer; | |
126 | bfd_size_type size; | |
127 | int was_mmapped; | |
be391dca TT |
128 | /* True if we have tried to read this section. */ |
129 | int readin; | |
dce234bc PP |
130 | }; |
131 | ||
6502dd73 DJ |
132 | struct dwarf2_per_objfile |
133 | { | |
dce234bc PP |
134 | struct dwarf2_section_info info; |
135 | struct dwarf2_section_info abbrev; | |
136 | struct dwarf2_section_info line; | |
dce234bc PP |
137 | struct dwarf2_section_info loc; |
138 | struct dwarf2_section_info macinfo; | |
139 | struct dwarf2_section_info str; | |
140 | struct dwarf2_section_info ranges; | |
348e048f | 141 | struct dwarf2_section_info types; |
dce234bc PP |
142 | struct dwarf2_section_info frame; |
143 | struct dwarf2_section_info eh_frame; | |
ae038cb0 | 144 | |
be391dca TT |
145 | /* Back link. */ |
146 | struct objfile *objfile; | |
147 | ||
10b3939b DJ |
148 | /* A list of all the compilation units. This is used to locate |
149 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
150 | struct dwarf2_per_cu_data **all_comp_units; |
151 | ||
152 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
153 | int n_comp_units; | |
154 | ||
155 | /* A chain of compilation units that are currently read in, so that | |
156 | they can be freed later. */ | |
157 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 158 | |
348e048f DE |
159 | /* A table mapping .debug_types signatures to its signatured_type entry. |
160 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
161 | htab_t signatured_types; | |
162 | ||
72dca2f5 FR |
163 | /* A flag indicating wether this objfile has a section loaded at a |
164 | VMA of 0. */ | |
165 | int has_section_at_zero; | |
6502dd73 DJ |
166 | }; |
167 | ||
168 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
169 | |
170 | /* names of the debugging sections */ | |
171 | ||
233a11ab CS |
172 | /* Note that if the debugging section has been compressed, it might |
173 | have a name like .zdebug_info. */ | |
174 | ||
175 | #define INFO_SECTION "debug_info" | |
176 | #define ABBREV_SECTION "debug_abbrev" | |
177 | #define LINE_SECTION "debug_line" | |
233a11ab CS |
178 | #define LOC_SECTION "debug_loc" |
179 | #define MACINFO_SECTION "debug_macinfo" | |
180 | #define STR_SECTION "debug_str" | |
181 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 182 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
183 | #define FRAME_SECTION "debug_frame" |
184 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
185 | |
186 | /* local data types */ | |
187 | ||
57349743 JB |
188 | /* We hold several abbreviation tables in memory at the same time. */ |
189 | #ifndef ABBREV_HASH_SIZE | |
190 | #define ABBREV_HASH_SIZE 121 | |
191 | #endif | |
192 | ||
107d2387 AC |
193 | /* The data in a compilation unit header, after target2host |
194 | translation, looks like this. */ | |
c906108c | 195 | struct comp_unit_head |
a738430d | 196 | { |
c764a876 | 197 | unsigned int length; |
a738430d | 198 | short version; |
a738430d MK |
199 | unsigned char addr_size; |
200 | unsigned char signed_addr_p; | |
9cbfa09e | 201 | unsigned int abbrev_offset; |
57349743 | 202 | |
a738430d MK |
203 | /* Size of file offsets; either 4 or 8. */ |
204 | unsigned int offset_size; | |
57349743 | 205 | |
a738430d MK |
206 | /* Size of the length field; either 4 or 12. */ |
207 | unsigned int initial_length_size; | |
57349743 | 208 | |
a738430d MK |
209 | /* Offset to the first byte of this compilation unit header in the |
210 | .debug_info section, for resolving relative reference dies. */ | |
211 | unsigned int offset; | |
57349743 | 212 | |
d00adf39 DE |
213 | /* Offset to first die in this cu from the start of the cu. |
214 | This will be the first byte following the compilation unit header. */ | |
215 | unsigned int first_die_offset; | |
a738430d | 216 | }; |
c906108c | 217 | |
e7c27a73 DJ |
218 | /* Internal state when decoding a particular compilation unit. */ |
219 | struct dwarf2_cu | |
220 | { | |
221 | /* The objfile containing this compilation unit. */ | |
222 | struct objfile *objfile; | |
223 | ||
d00adf39 | 224 | /* The header of the compilation unit. */ |
e7c27a73 | 225 | struct comp_unit_head header; |
e142c38c | 226 | |
d00adf39 DE |
227 | /* Base address of this compilation unit. */ |
228 | CORE_ADDR base_address; | |
229 | ||
230 | /* Non-zero if base_address has been set. */ | |
231 | int base_known; | |
232 | ||
e142c38c DJ |
233 | struct function_range *first_fn, *last_fn, *cached_fn; |
234 | ||
235 | /* The language we are debugging. */ | |
236 | enum language language; | |
237 | const struct language_defn *language_defn; | |
238 | ||
b0f35d58 DL |
239 | const char *producer; |
240 | ||
e142c38c DJ |
241 | /* The generic symbol table building routines have separate lists for |
242 | file scope symbols and all all other scopes (local scopes). So | |
243 | we need to select the right one to pass to add_symbol_to_list(). | |
244 | We do it by keeping a pointer to the correct list in list_in_scope. | |
245 | ||
246 | FIXME: The original dwarf code just treated the file scope as the | |
247 | first local scope, and all other local scopes as nested local | |
248 | scopes, and worked fine. Check to see if we really need to | |
249 | distinguish these in buildsym.c. */ | |
250 | struct pending **list_in_scope; | |
251 | ||
f3dd6933 DJ |
252 | /* DWARF abbreviation table associated with this compilation unit. */ |
253 | struct abbrev_info **dwarf2_abbrevs; | |
254 | ||
255 | /* Storage for the abbrev table. */ | |
256 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
257 | |
258 | /* Hash table holding all the loaded partial DIEs. */ | |
259 | htab_t partial_dies; | |
260 | ||
261 | /* Storage for things with the same lifetime as this read-in compilation | |
262 | unit, including partial DIEs. */ | |
263 | struct obstack comp_unit_obstack; | |
264 | ||
ae038cb0 DJ |
265 | /* When multiple dwarf2_cu structures are living in memory, this field |
266 | chains them all together, so that they can be released efficiently. | |
267 | We will probably also want a generation counter so that most-recently-used | |
268 | compilation units are cached... */ | |
269 | struct dwarf2_per_cu_data *read_in_chain; | |
270 | ||
271 | /* Backchain to our per_cu entry if the tree has been built. */ | |
272 | struct dwarf2_per_cu_data *per_cu; | |
273 | ||
f792889a DJ |
274 | /* Pointer to the die -> type map. Although it is stored |
275 | permanently in per_cu, we copy it here to avoid double | |
276 | indirection. */ | |
277 | htab_t type_hash; | |
278 | ||
ae038cb0 DJ |
279 | /* How many compilation units ago was this CU last referenced? */ |
280 | int last_used; | |
281 | ||
10b3939b | 282 | /* A hash table of die offsets for following references. */ |
51545339 | 283 | htab_t die_hash; |
10b3939b DJ |
284 | |
285 | /* Full DIEs if read in. */ | |
286 | struct die_info *dies; | |
287 | ||
288 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
289 | units referenced by this one. Only set during full symbol processing; | |
290 | partial symbol tables do not have dependencies. */ | |
291 | htab_t dependencies; | |
292 | ||
cb1df416 DJ |
293 | /* Header data from the line table, during full symbol processing. */ |
294 | struct line_header *line_header; | |
295 | ||
ae038cb0 DJ |
296 | /* Mark used when releasing cached dies. */ |
297 | unsigned int mark : 1; | |
298 | ||
299 | /* This flag will be set if this compilation unit might include | |
300 | inter-compilation-unit references. */ | |
301 | unsigned int has_form_ref_addr : 1; | |
302 | ||
72bf9492 DJ |
303 | /* This flag will be set if this compilation unit includes any |
304 | DW_TAG_namespace DIEs. If we know that there are explicit | |
305 | DIEs for namespaces, we don't need to try to infer them | |
306 | from mangled names. */ | |
307 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
308 | }; |
309 | ||
10b3939b DJ |
310 | /* Persistent data held for a compilation unit, even when not |
311 | processing it. We put a pointer to this structure in the | |
312 | read_symtab_private field of the psymtab. If we encounter | |
313 | inter-compilation-unit references, we also maintain a sorted | |
314 | list of all compilation units. */ | |
315 | ||
ae038cb0 DJ |
316 | struct dwarf2_per_cu_data |
317 | { | |
348e048f | 318 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 319 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
320 | - if it doesn't, GDB will fall over anyway. |
321 | NOTE: Unlike comp_unit_head.length, this length includes | |
322 | initial_length_size. */ | |
c764a876 | 323 | unsigned int offset; |
348e048f | 324 | unsigned int length : 29; |
ae038cb0 DJ |
325 | |
326 | /* Flag indicating this compilation unit will be read in before | |
327 | any of the current compilation units are processed. */ | |
c764a876 | 328 | unsigned int queued : 1; |
ae038cb0 | 329 | |
5afb4e99 DJ |
330 | /* This flag will be set if we need to load absolutely all DIEs |
331 | for this compilation unit, instead of just the ones we think | |
332 | are interesting. It gets set if we look for a DIE in the | |
333 | hash table and don't find it. */ | |
334 | unsigned int load_all_dies : 1; | |
335 | ||
348e048f DE |
336 | /* Non-zero if this CU is from .debug_types. |
337 | Otherwise it's from .debug_info. */ | |
338 | unsigned int from_debug_types : 1; | |
339 | ||
ae038cb0 DJ |
340 | /* Set iff currently read in. */ |
341 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
342 | |
343 | /* If full symbols for this CU have been read in, then this field | |
344 | holds a map of DIE offsets to types. It isn't always possible | |
345 | to reconstruct this information later, so we have to preserve | |
346 | it. */ | |
1c379e20 | 347 | htab_t type_hash; |
10b3939b | 348 | |
31ffec48 DJ |
349 | /* The partial symbol table associated with this compilation unit, |
350 | or NULL for partial units (which do not have an associated | |
351 | symtab). */ | |
10b3939b | 352 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
353 | }; |
354 | ||
348e048f DE |
355 | /* Entry in the signatured_types hash table. */ |
356 | ||
357 | struct signatured_type | |
358 | { | |
359 | ULONGEST signature; | |
360 | ||
361 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
362 | unsigned int offset; | |
363 | ||
364 | /* Offset in .debug_types of the type defined by this TU. */ | |
365 | unsigned int type_offset; | |
366 | ||
367 | /* The CU(/TU) of this type. */ | |
368 | struct dwarf2_per_cu_data per_cu; | |
369 | }; | |
370 | ||
93311388 DE |
371 | /* Struct used to pass misc. parameters to read_die_and_children, et. al. |
372 | which are used for both .debug_info and .debug_types dies. | |
373 | All parameters here are unchanging for the life of the call. | |
374 | This struct exists to abstract away the constant parameters of | |
375 | die reading. */ | |
376 | ||
377 | struct die_reader_specs | |
378 | { | |
379 | /* The bfd of this objfile. */ | |
380 | bfd* abfd; | |
381 | ||
382 | /* The CU of the DIE we are parsing. */ | |
383 | struct dwarf2_cu *cu; | |
384 | ||
385 | /* Pointer to start of section buffer. | |
386 | This is either the start of .debug_info or .debug_types. */ | |
387 | const gdb_byte *buffer; | |
388 | }; | |
389 | ||
debd256d JB |
390 | /* The line number information for a compilation unit (found in the |
391 | .debug_line section) begins with a "statement program header", | |
392 | which contains the following information. */ | |
393 | struct line_header | |
394 | { | |
395 | unsigned int total_length; | |
396 | unsigned short version; | |
397 | unsigned int header_length; | |
398 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 399 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
400 | unsigned char default_is_stmt; |
401 | int line_base; | |
402 | unsigned char line_range; | |
403 | unsigned char opcode_base; | |
404 | ||
405 | /* standard_opcode_lengths[i] is the number of operands for the | |
406 | standard opcode whose value is i. This means that | |
407 | standard_opcode_lengths[0] is unused, and the last meaningful | |
408 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
409 | unsigned char *standard_opcode_lengths; | |
410 | ||
411 | /* The include_directories table. NOTE! These strings are not | |
412 | allocated with xmalloc; instead, they are pointers into | |
413 | debug_line_buffer. If you try to free them, `free' will get | |
414 | indigestion. */ | |
415 | unsigned int num_include_dirs, include_dirs_size; | |
416 | char **include_dirs; | |
417 | ||
418 | /* The file_names table. NOTE! These strings are not allocated | |
419 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
420 | Don't try to free them directly. */ | |
421 | unsigned int num_file_names, file_names_size; | |
422 | struct file_entry | |
c906108c | 423 | { |
debd256d JB |
424 | char *name; |
425 | unsigned int dir_index; | |
426 | unsigned int mod_time; | |
427 | unsigned int length; | |
aaa75496 | 428 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 429 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
430 | } *file_names; |
431 | ||
432 | /* The start and end of the statement program following this | |
6502dd73 | 433 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 434 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 435 | }; |
c906108c SS |
436 | |
437 | /* When we construct a partial symbol table entry we only | |
438 | need this much information. */ | |
439 | struct partial_die_info | |
440 | { | |
72bf9492 | 441 | /* Offset of this DIE. */ |
c906108c | 442 | unsigned int offset; |
72bf9492 DJ |
443 | |
444 | /* DWARF-2 tag for this DIE. */ | |
445 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
446 | ||
72bf9492 DJ |
447 | /* Assorted flags describing the data found in this DIE. */ |
448 | unsigned int has_children : 1; | |
449 | unsigned int is_external : 1; | |
450 | unsigned int is_declaration : 1; | |
451 | unsigned int has_type : 1; | |
452 | unsigned int has_specification : 1; | |
453 | unsigned int has_pc_info : 1; | |
454 | ||
455 | /* Flag set if the SCOPE field of this structure has been | |
456 | computed. */ | |
457 | unsigned int scope_set : 1; | |
458 | ||
fa4028e9 JB |
459 | /* Flag set if the DIE has a byte_size attribute. */ |
460 | unsigned int has_byte_size : 1; | |
461 | ||
72bf9492 | 462 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 463 | sometimes a default name for unnamed DIEs. */ |
c906108c | 464 | char *name; |
72bf9492 DJ |
465 | |
466 | /* The scope to prepend to our children. This is generally | |
467 | allocated on the comp_unit_obstack, so will disappear | |
468 | when this compilation unit leaves the cache. */ | |
469 | char *scope; | |
470 | ||
471 | /* The location description associated with this DIE, if any. */ | |
472 | struct dwarf_block *locdesc; | |
473 | ||
474 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
475 | CORE_ADDR lowpc; |
476 | CORE_ADDR highpc; | |
72bf9492 | 477 | |
93311388 | 478 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 479 | DW_AT_sibling, if any. */ |
fe1b8b76 | 480 | gdb_byte *sibling; |
72bf9492 DJ |
481 | |
482 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
483 | DW_AT_specification (or DW_AT_abstract_origin or | |
484 | DW_AT_extension). */ | |
485 | unsigned int spec_offset; | |
486 | ||
487 | /* Pointers to this DIE's parent, first child, and next sibling, | |
488 | if any. */ | |
489 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
490 | }; |
491 | ||
492 | /* This data structure holds the information of an abbrev. */ | |
493 | struct abbrev_info | |
494 | { | |
495 | unsigned int number; /* number identifying abbrev */ | |
496 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
497 | unsigned short has_children; /* boolean */ |
498 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
499 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
500 | struct abbrev_info *next; /* next in chain */ | |
501 | }; | |
502 | ||
503 | struct attr_abbrev | |
504 | { | |
9d25dd43 DE |
505 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
506 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
507 | }; |
508 | ||
b60c80d6 DJ |
509 | /* Attributes have a name and a value */ |
510 | struct attribute | |
511 | { | |
9d25dd43 | 512 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
513 | ENUM_BITFIELD(dwarf_form) form : 15; |
514 | ||
515 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
516 | field should be in u.str (existing only for DW_STRING) but it is kept | |
517 | here for better struct attribute alignment. */ | |
518 | unsigned int string_is_canonical : 1; | |
519 | ||
b60c80d6 DJ |
520 | union |
521 | { | |
522 | char *str; | |
523 | struct dwarf_block *blk; | |
43bbcdc2 PH |
524 | ULONGEST unsnd; |
525 | LONGEST snd; | |
b60c80d6 | 526 | CORE_ADDR addr; |
348e048f | 527 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
528 | } |
529 | u; | |
530 | }; | |
531 | ||
c906108c SS |
532 | /* This data structure holds a complete die structure. */ |
533 | struct die_info | |
534 | { | |
76815b17 DE |
535 | /* DWARF-2 tag for this DIE. */ |
536 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
537 | ||
538 | /* Number of attributes */ | |
539 | unsigned short num_attrs; | |
540 | ||
541 | /* Abbrev number */ | |
542 | unsigned int abbrev; | |
543 | ||
93311388 | 544 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 545 | unsigned int offset; |
78ba4af6 JB |
546 | |
547 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
548 | points to this die's parent; CHILD points to the first child of | |
549 | this node; and all the children of a given node are chained | |
550 | together via their SIBLING fields, terminated by a die whose | |
551 | tag is zero. */ | |
639d11d3 DC |
552 | struct die_info *child; /* Its first child, if any. */ |
553 | struct die_info *sibling; /* Its next sibling, if any. */ | |
554 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 555 | |
b60c80d6 DJ |
556 | /* An array of attributes, with NUM_ATTRS elements. There may be |
557 | zero, but it's not common and zero-sized arrays are not | |
558 | sufficiently portable C. */ | |
559 | struct attribute attrs[1]; | |
c906108c SS |
560 | }; |
561 | ||
5fb290d7 DJ |
562 | struct function_range |
563 | { | |
564 | const char *name; | |
565 | CORE_ADDR lowpc, highpc; | |
566 | int seen_line; | |
567 | struct function_range *next; | |
568 | }; | |
569 | ||
c906108c SS |
570 | /* Get at parts of an attribute structure */ |
571 | ||
572 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 573 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
574 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
575 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
576 | #define DW_SND(attr) ((attr)->u.snd) | |
577 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 578 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c SS |
579 | |
580 | /* Blocks are a bunch of untyped bytes. */ | |
581 | struct dwarf_block | |
582 | { | |
583 | unsigned int size; | |
fe1b8b76 | 584 | gdb_byte *data; |
c906108c SS |
585 | }; |
586 | ||
c906108c SS |
587 | #ifndef ATTR_ALLOC_CHUNK |
588 | #define ATTR_ALLOC_CHUNK 4 | |
589 | #endif | |
590 | ||
c906108c SS |
591 | /* Allocate fields for structs, unions and enums in this size. */ |
592 | #ifndef DW_FIELD_ALLOC_CHUNK | |
593 | #define DW_FIELD_ALLOC_CHUNK 4 | |
594 | #endif | |
595 | ||
c906108c SS |
596 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
597 | but this would require a corresponding change in unpack_field_as_long | |
598 | and friends. */ | |
599 | static int bits_per_byte = 8; | |
600 | ||
601 | /* The routines that read and process dies for a C struct or C++ class | |
602 | pass lists of data member fields and lists of member function fields | |
603 | in an instance of a field_info structure, as defined below. */ | |
604 | struct field_info | |
c5aa993b JM |
605 | { |
606 | /* List of data member and baseclasses fields. */ | |
607 | struct nextfield | |
608 | { | |
609 | struct nextfield *next; | |
610 | int accessibility; | |
611 | int virtuality; | |
612 | struct field field; | |
613 | } | |
7d0ccb61 | 614 | *fields, *baseclasses; |
c906108c | 615 | |
7d0ccb61 | 616 | /* Number of fields (including baseclasses). */ |
c5aa993b | 617 | int nfields; |
c906108c | 618 | |
c5aa993b JM |
619 | /* Number of baseclasses. */ |
620 | int nbaseclasses; | |
c906108c | 621 | |
c5aa993b JM |
622 | /* Set if the accesibility of one of the fields is not public. */ |
623 | int non_public_fields; | |
c906108c | 624 | |
c5aa993b JM |
625 | /* Member function fields array, entries are allocated in the order they |
626 | are encountered in the object file. */ | |
627 | struct nextfnfield | |
628 | { | |
629 | struct nextfnfield *next; | |
630 | struct fn_field fnfield; | |
631 | } | |
632 | *fnfields; | |
c906108c | 633 | |
c5aa993b JM |
634 | /* Member function fieldlist array, contains name of possibly overloaded |
635 | member function, number of overloaded member functions and a pointer | |
636 | to the head of the member function field chain. */ | |
637 | struct fnfieldlist | |
638 | { | |
639 | char *name; | |
640 | int length; | |
641 | struct nextfnfield *head; | |
642 | } | |
643 | *fnfieldlists; | |
c906108c | 644 | |
c5aa993b JM |
645 | /* Number of entries in the fnfieldlists array. */ |
646 | int nfnfields; | |
647 | }; | |
c906108c | 648 | |
10b3939b DJ |
649 | /* One item on the queue of compilation units to read in full symbols |
650 | for. */ | |
651 | struct dwarf2_queue_item | |
652 | { | |
653 | struct dwarf2_per_cu_data *per_cu; | |
654 | struct dwarf2_queue_item *next; | |
655 | }; | |
656 | ||
657 | /* The current queue. */ | |
658 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
659 | ||
ae038cb0 DJ |
660 | /* Loaded secondary compilation units are kept in memory until they |
661 | have not been referenced for the processing of this many | |
662 | compilation units. Set this to zero to disable caching. Cache | |
663 | sizes of up to at least twenty will improve startup time for | |
664 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
665 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
666 | static void |
667 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
668 | struct cmd_list_element *c, const char *value) | |
669 | { | |
670 | fprintf_filtered (file, _("\ | |
671 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
672 | value); | |
673 | } | |
674 | ||
ae038cb0 | 675 | |
c906108c SS |
676 | /* Various complaints about symbol reading that don't abort the process */ |
677 | ||
4d3c2250 KB |
678 | static void |
679 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 680 | { |
4d3c2250 | 681 | complaint (&symfile_complaints, |
e2e0b3e5 | 682 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
683 | } |
684 | ||
25e43795 DJ |
685 | static void |
686 | dwarf2_debug_line_missing_file_complaint (void) | |
687 | { | |
688 | complaint (&symfile_complaints, | |
689 | _(".debug_line section has line data without a file")); | |
690 | } | |
691 | ||
59205f5a JB |
692 | static void |
693 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
694 | { | |
695 | complaint (&symfile_complaints, | |
696 | _(".debug_line section has line program sequence without an end")); | |
697 | } | |
698 | ||
4d3c2250 KB |
699 | static void |
700 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 701 | { |
e2e0b3e5 | 702 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
703 | } |
704 | ||
4d3c2250 KB |
705 | static void |
706 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
707 | int arg3) | |
2e276125 | 708 | { |
4d3c2250 | 709 | complaint (&symfile_complaints, |
e2e0b3e5 | 710 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
711 | arg2, arg3); |
712 | } | |
713 | ||
714 | static void | |
715 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 716 | { |
4d3c2250 | 717 | complaint (&symfile_complaints, |
e2e0b3e5 | 718 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
719 | } |
720 | ||
721 | static void | |
722 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 723 | { |
4d3c2250 | 724 | complaint (&symfile_complaints, |
e2e0b3e5 | 725 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
726 | arg1); |
727 | } | |
728 | ||
729 | static void | |
730 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 731 | { |
4d3c2250 | 732 | complaint (&symfile_complaints, |
e2e0b3e5 | 733 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 734 | } |
c906108c | 735 | |
c906108c SS |
736 | /* local function prototypes */ |
737 | ||
4efb68b1 | 738 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 739 | |
aaa75496 JB |
740 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
741 | struct objfile *); | |
742 | ||
743 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
d85a05f0 | 744 | struct die_info *, |
aaa75496 JB |
745 | struct partial_symtab *); |
746 | ||
c67a9c90 | 747 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 748 | |
72bf9492 DJ |
749 | static void scan_partial_symbols (struct partial_die_info *, |
750 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 751 | int, struct dwarf2_cu *); |
c906108c | 752 | |
72bf9492 DJ |
753 | static void add_partial_symbol (struct partial_die_info *, |
754 | struct dwarf2_cu *); | |
63d06c5c | 755 | |
72bf9492 DJ |
756 | static void add_partial_namespace (struct partial_die_info *pdi, |
757 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 758 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 759 | |
5d7cb8df JK |
760 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
761 | CORE_ADDR *highpc, int need_pc, | |
762 | struct dwarf2_cu *cu); | |
763 | ||
72bf9492 DJ |
764 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
765 | struct dwarf2_cu *cu); | |
91c24f0a | 766 | |
bc30ff58 JB |
767 | static void add_partial_subprogram (struct partial_die_info *pdi, |
768 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 769 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 770 | |
fe1b8b76 | 771 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
772 | gdb_byte *buffer, gdb_byte *info_ptr, |
773 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 774 | |
a14ed312 | 775 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 776 | |
a14ed312 | 777 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 778 | |
e7c27a73 | 779 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 780 | |
f3dd6933 | 781 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 782 | |
fe1b8b76 | 783 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 784 | struct dwarf2_cu *); |
72bf9492 | 785 | |
57349743 | 786 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 787 | struct dwarf2_cu *); |
c906108c | 788 | |
93311388 DE |
789 | static struct partial_die_info *load_partial_dies (bfd *, |
790 | gdb_byte *, gdb_byte *, | |
791 | int, struct dwarf2_cu *); | |
72bf9492 | 792 | |
fe1b8b76 | 793 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
794 | struct abbrev_info *abbrev, |
795 | unsigned int, bfd *, | |
796 | gdb_byte *, gdb_byte *, | |
797 | struct dwarf2_cu *); | |
c906108c | 798 | |
c764a876 | 799 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 800 | struct dwarf2_cu *); |
72bf9492 DJ |
801 | |
802 | static void fixup_partial_die (struct partial_die_info *, | |
803 | struct dwarf2_cu *); | |
804 | ||
fe1b8b76 JB |
805 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
806 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 807 | |
fe1b8b76 JB |
808 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
809 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 810 | |
fe1b8b76 | 811 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 812 | |
fe1b8b76 | 813 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 814 | |
fe1b8b76 | 815 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 816 | |
fe1b8b76 | 817 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 818 | |
93311388 | 819 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 820 | |
fe1b8b76 | 821 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 822 | unsigned int *); |
c906108c | 823 | |
c764a876 DE |
824 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
825 | ||
826 | static LONGEST read_checked_initial_length_and_offset | |
827 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
828 | unsigned int *, unsigned int *); | |
613e1657 | 829 | |
fe1b8b76 | 830 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
831 | unsigned int *); |
832 | ||
833 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 834 | |
fe1b8b76 | 835 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 836 | |
fe1b8b76 | 837 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 838 | |
fe1b8b76 JB |
839 | static char *read_indirect_string (bfd *, gdb_byte *, |
840 | const struct comp_unit_head *, | |
841 | unsigned int *); | |
4bdf3d34 | 842 | |
fe1b8b76 | 843 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 844 | |
fe1b8b76 | 845 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 846 | |
fe1b8b76 | 847 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 848 | |
e142c38c | 849 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 850 | |
e142c38c DJ |
851 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
852 | struct dwarf2_cu *); | |
c906108c | 853 | |
348e048f DE |
854 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
855 | unsigned int, | |
856 | struct dwarf2_cu *); | |
857 | ||
05cf31d1 JB |
858 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
859 | struct dwarf2_cu *cu); | |
860 | ||
e142c38c | 861 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 862 | |
e142c38c | 863 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 864 | struct dwarf2_cu **); |
63d06c5c | 865 | |
debd256d JB |
866 | static void free_line_header (struct line_header *lh); |
867 | ||
aaa75496 JB |
868 | static void add_file_name (struct line_header *, char *, unsigned int, |
869 | unsigned int, unsigned int); | |
870 | ||
debd256d JB |
871 | static struct line_header *(dwarf_decode_line_header |
872 | (unsigned int offset, | |
e7c27a73 | 873 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
874 | |
875 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 876 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 877 | |
4f1520fb | 878 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 879 | |
a14ed312 | 880 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 881 | struct dwarf2_cu *); |
c906108c | 882 | |
a14ed312 | 883 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 884 | struct dwarf2_cu *); |
c906108c | 885 | |
2df3850c JM |
886 | static void dwarf2_const_value_data (struct attribute *attr, |
887 | struct symbol *sym, | |
888 | int bits); | |
889 | ||
e7c27a73 | 890 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 891 | |
b4ba55a1 JB |
892 | static int need_gnat_info (struct dwarf2_cu *); |
893 | ||
894 | static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *); | |
895 | ||
896 | static void set_descriptive_type (struct type *, struct die_info *, | |
897 | struct dwarf2_cu *); | |
898 | ||
e7c27a73 DJ |
899 | static struct type *die_containing_type (struct die_info *, |
900 | struct dwarf2_cu *); | |
c906108c | 901 | |
e7c27a73 | 902 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 903 | |
f792889a | 904 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 905 | |
086ed43d | 906 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 907 | |
fe1b8b76 JB |
908 | static char *typename_concat (struct obstack *, |
909 | const char *prefix, | |
910 | const char *suffix, | |
987504bb | 911 | struct dwarf2_cu *); |
63d06c5c | 912 | |
e7c27a73 | 913 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 914 | |
348e048f DE |
915 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
916 | ||
e7c27a73 | 917 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 918 | |
e7c27a73 | 919 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 920 | |
ff013f42 JK |
921 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
922 | struct dwarf2_cu *, struct partial_symtab *); | |
923 | ||
a14ed312 | 924 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
925 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
926 | struct partial_symtab *); | |
c906108c | 927 | |
fae299cd DC |
928 | static void get_scope_pc_bounds (struct die_info *, |
929 | CORE_ADDR *, CORE_ADDR *, | |
930 | struct dwarf2_cu *); | |
931 | ||
801e3a5b JB |
932 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
933 | CORE_ADDR, struct dwarf2_cu *); | |
934 | ||
a14ed312 | 935 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 936 | struct dwarf2_cu *); |
c906108c | 937 | |
a14ed312 | 938 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 939 | struct type *, struct dwarf2_cu *); |
c906108c | 940 | |
a14ed312 | 941 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 942 | struct die_info *, struct type *, |
e7c27a73 | 943 | struct dwarf2_cu *); |
c906108c | 944 | |
a14ed312 | 945 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 946 | struct type *, struct dwarf2_cu *); |
c906108c | 947 | |
134d01f1 | 948 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 949 | |
e7c27a73 | 950 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 951 | |
e7c27a73 | 952 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 953 | |
5d7cb8df JK |
954 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
955 | ||
27aa8d6a SW |
956 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
957 | ||
38d518c9 | 958 | static const char *namespace_name (struct die_info *die, |
e142c38c | 959 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 960 | |
134d01f1 | 961 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 962 | |
e7c27a73 | 963 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 964 | |
7ca2d3a3 DL |
965 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
966 | struct dwarf2_cu *); | |
967 | ||
93311388 | 968 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 969 | |
93311388 DE |
970 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
971 | gdb_byte *info_ptr, | |
d97bc12b DE |
972 | gdb_byte **new_info_ptr, |
973 | struct die_info *parent); | |
974 | ||
93311388 DE |
975 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
976 | gdb_byte *info_ptr, | |
fe1b8b76 | 977 | gdb_byte **new_info_ptr, |
639d11d3 DC |
978 | struct die_info *parent); |
979 | ||
93311388 DE |
980 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
981 | gdb_byte *info_ptr, | |
fe1b8b76 | 982 | gdb_byte **new_info_ptr, |
639d11d3 DC |
983 | struct die_info *parent); |
984 | ||
93311388 DE |
985 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
986 | struct die_info **, gdb_byte *, | |
987 | int *); | |
988 | ||
e7c27a73 | 989 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 990 | |
71c25dea TT |
991 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
992 | struct obstack *); | |
993 | ||
e142c38c | 994 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 995 | |
e142c38c | 996 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 997 | struct dwarf2_cu **); |
9219021c | 998 | |
a14ed312 | 999 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1000 | |
a14ed312 | 1001 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1002 | |
a14ed312 | 1003 | static char *dwarf_form_name (unsigned int); |
c906108c | 1004 | |
a14ed312 | 1005 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 1006 | |
a14ed312 | 1007 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1008 | |
a14ed312 | 1009 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1010 | |
1011 | #if 0 | |
a14ed312 | 1012 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1013 | #endif |
1014 | ||
f9aca02d | 1015 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1016 | |
d97bc12b DE |
1017 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1018 | ||
1019 | static void dump_die_for_error (struct die_info *); | |
1020 | ||
1021 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1022 | struct die_info *); | |
c906108c | 1023 | |
d97bc12b | 1024 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1025 | |
51545339 | 1026 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1027 | struct dwarf2_cu *); |
c906108c | 1028 | |
93311388 DE |
1029 | static int is_ref_attr (struct attribute *); |
1030 | ||
c764a876 | 1031 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1032 | |
43bbcdc2 | 1033 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1034 | |
348e048f DE |
1035 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1036 | struct attribute *, | |
1037 | struct dwarf2_cu **); | |
1038 | ||
10b3939b DJ |
1039 | static struct die_info *follow_die_ref (struct die_info *, |
1040 | struct attribute *, | |
f2f0e013 | 1041 | struct dwarf2_cu **); |
c906108c | 1042 | |
348e048f DE |
1043 | static struct die_info *follow_die_sig (struct die_info *, |
1044 | struct attribute *, | |
1045 | struct dwarf2_cu **); | |
1046 | ||
1047 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1048 | unsigned int offset); | |
1049 | ||
1050 | static void read_signatured_type (struct objfile *, | |
1051 | struct signatured_type *type_sig); | |
1052 | ||
c906108c SS |
1053 | /* memory allocation interface */ |
1054 | ||
7b5a2f43 | 1055 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1056 | |
f3dd6933 | 1057 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1058 | |
b60c80d6 | 1059 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1060 | |
e142c38c | 1061 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1062 | |
e142c38c DJ |
1063 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1064 | struct dwarf2_cu *); | |
5fb290d7 | 1065 | |
2e276125 | 1066 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1067 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1068 | |
8e19ed76 PS |
1069 | static int attr_form_is_block (struct attribute *); |
1070 | ||
3690dd37 JB |
1071 | static int attr_form_is_section_offset (struct attribute *); |
1072 | ||
1073 | static int attr_form_is_constant (struct attribute *); | |
1074 | ||
93e7bd98 DJ |
1075 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1076 | struct symbol *sym, | |
1077 | struct dwarf2_cu *cu); | |
4c2df51b | 1078 | |
93311388 DE |
1079 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1080 | struct abbrev_info *abbrev, | |
1081 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1082 | |
72bf9492 DJ |
1083 | static void free_stack_comp_unit (void *); |
1084 | ||
72bf9492 DJ |
1085 | static hashval_t partial_die_hash (const void *item); |
1086 | ||
1087 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1088 | ||
ae038cb0 | 1089 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1090 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1091 | |
1092 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1093 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1094 | |
93311388 DE |
1095 | static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); |
1096 | ||
ae038cb0 DJ |
1097 | static void free_one_comp_unit (void *); |
1098 | ||
1099 | static void free_cached_comp_units (void *); | |
1100 | ||
1101 | static void age_cached_comp_units (void); | |
1102 | ||
1103 | static void free_one_cached_comp_unit (void *); | |
1104 | ||
f792889a DJ |
1105 | static struct type *set_die_type (struct die_info *, struct type *, |
1106 | struct dwarf2_cu *); | |
1c379e20 | 1107 | |
ae038cb0 DJ |
1108 | static void create_all_comp_units (struct objfile *); |
1109 | ||
93311388 DE |
1110 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1111 | struct objfile *); | |
10b3939b DJ |
1112 | |
1113 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1114 | ||
1115 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1116 | struct dwarf2_per_cu_data *); | |
1117 | ||
ae038cb0 DJ |
1118 | static void dwarf2_mark (struct dwarf2_cu *); |
1119 | ||
1120 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1121 | ||
f792889a | 1122 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1123 | |
c906108c SS |
1124 | /* Try to locate the sections we need for DWARF 2 debugging |
1125 | information and return true if we have enough to do something. */ | |
1126 | ||
1127 | int | |
6502dd73 | 1128 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1129 | { |
be391dca TT |
1130 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1131 | if (!dwarf2_per_objfile) | |
1132 | { | |
1133 | /* Initialize per-objfile state. */ | |
1134 | struct dwarf2_per_objfile *data | |
1135 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1136 | memset (data, 0, sizeof (*data)); | |
1137 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1138 | dwarf2_per_objfile = data; | |
6502dd73 | 1139 | |
be391dca TT |
1140 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
1141 | dwarf2_per_objfile->objfile = objfile; | |
1142 | } | |
1143 | return (dwarf2_per_objfile->info.asection != NULL | |
1144 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1145 | } |
1146 | ||
233a11ab CS |
1147 | /* When loading sections, we can either look for ".<name>", or for |
1148 | * ".z<name>", which indicates a compressed section. */ | |
1149 | ||
1150 | static int | |
dce234bc | 1151 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1152 | { |
dce234bc PP |
1153 | return (section_name[0] == '.' |
1154 | && (strcmp (section_name + 1, name) == 0 | |
1155 | || (section_name[1] == 'z' | |
1156 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1157 | } |
1158 | ||
c906108c SS |
1159 | /* This function is mapped across the sections and remembers the |
1160 | offset and size of each of the debugging sections we are interested | |
1161 | in. */ | |
1162 | ||
1163 | static void | |
72dca2f5 | 1164 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1165 | { |
dce234bc | 1166 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1167 | { |
dce234bc PP |
1168 | dwarf2_per_objfile->info.asection = sectp; |
1169 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1170 | } |
dce234bc | 1171 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1172 | { |
dce234bc PP |
1173 | dwarf2_per_objfile->abbrev.asection = sectp; |
1174 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1175 | } |
dce234bc | 1176 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1177 | { |
dce234bc PP |
1178 | dwarf2_per_objfile->line.asection = sectp; |
1179 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1180 | } |
dce234bc | 1181 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1182 | { |
dce234bc PP |
1183 | dwarf2_per_objfile->loc.asection = sectp; |
1184 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1185 | } |
dce234bc | 1186 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1187 | { |
dce234bc PP |
1188 | dwarf2_per_objfile->macinfo.asection = sectp; |
1189 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1190 | } |
dce234bc | 1191 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1192 | { |
dce234bc PP |
1193 | dwarf2_per_objfile->str.asection = sectp; |
1194 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1195 | } |
dce234bc | 1196 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1197 | { |
dce234bc PP |
1198 | dwarf2_per_objfile->frame.asection = sectp; |
1199 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1200 | } |
dce234bc | 1201 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1202 | { |
3799ccc6 EZ |
1203 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1204 | if (aflag & SEC_HAS_CONTENTS) | |
1205 | { | |
dce234bc PP |
1206 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1207 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1208 | } |
b6af0555 | 1209 | } |
dce234bc | 1210 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1211 | { |
dce234bc PP |
1212 | dwarf2_per_objfile->ranges.asection = sectp; |
1213 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1214 | } |
348e048f DE |
1215 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1216 | { | |
1217 | dwarf2_per_objfile->types.asection = sectp; | |
1218 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1219 | } | |
dce234bc | 1220 | |
72dca2f5 FR |
1221 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1222 | && bfd_section_vma (abfd, sectp) == 0) | |
1223 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1224 | } |
1225 | ||
dce234bc PP |
1226 | /* Decompress a section that was compressed using zlib. Store the |
1227 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1228 | |
1229 | static void | |
dce234bc PP |
1230 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1231 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1232 | { | |
1233 | bfd *abfd = objfile->obfd; | |
1234 | #ifndef HAVE_ZLIB_H | |
1235 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1236 | "is disabled in this copy of GDB"), | |
1237 | bfd_get_filename (abfd)); | |
1238 | #else | |
1239 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1240 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1241 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1242 | bfd_size_type uncompressed_size; |
1243 | gdb_byte *uncompressed_buffer; | |
1244 | z_stream strm; | |
1245 | int rc; | |
1246 | int header_size = 12; | |
1247 | ||
1248 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1249 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1250 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1251 | bfd_get_filename (abfd)); | |
1252 | ||
1253 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1254 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1255 | if (compressed_size < header_size | |
1256 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1257 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1258 | bfd_get_filename (abfd)); | |
1259 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1260 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1261 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1262 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1263 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1264 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1265 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1266 | uncompressed_size += compressed_buffer[11]; | |
1267 | ||
1268 | /* It is possible the section consists of several compressed | |
1269 | buffers concatenated together, so we uncompress in a loop. */ | |
1270 | strm.zalloc = NULL; | |
1271 | strm.zfree = NULL; | |
1272 | strm.opaque = NULL; | |
1273 | strm.avail_in = compressed_size - header_size; | |
1274 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1275 | strm.avail_out = uncompressed_size; | |
1276 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1277 | uncompressed_size); | |
1278 | rc = inflateInit (&strm); | |
1279 | while (strm.avail_in > 0) | |
1280 | { | |
1281 | if (rc != Z_OK) | |
1282 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1283 | bfd_get_filename (abfd), rc); | |
1284 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1285 | + (uncompressed_size - strm.avail_out)); | |
1286 | rc = inflate (&strm, Z_FINISH); | |
1287 | if (rc != Z_STREAM_END) | |
1288 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1289 | bfd_get_filename (abfd), rc); | |
1290 | rc = inflateReset (&strm); | |
1291 | } | |
1292 | rc = inflateEnd (&strm); | |
1293 | if (rc != Z_OK | |
1294 | || strm.avail_out != 0) | |
1295 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1296 | bfd_get_filename (abfd), rc); | |
1297 | ||
affddf13 | 1298 | do_cleanups (cleanup); |
dce234bc PP |
1299 | *outbuf = uncompressed_buffer; |
1300 | *outsize = uncompressed_size; | |
1301 | #endif | |
233a11ab CS |
1302 | } |
1303 | ||
dce234bc PP |
1304 | /* Read the contents of the section SECTP from object file specified by |
1305 | OBJFILE, store info about the section into INFO. | |
1306 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1307 | |
dce234bc PP |
1308 | static void |
1309 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1310 | { |
dce234bc PP |
1311 | bfd *abfd = objfile->obfd; |
1312 | asection *sectp = info->asection; | |
1313 | gdb_byte *buf, *retbuf; | |
1314 | unsigned char header[4]; | |
c906108c | 1315 | |
be391dca TT |
1316 | if (info->readin) |
1317 | return; | |
dce234bc PP |
1318 | info->buffer = NULL; |
1319 | info->was_mmapped = 0; | |
be391dca | 1320 | info->readin = 1; |
188dd5d6 | 1321 | |
dce234bc PP |
1322 | if (info->asection == NULL || info->size == 0) |
1323 | return; | |
c906108c | 1324 | |
dce234bc PP |
1325 | /* Check if the file has a 4-byte header indicating compression. */ |
1326 | if (info->size > sizeof (header) | |
1327 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1328 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1329 | { | |
1330 | /* Upon decompression, update the buffer and its size. */ | |
1331 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1332 | { | |
1333 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1334 | &info->size); | |
1335 | return; | |
1336 | } | |
1337 | } | |
4bdf3d34 | 1338 | |
dce234bc PP |
1339 | #ifdef HAVE_MMAP |
1340 | if (pagesize == 0) | |
1341 | pagesize = getpagesize (); | |
2e276125 | 1342 | |
dce234bc PP |
1343 | /* Only try to mmap sections which are large enough: we don't want to |
1344 | waste space due to fragmentation. Also, only try mmap for sections | |
1345 | without relocations. */ | |
1346 | ||
1347 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1348 | { | |
1349 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1350 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1351 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1352 | MAP_PRIVATE, pg_offset); | |
1353 | ||
1354 | if (retbuf != MAP_FAILED) | |
1355 | { | |
1356 | info->was_mmapped = 1; | |
1357 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
be391dca TT |
1358 | #if HAVE_POSIX_MADVISE |
1359 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); | |
1360 | #endif | |
dce234bc PP |
1361 | return; |
1362 | } | |
1363 | } | |
1364 | #endif | |
1365 | ||
1366 | /* If we get here, we are a normal, not-compressed section. */ | |
1367 | info->buffer = buf | |
1368 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1369 | ||
1370 | /* When debugging .o files, we may need to apply relocations; see | |
1371 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1372 | We never compress sections in .o files, so we only need to | |
1373 | try this when the section is not compressed. */ | |
ac8035ab | 1374 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1375 | if (retbuf != NULL) |
1376 | { | |
1377 | info->buffer = retbuf; | |
1378 | return; | |
1379 | } | |
1380 | ||
1381 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1382 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1383 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1384 | bfd_get_filename (abfd)); | |
1385 | } | |
1386 | ||
1387 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1388 | SECTION_NAME. */ | |
af34e669 | 1389 | |
dce234bc PP |
1390 | void |
1391 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1392 | asection **sectp, gdb_byte **bufp, | |
1393 | bfd_size_type *sizep) | |
1394 | { | |
1395 | struct dwarf2_per_objfile *data | |
1396 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1397 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1398 | |
1399 | /* We may see an objfile without any DWARF, in which case we just | |
1400 | return nothing. */ | |
1401 | if (data == NULL) | |
1402 | { | |
1403 | *sectp = NULL; | |
1404 | *bufp = NULL; | |
1405 | *sizep = 0; | |
1406 | return; | |
1407 | } | |
dce234bc PP |
1408 | if (section_is_p (section_name, EH_FRAME_SECTION)) |
1409 | info = &data->eh_frame; | |
1410 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1411 | info = &data->frame; | |
0d53c4c4 | 1412 | else |
dce234bc PP |
1413 | gdb_assert (0); |
1414 | ||
1415 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1416 | /* We haven't read this section in yet. Do it now. */ | |
1417 | dwarf2_read_section (objfile, info); | |
1418 | ||
1419 | *sectp = info->asection; | |
1420 | *bufp = info->buffer; | |
1421 | *sizep = info->size; | |
1422 | } | |
1423 | ||
1424 | /* Build a partial symbol table. */ | |
1425 | ||
1426 | void | |
f29dff0a | 1427 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 1428 | { |
f29dff0a | 1429 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
1430 | { |
1431 | init_psymbol_list (objfile, 1024); | |
1432 | } | |
1433 | ||
d146bf1e | 1434 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 1435 | } |
c906108c | 1436 | |
45452591 DE |
1437 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
1438 | ||
1439 | static inline int | |
1440 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
1441 | { | |
1442 | unsigned int bottom = cu_header->offset; | |
1443 | unsigned int top = (cu_header->offset | |
1444 | + cu_header->length | |
1445 | + cu_header->initial_length_size); | |
1446 | return (offset >= bottom && offset < top); | |
1447 | } | |
1448 | ||
93311388 DE |
1449 | /* Read in the comp unit header information from the debug_info at info_ptr. |
1450 | NOTE: This leaves members offset, first_die_offset to be filled in | |
1451 | by the caller. */ | |
107d2387 | 1452 | |
fe1b8b76 | 1453 | static gdb_byte * |
107d2387 | 1454 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1455 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1456 | { |
1457 | int signed_addr; | |
891d2f0b | 1458 | unsigned int bytes_read; |
c764a876 DE |
1459 | |
1460 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
1461 | cu_header->initial_length_size = bytes_read; | |
1462 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 1463 | info_ptr += bytes_read; |
107d2387 AC |
1464 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1465 | info_ptr += 2; | |
613e1657 | 1466 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 1467 | &bytes_read); |
613e1657 | 1468 | info_ptr += bytes_read; |
107d2387 AC |
1469 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1470 | info_ptr += 1; | |
1471 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1472 | if (signed_addr < 0) | |
8e65ff28 | 1473 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1474 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 1475 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 1476 | |
107d2387 AC |
1477 | return info_ptr; |
1478 | } | |
1479 | ||
fe1b8b76 JB |
1480 | static gdb_byte * |
1481 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 1482 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
1483 | bfd *abfd) |
1484 | { | |
fe1b8b76 | 1485 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1486 | |
1487 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1488 | ||
2dc7f7b3 | 1489 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 1490 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
1491 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
1492 | bfd_get_filename (abfd)); | |
72bf9492 | 1493 | |
dce234bc | 1494 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
1495 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1496 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 1497 | (long) header->abbrev_offset, |
93311388 | 1498 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
1499 | bfd_get_filename (abfd)); |
1500 | ||
1501 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 1502 | > buffer + buffer_size) |
8a3fe4f8 AC |
1503 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1504 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 1505 | (long) header->length, |
93311388 | 1506 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
1507 | bfd_get_filename (abfd)); |
1508 | ||
1509 | return info_ptr; | |
1510 | } | |
1511 | ||
348e048f DE |
1512 | /* Read in the types comp unit header information from .debug_types entry at |
1513 | types_ptr. The result is a pointer to one past the end of the header. */ | |
1514 | ||
1515 | static gdb_byte * | |
1516 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
1517 | ULONGEST *signature, | |
1518 | gdb_byte *types_ptr, bfd *abfd) | |
1519 | { | |
348e048f DE |
1520 | gdb_byte *initial_types_ptr = types_ptr; |
1521 | ||
fa238c03 MS |
1522 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
1523 | &dwarf2_per_objfile->types); | |
348e048f DE |
1524 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
1525 | ||
1526 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
1527 | ||
1528 | *signature = read_8_bytes (abfd, types_ptr); | |
1529 | types_ptr += 8; | |
1530 | types_ptr += cu_header->offset_size; | |
1531 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
1532 | ||
1533 | return types_ptr; | |
1534 | } | |
1535 | ||
aaa75496 JB |
1536 | /* Allocate a new partial symtab for file named NAME and mark this new |
1537 | partial symtab as being an include of PST. */ | |
1538 | ||
1539 | static void | |
1540 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1541 | struct objfile *objfile) | |
1542 | { | |
1543 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1544 | ||
1545 | subpst->section_offsets = pst->section_offsets; | |
1546 | subpst->textlow = 0; | |
1547 | subpst->texthigh = 0; | |
1548 | ||
1549 | subpst->dependencies = (struct partial_symtab **) | |
1550 | obstack_alloc (&objfile->objfile_obstack, | |
1551 | sizeof (struct partial_symtab *)); | |
1552 | subpst->dependencies[0] = pst; | |
1553 | subpst->number_of_dependencies = 1; | |
1554 | ||
1555 | subpst->globals_offset = 0; | |
1556 | subpst->n_global_syms = 0; | |
1557 | subpst->statics_offset = 0; | |
1558 | subpst->n_static_syms = 0; | |
1559 | subpst->symtab = NULL; | |
1560 | subpst->read_symtab = pst->read_symtab; | |
1561 | subpst->readin = 0; | |
1562 | ||
1563 | /* No private part is necessary for include psymtabs. This property | |
1564 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1565 | the regular ones. */ |
58a9656e | 1566 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1567 | } |
1568 | ||
1569 | /* Read the Line Number Program data and extract the list of files | |
1570 | included by the source file represented by PST. Build an include | |
d85a05f0 | 1571 | partial symtab for each of these included files. */ |
aaa75496 JB |
1572 | |
1573 | static void | |
1574 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 1575 | struct die_info *die, |
aaa75496 JB |
1576 | struct partial_symtab *pst) |
1577 | { | |
1578 | struct objfile *objfile = cu->objfile; | |
1579 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
1580 | struct line_header *lh = NULL; |
1581 | struct attribute *attr; | |
aaa75496 | 1582 | |
d85a05f0 DJ |
1583 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
1584 | if (attr) | |
1585 | { | |
1586 | unsigned int line_offset = DW_UNSND (attr); | |
1587 | lh = dwarf_decode_line_header (line_offset, abfd, cu); | |
1588 | } | |
aaa75496 JB |
1589 | if (lh == NULL) |
1590 | return; /* No linetable, so no includes. */ | |
1591 | ||
1592 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1593 | ||
1594 | free_line_header (lh); | |
1595 | } | |
1596 | ||
348e048f DE |
1597 | static hashval_t |
1598 | hash_type_signature (const void *item) | |
1599 | { | |
1600 | const struct signatured_type *type_sig = item; | |
1601 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ | |
1602 | return type_sig->signature; | |
1603 | } | |
1604 | ||
1605 | static int | |
1606 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
1607 | { | |
1608 | const struct signatured_type *lhs = item_lhs; | |
1609 | const struct signatured_type *rhs = item_rhs; | |
1610 | return lhs->signature == rhs->signature; | |
1611 | } | |
1612 | ||
1613 | /* Create the hash table of all entries in the .debug_types section. | |
1614 | The result is zero if there is an error (e.g. missing .debug_types section), | |
1615 | otherwise non-zero. */ | |
1616 | ||
1617 | static int | |
1618 | create_debug_types_hash_table (struct objfile *objfile) | |
1619 | { | |
be391dca | 1620 | gdb_byte *info_ptr; |
348e048f DE |
1621 | htab_t types_htab; |
1622 | ||
be391dca TT |
1623 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
1624 | info_ptr = dwarf2_per_objfile->types.buffer; | |
1625 | ||
348e048f DE |
1626 | if (info_ptr == NULL) |
1627 | { | |
1628 | dwarf2_per_objfile->signatured_types = NULL; | |
1629 | return 0; | |
1630 | } | |
1631 | ||
1632 | types_htab = htab_create_alloc_ex (41, | |
1633 | hash_type_signature, | |
1634 | eq_type_signature, | |
1635 | NULL, | |
1636 | &objfile->objfile_obstack, | |
1637 | hashtab_obstack_allocate, | |
1638 | dummy_obstack_deallocate); | |
1639 | ||
1640 | if (dwarf2_die_debug) | |
1641 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
1642 | ||
1643 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
1644 | { | |
1645 | unsigned int offset; | |
1646 | unsigned int offset_size; | |
1647 | unsigned int type_offset; | |
1648 | unsigned int length, initial_length_size; | |
1649 | unsigned short version; | |
1650 | ULONGEST signature; | |
1651 | struct signatured_type *type_sig; | |
1652 | void **slot; | |
1653 | gdb_byte *ptr = info_ptr; | |
1654 | ||
1655 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
1656 | ||
1657 | /* We need to read the type's signature in order to build the hash | |
1658 | table, but we don't need to read anything else just yet. */ | |
1659 | ||
1660 | /* Sanity check to ensure entire cu is present. */ | |
1661 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
1662 | if (ptr + length + initial_length_size | |
1663 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
1664 | { | |
1665 | complaint (&symfile_complaints, | |
1666 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
1667 | break; | |
1668 | } | |
1669 | ||
1670 | offset_size = initial_length_size == 4 ? 4 : 8; | |
1671 | ptr += initial_length_size; | |
1672 | version = bfd_get_16 (objfile->obfd, ptr); | |
1673 | ptr += 2; | |
1674 | ptr += offset_size; /* abbrev offset */ | |
1675 | ptr += 1; /* address size */ | |
1676 | signature = bfd_get_64 (objfile->obfd, ptr); | |
1677 | ptr += 8; | |
1678 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
1679 | ||
1680 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
1681 | memset (type_sig, 0, sizeof (*type_sig)); | |
1682 | type_sig->signature = signature; | |
1683 | type_sig->offset = offset; | |
1684 | type_sig->type_offset = type_offset; | |
1685 | ||
1686 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
1687 | gdb_assert (slot != NULL); | |
1688 | *slot = type_sig; | |
1689 | ||
1690 | if (dwarf2_die_debug) | |
1691 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
1692 | offset, phex (signature, sizeof (signature))); | |
1693 | ||
1694 | info_ptr = info_ptr + initial_length_size + length; | |
1695 | } | |
1696 | ||
1697 | dwarf2_per_objfile->signatured_types = types_htab; | |
1698 | ||
1699 | return 1; | |
1700 | } | |
1701 | ||
1702 | /* Lookup a signature based type. | |
1703 | Returns NULL if SIG is not present in the table. */ | |
1704 | ||
1705 | static struct signatured_type * | |
1706 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
1707 | { | |
1708 | struct signatured_type find_entry, *entry; | |
1709 | ||
1710 | if (dwarf2_per_objfile->signatured_types == NULL) | |
1711 | { | |
1712 | complaint (&symfile_complaints, | |
1713 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
1714 | return 0; | |
1715 | } | |
1716 | ||
1717 | find_entry.signature = sig; | |
1718 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
1719 | return entry; | |
1720 | } | |
1721 | ||
d85a05f0 DJ |
1722 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
1723 | ||
1724 | static void | |
1725 | init_cu_die_reader (struct die_reader_specs *reader, | |
1726 | struct dwarf2_cu *cu) | |
1727 | { | |
1728 | reader->abfd = cu->objfile->obfd; | |
1729 | reader->cu = cu; | |
1730 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
1731 | { |
1732 | gdb_assert (dwarf2_per_objfile->types.readin); | |
1733 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
1734 | } | |
d85a05f0 | 1735 | else |
be391dca TT |
1736 | { |
1737 | gdb_assert (dwarf2_per_objfile->info.readin); | |
1738 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
1739 | } | |
d85a05f0 DJ |
1740 | } |
1741 | ||
1742 | /* Find the base address of the compilation unit for range lists and | |
1743 | location lists. It will normally be specified by DW_AT_low_pc. | |
1744 | In DWARF-3 draft 4, the base address could be overridden by | |
1745 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
1746 | compilation units with discontinuous ranges. */ | |
1747 | ||
1748 | static void | |
1749 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
1750 | { | |
1751 | struct attribute *attr; | |
1752 | ||
1753 | cu->base_known = 0; | |
1754 | cu->base_address = 0; | |
1755 | ||
1756 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
1757 | if (attr) | |
1758 | { | |
1759 | cu->base_address = DW_ADDR (attr); | |
1760 | cu->base_known = 1; | |
1761 | } | |
1762 | else | |
1763 | { | |
1764 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
1765 | if (attr) | |
1766 | { | |
1767 | cu->base_address = DW_ADDR (attr); | |
1768 | cu->base_known = 1; | |
1769 | } | |
1770 | } | |
1771 | } | |
1772 | ||
348e048f DE |
1773 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
1774 | to combine the common parts. | |
93311388 | 1775 | Process a compilation unit for a psymtab. |
348e048f DE |
1776 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
1777 | either .debug_info or debug_types. | |
93311388 DE |
1778 | INFO_PTR is a pointer to the start of the CU. |
1779 | Returns a pointer to the next CU. */ | |
aaa75496 | 1780 | |
93311388 DE |
1781 | static gdb_byte * |
1782 | process_psymtab_comp_unit (struct objfile *objfile, | |
1783 | struct dwarf2_per_cu_data *this_cu, | |
1784 | gdb_byte *buffer, gdb_byte *info_ptr, | |
1785 | unsigned int buffer_size) | |
c906108c | 1786 | { |
c906108c | 1787 | bfd *abfd = objfile->obfd; |
93311388 | 1788 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 1789 | struct die_info *comp_unit_die; |
c906108c | 1790 | struct partial_symtab *pst; |
5734ee8b | 1791 | CORE_ADDR baseaddr; |
93311388 DE |
1792 | struct cleanup *back_to_inner; |
1793 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
1794 | int has_children, has_pc_info; |
1795 | struct attribute *attr; | |
d85a05f0 DJ |
1796 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
1797 | struct die_reader_specs reader_specs; | |
c906108c | 1798 | |
93311388 DE |
1799 | memset (&cu, 0, sizeof (cu)); |
1800 | cu.objfile = objfile; | |
1801 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 1802 | |
93311388 | 1803 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 1804 | |
93311388 DE |
1805 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
1806 | buffer, buffer_size, | |
1807 | abfd); | |
10b3939b | 1808 | |
93311388 DE |
1809 | /* Complete the cu_header. */ |
1810 | cu.header.offset = beg_of_comp_unit - buffer; | |
1811 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 1812 | |
93311388 | 1813 | cu.list_in_scope = &file_symbols; |
af703f96 | 1814 | |
328c9494 DJ |
1815 | /* If this compilation unit was already read in, free the |
1816 | cached copy in order to read it in again. This is | |
1817 | necessary because we skipped some symbols when we first | |
1818 | read in the compilation unit (see load_partial_dies). | |
1819 | This problem could be avoided, but the benefit is | |
1820 | unclear. */ | |
1821 | if (this_cu->cu != NULL) | |
1822 | free_one_cached_comp_unit (this_cu->cu); | |
1823 | ||
1824 | /* Note that this is a pointer to our stack frame, being | |
1825 | added to a global data structure. It will be cleaned up | |
1826 | in free_stack_comp_unit when we finish with this | |
1827 | compilation unit. */ | |
1828 | this_cu->cu = &cu; | |
d85a05f0 DJ |
1829 | cu.per_cu = this_cu; |
1830 | ||
93311388 DE |
1831 | /* Read the abbrevs for this compilation unit into a table. */ |
1832 | dwarf2_read_abbrevs (abfd, &cu); | |
1833 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 1834 | |
93311388 | 1835 | /* Read the compilation unit die. */ |
348e048f DE |
1836 | if (this_cu->from_debug_types) |
1837 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
1838 | init_cu_die_reader (&reader_specs, &cu); |
1839 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
1840 | &has_children); | |
93311388 | 1841 | |
348e048f DE |
1842 | if (this_cu->from_debug_types) |
1843 | { | |
1844 | /* offset,length haven't been set yet for type units. */ | |
1845 | this_cu->offset = cu.header.offset; | |
1846 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
1847 | } | |
d85a05f0 | 1848 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 1849 | { |
93311388 DE |
1850 | info_ptr = (beg_of_comp_unit + cu.header.length |
1851 | + cu.header.initial_length_size); | |
1852 | do_cleanups (back_to_inner); | |
1853 | return info_ptr; | |
1854 | } | |
72bf9492 | 1855 | |
93311388 | 1856 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
1857 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
1858 | if (attr) | |
1859 | set_cu_language (DW_UNSND (attr), &cu); | |
1860 | else | |
1861 | set_cu_language (language_minimal, &cu); | |
c906108c | 1862 | |
93311388 | 1863 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 1864 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 1865 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 1866 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
1867 | /* TEXTLOW and TEXTHIGH are set below. */ |
1868 | 0, | |
1869 | objfile->global_psymbols.next, | |
1870 | objfile->static_psymbols.next); | |
72bf9492 | 1871 | |
d85a05f0 DJ |
1872 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
1873 | if (attr != NULL) | |
1874 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 1875 | |
e38df1d0 | 1876 | pst->read_symtab_private = this_cu; |
72bf9492 | 1877 | |
93311388 | 1878 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 1879 | |
93311388 DE |
1880 | /* Store the function that reads in the rest of the symbol table */ |
1881 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 1882 | |
93311388 | 1883 | this_cu->psymtab = pst; |
c906108c | 1884 | |
d85a05f0 DJ |
1885 | dwarf2_find_base_address (comp_unit_die, &cu); |
1886 | ||
93311388 DE |
1887 | /* Possibly set the default values of LOWPC and HIGHPC from |
1888 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
1889 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
1890 | &best_highpc, &cu, pst); | |
1891 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
1892 | /* Store the contiguous range if it is not empty; it can be empty for |
1893 | CUs with no code. */ | |
1894 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
1895 | best_lowpc + baseaddr, |
1896 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
1897 | |
1898 | /* Check if comp unit has_children. | |
1899 | If so, read the rest of the partial symbols from this comp unit. | |
1900 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 1901 | if (has_children) |
93311388 DE |
1902 | { |
1903 | struct partial_die_info *first_die; | |
1904 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 1905 | |
93311388 DE |
1906 | lowpc = ((CORE_ADDR) -1); |
1907 | highpc = ((CORE_ADDR) 0); | |
c906108c | 1908 | |
93311388 | 1909 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 1910 | |
93311388 | 1911 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 1912 | ! has_pc_info, &cu); |
57c22c6c | 1913 | |
93311388 DE |
1914 | /* If we didn't find a lowpc, set it to highpc to avoid |
1915 | complaints from `maint check'. */ | |
1916 | if (lowpc == ((CORE_ADDR) -1)) | |
1917 | lowpc = highpc; | |
10b3939b | 1918 | |
93311388 DE |
1919 | /* If the compilation unit didn't have an explicit address range, |
1920 | then use the information extracted from its child dies. */ | |
d85a05f0 | 1921 | if (! has_pc_info) |
93311388 | 1922 | { |
d85a05f0 DJ |
1923 | best_lowpc = lowpc; |
1924 | best_highpc = highpc; | |
93311388 DE |
1925 | } |
1926 | } | |
d85a05f0 DJ |
1927 | pst->textlow = best_lowpc + baseaddr; |
1928 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 1929 | |
93311388 DE |
1930 | pst->n_global_syms = objfile->global_psymbols.next - |
1931 | (objfile->global_psymbols.list + pst->globals_offset); | |
1932 | pst->n_static_syms = objfile->static_psymbols.next - | |
1933 | (objfile->static_psymbols.list + pst->statics_offset); | |
1934 | sort_pst_symbols (pst); | |
c906108c | 1935 | |
93311388 DE |
1936 | info_ptr = (beg_of_comp_unit + cu.header.length |
1937 | + cu.header.initial_length_size); | |
ae038cb0 | 1938 | |
348e048f DE |
1939 | if (this_cu->from_debug_types) |
1940 | { | |
1941 | /* It's not clear we want to do anything with stmt lists here. | |
1942 | Waiting to see what gcc ultimately does. */ | |
1943 | } | |
d85a05f0 | 1944 | else |
93311388 DE |
1945 | { |
1946 | /* Get the list of files included in the current compilation unit, | |
1947 | and build a psymtab for each of them. */ | |
d85a05f0 | 1948 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 1949 | } |
ae038cb0 | 1950 | |
93311388 | 1951 | do_cleanups (back_to_inner); |
ae038cb0 | 1952 | |
93311388 DE |
1953 | return info_ptr; |
1954 | } | |
ff013f42 | 1955 | |
348e048f DE |
1956 | /* Traversal function for htab_traverse_noresize. |
1957 | Process one .debug_types comp-unit. */ | |
1958 | ||
1959 | static int | |
1960 | process_type_comp_unit (void **slot, void *info) | |
1961 | { | |
1962 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
1963 | struct objfile *objfile = (struct objfile *) info; | |
1964 | struct dwarf2_per_cu_data *this_cu; | |
1965 | ||
1966 | this_cu = &entry->per_cu; | |
1967 | this_cu->from_debug_types = 1; | |
1968 | ||
be391dca | 1969 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
1970 | process_psymtab_comp_unit (objfile, this_cu, |
1971 | dwarf2_per_objfile->types.buffer, | |
1972 | dwarf2_per_objfile->types.buffer + entry->offset, | |
1973 | dwarf2_per_objfile->types.size); | |
1974 | ||
1975 | return 1; | |
1976 | } | |
1977 | ||
1978 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
1979 | Build partial symbol tables for the .debug_types comp-units. */ | |
1980 | ||
1981 | static void | |
1982 | build_type_psymtabs (struct objfile *objfile) | |
1983 | { | |
1984 | if (! create_debug_types_hash_table (objfile)) | |
1985 | return; | |
1986 | ||
1987 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
1988 | process_type_comp_unit, objfile); | |
1989 | } | |
1990 | ||
93311388 DE |
1991 | /* Build the partial symbol table by doing a quick pass through the |
1992 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 1993 | |
93311388 | 1994 | static void |
c67a9c90 | 1995 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 1996 | { |
93311388 DE |
1997 | gdb_byte *info_ptr; |
1998 | struct cleanup *back_to; | |
1999 | ||
be391dca | 2000 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 2001 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 2002 | |
93311388 DE |
2003 | /* Any cached compilation units will be linked by the per-objfile |
2004 | read_in_chain. Make sure to free them when we're done. */ | |
2005 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 2006 | |
348e048f DE |
2007 | build_type_psymtabs (objfile); |
2008 | ||
93311388 | 2009 | create_all_comp_units (objfile); |
c906108c | 2010 | |
93311388 DE |
2011 | objfile->psymtabs_addrmap = |
2012 | addrmap_create_mutable (&objfile->objfile_obstack); | |
72bf9492 | 2013 | |
93311388 DE |
2014 | /* Since the objects we're extracting from .debug_info vary in |
2015 | length, only the individual functions to extract them (like | |
2016 | read_comp_unit_head and load_partial_die) can really know whether | |
2017 | the buffer is large enough to hold another complete object. | |
c906108c | 2018 | |
93311388 DE |
2019 | At the moment, they don't actually check that. If .debug_info |
2020 | holds just one extra byte after the last compilation unit's dies, | |
2021 | then read_comp_unit_head will happily read off the end of the | |
2022 | buffer. read_partial_die is similarly casual. Those functions | |
2023 | should be fixed. | |
c906108c | 2024 | |
93311388 DE |
2025 | For this loop condition, simply checking whether there's any data |
2026 | left at all should be sufficient. */ | |
c906108c | 2027 | |
93311388 DE |
2028 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
2029 | + dwarf2_per_objfile->info.size)) | |
2030 | { | |
2031 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 2032 | |
93311388 DE |
2033 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
2034 | objfile); | |
aaa75496 | 2035 | |
93311388 DE |
2036 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
2037 | dwarf2_per_objfile->info.buffer, | |
2038 | info_ptr, | |
2039 | dwarf2_per_objfile->info.size); | |
c906108c | 2040 | } |
ff013f42 JK |
2041 | |
2042 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
2043 | &objfile->objfile_obstack); | |
2044 | ||
ae038cb0 DJ |
2045 | do_cleanups (back_to); |
2046 | } | |
2047 | ||
93311388 | 2048 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
2049 | |
2050 | static void | |
93311388 DE |
2051 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
2052 | struct objfile *objfile) | |
ae038cb0 DJ |
2053 | { |
2054 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 2055 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 2056 | struct die_info *comp_unit_die; |
ae038cb0 | 2057 | struct dwarf2_cu *cu; |
ae038cb0 | 2058 | struct cleanup *back_to; |
d85a05f0 DJ |
2059 | struct attribute *attr; |
2060 | int has_children; | |
2061 | struct die_reader_specs reader_specs; | |
ae038cb0 | 2062 | |
348e048f DE |
2063 | gdb_assert (! this_cu->from_debug_types); |
2064 | ||
be391dca | 2065 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 2066 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
2067 | beg_of_comp_unit = info_ptr; |
2068 | ||
93311388 | 2069 | cu = alloc_one_comp_unit (objfile); |
ae038cb0 | 2070 | |
93311388 | 2071 | /* ??? Missing cleanup for CU? */ |
ae038cb0 | 2072 | |
328c9494 DJ |
2073 | /* Link this compilation unit into the compilation unit tree. */ |
2074 | this_cu->cu = cu; | |
2075 | cu->per_cu = this_cu; | |
2076 | cu->type_hash = this_cu->type_hash; | |
2077 | ||
93311388 DE |
2078 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
2079 | dwarf2_per_objfile->info.buffer, | |
2080 | dwarf2_per_objfile->info.size, | |
2081 | abfd); | |
ae038cb0 DJ |
2082 | |
2083 | /* Complete the cu_header. */ | |
93311388 | 2084 | cu->header.offset = this_cu->offset; |
d00adf39 | 2085 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
2086 | |
2087 | /* Read the abbrevs for this compilation unit into a table. */ | |
2088 | dwarf2_read_abbrevs (abfd, cu); | |
2089 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2090 | ||
2091 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
2092 | init_cu_die_reader (&reader_specs, cu); |
2093 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2094 | &has_children); | |
ae038cb0 DJ |
2095 | |
2096 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
2097 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
2098 | if (attr) | |
2099 | set_cu_language (DW_UNSND (attr), cu); | |
2100 | else | |
2101 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 2102 | |
ae038cb0 DJ |
2103 | /* Check if comp unit has_children. |
2104 | If so, read the rest of the partial symbols from this comp unit. | |
2105 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 2106 | if (has_children) |
93311388 | 2107 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 DJ |
2108 | |
2109 | do_cleanups (back_to); | |
2110 | } | |
2111 | ||
2112 | /* Create a list of all compilation units in OBJFILE. We do this only | |
2113 | if an inter-comp-unit reference is found; presumably if there is one, | |
2114 | there will be many, and one will occur early in the .debug_info section. | |
2115 | So there's no point in building this list incrementally. */ | |
2116 | ||
2117 | static void | |
2118 | create_all_comp_units (struct objfile *objfile) | |
2119 | { | |
2120 | int n_allocated; | |
2121 | int n_comp_units; | |
2122 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
2123 | gdb_byte *info_ptr; |
2124 | ||
2125 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
2126 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
2127 | |
2128 | n_comp_units = 0; | |
2129 | n_allocated = 10; | |
2130 | all_comp_units = xmalloc (n_allocated | |
2131 | * sizeof (struct dwarf2_per_cu_data *)); | |
2132 | ||
dce234bc | 2133 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 2134 | { |
c764a876 | 2135 | unsigned int length, initial_length_size; |
ae038cb0 | 2136 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 2137 | unsigned int offset; |
ae038cb0 | 2138 | |
dce234bc | 2139 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
2140 | |
2141 | /* Read just enough information to find out where the next | |
2142 | compilation unit is. */ | |
c764a876 DE |
2143 | length = read_initial_length (objfile->obfd, info_ptr, |
2144 | &initial_length_size); | |
ae038cb0 DJ |
2145 | |
2146 | /* Save the compilation unit for later lookup. */ | |
2147 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
2148 | sizeof (struct dwarf2_per_cu_data)); | |
2149 | memset (this_cu, 0, sizeof (*this_cu)); | |
2150 | this_cu->offset = offset; | |
c764a876 | 2151 | this_cu->length = length + initial_length_size; |
ae038cb0 DJ |
2152 | |
2153 | if (n_comp_units == n_allocated) | |
2154 | { | |
2155 | n_allocated *= 2; | |
2156 | all_comp_units = xrealloc (all_comp_units, | |
2157 | n_allocated | |
2158 | * sizeof (struct dwarf2_per_cu_data *)); | |
2159 | } | |
2160 | all_comp_units[n_comp_units++] = this_cu; | |
2161 | ||
2162 | info_ptr = info_ptr + this_cu->length; | |
2163 | } | |
2164 | ||
2165 | dwarf2_per_objfile->all_comp_units | |
2166 | = obstack_alloc (&objfile->objfile_obstack, | |
2167 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
2168 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
2169 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
2170 | xfree (all_comp_units); | |
2171 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
2172 | } |
2173 | ||
5734ee8b DJ |
2174 | /* Process all loaded DIEs for compilation unit CU, starting at |
2175 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
2176 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
2177 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
2178 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
2179 | and record the covered ranges in the addrmap. */ | |
c906108c | 2180 | |
72bf9492 DJ |
2181 | static void |
2182 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 2183 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 2184 | { |
72bf9492 | 2185 | struct partial_die_info *pdi; |
c906108c | 2186 | |
91c24f0a DC |
2187 | /* Now, march along the PDI's, descending into ones which have |
2188 | interesting children but skipping the children of the other ones, | |
2189 | until we reach the end of the compilation unit. */ | |
c906108c | 2190 | |
72bf9492 | 2191 | pdi = first_die; |
91c24f0a | 2192 | |
72bf9492 DJ |
2193 | while (pdi != NULL) |
2194 | { | |
2195 | fixup_partial_die (pdi, cu); | |
c906108c | 2196 | |
91c24f0a DC |
2197 | /* Anonymous namespaces have no name but have interesting |
2198 | children, so we need to look at them. Ditto for anonymous | |
2199 | enums. */ | |
933c6fe4 | 2200 | |
72bf9492 DJ |
2201 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
2202 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 2203 | { |
72bf9492 | 2204 | switch (pdi->tag) |
c906108c SS |
2205 | { |
2206 | case DW_TAG_subprogram: | |
5734ee8b | 2207 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
2208 | break; |
2209 | case DW_TAG_variable: | |
2210 | case DW_TAG_typedef: | |
91c24f0a | 2211 | case DW_TAG_union_type: |
72bf9492 | 2212 | if (!pdi->is_declaration) |
63d06c5c | 2213 | { |
72bf9492 | 2214 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
2215 | } |
2216 | break; | |
c906108c | 2217 | case DW_TAG_class_type: |
680b30c7 | 2218 | case DW_TAG_interface_type: |
c906108c | 2219 | case DW_TAG_structure_type: |
72bf9492 | 2220 | if (!pdi->is_declaration) |
c906108c | 2221 | { |
72bf9492 | 2222 | add_partial_symbol (pdi, cu); |
c906108c SS |
2223 | } |
2224 | break; | |
91c24f0a | 2225 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
2226 | if (!pdi->is_declaration) |
2227 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
2228 | break; |
2229 | case DW_TAG_base_type: | |
a02abb62 | 2230 | case DW_TAG_subrange_type: |
c906108c | 2231 | /* File scope base type definitions are added to the partial |
c5aa993b | 2232 | symbol table. */ |
72bf9492 | 2233 | add_partial_symbol (pdi, cu); |
c906108c | 2234 | break; |
d9fa45fe | 2235 | case DW_TAG_namespace: |
5734ee8b | 2236 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 2237 | break; |
5d7cb8df JK |
2238 | case DW_TAG_module: |
2239 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
2240 | break; | |
c906108c SS |
2241 | default: |
2242 | break; | |
2243 | } | |
2244 | } | |
2245 | ||
72bf9492 DJ |
2246 | /* If the die has a sibling, skip to the sibling. */ |
2247 | ||
2248 | pdi = pdi->die_sibling; | |
2249 | } | |
2250 | } | |
2251 | ||
2252 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 2253 | |
72bf9492 | 2254 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
2255 | name is concatenated with "::" and the partial DIE's name. For |
2256 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
2257 | Enumerators are an exception; they use the scope of their parent |
2258 | enumeration type, i.e. the name of the enumeration type is not | |
2259 | prepended to the enumerator. | |
91c24f0a | 2260 | |
72bf9492 DJ |
2261 | There are two complexities. One is DW_AT_specification; in this |
2262 | case "parent" means the parent of the target of the specification, | |
2263 | instead of the direct parent of the DIE. The other is compilers | |
2264 | which do not emit DW_TAG_namespace; in this case we try to guess | |
2265 | the fully qualified name of structure types from their members' | |
2266 | linkage names. This must be done using the DIE's children rather | |
2267 | than the children of any DW_AT_specification target. We only need | |
2268 | to do this for structures at the top level, i.e. if the target of | |
2269 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
2270 | have a parent. */ | |
2271 | ||
2272 | /* Compute the scope prefix associated with PDI's parent, in | |
2273 | compilation unit CU. The result will be allocated on CU's | |
2274 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
2275 | field. NULL is returned if no prefix is necessary. */ | |
2276 | static char * | |
2277 | partial_die_parent_scope (struct partial_die_info *pdi, | |
2278 | struct dwarf2_cu *cu) | |
2279 | { | |
2280 | char *grandparent_scope; | |
2281 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 2282 | |
72bf9492 DJ |
2283 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
2284 | then this means the parent of the specification DIE. */ | |
2285 | ||
2286 | real_pdi = pdi; | |
72bf9492 | 2287 | while (real_pdi->has_specification) |
10b3939b | 2288 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
2289 | |
2290 | parent = real_pdi->die_parent; | |
2291 | if (parent == NULL) | |
2292 | return NULL; | |
2293 | ||
2294 | if (parent->scope_set) | |
2295 | return parent->scope; | |
2296 | ||
2297 | fixup_partial_die (parent, cu); | |
2298 | ||
10b3939b | 2299 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 2300 | |
acebe513 UW |
2301 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
2302 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
2303 | Work around this problem here. */ | |
2304 | if (cu->language == language_cplus | |
2305 | && parent->tag == DW_TAG_namespace | |
2306 | && strcmp (parent->name, "::") == 0 | |
2307 | && grandparent_scope == NULL) | |
2308 | { | |
2309 | parent->scope = NULL; | |
2310 | parent->scope_set = 1; | |
2311 | return NULL; | |
2312 | } | |
2313 | ||
72bf9492 DJ |
2314 | if (parent->tag == DW_TAG_namespace |
2315 | || parent->tag == DW_TAG_structure_type | |
2316 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 2317 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
2318 | || parent->tag == DW_TAG_union_type |
2319 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
2320 | { |
2321 | if (grandparent_scope == NULL) | |
2322 | parent->scope = parent->name; | |
2323 | else | |
987504bb JJ |
2324 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
2325 | parent->name, cu); | |
72bf9492 | 2326 | } |
ceeb3d5a | 2327 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
2328 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
2329 | parent->scope = grandparent_scope; | |
2330 | else | |
2331 | { | |
2332 | /* FIXME drow/2004-04-01: What should we be doing with | |
2333 | function-local names? For partial symbols, we should probably be | |
2334 | ignoring them. */ | |
2335 | complaint (&symfile_complaints, | |
e2e0b3e5 | 2336 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
2337 | parent->tag, pdi->offset); |
2338 | parent->scope = grandparent_scope; | |
c906108c SS |
2339 | } |
2340 | ||
72bf9492 DJ |
2341 | parent->scope_set = 1; |
2342 | return parent->scope; | |
2343 | } | |
2344 | ||
2345 | /* Return the fully scoped name associated with PDI, from compilation unit | |
2346 | CU. The result will be allocated with malloc. */ | |
2347 | static char * | |
2348 | partial_die_full_name (struct partial_die_info *pdi, | |
2349 | struct dwarf2_cu *cu) | |
2350 | { | |
2351 | char *parent_scope; | |
2352 | ||
2353 | parent_scope = partial_die_parent_scope (pdi, cu); | |
2354 | if (parent_scope == NULL) | |
2355 | return NULL; | |
2356 | else | |
987504bb | 2357 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
2358 | } |
2359 | ||
2360 | static void | |
72bf9492 | 2361 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 2362 | { |
e7c27a73 | 2363 | struct objfile *objfile = cu->objfile; |
c906108c | 2364 | CORE_ADDR addr = 0; |
decbce07 | 2365 | char *actual_name = NULL; |
5c4e30ca | 2366 | const struct partial_symbol *psym = NULL; |
e142c38c | 2367 | CORE_ADDR baseaddr; |
72bf9492 | 2368 | int built_actual_name = 0; |
e142c38c DJ |
2369 | |
2370 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2371 | |
94af9270 KS |
2372 | actual_name = partial_die_full_name (pdi, cu); |
2373 | if (actual_name) | |
2374 | built_actual_name = 1; | |
63d06c5c | 2375 | |
72bf9492 DJ |
2376 | if (actual_name == NULL) |
2377 | actual_name = pdi->name; | |
2378 | ||
c906108c SS |
2379 | switch (pdi->tag) |
2380 | { | |
2381 | case DW_TAG_subprogram: | |
2cfa0c8d | 2382 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 2383 | { |
2cfa0c8d JB |
2384 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
2385 | of the global scope. But in Ada, we want to be able to access | |
2386 | nested procedures globally. So all Ada subprograms are stored | |
2387 | in the global scope. */ | |
38d518c9 | 2388 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2389 | mst_text, objfile); */ |
38d518c9 | 2390 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2391 | built_actual_name, |
5c4e30ca DC |
2392 | VAR_DOMAIN, LOC_BLOCK, |
2393 | &objfile->global_psymbols, | |
2394 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2395 | cu->language, objfile); |
c906108c SS |
2396 | } |
2397 | else | |
2398 | { | |
38d518c9 | 2399 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2400 | mst_file_text, objfile); */ |
38d518c9 | 2401 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2402 | built_actual_name, |
5c4e30ca DC |
2403 | VAR_DOMAIN, LOC_BLOCK, |
2404 | &objfile->static_psymbols, | |
2405 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2406 | cu->language, objfile); |
c906108c SS |
2407 | } |
2408 | break; | |
2409 | case DW_TAG_variable: | |
2410 | if (pdi->is_external) | |
2411 | { | |
2412 | /* Global Variable. | |
2413 | Don't enter into the minimal symbol tables as there is | |
2414 | a minimal symbol table entry from the ELF symbols already. | |
2415 | Enter into partial symbol table if it has a location | |
2416 | descriptor or a type. | |
2417 | If the location descriptor is missing, new_symbol will create | |
2418 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
2419 | be determined from the minimal symbol table whenever the variable | |
2420 | is referenced. | |
2421 | The address for the partial symbol table entry is not | |
2422 | used by GDB, but it comes in handy for debugging partial symbol | |
2423 | table building. */ | |
2424 | ||
2425 | if (pdi->locdesc) | |
e7c27a73 | 2426 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2427 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2428 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2429 | built_actual_name, |
5c4e30ca DC |
2430 | VAR_DOMAIN, LOC_STATIC, |
2431 | &objfile->global_psymbols, | |
2432 | 0, addr + baseaddr, | |
e142c38c | 2433 | cu->language, objfile); |
c906108c SS |
2434 | } |
2435 | else | |
2436 | { | |
2437 | /* Static Variable. Skip symbols without location descriptors. */ | |
2438 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2439 | { |
2440 | if (built_actual_name) | |
2441 | xfree (actual_name); | |
2442 | return; | |
2443 | } | |
e7c27a73 | 2444 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2445 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2446 | mst_file_data, objfile); */ |
38d518c9 | 2447 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2448 | built_actual_name, |
5c4e30ca DC |
2449 | VAR_DOMAIN, LOC_STATIC, |
2450 | &objfile->static_psymbols, | |
2451 | 0, addr + baseaddr, | |
e142c38c | 2452 | cu->language, objfile); |
c906108c SS |
2453 | } |
2454 | break; | |
2455 | case DW_TAG_typedef: | |
2456 | case DW_TAG_base_type: | |
a02abb62 | 2457 | case DW_TAG_subrange_type: |
38d518c9 | 2458 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2459 | built_actual_name, |
176620f1 | 2460 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2461 | &objfile->static_psymbols, |
e142c38c | 2462 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2463 | break; |
72bf9492 DJ |
2464 | case DW_TAG_namespace: |
2465 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 2466 | built_actual_name, |
72bf9492 DJ |
2467 | VAR_DOMAIN, LOC_TYPEDEF, |
2468 | &objfile->global_psymbols, | |
2469 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2470 | break; | |
c906108c | 2471 | case DW_TAG_class_type: |
680b30c7 | 2472 | case DW_TAG_interface_type: |
c906108c SS |
2473 | case DW_TAG_structure_type: |
2474 | case DW_TAG_union_type: | |
2475 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2476 | /* Skip external references. The DWARF standard says in the section |
2477 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2478 | structure, union or class type is represented by a structure, | |
2479 | union or class entry that does not have a byte size attribute | |
2480 | and that has a DW_AT_declaration attribute." */ | |
2481 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2482 | { |
2483 | if (built_actual_name) | |
2484 | xfree (actual_name); | |
2485 | return; | |
2486 | } | |
fa4028e9 | 2487 | |
63d06c5c DC |
2488 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2489 | static vs. global. */ | |
38d518c9 | 2490 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2491 | built_actual_name, |
176620f1 | 2492 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2493 | (cu->language == language_cplus |
2494 | || cu->language == language_java) | |
63d06c5c DC |
2495 | ? &objfile->global_psymbols |
2496 | : &objfile->static_psymbols, | |
e142c38c | 2497 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2498 | |
c906108c SS |
2499 | break; |
2500 | case DW_TAG_enumerator: | |
38d518c9 | 2501 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2502 | built_actual_name, |
176620f1 | 2503 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2504 | (cu->language == language_cplus |
2505 | || cu->language == language_java) | |
f6fe98ef DJ |
2506 | ? &objfile->global_psymbols |
2507 | : &objfile->static_psymbols, | |
e142c38c | 2508 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2509 | break; |
2510 | default: | |
2511 | break; | |
2512 | } | |
5c4e30ca | 2513 | |
72bf9492 DJ |
2514 | if (built_actual_name) |
2515 | xfree (actual_name); | |
c906108c SS |
2516 | } |
2517 | ||
5c4e30ca DC |
2518 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2519 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2520 | the name of the enclosing namespace. */ | |
91c24f0a | 2521 | |
72bf9492 DJ |
2522 | static void |
2523 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2524 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 2525 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 2526 | { |
72bf9492 | 2527 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2528 | |
72bf9492 | 2529 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2530 | |
2531 | /* Now scan partial symbols in that namespace. */ | |
2532 | ||
91c24f0a | 2533 | if (pdi->has_children) |
5734ee8b | 2534 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
2535 | } |
2536 | ||
5d7cb8df JK |
2537 | /* Read a partial die corresponding to a Fortran module. */ |
2538 | ||
2539 | static void | |
2540 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
2541 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
2542 | { | |
2543 | /* Now scan partial symbols in that module. | |
2544 | ||
2545 | FIXME: Support the separate Fortran module namespaces. */ | |
2546 | ||
2547 | if (pdi->has_children) | |
2548 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
2549 | } | |
2550 | ||
bc30ff58 JB |
2551 | /* Read a partial die corresponding to a subprogram and create a partial |
2552 | symbol for that subprogram. When the CU language allows it, this | |
2553 | routine also defines a partial symbol for each nested subprogram | |
2554 | that this subprogram contains. | |
2555 | ||
2556 | DIE my also be a lexical block, in which case we simply search | |
2557 | recursively for suprograms defined inside that lexical block. | |
2558 | Again, this is only performed when the CU language allows this | |
2559 | type of definitions. */ | |
2560 | ||
2561 | static void | |
2562 | add_partial_subprogram (struct partial_die_info *pdi, | |
2563 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 2564 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
2565 | { |
2566 | if (pdi->tag == DW_TAG_subprogram) | |
2567 | { | |
2568 | if (pdi->has_pc_info) | |
2569 | { | |
2570 | if (pdi->lowpc < *lowpc) | |
2571 | *lowpc = pdi->lowpc; | |
2572 | if (pdi->highpc > *highpc) | |
2573 | *highpc = pdi->highpc; | |
5734ee8b DJ |
2574 | if (need_pc) |
2575 | { | |
2576 | CORE_ADDR baseaddr; | |
2577 | struct objfile *objfile = cu->objfile; | |
2578 | ||
2579 | baseaddr = ANOFFSET (objfile->section_offsets, | |
2580 | SECT_OFF_TEXT (objfile)); | |
2581 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
2582 | pdi->lowpc + baseaddr, |
2583 | pdi->highpc - 1 + baseaddr, | |
5734ee8b DJ |
2584 | cu->per_cu->psymtab); |
2585 | } | |
bc30ff58 | 2586 | if (!pdi->is_declaration) |
e8d05480 JB |
2587 | /* Ignore subprogram DIEs that do not have a name, they are |
2588 | illegal. Do not emit a complaint at this point, we will | |
2589 | do so when we convert this psymtab into a symtab. */ | |
2590 | if (pdi->name) | |
2591 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
2592 | } |
2593 | } | |
2594 | ||
2595 | if (! pdi->has_children) | |
2596 | return; | |
2597 | ||
2598 | if (cu->language == language_ada) | |
2599 | { | |
2600 | pdi = pdi->die_child; | |
2601 | while (pdi != NULL) | |
2602 | { | |
2603 | fixup_partial_die (pdi, cu); | |
2604 | if (pdi->tag == DW_TAG_subprogram | |
2605 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 2606 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
2607 | pdi = pdi->die_sibling; |
2608 | } | |
2609 | } | |
2610 | } | |
2611 | ||
72bf9492 DJ |
2612 | /* See if we can figure out if the class lives in a namespace. We do |
2613 | this by looking for a member function; its demangled name will | |
2614 | contain namespace info, if there is any. */ | |
63d06c5c | 2615 | |
72bf9492 DJ |
2616 | static void |
2617 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2618 | struct dwarf2_cu *cu) | |
63d06c5c | 2619 | { |
987504bb JJ |
2620 | if ((cu->language == language_cplus |
2621 | || cu->language == language_java) | |
72bf9492 | 2622 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2623 | && struct_pdi->has_children) |
2624 | { | |
63d06c5c DC |
2625 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2626 | what template types look like, because the demangler | |
2627 | frequently doesn't give the same name as the debug info. We | |
2628 | could fix this by only using the demangled name to get the | |
134d01f1 | 2629 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2630 | |
72bf9492 | 2631 | struct partial_die_info *real_pdi; |
5d51ca54 | 2632 | |
72bf9492 DJ |
2633 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2634 | we should not do this. We'll prepend the parent's fully qualified | |
2635 | name when we create the partial symbol. */ | |
5d51ca54 | 2636 | |
72bf9492 | 2637 | real_pdi = struct_pdi; |
72bf9492 | 2638 | while (real_pdi->has_specification) |
10b3939b | 2639 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2640 | |
72bf9492 DJ |
2641 | if (real_pdi->die_parent != NULL) |
2642 | return; | |
63d06c5c | 2643 | } |
63d06c5c DC |
2644 | } |
2645 | ||
91c24f0a DC |
2646 | /* Read a partial die corresponding to an enumeration type. */ |
2647 | ||
72bf9492 DJ |
2648 | static void |
2649 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2650 | struct dwarf2_cu *cu) | |
91c24f0a | 2651 | { |
72bf9492 | 2652 | struct partial_die_info *pdi; |
91c24f0a DC |
2653 | |
2654 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2655 | add_partial_symbol (enum_pdi, cu); |
2656 | ||
2657 | pdi = enum_pdi->die_child; | |
2658 | while (pdi) | |
91c24f0a | 2659 | { |
72bf9492 | 2660 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2661 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2662 | else |
72bf9492 DJ |
2663 | add_partial_symbol (pdi, cu); |
2664 | pdi = pdi->die_sibling; | |
91c24f0a | 2665 | } |
91c24f0a DC |
2666 | } |
2667 | ||
4bb7a0a7 DJ |
2668 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2669 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2670 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2671 | the initial number. */ | |
2672 | ||
2673 | static struct abbrev_info * | |
fe1b8b76 | 2674 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2675 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2676 | { |
2677 | bfd *abfd = cu->objfile->obfd; | |
2678 | unsigned int abbrev_number; | |
2679 | struct abbrev_info *abbrev; | |
2680 | ||
2681 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2682 | ||
2683 | if (abbrev_number == 0) | |
2684 | return NULL; | |
2685 | ||
2686 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2687 | if (!abbrev) | |
2688 | { | |
8a3fe4f8 | 2689 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2690 | bfd_get_filename (abfd)); |
2691 | } | |
2692 | ||
2693 | return abbrev; | |
2694 | } | |
2695 | ||
93311388 DE |
2696 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2697 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
2698 | DIE. Any children of the skipped DIEs will also be skipped. */ |
2699 | ||
fe1b8b76 | 2700 | static gdb_byte * |
93311388 | 2701 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2702 | { |
2703 | struct abbrev_info *abbrev; | |
2704 | unsigned int bytes_read; | |
2705 | ||
2706 | while (1) | |
2707 | { | |
2708 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2709 | if (abbrev == NULL) | |
2710 | return info_ptr + bytes_read; | |
2711 | else | |
93311388 | 2712 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
2713 | } |
2714 | } | |
2715 | ||
93311388 DE |
2716 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2717 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
2718 | abbrev corresponding to that skipped uleb128 should be passed in |
2719 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2720 | children. */ | |
2721 | ||
fe1b8b76 | 2722 | static gdb_byte * |
93311388 DE |
2723 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
2724 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2725 | { |
2726 | unsigned int bytes_read; | |
2727 | struct attribute attr; | |
2728 | bfd *abfd = cu->objfile->obfd; | |
2729 | unsigned int form, i; | |
2730 | ||
2731 | for (i = 0; i < abbrev->num_attrs; i++) | |
2732 | { | |
2733 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2734 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2735 | { | |
2736 | read_attribute (&attr, &abbrev->attrs[i], | |
2737 | abfd, info_ptr, cu); | |
2738 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2739 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2740 | else |
93311388 | 2741 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
2742 | } |
2743 | ||
2744 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2745 | form = abbrev->attrs[i].form; | |
2746 | skip_attribute: | |
2747 | switch (form) | |
2748 | { | |
4bb7a0a7 | 2749 | case DW_FORM_ref_addr: |
ae411497 TT |
2750 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
2751 | and later it is offset sized. */ | |
2752 | if (cu->header.version == 2) | |
2753 | info_ptr += cu->header.addr_size; | |
2754 | else | |
2755 | info_ptr += cu->header.offset_size; | |
2756 | break; | |
2757 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
2758 | info_ptr += cu->header.addr_size; |
2759 | break; | |
2760 | case DW_FORM_data1: | |
2761 | case DW_FORM_ref1: | |
2762 | case DW_FORM_flag: | |
2763 | info_ptr += 1; | |
2764 | break; | |
2dc7f7b3 TT |
2765 | case DW_FORM_flag_present: |
2766 | break; | |
4bb7a0a7 DJ |
2767 | case DW_FORM_data2: |
2768 | case DW_FORM_ref2: | |
2769 | info_ptr += 2; | |
2770 | break; | |
2771 | case DW_FORM_data4: | |
2772 | case DW_FORM_ref4: | |
2773 | info_ptr += 4; | |
2774 | break; | |
2775 | case DW_FORM_data8: | |
2776 | case DW_FORM_ref8: | |
348e048f | 2777 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
2778 | info_ptr += 8; |
2779 | break; | |
2780 | case DW_FORM_string: | |
2781 | read_string (abfd, info_ptr, &bytes_read); | |
2782 | info_ptr += bytes_read; | |
2783 | break; | |
2dc7f7b3 | 2784 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
2785 | case DW_FORM_strp: |
2786 | info_ptr += cu->header.offset_size; | |
2787 | break; | |
2dc7f7b3 | 2788 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
2789 | case DW_FORM_block: |
2790 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2791 | info_ptr += bytes_read; | |
2792 | break; | |
2793 | case DW_FORM_block1: | |
2794 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2795 | break; | |
2796 | case DW_FORM_block2: | |
2797 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2798 | break; | |
2799 | case DW_FORM_block4: | |
2800 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2801 | break; | |
2802 | case DW_FORM_sdata: | |
2803 | case DW_FORM_udata: | |
2804 | case DW_FORM_ref_udata: | |
2805 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2806 | break; | |
2807 | case DW_FORM_indirect: | |
2808 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2809 | info_ptr += bytes_read; | |
2810 | /* We need to continue parsing from here, so just go back to | |
2811 | the top. */ | |
2812 | goto skip_attribute; | |
2813 | ||
2814 | default: | |
8a3fe4f8 | 2815 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2816 | dwarf_form_name (form), |
2817 | bfd_get_filename (abfd)); | |
2818 | } | |
2819 | } | |
2820 | ||
2821 | if (abbrev->has_children) | |
93311388 | 2822 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
2823 | else |
2824 | return info_ptr; | |
2825 | } | |
2826 | ||
93311388 DE |
2827 | /* Locate ORIG_PDI's sibling. |
2828 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
2829 | in BUFFER. */ | |
91c24f0a | 2830 | |
fe1b8b76 | 2831 | static gdb_byte * |
93311388 DE |
2832 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
2833 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 2834 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2835 | { |
2836 | /* Do we know the sibling already? */ | |
72bf9492 | 2837 | |
91c24f0a DC |
2838 | if (orig_pdi->sibling) |
2839 | return orig_pdi->sibling; | |
2840 | ||
2841 | /* Are there any children to deal with? */ | |
2842 | ||
2843 | if (!orig_pdi->has_children) | |
2844 | return info_ptr; | |
2845 | ||
4bb7a0a7 | 2846 | /* Skip the children the long way. */ |
91c24f0a | 2847 | |
93311388 | 2848 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
2849 | } |
2850 | ||
c906108c SS |
2851 | /* Expand this partial symbol table into a full symbol table. */ |
2852 | ||
2853 | static void | |
fba45db2 | 2854 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2855 | { |
2856 | /* FIXME: This is barely more than a stub. */ | |
2857 | if (pst != NULL) | |
2858 | { | |
2859 | if (pst->readin) | |
2860 | { | |
8a3fe4f8 | 2861 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2862 | } |
2863 | else | |
2864 | { | |
2865 | if (info_verbose) | |
2866 | { | |
a3f17187 | 2867 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2868 | gdb_flush (gdb_stdout); |
2869 | } | |
2870 | ||
10b3939b DJ |
2871 | /* Restore our global data. */ |
2872 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2873 | dwarf2_objfile_data_key); | |
2874 | ||
b2ab525c KB |
2875 | /* If this psymtab is constructed from a debug-only objfile, the |
2876 | has_section_at_zero flag will not necessarily be correct. We | |
2877 | can get the correct value for this flag by looking at the data | |
2878 | associated with the (presumably stripped) associated objfile. */ | |
2879 | if (pst->objfile->separate_debug_objfile_backlink) | |
2880 | { | |
2881 | struct dwarf2_per_objfile *dpo_backlink | |
2882 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
2883 | dwarf2_objfile_data_key); | |
2884 | dwarf2_per_objfile->has_section_at_zero | |
2885 | = dpo_backlink->has_section_at_zero; | |
2886 | } | |
2887 | ||
c906108c SS |
2888 | psymtab_to_symtab_1 (pst); |
2889 | ||
2890 | /* Finish up the debug error message. */ | |
2891 | if (info_verbose) | |
a3f17187 | 2892 | printf_filtered (_("done.\n")); |
c906108c SS |
2893 | } |
2894 | } | |
2895 | } | |
2896 | ||
10b3939b DJ |
2897 | /* Add PER_CU to the queue. */ |
2898 | ||
2899 | static void | |
03dd20cc | 2900 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
2901 | { |
2902 | struct dwarf2_queue_item *item; | |
2903 | ||
2904 | per_cu->queued = 1; | |
2905 | item = xmalloc (sizeof (*item)); | |
2906 | item->per_cu = per_cu; | |
2907 | item->next = NULL; | |
2908 | ||
2909 | if (dwarf2_queue == NULL) | |
2910 | dwarf2_queue = item; | |
2911 | else | |
2912 | dwarf2_queue_tail->next = item; | |
2913 | ||
2914 | dwarf2_queue_tail = item; | |
2915 | } | |
2916 | ||
2917 | /* Process the queue. */ | |
2918 | ||
2919 | static void | |
2920 | process_queue (struct objfile *objfile) | |
2921 | { | |
2922 | struct dwarf2_queue_item *item, *next_item; | |
2923 | ||
03dd20cc DJ |
2924 | /* The queue starts out with one item, but following a DIE reference |
2925 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
2926 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
2927 | { | |
31ffec48 | 2928 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2929 | process_full_comp_unit (item->per_cu); |
2930 | ||
2931 | item->per_cu->queued = 0; | |
2932 | next_item = item->next; | |
2933 | xfree (item); | |
2934 | } | |
2935 | ||
2936 | dwarf2_queue_tail = NULL; | |
2937 | } | |
2938 | ||
2939 | /* Free all allocated queue entries. This function only releases anything if | |
2940 | an error was thrown; if the queue was processed then it would have been | |
2941 | freed as we went along. */ | |
2942 | ||
2943 | static void | |
2944 | dwarf2_release_queue (void *dummy) | |
2945 | { | |
2946 | struct dwarf2_queue_item *item, *last; | |
2947 | ||
2948 | item = dwarf2_queue; | |
2949 | while (item) | |
2950 | { | |
2951 | /* Anything still marked queued is likely to be in an | |
2952 | inconsistent state, so discard it. */ | |
2953 | if (item->per_cu->queued) | |
2954 | { | |
2955 | if (item->per_cu->cu != NULL) | |
2956 | free_one_cached_comp_unit (item->per_cu->cu); | |
2957 | item->per_cu->queued = 0; | |
2958 | } | |
2959 | ||
2960 | last = item; | |
2961 | item = item->next; | |
2962 | xfree (last); | |
2963 | } | |
2964 | ||
2965 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2966 | } | |
2967 | ||
2968 | /* Read in full symbols for PST, and anything it depends on. */ | |
2969 | ||
c906108c | 2970 | static void |
fba45db2 | 2971 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2972 | { |
10b3939b | 2973 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2974 | struct cleanup *back_to; |
aaa75496 JB |
2975 | int i; |
2976 | ||
2977 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2978 | if (!pst->dependencies[i]->readin) | |
2979 | { | |
2980 | /* Inform about additional files that need to be read in. */ | |
2981 | if (info_verbose) | |
2982 | { | |
a3f17187 | 2983 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2984 | fputs_filtered (" ", gdb_stdout); |
2985 | wrap_here (""); | |
2986 | fputs_filtered ("and ", gdb_stdout); | |
2987 | wrap_here (""); | |
2988 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2989 | wrap_here (""); /* Flush output */ | |
2990 | gdb_flush (gdb_stdout); | |
2991 | } | |
2992 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2993 | } | |
2994 | ||
e38df1d0 | 2995 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
2996 | |
2997 | if (per_cu == NULL) | |
aaa75496 JB |
2998 | { |
2999 | /* It's an include file, no symbols to read for it. | |
3000 | Everything is in the parent symtab. */ | |
3001 | pst->readin = 1; | |
3002 | return; | |
3003 | } | |
c906108c | 3004 | |
10b3939b DJ |
3005 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
3006 | ||
03dd20cc | 3007 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b | 3008 | |
348e048f DE |
3009 | if (per_cu->from_debug_types) |
3010 | read_signatured_type_at_offset (pst->objfile, per_cu->offset); | |
3011 | else | |
3012 | load_full_comp_unit (per_cu, pst->objfile); | |
3013 | ||
10b3939b DJ |
3014 | process_queue (pst->objfile); |
3015 | ||
3016 | /* Age the cache, releasing compilation units that have not | |
3017 | been used recently. */ | |
3018 | age_cached_comp_units (); | |
3019 | ||
3020 | do_cleanups (back_to); | |
3021 | } | |
3022 | ||
93311388 | 3023 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 3024 | |
93311388 | 3025 | static void |
31ffec48 | 3026 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 3027 | { |
31ffec48 | 3028 | bfd *abfd = objfile->obfd; |
10b3939b | 3029 | struct dwarf2_cu *cu; |
c764a876 | 3030 | unsigned int offset; |
93311388 | 3031 | gdb_byte *info_ptr, *beg_of_comp_unit; |
10b3939b DJ |
3032 | struct cleanup *back_to, *free_cu_cleanup; |
3033 | struct attribute *attr; | |
6502dd73 | 3034 | |
348e048f DE |
3035 | gdb_assert (! per_cu->from_debug_types); |
3036 | ||
c906108c | 3037 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 3038 | offset = per_cu->offset; |
6502dd73 | 3039 | |
be391dca | 3040 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 3041 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 3042 | beg_of_comp_unit = info_ptr; |
63d06c5c | 3043 | |
93311388 | 3044 | cu = alloc_one_comp_unit (objfile); |
c906108c | 3045 | |
10b3939b DJ |
3046 | /* If an error occurs while loading, release our storage. */ |
3047 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 3048 | |
93311388 | 3049 | /* Read in the comp_unit header. */ |
10b3939b | 3050 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c | 3051 | |
93311388 DE |
3052 | /* Complete the cu_header. */ |
3053 | cu->header.offset = offset; | |
3054 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3055 | ||
3056 | /* Read the abbrevs for this compilation unit. */ | |
10b3939b DJ |
3057 | dwarf2_read_abbrevs (abfd, cu); |
3058 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
3059 | ||
93311388 | 3060 | /* Link this compilation unit into the compilation unit tree. */ |
10b3939b | 3061 | per_cu->cu = cu; |
93311388 | 3062 | cu->per_cu = per_cu; |
f792889a | 3063 | cu->type_hash = per_cu->type_hash; |
e142c38c | 3064 | |
93311388 | 3065 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
3066 | |
3067 | /* We try not to read any attributes in this function, because not | |
3068 | all objfiles needed for references have been loaded yet, and symbol | |
3069 | table processing isn't initialized. But we have to set the CU language, | |
3070 | or we won't be able to build types correctly. */ | |
3071 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
3072 | if (attr) | |
3073 | set_cu_language (DW_UNSND (attr), cu); | |
3074 | else | |
3075 | set_cu_language (language_minimal, cu); | |
3076 | ||
a6c727b2 DJ |
3077 | /* Similarly, if we do not read the producer, we can not apply |
3078 | producer-specific interpretation. */ | |
3079 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
3080 | if (attr) | |
3081 | cu->producer = DW_STRING (attr); | |
3082 | ||
348e048f DE |
3083 | /* Link this CU into read_in_chain. */ |
3084 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3085 | dwarf2_per_objfile->read_in_chain = per_cu; | |
3086 | ||
10b3939b | 3087 | do_cleanups (back_to); |
e142c38c | 3088 | |
10b3939b DJ |
3089 | /* We've successfully allocated this compilation unit. Let our caller |
3090 | clean it up when finished with it. */ | |
3091 | discard_cleanups (free_cu_cleanup); | |
10b3939b DJ |
3092 | } |
3093 | ||
3094 | /* Generate full symbol information for PST and CU, whose DIEs have | |
3095 | already been loaded into memory. */ | |
3096 | ||
3097 | static void | |
3098 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
3099 | { | |
3100 | struct partial_symtab *pst = per_cu->psymtab; | |
3101 | struct dwarf2_cu *cu = per_cu->cu; | |
3102 | struct objfile *objfile = pst->objfile; | |
10b3939b DJ |
3103 | CORE_ADDR lowpc, highpc; |
3104 | struct symtab *symtab; | |
3105 | struct cleanup *back_to; | |
10b3939b DJ |
3106 | CORE_ADDR baseaddr; |
3107 | ||
3108 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3109 | ||
10b3939b DJ |
3110 | buildsym_init (); |
3111 | back_to = make_cleanup (really_free_pendings, NULL); | |
3112 | ||
3113 | cu->list_in_scope = &file_symbols; | |
c906108c | 3114 | |
d85a05f0 | 3115 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 3116 | |
c906108c | 3117 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 3118 | process_die (cu->dies, cu); |
c906108c | 3119 | |
fae299cd DC |
3120 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
3121 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
3122 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 3123 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 3124 | |
613e1657 | 3125 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3126 | |
3127 | /* Set symtab language to language from DW_AT_language. | |
3128 | If the compilation is from a C file generated by language preprocessors, | |
3129 | do not set the language if it was already deduced by start_subfile. */ | |
3130 | if (symtab != NULL | |
10b3939b | 3131 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 3132 | { |
10b3939b | 3133 | symtab->language = cu->language; |
c906108c SS |
3134 | } |
3135 | pst->symtab = symtab; | |
3136 | pst->readin = 1; | |
c906108c SS |
3137 | |
3138 | do_cleanups (back_to); | |
3139 | } | |
3140 | ||
3141 | /* Process a die and its children. */ | |
3142 | ||
3143 | static void | |
e7c27a73 | 3144 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3145 | { |
3146 | switch (die->tag) | |
3147 | { | |
3148 | case DW_TAG_padding: | |
3149 | break; | |
3150 | case DW_TAG_compile_unit: | |
e7c27a73 | 3151 | read_file_scope (die, cu); |
c906108c | 3152 | break; |
348e048f DE |
3153 | case DW_TAG_type_unit: |
3154 | read_type_unit_scope (die, cu); | |
3155 | break; | |
c906108c | 3156 | case DW_TAG_subprogram: |
c906108c | 3157 | case DW_TAG_inlined_subroutine: |
edb3359d | 3158 | read_func_scope (die, cu); |
c906108c SS |
3159 | break; |
3160 | case DW_TAG_lexical_block: | |
14898363 L |
3161 | case DW_TAG_try_block: |
3162 | case DW_TAG_catch_block: | |
e7c27a73 | 3163 | read_lexical_block_scope (die, cu); |
c906108c SS |
3164 | break; |
3165 | case DW_TAG_class_type: | |
680b30c7 | 3166 | case DW_TAG_interface_type: |
c906108c SS |
3167 | case DW_TAG_structure_type: |
3168 | case DW_TAG_union_type: | |
134d01f1 | 3169 | process_structure_scope (die, cu); |
c906108c SS |
3170 | break; |
3171 | case DW_TAG_enumeration_type: | |
134d01f1 | 3172 | process_enumeration_scope (die, cu); |
c906108c | 3173 | break; |
134d01f1 | 3174 | |
f792889a DJ |
3175 | /* These dies have a type, but processing them does not create |
3176 | a symbol or recurse to process the children. Therefore we can | |
3177 | read them on-demand through read_type_die. */ | |
c906108c | 3178 | case DW_TAG_subroutine_type: |
72019c9c | 3179 | case DW_TAG_set_type: |
c906108c | 3180 | case DW_TAG_array_type: |
c906108c | 3181 | case DW_TAG_pointer_type: |
c906108c | 3182 | case DW_TAG_ptr_to_member_type: |
c906108c | 3183 | case DW_TAG_reference_type: |
c906108c | 3184 | case DW_TAG_string_type: |
c906108c | 3185 | break; |
134d01f1 | 3186 | |
c906108c | 3187 | case DW_TAG_base_type: |
a02abb62 | 3188 | case DW_TAG_subrange_type: |
cb249c71 | 3189 | case DW_TAG_typedef: |
134d01f1 DJ |
3190 | /* Add a typedef symbol for the type definition, if it has a |
3191 | DW_AT_name. */ | |
f792889a | 3192 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 3193 | break; |
c906108c | 3194 | case DW_TAG_common_block: |
e7c27a73 | 3195 | read_common_block (die, cu); |
c906108c SS |
3196 | break; |
3197 | case DW_TAG_common_inclusion: | |
3198 | break; | |
d9fa45fe | 3199 | case DW_TAG_namespace: |
63d06c5c | 3200 | processing_has_namespace_info = 1; |
e7c27a73 | 3201 | read_namespace (die, cu); |
d9fa45fe | 3202 | break; |
5d7cb8df JK |
3203 | case DW_TAG_module: |
3204 | read_module (die, cu); | |
3205 | break; | |
d9fa45fe DC |
3206 | case DW_TAG_imported_declaration: |
3207 | case DW_TAG_imported_module: | |
63d06c5c | 3208 | processing_has_namespace_info = 1; |
27aa8d6a SW |
3209 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
3210 | || cu->language != language_fortran)) | |
3211 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
3212 | dwarf_tag_name (die->tag)); | |
3213 | read_import_statement (die, cu); | |
d9fa45fe | 3214 | break; |
c906108c | 3215 | default: |
e7c27a73 | 3216 | new_symbol (die, NULL, cu); |
c906108c SS |
3217 | break; |
3218 | } | |
3219 | } | |
3220 | ||
94af9270 KS |
3221 | /* A helper function for dwarf2_compute_name which determines whether DIE |
3222 | needs to have the name of the scope prepended to the name listed in the | |
3223 | die. */ | |
3224 | ||
3225 | static int | |
3226 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
3227 | { | |
1c809c68 TT |
3228 | struct attribute *attr; |
3229 | ||
94af9270 KS |
3230 | switch (die->tag) |
3231 | { | |
3232 | case DW_TAG_namespace: | |
3233 | case DW_TAG_typedef: | |
3234 | case DW_TAG_class_type: | |
3235 | case DW_TAG_interface_type: | |
3236 | case DW_TAG_structure_type: | |
3237 | case DW_TAG_union_type: | |
3238 | case DW_TAG_enumeration_type: | |
3239 | case DW_TAG_enumerator: | |
3240 | case DW_TAG_subprogram: | |
3241 | case DW_TAG_member: | |
3242 | return 1; | |
3243 | ||
3244 | case DW_TAG_variable: | |
3245 | /* We only need to prefix "globally" visible variables. These include | |
3246 | any variable marked with DW_AT_external or any variable that | |
3247 | lives in a namespace. [Variables in anonymous namespaces | |
3248 | require prefixing, but they are not DW_AT_external.] */ | |
3249 | ||
3250 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
3251 | { | |
3252 | struct dwarf2_cu *spec_cu = cu; | |
3253 | return die_needs_namespace (die_specification (die, &spec_cu), | |
3254 | spec_cu); | |
3255 | } | |
3256 | ||
1c809c68 TT |
3257 | attr = dwarf2_attr (die, DW_AT_external, cu); |
3258 | if (attr == NULL && die->parent->tag != DW_TAG_namespace) | |
3259 | return 0; | |
3260 | /* A variable in a lexical block of some kind does not need a | |
3261 | namespace, even though in C++ such variables may be external | |
3262 | and have a mangled name. */ | |
3263 | if (die->parent->tag == DW_TAG_lexical_block | |
3264 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
3265 | || die->parent->tag == DW_TAG_catch_block |
3266 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
3267 | return 0; |
3268 | return 1; | |
94af9270 KS |
3269 | |
3270 | default: | |
3271 | return 0; | |
3272 | } | |
3273 | } | |
3274 | ||
3275 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, | |
3276 | compute the physname for the object, which include a method's | |
3277 | formal parameters (C++/Java) and return type (Java). | |
3278 | ||
af6b7be1 JB |
3279 | For Ada, return the DIE's linkage name rather than the fully qualified |
3280 | name. PHYSNAME is ignored.. | |
3281 | ||
94af9270 KS |
3282 | The result is allocated on the objfile_obstack and canonicalized. */ |
3283 | ||
3284 | static const char * | |
3285 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
3286 | int physname) | |
3287 | { | |
3288 | if (name == NULL) | |
3289 | name = dwarf2_name (die, cu); | |
3290 | ||
3291 | /* These are the only languages we know how to qualify names in. */ | |
3292 | if (name != NULL | |
3293 | && (cu->language == language_cplus || cu->language == language_java)) | |
3294 | { | |
3295 | if (die_needs_namespace (die, cu)) | |
3296 | { | |
3297 | long length; | |
3298 | char *prefix; | |
3299 | struct ui_file *buf; | |
3300 | ||
3301 | prefix = determine_prefix (die, cu); | |
3302 | buf = mem_fileopen (); | |
3303 | if (*prefix != '\0') | |
3304 | { | |
3305 | char *prefixed_name = typename_concat (NULL, prefix, name, cu); | |
3306 | fputs_unfiltered (prefixed_name, buf); | |
3307 | xfree (prefixed_name); | |
3308 | } | |
3309 | else | |
3310 | fputs_unfiltered (name ? name : "", buf); | |
3311 | ||
3312 | /* For Java and C++ methods, append formal parameter type | |
3313 | information, if PHYSNAME. */ | |
3314 | ||
3315 | if (physname && die->tag == DW_TAG_subprogram | |
3316 | && (cu->language == language_cplus | |
3317 | || cu->language == language_java)) | |
3318 | { | |
3319 | struct type *type = read_type_die (die, cu); | |
3320 | ||
3321 | c_type_print_args (type, buf, 0, cu->language); | |
3322 | ||
3323 | if (cu->language == language_java) | |
3324 | { | |
3325 | /* For java, we must append the return type to method | |
3326 | names. */ | |
3327 | if (die->tag == DW_TAG_subprogram) | |
3328 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
3329 | 0, 0); | |
3330 | } | |
3331 | else if (cu->language == language_cplus) | |
3332 | { | |
3333 | if (TYPE_NFIELDS (type) > 0 | |
3334 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
3335 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)))) | |
3336 | fputs_unfiltered (" const", buf); | |
3337 | } | |
3338 | } | |
3339 | ||
3340 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
3341 | &length); | |
3342 | ui_file_delete (buf); | |
3343 | ||
3344 | if (cu->language == language_cplus) | |
3345 | { | |
3346 | char *cname | |
3347 | = dwarf2_canonicalize_name (name, cu, | |
3348 | &cu->objfile->objfile_obstack); | |
3349 | if (cname != NULL) | |
3350 | name = cname; | |
3351 | } | |
3352 | } | |
3353 | } | |
af6b7be1 JB |
3354 | else if (cu->language == language_ada) |
3355 | { | |
3356 | /* For Ada unit, we prefer the linkage name over the name, as | |
3357 | the former contains the exported name, which the user expects | |
3358 | to be able to reference. Ideally, we want the user to be able | |
3359 | to reference this entity using either natural or linkage name, | |
3360 | but we haven't started looking at this enhancement yet. */ | |
3361 | struct attribute *attr; | |
3362 | ||
31ef98ae TT |
3363 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
3364 | if (attr == NULL) | |
3365 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
af6b7be1 JB |
3366 | if (attr && DW_STRING (attr)) |
3367 | name = DW_STRING (attr); | |
3368 | } | |
94af9270 KS |
3369 | |
3370 | return name; | |
3371 | } | |
3372 | ||
0114d602 DJ |
3373 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
3374 | If scope qualifiers are appropriate they will be added. The result | |
3375 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
3376 | not have a name. NAME may either be from a previous call to |
3377 | dwarf2_name or NULL. | |
3378 | ||
3379 | The output string will be canonicalized (if C++/Java). */ | |
0114d602 DJ |
3380 | |
3381 | static const char * | |
94af9270 | 3382 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 3383 | { |
94af9270 KS |
3384 | return dwarf2_compute_name (name, die, cu, 0); |
3385 | } | |
0114d602 | 3386 | |
94af9270 KS |
3387 | /* Construct a physname for the given DIE in CU. NAME may either be |
3388 | from a previous call to dwarf2_name or NULL. The result will be | |
3389 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
3390 | name. | |
0114d602 | 3391 | |
94af9270 | 3392 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 3393 | |
94af9270 KS |
3394 | static const char * |
3395 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
3396 | { | |
3397 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
3398 | } |
3399 | ||
27aa8d6a SW |
3400 | /* Read the import statement specified by the given die and record it. */ |
3401 | ||
3402 | static void | |
3403 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
3404 | { | |
3405 | struct attribute *import_attr; | |
3406 | struct die_info *imported_die; | |
de4affc9 | 3407 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 3408 | const char *imported_name; |
794684b6 | 3409 | const char *imported_name_prefix; |
13387711 SW |
3410 | const char *canonical_name; |
3411 | const char *import_alias; | |
3412 | const char *imported_declaration = NULL; | |
794684b6 | 3413 | const char *import_prefix; |
13387711 SW |
3414 | |
3415 | char *temp; | |
27aa8d6a SW |
3416 | |
3417 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
3418 | if (import_attr == NULL) | |
3419 | { | |
3420 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
3421 | dwarf_tag_name (die->tag)); | |
3422 | return; | |
3423 | } | |
3424 | ||
de4affc9 CC |
3425 | imported_cu = cu; |
3426 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
3427 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
3428 | if (imported_name == NULL) |
3429 | { | |
3430 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
3431 | ||
3432 | The import in the following code: | |
3433 | namespace A | |
3434 | { | |
3435 | typedef int B; | |
3436 | } | |
3437 | ||
3438 | int main () | |
3439 | { | |
3440 | using A::B; | |
3441 | B b; | |
3442 | return b; | |
3443 | } | |
3444 | ||
3445 | ... | |
3446 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
3447 | <52> DW_AT_decl_file : 1 | |
3448 | <53> DW_AT_decl_line : 6 | |
3449 | <54> DW_AT_import : <0x75> | |
3450 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
3451 | <59> DW_AT_name : B | |
3452 | <5b> DW_AT_decl_file : 1 | |
3453 | <5c> DW_AT_decl_line : 2 | |
3454 | <5d> DW_AT_type : <0x6e> | |
3455 | ... | |
3456 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
3457 | <76> DW_AT_byte_size : 4 | |
3458 | <77> DW_AT_encoding : 5 (signed) | |
3459 | ||
3460 | imports the wrong die ( 0x75 instead of 0x58 ). | |
3461 | This case will be ignored until the gcc bug is fixed. */ | |
3462 | return; | |
3463 | } | |
3464 | ||
82856980 SW |
3465 | /* Figure out the local name after import. */ |
3466 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 3467 | |
794684b6 SW |
3468 | /* Figure out where the statement is being imported to. */ |
3469 | import_prefix = determine_prefix (die, cu); | |
3470 | ||
3471 | /* Figure out what the scope of the imported die is and prepend it | |
3472 | to the name of the imported die. */ | |
de4affc9 | 3473 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 3474 | |
13387711 | 3475 | if (imported_die->tag != DW_TAG_namespace) |
794684b6 | 3476 | { |
13387711 SW |
3477 | imported_declaration = imported_name; |
3478 | canonical_name = imported_name_prefix; | |
794684b6 | 3479 | } |
13387711 | 3480 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 3481 | { |
13387711 SW |
3482 | temp = alloca (strlen (imported_name_prefix) |
3483 | + 2 + strlen (imported_name) + 1); | |
3484 | strcpy (temp, imported_name_prefix); | |
3485 | strcat (temp, "::"); | |
3486 | strcat (temp, imported_name); | |
3487 | canonical_name = temp; | |
794684b6 | 3488 | } |
13387711 SW |
3489 | else |
3490 | canonical_name = imported_name; | |
794684b6 | 3491 | |
c0cc3a76 SW |
3492 | cp_add_using_directive (import_prefix, |
3493 | canonical_name, | |
3494 | import_alias, | |
13387711 | 3495 | imported_declaration, |
c0cc3a76 | 3496 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
3497 | } |
3498 | ||
5fb290d7 | 3499 | static void |
e142c38c | 3500 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 3501 | { |
e142c38c | 3502 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
3503 | } |
3504 | ||
cb1df416 DJ |
3505 | static void |
3506 | free_cu_line_header (void *arg) | |
3507 | { | |
3508 | struct dwarf2_cu *cu = arg; | |
3509 | ||
3510 | free_line_header (cu->line_header); | |
3511 | cu->line_header = NULL; | |
3512 | } | |
3513 | ||
c906108c | 3514 | static void |
e7c27a73 | 3515 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3516 | { |
e7c27a73 | 3517 | struct objfile *objfile = cu->objfile; |
debd256d | 3518 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 3519 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
3520 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
3521 | struct attribute *attr; | |
e1024ff1 | 3522 | char *name = NULL; |
c906108c SS |
3523 | char *comp_dir = NULL; |
3524 | struct die_info *child_die; | |
3525 | bfd *abfd = objfile->obfd; | |
debd256d | 3526 | struct line_header *line_header = 0; |
e142c38c DJ |
3527 | CORE_ADDR baseaddr; |
3528 | ||
3529 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3530 | |
fae299cd | 3531 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
3532 | |
3533 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
3534 | from finish_block. */ | |
2acceee2 | 3535 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
3536 | lowpc = highpc; |
3537 | lowpc += baseaddr; | |
3538 | highpc += baseaddr; | |
3539 | ||
39cbfefa DJ |
3540 | /* Find the filename. Do not use dwarf2_name here, since the filename |
3541 | is not a source language identifier. */ | |
e142c38c | 3542 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3543 | if (attr) |
3544 | { | |
3545 | name = DW_STRING (attr); | |
3546 | } | |
e1024ff1 | 3547 | |
e142c38c | 3548 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 3549 | if (attr) |
e1024ff1 DJ |
3550 | comp_dir = DW_STRING (attr); |
3551 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 3552 | { |
e1024ff1 DJ |
3553 | comp_dir = ldirname (name); |
3554 | if (comp_dir != NULL) | |
3555 | make_cleanup (xfree, comp_dir); | |
3556 | } | |
3557 | if (comp_dir != NULL) | |
3558 | { | |
3559 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
3560 | directory, get rid of it. */ | |
3561 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 3562 | |
e1024ff1 DJ |
3563 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
3564 | comp_dir = cp + 1; | |
c906108c SS |
3565 | } |
3566 | ||
e1024ff1 DJ |
3567 | if (name == NULL) |
3568 | name = "<unknown>"; | |
3569 | ||
e142c38c | 3570 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
3571 | if (attr) |
3572 | { | |
e142c38c | 3573 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
3574 | } |
3575 | ||
b0f35d58 DL |
3576 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
3577 | if (attr) | |
3578 | cu->producer = DW_STRING (attr); | |
303b6f5d | 3579 | |
c906108c SS |
3580 | /* We assume that we're processing GCC output. */ |
3581 | processing_gcc_compilation = 2; | |
c906108c | 3582 | |
df8a16a1 DJ |
3583 | processing_has_namespace_info = 0; |
3584 | ||
c906108c SS |
3585 | start_symtab (name, comp_dir, lowpc); |
3586 | record_debugformat ("DWARF 2"); | |
303b6f5d | 3587 | record_producer (cu->producer); |
c906108c | 3588 | |
e142c38c | 3589 | initialize_cu_func_list (cu); |
c906108c | 3590 | |
cb1df416 DJ |
3591 | /* Decode line number information if present. We do this before |
3592 | processing child DIEs, so that the line header table is available | |
3593 | for DW_AT_decl_file. */ | |
e142c38c | 3594 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
3595 | if (attr) |
3596 | { | |
debd256d | 3597 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 3598 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
3599 | if (line_header) |
3600 | { | |
cb1df416 DJ |
3601 | cu->line_header = line_header; |
3602 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 3603 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 3604 | } |
5fb290d7 | 3605 | } |
debd256d | 3606 | |
cb1df416 DJ |
3607 | /* Process all dies in compilation unit. */ |
3608 | if (die->child != NULL) | |
3609 | { | |
3610 | child_die = die->child; | |
3611 | while (child_die && child_die->tag) | |
3612 | { | |
3613 | process_die (child_die, cu); | |
3614 | child_die = sibling_die (child_die); | |
3615 | } | |
3616 | } | |
3617 | ||
2e276125 JB |
3618 | /* Decode macro information, if present. Dwarf 2 macro information |
3619 | refers to information in the line number info statement program | |
3620 | header, so we can only read it if we've read the header | |
3621 | successfully. */ | |
e142c38c | 3622 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 3623 | if (attr && line_header) |
2e276125 JB |
3624 | { |
3625 | unsigned int macro_offset = DW_UNSND (attr); | |
3626 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 3627 | comp_dir, abfd, cu); |
2e276125 | 3628 | } |
debd256d | 3629 | do_cleanups (back_to); |
5fb290d7 DJ |
3630 | } |
3631 | ||
348e048f DE |
3632 | /* For TUs we want to skip the first top level sibling if it's not the |
3633 | actual type being defined by this TU. In this case the first top | |
3634 | level sibling is there to provide context only. */ | |
3635 | ||
3636 | static void | |
3637 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3638 | { | |
3639 | struct objfile *objfile = cu->objfile; | |
3640 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
3641 | CORE_ADDR lowpc; | |
3642 | struct attribute *attr; | |
3643 | char *name = NULL; | |
3644 | char *comp_dir = NULL; | |
3645 | struct die_info *child_die; | |
3646 | bfd *abfd = objfile->obfd; | |
348e048f DE |
3647 | |
3648 | /* start_symtab needs a low pc, but we don't really have one. | |
3649 | Do what read_file_scope would do in the absence of such info. */ | |
3650 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3651 | ||
3652 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
3653 | is not a source language identifier. */ | |
3654 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
3655 | if (attr) | |
3656 | name = DW_STRING (attr); | |
3657 | ||
3658 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
3659 | if (attr) | |
3660 | comp_dir = DW_STRING (attr); | |
3661 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
3662 | { | |
3663 | comp_dir = ldirname (name); | |
3664 | if (comp_dir != NULL) | |
3665 | make_cleanup (xfree, comp_dir); | |
3666 | } | |
3667 | ||
3668 | if (name == NULL) | |
3669 | name = "<unknown>"; | |
3670 | ||
3671 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
3672 | if (attr) | |
3673 | set_cu_language (DW_UNSND (attr), cu); | |
3674 | ||
3675 | /* This isn't technically needed today. It is done for symmetry | |
3676 | with read_file_scope. */ | |
3677 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
3678 | if (attr) | |
3679 | cu->producer = DW_STRING (attr); | |
3680 | ||
3681 | /* We assume that we're processing GCC output. */ | |
3682 | processing_gcc_compilation = 2; | |
3683 | ||
3684 | processing_has_namespace_info = 0; | |
3685 | ||
3686 | start_symtab (name, comp_dir, lowpc); | |
3687 | record_debugformat ("DWARF 2"); | |
3688 | record_producer (cu->producer); | |
3689 | ||
3690 | /* Process the dies in the type unit. */ | |
3691 | if (die->child == NULL) | |
3692 | { | |
3693 | dump_die_for_error (die); | |
3694 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
3695 | bfd_get_filename (abfd)); | |
3696 | } | |
3697 | ||
3698 | child_die = die->child; | |
3699 | ||
3700 | while (child_die && child_die->tag) | |
3701 | { | |
3702 | process_die (child_die, cu); | |
3703 | ||
3704 | child_die = sibling_die (child_die); | |
3705 | } | |
3706 | ||
3707 | do_cleanups (back_to); | |
3708 | } | |
3709 | ||
5fb290d7 | 3710 | static void |
e142c38c DJ |
3711 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
3712 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
3713 | { |
3714 | struct function_range *thisfn; | |
3715 | ||
3716 | thisfn = (struct function_range *) | |
7b5a2f43 | 3717 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
3718 | thisfn->name = name; |
3719 | thisfn->lowpc = lowpc; | |
3720 | thisfn->highpc = highpc; | |
3721 | thisfn->seen_line = 0; | |
3722 | thisfn->next = NULL; | |
3723 | ||
e142c38c DJ |
3724 | if (cu->last_fn == NULL) |
3725 | cu->first_fn = thisfn; | |
5fb290d7 | 3726 | else |
e142c38c | 3727 | cu->last_fn->next = thisfn; |
5fb290d7 | 3728 | |
e142c38c | 3729 | cu->last_fn = thisfn; |
c906108c SS |
3730 | } |
3731 | ||
d389af10 JK |
3732 | /* qsort helper for inherit_abstract_dies. */ |
3733 | ||
3734 | static int | |
3735 | unsigned_int_compar (const void *ap, const void *bp) | |
3736 | { | |
3737 | unsigned int a = *(unsigned int *) ap; | |
3738 | unsigned int b = *(unsigned int *) bp; | |
3739 | ||
3740 | return (a > b) - (b > a); | |
3741 | } | |
3742 | ||
3743 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3744 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
3745 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
3746 | ||
3747 | static void | |
3748 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
3749 | { | |
3750 | struct die_info *child_die; | |
3751 | unsigned die_children_count; | |
3752 | /* CU offsets which were referenced by children of the current DIE. */ | |
3753 | unsigned *offsets; | |
3754 | unsigned *offsets_end, *offsetp; | |
3755 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
3756 | struct die_info *origin_die; | |
3757 | /* Iterator of the ORIGIN_DIE children. */ | |
3758 | struct die_info *origin_child_die; | |
3759 | struct cleanup *cleanups; | |
3760 | struct attribute *attr; | |
3761 | ||
3762 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
3763 | if (!attr) | |
3764 | return; | |
3765 | ||
3766 | origin_die = follow_die_ref (die, attr, &cu); | |
edb3359d DJ |
3767 | if (die->tag != origin_die->tag |
3768 | && !(die->tag == DW_TAG_inlined_subroutine | |
3769 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3770 | complaint (&symfile_complaints, |
3771 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
3772 | die->offset, origin_die->offset); | |
3773 | ||
3774 | child_die = die->child; | |
3775 | die_children_count = 0; | |
3776 | while (child_die && child_die->tag) | |
3777 | { | |
3778 | child_die = sibling_die (child_die); | |
3779 | die_children_count++; | |
3780 | } | |
3781 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
3782 | cleanups = make_cleanup (xfree, offsets); | |
3783 | ||
3784 | offsets_end = offsets; | |
3785 | child_die = die->child; | |
3786 | while (child_die && child_die->tag) | |
3787 | { | |
c38f313d DJ |
3788 | /* For each CHILD_DIE, find the corresponding child of |
3789 | ORIGIN_DIE. If there is more than one layer of | |
3790 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
3791 | but GCC versions at least through 4.4 generate this (GCC PR | |
3792 | 40573). */ | |
3793 | struct die_info *child_origin_die = child_die; | |
3794 | while (1) | |
3795 | { | |
3796 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); | |
3797 | if (attr == NULL) | |
3798 | break; | |
3799 | child_origin_die = follow_die_ref (child_origin_die, attr, &cu); | |
3800 | } | |
3801 | ||
d389af10 JK |
3802 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
3803 | counterpart may exist. */ | |
c38f313d | 3804 | if (child_origin_die != child_die) |
d389af10 | 3805 | { |
edb3359d DJ |
3806 | if (child_die->tag != child_origin_die->tag |
3807 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
3808 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3809 | complaint (&symfile_complaints, |
3810 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3811 | "different tags"), child_die->offset, | |
3812 | child_origin_die->offset); | |
c38f313d DJ |
3813 | if (child_origin_die->parent != origin_die) |
3814 | complaint (&symfile_complaints, | |
3815 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3816 | "different parents"), child_die->offset, | |
3817 | child_origin_die->offset); | |
3818 | else | |
3819 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
3820 | } |
3821 | child_die = sibling_die (child_die); | |
3822 | } | |
3823 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
3824 | unsigned_int_compar); | |
3825 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
3826 | if (offsetp[-1] == *offsetp) | |
3827 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
3828 | "to DIE 0x%x as their abstract origin"), | |
3829 | die->offset, *offsetp); | |
3830 | ||
3831 | offsetp = offsets; | |
3832 | origin_child_die = origin_die->child; | |
3833 | while (origin_child_die && origin_child_die->tag) | |
3834 | { | |
3835 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
3836 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
3837 | offsetp++; | |
3838 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
3839 | { | |
3840 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
3841 | process_die (origin_child_die, cu); | |
3842 | } | |
3843 | origin_child_die = sibling_die (origin_child_die); | |
3844 | } | |
3845 | ||
3846 | do_cleanups (cleanups); | |
3847 | } | |
3848 | ||
c906108c | 3849 | static void |
e7c27a73 | 3850 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3851 | { |
e7c27a73 | 3852 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3853 | struct context_stack *new; |
c906108c SS |
3854 | CORE_ADDR lowpc; |
3855 | CORE_ADDR highpc; | |
3856 | struct die_info *child_die; | |
edb3359d | 3857 | struct attribute *attr, *call_line, *call_file; |
c906108c | 3858 | char *name; |
e142c38c | 3859 | CORE_ADDR baseaddr; |
801e3a5b | 3860 | struct block *block; |
edb3359d DJ |
3861 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
3862 | ||
3863 | if (inlined_func) | |
3864 | { | |
3865 | /* If we do not have call site information, we can't show the | |
3866 | caller of this inlined function. That's too confusing, so | |
3867 | only use the scope for local variables. */ | |
3868 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
3869 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
3870 | if (call_line == NULL || call_file == NULL) | |
3871 | { | |
3872 | read_lexical_block_scope (die, cu); | |
3873 | return; | |
3874 | } | |
3875 | } | |
c906108c | 3876 | |
e142c38c DJ |
3877 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
3878 | ||
94af9270 | 3879 | name = dwarf2_name (die, cu); |
c906108c | 3880 | |
e8d05480 JB |
3881 | /* Ignore functions with missing or empty names. These are actually |
3882 | illegal according to the DWARF standard. */ | |
3883 | if (name == NULL) | |
3884 | { | |
3885 | complaint (&symfile_complaints, | |
3886 | _("missing name for subprogram DIE at %d"), die->offset); | |
3887 | return; | |
3888 | } | |
3889 | ||
3890 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
3891 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
3892 | { | |
3893 | complaint (&symfile_complaints, | |
3894 | _("cannot get low and high bounds for subprogram DIE at %d"), | |
3895 | die->offset); | |
3896 | return; | |
3897 | } | |
c906108c SS |
3898 | |
3899 | lowpc += baseaddr; | |
3900 | highpc += baseaddr; | |
3901 | ||
5fb290d7 | 3902 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3903 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3904 | |
c906108c | 3905 | new = push_context (0, lowpc); |
f792889a | 3906 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3907 | |
4cecd739 DJ |
3908 | /* If there is a location expression for DW_AT_frame_base, record |
3909 | it. */ | |
e142c38c | 3910 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3911 | if (attr) |
c034e007 AC |
3912 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3913 | expression is being recorded directly in the function's symbol | |
3914 | and not in a separate frame-base object. I guess this hack is | |
3915 | to avoid adding some sort of frame-base adjunct/annex to the | |
3916 | function's symbol :-(. The problem with doing this is that it | |
3917 | results in a function symbol with a location expression that | |
3918 | has nothing to do with the location of the function, ouch! The | |
3919 | relationship should be: a function's symbol has-a frame base; a | |
3920 | frame-base has-a location expression. */ | |
e7c27a73 | 3921 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3922 | |
e142c38c | 3923 | cu->list_in_scope = &local_symbols; |
c906108c | 3924 | |
639d11d3 | 3925 | if (die->child != NULL) |
c906108c | 3926 | { |
639d11d3 | 3927 | child_die = die->child; |
c906108c SS |
3928 | while (child_die && child_die->tag) |
3929 | { | |
e7c27a73 | 3930 | process_die (child_die, cu); |
c906108c SS |
3931 | child_die = sibling_die (child_die); |
3932 | } | |
3933 | } | |
3934 | ||
d389af10 JK |
3935 | inherit_abstract_dies (die, cu); |
3936 | ||
4a811a97 UW |
3937 | /* If we have a DW_AT_specification, we might need to import using |
3938 | directives from the context of the specification DIE. See the | |
3939 | comment in determine_prefix. */ | |
3940 | if (cu->language == language_cplus | |
3941 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
3942 | { | |
3943 | struct dwarf2_cu *spec_cu = cu; | |
3944 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
3945 | ||
3946 | while (spec_die) | |
3947 | { | |
3948 | child_die = spec_die->child; | |
3949 | while (child_die && child_die->tag) | |
3950 | { | |
3951 | if (child_die->tag == DW_TAG_imported_module) | |
3952 | process_die (child_die, spec_cu); | |
3953 | child_die = sibling_die (child_die); | |
3954 | } | |
3955 | ||
3956 | /* In some cases, GCC generates specification DIEs that | |
3957 | themselves contain DW_AT_specification attributes. */ | |
3958 | spec_die = die_specification (spec_die, &spec_cu); | |
3959 | } | |
3960 | } | |
3961 | ||
c906108c SS |
3962 | new = pop_context (); |
3963 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3964 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3965 | lowpc, highpc, objfile); | |
3966 | ||
df8a16a1 DJ |
3967 | /* For C++, set the block's scope. */ |
3968 | if (cu->language == language_cplus) | |
3969 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, | |
0114d602 | 3970 | determine_prefix (die, cu), |
df8a16a1 DJ |
3971 | processing_has_namespace_info); |
3972 | ||
801e3a5b JB |
3973 | /* If we have address ranges, record them. */ |
3974 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3975 | |
3976 | /* In C++, we can have functions nested inside functions (e.g., when | |
3977 | a function declares a class that has methods). This means that | |
3978 | when we finish processing a function scope, we may need to go | |
3979 | back to building a containing block's symbol lists. */ | |
3980 | local_symbols = new->locals; | |
3981 | param_symbols = new->params; | |
27aa8d6a | 3982 | using_directives = new->using_directives; |
208d8187 | 3983 | |
921e78cf JB |
3984 | /* If we've finished processing a top-level function, subsequent |
3985 | symbols go in the file symbol list. */ | |
3986 | if (outermost_context_p ()) | |
e142c38c | 3987 | cu->list_in_scope = &file_symbols; |
c906108c SS |
3988 | } |
3989 | ||
3990 | /* Process all the DIES contained within a lexical block scope. Start | |
3991 | a new scope, process the dies, and then close the scope. */ | |
3992 | ||
3993 | static void | |
e7c27a73 | 3994 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3995 | { |
e7c27a73 | 3996 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3997 | struct context_stack *new; |
c906108c SS |
3998 | CORE_ADDR lowpc, highpc; |
3999 | struct die_info *child_die; | |
e142c38c DJ |
4000 | CORE_ADDR baseaddr; |
4001 | ||
4002 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
4003 | |
4004 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
4005 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
4006 | as multiple lexical blocks? Handling children in a sane way would | |
4007 | be nasty. Might be easier to properly extend generic blocks to | |
4008 | describe ranges. */ | |
d85a05f0 | 4009 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
4010 | return; |
4011 | lowpc += baseaddr; | |
4012 | highpc += baseaddr; | |
4013 | ||
4014 | push_context (0, lowpc); | |
639d11d3 | 4015 | if (die->child != NULL) |
c906108c | 4016 | { |
639d11d3 | 4017 | child_die = die->child; |
c906108c SS |
4018 | while (child_die && child_die->tag) |
4019 | { | |
e7c27a73 | 4020 | process_die (child_die, cu); |
c906108c SS |
4021 | child_die = sibling_die (child_die); |
4022 | } | |
4023 | } | |
4024 | new = pop_context (); | |
4025 | ||
8540c487 | 4026 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 4027 | { |
801e3a5b JB |
4028 | struct block *block |
4029 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
4030 | highpc, objfile); | |
4031 | ||
4032 | /* Note that recording ranges after traversing children, as we | |
4033 | do here, means that recording a parent's ranges entails | |
4034 | walking across all its children's ranges as they appear in | |
4035 | the address map, which is quadratic behavior. | |
4036 | ||
4037 | It would be nicer to record the parent's ranges before | |
4038 | traversing its children, simply overriding whatever you find | |
4039 | there. But since we don't even decide whether to create a | |
4040 | block until after we've traversed its children, that's hard | |
4041 | to do. */ | |
4042 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
4043 | } |
4044 | local_symbols = new->locals; | |
27aa8d6a | 4045 | using_directives = new->using_directives; |
c906108c SS |
4046 | } |
4047 | ||
43039443 | 4048 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
4049 | Return 1 if the attributes are present and valid, otherwise, return 0. |
4050 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
4051 | |
4052 | static int | |
4053 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
4054 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
4055 | struct partial_symtab *ranges_pst) | |
43039443 JK |
4056 | { |
4057 | struct objfile *objfile = cu->objfile; | |
4058 | struct comp_unit_head *cu_header = &cu->header; | |
4059 | bfd *obfd = objfile->obfd; | |
4060 | unsigned int addr_size = cu_header->addr_size; | |
4061 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
4062 | /* Base address selection entry. */ | |
4063 | CORE_ADDR base; | |
4064 | int found_base; | |
4065 | unsigned int dummy; | |
4066 | gdb_byte *buffer; | |
4067 | CORE_ADDR marker; | |
4068 | int low_set; | |
4069 | CORE_ADDR low = 0; | |
4070 | CORE_ADDR high = 0; | |
ff013f42 | 4071 | CORE_ADDR baseaddr; |
43039443 | 4072 | |
d00adf39 DE |
4073 | found_base = cu->base_known; |
4074 | base = cu->base_address; | |
43039443 | 4075 | |
be391dca | 4076 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 4077 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
4078 | { |
4079 | complaint (&symfile_complaints, | |
4080 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
4081 | offset); | |
4082 | return 0; | |
4083 | } | |
dce234bc | 4084 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
4085 | |
4086 | /* Read in the largest possible address. */ | |
4087 | marker = read_address (obfd, buffer, cu, &dummy); | |
4088 | if ((marker & mask) == mask) | |
4089 | { | |
4090 | /* If we found the largest possible address, then | |
4091 | read the base address. */ | |
4092 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4093 | buffer += 2 * addr_size; | |
4094 | offset += 2 * addr_size; | |
4095 | found_base = 1; | |
4096 | } | |
4097 | ||
4098 | low_set = 0; | |
4099 | ||
e7030f15 | 4100 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 4101 | |
43039443 JK |
4102 | while (1) |
4103 | { | |
4104 | CORE_ADDR range_beginning, range_end; | |
4105 | ||
4106 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
4107 | buffer += addr_size; | |
4108 | range_end = read_address (obfd, buffer, cu, &dummy); | |
4109 | buffer += addr_size; | |
4110 | offset += 2 * addr_size; | |
4111 | ||
4112 | /* An end of list marker is a pair of zero addresses. */ | |
4113 | if (range_beginning == 0 && range_end == 0) | |
4114 | /* Found the end of list entry. */ | |
4115 | break; | |
4116 | ||
4117 | /* Each base address selection entry is a pair of 2 values. | |
4118 | The first is the largest possible address, the second is | |
4119 | the base address. Check for a base address here. */ | |
4120 | if ((range_beginning & mask) == mask) | |
4121 | { | |
4122 | /* If we found the largest possible address, then | |
4123 | read the base address. */ | |
4124 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4125 | found_base = 1; | |
4126 | continue; | |
4127 | } | |
4128 | ||
4129 | if (!found_base) | |
4130 | { | |
4131 | /* We have no valid base address for the ranges | |
4132 | data. */ | |
4133 | complaint (&symfile_complaints, | |
4134 | _("Invalid .debug_ranges data (no base address)")); | |
4135 | return 0; | |
4136 | } | |
4137 | ||
4138 | range_beginning += base; | |
4139 | range_end += base; | |
4140 | ||
ff013f42 JK |
4141 | if (ranges_pst != NULL && range_beginning < range_end) |
4142 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
4143 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
4144 | ranges_pst); | |
4145 | ||
43039443 JK |
4146 | /* FIXME: This is recording everything as a low-high |
4147 | segment of consecutive addresses. We should have a | |
4148 | data structure for discontiguous block ranges | |
4149 | instead. */ | |
4150 | if (! low_set) | |
4151 | { | |
4152 | low = range_beginning; | |
4153 | high = range_end; | |
4154 | low_set = 1; | |
4155 | } | |
4156 | else | |
4157 | { | |
4158 | if (range_beginning < low) | |
4159 | low = range_beginning; | |
4160 | if (range_end > high) | |
4161 | high = range_end; | |
4162 | } | |
4163 | } | |
4164 | ||
4165 | if (! low_set) | |
4166 | /* If the first entry is an end-of-list marker, the range | |
4167 | describes an empty scope, i.e. no instructions. */ | |
4168 | return 0; | |
4169 | ||
4170 | if (low_return) | |
4171 | *low_return = low; | |
4172 | if (high_return) | |
4173 | *high_return = high; | |
4174 | return 1; | |
4175 | } | |
4176 | ||
af34e669 DJ |
4177 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
4178 | are present and valid, otherwise, return 0. Return -1 if the range is | |
4179 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 4180 | static int |
af34e669 | 4181 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
4182 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
4183 | struct partial_symtab *pst) | |
c906108c SS |
4184 | { |
4185 | struct attribute *attr; | |
af34e669 DJ |
4186 | CORE_ADDR low = 0; |
4187 | CORE_ADDR high = 0; | |
4188 | int ret = 0; | |
c906108c | 4189 | |
e142c38c | 4190 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 4191 | if (attr) |
af34e669 DJ |
4192 | { |
4193 | high = DW_ADDR (attr); | |
e142c38c | 4194 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
4195 | if (attr) |
4196 | low = DW_ADDR (attr); | |
4197 | else | |
4198 | /* Found high w/o low attribute. */ | |
4199 | return 0; | |
4200 | ||
4201 | /* Found consecutive range of addresses. */ | |
4202 | ret = 1; | |
4203 | } | |
c906108c | 4204 | else |
af34e669 | 4205 | { |
e142c38c | 4206 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
4207 | if (attr != NULL) |
4208 | { | |
af34e669 | 4209 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 4210 | .debug_ranges section. */ |
d85a05f0 | 4211 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 4212 | return 0; |
43039443 | 4213 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
4214 | ret = -1; |
4215 | } | |
4216 | } | |
c906108c SS |
4217 | |
4218 | if (high < low) | |
4219 | return 0; | |
4220 | ||
4221 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
4222 | eliminate duplicate copies of functions and vtables and such. | |
4223 | The linker will arbitrarily choose one and discard the others. | |
4224 | The AT_*_pc values for such functions refer to local labels in | |
4225 | these sections. If the section from that file was discarded, the | |
4226 | labels are not in the output, so the relocs get a value of 0. | |
4227 | If this is a discarded function, mark the pc bounds as invalid, | |
4228 | so that GDB will ignore it. */ | |
72dca2f5 | 4229 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
4230 | return 0; |
4231 | ||
4232 | *lowpc = low; | |
4233 | *highpc = high; | |
af34e669 | 4234 | return ret; |
c906108c SS |
4235 | } |
4236 | ||
b084d499 JB |
4237 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
4238 | its low and high PC addresses. Do nothing if these addresses could not | |
4239 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
4240 | and HIGHPC to the high address if greater than HIGHPC. */ | |
4241 | ||
4242 | static void | |
4243 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
4244 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4245 | struct dwarf2_cu *cu) | |
4246 | { | |
4247 | CORE_ADDR low, high; | |
4248 | struct die_info *child = die->child; | |
4249 | ||
d85a05f0 | 4250 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
4251 | { |
4252 | *lowpc = min (*lowpc, low); | |
4253 | *highpc = max (*highpc, high); | |
4254 | } | |
4255 | ||
4256 | /* If the language does not allow nested subprograms (either inside | |
4257 | subprograms or lexical blocks), we're done. */ | |
4258 | if (cu->language != language_ada) | |
4259 | return; | |
4260 | ||
4261 | /* Check all the children of the given DIE. If it contains nested | |
4262 | subprograms, then check their pc bounds. Likewise, we need to | |
4263 | check lexical blocks as well, as they may also contain subprogram | |
4264 | definitions. */ | |
4265 | while (child && child->tag) | |
4266 | { | |
4267 | if (child->tag == DW_TAG_subprogram | |
4268 | || child->tag == DW_TAG_lexical_block) | |
4269 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
4270 | child = sibling_die (child); | |
4271 | } | |
4272 | } | |
4273 | ||
fae299cd DC |
4274 | /* Get the low and high pc's represented by the scope DIE, and store |
4275 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
4276 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
4277 | ||
4278 | static void | |
4279 | get_scope_pc_bounds (struct die_info *die, | |
4280 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4281 | struct dwarf2_cu *cu) | |
4282 | { | |
4283 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
4284 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
4285 | CORE_ADDR current_low, current_high; | |
4286 | ||
d85a05f0 | 4287 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
4288 | { |
4289 | best_low = current_low; | |
4290 | best_high = current_high; | |
4291 | } | |
4292 | else | |
4293 | { | |
4294 | struct die_info *child = die->child; | |
4295 | ||
4296 | while (child && child->tag) | |
4297 | { | |
4298 | switch (child->tag) { | |
4299 | case DW_TAG_subprogram: | |
b084d499 | 4300 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
4301 | break; |
4302 | case DW_TAG_namespace: | |
4303 | /* FIXME: carlton/2004-01-16: Should we do this for | |
4304 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
4305 | that current GCC's always emit the DIEs corresponding | |
4306 | to definitions of methods of classes as children of a | |
4307 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
4308 | the DIEs giving the declarations, which could be | |
4309 | anywhere). But I don't see any reason why the | |
4310 | standards says that they have to be there. */ | |
4311 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
4312 | ||
4313 | if (current_low != ((CORE_ADDR) -1)) | |
4314 | { | |
4315 | best_low = min (best_low, current_low); | |
4316 | best_high = max (best_high, current_high); | |
4317 | } | |
4318 | break; | |
4319 | default: | |
4320 | /* Ignore. */ | |
4321 | break; | |
4322 | } | |
4323 | ||
4324 | child = sibling_die (child); | |
4325 | } | |
4326 | } | |
4327 | ||
4328 | *lowpc = best_low; | |
4329 | *highpc = best_high; | |
4330 | } | |
4331 | ||
801e3a5b JB |
4332 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
4333 | in DIE. */ | |
4334 | static void | |
4335 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
4336 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
4337 | { | |
4338 | struct attribute *attr; | |
4339 | ||
4340 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
4341 | if (attr) | |
4342 | { | |
4343 | CORE_ADDR high = DW_ADDR (attr); | |
4344 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
4345 | if (attr) | |
4346 | { | |
4347 | CORE_ADDR low = DW_ADDR (attr); | |
4348 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
4349 | } | |
4350 | } | |
4351 | ||
4352 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
4353 | if (attr) | |
4354 | { | |
4355 | bfd *obfd = cu->objfile->obfd; | |
4356 | ||
4357 | /* The value of the DW_AT_ranges attribute is the offset of the | |
4358 | address range list in the .debug_ranges section. */ | |
4359 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 4360 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
4361 | |
4362 | /* For some target architectures, but not others, the | |
4363 | read_address function sign-extends the addresses it returns. | |
4364 | To recognize base address selection entries, we need a | |
4365 | mask. */ | |
4366 | unsigned int addr_size = cu->header.addr_size; | |
4367 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
4368 | ||
4369 | /* The base address, to which the next pair is relative. Note | |
4370 | that this 'base' is a DWARF concept: most entries in a range | |
4371 | list are relative, to reduce the number of relocs against the | |
4372 | debugging information. This is separate from this function's | |
4373 | 'baseaddr' argument, which GDB uses to relocate debugging | |
4374 | information from a shared library based on the address at | |
4375 | which the library was loaded. */ | |
d00adf39 DE |
4376 | CORE_ADDR base = cu->base_address; |
4377 | int base_known = cu->base_known; | |
801e3a5b | 4378 | |
be391dca | 4379 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 4380 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
4381 | { |
4382 | complaint (&symfile_complaints, | |
4383 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
4384 | offset); | |
4385 | return; | |
4386 | } | |
4387 | ||
4388 | for (;;) | |
4389 | { | |
4390 | unsigned int bytes_read; | |
4391 | CORE_ADDR start, end; | |
4392 | ||
4393 | start = read_address (obfd, buffer, cu, &bytes_read); | |
4394 | buffer += bytes_read; | |
4395 | end = read_address (obfd, buffer, cu, &bytes_read); | |
4396 | buffer += bytes_read; | |
4397 | ||
4398 | /* Did we find the end of the range list? */ | |
4399 | if (start == 0 && end == 0) | |
4400 | break; | |
4401 | ||
4402 | /* Did we find a base address selection entry? */ | |
4403 | else if ((start & base_select_mask) == base_select_mask) | |
4404 | { | |
4405 | base = end; | |
4406 | base_known = 1; | |
4407 | } | |
4408 | ||
4409 | /* We found an ordinary address range. */ | |
4410 | else | |
4411 | { | |
4412 | if (!base_known) | |
4413 | { | |
4414 | complaint (&symfile_complaints, | |
4415 | _("Invalid .debug_ranges data (no base address)")); | |
4416 | return; | |
4417 | } | |
4418 | ||
4419 | record_block_range (block, | |
4420 | baseaddr + base + start, | |
4421 | baseaddr + base + end - 1); | |
4422 | } | |
4423 | } | |
4424 | } | |
4425 | } | |
4426 | ||
c906108c SS |
4427 | /* Add an aggregate field to the field list. */ |
4428 | ||
4429 | static void | |
107d2387 | 4430 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
4431 | struct dwarf2_cu *cu) |
4432 | { | |
4433 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 4434 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
4435 | struct nextfield *new_field; |
4436 | struct attribute *attr; | |
4437 | struct field *fp; | |
4438 | char *fieldname = ""; | |
4439 | ||
4440 | /* Allocate a new field list entry and link it in. */ | |
4441 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 4442 | make_cleanup (xfree, new_field); |
c906108c | 4443 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
4444 | |
4445 | if (die->tag == DW_TAG_inheritance) | |
4446 | { | |
4447 | new_field->next = fip->baseclasses; | |
4448 | fip->baseclasses = new_field; | |
4449 | } | |
4450 | else | |
4451 | { | |
4452 | new_field->next = fip->fields; | |
4453 | fip->fields = new_field; | |
4454 | } | |
c906108c SS |
4455 | fip->nfields++; |
4456 | ||
4457 | /* Handle accessibility and virtuality of field. | |
4458 | The default accessibility for members is public, the default | |
4459 | accessibility for inheritance is private. */ | |
4460 | if (die->tag != DW_TAG_inheritance) | |
4461 | new_field->accessibility = DW_ACCESS_public; | |
4462 | else | |
4463 | new_field->accessibility = DW_ACCESS_private; | |
4464 | new_field->virtuality = DW_VIRTUALITY_none; | |
4465 | ||
e142c38c | 4466 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4467 | if (attr) |
4468 | new_field->accessibility = DW_UNSND (attr); | |
4469 | if (new_field->accessibility != DW_ACCESS_public) | |
4470 | fip->non_public_fields = 1; | |
e142c38c | 4471 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
4472 | if (attr) |
4473 | new_field->virtuality = DW_UNSND (attr); | |
4474 | ||
4475 | fp = &new_field->field; | |
a9a9bd0f | 4476 | |
e142c38c | 4477 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 4478 | { |
a9a9bd0f DC |
4479 | /* Data member other than a C++ static data member. */ |
4480 | ||
c906108c | 4481 | /* Get type of field. */ |
e7c27a73 | 4482 | fp->type = die_type (die, cu); |
c906108c | 4483 | |
d6a843b5 | 4484 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 4485 | |
c906108c | 4486 | /* Get bit size of field (zero if none). */ |
e142c38c | 4487 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
4488 | if (attr) |
4489 | { | |
4490 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
4491 | } | |
4492 | else | |
4493 | { | |
4494 | FIELD_BITSIZE (*fp) = 0; | |
4495 | } | |
4496 | ||
4497 | /* Get bit offset of field. */ | |
e142c38c | 4498 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
4499 | if (attr) |
4500 | { | |
d4b96c9a | 4501 | int byte_offset = 0; |
c6a0999f | 4502 | |
3690dd37 | 4503 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 4504 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 4505 | else if (attr_form_is_constant (attr)) |
c6a0999f | 4506 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 4507 | else if (attr_form_is_block (attr)) |
c6a0999f | 4508 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
4509 | else |
4510 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 4511 | |
d6a843b5 | 4512 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 4513 | } |
e142c38c | 4514 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
4515 | if (attr) |
4516 | { | |
5e2b427d | 4517 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
4518 | { |
4519 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
4520 | additional bit offset from the MSB of the containing |
4521 | anonymous object to the MSB of the field. We don't | |
4522 | have to do anything special since we don't need to | |
4523 | know the size of the anonymous object. */ | |
c906108c SS |
4524 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
4525 | } | |
4526 | else | |
4527 | { | |
4528 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
4529 | MSB of the anonymous object, subtract off the number of |
4530 | bits from the MSB of the field to the MSB of the | |
4531 | object, and then subtract off the number of bits of | |
4532 | the field itself. The result is the bit offset of | |
4533 | the LSB of the field. */ | |
c906108c SS |
4534 | int anonymous_size; |
4535 | int bit_offset = DW_UNSND (attr); | |
4536 | ||
e142c38c | 4537 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4538 | if (attr) |
4539 | { | |
4540 | /* The size of the anonymous object containing | |
4541 | the bit field is explicit, so use the | |
4542 | indicated size (in bytes). */ | |
4543 | anonymous_size = DW_UNSND (attr); | |
4544 | } | |
4545 | else | |
4546 | { | |
4547 | /* The size of the anonymous object containing | |
4548 | the bit field must be inferred from the type | |
4549 | attribute of the data member containing the | |
4550 | bit field. */ | |
4551 | anonymous_size = TYPE_LENGTH (fp->type); | |
4552 | } | |
4553 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
4554 | - bit_offset - FIELD_BITSIZE (*fp); | |
4555 | } | |
4556 | } | |
4557 | ||
4558 | /* Get name of field. */ | |
39cbfefa DJ |
4559 | fieldname = dwarf2_name (die, cu); |
4560 | if (fieldname == NULL) | |
4561 | fieldname = ""; | |
d8151005 DJ |
4562 | |
4563 | /* The name is already allocated along with this objfile, so we don't | |
4564 | need to duplicate it for the type. */ | |
4565 | fp->name = fieldname; | |
c906108c SS |
4566 | |
4567 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 4568 | pointer or virtual base class pointer) to private. */ |
e142c38c | 4569 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 4570 | { |
d48cc9dd | 4571 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
4572 | new_field->accessibility = DW_ACCESS_private; |
4573 | fip->non_public_fields = 1; | |
4574 | } | |
4575 | } | |
a9a9bd0f | 4576 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 4577 | { |
a9a9bd0f DC |
4578 | /* C++ static member. */ |
4579 | ||
4580 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
4581 | is a declaration, but all versions of G++ as of this writing | |
4582 | (so through at least 3.2.1) incorrectly generate | |
4583 | DW_TAG_variable tags. */ | |
4584 | ||
c906108c | 4585 | char *physname; |
c906108c | 4586 | |
a9a9bd0f | 4587 | /* Get name of field. */ |
39cbfefa DJ |
4588 | fieldname = dwarf2_name (die, cu); |
4589 | if (fieldname == NULL) | |
c906108c SS |
4590 | return; |
4591 | ||
2df3850c | 4592 | /* Get physical name. */ |
94af9270 | 4593 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 4594 | |
d8151005 DJ |
4595 | /* The name is already allocated along with this objfile, so we don't |
4596 | need to duplicate it for the type. */ | |
4597 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 4598 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 4599 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
4600 | } |
4601 | else if (die->tag == DW_TAG_inheritance) | |
4602 | { | |
4603 | /* C++ base class field. */ | |
e142c38c | 4604 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 4605 | if (attr) |
d4b96c9a JK |
4606 | { |
4607 | int byte_offset = 0; | |
4608 | ||
4609 | if (attr_form_is_section_offset (attr)) | |
4610 | dwarf2_complex_location_expr_complaint (); | |
4611 | else if (attr_form_is_constant (attr)) | |
4612 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
4613 | else if (attr_form_is_block (attr)) | |
4614 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
4615 | else | |
4616 | dwarf2_complex_location_expr_complaint (); | |
4617 | ||
4618 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
4619 | } | |
c906108c | 4620 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 4621 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
4622 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
4623 | fip->nbaseclasses++; | |
4624 | } | |
4625 | } | |
4626 | ||
4627 | /* Create the vector of fields, and attach it to the type. */ | |
4628 | ||
4629 | static void | |
fba45db2 | 4630 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4631 | struct dwarf2_cu *cu) |
c906108c SS |
4632 | { |
4633 | int nfields = fip->nfields; | |
4634 | ||
4635 | /* Record the field count, allocate space for the array of fields, | |
4636 | and create blank accessibility bitfields if necessary. */ | |
4637 | TYPE_NFIELDS (type) = nfields; | |
4638 | TYPE_FIELDS (type) = (struct field *) | |
4639 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
4640 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
4641 | ||
b4ba55a1 | 4642 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
4643 | { |
4644 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
4645 | ||
4646 | TYPE_FIELD_PRIVATE_BITS (type) = | |
4647 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4648 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
4649 | ||
4650 | TYPE_FIELD_PROTECTED_BITS (type) = | |
4651 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4652 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
4653 | ||
4654 | TYPE_FIELD_IGNORE_BITS (type) = | |
4655 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4656 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
4657 | } | |
4658 | ||
4659 | /* If the type has baseclasses, allocate and clear a bit vector for | |
4660 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 4661 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
4662 | { |
4663 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 4664 | unsigned char *pointer; |
c906108c SS |
4665 | |
4666 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
4667 | pointer = TYPE_ALLOC (type, num_bytes); |
4668 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
4669 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
4670 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
4671 | } | |
4672 | ||
4673 | /* Copy the saved-up fields into the field vector. Start from the head | |
4674 | of the list, adding to the tail of the field array, so that they end | |
4675 | up in the same order in the array in which they were added to the list. */ | |
4676 | while (nfields-- > 0) | |
4677 | { | |
7d0ccb61 DJ |
4678 | struct nextfield *fieldp; |
4679 | ||
4680 | if (fip->fields) | |
4681 | { | |
4682 | fieldp = fip->fields; | |
4683 | fip->fields = fieldp->next; | |
4684 | } | |
4685 | else | |
4686 | { | |
4687 | fieldp = fip->baseclasses; | |
4688 | fip->baseclasses = fieldp->next; | |
4689 | } | |
4690 | ||
4691 | TYPE_FIELD (type, nfields) = fieldp->field; | |
4692 | switch (fieldp->accessibility) | |
c906108c | 4693 | { |
c5aa993b | 4694 | case DW_ACCESS_private: |
b4ba55a1 JB |
4695 | if (cu->language != language_ada) |
4696 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 4697 | break; |
c906108c | 4698 | |
c5aa993b | 4699 | case DW_ACCESS_protected: |
b4ba55a1 JB |
4700 | if (cu->language != language_ada) |
4701 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 4702 | break; |
c906108c | 4703 | |
c5aa993b JM |
4704 | case DW_ACCESS_public: |
4705 | break; | |
c906108c | 4706 | |
c5aa993b JM |
4707 | default: |
4708 | /* Unknown accessibility. Complain and treat it as public. */ | |
4709 | { | |
e2e0b3e5 | 4710 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 4711 | fieldp->accessibility); |
c5aa993b JM |
4712 | } |
4713 | break; | |
c906108c SS |
4714 | } |
4715 | if (nfields < fip->nbaseclasses) | |
4716 | { | |
7d0ccb61 | 4717 | switch (fieldp->virtuality) |
c906108c | 4718 | { |
c5aa993b JM |
4719 | case DW_VIRTUALITY_virtual: |
4720 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
4721 | if (cu->language == language_ada) |
4722 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
4723 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
4724 | break; | |
c906108c SS |
4725 | } |
4726 | } | |
c906108c SS |
4727 | } |
4728 | } | |
4729 | ||
c906108c SS |
4730 | /* Add a member function to the proper fieldlist. */ |
4731 | ||
4732 | static void | |
107d2387 | 4733 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 4734 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 4735 | { |
e7c27a73 | 4736 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4737 | struct attribute *attr; |
4738 | struct fnfieldlist *flp; | |
4739 | int i; | |
4740 | struct fn_field *fnp; | |
4741 | char *fieldname; | |
4742 | char *physname; | |
4743 | struct nextfnfield *new_fnfield; | |
f792889a | 4744 | struct type *this_type; |
c906108c | 4745 | |
b4ba55a1 JB |
4746 | if (cu->language == language_ada) |
4747 | error ("unexpected member function in Ada type"); | |
4748 | ||
2df3850c | 4749 | /* Get name of member function. */ |
39cbfefa DJ |
4750 | fieldname = dwarf2_name (die, cu); |
4751 | if (fieldname == NULL) | |
2df3850c | 4752 | return; |
c906108c | 4753 | |
2df3850c | 4754 | /* Get the mangled name. */ |
94af9270 | 4755 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c SS |
4756 | |
4757 | /* Look up member function name in fieldlist. */ | |
4758 | for (i = 0; i < fip->nfnfields; i++) | |
4759 | { | |
27bfe10e | 4760 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
4761 | break; |
4762 | } | |
4763 | ||
4764 | /* Create new list element if necessary. */ | |
4765 | if (i < fip->nfnfields) | |
4766 | flp = &fip->fnfieldlists[i]; | |
4767 | else | |
4768 | { | |
4769 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4770 | { | |
4771 | fip->fnfieldlists = (struct fnfieldlist *) | |
4772 | xrealloc (fip->fnfieldlists, | |
4773 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4774 | * sizeof (struct fnfieldlist)); |
c906108c | 4775 | if (fip->nfnfields == 0) |
c13c43fd | 4776 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
4777 | } |
4778 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
4779 | flp->name = fieldname; | |
4780 | flp->length = 0; | |
4781 | flp->head = NULL; | |
4782 | fip->nfnfields++; | |
4783 | } | |
4784 | ||
4785 | /* Create a new member function field and chain it to the field list | |
4786 | entry. */ | |
4787 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 4788 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
4789 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
4790 | new_fnfield->next = flp->head; | |
4791 | flp->head = new_fnfield; | |
4792 | flp->length++; | |
4793 | ||
4794 | /* Fill in the member function field info. */ | |
4795 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
4796 | /* The name is already allocated along with this objfile, so we don't |
4797 | need to duplicate it for the type. */ | |
4798 | fnp->physname = physname ? physname : ""; | |
c906108c | 4799 | fnp->type = alloc_type (objfile); |
f792889a DJ |
4800 | this_type = read_type_die (die, cu); |
4801 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 4802 | { |
f792889a | 4803 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 4804 | |
f792889a | 4805 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
4806 | of the method itself (TYPE_CODE_METHOD). */ |
4807 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
4808 | TYPE_TARGET_TYPE (this_type), |
4809 | TYPE_FIELDS (this_type), | |
4810 | TYPE_NFIELDS (this_type), | |
4811 | TYPE_VARARGS (this_type)); | |
c906108c SS |
4812 | |
4813 | /* Handle static member functions. | |
c5aa993b JM |
4814 | Dwarf2 has no clean way to discern C++ static and non-static |
4815 | member functions. G++ helps GDB by marking the first | |
4816 | parameter for non-static member functions (which is the | |
4817 | this pointer) as artificial. We obtain this information | |
4818 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 4819 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
4820 | fnp->voffset = VOFFSET_STATIC; |
4821 | } | |
4822 | else | |
e2e0b3e5 | 4823 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 4824 | physname); |
c906108c SS |
4825 | |
4826 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 4827 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 4828 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
4829 | |
4830 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
4831 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
4832 | ||
4833 | /* Get accessibility. */ | |
e142c38c | 4834 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4835 | if (attr) |
4836 | { | |
4837 | switch (DW_UNSND (attr)) | |
4838 | { | |
c5aa993b JM |
4839 | case DW_ACCESS_private: |
4840 | fnp->is_private = 1; | |
4841 | break; | |
4842 | case DW_ACCESS_protected: | |
4843 | fnp->is_protected = 1; | |
4844 | break; | |
c906108c SS |
4845 | } |
4846 | } | |
4847 | ||
b02dede2 | 4848 | /* Check for artificial methods. */ |
e142c38c | 4849 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
4850 | if (attr && DW_UNSND (attr) != 0) |
4851 | fnp->is_artificial = 1; | |
4852 | ||
0d564a31 DJ |
4853 | /* Get index in virtual function table if it is a virtual member |
4854 | function. For GCC, this is an offset in the appropriate | |
4855 | virtual table, as specified by DW_AT_containing_type. For | |
4856 | everyone else, it is an expression to be evaluated relative | |
4857 | to the object address. */ | |
4858 | ||
e142c38c | 4859 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
0d564a31 | 4860 | if (attr && fnp->fcontext) |
8e19ed76 PS |
4861 | { |
4862 | /* Support the .debug_loc offsets */ | |
4863 | if (attr_form_is_block (attr)) | |
4864 | { | |
e7c27a73 | 4865 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 4866 | } |
3690dd37 | 4867 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4868 | { |
4d3c2250 | 4869 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4870 | } |
4871 | else | |
4872 | { | |
4d3c2250 KB |
4873 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
4874 | fieldname); | |
8e19ed76 | 4875 | } |
0d564a31 DJ |
4876 | } |
4877 | else if (attr) | |
4878 | { | |
4879 | /* We only support trivial expressions here. This hack will work | |
ba950e4d | 4880 | for v3 classes, which always start with the vtable pointer. */ |
0d564a31 DJ |
4881 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0 |
4882 | && DW_BLOCK (attr)->data[0] == DW_OP_deref) | |
4883 | { | |
4884 | struct dwarf_block blk; | |
4885 | blk.size = DW_BLOCK (attr)->size - 1; | |
4886 | blk.data = DW_BLOCK (attr)->data + 1; | |
ba950e4d DJ |
4887 | fnp->voffset = decode_locdesc (&blk, cu); |
4888 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
4889 | dwarf2_complex_location_expr_complaint (); | |
4890 | else | |
4891 | fnp->voffset /= cu->header.addr_size; | |
0d564a31 DJ |
4892 | fnp->voffset += 2; |
4893 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
4894 | } | |
4895 | else | |
4896 | dwarf2_complex_location_expr_complaint (); | |
4897 | } | |
d48cc9dd DJ |
4898 | else |
4899 | { | |
4900 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
4901 | if (attr && DW_UNSND (attr)) | |
4902 | { | |
4903 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
4904 | complaint (&symfile_complaints, | |
4905 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
4906 | fieldname, die->offset); | |
4907 | TYPE_CPLUS_DYNAMIC (type) = 1; | |
4908 | } | |
4909 | } | |
c906108c SS |
4910 | } |
4911 | ||
4912 | /* Create the vector of member function fields, and attach it to the type. */ | |
4913 | ||
4914 | static void | |
fba45db2 | 4915 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4916 | struct dwarf2_cu *cu) |
c906108c SS |
4917 | { |
4918 | struct fnfieldlist *flp; | |
4919 | int total_length = 0; | |
4920 | int i; | |
4921 | ||
b4ba55a1 JB |
4922 | if (cu->language == language_ada) |
4923 | error ("unexpected member functions in Ada type"); | |
4924 | ||
c906108c SS |
4925 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
4926 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
4927 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
4928 | ||
4929 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
4930 | { | |
4931 | struct nextfnfield *nfp = flp->head; | |
4932 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
4933 | int k; | |
4934 | ||
4935 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
4936 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
4937 | fn_flp->fn_fields = (struct fn_field *) | |
4938 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
4939 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 4940 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
4941 | |
4942 | total_length += flp->length; | |
4943 | } | |
4944 | ||
4945 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
4946 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
4947 | } | |
4948 | ||
1168df01 JB |
4949 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
4950 | language, zero otherwise. */ | |
4951 | static int | |
4952 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
4953 | { | |
4954 | static const char vptr[] = "_vptr"; | |
987504bb | 4955 | static const char vtable[] = "vtable"; |
1168df01 | 4956 | |
987504bb JJ |
4957 | /* Look for the C++ and Java forms of the vtable. */ |
4958 | if ((cu->language == language_java | |
4959 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
4960 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
4961 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
4962 | return 1; |
4963 | ||
4964 | return 0; | |
4965 | } | |
4966 | ||
c0dd20ea | 4967 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
4968 | functions, with the ABI-specified layout. If TYPE describes |
4969 | such a structure, smash it into a member function type. | |
61049d3b DJ |
4970 | |
4971 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
4972 | This is GCC PR debug/28767. */ | |
c0dd20ea | 4973 | |
0b92b5bb TT |
4974 | static void |
4975 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 4976 | { |
0b92b5bb | 4977 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
4978 | |
4979 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
4980 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
4981 | return; | |
c0dd20ea DJ |
4982 | |
4983 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
4984 | if (TYPE_FIELD_NAME (type, 0) == NULL |
4985 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
4986 | || TYPE_FIELD_NAME (type, 1) == NULL | |
4987 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
4988 | return; | |
c0dd20ea DJ |
4989 | |
4990 | /* Find the type of the method. */ | |
0b92b5bb | 4991 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
4992 | if (pfn_type == NULL |
4993 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
4994 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 4995 | return; |
c0dd20ea DJ |
4996 | |
4997 | /* Look for the "this" argument. */ | |
4998 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
4999 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 5000 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 5001 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 5002 | return; |
c0dd20ea DJ |
5003 | |
5004 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
5005 | new_type = alloc_type (objfile); |
5006 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
5007 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
5008 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 5009 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 5010 | } |
1168df01 | 5011 | |
c906108c SS |
5012 | /* Called when we find the DIE that starts a structure or union scope |
5013 | (definition) to process all dies that define the members of the | |
5014 | structure or union. | |
5015 | ||
5016 | NOTE: we need to call struct_type regardless of whether or not the | |
5017 | DIE has an at_name attribute, since it might be an anonymous | |
5018 | structure or union. This gets the type entered into our set of | |
5019 | user defined types. | |
5020 | ||
5021 | However, if the structure is incomplete (an opaque struct/union) | |
5022 | then suppress creating a symbol table entry for it since gdb only | |
5023 | wants to find the one with the complete definition. Note that if | |
5024 | it is complete, we just call new_symbol, which does it's own | |
5025 | checking about whether the struct/union is anonymous or not (and | |
5026 | suppresses creating a symbol table entry itself). */ | |
5027 | ||
f792889a | 5028 | static struct type * |
134d01f1 | 5029 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5030 | { |
e7c27a73 | 5031 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5032 | struct type *type; |
5033 | struct attribute *attr; | |
39cbfefa | 5034 | char *name; |
0114d602 | 5035 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c | 5036 | |
348e048f DE |
5037 | /* If the definition of this type lives in .debug_types, read that type. |
5038 | Don't follow DW_AT_specification though, that will take us back up | |
5039 | the chain and we want to go down. */ | |
5040 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
5041 | if (attr) | |
5042 | { | |
5043 | struct dwarf2_cu *type_cu = cu; | |
5044 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
5045 | /* We could just recurse on read_structure_type, but we need to call | |
5046 | get_die_type to ensure only one type for this DIE is created. | |
5047 | This is important, for example, because for c++ classes we need | |
5048 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
5049 | type = read_type_die (type_die, type_cu); | |
5050 | return set_die_type (die, type, cu); | |
5051 | } | |
5052 | ||
c0dd20ea | 5053 | type = alloc_type (objfile); |
c906108c | 5054 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 5055 | |
39cbfefa DJ |
5056 | name = dwarf2_name (die, cu); |
5057 | if (name != NULL) | |
c906108c | 5058 | { |
987504bb JJ |
5059 | if (cu->language == language_cplus |
5060 | || cu->language == language_java) | |
63d06c5c | 5061 | { |
94af9270 KS |
5062 | TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu); |
5063 | if (die->tag == DW_TAG_structure_type | |
5064 | || die->tag == DW_TAG_class_type) | |
5065 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
5066 | } |
5067 | else | |
5068 | { | |
d8151005 DJ |
5069 | /* The name is already allocated along with this objfile, so |
5070 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
5071 | TYPE_TAG_NAME (type) = (char *) name; |
5072 | if (die->tag == DW_TAG_class_type) | |
5073 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 5074 | } |
c906108c SS |
5075 | } |
5076 | ||
5077 | if (die->tag == DW_TAG_structure_type) | |
5078 | { | |
5079 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
5080 | } | |
5081 | else if (die->tag == DW_TAG_union_type) | |
5082 | { | |
5083 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
5084 | } | |
5085 | else | |
5086 | { | |
c906108c SS |
5087 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
5088 | } | |
5089 | ||
0cc2414c TT |
5090 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
5091 | TYPE_DECLARED_CLASS (type) = 1; | |
5092 | ||
e142c38c | 5093 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5094 | if (attr) |
5095 | { | |
5096 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5097 | } | |
5098 | else | |
5099 | { | |
5100 | TYPE_LENGTH (type) = 0; | |
5101 | } | |
5102 | ||
876cecd0 | 5103 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 5104 | if (die_is_declaration (die, cu)) |
876cecd0 | 5105 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
5106 | else if (attr == NULL && die->child == NULL |
5107 | && producer_is_realview (cu->producer)) | |
5108 | /* RealView does not output the required DW_AT_declaration | |
5109 | on incomplete types. */ | |
5110 | TYPE_STUB (type) = 1; | |
dc718098 | 5111 | |
b4ba55a1 JB |
5112 | set_descriptive_type (type, die, cu); |
5113 | ||
c906108c SS |
5114 | /* We need to add the type field to the die immediately so we don't |
5115 | infinitely recurse when dealing with pointers to the structure | |
5116 | type within the structure itself. */ | |
1c379e20 | 5117 | set_die_type (die, type, cu); |
c906108c | 5118 | |
e142c38c | 5119 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
5120 | { |
5121 | struct field_info fi; | |
5122 | struct die_info *child_die; | |
c906108c SS |
5123 | |
5124 | memset (&fi, 0, sizeof (struct field_info)); | |
5125 | ||
639d11d3 | 5126 | child_die = die->child; |
c906108c SS |
5127 | |
5128 | while (child_die && child_die->tag) | |
5129 | { | |
a9a9bd0f DC |
5130 | if (child_die->tag == DW_TAG_member |
5131 | || child_die->tag == DW_TAG_variable) | |
c906108c | 5132 | { |
a9a9bd0f DC |
5133 | /* NOTE: carlton/2002-11-05: A C++ static data member |
5134 | should be a DW_TAG_member that is a declaration, but | |
5135 | all versions of G++ as of this writing (so through at | |
5136 | least 3.2.1) incorrectly generate DW_TAG_variable | |
5137 | tags for them instead. */ | |
e7c27a73 | 5138 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5139 | } |
8713b1b1 | 5140 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
5141 | { |
5142 | /* C++ member function. */ | |
e7c27a73 | 5143 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
5144 | } |
5145 | else if (child_die->tag == DW_TAG_inheritance) | |
5146 | { | |
5147 | /* C++ base class field. */ | |
e7c27a73 | 5148 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5149 | } |
c906108c SS |
5150 | child_die = sibling_die (child_die); |
5151 | } | |
5152 | ||
5153 | /* Attach fields and member functions to the type. */ | |
5154 | if (fi.nfields) | |
e7c27a73 | 5155 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
5156 | if (fi.nfnfields) |
5157 | { | |
e7c27a73 | 5158 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 5159 | |
c5aa993b | 5160 | /* Get the type which refers to the base class (possibly this |
c906108c | 5161 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
5162 | class from the DW_AT_containing_type attribute. This use of |
5163 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 5164 | |
e142c38c | 5165 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 5166 | { |
e7c27a73 | 5167 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
5168 | |
5169 | TYPE_VPTR_BASETYPE (type) = t; | |
5170 | if (type == t) | |
5171 | { | |
c906108c SS |
5172 | int i; |
5173 | ||
5174 | /* Our own class provides vtbl ptr. */ | |
5175 | for (i = TYPE_NFIELDS (t) - 1; | |
5176 | i >= TYPE_N_BASECLASSES (t); | |
5177 | --i) | |
5178 | { | |
5179 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
5180 | ||
1168df01 | 5181 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
5182 | { |
5183 | TYPE_VPTR_FIELDNO (type) = i; | |
5184 | break; | |
5185 | } | |
5186 | } | |
5187 | ||
5188 | /* Complain if virtual function table field not found. */ | |
5189 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 5190 | complaint (&symfile_complaints, |
e2e0b3e5 | 5191 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
5192 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
5193 | ""); | |
c906108c SS |
5194 | } |
5195 | else | |
5196 | { | |
5197 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
5198 | } | |
5199 | } | |
f6235d4c EZ |
5200 | else if (cu->producer |
5201 | && strncmp (cu->producer, | |
5202 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
5203 | { | |
5204 | /* The IBM XLC compiler does not provide direct indication | |
5205 | of the containing type, but the vtable pointer is | |
5206 | always named __vfp. */ | |
5207 | ||
5208 | int i; | |
5209 | ||
5210 | for (i = TYPE_NFIELDS (type) - 1; | |
5211 | i >= TYPE_N_BASECLASSES (type); | |
5212 | --i) | |
5213 | { | |
5214 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
5215 | { | |
5216 | TYPE_VPTR_FIELDNO (type) = i; | |
5217 | TYPE_VPTR_BASETYPE (type) = type; | |
5218 | break; | |
5219 | } | |
5220 | } | |
5221 | } | |
c906108c | 5222 | } |
c906108c | 5223 | } |
63d06c5c | 5224 | |
0b92b5bb TT |
5225 | quirk_gcc_member_function_pointer (type, cu->objfile); |
5226 | ||
0114d602 | 5227 | do_cleanups (back_to); |
f792889a | 5228 | return type; |
c906108c SS |
5229 | } |
5230 | ||
134d01f1 DJ |
5231 | static void |
5232 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5233 | { | |
90aeadfc | 5234 | struct die_info *child_die = die->child; |
f792889a | 5235 | struct type *this_type; |
c906108c | 5236 | |
f792889a DJ |
5237 | this_type = get_die_type (die, cu); |
5238 | if (this_type == NULL) | |
5239 | this_type = read_structure_type (die, cu); | |
c906108c | 5240 | |
90aeadfc DC |
5241 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
5242 | snapshots) has been known to create a die giving a declaration | |
5243 | for a class that has, as a child, a die giving a definition for a | |
5244 | nested class. So we have to process our children even if the | |
5245 | current die is a declaration. Normally, of course, a declaration | |
5246 | won't have any children at all. */ | |
134d01f1 | 5247 | |
90aeadfc DC |
5248 | while (child_die != NULL && child_die->tag) |
5249 | { | |
5250 | if (child_die->tag == DW_TAG_member | |
5251 | || child_die->tag == DW_TAG_variable | |
5252 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 5253 | { |
90aeadfc | 5254 | /* Do nothing. */ |
134d01f1 | 5255 | } |
90aeadfc DC |
5256 | else |
5257 | process_die (child_die, cu); | |
134d01f1 | 5258 | |
90aeadfc | 5259 | child_die = sibling_die (child_die); |
134d01f1 DJ |
5260 | } |
5261 | ||
fa4028e9 JB |
5262 | /* Do not consider external references. According to the DWARF standard, |
5263 | these DIEs are identified by the fact that they have no byte_size | |
5264 | attribute, and a declaration attribute. */ | |
5265 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
5266 | || !die_is_declaration (die, cu)) | |
f792889a | 5267 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
5268 | } |
5269 | ||
5270 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
5271 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 5272 | |
f792889a | 5273 | static struct type * |
134d01f1 | 5274 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5275 | { |
e7c27a73 | 5276 | struct objfile *objfile = cu->objfile; |
c906108c | 5277 | struct type *type; |
c906108c | 5278 | struct attribute *attr; |
0114d602 | 5279 | const char *name; |
134d01f1 | 5280 | |
348e048f DE |
5281 | /* If the definition of this type lives in .debug_types, read that type. |
5282 | Don't follow DW_AT_specification though, that will take us back up | |
5283 | the chain and we want to go down. */ | |
5284 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
5285 | if (attr) | |
5286 | { | |
5287 | struct dwarf2_cu *type_cu = cu; | |
5288 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
5289 | type = read_type_die (type_die, type_cu); | |
5290 | return set_die_type (die, type, cu); | |
5291 | } | |
5292 | ||
c906108c SS |
5293 | type = alloc_type (objfile); |
5294 | ||
5295 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 5296 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 5297 | if (name != NULL) |
0114d602 | 5298 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 5299 | |
e142c38c | 5300 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5301 | if (attr) |
5302 | { | |
5303 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5304 | } | |
5305 | else | |
5306 | { | |
5307 | TYPE_LENGTH (type) = 0; | |
5308 | } | |
5309 | ||
137033e9 JB |
5310 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
5311 | declared as private in the package spec, and then defined only | |
5312 | inside the package body. Such types are known as Taft Amendment | |
5313 | Types. When another package uses such a type, an incomplete DIE | |
5314 | may be generated by the compiler. */ | |
02eb380e | 5315 | if (die_is_declaration (die, cu)) |
876cecd0 | 5316 | TYPE_STUB (type) = 1; |
02eb380e | 5317 | |
f792889a | 5318 | return set_die_type (die, type, cu); |
134d01f1 DJ |
5319 | } |
5320 | ||
5321 | /* Given a pointer to a die which begins an enumeration, process all | |
5322 | the dies that define the members of the enumeration, and create the | |
5323 | symbol for the enumeration type. | |
5324 | ||
5325 | NOTE: We reverse the order of the element list. */ | |
5326 | ||
5327 | static void | |
5328 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5329 | { | |
134d01f1 DJ |
5330 | struct die_info *child_die; |
5331 | struct field *fields; | |
134d01f1 DJ |
5332 | struct symbol *sym; |
5333 | int num_fields; | |
5334 | int unsigned_enum = 1; | |
39cbfefa | 5335 | char *name; |
f792889a | 5336 | struct type *this_type; |
134d01f1 | 5337 | |
c906108c SS |
5338 | num_fields = 0; |
5339 | fields = NULL; | |
f792889a DJ |
5340 | this_type = get_die_type (die, cu); |
5341 | if (this_type == NULL) | |
5342 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 5343 | if (die->child != NULL) |
c906108c | 5344 | { |
639d11d3 | 5345 | child_die = die->child; |
c906108c SS |
5346 | while (child_die && child_die->tag) |
5347 | { | |
5348 | if (child_die->tag != DW_TAG_enumerator) | |
5349 | { | |
e7c27a73 | 5350 | process_die (child_die, cu); |
c906108c SS |
5351 | } |
5352 | else | |
5353 | { | |
39cbfefa DJ |
5354 | name = dwarf2_name (child_die, cu); |
5355 | if (name) | |
c906108c | 5356 | { |
f792889a | 5357 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
5358 | if (SYMBOL_VALUE (sym) < 0) |
5359 | unsigned_enum = 0; | |
5360 | ||
5361 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
5362 | { | |
5363 | fields = (struct field *) | |
5364 | xrealloc (fields, | |
5365 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 5366 | * sizeof (struct field)); |
c906108c SS |
5367 | } |
5368 | ||
3567439c | 5369 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 5370 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 5371 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
5372 | FIELD_BITSIZE (fields[num_fields]) = 0; |
5373 | ||
5374 | num_fields++; | |
5375 | } | |
5376 | } | |
5377 | ||
5378 | child_die = sibling_die (child_die); | |
5379 | } | |
5380 | ||
5381 | if (num_fields) | |
5382 | { | |
f792889a DJ |
5383 | TYPE_NFIELDS (this_type) = num_fields; |
5384 | TYPE_FIELDS (this_type) = (struct field *) | |
5385 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
5386 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 5387 | sizeof (struct field) * num_fields); |
b8c9b27d | 5388 | xfree (fields); |
c906108c SS |
5389 | } |
5390 | if (unsigned_enum) | |
876cecd0 | 5391 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 5392 | } |
134d01f1 | 5393 | |
f792889a | 5394 | new_symbol (die, this_type, cu); |
c906108c SS |
5395 | } |
5396 | ||
5397 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
5398 | the DIE's type field. For now, this only handles one dimensional | |
5399 | arrays. */ | |
5400 | ||
f792889a | 5401 | static struct type * |
e7c27a73 | 5402 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5403 | { |
e7c27a73 | 5404 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5405 | struct die_info *child_die; |
5406 | struct type *type = NULL; | |
5407 | struct type *element_type, *range_type, *index_type; | |
5408 | struct type **range_types = NULL; | |
5409 | struct attribute *attr; | |
5410 | int ndim = 0; | |
5411 | struct cleanup *back_to; | |
39cbfefa | 5412 | char *name; |
c906108c | 5413 | |
e7c27a73 | 5414 | element_type = die_type (die, cu); |
c906108c SS |
5415 | |
5416 | /* Irix 6.2 native cc creates array types without children for | |
5417 | arrays with unspecified length. */ | |
639d11d3 | 5418 | if (die->child == NULL) |
c906108c | 5419 | { |
46bf5051 | 5420 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5421 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
5422 | type = create_array_type (NULL, element_type, range_type); |
5423 | return set_die_type (die, type, cu); | |
c906108c SS |
5424 | } |
5425 | ||
5426 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 5427 | child_die = die->child; |
c906108c SS |
5428 | while (child_die && child_die->tag) |
5429 | { | |
5430 | if (child_die->tag == DW_TAG_subrange_type) | |
5431 | { | |
f792889a DJ |
5432 | struct type *child_type = read_type_die (child_die, cu); |
5433 | if (child_type != NULL) | |
a02abb62 JB |
5434 | { |
5435 | /* The range type was succesfully read. Save it for | |
5436 | the array type creation. */ | |
5437 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
5438 | { | |
5439 | range_types = (struct type **) | |
5440 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
5441 | * sizeof (struct type *)); | |
5442 | if (ndim == 0) | |
5443 | make_cleanup (free_current_contents, &range_types); | |
5444 | } | |
f792889a | 5445 | range_types[ndim++] = child_type; |
a02abb62 | 5446 | } |
c906108c SS |
5447 | } |
5448 | child_die = sibling_die (child_die); | |
5449 | } | |
5450 | ||
5451 | /* Dwarf2 dimensions are output from left to right, create the | |
5452 | necessary array types in backwards order. */ | |
7ca2d3a3 | 5453 | |
c906108c | 5454 | type = element_type; |
7ca2d3a3 DL |
5455 | |
5456 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
5457 | { | |
5458 | int i = 0; | |
5459 | while (i < ndim) | |
5460 | type = create_array_type (NULL, type, range_types[i++]); | |
5461 | } | |
5462 | else | |
5463 | { | |
5464 | while (ndim-- > 0) | |
5465 | type = create_array_type (NULL, type, range_types[ndim]); | |
5466 | } | |
c906108c | 5467 | |
f5f8a009 EZ |
5468 | /* Understand Dwarf2 support for vector types (like they occur on |
5469 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
5470 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
5471 | custom vendor extension. The main difference between a regular | |
5472 | array and the vector variant is that vectors are passed by value | |
5473 | to functions. */ | |
e142c38c | 5474 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 5475 | if (attr) |
ea37ba09 | 5476 | make_vector_type (type); |
f5f8a009 | 5477 | |
39cbfefa DJ |
5478 | name = dwarf2_name (die, cu); |
5479 | if (name) | |
5480 | TYPE_NAME (type) = name; | |
714e295e | 5481 | |
b4ba55a1 JB |
5482 | set_descriptive_type (type, die, cu); |
5483 | ||
c906108c SS |
5484 | do_cleanups (back_to); |
5485 | ||
5486 | /* Install the type in the die. */ | |
f792889a | 5487 | return set_die_type (die, type, cu); |
c906108c SS |
5488 | } |
5489 | ||
7ca2d3a3 DL |
5490 | static enum dwarf_array_dim_ordering |
5491 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
5492 | { | |
5493 | struct attribute *attr; | |
5494 | ||
5495 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
5496 | ||
5497 | if (attr) return DW_SND (attr); | |
5498 | ||
5499 | /* | |
5500 | GNU F77 is a special case, as at 08/2004 array type info is the | |
5501 | opposite order to the dwarf2 specification, but data is still | |
5502 | laid out as per normal fortran. | |
5503 | ||
5504 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
5505 | version checking. | |
5506 | */ | |
5507 | ||
905e0470 PM |
5508 | if (cu->language == language_fortran |
5509 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
5510 | { |
5511 | return DW_ORD_row_major; | |
5512 | } | |
5513 | ||
5514 | switch (cu->language_defn->la_array_ordering) | |
5515 | { | |
5516 | case array_column_major: | |
5517 | return DW_ORD_col_major; | |
5518 | case array_row_major: | |
5519 | default: | |
5520 | return DW_ORD_row_major; | |
5521 | }; | |
5522 | } | |
5523 | ||
72019c9c GM |
5524 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
5525 | the DIE's type field. */ | |
5526 | ||
f792889a | 5527 | static struct type * |
72019c9c GM |
5528 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
5529 | { | |
f792889a DJ |
5530 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
5531 | ||
5532 | return set_die_type (die, set_type, cu); | |
72019c9c | 5533 | } |
7ca2d3a3 | 5534 | |
c906108c SS |
5535 | /* First cut: install each common block member as a global variable. */ |
5536 | ||
5537 | static void | |
e7c27a73 | 5538 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5539 | { |
5540 | struct die_info *child_die; | |
5541 | struct attribute *attr; | |
5542 | struct symbol *sym; | |
5543 | CORE_ADDR base = (CORE_ADDR) 0; | |
5544 | ||
e142c38c | 5545 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
5546 | if (attr) |
5547 | { | |
8e19ed76 PS |
5548 | /* Support the .debug_loc offsets */ |
5549 | if (attr_form_is_block (attr)) | |
5550 | { | |
e7c27a73 | 5551 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 5552 | } |
3690dd37 | 5553 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 5554 | { |
4d3c2250 | 5555 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5556 | } |
5557 | else | |
5558 | { | |
4d3c2250 KB |
5559 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5560 | "common block member"); | |
8e19ed76 | 5561 | } |
c906108c | 5562 | } |
639d11d3 | 5563 | if (die->child != NULL) |
c906108c | 5564 | { |
639d11d3 | 5565 | child_die = die->child; |
c906108c SS |
5566 | while (child_die && child_die->tag) |
5567 | { | |
e7c27a73 | 5568 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 5569 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
5570 | if (attr) |
5571 | { | |
d4b96c9a JK |
5572 | CORE_ADDR byte_offset = 0; |
5573 | ||
5574 | if (attr_form_is_section_offset (attr)) | |
5575 | dwarf2_complex_location_expr_complaint (); | |
5576 | else if (attr_form_is_constant (attr)) | |
5577 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
5578 | else if (attr_form_is_block (attr)) | |
5579 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
5580 | else | |
5581 | dwarf2_complex_location_expr_complaint (); | |
5582 | ||
5583 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
5584 | add_symbol_to_list (sym, &global_symbols); |
5585 | } | |
5586 | child_die = sibling_die (child_die); | |
5587 | } | |
5588 | } | |
5589 | } | |
5590 | ||
0114d602 | 5591 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 5592 | |
0114d602 DJ |
5593 | static struct type * |
5594 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 5595 | { |
e7c27a73 | 5596 | struct objfile *objfile = cu->objfile; |
0114d602 | 5597 | const char *previous_prefix, *name; |
9219021c | 5598 | int is_anonymous; |
0114d602 DJ |
5599 | struct type *type; |
5600 | ||
5601 | /* For extensions, reuse the type of the original namespace. */ | |
5602 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
5603 | { | |
5604 | struct die_info *ext_die; | |
5605 | struct dwarf2_cu *ext_cu = cu; | |
5606 | ext_die = dwarf2_extension (die, &ext_cu); | |
5607 | type = read_type_die (ext_die, ext_cu); | |
5608 | return set_die_type (die, type, cu); | |
5609 | } | |
9219021c | 5610 | |
e142c38c | 5611 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
5612 | |
5613 | /* Now build the name of the current namespace. */ | |
5614 | ||
0114d602 DJ |
5615 | previous_prefix = determine_prefix (die, cu); |
5616 | if (previous_prefix[0] != '\0') | |
5617 | name = typename_concat (&objfile->objfile_obstack, | |
5618 | previous_prefix, name, cu); | |
5619 | ||
5620 | /* Create the type. */ | |
5621 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
5622 | objfile); | |
5623 | TYPE_NAME (type) = (char *) name; | |
5624 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5625 | ||
60531b24 | 5626 | return set_die_type (die, type, cu); |
0114d602 DJ |
5627 | } |
5628 | ||
5629 | /* Read a C++ namespace. */ | |
5630 | ||
5631 | static void | |
5632 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
5633 | { | |
5634 | struct objfile *objfile = cu->objfile; | |
5635 | const char *name; | |
5636 | int is_anonymous; | |
9219021c | 5637 | |
5c4e30ca DC |
5638 | /* Add a symbol associated to this if we haven't seen the namespace |
5639 | before. Also, add a using directive if it's an anonymous | |
5640 | namespace. */ | |
9219021c | 5641 | |
f2f0e013 | 5642 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
5643 | { |
5644 | struct type *type; | |
5645 | ||
0114d602 | 5646 | type = read_type_die (die, cu); |
e7c27a73 | 5647 | new_symbol (die, type, cu); |
5c4e30ca | 5648 | |
0114d602 | 5649 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 5650 | if (is_anonymous) |
0114d602 DJ |
5651 | { |
5652 | const char *previous_prefix = determine_prefix (die, cu); | |
c0cc3a76 | 5653 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 5654 | NULL, &objfile->objfile_obstack); |
0114d602 | 5655 | } |
5c4e30ca | 5656 | } |
9219021c | 5657 | |
639d11d3 | 5658 | if (die->child != NULL) |
d9fa45fe | 5659 | { |
639d11d3 | 5660 | struct die_info *child_die = die->child; |
d9fa45fe DC |
5661 | |
5662 | while (child_die && child_die->tag) | |
5663 | { | |
e7c27a73 | 5664 | process_die (child_die, cu); |
d9fa45fe DC |
5665 | child_die = sibling_die (child_die); |
5666 | } | |
5667 | } | |
38d518c9 EZ |
5668 | } |
5669 | ||
5d7cb8df JK |
5670 | /* Read a Fortran module. */ |
5671 | ||
5672 | static void | |
5673 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
5674 | { | |
5675 | struct die_info *child_die = die->child; | |
5676 | ||
5677 | /* FIXME: Support the separate Fortran module namespaces. */ | |
5678 | ||
5679 | while (child_die && child_die->tag) | |
5680 | { | |
5681 | process_die (child_die, cu); | |
5682 | child_die = sibling_die (child_die); | |
5683 | } | |
5684 | } | |
5685 | ||
38d518c9 EZ |
5686 | /* Return the name of the namespace represented by DIE. Set |
5687 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
5688 | namespace. */ | |
5689 | ||
5690 | static const char * | |
e142c38c | 5691 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
5692 | { |
5693 | struct die_info *current_die; | |
5694 | const char *name = NULL; | |
5695 | ||
5696 | /* Loop through the extensions until we find a name. */ | |
5697 | ||
5698 | for (current_die = die; | |
5699 | current_die != NULL; | |
f2f0e013 | 5700 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 5701 | { |
e142c38c | 5702 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
5703 | if (name != NULL) |
5704 | break; | |
5705 | } | |
5706 | ||
5707 | /* Is it an anonymous namespace? */ | |
5708 | ||
5709 | *is_anonymous = (name == NULL); | |
5710 | if (*is_anonymous) | |
5711 | name = "(anonymous namespace)"; | |
5712 | ||
5713 | return name; | |
d9fa45fe DC |
5714 | } |
5715 | ||
c906108c SS |
5716 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
5717 | the user defined type vector. */ | |
5718 | ||
f792889a | 5719 | static struct type * |
e7c27a73 | 5720 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5721 | { |
5e2b427d | 5722 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 5723 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 5724 | struct type *type; |
8b2dbe47 KB |
5725 | struct attribute *attr_byte_size; |
5726 | struct attribute *attr_address_class; | |
5727 | int byte_size, addr_class; | |
c906108c | 5728 | |
e7c27a73 | 5729 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 5730 | |
e142c38c | 5731 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
5732 | if (attr_byte_size) |
5733 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 5734 | else |
8b2dbe47 KB |
5735 | byte_size = cu_header->addr_size; |
5736 | ||
e142c38c | 5737 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
5738 | if (attr_address_class) |
5739 | addr_class = DW_UNSND (attr_address_class); | |
5740 | else | |
5741 | addr_class = DW_ADDR_none; | |
5742 | ||
5743 | /* If the pointer size or address class is different than the | |
5744 | default, create a type variant marked as such and set the | |
5745 | length accordingly. */ | |
5746 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 5747 | { |
5e2b427d | 5748 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
5749 | { |
5750 | int type_flags; | |
5751 | ||
849957d9 | 5752 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 5753 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
5754 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
5755 | == 0); | |
8b2dbe47 KB |
5756 | type = make_type_with_address_space (type, type_flags); |
5757 | } | |
5758 | else if (TYPE_LENGTH (type) != byte_size) | |
5759 | { | |
e2e0b3e5 | 5760 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
5761 | } |
5762 | else { | |
5763 | /* Should we also complain about unhandled address classes? */ | |
5764 | } | |
c906108c | 5765 | } |
8b2dbe47 KB |
5766 | |
5767 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 5768 | return set_die_type (die, type, cu); |
c906108c SS |
5769 | } |
5770 | ||
5771 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
5772 | the user defined type vector. */ | |
5773 | ||
f792889a | 5774 | static struct type * |
e7c27a73 | 5775 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5776 | { |
5777 | struct type *type; | |
5778 | struct type *to_type; | |
5779 | struct type *domain; | |
5780 | ||
e7c27a73 DJ |
5781 | to_type = die_type (die, cu); |
5782 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
5783 | |
5784 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
5785 | type = lookup_methodptr_type (to_type); | |
5786 | else | |
5787 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 5788 | |
f792889a | 5789 | return set_die_type (die, type, cu); |
c906108c SS |
5790 | } |
5791 | ||
5792 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
5793 | the user defined type vector. */ | |
5794 | ||
f792889a | 5795 | static struct type * |
e7c27a73 | 5796 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5797 | { |
e7c27a73 | 5798 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5799 | struct type *type; |
5800 | struct attribute *attr; | |
5801 | ||
e7c27a73 | 5802 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 5803 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5804 | if (attr) |
5805 | { | |
5806 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5807 | } | |
5808 | else | |
5809 | { | |
107d2387 | 5810 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 5811 | } |
f792889a | 5812 | return set_die_type (die, type, cu); |
c906108c SS |
5813 | } |
5814 | ||
f792889a | 5815 | static struct type * |
e7c27a73 | 5816 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5817 | { |
f792889a | 5818 | struct type *base_type, *cv_type; |
c906108c | 5819 | |
e7c27a73 | 5820 | base_type = die_type (die, cu); |
f792889a DJ |
5821 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
5822 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5823 | } |
5824 | ||
f792889a | 5825 | static struct type * |
e7c27a73 | 5826 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5827 | { |
f792889a | 5828 | struct type *base_type, *cv_type; |
c906108c | 5829 | |
e7c27a73 | 5830 | base_type = die_type (die, cu); |
f792889a DJ |
5831 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
5832 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5833 | } |
5834 | ||
5835 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
5836 | the user defined type vector. It isn't really a user defined type, | |
5837 | but it behaves like one, with other DIE's using an AT_user_def_type | |
5838 | attribute to reference it. */ | |
5839 | ||
f792889a | 5840 | static struct type * |
e7c27a73 | 5841 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5842 | { |
e7c27a73 | 5843 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 5844 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5845 | struct type *type, *range_type, *index_type, *char_type; |
5846 | struct attribute *attr; | |
5847 | unsigned int length; | |
5848 | ||
e142c38c | 5849 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
5850 | if (attr) |
5851 | { | |
5852 | length = DW_UNSND (attr); | |
5853 | } | |
5854 | else | |
5855 | { | |
b21b22e0 | 5856 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 5857 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
5858 | if (attr) |
5859 | { | |
5860 | length = DW_UNSND (attr); | |
5861 | } | |
5862 | else | |
5863 | { | |
5864 | length = 1; | |
5865 | } | |
c906108c | 5866 | } |
6ccb9162 | 5867 | |
46bf5051 | 5868 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5869 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
5870 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
5871 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 5872 | |
f792889a | 5873 | return set_die_type (die, type, cu); |
c906108c SS |
5874 | } |
5875 | ||
5876 | /* Handle DIES due to C code like: | |
5877 | ||
5878 | struct foo | |
c5aa993b JM |
5879 | { |
5880 | int (*funcp)(int a, long l); | |
5881 | int b; | |
5882 | }; | |
c906108c SS |
5883 | |
5884 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 5885 | */ |
c906108c | 5886 | |
f792889a | 5887 | static struct type * |
e7c27a73 | 5888 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5889 | { |
5890 | struct type *type; /* Type that this function returns */ | |
5891 | struct type *ftype; /* Function that returns above type */ | |
5892 | struct attribute *attr; | |
5893 | ||
e7c27a73 | 5894 | type = die_type (die, cu); |
0c8b41f1 | 5895 | ftype = lookup_function_type (type); |
c906108c | 5896 | |
5b8101ae | 5897 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 5898 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 5899 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 5900 | || cu->language == language_cplus |
5b8101ae PM |
5901 | || cu->language == language_java |
5902 | || cu->language == language_pascal) | |
876cecd0 | 5903 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
5904 | else if (producer_is_realview (cu->producer)) |
5905 | /* RealView does not emit DW_AT_prototyped. We can not | |
5906 | distinguish prototyped and unprototyped functions; default to | |
5907 | prototyped, since that is more common in modern code (and | |
5908 | RealView warns about unprototyped functions). */ | |
5909 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 5910 | |
c055b101 CV |
5911 | /* Store the calling convention in the type if it's available in |
5912 | the subroutine die. Otherwise set the calling convention to | |
5913 | the default value DW_CC_normal. */ | |
5914 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
5915 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
5916 | |
5917 | /* We need to add the subroutine type to the die immediately so | |
5918 | we don't infinitely recurse when dealing with parameters | |
5919 | declared as the same subroutine type. */ | |
5920 | set_die_type (die, ftype, cu); | |
c055b101 | 5921 | |
639d11d3 | 5922 | if (die->child != NULL) |
c906108c | 5923 | { |
8072405b | 5924 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 5925 | struct die_info *child_die; |
8072405b | 5926 | int nparams, iparams; |
c906108c SS |
5927 | |
5928 | /* Count the number of parameters. | |
5929 | FIXME: GDB currently ignores vararg functions, but knows about | |
5930 | vararg member functions. */ | |
8072405b | 5931 | nparams = 0; |
639d11d3 | 5932 | child_die = die->child; |
c906108c SS |
5933 | while (child_die && child_die->tag) |
5934 | { | |
5935 | if (child_die->tag == DW_TAG_formal_parameter) | |
5936 | nparams++; | |
5937 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 5938 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
5939 | child_die = sibling_die (child_die); |
5940 | } | |
5941 | ||
5942 | /* Allocate storage for parameters and fill them in. */ | |
5943 | TYPE_NFIELDS (ftype) = nparams; | |
5944 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 5945 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 5946 | |
8072405b JK |
5947 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
5948 | even if we error out during the parameters reading below. */ | |
5949 | for (iparams = 0; iparams < nparams; iparams++) | |
5950 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
5951 | ||
5952 | iparams = 0; | |
639d11d3 | 5953 | child_die = die->child; |
c906108c SS |
5954 | while (child_die && child_die->tag) |
5955 | { | |
5956 | if (child_die->tag == DW_TAG_formal_parameter) | |
5957 | { | |
5958 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
5959 | member functions. G++ helps GDB by marking the first |
5960 | parameter for non-static member functions (which is the | |
5961 | this pointer) as artificial. We pass this information | |
5962 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 5963 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
5964 | if (attr) |
5965 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
5966 | else | |
418835cc KS |
5967 | { |
5968 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
5969 | ||
5970 | /* GCC/43521: In java, the formal parameter | |
5971 | "this" is sometimes not marked with DW_AT_artificial. */ | |
5972 | if (cu->language == language_java) | |
5973 | { | |
5974 | const char *name = dwarf2_name (child_die, cu); | |
5975 | if (name && !strcmp (name, "this")) | |
5976 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
5977 | } | |
5978 | } | |
e7c27a73 | 5979 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
5980 | iparams++; |
5981 | } | |
5982 | child_die = sibling_die (child_die); | |
5983 | } | |
5984 | } | |
5985 | ||
76c10ea2 | 5986 | return ftype; |
c906108c SS |
5987 | } |
5988 | ||
f792889a | 5989 | static struct type * |
e7c27a73 | 5990 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5991 | { |
e7c27a73 | 5992 | struct objfile *objfile = cu->objfile; |
0114d602 | 5993 | const char *name = NULL; |
f792889a | 5994 | struct type *this_type; |
c906108c | 5995 | |
94af9270 | 5996 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 5997 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
5998 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
5999 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
6000 | set_die_type (die, this_type, cu); |
6001 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
6002 | return this_type; | |
c906108c SS |
6003 | } |
6004 | ||
6005 | /* Find a representation of a given base type and install | |
6006 | it in the TYPE field of the die. */ | |
6007 | ||
f792889a | 6008 | static struct type * |
e7c27a73 | 6009 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6010 | { |
e7c27a73 | 6011 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6012 | struct type *type; |
6013 | struct attribute *attr; | |
6014 | int encoding = 0, size = 0; | |
39cbfefa | 6015 | char *name; |
6ccb9162 UW |
6016 | enum type_code code = TYPE_CODE_INT; |
6017 | int type_flags = 0; | |
6018 | struct type *target_type = NULL; | |
c906108c | 6019 | |
e142c38c | 6020 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
6021 | if (attr) |
6022 | { | |
6023 | encoding = DW_UNSND (attr); | |
6024 | } | |
e142c38c | 6025 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6026 | if (attr) |
6027 | { | |
6028 | size = DW_UNSND (attr); | |
6029 | } | |
39cbfefa | 6030 | name = dwarf2_name (die, cu); |
6ccb9162 | 6031 | if (!name) |
c906108c | 6032 | { |
6ccb9162 UW |
6033 | complaint (&symfile_complaints, |
6034 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 6035 | } |
6ccb9162 UW |
6036 | |
6037 | switch (encoding) | |
c906108c | 6038 | { |
6ccb9162 UW |
6039 | case DW_ATE_address: |
6040 | /* Turn DW_ATE_address into a void * pointer. */ | |
6041 | code = TYPE_CODE_PTR; | |
6042 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6043 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
6044 | break; | |
6045 | case DW_ATE_boolean: | |
6046 | code = TYPE_CODE_BOOL; | |
6047 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6048 | break; | |
6049 | case DW_ATE_complex_float: | |
6050 | code = TYPE_CODE_COMPLEX; | |
6051 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
6052 | break; | |
6053 | case DW_ATE_decimal_float: | |
6054 | code = TYPE_CODE_DECFLOAT; | |
6055 | break; | |
6056 | case DW_ATE_float: | |
6057 | code = TYPE_CODE_FLT; | |
6058 | break; | |
6059 | case DW_ATE_signed: | |
6060 | break; | |
6061 | case DW_ATE_unsigned: | |
6062 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6063 | break; | |
6064 | case DW_ATE_signed_char: | |
868a0084 PM |
6065 | if (cu->language == language_ada || cu->language == language_m2 |
6066 | || cu->language == language_pascal) | |
6ccb9162 UW |
6067 | code = TYPE_CODE_CHAR; |
6068 | break; | |
6069 | case DW_ATE_unsigned_char: | |
868a0084 PM |
6070 | if (cu->language == language_ada || cu->language == language_m2 |
6071 | || cu->language == language_pascal) | |
6ccb9162 UW |
6072 | code = TYPE_CODE_CHAR; |
6073 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6074 | break; | |
6075 | default: | |
6076 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
6077 | dwarf_type_encoding_name (encoding)); | |
6078 | break; | |
c906108c | 6079 | } |
6ccb9162 | 6080 | |
0114d602 DJ |
6081 | type = init_type (code, size, type_flags, NULL, objfile); |
6082 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
6083 | TYPE_TARGET_TYPE (type) = target_type; |
6084 | ||
0114d602 | 6085 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 6086 | TYPE_NOSIGN (type) = 1; |
0114d602 | 6087 | |
f792889a | 6088 | return set_die_type (die, type, cu); |
c906108c SS |
6089 | } |
6090 | ||
a02abb62 JB |
6091 | /* Read the given DW_AT_subrange DIE. */ |
6092 | ||
f792889a | 6093 | static struct type * |
a02abb62 JB |
6094 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
6095 | { | |
5e2b427d | 6096 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
6097 | struct type *base_type; |
6098 | struct type *range_type; | |
6099 | struct attribute *attr; | |
43bbcdc2 PH |
6100 | LONGEST low = 0; |
6101 | LONGEST high = -1; | |
39cbfefa | 6102 | char *name; |
43bbcdc2 | 6103 | LONGEST negative_mask; |
a02abb62 | 6104 | |
a02abb62 | 6105 | base_type = die_type (die, cu); |
3d1f72c2 | 6106 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
6107 | { |
6108 | complaint (&symfile_complaints, | |
e2e0b3e5 | 6109 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 6110 | base_type |
5e2b427d | 6111 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 6112 | 0, NULL, cu->objfile); |
a02abb62 JB |
6113 | } |
6114 | ||
e142c38c | 6115 | if (cu->language == language_fortran) |
a02abb62 JB |
6116 | { |
6117 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
6118 | low = 1; | |
6119 | } | |
6120 | ||
dd5e6932 DJ |
6121 | /* FIXME: For variable sized arrays either of these could be |
6122 | a variable rather than a constant value. We'll allow it, | |
6123 | but we don't know how to handle it. */ | |
e142c38c | 6124 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
6125 | if (attr) |
6126 | low = dwarf2_get_attr_constant_value (attr, 0); | |
6127 | ||
e142c38c | 6128 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
6129 | if (attr) |
6130 | { | |
6131 | if (attr->form == DW_FORM_block1) | |
6132 | { | |
6133 | /* GCC encodes arrays with unspecified or dynamic length | |
6134 | with a DW_FORM_block1 attribute. | |
6135 | FIXME: GDB does not yet know how to handle dynamic | |
6136 | arrays properly, treat them as arrays with unspecified | |
6137 | length for now. | |
6138 | ||
6139 | FIXME: jimb/2003-09-22: GDB does not really know | |
6140 | how to handle arrays of unspecified length | |
6141 | either; we just represent them as zero-length | |
6142 | arrays. Choose an appropriate upper bound given | |
6143 | the lower bound we've computed above. */ | |
6144 | high = low - 1; | |
6145 | } | |
6146 | else | |
6147 | high = dwarf2_get_attr_constant_value (attr, 1); | |
6148 | } | |
6149 | ||
43bbcdc2 PH |
6150 | negative_mask = |
6151 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); | |
6152 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
6153 | low |= negative_mask; | |
6154 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
6155 | high |= negative_mask; | |
6156 | ||
a02abb62 JB |
6157 | range_type = create_range_type (NULL, base_type, low, high); |
6158 | ||
bbb0eef6 JK |
6159 | /* Mark arrays with dynamic length at least as an array of unspecified |
6160 | length. GDB could check the boundary but before it gets implemented at | |
6161 | least allow accessing the array elements. */ | |
6162 | if (attr && attr->form == DW_FORM_block1) | |
6163 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
6164 | ||
39cbfefa DJ |
6165 | name = dwarf2_name (die, cu); |
6166 | if (name) | |
6167 | TYPE_NAME (range_type) = name; | |
a02abb62 | 6168 | |
e142c38c | 6169 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
6170 | if (attr) |
6171 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
6172 | ||
b4ba55a1 JB |
6173 | set_descriptive_type (range_type, die, cu); |
6174 | ||
f792889a | 6175 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
6176 | } |
6177 | ||
f792889a | 6178 | static struct type * |
81a17f79 JB |
6179 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
6180 | { | |
6181 | struct type *type; | |
81a17f79 | 6182 | |
81a17f79 JB |
6183 | /* For now, we only support the C meaning of an unspecified type: void. */ |
6184 | ||
0114d602 DJ |
6185 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
6186 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 6187 | |
f792889a | 6188 | return set_die_type (die, type, cu); |
81a17f79 | 6189 | } |
a02abb62 | 6190 | |
51545339 DJ |
6191 | /* Trivial hash function for die_info: the hash value of a DIE |
6192 | is its offset in .debug_info for this objfile. */ | |
6193 | ||
6194 | static hashval_t | |
6195 | die_hash (const void *item) | |
6196 | { | |
6197 | const struct die_info *die = item; | |
6198 | return die->offset; | |
6199 | } | |
6200 | ||
6201 | /* Trivial comparison function for die_info structures: two DIEs | |
6202 | are equal if they have the same offset. */ | |
6203 | ||
6204 | static int | |
6205 | die_eq (const void *item_lhs, const void *item_rhs) | |
6206 | { | |
6207 | const struct die_info *die_lhs = item_lhs; | |
6208 | const struct die_info *die_rhs = item_rhs; | |
6209 | return die_lhs->offset == die_rhs->offset; | |
6210 | } | |
6211 | ||
c906108c SS |
6212 | /* Read a whole compilation unit into a linked list of dies. */ |
6213 | ||
f9aca02d | 6214 | static struct die_info * |
93311388 | 6215 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 6216 | { |
93311388 DE |
6217 | struct die_reader_specs reader_specs; |
6218 | ||
348e048f | 6219 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
6220 | cu->die_hash |
6221 | = htab_create_alloc_ex (cu->header.length / 12, | |
6222 | die_hash, | |
6223 | die_eq, | |
6224 | NULL, | |
6225 | &cu->comp_unit_obstack, | |
6226 | hashtab_obstack_allocate, | |
6227 | dummy_obstack_deallocate); | |
6228 | ||
93311388 DE |
6229 | init_cu_die_reader (&reader_specs, cu); |
6230 | ||
6231 | return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); | |
639d11d3 DC |
6232 | } |
6233 | ||
d97bc12b DE |
6234 | /* Main entry point for reading a DIE and all children. |
6235 | Read the DIE and dump it if requested. */ | |
6236 | ||
6237 | static struct die_info * | |
93311388 DE |
6238 | read_die_and_children (const struct die_reader_specs *reader, |
6239 | gdb_byte *info_ptr, | |
d97bc12b DE |
6240 | gdb_byte **new_info_ptr, |
6241 | struct die_info *parent) | |
6242 | { | |
93311388 | 6243 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
6244 | new_info_ptr, parent); |
6245 | ||
6246 | if (dwarf2_die_debug) | |
6247 | { | |
348e048f DE |
6248 | fprintf_unfiltered (gdb_stdlog, |
6249 | "\nRead die from %s of %s:\n", | |
6250 | reader->buffer == dwarf2_per_objfile->info.buffer | |
6251 | ? ".debug_info" | |
6252 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
6253 | ? ".debug_types" | |
6254 | : "unknown section", | |
6255 | reader->abfd->filename); | |
d97bc12b DE |
6256 | dump_die (result, dwarf2_die_debug); |
6257 | } | |
6258 | ||
6259 | return result; | |
6260 | } | |
6261 | ||
639d11d3 DC |
6262 | /* Read a single die and all its descendents. Set the die's sibling |
6263 | field to NULL; set other fields in the die correctly, and set all | |
6264 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
6265 | location of the info_ptr after reading all of those dies. PARENT | |
6266 | is the parent of the die in question. */ | |
6267 | ||
6268 | static struct die_info * | |
93311388 DE |
6269 | read_die_and_children_1 (const struct die_reader_specs *reader, |
6270 | gdb_byte *info_ptr, | |
d97bc12b DE |
6271 | gdb_byte **new_info_ptr, |
6272 | struct die_info *parent) | |
639d11d3 DC |
6273 | { |
6274 | struct die_info *die; | |
fe1b8b76 | 6275 | gdb_byte *cur_ptr; |
639d11d3 DC |
6276 | int has_children; |
6277 | ||
93311388 | 6278 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
6279 | if (die == NULL) |
6280 | { | |
6281 | *new_info_ptr = cur_ptr; | |
6282 | return NULL; | |
6283 | } | |
93311388 | 6284 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
6285 | |
6286 | if (has_children) | |
348e048f | 6287 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
6288 | else |
6289 | { | |
6290 | die->child = NULL; | |
6291 | *new_info_ptr = cur_ptr; | |
6292 | } | |
6293 | ||
6294 | die->sibling = NULL; | |
6295 | die->parent = parent; | |
6296 | return die; | |
6297 | } | |
6298 | ||
6299 | /* Read a die, all of its descendents, and all of its siblings; set | |
6300 | all of the fields of all of the dies correctly. Arguments are as | |
6301 | in read_die_and_children. */ | |
6302 | ||
6303 | static struct die_info * | |
93311388 DE |
6304 | read_die_and_siblings (const struct die_reader_specs *reader, |
6305 | gdb_byte *info_ptr, | |
fe1b8b76 | 6306 | gdb_byte **new_info_ptr, |
639d11d3 DC |
6307 | struct die_info *parent) |
6308 | { | |
6309 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 6310 | gdb_byte *cur_ptr; |
639d11d3 | 6311 | |
c906108c | 6312 | cur_ptr = info_ptr; |
639d11d3 DC |
6313 | first_die = last_sibling = NULL; |
6314 | ||
6315 | while (1) | |
c906108c | 6316 | { |
639d11d3 | 6317 | struct die_info *die |
93311388 | 6318 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 6319 | |
1d325ec1 | 6320 | if (die == NULL) |
c906108c | 6321 | { |
639d11d3 DC |
6322 | *new_info_ptr = cur_ptr; |
6323 | return first_die; | |
c906108c | 6324 | } |
1d325ec1 DJ |
6325 | |
6326 | if (!first_die) | |
6327 | first_die = die; | |
c906108c | 6328 | else |
1d325ec1 DJ |
6329 | last_sibling->sibling = die; |
6330 | ||
6331 | last_sibling = die; | |
c906108c | 6332 | } |
c906108c SS |
6333 | } |
6334 | ||
93311388 DE |
6335 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6336 | point to a newly allocated die with its information, except for its | |
6337 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6338 | whether the die has children or not. */ | |
6339 | ||
6340 | static gdb_byte * | |
6341 | read_full_die (const struct die_reader_specs *reader, | |
6342 | struct die_info **diep, gdb_byte *info_ptr, | |
6343 | int *has_children) | |
6344 | { | |
6345 | unsigned int abbrev_number, bytes_read, i, offset; | |
6346 | struct abbrev_info *abbrev; | |
6347 | struct die_info *die; | |
6348 | struct dwarf2_cu *cu = reader->cu; | |
6349 | bfd *abfd = reader->abfd; | |
6350 | ||
6351 | offset = info_ptr - reader->buffer; | |
6352 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6353 | info_ptr += bytes_read; | |
6354 | if (!abbrev_number) | |
6355 | { | |
6356 | *diep = NULL; | |
6357 | *has_children = 0; | |
6358 | return info_ptr; | |
6359 | } | |
6360 | ||
6361 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
6362 | if (!abbrev) | |
348e048f DE |
6363 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
6364 | abbrev_number, | |
6365 | bfd_get_filename (abfd)); | |
6366 | ||
93311388 DE |
6367 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
6368 | die->offset = offset; | |
6369 | die->tag = abbrev->tag; | |
6370 | die->abbrev = abbrev_number; | |
6371 | ||
6372 | die->num_attrs = abbrev->num_attrs; | |
6373 | ||
6374 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6375 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
6376 | abfd, info_ptr, cu); | |
6377 | ||
6378 | *diep = die; | |
6379 | *has_children = abbrev->has_children; | |
6380 | return info_ptr; | |
6381 | } | |
6382 | ||
c906108c SS |
6383 | /* In DWARF version 2, the description of the debugging information is |
6384 | stored in a separate .debug_abbrev section. Before we read any | |
6385 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
6386 | in a hash table. This function also sets flags in CU describing |
6387 | the data found in the abbrev table. */ | |
c906108c SS |
6388 | |
6389 | static void | |
e7c27a73 | 6390 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 6391 | { |
e7c27a73 | 6392 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 6393 | gdb_byte *abbrev_ptr; |
c906108c SS |
6394 | struct abbrev_info *cur_abbrev; |
6395 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
6396 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
6397 | struct attr_abbrev *cur_attrs; |
6398 | unsigned int allocated_attrs; | |
c906108c | 6399 | |
57349743 | 6400 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
6401 | obstack_init (&cu->abbrev_obstack); |
6402 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
6403 | (ABBREV_HASH_SIZE | |
6404 | * sizeof (struct abbrev_info *))); | |
6405 | memset (cu->dwarf2_abbrevs, 0, | |
6406 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 6407 | |
be391dca TT |
6408 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
6409 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 6410 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
6411 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6412 | abbrev_ptr += bytes_read; | |
6413 | ||
f3dd6933 DJ |
6414 | allocated_attrs = ATTR_ALLOC_CHUNK; |
6415 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6416 | ||
c906108c SS |
6417 | /* loop until we reach an abbrev number of 0 */ |
6418 | while (abbrev_number) | |
6419 | { | |
f3dd6933 | 6420 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
6421 | |
6422 | /* read in abbrev header */ | |
6423 | cur_abbrev->number = abbrev_number; | |
6424 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6425 | abbrev_ptr += bytes_read; | |
6426 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
6427 | abbrev_ptr += 1; | |
6428 | ||
72bf9492 DJ |
6429 | if (cur_abbrev->tag == DW_TAG_namespace) |
6430 | cu->has_namespace_info = 1; | |
6431 | ||
c906108c SS |
6432 | /* now read in declarations */ |
6433 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6434 | abbrev_ptr += bytes_read; | |
6435 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6436 | abbrev_ptr += bytes_read; | |
6437 | while (abbrev_name) | |
6438 | { | |
f3dd6933 | 6439 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 6440 | { |
f3dd6933 DJ |
6441 | allocated_attrs += ATTR_ALLOC_CHUNK; |
6442 | cur_attrs | |
6443 | = xrealloc (cur_attrs, (allocated_attrs | |
6444 | * sizeof (struct attr_abbrev))); | |
c906108c | 6445 | } |
ae038cb0 DJ |
6446 | |
6447 | /* Record whether this compilation unit might have | |
6448 | inter-compilation-unit references. If we don't know what form | |
6449 | this attribute will have, then it might potentially be a | |
6450 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
6451 | references. */ | |
6452 | ||
6453 | if (abbrev_form == DW_FORM_ref_addr | |
6454 | || abbrev_form == DW_FORM_indirect) | |
6455 | cu->has_form_ref_addr = 1; | |
6456 | ||
f3dd6933 DJ |
6457 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
6458 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
6459 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6460 | abbrev_ptr += bytes_read; | |
6461 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6462 | abbrev_ptr += bytes_read; | |
6463 | } | |
6464 | ||
f3dd6933 DJ |
6465 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
6466 | (cur_abbrev->num_attrs | |
6467 | * sizeof (struct attr_abbrev))); | |
6468 | memcpy (cur_abbrev->attrs, cur_attrs, | |
6469 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
6470 | ||
c906108c | 6471 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
6472 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
6473 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
6474 | |
6475 | /* Get next abbreviation. | |
6476 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
6477 | always properly terminated with an abbrev number of 0. |
6478 | Exit loop if we encounter an abbreviation which we have | |
6479 | already read (which means we are about to read the abbreviations | |
6480 | for the next compile unit) or if the end of the abbreviation | |
6481 | table is reached. */ | |
dce234bc PP |
6482 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
6483 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
6484 | break; |
6485 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6486 | abbrev_ptr += bytes_read; | |
e7c27a73 | 6487 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
6488 | break; |
6489 | } | |
f3dd6933 DJ |
6490 | |
6491 | xfree (cur_attrs); | |
c906108c SS |
6492 | } |
6493 | ||
f3dd6933 | 6494 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 6495 | |
c906108c | 6496 | static void |
f3dd6933 | 6497 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 6498 | { |
f3dd6933 | 6499 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 6500 | |
f3dd6933 DJ |
6501 | obstack_free (&cu->abbrev_obstack, NULL); |
6502 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
6503 | } |
6504 | ||
6505 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
6506 | ||
6507 | static struct abbrev_info * | |
e7c27a73 | 6508 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
6509 | { |
6510 | unsigned int hash_number; | |
6511 | struct abbrev_info *abbrev; | |
6512 | ||
6513 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 6514 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
6515 | |
6516 | while (abbrev) | |
6517 | { | |
6518 | if (abbrev->number == number) | |
6519 | return abbrev; | |
6520 | else | |
6521 | abbrev = abbrev->next; | |
6522 | } | |
6523 | return NULL; | |
6524 | } | |
6525 | ||
72bf9492 DJ |
6526 | /* Returns nonzero if TAG represents a type that we might generate a partial |
6527 | symbol for. */ | |
6528 | ||
6529 | static int | |
6530 | is_type_tag_for_partial (int tag) | |
6531 | { | |
6532 | switch (tag) | |
6533 | { | |
6534 | #if 0 | |
6535 | /* Some types that would be reasonable to generate partial symbols for, | |
6536 | that we don't at present. */ | |
6537 | case DW_TAG_array_type: | |
6538 | case DW_TAG_file_type: | |
6539 | case DW_TAG_ptr_to_member_type: | |
6540 | case DW_TAG_set_type: | |
6541 | case DW_TAG_string_type: | |
6542 | case DW_TAG_subroutine_type: | |
6543 | #endif | |
6544 | case DW_TAG_base_type: | |
6545 | case DW_TAG_class_type: | |
680b30c7 | 6546 | case DW_TAG_interface_type: |
72bf9492 DJ |
6547 | case DW_TAG_enumeration_type: |
6548 | case DW_TAG_structure_type: | |
6549 | case DW_TAG_subrange_type: | |
6550 | case DW_TAG_typedef: | |
6551 | case DW_TAG_union_type: | |
6552 | return 1; | |
6553 | default: | |
6554 | return 0; | |
6555 | } | |
6556 | } | |
6557 | ||
6558 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
6559 | ||
6560 | static struct partial_die_info * | |
93311388 DE |
6561 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
6562 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
6563 | { |
6564 | struct partial_die_info *part_die; | |
6565 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
6566 | struct abbrev_info *abbrev; | |
6567 | unsigned int bytes_read; | |
5afb4e99 | 6568 | unsigned int load_all = 0; |
72bf9492 DJ |
6569 | |
6570 | int nesting_level = 1; | |
6571 | ||
6572 | parent_die = NULL; | |
6573 | last_die = NULL; | |
6574 | ||
5afb4e99 DJ |
6575 | if (cu->per_cu && cu->per_cu->load_all_dies) |
6576 | load_all = 1; | |
6577 | ||
72bf9492 DJ |
6578 | cu->partial_dies |
6579 | = htab_create_alloc_ex (cu->header.length / 12, | |
6580 | partial_die_hash, | |
6581 | partial_die_eq, | |
6582 | NULL, | |
6583 | &cu->comp_unit_obstack, | |
6584 | hashtab_obstack_allocate, | |
6585 | dummy_obstack_deallocate); | |
6586 | ||
6587 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6588 | sizeof (struct partial_die_info)); | |
6589 | ||
6590 | while (1) | |
6591 | { | |
6592 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
6593 | ||
6594 | /* A NULL abbrev means the end of a series of children. */ | |
6595 | if (abbrev == NULL) | |
6596 | { | |
6597 | if (--nesting_level == 0) | |
6598 | { | |
6599 | /* PART_DIE was probably the last thing allocated on the | |
6600 | comp_unit_obstack, so we could call obstack_free | |
6601 | here. We don't do that because the waste is small, | |
6602 | and will be cleaned up when we're done with this | |
6603 | compilation unit. This way, we're also more robust | |
6604 | against other users of the comp_unit_obstack. */ | |
6605 | return first_die; | |
6606 | } | |
6607 | info_ptr += bytes_read; | |
6608 | last_die = parent_die; | |
6609 | parent_die = parent_die->die_parent; | |
6610 | continue; | |
6611 | } | |
6612 | ||
5afb4e99 DJ |
6613 | /* Check whether this DIE is interesting enough to save. Normally |
6614 | we would not be interested in members here, but there may be | |
6615 | later variables referencing them via DW_AT_specification (for | |
6616 | static members). */ | |
6617 | if (!load_all | |
6618 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
6619 | && abbrev->tag != DW_TAG_enumerator |
6620 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 6621 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 6622 | && abbrev->tag != DW_TAG_variable |
5afb4e99 DJ |
6623 | && abbrev->tag != DW_TAG_namespace |
6624 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
6625 | { |
6626 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6627 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
6628 | continue; |
6629 | } | |
6630 | ||
93311388 DE |
6631 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
6632 | buffer, info_ptr, cu); | |
72bf9492 DJ |
6633 | |
6634 | /* This two-pass algorithm for processing partial symbols has a | |
6635 | high cost in cache pressure. Thus, handle some simple cases | |
6636 | here which cover the majority of C partial symbols. DIEs | |
6637 | which neither have specification tags in them, nor could have | |
6638 | specification tags elsewhere pointing at them, can simply be | |
6639 | processed and discarded. | |
6640 | ||
6641 | This segment is also optional; scan_partial_symbols and | |
6642 | add_partial_symbol will handle these DIEs if we chain | |
6643 | them in normally. When compilers which do not emit large | |
6644 | quantities of duplicate debug information are more common, | |
6645 | this code can probably be removed. */ | |
6646 | ||
6647 | /* Any complete simple types at the top level (pretty much all | |
6648 | of them, for a language without namespaces), can be processed | |
6649 | directly. */ | |
6650 | if (parent_die == NULL | |
6651 | && part_die->has_specification == 0 | |
6652 | && part_die->is_declaration == 0 | |
6653 | && (part_die->tag == DW_TAG_typedef | |
6654 | || part_die->tag == DW_TAG_base_type | |
6655 | || part_die->tag == DW_TAG_subrange_type)) | |
6656 | { | |
6657 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 6658 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
6659 | VAR_DOMAIN, LOC_TYPEDEF, |
6660 | &cu->objfile->static_psymbols, | |
6661 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 6662 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6663 | continue; |
6664 | } | |
6665 | ||
6666 | /* If we're at the second level, and we're an enumerator, and | |
6667 | our parent has no specification (meaning possibly lives in a | |
6668 | namespace elsewhere), then we can add the partial symbol now | |
6669 | instead of queueing it. */ | |
6670 | if (part_die->tag == DW_TAG_enumerator | |
6671 | && parent_die != NULL | |
6672 | && parent_die->die_parent == NULL | |
6673 | && parent_die->tag == DW_TAG_enumeration_type | |
6674 | && parent_die->has_specification == 0) | |
6675 | { | |
6676 | if (part_die->name == NULL) | |
e2e0b3e5 | 6677 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 6678 | else if (building_psymtab) |
04a679b8 | 6679 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 6680 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
6681 | (cu->language == language_cplus |
6682 | || cu->language == language_java) | |
72bf9492 DJ |
6683 | ? &cu->objfile->global_psymbols |
6684 | : &cu->objfile->static_psymbols, | |
6685 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
6686 | ||
93311388 | 6687 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6688 | continue; |
6689 | } | |
6690 | ||
6691 | /* We'll save this DIE so link it in. */ | |
6692 | part_die->die_parent = parent_die; | |
6693 | part_die->die_sibling = NULL; | |
6694 | part_die->die_child = NULL; | |
6695 | ||
6696 | if (last_die && last_die == parent_die) | |
6697 | last_die->die_child = part_die; | |
6698 | else if (last_die) | |
6699 | last_die->die_sibling = part_die; | |
6700 | ||
6701 | last_die = part_die; | |
6702 | ||
6703 | if (first_die == NULL) | |
6704 | first_die = part_die; | |
6705 | ||
6706 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
6707 | find interesting need to be in the hash table, because we | |
6708 | also have the parent/sibling/child chains; only those that we | |
6709 | might refer to by offset later during partial symbol reading. | |
6710 | ||
6711 | For now this means things that might have be the target of a | |
6712 | DW_AT_specification, DW_AT_abstract_origin, or | |
6713 | DW_AT_extension. DW_AT_extension will refer only to | |
6714 | namespaces; DW_AT_abstract_origin refers to functions (and | |
6715 | many things under the function DIE, but we do not recurse | |
6716 | into function DIEs during partial symbol reading) and | |
6717 | possibly variables as well; DW_AT_specification refers to | |
6718 | declarations. Declarations ought to have the DW_AT_declaration | |
6719 | flag. It happens that GCC forgets to put it in sometimes, but | |
6720 | only for functions, not for types. | |
6721 | ||
6722 | Adding more things than necessary to the hash table is harmless | |
6723 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
6724 | wasted time in find_partial_die, when we reread the compilation |
6725 | unit with load_all_dies set. */ | |
72bf9492 | 6726 | |
5afb4e99 DJ |
6727 | if (load_all |
6728 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
6729 | || abbrev->tag == DW_TAG_variable |
6730 | || abbrev->tag == DW_TAG_namespace | |
6731 | || part_die->is_declaration) | |
6732 | { | |
6733 | void **slot; | |
6734 | ||
6735 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
6736 | part_die->offset, INSERT); | |
6737 | *slot = part_die; | |
6738 | } | |
6739 | ||
6740 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6741 | sizeof (struct partial_die_info)); | |
6742 | ||
6743 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 6744 | we have no reason to follow the children of structures; for other |
72bf9492 | 6745 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
6746 | to infer fully qualified class names, and for DW_AT_specification. |
6747 | ||
6748 | For Ada, we need to scan the children of subprograms and lexical | |
6749 | blocks as well because Ada allows the definition of nested | |
6750 | entities that could be interesting for the debugger, such as | |
6751 | nested subprograms for instance. */ | |
72bf9492 | 6752 | if (last_die->has_children |
5afb4e99 DJ |
6753 | && (load_all |
6754 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
6755 | || last_die->tag == DW_TAG_enumeration_type |
6756 | || (cu->language != language_c | |
6757 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 6758 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 6759 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
6760 | || last_die->tag == DW_TAG_union_type)) |
6761 | || (cu->language == language_ada | |
6762 | && (last_die->tag == DW_TAG_subprogram | |
6763 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
6764 | { |
6765 | nesting_level++; | |
6766 | parent_die = last_die; | |
6767 | continue; | |
6768 | } | |
6769 | ||
6770 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6771 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6772 | |
6773 | /* Back to the top, do it again. */ | |
6774 | } | |
6775 | } | |
6776 | ||
c906108c SS |
6777 | /* Read a minimal amount of information into the minimal die structure. */ |
6778 | ||
fe1b8b76 | 6779 | static gdb_byte * |
72bf9492 DJ |
6780 | read_partial_die (struct partial_die_info *part_die, |
6781 | struct abbrev_info *abbrev, | |
6782 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
6783 | gdb_byte *buffer, gdb_byte *info_ptr, |
6784 | struct dwarf2_cu *cu) | |
c906108c | 6785 | { |
fa238c03 | 6786 | unsigned int i; |
c906108c | 6787 | struct attribute attr; |
c5aa993b | 6788 | int has_low_pc_attr = 0; |
c906108c SS |
6789 | int has_high_pc_attr = 0; |
6790 | ||
72bf9492 | 6791 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 6792 | |
93311388 | 6793 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
6794 | |
6795 | info_ptr += abbrev_len; | |
6796 | ||
6797 | if (abbrev == NULL) | |
6798 | return info_ptr; | |
6799 | ||
c906108c SS |
6800 | part_die->tag = abbrev->tag; |
6801 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
6802 | |
6803 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6804 | { | |
e7c27a73 | 6805 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
6806 | |
6807 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 6808 | partial symbol table. */ |
c906108c SS |
6809 | switch (attr.name) |
6810 | { | |
6811 | case DW_AT_name: | |
71c25dea TT |
6812 | switch (part_die->tag) |
6813 | { | |
6814 | case DW_TAG_compile_unit: | |
348e048f | 6815 | case DW_TAG_type_unit: |
71c25dea TT |
6816 | /* Compilation units have a DW_AT_name that is a filename, not |
6817 | a source language identifier. */ | |
6818 | case DW_TAG_enumeration_type: | |
6819 | case DW_TAG_enumerator: | |
6820 | /* These tags always have simple identifiers already; no need | |
6821 | to canonicalize them. */ | |
6822 | part_die->name = DW_STRING (&attr); | |
6823 | break; | |
6824 | default: | |
6825 | part_die->name | |
6826 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 6827 | &cu->objfile->objfile_obstack); |
71c25dea TT |
6828 | break; |
6829 | } | |
c906108c | 6830 | break; |
31ef98ae | 6831 | case DW_AT_linkage_name: |
c906108c | 6832 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
6833 | /* Note that both forms of linkage name might appear. We |
6834 | assume they will be the same, and we only store the last | |
6835 | one we see. */ | |
94af9270 KS |
6836 | if (cu->language == language_ada) |
6837 | part_die->name = DW_STRING (&attr); | |
c906108c SS |
6838 | break; |
6839 | case DW_AT_low_pc: | |
6840 | has_low_pc_attr = 1; | |
6841 | part_die->lowpc = DW_ADDR (&attr); | |
6842 | break; | |
6843 | case DW_AT_high_pc: | |
6844 | has_high_pc_attr = 1; | |
6845 | part_die->highpc = DW_ADDR (&attr); | |
6846 | break; | |
6847 | case DW_AT_location: | |
8e19ed76 PS |
6848 | /* Support the .debug_loc offsets */ |
6849 | if (attr_form_is_block (&attr)) | |
6850 | { | |
6851 | part_die->locdesc = DW_BLOCK (&attr); | |
6852 | } | |
3690dd37 | 6853 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 6854 | { |
4d3c2250 | 6855 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6856 | } |
6857 | else | |
6858 | { | |
4d3c2250 KB |
6859 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6860 | "partial symbol information"); | |
8e19ed76 | 6861 | } |
c906108c | 6862 | break; |
c906108c SS |
6863 | case DW_AT_external: |
6864 | part_die->is_external = DW_UNSND (&attr); | |
6865 | break; | |
6866 | case DW_AT_declaration: | |
6867 | part_die->is_declaration = DW_UNSND (&attr); | |
6868 | break; | |
6869 | case DW_AT_type: | |
6870 | part_die->has_type = 1; | |
6871 | break; | |
6872 | case DW_AT_abstract_origin: | |
6873 | case DW_AT_specification: | |
72bf9492 DJ |
6874 | case DW_AT_extension: |
6875 | part_die->has_specification = 1; | |
c764a876 | 6876 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
6877 | break; |
6878 | case DW_AT_sibling: | |
6879 | /* Ignore absolute siblings, they might point outside of | |
6880 | the current compile unit. */ | |
6881 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 6882 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 6883 | else |
93311388 | 6884 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 6885 | break; |
fa4028e9 JB |
6886 | case DW_AT_byte_size: |
6887 | part_die->has_byte_size = 1; | |
6888 | break; | |
68511cec CES |
6889 | case DW_AT_calling_convention: |
6890 | /* DWARF doesn't provide a way to identify a program's source-level | |
6891 | entry point. DW_AT_calling_convention attributes are only meant | |
6892 | to describe functions' calling conventions. | |
6893 | ||
6894 | However, because it's a necessary piece of information in | |
6895 | Fortran, and because DW_CC_program is the only piece of debugging | |
6896 | information whose definition refers to a 'main program' at all, | |
6897 | several compilers have begun marking Fortran main programs with | |
6898 | DW_CC_program --- even when those functions use the standard | |
6899 | calling conventions. | |
6900 | ||
6901 | So until DWARF specifies a way to provide this information and | |
6902 | compilers pick up the new representation, we'll support this | |
6903 | practice. */ | |
6904 | if (DW_UNSND (&attr) == DW_CC_program | |
6905 | && cu->language == language_fortran) | |
6906 | set_main_name (part_die->name); | |
6907 | break; | |
c906108c SS |
6908 | default: |
6909 | break; | |
6910 | } | |
6911 | } | |
6912 | ||
c906108c SS |
6913 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
6914 | eliminate duplicate copies of functions and vtables and such. | |
6915 | The linker will arbitrarily choose one and discard the others. | |
6916 | The AT_*_pc values for such functions refer to local labels in | |
6917 | these sections. If the section from that file was discarded, the | |
6918 | labels are not in the output, so the relocs get a value of 0. | |
6919 | If this is a discarded function, mark the pc bounds as invalid, | |
6920 | so that GDB will ignore it. */ | |
6921 | if (has_low_pc_attr && has_high_pc_attr | |
6922 | && part_die->lowpc < part_die->highpc | |
6923 | && (part_die->lowpc != 0 | |
72dca2f5 | 6924 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 6925 | part_die->has_pc_info = 1; |
85cbf3d3 | 6926 | |
c906108c SS |
6927 | return info_ptr; |
6928 | } | |
6929 | ||
72bf9492 DJ |
6930 | /* Find a cached partial DIE at OFFSET in CU. */ |
6931 | ||
6932 | static struct partial_die_info * | |
c764a876 | 6933 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
6934 | { |
6935 | struct partial_die_info *lookup_die = NULL; | |
6936 | struct partial_die_info part_die; | |
6937 | ||
6938 | part_die.offset = offset; | |
6939 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
6940 | ||
72bf9492 DJ |
6941 | return lookup_die; |
6942 | } | |
6943 | ||
348e048f DE |
6944 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
6945 | except in the case of .debug_types DIEs which do not reference | |
6946 | outside their CU (they do however referencing other types via | |
6947 | DW_FORM_sig8). */ | |
72bf9492 DJ |
6948 | |
6949 | static struct partial_die_info * | |
c764a876 | 6950 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 6951 | { |
5afb4e99 DJ |
6952 | struct dwarf2_per_cu_data *per_cu = NULL; |
6953 | struct partial_die_info *pd = NULL; | |
72bf9492 | 6954 | |
348e048f DE |
6955 | if (cu->per_cu->from_debug_types) |
6956 | { | |
6957 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6958 | if (pd != NULL) | |
6959 | return pd; | |
6960 | goto not_found; | |
6961 | } | |
6962 | ||
45452591 | 6963 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
6964 | { |
6965 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6966 | if (pd != NULL) | |
6967 | return pd; | |
6968 | } | |
72bf9492 | 6969 | |
ae038cb0 DJ |
6970 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
6971 | ||
ae038cb0 DJ |
6972 | if (per_cu->cu == NULL) |
6973 | { | |
93311388 | 6974 | load_partial_comp_unit (per_cu, cu->objfile); |
ae038cb0 DJ |
6975 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
6976 | dwarf2_per_objfile->read_in_chain = per_cu; | |
6977 | } | |
6978 | ||
6979 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
6980 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
6981 | ||
6982 | if (pd == NULL && per_cu->load_all_dies == 0) | |
6983 | { | |
6984 | struct cleanup *back_to; | |
6985 | struct partial_die_info comp_unit_die; | |
6986 | struct abbrev_info *abbrev; | |
6987 | unsigned int bytes_read; | |
6988 | char *info_ptr; | |
6989 | ||
6990 | per_cu->load_all_dies = 1; | |
6991 | ||
6992 | /* Re-read the DIEs. */ | |
6993 | back_to = make_cleanup (null_cleanup, 0); | |
6994 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
6995 | { | |
6996 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 6997 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 6998 | } |
dce234bc | 6999 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
7000 | + per_cu->cu->header.offset |
7001 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
7002 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
7003 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
7004 | per_cu->cu->objfile->obfd, |
7005 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
7006 | per_cu->cu); |
7007 | if (comp_unit_die.has_children) | |
93311388 DE |
7008 | load_partial_dies (per_cu->cu->objfile->obfd, |
7009 | dwarf2_per_objfile->info.buffer, info_ptr, | |
7010 | 0, per_cu->cu); | |
5afb4e99 DJ |
7011 | do_cleanups (back_to); |
7012 | ||
7013 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
7014 | } | |
7015 | ||
348e048f DE |
7016 | not_found: |
7017 | ||
5afb4e99 DJ |
7018 | if (pd == NULL) |
7019 | internal_error (__FILE__, __LINE__, | |
c764a876 | 7020 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
7021 | offset, bfd_get_filename (cu->objfile->obfd)); |
7022 | return pd; | |
72bf9492 DJ |
7023 | } |
7024 | ||
7025 | /* Adjust PART_DIE before generating a symbol for it. This function | |
7026 | may set the is_external flag or change the DIE's name. */ | |
7027 | ||
7028 | static void | |
7029 | fixup_partial_die (struct partial_die_info *part_die, | |
7030 | struct dwarf2_cu *cu) | |
7031 | { | |
7032 | /* If we found a reference attribute and the DIE has no name, try | |
7033 | to find a name in the referred to DIE. */ | |
7034 | ||
7035 | if (part_die->name == NULL && part_die->has_specification) | |
7036 | { | |
7037 | struct partial_die_info *spec_die; | |
72bf9492 | 7038 | |
10b3939b | 7039 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 7040 | |
10b3939b | 7041 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
7042 | |
7043 | if (spec_die->name) | |
7044 | { | |
7045 | part_die->name = spec_die->name; | |
7046 | ||
7047 | /* Copy DW_AT_external attribute if it is set. */ | |
7048 | if (spec_die->is_external) | |
7049 | part_die->is_external = spec_die->is_external; | |
7050 | } | |
7051 | } | |
7052 | ||
7053 | /* Set default names for some unnamed DIEs. */ | |
7054 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
7055 | || part_die->tag == DW_TAG_class_type)) | |
7056 | part_die->name = "(anonymous class)"; | |
7057 | ||
7058 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
7059 | part_die->name = "(anonymous namespace)"; | |
7060 | ||
7061 | if (part_die->tag == DW_TAG_structure_type | |
7062 | || part_die->tag == DW_TAG_class_type | |
7063 | || part_die->tag == DW_TAG_union_type) | |
7064 | guess_structure_name (part_die, cu); | |
7065 | } | |
7066 | ||
a8329558 | 7067 | /* Read an attribute value described by an attribute form. */ |
c906108c | 7068 | |
fe1b8b76 | 7069 | static gdb_byte * |
a8329558 | 7070 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 7071 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 7072 | struct dwarf2_cu *cu) |
c906108c | 7073 | { |
e7c27a73 | 7074 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7075 | unsigned int bytes_read; |
7076 | struct dwarf_block *blk; | |
7077 | ||
a8329558 KW |
7078 | attr->form = form; |
7079 | switch (form) | |
c906108c | 7080 | { |
c906108c | 7081 | case DW_FORM_ref_addr: |
ae411497 TT |
7082 | if (cu->header.version == 2) |
7083 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
7084 | else | |
7085 | DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
7086 | info_ptr += bytes_read; | |
7087 | break; | |
7088 | case DW_FORM_addr: | |
e7c27a73 | 7089 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 7090 | info_ptr += bytes_read; |
c906108c SS |
7091 | break; |
7092 | case DW_FORM_block2: | |
7b5a2f43 | 7093 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7094 | blk->size = read_2_bytes (abfd, info_ptr); |
7095 | info_ptr += 2; | |
7096 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7097 | info_ptr += blk->size; | |
7098 | DW_BLOCK (attr) = blk; | |
7099 | break; | |
7100 | case DW_FORM_block4: | |
7b5a2f43 | 7101 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7102 | blk->size = read_4_bytes (abfd, info_ptr); |
7103 | info_ptr += 4; | |
7104 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7105 | info_ptr += blk->size; | |
7106 | DW_BLOCK (attr) = blk; | |
7107 | break; | |
7108 | case DW_FORM_data2: | |
7109 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
7110 | info_ptr += 2; | |
7111 | break; | |
7112 | case DW_FORM_data4: | |
7113 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
7114 | info_ptr += 4; | |
7115 | break; | |
7116 | case DW_FORM_data8: | |
7117 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
7118 | info_ptr += 8; | |
7119 | break; | |
2dc7f7b3 TT |
7120 | case DW_FORM_sec_offset: |
7121 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
7122 | info_ptr += bytes_read; | |
7123 | break; | |
c906108c SS |
7124 | case DW_FORM_string: |
7125 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
8285870a | 7126 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
7127 | info_ptr += bytes_read; |
7128 | break; | |
4bdf3d34 JJ |
7129 | case DW_FORM_strp: |
7130 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
7131 | &bytes_read); | |
8285870a | 7132 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
7133 | info_ptr += bytes_read; |
7134 | break; | |
2dc7f7b3 | 7135 | case DW_FORM_exprloc: |
c906108c | 7136 | case DW_FORM_block: |
7b5a2f43 | 7137 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7138 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7139 | info_ptr += bytes_read; | |
7140 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7141 | info_ptr += blk->size; | |
7142 | DW_BLOCK (attr) = blk; | |
7143 | break; | |
7144 | case DW_FORM_block1: | |
7b5a2f43 | 7145 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7146 | blk->size = read_1_byte (abfd, info_ptr); |
7147 | info_ptr += 1; | |
7148 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7149 | info_ptr += blk->size; | |
7150 | DW_BLOCK (attr) = blk; | |
7151 | break; | |
7152 | case DW_FORM_data1: | |
7153 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7154 | info_ptr += 1; | |
7155 | break; | |
7156 | case DW_FORM_flag: | |
7157 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7158 | info_ptr += 1; | |
7159 | break; | |
2dc7f7b3 TT |
7160 | case DW_FORM_flag_present: |
7161 | DW_UNSND (attr) = 1; | |
7162 | break; | |
c906108c SS |
7163 | case DW_FORM_sdata: |
7164 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
7165 | info_ptr += bytes_read; | |
7166 | break; | |
7167 | case DW_FORM_udata: | |
7168 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7169 | info_ptr += bytes_read; | |
7170 | break; | |
7171 | case DW_FORM_ref1: | |
10b3939b | 7172 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
7173 | info_ptr += 1; |
7174 | break; | |
7175 | case DW_FORM_ref2: | |
10b3939b | 7176 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
7177 | info_ptr += 2; |
7178 | break; | |
7179 | case DW_FORM_ref4: | |
10b3939b | 7180 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
7181 | info_ptr += 4; |
7182 | break; | |
613e1657 | 7183 | case DW_FORM_ref8: |
10b3939b | 7184 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
7185 | info_ptr += 8; |
7186 | break; | |
348e048f DE |
7187 | case DW_FORM_sig8: |
7188 | /* Convert the signature to something we can record in DW_UNSND | |
7189 | for later lookup. | |
7190 | NOTE: This is NULL if the type wasn't found. */ | |
7191 | DW_SIGNATURED_TYPE (attr) = | |
7192 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
7193 | info_ptr += 8; | |
7194 | break; | |
c906108c | 7195 | case DW_FORM_ref_udata: |
10b3939b DJ |
7196 | DW_ADDR (attr) = (cu->header.offset |
7197 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
7198 | info_ptr += bytes_read; |
7199 | break; | |
c906108c | 7200 | case DW_FORM_indirect: |
a8329558 KW |
7201 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7202 | info_ptr += bytes_read; | |
e7c27a73 | 7203 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 7204 | break; |
c906108c | 7205 | default: |
8a3fe4f8 | 7206 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
7207 | dwarf_form_name (form), |
7208 | bfd_get_filename (abfd)); | |
c906108c | 7209 | } |
28e94949 JB |
7210 | |
7211 | /* We have seen instances where the compiler tried to emit a byte | |
7212 | size attribute of -1 which ended up being encoded as an unsigned | |
7213 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
7214 | an object of this size seems pretty unlikely so we can relatively | |
7215 | safely treat these cases as if the size attribute was invalid and | |
7216 | treat them as zero by default. */ | |
7217 | if (attr->name == DW_AT_byte_size | |
7218 | && form == DW_FORM_data4 | |
7219 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
7220 | { |
7221 | complaint | |
7222 | (&symfile_complaints, | |
43bbcdc2 PH |
7223 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
7224 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
7225 | DW_UNSND (attr) = 0; |
7226 | } | |
28e94949 | 7227 | |
c906108c SS |
7228 | return info_ptr; |
7229 | } | |
7230 | ||
a8329558 KW |
7231 | /* Read an attribute described by an abbreviated attribute. */ |
7232 | ||
fe1b8b76 | 7233 | static gdb_byte * |
a8329558 | 7234 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 7235 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
7236 | { |
7237 | attr->name = abbrev->name; | |
e7c27a73 | 7238 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
7239 | } |
7240 | ||
c906108c SS |
7241 | /* read dwarf information from a buffer */ |
7242 | ||
7243 | static unsigned int | |
fe1b8b76 | 7244 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7245 | { |
fe1b8b76 | 7246 | return bfd_get_8 (abfd, buf); |
c906108c SS |
7247 | } |
7248 | ||
7249 | static int | |
fe1b8b76 | 7250 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7251 | { |
fe1b8b76 | 7252 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
7253 | } |
7254 | ||
7255 | static unsigned int | |
fe1b8b76 | 7256 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7257 | { |
fe1b8b76 | 7258 | return bfd_get_16 (abfd, buf); |
c906108c SS |
7259 | } |
7260 | ||
7261 | static int | |
fe1b8b76 | 7262 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7263 | { |
fe1b8b76 | 7264 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
7265 | } |
7266 | ||
7267 | static unsigned int | |
fe1b8b76 | 7268 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7269 | { |
fe1b8b76 | 7270 | return bfd_get_32 (abfd, buf); |
c906108c SS |
7271 | } |
7272 | ||
7273 | static int | |
fe1b8b76 | 7274 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7275 | { |
fe1b8b76 | 7276 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
7277 | } |
7278 | ||
93311388 | 7279 | static ULONGEST |
fe1b8b76 | 7280 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7281 | { |
fe1b8b76 | 7282 | return bfd_get_64 (abfd, buf); |
c906108c SS |
7283 | } |
7284 | ||
7285 | static CORE_ADDR | |
fe1b8b76 | 7286 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 7287 | unsigned int *bytes_read) |
c906108c | 7288 | { |
e7c27a73 | 7289 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7290 | CORE_ADDR retval = 0; |
7291 | ||
107d2387 | 7292 | if (cu_header->signed_addr_p) |
c906108c | 7293 | { |
107d2387 AC |
7294 | switch (cu_header->addr_size) |
7295 | { | |
7296 | case 2: | |
fe1b8b76 | 7297 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
7298 | break; |
7299 | case 4: | |
fe1b8b76 | 7300 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
7301 | break; |
7302 | case 8: | |
fe1b8b76 | 7303 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
7304 | break; |
7305 | default: | |
8e65ff28 | 7306 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7307 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 7308 | bfd_get_filename (abfd)); |
107d2387 AC |
7309 | } |
7310 | } | |
7311 | else | |
7312 | { | |
7313 | switch (cu_header->addr_size) | |
7314 | { | |
7315 | case 2: | |
fe1b8b76 | 7316 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
7317 | break; |
7318 | case 4: | |
fe1b8b76 | 7319 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
7320 | break; |
7321 | case 8: | |
fe1b8b76 | 7322 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
7323 | break; |
7324 | default: | |
8e65ff28 | 7325 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7326 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 7327 | bfd_get_filename (abfd)); |
107d2387 | 7328 | } |
c906108c | 7329 | } |
64367e0a | 7330 | |
107d2387 AC |
7331 | *bytes_read = cu_header->addr_size; |
7332 | return retval; | |
c906108c SS |
7333 | } |
7334 | ||
f7ef9339 | 7335 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
7336 | specification allows the initial length to take up either 4 bytes |
7337 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
7338 | bytes describe the length and all offsets will be 8 bytes in length | |
7339 | instead of 4. | |
7340 | ||
f7ef9339 KB |
7341 | An older, non-standard 64-bit format is also handled by this |
7342 | function. The older format in question stores the initial length | |
7343 | as an 8-byte quantity without an escape value. Lengths greater | |
7344 | than 2^32 aren't very common which means that the initial 4 bytes | |
7345 | is almost always zero. Since a length value of zero doesn't make | |
7346 | sense for the 32-bit format, this initial zero can be considered to | |
7347 | be an escape value which indicates the presence of the older 64-bit | |
7348 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
7349 | greater than 4GB. If it becomes necessary to handle lengths |
7350 | somewhat larger than 4GB, we could allow other small values (such | |
7351 | as the non-sensical values of 1, 2, and 3) to also be used as | |
7352 | escape values indicating the presence of the old format. | |
f7ef9339 | 7353 | |
917c78fc MK |
7354 | The value returned via bytes_read should be used to increment the |
7355 | relevant pointer after calling read_initial_length(). | |
c764a876 | 7356 | |
613e1657 KB |
7357 | [ Note: read_initial_length() and read_offset() are based on the |
7358 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 7359 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
7360 | from: |
7361 | ||
f7ef9339 | 7362 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
7363 | |
7364 | This document is only a draft and is subject to change. (So beware.) | |
7365 | ||
f7ef9339 | 7366 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
7367 | determined empirically by examining 64-bit ELF files produced by |
7368 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
7369 | |
7370 | - Kevin, July 16, 2002 | |
613e1657 KB |
7371 | ] */ |
7372 | ||
7373 | static LONGEST | |
c764a876 | 7374 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 7375 | { |
fe1b8b76 | 7376 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 7377 | |
dd373385 | 7378 | if (length == 0xffffffff) |
613e1657 | 7379 | { |
fe1b8b76 | 7380 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 7381 | *bytes_read = 12; |
613e1657 | 7382 | } |
dd373385 | 7383 | else if (length == 0) |
f7ef9339 | 7384 | { |
dd373385 | 7385 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 7386 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 7387 | *bytes_read = 8; |
f7ef9339 | 7388 | } |
613e1657 KB |
7389 | else |
7390 | { | |
7391 | *bytes_read = 4; | |
613e1657 KB |
7392 | } |
7393 | ||
c764a876 DE |
7394 | return length; |
7395 | } | |
dd373385 | 7396 | |
c764a876 DE |
7397 | /* Cover function for read_initial_length. |
7398 | Returns the length of the object at BUF, and stores the size of the | |
7399 | initial length in *BYTES_READ and stores the size that offsets will be in | |
7400 | *OFFSET_SIZE. | |
7401 | If the initial length size is not equivalent to that specified in | |
7402 | CU_HEADER then issue a complaint. | |
7403 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 7404 | |
c764a876 DE |
7405 | static LONGEST |
7406 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
7407 | const struct comp_unit_head *cu_header, | |
7408 | unsigned int *bytes_read, | |
7409 | unsigned int *offset_size) | |
7410 | { | |
7411 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
7412 | ||
7413 | gdb_assert (cu_header->initial_length_size == 4 | |
7414 | || cu_header->initial_length_size == 8 | |
7415 | || cu_header->initial_length_size == 12); | |
7416 | ||
7417 | if (cu_header->initial_length_size != *bytes_read) | |
7418 | complaint (&symfile_complaints, | |
7419 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 7420 | |
c764a876 | 7421 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 7422 | return length; |
613e1657 KB |
7423 | } |
7424 | ||
7425 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 7426 | given by cu_header->offset_size. */ |
613e1657 KB |
7427 | |
7428 | static LONGEST | |
fe1b8b76 | 7429 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 7430 | unsigned int *bytes_read) |
c764a876 DE |
7431 | { |
7432 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
7433 | *bytes_read = cu_header->offset_size; | |
7434 | return offset; | |
7435 | } | |
7436 | ||
7437 | /* Read an offset from the data stream. */ | |
7438 | ||
7439 | static LONGEST | |
7440 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
7441 | { |
7442 | LONGEST retval = 0; | |
7443 | ||
c764a876 | 7444 | switch (offset_size) |
613e1657 KB |
7445 | { |
7446 | case 4: | |
fe1b8b76 | 7447 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
7448 | break; |
7449 | case 8: | |
fe1b8b76 | 7450 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
7451 | break; |
7452 | default: | |
8e65ff28 | 7453 | internal_error (__FILE__, __LINE__, |
c764a876 | 7454 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 7455 | bfd_get_filename (abfd)); |
613e1657 KB |
7456 | } |
7457 | ||
917c78fc | 7458 | return retval; |
613e1657 KB |
7459 | } |
7460 | ||
fe1b8b76 JB |
7461 | static gdb_byte * |
7462 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
7463 | { |
7464 | /* If the size of a host char is 8 bits, we can return a pointer | |
7465 | to the buffer, otherwise we have to copy the data to a buffer | |
7466 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7467 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 7468 | return buf; |
c906108c SS |
7469 | } |
7470 | ||
7471 | static char * | |
fe1b8b76 | 7472 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
7473 | { |
7474 | /* If the size of a host char is 8 bits, we can return a pointer | |
7475 | to the string, otherwise we have to copy the string to a buffer | |
7476 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7477 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
7478 | if (*buf == '\0') |
7479 | { | |
7480 | *bytes_read_ptr = 1; | |
7481 | return NULL; | |
7482 | } | |
fe1b8b76 JB |
7483 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
7484 | return (char *) buf; | |
4bdf3d34 JJ |
7485 | } |
7486 | ||
7487 | static char * | |
fe1b8b76 | 7488 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
7489 | const struct comp_unit_head *cu_header, |
7490 | unsigned int *bytes_read_ptr) | |
7491 | { | |
c764a876 | 7492 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 7493 | |
be391dca | 7494 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 7495 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 7496 | { |
8a3fe4f8 | 7497 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 7498 | bfd_get_filename (abfd)); |
4bdf3d34 | 7499 | return NULL; |
c906108c | 7500 | } |
dce234bc | 7501 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 7502 | { |
8a3fe4f8 | 7503 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 7504 | bfd_get_filename (abfd)); |
c906108c SS |
7505 | return NULL; |
7506 | } | |
4bdf3d34 | 7507 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 7508 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 7509 | return NULL; |
dce234bc | 7510 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
7511 | } |
7512 | ||
ce5d95e1 | 7513 | static unsigned long |
fe1b8b76 | 7514 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7515 | { |
ce5d95e1 JB |
7516 | unsigned long result; |
7517 | unsigned int num_read; | |
c906108c SS |
7518 | int i, shift; |
7519 | unsigned char byte; | |
7520 | ||
7521 | result = 0; | |
7522 | shift = 0; | |
7523 | num_read = 0; | |
7524 | i = 0; | |
7525 | while (1) | |
7526 | { | |
fe1b8b76 | 7527 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7528 | buf++; |
7529 | num_read++; | |
ce5d95e1 | 7530 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
7531 | if ((byte & 128) == 0) |
7532 | { | |
7533 | break; | |
7534 | } | |
7535 | shift += 7; | |
7536 | } | |
7537 | *bytes_read_ptr = num_read; | |
7538 | return result; | |
7539 | } | |
7540 | ||
ce5d95e1 | 7541 | static long |
fe1b8b76 | 7542 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7543 | { |
ce5d95e1 | 7544 | long result; |
77e0b926 | 7545 | int i, shift, num_read; |
c906108c SS |
7546 | unsigned char byte; |
7547 | ||
7548 | result = 0; | |
7549 | shift = 0; | |
c906108c SS |
7550 | num_read = 0; |
7551 | i = 0; | |
7552 | while (1) | |
7553 | { | |
fe1b8b76 | 7554 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7555 | buf++; |
7556 | num_read++; | |
ce5d95e1 | 7557 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
7558 | shift += 7; |
7559 | if ((byte & 128) == 0) | |
7560 | { | |
7561 | break; | |
7562 | } | |
7563 | } | |
77e0b926 DJ |
7564 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
7565 | result |= -(((long)1) << shift); | |
c906108c SS |
7566 | *bytes_read_ptr = num_read; |
7567 | return result; | |
7568 | } | |
7569 | ||
4bb7a0a7 DJ |
7570 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
7571 | ||
fe1b8b76 JB |
7572 | static gdb_byte * |
7573 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
7574 | { |
7575 | int byte; | |
7576 | ||
7577 | while (1) | |
7578 | { | |
fe1b8b76 | 7579 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
7580 | buf++; |
7581 | if ((byte & 128) == 0) | |
7582 | return buf; | |
7583 | } | |
7584 | } | |
7585 | ||
c906108c | 7586 | static void |
e142c38c | 7587 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
7588 | { |
7589 | switch (lang) | |
7590 | { | |
7591 | case DW_LANG_C89: | |
76bee0cc | 7592 | case DW_LANG_C99: |
c906108c | 7593 | case DW_LANG_C: |
e142c38c | 7594 | cu->language = language_c; |
c906108c SS |
7595 | break; |
7596 | case DW_LANG_C_plus_plus: | |
e142c38c | 7597 | cu->language = language_cplus; |
c906108c | 7598 | break; |
6aecb9c2 JB |
7599 | case DW_LANG_D: |
7600 | cu->language = language_d; | |
7601 | break; | |
c906108c SS |
7602 | case DW_LANG_Fortran77: |
7603 | case DW_LANG_Fortran90: | |
b21b22e0 | 7604 | case DW_LANG_Fortran95: |
e142c38c | 7605 | cu->language = language_fortran; |
c906108c SS |
7606 | break; |
7607 | case DW_LANG_Mips_Assembler: | |
e142c38c | 7608 | cu->language = language_asm; |
c906108c | 7609 | break; |
bebd888e | 7610 | case DW_LANG_Java: |
e142c38c | 7611 | cu->language = language_java; |
bebd888e | 7612 | break; |
c906108c | 7613 | case DW_LANG_Ada83: |
8aaf0b47 | 7614 | case DW_LANG_Ada95: |
bc5f45f8 JB |
7615 | cu->language = language_ada; |
7616 | break; | |
72019c9c GM |
7617 | case DW_LANG_Modula2: |
7618 | cu->language = language_m2; | |
7619 | break; | |
fe8e67fd PM |
7620 | case DW_LANG_Pascal83: |
7621 | cu->language = language_pascal; | |
7622 | break; | |
22566fbd DJ |
7623 | case DW_LANG_ObjC: |
7624 | cu->language = language_objc; | |
7625 | break; | |
c906108c SS |
7626 | case DW_LANG_Cobol74: |
7627 | case DW_LANG_Cobol85: | |
c906108c | 7628 | default: |
e142c38c | 7629 | cu->language = language_minimal; |
c906108c SS |
7630 | break; |
7631 | } | |
e142c38c | 7632 | cu->language_defn = language_def (cu->language); |
c906108c SS |
7633 | } |
7634 | ||
7635 | /* Return the named attribute or NULL if not there. */ | |
7636 | ||
7637 | static struct attribute * | |
e142c38c | 7638 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
7639 | { |
7640 | unsigned int i; | |
7641 | struct attribute *spec = NULL; | |
7642 | ||
7643 | for (i = 0; i < die->num_attrs; ++i) | |
7644 | { | |
7645 | if (die->attrs[i].name == name) | |
10b3939b | 7646 | return &die->attrs[i]; |
c906108c SS |
7647 | if (die->attrs[i].name == DW_AT_specification |
7648 | || die->attrs[i].name == DW_AT_abstract_origin) | |
7649 | spec = &die->attrs[i]; | |
7650 | } | |
c906108c | 7651 | |
10b3939b | 7652 | if (spec) |
f2f0e013 DJ |
7653 | { |
7654 | die = follow_die_ref (die, spec, &cu); | |
7655 | return dwarf2_attr (die, name, cu); | |
7656 | } | |
c5aa993b | 7657 | |
c906108c SS |
7658 | return NULL; |
7659 | } | |
7660 | ||
348e048f DE |
7661 | /* Return the named attribute or NULL if not there, |
7662 | but do not follow DW_AT_specification, etc. | |
7663 | This is for use in contexts where we're reading .debug_types dies. | |
7664 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
7665 | back up the chain, and we want to go down. */ | |
7666 | ||
7667 | static struct attribute * | |
7668 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
7669 | struct dwarf2_cu *cu) | |
7670 | { | |
7671 | unsigned int i; | |
7672 | ||
7673 | for (i = 0; i < die->num_attrs; ++i) | |
7674 | if (die->attrs[i].name == name) | |
7675 | return &die->attrs[i]; | |
7676 | ||
7677 | return NULL; | |
7678 | } | |
7679 | ||
05cf31d1 JB |
7680 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
7681 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 7682 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
7683 | |
7684 | static int | |
7685 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
7686 | { | |
7687 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
7688 | ||
7689 | return (attr && DW_UNSND (attr)); | |
7690 | } | |
7691 | ||
3ca72b44 | 7692 | static int |
e142c38c | 7693 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 7694 | { |
05cf31d1 JB |
7695 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
7696 | which value is non-zero. However, we have to be careful with | |
7697 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
7698 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
7699 | end up accidently finding a declaration attribute that belongs | |
7700 | to a different DIE referenced by the specification attribute, | |
7701 | even though the given DIE does not have a declaration attribute. */ | |
7702 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
7703 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
7704 | } |
7705 | ||
63d06c5c | 7706 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 7707 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
7708 | containing the return value on output. If there is no |
7709 | specification, but there is an abstract origin, that is | |
7710 | returned. */ | |
63d06c5c DC |
7711 | |
7712 | static struct die_info * | |
f2f0e013 | 7713 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 7714 | { |
f2f0e013 DJ |
7715 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
7716 | *spec_cu); | |
63d06c5c | 7717 | |
edb3359d DJ |
7718 | if (spec_attr == NULL) |
7719 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
7720 | ||
63d06c5c DC |
7721 | if (spec_attr == NULL) |
7722 | return NULL; | |
7723 | else | |
f2f0e013 | 7724 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 7725 | } |
c906108c | 7726 | |
debd256d JB |
7727 | /* Free the line_header structure *LH, and any arrays and strings it |
7728 | refers to. */ | |
7729 | static void | |
7730 | free_line_header (struct line_header *lh) | |
7731 | { | |
7732 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 7733 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
7734 | |
7735 | /* Remember that all the lh->file_names[i].name pointers are | |
7736 | pointers into debug_line_buffer, and don't need to be freed. */ | |
7737 | if (lh->file_names) | |
a8bc7b56 | 7738 | xfree (lh->file_names); |
debd256d JB |
7739 | |
7740 | /* Similarly for the include directory names. */ | |
7741 | if (lh->include_dirs) | |
a8bc7b56 | 7742 | xfree (lh->include_dirs); |
debd256d | 7743 | |
a8bc7b56 | 7744 | xfree (lh); |
debd256d JB |
7745 | } |
7746 | ||
7747 | ||
7748 | /* Add an entry to LH's include directory table. */ | |
7749 | static void | |
7750 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 7751 | { |
debd256d JB |
7752 | /* Grow the array if necessary. */ |
7753 | if (lh->include_dirs_size == 0) | |
c5aa993b | 7754 | { |
debd256d JB |
7755 | lh->include_dirs_size = 1; /* for testing */ |
7756 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
7757 | * sizeof (*lh->include_dirs)); | |
7758 | } | |
7759 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
7760 | { | |
7761 | lh->include_dirs_size *= 2; | |
7762 | lh->include_dirs = xrealloc (lh->include_dirs, | |
7763 | (lh->include_dirs_size | |
7764 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 7765 | } |
c906108c | 7766 | |
debd256d JB |
7767 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
7768 | } | |
7769 | ||
7770 | ||
7771 | /* Add an entry to LH's file name table. */ | |
7772 | static void | |
7773 | add_file_name (struct line_header *lh, | |
7774 | char *name, | |
7775 | unsigned int dir_index, | |
7776 | unsigned int mod_time, | |
7777 | unsigned int length) | |
7778 | { | |
7779 | struct file_entry *fe; | |
7780 | ||
7781 | /* Grow the array if necessary. */ | |
7782 | if (lh->file_names_size == 0) | |
7783 | { | |
7784 | lh->file_names_size = 1; /* for testing */ | |
7785 | lh->file_names = xmalloc (lh->file_names_size | |
7786 | * sizeof (*lh->file_names)); | |
7787 | } | |
7788 | else if (lh->num_file_names >= lh->file_names_size) | |
7789 | { | |
7790 | lh->file_names_size *= 2; | |
7791 | lh->file_names = xrealloc (lh->file_names, | |
7792 | (lh->file_names_size | |
7793 | * sizeof (*lh->file_names))); | |
7794 | } | |
7795 | ||
7796 | fe = &lh->file_names[lh->num_file_names++]; | |
7797 | fe->name = name; | |
7798 | fe->dir_index = dir_index; | |
7799 | fe->mod_time = mod_time; | |
7800 | fe->length = length; | |
aaa75496 | 7801 | fe->included_p = 0; |
cb1df416 | 7802 | fe->symtab = NULL; |
debd256d JB |
7803 | } |
7804 | ||
7805 | ||
7806 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
7807 | .debug_line, according to the endianness of ABFD. Return a pointer |
7808 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
7809 | |
7810 | NOTE: the strings in the include directory and file name tables of | |
7811 | the returned object point into debug_line_buffer, and must not be | |
7812 | freed. */ | |
7813 | static struct line_header * | |
7814 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 7815 | struct dwarf2_cu *cu) |
debd256d JB |
7816 | { |
7817 | struct cleanup *back_to; | |
7818 | struct line_header *lh; | |
fe1b8b76 | 7819 | gdb_byte *line_ptr; |
c764a876 | 7820 | unsigned int bytes_read, offset_size; |
debd256d JB |
7821 | int i; |
7822 | char *cur_dir, *cur_file; | |
7823 | ||
be391dca | 7824 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 7825 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 7826 | { |
e2e0b3e5 | 7827 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
7828 | return 0; |
7829 | } | |
7830 | ||
a738430d MK |
7831 | /* Make sure that at least there's room for the total_length field. |
7832 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 7833 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 7834 | { |
4d3c2250 | 7835 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7836 | return 0; |
7837 | } | |
7838 | ||
7839 | lh = xmalloc (sizeof (*lh)); | |
7840 | memset (lh, 0, sizeof (*lh)); | |
7841 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
7842 | (void *) lh); | |
7843 | ||
dce234bc | 7844 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 7845 | |
a738430d | 7846 | /* Read in the header. */ |
dd373385 | 7847 | lh->total_length = |
c764a876 DE |
7848 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
7849 | &bytes_read, &offset_size); | |
debd256d | 7850 | line_ptr += bytes_read; |
dce234bc PP |
7851 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
7852 | + dwarf2_per_objfile->line.size)) | |
debd256d | 7853 | { |
4d3c2250 | 7854 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7855 | return 0; |
7856 | } | |
7857 | lh->statement_program_end = line_ptr + lh->total_length; | |
7858 | lh->version = read_2_bytes (abfd, line_ptr); | |
7859 | line_ptr += 2; | |
c764a876 DE |
7860 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
7861 | line_ptr += offset_size; | |
debd256d JB |
7862 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
7863 | line_ptr += 1; | |
2dc7f7b3 TT |
7864 | if (lh->version >= 4) |
7865 | { | |
7866 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
7867 | line_ptr += 1; | |
7868 | } | |
7869 | else | |
7870 | lh->maximum_ops_per_instruction = 1; | |
7871 | ||
7872 | if (lh->maximum_ops_per_instruction == 0) | |
7873 | { | |
7874 | lh->maximum_ops_per_instruction = 1; | |
7875 | complaint (&symfile_complaints, | |
7876 | _("invalid maximum_ops_per_instruction in `.debug_line' section")); | |
7877 | } | |
7878 | ||
debd256d JB |
7879 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
7880 | line_ptr += 1; | |
7881 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
7882 | line_ptr += 1; | |
7883 | lh->line_range = read_1_byte (abfd, line_ptr); | |
7884 | line_ptr += 1; | |
7885 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
7886 | line_ptr += 1; | |
7887 | lh->standard_opcode_lengths | |
fe1b8b76 | 7888 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
7889 | |
7890 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
7891 | for (i = 1; i < lh->opcode_base; ++i) | |
7892 | { | |
7893 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
7894 | line_ptr += 1; | |
7895 | } | |
7896 | ||
a738430d | 7897 | /* Read directory table. */ |
debd256d JB |
7898 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7899 | { | |
7900 | line_ptr += bytes_read; | |
7901 | add_include_dir (lh, cur_dir); | |
7902 | } | |
7903 | line_ptr += bytes_read; | |
7904 | ||
a738430d | 7905 | /* Read file name table. */ |
debd256d JB |
7906 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7907 | { | |
7908 | unsigned int dir_index, mod_time, length; | |
7909 | ||
7910 | line_ptr += bytes_read; | |
7911 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7912 | line_ptr += bytes_read; | |
7913 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7914 | line_ptr += bytes_read; | |
7915 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7916 | line_ptr += bytes_read; | |
7917 | ||
7918 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7919 | } | |
7920 | line_ptr += bytes_read; | |
7921 | lh->statement_program_start = line_ptr; | |
7922 | ||
dce234bc PP |
7923 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
7924 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 7925 | complaint (&symfile_complaints, |
e2e0b3e5 | 7926 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
7927 | |
7928 | discard_cleanups (back_to); | |
7929 | return lh; | |
7930 | } | |
c906108c | 7931 | |
5fb290d7 DJ |
7932 | /* This function exists to work around a bug in certain compilers |
7933 | (particularly GCC 2.95), in which the first line number marker of a | |
7934 | function does not show up until after the prologue, right before | |
7935 | the second line number marker. This function shifts ADDRESS down | |
7936 | to the beginning of the function if necessary, and is called on | |
7937 | addresses passed to record_line. */ | |
7938 | ||
7939 | static CORE_ADDR | |
e142c38c | 7940 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
7941 | { |
7942 | struct function_range *fn; | |
7943 | ||
7944 | /* Find the function_range containing address. */ | |
e142c38c | 7945 | if (!cu->first_fn) |
5fb290d7 DJ |
7946 | return address; |
7947 | ||
e142c38c DJ |
7948 | if (!cu->cached_fn) |
7949 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 7950 | |
e142c38c | 7951 | fn = cu->cached_fn; |
5fb290d7 DJ |
7952 | while (fn) |
7953 | if (fn->lowpc <= address && fn->highpc > address) | |
7954 | goto found; | |
7955 | else | |
7956 | fn = fn->next; | |
7957 | ||
e142c38c DJ |
7958 | fn = cu->first_fn; |
7959 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
7960 | if (fn->lowpc <= address && fn->highpc > address) |
7961 | goto found; | |
7962 | else | |
7963 | fn = fn->next; | |
7964 | ||
7965 | return address; | |
7966 | ||
7967 | found: | |
7968 | if (fn->seen_line) | |
7969 | return address; | |
7970 | if (address != fn->lowpc) | |
4d3c2250 | 7971 | complaint (&symfile_complaints, |
e2e0b3e5 | 7972 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 7973 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
7974 | fn->seen_line = 1; |
7975 | return fn->lowpc; | |
7976 | } | |
7977 | ||
aaa75496 JB |
7978 | /* Decode the Line Number Program (LNP) for the given line_header |
7979 | structure and CU. The actual information extracted and the type | |
7980 | of structures created from the LNP depends on the value of PST. | |
7981 | ||
7982 | 1. If PST is NULL, then this procedure uses the data from the program | |
7983 | to create all necessary symbol tables, and their linetables. | |
7984 | The compilation directory of the file is passed in COMP_DIR, | |
7985 | and must not be NULL. | |
7986 | ||
7987 | 2. If PST is not NULL, this procedure reads the program to determine | |
7988 | the list of files included by the unit represented by PST, and | |
7989 | builds all the associated partial symbol tables. In this case, | |
7990 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
7991 | is not used to compute the full name of the symtab, and therefore | |
7992 | omitting it when building the partial symtab does not introduce | |
7993 | the potential for inconsistency - a partial symtab and its associated | |
7994 | symbtab having a different fullname -). */ | |
debd256d | 7995 | |
c906108c | 7996 | static void |
debd256d | 7997 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 7998 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 7999 | { |
a8c50c1f | 8000 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 8001 | gdb_byte *line_end; |
a8c50c1f | 8002 | unsigned int bytes_read, extended_len; |
c906108c | 8003 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
8004 | CORE_ADDR baseaddr; |
8005 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 8006 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 8007 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 8008 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
8009 | |
8010 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 8011 | |
debd256d JB |
8012 | line_ptr = lh->statement_program_start; |
8013 | line_end = lh->statement_program_end; | |
c906108c SS |
8014 | |
8015 | /* Read the statement sequences until there's nothing left. */ | |
8016 | while (line_ptr < line_end) | |
8017 | { | |
8018 | /* state machine registers */ | |
8019 | CORE_ADDR address = 0; | |
8020 | unsigned int file = 1; | |
8021 | unsigned int line = 1; | |
8022 | unsigned int column = 0; | |
debd256d | 8023 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
8024 | int basic_block = 0; |
8025 | int end_sequence = 0; | |
fbf65064 | 8026 | CORE_ADDR addr; |
2dc7f7b3 | 8027 | unsigned char op_index = 0; |
c906108c | 8028 | |
aaa75496 | 8029 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 8030 | { |
aaa75496 | 8031 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
8032 | /* lh->include_dirs and lh->file_names are 0-based, but the |
8033 | directory and file name numbers in the statement program | |
8034 | are 1-based. */ | |
8035 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 8036 | char *dir = NULL; |
a738430d | 8037 | |
debd256d JB |
8038 | if (fe->dir_index) |
8039 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
8040 | |
8041 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
8042 | } |
8043 | ||
a738430d | 8044 | /* Decode the table. */ |
c5aa993b | 8045 | while (!end_sequence) |
c906108c SS |
8046 | { |
8047 | op_code = read_1_byte (abfd, line_ptr); | |
8048 | line_ptr += 1; | |
59205f5a JB |
8049 | if (line_ptr > line_end) |
8050 | { | |
8051 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
8052 | break; | |
8053 | } | |
9aa1fe7e | 8054 | |
debd256d | 8055 | if (op_code >= lh->opcode_base) |
a738430d MK |
8056 | { |
8057 | /* Special operand. */ | |
debd256d | 8058 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
8059 | address += (((op_index + (adj_opcode / lh->line_range)) |
8060 | / lh->maximum_ops_per_instruction) | |
8061 | * lh->minimum_instruction_length); | |
8062 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
8063 | % lh->maximum_ops_per_instruction); | |
debd256d | 8064 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 8065 | if (lh->num_file_names < file || file == 0) |
25e43795 | 8066 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
8067 | /* For now we ignore lines not starting on an |
8068 | instruction boundary. */ | |
8069 | else if (op_index == 0) | |
25e43795 DJ |
8070 | { |
8071 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 8072 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
8073 | { |
8074 | if (last_subfile != current_subfile) | |
8075 | { | |
8076 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8077 | if (last_subfile) | |
8078 | record_line (last_subfile, 0, addr); | |
8079 | last_subfile = current_subfile; | |
8080 | } | |
25e43795 | 8081 | /* Append row to matrix using current values. */ |
fbf65064 UW |
8082 | addr = check_cu_functions (address, cu); |
8083 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
8084 | record_line (current_subfile, line, addr); | |
366da635 | 8085 | } |
25e43795 | 8086 | } |
ca5f395d | 8087 | basic_block = 0; |
9aa1fe7e GK |
8088 | } |
8089 | else switch (op_code) | |
c906108c SS |
8090 | { |
8091 | case DW_LNS_extended_op: | |
a8c50c1f | 8092 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 8093 | line_ptr += bytes_read; |
a8c50c1f | 8094 | extended_end = line_ptr + extended_len; |
c906108c SS |
8095 | extended_op = read_1_byte (abfd, line_ptr); |
8096 | line_ptr += 1; | |
8097 | switch (extended_op) | |
8098 | { | |
8099 | case DW_LNE_end_sequence: | |
8100 | end_sequence = 1; | |
c906108c SS |
8101 | break; |
8102 | case DW_LNE_set_address: | |
e7c27a73 | 8103 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
2dc7f7b3 | 8104 | op_index = 0; |
107d2387 AC |
8105 | line_ptr += bytes_read; |
8106 | address += baseaddr; | |
c906108c SS |
8107 | break; |
8108 | case DW_LNE_define_file: | |
debd256d JB |
8109 | { |
8110 | char *cur_file; | |
8111 | unsigned int dir_index, mod_time, length; | |
8112 | ||
8113 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
8114 | line_ptr += bytes_read; | |
8115 | dir_index = | |
8116 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8117 | line_ptr += bytes_read; | |
8118 | mod_time = | |
8119 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8120 | line_ptr += bytes_read; | |
8121 | length = | |
8122 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8123 | line_ptr += bytes_read; | |
8124 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
8125 | } | |
c906108c | 8126 | break; |
d0c6ba3d CC |
8127 | case DW_LNE_set_discriminator: |
8128 | /* The discriminator is not interesting to the debugger; | |
8129 | just ignore it. */ | |
8130 | line_ptr = extended_end; | |
8131 | break; | |
c906108c | 8132 | default: |
4d3c2250 | 8133 | complaint (&symfile_complaints, |
e2e0b3e5 | 8134 | _("mangled .debug_line section")); |
debd256d | 8135 | return; |
c906108c | 8136 | } |
a8c50c1f DJ |
8137 | /* Make sure that we parsed the extended op correctly. If e.g. |
8138 | we expected a different address size than the producer used, | |
8139 | we may have read the wrong number of bytes. */ | |
8140 | if (line_ptr != extended_end) | |
8141 | { | |
8142 | complaint (&symfile_complaints, | |
8143 | _("mangled .debug_line section")); | |
8144 | return; | |
8145 | } | |
c906108c SS |
8146 | break; |
8147 | case DW_LNS_copy: | |
59205f5a | 8148 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8149 | dwarf2_debug_line_missing_file_complaint (); |
8150 | else | |
366da635 | 8151 | { |
25e43795 | 8152 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 8153 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
8154 | { |
8155 | if (last_subfile != current_subfile) | |
8156 | { | |
8157 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8158 | if (last_subfile) | |
8159 | record_line (last_subfile, 0, addr); | |
8160 | last_subfile = current_subfile; | |
8161 | } | |
8162 | addr = check_cu_functions (address, cu); | |
8163 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
8164 | record_line (current_subfile, line, addr); | |
8165 | } | |
366da635 | 8166 | } |
c906108c SS |
8167 | basic_block = 0; |
8168 | break; | |
8169 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
8170 | { |
8171 | CORE_ADDR adjust | |
8172 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8173 | ||
8174 | address += (((op_index + adjust) | |
8175 | / lh->maximum_ops_per_instruction) | |
8176 | * lh->minimum_instruction_length); | |
8177 | op_index = ((op_index + adjust) | |
8178 | % lh->maximum_ops_per_instruction); | |
8179 | line_ptr += bytes_read; | |
8180 | } | |
c906108c SS |
8181 | break; |
8182 | case DW_LNS_advance_line: | |
8183 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
8184 | line_ptr += bytes_read; | |
8185 | break; | |
8186 | case DW_LNS_set_file: | |
debd256d | 8187 | { |
a738430d MK |
8188 | /* The arrays lh->include_dirs and lh->file_names are |
8189 | 0-based, but the directory and file name numbers in | |
8190 | the statement program are 1-based. */ | |
debd256d | 8191 | struct file_entry *fe; |
4f1520fb | 8192 | char *dir = NULL; |
a738430d | 8193 | |
debd256d JB |
8194 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8195 | line_ptr += bytes_read; | |
59205f5a | 8196 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8197 | dwarf2_debug_line_missing_file_complaint (); |
8198 | else | |
8199 | { | |
8200 | fe = &lh->file_names[file - 1]; | |
8201 | if (fe->dir_index) | |
8202 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8203 | if (!decode_for_pst_p) | |
8204 | { | |
8205 | last_subfile = current_subfile; | |
8206 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8207 | } | |
8208 | } | |
debd256d | 8209 | } |
c906108c SS |
8210 | break; |
8211 | case DW_LNS_set_column: | |
8212 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8213 | line_ptr += bytes_read; | |
8214 | break; | |
8215 | case DW_LNS_negate_stmt: | |
8216 | is_stmt = (!is_stmt); | |
8217 | break; | |
8218 | case DW_LNS_set_basic_block: | |
8219 | basic_block = 1; | |
8220 | break; | |
c2c6d25f JM |
8221 | /* Add to the address register of the state machine the |
8222 | address increment value corresponding to special opcode | |
a738430d MK |
8223 | 255. I.e., this value is scaled by the minimum |
8224 | instruction length since special opcode 255 would have | |
8225 | scaled the the increment. */ | |
c906108c | 8226 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
8227 | { |
8228 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
8229 | ||
8230 | address += (((op_index + adjust) | |
8231 | / lh->maximum_ops_per_instruction) | |
8232 | * lh->minimum_instruction_length); | |
8233 | op_index = ((op_index + adjust) | |
8234 | % lh->maximum_ops_per_instruction); | |
8235 | } | |
c906108c SS |
8236 | break; |
8237 | case DW_LNS_fixed_advance_pc: | |
8238 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 8239 | op_index = 0; |
c906108c SS |
8240 | line_ptr += 2; |
8241 | break; | |
9aa1fe7e | 8242 | default: |
a738430d MK |
8243 | { |
8244 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 8245 | int i; |
a738430d | 8246 | |
debd256d | 8247 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
8248 | { |
8249 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8250 | line_ptr += bytes_read; | |
8251 | } | |
8252 | } | |
c906108c SS |
8253 | } |
8254 | } | |
59205f5a JB |
8255 | if (lh->num_file_names < file || file == 0) |
8256 | dwarf2_debug_line_missing_file_complaint (); | |
8257 | else | |
8258 | { | |
8259 | lh->file_names[file - 1].included_p = 1; | |
8260 | if (!decode_for_pst_p) | |
fbf65064 UW |
8261 | { |
8262 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8263 | record_line (current_subfile, 0, addr); | |
8264 | } | |
59205f5a | 8265 | } |
c906108c | 8266 | } |
aaa75496 JB |
8267 | |
8268 | if (decode_for_pst_p) | |
8269 | { | |
8270 | int file_index; | |
8271 | ||
8272 | /* Now that we're done scanning the Line Header Program, we can | |
8273 | create the psymtab of each included file. */ | |
8274 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
8275 | if (lh->file_names[file_index].included_p == 1) | |
8276 | { | |
5b5464ad JB |
8277 | const struct file_entry fe = lh->file_names [file_index]; |
8278 | char *include_name = fe.name; | |
8279 | char *dir_name = NULL; | |
8280 | char *pst_filename = pst->filename; | |
8281 | ||
8282 | if (fe.dir_index) | |
8283 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
8284 | ||
8285 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
8286 | { | |
1754f103 MK |
8287 | include_name = concat (dir_name, SLASH_STRING, |
8288 | include_name, (char *)NULL); | |
5b5464ad JB |
8289 | make_cleanup (xfree, include_name); |
8290 | } | |
8291 | ||
8292 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
8293 | { | |
1754f103 MK |
8294 | pst_filename = concat (pst->dirname, SLASH_STRING, |
8295 | pst_filename, (char *)NULL); | |
5b5464ad JB |
8296 | make_cleanup (xfree, pst_filename); |
8297 | } | |
8298 | ||
8299 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
8300 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
8301 | } | |
8302 | } | |
cb1df416 DJ |
8303 | else |
8304 | { | |
8305 | /* Make sure a symtab is created for every file, even files | |
8306 | which contain only variables (i.e. no code with associated | |
8307 | line numbers). */ | |
8308 | ||
8309 | int i; | |
8310 | struct file_entry *fe; | |
8311 | ||
8312 | for (i = 0; i < lh->num_file_names; i++) | |
8313 | { | |
8314 | char *dir = NULL; | |
8315 | fe = &lh->file_names[i]; | |
8316 | if (fe->dir_index) | |
8317 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8318 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8319 | ||
8320 | /* Skip the main file; we don't need it, and it must be | |
8321 | allocated last, so that it will show up before the | |
8322 | non-primary symtabs in the objfile's symtab list. */ | |
8323 | if (current_subfile == first_subfile) | |
8324 | continue; | |
8325 | ||
8326 | if (current_subfile->symtab == NULL) | |
8327 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
8328 | cu->objfile); | |
8329 | fe->symtab = current_subfile->symtab; | |
8330 | } | |
8331 | } | |
c906108c SS |
8332 | } |
8333 | ||
8334 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
8335 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
8336 | or NULL if not known. COMP_DIR is the compilation directory for the |
8337 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
8338 | This routine tries to keep line numbers from identical absolute and |
8339 | relative file names in a common subfile. | |
8340 | ||
8341 | Using the `list' example from the GDB testsuite, which resides in | |
8342 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
8343 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
8344 | ||
c5aa993b JM |
8345 | DW_AT_name: /srcdir/list0.c |
8346 | DW_AT_comp_dir: /compdir | |
357e46e7 | 8347 | files.files[0].name: list0.h |
c5aa993b | 8348 | files.files[0].dir: /srcdir |
357e46e7 | 8349 | files.files[1].name: list0.c |
c5aa993b | 8350 | files.files[1].dir: /srcdir |
c906108c SS |
8351 | |
8352 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
8353 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
8354 | start_subfile will ensure that this happens provided that we pass the | |
8355 | concatenation of files.files[1].dir and files.files[1].name as the | |
8356 | subfile's name. */ | |
c906108c SS |
8357 | |
8358 | static void | |
4f1520fb | 8359 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 8360 | { |
4f1520fb FR |
8361 | char *fullname; |
8362 | ||
8363 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
8364 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
8365 | second argument to start_subfile. To be consistent, we do the | |
8366 | same here. In order not to lose the line information directory, | |
8367 | we concatenate it to the filename when it makes sense. | |
8368 | Note that the Dwarf3 standard says (speaking of filenames in line | |
8369 | information): ``The directory index is ignored for file names | |
8370 | that represent full path names''. Thus ignoring dirname in the | |
8371 | `else' branch below isn't an issue. */ | |
c906108c | 8372 | |
d5166ae1 | 8373 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
8374 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
8375 | else | |
8376 | fullname = filename; | |
c906108c | 8377 | |
4f1520fb FR |
8378 | start_subfile (fullname, comp_dir); |
8379 | ||
8380 | if (fullname != filename) | |
8381 | xfree (fullname); | |
c906108c SS |
8382 | } |
8383 | ||
4c2df51b DJ |
8384 | static void |
8385 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8386 | struct dwarf2_cu *cu) |
4c2df51b | 8387 | { |
e7c27a73 DJ |
8388 | struct objfile *objfile = cu->objfile; |
8389 | struct comp_unit_head *cu_header = &cu->header; | |
8390 | ||
4c2df51b DJ |
8391 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
8392 | code here to turn a symbol with DW_AT_external and a | |
8393 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
8394 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
8395 | with some versions of binutils) where shared libraries could have | |
8396 | relocations against symbols in their debug information - the | |
8397 | minimal symbol would have the right address, but the debug info | |
8398 | would not. It's no longer necessary, because we will explicitly | |
8399 | apply relocations when we read in the debug information now. */ | |
8400 | ||
8401 | /* A DW_AT_location attribute with no contents indicates that a | |
8402 | variable has been optimized away. */ | |
8403 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
8404 | { | |
8405 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
8406 | return; | |
8407 | } | |
8408 | ||
8409 | /* Handle one degenerate form of location expression specially, to | |
8410 | preserve GDB's previous behavior when section offsets are | |
8411 | specified. If this is just a DW_OP_addr then mark this symbol | |
8412 | as LOC_STATIC. */ | |
8413 | ||
8414 | if (attr_form_is_block (attr) | |
8415 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
8416 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
8417 | { | |
891d2f0b | 8418 | unsigned int dummy; |
4c2df51b DJ |
8419 | |
8420 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 8421 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 8422 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
8423 | fixup_symbol_section (sym, objfile); |
8424 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
8425 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
8426 | return; |
8427 | } | |
8428 | ||
8429 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
8430 | expression evaluator, and use LOC_COMPUTED only when necessary | |
8431 | (i.e. when the value of a register or memory location is | |
8432 | referenced, or a thread-local block, etc.). Then again, it might | |
8433 | not be worthwhile. I'm assuming that it isn't unless performance | |
8434 | or memory numbers show me otherwise. */ | |
8435 | ||
e7c27a73 | 8436 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
8437 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8438 | } | |
8439 | ||
c906108c SS |
8440 | /* Given a pointer to a DWARF information entry, figure out if we need |
8441 | to make a symbol table entry for it, and if so, create a new entry | |
8442 | and return a pointer to it. | |
8443 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 8444 | used the passed type. */ |
c906108c SS |
8445 | |
8446 | static struct symbol * | |
e7c27a73 | 8447 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 8448 | { |
e7c27a73 | 8449 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8450 | struct symbol *sym = NULL; |
8451 | char *name; | |
8452 | struct attribute *attr = NULL; | |
8453 | struct attribute *attr2 = NULL; | |
e142c38c | 8454 | CORE_ADDR baseaddr; |
edb3359d | 8455 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
8456 | |
8457 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 8458 | |
94af9270 | 8459 | name = dwarf2_name (die, cu); |
c906108c SS |
8460 | if (name) |
8461 | { | |
94af9270 KS |
8462 | const char *linkagename; |
8463 | ||
4a146b47 | 8464 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
8465 | sizeof (struct symbol)); |
8466 | OBJSTAT (objfile, n_syms++); | |
8467 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
8468 | |
8469 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 8470 | SYMBOL_LANGUAGE (sym) = cu->language; |
94af9270 KS |
8471 | linkagename = dwarf2_physname (name, die, cu); |
8472 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c SS |
8473 | |
8474 | /* Default assumptions. | |
c5aa993b | 8475 | Use the passed type or decode it from the die. */ |
176620f1 | 8476 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 8477 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
8478 | if (type != NULL) |
8479 | SYMBOL_TYPE (sym) = type; | |
8480 | else | |
e7c27a73 | 8481 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
8482 | attr = dwarf2_attr (die, |
8483 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
8484 | cu); | |
c906108c SS |
8485 | if (attr) |
8486 | { | |
8487 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
8488 | } | |
cb1df416 | 8489 | |
edb3359d DJ |
8490 | attr = dwarf2_attr (die, |
8491 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
8492 | cu); | |
cb1df416 DJ |
8493 | if (attr) |
8494 | { | |
8495 | int file_index = DW_UNSND (attr); | |
8496 | if (cu->line_header == NULL | |
8497 | || file_index > cu->line_header->num_file_names) | |
8498 | complaint (&symfile_complaints, | |
8499 | _("file index out of range")); | |
1c3d648d | 8500 | else if (file_index > 0) |
cb1df416 DJ |
8501 | { |
8502 | struct file_entry *fe; | |
8503 | fe = &cu->line_header->file_names[file_index - 1]; | |
8504 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
8505 | } | |
8506 | } | |
8507 | ||
c906108c SS |
8508 | switch (die->tag) |
8509 | { | |
8510 | case DW_TAG_label: | |
e142c38c | 8511 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
8512 | if (attr) |
8513 | { | |
8514 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
8515 | } | |
8516 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
8517 | break; | |
8518 | case DW_TAG_subprogram: | |
8519 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8520 | finish_block. */ | |
8521 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 8522 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
8523 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
8524 | || cu->language == language_ada) | |
c906108c | 8525 | { |
2cfa0c8d JB |
8526 | /* Subprograms marked external are stored as a global symbol. |
8527 | Ada subprograms, whether marked external or not, are always | |
8528 | stored as a global symbol, because we want to be able to | |
8529 | access them globally. For instance, we want to be able | |
8530 | to break on a nested subprogram without having to | |
8531 | specify the context. */ | |
c906108c SS |
8532 | add_symbol_to_list (sym, &global_symbols); |
8533 | } | |
8534 | else | |
8535 | { | |
e142c38c | 8536 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8537 | } |
8538 | break; | |
edb3359d DJ |
8539 | case DW_TAG_inlined_subroutine: |
8540 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8541 | finish_block. */ | |
8542 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
8543 | SYMBOL_INLINED (sym) = 1; | |
8544 | /* Do not add the symbol to any lists. It will be found via | |
8545 | BLOCK_FUNCTION from the blockvector. */ | |
8546 | break; | |
c906108c SS |
8547 | case DW_TAG_variable: |
8548 | /* Compilation with minimal debug info may result in variables | |
8549 | with missing type entries. Change the misleading `void' type | |
8550 | to something sensible. */ | |
8551 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 8552 | SYMBOL_TYPE (sym) |
46bf5051 | 8553 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 8554 | |
e142c38c | 8555 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8556 | if (attr) |
8557 | { | |
e7c27a73 | 8558 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 8559 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
8560 | if (attr2 && (DW_UNSND (attr2) != 0)) |
8561 | add_symbol_to_list (sym, &global_symbols); | |
8562 | else | |
e142c38c | 8563 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8564 | break; |
8565 | } | |
e142c38c | 8566 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8567 | if (attr) |
8568 | { | |
e7c27a73 | 8569 | var_decode_location (attr, sym, cu); |
e142c38c | 8570 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8571 | if (attr2 && (DW_UNSND (attr2) != 0)) |
1c809c68 TT |
8572 | { |
8573 | struct pending **list_to_add; | |
8574 | ||
8575 | /* A variable with DW_AT_external is never static, | |
8576 | but it may be block-scoped. */ | |
8577 | list_to_add = (cu->list_in_scope == &file_symbols | |
8578 | ? &global_symbols : cu->list_in_scope); | |
8579 | add_symbol_to_list (sym, list_to_add); | |
8580 | } | |
c906108c | 8581 | else |
e142c38c | 8582 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8583 | } |
8584 | else | |
8585 | { | |
8586 | /* We do not know the address of this symbol. | |
c5aa993b JM |
8587 | If it is an external symbol and we have type information |
8588 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
8589 | The address of the variable will then be determined from | |
8590 | the minimal symbol table whenever the variable is | |
8591 | referenced. */ | |
e142c38c | 8592 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8593 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 8594 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 8595 | { |
0fe7935b DJ |
8596 | struct pending **list_to_add; |
8597 | ||
8598 | /* A variable with DW_AT_external is never static, but it | |
8599 | may be block-scoped. */ | |
8600 | list_to_add = (cu->list_in_scope == &file_symbols | |
8601 | ? &global_symbols : cu->list_in_scope); | |
8602 | ||
c906108c | 8603 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
0fe7935b | 8604 | add_symbol_to_list (sym, list_to_add); |
c906108c | 8605 | } |
442ddf59 JK |
8606 | else if (!die_is_declaration (die, cu)) |
8607 | { | |
8608 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
8609 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
8610 | add_symbol_to_list (sym, cu->list_in_scope); | |
8611 | } | |
c906108c SS |
8612 | } |
8613 | break; | |
8614 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
8615 | /* If we are inside a function, mark this as an argument. If |
8616 | not, we might be looking at an argument to an inlined function | |
8617 | when we do not have enough information to show inlined frames; | |
8618 | pretend it's a local variable in that case so that the user can | |
8619 | still see it. */ | |
8620 | if (context_stack_depth > 0 | |
8621 | && context_stack[context_stack_depth - 1].name != NULL) | |
8622 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 8623 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8624 | if (attr) |
8625 | { | |
e7c27a73 | 8626 | var_decode_location (attr, sym, cu); |
c906108c | 8627 | } |
e142c38c | 8628 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8629 | if (attr) |
8630 | { | |
e7c27a73 | 8631 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8632 | } |
e142c38c | 8633 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8634 | break; |
8635 | case DW_TAG_unspecified_parameters: | |
8636 | /* From varargs functions; gdb doesn't seem to have any | |
8637 | interest in this information, so just ignore it for now. | |
8638 | (FIXME?) */ | |
8639 | break; | |
8640 | case DW_TAG_class_type: | |
680b30c7 | 8641 | case DW_TAG_interface_type: |
c906108c SS |
8642 | case DW_TAG_structure_type: |
8643 | case DW_TAG_union_type: | |
72019c9c | 8644 | case DW_TAG_set_type: |
c906108c SS |
8645 | case DW_TAG_enumeration_type: |
8646 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 8647 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 8648 | |
63d06c5c DC |
8649 | /* Make sure that the symbol includes appropriate enclosing |
8650 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 8651 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
8652 | the type. */ |
8653 | ||
987504bb JJ |
8654 | if (cu->language == language_cplus |
8655 | || cu->language == language_java) | |
c906108c | 8656 | { |
63d06c5c DC |
8657 | struct type *type = SYMBOL_TYPE (sym); |
8658 | ||
8659 | if (TYPE_TAG_NAME (type) != NULL) | |
8660 | { | |
8661 | /* FIXME: carlton/2003-11-10: Should this use | |
8662 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
8663 | arises further down in this function.) */ |
8664 | /* The type's name is already allocated along with | |
8665 | this objfile, so we don't need to duplicate it | |
8666 | for the symbol. */ | |
8667 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 8668 | } |
c906108c | 8669 | } |
63d06c5c DC |
8670 | |
8671 | { | |
987504bb | 8672 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
8673 | really ever be static objects: otherwise, if you try |
8674 | to, say, break of a class's method and you're in a file | |
8675 | which doesn't mention that class, it won't work unless | |
8676 | the check for all static symbols in lookup_symbol_aux | |
8677 | saves you. See the OtherFileClass tests in | |
8678 | gdb.c++/namespace.exp. */ | |
8679 | ||
8680 | struct pending **list_to_add; | |
8681 | ||
e142c38c | 8682 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8683 | && (cu->language == language_cplus |
8684 | || cu->language == language_java) | |
e142c38c | 8685 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8686 | |
8687 | add_symbol_to_list (sym, list_to_add); | |
8688 | ||
8689 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 8690 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 8691 | defines a typedef for the class. */ |
987504bb | 8692 | if (cu->language == language_cplus |
8c6860bb JB |
8693 | || cu->language == language_java |
8694 | || cu->language == language_ada) | |
63d06c5c | 8695 | { |
d8151005 DJ |
8696 | /* The symbol's name is already allocated along with |
8697 | this objfile, so we don't need to duplicate it for | |
8698 | the type. */ | |
63d06c5c | 8699 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 8700 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
8701 | } |
8702 | } | |
c906108c SS |
8703 | break; |
8704 | case DW_TAG_typedef: | |
94af9270 KS |
8705 | SYMBOL_LINKAGE_NAME (sym) |
8706 | = (char *) dwarf2_full_name (name, die, cu); | |
63d06c5c DC |
8707 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
8708 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 8709 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 8710 | break; |
c906108c | 8711 | case DW_TAG_base_type: |
a02abb62 | 8712 | case DW_TAG_subrange_type: |
c906108c | 8713 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 8714 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 8715 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8716 | break; |
8717 | case DW_TAG_enumerator: | |
94af9270 KS |
8718 | SYMBOL_LINKAGE_NAME (sym) |
8719 | = (char *) dwarf2_full_name (name, die, cu); | |
e142c38c | 8720 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8721 | if (attr) |
8722 | { | |
e7c27a73 | 8723 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8724 | } |
63d06c5c DC |
8725 | { |
8726 | /* NOTE: carlton/2003-11-10: See comment above in the | |
8727 | DW_TAG_class_type, etc. block. */ | |
8728 | ||
8729 | struct pending **list_to_add; | |
8730 | ||
e142c38c | 8731 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8732 | && (cu->language == language_cplus |
8733 | || cu->language == language_java) | |
e142c38c | 8734 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8735 | |
8736 | add_symbol_to_list (sym, list_to_add); | |
8737 | } | |
c906108c | 8738 | break; |
5c4e30ca DC |
8739 | case DW_TAG_namespace: |
8740 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
8741 | add_symbol_to_list (sym, &global_symbols); | |
8742 | break; | |
c906108c SS |
8743 | default: |
8744 | /* Not a tag we recognize. Hopefully we aren't processing | |
8745 | trash data, but since we must specifically ignore things | |
8746 | we don't recognize, there is nothing else we should do at | |
8747 | this point. */ | |
e2e0b3e5 | 8748 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 8749 | dwarf_tag_name (die->tag)); |
c906108c SS |
8750 | break; |
8751 | } | |
df8a16a1 DJ |
8752 | |
8753 | /* For the benefit of old versions of GCC, check for anonymous | |
8754 | namespaces based on the demangled name. */ | |
8755 | if (!processing_has_namespace_info | |
94af9270 | 8756 | && cu->language == language_cplus) |
df8a16a1 | 8757 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
8758 | } |
8759 | return (sym); | |
8760 | } | |
8761 | ||
8762 | /* Copy constant value from an attribute to a symbol. */ | |
8763 | ||
8764 | static void | |
107d2387 | 8765 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 8766 | struct dwarf2_cu *cu) |
c906108c | 8767 | { |
e7c27a73 DJ |
8768 | struct objfile *objfile = cu->objfile; |
8769 | struct comp_unit_head *cu_header = &cu->header; | |
e17a4113 UW |
8770 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
8771 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
c906108c SS |
8772 | struct dwarf_block *blk; |
8773 | ||
8774 | switch (attr->form) | |
8775 | { | |
8776 | case DW_FORM_addr: | |
107d2387 | 8777 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
3567439c | 8778 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8779 | cu_header->addr_size, |
8780 | TYPE_LENGTH (SYMBOL_TYPE | |
8781 | (sym))); | |
4e38b386 | 8782 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8783 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
8784 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
8785 | it's body - store_unsigned_integer. */ | |
8786 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
72f2769e | 8787 | byte_order, DW_ADDR (attr)); |
c906108c SS |
8788 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
8789 | break; | |
4ac36638 | 8790 | case DW_FORM_string: |
93b5768b PA |
8791 | case DW_FORM_strp: |
8792 | /* DW_STRING is already allocated on the obstack, point directly | |
8793 | to it. */ | |
8794 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
8795 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8796 | break; | |
c906108c SS |
8797 | case DW_FORM_block1: |
8798 | case DW_FORM_block2: | |
8799 | case DW_FORM_block4: | |
8800 | case DW_FORM_block: | |
2dc7f7b3 | 8801 | case DW_FORM_exprloc: |
c906108c SS |
8802 | blk = DW_BLOCK (attr); |
8803 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 8804 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8805 | blk->size, |
8806 | TYPE_LENGTH (SYMBOL_TYPE | |
8807 | (sym))); | |
4e38b386 | 8808 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8809 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
8810 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
8811 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8812 | break; | |
2df3850c JM |
8813 | |
8814 | /* The DW_AT_const_value attributes are supposed to carry the | |
8815 | symbol's value "represented as it would be on the target | |
8816 | architecture." By the time we get here, it's already been | |
8817 | converted to host endianness, so we just need to sign- or | |
8818 | zero-extend it as appropriate. */ | |
8819 | case DW_FORM_data1: | |
8820 | dwarf2_const_value_data (attr, sym, 8); | |
8821 | break; | |
c906108c | 8822 | case DW_FORM_data2: |
2df3850c JM |
8823 | dwarf2_const_value_data (attr, sym, 16); |
8824 | break; | |
c906108c | 8825 | case DW_FORM_data4: |
2df3850c JM |
8826 | dwarf2_const_value_data (attr, sym, 32); |
8827 | break; | |
c906108c | 8828 | case DW_FORM_data8: |
2df3850c JM |
8829 | dwarf2_const_value_data (attr, sym, 64); |
8830 | break; | |
8831 | ||
c906108c | 8832 | case DW_FORM_sdata: |
2df3850c JM |
8833 | SYMBOL_VALUE (sym) = DW_SND (attr); |
8834 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8835 | break; | |
8836 | ||
c906108c SS |
8837 | case DW_FORM_udata: |
8838 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
8839 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8840 | break; | |
2df3850c | 8841 | |
c906108c | 8842 | default: |
4d3c2250 | 8843 | complaint (&symfile_complaints, |
e2e0b3e5 | 8844 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 8845 | dwarf_form_name (attr->form)); |
c906108c SS |
8846 | SYMBOL_VALUE (sym) = 0; |
8847 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8848 | break; | |
8849 | } | |
8850 | } | |
8851 | ||
2df3850c JM |
8852 | |
8853 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
8854 | or zero-extend it as appropriate for the symbol's type. */ | |
8855 | static void | |
8856 | dwarf2_const_value_data (struct attribute *attr, | |
8857 | struct symbol *sym, | |
8858 | int bits) | |
8859 | { | |
8860 | LONGEST l = DW_UNSND (attr); | |
8861 | ||
8862 | if (bits < sizeof (l) * 8) | |
8863 | { | |
8864 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
8865 | l &= ((LONGEST) 1 << bits) - 1; | |
8866 | else | |
bf9198f1 | 8867 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
8868 | } |
8869 | ||
8870 | SYMBOL_VALUE (sym) = l; | |
8871 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8872 | } | |
8873 | ||
8874 | ||
c906108c SS |
8875 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
8876 | ||
8877 | static struct type * | |
e7c27a73 | 8878 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8879 | { |
c906108c SS |
8880 | struct attribute *type_attr; |
8881 | struct die_info *type_die; | |
c906108c | 8882 | |
e142c38c | 8883 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
8884 | if (!type_attr) |
8885 | { | |
8886 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 8887 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 8888 | } |
348e048f DE |
8889 | |
8890 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10b3939b | 8891 | |
33ac96f0 | 8892 | return tag_type_to_type (type_die, cu); |
c906108c SS |
8893 | } |
8894 | ||
b4ba55a1 JB |
8895 | /* True iff CU's producer generates GNAT Ada auxiliary information |
8896 | that allows to find parallel types through that information instead | |
8897 | of having to do expensive parallel lookups by type name. */ | |
8898 | ||
8899 | static int | |
8900 | need_gnat_info (struct dwarf2_cu *cu) | |
8901 | { | |
8902 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
8903 | of GNAT produces this auxiliary information, without any indication | |
8904 | that it is produced. Part of enhancing the FSF version of GNAT | |
8905 | to produce that information will be to put in place an indicator | |
8906 | that we can use in order to determine whether the descriptive type | |
8907 | info is available or not. One suggestion that has been made is | |
8908 | to use a new attribute, attached to the CU die. For now, assume | |
8909 | that the descriptive type info is not available. */ | |
8910 | return 0; | |
8911 | } | |
8912 | ||
8913 | ||
8914 | /* Return the auxiliary type of the die in question using its | |
8915 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
8916 | attribute is not present. */ | |
8917 | ||
8918 | static struct type * | |
8919 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
8920 | { | |
b4ba55a1 JB |
8921 | struct attribute *type_attr; |
8922 | struct die_info *type_die; | |
8923 | ||
8924 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
8925 | if (!type_attr) | |
8926 | return NULL; | |
8927 | ||
8928 | type_die = follow_die_ref (die, type_attr, &cu); | |
33ac96f0 | 8929 | return tag_type_to_type (type_die, cu); |
b4ba55a1 JB |
8930 | } |
8931 | ||
8932 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
8933 | descriptive type accordingly. */ | |
8934 | ||
8935 | static void | |
8936 | set_descriptive_type (struct type *type, struct die_info *die, | |
8937 | struct dwarf2_cu *cu) | |
8938 | { | |
8939 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
8940 | ||
8941 | if (descriptive_type) | |
8942 | { | |
8943 | ALLOCATE_GNAT_AUX_TYPE (type); | |
8944 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
8945 | } | |
8946 | } | |
8947 | ||
c906108c SS |
8948 | /* Return the containing type of the die in question using its |
8949 | DW_AT_containing_type attribute. */ | |
8950 | ||
8951 | static struct type * | |
e7c27a73 | 8952 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8953 | { |
c906108c | 8954 | struct attribute *type_attr; |
33ac96f0 | 8955 | struct die_info *type_die; |
c906108c | 8956 | |
e142c38c | 8957 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
8958 | if (!type_attr) |
8959 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
8960 | "[in module %s]"), cu->objfile->name); | |
8961 | ||
8962 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
8963 | return tag_type_to_type (type_die, cu); | |
c906108c SS |
8964 | } |
8965 | ||
c906108c | 8966 | static struct type * |
e7c27a73 | 8967 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8968 | { |
f792889a DJ |
8969 | struct type *this_type; |
8970 | ||
8971 | this_type = read_type_die (die, cu); | |
8972 | if (!this_type) | |
c906108c | 8973 | { |
d97bc12b | 8974 | dump_die_for_error (die); |
f792889a DJ |
8975 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
8976 | cu->objfile->name); | |
c906108c | 8977 | } |
f792889a | 8978 | return this_type; |
c906108c SS |
8979 | } |
8980 | ||
f792889a | 8981 | static struct type * |
e7c27a73 | 8982 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8983 | { |
f792889a DJ |
8984 | struct type *this_type; |
8985 | ||
8986 | this_type = get_die_type (die, cu); | |
8987 | if (this_type) | |
8988 | return this_type; | |
8989 | ||
c906108c SS |
8990 | switch (die->tag) |
8991 | { | |
8992 | case DW_TAG_class_type: | |
680b30c7 | 8993 | case DW_TAG_interface_type: |
c906108c SS |
8994 | case DW_TAG_structure_type: |
8995 | case DW_TAG_union_type: | |
f792889a | 8996 | this_type = read_structure_type (die, cu); |
c906108c SS |
8997 | break; |
8998 | case DW_TAG_enumeration_type: | |
f792889a | 8999 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
9000 | break; |
9001 | case DW_TAG_subprogram: | |
9002 | case DW_TAG_subroutine_type: | |
edb3359d | 9003 | case DW_TAG_inlined_subroutine: |
f792889a | 9004 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
9005 | break; |
9006 | case DW_TAG_array_type: | |
f792889a | 9007 | this_type = read_array_type (die, cu); |
c906108c | 9008 | break; |
72019c9c | 9009 | case DW_TAG_set_type: |
f792889a | 9010 | this_type = read_set_type (die, cu); |
72019c9c | 9011 | break; |
c906108c | 9012 | case DW_TAG_pointer_type: |
f792889a | 9013 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
9014 | break; |
9015 | case DW_TAG_ptr_to_member_type: | |
f792889a | 9016 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
9017 | break; |
9018 | case DW_TAG_reference_type: | |
f792889a | 9019 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
9020 | break; |
9021 | case DW_TAG_const_type: | |
f792889a | 9022 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
9023 | break; |
9024 | case DW_TAG_volatile_type: | |
f792889a | 9025 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
9026 | break; |
9027 | case DW_TAG_string_type: | |
f792889a | 9028 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
9029 | break; |
9030 | case DW_TAG_typedef: | |
f792889a | 9031 | this_type = read_typedef (die, cu); |
c906108c | 9032 | break; |
a02abb62 | 9033 | case DW_TAG_subrange_type: |
f792889a | 9034 | this_type = read_subrange_type (die, cu); |
a02abb62 | 9035 | break; |
c906108c | 9036 | case DW_TAG_base_type: |
f792889a | 9037 | this_type = read_base_type (die, cu); |
c906108c | 9038 | break; |
81a17f79 | 9039 | case DW_TAG_unspecified_type: |
f792889a | 9040 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 9041 | break; |
0114d602 DJ |
9042 | case DW_TAG_namespace: |
9043 | this_type = read_namespace_type (die, cu); | |
9044 | break; | |
c906108c | 9045 | default: |
a1f5b845 | 9046 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 9047 | dwarf_tag_name (die->tag)); |
c906108c SS |
9048 | break; |
9049 | } | |
63d06c5c | 9050 | |
f792889a | 9051 | return this_type; |
63d06c5c DC |
9052 | } |
9053 | ||
fdde2d81 | 9054 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 9055 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 9056 | |
0114d602 DJ |
9057 | For example, if we're within the method foo() in the following |
9058 | code: | |
9059 | ||
9060 | namespace N { | |
9061 | class C { | |
9062 | void foo () { | |
9063 | } | |
9064 | }; | |
9065 | } | |
9066 | ||
9067 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
9068 | |
9069 | static char * | |
e142c38c | 9070 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 9071 | { |
0114d602 DJ |
9072 | struct die_info *parent, *spec_die; |
9073 | struct dwarf2_cu *spec_cu; | |
9074 | struct type *parent_type; | |
63d06c5c | 9075 | |
987504bb JJ |
9076 | if (cu->language != language_cplus |
9077 | && cu->language != language_java) | |
0114d602 DJ |
9078 | return ""; |
9079 | ||
9080 | /* We have to be careful in the presence of DW_AT_specification. | |
9081 | For example, with GCC 3.4, given the code | |
9082 | ||
9083 | namespace N { | |
9084 | void foo() { | |
9085 | // Definition of N::foo. | |
9086 | } | |
9087 | } | |
9088 | ||
9089 | then we'll have a tree of DIEs like this: | |
9090 | ||
9091 | 1: DW_TAG_compile_unit | |
9092 | 2: DW_TAG_namespace // N | |
9093 | 3: DW_TAG_subprogram // declaration of N::foo | |
9094 | 4: DW_TAG_subprogram // definition of N::foo | |
9095 | DW_AT_specification // refers to die #3 | |
9096 | ||
9097 | Thus, when processing die #4, we have to pretend that we're in | |
9098 | the context of its DW_AT_specification, namely the contex of die | |
9099 | #3. */ | |
9100 | spec_cu = cu; | |
9101 | spec_die = die_specification (die, &spec_cu); | |
9102 | if (spec_die == NULL) | |
9103 | parent = die->parent; | |
9104 | else | |
63d06c5c | 9105 | { |
0114d602 DJ |
9106 | parent = spec_die->parent; |
9107 | cu = spec_cu; | |
63d06c5c | 9108 | } |
0114d602 DJ |
9109 | |
9110 | if (parent == NULL) | |
9111 | return ""; | |
63d06c5c | 9112 | else |
0114d602 DJ |
9113 | switch (parent->tag) |
9114 | { | |
63d06c5c | 9115 | case DW_TAG_namespace: |
0114d602 | 9116 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
9117 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
9118 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
9119 | Work around this problem here. */ | |
9120 | if (cu->language == language_cplus | |
9121 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
9122 | return ""; | |
0114d602 DJ |
9123 | /* We give a name to even anonymous namespaces. */ |
9124 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 9125 | case DW_TAG_class_type: |
680b30c7 | 9126 | case DW_TAG_interface_type: |
63d06c5c | 9127 | case DW_TAG_structure_type: |
0114d602 DJ |
9128 | case DW_TAG_union_type: |
9129 | parent_type = read_type_die (parent, cu); | |
9130 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
9131 | return TYPE_TAG_NAME (parent_type); | |
9132 | else | |
9133 | /* An anonymous structure is only allowed non-static data | |
9134 | members; no typedefs, no member functions, et cetera. | |
9135 | So it does not need a prefix. */ | |
9136 | return ""; | |
63d06c5c | 9137 | default: |
8176b9b8 | 9138 | return determine_prefix (parent, cu); |
63d06c5c | 9139 | } |
63d06c5c DC |
9140 | } |
9141 | ||
987504bb JJ |
9142 | /* Return a newly-allocated string formed by concatenating PREFIX and |
9143 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
9144 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
9145 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
9146 | is used to determine the language and hence, the appropriate separator. */ | |
9147 | ||
9148 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
9149 | |
9150 | static char * | |
987504bb JJ |
9151 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
9152 | struct dwarf2_cu *cu) | |
63d06c5c | 9153 | { |
987504bb | 9154 | char *sep; |
63d06c5c | 9155 | |
987504bb JJ |
9156 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
9157 | sep = ""; | |
9158 | else if (cu->language == language_java) | |
9159 | sep = "."; | |
9160 | else | |
9161 | sep = "::"; | |
63d06c5c | 9162 | |
6dd47d34 DE |
9163 | if (prefix == NULL) |
9164 | prefix = ""; | |
9165 | if (suffix == NULL) | |
9166 | suffix = ""; | |
9167 | ||
987504bb JJ |
9168 | if (obs == NULL) |
9169 | { | |
9170 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
6dd47d34 DE |
9171 | strcpy (retval, prefix); |
9172 | strcat (retval, sep); | |
9173 | strcat (retval, suffix); | |
63d06c5c DC |
9174 | return retval; |
9175 | } | |
987504bb JJ |
9176 | else |
9177 | { | |
9178 | /* We have an obstack. */ | |
48cb83fd | 9179 | return obconcat (obs, prefix, sep, suffix, (char *) NULL); |
987504bb | 9180 | } |
63d06c5c DC |
9181 | } |
9182 | ||
c906108c SS |
9183 | /* Return sibling of die, NULL if no sibling. */ |
9184 | ||
f9aca02d | 9185 | static struct die_info * |
fba45db2 | 9186 | sibling_die (struct die_info *die) |
c906108c | 9187 | { |
639d11d3 | 9188 | return die->sibling; |
c906108c SS |
9189 | } |
9190 | ||
71c25dea TT |
9191 | /* Get name of a die, return NULL if not found. */ |
9192 | ||
9193 | static char * | |
9194 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
9195 | struct obstack *obstack) | |
9196 | { | |
9197 | if (name && cu->language == language_cplus) | |
9198 | { | |
9199 | char *canon_name = cp_canonicalize_string (name); | |
9200 | ||
9201 | if (canon_name != NULL) | |
9202 | { | |
9203 | if (strcmp (canon_name, name) != 0) | |
9204 | name = obsavestring (canon_name, strlen (canon_name), | |
9205 | obstack); | |
9206 | xfree (canon_name); | |
9207 | } | |
9208 | } | |
9209 | ||
9210 | return name; | |
c906108c SS |
9211 | } |
9212 | ||
9219021c DC |
9213 | /* Get name of a die, return NULL if not found. */ |
9214 | ||
9215 | static char * | |
e142c38c | 9216 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
9217 | { |
9218 | struct attribute *attr; | |
9219 | ||
e142c38c | 9220 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
9221 | if (!attr || !DW_STRING (attr)) |
9222 | return NULL; | |
9223 | ||
9224 | switch (die->tag) | |
9225 | { | |
9226 | case DW_TAG_compile_unit: | |
9227 | /* Compilation units have a DW_AT_name that is a filename, not | |
9228 | a source language identifier. */ | |
9229 | case DW_TAG_enumeration_type: | |
9230 | case DW_TAG_enumerator: | |
9231 | /* These tags always have simple identifiers already; no need | |
9232 | to canonicalize them. */ | |
9233 | return DW_STRING (attr); | |
907af001 | 9234 | |
418835cc KS |
9235 | case DW_TAG_subprogram: |
9236 | /* Java constructors will all be named "<init>", so return | |
9237 | the class name when we see this special case. */ | |
9238 | if (cu->language == language_java | |
9239 | && DW_STRING (attr) != NULL | |
9240 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
9241 | { | |
9242 | struct dwarf2_cu *spec_cu = cu; | |
9243 | struct die_info *spec_die; | |
9244 | ||
9245 | /* GCJ will output '<init>' for Java constructor names. | |
9246 | For this special case, return the name of the parent class. */ | |
9247 | ||
9248 | /* GCJ may output suprogram DIEs with AT_specification set. | |
9249 | If so, use the name of the specified DIE. */ | |
9250 | spec_die = die_specification (die, &spec_cu); | |
9251 | if (spec_die != NULL) | |
9252 | return dwarf2_name (spec_die, spec_cu); | |
9253 | ||
9254 | do | |
9255 | { | |
9256 | die = die->parent; | |
9257 | if (die->tag == DW_TAG_class_type) | |
9258 | return dwarf2_name (die, cu); | |
9259 | } | |
9260 | while (die->tag != DW_TAG_compile_unit); | |
9261 | } | |
907af001 UW |
9262 | break; |
9263 | ||
9264 | case DW_TAG_class_type: | |
9265 | case DW_TAG_interface_type: | |
9266 | case DW_TAG_structure_type: | |
9267 | case DW_TAG_union_type: | |
9268 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
9269 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
9270 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
9271 | and GCC 4.4. We work around this problem by ignoring these. */ | |
9272 | if (strncmp (DW_STRING (attr), "._", 2) == 0 | |
9273 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0) | |
9274 | return NULL; | |
9275 | break; | |
9276 | ||
71c25dea | 9277 | default: |
907af001 UW |
9278 | break; |
9279 | } | |
9280 | ||
9281 | if (!DW_STRING_IS_CANONICAL (attr)) | |
9282 | { | |
9283 | DW_STRING (attr) | |
9284 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
9285 | &cu->objfile->objfile_obstack); | |
9286 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 9287 | } |
907af001 | 9288 | return DW_STRING (attr); |
9219021c DC |
9289 | } |
9290 | ||
9291 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
9292 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
9293 | containing the return value on output. */ | |
9219021c DC |
9294 | |
9295 | static struct die_info * | |
f2f0e013 | 9296 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
9297 | { |
9298 | struct attribute *attr; | |
9219021c | 9299 | |
f2f0e013 | 9300 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
9301 | if (attr == NULL) |
9302 | return NULL; | |
9303 | ||
f2f0e013 | 9304 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
9305 | } |
9306 | ||
c906108c SS |
9307 | /* Convert a DIE tag into its string name. */ |
9308 | ||
9309 | static char * | |
aa1ee363 | 9310 | dwarf_tag_name (unsigned tag) |
c906108c SS |
9311 | { |
9312 | switch (tag) | |
9313 | { | |
9314 | case DW_TAG_padding: | |
9315 | return "DW_TAG_padding"; | |
9316 | case DW_TAG_array_type: | |
9317 | return "DW_TAG_array_type"; | |
9318 | case DW_TAG_class_type: | |
9319 | return "DW_TAG_class_type"; | |
9320 | case DW_TAG_entry_point: | |
9321 | return "DW_TAG_entry_point"; | |
9322 | case DW_TAG_enumeration_type: | |
9323 | return "DW_TAG_enumeration_type"; | |
9324 | case DW_TAG_formal_parameter: | |
9325 | return "DW_TAG_formal_parameter"; | |
9326 | case DW_TAG_imported_declaration: | |
9327 | return "DW_TAG_imported_declaration"; | |
9328 | case DW_TAG_label: | |
9329 | return "DW_TAG_label"; | |
9330 | case DW_TAG_lexical_block: | |
9331 | return "DW_TAG_lexical_block"; | |
9332 | case DW_TAG_member: | |
9333 | return "DW_TAG_member"; | |
9334 | case DW_TAG_pointer_type: | |
9335 | return "DW_TAG_pointer_type"; | |
9336 | case DW_TAG_reference_type: | |
9337 | return "DW_TAG_reference_type"; | |
9338 | case DW_TAG_compile_unit: | |
9339 | return "DW_TAG_compile_unit"; | |
9340 | case DW_TAG_string_type: | |
9341 | return "DW_TAG_string_type"; | |
9342 | case DW_TAG_structure_type: | |
9343 | return "DW_TAG_structure_type"; | |
9344 | case DW_TAG_subroutine_type: | |
9345 | return "DW_TAG_subroutine_type"; | |
9346 | case DW_TAG_typedef: | |
9347 | return "DW_TAG_typedef"; | |
9348 | case DW_TAG_union_type: | |
9349 | return "DW_TAG_union_type"; | |
9350 | case DW_TAG_unspecified_parameters: | |
9351 | return "DW_TAG_unspecified_parameters"; | |
9352 | case DW_TAG_variant: | |
9353 | return "DW_TAG_variant"; | |
9354 | case DW_TAG_common_block: | |
9355 | return "DW_TAG_common_block"; | |
9356 | case DW_TAG_common_inclusion: | |
9357 | return "DW_TAG_common_inclusion"; | |
9358 | case DW_TAG_inheritance: | |
9359 | return "DW_TAG_inheritance"; | |
9360 | case DW_TAG_inlined_subroutine: | |
9361 | return "DW_TAG_inlined_subroutine"; | |
9362 | case DW_TAG_module: | |
9363 | return "DW_TAG_module"; | |
9364 | case DW_TAG_ptr_to_member_type: | |
9365 | return "DW_TAG_ptr_to_member_type"; | |
9366 | case DW_TAG_set_type: | |
9367 | return "DW_TAG_set_type"; | |
9368 | case DW_TAG_subrange_type: | |
9369 | return "DW_TAG_subrange_type"; | |
9370 | case DW_TAG_with_stmt: | |
9371 | return "DW_TAG_with_stmt"; | |
9372 | case DW_TAG_access_declaration: | |
9373 | return "DW_TAG_access_declaration"; | |
9374 | case DW_TAG_base_type: | |
9375 | return "DW_TAG_base_type"; | |
9376 | case DW_TAG_catch_block: | |
9377 | return "DW_TAG_catch_block"; | |
9378 | case DW_TAG_const_type: | |
9379 | return "DW_TAG_const_type"; | |
9380 | case DW_TAG_constant: | |
9381 | return "DW_TAG_constant"; | |
9382 | case DW_TAG_enumerator: | |
9383 | return "DW_TAG_enumerator"; | |
9384 | case DW_TAG_file_type: | |
9385 | return "DW_TAG_file_type"; | |
9386 | case DW_TAG_friend: | |
9387 | return "DW_TAG_friend"; | |
9388 | case DW_TAG_namelist: | |
9389 | return "DW_TAG_namelist"; | |
9390 | case DW_TAG_namelist_item: | |
9391 | return "DW_TAG_namelist_item"; | |
9392 | case DW_TAG_packed_type: | |
9393 | return "DW_TAG_packed_type"; | |
9394 | case DW_TAG_subprogram: | |
9395 | return "DW_TAG_subprogram"; | |
9396 | case DW_TAG_template_type_param: | |
9397 | return "DW_TAG_template_type_param"; | |
9398 | case DW_TAG_template_value_param: | |
9399 | return "DW_TAG_template_value_param"; | |
9400 | case DW_TAG_thrown_type: | |
9401 | return "DW_TAG_thrown_type"; | |
9402 | case DW_TAG_try_block: | |
9403 | return "DW_TAG_try_block"; | |
9404 | case DW_TAG_variant_part: | |
9405 | return "DW_TAG_variant_part"; | |
9406 | case DW_TAG_variable: | |
9407 | return "DW_TAG_variable"; | |
9408 | case DW_TAG_volatile_type: | |
9409 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
9410 | case DW_TAG_dwarf_procedure: |
9411 | return "DW_TAG_dwarf_procedure"; | |
9412 | case DW_TAG_restrict_type: | |
9413 | return "DW_TAG_restrict_type"; | |
9414 | case DW_TAG_interface_type: | |
9415 | return "DW_TAG_interface_type"; | |
9416 | case DW_TAG_namespace: | |
9417 | return "DW_TAG_namespace"; | |
9418 | case DW_TAG_imported_module: | |
9419 | return "DW_TAG_imported_module"; | |
9420 | case DW_TAG_unspecified_type: | |
9421 | return "DW_TAG_unspecified_type"; | |
9422 | case DW_TAG_partial_unit: | |
9423 | return "DW_TAG_partial_unit"; | |
9424 | case DW_TAG_imported_unit: | |
9425 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
9426 | case DW_TAG_condition: |
9427 | return "DW_TAG_condition"; | |
9428 | case DW_TAG_shared_type: | |
9429 | return "DW_TAG_shared_type"; | |
348e048f DE |
9430 | case DW_TAG_type_unit: |
9431 | return "DW_TAG_type_unit"; | |
c906108c SS |
9432 | case DW_TAG_MIPS_loop: |
9433 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
9434 | case DW_TAG_HP_array_descriptor: |
9435 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
9436 | case DW_TAG_format_label: |
9437 | return "DW_TAG_format_label"; | |
9438 | case DW_TAG_function_template: | |
9439 | return "DW_TAG_function_template"; | |
9440 | case DW_TAG_class_template: | |
9441 | return "DW_TAG_class_template"; | |
b7619582 GF |
9442 | case DW_TAG_GNU_BINCL: |
9443 | return "DW_TAG_GNU_BINCL"; | |
9444 | case DW_TAG_GNU_EINCL: | |
9445 | return "DW_TAG_GNU_EINCL"; | |
9446 | case DW_TAG_upc_shared_type: | |
9447 | return "DW_TAG_upc_shared_type"; | |
9448 | case DW_TAG_upc_strict_type: | |
9449 | return "DW_TAG_upc_strict_type"; | |
9450 | case DW_TAG_upc_relaxed_type: | |
9451 | return "DW_TAG_upc_relaxed_type"; | |
9452 | case DW_TAG_PGI_kanji_type: | |
9453 | return "DW_TAG_PGI_kanji_type"; | |
9454 | case DW_TAG_PGI_interface_block: | |
9455 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
9456 | default: |
9457 | return "DW_TAG_<unknown>"; | |
9458 | } | |
9459 | } | |
9460 | ||
9461 | /* Convert a DWARF attribute code into its string name. */ | |
9462 | ||
9463 | static char * | |
aa1ee363 | 9464 | dwarf_attr_name (unsigned attr) |
c906108c SS |
9465 | { |
9466 | switch (attr) | |
9467 | { | |
9468 | case DW_AT_sibling: | |
9469 | return "DW_AT_sibling"; | |
9470 | case DW_AT_location: | |
9471 | return "DW_AT_location"; | |
9472 | case DW_AT_name: | |
9473 | return "DW_AT_name"; | |
9474 | case DW_AT_ordering: | |
9475 | return "DW_AT_ordering"; | |
9476 | case DW_AT_subscr_data: | |
9477 | return "DW_AT_subscr_data"; | |
9478 | case DW_AT_byte_size: | |
9479 | return "DW_AT_byte_size"; | |
9480 | case DW_AT_bit_offset: | |
9481 | return "DW_AT_bit_offset"; | |
9482 | case DW_AT_bit_size: | |
9483 | return "DW_AT_bit_size"; | |
9484 | case DW_AT_element_list: | |
9485 | return "DW_AT_element_list"; | |
9486 | case DW_AT_stmt_list: | |
9487 | return "DW_AT_stmt_list"; | |
9488 | case DW_AT_low_pc: | |
9489 | return "DW_AT_low_pc"; | |
9490 | case DW_AT_high_pc: | |
9491 | return "DW_AT_high_pc"; | |
9492 | case DW_AT_language: | |
9493 | return "DW_AT_language"; | |
9494 | case DW_AT_member: | |
9495 | return "DW_AT_member"; | |
9496 | case DW_AT_discr: | |
9497 | return "DW_AT_discr"; | |
9498 | case DW_AT_discr_value: | |
9499 | return "DW_AT_discr_value"; | |
9500 | case DW_AT_visibility: | |
9501 | return "DW_AT_visibility"; | |
9502 | case DW_AT_import: | |
9503 | return "DW_AT_import"; | |
9504 | case DW_AT_string_length: | |
9505 | return "DW_AT_string_length"; | |
9506 | case DW_AT_common_reference: | |
9507 | return "DW_AT_common_reference"; | |
9508 | case DW_AT_comp_dir: | |
9509 | return "DW_AT_comp_dir"; | |
9510 | case DW_AT_const_value: | |
9511 | return "DW_AT_const_value"; | |
9512 | case DW_AT_containing_type: | |
9513 | return "DW_AT_containing_type"; | |
9514 | case DW_AT_default_value: | |
9515 | return "DW_AT_default_value"; | |
9516 | case DW_AT_inline: | |
9517 | return "DW_AT_inline"; | |
9518 | case DW_AT_is_optional: | |
9519 | return "DW_AT_is_optional"; | |
9520 | case DW_AT_lower_bound: | |
9521 | return "DW_AT_lower_bound"; | |
9522 | case DW_AT_producer: | |
9523 | return "DW_AT_producer"; | |
9524 | case DW_AT_prototyped: | |
9525 | return "DW_AT_prototyped"; | |
9526 | case DW_AT_return_addr: | |
9527 | return "DW_AT_return_addr"; | |
9528 | case DW_AT_start_scope: | |
9529 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
9530 | case DW_AT_bit_stride: |
9531 | return "DW_AT_bit_stride"; | |
c906108c SS |
9532 | case DW_AT_upper_bound: |
9533 | return "DW_AT_upper_bound"; | |
9534 | case DW_AT_abstract_origin: | |
9535 | return "DW_AT_abstract_origin"; | |
9536 | case DW_AT_accessibility: | |
9537 | return "DW_AT_accessibility"; | |
9538 | case DW_AT_address_class: | |
9539 | return "DW_AT_address_class"; | |
9540 | case DW_AT_artificial: | |
9541 | return "DW_AT_artificial"; | |
9542 | case DW_AT_base_types: | |
9543 | return "DW_AT_base_types"; | |
9544 | case DW_AT_calling_convention: | |
9545 | return "DW_AT_calling_convention"; | |
9546 | case DW_AT_count: | |
9547 | return "DW_AT_count"; | |
9548 | case DW_AT_data_member_location: | |
9549 | return "DW_AT_data_member_location"; | |
9550 | case DW_AT_decl_column: | |
9551 | return "DW_AT_decl_column"; | |
9552 | case DW_AT_decl_file: | |
9553 | return "DW_AT_decl_file"; | |
9554 | case DW_AT_decl_line: | |
9555 | return "DW_AT_decl_line"; | |
9556 | case DW_AT_declaration: | |
9557 | return "DW_AT_declaration"; | |
9558 | case DW_AT_discr_list: | |
9559 | return "DW_AT_discr_list"; | |
9560 | case DW_AT_encoding: | |
9561 | return "DW_AT_encoding"; | |
9562 | case DW_AT_external: | |
9563 | return "DW_AT_external"; | |
9564 | case DW_AT_frame_base: | |
9565 | return "DW_AT_frame_base"; | |
9566 | case DW_AT_friend: | |
9567 | return "DW_AT_friend"; | |
9568 | case DW_AT_identifier_case: | |
9569 | return "DW_AT_identifier_case"; | |
9570 | case DW_AT_macro_info: | |
9571 | return "DW_AT_macro_info"; | |
9572 | case DW_AT_namelist_items: | |
9573 | return "DW_AT_namelist_items"; | |
9574 | case DW_AT_priority: | |
9575 | return "DW_AT_priority"; | |
9576 | case DW_AT_segment: | |
9577 | return "DW_AT_segment"; | |
9578 | case DW_AT_specification: | |
9579 | return "DW_AT_specification"; | |
9580 | case DW_AT_static_link: | |
9581 | return "DW_AT_static_link"; | |
9582 | case DW_AT_type: | |
9583 | return "DW_AT_type"; | |
9584 | case DW_AT_use_location: | |
9585 | return "DW_AT_use_location"; | |
9586 | case DW_AT_variable_parameter: | |
9587 | return "DW_AT_variable_parameter"; | |
9588 | case DW_AT_virtuality: | |
9589 | return "DW_AT_virtuality"; | |
9590 | case DW_AT_vtable_elem_location: | |
9591 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 9592 | /* DWARF 3 values. */ |
d9fa45fe DC |
9593 | case DW_AT_allocated: |
9594 | return "DW_AT_allocated"; | |
9595 | case DW_AT_associated: | |
9596 | return "DW_AT_associated"; | |
9597 | case DW_AT_data_location: | |
9598 | return "DW_AT_data_location"; | |
09fa0d7c JK |
9599 | case DW_AT_byte_stride: |
9600 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
9601 | case DW_AT_entry_pc: |
9602 | return "DW_AT_entry_pc"; | |
9603 | case DW_AT_use_UTF8: | |
9604 | return "DW_AT_use_UTF8"; | |
9605 | case DW_AT_extension: | |
9606 | return "DW_AT_extension"; | |
9607 | case DW_AT_ranges: | |
9608 | return "DW_AT_ranges"; | |
9609 | case DW_AT_trampoline: | |
9610 | return "DW_AT_trampoline"; | |
9611 | case DW_AT_call_column: | |
9612 | return "DW_AT_call_column"; | |
9613 | case DW_AT_call_file: | |
9614 | return "DW_AT_call_file"; | |
9615 | case DW_AT_call_line: | |
9616 | return "DW_AT_call_line"; | |
b7619582 GF |
9617 | case DW_AT_description: |
9618 | return "DW_AT_description"; | |
9619 | case DW_AT_binary_scale: | |
9620 | return "DW_AT_binary_scale"; | |
9621 | case DW_AT_decimal_scale: | |
9622 | return "DW_AT_decimal_scale"; | |
9623 | case DW_AT_small: | |
9624 | return "DW_AT_small"; | |
9625 | case DW_AT_decimal_sign: | |
9626 | return "DW_AT_decimal_sign"; | |
9627 | case DW_AT_digit_count: | |
9628 | return "DW_AT_digit_count"; | |
9629 | case DW_AT_picture_string: | |
9630 | return "DW_AT_picture_string"; | |
9631 | case DW_AT_mutable: | |
9632 | return "DW_AT_mutable"; | |
9633 | case DW_AT_threads_scaled: | |
9634 | return "DW_AT_threads_scaled"; | |
9635 | case DW_AT_explicit: | |
9636 | return "DW_AT_explicit"; | |
9637 | case DW_AT_object_pointer: | |
9638 | return "DW_AT_object_pointer"; | |
9639 | case DW_AT_endianity: | |
9640 | return "DW_AT_endianity"; | |
9641 | case DW_AT_elemental: | |
9642 | return "DW_AT_elemental"; | |
9643 | case DW_AT_pure: | |
9644 | return "DW_AT_pure"; | |
9645 | case DW_AT_recursive: | |
9646 | return "DW_AT_recursive"; | |
348e048f DE |
9647 | /* DWARF 4 values. */ |
9648 | case DW_AT_signature: | |
9649 | return "DW_AT_signature"; | |
31ef98ae TT |
9650 | case DW_AT_linkage_name: |
9651 | return "DW_AT_linkage_name"; | |
b7619582 | 9652 | /* SGI/MIPS extensions. */ |
c764a876 | 9653 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
9654 | case DW_AT_MIPS_fde: |
9655 | return "DW_AT_MIPS_fde"; | |
c764a876 | 9656 | #endif |
c906108c SS |
9657 | case DW_AT_MIPS_loop_begin: |
9658 | return "DW_AT_MIPS_loop_begin"; | |
9659 | case DW_AT_MIPS_tail_loop_begin: | |
9660 | return "DW_AT_MIPS_tail_loop_begin"; | |
9661 | case DW_AT_MIPS_epilog_begin: | |
9662 | return "DW_AT_MIPS_epilog_begin"; | |
9663 | case DW_AT_MIPS_loop_unroll_factor: | |
9664 | return "DW_AT_MIPS_loop_unroll_factor"; | |
9665 | case DW_AT_MIPS_software_pipeline_depth: | |
9666 | return "DW_AT_MIPS_software_pipeline_depth"; | |
9667 | case DW_AT_MIPS_linkage_name: | |
9668 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
9669 | case DW_AT_MIPS_stride: |
9670 | return "DW_AT_MIPS_stride"; | |
9671 | case DW_AT_MIPS_abstract_name: | |
9672 | return "DW_AT_MIPS_abstract_name"; | |
9673 | case DW_AT_MIPS_clone_origin: | |
9674 | return "DW_AT_MIPS_clone_origin"; | |
9675 | case DW_AT_MIPS_has_inlines: | |
9676 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 9677 | /* HP extensions. */ |
c764a876 | 9678 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
9679 | case DW_AT_HP_block_index: |
9680 | return "DW_AT_HP_block_index"; | |
c764a876 | 9681 | #endif |
b7619582 GF |
9682 | case DW_AT_HP_unmodifiable: |
9683 | return "DW_AT_HP_unmodifiable"; | |
9684 | case DW_AT_HP_actuals_stmt_list: | |
9685 | return "DW_AT_HP_actuals_stmt_list"; | |
9686 | case DW_AT_HP_proc_per_section: | |
9687 | return "DW_AT_HP_proc_per_section"; | |
9688 | case DW_AT_HP_raw_data_ptr: | |
9689 | return "DW_AT_HP_raw_data_ptr"; | |
9690 | case DW_AT_HP_pass_by_reference: | |
9691 | return "DW_AT_HP_pass_by_reference"; | |
9692 | case DW_AT_HP_opt_level: | |
9693 | return "DW_AT_HP_opt_level"; | |
9694 | case DW_AT_HP_prof_version_id: | |
9695 | return "DW_AT_HP_prof_version_id"; | |
9696 | case DW_AT_HP_opt_flags: | |
9697 | return "DW_AT_HP_opt_flags"; | |
9698 | case DW_AT_HP_cold_region_low_pc: | |
9699 | return "DW_AT_HP_cold_region_low_pc"; | |
9700 | case DW_AT_HP_cold_region_high_pc: | |
9701 | return "DW_AT_HP_cold_region_high_pc"; | |
9702 | case DW_AT_HP_all_variables_modifiable: | |
9703 | return "DW_AT_HP_all_variables_modifiable"; | |
9704 | case DW_AT_HP_linkage_name: | |
9705 | return "DW_AT_HP_linkage_name"; | |
9706 | case DW_AT_HP_prof_flags: | |
9707 | return "DW_AT_HP_prof_flags"; | |
9708 | /* GNU extensions. */ | |
c906108c SS |
9709 | case DW_AT_sf_names: |
9710 | return "DW_AT_sf_names"; | |
9711 | case DW_AT_src_info: | |
9712 | return "DW_AT_src_info"; | |
9713 | case DW_AT_mac_info: | |
9714 | return "DW_AT_mac_info"; | |
9715 | case DW_AT_src_coords: | |
9716 | return "DW_AT_src_coords"; | |
9717 | case DW_AT_body_begin: | |
9718 | return "DW_AT_body_begin"; | |
9719 | case DW_AT_body_end: | |
9720 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
9721 | case DW_AT_GNU_vector: |
9722 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
9723 | /* VMS extensions. */ |
9724 | case DW_AT_VMS_rtnbeg_pd_address: | |
9725 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
9726 | /* UPC extension. */ | |
9727 | case DW_AT_upc_threads_scaled: | |
9728 | return "DW_AT_upc_threads_scaled"; | |
9729 | /* PGI (STMicroelectronics) extensions. */ | |
9730 | case DW_AT_PGI_lbase: | |
9731 | return "DW_AT_PGI_lbase"; | |
9732 | case DW_AT_PGI_soffset: | |
9733 | return "DW_AT_PGI_soffset"; | |
9734 | case DW_AT_PGI_lstride: | |
9735 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
9736 | default: |
9737 | return "DW_AT_<unknown>"; | |
9738 | } | |
9739 | } | |
9740 | ||
9741 | /* Convert a DWARF value form code into its string name. */ | |
9742 | ||
9743 | static char * | |
aa1ee363 | 9744 | dwarf_form_name (unsigned form) |
c906108c SS |
9745 | { |
9746 | switch (form) | |
9747 | { | |
9748 | case DW_FORM_addr: | |
9749 | return "DW_FORM_addr"; | |
9750 | case DW_FORM_block2: | |
9751 | return "DW_FORM_block2"; | |
9752 | case DW_FORM_block4: | |
9753 | return "DW_FORM_block4"; | |
9754 | case DW_FORM_data2: | |
9755 | return "DW_FORM_data2"; | |
9756 | case DW_FORM_data4: | |
9757 | return "DW_FORM_data4"; | |
9758 | case DW_FORM_data8: | |
9759 | return "DW_FORM_data8"; | |
9760 | case DW_FORM_string: | |
9761 | return "DW_FORM_string"; | |
9762 | case DW_FORM_block: | |
9763 | return "DW_FORM_block"; | |
9764 | case DW_FORM_block1: | |
9765 | return "DW_FORM_block1"; | |
9766 | case DW_FORM_data1: | |
9767 | return "DW_FORM_data1"; | |
9768 | case DW_FORM_flag: | |
9769 | return "DW_FORM_flag"; | |
9770 | case DW_FORM_sdata: | |
9771 | return "DW_FORM_sdata"; | |
9772 | case DW_FORM_strp: | |
9773 | return "DW_FORM_strp"; | |
9774 | case DW_FORM_udata: | |
9775 | return "DW_FORM_udata"; | |
9776 | case DW_FORM_ref_addr: | |
9777 | return "DW_FORM_ref_addr"; | |
9778 | case DW_FORM_ref1: | |
9779 | return "DW_FORM_ref1"; | |
9780 | case DW_FORM_ref2: | |
9781 | return "DW_FORM_ref2"; | |
9782 | case DW_FORM_ref4: | |
9783 | return "DW_FORM_ref4"; | |
9784 | case DW_FORM_ref8: | |
9785 | return "DW_FORM_ref8"; | |
9786 | case DW_FORM_ref_udata: | |
9787 | return "DW_FORM_ref_udata"; | |
9788 | case DW_FORM_indirect: | |
9789 | return "DW_FORM_indirect"; | |
348e048f DE |
9790 | case DW_FORM_sec_offset: |
9791 | return "DW_FORM_sec_offset"; | |
9792 | case DW_FORM_exprloc: | |
9793 | return "DW_FORM_exprloc"; | |
9794 | case DW_FORM_flag_present: | |
9795 | return "DW_FORM_flag_present"; | |
9796 | case DW_FORM_sig8: | |
9797 | return "DW_FORM_sig8"; | |
c906108c SS |
9798 | default: |
9799 | return "DW_FORM_<unknown>"; | |
9800 | } | |
9801 | } | |
9802 | ||
9803 | /* Convert a DWARF stack opcode into its string name. */ | |
9804 | ||
9805 | static char * | |
aa1ee363 | 9806 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
9807 | { |
9808 | switch (op) | |
9809 | { | |
9810 | case DW_OP_addr: | |
9811 | return "DW_OP_addr"; | |
9812 | case DW_OP_deref: | |
9813 | return "DW_OP_deref"; | |
9814 | case DW_OP_const1u: | |
9815 | return "DW_OP_const1u"; | |
9816 | case DW_OP_const1s: | |
9817 | return "DW_OP_const1s"; | |
9818 | case DW_OP_const2u: | |
9819 | return "DW_OP_const2u"; | |
9820 | case DW_OP_const2s: | |
9821 | return "DW_OP_const2s"; | |
9822 | case DW_OP_const4u: | |
9823 | return "DW_OP_const4u"; | |
9824 | case DW_OP_const4s: | |
9825 | return "DW_OP_const4s"; | |
9826 | case DW_OP_const8u: | |
9827 | return "DW_OP_const8u"; | |
9828 | case DW_OP_const8s: | |
9829 | return "DW_OP_const8s"; | |
9830 | case DW_OP_constu: | |
9831 | return "DW_OP_constu"; | |
9832 | case DW_OP_consts: | |
9833 | return "DW_OP_consts"; | |
9834 | case DW_OP_dup: | |
9835 | return "DW_OP_dup"; | |
9836 | case DW_OP_drop: | |
9837 | return "DW_OP_drop"; | |
9838 | case DW_OP_over: | |
9839 | return "DW_OP_over"; | |
9840 | case DW_OP_pick: | |
9841 | return "DW_OP_pick"; | |
9842 | case DW_OP_swap: | |
9843 | return "DW_OP_swap"; | |
9844 | case DW_OP_rot: | |
9845 | return "DW_OP_rot"; | |
9846 | case DW_OP_xderef: | |
9847 | return "DW_OP_xderef"; | |
9848 | case DW_OP_abs: | |
9849 | return "DW_OP_abs"; | |
9850 | case DW_OP_and: | |
9851 | return "DW_OP_and"; | |
9852 | case DW_OP_div: | |
9853 | return "DW_OP_div"; | |
9854 | case DW_OP_minus: | |
9855 | return "DW_OP_minus"; | |
9856 | case DW_OP_mod: | |
9857 | return "DW_OP_mod"; | |
9858 | case DW_OP_mul: | |
9859 | return "DW_OP_mul"; | |
9860 | case DW_OP_neg: | |
9861 | return "DW_OP_neg"; | |
9862 | case DW_OP_not: | |
9863 | return "DW_OP_not"; | |
9864 | case DW_OP_or: | |
9865 | return "DW_OP_or"; | |
9866 | case DW_OP_plus: | |
9867 | return "DW_OP_plus"; | |
9868 | case DW_OP_plus_uconst: | |
9869 | return "DW_OP_plus_uconst"; | |
9870 | case DW_OP_shl: | |
9871 | return "DW_OP_shl"; | |
9872 | case DW_OP_shr: | |
9873 | return "DW_OP_shr"; | |
9874 | case DW_OP_shra: | |
9875 | return "DW_OP_shra"; | |
9876 | case DW_OP_xor: | |
9877 | return "DW_OP_xor"; | |
9878 | case DW_OP_bra: | |
9879 | return "DW_OP_bra"; | |
9880 | case DW_OP_eq: | |
9881 | return "DW_OP_eq"; | |
9882 | case DW_OP_ge: | |
9883 | return "DW_OP_ge"; | |
9884 | case DW_OP_gt: | |
9885 | return "DW_OP_gt"; | |
9886 | case DW_OP_le: | |
9887 | return "DW_OP_le"; | |
9888 | case DW_OP_lt: | |
9889 | return "DW_OP_lt"; | |
9890 | case DW_OP_ne: | |
9891 | return "DW_OP_ne"; | |
9892 | case DW_OP_skip: | |
9893 | return "DW_OP_skip"; | |
9894 | case DW_OP_lit0: | |
9895 | return "DW_OP_lit0"; | |
9896 | case DW_OP_lit1: | |
9897 | return "DW_OP_lit1"; | |
9898 | case DW_OP_lit2: | |
9899 | return "DW_OP_lit2"; | |
9900 | case DW_OP_lit3: | |
9901 | return "DW_OP_lit3"; | |
9902 | case DW_OP_lit4: | |
9903 | return "DW_OP_lit4"; | |
9904 | case DW_OP_lit5: | |
9905 | return "DW_OP_lit5"; | |
9906 | case DW_OP_lit6: | |
9907 | return "DW_OP_lit6"; | |
9908 | case DW_OP_lit7: | |
9909 | return "DW_OP_lit7"; | |
9910 | case DW_OP_lit8: | |
9911 | return "DW_OP_lit8"; | |
9912 | case DW_OP_lit9: | |
9913 | return "DW_OP_lit9"; | |
9914 | case DW_OP_lit10: | |
9915 | return "DW_OP_lit10"; | |
9916 | case DW_OP_lit11: | |
9917 | return "DW_OP_lit11"; | |
9918 | case DW_OP_lit12: | |
9919 | return "DW_OP_lit12"; | |
9920 | case DW_OP_lit13: | |
9921 | return "DW_OP_lit13"; | |
9922 | case DW_OP_lit14: | |
9923 | return "DW_OP_lit14"; | |
9924 | case DW_OP_lit15: | |
9925 | return "DW_OP_lit15"; | |
9926 | case DW_OP_lit16: | |
9927 | return "DW_OP_lit16"; | |
9928 | case DW_OP_lit17: | |
9929 | return "DW_OP_lit17"; | |
9930 | case DW_OP_lit18: | |
9931 | return "DW_OP_lit18"; | |
9932 | case DW_OP_lit19: | |
9933 | return "DW_OP_lit19"; | |
9934 | case DW_OP_lit20: | |
9935 | return "DW_OP_lit20"; | |
9936 | case DW_OP_lit21: | |
9937 | return "DW_OP_lit21"; | |
9938 | case DW_OP_lit22: | |
9939 | return "DW_OP_lit22"; | |
9940 | case DW_OP_lit23: | |
9941 | return "DW_OP_lit23"; | |
9942 | case DW_OP_lit24: | |
9943 | return "DW_OP_lit24"; | |
9944 | case DW_OP_lit25: | |
9945 | return "DW_OP_lit25"; | |
9946 | case DW_OP_lit26: | |
9947 | return "DW_OP_lit26"; | |
9948 | case DW_OP_lit27: | |
9949 | return "DW_OP_lit27"; | |
9950 | case DW_OP_lit28: | |
9951 | return "DW_OP_lit28"; | |
9952 | case DW_OP_lit29: | |
9953 | return "DW_OP_lit29"; | |
9954 | case DW_OP_lit30: | |
9955 | return "DW_OP_lit30"; | |
9956 | case DW_OP_lit31: | |
9957 | return "DW_OP_lit31"; | |
9958 | case DW_OP_reg0: | |
9959 | return "DW_OP_reg0"; | |
9960 | case DW_OP_reg1: | |
9961 | return "DW_OP_reg1"; | |
9962 | case DW_OP_reg2: | |
9963 | return "DW_OP_reg2"; | |
9964 | case DW_OP_reg3: | |
9965 | return "DW_OP_reg3"; | |
9966 | case DW_OP_reg4: | |
9967 | return "DW_OP_reg4"; | |
9968 | case DW_OP_reg5: | |
9969 | return "DW_OP_reg5"; | |
9970 | case DW_OP_reg6: | |
9971 | return "DW_OP_reg6"; | |
9972 | case DW_OP_reg7: | |
9973 | return "DW_OP_reg7"; | |
9974 | case DW_OP_reg8: | |
9975 | return "DW_OP_reg8"; | |
9976 | case DW_OP_reg9: | |
9977 | return "DW_OP_reg9"; | |
9978 | case DW_OP_reg10: | |
9979 | return "DW_OP_reg10"; | |
9980 | case DW_OP_reg11: | |
9981 | return "DW_OP_reg11"; | |
9982 | case DW_OP_reg12: | |
9983 | return "DW_OP_reg12"; | |
9984 | case DW_OP_reg13: | |
9985 | return "DW_OP_reg13"; | |
9986 | case DW_OP_reg14: | |
9987 | return "DW_OP_reg14"; | |
9988 | case DW_OP_reg15: | |
9989 | return "DW_OP_reg15"; | |
9990 | case DW_OP_reg16: | |
9991 | return "DW_OP_reg16"; | |
9992 | case DW_OP_reg17: | |
9993 | return "DW_OP_reg17"; | |
9994 | case DW_OP_reg18: | |
9995 | return "DW_OP_reg18"; | |
9996 | case DW_OP_reg19: | |
9997 | return "DW_OP_reg19"; | |
9998 | case DW_OP_reg20: | |
9999 | return "DW_OP_reg20"; | |
10000 | case DW_OP_reg21: | |
10001 | return "DW_OP_reg21"; | |
10002 | case DW_OP_reg22: | |
10003 | return "DW_OP_reg22"; | |
10004 | case DW_OP_reg23: | |
10005 | return "DW_OP_reg23"; | |
10006 | case DW_OP_reg24: | |
10007 | return "DW_OP_reg24"; | |
10008 | case DW_OP_reg25: | |
10009 | return "DW_OP_reg25"; | |
10010 | case DW_OP_reg26: | |
10011 | return "DW_OP_reg26"; | |
10012 | case DW_OP_reg27: | |
10013 | return "DW_OP_reg27"; | |
10014 | case DW_OP_reg28: | |
10015 | return "DW_OP_reg28"; | |
10016 | case DW_OP_reg29: | |
10017 | return "DW_OP_reg29"; | |
10018 | case DW_OP_reg30: | |
10019 | return "DW_OP_reg30"; | |
10020 | case DW_OP_reg31: | |
10021 | return "DW_OP_reg31"; | |
10022 | case DW_OP_breg0: | |
10023 | return "DW_OP_breg0"; | |
10024 | case DW_OP_breg1: | |
10025 | return "DW_OP_breg1"; | |
10026 | case DW_OP_breg2: | |
10027 | return "DW_OP_breg2"; | |
10028 | case DW_OP_breg3: | |
10029 | return "DW_OP_breg3"; | |
10030 | case DW_OP_breg4: | |
10031 | return "DW_OP_breg4"; | |
10032 | case DW_OP_breg5: | |
10033 | return "DW_OP_breg5"; | |
10034 | case DW_OP_breg6: | |
10035 | return "DW_OP_breg6"; | |
10036 | case DW_OP_breg7: | |
10037 | return "DW_OP_breg7"; | |
10038 | case DW_OP_breg8: | |
10039 | return "DW_OP_breg8"; | |
10040 | case DW_OP_breg9: | |
10041 | return "DW_OP_breg9"; | |
10042 | case DW_OP_breg10: | |
10043 | return "DW_OP_breg10"; | |
10044 | case DW_OP_breg11: | |
10045 | return "DW_OP_breg11"; | |
10046 | case DW_OP_breg12: | |
10047 | return "DW_OP_breg12"; | |
10048 | case DW_OP_breg13: | |
10049 | return "DW_OP_breg13"; | |
10050 | case DW_OP_breg14: | |
10051 | return "DW_OP_breg14"; | |
10052 | case DW_OP_breg15: | |
10053 | return "DW_OP_breg15"; | |
10054 | case DW_OP_breg16: | |
10055 | return "DW_OP_breg16"; | |
10056 | case DW_OP_breg17: | |
10057 | return "DW_OP_breg17"; | |
10058 | case DW_OP_breg18: | |
10059 | return "DW_OP_breg18"; | |
10060 | case DW_OP_breg19: | |
10061 | return "DW_OP_breg19"; | |
10062 | case DW_OP_breg20: | |
10063 | return "DW_OP_breg20"; | |
10064 | case DW_OP_breg21: | |
10065 | return "DW_OP_breg21"; | |
10066 | case DW_OP_breg22: | |
10067 | return "DW_OP_breg22"; | |
10068 | case DW_OP_breg23: | |
10069 | return "DW_OP_breg23"; | |
10070 | case DW_OP_breg24: | |
10071 | return "DW_OP_breg24"; | |
10072 | case DW_OP_breg25: | |
10073 | return "DW_OP_breg25"; | |
10074 | case DW_OP_breg26: | |
10075 | return "DW_OP_breg26"; | |
10076 | case DW_OP_breg27: | |
10077 | return "DW_OP_breg27"; | |
10078 | case DW_OP_breg28: | |
10079 | return "DW_OP_breg28"; | |
10080 | case DW_OP_breg29: | |
10081 | return "DW_OP_breg29"; | |
10082 | case DW_OP_breg30: | |
10083 | return "DW_OP_breg30"; | |
10084 | case DW_OP_breg31: | |
10085 | return "DW_OP_breg31"; | |
10086 | case DW_OP_regx: | |
10087 | return "DW_OP_regx"; | |
10088 | case DW_OP_fbreg: | |
10089 | return "DW_OP_fbreg"; | |
10090 | case DW_OP_bregx: | |
10091 | return "DW_OP_bregx"; | |
10092 | case DW_OP_piece: | |
10093 | return "DW_OP_piece"; | |
10094 | case DW_OP_deref_size: | |
10095 | return "DW_OP_deref_size"; | |
10096 | case DW_OP_xderef_size: | |
10097 | return "DW_OP_xderef_size"; | |
10098 | case DW_OP_nop: | |
10099 | return "DW_OP_nop"; | |
b7619582 | 10100 | /* DWARF 3 extensions. */ |
ed348acc EZ |
10101 | case DW_OP_push_object_address: |
10102 | return "DW_OP_push_object_address"; | |
10103 | case DW_OP_call2: | |
10104 | return "DW_OP_call2"; | |
10105 | case DW_OP_call4: | |
10106 | return "DW_OP_call4"; | |
10107 | case DW_OP_call_ref: | |
10108 | return "DW_OP_call_ref"; | |
b7619582 GF |
10109 | /* GNU extensions. */ |
10110 | case DW_OP_form_tls_address: | |
10111 | return "DW_OP_form_tls_address"; | |
10112 | case DW_OP_call_frame_cfa: | |
10113 | return "DW_OP_call_frame_cfa"; | |
10114 | case DW_OP_bit_piece: | |
10115 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
10116 | case DW_OP_GNU_push_tls_address: |
10117 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
10118 | case DW_OP_GNU_uninit: |
10119 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
10120 | /* HP extensions. */ |
10121 | case DW_OP_HP_is_value: | |
10122 | return "DW_OP_HP_is_value"; | |
10123 | case DW_OP_HP_fltconst4: | |
10124 | return "DW_OP_HP_fltconst4"; | |
10125 | case DW_OP_HP_fltconst8: | |
10126 | return "DW_OP_HP_fltconst8"; | |
10127 | case DW_OP_HP_mod_range: | |
10128 | return "DW_OP_HP_mod_range"; | |
10129 | case DW_OP_HP_unmod_range: | |
10130 | return "DW_OP_HP_unmod_range"; | |
10131 | case DW_OP_HP_tls: | |
10132 | return "DW_OP_HP_tls"; | |
c906108c SS |
10133 | default: |
10134 | return "OP_<unknown>"; | |
10135 | } | |
10136 | } | |
10137 | ||
10138 | static char * | |
fba45db2 | 10139 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
10140 | { |
10141 | if (mybool) | |
10142 | return "TRUE"; | |
10143 | else | |
10144 | return "FALSE"; | |
10145 | } | |
10146 | ||
10147 | /* Convert a DWARF type code into its string name. */ | |
10148 | ||
10149 | static char * | |
aa1ee363 | 10150 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
10151 | { |
10152 | switch (enc) | |
10153 | { | |
b7619582 GF |
10154 | case DW_ATE_void: |
10155 | return "DW_ATE_void"; | |
c906108c SS |
10156 | case DW_ATE_address: |
10157 | return "DW_ATE_address"; | |
10158 | case DW_ATE_boolean: | |
10159 | return "DW_ATE_boolean"; | |
10160 | case DW_ATE_complex_float: | |
10161 | return "DW_ATE_complex_float"; | |
10162 | case DW_ATE_float: | |
10163 | return "DW_ATE_float"; | |
10164 | case DW_ATE_signed: | |
10165 | return "DW_ATE_signed"; | |
10166 | case DW_ATE_signed_char: | |
10167 | return "DW_ATE_signed_char"; | |
10168 | case DW_ATE_unsigned: | |
10169 | return "DW_ATE_unsigned"; | |
10170 | case DW_ATE_unsigned_char: | |
10171 | return "DW_ATE_unsigned_char"; | |
b7619582 | 10172 | /* DWARF 3. */ |
d9fa45fe DC |
10173 | case DW_ATE_imaginary_float: |
10174 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
10175 | case DW_ATE_packed_decimal: |
10176 | return "DW_ATE_packed_decimal"; | |
10177 | case DW_ATE_numeric_string: | |
10178 | return "DW_ATE_numeric_string"; | |
10179 | case DW_ATE_edited: | |
10180 | return "DW_ATE_edited"; | |
10181 | case DW_ATE_signed_fixed: | |
10182 | return "DW_ATE_signed_fixed"; | |
10183 | case DW_ATE_unsigned_fixed: | |
10184 | return "DW_ATE_unsigned_fixed"; | |
10185 | case DW_ATE_decimal_float: | |
10186 | return "DW_ATE_decimal_float"; | |
10187 | /* HP extensions. */ | |
10188 | case DW_ATE_HP_float80: | |
10189 | return "DW_ATE_HP_float80"; | |
10190 | case DW_ATE_HP_complex_float80: | |
10191 | return "DW_ATE_HP_complex_float80"; | |
10192 | case DW_ATE_HP_float128: | |
10193 | return "DW_ATE_HP_float128"; | |
10194 | case DW_ATE_HP_complex_float128: | |
10195 | return "DW_ATE_HP_complex_float128"; | |
10196 | case DW_ATE_HP_floathpintel: | |
10197 | return "DW_ATE_HP_floathpintel"; | |
10198 | case DW_ATE_HP_imaginary_float80: | |
10199 | return "DW_ATE_HP_imaginary_float80"; | |
10200 | case DW_ATE_HP_imaginary_float128: | |
10201 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
10202 | default: |
10203 | return "DW_ATE_<unknown>"; | |
10204 | } | |
10205 | } | |
10206 | ||
10207 | /* Convert a DWARF call frame info operation to its string name. */ | |
10208 | ||
10209 | #if 0 | |
10210 | static char * | |
aa1ee363 | 10211 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
10212 | { |
10213 | switch (cfi_opc) | |
10214 | { | |
10215 | case DW_CFA_advance_loc: | |
10216 | return "DW_CFA_advance_loc"; | |
10217 | case DW_CFA_offset: | |
10218 | return "DW_CFA_offset"; | |
10219 | case DW_CFA_restore: | |
10220 | return "DW_CFA_restore"; | |
10221 | case DW_CFA_nop: | |
10222 | return "DW_CFA_nop"; | |
10223 | case DW_CFA_set_loc: | |
10224 | return "DW_CFA_set_loc"; | |
10225 | case DW_CFA_advance_loc1: | |
10226 | return "DW_CFA_advance_loc1"; | |
10227 | case DW_CFA_advance_loc2: | |
10228 | return "DW_CFA_advance_loc2"; | |
10229 | case DW_CFA_advance_loc4: | |
10230 | return "DW_CFA_advance_loc4"; | |
10231 | case DW_CFA_offset_extended: | |
10232 | return "DW_CFA_offset_extended"; | |
10233 | case DW_CFA_restore_extended: | |
10234 | return "DW_CFA_restore_extended"; | |
10235 | case DW_CFA_undefined: | |
10236 | return "DW_CFA_undefined"; | |
10237 | case DW_CFA_same_value: | |
10238 | return "DW_CFA_same_value"; | |
10239 | case DW_CFA_register: | |
10240 | return "DW_CFA_register"; | |
10241 | case DW_CFA_remember_state: | |
10242 | return "DW_CFA_remember_state"; | |
10243 | case DW_CFA_restore_state: | |
10244 | return "DW_CFA_restore_state"; | |
10245 | case DW_CFA_def_cfa: | |
10246 | return "DW_CFA_def_cfa"; | |
10247 | case DW_CFA_def_cfa_register: | |
10248 | return "DW_CFA_def_cfa_register"; | |
10249 | case DW_CFA_def_cfa_offset: | |
10250 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 10251 | /* DWARF 3. */ |
985cb1a3 JM |
10252 | case DW_CFA_def_cfa_expression: |
10253 | return "DW_CFA_def_cfa_expression"; | |
10254 | case DW_CFA_expression: | |
10255 | return "DW_CFA_expression"; | |
10256 | case DW_CFA_offset_extended_sf: | |
10257 | return "DW_CFA_offset_extended_sf"; | |
10258 | case DW_CFA_def_cfa_sf: | |
10259 | return "DW_CFA_def_cfa_sf"; | |
10260 | case DW_CFA_def_cfa_offset_sf: | |
10261 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
10262 | case DW_CFA_val_offset: |
10263 | return "DW_CFA_val_offset"; | |
10264 | case DW_CFA_val_offset_sf: | |
10265 | return "DW_CFA_val_offset_sf"; | |
10266 | case DW_CFA_val_expression: | |
10267 | return "DW_CFA_val_expression"; | |
10268 | /* SGI/MIPS specific. */ | |
c906108c SS |
10269 | case DW_CFA_MIPS_advance_loc8: |
10270 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 10271 | /* GNU extensions. */ |
985cb1a3 JM |
10272 | case DW_CFA_GNU_window_save: |
10273 | return "DW_CFA_GNU_window_save"; | |
10274 | case DW_CFA_GNU_args_size: | |
10275 | return "DW_CFA_GNU_args_size"; | |
10276 | case DW_CFA_GNU_negative_offset_extended: | |
10277 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
10278 | default: |
10279 | return "DW_CFA_<unknown>"; | |
10280 | } | |
10281 | } | |
10282 | #endif | |
10283 | ||
f9aca02d | 10284 | static void |
d97bc12b | 10285 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
10286 | { |
10287 | unsigned int i; | |
10288 | ||
d97bc12b DE |
10289 | print_spaces (indent, f); |
10290 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 10291 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
10292 | |
10293 | if (die->parent != NULL) | |
10294 | { | |
10295 | print_spaces (indent, f); | |
10296 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
10297 | die->parent->offset); | |
10298 | } | |
10299 | ||
10300 | print_spaces (indent, f); | |
10301 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 10302 | dwarf_bool_name (die->child != NULL)); |
c906108c | 10303 | |
d97bc12b DE |
10304 | print_spaces (indent, f); |
10305 | fprintf_unfiltered (f, " attributes:\n"); | |
10306 | ||
c906108c SS |
10307 | for (i = 0; i < die->num_attrs; ++i) |
10308 | { | |
d97bc12b DE |
10309 | print_spaces (indent, f); |
10310 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
10311 | dwarf_attr_name (die->attrs[i].name), |
10312 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 10313 | |
c906108c SS |
10314 | switch (die->attrs[i].form) |
10315 | { | |
10316 | case DW_FORM_ref_addr: | |
10317 | case DW_FORM_addr: | |
d97bc12b | 10318 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 10319 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
10320 | break; |
10321 | case DW_FORM_block2: | |
10322 | case DW_FORM_block4: | |
10323 | case DW_FORM_block: | |
10324 | case DW_FORM_block1: | |
d97bc12b | 10325 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 10326 | break; |
2dc7f7b3 TT |
10327 | case DW_FORM_exprloc: |
10328 | fprintf_unfiltered (f, "expression: size %u", | |
10329 | DW_BLOCK (&die->attrs[i])->size); | |
10330 | break; | |
10b3939b DJ |
10331 | case DW_FORM_ref1: |
10332 | case DW_FORM_ref2: | |
10333 | case DW_FORM_ref4: | |
d97bc12b | 10334 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
10335 | (long) (DW_ADDR (&die->attrs[i]))); |
10336 | break; | |
c906108c SS |
10337 | case DW_FORM_data1: |
10338 | case DW_FORM_data2: | |
10339 | case DW_FORM_data4: | |
ce5d95e1 | 10340 | case DW_FORM_data8: |
c906108c SS |
10341 | case DW_FORM_udata: |
10342 | case DW_FORM_sdata: | |
43bbcdc2 PH |
10343 | fprintf_unfiltered (f, "constant: %s", |
10344 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 10345 | break; |
2dc7f7b3 TT |
10346 | case DW_FORM_sec_offset: |
10347 | fprintf_unfiltered (f, "section offset: %s", | |
10348 | pulongest (DW_UNSND (&die->attrs[i]))); | |
10349 | break; | |
348e048f DE |
10350 | case DW_FORM_sig8: |
10351 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
10352 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
10353 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
10354 | else | |
10355 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
10356 | break; | |
c906108c | 10357 | case DW_FORM_string: |
4bdf3d34 | 10358 | case DW_FORM_strp: |
8285870a | 10359 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 10360 | DW_STRING (&die->attrs[i]) |
8285870a JK |
10361 | ? DW_STRING (&die->attrs[i]) : "", |
10362 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
10363 | break; |
10364 | case DW_FORM_flag: | |
10365 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 10366 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 10367 | else |
d97bc12b | 10368 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 10369 | break; |
2dc7f7b3 TT |
10370 | case DW_FORM_flag_present: |
10371 | fprintf_unfiltered (f, "flag: TRUE"); | |
10372 | break; | |
a8329558 KW |
10373 | case DW_FORM_indirect: |
10374 | /* the reader will have reduced the indirect form to | |
10375 | the "base form" so this form should not occur */ | |
d97bc12b | 10376 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 10377 | break; |
c906108c | 10378 | default: |
d97bc12b | 10379 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 10380 | die->attrs[i].form); |
d97bc12b | 10381 | break; |
c906108c | 10382 | } |
d97bc12b | 10383 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
10384 | } |
10385 | } | |
10386 | ||
f9aca02d | 10387 | static void |
d97bc12b | 10388 | dump_die_for_error (struct die_info *die) |
c906108c | 10389 | { |
d97bc12b DE |
10390 | dump_die_shallow (gdb_stderr, 0, die); |
10391 | } | |
10392 | ||
10393 | static void | |
10394 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
10395 | { | |
10396 | int indent = level * 4; | |
10397 | ||
10398 | gdb_assert (die != NULL); | |
10399 | ||
10400 | if (level >= max_level) | |
10401 | return; | |
10402 | ||
10403 | dump_die_shallow (f, indent, die); | |
10404 | ||
10405 | if (die->child != NULL) | |
c906108c | 10406 | { |
d97bc12b DE |
10407 | print_spaces (indent, f); |
10408 | fprintf_unfiltered (f, " Children:"); | |
10409 | if (level + 1 < max_level) | |
10410 | { | |
10411 | fprintf_unfiltered (f, "\n"); | |
10412 | dump_die_1 (f, level + 1, max_level, die->child); | |
10413 | } | |
10414 | else | |
10415 | { | |
10416 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
10417 | } | |
10418 | } | |
10419 | ||
10420 | if (die->sibling != NULL && level > 0) | |
10421 | { | |
10422 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
10423 | } |
10424 | } | |
10425 | ||
d97bc12b DE |
10426 | /* This is called from the pdie macro in gdbinit.in. |
10427 | It's not static so gcc will keep a copy callable from gdb. */ | |
10428 | ||
10429 | void | |
10430 | dump_die (struct die_info *die, int max_level) | |
10431 | { | |
10432 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
10433 | } | |
10434 | ||
f9aca02d | 10435 | static void |
51545339 | 10436 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10437 | { |
51545339 | 10438 | void **slot; |
c906108c | 10439 | |
51545339 DJ |
10440 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
10441 | ||
10442 | *slot = die; | |
c906108c SS |
10443 | } |
10444 | ||
93311388 DE |
10445 | static int |
10446 | is_ref_attr (struct attribute *attr) | |
c906108c | 10447 | { |
c906108c SS |
10448 | switch (attr->form) |
10449 | { | |
10450 | case DW_FORM_ref_addr: | |
c906108c SS |
10451 | case DW_FORM_ref1: |
10452 | case DW_FORM_ref2: | |
10453 | case DW_FORM_ref4: | |
613e1657 | 10454 | case DW_FORM_ref8: |
c906108c | 10455 | case DW_FORM_ref_udata: |
93311388 | 10456 | return 1; |
c906108c | 10457 | default: |
93311388 | 10458 | return 0; |
c906108c | 10459 | } |
93311388 DE |
10460 | } |
10461 | ||
10462 | static unsigned int | |
10463 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
10464 | { | |
10465 | if (is_ref_attr (attr)) | |
10466 | return DW_ADDR (attr); | |
10467 | ||
10468 | complaint (&symfile_complaints, | |
10469 | _("unsupported die ref attribute form: '%s'"), | |
10470 | dwarf_form_name (attr->form)); | |
10471 | return 0; | |
c906108c SS |
10472 | } |
10473 | ||
43bbcdc2 PH |
10474 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
10475 | * the value held by the attribute is not constant. */ | |
a02abb62 | 10476 | |
43bbcdc2 | 10477 | static LONGEST |
a02abb62 JB |
10478 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
10479 | { | |
10480 | if (attr->form == DW_FORM_sdata) | |
10481 | return DW_SND (attr); | |
10482 | else if (attr->form == DW_FORM_udata | |
10483 | || attr->form == DW_FORM_data1 | |
10484 | || attr->form == DW_FORM_data2 | |
10485 | || attr->form == DW_FORM_data4 | |
10486 | || attr->form == DW_FORM_data8) | |
10487 | return DW_UNSND (attr); | |
10488 | else | |
10489 | { | |
e2e0b3e5 | 10490 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
10491 | dwarf_form_name (attr->form)); |
10492 | return default_value; | |
10493 | } | |
10494 | } | |
10495 | ||
03dd20cc | 10496 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
10497 | unit and add it to our queue. |
10498 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
10499 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 10500 | |
348e048f | 10501 | static int |
03dd20cc DJ |
10502 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
10503 | struct dwarf2_per_cu_data *per_cu) | |
10504 | { | |
10505 | /* Mark the dependence relation so that we don't flush PER_CU | |
10506 | too early. */ | |
10507 | dwarf2_add_dependence (this_cu, per_cu); | |
10508 | ||
10509 | /* If it's already on the queue, we have nothing to do. */ | |
10510 | if (per_cu->queued) | |
348e048f | 10511 | return 0; |
03dd20cc DJ |
10512 | |
10513 | /* If the compilation unit is already loaded, just mark it as | |
10514 | used. */ | |
10515 | if (per_cu->cu != NULL) | |
10516 | { | |
10517 | per_cu->cu->last_used = 0; | |
348e048f | 10518 | return 0; |
03dd20cc DJ |
10519 | } |
10520 | ||
10521 | /* Add it to the queue. */ | |
10522 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
10523 | |
10524 | return 1; | |
10525 | } | |
10526 | ||
10527 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
10528 | On entry *REF_CU is the CU of SRC_DIE. | |
10529 | On exit *REF_CU is the CU of the result. */ | |
10530 | ||
10531 | static struct die_info * | |
10532 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
10533 | struct dwarf2_cu **ref_cu) | |
10534 | { | |
10535 | struct die_info *die; | |
10536 | ||
10537 | if (is_ref_attr (attr)) | |
10538 | die = follow_die_ref (src_die, attr, ref_cu); | |
10539 | else if (attr->form == DW_FORM_sig8) | |
10540 | die = follow_die_sig (src_die, attr, ref_cu); | |
10541 | else | |
10542 | { | |
10543 | dump_die_for_error (src_die); | |
10544 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
10545 | (*ref_cu)->objfile->name); | |
10546 | } | |
10547 | ||
10548 | return die; | |
03dd20cc DJ |
10549 | } |
10550 | ||
f504f079 DE |
10551 | /* Follow reference attribute ATTR of SRC_DIE. |
10552 | On entry *REF_CU is the CU of SRC_DIE. | |
10553 | On exit *REF_CU is the CU of the result. */ | |
10554 | ||
f9aca02d | 10555 | static struct die_info * |
10b3939b | 10556 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 10557 | struct dwarf2_cu **ref_cu) |
c906108c SS |
10558 | { |
10559 | struct die_info *die; | |
10b3939b | 10560 | unsigned int offset; |
10b3939b | 10561 | struct die_info temp_die; |
f2f0e013 | 10562 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 10563 | |
348e048f DE |
10564 | gdb_assert (cu->per_cu != NULL); |
10565 | ||
c764a876 | 10566 | offset = dwarf2_get_ref_die_offset (attr); |
10b3939b | 10567 | |
348e048f DE |
10568 | if (cu->per_cu->from_debug_types) |
10569 | { | |
10570 | /* .debug_types CUs cannot reference anything outside their CU. | |
10571 | If they need to, they have to reference a signatured type via | |
10572 | DW_FORM_sig8. */ | |
10573 | if (! offset_in_cu_p (&cu->header, offset)) | |
10574 | goto not_found; | |
10575 | target_cu = cu; | |
10576 | } | |
10577 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
10578 | { |
10579 | struct dwarf2_per_cu_data *per_cu; | |
45452591 | 10580 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
10581 | |
10582 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
10583 | if (maybe_queue_comp_unit (cu, per_cu)) |
10584 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 10585 | |
10b3939b DJ |
10586 | target_cu = per_cu->cu; |
10587 | } | |
10588 | else | |
10589 | target_cu = cu; | |
c906108c | 10590 | |
f2f0e013 | 10591 | *ref_cu = target_cu; |
51545339 DJ |
10592 | temp_die.offset = offset; |
10593 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
10594 | if (die) | |
10595 | return die; | |
10b3939b | 10596 | |
348e048f DE |
10597 | not_found: |
10598 | ||
10599 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
10600 | "at 0x%x [in module %s]"), | |
10601 | offset, src_die->offset, cu->objfile->name); | |
10602 | } | |
10603 | ||
10604 | /* Follow the signature attribute ATTR in SRC_DIE. | |
10605 | On entry *REF_CU is the CU of SRC_DIE. | |
10606 | On exit *REF_CU is the CU of the result. */ | |
10607 | ||
10608 | static struct die_info * | |
10609 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
10610 | struct dwarf2_cu **ref_cu) | |
10611 | { | |
10612 | struct objfile *objfile = (*ref_cu)->objfile; | |
10613 | struct die_info temp_die; | |
10614 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
10615 | struct dwarf2_cu *sig_cu; | |
10616 | struct die_info *die; | |
10617 | ||
10618 | /* sig_type will be NULL if the signatured type is missing from | |
10619 | the debug info. */ | |
10620 | if (sig_type == NULL) | |
10621 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
10622 | "at 0x%x [in module %s]"), | |
10623 | src_die->offset, objfile->name); | |
10624 | ||
10625 | /* If necessary, add it to the queue and load its DIEs. */ | |
10626 | ||
10627 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
10628 | read_signatured_type (objfile, sig_type); | |
10629 | ||
10630 | gdb_assert (sig_type->per_cu.cu != NULL); | |
10631 | ||
10632 | sig_cu = sig_type->per_cu.cu; | |
10633 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
10634 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
10635 | if (die) | |
10636 | { | |
10637 | *ref_cu = sig_cu; | |
10638 | return die; | |
10639 | } | |
10640 | ||
10641 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
10642 | "at 0x%x [in module %s]"), | |
10643 | sig_type->type_offset, src_die->offset, objfile->name); | |
10644 | } | |
10645 | ||
10646 | /* Given an offset of a signatured type, return its signatured_type. */ | |
10647 | ||
10648 | static struct signatured_type * | |
10649 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
10650 | { | |
10651 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
10652 | unsigned int length, initial_length_size; | |
10653 | unsigned int sig_offset; | |
10654 | struct signatured_type find_entry, *type_sig; | |
10655 | ||
10656 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
10657 | sig_offset = (initial_length_size | |
10658 | + 2 /*version*/ | |
10659 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
10660 | + 1 /*address_size*/); | |
10661 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
10662 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
10663 | ||
10664 | /* This is only used to lookup previously recorded types. | |
10665 | If we didn't find it, it's our bug. */ | |
10666 | gdb_assert (type_sig != NULL); | |
10667 | gdb_assert (offset == type_sig->offset); | |
10668 | ||
10669 | return type_sig; | |
10670 | } | |
10671 | ||
10672 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
10673 | ||
10674 | static void | |
10675 | read_signatured_type_at_offset (struct objfile *objfile, | |
10676 | unsigned int offset) | |
10677 | { | |
10678 | struct signatured_type *type_sig; | |
10679 | ||
be391dca TT |
10680 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
10681 | ||
348e048f DE |
10682 | /* We have the section offset, but we need the signature to do the |
10683 | hash table lookup. */ | |
10684 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
10685 | ||
10686 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10687 | ||
10688 | read_signatured_type (objfile, type_sig); | |
10689 | ||
10690 | gdb_assert (type_sig->per_cu.cu != NULL); | |
10691 | } | |
10692 | ||
10693 | /* Read in a signatured type and build its CU and DIEs. */ | |
10694 | ||
10695 | static void | |
10696 | read_signatured_type (struct objfile *objfile, | |
10697 | struct signatured_type *type_sig) | |
10698 | { | |
10699 | gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
10700 | struct die_reader_specs reader_specs; | |
10701 | struct dwarf2_cu *cu; | |
10702 | ULONGEST signature; | |
10703 | struct cleanup *back_to, *free_cu_cleanup; | |
10704 | struct attribute *attr; | |
10705 | ||
10706 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10707 | ||
10708 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
10709 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
10710 | obstack_init (&cu->comp_unit_obstack); | |
10711 | cu->objfile = objfile; | |
10712 | type_sig->per_cu.cu = cu; | |
10713 | cu->per_cu = &type_sig->per_cu; | |
10714 | ||
10715 | /* If an error occurs while loading, release our storage. */ | |
10716 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
10717 | ||
10718 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
10719 | types_ptr, objfile->obfd); | |
10720 | gdb_assert (signature == type_sig->signature); | |
10721 | ||
10722 | cu->die_hash | |
10723 | = htab_create_alloc_ex (cu->header.length / 12, | |
10724 | die_hash, | |
10725 | die_eq, | |
10726 | NULL, | |
10727 | &cu->comp_unit_obstack, | |
10728 | hashtab_obstack_allocate, | |
10729 | dummy_obstack_deallocate); | |
10730 | ||
10731 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
10732 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10733 | ||
10734 | init_cu_die_reader (&reader_specs, cu); | |
10735 | ||
10736 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
10737 | NULL /*parent*/); | |
10738 | ||
10739 | /* We try not to read any attributes in this function, because not | |
10740 | all objfiles needed for references have been loaded yet, and symbol | |
10741 | table processing isn't initialized. But we have to set the CU language, | |
10742 | or we won't be able to build types correctly. */ | |
10743 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
10744 | if (attr) | |
10745 | set_cu_language (DW_UNSND (attr), cu); | |
10746 | else | |
10747 | set_cu_language (language_minimal, cu); | |
10748 | ||
10749 | do_cleanups (back_to); | |
10750 | ||
10751 | /* We've successfully allocated this compilation unit. Let our caller | |
10752 | clean it up when finished with it. */ | |
10753 | discard_cleanups (free_cu_cleanup); | |
10754 | ||
10755 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
10756 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
10757 | } |
10758 | ||
c906108c SS |
10759 | /* Decode simple location descriptions. |
10760 | Given a pointer to a dwarf block that defines a location, compute | |
10761 | the location and return the value. | |
10762 | ||
4cecd739 DJ |
10763 | NOTE drow/2003-11-18: This function is called in two situations |
10764 | now: for the address of static or global variables (partial symbols | |
10765 | only) and for offsets into structures which are expected to be | |
10766 | (more or less) constant. The partial symbol case should go away, | |
10767 | and only the constant case should remain. That will let this | |
10768 | function complain more accurately. A few special modes are allowed | |
10769 | without complaint for global variables (for instance, global | |
10770 | register values and thread-local values). | |
c906108c SS |
10771 | |
10772 | A location description containing no operations indicates that the | |
4cecd739 | 10773 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
10774 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
10775 | callers will only want a very basic result and this can become a | |
10776 | complaint. | |
c906108c | 10777 | |
c906108c SS |
10778 | Note that stack[0] is unused except as a default error return. |
10779 | Note that stack overflow is not yet handled. */ | |
10780 | ||
10781 | static CORE_ADDR | |
e7c27a73 | 10782 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 10783 | { |
e7c27a73 | 10784 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10785 | int i; |
10786 | int size = blk->size; | |
fe1b8b76 | 10787 | gdb_byte *data = blk->data; |
c906108c SS |
10788 | CORE_ADDR stack[64]; |
10789 | int stacki; | |
10790 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 10791 | gdb_byte op; |
c906108c SS |
10792 | |
10793 | i = 0; | |
10794 | stacki = 0; | |
10795 | stack[stacki] = 0; | |
c906108c SS |
10796 | |
10797 | while (i < size) | |
10798 | { | |
c906108c SS |
10799 | op = data[i++]; |
10800 | switch (op) | |
10801 | { | |
f1bea926 JM |
10802 | case DW_OP_lit0: |
10803 | case DW_OP_lit1: | |
10804 | case DW_OP_lit2: | |
10805 | case DW_OP_lit3: | |
10806 | case DW_OP_lit4: | |
10807 | case DW_OP_lit5: | |
10808 | case DW_OP_lit6: | |
10809 | case DW_OP_lit7: | |
10810 | case DW_OP_lit8: | |
10811 | case DW_OP_lit9: | |
10812 | case DW_OP_lit10: | |
10813 | case DW_OP_lit11: | |
10814 | case DW_OP_lit12: | |
10815 | case DW_OP_lit13: | |
10816 | case DW_OP_lit14: | |
10817 | case DW_OP_lit15: | |
10818 | case DW_OP_lit16: | |
10819 | case DW_OP_lit17: | |
10820 | case DW_OP_lit18: | |
10821 | case DW_OP_lit19: | |
10822 | case DW_OP_lit20: | |
10823 | case DW_OP_lit21: | |
10824 | case DW_OP_lit22: | |
10825 | case DW_OP_lit23: | |
10826 | case DW_OP_lit24: | |
10827 | case DW_OP_lit25: | |
10828 | case DW_OP_lit26: | |
10829 | case DW_OP_lit27: | |
10830 | case DW_OP_lit28: | |
10831 | case DW_OP_lit29: | |
10832 | case DW_OP_lit30: | |
10833 | case DW_OP_lit31: | |
10834 | stack[++stacki] = op - DW_OP_lit0; | |
10835 | break; | |
10836 | ||
c906108c SS |
10837 | case DW_OP_reg0: |
10838 | case DW_OP_reg1: | |
10839 | case DW_OP_reg2: | |
10840 | case DW_OP_reg3: | |
10841 | case DW_OP_reg4: | |
10842 | case DW_OP_reg5: | |
10843 | case DW_OP_reg6: | |
10844 | case DW_OP_reg7: | |
10845 | case DW_OP_reg8: | |
10846 | case DW_OP_reg9: | |
10847 | case DW_OP_reg10: | |
10848 | case DW_OP_reg11: | |
10849 | case DW_OP_reg12: | |
10850 | case DW_OP_reg13: | |
10851 | case DW_OP_reg14: | |
10852 | case DW_OP_reg15: | |
10853 | case DW_OP_reg16: | |
10854 | case DW_OP_reg17: | |
10855 | case DW_OP_reg18: | |
10856 | case DW_OP_reg19: | |
10857 | case DW_OP_reg20: | |
10858 | case DW_OP_reg21: | |
10859 | case DW_OP_reg22: | |
10860 | case DW_OP_reg23: | |
10861 | case DW_OP_reg24: | |
10862 | case DW_OP_reg25: | |
10863 | case DW_OP_reg26: | |
10864 | case DW_OP_reg27: | |
10865 | case DW_OP_reg28: | |
10866 | case DW_OP_reg29: | |
10867 | case DW_OP_reg30: | |
10868 | case DW_OP_reg31: | |
c906108c | 10869 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
10870 | if (i < size) |
10871 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10872 | break; |
10873 | ||
10874 | case DW_OP_regx: | |
c906108c SS |
10875 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
10876 | i += bytes_read; | |
c906108c | 10877 | stack[++stacki] = unsnd; |
4cecd739 DJ |
10878 | if (i < size) |
10879 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10880 | break; |
10881 | ||
10882 | case DW_OP_addr: | |
107d2387 | 10883 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 10884 | cu, &bytes_read); |
107d2387 | 10885 | i += bytes_read; |
c906108c SS |
10886 | break; |
10887 | ||
10888 | case DW_OP_const1u: | |
10889 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
10890 | i += 1; | |
10891 | break; | |
10892 | ||
10893 | case DW_OP_const1s: | |
10894 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
10895 | i += 1; | |
10896 | break; | |
10897 | ||
10898 | case DW_OP_const2u: | |
10899 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
10900 | i += 2; | |
10901 | break; | |
10902 | ||
10903 | case DW_OP_const2s: | |
10904 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
10905 | i += 2; | |
10906 | break; | |
10907 | ||
10908 | case DW_OP_const4u: | |
10909 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
10910 | i += 4; | |
10911 | break; | |
10912 | ||
10913 | case DW_OP_const4s: | |
10914 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
10915 | i += 4; | |
10916 | break; | |
10917 | ||
10918 | case DW_OP_constu: | |
10919 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 10920 | &bytes_read); |
c906108c SS |
10921 | i += bytes_read; |
10922 | break; | |
10923 | ||
10924 | case DW_OP_consts: | |
10925 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
10926 | i += bytes_read; | |
10927 | break; | |
10928 | ||
f1bea926 JM |
10929 | case DW_OP_dup: |
10930 | stack[stacki + 1] = stack[stacki]; | |
10931 | stacki++; | |
10932 | break; | |
10933 | ||
c906108c SS |
10934 | case DW_OP_plus: |
10935 | stack[stacki - 1] += stack[stacki]; | |
10936 | stacki--; | |
10937 | break; | |
10938 | ||
10939 | case DW_OP_plus_uconst: | |
10940 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
10941 | i += bytes_read; | |
10942 | break; | |
10943 | ||
10944 | case DW_OP_minus: | |
f1bea926 | 10945 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
10946 | stacki--; |
10947 | break; | |
10948 | ||
7a292a7a | 10949 | case DW_OP_deref: |
7a292a7a | 10950 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
10951 | this using GDB's address_class enum. This is valid for partial |
10952 | global symbols, although the variable's address will be bogus | |
10953 | in the psymtab. */ | |
7a292a7a | 10954 | if (i < size) |
4d3c2250 | 10955 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
10956 | break; |
10957 | ||
9d774e44 | 10958 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
10959 | /* The top of the stack has the offset from the beginning |
10960 | of the thread control block at which the variable is located. */ | |
10961 | /* Nothing should follow this operator, so the top of stack would | |
10962 | be returned. */ | |
4cecd739 DJ |
10963 | /* This is valid for partial global symbols, but the variable's |
10964 | address will be bogus in the psymtab. */ | |
9d774e44 | 10965 | if (i < size) |
4d3c2250 | 10966 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
10967 | break; |
10968 | ||
42be36b3 CT |
10969 | case DW_OP_GNU_uninit: |
10970 | break; | |
10971 | ||
c906108c | 10972 | default: |
e2e0b3e5 | 10973 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 10974 | dwarf_stack_op_name (op)); |
c906108c SS |
10975 | return (stack[stacki]); |
10976 | } | |
10977 | } | |
10978 | return (stack[stacki]); | |
10979 | } | |
10980 | ||
10981 | /* memory allocation interface */ | |
10982 | ||
c906108c | 10983 | static struct dwarf_block * |
7b5a2f43 | 10984 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
10985 | { |
10986 | struct dwarf_block *blk; | |
10987 | ||
10988 | blk = (struct dwarf_block *) | |
7b5a2f43 | 10989 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
10990 | return (blk); |
10991 | } | |
10992 | ||
10993 | static struct abbrev_info * | |
f3dd6933 | 10994 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
10995 | { |
10996 | struct abbrev_info *abbrev; | |
10997 | ||
f3dd6933 DJ |
10998 | abbrev = (struct abbrev_info *) |
10999 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
11000 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
11001 | return (abbrev); | |
11002 | } | |
11003 | ||
11004 | static struct die_info * | |
b60c80d6 | 11005 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
11006 | { |
11007 | struct die_info *die; | |
b60c80d6 DJ |
11008 | size_t size = sizeof (struct die_info); |
11009 | ||
11010 | if (num_attrs > 1) | |
11011 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 11012 | |
b60c80d6 | 11013 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
11014 | memset (die, 0, sizeof (struct die_info)); |
11015 | return (die); | |
11016 | } | |
2e276125 JB |
11017 | |
11018 | \f | |
11019 | /* Macro support. */ | |
11020 | ||
11021 | ||
11022 | /* Return the full name of file number I in *LH's file name table. | |
11023 | Use COMP_DIR as the name of the current directory of the | |
11024 | compilation. The result is allocated using xmalloc; the caller is | |
11025 | responsible for freeing it. */ | |
11026 | static char * | |
11027 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
11028 | { | |
6a83a1e6 EZ |
11029 | /* Is the file number a valid index into the line header's file name |
11030 | table? Remember that file numbers start with one, not zero. */ | |
11031 | if (1 <= file && file <= lh->num_file_names) | |
11032 | { | |
11033 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 11034 | |
6a83a1e6 EZ |
11035 | if (IS_ABSOLUTE_PATH (fe->name)) |
11036 | return xstrdup (fe->name); | |
11037 | else | |
11038 | { | |
11039 | const char *dir; | |
11040 | int dir_len; | |
11041 | char *full_name; | |
11042 | ||
11043 | if (fe->dir_index) | |
11044 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11045 | else | |
11046 | dir = comp_dir; | |
11047 | ||
11048 | if (dir) | |
11049 | { | |
11050 | dir_len = strlen (dir); | |
11051 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
11052 | strcpy (full_name, dir); | |
11053 | full_name[dir_len] = '/'; | |
11054 | strcpy (full_name + dir_len + 1, fe->name); | |
11055 | return full_name; | |
11056 | } | |
11057 | else | |
11058 | return xstrdup (fe->name); | |
11059 | } | |
11060 | } | |
2e276125 JB |
11061 | else |
11062 | { | |
6a83a1e6 EZ |
11063 | /* The compiler produced a bogus file number. We can at least |
11064 | record the macro definitions made in the file, even if we | |
11065 | won't be able to find the file by name. */ | |
11066 | char fake_name[80]; | |
11067 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 11068 | |
6a83a1e6 EZ |
11069 | complaint (&symfile_complaints, |
11070 | _("bad file number in macro information (%d)"), | |
11071 | file); | |
2e276125 | 11072 | |
6a83a1e6 | 11073 | return xstrdup (fake_name); |
2e276125 JB |
11074 | } |
11075 | } | |
11076 | ||
11077 | ||
11078 | static struct macro_source_file * | |
11079 | macro_start_file (int file, int line, | |
11080 | struct macro_source_file *current_file, | |
11081 | const char *comp_dir, | |
11082 | struct line_header *lh, struct objfile *objfile) | |
11083 | { | |
11084 | /* The full name of this source file. */ | |
11085 | char *full_name = file_full_name (file, lh, comp_dir); | |
11086 | ||
11087 | /* We don't create a macro table for this compilation unit | |
11088 | at all until we actually get a filename. */ | |
11089 | if (! pending_macros) | |
4a146b47 | 11090 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 11091 | objfile->macro_cache); |
2e276125 JB |
11092 | |
11093 | if (! current_file) | |
11094 | /* If we have no current file, then this must be the start_file | |
11095 | directive for the compilation unit's main source file. */ | |
11096 | current_file = macro_set_main (pending_macros, full_name); | |
11097 | else | |
11098 | current_file = macro_include (current_file, line, full_name); | |
11099 | ||
11100 | xfree (full_name); | |
11101 | ||
11102 | return current_file; | |
11103 | } | |
11104 | ||
11105 | ||
11106 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
11107 | followed by a null byte. */ | |
11108 | static char * | |
11109 | copy_string (const char *buf, int len) | |
11110 | { | |
11111 | char *s = xmalloc (len + 1); | |
11112 | memcpy (s, buf, len); | |
11113 | s[len] = '\0'; | |
11114 | ||
11115 | return s; | |
11116 | } | |
11117 | ||
11118 | ||
11119 | static const char * | |
11120 | consume_improper_spaces (const char *p, const char *body) | |
11121 | { | |
11122 | if (*p == ' ') | |
11123 | { | |
4d3c2250 | 11124 | complaint (&symfile_complaints, |
e2e0b3e5 | 11125 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 11126 | body); |
2e276125 JB |
11127 | |
11128 | while (*p == ' ') | |
11129 | p++; | |
11130 | } | |
11131 | ||
11132 | return p; | |
11133 | } | |
11134 | ||
11135 | ||
11136 | static void | |
11137 | parse_macro_definition (struct macro_source_file *file, int line, | |
11138 | const char *body) | |
11139 | { | |
11140 | const char *p; | |
11141 | ||
11142 | /* The body string takes one of two forms. For object-like macro | |
11143 | definitions, it should be: | |
11144 | ||
11145 | <macro name> " " <definition> | |
11146 | ||
11147 | For function-like macro definitions, it should be: | |
11148 | ||
11149 | <macro name> "() " <definition> | |
11150 | or | |
11151 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
11152 | ||
11153 | Spaces may appear only where explicitly indicated, and in the | |
11154 | <definition>. | |
11155 | ||
11156 | The Dwarf 2 spec says that an object-like macro's name is always | |
11157 | followed by a space, but versions of GCC around March 2002 omit | |
11158 | the space when the macro's definition is the empty string. | |
11159 | ||
11160 | The Dwarf 2 spec says that there should be no spaces between the | |
11161 | formal arguments in a function-like macro's formal argument list, | |
11162 | but versions of GCC around March 2002 include spaces after the | |
11163 | commas. */ | |
11164 | ||
11165 | ||
11166 | /* Find the extent of the macro name. The macro name is terminated | |
11167 | by either a space or null character (for an object-like macro) or | |
11168 | an opening paren (for a function-like macro). */ | |
11169 | for (p = body; *p; p++) | |
11170 | if (*p == ' ' || *p == '(') | |
11171 | break; | |
11172 | ||
11173 | if (*p == ' ' || *p == '\0') | |
11174 | { | |
11175 | /* It's an object-like macro. */ | |
11176 | int name_len = p - body; | |
11177 | char *name = copy_string (body, name_len); | |
11178 | const char *replacement; | |
11179 | ||
11180 | if (*p == ' ') | |
11181 | replacement = body + name_len + 1; | |
11182 | else | |
11183 | { | |
4d3c2250 | 11184 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11185 | replacement = body + name_len; |
11186 | } | |
11187 | ||
11188 | macro_define_object (file, line, name, replacement); | |
11189 | ||
11190 | xfree (name); | |
11191 | } | |
11192 | else if (*p == '(') | |
11193 | { | |
11194 | /* It's a function-like macro. */ | |
11195 | char *name = copy_string (body, p - body); | |
11196 | int argc = 0; | |
11197 | int argv_size = 1; | |
11198 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
11199 | ||
11200 | p++; | |
11201 | ||
11202 | p = consume_improper_spaces (p, body); | |
11203 | ||
11204 | /* Parse the formal argument list. */ | |
11205 | while (*p && *p != ')') | |
11206 | { | |
11207 | /* Find the extent of the current argument name. */ | |
11208 | const char *arg_start = p; | |
11209 | ||
11210 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
11211 | p++; | |
11212 | ||
11213 | if (! *p || p == arg_start) | |
4d3c2250 | 11214 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11215 | else |
11216 | { | |
11217 | /* Make sure argv has room for the new argument. */ | |
11218 | if (argc >= argv_size) | |
11219 | { | |
11220 | argv_size *= 2; | |
11221 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
11222 | } | |
11223 | ||
11224 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
11225 | } | |
11226 | ||
11227 | p = consume_improper_spaces (p, body); | |
11228 | ||
11229 | /* Consume the comma, if present. */ | |
11230 | if (*p == ',') | |
11231 | { | |
11232 | p++; | |
11233 | ||
11234 | p = consume_improper_spaces (p, body); | |
11235 | } | |
11236 | } | |
11237 | ||
11238 | if (*p == ')') | |
11239 | { | |
11240 | p++; | |
11241 | ||
11242 | if (*p == ' ') | |
11243 | /* Perfectly formed definition, no complaints. */ | |
11244 | macro_define_function (file, line, name, | |
11245 | argc, (const char **) argv, | |
11246 | p + 1); | |
11247 | else if (*p == '\0') | |
11248 | { | |
11249 | /* Complain, but do define it. */ | |
4d3c2250 | 11250 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11251 | macro_define_function (file, line, name, |
11252 | argc, (const char **) argv, | |
11253 | p); | |
11254 | } | |
11255 | else | |
11256 | /* Just complain. */ | |
4d3c2250 | 11257 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11258 | } |
11259 | else | |
11260 | /* Just complain. */ | |
4d3c2250 | 11261 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11262 | |
11263 | xfree (name); | |
11264 | { | |
11265 | int i; | |
11266 | ||
11267 | for (i = 0; i < argc; i++) | |
11268 | xfree (argv[i]); | |
11269 | } | |
11270 | xfree (argv); | |
11271 | } | |
11272 | else | |
4d3c2250 | 11273 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11274 | } |
11275 | ||
11276 | ||
11277 | static void | |
11278 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
11279 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 11280 | struct dwarf2_cu *cu) |
2e276125 | 11281 | { |
fe1b8b76 | 11282 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 11283 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
11284 | enum dwarf_macinfo_record_type macinfo_type; |
11285 | int at_commandline; | |
2e276125 | 11286 | |
be391dca TT |
11287 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
11288 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 11289 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 11290 | { |
e2e0b3e5 | 11291 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
11292 | return; |
11293 | } | |
11294 | ||
757a13d0 JK |
11295 | /* First pass: Find the name of the base filename. |
11296 | This filename is needed in order to process all macros whose definition | |
11297 | (or undefinition) comes from the command line. These macros are defined | |
11298 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
11299 | associated to the base file. | |
11300 | ||
11301 | To determine the base file name, we scan the macro definitions until we | |
11302 | reach the first DW_MACINFO_start_file entry. We then initialize | |
11303 | CURRENT_FILE accordingly so that any macro definition found before the | |
11304 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
11305 | ||
dce234bc PP |
11306 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
11307 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
11308 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 11309 | |
757a13d0 | 11310 | do |
2e276125 | 11311 | { |
2e276125 JB |
11312 | /* Do we at least have room for a macinfo type byte? */ |
11313 | if (mac_ptr >= mac_end) | |
11314 | { | |
757a13d0 JK |
11315 | /* Complaint is printed during the second pass as GDB will probably |
11316 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
11317 | break; | |
2e276125 JB |
11318 | } |
11319 | ||
11320 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11321 | mac_ptr++; | |
11322 | ||
11323 | switch (macinfo_type) | |
11324 | { | |
11325 | /* A zero macinfo type indicates the end of the macro | |
11326 | information. */ | |
11327 | case 0: | |
757a13d0 JK |
11328 | break; |
11329 | ||
11330 | case DW_MACINFO_define: | |
11331 | case DW_MACINFO_undef: | |
11332 | /* Only skip the data by MAC_PTR. */ | |
11333 | { | |
11334 | unsigned int bytes_read; | |
11335 | ||
11336 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11337 | mac_ptr += bytes_read; | |
11338 | read_string (abfd, mac_ptr, &bytes_read); | |
11339 | mac_ptr += bytes_read; | |
11340 | } | |
11341 | break; | |
11342 | ||
11343 | case DW_MACINFO_start_file: | |
11344 | { | |
11345 | unsigned int bytes_read; | |
11346 | int line, file; | |
11347 | ||
11348 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11349 | mac_ptr += bytes_read; | |
11350 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11351 | mac_ptr += bytes_read; | |
11352 | ||
11353 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
11354 | lh, cu->objfile); | |
11355 | } | |
11356 | break; | |
11357 | ||
11358 | case DW_MACINFO_end_file: | |
11359 | /* No data to skip by MAC_PTR. */ | |
11360 | break; | |
11361 | ||
11362 | case DW_MACINFO_vendor_ext: | |
11363 | /* Only skip the data by MAC_PTR. */ | |
11364 | { | |
11365 | unsigned int bytes_read; | |
11366 | ||
11367 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11368 | mac_ptr += bytes_read; | |
11369 | read_string (abfd, mac_ptr, &bytes_read); | |
11370 | mac_ptr += bytes_read; | |
11371 | } | |
11372 | break; | |
11373 | ||
11374 | default: | |
11375 | break; | |
11376 | } | |
11377 | } while (macinfo_type != 0 && current_file == NULL); | |
11378 | ||
11379 | /* Second pass: Process all entries. | |
11380 | ||
11381 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
11382 | command-line macro definitions/undefinitions. This flag is unset when we | |
11383 | reach the first DW_MACINFO_start_file entry. */ | |
11384 | ||
dce234bc | 11385 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
11386 | |
11387 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
11388 | GDB is still reading the definitions from command line. First | |
11389 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
11390 | to create CURRENT_FILE for the main source holding also the command line | |
11391 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
11392 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
11393 | ||
11394 | at_commandline = 1; | |
11395 | ||
11396 | do | |
11397 | { | |
11398 | /* Do we at least have room for a macinfo type byte? */ | |
11399 | if (mac_ptr >= mac_end) | |
11400 | { | |
11401 | dwarf2_macros_too_long_complaint (); | |
11402 | break; | |
11403 | } | |
11404 | ||
11405 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11406 | mac_ptr++; | |
11407 | ||
11408 | switch (macinfo_type) | |
11409 | { | |
11410 | /* A zero macinfo type indicates the end of the macro | |
11411 | information. */ | |
11412 | case 0: | |
11413 | break; | |
2e276125 JB |
11414 | |
11415 | case DW_MACINFO_define: | |
11416 | case DW_MACINFO_undef: | |
11417 | { | |
891d2f0b | 11418 | unsigned int bytes_read; |
2e276125 JB |
11419 | int line; |
11420 | char *body; | |
11421 | ||
11422 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11423 | mac_ptr += bytes_read; | |
11424 | body = read_string (abfd, mac_ptr, &bytes_read); | |
11425 | mac_ptr += bytes_read; | |
11426 | ||
11427 | if (! current_file) | |
757a13d0 JK |
11428 | { |
11429 | /* DWARF violation as no main source is present. */ | |
11430 | complaint (&symfile_complaints, | |
11431 | _("debug info with no main source gives macro %s " | |
11432 | "on line %d: %s"), | |
905e0470 PM |
11433 | macinfo_type == DW_MACINFO_define ? |
11434 | _("definition") : | |
11435 | macinfo_type == DW_MACINFO_undef ? | |
11436 | _("undefinition") : | |
11437 | _("something-or-other"), line, body); | |
757a13d0 JK |
11438 | break; |
11439 | } | |
11440 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 11441 | complaint (&symfile_complaints, |
757a13d0 JK |
11442 | _("debug info gives %s macro %s with %s line %d: %s"), |
11443 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 PM |
11444 | macinfo_type == DW_MACINFO_define ? |
11445 | _("definition") : | |
11446 | macinfo_type == DW_MACINFO_undef ? | |
11447 | _("undefinition") : | |
11448 | _("something-or-other"), | |
757a13d0 JK |
11449 | line == 0 ? _("zero") : _("non-zero"), line, body); |
11450 | ||
11451 | if (macinfo_type == DW_MACINFO_define) | |
11452 | parse_macro_definition (current_file, line, body); | |
11453 | else if (macinfo_type == DW_MACINFO_undef) | |
11454 | macro_undef (current_file, line, body); | |
2e276125 JB |
11455 | } |
11456 | break; | |
11457 | ||
11458 | case DW_MACINFO_start_file: | |
11459 | { | |
891d2f0b | 11460 | unsigned int bytes_read; |
2e276125 JB |
11461 | int line, file; |
11462 | ||
11463 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11464 | mac_ptr += bytes_read; | |
11465 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11466 | mac_ptr += bytes_read; | |
11467 | ||
757a13d0 JK |
11468 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
11469 | complaint (&symfile_complaints, | |
11470 | _("debug info gives source %d included " | |
11471 | "from %s at %s line %d"), | |
11472 | file, at_commandline ? _("command-line") : _("file"), | |
11473 | line == 0 ? _("zero") : _("non-zero"), line); | |
11474 | ||
11475 | if (at_commandline) | |
11476 | { | |
11477 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
11478 | at_commandline = 0; | |
11479 | } | |
11480 | else | |
11481 | current_file = macro_start_file (file, line, | |
11482 | current_file, comp_dir, | |
11483 | lh, cu->objfile); | |
2e276125 JB |
11484 | } |
11485 | break; | |
11486 | ||
11487 | case DW_MACINFO_end_file: | |
11488 | if (! current_file) | |
4d3c2250 | 11489 | complaint (&symfile_complaints, |
e2e0b3e5 | 11490 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
11491 | else |
11492 | { | |
11493 | current_file = current_file->included_by; | |
11494 | if (! current_file) | |
11495 | { | |
11496 | enum dwarf_macinfo_record_type next_type; | |
11497 | ||
11498 | /* GCC circa March 2002 doesn't produce the zero | |
11499 | type byte marking the end of the compilation | |
11500 | unit. Complain if it's not there, but exit no | |
11501 | matter what. */ | |
11502 | ||
11503 | /* Do we at least have room for a macinfo type byte? */ | |
11504 | if (mac_ptr >= mac_end) | |
11505 | { | |
4d3c2250 | 11506 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
11507 | return; |
11508 | } | |
11509 | ||
11510 | /* We don't increment mac_ptr here, so this is just | |
11511 | a look-ahead. */ | |
11512 | next_type = read_1_byte (abfd, mac_ptr); | |
11513 | if (next_type != 0) | |
4d3c2250 | 11514 | complaint (&symfile_complaints, |
e2e0b3e5 | 11515 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
11516 | |
11517 | return; | |
11518 | } | |
11519 | } | |
11520 | break; | |
11521 | ||
11522 | case DW_MACINFO_vendor_ext: | |
11523 | { | |
891d2f0b | 11524 | unsigned int bytes_read; |
2e276125 JB |
11525 | int constant; |
11526 | char *string; | |
11527 | ||
11528 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11529 | mac_ptr += bytes_read; | |
11530 | string = read_string (abfd, mac_ptr, &bytes_read); | |
11531 | mac_ptr += bytes_read; | |
11532 | ||
11533 | /* We don't recognize any vendor extensions. */ | |
11534 | } | |
11535 | break; | |
11536 | } | |
757a13d0 | 11537 | } while (macinfo_type != 0); |
2e276125 | 11538 | } |
8e19ed76 PS |
11539 | |
11540 | /* Check if the attribute's form is a DW_FORM_block* | |
11541 | if so return true else false. */ | |
11542 | static int | |
11543 | attr_form_is_block (struct attribute *attr) | |
11544 | { | |
11545 | return (attr == NULL ? 0 : | |
11546 | attr->form == DW_FORM_block1 | |
11547 | || attr->form == DW_FORM_block2 | |
11548 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
11549 | || attr->form == DW_FORM_block |
11550 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 11551 | } |
4c2df51b | 11552 | |
c6a0999f JB |
11553 | /* Return non-zero if ATTR's value is a section offset --- classes |
11554 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
11555 | You may use DW_UNSND (attr) to retrieve such offsets. | |
11556 | ||
11557 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
11558 | may have a value that belongs to more than one of these classes; it | |
11559 | would be ambiguous if we did, because we use the same forms for all | |
11560 | of them. */ | |
3690dd37 JB |
11561 | static int |
11562 | attr_form_is_section_offset (struct attribute *attr) | |
11563 | { | |
11564 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
11565 | || attr->form == DW_FORM_data8 |
11566 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
11567 | } |
11568 | ||
11569 | ||
11570 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
11571 | zero otherwise. When this function returns true, you can apply | |
11572 | dwarf2_get_attr_constant_value to it. | |
11573 | ||
11574 | However, note that for some attributes you must check | |
11575 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
11576 | and DW_FORM_data8 are members of both the constant class, and of | |
11577 | the classes that contain offsets into other debug sections | |
11578 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
11579 | that, if an attribute's can be either a constant or one of the | |
11580 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
11581 | taken as section offsets, not constants. */ | |
11582 | static int | |
11583 | attr_form_is_constant (struct attribute *attr) | |
11584 | { | |
11585 | switch (attr->form) | |
11586 | { | |
11587 | case DW_FORM_sdata: | |
11588 | case DW_FORM_udata: | |
11589 | case DW_FORM_data1: | |
11590 | case DW_FORM_data2: | |
11591 | case DW_FORM_data4: | |
11592 | case DW_FORM_data8: | |
11593 | return 1; | |
11594 | default: | |
11595 | return 0; | |
11596 | } | |
11597 | } | |
11598 | ||
4c2df51b DJ |
11599 | static void |
11600 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11601 | struct dwarf2_cu *cu) |
4c2df51b | 11602 | { |
3690dd37 | 11603 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
11604 | /* ".debug_loc" may not exist at all, or the offset may be outside |
11605 | the section. If so, fall through to the complaint in the | |
11606 | other branch. */ | |
dce234bc | 11607 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 11608 | { |
0d53c4c4 | 11609 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 11610 | |
4a146b47 | 11611 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11612 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
11613 | baton->per_cu = cu->per_cu; |
11614 | gdb_assert (baton->per_cu); | |
4c2df51b | 11615 | |
be391dca TT |
11616 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
11617 | &dwarf2_per_objfile->loc); | |
11618 | ||
0d53c4c4 DJ |
11619 | /* We don't know how long the location list is, but make sure we |
11620 | don't run off the edge of the section. */ | |
dce234bc PP |
11621 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
11622 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
11623 | baton->base_address = cu->base_address; |
11624 | if (cu->base_known == 0) | |
0d53c4c4 | 11625 | complaint (&symfile_complaints, |
e2e0b3e5 | 11626 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 11627 | |
768a979c | 11628 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
11629 | SYMBOL_LOCATION_BATON (sym) = baton; |
11630 | } | |
11631 | else | |
11632 | { | |
11633 | struct dwarf2_locexpr_baton *baton; | |
11634 | ||
4a146b47 | 11635 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11636 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
11637 | baton->per_cu = cu->per_cu; |
11638 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
11639 | |
11640 | if (attr_form_is_block (attr)) | |
11641 | { | |
11642 | /* Note that we're just copying the block's data pointer | |
11643 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
11644 | info_buffer for SYM's objfile; right now we never release |
11645 | that buffer, but when we do clean up properly this may | |
11646 | need to change. */ | |
0d53c4c4 DJ |
11647 | baton->size = DW_BLOCK (attr)->size; |
11648 | baton->data = DW_BLOCK (attr)->data; | |
11649 | } | |
11650 | else | |
11651 | { | |
11652 | dwarf2_invalid_attrib_class_complaint ("location description", | |
11653 | SYMBOL_NATURAL_NAME (sym)); | |
11654 | baton->size = 0; | |
11655 | baton->data = NULL; | |
11656 | } | |
11657 | ||
768a979c | 11658 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
11659 | SYMBOL_LOCATION_BATON (sym) = baton; |
11660 | } | |
4c2df51b | 11661 | } |
6502dd73 | 11662 | |
ae0d2f24 UW |
11663 | /* Return the OBJFILE associated with the compilation unit CU. */ |
11664 | ||
11665 | struct objfile * | |
11666 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
11667 | { | |
11668 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11669 | ||
11670 | /* Return the master objfile, so that we can report and look up the | |
11671 | correct file containing this variable. */ | |
11672 | if (objfile->separate_debug_objfile_backlink) | |
11673 | objfile = objfile->separate_debug_objfile_backlink; | |
11674 | ||
11675 | return objfile; | |
11676 | } | |
11677 | ||
11678 | /* Return the address size given in the compilation unit header for CU. */ | |
11679 | ||
11680 | CORE_ADDR | |
11681 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
11682 | { | |
11683 | if (per_cu->cu) | |
11684 | return per_cu->cu->header.addr_size; | |
11685 | else | |
11686 | { | |
11687 | /* If the CU is not currently read in, we re-read its header. */ | |
11688 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11689 | struct dwarf2_per_objfile *per_objfile | |
11690 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 11691 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 UW |
11692 | |
11693 | struct comp_unit_head cu_header; | |
11694 | memset (&cu_header, 0, sizeof cu_header); | |
11695 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
11696 | return cu_header.addr_size; | |
11697 | } | |
11698 | } | |
11699 | ||
348e048f DE |
11700 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
11701 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
11702 | |
11703 | static struct dwarf2_per_cu_data * | |
c764a876 | 11704 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
11705 | struct objfile *objfile) |
11706 | { | |
11707 | struct dwarf2_per_cu_data *this_cu; | |
11708 | int low, high; | |
11709 | ||
ae038cb0 DJ |
11710 | low = 0; |
11711 | high = dwarf2_per_objfile->n_comp_units - 1; | |
11712 | while (high > low) | |
11713 | { | |
11714 | int mid = low + (high - low) / 2; | |
11715 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
11716 | high = mid; | |
11717 | else | |
11718 | low = mid + 1; | |
11719 | } | |
11720 | gdb_assert (low == high); | |
11721 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
11722 | { | |
10b3939b | 11723 | if (low == 0) |
8a3fe4f8 AC |
11724 | error (_("Dwarf Error: could not find partial DIE containing " |
11725 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
11726 | (long) offset, bfd_get_filename (objfile->obfd)); |
11727 | ||
ae038cb0 DJ |
11728 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
11729 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
11730 | } | |
11731 | else | |
11732 | { | |
11733 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
11734 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
11735 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 11736 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
11737 | gdb_assert (offset < this_cu->offset + this_cu->length); |
11738 | return this_cu; | |
11739 | } | |
11740 | } | |
11741 | ||
10b3939b DJ |
11742 | /* Locate the compilation unit from OBJFILE which is located at exactly |
11743 | OFFSET. Raises an error on failure. */ | |
11744 | ||
ae038cb0 | 11745 | static struct dwarf2_per_cu_data * |
c764a876 | 11746 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
11747 | { |
11748 | struct dwarf2_per_cu_data *this_cu; | |
11749 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
11750 | if (this_cu->offset != offset) | |
c764a876 | 11751 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
11752 | return this_cu; |
11753 | } | |
11754 | ||
93311388 DE |
11755 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
11756 | ||
11757 | static struct dwarf2_cu * | |
11758 | alloc_one_comp_unit (struct objfile *objfile) | |
11759 | { | |
11760 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
11761 | cu->objfile = objfile; | |
11762 | obstack_init (&cu->comp_unit_obstack); | |
11763 | return cu; | |
11764 | } | |
11765 | ||
ae038cb0 DJ |
11766 | /* Release one cached compilation unit, CU. We unlink it from the tree |
11767 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
11768 | the caller is responsible for that. |
11769 | NOTE: DATA is a void * because this function is also used as a | |
11770 | cleanup routine. */ | |
ae038cb0 DJ |
11771 | |
11772 | static void | |
11773 | free_one_comp_unit (void *data) | |
11774 | { | |
11775 | struct dwarf2_cu *cu = data; | |
11776 | ||
11777 | if (cu->per_cu != NULL) | |
11778 | cu->per_cu->cu = NULL; | |
11779 | cu->per_cu = NULL; | |
11780 | ||
11781 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11782 | ||
11783 | xfree (cu); | |
11784 | } | |
11785 | ||
72bf9492 | 11786 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
11787 | when we're finished with it. We can't free the pointer itself, but be |
11788 | sure to unlink it from the cache. Also release any associated storage | |
11789 | and perform cache maintenance. | |
72bf9492 DJ |
11790 | |
11791 | Only used during partial symbol parsing. */ | |
11792 | ||
11793 | static void | |
11794 | free_stack_comp_unit (void *data) | |
11795 | { | |
11796 | struct dwarf2_cu *cu = data; | |
11797 | ||
11798 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11799 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
11800 | |
11801 | if (cu->per_cu != NULL) | |
11802 | { | |
11803 | /* This compilation unit is on the stack in our caller, so we | |
11804 | should not xfree it. Just unlink it. */ | |
11805 | cu->per_cu->cu = NULL; | |
11806 | cu->per_cu = NULL; | |
11807 | ||
11808 | /* If we had a per-cu pointer, then we may have other compilation | |
11809 | units loaded, so age them now. */ | |
11810 | age_cached_comp_units (); | |
11811 | } | |
11812 | } | |
11813 | ||
11814 | /* Free all cached compilation units. */ | |
11815 | ||
11816 | static void | |
11817 | free_cached_comp_units (void *data) | |
11818 | { | |
11819 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11820 | ||
11821 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11822 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11823 | while (per_cu != NULL) | |
11824 | { | |
11825 | struct dwarf2_per_cu_data *next_cu; | |
11826 | ||
11827 | next_cu = per_cu->cu->read_in_chain; | |
11828 | ||
11829 | free_one_comp_unit (per_cu->cu); | |
11830 | *last_chain = next_cu; | |
11831 | ||
11832 | per_cu = next_cu; | |
11833 | } | |
11834 | } | |
11835 | ||
11836 | /* Increase the age counter on each cached compilation unit, and free | |
11837 | any that are too old. */ | |
11838 | ||
11839 | static void | |
11840 | age_cached_comp_units (void) | |
11841 | { | |
11842 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11843 | ||
11844 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
11845 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11846 | while (per_cu != NULL) | |
11847 | { | |
11848 | per_cu->cu->last_used ++; | |
11849 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
11850 | dwarf2_mark (per_cu->cu); | |
11851 | per_cu = per_cu->cu->read_in_chain; | |
11852 | } | |
11853 | ||
11854 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11855 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11856 | while (per_cu != NULL) | |
11857 | { | |
11858 | struct dwarf2_per_cu_data *next_cu; | |
11859 | ||
11860 | next_cu = per_cu->cu->read_in_chain; | |
11861 | ||
11862 | if (!per_cu->cu->mark) | |
11863 | { | |
11864 | free_one_comp_unit (per_cu->cu); | |
11865 | *last_chain = next_cu; | |
11866 | } | |
11867 | else | |
11868 | last_chain = &per_cu->cu->read_in_chain; | |
11869 | ||
11870 | per_cu = next_cu; | |
11871 | } | |
11872 | } | |
11873 | ||
11874 | /* Remove a single compilation unit from the cache. */ | |
11875 | ||
11876 | static void | |
11877 | free_one_cached_comp_unit (void *target_cu) | |
11878 | { | |
11879 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11880 | ||
11881 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11882 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11883 | while (per_cu != NULL) | |
11884 | { | |
11885 | struct dwarf2_per_cu_data *next_cu; | |
11886 | ||
11887 | next_cu = per_cu->cu->read_in_chain; | |
11888 | ||
11889 | if (per_cu->cu == target_cu) | |
11890 | { | |
11891 | free_one_comp_unit (per_cu->cu); | |
11892 | *last_chain = next_cu; | |
11893 | break; | |
11894 | } | |
11895 | else | |
11896 | last_chain = &per_cu->cu->read_in_chain; | |
11897 | ||
11898 | per_cu = next_cu; | |
11899 | } | |
11900 | } | |
11901 | ||
fe3e1990 DJ |
11902 | /* Release all extra memory associated with OBJFILE. */ |
11903 | ||
11904 | void | |
11905 | dwarf2_free_objfile (struct objfile *objfile) | |
11906 | { | |
11907 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
11908 | ||
11909 | if (dwarf2_per_objfile == NULL) | |
11910 | return; | |
11911 | ||
11912 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
11913 | free_cached_comp_units (NULL); | |
11914 | ||
11915 | /* Everything else should be on the objfile obstack. */ | |
11916 | } | |
11917 | ||
1c379e20 DJ |
11918 | /* A pair of DIE offset and GDB type pointer. We store these |
11919 | in a hash table separate from the DIEs, and preserve them | |
11920 | when the DIEs are flushed out of cache. */ | |
11921 | ||
11922 | struct dwarf2_offset_and_type | |
11923 | { | |
11924 | unsigned int offset; | |
11925 | struct type *type; | |
11926 | }; | |
11927 | ||
11928 | /* Hash function for a dwarf2_offset_and_type. */ | |
11929 | ||
11930 | static hashval_t | |
11931 | offset_and_type_hash (const void *item) | |
11932 | { | |
11933 | const struct dwarf2_offset_and_type *ofs = item; | |
11934 | return ofs->offset; | |
11935 | } | |
11936 | ||
11937 | /* Equality function for a dwarf2_offset_and_type. */ | |
11938 | ||
11939 | static int | |
11940 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
11941 | { | |
11942 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
11943 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
11944 | return ofs_lhs->offset == ofs_rhs->offset; | |
11945 | } | |
11946 | ||
11947 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 11948 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 11949 | |
f792889a | 11950 | static struct type * |
1c379e20 DJ |
11951 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
11952 | { | |
11953 | struct dwarf2_offset_and_type **slot, ofs; | |
11954 | ||
b4ba55a1 JB |
11955 | /* For Ada types, make sure that the gnat-specific data is always |
11956 | initialized (if not already set). There are a few types where | |
11957 | we should not be doing so, because the type-specific area is | |
11958 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
11959 | where the type-specific area is used to store the floatformat). | |
11960 | But this is not a problem, because the gnat-specific information | |
11961 | is actually not needed for these types. */ | |
11962 | if (need_gnat_info (cu) | |
11963 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
11964 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
11965 | && !HAVE_GNAT_AUX_INFO (type)) | |
11966 | INIT_GNAT_SPECIFIC (type); | |
11967 | ||
f792889a DJ |
11968 | if (cu->type_hash == NULL) |
11969 | { | |
11970 | gdb_assert (cu->per_cu != NULL); | |
11971 | cu->per_cu->type_hash | |
11972 | = htab_create_alloc_ex (cu->header.length / 24, | |
11973 | offset_and_type_hash, | |
11974 | offset_and_type_eq, | |
11975 | NULL, | |
11976 | &cu->objfile->objfile_obstack, | |
11977 | hashtab_obstack_allocate, | |
11978 | dummy_obstack_deallocate); | |
11979 | cu->type_hash = cu->per_cu->type_hash; | |
11980 | } | |
1c379e20 DJ |
11981 | |
11982 | ofs.offset = die->offset; | |
11983 | ofs.type = type; | |
11984 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 11985 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
11986 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
11987 | **slot = ofs; | |
f792889a | 11988 | return type; |
1c379e20 DJ |
11989 | } |
11990 | ||
f792889a DJ |
11991 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
11992 | not have a saved type. */ | |
1c379e20 DJ |
11993 | |
11994 | static struct type * | |
f792889a | 11995 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
11996 | { |
11997 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
11998 | htab_t type_hash = cu->type_hash; |
11999 | ||
12000 | if (type_hash == NULL) | |
12001 | return NULL; | |
1c379e20 DJ |
12002 | |
12003 | ofs.offset = die->offset; | |
12004 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
12005 | if (slot) | |
12006 | return slot->type; | |
12007 | else | |
12008 | return NULL; | |
12009 | } | |
12010 | ||
10b3939b DJ |
12011 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
12012 | ||
12013 | static void | |
12014 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
12015 | struct dwarf2_per_cu_data *ref_per_cu) | |
12016 | { | |
12017 | void **slot; | |
12018 | ||
12019 | if (cu->dependencies == NULL) | |
12020 | cu->dependencies | |
12021 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
12022 | NULL, &cu->comp_unit_obstack, | |
12023 | hashtab_obstack_allocate, | |
12024 | dummy_obstack_deallocate); | |
12025 | ||
12026 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
12027 | if (*slot == NULL) | |
12028 | *slot = ref_per_cu; | |
12029 | } | |
1c379e20 | 12030 | |
f504f079 DE |
12031 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
12032 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
12033 | cache that we must keep because we are keeping CU. */ |
12034 | ||
10b3939b DJ |
12035 | static int |
12036 | dwarf2_mark_helper (void **slot, void *data) | |
12037 | { | |
12038 | struct dwarf2_per_cu_data *per_cu; | |
12039 | ||
12040 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
12041 | if (per_cu->cu->mark) | |
12042 | return 1; | |
12043 | per_cu->cu->mark = 1; | |
12044 | ||
12045 | if (per_cu->cu->dependencies != NULL) | |
12046 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
12047 | ||
12048 | return 1; | |
12049 | } | |
12050 | ||
f504f079 DE |
12051 | /* Set the mark field in CU and in every other compilation unit in the |
12052 | cache that we must keep because we are keeping CU. */ | |
12053 | ||
ae038cb0 DJ |
12054 | static void |
12055 | dwarf2_mark (struct dwarf2_cu *cu) | |
12056 | { | |
12057 | if (cu->mark) | |
12058 | return; | |
12059 | cu->mark = 1; | |
10b3939b DJ |
12060 | if (cu->dependencies != NULL) |
12061 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
12062 | } |
12063 | ||
12064 | static void | |
12065 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
12066 | { | |
12067 | while (per_cu) | |
12068 | { | |
12069 | per_cu->cu->mark = 0; | |
12070 | per_cu = per_cu->cu->read_in_chain; | |
12071 | } | |
72bf9492 DJ |
12072 | } |
12073 | ||
72bf9492 DJ |
12074 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
12075 | is its offset in .debug_info for this objfile. */ | |
12076 | ||
12077 | static hashval_t | |
12078 | partial_die_hash (const void *item) | |
12079 | { | |
12080 | const struct partial_die_info *part_die = item; | |
12081 | return part_die->offset; | |
12082 | } | |
12083 | ||
12084 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
12085 | are equal if they have the same offset. */ | |
12086 | ||
12087 | static int | |
12088 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
12089 | { | |
12090 | const struct partial_die_info *part_die_lhs = item_lhs; | |
12091 | const struct partial_die_info *part_die_rhs = item_rhs; | |
12092 | return part_die_lhs->offset == part_die_rhs->offset; | |
12093 | } | |
12094 | ||
ae038cb0 DJ |
12095 | static struct cmd_list_element *set_dwarf2_cmdlist; |
12096 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
12097 | ||
12098 | static void | |
12099 | set_dwarf2_cmd (char *args, int from_tty) | |
12100 | { | |
12101 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
12102 | } | |
12103 | ||
12104 | static void | |
12105 | show_dwarf2_cmd (char *args, int from_tty) | |
12106 | { | |
12107 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
12108 | } | |
12109 | ||
dce234bc PP |
12110 | /* If section described by INFO was mmapped, munmap it now. */ |
12111 | ||
12112 | static void | |
12113 | munmap_section_buffer (struct dwarf2_section_info *info) | |
12114 | { | |
12115 | if (info->was_mmapped) | |
12116 | { | |
12117 | #ifdef HAVE_MMAP | |
12118 | intptr_t begin = (intptr_t) info->buffer; | |
12119 | intptr_t map_begin = begin & ~(pagesize - 1); | |
12120 | size_t map_length = info->size + begin - map_begin; | |
12121 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); | |
12122 | #else | |
12123 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
12124 | gdb_assert (0); | |
12125 | #endif | |
12126 | } | |
12127 | } | |
12128 | ||
12129 | /* munmap debug sections for OBJFILE, if necessary. */ | |
12130 | ||
12131 | static void | |
c1bd65d0 | 12132 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
12133 | { |
12134 | struct dwarf2_per_objfile *data = d; | |
12135 | munmap_section_buffer (&data->info); | |
12136 | munmap_section_buffer (&data->abbrev); | |
12137 | munmap_section_buffer (&data->line); | |
12138 | munmap_section_buffer (&data->str); | |
12139 | munmap_section_buffer (&data->macinfo); | |
12140 | munmap_section_buffer (&data->ranges); | |
12141 | munmap_section_buffer (&data->loc); | |
12142 | munmap_section_buffer (&data->frame); | |
12143 | munmap_section_buffer (&data->eh_frame); | |
12144 | } | |
12145 | ||
6502dd73 DJ |
12146 | void _initialize_dwarf2_read (void); |
12147 | ||
12148 | void | |
12149 | _initialize_dwarf2_read (void) | |
12150 | { | |
dce234bc | 12151 | dwarf2_objfile_data_key |
c1bd65d0 | 12152 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 12153 | |
1bedd215 AC |
12154 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
12155 | Set DWARF 2 specific variables.\n\ | |
12156 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
12157 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
12158 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
12159 | ||
1bedd215 AC |
12160 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
12161 | Show DWARF 2 specific variables\n\ | |
12162 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
12163 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
12164 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
12165 | ||
12166 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
12167 | &dwarf2_max_cache_age, _("\ |
12168 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
12169 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
12170 | A higher limit means that cached compilation units will be stored\n\ | |
12171 | in memory longer, and more total memory will be used. Zero disables\n\ | |
12172 | caching, which can slow down startup."), | |
2c5b56ce | 12173 | NULL, |
920d2a44 | 12174 | show_dwarf2_max_cache_age, |
2c5b56ce | 12175 | &set_dwarf2_cmdlist, |
ae038cb0 | 12176 | &show_dwarf2_cmdlist); |
d97bc12b DE |
12177 | |
12178 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ | |
12179 | Set debugging of the dwarf2 DIE reader."), _("\ | |
12180 | Show debugging of the dwarf2 DIE reader."), _("\ | |
12181 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
12182 | The value is the maximum depth to print."), | |
12183 | NULL, | |
12184 | NULL, | |
12185 | &setdebuglist, &showdebuglist); | |
6502dd73 | 12186 | } |