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" |
4c2df51b | 51 | |
c906108c SS |
52 | #include <fcntl.h> |
53 | #include "gdb_string.h" | |
4bdf3d34 | 54 | #include "gdb_assert.h" |
c906108c | 55 | #include <sys/types.h> |
233a11ab CS |
56 | #ifdef HAVE_ZLIB_H |
57 | #include <zlib.h> | |
58 | #endif | |
dce234bc PP |
59 | #ifdef HAVE_MMAP |
60 | #include <sys/mman.h> | |
85d9bd0e TT |
61 | #ifndef MAP_FAILED |
62 | #define MAP_FAILED ((void *) -1) | |
63 | #endif | |
dce234bc | 64 | #endif |
d8151005 | 65 | |
107d2387 | 66 | #if 0 |
357e46e7 | 67 | /* .debug_info header for a compilation unit |
c906108c SS |
68 | Because of alignment constraints, this structure has padding and cannot |
69 | be mapped directly onto the beginning of the .debug_info section. */ | |
70 | typedef struct comp_unit_header | |
71 | { | |
72 | unsigned int length; /* length of the .debug_info | |
73 | contribution */ | |
74 | unsigned short version; /* version number -- 2 for DWARF | |
75 | version 2 */ | |
76 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
77 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
78 | } | |
79 | _COMP_UNIT_HEADER; | |
80 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 81 | #endif |
c906108c SS |
82 | |
83 | /* .debug_pubnames header | |
84 | Because of alignment constraints, this structure has padding and cannot | |
85 | be mapped directly onto the beginning of the .debug_info section. */ | |
86 | typedef struct pubnames_header | |
87 | { | |
88 | unsigned int length; /* length of the .debug_pubnames | |
89 | contribution */ | |
90 | unsigned char version; /* version number -- 2 for DWARF | |
91 | version 2 */ | |
92 | unsigned int info_offset; /* offset into .debug_info section */ | |
93 | unsigned int info_size; /* byte size of .debug_info section | |
94 | portion */ | |
95 | } | |
96 | _PUBNAMES_HEADER; | |
97 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
98 | ||
99 | /* .debug_pubnames header | |
100 | Because of alignment constraints, this structure has padding and cannot | |
101 | be mapped directly onto the beginning of the .debug_info section. */ | |
102 | typedef struct aranges_header | |
103 | { | |
104 | unsigned int length; /* byte len of the .debug_aranges | |
105 | contribution */ | |
106 | unsigned short version; /* version number -- 2 for DWARF | |
107 | version 2 */ | |
108 | unsigned int info_offset; /* offset into .debug_info section */ | |
109 | unsigned char addr_size; /* byte size of an address */ | |
110 | unsigned char seg_size; /* byte size of segment descriptor */ | |
111 | } | |
112 | _ARANGES_HEADER; | |
113 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
114 | ||
115 | /* .debug_line statement program prologue | |
116 | Because of alignment constraints, this structure has padding and cannot | |
117 | be mapped directly onto the beginning of the .debug_info section. */ | |
118 | typedef struct statement_prologue | |
119 | { | |
120 | unsigned int total_length; /* byte length of the statement | |
121 | information */ | |
122 | unsigned short version; /* version number -- 2 for DWARF | |
123 | version 2 */ | |
124 | unsigned int prologue_length; /* # bytes between prologue & | |
125 | stmt program */ | |
126 | unsigned char minimum_instruction_length; /* byte size of | |
127 | smallest instr */ | |
128 | unsigned char default_is_stmt; /* initial value of is_stmt | |
129 | register */ | |
130 | char line_base; | |
131 | unsigned char line_range; | |
132 | unsigned char opcode_base; /* number assigned to first special | |
133 | opcode */ | |
134 | unsigned char *standard_opcode_lengths; | |
135 | } | |
136 | _STATEMENT_PROLOGUE; | |
137 | ||
d97bc12b DE |
138 | /* When non-zero, dump DIEs after they are read in. */ |
139 | static int dwarf2_die_debug = 0; | |
140 | ||
dce234bc PP |
141 | static int pagesize; |
142 | ||
df8a16a1 DJ |
143 | /* When set, the file that we're processing is known to have debugging |
144 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
145 | but later versions do. */ | |
146 | ||
147 | static int processing_has_namespace_info; | |
148 | ||
6502dd73 DJ |
149 | static const struct objfile_data *dwarf2_objfile_data_key; |
150 | ||
dce234bc PP |
151 | struct dwarf2_section_info |
152 | { | |
153 | asection *asection; | |
154 | gdb_byte *buffer; | |
155 | bfd_size_type size; | |
156 | int was_mmapped; | |
157 | }; | |
158 | ||
6502dd73 DJ |
159 | struct dwarf2_per_objfile |
160 | { | |
dce234bc PP |
161 | struct dwarf2_section_info info; |
162 | struct dwarf2_section_info abbrev; | |
163 | struct dwarf2_section_info line; | |
164 | struct dwarf2_section_info pubnames; | |
165 | struct dwarf2_section_info aranges; | |
166 | struct dwarf2_section_info loc; | |
167 | struct dwarf2_section_info macinfo; | |
168 | struct dwarf2_section_info str; | |
169 | struct dwarf2_section_info ranges; | |
348e048f | 170 | struct dwarf2_section_info types; |
dce234bc PP |
171 | struct dwarf2_section_info frame; |
172 | struct dwarf2_section_info eh_frame; | |
ae038cb0 | 173 | |
10b3939b DJ |
174 | /* A list of all the compilation units. This is used to locate |
175 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
176 | struct dwarf2_per_cu_data **all_comp_units; |
177 | ||
178 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
179 | int n_comp_units; | |
180 | ||
181 | /* A chain of compilation units that are currently read in, so that | |
182 | they can be freed later. */ | |
183 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 184 | |
348e048f DE |
185 | /* A table mapping .debug_types signatures to its signatured_type entry. |
186 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
187 | htab_t signatured_types; | |
188 | ||
72dca2f5 FR |
189 | /* A flag indicating wether this objfile has a section loaded at a |
190 | VMA of 0. */ | |
191 | int has_section_at_zero; | |
6502dd73 DJ |
192 | }; |
193 | ||
194 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
195 | |
196 | /* names of the debugging sections */ | |
197 | ||
233a11ab CS |
198 | /* Note that if the debugging section has been compressed, it might |
199 | have a name like .zdebug_info. */ | |
200 | ||
201 | #define INFO_SECTION "debug_info" | |
202 | #define ABBREV_SECTION "debug_abbrev" | |
203 | #define LINE_SECTION "debug_line" | |
204 | #define PUBNAMES_SECTION "debug_pubnames" | |
205 | #define ARANGES_SECTION "debug_aranges" | |
206 | #define LOC_SECTION "debug_loc" | |
207 | #define MACINFO_SECTION "debug_macinfo" | |
208 | #define STR_SECTION "debug_str" | |
209 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 210 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
211 | #define FRAME_SECTION "debug_frame" |
212 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
213 | |
214 | /* local data types */ | |
215 | ||
57349743 JB |
216 | /* We hold several abbreviation tables in memory at the same time. */ |
217 | #ifndef ABBREV_HASH_SIZE | |
218 | #define ABBREV_HASH_SIZE 121 | |
219 | #endif | |
220 | ||
107d2387 AC |
221 | /* The data in a compilation unit header, after target2host |
222 | translation, looks like this. */ | |
c906108c | 223 | struct comp_unit_head |
a738430d | 224 | { |
c764a876 | 225 | unsigned int length; |
a738430d | 226 | short version; |
a738430d MK |
227 | unsigned char addr_size; |
228 | unsigned char signed_addr_p; | |
9cbfa09e | 229 | unsigned int abbrev_offset; |
57349743 | 230 | |
a738430d MK |
231 | /* Size of file offsets; either 4 or 8. */ |
232 | unsigned int offset_size; | |
57349743 | 233 | |
a738430d MK |
234 | /* Size of the length field; either 4 or 12. */ |
235 | unsigned int initial_length_size; | |
57349743 | 236 | |
a738430d MK |
237 | /* Offset to the first byte of this compilation unit header in the |
238 | .debug_info section, for resolving relative reference dies. */ | |
239 | unsigned int offset; | |
57349743 | 240 | |
d00adf39 DE |
241 | /* Offset to first die in this cu from the start of the cu. |
242 | This will be the first byte following the compilation unit header. */ | |
243 | unsigned int first_die_offset; | |
a738430d | 244 | }; |
c906108c | 245 | |
e7c27a73 DJ |
246 | /* Internal state when decoding a particular compilation unit. */ |
247 | struct dwarf2_cu | |
248 | { | |
249 | /* The objfile containing this compilation unit. */ | |
250 | struct objfile *objfile; | |
251 | ||
d00adf39 | 252 | /* The header of the compilation unit. */ |
e7c27a73 | 253 | struct comp_unit_head header; |
e142c38c | 254 | |
d00adf39 DE |
255 | /* Base address of this compilation unit. */ |
256 | CORE_ADDR base_address; | |
257 | ||
258 | /* Non-zero if base_address has been set. */ | |
259 | int base_known; | |
260 | ||
e142c38c DJ |
261 | struct function_range *first_fn, *last_fn, *cached_fn; |
262 | ||
263 | /* The language we are debugging. */ | |
264 | enum language language; | |
265 | const struct language_defn *language_defn; | |
266 | ||
b0f35d58 DL |
267 | const char *producer; |
268 | ||
e142c38c DJ |
269 | /* The generic symbol table building routines have separate lists for |
270 | file scope symbols and all all other scopes (local scopes). So | |
271 | we need to select the right one to pass to add_symbol_to_list(). | |
272 | We do it by keeping a pointer to the correct list in list_in_scope. | |
273 | ||
274 | FIXME: The original dwarf code just treated the file scope as the | |
275 | first local scope, and all other local scopes as nested local | |
276 | scopes, and worked fine. Check to see if we really need to | |
277 | distinguish these in buildsym.c. */ | |
278 | struct pending **list_in_scope; | |
279 | ||
f3dd6933 DJ |
280 | /* DWARF abbreviation table associated with this compilation unit. */ |
281 | struct abbrev_info **dwarf2_abbrevs; | |
282 | ||
283 | /* Storage for the abbrev table. */ | |
284 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
285 | |
286 | /* Hash table holding all the loaded partial DIEs. */ | |
287 | htab_t partial_dies; | |
288 | ||
289 | /* Storage for things with the same lifetime as this read-in compilation | |
290 | unit, including partial DIEs. */ | |
291 | struct obstack comp_unit_obstack; | |
292 | ||
ae038cb0 DJ |
293 | /* When multiple dwarf2_cu structures are living in memory, this field |
294 | chains them all together, so that they can be released efficiently. | |
295 | We will probably also want a generation counter so that most-recently-used | |
296 | compilation units are cached... */ | |
297 | struct dwarf2_per_cu_data *read_in_chain; | |
298 | ||
299 | /* Backchain to our per_cu entry if the tree has been built. */ | |
300 | struct dwarf2_per_cu_data *per_cu; | |
301 | ||
f792889a DJ |
302 | /* Pointer to the die -> type map. Although it is stored |
303 | permanently in per_cu, we copy it here to avoid double | |
304 | indirection. */ | |
305 | htab_t type_hash; | |
306 | ||
ae038cb0 DJ |
307 | /* How many compilation units ago was this CU last referenced? */ |
308 | int last_used; | |
309 | ||
10b3939b | 310 | /* A hash table of die offsets for following references. */ |
51545339 | 311 | htab_t die_hash; |
10b3939b DJ |
312 | |
313 | /* Full DIEs if read in. */ | |
314 | struct die_info *dies; | |
315 | ||
316 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
317 | units referenced by this one. Only set during full symbol processing; | |
318 | partial symbol tables do not have dependencies. */ | |
319 | htab_t dependencies; | |
320 | ||
cb1df416 DJ |
321 | /* Header data from the line table, during full symbol processing. */ |
322 | struct line_header *line_header; | |
323 | ||
ae038cb0 DJ |
324 | /* Mark used when releasing cached dies. */ |
325 | unsigned int mark : 1; | |
326 | ||
327 | /* This flag will be set if this compilation unit might include | |
328 | inter-compilation-unit references. */ | |
329 | unsigned int has_form_ref_addr : 1; | |
330 | ||
72bf9492 DJ |
331 | /* This flag will be set if this compilation unit includes any |
332 | DW_TAG_namespace DIEs. If we know that there are explicit | |
333 | DIEs for namespaces, we don't need to try to infer them | |
334 | from mangled names. */ | |
335 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
336 | }; |
337 | ||
10b3939b DJ |
338 | /* Persistent data held for a compilation unit, even when not |
339 | processing it. We put a pointer to this structure in the | |
340 | read_symtab_private field of the psymtab. If we encounter | |
341 | inter-compilation-unit references, we also maintain a sorted | |
342 | list of all compilation units. */ | |
343 | ||
ae038cb0 DJ |
344 | struct dwarf2_per_cu_data |
345 | { | |
348e048f | 346 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 347 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
348 | - if it doesn't, GDB will fall over anyway. |
349 | NOTE: Unlike comp_unit_head.length, this length includes | |
350 | initial_length_size. */ | |
c764a876 | 351 | unsigned int offset; |
348e048f | 352 | unsigned int length : 29; |
ae038cb0 DJ |
353 | |
354 | /* Flag indicating this compilation unit will be read in before | |
355 | any of the current compilation units are processed. */ | |
c764a876 | 356 | unsigned int queued : 1; |
ae038cb0 | 357 | |
5afb4e99 DJ |
358 | /* This flag will be set if we need to load absolutely all DIEs |
359 | for this compilation unit, instead of just the ones we think | |
360 | are interesting. It gets set if we look for a DIE in the | |
361 | hash table and don't find it. */ | |
362 | unsigned int load_all_dies : 1; | |
363 | ||
348e048f DE |
364 | /* Non-zero if this CU is from .debug_types. |
365 | Otherwise it's from .debug_info. */ | |
366 | unsigned int from_debug_types : 1; | |
367 | ||
ae038cb0 DJ |
368 | /* Set iff currently read in. */ |
369 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
370 | |
371 | /* If full symbols for this CU have been read in, then this field | |
372 | holds a map of DIE offsets to types. It isn't always possible | |
373 | to reconstruct this information later, so we have to preserve | |
374 | it. */ | |
1c379e20 | 375 | htab_t type_hash; |
10b3939b | 376 | |
31ffec48 DJ |
377 | /* The partial symbol table associated with this compilation unit, |
378 | or NULL for partial units (which do not have an associated | |
379 | symtab). */ | |
10b3939b | 380 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
381 | }; |
382 | ||
348e048f DE |
383 | /* Entry in the signatured_types hash table. */ |
384 | ||
385 | struct signatured_type | |
386 | { | |
387 | ULONGEST signature; | |
388 | ||
389 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
390 | unsigned int offset; | |
391 | ||
392 | /* Offset in .debug_types of the type defined by this TU. */ | |
393 | unsigned int type_offset; | |
394 | ||
395 | /* The CU(/TU) of this type. */ | |
396 | struct dwarf2_per_cu_data per_cu; | |
397 | }; | |
398 | ||
93311388 DE |
399 | /* Struct used to pass misc. parameters to read_die_and_children, et. al. |
400 | which are used for both .debug_info and .debug_types dies. | |
401 | All parameters here are unchanging for the life of the call. | |
402 | This struct exists to abstract away the constant parameters of | |
403 | die reading. */ | |
404 | ||
405 | struct die_reader_specs | |
406 | { | |
407 | /* The bfd of this objfile. */ | |
408 | bfd* abfd; | |
409 | ||
410 | /* The CU of the DIE we are parsing. */ | |
411 | struct dwarf2_cu *cu; | |
412 | ||
413 | /* Pointer to start of section buffer. | |
414 | This is either the start of .debug_info or .debug_types. */ | |
415 | const gdb_byte *buffer; | |
416 | }; | |
417 | ||
debd256d JB |
418 | /* The line number information for a compilation unit (found in the |
419 | .debug_line section) begins with a "statement program header", | |
420 | which contains the following information. */ | |
421 | struct line_header | |
422 | { | |
423 | unsigned int total_length; | |
424 | unsigned short version; | |
425 | unsigned int header_length; | |
426 | unsigned char minimum_instruction_length; | |
427 | unsigned char default_is_stmt; | |
428 | int line_base; | |
429 | unsigned char line_range; | |
430 | unsigned char opcode_base; | |
431 | ||
432 | /* standard_opcode_lengths[i] is the number of operands for the | |
433 | standard opcode whose value is i. This means that | |
434 | standard_opcode_lengths[0] is unused, and the last meaningful | |
435 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
436 | unsigned char *standard_opcode_lengths; | |
437 | ||
438 | /* The include_directories table. NOTE! These strings are not | |
439 | allocated with xmalloc; instead, they are pointers into | |
440 | debug_line_buffer. If you try to free them, `free' will get | |
441 | indigestion. */ | |
442 | unsigned int num_include_dirs, include_dirs_size; | |
443 | char **include_dirs; | |
444 | ||
445 | /* The file_names table. NOTE! These strings are not allocated | |
446 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
447 | Don't try to free them directly. */ | |
448 | unsigned int num_file_names, file_names_size; | |
449 | struct file_entry | |
c906108c | 450 | { |
debd256d JB |
451 | char *name; |
452 | unsigned int dir_index; | |
453 | unsigned int mod_time; | |
454 | unsigned int length; | |
aaa75496 | 455 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 456 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
457 | } *file_names; |
458 | ||
459 | /* The start and end of the statement program following this | |
6502dd73 | 460 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 461 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 462 | }; |
c906108c SS |
463 | |
464 | /* When we construct a partial symbol table entry we only | |
465 | need this much information. */ | |
466 | struct partial_die_info | |
467 | { | |
72bf9492 | 468 | /* Offset of this DIE. */ |
c906108c | 469 | unsigned int offset; |
72bf9492 DJ |
470 | |
471 | /* DWARF-2 tag for this DIE. */ | |
472 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
473 | ||
72bf9492 DJ |
474 | /* Assorted flags describing the data found in this DIE. */ |
475 | unsigned int has_children : 1; | |
476 | unsigned int is_external : 1; | |
477 | unsigned int is_declaration : 1; | |
478 | unsigned int has_type : 1; | |
479 | unsigned int has_specification : 1; | |
480 | unsigned int has_pc_info : 1; | |
481 | ||
482 | /* Flag set if the SCOPE field of this structure has been | |
483 | computed. */ | |
484 | unsigned int scope_set : 1; | |
485 | ||
fa4028e9 JB |
486 | /* Flag set if the DIE has a byte_size attribute. */ |
487 | unsigned int has_byte_size : 1; | |
488 | ||
72bf9492 DJ |
489 | /* The name of this DIE. Normally the value of DW_AT_name, but |
490 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
491 | other fashion. */ | |
c906108c | 492 | char *name; |
72bf9492 DJ |
493 | |
494 | /* The scope to prepend to our children. This is generally | |
495 | allocated on the comp_unit_obstack, so will disappear | |
496 | when this compilation unit leaves the cache. */ | |
497 | char *scope; | |
498 | ||
499 | /* The location description associated with this DIE, if any. */ | |
500 | struct dwarf_block *locdesc; | |
501 | ||
502 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
503 | CORE_ADDR lowpc; |
504 | CORE_ADDR highpc; | |
72bf9492 | 505 | |
93311388 | 506 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 507 | DW_AT_sibling, if any. */ |
fe1b8b76 | 508 | gdb_byte *sibling; |
72bf9492 DJ |
509 | |
510 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
511 | DW_AT_specification (or DW_AT_abstract_origin or | |
512 | DW_AT_extension). */ | |
513 | unsigned int spec_offset; | |
514 | ||
515 | /* Pointers to this DIE's parent, first child, and next sibling, | |
516 | if any. */ | |
517 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
518 | }; |
519 | ||
520 | /* This data structure holds the information of an abbrev. */ | |
521 | struct abbrev_info | |
522 | { | |
523 | unsigned int number; /* number identifying abbrev */ | |
524 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
525 | unsigned short has_children; /* boolean */ |
526 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
527 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
528 | struct abbrev_info *next; /* next in chain */ | |
529 | }; | |
530 | ||
531 | struct attr_abbrev | |
532 | { | |
9d25dd43 DE |
533 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
534 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
535 | }; |
536 | ||
b60c80d6 DJ |
537 | /* Attributes have a name and a value */ |
538 | struct attribute | |
539 | { | |
9d25dd43 | 540 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
541 | ENUM_BITFIELD(dwarf_form) form : 15; |
542 | ||
543 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
544 | field should be in u.str (existing only for DW_STRING) but it is kept | |
545 | here for better struct attribute alignment. */ | |
546 | unsigned int string_is_canonical : 1; | |
547 | ||
b60c80d6 DJ |
548 | union |
549 | { | |
550 | char *str; | |
551 | struct dwarf_block *blk; | |
43bbcdc2 PH |
552 | ULONGEST unsnd; |
553 | LONGEST snd; | |
b60c80d6 | 554 | CORE_ADDR addr; |
348e048f | 555 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
556 | } |
557 | u; | |
558 | }; | |
559 | ||
c906108c SS |
560 | /* This data structure holds a complete die structure. */ |
561 | struct die_info | |
562 | { | |
76815b17 DE |
563 | /* DWARF-2 tag for this DIE. */ |
564 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
565 | ||
566 | /* Number of attributes */ | |
567 | unsigned short num_attrs; | |
568 | ||
569 | /* Abbrev number */ | |
570 | unsigned int abbrev; | |
571 | ||
93311388 | 572 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 573 | unsigned int offset; |
78ba4af6 JB |
574 | |
575 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
576 | points to this die's parent; CHILD points to the first child of | |
577 | this node; and all the children of a given node are chained | |
578 | together via their SIBLING fields, terminated by a die whose | |
579 | tag is zero. */ | |
639d11d3 DC |
580 | struct die_info *child; /* Its first child, if any. */ |
581 | struct die_info *sibling; /* Its next sibling, if any. */ | |
582 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 583 | |
b60c80d6 DJ |
584 | /* An array of attributes, with NUM_ATTRS elements. There may be |
585 | zero, but it's not common and zero-sized arrays are not | |
586 | sufficiently portable C. */ | |
587 | struct attribute attrs[1]; | |
c906108c SS |
588 | }; |
589 | ||
5fb290d7 DJ |
590 | struct function_range |
591 | { | |
592 | const char *name; | |
593 | CORE_ADDR lowpc, highpc; | |
594 | int seen_line; | |
595 | struct function_range *next; | |
596 | }; | |
597 | ||
c906108c SS |
598 | /* Get at parts of an attribute structure */ |
599 | ||
600 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 601 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
602 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
603 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
604 | #define DW_SND(attr) ((attr)->u.snd) | |
605 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 606 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c SS |
607 | |
608 | /* Blocks are a bunch of untyped bytes. */ | |
609 | struct dwarf_block | |
610 | { | |
611 | unsigned int size; | |
fe1b8b76 | 612 | gdb_byte *data; |
c906108c SS |
613 | }; |
614 | ||
c906108c SS |
615 | #ifndef ATTR_ALLOC_CHUNK |
616 | #define ATTR_ALLOC_CHUNK 4 | |
617 | #endif | |
618 | ||
c906108c SS |
619 | /* Allocate fields for structs, unions and enums in this size. */ |
620 | #ifndef DW_FIELD_ALLOC_CHUNK | |
621 | #define DW_FIELD_ALLOC_CHUNK 4 | |
622 | #endif | |
623 | ||
c906108c SS |
624 | /* A zeroed version of a partial die for initialization purposes. */ |
625 | static struct partial_die_info zeroed_partial_die; | |
626 | ||
c906108c SS |
627 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
628 | but this would require a corresponding change in unpack_field_as_long | |
629 | and friends. */ | |
630 | static int bits_per_byte = 8; | |
631 | ||
632 | /* The routines that read and process dies for a C struct or C++ class | |
633 | pass lists of data member fields and lists of member function fields | |
634 | in an instance of a field_info structure, as defined below. */ | |
635 | struct field_info | |
c5aa993b JM |
636 | { |
637 | /* List of data member and baseclasses fields. */ | |
638 | struct nextfield | |
639 | { | |
640 | struct nextfield *next; | |
641 | int accessibility; | |
642 | int virtuality; | |
643 | struct field field; | |
644 | } | |
7d0ccb61 | 645 | *fields, *baseclasses; |
c906108c | 646 | |
7d0ccb61 | 647 | /* Number of fields (including baseclasses). */ |
c5aa993b | 648 | int nfields; |
c906108c | 649 | |
c5aa993b JM |
650 | /* Number of baseclasses. */ |
651 | int nbaseclasses; | |
c906108c | 652 | |
c5aa993b JM |
653 | /* Set if the accesibility of one of the fields is not public. */ |
654 | int non_public_fields; | |
c906108c | 655 | |
c5aa993b JM |
656 | /* Member function fields array, entries are allocated in the order they |
657 | are encountered in the object file. */ | |
658 | struct nextfnfield | |
659 | { | |
660 | struct nextfnfield *next; | |
661 | struct fn_field fnfield; | |
662 | } | |
663 | *fnfields; | |
c906108c | 664 | |
c5aa993b JM |
665 | /* Member function fieldlist array, contains name of possibly overloaded |
666 | member function, number of overloaded member functions and a pointer | |
667 | to the head of the member function field chain. */ | |
668 | struct fnfieldlist | |
669 | { | |
670 | char *name; | |
671 | int length; | |
672 | struct nextfnfield *head; | |
673 | } | |
674 | *fnfieldlists; | |
c906108c | 675 | |
c5aa993b JM |
676 | /* Number of entries in the fnfieldlists array. */ |
677 | int nfnfields; | |
678 | }; | |
c906108c | 679 | |
10b3939b DJ |
680 | /* One item on the queue of compilation units to read in full symbols |
681 | for. */ | |
682 | struct dwarf2_queue_item | |
683 | { | |
684 | struct dwarf2_per_cu_data *per_cu; | |
685 | struct dwarf2_queue_item *next; | |
686 | }; | |
687 | ||
688 | /* The current queue. */ | |
689 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
690 | ||
ae038cb0 DJ |
691 | /* Loaded secondary compilation units are kept in memory until they |
692 | have not been referenced for the processing of this many | |
693 | compilation units. Set this to zero to disable caching. Cache | |
694 | sizes of up to at least twenty will improve startup time for | |
695 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
696 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
697 | static void |
698 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
699 | struct cmd_list_element *c, const char *value) | |
700 | { | |
701 | fprintf_filtered (file, _("\ | |
702 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
703 | value); | |
704 | } | |
705 | ||
ae038cb0 | 706 | |
c906108c SS |
707 | /* Various complaints about symbol reading that don't abort the process */ |
708 | ||
4d3c2250 KB |
709 | static void |
710 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 711 | { |
4d3c2250 | 712 | complaint (&symfile_complaints, |
e2e0b3e5 | 713 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
714 | } |
715 | ||
25e43795 DJ |
716 | static void |
717 | dwarf2_debug_line_missing_file_complaint (void) | |
718 | { | |
719 | complaint (&symfile_complaints, | |
720 | _(".debug_line section has line data without a file")); | |
721 | } | |
722 | ||
59205f5a JB |
723 | static void |
724 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
725 | { | |
726 | complaint (&symfile_complaints, | |
727 | _(".debug_line section has line program sequence without an end")); | |
728 | } | |
729 | ||
4d3c2250 KB |
730 | static void |
731 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 732 | { |
e2e0b3e5 | 733 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
734 | } |
735 | ||
4d3c2250 KB |
736 | static void |
737 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
738 | int arg3) | |
2e276125 | 739 | { |
4d3c2250 | 740 | complaint (&symfile_complaints, |
e2e0b3e5 | 741 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
742 | arg2, arg3); |
743 | } | |
744 | ||
745 | static void | |
746 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 747 | { |
4d3c2250 | 748 | complaint (&symfile_complaints, |
e2e0b3e5 | 749 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
750 | } |
751 | ||
752 | static void | |
753 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 754 | { |
4d3c2250 | 755 | complaint (&symfile_complaints, |
e2e0b3e5 | 756 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
757 | arg1); |
758 | } | |
759 | ||
760 | static void | |
761 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 762 | { |
4d3c2250 | 763 | complaint (&symfile_complaints, |
e2e0b3e5 | 764 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 765 | } |
c906108c | 766 | |
c906108c SS |
767 | /* local function prototypes */ |
768 | ||
4efb68b1 | 769 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
770 | |
771 | #if 0 | |
c67a9c90 | 772 | static void dwarf2_build_psymtabs_easy (struct objfile *); |
c906108c SS |
773 | #endif |
774 | ||
aaa75496 JB |
775 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
776 | struct objfile *); | |
777 | ||
778 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
d85a05f0 | 779 | struct die_info *, |
aaa75496 JB |
780 | struct partial_symtab *); |
781 | ||
c67a9c90 | 782 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 783 | |
72bf9492 DJ |
784 | static void scan_partial_symbols (struct partial_die_info *, |
785 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 786 | int, struct dwarf2_cu *); |
c906108c | 787 | |
72bf9492 DJ |
788 | static void add_partial_symbol (struct partial_die_info *, |
789 | struct dwarf2_cu *); | |
63d06c5c | 790 | |
72bf9492 | 791 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 792 | |
72bf9492 DJ |
793 | static void add_partial_namespace (struct partial_die_info *pdi, |
794 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 795 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 796 | |
5d7cb8df JK |
797 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
798 | CORE_ADDR *highpc, int need_pc, | |
799 | struct dwarf2_cu *cu); | |
800 | ||
72bf9492 DJ |
801 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
802 | struct dwarf2_cu *cu); | |
91c24f0a | 803 | |
bc30ff58 JB |
804 | static void add_partial_subprogram (struct partial_die_info *pdi, |
805 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 806 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 807 | |
fe1b8b76 | 808 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
809 | gdb_byte *buffer, gdb_byte *info_ptr, |
810 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 811 | |
a14ed312 | 812 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 813 | |
a14ed312 | 814 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 815 | |
e7c27a73 | 816 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 817 | |
f3dd6933 | 818 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 819 | |
fe1b8b76 | 820 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 821 | struct dwarf2_cu *); |
72bf9492 | 822 | |
57349743 | 823 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 824 | struct dwarf2_cu *); |
c906108c | 825 | |
93311388 DE |
826 | static struct partial_die_info *load_partial_dies (bfd *, |
827 | gdb_byte *, gdb_byte *, | |
828 | int, struct dwarf2_cu *); | |
72bf9492 | 829 | |
fe1b8b76 | 830 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
831 | struct abbrev_info *abbrev, |
832 | unsigned int, bfd *, | |
833 | gdb_byte *, gdb_byte *, | |
834 | struct dwarf2_cu *); | |
c906108c | 835 | |
c764a876 | 836 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 837 | struct dwarf2_cu *); |
72bf9492 DJ |
838 | |
839 | static void fixup_partial_die (struct partial_die_info *, | |
840 | struct dwarf2_cu *); | |
841 | ||
fe1b8b76 JB |
842 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
843 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 844 | |
fe1b8b76 JB |
845 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
846 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 847 | |
fe1b8b76 | 848 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 849 | |
fe1b8b76 | 850 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 851 | |
fe1b8b76 | 852 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 853 | |
fe1b8b76 | 854 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 855 | |
93311388 | 856 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 857 | |
fe1b8b76 | 858 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 859 | unsigned int *); |
c906108c | 860 | |
c764a876 DE |
861 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
862 | ||
863 | static LONGEST read_checked_initial_length_and_offset | |
864 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
865 | unsigned int *, unsigned int *); | |
613e1657 | 866 | |
fe1b8b76 | 867 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
868 | unsigned int *); |
869 | ||
870 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 871 | |
fe1b8b76 | 872 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 873 | |
fe1b8b76 | 874 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 875 | |
fe1b8b76 JB |
876 | static char *read_indirect_string (bfd *, gdb_byte *, |
877 | const struct comp_unit_head *, | |
878 | unsigned int *); | |
4bdf3d34 | 879 | |
fe1b8b76 | 880 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 881 | |
fe1b8b76 | 882 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 883 | |
fe1b8b76 | 884 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 885 | |
e142c38c | 886 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 887 | |
e142c38c DJ |
888 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
889 | struct dwarf2_cu *); | |
c906108c | 890 | |
348e048f DE |
891 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
892 | unsigned int, | |
893 | struct dwarf2_cu *); | |
894 | ||
05cf31d1 JB |
895 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
896 | struct dwarf2_cu *cu); | |
897 | ||
e142c38c | 898 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 899 | |
e142c38c | 900 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 901 | struct dwarf2_cu **); |
63d06c5c | 902 | |
debd256d JB |
903 | static void free_line_header (struct line_header *lh); |
904 | ||
aaa75496 JB |
905 | static void add_file_name (struct line_header *, char *, unsigned int, |
906 | unsigned int, unsigned int); | |
907 | ||
debd256d JB |
908 | static struct line_header *(dwarf_decode_line_header |
909 | (unsigned int offset, | |
e7c27a73 | 910 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
911 | |
912 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 913 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 914 | |
4f1520fb | 915 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 916 | |
a14ed312 | 917 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 918 | struct dwarf2_cu *); |
c906108c | 919 | |
a14ed312 | 920 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 921 | struct dwarf2_cu *); |
c906108c | 922 | |
2df3850c JM |
923 | static void dwarf2_const_value_data (struct attribute *attr, |
924 | struct symbol *sym, | |
925 | int bits); | |
926 | ||
e7c27a73 | 927 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 928 | |
b4ba55a1 JB |
929 | static int need_gnat_info (struct dwarf2_cu *); |
930 | ||
931 | static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *); | |
932 | ||
933 | static void set_descriptive_type (struct type *, struct die_info *, | |
934 | struct dwarf2_cu *); | |
935 | ||
e7c27a73 DJ |
936 | static struct type *die_containing_type (struct die_info *, |
937 | struct dwarf2_cu *); | |
c906108c | 938 | |
e7c27a73 | 939 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 940 | |
f792889a | 941 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 942 | |
086ed43d | 943 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 944 | |
fe1b8b76 JB |
945 | static char *typename_concat (struct obstack *, |
946 | const char *prefix, | |
947 | const char *suffix, | |
987504bb | 948 | struct dwarf2_cu *); |
63d06c5c | 949 | |
e7c27a73 | 950 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 951 | |
348e048f DE |
952 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
953 | ||
e7c27a73 | 954 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 955 | |
e7c27a73 | 956 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 957 | |
ff013f42 JK |
958 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
959 | struct dwarf2_cu *, struct partial_symtab *); | |
960 | ||
a14ed312 | 961 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
962 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
963 | struct partial_symtab *); | |
c906108c | 964 | |
fae299cd DC |
965 | static void get_scope_pc_bounds (struct die_info *, |
966 | CORE_ADDR *, CORE_ADDR *, | |
967 | struct dwarf2_cu *); | |
968 | ||
801e3a5b JB |
969 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
970 | CORE_ADDR, struct dwarf2_cu *); | |
971 | ||
a14ed312 | 972 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 973 | struct dwarf2_cu *); |
c906108c | 974 | |
a14ed312 | 975 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 976 | struct type *, struct dwarf2_cu *); |
c906108c | 977 | |
a14ed312 | 978 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 979 | struct die_info *, struct type *, |
e7c27a73 | 980 | struct dwarf2_cu *); |
c906108c | 981 | |
a14ed312 | 982 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 983 | struct type *, struct dwarf2_cu *); |
c906108c | 984 | |
134d01f1 | 985 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 986 | |
0114d602 DJ |
987 | static const char *determine_class_name (struct die_info *die, |
988 | struct dwarf2_cu *cu); | |
8176b9b8 | 989 | |
e7c27a73 | 990 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 991 | |
e7c27a73 | 992 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 993 | |
5d7cb8df JK |
994 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
995 | ||
27aa8d6a SW |
996 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
997 | ||
38d518c9 | 998 | static const char *namespace_name (struct die_info *die, |
e142c38c | 999 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1000 | |
134d01f1 | 1001 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1002 | |
e7c27a73 | 1003 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1004 | |
7ca2d3a3 DL |
1005 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
1006 | struct dwarf2_cu *); | |
1007 | ||
93311388 | 1008 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1009 | |
93311388 DE |
1010 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1011 | gdb_byte *info_ptr, | |
d97bc12b DE |
1012 | gdb_byte **new_info_ptr, |
1013 | struct die_info *parent); | |
1014 | ||
93311388 DE |
1015 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1016 | gdb_byte *info_ptr, | |
fe1b8b76 | 1017 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1018 | struct die_info *parent); |
1019 | ||
93311388 DE |
1020 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1021 | gdb_byte *info_ptr, | |
fe1b8b76 | 1022 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1023 | struct die_info *parent); |
1024 | ||
93311388 DE |
1025 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1026 | struct die_info **, gdb_byte *, | |
1027 | int *); | |
1028 | ||
e7c27a73 | 1029 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1030 | |
e142c38c | 1031 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 1032 | |
71c25dea TT |
1033 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1034 | struct obstack *); | |
1035 | ||
e142c38c | 1036 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1037 | |
e142c38c | 1038 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1039 | struct dwarf2_cu **); |
9219021c | 1040 | |
a14ed312 | 1041 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1042 | |
a14ed312 | 1043 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1044 | |
a14ed312 | 1045 | static char *dwarf_form_name (unsigned int); |
c906108c | 1046 | |
a14ed312 | 1047 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 1048 | |
a14ed312 | 1049 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1050 | |
a14ed312 | 1051 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1052 | |
1053 | #if 0 | |
a14ed312 | 1054 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1055 | #endif |
1056 | ||
f9aca02d | 1057 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1058 | |
d97bc12b DE |
1059 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1060 | ||
1061 | static void dump_die_for_error (struct die_info *); | |
1062 | ||
1063 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1064 | struct die_info *); | |
c906108c | 1065 | |
d97bc12b | 1066 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1067 | |
51545339 | 1068 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1069 | struct dwarf2_cu *); |
c906108c | 1070 | |
93311388 DE |
1071 | static int is_ref_attr (struct attribute *); |
1072 | ||
c764a876 | 1073 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1074 | |
43bbcdc2 | 1075 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1076 | |
348e048f DE |
1077 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1078 | struct attribute *, | |
1079 | struct dwarf2_cu **); | |
1080 | ||
10b3939b DJ |
1081 | static struct die_info *follow_die_ref (struct die_info *, |
1082 | struct attribute *, | |
f2f0e013 | 1083 | struct dwarf2_cu **); |
c906108c | 1084 | |
348e048f DE |
1085 | static struct die_info *follow_die_sig (struct die_info *, |
1086 | struct attribute *, | |
1087 | struct dwarf2_cu **); | |
1088 | ||
1089 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1090 | unsigned int offset); | |
1091 | ||
1092 | static void read_signatured_type (struct objfile *, | |
1093 | struct signatured_type *type_sig); | |
1094 | ||
c906108c SS |
1095 | /* memory allocation interface */ |
1096 | ||
7b5a2f43 | 1097 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1098 | |
f3dd6933 | 1099 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1100 | |
b60c80d6 | 1101 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1102 | |
e142c38c | 1103 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1104 | |
e142c38c DJ |
1105 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1106 | struct dwarf2_cu *); | |
5fb290d7 | 1107 | |
2e276125 | 1108 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1109 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1110 | |
8e19ed76 PS |
1111 | static int attr_form_is_block (struct attribute *); |
1112 | ||
3690dd37 JB |
1113 | static int attr_form_is_section_offset (struct attribute *); |
1114 | ||
1115 | static int attr_form_is_constant (struct attribute *); | |
1116 | ||
93e7bd98 DJ |
1117 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1118 | struct symbol *sym, | |
1119 | struct dwarf2_cu *cu); | |
4c2df51b | 1120 | |
93311388 DE |
1121 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1122 | struct abbrev_info *abbrev, | |
1123 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1124 | |
72bf9492 DJ |
1125 | static void free_stack_comp_unit (void *); |
1126 | ||
72bf9492 DJ |
1127 | static hashval_t partial_die_hash (const void *item); |
1128 | ||
1129 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1130 | ||
ae038cb0 | 1131 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1132 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1133 | |
1134 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1135 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1136 | |
93311388 DE |
1137 | static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); |
1138 | ||
ae038cb0 DJ |
1139 | static void free_one_comp_unit (void *); |
1140 | ||
1141 | static void free_cached_comp_units (void *); | |
1142 | ||
1143 | static void age_cached_comp_units (void); | |
1144 | ||
1145 | static void free_one_cached_comp_unit (void *); | |
1146 | ||
f792889a DJ |
1147 | static struct type *set_die_type (struct die_info *, struct type *, |
1148 | struct dwarf2_cu *); | |
1c379e20 | 1149 | |
ae038cb0 DJ |
1150 | static void create_all_comp_units (struct objfile *); |
1151 | ||
93311388 DE |
1152 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1153 | struct objfile *); | |
10b3939b DJ |
1154 | |
1155 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1156 | ||
1157 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1158 | struct dwarf2_per_cu_data *); | |
1159 | ||
ae038cb0 DJ |
1160 | static void dwarf2_mark (struct dwarf2_cu *); |
1161 | ||
1162 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1163 | ||
f792889a | 1164 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1165 | |
c906108c SS |
1166 | /* Try to locate the sections we need for DWARF 2 debugging |
1167 | information and return true if we have enough to do something. */ | |
1168 | ||
1169 | int | |
6502dd73 | 1170 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1171 | { |
6502dd73 DJ |
1172 | struct dwarf2_per_objfile *data; |
1173 | ||
1174 | /* Initialize per-objfile state. */ | |
1175 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1176 | memset (data, 0, sizeof (*data)); | |
1177 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1178 | dwarf2_per_objfile = data; | |
1179 | ||
6502dd73 | 1180 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
dce234bc | 1181 | return (data->info.asection != NULL && data->abbrev.asection != NULL); |
c906108c SS |
1182 | } |
1183 | ||
233a11ab CS |
1184 | /* When loading sections, we can either look for ".<name>", or for |
1185 | * ".z<name>", which indicates a compressed section. */ | |
1186 | ||
1187 | static int | |
dce234bc | 1188 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1189 | { |
dce234bc PP |
1190 | return (section_name[0] == '.' |
1191 | && (strcmp (section_name + 1, name) == 0 | |
1192 | || (section_name[1] == 'z' | |
1193 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1194 | } |
1195 | ||
c906108c SS |
1196 | /* This function is mapped across the sections and remembers the |
1197 | offset and size of each of the debugging sections we are interested | |
1198 | in. */ | |
1199 | ||
1200 | static void | |
72dca2f5 | 1201 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1202 | { |
dce234bc | 1203 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1204 | { |
dce234bc PP |
1205 | dwarf2_per_objfile->info.asection = sectp; |
1206 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1207 | } |
dce234bc | 1208 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1209 | { |
dce234bc PP |
1210 | dwarf2_per_objfile->abbrev.asection = sectp; |
1211 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1212 | } |
dce234bc | 1213 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1214 | { |
dce234bc PP |
1215 | dwarf2_per_objfile->line.asection = sectp; |
1216 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1217 | } |
dce234bc | 1218 | else if (section_is_p (sectp->name, PUBNAMES_SECTION)) |
c906108c | 1219 | { |
dce234bc PP |
1220 | dwarf2_per_objfile->pubnames.asection = sectp; |
1221 | dwarf2_per_objfile->pubnames.size = bfd_get_section_size (sectp); | |
c906108c | 1222 | } |
dce234bc | 1223 | else if (section_is_p (sectp->name, ARANGES_SECTION)) |
c906108c | 1224 | { |
dce234bc PP |
1225 | dwarf2_per_objfile->aranges.asection = sectp; |
1226 | dwarf2_per_objfile->aranges.size = bfd_get_section_size (sectp); | |
c906108c | 1227 | } |
dce234bc | 1228 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1229 | { |
dce234bc PP |
1230 | dwarf2_per_objfile->loc.asection = sectp; |
1231 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1232 | } |
dce234bc | 1233 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1234 | { |
dce234bc PP |
1235 | dwarf2_per_objfile->macinfo.asection = sectp; |
1236 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1237 | } |
dce234bc | 1238 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1239 | { |
dce234bc PP |
1240 | dwarf2_per_objfile->str.asection = sectp; |
1241 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1242 | } |
dce234bc | 1243 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1244 | { |
dce234bc PP |
1245 | dwarf2_per_objfile->frame.asection = sectp; |
1246 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1247 | } |
dce234bc | 1248 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1249 | { |
3799ccc6 EZ |
1250 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1251 | if (aflag & SEC_HAS_CONTENTS) | |
1252 | { | |
dce234bc PP |
1253 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1254 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1255 | } |
b6af0555 | 1256 | } |
dce234bc | 1257 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1258 | { |
dce234bc PP |
1259 | dwarf2_per_objfile->ranges.asection = sectp; |
1260 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1261 | } |
348e048f DE |
1262 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1263 | { | |
1264 | dwarf2_per_objfile->types.asection = sectp; | |
1265 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1266 | } | |
dce234bc | 1267 | |
72dca2f5 FR |
1268 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1269 | && bfd_section_vma (abfd, sectp) == 0) | |
1270 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1271 | } |
1272 | ||
dce234bc PP |
1273 | /* Decompress a section that was compressed using zlib. Store the |
1274 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1275 | |
1276 | static void | |
dce234bc PP |
1277 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1278 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1279 | { | |
1280 | bfd *abfd = objfile->obfd; | |
1281 | #ifndef HAVE_ZLIB_H | |
1282 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1283 | "is disabled in this copy of GDB"), | |
1284 | bfd_get_filename (abfd)); | |
1285 | #else | |
1286 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1287 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1288 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1289 | bfd_size_type uncompressed_size; |
1290 | gdb_byte *uncompressed_buffer; | |
1291 | z_stream strm; | |
1292 | int rc; | |
1293 | int header_size = 12; | |
1294 | ||
1295 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1296 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1297 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1298 | bfd_get_filename (abfd)); | |
1299 | ||
1300 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1301 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1302 | if (compressed_size < header_size | |
1303 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1304 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1305 | bfd_get_filename (abfd)); | |
1306 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1307 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1308 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1309 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1310 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1311 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1312 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1313 | uncompressed_size += compressed_buffer[11]; | |
1314 | ||
1315 | /* It is possible the section consists of several compressed | |
1316 | buffers concatenated together, so we uncompress in a loop. */ | |
1317 | strm.zalloc = NULL; | |
1318 | strm.zfree = NULL; | |
1319 | strm.opaque = NULL; | |
1320 | strm.avail_in = compressed_size - header_size; | |
1321 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1322 | strm.avail_out = uncompressed_size; | |
1323 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1324 | uncompressed_size); | |
1325 | rc = inflateInit (&strm); | |
1326 | while (strm.avail_in > 0) | |
1327 | { | |
1328 | if (rc != Z_OK) | |
1329 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1330 | bfd_get_filename (abfd), rc); | |
1331 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1332 | + (uncompressed_size - strm.avail_out)); | |
1333 | rc = inflate (&strm, Z_FINISH); | |
1334 | if (rc != Z_STREAM_END) | |
1335 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1336 | bfd_get_filename (abfd), rc); | |
1337 | rc = inflateReset (&strm); | |
1338 | } | |
1339 | rc = inflateEnd (&strm); | |
1340 | if (rc != Z_OK | |
1341 | || strm.avail_out != 0) | |
1342 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1343 | bfd_get_filename (abfd), rc); | |
1344 | ||
affddf13 | 1345 | do_cleanups (cleanup); |
dce234bc PP |
1346 | *outbuf = uncompressed_buffer; |
1347 | *outsize = uncompressed_size; | |
1348 | #endif | |
233a11ab CS |
1349 | } |
1350 | ||
dce234bc PP |
1351 | /* Read the contents of the section SECTP from object file specified by |
1352 | OBJFILE, store info about the section into INFO. | |
1353 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1354 | |
dce234bc PP |
1355 | static void |
1356 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1357 | { |
dce234bc PP |
1358 | bfd *abfd = objfile->obfd; |
1359 | asection *sectp = info->asection; | |
1360 | gdb_byte *buf, *retbuf; | |
1361 | unsigned char header[4]; | |
c906108c | 1362 | |
dce234bc PP |
1363 | info->buffer = NULL; |
1364 | info->was_mmapped = 0; | |
188dd5d6 | 1365 | |
dce234bc PP |
1366 | if (info->asection == NULL || info->size == 0) |
1367 | return; | |
c906108c | 1368 | |
dce234bc PP |
1369 | /* Check if the file has a 4-byte header indicating compression. */ |
1370 | if (info->size > sizeof (header) | |
1371 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1372 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1373 | { | |
1374 | /* Upon decompression, update the buffer and its size. */ | |
1375 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1376 | { | |
1377 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1378 | &info->size); | |
1379 | return; | |
1380 | } | |
1381 | } | |
4bdf3d34 | 1382 | |
dce234bc PP |
1383 | #ifdef HAVE_MMAP |
1384 | if (pagesize == 0) | |
1385 | pagesize = getpagesize (); | |
2e276125 | 1386 | |
dce234bc PP |
1387 | /* Only try to mmap sections which are large enough: we don't want to |
1388 | waste space due to fragmentation. Also, only try mmap for sections | |
1389 | without relocations. */ | |
1390 | ||
1391 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1392 | { | |
1393 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1394 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1395 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1396 | MAP_PRIVATE, pg_offset); | |
1397 | ||
1398 | if (retbuf != MAP_FAILED) | |
1399 | { | |
1400 | info->was_mmapped = 1; | |
1401 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
1402 | return; | |
1403 | } | |
1404 | } | |
1405 | #endif | |
1406 | ||
1407 | /* If we get here, we are a normal, not-compressed section. */ | |
1408 | info->buffer = buf | |
1409 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1410 | ||
1411 | /* When debugging .o files, we may need to apply relocations; see | |
1412 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1413 | We never compress sections in .o files, so we only need to | |
1414 | try this when the section is not compressed. */ | |
1415 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); | |
1416 | if (retbuf != NULL) | |
1417 | { | |
1418 | info->buffer = retbuf; | |
1419 | return; | |
1420 | } | |
1421 | ||
1422 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1423 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1424 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1425 | bfd_get_filename (abfd)); | |
1426 | } | |
1427 | ||
1428 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1429 | SECTION_NAME. */ | |
af34e669 | 1430 | |
dce234bc PP |
1431 | void |
1432 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1433 | asection **sectp, gdb_byte **bufp, | |
1434 | bfd_size_type *sizep) | |
1435 | { | |
1436 | struct dwarf2_per_objfile *data | |
1437 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1438 | struct dwarf2_section_info *info; | |
1439 | if (section_is_p (section_name, EH_FRAME_SECTION)) | |
1440 | info = &data->eh_frame; | |
1441 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1442 | info = &data->frame; | |
0d53c4c4 | 1443 | else |
dce234bc PP |
1444 | gdb_assert (0); |
1445 | ||
1446 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1447 | /* We haven't read this section in yet. Do it now. */ | |
1448 | dwarf2_read_section (objfile, info); | |
1449 | ||
1450 | *sectp = info->asection; | |
1451 | *bufp = info->buffer; | |
1452 | *sizep = info->size; | |
1453 | } | |
1454 | ||
1455 | /* Build a partial symbol table. */ | |
1456 | ||
1457 | void | |
f29dff0a | 1458 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc PP |
1459 | { |
1460 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
1461 | dwarf2_read_section (objfile, &dwarf2_per_objfile->abbrev); | |
1462 | dwarf2_read_section (objfile, &dwarf2_per_objfile->line); | |
1463 | dwarf2_read_section (objfile, &dwarf2_per_objfile->str); | |
1464 | dwarf2_read_section (objfile, &dwarf2_per_objfile->macinfo); | |
1465 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); | |
348e048f | 1466 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
dce234bc PP |
1467 | dwarf2_read_section (objfile, &dwarf2_per_objfile->loc); |
1468 | dwarf2_read_section (objfile, &dwarf2_per_objfile->eh_frame); | |
1469 | dwarf2_read_section (objfile, &dwarf2_per_objfile->frame); | |
0d53c4c4 | 1470 | |
f29dff0a | 1471 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
1472 | { |
1473 | init_psymbol_list (objfile, 1024); | |
1474 | } | |
1475 | ||
1476 | #if 0 | |
1477 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1478 | { | |
d4f3574e | 1479 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1480 | .debug_pubnames sections */ |
1481 | ||
c67a9c90 | 1482 | dwarf2_build_psymtabs_easy (objfile); |
c906108c SS |
1483 | } |
1484 | else | |
1485 | #endif | |
1486 | /* only test this case for now */ | |
c5aa993b | 1487 | { |
c906108c | 1488 | /* In this case we have to work a bit harder */ |
c67a9c90 | 1489 | dwarf2_build_psymtabs_hard (objfile); |
c906108c SS |
1490 | } |
1491 | } | |
1492 | ||
1493 | #if 0 | |
1494 | /* Build the partial symbol table from the information in the | |
1495 | .debug_pubnames and .debug_aranges sections. */ | |
1496 | ||
1497 | static void | |
c67a9c90 | 1498 | dwarf2_build_psymtabs_easy (struct objfile *objfile) |
c906108c SS |
1499 | { |
1500 | bfd *abfd = objfile->obfd; | |
1501 | char *aranges_buffer, *pubnames_buffer; | |
1502 | char *aranges_ptr, *pubnames_ptr; | |
1503 | unsigned int entry_length, version, info_offset, info_size; | |
1504 | ||
1505 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1506 | dwarf_pubnames_section); |
c906108c | 1507 | pubnames_ptr = pubnames_buffer; |
dce234bc | 1508 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames.size) |
c906108c | 1509 | { |
891d2f0b | 1510 | unsigned int bytes_read; |
613e1657 | 1511 | |
c764a876 | 1512 | entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read); |
613e1657 | 1513 | pubnames_ptr += bytes_read; |
c906108c SS |
1514 | version = read_1_byte (abfd, pubnames_ptr); |
1515 | pubnames_ptr += 1; | |
1516 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1517 | pubnames_ptr += 4; | |
1518 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1519 | pubnames_ptr += 4; | |
1520 | } | |
1521 | ||
1522 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1523 | dwarf_aranges_section); |
c906108c SS |
1524 | |
1525 | } | |
1526 | #endif | |
1527 | ||
45452591 DE |
1528 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
1529 | ||
1530 | static inline int | |
1531 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
1532 | { | |
1533 | unsigned int bottom = cu_header->offset; | |
1534 | unsigned int top = (cu_header->offset | |
1535 | + cu_header->length | |
1536 | + cu_header->initial_length_size); | |
1537 | return (offset >= bottom && offset < top); | |
1538 | } | |
1539 | ||
93311388 DE |
1540 | /* Read in the comp unit header information from the debug_info at info_ptr. |
1541 | NOTE: This leaves members offset, first_die_offset to be filled in | |
1542 | by the caller. */ | |
107d2387 | 1543 | |
fe1b8b76 | 1544 | static gdb_byte * |
107d2387 | 1545 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1546 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1547 | { |
1548 | int signed_addr; | |
891d2f0b | 1549 | unsigned int bytes_read; |
c764a876 DE |
1550 | |
1551 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
1552 | cu_header->initial_length_size = bytes_read; | |
1553 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 1554 | info_ptr += bytes_read; |
107d2387 AC |
1555 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1556 | info_ptr += 2; | |
613e1657 | 1557 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 1558 | &bytes_read); |
613e1657 | 1559 | info_ptr += bytes_read; |
107d2387 AC |
1560 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1561 | info_ptr += 1; | |
1562 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1563 | if (signed_addr < 0) | |
8e65ff28 | 1564 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1565 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 1566 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 1567 | |
107d2387 AC |
1568 | return info_ptr; |
1569 | } | |
1570 | ||
fe1b8b76 JB |
1571 | static gdb_byte * |
1572 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 1573 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
1574 | bfd *abfd) |
1575 | { | |
fe1b8b76 | 1576 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1577 | |
1578 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1579 | ||
2b949cb6 | 1580 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1581 | error (_("Dwarf Error: wrong version in compilation unit header " |
1582 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1583 | 2, bfd_get_filename (abfd)); |
1584 | ||
dce234bc | 1585 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
1586 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1587 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 1588 | (long) header->abbrev_offset, |
93311388 | 1589 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
1590 | bfd_get_filename (abfd)); |
1591 | ||
1592 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 1593 | > buffer + buffer_size) |
8a3fe4f8 AC |
1594 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1595 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 1596 | (long) header->length, |
93311388 | 1597 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
1598 | bfd_get_filename (abfd)); |
1599 | ||
1600 | return info_ptr; | |
1601 | } | |
1602 | ||
348e048f DE |
1603 | /* Read in the types comp unit header information from .debug_types entry at |
1604 | types_ptr. The result is a pointer to one past the end of the header. */ | |
1605 | ||
1606 | static gdb_byte * | |
1607 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
1608 | ULONGEST *signature, | |
1609 | gdb_byte *types_ptr, bfd *abfd) | |
1610 | { | |
1611 | unsigned int bytes_read; | |
1612 | gdb_byte *initial_types_ptr = types_ptr; | |
1613 | ||
1614 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; | |
1615 | ||
1616 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
1617 | ||
1618 | *signature = read_8_bytes (abfd, types_ptr); | |
1619 | types_ptr += 8; | |
1620 | types_ptr += cu_header->offset_size; | |
1621 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
1622 | ||
1623 | return types_ptr; | |
1624 | } | |
1625 | ||
aaa75496 JB |
1626 | /* Allocate a new partial symtab for file named NAME and mark this new |
1627 | partial symtab as being an include of PST. */ | |
1628 | ||
1629 | static void | |
1630 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1631 | struct objfile *objfile) | |
1632 | { | |
1633 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1634 | ||
1635 | subpst->section_offsets = pst->section_offsets; | |
1636 | subpst->textlow = 0; | |
1637 | subpst->texthigh = 0; | |
1638 | ||
1639 | subpst->dependencies = (struct partial_symtab **) | |
1640 | obstack_alloc (&objfile->objfile_obstack, | |
1641 | sizeof (struct partial_symtab *)); | |
1642 | subpst->dependencies[0] = pst; | |
1643 | subpst->number_of_dependencies = 1; | |
1644 | ||
1645 | subpst->globals_offset = 0; | |
1646 | subpst->n_global_syms = 0; | |
1647 | subpst->statics_offset = 0; | |
1648 | subpst->n_static_syms = 0; | |
1649 | subpst->symtab = NULL; | |
1650 | subpst->read_symtab = pst->read_symtab; | |
1651 | subpst->readin = 0; | |
1652 | ||
1653 | /* No private part is necessary for include psymtabs. This property | |
1654 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1655 | the regular ones. */ |
58a9656e | 1656 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1657 | } |
1658 | ||
1659 | /* Read the Line Number Program data and extract the list of files | |
1660 | included by the source file represented by PST. Build an include | |
d85a05f0 | 1661 | partial symtab for each of these included files. */ |
aaa75496 JB |
1662 | |
1663 | static void | |
1664 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 1665 | struct die_info *die, |
aaa75496 JB |
1666 | struct partial_symtab *pst) |
1667 | { | |
1668 | struct objfile *objfile = cu->objfile; | |
1669 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
1670 | struct line_header *lh = NULL; |
1671 | struct attribute *attr; | |
aaa75496 | 1672 | |
d85a05f0 DJ |
1673 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
1674 | if (attr) | |
1675 | { | |
1676 | unsigned int line_offset = DW_UNSND (attr); | |
1677 | lh = dwarf_decode_line_header (line_offset, abfd, cu); | |
1678 | } | |
aaa75496 JB |
1679 | if (lh == NULL) |
1680 | return; /* No linetable, so no includes. */ | |
1681 | ||
1682 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1683 | ||
1684 | free_line_header (lh); | |
1685 | } | |
1686 | ||
348e048f DE |
1687 | static hashval_t |
1688 | hash_type_signature (const void *item) | |
1689 | { | |
1690 | const struct signatured_type *type_sig = item; | |
1691 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ | |
1692 | return type_sig->signature; | |
1693 | } | |
1694 | ||
1695 | static int | |
1696 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
1697 | { | |
1698 | const struct signatured_type *lhs = item_lhs; | |
1699 | const struct signatured_type *rhs = item_rhs; | |
1700 | return lhs->signature == rhs->signature; | |
1701 | } | |
1702 | ||
1703 | /* Create the hash table of all entries in the .debug_types section. | |
1704 | The result is zero if there is an error (e.g. missing .debug_types section), | |
1705 | otherwise non-zero. */ | |
1706 | ||
1707 | static int | |
1708 | create_debug_types_hash_table (struct objfile *objfile) | |
1709 | { | |
1710 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer; | |
1711 | htab_t types_htab; | |
1712 | ||
1713 | if (info_ptr == NULL) | |
1714 | { | |
1715 | dwarf2_per_objfile->signatured_types = NULL; | |
1716 | return 0; | |
1717 | } | |
1718 | ||
1719 | types_htab = htab_create_alloc_ex (41, | |
1720 | hash_type_signature, | |
1721 | eq_type_signature, | |
1722 | NULL, | |
1723 | &objfile->objfile_obstack, | |
1724 | hashtab_obstack_allocate, | |
1725 | dummy_obstack_deallocate); | |
1726 | ||
1727 | if (dwarf2_die_debug) | |
1728 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
1729 | ||
1730 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
1731 | { | |
1732 | unsigned int offset; | |
1733 | unsigned int offset_size; | |
1734 | unsigned int type_offset; | |
1735 | unsigned int length, initial_length_size; | |
1736 | unsigned short version; | |
1737 | ULONGEST signature; | |
1738 | struct signatured_type *type_sig; | |
1739 | void **slot; | |
1740 | gdb_byte *ptr = info_ptr; | |
1741 | ||
1742 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
1743 | ||
1744 | /* We need to read the type's signature in order to build the hash | |
1745 | table, but we don't need to read anything else just yet. */ | |
1746 | ||
1747 | /* Sanity check to ensure entire cu is present. */ | |
1748 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
1749 | if (ptr + length + initial_length_size | |
1750 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
1751 | { | |
1752 | complaint (&symfile_complaints, | |
1753 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
1754 | break; | |
1755 | } | |
1756 | ||
1757 | offset_size = initial_length_size == 4 ? 4 : 8; | |
1758 | ptr += initial_length_size; | |
1759 | version = bfd_get_16 (objfile->obfd, ptr); | |
1760 | ptr += 2; | |
1761 | ptr += offset_size; /* abbrev offset */ | |
1762 | ptr += 1; /* address size */ | |
1763 | signature = bfd_get_64 (objfile->obfd, ptr); | |
1764 | ptr += 8; | |
1765 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
1766 | ||
1767 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
1768 | memset (type_sig, 0, sizeof (*type_sig)); | |
1769 | type_sig->signature = signature; | |
1770 | type_sig->offset = offset; | |
1771 | type_sig->type_offset = type_offset; | |
1772 | ||
1773 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
1774 | gdb_assert (slot != NULL); | |
1775 | *slot = type_sig; | |
1776 | ||
1777 | if (dwarf2_die_debug) | |
1778 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
1779 | offset, phex (signature, sizeof (signature))); | |
1780 | ||
1781 | info_ptr = info_ptr + initial_length_size + length; | |
1782 | } | |
1783 | ||
1784 | dwarf2_per_objfile->signatured_types = types_htab; | |
1785 | ||
1786 | return 1; | |
1787 | } | |
1788 | ||
1789 | /* Lookup a signature based type. | |
1790 | Returns NULL if SIG is not present in the table. */ | |
1791 | ||
1792 | static struct signatured_type * | |
1793 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
1794 | { | |
1795 | struct signatured_type find_entry, *entry; | |
1796 | ||
1797 | if (dwarf2_per_objfile->signatured_types == NULL) | |
1798 | { | |
1799 | complaint (&symfile_complaints, | |
1800 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
1801 | return 0; | |
1802 | } | |
1803 | ||
1804 | find_entry.signature = sig; | |
1805 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
1806 | return entry; | |
1807 | } | |
1808 | ||
d85a05f0 DJ |
1809 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
1810 | ||
1811 | static void | |
1812 | init_cu_die_reader (struct die_reader_specs *reader, | |
1813 | struct dwarf2_cu *cu) | |
1814 | { | |
1815 | reader->abfd = cu->objfile->obfd; | |
1816 | reader->cu = cu; | |
1817 | if (cu->per_cu->from_debug_types) | |
1818 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
1819 | else | |
1820 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
1821 | } | |
1822 | ||
1823 | /* Find the base address of the compilation unit for range lists and | |
1824 | location lists. It will normally be specified by DW_AT_low_pc. | |
1825 | In DWARF-3 draft 4, the base address could be overridden by | |
1826 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
1827 | compilation units with discontinuous ranges. */ | |
1828 | ||
1829 | static void | |
1830 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
1831 | { | |
1832 | struct attribute *attr; | |
1833 | ||
1834 | cu->base_known = 0; | |
1835 | cu->base_address = 0; | |
1836 | ||
1837 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
1838 | if (attr) | |
1839 | { | |
1840 | cu->base_address = DW_ADDR (attr); | |
1841 | cu->base_known = 1; | |
1842 | } | |
1843 | else | |
1844 | { | |
1845 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
1846 | if (attr) | |
1847 | { | |
1848 | cu->base_address = DW_ADDR (attr); | |
1849 | cu->base_known = 1; | |
1850 | } | |
1851 | } | |
1852 | } | |
1853 | ||
348e048f DE |
1854 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
1855 | to combine the common parts. | |
93311388 | 1856 | Process a compilation unit for a psymtab. |
348e048f DE |
1857 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
1858 | either .debug_info or debug_types. | |
93311388 DE |
1859 | INFO_PTR is a pointer to the start of the CU. |
1860 | Returns a pointer to the next CU. */ | |
aaa75496 | 1861 | |
93311388 DE |
1862 | static gdb_byte * |
1863 | process_psymtab_comp_unit (struct objfile *objfile, | |
1864 | struct dwarf2_per_cu_data *this_cu, | |
1865 | gdb_byte *buffer, gdb_byte *info_ptr, | |
1866 | unsigned int buffer_size) | |
c906108c | 1867 | { |
c906108c | 1868 | bfd *abfd = objfile->obfd; |
93311388 | 1869 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 1870 | struct die_info *comp_unit_die; |
c906108c | 1871 | struct partial_symtab *pst; |
5734ee8b | 1872 | CORE_ADDR baseaddr; |
93311388 DE |
1873 | struct cleanup *back_to_inner; |
1874 | struct dwarf2_cu cu; | |
93311388 | 1875 | unsigned int bytes_read; |
d85a05f0 DJ |
1876 | int has_children, has_pc_info; |
1877 | struct attribute *attr; | |
1878 | const char *name; | |
1879 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
1880 | struct die_reader_specs reader_specs; | |
c906108c | 1881 | |
93311388 DE |
1882 | memset (&cu, 0, sizeof (cu)); |
1883 | cu.objfile = objfile; | |
1884 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 1885 | |
93311388 | 1886 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 1887 | |
93311388 DE |
1888 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
1889 | buffer, buffer_size, | |
1890 | abfd); | |
10b3939b | 1891 | |
93311388 DE |
1892 | /* Complete the cu_header. */ |
1893 | cu.header.offset = beg_of_comp_unit - buffer; | |
1894 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 1895 | |
93311388 | 1896 | cu.list_in_scope = &file_symbols; |
af703f96 | 1897 | |
328c9494 DJ |
1898 | /* If this compilation unit was already read in, free the |
1899 | cached copy in order to read it in again. This is | |
1900 | necessary because we skipped some symbols when we first | |
1901 | read in the compilation unit (see load_partial_dies). | |
1902 | This problem could be avoided, but the benefit is | |
1903 | unclear. */ | |
1904 | if (this_cu->cu != NULL) | |
1905 | free_one_cached_comp_unit (this_cu->cu); | |
1906 | ||
1907 | /* Note that this is a pointer to our stack frame, being | |
1908 | added to a global data structure. It will be cleaned up | |
1909 | in free_stack_comp_unit when we finish with this | |
1910 | compilation unit. */ | |
1911 | this_cu->cu = &cu; | |
d85a05f0 DJ |
1912 | cu.per_cu = this_cu; |
1913 | ||
93311388 DE |
1914 | /* Read the abbrevs for this compilation unit into a table. */ |
1915 | dwarf2_read_abbrevs (abfd, &cu); | |
1916 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 1917 | |
93311388 | 1918 | /* Read the compilation unit die. */ |
348e048f DE |
1919 | if (this_cu->from_debug_types) |
1920 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
1921 | init_cu_die_reader (&reader_specs, &cu); |
1922 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
1923 | &has_children); | |
93311388 | 1924 | |
348e048f DE |
1925 | if (this_cu->from_debug_types) |
1926 | { | |
1927 | /* offset,length haven't been set yet for type units. */ | |
1928 | this_cu->offset = cu.header.offset; | |
1929 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
1930 | } | |
d85a05f0 | 1931 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 1932 | { |
93311388 DE |
1933 | info_ptr = (beg_of_comp_unit + cu.header.length |
1934 | + cu.header.initial_length_size); | |
1935 | do_cleanups (back_to_inner); | |
1936 | return info_ptr; | |
1937 | } | |
72bf9492 | 1938 | |
93311388 | 1939 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
1940 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
1941 | if (attr) | |
1942 | set_cu_language (DW_UNSND (attr), &cu); | |
1943 | else | |
1944 | set_cu_language (language_minimal, &cu); | |
c906108c | 1945 | |
93311388 | 1946 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 1947 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 1948 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 1949 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
1950 | /* TEXTLOW and TEXTHIGH are set below. */ |
1951 | 0, | |
1952 | objfile->global_psymbols.next, | |
1953 | objfile->static_psymbols.next); | |
72bf9492 | 1954 | |
d85a05f0 DJ |
1955 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
1956 | if (attr != NULL) | |
1957 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 1958 | |
93311388 | 1959 | pst->read_symtab_private = (char *) this_cu; |
72bf9492 | 1960 | |
93311388 | 1961 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 1962 | |
93311388 DE |
1963 | /* Store the function that reads in the rest of the symbol table */ |
1964 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 1965 | |
93311388 | 1966 | this_cu->psymtab = pst; |
c906108c | 1967 | |
d85a05f0 DJ |
1968 | dwarf2_find_base_address (comp_unit_die, &cu); |
1969 | ||
93311388 DE |
1970 | /* Possibly set the default values of LOWPC and HIGHPC from |
1971 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
1972 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
1973 | &best_highpc, &cu, pst); | |
1974 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
1975 | /* Store the contiguous range if it is not empty; it can be empty for |
1976 | CUs with no code. */ | |
1977 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
1978 | best_lowpc + baseaddr, |
1979 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
1980 | |
1981 | /* Check if comp unit has_children. | |
1982 | If so, read the rest of the partial symbols from this comp unit. | |
1983 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 1984 | if (has_children) |
93311388 DE |
1985 | { |
1986 | struct partial_die_info *first_die; | |
1987 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 1988 | |
93311388 DE |
1989 | lowpc = ((CORE_ADDR) -1); |
1990 | highpc = ((CORE_ADDR) 0); | |
c906108c | 1991 | |
93311388 | 1992 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 1993 | |
93311388 | 1994 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 1995 | ! has_pc_info, &cu); |
57c22c6c | 1996 | |
93311388 DE |
1997 | /* If we didn't find a lowpc, set it to highpc to avoid |
1998 | complaints from `maint check'. */ | |
1999 | if (lowpc == ((CORE_ADDR) -1)) | |
2000 | lowpc = highpc; | |
10b3939b | 2001 | |
93311388 DE |
2002 | /* If the compilation unit didn't have an explicit address range, |
2003 | then use the information extracted from its child dies. */ | |
d85a05f0 | 2004 | if (! has_pc_info) |
93311388 | 2005 | { |
d85a05f0 DJ |
2006 | best_lowpc = lowpc; |
2007 | best_highpc = highpc; | |
93311388 DE |
2008 | } |
2009 | } | |
d85a05f0 DJ |
2010 | pst->textlow = best_lowpc + baseaddr; |
2011 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 2012 | |
93311388 DE |
2013 | pst->n_global_syms = objfile->global_psymbols.next - |
2014 | (objfile->global_psymbols.list + pst->globals_offset); | |
2015 | pst->n_static_syms = objfile->static_psymbols.next - | |
2016 | (objfile->static_psymbols.list + pst->statics_offset); | |
2017 | sort_pst_symbols (pst); | |
c906108c | 2018 | |
93311388 DE |
2019 | info_ptr = (beg_of_comp_unit + cu.header.length |
2020 | + cu.header.initial_length_size); | |
ae038cb0 | 2021 | |
348e048f DE |
2022 | if (this_cu->from_debug_types) |
2023 | { | |
2024 | /* It's not clear we want to do anything with stmt lists here. | |
2025 | Waiting to see what gcc ultimately does. */ | |
2026 | } | |
d85a05f0 | 2027 | else |
93311388 DE |
2028 | { |
2029 | /* Get the list of files included in the current compilation unit, | |
2030 | and build a psymtab for each of them. */ | |
d85a05f0 | 2031 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 2032 | } |
ae038cb0 | 2033 | |
93311388 | 2034 | do_cleanups (back_to_inner); |
ae038cb0 | 2035 | |
93311388 DE |
2036 | return info_ptr; |
2037 | } | |
ff013f42 | 2038 | |
348e048f DE |
2039 | /* Traversal function for htab_traverse_noresize. |
2040 | Process one .debug_types comp-unit. */ | |
2041 | ||
2042 | static int | |
2043 | process_type_comp_unit (void **slot, void *info) | |
2044 | { | |
2045 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
2046 | struct objfile *objfile = (struct objfile *) info; | |
2047 | struct dwarf2_per_cu_data *this_cu; | |
2048 | ||
2049 | this_cu = &entry->per_cu; | |
2050 | this_cu->from_debug_types = 1; | |
2051 | ||
2052 | process_psymtab_comp_unit (objfile, this_cu, | |
2053 | dwarf2_per_objfile->types.buffer, | |
2054 | dwarf2_per_objfile->types.buffer + entry->offset, | |
2055 | dwarf2_per_objfile->types.size); | |
2056 | ||
2057 | return 1; | |
2058 | } | |
2059 | ||
2060 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
2061 | Build partial symbol tables for the .debug_types comp-units. */ | |
2062 | ||
2063 | static void | |
2064 | build_type_psymtabs (struct objfile *objfile) | |
2065 | { | |
2066 | if (! create_debug_types_hash_table (objfile)) | |
2067 | return; | |
2068 | ||
2069 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
2070 | process_type_comp_unit, objfile); | |
2071 | } | |
2072 | ||
93311388 DE |
2073 | /* Build the partial symbol table by doing a quick pass through the |
2074 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 2075 | |
93311388 | 2076 | static void |
c67a9c90 | 2077 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 DE |
2078 | { |
2079 | /* Instead of reading this into a big buffer, we should probably use | |
2080 | mmap() on architectures that support it. (FIXME) */ | |
2081 | bfd *abfd = objfile->obfd; | |
2082 | gdb_byte *info_ptr; | |
2083 | struct cleanup *back_to; | |
2084 | ||
2085 | info_ptr = dwarf2_per_objfile->info.buffer; | |
91c24f0a | 2086 | |
93311388 DE |
2087 | /* Any cached compilation units will be linked by the per-objfile |
2088 | read_in_chain. Make sure to free them when we're done. */ | |
2089 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 2090 | |
348e048f DE |
2091 | build_type_psymtabs (objfile); |
2092 | ||
93311388 | 2093 | create_all_comp_units (objfile); |
c906108c | 2094 | |
93311388 DE |
2095 | objfile->psymtabs_addrmap = |
2096 | addrmap_create_mutable (&objfile->objfile_obstack); | |
72bf9492 | 2097 | |
93311388 DE |
2098 | /* Since the objects we're extracting from .debug_info vary in |
2099 | length, only the individual functions to extract them (like | |
2100 | read_comp_unit_head and load_partial_die) can really know whether | |
2101 | the buffer is large enough to hold another complete object. | |
c906108c | 2102 | |
93311388 DE |
2103 | At the moment, they don't actually check that. If .debug_info |
2104 | holds just one extra byte after the last compilation unit's dies, | |
2105 | then read_comp_unit_head will happily read off the end of the | |
2106 | buffer. read_partial_die is similarly casual. Those functions | |
2107 | should be fixed. | |
c906108c | 2108 | |
93311388 DE |
2109 | For this loop condition, simply checking whether there's any data |
2110 | left at all should be sufficient. */ | |
c906108c | 2111 | |
93311388 DE |
2112 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
2113 | + dwarf2_per_objfile->info.size)) | |
2114 | { | |
2115 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 2116 | |
93311388 DE |
2117 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
2118 | objfile); | |
aaa75496 | 2119 | |
93311388 DE |
2120 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
2121 | dwarf2_per_objfile->info.buffer, | |
2122 | info_ptr, | |
2123 | dwarf2_per_objfile->info.size); | |
c906108c | 2124 | } |
ff013f42 JK |
2125 | |
2126 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
2127 | &objfile->objfile_obstack); | |
2128 | ||
ae038cb0 DJ |
2129 | do_cleanups (back_to); |
2130 | } | |
2131 | ||
93311388 | 2132 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
2133 | |
2134 | static void | |
93311388 DE |
2135 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
2136 | struct objfile *objfile) | |
ae038cb0 DJ |
2137 | { |
2138 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 2139 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 2140 | struct die_info *comp_unit_die; |
ae038cb0 | 2141 | struct dwarf2_cu *cu; |
ae038cb0 DJ |
2142 | unsigned int bytes_read; |
2143 | struct cleanup *back_to; | |
d85a05f0 DJ |
2144 | struct attribute *attr; |
2145 | int has_children; | |
2146 | struct die_reader_specs reader_specs; | |
ae038cb0 | 2147 | |
348e048f DE |
2148 | gdb_assert (! this_cu->from_debug_types); |
2149 | ||
dce234bc | 2150 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
2151 | beg_of_comp_unit = info_ptr; |
2152 | ||
93311388 | 2153 | cu = alloc_one_comp_unit (objfile); |
ae038cb0 | 2154 | |
93311388 | 2155 | /* ??? Missing cleanup for CU? */ |
ae038cb0 | 2156 | |
328c9494 DJ |
2157 | /* Link this compilation unit into the compilation unit tree. */ |
2158 | this_cu->cu = cu; | |
2159 | cu->per_cu = this_cu; | |
2160 | cu->type_hash = this_cu->type_hash; | |
2161 | ||
93311388 DE |
2162 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
2163 | dwarf2_per_objfile->info.buffer, | |
2164 | dwarf2_per_objfile->info.size, | |
2165 | abfd); | |
ae038cb0 DJ |
2166 | |
2167 | /* Complete the cu_header. */ | |
93311388 | 2168 | cu->header.offset = this_cu->offset; |
d00adf39 | 2169 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
2170 | |
2171 | /* Read the abbrevs for this compilation unit into a table. */ | |
2172 | dwarf2_read_abbrevs (abfd, cu); | |
2173 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2174 | ||
2175 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
2176 | init_cu_die_reader (&reader_specs, cu); |
2177 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2178 | &has_children); | |
ae038cb0 DJ |
2179 | |
2180 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
2181 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
2182 | if (attr) | |
2183 | set_cu_language (DW_UNSND (attr), cu); | |
2184 | else | |
2185 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 2186 | |
ae038cb0 DJ |
2187 | /* Check if comp unit has_children. |
2188 | If so, read the rest of the partial symbols from this comp unit. | |
2189 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 2190 | if (has_children) |
93311388 | 2191 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 DJ |
2192 | |
2193 | do_cleanups (back_to); | |
2194 | } | |
2195 | ||
2196 | /* Create a list of all compilation units in OBJFILE. We do this only | |
2197 | if an inter-comp-unit reference is found; presumably if there is one, | |
2198 | there will be many, and one will occur early in the .debug_info section. | |
2199 | So there's no point in building this list incrementally. */ | |
2200 | ||
2201 | static void | |
2202 | create_all_comp_units (struct objfile *objfile) | |
2203 | { | |
2204 | int n_allocated; | |
2205 | int n_comp_units; | |
2206 | struct dwarf2_per_cu_data **all_comp_units; | |
dce234bc | 2207 | gdb_byte *info_ptr = dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
2208 | |
2209 | n_comp_units = 0; | |
2210 | n_allocated = 10; | |
2211 | all_comp_units = xmalloc (n_allocated | |
2212 | * sizeof (struct dwarf2_per_cu_data *)); | |
2213 | ||
dce234bc | 2214 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 2215 | { |
c764a876 | 2216 | unsigned int length, initial_length_size; |
fe1b8b76 | 2217 | gdb_byte *beg_of_comp_unit; |
ae038cb0 | 2218 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 2219 | unsigned int offset; |
ae038cb0 | 2220 | |
dce234bc | 2221 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
2222 | |
2223 | /* Read just enough information to find out where the next | |
2224 | compilation unit is. */ | |
c764a876 DE |
2225 | length = read_initial_length (objfile->obfd, info_ptr, |
2226 | &initial_length_size); | |
ae038cb0 DJ |
2227 | |
2228 | /* Save the compilation unit for later lookup. */ | |
2229 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
2230 | sizeof (struct dwarf2_per_cu_data)); | |
2231 | memset (this_cu, 0, sizeof (*this_cu)); | |
2232 | this_cu->offset = offset; | |
c764a876 | 2233 | this_cu->length = length + initial_length_size; |
ae038cb0 DJ |
2234 | |
2235 | if (n_comp_units == n_allocated) | |
2236 | { | |
2237 | n_allocated *= 2; | |
2238 | all_comp_units = xrealloc (all_comp_units, | |
2239 | n_allocated | |
2240 | * sizeof (struct dwarf2_per_cu_data *)); | |
2241 | } | |
2242 | all_comp_units[n_comp_units++] = this_cu; | |
2243 | ||
2244 | info_ptr = info_ptr + this_cu->length; | |
2245 | } | |
2246 | ||
2247 | dwarf2_per_objfile->all_comp_units | |
2248 | = obstack_alloc (&objfile->objfile_obstack, | |
2249 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
2250 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
2251 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
2252 | xfree (all_comp_units); | |
2253 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
2254 | } |
2255 | ||
5734ee8b DJ |
2256 | /* Process all loaded DIEs for compilation unit CU, starting at |
2257 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
2258 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
2259 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
2260 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
2261 | and record the covered ranges in the addrmap. */ | |
c906108c | 2262 | |
72bf9492 DJ |
2263 | static void |
2264 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 2265 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 2266 | { |
e7c27a73 | 2267 | struct objfile *objfile = cu->objfile; |
c906108c | 2268 | bfd *abfd = objfile->obfd; |
72bf9492 | 2269 | struct partial_die_info *pdi; |
c906108c | 2270 | |
91c24f0a DC |
2271 | /* Now, march along the PDI's, descending into ones which have |
2272 | interesting children but skipping the children of the other ones, | |
2273 | until we reach the end of the compilation unit. */ | |
c906108c | 2274 | |
72bf9492 | 2275 | pdi = first_die; |
91c24f0a | 2276 | |
72bf9492 DJ |
2277 | while (pdi != NULL) |
2278 | { | |
2279 | fixup_partial_die (pdi, cu); | |
c906108c | 2280 | |
91c24f0a DC |
2281 | /* Anonymous namespaces have no name but have interesting |
2282 | children, so we need to look at them. Ditto for anonymous | |
2283 | enums. */ | |
933c6fe4 | 2284 | |
72bf9492 DJ |
2285 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
2286 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 2287 | { |
72bf9492 | 2288 | switch (pdi->tag) |
c906108c SS |
2289 | { |
2290 | case DW_TAG_subprogram: | |
5734ee8b | 2291 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
2292 | break; |
2293 | case DW_TAG_variable: | |
2294 | case DW_TAG_typedef: | |
91c24f0a | 2295 | case DW_TAG_union_type: |
72bf9492 | 2296 | if (!pdi->is_declaration) |
63d06c5c | 2297 | { |
72bf9492 | 2298 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
2299 | } |
2300 | break; | |
c906108c | 2301 | case DW_TAG_class_type: |
680b30c7 | 2302 | case DW_TAG_interface_type: |
c906108c | 2303 | case DW_TAG_structure_type: |
72bf9492 | 2304 | if (!pdi->is_declaration) |
c906108c | 2305 | { |
72bf9492 | 2306 | add_partial_symbol (pdi, cu); |
c906108c SS |
2307 | } |
2308 | break; | |
91c24f0a | 2309 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
2310 | if (!pdi->is_declaration) |
2311 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
2312 | break; |
2313 | case DW_TAG_base_type: | |
a02abb62 | 2314 | case DW_TAG_subrange_type: |
c906108c | 2315 | /* File scope base type definitions are added to the partial |
c5aa993b | 2316 | symbol table. */ |
72bf9492 | 2317 | add_partial_symbol (pdi, cu); |
c906108c | 2318 | break; |
d9fa45fe | 2319 | case DW_TAG_namespace: |
5734ee8b | 2320 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 2321 | break; |
5d7cb8df JK |
2322 | case DW_TAG_module: |
2323 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
2324 | break; | |
c906108c SS |
2325 | default: |
2326 | break; | |
2327 | } | |
2328 | } | |
2329 | ||
72bf9492 DJ |
2330 | /* If the die has a sibling, skip to the sibling. */ |
2331 | ||
2332 | pdi = pdi->die_sibling; | |
2333 | } | |
2334 | } | |
2335 | ||
2336 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 2337 | |
72bf9492 | 2338 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
2339 | name is concatenated with "::" and the partial DIE's name. For |
2340 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
2341 | Enumerators are an exception; they use the scope of their parent |
2342 | enumeration type, i.e. the name of the enumeration type is not | |
2343 | prepended to the enumerator. | |
91c24f0a | 2344 | |
72bf9492 DJ |
2345 | There are two complexities. One is DW_AT_specification; in this |
2346 | case "parent" means the parent of the target of the specification, | |
2347 | instead of the direct parent of the DIE. The other is compilers | |
2348 | which do not emit DW_TAG_namespace; in this case we try to guess | |
2349 | the fully qualified name of structure types from their members' | |
2350 | linkage names. This must be done using the DIE's children rather | |
2351 | than the children of any DW_AT_specification target. We only need | |
2352 | to do this for structures at the top level, i.e. if the target of | |
2353 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
2354 | have a parent. */ | |
2355 | ||
2356 | /* Compute the scope prefix associated with PDI's parent, in | |
2357 | compilation unit CU. The result will be allocated on CU's | |
2358 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
2359 | field. NULL is returned if no prefix is necessary. */ | |
2360 | static char * | |
2361 | partial_die_parent_scope (struct partial_die_info *pdi, | |
2362 | struct dwarf2_cu *cu) | |
2363 | { | |
2364 | char *grandparent_scope; | |
2365 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 2366 | |
72bf9492 DJ |
2367 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
2368 | then this means the parent of the specification DIE. */ | |
2369 | ||
2370 | real_pdi = pdi; | |
72bf9492 | 2371 | while (real_pdi->has_specification) |
10b3939b | 2372 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
2373 | |
2374 | parent = real_pdi->die_parent; | |
2375 | if (parent == NULL) | |
2376 | return NULL; | |
2377 | ||
2378 | if (parent->scope_set) | |
2379 | return parent->scope; | |
2380 | ||
2381 | fixup_partial_die (parent, cu); | |
2382 | ||
10b3939b | 2383 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
2384 | |
2385 | if (parent->tag == DW_TAG_namespace | |
2386 | || parent->tag == DW_TAG_structure_type | |
2387 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 2388 | || parent->tag == DW_TAG_interface_type |
72bf9492 DJ |
2389 | || parent->tag == DW_TAG_union_type) |
2390 | { | |
2391 | if (grandparent_scope == NULL) | |
2392 | parent->scope = parent->name; | |
2393 | else | |
987504bb JJ |
2394 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
2395 | parent->name, cu); | |
72bf9492 DJ |
2396 | } |
2397 | else if (parent->tag == DW_TAG_enumeration_type) | |
2398 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
2399 | parent->scope = grandparent_scope; | |
2400 | else | |
2401 | { | |
2402 | /* FIXME drow/2004-04-01: What should we be doing with | |
2403 | function-local names? For partial symbols, we should probably be | |
2404 | ignoring them. */ | |
2405 | complaint (&symfile_complaints, | |
e2e0b3e5 | 2406 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
2407 | parent->tag, pdi->offset); |
2408 | parent->scope = grandparent_scope; | |
c906108c SS |
2409 | } |
2410 | ||
72bf9492 DJ |
2411 | parent->scope_set = 1; |
2412 | return parent->scope; | |
2413 | } | |
2414 | ||
2415 | /* Return the fully scoped name associated with PDI, from compilation unit | |
2416 | CU. The result will be allocated with malloc. */ | |
2417 | static char * | |
2418 | partial_die_full_name (struct partial_die_info *pdi, | |
2419 | struct dwarf2_cu *cu) | |
2420 | { | |
2421 | char *parent_scope; | |
2422 | ||
2423 | parent_scope = partial_die_parent_scope (pdi, cu); | |
2424 | if (parent_scope == NULL) | |
2425 | return NULL; | |
2426 | else | |
987504bb | 2427 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
2428 | } |
2429 | ||
2430 | static void | |
72bf9492 | 2431 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 2432 | { |
e7c27a73 | 2433 | struct objfile *objfile = cu->objfile; |
c906108c | 2434 | CORE_ADDR addr = 0; |
decbce07 | 2435 | char *actual_name = NULL; |
72bf9492 | 2436 | const char *my_prefix; |
5c4e30ca | 2437 | const struct partial_symbol *psym = NULL; |
e142c38c | 2438 | CORE_ADDR baseaddr; |
72bf9492 | 2439 | int built_actual_name = 0; |
e142c38c DJ |
2440 | |
2441 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2442 | |
72bf9492 | 2443 | if (pdi_needs_namespace (pdi->tag)) |
63d06c5c | 2444 | { |
72bf9492 DJ |
2445 | actual_name = partial_die_full_name (pdi, cu); |
2446 | if (actual_name) | |
2447 | built_actual_name = 1; | |
63d06c5c DC |
2448 | } |
2449 | ||
72bf9492 DJ |
2450 | if (actual_name == NULL) |
2451 | actual_name = pdi->name; | |
2452 | ||
c906108c SS |
2453 | switch (pdi->tag) |
2454 | { | |
2455 | case DW_TAG_subprogram: | |
2cfa0c8d | 2456 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 2457 | { |
2cfa0c8d JB |
2458 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
2459 | of the global scope. But in Ada, we want to be able to access | |
2460 | nested procedures globally. So all Ada subprograms are stored | |
2461 | in the global scope. */ | |
38d518c9 | 2462 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2463 | mst_text, objfile); */ |
38d518c9 | 2464 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2465 | built_actual_name, |
5c4e30ca DC |
2466 | VAR_DOMAIN, LOC_BLOCK, |
2467 | &objfile->global_psymbols, | |
2468 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2469 | cu->language, objfile); |
c906108c SS |
2470 | } |
2471 | else | |
2472 | { | |
38d518c9 | 2473 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2474 | mst_file_text, objfile); */ |
38d518c9 | 2475 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2476 | built_actual_name, |
5c4e30ca DC |
2477 | VAR_DOMAIN, LOC_BLOCK, |
2478 | &objfile->static_psymbols, | |
2479 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2480 | cu->language, objfile); |
c906108c SS |
2481 | } |
2482 | break; | |
2483 | case DW_TAG_variable: | |
2484 | if (pdi->is_external) | |
2485 | { | |
2486 | /* Global Variable. | |
2487 | Don't enter into the minimal symbol tables as there is | |
2488 | a minimal symbol table entry from the ELF symbols already. | |
2489 | Enter into partial symbol table if it has a location | |
2490 | descriptor or a type. | |
2491 | If the location descriptor is missing, new_symbol will create | |
2492 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
2493 | be determined from the minimal symbol table whenever the variable | |
2494 | is referenced. | |
2495 | The address for the partial symbol table entry is not | |
2496 | used by GDB, but it comes in handy for debugging partial symbol | |
2497 | table building. */ | |
2498 | ||
2499 | if (pdi->locdesc) | |
e7c27a73 | 2500 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2501 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2502 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2503 | built_actual_name, |
5c4e30ca DC |
2504 | VAR_DOMAIN, LOC_STATIC, |
2505 | &objfile->global_psymbols, | |
2506 | 0, addr + baseaddr, | |
e142c38c | 2507 | cu->language, objfile); |
c906108c SS |
2508 | } |
2509 | else | |
2510 | { | |
2511 | /* Static Variable. Skip symbols without location descriptors. */ | |
2512 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2513 | { |
2514 | if (built_actual_name) | |
2515 | xfree (actual_name); | |
2516 | return; | |
2517 | } | |
e7c27a73 | 2518 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2519 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2520 | mst_file_data, objfile); */ |
38d518c9 | 2521 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2522 | built_actual_name, |
5c4e30ca DC |
2523 | VAR_DOMAIN, LOC_STATIC, |
2524 | &objfile->static_psymbols, | |
2525 | 0, addr + baseaddr, | |
e142c38c | 2526 | cu->language, objfile); |
c906108c SS |
2527 | } |
2528 | break; | |
2529 | case DW_TAG_typedef: | |
2530 | case DW_TAG_base_type: | |
a02abb62 | 2531 | case DW_TAG_subrange_type: |
38d518c9 | 2532 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2533 | built_actual_name, |
176620f1 | 2534 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2535 | &objfile->static_psymbols, |
e142c38c | 2536 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2537 | break; |
72bf9492 DJ |
2538 | case DW_TAG_namespace: |
2539 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 2540 | built_actual_name, |
72bf9492 DJ |
2541 | VAR_DOMAIN, LOC_TYPEDEF, |
2542 | &objfile->global_psymbols, | |
2543 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2544 | break; | |
c906108c | 2545 | case DW_TAG_class_type: |
680b30c7 | 2546 | case DW_TAG_interface_type: |
c906108c SS |
2547 | case DW_TAG_structure_type: |
2548 | case DW_TAG_union_type: | |
2549 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2550 | /* Skip external references. The DWARF standard says in the section |
2551 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2552 | structure, union or class type is represented by a structure, | |
2553 | union or class entry that does not have a byte size attribute | |
2554 | and that has a DW_AT_declaration attribute." */ | |
2555 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2556 | { |
2557 | if (built_actual_name) | |
2558 | xfree (actual_name); | |
2559 | return; | |
2560 | } | |
fa4028e9 | 2561 | |
63d06c5c DC |
2562 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2563 | static vs. global. */ | |
38d518c9 | 2564 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2565 | built_actual_name, |
176620f1 | 2566 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2567 | (cu->language == language_cplus |
2568 | || cu->language == language_java) | |
63d06c5c DC |
2569 | ? &objfile->global_psymbols |
2570 | : &objfile->static_psymbols, | |
e142c38c | 2571 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2572 | |
c906108c SS |
2573 | break; |
2574 | case DW_TAG_enumerator: | |
38d518c9 | 2575 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2576 | built_actual_name, |
176620f1 | 2577 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2578 | (cu->language == language_cplus |
2579 | || cu->language == language_java) | |
f6fe98ef DJ |
2580 | ? &objfile->global_psymbols |
2581 | : &objfile->static_psymbols, | |
e142c38c | 2582 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2583 | break; |
2584 | default: | |
2585 | break; | |
2586 | } | |
5c4e30ca DC |
2587 | |
2588 | /* Check to see if we should scan the name for possible namespace | |
2589 | info. Only do this if this is C++, if we don't have namespace | |
2590 | debugging info in the file, if the psym is of an appropriate type | |
2591 | (otherwise we'll have psym == NULL), and if we actually had a | |
2592 | mangled name to begin with. */ | |
2593 | ||
72bf9492 DJ |
2594 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2595 | cases which do not set PSYM above? */ | |
2596 | ||
e142c38c | 2597 | if (cu->language == language_cplus |
72bf9492 | 2598 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2599 | && psym != NULL |
2600 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2601 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2602 | objfile); | |
72bf9492 DJ |
2603 | |
2604 | if (built_actual_name) | |
2605 | xfree (actual_name); | |
c906108c SS |
2606 | } |
2607 | ||
72bf9492 DJ |
2608 | /* Determine whether a die of type TAG living in a C++ class or |
2609 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2610 | name listed in the die. */ |
2611 | ||
2612 | static int | |
72bf9492 | 2613 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2614 | { |
63d06c5c DC |
2615 | switch (tag) |
2616 | { | |
72bf9492 | 2617 | case DW_TAG_namespace: |
63d06c5c DC |
2618 | case DW_TAG_typedef: |
2619 | case DW_TAG_class_type: | |
680b30c7 | 2620 | case DW_TAG_interface_type: |
63d06c5c DC |
2621 | case DW_TAG_structure_type: |
2622 | case DW_TAG_union_type: | |
2623 | case DW_TAG_enumeration_type: | |
2624 | case DW_TAG_enumerator: | |
2625 | return 1; | |
2626 | default: | |
2627 | return 0; | |
2628 | } | |
2629 | } | |
2630 | ||
5c4e30ca DC |
2631 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2632 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2633 | the name of the enclosing namespace. */ | |
91c24f0a | 2634 | |
72bf9492 DJ |
2635 | static void |
2636 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2637 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 2638 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 2639 | { |
e7c27a73 | 2640 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2641 | |
72bf9492 | 2642 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2643 | |
72bf9492 | 2644 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2645 | |
2646 | /* Now scan partial symbols in that namespace. */ | |
2647 | ||
91c24f0a | 2648 | if (pdi->has_children) |
5734ee8b | 2649 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
2650 | } |
2651 | ||
5d7cb8df JK |
2652 | /* Read a partial die corresponding to a Fortran module. */ |
2653 | ||
2654 | static void | |
2655 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
2656 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
2657 | { | |
2658 | /* Now scan partial symbols in that module. | |
2659 | ||
2660 | FIXME: Support the separate Fortran module namespaces. */ | |
2661 | ||
2662 | if (pdi->has_children) | |
2663 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
2664 | } | |
2665 | ||
bc30ff58 JB |
2666 | /* Read a partial die corresponding to a subprogram and create a partial |
2667 | symbol for that subprogram. When the CU language allows it, this | |
2668 | routine also defines a partial symbol for each nested subprogram | |
2669 | that this subprogram contains. | |
2670 | ||
2671 | DIE my also be a lexical block, in which case we simply search | |
2672 | recursively for suprograms defined inside that lexical block. | |
2673 | Again, this is only performed when the CU language allows this | |
2674 | type of definitions. */ | |
2675 | ||
2676 | static void | |
2677 | add_partial_subprogram (struct partial_die_info *pdi, | |
2678 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 2679 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
2680 | { |
2681 | if (pdi->tag == DW_TAG_subprogram) | |
2682 | { | |
2683 | if (pdi->has_pc_info) | |
2684 | { | |
2685 | if (pdi->lowpc < *lowpc) | |
2686 | *lowpc = pdi->lowpc; | |
2687 | if (pdi->highpc > *highpc) | |
2688 | *highpc = pdi->highpc; | |
5734ee8b DJ |
2689 | if (need_pc) |
2690 | { | |
2691 | CORE_ADDR baseaddr; | |
2692 | struct objfile *objfile = cu->objfile; | |
2693 | ||
2694 | baseaddr = ANOFFSET (objfile->section_offsets, | |
2695 | SECT_OFF_TEXT (objfile)); | |
2696 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
2697 | pdi->lowpc, pdi->highpc - 1, | |
2698 | cu->per_cu->psymtab); | |
2699 | } | |
bc30ff58 JB |
2700 | if (!pdi->is_declaration) |
2701 | add_partial_symbol (pdi, cu); | |
2702 | } | |
2703 | } | |
2704 | ||
2705 | if (! pdi->has_children) | |
2706 | return; | |
2707 | ||
2708 | if (cu->language == language_ada) | |
2709 | { | |
2710 | pdi = pdi->die_child; | |
2711 | while (pdi != NULL) | |
2712 | { | |
2713 | fixup_partial_die (pdi, cu); | |
2714 | if (pdi->tag == DW_TAG_subprogram | |
2715 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 2716 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
2717 | pdi = pdi->die_sibling; |
2718 | } | |
2719 | } | |
2720 | } | |
2721 | ||
72bf9492 DJ |
2722 | /* See if we can figure out if the class lives in a namespace. We do |
2723 | this by looking for a member function; its demangled name will | |
2724 | contain namespace info, if there is any. */ | |
63d06c5c | 2725 | |
72bf9492 DJ |
2726 | static void |
2727 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2728 | struct dwarf2_cu *cu) | |
63d06c5c | 2729 | { |
987504bb JJ |
2730 | if ((cu->language == language_cplus |
2731 | || cu->language == language_java) | |
72bf9492 | 2732 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2733 | && struct_pdi->has_children) |
2734 | { | |
63d06c5c DC |
2735 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2736 | what template types look like, because the demangler | |
2737 | frequently doesn't give the same name as the debug info. We | |
2738 | could fix this by only using the demangled name to get the | |
134d01f1 | 2739 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2740 | |
72bf9492 DJ |
2741 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2742 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2743 | |
72bf9492 DJ |
2744 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2745 | we should not do this. We'll prepend the parent's fully qualified | |
2746 | name when we create the partial symbol. */ | |
5d51ca54 | 2747 | |
72bf9492 | 2748 | real_pdi = struct_pdi; |
72bf9492 | 2749 | while (real_pdi->has_specification) |
10b3939b | 2750 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2751 | |
72bf9492 DJ |
2752 | if (real_pdi->die_parent != NULL) |
2753 | return; | |
63d06c5c | 2754 | |
72bf9492 DJ |
2755 | while (child_pdi != NULL) |
2756 | { | |
2757 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2758 | { |
72bf9492 | 2759 | char *actual_class_name |
31c27f77 JJ |
2760 | = language_class_name_from_physname (cu->language_defn, |
2761 | child_pdi->name); | |
63d06c5c | 2762 | if (actual_class_name != NULL) |
72bf9492 DJ |
2763 | { |
2764 | struct_pdi->name | |
2765 | = obsavestring (actual_class_name, | |
2766 | strlen (actual_class_name), | |
2767 | &cu->comp_unit_obstack); | |
2768 | xfree (actual_class_name); | |
2769 | } | |
63d06c5c DC |
2770 | break; |
2771 | } | |
72bf9492 DJ |
2772 | |
2773 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2774 | } |
2775 | } | |
63d06c5c DC |
2776 | } |
2777 | ||
91c24f0a DC |
2778 | /* Read a partial die corresponding to an enumeration type. */ |
2779 | ||
72bf9492 DJ |
2780 | static void |
2781 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2782 | struct dwarf2_cu *cu) | |
91c24f0a | 2783 | { |
e7c27a73 | 2784 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2785 | bfd *abfd = objfile->obfd; |
72bf9492 | 2786 | struct partial_die_info *pdi; |
91c24f0a DC |
2787 | |
2788 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2789 | add_partial_symbol (enum_pdi, cu); |
2790 | ||
2791 | pdi = enum_pdi->die_child; | |
2792 | while (pdi) | |
91c24f0a | 2793 | { |
72bf9492 | 2794 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2795 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2796 | else |
72bf9492 DJ |
2797 | add_partial_symbol (pdi, cu); |
2798 | pdi = pdi->die_sibling; | |
91c24f0a | 2799 | } |
91c24f0a DC |
2800 | } |
2801 | ||
4bb7a0a7 DJ |
2802 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2803 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2804 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2805 | the initial number. */ | |
2806 | ||
2807 | static struct abbrev_info * | |
fe1b8b76 | 2808 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2809 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2810 | { |
2811 | bfd *abfd = cu->objfile->obfd; | |
2812 | unsigned int abbrev_number; | |
2813 | struct abbrev_info *abbrev; | |
2814 | ||
2815 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2816 | ||
2817 | if (abbrev_number == 0) | |
2818 | return NULL; | |
2819 | ||
2820 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2821 | if (!abbrev) | |
2822 | { | |
8a3fe4f8 | 2823 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2824 | bfd_get_filename (abfd)); |
2825 | } | |
2826 | ||
2827 | return abbrev; | |
2828 | } | |
2829 | ||
93311388 DE |
2830 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2831 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
2832 | DIE. Any children of the skipped DIEs will also be skipped. */ |
2833 | ||
fe1b8b76 | 2834 | static gdb_byte * |
93311388 | 2835 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2836 | { |
2837 | struct abbrev_info *abbrev; | |
2838 | unsigned int bytes_read; | |
2839 | ||
2840 | while (1) | |
2841 | { | |
2842 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2843 | if (abbrev == NULL) | |
2844 | return info_ptr + bytes_read; | |
2845 | else | |
93311388 | 2846 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
2847 | } |
2848 | } | |
2849 | ||
93311388 DE |
2850 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2851 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
2852 | abbrev corresponding to that skipped uleb128 should be passed in |
2853 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2854 | children. */ | |
2855 | ||
fe1b8b76 | 2856 | static gdb_byte * |
93311388 DE |
2857 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
2858 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2859 | { |
2860 | unsigned int bytes_read; | |
2861 | struct attribute attr; | |
2862 | bfd *abfd = cu->objfile->obfd; | |
2863 | unsigned int form, i; | |
2864 | ||
2865 | for (i = 0; i < abbrev->num_attrs; i++) | |
2866 | { | |
2867 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2868 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2869 | { | |
2870 | read_attribute (&attr, &abbrev->attrs[i], | |
2871 | abfd, info_ptr, cu); | |
2872 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2873 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2874 | else |
93311388 | 2875 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
2876 | } |
2877 | ||
2878 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2879 | form = abbrev->attrs[i].form; | |
2880 | skip_attribute: | |
2881 | switch (form) | |
2882 | { | |
2883 | case DW_FORM_addr: | |
2884 | case DW_FORM_ref_addr: | |
2885 | info_ptr += cu->header.addr_size; | |
2886 | break; | |
2887 | case DW_FORM_data1: | |
2888 | case DW_FORM_ref1: | |
2889 | case DW_FORM_flag: | |
2890 | info_ptr += 1; | |
2891 | break; | |
2892 | case DW_FORM_data2: | |
2893 | case DW_FORM_ref2: | |
2894 | info_ptr += 2; | |
2895 | break; | |
2896 | case DW_FORM_data4: | |
2897 | case DW_FORM_ref4: | |
2898 | info_ptr += 4; | |
2899 | break; | |
2900 | case DW_FORM_data8: | |
2901 | case DW_FORM_ref8: | |
348e048f | 2902 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
2903 | info_ptr += 8; |
2904 | break; | |
2905 | case DW_FORM_string: | |
2906 | read_string (abfd, info_ptr, &bytes_read); | |
2907 | info_ptr += bytes_read; | |
2908 | break; | |
2909 | case DW_FORM_strp: | |
2910 | info_ptr += cu->header.offset_size; | |
2911 | break; | |
2912 | case DW_FORM_block: | |
2913 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2914 | info_ptr += bytes_read; | |
2915 | break; | |
2916 | case DW_FORM_block1: | |
2917 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2918 | break; | |
2919 | case DW_FORM_block2: | |
2920 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2921 | break; | |
2922 | case DW_FORM_block4: | |
2923 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2924 | break; | |
2925 | case DW_FORM_sdata: | |
2926 | case DW_FORM_udata: | |
2927 | case DW_FORM_ref_udata: | |
2928 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2929 | break; | |
2930 | case DW_FORM_indirect: | |
2931 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2932 | info_ptr += bytes_read; | |
2933 | /* We need to continue parsing from here, so just go back to | |
2934 | the top. */ | |
2935 | goto skip_attribute; | |
2936 | ||
2937 | default: | |
8a3fe4f8 | 2938 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2939 | dwarf_form_name (form), |
2940 | bfd_get_filename (abfd)); | |
2941 | } | |
2942 | } | |
2943 | ||
2944 | if (abbrev->has_children) | |
93311388 | 2945 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
2946 | else |
2947 | return info_ptr; | |
2948 | } | |
2949 | ||
93311388 DE |
2950 | /* Locate ORIG_PDI's sibling. |
2951 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
2952 | in BUFFER. */ | |
91c24f0a | 2953 | |
fe1b8b76 | 2954 | static gdb_byte * |
93311388 DE |
2955 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
2956 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 2957 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2958 | { |
2959 | /* Do we know the sibling already? */ | |
72bf9492 | 2960 | |
91c24f0a DC |
2961 | if (orig_pdi->sibling) |
2962 | return orig_pdi->sibling; | |
2963 | ||
2964 | /* Are there any children to deal with? */ | |
2965 | ||
2966 | if (!orig_pdi->has_children) | |
2967 | return info_ptr; | |
2968 | ||
4bb7a0a7 | 2969 | /* Skip the children the long way. */ |
91c24f0a | 2970 | |
93311388 | 2971 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
2972 | } |
2973 | ||
c906108c SS |
2974 | /* Expand this partial symbol table into a full symbol table. */ |
2975 | ||
2976 | static void | |
fba45db2 | 2977 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2978 | { |
2979 | /* FIXME: This is barely more than a stub. */ | |
2980 | if (pst != NULL) | |
2981 | { | |
2982 | if (pst->readin) | |
2983 | { | |
8a3fe4f8 | 2984 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2985 | } |
2986 | else | |
2987 | { | |
2988 | if (info_verbose) | |
2989 | { | |
a3f17187 | 2990 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2991 | gdb_flush (gdb_stdout); |
2992 | } | |
2993 | ||
10b3939b DJ |
2994 | /* Restore our global data. */ |
2995 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2996 | dwarf2_objfile_data_key); | |
2997 | ||
b2ab525c KB |
2998 | /* If this psymtab is constructed from a debug-only objfile, the |
2999 | has_section_at_zero flag will not necessarily be correct. We | |
3000 | can get the correct value for this flag by looking at the data | |
3001 | associated with the (presumably stripped) associated objfile. */ | |
3002 | if (pst->objfile->separate_debug_objfile_backlink) | |
3003 | { | |
3004 | struct dwarf2_per_objfile *dpo_backlink | |
3005 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
3006 | dwarf2_objfile_data_key); | |
3007 | dwarf2_per_objfile->has_section_at_zero | |
3008 | = dpo_backlink->has_section_at_zero; | |
3009 | } | |
3010 | ||
c906108c SS |
3011 | psymtab_to_symtab_1 (pst); |
3012 | ||
3013 | /* Finish up the debug error message. */ | |
3014 | if (info_verbose) | |
a3f17187 | 3015 | printf_filtered (_("done.\n")); |
c906108c SS |
3016 | } |
3017 | } | |
3018 | } | |
3019 | ||
10b3939b DJ |
3020 | /* Add PER_CU to the queue. */ |
3021 | ||
3022 | static void | |
03dd20cc | 3023 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
3024 | { |
3025 | struct dwarf2_queue_item *item; | |
3026 | ||
3027 | per_cu->queued = 1; | |
3028 | item = xmalloc (sizeof (*item)); | |
3029 | item->per_cu = per_cu; | |
3030 | item->next = NULL; | |
3031 | ||
3032 | if (dwarf2_queue == NULL) | |
3033 | dwarf2_queue = item; | |
3034 | else | |
3035 | dwarf2_queue_tail->next = item; | |
3036 | ||
3037 | dwarf2_queue_tail = item; | |
3038 | } | |
3039 | ||
3040 | /* Process the queue. */ | |
3041 | ||
3042 | static void | |
3043 | process_queue (struct objfile *objfile) | |
3044 | { | |
3045 | struct dwarf2_queue_item *item, *next_item; | |
3046 | ||
03dd20cc DJ |
3047 | /* The queue starts out with one item, but following a DIE reference |
3048 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
3049 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
3050 | { | |
31ffec48 | 3051 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
3052 | process_full_comp_unit (item->per_cu); |
3053 | ||
3054 | item->per_cu->queued = 0; | |
3055 | next_item = item->next; | |
3056 | xfree (item); | |
3057 | } | |
3058 | ||
3059 | dwarf2_queue_tail = NULL; | |
3060 | } | |
3061 | ||
3062 | /* Free all allocated queue entries. This function only releases anything if | |
3063 | an error was thrown; if the queue was processed then it would have been | |
3064 | freed as we went along. */ | |
3065 | ||
3066 | static void | |
3067 | dwarf2_release_queue (void *dummy) | |
3068 | { | |
3069 | struct dwarf2_queue_item *item, *last; | |
3070 | ||
3071 | item = dwarf2_queue; | |
3072 | while (item) | |
3073 | { | |
3074 | /* Anything still marked queued is likely to be in an | |
3075 | inconsistent state, so discard it. */ | |
3076 | if (item->per_cu->queued) | |
3077 | { | |
3078 | if (item->per_cu->cu != NULL) | |
3079 | free_one_cached_comp_unit (item->per_cu->cu); | |
3080 | item->per_cu->queued = 0; | |
3081 | } | |
3082 | ||
3083 | last = item; | |
3084 | item = item->next; | |
3085 | xfree (last); | |
3086 | } | |
3087 | ||
3088 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
3089 | } | |
3090 | ||
3091 | /* Read in full symbols for PST, and anything it depends on. */ | |
3092 | ||
c906108c | 3093 | static void |
fba45db2 | 3094 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 3095 | { |
10b3939b | 3096 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 3097 | struct cleanup *back_to; |
aaa75496 JB |
3098 | int i; |
3099 | ||
3100 | for (i = 0; i < pst->number_of_dependencies; i++) | |
3101 | if (!pst->dependencies[i]->readin) | |
3102 | { | |
3103 | /* Inform about additional files that need to be read in. */ | |
3104 | if (info_verbose) | |
3105 | { | |
a3f17187 | 3106 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
3107 | fputs_filtered (" ", gdb_stdout); |
3108 | wrap_here (""); | |
3109 | fputs_filtered ("and ", gdb_stdout); | |
3110 | wrap_here (""); | |
3111 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
3112 | wrap_here (""); /* Flush output */ | |
3113 | gdb_flush (gdb_stdout); | |
3114 | } | |
3115 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
3116 | } | |
3117 | ||
10b3939b DJ |
3118 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
3119 | ||
3120 | if (per_cu == NULL) | |
aaa75496 JB |
3121 | { |
3122 | /* It's an include file, no symbols to read for it. | |
3123 | Everything is in the parent symtab. */ | |
3124 | pst->readin = 1; | |
3125 | return; | |
3126 | } | |
c906108c | 3127 | |
10b3939b DJ |
3128 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
3129 | ||
03dd20cc | 3130 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b | 3131 | |
348e048f DE |
3132 | if (per_cu->from_debug_types) |
3133 | read_signatured_type_at_offset (pst->objfile, per_cu->offset); | |
3134 | else | |
3135 | load_full_comp_unit (per_cu, pst->objfile); | |
3136 | ||
10b3939b DJ |
3137 | process_queue (pst->objfile); |
3138 | ||
3139 | /* Age the cache, releasing compilation units that have not | |
3140 | been used recently. */ | |
3141 | age_cached_comp_units (); | |
3142 | ||
3143 | do_cleanups (back_to); | |
3144 | } | |
3145 | ||
93311388 | 3146 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 3147 | |
93311388 | 3148 | static void |
31ffec48 | 3149 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 3150 | { |
31ffec48 | 3151 | bfd *abfd = objfile->obfd; |
10b3939b | 3152 | struct dwarf2_cu *cu; |
c764a876 | 3153 | unsigned int offset; |
93311388 | 3154 | gdb_byte *info_ptr, *beg_of_comp_unit; |
10b3939b DJ |
3155 | struct cleanup *back_to, *free_cu_cleanup; |
3156 | struct attribute *attr; | |
3157 | CORE_ADDR baseaddr; | |
6502dd73 | 3158 | |
348e048f DE |
3159 | gdb_assert (! per_cu->from_debug_types); |
3160 | ||
c906108c | 3161 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 3162 | offset = per_cu->offset; |
6502dd73 | 3163 | |
dce234bc | 3164 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 3165 | beg_of_comp_unit = info_ptr; |
63d06c5c | 3166 | |
93311388 | 3167 | cu = alloc_one_comp_unit (objfile); |
c906108c | 3168 | |
10b3939b DJ |
3169 | /* If an error occurs while loading, release our storage. */ |
3170 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 3171 | |
93311388 | 3172 | /* Read in the comp_unit header. */ |
10b3939b | 3173 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c | 3174 | |
93311388 DE |
3175 | /* Complete the cu_header. */ |
3176 | cu->header.offset = offset; | |
3177 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3178 | ||
3179 | /* Read the abbrevs for this compilation unit. */ | |
10b3939b DJ |
3180 | dwarf2_read_abbrevs (abfd, cu); |
3181 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
3182 | ||
93311388 | 3183 | /* Link this compilation unit into the compilation unit tree. */ |
10b3939b | 3184 | per_cu->cu = cu; |
93311388 | 3185 | cu->per_cu = per_cu; |
f792889a | 3186 | cu->type_hash = per_cu->type_hash; |
e142c38c | 3187 | |
93311388 | 3188 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
3189 | |
3190 | /* We try not to read any attributes in this function, because not | |
3191 | all objfiles needed for references have been loaded yet, and symbol | |
3192 | table processing isn't initialized. But we have to set the CU language, | |
3193 | or we won't be able to build types correctly. */ | |
3194 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
3195 | if (attr) | |
3196 | set_cu_language (DW_UNSND (attr), cu); | |
3197 | else | |
3198 | set_cu_language (language_minimal, cu); | |
3199 | ||
348e048f DE |
3200 | /* Link this CU into read_in_chain. */ |
3201 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3202 | dwarf2_per_objfile->read_in_chain = per_cu; | |
3203 | ||
10b3939b | 3204 | do_cleanups (back_to); |
e142c38c | 3205 | |
10b3939b DJ |
3206 | /* We've successfully allocated this compilation unit. Let our caller |
3207 | clean it up when finished with it. */ | |
3208 | discard_cleanups (free_cu_cleanup); | |
10b3939b DJ |
3209 | } |
3210 | ||
3211 | /* Generate full symbol information for PST and CU, whose DIEs have | |
3212 | already been loaded into memory. */ | |
3213 | ||
3214 | static void | |
3215 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
3216 | { | |
3217 | struct partial_symtab *pst = per_cu->psymtab; | |
3218 | struct dwarf2_cu *cu = per_cu->cu; | |
3219 | struct objfile *objfile = pst->objfile; | |
3220 | bfd *abfd = objfile->obfd; | |
3221 | CORE_ADDR lowpc, highpc; | |
3222 | struct symtab *symtab; | |
3223 | struct cleanup *back_to; | |
10b3939b DJ |
3224 | CORE_ADDR baseaddr; |
3225 | ||
3226 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3227 | ||
10b3939b DJ |
3228 | buildsym_init (); |
3229 | back_to = make_cleanup (really_free_pendings, NULL); | |
3230 | ||
3231 | cu->list_in_scope = &file_symbols; | |
c906108c | 3232 | |
d85a05f0 | 3233 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 3234 | |
c906108c | 3235 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 3236 | process_die (cu->dies, cu); |
c906108c | 3237 | |
fae299cd DC |
3238 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
3239 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
3240 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 3241 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 3242 | |
613e1657 | 3243 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3244 | |
3245 | /* Set symtab language to language from DW_AT_language. | |
3246 | If the compilation is from a C file generated by language preprocessors, | |
3247 | do not set the language if it was already deduced by start_subfile. */ | |
3248 | if (symtab != NULL | |
10b3939b | 3249 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 3250 | { |
10b3939b | 3251 | symtab->language = cu->language; |
c906108c SS |
3252 | } |
3253 | pst->symtab = symtab; | |
3254 | pst->readin = 1; | |
c906108c SS |
3255 | |
3256 | do_cleanups (back_to); | |
3257 | } | |
3258 | ||
3259 | /* Process a die and its children. */ | |
3260 | ||
3261 | static void | |
e7c27a73 | 3262 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3263 | { |
3264 | switch (die->tag) | |
3265 | { | |
3266 | case DW_TAG_padding: | |
3267 | break; | |
3268 | case DW_TAG_compile_unit: | |
e7c27a73 | 3269 | read_file_scope (die, cu); |
c906108c | 3270 | break; |
348e048f DE |
3271 | case DW_TAG_type_unit: |
3272 | read_type_unit_scope (die, cu); | |
3273 | break; | |
c906108c | 3274 | case DW_TAG_subprogram: |
c906108c | 3275 | case DW_TAG_inlined_subroutine: |
edb3359d | 3276 | read_func_scope (die, cu); |
c906108c SS |
3277 | break; |
3278 | case DW_TAG_lexical_block: | |
14898363 L |
3279 | case DW_TAG_try_block: |
3280 | case DW_TAG_catch_block: | |
e7c27a73 | 3281 | read_lexical_block_scope (die, cu); |
c906108c SS |
3282 | break; |
3283 | case DW_TAG_class_type: | |
680b30c7 | 3284 | case DW_TAG_interface_type: |
c906108c SS |
3285 | case DW_TAG_structure_type: |
3286 | case DW_TAG_union_type: | |
134d01f1 | 3287 | process_structure_scope (die, cu); |
c906108c SS |
3288 | break; |
3289 | case DW_TAG_enumeration_type: | |
134d01f1 | 3290 | process_enumeration_scope (die, cu); |
c906108c | 3291 | break; |
134d01f1 | 3292 | |
f792889a DJ |
3293 | /* These dies have a type, but processing them does not create |
3294 | a symbol or recurse to process the children. Therefore we can | |
3295 | read them on-demand through read_type_die. */ | |
c906108c | 3296 | case DW_TAG_subroutine_type: |
72019c9c | 3297 | case DW_TAG_set_type: |
c906108c | 3298 | case DW_TAG_array_type: |
c906108c | 3299 | case DW_TAG_pointer_type: |
c906108c | 3300 | case DW_TAG_ptr_to_member_type: |
c906108c | 3301 | case DW_TAG_reference_type: |
c906108c | 3302 | case DW_TAG_string_type: |
c906108c | 3303 | break; |
134d01f1 | 3304 | |
c906108c | 3305 | case DW_TAG_base_type: |
a02abb62 | 3306 | case DW_TAG_subrange_type: |
cb249c71 | 3307 | case DW_TAG_typedef: |
134d01f1 DJ |
3308 | /* Add a typedef symbol for the type definition, if it has a |
3309 | DW_AT_name. */ | |
f792889a | 3310 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 3311 | break; |
c906108c | 3312 | case DW_TAG_common_block: |
e7c27a73 | 3313 | read_common_block (die, cu); |
c906108c SS |
3314 | break; |
3315 | case DW_TAG_common_inclusion: | |
3316 | break; | |
d9fa45fe | 3317 | case DW_TAG_namespace: |
63d06c5c | 3318 | processing_has_namespace_info = 1; |
e7c27a73 | 3319 | read_namespace (die, cu); |
d9fa45fe | 3320 | break; |
5d7cb8df JK |
3321 | case DW_TAG_module: |
3322 | read_module (die, cu); | |
3323 | break; | |
d9fa45fe DC |
3324 | case DW_TAG_imported_declaration: |
3325 | case DW_TAG_imported_module: | |
63d06c5c | 3326 | processing_has_namespace_info = 1; |
27aa8d6a SW |
3327 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
3328 | || cu->language != language_fortran)) | |
3329 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
3330 | dwarf_tag_name (die->tag)); | |
3331 | read_import_statement (die, cu); | |
d9fa45fe | 3332 | break; |
c906108c | 3333 | default: |
e7c27a73 | 3334 | new_symbol (die, NULL, cu); |
c906108c SS |
3335 | break; |
3336 | } | |
3337 | } | |
3338 | ||
0114d602 DJ |
3339 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
3340 | If scope qualifiers are appropriate they will be added. The result | |
3341 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
3342 | not have a name. */ | |
3343 | ||
3344 | static const char * | |
3345 | dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu) | |
3346 | { | |
3347 | struct attribute *attr; | |
3348 | char *prefix, *name; | |
3349 | struct ui_file *buf = NULL; | |
3350 | ||
3351 | name = dwarf2_name (die, cu); | |
3352 | if (!name) | |
3353 | return NULL; | |
3354 | ||
3355 | /* These are the only languages we know how to qualify names in. */ | |
3356 | if (cu->language != language_cplus | |
3357 | && cu->language != language_java) | |
3358 | return name; | |
3359 | ||
3360 | /* If no prefix is necessary for this type of DIE, return the | |
3361 | unqualified name. The other three tags listed could be handled | |
3362 | in pdi_needs_namespace, but that requires broader changes. */ | |
3363 | if (!pdi_needs_namespace (die->tag) | |
3364 | && die->tag != DW_TAG_subprogram | |
3365 | && die->tag != DW_TAG_variable | |
3366 | && die->tag != DW_TAG_member) | |
3367 | return name; | |
3368 | ||
3369 | prefix = determine_prefix (die, cu); | |
3370 | if (*prefix != '\0') | |
3371 | name = typename_concat (&cu->objfile->objfile_obstack, prefix, | |
3372 | name, cu); | |
3373 | ||
3374 | return name; | |
3375 | } | |
3376 | ||
27aa8d6a SW |
3377 | /* Read the import statement specified by the given die and record it. */ |
3378 | ||
3379 | static void | |
3380 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
3381 | { | |
3382 | struct attribute *import_attr; | |
3383 | struct die_info *imported_die; | |
de4affc9 | 3384 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 3385 | const char *imported_name; |
794684b6 SW |
3386 | const char *imported_name_prefix; |
3387 | const char *import_prefix; | |
3388 | char *canonical_name; | |
27aa8d6a SW |
3389 | |
3390 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
3391 | if (import_attr == NULL) | |
3392 | { | |
3393 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
3394 | dwarf_tag_name (die->tag)); | |
3395 | return; | |
3396 | } | |
3397 | ||
de4affc9 CC |
3398 | imported_cu = cu; |
3399 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
3400 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
3401 | if (imported_name == NULL) |
3402 | { | |
3403 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
3404 | ||
3405 | The import in the following code: | |
3406 | namespace A | |
3407 | { | |
3408 | typedef int B; | |
3409 | } | |
3410 | ||
3411 | int main () | |
3412 | { | |
3413 | using A::B; | |
3414 | B b; | |
3415 | return b; | |
3416 | } | |
3417 | ||
3418 | ... | |
3419 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
3420 | <52> DW_AT_decl_file : 1 | |
3421 | <53> DW_AT_decl_line : 6 | |
3422 | <54> DW_AT_import : <0x75> | |
3423 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
3424 | <59> DW_AT_name : B | |
3425 | <5b> DW_AT_decl_file : 1 | |
3426 | <5c> DW_AT_decl_line : 2 | |
3427 | <5d> DW_AT_type : <0x6e> | |
3428 | ... | |
3429 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
3430 | <76> DW_AT_byte_size : 4 | |
3431 | <77> DW_AT_encoding : 5 (signed) | |
3432 | ||
3433 | imports the wrong die ( 0x75 instead of 0x58 ). | |
3434 | This case will be ignored until the gcc bug is fixed. */ | |
3435 | return; | |
3436 | } | |
3437 | ||
3438 | /* FIXME: dwarf2_name (die); for the local name after import. */ | |
3439 | ||
794684b6 SW |
3440 | /* Figure out where the statement is being imported to. */ |
3441 | import_prefix = determine_prefix (die, cu); | |
3442 | ||
3443 | /* Figure out what the scope of the imported die is and prepend it | |
3444 | to the name of the imported die. */ | |
de4affc9 | 3445 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 SW |
3446 | |
3447 | if (strlen (imported_name_prefix) > 0) | |
3448 | { | |
3449 | canonical_name = alloca (strlen (imported_name_prefix) + 2 + strlen (imported_name) + 1); | |
3450 | strcpy (canonical_name, imported_name_prefix); | |
3451 | strcat (canonical_name, "::"); | |
3452 | strcat (canonical_name, imported_name); | |
3453 | } | |
3454 | else | |
3455 | { | |
3456 | canonical_name = alloca (strlen (imported_name) + 1); | |
3457 | strcpy (canonical_name, imported_name); | |
3458 | } | |
3459 | ||
3460 | using_directives = cp_add_using (import_prefix,canonical_name, using_directives); | |
27aa8d6a SW |
3461 | } |
3462 | ||
5fb290d7 | 3463 | static void |
e142c38c | 3464 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 3465 | { |
e142c38c | 3466 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
3467 | } |
3468 | ||
cb1df416 DJ |
3469 | static void |
3470 | free_cu_line_header (void *arg) | |
3471 | { | |
3472 | struct dwarf2_cu *cu = arg; | |
3473 | ||
3474 | free_line_header (cu->line_header); | |
3475 | cu->line_header = NULL; | |
3476 | } | |
3477 | ||
c906108c | 3478 | static void |
e7c27a73 | 3479 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3480 | { |
e7c27a73 DJ |
3481 | struct objfile *objfile = cu->objfile; |
3482 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 3483 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 3484 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
3485 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
3486 | struct attribute *attr; | |
e1024ff1 | 3487 | char *name = NULL; |
c906108c SS |
3488 | char *comp_dir = NULL; |
3489 | struct die_info *child_die; | |
3490 | bfd *abfd = objfile->obfd; | |
debd256d | 3491 | struct line_header *line_header = 0; |
e142c38c DJ |
3492 | CORE_ADDR baseaddr; |
3493 | ||
3494 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3495 | |
fae299cd | 3496 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
3497 | |
3498 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
3499 | from finish_block. */ | |
2acceee2 | 3500 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
3501 | lowpc = highpc; |
3502 | lowpc += baseaddr; | |
3503 | highpc += baseaddr; | |
3504 | ||
39cbfefa DJ |
3505 | /* Find the filename. Do not use dwarf2_name here, since the filename |
3506 | is not a source language identifier. */ | |
e142c38c | 3507 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3508 | if (attr) |
3509 | { | |
3510 | name = DW_STRING (attr); | |
3511 | } | |
e1024ff1 | 3512 | |
e142c38c | 3513 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 3514 | if (attr) |
e1024ff1 DJ |
3515 | comp_dir = DW_STRING (attr); |
3516 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 3517 | { |
e1024ff1 DJ |
3518 | comp_dir = ldirname (name); |
3519 | if (comp_dir != NULL) | |
3520 | make_cleanup (xfree, comp_dir); | |
3521 | } | |
3522 | if (comp_dir != NULL) | |
3523 | { | |
3524 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
3525 | directory, get rid of it. */ | |
3526 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 3527 | |
e1024ff1 DJ |
3528 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
3529 | comp_dir = cp + 1; | |
c906108c SS |
3530 | } |
3531 | ||
e1024ff1 DJ |
3532 | if (name == NULL) |
3533 | name = "<unknown>"; | |
3534 | ||
e142c38c | 3535 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
3536 | if (attr) |
3537 | { | |
e142c38c | 3538 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
3539 | } |
3540 | ||
b0f35d58 DL |
3541 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
3542 | if (attr) | |
3543 | cu->producer = DW_STRING (attr); | |
303b6f5d | 3544 | |
c906108c SS |
3545 | /* We assume that we're processing GCC output. */ |
3546 | processing_gcc_compilation = 2; | |
c906108c | 3547 | |
df8a16a1 DJ |
3548 | processing_has_namespace_info = 0; |
3549 | ||
c906108c SS |
3550 | start_symtab (name, comp_dir, lowpc); |
3551 | record_debugformat ("DWARF 2"); | |
303b6f5d | 3552 | record_producer (cu->producer); |
c906108c | 3553 | |
e142c38c | 3554 | initialize_cu_func_list (cu); |
c906108c | 3555 | |
cb1df416 DJ |
3556 | /* Decode line number information if present. We do this before |
3557 | processing child DIEs, so that the line header table is available | |
3558 | for DW_AT_decl_file. */ | |
e142c38c | 3559 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
3560 | if (attr) |
3561 | { | |
debd256d | 3562 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 3563 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
3564 | if (line_header) |
3565 | { | |
cb1df416 DJ |
3566 | cu->line_header = line_header; |
3567 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 3568 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 3569 | } |
5fb290d7 | 3570 | } |
debd256d | 3571 | |
cb1df416 DJ |
3572 | /* Process all dies in compilation unit. */ |
3573 | if (die->child != NULL) | |
3574 | { | |
3575 | child_die = die->child; | |
3576 | while (child_die && child_die->tag) | |
3577 | { | |
3578 | process_die (child_die, cu); | |
3579 | child_die = sibling_die (child_die); | |
3580 | } | |
3581 | } | |
3582 | ||
2e276125 JB |
3583 | /* Decode macro information, if present. Dwarf 2 macro information |
3584 | refers to information in the line number info statement program | |
3585 | header, so we can only read it if we've read the header | |
3586 | successfully. */ | |
e142c38c | 3587 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 3588 | if (attr && line_header) |
2e276125 JB |
3589 | { |
3590 | unsigned int macro_offset = DW_UNSND (attr); | |
3591 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 3592 | comp_dir, abfd, cu); |
2e276125 | 3593 | } |
debd256d | 3594 | do_cleanups (back_to); |
5fb290d7 DJ |
3595 | } |
3596 | ||
348e048f DE |
3597 | /* For TUs we want to skip the first top level sibling if it's not the |
3598 | actual type being defined by this TU. In this case the first top | |
3599 | level sibling is there to provide context only. */ | |
3600 | ||
3601 | static void | |
3602 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3603 | { | |
3604 | struct objfile *objfile = cu->objfile; | |
3605 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
3606 | CORE_ADDR lowpc; | |
3607 | struct attribute *attr; | |
3608 | char *name = NULL; | |
3609 | char *comp_dir = NULL; | |
3610 | struct die_info *child_die; | |
3611 | bfd *abfd = objfile->obfd; | |
3612 | struct line_header *line_header = 0; | |
3613 | ||
3614 | /* start_symtab needs a low pc, but we don't really have one. | |
3615 | Do what read_file_scope would do in the absence of such info. */ | |
3616 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3617 | ||
3618 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
3619 | is not a source language identifier. */ | |
3620 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
3621 | if (attr) | |
3622 | name = DW_STRING (attr); | |
3623 | ||
3624 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
3625 | if (attr) | |
3626 | comp_dir = DW_STRING (attr); | |
3627 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
3628 | { | |
3629 | comp_dir = ldirname (name); | |
3630 | if (comp_dir != NULL) | |
3631 | make_cleanup (xfree, comp_dir); | |
3632 | } | |
3633 | ||
3634 | if (name == NULL) | |
3635 | name = "<unknown>"; | |
3636 | ||
3637 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
3638 | if (attr) | |
3639 | set_cu_language (DW_UNSND (attr), cu); | |
3640 | ||
3641 | /* This isn't technically needed today. It is done for symmetry | |
3642 | with read_file_scope. */ | |
3643 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
3644 | if (attr) | |
3645 | cu->producer = DW_STRING (attr); | |
3646 | ||
3647 | /* We assume that we're processing GCC output. */ | |
3648 | processing_gcc_compilation = 2; | |
3649 | ||
3650 | processing_has_namespace_info = 0; | |
3651 | ||
3652 | start_symtab (name, comp_dir, lowpc); | |
3653 | record_debugformat ("DWARF 2"); | |
3654 | record_producer (cu->producer); | |
3655 | ||
3656 | /* Process the dies in the type unit. */ | |
3657 | if (die->child == NULL) | |
3658 | { | |
3659 | dump_die_for_error (die); | |
3660 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
3661 | bfd_get_filename (abfd)); | |
3662 | } | |
3663 | ||
3664 | child_die = die->child; | |
3665 | ||
3666 | while (child_die && child_die->tag) | |
3667 | { | |
3668 | process_die (child_die, cu); | |
3669 | ||
3670 | child_die = sibling_die (child_die); | |
3671 | } | |
3672 | ||
3673 | do_cleanups (back_to); | |
3674 | } | |
3675 | ||
5fb290d7 | 3676 | static void |
e142c38c DJ |
3677 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
3678 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
3679 | { |
3680 | struct function_range *thisfn; | |
3681 | ||
3682 | thisfn = (struct function_range *) | |
7b5a2f43 | 3683 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
3684 | thisfn->name = name; |
3685 | thisfn->lowpc = lowpc; | |
3686 | thisfn->highpc = highpc; | |
3687 | thisfn->seen_line = 0; | |
3688 | thisfn->next = NULL; | |
3689 | ||
e142c38c DJ |
3690 | if (cu->last_fn == NULL) |
3691 | cu->first_fn = thisfn; | |
5fb290d7 | 3692 | else |
e142c38c | 3693 | cu->last_fn->next = thisfn; |
5fb290d7 | 3694 | |
e142c38c | 3695 | cu->last_fn = thisfn; |
c906108c SS |
3696 | } |
3697 | ||
d389af10 JK |
3698 | /* qsort helper for inherit_abstract_dies. */ |
3699 | ||
3700 | static int | |
3701 | unsigned_int_compar (const void *ap, const void *bp) | |
3702 | { | |
3703 | unsigned int a = *(unsigned int *) ap; | |
3704 | unsigned int b = *(unsigned int *) bp; | |
3705 | ||
3706 | return (a > b) - (b > a); | |
3707 | } | |
3708 | ||
3709 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3710 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
3711 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
3712 | ||
3713 | static void | |
3714 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
3715 | { | |
3716 | struct die_info *child_die; | |
3717 | unsigned die_children_count; | |
3718 | /* CU offsets which were referenced by children of the current DIE. */ | |
3719 | unsigned *offsets; | |
3720 | unsigned *offsets_end, *offsetp; | |
3721 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
3722 | struct die_info *origin_die; | |
3723 | /* Iterator of the ORIGIN_DIE children. */ | |
3724 | struct die_info *origin_child_die; | |
3725 | struct cleanup *cleanups; | |
3726 | struct attribute *attr; | |
3727 | ||
3728 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
3729 | if (!attr) | |
3730 | return; | |
3731 | ||
3732 | origin_die = follow_die_ref (die, attr, &cu); | |
edb3359d DJ |
3733 | if (die->tag != origin_die->tag |
3734 | && !(die->tag == DW_TAG_inlined_subroutine | |
3735 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3736 | complaint (&symfile_complaints, |
3737 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
3738 | die->offset, origin_die->offset); | |
3739 | ||
3740 | child_die = die->child; | |
3741 | die_children_count = 0; | |
3742 | while (child_die && child_die->tag) | |
3743 | { | |
3744 | child_die = sibling_die (child_die); | |
3745 | die_children_count++; | |
3746 | } | |
3747 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
3748 | cleanups = make_cleanup (xfree, offsets); | |
3749 | ||
3750 | offsets_end = offsets; | |
3751 | child_die = die->child; | |
3752 | while (child_die && child_die->tag) | |
3753 | { | |
c38f313d DJ |
3754 | /* For each CHILD_DIE, find the corresponding child of |
3755 | ORIGIN_DIE. If there is more than one layer of | |
3756 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
3757 | but GCC versions at least through 4.4 generate this (GCC PR | |
3758 | 40573). */ | |
3759 | struct die_info *child_origin_die = child_die; | |
3760 | while (1) | |
3761 | { | |
3762 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); | |
3763 | if (attr == NULL) | |
3764 | break; | |
3765 | child_origin_die = follow_die_ref (child_origin_die, attr, &cu); | |
3766 | } | |
3767 | ||
d389af10 JK |
3768 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
3769 | counterpart may exist. */ | |
c38f313d | 3770 | if (child_origin_die != child_die) |
d389af10 | 3771 | { |
edb3359d DJ |
3772 | if (child_die->tag != child_origin_die->tag |
3773 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
3774 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3775 | complaint (&symfile_complaints, |
3776 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3777 | "different tags"), child_die->offset, | |
3778 | child_origin_die->offset); | |
c38f313d DJ |
3779 | if (child_origin_die->parent != origin_die) |
3780 | complaint (&symfile_complaints, | |
3781 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3782 | "different parents"), child_die->offset, | |
3783 | child_origin_die->offset); | |
3784 | else | |
3785 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
3786 | } |
3787 | child_die = sibling_die (child_die); | |
3788 | } | |
3789 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
3790 | unsigned_int_compar); | |
3791 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
3792 | if (offsetp[-1] == *offsetp) | |
3793 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
3794 | "to DIE 0x%x as their abstract origin"), | |
3795 | die->offset, *offsetp); | |
3796 | ||
3797 | offsetp = offsets; | |
3798 | origin_child_die = origin_die->child; | |
3799 | while (origin_child_die && origin_child_die->tag) | |
3800 | { | |
3801 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
3802 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
3803 | offsetp++; | |
3804 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
3805 | { | |
3806 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
3807 | process_die (origin_child_die, cu); | |
3808 | } | |
3809 | origin_child_die = sibling_die (origin_child_die); | |
3810 | } | |
3811 | ||
3812 | do_cleanups (cleanups); | |
3813 | } | |
3814 | ||
c906108c | 3815 | static void |
e7c27a73 | 3816 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3817 | { |
e7c27a73 | 3818 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3819 | struct context_stack *new; |
c906108c SS |
3820 | CORE_ADDR lowpc; |
3821 | CORE_ADDR highpc; | |
3822 | struct die_info *child_die; | |
edb3359d | 3823 | struct attribute *attr, *call_line, *call_file; |
c906108c | 3824 | char *name; |
e142c38c | 3825 | CORE_ADDR baseaddr; |
801e3a5b | 3826 | struct block *block; |
edb3359d DJ |
3827 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
3828 | ||
3829 | if (inlined_func) | |
3830 | { | |
3831 | /* If we do not have call site information, we can't show the | |
3832 | caller of this inlined function. That's too confusing, so | |
3833 | only use the scope for local variables. */ | |
3834 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
3835 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
3836 | if (call_line == NULL || call_file == NULL) | |
3837 | { | |
3838 | read_lexical_block_scope (die, cu); | |
3839 | return; | |
3840 | } | |
3841 | } | |
c906108c | 3842 | |
e142c38c DJ |
3843 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
3844 | ||
3845 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
3846 | |
3847 | /* Ignore functions with missing or empty names and functions with | |
3848 | missing or invalid low and high pc attributes. */ | |
d85a05f0 | 3849 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
3850 | return; |
3851 | ||
3852 | lowpc += baseaddr; | |
3853 | highpc += baseaddr; | |
3854 | ||
5fb290d7 | 3855 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3856 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3857 | |
c906108c | 3858 | new = push_context (0, lowpc); |
f792889a | 3859 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3860 | |
4cecd739 DJ |
3861 | /* If there is a location expression for DW_AT_frame_base, record |
3862 | it. */ | |
e142c38c | 3863 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3864 | if (attr) |
c034e007 AC |
3865 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3866 | expression is being recorded directly in the function's symbol | |
3867 | and not in a separate frame-base object. I guess this hack is | |
3868 | to avoid adding some sort of frame-base adjunct/annex to the | |
3869 | function's symbol :-(. The problem with doing this is that it | |
3870 | results in a function symbol with a location expression that | |
3871 | has nothing to do with the location of the function, ouch! The | |
3872 | relationship should be: a function's symbol has-a frame base; a | |
3873 | frame-base has-a location expression. */ | |
e7c27a73 | 3874 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3875 | |
e142c38c | 3876 | cu->list_in_scope = &local_symbols; |
c906108c | 3877 | |
639d11d3 | 3878 | if (die->child != NULL) |
c906108c | 3879 | { |
639d11d3 | 3880 | child_die = die->child; |
c906108c SS |
3881 | while (child_die && child_die->tag) |
3882 | { | |
e7c27a73 | 3883 | process_die (child_die, cu); |
c906108c SS |
3884 | child_die = sibling_die (child_die); |
3885 | } | |
3886 | } | |
3887 | ||
d389af10 JK |
3888 | inherit_abstract_dies (die, cu); |
3889 | ||
c906108c SS |
3890 | new = pop_context (); |
3891 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3892 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3893 | lowpc, highpc, objfile); | |
3894 | ||
df8a16a1 DJ |
3895 | /* For C++, set the block's scope. */ |
3896 | if (cu->language == language_cplus) | |
3897 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, | |
0114d602 | 3898 | determine_prefix (die, cu), |
df8a16a1 DJ |
3899 | processing_has_namespace_info); |
3900 | ||
801e3a5b JB |
3901 | /* If we have address ranges, record them. */ |
3902 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3903 | |
3904 | /* In C++, we can have functions nested inside functions (e.g., when | |
3905 | a function declares a class that has methods). This means that | |
3906 | when we finish processing a function scope, we may need to go | |
3907 | back to building a containing block's symbol lists. */ | |
3908 | local_symbols = new->locals; | |
3909 | param_symbols = new->params; | |
27aa8d6a | 3910 | using_directives = new->using_directives; |
208d8187 | 3911 | |
921e78cf JB |
3912 | /* If we've finished processing a top-level function, subsequent |
3913 | symbols go in the file symbol list. */ | |
3914 | if (outermost_context_p ()) | |
e142c38c | 3915 | cu->list_in_scope = &file_symbols; |
c906108c SS |
3916 | } |
3917 | ||
3918 | /* Process all the DIES contained within a lexical block scope. Start | |
3919 | a new scope, process the dies, and then close the scope. */ | |
3920 | ||
3921 | static void | |
e7c27a73 | 3922 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3923 | { |
e7c27a73 | 3924 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3925 | struct context_stack *new; |
c906108c SS |
3926 | CORE_ADDR lowpc, highpc; |
3927 | struct die_info *child_die; | |
e142c38c DJ |
3928 | CORE_ADDR baseaddr; |
3929 | ||
3930 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3931 | |
3932 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3933 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3934 | as multiple lexical blocks? Handling children in a sane way would | |
3935 | be nasty. Might be easier to properly extend generic blocks to | |
3936 | describe ranges. */ | |
d85a05f0 | 3937 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
3938 | return; |
3939 | lowpc += baseaddr; | |
3940 | highpc += baseaddr; | |
3941 | ||
3942 | push_context (0, lowpc); | |
639d11d3 | 3943 | if (die->child != NULL) |
c906108c | 3944 | { |
639d11d3 | 3945 | child_die = die->child; |
c906108c SS |
3946 | while (child_die && child_die->tag) |
3947 | { | |
e7c27a73 | 3948 | process_die (child_die, cu); |
c906108c SS |
3949 | child_die = sibling_die (child_die); |
3950 | } | |
3951 | } | |
3952 | new = pop_context (); | |
3953 | ||
3954 | if (local_symbols != NULL) | |
3955 | { | |
801e3a5b JB |
3956 | struct block *block |
3957 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3958 | highpc, objfile); | |
3959 | ||
3960 | /* Note that recording ranges after traversing children, as we | |
3961 | do here, means that recording a parent's ranges entails | |
3962 | walking across all its children's ranges as they appear in | |
3963 | the address map, which is quadratic behavior. | |
3964 | ||
3965 | It would be nicer to record the parent's ranges before | |
3966 | traversing its children, simply overriding whatever you find | |
3967 | there. But since we don't even decide whether to create a | |
3968 | block until after we've traversed its children, that's hard | |
3969 | to do. */ | |
3970 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3971 | } |
3972 | local_symbols = new->locals; | |
27aa8d6a | 3973 | using_directives = new->using_directives; |
c906108c SS |
3974 | } |
3975 | ||
43039443 | 3976 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3977 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3978 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3979 | |
3980 | static int | |
3981 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3982 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3983 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3984 | { |
3985 | struct objfile *objfile = cu->objfile; | |
3986 | struct comp_unit_head *cu_header = &cu->header; | |
3987 | bfd *obfd = objfile->obfd; | |
3988 | unsigned int addr_size = cu_header->addr_size; | |
3989 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3990 | /* Base address selection entry. */ | |
3991 | CORE_ADDR base; | |
3992 | int found_base; | |
3993 | unsigned int dummy; | |
3994 | gdb_byte *buffer; | |
3995 | CORE_ADDR marker; | |
3996 | int low_set; | |
3997 | CORE_ADDR low = 0; | |
3998 | CORE_ADDR high = 0; | |
ff013f42 | 3999 | CORE_ADDR baseaddr; |
43039443 | 4000 | |
d00adf39 DE |
4001 | found_base = cu->base_known; |
4002 | base = cu->base_address; | |
43039443 | 4003 | |
dce234bc | 4004 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
4005 | { |
4006 | complaint (&symfile_complaints, | |
4007 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
4008 | offset); | |
4009 | return 0; | |
4010 | } | |
dce234bc | 4011 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
4012 | |
4013 | /* Read in the largest possible address. */ | |
4014 | marker = read_address (obfd, buffer, cu, &dummy); | |
4015 | if ((marker & mask) == mask) | |
4016 | { | |
4017 | /* If we found the largest possible address, then | |
4018 | read the base address. */ | |
4019 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4020 | buffer += 2 * addr_size; | |
4021 | offset += 2 * addr_size; | |
4022 | found_base = 1; | |
4023 | } | |
4024 | ||
4025 | low_set = 0; | |
4026 | ||
e7030f15 | 4027 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 4028 | |
43039443 JK |
4029 | while (1) |
4030 | { | |
4031 | CORE_ADDR range_beginning, range_end; | |
4032 | ||
4033 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
4034 | buffer += addr_size; | |
4035 | range_end = read_address (obfd, buffer, cu, &dummy); | |
4036 | buffer += addr_size; | |
4037 | offset += 2 * addr_size; | |
4038 | ||
4039 | /* An end of list marker is a pair of zero addresses. */ | |
4040 | if (range_beginning == 0 && range_end == 0) | |
4041 | /* Found the end of list entry. */ | |
4042 | break; | |
4043 | ||
4044 | /* Each base address selection entry is a pair of 2 values. | |
4045 | The first is the largest possible address, the second is | |
4046 | the base address. Check for a base address here. */ | |
4047 | if ((range_beginning & mask) == mask) | |
4048 | { | |
4049 | /* If we found the largest possible address, then | |
4050 | read the base address. */ | |
4051 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4052 | found_base = 1; | |
4053 | continue; | |
4054 | } | |
4055 | ||
4056 | if (!found_base) | |
4057 | { | |
4058 | /* We have no valid base address for the ranges | |
4059 | data. */ | |
4060 | complaint (&symfile_complaints, | |
4061 | _("Invalid .debug_ranges data (no base address)")); | |
4062 | return 0; | |
4063 | } | |
4064 | ||
4065 | range_beginning += base; | |
4066 | range_end += base; | |
4067 | ||
ff013f42 JK |
4068 | if (ranges_pst != NULL && range_beginning < range_end) |
4069 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
4070 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
4071 | ranges_pst); | |
4072 | ||
43039443 JK |
4073 | /* FIXME: This is recording everything as a low-high |
4074 | segment of consecutive addresses. We should have a | |
4075 | data structure for discontiguous block ranges | |
4076 | instead. */ | |
4077 | if (! low_set) | |
4078 | { | |
4079 | low = range_beginning; | |
4080 | high = range_end; | |
4081 | low_set = 1; | |
4082 | } | |
4083 | else | |
4084 | { | |
4085 | if (range_beginning < low) | |
4086 | low = range_beginning; | |
4087 | if (range_end > high) | |
4088 | high = range_end; | |
4089 | } | |
4090 | } | |
4091 | ||
4092 | if (! low_set) | |
4093 | /* If the first entry is an end-of-list marker, the range | |
4094 | describes an empty scope, i.e. no instructions. */ | |
4095 | return 0; | |
4096 | ||
4097 | if (low_return) | |
4098 | *low_return = low; | |
4099 | if (high_return) | |
4100 | *high_return = high; | |
4101 | return 1; | |
4102 | } | |
4103 | ||
af34e669 DJ |
4104 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
4105 | are present and valid, otherwise, return 0. Return -1 if the range is | |
4106 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 4107 | static int |
af34e669 | 4108 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
4109 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
4110 | struct partial_symtab *pst) | |
c906108c SS |
4111 | { |
4112 | struct attribute *attr; | |
af34e669 DJ |
4113 | CORE_ADDR low = 0; |
4114 | CORE_ADDR high = 0; | |
4115 | int ret = 0; | |
c906108c | 4116 | |
e142c38c | 4117 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 4118 | if (attr) |
af34e669 DJ |
4119 | { |
4120 | high = DW_ADDR (attr); | |
e142c38c | 4121 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
4122 | if (attr) |
4123 | low = DW_ADDR (attr); | |
4124 | else | |
4125 | /* Found high w/o low attribute. */ | |
4126 | return 0; | |
4127 | ||
4128 | /* Found consecutive range of addresses. */ | |
4129 | ret = 1; | |
4130 | } | |
c906108c | 4131 | else |
af34e669 | 4132 | { |
e142c38c | 4133 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
4134 | if (attr != NULL) |
4135 | { | |
af34e669 | 4136 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 4137 | .debug_ranges section. */ |
d85a05f0 | 4138 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 4139 | return 0; |
43039443 | 4140 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
4141 | ret = -1; |
4142 | } | |
4143 | } | |
c906108c SS |
4144 | |
4145 | if (high < low) | |
4146 | return 0; | |
4147 | ||
4148 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
4149 | eliminate duplicate copies of functions and vtables and such. | |
4150 | The linker will arbitrarily choose one and discard the others. | |
4151 | The AT_*_pc values for such functions refer to local labels in | |
4152 | these sections. If the section from that file was discarded, the | |
4153 | labels are not in the output, so the relocs get a value of 0. | |
4154 | If this is a discarded function, mark the pc bounds as invalid, | |
4155 | so that GDB will ignore it. */ | |
72dca2f5 | 4156 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
4157 | return 0; |
4158 | ||
4159 | *lowpc = low; | |
4160 | *highpc = high; | |
af34e669 | 4161 | return ret; |
c906108c SS |
4162 | } |
4163 | ||
b084d499 JB |
4164 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
4165 | its low and high PC addresses. Do nothing if these addresses could not | |
4166 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
4167 | and HIGHPC to the high address if greater than HIGHPC. */ | |
4168 | ||
4169 | static void | |
4170 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
4171 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4172 | struct dwarf2_cu *cu) | |
4173 | { | |
4174 | CORE_ADDR low, high; | |
4175 | struct die_info *child = die->child; | |
4176 | ||
d85a05f0 | 4177 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
4178 | { |
4179 | *lowpc = min (*lowpc, low); | |
4180 | *highpc = max (*highpc, high); | |
4181 | } | |
4182 | ||
4183 | /* If the language does not allow nested subprograms (either inside | |
4184 | subprograms or lexical blocks), we're done. */ | |
4185 | if (cu->language != language_ada) | |
4186 | return; | |
4187 | ||
4188 | /* Check all the children of the given DIE. If it contains nested | |
4189 | subprograms, then check their pc bounds. Likewise, we need to | |
4190 | check lexical blocks as well, as they may also contain subprogram | |
4191 | definitions. */ | |
4192 | while (child && child->tag) | |
4193 | { | |
4194 | if (child->tag == DW_TAG_subprogram | |
4195 | || child->tag == DW_TAG_lexical_block) | |
4196 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
4197 | child = sibling_die (child); | |
4198 | } | |
4199 | } | |
4200 | ||
fae299cd DC |
4201 | /* Get the low and high pc's represented by the scope DIE, and store |
4202 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
4203 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
4204 | ||
4205 | static void | |
4206 | get_scope_pc_bounds (struct die_info *die, | |
4207 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4208 | struct dwarf2_cu *cu) | |
4209 | { | |
4210 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
4211 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
4212 | CORE_ADDR current_low, current_high; | |
4213 | ||
d85a05f0 | 4214 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
4215 | { |
4216 | best_low = current_low; | |
4217 | best_high = current_high; | |
4218 | } | |
4219 | else | |
4220 | { | |
4221 | struct die_info *child = die->child; | |
4222 | ||
4223 | while (child && child->tag) | |
4224 | { | |
4225 | switch (child->tag) { | |
4226 | case DW_TAG_subprogram: | |
b084d499 | 4227 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
4228 | break; |
4229 | case DW_TAG_namespace: | |
4230 | /* FIXME: carlton/2004-01-16: Should we do this for | |
4231 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
4232 | that current GCC's always emit the DIEs corresponding | |
4233 | to definitions of methods of classes as children of a | |
4234 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
4235 | the DIEs giving the declarations, which could be | |
4236 | anywhere). But I don't see any reason why the | |
4237 | standards says that they have to be there. */ | |
4238 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
4239 | ||
4240 | if (current_low != ((CORE_ADDR) -1)) | |
4241 | { | |
4242 | best_low = min (best_low, current_low); | |
4243 | best_high = max (best_high, current_high); | |
4244 | } | |
4245 | break; | |
4246 | default: | |
4247 | /* Ignore. */ | |
4248 | break; | |
4249 | } | |
4250 | ||
4251 | child = sibling_die (child); | |
4252 | } | |
4253 | } | |
4254 | ||
4255 | *lowpc = best_low; | |
4256 | *highpc = best_high; | |
4257 | } | |
4258 | ||
801e3a5b JB |
4259 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
4260 | in DIE. */ | |
4261 | static void | |
4262 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
4263 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
4264 | { | |
4265 | struct attribute *attr; | |
4266 | ||
4267 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
4268 | if (attr) | |
4269 | { | |
4270 | CORE_ADDR high = DW_ADDR (attr); | |
4271 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
4272 | if (attr) | |
4273 | { | |
4274 | CORE_ADDR low = DW_ADDR (attr); | |
4275 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
4276 | } | |
4277 | } | |
4278 | ||
4279 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
4280 | if (attr) | |
4281 | { | |
4282 | bfd *obfd = cu->objfile->obfd; | |
4283 | ||
4284 | /* The value of the DW_AT_ranges attribute is the offset of the | |
4285 | address range list in the .debug_ranges section. */ | |
4286 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 4287 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
4288 | |
4289 | /* For some target architectures, but not others, the | |
4290 | read_address function sign-extends the addresses it returns. | |
4291 | To recognize base address selection entries, we need a | |
4292 | mask. */ | |
4293 | unsigned int addr_size = cu->header.addr_size; | |
4294 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
4295 | ||
4296 | /* The base address, to which the next pair is relative. Note | |
4297 | that this 'base' is a DWARF concept: most entries in a range | |
4298 | list are relative, to reduce the number of relocs against the | |
4299 | debugging information. This is separate from this function's | |
4300 | 'baseaddr' argument, which GDB uses to relocate debugging | |
4301 | information from a shared library based on the address at | |
4302 | which the library was loaded. */ | |
d00adf39 DE |
4303 | CORE_ADDR base = cu->base_address; |
4304 | int base_known = cu->base_known; | |
801e3a5b | 4305 | |
dce234bc | 4306 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
4307 | { |
4308 | complaint (&symfile_complaints, | |
4309 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
4310 | offset); | |
4311 | return; | |
4312 | } | |
4313 | ||
4314 | for (;;) | |
4315 | { | |
4316 | unsigned int bytes_read; | |
4317 | CORE_ADDR start, end; | |
4318 | ||
4319 | start = read_address (obfd, buffer, cu, &bytes_read); | |
4320 | buffer += bytes_read; | |
4321 | end = read_address (obfd, buffer, cu, &bytes_read); | |
4322 | buffer += bytes_read; | |
4323 | ||
4324 | /* Did we find the end of the range list? */ | |
4325 | if (start == 0 && end == 0) | |
4326 | break; | |
4327 | ||
4328 | /* Did we find a base address selection entry? */ | |
4329 | else if ((start & base_select_mask) == base_select_mask) | |
4330 | { | |
4331 | base = end; | |
4332 | base_known = 1; | |
4333 | } | |
4334 | ||
4335 | /* We found an ordinary address range. */ | |
4336 | else | |
4337 | { | |
4338 | if (!base_known) | |
4339 | { | |
4340 | complaint (&symfile_complaints, | |
4341 | _("Invalid .debug_ranges data (no base address)")); | |
4342 | return; | |
4343 | } | |
4344 | ||
4345 | record_block_range (block, | |
4346 | baseaddr + base + start, | |
4347 | baseaddr + base + end - 1); | |
4348 | } | |
4349 | } | |
4350 | } | |
4351 | } | |
4352 | ||
c906108c SS |
4353 | /* Add an aggregate field to the field list. */ |
4354 | ||
4355 | static void | |
107d2387 | 4356 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
4357 | struct dwarf2_cu *cu) |
4358 | { | |
4359 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 4360 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
4361 | struct nextfield *new_field; |
4362 | struct attribute *attr; | |
4363 | struct field *fp; | |
4364 | char *fieldname = ""; | |
4365 | ||
4366 | /* Allocate a new field list entry and link it in. */ | |
4367 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 4368 | make_cleanup (xfree, new_field); |
c906108c | 4369 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
4370 | |
4371 | if (die->tag == DW_TAG_inheritance) | |
4372 | { | |
4373 | new_field->next = fip->baseclasses; | |
4374 | fip->baseclasses = new_field; | |
4375 | } | |
4376 | else | |
4377 | { | |
4378 | new_field->next = fip->fields; | |
4379 | fip->fields = new_field; | |
4380 | } | |
c906108c SS |
4381 | fip->nfields++; |
4382 | ||
4383 | /* Handle accessibility and virtuality of field. | |
4384 | The default accessibility for members is public, the default | |
4385 | accessibility for inheritance is private. */ | |
4386 | if (die->tag != DW_TAG_inheritance) | |
4387 | new_field->accessibility = DW_ACCESS_public; | |
4388 | else | |
4389 | new_field->accessibility = DW_ACCESS_private; | |
4390 | new_field->virtuality = DW_VIRTUALITY_none; | |
4391 | ||
e142c38c | 4392 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4393 | if (attr) |
4394 | new_field->accessibility = DW_UNSND (attr); | |
4395 | if (new_field->accessibility != DW_ACCESS_public) | |
4396 | fip->non_public_fields = 1; | |
e142c38c | 4397 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
4398 | if (attr) |
4399 | new_field->virtuality = DW_UNSND (attr); | |
4400 | ||
4401 | fp = &new_field->field; | |
a9a9bd0f | 4402 | |
e142c38c | 4403 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 4404 | { |
a9a9bd0f DC |
4405 | /* Data member other than a C++ static data member. */ |
4406 | ||
c906108c | 4407 | /* Get type of field. */ |
e7c27a73 | 4408 | fp->type = die_type (die, cu); |
c906108c | 4409 | |
d6a843b5 | 4410 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 4411 | |
c906108c | 4412 | /* Get bit size of field (zero if none). */ |
e142c38c | 4413 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
4414 | if (attr) |
4415 | { | |
4416 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
4417 | } | |
4418 | else | |
4419 | { | |
4420 | FIELD_BITSIZE (*fp) = 0; | |
4421 | } | |
4422 | ||
4423 | /* Get bit offset of field. */ | |
e142c38c | 4424 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
4425 | if (attr) |
4426 | { | |
d4b96c9a | 4427 | int byte_offset = 0; |
c6a0999f | 4428 | |
3690dd37 | 4429 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 4430 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 4431 | else if (attr_form_is_constant (attr)) |
c6a0999f | 4432 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 4433 | else if (attr_form_is_block (attr)) |
c6a0999f | 4434 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
4435 | else |
4436 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 4437 | |
d6a843b5 | 4438 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 4439 | } |
e142c38c | 4440 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
4441 | if (attr) |
4442 | { | |
5e2b427d | 4443 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
4444 | { |
4445 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
4446 | additional bit offset from the MSB of the containing |
4447 | anonymous object to the MSB of the field. We don't | |
4448 | have to do anything special since we don't need to | |
4449 | know the size of the anonymous object. */ | |
c906108c SS |
4450 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
4451 | } | |
4452 | else | |
4453 | { | |
4454 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
4455 | MSB of the anonymous object, subtract off the number of |
4456 | bits from the MSB of the field to the MSB of the | |
4457 | object, and then subtract off the number of bits of | |
4458 | the field itself. The result is the bit offset of | |
4459 | the LSB of the field. */ | |
c906108c SS |
4460 | int anonymous_size; |
4461 | int bit_offset = DW_UNSND (attr); | |
4462 | ||
e142c38c | 4463 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4464 | if (attr) |
4465 | { | |
4466 | /* The size of the anonymous object containing | |
4467 | the bit field is explicit, so use the | |
4468 | indicated size (in bytes). */ | |
4469 | anonymous_size = DW_UNSND (attr); | |
4470 | } | |
4471 | else | |
4472 | { | |
4473 | /* The size of the anonymous object containing | |
4474 | the bit field must be inferred from the type | |
4475 | attribute of the data member containing the | |
4476 | bit field. */ | |
4477 | anonymous_size = TYPE_LENGTH (fp->type); | |
4478 | } | |
4479 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
4480 | - bit_offset - FIELD_BITSIZE (*fp); | |
4481 | } | |
4482 | } | |
4483 | ||
4484 | /* Get name of field. */ | |
39cbfefa DJ |
4485 | fieldname = dwarf2_name (die, cu); |
4486 | if (fieldname == NULL) | |
4487 | fieldname = ""; | |
d8151005 DJ |
4488 | |
4489 | /* The name is already allocated along with this objfile, so we don't | |
4490 | need to duplicate it for the type. */ | |
4491 | fp->name = fieldname; | |
c906108c SS |
4492 | |
4493 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 4494 | pointer or virtual base class pointer) to private. */ |
e142c38c | 4495 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 4496 | { |
d48cc9dd | 4497 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
4498 | new_field->accessibility = DW_ACCESS_private; |
4499 | fip->non_public_fields = 1; | |
4500 | } | |
4501 | } | |
a9a9bd0f | 4502 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 4503 | { |
a9a9bd0f DC |
4504 | /* C++ static member. */ |
4505 | ||
4506 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
4507 | is a declaration, but all versions of G++ as of this writing | |
4508 | (so through at least 3.2.1) incorrectly generate | |
4509 | DW_TAG_variable tags. */ | |
4510 | ||
c906108c | 4511 | char *physname; |
c906108c | 4512 | |
a9a9bd0f | 4513 | /* Get name of field. */ |
39cbfefa DJ |
4514 | fieldname = dwarf2_name (die, cu); |
4515 | if (fieldname == NULL) | |
c906108c SS |
4516 | return; |
4517 | ||
2df3850c | 4518 | /* Get physical name. */ |
e142c38c | 4519 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 4520 | |
d8151005 DJ |
4521 | /* The name is already allocated along with this objfile, so we don't |
4522 | need to duplicate it for the type. */ | |
4523 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 4524 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 4525 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
4526 | } |
4527 | else if (die->tag == DW_TAG_inheritance) | |
4528 | { | |
4529 | /* C++ base class field. */ | |
e142c38c | 4530 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 4531 | if (attr) |
d4b96c9a JK |
4532 | { |
4533 | int byte_offset = 0; | |
4534 | ||
4535 | if (attr_form_is_section_offset (attr)) | |
4536 | dwarf2_complex_location_expr_complaint (); | |
4537 | else if (attr_form_is_constant (attr)) | |
4538 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
4539 | else if (attr_form_is_block (attr)) | |
4540 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
4541 | else | |
4542 | dwarf2_complex_location_expr_complaint (); | |
4543 | ||
4544 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
4545 | } | |
c906108c | 4546 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 4547 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
4548 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
4549 | fip->nbaseclasses++; | |
4550 | } | |
4551 | } | |
4552 | ||
4553 | /* Create the vector of fields, and attach it to the type. */ | |
4554 | ||
4555 | static void | |
fba45db2 | 4556 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4557 | struct dwarf2_cu *cu) |
c906108c SS |
4558 | { |
4559 | int nfields = fip->nfields; | |
4560 | ||
4561 | /* Record the field count, allocate space for the array of fields, | |
4562 | and create blank accessibility bitfields if necessary. */ | |
4563 | TYPE_NFIELDS (type) = nfields; | |
4564 | TYPE_FIELDS (type) = (struct field *) | |
4565 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
4566 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
4567 | ||
b4ba55a1 | 4568 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
4569 | { |
4570 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
4571 | ||
4572 | TYPE_FIELD_PRIVATE_BITS (type) = | |
4573 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4574 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
4575 | ||
4576 | TYPE_FIELD_PROTECTED_BITS (type) = | |
4577 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4578 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
4579 | ||
4580 | TYPE_FIELD_IGNORE_BITS (type) = | |
4581 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4582 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
4583 | } | |
4584 | ||
4585 | /* If the type has baseclasses, allocate and clear a bit vector for | |
4586 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 4587 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
4588 | { |
4589 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 4590 | unsigned char *pointer; |
c906108c SS |
4591 | |
4592 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
4593 | pointer = TYPE_ALLOC (type, num_bytes); |
4594 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
4595 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
4596 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
4597 | } | |
4598 | ||
4599 | /* Copy the saved-up fields into the field vector. Start from the head | |
4600 | of the list, adding to the tail of the field array, so that they end | |
4601 | up in the same order in the array in which they were added to the list. */ | |
4602 | while (nfields-- > 0) | |
4603 | { | |
7d0ccb61 DJ |
4604 | struct nextfield *fieldp; |
4605 | ||
4606 | if (fip->fields) | |
4607 | { | |
4608 | fieldp = fip->fields; | |
4609 | fip->fields = fieldp->next; | |
4610 | } | |
4611 | else | |
4612 | { | |
4613 | fieldp = fip->baseclasses; | |
4614 | fip->baseclasses = fieldp->next; | |
4615 | } | |
4616 | ||
4617 | TYPE_FIELD (type, nfields) = fieldp->field; | |
4618 | switch (fieldp->accessibility) | |
c906108c | 4619 | { |
c5aa993b | 4620 | case DW_ACCESS_private: |
b4ba55a1 JB |
4621 | if (cu->language != language_ada) |
4622 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 4623 | break; |
c906108c | 4624 | |
c5aa993b | 4625 | case DW_ACCESS_protected: |
b4ba55a1 JB |
4626 | if (cu->language != language_ada) |
4627 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 4628 | break; |
c906108c | 4629 | |
c5aa993b JM |
4630 | case DW_ACCESS_public: |
4631 | break; | |
c906108c | 4632 | |
c5aa993b JM |
4633 | default: |
4634 | /* Unknown accessibility. Complain and treat it as public. */ | |
4635 | { | |
e2e0b3e5 | 4636 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 4637 | fieldp->accessibility); |
c5aa993b JM |
4638 | } |
4639 | break; | |
c906108c SS |
4640 | } |
4641 | if (nfields < fip->nbaseclasses) | |
4642 | { | |
7d0ccb61 | 4643 | switch (fieldp->virtuality) |
c906108c | 4644 | { |
c5aa993b JM |
4645 | case DW_VIRTUALITY_virtual: |
4646 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
4647 | if (cu->language == language_ada) |
4648 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
4649 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
4650 | break; | |
c906108c SS |
4651 | } |
4652 | } | |
c906108c SS |
4653 | } |
4654 | } | |
4655 | ||
c906108c SS |
4656 | /* Add a member function to the proper fieldlist. */ |
4657 | ||
4658 | static void | |
107d2387 | 4659 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 4660 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 4661 | { |
e7c27a73 | 4662 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4663 | struct attribute *attr; |
4664 | struct fnfieldlist *flp; | |
4665 | int i; | |
4666 | struct fn_field *fnp; | |
4667 | char *fieldname; | |
4668 | char *physname; | |
4669 | struct nextfnfield *new_fnfield; | |
f792889a | 4670 | struct type *this_type; |
c906108c | 4671 | |
b4ba55a1 JB |
4672 | if (cu->language == language_ada) |
4673 | error ("unexpected member function in Ada type"); | |
4674 | ||
2df3850c | 4675 | /* Get name of member function. */ |
39cbfefa DJ |
4676 | fieldname = dwarf2_name (die, cu); |
4677 | if (fieldname == NULL) | |
2df3850c | 4678 | return; |
c906108c | 4679 | |
2df3850c | 4680 | /* Get the mangled name. */ |
e142c38c | 4681 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
4682 | |
4683 | /* Look up member function name in fieldlist. */ | |
4684 | for (i = 0; i < fip->nfnfields; i++) | |
4685 | { | |
27bfe10e | 4686 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
4687 | break; |
4688 | } | |
4689 | ||
4690 | /* Create new list element if necessary. */ | |
4691 | if (i < fip->nfnfields) | |
4692 | flp = &fip->fnfieldlists[i]; | |
4693 | else | |
4694 | { | |
4695 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4696 | { | |
4697 | fip->fnfieldlists = (struct fnfieldlist *) | |
4698 | xrealloc (fip->fnfieldlists, | |
4699 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4700 | * sizeof (struct fnfieldlist)); |
c906108c | 4701 | if (fip->nfnfields == 0) |
c13c43fd | 4702 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
4703 | } |
4704 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
4705 | flp->name = fieldname; | |
4706 | flp->length = 0; | |
4707 | flp->head = NULL; | |
4708 | fip->nfnfields++; | |
4709 | } | |
4710 | ||
4711 | /* Create a new member function field and chain it to the field list | |
4712 | entry. */ | |
4713 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 4714 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
4715 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
4716 | new_fnfield->next = flp->head; | |
4717 | flp->head = new_fnfield; | |
4718 | flp->length++; | |
4719 | ||
4720 | /* Fill in the member function field info. */ | |
4721 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
4722 | /* The name is already allocated along with this objfile, so we don't |
4723 | need to duplicate it for the type. */ | |
4724 | fnp->physname = physname ? physname : ""; | |
c906108c | 4725 | fnp->type = alloc_type (objfile); |
f792889a DJ |
4726 | this_type = read_type_die (die, cu); |
4727 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 4728 | { |
f792889a | 4729 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 4730 | |
f792889a | 4731 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
4732 | of the method itself (TYPE_CODE_METHOD). */ |
4733 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
4734 | TYPE_TARGET_TYPE (this_type), |
4735 | TYPE_FIELDS (this_type), | |
4736 | TYPE_NFIELDS (this_type), | |
4737 | TYPE_VARARGS (this_type)); | |
c906108c SS |
4738 | |
4739 | /* Handle static member functions. | |
c5aa993b JM |
4740 | Dwarf2 has no clean way to discern C++ static and non-static |
4741 | member functions. G++ helps GDB by marking the first | |
4742 | parameter for non-static member functions (which is the | |
4743 | this pointer) as artificial. We obtain this information | |
4744 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 4745 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
4746 | fnp->voffset = VOFFSET_STATIC; |
4747 | } | |
4748 | else | |
e2e0b3e5 | 4749 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 4750 | physname); |
c906108c SS |
4751 | |
4752 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 4753 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 4754 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
4755 | |
4756 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
4757 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
4758 | ||
4759 | /* Get accessibility. */ | |
e142c38c | 4760 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4761 | if (attr) |
4762 | { | |
4763 | switch (DW_UNSND (attr)) | |
4764 | { | |
c5aa993b JM |
4765 | case DW_ACCESS_private: |
4766 | fnp->is_private = 1; | |
4767 | break; | |
4768 | case DW_ACCESS_protected: | |
4769 | fnp->is_protected = 1; | |
4770 | break; | |
c906108c SS |
4771 | } |
4772 | } | |
4773 | ||
b02dede2 | 4774 | /* Check for artificial methods. */ |
e142c38c | 4775 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
4776 | if (attr && DW_UNSND (attr) != 0) |
4777 | fnp->is_artificial = 1; | |
4778 | ||
0d564a31 DJ |
4779 | /* Get index in virtual function table if it is a virtual member |
4780 | function. For GCC, this is an offset in the appropriate | |
4781 | virtual table, as specified by DW_AT_containing_type. For | |
4782 | everyone else, it is an expression to be evaluated relative | |
4783 | to the object address. */ | |
4784 | ||
e142c38c | 4785 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
0d564a31 | 4786 | if (attr && fnp->fcontext) |
8e19ed76 PS |
4787 | { |
4788 | /* Support the .debug_loc offsets */ | |
4789 | if (attr_form_is_block (attr)) | |
4790 | { | |
e7c27a73 | 4791 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 4792 | } |
3690dd37 | 4793 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4794 | { |
4d3c2250 | 4795 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4796 | } |
4797 | else | |
4798 | { | |
4d3c2250 KB |
4799 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
4800 | fieldname); | |
8e19ed76 | 4801 | } |
0d564a31 DJ |
4802 | } |
4803 | else if (attr) | |
4804 | { | |
4805 | /* We only support trivial expressions here. This hack will work | |
ba950e4d | 4806 | for v3 classes, which always start with the vtable pointer. */ |
0d564a31 DJ |
4807 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0 |
4808 | && DW_BLOCK (attr)->data[0] == DW_OP_deref) | |
4809 | { | |
4810 | struct dwarf_block blk; | |
4811 | blk.size = DW_BLOCK (attr)->size - 1; | |
4812 | blk.data = DW_BLOCK (attr)->data + 1; | |
ba950e4d DJ |
4813 | fnp->voffset = decode_locdesc (&blk, cu); |
4814 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
4815 | dwarf2_complex_location_expr_complaint (); | |
4816 | else | |
4817 | fnp->voffset /= cu->header.addr_size; | |
0d564a31 DJ |
4818 | fnp->voffset += 2; |
4819 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
4820 | } | |
4821 | else | |
4822 | dwarf2_complex_location_expr_complaint (); | |
4823 | } | |
d48cc9dd DJ |
4824 | else |
4825 | { | |
4826 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
4827 | if (attr && DW_UNSND (attr)) | |
4828 | { | |
4829 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
4830 | complaint (&symfile_complaints, | |
4831 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
4832 | fieldname, die->offset); | |
4833 | TYPE_CPLUS_DYNAMIC (type) = 1; | |
4834 | } | |
4835 | } | |
c906108c SS |
4836 | } |
4837 | ||
4838 | /* Create the vector of member function fields, and attach it to the type. */ | |
4839 | ||
4840 | static void | |
fba45db2 | 4841 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4842 | struct dwarf2_cu *cu) |
c906108c SS |
4843 | { |
4844 | struct fnfieldlist *flp; | |
4845 | int total_length = 0; | |
4846 | int i; | |
4847 | ||
b4ba55a1 JB |
4848 | if (cu->language == language_ada) |
4849 | error ("unexpected member functions in Ada type"); | |
4850 | ||
c906108c SS |
4851 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
4852 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
4853 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
4854 | ||
4855 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
4856 | { | |
4857 | struct nextfnfield *nfp = flp->head; | |
4858 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
4859 | int k; | |
4860 | ||
4861 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
4862 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
4863 | fn_flp->fn_fields = (struct fn_field *) | |
4864 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
4865 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 4866 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
4867 | |
4868 | total_length += flp->length; | |
4869 | } | |
4870 | ||
4871 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
4872 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
4873 | } | |
4874 | ||
1168df01 JB |
4875 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
4876 | language, zero otherwise. */ | |
4877 | static int | |
4878 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
4879 | { | |
4880 | static const char vptr[] = "_vptr"; | |
987504bb | 4881 | static const char vtable[] = "vtable"; |
1168df01 | 4882 | |
987504bb JJ |
4883 | /* Look for the C++ and Java forms of the vtable. */ |
4884 | if ((cu->language == language_java | |
4885 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
4886 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
4887 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
4888 | return 1; |
4889 | ||
4890 | return 0; | |
4891 | } | |
4892 | ||
c0dd20ea DJ |
4893 | /* GCC outputs unnamed structures that are really pointers to member |
4894 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
4895 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
4896 | zero. |
4897 | ||
4898 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
4899 | This is GCC PR debug/28767. */ | |
c0dd20ea | 4900 | |
f792889a | 4901 | static struct type * |
c0dd20ea DJ |
4902 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) |
4903 | { | |
4904 | struct objfile *objfile = cu->objfile; | |
4905 | struct type *type; | |
4906 | struct die_info *pfn_die, *delta_die; | |
4907 | struct attribute *pfn_name, *delta_name; | |
4908 | struct type *pfn_type, *domain_type; | |
4909 | ||
4910 | /* Check for a structure with no name and two children. */ | |
4911 | if (die->tag != DW_TAG_structure_type | |
4912 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
4913 | || die->child == NULL | |
4914 | || die->child->sibling == NULL | |
4915 | || (die->child->sibling->sibling != NULL | |
4916 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
f792889a | 4917 | return NULL; |
c0dd20ea DJ |
4918 | |
4919 | /* Check for __pfn and __delta members. */ | |
4920 | pfn_die = die->child; | |
4921 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
4922 | if (pfn_die->tag != DW_TAG_member | |
4923 | || pfn_name == NULL | |
4924 | || DW_STRING (pfn_name) == NULL | |
4925 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
f792889a | 4926 | return NULL; |
c0dd20ea DJ |
4927 | |
4928 | delta_die = pfn_die->sibling; | |
4929 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
4930 | if (delta_die->tag != DW_TAG_member | |
4931 | || delta_name == NULL | |
4932 | || DW_STRING (delta_name) == NULL | |
4933 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
f792889a | 4934 | return NULL; |
c0dd20ea DJ |
4935 | |
4936 | /* Find the type of the method. */ | |
4937 | pfn_type = die_type (pfn_die, cu); | |
4938 | if (pfn_type == NULL | |
4939 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
4940 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
f792889a | 4941 | return NULL; |
c0dd20ea DJ |
4942 | |
4943 | /* Look for the "this" argument. */ | |
4944 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
4945 | if (TYPE_NFIELDS (pfn_type) == 0 | |
4946 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
f792889a | 4947 | return NULL; |
c0dd20ea DJ |
4948 | |
4949 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
4950 | type = alloc_type (objfile); | |
4951 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
4952 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
4953 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 4954 | type = lookup_methodptr_type (type); |
f792889a | 4955 | return set_die_type (die, type, cu); |
c0dd20ea | 4956 | } |
1168df01 | 4957 | |
c906108c SS |
4958 | /* Called when we find the DIE that starts a structure or union scope |
4959 | (definition) to process all dies that define the members of the | |
4960 | structure or union. | |
4961 | ||
4962 | NOTE: we need to call struct_type regardless of whether or not the | |
4963 | DIE has an at_name attribute, since it might be an anonymous | |
4964 | structure or union. This gets the type entered into our set of | |
4965 | user defined types. | |
4966 | ||
4967 | However, if the structure is incomplete (an opaque struct/union) | |
4968 | then suppress creating a symbol table entry for it since gdb only | |
4969 | wants to find the one with the complete definition. Note that if | |
4970 | it is complete, we just call new_symbol, which does it's own | |
4971 | checking about whether the struct/union is anonymous or not (and | |
4972 | suppresses creating a symbol table entry itself). */ | |
4973 | ||
f792889a | 4974 | static struct type * |
134d01f1 | 4975 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4976 | { |
e7c27a73 | 4977 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4978 | struct type *type; |
4979 | struct attribute *attr; | |
39cbfefa | 4980 | char *name; |
0114d602 | 4981 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c | 4982 | |
f792889a DJ |
4983 | type = quirk_gcc_member_function_pointer (die, cu); |
4984 | if (type) | |
4985 | return type; | |
c906108c | 4986 | |
348e048f DE |
4987 | /* If the definition of this type lives in .debug_types, read that type. |
4988 | Don't follow DW_AT_specification though, that will take us back up | |
4989 | the chain and we want to go down. */ | |
4990 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
4991 | if (attr) | |
4992 | { | |
4993 | struct dwarf2_cu *type_cu = cu; | |
4994 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
4995 | /* We could just recurse on read_structure_type, but we need to call | |
4996 | get_die_type to ensure only one type for this DIE is created. | |
4997 | This is important, for example, because for c++ classes we need | |
4998 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
4999 | type = read_type_die (type_die, type_cu); | |
5000 | return set_die_type (die, type, cu); | |
5001 | } | |
5002 | ||
c0dd20ea | 5003 | type = alloc_type (objfile); |
c906108c | 5004 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 5005 | |
39cbfefa DJ |
5006 | name = dwarf2_name (die, cu); |
5007 | if (name != NULL) | |
c906108c | 5008 | { |
987504bb JJ |
5009 | if (cu->language == language_cplus |
5010 | || cu->language == language_java) | |
63d06c5c | 5011 | { |
0114d602 DJ |
5012 | const char *new_prefix = determine_class_name (die, cu); |
5013 | TYPE_TAG_NAME (type) = (char *) new_prefix; | |
63d06c5c DC |
5014 | } |
5015 | else | |
5016 | { | |
d8151005 DJ |
5017 | /* The name is already allocated along with this objfile, so |
5018 | we don't need to duplicate it for the type. */ | |
39cbfefa | 5019 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 5020 | } |
c906108c SS |
5021 | } |
5022 | ||
5023 | if (die->tag == DW_TAG_structure_type) | |
5024 | { | |
5025 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
5026 | } | |
5027 | else if (die->tag == DW_TAG_union_type) | |
5028 | { | |
5029 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
5030 | } | |
5031 | else | |
5032 | { | |
5033 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 5034 | in gdbtypes.h. */ |
c906108c SS |
5035 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
5036 | } | |
5037 | ||
e142c38c | 5038 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5039 | if (attr) |
5040 | { | |
5041 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5042 | } | |
5043 | else | |
5044 | { | |
5045 | TYPE_LENGTH (type) = 0; | |
5046 | } | |
5047 | ||
876cecd0 | 5048 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 5049 | if (die_is_declaration (die, cu)) |
876cecd0 | 5050 | TYPE_STUB (type) = 1; |
dc718098 | 5051 | |
b4ba55a1 JB |
5052 | set_descriptive_type (type, die, cu); |
5053 | ||
c906108c SS |
5054 | /* We need to add the type field to the die immediately so we don't |
5055 | infinitely recurse when dealing with pointers to the structure | |
5056 | type within the structure itself. */ | |
1c379e20 | 5057 | set_die_type (die, type, cu); |
c906108c | 5058 | |
e142c38c | 5059 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
5060 | { |
5061 | struct field_info fi; | |
5062 | struct die_info *child_die; | |
c906108c SS |
5063 | |
5064 | memset (&fi, 0, sizeof (struct field_info)); | |
5065 | ||
639d11d3 | 5066 | child_die = die->child; |
c906108c SS |
5067 | |
5068 | while (child_die && child_die->tag) | |
5069 | { | |
a9a9bd0f DC |
5070 | if (child_die->tag == DW_TAG_member |
5071 | || child_die->tag == DW_TAG_variable) | |
c906108c | 5072 | { |
a9a9bd0f DC |
5073 | /* NOTE: carlton/2002-11-05: A C++ static data member |
5074 | should be a DW_TAG_member that is a declaration, but | |
5075 | all versions of G++ as of this writing (so through at | |
5076 | least 3.2.1) incorrectly generate DW_TAG_variable | |
5077 | tags for them instead. */ | |
e7c27a73 | 5078 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5079 | } |
8713b1b1 | 5080 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
5081 | { |
5082 | /* C++ member function. */ | |
e7c27a73 | 5083 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
5084 | } |
5085 | else if (child_die->tag == DW_TAG_inheritance) | |
5086 | { | |
5087 | /* C++ base class field. */ | |
e7c27a73 | 5088 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5089 | } |
c906108c SS |
5090 | child_die = sibling_die (child_die); |
5091 | } | |
5092 | ||
5093 | /* Attach fields and member functions to the type. */ | |
5094 | if (fi.nfields) | |
e7c27a73 | 5095 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
5096 | if (fi.nfnfields) |
5097 | { | |
e7c27a73 | 5098 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 5099 | |
c5aa993b | 5100 | /* Get the type which refers to the base class (possibly this |
c906108c | 5101 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
5102 | class from the DW_AT_containing_type attribute. This use of |
5103 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 5104 | |
e142c38c | 5105 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 5106 | { |
e7c27a73 | 5107 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
5108 | |
5109 | TYPE_VPTR_BASETYPE (type) = t; | |
5110 | if (type == t) | |
5111 | { | |
c906108c SS |
5112 | int i; |
5113 | ||
5114 | /* Our own class provides vtbl ptr. */ | |
5115 | for (i = TYPE_NFIELDS (t) - 1; | |
5116 | i >= TYPE_N_BASECLASSES (t); | |
5117 | --i) | |
5118 | { | |
5119 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
5120 | ||
1168df01 | 5121 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
5122 | { |
5123 | TYPE_VPTR_FIELDNO (type) = i; | |
5124 | break; | |
5125 | } | |
5126 | } | |
5127 | ||
5128 | /* Complain if virtual function table field not found. */ | |
5129 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 5130 | complaint (&symfile_complaints, |
e2e0b3e5 | 5131 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
5132 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
5133 | ""); | |
c906108c SS |
5134 | } |
5135 | else | |
5136 | { | |
5137 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
5138 | } | |
5139 | } | |
f6235d4c EZ |
5140 | else if (cu->producer |
5141 | && strncmp (cu->producer, | |
5142 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
5143 | { | |
5144 | /* The IBM XLC compiler does not provide direct indication | |
5145 | of the containing type, but the vtable pointer is | |
5146 | always named __vfp. */ | |
5147 | ||
5148 | int i; | |
5149 | ||
5150 | for (i = TYPE_NFIELDS (type) - 1; | |
5151 | i >= TYPE_N_BASECLASSES (type); | |
5152 | --i) | |
5153 | { | |
5154 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
5155 | { | |
5156 | TYPE_VPTR_FIELDNO (type) = i; | |
5157 | TYPE_VPTR_BASETYPE (type) = type; | |
5158 | break; | |
5159 | } | |
5160 | } | |
5161 | } | |
c906108c | 5162 | } |
c906108c | 5163 | } |
63d06c5c | 5164 | |
0114d602 | 5165 | do_cleanups (back_to); |
f792889a | 5166 | return type; |
c906108c SS |
5167 | } |
5168 | ||
134d01f1 DJ |
5169 | static void |
5170 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5171 | { | |
5172 | struct objfile *objfile = cu->objfile; | |
90aeadfc | 5173 | struct die_info *child_die = die->child; |
f792889a | 5174 | struct type *this_type; |
c906108c | 5175 | |
f792889a DJ |
5176 | this_type = get_die_type (die, cu); |
5177 | if (this_type == NULL) | |
5178 | this_type = read_structure_type (die, cu); | |
c906108c | 5179 | |
90aeadfc DC |
5180 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
5181 | snapshots) has been known to create a die giving a declaration | |
5182 | for a class that has, as a child, a die giving a definition for a | |
5183 | nested class. So we have to process our children even if the | |
5184 | current die is a declaration. Normally, of course, a declaration | |
5185 | won't have any children at all. */ | |
134d01f1 | 5186 | |
90aeadfc DC |
5187 | while (child_die != NULL && child_die->tag) |
5188 | { | |
5189 | if (child_die->tag == DW_TAG_member | |
5190 | || child_die->tag == DW_TAG_variable | |
5191 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 5192 | { |
90aeadfc | 5193 | /* Do nothing. */ |
134d01f1 | 5194 | } |
90aeadfc DC |
5195 | else |
5196 | process_die (child_die, cu); | |
134d01f1 | 5197 | |
90aeadfc | 5198 | child_die = sibling_die (child_die); |
134d01f1 DJ |
5199 | } |
5200 | ||
fa4028e9 JB |
5201 | /* Do not consider external references. According to the DWARF standard, |
5202 | these DIEs are identified by the fact that they have no byte_size | |
5203 | attribute, and a declaration attribute. */ | |
5204 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
5205 | || !die_is_declaration (die, cu)) | |
f792889a | 5206 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
5207 | } |
5208 | ||
5209 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
5210 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 5211 | |
f792889a | 5212 | static struct type * |
134d01f1 | 5213 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5214 | { |
e7c27a73 | 5215 | struct objfile *objfile = cu->objfile; |
c906108c | 5216 | struct type *type; |
c906108c | 5217 | struct attribute *attr; |
0114d602 | 5218 | const char *name; |
134d01f1 | 5219 | |
348e048f DE |
5220 | /* If the definition of this type lives in .debug_types, read that type. |
5221 | Don't follow DW_AT_specification though, that will take us back up | |
5222 | the chain and we want to go down. */ | |
5223 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
5224 | if (attr) | |
5225 | { | |
5226 | struct dwarf2_cu *type_cu = cu; | |
5227 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
5228 | type = read_type_die (type_die, type_cu); | |
5229 | return set_die_type (die, type, cu); | |
5230 | } | |
5231 | ||
c906108c SS |
5232 | type = alloc_type (objfile); |
5233 | ||
5234 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
0114d602 | 5235 | name = dwarf2_full_name (die, cu); |
39cbfefa | 5236 | if (name != NULL) |
0114d602 | 5237 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 5238 | |
e142c38c | 5239 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5240 | if (attr) |
5241 | { | |
5242 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5243 | } | |
5244 | else | |
5245 | { | |
5246 | TYPE_LENGTH (type) = 0; | |
5247 | } | |
5248 | ||
137033e9 JB |
5249 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
5250 | declared as private in the package spec, and then defined only | |
5251 | inside the package body. Such types are known as Taft Amendment | |
5252 | Types. When another package uses such a type, an incomplete DIE | |
5253 | may be generated by the compiler. */ | |
02eb380e | 5254 | if (die_is_declaration (die, cu)) |
876cecd0 | 5255 | TYPE_STUB (type) = 1; |
02eb380e | 5256 | |
f792889a | 5257 | return set_die_type (die, type, cu); |
134d01f1 DJ |
5258 | } |
5259 | ||
8176b9b8 | 5260 | /* Determine the name of the type represented by DIE, which should be |
0114d602 DJ |
5261 | a named C++ or Java compound type. Return the name in question, |
5262 | allocated on the objfile obstack. */ | |
8176b9b8 | 5263 | |
0114d602 | 5264 | static const char * |
8176b9b8 DC |
5265 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) |
5266 | { | |
0114d602 | 5267 | const char *new_prefix = NULL; |
8176b9b8 DC |
5268 | |
5269 | /* If we don't have namespace debug info, guess the name by trying | |
5270 | to demangle the names of members, just like we did in | |
72bf9492 | 5271 | guess_structure_name. */ |
8176b9b8 DC |
5272 | if (!processing_has_namespace_info) |
5273 | { | |
5274 | struct die_info *child; | |
5275 | ||
5276 | for (child = die->child; | |
5277 | child != NULL && child->tag != 0; | |
5278 | child = sibling_die (child)) | |
5279 | { | |
5280 | if (child->tag == DW_TAG_subprogram) | |
5281 | { | |
0114d602 | 5282 | char *phys_prefix |
31c27f77 JJ |
5283 | = language_class_name_from_physname (cu->language_defn, |
5284 | dwarf2_linkage_name | |
8176b9b8 DC |
5285 | (child, cu)); |
5286 | ||
0114d602 DJ |
5287 | if (phys_prefix != NULL) |
5288 | { | |
5289 | new_prefix | |
5290 | = obsavestring (phys_prefix, strlen (phys_prefix), | |
5291 | &cu->objfile->objfile_obstack); | |
5292 | xfree (phys_prefix); | |
5293 | break; | |
5294 | } | |
8176b9b8 DC |
5295 | } |
5296 | } | |
5297 | } | |
5298 | ||
5299 | if (new_prefix == NULL) | |
0114d602 | 5300 | new_prefix = dwarf2_full_name (die, cu); |
8176b9b8 DC |
5301 | |
5302 | return new_prefix; | |
5303 | } | |
5304 | ||
134d01f1 DJ |
5305 | /* Given a pointer to a die which begins an enumeration, process all |
5306 | the dies that define the members of the enumeration, and create the | |
5307 | symbol for the enumeration type. | |
5308 | ||
5309 | NOTE: We reverse the order of the element list. */ | |
5310 | ||
5311 | static void | |
5312 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5313 | { | |
5314 | struct objfile *objfile = cu->objfile; | |
5315 | struct die_info *child_die; | |
5316 | struct field *fields; | |
134d01f1 DJ |
5317 | struct symbol *sym; |
5318 | int num_fields; | |
5319 | int unsigned_enum = 1; | |
39cbfefa | 5320 | char *name; |
f792889a | 5321 | struct type *this_type; |
134d01f1 | 5322 | |
c906108c SS |
5323 | num_fields = 0; |
5324 | fields = NULL; | |
f792889a DJ |
5325 | this_type = get_die_type (die, cu); |
5326 | if (this_type == NULL) | |
5327 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 5328 | if (die->child != NULL) |
c906108c | 5329 | { |
639d11d3 | 5330 | child_die = die->child; |
c906108c SS |
5331 | while (child_die && child_die->tag) |
5332 | { | |
5333 | if (child_die->tag != DW_TAG_enumerator) | |
5334 | { | |
e7c27a73 | 5335 | process_die (child_die, cu); |
c906108c SS |
5336 | } |
5337 | else | |
5338 | { | |
39cbfefa DJ |
5339 | name = dwarf2_name (child_die, cu); |
5340 | if (name) | |
c906108c | 5341 | { |
f792889a | 5342 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
5343 | if (SYMBOL_VALUE (sym) < 0) |
5344 | unsigned_enum = 0; | |
5345 | ||
5346 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
5347 | { | |
5348 | fields = (struct field *) | |
5349 | xrealloc (fields, | |
5350 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 5351 | * sizeof (struct field)); |
c906108c SS |
5352 | } |
5353 | ||
3567439c | 5354 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 5355 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 5356 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
5357 | FIELD_BITSIZE (fields[num_fields]) = 0; |
5358 | ||
5359 | num_fields++; | |
5360 | } | |
5361 | } | |
5362 | ||
5363 | child_die = sibling_die (child_die); | |
5364 | } | |
5365 | ||
5366 | if (num_fields) | |
5367 | { | |
f792889a DJ |
5368 | TYPE_NFIELDS (this_type) = num_fields; |
5369 | TYPE_FIELDS (this_type) = (struct field *) | |
5370 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
5371 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 5372 | sizeof (struct field) * num_fields); |
b8c9b27d | 5373 | xfree (fields); |
c906108c SS |
5374 | } |
5375 | if (unsigned_enum) | |
876cecd0 | 5376 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 5377 | } |
134d01f1 | 5378 | |
f792889a | 5379 | new_symbol (die, this_type, cu); |
c906108c SS |
5380 | } |
5381 | ||
5382 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
5383 | the DIE's type field. For now, this only handles one dimensional | |
5384 | arrays. */ | |
5385 | ||
f792889a | 5386 | static struct type * |
e7c27a73 | 5387 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5388 | { |
e7c27a73 | 5389 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5390 | struct die_info *child_die; |
5391 | struct type *type = NULL; | |
5392 | struct type *element_type, *range_type, *index_type; | |
5393 | struct type **range_types = NULL; | |
5394 | struct attribute *attr; | |
5395 | int ndim = 0; | |
5396 | struct cleanup *back_to; | |
39cbfefa | 5397 | char *name; |
c906108c | 5398 | |
e7c27a73 | 5399 | element_type = die_type (die, cu); |
c906108c SS |
5400 | |
5401 | /* Irix 6.2 native cc creates array types without children for | |
5402 | arrays with unspecified length. */ | |
639d11d3 | 5403 | if (die->child == NULL) |
c906108c | 5404 | { |
46bf5051 | 5405 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5406 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
5407 | type = create_array_type (NULL, element_type, range_type); |
5408 | return set_die_type (die, type, cu); | |
c906108c SS |
5409 | } |
5410 | ||
5411 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 5412 | child_die = die->child; |
c906108c SS |
5413 | while (child_die && child_die->tag) |
5414 | { | |
5415 | if (child_die->tag == DW_TAG_subrange_type) | |
5416 | { | |
f792889a DJ |
5417 | struct type *child_type = read_type_die (child_die, cu); |
5418 | if (child_type != NULL) | |
a02abb62 JB |
5419 | { |
5420 | /* The range type was succesfully read. Save it for | |
5421 | the array type creation. */ | |
5422 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
5423 | { | |
5424 | range_types = (struct type **) | |
5425 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
5426 | * sizeof (struct type *)); | |
5427 | if (ndim == 0) | |
5428 | make_cleanup (free_current_contents, &range_types); | |
5429 | } | |
f792889a | 5430 | range_types[ndim++] = child_type; |
a02abb62 | 5431 | } |
c906108c SS |
5432 | } |
5433 | child_die = sibling_die (child_die); | |
5434 | } | |
5435 | ||
5436 | /* Dwarf2 dimensions are output from left to right, create the | |
5437 | necessary array types in backwards order. */ | |
7ca2d3a3 | 5438 | |
c906108c | 5439 | type = element_type; |
7ca2d3a3 DL |
5440 | |
5441 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
5442 | { | |
5443 | int i = 0; | |
5444 | while (i < ndim) | |
5445 | type = create_array_type (NULL, type, range_types[i++]); | |
5446 | } | |
5447 | else | |
5448 | { | |
5449 | while (ndim-- > 0) | |
5450 | type = create_array_type (NULL, type, range_types[ndim]); | |
5451 | } | |
c906108c | 5452 | |
f5f8a009 EZ |
5453 | /* Understand Dwarf2 support for vector types (like they occur on |
5454 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
5455 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
5456 | custom vendor extension. The main difference between a regular | |
5457 | array and the vector variant is that vectors are passed by value | |
5458 | to functions. */ | |
e142c38c | 5459 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 5460 | if (attr) |
ea37ba09 | 5461 | make_vector_type (type); |
f5f8a009 | 5462 | |
39cbfefa DJ |
5463 | name = dwarf2_name (die, cu); |
5464 | if (name) | |
5465 | TYPE_NAME (type) = name; | |
714e295e | 5466 | |
b4ba55a1 JB |
5467 | set_descriptive_type (type, die, cu); |
5468 | ||
c906108c SS |
5469 | do_cleanups (back_to); |
5470 | ||
5471 | /* Install the type in the die. */ | |
f792889a | 5472 | return set_die_type (die, type, cu); |
c906108c SS |
5473 | } |
5474 | ||
7ca2d3a3 DL |
5475 | static enum dwarf_array_dim_ordering |
5476 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
5477 | { | |
5478 | struct attribute *attr; | |
5479 | ||
5480 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
5481 | ||
5482 | if (attr) return DW_SND (attr); | |
5483 | ||
5484 | /* | |
5485 | GNU F77 is a special case, as at 08/2004 array type info is the | |
5486 | opposite order to the dwarf2 specification, but data is still | |
5487 | laid out as per normal fortran. | |
5488 | ||
5489 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
5490 | version checking. | |
5491 | */ | |
5492 | ||
905e0470 PM |
5493 | if (cu->language == language_fortran |
5494 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
5495 | { |
5496 | return DW_ORD_row_major; | |
5497 | } | |
5498 | ||
5499 | switch (cu->language_defn->la_array_ordering) | |
5500 | { | |
5501 | case array_column_major: | |
5502 | return DW_ORD_col_major; | |
5503 | case array_row_major: | |
5504 | default: | |
5505 | return DW_ORD_row_major; | |
5506 | }; | |
5507 | } | |
5508 | ||
72019c9c GM |
5509 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
5510 | the DIE's type field. */ | |
5511 | ||
f792889a | 5512 | static struct type * |
72019c9c GM |
5513 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
5514 | { | |
f792889a DJ |
5515 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
5516 | ||
5517 | return set_die_type (die, set_type, cu); | |
72019c9c | 5518 | } |
7ca2d3a3 | 5519 | |
c906108c SS |
5520 | /* First cut: install each common block member as a global variable. */ |
5521 | ||
5522 | static void | |
e7c27a73 | 5523 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5524 | { |
5525 | struct die_info *child_die; | |
5526 | struct attribute *attr; | |
5527 | struct symbol *sym; | |
5528 | CORE_ADDR base = (CORE_ADDR) 0; | |
5529 | ||
e142c38c | 5530 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
5531 | if (attr) |
5532 | { | |
8e19ed76 PS |
5533 | /* Support the .debug_loc offsets */ |
5534 | if (attr_form_is_block (attr)) | |
5535 | { | |
e7c27a73 | 5536 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 5537 | } |
3690dd37 | 5538 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 5539 | { |
4d3c2250 | 5540 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5541 | } |
5542 | else | |
5543 | { | |
4d3c2250 KB |
5544 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5545 | "common block member"); | |
8e19ed76 | 5546 | } |
c906108c | 5547 | } |
639d11d3 | 5548 | if (die->child != NULL) |
c906108c | 5549 | { |
639d11d3 | 5550 | child_die = die->child; |
c906108c SS |
5551 | while (child_die && child_die->tag) |
5552 | { | |
e7c27a73 | 5553 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 5554 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
5555 | if (attr) |
5556 | { | |
d4b96c9a JK |
5557 | CORE_ADDR byte_offset = 0; |
5558 | ||
5559 | if (attr_form_is_section_offset (attr)) | |
5560 | dwarf2_complex_location_expr_complaint (); | |
5561 | else if (attr_form_is_constant (attr)) | |
5562 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
5563 | else if (attr_form_is_block (attr)) | |
5564 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
5565 | else | |
5566 | dwarf2_complex_location_expr_complaint (); | |
5567 | ||
5568 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
5569 | add_symbol_to_list (sym, &global_symbols); |
5570 | } | |
5571 | child_die = sibling_die (child_die); | |
5572 | } | |
5573 | } | |
5574 | } | |
5575 | ||
0114d602 | 5576 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 5577 | |
0114d602 DJ |
5578 | static struct type * |
5579 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 5580 | { |
e7c27a73 | 5581 | struct objfile *objfile = cu->objfile; |
0114d602 | 5582 | const char *previous_prefix, *name; |
9219021c | 5583 | int is_anonymous; |
0114d602 DJ |
5584 | struct type *type; |
5585 | ||
5586 | /* For extensions, reuse the type of the original namespace. */ | |
5587 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
5588 | { | |
5589 | struct die_info *ext_die; | |
5590 | struct dwarf2_cu *ext_cu = cu; | |
5591 | ext_die = dwarf2_extension (die, &ext_cu); | |
5592 | type = read_type_die (ext_die, ext_cu); | |
5593 | return set_die_type (die, type, cu); | |
5594 | } | |
9219021c | 5595 | |
e142c38c | 5596 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
5597 | |
5598 | /* Now build the name of the current namespace. */ | |
5599 | ||
0114d602 DJ |
5600 | previous_prefix = determine_prefix (die, cu); |
5601 | if (previous_prefix[0] != '\0') | |
5602 | name = typename_concat (&objfile->objfile_obstack, | |
5603 | previous_prefix, name, cu); | |
5604 | ||
5605 | /* Create the type. */ | |
5606 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
5607 | objfile); | |
5608 | TYPE_NAME (type) = (char *) name; | |
5609 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5610 | ||
5611 | set_die_type (die, type, cu); | |
5612 | ||
5613 | return type; | |
5614 | } | |
5615 | ||
5616 | /* Read a C++ namespace. */ | |
5617 | ||
5618 | static void | |
5619 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
5620 | { | |
5621 | struct objfile *objfile = cu->objfile; | |
5622 | const char *name; | |
5623 | int is_anonymous; | |
9219021c | 5624 | |
5c4e30ca DC |
5625 | /* Add a symbol associated to this if we haven't seen the namespace |
5626 | before. Also, add a using directive if it's an anonymous | |
5627 | namespace. */ | |
9219021c | 5628 | |
f2f0e013 | 5629 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
5630 | { |
5631 | struct type *type; | |
5632 | ||
0114d602 | 5633 | type = read_type_die (die, cu); |
e7c27a73 | 5634 | new_symbol (die, type, cu); |
5c4e30ca | 5635 | |
0114d602 | 5636 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 5637 | if (is_anonymous) |
0114d602 DJ |
5638 | { |
5639 | const char *previous_prefix = determine_prefix (die, cu); | |
794684b6 | 5640 | cp_add_using_directive (previous_prefix, TYPE_NAME (type)); |
0114d602 | 5641 | } |
5c4e30ca | 5642 | } |
9219021c | 5643 | |
639d11d3 | 5644 | if (die->child != NULL) |
d9fa45fe | 5645 | { |
639d11d3 | 5646 | struct die_info *child_die = die->child; |
d9fa45fe DC |
5647 | |
5648 | while (child_die && child_die->tag) | |
5649 | { | |
e7c27a73 | 5650 | process_die (child_die, cu); |
d9fa45fe DC |
5651 | child_die = sibling_die (child_die); |
5652 | } | |
5653 | } | |
38d518c9 EZ |
5654 | } |
5655 | ||
5d7cb8df JK |
5656 | /* Read a Fortran module. */ |
5657 | ||
5658 | static void | |
5659 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
5660 | { | |
5661 | struct die_info *child_die = die->child; | |
5662 | ||
5663 | /* FIXME: Support the separate Fortran module namespaces. */ | |
5664 | ||
5665 | while (child_die && child_die->tag) | |
5666 | { | |
5667 | process_die (child_die, cu); | |
5668 | child_die = sibling_die (child_die); | |
5669 | } | |
5670 | } | |
5671 | ||
38d518c9 EZ |
5672 | /* Return the name of the namespace represented by DIE. Set |
5673 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
5674 | namespace. */ | |
5675 | ||
5676 | static const char * | |
e142c38c | 5677 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
5678 | { |
5679 | struct die_info *current_die; | |
5680 | const char *name = NULL; | |
5681 | ||
5682 | /* Loop through the extensions until we find a name. */ | |
5683 | ||
5684 | for (current_die = die; | |
5685 | current_die != NULL; | |
f2f0e013 | 5686 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 5687 | { |
e142c38c | 5688 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
5689 | if (name != NULL) |
5690 | break; | |
5691 | } | |
5692 | ||
5693 | /* Is it an anonymous namespace? */ | |
5694 | ||
5695 | *is_anonymous = (name == NULL); | |
5696 | if (*is_anonymous) | |
5697 | name = "(anonymous namespace)"; | |
5698 | ||
5699 | return name; | |
d9fa45fe DC |
5700 | } |
5701 | ||
c906108c SS |
5702 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
5703 | the user defined type vector. */ | |
5704 | ||
f792889a | 5705 | static struct type * |
e7c27a73 | 5706 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5707 | { |
5e2b427d | 5708 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 5709 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 5710 | struct type *type; |
8b2dbe47 KB |
5711 | struct attribute *attr_byte_size; |
5712 | struct attribute *attr_address_class; | |
5713 | int byte_size, addr_class; | |
c906108c | 5714 | |
e7c27a73 | 5715 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 5716 | |
e142c38c | 5717 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
5718 | if (attr_byte_size) |
5719 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 5720 | else |
8b2dbe47 KB |
5721 | byte_size = cu_header->addr_size; |
5722 | ||
e142c38c | 5723 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
5724 | if (attr_address_class) |
5725 | addr_class = DW_UNSND (attr_address_class); | |
5726 | else | |
5727 | addr_class = DW_ADDR_none; | |
5728 | ||
5729 | /* If the pointer size or address class is different than the | |
5730 | default, create a type variant marked as such and set the | |
5731 | length accordingly. */ | |
5732 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 5733 | { |
5e2b427d | 5734 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
5735 | { |
5736 | int type_flags; | |
5737 | ||
849957d9 | 5738 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 5739 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
5740 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
5741 | == 0); | |
8b2dbe47 KB |
5742 | type = make_type_with_address_space (type, type_flags); |
5743 | } | |
5744 | else if (TYPE_LENGTH (type) != byte_size) | |
5745 | { | |
e2e0b3e5 | 5746 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
5747 | } |
5748 | else { | |
5749 | /* Should we also complain about unhandled address classes? */ | |
5750 | } | |
c906108c | 5751 | } |
8b2dbe47 KB |
5752 | |
5753 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 5754 | return set_die_type (die, type, cu); |
c906108c SS |
5755 | } |
5756 | ||
5757 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
5758 | the user defined type vector. */ | |
5759 | ||
f792889a | 5760 | static struct type * |
e7c27a73 | 5761 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5762 | { |
e7c27a73 | 5763 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5764 | struct type *type; |
5765 | struct type *to_type; | |
5766 | struct type *domain; | |
5767 | ||
e7c27a73 DJ |
5768 | to_type = die_type (die, cu); |
5769 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
5770 | |
5771 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
5772 | type = lookup_methodptr_type (to_type); | |
5773 | else | |
5774 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 5775 | |
f792889a | 5776 | return set_die_type (die, type, cu); |
c906108c SS |
5777 | } |
5778 | ||
5779 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
5780 | the user defined type vector. */ | |
5781 | ||
f792889a | 5782 | static struct type * |
e7c27a73 | 5783 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5784 | { |
e7c27a73 | 5785 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5786 | struct type *type; |
5787 | struct attribute *attr; | |
5788 | ||
e7c27a73 | 5789 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 5790 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5791 | if (attr) |
5792 | { | |
5793 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5794 | } | |
5795 | else | |
5796 | { | |
107d2387 | 5797 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 5798 | } |
f792889a | 5799 | return set_die_type (die, type, cu); |
c906108c SS |
5800 | } |
5801 | ||
f792889a | 5802 | static struct type * |
e7c27a73 | 5803 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5804 | { |
f792889a | 5805 | struct type *base_type, *cv_type; |
c906108c | 5806 | |
e7c27a73 | 5807 | base_type = die_type (die, cu); |
f792889a DJ |
5808 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
5809 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5810 | } |
5811 | ||
f792889a | 5812 | static struct type * |
e7c27a73 | 5813 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5814 | { |
f792889a | 5815 | struct type *base_type, *cv_type; |
c906108c | 5816 | |
e7c27a73 | 5817 | base_type = die_type (die, cu); |
f792889a DJ |
5818 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
5819 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5820 | } |
5821 | ||
5822 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
5823 | the user defined type vector. It isn't really a user defined type, | |
5824 | but it behaves like one, with other DIE's using an AT_user_def_type | |
5825 | attribute to reference it. */ | |
5826 | ||
f792889a | 5827 | static struct type * |
e7c27a73 | 5828 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5829 | { |
e7c27a73 | 5830 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 5831 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5832 | struct type *type, *range_type, *index_type, *char_type; |
5833 | struct attribute *attr; | |
5834 | unsigned int length; | |
5835 | ||
e142c38c | 5836 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
5837 | if (attr) |
5838 | { | |
5839 | length = DW_UNSND (attr); | |
5840 | } | |
5841 | else | |
5842 | { | |
b21b22e0 | 5843 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 5844 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
5845 | if (attr) |
5846 | { | |
5847 | length = DW_UNSND (attr); | |
5848 | } | |
5849 | else | |
5850 | { | |
5851 | length = 1; | |
5852 | } | |
c906108c | 5853 | } |
6ccb9162 | 5854 | |
46bf5051 | 5855 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5856 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
5857 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
5858 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 5859 | |
f792889a | 5860 | return set_die_type (die, type, cu); |
c906108c SS |
5861 | } |
5862 | ||
5863 | /* Handle DIES due to C code like: | |
5864 | ||
5865 | struct foo | |
c5aa993b JM |
5866 | { |
5867 | int (*funcp)(int a, long l); | |
5868 | int b; | |
5869 | }; | |
c906108c SS |
5870 | |
5871 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 5872 | */ |
c906108c | 5873 | |
f792889a | 5874 | static struct type * |
e7c27a73 | 5875 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5876 | { |
5877 | struct type *type; /* Type that this function returns */ | |
5878 | struct type *ftype; /* Function that returns above type */ | |
5879 | struct attribute *attr; | |
5880 | ||
e7c27a73 | 5881 | type = die_type (die, cu); |
0c8b41f1 | 5882 | ftype = lookup_function_type (type); |
c906108c | 5883 | |
5b8101ae | 5884 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 5885 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 5886 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 5887 | || cu->language == language_cplus |
5b8101ae PM |
5888 | || cu->language == language_java |
5889 | || cu->language == language_pascal) | |
876cecd0 | 5890 | TYPE_PROTOTYPED (ftype) = 1; |
c906108c | 5891 | |
c055b101 CV |
5892 | /* Store the calling convention in the type if it's available in |
5893 | the subroutine die. Otherwise set the calling convention to | |
5894 | the default value DW_CC_normal. */ | |
5895 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
5896 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
5897 | |
5898 | /* We need to add the subroutine type to the die immediately so | |
5899 | we don't infinitely recurse when dealing with parameters | |
5900 | declared as the same subroutine type. */ | |
5901 | set_die_type (die, ftype, cu); | |
c055b101 | 5902 | |
639d11d3 | 5903 | if (die->child != NULL) |
c906108c SS |
5904 | { |
5905 | struct die_info *child_die; | |
5906 | int nparams = 0; | |
5907 | int iparams = 0; | |
5908 | ||
5909 | /* Count the number of parameters. | |
5910 | FIXME: GDB currently ignores vararg functions, but knows about | |
5911 | vararg member functions. */ | |
639d11d3 | 5912 | child_die = die->child; |
c906108c SS |
5913 | while (child_die && child_die->tag) |
5914 | { | |
5915 | if (child_die->tag == DW_TAG_formal_parameter) | |
5916 | nparams++; | |
5917 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 5918 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
5919 | child_die = sibling_die (child_die); |
5920 | } | |
5921 | ||
5922 | /* Allocate storage for parameters and fill them in. */ | |
5923 | TYPE_NFIELDS (ftype) = nparams; | |
5924 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 5925 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 5926 | |
639d11d3 | 5927 | child_die = die->child; |
c906108c SS |
5928 | while (child_die && child_die->tag) |
5929 | { | |
5930 | if (child_die->tag == DW_TAG_formal_parameter) | |
5931 | { | |
5932 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
5933 | member functions. G++ helps GDB by marking the first |
5934 | parameter for non-static member functions (which is the | |
5935 | this pointer) as artificial. We pass this information | |
5936 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 5937 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
5938 | if (attr) |
5939 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
5940 | else | |
5941 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 5942 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
5943 | iparams++; |
5944 | } | |
5945 | child_die = sibling_die (child_die); | |
5946 | } | |
5947 | } | |
5948 | ||
76c10ea2 | 5949 | return ftype; |
c906108c SS |
5950 | } |
5951 | ||
f792889a | 5952 | static struct type * |
e7c27a73 | 5953 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5954 | { |
e7c27a73 | 5955 | struct objfile *objfile = cu->objfile; |
2f038fcb | 5956 | struct attribute *attr; |
0114d602 | 5957 | const char *name = NULL; |
f792889a | 5958 | struct type *this_type; |
c906108c | 5959 | |
0114d602 | 5960 | name = dwarf2_full_name (die, cu); |
f792889a | 5961 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
5962 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
5963 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
5964 | set_die_type (die, this_type, cu); |
5965 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
5966 | return this_type; | |
c906108c SS |
5967 | } |
5968 | ||
5969 | /* Find a representation of a given base type and install | |
5970 | it in the TYPE field of the die. */ | |
5971 | ||
f792889a | 5972 | static struct type * |
e7c27a73 | 5973 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5974 | { |
e7c27a73 | 5975 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5976 | struct type *type; |
5977 | struct attribute *attr; | |
5978 | int encoding = 0, size = 0; | |
39cbfefa | 5979 | char *name; |
6ccb9162 UW |
5980 | enum type_code code = TYPE_CODE_INT; |
5981 | int type_flags = 0; | |
5982 | struct type *target_type = NULL; | |
c906108c | 5983 | |
e142c38c | 5984 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
5985 | if (attr) |
5986 | { | |
5987 | encoding = DW_UNSND (attr); | |
5988 | } | |
e142c38c | 5989 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5990 | if (attr) |
5991 | { | |
5992 | size = DW_UNSND (attr); | |
5993 | } | |
39cbfefa | 5994 | name = dwarf2_name (die, cu); |
6ccb9162 | 5995 | if (!name) |
c906108c | 5996 | { |
6ccb9162 UW |
5997 | complaint (&symfile_complaints, |
5998 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 5999 | } |
6ccb9162 UW |
6000 | |
6001 | switch (encoding) | |
c906108c | 6002 | { |
6ccb9162 UW |
6003 | case DW_ATE_address: |
6004 | /* Turn DW_ATE_address into a void * pointer. */ | |
6005 | code = TYPE_CODE_PTR; | |
6006 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6007 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
6008 | break; | |
6009 | case DW_ATE_boolean: | |
6010 | code = TYPE_CODE_BOOL; | |
6011 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6012 | break; | |
6013 | case DW_ATE_complex_float: | |
6014 | code = TYPE_CODE_COMPLEX; | |
6015 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
6016 | break; | |
6017 | case DW_ATE_decimal_float: | |
6018 | code = TYPE_CODE_DECFLOAT; | |
6019 | break; | |
6020 | case DW_ATE_float: | |
6021 | code = TYPE_CODE_FLT; | |
6022 | break; | |
6023 | case DW_ATE_signed: | |
6024 | break; | |
6025 | case DW_ATE_unsigned: | |
6026 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6027 | break; | |
6028 | case DW_ATE_signed_char: | |
868a0084 PM |
6029 | if (cu->language == language_ada || cu->language == language_m2 |
6030 | || cu->language == language_pascal) | |
6ccb9162 UW |
6031 | code = TYPE_CODE_CHAR; |
6032 | break; | |
6033 | case DW_ATE_unsigned_char: | |
868a0084 PM |
6034 | if (cu->language == language_ada || cu->language == language_m2 |
6035 | || cu->language == language_pascal) | |
6ccb9162 UW |
6036 | code = TYPE_CODE_CHAR; |
6037 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6038 | break; | |
6039 | default: | |
6040 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
6041 | dwarf_type_encoding_name (encoding)); | |
6042 | break; | |
c906108c | 6043 | } |
6ccb9162 | 6044 | |
0114d602 DJ |
6045 | type = init_type (code, size, type_flags, NULL, objfile); |
6046 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
6047 | TYPE_TARGET_TYPE (type) = target_type; |
6048 | ||
0114d602 | 6049 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 6050 | TYPE_NOSIGN (type) = 1; |
0114d602 | 6051 | |
f792889a | 6052 | return set_die_type (die, type, cu); |
c906108c SS |
6053 | } |
6054 | ||
a02abb62 JB |
6055 | /* Read the given DW_AT_subrange DIE. */ |
6056 | ||
f792889a | 6057 | static struct type * |
a02abb62 JB |
6058 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
6059 | { | |
5e2b427d | 6060 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
6061 | struct type *base_type; |
6062 | struct type *range_type; | |
6063 | struct attribute *attr; | |
43bbcdc2 PH |
6064 | LONGEST low = 0; |
6065 | LONGEST high = -1; | |
39cbfefa | 6066 | char *name; |
43bbcdc2 | 6067 | LONGEST negative_mask; |
a02abb62 | 6068 | |
a02abb62 | 6069 | base_type = die_type (die, cu); |
3d1f72c2 | 6070 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
6071 | { |
6072 | complaint (&symfile_complaints, | |
e2e0b3e5 | 6073 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 6074 | base_type |
5e2b427d | 6075 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 6076 | 0, NULL, cu->objfile); |
a02abb62 JB |
6077 | } |
6078 | ||
e142c38c | 6079 | if (cu->language == language_fortran) |
a02abb62 JB |
6080 | { |
6081 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
6082 | low = 1; | |
6083 | } | |
6084 | ||
dd5e6932 DJ |
6085 | /* FIXME: For variable sized arrays either of these could be |
6086 | a variable rather than a constant value. We'll allow it, | |
6087 | but we don't know how to handle it. */ | |
e142c38c | 6088 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
6089 | if (attr) |
6090 | low = dwarf2_get_attr_constant_value (attr, 0); | |
6091 | ||
e142c38c | 6092 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
6093 | if (attr) |
6094 | { | |
6095 | if (attr->form == DW_FORM_block1) | |
6096 | { | |
6097 | /* GCC encodes arrays with unspecified or dynamic length | |
6098 | with a DW_FORM_block1 attribute. | |
6099 | FIXME: GDB does not yet know how to handle dynamic | |
6100 | arrays properly, treat them as arrays with unspecified | |
6101 | length for now. | |
6102 | ||
6103 | FIXME: jimb/2003-09-22: GDB does not really know | |
6104 | how to handle arrays of unspecified length | |
6105 | either; we just represent them as zero-length | |
6106 | arrays. Choose an appropriate upper bound given | |
6107 | the lower bound we've computed above. */ | |
6108 | high = low - 1; | |
6109 | } | |
6110 | else | |
6111 | high = dwarf2_get_attr_constant_value (attr, 1); | |
6112 | } | |
6113 | ||
43bbcdc2 PH |
6114 | negative_mask = |
6115 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); | |
6116 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
6117 | low |= negative_mask; | |
6118 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
6119 | high |= negative_mask; | |
6120 | ||
a02abb62 JB |
6121 | range_type = create_range_type (NULL, base_type, low, high); |
6122 | ||
39cbfefa DJ |
6123 | name = dwarf2_name (die, cu); |
6124 | if (name) | |
6125 | TYPE_NAME (range_type) = name; | |
a02abb62 | 6126 | |
e142c38c | 6127 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
6128 | if (attr) |
6129 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
6130 | ||
b4ba55a1 JB |
6131 | set_descriptive_type (range_type, die, cu); |
6132 | ||
f792889a | 6133 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
6134 | } |
6135 | ||
f792889a | 6136 | static struct type * |
81a17f79 JB |
6137 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
6138 | { | |
6139 | struct type *type; | |
81a17f79 | 6140 | |
81a17f79 JB |
6141 | /* For now, we only support the C meaning of an unspecified type: void. */ |
6142 | ||
0114d602 DJ |
6143 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
6144 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 6145 | |
f792889a | 6146 | return set_die_type (die, type, cu); |
81a17f79 | 6147 | } |
a02abb62 | 6148 | |
51545339 DJ |
6149 | /* Trivial hash function for die_info: the hash value of a DIE |
6150 | is its offset in .debug_info for this objfile. */ | |
6151 | ||
6152 | static hashval_t | |
6153 | die_hash (const void *item) | |
6154 | { | |
6155 | const struct die_info *die = item; | |
6156 | return die->offset; | |
6157 | } | |
6158 | ||
6159 | /* Trivial comparison function for die_info structures: two DIEs | |
6160 | are equal if they have the same offset. */ | |
6161 | ||
6162 | static int | |
6163 | die_eq (const void *item_lhs, const void *item_rhs) | |
6164 | { | |
6165 | const struct die_info *die_lhs = item_lhs; | |
6166 | const struct die_info *die_rhs = item_rhs; | |
6167 | return die_lhs->offset == die_rhs->offset; | |
6168 | } | |
6169 | ||
c906108c SS |
6170 | /* Read a whole compilation unit into a linked list of dies. */ |
6171 | ||
f9aca02d | 6172 | static struct die_info * |
93311388 | 6173 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 6174 | { |
93311388 DE |
6175 | struct die_reader_specs reader_specs; |
6176 | ||
348e048f | 6177 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
6178 | cu->die_hash |
6179 | = htab_create_alloc_ex (cu->header.length / 12, | |
6180 | die_hash, | |
6181 | die_eq, | |
6182 | NULL, | |
6183 | &cu->comp_unit_obstack, | |
6184 | hashtab_obstack_allocate, | |
6185 | dummy_obstack_deallocate); | |
6186 | ||
93311388 DE |
6187 | init_cu_die_reader (&reader_specs, cu); |
6188 | ||
6189 | return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); | |
639d11d3 DC |
6190 | } |
6191 | ||
d97bc12b DE |
6192 | /* Main entry point for reading a DIE and all children. |
6193 | Read the DIE and dump it if requested. */ | |
6194 | ||
6195 | static struct die_info * | |
93311388 DE |
6196 | read_die_and_children (const struct die_reader_specs *reader, |
6197 | gdb_byte *info_ptr, | |
d97bc12b DE |
6198 | gdb_byte **new_info_ptr, |
6199 | struct die_info *parent) | |
6200 | { | |
93311388 | 6201 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
6202 | new_info_ptr, parent); |
6203 | ||
6204 | if (dwarf2_die_debug) | |
6205 | { | |
348e048f DE |
6206 | fprintf_unfiltered (gdb_stdlog, |
6207 | "\nRead die from %s of %s:\n", | |
6208 | reader->buffer == dwarf2_per_objfile->info.buffer | |
6209 | ? ".debug_info" | |
6210 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
6211 | ? ".debug_types" | |
6212 | : "unknown section", | |
6213 | reader->abfd->filename); | |
d97bc12b DE |
6214 | dump_die (result, dwarf2_die_debug); |
6215 | } | |
6216 | ||
6217 | return result; | |
6218 | } | |
6219 | ||
639d11d3 DC |
6220 | /* Read a single die and all its descendents. Set the die's sibling |
6221 | field to NULL; set other fields in the die correctly, and set all | |
6222 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
6223 | location of the info_ptr after reading all of those dies. PARENT | |
6224 | is the parent of the die in question. */ | |
6225 | ||
6226 | static struct die_info * | |
93311388 DE |
6227 | read_die_and_children_1 (const struct die_reader_specs *reader, |
6228 | gdb_byte *info_ptr, | |
d97bc12b DE |
6229 | gdb_byte **new_info_ptr, |
6230 | struct die_info *parent) | |
639d11d3 DC |
6231 | { |
6232 | struct die_info *die; | |
fe1b8b76 | 6233 | gdb_byte *cur_ptr; |
639d11d3 DC |
6234 | int has_children; |
6235 | ||
93311388 | 6236 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
6237 | if (die == NULL) |
6238 | { | |
6239 | *new_info_ptr = cur_ptr; | |
6240 | return NULL; | |
6241 | } | |
93311388 | 6242 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
6243 | |
6244 | if (has_children) | |
348e048f | 6245 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
6246 | else |
6247 | { | |
6248 | die->child = NULL; | |
6249 | *new_info_ptr = cur_ptr; | |
6250 | } | |
6251 | ||
6252 | die->sibling = NULL; | |
6253 | die->parent = parent; | |
6254 | return die; | |
6255 | } | |
6256 | ||
6257 | /* Read a die, all of its descendents, and all of its siblings; set | |
6258 | all of the fields of all of the dies correctly. Arguments are as | |
6259 | in read_die_and_children. */ | |
6260 | ||
6261 | static struct die_info * | |
93311388 DE |
6262 | read_die_and_siblings (const struct die_reader_specs *reader, |
6263 | gdb_byte *info_ptr, | |
fe1b8b76 | 6264 | gdb_byte **new_info_ptr, |
639d11d3 DC |
6265 | struct die_info *parent) |
6266 | { | |
6267 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 6268 | gdb_byte *cur_ptr; |
639d11d3 | 6269 | |
c906108c | 6270 | cur_ptr = info_ptr; |
639d11d3 DC |
6271 | first_die = last_sibling = NULL; |
6272 | ||
6273 | while (1) | |
c906108c | 6274 | { |
639d11d3 | 6275 | struct die_info *die |
93311388 | 6276 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 6277 | |
1d325ec1 | 6278 | if (die == NULL) |
c906108c | 6279 | { |
639d11d3 DC |
6280 | *new_info_ptr = cur_ptr; |
6281 | return first_die; | |
c906108c | 6282 | } |
1d325ec1 DJ |
6283 | |
6284 | if (!first_die) | |
6285 | first_die = die; | |
c906108c | 6286 | else |
1d325ec1 DJ |
6287 | last_sibling->sibling = die; |
6288 | ||
6289 | last_sibling = die; | |
c906108c | 6290 | } |
c906108c SS |
6291 | } |
6292 | ||
93311388 DE |
6293 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6294 | point to a newly allocated die with its information, except for its | |
6295 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6296 | whether the die has children or not. */ | |
6297 | ||
6298 | static gdb_byte * | |
6299 | read_full_die (const struct die_reader_specs *reader, | |
6300 | struct die_info **diep, gdb_byte *info_ptr, | |
6301 | int *has_children) | |
6302 | { | |
6303 | unsigned int abbrev_number, bytes_read, i, offset; | |
6304 | struct abbrev_info *abbrev; | |
6305 | struct die_info *die; | |
6306 | struct dwarf2_cu *cu = reader->cu; | |
6307 | bfd *abfd = reader->abfd; | |
6308 | ||
6309 | offset = info_ptr - reader->buffer; | |
6310 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6311 | info_ptr += bytes_read; | |
6312 | if (!abbrev_number) | |
6313 | { | |
6314 | *diep = NULL; | |
6315 | *has_children = 0; | |
6316 | return info_ptr; | |
6317 | } | |
6318 | ||
6319 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
6320 | if (!abbrev) | |
348e048f DE |
6321 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
6322 | abbrev_number, | |
6323 | bfd_get_filename (abfd)); | |
6324 | ||
93311388 DE |
6325 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
6326 | die->offset = offset; | |
6327 | die->tag = abbrev->tag; | |
6328 | die->abbrev = abbrev_number; | |
6329 | ||
6330 | die->num_attrs = abbrev->num_attrs; | |
6331 | ||
6332 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6333 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
6334 | abfd, info_ptr, cu); | |
6335 | ||
6336 | *diep = die; | |
6337 | *has_children = abbrev->has_children; | |
6338 | return info_ptr; | |
6339 | } | |
6340 | ||
c906108c SS |
6341 | /* In DWARF version 2, the description of the debugging information is |
6342 | stored in a separate .debug_abbrev section. Before we read any | |
6343 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
6344 | in a hash table. This function also sets flags in CU describing |
6345 | the data found in the abbrev table. */ | |
c906108c SS |
6346 | |
6347 | static void | |
e7c27a73 | 6348 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 6349 | { |
e7c27a73 | 6350 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 6351 | gdb_byte *abbrev_ptr; |
c906108c SS |
6352 | struct abbrev_info *cur_abbrev; |
6353 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
6354 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
6355 | struct attr_abbrev *cur_attrs; |
6356 | unsigned int allocated_attrs; | |
c906108c | 6357 | |
57349743 | 6358 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
6359 | obstack_init (&cu->abbrev_obstack); |
6360 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
6361 | (ABBREV_HASH_SIZE | |
6362 | * sizeof (struct abbrev_info *))); | |
6363 | memset (cu->dwarf2_abbrevs, 0, | |
6364 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 6365 | |
dce234bc | 6366 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
6367 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6368 | abbrev_ptr += bytes_read; | |
6369 | ||
f3dd6933 DJ |
6370 | allocated_attrs = ATTR_ALLOC_CHUNK; |
6371 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6372 | ||
c906108c SS |
6373 | /* loop until we reach an abbrev number of 0 */ |
6374 | while (abbrev_number) | |
6375 | { | |
f3dd6933 | 6376 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
6377 | |
6378 | /* read in abbrev header */ | |
6379 | cur_abbrev->number = abbrev_number; | |
6380 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6381 | abbrev_ptr += bytes_read; | |
6382 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
6383 | abbrev_ptr += 1; | |
6384 | ||
72bf9492 DJ |
6385 | if (cur_abbrev->tag == DW_TAG_namespace) |
6386 | cu->has_namespace_info = 1; | |
6387 | ||
c906108c SS |
6388 | /* now read in declarations */ |
6389 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6390 | abbrev_ptr += bytes_read; | |
6391 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6392 | abbrev_ptr += bytes_read; | |
6393 | while (abbrev_name) | |
6394 | { | |
f3dd6933 | 6395 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 6396 | { |
f3dd6933 DJ |
6397 | allocated_attrs += ATTR_ALLOC_CHUNK; |
6398 | cur_attrs | |
6399 | = xrealloc (cur_attrs, (allocated_attrs | |
6400 | * sizeof (struct attr_abbrev))); | |
c906108c | 6401 | } |
ae038cb0 DJ |
6402 | |
6403 | /* Record whether this compilation unit might have | |
6404 | inter-compilation-unit references. If we don't know what form | |
6405 | this attribute will have, then it might potentially be a | |
6406 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
6407 | references. */ | |
6408 | ||
6409 | if (abbrev_form == DW_FORM_ref_addr | |
6410 | || abbrev_form == DW_FORM_indirect) | |
6411 | cu->has_form_ref_addr = 1; | |
6412 | ||
f3dd6933 DJ |
6413 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
6414 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
6415 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6416 | abbrev_ptr += bytes_read; | |
6417 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6418 | abbrev_ptr += bytes_read; | |
6419 | } | |
6420 | ||
f3dd6933 DJ |
6421 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
6422 | (cur_abbrev->num_attrs | |
6423 | * sizeof (struct attr_abbrev))); | |
6424 | memcpy (cur_abbrev->attrs, cur_attrs, | |
6425 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
6426 | ||
c906108c | 6427 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
6428 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
6429 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
6430 | |
6431 | /* Get next abbreviation. | |
6432 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
6433 | always properly terminated with an abbrev number of 0. |
6434 | Exit loop if we encounter an abbreviation which we have | |
6435 | already read (which means we are about to read the abbreviations | |
6436 | for the next compile unit) or if the end of the abbreviation | |
6437 | table is reached. */ | |
dce234bc PP |
6438 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
6439 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
6440 | break; |
6441 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6442 | abbrev_ptr += bytes_read; | |
e7c27a73 | 6443 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
6444 | break; |
6445 | } | |
f3dd6933 DJ |
6446 | |
6447 | xfree (cur_attrs); | |
c906108c SS |
6448 | } |
6449 | ||
f3dd6933 | 6450 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 6451 | |
c906108c | 6452 | static void |
f3dd6933 | 6453 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 6454 | { |
f3dd6933 | 6455 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 6456 | |
f3dd6933 DJ |
6457 | obstack_free (&cu->abbrev_obstack, NULL); |
6458 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
6459 | } |
6460 | ||
6461 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
6462 | ||
6463 | static struct abbrev_info * | |
e7c27a73 | 6464 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
6465 | { |
6466 | unsigned int hash_number; | |
6467 | struct abbrev_info *abbrev; | |
6468 | ||
6469 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 6470 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
6471 | |
6472 | while (abbrev) | |
6473 | { | |
6474 | if (abbrev->number == number) | |
6475 | return abbrev; | |
6476 | else | |
6477 | abbrev = abbrev->next; | |
6478 | } | |
6479 | return NULL; | |
6480 | } | |
6481 | ||
72bf9492 DJ |
6482 | /* Returns nonzero if TAG represents a type that we might generate a partial |
6483 | symbol for. */ | |
6484 | ||
6485 | static int | |
6486 | is_type_tag_for_partial (int tag) | |
6487 | { | |
6488 | switch (tag) | |
6489 | { | |
6490 | #if 0 | |
6491 | /* Some types that would be reasonable to generate partial symbols for, | |
6492 | that we don't at present. */ | |
6493 | case DW_TAG_array_type: | |
6494 | case DW_TAG_file_type: | |
6495 | case DW_TAG_ptr_to_member_type: | |
6496 | case DW_TAG_set_type: | |
6497 | case DW_TAG_string_type: | |
6498 | case DW_TAG_subroutine_type: | |
6499 | #endif | |
6500 | case DW_TAG_base_type: | |
6501 | case DW_TAG_class_type: | |
680b30c7 | 6502 | case DW_TAG_interface_type: |
72bf9492 DJ |
6503 | case DW_TAG_enumeration_type: |
6504 | case DW_TAG_structure_type: | |
6505 | case DW_TAG_subrange_type: | |
6506 | case DW_TAG_typedef: | |
6507 | case DW_TAG_union_type: | |
6508 | return 1; | |
6509 | default: | |
6510 | return 0; | |
6511 | } | |
6512 | } | |
6513 | ||
6514 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
6515 | ||
6516 | static struct partial_die_info * | |
93311388 DE |
6517 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
6518 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
6519 | { |
6520 | struct partial_die_info *part_die; | |
6521 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
6522 | struct abbrev_info *abbrev; | |
6523 | unsigned int bytes_read; | |
5afb4e99 | 6524 | unsigned int load_all = 0; |
72bf9492 DJ |
6525 | |
6526 | int nesting_level = 1; | |
6527 | ||
6528 | parent_die = NULL; | |
6529 | last_die = NULL; | |
6530 | ||
5afb4e99 DJ |
6531 | if (cu->per_cu && cu->per_cu->load_all_dies) |
6532 | load_all = 1; | |
6533 | ||
72bf9492 DJ |
6534 | cu->partial_dies |
6535 | = htab_create_alloc_ex (cu->header.length / 12, | |
6536 | partial_die_hash, | |
6537 | partial_die_eq, | |
6538 | NULL, | |
6539 | &cu->comp_unit_obstack, | |
6540 | hashtab_obstack_allocate, | |
6541 | dummy_obstack_deallocate); | |
6542 | ||
6543 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6544 | sizeof (struct partial_die_info)); | |
6545 | ||
6546 | while (1) | |
6547 | { | |
6548 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
6549 | ||
6550 | /* A NULL abbrev means the end of a series of children. */ | |
6551 | if (abbrev == NULL) | |
6552 | { | |
6553 | if (--nesting_level == 0) | |
6554 | { | |
6555 | /* PART_DIE was probably the last thing allocated on the | |
6556 | comp_unit_obstack, so we could call obstack_free | |
6557 | here. We don't do that because the waste is small, | |
6558 | and will be cleaned up when we're done with this | |
6559 | compilation unit. This way, we're also more robust | |
6560 | against other users of the comp_unit_obstack. */ | |
6561 | return first_die; | |
6562 | } | |
6563 | info_ptr += bytes_read; | |
6564 | last_die = parent_die; | |
6565 | parent_die = parent_die->die_parent; | |
6566 | continue; | |
6567 | } | |
6568 | ||
5afb4e99 DJ |
6569 | /* Check whether this DIE is interesting enough to save. Normally |
6570 | we would not be interested in members here, but there may be | |
6571 | later variables referencing them via DW_AT_specification (for | |
6572 | static members). */ | |
6573 | if (!load_all | |
6574 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
6575 | && abbrev->tag != DW_TAG_enumerator |
6576 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 6577 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 6578 | && abbrev->tag != DW_TAG_variable |
5afb4e99 DJ |
6579 | && abbrev->tag != DW_TAG_namespace |
6580 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
6581 | { |
6582 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6583 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
6584 | continue; |
6585 | } | |
6586 | ||
93311388 DE |
6587 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
6588 | buffer, info_ptr, cu); | |
72bf9492 DJ |
6589 | |
6590 | /* This two-pass algorithm for processing partial symbols has a | |
6591 | high cost in cache pressure. Thus, handle some simple cases | |
6592 | here which cover the majority of C partial symbols. DIEs | |
6593 | which neither have specification tags in them, nor could have | |
6594 | specification tags elsewhere pointing at them, can simply be | |
6595 | processed and discarded. | |
6596 | ||
6597 | This segment is also optional; scan_partial_symbols and | |
6598 | add_partial_symbol will handle these DIEs if we chain | |
6599 | them in normally. When compilers which do not emit large | |
6600 | quantities of duplicate debug information are more common, | |
6601 | this code can probably be removed. */ | |
6602 | ||
6603 | /* Any complete simple types at the top level (pretty much all | |
6604 | of them, for a language without namespaces), can be processed | |
6605 | directly. */ | |
6606 | if (parent_die == NULL | |
6607 | && part_die->has_specification == 0 | |
6608 | && part_die->is_declaration == 0 | |
6609 | && (part_die->tag == DW_TAG_typedef | |
6610 | || part_die->tag == DW_TAG_base_type | |
6611 | || part_die->tag == DW_TAG_subrange_type)) | |
6612 | { | |
6613 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 6614 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
6615 | VAR_DOMAIN, LOC_TYPEDEF, |
6616 | &cu->objfile->static_psymbols, | |
6617 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 6618 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6619 | continue; |
6620 | } | |
6621 | ||
6622 | /* If we're at the second level, and we're an enumerator, and | |
6623 | our parent has no specification (meaning possibly lives in a | |
6624 | namespace elsewhere), then we can add the partial symbol now | |
6625 | instead of queueing it. */ | |
6626 | if (part_die->tag == DW_TAG_enumerator | |
6627 | && parent_die != NULL | |
6628 | && parent_die->die_parent == NULL | |
6629 | && parent_die->tag == DW_TAG_enumeration_type | |
6630 | && parent_die->has_specification == 0) | |
6631 | { | |
6632 | if (part_die->name == NULL) | |
e2e0b3e5 | 6633 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 6634 | else if (building_psymtab) |
04a679b8 | 6635 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 6636 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
6637 | (cu->language == language_cplus |
6638 | || cu->language == language_java) | |
72bf9492 DJ |
6639 | ? &cu->objfile->global_psymbols |
6640 | : &cu->objfile->static_psymbols, | |
6641 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
6642 | ||
93311388 | 6643 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6644 | continue; |
6645 | } | |
6646 | ||
6647 | /* We'll save this DIE so link it in. */ | |
6648 | part_die->die_parent = parent_die; | |
6649 | part_die->die_sibling = NULL; | |
6650 | part_die->die_child = NULL; | |
6651 | ||
6652 | if (last_die && last_die == parent_die) | |
6653 | last_die->die_child = part_die; | |
6654 | else if (last_die) | |
6655 | last_die->die_sibling = part_die; | |
6656 | ||
6657 | last_die = part_die; | |
6658 | ||
6659 | if (first_die == NULL) | |
6660 | first_die = part_die; | |
6661 | ||
6662 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
6663 | find interesting need to be in the hash table, because we | |
6664 | also have the parent/sibling/child chains; only those that we | |
6665 | might refer to by offset later during partial symbol reading. | |
6666 | ||
6667 | For now this means things that might have be the target of a | |
6668 | DW_AT_specification, DW_AT_abstract_origin, or | |
6669 | DW_AT_extension. DW_AT_extension will refer only to | |
6670 | namespaces; DW_AT_abstract_origin refers to functions (and | |
6671 | many things under the function DIE, but we do not recurse | |
6672 | into function DIEs during partial symbol reading) and | |
6673 | possibly variables as well; DW_AT_specification refers to | |
6674 | declarations. Declarations ought to have the DW_AT_declaration | |
6675 | flag. It happens that GCC forgets to put it in sometimes, but | |
6676 | only for functions, not for types. | |
6677 | ||
6678 | Adding more things than necessary to the hash table is harmless | |
6679 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
6680 | wasted time in find_partial_die, when we reread the compilation |
6681 | unit with load_all_dies set. */ | |
72bf9492 | 6682 | |
5afb4e99 DJ |
6683 | if (load_all |
6684 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
6685 | || abbrev->tag == DW_TAG_variable |
6686 | || abbrev->tag == DW_TAG_namespace | |
6687 | || part_die->is_declaration) | |
6688 | { | |
6689 | void **slot; | |
6690 | ||
6691 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
6692 | part_die->offset, INSERT); | |
6693 | *slot = part_die; | |
6694 | } | |
6695 | ||
6696 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6697 | sizeof (struct partial_die_info)); | |
6698 | ||
6699 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 6700 | we have no reason to follow the children of structures; for other |
72bf9492 | 6701 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
6702 | to infer fully qualified class names, and for DW_AT_specification. |
6703 | ||
6704 | For Ada, we need to scan the children of subprograms and lexical | |
6705 | blocks as well because Ada allows the definition of nested | |
6706 | entities that could be interesting for the debugger, such as | |
6707 | nested subprograms for instance. */ | |
72bf9492 | 6708 | if (last_die->has_children |
5afb4e99 DJ |
6709 | && (load_all |
6710 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
6711 | || last_die->tag == DW_TAG_enumeration_type |
6712 | || (cu->language != language_c | |
6713 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 6714 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 6715 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
6716 | || last_die->tag == DW_TAG_union_type)) |
6717 | || (cu->language == language_ada | |
6718 | && (last_die->tag == DW_TAG_subprogram | |
6719 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
6720 | { |
6721 | nesting_level++; | |
6722 | parent_die = last_die; | |
6723 | continue; | |
6724 | } | |
6725 | ||
6726 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6727 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6728 | |
6729 | /* Back to the top, do it again. */ | |
6730 | } | |
6731 | } | |
6732 | ||
c906108c SS |
6733 | /* Read a minimal amount of information into the minimal die structure. */ |
6734 | ||
fe1b8b76 | 6735 | static gdb_byte * |
72bf9492 DJ |
6736 | read_partial_die (struct partial_die_info *part_die, |
6737 | struct abbrev_info *abbrev, | |
6738 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
6739 | gdb_byte *buffer, gdb_byte *info_ptr, |
6740 | struct dwarf2_cu *cu) | |
c906108c | 6741 | { |
72bf9492 | 6742 | unsigned int bytes_read, i; |
c906108c | 6743 | struct attribute attr; |
c5aa993b | 6744 | int has_low_pc_attr = 0; |
c906108c SS |
6745 | int has_high_pc_attr = 0; |
6746 | ||
72bf9492 | 6747 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 6748 | |
93311388 | 6749 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
6750 | |
6751 | info_ptr += abbrev_len; | |
6752 | ||
6753 | if (abbrev == NULL) | |
6754 | return info_ptr; | |
6755 | ||
c906108c SS |
6756 | part_die->tag = abbrev->tag; |
6757 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
6758 | |
6759 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6760 | { | |
e7c27a73 | 6761 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
6762 | |
6763 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 6764 | partial symbol table. */ |
c906108c SS |
6765 | switch (attr.name) |
6766 | { | |
6767 | case DW_AT_name: | |
71c25dea TT |
6768 | switch (part_die->tag) |
6769 | { | |
6770 | case DW_TAG_compile_unit: | |
348e048f | 6771 | case DW_TAG_type_unit: |
71c25dea TT |
6772 | /* Compilation units have a DW_AT_name that is a filename, not |
6773 | a source language identifier. */ | |
6774 | case DW_TAG_enumeration_type: | |
6775 | case DW_TAG_enumerator: | |
6776 | /* These tags always have simple identifiers already; no need | |
6777 | to canonicalize them. */ | |
6778 | part_die->name = DW_STRING (&attr); | |
6779 | break; | |
6780 | default: | |
6781 | part_die->name | |
6782 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
6783 | &cu->comp_unit_obstack); | |
6784 | break; | |
6785 | } | |
c906108c SS |
6786 | break; |
6787 | case DW_AT_MIPS_linkage_name: | |
6788 | part_die->name = DW_STRING (&attr); | |
6789 | break; | |
6790 | case DW_AT_low_pc: | |
6791 | has_low_pc_attr = 1; | |
6792 | part_die->lowpc = DW_ADDR (&attr); | |
6793 | break; | |
6794 | case DW_AT_high_pc: | |
6795 | has_high_pc_attr = 1; | |
6796 | part_die->highpc = DW_ADDR (&attr); | |
6797 | break; | |
6798 | case DW_AT_location: | |
8e19ed76 PS |
6799 | /* Support the .debug_loc offsets */ |
6800 | if (attr_form_is_block (&attr)) | |
6801 | { | |
6802 | part_die->locdesc = DW_BLOCK (&attr); | |
6803 | } | |
3690dd37 | 6804 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 6805 | { |
4d3c2250 | 6806 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6807 | } |
6808 | else | |
6809 | { | |
4d3c2250 KB |
6810 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6811 | "partial symbol information"); | |
8e19ed76 | 6812 | } |
c906108c | 6813 | break; |
c906108c SS |
6814 | case DW_AT_external: |
6815 | part_die->is_external = DW_UNSND (&attr); | |
6816 | break; | |
6817 | case DW_AT_declaration: | |
6818 | part_die->is_declaration = DW_UNSND (&attr); | |
6819 | break; | |
6820 | case DW_AT_type: | |
6821 | part_die->has_type = 1; | |
6822 | break; | |
6823 | case DW_AT_abstract_origin: | |
6824 | case DW_AT_specification: | |
72bf9492 DJ |
6825 | case DW_AT_extension: |
6826 | part_die->has_specification = 1; | |
c764a876 | 6827 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
6828 | break; |
6829 | case DW_AT_sibling: | |
6830 | /* Ignore absolute siblings, they might point outside of | |
6831 | the current compile unit. */ | |
6832 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 6833 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 6834 | else |
93311388 | 6835 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 6836 | break; |
fa4028e9 JB |
6837 | case DW_AT_byte_size: |
6838 | part_die->has_byte_size = 1; | |
6839 | break; | |
68511cec CES |
6840 | case DW_AT_calling_convention: |
6841 | /* DWARF doesn't provide a way to identify a program's source-level | |
6842 | entry point. DW_AT_calling_convention attributes are only meant | |
6843 | to describe functions' calling conventions. | |
6844 | ||
6845 | However, because it's a necessary piece of information in | |
6846 | Fortran, and because DW_CC_program is the only piece of debugging | |
6847 | information whose definition refers to a 'main program' at all, | |
6848 | several compilers have begun marking Fortran main programs with | |
6849 | DW_CC_program --- even when those functions use the standard | |
6850 | calling conventions. | |
6851 | ||
6852 | So until DWARF specifies a way to provide this information and | |
6853 | compilers pick up the new representation, we'll support this | |
6854 | practice. */ | |
6855 | if (DW_UNSND (&attr) == DW_CC_program | |
6856 | && cu->language == language_fortran) | |
6857 | set_main_name (part_die->name); | |
6858 | break; | |
c906108c SS |
6859 | default: |
6860 | break; | |
6861 | } | |
6862 | } | |
6863 | ||
c906108c SS |
6864 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
6865 | eliminate duplicate copies of functions and vtables and such. | |
6866 | The linker will arbitrarily choose one and discard the others. | |
6867 | The AT_*_pc values for such functions refer to local labels in | |
6868 | these sections. If the section from that file was discarded, the | |
6869 | labels are not in the output, so the relocs get a value of 0. | |
6870 | If this is a discarded function, mark the pc bounds as invalid, | |
6871 | so that GDB will ignore it. */ | |
6872 | if (has_low_pc_attr && has_high_pc_attr | |
6873 | && part_die->lowpc < part_die->highpc | |
6874 | && (part_die->lowpc != 0 | |
72dca2f5 | 6875 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 6876 | part_die->has_pc_info = 1; |
85cbf3d3 | 6877 | |
c906108c SS |
6878 | return info_ptr; |
6879 | } | |
6880 | ||
72bf9492 DJ |
6881 | /* Find a cached partial DIE at OFFSET in CU. */ |
6882 | ||
6883 | static struct partial_die_info * | |
c764a876 | 6884 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
6885 | { |
6886 | struct partial_die_info *lookup_die = NULL; | |
6887 | struct partial_die_info part_die; | |
6888 | ||
6889 | part_die.offset = offset; | |
6890 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
6891 | ||
72bf9492 DJ |
6892 | return lookup_die; |
6893 | } | |
6894 | ||
348e048f DE |
6895 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
6896 | except in the case of .debug_types DIEs which do not reference | |
6897 | outside their CU (they do however referencing other types via | |
6898 | DW_FORM_sig8). */ | |
72bf9492 DJ |
6899 | |
6900 | static struct partial_die_info * | |
c764a876 | 6901 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 6902 | { |
5afb4e99 DJ |
6903 | struct dwarf2_per_cu_data *per_cu = NULL; |
6904 | struct partial_die_info *pd = NULL; | |
72bf9492 | 6905 | |
348e048f DE |
6906 | if (cu->per_cu->from_debug_types) |
6907 | { | |
6908 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6909 | if (pd != NULL) | |
6910 | return pd; | |
6911 | goto not_found; | |
6912 | } | |
6913 | ||
45452591 | 6914 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
6915 | { |
6916 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6917 | if (pd != NULL) | |
6918 | return pd; | |
6919 | } | |
72bf9492 | 6920 | |
ae038cb0 DJ |
6921 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
6922 | ||
ae038cb0 DJ |
6923 | if (per_cu->cu == NULL) |
6924 | { | |
93311388 | 6925 | load_partial_comp_unit (per_cu, cu->objfile); |
ae038cb0 DJ |
6926 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
6927 | dwarf2_per_objfile->read_in_chain = per_cu; | |
6928 | } | |
6929 | ||
6930 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
6931 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
6932 | ||
6933 | if (pd == NULL && per_cu->load_all_dies == 0) | |
6934 | { | |
6935 | struct cleanup *back_to; | |
6936 | struct partial_die_info comp_unit_die; | |
6937 | struct abbrev_info *abbrev; | |
6938 | unsigned int bytes_read; | |
6939 | char *info_ptr; | |
6940 | ||
6941 | per_cu->load_all_dies = 1; | |
6942 | ||
6943 | /* Re-read the DIEs. */ | |
6944 | back_to = make_cleanup (null_cleanup, 0); | |
6945 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
6946 | { | |
6947 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 6948 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 6949 | } |
dce234bc | 6950 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
6951 | + per_cu->cu->header.offset |
6952 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
6953 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
6954 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
6955 | per_cu->cu->objfile->obfd, |
6956 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
6957 | per_cu->cu); |
6958 | if (comp_unit_die.has_children) | |
93311388 DE |
6959 | load_partial_dies (per_cu->cu->objfile->obfd, |
6960 | dwarf2_per_objfile->info.buffer, info_ptr, | |
6961 | 0, per_cu->cu); | |
5afb4e99 DJ |
6962 | do_cleanups (back_to); |
6963 | ||
6964 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
6965 | } | |
6966 | ||
348e048f DE |
6967 | not_found: |
6968 | ||
5afb4e99 DJ |
6969 | if (pd == NULL) |
6970 | internal_error (__FILE__, __LINE__, | |
c764a876 | 6971 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
6972 | offset, bfd_get_filename (cu->objfile->obfd)); |
6973 | return pd; | |
72bf9492 DJ |
6974 | } |
6975 | ||
6976 | /* Adjust PART_DIE before generating a symbol for it. This function | |
6977 | may set the is_external flag or change the DIE's name. */ | |
6978 | ||
6979 | static void | |
6980 | fixup_partial_die (struct partial_die_info *part_die, | |
6981 | struct dwarf2_cu *cu) | |
6982 | { | |
6983 | /* If we found a reference attribute and the DIE has no name, try | |
6984 | to find a name in the referred to DIE. */ | |
6985 | ||
6986 | if (part_die->name == NULL && part_die->has_specification) | |
6987 | { | |
6988 | struct partial_die_info *spec_die; | |
72bf9492 | 6989 | |
10b3939b | 6990 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6991 | |
10b3939b | 6992 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6993 | |
6994 | if (spec_die->name) | |
6995 | { | |
6996 | part_die->name = spec_die->name; | |
6997 | ||
6998 | /* Copy DW_AT_external attribute if it is set. */ | |
6999 | if (spec_die->is_external) | |
7000 | part_die->is_external = spec_die->is_external; | |
7001 | } | |
7002 | } | |
7003 | ||
7004 | /* Set default names for some unnamed DIEs. */ | |
7005 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
7006 | || part_die->tag == DW_TAG_class_type)) | |
7007 | part_die->name = "(anonymous class)"; | |
7008 | ||
7009 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
7010 | part_die->name = "(anonymous namespace)"; | |
7011 | ||
7012 | if (part_die->tag == DW_TAG_structure_type | |
7013 | || part_die->tag == DW_TAG_class_type | |
7014 | || part_die->tag == DW_TAG_union_type) | |
7015 | guess_structure_name (part_die, cu); | |
7016 | } | |
7017 | ||
a8329558 | 7018 | /* Read an attribute value described by an attribute form. */ |
c906108c | 7019 | |
fe1b8b76 | 7020 | static gdb_byte * |
a8329558 | 7021 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 7022 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 7023 | struct dwarf2_cu *cu) |
c906108c | 7024 | { |
e7c27a73 | 7025 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7026 | unsigned int bytes_read; |
7027 | struct dwarf_block *blk; | |
7028 | ||
a8329558 KW |
7029 | attr->form = form; |
7030 | switch (form) | |
c906108c SS |
7031 | { |
7032 | case DW_FORM_addr: | |
7033 | case DW_FORM_ref_addr: | |
e7c27a73 | 7034 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 7035 | info_ptr += bytes_read; |
c906108c SS |
7036 | break; |
7037 | case DW_FORM_block2: | |
7b5a2f43 | 7038 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7039 | blk->size = read_2_bytes (abfd, info_ptr); |
7040 | info_ptr += 2; | |
7041 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7042 | info_ptr += blk->size; | |
7043 | DW_BLOCK (attr) = blk; | |
7044 | break; | |
7045 | case DW_FORM_block4: | |
7b5a2f43 | 7046 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7047 | blk->size = read_4_bytes (abfd, info_ptr); |
7048 | info_ptr += 4; | |
7049 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7050 | info_ptr += blk->size; | |
7051 | DW_BLOCK (attr) = blk; | |
7052 | break; | |
7053 | case DW_FORM_data2: | |
7054 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
7055 | info_ptr += 2; | |
7056 | break; | |
7057 | case DW_FORM_data4: | |
7058 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
7059 | info_ptr += 4; | |
7060 | break; | |
7061 | case DW_FORM_data8: | |
7062 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
7063 | info_ptr += 8; | |
7064 | break; | |
7065 | case DW_FORM_string: | |
7066 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
8285870a | 7067 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
7068 | info_ptr += bytes_read; |
7069 | break; | |
4bdf3d34 JJ |
7070 | case DW_FORM_strp: |
7071 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
7072 | &bytes_read); | |
8285870a | 7073 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
7074 | info_ptr += bytes_read; |
7075 | break; | |
c906108c | 7076 | case DW_FORM_block: |
7b5a2f43 | 7077 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7078 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7079 | info_ptr += bytes_read; | |
7080 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7081 | info_ptr += blk->size; | |
7082 | DW_BLOCK (attr) = blk; | |
7083 | break; | |
7084 | case DW_FORM_block1: | |
7b5a2f43 | 7085 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7086 | blk->size = read_1_byte (abfd, info_ptr); |
7087 | info_ptr += 1; | |
7088 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7089 | info_ptr += blk->size; | |
7090 | DW_BLOCK (attr) = blk; | |
7091 | break; | |
7092 | case DW_FORM_data1: | |
7093 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7094 | info_ptr += 1; | |
7095 | break; | |
7096 | case DW_FORM_flag: | |
7097 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7098 | info_ptr += 1; | |
7099 | break; | |
7100 | case DW_FORM_sdata: | |
7101 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
7102 | info_ptr += bytes_read; | |
7103 | break; | |
7104 | case DW_FORM_udata: | |
7105 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7106 | info_ptr += bytes_read; | |
7107 | break; | |
7108 | case DW_FORM_ref1: | |
10b3939b | 7109 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
7110 | info_ptr += 1; |
7111 | break; | |
7112 | case DW_FORM_ref2: | |
10b3939b | 7113 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
7114 | info_ptr += 2; |
7115 | break; | |
7116 | case DW_FORM_ref4: | |
10b3939b | 7117 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
7118 | info_ptr += 4; |
7119 | break; | |
613e1657 | 7120 | case DW_FORM_ref8: |
10b3939b | 7121 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
7122 | info_ptr += 8; |
7123 | break; | |
348e048f DE |
7124 | case DW_FORM_sig8: |
7125 | /* Convert the signature to something we can record in DW_UNSND | |
7126 | for later lookup. | |
7127 | NOTE: This is NULL if the type wasn't found. */ | |
7128 | DW_SIGNATURED_TYPE (attr) = | |
7129 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
7130 | info_ptr += 8; | |
7131 | break; | |
c906108c | 7132 | case DW_FORM_ref_udata: |
10b3939b DJ |
7133 | DW_ADDR (attr) = (cu->header.offset |
7134 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
7135 | info_ptr += bytes_read; |
7136 | break; | |
c906108c | 7137 | case DW_FORM_indirect: |
a8329558 KW |
7138 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7139 | info_ptr += bytes_read; | |
e7c27a73 | 7140 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 7141 | break; |
c906108c | 7142 | default: |
8a3fe4f8 | 7143 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
7144 | dwarf_form_name (form), |
7145 | bfd_get_filename (abfd)); | |
c906108c | 7146 | } |
28e94949 JB |
7147 | |
7148 | /* We have seen instances where the compiler tried to emit a byte | |
7149 | size attribute of -1 which ended up being encoded as an unsigned | |
7150 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
7151 | an object of this size seems pretty unlikely so we can relatively | |
7152 | safely treat these cases as if the size attribute was invalid and | |
7153 | treat them as zero by default. */ | |
7154 | if (attr->name == DW_AT_byte_size | |
7155 | && form == DW_FORM_data4 | |
7156 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
7157 | { |
7158 | complaint | |
7159 | (&symfile_complaints, | |
43bbcdc2 PH |
7160 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
7161 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
7162 | DW_UNSND (attr) = 0; |
7163 | } | |
28e94949 | 7164 | |
c906108c SS |
7165 | return info_ptr; |
7166 | } | |
7167 | ||
a8329558 KW |
7168 | /* Read an attribute described by an abbreviated attribute. */ |
7169 | ||
fe1b8b76 | 7170 | static gdb_byte * |
a8329558 | 7171 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 7172 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
7173 | { |
7174 | attr->name = abbrev->name; | |
e7c27a73 | 7175 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
7176 | } |
7177 | ||
c906108c SS |
7178 | /* read dwarf information from a buffer */ |
7179 | ||
7180 | static unsigned int | |
fe1b8b76 | 7181 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7182 | { |
fe1b8b76 | 7183 | return bfd_get_8 (abfd, buf); |
c906108c SS |
7184 | } |
7185 | ||
7186 | static int | |
fe1b8b76 | 7187 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7188 | { |
fe1b8b76 | 7189 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
7190 | } |
7191 | ||
7192 | static unsigned int | |
fe1b8b76 | 7193 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7194 | { |
fe1b8b76 | 7195 | return bfd_get_16 (abfd, buf); |
c906108c SS |
7196 | } |
7197 | ||
7198 | static int | |
fe1b8b76 | 7199 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7200 | { |
fe1b8b76 | 7201 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
7202 | } |
7203 | ||
7204 | static unsigned int | |
fe1b8b76 | 7205 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7206 | { |
fe1b8b76 | 7207 | return bfd_get_32 (abfd, buf); |
c906108c SS |
7208 | } |
7209 | ||
7210 | static int | |
fe1b8b76 | 7211 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7212 | { |
fe1b8b76 | 7213 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
7214 | } |
7215 | ||
93311388 | 7216 | static ULONGEST |
fe1b8b76 | 7217 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7218 | { |
fe1b8b76 | 7219 | return bfd_get_64 (abfd, buf); |
c906108c SS |
7220 | } |
7221 | ||
7222 | static CORE_ADDR | |
fe1b8b76 | 7223 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 7224 | unsigned int *bytes_read) |
c906108c | 7225 | { |
e7c27a73 | 7226 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7227 | CORE_ADDR retval = 0; |
7228 | ||
107d2387 | 7229 | if (cu_header->signed_addr_p) |
c906108c | 7230 | { |
107d2387 AC |
7231 | switch (cu_header->addr_size) |
7232 | { | |
7233 | case 2: | |
fe1b8b76 | 7234 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
7235 | break; |
7236 | case 4: | |
fe1b8b76 | 7237 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
7238 | break; |
7239 | case 8: | |
fe1b8b76 | 7240 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
7241 | break; |
7242 | default: | |
8e65ff28 | 7243 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7244 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 7245 | bfd_get_filename (abfd)); |
107d2387 AC |
7246 | } |
7247 | } | |
7248 | else | |
7249 | { | |
7250 | switch (cu_header->addr_size) | |
7251 | { | |
7252 | case 2: | |
fe1b8b76 | 7253 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
7254 | break; |
7255 | case 4: | |
fe1b8b76 | 7256 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
7257 | break; |
7258 | case 8: | |
fe1b8b76 | 7259 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
7260 | break; |
7261 | default: | |
8e65ff28 | 7262 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7263 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 7264 | bfd_get_filename (abfd)); |
107d2387 | 7265 | } |
c906108c | 7266 | } |
64367e0a | 7267 | |
107d2387 AC |
7268 | *bytes_read = cu_header->addr_size; |
7269 | return retval; | |
c906108c SS |
7270 | } |
7271 | ||
f7ef9339 | 7272 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
7273 | specification allows the initial length to take up either 4 bytes |
7274 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
7275 | bytes describe the length and all offsets will be 8 bytes in length | |
7276 | instead of 4. | |
7277 | ||
f7ef9339 KB |
7278 | An older, non-standard 64-bit format is also handled by this |
7279 | function. The older format in question stores the initial length | |
7280 | as an 8-byte quantity without an escape value. Lengths greater | |
7281 | than 2^32 aren't very common which means that the initial 4 bytes | |
7282 | is almost always zero. Since a length value of zero doesn't make | |
7283 | sense for the 32-bit format, this initial zero can be considered to | |
7284 | be an escape value which indicates the presence of the older 64-bit | |
7285 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
7286 | greater than 4GB. If it becomes necessary to handle lengths |
7287 | somewhat larger than 4GB, we could allow other small values (such | |
7288 | as the non-sensical values of 1, 2, and 3) to also be used as | |
7289 | escape values indicating the presence of the old format. | |
f7ef9339 | 7290 | |
917c78fc MK |
7291 | The value returned via bytes_read should be used to increment the |
7292 | relevant pointer after calling read_initial_length(). | |
c764a876 | 7293 | |
613e1657 KB |
7294 | [ Note: read_initial_length() and read_offset() are based on the |
7295 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 7296 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
7297 | from: |
7298 | ||
f7ef9339 | 7299 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
7300 | |
7301 | This document is only a draft and is subject to change. (So beware.) | |
7302 | ||
f7ef9339 | 7303 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
7304 | determined empirically by examining 64-bit ELF files produced by |
7305 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
7306 | |
7307 | - Kevin, July 16, 2002 | |
613e1657 KB |
7308 | ] */ |
7309 | ||
7310 | static LONGEST | |
c764a876 | 7311 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 7312 | { |
fe1b8b76 | 7313 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 7314 | |
dd373385 | 7315 | if (length == 0xffffffff) |
613e1657 | 7316 | { |
fe1b8b76 | 7317 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 7318 | *bytes_read = 12; |
613e1657 | 7319 | } |
dd373385 | 7320 | else if (length == 0) |
f7ef9339 | 7321 | { |
dd373385 | 7322 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 7323 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 7324 | *bytes_read = 8; |
f7ef9339 | 7325 | } |
613e1657 KB |
7326 | else |
7327 | { | |
7328 | *bytes_read = 4; | |
613e1657 KB |
7329 | } |
7330 | ||
c764a876 DE |
7331 | return length; |
7332 | } | |
dd373385 | 7333 | |
c764a876 DE |
7334 | /* Cover function for read_initial_length. |
7335 | Returns the length of the object at BUF, and stores the size of the | |
7336 | initial length in *BYTES_READ and stores the size that offsets will be in | |
7337 | *OFFSET_SIZE. | |
7338 | If the initial length size is not equivalent to that specified in | |
7339 | CU_HEADER then issue a complaint. | |
7340 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 7341 | |
c764a876 DE |
7342 | static LONGEST |
7343 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
7344 | const struct comp_unit_head *cu_header, | |
7345 | unsigned int *bytes_read, | |
7346 | unsigned int *offset_size) | |
7347 | { | |
7348 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
7349 | ||
7350 | gdb_assert (cu_header->initial_length_size == 4 | |
7351 | || cu_header->initial_length_size == 8 | |
7352 | || cu_header->initial_length_size == 12); | |
7353 | ||
7354 | if (cu_header->initial_length_size != *bytes_read) | |
7355 | complaint (&symfile_complaints, | |
7356 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 7357 | |
c764a876 | 7358 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 7359 | return length; |
613e1657 KB |
7360 | } |
7361 | ||
7362 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 7363 | given by cu_header->offset_size. */ |
613e1657 KB |
7364 | |
7365 | static LONGEST | |
fe1b8b76 | 7366 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 7367 | unsigned int *bytes_read) |
c764a876 DE |
7368 | { |
7369 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
7370 | *bytes_read = cu_header->offset_size; | |
7371 | return offset; | |
7372 | } | |
7373 | ||
7374 | /* Read an offset from the data stream. */ | |
7375 | ||
7376 | static LONGEST | |
7377 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
7378 | { |
7379 | LONGEST retval = 0; | |
7380 | ||
c764a876 | 7381 | switch (offset_size) |
613e1657 KB |
7382 | { |
7383 | case 4: | |
fe1b8b76 | 7384 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
7385 | break; |
7386 | case 8: | |
fe1b8b76 | 7387 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
7388 | break; |
7389 | default: | |
8e65ff28 | 7390 | internal_error (__FILE__, __LINE__, |
c764a876 | 7391 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 7392 | bfd_get_filename (abfd)); |
613e1657 KB |
7393 | } |
7394 | ||
917c78fc | 7395 | return retval; |
613e1657 KB |
7396 | } |
7397 | ||
fe1b8b76 JB |
7398 | static gdb_byte * |
7399 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
7400 | { |
7401 | /* If the size of a host char is 8 bits, we can return a pointer | |
7402 | to the buffer, otherwise we have to copy the data to a buffer | |
7403 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7404 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 7405 | return buf; |
c906108c SS |
7406 | } |
7407 | ||
7408 | static char * | |
fe1b8b76 | 7409 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
7410 | { |
7411 | /* If the size of a host char is 8 bits, we can return a pointer | |
7412 | to the string, otherwise we have to copy the string to a buffer | |
7413 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7414 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
7415 | if (*buf == '\0') |
7416 | { | |
7417 | *bytes_read_ptr = 1; | |
7418 | return NULL; | |
7419 | } | |
fe1b8b76 JB |
7420 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
7421 | return (char *) buf; | |
4bdf3d34 JJ |
7422 | } |
7423 | ||
7424 | static char * | |
fe1b8b76 | 7425 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
7426 | const struct comp_unit_head *cu_header, |
7427 | unsigned int *bytes_read_ptr) | |
7428 | { | |
c764a876 | 7429 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 7430 | |
dce234bc | 7431 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 7432 | { |
8a3fe4f8 | 7433 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 7434 | bfd_get_filename (abfd)); |
4bdf3d34 | 7435 | return NULL; |
c906108c | 7436 | } |
dce234bc | 7437 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 7438 | { |
8a3fe4f8 | 7439 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 7440 | bfd_get_filename (abfd)); |
c906108c SS |
7441 | return NULL; |
7442 | } | |
4bdf3d34 | 7443 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 7444 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 7445 | return NULL; |
dce234bc | 7446 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
7447 | } |
7448 | ||
ce5d95e1 | 7449 | static unsigned long |
fe1b8b76 | 7450 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7451 | { |
ce5d95e1 JB |
7452 | unsigned long result; |
7453 | unsigned int num_read; | |
c906108c SS |
7454 | int i, shift; |
7455 | unsigned char byte; | |
7456 | ||
7457 | result = 0; | |
7458 | shift = 0; | |
7459 | num_read = 0; | |
7460 | i = 0; | |
7461 | while (1) | |
7462 | { | |
fe1b8b76 | 7463 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7464 | buf++; |
7465 | num_read++; | |
ce5d95e1 | 7466 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
7467 | if ((byte & 128) == 0) |
7468 | { | |
7469 | break; | |
7470 | } | |
7471 | shift += 7; | |
7472 | } | |
7473 | *bytes_read_ptr = num_read; | |
7474 | return result; | |
7475 | } | |
7476 | ||
ce5d95e1 | 7477 | static long |
fe1b8b76 | 7478 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7479 | { |
ce5d95e1 | 7480 | long result; |
77e0b926 | 7481 | int i, shift, num_read; |
c906108c SS |
7482 | unsigned char byte; |
7483 | ||
7484 | result = 0; | |
7485 | shift = 0; | |
c906108c SS |
7486 | num_read = 0; |
7487 | i = 0; | |
7488 | while (1) | |
7489 | { | |
fe1b8b76 | 7490 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7491 | buf++; |
7492 | num_read++; | |
ce5d95e1 | 7493 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
7494 | shift += 7; |
7495 | if ((byte & 128) == 0) | |
7496 | { | |
7497 | break; | |
7498 | } | |
7499 | } | |
77e0b926 DJ |
7500 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
7501 | result |= -(((long)1) << shift); | |
c906108c SS |
7502 | *bytes_read_ptr = num_read; |
7503 | return result; | |
7504 | } | |
7505 | ||
4bb7a0a7 DJ |
7506 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
7507 | ||
fe1b8b76 JB |
7508 | static gdb_byte * |
7509 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
7510 | { |
7511 | int byte; | |
7512 | ||
7513 | while (1) | |
7514 | { | |
fe1b8b76 | 7515 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
7516 | buf++; |
7517 | if ((byte & 128) == 0) | |
7518 | return buf; | |
7519 | } | |
7520 | } | |
7521 | ||
c906108c | 7522 | static void |
e142c38c | 7523 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
7524 | { |
7525 | switch (lang) | |
7526 | { | |
7527 | case DW_LANG_C89: | |
76bee0cc | 7528 | case DW_LANG_C99: |
c906108c | 7529 | case DW_LANG_C: |
e142c38c | 7530 | cu->language = language_c; |
c906108c SS |
7531 | break; |
7532 | case DW_LANG_C_plus_plus: | |
e142c38c | 7533 | cu->language = language_cplus; |
c906108c SS |
7534 | break; |
7535 | case DW_LANG_Fortran77: | |
7536 | case DW_LANG_Fortran90: | |
b21b22e0 | 7537 | case DW_LANG_Fortran95: |
e142c38c | 7538 | cu->language = language_fortran; |
c906108c SS |
7539 | break; |
7540 | case DW_LANG_Mips_Assembler: | |
e142c38c | 7541 | cu->language = language_asm; |
c906108c | 7542 | break; |
bebd888e | 7543 | case DW_LANG_Java: |
e142c38c | 7544 | cu->language = language_java; |
bebd888e | 7545 | break; |
c906108c | 7546 | case DW_LANG_Ada83: |
8aaf0b47 | 7547 | case DW_LANG_Ada95: |
bc5f45f8 JB |
7548 | cu->language = language_ada; |
7549 | break; | |
72019c9c GM |
7550 | case DW_LANG_Modula2: |
7551 | cu->language = language_m2; | |
7552 | break; | |
fe8e67fd PM |
7553 | case DW_LANG_Pascal83: |
7554 | cu->language = language_pascal; | |
7555 | break; | |
22566fbd DJ |
7556 | case DW_LANG_ObjC: |
7557 | cu->language = language_objc; | |
7558 | break; | |
c906108c SS |
7559 | case DW_LANG_Cobol74: |
7560 | case DW_LANG_Cobol85: | |
c906108c | 7561 | default: |
e142c38c | 7562 | cu->language = language_minimal; |
c906108c SS |
7563 | break; |
7564 | } | |
e142c38c | 7565 | cu->language_defn = language_def (cu->language); |
c906108c SS |
7566 | } |
7567 | ||
7568 | /* Return the named attribute or NULL if not there. */ | |
7569 | ||
7570 | static struct attribute * | |
e142c38c | 7571 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
7572 | { |
7573 | unsigned int i; | |
7574 | struct attribute *spec = NULL; | |
7575 | ||
7576 | for (i = 0; i < die->num_attrs; ++i) | |
7577 | { | |
7578 | if (die->attrs[i].name == name) | |
10b3939b | 7579 | return &die->attrs[i]; |
c906108c SS |
7580 | if (die->attrs[i].name == DW_AT_specification |
7581 | || die->attrs[i].name == DW_AT_abstract_origin) | |
7582 | spec = &die->attrs[i]; | |
7583 | } | |
c906108c | 7584 | |
10b3939b | 7585 | if (spec) |
f2f0e013 DJ |
7586 | { |
7587 | die = follow_die_ref (die, spec, &cu); | |
7588 | return dwarf2_attr (die, name, cu); | |
7589 | } | |
c5aa993b | 7590 | |
c906108c SS |
7591 | return NULL; |
7592 | } | |
7593 | ||
348e048f DE |
7594 | /* Return the named attribute or NULL if not there, |
7595 | but do not follow DW_AT_specification, etc. | |
7596 | This is for use in contexts where we're reading .debug_types dies. | |
7597 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
7598 | back up the chain, and we want to go down. */ | |
7599 | ||
7600 | static struct attribute * | |
7601 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
7602 | struct dwarf2_cu *cu) | |
7603 | { | |
7604 | unsigned int i; | |
7605 | ||
7606 | for (i = 0; i < die->num_attrs; ++i) | |
7607 | if (die->attrs[i].name == name) | |
7608 | return &die->attrs[i]; | |
7609 | ||
7610 | return NULL; | |
7611 | } | |
7612 | ||
05cf31d1 JB |
7613 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
7614 | and holds a non-zero value. This function should only be used for | |
7615 | DW_FORM_flag attributes. */ | |
7616 | ||
7617 | static int | |
7618 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
7619 | { | |
7620 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
7621 | ||
7622 | return (attr && DW_UNSND (attr)); | |
7623 | } | |
7624 | ||
3ca72b44 | 7625 | static int |
e142c38c | 7626 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 7627 | { |
05cf31d1 JB |
7628 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
7629 | which value is non-zero. However, we have to be careful with | |
7630 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
7631 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
7632 | end up accidently finding a declaration attribute that belongs | |
7633 | to a different DIE referenced by the specification attribute, | |
7634 | even though the given DIE does not have a declaration attribute. */ | |
7635 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
7636 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
7637 | } |
7638 | ||
63d06c5c | 7639 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 7640 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
7641 | containing the return value on output. If there is no |
7642 | specification, but there is an abstract origin, that is | |
7643 | returned. */ | |
63d06c5c DC |
7644 | |
7645 | static struct die_info * | |
f2f0e013 | 7646 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 7647 | { |
f2f0e013 DJ |
7648 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
7649 | *spec_cu); | |
63d06c5c | 7650 | |
edb3359d DJ |
7651 | if (spec_attr == NULL) |
7652 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
7653 | ||
63d06c5c DC |
7654 | if (spec_attr == NULL) |
7655 | return NULL; | |
7656 | else | |
f2f0e013 | 7657 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 7658 | } |
c906108c | 7659 | |
debd256d JB |
7660 | /* Free the line_header structure *LH, and any arrays and strings it |
7661 | refers to. */ | |
7662 | static void | |
7663 | free_line_header (struct line_header *lh) | |
7664 | { | |
7665 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 7666 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
7667 | |
7668 | /* Remember that all the lh->file_names[i].name pointers are | |
7669 | pointers into debug_line_buffer, and don't need to be freed. */ | |
7670 | if (lh->file_names) | |
a8bc7b56 | 7671 | xfree (lh->file_names); |
debd256d JB |
7672 | |
7673 | /* Similarly for the include directory names. */ | |
7674 | if (lh->include_dirs) | |
a8bc7b56 | 7675 | xfree (lh->include_dirs); |
debd256d | 7676 | |
a8bc7b56 | 7677 | xfree (lh); |
debd256d JB |
7678 | } |
7679 | ||
7680 | ||
7681 | /* Add an entry to LH's include directory table. */ | |
7682 | static void | |
7683 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 7684 | { |
debd256d JB |
7685 | /* Grow the array if necessary. */ |
7686 | if (lh->include_dirs_size == 0) | |
c5aa993b | 7687 | { |
debd256d JB |
7688 | lh->include_dirs_size = 1; /* for testing */ |
7689 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
7690 | * sizeof (*lh->include_dirs)); | |
7691 | } | |
7692 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
7693 | { | |
7694 | lh->include_dirs_size *= 2; | |
7695 | lh->include_dirs = xrealloc (lh->include_dirs, | |
7696 | (lh->include_dirs_size | |
7697 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 7698 | } |
c906108c | 7699 | |
debd256d JB |
7700 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
7701 | } | |
7702 | ||
7703 | ||
7704 | /* Add an entry to LH's file name table. */ | |
7705 | static void | |
7706 | add_file_name (struct line_header *lh, | |
7707 | char *name, | |
7708 | unsigned int dir_index, | |
7709 | unsigned int mod_time, | |
7710 | unsigned int length) | |
7711 | { | |
7712 | struct file_entry *fe; | |
7713 | ||
7714 | /* Grow the array if necessary. */ | |
7715 | if (lh->file_names_size == 0) | |
7716 | { | |
7717 | lh->file_names_size = 1; /* for testing */ | |
7718 | lh->file_names = xmalloc (lh->file_names_size | |
7719 | * sizeof (*lh->file_names)); | |
7720 | } | |
7721 | else if (lh->num_file_names >= lh->file_names_size) | |
7722 | { | |
7723 | lh->file_names_size *= 2; | |
7724 | lh->file_names = xrealloc (lh->file_names, | |
7725 | (lh->file_names_size | |
7726 | * sizeof (*lh->file_names))); | |
7727 | } | |
7728 | ||
7729 | fe = &lh->file_names[lh->num_file_names++]; | |
7730 | fe->name = name; | |
7731 | fe->dir_index = dir_index; | |
7732 | fe->mod_time = mod_time; | |
7733 | fe->length = length; | |
aaa75496 | 7734 | fe->included_p = 0; |
cb1df416 | 7735 | fe->symtab = NULL; |
debd256d JB |
7736 | } |
7737 | ||
7738 | ||
7739 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
7740 | .debug_line, according to the endianness of ABFD. Return a pointer |
7741 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
7742 | |
7743 | NOTE: the strings in the include directory and file name tables of | |
7744 | the returned object point into debug_line_buffer, and must not be | |
7745 | freed. */ | |
7746 | static struct line_header * | |
7747 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 7748 | struct dwarf2_cu *cu) |
debd256d JB |
7749 | { |
7750 | struct cleanup *back_to; | |
7751 | struct line_header *lh; | |
fe1b8b76 | 7752 | gdb_byte *line_ptr; |
c764a876 | 7753 | unsigned int bytes_read, offset_size; |
debd256d JB |
7754 | int i; |
7755 | char *cur_dir, *cur_file; | |
7756 | ||
dce234bc | 7757 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 7758 | { |
e2e0b3e5 | 7759 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
7760 | return 0; |
7761 | } | |
7762 | ||
a738430d MK |
7763 | /* Make sure that at least there's room for the total_length field. |
7764 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 7765 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 7766 | { |
4d3c2250 | 7767 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7768 | return 0; |
7769 | } | |
7770 | ||
7771 | lh = xmalloc (sizeof (*lh)); | |
7772 | memset (lh, 0, sizeof (*lh)); | |
7773 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
7774 | (void *) lh); | |
7775 | ||
dce234bc | 7776 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 7777 | |
a738430d | 7778 | /* Read in the header. */ |
dd373385 | 7779 | lh->total_length = |
c764a876 DE |
7780 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
7781 | &bytes_read, &offset_size); | |
debd256d | 7782 | line_ptr += bytes_read; |
dce234bc PP |
7783 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
7784 | + dwarf2_per_objfile->line.size)) | |
debd256d | 7785 | { |
4d3c2250 | 7786 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7787 | return 0; |
7788 | } | |
7789 | lh->statement_program_end = line_ptr + lh->total_length; | |
7790 | lh->version = read_2_bytes (abfd, line_ptr); | |
7791 | line_ptr += 2; | |
c764a876 DE |
7792 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
7793 | line_ptr += offset_size; | |
debd256d JB |
7794 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
7795 | line_ptr += 1; | |
7796 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
7797 | line_ptr += 1; | |
7798 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
7799 | line_ptr += 1; | |
7800 | lh->line_range = read_1_byte (abfd, line_ptr); | |
7801 | line_ptr += 1; | |
7802 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
7803 | line_ptr += 1; | |
7804 | lh->standard_opcode_lengths | |
fe1b8b76 | 7805 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
7806 | |
7807 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
7808 | for (i = 1; i < lh->opcode_base; ++i) | |
7809 | { | |
7810 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
7811 | line_ptr += 1; | |
7812 | } | |
7813 | ||
a738430d | 7814 | /* Read directory table. */ |
debd256d JB |
7815 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7816 | { | |
7817 | line_ptr += bytes_read; | |
7818 | add_include_dir (lh, cur_dir); | |
7819 | } | |
7820 | line_ptr += bytes_read; | |
7821 | ||
a738430d | 7822 | /* Read file name table. */ |
debd256d JB |
7823 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7824 | { | |
7825 | unsigned int dir_index, mod_time, length; | |
7826 | ||
7827 | line_ptr += bytes_read; | |
7828 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7829 | line_ptr += bytes_read; | |
7830 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7831 | line_ptr += bytes_read; | |
7832 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7833 | line_ptr += bytes_read; | |
7834 | ||
7835 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7836 | } | |
7837 | line_ptr += bytes_read; | |
7838 | lh->statement_program_start = line_ptr; | |
7839 | ||
dce234bc PP |
7840 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
7841 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 7842 | complaint (&symfile_complaints, |
e2e0b3e5 | 7843 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
7844 | |
7845 | discard_cleanups (back_to); | |
7846 | return lh; | |
7847 | } | |
c906108c | 7848 | |
5fb290d7 DJ |
7849 | /* This function exists to work around a bug in certain compilers |
7850 | (particularly GCC 2.95), in which the first line number marker of a | |
7851 | function does not show up until after the prologue, right before | |
7852 | the second line number marker. This function shifts ADDRESS down | |
7853 | to the beginning of the function if necessary, and is called on | |
7854 | addresses passed to record_line. */ | |
7855 | ||
7856 | static CORE_ADDR | |
e142c38c | 7857 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
7858 | { |
7859 | struct function_range *fn; | |
7860 | ||
7861 | /* Find the function_range containing address. */ | |
e142c38c | 7862 | if (!cu->first_fn) |
5fb290d7 DJ |
7863 | return address; |
7864 | ||
e142c38c DJ |
7865 | if (!cu->cached_fn) |
7866 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 7867 | |
e142c38c | 7868 | fn = cu->cached_fn; |
5fb290d7 DJ |
7869 | while (fn) |
7870 | if (fn->lowpc <= address && fn->highpc > address) | |
7871 | goto found; | |
7872 | else | |
7873 | fn = fn->next; | |
7874 | ||
e142c38c DJ |
7875 | fn = cu->first_fn; |
7876 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
7877 | if (fn->lowpc <= address && fn->highpc > address) |
7878 | goto found; | |
7879 | else | |
7880 | fn = fn->next; | |
7881 | ||
7882 | return address; | |
7883 | ||
7884 | found: | |
7885 | if (fn->seen_line) | |
7886 | return address; | |
7887 | if (address != fn->lowpc) | |
4d3c2250 | 7888 | complaint (&symfile_complaints, |
e2e0b3e5 | 7889 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 7890 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
7891 | fn->seen_line = 1; |
7892 | return fn->lowpc; | |
7893 | } | |
7894 | ||
aaa75496 JB |
7895 | /* Decode the Line Number Program (LNP) for the given line_header |
7896 | structure and CU. The actual information extracted and the type | |
7897 | of structures created from the LNP depends on the value of PST. | |
7898 | ||
7899 | 1. If PST is NULL, then this procedure uses the data from the program | |
7900 | to create all necessary symbol tables, and their linetables. | |
7901 | The compilation directory of the file is passed in COMP_DIR, | |
7902 | and must not be NULL. | |
7903 | ||
7904 | 2. If PST is not NULL, this procedure reads the program to determine | |
7905 | the list of files included by the unit represented by PST, and | |
7906 | builds all the associated partial symbol tables. In this case, | |
7907 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
7908 | is not used to compute the full name of the symtab, and therefore | |
7909 | omitting it when building the partial symtab does not introduce | |
7910 | the potential for inconsistency - a partial symtab and its associated | |
7911 | symbtab having a different fullname -). */ | |
debd256d | 7912 | |
c906108c | 7913 | static void |
debd256d | 7914 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 7915 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 7916 | { |
a8c50c1f | 7917 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 7918 | gdb_byte *line_end; |
a8c50c1f | 7919 | unsigned int bytes_read, extended_len; |
c906108c | 7920 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
7921 | CORE_ADDR baseaddr; |
7922 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 7923 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 7924 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 7925 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
7926 | |
7927 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7928 | |
debd256d JB |
7929 | line_ptr = lh->statement_program_start; |
7930 | line_end = lh->statement_program_end; | |
c906108c SS |
7931 | |
7932 | /* Read the statement sequences until there's nothing left. */ | |
7933 | while (line_ptr < line_end) | |
7934 | { | |
7935 | /* state machine registers */ | |
7936 | CORE_ADDR address = 0; | |
7937 | unsigned int file = 1; | |
7938 | unsigned int line = 1; | |
7939 | unsigned int column = 0; | |
debd256d | 7940 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
7941 | int basic_block = 0; |
7942 | int end_sequence = 0; | |
fbf65064 | 7943 | CORE_ADDR addr; |
c906108c | 7944 | |
aaa75496 | 7945 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 7946 | { |
aaa75496 | 7947 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
7948 | /* lh->include_dirs and lh->file_names are 0-based, but the |
7949 | directory and file name numbers in the statement program | |
7950 | are 1-based. */ | |
7951 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 7952 | char *dir = NULL; |
a738430d | 7953 | |
debd256d JB |
7954 | if (fe->dir_index) |
7955 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
7956 | |
7957 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
7958 | } |
7959 | ||
a738430d | 7960 | /* Decode the table. */ |
c5aa993b | 7961 | while (!end_sequence) |
c906108c SS |
7962 | { |
7963 | op_code = read_1_byte (abfd, line_ptr); | |
7964 | line_ptr += 1; | |
59205f5a JB |
7965 | if (line_ptr > line_end) |
7966 | { | |
7967 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
7968 | break; | |
7969 | } | |
9aa1fe7e | 7970 | |
debd256d | 7971 | if (op_code >= lh->opcode_base) |
a738430d MK |
7972 | { |
7973 | /* Special operand. */ | |
debd256d JB |
7974 | adj_opcode = op_code - lh->opcode_base; |
7975 | address += (adj_opcode / lh->line_range) | |
7976 | * lh->minimum_instruction_length; | |
7977 | line += lh->line_base + (adj_opcode % lh->line_range); | |
59205f5a | 7978 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
7979 | dwarf2_debug_line_missing_file_complaint (); |
7980 | else | |
7981 | { | |
7982 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 7983 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
7984 | { |
7985 | if (last_subfile != current_subfile) | |
7986 | { | |
7987 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
7988 | if (last_subfile) | |
7989 | record_line (last_subfile, 0, addr); | |
7990 | last_subfile = current_subfile; | |
7991 | } | |
25e43795 | 7992 | /* Append row to matrix using current values. */ |
fbf65064 UW |
7993 | addr = check_cu_functions (address, cu); |
7994 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
7995 | record_line (current_subfile, line, addr); | |
366da635 | 7996 | } |
25e43795 | 7997 | } |
ca5f395d | 7998 | basic_block = 0; |
9aa1fe7e GK |
7999 | } |
8000 | else switch (op_code) | |
c906108c SS |
8001 | { |
8002 | case DW_LNS_extended_op: | |
a8c50c1f | 8003 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 8004 | line_ptr += bytes_read; |
a8c50c1f | 8005 | extended_end = line_ptr + extended_len; |
c906108c SS |
8006 | extended_op = read_1_byte (abfd, line_ptr); |
8007 | line_ptr += 1; | |
8008 | switch (extended_op) | |
8009 | { | |
8010 | case DW_LNE_end_sequence: | |
8011 | end_sequence = 1; | |
c906108c SS |
8012 | break; |
8013 | case DW_LNE_set_address: | |
e7c27a73 | 8014 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
8015 | line_ptr += bytes_read; |
8016 | address += baseaddr; | |
c906108c SS |
8017 | break; |
8018 | case DW_LNE_define_file: | |
debd256d JB |
8019 | { |
8020 | char *cur_file; | |
8021 | unsigned int dir_index, mod_time, length; | |
8022 | ||
8023 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
8024 | line_ptr += bytes_read; | |
8025 | dir_index = | |
8026 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8027 | line_ptr += bytes_read; | |
8028 | mod_time = | |
8029 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8030 | line_ptr += bytes_read; | |
8031 | length = | |
8032 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8033 | line_ptr += bytes_read; | |
8034 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
8035 | } | |
c906108c | 8036 | break; |
d0c6ba3d CC |
8037 | case DW_LNE_set_discriminator: |
8038 | /* The discriminator is not interesting to the debugger; | |
8039 | just ignore it. */ | |
8040 | line_ptr = extended_end; | |
8041 | break; | |
c906108c | 8042 | default: |
4d3c2250 | 8043 | complaint (&symfile_complaints, |
e2e0b3e5 | 8044 | _("mangled .debug_line section")); |
debd256d | 8045 | return; |
c906108c | 8046 | } |
a8c50c1f DJ |
8047 | /* Make sure that we parsed the extended op correctly. If e.g. |
8048 | we expected a different address size than the producer used, | |
8049 | we may have read the wrong number of bytes. */ | |
8050 | if (line_ptr != extended_end) | |
8051 | { | |
8052 | complaint (&symfile_complaints, | |
8053 | _("mangled .debug_line section")); | |
8054 | return; | |
8055 | } | |
c906108c SS |
8056 | break; |
8057 | case DW_LNS_copy: | |
59205f5a | 8058 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8059 | dwarf2_debug_line_missing_file_complaint (); |
8060 | else | |
366da635 | 8061 | { |
25e43795 | 8062 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 8063 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
8064 | { |
8065 | if (last_subfile != current_subfile) | |
8066 | { | |
8067 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8068 | if (last_subfile) | |
8069 | record_line (last_subfile, 0, addr); | |
8070 | last_subfile = current_subfile; | |
8071 | } | |
8072 | addr = check_cu_functions (address, cu); | |
8073 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
8074 | record_line (current_subfile, line, addr); | |
8075 | } | |
366da635 | 8076 | } |
c906108c SS |
8077 | basic_block = 0; |
8078 | break; | |
8079 | case DW_LNS_advance_pc: | |
debd256d | 8080 | address += lh->minimum_instruction_length |
c906108c SS |
8081 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8082 | line_ptr += bytes_read; | |
8083 | break; | |
8084 | case DW_LNS_advance_line: | |
8085 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
8086 | line_ptr += bytes_read; | |
8087 | break; | |
8088 | case DW_LNS_set_file: | |
debd256d | 8089 | { |
a738430d MK |
8090 | /* The arrays lh->include_dirs and lh->file_names are |
8091 | 0-based, but the directory and file name numbers in | |
8092 | the statement program are 1-based. */ | |
debd256d | 8093 | struct file_entry *fe; |
4f1520fb | 8094 | char *dir = NULL; |
a738430d | 8095 | |
debd256d JB |
8096 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8097 | line_ptr += bytes_read; | |
59205f5a | 8098 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8099 | dwarf2_debug_line_missing_file_complaint (); |
8100 | else | |
8101 | { | |
8102 | fe = &lh->file_names[file - 1]; | |
8103 | if (fe->dir_index) | |
8104 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8105 | if (!decode_for_pst_p) | |
8106 | { | |
8107 | last_subfile = current_subfile; | |
8108 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8109 | } | |
8110 | } | |
debd256d | 8111 | } |
c906108c SS |
8112 | break; |
8113 | case DW_LNS_set_column: | |
8114 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8115 | line_ptr += bytes_read; | |
8116 | break; | |
8117 | case DW_LNS_negate_stmt: | |
8118 | is_stmt = (!is_stmt); | |
8119 | break; | |
8120 | case DW_LNS_set_basic_block: | |
8121 | basic_block = 1; | |
8122 | break; | |
c2c6d25f JM |
8123 | /* Add to the address register of the state machine the |
8124 | address increment value corresponding to special opcode | |
a738430d MK |
8125 | 255. I.e., this value is scaled by the minimum |
8126 | instruction length since special opcode 255 would have | |
8127 | scaled the the increment. */ | |
c906108c | 8128 | case DW_LNS_const_add_pc: |
debd256d JB |
8129 | address += (lh->minimum_instruction_length |
8130 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
8131 | break; |
8132 | case DW_LNS_fixed_advance_pc: | |
8133 | address += read_2_bytes (abfd, line_ptr); | |
8134 | line_ptr += 2; | |
8135 | break; | |
9aa1fe7e | 8136 | default: |
a738430d MK |
8137 | { |
8138 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 8139 | int i; |
a738430d | 8140 | |
debd256d | 8141 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
8142 | { |
8143 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8144 | line_ptr += bytes_read; | |
8145 | } | |
8146 | } | |
c906108c SS |
8147 | } |
8148 | } | |
59205f5a JB |
8149 | if (lh->num_file_names < file || file == 0) |
8150 | dwarf2_debug_line_missing_file_complaint (); | |
8151 | else | |
8152 | { | |
8153 | lh->file_names[file - 1].included_p = 1; | |
8154 | if (!decode_for_pst_p) | |
fbf65064 UW |
8155 | { |
8156 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8157 | record_line (current_subfile, 0, addr); | |
8158 | } | |
59205f5a | 8159 | } |
c906108c | 8160 | } |
aaa75496 JB |
8161 | |
8162 | if (decode_for_pst_p) | |
8163 | { | |
8164 | int file_index; | |
8165 | ||
8166 | /* Now that we're done scanning the Line Header Program, we can | |
8167 | create the psymtab of each included file. */ | |
8168 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
8169 | if (lh->file_names[file_index].included_p == 1) | |
8170 | { | |
5b5464ad JB |
8171 | const struct file_entry fe = lh->file_names [file_index]; |
8172 | char *include_name = fe.name; | |
8173 | char *dir_name = NULL; | |
8174 | char *pst_filename = pst->filename; | |
8175 | ||
8176 | if (fe.dir_index) | |
8177 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
8178 | ||
8179 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
8180 | { | |
1754f103 MK |
8181 | include_name = concat (dir_name, SLASH_STRING, |
8182 | include_name, (char *)NULL); | |
5b5464ad JB |
8183 | make_cleanup (xfree, include_name); |
8184 | } | |
8185 | ||
8186 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
8187 | { | |
1754f103 MK |
8188 | pst_filename = concat (pst->dirname, SLASH_STRING, |
8189 | pst_filename, (char *)NULL); | |
5b5464ad JB |
8190 | make_cleanup (xfree, pst_filename); |
8191 | } | |
8192 | ||
8193 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
8194 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
8195 | } | |
8196 | } | |
cb1df416 DJ |
8197 | else |
8198 | { | |
8199 | /* Make sure a symtab is created for every file, even files | |
8200 | which contain only variables (i.e. no code with associated | |
8201 | line numbers). */ | |
8202 | ||
8203 | int i; | |
8204 | struct file_entry *fe; | |
8205 | ||
8206 | for (i = 0; i < lh->num_file_names; i++) | |
8207 | { | |
8208 | char *dir = NULL; | |
8209 | fe = &lh->file_names[i]; | |
8210 | if (fe->dir_index) | |
8211 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8212 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8213 | ||
8214 | /* Skip the main file; we don't need it, and it must be | |
8215 | allocated last, so that it will show up before the | |
8216 | non-primary symtabs in the objfile's symtab list. */ | |
8217 | if (current_subfile == first_subfile) | |
8218 | continue; | |
8219 | ||
8220 | if (current_subfile->symtab == NULL) | |
8221 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
8222 | cu->objfile); | |
8223 | fe->symtab = current_subfile->symtab; | |
8224 | } | |
8225 | } | |
c906108c SS |
8226 | } |
8227 | ||
8228 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
8229 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
8230 | or NULL if not known. COMP_DIR is the compilation directory for the |
8231 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
8232 | This routine tries to keep line numbers from identical absolute and |
8233 | relative file names in a common subfile. | |
8234 | ||
8235 | Using the `list' example from the GDB testsuite, which resides in | |
8236 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
8237 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
8238 | ||
c5aa993b JM |
8239 | DW_AT_name: /srcdir/list0.c |
8240 | DW_AT_comp_dir: /compdir | |
357e46e7 | 8241 | files.files[0].name: list0.h |
c5aa993b | 8242 | files.files[0].dir: /srcdir |
357e46e7 | 8243 | files.files[1].name: list0.c |
c5aa993b | 8244 | files.files[1].dir: /srcdir |
c906108c SS |
8245 | |
8246 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
8247 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
8248 | start_subfile will ensure that this happens provided that we pass the | |
8249 | concatenation of files.files[1].dir and files.files[1].name as the | |
8250 | subfile's name. */ | |
c906108c SS |
8251 | |
8252 | static void | |
4f1520fb | 8253 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 8254 | { |
4f1520fb FR |
8255 | char *fullname; |
8256 | ||
8257 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
8258 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
8259 | second argument to start_subfile. To be consistent, we do the | |
8260 | same here. In order not to lose the line information directory, | |
8261 | we concatenate it to the filename when it makes sense. | |
8262 | Note that the Dwarf3 standard says (speaking of filenames in line | |
8263 | information): ``The directory index is ignored for file names | |
8264 | that represent full path names''. Thus ignoring dirname in the | |
8265 | `else' branch below isn't an issue. */ | |
c906108c | 8266 | |
d5166ae1 | 8267 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
8268 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
8269 | else | |
8270 | fullname = filename; | |
c906108c | 8271 | |
4f1520fb FR |
8272 | start_subfile (fullname, comp_dir); |
8273 | ||
8274 | if (fullname != filename) | |
8275 | xfree (fullname); | |
c906108c SS |
8276 | } |
8277 | ||
4c2df51b DJ |
8278 | static void |
8279 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8280 | struct dwarf2_cu *cu) |
4c2df51b | 8281 | { |
e7c27a73 DJ |
8282 | struct objfile *objfile = cu->objfile; |
8283 | struct comp_unit_head *cu_header = &cu->header; | |
8284 | ||
4c2df51b DJ |
8285 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
8286 | code here to turn a symbol with DW_AT_external and a | |
8287 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
8288 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
8289 | with some versions of binutils) where shared libraries could have | |
8290 | relocations against symbols in their debug information - the | |
8291 | minimal symbol would have the right address, but the debug info | |
8292 | would not. It's no longer necessary, because we will explicitly | |
8293 | apply relocations when we read in the debug information now. */ | |
8294 | ||
8295 | /* A DW_AT_location attribute with no contents indicates that a | |
8296 | variable has been optimized away. */ | |
8297 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
8298 | { | |
8299 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
8300 | return; | |
8301 | } | |
8302 | ||
8303 | /* Handle one degenerate form of location expression specially, to | |
8304 | preserve GDB's previous behavior when section offsets are | |
8305 | specified. If this is just a DW_OP_addr then mark this symbol | |
8306 | as LOC_STATIC. */ | |
8307 | ||
8308 | if (attr_form_is_block (attr) | |
8309 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
8310 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
8311 | { | |
891d2f0b | 8312 | unsigned int dummy; |
4c2df51b DJ |
8313 | |
8314 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 8315 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 8316 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
8317 | fixup_symbol_section (sym, objfile); |
8318 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
8319 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
8320 | return; |
8321 | } | |
8322 | ||
8323 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
8324 | expression evaluator, and use LOC_COMPUTED only when necessary | |
8325 | (i.e. when the value of a register or memory location is | |
8326 | referenced, or a thread-local block, etc.). Then again, it might | |
8327 | not be worthwhile. I'm assuming that it isn't unless performance | |
8328 | or memory numbers show me otherwise. */ | |
8329 | ||
e7c27a73 | 8330 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
8331 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8332 | } | |
8333 | ||
c906108c SS |
8334 | /* Given a pointer to a DWARF information entry, figure out if we need |
8335 | to make a symbol table entry for it, and if so, create a new entry | |
8336 | and return a pointer to it. | |
8337 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 8338 | used the passed type. */ |
c906108c SS |
8339 | |
8340 | static struct symbol * | |
e7c27a73 | 8341 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 8342 | { |
e7c27a73 | 8343 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8344 | struct symbol *sym = NULL; |
8345 | char *name; | |
8346 | struct attribute *attr = NULL; | |
8347 | struct attribute *attr2 = NULL; | |
e142c38c | 8348 | CORE_ADDR baseaddr; |
edb3359d | 8349 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
8350 | |
8351 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 8352 | |
5c4e30ca | 8353 | if (die->tag != DW_TAG_namespace) |
e142c38c | 8354 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
8355 | else |
8356 | name = TYPE_NAME (type); | |
8357 | ||
c906108c SS |
8358 | if (name) |
8359 | { | |
4a146b47 | 8360 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
8361 | sizeof (struct symbol)); |
8362 | OBJSTAT (objfile, n_syms++); | |
8363 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
8364 | |
8365 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 8366 | SYMBOL_LANGUAGE (sym) = cu->language; |
04a679b8 | 8367 | SYMBOL_SET_NAMES (sym, name, strlen (name), 0, objfile); |
c906108c SS |
8368 | |
8369 | /* Default assumptions. | |
c5aa993b | 8370 | Use the passed type or decode it from the die. */ |
176620f1 | 8371 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 8372 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
8373 | if (type != NULL) |
8374 | SYMBOL_TYPE (sym) = type; | |
8375 | else | |
e7c27a73 | 8376 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
8377 | attr = dwarf2_attr (die, |
8378 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
8379 | cu); | |
c906108c SS |
8380 | if (attr) |
8381 | { | |
8382 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
8383 | } | |
cb1df416 | 8384 | |
edb3359d DJ |
8385 | attr = dwarf2_attr (die, |
8386 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
8387 | cu); | |
cb1df416 DJ |
8388 | if (attr) |
8389 | { | |
8390 | int file_index = DW_UNSND (attr); | |
8391 | if (cu->line_header == NULL | |
8392 | || file_index > cu->line_header->num_file_names) | |
8393 | complaint (&symfile_complaints, | |
8394 | _("file index out of range")); | |
1c3d648d | 8395 | else if (file_index > 0) |
cb1df416 DJ |
8396 | { |
8397 | struct file_entry *fe; | |
8398 | fe = &cu->line_header->file_names[file_index - 1]; | |
8399 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
8400 | } | |
8401 | } | |
8402 | ||
c906108c SS |
8403 | switch (die->tag) |
8404 | { | |
8405 | case DW_TAG_label: | |
e142c38c | 8406 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
8407 | if (attr) |
8408 | { | |
8409 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
8410 | } | |
8411 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
8412 | break; | |
8413 | case DW_TAG_subprogram: | |
8414 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8415 | finish_block. */ | |
8416 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 8417 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
8418 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
8419 | || cu->language == language_ada) | |
c906108c | 8420 | { |
2cfa0c8d JB |
8421 | /* Subprograms marked external are stored as a global symbol. |
8422 | Ada subprograms, whether marked external or not, are always | |
8423 | stored as a global symbol, because we want to be able to | |
8424 | access them globally. For instance, we want to be able | |
8425 | to break on a nested subprogram without having to | |
8426 | specify the context. */ | |
c906108c SS |
8427 | add_symbol_to_list (sym, &global_symbols); |
8428 | } | |
8429 | else | |
8430 | { | |
e142c38c | 8431 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8432 | } |
8433 | break; | |
edb3359d DJ |
8434 | case DW_TAG_inlined_subroutine: |
8435 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8436 | finish_block. */ | |
8437 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
8438 | SYMBOL_INLINED (sym) = 1; | |
8439 | /* Do not add the symbol to any lists. It will be found via | |
8440 | BLOCK_FUNCTION from the blockvector. */ | |
8441 | break; | |
c906108c SS |
8442 | case DW_TAG_variable: |
8443 | /* Compilation with minimal debug info may result in variables | |
8444 | with missing type entries. Change the misleading `void' type | |
8445 | to something sensible. */ | |
8446 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 8447 | SYMBOL_TYPE (sym) |
46bf5051 | 8448 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 8449 | |
e142c38c | 8450 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8451 | if (attr) |
8452 | { | |
e7c27a73 | 8453 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 8454 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
8455 | if (attr2 && (DW_UNSND (attr2) != 0)) |
8456 | add_symbol_to_list (sym, &global_symbols); | |
8457 | else | |
e142c38c | 8458 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8459 | break; |
8460 | } | |
e142c38c | 8461 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8462 | if (attr) |
8463 | { | |
e7c27a73 | 8464 | var_decode_location (attr, sym, cu); |
e142c38c | 8465 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8466 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 8467 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 8468 | else |
e142c38c | 8469 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8470 | } |
8471 | else | |
8472 | { | |
8473 | /* We do not know the address of this symbol. | |
c5aa993b JM |
8474 | If it is an external symbol and we have type information |
8475 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
8476 | The address of the variable will then be determined from | |
8477 | the minimal symbol table whenever the variable is | |
8478 | referenced. */ | |
e142c38c | 8479 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8480 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 8481 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 8482 | { |
0fe7935b DJ |
8483 | struct pending **list_to_add; |
8484 | ||
8485 | /* A variable with DW_AT_external is never static, but it | |
8486 | may be block-scoped. */ | |
8487 | list_to_add = (cu->list_in_scope == &file_symbols | |
8488 | ? &global_symbols : cu->list_in_scope); | |
8489 | ||
c906108c | 8490 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
0fe7935b | 8491 | add_symbol_to_list (sym, list_to_add); |
c906108c | 8492 | } |
442ddf59 JK |
8493 | else if (!die_is_declaration (die, cu)) |
8494 | { | |
8495 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
8496 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
8497 | add_symbol_to_list (sym, cu->list_in_scope); | |
8498 | } | |
c906108c SS |
8499 | } |
8500 | break; | |
8501 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
8502 | /* If we are inside a function, mark this as an argument. If |
8503 | not, we might be looking at an argument to an inlined function | |
8504 | when we do not have enough information to show inlined frames; | |
8505 | pretend it's a local variable in that case so that the user can | |
8506 | still see it. */ | |
8507 | if (context_stack_depth > 0 | |
8508 | && context_stack[context_stack_depth - 1].name != NULL) | |
8509 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 8510 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8511 | if (attr) |
8512 | { | |
e7c27a73 | 8513 | var_decode_location (attr, sym, cu); |
c906108c | 8514 | } |
e142c38c | 8515 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8516 | if (attr) |
8517 | { | |
e7c27a73 | 8518 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8519 | } |
e142c38c | 8520 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8521 | break; |
8522 | case DW_TAG_unspecified_parameters: | |
8523 | /* From varargs functions; gdb doesn't seem to have any | |
8524 | interest in this information, so just ignore it for now. | |
8525 | (FIXME?) */ | |
8526 | break; | |
8527 | case DW_TAG_class_type: | |
680b30c7 | 8528 | case DW_TAG_interface_type: |
c906108c SS |
8529 | case DW_TAG_structure_type: |
8530 | case DW_TAG_union_type: | |
72019c9c | 8531 | case DW_TAG_set_type: |
c906108c SS |
8532 | case DW_TAG_enumeration_type: |
8533 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 8534 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 8535 | |
63d06c5c DC |
8536 | /* Make sure that the symbol includes appropriate enclosing |
8537 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 8538 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
8539 | the type. */ |
8540 | ||
987504bb JJ |
8541 | if (cu->language == language_cplus |
8542 | || cu->language == language_java) | |
c906108c | 8543 | { |
63d06c5c DC |
8544 | struct type *type = SYMBOL_TYPE (sym); |
8545 | ||
8546 | if (TYPE_TAG_NAME (type) != NULL) | |
8547 | { | |
8548 | /* FIXME: carlton/2003-11-10: Should this use | |
8549 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
8550 | arises further down in this function.) */ |
8551 | /* The type's name is already allocated along with | |
8552 | this objfile, so we don't need to duplicate it | |
8553 | for the symbol. */ | |
8554 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 8555 | } |
c906108c | 8556 | } |
63d06c5c DC |
8557 | |
8558 | { | |
987504bb | 8559 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
8560 | really ever be static objects: otherwise, if you try |
8561 | to, say, break of a class's method and you're in a file | |
8562 | which doesn't mention that class, it won't work unless | |
8563 | the check for all static symbols in lookup_symbol_aux | |
8564 | saves you. See the OtherFileClass tests in | |
8565 | gdb.c++/namespace.exp. */ | |
8566 | ||
8567 | struct pending **list_to_add; | |
8568 | ||
e142c38c | 8569 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8570 | && (cu->language == language_cplus |
8571 | || cu->language == language_java) | |
e142c38c | 8572 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8573 | |
8574 | add_symbol_to_list (sym, list_to_add); | |
8575 | ||
8576 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 8577 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 8578 | defines a typedef for the class. */ |
987504bb | 8579 | if (cu->language == language_cplus |
8c6860bb JB |
8580 | || cu->language == language_java |
8581 | || cu->language == language_ada) | |
63d06c5c | 8582 | { |
d8151005 DJ |
8583 | /* The symbol's name is already allocated along with |
8584 | this objfile, so we don't need to duplicate it for | |
8585 | the type. */ | |
63d06c5c | 8586 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 8587 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
8588 | } |
8589 | } | |
c906108c SS |
8590 | break; |
8591 | case DW_TAG_typedef: | |
0114d602 | 8592 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
63d06c5c DC |
8593 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
8594 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 8595 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 8596 | break; |
c906108c | 8597 | case DW_TAG_base_type: |
a02abb62 | 8598 | case DW_TAG_subrange_type: |
c906108c | 8599 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 8600 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 8601 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8602 | break; |
8603 | case DW_TAG_enumerator: | |
0114d602 | 8604 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
e142c38c | 8605 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8606 | if (attr) |
8607 | { | |
e7c27a73 | 8608 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8609 | } |
63d06c5c DC |
8610 | { |
8611 | /* NOTE: carlton/2003-11-10: See comment above in the | |
8612 | DW_TAG_class_type, etc. block. */ | |
8613 | ||
8614 | struct pending **list_to_add; | |
8615 | ||
e142c38c | 8616 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8617 | && (cu->language == language_cplus |
8618 | || cu->language == language_java) | |
e142c38c | 8619 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8620 | |
8621 | add_symbol_to_list (sym, list_to_add); | |
8622 | } | |
c906108c | 8623 | break; |
5c4e30ca DC |
8624 | case DW_TAG_namespace: |
8625 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
8626 | add_symbol_to_list (sym, &global_symbols); | |
8627 | break; | |
c906108c SS |
8628 | default: |
8629 | /* Not a tag we recognize. Hopefully we aren't processing | |
8630 | trash data, but since we must specifically ignore things | |
8631 | we don't recognize, there is nothing else we should do at | |
8632 | this point. */ | |
e2e0b3e5 | 8633 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 8634 | dwarf_tag_name (die->tag)); |
c906108c SS |
8635 | break; |
8636 | } | |
df8a16a1 DJ |
8637 | |
8638 | /* For the benefit of old versions of GCC, check for anonymous | |
8639 | namespaces based on the demangled name. */ | |
8640 | if (!processing_has_namespace_info | |
8641 | && cu->language == language_cplus | |
8642 | && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL) | |
8643 | cp_scan_for_anonymous_namespaces (sym); | |
c906108c SS |
8644 | } |
8645 | return (sym); | |
8646 | } | |
8647 | ||
8648 | /* Copy constant value from an attribute to a symbol. */ | |
8649 | ||
8650 | static void | |
107d2387 | 8651 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 8652 | struct dwarf2_cu *cu) |
c906108c | 8653 | { |
e7c27a73 DJ |
8654 | struct objfile *objfile = cu->objfile; |
8655 | struct comp_unit_head *cu_header = &cu->header; | |
e17a4113 UW |
8656 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
8657 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
c906108c SS |
8658 | struct dwarf_block *blk; |
8659 | ||
8660 | switch (attr->form) | |
8661 | { | |
8662 | case DW_FORM_addr: | |
107d2387 | 8663 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
3567439c | 8664 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8665 | cu_header->addr_size, |
8666 | TYPE_LENGTH (SYMBOL_TYPE | |
8667 | (sym))); | |
4e38b386 | 8668 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8669 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
8670 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
8671 | it's body - store_unsigned_integer. */ | |
8672 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
72f2769e | 8673 | byte_order, DW_ADDR (attr)); |
c906108c SS |
8674 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
8675 | break; | |
4ac36638 | 8676 | case DW_FORM_string: |
93b5768b PA |
8677 | case DW_FORM_strp: |
8678 | /* DW_STRING is already allocated on the obstack, point directly | |
8679 | to it. */ | |
8680 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
8681 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8682 | break; | |
c906108c SS |
8683 | case DW_FORM_block1: |
8684 | case DW_FORM_block2: | |
8685 | case DW_FORM_block4: | |
8686 | case DW_FORM_block: | |
8687 | blk = DW_BLOCK (attr); | |
8688 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 8689 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8690 | blk->size, |
8691 | TYPE_LENGTH (SYMBOL_TYPE | |
8692 | (sym))); | |
4e38b386 | 8693 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8694 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
8695 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
8696 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8697 | break; | |
2df3850c JM |
8698 | |
8699 | /* The DW_AT_const_value attributes are supposed to carry the | |
8700 | symbol's value "represented as it would be on the target | |
8701 | architecture." By the time we get here, it's already been | |
8702 | converted to host endianness, so we just need to sign- or | |
8703 | zero-extend it as appropriate. */ | |
8704 | case DW_FORM_data1: | |
8705 | dwarf2_const_value_data (attr, sym, 8); | |
8706 | break; | |
c906108c | 8707 | case DW_FORM_data2: |
2df3850c JM |
8708 | dwarf2_const_value_data (attr, sym, 16); |
8709 | break; | |
c906108c | 8710 | case DW_FORM_data4: |
2df3850c JM |
8711 | dwarf2_const_value_data (attr, sym, 32); |
8712 | break; | |
c906108c | 8713 | case DW_FORM_data8: |
2df3850c JM |
8714 | dwarf2_const_value_data (attr, sym, 64); |
8715 | break; | |
8716 | ||
c906108c | 8717 | case DW_FORM_sdata: |
2df3850c JM |
8718 | SYMBOL_VALUE (sym) = DW_SND (attr); |
8719 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8720 | break; | |
8721 | ||
c906108c SS |
8722 | case DW_FORM_udata: |
8723 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
8724 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8725 | break; | |
2df3850c | 8726 | |
c906108c | 8727 | default: |
4d3c2250 | 8728 | complaint (&symfile_complaints, |
e2e0b3e5 | 8729 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 8730 | dwarf_form_name (attr->form)); |
c906108c SS |
8731 | SYMBOL_VALUE (sym) = 0; |
8732 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8733 | break; | |
8734 | } | |
8735 | } | |
8736 | ||
2df3850c JM |
8737 | |
8738 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
8739 | or zero-extend it as appropriate for the symbol's type. */ | |
8740 | static void | |
8741 | dwarf2_const_value_data (struct attribute *attr, | |
8742 | struct symbol *sym, | |
8743 | int bits) | |
8744 | { | |
8745 | LONGEST l = DW_UNSND (attr); | |
8746 | ||
8747 | if (bits < sizeof (l) * 8) | |
8748 | { | |
8749 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
8750 | l &= ((LONGEST) 1 << bits) - 1; | |
8751 | else | |
bf9198f1 | 8752 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
8753 | } |
8754 | ||
8755 | SYMBOL_VALUE (sym) = l; | |
8756 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8757 | } | |
8758 | ||
8759 | ||
c906108c SS |
8760 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
8761 | ||
8762 | static struct type * | |
e7c27a73 | 8763 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8764 | { |
8765 | struct type *type; | |
8766 | struct attribute *type_attr; | |
8767 | struct die_info *type_die; | |
c906108c | 8768 | |
e142c38c | 8769 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
8770 | if (!type_attr) |
8771 | { | |
8772 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 8773 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 8774 | } |
348e048f DE |
8775 | |
8776 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10b3939b | 8777 | |
e7c27a73 | 8778 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8779 | if (!type) |
8780 | { | |
d97bc12b | 8781 | dump_die_for_error (type_die); |
8a3fe4f8 | 8782 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 8783 | cu->objfile->name); |
c906108c SS |
8784 | } |
8785 | return type; | |
8786 | } | |
8787 | ||
b4ba55a1 JB |
8788 | /* True iff CU's producer generates GNAT Ada auxiliary information |
8789 | that allows to find parallel types through that information instead | |
8790 | of having to do expensive parallel lookups by type name. */ | |
8791 | ||
8792 | static int | |
8793 | need_gnat_info (struct dwarf2_cu *cu) | |
8794 | { | |
8795 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
8796 | of GNAT produces this auxiliary information, without any indication | |
8797 | that it is produced. Part of enhancing the FSF version of GNAT | |
8798 | to produce that information will be to put in place an indicator | |
8799 | that we can use in order to determine whether the descriptive type | |
8800 | info is available or not. One suggestion that has been made is | |
8801 | to use a new attribute, attached to the CU die. For now, assume | |
8802 | that the descriptive type info is not available. */ | |
8803 | return 0; | |
8804 | } | |
8805 | ||
8806 | ||
8807 | /* Return the auxiliary type of the die in question using its | |
8808 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
8809 | attribute is not present. */ | |
8810 | ||
8811 | static struct type * | |
8812 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
8813 | { | |
8814 | struct type *type; | |
8815 | struct attribute *type_attr; | |
8816 | struct die_info *type_die; | |
8817 | ||
8818 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
8819 | if (!type_attr) | |
8820 | return NULL; | |
8821 | ||
8822 | type_die = follow_die_ref (die, type_attr, &cu); | |
8823 | type = tag_type_to_type (type_die, cu); | |
8824 | if (!type) | |
8825 | { | |
8826 | dump_die_for_error (type_die); | |
8827 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), | |
8828 | cu->objfile->name); | |
8829 | } | |
8830 | return type; | |
8831 | } | |
8832 | ||
8833 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
8834 | descriptive type accordingly. */ | |
8835 | ||
8836 | static void | |
8837 | set_descriptive_type (struct type *type, struct die_info *die, | |
8838 | struct dwarf2_cu *cu) | |
8839 | { | |
8840 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
8841 | ||
8842 | if (descriptive_type) | |
8843 | { | |
8844 | ALLOCATE_GNAT_AUX_TYPE (type); | |
8845 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
8846 | } | |
8847 | } | |
8848 | ||
c906108c SS |
8849 | /* Return the containing type of the die in question using its |
8850 | DW_AT_containing_type attribute. */ | |
8851 | ||
8852 | static struct type * | |
e7c27a73 | 8853 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8854 | { |
8855 | struct type *type = NULL; | |
8856 | struct attribute *type_attr; | |
8857 | struct die_info *type_die = NULL; | |
c906108c | 8858 | |
e142c38c | 8859 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
8860 | if (type_attr) |
8861 | { | |
348e048f | 8862 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); |
e7c27a73 | 8863 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8864 | } |
8865 | if (!type) | |
8866 | { | |
8867 | if (type_die) | |
d97bc12b | 8868 | dump_die_for_error (type_die); |
8a3fe4f8 | 8869 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 8870 | cu->objfile->name); |
c906108c SS |
8871 | } |
8872 | return type; | |
8873 | } | |
8874 | ||
c906108c | 8875 | static struct type * |
e7c27a73 | 8876 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8877 | { |
f792889a DJ |
8878 | struct type *this_type; |
8879 | ||
8880 | this_type = read_type_die (die, cu); | |
8881 | if (!this_type) | |
c906108c | 8882 | { |
d97bc12b | 8883 | dump_die_for_error (die); |
f792889a DJ |
8884 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
8885 | cu->objfile->name); | |
c906108c | 8886 | } |
f792889a | 8887 | return this_type; |
c906108c SS |
8888 | } |
8889 | ||
f792889a | 8890 | static struct type * |
e7c27a73 | 8891 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8892 | { |
f792889a DJ |
8893 | struct type *this_type; |
8894 | ||
8895 | this_type = get_die_type (die, cu); | |
8896 | if (this_type) | |
8897 | return this_type; | |
8898 | ||
c906108c SS |
8899 | switch (die->tag) |
8900 | { | |
8901 | case DW_TAG_class_type: | |
680b30c7 | 8902 | case DW_TAG_interface_type: |
c906108c SS |
8903 | case DW_TAG_structure_type: |
8904 | case DW_TAG_union_type: | |
f792889a | 8905 | this_type = read_structure_type (die, cu); |
c906108c SS |
8906 | break; |
8907 | case DW_TAG_enumeration_type: | |
f792889a | 8908 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
8909 | break; |
8910 | case DW_TAG_subprogram: | |
8911 | case DW_TAG_subroutine_type: | |
edb3359d | 8912 | case DW_TAG_inlined_subroutine: |
f792889a | 8913 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
8914 | break; |
8915 | case DW_TAG_array_type: | |
f792889a | 8916 | this_type = read_array_type (die, cu); |
c906108c | 8917 | break; |
72019c9c | 8918 | case DW_TAG_set_type: |
f792889a | 8919 | this_type = read_set_type (die, cu); |
72019c9c | 8920 | break; |
c906108c | 8921 | case DW_TAG_pointer_type: |
f792889a | 8922 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
8923 | break; |
8924 | case DW_TAG_ptr_to_member_type: | |
f792889a | 8925 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
8926 | break; |
8927 | case DW_TAG_reference_type: | |
f792889a | 8928 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
8929 | break; |
8930 | case DW_TAG_const_type: | |
f792889a | 8931 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
8932 | break; |
8933 | case DW_TAG_volatile_type: | |
f792889a | 8934 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
8935 | break; |
8936 | case DW_TAG_string_type: | |
f792889a | 8937 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
8938 | break; |
8939 | case DW_TAG_typedef: | |
f792889a | 8940 | this_type = read_typedef (die, cu); |
c906108c | 8941 | break; |
a02abb62 | 8942 | case DW_TAG_subrange_type: |
f792889a | 8943 | this_type = read_subrange_type (die, cu); |
a02abb62 | 8944 | break; |
c906108c | 8945 | case DW_TAG_base_type: |
f792889a | 8946 | this_type = read_base_type (die, cu); |
c906108c | 8947 | break; |
81a17f79 | 8948 | case DW_TAG_unspecified_type: |
f792889a | 8949 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 8950 | break; |
0114d602 DJ |
8951 | case DW_TAG_namespace: |
8952 | this_type = read_namespace_type (die, cu); | |
8953 | break; | |
c906108c | 8954 | default: |
a1f5b845 | 8955 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 8956 | dwarf_tag_name (die->tag)); |
c906108c SS |
8957 | break; |
8958 | } | |
63d06c5c | 8959 | |
f792889a | 8960 | return this_type; |
63d06c5c DC |
8961 | } |
8962 | ||
fdde2d81 | 8963 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 8964 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 8965 | |
0114d602 DJ |
8966 | For example, if we're within the method foo() in the following |
8967 | code: | |
8968 | ||
8969 | namespace N { | |
8970 | class C { | |
8971 | void foo () { | |
8972 | } | |
8973 | }; | |
8974 | } | |
8975 | ||
8976 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
8977 | |
8978 | static char * | |
e142c38c | 8979 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 8980 | { |
0114d602 DJ |
8981 | struct die_info *parent, *spec_die; |
8982 | struct dwarf2_cu *spec_cu; | |
8983 | struct type *parent_type; | |
63d06c5c | 8984 | |
987504bb JJ |
8985 | if (cu->language != language_cplus |
8986 | && cu->language != language_java) | |
0114d602 DJ |
8987 | return ""; |
8988 | ||
8989 | /* We have to be careful in the presence of DW_AT_specification. | |
8990 | For example, with GCC 3.4, given the code | |
8991 | ||
8992 | namespace N { | |
8993 | void foo() { | |
8994 | // Definition of N::foo. | |
8995 | } | |
8996 | } | |
8997 | ||
8998 | then we'll have a tree of DIEs like this: | |
8999 | ||
9000 | 1: DW_TAG_compile_unit | |
9001 | 2: DW_TAG_namespace // N | |
9002 | 3: DW_TAG_subprogram // declaration of N::foo | |
9003 | 4: DW_TAG_subprogram // definition of N::foo | |
9004 | DW_AT_specification // refers to die #3 | |
9005 | ||
9006 | Thus, when processing die #4, we have to pretend that we're in | |
9007 | the context of its DW_AT_specification, namely the contex of die | |
9008 | #3. */ | |
9009 | spec_cu = cu; | |
9010 | spec_die = die_specification (die, &spec_cu); | |
9011 | if (spec_die == NULL) | |
9012 | parent = die->parent; | |
9013 | else | |
63d06c5c | 9014 | { |
0114d602 DJ |
9015 | parent = spec_die->parent; |
9016 | cu = spec_cu; | |
63d06c5c | 9017 | } |
0114d602 DJ |
9018 | |
9019 | if (parent == NULL) | |
9020 | return ""; | |
63d06c5c | 9021 | else |
0114d602 DJ |
9022 | switch (parent->tag) |
9023 | { | |
63d06c5c | 9024 | case DW_TAG_namespace: |
0114d602 DJ |
9025 | parent_type = read_type_die (parent, cu); |
9026 | /* We give a name to even anonymous namespaces. */ | |
9027 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 9028 | case DW_TAG_class_type: |
680b30c7 | 9029 | case DW_TAG_interface_type: |
63d06c5c | 9030 | case DW_TAG_structure_type: |
0114d602 DJ |
9031 | case DW_TAG_union_type: |
9032 | parent_type = read_type_die (parent, cu); | |
9033 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
9034 | return TYPE_TAG_NAME (parent_type); | |
9035 | else | |
9036 | /* An anonymous structure is only allowed non-static data | |
9037 | members; no typedefs, no member functions, et cetera. | |
9038 | So it does not need a prefix. */ | |
9039 | return ""; | |
63d06c5c | 9040 | default: |
8176b9b8 | 9041 | return determine_prefix (parent, cu); |
63d06c5c | 9042 | } |
63d06c5c DC |
9043 | } |
9044 | ||
987504bb JJ |
9045 | /* Return a newly-allocated string formed by concatenating PREFIX and |
9046 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
9047 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
9048 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
9049 | is used to determine the language and hence, the appropriate separator. */ | |
9050 | ||
9051 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
9052 | |
9053 | static char * | |
987504bb JJ |
9054 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
9055 | struct dwarf2_cu *cu) | |
63d06c5c | 9056 | { |
987504bb | 9057 | char *sep; |
63d06c5c | 9058 | |
987504bb JJ |
9059 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
9060 | sep = ""; | |
9061 | else if (cu->language == language_java) | |
9062 | sep = "."; | |
9063 | else | |
9064 | sep = "::"; | |
63d06c5c | 9065 | |
6dd47d34 DE |
9066 | if (prefix == NULL) |
9067 | prefix = ""; | |
9068 | if (suffix == NULL) | |
9069 | suffix = ""; | |
9070 | ||
987504bb JJ |
9071 | if (obs == NULL) |
9072 | { | |
9073 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
6dd47d34 DE |
9074 | strcpy (retval, prefix); |
9075 | strcat (retval, sep); | |
9076 | strcat (retval, suffix); | |
63d06c5c DC |
9077 | return retval; |
9078 | } | |
987504bb JJ |
9079 | else |
9080 | { | |
9081 | /* We have an obstack. */ | |
9082 | return obconcat (obs, prefix, sep, suffix); | |
9083 | } | |
63d06c5c DC |
9084 | } |
9085 | ||
c906108c SS |
9086 | /* Return sibling of die, NULL if no sibling. */ |
9087 | ||
f9aca02d | 9088 | static struct die_info * |
fba45db2 | 9089 | sibling_die (struct die_info *die) |
c906108c | 9090 | { |
639d11d3 | 9091 | return die->sibling; |
c906108c SS |
9092 | } |
9093 | ||
9094 | /* Get linkage name of a die, return NULL if not found. */ | |
9095 | ||
9096 | static char * | |
e142c38c | 9097 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
9098 | { |
9099 | struct attribute *attr; | |
9100 | ||
e142c38c | 9101 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
9102 | if (attr && DW_STRING (attr)) |
9103 | return DW_STRING (attr); | |
71c25dea TT |
9104 | return dwarf2_name (die, cu); |
9105 | } | |
9106 | ||
9107 | /* Get name of a die, return NULL if not found. */ | |
9108 | ||
9109 | static char * | |
9110 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
9111 | struct obstack *obstack) | |
9112 | { | |
9113 | if (name && cu->language == language_cplus) | |
9114 | { | |
9115 | char *canon_name = cp_canonicalize_string (name); | |
9116 | ||
9117 | if (canon_name != NULL) | |
9118 | { | |
9119 | if (strcmp (canon_name, name) != 0) | |
9120 | name = obsavestring (canon_name, strlen (canon_name), | |
9121 | obstack); | |
9122 | xfree (canon_name); | |
9123 | } | |
9124 | } | |
9125 | ||
9126 | return name; | |
c906108c SS |
9127 | } |
9128 | ||
9219021c DC |
9129 | /* Get name of a die, return NULL if not found. */ |
9130 | ||
9131 | static char * | |
e142c38c | 9132 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
9133 | { |
9134 | struct attribute *attr; | |
9135 | ||
e142c38c | 9136 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
9137 | if (!attr || !DW_STRING (attr)) |
9138 | return NULL; | |
9139 | ||
9140 | switch (die->tag) | |
9141 | { | |
9142 | case DW_TAG_compile_unit: | |
9143 | /* Compilation units have a DW_AT_name that is a filename, not | |
9144 | a source language identifier. */ | |
9145 | case DW_TAG_enumeration_type: | |
9146 | case DW_TAG_enumerator: | |
9147 | /* These tags always have simple identifiers already; no need | |
9148 | to canonicalize them. */ | |
9149 | return DW_STRING (attr); | |
9150 | default: | |
8285870a | 9151 | if (!DW_STRING_IS_CANONICAL (attr)) |
71c25dea TT |
9152 | { |
9153 | DW_STRING (attr) | |
9154 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
9155 | &cu->objfile->objfile_obstack); | |
8285870a | 9156 | DW_STRING_IS_CANONICAL (attr) = 1; |
71c25dea TT |
9157 | } |
9158 | return DW_STRING (attr); | |
9159 | } | |
9219021c DC |
9160 | } |
9161 | ||
9162 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
9163 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
9164 | containing the return value on output. */ | |
9219021c DC |
9165 | |
9166 | static struct die_info * | |
f2f0e013 | 9167 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
9168 | { |
9169 | struct attribute *attr; | |
9219021c | 9170 | |
f2f0e013 | 9171 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
9172 | if (attr == NULL) |
9173 | return NULL; | |
9174 | ||
f2f0e013 | 9175 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
9176 | } |
9177 | ||
c906108c SS |
9178 | /* Convert a DIE tag into its string name. */ |
9179 | ||
9180 | static char * | |
aa1ee363 | 9181 | dwarf_tag_name (unsigned tag) |
c906108c SS |
9182 | { |
9183 | switch (tag) | |
9184 | { | |
9185 | case DW_TAG_padding: | |
9186 | return "DW_TAG_padding"; | |
9187 | case DW_TAG_array_type: | |
9188 | return "DW_TAG_array_type"; | |
9189 | case DW_TAG_class_type: | |
9190 | return "DW_TAG_class_type"; | |
9191 | case DW_TAG_entry_point: | |
9192 | return "DW_TAG_entry_point"; | |
9193 | case DW_TAG_enumeration_type: | |
9194 | return "DW_TAG_enumeration_type"; | |
9195 | case DW_TAG_formal_parameter: | |
9196 | return "DW_TAG_formal_parameter"; | |
9197 | case DW_TAG_imported_declaration: | |
9198 | return "DW_TAG_imported_declaration"; | |
9199 | case DW_TAG_label: | |
9200 | return "DW_TAG_label"; | |
9201 | case DW_TAG_lexical_block: | |
9202 | return "DW_TAG_lexical_block"; | |
9203 | case DW_TAG_member: | |
9204 | return "DW_TAG_member"; | |
9205 | case DW_TAG_pointer_type: | |
9206 | return "DW_TAG_pointer_type"; | |
9207 | case DW_TAG_reference_type: | |
9208 | return "DW_TAG_reference_type"; | |
9209 | case DW_TAG_compile_unit: | |
9210 | return "DW_TAG_compile_unit"; | |
9211 | case DW_TAG_string_type: | |
9212 | return "DW_TAG_string_type"; | |
9213 | case DW_TAG_structure_type: | |
9214 | return "DW_TAG_structure_type"; | |
9215 | case DW_TAG_subroutine_type: | |
9216 | return "DW_TAG_subroutine_type"; | |
9217 | case DW_TAG_typedef: | |
9218 | return "DW_TAG_typedef"; | |
9219 | case DW_TAG_union_type: | |
9220 | return "DW_TAG_union_type"; | |
9221 | case DW_TAG_unspecified_parameters: | |
9222 | return "DW_TAG_unspecified_parameters"; | |
9223 | case DW_TAG_variant: | |
9224 | return "DW_TAG_variant"; | |
9225 | case DW_TAG_common_block: | |
9226 | return "DW_TAG_common_block"; | |
9227 | case DW_TAG_common_inclusion: | |
9228 | return "DW_TAG_common_inclusion"; | |
9229 | case DW_TAG_inheritance: | |
9230 | return "DW_TAG_inheritance"; | |
9231 | case DW_TAG_inlined_subroutine: | |
9232 | return "DW_TAG_inlined_subroutine"; | |
9233 | case DW_TAG_module: | |
9234 | return "DW_TAG_module"; | |
9235 | case DW_TAG_ptr_to_member_type: | |
9236 | return "DW_TAG_ptr_to_member_type"; | |
9237 | case DW_TAG_set_type: | |
9238 | return "DW_TAG_set_type"; | |
9239 | case DW_TAG_subrange_type: | |
9240 | return "DW_TAG_subrange_type"; | |
9241 | case DW_TAG_with_stmt: | |
9242 | return "DW_TAG_with_stmt"; | |
9243 | case DW_TAG_access_declaration: | |
9244 | return "DW_TAG_access_declaration"; | |
9245 | case DW_TAG_base_type: | |
9246 | return "DW_TAG_base_type"; | |
9247 | case DW_TAG_catch_block: | |
9248 | return "DW_TAG_catch_block"; | |
9249 | case DW_TAG_const_type: | |
9250 | return "DW_TAG_const_type"; | |
9251 | case DW_TAG_constant: | |
9252 | return "DW_TAG_constant"; | |
9253 | case DW_TAG_enumerator: | |
9254 | return "DW_TAG_enumerator"; | |
9255 | case DW_TAG_file_type: | |
9256 | return "DW_TAG_file_type"; | |
9257 | case DW_TAG_friend: | |
9258 | return "DW_TAG_friend"; | |
9259 | case DW_TAG_namelist: | |
9260 | return "DW_TAG_namelist"; | |
9261 | case DW_TAG_namelist_item: | |
9262 | return "DW_TAG_namelist_item"; | |
9263 | case DW_TAG_packed_type: | |
9264 | return "DW_TAG_packed_type"; | |
9265 | case DW_TAG_subprogram: | |
9266 | return "DW_TAG_subprogram"; | |
9267 | case DW_TAG_template_type_param: | |
9268 | return "DW_TAG_template_type_param"; | |
9269 | case DW_TAG_template_value_param: | |
9270 | return "DW_TAG_template_value_param"; | |
9271 | case DW_TAG_thrown_type: | |
9272 | return "DW_TAG_thrown_type"; | |
9273 | case DW_TAG_try_block: | |
9274 | return "DW_TAG_try_block"; | |
9275 | case DW_TAG_variant_part: | |
9276 | return "DW_TAG_variant_part"; | |
9277 | case DW_TAG_variable: | |
9278 | return "DW_TAG_variable"; | |
9279 | case DW_TAG_volatile_type: | |
9280 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
9281 | case DW_TAG_dwarf_procedure: |
9282 | return "DW_TAG_dwarf_procedure"; | |
9283 | case DW_TAG_restrict_type: | |
9284 | return "DW_TAG_restrict_type"; | |
9285 | case DW_TAG_interface_type: | |
9286 | return "DW_TAG_interface_type"; | |
9287 | case DW_TAG_namespace: | |
9288 | return "DW_TAG_namespace"; | |
9289 | case DW_TAG_imported_module: | |
9290 | return "DW_TAG_imported_module"; | |
9291 | case DW_TAG_unspecified_type: | |
9292 | return "DW_TAG_unspecified_type"; | |
9293 | case DW_TAG_partial_unit: | |
9294 | return "DW_TAG_partial_unit"; | |
9295 | case DW_TAG_imported_unit: | |
9296 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
9297 | case DW_TAG_condition: |
9298 | return "DW_TAG_condition"; | |
9299 | case DW_TAG_shared_type: | |
9300 | return "DW_TAG_shared_type"; | |
348e048f DE |
9301 | case DW_TAG_type_unit: |
9302 | return "DW_TAG_type_unit"; | |
c906108c SS |
9303 | case DW_TAG_MIPS_loop: |
9304 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
9305 | case DW_TAG_HP_array_descriptor: |
9306 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
9307 | case DW_TAG_format_label: |
9308 | return "DW_TAG_format_label"; | |
9309 | case DW_TAG_function_template: | |
9310 | return "DW_TAG_function_template"; | |
9311 | case DW_TAG_class_template: | |
9312 | return "DW_TAG_class_template"; | |
b7619582 GF |
9313 | case DW_TAG_GNU_BINCL: |
9314 | return "DW_TAG_GNU_BINCL"; | |
9315 | case DW_TAG_GNU_EINCL: | |
9316 | return "DW_TAG_GNU_EINCL"; | |
9317 | case DW_TAG_upc_shared_type: | |
9318 | return "DW_TAG_upc_shared_type"; | |
9319 | case DW_TAG_upc_strict_type: | |
9320 | return "DW_TAG_upc_strict_type"; | |
9321 | case DW_TAG_upc_relaxed_type: | |
9322 | return "DW_TAG_upc_relaxed_type"; | |
9323 | case DW_TAG_PGI_kanji_type: | |
9324 | return "DW_TAG_PGI_kanji_type"; | |
9325 | case DW_TAG_PGI_interface_block: | |
9326 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
9327 | default: |
9328 | return "DW_TAG_<unknown>"; | |
9329 | } | |
9330 | } | |
9331 | ||
9332 | /* Convert a DWARF attribute code into its string name. */ | |
9333 | ||
9334 | static char * | |
aa1ee363 | 9335 | dwarf_attr_name (unsigned attr) |
c906108c SS |
9336 | { |
9337 | switch (attr) | |
9338 | { | |
9339 | case DW_AT_sibling: | |
9340 | return "DW_AT_sibling"; | |
9341 | case DW_AT_location: | |
9342 | return "DW_AT_location"; | |
9343 | case DW_AT_name: | |
9344 | return "DW_AT_name"; | |
9345 | case DW_AT_ordering: | |
9346 | return "DW_AT_ordering"; | |
9347 | case DW_AT_subscr_data: | |
9348 | return "DW_AT_subscr_data"; | |
9349 | case DW_AT_byte_size: | |
9350 | return "DW_AT_byte_size"; | |
9351 | case DW_AT_bit_offset: | |
9352 | return "DW_AT_bit_offset"; | |
9353 | case DW_AT_bit_size: | |
9354 | return "DW_AT_bit_size"; | |
9355 | case DW_AT_element_list: | |
9356 | return "DW_AT_element_list"; | |
9357 | case DW_AT_stmt_list: | |
9358 | return "DW_AT_stmt_list"; | |
9359 | case DW_AT_low_pc: | |
9360 | return "DW_AT_low_pc"; | |
9361 | case DW_AT_high_pc: | |
9362 | return "DW_AT_high_pc"; | |
9363 | case DW_AT_language: | |
9364 | return "DW_AT_language"; | |
9365 | case DW_AT_member: | |
9366 | return "DW_AT_member"; | |
9367 | case DW_AT_discr: | |
9368 | return "DW_AT_discr"; | |
9369 | case DW_AT_discr_value: | |
9370 | return "DW_AT_discr_value"; | |
9371 | case DW_AT_visibility: | |
9372 | return "DW_AT_visibility"; | |
9373 | case DW_AT_import: | |
9374 | return "DW_AT_import"; | |
9375 | case DW_AT_string_length: | |
9376 | return "DW_AT_string_length"; | |
9377 | case DW_AT_common_reference: | |
9378 | return "DW_AT_common_reference"; | |
9379 | case DW_AT_comp_dir: | |
9380 | return "DW_AT_comp_dir"; | |
9381 | case DW_AT_const_value: | |
9382 | return "DW_AT_const_value"; | |
9383 | case DW_AT_containing_type: | |
9384 | return "DW_AT_containing_type"; | |
9385 | case DW_AT_default_value: | |
9386 | return "DW_AT_default_value"; | |
9387 | case DW_AT_inline: | |
9388 | return "DW_AT_inline"; | |
9389 | case DW_AT_is_optional: | |
9390 | return "DW_AT_is_optional"; | |
9391 | case DW_AT_lower_bound: | |
9392 | return "DW_AT_lower_bound"; | |
9393 | case DW_AT_producer: | |
9394 | return "DW_AT_producer"; | |
9395 | case DW_AT_prototyped: | |
9396 | return "DW_AT_prototyped"; | |
9397 | case DW_AT_return_addr: | |
9398 | return "DW_AT_return_addr"; | |
9399 | case DW_AT_start_scope: | |
9400 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
9401 | case DW_AT_bit_stride: |
9402 | return "DW_AT_bit_stride"; | |
c906108c SS |
9403 | case DW_AT_upper_bound: |
9404 | return "DW_AT_upper_bound"; | |
9405 | case DW_AT_abstract_origin: | |
9406 | return "DW_AT_abstract_origin"; | |
9407 | case DW_AT_accessibility: | |
9408 | return "DW_AT_accessibility"; | |
9409 | case DW_AT_address_class: | |
9410 | return "DW_AT_address_class"; | |
9411 | case DW_AT_artificial: | |
9412 | return "DW_AT_artificial"; | |
9413 | case DW_AT_base_types: | |
9414 | return "DW_AT_base_types"; | |
9415 | case DW_AT_calling_convention: | |
9416 | return "DW_AT_calling_convention"; | |
9417 | case DW_AT_count: | |
9418 | return "DW_AT_count"; | |
9419 | case DW_AT_data_member_location: | |
9420 | return "DW_AT_data_member_location"; | |
9421 | case DW_AT_decl_column: | |
9422 | return "DW_AT_decl_column"; | |
9423 | case DW_AT_decl_file: | |
9424 | return "DW_AT_decl_file"; | |
9425 | case DW_AT_decl_line: | |
9426 | return "DW_AT_decl_line"; | |
9427 | case DW_AT_declaration: | |
9428 | return "DW_AT_declaration"; | |
9429 | case DW_AT_discr_list: | |
9430 | return "DW_AT_discr_list"; | |
9431 | case DW_AT_encoding: | |
9432 | return "DW_AT_encoding"; | |
9433 | case DW_AT_external: | |
9434 | return "DW_AT_external"; | |
9435 | case DW_AT_frame_base: | |
9436 | return "DW_AT_frame_base"; | |
9437 | case DW_AT_friend: | |
9438 | return "DW_AT_friend"; | |
9439 | case DW_AT_identifier_case: | |
9440 | return "DW_AT_identifier_case"; | |
9441 | case DW_AT_macro_info: | |
9442 | return "DW_AT_macro_info"; | |
9443 | case DW_AT_namelist_items: | |
9444 | return "DW_AT_namelist_items"; | |
9445 | case DW_AT_priority: | |
9446 | return "DW_AT_priority"; | |
9447 | case DW_AT_segment: | |
9448 | return "DW_AT_segment"; | |
9449 | case DW_AT_specification: | |
9450 | return "DW_AT_specification"; | |
9451 | case DW_AT_static_link: | |
9452 | return "DW_AT_static_link"; | |
9453 | case DW_AT_type: | |
9454 | return "DW_AT_type"; | |
9455 | case DW_AT_use_location: | |
9456 | return "DW_AT_use_location"; | |
9457 | case DW_AT_variable_parameter: | |
9458 | return "DW_AT_variable_parameter"; | |
9459 | case DW_AT_virtuality: | |
9460 | return "DW_AT_virtuality"; | |
9461 | case DW_AT_vtable_elem_location: | |
9462 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 9463 | /* DWARF 3 values. */ |
d9fa45fe DC |
9464 | case DW_AT_allocated: |
9465 | return "DW_AT_allocated"; | |
9466 | case DW_AT_associated: | |
9467 | return "DW_AT_associated"; | |
9468 | case DW_AT_data_location: | |
9469 | return "DW_AT_data_location"; | |
09fa0d7c JK |
9470 | case DW_AT_byte_stride: |
9471 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
9472 | case DW_AT_entry_pc: |
9473 | return "DW_AT_entry_pc"; | |
9474 | case DW_AT_use_UTF8: | |
9475 | return "DW_AT_use_UTF8"; | |
9476 | case DW_AT_extension: | |
9477 | return "DW_AT_extension"; | |
9478 | case DW_AT_ranges: | |
9479 | return "DW_AT_ranges"; | |
9480 | case DW_AT_trampoline: | |
9481 | return "DW_AT_trampoline"; | |
9482 | case DW_AT_call_column: | |
9483 | return "DW_AT_call_column"; | |
9484 | case DW_AT_call_file: | |
9485 | return "DW_AT_call_file"; | |
9486 | case DW_AT_call_line: | |
9487 | return "DW_AT_call_line"; | |
b7619582 GF |
9488 | case DW_AT_description: |
9489 | return "DW_AT_description"; | |
9490 | case DW_AT_binary_scale: | |
9491 | return "DW_AT_binary_scale"; | |
9492 | case DW_AT_decimal_scale: | |
9493 | return "DW_AT_decimal_scale"; | |
9494 | case DW_AT_small: | |
9495 | return "DW_AT_small"; | |
9496 | case DW_AT_decimal_sign: | |
9497 | return "DW_AT_decimal_sign"; | |
9498 | case DW_AT_digit_count: | |
9499 | return "DW_AT_digit_count"; | |
9500 | case DW_AT_picture_string: | |
9501 | return "DW_AT_picture_string"; | |
9502 | case DW_AT_mutable: | |
9503 | return "DW_AT_mutable"; | |
9504 | case DW_AT_threads_scaled: | |
9505 | return "DW_AT_threads_scaled"; | |
9506 | case DW_AT_explicit: | |
9507 | return "DW_AT_explicit"; | |
9508 | case DW_AT_object_pointer: | |
9509 | return "DW_AT_object_pointer"; | |
9510 | case DW_AT_endianity: | |
9511 | return "DW_AT_endianity"; | |
9512 | case DW_AT_elemental: | |
9513 | return "DW_AT_elemental"; | |
9514 | case DW_AT_pure: | |
9515 | return "DW_AT_pure"; | |
9516 | case DW_AT_recursive: | |
9517 | return "DW_AT_recursive"; | |
348e048f DE |
9518 | /* DWARF 4 values. */ |
9519 | case DW_AT_signature: | |
9520 | return "DW_AT_signature"; | |
b7619582 | 9521 | /* SGI/MIPS extensions. */ |
c764a876 | 9522 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
9523 | case DW_AT_MIPS_fde: |
9524 | return "DW_AT_MIPS_fde"; | |
c764a876 | 9525 | #endif |
c906108c SS |
9526 | case DW_AT_MIPS_loop_begin: |
9527 | return "DW_AT_MIPS_loop_begin"; | |
9528 | case DW_AT_MIPS_tail_loop_begin: | |
9529 | return "DW_AT_MIPS_tail_loop_begin"; | |
9530 | case DW_AT_MIPS_epilog_begin: | |
9531 | return "DW_AT_MIPS_epilog_begin"; | |
9532 | case DW_AT_MIPS_loop_unroll_factor: | |
9533 | return "DW_AT_MIPS_loop_unroll_factor"; | |
9534 | case DW_AT_MIPS_software_pipeline_depth: | |
9535 | return "DW_AT_MIPS_software_pipeline_depth"; | |
9536 | case DW_AT_MIPS_linkage_name: | |
9537 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
9538 | case DW_AT_MIPS_stride: |
9539 | return "DW_AT_MIPS_stride"; | |
9540 | case DW_AT_MIPS_abstract_name: | |
9541 | return "DW_AT_MIPS_abstract_name"; | |
9542 | case DW_AT_MIPS_clone_origin: | |
9543 | return "DW_AT_MIPS_clone_origin"; | |
9544 | case DW_AT_MIPS_has_inlines: | |
9545 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 9546 | /* HP extensions. */ |
c764a876 | 9547 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
9548 | case DW_AT_HP_block_index: |
9549 | return "DW_AT_HP_block_index"; | |
c764a876 | 9550 | #endif |
b7619582 GF |
9551 | case DW_AT_HP_unmodifiable: |
9552 | return "DW_AT_HP_unmodifiable"; | |
9553 | case DW_AT_HP_actuals_stmt_list: | |
9554 | return "DW_AT_HP_actuals_stmt_list"; | |
9555 | case DW_AT_HP_proc_per_section: | |
9556 | return "DW_AT_HP_proc_per_section"; | |
9557 | case DW_AT_HP_raw_data_ptr: | |
9558 | return "DW_AT_HP_raw_data_ptr"; | |
9559 | case DW_AT_HP_pass_by_reference: | |
9560 | return "DW_AT_HP_pass_by_reference"; | |
9561 | case DW_AT_HP_opt_level: | |
9562 | return "DW_AT_HP_opt_level"; | |
9563 | case DW_AT_HP_prof_version_id: | |
9564 | return "DW_AT_HP_prof_version_id"; | |
9565 | case DW_AT_HP_opt_flags: | |
9566 | return "DW_AT_HP_opt_flags"; | |
9567 | case DW_AT_HP_cold_region_low_pc: | |
9568 | return "DW_AT_HP_cold_region_low_pc"; | |
9569 | case DW_AT_HP_cold_region_high_pc: | |
9570 | return "DW_AT_HP_cold_region_high_pc"; | |
9571 | case DW_AT_HP_all_variables_modifiable: | |
9572 | return "DW_AT_HP_all_variables_modifiable"; | |
9573 | case DW_AT_HP_linkage_name: | |
9574 | return "DW_AT_HP_linkage_name"; | |
9575 | case DW_AT_HP_prof_flags: | |
9576 | return "DW_AT_HP_prof_flags"; | |
9577 | /* GNU extensions. */ | |
c906108c SS |
9578 | case DW_AT_sf_names: |
9579 | return "DW_AT_sf_names"; | |
9580 | case DW_AT_src_info: | |
9581 | return "DW_AT_src_info"; | |
9582 | case DW_AT_mac_info: | |
9583 | return "DW_AT_mac_info"; | |
9584 | case DW_AT_src_coords: | |
9585 | return "DW_AT_src_coords"; | |
9586 | case DW_AT_body_begin: | |
9587 | return "DW_AT_body_begin"; | |
9588 | case DW_AT_body_end: | |
9589 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
9590 | case DW_AT_GNU_vector: |
9591 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
9592 | /* VMS extensions. */ |
9593 | case DW_AT_VMS_rtnbeg_pd_address: | |
9594 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
9595 | /* UPC extension. */ | |
9596 | case DW_AT_upc_threads_scaled: | |
9597 | return "DW_AT_upc_threads_scaled"; | |
9598 | /* PGI (STMicroelectronics) extensions. */ | |
9599 | case DW_AT_PGI_lbase: | |
9600 | return "DW_AT_PGI_lbase"; | |
9601 | case DW_AT_PGI_soffset: | |
9602 | return "DW_AT_PGI_soffset"; | |
9603 | case DW_AT_PGI_lstride: | |
9604 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
9605 | default: |
9606 | return "DW_AT_<unknown>"; | |
9607 | } | |
9608 | } | |
9609 | ||
9610 | /* Convert a DWARF value form code into its string name. */ | |
9611 | ||
9612 | static char * | |
aa1ee363 | 9613 | dwarf_form_name (unsigned form) |
c906108c SS |
9614 | { |
9615 | switch (form) | |
9616 | { | |
9617 | case DW_FORM_addr: | |
9618 | return "DW_FORM_addr"; | |
9619 | case DW_FORM_block2: | |
9620 | return "DW_FORM_block2"; | |
9621 | case DW_FORM_block4: | |
9622 | return "DW_FORM_block4"; | |
9623 | case DW_FORM_data2: | |
9624 | return "DW_FORM_data2"; | |
9625 | case DW_FORM_data4: | |
9626 | return "DW_FORM_data4"; | |
9627 | case DW_FORM_data8: | |
9628 | return "DW_FORM_data8"; | |
9629 | case DW_FORM_string: | |
9630 | return "DW_FORM_string"; | |
9631 | case DW_FORM_block: | |
9632 | return "DW_FORM_block"; | |
9633 | case DW_FORM_block1: | |
9634 | return "DW_FORM_block1"; | |
9635 | case DW_FORM_data1: | |
9636 | return "DW_FORM_data1"; | |
9637 | case DW_FORM_flag: | |
9638 | return "DW_FORM_flag"; | |
9639 | case DW_FORM_sdata: | |
9640 | return "DW_FORM_sdata"; | |
9641 | case DW_FORM_strp: | |
9642 | return "DW_FORM_strp"; | |
9643 | case DW_FORM_udata: | |
9644 | return "DW_FORM_udata"; | |
9645 | case DW_FORM_ref_addr: | |
9646 | return "DW_FORM_ref_addr"; | |
9647 | case DW_FORM_ref1: | |
9648 | return "DW_FORM_ref1"; | |
9649 | case DW_FORM_ref2: | |
9650 | return "DW_FORM_ref2"; | |
9651 | case DW_FORM_ref4: | |
9652 | return "DW_FORM_ref4"; | |
9653 | case DW_FORM_ref8: | |
9654 | return "DW_FORM_ref8"; | |
9655 | case DW_FORM_ref_udata: | |
9656 | return "DW_FORM_ref_udata"; | |
9657 | case DW_FORM_indirect: | |
9658 | return "DW_FORM_indirect"; | |
348e048f DE |
9659 | case DW_FORM_sec_offset: |
9660 | return "DW_FORM_sec_offset"; | |
9661 | case DW_FORM_exprloc: | |
9662 | return "DW_FORM_exprloc"; | |
9663 | case DW_FORM_flag_present: | |
9664 | return "DW_FORM_flag_present"; | |
9665 | case DW_FORM_sig8: | |
9666 | return "DW_FORM_sig8"; | |
c906108c SS |
9667 | default: |
9668 | return "DW_FORM_<unknown>"; | |
9669 | } | |
9670 | } | |
9671 | ||
9672 | /* Convert a DWARF stack opcode into its string name. */ | |
9673 | ||
9674 | static char * | |
aa1ee363 | 9675 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
9676 | { |
9677 | switch (op) | |
9678 | { | |
9679 | case DW_OP_addr: | |
9680 | return "DW_OP_addr"; | |
9681 | case DW_OP_deref: | |
9682 | return "DW_OP_deref"; | |
9683 | case DW_OP_const1u: | |
9684 | return "DW_OP_const1u"; | |
9685 | case DW_OP_const1s: | |
9686 | return "DW_OP_const1s"; | |
9687 | case DW_OP_const2u: | |
9688 | return "DW_OP_const2u"; | |
9689 | case DW_OP_const2s: | |
9690 | return "DW_OP_const2s"; | |
9691 | case DW_OP_const4u: | |
9692 | return "DW_OP_const4u"; | |
9693 | case DW_OP_const4s: | |
9694 | return "DW_OP_const4s"; | |
9695 | case DW_OP_const8u: | |
9696 | return "DW_OP_const8u"; | |
9697 | case DW_OP_const8s: | |
9698 | return "DW_OP_const8s"; | |
9699 | case DW_OP_constu: | |
9700 | return "DW_OP_constu"; | |
9701 | case DW_OP_consts: | |
9702 | return "DW_OP_consts"; | |
9703 | case DW_OP_dup: | |
9704 | return "DW_OP_dup"; | |
9705 | case DW_OP_drop: | |
9706 | return "DW_OP_drop"; | |
9707 | case DW_OP_over: | |
9708 | return "DW_OP_over"; | |
9709 | case DW_OP_pick: | |
9710 | return "DW_OP_pick"; | |
9711 | case DW_OP_swap: | |
9712 | return "DW_OP_swap"; | |
9713 | case DW_OP_rot: | |
9714 | return "DW_OP_rot"; | |
9715 | case DW_OP_xderef: | |
9716 | return "DW_OP_xderef"; | |
9717 | case DW_OP_abs: | |
9718 | return "DW_OP_abs"; | |
9719 | case DW_OP_and: | |
9720 | return "DW_OP_and"; | |
9721 | case DW_OP_div: | |
9722 | return "DW_OP_div"; | |
9723 | case DW_OP_minus: | |
9724 | return "DW_OP_minus"; | |
9725 | case DW_OP_mod: | |
9726 | return "DW_OP_mod"; | |
9727 | case DW_OP_mul: | |
9728 | return "DW_OP_mul"; | |
9729 | case DW_OP_neg: | |
9730 | return "DW_OP_neg"; | |
9731 | case DW_OP_not: | |
9732 | return "DW_OP_not"; | |
9733 | case DW_OP_or: | |
9734 | return "DW_OP_or"; | |
9735 | case DW_OP_plus: | |
9736 | return "DW_OP_plus"; | |
9737 | case DW_OP_plus_uconst: | |
9738 | return "DW_OP_plus_uconst"; | |
9739 | case DW_OP_shl: | |
9740 | return "DW_OP_shl"; | |
9741 | case DW_OP_shr: | |
9742 | return "DW_OP_shr"; | |
9743 | case DW_OP_shra: | |
9744 | return "DW_OP_shra"; | |
9745 | case DW_OP_xor: | |
9746 | return "DW_OP_xor"; | |
9747 | case DW_OP_bra: | |
9748 | return "DW_OP_bra"; | |
9749 | case DW_OP_eq: | |
9750 | return "DW_OP_eq"; | |
9751 | case DW_OP_ge: | |
9752 | return "DW_OP_ge"; | |
9753 | case DW_OP_gt: | |
9754 | return "DW_OP_gt"; | |
9755 | case DW_OP_le: | |
9756 | return "DW_OP_le"; | |
9757 | case DW_OP_lt: | |
9758 | return "DW_OP_lt"; | |
9759 | case DW_OP_ne: | |
9760 | return "DW_OP_ne"; | |
9761 | case DW_OP_skip: | |
9762 | return "DW_OP_skip"; | |
9763 | case DW_OP_lit0: | |
9764 | return "DW_OP_lit0"; | |
9765 | case DW_OP_lit1: | |
9766 | return "DW_OP_lit1"; | |
9767 | case DW_OP_lit2: | |
9768 | return "DW_OP_lit2"; | |
9769 | case DW_OP_lit3: | |
9770 | return "DW_OP_lit3"; | |
9771 | case DW_OP_lit4: | |
9772 | return "DW_OP_lit4"; | |
9773 | case DW_OP_lit5: | |
9774 | return "DW_OP_lit5"; | |
9775 | case DW_OP_lit6: | |
9776 | return "DW_OP_lit6"; | |
9777 | case DW_OP_lit7: | |
9778 | return "DW_OP_lit7"; | |
9779 | case DW_OP_lit8: | |
9780 | return "DW_OP_lit8"; | |
9781 | case DW_OP_lit9: | |
9782 | return "DW_OP_lit9"; | |
9783 | case DW_OP_lit10: | |
9784 | return "DW_OP_lit10"; | |
9785 | case DW_OP_lit11: | |
9786 | return "DW_OP_lit11"; | |
9787 | case DW_OP_lit12: | |
9788 | return "DW_OP_lit12"; | |
9789 | case DW_OP_lit13: | |
9790 | return "DW_OP_lit13"; | |
9791 | case DW_OP_lit14: | |
9792 | return "DW_OP_lit14"; | |
9793 | case DW_OP_lit15: | |
9794 | return "DW_OP_lit15"; | |
9795 | case DW_OP_lit16: | |
9796 | return "DW_OP_lit16"; | |
9797 | case DW_OP_lit17: | |
9798 | return "DW_OP_lit17"; | |
9799 | case DW_OP_lit18: | |
9800 | return "DW_OP_lit18"; | |
9801 | case DW_OP_lit19: | |
9802 | return "DW_OP_lit19"; | |
9803 | case DW_OP_lit20: | |
9804 | return "DW_OP_lit20"; | |
9805 | case DW_OP_lit21: | |
9806 | return "DW_OP_lit21"; | |
9807 | case DW_OP_lit22: | |
9808 | return "DW_OP_lit22"; | |
9809 | case DW_OP_lit23: | |
9810 | return "DW_OP_lit23"; | |
9811 | case DW_OP_lit24: | |
9812 | return "DW_OP_lit24"; | |
9813 | case DW_OP_lit25: | |
9814 | return "DW_OP_lit25"; | |
9815 | case DW_OP_lit26: | |
9816 | return "DW_OP_lit26"; | |
9817 | case DW_OP_lit27: | |
9818 | return "DW_OP_lit27"; | |
9819 | case DW_OP_lit28: | |
9820 | return "DW_OP_lit28"; | |
9821 | case DW_OP_lit29: | |
9822 | return "DW_OP_lit29"; | |
9823 | case DW_OP_lit30: | |
9824 | return "DW_OP_lit30"; | |
9825 | case DW_OP_lit31: | |
9826 | return "DW_OP_lit31"; | |
9827 | case DW_OP_reg0: | |
9828 | return "DW_OP_reg0"; | |
9829 | case DW_OP_reg1: | |
9830 | return "DW_OP_reg1"; | |
9831 | case DW_OP_reg2: | |
9832 | return "DW_OP_reg2"; | |
9833 | case DW_OP_reg3: | |
9834 | return "DW_OP_reg3"; | |
9835 | case DW_OP_reg4: | |
9836 | return "DW_OP_reg4"; | |
9837 | case DW_OP_reg5: | |
9838 | return "DW_OP_reg5"; | |
9839 | case DW_OP_reg6: | |
9840 | return "DW_OP_reg6"; | |
9841 | case DW_OP_reg7: | |
9842 | return "DW_OP_reg7"; | |
9843 | case DW_OP_reg8: | |
9844 | return "DW_OP_reg8"; | |
9845 | case DW_OP_reg9: | |
9846 | return "DW_OP_reg9"; | |
9847 | case DW_OP_reg10: | |
9848 | return "DW_OP_reg10"; | |
9849 | case DW_OP_reg11: | |
9850 | return "DW_OP_reg11"; | |
9851 | case DW_OP_reg12: | |
9852 | return "DW_OP_reg12"; | |
9853 | case DW_OP_reg13: | |
9854 | return "DW_OP_reg13"; | |
9855 | case DW_OP_reg14: | |
9856 | return "DW_OP_reg14"; | |
9857 | case DW_OP_reg15: | |
9858 | return "DW_OP_reg15"; | |
9859 | case DW_OP_reg16: | |
9860 | return "DW_OP_reg16"; | |
9861 | case DW_OP_reg17: | |
9862 | return "DW_OP_reg17"; | |
9863 | case DW_OP_reg18: | |
9864 | return "DW_OP_reg18"; | |
9865 | case DW_OP_reg19: | |
9866 | return "DW_OP_reg19"; | |
9867 | case DW_OP_reg20: | |
9868 | return "DW_OP_reg20"; | |
9869 | case DW_OP_reg21: | |
9870 | return "DW_OP_reg21"; | |
9871 | case DW_OP_reg22: | |
9872 | return "DW_OP_reg22"; | |
9873 | case DW_OP_reg23: | |
9874 | return "DW_OP_reg23"; | |
9875 | case DW_OP_reg24: | |
9876 | return "DW_OP_reg24"; | |
9877 | case DW_OP_reg25: | |
9878 | return "DW_OP_reg25"; | |
9879 | case DW_OP_reg26: | |
9880 | return "DW_OP_reg26"; | |
9881 | case DW_OP_reg27: | |
9882 | return "DW_OP_reg27"; | |
9883 | case DW_OP_reg28: | |
9884 | return "DW_OP_reg28"; | |
9885 | case DW_OP_reg29: | |
9886 | return "DW_OP_reg29"; | |
9887 | case DW_OP_reg30: | |
9888 | return "DW_OP_reg30"; | |
9889 | case DW_OP_reg31: | |
9890 | return "DW_OP_reg31"; | |
9891 | case DW_OP_breg0: | |
9892 | return "DW_OP_breg0"; | |
9893 | case DW_OP_breg1: | |
9894 | return "DW_OP_breg1"; | |
9895 | case DW_OP_breg2: | |
9896 | return "DW_OP_breg2"; | |
9897 | case DW_OP_breg3: | |
9898 | return "DW_OP_breg3"; | |
9899 | case DW_OP_breg4: | |
9900 | return "DW_OP_breg4"; | |
9901 | case DW_OP_breg5: | |
9902 | return "DW_OP_breg5"; | |
9903 | case DW_OP_breg6: | |
9904 | return "DW_OP_breg6"; | |
9905 | case DW_OP_breg7: | |
9906 | return "DW_OP_breg7"; | |
9907 | case DW_OP_breg8: | |
9908 | return "DW_OP_breg8"; | |
9909 | case DW_OP_breg9: | |
9910 | return "DW_OP_breg9"; | |
9911 | case DW_OP_breg10: | |
9912 | return "DW_OP_breg10"; | |
9913 | case DW_OP_breg11: | |
9914 | return "DW_OP_breg11"; | |
9915 | case DW_OP_breg12: | |
9916 | return "DW_OP_breg12"; | |
9917 | case DW_OP_breg13: | |
9918 | return "DW_OP_breg13"; | |
9919 | case DW_OP_breg14: | |
9920 | return "DW_OP_breg14"; | |
9921 | case DW_OP_breg15: | |
9922 | return "DW_OP_breg15"; | |
9923 | case DW_OP_breg16: | |
9924 | return "DW_OP_breg16"; | |
9925 | case DW_OP_breg17: | |
9926 | return "DW_OP_breg17"; | |
9927 | case DW_OP_breg18: | |
9928 | return "DW_OP_breg18"; | |
9929 | case DW_OP_breg19: | |
9930 | return "DW_OP_breg19"; | |
9931 | case DW_OP_breg20: | |
9932 | return "DW_OP_breg20"; | |
9933 | case DW_OP_breg21: | |
9934 | return "DW_OP_breg21"; | |
9935 | case DW_OP_breg22: | |
9936 | return "DW_OP_breg22"; | |
9937 | case DW_OP_breg23: | |
9938 | return "DW_OP_breg23"; | |
9939 | case DW_OP_breg24: | |
9940 | return "DW_OP_breg24"; | |
9941 | case DW_OP_breg25: | |
9942 | return "DW_OP_breg25"; | |
9943 | case DW_OP_breg26: | |
9944 | return "DW_OP_breg26"; | |
9945 | case DW_OP_breg27: | |
9946 | return "DW_OP_breg27"; | |
9947 | case DW_OP_breg28: | |
9948 | return "DW_OP_breg28"; | |
9949 | case DW_OP_breg29: | |
9950 | return "DW_OP_breg29"; | |
9951 | case DW_OP_breg30: | |
9952 | return "DW_OP_breg30"; | |
9953 | case DW_OP_breg31: | |
9954 | return "DW_OP_breg31"; | |
9955 | case DW_OP_regx: | |
9956 | return "DW_OP_regx"; | |
9957 | case DW_OP_fbreg: | |
9958 | return "DW_OP_fbreg"; | |
9959 | case DW_OP_bregx: | |
9960 | return "DW_OP_bregx"; | |
9961 | case DW_OP_piece: | |
9962 | return "DW_OP_piece"; | |
9963 | case DW_OP_deref_size: | |
9964 | return "DW_OP_deref_size"; | |
9965 | case DW_OP_xderef_size: | |
9966 | return "DW_OP_xderef_size"; | |
9967 | case DW_OP_nop: | |
9968 | return "DW_OP_nop"; | |
b7619582 | 9969 | /* DWARF 3 extensions. */ |
ed348acc EZ |
9970 | case DW_OP_push_object_address: |
9971 | return "DW_OP_push_object_address"; | |
9972 | case DW_OP_call2: | |
9973 | return "DW_OP_call2"; | |
9974 | case DW_OP_call4: | |
9975 | return "DW_OP_call4"; | |
9976 | case DW_OP_call_ref: | |
9977 | return "DW_OP_call_ref"; | |
b7619582 GF |
9978 | /* GNU extensions. */ |
9979 | case DW_OP_form_tls_address: | |
9980 | return "DW_OP_form_tls_address"; | |
9981 | case DW_OP_call_frame_cfa: | |
9982 | return "DW_OP_call_frame_cfa"; | |
9983 | case DW_OP_bit_piece: | |
9984 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
9985 | case DW_OP_GNU_push_tls_address: |
9986 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
9987 | case DW_OP_GNU_uninit: |
9988 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
9989 | /* HP extensions. */ |
9990 | case DW_OP_HP_is_value: | |
9991 | return "DW_OP_HP_is_value"; | |
9992 | case DW_OP_HP_fltconst4: | |
9993 | return "DW_OP_HP_fltconst4"; | |
9994 | case DW_OP_HP_fltconst8: | |
9995 | return "DW_OP_HP_fltconst8"; | |
9996 | case DW_OP_HP_mod_range: | |
9997 | return "DW_OP_HP_mod_range"; | |
9998 | case DW_OP_HP_unmod_range: | |
9999 | return "DW_OP_HP_unmod_range"; | |
10000 | case DW_OP_HP_tls: | |
10001 | return "DW_OP_HP_tls"; | |
c906108c SS |
10002 | default: |
10003 | return "OP_<unknown>"; | |
10004 | } | |
10005 | } | |
10006 | ||
10007 | static char * | |
fba45db2 | 10008 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
10009 | { |
10010 | if (mybool) | |
10011 | return "TRUE"; | |
10012 | else | |
10013 | return "FALSE"; | |
10014 | } | |
10015 | ||
10016 | /* Convert a DWARF type code into its string name. */ | |
10017 | ||
10018 | static char * | |
aa1ee363 | 10019 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
10020 | { |
10021 | switch (enc) | |
10022 | { | |
b7619582 GF |
10023 | case DW_ATE_void: |
10024 | return "DW_ATE_void"; | |
c906108c SS |
10025 | case DW_ATE_address: |
10026 | return "DW_ATE_address"; | |
10027 | case DW_ATE_boolean: | |
10028 | return "DW_ATE_boolean"; | |
10029 | case DW_ATE_complex_float: | |
10030 | return "DW_ATE_complex_float"; | |
10031 | case DW_ATE_float: | |
10032 | return "DW_ATE_float"; | |
10033 | case DW_ATE_signed: | |
10034 | return "DW_ATE_signed"; | |
10035 | case DW_ATE_signed_char: | |
10036 | return "DW_ATE_signed_char"; | |
10037 | case DW_ATE_unsigned: | |
10038 | return "DW_ATE_unsigned"; | |
10039 | case DW_ATE_unsigned_char: | |
10040 | return "DW_ATE_unsigned_char"; | |
b7619582 | 10041 | /* DWARF 3. */ |
d9fa45fe DC |
10042 | case DW_ATE_imaginary_float: |
10043 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
10044 | case DW_ATE_packed_decimal: |
10045 | return "DW_ATE_packed_decimal"; | |
10046 | case DW_ATE_numeric_string: | |
10047 | return "DW_ATE_numeric_string"; | |
10048 | case DW_ATE_edited: | |
10049 | return "DW_ATE_edited"; | |
10050 | case DW_ATE_signed_fixed: | |
10051 | return "DW_ATE_signed_fixed"; | |
10052 | case DW_ATE_unsigned_fixed: | |
10053 | return "DW_ATE_unsigned_fixed"; | |
10054 | case DW_ATE_decimal_float: | |
10055 | return "DW_ATE_decimal_float"; | |
10056 | /* HP extensions. */ | |
10057 | case DW_ATE_HP_float80: | |
10058 | return "DW_ATE_HP_float80"; | |
10059 | case DW_ATE_HP_complex_float80: | |
10060 | return "DW_ATE_HP_complex_float80"; | |
10061 | case DW_ATE_HP_float128: | |
10062 | return "DW_ATE_HP_float128"; | |
10063 | case DW_ATE_HP_complex_float128: | |
10064 | return "DW_ATE_HP_complex_float128"; | |
10065 | case DW_ATE_HP_floathpintel: | |
10066 | return "DW_ATE_HP_floathpintel"; | |
10067 | case DW_ATE_HP_imaginary_float80: | |
10068 | return "DW_ATE_HP_imaginary_float80"; | |
10069 | case DW_ATE_HP_imaginary_float128: | |
10070 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
10071 | default: |
10072 | return "DW_ATE_<unknown>"; | |
10073 | } | |
10074 | } | |
10075 | ||
10076 | /* Convert a DWARF call frame info operation to its string name. */ | |
10077 | ||
10078 | #if 0 | |
10079 | static char * | |
aa1ee363 | 10080 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
10081 | { |
10082 | switch (cfi_opc) | |
10083 | { | |
10084 | case DW_CFA_advance_loc: | |
10085 | return "DW_CFA_advance_loc"; | |
10086 | case DW_CFA_offset: | |
10087 | return "DW_CFA_offset"; | |
10088 | case DW_CFA_restore: | |
10089 | return "DW_CFA_restore"; | |
10090 | case DW_CFA_nop: | |
10091 | return "DW_CFA_nop"; | |
10092 | case DW_CFA_set_loc: | |
10093 | return "DW_CFA_set_loc"; | |
10094 | case DW_CFA_advance_loc1: | |
10095 | return "DW_CFA_advance_loc1"; | |
10096 | case DW_CFA_advance_loc2: | |
10097 | return "DW_CFA_advance_loc2"; | |
10098 | case DW_CFA_advance_loc4: | |
10099 | return "DW_CFA_advance_loc4"; | |
10100 | case DW_CFA_offset_extended: | |
10101 | return "DW_CFA_offset_extended"; | |
10102 | case DW_CFA_restore_extended: | |
10103 | return "DW_CFA_restore_extended"; | |
10104 | case DW_CFA_undefined: | |
10105 | return "DW_CFA_undefined"; | |
10106 | case DW_CFA_same_value: | |
10107 | return "DW_CFA_same_value"; | |
10108 | case DW_CFA_register: | |
10109 | return "DW_CFA_register"; | |
10110 | case DW_CFA_remember_state: | |
10111 | return "DW_CFA_remember_state"; | |
10112 | case DW_CFA_restore_state: | |
10113 | return "DW_CFA_restore_state"; | |
10114 | case DW_CFA_def_cfa: | |
10115 | return "DW_CFA_def_cfa"; | |
10116 | case DW_CFA_def_cfa_register: | |
10117 | return "DW_CFA_def_cfa_register"; | |
10118 | case DW_CFA_def_cfa_offset: | |
10119 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 10120 | /* DWARF 3. */ |
985cb1a3 JM |
10121 | case DW_CFA_def_cfa_expression: |
10122 | return "DW_CFA_def_cfa_expression"; | |
10123 | case DW_CFA_expression: | |
10124 | return "DW_CFA_expression"; | |
10125 | case DW_CFA_offset_extended_sf: | |
10126 | return "DW_CFA_offset_extended_sf"; | |
10127 | case DW_CFA_def_cfa_sf: | |
10128 | return "DW_CFA_def_cfa_sf"; | |
10129 | case DW_CFA_def_cfa_offset_sf: | |
10130 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
10131 | case DW_CFA_val_offset: |
10132 | return "DW_CFA_val_offset"; | |
10133 | case DW_CFA_val_offset_sf: | |
10134 | return "DW_CFA_val_offset_sf"; | |
10135 | case DW_CFA_val_expression: | |
10136 | return "DW_CFA_val_expression"; | |
10137 | /* SGI/MIPS specific. */ | |
c906108c SS |
10138 | case DW_CFA_MIPS_advance_loc8: |
10139 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 10140 | /* GNU extensions. */ |
985cb1a3 JM |
10141 | case DW_CFA_GNU_window_save: |
10142 | return "DW_CFA_GNU_window_save"; | |
10143 | case DW_CFA_GNU_args_size: | |
10144 | return "DW_CFA_GNU_args_size"; | |
10145 | case DW_CFA_GNU_negative_offset_extended: | |
10146 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
10147 | default: |
10148 | return "DW_CFA_<unknown>"; | |
10149 | } | |
10150 | } | |
10151 | #endif | |
10152 | ||
f9aca02d | 10153 | static void |
d97bc12b | 10154 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
10155 | { |
10156 | unsigned int i; | |
10157 | ||
d97bc12b DE |
10158 | print_spaces (indent, f); |
10159 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 10160 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
10161 | |
10162 | if (die->parent != NULL) | |
10163 | { | |
10164 | print_spaces (indent, f); | |
10165 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
10166 | die->parent->offset); | |
10167 | } | |
10168 | ||
10169 | print_spaces (indent, f); | |
10170 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 10171 | dwarf_bool_name (die->child != NULL)); |
c906108c | 10172 | |
d97bc12b DE |
10173 | print_spaces (indent, f); |
10174 | fprintf_unfiltered (f, " attributes:\n"); | |
10175 | ||
c906108c SS |
10176 | for (i = 0; i < die->num_attrs; ++i) |
10177 | { | |
d97bc12b DE |
10178 | print_spaces (indent, f); |
10179 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
10180 | dwarf_attr_name (die->attrs[i].name), |
10181 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 10182 | |
c906108c SS |
10183 | switch (die->attrs[i].form) |
10184 | { | |
10185 | case DW_FORM_ref_addr: | |
10186 | case DW_FORM_addr: | |
d97bc12b | 10187 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 10188 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
10189 | break; |
10190 | case DW_FORM_block2: | |
10191 | case DW_FORM_block4: | |
10192 | case DW_FORM_block: | |
10193 | case DW_FORM_block1: | |
d97bc12b | 10194 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 10195 | break; |
10b3939b DJ |
10196 | case DW_FORM_ref1: |
10197 | case DW_FORM_ref2: | |
10198 | case DW_FORM_ref4: | |
d97bc12b | 10199 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
10200 | (long) (DW_ADDR (&die->attrs[i]))); |
10201 | break; | |
c906108c SS |
10202 | case DW_FORM_data1: |
10203 | case DW_FORM_data2: | |
10204 | case DW_FORM_data4: | |
ce5d95e1 | 10205 | case DW_FORM_data8: |
c906108c SS |
10206 | case DW_FORM_udata: |
10207 | case DW_FORM_sdata: | |
43bbcdc2 PH |
10208 | fprintf_unfiltered (f, "constant: %s", |
10209 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 10210 | break; |
348e048f DE |
10211 | case DW_FORM_sig8: |
10212 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
10213 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
10214 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
10215 | else | |
10216 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
10217 | break; | |
c906108c | 10218 | case DW_FORM_string: |
4bdf3d34 | 10219 | case DW_FORM_strp: |
8285870a | 10220 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 10221 | DW_STRING (&die->attrs[i]) |
8285870a JK |
10222 | ? DW_STRING (&die->attrs[i]) : "", |
10223 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
10224 | break; |
10225 | case DW_FORM_flag: | |
10226 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 10227 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 10228 | else |
d97bc12b | 10229 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 10230 | break; |
a8329558 KW |
10231 | case DW_FORM_indirect: |
10232 | /* the reader will have reduced the indirect form to | |
10233 | the "base form" so this form should not occur */ | |
d97bc12b | 10234 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 10235 | break; |
c906108c | 10236 | default: |
d97bc12b | 10237 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 10238 | die->attrs[i].form); |
d97bc12b | 10239 | break; |
c906108c | 10240 | } |
d97bc12b | 10241 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
10242 | } |
10243 | } | |
10244 | ||
f9aca02d | 10245 | static void |
d97bc12b | 10246 | dump_die_for_error (struct die_info *die) |
c906108c | 10247 | { |
d97bc12b DE |
10248 | dump_die_shallow (gdb_stderr, 0, die); |
10249 | } | |
10250 | ||
10251 | static void | |
10252 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
10253 | { | |
10254 | int indent = level * 4; | |
10255 | ||
10256 | gdb_assert (die != NULL); | |
10257 | ||
10258 | if (level >= max_level) | |
10259 | return; | |
10260 | ||
10261 | dump_die_shallow (f, indent, die); | |
10262 | ||
10263 | if (die->child != NULL) | |
c906108c | 10264 | { |
d97bc12b DE |
10265 | print_spaces (indent, f); |
10266 | fprintf_unfiltered (f, " Children:"); | |
10267 | if (level + 1 < max_level) | |
10268 | { | |
10269 | fprintf_unfiltered (f, "\n"); | |
10270 | dump_die_1 (f, level + 1, max_level, die->child); | |
10271 | } | |
10272 | else | |
10273 | { | |
10274 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
10275 | } | |
10276 | } | |
10277 | ||
10278 | if (die->sibling != NULL && level > 0) | |
10279 | { | |
10280 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
10281 | } |
10282 | } | |
10283 | ||
d97bc12b DE |
10284 | /* This is called from the pdie macro in gdbinit.in. |
10285 | It's not static so gcc will keep a copy callable from gdb. */ | |
10286 | ||
10287 | void | |
10288 | dump_die (struct die_info *die, int max_level) | |
10289 | { | |
10290 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
10291 | } | |
10292 | ||
f9aca02d | 10293 | static void |
51545339 | 10294 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10295 | { |
51545339 | 10296 | void **slot; |
c906108c | 10297 | |
51545339 DJ |
10298 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
10299 | ||
10300 | *slot = die; | |
c906108c SS |
10301 | } |
10302 | ||
93311388 DE |
10303 | static int |
10304 | is_ref_attr (struct attribute *attr) | |
c906108c | 10305 | { |
c906108c SS |
10306 | switch (attr->form) |
10307 | { | |
10308 | case DW_FORM_ref_addr: | |
c906108c SS |
10309 | case DW_FORM_ref1: |
10310 | case DW_FORM_ref2: | |
10311 | case DW_FORM_ref4: | |
613e1657 | 10312 | case DW_FORM_ref8: |
c906108c | 10313 | case DW_FORM_ref_udata: |
93311388 | 10314 | return 1; |
c906108c | 10315 | default: |
93311388 | 10316 | return 0; |
c906108c | 10317 | } |
93311388 DE |
10318 | } |
10319 | ||
10320 | static unsigned int | |
10321 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
10322 | { | |
10323 | if (is_ref_attr (attr)) | |
10324 | return DW_ADDR (attr); | |
10325 | ||
10326 | complaint (&symfile_complaints, | |
10327 | _("unsupported die ref attribute form: '%s'"), | |
10328 | dwarf_form_name (attr->form)); | |
10329 | return 0; | |
c906108c SS |
10330 | } |
10331 | ||
43bbcdc2 PH |
10332 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
10333 | * the value held by the attribute is not constant. */ | |
a02abb62 | 10334 | |
43bbcdc2 | 10335 | static LONGEST |
a02abb62 JB |
10336 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
10337 | { | |
10338 | if (attr->form == DW_FORM_sdata) | |
10339 | return DW_SND (attr); | |
10340 | else if (attr->form == DW_FORM_udata | |
10341 | || attr->form == DW_FORM_data1 | |
10342 | || attr->form == DW_FORM_data2 | |
10343 | || attr->form == DW_FORM_data4 | |
10344 | || attr->form == DW_FORM_data8) | |
10345 | return DW_UNSND (attr); | |
10346 | else | |
10347 | { | |
e2e0b3e5 | 10348 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
10349 | dwarf_form_name (attr->form)); |
10350 | return default_value; | |
10351 | } | |
10352 | } | |
10353 | ||
03dd20cc | 10354 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
10355 | unit and add it to our queue. |
10356 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
10357 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 10358 | |
348e048f | 10359 | static int |
03dd20cc DJ |
10360 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
10361 | struct dwarf2_per_cu_data *per_cu) | |
10362 | { | |
10363 | /* Mark the dependence relation so that we don't flush PER_CU | |
10364 | too early. */ | |
10365 | dwarf2_add_dependence (this_cu, per_cu); | |
10366 | ||
10367 | /* If it's already on the queue, we have nothing to do. */ | |
10368 | if (per_cu->queued) | |
348e048f | 10369 | return 0; |
03dd20cc DJ |
10370 | |
10371 | /* If the compilation unit is already loaded, just mark it as | |
10372 | used. */ | |
10373 | if (per_cu->cu != NULL) | |
10374 | { | |
10375 | per_cu->cu->last_used = 0; | |
348e048f | 10376 | return 0; |
03dd20cc DJ |
10377 | } |
10378 | ||
10379 | /* Add it to the queue. */ | |
10380 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
10381 | |
10382 | return 1; | |
10383 | } | |
10384 | ||
10385 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
10386 | On entry *REF_CU is the CU of SRC_DIE. | |
10387 | On exit *REF_CU is the CU of the result. */ | |
10388 | ||
10389 | static struct die_info * | |
10390 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
10391 | struct dwarf2_cu **ref_cu) | |
10392 | { | |
10393 | struct die_info *die; | |
10394 | ||
10395 | if (is_ref_attr (attr)) | |
10396 | die = follow_die_ref (src_die, attr, ref_cu); | |
10397 | else if (attr->form == DW_FORM_sig8) | |
10398 | die = follow_die_sig (src_die, attr, ref_cu); | |
10399 | else | |
10400 | { | |
10401 | dump_die_for_error (src_die); | |
10402 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
10403 | (*ref_cu)->objfile->name); | |
10404 | } | |
10405 | ||
10406 | return die; | |
03dd20cc DJ |
10407 | } |
10408 | ||
f504f079 DE |
10409 | /* Follow reference attribute ATTR of SRC_DIE. |
10410 | On entry *REF_CU is the CU of SRC_DIE. | |
10411 | On exit *REF_CU is the CU of the result. */ | |
10412 | ||
f9aca02d | 10413 | static struct die_info * |
10b3939b | 10414 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 10415 | struct dwarf2_cu **ref_cu) |
c906108c SS |
10416 | { |
10417 | struct die_info *die; | |
10b3939b | 10418 | unsigned int offset; |
10b3939b | 10419 | struct die_info temp_die; |
f2f0e013 | 10420 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 10421 | |
348e048f DE |
10422 | gdb_assert (cu->per_cu != NULL); |
10423 | ||
c764a876 | 10424 | offset = dwarf2_get_ref_die_offset (attr); |
10b3939b | 10425 | |
348e048f DE |
10426 | if (cu->per_cu->from_debug_types) |
10427 | { | |
10428 | /* .debug_types CUs cannot reference anything outside their CU. | |
10429 | If they need to, they have to reference a signatured type via | |
10430 | DW_FORM_sig8. */ | |
10431 | if (! offset_in_cu_p (&cu->header, offset)) | |
10432 | goto not_found; | |
10433 | target_cu = cu; | |
10434 | } | |
10435 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
10436 | { |
10437 | struct dwarf2_per_cu_data *per_cu; | |
45452591 | 10438 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
10439 | |
10440 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
10441 | if (maybe_queue_comp_unit (cu, per_cu)) |
10442 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 10443 | |
10b3939b DJ |
10444 | target_cu = per_cu->cu; |
10445 | } | |
10446 | else | |
10447 | target_cu = cu; | |
c906108c | 10448 | |
f2f0e013 | 10449 | *ref_cu = target_cu; |
51545339 DJ |
10450 | temp_die.offset = offset; |
10451 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
10452 | if (die) | |
10453 | return die; | |
10b3939b | 10454 | |
348e048f DE |
10455 | not_found: |
10456 | ||
10457 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
10458 | "at 0x%x [in module %s]"), | |
10459 | offset, src_die->offset, cu->objfile->name); | |
10460 | } | |
10461 | ||
10462 | /* Follow the signature attribute ATTR in SRC_DIE. | |
10463 | On entry *REF_CU is the CU of SRC_DIE. | |
10464 | On exit *REF_CU is the CU of the result. */ | |
10465 | ||
10466 | static struct die_info * | |
10467 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
10468 | struct dwarf2_cu **ref_cu) | |
10469 | { | |
10470 | struct objfile *objfile = (*ref_cu)->objfile; | |
10471 | struct die_info temp_die; | |
10472 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
10473 | struct dwarf2_cu *sig_cu; | |
10474 | struct die_info *die; | |
10475 | ||
10476 | /* sig_type will be NULL if the signatured type is missing from | |
10477 | the debug info. */ | |
10478 | if (sig_type == NULL) | |
10479 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
10480 | "at 0x%x [in module %s]"), | |
10481 | src_die->offset, objfile->name); | |
10482 | ||
10483 | /* If necessary, add it to the queue and load its DIEs. */ | |
10484 | ||
10485 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
10486 | read_signatured_type (objfile, sig_type); | |
10487 | ||
10488 | gdb_assert (sig_type->per_cu.cu != NULL); | |
10489 | ||
10490 | sig_cu = sig_type->per_cu.cu; | |
10491 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
10492 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
10493 | if (die) | |
10494 | { | |
10495 | *ref_cu = sig_cu; | |
10496 | return die; | |
10497 | } | |
10498 | ||
10499 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
10500 | "at 0x%x [in module %s]"), | |
10501 | sig_type->type_offset, src_die->offset, objfile->name); | |
10502 | } | |
10503 | ||
10504 | /* Given an offset of a signatured type, return its signatured_type. */ | |
10505 | ||
10506 | static struct signatured_type * | |
10507 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
10508 | { | |
10509 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
10510 | unsigned int length, initial_length_size; | |
10511 | unsigned int sig_offset; | |
10512 | struct signatured_type find_entry, *type_sig; | |
10513 | ||
10514 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
10515 | sig_offset = (initial_length_size | |
10516 | + 2 /*version*/ | |
10517 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
10518 | + 1 /*address_size*/); | |
10519 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
10520 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
10521 | ||
10522 | /* This is only used to lookup previously recorded types. | |
10523 | If we didn't find it, it's our bug. */ | |
10524 | gdb_assert (type_sig != NULL); | |
10525 | gdb_assert (offset == type_sig->offset); | |
10526 | ||
10527 | return type_sig; | |
10528 | } | |
10529 | ||
10530 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
10531 | ||
10532 | static void | |
10533 | read_signatured_type_at_offset (struct objfile *objfile, | |
10534 | unsigned int offset) | |
10535 | { | |
10536 | struct signatured_type *type_sig; | |
10537 | ||
10538 | /* We have the section offset, but we need the signature to do the | |
10539 | hash table lookup. */ | |
10540 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
10541 | ||
10542 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10543 | ||
10544 | read_signatured_type (objfile, type_sig); | |
10545 | ||
10546 | gdb_assert (type_sig->per_cu.cu != NULL); | |
10547 | } | |
10548 | ||
10549 | /* Read in a signatured type and build its CU and DIEs. */ | |
10550 | ||
10551 | static void | |
10552 | read_signatured_type (struct objfile *objfile, | |
10553 | struct signatured_type *type_sig) | |
10554 | { | |
10555 | gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
10556 | struct die_reader_specs reader_specs; | |
10557 | struct dwarf2_cu *cu; | |
10558 | ULONGEST signature; | |
10559 | struct cleanup *back_to, *free_cu_cleanup; | |
10560 | struct attribute *attr; | |
10561 | ||
10562 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10563 | ||
10564 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
10565 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
10566 | obstack_init (&cu->comp_unit_obstack); | |
10567 | cu->objfile = objfile; | |
10568 | type_sig->per_cu.cu = cu; | |
10569 | cu->per_cu = &type_sig->per_cu; | |
10570 | ||
10571 | /* If an error occurs while loading, release our storage. */ | |
10572 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
10573 | ||
10574 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
10575 | types_ptr, objfile->obfd); | |
10576 | gdb_assert (signature == type_sig->signature); | |
10577 | ||
10578 | cu->die_hash | |
10579 | = htab_create_alloc_ex (cu->header.length / 12, | |
10580 | die_hash, | |
10581 | die_eq, | |
10582 | NULL, | |
10583 | &cu->comp_unit_obstack, | |
10584 | hashtab_obstack_allocate, | |
10585 | dummy_obstack_deallocate); | |
10586 | ||
10587 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
10588 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10589 | ||
10590 | init_cu_die_reader (&reader_specs, cu); | |
10591 | ||
10592 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
10593 | NULL /*parent*/); | |
10594 | ||
10595 | /* We try not to read any attributes in this function, because not | |
10596 | all objfiles needed for references have been loaded yet, and symbol | |
10597 | table processing isn't initialized. But we have to set the CU language, | |
10598 | or we won't be able to build types correctly. */ | |
10599 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
10600 | if (attr) | |
10601 | set_cu_language (DW_UNSND (attr), cu); | |
10602 | else | |
10603 | set_cu_language (language_minimal, cu); | |
10604 | ||
10605 | do_cleanups (back_to); | |
10606 | ||
10607 | /* We've successfully allocated this compilation unit. Let our caller | |
10608 | clean it up when finished with it. */ | |
10609 | discard_cleanups (free_cu_cleanup); | |
10610 | ||
10611 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
10612 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
10613 | } |
10614 | ||
c906108c SS |
10615 | /* Decode simple location descriptions. |
10616 | Given a pointer to a dwarf block that defines a location, compute | |
10617 | the location and return the value. | |
10618 | ||
4cecd739 DJ |
10619 | NOTE drow/2003-11-18: This function is called in two situations |
10620 | now: for the address of static or global variables (partial symbols | |
10621 | only) and for offsets into structures which are expected to be | |
10622 | (more or less) constant. The partial symbol case should go away, | |
10623 | and only the constant case should remain. That will let this | |
10624 | function complain more accurately. A few special modes are allowed | |
10625 | without complaint for global variables (for instance, global | |
10626 | register values and thread-local values). | |
c906108c SS |
10627 | |
10628 | A location description containing no operations indicates that the | |
4cecd739 | 10629 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
10630 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
10631 | callers will only want a very basic result and this can become a | |
10632 | complaint. | |
c906108c | 10633 | |
c906108c SS |
10634 | Note that stack[0] is unused except as a default error return. |
10635 | Note that stack overflow is not yet handled. */ | |
10636 | ||
10637 | static CORE_ADDR | |
e7c27a73 | 10638 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 10639 | { |
e7c27a73 DJ |
10640 | struct objfile *objfile = cu->objfile; |
10641 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
10642 | int i; |
10643 | int size = blk->size; | |
fe1b8b76 | 10644 | gdb_byte *data = blk->data; |
c906108c SS |
10645 | CORE_ADDR stack[64]; |
10646 | int stacki; | |
10647 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 10648 | gdb_byte op; |
c906108c SS |
10649 | |
10650 | i = 0; | |
10651 | stacki = 0; | |
10652 | stack[stacki] = 0; | |
c906108c SS |
10653 | |
10654 | while (i < size) | |
10655 | { | |
c906108c SS |
10656 | op = data[i++]; |
10657 | switch (op) | |
10658 | { | |
f1bea926 JM |
10659 | case DW_OP_lit0: |
10660 | case DW_OP_lit1: | |
10661 | case DW_OP_lit2: | |
10662 | case DW_OP_lit3: | |
10663 | case DW_OP_lit4: | |
10664 | case DW_OP_lit5: | |
10665 | case DW_OP_lit6: | |
10666 | case DW_OP_lit7: | |
10667 | case DW_OP_lit8: | |
10668 | case DW_OP_lit9: | |
10669 | case DW_OP_lit10: | |
10670 | case DW_OP_lit11: | |
10671 | case DW_OP_lit12: | |
10672 | case DW_OP_lit13: | |
10673 | case DW_OP_lit14: | |
10674 | case DW_OP_lit15: | |
10675 | case DW_OP_lit16: | |
10676 | case DW_OP_lit17: | |
10677 | case DW_OP_lit18: | |
10678 | case DW_OP_lit19: | |
10679 | case DW_OP_lit20: | |
10680 | case DW_OP_lit21: | |
10681 | case DW_OP_lit22: | |
10682 | case DW_OP_lit23: | |
10683 | case DW_OP_lit24: | |
10684 | case DW_OP_lit25: | |
10685 | case DW_OP_lit26: | |
10686 | case DW_OP_lit27: | |
10687 | case DW_OP_lit28: | |
10688 | case DW_OP_lit29: | |
10689 | case DW_OP_lit30: | |
10690 | case DW_OP_lit31: | |
10691 | stack[++stacki] = op - DW_OP_lit0; | |
10692 | break; | |
10693 | ||
c906108c SS |
10694 | case DW_OP_reg0: |
10695 | case DW_OP_reg1: | |
10696 | case DW_OP_reg2: | |
10697 | case DW_OP_reg3: | |
10698 | case DW_OP_reg4: | |
10699 | case DW_OP_reg5: | |
10700 | case DW_OP_reg6: | |
10701 | case DW_OP_reg7: | |
10702 | case DW_OP_reg8: | |
10703 | case DW_OP_reg9: | |
10704 | case DW_OP_reg10: | |
10705 | case DW_OP_reg11: | |
10706 | case DW_OP_reg12: | |
10707 | case DW_OP_reg13: | |
10708 | case DW_OP_reg14: | |
10709 | case DW_OP_reg15: | |
10710 | case DW_OP_reg16: | |
10711 | case DW_OP_reg17: | |
10712 | case DW_OP_reg18: | |
10713 | case DW_OP_reg19: | |
10714 | case DW_OP_reg20: | |
10715 | case DW_OP_reg21: | |
10716 | case DW_OP_reg22: | |
10717 | case DW_OP_reg23: | |
10718 | case DW_OP_reg24: | |
10719 | case DW_OP_reg25: | |
10720 | case DW_OP_reg26: | |
10721 | case DW_OP_reg27: | |
10722 | case DW_OP_reg28: | |
10723 | case DW_OP_reg29: | |
10724 | case DW_OP_reg30: | |
10725 | case DW_OP_reg31: | |
c906108c | 10726 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
10727 | if (i < size) |
10728 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10729 | break; |
10730 | ||
10731 | case DW_OP_regx: | |
c906108c SS |
10732 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
10733 | i += bytes_read; | |
c906108c | 10734 | stack[++stacki] = unsnd; |
4cecd739 DJ |
10735 | if (i < size) |
10736 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10737 | break; |
10738 | ||
10739 | case DW_OP_addr: | |
107d2387 | 10740 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 10741 | cu, &bytes_read); |
107d2387 | 10742 | i += bytes_read; |
c906108c SS |
10743 | break; |
10744 | ||
10745 | case DW_OP_const1u: | |
10746 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
10747 | i += 1; | |
10748 | break; | |
10749 | ||
10750 | case DW_OP_const1s: | |
10751 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
10752 | i += 1; | |
10753 | break; | |
10754 | ||
10755 | case DW_OP_const2u: | |
10756 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
10757 | i += 2; | |
10758 | break; | |
10759 | ||
10760 | case DW_OP_const2s: | |
10761 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
10762 | i += 2; | |
10763 | break; | |
10764 | ||
10765 | case DW_OP_const4u: | |
10766 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
10767 | i += 4; | |
10768 | break; | |
10769 | ||
10770 | case DW_OP_const4s: | |
10771 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
10772 | i += 4; | |
10773 | break; | |
10774 | ||
10775 | case DW_OP_constu: | |
10776 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 10777 | &bytes_read); |
c906108c SS |
10778 | i += bytes_read; |
10779 | break; | |
10780 | ||
10781 | case DW_OP_consts: | |
10782 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
10783 | i += bytes_read; | |
10784 | break; | |
10785 | ||
f1bea926 JM |
10786 | case DW_OP_dup: |
10787 | stack[stacki + 1] = stack[stacki]; | |
10788 | stacki++; | |
10789 | break; | |
10790 | ||
c906108c SS |
10791 | case DW_OP_plus: |
10792 | stack[stacki - 1] += stack[stacki]; | |
10793 | stacki--; | |
10794 | break; | |
10795 | ||
10796 | case DW_OP_plus_uconst: | |
10797 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
10798 | i += bytes_read; | |
10799 | break; | |
10800 | ||
10801 | case DW_OP_minus: | |
f1bea926 | 10802 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
10803 | stacki--; |
10804 | break; | |
10805 | ||
7a292a7a | 10806 | case DW_OP_deref: |
7a292a7a | 10807 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
10808 | this using GDB's address_class enum. This is valid for partial |
10809 | global symbols, although the variable's address will be bogus | |
10810 | in the psymtab. */ | |
7a292a7a | 10811 | if (i < size) |
4d3c2250 | 10812 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
10813 | break; |
10814 | ||
9d774e44 | 10815 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
10816 | /* The top of the stack has the offset from the beginning |
10817 | of the thread control block at which the variable is located. */ | |
10818 | /* Nothing should follow this operator, so the top of stack would | |
10819 | be returned. */ | |
4cecd739 DJ |
10820 | /* This is valid for partial global symbols, but the variable's |
10821 | address will be bogus in the psymtab. */ | |
9d774e44 | 10822 | if (i < size) |
4d3c2250 | 10823 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
10824 | break; |
10825 | ||
42be36b3 CT |
10826 | case DW_OP_GNU_uninit: |
10827 | break; | |
10828 | ||
c906108c | 10829 | default: |
e2e0b3e5 | 10830 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 10831 | dwarf_stack_op_name (op)); |
c906108c SS |
10832 | return (stack[stacki]); |
10833 | } | |
10834 | } | |
10835 | return (stack[stacki]); | |
10836 | } | |
10837 | ||
10838 | /* memory allocation interface */ | |
10839 | ||
c906108c | 10840 | static struct dwarf_block * |
7b5a2f43 | 10841 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
10842 | { |
10843 | struct dwarf_block *blk; | |
10844 | ||
10845 | blk = (struct dwarf_block *) | |
7b5a2f43 | 10846 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
10847 | return (blk); |
10848 | } | |
10849 | ||
10850 | static struct abbrev_info * | |
f3dd6933 | 10851 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
10852 | { |
10853 | struct abbrev_info *abbrev; | |
10854 | ||
f3dd6933 DJ |
10855 | abbrev = (struct abbrev_info *) |
10856 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
10857 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
10858 | return (abbrev); | |
10859 | } | |
10860 | ||
10861 | static struct die_info * | |
b60c80d6 | 10862 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
10863 | { |
10864 | struct die_info *die; | |
b60c80d6 DJ |
10865 | size_t size = sizeof (struct die_info); |
10866 | ||
10867 | if (num_attrs > 1) | |
10868 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 10869 | |
b60c80d6 | 10870 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
10871 | memset (die, 0, sizeof (struct die_info)); |
10872 | return (die); | |
10873 | } | |
2e276125 JB |
10874 | |
10875 | \f | |
10876 | /* Macro support. */ | |
10877 | ||
10878 | ||
10879 | /* Return the full name of file number I in *LH's file name table. | |
10880 | Use COMP_DIR as the name of the current directory of the | |
10881 | compilation. The result is allocated using xmalloc; the caller is | |
10882 | responsible for freeing it. */ | |
10883 | static char * | |
10884 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
10885 | { | |
6a83a1e6 EZ |
10886 | /* Is the file number a valid index into the line header's file name |
10887 | table? Remember that file numbers start with one, not zero. */ | |
10888 | if (1 <= file && file <= lh->num_file_names) | |
10889 | { | |
10890 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 10891 | |
6a83a1e6 EZ |
10892 | if (IS_ABSOLUTE_PATH (fe->name)) |
10893 | return xstrdup (fe->name); | |
10894 | else | |
10895 | { | |
10896 | const char *dir; | |
10897 | int dir_len; | |
10898 | char *full_name; | |
10899 | ||
10900 | if (fe->dir_index) | |
10901 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10902 | else | |
10903 | dir = comp_dir; | |
10904 | ||
10905 | if (dir) | |
10906 | { | |
10907 | dir_len = strlen (dir); | |
10908 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
10909 | strcpy (full_name, dir); | |
10910 | full_name[dir_len] = '/'; | |
10911 | strcpy (full_name + dir_len + 1, fe->name); | |
10912 | return full_name; | |
10913 | } | |
10914 | else | |
10915 | return xstrdup (fe->name); | |
10916 | } | |
10917 | } | |
2e276125 JB |
10918 | else |
10919 | { | |
6a83a1e6 EZ |
10920 | /* The compiler produced a bogus file number. We can at least |
10921 | record the macro definitions made in the file, even if we | |
10922 | won't be able to find the file by name. */ | |
10923 | char fake_name[80]; | |
10924 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 10925 | |
6a83a1e6 EZ |
10926 | complaint (&symfile_complaints, |
10927 | _("bad file number in macro information (%d)"), | |
10928 | file); | |
2e276125 | 10929 | |
6a83a1e6 | 10930 | return xstrdup (fake_name); |
2e276125 JB |
10931 | } |
10932 | } | |
10933 | ||
10934 | ||
10935 | static struct macro_source_file * | |
10936 | macro_start_file (int file, int line, | |
10937 | struct macro_source_file *current_file, | |
10938 | const char *comp_dir, | |
10939 | struct line_header *lh, struct objfile *objfile) | |
10940 | { | |
10941 | /* The full name of this source file. */ | |
10942 | char *full_name = file_full_name (file, lh, comp_dir); | |
10943 | ||
10944 | /* We don't create a macro table for this compilation unit | |
10945 | at all until we actually get a filename. */ | |
10946 | if (! pending_macros) | |
4a146b47 | 10947 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 10948 | objfile->macro_cache); |
2e276125 JB |
10949 | |
10950 | if (! current_file) | |
10951 | /* If we have no current file, then this must be the start_file | |
10952 | directive for the compilation unit's main source file. */ | |
10953 | current_file = macro_set_main (pending_macros, full_name); | |
10954 | else | |
10955 | current_file = macro_include (current_file, line, full_name); | |
10956 | ||
10957 | xfree (full_name); | |
10958 | ||
10959 | return current_file; | |
10960 | } | |
10961 | ||
10962 | ||
10963 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
10964 | followed by a null byte. */ | |
10965 | static char * | |
10966 | copy_string (const char *buf, int len) | |
10967 | { | |
10968 | char *s = xmalloc (len + 1); | |
10969 | memcpy (s, buf, len); | |
10970 | s[len] = '\0'; | |
10971 | ||
10972 | return s; | |
10973 | } | |
10974 | ||
10975 | ||
10976 | static const char * | |
10977 | consume_improper_spaces (const char *p, const char *body) | |
10978 | { | |
10979 | if (*p == ' ') | |
10980 | { | |
4d3c2250 | 10981 | complaint (&symfile_complaints, |
e2e0b3e5 | 10982 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 10983 | body); |
2e276125 JB |
10984 | |
10985 | while (*p == ' ') | |
10986 | p++; | |
10987 | } | |
10988 | ||
10989 | return p; | |
10990 | } | |
10991 | ||
10992 | ||
10993 | static void | |
10994 | parse_macro_definition (struct macro_source_file *file, int line, | |
10995 | const char *body) | |
10996 | { | |
10997 | const char *p; | |
10998 | ||
10999 | /* The body string takes one of two forms. For object-like macro | |
11000 | definitions, it should be: | |
11001 | ||
11002 | <macro name> " " <definition> | |
11003 | ||
11004 | For function-like macro definitions, it should be: | |
11005 | ||
11006 | <macro name> "() " <definition> | |
11007 | or | |
11008 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
11009 | ||
11010 | Spaces may appear only where explicitly indicated, and in the | |
11011 | <definition>. | |
11012 | ||
11013 | The Dwarf 2 spec says that an object-like macro's name is always | |
11014 | followed by a space, but versions of GCC around March 2002 omit | |
11015 | the space when the macro's definition is the empty string. | |
11016 | ||
11017 | The Dwarf 2 spec says that there should be no spaces between the | |
11018 | formal arguments in a function-like macro's formal argument list, | |
11019 | but versions of GCC around March 2002 include spaces after the | |
11020 | commas. */ | |
11021 | ||
11022 | ||
11023 | /* Find the extent of the macro name. The macro name is terminated | |
11024 | by either a space or null character (for an object-like macro) or | |
11025 | an opening paren (for a function-like macro). */ | |
11026 | for (p = body; *p; p++) | |
11027 | if (*p == ' ' || *p == '(') | |
11028 | break; | |
11029 | ||
11030 | if (*p == ' ' || *p == '\0') | |
11031 | { | |
11032 | /* It's an object-like macro. */ | |
11033 | int name_len = p - body; | |
11034 | char *name = copy_string (body, name_len); | |
11035 | const char *replacement; | |
11036 | ||
11037 | if (*p == ' ') | |
11038 | replacement = body + name_len + 1; | |
11039 | else | |
11040 | { | |
4d3c2250 | 11041 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11042 | replacement = body + name_len; |
11043 | } | |
11044 | ||
11045 | macro_define_object (file, line, name, replacement); | |
11046 | ||
11047 | xfree (name); | |
11048 | } | |
11049 | else if (*p == '(') | |
11050 | { | |
11051 | /* It's a function-like macro. */ | |
11052 | char *name = copy_string (body, p - body); | |
11053 | int argc = 0; | |
11054 | int argv_size = 1; | |
11055 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
11056 | ||
11057 | p++; | |
11058 | ||
11059 | p = consume_improper_spaces (p, body); | |
11060 | ||
11061 | /* Parse the formal argument list. */ | |
11062 | while (*p && *p != ')') | |
11063 | { | |
11064 | /* Find the extent of the current argument name. */ | |
11065 | const char *arg_start = p; | |
11066 | ||
11067 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
11068 | p++; | |
11069 | ||
11070 | if (! *p || p == arg_start) | |
4d3c2250 | 11071 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11072 | else |
11073 | { | |
11074 | /* Make sure argv has room for the new argument. */ | |
11075 | if (argc >= argv_size) | |
11076 | { | |
11077 | argv_size *= 2; | |
11078 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
11079 | } | |
11080 | ||
11081 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
11082 | } | |
11083 | ||
11084 | p = consume_improper_spaces (p, body); | |
11085 | ||
11086 | /* Consume the comma, if present. */ | |
11087 | if (*p == ',') | |
11088 | { | |
11089 | p++; | |
11090 | ||
11091 | p = consume_improper_spaces (p, body); | |
11092 | } | |
11093 | } | |
11094 | ||
11095 | if (*p == ')') | |
11096 | { | |
11097 | p++; | |
11098 | ||
11099 | if (*p == ' ') | |
11100 | /* Perfectly formed definition, no complaints. */ | |
11101 | macro_define_function (file, line, name, | |
11102 | argc, (const char **) argv, | |
11103 | p + 1); | |
11104 | else if (*p == '\0') | |
11105 | { | |
11106 | /* Complain, but do define it. */ | |
4d3c2250 | 11107 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11108 | macro_define_function (file, line, name, |
11109 | argc, (const char **) argv, | |
11110 | p); | |
11111 | } | |
11112 | else | |
11113 | /* Just complain. */ | |
4d3c2250 | 11114 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11115 | } |
11116 | else | |
11117 | /* Just complain. */ | |
4d3c2250 | 11118 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11119 | |
11120 | xfree (name); | |
11121 | { | |
11122 | int i; | |
11123 | ||
11124 | for (i = 0; i < argc; i++) | |
11125 | xfree (argv[i]); | |
11126 | } | |
11127 | xfree (argv); | |
11128 | } | |
11129 | else | |
4d3c2250 | 11130 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11131 | } |
11132 | ||
11133 | ||
11134 | static void | |
11135 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
11136 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 11137 | struct dwarf2_cu *cu) |
2e276125 | 11138 | { |
fe1b8b76 | 11139 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 11140 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
11141 | enum dwarf_macinfo_record_type macinfo_type; |
11142 | int at_commandline; | |
2e276125 | 11143 | |
dce234bc | 11144 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 11145 | { |
e2e0b3e5 | 11146 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
11147 | return; |
11148 | } | |
11149 | ||
757a13d0 JK |
11150 | /* First pass: Find the name of the base filename. |
11151 | This filename is needed in order to process all macros whose definition | |
11152 | (or undefinition) comes from the command line. These macros are defined | |
11153 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
11154 | associated to the base file. | |
11155 | ||
11156 | To determine the base file name, we scan the macro definitions until we | |
11157 | reach the first DW_MACINFO_start_file entry. We then initialize | |
11158 | CURRENT_FILE accordingly so that any macro definition found before the | |
11159 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
11160 | ||
dce234bc PP |
11161 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
11162 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
11163 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 11164 | |
757a13d0 | 11165 | do |
2e276125 | 11166 | { |
2e276125 JB |
11167 | /* Do we at least have room for a macinfo type byte? */ |
11168 | if (mac_ptr >= mac_end) | |
11169 | { | |
757a13d0 JK |
11170 | /* Complaint is printed during the second pass as GDB will probably |
11171 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
11172 | break; | |
2e276125 JB |
11173 | } |
11174 | ||
11175 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11176 | mac_ptr++; | |
11177 | ||
11178 | switch (macinfo_type) | |
11179 | { | |
11180 | /* A zero macinfo type indicates the end of the macro | |
11181 | information. */ | |
11182 | case 0: | |
757a13d0 JK |
11183 | break; |
11184 | ||
11185 | case DW_MACINFO_define: | |
11186 | case DW_MACINFO_undef: | |
11187 | /* Only skip the data by MAC_PTR. */ | |
11188 | { | |
11189 | unsigned int bytes_read; | |
11190 | ||
11191 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11192 | mac_ptr += bytes_read; | |
11193 | read_string (abfd, mac_ptr, &bytes_read); | |
11194 | mac_ptr += bytes_read; | |
11195 | } | |
11196 | break; | |
11197 | ||
11198 | case DW_MACINFO_start_file: | |
11199 | { | |
11200 | unsigned int bytes_read; | |
11201 | int line, file; | |
11202 | ||
11203 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11204 | mac_ptr += bytes_read; | |
11205 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11206 | mac_ptr += bytes_read; | |
11207 | ||
11208 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
11209 | lh, cu->objfile); | |
11210 | } | |
11211 | break; | |
11212 | ||
11213 | case DW_MACINFO_end_file: | |
11214 | /* No data to skip by MAC_PTR. */ | |
11215 | break; | |
11216 | ||
11217 | case DW_MACINFO_vendor_ext: | |
11218 | /* Only skip the data by MAC_PTR. */ | |
11219 | { | |
11220 | unsigned int bytes_read; | |
11221 | ||
11222 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11223 | mac_ptr += bytes_read; | |
11224 | read_string (abfd, mac_ptr, &bytes_read); | |
11225 | mac_ptr += bytes_read; | |
11226 | } | |
11227 | break; | |
11228 | ||
11229 | default: | |
11230 | break; | |
11231 | } | |
11232 | } while (macinfo_type != 0 && current_file == NULL); | |
11233 | ||
11234 | /* Second pass: Process all entries. | |
11235 | ||
11236 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
11237 | command-line macro definitions/undefinitions. This flag is unset when we | |
11238 | reach the first DW_MACINFO_start_file entry. */ | |
11239 | ||
dce234bc | 11240 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
11241 | |
11242 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
11243 | GDB is still reading the definitions from command line. First | |
11244 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
11245 | to create CURRENT_FILE for the main source holding also the command line | |
11246 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
11247 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
11248 | ||
11249 | at_commandline = 1; | |
11250 | ||
11251 | do | |
11252 | { | |
11253 | /* Do we at least have room for a macinfo type byte? */ | |
11254 | if (mac_ptr >= mac_end) | |
11255 | { | |
11256 | dwarf2_macros_too_long_complaint (); | |
11257 | break; | |
11258 | } | |
11259 | ||
11260 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11261 | mac_ptr++; | |
11262 | ||
11263 | switch (macinfo_type) | |
11264 | { | |
11265 | /* A zero macinfo type indicates the end of the macro | |
11266 | information. */ | |
11267 | case 0: | |
11268 | break; | |
2e276125 JB |
11269 | |
11270 | case DW_MACINFO_define: | |
11271 | case DW_MACINFO_undef: | |
11272 | { | |
891d2f0b | 11273 | unsigned int bytes_read; |
2e276125 JB |
11274 | int line; |
11275 | char *body; | |
11276 | ||
11277 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11278 | mac_ptr += bytes_read; | |
11279 | body = read_string (abfd, mac_ptr, &bytes_read); | |
11280 | mac_ptr += bytes_read; | |
11281 | ||
11282 | if (! current_file) | |
757a13d0 JK |
11283 | { |
11284 | /* DWARF violation as no main source is present. */ | |
11285 | complaint (&symfile_complaints, | |
11286 | _("debug info with no main source gives macro %s " | |
11287 | "on line %d: %s"), | |
905e0470 PM |
11288 | macinfo_type == DW_MACINFO_define ? |
11289 | _("definition") : | |
11290 | macinfo_type == DW_MACINFO_undef ? | |
11291 | _("undefinition") : | |
11292 | _("something-or-other"), line, body); | |
757a13d0 JK |
11293 | break; |
11294 | } | |
11295 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 11296 | complaint (&symfile_complaints, |
757a13d0 JK |
11297 | _("debug info gives %s macro %s with %s line %d: %s"), |
11298 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 PM |
11299 | macinfo_type == DW_MACINFO_define ? |
11300 | _("definition") : | |
11301 | macinfo_type == DW_MACINFO_undef ? | |
11302 | _("undefinition") : | |
11303 | _("something-or-other"), | |
757a13d0 JK |
11304 | line == 0 ? _("zero") : _("non-zero"), line, body); |
11305 | ||
11306 | if (macinfo_type == DW_MACINFO_define) | |
11307 | parse_macro_definition (current_file, line, body); | |
11308 | else if (macinfo_type == DW_MACINFO_undef) | |
11309 | macro_undef (current_file, line, body); | |
2e276125 JB |
11310 | } |
11311 | break; | |
11312 | ||
11313 | case DW_MACINFO_start_file: | |
11314 | { | |
891d2f0b | 11315 | unsigned int bytes_read; |
2e276125 JB |
11316 | int line, file; |
11317 | ||
11318 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11319 | mac_ptr += bytes_read; | |
11320 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11321 | mac_ptr += bytes_read; | |
11322 | ||
757a13d0 JK |
11323 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
11324 | complaint (&symfile_complaints, | |
11325 | _("debug info gives source %d included " | |
11326 | "from %s at %s line %d"), | |
11327 | file, at_commandline ? _("command-line") : _("file"), | |
11328 | line == 0 ? _("zero") : _("non-zero"), line); | |
11329 | ||
11330 | if (at_commandline) | |
11331 | { | |
11332 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
11333 | at_commandline = 0; | |
11334 | } | |
11335 | else | |
11336 | current_file = macro_start_file (file, line, | |
11337 | current_file, comp_dir, | |
11338 | lh, cu->objfile); | |
2e276125 JB |
11339 | } |
11340 | break; | |
11341 | ||
11342 | case DW_MACINFO_end_file: | |
11343 | if (! current_file) | |
4d3c2250 | 11344 | complaint (&symfile_complaints, |
e2e0b3e5 | 11345 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
11346 | else |
11347 | { | |
11348 | current_file = current_file->included_by; | |
11349 | if (! current_file) | |
11350 | { | |
11351 | enum dwarf_macinfo_record_type next_type; | |
11352 | ||
11353 | /* GCC circa March 2002 doesn't produce the zero | |
11354 | type byte marking the end of the compilation | |
11355 | unit. Complain if it's not there, but exit no | |
11356 | matter what. */ | |
11357 | ||
11358 | /* Do we at least have room for a macinfo type byte? */ | |
11359 | if (mac_ptr >= mac_end) | |
11360 | { | |
4d3c2250 | 11361 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
11362 | return; |
11363 | } | |
11364 | ||
11365 | /* We don't increment mac_ptr here, so this is just | |
11366 | a look-ahead. */ | |
11367 | next_type = read_1_byte (abfd, mac_ptr); | |
11368 | if (next_type != 0) | |
4d3c2250 | 11369 | complaint (&symfile_complaints, |
e2e0b3e5 | 11370 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
11371 | |
11372 | return; | |
11373 | } | |
11374 | } | |
11375 | break; | |
11376 | ||
11377 | case DW_MACINFO_vendor_ext: | |
11378 | { | |
891d2f0b | 11379 | unsigned int bytes_read; |
2e276125 JB |
11380 | int constant; |
11381 | char *string; | |
11382 | ||
11383 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11384 | mac_ptr += bytes_read; | |
11385 | string = read_string (abfd, mac_ptr, &bytes_read); | |
11386 | mac_ptr += bytes_read; | |
11387 | ||
11388 | /* We don't recognize any vendor extensions. */ | |
11389 | } | |
11390 | break; | |
11391 | } | |
757a13d0 | 11392 | } while (macinfo_type != 0); |
2e276125 | 11393 | } |
8e19ed76 PS |
11394 | |
11395 | /* Check if the attribute's form is a DW_FORM_block* | |
11396 | if so return true else false. */ | |
11397 | static int | |
11398 | attr_form_is_block (struct attribute *attr) | |
11399 | { | |
11400 | return (attr == NULL ? 0 : | |
11401 | attr->form == DW_FORM_block1 | |
11402 | || attr->form == DW_FORM_block2 | |
11403 | || attr->form == DW_FORM_block4 | |
11404 | || attr->form == DW_FORM_block); | |
11405 | } | |
4c2df51b | 11406 | |
c6a0999f JB |
11407 | /* Return non-zero if ATTR's value is a section offset --- classes |
11408 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
11409 | You may use DW_UNSND (attr) to retrieve such offsets. | |
11410 | ||
11411 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
11412 | may have a value that belongs to more than one of these classes; it | |
11413 | would be ambiguous if we did, because we use the same forms for all | |
11414 | of them. */ | |
3690dd37 JB |
11415 | static int |
11416 | attr_form_is_section_offset (struct attribute *attr) | |
11417 | { | |
11418 | return (attr->form == DW_FORM_data4 | |
11419 | || attr->form == DW_FORM_data8); | |
11420 | } | |
11421 | ||
11422 | ||
11423 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
11424 | zero otherwise. When this function returns true, you can apply | |
11425 | dwarf2_get_attr_constant_value to it. | |
11426 | ||
11427 | However, note that for some attributes you must check | |
11428 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
11429 | and DW_FORM_data8 are members of both the constant class, and of | |
11430 | the classes that contain offsets into other debug sections | |
11431 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
11432 | that, if an attribute's can be either a constant or one of the | |
11433 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
11434 | taken as section offsets, not constants. */ | |
11435 | static int | |
11436 | attr_form_is_constant (struct attribute *attr) | |
11437 | { | |
11438 | switch (attr->form) | |
11439 | { | |
11440 | case DW_FORM_sdata: | |
11441 | case DW_FORM_udata: | |
11442 | case DW_FORM_data1: | |
11443 | case DW_FORM_data2: | |
11444 | case DW_FORM_data4: | |
11445 | case DW_FORM_data8: | |
11446 | return 1; | |
11447 | default: | |
11448 | return 0; | |
11449 | } | |
11450 | } | |
11451 | ||
4c2df51b DJ |
11452 | static void |
11453 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11454 | struct dwarf2_cu *cu) |
4c2df51b | 11455 | { |
3690dd37 | 11456 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
11457 | /* ".debug_loc" may not exist at all, or the offset may be outside |
11458 | the section. If so, fall through to the complaint in the | |
11459 | other branch. */ | |
dce234bc | 11460 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 11461 | { |
0d53c4c4 | 11462 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 11463 | |
4a146b47 | 11464 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11465 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
11466 | baton->per_cu = cu->per_cu; |
11467 | gdb_assert (baton->per_cu); | |
4c2df51b | 11468 | |
0d53c4c4 DJ |
11469 | /* We don't know how long the location list is, but make sure we |
11470 | don't run off the edge of the section. */ | |
dce234bc PP |
11471 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
11472 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
11473 | baton->base_address = cu->base_address; |
11474 | if (cu->base_known == 0) | |
0d53c4c4 | 11475 | complaint (&symfile_complaints, |
e2e0b3e5 | 11476 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 11477 | |
768a979c | 11478 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
11479 | SYMBOL_LOCATION_BATON (sym) = baton; |
11480 | } | |
11481 | else | |
11482 | { | |
11483 | struct dwarf2_locexpr_baton *baton; | |
11484 | ||
4a146b47 | 11485 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11486 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
11487 | baton->per_cu = cu->per_cu; |
11488 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
11489 | |
11490 | if (attr_form_is_block (attr)) | |
11491 | { | |
11492 | /* Note that we're just copying the block's data pointer | |
11493 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
11494 | info_buffer for SYM's objfile; right now we never release |
11495 | that buffer, but when we do clean up properly this may | |
11496 | need to change. */ | |
0d53c4c4 DJ |
11497 | baton->size = DW_BLOCK (attr)->size; |
11498 | baton->data = DW_BLOCK (attr)->data; | |
11499 | } | |
11500 | else | |
11501 | { | |
11502 | dwarf2_invalid_attrib_class_complaint ("location description", | |
11503 | SYMBOL_NATURAL_NAME (sym)); | |
11504 | baton->size = 0; | |
11505 | baton->data = NULL; | |
11506 | } | |
11507 | ||
768a979c | 11508 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
11509 | SYMBOL_LOCATION_BATON (sym) = baton; |
11510 | } | |
4c2df51b | 11511 | } |
6502dd73 | 11512 | |
ae0d2f24 UW |
11513 | /* Return the OBJFILE associated with the compilation unit CU. */ |
11514 | ||
11515 | struct objfile * | |
11516 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
11517 | { | |
11518 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11519 | ||
11520 | /* Return the master objfile, so that we can report and look up the | |
11521 | correct file containing this variable. */ | |
11522 | if (objfile->separate_debug_objfile_backlink) | |
11523 | objfile = objfile->separate_debug_objfile_backlink; | |
11524 | ||
11525 | return objfile; | |
11526 | } | |
11527 | ||
11528 | /* Return the address size given in the compilation unit header for CU. */ | |
11529 | ||
11530 | CORE_ADDR | |
11531 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
11532 | { | |
11533 | if (per_cu->cu) | |
11534 | return per_cu->cu->header.addr_size; | |
11535 | else | |
11536 | { | |
11537 | /* If the CU is not currently read in, we re-read its header. */ | |
11538 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11539 | struct dwarf2_per_objfile *per_objfile | |
11540 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 11541 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 UW |
11542 | |
11543 | struct comp_unit_head cu_header; | |
11544 | memset (&cu_header, 0, sizeof cu_header); | |
11545 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
11546 | return cu_header.addr_size; | |
11547 | } | |
11548 | } | |
11549 | ||
348e048f DE |
11550 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
11551 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
11552 | |
11553 | static struct dwarf2_per_cu_data * | |
c764a876 | 11554 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
11555 | struct objfile *objfile) |
11556 | { | |
11557 | struct dwarf2_per_cu_data *this_cu; | |
11558 | int low, high; | |
11559 | ||
ae038cb0 DJ |
11560 | low = 0; |
11561 | high = dwarf2_per_objfile->n_comp_units - 1; | |
11562 | while (high > low) | |
11563 | { | |
11564 | int mid = low + (high - low) / 2; | |
11565 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
11566 | high = mid; | |
11567 | else | |
11568 | low = mid + 1; | |
11569 | } | |
11570 | gdb_assert (low == high); | |
11571 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
11572 | { | |
10b3939b | 11573 | if (low == 0) |
8a3fe4f8 AC |
11574 | error (_("Dwarf Error: could not find partial DIE containing " |
11575 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
11576 | (long) offset, bfd_get_filename (objfile->obfd)); |
11577 | ||
ae038cb0 DJ |
11578 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
11579 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
11580 | } | |
11581 | else | |
11582 | { | |
11583 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
11584 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
11585 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 11586 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
11587 | gdb_assert (offset < this_cu->offset + this_cu->length); |
11588 | return this_cu; | |
11589 | } | |
11590 | } | |
11591 | ||
10b3939b DJ |
11592 | /* Locate the compilation unit from OBJFILE which is located at exactly |
11593 | OFFSET. Raises an error on failure. */ | |
11594 | ||
ae038cb0 | 11595 | static struct dwarf2_per_cu_data * |
c764a876 | 11596 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
11597 | { |
11598 | struct dwarf2_per_cu_data *this_cu; | |
11599 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
11600 | if (this_cu->offset != offset) | |
c764a876 | 11601 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
11602 | return this_cu; |
11603 | } | |
11604 | ||
93311388 DE |
11605 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
11606 | ||
11607 | static struct dwarf2_cu * | |
11608 | alloc_one_comp_unit (struct objfile *objfile) | |
11609 | { | |
11610 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
11611 | cu->objfile = objfile; | |
11612 | obstack_init (&cu->comp_unit_obstack); | |
11613 | return cu; | |
11614 | } | |
11615 | ||
ae038cb0 DJ |
11616 | /* Release one cached compilation unit, CU. We unlink it from the tree |
11617 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
11618 | the caller is responsible for that. |
11619 | NOTE: DATA is a void * because this function is also used as a | |
11620 | cleanup routine. */ | |
ae038cb0 DJ |
11621 | |
11622 | static void | |
11623 | free_one_comp_unit (void *data) | |
11624 | { | |
11625 | struct dwarf2_cu *cu = data; | |
11626 | ||
11627 | if (cu->per_cu != NULL) | |
11628 | cu->per_cu->cu = NULL; | |
11629 | cu->per_cu = NULL; | |
11630 | ||
11631 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11632 | ||
11633 | xfree (cu); | |
11634 | } | |
11635 | ||
72bf9492 | 11636 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
11637 | when we're finished with it. We can't free the pointer itself, but be |
11638 | sure to unlink it from the cache. Also release any associated storage | |
11639 | and perform cache maintenance. | |
72bf9492 DJ |
11640 | |
11641 | Only used during partial symbol parsing. */ | |
11642 | ||
11643 | static void | |
11644 | free_stack_comp_unit (void *data) | |
11645 | { | |
11646 | struct dwarf2_cu *cu = data; | |
11647 | ||
11648 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11649 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
11650 | |
11651 | if (cu->per_cu != NULL) | |
11652 | { | |
11653 | /* This compilation unit is on the stack in our caller, so we | |
11654 | should not xfree it. Just unlink it. */ | |
11655 | cu->per_cu->cu = NULL; | |
11656 | cu->per_cu = NULL; | |
11657 | ||
11658 | /* If we had a per-cu pointer, then we may have other compilation | |
11659 | units loaded, so age them now. */ | |
11660 | age_cached_comp_units (); | |
11661 | } | |
11662 | } | |
11663 | ||
11664 | /* Free all cached compilation units. */ | |
11665 | ||
11666 | static void | |
11667 | free_cached_comp_units (void *data) | |
11668 | { | |
11669 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11670 | ||
11671 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11672 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11673 | while (per_cu != NULL) | |
11674 | { | |
11675 | struct dwarf2_per_cu_data *next_cu; | |
11676 | ||
11677 | next_cu = per_cu->cu->read_in_chain; | |
11678 | ||
11679 | free_one_comp_unit (per_cu->cu); | |
11680 | *last_chain = next_cu; | |
11681 | ||
11682 | per_cu = next_cu; | |
11683 | } | |
11684 | } | |
11685 | ||
11686 | /* Increase the age counter on each cached compilation unit, and free | |
11687 | any that are too old. */ | |
11688 | ||
11689 | static void | |
11690 | age_cached_comp_units (void) | |
11691 | { | |
11692 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11693 | ||
11694 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
11695 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11696 | while (per_cu != NULL) | |
11697 | { | |
11698 | per_cu->cu->last_used ++; | |
11699 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
11700 | dwarf2_mark (per_cu->cu); | |
11701 | per_cu = per_cu->cu->read_in_chain; | |
11702 | } | |
11703 | ||
11704 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11705 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11706 | while (per_cu != NULL) | |
11707 | { | |
11708 | struct dwarf2_per_cu_data *next_cu; | |
11709 | ||
11710 | next_cu = per_cu->cu->read_in_chain; | |
11711 | ||
11712 | if (!per_cu->cu->mark) | |
11713 | { | |
11714 | free_one_comp_unit (per_cu->cu); | |
11715 | *last_chain = next_cu; | |
11716 | } | |
11717 | else | |
11718 | last_chain = &per_cu->cu->read_in_chain; | |
11719 | ||
11720 | per_cu = next_cu; | |
11721 | } | |
11722 | } | |
11723 | ||
11724 | /* Remove a single compilation unit from the cache. */ | |
11725 | ||
11726 | static void | |
11727 | free_one_cached_comp_unit (void *target_cu) | |
11728 | { | |
11729 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11730 | ||
11731 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11732 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11733 | while (per_cu != NULL) | |
11734 | { | |
11735 | struct dwarf2_per_cu_data *next_cu; | |
11736 | ||
11737 | next_cu = per_cu->cu->read_in_chain; | |
11738 | ||
11739 | if (per_cu->cu == target_cu) | |
11740 | { | |
11741 | free_one_comp_unit (per_cu->cu); | |
11742 | *last_chain = next_cu; | |
11743 | break; | |
11744 | } | |
11745 | else | |
11746 | last_chain = &per_cu->cu->read_in_chain; | |
11747 | ||
11748 | per_cu = next_cu; | |
11749 | } | |
11750 | } | |
11751 | ||
fe3e1990 DJ |
11752 | /* Release all extra memory associated with OBJFILE. */ |
11753 | ||
11754 | void | |
11755 | dwarf2_free_objfile (struct objfile *objfile) | |
11756 | { | |
11757 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
11758 | ||
11759 | if (dwarf2_per_objfile == NULL) | |
11760 | return; | |
11761 | ||
11762 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
11763 | free_cached_comp_units (NULL); | |
11764 | ||
11765 | /* Everything else should be on the objfile obstack. */ | |
11766 | } | |
11767 | ||
1c379e20 DJ |
11768 | /* A pair of DIE offset and GDB type pointer. We store these |
11769 | in a hash table separate from the DIEs, and preserve them | |
11770 | when the DIEs are flushed out of cache. */ | |
11771 | ||
11772 | struct dwarf2_offset_and_type | |
11773 | { | |
11774 | unsigned int offset; | |
11775 | struct type *type; | |
11776 | }; | |
11777 | ||
11778 | /* Hash function for a dwarf2_offset_and_type. */ | |
11779 | ||
11780 | static hashval_t | |
11781 | offset_and_type_hash (const void *item) | |
11782 | { | |
11783 | const struct dwarf2_offset_and_type *ofs = item; | |
11784 | return ofs->offset; | |
11785 | } | |
11786 | ||
11787 | /* Equality function for a dwarf2_offset_and_type. */ | |
11788 | ||
11789 | static int | |
11790 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
11791 | { | |
11792 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
11793 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
11794 | return ofs_lhs->offset == ofs_rhs->offset; | |
11795 | } | |
11796 | ||
11797 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 11798 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 11799 | |
f792889a | 11800 | static struct type * |
1c379e20 DJ |
11801 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
11802 | { | |
11803 | struct dwarf2_offset_and_type **slot, ofs; | |
11804 | ||
b4ba55a1 JB |
11805 | /* For Ada types, make sure that the gnat-specific data is always |
11806 | initialized (if not already set). There are a few types where | |
11807 | we should not be doing so, because the type-specific area is | |
11808 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
11809 | where the type-specific area is used to store the floatformat). | |
11810 | But this is not a problem, because the gnat-specific information | |
11811 | is actually not needed for these types. */ | |
11812 | if (need_gnat_info (cu) | |
11813 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
11814 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
11815 | && !HAVE_GNAT_AUX_INFO (type)) | |
11816 | INIT_GNAT_SPECIFIC (type); | |
11817 | ||
f792889a DJ |
11818 | if (cu->type_hash == NULL) |
11819 | { | |
11820 | gdb_assert (cu->per_cu != NULL); | |
11821 | cu->per_cu->type_hash | |
11822 | = htab_create_alloc_ex (cu->header.length / 24, | |
11823 | offset_and_type_hash, | |
11824 | offset_and_type_eq, | |
11825 | NULL, | |
11826 | &cu->objfile->objfile_obstack, | |
11827 | hashtab_obstack_allocate, | |
11828 | dummy_obstack_deallocate); | |
11829 | cu->type_hash = cu->per_cu->type_hash; | |
11830 | } | |
1c379e20 DJ |
11831 | |
11832 | ofs.offset = die->offset; | |
11833 | ofs.type = type; | |
11834 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 11835 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
11836 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
11837 | **slot = ofs; | |
f792889a | 11838 | return type; |
1c379e20 DJ |
11839 | } |
11840 | ||
f792889a DJ |
11841 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
11842 | not have a saved type. */ | |
1c379e20 DJ |
11843 | |
11844 | static struct type * | |
f792889a | 11845 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
11846 | { |
11847 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
11848 | htab_t type_hash = cu->type_hash; |
11849 | ||
11850 | if (type_hash == NULL) | |
11851 | return NULL; | |
1c379e20 DJ |
11852 | |
11853 | ofs.offset = die->offset; | |
11854 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
11855 | if (slot) | |
11856 | return slot->type; | |
11857 | else | |
11858 | return NULL; | |
11859 | } | |
11860 | ||
10b3939b DJ |
11861 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
11862 | ||
11863 | static void | |
11864 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
11865 | struct dwarf2_per_cu_data *ref_per_cu) | |
11866 | { | |
11867 | void **slot; | |
11868 | ||
11869 | if (cu->dependencies == NULL) | |
11870 | cu->dependencies | |
11871 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
11872 | NULL, &cu->comp_unit_obstack, | |
11873 | hashtab_obstack_allocate, | |
11874 | dummy_obstack_deallocate); | |
11875 | ||
11876 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
11877 | if (*slot == NULL) | |
11878 | *slot = ref_per_cu; | |
11879 | } | |
1c379e20 | 11880 | |
f504f079 DE |
11881 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
11882 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
11883 | cache that we must keep because we are keeping CU. */ |
11884 | ||
10b3939b DJ |
11885 | static int |
11886 | dwarf2_mark_helper (void **slot, void *data) | |
11887 | { | |
11888 | struct dwarf2_per_cu_data *per_cu; | |
11889 | ||
11890 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
11891 | if (per_cu->cu->mark) | |
11892 | return 1; | |
11893 | per_cu->cu->mark = 1; | |
11894 | ||
11895 | if (per_cu->cu->dependencies != NULL) | |
11896 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
11897 | ||
11898 | return 1; | |
11899 | } | |
11900 | ||
f504f079 DE |
11901 | /* Set the mark field in CU and in every other compilation unit in the |
11902 | cache that we must keep because we are keeping CU. */ | |
11903 | ||
ae038cb0 DJ |
11904 | static void |
11905 | dwarf2_mark (struct dwarf2_cu *cu) | |
11906 | { | |
11907 | if (cu->mark) | |
11908 | return; | |
11909 | cu->mark = 1; | |
10b3939b DJ |
11910 | if (cu->dependencies != NULL) |
11911 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
11912 | } |
11913 | ||
11914 | static void | |
11915 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
11916 | { | |
11917 | while (per_cu) | |
11918 | { | |
11919 | per_cu->cu->mark = 0; | |
11920 | per_cu = per_cu->cu->read_in_chain; | |
11921 | } | |
72bf9492 DJ |
11922 | } |
11923 | ||
72bf9492 DJ |
11924 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
11925 | is its offset in .debug_info for this objfile. */ | |
11926 | ||
11927 | static hashval_t | |
11928 | partial_die_hash (const void *item) | |
11929 | { | |
11930 | const struct partial_die_info *part_die = item; | |
11931 | return part_die->offset; | |
11932 | } | |
11933 | ||
11934 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
11935 | are equal if they have the same offset. */ | |
11936 | ||
11937 | static int | |
11938 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
11939 | { | |
11940 | const struct partial_die_info *part_die_lhs = item_lhs; | |
11941 | const struct partial_die_info *part_die_rhs = item_rhs; | |
11942 | return part_die_lhs->offset == part_die_rhs->offset; | |
11943 | } | |
11944 | ||
ae038cb0 DJ |
11945 | static struct cmd_list_element *set_dwarf2_cmdlist; |
11946 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
11947 | ||
11948 | static void | |
11949 | set_dwarf2_cmd (char *args, int from_tty) | |
11950 | { | |
11951 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
11952 | } | |
11953 | ||
11954 | static void | |
11955 | show_dwarf2_cmd (char *args, int from_tty) | |
11956 | { | |
11957 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
11958 | } | |
11959 | ||
dce234bc PP |
11960 | /* If section described by INFO was mmapped, munmap it now. */ |
11961 | ||
11962 | static void | |
11963 | munmap_section_buffer (struct dwarf2_section_info *info) | |
11964 | { | |
11965 | if (info->was_mmapped) | |
11966 | { | |
11967 | #ifdef HAVE_MMAP | |
11968 | intptr_t begin = (intptr_t) info->buffer; | |
11969 | intptr_t map_begin = begin & ~(pagesize - 1); | |
11970 | size_t map_length = info->size + begin - map_begin; | |
11971 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); | |
11972 | #else | |
11973 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
11974 | gdb_assert (0); | |
11975 | #endif | |
11976 | } | |
11977 | } | |
11978 | ||
11979 | /* munmap debug sections for OBJFILE, if necessary. */ | |
11980 | ||
11981 | static void | |
c1bd65d0 | 11982 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
11983 | { |
11984 | struct dwarf2_per_objfile *data = d; | |
11985 | munmap_section_buffer (&data->info); | |
11986 | munmap_section_buffer (&data->abbrev); | |
11987 | munmap_section_buffer (&data->line); | |
11988 | munmap_section_buffer (&data->str); | |
11989 | munmap_section_buffer (&data->macinfo); | |
11990 | munmap_section_buffer (&data->ranges); | |
11991 | munmap_section_buffer (&data->loc); | |
11992 | munmap_section_buffer (&data->frame); | |
11993 | munmap_section_buffer (&data->eh_frame); | |
11994 | } | |
11995 | ||
6502dd73 DJ |
11996 | void _initialize_dwarf2_read (void); |
11997 | ||
11998 | void | |
11999 | _initialize_dwarf2_read (void) | |
12000 | { | |
dce234bc | 12001 | dwarf2_objfile_data_key |
c1bd65d0 | 12002 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 12003 | |
1bedd215 AC |
12004 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
12005 | Set DWARF 2 specific variables.\n\ | |
12006 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
12007 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
12008 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
12009 | ||
1bedd215 AC |
12010 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
12011 | Show DWARF 2 specific variables\n\ | |
12012 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
12013 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
12014 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
12015 | ||
12016 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
12017 | &dwarf2_max_cache_age, _("\ |
12018 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
12019 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
12020 | A higher limit means that cached compilation units will be stored\n\ | |
12021 | in memory longer, and more total memory will be used. Zero disables\n\ | |
12022 | caching, which can slow down startup."), | |
2c5b56ce | 12023 | NULL, |
920d2a44 | 12024 | show_dwarf2_max_cache_age, |
2c5b56ce | 12025 | &set_dwarf2_cmdlist, |
ae038cb0 | 12026 | &show_dwarf2_cmdlist); |
d97bc12b DE |
12027 | |
12028 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ | |
12029 | Set debugging of the dwarf2 DIE reader."), _("\ | |
12030 | Show debugging of the dwarf2 DIE reader."), _("\ | |
12031 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
12032 | The value is the maximum depth to print."), | |
12033 | NULL, | |
12034 | NULL, | |
12035 | &setdebuglist, &showdebuglist); | |
6502dd73 | 12036 | } |