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" | |
4c2df51b | 53 | |
c906108c SS |
54 | #include <fcntl.h> |
55 | #include "gdb_string.h" | |
4bdf3d34 | 56 | #include "gdb_assert.h" |
c906108c | 57 | #include <sys/types.h> |
233a11ab CS |
58 | #ifdef HAVE_ZLIB_H |
59 | #include <zlib.h> | |
60 | #endif | |
dce234bc PP |
61 | #ifdef HAVE_MMAP |
62 | #include <sys/mman.h> | |
85d9bd0e TT |
63 | #ifndef MAP_FAILED |
64 | #define MAP_FAILED ((void *) -1) | |
65 | #endif | |
dce234bc | 66 | #endif |
d8151005 | 67 | |
107d2387 | 68 | #if 0 |
357e46e7 | 69 | /* .debug_info header for a compilation unit |
c906108c SS |
70 | Because of alignment constraints, this structure has padding and cannot |
71 | be mapped directly onto the beginning of the .debug_info section. */ | |
72 | typedef struct comp_unit_header | |
73 | { | |
74 | unsigned int length; /* length of the .debug_info | |
75 | contribution */ | |
76 | unsigned short version; /* version number -- 2 for DWARF | |
77 | version 2 */ | |
78 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
79 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
80 | } | |
81 | _COMP_UNIT_HEADER; | |
82 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 83 | #endif |
c906108c SS |
84 | |
85 | /* .debug_pubnames header | |
86 | Because of alignment constraints, this structure has padding and cannot | |
87 | be mapped directly onto the beginning of the .debug_info section. */ | |
88 | typedef struct pubnames_header | |
89 | { | |
90 | unsigned int length; /* length of the .debug_pubnames | |
91 | contribution */ | |
92 | unsigned char version; /* version number -- 2 for DWARF | |
93 | version 2 */ | |
94 | unsigned int info_offset; /* offset into .debug_info section */ | |
95 | unsigned int info_size; /* byte size of .debug_info section | |
96 | portion */ | |
97 | } | |
98 | _PUBNAMES_HEADER; | |
99 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
100 | ||
101 | /* .debug_pubnames header | |
102 | Because of alignment constraints, this structure has padding and cannot | |
103 | be mapped directly onto the beginning of the .debug_info section. */ | |
104 | typedef struct aranges_header | |
105 | { | |
106 | unsigned int length; /* byte len of the .debug_aranges | |
107 | contribution */ | |
108 | unsigned short version; /* version number -- 2 for DWARF | |
109 | version 2 */ | |
110 | unsigned int info_offset; /* offset into .debug_info section */ | |
111 | unsigned char addr_size; /* byte size of an address */ | |
112 | unsigned char seg_size; /* byte size of segment descriptor */ | |
113 | } | |
114 | _ARANGES_HEADER; | |
115 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
116 | ||
117 | /* .debug_line statement program prologue | |
118 | Because of alignment constraints, this structure has padding and cannot | |
119 | be mapped directly onto the beginning of the .debug_info section. */ | |
120 | typedef struct statement_prologue | |
121 | { | |
122 | unsigned int total_length; /* byte length of the statement | |
123 | information */ | |
124 | unsigned short version; /* version number -- 2 for DWARF | |
125 | version 2 */ | |
126 | unsigned int prologue_length; /* # bytes between prologue & | |
127 | stmt program */ | |
128 | unsigned char minimum_instruction_length; /* byte size of | |
129 | smallest instr */ | |
130 | unsigned char default_is_stmt; /* initial value of is_stmt | |
131 | register */ | |
132 | char line_base; | |
133 | unsigned char line_range; | |
134 | unsigned char opcode_base; /* number assigned to first special | |
135 | opcode */ | |
136 | unsigned char *standard_opcode_lengths; | |
137 | } | |
138 | _STATEMENT_PROLOGUE; | |
139 | ||
d97bc12b DE |
140 | /* When non-zero, dump DIEs after they are read in. */ |
141 | static int dwarf2_die_debug = 0; | |
142 | ||
dce234bc PP |
143 | static int pagesize; |
144 | ||
df8a16a1 DJ |
145 | /* When set, the file that we're processing is known to have debugging |
146 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
147 | but later versions do. */ | |
148 | ||
149 | static int processing_has_namespace_info; | |
150 | ||
6502dd73 DJ |
151 | static const struct objfile_data *dwarf2_objfile_data_key; |
152 | ||
dce234bc PP |
153 | struct dwarf2_section_info |
154 | { | |
155 | asection *asection; | |
156 | gdb_byte *buffer; | |
157 | bfd_size_type size; | |
158 | int was_mmapped; | |
159 | }; | |
160 | ||
6502dd73 DJ |
161 | struct dwarf2_per_objfile |
162 | { | |
dce234bc PP |
163 | struct dwarf2_section_info info; |
164 | struct dwarf2_section_info abbrev; | |
165 | struct dwarf2_section_info line; | |
166 | struct dwarf2_section_info pubnames; | |
167 | struct dwarf2_section_info aranges; | |
168 | struct dwarf2_section_info loc; | |
169 | struct dwarf2_section_info macinfo; | |
170 | struct dwarf2_section_info str; | |
171 | struct dwarf2_section_info ranges; | |
348e048f | 172 | struct dwarf2_section_info types; |
dce234bc PP |
173 | struct dwarf2_section_info frame; |
174 | struct dwarf2_section_info eh_frame; | |
ae038cb0 | 175 | |
10b3939b DJ |
176 | /* A list of all the compilation units. This is used to locate |
177 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
178 | struct dwarf2_per_cu_data **all_comp_units; |
179 | ||
180 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
181 | int n_comp_units; | |
182 | ||
183 | /* A chain of compilation units that are currently read in, so that | |
184 | they can be freed later. */ | |
185 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 186 | |
348e048f DE |
187 | /* A table mapping .debug_types signatures to its signatured_type entry. |
188 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
189 | htab_t signatured_types; | |
190 | ||
72dca2f5 FR |
191 | /* A flag indicating wether this objfile has a section loaded at a |
192 | VMA of 0. */ | |
193 | int has_section_at_zero; | |
6502dd73 DJ |
194 | }; |
195 | ||
196 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
197 | |
198 | /* names of the debugging sections */ | |
199 | ||
233a11ab CS |
200 | /* Note that if the debugging section has been compressed, it might |
201 | have a name like .zdebug_info. */ | |
202 | ||
203 | #define INFO_SECTION "debug_info" | |
204 | #define ABBREV_SECTION "debug_abbrev" | |
205 | #define LINE_SECTION "debug_line" | |
206 | #define PUBNAMES_SECTION "debug_pubnames" | |
207 | #define ARANGES_SECTION "debug_aranges" | |
208 | #define LOC_SECTION "debug_loc" | |
209 | #define MACINFO_SECTION "debug_macinfo" | |
210 | #define STR_SECTION "debug_str" | |
211 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 212 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
213 | #define FRAME_SECTION "debug_frame" |
214 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
215 | |
216 | /* local data types */ | |
217 | ||
57349743 JB |
218 | /* We hold several abbreviation tables in memory at the same time. */ |
219 | #ifndef ABBREV_HASH_SIZE | |
220 | #define ABBREV_HASH_SIZE 121 | |
221 | #endif | |
222 | ||
107d2387 AC |
223 | /* The data in a compilation unit header, after target2host |
224 | translation, looks like this. */ | |
c906108c | 225 | struct comp_unit_head |
a738430d | 226 | { |
c764a876 | 227 | unsigned int length; |
a738430d | 228 | short version; |
a738430d MK |
229 | unsigned char addr_size; |
230 | unsigned char signed_addr_p; | |
9cbfa09e | 231 | unsigned int abbrev_offset; |
57349743 | 232 | |
a738430d MK |
233 | /* Size of file offsets; either 4 or 8. */ |
234 | unsigned int offset_size; | |
57349743 | 235 | |
a738430d MK |
236 | /* Size of the length field; either 4 or 12. */ |
237 | unsigned int initial_length_size; | |
57349743 | 238 | |
a738430d MK |
239 | /* Offset to the first byte of this compilation unit header in the |
240 | .debug_info section, for resolving relative reference dies. */ | |
241 | unsigned int offset; | |
57349743 | 242 | |
d00adf39 DE |
243 | /* Offset to first die in this cu from the start of the cu. |
244 | This will be the first byte following the compilation unit header. */ | |
245 | unsigned int first_die_offset; | |
a738430d | 246 | }; |
c906108c | 247 | |
e7c27a73 DJ |
248 | /* Internal state when decoding a particular compilation unit. */ |
249 | struct dwarf2_cu | |
250 | { | |
251 | /* The objfile containing this compilation unit. */ | |
252 | struct objfile *objfile; | |
253 | ||
d00adf39 | 254 | /* The header of the compilation unit. */ |
e7c27a73 | 255 | struct comp_unit_head header; |
e142c38c | 256 | |
d00adf39 DE |
257 | /* Base address of this compilation unit. */ |
258 | CORE_ADDR base_address; | |
259 | ||
260 | /* Non-zero if base_address has been set. */ | |
261 | int base_known; | |
262 | ||
e142c38c DJ |
263 | struct function_range *first_fn, *last_fn, *cached_fn; |
264 | ||
265 | /* The language we are debugging. */ | |
266 | enum language language; | |
267 | const struct language_defn *language_defn; | |
268 | ||
b0f35d58 DL |
269 | const char *producer; |
270 | ||
e142c38c DJ |
271 | /* The generic symbol table building routines have separate lists for |
272 | file scope symbols and all all other scopes (local scopes). So | |
273 | we need to select the right one to pass to add_symbol_to_list(). | |
274 | We do it by keeping a pointer to the correct list in list_in_scope. | |
275 | ||
276 | FIXME: The original dwarf code just treated the file scope as the | |
277 | first local scope, and all other local scopes as nested local | |
278 | scopes, and worked fine. Check to see if we really need to | |
279 | distinguish these in buildsym.c. */ | |
280 | struct pending **list_in_scope; | |
281 | ||
f3dd6933 DJ |
282 | /* DWARF abbreviation table associated with this compilation unit. */ |
283 | struct abbrev_info **dwarf2_abbrevs; | |
284 | ||
285 | /* Storage for the abbrev table. */ | |
286 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
287 | |
288 | /* Hash table holding all the loaded partial DIEs. */ | |
289 | htab_t partial_dies; | |
290 | ||
291 | /* Storage for things with the same lifetime as this read-in compilation | |
292 | unit, including partial DIEs. */ | |
293 | struct obstack comp_unit_obstack; | |
294 | ||
ae038cb0 DJ |
295 | /* When multiple dwarf2_cu structures are living in memory, this field |
296 | chains them all together, so that they can be released efficiently. | |
297 | We will probably also want a generation counter so that most-recently-used | |
298 | compilation units are cached... */ | |
299 | struct dwarf2_per_cu_data *read_in_chain; | |
300 | ||
301 | /* Backchain to our per_cu entry if the tree has been built. */ | |
302 | struct dwarf2_per_cu_data *per_cu; | |
303 | ||
f792889a DJ |
304 | /* Pointer to the die -> type map. Although it is stored |
305 | permanently in per_cu, we copy it here to avoid double | |
306 | indirection. */ | |
307 | htab_t type_hash; | |
308 | ||
ae038cb0 DJ |
309 | /* How many compilation units ago was this CU last referenced? */ |
310 | int last_used; | |
311 | ||
10b3939b | 312 | /* A hash table of die offsets for following references. */ |
51545339 | 313 | htab_t die_hash; |
10b3939b DJ |
314 | |
315 | /* Full DIEs if read in. */ | |
316 | struct die_info *dies; | |
317 | ||
318 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
319 | units referenced by this one. Only set during full symbol processing; | |
320 | partial symbol tables do not have dependencies. */ | |
321 | htab_t dependencies; | |
322 | ||
cb1df416 DJ |
323 | /* Header data from the line table, during full symbol processing. */ |
324 | struct line_header *line_header; | |
325 | ||
ae038cb0 DJ |
326 | /* Mark used when releasing cached dies. */ |
327 | unsigned int mark : 1; | |
328 | ||
329 | /* This flag will be set if this compilation unit might include | |
330 | inter-compilation-unit references. */ | |
331 | unsigned int has_form_ref_addr : 1; | |
332 | ||
72bf9492 DJ |
333 | /* This flag will be set if this compilation unit includes any |
334 | DW_TAG_namespace DIEs. If we know that there are explicit | |
335 | DIEs for namespaces, we don't need to try to infer them | |
336 | from mangled names. */ | |
337 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
338 | }; |
339 | ||
10b3939b DJ |
340 | /* Persistent data held for a compilation unit, even when not |
341 | processing it. We put a pointer to this structure in the | |
342 | read_symtab_private field of the psymtab. If we encounter | |
343 | inter-compilation-unit references, we also maintain a sorted | |
344 | list of all compilation units. */ | |
345 | ||
ae038cb0 DJ |
346 | struct dwarf2_per_cu_data |
347 | { | |
348e048f | 348 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 349 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
350 | - if it doesn't, GDB will fall over anyway. |
351 | NOTE: Unlike comp_unit_head.length, this length includes | |
352 | initial_length_size. */ | |
c764a876 | 353 | unsigned int offset; |
348e048f | 354 | unsigned int length : 29; |
ae038cb0 DJ |
355 | |
356 | /* Flag indicating this compilation unit will be read in before | |
357 | any of the current compilation units are processed. */ | |
c764a876 | 358 | unsigned int queued : 1; |
ae038cb0 | 359 | |
5afb4e99 DJ |
360 | /* This flag will be set if we need to load absolutely all DIEs |
361 | for this compilation unit, instead of just the ones we think | |
362 | are interesting. It gets set if we look for a DIE in the | |
363 | hash table and don't find it. */ | |
364 | unsigned int load_all_dies : 1; | |
365 | ||
348e048f DE |
366 | /* Non-zero if this CU is from .debug_types. |
367 | Otherwise it's from .debug_info. */ | |
368 | unsigned int from_debug_types : 1; | |
369 | ||
ae038cb0 DJ |
370 | /* Set iff currently read in. */ |
371 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
372 | |
373 | /* If full symbols for this CU have been read in, then this field | |
374 | holds a map of DIE offsets to types. It isn't always possible | |
375 | to reconstruct this information later, so we have to preserve | |
376 | it. */ | |
1c379e20 | 377 | htab_t type_hash; |
10b3939b | 378 | |
31ffec48 DJ |
379 | /* The partial symbol table associated with this compilation unit, |
380 | or NULL for partial units (which do not have an associated | |
381 | symtab). */ | |
10b3939b | 382 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
383 | }; |
384 | ||
348e048f DE |
385 | /* Entry in the signatured_types hash table. */ |
386 | ||
387 | struct signatured_type | |
388 | { | |
389 | ULONGEST signature; | |
390 | ||
391 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
392 | unsigned int offset; | |
393 | ||
394 | /* Offset in .debug_types of the type defined by this TU. */ | |
395 | unsigned int type_offset; | |
396 | ||
397 | /* The CU(/TU) of this type. */ | |
398 | struct dwarf2_per_cu_data per_cu; | |
399 | }; | |
400 | ||
93311388 DE |
401 | /* Struct used to pass misc. parameters to read_die_and_children, et. al. |
402 | which are used for both .debug_info and .debug_types dies. | |
403 | All parameters here are unchanging for the life of the call. | |
404 | This struct exists to abstract away the constant parameters of | |
405 | die reading. */ | |
406 | ||
407 | struct die_reader_specs | |
408 | { | |
409 | /* The bfd of this objfile. */ | |
410 | bfd* abfd; | |
411 | ||
412 | /* The CU of the DIE we are parsing. */ | |
413 | struct dwarf2_cu *cu; | |
414 | ||
415 | /* Pointer to start of section buffer. | |
416 | This is either the start of .debug_info or .debug_types. */ | |
417 | const gdb_byte *buffer; | |
418 | }; | |
419 | ||
debd256d JB |
420 | /* The line number information for a compilation unit (found in the |
421 | .debug_line section) begins with a "statement program header", | |
422 | which contains the following information. */ | |
423 | struct line_header | |
424 | { | |
425 | unsigned int total_length; | |
426 | unsigned short version; | |
427 | unsigned int header_length; | |
428 | unsigned char minimum_instruction_length; | |
429 | unsigned char default_is_stmt; | |
430 | int line_base; | |
431 | unsigned char line_range; | |
432 | unsigned char opcode_base; | |
433 | ||
434 | /* standard_opcode_lengths[i] is the number of operands for the | |
435 | standard opcode whose value is i. This means that | |
436 | standard_opcode_lengths[0] is unused, and the last meaningful | |
437 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
438 | unsigned char *standard_opcode_lengths; | |
439 | ||
440 | /* The include_directories table. NOTE! These strings are not | |
441 | allocated with xmalloc; instead, they are pointers into | |
442 | debug_line_buffer. If you try to free them, `free' will get | |
443 | indigestion. */ | |
444 | unsigned int num_include_dirs, include_dirs_size; | |
445 | char **include_dirs; | |
446 | ||
447 | /* The file_names table. NOTE! These strings are not allocated | |
448 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
449 | Don't try to free them directly. */ | |
450 | unsigned int num_file_names, file_names_size; | |
451 | struct file_entry | |
c906108c | 452 | { |
debd256d JB |
453 | char *name; |
454 | unsigned int dir_index; | |
455 | unsigned int mod_time; | |
456 | unsigned int length; | |
aaa75496 | 457 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 458 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
459 | } *file_names; |
460 | ||
461 | /* The start and end of the statement program following this | |
6502dd73 | 462 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 463 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 464 | }; |
c906108c SS |
465 | |
466 | /* When we construct a partial symbol table entry we only | |
467 | need this much information. */ | |
468 | struct partial_die_info | |
469 | { | |
72bf9492 | 470 | /* Offset of this DIE. */ |
c906108c | 471 | unsigned int offset; |
72bf9492 DJ |
472 | |
473 | /* DWARF-2 tag for this DIE. */ | |
474 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
475 | ||
72bf9492 DJ |
476 | /* Assorted flags describing the data found in this DIE. */ |
477 | unsigned int has_children : 1; | |
478 | unsigned int is_external : 1; | |
479 | unsigned int is_declaration : 1; | |
480 | unsigned int has_type : 1; | |
481 | unsigned int has_specification : 1; | |
482 | unsigned int has_pc_info : 1; | |
483 | ||
484 | /* Flag set if the SCOPE field of this structure has been | |
485 | computed. */ | |
486 | unsigned int scope_set : 1; | |
487 | ||
fa4028e9 JB |
488 | /* Flag set if the DIE has a byte_size attribute. */ |
489 | unsigned int has_byte_size : 1; | |
490 | ||
72bf9492 | 491 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 492 | sometimes a default name for unnamed DIEs. */ |
c906108c | 493 | char *name; |
72bf9492 DJ |
494 | |
495 | /* The scope to prepend to our children. This is generally | |
496 | allocated on the comp_unit_obstack, so will disappear | |
497 | when this compilation unit leaves the cache. */ | |
498 | char *scope; | |
499 | ||
500 | /* The location description associated with this DIE, if any. */ | |
501 | struct dwarf_block *locdesc; | |
502 | ||
503 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
504 | CORE_ADDR lowpc; |
505 | CORE_ADDR highpc; | |
72bf9492 | 506 | |
93311388 | 507 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 508 | DW_AT_sibling, if any. */ |
fe1b8b76 | 509 | gdb_byte *sibling; |
72bf9492 DJ |
510 | |
511 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
512 | DW_AT_specification (or DW_AT_abstract_origin or | |
513 | DW_AT_extension). */ | |
514 | unsigned int spec_offset; | |
515 | ||
516 | /* Pointers to this DIE's parent, first child, and next sibling, | |
517 | if any. */ | |
518 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
519 | }; |
520 | ||
521 | /* This data structure holds the information of an abbrev. */ | |
522 | struct abbrev_info | |
523 | { | |
524 | unsigned int number; /* number identifying abbrev */ | |
525 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
526 | unsigned short has_children; /* boolean */ |
527 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
528 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
529 | struct abbrev_info *next; /* next in chain */ | |
530 | }; | |
531 | ||
532 | struct attr_abbrev | |
533 | { | |
9d25dd43 DE |
534 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
535 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
536 | }; |
537 | ||
b60c80d6 DJ |
538 | /* Attributes have a name and a value */ |
539 | struct attribute | |
540 | { | |
9d25dd43 | 541 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
542 | ENUM_BITFIELD(dwarf_form) form : 15; |
543 | ||
544 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
545 | field should be in u.str (existing only for DW_STRING) but it is kept | |
546 | here for better struct attribute alignment. */ | |
547 | unsigned int string_is_canonical : 1; | |
548 | ||
b60c80d6 DJ |
549 | union |
550 | { | |
551 | char *str; | |
552 | struct dwarf_block *blk; | |
43bbcdc2 PH |
553 | ULONGEST unsnd; |
554 | LONGEST snd; | |
b60c80d6 | 555 | CORE_ADDR addr; |
348e048f | 556 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
557 | } |
558 | u; | |
559 | }; | |
560 | ||
c906108c SS |
561 | /* This data structure holds a complete die structure. */ |
562 | struct die_info | |
563 | { | |
76815b17 DE |
564 | /* DWARF-2 tag for this DIE. */ |
565 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
566 | ||
567 | /* Number of attributes */ | |
568 | unsigned short num_attrs; | |
569 | ||
570 | /* Abbrev number */ | |
571 | unsigned int abbrev; | |
572 | ||
93311388 | 573 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 574 | unsigned int offset; |
78ba4af6 JB |
575 | |
576 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
577 | points to this die's parent; CHILD points to the first child of | |
578 | this node; and all the children of a given node are chained | |
579 | together via their SIBLING fields, terminated by a die whose | |
580 | tag is zero. */ | |
639d11d3 DC |
581 | struct die_info *child; /* Its first child, if any. */ |
582 | struct die_info *sibling; /* Its next sibling, if any. */ | |
583 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 584 | |
b60c80d6 DJ |
585 | /* An array of attributes, with NUM_ATTRS elements. There may be |
586 | zero, but it's not common and zero-sized arrays are not | |
587 | sufficiently portable C. */ | |
588 | struct attribute attrs[1]; | |
c906108c SS |
589 | }; |
590 | ||
5fb290d7 DJ |
591 | struct function_range |
592 | { | |
593 | const char *name; | |
594 | CORE_ADDR lowpc, highpc; | |
595 | int seen_line; | |
596 | struct function_range *next; | |
597 | }; | |
598 | ||
c906108c SS |
599 | /* Get at parts of an attribute structure */ |
600 | ||
601 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 602 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
603 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
604 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
605 | #define DW_SND(attr) ((attr)->u.snd) | |
606 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 607 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c SS |
608 | |
609 | /* Blocks are a bunch of untyped bytes. */ | |
610 | struct dwarf_block | |
611 | { | |
612 | unsigned int size; | |
fe1b8b76 | 613 | gdb_byte *data; |
c906108c SS |
614 | }; |
615 | ||
c906108c SS |
616 | #ifndef ATTR_ALLOC_CHUNK |
617 | #define ATTR_ALLOC_CHUNK 4 | |
618 | #endif | |
619 | ||
c906108c SS |
620 | /* Allocate fields for structs, unions and enums in this size. */ |
621 | #ifndef DW_FIELD_ALLOC_CHUNK | |
622 | #define DW_FIELD_ALLOC_CHUNK 4 | |
623 | #endif | |
624 | ||
c906108c SS |
625 | /* A zeroed version of a partial die for initialization purposes. */ |
626 | static struct partial_die_info zeroed_partial_die; | |
627 | ||
c906108c SS |
628 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
629 | but this would require a corresponding change in unpack_field_as_long | |
630 | and friends. */ | |
631 | static int bits_per_byte = 8; | |
632 | ||
633 | /* The routines that read and process dies for a C struct or C++ class | |
634 | pass lists of data member fields and lists of member function fields | |
635 | in an instance of a field_info structure, as defined below. */ | |
636 | struct field_info | |
c5aa993b JM |
637 | { |
638 | /* List of data member and baseclasses fields. */ | |
639 | struct nextfield | |
640 | { | |
641 | struct nextfield *next; | |
642 | int accessibility; | |
643 | int virtuality; | |
644 | struct field field; | |
645 | } | |
7d0ccb61 | 646 | *fields, *baseclasses; |
c906108c | 647 | |
7d0ccb61 | 648 | /* Number of fields (including baseclasses). */ |
c5aa993b | 649 | int nfields; |
c906108c | 650 | |
c5aa993b JM |
651 | /* Number of baseclasses. */ |
652 | int nbaseclasses; | |
c906108c | 653 | |
c5aa993b JM |
654 | /* Set if the accesibility of one of the fields is not public. */ |
655 | int non_public_fields; | |
c906108c | 656 | |
c5aa993b JM |
657 | /* Member function fields array, entries are allocated in the order they |
658 | are encountered in the object file. */ | |
659 | struct nextfnfield | |
660 | { | |
661 | struct nextfnfield *next; | |
662 | struct fn_field fnfield; | |
663 | } | |
664 | *fnfields; | |
c906108c | 665 | |
c5aa993b JM |
666 | /* Member function fieldlist array, contains name of possibly overloaded |
667 | member function, number of overloaded member functions and a pointer | |
668 | to the head of the member function field chain. */ | |
669 | struct fnfieldlist | |
670 | { | |
671 | char *name; | |
672 | int length; | |
673 | struct nextfnfield *head; | |
674 | } | |
675 | *fnfieldlists; | |
c906108c | 676 | |
c5aa993b JM |
677 | /* Number of entries in the fnfieldlists array. */ |
678 | int nfnfields; | |
679 | }; | |
c906108c | 680 | |
10b3939b DJ |
681 | /* One item on the queue of compilation units to read in full symbols |
682 | for. */ | |
683 | struct dwarf2_queue_item | |
684 | { | |
685 | struct dwarf2_per_cu_data *per_cu; | |
686 | struct dwarf2_queue_item *next; | |
687 | }; | |
688 | ||
689 | /* The current queue. */ | |
690 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
691 | ||
ae038cb0 DJ |
692 | /* Loaded secondary compilation units are kept in memory until they |
693 | have not been referenced for the processing of this many | |
694 | compilation units. Set this to zero to disable caching. Cache | |
695 | sizes of up to at least twenty will improve startup time for | |
696 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
697 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
698 | static void |
699 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
700 | struct cmd_list_element *c, const char *value) | |
701 | { | |
702 | fprintf_filtered (file, _("\ | |
703 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
704 | value); | |
705 | } | |
706 | ||
ae038cb0 | 707 | |
c906108c SS |
708 | /* Various complaints about symbol reading that don't abort the process */ |
709 | ||
4d3c2250 KB |
710 | static void |
711 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 712 | { |
4d3c2250 | 713 | complaint (&symfile_complaints, |
e2e0b3e5 | 714 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
715 | } |
716 | ||
25e43795 DJ |
717 | static void |
718 | dwarf2_debug_line_missing_file_complaint (void) | |
719 | { | |
720 | complaint (&symfile_complaints, | |
721 | _(".debug_line section has line data without a file")); | |
722 | } | |
723 | ||
59205f5a JB |
724 | static void |
725 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
726 | { | |
727 | complaint (&symfile_complaints, | |
728 | _(".debug_line section has line program sequence without an end")); | |
729 | } | |
730 | ||
4d3c2250 KB |
731 | static void |
732 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 733 | { |
e2e0b3e5 | 734 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
735 | } |
736 | ||
4d3c2250 KB |
737 | static void |
738 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
739 | int arg3) | |
2e276125 | 740 | { |
4d3c2250 | 741 | complaint (&symfile_complaints, |
e2e0b3e5 | 742 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
743 | arg2, arg3); |
744 | } | |
745 | ||
746 | static void | |
747 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 748 | { |
4d3c2250 | 749 | complaint (&symfile_complaints, |
e2e0b3e5 | 750 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
751 | } |
752 | ||
753 | static void | |
754 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 755 | { |
4d3c2250 | 756 | complaint (&symfile_complaints, |
e2e0b3e5 | 757 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
758 | arg1); |
759 | } | |
760 | ||
761 | static void | |
762 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 763 | { |
4d3c2250 | 764 | complaint (&symfile_complaints, |
e2e0b3e5 | 765 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 766 | } |
c906108c | 767 | |
c906108c SS |
768 | /* local function prototypes */ |
769 | ||
4efb68b1 | 770 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
771 | |
772 | #if 0 | |
c67a9c90 | 773 | static void dwarf2_build_psymtabs_easy (struct objfile *); |
c906108c SS |
774 | #endif |
775 | ||
aaa75496 JB |
776 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
777 | struct objfile *); | |
778 | ||
779 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
d85a05f0 | 780 | struct die_info *, |
aaa75496 JB |
781 | struct partial_symtab *); |
782 | ||
c67a9c90 | 783 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 784 | |
72bf9492 DJ |
785 | static void scan_partial_symbols (struct partial_die_info *, |
786 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 787 | int, struct dwarf2_cu *); |
c906108c | 788 | |
72bf9492 DJ |
789 | static void add_partial_symbol (struct partial_die_info *, |
790 | struct dwarf2_cu *); | |
63d06c5c | 791 | |
72bf9492 DJ |
792 | static void add_partial_namespace (struct partial_die_info *pdi, |
793 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 794 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 795 | |
5d7cb8df JK |
796 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
797 | CORE_ADDR *highpc, int need_pc, | |
798 | struct dwarf2_cu *cu); | |
799 | ||
72bf9492 DJ |
800 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
801 | struct dwarf2_cu *cu); | |
91c24f0a | 802 | |
bc30ff58 JB |
803 | static void add_partial_subprogram (struct partial_die_info *pdi, |
804 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 805 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 806 | |
fe1b8b76 | 807 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
808 | gdb_byte *buffer, gdb_byte *info_ptr, |
809 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 810 | |
a14ed312 | 811 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 812 | |
a14ed312 | 813 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 814 | |
e7c27a73 | 815 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 816 | |
f3dd6933 | 817 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 818 | |
fe1b8b76 | 819 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 820 | struct dwarf2_cu *); |
72bf9492 | 821 | |
57349743 | 822 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 823 | struct dwarf2_cu *); |
c906108c | 824 | |
93311388 DE |
825 | static struct partial_die_info *load_partial_dies (bfd *, |
826 | gdb_byte *, gdb_byte *, | |
827 | int, struct dwarf2_cu *); | |
72bf9492 | 828 | |
fe1b8b76 | 829 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
830 | struct abbrev_info *abbrev, |
831 | unsigned int, bfd *, | |
832 | gdb_byte *, gdb_byte *, | |
833 | struct dwarf2_cu *); | |
c906108c | 834 | |
c764a876 | 835 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 836 | struct dwarf2_cu *); |
72bf9492 DJ |
837 | |
838 | static void fixup_partial_die (struct partial_die_info *, | |
839 | struct dwarf2_cu *); | |
840 | ||
fe1b8b76 JB |
841 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
842 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 843 | |
fe1b8b76 JB |
844 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
845 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 846 | |
fe1b8b76 | 847 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 848 | |
fe1b8b76 | 849 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 850 | |
fe1b8b76 | 851 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 852 | |
fe1b8b76 | 853 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 854 | |
93311388 | 855 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 856 | |
fe1b8b76 | 857 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 858 | unsigned int *); |
c906108c | 859 | |
c764a876 DE |
860 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
861 | ||
862 | static LONGEST read_checked_initial_length_and_offset | |
863 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
864 | unsigned int *, unsigned int *); | |
613e1657 | 865 | |
fe1b8b76 | 866 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
867 | unsigned int *); |
868 | ||
869 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 870 | |
fe1b8b76 | 871 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 872 | |
fe1b8b76 | 873 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 874 | |
fe1b8b76 JB |
875 | static char *read_indirect_string (bfd *, gdb_byte *, |
876 | const struct comp_unit_head *, | |
877 | unsigned int *); | |
4bdf3d34 | 878 | |
fe1b8b76 | 879 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 880 | |
fe1b8b76 | 881 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 882 | |
fe1b8b76 | 883 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 884 | |
e142c38c | 885 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 886 | |
e142c38c DJ |
887 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
888 | struct dwarf2_cu *); | |
c906108c | 889 | |
348e048f DE |
890 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
891 | unsigned int, | |
892 | struct dwarf2_cu *); | |
893 | ||
05cf31d1 JB |
894 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
895 | struct dwarf2_cu *cu); | |
896 | ||
e142c38c | 897 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 898 | |
e142c38c | 899 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 900 | struct dwarf2_cu **); |
63d06c5c | 901 | |
debd256d JB |
902 | static void free_line_header (struct line_header *lh); |
903 | ||
aaa75496 JB |
904 | static void add_file_name (struct line_header *, char *, unsigned int, |
905 | unsigned int, unsigned int); | |
906 | ||
debd256d JB |
907 | static struct line_header *(dwarf_decode_line_header |
908 | (unsigned int offset, | |
e7c27a73 | 909 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
910 | |
911 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 912 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 913 | |
4f1520fb | 914 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 915 | |
a14ed312 | 916 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 917 | struct dwarf2_cu *); |
c906108c | 918 | |
a14ed312 | 919 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 920 | struct dwarf2_cu *); |
c906108c | 921 | |
2df3850c JM |
922 | static void dwarf2_const_value_data (struct attribute *attr, |
923 | struct symbol *sym, | |
924 | int bits); | |
925 | ||
e7c27a73 | 926 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 927 | |
b4ba55a1 JB |
928 | static int need_gnat_info (struct dwarf2_cu *); |
929 | ||
930 | static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *); | |
931 | ||
932 | static void set_descriptive_type (struct type *, struct die_info *, | |
933 | struct dwarf2_cu *); | |
934 | ||
e7c27a73 DJ |
935 | static struct type *die_containing_type (struct die_info *, |
936 | struct dwarf2_cu *); | |
c906108c | 937 | |
e7c27a73 | 938 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 939 | |
f792889a | 940 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 941 | |
086ed43d | 942 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 943 | |
fe1b8b76 JB |
944 | static char *typename_concat (struct obstack *, |
945 | const char *prefix, | |
946 | const char *suffix, | |
987504bb | 947 | struct dwarf2_cu *); |
63d06c5c | 948 | |
e7c27a73 | 949 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 950 | |
348e048f DE |
951 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
952 | ||
e7c27a73 | 953 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 954 | |
e7c27a73 | 955 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 956 | |
ff013f42 JK |
957 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
958 | struct dwarf2_cu *, struct partial_symtab *); | |
959 | ||
a14ed312 | 960 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
961 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
962 | struct partial_symtab *); | |
c906108c | 963 | |
fae299cd DC |
964 | static void get_scope_pc_bounds (struct die_info *, |
965 | CORE_ADDR *, CORE_ADDR *, | |
966 | struct dwarf2_cu *); | |
967 | ||
801e3a5b JB |
968 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
969 | CORE_ADDR, struct dwarf2_cu *); | |
970 | ||
a14ed312 | 971 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 972 | struct dwarf2_cu *); |
c906108c | 973 | |
a14ed312 | 974 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 975 | struct type *, struct dwarf2_cu *); |
c906108c | 976 | |
a14ed312 | 977 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 978 | struct die_info *, struct type *, |
e7c27a73 | 979 | struct dwarf2_cu *); |
c906108c | 980 | |
a14ed312 | 981 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 982 | struct type *, struct dwarf2_cu *); |
c906108c | 983 | |
134d01f1 | 984 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 985 | |
e7c27a73 | 986 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 987 | |
e7c27a73 | 988 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 989 | |
5d7cb8df JK |
990 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
991 | ||
27aa8d6a SW |
992 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
993 | ||
38d518c9 | 994 | static const char *namespace_name (struct die_info *die, |
e142c38c | 995 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 996 | |
134d01f1 | 997 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 998 | |
e7c27a73 | 999 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1000 | |
7ca2d3a3 DL |
1001 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
1002 | struct dwarf2_cu *); | |
1003 | ||
93311388 | 1004 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1005 | |
93311388 DE |
1006 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1007 | gdb_byte *info_ptr, | |
d97bc12b DE |
1008 | gdb_byte **new_info_ptr, |
1009 | struct die_info *parent); | |
1010 | ||
93311388 DE |
1011 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1012 | gdb_byte *info_ptr, | |
fe1b8b76 | 1013 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1014 | struct die_info *parent); |
1015 | ||
93311388 DE |
1016 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1017 | gdb_byte *info_ptr, | |
fe1b8b76 | 1018 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1019 | struct die_info *parent); |
1020 | ||
93311388 DE |
1021 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1022 | struct die_info **, gdb_byte *, | |
1023 | int *); | |
1024 | ||
e7c27a73 | 1025 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1026 | |
71c25dea TT |
1027 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1028 | struct obstack *); | |
1029 | ||
e142c38c | 1030 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1031 | |
e142c38c | 1032 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1033 | struct dwarf2_cu **); |
9219021c | 1034 | |
a14ed312 | 1035 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1036 | |
a14ed312 | 1037 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1038 | |
a14ed312 | 1039 | static char *dwarf_form_name (unsigned int); |
c906108c | 1040 | |
a14ed312 | 1041 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 1042 | |
a14ed312 | 1043 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1044 | |
a14ed312 | 1045 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1046 | |
1047 | #if 0 | |
a14ed312 | 1048 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1049 | #endif |
1050 | ||
f9aca02d | 1051 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1052 | |
d97bc12b DE |
1053 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1054 | ||
1055 | static void dump_die_for_error (struct die_info *); | |
1056 | ||
1057 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1058 | struct die_info *); | |
c906108c | 1059 | |
d97bc12b | 1060 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1061 | |
51545339 | 1062 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1063 | struct dwarf2_cu *); |
c906108c | 1064 | |
93311388 DE |
1065 | static int is_ref_attr (struct attribute *); |
1066 | ||
c764a876 | 1067 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1068 | |
43bbcdc2 | 1069 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1070 | |
348e048f DE |
1071 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1072 | struct attribute *, | |
1073 | struct dwarf2_cu **); | |
1074 | ||
10b3939b DJ |
1075 | static struct die_info *follow_die_ref (struct die_info *, |
1076 | struct attribute *, | |
f2f0e013 | 1077 | struct dwarf2_cu **); |
c906108c | 1078 | |
348e048f DE |
1079 | static struct die_info *follow_die_sig (struct die_info *, |
1080 | struct attribute *, | |
1081 | struct dwarf2_cu **); | |
1082 | ||
1083 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1084 | unsigned int offset); | |
1085 | ||
1086 | static void read_signatured_type (struct objfile *, | |
1087 | struct signatured_type *type_sig); | |
1088 | ||
c906108c SS |
1089 | /* memory allocation interface */ |
1090 | ||
7b5a2f43 | 1091 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1092 | |
f3dd6933 | 1093 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1094 | |
b60c80d6 | 1095 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1096 | |
e142c38c | 1097 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1098 | |
e142c38c DJ |
1099 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1100 | struct dwarf2_cu *); | |
5fb290d7 | 1101 | |
2e276125 | 1102 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1103 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1104 | |
8e19ed76 PS |
1105 | static int attr_form_is_block (struct attribute *); |
1106 | ||
3690dd37 JB |
1107 | static int attr_form_is_section_offset (struct attribute *); |
1108 | ||
1109 | static int attr_form_is_constant (struct attribute *); | |
1110 | ||
93e7bd98 DJ |
1111 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1112 | struct symbol *sym, | |
1113 | struct dwarf2_cu *cu); | |
4c2df51b | 1114 | |
93311388 DE |
1115 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1116 | struct abbrev_info *abbrev, | |
1117 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1118 | |
72bf9492 DJ |
1119 | static void free_stack_comp_unit (void *); |
1120 | ||
72bf9492 DJ |
1121 | static hashval_t partial_die_hash (const void *item); |
1122 | ||
1123 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1124 | ||
ae038cb0 | 1125 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1126 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1127 | |
1128 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1129 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1130 | |
93311388 DE |
1131 | static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); |
1132 | ||
ae038cb0 DJ |
1133 | static void free_one_comp_unit (void *); |
1134 | ||
1135 | static void free_cached_comp_units (void *); | |
1136 | ||
1137 | static void age_cached_comp_units (void); | |
1138 | ||
1139 | static void free_one_cached_comp_unit (void *); | |
1140 | ||
f792889a DJ |
1141 | static struct type *set_die_type (struct die_info *, struct type *, |
1142 | struct dwarf2_cu *); | |
1c379e20 | 1143 | |
ae038cb0 DJ |
1144 | static void create_all_comp_units (struct objfile *); |
1145 | ||
93311388 DE |
1146 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1147 | struct objfile *); | |
10b3939b DJ |
1148 | |
1149 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1150 | ||
1151 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1152 | struct dwarf2_per_cu_data *); | |
1153 | ||
ae038cb0 DJ |
1154 | static void dwarf2_mark (struct dwarf2_cu *); |
1155 | ||
1156 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1157 | ||
f792889a | 1158 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1159 | |
c906108c SS |
1160 | /* Try to locate the sections we need for DWARF 2 debugging |
1161 | information and return true if we have enough to do something. */ | |
1162 | ||
1163 | int | |
6502dd73 | 1164 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1165 | { |
6502dd73 DJ |
1166 | struct dwarf2_per_objfile *data; |
1167 | ||
1168 | /* Initialize per-objfile state. */ | |
1169 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1170 | memset (data, 0, sizeof (*data)); | |
1171 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1172 | dwarf2_per_objfile = data; | |
1173 | ||
6502dd73 | 1174 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
dce234bc | 1175 | return (data->info.asection != NULL && data->abbrev.asection != NULL); |
c906108c SS |
1176 | } |
1177 | ||
233a11ab CS |
1178 | /* When loading sections, we can either look for ".<name>", or for |
1179 | * ".z<name>", which indicates a compressed section. */ | |
1180 | ||
1181 | static int | |
dce234bc | 1182 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1183 | { |
dce234bc PP |
1184 | return (section_name[0] == '.' |
1185 | && (strcmp (section_name + 1, name) == 0 | |
1186 | || (section_name[1] == 'z' | |
1187 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1188 | } |
1189 | ||
c906108c SS |
1190 | /* This function is mapped across the sections and remembers the |
1191 | offset and size of each of the debugging sections we are interested | |
1192 | in. */ | |
1193 | ||
1194 | static void | |
72dca2f5 | 1195 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1196 | { |
dce234bc | 1197 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1198 | { |
dce234bc PP |
1199 | dwarf2_per_objfile->info.asection = sectp; |
1200 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1201 | } |
dce234bc | 1202 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1203 | { |
dce234bc PP |
1204 | dwarf2_per_objfile->abbrev.asection = sectp; |
1205 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1206 | } |
dce234bc | 1207 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1208 | { |
dce234bc PP |
1209 | dwarf2_per_objfile->line.asection = sectp; |
1210 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1211 | } |
dce234bc | 1212 | else if (section_is_p (sectp->name, PUBNAMES_SECTION)) |
c906108c | 1213 | { |
dce234bc PP |
1214 | dwarf2_per_objfile->pubnames.asection = sectp; |
1215 | dwarf2_per_objfile->pubnames.size = bfd_get_section_size (sectp); | |
c906108c | 1216 | } |
dce234bc | 1217 | else if (section_is_p (sectp->name, ARANGES_SECTION)) |
c906108c | 1218 | { |
dce234bc PP |
1219 | dwarf2_per_objfile->aranges.asection = sectp; |
1220 | dwarf2_per_objfile->aranges.size = bfd_get_section_size (sectp); | |
c906108c | 1221 | } |
dce234bc | 1222 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1223 | { |
dce234bc PP |
1224 | dwarf2_per_objfile->loc.asection = sectp; |
1225 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1226 | } |
dce234bc | 1227 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1228 | { |
dce234bc PP |
1229 | dwarf2_per_objfile->macinfo.asection = sectp; |
1230 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1231 | } |
dce234bc | 1232 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1233 | { |
dce234bc PP |
1234 | dwarf2_per_objfile->str.asection = sectp; |
1235 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1236 | } |
dce234bc | 1237 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1238 | { |
dce234bc PP |
1239 | dwarf2_per_objfile->frame.asection = sectp; |
1240 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1241 | } |
dce234bc | 1242 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1243 | { |
3799ccc6 EZ |
1244 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1245 | if (aflag & SEC_HAS_CONTENTS) | |
1246 | { | |
dce234bc PP |
1247 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1248 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1249 | } |
b6af0555 | 1250 | } |
dce234bc | 1251 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1252 | { |
dce234bc PP |
1253 | dwarf2_per_objfile->ranges.asection = sectp; |
1254 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1255 | } |
348e048f DE |
1256 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1257 | { | |
1258 | dwarf2_per_objfile->types.asection = sectp; | |
1259 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1260 | } | |
dce234bc | 1261 | |
72dca2f5 FR |
1262 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1263 | && bfd_section_vma (abfd, sectp) == 0) | |
1264 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1265 | } |
1266 | ||
dce234bc PP |
1267 | /* Decompress a section that was compressed using zlib. Store the |
1268 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1269 | |
1270 | static void | |
dce234bc PP |
1271 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1272 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1273 | { | |
1274 | bfd *abfd = objfile->obfd; | |
1275 | #ifndef HAVE_ZLIB_H | |
1276 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1277 | "is disabled in this copy of GDB"), | |
1278 | bfd_get_filename (abfd)); | |
1279 | #else | |
1280 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1281 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1282 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1283 | bfd_size_type uncompressed_size; |
1284 | gdb_byte *uncompressed_buffer; | |
1285 | z_stream strm; | |
1286 | int rc; | |
1287 | int header_size = 12; | |
1288 | ||
1289 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1290 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1291 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1292 | bfd_get_filename (abfd)); | |
1293 | ||
1294 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1295 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1296 | if (compressed_size < header_size | |
1297 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1298 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1299 | bfd_get_filename (abfd)); | |
1300 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1301 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1302 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1303 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1304 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1305 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1306 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1307 | uncompressed_size += compressed_buffer[11]; | |
1308 | ||
1309 | /* It is possible the section consists of several compressed | |
1310 | buffers concatenated together, so we uncompress in a loop. */ | |
1311 | strm.zalloc = NULL; | |
1312 | strm.zfree = NULL; | |
1313 | strm.opaque = NULL; | |
1314 | strm.avail_in = compressed_size - header_size; | |
1315 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1316 | strm.avail_out = uncompressed_size; | |
1317 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1318 | uncompressed_size); | |
1319 | rc = inflateInit (&strm); | |
1320 | while (strm.avail_in > 0) | |
1321 | { | |
1322 | if (rc != Z_OK) | |
1323 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1324 | bfd_get_filename (abfd), rc); | |
1325 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1326 | + (uncompressed_size - strm.avail_out)); | |
1327 | rc = inflate (&strm, Z_FINISH); | |
1328 | if (rc != Z_STREAM_END) | |
1329 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1330 | bfd_get_filename (abfd), rc); | |
1331 | rc = inflateReset (&strm); | |
1332 | } | |
1333 | rc = inflateEnd (&strm); | |
1334 | if (rc != Z_OK | |
1335 | || strm.avail_out != 0) | |
1336 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1337 | bfd_get_filename (abfd), rc); | |
1338 | ||
affddf13 | 1339 | do_cleanups (cleanup); |
dce234bc PP |
1340 | *outbuf = uncompressed_buffer; |
1341 | *outsize = uncompressed_size; | |
1342 | #endif | |
233a11ab CS |
1343 | } |
1344 | ||
dce234bc PP |
1345 | /* Read the contents of the section SECTP from object file specified by |
1346 | OBJFILE, store info about the section into INFO. | |
1347 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1348 | |
dce234bc PP |
1349 | static void |
1350 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1351 | { |
dce234bc PP |
1352 | bfd *abfd = objfile->obfd; |
1353 | asection *sectp = info->asection; | |
1354 | gdb_byte *buf, *retbuf; | |
1355 | unsigned char header[4]; | |
c906108c | 1356 | |
dce234bc PP |
1357 | info->buffer = NULL; |
1358 | info->was_mmapped = 0; | |
188dd5d6 | 1359 | |
dce234bc PP |
1360 | if (info->asection == NULL || info->size == 0) |
1361 | return; | |
c906108c | 1362 | |
dce234bc PP |
1363 | /* Check if the file has a 4-byte header indicating compression. */ |
1364 | if (info->size > sizeof (header) | |
1365 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1366 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1367 | { | |
1368 | /* Upon decompression, update the buffer and its size. */ | |
1369 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1370 | { | |
1371 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1372 | &info->size); | |
1373 | return; | |
1374 | } | |
1375 | } | |
4bdf3d34 | 1376 | |
dce234bc PP |
1377 | #ifdef HAVE_MMAP |
1378 | if (pagesize == 0) | |
1379 | pagesize = getpagesize (); | |
2e276125 | 1380 | |
dce234bc PP |
1381 | /* Only try to mmap sections which are large enough: we don't want to |
1382 | waste space due to fragmentation. Also, only try mmap for sections | |
1383 | without relocations. */ | |
1384 | ||
1385 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1386 | { | |
1387 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1388 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1389 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1390 | MAP_PRIVATE, pg_offset); | |
1391 | ||
1392 | if (retbuf != MAP_FAILED) | |
1393 | { | |
1394 | info->was_mmapped = 1; | |
1395 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
1396 | return; | |
1397 | } | |
1398 | } | |
1399 | #endif | |
1400 | ||
1401 | /* If we get here, we are a normal, not-compressed section. */ | |
1402 | info->buffer = buf | |
1403 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1404 | ||
1405 | /* When debugging .o files, we may need to apply relocations; see | |
1406 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1407 | We never compress sections in .o files, so we only need to | |
1408 | try this when the section is not compressed. */ | |
ac8035ab | 1409 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1410 | if (retbuf != NULL) |
1411 | { | |
1412 | info->buffer = retbuf; | |
1413 | return; | |
1414 | } | |
1415 | ||
1416 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1417 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1418 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1419 | bfd_get_filename (abfd)); | |
1420 | } | |
1421 | ||
1422 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1423 | SECTION_NAME. */ | |
af34e669 | 1424 | |
dce234bc PP |
1425 | void |
1426 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1427 | asection **sectp, gdb_byte **bufp, | |
1428 | bfd_size_type *sizep) | |
1429 | { | |
1430 | struct dwarf2_per_objfile *data | |
1431 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1432 | struct dwarf2_section_info *info; | |
1433 | if (section_is_p (section_name, EH_FRAME_SECTION)) | |
1434 | info = &data->eh_frame; | |
1435 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1436 | info = &data->frame; | |
0d53c4c4 | 1437 | else |
dce234bc PP |
1438 | gdb_assert (0); |
1439 | ||
1440 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1441 | /* We haven't read this section in yet. Do it now. */ | |
1442 | dwarf2_read_section (objfile, info); | |
1443 | ||
1444 | *sectp = info->asection; | |
1445 | *bufp = info->buffer; | |
1446 | *sizep = info->size; | |
1447 | } | |
1448 | ||
1449 | /* Build a partial symbol table. */ | |
1450 | ||
1451 | void | |
f29dff0a | 1452 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc PP |
1453 | { |
1454 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
1455 | dwarf2_read_section (objfile, &dwarf2_per_objfile->abbrev); | |
1456 | dwarf2_read_section (objfile, &dwarf2_per_objfile->line); | |
1457 | dwarf2_read_section (objfile, &dwarf2_per_objfile->str); | |
1458 | dwarf2_read_section (objfile, &dwarf2_per_objfile->macinfo); | |
1459 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); | |
348e048f | 1460 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
dce234bc PP |
1461 | dwarf2_read_section (objfile, &dwarf2_per_objfile->loc); |
1462 | dwarf2_read_section (objfile, &dwarf2_per_objfile->eh_frame); | |
1463 | dwarf2_read_section (objfile, &dwarf2_per_objfile->frame); | |
0d53c4c4 | 1464 | |
f29dff0a | 1465 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
1466 | { |
1467 | init_psymbol_list (objfile, 1024); | |
1468 | } | |
1469 | ||
1470 | #if 0 | |
1471 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1472 | { | |
d4f3574e | 1473 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1474 | .debug_pubnames sections */ |
1475 | ||
c67a9c90 | 1476 | dwarf2_build_psymtabs_easy (objfile); |
c906108c SS |
1477 | } |
1478 | else | |
1479 | #endif | |
1480 | /* only test this case for now */ | |
c5aa993b | 1481 | { |
c906108c | 1482 | /* In this case we have to work a bit harder */ |
c67a9c90 | 1483 | dwarf2_build_psymtabs_hard (objfile); |
c906108c SS |
1484 | } |
1485 | } | |
1486 | ||
1487 | #if 0 | |
1488 | /* Build the partial symbol table from the information in the | |
1489 | .debug_pubnames and .debug_aranges sections. */ | |
1490 | ||
1491 | static void | |
c67a9c90 | 1492 | dwarf2_build_psymtabs_easy (struct objfile *objfile) |
c906108c SS |
1493 | { |
1494 | bfd *abfd = objfile->obfd; | |
1495 | char *aranges_buffer, *pubnames_buffer; | |
1496 | char *aranges_ptr, *pubnames_ptr; | |
1497 | unsigned int entry_length, version, info_offset, info_size; | |
1498 | ||
1499 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1500 | dwarf_pubnames_section); |
c906108c | 1501 | pubnames_ptr = pubnames_buffer; |
dce234bc | 1502 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames.size) |
c906108c | 1503 | { |
891d2f0b | 1504 | unsigned int bytes_read; |
613e1657 | 1505 | |
c764a876 | 1506 | entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read); |
613e1657 | 1507 | pubnames_ptr += bytes_read; |
c906108c SS |
1508 | version = read_1_byte (abfd, pubnames_ptr); |
1509 | pubnames_ptr += 1; | |
1510 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1511 | pubnames_ptr += 4; | |
1512 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1513 | pubnames_ptr += 4; | |
1514 | } | |
1515 | ||
1516 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1517 | dwarf_aranges_section); |
c906108c SS |
1518 | |
1519 | } | |
1520 | #endif | |
1521 | ||
45452591 DE |
1522 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
1523 | ||
1524 | static inline int | |
1525 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
1526 | { | |
1527 | unsigned int bottom = cu_header->offset; | |
1528 | unsigned int top = (cu_header->offset | |
1529 | + cu_header->length | |
1530 | + cu_header->initial_length_size); | |
1531 | return (offset >= bottom && offset < top); | |
1532 | } | |
1533 | ||
93311388 DE |
1534 | /* Read in the comp unit header information from the debug_info at info_ptr. |
1535 | NOTE: This leaves members offset, first_die_offset to be filled in | |
1536 | by the caller. */ | |
107d2387 | 1537 | |
fe1b8b76 | 1538 | static gdb_byte * |
107d2387 | 1539 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1540 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1541 | { |
1542 | int signed_addr; | |
891d2f0b | 1543 | unsigned int bytes_read; |
c764a876 DE |
1544 | |
1545 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
1546 | cu_header->initial_length_size = bytes_read; | |
1547 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 1548 | info_ptr += bytes_read; |
107d2387 AC |
1549 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1550 | info_ptr += 2; | |
613e1657 | 1551 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 1552 | &bytes_read); |
613e1657 | 1553 | info_ptr += bytes_read; |
107d2387 AC |
1554 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1555 | info_ptr += 1; | |
1556 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1557 | if (signed_addr < 0) | |
8e65ff28 | 1558 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1559 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 1560 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 1561 | |
107d2387 AC |
1562 | return info_ptr; |
1563 | } | |
1564 | ||
fe1b8b76 JB |
1565 | static gdb_byte * |
1566 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 1567 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
1568 | bfd *abfd) |
1569 | { | |
fe1b8b76 | 1570 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1571 | |
1572 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1573 | ||
2b949cb6 | 1574 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1575 | error (_("Dwarf Error: wrong version in compilation unit header " |
1576 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1577 | 2, bfd_get_filename (abfd)); |
1578 | ||
dce234bc | 1579 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
1580 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1581 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 1582 | (long) header->abbrev_offset, |
93311388 | 1583 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
1584 | bfd_get_filename (abfd)); |
1585 | ||
1586 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 1587 | > buffer + buffer_size) |
8a3fe4f8 AC |
1588 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1589 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 1590 | (long) header->length, |
93311388 | 1591 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
1592 | bfd_get_filename (abfd)); |
1593 | ||
1594 | return info_ptr; | |
1595 | } | |
1596 | ||
348e048f DE |
1597 | /* Read in the types comp unit header information from .debug_types entry at |
1598 | types_ptr. The result is a pointer to one past the end of the header. */ | |
1599 | ||
1600 | static gdb_byte * | |
1601 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
1602 | ULONGEST *signature, | |
1603 | gdb_byte *types_ptr, bfd *abfd) | |
1604 | { | |
1605 | unsigned int bytes_read; | |
1606 | gdb_byte *initial_types_ptr = types_ptr; | |
1607 | ||
1608 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; | |
1609 | ||
1610 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
1611 | ||
1612 | *signature = read_8_bytes (abfd, types_ptr); | |
1613 | types_ptr += 8; | |
1614 | types_ptr += cu_header->offset_size; | |
1615 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
1616 | ||
1617 | return types_ptr; | |
1618 | } | |
1619 | ||
aaa75496 JB |
1620 | /* Allocate a new partial symtab for file named NAME and mark this new |
1621 | partial symtab as being an include of PST. */ | |
1622 | ||
1623 | static void | |
1624 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1625 | struct objfile *objfile) | |
1626 | { | |
1627 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1628 | ||
1629 | subpst->section_offsets = pst->section_offsets; | |
1630 | subpst->textlow = 0; | |
1631 | subpst->texthigh = 0; | |
1632 | ||
1633 | subpst->dependencies = (struct partial_symtab **) | |
1634 | obstack_alloc (&objfile->objfile_obstack, | |
1635 | sizeof (struct partial_symtab *)); | |
1636 | subpst->dependencies[0] = pst; | |
1637 | subpst->number_of_dependencies = 1; | |
1638 | ||
1639 | subpst->globals_offset = 0; | |
1640 | subpst->n_global_syms = 0; | |
1641 | subpst->statics_offset = 0; | |
1642 | subpst->n_static_syms = 0; | |
1643 | subpst->symtab = NULL; | |
1644 | subpst->read_symtab = pst->read_symtab; | |
1645 | subpst->readin = 0; | |
1646 | ||
1647 | /* No private part is necessary for include psymtabs. This property | |
1648 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1649 | the regular ones. */ |
58a9656e | 1650 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1651 | } |
1652 | ||
1653 | /* Read the Line Number Program data and extract the list of files | |
1654 | included by the source file represented by PST. Build an include | |
d85a05f0 | 1655 | partial symtab for each of these included files. */ |
aaa75496 JB |
1656 | |
1657 | static void | |
1658 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 1659 | struct die_info *die, |
aaa75496 JB |
1660 | struct partial_symtab *pst) |
1661 | { | |
1662 | struct objfile *objfile = cu->objfile; | |
1663 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
1664 | struct line_header *lh = NULL; |
1665 | struct attribute *attr; | |
aaa75496 | 1666 | |
d85a05f0 DJ |
1667 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
1668 | if (attr) | |
1669 | { | |
1670 | unsigned int line_offset = DW_UNSND (attr); | |
1671 | lh = dwarf_decode_line_header (line_offset, abfd, cu); | |
1672 | } | |
aaa75496 JB |
1673 | if (lh == NULL) |
1674 | return; /* No linetable, so no includes. */ | |
1675 | ||
1676 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1677 | ||
1678 | free_line_header (lh); | |
1679 | } | |
1680 | ||
348e048f DE |
1681 | static hashval_t |
1682 | hash_type_signature (const void *item) | |
1683 | { | |
1684 | const struct signatured_type *type_sig = item; | |
1685 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ | |
1686 | return type_sig->signature; | |
1687 | } | |
1688 | ||
1689 | static int | |
1690 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
1691 | { | |
1692 | const struct signatured_type *lhs = item_lhs; | |
1693 | const struct signatured_type *rhs = item_rhs; | |
1694 | return lhs->signature == rhs->signature; | |
1695 | } | |
1696 | ||
1697 | /* Create the hash table of all entries in the .debug_types section. | |
1698 | The result is zero if there is an error (e.g. missing .debug_types section), | |
1699 | otherwise non-zero. */ | |
1700 | ||
1701 | static int | |
1702 | create_debug_types_hash_table (struct objfile *objfile) | |
1703 | { | |
1704 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer; | |
1705 | htab_t types_htab; | |
1706 | ||
1707 | if (info_ptr == NULL) | |
1708 | { | |
1709 | dwarf2_per_objfile->signatured_types = NULL; | |
1710 | return 0; | |
1711 | } | |
1712 | ||
1713 | types_htab = htab_create_alloc_ex (41, | |
1714 | hash_type_signature, | |
1715 | eq_type_signature, | |
1716 | NULL, | |
1717 | &objfile->objfile_obstack, | |
1718 | hashtab_obstack_allocate, | |
1719 | dummy_obstack_deallocate); | |
1720 | ||
1721 | if (dwarf2_die_debug) | |
1722 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
1723 | ||
1724 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
1725 | { | |
1726 | unsigned int offset; | |
1727 | unsigned int offset_size; | |
1728 | unsigned int type_offset; | |
1729 | unsigned int length, initial_length_size; | |
1730 | unsigned short version; | |
1731 | ULONGEST signature; | |
1732 | struct signatured_type *type_sig; | |
1733 | void **slot; | |
1734 | gdb_byte *ptr = info_ptr; | |
1735 | ||
1736 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
1737 | ||
1738 | /* We need to read the type's signature in order to build the hash | |
1739 | table, but we don't need to read anything else just yet. */ | |
1740 | ||
1741 | /* Sanity check to ensure entire cu is present. */ | |
1742 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
1743 | if (ptr + length + initial_length_size | |
1744 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
1745 | { | |
1746 | complaint (&symfile_complaints, | |
1747 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
1748 | break; | |
1749 | } | |
1750 | ||
1751 | offset_size = initial_length_size == 4 ? 4 : 8; | |
1752 | ptr += initial_length_size; | |
1753 | version = bfd_get_16 (objfile->obfd, ptr); | |
1754 | ptr += 2; | |
1755 | ptr += offset_size; /* abbrev offset */ | |
1756 | ptr += 1; /* address size */ | |
1757 | signature = bfd_get_64 (objfile->obfd, ptr); | |
1758 | ptr += 8; | |
1759 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
1760 | ||
1761 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
1762 | memset (type_sig, 0, sizeof (*type_sig)); | |
1763 | type_sig->signature = signature; | |
1764 | type_sig->offset = offset; | |
1765 | type_sig->type_offset = type_offset; | |
1766 | ||
1767 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
1768 | gdb_assert (slot != NULL); | |
1769 | *slot = type_sig; | |
1770 | ||
1771 | if (dwarf2_die_debug) | |
1772 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
1773 | offset, phex (signature, sizeof (signature))); | |
1774 | ||
1775 | info_ptr = info_ptr + initial_length_size + length; | |
1776 | } | |
1777 | ||
1778 | dwarf2_per_objfile->signatured_types = types_htab; | |
1779 | ||
1780 | return 1; | |
1781 | } | |
1782 | ||
1783 | /* Lookup a signature based type. | |
1784 | Returns NULL if SIG is not present in the table. */ | |
1785 | ||
1786 | static struct signatured_type * | |
1787 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
1788 | { | |
1789 | struct signatured_type find_entry, *entry; | |
1790 | ||
1791 | if (dwarf2_per_objfile->signatured_types == NULL) | |
1792 | { | |
1793 | complaint (&symfile_complaints, | |
1794 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
1795 | return 0; | |
1796 | } | |
1797 | ||
1798 | find_entry.signature = sig; | |
1799 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
1800 | return entry; | |
1801 | } | |
1802 | ||
d85a05f0 DJ |
1803 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
1804 | ||
1805 | static void | |
1806 | init_cu_die_reader (struct die_reader_specs *reader, | |
1807 | struct dwarf2_cu *cu) | |
1808 | { | |
1809 | reader->abfd = cu->objfile->obfd; | |
1810 | reader->cu = cu; | |
1811 | if (cu->per_cu->from_debug_types) | |
1812 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
1813 | else | |
1814 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
1815 | } | |
1816 | ||
1817 | /* Find the base address of the compilation unit for range lists and | |
1818 | location lists. It will normally be specified by DW_AT_low_pc. | |
1819 | In DWARF-3 draft 4, the base address could be overridden by | |
1820 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
1821 | compilation units with discontinuous ranges. */ | |
1822 | ||
1823 | static void | |
1824 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
1825 | { | |
1826 | struct attribute *attr; | |
1827 | ||
1828 | cu->base_known = 0; | |
1829 | cu->base_address = 0; | |
1830 | ||
1831 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
1832 | if (attr) | |
1833 | { | |
1834 | cu->base_address = DW_ADDR (attr); | |
1835 | cu->base_known = 1; | |
1836 | } | |
1837 | else | |
1838 | { | |
1839 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
1840 | if (attr) | |
1841 | { | |
1842 | cu->base_address = DW_ADDR (attr); | |
1843 | cu->base_known = 1; | |
1844 | } | |
1845 | } | |
1846 | } | |
1847 | ||
348e048f DE |
1848 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
1849 | to combine the common parts. | |
93311388 | 1850 | Process a compilation unit for a psymtab. |
348e048f DE |
1851 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
1852 | either .debug_info or debug_types. | |
93311388 DE |
1853 | INFO_PTR is a pointer to the start of the CU. |
1854 | Returns a pointer to the next CU. */ | |
aaa75496 | 1855 | |
93311388 DE |
1856 | static gdb_byte * |
1857 | process_psymtab_comp_unit (struct objfile *objfile, | |
1858 | struct dwarf2_per_cu_data *this_cu, | |
1859 | gdb_byte *buffer, gdb_byte *info_ptr, | |
1860 | unsigned int buffer_size) | |
c906108c | 1861 | { |
c906108c | 1862 | bfd *abfd = objfile->obfd; |
93311388 | 1863 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 1864 | struct die_info *comp_unit_die; |
c906108c | 1865 | struct partial_symtab *pst; |
5734ee8b | 1866 | CORE_ADDR baseaddr; |
93311388 DE |
1867 | struct cleanup *back_to_inner; |
1868 | struct dwarf2_cu cu; | |
93311388 | 1869 | unsigned int bytes_read; |
d85a05f0 DJ |
1870 | int has_children, has_pc_info; |
1871 | struct attribute *attr; | |
1872 | const char *name; | |
1873 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
1874 | struct die_reader_specs reader_specs; | |
c906108c | 1875 | |
93311388 DE |
1876 | memset (&cu, 0, sizeof (cu)); |
1877 | cu.objfile = objfile; | |
1878 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 1879 | |
93311388 | 1880 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 1881 | |
93311388 DE |
1882 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
1883 | buffer, buffer_size, | |
1884 | abfd); | |
10b3939b | 1885 | |
93311388 DE |
1886 | /* Complete the cu_header. */ |
1887 | cu.header.offset = beg_of_comp_unit - buffer; | |
1888 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 1889 | |
93311388 | 1890 | cu.list_in_scope = &file_symbols; |
af703f96 | 1891 | |
328c9494 DJ |
1892 | /* If this compilation unit was already read in, free the |
1893 | cached copy in order to read it in again. This is | |
1894 | necessary because we skipped some symbols when we first | |
1895 | read in the compilation unit (see load_partial_dies). | |
1896 | This problem could be avoided, but the benefit is | |
1897 | unclear. */ | |
1898 | if (this_cu->cu != NULL) | |
1899 | free_one_cached_comp_unit (this_cu->cu); | |
1900 | ||
1901 | /* Note that this is a pointer to our stack frame, being | |
1902 | added to a global data structure. It will be cleaned up | |
1903 | in free_stack_comp_unit when we finish with this | |
1904 | compilation unit. */ | |
1905 | this_cu->cu = &cu; | |
d85a05f0 DJ |
1906 | cu.per_cu = this_cu; |
1907 | ||
93311388 DE |
1908 | /* Read the abbrevs for this compilation unit into a table. */ |
1909 | dwarf2_read_abbrevs (abfd, &cu); | |
1910 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 1911 | |
93311388 | 1912 | /* Read the compilation unit die. */ |
348e048f DE |
1913 | if (this_cu->from_debug_types) |
1914 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
1915 | init_cu_die_reader (&reader_specs, &cu); |
1916 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
1917 | &has_children); | |
93311388 | 1918 | |
348e048f DE |
1919 | if (this_cu->from_debug_types) |
1920 | { | |
1921 | /* offset,length haven't been set yet for type units. */ | |
1922 | this_cu->offset = cu.header.offset; | |
1923 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
1924 | } | |
d85a05f0 | 1925 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 1926 | { |
93311388 DE |
1927 | info_ptr = (beg_of_comp_unit + cu.header.length |
1928 | + cu.header.initial_length_size); | |
1929 | do_cleanups (back_to_inner); | |
1930 | return info_ptr; | |
1931 | } | |
72bf9492 | 1932 | |
93311388 | 1933 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
1934 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
1935 | if (attr) | |
1936 | set_cu_language (DW_UNSND (attr), &cu); | |
1937 | else | |
1938 | set_cu_language (language_minimal, &cu); | |
c906108c | 1939 | |
93311388 | 1940 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 1941 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 1942 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 1943 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
1944 | /* TEXTLOW and TEXTHIGH are set below. */ |
1945 | 0, | |
1946 | objfile->global_psymbols.next, | |
1947 | objfile->static_psymbols.next); | |
72bf9492 | 1948 | |
d85a05f0 DJ |
1949 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
1950 | if (attr != NULL) | |
1951 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 1952 | |
93311388 | 1953 | pst->read_symtab_private = (char *) this_cu; |
72bf9492 | 1954 | |
93311388 | 1955 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 1956 | |
93311388 DE |
1957 | /* Store the function that reads in the rest of the symbol table */ |
1958 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 1959 | |
93311388 | 1960 | this_cu->psymtab = pst; |
c906108c | 1961 | |
d85a05f0 DJ |
1962 | dwarf2_find_base_address (comp_unit_die, &cu); |
1963 | ||
93311388 DE |
1964 | /* Possibly set the default values of LOWPC and HIGHPC from |
1965 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
1966 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
1967 | &best_highpc, &cu, pst); | |
1968 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
1969 | /* Store the contiguous range if it is not empty; it can be empty for |
1970 | CUs with no code. */ | |
1971 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
1972 | best_lowpc + baseaddr, |
1973 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
1974 | |
1975 | /* Check if comp unit has_children. | |
1976 | If so, read the rest of the partial symbols from this comp unit. | |
1977 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 1978 | if (has_children) |
93311388 DE |
1979 | { |
1980 | struct partial_die_info *first_die; | |
1981 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 1982 | |
93311388 DE |
1983 | lowpc = ((CORE_ADDR) -1); |
1984 | highpc = ((CORE_ADDR) 0); | |
c906108c | 1985 | |
93311388 | 1986 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 1987 | |
93311388 | 1988 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 1989 | ! has_pc_info, &cu); |
57c22c6c | 1990 | |
93311388 DE |
1991 | /* If we didn't find a lowpc, set it to highpc to avoid |
1992 | complaints from `maint check'. */ | |
1993 | if (lowpc == ((CORE_ADDR) -1)) | |
1994 | lowpc = highpc; | |
10b3939b | 1995 | |
93311388 DE |
1996 | /* If the compilation unit didn't have an explicit address range, |
1997 | then use the information extracted from its child dies. */ | |
d85a05f0 | 1998 | if (! has_pc_info) |
93311388 | 1999 | { |
d85a05f0 DJ |
2000 | best_lowpc = lowpc; |
2001 | best_highpc = highpc; | |
93311388 DE |
2002 | } |
2003 | } | |
d85a05f0 DJ |
2004 | pst->textlow = best_lowpc + baseaddr; |
2005 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 2006 | |
93311388 DE |
2007 | pst->n_global_syms = objfile->global_psymbols.next - |
2008 | (objfile->global_psymbols.list + pst->globals_offset); | |
2009 | pst->n_static_syms = objfile->static_psymbols.next - | |
2010 | (objfile->static_psymbols.list + pst->statics_offset); | |
2011 | sort_pst_symbols (pst); | |
c906108c | 2012 | |
93311388 DE |
2013 | info_ptr = (beg_of_comp_unit + cu.header.length |
2014 | + cu.header.initial_length_size); | |
ae038cb0 | 2015 | |
348e048f DE |
2016 | if (this_cu->from_debug_types) |
2017 | { | |
2018 | /* It's not clear we want to do anything with stmt lists here. | |
2019 | Waiting to see what gcc ultimately does. */ | |
2020 | } | |
d85a05f0 | 2021 | else |
93311388 DE |
2022 | { |
2023 | /* Get the list of files included in the current compilation unit, | |
2024 | and build a psymtab for each of them. */ | |
d85a05f0 | 2025 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 2026 | } |
ae038cb0 | 2027 | |
93311388 | 2028 | do_cleanups (back_to_inner); |
ae038cb0 | 2029 | |
93311388 DE |
2030 | return info_ptr; |
2031 | } | |
ff013f42 | 2032 | |
348e048f DE |
2033 | /* Traversal function for htab_traverse_noresize. |
2034 | Process one .debug_types comp-unit. */ | |
2035 | ||
2036 | static int | |
2037 | process_type_comp_unit (void **slot, void *info) | |
2038 | { | |
2039 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
2040 | struct objfile *objfile = (struct objfile *) info; | |
2041 | struct dwarf2_per_cu_data *this_cu; | |
2042 | ||
2043 | this_cu = &entry->per_cu; | |
2044 | this_cu->from_debug_types = 1; | |
2045 | ||
2046 | process_psymtab_comp_unit (objfile, this_cu, | |
2047 | dwarf2_per_objfile->types.buffer, | |
2048 | dwarf2_per_objfile->types.buffer + entry->offset, | |
2049 | dwarf2_per_objfile->types.size); | |
2050 | ||
2051 | return 1; | |
2052 | } | |
2053 | ||
2054 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
2055 | Build partial symbol tables for the .debug_types comp-units. */ | |
2056 | ||
2057 | static void | |
2058 | build_type_psymtabs (struct objfile *objfile) | |
2059 | { | |
2060 | if (! create_debug_types_hash_table (objfile)) | |
2061 | return; | |
2062 | ||
2063 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
2064 | process_type_comp_unit, objfile); | |
2065 | } | |
2066 | ||
93311388 DE |
2067 | /* Build the partial symbol table by doing a quick pass through the |
2068 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 2069 | |
93311388 | 2070 | static void |
c67a9c90 | 2071 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 DE |
2072 | { |
2073 | /* Instead of reading this into a big buffer, we should probably use | |
2074 | mmap() on architectures that support it. (FIXME) */ | |
2075 | bfd *abfd = objfile->obfd; | |
2076 | gdb_byte *info_ptr; | |
2077 | struct cleanup *back_to; | |
2078 | ||
2079 | info_ptr = dwarf2_per_objfile->info.buffer; | |
91c24f0a | 2080 | |
93311388 DE |
2081 | /* Any cached compilation units will be linked by the per-objfile |
2082 | read_in_chain. Make sure to free them when we're done. */ | |
2083 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 2084 | |
348e048f DE |
2085 | build_type_psymtabs (objfile); |
2086 | ||
93311388 | 2087 | create_all_comp_units (objfile); |
c906108c | 2088 | |
93311388 DE |
2089 | objfile->psymtabs_addrmap = |
2090 | addrmap_create_mutable (&objfile->objfile_obstack); | |
72bf9492 | 2091 | |
93311388 DE |
2092 | /* Since the objects we're extracting from .debug_info vary in |
2093 | length, only the individual functions to extract them (like | |
2094 | read_comp_unit_head and load_partial_die) can really know whether | |
2095 | the buffer is large enough to hold another complete object. | |
c906108c | 2096 | |
93311388 DE |
2097 | At the moment, they don't actually check that. If .debug_info |
2098 | holds just one extra byte after the last compilation unit's dies, | |
2099 | then read_comp_unit_head will happily read off the end of the | |
2100 | buffer. read_partial_die is similarly casual. Those functions | |
2101 | should be fixed. | |
c906108c | 2102 | |
93311388 DE |
2103 | For this loop condition, simply checking whether there's any data |
2104 | left at all should be sufficient. */ | |
c906108c | 2105 | |
93311388 DE |
2106 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
2107 | + dwarf2_per_objfile->info.size)) | |
2108 | { | |
2109 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 2110 | |
93311388 DE |
2111 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
2112 | objfile); | |
aaa75496 | 2113 | |
93311388 DE |
2114 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
2115 | dwarf2_per_objfile->info.buffer, | |
2116 | info_ptr, | |
2117 | dwarf2_per_objfile->info.size); | |
c906108c | 2118 | } |
ff013f42 JK |
2119 | |
2120 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
2121 | &objfile->objfile_obstack); | |
2122 | ||
ae038cb0 DJ |
2123 | do_cleanups (back_to); |
2124 | } | |
2125 | ||
93311388 | 2126 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
2127 | |
2128 | static void | |
93311388 DE |
2129 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
2130 | struct objfile *objfile) | |
ae038cb0 DJ |
2131 | { |
2132 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 2133 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 2134 | struct die_info *comp_unit_die; |
ae038cb0 | 2135 | struct dwarf2_cu *cu; |
ae038cb0 DJ |
2136 | unsigned int bytes_read; |
2137 | struct cleanup *back_to; | |
d85a05f0 DJ |
2138 | struct attribute *attr; |
2139 | int has_children; | |
2140 | struct die_reader_specs reader_specs; | |
ae038cb0 | 2141 | |
348e048f DE |
2142 | gdb_assert (! this_cu->from_debug_types); |
2143 | ||
dce234bc | 2144 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
2145 | beg_of_comp_unit = info_ptr; |
2146 | ||
93311388 | 2147 | cu = alloc_one_comp_unit (objfile); |
ae038cb0 | 2148 | |
93311388 | 2149 | /* ??? Missing cleanup for CU? */ |
ae038cb0 | 2150 | |
328c9494 DJ |
2151 | /* Link this compilation unit into the compilation unit tree. */ |
2152 | this_cu->cu = cu; | |
2153 | cu->per_cu = this_cu; | |
2154 | cu->type_hash = this_cu->type_hash; | |
2155 | ||
93311388 DE |
2156 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
2157 | dwarf2_per_objfile->info.buffer, | |
2158 | dwarf2_per_objfile->info.size, | |
2159 | abfd); | |
ae038cb0 DJ |
2160 | |
2161 | /* Complete the cu_header. */ | |
93311388 | 2162 | cu->header.offset = this_cu->offset; |
d00adf39 | 2163 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
2164 | |
2165 | /* Read the abbrevs for this compilation unit into a table. */ | |
2166 | dwarf2_read_abbrevs (abfd, cu); | |
2167 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2168 | ||
2169 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
2170 | init_cu_die_reader (&reader_specs, cu); |
2171 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2172 | &has_children); | |
ae038cb0 DJ |
2173 | |
2174 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
2175 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
2176 | if (attr) | |
2177 | set_cu_language (DW_UNSND (attr), cu); | |
2178 | else | |
2179 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 2180 | |
ae038cb0 DJ |
2181 | /* Check if comp unit has_children. |
2182 | If so, read the rest of the partial symbols from this comp unit. | |
2183 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 2184 | if (has_children) |
93311388 | 2185 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 DJ |
2186 | |
2187 | do_cleanups (back_to); | |
2188 | } | |
2189 | ||
2190 | /* Create a list of all compilation units in OBJFILE. We do this only | |
2191 | if an inter-comp-unit reference is found; presumably if there is one, | |
2192 | there will be many, and one will occur early in the .debug_info section. | |
2193 | So there's no point in building this list incrementally. */ | |
2194 | ||
2195 | static void | |
2196 | create_all_comp_units (struct objfile *objfile) | |
2197 | { | |
2198 | int n_allocated; | |
2199 | int n_comp_units; | |
2200 | struct dwarf2_per_cu_data **all_comp_units; | |
dce234bc | 2201 | gdb_byte *info_ptr = dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
2202 | |
2203 | n_comp_units = 0; | |
2204 | n_allocated = 10; | |
2205 | all_comp_units = xmalloc (n_allocated | |
2206 | * sizeof (struct dwarf2_per_cu_data *)); | |
2207 | ||
dce234bc | 2208 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 2209 | { |
c764a876 | 2210 | unsigned int length, initial_length_size; |
fe1b8b76 | 2211 | gdb_byte *beg_of_comp_unit; |
ae038cb0 | 2212 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 2213 | unsigned int offset; |
ae038cb0 | 2214 | |
dce234bc | 2215 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
2216 | |
2217 | /* Read just enough information to find out where the next | |
2218 | compilation unit is. */ | |
c764a876 DE |
2219 | length = read_initial_length (objfile->obfd, info_ptr, |
2220 | &initial_length_size); | |
ae038cb0 DJ |
2221 | |
2222 | /* Save the compilation unit for later lookup. */ | |
2223 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
2224 | sizeof (struct dwarf2_per_cu_data)); | |
2225 | memset (this_cu, 0, sizeof (*this_cu)); | |
2226 | this_cu->offset = offset; | |
c764a876 | 2227 | this_cu->length = length + initial_length_size; |
ae038cb0 DJ |
2228 | |
2229 | if (n_comp_units == n_allocated) | |
2230 | { | |
2231 | n_allocated *= 2; | |
2232 | all_comp_units = xrealloc (all_comp_units, | |
2233 | n_allocated | |
2234 | * sizeof (struct dwarf2_per_cu_data *)); | |
2235 | } | |
2236 | all_comp_units[n_comp_units++] = this_cu; | |
2237 | ||
2238 | info_ptr = info_ptr + this_cu->length; | |
2239 | } | |
2240 | ||
2241 | dwarf2_per_objfile->all_comp_units | |
2242 | = obstack_alloc (&objfile->objfile_obstack, | |
2243 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
2244 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
2245 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
2246 | xfree (all_comp_units); | |
2247 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
2248 | } |
2249 | ||
5734ee8b DJ |
2250 | /* Process all loaded DIEs for compilation unit CU, starting at |
2251 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
2252 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
2253 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
2254 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
2255 | and record the covered ranges in the addrmap. */ | |
c906108c | 2256 | |
72bf9492 DJ |
2257 | static void |
2258 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 2259 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 2260 | { |
e7c27a73 | 2261 | struct objfile *objfile = cu->objfile; |
c906108c | 2262 | bfd *abfd = objfile->obfd; |
72bf9492 | 2263 | struct partial_die_info *pdi; |
c906108c | 2264 | |
91c24f0a DC |
2265 | /* Now, march along the PDI's, descending into ones which have |
2266 | interesting children but skipping the children of the other ones, | |
2267 | until we reach the end of the compilation unit. */ | |
c906108c | 2268 | |
72bf9492 | 2269 | pdi = first_die; |
91c24f0a | 2270 | |
72bf9492 DJ |
2271 | while (pdi != NULL) |
2272 | { | |
2273 | fixup_partial_die (pdi, cu); | |
c906108c | 2274 | |
91c24f0a DC |
2275 | /* Anonymous namespaces have no name but have interesting |
2276 | children, so we need to look at them. Ditto for anonymous | |
2277 | enums. */ | |
933c6fe4 | 2278 | |
72bf9492 DJ |
2279 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
2280 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 2281 | { |
72bf9492 | 2282 | switch (pdi->tag) |
c906108c SS |
2283 | { |
2284 | case DW_TAG_subprogram: | |
5734ee8b | 2285 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
2286 | break; |
2287 | case DW_TAG_variable: | |
2288 | case DW_TAG_typedef: | |
91c24f0a | 2289 | case DW_TAG_union_type: |
72bf9492 | 2290 | if (!pdi->is_declaration) |
63d06c5c | 2291 | { |
72bf9492 | 2292 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
2293 | } |
2294 | break; | |
c906108c | 2295 | case DW_TAG_class_type: |
680b30c7 | 2296 | case DW_TAG_interface_type: |
c906108c | 2297 | case DW_TAG_structure_type: |
72bf9492 | 2298 | if (!pdi->is_declaration) |
c906108c | 2299 | { |
72bf9492 | 2300 | add_partial_symbol (pdi, cu); |
c906108c SS |
2301 | } |
2302 | break; | |
91c24f0a | 2303 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
2304 | if (!pdi->is_declaration) |
2305 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
2306 | break; |
2307 | case DW_TAG_base_type: | |
a02abb62 | 2308 | case DW_TAG_subrange_type: |
c906108c | 2309 | /* File scope base type definitions are added to the partial |
c5aa993b | 2310 | symbol table. */ |
72bf9492 | 2311 | add_partial_symbol (pdi, cu); |
c906108c | 2312 | break; |
d9fa45fe | 2313 | case DW_TAG_namespace: |
5734ee8b | 2314 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 2315 | break; |
5d7cb8df JK |
2316 | case DW_TAG_module: |
2317 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
2318 | break; | |
c906108c SS |
2319 | default: |
2320 | break; | |
2321 | } | |
2322 | } | |
2323 | ||
72bf9492 DJ |
2324 | /* If the die has a sibling, skip to the sibling. */ |
2325 | ||
2326 | pdi = pdi->die_sibling; | |
2327 | } | |
2328 | } | |
2329 | ||
2330 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 2331 | |
72bf9492 | 2332 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
2333 | name is concatenated with "::" and the partial DIE's name. For |
2334 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
2335 | Enumerators are an exception; they use the scope of their parent |
2336 | enumeration type, i.e. the name of the enumeration type is not | |
2337 | prepended to the enumerator. | |
91c24f0a | 2338 | |
72bf9492 DJ |
2339 | There are two complexities. One is DW_AT_specification; in this |
2340 | case "parent" means the parent of the target of the specification, | |
2341 | instead of the direct parent of the DIE. The other is compilers | |
2342 | which do not emit DW_TAG_namespace; in this case we try to guess | |
2343 | the fully qualified name of structure types from their members' | |
2344 | linkage names. This must be done using the DIE's children rather | |
2345 | than the children of any DW_AT_specification target. We only need | |
2346 | to do this for structures at the top level, i.e. if the target of | |
2347 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
2348 | have a parent. */ | |
2349 | ||
2350 | /* Compute the scope prefix associated with PDI's parent, in | |
2351 | compilation unit CU. The result will be allocated on CU's | |
2352 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
2353 | field. NULL is returned if no prefix is necessary. */ | |
2354 | static char * | |
2355 | partial_die_parent_scope (struct partial_die_info *pdi, | |
2356 | struct dwarf2_cu *cu) | |
2357 | { | |
2358 | char *grandparent_scope; | |
2359 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 2360 | |
72bf9492 DJ |
2361 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
2362 | then this means the parent of the specification DIE. */ | |
2363 | ||
2364 | real_pdi = pdi; | |
72bf9492 | 2365 | while (real_pdi->has_specification) |
10b3939b | 2366 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
2367 | |
2368 | parent = real_pdi->die_parent; | |
2369 | if (parent == NULL) | |
2370 | return NULL; | |
2371 | ||
2372 | if (parent->scope_set) | |
2373 | return parent->scope; | |
2374 | ||
2375 | fixup_partial_die (parent, cu); | |
2376 | ||
10b3939b | 2377 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
2378 | |
2379 | if (parent->tag == DW_TAG_namespace | |
2380 | || parent->tag == DW_TAG_structure_type | |
2381 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 2382 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
2383 | || parent->tag == DW_TAG_union_type |
2384 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
2385 | { |
2386 | if (grandparent_scope == NULL) | |
2387 | parent->scope = parent->name; | |
2388 | else | |
987504bb JJ |
2389 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
2390 | parent->name, cu); | |
72bf9492 | 2391 | } |
ceeb3d5a | 2392 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
2393 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
2394 | parent->scope = grandparent_scope; | |
2395 | else | |
2396 | { | |
2397 | /* FIXME drow/2004-04-01: What should we be doing with | |
2398 | function-local names? For partial symbols, we should probably be | |
2399 | ignoring them. */ | |
2400 | complaint (&symfile_complaints, | |
e2e0b3e5 | 2401 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
2402 | parent->tag, pdi->offset); |
2403 | parent->scope = grandparent_scope; | |
c906108c SS |
2404 | } |
2405 | ||
72bf9492 DJ |
2406 | parent->scope_set = 1; |
2407 | return parent->scope; | |
2408 | } | |
2409 | ||
2410 | /* Return the fully scoped name associated with PDI, from compilation unit | |
2411 | CU. The result will be allocated with malloc. */ | |
2412 | static char * | |
2413 | partial_die_full_name (struct partial_die_info *pdi, | |
2414 | struct dwarf2_cu *cu) | |
2415 | { | |
2416 | char *parent_scope; | |
2417 | ||
2418 | parent_scope = partial_die_parent_scope (pdi, cu); | |
2419 | if (parent_scope == NULL) | |
2420 | return NULL; | |
2421 | else | |
987504bb | 2422 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
2423 | } |
2424 | ||
2425 | static void | |
72bf9492 | 2426 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 2427 | { |
e7c27a73 | 2428 | struct objfile *objfile = cu->objfile; |
c906108c | 2429 | CORE_ADDR addr = 0; |
decbce07 | 2430 | char *actual_name = NULL; |
72bf9492 | 2431 | const char *my_prefix; |
5c4e30ca | 2432 | const struct partial_symbol *psym = NULL; |
e142c38c | 2433 | CORE_ADDR baseaddr; |
72bf9492 | 2434 | int built_actual_name = 0; |
e142c38c DJ |
2435 | |
2436 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2437 | |
94af9270 KS |
2438 | actual_name = partial_die_full_name (pdi, cu); |
2439 | if (actual_name) | |
2440 | built_actual_name = 1; | |
63d06c5c | 2441 | |
72bf9492 DJ |
2442 | if (actual_name == NULL) |
2443 | actual_name = pdi->name; | |
2444 | ||
c906108c SS |
2445 | switch (pdi->tag) |
2446 | { | |
2447 | case DW_TAG_subprogram: | |
2cfa0c8d | 2448 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 2449 | { |
2cfa0c8d JB |
2450 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
2451 | of the global scope. But in Ada, we want to be able to access | |
2452 | nested procedures globally. So all Ada subprograms are stored | |
2453 | in the global scope. */ | |
38d518c9 | 2454 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2455 | mst_text, objfile); */ |
38d518c9 | 2456 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2457 | built_actual_name, |
5c4e30ca DC |
2458 | VAR_DOMAIN, LOC_BLOCK, |
2459 | &objfile->global_psymbols, | |
2460 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2461 | cu->language, objfile); |
c906108c SS |
2462 | } |
2463 | else | |
2464 | { | |
38d518c9 | 2465 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2466 | mst_file_text, objfile); */ |
38d518c9 | 2467 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2468 | built_actual_name, |
5c4e30ca DC |
2469 | VAR_DOMAIN, LOC_BLOCK, |
2470 | &objfile->static_psymbols, | |
2471 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2472 | cu->language, objfile); |
c906108c SS |
2473 | } |
2474 | break; | |
2475 | case DW_TAG_variable: | |
2476 | if (pdi->is_external) | |
2477 | { | |
2478 | /* Global Variable. | |
2479 | Don't enter into the minimal symbol tables as there is | |
2480 | a minimal symbol table entry from the ELF symbols already. | |
2481 | Enter into partial symbol table if it has a location | |
2482 | descriptor or a type. | |
2483 | If the location descriptor is missing, new_symbol will create | |
2484 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
2485 | be determined from the minimal symbol table whenever the variable | |
2486 | is referenced. | |
2487 | The address for the partial symbol table entry is not | |
2488 | used by GDB, but it comes in handy for debugging partial symbol | |
2489 | table building. */ | |
2490 | ||
2491 | if (pdi->locdesc) | |
e7c27a73 | 2492 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2493 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2494 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2495 | built_actual_name, |
5c4e30ca DC |
2496 | VAR_DOMAIN, LOC_STATIC, |
2497 | &objfile->global_psymbols, | |
2498 | 0, addr + baseaddr, | |
e142c38c | 2499 | cu->language, objfile); |
c906108c SS |
2500 | } |
2501 | else | |
2502 | { | |
2503 | /* Static Variable. Skip symbols without location descriptors. */ | |
2504 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2505 | { |
2506 | if (built_actual_name) | |
2507 | xfree (actual_name); | |
2508 | return; | |
2509 | } | |
e7c27a73 | 2510 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2511 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2512 | mst_file_data, objfile); */ |
38d518c9 | 2513 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2514 | built_actual_name, |
5c4e30ca DC |
2515 | VAR_DOMAIN, LOC_STATIC, |
2516 | &objfile->static_psymbols, | |
2517 | 0, addr + baseaddr, | |
e142c38c | 2518 | cu->language, objfile); |
c906108c SS |
2519 | } |
2520 | break; | |
2521 | case DW_TAG_typedef: | |
2522 | case DW_TAG_base_type: | |
a02abb62 | 2523 | case DW_TAG_subrange_type: |
38d518c9 | 2524 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2525 | built_actual_name, |
176620f1 | 2526 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2527 | &objfile->static_psymbols, |
e142c38c | 2528 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2529 | break; |
72bf9492 DJ |
2530 | case DW_TAG_namespace: |
2531 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 2532 | built_actual_name, |
72bf9492 DJ |
2533 | VAR_DOMAIN, LOC_TYPEDEF, |
2534 | &objfile->global_psymbols, | |
2535 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2536 | break; | |
c906108c | 2537 | case DW_TAG_class_type: |
680b30c7 | 2538 | case DW_TAG_interface_type: |
c906108c SS |
2539 | case DW_TAG_structure_type: |
2540 | case DW_TAG_union_type: | |
2541 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2542 | /* Skip external references. The DWARF standard says in the section |
2543 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2544 | structure, union or class type is represented by a structure, | |
2545 | union or class entry that does not have a byte size attribute | |
2546 | and that has a DW_AT_declaration attribute." */ | |
2547 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2548 | { |
2549 | if (built_actual_name) | |
2550 | xfree (actual_name); | |
2551 | return; | |
2552 | } | |
fa4028e9 | 2553 | |
63d06c5c DC |
2554 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2555 | static vs. global. */ | |
38d518c9 | 2556 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2557 | built_actual_name, |
176620f1 | 2558 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2559 | (cu->language == language_cplus |
2560 | || cu->language == language_java) | |
63d06c5c DC |
2561 | ? &objfile->global_psymbols |
2562 | : &objfile->static_psymbols, | |
e142c38c | 2563 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2564 | |
c906108c SS |
2565 | break; |
2566 | case DW_TAG_enumerator: | |
38d518c9 | 2567 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2568 | built_actual_name, |
176620f1 | 2569 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2570 | (cu->language == language_cplus |
2571 | || cu->language == language_java) | |
f6fe98ef DJ |
2572 | ? &objfile->global_psymbols |
2573 | : &objfile->static_psymbols, | |
e142c38c | 2574 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2575 | break; |
2576 | default: | |
2577 | break; | |
2578 | } | |
5c4e30ca | 2579 | |
72bf9492 DJ |
2580 | if (built_actual_name) |
2581 | xfree (actual_name); | |
c906108c SS |
2582 | } |
2583 | ||
5c4e30ca DC |
2584 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2585 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2586 | the name of the enclosing namespace. */ | |
91c24f0a | 2587 | |
72bf9492 DJ |
2588 | static void |
2589 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2590 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 2591 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 2592 | { |
e7c27a73 | 2593 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2594 | |
72bf9492 | 2595 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2596 | |
72bf9492 | 2597 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2598 | |
2599 | /* Now scan partial symbols in that namespace. */ | |
2600 | ||
91c24f0a | 2601 | if (pdi->has_children) |
5734ee8b | 2602 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
2603 | } |
2604 | ||
5d7cb8df JK |
2605 | /* Read a partial die corresponding to a Fortran module. */ |
2606 | ||
2607 | static void | |
2608 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
2609 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
2610 | { | |
2611 | /* Now scan partial symbols in that module. | |
2612 | ||
2613 | FIXME: Support the separate Fortran module namespaces. */ | |
2614 | ||
2615 | if (pdi->has_children) | |
2616 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
2617 | } | |
2618 | ||
bc30ff58 JB |
2619 | /* Read a partial die corresponding to a subprogram and create a partial |
2620 | symbol for that subprogram. When the CU language allows it, this | |
2621 | routine also defines a partial symbol for each nested subprogram | |
2622 | that this subprogram contains. | |
2623 | ||
2624 | DIE my also be a lexical block, in which case we simply search | |
2625 | recursively for suprograms defined inside that lexical block. | |
2626 | Again, this is only performed when the CU language allows this | |
2627 | type of definitions. */ | |
2628 | ||
2629 | static void | |
2630 | add_partial_subprogram (struct partial_die_info *pdi, | |
2631 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 2632 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
2633 | { |
2634 | if (pdi->tag == DW_TAG_subprogram) | |
2635 | { | |
2636 | if (pdi->has_pc_info) | |
2637 | { | |
2638 | if (pdi->lowpc < *lowpc) | |
2639 | *lowpc = pdi->lowpc; | |
2640 | if (pdi->highpc > *highpc) | |
2641 | *highpc = pdi->highpc; | |
5734ee8b DJ |
2642 | if (need_pc) |
2643 | { | |
2644 | CORE_ADDR baseaddr; | |
2645 | struct objfile *objfile = cu->objfile; | |
2646 | ||
2647 | baseaddr = ANOFFSET (objfile->section_offsets, | |
2648 | SECT_OFF_TEXT (objfile)); | |
2649 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
2650 | pdi->lowpc + baseaddr, |
2651 | pdi->highpc - 1 + baseaddr, | |
5734ee8b DJ |
2652 | cu->per_cu->psymtab); |
2653 | } | |
bc30ff58 JB |
2654 | if (!pdi->is_declaration) |
2655 | add_partial_symbol (pdi, cu); | |
2656 | } | |
2657 | } | |
2658 | ||
2659 | if (! pdi->has_children) | |
2660 | return; | |
2661 | ||
2662 | if (cu->language == language_ada) | |
2663 | { | |
2664 | pdi = pdi->die_child; | |
2665 | while (pdi != NULL) | |
2666 | { | |
2667 | fixup_partial_die (pdi, cu); | |
2668 | if (pdi->tag == DW_TAG_subprogram | |
2669 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 2670 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
2671 | pdi = pdi->die_sibling; |
2672 | } | |
2673 | } | |
2674 | } | |
2675 | ||
72bf9492 DJ |
2676 | /* See if we can figure out if the class lives in a namespace. We do |
2677 | this by looking for a member function; its demangled name will | |
2678 | contain namespace info, if there is any. */ | |
63d06c5c | 2679 | |
72bf9492 DJ |
2680 | static void |
2681 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2682 | struct dwarf2_cu *cu) | |
63d06c5c | 2683 | { |
987504bb JJ |
2684 | if ((cu->language == language_cplus |
2685 | || cu->language == language_java) | |
72bf9492 | 2686 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2687 | && struct_pdi->has_children) |
2688 | { | |
63d06c5c DC |
2689 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2690 | what template types look like, because the demangler | |
2691 | frequently doesn't give the same name as the debug info. We | |
2692 | could fix this by only using the demangled name to get the | |
134d01f1 | 2693 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2694 | |
72bf9492 | 2695 | struct partial_die_info *real_pdi; |
5d51ca54 | 2696 | |
72bf9492 DJ |
2697 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2698 | we should not do this. We'll prepend the parent's fully qualified | |
2699 | name when we create the partial symbol. */ | |
5d51ca54 | 2700 | |
72bf9492 | 2701 | real_pdi = struct_pdi; |
72bf9492 | 2702 | while (real_pdi->has_specification) |
10b3939b | 2703 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2704 | |
72bf9492 DJ |
2705 | if (real_pdi->die_parent != NULL) |
2706 | return; | |
63d06c5c | 2707 | } |
63d06c5c DC |
2708 | } |
2709 | ||
91c24f0a DC |
2710 | /* Read a partial die corresponding to an enumeration type. */ |
2711 | ||
72bf9492 DJ |
2712 | static void |
2713 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2714 | struct dwarf2_cu *cu) | |
91c24f0a | 2715 | { |
e7c27a73 | 2716 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2717 | bfd *abfd = objfile->obfd; |
72bf9492 | 2718 | struct partial_die_info *pdi; |
91c24f0a DC |
2719 | |
2720 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2721 | add_partial_symbol (enum_pdi, cu); |
2722 | ||
2723 | pdi = enum_pdi->die_child; | |
2724 | while (pdi) | |
91c24f0a | 2725 | { |
72bf9492 | 2726 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2727 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2728 | else |
72bf9492 DJ |
2729 | add_partial_symbol (pdi, cu); |
2730 | pdi = pdi->die_sibling; | |
91c24f0a | 2731 | } |
91c24f0a DC |
2732 | } |
2733 | ||
4bb7a0a7 DJ |
2734 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2735 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2736 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2737 | the initial number. */ | |
2738 | ||
2739 | static struct abbrev_info * | |
fe1b8b76 | 2740 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2741 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2742 | { |
2743 | bfd *abfd = cu->objfile->obfd; | |
2744 | unsigned int abbrev_number; | |
2745 | struct abbrev_info *abbrev; | |
2746 | ||
2747 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2748 | ||
2749 | if (abbrev_number == 0) | |
2750 | return NULL; | |
2751 | ||
2752 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2753 | if (!abbrev) | |
2754 | { | |
8a3fe4f8 | 2755 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2756 | bfd_get_filename (abfd)); |
2757 | } | |
2758 | ||
2759 | return abbrev; | |
2760 | } | |
2761 | ||
93311388 DE |
2762 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2763 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
2764 | DIE. Any children of the skipped DIEs will also be skipped. */ |
2765 | ||
fe1b8b76 | 2766 | static gdb_byte * |
93311388 | 2767 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2768 | { |
2769 | struct abbrev_info *abbrev; | |
2770 | unsigned int bytes_read; | |
2771 | ||
2772 | while (1) | |
2773 | { | |
2774 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2775 | if (abbrev == NULL) | |
2776 | return info_ptr + bytes_read; | |
2777 | else | |
93311388 | 2778 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
2779 | } |
2780 | } | |
2781 | ||
93311388 DE |
2782 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2783 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
2784 | abbrev corresponding to that skipped uleb128 should be passed in |
2785 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2786 | children. */ | |
2787 | ||
fe1b8b76 | 2788 | static gdb_byte * |
93311388 DE |
2789 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
2790 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2791 | { |
2792 | unsigned int bytes_read; | |
2793 | struct attribute attr; | |
2794 | bfd *abfd = cu->objfile->obfd; | |
2795 | unsigned int form, i; | |
2796 | ||
2797 | for (i = 0; i < abbrev->num_attrs; i++) | |
2798 | { | |
2799 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2800 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2801 | { | |
2802 | read_attribute (&attr, &abbrev->attrs[i], | |
2803 | abfd, info_ptr, cu); | |
2804 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2805 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2806 | else |
93311388 | 2807 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
2808 | } |
2809 | ||
2810 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2811 | form = abbrev->attrs[i].form; | |
2812 | skip_attribute: | |
2813 | switch (form) | |
2814 | { | |
4bb7a0a7 | 2815 | case DW_FORM_ref_addr: |
ae411497 TT |
2816 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
2817 | and later it is offset sized. */ | |
2818 | if (cu->header.version == 2) | |
2819 | info_ptr += cu->header.addr_size; | |
2820 | else | |
2821 | info_ptr += cu->header.offset_size; | |
2822 | break; | |
2823 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
2824 | info_ptr += cu->header.addr_size; |
2825 | break; | |
2826 | case DW_FORM_data1: | |
2827 | case DW_FORM_ref1: | |
2828 | case DW_FORM_flag: | |
2829 | info_ptr += 1; | |
2830 | break; | |
2831 | case DW_FORM_data2: | |
2832 | case DW_FORM_ref2: | |
2833 | info_ptr += 2; | |
2834 | break; | |
2835 | case DW_FORM_data4: | |
2836 | case DW_FORM_ref4: | |
2837 | info_ptr += 4; | |
2838 | break; | |
2839 | case DW_FORM_data8: | |
2840 | case DW_FORM_ref8: | |
348e048f | 2841 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
2842 | info_ptr += 8; |
2843 | break; | |
2844 | case DW_FORM_string: | |
2845 | read_string (abfd, info_ptr, &bytes_read); | |
2846 | info_ptr += bytes_read; | |
2847 | break; | |
2848 | case DW_FORM_strp: | |
2849 | info_ptr += cu->header.offset_size; | |
2850 | break; | |
2851 | case DW_FORM_block: | |
2852 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2853 | info_ptr += bytes_read; | |
2854 | break; | |
2855 | case DW_FORM_block1: | |
2856 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2857 | break; | |
2858 | case DW_FORM_block2: | |
2859 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2860 | break; | |
2861 | case DW_FORM_block4: | |
2862 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2863 | break; | |
2864 | case DW_FORM_sdata: | |
2865 | case DW_FORM_udata: | |
2866 | case DW_FORM_ref_udata: | |
2867 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2868 | break; | |
2869 | case DW_FORM_indirect: | |
2870 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2871 | info_ptr += bytes_read; | |
2872 | /* We need to continue parsing from here, so just go back to | |
2873 | the top. */ | |
2874 | goto skip_attribute; | |
2875 | ||
2876 | default: | |
8a3fe4f8 | 2877 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2878 | dwarf_form_name (form), |
2879 | bfd_get_filename (abfd)); | |
2880 | } | |
2881 | } | |
2882 | ||
2883 | if (abbrev->has_children) | |
93311388 | 2884 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
2885 | else |
2886 | return info_ptr; | |
2887 | } | |
2888 | ||
93311388 DE |
2889 | /* Locate ORIG_PDI's sibling. |
2890 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
2891 | in BUFFER. */ | |
91c24f0a | 2892 | |
fe1b8b76 | 2893 | static gdb_byte * |
93311388 DE |
2894 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
2895 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 2896 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2897 | { |
2898 | /* Do we know the sibling already? */ | |
72bf9492 | 2899 | |
91c24f0a DC |
2900 | if (orig_pdi->sibling) |
2901 | return orig_pdi->sibling; | |
2902 | ||
2903 | /* Are there any children to deal with? */ | |
2904 | ||
2905 | if (!orig_pdi->has_children) | |
2906 | return info_ptr; | |
2907 | ||
4bb7a0a7 | 2908 | /* Skip the children the long way. */ |
91c24f0a | 2909 | |
93311388 | 2910 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
2911 | } |
2912 | ||
c906108c SS |
2913 | /* Expand this partial symbol table into a full symbol table. */ |
2914 | ||
2915 | static void | |
fba45db2 | 2916 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2917 | { |
2918 | /* FIXME: This is barely more than a stub. */ | |
2919 | if (pst != NULL) | |
2920 | { | |
2921 | if (pst->readin) | |
2922 | { | |
8a3fe4f8 | 2923 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2924 | } |
2925 | else | |
2926 | { | |
2927 | if (info_verbose) | |
2928 | { | |
a3f17187 | 2929 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2930 | gdb_flush (gdb_stdout); |
2931 | } | |
2932 | ||
10b3939b DJ |
2933 | /* Restore our global data. */ |
2934 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2935 | dwarf2_objfile_data_key); | |
2936 | ||
b2ab525c KB |
2937 | /* If this psymtab is constructed from a debug-only objfile, the |
2938 | has_section_at_zero flag will not necessarily be correct. We | |
2939 | can get the correct value for this flag by looking at the data | |
2940 | associated with the (presumably stripped) associated objfile. */ | |
2941 | if (pst->objfile->separate_debug_objfile_backlink) | |
2942 | { | |
2943 | struct dwarf2_per_objfile *dpo_backlink | |
2944 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
2945 | dwarf2_objfile_data_key); | |
2946 | dwarf2_per_objfile->has_section_at_zero | |
2947 | = dpo_backlink->has_section_at_zero; | |
2948 | } | |
2949 | ||
c906108c SS |
2950 | psymtab_to_symtab_1 (pst); |
2951 | ||
2952 | /* Finish up the debug error message. */ | |
2953 | if (info_verbose) | |
a3f17187 | 2954 | printf_filtered (_("done.\n")); |
c906108c SS |
2955 | } |
2956 | } | |
2957 | } | |
2958 | ||
10b3939b DJ |
2959 | /* Add PER_CU to the queue. */ |
2960 | ||
2961 | static void | |
03dd20cc | 2962 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
2963 | { |
2964 | struct dwarf2_queue_item *item; | |
2965 | ||
2966 | per_cu->queued = 1; | |
2967 | item = xmalloc (sizeof (*item)); | |
2968 | item->per_cu = per_cu; | |
2969 | item->next = NULL; | |
2970 | ||
2971 | if (dwarf2_queue == NULL) | |
2972 | dwarf2_queue = item; | |
2973 | else | |
2974 | dwarf2_queue_tail->next = item; | |
2975 | ||
2976 | dwarf2_queue_tail = item; | |
2977 | } | |
2978 | ||
2979 | /* Process the queue. */ | |
2980 | ||
2981 | static void | |
2982 | process_queue (struct objfile *objfile) | |
2983 | { | |
2984 | struct dwarf2_queue_item *item, *next_item; | |
2985 | ||
03dd20cc DJ |
2986 | /* The queue starts out with one item, but following a DIE reference |
2987 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
2988 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
2989 | { | |
31ffec48 | 2990 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2991 | process_full_comp_unit (item->per_cu); |
2992 | ||
2993 | item->per_cu->queued = 0; | |
2994 | next_item = item->next; | |
2995 | xfree (item); | |
2996 | } | |
2997 | ||
2998 | dwarf2_queue_tail = NULL; | |
2999 | } | |
3000 | ||
3001 | /* Free all allocated queue entries. This function only releases anything if | |
3002 | an error was thrown; if the queue was processed then it would have been | |
3003 | freed as we went along. */ | |
3004 | ||
3005 | static void | |
3006 | dwarf2_release_queue (void *dummy) | |
3007 | { | |
3008 | struct dwarf2_queue_item *item, *last; | |
3009 | ||
3010 | item = dwarf2_queue; | |
3011 | while (item) | |
3012 | { | |
3013 | /* Anything still marked queued is likely to be in an | |
3014 | inconsistent state, so discard it. */ | |
3015 | if (item->per_cu->queued) | |
3016 | { | |
3017 | if (item->per_cu->cu != NULL) | |
3018 | free_one_cached_comp_unit (item->per_cu->cu); | |
3019 | item->per_cu->queued = 0; | |
3020 | } | |
3021 | ||
3022 | last = item; | |
3023 | item = item->next; | |
3024 | xfree (last); | |
3025 | } | |
3026 | ||
3027 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
3028 | } | |
3029 | ||
3030 | /* Read in full symbols for PST, and anything it depends on. */ | |
3031 | ||
c906108c | 3032 | static void |
fba45db2 | 3033 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 3034 | { |
10b3939b | 3035 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 3036 | struct cleanup *back_to; |
aaa75496 JB |
3037 | int i; |
3038 | ||
3039 | for (i = 0; i < pst->number_of_dependencies; i++) | |
3040 | if (!pst->dependencies[i]->readin) | |
3041 | { | |
3042 | /* Inform about additional files that need to be read in. */ | |
3043 | if (info_verbose) | |
3044 | { | |
a3f17187 | 3045 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
3046 | fputs_filtered (" ", gdb_stdout); |
3047 | wrap_here (""); | |
3048 | fputs_filtered ("and ", gdb_stdout); | |
3049 | wrap_here (""); | |
3050 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
3051 | wrap_here (""); /* Flush output */ | |
3052 | gdb_flush (gdb_stdout); | |
3053 | } | |
3054 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
3055 | } | |
3056 | ||
10b3939b DJ |
3057 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
3058 | ||
3059 | if (per_cu == NULL) | |
aaa75496 JB |
3060 | { |
3061 | /* It's an include file, no symbols to read for it. | |
3062 | Everything is in the parent symtab. */ | |
3063 | pst->readin = 1; | |
3064 | return; | |
3065 | } | |
c906108c | 3066 | |
10b3939b DJ |
3067 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
3068 | ||
03dd20cc | 3069 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b | 3070 | |
348e048f DE |
3071 | if (per_cu->from_debug_types) |
3072 | read_signatured_type_at_offset (pst->objfile, per_cu->offset); | |
3073 | else | |
3074 | load_full_comp_unit (per_cu, pst->objfile); | |
3075 | ||
10b3939b DJ |
3076 | process_queue (pst->objfile); |
3077 | ||
3078 | /* Age the cache, releasing compilation units that have not | |
3079 | been used recently. */ | |
3080 | age_cached_comp_units (); | |
3081 | ||
3082 | do_cleanups (back_to); | |
3083 | } | |
3084 | ||
93311388 | 3085 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 3086 | |
93311388 | 3087 | static void |
31ffec48 | 3088 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 3089 | { |
31ffec48 | 3090 | bfd *abfd = objfile->obfd; |
10b3939b | 3091 | struct dwarf2_cu *cu; |
c764a876 | 3092 | unsigned int offset; |
93311388 | 3093 | gdb_byte *info_ptr, *beg_of_comp_unit; |
10b3939b DJ |
3094 | struct cleanup *back_to, *free_cu_cleanup; |
3095 | struct attribute *attr; | |
3096 | CORE_ADDR baseaddr; | |
6502dd73 | 3097 | |
348e048f DE |
3098 | gdb_assert (! per_cu->from_debug_types); |
3099 | ||
c906108c | 3100 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 3101 | offset = per_cu->offset; |
6502dd73 | 3102 | |
dce234bc | 3103 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 3104 | beg_of_comp_unit = info_ptr; |
63d06c5c | 3105 | |
93311388 | 3106 | cu = alloc_one_comp_unit (objfile); |
c906108c | 3107 | |
10b3939b DJ |
3108 | /* If an error occurs while loading, release our storage. */ |
3109 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 3110 | |
93311388 | 3111 | /* Read in the comp_unit header. */ |
10b3939b | 3112 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c | 3113 | |
93311388 DE |
3114 | /* Complete the cu_header. */ |
3115 | cu->header.offset = offset; | |
3116 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3117 | ||
3118 | /* Read the abbrevs for this compilation unit. */ | |
10b3939b DJ |
3119 | dwarf2_read_abbrevs (abfd, cu); |
3120 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
3121 | ||
93311388 | 3122 | /* Link this compilation unit into the compilation unit tree. */ |
10b3939b | 3123 | per_cu->cu = cu; |
93311388 | 3124 | cu->per_cu = per_cu; |
f792889a | 3125 | cu->type_hash = per_cu->type_hash; |
e142c38c | 3126 | |
93311388 | 3127 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
3128 | |
3129 | /* We try not to read any attributes in this function, because not | |
3130 | all objfiles needed for references have been loaded yet, and symbol | |
3131 | table processing isn't initialized. But we have to set the CU language, | |
3132 | or we won't be able to build types correctly. */ | |
3133 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
3134 | if (attr) | |
3135 | set_cu_language (DW_UNSND (attr), cu); | |
3136 | else | |
3137 | set_cu_language (language_minimal, cu); | |
3138 | ||
348e048f DE |
3139 | /* Link this CU into read_in_chain. */ |
3140 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3141 | dwarf2_per_objfile->read_in_chain = per_cu; | |
3142 | ||
10b3939b | 3143 | do_cleanups (back_to); |
e142c38c | 3144 | |
10b3939b DJ |
3145 | /* We've successfully allocated this compilation unit. Let our caller |
3146 | clean it up when finished with it. */ | |
3147 | discard_cleanups (free_cu_cleanup); | |
10b3939b DJ |
3148 | } |
3149 | ||
3150 | /* Generate full symbol information for PST and CU, whose DIEs have | |
3151 | already been loaded into memory. */ | |
3152 | ||
3153 | static void | |
3154 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
3155 | { | |
3156 | struct partial_symtab *pst = per_cu->psymtab; | |
3157 | struct dwarf2_cu *cu = per_cu->cu; | |
3158 | struct objfile *objfile = pst->objfile; | |
3159 | bfd *abfd = objfile->obfd; | |
3160 | CORE_ADDR lowpc, highpc; | |
3161 | struct symtab *symtab; | |
3162 | struct cleanup *back_to; | |
10b3939b DJ |
3163 | CORE_ADDR baseaddr; |
3164 | ||
3165 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3166 | ||
10b3939b DJ |
3167 | buildsym_init (); |
3168 | back_to = make_cleanup (really_free_pendings, NULL); | |
3169 | ||
3170 | cu->list_in_scope = &file_symbols; | |
c906108c | 3171 | |
d85a05f0 | 3172 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 3173 | |
c906108c | 3174 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 3175 | process_die (cu->dies, cu); |
c906108c | 3176 | |
fae299cd DC |
3177 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
3178 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
3179 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 3180 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 3181 | |
613e1657 | 3182 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3183 | |
3184 | /* Set symtab language to language from DW_AT_language. | |
3185 | If the compilation is from a C file generated by language preprocessors, | |
3186 | do not set the language if it was already deduced by start_subfile. */ | |
3187 | if (symtab != NULL | |
10b3939b | 3188 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 3189 | { |
10b3939b | 3190 | symtab->language = cu->language; |
c906108c SS |
3191 | } |
3192 | pst->symtab = symtab; | |
3193 | pst->readin = 1; | |
c906108c SS |
3194 | |
3195 | do_cleanups (back_to); | |
3196 | } | |
3197 | ||
3198 | /* Process a die and its children. */ | |
3199 | ||
3200 | static void | |
e7c27a73 | 3201 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3202 | { |
3203 | switch (die->tag) | |
3204 | { | |
3205 | case DW_TAG_padding: | |
3206 | break; | |
3207 | case DW_TAG_compile_unit: | |
e7c27a73 | 3208 | read_file_scope (die, cu); |
c906108c | 3209 | break; |
348e048f DE |
3210 | case DW_TAG_type_unit: |
3211 | read_type_unit_scope (die, cu); | |
3212 | break; | |
c906108c | 3213 | case DW_TAG_subprogram: |
c906108c | 3214 | case DW_TAG_inlined_subroutine: |
edb3359d | 3215 | read_func_scope (die, cu); |
c906108c SS |
3216 | break; |
3217 | case DW_TAG_lexical_block: | |
14898363 L |
3218 | case DW_TAG_try_block: |
3219 | case DW_TAG_catch_block: | |
e7c27a73 | 3220 | read_lexical_block_scope (die, cu); |
c906108c SS |
3221 | break; |
3222 | case DW_TAG_class_type: | |
680b30c7 | 3223 | case DW_TAG_interface_type: |
c906108c SS |
3224 | case DW_TAG_structure_type: |
3225 | case DW_TAG_union_type: | |
134d01f1 | 3226 | process_structure_scope (die, cu); |
c906108c SS |
3227 | break; |
3228 | case DW_TAG_enumeration_type: | |
134d01f1 | 3229 | process_enumeration_scope (die, cu); |
c906108c | 3230 | break; |
134d01f1 | 3231 | |
f792889a DJ |
3232 | /* These dies have a type, but processing them does not create |
3233 | a symbol or recurse to process the children. Therefore we can | |
3234 | read them on-demand through read_type_die. */ | |
c906108c | 3235 | case DW_TAG_subroutine_type: |
72019c9c | 3236 | case DW_TAG_set_type: |
c906108c | 3237 | case DW_TAG_array_type: |
c906108c | 3238 | case DW_TAG_pointer_type: |
c906108c | 3239 | case DW_TAG_ptr_to_member_type: |
c906108c | 3240 | case DW_TAG_reference_type: |
c906108c | 3241 | case DW_TAG_string_type: |
c906108c | 3242 | break; |
134d01f1 | 3243 | |
c906108c | 3244 | case DW_TAG_base_type: |
a02abb62 | 3245 | case DW_TAG_subrange_type: |
cb249c71 | 3246 | case DW_TAG_typedef: |
134d01f1 DJ |
3247 | /* Add a typedef symbol for the type definition, if it has a |
3248 | DW_AT_name. */ | |
f792889a | 3249 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 3250 | break; |
c906108c | 3251 | case DW_TAG_common_block: |
e7c27a73 | 3252 | read_common_block (die, cu); |
c906108c SS |
3253 | break; |
3254 | case DW_TAG_common_inclusion: | |
3255 | break; | |
d9fa45fe | 3256 | case DW_TAG_namespace: |
63d06c5c | 3257 | processing_has_namespace_info = 1; |
e7c27a73 | 3258 | read_namespace (die, cu); |
d9fa45fe | 3259 | break; |
5d7cb8df JK |
3260 | case DW_TAG_module: |
3261 | read_module (die, cu); | |
3262 | break; | |
d9fa45fe DC |
3263 | case DW_TAG_imported_declaration: |
3264 | case DW_TAG_imported_module: | |
63d06c5c | 3265 | processing_has_namespace_info = 1; |
27aa8d6a SW |
3266 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
3267 | || cu->language != language_fortran)) | |
3268 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
3269 | dwarf_tag_name (die->tag)); | |
3270 | read_import_statement (die, cu); | |
d9fa45fe | 3271 | break; |
c906108c | 3272 | default: |
e7c27a73 | 3273 | new_symbol (die, NULL, cu); |
c906108c SS |
3274 | break; |
3275 | } | |
3276 | } | |
3277 | ||
94af9270 KS |
3278 | /* A helper function for dwarf2_compute_name which determines whether DIE |
3279 | needs to have the name of the scope prepended to the name listed in the | |
3280 | die. */ | |
3281 | ||
3282 | static int | |
3283 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
3284 | { | |
3285 | switch (die->tag) | |
3286 | { | |
3287 | case DW_TAG_namespace: | |
3288 | case DW_TAG_typedef: | |
3289 | case DW_TAG_class_type: | |
3290 | case DW_TAG_interface_type: | |
3291 | case DW_TAG_structure_type: | |
3292 | case DW_TAG_union_type: | |
3293 | case DW_TAG_enumeration_type: | |
3294 | case DW_TAG_enumerator: | |
3295 | case DW_TAG_subprogram: | |
3296 | case DW_TAG_member: | |
3297 | return 1; | |
3298 | ||
3299 | case DW_TAG_variable: | |
3300 | /* We only need to prefix "globally" visible variables. These include | |
3301 | any variable marked with DW_AT_external or any variable that | |
3302 | lives in a namespace. [Variables in anonymous namespaces | |
3303 | require prefixing, but they are not DW_AT_external.] */ | |
3304 | ||
3305 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
3306 | { | |
3307 | struct dwarf2_cu *spec_cu = cu; | |
3308 | return die_needs_namespace (die_specification (die, &spec_cu), | |
3309 | spec_cu); | |
3310 | } | |
3311 | ||
3312 | if (dwarf2_attr (die, DW_AT_external, cu) | |
3313 | || die->parent->tag == DW_TAG_namespace) | |
3314 | return 1; | |
3315 | ||
3316 | return 0; | |
3317 | ||
3318 | default: | |
3319 | return 0; | |
3320 | } | |
3321 | } | |
3322 | ||
3323 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, | |
3324 | compute the physname for the object, which include a method's | |
3325 | formal parameters (C++/Java) and return type (Java). | |
3326 | ||
af6b7be1 JB |
3327 | For Ada, return the DIE's linkage name rather than the fully qualified |
3328 | name. PHYSNAME is ignored.. | |
3329 | ||
94af9270 KS |
3330 | The result is allocated on the objfile_obstack and canonicalized. */ |
3331 | ||
3332 | static const char * | |
3333 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
3334 | int physname) | |
3335 | { | |
3336 | if (name == NULL) | |
3337 | name = dwarf2_name (die, cu); | |
3338 | ||
3339 | /* These are the only languages we know how to qualify names in. */ | |
3340 | if (name != NULL | |
3341 | && (cu->language == language_cplus || cu->language == language_java)) | |
3342 | { | |
3343 | if (die_needs_namespace (die, cu)) | |
3344 | { | |
3345 | long length; | |
3346 | char *prefix; | |
3347 | struct ui_file *buf; | |
3348 | ||
3349 | prefix = determine_prefix (die, cu); | |
3350 | buf = mem_fileopen (); | |
3351 | if (*prefix != '\0') | |
3352 | { | |
3353 | char *prefixed_name = typename_concat (NULL, prefix, name, cu); | |
3354 | fputs_unfiltered (prefixed_name, buf); | |
3355 | xfree (prefixed_name); | |
3356 | } | |
3357 | else | |
3358 | fputs_unfiltered (name ? name : "", buf); | |
3359 | ||
3360 | /* For Java and C++ methods, append formal parameter type | |
3361 | information, if PHYSNAME. */ | |
3362 | ||
3363 | if (physname && die->tag == DW_TAG_subprogram | |
3364 | && (cu->language == language_cplus | |
3365 | || cu->language == language_java)) | |
3366 | { | |
3367 | struct type *type = read_type_die (die, cu); | |
3368 | ||
3369 | c_type_print_args (type, buf, 0, cu->language); | |
3370 | ||
3371 | if (cu->language == language_java) | |
3372 | { | |
3373 | /* For java, we must append the return type to method | |
3374 | names. */ | |
3375 | if (die->tag == DW_TAG_subprogram) | |
3376 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
3377 | 0, 0); | |
3378 | } | |
3379 | else if (cu->language == language_cplus) | |
3380 | { | |
3381 | if (TYPE_NFIELDS (type) > 0 | |
3382 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
3383 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)))) | |
3384 | fputs_unfiltered (" const", buf); | |
3385 | } | |
3386 | } | |
3387 | ||
3388 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
3389 | &length); | |
3390 | ui_file_delete (buf); | |
3391 | ||
3392 | if (cu->language == language_cplus) | |
3393 | { | |
3394 | char *cname | |
3395 | = dwarf2_canonicalize_name (name, cu, | |
3396 | &cu->objfile->objfile_obstack); | |
3397 | if (cname != NULL) | |
3398 | name = cname; | |
3399 | } | |
3400 | } | |
3401 | } | |
af6b7be1 JB |
3402 | else if (cu->language == language_ada) |
3403 | { | |
3404 | /* For Ada unit, we prefer the linkage name over the name, as | |
3405 | the former contains the exported name, which the user expects | |
3406 | to be able to reference. Ideally, we want the user to be able | |
3407 | to reference this entity using either natural or linkage name, | |
3408 | but we haven't started looking at this enhancement yet. */ | |
3409 | struct attribute *attr; | |
3410 | ||
3411 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
3412 | if (attr && DW_STRING (attr)) | |
3413 | name = DW_STRING (attr); | |
3414 | } | |
94af9270 KS |
3415 | |
3416 | return name; | |
3417 | } | |
3418 | ||
0114d602 DJ |
3419 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
3420 | If scope qualifiers are appropriate they will be added. The result | |
3421 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
3422 | not have a name. NAME may either be from a previous call to |
3423 | dwarf2_name or NULL. | |
3424 | ||
3425 | The output string will be canonicalized (if C++/Java). */ | |
0114d602 DJ |
3426 | |
3427 | static const char * | |
94af9270 | 3428 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 3429 | { |
94af9270 KS |
3430 | return dwarf2_compute_name (name, die, cu, 0); |
3431 | } | |
0114d602 | 3432 | |
94af9270 KS |
3433 | /* Construct a physname for the given DIE in CU. NAME may either be |
3434 | from a previous call to dwarf2_name or NULL. The result will be | |
3435 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
3436 | name. | |
0114d602 | 3437 | |
94af9270 | 3438 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 3439 | |
94af9270 KS |
3440 | static const char * |
3441 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
3442 | { | |
3443 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
3444 | } |
3445 | ||
27aa8d6a SW |
3446 | /* Read the import statement specified by the given die and record it. */ |
3447 | ||
3448 | static void | |
3449 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
3450 | { | |
3451 | struct attribute *import_attr; | |
3452 | struct die_info *imported_die; | |
de4affc9 | 3453 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 3454 | const char *imported_name; |
794684b6 | 3455 | const char *imported_name_prefix; |
82856980 SW |
3456 | char *import_alias; |
3457 | ||
794684b6 SW |
3458 | const char *import_prefix; |
3459 | char *canonical_name; | |
27aa8d6a SW |
3460 | |
3461 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
3462 | if (import_attr == NULL) | |
3463 | { | |
3464 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
3465 | dwarf_tag_name (die->tag)); | |
3466 | return; | |
3467 | } | |
3468 | ||
de4affc9 CC |
3469 | imported_cu = cu; |
3470 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
3471 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
3472 | if (imported_name == NULL) |
3473 | { | |
3474 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
3475 | ||
3476 | The import in the following code: | |
3477 | namespace A | |
3478 | { | |
3479 | typedef int B; | |
3480 | } | |
3481 | ||
3482 | int main () | |
3483 | { | |
3484 | using A::B; | |
3485 | B b; | |
3486 | return b; | |
3487 | } | |
3488 | ||
3489 | ... | |
3490 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
3491 | <52> DW_AT_decl_file : 1 | |
3492 | <53> DW_AT_decl_line : 6 | |
3493 | <54> DW_AT_import : <0x75> | |
3494 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
3495 | <59> DW_AT_name : B | |
3496 | <5b> DW_AT_decl_file : 1 | |
3497 | <5c> DW_AT_decl_line : 2 | |
3498 | <5d> DW_AT_type : <0x6e> | |
3499 | ... | |
3500 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
3501 | <76> DW_AT_byte_size : 4 | |
3502 | <77> DW_AT_encoding : 5 (signed) | |
3503 | ||
3504 | imports the wrong die ( 0x75 instead of 0x58 ). | |
3505 | This case will be ignored until the gcc bug is fixed. */ | |
3506 | return; | |
3507 | } | |
3508 | ||
82856980 SW |
3509 | /* Figure out the local name after import. */ |
3510 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 3511 | |
794684b6 SW |
3512 | /* Figure out where the statement is being imported to. */ |
3513 | import_prefix = determine_prefix (die, cu); | |
3514 | ||
3515 | /* Figure out what the scope of the imported die is and prepend it | |
3516 | to the name of the imported die. */ | |
de4affc9 | 3517 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 SW |
3518 | |
3519 | if (strlen (imported_name_prefix) > 0) | |
3520 | { | |
82856980 SW |
3521 | canonical_name = alloca (strlen (imported_name_prefix) |
3522 | + 2 + strlen (imported_name) + 1); | |
794684b6 SW |
3523 | strcpy (canonical_name, imported_name_prefix); |
3524 | strcat (canonical_name, "::"); | |
3525 | strcat (canonical_name, imported_name); | |
3526 | } | |
3527 | else | |
3528 | { | |
3529 | canonical_name = alloca (strlen (imported_name) + 1); | |
3530 | strcpy (canonical_name, imported_name); | |
3531 | } | |
3532 | ||
82856980 SW |
3533 | using_directives = cp_add_using (import_prefix, |
3534 | canonical_name, | |
3535 | import_alias, | |
3536 | using_directives); | |
27aa8d6a SW |
3537 | } |
3538 | ||
5fb290d7 | 3539 | static void |
e142c38c | 3540 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 3541 | { |
e142c38c | 3542 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
3543 | } |
3544 | ||
cb1df416 DJ |
3545 | static void |
3546 | free_cu_line_header (void *arg) | |
3547 | { | |
3548 | struct dwarf2_cu *cu = arg; | |
3549 | ||
3550 | free_line_header (cu->line_header); | |
3551 | cu->line_header = NULL; | |
3552 | } | |
3553 | ||
c906108c | 3554 | static void |
e7c27a73 | 3555 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3556 | { |
e7c27a73 DJ |
3557 | struct objfile *objfile = cu->objfile; |
3558 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 3559 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 3560 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
3561 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
3562 | struct attribute *attr; | |
e1024ff1 | 3563 | char *name = NULL; |
c906108c SS |
3564 | char *comp_dir = NULL; |
3565 | struct die_info *child_die; | |
3566 | bfd *abfd = objfile->obfd; | |
debd256d | 3567 | struct line_header *line_header = 0; |
e142c38c DJ |
3568 | CORE_ADDR baseaddr; |
3569 | ||
3570 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3571 | |
fae299cd | 3572 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
3573 | |
3574 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
3575 | from finish_block. */ | |
2acceee2 | 3576 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
3577 | lowpc = highpc; |
3578 | lowpc += baseaddr; | |
3579 | highpc += baseaddr; | |
3580 | ||
39cbfefa DJ |
3581 | /* Find the filename. Do not use dwarf2_name here, since the filename |
3582 | is not a source language identifier. */ | |
e142c38c | 3583 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3584 | if (attr) |
3585 | { | |
3586 | name = DW_STRING (attr); | |
3587 | } | |
e1024ff1 | 3588 | |
e142c38c | 3589 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 3590 | if (attr) |
e1024ff1 DJ |
3591 | comp_dir = DW_STRING (attr); |
3592 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 3593 | { |
e1024ff1 DJ |
3594 | comp_dir = ldirname (name); |
3595 | if (comp_dir != NULL) | |
3596 | make_cleanup (xfree, comp_dir); | |
3597 | } | |
3598 | if (comp_dir != NULL) | |
3599 | { | |
3600 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
3601 | directory, get rid of it. */ | |
3602 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 3603 | |
e1024ff1 DJ |
3604 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
3605 | comp_dir = cp + 1; | |
c906108c SS |
3606 | } |
3607 | ||
e1024ff1 DJ |
3608 | if (name == NULL) |
3609 | name = "<unknown>"; | |
3610 | ||
e142c38c | 3611 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
3612 | if (attr) |
3613 | { | |
e142c38c | 3614 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
3615 | } |
3616 | ||
b0f35d58 DL |
3617 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
3618 | if (attr) | |
3619 | cu->producer = DW_STRING (attr); | |
303b6f5d | 3620 | |
c906108c SS |
3621 | /* We assume that we're processing GCC output. */ |
3622 | processing_gcc_compilation = 2; | |
c906108c | 3623 | |
df8a16a1 DJ |
3624 | processing_has_namespace_info = 0; |
3625 | ||
c906108c SS |
3626 | start_symtab (name, comp_dir, lowpc); |
3627 | record_debugformat ("DWARF 2"); | |
303b6f5d | 3628 | record_producer (cu->producer); |
c906108c | 3629 | |
e142c38c | 3630 | initialize_cu_func_list (cu); |
c906108c | 3631 | |
cb1df416 DJ |
3632 | /* Decode line number information if present. We do this before |
3633 | processing child DIEs, so that the line header table is available | |
3634 | for DW_AT_decl_file. */ | |
e142c38c | 3635 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
3636 | if (attr) |
3637 | { | |
debd256d | 3638 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 3639 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
3640 | if (line_header) |
3641 | { | |
cb1df416 DJ |
3642 | cu->line_header = line_header; |
3643 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 3644 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 3645 | } |
5fb290d7 | 3646 | } |
debd256d | 3647 | |
cb1df416 DJ |
3648 | /* Process all dies in compilation unit. */ |
3649 | if (die->child != NULL) | |
3650 | { | |
3651 | child_die = die->child; | |
3652 | while (child_die && child_die->tag) | |
3653 | { | |
3654 | process_die (child_die, cu); | |
3655 | child_die = sibling_die (child_die); | |
3656 | } | |
3657 | } | |
3658 | ||
2e276125 JB |
3659 | /* Decode macro information, if present. Dwarf 2 macro information |
3660 | refers to information in the line number info statement program | |
3661 | header, so we can only read it if we've read the header | |
3662 | successfully. */ | |
e142c38c | 3663 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 3664 | if (attr && line_header) |
2e276125 JB |
3665 | { |
3666 | unsigned int macro_offset = DW_UNSND (attr); | |
3667 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 3668 | comp_dir, abfd, cu); |
2e276125 | 3669 | } |
debd256d | 3670 | do_cleanups (back_to); |
5fb290d7 DJ |
3671 | } |
3672 | ||
348e048f DE |
3673 | /* For TUs we want to skip the first top level sibling if it's not the |
3674 | actual type being defined by this TU. In this case the first top | |
3675 | level sibling is there to provide context only. */ | |
3676 | ||
3677 | static void | |
3678 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3679 | { | |
3680 | struct objfile *objfile = cu->objfile; | |
3681 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
3682 | CORE_ADDR lowpc; | |
3683 | struct attribute *attr; | |
3684 | char *name = NULL; | |
3685 | char *comp_dir = NULL; | |
3686 | struct die_info *child_die; | |
3687 | bfd *abfd = objfile->obfd; | |
3688 | struct line_header *line_header = 0; | |
3689 | ||
3690 | /* start_symtab needs a low pc, but we don't really have one. | |
3691 | Do what read_file_scope would do in the absence of such info. */ | |
3692 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3693 | ||
3694 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
3695 | is not a source language identifier. */ | |
3696 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
3697 | if (attr) | |
3698 | name = DW_STRING (attr); | |
3699 | ||
3700 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
3701 | if (attr) | |
3702 | comp_dir = DW_STRING (attr); | |
3703 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
3704 | { | |
3705 | comp_dir = ldirname (name); | |
3706 | if (comp_dir != NULL) | |
3707 | make_cleanup (xfree, comp_dir); | |
3708 | } | |
3709 | ||
3710 | if (name == NULL) | |
3711 | name = "<unknown>"; | |
3712 | ||
3713 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
3714 | if (attr) | |
3715 | set_cu_language (DW_UNSND (attr), cu); | |
3716 | ||
3717 | /* This isn't technically needed today. It is done for symmetry | |
3718 | with read_file_scope. */ | |
3719 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
3720 | if (attr) | |
3721 | cu->producer = DW_STRING (attr); | |
3722 | ||
3723 | /* We assume that we're processing GCC output. */ | |
3724 | processing_gcc_compilation = 2; | |
3725 | ||
3726 | processing_has_namespace_info = 0; | |
3727 | ||
3728 | start_symtab (name, comp_dir, lowpc); | |
3729 | record_debugformat ("DWARF 2"); | |
3730 | record_producer (cu->producer); | |
3731 | ||
3732 | /* Process the dies in the type unit. */ | |
3733 | if (die->child == NULL) | |
3734 | { | |
3735 | dump_die_for_error (die); | |
3736 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
3737 | bfd_get_filename (abfd)); | |
3738 | } | |
3739 | ||
3740 | child_die = die->child; | |
3741 | ||
3742 | while (child_die && child_die->tag) | |
3743 | { | |
3744 | process_die (child_die, cu); | |
3745 | ||
3746 | child_die = sibling_die (child_die); | |
3747 | } | |
3748 | ||
3749 | do_cleanups (back_to); | |
3750 | } | |
3751 | ||
5fb290d7 | 3752 | static void |
e142c38c DJ |
3753 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
3754 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
3755 | { |
3756 | struct function_range *thisfn; | |
3757 | ||
3758 | thisfn = (struct function_range *) | |
7b5a2f43 | 3759 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
3760 | thisfn->name = name; |
3761 | thisfn->lowpc = lowpc; | |
3762 | thisfn->highpc = highpc; | |
3763 | thisfn->seen_line = 0; | |
3764 | thisfn->next = NULL; | |
3765 | ||
e142c38c DJ |
3766 | if (cu->last_fn == NULL) |
3767 | cu->first_fn = thisfn; | |
5fb290d7 | 3768 | else |
e142c38c | 3769 | cu->last_fn->next = thisfn; |
5fb290d7 | 3770 | |
e142c38c | 3771 | cu->last_fn = thisfn; |
c906108c SS |
3772 | } |
3773 | ||
d389af10 JK |
3774 | /* qsort helper for inherit_abstract_dies. */ |
3775 | ||
3776 | static int | |
3777 | unsigned_int_compar (const void *ap, const void *bp) | |
3778 | { | |
3779 | unsigned int a = *(unsigned int *) ap; | |
3780 | unsigned int b = *(unsigned int *) bp; | |
3781 | ||
3782 | return (a > b) - (b > a); | |
3783 | } | |
3784 | ||
3785 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3786 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
3787 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
3788 | ||
3789 | static void | |
3790 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
3791 | { | |
3792 | struct die_info *child_die; | |
3793 | unsigned die_children_count; | |
3794 | /* CU offsets which were referenced by children of the current DIE. */ | |
3795 | unsigned *offsets; | |
3796 | unsigned *offsets_end, *offsetp; | |
3797 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
3798 | struct die_info *origin_die; | |
3799 | /* Iterator of the ORIGIN_DIE children. */ | |
3800 | struct die_info *origin_child_die; | |
3801 | struct cleanup *cleanups; | |
3802 | struct attribute *attr; | |
3803 | ||
3804 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
3805 | if (!attr) | |
3806 | return; | |
3807 | ||
3808 | origin_die = follow_die_ref (die, attr, &cu); | |
edb3359d DJ |
3809 | if (die->tag != origin_die->tag |
3810 | && !(die->tag == DW_TAG_inlined_subroutine | |
3811 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3812 | complaint (&symfile_complaints, |
3813 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
3814 | die->offset, origin_die->offset); | |
3815 | ||
3816 | child_die = die->child; | |
3817 | die_children_count = 0; | |
3818 | while (child_die && child_die->tag) | |
3819 | { | |
3820 | child_die = sibling_die (child_die); | |
3821 | die_children_count++; | |
3822 | } | |
3823 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
3824 | cleanups = make_cleanup (xfree, offsets); | |
3825 | ||
3826 | offsets_end = offsets; | |
3827 | child_die = die->child; | |
3828 | while (child_die && child_die->tag) | |
3829 | { | |
c38f313d DJ |
3830 | /* For each CHILD_DIE, find the corresponding child of |
3831 | ORIGIN_DIE. If there is more than one layer of | |
3832 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
3833 | but GCC versions at least through 4.4 generate this (GCC PR | |
3834 | 40573). */ | |
3835 | struct die_info *child_origin_die = child_die; | |
3836 | while (1) | |
3837 | { | |
3838 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); | |
3839 | if (attr == NULL) | |
3840 | break; | |
3841 | child_origin_die = follow_die_ref (child_origin_die, attr, &cu); | |
3842 | } | |
3843 | ||
d389af10 JK |
3844 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
3845 | counterpart may exist. */ | |
c38f313d | 3846 | if (child_origin_die != child_die) |
d389af10 | 3847 | { |
edb3359d DJ |
3848 | if (child_die->tag != child_origin_die->tag |
3849 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
3850 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3851 | complaint (&symfile_complaints, |
3852 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3853 | "different tags"), child_die->offset, | |
3854 | child_origin_die->offset); | |
c38f313d DJ |
3855 | if (child_origin_die->parent != origin_die) |
3856 | complaint (&symfile_complaints, | |
3857 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3858 | "different parents"), child_die->offset, | |
3859 | child_origin_die->offset); | |
3860 | else | |
3861 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
3862 | } |
3863 | child_die = sibling_die (child_die); | |
3864 | } | |
3865 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
3866 | unsigned_int_compar); | |
3867 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
3868 | if (offsetp[-1] == *offsetp) | |
3869 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
3870 | "to DIE 0x%x as their abstract origin"), | |
3871 | die->offset, *offsetp); | |
3872 | ||
3873 | offsetp = offsets; | |
3874 | origin_child_die = origin_die->child; | |
3875 | while (origin_child_die && origin_child_die->tag) | |
3876 | { | |
3877 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
3878 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
3879 | offsetp++; | |
3880 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
3881 | { | |
3882 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
3883 | process_die (origin_child_die, cu); | |
3884 | } | |
3885 | origin_child_die = sibling_die (origin_child_die); | |
3886 | } | |
3887 | ||
3888 | do_cleanups (cleanups); | |
3889 | } | |
3890 | ||
c906108c | 3891 | static void |
e7c27a73 | 3892 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3893 | { |
e7c27a73 | 3894 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3895 | struct context_stack *new; |
c906108c SS |
3896 | CORE_ADDR lowpc; |
3897 | CORE_ADDR highpc; | |
3898 | struct die_info *child_die; | |
edb3359d | 3899 | struct attribute *attr, *call_line, *call_file; |
c906108c | 3900 | char *name; |
e142c38c | 3901 | CORE_ADDR baseaddr; |
801e3a5b | 3902 | struct block *block; |
edb3359d DJ |
3903 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
3904 | ||
3905 | if (inlined_func) | |
3906 | { | |
3907 | /* If we do not have call site information, we can't show the | |
3908 | caller of this inlined function. That's too confusing, so | |
3909 | only use the scope for local variables. */ | |
3910 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
3911 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
3912 | if (call_line == NULL || call_file == NULL) | |
3913 | { | |
3914 | read_lexical_block_scope (die, cu); | |
3915 | return; | |
3916 | } | |
3917 | } | |
c906108c | 3918 | |
e142c38c DJ |
3919 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
3920 | ||
94af9270 | 3921 | name = dwarf2_name (die, cu); |
c906108c SS |
3922 | |
3923 | /* Ignore functions with missing or empty names and functions with | |
3924 | missing or invalid low and high pc attributes. */ | |
d85a05f0 | 3925 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
3926 | return; |
3927 | ||
3928 | lowpc += baseaddr; | |
3929 | highpc += baseaddr; | |
3930 | ||
5fb290d7 | 3931 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3932 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3933 | |
c906108c | 3934 | new = push_context (0, lowpc); |
f792889a | 3935 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3936 | |
4cecd739 DJ |
3937 | /* If there is a location expression for DW_AT_frame_base, record |
3938 | it. */ | |
e142c38c | 3939 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3940 | if (attr) |
c034e007 AC |
3941 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3942 | expression is being recorded directly in the function's symbol | |
3943 | and not in a separate frame-base object. I guess this hack is | |
3944 | to avoid adding some sort of frame-base adjunct/annex to the | |
3945 | function's symbol :-(. The problem with doing this is that it | |
3946 | results in a function symbol with a location expression that | |
3947 | has nothing to do with the location of the function, ouch! The | |
3948 | relationship should be: a function's symbol has-a frame base; a | |
3949 | frame-base has-a location expression. */ | |
e7c27a73 | 3950 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3951 | |
e142c38c | 3952 | cu->list_in_scope = &local_symbols; |
c906108c | 3953 | |
639d11d3 | 3954 | if (die->child != NULL) |
c906108c | 3955 | { |
639d11d3 | 3956 | child_die = die->child; |
c906108c SS |
3957 | while (child_die && child_die->tag) |
3958 | { | |
e7c27a73 | 3959 | process_die (child_die, cu); |
c906108c SS |
3960 | child_die = sibling_die (child_die); |
3961 | } | |
3962 | } | |
3963 | ||
d389af10 JK |
3964 | inherit_abstract_dies (die, cu); |
3965 | ||
c906108c SS |
3966 | new = pop_context (); |
3967 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3968 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3969 | lowpc, highpc, objfile); | |
3970 | ||
df8a16a1 DJ |
3971 | /* For C++, set the block's scope. */ |
3972 | if (cu->language == language_cplus) | |
3973 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, | |
0114d602 | 3974 | determine_prefix (die, cu), |
df8a16a1 DJ |
3975 | processing_has_namespace_info); |
3976 | ||
801e3a5b JB |
3977 | /* If we have address ranges, record them. */ |
3978 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3979 | |
3980 | /* In C++, we can have functions nested inside functions (e.g., when | |
3981 | a function declares a class that has methods). This means that | |
3982 | when we finish processing a function scope, we may need to go | |
3983 | back to building a containing block's symbol lists. */ | |
3984 | local_symbols = new->locals; | |
3985 | param_symbols = new->params; | |
27aa8d6a | 3986 | using_directives = new->using_directives; |
208d8187 | 3987 | |
921e78cf JB |
3988 | /* If we've finished processing a top-level function, subsequent |
3989 | symbols go in the file symbol list. */ | |
3990 | if (outermost_context_p ()) | |
e142c38c | 3991 | cu->list_in_scope = &file_symbols; |
c906108c SS |
3992 | } |
3993 | ||
3994 | /* Process all the DIES contained within a lexical block scope. Start | |
3995 | a new scope, process the dies, and then close the scope. */ | |
3996 | ||
3997 | static void | |
e7c27a73 | 3998 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3999 | { |
e7c27a73 | 4000 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 4001 | struct context_stack *new; |
c906108c SS |
4002 | CORE_ADDR lowpc, highpc; |
4003 | struct die_info *child_die; | |
e142c38c DJ |
4004 | CORE_ADDR baseaddr; |
4005 | ||
4006 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
4007 | |
4008 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
4009 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
4010 | as multiple lexical blocks? Handling children in a sane way would | |
4011 | be nasty. Might be easier to properly extend generic blocks to | |
4012 | describe ranges. */ | |
d85a05f0 | 4013 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
4014 | return; |
4015 | lowpc += baseaddr; | |
4016 | highpc += baseaddr; | |
4017 | ||
4018 | push_context (0, lowpc); | |
639d11d3 | 4019 | if (die->child != NULL) |
c906108c | 4020 | { |
639d11d3 | 4021 | child_die = die->child; |
c906108c SS |
4022 | while (child_die && child_die->tag) |
4023 | { | |
e7c27a73 | 4024 | process_die (child_die, cu); |
c906108c SS |
4025 | child_die = sibling_die (child_die); |
4026 | } | |
4027 | } | |
4028 | new = pop_context (); | |
4029 | ||
8540c487 | 4030 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 4031 | { |
801e3a5b JB |
4032 | struct block *block |
4033 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
4034 | highpc, objfile); | |
4035 | ||
4036 | /* Note that recording ranges after traversing children, as we | |
4037 | do here, means that recording a parent's ranges entails | |
4038 | walking across all its children's ranges as they appear in | |
4039 | the address map, which is quadratic behavior. | |
4040 | ||
4041 | It would be nicer to record the parent's ranges before | |
4042 | traversing its children, simply overriding whatever you find | |
4043 | there. But since we don't even decide whether to create a | |
4044 | block until after we've traversed its children, that's hard | |
4045 | to do. */ | |
4046 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
4047 | } |
4048 | local_symbols = new->locals; | |
27aa8d6a | 4049 | using_directives = new->using_directives; |
c906108c SS |
4050 | } |
4051 | ||
43039443 | 4052 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
4053 | Return 1 if the attributes are present and valid, otherwise, return 0. |
4054 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
4055 | |
4056 | static int | |
4057 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
4058 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
4059 | struct partial_symtab *ranges_pst) | |
43039443 JK |
4060 | { |
4061 | struct objfile *objfile = cu->objfile; | |
4062 | struct comp_unit_head *cu_header = &cu->header; | |
4063 | bfd *obfd = objfile->obfd; | |
4064 | unsigned int addr_size = cu_header->addr_size; | |
4065 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
4066 | /* Base address selection entry. */ | |
4067 | CORE_ADDR base; | |
4068 | int found_base; | |
4069 | unsigned int dummy; | |
4070 | gdb_byte *buffer; | |
4071 | CORE_ADDR marker; | |
4072 | int low_set; | |
4073 | CORE_ADDR low = 0; | |
4074 | CORE_ADDR high = 0; | |
ff013f42 | 4075 | CORE_ADDR baseaddr; |
43039443 | 4076 | |
d00adf39 DE |
4077 | found_base = cu->base_known; |
4078 | base = cu->base_address; | |
43039443 | 4079 | |
dce234bc | 4080 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
4081 | { |
4082 | complaint (&symfile_complaints, | |
4083 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
4084 | offset); | |
4085 | return 0; | |
4086 | } | |
dce234bc | 4087 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
4088 | |
4089 | /* Read in the largest possible address. */ | |
4090 | marker = read_address (obfd, buffer, cu, &dummy); | |
4091 | if ((marker & mask) == mask) | |
4092 | { | |
4093 | /* If we found the largest possible address, then | |
4094 | read the base address. */ | |
4095 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4096 | buffer += 2 * addr_size; | |
4097 | offset += 2 * addr_size; | |
4098 | found_base = 1; | |
4099 | } | |
4100 | ||
4101 | low_set = 0; | |
4102 | ||
e7030f15 | 4103 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 4104 | |
43039443 JK |
4105 | while (1) |
4106 | { | |
4107 | CORE_ADDR range_beginning, range_end; | |
4108 | ||
4109 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
4110 | buffer += addr_size; | |
4111 | range_end = read_address (obfd, buffer, cu, &dummy); | |
4112 | buffer += addr_size; | |
4113 | offset += 2 * addr_size; | |
4114 | ||
4115 | /* An end of list marker is a pair of zero addresses. */ | |
4116 | if (range_beginning == 0 && range_end == 0) | |
4117 | /* Found the end of list entry. */ | |
4118 | break; | |
4119 | ||
4120 | /* Each base address selection entry is a pair of 2 values. | |
4121 | The first is the largest possible address, the second is | |
4122 | the base address. Check for a base address here. */ | |
4123 | if ((range_beginning & mask) == mask) | |
4124 | { | |
4125 | /* If we found the largest possible address, then | |
4126 | read the base address. */ | |
4127 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4128 | found_base = 1; | |
4129 | continue; | |
4130 | } | |
4131 | ||
4132 | if (!found_base) | |
4133 | { | |
4134 | /* We have no valid base address for the ranges | |
4135 | data. */ | |
4136 | complaint (&symfile_complaints, | |
4137 | _("Invalid .debug_ranges data (no base address)")); | |
4138 | return 0; | |
4139 | } | |
4140 | ||
4141 | range_beginning += base; | |
4142 | range_end += base; | |
4143 | ||
ff013f42 JK |
4144 | if (ranges_pst != NULL && range_beginning < range_end) |
4145 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
4146 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
4147 | ranges_pst); | |
4148 | ||
43039443 JK |
4149 | /* FIXME: This is recording everything as a low-high |
4150 | segment of consecutive addresses. We should have a | |
4151 | data structure for discontiguous block ranges | |
4152 | instead. */ | |
4153 | if (! low_set) | |
4154 | { | |
4155 | low = range_beginning; | |
4156 | high = range_end; | |
4157 | low_set = 1; | |
4158 | } | |
4159 | else | |
4160 | { | |
4161 | if (range_beginning < low) | |
4162 | low = range_beginning; | |
4163 | if (range_end > high) | |
4164 | high = range_end; | |
4165 | } | |
4166 | } | |
4167 | ||
4168 | if (! low_set) | |
4169 | /* If the first entry is an end-of-list marker, the range | |
4170 | describes an empty scope, i.e. no instructions. */ | |
4171 | return 0; | |
4172 | ||
4173 | if (low_return) | |
4174 | *low_return = low; | |
4175 | if (high_return) | |
4176 | *high_return = high; | |
4177 | return 1; | |
4178 | } | |
4179 | ||
af34e669 DJ |
4180 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
4181 | are present and valid, otherwise, return 0. Return -1 if the range is | |
4182 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 4183 | static int |
af34e669 | 4184 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
4185 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
4186 | struct partial_symtab *pst) | |
c906108c SS |
4187 | { |
4188 | struct attribute *attr; | |
af34e669 DJ |
4189 | CORE_ADDR low = 0; |
4190 | CORE_ADDR high = 0; | |
4191 | int ret = 0; | |
c906108c | 4192 | |
e142c38c | 4193 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 4194 | if (attr) |
af34e669 DJ |
4195 | { |
4196 | high = DW_ADDR (attr); | |
e142c38c | 4197 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
4198 | if (attr) |
4199 | low = DW_ADDR (attr); | |
4200 | else | |
4201 | /* Found high w/o low attribute. */ | |
4202 | return 0; | |
4203 | ||
4204 | /* Found consecutive range of addresses. */ | |
4205 | ret = 1; | |
4206 | } | |
c906108c | 4207 | else |
af34e669 | 4208 | { |
e142c38c | 4209 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
4210 | if (attr != NULL) |
4211 | { | |
af34e669 | 4212 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 4213 | .debug_ranges section. */ |
d85a05f0 | 4214 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 4215 | return 0; |
43039443 | 4216 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
4217 | ret = -1; |
4218 | } | |
4219 | } | |
c906108c SS |
4220 | |
4221 | if (high < low) | |
4222 | return 0; | |
4223 | ||
4224 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
4225 | eliminate duplicate copies of functions and vtables and such. | |
4226 | The linker will arbitrarily choose one and discard the others. | |
4227 | The AT_*_pc values for such functions refer to local labels in | |
4228 | these sections. If the section from that file was discarded, the | |
4229 | labels are not in the output, so the relocs get a value of 0. | |
4230 | If this is a discarded function, mark the pc bounds as invalid, | |
4231 | so that GDB will ignore it. */ | |
72dca2f5 | 4232 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
4233 | return 0; |
4234 | ||
4235 | *lowpc = low; | |
4236 | *highpc = high; | |
af34e669 | 4237 | return ret; |
c906108c SS |
4238 | } |
4239 | ||
b084d499 JB |
4240 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
4241 | its low and high PC addresses. Do nothing if these addresses could not | |
4242 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
4243 | and HIGHPC to the high address if greater than HIGHPC. */ | |
4244 | ||
4245 | static void | |
4246 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
4247 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4248 | struct dwarf2_cu *cu) | |
4249 | { | |
4250 | CORE_ADDR low, high; | |
4251 | struct die_info *child = die->child; | |
4252 | ||
d85a05f0 | 4253 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
4254 | { |
4255 | *lowpc = min (*lowpc, low); | |
4256 | *highpc = max (*highpc, high); | |
4257 | } | |
4258 | ||
4259 | /* If the language does not allow nested subprograms (either inside | |
4260 | subprograms or lexical blocks), we're done. */ | |
4261 | if (cu->language != language_ada) | |
4262 | return; | |
4263 | ||
4264 | /* Check all the children of the given DIE. If it contains nested | |
4265 | subprograms, then check their pc bounds. Likewise, we need to | |
4266 | check lexical blocks as well, as they may also contain subprogram | |
4267 | definitions. */ | |
4268 | while (child && child->tag) | |
4269 | { | |
4270 | if (child->tag == DW_TAG_subprogram | |
4271 | || child->tag == DW_TAG_lexical_block) | |
4272 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
4273 | child = sibling_die (child); | |
4274 | } | |
4275 | } | |
4276 | ||
fae299cd DC |
4277 | /* Get the low and high pc's represented by the scope DIE, and store |
4278 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
4279 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
4280 | ||
4281 | static void | |
4282 | get_scope_pc_bounds (struct die_info *die, | |
4283 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4284 | struct dwarf2_cu *cu) | |
4285 | { | |
4286 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
4287 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
4288 | CORE_ADDR current_low, current_high; | |
4289 | ||
d85a05f0 | 4290 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
4291 | { |
4292 | best_low = current_low; | |
4293 | best_high = current_high; | |
4294 | } | |
4295 | else | |
4296 | { | |
4297 | struct die_info *child = die->child; | |
4298 | ||
4299 | while (child && child->tag) | |
4300 | { | |
4301 | switch (child->tag) { | |
4302 | case DW_TAG_subprogram: | |
b084d499 | 4303 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
4304 | break; |
4305 | case DW_TAG_namespace: | |
4306 | /* FIXME: carlton/2004-01-16: Should we do this for | |
4307 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
4308 | that current GCC's always emit the DIEs corresponding | |
4309 | to definitions of methods of classes as children of a | |
4310 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
4311 | the DIEs giving the declarations, which could be | |
4312 | anywhere). But I don't see any reason why the | |
4313 | standards says that they have to be there. */ | |
4314 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
4315 | ||
4316 | if (current_low != ((CORE_ADDR) -1)) | |
4317 | { | |
4318 | best_low = min (best_low, current_low); | |
4319 | best_high = max (best_high, current_high); | |
4320 | } | |
4321 | break; | |
4322 | default: | |
4323 | /* Ignore. */ | |
4324 | break; | |
4325 | } | |
4326 | ||
4327 | child = sibling_die (child); | |
4328 | } | |
4329 | } | |
4330 | ||
4331 | *lowpc = best_low; | |
4332 | *highpc = best_high; | |
4333 | } | |
4334 | ||
801e3a5b JB |
4335 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
4336 | in DIE. */ | |
4337 | static void | |
4338 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
4339 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
4340 | { | |
4341 | struct attribute *attr; | |
4342 | ||
4343 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
4344 | if (attr) | |
4345 | { | |
4346 | CORE_ADDR high = DW_ADDR (attr); | |
4347 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
4348 | if (attr) | |
4349 | { | |
4350 | CORE_ADDR low = DW_ADDR (attr); | |
4351 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
4352 | } | |
4353 | } | |
4354 | ||
4355 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
4356 | if (attr) | |
4357 | { | |
4358 | bfd *obfd = cu->objfile->obfd; | |
4359 | ||
4360 | /* The value of the DW_AT_ranges attribute is the offset of the | |
4361 | address range list in the .debug_ranges section. */ | |
4362 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 4363 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
4364 | |
4365 | /* For some target architectures, but not others, the | |
4366 | read_address function sign-extends the addresses it returns. | |
4367 | To recognize base address selection entries, we need a | |
4368 | mask. */ | |
4369 | unsigned int addr_size = cu->header.addr_size; | |
4370 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
4371 | ||
4372 | /* The base address, to which the next pair is relative. Note | |
4373 | that this 'base' is a DWARF concept: most entries in a range | |
4374 | list are relative, to reduce the number of relocs against the | |
4375 | debugging information. This is separate from this function's | |
4376 | 'baseaddr' argument, which GDB uses to relocate debugging | |
4377 | information from a shared library based on the address at | |
4378 | which the library was loaded. */ | |
d00adf39 DE |
4379 | CORE_ADDR base = cu->base_address; |
4380 | int base_known = cu->base_known; | |
801e3a5b | 4381 | |
dce234bc | 4382 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
4383 | { |
4384 | complaint (&symfile_complaints, | |
4385 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
4386 | offset); | |
4387 | return; | |
4388 | } | |
4389 | ||
4390 | for (;;) | |
4391 | { | |
4392 | unsigned int bytes_read; | |
4393 | CORE_ADDR start, end; | |
4394 | ||
4395 | start = read_address (obfd, buffer, cu, &bytes_read); | |
4396 | buffer += bytes_read; | |
4397 | end = read_address (obfd, buffer, cu, &bytes_read); | |
4398 | buffer += bytes_read; | |
4399 | ||
4400 | /* Did we find the end of the range list? */ | |
4401 | if (start == 0 && end == 0) | |
4402 | break; | |
4403 | ||
4404 | /* Did we find a base address selection entry? */ | |
4405 | else if ((start & base_select_mask) == base_select_mask) | |
4406 | { | |
4407 | base = end; | |
4408 | base_known = 1; | |
4409 | } | |
4410 | ||
4411 | /* We found an ordinary address range. */ | |
4412 | else | |
4413 | { | |
4414 | if (!base_known) | |
4415 | { | |
4416 | complaint (&symfile_complaints, | |
4417 | _("Invalid .debug_ranges data (no base address)")); | |
4418 | return; | |
4419 | } | |
4420 | ||
4421 | record_block_range (block, | |
4422 | baseaddr + base + start, | |
4423 | baseaddr + base + end - 1); | |
4424 | } | |
4425 | } | |
4426 | } | |
4427 | } | |
4428 | ||
c906108c SS |
4429 | /* Add an aggregate field to the field list. */ |
4430 | ||
4431 | static void | |
107d2387 | 4432 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
4433 | struct dwarf2_cu *cu) |
4434 | { | |
4435 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 4436 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
4437 | struct nextfield *new_field; |
4438 | struct attribute *attr; | |
4439 | struct field *fp; | |
4440 | char *fieldname = ""; | |
4441 | ||
4442 | /* Allocate a new field list entry and link it in. */ | |
4443 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 4444 | make_cleanup (xfree, new_field); |
c906108c | 4445 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
4446 | |
4447 | if (die->tag == DW_TAG_inheritance) | |
4448 | { | |
4449 | new_field->next = fip->baseclasses; | |
4450 | fip->baseclasses = new_field; | |
4451 | } | |
4452 | else | |
4453 | { | |
4454 | new_field->next = fip->fields; | |
4455 | fip->fields = new_field; | |
4456 | } | |
c906108c SS |
4457 | fip->nfields++; |
4458 | ||
4459 | /* Handle accessibility and virtuality of field. | |
4460 | The default accessibility for members is public, the default | |
4461 | accessibility for inheritance is private. */ | |
4462 | if (die->tag != DW_TAG_inheritance) | |
4463 | new_field->accessibility = DW_ACCESS_public; | |
4464 | else | |
4465 | new_field->accessibility = DW_ACCESS_private; | |
4466 | new_field->virtuality = DW_VIRTUALITY_none; | |
4467 | ||
e142c38c | 4468 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4469 | if (attr) |
4470 | new_field->accessibility = DW_UNSND (attr); | |
4471 | if (new_field->accessibility != DW_ACCESS_public) | |
4472 | fip->non_public_fields = 1; | |
e142c38c | 4473 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
4474 | if (attr) |
4475 | new_field->virtuality = DW_UNSND (attr); | |
4476 | ||
4477 | fp = &new_field->field; | |
a9a9bd0f | 4478 | |
e142c38c | 4479 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 4480 | { |
a9a9bd0f DC |
4481 | /* Data member other than a C++ static data member. */ |
4482 | ||
c906108c | 4483 | /* Get type of field. */ |
e7c27a73 | 4484 | fp->type = die_type (die, cu); |
c906108c | 4485 | |
d6a843b5 | 4486 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 4487 | |
c906108c | 4488 | /* Get bit size of field (zero if none). */ |
e142c38c | 4489 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
4490 | if (attr) |
4491 | { | |
4492 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
4493 | } | |
4494 | else | |
4495 | { | |
4496 | FIELD_BITSIZE (*fp) = 0; | |
4497 | } | |
4498 | ||
4499 | /* Get bit offset of field. */ | |
e142c38c | 4500 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
4501 | if (attr) |
4502 | { | |
d4b96c9a | 4503 | int byte_offset = 0; |
c6a0999f | 4504 | |
3690dd37 | 4505 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 4506 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 4507 | else if (attr_form_is_constant (attr)) |
c6a0999f | 4508 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 4509 | else if (attr_form_is_block (attr)) |
c6a0999f | 4510 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
4511 | else |
4512 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 4513 | |
d6a843b5 | 4514 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 4515 | } |
e142c38c | 4516 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
4517 | if (attr) |
4518 | { | |
5e2b427d | 4519 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
4520 | { |
4521 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
4522 | additional bit offset from the MSB of the containing |
4523 | anonymous object to the MSB of the field. We don't | |
4524 | have to do anything special since we don't need to | |
4525 | know the size of the anonymous object. */ | |
c906108c SS |
4526 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
4527 | } | |
4528 | else | |
4529 | { | |
4530 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
4531 | MSB of the anonymous object, subtract off the number of |
4532 | bits from the MSB of the field to the MSB of the | |
4533 | object, and then subtract off the number of bits of | |
4534 | the field itself. The result is the bit offset of | |
4535 | the LSB of the field. */ | |
c906108c SS |
4536 | int anonymous_size; |
4537 | int bit_offset = DW_UNSND (attr); | |
4538 | ||
e142c38c | 4539 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4540 | if (attr) |
4541 | { | |
4542 | /* The size of the anonymous object containing | |
4543 | the bit field is explicit, so use the | |
4544 | indicated size (in bytes). */ | |
4545 | anonymous_size = DW_UNSND (attr); | |
4546 | } | |
4547 | else | |
4548 | { | |
4549 | /* The size of the anonymous object containing | |
4550 | the bit field must be inferred from the type | |
4551 | attribute of the data member containing the | |
4552 | bit field. */ | |
4553 | anonymous_size = TYPE_LENGTH (fp->type); | |
4554 | } | |
4555 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
4556 | - bit_offset - FIELD_BITSIZE (*fp); | |
4557 | } | |
4558 | } | |
4559 | ||
4560 | /* Get name of field. */ | |
39cbfefa DJ |
4561 | fieldname = dwarf2_name (die, cu); |
4562 | if (fieldname == NULL) | |
4563 | fieldname = ""; | |
d8151005 DJ |
4564 | |
4565 | /* The name is already allocated along with this objfile, so we don't | |
4566 | need to duplicate it for the type. */ | |
4567 | fp->name = fieldname; | |
c906108c SS |
4568 | |
4569 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 4570 | pointer or virtual base class pointer) to private. */ |
e142c38c | 4571 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 4572 | { |
d48cc9dd | 4573 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
4574 | new_field->accessibility = DW_ACCESS_private; |
4575 | fip->non_public_fields = 1; | |
4576 | } | |
4577 | } | |
a9a9bd0f | 4578 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 4579 | { |
a9a9bd0f DC |
4580 | /* C++ static member. */ |
4581 | ||
4582 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
4583 | is a declaration, but all versions of G++ as of this writing | |
4584 | (so through at least 3.2.1) incorrectly generate | |
4585 | DW_TAG_variable tags. */ | |
4586 | ||
c906108c | 4587 | char *physname; |
c906108c | 4588 | |
a9a9bd0f | 4589 | /* Get name of field. */ |
39cbfefa DJ |
4590 | fieldname = dwarf2_name (die, cu); |
4591 | if (fieldname == NULL) | |
c906108c SS |
4592 | return; |
4593 | ||
2df3850c | 4594 | /* Get physical name. */ |
94af9270 | 4595 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 4596 | |
d8151005 DJ |
4597 | /* The name is already allocated along with this objfile, so we don't |
4598 | need to duplicate it for the type. */ | |
4599 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 4600 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 4601 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
4602 | } |
4603 | else if (die->tag == DW_TAG_inheritance) | |
4604 | { | |
4605 | /* C++ base class field. */ | |
e142c38c | 4606 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 4607 | if (attr) |
d4b96c9a JK |
4608 | { |
4609 | int byte_offset = 0; | |
4610 | ||
4611 | if (attr_form_is_section_offset (attr)) | |
4612 | dwarf2_complex_location_expr_complaint (); | |
4613 | else if (attr_form_is_constant (attr)) | |
4614 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
4615 | else if (attr_form_is_block (attr)) | |
4616 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
4617 | else | |
4618 | dwarf2_complex_location_expr_complaint (); | |
4619 | ||
4620 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
4621 | } | |
c906108c | 4622 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 4623 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
4624 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
4625 | fip->nbaseclasses++; | |
4626 | } | |
4627 | } | |
4628 | ||
4629 | /* Create the vector of fields, and attach it to the type. */ | |
4630 | ||
4631 | static void | |
fba45db2 | 4632 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4633 | struct dwarf2_cu *cu) |
c906108c SS |
4634 | { |
4635 | int nfields = fip->nfields; | |
4636 | ||
4637 | /* Record the field count, allocate space for the array of fields, | |
4638 | and create blank accessibility bitfields if necessary. */ | |
4639 | TYPE_NFIELDS (type) = nfields; | |
4640 | TYPE_FIELDS (type) = (struct field *) | |
4641 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
4642 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
4643 | ||
b4ba55a1 | 4644 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
4645 | { |
4646 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
4647 | ||
4648 | TYPE_FIELD_PRIVATE_BITS (type) = | |
4649 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4650 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
4651 | ||
4652 | TYPE_FIELD_PROTECTED_BITS (type) = | |
4653 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4654 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
4655 | ||
4656 | TYPE_FIELD_IGNORE_BITS (type) = | |
4657 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4658 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
4659 | } | |
4660 | ||
4661 | /* If the type has baseclasses, allocate and clear a bit vector for | |
4662 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 4663 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
4664 | { |
4665 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 4666 | unsigned char *pointer; |
c906108c SS |
4667 | |
4668 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
4669 | pointer = TYPE_ALLOC (type, num_bytes); |
4670 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
4671 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
4672 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
4673 | } | |
4674 | ||
4675 | /* Copy the saved-up fields into the field vector. Start from the head | |
4676 | of the list, adding to the tail of the field array, so that they end | |
4677 | up in the same order in the array in which they were added to the list. */ | |
4678 | while (nfields-- > 0) | |
4679 | { | |
7d0ccb61 DJ |
4680 | struct nextfield *fieldp; |
4681 | ||
4682 | if (fip->fields) | |
4683 | { | |
4684 | fieldp = fip->fields; | |
4685 | fip->fields = fieldp->next; | |
4686 | } | |
4687 | else | |
4688 | { | |
4689 | fieldp = fip->baseclasses; | |
4690 | fip->baseclasses = fieldp->next; | |
4691 | } | |
4692 | ||
4693 | TYPE_FIELD (type, nfields) = fieldp->field; | |
4694 | switch (fieldp->accessibility) | |
c906108c | 4695 | { |
c5aa993b | 4696 | case DW_ACCESS_private: |
b4ba55a1 JB |
4697 | if (cu->language != language_ada) |
4698 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 4699 | break; |
c906108c | 4700 | |
c5aa993b | 4701 | case DW_ACCESS_protected: |
b4ba55a1 JB |
4702 | if (cu->language != language_ada) |
4703 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 4704 | break; |
c906108c | 4705 | |
c5aa993b JM |
4706 | case DW_ACCESS_public: |
4707 | break; | |
c906108c | 4708 | |
c5aa993b JM |
4709 | default: |
4710 | /* Unknown accessibility. Complain and treat it as public. */ | |
4711 | { | |
e2e0b3e5 | 4712 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 4713 | fieldp->accessibility); |
c5aa993b JM |
4714 | } |
4715 | break; | |
c906108c SS |
4716 | } |
4717 | if (nfields < fip->nbaseclasses) | |
4718 | { | |
7d0ccb61 | 4719 | switch (fieldp->virtuality) |
c906108c | 4720 | { |
c5aa993b JM |
4721 | case DW_VIRTUALITY_virtual: |
4722 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
4723 | if (cu->language == language_ada) |
4724 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
4725 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
4726 | break; | |
c906108c SS |
4727 | } |
4728 | } | |
c906108c SS |
4729 | } |
4730 | } | |
4731 | ||
c906108c SS |
4732 | /* Add a member function to the proper fieldlist. */ |
4733 | ||
4734 | static void | |
107d2387 | 4735 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 4736 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 4737 | { |
e7c27a73 | 4738 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4739 | struct attribute *attr; |
4740 | struct fnfieldlist *flp; | |
4741 | int i; | |
4742 | struct fn_field *fnp; | |
4743 | char *fieldname; | |
4744 | char *physname; | |
4745 | struct nextfnfield *new_fnfield; | |
f792889a | 4746 | struct type *this_type; |
c906108c | 4747 | |
b4ba55a1 JB |
4748 | if (cu->language == language_ada) |
4749 | error ("unexpected member function in Ada type"); | |
4750 | ||
2df3850c | 4751 | /* Get name of member function. */ |
39cbfefa DJ |
4752 | fieldname = dwarf2_name (die, cu); |
4753 | if (fieldname == NULL) | |
2df3850c | 4754 | return; |
c906108c | 4755 | |
2df3850c | 4756 | /* Get the mangled name. */ |
94af9270 | 4757 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c SS |
4758 | |
4759 | /* Look up member function name in fieldlist. */ | |
4760 | for (i = 0; i < fip->nfnfields; i++) | |
4761 | { | |
27bfe10e | 4762 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
4763 | break; |
4764 | } | |
4765 | ||
4766 | /* Create new list element if necessary. */ | |
4767 | if (i < fip->nfnfields) | |
4768 | flp = &fip->fnfieldlists[i]; | |
4769 | else | |
4770 | { | |
4771 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4772 | { | |
4773 | fip->fnfieldlists = (struct fnfieldlist *) | |
4774 | xrealloc (fip->fnfieldlists, | |
4775 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4776 | * sizeof (struct fnfieldlist)); |
c906108c | 4777 | if (fip->nfnfields == 0) |
c13c43fd | 4778 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
4779 | } |
4780 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
4781 | flp->name = fieldname; | |
4782 | flp->length = 0; | |
4783 | flp->head = NULL; | |
4784 | fip->nfnfields++; | |
4785 | } | |
4786 | ||
4787 | /* Create a new member function field and chain it to the field list | |
4788 | entry. */ | |
4789 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 4790 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
4791 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
4792 | new_fnfield->next = flp->head; | |
4793 | flp->head = new_fnfield; | |
4794 | flp->length++; | |
4795 | ||
4796 | /* Fill in the member function field info. */ | |
4797 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
4798 | /* The name is already allocated along with this objfile, so we don't |
4799 | need to duplicate it for the type. */ | |
4800 | fnp->physname = physname ? physname : ""; | |
c906108c | 4801 | fnp->type = alloc_type (objfile); |
f792889a DJ |
4802 | this_type = read_type_die (die, cu); |
4803 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 4804 | { |
f792889a | 4805 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 4806 | |
f792889a | 4807 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
4808 | of the method itself (TYPE_CODE_METHOD). */ |
4809 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
4810 | TYPE_TARGET_TYPE (this_type), |
4811 | TYPE_FIELDS (this_type), | |
4812 | TYPE_NFIELDS (this_type), | |
4813 | TYPE_VARARGS (this_type)); | |
c906108c SS |
4814 | |
4815 | /* Handle static member functions. | |
c5aa993b JM |
4816 | Dwarf2 has no clean way to discern C++ static and non-static |
4817 | member functions. G++ helps GDB by marking the first | |
4818 | parameter for non-static member functions (which is the | |
4819 | this pointer) as artificial. We obtain this information | |
4820 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 4821 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
4822 | fnp->voffset = VOFFSET_STATIC; |
4823 | } | |
4824 | else | |
e2e0b3e5 | 4825 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 4826 | physname); |
c906108c SS |
4827 | |
4828 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 4829 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 4830 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
4831 | |
4832 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
4833 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
4834 | ||
4835 | /* Get accessibility. */ | |
e142c38c | 4836 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4837 | if (attr) |
4838 | { | |
4839 | switch (DW_UNSND (attr)) | |
4840 | { | |
c5aa993b JM |
4841 | case DW_ACCESS_private: |
4842 | fnp->is_private = 1; | |
4843 | break; | |
4844 | case DW_ACCESS_protected: | |
4845 | fnp->is_protected = 1; | |
4846 | break; | |
c906108c SS |
4847 | } |
4848 | } | |
4849 | ||
b02dede2 | 4850 | /* Check for artificial methods. */ |
e142c38c | 4851 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
4852 | if (attr && DW_UNSND (attr) != 0) |
4853 | fnp->is_artificial = 1; | |
4854 | ||
0d564a31 DJ |
4855 | /* Get index in virtual function table if it is a virtual member |
4856 | function. For GCC, this is an offset in the appropriate | |
4857 | virtual table, as specified by DW_AT_containing_type. For | |
4858 | everyone else, it is an expression to be evaluated relative | |
4859 | to the object address. */ | |
4860 | ||
e142c38c | 4861 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
0d564a31 | 4862 | if (attr && fnp->fcontext) |
8e19ed76 PS |
4863 | { |
4864 | /* Support the .debug_loc offsets */ | |
4865 | if (attr_form_is_block (attr)) | |
4866 | { | |
e7c27a73 | 4867 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 4868 | } |
3690dd37 | 4869 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4870 | { |
4d3c2250 | 4871 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4872 | } |
4873 | else | |
4874 | { | |
4d3c2250 KB |
4875 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
4876 | fieldname); | |
8e19ed76 | 4877 | } |
0d564a31 DJ |
4878 | } |
4879 | else if (attr) | |
4880 | { | |
4881 | /* We only support trivial expressions here. This hack will work | |
ba950e4d | 4882 | for v3 classes, which always start with the vtable pointer. */ |
0d564a31 DJ |
4883 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0 |
4884 | && DW_BLOCK (attr)->data[0] == DW_OP_deref) | |
4885 | { | |
4886 | struct dwarf_block blk; | |
4887 | blk.size = DW_BLOCK (attr)->size - 1; | |
4888 | blk.data = DW_BLOCK (attr)->data + 1; | |
ba950e4d DJ |
4889 | fnp->voffset = decode_locdesc (&blk, cu); |
4890 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
4891 | dwarf2_complex_location_expr_complaint (); | |
4892 | else | |
4893 | fnp->voffset /= cu->header.addr_size; | |
0d564a31 DJ |
4894 | fnp->voffset += 2; |
4895 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
4896 | } | |
4897 | else | |
4898 | dwarf2_complex_location_expr_complaint (); | |
4899 | } | |
d48cc9dd DJ |
4900 | else |
4901 | { | |
4902 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
4903 | if (attr && DW_UNSND (attr)) | |
4904 | { | |
4905 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
4906 | complaint (&symfile_complaints, | |
4907 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
4908 | fieldname, die->offset); | |
4909 | TYPE_CPLUS_DYNAMIC (type) = 1; | |
4910 | } | |
4911 | } | |
c906108c SS |
4912 | } |
4913 | ||
4914 | /* Create the vector of member function fields, and attach it to the type. */ | |
4915 | ||
4916 | static void | |
fba45db2 | 4917 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4918 | struct dwarf2_cu *cu) |
c906108c SS |
4919 | { |
4920 | struct fnfieldlist *flp; | |
4921 | int total_length = 0; | |
4922 | int i; | |
4923 | ||
b4ba55a1 JB |
4924 | if (cu->language == language_ada) |
4925 | error ("unexpected member functions in Ada type"); | |
4926 | ||
c906108c SS |
4927 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
4928 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
4929 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
4930 | ||
4931 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
4932 | { | |
4933 | struct nextfnfield *nfp = flp->head; | |
4934 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
4935 | int k; | |
4936 | ||
4937 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
4938 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
4939 | fn_flp->fn_fields = (struct fn_field *) | |
4940 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
4941 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 4942 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
4943 | |
4944 | total_length += flp->length; | |
4945 | } | |
4946 | ||
4947 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
4948 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
4949 | } | |
4950 | ||
1168df01 JB |
4951 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
4952 | language, zero otherwise. */ | |
4953 | static int | |
4954 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
4955 | { | |
4956 | static const char vptr[] = "_vptr"; | |
987504bb | 4957 | static const char vtable[] = "vtable"; |
1168df01 | 4958 | |
987504bb JJ |
4959 | /* Look for the C++ and Java forms of the vtable. */ |
4960 | if ((cu->language == language_java | |
4961 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
4962 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
4963 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
4964 | return 1; |
4965 | ||
4966 | return 0; | |
4967 | } | |
4968 | ||
c0dd20ea | 4969 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
4970 | functions, with the ABI-specified layout. If TYPE describes |
4971 | such a structure, smash it into a member function type. | |
61049d3b DJ |
4972 | |
4973 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
4974 | This is GCC PR debug/28767. */ | |
c0dd20ea | 4975 | |
0b92b5bb TT |
4976 | static void |
4977 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 4978 | { |
0b92b5bb | 4979 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
4980 | |
4981 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
4982 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
4983 | return; | |
c0dd20ea DJ |
4984 | |
4985 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
4986 | if (TYPE_FIELD_NAME (type, 0) == NULL |
4987 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
4988 | || TYPE_FIELD_NAME (type, 1) == NULL | |
4989 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
4990 | return; | |
c0dd20ea DJ |
4991 | |
4992 | /* Find the type of the method. */ | |
0b92b5bb | 4993 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
4994 | if (pfn_type == NULL |
4995 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
4996 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 4997 | return; |
c0dd20ea DJ |
4998 | |
4999 | /* Look for the "this" argument. */ | |
5000 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
5001 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 5002 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 5003 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 5004 | return; |
c0dd20ea DJ |
5005 | |
5006 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
5007 | new_type = alloc_type (objfile); |
5008 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
5009 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
5010 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 5011 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 5012 | } |
1168df01 | 5013 | |
c906108c SS |
5014 | /* Called when we find the DIE that starts a structure or union scope |
5015 | (definition) to process all dies that define the members of the | |
5016 | structure or union. | |
5017 | ||
5018 | NOTE: we need to call struct_type regardless of whether or not the | |
5019 | DIE has an at_name attribute, since it might be an anonymous | |
5020 | structure or union. This gets the type entered into our set of | |
5021 | user defined types. | |
5022 | ||
5023 | However, if the structure is incomplete (an opaque struct/union) | |
5024 | then suppress creating a symbol table entry for it since gdb only | |
5025 | wants to find the one with the complete definition. Note that if | |
5026 | it is complete, we just call new_symbol, which does it's own | |
5027 | checking about whether the struct/union is anonymous or not (and | |
5028 | suppresses creating a symbol table entry itself). */ | |
5029 | ||
f792889a | 5030 | static struct type * |
134d01f1 | 5031 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5032 | { |
e7c27a73 | 5033 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5034 | struct type *type; |
5035 | struct attribute *attr; | |
39cbfefa | 5036 | char *name; |
0114d602 | 5037 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c | 5038 | |
348e048f DE |
5039 | /* If the definition of this type lives in .debug_types, read that type. |
5040 | Don't follow DW_AT_specification though, that will take us back up | |
5041 | the chain and we want to go down. */ | |
5042 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
5043 | if (attr) | |
5044 | { | |
5045 | struct dwarf2_cu *type_cu = cu; | |
5046 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
5047 | /* We could just recurse on read_structure_type, but we need to call | |
5048 | get_die_type to ensure only one type for this DIE is created. | |
5049 | This is important, for example, because for c++ classes we need | |
5050 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
5051 | type = read_type_die (type_die, type_cu); | |
5052 | return set_die_type (die, type, cu); | |
5053 | } | |
5054 | ||
c0dd20ea | 5055 | type = alloc_type (objfile); |
c906108c | 5056 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 5057 | |
39cbfefa DJ |
5058 | name = dwarf2_name (die, cu); |
5059 | if (name != NULL) | |
c906108c | 5060 | { |
987504bb JJ |
5061 | if (cu->language == language_cplus |
5062 | || cu->language == language_java) | |
63d06c5c | 5063 | { |
94af9270 KS |
5064 | TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu); |
5065 | if (die->tag == DW_TAG_structure_type | |
5066 | || die->tag == DW_TAG_class_type) | |
5067 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
5068 | } |
5069 | else | |
5070 | { | |
d8151005 DJ |
5071 | /* The name is already allocated along with this objfile, so |
5072 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
5073 | TYPE_TAG_NAME (type) = (char *) name; |
5074 | if (die->tag == DW_TAG_class_type) | |
5075 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 5076 | } |
c906108c SS |
5077 | } |
5078 | ||
5079 | if (die->tag == DW_TAG_structure_type) | |
5080 | { | |
5081 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
5082 | } | |
5083 | else if (die->tag == DW_TAG_union_type) | |
5084 | { | |
5085 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
5086 | } | |
5087 | else | |
5088 | { | |
c906108c SS |
5089 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
5090 | } | |
5091 | ||
0cc2414c TT |
5092 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
5093 | TYPE_DECLARED_CLASS (type) = 1; | |
5094 | ||
e142c38c | 5095 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5096 | if (attr) |
5097 | { | |
5098 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5099 | } | |
5100 | else | |
5101 | { | |
5102 | TYPE_LENGTH (type) = 0; | |
5103 | } | |
5104 | ||
876cecd0 | 5105 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 5106 | if (die_is_declaration (die, cu)) |
876cecd0 | 5107 | TYPE_STUB (type) = 1; |
dc718098 | 5108 | |
b4ba55a1 JB |
5109 | set_descriptive_type (type, die, cu); |
5110 | ||
c906108c SS |
5111 | /* We need to add the type field to the die immediately so we don't |
5112 | infinitely recurse when dealing with pointers to the structure | |
5113 | type within the structure itself. */ | |
1c379e20 | 5114 | set_die_type (die, type, cu); |
c906108c | 5115 | |
e142c38c | 5116 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
5117 | { |
5118 | struct field_info fi; | |
5119 | struct die_info *child_die; | |
c906108c SS |
5120 | |
5121 | memset (&fi, 0, sizeof (struct field_info)); | |
5122 | ||
639d11d3 | 5123 | child_die = die->child; |
c906108c SS |
5124 | |
5125 | while (child_die && child_die->tag) | |
5126 | { | |
a9a9bd0f DC |
5127 | if (child_die->tag == DW_TAG_member |
5128 | || child_die->tag == DW_TAG_variable) | |
c906108c | 5129 | { |
a9a9bd0f DC |
5130 | /* NOTE: carlton/2002-11-05: A C++ static data member |
5131 | should be a DW_TAG_member that is a declaration, but | |
5132 | all versions of G++ as of this writing (so through at | |
5133 | least 3.2.1) incorrectly generate DW_TAG_variable | |
5134 | tags for them instead. */ | |
e7c27a73 | 5135 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5136 | } |
8713b1b1 | 5137 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
5138 | { |
5139 | /* C++ member function. */ | |
e7c27a73 | 5140 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
5141 | } |
5142 | else if (child_die->tag == DW_TAG_inheritance) | |
5143 | { | |
5144 | /* C++ base class field. */ | |
e7c27a73 | 5145 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5146 | } |
c906108c SS |
5147 | child_die = sibling_die (child_die); |
5148 | } | |
5149 | ||
5150 | /* Attach fields and member functions to the type. */ | |
5151 | if (fi.nfields) | |
e7c27a73 | 5152 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
5153 | if (fi.nfnfields) |
5154 | { | |
e7c27a73 | 5155 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 5156 | |
c5aa993b | 5157 | /* Get the type which refers to the base class (possibly this |
c906108c | 5158 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
5159 | class from the DW_AT_containing_type attribute. This use of |
5160 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 5161 | |
e142c38c | 5162 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 5163 | { |
e7c27a73 | 5164 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
5165 | |
5166 | TYPE_VPTR_BASETYPE (type) = t; | |
5167 | if (type == t) | |
5168 | { | |
c906108c SS |
5169 | int i; |
5170 | ||
5171 | /* Our own class provides vtbl ptr. */ | |
5172 | for (i = TYPE_NFIELDS (t) - 1; | |
5173 | i >= TYPE_N_BASECLASSES (t); | |
5174 | --i) | |
5175 | { | |
5176 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
5177 | ||
1168df01 | 5178 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
5179 | { |
5180 | TYPE_VPTR_FIELDNO (type) = i; | |
5181 | break; | |
5182 | } | |
5183 | } | |
5184 | ||
5185 | /* Complain if virtual function table field not found. */ | |
5186 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 5187 | complaint (&symfile_complaints, |
e2e0b3e5 | 5188 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
5189 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
5190 | ""); | |
c906108c SS |
5191 | } |
5192 | else | |
5193 | { | |
5194 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
5195 | } | |
5196 | } | |
f6235d4c EZ |
5197 | else if (cu->producer |
5198 | && strncmp (cu->producer, | |
5199 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
5200 | { | |
5201 | /* The IBM XLC compiler does not provide direct indication | |
5202 | of the containing type, but the vtable pointer is | |
5203 | always named __vfp. */ | |
5204 | ||
5205 | int i; | |
5206 | ||
5207 | for (i = TYPE_NFIELDS (type) - 1; | |
5208 | i >= TYPE_N_BASECLASSES (type); | |
5209 | --i) | |
5210 | { | |
5211 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
5212 | { | |
5213 | TYPE_VPTR_FIELDNO (type) = i; | |
5214 | TYPE_VPTR_BASETYPE (type) = type; | |
5215 | break; | |
5216 | } | |
5217 | } | |
5218 | } | |
c906108c | 5219 | } |
c906108c | 5220 | } |
63d06c5c | 5221 | |
0b92b5bb TT |
5222 | quirk_gcc_member_function_pointer (type, cu->objfile); |
5223 | ||
0114d602 | 5224 | do_cleanups (back_to); |
f792889a | 5225 | return type; |
c906108c SS |
5226 | } |
5227 | ||
134d01f1 DJ |
5228 | static void |
5229 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5230 | { | |
5231 | struct objfile *objfile = cu->objfile; | |
90aeadfc | 5232 | struct die_info *child_die = die->child; |
f792889a | 5233 | struct type *this_type; |
c906108c | 5234 | |
f792889a DJ |
5235 | this_type = get_die_type (die, cu); |
5236 | if (this_type == NULL) | |
5237 | this_type = read_structure_type (die, cu); | |
c906108c | 5238 | |
90aeadfc DC |
5239 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
5240 | snapshots) has been known to create a die giving a declaration | |
5241 | for a class that has, as a child, a die giving a definition for a | |
5242 | nested class. So we have to process our children even if the | |
5243 | current die is a declaration. Normally, of course, a declaration | |
5244 | won't have any children at all. */ | |
134d01f1 | 5245 | |
90aeadfc DC |
5246 | while (child_die != NULL && child_die->tag) |
5247 | { | |
5248 | if (child_die->tag == DW_TAG_member | |
5249 | || child_die->tag == DW_TAG_variable | |
5250 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 5251 | { |
90aeadfc | 5252 | /* Do nothing. */ |
134d01f1 | 5253 | } |
90aeadfc DC |
5254 | else |
5255 | process_die (child_die, cu); | |
134d01f1 | 5256 | |
90aeadfc | 5257 | child_die = sibling_die (child_die); |
134d01f1 DJ |
5258 | } |
5259 | ||
fa4028e9 JB |
5260 | /* Do not consider external references. According to the DWARF standard, |
5261 | these DIEs are identified by the fact that they have no byte_size | |
5262 | attribute, and a declaration attribute. */ | |
5263 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
5264 | || !die_is_declaration (die, cu)) | |
f792889a | 5265 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
5266 | } |
5267 | ||
5268 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
5269 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 5270 | |
f792889a | 5271 | static struct type * |
134d01f1 | 5272 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5273 | { |
e7c27a73 | 5274 | struct objfile *objfile = cu->objfile; |
c906108c | 5275 | struct type *type; |
c906108c | 5276 | struct attribute *attr; |
0114d602 | 5277 | const char *name; |
134d01f1 | 5278 | |
348e048f DE |
5279 | /* If the definition of this type lives in .debug_types, read that type. |
5280 | Don't follow DW_AT_specification though, that will take us back up | |
5281 | the chain and we want to go down. */ | |
5282 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
5283 | if (attr) | |
5284 | { | |
5285 | struct dwarf2_cu *type_cu = cu; | |
5286 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
5287 | type = read_type_die (type_die, type_cu); | |
5288 | return set_die_type (die, type, cu); | |
5289 | } | |
5290 | ||
c906108c SS |
5291 | type = alloc_type (objfile); |
5292 | ||
5293 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 5294 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 5295 | if (name != NULL) |
0114d602 | 5296 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 5297 | |
e142c38c | 5298 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5299 | if (attr) |
5300 | { | |
5301 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5302 | } | |
5303 | else | |
5304 | { | |
5305 | TYPE_LENGTH (type) = 0; | |
5306 | } | |
5307 | ||
137033e9 JB |
5308 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
5309 | declared as private in the package spec, and then defined only | |
5310 | inside the package body. Such types are known as Taft Amendment | |
5311 | Types. When another package uses such a type, an incomplete DIE | |
5312 | may be generated by the compiler. */ | |
02eb380e | 5313 | if (die_is_declaration (die, cu)) |
876cecd0 | 5314 | TYPE_STUB (type) = 1; |
02eb380e | 5315 | |
f792889a | 5316 | return set_die_type (die, type, cu); |
134d01f1 DJ |
5317 | } |
5318 | ||
5319 | /* Given a pointer to a die which begins an enumeration, process all | |
5320 | the dies that define the members of the enumeration, and create the | |
5321 | symbol for the enumeration type. | |
5322 | ||
5323 | NOTE: We reverse the order of the element list. */ | |
5324 | ||
5325 | static void | |
5326 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5327 | { | |
5328 | struct objfile *objfile = cu->objfile; | |
5329 | struct die_info *child_die; | |
5330 | struct field *fields; | |
134d01f1 DJ |
5331 | struct symbol *sym; |
5332 | int num_fields; | |
5333 | int unsigned_enum = 1; | |
39cbfefa | 5334 | char *name; |
f792889a | 5335 | struct type *this_type; |
134d01f1 | 5336 | |
c906108c SS |
5337 | num_fields = 0; |
5338 | fields = NULL; | |
f792889a DJ |
5339 | this_type = get_die_type (die, cu); |
5340 | if (this_type == NULL) | |
5341 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 5342 | if (die->child != NULL) |
c906108c | 5343 | { |
639d11d3 | 5344 | child_die = die->child; |
c906108c SS |
5345 | while (child_die && child_die->tag) |
5346 | { | |
5347 | if (child_die->tag != DW_TAG_enumerator) | |
5348 | { | |
e7c27a73 | 5349 | process_die (child_die, cu); |
c906108c SS |
5350 | } |
5351 | else | |
5352 | { | |
39cbfefa DJ |
5353 | name = dwarf2_name (child_die, cu); |
5354 | if (name) | |
c906108c | 5355 | { |
f792889a | 5356 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
5357 | if (SYMBOL_VALUE (sym) < 0) |
5358 | unsigned_enum = 0; | |
5359 | ||
5360 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
5361 | { | |
5362 | fields = (struct field *) | |
5363 | xrealloc (fields, | |
5364 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 5365 | * sizeof (struct field)); |
c906108c SS |
5366 | } |
5367 | ||
3567439c | 5368 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 5369 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 5370 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
5371 | FIELD_BITSIZE (fields[num_fields]) = 0; |
5372 | ||
5373 | num_fields++; | |
5374 | } | |
5375 | } | |
5376 | ||
5377 | child_die = sibling_die (child_die); | |
5378 | } | |
5379 | ||
5380 | if (num_fields) | |
5381 | { | |
f792889a DJ |
5382 | TYPE_NFIELDS (this_type) = num_fields; |
5383 | TYPE_FIELDS (this_type) = (struct field *) | |
5384 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
5385 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 5386 | sizeof (struct field) * num_fields); |
b8c9b27d | 5387 | xfree (fields); |
c906108c SS |
5388 | } |
5389 | if (unsigned_enum) | |
876cecd0 | 5390 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 5391 | } |
134d01f1 | 5392 | |
f792889a | 5393 | new_symbol (die, this_type, cu); |
c906108c SS |
5394 | } |
5395 | ||
5396 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
5397 | the DIE's type field. For now, this only handles one dimensional | |
5398 | arrays. */ | |
5399 | ||
f792889a | 5400 | static struct type * |
e7c27a73 | 5401 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5402 | { |
e7c27a73 | 5403 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5404 | struct die_info *child_die; |
5405 | struct type *type = NULL; | |
5406 | struct type *element_type, *range_type, *index_type; | |
5407 | struct type **range_types = NULL; | |
5408 | struct attribute *attr; | |
5409 | int ndim = 0; | |
5410 | struct cleanup *back_to; | |
39cbfefa | 5411 | char *name; |
c906108c | 5412 | |
e7c27a73 | 5413 | element_type = die_type (die, cu); |
c906108c SS |
5414 | |
5415 | /* Irix 6.2 native cc creates array types without children for | |
5416 | arrays with unspecified length. */ | |
639d11d3 | 5417 | if (die->child == NULL) |
c906108c | 5418 | { |
46bf5051 | 5419 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5420 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
5421 | type = create_array_type (NULL, element_type, range_type); |
5422 | return set_die_type (die, type, cu); | |
c906108c SS |
5423 | } |
5424 | ||
5425 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 5426 | child_die = die->child; |
c906108c SS |
5427 | while (child_die && child_die->tag) |
5428 | { | |
5429 | if (child_die->tag == DW_TAG_subrange_type) | |
5430 | { | |
f792889a DJ |
5431 | struct type *child_type = read_type_die (child_die, cu); |
5432 | if (child_type != NULL) | |
a02abb62 JB |
5433 | { |
5434 | /* The range type was succesfully read. Save it for | |
5435 | the array type creation. */ | |
5436 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
5437 | { | |
5438 | range_types = (struct type **) | |
5439 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
5440 | * sizeof (struct type *)); | |
5441 | if (ndim == 0) | |
5442 | make_cleanup (free_current_contents, &range_types); | |
5443 | } | |
f792889a | 5444 | range_types[ndim++] = child_type; |
a02abb62 | 5445 | } |
c906108c SS |
5446 | } |
5447 | child_die = sibling_die (child_die); | |
5448 | } | |
5449 | ||
5450 | /* Dwarf2 dimensions are output from left to right, create the | |
5451 | necessary array types in backwards order. */ | |
7ca2d3a3 | 5452 | |
c906108c | 5453 | type = element_type; |
7ca2d3a3 DL |
5454 | |
5455 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
5456 | { | |
5457 | int i = 0; | |
5458 | while (i < ndim) | |
5459 | type = create_array_type (NULL, type, range_types[i++]); | |
5460 | } | |
5461 | else | |
5462 | { | |
5463 | while (ndim-- > 0) | |
5464 | type = create_array_type (NULL, type, range_types[ndim]); | |
5465 | } | |
c906108c | 5466 | |
f5f8a009 EZ |
5467 | /* Understand Dwarf2 support for vector types (like they occur on |
5468 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
5469 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
5470 | custom vendor extension. The main difference between a regular | |
5471 | array and the vector variant is that vectors are passed by value | |
5472 | to functions. */ | |
e142c38c | 5473 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 5474 | if (attr) |
ea37ba09 | 5475 | make_vector_type (type); |
f5f8a009 | 5476 | |
39cbfefa DJ |
5477 | name = dwarf2_name (die, cu); |
5478 | if (name) | |
5479 | TYPE_NAME (type) = name; | |
714e295e | 5480 | |
b4ba55a1 JB |
5481 | set_descriptive_type (type, die, cu); |
5482 | ||
c906108c SS |
5483 | do_cleanups (back_to); |
5484 | ||
5485 | /* Install the type in the die. */ | |
f792889a | 5486 | return set_die_type (die, type, cu); |
c906108c SS |
5487 | } |
5488 | ||
7ca2d3a3 DL |
5489 | static enum dwarf_array_dim_ordering |
5490 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
5491 | { | |
5492 | struct attribute *attr; | |
5493 | ||
5494 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
5495 | ||
5496 | if (attr) return DW_SND (attr); | |
5497 | ||
5498 | /* | |
5499 | GNU F77 is a special case, as at 08/2004 array type info is the | |
5500 | opposite order to the dwarf2 specification, but data is still | |
5501 | laid out as per normal fortran. | |
5502 | ||
5503 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
5504 | version checking. | |
5505 | */ | |
5506 | ||
905e0470 PM |
5507 | if (cu->language == language_fortran |
5508 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
5509 | { |
5510 | return DW_ORD_row_major; | |
5511 | } | |
5512 | ||
5513 | switch (cu->language_defn->la_array_ordering) | |
5514 | { | |
5515 | case array_column_major: | |
5516 | return DW_ORD_col_major; | |
5517 | case array_row_major: | |
5518 | default: | |
5519 | return DW_ORD_row_major; | |
5520 | }; | |
5521 | } | |
5522 | ||
72019c9c GM |
5523 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
5524 | the DIE's type field. */ | |
5525 | ||
f792889a | 5526 | static struct type * |
72019c9c GM |
5527 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
5528 | { | |
f792889a DJ |
5529 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
5530 | ||
5531 | return set_die_type (die, set_type, cu); | |
72019c9c | 5532 | } |
7ca2d3a3 | 5533 | |
c906108c SS |
5534 | /* First cut: install each common block member as a global variable. */ |
5535 | ||
5536 | static void | |
e7c27a73 | 5537 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5538 | { |
5539 | struct die_info *child_die; | |
5540 | struct attribute *attr; | |
5541 | struct symbol *sym; | |
5542 | CORE_ADDR base = (CORE_ADDR) 0; | |
5543 | ||
e142c38c | 5544 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
5545 | if (attr) |
5546 | { | |
8e19ed76 PS |
5547 | /* Support the .debug_loc offsets */ |
5548 | if (attr_form_is_block (attr)) | |
5549 | { | |
e7c27a73 | 5550 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 5551 | } |
3690dd37 | 5552 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 5553 | { |
4d3c2250 | 5554 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5555 | } |
5556 | else | |
5557 | { | |
4d3c2250 KB |
5558 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5559 | "common block member"); | |
8e19ed76 | 5560 | } |
c906108c | 5561 | } |
639d11d3 | 5562 | if (die->child != NULL) |
c906108c | 5563 | { |
639d11d3 | 5564 | child_die = die->child; |
c906108c SS |
5565 | while (child_die && child_die->tag) |
5566 | { | |
e7c27a73 | 5567 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 5568 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
5569 | if (attr) |
5570 | { | |
d4b96c9a JK |
5571 | CORE_ADDR byte_offset = 0; |
5572 | ||
5573 | if (attr_form_is_section_offset (attr)) | |
5574 | dwarf2_complex_location_expr_complaint (); | |
5575 | else if (attr_form_is_constant (attr)) | |
5576 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
5577 | else if (attr_form_is_block (attr)) | |
5578 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
5579 | else | |
5580 | dwarf2_complex_location_expr_complaint (); | |
5581 | ||
5582 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
5583 | add_symbol_to_list (sym, &global_symbols); |
5584 | } | |
5585 | child_die = sibling_die (child_die); | |
5586 | } | |
5587 | } | |
5588 | } | |
5589 | ||
0114d602 | 5590 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 5591 | |
0114d602 DJ |
5592 | static struct type * |
5593 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 5594 | { |
e7c27a73 | 5595 | struct objfile *objfile = cu->objfile; |
0114d602 | 5596 | const char *previous_prefix, *name; |
9219021c | 5597 | int is_anonymous; |
0114d602 DJ |
5598 | struct type *type; |
5599 | ||
5600 | /* For extensions, reuse the type of the original namespace. */ | |
5601 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
5602 | { | |
5603 | struct die_info *ext_die; | |
5604 | struct dwarf2_cu *ext_cu = cu; | |
5605 | ext_die = dwarf2_extension (die, &ext_cu); | |
5606 | type = read_type_die (ext_die, ext_cu); | |
5607 | return set_die_type (die, type, cu); | |
5608 | } | |
9219021c | 5609 | |
e142c38c | 5610 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
5611 | |
5612 | /* Now build the name of the current namespace. */ | |
5613 | ||
0114d602 DJ |
5614 | previous_prefix = determine_prefix (die, cu); |
5615 | if (previous_prefix[0] != '\0') | |
5616 | name = typename_concat (&objfile->objfile_obstack, | |
5617 | previous_prefix, name, cu); | |
5618 | ||
5619 | /* Create the type. */ | |
5620 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
5621 | objfile); | |
5622 | TYPE_NAME (type) = (char *) name; | |
5623 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5624 | ||
5625 | set_die_type (die, type, cu); | |
5626 | ||
5627 | return type; | |
5628 | } | |
5629 | ||
5630 | /* Read a C++ namespace. */ | |
5631 | ||
5632 | static void | |
5633 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
5634 | { | |
5635 | struct objfile *objfile = cu->objfile; | |
5636 | const char *name; | |
5637 | int is_anonymous; | |
9219021c | 5638 | |
5c4e30ca DC |
5639 | /* Add a symbol associated to this if we haven't seen the namespace |
5640 | before. Also, add a using directive if it's an anonymous | |
5641 | namespace. */ | |
9219021c | 5642 | |
f2f0e013 | 5643 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
5644 | { |
5645 | struct type *type; | |
5646 | ||
0114d602 | 5647 | type = read_type_die (die, cu); |
e7c27a73 | 5648 | new_symbol (die, type, cu); |
5c4e30ca | 5649 | |
0114d602 | 5650 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 5651 | if (is_anonymous) |
0114d602 DJ |
5652 | { |
5653 | const char *previous_prefix = determine_prefix (die, cu); | |
82856980 | 5654 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL); |
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 | 5776 | { |
e7c27a73 | 5777 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5778 | struct type *type; |
5779 | struct type *to_type; | |
5780 | struct type *domain; | |
5781 | ||
e7c27a73 DJ |
5782 | to_type = die_type (die, cu); |
5783 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
5784 | |
5785 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
5786 | type = lookup_methodptr_type (to_type); | |
5787 | else | |
5788 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 5789 | |
f792889a | 5790 | return set_die_type (die, type, cu); |
c906108c SS |
5791 | } |
5792 | ||
5793 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
5794 | the user defined type vector. */ | |
5795 | ||
f792889a | 5796 | static struct type * |
e7c27a73 | 5797 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5798 | { |
e7c27a73 | 5799 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5800 | struct type *type; |
5801 | struct attribute *attr; | |
5802 | ||
e7c27a73 | 5803 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 5804 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5805 | if (attr) |
5806 | { | |
5807 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5808 | } | |
5809 | else | |
5810 | { | |
107d2387 | 5811 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 5812 | } |
f792889a | 5813 | return set_die_type (die, type, cu); |
c906108c SS |
5814 | } |
5815 | ||
f792889a | 5816 | static struct type * |
e7c27a73 | 5817 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5818 | { |
f792889a | 5819 | struct type *base_type, *cv_type; |
c906108c | 5820 | |
e7c27a73 | 5821 | base_type = die_type (die, cu); |
f792889a DJ |
5822 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
5823 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5824 | } |
5825 | ||
f792889a | 5826 | static struct type * |
e7c27a73 | 5827 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5828 | { |
f792889a | 5829 | struct type *base_type, *cv_type; |
c906108c | 5830 | |
e7c27a73 | 5831 | base_type = die_type (die, cu); |
f792889a DJ |
5832 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
5833 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5834 | } |
5835 | ||
5836 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
5837 | the user defined type vector. It isn't really a user defined type, | |
5838 | but it behaves like one, with other DIE's using an AT_user_def_type | |
5839 | attribute to reference it. */ | |
5840 | ||
f792889a | 5841 | static struct type * |
e7c27a73 | 5842 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5843 | { |
e7c27a73 | 5844 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 5845 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5846 | struct type *type, *range_type, *index_type, *char_type; |
5847 | struct attribute *attr; | |
5848 | unsigned int length; | |
5849 | ||
e142c38c | 5850 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
5851 | if (attr) |
5852 | { | |
5853 | length = DW_UNSND (attr); | |
5854 | } | |
5855 | else | |
5856 | { | |
b21b22e0 | 5857 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 5858 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
5859 | if (attr) |
5860 | { | |
5861 | length = DW_UNSND (attr); | |
5862 | } | |
5863 | else | |
5864 | { | |
5865 | length = 1; | |
5866 | } | |
c906108c | 5867 | } |
6ccb9162 | 5868 | |
46bf5051 | 5869 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5870 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
5871 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
5872 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 5873 | |
f792889a | 5874 | return set_die_type (die, type, cu); |
c906108c SS |
5875 | } |
5876 | ||
5877 | /* Handle DIES due to C code like: | |
5878 | ||
5879 | struct foo | |
c5aa993b JM |
5880 | { |
5881 | int (*funcp)(int a, long l); | |
5882 | int b; | |
5883 | }; | |
c906108c SS |
5884 | |
5885 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 5886 | */ |
c906108c | 5887 | |
f792889a | 5888 | static struct type * |
e7c27a73 | 5889 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5890 | { |
5891 | struct type *type; /* Type that this function returns */ | |
5892 | struct type *ftype; /* Function that returns above type */ | |
5893 | struct attribute *attr; | |
5894 | ||
e7c27a73 | 5895 | type = die_type (die, cu); |
0c8b41f1 | 5896 | ftype = lookup_function_type (type); |
c906108c | 5897 | |
5b8101ae | 5898 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 5899 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 5900 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 5901 | || cu->language == language_cplus |
5b8101ae PM |
5902 | || cu->language == language_java |
5903 | || cu->language == language_pascal) | |
876cecd0 | 5904 | TYPE_PROTOTYPED (ftype) = 1; |
c906108c | 5905 | |
c055b101 CV |
5906 | /* Store the calling convention in the type if it's available in |
5907 | the subroutine die. Otherwise set the calling convention to | |
5908 | the default value DW_CC_normal. */ | |
5909 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
5910 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
5911 | |
5912 | /* We need to add the subroutine type to the die immediately so | |
5913 | we don't infinitely recurse when dealing with parameters | |
5914 | declared as the same subroutine type. */ | |
5915 | set_die_type (die, ftype, cu); | |
c055b101 | 5916 | |
639d11d3 | 5917 | if (die->child != NULL) |
c906108c SS |
5918 | { |
5919 | struct die_info *child_die; | |
5920 | int nparams = 0; | |
5921 | int iparams = 0; | |
5922 | ||
5923 | /* Count the number of parameters. | |
5924 | FIXME: GDB currently ignores vararg functions, but knows about | |
5925 | vararg member functions. */ | |
639d11d3 | 5926 | child_die = die->child; |
c906108c SS |
5927 | while (child_die && child_die->tag) |
5928 | { | |
5929 | if (child_die->tag == DW_TAG_formal_parameter) | |
5930 | nparams++; | |
5931 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 5932 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
5933 | child_die = sibling_die (child_die); |
5934 | } | |
5935 | ||
5936 | /* Allocate storage for parameters and fill them in. */ | |
5937 | TYPE_NFIELDS (ftype) = nparams; | |
5938 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 5939 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 5940 | |
639d11d3 | 5941 | child_die = die->child; |
c906108c SS |
5942 | while (child_die && child_die->tag) |
5943 | { | |
5944 | if (child_die->tag == DW_TAG_formal_parameter) | |
5945 | { | |
5946 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
5947 | member functions. G++ helps GDB by marking the first |
5948 | parameter for non-static member functions (which is the | |
5949 | this pointer) as artificial. We pass this information | |
5950 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 5951 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
5952 | if (attr) |
5953 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
5954 | else | |
5955 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 5956 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
5957 | iparams++; |
5958 | } | |
5959 | child_die = sibling_die (child_die); | |
5960 | } | |
5961 | } | |
5962 | ||
76c10ea2 | 5963 | return ftype; |
c906108c SS |
5964 | } |
5965 | ||
f792889a | 5966 | static struct type * |
e7c27a73 | 5967 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5968 | { |
e7c27a73 | 5969 | struct objfile *objfile = cu->objfile; |
2f038fcb | 5970 | struct attribute *attr; |
0114d602 | 5971 | const char *name = NULL; |
f792889a | 5972 | struct type *this_type; |
c906108c | 5973 | |
94af9270 | 5974 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 5975 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
5976 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
5977 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
5978 | set_die_type (die, this_type, cu); |
5979 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
5980 | return this_type; | |
c906108c SS |
5981 | } |
5982 | ||
5983 | /* Find a representation of a given base type and install | |
5984 | it in the TYPE field of the die. */ | |
5985 | ||
f792889a | 5986 | static struct type * |
e7c27a73 | 5987 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5988 | { |
e7c27a73 | 5989 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5990 | struct type *type; |
5991 | struct attribute *attr; | |
5992 | int encoding = 0, size = 0; | |
39cbfefa | 5993 | char *name; |
6ccb9162 UW |
5994 | enum type_code code = TYPE_CODE_INT; |
5995 | int type_flags = 0; | |
5996 | struct type *target_type = NULL; | |
c906108c | 5997 | |
e142c38c | 5998 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
5999 | if (attr) |
6000 | { | |
6001 | encoding = DW_UNSND (attr); | |
6002 | } | |
e142c38c | 6003 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6004 | if (attr) |
6005 | { | |
6006 | size = DW_UNSND (attr); | |
6007 | } | |
39cbfefa | 6008 | name = dwarf2_name (die, cu); |
6ccb9162 | 6009 | if (!name) |
c906108c | 6010 | { |
6ccb9162 UW |
6011 | complaint (&symfile_complaints, |
6012 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 6013 | } |
6ccb9162 UW |
6014 | |
6015 | switch (encoding) | |
c906108c | 6016 | { |
6ccb9162 UW |
6017 | case DW_ATE_address: |
6018 | /* Turn DW_ATE_address into a void * pointer. */ | |
6019 | code = TYPE_CODE_PTR; | |
6020 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6021 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
6022 | break; | |
6023 | case DW_ATE_boolean: | |
6024 | code = TYPE_CODE_BOOL; | |
6025 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6026 | break; | |
6027 | case DW_ATE_complex_float: | |
6028 | code = TYPE_CODE_COMPLEX; | |
6029 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
6030 | break; | |
6031 | case DW_ATE_decimal_float: | |
6032 | code = TYPE_CODE_DECFLOAT; | |
6033 | break; | |
6034 | case DW_ATE_float: | |
6035 | code = TYPE_CODE_FLT; | |
6036 | break; | |
6037 | case DW_ATE_signed: | |
6038 | break; | |
6039 | case DW_ATE_unsigned: | |
6040 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6041 | break; | |
6042 | case DW_ATE_signed_char: | |
868a0084 PM |
6043 | if (cu->language == language_ada || cu->language == language_m2 |
6044 | || cu->language == language_pascal) | |
6ccb9162 UW |
6045 | code = TYPE_CODE_CHAR; |
6046 | break; | |
6047 | case DW_ATE_unsigned_char: | |
868a0084 PM |
6048 | if (cu->language == language_ada || cu->language == language_m2 |
6049 | || cu->language == language_pascal) | |
6ccb9162 UW |
6050 | code = TYPE_CODE_CHAR; |
6051 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6052 | break; | |
6053 | default: | |
6054 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
6055 | dwarf_type_encoding_name (encoding)); | |
6056 | break; | |
c906108c | 6057 | } |
6ccb9162 | 6058 | |
0114d602 DJ |
6059 | type = init_type (code, size, type_flags, NULL, objfile); |
6060 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
6061 | TYPE_TARGET_TYPE (type) = target_type; |
6062 | ||
0114d602 | 6063 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 6064 | TYPE_NOSIGN (type) = 1; |
0114d602 | 6065 | |
f792889a | 6066 | return set_die_type (die, type, cu); |
c906108c SS |
6067 | } |
6068 | ||
a02abb62 JB |
6069 | /* Read the given DW_AT_subrange DIE. */ |
6070 | ||
f792889a | 6071 | static struct type * |
a02abb62 JB |
6072 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
6073 | { | |
5e2b427d | 6074 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
6075 | struct type *base_type; |
6076 | struct type *range_type; | |
6077 | struct attribute *attr; | |
43bbcdc2 PH |
6078 | LONGEST low = 0; |
6079 | LONGEST high = -1; | |
39cbfefa | 6080 | char *name; |
43bbcdc2 | 6081 | LONGEST negative_mask; |
a02abb62 | 6082 | |
a02abb62 | 6083 | base_type = die_type (die, cu); |
3d1f72c2 | 6084 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
6085 | { |
6086 | complaint (&symfile_complaints, | |
e2e0b3e5 | 6087 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 6088 | base_type |
5e2b427d | 6089 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 6090 | 0, NULL, cu->objfile); |
a02abb62 JB |
6091 | } |
6092 | ||
e142c38c | 6093 | if (cu->language == language_fortran) |
a02abb62 JB |
6094 | { |
6095 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
6096 | low = 1; | |
6097 | } | |
6098 | ||
dd5e6932 DJ |
6099 | /* FIXME: For variable sized arrays either of these could be |
6100 | a variable rather than a constant value. We'll allow it, | |
6101 | but we don't know how to handle it. */ | |
e142c38c | 6102 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
6103 | if (attr) |
6104 | low = dwarf2_get_attr_constant_value (attr, 0); | |
6105 | ||
e142c38c | 6106 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
6107 | if (attr) |
6108 | { | |
6109 | if (attr->form == DW_FORM_block1) | |
6110 | { | |
6111 | /* GCC encodes arrays with unspecified or dynamic length | |
6112 | with a DW_FORM_block1 attribute. | |
6113 | FIXME: GDB does not yet know how to handle dynamic | |
6114 | arrays properly, treat them as arrays with unspecified | |
6115 | length for now. | |
6116 | ||
6117 | FIXME: jimb/2003-09-22: GDB does not really know | |
6118 | how to handle arrays of unspecified length | |
6119 | either; we just represent them as zero-length | |
6120 | arrays. Choose an appropriate upper bound given | |
6121 | the lower bound we've computed above. */ | |
6122 | high = low - 1; | |
6123 | } | |
6124 | else | |
6125 | high = dwarf2_get_attr_constant_value (attr, 1); | |
6126 | } | |
6127 | ||
43bbcdc2 PH |
6128 | negative_mask = |
6129 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); | |
6130 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
6131 | low |= negative_mask; | |
6132 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
6133 | high |= negative_mask; | |
6134 | ||
a02abb62 JB |
6135 | range_type = create_range_type (NULL, base_type, low, high); |
6136 | ||
39cbfefa DJ |
6137 | name = dwarf2_name (die, cu); |
6138 | if (name) | |
6139 | TYPE_NAME (range_type) = name; | |
a02abb62 | 6140 | |
e142c38c | 6141 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
6142 | if (attr) |
6143 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
6144 | ||
b4ba55a1 JB |
6145 | set_descriptive_type (range_type, die, cu); |
6146 | ||
f792889a | 6147 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
6148 | } |
6149 | ||
f792889a | 6150 | static struct type * |
81a17f79 JB |
6151 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
6152 | { | |
6153 | struct type *type; | |
81a17f79 | 6154 | |
81a17f79 JB |
6155 | /* For now, we only support the C meaning of an unspecified type: void. */ |
6156 | ||
0114d602 DJ |
6157 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
6158 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 6159 | |
f792889a | 6160 | return set_die_type (die, type, cu); |
81a17f79 | 6161 | } |
a02abb62 | 6162 | |
51545339 DJ |
6163 | /* Trivial hash function for die_info: the hash value of a DIE |
6164 | is its offset in .debug_info for this objfile. */ | |
6165 | ||
6166 | static hashval_t | |
6167 | die_hash (const void *item) | |
6168 | { | |
6169 | const struct die_info *die = item; | |
6170 | return die->offset; | |
6171 | } | |
6172 | ||
6173 | /* Trivial comparison function for die_info structures: two DIEs | |
6174 | are equal if they have the same offset. */ | |
6175 | ||
6176 | static int | |
6177 | die_eq (const void *item_lhs, const void *item_rhs) | |
6178 | { | |
6179 | const struct die_info *die_lhs = item_lhs; | |
6180 | const struct die_info *die_rhs = item_rhs; | |
6181 | return die_lhs->offset == die_rhs->offset; | |
6182 | } | |
6183 | ||
c906108c SS |
6184 | /* Read a whole compilation unit into a linked list of dies. */ |
6185 | ||
f9aca02d | 6186 | static struct die_info * |
93311388 | 6187 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 6188 | { |
93311388 DE |
6189 | struct die_reader_specs reader_specs; |
6190 | ||
348e048f | 6191 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
6192 | cu->die_hash |
6193 | = htab_create_alloc_ex (cu->header.length / 12, | |
6194 | die_hash, | |
6195 | die_eq, | |
6196 | NULL, | |
6197 | &cu->comp_unit_obstack, | |
6198 | hashtab_obstack_allocate, | |
6199 | dummy_obstack_deallocate); | |
6200 | ||
93311388 DE |
6201 | init_cu_die_reader (&reader_specs, cu); |
6202 | ||
6203 | return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); | |
639d11d3 DC |
6204 | } |
6205 | ||
d97bc12b DE |
6206 | /* Main entry point for reading a DIE and all children. |
6207 | Read the DIE and dump it if requested. */ | |
6208 | ||
6209 | static struct die_info * | |
93311388 DE |
6210 | read_die_and_children (const struct die_reader_specs *reader, |
6211 | gdb_byte *info_ptr, | |
d97bc12b DE |
6212 | gdb_byte **new_info_ptr, |
6213 | struct die_info *parent) | |
6214 | { | |
93311388 | 6215 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
6216 | new_info_ptr, parent); |
6217 | ||
6218 | if (dwarf2_die_debug) | |
6219 | { | |
348e048f DE |
6220 | fprintf_unfiltered (gdb_stdlog, |
6221 | "\nRead die from %s of %s:\n", | |
6222 | reader->buffer == dwarf2_per_objfile->info.buffer | |
6223 | ? ".debug_info" | |
6224 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
6225 | ? ".debug_types" | |
6226 | : "unknown section", | |
6227 | reader->abfd->filename); | |
d97bc12b DE |
6228 | dump_die (result, dwarf2_die_debug); |
6229 | } | |
6230 | ||
6231 | return result; | |
6232 | } | |
6233 | ||
639d11d3 DC |
6234 | /* Read a single die and all its descendents. Set the die's sibling |
6235 | field to NULL; set other fields in the die correctly, and set all | |
6236 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
6237 | location of the info_ptr after reading all of those dies. PARENT | |
6238 | is the parent of the die in question. */ | |
6239 | ||
6240 | static struct die_info * | |
93311388 DE |
6241 | read_die_and_children_1 (const struct die_reader_specs *reader, |
6242 | gdb_byte *info_ptr, | |
d97bc12b DE |
6243 | gdb_byte **new_info_ptr, |
6244 | struct die_info *parent) | |
639d11d3 DC |
6245 | { |
6246 | struct die_info *die; | |
fe1b8b76 | 6247 | gdb_byte *cur_ptr; |
639d11d3 DC |
6248 | int has_children; |
6249 | ||
93311388 | 6250 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
6251 | if (die == NULL) |
6252 | { | |
6253 | *new_info_ptr = cur_ptr; | |
6254 | return NULL; | |
6255 | } | |
93311388 | 6256 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
6257 | |
6258 | if (has_children) | |
348e048f | 6259 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
6260 | else |
6261 | { | |
6262 | die->child = NULL; | |
6263 | *new_info_ptr = cur_ptr; | |
6264 | } | |
6265 | ||
6266 | die->sibling = NULL; | |
6267 | die->parent = parent; | |
6268 | return die; | |
6269 | } | |
6270 | ||
6271 | /* Read a die, all of its descendents, and all of its siblings; set | |
6272 | all of the fields of all of the dies correctly. Arguments are as | |
6273 | in read_die_and_children. */ | |
6274 | ||
6275 | static struct die_info * | |
93311388 DE |
6276 | read_die_and_siblings (const struct die_reader_specs *reader, |
6277 | gdb_byte *info_ptr, | |
fe1b8b76 | 6278 | gdb_byte **new_info_ptr, |
639d11d3 DC |
6279 | struct die_info *parent) |
6280 | { | |
6281 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 6282 | gdb_byte *cur_ptr; |
639d11d3 | 6283 | |
c906108c | 6284 | cur_ptr = info_ptr; |
639d11d3 DC |
6285 | first_die = last_sibling = NULL; |
6286 | ||
6287 | while (1) | |
c906108c | 6288 | { |
639d11d3 | 6289 | struct die_info *die |
93311388 | 6290 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 6291 | |
1d325ec1 | 6292 | if (die == NULL) |
c906108c | 6293 | { |
639d11d3 DC |
6294 | *new_info_ptr = cur_ptr; |
6295 | return first_die; | |
c906108c | 6296 | } |
1d325ec1 DJ |
6297 | |
6298 | if (!first_die) | |
6299 | first_die = die; | |
c906108c | 6300 | else |
1d325ec1 DJ |
6301 | last_sibling->sibling = die; |
6302 | ||
6303 | last_sibling = die; | |
c906108c | 6304 | } |
c906108c SS |
6305 | } |
6306 | ||
93311388 DE |
6307 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6308 | point to a newly allocated die with its information, except for its | |
6309 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6310 | whether the die has children or not. */ | |
6311 | ||
6312 | static gdb_byte * | |
6313 | read_full_die (const struct die_reader_specs *reader, | |
6314 | struct die_info **diep, gdb_byte *info_ptr, | |
6315 | int *has_children) | |
6316 | { | |
6317 | unsigned int abbrev_number, bytes_read, i, offset; | |
6318 | struct abbrev_info *abbrev; | |
6319 | struct die_info *die; | |
6320 | struct dwarf2_cu *cu = reader->cu; | |
6321 | bfd *abfd = reader->abfd; | |
6322 | ||
6323 | offset = info_ptr - reader->buffer; | |
6324 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6325 | info_ptr += bytes_read; | |
6326 | if (!abbrev_number) | |
6327 | { | |
6328 | *diep = NULL; | |
6329 | *has_children = 0; | |
6330 | return info_ptr; | |
6331 | } | |
6332 | ||
6333 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
6334 | if (!abbrev) | |
348e048f DE |
6335 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
6336 | abbrev_number, | |
6337 | bfd_get_filename (abfd)); | |
6338 | ||
93311388 DE |
6339 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
6340 | die->offset = offset; | |
6341 | die->tag = abbrev->tag; | |
6342 | die->abbrev = abbrev_number; | |
6343 | ||
6344 | die->num_attrs = abbrev->num_attrs; | |
6345 | ||
6346 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6347 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
6348 | abfd, info_ptr, cu); | |
6349 | ||
6350 | *diep = die; | |
6351 | *has_children = abbrev->has_children; | |
6352 | return info_ptr; | |
6353 | } | |
6354 | ||
c906108c SS |
6355 | /* In DWARF version 2, the description of the debugging information is |
6356 | stored in a separate .debug_abbrev section. Before we read any | |
6357 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
6358 | in a hash table. This function also sets flags in CU describing |
6359 | the data found in the abbrev table. */ | |
c906108c SS |
6360 | |
6361 | static void | |
e7c27a73 | 6362 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 6363 | { |
e7c27a73 | 6364 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 6365 | gdb_byte *abbrev_ptr; |
c906108c SS |
6366 | struct abbrev_info *cur_abbrev; |
6367 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
6368 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
6369 | struct attr_abbrev *cur_attrs; |
6370 | unsigned int allocated_attrs; | |
c906108c | 6371 | |
57349743 | 6372 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
6373 | obstack_init (&cu->abbrev_obstack); |
6374 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
6375 | (ABBREV_HASH_SIZE | |
6376 | * sizeof (struct abbrev_info *))); | |
6377 | memset (cu->dwarf2_abbrevs, 0, | |
6378 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 6379 | |
dce234bc | 6380 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
6381 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6382 | abbrev_ptr += bytes_read; | |
6383 | ||
f3dd6933 DJ |
6384 | allocated_attrs = ATTR_ALLOC_CHUNK; |
6385 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6386 | ||
c906108c SS |
6387 | /* loop until we reach an abbrev number of 0 */ |
6388 | while (abbrev_number) | |
6389 | { | |
f3dd6933 | 6390 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
6391 | |
6392 | /* read in abbrev header */ | |
6393 | cur_abbrev->number = abbrev_number; | |
6394 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6395 | abbrev_ptr += bytes_read; | |
6396 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
6397 | abbrev_ptr += 1; | |
6398 | ||
72bf9492 DJ |
6399 | if (cur_abbrev->tag == DW_TAG_namespace) |
6400 | cu->has_namespace_info = 1; | |
6401 | ||
c906108c SS |
6402 | /* now read in declarations */ |
6403 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6404 | abbrev_ptr += bytes_read; | |
6405 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6406 | abbrev_ptr += bytes_read; | |
6407 | while (abbrev_name) | |
6408 | { | |
f3dd6933 | 6409 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 6410 | { |
f3dd6933 DJ |
6411 | allocated_attrs += ATTR_ALLOC_CHUNK; |
6412 | cur_attrs | |
6413 | = xrealloc (cur_attrs, (allocated_attrs | |
6414 | * sizeof (struct attr_abbrev))); | |
c906108c | 6415 | } |
ae038cb0 DJ |
6416 | |
6417 | /* Record whether this compilation unit might have | |
6418 | inter-compilation-unit references. If we don't know what form | |
6419 | this attribute will have, then it might potentially be a | |
6420 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
6421 | references. */ | |
6422 | ||
6423 | if (abbrev_form == DW_FORM_ref_addr | |
6424 | || abbrev_form == DW_FORM_indirect) | |
6425 | cu->has_form_ref_addr = 1; | |
6426 | ||
f3dd6933 DJ |
6427 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
6428 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
6429 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6430 | abbrev_ptr += bytes_read; | |
6431 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6432 | abbrev_ptr += bytes_read; | |
6433 | } | |
6434 | ||
f3dd6933 DJ |
6435 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
6436 | (cur_abbrev->num_attrs | |
6437 | * sizeof (struct attr_abbrev))); | |
6438 | memcpy (cur_abbrev->attrs, cur_attrs, | |
6439 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
6440 | ||
c906108c | 6441 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
6442 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
6443 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
6444 | |
6445 | /* Get next abbreviation. | |
6446 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
6447 | always properly terminated with an abbrev number of 0. |
6448 | Exit loop if we encounter an abbreviation which we have | |
6449 | already read (which means we are about to read the abbreviations | |
6450 | for the next compile unit) or if the end of the abbreviation | |
6451 | table is reached. */ | |
dce234bc PP |
6452 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
6453 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
6454 | break; |
6455 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6456 | abbrev_ptr += bytes_read; | |
e7c27a73 | 6457 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
6458 | break; |
6459 | } | |
f3dd6933 DJ |
6460 | |
6461 | xfree (cur_attrs); | |
c906108c SS |
6462 | } |
6463 | ||
f3dd6933 | 6464 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 6465 | |
c906108c | 6466 | static void |
f3dd6933 | 6467 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 6468 | { |
f3dd6933 | 6469 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 6470 | |
f3dd6933 DJ |
6471 | obstack_free (&cu->abbrev_obstack, NULL); |
6472 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
6473 | } |
6474 | ||
6475 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
6476 | ||
6477 | static struct abbrev_info * | |
e7c27a73 | 6478 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
6479 | { |
6480 | unsigned int hash_number; | |
6481 | struct abbrev_info *abbrev; | |
6482 | ||
6483 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 6484 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
6485 | |
6486 | while (abbrev) | |
6487 | { | |
6488 | if (abbrev->number == number) | |
6489 | return abbrev; | |
6490 | else | |
6491 | abbrev = abbrev->next; | |
6492 | } | |
6493 | return NULL; | |
6494 | } | |
6495 | ||
72bf9492 DJ |
6496 | /* Returns nonzero if TAG represents a type that we might generate a partial |
6497 | symbol for. */ | |
6498 | ||
6499 | static int | |
6500 | is_type_tag_for_partial (int tag) | |
6501 | { | |
6502 | switch (tag) | |
6503 | { | |
6504 | #if 0 | |
6505 | /* Some types that would be reasonable to generate partial symbols for, | |
6506 | that we don't at present. */ | |
6507 | case DW_TAG_array_type: | |
6508 | case DW_TAG_file_type: | |
6509 | case DW_TAG_ptr_to_member_type: | |
6510 | case DW_TAG_set_type: | |
6511 | case DW_TAG_string_type: | |
6512 | case DW_TAG_subroutine_type: | |
6513 | #endif | |
6514 | case DW_TAG_base_type: | |
6515 | case DW_TAG_class_type: | |
680b30c7 | 6516 | case DW_TAG_interface_type: |
72bf9492 DJ |
6517 | case DW_TAG_enumeration_type: |
6518 | case DW_TAG_structure_type: | |
6519 | case DW_TAG_subrange_type: | |
6520 | case DW_TAG_typedef: | |
6521 | case DW_TAG_union_type: | |
6522 | return 1; | |
6523 | default: | |
6524 | return 0; | |
6525 | } | |
6526 | } | |
6527 | ||
6528 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
6529 | ||
6530 | static struct partial_die_info * | |
93311388 DE |
6531 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
6532 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
6533 | { |
6534 | struct partial_die_info *part_die; | |
6535 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
6536 | struct abbrev_info *abbrev; | |
6537 | unsigned int bytes_read; | |
5afb4e99 | 6538 | unsigned int load_all = 0; |
72bf9492 DJ |
6539 | |
6540 | int nesting_level = 1; | |
6541 | ||
6542 | parent_die = NULL; | |
6543 | last_die = NULL; | |
6544 | ||
5afb4e99 DJ |
6545 | if (cu->per_cu && cu->per_cu->load_all_dies) |
6546 | load_all = 1; | |
6547 | ||
72bf9492 DJ |
6548 | cu->partial_dies |
6549 | = htab_create_alloc_ex (cu->header.length / 12, | |
6550 | partial_die_hash, | |
6551 | partial_die_eq, | |
6552 | NULL, | |
6553 | &cu->comp_unit_obstack, | |
6554 | hashtab_obstack_allocate, | |
6555 | dummy_obstack_deallocate); | |
6556 | ||
6557 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6558 | sizeof (struct partial_die_info)); | |
6559 | ||
6560 | while (1) | |
6561 | { | |
6562 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
6563 | ||
6564 | /* A NULL abbrev means the end of a series of children. */ | |
6565 | if (abbrev == NULL) | |
6566 | { | |
6567 | if (--nesting_level == 0) | |
6568 | { | |
6569 | /* PART_DIE was probably the last thing allocated on the | |
6570 | comp_unit_obstack, so we could call obstack_free | |
6571 | here. We don't do that because the waste is small, | |
6572 | and will be cleaned up when we're done with this | |
6573 | compilation unit. This way, we're also more robust | |
6574 | against other users of the comp_unit_obstack. */ | |
6575 | return first_die; | |
6576 | } | |
6577 | info_ptr += bytes_read; | |
6578 | last_die = parent_die; | |
6579 | parent_die = parent_die->die_parent; | |
6580 | continue; | |
6581 | } | |
6582 | ||
5afb4e99 DJ |
6583 | /* Check whether this DIE is interesting enough to save. Normally |
6584 | we would not be interested in members here, but there may be | |
6585 | later variables referencing them via DW_AT_specification (for | |
6586 | static members). */ | |
6587 | if (!load_all | |
6588 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
6589 | && abbrev->tag != DW_TAG_enumerator |
6590 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 6591 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 6592 | && abbrev->tag != DW_TAG_variable |
5afb4e99 DJ |
6593 | && abbrev->tag != DW_TAG_namespace |
6594 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
6595 | { |
6596 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6597 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
6598 | continue; |
6599 | } | |
6600 | ||
93311388 DE |
6601 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
6602 | buffer, info_ptr, cu); | |
72bf9492 DJ |
6603 | |
6604 | /* This two-pass algorithm for processing partial symbols has a | |
6605 | high cost in cache pressure. Thus, handle some simple cases | |
6606 | here which cover the majority of C partial symbols. DIEs | |
6607 | which neither have specification tags in them, nor could have | |
6608 | specification tags elsewhere pointing at them, can simply be | |
6609 | processed and discarded. | |
6610 | ||
6611 | This segment is also optional; scan_partial_symbols and | |
6612 | add_partial_symbol will handle these DIEs if we chain | |
6613 | them in normally. When compilers which do not emit large | |
6614 | quantities of duplicate debug information are more common, | |
6615 | this code can probably be removed. */ | |
6616 | ||
6617 | /* Any complete simple types at the top level (pretty much all | |
6618 | of them, for a language without namespaces), can be processed | |
6619 | directly. */ | |
6620 | if (parent_die == NULL | |
6621 | && part_die->has_specification == 0 | |
6622 | && part_die->is_declaration == 0 | |
6623 | && (part_die->tag == DW_TAG_typedef | |
6624 | || part_die->tag == DW_TAG_base_type | |
6625 | || part_die->tag == DW_TAG_subrange_type)) | |
6626 | { | |
6627 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 6628 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
6629 | VAR_DOMAIN, LOC_TYPEDEF, |
6630 | &cu->objfile->static_psymbols, | |
6631 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 6632 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6633 | continue; |
6634 | } | |
6635 | ||
6636 | /* If we're at the second level, and we're an enumerator, and | |
6637 | our parent has no specification (meaning possibly lives in a | |
6638 | namespace elsewhere), then we can add the partial symbol now | |
6639 | instead of queueing it. */ | |
6640 | if (part_die->tag == DW_TAG_enumerator | |
6641 | && parent_die != NULL | |
6642 | && parent_die->die_parent == NULL | |
6643 | && parent_die->tag == DW_TAG_enumeration_type | |
6644 | && parent_die->has_specification == 0) | |
6645 | { | |
6646 | if (part_die->name == NULL) | |
e2e0b3e5 | 6647 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 6648 | else if (building_psymtab) |
04a679b8 | 6649 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 6650 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
6651 | (cu->language == language_cplus |
6652 | || cu->language == language_java) | |
72bf9492 DJ |
6653 | ? &cu->objfile->global_psymbols |
6654 | : &cu->objfile->static_psymbols, | |
6655 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
6656 | ||
93311388 | 6657 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6658 | continue; |
6659 | } | |
6660 | ||
6661 | /* We'll save this DIE so link it in. */ | |
6662 | part_die->die_parent = parent_die; | |
6663 | part_die->die_sibling = NULL; | |
6664 | part_die->die_child = NULL; | |
6665 | ||
6666 | if (last_die && last_die == parent_die) | |
6667 | last_die->die_child = part_die; | |
6668 | else if (last_die) | |
6669 | last_die->die_sibling = part_die; | |
6670 | ||
6671 | last_die = part_die; | |
6672 | ||
6673 | if (first_die == NULL) | |
6674 | first_die = part_die; | |
6675 | ||
6676 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
6677 | find interesting need to be in the hash table, because we | |
6678 | also have the parent/sibling/child chains; only those that we | |
6679 | might refer to by offset later during partial symbol reading. | |
6680 | ||
6681 | For now this means things that might have be the target of a | |
6682 | DW_AT_specification, DW_AT_abstract_origin, or | |
6683 | DW_AT_extension. DW_AT_extension will refer only to | |
6684 | namespaces; DW_AT_abstract_origin refers to functions (and | |
6685 | many things under the function DIE, but we do not recurse | |
6686 | into function DIEs during partial symbol reading) and | |
6687 | possibly variables as well; DW_AT_specification refers to | |
6688 | declarations. Declarations ought to have the DW_AT_declaration | |
6689 | flag. It happens that GCC forgets to put it in sometimes, but | |
6690 | only for functions, not for types. | |
6691 | ||
6692 | Adding more things than necessary to the hash table is harmless | |
6693 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
6694 | wasted time in find_partial_die, when we reread the compilation |
6695 | unit with load_all_dies set. */ | |
72bf9492 | 6696 | |
5afb4e99 DJ |
6697 | if (load_all |
6698 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
6699 | || abbrev->tag == DW_TAG_variable |
6700 | || abbrev->tag == DW_TAG_namespace | |
6701 | || part_die->is_declaration) | |
6702 | { | |
6703 | void **slot; | |
6704 | ||
6705 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
6706 | part_die->offset, INSERT); | |
6707 | *slot = part_die; | |
6708 | } | |
6709 | ||
6710 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6711 | sizeof (struct partial_die_info)); | |
6712 | ||
6713 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 6714 | we have no reason to follow the children of structures; for other |
72bf9492 | 6715 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
6716 | to infer fully qualified class names, and for DW_AT_specification. |
6717 | ||
6718 | For Ada, we need to scan the children of subprograms and lexical | |
6719 | blocks as well because Ada allows the definition of nested | |
6720 | entities that could be interesting for the debugger, such as | |
6721 | nested subprograms for instance. */ | |
72bf9492 | 6722 | if (last_die->has_children |
5afb4e99 DJ |
6723 | && (load_all |
6724 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
6725 | || last_die->tag == DW_TAG_enumeration_type |
6726 | || (cu->language != language_c | |
6727 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 6728 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 6729 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
6730 | || last_die->tag == DW_TAG_union_type)) |
6731 | || (cu->language == language_ada | |
6732 | && (last_die->tag == DW_TAG_subprogram | |
6733 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
6734 | { |
6735 | nesting_level++; | |
6736 | parent_die = last_die; | |
6737 | continue; | |
6738 | } | |
6739 | ||
6740 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6741 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6742 | |
6743 | /* Back to the top, do it again. */ | |
6744 | } | |
6745 | } | |
6746 | ||
c906108c SS |
6747 | /* Read a minimal amount of information into the minimal die structure. */ |
6748 | ||
fe1b8b76 | 6749 | static gdb_byte * |
72bf9492 DJ |
6750 | read_partial_die (struct partial_die_info *part_die, |
6751 | struct abbrev_info *abbrev, | |
6752 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
6753 | gdb_byte *buffer, gdb_byte *info_ptr, |
6754 | struct dwarf2_cu *cu) | |
c906108c | 6755 | { |
72bf9492 | 6756 | unsigned int bytes_read, i; |
c906108c | 6757 | struct attribute attr; |
c5aa993b | 6758 | int has_low_pc_attr = 0; |
c906108c SS |
6759 | int has_high_pc_attr = 0; |
6760 | ||
72bf9492 | 6761 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 6762 | |
93311388 | 6763 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
6764 | |
6765 | info_ptr += abbrev_len; | |
6766 | ||
6767 | if (abbrev == NULL) | |
6768 | return info_ptr; | |
6769 | ||
c906108c SS |
6770 | part_die->tag = abbrev->tag; |
6771 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
6772 | |
6773 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6774 | { | |
e7c27a73 | 6775 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
6776 | |
6777 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 6778 | partial symbol table. */ |
c906108c SS |
6779 | switch (attr.name) |
6780 | { | |
6781 | case DW_AT_name: | |
71c25dea TT |
6782 | switch (part_die->tag) |
6783 | { | |
6784 | case DW_TAG_compile_unit: | |
348e048f | 6785 | case DW_TAG_type_unit: |
71c25dea TT |
6786 | /* Compilation units have a DW_AT_name that is a filename, not |
6787 | a source language identifier. */ | |
6788 | case DW_TAG_enumeration_type: | |
6789 | case DW_TAG_enumerator: | |
6790 | /* These tags always have simple identifiers already; no need | |
6791 | to canonicalize them. */ | |
6792 | part_die->name = DW_STRING (&attr); | |
6793 | break; | |
6794 | default: | |
6795 | part_die->name | |
6796 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 6797 | &cu->objfile->objfile_obstack); |
71c25dea TT |
6798 | break; |
6799 | } | |
c906108c SS |
6800 | break; |
6801 | case DW_AT_MIPS_linkage_name: | |
94af9270 KS |
6802 | if (cu->language == language_ada) |
6803 | part_die->name = DW_STRING (&attr); | |
c906108c SS |
6804 | break; |
6805 | case DW_AT_low_pc: | |
6806 | has_low_pc_attr = 1; | |
6807 | part_die->lowpc = DW_ADDR (&attr); | |
6808 | break; | |
6809 | case DW_AT_high_pc: | |
6810 | has_high_pc_attr = 1; | |
6811 | part_die->highpc = DW_ADDR (&attr); | |
6812 | break; | |
6813 | case DW_AT_location: | |
8e19ed76 PS |
6814 | /* Support the .debug_loc offsets */ |
6815 | if (attr_form_is_block (&attr)) | |
6816 | { | |
6817 | part_die->locdesc = DW_BLOCK (&attr); | |
6818 | } | |
3690dd37 | 6819 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 6820 | { |
4d3c2250 | 6821 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6822 | } |
6823 | else | |
6824 | { | |
4d3c2250 KB |
6825 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6826 | "partial symbol information"); | |
8e19ed76 | 6827 | } |
c906108c | 6828 | break; |
c906108c SS |
6829 | case DW_AT_external: |
6830 | part_die->is_external = DW_UNSND (&attr); | |
6831 | break; | |
6832 | case DW_AT_declaration: | |
6833 | part_die->is_declaration = DW_UNSND (&attr); | |
6834 | break; | |
6835 | case DW_AT_type: | |
6836 | part_die->has_type = 1; | |
6837 | break; | |
6838 | case DW_AT_abstract_origin: | |
6839 | case DW_AT_specification: | |
72bf9492 DJ |
6840 | case DW_AT_extension: |
6841 | part_die->has_specification = 1; | |
c764a876 | 6842 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
6843 | break; |
6844 | case DW_AT_sibling: | |
6845 | /* Ignore absolute siblings, they might point outside of | |
6846 | the current compile unit. */ | |
6847 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 6848 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 6849 | else |
93311388 | 6850 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 6851 | break; |
fa4028e9 JB |
6852 | case DW_AT_byte_size: |
6853 | part_die->has_byte_size = 1; | |
6854 | break; | |
68511cec CES |
6855 | case DW_AT_calling_convention: |
6856 | /* DWARF doesn't provide a way to identify a program's source-level | |
6857 | entry point. DW_AT_calling_convention attributes are only meant | |
6858 | to describe functions' calling conventions. | |
6859 | ||
6860 | However, because it's a necessary piece of information in | |
6861 | Fortran, and because DW_CC_program is the only piece of debugging | |
6862 | information whose definition refers to a 'main program' at all, | |
6863 | several compilers have begun marking Fortran main programs with | |
6864 | DW_CC_program --- even when those functions use the standard | |
6865 | calling conventions. | |
6866 | ||
6867 | So until DWARF specifies a way to provide this information and | |
6868 | compilers pick up the new representation, we'll support this | |
6869 | practice. */ | |
6870 | if (DW_UNSND (&attr) == DW_CC_program | |
6871 | && cu->language == language_fortran) | |
6872 | set_main_name (part_die->name); | |
6873 | break; | |
c906108c SS |
6874 | default: |
6875 | break; | |
6876 | } | |
6877 | } | |
6878 | ||
c906108c SS |
6879 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
6880 | eliminate duplicate copies of functions and vtables and such. | |
6881 | The linker will arbitrarily choose one and discard the others. | |
6882 | The AT_*_pc values for such functions refer to local labels in | |
6883 | these sections. If the section from that file was discarded, the | |
6884 | labels are not in the output, so the relocs get a value of 0. | |
6885 | If this is a discarded function, mark the pc bounds as invalid, | |
6886 | so that GDB will ignore it. */ | |
6887 | if (has_low_pc_attr && has_high_pc_attr | |
6888 | && part_die->lowpc < part_die->highpc | |
6889 | && (part_die->lowpc != 0 | |
72dca2f5 | 6890 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 6891 | part_die->has_pc_info = 1; |
85cbf3d3 | 6892 | |
c906108c SS |
6893 | return info_ptr; |
6894 | } | |
6895 | ||
72bf9492 DJ |
6896 | /* Find a cached partial DIE at OFFSET in CU. */ |
6897 | ||
6898 | static struct partial_die_info * | |
c764a876 | 6899 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
6900 | { |
6901 | struct partial_die_info *lookup_die = NULL; | |
6902 | struct partial_die_info part_die; | |
6903 | ||
6904 | part_die.offset = offset; | |
6905 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
6906 | ||
72bf9492 DJ |
6907 | return lookup_die; |
6908 | } | |
6909 | ||
348e048f DE |
6910 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
6911 | except in the case of .debug_types DIEs which do not reference | |
6912 | outside their CU (they do however referencing other types via | |
6913 | DW_FORM_sig8). */ | |
72bf9492 DJ |
6914 | |
6915 | static struct partial_die_info * | |
c764a876 | 6916 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 6917 | { |
5afb4e99 DJ |
6918 | struct dwarf2_per_cu_data *per_cu = NULL; |
6919 | struct partial_die_info *pd = NULL; | |
72bf9492 | 6920 | |
348e048f DE |
6921 | if (cu->per_cu->from_debug_types) |
6922 | { | |
6923 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6924 | if (pd != NULL) | |
6925 | return pd; | |
6926 | goto not_found; | |
6927 | } | |
6928 | ||
45452591 | 6929 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
6930 | { |
6931 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6932 | if (pd != NULL) | |
6933 | return pd; | |
6934 | } | |
72bf9492 | 6935 | |
ae038cb0 DJ |
6936 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
6937 | ||
ae038cb0 DJ |
6938 | if (per_cu->cu == NULL) |
6939 | { | |
93311388 | 6940 | load_partial_comp_unit (per_cu, cu->objfile); |
ae038cb0 DJ |
6941 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
6942 | dwarf2_per_objfile->read_in_chain = per_cu; | |
6943 | } | |
6944 | ||
6945 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
6946 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
6947 | ||
6948 | if (pd == NULL && per_cu->load_all_dies == 0) | |
6949 | { | |
6950 | struct cleanup *back_to; | |
6951 | struct partial_die_info comp_unit_die; | |
6952 | struct abbrev_info *abbrev; | |
6953 | unsigned int bytes_read; | |
6954 | char *info_ptr; | |
6955 | ||
6956 | per_cu->load_all_dies = 1; | |
6957 | ||
6958 | /* Re-read the DIEs. */ | |
6959 | back_to = make_cleanup (null_cleanup, 0); | |
6960 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
6961 | { | |
6962 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 6963 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 6964 | } |
dce234bc | 6965 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
6966 | + per_cu->cu->header.offset |
6967 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
6968 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
6969 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
6970 | per_cu->cu->objfile->obfd, |
6971 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
6972 | per_cu->cu); |
6973 | if (comp_unit_die.has_children) | |
93311388 DE |
6974 | load_partial_dies (per_cu->cu->objfile->obfd, |
6975 | dwarf2_per_objfile->info.buffer, info_ptr, | |
6976 | 0, per_cu->cu); | |
5afb4e99 DJ |
6977 | do_cleanups (back_to); |
6978 | ||
6979 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
6980 | } | |
6981 | ||
348e048f DE |
6982 | not_found: |
6983 | ||
5afb4e99 DJ |
6984 | if (pd == NULL) |
6985 | internal_error (__FILE__, __LINE__, | |
c764a876 | 6986 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
6987 | offset, bfd_get_filename (cu->objfile->obfd)); |
6988 | return pd; | |
72bf9492 DJ |
6989 | } |
6990 | ||
6991 | /* Adjust PART_DIE before generating a symbol for it. This function | |
6992 | may set the is_external flag or change the DIE's name. */ | |
6993 | ||
6994 | static void | |
6995 | fixup_partial_die (struct partial_die_info *part_die, | |
6996 | struct dwarf2_cu *cu) | |
6997 | { | |
6998 | /* If we found a reference attribute and the DIE has no name, try | |
6999 | to find a name in the referred to DIE. */ | |
7000 | ||
7001 | if (part_die->name == NULL && part_die->has_specification) | |
7002 | { | |
7003 | struct partial_die_info *spec_die; | |
72bf9492 | 7004 | |
10b3939b | 7005 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 7006 | |
10b3939b | 7007 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
7008 | |
7009 | if (spec_die->name) | |
7010 | { | |
7011 | part_die->name = spec_die->name; | |
7012 | ||
7013 | /* Copy DW_AT_external attribute if it is set. */ | |
7014 | if (spec_die->is_external) | |
7015 | part_die->is_external = spec_die->is_external; | |
7016 | } | |
7017 | } | |
7018 | ||
7019 | /* Set default names for some unnamed DIEs. */ | |
7020 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
7021 | || part_die->tag == DW_TAG_class_type)) | |
7022 | part_die->name = "(anonymous class)"; | |
7023 | ||
7024 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
7025 | part_die->name = "(anonymous namespace)"; | |
7026 | ||
7027 | if (part_die->tag == DW_TAG_structure_type | |
7028 | || part_die->tag == DW_TAG_class_type | |
7029 | || part_die->tag == DW_TAG_union_type) | |
7030 | guess_structure_name (part_die, cu); | |
7031 | } | |
7032 | ||
a8329558 | 7033 | /* Read an attribute value described by an attribute form. */ |
c906108c | 7034 | |
fe1b8b76 | 7035 | static gdb_byte * |
a8329558 | 7036 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 7037 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 7038 | struct dwarf2_cu *cu) |
c906108c | 7039 | { |
e7c27a73 | 7040 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7041 | unsigned int bytes_read; |
7042 | struct dwarf_block *blk; | |
7043 | ||
a8329558 KW |
7044 | attr->form = form; |
7045 | switch (form) | |
c906108c | 7046 | { |
c906108c | 7047 | case DW_FORM_ref_addr: |
ae411497 TT |
7048 | if (cu->header.version == 2) |
7049 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
7050 | else | |
7051 | DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
7052 | info_ptr += bytes_read; | |
7053 | break; | |
7054 | case DW_FORM_addr: | |
e7c27a73 | 7055 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 7056 | info_ptr += bytes_read; |
c906108c SS |
7057 | break; |
7058 | case DW_FORM_block2: | |
7b5a2f43 | 7059 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7060 | blk->size = read_2_bytes (abfd, info_ptr); |
7061 | info_ptr += 2; | |
7062 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7063 | info_ptr += blk->size; | |
7064 | DW_BLOCK (attr) = blk; | |
7065 | break; | |
7066 | case DW_FORM_block4: | |
7b5a2f43 | 7067 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7068 | blk->size = read_4_bytes (abfd, info_ptr); |
7069 | info_ptr += 4; | |
7070 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7071 | info_ptr += blk->size; | |
7072 | DW_BLOCK (attr) = blk; | |
7073 | break; | |
7074 | case DW_FORM_data2: | |
7075 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
7076 | info_ptr += 2; | |
7077 | break; | |
7078 | case DW_FORM_data4: | |
7079 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
7080 | info_ptr += 4; | |
7081 | break; | |
7082 | case DW_FORM_data8: | |
7083 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
7084 | info_ptr += 8; | |
7085 | break; | |
7086 | case DW_FORM_string: | |
7087 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
8285870a | 7088 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
7089 | info_ptr += bytes_read; |
7090 | break; | |
4bdf3d34 JJ |
7091 | case DW_FORM_strp: |
7092 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
7093 | &bytes_read); | |
8285870a | 7094 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
7095 | info_ptr += bytes_read; |
7096 | break; | |
c906108c | 7097 | case DW_FORM_block: |
7b5a2f43 | 7098 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7099 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7100 | info_ptr += bytes_read; | |
7101 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7102 | info_ptr += blk->size; | |
7103 | DW_BLOCK (attr) = blk; | |
7104 | break; | |
7105 | case DW_FORM_block1: | |
7b5a2f43 | 7106 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7107 | blk->size = read_1_byte (abfd, info_ptr); |
7108 | info_ptr += 1; | |
7109 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7110 | info_ptr += blk->size; | |
7111 | DW_BLOCK (attr) = blk; | |
7112 | break; | |
7113 | case DW_FORM_data1: | |
7114 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7115 | info_ptr += 1; | |
7116 | break; | |
7117 | case DW_FORM_flag: | |
7118 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7119 | info_ptr += 1; | |
7120 | break; | |
7121 | case DW_FORM_sdata: | |
7122 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
7123 | info_ptr += bytes_read; | |
7124 | break; | |
7125 | case DW_FORM_udata: | |
7126 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7127 | info_ptr += bytes_read; | |
7128 | break; | |
7129 | case DW_FORM_ref1: | |
10b3939b | 7130 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
7131 | info_ptr += 1; |
7132 | break; | |
7133 | case DW_FORM_ref2: | |
10b3939b | 7134 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
7135 | info_ptr += 2; |
7136 | break; | |
7137 | case DW_FORM_ref4: | |
10b3939b | 7138 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
7139 | info_ptr += 4; |
7140 | break; | |
613e1657 | 7141 | case DW_FORM_ref8: |
10b3939b | 7142 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
7143 | info_ptr += 8; |
7144 | break; | |
348e048f DE |
7145 | case DW_FORM_sig8: |
7146 | /* Convert the signature to something we can record in DW_UNSND | |
7147 | for later lookup. | |
7148 | NOTE: This is NULL if the type wasn't found. */ | |
7149 | DW_SIGNATURED_TYPE (attr) = | |
7150 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
7151 | info_ptr += 8; | |
7152 | break; | |
c906108c | 7153 | case DW_FORM_ref_udata: |
10b3939b DJ |
7154 | DW_ADDR (attr) = (cu->header.offset |
7155 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
7156 | info_ptr += bytes_read; |
7157 | break; | |
c906108c | 7158 | case DW_FORM_indirect: |
a8329558 KW |
7159 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7160 | info_ptr += bytes_read; | |
e7c27a73 | 7161 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 7162 | break; |
c906108c | 7163 | default: |
8a3fe4f8 | 7164 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
7165 | dwarf_form_name (form), |
7166 | bfd_get_filename (abfd)); | |
c906108c | 7167 | } |
28e94949 JB |
7168 | |
7169 | /* We have seen instances where the compiler tried to emit a byte | |
7170 | size attribute of -1 which ended up being encoded as an unsigned | |
7171 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
7172 | an object of this size seems pretty unlikely so we can relatively | |
7173 | safely treat these cases as if the size attribute was invalid and | |
7174 | treat them as zero by default. */ | |
7175 | if (attr->name == DW_AT_byte_size | |
7176 | && form == DW_FORM_data4 | |
7177 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
7178 | { |
7179 | complaint | |
7180 | (&symfile_complaints, | |
43bbcdc2 PH |
7181 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
7182 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
7183 | DW_UNSND (attr) = 0; |
7184 | } | |
28e94949 | 7185 | |
c906108c SS |
7186 | return info_ptr; |
7187 | } | |
7188 | ||
a8329558 KW |
7189 | /* Read an attribute described by an abbreviated attribute. */ |
7190 | ||
fe1b8b76 | 7191 | static gdb_byte * |
a8329558 | 7192 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 7193 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
7194 | { |
7195 | attr->name = abbrev->name; | |
e7c27a73 | 7196 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
7197 | } |
7198 | ||
c906108c SS |
7199 | /* read dwarf information from a buffer */ |
7200 | ||
7201 | static unsigned int | |
fe1b8b76 | 7202 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7203 | { |
fe1b8b76 | 7204 | return bfd_get_8 (abfd, buf); |
c906108c SS |
7205 | } |
7206 | ||
7207 | static int | |
fe1b8b76 | 7208 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7209 | { |
fe1b8b76 | 7210 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
7211 | } |
7212 | ||
7213 | static unsigned int | |
fe1b8b76 | 7214 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7215 | { |
fe1b8b76 | 7216 | return bfd_get_16 (abfd, buf); |
c906108c SS |
7217 | } |
7218 | ||
7219 | static int | |
fe1b8b76 | 7220 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7221 | { |
fe1b8b76 | 7222 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
7223 | } |
7224 | ||
7225 | static unsigned int | |
fe1b8b76 | 7226 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7227 | { |
fe1b8b76 | 7228 | return bfd_get_32 (abfd, buf); |
c906108c SS |
7229 | } |
7230 | ||
7231 | static int | |
fe1b8b76 | 7232 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7233 | { |
fe1b8b76 | 7234 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
7235 | } |
7236 | ||
93311388 | 7237 | static ULONGEST |
fe1b8b76 | 7238 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7239 | { |
fe1b8b76 | 7240 | return bfd_get_64 (abfd, buf); |
c906108c SS |
7241 | } |
7242 | ||
7243 | static CORE_ADDR | |
fe1b8b76 | 7244 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 7245 | unsigned int *bytes_read) |
c906108c | 7246 | { |
e7c27a73 | 7247 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7248 | CORE_ADDR retval = 0; |
7249 | ||
107d2387 | 7250 | if (cu_header->signed_addr_p) |
c906108c | 7251 | { |
107d2387 AC |
7252 | switch (cu_header->addr_size) |
7253 | { | |
7254 | case 2: | |
fe1b8b76 | 7255 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
7256 | break; |
7257 | case 4: | |
fe1b8b76 | 7258 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
7259 | break; |
7260 | case 8: | |
fe1b8b76 | 7261 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
7262 | break; |
7263 | default: | |
8e65ff28 | 7264 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7265 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 7266 | bfd_get_filename (abfd)); |
107d2387 AC |
7267 | } |
7268 | } | |
7269 | else | |
7270 | { | |
7271 | switch (cu_header->addr_size) | |
7272 | { | |
7273 | case 2: | |
fe1b8b76 | 7274 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
7275 | break; |
7276 | case 4: | |
fe1b8b76 | 7277 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
7278 | break; |
7279 | case 8: | |
fe1b8b76 | 7280 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
7281 | break; |
7282 | default: | |
8e65ff28 | 7283 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7284 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 7285 | bfd_get_filename (abfd)); |
107d2387 | 7286 | } |
c906108c | 7287 | } |
64367e0a | 7288 | |
107d2387 AC |
7289 | *bytes_read = cu_header->addr_size; |
7290 | return retval; | |
c906108c SS |
7291 | } |
7292 | ||
f7ef9339 | 7293 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
7294 | specification allows the initial length to take up either 4 bytes |
7295 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
7296 | bytes describe the length and all offsets will be 8 bytes in length | |
7297 | instead of 4. | |
7298 | ||
f7ef9339 KB |
7299 | An older, non-standard 64-bit format is also handled by this |
7300 | function. The older format in question stores the initial length | |
7301 | as an 8-byte quantity without an escape value. Lengths greater | |
7302 | than 2^32 aren't very common which means that the initial 4 bytes | |
7303 | is almost always zero. Since a length value of zero doesn't make | |
7304 | sense for the 32-bit format, this initial zero can be considered to | |
7305 | be an escape value which indicates the presence of the older 64-bit | |
7306 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
7307 | greater than 4GB. If it becomes necessary to handle lengths |
7308 | somewhat larger than 4GB, we could allow other small values (such | |
7309 | as the non-sensical values of 1, 2, and 3) to also be used as | |
7310 | escape values indicating the presence of the old format. | |
f7ef9339 | 7311 | |
917c78fc MK |
7312 | The value returned via bytes_read should be used to increment the |
7313 | relevant pointer after calling read_initial_length(). | |
c764a876 | 7314 | |
613e1657 KB |
7315 | [ Note: read_initial_length() and read_offset() are based on the |
7316 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 7317 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
7318 | from: |
7319 | ||
f7ef9339 | 7320 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
7321 | |
7322 | This document is only a draft and is subject to change. (So beware.) | |
7323 | ||
f7ef9339 | 7324 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
7325 | determined empirically by examining 64-bit ELF files produced by |
7326 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
7327 | |
7328 | - Kevin, July 16, 2002 | |
613e1657 KB |
7329 | ] */ |
7330 | ||
7331 | static LONGEST | |
c764a876 | 7332 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 7333 | { |
fe1b8b76 | 7334 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 7335 | |
dd373385 | 7336 | if (length == 0xffffffff) |
613e1657 | 7337 | { |
fe1b8b76 | 7338 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 7339 | *bytes_read = 12; |
613e1657 | 7340 | } |
dd373385 | 7341 | else if (length == 0) |
f7ef9339 | 7342 | { |
dd373385 | 7343 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 7344 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 7345 | *bytes_read = 8; |
f7ef9339 | 7346 | } |
613e1657 KB |
7347 | else |
7348 | { | |
7349 | *bytes_read = 4; | |
613e1657 KB |
7350 | } |
7351 | ||
c764a876 DE |
7352 | return length; |
7353 | } | |
dd373385 | 7354 | |
c764a876 DE |
7355 | /* Cover function for read_initial_length. |
7356 | Returns the length of the object at BUF, and stores the size of the | |
7357 | initial length in *BYTES_READ and stores the size that offsets will be in | |
7358 | *OFFSET_SIZE. | |
7359 | If the initial length size is not equivalent to that specified in | |
7360 | CU_HEADER then issue a complaint. | |
7361 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 7362 | |
c764a876 DE |
7363 | static LONGEST |
7364 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
7365 | const struct comp_unit_head *cu_header, | |
7366 | unsigned int *bytes_read, | |
7367 | unsigned int *offset_size) | |
7368 | { | |
7369 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
7370 | ||
7371 | gdb_assert (cu_header->initial_length_size == 4 | |
7372 | || cu_header->initial_length_size == 8 | |
7373 | || cu_header->initial_length_size == 12); | |
7374 | ||
7375 | if (cu_header->initial_length_size != *bytes_read) | |
7376 | complaint (&symfile_complaints, | |
7377 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 7378 | |
c764a876 | 7379 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 7380 | return length; |
613e1657 KB |
7381 | } |
7382 | ||
7383 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 7384 | given by cu_header->offset_size. */ |
613e1657 KB |
7385 | |
7386 | static LONGEST | |
fe1b8b76 | 7387 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 7388 | unsigned int *bytes_read) |
c764a876 DE |
7389 | { |
7390 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
7391 | *bytes_read = cu_header->offset_size; | |
7392 | return offset; | |
7393 | } | |
7394 | ||
7395 | /* Read an offset from the data stream. */ | |
7396 | ||
7397 | static LONGEST | |
7398 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
7399 | { |
7400 | LONGEST retval = 0; | |
7401 | ||
c764a876 | 7402 | switch (offset_size) |
613e1657 KB |
7403 | { |
7404 | case 4: | |
fe1b8b76 | 7405 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
7406 | break; |
7407 | case 8: | |
fe1b8b76 | 7408 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
7409 | break; |
7410 | default: | |
8e65ff28 | 7411 | internal_error (__FILE__, __LINE__, |
c764a876 | 7412 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 7413 | bfd_get_filename (abfd)); |
613e1657 KB |
7414 | } |
7415 | ||
917c78fc | 7416 | return retval; |
613e1657 KB |
7417 | } |
7418 | ||
fe1b8b76 JB |
7419 | static gdb_byte * |
7420 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
7421 | { |
7422 | /* If the size of a host char is 8 bits, we can return a pointer | |
7423 | to the buffer, otherwise we have to copy the data to a buffer | |
7424 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7425 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 7426 | return buf; |
c906108c SS |
7427 | } |
7428 | ||
7429 | static char * | |
fe1b8b76 | 7430 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
7431 | { |
7432 | /* If the size of a host char is 8 bits, we can return a pointer | |
7433 | to the string, otherwise we have to copy the string to a buffer | |
7434 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7435 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
7436 | if (*buf == '\0') |
7437 | { | |
7438 | *bytes_read_ptr = 1; | |
7439 | return NULL; | |
7440 | } | |
fe1b8b76 JB |
7441 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
7442 | return (char *) buf; | |
4bdf3d34 JJ |
7443 | } |
7444 | ||
7445 | static char * | |
fe1b8b76 | 7446 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
7447 | const struct comp_unit_head *cu_header, |
7448 | unsigned int *bytes_read_ptr) | |
7449 | { | |
c764a876 | 7450 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 7451 | |
dce234bc | 7452 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 7453 | { |
8a3fe4f8 | 7454 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 7455 | bfd_get_filename (abfd)); |
4bdf3d34 | 7456 | return NULL; |
c906108c | 7457 | } |
dce234bc | 7458 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 7459 | { |
8a3fe4f8 | 7460 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 7461 | bfd_get_filename (abfd)); |
c906108c SS |
7462 | return NULL; |
7463 | } | |
4bdf3d34 | 7464 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 7465 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 7466 | return NULL; |
dce234bc | 7467 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
7468 | } |
7469 | ||
ce5d95e1 | 7470 | static unsigned long |
fe1b8b76 | 7471 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7472 | { |
ce5d95e1 JB |
7473 | unsigned long result; |
7474 | unsigned int num_read; | |
c906108c SS |
7475 | int i, shift; |
7476 | unsigned char byte; | |
7477 | ||
7478 | result = 0; | |
7479 | shift = 0; | |
7480 | num_read = 0; | |
7481 | i = 0; | |
7482 | while (1) | |
7483 | { | |
fe1b8b76 | 7484 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7485 | buf++; |
7486 | num_read++; | |
ce5d95e1 | 7487 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
7488 | if ((byte & 128) == 0) |
7489 | { | |
7490 | break; | |
7491 | } | |
7492 | shift += 7; | |
7493 | } | |
7494 | *bytes_read_ptr = num_read; | |
7495 | return result; | |
7496 | } | |
7497 | ||
ce5d95e1 | 7498 | static long |
fe1b8b76 | 7499 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7500 | { |
ce5d95e1 | 7501 | long result; |
77e0b926 | 7502 | int i, shift, num_read; |
c906108c SS |
7503 | unsigned char byte; |
7504 | ||
7505 | result = 0; | |
7506 | shift = 0; | |
c906108c SS |
7507 | num_read = 0; |
7508 | i = 0; | |
7509 | while (1) | |
7510 | { | |
fe1b8b76 | 7511 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7512 | buf++; |
7513 | num_read++; | |
ce5d95e1 | 7514 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
7515 | shift += 7; |
7516 | if ((byte & 128) == 0) | |
7517 | { | |
7518 | break; | |
7519 | } | |
7520 | } | |
77e0b926 DJ |
7521 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
7522 | result |= -(((long)1) << shift); | |
c906108c SS |
7523 | *bytes_read_ptr = num_read; |
7524 | return result; | |
7525 | } | |
7526 | ||
4bb7a0a7 DJ |
7527 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
7528 | ||
fe1b8b76 JB |
7529 | static gdb_byte * |
7530 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
7531 | { |
7532 | int byte; | |
7533 | ||
7534 | while (1) | |
7535 | { | |
fe1b8b76 | 7536 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
7537 | buf++; |
7538 | if ((byte & 128) == 0) | |
7539 | return buf; | |
7540 | } | |
7541 | } | |
7542 | ||
c906108c | 7543 | static void |
e142c38c | 7544 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
7545 | { |
7546 | switch (lang) | |
7547 | { | |
7548 | case DW_LANG_C89: | |
76bee0cc | 7549 | case DW_LANG_C99: |
c906108c | 7550 | case DW_LANG_C: |
e142c38c | 7551 | cu->language = language_c; |
c906108c SS |
7552 | break; |
7553 | case DW_LANG_C_plus_plus: | |
e142c38c | 7554 | cu->language = language_cplus; |
c906108c SS |
7555 | break; |
7556 | case DW_LANG_Fortran77: | |
7557 | case DW_LANG_Fortran90: | |
b21b22e0 | 7558 | case DW_LANG_Fortran95: |
e142c38c | 7559 | cu->language = language_fortran; |
c906108c SS |
7560 | break; |
7561 | case DW_LANG_Mips_Assembler: | |
e142c38c | 7562 | cu->language = language_asm; |
c906108c | 7563 | break; |
bebd888e | 7564 | case DW_LANG_Java: |
e142c38c | 7565 | cu->language = language_java; |
bebd888e | 7566 | break; |
c906108c | 7567 | case DW_LANG_Ada83: |
8aaf0b47 | 7568 | case DW_LANG_Ada95: |
bc5f45f8 JB |
7569 | cu->language = language_ada; |
7570 | break; | |
72019c9c GM |
7571 | case DW_LANG_Modula2: |
7572 | cu->language = language_m2; | |
7573 | break; | |
fe8e67fd PM |
7574 | case DW_LANG_Pascal83: |
7575 | cu->language = language_pascal; | |
7576 | break; | |
22566fbd DJ |
7577 | case DW_LANG_ObjC: |
7578 | cu->language = language_objc; | |
7579 | break; | |
c906108c SS |
7580 | case DW_LANG_Cobol74: |
7581 | case DW_LANG_Cobol85: | |
c906108c | 7582 | default: |
e142c38c | 7583 | cu->language = language_minimal; |
c906108c SS |
7584 | break; |
7585 | } | |
e142c38c | 7586 | cu->language_defn = language_def (cu->language); |
c906108c SS |
7587 | } |
7588 | ||
7589 | /* Return the named attribute or NULL if not there. */ | |
7590 | ||
7591 | static struct attribute * | |
e142c38c | 7592 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
7593 | { |
7594 | unsigned int i; | |
7595 | struct attribute *spec = NULL; | |
7596 | ||
7597 | for (i = 0; i < die->num_attrs; ++i) | |
7598 | { | |
7599 | if (die->attrs[i].name == name) | |
10b3939b | 7600 | return &die->attrs[i]; |
c906108c SS |
7601 | if (die->attrs[i].name == DW_AT_specification |
7602 | || die->attrs[i].name == DW_AT_abstract_origin) | |
7603 | spec = &die->attrs[i]; | |
7604 | } | |
c906108c | 7605 | |
10b3939b | 7606 | if (spec) |
f2f0e013 DJ |
7607 | { |
7608 | die = follow_die_ref (die, spec, &cu); | |
7609 | return dwarf2_attr (die, name, cu); | |
7610 | } | |
c5aa993b | 7611 | |
c906108c SS |
7612 | return NULL; |
7613 | } | |
7614 | ||
348e048f DE |
7615 | /* Return the named attribute or NULL if not there, |
7616 | but do not follow DW_AT_specification, etc. | |
7617 | This is for use in contexts where we're reading .debug_types dies. | |
7618 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
7619 | back up the chain, and we want to go down. */ | |
7620 | ||
7621 | static struct attribute * | |
7622 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
7623 | struct dwarf2_cu *cu) | |
7624 | { | |
7625 | unsigned int i; | |
7626 | ||
7627 | for (i = 0; i < die->num_attrs; ++i) | |
7628 | if (die->attrs[i].name == name) | |
7629 | return &die->attrs[i]; | |
7630 | ||
7631 | return NULL; | |
7632 | } | |
7633 | ||
05cf31d1 JB |
7634 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
7635 | and holds a non-zero value. This function should only be used for | |
7636 | DW_FORM_flag attributes. */ | |
7637 | ||
7638 | static int | |
7639 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
7640 | { | |
7641 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
7642 | ||
7643 | return (attr && DW_UNSND (attr)); | |
7644 | } | |
7645 | ||
3ca72b44 | 7646 | static int |
e142c38c | 7647 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 7648 | { |
05cf31d1 JB |
7649 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
7650 | which value is non-zero. However, we have to be careful with | |
7651 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
7652 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
7653 | end up accidently finding a declaration attribute that belongs | |
7654 | to a different DIE referenced by the specification attribute, | |
7655 | even though the given DIE does not have a declaration attribute. */ | |
7656 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
7657 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
7658 | } |
7659 | ||
63d06c5c | 7660 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 7661 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
7662 | containing the return value on output. If there is no |
7663 | specification, but there is an abstract origin, that is | |
7664 | returned. */ | |
63d06c5c DC |
7665 | |
7666 | static struct die_info * | |
f2f0e013 | 7667 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 7668 | { |
f2f0e013 DJ |
7669 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
7670 | *spec_cu); | |
63d06c5c | 7671 | |
edb3359d DJ |
7672 | if (spec_attr == NULL) |
7673 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
7674 | ||
63d06c5c DC |
7675 | if (spec_attr == NULL) |
7676 | return NULL; | |
7677 | else | |
f2f0e013 | 7678 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 7679 | } |
c906108c | 7680 | |
debd256d JB |
7681 | /* Free the line_header structure *LH, and any arrays and strings it |
7682 | refers to. */ | |
7683 | static void | |
7684 | free_line_header (struct line_header *lh) | |
7685 | { | |
7686 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 7687 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
7688 | |
7689 | /* Remember that all the lh->file_names[i].name pointers are | |
7690 | pointers into debug_line_buffer, and don't need to be freed. */ | |
7691 | if (lh->file_names) | |
a8bc7b56 | 7692 | xfree (lh->file_names); |
debd256d JB |
7693 | |
7694 | /* Similarly for the include directory names. */ | |
7695 | if (lh->include_dirs) | |
a8bc7b56 | 7696 | xfree (lh->include_dirs); |
debd256d | 7697 | |
a8bc7b56 | 7698 | xfree (lh); |
debd256d JB |
7699 | } |
7700 | ||
7701 | ||
7702 | /* Add an entry to LH's include directory table. */ | |
7703 | static void | |
7704 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 7705 | { |
debd256d JB |
7706 | /* Grow the array if necessary. */ |
7707 | if (lh->include_dirs_size == 0) | |
c5aa993b | 7708 | { |
debd256d JB |
7709 | lh->include_dirs_size = 1; /* for testing */ |
7710 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
7711 | * sizeof (*lh->include_dirs)); | |
7712 | } | |
7713 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
7714 | { | |
7715 | lh->include_dirs_size *= 2; | |
7716 | lh->include_dirs = xrealloc (lh->include_dirs, | |
7717 | (lh->include_dirs_size | |
7718 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 7719 | } |
c906108c | 7720 | |
debd256d JB |
7721 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
7722 | } | |
7723 | ||
7724 | ||
7725 | /* Add an entry to LH's file name table. */ | |
7726 | static void | |
7727 | add_file_name (struct line_header *lh, | |
7728 | char *name, | |
7729 | unsigned int dir_index, | |
7730 | unsigned int mod_time, | |
7731 | unsigned int length) | |
7732 | { | |
7733 | struct file_entry *fe; | |
7734 | ||
7735 | /* Grow the array if necessary. */ | |
7736 | if (lh->file_names_size == 0) | |
7737 | { | |
7738 | lh->file_names_size = 1; /* for testing */ | |
7739 | lh->file_names = xmalloc (lh->file_names_size | |
7740 | * sizeof (*lh->file_names)); | |
7741 | } | |
7742 | else if (lh->num_file_names >= lh->file_names_size) | |
7743 | { | |
7744 | lh->file_names_size *= 2; | |
7745 | lh->file_names = xrealloc (lh->file_names, | |
7746 | (lh->file_names_size | |
7747 | * sizeof (*lh->file_names))); | |
7748 | } | |
7749 | ||
7750 | fe = &lh->file_names[lh->num_file_names++]; | |
7751 | fe->name = name; | |
7752 | fe->dir_index = dir_index; | |
7753 | fe->mod_time = mod_time; | |
7754 | fe->length = length; | |
aaa75496 | 7755 | fe->included_p = 0; |
cb1df416 | 7756 | fe->symtab = NULL; |
debd256d JB |
7757 | } |
7758 | ||
7759 | ||
7760 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
7761 | .debug_line, according to the endianness of ABFD. Return a pointer |
7762 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
7763 | |
7764 | NOTE: the strings in the include directory and file name tables of | |
7765 | the returned object point into debug_line_buffer, and must not be | |
7766 | freed. */ | |
7767 | static struct line_header * | |
7768 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 7769 | struct dwarf2_cu *cu) |
debd256d JB |
7770 | { |
7771 | struct cleanup *back_to; | |
7772 | struct line_header *lh; | |
fe1b8b76 | 7773 | gdb_byte *line_ptr; |
c764a876 | 7774 | unsigned int bytes_read, offset_size; |
debd256d JB |
7775 | int i; |
7776 | char *cur_dir, *cur_file; | |
7777 | ||
dce234bc | 7778 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 7779 | { |
e2e0b3e5 | 7780 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
7781 | return 0; |
7782 | } | |
7783 | ||
a738430d MK |
7784 | /* Make sure that at least there's room for the total_length field. |
7785 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 7786 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 7787 | { |
4d3c2250 | 7788 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7789 | return 0; |
7790 | } | |
7791 | ||
7792 | lh = xmalloc (sizeof (*lh)); | |
7793 | memset (lh, 0, sizeof (*lh)); | |
7794 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
7795 | (void *) lh); | |
7796 | ||
dce234bc | 7797 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 7798 | |
a738430d | 7799 | /* Read in the header. */ |
dd373385 | 7800 | lh->total_length = |
c764a876 DE |
7801 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
7802 | &bytes_read, &offset_size); | |
debd256d | 7803 | line_ptr += bytes_read; |
dce234bc PP |
7804 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
7805 | + dwarf2_per_objfile->line.size)) | |
debd256d | 7806 | { |
4d3c2250 | 7807 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7808 | return 0; |
7809 | } | |
7810 | lh->statement_program_end = line_ptr + lh->total_length; | |
7811 | lh->version = read_2_bytes (abfd, line_ptr); | |
7812 | line_ptr += 2; | |
c764a876 DE |
7813 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
7814 | line_ptr += offset_size; | |
debd256d JB |
7815 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
7816 | line_ptr += 1; | |
7817 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
7818 | line_ptr += 1; | |
7819 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
7820 | line_ptr += 1; | |
7821 | lh->line_range = read_1_byte (abfd, line_ptr); | |
7822 | line_ptr += 1; | |
7823 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
7824 | line_ptr += 1; | |
7825 | lh->standard_opcode_lengths | |
fe1b8b76 | 7826 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
7827 | |
7828 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
7829 | for (i = 1; i < lh->opcode_base; ++i) | |
7830 | { | |
7831 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
7832 | line_ptr += 1; | |
7833 | } | |
7834 | ||
a738430d | 7835 | /* Read directory table. */ |
debd256d JB |
7836 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7837 | { | |
7838 | line_ptr += bytes_read; | |
7839 | add_include_dir (lh, cur_dir); | |
7840 | } | |
7841 | line_ptr += bytes_read; | |
7842 | ||
a738430d | 7843 | /* Read file name table. */ |
debd256d JB |
7844 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7845 | { | |
7846 | unsigned int dir_index, mod_time, length; | |
7847 | ||
7848 | line_ptr += bytes_read; | |
7849 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7850 | line_ptr += bytes_read; | |
7851 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7852 | line_ptr += bytes_read; | |
7853 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7854 | line_ptr += bytes_read; | |
7855 | ||
7856 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7857 | } | |
7858 | line_ptr += bytes_read; | |
7859 | lh->statement_program_start = line_ptr; | |
7860 | ||
dce234bc PP |
7861 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
7862 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 7863 | complaint (&symfile_complaints, |
e2e0b3e5 | 7864 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
7865 | |
7866 | discard_cleanups (back_to); | |
7867 | return lh; | |
7868 | } | |
c906108c | 7869 | |
5fb290d7 DJ |
7870 | /* This function exists to work around a bug in certain compilers |
7871 | (particularly GCC 2.95), in which the first line number marker of a | |
7872 | function does not show up until after the prologue, right before | |
7873 | the second line number marker. This function shifts ADDRESS down | |
7874 | to the beginning of the function if necessary, and is called on | |
7875 | addresses passed to record_line. */ | |
7876 | ||
7877 | static CORE_ADDR | |
e142c38c | 7878 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
7879 | { |
7880 | struct function_range *fn; | |
7881 | ||
7882 | /* Find the function_range containing address. */ | |
e142c38c | 7883 | if (!cu->first_fn) |
5fb290d7 DJ |
7884 | return address; |
7885 | ||
e142c38c DJ |
7886 | if (!cu->cached_fn) |
7887 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 7888 | |
e142c38c | 7889 | fn = cu->cached_fn; |
5fb290d7 DJ |
7890 | while (fn) |
7891 | if (fn->lowpc <= address && fn->highpc > address) | |
7892 | goto found; | |
7893 | else | |
7894 | fn = fn->next; | |
7895 | ||
e142c38c DJ |
7896 | fn = cu->first_fn; |
7897 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
7898 | if (fn->lowpc <= address && fn->highpc > address) |
7899 | goto found; | |
7900 | else | |
7901 | fn = fn->next; | |
7902 | ||
7903 | return address; | |
7904 | ||
7905 | found: | |
7906 | if (fn->seen_line) | |
7907 | return address; | |
7908 | if (address != fn->lowpc) | |
4d3c2250 | 7909 | complaint (&symfile_complaints, |
e2e0b3e5 | 7910 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 7911 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
7912 | fn->seen_line = 1; |
7913 | return fn->lowpc; | |
7914 | } | |
7915 | ||
aaa75496 JB |
7916 | /* Decode the Line Number Program (LNP) for the given line_header |
7917 | structure and CU. The actual information extracted and the type | |
7918 | of structures created from the LNP depends on the value of PST. | |
7919 | ||
7920 | 1. If PST is NULL, then this procedure uses the data from the program | |
7921 | to create all necessary symbol tables, and their linetables. | |
7922 | The compilation directory of the file is passed in COMP_DIR, | |
7923 | and must not be NULL. | |
7924 | ||
7925 | 2. If PST is not NULL, this procedure reads the program to determine | |
7926 | the list of files included by the unit represented by PST, and | |
7927 | builds all the associated partial symbol tables. In this case, | |
7928 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
7929 | is not used to compute the full name of the symtab, and therefore | |
7930 | omitting it when building the partial symtab does not introduce | |
7931 | the potential for inconsistency - a partial symtab and its associated | |
7932 | symbtab having a different fullname -). */ | |
debd256d | 7933 | |
c906108c | 7934 | static void |
debd256d | 7935 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 7936 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 7937 | { |
a8c50c1f | 7938 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 7939 | gdb_byte *line_end; |
a8c50c1f | 7940 | unsigned int bytes_read, extended_len; |
c906108c | 7941 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
7942 | CORE_ADDR baseaddr; |
7943 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 7944 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 7945 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 7946 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
7947 | |
7948 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7949 | |
debd256d JB |
7950 | line_ptr = lh->statement_program_start; |
7951 | line_end = lh->statement_program_end; | |
c906108c SS |
7952 | |
7953 | /* Read the statement sequences until there's nothing left. */ | |
7954 | while (line_ptr < line_end) | |
7955 | { | |
7956 | /* state machine registers */ | |
7957 | CORE_ADDR address = 0; | |
7958 | unsigned int file = 1; | |
7959 | unsigned int line = 1; | |
7960 | unsigned int column = 0; | |
debd256d | 7961 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
7962 | int basic_block = 0; |
7963 | int end_sequence = 0; | |
fbf65064 | 7964 | CORE_ADDR addr; |
c906108c | 7965 | |
aaa75496 | 7966 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 7967 | { |
aaa75496 | 7968 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
7969 | /* lh->include_dirs and lh->file_names are 0-based, but the |
7970 | directory and file name numbers in the statement program | |
7971 | are 1-based. */ | |
7972 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 7973 | char *dir = NULL; |
a738430d | 7974 | |
debd256d JB |
7975 | if (fe->dir_index) |
7976 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
7977 | |
7978 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
7979 | } |
7980 | ||
a738430d | 7981 | /* Decode the table. */ |
c5aa993b | 7982 | while (!end_sequence) |
c906108c SS |
7983 | { |
7984 | op_code = read_1_byte (abfd, line_ptr); | |
7985 | line_ptr += 1; | |
59205f5a JB |
7986 | if (line_ptr > line_end) |
7987 | { | |
7988 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
7989 | break; | |
7990 | } | |
9aa1fe7e | 7991 | |
debd256d | 7992 | if (op_code >= lh->opcode_base) |
a738430d MK |
7993 | { |
7994 | /* Special operand. */ | |
debd256d JB |
7995 | adj_opcode = op_code - lh->opcode_base; |
7996 | address += (adj_opcode / lh->line_range) | |
7997 | * lh->minimum_instruction_length; | |
7998 | line += lh->line_base + (adj_opcode % lh->line_range); | |
59205f5a | 7999 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8000 | dwarf2_debug_line_missing_file_complaint (); |
8001 | else | |
8002 | { | |
8003 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 8004 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
8005 | { |
8006 | if (last_subfile != current_subfile) | |
8007 | { | |
8008 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8009 | if (last_subfile) | |
8010 | record_line (last_subfile, 0, addr); | |
8011 | last_subfile = current_subfile; | |
8012 | } | |
25e43795 | 8013 | /* Append row to matrix using current values. */ |
fbf65064 UW |
8014 | addr = check_cu_functions (address, cu); |
8015 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
8016 | record_line (current_subfile, line, addr); | |
366da635 | 8017 | } |
25e43795 | 8018 | } |
ca5f395d | 8019 | basic_block = 0; |
9aa1fe7e GK |
8020 | } |
8021 | else switch (op_code) | |
c906108c SS |
8022 | { |
8023 | case DW_LNS_extended_op: | |
a8c50c1f | 8024 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 8025 | line_ptr += bytes_read; |
a8c50c1f | 8026 | extended_end = line_ptr + extended_len; |
c906108c SS |
8027 | extended_op = read_1_byte (abfd, line_ptr); |
8028 | line_ptr += 1; | |
8029 | switch (extended_op) | |
8030 | { | |
8031 | case DW_LNE_end_sequence: | |
8032 | end_sequence = 1; | |
c906108c SS |
8033 | break; |
8034 | case DW_LNE_set_address: | |
e7c27a73 | 8035 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
8036 | line_ptr += bytes_read; |
8037 | address += baseaddr; | |
c906108c SS |
8038 | break; |
8039 | case DW_LNE_define_file: | |
debd256d JB |
8040 | { |
8041 | char *cur_file; | |
8042 | unsigned int dir_index, mod_time, length; | |
8043 | ||
8044 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
8045 | line_ptr += bytes_read; | |
8046 | dir_index = | |
8047 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8048 | line_ptr += bytes_read; | |
8049 | mod_time = | |
8050 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8051 | line_ptr += bytes_read; | |
8052 | length = | |
8053 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8054 | line_ptr += bytes_read; | |
8055 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
8056 | } | |
c906108c | 8057 | break; |
d0c6ba3d CC |
8058 | case DW_LNE_set_discriminator: |
8059 | /* The discriminator is not interesting to the debugger; | |
8060 | just ignore it. */ | |
8061 | line_ptr = extended_end; | |
8062 | break; | |
c906108c | 8063 | default: |
4d3c2250 | 8064 | complaint (&symfile_complaints, |
e2e0b3e5 | 8065 | _("mangled .debug_line section")); |
debd256d | 8066 | return; |
c906108c | 8067 | } |
a8c50c1f DJ |
8068 | /* Make sure that we parsed the extended op correctly. If e.g. |
8069 | we expected a different address size than the producer used, | |
8070 | we may have read the wrong number of bytes. */ | |
8071 | if (line_ptr != extended_end) | |
8072 | { | |
8073 | complaint (&symfile_complaints, | |
8074 | _("mangled .debug_line section")); | |
8075 | return; | |
8076 | } | |
c906108c SS |
8077 | break; |
8078 | case DW_LNS_copy: | |
59205f5a | 8079 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8080 | dwarf2_debug_line_missing_file_complaint (); |
8081 | else | |
366da635 | 8082 | { |
25e43795 | 8083 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 8084 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
8085 | { |
8086 | if (last_subfile != current_subfile) | |
8087 | { | |
8088 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8089 | if (last_subfile) | |
8090 | record_line (last_subfile, 0, addr); | |
8091 | last_subfile = current_subfile; | |
8092 | } | |
8093 | addr = check_cu_functions (address, cu); | |
8094 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
8095 | record_line (current_subfile, line, addr); | |
8096 | } | |
366da635 | 8097 | } |
c906108c SS |
8098 | basic_block = 0; |
8099 | break; | |
8100 | case DW_LNS_advance_pc: | |
debd256d | 8101 | address += lh->minimum_instruction_length |
c906108c SS |
8102 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8103 | line_ptr += bytes_read; | |
8104 | break; | |
8105 | case DW_LNS_advance_line: | |
8106 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
8107 | line_ptr += bytes_read; | |
8108 | break; | |
8109 | case DW_LNS_set_file: | |
debd256d | 8110 | { |
a738430d MK |
8111 | /* The arrays lh->include_dirs and lh->file_names are |
8112 | 0-based, but the directory and file name numbers in | |
8113 | the statement program are 1-based. */ | |
debd256d | 8114 | struct file_entry *fe; |
4f1520fb | 8115 | char *dir = NULL; |
a738430d | 8116 | |
debd256d JB |
8117 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8118 | line_ptr += bytes_read; | |
59205f5a | 8119 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8120 | dwarf2_debug_line_missing_file_complaint (); |
8121 | else | |
8122 | { | |
8123 | fe = &lh->file_names[file - 1]; | |
8124 | if (fe->dir_index) | |
8125 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8126 | if (!decode_for_pst_p) | |
8127 | { | |
8128 | last_subfile = current_subfile; | |
8129 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8130 | } | |
8131 | } | |
debd256d | 8132 | } |
c906108c SS |
8133 | break; |
8134 | case DW_LNS_set_column: | |
8135 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8136 | line_ptr += bytes_read; | |
8137 | break; | |
8138 | case DW_LNS_negate_stmt: | |
8139 | is_stmt = (!is_stmt); | |
8140 | break; | |
8141 | case DW_LNS_set_basic_block: | |
8142 | basic_block = 1; | |
8143 | break; | |
c2c6d25f JM |
8144 | /* Add to the address register of the state machine the |
8145 | address increment value corresponding to special opcode | |
a738430d MK |
8146 | 255. I.e., this value is scaled by the minimum |
8147 | instruction length since special opcode 255 would have | |
8148 | scaled the the increment. */ | |
c906108c | 8149 | case DW_LNS_const_add_pc: |
debd256d JB |
8150 | address += (lh->minimum_instruction_length |
8151 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
8152 | break; |
8153 | case DW_LNS_fixed_advance_pc: | |
8154 | address += read_2_bytes (abfd, line_ptr); | |
8155 | line_ptr += 2; | |
8156 | break; | |
9aa1fe7e | 8157 | default: |
a738430d MK |
8158 | { |
8159 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 8160 | int i; |
a738430d | 8161 | |
debd256d | 8162 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
8163 | { |
8164 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8165 | line_ptr += bytes_read; | |
8166 | } | |
8167 | } | |
c906108c SS |
8168 | } |
8169 | } | |
59205f5a JB |
8170 | if (lh->num_file_names < file || file == 0) |
8171 | dwarf2_debug_line_missing_file_complaint (); | |
8172 | else | |
8173 | { | |
8174 | lh->file_names[file - 1].included_p = 1; | |
8175 | if (!decode_for_pst_p) | |
fbf65064 UW |
8176 | { |
8177 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8178 | record_line (current_subfile, 0, addr); | |
8179 | } | |
59205f5a | 8180 | } |
c906108c | 8181 | } |
aaa75496 JB |
8182 | |
8183 | if (decode_for_pst_p) | |
8184 | { | |
8185 | int file_index; | |
8186 | ||
8187 | /* Now that we're done scanning the Line Header Program, we can | |
8188 | create the psymtab of each included file. */ | |
8189 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
8190 | if (lh->file_names[file_index].included_p == 1) | |
8191 | { | |
5b5464ad JB |
8192 | const struct file_entry fe = lh->file_names [file_index]; |
8193 | char *include_name = fe.name; | |
8194 | char *dir_name = NULL; | |
8195 | char *pst_filename = pst->filename; | |
8196 | ||
8197 | if (fe.dir_index) | |
8198 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
8199 | ||
8200 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
8201 | { | |
1754f103 MK |
8202 | include_name = concat (dir_name, SLASH_STRING, |
8203 | include_name, (char *)NULL); | |
5b5464ad JB |
8204 | make_cleanup (xfree, include_name); |
8205 | } | |
8206 | ||
8207 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
8208 | { | |
1754f103 MK |
8209 | pst_filename = concat (pst->dirname, SLASH_STRING, |
8210 | pst_filename, (char *)NULL); | |
5b5464ad JB |
8211 | make_cleanup (xfree, pst_filename); |
8212 | } | |
8213 | ||
8214 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
8215 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
8216 | } | |
8217 | } | |
cb1df416 DJ |
8218 | else |
8219 | { | |
8220 | /* Make sure a symtab is created for every file, even files | |
8221 | which contain only variables (i.e. no code with associated | |
8222 | line numbers). */ | |
8223 | ||
8224 | int i; | |
8225 | struct file_entry *fe; | |
8226 | ||
8227 | for (i = 0; i < lh->num_file_names; i++) | |
8228 | { | |
8229 | char *dir = NULL; | |
8230 | fe = &lh->file_names[i]; | |
8231 | if (fe->dir_index) | |
8232 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8233 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8234 | ||
8235 | /* Skip the main file; we don't need it, and it must be | |
8236 | allocated last, so that it will show up before the | |
8237 | non-primary symtabs in the objfile's symtab list. */ | |
8238 | if (current_subfile == first_subfile) | |
8239 | continue; | |
8240 | ||
8241 | if (current_subfile->symtab == NULL) | |
8242 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
8243 | cu->objfile); | |
8244 | fe->symtab = current_subfile->symtab; | |
8245 | } | |
8246 | } | |
c906108c SS |
8247 | } |
8248 | ||
8249 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
8250 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
8251 | or NULL if not known. COMP_DIR is the compilation directory for the |
8252 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
8253 | This routine tries to keep line numbers from identical absolute and |
8254 | relative file names in a common subfile. | |
8255 | ||
8256 | Using the `list' example from the GDB testsuite, which resides in | |
8257 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
8258 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
8259 | ||
c5aa993b JM |
8260 | DW_AT_name: /srcdir/list0.c |
8261 | DW_AT_comp_dir: /compdir | |
357e46e7 | 8262 | files.files[0].name: list0.h |
c5aa993b | 8263 | files.files[0].dir: /srcdir |
357e46e7 | 8264 | files.files[1].name: list0.c |
c5aa993b | 8265 | files.files[1].dir: /srcdir |
c906108c SS |
8266 | |
8267 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
8268 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
8269 | start_subfile will ensure that this happens provided that we pass the | |
8270 | concatenation of files.files[1].dir and files.files[1].name as the | |
8271 | subfile's name. */ | |
c906108c SS |
8272 | |
8273 | static void | |
4f1520fb | 8274 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 8275 | { |
4f1520fb FR |
8276 | char *fullname; |
8277 | ||
8278 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
8279 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
8280 | second argument to start_subfile. To be consistent, we do the | |
8281 | same here. In order not to lose the line information directory, | |
8282 | we concatenate it to the filename when it makes sense. | |
8283 | Note that the Dwarf3 standard says (speaking of filenames in line | |
8284 | information): ``The directory index is ignored for file names | |
8285 | that represent full path names''. Thus ignoring dirname in the | |
8286 | `else' branch below isn't an issue. */ | |
c906108c | 8287 | |
d5166ae1 | 8288 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
8289 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
8290 | else | |
8291 | fullname = filename; | |
c906108c | 8292 | |
4f1520fb FR |
8293 | start_subfile (fullname, comp_dir); |
8294 | ||
8295 | if (fullname != filename) | |
8296 | xfree (fullname); | |
c906108c SS |
8297 | } |
8298 | ||
4c2df51b DJ |
8299 | static void |
8300 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8301 | struct dwarf2_cu *cu) |
4c2df51b | 8302 | { |
e7c27a73 DJ |
8303 | struct objfile *objfile = cu->objfile; |
8304 | struct comp_unit_head *cu_header = &cu->header; | |
8305 | ||
4c2df51b DJ |
8306 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
8307 | code here to turn a symbol with DW_AT_external and a | |
8308 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
8309 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
8310 | with some versions of binutils) where shared libraries could have | |
8311 | relocations against symbols in their debug information - the | |
8312 | minimal symbol would have the right address, but the debug info | |
8313 | would not. It's no longer necessary, because we will explicitly | |
8314 | apply relocations when we read in the debug information now. */ | |
8315 | ||
8316 | /* A DW_AT_location attribute with no contents indicates that a | |
8317 | variable has been optimized away. */ | |
8318 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
8319 | { | |
8320 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
8321 | return; | |
8322 | } | |
8323 | ||
8324 | /* Handle one degenerate form of location expression specially, to | |
8325 | preserve GDB's previous behavior when section offsets are | |
8326 | specified. If this is just a DW_OP_addr then mark this symbol | |
8327 | as LOC_STATIC. */ | |
8328 | ||
8329 | if (attr_form_is_block (attr) | |
8330 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
8331 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
8332 | { | |
891d2f0b | 8333 | unsigned int dummy; |
4c2df51b DJ |
8334 | |
8335 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 8336 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 8337 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
8338 | fixup_symbol_section (sym, objfile); |
8339 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
8340 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
8341 | return; |
8342 | } | |
8343 | ||
8344 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
8345 | expression evaluator, and use LOC_COMPUTED only when necessary | |
8346 | (i.e. when the value of a register or memory location is | |
8347 | referenced, or a thread-local block, etc.). Then again, it might | |
8348 | not be worthwhile. I'm assuming that it isn't unless performance | |
8349 | or memory numbers show me otherwise. */ | |
8350 | ||
e7c27a73 | 8351 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
8352 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8353 | } | |
8354 | ||
c906108c SS |
8355 | /* Given a pointer to a DWARF information entry, figure out if we need |
8356 | to make a symbol table entry for it, and if so, create a new entry | |
8357 | and return a pointer to it. | |
8358 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 8359 | used the passed type. */ |
c906108c SS |
8360 | |
8361 | static struct symbol * | |
e7c27a73 | 8362 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 8363 | { |
e7c27a73 | 8364 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8365 | struct symbol *sym = NULL; |
8366 | char *name; | |
8367 | struct attribute *attr = NULL; | |
8368 | struct attribute *attr2 = NULL; | |
e142c38c | 8369 | CORE_ADDR baseaddr; |
edb3359d | 8370 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
8371 | |
8372 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 8373 | |
94af9270 | 8374 | name = dwarf2_name (die, cu); |
c906108c SS |
8375 | if (name) |
8376 | { | |
94af9270 KS |
8377 | const char *linkagename; |
8378 | ||
4a146b47 | 8379 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
8380 | sizeof (struct symbol)); |
8381 | OBJSTAT (objfile, n_syms++); | |
8382 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
8383 | |
8384 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 8385 | SYMBOL_LANGUAGE (sym) = cu->language; |
94af9270 KS |
8386 | linkagename = dwarf2_physname (name, die, cu); |
8387 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c SS |
8388 | |
8389 | /* Default assumptions. | |
c5aa993b | 8390 | Use the passed type or decode it from the die. */ |
176620f1 | 8391 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 8392 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
8393 | if (type != NULL) |
8394 | SYMBOL_TYPE (sym) = type; | |
8395 | else | |
e7c27a73 | 8396 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
8397 | attr = dwarf2_attr (die, |
8398 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
8399 | cu); | |
c906108c SS |
8400 | if (attr) |
8401 | { | |
8402 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
8403 | } | |
cb1df416 | 8404 | |
edb3359d DJ |
8405 | attr = dwarf2_attr (die, |
8406 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
8407 | cu); | |
cb1df416 DJ |
8408 | if (attr) |
8409 | { | |
8410 | int file_index = DW_UNSND (attr); | |
8411 | if (cu->line_header == NULL | |
8412 | || file_index > cu->line_header->num_file_names) | |
8413 | complaint (&symfile_complaints, | |
8414 | _("file index out of range")); | |
1c3d648d | 8415 | else if (file_index > 0) |
cb1df416 DJ |
8416 | { |
8417 | struct file_entry *fe; | |
8418 | fe = &cu->line_header->file_names[file_index - 1]; | |
8419 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
8420 | } | |
8421 | } | |
8422 | ||
c906108c SS |
8423 | switch (die->tag) |
8424 | { | |
8425 | case DW_TAG_label: | |
e142c38c | 8426 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
8427 | if (attr) |
8428 | { | |
8429 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
8430 | } | |
8431 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
8432 | break; | |
8433 | case DW_TAG_subprogram: | |
8434 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8435 | finish_block. */ | |
8436 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 8437 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
8438 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
8439 | || cu->language == language_ada) | |
c906108c | 8440 | { |
2cfa0c8d JB |
8441 | /* Subprograms marked external are stored as a global symbol. |
8442 | Ada subprograms, whether marked external or not, are always | |
8443 | stored as a global symbol, because we want to be able to | |
8444 | access them globally. For instance, we want to be able | |
8445 | to break on a nested subprogram without having to | |
8446 | specify the context. */ | |
c906108c SS |
8447 | add_symbol_to_list (sym, &global_symbols); |
8448 | } | |
8449 | else | |
8450 | { | |
e142c38c | 8451 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8452 | } |
8453 | break; | |
edb3359d DJ |
8454 | case DW_TAG_inlined_subroutine: |
8455 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8456 | finish_block. */ | |
8457 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
8458 | SYMBOL_INLINED (sym) = 1; | |
8459 | /* Do not add the symbol to any lists. It will be found via | |
8460 | BLOCK_FUNCTION from the blockvector. */ | |
8461 | break; | |
c906108c SS |
8462 | case DW_TAG_variable: |
8463 | /* Compilation with minimal debug info may result in variables | |
8464 | with missing type entries. Change the misleading `void' type | |
8465 | to something sensible. */ | |
8466 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 8467 | SYMBOL_TYPE (sym) |
46bf5051 | 8468 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 8469 | |
e142c38c | 8470 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8471 | if (attr) |
8472 | { | |
e7c27a73 | 8473 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 8474 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
8475 | if (attr2 && (DW_UNSND (attr2) != 0)) |
8476 | add_symbol_to_list (sym, &global_symbols); | |
8477 | else | |
e142c38c | 8478 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8479 | break; |
8480 | } | |
e142c38c | 8481 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8482 | if (attr) |
8483 | { | |
e7c27a73 | 8484 | var_decode_location (attr, sym, cu); |
e142c38c | 8485 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8486 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 8487 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 8488 | else |
e142c38c | 8489 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8490 | } |
8491 | else | |
8492 | { | |
8493 | /* We do not know the address of this symbol. | |
c5aa993b JM |
8494 | If it is an external symbol and we have type information |
8495 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
8496 | The address of the variable will then be determined from | |
8497 | the minimal symbol table whenever the variable is | |
8498 | referenced. */ | |
e142c38c | 8499 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8500 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 8501 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 8502 | { |
0fe7935b DJ |
8503 | struct pending **list_to_add; |
8504 | ||
8505 | /* A variable with DW_AT_external is never static, but it | |
8506 | may be block-scoped. */ | |
8507 | list_to_add = (cu->list_in_scope == &file_symbols | |
8508 | ? &global_symbols : cu->list_in_scope); | |
8509 | ||
c906108c | 8510 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
0fe7935b | 8511 | add_symbol_to_list (sym, list_to_add); |
c906108c | 8512 | } |
442ddf59 JK |
8513 | else if (!die_is_declaration (die, cu)) |
8514 | { | |
8515 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
8516 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
8517 | add_symbol_to_list (sym, cu->list_in_scope); | |
8518 | } | |
c906108c SS |
8519 | } |
8520 | break; | |
8521 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
8522 | /* If we are inside a function, mark this as an argument. If |
8523 | not, we might be looking at an argument to an inlined function | |
8524 | when we do not have enough information to show inlined frames; | |
8525 | pretend it's a local variable in that case so that the user can | |
8526 | still see it. */ | |
8527 | if (context_stack_depth > 0 | |
8528 | && context_stack[context_stack_depth - 1].name != NULL) | |
8529 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 8530 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8531 | if (attr) |
8532 | { | |
e7c27a73 | 8533 | var_decode_location (attr, sym, cu); |
c906108c | 8534 | } |
e142c38c | 8535 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8536 | if (attr) |
8537 | { | |
e7c27a73 | 8538 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8539 | } |
e142c38c | 8540 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8541 | break; |
8542 | case DW_TAG_unspecified_parameters: | |
8543 | /* From varargs functions; gdb doesn't seem to have any | |
8544 | interest in this information, so just ignore it for now. | |
8545 | (FIXME?) */ | |
8546 | break; | |
8547 | case DW_TAG_class_type: | |
680b30c7 | 8548 | case DW_TAG_interface_type: |
c906108c SS |
8549 | case DW_TAG_structure_type: |
8550 | case DW_TAG_union_type: | |
72019c9c | 8551 | case DW_TAG_set_type: |
c906108c SS |
8552 | case DW_TAG_enumeration_type: |
8553 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 8554 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 8555 | |
63d06c5c DC |
8556 | /* Make sure that the symbol includes appropriate enclosing |
8557 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 8558 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
8559 | the type. */ |
8560 | ||
987504bb JJ |
8561 | if (cu->language == language_cplus |
8562 | || cu->language == language_java) | |
c906108c | 8563 | { |
63d06c5c DC |
8564 | struct type *type = SYMBOL_TYPE (sym); |
8565 | ||
8566 | if (TYPE_TAG_NAME (type) != NULL) | |
8567 | { | |
8568 | /* FIXME: carlton/2003-11-10: Should this use | |
8569 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
8570 | arises further down in this function.) */ |
8571 | /* The type's name is already allocated along with | |
8572 | this objfile, so we don't need to duplicate it | |
8573 | for the symbol. */ | |
8574 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 8575 | } |
c906108c | 8576 | } |
63d06c5c DC |
8577 | |
8578 | { | |
987504bb | 8579 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
8580 | really ever be static objects: otherwise, if you try |
8581 | to, say, break of a class's method and you're in a file | |
8582 | which doesn't mention that class, it won't work unless | |
8583 | the check for all static symbols in lookup_symbol_aux | |
8584 | saves you. See the OtherFileClass tests in | |
8585 | gdb.c++/namespace.exp. */ | |
8586 | ||
8587 | struct pending **list_to_add; | |
8588 | ||
e142c38c | 8589 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8590 | && (cu->language == language_cplus |
8591 | || cu->language == language_java) | |
e142c38c | 8592 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8593 | |
8594 | add_symbol_to_list (sym, list_to_add); | |
8595 | ||
8596 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 8597 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 8598 | defines a typedef for the class. */ |
987504bb | 8599 | if (cu->language == language_cplus |
8c6860bb JB |
8600 | || cu->language == language_java |
8601 | || cu->language == language_ada) | |
63d06c5c | 8602 | { |
d8151005 DJ |
8603 | /* The symbol's name is already allocated along with |
8604 | this objfile, so we don't need to duplicate it for | |
8605 | the type. */ | |
63d06c5c | 8606 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 8607 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
8608 | } |
8609 | } | |
c906108c SS |
8610 | break; |
8611 | case DW_TAG_typedef: | |
94af9270 KS |
8612 | SYMBOL_LINKAGE_NAME (sym) |
8613 | = (char *) dwarf2_full_name (name, die, cu); | |
63d06c5c DC |
8614 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
8615 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 8616 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 8617 | break; |
c906108c | 8618 | case DW_TAG_base_type: |
a02abb62 | 8619 | case DW_TAG_subrange_type: |
c906108c | 8620 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 8621 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 8622 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8623 | break; |
8624 | case DW_TAG_enumerator: | |
94af9270 KS |
8625 | SYMBOL_LINKAGE_NAME (sym) |
8626 | = (char *) dwarf2_full_name (name, die, cu); | |
e142c38c | 8627 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8628 | if (attr) |
8629 | { | |
e7c27a73 | 8630 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8631 | } |
63d06c5c DC |
8632 | { |
8633 | /* NOTE: carlton/2003-11-10: See comment above in the | |
8634 | DW_TAG_class_type, etc. block. */ | |
8635 | ||
8636 | struct pending **list_to_add; | |
8637 | ||
e142c38c | 8638 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8639 | && (cu->language == language_cplus |
8640 | || cu->language == language_java) | |
e142c38c | 8641 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8642 | |
8643 | add_symbol_to_list (sym, list_to_add); | |
8644 | } | |
c906108c | 8645 | break; |
5c4e30ca DC |
8646 | case DW_TAG_namespace: |
8647 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
8648 | add_symbol_to_list (sym, &global_symbols); | |
8649 | break; | |
c906108c SS |
8650 | default: |
8651 | /* Not a tag we recognize. Hopefully we aren't processing | |
8652 | trash data, but since we must specifically ignore things | |
8653 | we don't recognize, there is nothing else we should do at | |
8654 | this point. */ | |
e2e0b3e5 | 8655 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 8656 | dwarf_tag_name (die->tag)); |
c906108c SS |
8657 | break; |
8658 | } | |
df8a16a1 DJ |
8659 | |
8660 | /* For the benefit of old versions of GCC, check for anonymous | |
8661 | namespaces based on the demangled name. */ | |
8662 | if (!processing_has_namespace_info | |
94af9270 | 8663 | && cu->language == language_cplus) |
df8a16a1 | 8664 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
8665 | } |
8666 | return (sym); | |
8667 | } | |
8668 | ||
8669 | /* Copy constant value from an attribute to a symbol. */ | |
8670 | ||
8671 | static void | |
107d2387 | 8672 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 8673 | struct dwarf2_cu *cu) |
c906108c | 8674 | { |
e7c27a73 DJ |
8675 | struct objfile *objfile = cu->objfile; |
8676 | struct comp_unit_head *cu_header = &cu->header; | |
e17a4113 UW |
8677 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
8678 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
c906108c SS |
8679 | struct dwarf_block *blk; |
8680 | ||
8681 | switch (attr->form) | |
8682 | { | |
8683 | case DW_FORM_addr: | |
107d2387 | 8684 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
3567439c | 8685 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8686 | cu_header->addr_size, |
8687 | TYPE_LENGTH (SYMBOL_TYPE | |
8688 | (sym))); | |
4e38b386 | 8689 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8690 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
8691 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
8692 | it's body - store_unsigned_integer. */ | |
8693 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
72f2769e | 8694 | byte_order, DW_ADDR (attr)); |
c906108c SS |
8695 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
8696 | break; | |
4ac36638 | 8697 | case DW_FORM_string: |
93b5768b PA |
8698 | case DW_FORM_strp: |
8699 | /* DW_STRING is already allocated on the obstack, point directly | |
8700 | to it. */ | |
8701 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
8702 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8703 | break; | |
c906108c SS |
8704 | case DW_FORM_block1: |
8705 | case DW_FORM_block2: | |
8706 | case DW_FORM_block4: | |
8707 | case DW_FORM_block: | |
8708 | blk = DW_BLOCK (attr); | |
8709 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 8710 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8711 | blk->size, |
8712 | TYPE_LENGTH (SYMBOL_TYPE | |
8713 | (sym))); | |
4e38b386 | 8714 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8715 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
8716 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
8717 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8718 | break; | |
2df3850c JM |
8719 | |
8720 | /* The DW_AT_const_value attributes are supposed to carry the | |
8721 | symbol's value "represented as it would be on the target | |
8722 | architecture." By the time we get here, it's already been | |
8723 | converted to host endianness, so we just need to sign- or | |
8724 | zero-extend it as appropriate. */ | |
8725 | case DW_FORM_data1: | |
8726 | dwarf2_const_value_data (attr, sym, 8); | |
8727 | break; | |
c906108c | 8728 | case DW_FORM_data2: |
2df3850c JM |
8729 | dwarf2_const_value_data (attr, sym, 16); |
8730 | break; | |
c906108c | 8731 | case DW_FORM_data4: |
2df3850c JM |
8732 | dwarf2_const_value_data (attr, sym, 32); |
8733 | break; | |
c906108c | 8734 | case DW_FORM_data8: |
2df3850c JM |
8735 | dwarf2_const_value_data (attr, sym, 64); |
8736 | break; | |
8737 | ||
c906108c | 8738 | case DW_FORM_sdata: |
2df3850c JM |
8739 | SYMBOL_VALUE (sym) = DW_SND (attr); |
8740 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8741 | break; | |
8742 | ||
c906108c SS |
8743 | case DW_FORM_udata: |
8744 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
8745 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8746 | break; | |
2df3850c | 8747 | |
c906108c | 8748 | default: |
4d3c2250 | 8749 | complaint (&symfile_complaints, |
e2e0b3e5 | 8750 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 8751 | dwarf_form_name (attr->form)); |
c906108c SS |
8752 | SYMBOL_VALUE (sym) = 0; |
8753 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8754 | break; | |
8755 | } | |
8756 | } | |
8757 | ||
2df3850c JM |
8758 | |
8759 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
8760 | or zero-extend it as appropriate for the symbol's type. */ | |
8761 | static void | |
8762 | dwarf2_const_value_data (struct attribute *attr, | |
8763 | struct symbol *sym, | |
8764 | int bits) | |
8765 | { | |
8766 | LONGEST l = DW_UNSND (attr); | |
8767 | ||
8768 | if (bits < sizeof (l) * 8) | |
8769 | { | |
8770 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
8771 | l &= ((LONGEST) 1 << bits) - 1; | |
8772 | else | |
bf9198f1 | 8773 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
8774 | } |
8775 | ||
8776 | SYMBOL_VALUE (sym) = l; | |
8777 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8778 | } | |
8779 | ||
8780 | ||
c906108c SS |
8781 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
8782 | ||
8783 | static struct type * | |
e7c27a73 | 8784 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8785 | { |
8786 | struct type *type; | |
8787 | struct attribute *type_attr; | |
8788 | struct die_info *type_die; | |
c906108c | 8789 | |
e142c38c | 8790 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
8791 | if (!type_attr) |
8792 | { | |
8793 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 8794 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 8795 | } |
348e048f DE |
8796 | |
8797 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10b3939b | 8798 | |
e7c27a73 | 8799 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8800 | if (!type) |
8801 | { | |
d97bc12b | 8802 | dump_die_for_error (type_die); |
8a3fe4f8 | 8803 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 8804 | cu->objfile->name); |
c906108c SS |
8805 | } |
8806 | return type; | |
8807 | } | |
8808 | ||
b4ba55a1 JB |
8809 | /* True iff CU's producer generates GNAT Ada auxiliary information |
8810 | that allows to find parallel types through that information instead | |
8811 | of having to do expensive parallel lookups by type name. */ | |
8812 | ||
8813 | static int | |
8814 | need_gnat_info (struct dwarf2_cu *cu) | |
8815 | { | |
8816 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
8817 | of GNAT produces this auxiliary information, without any indication | |
8818 | that it is produced. Part of enhancing the FSF version of GNAT | |
8819 | to produce that information will be to put in place an indicator | |
8820 | that we can use in order to determine whether the descriptive type | |
8821 | info is available or not. One suggestion that has been made is | |
8822 | to use a new attribute, attached to the CU die. For now, assume | |
8823 | that the descriptive type info is not available. */ | |
8824 | return 0; | |
8825 | } | |
8826 | ||
8827 | ||
8828 | /* Return the auxiliary type of the die in question using its | |
8829 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
8830 | attribute is not present. */ | |
8831 | ||
8832 | static struct type * | |
8833 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
8834 | { | |
8835 | struct type *type; | |
8836 | struct attribute *type_attr; | |
8837 | struct die_info *type_die; | |
8838 | ||
8839 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
8840 | if (!type_attr) | |
8841 | return NULL; | |
8842 | ||
8843 | type_die = follow_die_ref (die, type_attr, &cu); | |
8844 | type = tag_type_to_type (type_die, cu); | |
8845 | if (!type) | |
8846 | { | |
8847 | dump_die_for_error (type_die); | |
8848 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), | |
8849 | cu->objfile->name); | |
8850 | } | |
8851 | return type; | |
8852 | } | |
8853 | ||
8854 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
8855 | descriptive type accordingly. */ | |
8856 | ||
8857 | static void | |
8858 | set_descriptive_type (struct type *type, struct die_info *die, | |
8859 | struct dwarf2_cu *cu) | |
8860 | { | |
8861 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
8862 | ||
8863 | if (descriptive_type) | |
8864 | { | |
8865 | ALLOCATE_GNAT_AUX_TYPE (type); | |
8866 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
8867 | } | |
8868 | } | |
8869 | ||
c906108c SS |
8870 | /* Return the containing type of the die in question using its |
8871 | DW_AT_containing_type attribute. */ | |
8872 | ||
8873 | static struct type * | |
e7c27a73 | 8874 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8875 | { |
8876 | struct type *type = NULL; | |
8877 | struct attribute *type_attr; | |
8878 | struct die_info *type_die = NULL; | |
c906108c | 8879 | |
e142c38c | 8880 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
8881 | if (type_attr) |
8882 | { | |
348e048f | 8883 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); |
e7c27a73 | 8884 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8885 | } |
8886 | if (!type) | |
8887 | { | |
8888 | if (type_die) | |
d97bc12b | 8889 | dump_die_for_error (type_die); |
8a3fe4f8 | 8890 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 8891 | cu->objfile->name); |
c906108c SS |
8892 | } |
8893 | return type; | |
8894 | } | |
8895 | ||
c906108c | 8896 | static struct type * |
e7c27a73 | 8897 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8898 | { |
f792889a DJ |
8899 | struct type *this_type; |
8900 | ||
8901 | this_type = read_type_die (die, cu); | |
8902 | if (!this_type) | |
c906108c | 8903 | { |
d97bc12b | 8904 | dump_die_for_error (die); |
f792889a DJ |
8905 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
8906 | cu->objfile->name); | |
c906108c | 8907 | } |
f792889a | 8908 | return this_type; |
c906108c SS |
8909 | } |
8910 | ||
f792889a | 8911 | static struct type * |
e7c27a73 | 8912 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8913 | { |
f792889a DJ |
8914 | struct type *this_type; |
8915 | ||
8916 | this_type = get_die_type (die, cu); | |
8917 | if (this_type) | |
8918 | return this_type; | |
8919 | ||
c906108c SS |
8920 | switch (die->tag) |
8921 | { | |
8922 | case DW_TAG_class_type: | |
680b30c7 | 8923 | case DW_TAG_interface_type: |
c906108c SS |
8924 | case DW_TAG_structure_type: |
8925 | case DW_TAG_union_type: | |
f792889a | 8926 | this_type = read_structure_type (die, cu); |
c906108c SS |
8927 | break; |
8928 | case DW_TAG_enumeration_type: | |
f792889a | 8929 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
8930 | break; |
8931 | case DW_TAG_subprogram: | |
8932 | case DW_TAG_subroutine_type: | |
edb3359d | 8933 | case DW_TAG_inlined_subroutine: |
f792889a | 8934 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
8935 | break; |
8936 | case DW_TAG_array_type: | |
f792889a | 8937 | this_type = read_array_type (die, cu); |
c906108c | 8938 | break; |
72019c9c | 8939 | case DW_TAG_set_type: |
f792889a | 8940 | this_type = read_set_type (die, cu); |
72019c9c | 8941 | break; |
c906108c | 8942 | case DW_TAG_pointer_type: |
f792889a | 8943 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
8944 | break; |
8945 | case DW_TAG_ptr_to_member_type: | |
f792889a | 8946 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
8947 | break; |
8948 | case DW_TAG_reference_type: | |
f792889a | 8949 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
8950 | break; |
8951 | case DW_TAG_const_type: | |
f792889a | 8952 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
8953 | break; |
8954 | case DW_TAG_volatile_type: | |
f792889a | 8955 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
8956 | break; |
8957 | case DW_TAG_string_type: | |
f792889a | 8958 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
8959 | break; |
8960 | case DW_TAG_typedef: | |
f792889a | 8961 | this_type = read_typedef (die, cu); |
c906108c | 8962 | break; |
a02abb62 | 8963 | case DW_TAG_subrange_type: |
f792889a | 8964 | this_type = read_subrange_type (die, cu); |
a02abb62 | 8965 | break; |
c906108c | 8966 | case DW_TAG_base_type: |
f792889a | 8967 | this_type = read_base_type (die, cu); |
c906108c | 8968 | break; |
81a17f79 | 8969 | case DW_TAG_unspecified_type: |
f792889a | 8970 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 8971 | break; |
0114d602 DJ |
8972 | case DW_TAG_namespace: |
8973 | this_type = read_namespace_type (die, cu); | |
8974 | break; | |
c906108c | 8975 | default: |
a1f5b845 | 8976 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 8977 | dwarf_tag_name (die->tag)); |
c906108c SS |
8978 | break; |
8979 | } | |
63d06c5c | 8980 | |
f792889a | 8981 | return this_type; |
63d06c5c DC |
8982 | } |
8983 | ||
fdde2d81 | 8984 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 8985 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 8986 | |
0114d602 DJ |
8987 | For example, if we're within the method foo() in the following |
8988 | code: | |
8989 | ||
8990 | namespace N { | |
8991 | class C { | |
8992 | void foo () { | |
8993 | } | |
8994 | }; | |
8995 | } | |
8996 | ||
8997 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
8998 | |
8999 | static char * | |
e142c38c | 9000 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 9001 | { |
0114d602 DJ |
9002 | struct die_info *parent, *spec_die; |
9003 | struct dwarf2_cu *spec_cu; | |
9004 | struct type *parent_type; | |
63d06c5c | 9005 | |
987504bb JJ |
9006 | if (cu->language != language_cplus |
9007 | && cu->language != language_java) | |
0114d602 DJ |
9008 | return ""; |
9009 | ||
9010 | /* We have to be careful in the presence of DW_AT_specification. | |
9011 | For example, with GCC 3.4, given the code | |
9012 | ||
9013 | namespace N { | |
9014 | void foo() { | |
9015 | // Definition of N::foo. | |
9016 | } | |
9017 | } | |
9018 | ||
9019 | then we'll have a tree of DIEs like this: | |
9020 | ||
9021 | 1: DW_TAG_compile_unit | |
9022 | 2: DW_TAG_namespace // N | |
9023 | 3: DW_TAG_subprogram // declaration of N::foo | |
9024 | 4: DW_TAG_subprogram // definition of N::foo | |
9025 | DW_AT_specification // refers to die #3 | |
9026 | ||
9027 | Thus, when processing die #4, we have to pretend that we're in | |
9028 | the context of its DW_AT_specification, namely the contex of die | |
9029 | #3. */ | |
9030 | spec_cu = cu; | |
9031 | spec_die = die_specification (die, &spec_cu); | |
9032 | if (spec_die == NULL) | |
9033 | parent = die->parent; | |
9034 | else | |
63d06c5c | 9035 | { |
0114d602 DJ |
9036 | parent = spec_die->parent; |
9037 | cu = spec_cu; | |
63d06c5c | 9038 | } |
0114d602 DJ |
9039 | |
9040 | if (parent == NULL) | |
9041 | return ""; | |
63d06c5c | 9042 | else |
0114d602 DJ |
9043 | switch (parent->tag) |
9044 | { | |
63d06c5c | 9045 | case DW_TAG_namespace: |
0114d602 DJ |
9046 | parent_type = read_type_die (parent, cu); |
9047 | /* We give a name to even anonymous namespaces. */ | |
9048 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 9049 | case DW_TAG_class_type: |
680b30c7 | 9050 | case DW_TAG_interface_type: |
63d06c5c | 9051 | case DW_TAG_structure_type: |
0114d602 DJ |
9052 | case DW_TAG_union_type: |
9053 | parent_type = read_type_die (parent, cu); | |
9054 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
9055 | return TYPE_TAG_NAME (parent_type); | |
9056 | else | |
9057 | /* An anonymous structure is only allowed non-static data | |
9058 | members; no typedefs, no member functions, et cetera. | |
9059 | So it does not need a prefix. */ | |
9060 | return ""; | |
63d06c5c | 9061 | default: |
8176b9b8 | 9062 | return determine_prefix (parent, cu); |
63d06c5c | 9063 | } |
63d06c5c DC |
9064 | } |
9065 | ||
987504bb JJ |
9066 | /* Return a newly-allocated string formed by concatenating PREFIX and |
9067 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
9068 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
9069 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
9070 | is used to determine the language and hence, the appropriate separator. */ | |
9071 | ||
9072 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
9073 | |
9074 | static char * | |
987504bb JJ |
9075 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
9076 | struct dwarf2_cu *cu) | |
63d06c5c | 9077 | { |
987504bb | 9078 | char *sep; |
63d06c5c | 9079 | |
987504bb JJ |
9080 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
9081 | sep = ""; | |
9082 | else if (cu->language == language_java) | |
9083 | sep = "."; | |
9084 | else | |
9085 | sep = "::"; | |
63d06c5c | 9086 | |
6dd47d34 DE |
9087 | if (prefix == NULL) |
9088 | prefix = ""; | |
9089 | if (suffix == NULL) | |
9090 | suffix = ""; | |
9091 | ||
987504bb JJ |
9092 | if (obs == NULL) |
9093 | { | |
9094 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
6dd47d34 DE |
9095 | strcpy (retval, prefix); |
9096 | strcat (retval, sep); | |
9097 | strcat (retval, suffix); | |
63d06c5c DC |
9098 | return retval; |
9099 | } | |
987504bb JJ |
9100 | else |
9101 | { | |
9102 | /* We have an obstack. */ | |
9103 | return obconcat (obs, prefix, sep, suffix); | |
9104 | } | |
63d06c5c DC |
9105 | } |
9106 | ||
c906108c SS |
9107 | /* Return sibling of die, NULL if no sibling. */ |
9108 | ||
f9aca02d | 9109 | static struct die_info * |
fba45db2 | 9110 | sibling_die (struct die_info *die) |
c906108c | 9111 | { |
639d11d3 | 9112 | return die->sibling; |
c906108c SS |
9113 | } |
9114 | ||
71c25dea TT |
9115 | /* Get name of a die, return NULL if not found. */ |
9116 | ||
9117 | static char * | |
9118 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
9119 | struct obstack *obstack) | |
9120 | { | |
9121 | if (name && cu->language == language_cplus) | |
9122 | { | |
9123 | char *canon_name = cp_canonicalize_string (name); | |
9124 | ||
9125 | if (canon_name != NULL) | |
9126 | { | |
9127 | if (strcmp (canon_name, name) != 0) | |
9128 | name = obsavestring (canon_name, strlen (canon_name), | |
9129 | obstack); | |
9130 | xfree (canon_name); | |
9131 | } | |
9132 | } | |
9133 | ||
9134 | return name; | |
c906108c SS |
9135 | } |
9136 | ||
9219021c DC |
9137 | /* Get name of a die, return NULL if not found. */ |
9138 | ||
9139 | static char * | |
e142c38c | 9140 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
9141 | { |
9142 | struct attribute *attr; | |
9143 | ||
e142c38c | 9144 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
9145 | if (!attr || !DW_STRING (attr)) |
9146 | return NULL; | |
9147 | ||
9148 | switch (die->tag) | |
9149 | { | |
9150 | case DW_TAG_compile_unit: | |
9151 | /* Compilation units have a DW_AT_name that is a filename, not | |
9152 | a source language identifier. */ | |
9153 | case DW_TAG_enumeration_type: | |
9154 | case DW_TAG_enumerator: | |
9155 | /* These tags always have simple identifiers already; no need | |
9156 | to canonicalize them. */ | |
9157 | return DW_STRING (attr); | |
9158 | default: | |
8285870a | 9159 | if (!DW_STRING_IS_CANONICAL (attr)) |
71c25dea TT |
9160 | { |
9161 | DW_STRING (attr) | |
9162 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
9163 | &cu->objfile->objfile_obstack); | |
8285870a | 9164 | DW_STRING_IS_CANONICAL (attr) = 1; |
71c25dea TT |
9165 | } |
9166 | return DW_STRING (attr); | |
9167 | } | |
9219021c DC |
9168 | } |
9169 | ||
9170 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
9171 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
9172 | containing the return value on output. */ | |
9219021c DC |
9173 | |
9174 | static struct die_info * | |
f2f0e013 | 9175 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
9176 | { |
9177 | struct attribute *attr; | |
9219021c | 9178 | |
f2f0e013 | 9179 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
9180 | if (attr == NULL) |
9181 | return NULL; | |
9182 | ||
f2f0e013 | 9183 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
9184 | } |
9185 | ||
c906108c SS |
9186 | /* Convert a DIE tag into its string name. */ |
9187 | ||
9188 | static char * | |
aa1ee363 | 9189 | dwarf_tag_name (unsigned tag) |
c906108c SS |
9190 | { |
9191 | switch (tag) | |
9192 | { | |
9193 | case DW_TAG_padding: | |
9194 | return "DW_TAG_padding"; | |
9195 | case DW_TAG_array_type: | |
9196 | return "DW_TAG_array_type"; | |
9197 | case DW_TAG_class_type: | |
9198 | return "DW_TAG_class_type"; | |
9199 | case DW_TAG_entry_point: | |
9200 | return "DW_TAG_entry_point"; | |
9201 | case DW_TAG_enumeration_type: | |
9202 | return "DW_TAG_enumeration_type"; | |
9203 | case DW_TAG_formal_parameter: | |
9204 | return "DW_TAG_formal_parameter"; | |
9205 | case DW_TAG_imported_declaration: | |
9206 | return "DW_TAG_imported_declaration"; | |
9207 | case DW_TAG_label: | |
9208 | return "DW_TAG_label"; | |
9209 | case DW_TAG_lexical_block: | |
9210 | return "DW_TAG_lexical_block"; | |
9211 | case DW_TAG_member: | |
9212 | return "DW_TAG_member"; | |
9213 | case DW_TAG_pointer_type: | |
9214 | return "DW_TAG_pointer_type"; | |
9215 | case DW_TAG_reference_type: | |
9216 | return "DW_TAG_reference_type"; | |
9217 | case DW_TAG_compile_unit: | |
9218 | return "DW_TAG_compile_unit"; | |
9219 | case DW_TAG_string_type: | |
9220 | return "DW_TAG_string_type"; | |
9221 | case DW_TAG_structure_type: | |
9222 | return "DW_TAG_structure_type"; | |
9223 | case DW_TAG_subroutine_type: | |
9224 | return "DW_TAG_subroutine_type"; | |
9225 | case DW_TAG_typedef: | |
9226 | return "DW_TAG_typedef"; | |
9227 | case DW_TAG_union_type: | |
9228 | return "DW_TAG_union_type"; | |
9229 | case DW_TAG_unspecified_parameters: | |
9230 | return "DW_TAG_unspecified_parameters"; | |
9231 | case DW_TAG_variant: | |
9232 | return "DW_TAG_variant"; | |
9233 | case DW_TAG_common_block: | |
9234 | return "DW_TAG_common_block"; | |
9235 | case DW_TAG_common_inclusion: | |
9236 | return "DW_TAG_common_inclusion"; | |
9237 | case DW_TAG_inheritance: | |
9238 | return "DW_TAG_inheritance"; | |
9239 | case DW_TAG_inlined_subroutine: | |
9240 | return "DW_TAG_inlined_subroutine"; | |
9241 | case DW_TAG_module: | |
9242 | return "DW_TAG_module"; | |
9243 | case DW_TAG_ptr_to_member_type: | |
9244 | return "DW_TAG_ptr_to_member_type"; | |
9245 | case DW_TAG_set_type: | |
9246 | return "DW_TAG_set_type"; | |
9247 | case DW_TAG_subrange_type: | |
9248 | return "DW_TAG_subrange_type"; | |
9249 | case DW_TAG_with_stmt: | |
9250 | return "DW_TAG_with_stmt"; | |
9251 | case DW_TAG_access_declaration: | |
9252 | return "DW_TAG_access_declaration"; | |
9253 | case DW_TAG_base_type: | |
9254 | return "DW_TAG_base_type"; | |
9255 | case DW_TAG_catch_block: | |
9256 | return "DW_TAG_catch_block"; | |
9257 | case DW_TAG_const_type: | |
9258 | return "DW_TAG_const_type"; | |
9259 | case DW_TAG_constant: | |
9260 | return "DW_TAG_constant"; | |
9261 | case DW_TAG_enumerator: | |
9262 | return "DW_TAG_enumerator"; | |
9263 | case DW_TAG_file_type: | |
9264 | return "DW_TAG_file_type"; | |
9265 | case DW_TAG_friend: | |
9266 | return "DW_TAG_friend"; | |
9267 | case DW_TAG_namelist: | |
9268 | return "DW_TAG_namelist"; | |
9269 | case DW_TAG_namelist_item: | |
9270 | return "DW_TAG_namelist_item"; | |
9271 | case DW_TAG_packed_type: | |
9272 | return "DW_TAG_packed_type"; | |
9273 | case DW_TAG_subprogram: | |
9274 | return "DW_TAG_subprogram"; | |
9275 | case DW_TAG_template_type_param: | |
9276 | return "DW_TAG_template_type_param"; | |
9277 | case DW_TAG_template_value_param: | |
9278 | return "DW_TAG_template_value_param"; | |
9279 | case DW_TAG_thrown_type: | |
9280 | return "DW_TAG_thrown_type"; | |
9281 | case DW_TAG_try_block: | |
9282 | return "DW_TAG_try_block"; | |
9283 | case DW_TAG_variant_part: | |
9284 | return "DW_TAG_variant_part"; | |
9285 | case DW_TAG_variable: | |
9286 | return "DW_TAG_variable"; | |
9287 | case DW_TAG_volatile_type: | |
9288 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
9289 | case DW_TAG_dwarf_procedure: |
9290 | return "DW_TAG_dwarf_procedure"; | |
9291 | case DW_TAG_restrict_type: | |
9292 | return "DW_TAG_restrict_type"; | |
9293 | case DW_TAG_interface_type: | |
9294 | return "DW_TAG_interface_type"; | |
9295 | case DW_TAG_namespace: | |
9296 | return "DW_TAG_namespace"; | |
9297 | case DW_TAG_imported_module: | |
9298 | return "DW_TAG_imported_module"; | |
9299 | case DW_TAG_unspecified_type: | |
9300 | return "DW_TAG_unspecified_type"; | |
9301 | case DW_TAG_partial_unit: | |
9302 | return "DW_TAG_partial_unit"; | |
9303 | case DW_TAG_imported_unit: | |
9304 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
9305 | case DW_TAG_condition: |
9306 | return "DW_TAG_condition"; | |
9307 | case DW_TAG_shared_type: | |
9308 | return "DW_TAG_shared_type"; | |
348e048f DE |
9309 | case DW_TAG_type_unit: |
9310 | return "DW_TAG_type_unit"; | |
c906108c SS |
9311 | case DW_TAG_MIPS_loop: |
9312 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
9313 | case DW_TAG_HP_array_descriptor: |
9314 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
9315 | case DW_TAG_format_label: |
9316 | return "DW_TAG_format_label"; | |
9317 | case DW_TAG_function_template: | |
9318 | return "DW_TAG_function_template"; | |
9319 | case DW_TAG_class_template: | |
9320 | return "DW_TAG_class_template"; | |
b7619582 GF |
9321 | case DW_TAG_GNU_BINCL: |
9322 | return "DW_TAG_GNU_BINCL"; | |
9323 | case DW_TAG_GNU_EINCL: | |
9324 | return "DW_TAG_GNU_EINCL"; | |
9325 | case DW_TAG_upc_shared_type: | |
9326 | return "DW_TAG_upc_shared_type"; | |
9327 | case DW_TAG_upc_strict_type: | |
9328 | return "DW_TAG_upc_strict_type"; | |
9329 | case DW_TAG_upc_relaxed_type: | |
9330 | return "DW_TAG_upc_relaxed_type"; | |
9331 | case DW_TAG_PGI_kanji_type: | |
9332 | return "DW_TAG_PGI_kanji_type"; | |
9333 | case DW_TAG_PGI_interface_block: | |
9334 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
9335 | default: |
9336 | return "DW_TAG_<unknown>"; | |
9337 | } | |
9338 | } | |
9339 | ||
9340 | /* Convert a DWARF attribute code into its string name. */ | |
9341 | ||
9342 | static char * | |
aa1ee363 | 9343 | dwarf_attr_name (unsigned attr) |
c906108c SS |
9344 | { |
9345 | switch (attr) | |
9346 | { | |
9347 | case DW_AT_sibling: | |
9348 | return "DW_AT_sibling"; | |
9349 | case DW_AT_location: | |
9350 | return "DW_AT_location"; | |
9351 | case DW_AT_name: | |
9352 | return "DW_AT_name"; | |
9353 | case DW_AT_ordering: | |
9354 | return "DW_AT_ordering"; | |
9355 | case DW_AT_subscr_data: | |
9356 | return "DW_AT_subscr_data"; | |
9357 | case DW_AT_byte_size: | |
9358 | return "DW_AT_byte_size"; | |
9359 | case DW_AT_bit_offset: | |
9360 | return "DW_AT_bit_offset"; | |
9361 | case DW_AT_bit_size: | |
9362 | return "DW_AT_bit_size"; | |
9363 | case DW_AT_element_list: | |
9364 | return "DW_AT_element_list"; | |
9365 | case DW_AT_stmt_list: | |
9366 | return "DW_AT_stmt_list"; | |
9367 | case DW_AT_low_pc: | |
9368 | return "DW_AT_low_pc"; | |
9369 | case DW_AT_high_pc: | |
9370 | return "DW_AT_high_pc"; | |
9371 | case DW_AT_language: | |
9372 | return "DW_AT_language"; | |
9373 | case DW_AT_member: | |
9374 | return "DW_AT_member"; | |
9375 | case DW_AT_discr: | |
9376 | return "DW_AT_discr"; | |
9377 | case DW_AT_discr_value: | |
9378 | return "DW_AT_discr_value"; | |
9379 | case DW_AT_visibility: | |
9380 | return "DW_AT_visibility"; | |
9381 | case DW_AT_import: | |
9382 | return "DW_AT_import"; | |
9383 | case DW_AT_string_length: | |
9384 | return "DW_AT_string_length"; | |
9385 | case DW_AT_common_reference: | |
9386 | return "DW_AT_common_reference"; | |
9387 | case DW_AT_comp_dir: | |
9388 | return "DW_AT_comp_dir"; | |
9389 | case DW_AT_const_value: | |
9390 | return "DW_AT_const_value"; | |
9391 | case DW_AT_containing_type: | |
9392 | return "DW_AT_containing_type"; | |
9393 | case DW_AT_default_value: | |
9394 | return "DW_AT_default_value"; | |
9395 | case DW_AT_inline: | |
9396 | return "DW_AT_inline"; | |
9397 | case DW_AT_is_optional: | |
9398 | return "DW_AT_is_optional"; | |
9399 | case DW_AT_lower_bound: | |
9400 | return "DW_AT_lower_bound"; | |
9401 | case DW_AT_producer: | |
9402 | return "DW_AT_producer"; | |
9403 | case DW_AT_prototyped: | |
9404 | return "DW_AT_prototyped"; | |
9405 | case DW_AT_return_addr: | |
9406 | return "DW_AT_return_addr"; | |
9407 | case DW_AT_start_scope: | |
9408 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
9409 | case DW_AT_bit_stride: |
9410 | return "DW_AT_bit_stride"; | |
c906108c SS |
9411 | case DW_AT_upper_bound: |
9412 | return "DW_AT_upper_bound"; | |
9413 | case DW_AT_abstract_origin: | |
9414 | return "DW_AT_abstract_origin"; | |
9415 | case DW_AT_accessibility: | |
9416 | return "DW_AT_accessibility"; | |
9417 | case DW_AT_address_class: | |
9418 | return "DW_AT_address_class"; | |
9419 | case DW_AT_artificial: | |
9420 | return "DW_AT_artificial"; | |
9421 | case DW_AT_base_types: | |
9422 | return "DW_AT_base_types"; | |
9423 | case DW_AT_calling_convention: | |
9424 | return "DW_AT_calling_convention"; | |
9425 | case DW_AT_count: | |
9426 | return "DW_AT_count"; | |
9427 | case DW_AT_data_member_location: | |
9428 | return "DW_AT_data_member_location"; | |
9429 | case DW_AT_decl_column: | |
9430 | return "DW_AT_decl_column"; | |
9431 | case DW_AT_decl_file: | |
9432 | return "DW_AT_decl_file"; | |
9433 | case DW_AT_decl_line: | |
9434 | return "DW_AT_decl_line"; | |
9435 | case DW_AT_declaration: | |
9436 | return "DW_AT_declaration"; | |
9437 | case DW_AT_discr_list: | |
9438 | return "DW_AT_discr_list"; | |
9439 | case DW_AT_encoding: | |
9440 | return "DW_AT_encoding"; | |
9441 | case DW_AT_external: | |
9442 | return "DW_AT_external"; | |
9443 | case DW_AT_frame_base: | |
9444 | return "DW_AT_frame_base"; | |
9445 | case DW_AT_friend: | |
9446 | return "DW_AT_friend"; | |
9447 | case DW_AT_identifier_case: | |
9448 | return "DW_AT_identifier_case"; | |
9449 | case DW_AT_macro_info: | |
9450 | return "DW_AT_macro_info"; | |
9451 | case DW_AT_namelist_items: | |
9452 | return "DW_AT_namelist_items"; | |
9453 | case DW_AT_priority: | |
9454 | return "DW_AT_priority"; | |
9455 | case DW_AT_segment: | |
9456 | return "DW_AT_segment"; | |
9457 | case DW_AT_specification: | |
9458 | return "DW_AT_specification"; | |
9459 | case DW_AT_static_link: | |
9460 | return "DW_AT_static_link"; | |
9461 | case DW_AT_type: | |
9462 | return "DW_AT_type"; | |
9463 | case DW_AT_use_location: | |
9464 | return "DW_AT_use_location"; | |
9465 | case DW_AT_variable_parameter: | |
9466 | return "DW_AT_variable_parameter"; | |
9467 | case DW_AT_virtuality: | |
9468 | return "DW_AT_virtuality"; | |
9469 | case DW_AT_vtable_elem_location: | |
9470 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 9471 | /* DWARF 3 values. */ |
d9fa45fe DC |
9472 | case DW_AT_allocated: |
9473 | return "DW_AT_allocated"; | |
9474 | case DW_AT_associated: | |
9475 | return "DW_AT_associated"; | |
9476 | case DW_AT_data_location: | |
9477 | return "DW_AT_data_location"; | |
09fa0d7c JK |
9478 | case DW_AT_byte_stride: |
9479 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
9480 | case DW_AT_entry_pc: |
9481 | return "DW_AT_entry_pc"; | |
9482 | case DW_AT_use_UTF8: | |
9483 | return "DW_AT_use_UTF8"; | |
9484 | case DW_AT_extension: | |
9485 | return "DW_AT_extension"; | |
9486 | case DW_AT_ranges: | |
9487 | return "DW_AT_ranges"; | |
9488 | case DW_AT_trampoline: | |
9489 | return "DW_AT_trampoline"; | |
9490 | case DW_AT_call_column: | |
9491 | return "DW_AT_call_column"; | |
9492 | case DW_AT_call_file: | |
9493 | return "DW_AT_call_file"; | |
9494 | case DW_AT_call_line: | |
9495 | return "DW_AT_call_line"; | |
b7619582 GF |
9496 | case DW_AT_description: |
9497 | return "DW_AT_description"; | |
9498 | case DW_AT_binary_scale: | |
9499 | return "DW_AT_binary_scale"; | |
9500 | case DW_AT_decimal_scale: | |
9501 | return "DW_AT_decimal_scale"; | |
9502 | case DW_AT_small: | |
9503 | return "DW_AT_small"; | |
9504 | case DW_AT_decimal_sign: | |
9505 | return "DW_AT_decimal_sign"; | |
9506 | case DW_AT_digit_count: | |
9507 | return "DW_AT_digit_count"; | |
9508 | case DW_AT_picture_string: | |
9509 | return "DW_AT_picture_string"; | |
9510 | case DW_AT_mutable: | |
9511 | return "DW_AT_mutable"; | |
9512 | case DW_AT_threads_scaled: | |
9513 | return "DW_AT_threads_scaled"; | |
9514 | case DW_AT_explicit: | |
9515 | return "DW_AT_explicit"; | |
9516 | case DW_AT_object_pointer: | |
9517 | return "DW_AT_object_pointer"; | |
9518 | case DW_AT_endianity: | |
9519 | return "DW_AT_endianity"; | |
9520 | case DW_AT_elemental: | |
9521 | return "DW_AT_elemental"; | |
9522 | case DW_AT_pure: | |
9523 | return "DW_AT_pure"; | |
9524 | case DW_AT_recursive: | |
9525 | return "DW_AT_recursive"; | |
348e048f DE |
9526 | /* DWARF 4 values. */ |
9527 | case DW_AT_signature: | |
9528 | return "DW_AT_signature"; | |
b7619582 | 9529 | /* SGI/MIPS extensions. */ |
c764a876 | 9530 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
9531 | case DW_AT_MIPS_fde: |
9532 | return "DW_AT_MIPS_fde"; | |
c764a876 | 9533 | #endif |
c906108c SS |
9534 | case DW_AT_MIPS_loop_begin: |
9535 | return "DW_AT_MIPS_loop_begin"; | |
9536 | case DW_AT_MIPS_tail_loop_begin: | |
9537 | return "DW_AT_MIPS_tail_loop_begin"; | |
9538 | case DW_AT_MIPS_epilog_begin: | |
9539 | return "DW_AT_MIPS_epilog_begin"; | |
9540 | case DW_AT_MIPS_loop_unroll_factor: | |
9541 | return "DW_AT_MIPS_loop_unroll_factor"; | |
9542 | case DW_AT_MIPS_software_pipeline_depth: | |
9543 | return "DW_AT_MIPS_software_pipeline_depth"; | |
9544 | case DW_AT_MIPS_linkage_name: | |
9545 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
9546 | case DW_AT_MIPS_stride: |
9547 | return "DW_AT_MIPS_stride"; | |
9548 | case DW_AT_MIPS_abstract_name: | |
9549 | return "DW_AT_MIPS_abstract_name"; | |
9550 | case DW_AT_MIPS_clone_origin: | |
9551 | return "DW_AT_MIPS_clone_origin"; | |
9552 | case DW_AT_MIPS_has_inlines: | |
9553 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 9554 | /* HP extensions. */ |
c764a876 | 9555 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
9556 | case DW_AT_HP_block_index: |
9557 | return "DW_AT_HP_block_index"; | |
c764a876 | 9558 | #endif |
b7619582 GF |
9559 | case DW_AT_HP_unmodifiable: |
9560 | return "DW_AT_HP_unmodifiable"; | |
9561 | case DW_AT_HP_actuals_stmt_list: | |
9562 | return "DW_AT_HP_actuals_stmt_list"; | |
9563 | case DW_AT_HP_proc_per_section: | |
9564 | return "DW_AT_HP_proc_per_section"; | |
9565 | case DW_AT_HP_raw_data_ptr: | |
9566 | return "DW_AT_HP_raw_data_ptr"; | |
9567 | case DW_AT_HP_pass_by_reference: | |
9568 | return "DW_AT_HP_pass_by_reference"; | |
9569 | case DW_AT_HP_opt_level: | |
9570 | return "DW_AT_HP_opt_level"; | |
9571 | case DW_AT_HP_prof_version_id: | |
9572 | return "DW_AT_HP_prof_version_id"; | |
9573 | case DW_AT_HP_opt_flags: | |
9574 | return "DW_AT_HP_opt_flags"; | |
9575 | case DW_AT_HP_cold_region_low_pc: | |
9576 | return "DW_AT_HP_cold_region_low_pc"; | |
9577 | case DW_AT_HP_cold_region_high_pc: | |
9578 | return "DW_AT_HP_cold_region_high_pc"; | |
9579 | case DW_AT_HP_all_variables_modifiable: | |
9580 | return "DW_AT_HP_all_variables_modifiable"; | |
9581 | case DW_AT_HP_linkage_name: | |
9582 | return "DW_AT_HP_linkage_name"; | |
9583 | case DW_AT_HP_prof_flags: | |
9584 | return "DW_AT_HP_prof_flags"; | |
9585 | /* GNU extensions. */ | |
c906108c SS |
9586 | case DW_AT_sf_names: |
9587 | return "DW_AT_sf_names"; | |
9588 | case DW_AT_src_info: | |
9589 | return "DW_AT_src_info"; | |
9590 | case DW_AT_mac_info: | |
9591 | return "DW_AT_mac_info"; | |
9592 | case DW_AT_src_coords: | |
9593 | return "DW_AT_src_coords"; | |
9594 | case DW_AT_body_begin: | |
9595 | return "DW_AT_body_begin"; | |
9596 | case DW_AT_body_end: | |
9597 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
9598 | case DW_AT_GNU_vector: |
9599 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
9600 | /* VMS extensions. */ |
9601 | case DW_AT_VMS_rtnbeg_pd_address: | |
9602 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
9603 | /* UPC extension. */ | |
9604 | case DW_AT_upc_threads_scaled: | |
9605 | return "DW_AT_upc_threads_scaled"; | |
9606 | /* PGI (STMicroelectronics) extensions. */ | |
9607 | case DW_AT_PGI_lbase: | |
9608 | return "DW_AT_PGI_lbase"; | |
9609 | case DW_AT_PGI_soffset: | |
9610 | return "DW_AT_PGI_soffset"; | |
9611 | case DW_AT_PGI_lstride: | |
9612 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
9613 | default: |
9614 | return "DW_AT_<unknown>"; | |
9615 | } | |
9616 | } | |
9617 | ||
9618 | /* Convert a DWARF value form code into its string name. */ | |
9619 | ||
9620 | static char * | |
aa1ee363 | 9621 | dwarf_form_name (unsigned form) |
c906108c SS |
9622 | { |
9623 | switch (form) | |
9624 | { | |
9625 | case DW_FORM_addr: | |
9626 | return "DW_FORM_addr"; | |
9627 | case DW_FORM_block2: | |
9628 | return "DW_FORM_block2"; | |
9629 | case DW_FORM_block4: | |
9630 | return "DW_FORM_block4"; | |
9631 | case DW_FORM_data2: | |
9632 | return "DW_FORM_data2"; | |
9633 | case DW_FORM_data4: | |
9634 | return "DW_FORM_data4"; | |
9635 | case DW_FORM_data8: | |
9636 | return "DW_FORM_data8"; | |
9637 | case DW_FORM_string: | |
9638 | return "DW_FORM_string"; | |
9639 | case DW_FORM_block: | |
9640 | return "DW_FORM_block"; | |
9641 | case DW_FORM_block1: | |
9642 | return "DW_FORM_block1"; | |
9643 | case DW_FORM_data1: | |
9644 | return "DW_FORM_data1"; | |
9645 | case DW_FORM_flag: | |
9646 | return "DW_FORM_flag"; | |
9647 | case DW_FORM_sdata: | |
9648 | return "DW_FORM_sdata"; | |
9649 | case DW_FORM_strp: | |
9650 | return "DW_FORM_strp"; | |
9651 | case DW_FORM_udata: | |
9652 | return "DW_FORM_udata"; | |
9653 | case DW_FORM_ref_addr: | |
9654 | return "DW_FORM_ref_addr"; | |
9655 | case DW_FORM_ref1: | |
9656 | return "DW_FORM_ref1"; | |
9657 | case DW_FORM_ref2: | |
9658 | return "DW_FORM_ref2"; | |
9659 | case DW_FORM_ref4: | |
9660 | return "DW_FORM_ref4"; | |
9661 | case DW_FORM_ref8: | |
9662 | return "DW_FORM_ref8"; | |
9663 | case DW_FORM_ref_udata: | |
9664 | return "DW_FORM_ref_udata"; | |
9665 | case DW_FORM_indirect: | |
9666 | return "DW_FORM_indirect"; | |
348e048f DE |
9667 | case DW_FORM_sec_offset: |
9668 | return "DW_FORM_sec_offset"; | |
9669 | case DW_FORM_exprloc: | |
9670 | return "DW_FORM_exprloc"; | |
9671 | case DW_FORM_flag_present: | |
9672 | return "DW_FORM_flag_present"; | |
9673 | case DW_FORM_sig8: | |
9674 | return "DW_FORM_sig8"; | |
c906108c SS |
9675 | default: |
9676 | return "DW_FORM_<unknown>"; | |
9677 | } | |
9678 | } | |
9679 | ||
9680 | /* Convert a DWARF stack opcode into its string name. */ | |
9681 | ||
9682 | static char * | |
aa1ee363 | 9683 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
9684 | { |
9685 | switch (op) | |
9686 | { | |
9687 | case DW_OP_addr: | |
9688 | return "DW_OP_addr"; | |
9689 | case DW_OP_deref: | |
9690 | return "DW_OP_deref"; | |
9691 | case DW_OP_const1u: | |
9692 | return "DW_OP_const1u"; | |
9693 | case DW_OP_const1s: | |
9694 | return "DW_OP_const1s"; | |
9695 | case DW_OP_const2u: | |
9696 | return "DW_OP_const2u"; | |
9697 | case DW_OP_const2s: | |
9698 | return "DW_OP_const2s"; | |
9699 | case DW_OP_const4u: | |
9700 | return "DW_OP_const4u"; | |
9701 | case DW_OP_const4s: | |
9702 | return "DW_OP_const4s"; | |
9703 | case DW_OP_const8u: | |
9704 | return "DW_OP_const8u"; | |
9705 | case DW_OP_const8s: | |
9706 | return "DW_OP_const8s"; | |
9707 | case DW_OP_constu: | |
9708 | return "DW_OP_constu"; | |
9709 | case DW_OP_consts: | |
9710 | return "DW_OP_consts"; | |
9711 | case DW_OP_dup: | |
9712 | return "DW_OP_dup"; | |
9713 | case DW_OP_drop: | |
9714 | return "DW_OP_drop"; | |
9715 | case DW_OP_over: | |
9716 | return "DW_OP_over"; | |
9717 | case DW_OP_pick: | |
9718 | return "DW_OP_pick"; | |
9719 | case DW_OP_swap: | |
9720 | return "DW_OP_swap"; | |
9721 | case DW_OP_rot: | |
9722 | return "DW_OP_rot"; | |
9723 | case DW_OP_xderef: | |
9724 | return "DW_OP_xderef"; | |
9725 | case DW_OP_abs: | |
9726 | return "DW_OP_abs"; | |
9727 | case DW_OP_and: | |
9728 | return "DW_OP_and"; | |
9729 | case DW_OP_div: | |
9730 | return "DW_OP_div"; | |
9731 | case DW_OP_minus: | |
9732 | return "DW_OP_minus"; | |
9733 | case DW_OP_mod: | |
9734 | return "DW_OP_mod"; | |
9735 | case DW_OP_mul: | |
9736 | return "DW_OP_mul"; | |
9737 | case DW_OP_neg: | |
9738 | return "DW_OP_neg"; | |
9739 | case DW_OP_not: | |
9740 | return "DW_OP_not"; | |
9741 | case DW_OP_or: | |
9742 | return "DW_OP_or"; | |
9743 | case DW_OP_plus: | |
9744 | return "DW_OP_plus"; | |
9745 | case DW_OP_plus_uconst: | |
9746 | return "DW_OP_plus_uconst"; | |
9747 | case DW_OP_shl: | |
9748 | return "DW_OP_shl"; | |
9749 | case DW_OP_shr: | |
9750 | return "DW_OP_shr"; | |
9751 | case DW_OP_shra: | |
9752 | return "DW_OP_shra"; | |
9753 | case DW_OP_xor: | |
9754 | return "DW_OP_xor"; | |
9755 | case DW_OP_bra: | |
9756 | return "DW_OP_bra"; | |
9757 | case DW_OP_eq: | |
9758 | return "DW_OP_eq"; | |
9759 | case DW_OP_ge: | |
9760 | return "DW_OP_ge"; | |
9761 | case DW_OP_gt: | |
9762 | return "DW_OP_gt"; | |
9763 | case DW_OP_le: | |
9764 | return "DW_OP_le"; | |
9765 | case DW_OP_lt: | |
9766 | return "DW_OP_lt"; | |
9767 | case DW_OP_ne: | |
9768 | return "DW_OP_ne"; | |
9769 | case DW_OP_skip: | |
9770 | return "DW_OP_skip"; | |
9771 | case DW_OP_lit0: | |
9772 | return "DW_OP_lit0"; | |
9773 | case DW_OP_lit1: | |
9774 | return "DW_OP_lit1"; | |
9775 | case DW_OP_lit2: | |
9776 | return "DW_OP_lit2"; | |
9777 | case DW_OP_lit3: | |
9778 | return "DW_OP_lit3"; | |
9779 | case DW_OP_lit4: | |
9780 | return "DW_OP_lit4"; | |
9781 | case DW_OP_lit5: | |
9782 | return "DW_OP_lit5"; | |
9783 | case DW_OP_lit6: | |
9784 | return "DW_OP_lit6"; | |
9785 | case DW_OP_lit7: | |
9786 | return "DW_OP_lit7"; | |
9787 | case DW_OP_lit8: | |
9788 | return "DW_OP_lit8"; | |
9789 | case DW_OP_lit9: | |
9790 | return "DW_OP_lit9"; | |
9791 | case DW_OP_lit10: | |
9792 | return "DW_OP_lit10"; | |
9793 | case DW_OP_lit11: | |
9794 | return "DW_OP_lit11"; | |
9795 | case DW_OP_lit12: | |
9796 | return "DW_OP_lit12"; | |
9797 | case DW_OP_lit13: | |
9798 | return "DW_OP_lit13"; | |
9799 | case DW_OP_lit14: | |
9800 | return "DW_OP_lit14"; | |
9801 | case DW_OP_lit15: | |
9802 | return "DW_OP_lit15"; | |
9803 | case DW_OP_lit16: | |
9804 | return "DW_OP_lit16"; | |
9805 | case DW_OP_lit17: | |
9806 | return "DW_OP_lit17"; | |
9807 | case DW_OP_lit18: | |
9808 | return "DW_OP_lit18"; | |
9809 | case DW_OP_lit19: | |
9810 | return "DW_OP_lit19"; | |
9811 | case DW_OP_lit20: | |
9812 | return "DW_OP_lit20"; | |
9813 | case DW_OP_lit21: | |
9814 | return "DW_OP_lit21"; | |
9815 | case DW_OP_lit22: | |
9816 | return "DW_OP_lit22"; | |
9817 | case DW_OP_lit23: | |
9818 | return "DW_OP_lit23"; | |
9819 | case DW_OP_lit24: | |
9820 | return "DW_OP_lit24"; | |
9821 | case DW_OP_lit25: | |
9822 | return "DW_OP_lit25"; | |
9823 | case DW_OP_lit26: | |
9824 | return "DW_OP_lit26"; | |
9825 | case DW_OP_lit27: | |
9826 | return "DW_OP_lit27"; | |
9827 | case DW_OP_lit28: | |
9828 | return "DW_OP_lit28"; | |
9829 | case DW_OP_lit29: | |
9830 | return "DW_OP_lit29"; | |
9831 | case DW_OP_lit30: | |
9832 | return "DW_OP_lit30"; | |
9833 | case DW_OP_lit31: | |
9834 | return "DW_OP_lit31"; | |
9835 | case DW_OP_reg0: | |
9836 | return "DW_OP_reg0"; | |
9837 | case DW_OP_reg1: | |
9838 | return "DW_OP_reg1"; | |
9839 | case DW_OP_reg2: | |
9840 | return "DW_OP_reg2"; | |
9841 | case DW_OP_reg3: | |
9842 | return "DW_OP_reg3"; | |
9843 | case DW_OP_reg4: | |
9844 | return "DW_OP_reg4"; | |
9845 | case DW_OP_reg5: | |
9846 | return "DW_OP_reg5"; | |
9847 | case DW_OP_reg6: | |
9848 | return "DW_OP_reg6"; | |
9849 | case DW_OP_reg7: | |
9850 | return "DW_OP_reg7"; | |
9851 | case DW_OP_reg8: | |
9852 | return "DW_OP_reg8"; | |
9853 | case DW_OP_reg9: | |
9854 | return "DW_OP_reg9"; | |
9855 | case DW_OP_reg10: | |
9856 | return "DW_OP_reg10"; | |
9857 | case DW_OP_reg11: | |
9858 | return "DW_OP_reg11"; | |
9859 | case DW_OP_reg12: | |
9860 | return "DW_OP_reg12"; | |
9861 | case DW_OP_reg13: | |
9862 | return "DW_OP_reg13"; | |
9863 | case DW_OP_reg14: | |
9864 | return "DW_OP_reg14"; | |
9865 | case DW_OP_reg15: | |
9866 | return "DW_OP_reg15"; | |
9867 | case DW_OP_reg16: | |
9868 | return "DW_OP_reg16"; | |
9869 | case DW_OP_reg17: | |
9870 | return "DW_OP_reg17"; | |
9871 | case DW_OP_reg18: | |
9872 | return "DW_OP_reg18"; | |
9873 | case DW_OP_reg19: | |
9874 | return "DW_OP_reg19"; | |
9875 | case DW_OP_reg20: | |
9876 | return "DW_OP_reg20"; | |
9877 | case DW_OP_reg21: | |
9878 | return "DW_OP_reg21"; | |
9879 | case DW_OP_reg22: | |
9880 | return "DW_OP_reg22"; | |
9881 | case DW_OP_reg23: | |
9882 | return "DW_OP_reg23"; | |
9883 | case DW_OP_reg24: | |
9884 | return "DW_OP_reg24"; | |
9885 | case DW_OP_reg25: | |
9886 | return "DW_OP_reg25"; | |
9887 | case DW_OP_reg26: | |
9888 | return "DW_OP_reg26"; | |
9889 | case DW_OP_reg27: | |
9890 | return "DW_OP_reg27"; | |
9891 | case DW_OP_reg28: | |
9892 | return "DW_OP_reg28"; | |
9893 | case DW_OP_reg29: | |
9894 | return "DW_OP_reg29"; | |
9895 | case DW_OP_reg30: | |
9896 | return "DW_OP_reg30"; | |
9897 | case DW_OP_reg31: | |
9898 | return "DW_OP_reg31"; | |
9899 | case DW_OP_breg0: | |
9900 | return "DW_OP_breg0"; | |
9901 | case DW_OP_breg1: | |
9902 | return "DW_OP_breg1"; | |
9903 | case DW_OP_breg2: | |
9904 | return "DW_OP_breg2"; | |
9905 | case DW_OP_breg3: | |
9906 | return "DW_OP_breg3"; | |
9907 | case DW_OP_breg4: | |
9908 | return "DW_OP_breg4"; | |
9909 | case DW_OP_breg5: | |
9910 | return "DW_OP_breg5"; | |
9911 | case DW_OP_breg6: | |
9912 | return "DW_OP_breg6"; | |
9913 | case DW_OP_breg7: | |
9914 | return "DW_OP_breg7"; | |
9915 | case DW_OP_breg8: | |
9916 | return "DW_OP_breg8"; | |
9917 | case DW_OP_breg9: | |
9918 | return "DW_OP_breg9"; | |
9919 | case DW_OP_breg10: | |
9920 | return "DW_OP_breg10"; | |
9921 | case DW_OP_breg11: | |
9922 | return "DW_OP_breg11"; | |
9923 | case DW_OP_breg12: | |
9924 | return "DW_OP_breg12"; | |
9925 | case DW_OP_breg13: | |
9926 | return "DW_OP_breg13"; | |
9927 | case DW_OP_breg14: | |
9928 | return "DW_OP_breg14"; | |
9929 | case DW_OP_breg15: | |
9930 | return "DW_OP_breg15"; | |
9931 | case DW_OP_breg16: | |
9932 | return "DW_OP_breg16"; | |
9933 | case DW_OP_breg17: | |
9934 | return "DW_OP_breg17"; | |
9935 | case DW_OP_breg18: | |
9936 | return "DW_OP_breg18"; | |
9937 | case DW_OP_breg19: | |
9938 | return "DW_OP_breg19"; | |
9939 | case DW_OP_breg20: | |
9940 | return "DW_OP_breg20"; | |
9941 | case DW_OP_breg21: | |
9942 | return "DW_OP_breg21"; | |
9943 | case DW_OP_breg22: | |
9944 | return "DW_OP_breg22"; | |
9945 | case DW_OP_breg23: | |
9946 | return "DW_OP_breg23"; | |
9947 | case DW_OP_breg24: | |
9948 | return "DW_OP_breg24"; | |
9949 | case DW_OP_breg25: | |
9950 | return "DW_OP_breg25"; | |
9951 | case DW_OP_breg26: | |
9952 | return "DW_OP_breg26"; | |
9953 | case DW_OP_breg27: | |
9954 | return "DW_OP_breg27"; | |
9955 | case DW_OP_breg28: | |
9956 | return "DW_OP_breg28"; | |
9957 | case DW_OP_breg29: | |
9958 | return "DW_OP_breg29"; | |
9959 | case DW_OP_breg30: | |
9960 | return "DW_OP_breg30"; | |
9961 | case DW_OP_breg31: | |
9962 | return "DW_OP_breg31"; | |
9963 | case DW_OP_regx: | |
9964 | return "DW_OP_regx"; | |
9965 | case DW_OP_fbreg: | |
9966 | return "DW_OP_fbreg"; | |
9967 | case DW_OP_bregx: | |
9968 | return "DW_OP_bregx"; | |
9969 | case DW_OP_piece: | |
9970 | return "DW_OP_piece"; | |
9971 | case DW_OP_deref_size: | |
9972 | return "DW_OP_deref_size"; | |
9973 | case DW_OP_xderef_size: | |
9974 | return "DW_OP_xderef_size"; | |
9975 | case DW_OP_nop: | |
9976 | return "DW_OP_nop"; | |
b7619582 | 9977 | /* DWARF 3 extensions. */ |
ed348acc EZ |
9978 | case DW_OP_push_object_address: |
9979 | return "DW_OP_push_object_address"; | |
9980 | case DW_OP_call2: | |
9981 | return "DW_OP_call2"; | |
9982 | case DW_OP_call4: | |
9983 | return "DW_OP_call4"; | |
9984 | case DW_OP_call_ref: | |
9985 | return "DW_OP_call_ref"; | |
b7619582 GF |
9986 | /* GNU extensions. */ |
9987 | case DW_OP_form_tls_address: | |
9988 | return "DW_OP_form_tls_address"; | |
9989 | case DW_OP_call_frame_cfa: | |
9990 | return "DW_OP_call_frame_cfa"; | |
9991 | case DW_OP_bit_piece: | |
9992 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
9993 | case DW_OP_GNU_push_tls_address: |
9994 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
9995 | case DW_OP_GNU_uninit: |
9996 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
9997 | /* HP extensions. */ |
9998 | case DW_OP_HP_is_value: | |
9999 | return "DW_OP_HP_is_value"; | |
10000 | case DW_OP_HP_fltconst4: | |
10001 | return "DW_OP_HP_fltconst4"; | |
10002 | case DW_OP_HP_fltconst8: | |
10003 | return "DW_OP_HP_fltconst8"; | |
10004 | case DW_OP_HP_mod_range: | |
10005 | return "DW_OP_HP_mod_range"; | |
10006 | case DW_OP_HP_unmod_range: | |
10007 | return "DW_OP_HP_unmod_range"; | |
10008 | case DW_OP_HP_tls: | |
10009 | return "DW_OP_HP_tls"; | |
c906108c SS |
10010 | default: |
10011 | return "OP_<unknown>"; | |
10012 | } | |
10013 | } | |
10014 | ||
10015 | static char * | |
fba45db2 | 10016 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
10017 | { |
10018 | if (mybool) | |
10019 | return "TRUE"; | |
10020 | else | |
10021 | return "FALSE"; | |
10022 | } | |
10023 | ||
10024 | /* Convert a DWARF type code into its string name. */ | |
10025 | ||
10026 | static char * | |
aa1ee363 | 10027 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
10028 | { |
10029 | switch (enc) | |
10030 | { | |
b7619582 GF |
10031 | case DW_ATE_void: |
10032 | return "DW_ATE_void"; | |
c906108c SS |
10033 | case DW_ATE_address: |
10034 | return "DW_ATE_address"; | |
10035 | case DW_ATE_boolean: | |
10036 | return "DW_ATE_boolean"; | |
10037 | case DW_ATE_complex_float: | |
10038 | return "DW_ATE_complex_float"; | |
10039 | case DW_ATE_float: | |
10040 | return "DW_ATE_float"; | |
10041 | case DW_ATE_signed: | |
10042 | return "DW_ATE_signed"; | |
10043 | case DW_ATE_signed_char: | |
10044 | return "DW_ATE_signed_char"; | |
10045 | case DW_ATE_unsigned: | |
10046 | return "DW_ATE_unsigned"; | |
10047 | case DW_ATE_unsigned_char: | |
10048 | return "DW_ATE_unsigned_char"; | |
b7619582 | 10049 | /* DWARF 3. */ |
d9fa45fe DC |
10050 | case DW_ATE_imaginary_float: |
10051 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
10052 | case DW_ATE_packed_decimal: |
10053 | return "DW_ATE_packed_decimal"; | |
10054 | case DW_ATE_numeric_string: | |
10055 | return "DW_ATE_numeric_string"; | |
10056 | case DW_ATE_edited: | |
10057 | return "DW_ATE_edited"; | |
10058 | case DW_ATE_signed_fixed: | |
10059 | return "DW_ATE_signed_fixed"; | |
10060 | case DW_ATE_unsigned_fixed: | |
10061 | return "DW_ATE_unsigned_fixed"; | |
10062 | case DW_ATE_decimal_float: | |
10063 | return "DW_ATE_decimal_float"; | |
10064 | /* HP extensions. */ | |
10065 | case DW_ATE_HP_float80: | |
10066 | return "DW_ATE_HP_float80"; | |
10067 | case DW_ATE_HP_complex_float80: | |
10068 | return "DW_ATE_HP_complex_float80"; | |
10069 | case DW_ATE_HP_float128: | |
10070 | return "DW_ATE_HP_float128"; | |
10071 | case DW_ATE_HP_complex_float128: | |
10072 | return "DW_ATE_HP_complex_float128"; | |
10073 | case DW_ATE_HP_floathpintel: | |
10074 | return "DW_ATE_HP_floathpintel"; | |
10075 | case DW_ATE_HP_imaginary_float80: | |
10076 | return "DW_ATE_HP_imaginary_float80"; | |
10077 | case DW_ATE_HP_imaginary_float128: | |
10078 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
10079 | default: |
10080 | return "DW_ATE_<unknown>"; | |
10081 | } | |
10082 | } | |
10083 | ||
10084 | /* Convert a DWARF call frame info operation to its string name. */ | |
10085 | ||
10086 | #if 0 | |
10087 | static char * | |
aa1ee363 | 10088 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
10089 | { |
10090 | switch (cfi_opc) | |
10091 | { | |
10092 | case DW_CFA_advance_loc: | |
10093 | return "DW_CFA_advance_loc"; | |
10094 | case DW_CFA_offset: | |
10095 | return "DW_CFA_offset"; | |
10096 | case DW_CFA_restore: | |
10097 | return "DW_CFA_restore"; | |
10098 | case DW_CFA_nop: | |
10099 | return "DW_CFA_nop"; | |
10100 | case DW_CFA_set_loc: | |
10101 | return "DW_CFA_set_loc"; | |
10102 | case DW_CFA_advance_loc1: | |
10103 | return "DW_CFA_advance_loc1"; | |
10104 | case DW_CFA_advance_loc2: | |
10105 | return "DW_CFA_advance_loc2"; | |
10106 | case DW_CFA_advance_loc4: | |
10107 | return "DW_CFA_advance_loc4"; | |
10108 | case DW_CFA_offset_extended: | |
10109 | return "DW_CFA_offset_extended"; | |
10110 | case DW_CFA_restore_extended: | |
10111 | return "DW_CFA_restore_extended"; | |
10112 | case DW_CFA_undefined: | |
10113 | return "DW_CFA_undefined"; | |
10114 | case DW_CFA_same_value: | |
10115 | return "DW_CFA_same_value"; | |
10116 | case DW_CFA_register: | |
10117 | return "DW_CFA_register"; | |
10118 | case DW_CFA_remember_state: | |
10119 | return "DW_CFA_remember_state"; | |
10120 | case DW_CFA_restore_state: | |
10121 | return "DW_CFA_restore_state"; | |
10122 | case DW_CFA_def_cfa: | |
10123 | return "DW_CFA_def_cfa"; | |
10124 | case DW_CFA_def_cfa_register: | |
10125 | return "DW_CFA_def_cfa_register"; | |
10126 | case DW_CFA_def_cfa_offset: | |
10127 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 10128 | /* DWARF 3. */ |
985cb1a3 JM |
10129 | case DW_CFA_def_cfa_expression: |
10130 | return "DW_CFA_def_cfa_expression"; | |
10131 | case DW_CFA_expression: | |
10132 | return "DW_CFA_expression"; | |
10133 | case DW_CFA_offset_extended_sf: | |
10134 | return "DW_CFA_offset_extended_sf"; | |
10135 | case DW_CFA_def_cfa_sf: | |
10136 | return "DW_CFA_def_cfa_sf"; | |
10137 | case DW_CFA_def_cfa_offset_sf: | |
10138 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
10139 | case DW_CFA_val_offset: |
10140 | return "DW_CFA_val_offset"; | |
10141 | case DW_CFA_val_offset_sf: | |
10142 | return "DW_CFA_val_offset_sf"; | |
10143 | case DW_CFA_val_expression: | |
10144 | return "DW_CFA_val_expression"; | |
10145 | /* SGI/MIPS specific. */ | |
c906108c SS |
10146 | case DW_CFA_MIPS_advance_loc8: |
10147 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 10148 | /* GNU extensions. */ |
985cb1a3 JM |
10149 | case DW_CFA_GNU_window_save: |
10150 | return "DW_CFA_GNU_window_save"; | |
10151 | case DW_CFA_GNU_args_size: | |
10152 | return "DW_CFA_GNU_args_size"; | |
10153 | case DW_CFA_GNU_negative_offset_extended: | |
10154 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
10155 | default: |
10156 | return "DW_CFA_<unknown>"; | |
10157 | } | |
10158 | } | |
10159 | #endif | |
10160 | ||
f9aca02d | 10161 | static void |
d97bc12b | 10162 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
10163 | { |
10164 | unsigned int i; | |
10165 | ||
d97bc12b DE |
10166 | print_spaces (indent, f); |
10167 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 10168 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
10169 | |
10170 | if (die->parent != NULL) | |
10171 | { | |
10172 | print_spaces (indent, f); | |
10173 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
10174 | die->parent->offset); | |
10175 | } | |
10176 | ||
10177 | print_spaces (indent, f); | |
10178 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 10179 | dwarf_bool_name (die->child != NULL)); |
c906108c | 10180 | |
d97bc12b DE |
10181 | print_spaces (indent, f); |
10182 | fprintf_unfiltered (f, " attributes:\n"); | |
10183 | ||
c906108c SS |
10184 | for (i = 0; i < die->num_attrs; ++i) |
10185 | { | |
d97bc12b DE |
10186 | print_spaces (indent, f); |
10187 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
10188 | dwarf_attr_name (die->attrs[i].name), |
10189 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 10190 | |
c906108c SS |
10191 | switch (die->attrs[i].form) |
10192 | { | |
10193 | case DW_FORM_ref_addr: | |
10194 | case DW_FORM_addr: | |
d97bc12b | 10195 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 10196 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
10197 | break; |
10198 | case DW_FORM_block2: | |
10199 | case DW_FORM_block4: | |
10200 | case DW_FORM_block: | |
10201 | case DW_FORM_block1: | |
d97bc12b | 10202 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 10203 | break; |
10b3939b DJ |
10204 | case DW_FORM_ref1: |
10205 | case DW_FORM_ref2: | |
10206 | case DW_FORM_ref4: | |
d97bc12b | 10207 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
10208 | (long) (DW_ADDR (&die->attrs[i]))); |
10209 | break; | |
c906108c SS |
10210 | case DW_FORM_data1: |
10211 | case DW_FORM_data2: | |
10212 | case DW_FORM_data4: | |
ce5d95e1 | 10213 | case DW_FORM_data8: |
c906108c SS |
10214 | case DW_FORM_udata: |
10215 | case DW_FORM_sdata: | |
43bbcdc2 PH |
10216 | fprintf_unfiltered (f, "constant: %s", |
10217 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 10218 | break; |
348e048f DE |
10219 | case DW_FORM_sig8: |
10220 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
10221 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
10222 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
10223 | else | |
10224 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
10225 | break; | |
c906108c | 10226 | case DW_FORM_string: |
4bdf3d34 | 10227 | case DW_FORM_strp: |
8285870a | 10228 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 10229 | DW_STRING (&die->attrs[i]) |
8285870a JK |
10230 | ? DW_STRING (&die->attrs[i]) : "", |
10231 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
10232 | break; |
10233 | case DW_FORM_flag: | |
10234 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 10235 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 10236 | else |
d97bc12b | 10237 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 10238 | break; |
a8329558 KW |
10239 | case DW_FORM_indirect: |
10240 | /* the reader will have reduced the indirect form to | |
10241 | the "base form" so this form should not occur */ | |
d97bc12b | 10242 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 10243 | break; |
c906108c | 10244 | default: |
d97bc12b | 10245 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 10246 | die->attrs[i].form); |
d97bc12b | 10247 | break; |
c906108c | 10248 | } |
d97bc12b | 10249 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
10250 | } |
10251 | } | |
10252 | ||
f9aca02d | 10253 | static void |
d97bc12b | 10254 | dump_die_for_error (struct die_info *die) |
c906108c | 10255 | { |
d97bc12b DE |
10256 | dump_die_shallow (gdb_stderr, 0, die); |
10257 | } | |
10258 | ||
10259 | static void | |
10260 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
10261 | { | |
10262 | int indent = level * 4; | |
10263 | ||
10264 | gdb_assert (die != NULL); | |
10265 | ||
10266 | if (level >= max_level) | |
10267 | return; | |
10268 | ||
10269 | dump_die_shallow (f, indent, die); | |
10270 | ||
10271 | if (die->child != NULL) | |
c906108c | 10272 | { |
d97bc12b DE |
10273 | print_spaces (indent, f); |
10274 | fprintf_unfiltered (f, " Children:"); | |
10275 | if (level + 1 < max_level) | |
10276 | { | |
10277 | fprintf_unfiltered (f, "\n"); | |
10278 | dump_die_1 (f, level + 1, max_level, die->child); | |
10279 | } | |
10280 | else | |
10281 | { | |
10282 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
10283 | } | |
10284 | } | |
10285 | ||
10286 | if (die->sibling != NULL && level > 0) | |
10287 | { | |
10288 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
10289 | } |
10290 | } | |
10291 | ||
d97bc12b DE |
10292 | /* This is called from the pdie macro in gdbinit.in. |
10293 | It's not static so gcc will keep a copy callable from gdb. */ | |
10294 | ||
10295 | void | |
10296 | dump_die (struct die_info *die, int max_level) | |
10297 | { | |
10298 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
10299 | } | |
10300 | ||
f9aca02d | 10301 | static void |
51545339 | 10302 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10303 | { |
51545339 | 10304 | void **slot; |
c906108c | 10305 | |
51545339 DJ |
10306 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
10307 | ||
10308 | *slot = die; | |
c906108c SS |
10309 | } |
10310 | ||
93311388 DE |
10311 | static int |
10312 | is_ref_attr (struct attribute *attr) | |
c906108c | 10313 | { |
c906108c SS |
10314 | switch (attr->form) |
10315 | { | |
10316 | case DW_FORM_ref_addr: | |
c906108c SS |
10317 | case DW_FORM_ref1: |
10318 | case DW_FORM_ref2: | |
10319 | case DW_FORM_ref4: | |
613e1657 | 10320 | case DW_FORM_ref8: |
c906108c | 10321 | case DW_FORM_ref_udata: |
93311388 | 10322 | return 1; |
c906108c | 10323 | default: |
93311388 | 10324 | return 0; |
c906108c | 10325 | } |
93311388 DE |
10326 | } |
10327 | ||
10328 | static unsigned int | |
10329 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
10330 | { | |
10331 | if (is_ref_attr (attr)) | |
10332 | return DW_ADDR (attr); | |
10333 | ||
10334 | complaint (&symfile_complaints, | |
10335 | _("unsupported die ref attribute form: '%s'"), | |
10336 | dwarf_form_name (attr->form)); | |
10337 | return 0; | |
c906108c SS |
10338 | } |
10339 | ||
43bbcdc2 PH |
10340 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
10341 | * the value held by the attribute is not constant. */ | |
a02abb62 | 10342 | |
43bbcdc2 | 10343 | static LONGEST |
a02abb62 JB |
10344 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
10345 | { | |
10346 | if (attr->form == DW_FORM_sdata) | |
10347 | return DW_SND (attr); | |
10348 | else if (attr->form == DW_FORM_udata | |
10349 | || attr->form == DW_FORM_data1 | |
10350 | || attr->form == DW_FORM_data2 | |
10351 | || attr->form == DW_FORM_data4 | |
10352 | || attr->form == DW_FORM_data8) | |
10353 | return DW_UNSND (attr); | |
10354 | else | |
10355 | { | |
e2e0b3e5 | 10356 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
10357 | dwarf_form_name (attr->form)); |
10358 | return default_value; | |
10359 | } | |
10360 | } | |
10361 | ||
03dd20cc | 10362 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
10363 | unit and add it to our queue. |
10364 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
10365 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 10366 | |
348e048f | 10367 | static int |
03dd20cc DJ |
10368 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
10369 | struct dwarf2_per_cu_data *per_cu) | |
10370 | { | |
10371 | /* Mark the dependence relation so that we don't flush PER_CU | |
10372 | too early. */ | |
10373 | dwarf2_add_dependence (this_cu, per_cu); | |
10374 | ||
10375 | /* If it's already on the queue, we have nothing to do. */ | |
10376 | if (per_cu->queued) | |
348e048f | 10377 | return 0; |
03dd20cc DJ |
10378 | |
10379 | /* If the compilation unit is already loaded, just mark it as | |
10380 | used. */ | |
10381 | if (per_cu->cu != NULL) | |
10382 | { | |
10383 | per_cu->cu->last_used = 0; | |
348e048f | 10384 | return 0; |
03dd20cc DJ |
10385 | } |
10386 | ||
10387 | /* Add it to the queue. */ | |
10388 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
10389 | |
10390 | return 1; | |
10391 | } | |
10392 | ||
10393 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
10394 | On entry *REF_CU is the CU of SRC_DIE. | |
10395 | On exit *REF_CU is the CU of the result. */ | |
10396 | ||
10397 | static struct die_info * | |
10398 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
10399 | struct dwarf2_cu **ref_cu) | |
10400 | { | |
10401 | struct die_info *die; | |
10402 | ||
10403 | if (is_ref_attr (attr)) | |
10404 | die = follow_die_ref (src_die, attr, ref_cu); | |
10405 | else if (attr->form == DW_FORM_sig8) | |
10406 | die = follow_die_sig (src_die, attr, ref_cu); | |
10407 | else | |
10408 | { | |
10409 | dump_die_for_error (src_die); | |
10410 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
10411 | (*ref_cu)->objfile->name); | |
10412 | } | |
10413 | ||
10414 | return die; | |
03dd20cc DJ |
10415 | } |
10416 | ||
f504f079 DE |
10417 | /* Follow reference attribute ATTR of SRC_DIE. |
10418 | On entry *REF_CU is the CU of SRC_DIE. | |
10419 | On exit *REF_CU is the CU of the result. */ | |
10420 | ||
f9aca02d | 10421 | static struct die_info * |
10b3939b | 10422 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 10423 | struct dwarf2_cu **ref_cu) |
c906108c SS |
10424 | { |
10425 | struct die_info *die; | |
10b3939b | 10426 | unsigned int offset; |
10b3939b | 10427 | struct die_info temp_die; |
f2f0e013 | 10428 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 10429 | |
348e048f DE |
10430 | gdb_assert (cu->per_cu != NULL); |
10431 | ||
c764a876 | 10432 | offset = dwarf2_get_ref_die_offset (attr); |
10b3939b | 10433 | |
348e048f DE |
10434 | if (cu->per_cu->from_debug_types) |
10435 | { | |
10436 | /* .debug_types CUs cannot reference anything outside their CU. | |
10437 | If they need to, they have to reference a signatured type via | |
10438 | DW_FORM_sig8. */ | |
10439 | if (! offset_in_cu_p (&cu->header, offset)) | |
10440 | goto not_found; | |
10441 | target_cu = cu; | |
10442 | } | |
10443 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
10444 | { |
10445 | struct dwarf2_per_cu_data *per_cu; | |
45452591 | 10446 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
10447 | |
10448 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
10449 | if (maybe_queue_comp_unit (cu, per_cu)) |
10450 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 10451 | |
10b3939b DJ |
10452 | target_cu = per_cu->cu; |
10453 | } | |
10454 | else | |
10455 | target_cu = cu; | |
c906108c | 10456 | |
f2f0e013 | 10457 | *ref_cu = target_cu; |
51545339 DJ |
10458 | temp_die.offset = offset; |
10459 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
10460 | if (die) | |
10461 | return die; | |
10b3939b | 10462 | |
348e048f DE |
10463 | not_found: |
10464 | ||
10465 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
10466 | "at 0x%x [in module %s]"), | |
10467 | offset, src_die->offset, cu->objfile->name); | |
10468 | } | |
10469 | ||
10470 | /* Follow the signature attribute ATTR in SRC_DIE. | |
10471 | On entry *REF_CU is the CU of SRC_DIE. | |
10472 | On exit *REF_CU is the CU of the result. */ | |
10473 | ||
10474 | static struct die_info * | |
10475 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
10476 | struct dwarf2_cu **ref_cu) | |
10477 | { | |
10478 | struct objfile *objfile = (*ref_cu)->objfile; | |
10479 | struct die_info temp_die; | |
10480 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
10481 | struct dwarf2_cu *sig_cu; | |
10482 | struct die_info *die; | |
10483 | ||
10484 | /* sig_type will be NULL if the signatured type is missing from | |
10485 | the debug info. */ | |
10486 | if (sig_type == NULL) | |
10487 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
10488 | "at 0x%x [in module %s]"), | |
10489 | src_die->offset, objfile->name); | |
10490 | ||
10491 | /* If necessary, add it to the queue and load its DIEs. */ | |
10492 | ||
10493 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
10494 | read_signatured_type (objfile, sig_type); | |
10495 | ||
10496 | gdb_assert (sig_type->per_cu.cu != NULL); | |
10497 | ||
10498 | sig_cu = sig_type->per_cu.cu; | |
10499 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
10500 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
10501 | if (die) | |
10502 | { | |
10503 | *ref_cu = sig_cu; | |
10504 | return die; | |
10505 | } | |
10506 | ||
10507 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
10508 | "at 0x%x [in module %s]"), | |
10509 | sig_type->type_offset, src_die->offset, objfile->name); | |
10510 | } | |
10511 | ||
10512 | /* Given an offset of a signatured type, return its signatured_type. */ | |
10513 | ||
10514 | static struct signatured_type * | |
10515 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
10516 | { | |
10517 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
10518 | unsigned int length, initial_length_size; | |
10519 | unsigned int sig_offset; | |
10520 | struct signatured_type find_entry, *type_sig; | |
10521 | ||
10522 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
10523 | sig_offset = (initial_length_size | |
10524 | + 2 /*version*/ | |
10525 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
10526 | + 1 /*address_size*/); | |
10527 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
10528 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
10529 | ||
10530 | /* This is only used to lookup previously recorded types. | |
10531 | If we didn't find it, it's our bug. */ | |
10532 | gdb_assert (type_sig != NULL); | |
10533 | gdb_assert (offset == type_sig->offset); | |
10534 | ||
10535 | return type_sig; | |
10536 | } | |
10537 | ||
10538 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
10539 | ||
10540 | static void | |
10541 | read_signatured_type_at_offset (struct objfile *objfile, | |
10542 | unsigned int offset) | |
10543 | { | |
10544 | struct signatured_type *type_sig; | |
10545 | ||
10546 | /* We have the section offset, but we need the signature to do the | |
10547 | hash table lookup. */ | |
10548 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
10549 | ||
10550 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10551 | ||
10552 | read_signatured_type (objfile, type_sig); | |
10553 | ||
10554 | gdb_assert (type_sig->per_cu.cu != NULL); | |
10555 | } | |
10556 | ||
10557 | /* Read in a signatured type and build its CU and DIEs. */ | |
10558 | ||
10559 | static void | |
10560 | read_signatured_type (struct objfile *objfile, | |
10561 | struct signatured_type *type_sig) | |
10562 | { | |
10563 | gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
10564 | struct die_reader_specs reader_specs; | |
10565 | struct dwarf2_cu *cu; | |
10566 | ULONGEST signature; | |
10567 | struct cleanup *back_to, *free_cu_cleanup; | |
10568 | struct attribute *attr; | |
10569 | ||
10570 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10571 | ||
10572 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
10573 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
10574 | obstack_init (&cu->comp_unit_obstack); | |
10575 | cu->objfile = objfile; | |
10576 | type_sig->per_cu.cu = cu; | |
10577 | cu->per_cu = &type_sig->per_cu; | |
10578 | ||
10579 | /* If an error occurs while loading, release our storage. */ | |
10580 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
10581 | ||
10582 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
10583 | types_ptr, objfile->obfd); | |
10584 | gdb_assert (signature == type_sig->signature); | |
10585 | ||
10586 | cu->die_hash | |
10587 | = htab_create_alloc_ex (cu->header.length / 12, | |
10588 | die_hash, | |
10589 | die_eq, | |
10590 | NULL, | |
10591 | &cu->comp_unit_obstack, | |
10592 | hashtab_obstack_allocate, | |
10593 | dummy_obstack_deallocate); | |
10594 | ||
10595 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
10596 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10597 | ||
10598 | init_cu_die_reader (&reader_specs, cu); | |
10599 | ||
10600 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
10601 | NULL /*parent*/); | |
10602 | ||
10603 | /* We try not to read any attributes in this function, because not | |
10604 | all objfiles needed for references have been loaded yet, and symbol | |
10605 | table processing isn't initialized. But we have to set the CU language, | |
10606 | or we won't be able to build types correctly. */ | |
10607 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
10608 | if (attr) | |
10609 | set_cu_language (DW_UNSND (attr), cu); | |
10610 | else | |
10611 | set_cu_language (language_minimal, cu); | |
10612 | ||
10613 | do_cleanups (back_to); | |
10614 | ||
10615 | /* We've successfully allocated this compilation unit. Let our caller | |
10616 | clean it up when finished with it. */ | |
10617 | discard_cleanups (free_cu_cleanup); | |
10618 | ||
10619 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
10620 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
10621 | } |
10622 | ||
c906108c SS |
10623 | /* Decode simple location descriptions. |
10624 | Given a pointer to a dwarf block that defines a location, compute | |
10625 | the location and return the value. | |
10626 | ||
4cecd739 DJ |
10627 | NOTE drow/2003-11-18: This function is called in two situations |
10628 | now: for the address of static or global variables (partial symbols | |
10629 | only) and for offsets into structures which are expected to be | |
10630 | (more or less) constant. The partial symbol case should go away, | |
10631 | and only the constant case should remain. That will let this | |
10632 | function complain more accurately. A few special modes are allowed | |
10633 | without complaint for global variables (for instance, global | |
10634 | register values and thread-local values). | |
c906108c SS |
10635 | |
10636 | A location description containing no operations indicates that the | |
4cecd739 | 10637 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
10638 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
10639 | callers will only want a very basic result and this can become a | |
10640 | complaint. | |
c906108c | 10641 | |
c906108c SS |
10642 | Note that stack[0] is unused except as a default error return. |
10643 | Note that stack overflow is not yet handled. */ | |
10644 | ||
10645 | static CORE_ADDR | |
e7c27a73 | 10646 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 10647 | { |
e7c27a73 DJ |
10648 | struct objfile *objfile = cu->objfile; |
10649 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
10650 | int i; |
10651 | int size = blk->size; | |
fe1b8b76 | 10652 | gdb_byte *data = blk->data; |
c906108c SS |
10653 | CORE_ADDR stack[64]; |
10654 | int stacki; | |
10655 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 10656 | gdb_byte op; |
c906108c SS |
10657 | |
10658 | i = 0; | |
10659 | stacki = 0; | |
10660 | stack[stacki] = 0; | |
c906108c SS |
10661 | |
10662 | while (i < size) | |
10663 | { | |
c906108c SS |
10664 | op = data[i++]; |
10665 | switch (op) | |
10666 | { | |
f1bea926 JM |
10667 | case DW_OP_lit0: |
10668 | case DW_OP_lit1: | |
10669 | case DW_OP_lit2: | |
10670 | case DW_OP_lit3: | |
10671 | case DW_OP_lit4: | |
10672 | case DW_OP_lit5: | |
10673 | case DW_OP_lit6: | |
10674 | case DW_OP_lit7: | |
10675 | case DW_OP_lit8: | |
10676 | case DW_OP_lit9: | |
10677 | case DW_OP_lit10: | |
10678 | case DW_OP_lit11: | |
10679 | case DW_OP_lit12: | |
10680 | case DW_OP_lit13: | |
10681 | case DW_OP_lit14: | |
10682 | case DW_OP_lit15: | |
10683 | case DW_OP_lit16: | |
10684 | case DW_OP_lit17: | |
10685 | case DW_OP_lit18: | |
10686 | case DW_OP_lit19: | |
10687 | case DW_OP_lit20: | |
10688 | case DW_OP_lit21: | |
10689 | case DW_OP_lit22: | |
10690 | case DW_OP_lit23: | |
10691 | case DW_OP_lit24: | |
10692 | case DW_OP_lit25: | |
10693 | case DW_OP_lit26: | |
10694 | case DW_OP_lit27: | |
10695 | case DW_OP_lit28: | |
10696 | case DW_OP_lit29: | |
10697 | case DW_OP_lit30: | |
10698 | case DW_OP_lit31: | |
10699 | stack[++stacki] = op - DW_OP_lit0; | |
10700 | break; | |
10701 | ||
c906108c SS |
10702 | case DW_OP_reg0: |
10703 | case DW_OP_reg1: | |
10704 | case DW_OP_reg2: | |
10705 | case DW_OP_reg3: | |
10706 | case DW_OP_reg4: | |
10707 | case DW_OP_reg5: | |
10708 | case DW_OP_reg6: | |
10709 | case DW_OP_reg7: | |
10710 | case DW_OP_reg8: | |
10711 | case DW_OP_reg9: | |
10712 | case DW_OP_reg10: | |
10713 | case DW_OP_reg11: | |
10714 | case DW_OP_reg12: | |
10715 | case DW_OP_reg13: | |
10716 | case DW_OP_reg14: | |
10717 | case DW_OP_reg15: | |
10718 | case DW_OP_reg16: | |
10719 | case DW_OP_reg17: | |
10720 | case DW_OP_reg18: | |
10721 | case DW_OP_reg19: | |
10722 | case DW_OP_reg20: | |
10723 | case DW_OP_reg21: | |
10724 | case DW_OP_reg22: | |
10725 | case DW_OP_reg23: | |
10726 | case DW_OP_reg24: | |
10727 | case DW_OP_reg25: | |
10728 | case DW_OP_reg26: | |
10729 | case DW_OP_reg27: | |
10730 | case DW_OP_reg28: | |
10731 | case DW_OP_reg29: | |
10732 | case DW_OP_reg30: | |
10733 | case DW_OP_reg31: | |
c906108c | 10734 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
10735 | if (i < size) |
10736 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10737 | break; |
10738 | ||
10739 | case DW_OP_regx: | |
c906108c SS |
10740 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
10741 | i += bytes_read; | |
c906108c | 10742 | stack[++stacki] = unsnd; |
4cecd739 DJ |
10743 | if (i < size) |
10744 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10745 | break; |
10746 | ||
10747 | case DW_OP_addr: | |
107d2387 | 10748 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 10749 | cu, &bytes_read); |
107d2387 | 10750 | i += bytes_read; |
c906108c SS |
10751 | break; |
10752 | ||
10753 | case DW_OP_const1u: | |
10754 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
10755 | i += 1; | |
10756 | break; | |
10757 | ||
10758 | case DW_OP_const1s: | |
10759 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
10760 | i += 1; | |
10761 | break; | |
10762 | ||
10763 | case DW_OP_const2u: | |
10764 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
10765 | i += 2; | |
10766 | break; | |
10767 | ||
10768 | case DW_OP_const2s: | |
10769 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
10770 | i += 2; | |
10771 | break; | |
10772 | ||
10773 | case DW_OP_const4u: | |
10774 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
10775 | i += 4; | |
10776 | break; | |
10777 | ||
10778 | case DW_OP_const4s: | |
10779 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
10780 | i += 4; | |
10781 | break; | |
10782 | ||
10783 | case DW_OP_constu: | |
10784 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 10785 | &bytes_read); |
c906108c SS |
10786 | i += bytes_read; |
10787 | break; | |
10788 | ||
10789 | case DW_OP_consts: | |
10790 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
10791 | i += bytes_read; | |
10792 | break; | |
10793 | ||
f1bea926 JM |
10794 | case DW_OP_dup: |
10795 | stack[stacki + 1] = stack[stacki]; | |
10796 | stacki++; | |
10797 | break; | |
10798 | ||
c906108c SS |
10799 | case DW_OP_plus: |
10800 | stack[stacki - 1] += stack[stacki]; | |
10801 | stacki--; | |
10802 | break; | |
10803 | ||
10804 | case DW_OP_plus_uconst: | |
10805 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
10806 | i += bytes_read; | |
10807 | break; | |
10808 | ||
10809 | case DW_OP_minus: | |
f1bea926 | 10810 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
10811 | stacki--; |
10812 | break; | |
10813 | ||
7a292a7a | 10814 | case DW_OP_deref: |
7a292a7a | 10815 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
10816 | this using GDB's address_class enum. This is valid for partial |
10817 | global symbols, although the variable's address will be bogus | |
10818 | in the psymtab. */ | |
7a292a7a | 10819 | if (i < size) |
4d3c2250 | 10820 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
10821 | break; |
10822 | ||
9d774e44 | 10823 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
10824 | /* The top of the stack has the offset from the beginning |
10825 | of the thread control block at which the variable is located. */ | |
10826 | /* Nothing should follow this operator, so the top of stack would | |
10827 | be returned. */ | |
4cecd739 DJ |
10828 | /* This is valid for partial global symbols, but the variable's |
10829 | address will be bogus in the psymtab. */ | |
9d774e44 | 10830 | if (i < size) |
4d3c2250 | 10831 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
10832 | break; |
10833 | ||
42be36b3 CT |
10834 | case DW_OP_GNU_uninit: |
10835 | break; | |
10836 | ||
c906108c | 10837 | default: |
e2e0b3e5 | 10838 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 10839 | dwarf_stack_op_name (op)); |
c906108c SS |
10840 | return (stack[stacki]); |
10841 | } | |
10842 | } | |
10843 | return (stack[stacki]); | |
10844 | } | |
10845 | ||
10846 | /* memory allocation interface */ | |
10847 | ||
c906108c | 10848 | static struct dwarf_block * |
7b5a2f43 | 10849 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
10850 | { |
10851 | struct dwarf_block *blk; | |
10852 | ||
10853 | blk = (struct dwarf_block *) | |
7b5a2f43 | 10854 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
10855 | return (blk); |
10856 | } | |
10857 | ||
10858 | static struct abbrev_info * | |
f3dd6933 | 10859 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
10860 | { |
10861 | struct abbrev_info *abbrev; | |
10862 | ||
f3dd6933 DJ |
10863 | abbrev = (struct abbrev_info *) |
10864 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
10865 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
10866 | return (abbrev); | |
10867 | } | |
10868 | ||
10869 | static struct die_info * | |
b60c80d6 | 10870 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
10871 | { |
10872 | struct die_info *die; | |
b60c80d6 DJ |
10873 | size_t size = sizeof (struct die_info); |
10874 | ||
10875 | if (num_attrs > 1) | |
10876 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 10877 | |
b60c80d6 | 10878 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
10879 | memset (die, 0, sizeof (struct die_info)); |
10880 | return (die); | |
10881 | } | |
2e276125 JB |
10882 | |
10883 | \f | |
10884 | /* Macro support. */ | |
10885 | ||
10886 | ||
10887 | /* Return the full name of file number I in *LH's file name table. | |
10888 | Use COMP_DIR as the name of the current directory of the | |
10889 | compilation. The result is allocated using xmalloc; the caller is | |
10890 | responsible for freeing it. */ | |
10891 | static char * | |
10892 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
10893 | { | |
6a83a1e6 EZ |
10894 | /* Is the file number a valid index into the line header's file name |
10895 | table? Remember that file numbers start with one, not zero. */ | |
10896 | if (1 <= file && file <= lh->num_file_names) | |
10897 | { | |
10898 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 10899 | |
6a83a1e6 EZ |
10900 | if (IS_ABSOLUTE_PATH (fe->name)) |
10901 | return xstrdup (fe->name); | |
10902 | else | |
10903 | { | |
10904 | const char *dir; | |
10905 | int dir_len; | |
10906 | char *full_name; | |
10907 | ||
10908 | if (fe->dir_index) | |
10909 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10910 | else | |
10911 | dir = comp_dir; | |
10912 | ||
10913 | if (dir) | |
10914 | { | |
10915 | dir_len = strlen (dir); | |
10916 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
10917 | strcpy (full_name, dir); | |
10918 | full_name[dir_len] = '/'; | |
10919 | strcpy (full_name + dir_len + 1, fe->name); | |
10920 | return full_name; | |
10921 | } | |
10922 | else | |
10923 | return xstrdup (fe->name); | |
10924 | } | |
10925 | } | |
2e276125 JB |
10926 | else |
10927 | { | |
6a83a1e6 EZ |
10928 | /* The compiler produced a bogus file number. We can at least |
10929 | record the macro definitions made in the file, even if we | |
10930 | won't be able to find the file by name. */ | |
10931 | char fake_name[80]; | |
10932 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 10933 | |
6a83a1e6 EZ |
10934 | complaint (&symfile_complaints, |
10935 | _("bad file number in macro information (%d)"), | |
10936 | file); | |
2e276125 | 10937 | |
6a83a1e6 | 10938 | return xstrdup (fake_name); |
2e276125 JB |
10939 | } |
10940 | } | |
10941 | ||
10942 | ||
10943 | static struct macro_source_file * | |
10944 | macro_start_file (int file, int line, | |
10945 | struct macro_source_file *current_file, | |
10946 | const char *comp_dir, | |
10947 | struct line_header *lh, struct objfile *objfile) | |
10948 | { | |
10949 | /* The full name of this source file. */ | |
10950 | char *full_name = file_full_name (file, lh, comp_dir); | |
10951 | ||
10952 | /* We don't create a macro table for this compilation unit | |
10953 | at all until we actually get a filename. */ | |
10954 | if (! pending_macros) | |
4a146b47 | 10955 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 10956 | objfile->macro_cache); |
2e276125 JB |
10957 | |
10958 | if (! current_file) | |
10959 | /* If we have no current file, then this must be the start_file | |
10960 | directive for the compilation unit's main source file. */ | |
10961 | current_file = macro_set_main (pending_macros, full_name); | |
10962 | else | |
10963 | current_file = macro_include (current_file, line, full_name); | |
10964 | ||
10965 | xfree (full_name); | |
10966 | ||
10967 | return current_file; | |
10968 | } | |
10969 | ||
10970 | ||
10971 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
10972 | followed by a null byte. */ | |
10973 | static char * | |
10974 | copy_string (const char *buf, int len) | |
10975 | { | |
10976 | char *s = xmalloc (len + 1); | |
10977 | memcpy (s, buf, len); | |
10978 | s[len] = '\0'; | |
10979 | ||
10980 | return s; | |
10981 | } | |
10982 | ||
10983 | ||
10984 | static const char * | |
10985 | consume_improper_spaces (const char *p, const char *body) | |
10986 | { | |
10987 | if (*p == ' ') | |
10988 | { | |
4d3c2250 | 10989 | complaint (&symfile_complaints, |
e2e0b3e5 | 10990 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 10991 | body); |
2e276125 JB |
10992 | |
10993 | while (*p == ' ') | |
10994 | p++; | |
10995 | } | |
10996 | ||
10997 | return p; | |
10998 | } | |
10999 | ||
11000 | ||
11001 | static void | |
11002 | parse_macro_definition (struct macro_source_file *file, int line, | |
11003 | const char *body) | |
11004 | { | |
11005 | const char *p; | |
11006 | ||
11007 | /* The body string takes one of two forms. For object-like macro | |
11008 | definitions, it should be: | |
11009 | ||
11010 | <macro name> " " <definition> | |
11011 | ||
11012 | For function-like macro definitions, it should be: | |
11013 | ||
11014 | <macro name> "() " <definition> | |
11015 | or | |
11016 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
11017 | ||
11018 | Spaces may appear only where explicitly indicated, and in the | |
11019 | <definition>. | |
11020 | ||
11021 | The Dwarf 2 spec says that an object-like macro's name is always | |
11022 | followed by a space, but versions of GCC around March 2002 omit | |
11023 | the space when the macro's definition is the empty string. | |
11024 | ||
11025 | The Dwarf 2 spec says that there should be no spaces between the | |
11026 | formal arguments in a function-like macro's formal argument list, | |
11027 | but versions of GCC around March 2002 include spaces after the | |
11028 | commas. */ | |
11029 | ||
11030 | ||
11031 | /* Find the extent of the macro name. The macro name is terminated | |
11032 | by either a space or null character (for an object-like macro) or | |
11033 | an opening paren (for a function-like macro). */ | |
11034 | for (p = body; *p; p++) | |
11035 | if (*p == ' ' || *p == '(') | |
11036 | break; | |
11037 | ||
11038 | if (*p == ' ' || *p == '\0') | |
11039 | { | |
11040 | /* It's an object-like macro. */ | |
11041 | int name_len = p - body; | |
11042 | char *name = copy_string (body, name_len); | |
11043 | const char *replacement; | |
11044 | ||
11045 | if (*p == ' ') | |
11046 | replacement = body + name_len + 1; | |
11047 | else | |
11048 | { | |
4d3c2250 | 11049 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11050 | replacement = body + name_len; |
11051 | } | |
11052 | ||
11053 | macro_define_object (file, line, name, replacement); | |
11054 | ||
11055 | xfree (name); | |
11056 | } | |
11057 | else if (*p == '(') | |
11058 | { | |
11059 | /* It's a function-like macro. */ | |
11060 | char *name = copy_string (body, p - body); | |
11061 | int argc = 0; | |
11062 | int argv_size = 1; | |
11063 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
11064 | ||
11065 | p++; | |
11066 | ||
11067 | p = consume_improper_spaces (p, body); | |
11068 | ||
11069 | /* Parse the formal argument list. */ | |
11070 | while (*p && *p != ')') | |
11071 | { | |
11072 | /* Find the extent of the current argument name. */ | |
11073 | const char *arg_start = p; | |
11074 | ||
11075 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
11076 | p++; | |
11077 | ||
11078 | if (! *p || p == arg_start) | |
4d3c2250 | 11079 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11080 | else |
11081 | { | |
11082 | /* Make sure argv has room for the new argument. */ | |
11083 | if (argc >= argv_size) | |
11084 | { | |
11085 | argv_size *= 2; | |
11086 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
11087 | } | |
11088 | ||
11089 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
11090 | } | |
11091 | ||
11092 | p = consume_improper_spaces (p, body); | |
11093 | ||
11094 | /* Consume the comma, if present. */ | |
11095 | if (*p == ',') | |
11096 | { | |
11097 | p++; | |
11098 | ||
11099 | p = consume_improper_spaces (p, body); | |
11100 | } | |
11101 | } | |
11102 | ||
11103 | if (*p == ')') | |
11104 | { | |
11105 | p++; | |
11106 | ||
11107 | if (*p == ' ') | |
11108 | /* Perfectly formed definition, no complaints. */ | |
11109 | macro_define_function (file, line, name, | |
11110 | argc, (const char **) argv, | |
11111 | p + 1); | |
11112 | else if (*p == '\0') | |
11113 | { | |
11114 | /* Complain, but do define it. */ | |
4d3c2250 | 11115 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11116 | macro_define_function (file, line, name, |
11117 | argc, (const char **) argv, | |
11118 | p); | |
11119 | } | |
11120 | else | |
11121 | /* Just complain. */ | |
4d3c2250 | 11122 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11123 | } |
11124 | else | |
11125 | /* Just complain. */ | |
4d3c2250 | 11126 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11127 | |
11128 | xfree (name); | |
11129 | { | |
11130 | int i; | |
11131 | ||
11132 | for (i = 0; i < argc; i++) | |
11133 | xfree (argv[i]); | |
11134 | } | |
11135 | xfree (argv); | |
11136 | } | |
11137 | else | |
4d3c2250 | 11138 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11139 | } |
11140 | ||
11141 | ||
11142 | static void | |
11143 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
11144 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 11145 | struct dwarf2_cu *cu) |
2e276125 | 11146 | { |
fe1b8b76 | 11147 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 11148 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
11149 | enum dwarf_macinfo_record_type macinfo_type; |
11150 | int at_commandline; | |
2e276125 | 11151 | |
dce234bc | 11152 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 11153 | { |
e2e0b3e5 | 11154 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
11155 | return; |
11156 | } | |
11157 | ||
757a13d0 JK |
11158 | /* First pass: Find the name of the base filename. |
11159 | This filename is needed in order to process all macros whose definition | |
11160 | (or undefinition) comes from the command line. These macros are defined | |
11161 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
11162 | associated to the base file. | |
11163 | ||
11164 | To determine the base file name, we scan the macro definitions until we | |
11165 | reach the first DW_MACINFO_start_file entry. We then initialize | |
11166 | CURRENT_FILE accordingly so that any macro definition found before the | |
11167 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
11168 | ||
dce234bc PP |
11169 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
11170 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
11171 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 11172 | |
757a13d0 | 11173 | do |
2e276125 | 11174 | { |
2e276125 JB |
11175 | /* Do we at least have room for a macinfo type byte? */ |
11176 | if (mac_ptr >= mac_end) | |
11177 | { | |
757a13d0 JK |
11178 | /* Complaint is printed during the second pass as GDB will probably |
11179 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
11180 | break; | |
2e276125 JB |
11181 | } |
11182 | ||
11183 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11184 | mac_ptr++; | |
11185 | ||
11186 | switch (macinfo_type) | |
11187 | { | |
11188 | /* A zero macinfo type indicates the end of the macro | |
11189 | information. */ | |
11190 | case 0: | |
757a13d0 JK |
11191 | break; |
11192 | ||
11193 | case DW_MACINFO_define: | |
11194 | case DW_MACINFO_undef: | |
11195 | /* Only skip the data by MAC_PTR. */ | |
11196 | { | |
11197 | unsigned int bytes_read; | |
11198 | ||
11199 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11200 | mac_ptr += bytes_read; | |
11201 | read_string (abfd, mac_ptr, &bytes_read); | |
11202 | mac_ptr += bytes_read; | |
11203 | } | |
11204 | break; | |
11205 | ||
11206 | case DW_MACINFO_start_file: | |
11207 | { | |
11208 | unsigned int bytes_read; | |
11209 | int line, file; | |
11210 | ||
11211 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11212 | mac_ptr += bytes_read; | |
11213 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11214 | mac_ptr += bytes_read; | |
11215 | ||
11216 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
11217 | lh, cu->objfile); | |
11218 | } | |
11219 | break; | |
11220 | ||
11221 | case DW_MACINFO_end_file: | |
11222 | /* No data to skip by MAC_PTR. */ | |
11223 | break; | |
11224 | ||
11225 | case DW_MACINFO_vendor_ext: | |
11226 | /* Only skip the data by MAC_PTR. */ | |
11227 | { | |
11228 | unsigned int bytes_read; | |
11229 | ||
11230 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11231 | mac_ptr += bytes_read; | |
11232 | read_string (abfd, mac_ptr, &bytes_read); | |
11233 | mac_ptr += bytes_read; | |
11234 | } | |
11235 | break; | |
11236 | ||
11237 | default: | |
11238 | break; | |
11239 | } | |
11240 | } while (macinfo_type != 0 && current_file == NULL); | |
11241 | ||
11242 | /* Second pass: Process all entries. | |
11243 | ||
11244 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
11245 | command-line macro definitions/undefinitions. This flag is unset when we | |
11246 | reach the first DW_MACINFO_start_file entry. */ | |
11247 | ||
dce234bc | 11248 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
11249 | |
11250 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
11251 | GDB is still reading the definitions from command line. First | |
11252 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
11253 | to create CURRENT_FILE for the main source holding also the command line | |
11254 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
11255 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
11256 | ||
11257 | at_commandline = 1; | |
11258 | ||
11259 | do | |
11260 | { | |
11261 | /* Do we at least have room for a macinfo type byte? */ | |
11262 | if (mac_ptr >= mac_end) | |
11263 | { | |
11264 | dwarf2_macros_too_long_complaint (); | |
11265 | break; | |
11266 | } | |
11267 | ||
11268 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11269 | mac_ptr++; | |
11270 | ||
11271 | switch (macinfo_type) | |
11272 | { | |
11273 | /* A zero macinfo type indicates the end of the macro | |
11274 | information. */ | |
11275 | case 0: | |
11276 | break; | |
2e276125 JB |
11277 | |
11278 | case DW_MACINFO_define: | |
11279 | case DW_MACINFO_undef: | |
11280 | { | |
891d2f0b | 11281 | unsigned int bytes_read; |
2e276125 JB |
11282 | int line; |
11283 | char *body; | |
11284 | ||
11285 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11286 | mac_ptr += bytes_read; | |
11287 | body = read_string (abfd, mac_ptr, &bytes_read); | |
11288 | mac_ptr += bytes_read; | |
11289 | ||
11290 | if (! current_file) | |
757a13d0 JK |
11291 | { |
11292 | /* DWARF violation as no main source is present. */ | |
11293 | complaint (&symfile_complaints, | |
11294 | _("debug info with no main source gives macro %s " | |
11295 | "on line %d: %s"), | |
905e0470 PM |
11296 | macinfo_type == DW_MACINFO_define ? |
11297 | _("definition") : | |
11298 | macinfo_type == DW_MACINFO_undef ? | |
11299 | _("undefinition") : | |
11300 | _("something-or-other"), line, body); | |
757a13d0 JK |
11301 | break; |
11302 | } | |
11303 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 11304 | complaint (&symfile_complaints, |
757a13d0 JK |
11305 | _("debug info gives %s macro %s with %s line %d: %s"), |
11306 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 PM |
11307 | macinfo_type == DW_MACINFO_define ? |
11308 | _("definition") : | |
11309 | macinfo_type == DW_MACINFO_undef ? | |
11310 | _("undefinition") : | |
11311 | _("something-or-other"), | |
757a13d0 JK |
11312 | line == 0 ? _("zero") : _("non-zero"), line, body); |
11313 | ||
11314 | if (macinfo_type == DW_MACINFO_define) | |
11315 | parse_macro_definition (current_file, line, body); | |
11316 | else if (macinfo_type == DW_MACINFO_undef) | |
11317 | macro_undef (current_file, line, body); | |
2e276125 JB |
11318 | } |
11319 | break; | |
11320 | ||
11321 | case DW_MACINFO_start_file: | |
11322 | { | |
891d2f0b | 11323 | unsigned int bytes_read; |
2e276125 JB |
11324 | int line, file; |
11325 | ||
11326 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11327 | mac_ptr += bytes_read; | |
11328 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11329 | mac_ptr += bytes_read; | |
11330 | ||
757a13d0 JK |
11331 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
11332 | complaint (&symfile_complaints, | |
11333 | _("debug info gives source %d included " | |
11334 | "from %s at %s line %d"), | |
11335 | file, at_commandline ? _("command-line") : _("file"), | |
11336 | line == 0 ? _("zero") : _("non-zero"), line); | |
11337 | ||
11338 | if (at_commandline) | |
11339 | { | |
11340 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
11341 | at_commandline = 0; | |
11342 | } | |
11343 | else | |
11344 | current_file = macro_start_file (file, line, | |
11345 | current_file, comp_dir, | |
11346 | lh, cu->objfile); | |
2e276125 JB |
11347 | } |
11348 | break; | |
11349 | ||
11350 | case DW_MACINFO_end_file: | |
11351 | if (! current_file) | |
4d3c2250 | 11352 | complaint (&symfile_complaints, |
e2e0b3e5 | 11353 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
11354 | else |
11355 | { | |
11356 | current_file = current_file->included_by; | |
11357 | if (! current_file) | |
11358 | { | |
11359 | enum dwarf_macinfo_record_type next_type; | |
11360 | ||
11361 | /* GCC circa March 2002 doesn't produce the zero | |
11362 | type byte marking the end of the compilation | |
11363 | unit. Complain if it's not there, but exit no | |
11364 | matter what. */ | |
11365 | ||
11366 | /* Do we at least have room for a macinfo type byte? */ | |
11367 | if (mac_ptr >= mac_end) | |
11368 | { | |
4d3c2250 | 11369 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
11370 | return; |
11371 | } | |
11372 | ||
11373 | /* We don't increment mac_ptr here, so this is just | |
11374 | a look-ahead. */ | |
11375 | next_type = read_1_byte (abfd, mac_ptr); | |
11376 | if (next_type != 0) | |
4d3c2250 | 11377 | complaint (&symfile_complaints, |
e2e0b3e5 | 11378 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
11379 | |
11380 | return; | |
11381 | } | |
11382 | } | |
11383 | break; | |
11384 | ||
11385 | case DW_MACINFO_vendor_ext: | |
11386 | { | |
891d2f0b | 11387 | unsigned int bytes_read; |
2e276125 JB |
11388 | int constant; |
11389 | char *string; | |
11390 | ||
11391 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11392 | mac_ptr += bytes_read; | |
11393 | string = read_string (abfd, mac_ptr, &bytes_read); | |
11394 | mac_ptr += bytes_read; | |
11395 | ||
11396 | /* We don't recognize any vendor extensions. */ | |
11397 | } | |
11398 | break; | |
11399 | } | |
757a13d0 | 11400 | } while (macinfo_type != 0); |
2e276125 | 11401 | } |
8e19ed76 PS |
11402 | |
11403 | /* Check if the attribute's form is a DW_FORM_block* | |
11404 | if so return true else false. */ | |
11405 | static int | |
11406 | attr_form_is_block (struct attribute *attr) | |
11407 | { | |
11408 | return (attr == NULL ? 0 : | |
11409 | attr->form == DW_FORM_block1 | |
11410 | || attr->form == DW_FORM_block2 | |
11411 | || attr->form == DW_FORM_block4 | |
11412 | || attr->form == DW_FORM_block); | |
11413 | } | |
4c2df51b | 11414 | |
c6a0999f JB |
11415 | /* Return non-zero if ATTR's value is a section offset --- classes |
11416 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
11417 | You may use DW_UNSND (attr) to retrieve such offsets. | |
11418 | ||
11419 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
11420 | may have a value that belongs to more than one of these classes; it | |
11421 | would be ambiguous if we did, because we use the same forms for all | |
11422 | of them. */ | |
3690dd37 JB |
11423 | static int |
11424 | attr_form_is_section_offset (struct attribute *attr) | |
11425 | { | |
11426 | return (attr->form == DW_FORM_data4 | |
11427 | || attr->form == DW_FORM_data8); | |
11428 | } | |
11429 | ||
11430 | ||
11431 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
11432 | zero otherwise. When this function returns true, you can apply | |
11433 | dwarf2_get_attr_constant_value to it. | |
11434 | ||
11435 | However, note that for some attributes you must check | |
11436 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
11437 | and DW_FORM_data8 are members of both the constant class, and of | |
11438 | the classes that contain offsets into other debug sections | |
11439 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
11440 | that, if an attribute's can be either a constant or one of the | |
11441 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
11442 | taken as section offsets, not constants. */ | |
11443 | static int | |
11444 | attr_form_is_constant (struct attribute *attr) | |
11445 | { | |
11446 | switch (attr->form) | |
11447 | { | |
11448 | case DW_FORM_sdata: | |
11449 | case DW_FORM_udata: | |
11450 | case DW_FORM_data1: | |
11451 | case DW_FORM_data2: | |
11452 | case DW_FORM_data4: | |
11453 | case DW_FORM_data8: | |
11454 | return 1; | |
11455 | default: | |
11456 | return 0; | |
11457 | } | |
11458 | } | |
11459 | ||
4c2df51b DJ |
11460 | static void |
11461 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11462 | struct dwarf2_cu *cu) |
4c2df51b | 11463 | { |
3690dd37 | 11464 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
11465 | /* ".debug_loc" may not exist at all, or the offset may be outside |
11466 | the section. If so, fall through to the complaint in the | |
11467 | other branch. */ | |
dce234bc | 11468 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 11469 | { |
0d53c4c4 | 11470 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 11471 | |
4a146b47 | 11472 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11473 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
11474 | baton->per_cu = cu->per_cu; |
11475 | gdb_assert (baton->per_cu); | |
4c2df51b | 11476 | |
0d53c4c4 DJ |
11477 | /* We don't know how long the location list is, but make sure we |
11478 | don't run off the edge of the section. */ | |
dce234bc PP |
11479 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
11480 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
11481 | baton->base_address = cu->base_address; |
11482 | if (cu->base_known == 0) | |
0d53c4c4 | 11483 | complaint (&symfile_complaints, |
e2e0b3e5 | 11484 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 11485 | |
768a979c | 11486 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
11487 | SYMBOL_LOCATION_BATON (sym) = baton; |
11488 | } | |
11489 | else | |
11490 | { | |
11491 | struct dwarf2_locexpr_baton *baton; | |
11492 | ||
4a146b47 | 11493 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11494 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
11495 | baton->per_cu = cu->per_cu; |
11496 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
11497 | |
11498 | if (attr_form_is_block (attr)) | |
11499 | { | |
11500 | /* Note that we're just copying the block's data pointer | |
11501 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
11502 | info_buffer for SYM's objfile; right now we never release |
11503 | that buffer, but when we do clean up properly this may | |
11504 | need to change. */ | |
0d53c4c4 DJ |
11505 | baton->size = DW_BLOCK (attr)->size; |
11506 | baton->data = DW_BLOCK (attr)->data; | |
11507 | } | |
11508 | else | |
11509 | { | |
11510 | dwarf2_invalid_attrib_class_complaint ("location description", | |
11511 | SYMBOL_NATURAL_NAME (sym)); | |
11512 | baton->size = 0; | |
11513 | baton->data = NULL; | |
11514 | } | |
11515 | ||
768a979c | 11516 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
11517 | SYMBOL_LOCATION_BATON (sym) = baton; |
11518 | } | |
4c2df51b | 11519 | } |
6502dd73 | 11520 | |
ae0d2f24 UW |
11521 | /* Return the OBJFILE associated with the compilation unit CU. */ |
11522 | ||
11523 | struct objfile * | |
11524 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
11525 | { | |
11526 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11527 | ||
11528 | /* Return the master objfile, so that we can report and look up the | |
11529 | correct file containing this variable. */ | |
11530 | if (objfile->separate_debug_objfile_backlink) | |
11531 | objfile = objfile->separate_debug_objfile_backlink; | |
11532 | ||
11533 | return objfile; | |
11534 | } | |
11535 | ||
11536 | /* Return the address size given in the compilation unit header for CU. */ | |
11537 | ||
11538 | CORE_ADDR | |
11539 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
11540 | { | |
11541 | if (per_cu->cu) | |
11542 | return per_cu->cu->header.addr_size; | |
11543 | else | |
11544 | { | |
11545 | /* If the CU is not currently read in, we re-read its header. */ | |
11546 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11547 | struct dwarf2_per_objfile *per_objfile | |
11548 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 11549 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 UW |
11550 | |
11551 | struct comp_unit_head cu_header; | |
11552 | memset (&cu_header, 0, sizeof cu_header); | |
11553 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
11554 | return cu_header.addr_size; | |
11555 | } | |
11556 | } | |
11557 | ||
348e048f DE |
11558 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
11559 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
11560 | |
11561 | static struct dwarf2_per_cu_data * | |
c764a876 | 11562 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
11563 | struct objfile *objfile) |
11564 | { | |
11565 | struct dwarf2_per_cu_data *this_cu; | |
11566 | int low, high; | |
11567 | ||
ae038cb0 DJ |
11568 | low = 0; |
11569 | high = dwarf2_per_objfile->n_comp_units - 1; | |
11570 | while (high > low) | |
11571 | { | |
11572 | int mid = low + (high - low) / 2; | |
11573 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
11574 | high = mid; | |
11575 | else | |
11576 | low = mid + 1; | |
11577 | } | |
11578 | gdb_assert (low == high); | |
11579 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
11580 | { | |
10b3939b | 11581 | if (low == 0) |
8a3fe4f8 AC |
11582 | error (_("Dwarf Error: could not find partial DIE containing " |
11583 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
11584 | (long) offset, bfd_get_filename (objfile->obfd)); |
11585 | ||
ae038cb0 DJ |
11586 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
11587 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
11588 | } | |
11589 | else | |
11590 | { | |
11591 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
11592 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
11593 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 11594 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
11595 | gdb_assert (offset < this_cu->offset + this_cu->length); |
11596 | return this_cu; | |
11597 | } | |
11598 | } | |
11599 | ||
10b3939b DJ |
11600 | /* Locate the compilation unit from OBJFILE which is located at exactly |
11601 | OFFSET. Raises an error on failure. */ | |
11602 | ||
ae038cb0 | 11603 | static struct dwarf2_per_cu_data * |
c764a876 | 11604 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
11605 | { |
11606 | struct dwarf2_per_cu_data *this_cu; | |
11607 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
11608 | if (this_cu->offset != offset) | |
c764a876 | 11609 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
11610 | return this_cu; |
11611 | } | |
11612 | ||
93311388 DE |
11613 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
11614 | ||
11615 | static struct dwarf2_cu * | |
11616 | alloc_one_comp_unit (struct objfile *objfile) | |
11617 | { | |
11618 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
11619 | cu->objfile = objfile; | |
11620 | obstack_init (&cu->comp_unit_obstack); | |
11621 | return cu; | |
11622 | } | |
11623 | ||
ae038cb0 DJ |
11624 | /* Release one cached compilation unit, CU. We unlink it from the tree |
11625 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
11626 | the caller is responsible for that. |
11627 | NOTE: DATA is a void * because this function is also used as a | |
11628 | cleanup routine. */ | |
ae038cb0 DJ |
11629 | |
11630 | static void | |
11631 | free_one_comp_unit (void *data) | |
11632 | { | |
11633 | struct dwarf2_cu *cu = data; | |
11634 | ||
11635 | if (cu->per_cu != NULL) | |
11636 | cu->per_cu->cu = NULL; | |
11637 | cu->per_cu = NULL; | |
11638 | ||
11639 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11640 | ||
11641 | xfree (cu); | |
11642 | } | |
11643 | ||
72bf9492 | 11644 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
11645 | when we're finished with it. We can't free the pointer itself, but be |
11646 | sure to unlink it from the cache. Also release any associated storage | |
11647 | and perform cache maintenance. | |
72bf9492 DJ |
11648 | |
11649 | Only used during partial symbol parsing. */ | |
11650 | ||
11651 | static void | |
11652 | free_stack_comp_unit (void *data) | |
11653 | { | |
11654 | struct dwarf2_cu *cu = data; | |
11655 | ||
11656 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11657 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
11658 | |
11659 | if (cu->per_cu != NULL) | |
11660 | { | |
11661 | /* This compilation unit is on the stack in our caller, so we | |
11662 | should not xfree it. Just unlink it. */ | |
11663 | cu->per_cu->cu = NULL; | |
11664 | cu->per_cu = NULL; | |
11665 | ||
11666 | /* If we had a per-cu pointer, then we may have other compilation | |
11667 | units loaded, so age them now. */ | |
11668 | age_cached_comp_units (); | |
11669 | } | |
11670 | } | |
11671 | ||
11672 | /* Free all cached compilation units. */ | |
11673 | ||
11674 | static void | |
11675 | free_cached_comp_units (void *data) | |
11676 | { | |
11677 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11678 | ||
11679 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11680 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11681 | while (per_cu != NULL) | |
11682 | { | |
11683 | struct dwarf2_per_cu_data *next_cu; | |
11684 | ||
11685 | next_cu = per_cu->cu->read_in_chain; | |
11686 | ||
11687 | free_one_comp_unit (per_cu->cu); | |
11688 | *last_chain = next_cu; | |
11689 | ||
11690 | per_cu = next_cu; | |
11691 | } | |
11692 | } | |
11693 | ||
11694 | /* Increase the age counter on each cached compilation unit, and free | |
11695 | any that are too old. */ | |
11696 | ||
11697 | static void | |
11698 | age_cached_comp_units (void) | |
11699 | { | |
11700 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11701 | ||
11702 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
11703 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11704 | while (per_cu != NULL) | |
11705 | { | |
11706 | per_cu->cu->last_used ++; | |
11707 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
11708 | dwarf2_mark (per_cu->cu); | |
11709 | per_cu = per_cu->cu->read_in_chain; | |
11710 | } | |
11711 | ||
11712 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11713 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11714 | while (per_cu != NULL) | |
11715 | { | |
11716 | struct dwarf2_per_cu_data *next_cu; | |
11717 | ||
11718 | next_cu = per_cu->cu->read_in_chain; | |
11719 | ||
11720 | if (!per_cu->cu->mark) | |
11721 | { | |
11722 | free_one_comp_unit (per_cu->cu); | |
11723 | *last_chain = next_cu; | |
11724 | } | |
11725 | else | |
11726 | last_chain = &per_cu->cu->read_in_chain; | |
11727 | ||
11728 | per_cu = next_cu; | |
11729 | } | |
11730 | } | |
11731 | ||
11732 | /* Remove a single compilation unit from the cache. */ | |
11733 | ||
11734 | static void | |
11735 | free_one_cached_comp_unit (void *target_cu) | |
11736 | { | |
11737 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11738 | ||
11739 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11740 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11741 | while (per_cu != NULL) | |
11742 | { | |
11743 | struct dwarf2_per_cu_data *next_cu; | |
11744 | ||
11745 | next_cu = per_cu->cu->read_in_chain; | |
11746 | ||
11747 | if (per_cu->cu == target_cu) | |
11748 | { | |
11749 | free_one_comp_unit (per_cu->cu); | |
11750 | *last_chain = next_cu; | |
11751 | break; | |
11752 | } | |
11753 | else | |
11754 | last_chain = &per_cu->cu->read_in_chain; | |
11755 | ||
11756 | per_cu = next_cu; | |
11757 | } | |
11758 | } | |
11759 | ||
fe3e1990 DJ |
11760 | /* Release all extra memory associated with OBJFILE. */ |
11761 | ||
11762 | void | |
11763 | dwarf2_free_objfile (struct objfile *objfile) | |
11764 | { | |
11765 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
11766 | ||
11767 | if (dwarf2_per_objfile == NULL) | |
11768 | return; | |
11769 | ||
11770 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
11771 | free_cached_comp_units (NULL); | |
11772 | ||
11773 | /* Everything else should be on the objfile obstack. */ | |
11774 | } | |
11775 | ||
1c379e20 DJ |
11776 | /* A pair of DIE offset and GDB type pointer. We store these |
11777 | in a hash table separate from the DIEs, and preserve them | |
11778 | when the DIEs are flushed out of cache. */ | |
11779 | ||
11780 | struct dwarf2_offset_and_type | |
11781 | { | |
11782 | unsigned int offset; | |
11783 | struct type *type; | |
11784 | }; | |
11785 | ||
11786 | /* Hash function for a dwarf2_offset_and_type. */ | |
11787 | ||
11788 | static hashval_t | |
11789 | offset_and_type_hash (const void *item) | |
11790 | { | |
11791 | const struct dwarf2_offset_and_type *ofs = item; | |
11792 | return ofs->offset; | |
11793 | } | |
11794 | ||
11795 | /* Equality function for a dwarf2_offset_and_type. */ | |
11796 | ||
11797 | static int | |
11798 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
11799 | { | |
11800 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
11801 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
11802 | return ofs_lhs->offset == ofs_rhs->offset; | |
11803 | } | |
11804 | ||
11805 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 11806 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 11807 | |
f792889a | 11808 | static struct type * |
1c379e20 DJ |
11809 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
11810 | { | |
11811 | struct dwarf2_offset_and_type **slot, ofs; | |
11812 | ||
b4ba55a1 JB |
11813 | /* For Ada types, make sure that the gnat-specific data is always |
11814 | initialized (if not already set). There are a few types where | |
11815 | we should not be doing so, because the type-specific area is | |
11816 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
11817 | where the type-specific area is used to store the floatformat). | |
11818 | But this is not a problem, because the gnat-specific information | |
11819 | is actually not needed for these types. */ | |
11820 | if (need_gnat_info (cu) | |
11821 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
11822 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
11823 | && !HAVE_GNAT_AUX_INFO (type)) | |
11824 | INIT_GNAT_SPECIFIC (type); | |
11825 | ||
f792889a DJ |
11826 | if (cu->type_hash == NULL) |
11827 | { | |
11828 | gdb_assert (cu->per_cu != NULL); | |
11829 | cu->per_cu->type_hash | |
11830 | = htab_create_alloc_ex (cu->header.length / 24, | |
11831 | offset_and_type_hash, | |
11832 | offset_and_type_eq, | |
11833 | NULL, | |
11834 | &cu->objfile->objfile_obstack, | |
11835 | hashtab_obstack_allocate, | |
11836 | dummy_obstack_deallocate); | |
11837 | cu->type_hash = cu->per_cu->type_hash; | |
11838 | } | |
1c379e20 DJ |
11839 | |
11840 | ofs.offset = die->offset; | |
11841 | ofs.type = type; | |
11842 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 11843 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
11844 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
11845 | **slot = ofs; | |
f792889a | 11846 | return type; |
1c379e20 DJ |
11847 | } |
11848 | ||
f792889a DJ |
11849 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
11850 | not have a saved type. */ | |
1c379e20 DJ |
11851 | |
11852 | static struct type * | |
f792889a | 11853 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
11854 | { |
11855 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
11856 | htab_t type_hash = cu->type_hash; |
11857 | ||
11858 | if (type_hash == NULL) | |
11859 | return NULL; | |
1c379e20 DJ |
11860 | |
11861 | ofs.offset = die->offset; | |
11862 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
11863 | if (slot) | |
11864 | return slot->type; | |
11865 | else | |
11866 | return NULL; | |
11867 | } | |
11868 | ||
10b3939b DJ |
11869 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
11870 | ||
11871 | static void | |
11872 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
11873 | struct dwarf2_per_cu_data *ref_per_cu) | |
11874 | { | |
11875 | void **slot; | |
11876 | ||
11877 | if (cu->dependencies == NULL) | |
11878 | cu->dependencies | |
11879 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
11880 | NULL, &cu->comp_unit_obstack, | |
11881 | hashtab_obstack_allocate, | |
11882 | dummy_obstack_deallocate); | |
11883 | ||
11884 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
11885 | if (*slot == NULL) | |
11886 | *slot = ref_per_cu; | |
11887 | } | |
1c379e20 | 11888 | |
f504f079 DE |
11889 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
11890 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
11891 | cache that we must keep because we are keeping CU. */ |
11892 | ||
10b3939b DJ |
11893 | static int |
11894 | dwarf2_mark_helper (void **slot, void *data) | |
11895 | { | |
11896 | struct dwarf2_per_cu_data *per_cu; | |
11897 | ||
11898 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
11899 | if (per_cu->cu->mark) | |
11900 | return 1; | |
11901 | per_cu->cu->mark = 1; | |
11902 | ||
11903 | if (per_cu->cu->dependencies != NULL) | |
11904 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
11905 | ||
11906 | return 1; | |
11907 | } | |
11908 | ||
f504f079 DE |
11909 | /* Set the mark field in CU and in every other compilation unit in the |
11910 | cache that we must keep because we are keeping CU. */ | |
11911 | ||
ae038cb0 DJ |
11912 | static void |
11913 | dwarf2_mark (struct dwarf2_cu *cu) | |
11914 | { | |
11915 | if (cu->mark) | |
11916 | return; | |
11917 | cu->mark = 1; | |
10b3939b DJ |
11918 | if (cu->dependencies != NULL) |
11919 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
11920 | } |
11921 | ||
11922 | static void | |
11923 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
11924 | { | |
11925 | while (per_cu) | |
11926 | { | |
11927 | per_cu->cu->mark = 0; | |
11928 | per_cu = per_cu->cu->read_in_chain; | |
11929 | } | |
72bf9492 DJ |
11930 | } |
11931 | ||
72bf9492 DJ |
11932 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
11933 | is its offset in .debug_info for this objfile. */ | |
11934 | ||
11935 | static hashval_t | |
11936 | partial_die_hash (const void *item) | |
11937 | { | |
11938 | const struct partial_die_info *part_die = item; | |
11939 | return part_die->offset; | |
11940 | } | |
11941 | ||
11942 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
11943 | are equal if they have the same offset. */ | |
11944 | ||
11945 | static int | |
11946 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
11947 | { | |
11948 | const struct partial_die_info *part_die_lhs = item_lhs; | |
11949 | const struct partial_die_info *part_die_rhs = item_rhs; | |
11950 | return part_die_lhs->offset == part_die_rhs->offset; | |
11951 | } | |
11952 | ||
ae038cb0 DJ |
11953 | static struct cmd_list_element *set_dwarf2_cmdlist; |
11954 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
11955 | ||
11956 | static void | |
11957 | set_dwarf2_cmd (char *args, int from_tty) | |
11958 | { | |
11959 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
11960 | } | |
11961 | ||
11962 | static void | |
11963 | show_dwarf2_cmd (char *args, int from_tty) | |
11964 | { | |
11965 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
11966 | } | |
11967 | ||
dce234bc PP |
11968 | /* If section described by INFO was mmapped, munmap it now. */ |
11969 | ||
11970 | static void | |
11971 | munmap_section_buffer (struct dwarf2_section_info *info) | |
11972 | { | |
11973 | if (info->was_mmapped) | |
11974 | { | |
11975 | #ifdef HAVE_MMAP | |
11976 | intptr_t begin = (intptr_t) info->buffer; | |
11977 | intptr_t map_begin = begin & ~(pagesize - 1); | |
11978 | size_t map_length = info->size + begin - map_begin; | |
11979 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); | |
11980 | #else | |
11981 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
11982 | gdb_assert (0); | |
11983 | #endif | |
11984 | } | |
11985 | } | |
11986 | ||
11987 | /* munmap debug sections for OBJFILE, if necessary. */ | |
11988 | ||
11989 | static void | |
c1bd65d0 | 11990 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
11991 | { |
11992 | struct dwarf2_per_objfile *data = d; | |
11993 | munmap_section_buffer (&data->info); | |
11994 | munmap_section_buffer (&data->abbrev); | |
11995 | munmap_section_buffer (&data->line); | |
11996 | munmap_section_buffer (&data->str); | |
11997 | munmap_section_buffer (&data->macinfo); | |
11998 | munmap_section_buffer (&data->ranges); | |
11999 | munmap_section_buffer (&data->loc); | |
12000 | munmap_section_buffer (&data->frame); | |
12001 | munmap_section_buffer (&data->eh_frame); | |
12002 | } | |
12003 | ||
6502dd73 DJ |
12004 | void _initialize_dwarf2_read (void); |
12005 | ||
12006 | void | |
12007 | _initialize_dwarf2_read (void) | |
12008 | { | |
dce234bc | 12009 | dwarf2_objfile_data_key |
c1bd65d0 | 12010 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 12011 | |
1bedd215 AC |
12012 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
12013 | Set DWARF 2 specific variables.\n\ | |
12014 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
12015 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
12016 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
12017 | ||
1bedd215 AC |
12018 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
12019 | Show DWARF 2 specific variables\n\ | |
12020 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
12021 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
12022 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
12023 | ||
12024 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
12025 | &dwarf2_max_cache_age, _("\ |
12026 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
12027 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
12028 | A higher limit means that cached compilation units will be stored\n\ | |
12029 | in memory longer, and more total memory will be used. Zero disables\n\ | |
12030 | caching, which can slow down startup."), | |
2c5b56ce | 12031 | NULL, |
920d2a44 | 12032 | show_dwarf2_max_cache_age, |
2c5b56ce | 12033 | &set_dwarf2_cmdlist, |
ae038cb0 | 12034 | &show_dwarf2_cmdlist); |
d97bc12b DE |
12035 | |
12036 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ | |
12037 | Set debugging of the dwarf2 DIE reader."), _("\ | |
12038 | Show debugging of the dwarf2 DIE reader."), _("\ | |
12039 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
12040 | The value is the maximum depth to print."), | |
12041 | NULL, | |
12042 | NULL, | |
12043 | &setdebuglist, &showdebuglist); | |
6502dd73 | 12044 | } |