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 |
ceeb3d5a TT |
2389 | || parent->tag == DW_TAG_union_type |
2390 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
2391 | { |
2392 | if (grandparent_scope == NULL) | |
2393 | parent->scope = parent->name; | |
2394 | else | |
987504bb JJ |
2395 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
2396 | parent->name, cu); | |
72bf9492 | 2397 | } |
ceeb3d5a | 2398 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
2399 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
2400 | parent->scope = grandparent_scope; | |
2401 | else | |
2402 | { | |
2403 | /* FIXME drow/2004-04-01: What should we be doing with | |
2404 | function-local names? For partial symbols, we should probably be | |
2405 | ignoring them. */ | |
2406 | complaint (&symfile_complaints, | |
e2e0b3e5 | 2407 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
2408 | parent->tag, pdi->offset); |
2409 | parent->scope = grandparent_scope; | |
c906108c SS |
2410 | } |
2411 | ||
72bf9492 DJ |
2412 | parent->scope_set = 1; |
2413 | return parent->scope; | |
2414 | } | |
2415 | ||
2416 | /* Return the fully scoped name associated with PDI, from compilation unit | |
2417 | CU. The result will be allocated with malloc. */ | |
2418 | static char * | |
2419 | partial_die_full_name (struct partial_die_info *pdi, | |
2420 | struct dwarf2_cu *cu) | |
2421 | { | |
2422 | char *parent_scope; | |
2423 | ||
2424 | parent_scope = partial_die_parent_scope (pdi, cu); | |
2425 | if (parent_scope == NULL) | |
2426 | return NULL; | |
2427 | else | |
987504bb | 2428 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
2429 | } |
2430 | ||
2431 | static void | |
72bf9492 | 2432 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 2433 | { |
e7c27a73 | 2434 | struct objfile *objfile = cu->objfile; |
c906108c | 2435 | CORE_ADDR addr = 0; |
decbce07 | 2436 | char *actual_name = NULL; |
72bf9492 | 2437 | const char *my_prefix; |
5c4e30ca | 2438 | const struct partial_symbol *psym = NULL; |
e142c38c | 2439 | CORE_ADDR baseaddr; |
72bf9492 | 2440 | int built_actual_name = 0; |
e142c38c DJ |
2441 | |
2442 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2443 | |
72bf9492 | 2444 | if (pdi_needs_namespace (pdi->tag)) |
63d06c5c | 2445 | { |
72bf9492 DJ |
2446 | actual_name = partial_die_full_name (pdi, cu); |
2447 | if (actual_name) | |
2448 | built_actual_name = 1; | |
63d06c5c DC |
2449 | } |
2450 | ||
72bf9492 DJ |
2451 | if (actual_name == NULL) |
2452 | actual_name = pdi->name; | |
2453 | ||
c906108c SS |
2454 | switch (pdi->tag) |
2455 | { | |
2456 | case DW_TAG_subprogram: | |
2cfa0c8d | 2457 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 2458 | { |
2cfa0c8d JB |
2459 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
2460 | of the global scope. But in Ada, we want to be able to access | |
2461 | nested procedures globally. So all Ada subprograms are stored | |
2462 | in the global scope. */ | |
38d518c9 | 2463 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2464 | mst_text, objfile); */ |
38d518c9 | 2465 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2466 | built_actual_name, |
5c4e30ca DC |
2467 | VAR_DOMAIN, LOC_BLOCK, |
2468 | &objfile->global_psymbols, | |
2469 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2470 | cu->language, objfile); |
c906108c SS |
2471 | } |
2472 | else | |
2473 | { | |
38d518c9 | 2474 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2475 | mst_file_text, objfile); */ |
38d518c9 | 2476 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2477 | built_actual_name, |
5c4e30ca DC |
2478 | VAR_DOMAIN, LOC_BLOCK, |
2479 | &objfile->static_psymbols, | |
2480 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2481 | cu->language, objfile); |
c906108c SS |
2482 | } |
2483 | break; | |
2484 | case DW_TAG_variable: | |
2485 | if (pdi->is_external) | |
2486 | { | |
2487 | /* Global Variable. | |
2488 | Don't enter into the minimal symbol tables as there is | |
2489 | a minimal symbol table entry from the ELF symbols already. | |
2490 | Enter into partial symbol table if it has a location | |
2491 | descriptor or a type. | |
2492 | If the location descriptor is missing, new_symbol will create | |
2493 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
2494 | be determined from the minimal symbol table whenever the variable | |
2495 | is referenced. | |
2496 | The address for the partial symbol table entry is not | |
2497 | used by GDB, but it comes in handy for debugging partial symbol | |
2498 | table building. */ | |
2499 | ||
2500 | if (pdi->locdesc) | |
e7c27a73 | 2501 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2502 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2503 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2504 | built_actual_name, |
5c4e30ca DC |
2505 | VAR_DOMAIN, LOC_STATIC, |
2506 | &objfile->global_psymbols, | |
2507 | 0, addr + baseaddr, | |
e142c38c | 2508 | cu->language, objfile); |
c906108c SS |
2509 | } |
2510 | else | |
2511 | { | |
2512 | /* Static Variable. Skip symbols without location descriptors. */ | |
2513 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2514 | { |
2515 | if (built_actual_name) | |
2516 | xfree (actual_name); | |
2517 | return; | |
2518 | } | |
e7c27a73 | 2519 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2520 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2521 | mst_file_data, objfile); */ |
38d518c9 | 2522 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2523 | built_actual_name, |
5c4e30ca DC |
2524 | VAR_DOMAIN, LOC_STATIC, |
2525 | &objfile->static_psymbols, | |
2526 | 0, addr + baseaddr, | |
e142c38c | 2527 | cu->language, objfile); |
c906108c SS |
2528 | } |
2529 | break; | |
2530 | case DW_TAG_typedef: | |
2531 | case DW_TAG_base_type: | |
a02abb62 | 2532 | case DW_TAG_subrange_type: |
38d518c9 | 2533 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2534 | built_actual_name, |
176620f1 | 2535 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2536 | &objfile->static_psymbols, |
e142c38c | 2537 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2538 | break; |
72bf9492 DJ |
2539 | case DW_TAG_namespace: |
2540 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 2541 | built_actual_name, |
72bf9492 DJ |
2542 | VAR_DOMAIN, LOC_TYPEDEF, |
2543 | &objfile->global_psymbols, | |
2544 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2545 | break; | |
c906108c | 2546 | case DW_TAG_class_type: |
680b30c7 | 2547 | case DW_TAG_interface_type: |
c906108c SS |
2548 | case DW_TAG_structure_type: |
2549 | case DW_TAG_union_type: | |
2550 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2551 | /* Skip external references. The DWARF standard says in the section |
2552 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2553 | structure, union or class type is represented by a structure, | |
2554 | union or class entry that does not have a byte size attribute | |
2555 | and that has a DW_AT_declaration attribute." */ | |
2556 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2557 | { |
2558 | if (built_actual_name) | |
2559 | xfree (actual_name); | |
2560 | return; | |
2561 | } | |
fa4028e9 | 2562 | |
63d06c5c DC |
2563 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2564 | static vs. global. */ | |
38d518c9 | 2565 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2566 | built_actual_name, |
176620f1 | 2567 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2568 | (cu->language == language_cplus |
2569 | || cu->language == language_java) | |
63d06c5c DC |
2570 | ? &objfile->global_psymbols |
2571 | : &objfile->static_psymbols, | |
e142c38c | 2572 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2573 | |
c906108c SS |
2574 | break; |
2575 | case DW_TAG_enumerator: | |
38d518c9 | 2576 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 2577 | built_actual_name, |
176620f1 | 2578 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2579 | (cu->language == language_cplus |
2580 | || cu->language == language_java) | |
f6fe98ef DJ |
2581 | ? &objfile->global_psymbols |
2582 | : &objfile->static_psymbols, | |
e142c38c | 2583 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2584 | break; |
2585 | default: | |
2586 | break; | |
2587 | } | |
5c4e30ca DC |
2588 | |
2589 | /* Check to see if we should scan the name for possible namespace | |
2590 | info. Only do this if this is C++, if we don't have namespace | |
2591 | debugging info in the file, if the psym is of an appropriate type | |
2592 | (otherwise we'll have psym == NULL), and if we actually had a | |
2593 | mangled name to begin with. */ | |
2594 | ||
72bf9492 DJ |
2595 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2596 | cases which do not set PSYM above? */ | |
2597 | ||
e142c38c | 2598 | if (cu->language == language_cplus |
72bf9492 | 2599 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2600 | && psym != NULL |
2601 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2602 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2603 | objfile); | |
72bf9492 DJ |
2604 | |
2605 | if (built_actual_name) | |
2606 | xfree (actual_name); | |
c906108c SS |
2607 | } |
2608 | ||
72bf9492 DJ |
2609 | /* Determine whether a die of type TAG living in a C++ class or |
2610 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2611 | name listed in the die. */ |
2612 | ||
2613 | static int | |
72bf9492 | 2614 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2615 | { |
63d06c5c DC |
2616 | switch (tag) |
2617 | { | |
72bf9492 | 2618 | case DW_TAG_namespace: |
63d06c5c DC |
2619 | case DW_TAG_typedef: |
2620 | case DW_TAG_class_type: | |
680b30c7 | 2621 | case DW_TAG_interface_type: |
63d06c5c DC |
2622 | case DW_TAG_structure_type: |
2623 | case DW_TAG_union_type: | |
2624 | case DW_TAG_enumeration_type: | |
2625 | case DW_TAG_enumerator: | |
2626 | return 1; | |
2627 | default: | |
2628 | return 0; | |
2629 | } | |
2630 | } | |
2631 | ||
5c4e30ca DC |
2632 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2633 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2634 | the name of the enclosing namespace. */ | |
91c24f0a | 2635 | |
72bf9492 DJ |
2636 | static void |
2637 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2638 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 2639 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 2640 | { |
e7c27a73 | 2641 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2642 | |
72bf9492 | 2643 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2644 | |
72bf9492 | 2645 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2646 | |
2647 | /* Now scan partial symbols in that namespace. */ | |
2648 | ||
91c24f0a | 2649 | if (pdi->has_children) |
5734ee8b | 2650 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
2651 | } |
2652 | ||
5d7cb8df JK |
2653 | /* Read a partial die corresponding to a Fortran module. */ |
2654 | ||
2655 | static void | |
2656 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
2657 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
2658 | { | |
2659 | /* Now scan partial symbols in that module. | |
2660 | ||
2661 | FIXME: Support the separate Fortran module namespaces. */ | |
2662 | ||
2663 | if (pdi->has_children) | |
2664 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
2665 | } | |
2666 | ||
bc30ff58 JB |
2667 | /* Read a partial die corresponding to a subprogram and create a partial |
2668 | symbol for that subprogram. When the CU language allows it, this | |
2669 | routine also defines a partial symbol for each nested subprogram | |
2670 | that this subprogram contains. | |
2671 | ||
2672 | DIE my also be a lexical block, in which case we simply search | |
2673 | recursively for suprograms defined inside that lexical block. | |
2674 | Again, this is only performed when the CU language allows this | |
2675 | type of definitions. */ | |
2676 | ||
2677 | static void | |
2678 | add_partial_subprogram (struct partial_die_info *pdi, | |
2679 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 2680 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
2681 | { |
2682 | if (pdi->tag == DW_TAG_subprogram) | |
2683 | { | |
2684 | if (pdi->has_pc_info) | |
2685 | { | |
2686 | if (pdi->lowpc < *lowpc) | |
2687 | *lowpc = pdi->lowpc; | |
2688 | if (pdi->highpc > *highpc) | |
2689 | *highpc = pdi->highpc; | |
5734ee8b DJ |
2690 | if (need_pc) |
2691 | { | |
2692 | CORE_ADDR baseaddr; | |
2693 | struct objfile *objfile = cu->objfile; | |
2694 | ||
2695 | baseaddr = ANOFFSET (objfile->section_offsets, | |
2696 | SECT_OFF_TEXT (objfile)); | |
2697 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
2698 | pdi->lowpc, pdi->highpc - 1, | |
2699 | cu->per_cu->psymtab); | |
2700 | } | |
bc30ff58 JB |
2701 | if (!pdi->is_declaration) |
2702 | add_partial_symbol (pdi, cu); | |
2703 | } | |
2704 | } | |
2705 | ||
2706 | if (! pdi->has_children) | |
2707 | return; | |
2708 | ||
2709 | if (cu->language == language_ada) | |
2710 | { | |
2711 | pdi = pdi->die_child; | |
2712 | while (pdi != NULL) | |
2713 | { | |
2714 | fixup_partial_die (pdi, cu); | |
2715 | if (pdi->tag == DW_TAG_subprogram | |
2716 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 2717 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
2718 | pdi = pdi->die_sibling; |
2719 | } | |
2720 | } | |
2721 | } | |
2722 | ||
72bf9492 DJ |
2723 | /* See if we can figure out if the class lives in a namespace. We do |
2724 | this by looking for a member function; its demangled name will | |
2725 | contain namespace info, if there is any. */ | |
63d06c5c | 2726 | |
72bf9492 DJ |
2727 | static void |
2728 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2729 | struct dwarf2_cu *cu) | |
63d06c5c | 2730 | { |
987504bb JJ |
2731 | if ((cu->language == language_cplus |
2732 | || cu->language == language_java) | |
72bf9492 | 2733 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2734 | && struct_pdi->has_children) |
2735 | { | |
63d06c5c DC |
2736 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2737 | what template types look like, because the demangler | |
2738 | frequently doesn't give the same name as the debug info. We | |
2739 | could fix this by only using the demangled name to get the | |
134d01f1 | 2740 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2741 | |
72bf9492 DJ |
2742 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2743 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2744 | |
72bf9492 DJ |
2745 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2746 | we should not do this. We'll prepend the parent's fully qualified | |
2747 | name when we create the partial symbol. */ | |
5d51ca54 | 2748 | |
72bf9492 | 2749 | real_pdi = struct_pdi; |
72bf9492 | 2750 | while (real_pdi->has_specification) |
10b3939b | 2751 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2752 | |
72bf9492 DJ |
2753 | if (real_pdi->die_parent != NULL) |
2754 | return; | |
63d06c5c | 2755 | |
72bf9492 DJ |
2756 | while (child_pdi != NULL) |
2757 | { | |
2758 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2759 | { |
72bf9492 | 2760 | char *actual_class_name |
31c27f77 JJ |
2761 | = language_class_name_from_physname (cu->language_defn, |
2762 | child_pdi->name); | |
63d06c5c | 2763 | if (actual_class_name != NULL) |
72bf9492 DJ |
2764 | { |
2765 | struct_pdi->name | |
2766 | = obsavestring (actual_class_name, | |
2767 | strlen (actual_class_name), | |
2768 | &cu->comp_unit_obstack); | |
2769 | xfree (actual_class_name); | |
2770 | } | |
63d06c5c DC |
2771 | break; |
2772 | } | |
72bf9492 DJ |
2773 | |
2774 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2775 | } |
2776 | } | |
63d06c5c DC |
2777 | } |
2778 | ||
91c24f0a DC |
2779 | /* Read a partial die corresponding to an enumeration type. */ |
2780 | ||
72bf9492 DJ |
2781 | static void |
2782 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2783 | struct dwarf2_cu *cu) | |
91c24f0a | 2784 | { |
e7c27a73 | 2785 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2786 | bfd *abfd = objfile->obfd; |
72bf9492 | 2787 | struct partial_die_info *pdi; |
91c24f0a DC |
2788 | |
2789 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2790 | add_partial_symbol (enum_pdi, cu); |
2791 | ||
2792 | pdi = enum_pdi->die_child; | |
2793 | while (pdi) | |
91c24f0a | 2794 | { |
72bf9492 | 2795 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2796 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2797 | else |
72bf9492 DJ |
2798 | add_partial_symbol (pdi, cu); |
2799 | pdi = pdi->die_sibling; | |
91c24f0a | 2800 | } |
91c24f0a DC |
2801 | } |
2802 | ||
4bb7a0a7 DJ |
2803 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2804 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2805 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2806 | the initial number. */ | |
2807 | ||
2808 | static struct abbrev_info * | |
fe1b8b76 | 2809 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2810 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2811 | { |
2812 | bfd *abfd = cu->objfile->obfd; | |
2813 | unsigned int abbrev_number; | |
2814 | struct abbrev_info *abbrev; | |
2815 | ||
2816 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2817 | ||
2818 | if (abbrev_number == 0) | |
2819 | return NULL; | |
2820 | ||
2821 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2822 | if (!abbrev) | |
2823 | { | |
8a3fe4f8 | 2824 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2825 | bfd_get_filename (abfd)); |
2826 | } | |
2827 | ||
2828 | return abbrev; | |
2829 | } | |
2830 | ||
93311388 DE |
2831 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2832 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
2833 | DIE. Any children of the skipped DIEs will also be skipped. */ |
2834 | ||
fe1b8b76 | 2835 | static gdb_byte * |
93311388 | 2836 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2837 | { |
2838 | struct abbrev_info *abbrev; | |
2839 | unsigned int bytes_read; | |
2840 | ||
2841 | while (1) | |
2842 | { | |
2843 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2844 | if (abbrev == NULL) | |
2845 | return info_ptr + bytes_read; | |
2846 | else | |
93311388 | 2847 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
2848 | } |
2849 | } | |
2850 | ||
93311388 DE |
2851 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
2852 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
2853 | abbrev corresponding to that skipped uleb128 should be passed in |
2854 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2855 | children. */ | |
2856 | ||
fe1b8b76 | 2857 | static gdb_byte * |
93311388 DE |
2858 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
2859 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2860 | { |
2861 | unsigned int bytes_read; | |
2862 | struct attribute attr; | |
2863 | bfd *abfd = cu->objfile->obfd; | |
2864 | unsigned int form, i; | |
2865 | ||
2866 | for (i = 0; i < abbrev->num_attrs; i++) | |
2867 | { | |
2868 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2869 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2870 | { | |
2871 | read_attribute (&attr, &abbrev->attrs[i], | |
2872 | abfd, info_ptr, cu); | |
2873 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2874 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2875 | else |
93311388 | 2876 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
2877 | } |
2878 | ||
2879 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2880 | form = abbrev->attrs[i].form; | |
2881 | skip_attribute: | |
2882 | switch (form) | |
2883 | { | |
2884 | case DW_FORM_addr: | |
2885 | case DW_FORM_ref_addr: | |
2886 | info_ptr += cu->header.addr_size; | |
2887 | break; | |
2888 | case DW_FORM_data1: | |
2889 | case DW_FORM_ref1: | |
2890 | case DW_FORM_flag: | |
2891 | info_ptr += 1; | |
2892 | break; | |
2893 | case DW_FORM_data2: | |
2894 | case DW_FORM_ref2: | |
2895 | info_ptr += 2; | |
2896 | break; | |
2897 | case DW_FORM_data4: | |
2898 | case DW_FORM_ref4: | |
2899 | info_ptr += 4; | |
2900 | break; | |
2901 | case DW_FORM_data8: | |
2902 | case DW_FORM_ref8: | |
348e048f | 2903 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
2904 | info_ptr += 8; |
2905 | break; | |
2906 | case DW_FORM_string: | |
2907 | read_string (abfd, info_ptr, &bytes_read); | |
2908 | info_ptr += bytes_read; | |
2909 | break; | |
2910 | case DW_FORM_strp: | |
2911 | info_ptr += cu->header.offset_size; | |
2912 | break; | |
2913 | case DW_FORM_block: | |
2914 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2915 | info_ptr += bytes_read; | |
2916 | break; | |
2917 | case DW_FORM_block1: | |
2918 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2919 | break; | |
2920 | case DW_FORM_block2: | |
2921 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2922 | break; | |
2923 | case DW_FORM_block4: | |
2924 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2925 | break; | |
2926 | case DW_FORM_sdata: | |
2927 | case DW_FORM_udata: | |
2928 | case DW_FORM_ref_udata: | |
2929 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2930 | break; | |
2931 | case DW_FORM_indirect: | |
2932 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2933 | info_ptr += bytes_read; | |
2934 | /* We need to continue parsing from here, so just go back to | |
2935 | the top. */ | |
2936 | goto skip_attribute; | |
2937 | ||
2938 | default: | |
8a3fe4f8 | 2939 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2940 | dwarf_form_name (form), |
2941 | bfd_get_filename (abfd)); | |
2942 | } | |
2943 | } | |
2944 | ||
2945 | if (abbrev->has_children) | |
93311388 | 2946 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
2947 | else |
2948 | return info_ptr; | |
2949 | } | |
2950 | ||
93311388 DE |
2951 | /* Locate ORIG_PDI's sibling. |
2952 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
2953 | in BUFFER. */ | |
91c24f0a | 2954 | |
fe1b8b76 | 2955 | static gdb_byte * |
93311388 DE |
2956 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
2957 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 2958 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2959 | { |
2960 | /* Do we know the sibling already? */ | |
72bf9492 | 2961 | |
91c24f0a DC |
2962 | if (orig_pdi->sibling) |
2963 | return orig_pdi->sibling; | |
2964 | ||
2965 | /* Are there any children to deal with? */ | |
2966 | ||
2967 | if (!orig_pdi->has_children) | |
2968 | return info_ptr; | |
2969 | ||
4bb7a0a7 | 2970 | /* Skip the children the long way. */ |
91c24f0a | 2971 | |
93311388 | 2972 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
2973 | } |
2974 | ||
c906108c SS |
2975 | /* Expand this partial symbol table into a full symbol table. */ |
2976 | ||
2977 | static void | |
fba45db2 | 2978 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2979 | { |
2980 | /* FIXME: This is barely more than a stub. */ | |
2981 | if (pst != NULL) | |
2982 | { | |
2983 | if (pst->readin) | |
2984 | { | |
8a3fe4f8 | 2985 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2986 | } |
2987 | else | |
2988 | { | |
2989 | if (info_verbose) | |
2990 | { | |
a3f17187 | 2991 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2992 | gdb_flush (gdb_stdout); |
2993 | } | |
2994 | ||
10b3939b DJ |
2995 | /* Restore our global data. */ |
2996 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2997 | dwarf2_objfile_data_key); | |
2998 | ||
b2ab525c KB |
2999 | /* If this psymtab is constructed from a debug-only objfile, the |
3000 | has_section_at_zero flag will not necessarily be correct. We | |
3001 | can get the correct value for this flag by looking at the data | |
3002 | associated with the (presumably stripped) associated objfile. */ | |
3003 | if (pst->objfile->separate_debug_objfile_backlink) | |
3004 | { | |
3005 | struct dwarf2_per_objfile *dpo_backlink | |
3006 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
3007 | dwarf2_objfile_data_key); | |
3008 | dwarf2_per_objfile->has_section_at_zero | |
3009 | = dpo_backlink->has_section_at_zero; | |
3010 | } | |
3011 | ||
c906108c SS |
3012 | psymtab_to_symtab_1 (pst); |
3013 | ||
3014 | /* Finish up the debug error message. */ | |
3015 | if (info_verbose) | |
a3f17187 | 3016 | printf_filtered (_("done.\n")); |
c906108c SS |
3017 | } |
3018 | } | |
3019 | } | |
3020 | ||
10b3939b DJ |
3021 | /* Add PER_CU to the queue. */ |
3022 | ||
3023 | static void | |
03dd20cc | 3024 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
3025 | { |
3026 | struct dwarf2_queue_item *item; | |
3027 | ||
3028 | per_cu->queued = 1; | |
3029 | item = xmalloc (sizeof (*item)); | |
3030 | item->per_cu = per_cu; | |
3031 | item->next = NULL; | |
3032 | ||
3033 | if (dwarf2_queue == NULL) | |
3034 | dwarf2_queue = item; | |
3035 | else | |
3036 | dwarf2_queue_tail->next = item; | |
3037 | ||
3038 | dwarf2_queue_tail = item; | |
3039 | } | |
3040 | ||
3041 | /* Process the queue. */ | |
3042 | ||
3043 | static void | |
3044 | process_queue (struct objfile *objfile) | |
3045 | { | |
3046 | struct dwarf2_queue_item *item, *next_item; | |
3047 | ||
03dd20cc DJ |
3048 | /* The queue starts out with one item, but following a DIE reference |
3049 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
3050 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
3051 | { | |
31ffec48 | 3052 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
3053 | process_full_comp_unit (item->per_cu); |
3054 | ||
3055 | item->per_cu->queued = 0; | |
3056 | next_item = item->next; | |
3057 | xfree (item); | |
3058 | } | |
3059 | ||
3060 | dwarf2_queue_tail = NULL; | |
3061 | } | |
3062 | ||
3063 | /* Free all allocated queue entries. This function only releases anything if | |
3064 | an error was thrown; if the queue was processed then it would have been | |
3065 | freed as we went along. */ | |
3066 | ||
3067 | static void | |
3068 | dwarf2_release_queue (void *dummy) | |
3069 | { | |
3070 | struct dwarf2_queue_item *item, *last; | |
3071 | ||
3072 | item = dwarf2_queue; | |
3073 | while (item) | |
3074 | { | |
3075 | /* Anything still marked queued is likely to be in an | |
3076 | inconsistent state, so discard it. */ | |
3077 | if (item->per_cu->queued) | |
3078 | { | |
3079 | if (item->per_cu->cu != NULL) | |
3080 | free_one_cached_comp_unit (item->per_cu->cu); | |
3081 | item->per_cu->queued = 0; | |
3082 | } | |
3083 | ||
3084 | last = item; | |
3085 | item = item->next; | |
3086 | xfree (last); | |
3087 | } | |
3088 | ||
3089 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
3090 | } | |
3091 | ||
3092 | /* Read in full symbols for PST, and anything it depends on. */ | |
3093 | ||
c906108c | 3094 | static void |
fba45db2 | 3095 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 3096 | { |
10b3939b | 3097 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 3098 | struct cleanup *back_to; |
aaa75496 JB |
3099 | int i; |
3100 | ||
3101 | for (i = 0; i < pst->number_of_dependencies; i++) | |
3102 | if (!pst->dependencies[i]->readin) | |
3103 | { | |
3104 | /* Inform about additional files that need to be read in. */ | |
3105 | if (info_verbose) | |
3106 | { | |
a3f17187 | 3107 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
3108 | fputs_filtered (" ", gdb_stdout); |
3109 | wrap_here (""); | |
3110 | fputs_filtered ("and ", gdb_stdout); | |
3111 | wrap_here (""); | |
3112 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
3113 | wrap_here (""); /* Flush output */ | |
3114 | gdb_flush (gdb_stdout); | |
3115 | } | |
3116 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
3117 | } | |
3118 | ||
10b3939b DJ |
3119 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
3120 | ||
3121 | if (per_cu == NULL) | |
aaa75496 JB |
3122 | { |
3123 | /* It's an include file, no symbols to read for it. | |
3124 | Everything is in the parent symtab. */ | |
3125 | pst->readin = 1; | |
3126 | return; | |
3127 | } | |
c906108c | 3128 | |
10b3939b DJ |
3129 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
3130 | ||
03dd20cc | 3131 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b | 3132 | |
348e048f DE |
3133 | if (per_cu->from_debug_types) |
3134 | read_signatured_type_at_offset (pst->objfile, per_cu->offset); | |
3135 | else | |
3136 | load_full_comp_unit (per_cu, pst->objfile); | |
3137 | ||
10b3939b DJ |
3138 | process_queue (pst->objfile); |
3139 | ||
3140 | /* Age the cache, releasing compilation units that have not | |
3141 | been used recently. */ | |
3142 | age_cached_comp_units (); | |
3143 | ||
3144 | do_cleanups (back_to); | |
3145 | } | |
3146 | ||
93311388 | 3147 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 3148 | |
93311388 | 3149 | static void |
31ffec48 | 3150 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 3151 | { |
31ffec48 | 3152 | bfd *abfd = objfile->obfd; |
10b3939b | 3153 | struct dwarf2_cu *cu; |
c764a876 | 3154 | unsigned int offset; |
93311388 | 3155 | gdb_byte *info_ptr, *beg_of_comp_unit; |
10b3939b DJ |
3156 | struct cleanup *back_to, *free_cu_cleanup; |
3157 | struct attribute *attr; | |
3158 | CORE_ADDR baseaddr; | |
6502dd73 | 3159 | |
348e048f DE |
3160 | gdb_assert (! per_cu->from_debug_types); |
3161 | ||
c906108c | 3162 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 3163 | offset = per_cu->offset; |
6502dd73 | 3164 | |
dce234bc | 3165 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 3166 | beg_of_comp_unit = info_ptr; |
63d06c5c | 3167 | |
93311388 | 3168 | cu = alloc_one_comp_unit (objfile); |
c906108c | 3169 | |
10b3939b DJ |
3170 | /* If an error occurs while loading, release our storage. */ |
3171 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 3172 | |
93311388 | 3173 | /* Read in the comp_unit header. */ |
10b3939b | 3174 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c | 3175 | |
93311388 DE |
3176 | /* Complete the cu_header. */ |
3177 | cu->header.offset = offset; | |
3178 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3179 | ||
3180 | /* Read the abbrevs for this compilation unit. */ | |
10b3939b DJ |
3181 | dwarf2_read_abbrevs (abfd, cu); |
3182 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
3183 | ||
93311388 | 3184 | /* Link this compilation unit into the compilation unit tree. */ |
10b3939b | 3185 | per_cu->cu = cu; |
93311388 | 3186 | cu->per_cu = per_cu; |
f792889a | 3187 | cu->type_hash = per_cu->type_hash; |
e142c38c | 3188 | |
93311388 | 3189 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
3190 | |
3191 | /* We try not to read any attributes in this function, because not | |
3192 | all objfiles needed for references have been loaded yet, and symbol | |
3193 | table processing isn't initialized. But we have to set the CU language, | |
3194 | or we won't be able to build types correctly. */ | |
3195 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
3196 | if (attr) | |
3197 | set_cu_language (DW_UNSND (attr), cu); | |
3198 | else | |
3199 | set_cu_language (language_minimal, cu); | |
3200 | ||
348e048f DE |
3201 | /* Link this CU into read_in_chain. */ |
3202 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3203 | dwarf2_per_objfile->read_in_chain = per_cu; | |
3204 | ||
10b3939b | 3205 | do_cleanups (back_to); |
e142c38c | 3206 | |
10b3939b DJ |
3207 | /* We've successfully allocated this compilation unit. Let our caller |
3208 | clean it up when finished with it. */ | |
3209 | discard_cleanups (free_cu_cleanup); | |
10b3939b DJ |
3210 | } |
3211 | ||
3212 | /* Generate full symbol information for PST and CU, whose DIEs have | |
3213 | already been loaded into memory. */ | |
3214 | ||
3215 | static void | |
3216 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
3217 | { | |
3218 | struct partial_symtab *pst = per_cu->psymtab; | |
3219 | struct dwarf2_cu *cu = per_cu->cu; | |
3220 | struct objfile *objfile = pst->objfile; | |
3221 | bfd *abfd = objfile->obfd; | |
3222 | CORE_ADDR lowpc, highpc; | |
3223 | struct symtab *symtab; | |
3224 | struct cleanup *back_to; | |
10b3939b DJ |
3225 | CORE_ADDR baseaddr; |
3226 | ||
3227 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3228 | ||
10b3939b DJ |
3229 | buildsym_init (); |
3230 | back_to = make_cleanup (really_free_pendings, NULL); | |
3231 | ||
3232 | cu->list_in_scope = &file_symbols; | |
c906108c | 3233 | |
d85a05f0 | 3234 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 3235 | |
c906108c | 3236 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 3237 | process_die (cu->dies, cu); |
c906108c | 3238 | |
fae299cd DC |
3239 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
3240 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
3241 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 3242 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 3243 | |
613e1657 | 3244 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3245 | |
3246 | /* Set symtab language to language from DW_AT_language. | |
3247 | If the compilation is from a C file generated by language preprocessors, | |
3248 | do not set the language if it was already deduced by start_subfile. */ | |
3249 | if (symtab != NULL | |
10b3939b | 3250 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 3251 | { |
10b3939b | 3252 | symtab->language = cu->language; |
c906108c SS |
3253 | } |
3254 | pst->symtab = symtab; | |
3255 | pst->readin = 1; | |
c906108c SS |
3256 | |
3257 | do_cleanups (back_to); | |
3258 | } | |
3259 | ||
3260 | /* Process a die and its children. */ | |
3261 | ||
3262 | static void | |
e7c27a73 | 3263 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3264 | { |
3265 | switch (die->tag) | |
3266 | { | |
3267 | case DW_TAG_padding: | |
3268 | break; | |
3269 | case DW_TAG_compile_unit: | |
e7c27a73 | 3270 | read_file_scope (die, cu); |
c906108c | 3271 | break; |
348e048f DE |
3272 | case DW_TAG_type_unit: |
3273 | read_type_unit_scope (die, cu); | |
3274 | break; | |
c906108c | 3275 | case DW_TAG_subprogram: |
c906108c | 3276 | case DW_TAG_inlined_subroutine: |
edb3359d | 3277 | read_func_scope (die, cu); |
c906108c SS |
3278 | break; |
3279 | case DW_TAG_lexical_block: | |
14898363 L |
3280 | case DW_TAG_try_block: |
3281 | case DW_TAG_catch_block: | |
e7c27a73 | 3282 | read_lexical_block_scope (die, cu); |
c906108c SS |
3283 | break; |
3284 | case DW_TAG_class_type: | |
680b30c7 | 3285 | case DW_TAG_interface_type: |
c906108c SS |
3286 | case DW_TAG_structure_type: |
3287 | case DW_TAG_union_type: | |
134d01f1 | 3288 | process_structure_scope (die, cu); |
c906108c SS |
3289 | break; |
3290 | case DW_TAG_enumeration_type: | |
134d01f1 | 3291 | process_enumeration_scope (die, cu); |
c906108c | 3292 | break; |
134d01f1 | 3293 | |
f792889a DJ |
3294 | /* These dies have a type, but processing them does not create |
3295 | a symbol or recurse to process the children. Therefore we can | |
3296 | read them on-demand through read_type_die. */ | |
c906108c | 3297 | case DW_TAG_subroutine_type: |
72019c9c | 3298 | case DW_TAG_set_type: |
c906108c | 3299 | case DW_TAG_array_type: |
c906108c | 3300 | case DW_TAG_pointer_type: |
c906108c | 3301 | case DW_TAG_ptr_to_member_type: |
c906108c | 3302 | case DW_TAG_reference_type: |
c906108c | 3303 | case DW_TAG_string_type: |
c906108c | 3304 | break; |
134d01f1 | 3305 | |
c906108c | 3306 | case DW_TAG_base_type: |
a02abb62 | 3307 | case DW_TAG_subrange_type: |
cb249c71 | 3308 | case DW_TAG_typedef: |
134d01f1 DJ |
3309 | /* Add a typedef symbol for the type definition, if it has a |
3310 | DW_AT_name. */ | |
f792889a | 3311 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 3312 | break; |
c906108c | 3313 | case DW_TAG_common_block: |
e7c27a73 | 3314 | read_common_block (die, cu); |
c906108c SS |
3315 | break; |
3316 | case DW_TAG_common_inclusion: | |
3317 | break; | |
d9fa45fe | 3318 | case DW_TAG_namespace: |
63d06c5c | 3319 | processing_has_namespace_info = 1; |
e7c27a73 | 3320 | read_namespace (die, cu); |
d9fa45fe | 3321 | break; |
5d7cb8df JK |
3322 | case DW_TAG_module: |
3323 | read_module (die, cu); | |
3324 | break; | |
d9fa45fe DC |
3325 | case DW_TAG_imported_declaration: |
3326 | case DW_TAG_imported_module: | |
63d06c5c | 3327 | processing_has_namespace_info = 1; |
27aa8d6a SW |
3328 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
3329 | || cu->language != language_fortran)) | |
3330 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
3331 | dwarf_tag_name (die->tag)); | |
3332 | read_import_statement (die, cu); | |
d9fa45fe | 3333 | break; |
c906108c | 3334 | default: |
e7c27a73 | 3335 | new_symbol (die, NULL, cu); |
c906108c SS |
3336 | break; |
3337 | } | |
3338 | } | |
3339 | ||
0114d602 DJ |
3340 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
3341 | If scope qualifiers are appropriate they will be added. The result | |
3342 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
3343 | not have a name. */ | |
3344 | ||
3345 | static const char * | |
3346 | dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu) | |
3347 | { | |
3348 | struct attribute *attr; | |
3349 | char *prefix, *name; | |
3350 | struct ui_file *buf = NULL; | |
3351 | ||
3352 | name = dwarf2_name (die, cu); | |
3353 | if (!name) | |
3354 | return NULL; | |
3355 | ||
3356 | /* These are the only languages we know how to qualify names in. */ | |
3357 | if (cu->language != language_cplus | |
3358 | && cu->language != language_java) | |
3359 | return name; | |
3360 | ||
3361 | /* If no prefix is necessary for this type of DIE, return the | |
3362 | unqualified name. The other three tags listed could be handled | |
3363 | in pdi_needs_namespace, but that requires broader changes. */ | |
3364 | if (!pdi_needs_namespace (die->tag) | |
3365 | && die->tag != DW_TAG_subprogram | |
3366 | && die->tag != DW_TAG_variable | |
3367 | && die->tag != DW_TAG_member) | |
3368 | return name; | |
3369 | ||
3370 | prefix = determine_prefix (die, cu); | |
3371 | if (*prefix != '\0') | |
3372 | name = typename_concat (&cu->objfile->objfile_obstack, prefix, | |
3373 | name, cu); | |
3374 | ||
3375 | return name; | |
3376 | } | |
3377 | ||
27aa8d6a SW |
3378 | /* Read the import statement specified by the given die and record it. */ |
3379 | ||
3380 | static void | |
3381 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
3382 | { | |
3383 | struct attribute *import_attr; | |
3384 | struct die_info *imported_die; | |
de4affc9 | 3385 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 3386 | const char *imported_name; |
794684b6 SW |
3387 | const char *imported_name_prefix; |
3388 | const char *import_prefix; | |
3389 | char *canonical_name; | |
27aa8d6a SW |
3390 | |
3391 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
3392 | if (import_attr == NULL) | |
3393 | { | |
3394 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
3395 | dwarf_tag_name (die->tag)); | |
3396 | return; | |
3397 | } | |
3398 | ||
de4affc9 CC |
3399 | imported_cu = cu; |
3400 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
3401 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
3402 | if (imported_name == NULL) |
3403 | { | |
3404 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
3405 | ||
3406 | The import in the following code: | |
3407 | namespace A | |
3408 | { | |
3409 | typedef int B; | |
3410 | } | |
3411 | ||
3412 | int main () | |
3413 | { | |
3414 | using A::B; | |
3415 | B b; | |
3416 | return b; | |
3417 | } | |
3418 | ||
3419 | ... | |
3420 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
3421 | <52> DW_AT_decl_file : 1 | |
3422 | <53> DW_AT_decl_line : 6 | |
3423 | <54> DW_AT_import : <0x75> | |
3424 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
3425 | <59> DW_AT_name : B | |
3426 | <5b> DW_AT_decl_file : 1 | |
3427 | <5c> DW_AT_decl_line : 2 | |
3428 | <5d> DW_AT_type : <0x6e> | |
3429 | ... | |
3430 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
3431 | <76> DW_AT_byte_size : 4 | |
3432 | <77> DW_AT_encoding : 5 (signed) | |
3433 | ||
3434 | imports the wrong die ( 0x75 instead of 0x58 ). | |
3435 | This case will be ignored until the gcc bug is fixed. */ | |
3436 | return; | |
3437 | } | |
3438 | ||
3439 | /* FIXME: dwarf2_name (die); for the local name after import. */ | |
3440 | ||
794684b6 SW |
3441 | /* Figure out where the statement is being imported to. */ |
3442 | import_prefix = determine_prefix (die, cu); | |
3443 | ||
3444 | /* Figure out what the scope of the imported die is and prepend it | |
3445 | to the name of the imported die. */ | |
de4affc9 | 3446 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 SW |
3447 | |
3448 | if (strlen (imported_name_prefix) > 0) | |
3449 | { | |
3450 | canonical_name = alloca (strlen (imported_name_prefix) + 2 + strlen (imported_name) + 1); | |
3451 | strcpy (canonical_name, imported_name_prefix); | |
3452 | strcat (canonical_name, "::"); | |
3453 | strcat (canonical_name, imported_name); | |
3454 | } | |
3455 | else | |
3456 | { | |
3457 | canonical_name = alloca (strlen (imported_name) + 1); | |
3458 | strcpy (canonical_name, imported_name); | |
3459 | } | |
3460 | ||
3461 | using_directives = cp_add_using (import_prefix,canonical_name, using_directives); | |
27aa8d6a SW |
3462 | } |
3463 | ||
5fb290d7 | 3464 | static void |
e142c38c | 3465 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 3466 | { |
e142c38c | 3467 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
3468 | } |
3469 | ||
cb1df416 DJ |
3470 | static void |
3471 | free_cu_line_header (void *arg) | |
3472 | { | |
3473 | struct dwarf2_cu *cu = arg; | |
3474 | ||
3475 | free_line_header (cu->line_header); | |
3476 | cu->line_header = NULL; | |
3477 | } | |
3478 | ||
c906108c | 3479 | static void |
e7c27a73 | 3480 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3481 | { |
e7c27a73 DJ |
3482 | struct objfile *objfile = cu->objfile; |
3483 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 3484 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 3485 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
3486 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
3487 | struct attribute *attr; | |
e1024ff1 | 3488 | char *name = NULL; |
c906108c SS |
3489 | char *comp_dir = NULL; |
3490 | struct die_info *child_die; | |
3491 | bfd *abfd = objfile->obfd; | |
debd256d | 3492 | struct line_header *line_header = 0; |
e142c38c DJ |
3493 | CORE_ADDR baseaddr; |
3494 | ||
3495 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3496 | |
fae299cd | 3497 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
3498 | |
3499 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
3500 | from finish_block. */ | |
2acceee2 | 3501 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
3502 | lowpc = highpc; |
3503 | lowpc += baseaddr; | |
3504 | highpc += baseaddr; | |
3505 | ||
39cbfefa DJ |
3506 | /* Find the filename. Do not use dwarf2_name here, since the filename |
3507 | is not a source language identifier. */ | |
e142c38c | 3508 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3509 | if (attr) |
3510 | { | |
3511 | name = DW_STRING (attr); | |
3512 | } | |
e1024ff1 | 3513 | |
e142c38c | 3514 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 3515 | if (attr) |
e1024ff1 DJ |
3516 | comp_dir = DW_STRING (attr); |
3517 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 3518 | { |
e1024ff1 DJ |
3519 | comp_dir = ldirname (name); |
3520 | if (comp_dir != NULL) | |
3521 | make_cleanup (xfree, comp_dir); | |
3522 | } | |
3523 | if (comp_dir != NULL) | |
3524 | { | |
3525 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
3526 | directory, get rid of it. */ | |
3527 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 3528 | |
e1024ff1 DJ |
3529 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
3530 | comp_dir = cp + 1; | |
c906108c SS |
3531 | } |
3532 | ||
e1024ff1 DJ |
3533 | if (name == NULL) |
3534 | name = "<unknown>"; | |
3535 | ||
e142c38c | 3536 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
3537 | if (attr) |
3538 | { | |
e142c38c | 3539 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
3540 | } |
3541 | ||
b0f35d58 DL |
3542 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
3543 | if (attr) | |
3544 | cu->producer = DW_STRING (attr); | |
303b6f5d | 3545 | |
c906108c SS |
3546 | /* We assume that we're processing GCC output. */ |
3547 | processing_gcc_compilation = 2; | |
c906108c | 3548 | |
df8a16a1 DJ |
3549 | processing_has_namespace_info = 0; |
3550 | ||
c906108c SS |
3551 | start_symtab (name, comp_dir, lowpc); |
3552 | record_debugformat ("DWARF 2"); | |
303b6f5d | 3553 | record_producer (cu->producer); |
c906108c | 3554 | |
e142c38c | 3555 | initialize_cu_func_list (cu); |
c906108c | 3556 | |
cb1df416 DJ |
3557 | /* Decode line number information if present. We do this before |
3558 | processing child DIEs, so that the line header table is available | |
3559 | for DW_AT_decl_file. */ | |
e142c38c | 3560 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
3561 | if (attr) |
3562 | { | |
debd256d | 3563 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 3564 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
3565 | if (line_header) |
3566 | { | |
cb1df416 DJ |
3567 | cu->line_header = line_header; |
3568 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 3569 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 3570 | } |
5fb290d7 | 3571 | } |
debd256d | 3572 | |
cb1df416 DJ |
3573 | /* Process all dies in compilation unit. */ |
3574 | if (die->child != NULL) | |
3575 | { | |
3576 | child_die = die->child; | |
3577 | while (child_die && child_die->tag) | |
3578 | { | |
3579 | process_die (child_die, cu); | |
3580 | child_die = sibling_die (child_die); | |
3581 | } | |
3582 | } | |
3583 | ||
2e276125 JB |
3584 | /* Decode macro information, if present. Dwarf 2 macro information |
3585 | refers to information in the line number info statement program | |
3586 | header, so we can only read it if we've read the header | |
3587 | successfully. */ | |
e142c38c | 3588 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 3589 | if (attr && line_header) |
2e276125 JB |
3590 | { |
3591 | unsigned int macro_offset = DW_UNSND (attr); | |
3592 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 3593 | comp_dir, abfd, cu); |
2e276125 | 3594 | } |
debd256d | 3595 | do_cleanups (back_to); |
5fb290d7 DJ |
3596 | } |
3597 | ||
348e048f DE |
3598 | /* For TUs we want to skip the first top level sibling if it's not the |
3599 | actual type being defined by this TU. In this case the first top | |
3600 | level sibling is there to provide context only. */ | |
3601 | ||
3602 | static void | |
3603 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3604 | { | |
3605 | struct objfile *objfile = cu->objfile; | |
3606 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
3607 | CORE_ADDR lowpc; | |
3608 | struct attribute *attr; | |
3609 | char *name = NULL; | |
3610 | char *comp_dir = NULL; | |
3611 | struct die_info *child_die; | |
3612 | bfd *abfd = objfile->obfd; | |
3613 | struct line_header *line_header = 0; | |
3614 | ||
3615 | /* start_symtab needs a low pc, but we don't really have one. | |
3616 | Do what read_file_scope would do in the absence of such info. */ | |
3617 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3618 | ||
3619 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
3620 | is not a source language identifier. */ | |
3621 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
3622 | if (attr) | |
3623 | name = DW_STRING (attr); | |
3624 | ||
3625 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
3626 | if (attr) | |
3627 | comp_dir = DW_STRING (attr); | |
3628 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
3629 | { | |
3630 | comp_dir = ldirname (name); | |
3631 | if (comp_dir != NULL) | |
3632 | make_cleanup (xfree, comp_dir); | |
3633 | } | |
3634 | ||
3635 | if (name == NULL) | |
3636 | name = "<unknown>"; | |
3637 | ||
3638 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
3639 | if (attr) | |
3640 | set_cu_language (DW_UNSND (attr), cu); | |
3641 | ||
3642 | /* This isn't technically needed today. It is done for symmetry | |
3643 | with read_file_scope. */ | |
3644 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
3645 | if (attr) | |
3646 | cu->producer = DW_STRING (attr); | |
3647 | ||
3648 | /* We assume that we're processing GCC output. */ | |
3649 | processing_gcc_compilation = 2; | |
3650 | ||
3651 | processing_has_namespace_info = 0; | |
3652 | ||
3653 | start_symtab (name, comp_dir, lowpc); | |
3654 | record_debugformat ("DWARF 2"); | |
3655 | record_producer (cu->producer); | |
3656 | ||
3657 | /* Process the dies in the type unit. */ | |
3658 | if (die->child == NULL) | |
3659 | { | |
3660 | dump_die_for_error (die); | |
3661 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
3662 | bfd_get_filename (abfd)); | |
3663 | } | |
3664 | ||
3665 | child_die = die->child; | |
3666 | ||
3667 | while (child_die && child_die->tag) | |
3668 | { | |
3669 | process_die (child_die, cu); | |
3670 | ||
3671 | child_die = sibling_die (child_die); | |
3672 | } | |
3673 | ||
3674 | do_cleanups (back_to); | |
3675 | } | |
3676 | ||
5fb290d7 | 3677 | static void |
e142c38c DJ |
3678 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
3679 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
3680 | { |
3681 | struct function_range *thisfn; | |
3682 | ||
3683 | thisfn = (struct function_range *) | |
7b5a2f43 | 3684 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
3685 | thisfn->name = name; |
3686 | thisfn->lowpc = lowpc; | |
3687 | thisfn->highpc = highpc; | |
3688 | thisfn->seen_line = 0; | |
3689 | thisfn->next = NULL; | |
3690 | ||
e142c38c DJ |
3691 | if (cu->last_fn == NULL) |
3692 | cu->first_fn = thisfn; | |
5fb290d7 | 3693 | else |
e142c38c | 3694 | cu->last_fn->next = thisfn; |
5fb290d7 | 3695 | |
e142c38c | 3696 | cu->last_fn = thisfn; |
c906108c SS |
3697 | } |
3698 | ||
d389af10 JK |
3699 | /* qsort helper for inherit_abstract_dies. */ |
3700 | ||
3701 | static int | |
3702 | unsigned_int_compar (const void *ap, const void *bp) | |
3703 | { | |
3704 | unsigned int a = *(unsigned int *) ap; | |
3705 | unsigned int b = *(unsigned int *) bp; | |
3706 | ||
3707 | return (a > b) - (b > a); | |
3708 | } | |
3709 | ||
3710 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3711 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
3712 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
3713 | ||
3714 | static void | |
3715 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
3716 | { | |
3717 | struct die_info *child_die; | |
3718 | unsigned die_children_count; | |
3719 | /* CU offsets which were referenced by children of the current DIE. */ | |
3720 | unsigned *offsets; | |
3721 | unsigned *offsets_end, *offsetp; | |
3722 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
3723 | struct die_info *origin_die; | |
3724 | /* Iterator of the ORIGIN_DIE children. */ | |
3725 | struct die_info *origin_child_die; | |
3726 | struct cleanup *cleanups; | |
3727 | struct attribute *attr; | |
3728 | ||
3729 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
3730 | if (!attr) | |
3731 | return; | |
3732 | ||
3733 | origin_die = follow_die_ref (die, attr, &cu); | |
edb3359d DJ |
3734 | if (die->tag != origin_die->tag |
3735 | && !(die->tag == DW_TAG_inlined_subroutine | |
3736 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3737 | complaint (&symfile_complaints, |
3738 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
3739 | die->offset, origin_die->offset); | |
3740 | ||
3741 | child_die = die->child; | |
3742 | die_children_count = 0; | |
3743 | while (child_die && child_die->tag) | |
3744 | { | |
3745 | child_die = sibling_die (child_die); | |
3746 | die_children_count++; | |
3747 | } | |
3748 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
3749 | cleanups = make_cleanup (xfree, offsets); | |
3750 | ||
3751 | offsets_end = offsets; | |
3752 | child_die = die->child; | |
3753 | while (child_die && child_die->tag) | |
3754 | { | |
c38f313d DJ |
3755 | /* For each CHILD_DIE, find the corresponding child of |
3756 | ORIGIN_DIE. If there is more than one layer of | |
3757 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
3758 | but GCC versions at least through 4.4 generate this (GCC PR | |
3759 | 40573). */ | |
3760 | struct die_info *child_origin_die = child_die; | |
3761 | while (1) | |
3762 | { | |
3763 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); | |
3764 | if (attr == NULL) | |
3765 | break; | |
3766 | child_origin_die = follow_die_ref (child_origin_die, attr, &cu); | |
3767 | } | |
3768 | ||
d389af10 JK |
3769 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
3770 | counterpart may exist. */ | |
c38f313d | 3771 | if (child_origin_die != child_die) |
d389af10 | 3772 | { |
edb3359d DJ |
3773 | if (child_die->tag != child_origin_die->tag |
3774 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
3775 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
3776 | complaint (&symfile_complaints, |
3777 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3778 | "different tags"), child_die->offset, | |
3779 | child_origin_die->offset); | |
c38f313d DJ |
3780 | if (child_origin_die->parent != origin_die) |
3781 | complaint (&symfile_complaints, | |
3782 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3783 | "different parents"), child_die->offset, | |
3784 | child_origin_die->offset); | |
3785 | else | |
3786 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
3787 | } |
3788 | child_die = sibling_die (child_die); | |
3789 | } | |
3790 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
3791 | unsigned_int_compar); | |
3792 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
3793 | if (offsetp[-1] == *offsetp) | |
3794 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
3795 | "to DIE 0x%x as their abstract origin"), | |
3796 | die->offset, *offsetp); | |
3797 | ||
3798 | offsetp = offsets; | |
3799 | origin_child_die = origin_die->child; | |
3800 | while (origin_child_die && origin_child_die->tag) | |
3801 | { | |
3802 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
3803 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
3804 | offsetp++; | |
3805 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
3806 | { | |
3807 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
3808 | process_die (origin_child_die, cu); | |
3809 | } | |
3810 | origin_child_die = sibling_die (origin_child_die); | |
3811 | } | |
3812 | ||
3813 | do_cleanups (cleanups); | |
3814 | } | |
3815 | ||
c906108c | 3816 | static void |
e7c27a73 | 3817 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3818 | { |
e7c27a73 | 3819 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3820 | struct context_stack *new; |
c906108c SS |
3821 | CORE_ADDR lowpc; |
3822 | CORE_ADDR highpc; | |
3823 | struct die_info *child_die; | |
edb3359d | 3824 | struct attribute *attr, *call_line, *call_file; |
c906108c | 3825 | char *name; |
e142c38c | 3826 | CORE_ADDR baseaddr; |
801e3a5b | 3827 | struct block *block; |
edb3359d DJ |
3828 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
3829 | ||
3830 | if (inlined_func) | |
3831 | { | |
3832 | /* If we do not have call site information, we can't show the | |
3833 | caller of this inlined function. That's too confusing, so | |
3834 | only use the scope for local variables. */ | |
3835 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
3836 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
3837 | if (call_line == NULL || call_file == NULL) | |
3838 | { | |
3839 | read_lexical_block_scope (die, cu); | |
3840 | return; | |
3841 | } | |
3842 | } | |
c906108c | 3843 | |
e142c38c DJ |
3844 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
3845 | ||
3846 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
3847 | |
3848 | /* Ignore functions with missing or empty names and functions with | |
3849 | missing or invalid low and high pc attributes. */ | |
d85a05f0 | 3850 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
3851 | return; |
3852 | ||
3853 | lowpc += baseaddr; | |
3854 | highpc += baseaddr; | |
3855 | ||
5fb290d7 | 3856 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3857 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3858 | |
c906108c | 3859 | new = push_context (0, lowpc); |
f792889a | 3860 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3861 | |
4cecd739 DJ |
3862 | /* If there is a location expression for DW_AT_frame_base, record |
3863 | it. */ | |
e142c38c | 3864 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3865 | if (attr) |
c034e007 AC |
3866 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3867 | expression is being recorded directly in the function's symbol | |
3868 | and not in a separate frame-base object. I guess this hack is | |
3869 | to avoid adding some sort of frame-base adjunct/annex to the | |
3870 | function's symbol :-(. The problem with doing this is that it | |
3871 | results in a function symbol with a location expression that | |
3872 | has nothing to do with the location of the function, ouch! The | |
3873 | relationship should be: a function's symbol has-a frame base; a | |
3874 | frame-base has-a location expression. */ | |
e7c27a73 | 3875 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3876 | |
e142c38c | 3877 | cu->list_in_scope = &local_symbols; |
c906108c | 3878 | |
639d11d3 | 3879 | if (die->child != NULL) |
c906108c | 3880 | { |
639d11d3 | 3881 | child_die = die->child; |
c906108c SS |
3882 | while (child_die && child_die->tag) |
3883 | { | |
e7c27a73 | 3884 | process_die (child_die, cu); |
c906108c SS |
3885 | child_die = sibling_die (child_die); |
3886 | } | |
3887 | } | |
3888 | ||
d389af10 JK |
3889 | inherit_abstract_dies (die, cu); |
3890 | ||
c906108c SS |
3891 | new = pop_context (); |
3892 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3893 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3894 | lowpc, highpc, objfile); | |
3895 | ||
df8a16a1 DJ |
3896 | /* For C++, set the block's scope. */ |
3897 | if (cu->language == language_cplus) | |
3898 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, | |
0114d602 | 3899 | determine_prefix (die, cu), |
df8a16a1 DJ |
3900 | processing_has_namespace_info); |
3901 | ||
801e3a5b JB |
3902 | /* If we have address ranges, record them. */ |
3903 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3904 | |
3905 | /* In C++, we can have functions nested inside functions (e.g., when | |
3906 | a function declares a class that has methods). This means that | |
3907 | when we finish processing a function scope, we may need to go | |
3908 | back to building a containing block's symbol lists. */ | |
3909 | local_symbols = new->locals; | |
3910 | param_symbols = new->params; | |
27aa8d6a | 3911 | using_directives = new->using_directives; |
208d8187 | 3912 | |
921e78cf JB |
3913 | /* If we've finished processing a top-level function, subsequent |
3914 | symbols go in the file symbol list. */ | |
3915 | if (outermost_context_p ()) | |
e142c38c | 3916 | cu->list_in_scope = &file_symbols; |
c906108c SS |
3917 | } |
3918 | ||
3919 | /* Process all the DIES contained within a lexical block scope. Start | |
3920 | a new scope, process the dies, and then close the scope. */ | |
3921 | ||
3922 | static void | |
e7c27a73 | 3923 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3924 | { |
e7c27a73 | 3925 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3926 | struct context_stack *new; |
c906108c SS |
3927 | CORE_ADDR lowpc, highpc; |
3928 | struct die_info *child_die; | |
e142c38c DJ |
3929 | CORE_ADDR baseaddr; |
3930 | ||
3931 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3932 | |
3933 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3934 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3935 | as multiple lexical blocks? Handling children in a sane way would | |
3936 | be nasty. Might be easier to properly extend generic blocks to | |
3937 | describe ranges. */ | |
d85a05f0 | 3938 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
3939 | return; |
3940 | lowpc += baseaddr; | |
3941 | highpc += baseaddr; | |
3942 | ||
3943 | push_context (0, lowpc); | |
639d11d3 | 3944 | if (die->child != NULL) |
c906108c | 3945 | { |
639d11d3 | 3946 | child_die = die->child; |
c906108c SS |
3947 | while (child_die && child_die->tag) |
3948 | { | |
e7c27a73 | 3949 | process_die (child_die, cu); |
c906108c SS |
3950 | child_die = sibling_die (child_die); |
3951 | } | |
3952 | } | |
3953 | new = pop_context (); | |
3954 | ||
3955 | if (local_symbols != NULL) | |
3956 | { | |
801e3a5b JB |
3957 | struct block *block |
3958 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3959 | highpc, objfile); | |
3960 | ||
3961 | /* Note that recording ranges after traversing children, as we | |
3962 | do here, means that recording a parent's ranges entails | |
3963 | walking across all its children's ranges as they appear in | |
3964 | the address map, which is quadratic behavior. | |
3965 | ||
3966 | It would be nicer to record the parent's ranges before | |
3967 | traversing its children, simply overriding whatever you find | |
3968 | there. But since we don't even decide whether to create a | |
3969 | block until after we've traversed its children, that's hard | |
3970 | to do. */ | |
3971 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3972 | } |
3973 | local_symbols = new->locals; | |
27aa8d6a | 3974 | using_directives = new->using_directives; |
c906108c SS |
3975 | } |
3976 | ||
43039443 | 3977 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3978 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3979 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3980 | |
3981 | static int | |
3982 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3983 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3984 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3985 | { |
3986 | struct objfile *objfile = cu->objfile; | |
3987 | struct comp_unit_head *cu_header = &cu->header; | |
3988 | bfd *obfd = objfile->obfd; | |
3989 | unsigned int addr_size = cu_header->addr_size; | |
3990 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3991 | /* Base address selection entry. */ | |
3992 | CORE_ADDR base; | |
3993 | int found_base; | |
3994 | unsigned int dummy; | |
3995 | gdb_byte *buffer; | |
3996 | CORE_ADDR marker; | |
3997 | int low_set; | |
3998 | CORE_ADDR low = 0; | |
3999 | CORE_ADDR high = 0; | |
ff013f42 | 4000 | CORE_ADDR baseaddr; |
43039443 | 4001 | |
d00adf39 DE |
4002 | found_base = cu->base_known; |
4003 | base = cu->base_address; | |
43039443 | 4004 | |
dce234bc | 4005 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
4006 | { |
4007 | complaint (&symfile_complaints, | |
4008 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
4009 | offset); | |
4010 | return 0; | |
4011 | } | |
dce234bc | 4012 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
4013 | |
4014 | /* Read in the largest possible address. */ | |
4015 | marker = read_address (obfd, buffer, cu, &dummy); | |
4016 | if ((marker & mask) == mask) | |
4017 | { | |
4018 | /* If we found the largest possible address, then | |
4019 | read the base address. */ | |
4020 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4021 | buffer += 2 * addr_size; | |
4022 | offset += 2 * addr_size; | |
4023 | found_base = 1; | |
4024 | } | |
4025 | ||
4026 | low_set = 0; | |
4027 | ||
e7030f15 | 4028 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 4029 | |
43039443 JK |
4030 | while (1) |
4031 | { | |
4032 | CORE_ADDR range_beginning, range_end; | |
4033 | ||
4034 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
4035 | buffer += addr_size; | |
4036 | range_end = read_address (obfd, buffer, cu, &dummy); | |
4037 | buffer += addr_size; | |
4038 | offset += 2 * addr_size; | |
4039 | ||
4040 | /* An end of list marker is a pair of zero addresses. */ | |
4041 | if (range_beginning == 0 && range_end == 0) | |
4042 | /* Found the end of list entry. */ | |
4043 | break; | |
4044 | ||
4045 | /* Each base address selection entry is a pair of 2 values. | |
4046 | The first is the largest possible address, the second is | |
4047 | the base address. Check for a base address here. */ | |
4048 | if ((range_beginning & mask) == mask) | |
4049 | { | |
4050 | /* If we found the largest possible address, then | |
4051 | read the base address. */ | |
4052 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
4053 | found_base = 1; | |
4054 | continue; | |
4055 | } | |
4056 | ||
4057 | if (!found_base) | |
4058 | { | |
4059 | /* We have no valid base address for the ranges | |
4060 | data. */ | |
4061 | complaint (&symfile_complaints, | |
4062 | _("Invalid .debug_ranges data (no base address)")); | |
4063 | return 0; | |
4064 | } | |
4065 | ||
4066 | range_beginning += base; | |
4067 | range_end += base; | |
4068 | ||
ff013f42 JK |
4069 | if (ranges_pst != NULL && range_beginning < range_end) |
4070 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
4071 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
4072 | ranges_pst); | |
4073 | ||
43039443 JK |
4074 | /* FIXME: This is recording everything as a low-high |
4075 | segment of consecutive addresses. We should have a | |
4076 | data structure for discontiguous block ranges | |
4077 | instead. */ | |
4078 | if (! low_set) | |
4079 | { | |
4080 | low = range_beginning; | |
4081 | high = range_end; | |
4082 | low_set = 1; | |
4083 | } | |
4084 | else | |
4085 | { | |
4086 | if (range_beginning < low) | |
4087 | low = range_beginning; | |
4088 | if (range_end > high) | |
4089 | high = range_end; | |
4090 | } | |
4091 | } | |
4092 | ||
4093 | if (! low_set) | |
4094 | /* If the first entry is an end-of-list marker, the range | |
4095 | describes an empty scope, i.e. no instructions. */ | |
4096 | return 0; | |
4097 | ||
4098 | if (low_return) | |
4099 | *low_return = low; | |
4100 | if (high_return) | |
4101 | *high_return = high; | |
4102 | return 1; | |
4103 | } | |
4104 | ||
af34e669 DJ |
4105 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
4106 | are present and valid, otherwise, return 0. Return -1 if the range is | |
4107 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 4108 | static int |
af34e669 | 4109 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
4110 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
4111 | struct partial_symtab *pst) | |
c906108c SS |
4112 | { |
4113 | struct attribute *attr; | |
af34e669 DJ |
4114 | CORE_ADDR low = 0; |
4115 | CORE_ADDR high = 0; | |
4116 | int ret = 0; | |
c906108c | 4117 | |
e142c38c | 4118 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 4119 | if (attr) |
af34e669 DJ |
4120 | { |
4121 | high = DW_ADDR (attr); | |
e142c38c | 4122 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
4123 | if (attr) |
4124 | low = DW_ADDR (attr); | |
4125 | else | |
4126 | /* Found high w/o low attribute. */ | |
4127 | return 0; | |
4128 | ||
4129 | /* Found consecutive range of addresses. */ | |
4130 | ret = 1; | |
4131 | } | |
c906108c | 4132 | else |
af34e669 | 4133 | { |
e142c38c | 4134 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
4135 | if (attr != NULL) |
4136 | { | |
af34e669 | 4137 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 4138 | .debug_ranges section. */ |
d85a05f0 | 4139 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 4140 | return 0; |
43039443 | 4141 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
4142 | ret = -1; |
4143 | } | |
4144 | } | |
c906108c SS |
4145 | |
4146 | if (high < low) | |
4147 | return 0; | |
4148 | ||
4149 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
4150 | eliminate duplicate copies of functions and vtables and such. | |
4151 | The linker will arbitrarily choose one and discard the others. | |
4152 | The AT_*_pc values for such functions refer to local labels in | |
4153 | these sections. If the section from that file was discarded, the | |
4154 | labels are not in the output, so the relocs get a value of 0. | |
4155 | If this is a discarded function, mark the pc bounds as invalid, | |
4156 | so that GDB will ignore it. */ | |
72dca2f5 | 4157 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
4158 | return 0; |
4159 | ||
4160 | *lowpc = low; | |
4161 | *highpc = high; | |
af34e669 | 4162 | return ret; |
c906108c SS |
4163 | } |
4164 | ||
b084d499 JB |
4165 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
4166 | its low and high PC addresses. Do nothing if these addresses could not | |
4167 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
4168 | and HIGHPC to the high address if greater than HIGHPC. */ | |
4169 | ||
4170 | static void | |
4171 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
4172 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4173 | struct dwarf2_cu *cu) | |
4174 | { | |
4175 | CORE_ADDR low, high; | |
4176 | struct die_info *child = die->child; | |
4177 | ||
d85a05f0 | 4178 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
4179 | { |
4180 | *lowpc = min (*lowpc, low); | |
4181 | *highpc = max (*highpc, high); | |
4182 | } | |
4183 | ||
4184 | /* If the language does not allow nested subprograms (either inside | |
4185 | subprograms or lexical blocks), we're done. */ | |
4186 | if (cu->language != language_ada) | |
4187 | return; | |
4188 | ||
4189 | /* Check all the children of the given DIE. If it contains nested | |
4190 | subprograms, then check their pc bounds. Likewise, we need to | |
4191 | check lexical blocks as well, as they may also contain subprogram | |
4192 | definitions. */ | |
4193 | while (child && child->tag) | |
4194 | { | |
4195 | if (child->tag == DW_TAG_subprogram | |
4196 | || child->tag == DW_TAG_lexical_block) | |
4197 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
4198 | child = sibling_die (child); | |
4199 | } | |
4200 | } | |
4201 | ||
fae299cd DC |
4202 | /* Get the low and high pc's represented by the scope DIE, and store |
4203 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
4204 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
4205 | ||
4206 | static void | |
4207 | get_scope_pc_bounds (struct die_info *die, | |
4208 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
4209 | struct dwarf2_cu *cu) | |
4210 | { | |
4211 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
4212 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
4213 | CORE_ADDR current_low, current_high; | |
4214 | ||
d85a05f0 | 4215 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
4216 | { |
4217 | best_low = current_low; | |
4218 | best_high = current_high; | |
4219 | } | |
4220 | else | |
4221 | { | |
4222 | struct die_info *child = die->child; | |
4223 | ||
4224 | while (child && child->tag) | |
4225 | { | |
4226 | switch (child->tag) { | |
4227 | case DW_TAG_subprogram: | |
b084d499 | 4228 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
4229 | break; |
4230 | case DW_TAG_namespace: | |
4231 | /* FIXME: carlton/2004-01-16: Should we do this for | |
4232 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
4233 | that current GCC's always emit the DIEs corresponding | |
4234 | to definitions of methods of classes as children of a | |
4235 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
4236 | the DIEs giving the declarations, which could be | |
4237 | anywhere). But I don't see any reason why the | |
4238 | standards says that they have to be there. */ | |
4239 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
4240 | ||
4241 | if (current_low != ((CORE_ADDR) -1)) | |
4242 | { | |
4243 | best_low = min (best_low, current_low); | |
4244 | best_high = max (best_high, current_high); | |
4245 | } | |
4246 | break; | |
4247 | default: | |
4248 | /* Ignore. */ | |
4249 | break; | |
4250 | } | |
4251 | ||
4252 | child = sibling_die (child); | |
4253 | } | |
4254 | } | |
4255 | ||
4256 | *lowpc = best_low; | |
4257 | *highpc = best_high; | |
4258 | } | |
4259 | ||
801e3a5b JB |
4260 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
4261 | in DIE. */ | |
4262 | static void | |
4263 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
4264 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
4265 | { | |
4266 | struct attribute *attr; | |
4267 | ||
4268 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
4269 | if (attr) | |
4270 | { | |
4271 | CORE_ADDR high = DW_ADDR (attr); | |
4272 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
4273 | if (attr) | |
4274 | { | |
4275 | CORE_ADDR low = DW_ADDR (attr); | |
4276 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
4277 | } | |
4278 | } | |
4279 | ||
4280 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
4281 | if (attr) | |
4282 | { | |
4283 | bfd *obfd = cu->objfile->obfd; | |
4284 | ||
4285 | /* The value of the DW_AT_ranges attribute is the offset of the | |
4286 | address range list in the .debug_ranges section. */ | |
4287 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 4288 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
4289 | |
4290 | /* For some target architectures, but not others, the | |
4291 | read_address function sign-extends the addresses it returns. | |
4292 | To recognize base address selection entries, we need a | |
4293 | mask. */ | |
4294 | unsigned int addr_size = cu->header.addr_size; | |
4295 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
4296 | ||
4297 | /* The base address, to which the next pair is relative. Note | |
4298 | that this 'base' is a DWARF concept: most entries in a range | |
4299 | list are relative, to reduce the number of relocs against the | |
4300 | debugging information. This is separate from this function's | |
4301 | 'baseaddr' argument, which GDB uses to relocate debugging | |
4302 | information from a shared library based on the address at | |
4303 | which the library was loaded. */ | |
d00adf39 DE |
4304 | CORE_ADDR base = cu->base_address; |
4305 | int base_known = cu->base_known; | |
801e3a5b | 4306 | |
dce234bc | 4307 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
4308 | { |
4309 | complaint (&symfile_complaints, | |
4310 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
4311 | offset); | |
4312 | return; | |
4313 | } | |
4314 | ||
4315 | for (;;) | |
4316 | { | |
4317 | unsigned int bytes_read; | |
4318 | CORE_ADDR start, end; | |
4319 | ||
4320 | start = read_address (obfd, buffer, cu, &bytes_read); | |
4321 | buffer += bytes_read; | |
4322 | end = read_address (obfd, buffer, cu, &bytes_read); | |
4323 | buffer += bytes_read; | |
4324 | ||
4325 | /* Did we find the end of the range list? */ | |
4326 | if (start == 0 && end == 0) | |
4327 | break; | |
4328 | ||
4329 | /* Did we find a base address selection entry? */ | |
4330 | else if ((start & base_select_mask) == base_select_mask) | |
4331 | { | |
4332 | base = end; | |
4333 | base_known = 1; | |
4334 | } | |
4335 | ||
4336 | /* We found an ordinary address range. */ | |
4337 | else | |
4338 | { | |
4339 | if (!base_known) | |
4340 | { | |
4341 | complaint (&symfile_complaints, | |
4342 | _("Invalid .debug_ranges data (no base address)")); | |
4343 | return; | |
4344 | } | |
4345 | ||
4346 | record_block_range (block, | |
4347 | baseaddr + base + start, | |
4348 | baseaddr + base + end - 1); | |
4349 | } | |
4350 | } | |
4351 | } | |
4352 | } | |
4353 | ||
c906108c SS |
4354 | /* Add an aggregate field to the field list. */ |
4355 | ||
4356 | static void | |
107d2387 | 4357 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
4358 | struct dwarf2_cu *cu) |
4359 | { | |
4360 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 4361 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
4362 | struct nextfield *new_field; |
4363 | struct attribute *attr; | |
4364 | struct field *fp; | |
4365 | char *fieldname = ""; | |
4366 | ||
4367 | /* Allocate a new field list entry and link it in. */ | |
4368 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 4369 | make_cleanup (xfree, new_field); |
c906108c | 4370 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
4371 | |
4372 | if (die->tag == DW_TAG_inheritance) | |
4373 | { | |
4374 | new_field->next = fip->baseclasses; | |
4375 | fip->baseclasses = new_field; | |
4376 | } | |
4377 | else | |
4378 | { | |
4379 | new_field->next = fip->fields; | |
4380 | fip->fields = new_field; | |
4381 | } | |
c906108c SS |
4382 | fip->nfields++; |
4383 | ||
4384 | /* Handle accessibility and virtuality of field. | |
4385 | The default accessibility for members is public, the default | |
4386 | accessibility for inheritance is private. */ | |
4387 | if (die->tag != DW_TAG_inheritance) | |
4388 | new_field->accessibility = DW_ACCESS_public; | |
4389 | else | |
4390 | new_field->accessibility = DW_ACCESS_private; | |
4391 | new_field->virtuality = DW_VIRTUALITY_none; | |
4392 | ||
e142c38c | 4393 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4394 | if (attr) |
4395 | new_field->accessibility = DW_UNSND (attr); | |
4396 | if (new_field->accessibility != DW_ACCESS_public) | |
4397 | fip->non_public_fields = 1; | |
e142c38c | 4398 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
4399 | if (attr) |
4400 | new_field->virtuality = DW_UNSND (attr); | |
4401 | ||
4402 | fp = &new_field->field; | |
a9a9bd0f | 4403 | |
e142c38c | 4404 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 4405 | { |
a9a9bd0f DC |
4406 | /* Data member other than a C++ static data member. */ |
4407 | ||
c906108c | 4408 | /* Get type of field. */ |
e7c27a73 | 4409 | fp->type = die_type (die, cu); |
c906108c | 4410 | |
d6a843b5 | 4411 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 4412 | |
c906108c | 4413 | /* Get bit size of field (zero if none). */ |
e142c38c | 4414 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
4415 | if (attr) |
4416 | { | |
4417 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
4418 | } | |
4419 | else | |
4420 | { | |
4421 | FIELD_BITSIZE (*fp) = 0; | |
4422 | } | |
4423 | ||
4424 | /* Get bit offset of field. */ | |
e142c38c | 4425 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
4426 | if (attr) |
4427 | { | |
d4b96c9a | 4428 | int byte_offset = 0; |
c6a0999f | 4429 | |
3690dd37 | 4430 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 4431 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 4432 | else if (attr_form_is_constant (attr)) |
c6a0999f | 4433 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 4434 | else if (attr_form_is_block (attr)) |
c6a0999f | 4435 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
4436 | else |
4437 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 4438 | |
d6a843b5 | 4439 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 4440 | } |
e142c38c | 4441 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
4442 | if (attr) |
4443 | { | |
5e2b427d | 4444 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
4445 | { |
4446 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
4447 | additional bit offset from the MSB of the containing |
4448 | anonymous object to the MSB of the field. We don't | |
4449 | have to do anything special since we don't need to | |
4450 | know the size of the anonymous object. */ | |
c906108c SS |
4451 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
4452 | } | |
4453 | else | |
4454 | { | |
4455 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
4456 | MSB of the anonymous object, subtract off the number of |
4457 | bits from the MSB of the field to the MSB of the | |
4458 | object, and then subtract off the number of bits of | |
4459 | the field itself. The result is the bit offset of | |
4460 | the LSB of the field. */ | |
c906108c SS |
4461 | int anonymous_size; |
4462 | int bit_offset = DW_UNSND (attr); | |
4463 | ||
e142c38c | 4464 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4465 | if (attr) |
4466 | { | |
4467 | /* The size of the anonymous object containing | |
4468 | the bit field is explicit, so use the | |
4469 | indicated size (in bytes). */ | |
4470 | anonymous_size = DW_UNSND (attr); | |
4471 | } | |
4472 | else | |
4473 | { | |
4474 | /* The size of the anonymous object containing | |
4475 | the bit field must be inferred from the type | |
4476 | attribute of the data member containing the | |
4477 | bit field. */ | |
4478 | anonymous_size = TYPE_LENGTH (fp->type); | |
4479 | } | |
4480 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
4481 | - bit_offset - FIELD_BITSIZE (*fp); | |
4482 | } | |
4483 | } | |
4484 | ||
4485 | /* Get name of field. */ | |
39cbfefa DJ |
4486 | fieldname = dwarf2_name (die, cu); |
4487 | if (fieldname == NULL) | |
4488 | fieldname = ""; | |
d8151005 DJ |
4489 | |
4490 | /* The name is already allocated along with this objfile, so we don't | |
4491 | need to duplicate it for the type. */ | |
4492 | fp->name = fieldname; | |
c906108c SS |
4493 | |
4494 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 4495 | pointer or virtual base class pointer) to private. */ |
e142c38c | 4496 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 4497 | { |
d48cc9dd | 4498 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
4499 | new_field->accessibility = DW_ACCESS_private; |
4500 | fip->non_public_fields = 1; | |
4501 | } | |
4502 | } | |
a9a9bd0f | 4503 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 4504 | { |
a9a9bd0f DC |
4505 | /* C++ static member. */ |
4506 | ||
4507 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
4508 | is a declaration, but all versions of G++ as of this writing | |
4509 | (so through at least 3.2.1) incorrectly generate | |
4510 | DW_TAG_variable tags. */ | |
4511 | ||
c906108c | 4512 | char *physname; |
c906108c | 4513 | |
a9a9bd0f | 4514 | /* Get name of field. */ |
39cbfefa DJ |
4515 | fieldname = dwarf2_name (die, cu); |
4516 | if (fieldname == NULL) | |
c906108c SS |
4517 | return; |
4518 | ||
2df3850c | 4519 | /* Get physical name. */ |
e142c38c | 4520 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 4521 | |
d8151005 DJ |
4522 | /* The name is already allocated along with this objfile, so we don't |
4523 | need to duplicate it for the type. */ | |
4524 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 4525 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 4526 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
4527 | } |
4528 | else if (die->tag == DW_TAG_inheritance) | |
4529 | { | |
4530 | /* C++ base class field. */ | |
e142c38c | 4531 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 4532 | if (attr) |
d4b96c9a JK |
4533 | { |
4534 | int byte_offset = 0; | |
4535 | ||
4536 | if (attr_form_is_section_offset (attr)) | |
4537 | dwarf2_complex_location_expr_complaint (); | |
4538 | else if (attr_form_is_constant (attr)) | |
4539 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
4540 | else if (attr_form_is_block (attr)) | |
4541 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
4542 | else | |
4543 | dwarf2_complex_location_expr_complaint (); | |
4544 | ||
4545 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
4546 | } | |
c906108c | 4547 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 4548 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
4549 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
4550 | fip->nbaseclasses++; | |
4551 | } | |
4552 | } | |
4553 | ||
4554 | /* Create the vector of fields, and attach it to the type. */ | |
4555 | ||
4556 | static void | |
fba45db2 | 4557 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4558 | struct dwarf2_cu *cu) |
c906108c SS |
4559 | { |
4560 | int nfields = fip->nfields; | |
4561 | ||
4562 | /* Record the field count, allocate space for the array of fields, | |
4563 | and create blank accessibility bitfields if necessary. */ | |
4564 | TYPE_NFIELDS (type) = nfields; | |
4565 | TYPE_FIELDS (type) = (struct field *) | |
4566 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
4567 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
4568 | ||
b4ba55a1 | 4569 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
4570 | { |
4571 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
4572 | ||
4573 | TYPE_FIELD_PRIVATE_BITS (type) = | |
4574 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4575 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
4576 | ||
4577 | TYPE_FIELD_PROTECTED_BITS (type) = | |
4578 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4579 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
4580 | ||
4581 | TYPE_FIELD_IGNORE_BITS (type) = | |
4582 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4583 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
4584 | } | |
4585 | ||
4586 | /* If the type has baseclasses, allocate and clear a bit vector for | |
4587 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 4588 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
4589 | { |
4590 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 4591 | unsigned char *pointer; |
c906108c SS |
4592 | |
4593 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
4594 | pointer = TYPE_ALLOC (type, num_bytes); |
4595 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
4596 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
4597 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
4598 | } | |
4599 | ||
4600 | /* Copy the saved-up fields into the field vector. Start from the head | |
4601 | of the list, adding to the tail of the field array, so that they end | |
4602 | up in the same order in the array in which they were added to the list. */ | |
4603 | while (nfields-- > 0) | |
4604 | { | |
7d0ccb61 DJ |
4605 | struct nextfield *fieldp; |
4606 | ||
4607 | if (fip->fields) | |
4608 | { | |
4609 | fieldp = fip->fields; | |
4610 | fip->fields = fieldp->next; | |
4611 | } | |
4612 | else | |
4613 | { | |
4614 | fieldp = fip->baseclasses; | |
4615 | fip->baseclasses = fieldp->next; | |
4616 | } | |
4617 | ||
4618 | TYPE_FIELD (type, nfields) = fieldp->field; | |
4619 | switch (fieldp->accessibility) | |
c906108c | 4620 | { |
c5aa993b | 4621 | case DW_ACCESS_private: |
b4ba55a1 JB |
4622 | if (cu->language != language_ada) |
4623 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 4624 | break; |
c906108c | 4625 | |
c5aa993b | 4626 | case DW_ACCESS_protected: |
b4ba55a1 JB |
4627 | if (cu->language != language_ada) |
4628 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 4629 | break; |
c906108c | 4630 | |
c5aa993b JM |
4631 | case DW_ACCESS_public: |
4632 | break; | |
c906108c | 4633 | |
c5aa993b JM |
4634 | default: |
4635 | /* Unknown accessibility. Complain and treat it as public. */ | |
4636 | { | |
e2e0b3e5 | 4637 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 4638 | fieldp->accessibility); |
c5aa993b JM |
4639 | } |
4640 | break; | |
c906108c SS |
4641 | } |
4642 | if (nfields < fip->nbaseclasses) | |
4643 | { | |
7d0ccb61 | 4644 | switch (fieldp->virtuality) |
c906108c | 4645 | { |
c5aa993b JM |
4646 | case DW_VIRTUALITY_virtual: |
4647 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
4648 | if (cu->language == language_ada) |
4649 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
4650 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
4651 | break; | |
c906108c SS |
4652 | } |
4653 | } | |
c906108c SS |
4654 | } |
4655 | } | |
4656 | ||
c906108c SS |
4657 | /* Add a member function to the proper fieldlist. */ |
4658 | ||
4659 | static void | |
107d2387 | 4660 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 4661 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 4662 | { |
e7c27a73 | 4663 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4664 | struct attribute *attr; |
4665 | struct fnfieldlist *flp; | |
4666 | int i; | |
4667 | struct fn_field *fnp; | |
4668 | char *fieldname; | |
4669 | char *physname; | |
4670 | struct nextfnfield *new_fnfield; | |
f792889a | 4671 | struct type *this_type; |
c906108c | 4672 | |
b4ba55a1 JB |
4673 | if (cu->language == language_ada) |
4674 | error ("unexpected member function in Ada type"); | |
4675 | ||
2df3850c | 4676 | /* Get name of member function. */ |
39cbfefa DJ |
4677 | fieldname = dwarf2_name (die, cu); |
4678 | if (fieldname == NULL) | |
2df3850c | 4679 | return; |
c906108c | 4680 | |
2df3850c | 4681 | /* Get the mangled name. */ |
e142c38c | 4682 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
4683 | |
4684 | /* Look up member function name in fieldlist. */ | |
4685 | for (i = 0; i < fip->nfnfields; i++) | |
4686 | { | |
27bfe10e | 4687 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
4688 | break; |
4689 | } | |
4690 | ||
4691 | /* Create new list element if necessary. */ | |
4692 | if (i < fip->nfnfields) | |
4693 | flp = &fip->fnfieldlists[i]; | |
4694 | else | |
4695 | { | |
4696 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4697 | { | |
4698 | fip->fnfieldlists = (struct fnfieldlist *) | |
4699 | xrealloc (fip->fnfieldlists, | |
4700 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4701 | * sizeof (struct fnfieldlist)); |
c906108c | 4702 | if (fip->nfnfields == 0) |
c13c43fd | 4703 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
4704 | } |
4705 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
4706 | flp->name = fieldname; | |
4707 | flp->length = 0; | |
4708 | flp->head = NULL; | |
4709 | fip->nfnfields++; | |
4710 | } | |
4711 | ||
4712 | /* Create a new member function field and chain it to the field list | |
4713 | entry. */ | |
4714 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 4715 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
4716 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
4717 | new_fnfield->next = flp->head; | |
4718 | flp->head = new_fnfield; | |
4719 | flp->length++; | |
4720 | ||
4721 | /* Fill in the member function field info. */ | |
4722 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
4723 | /* The name is already allocated along with this objfile, so we don't |
4724 | need to duplicate it for the type. */ | |
4725 | fnp->physname = physname ? physname : ""; | |
c906108c | 4726 | fnp->type = alloc_type (objfile); |
f792889a DJ |
4727 | this_type = read_type_die (die, cu); |
4728 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 4729 | { |
f792889a | 4730 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 4731 | |
f792889a | 4732 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
4733 | of the method itself (TYPE_CODE_METHOD). */ |
4734 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
4735 | TYPE_TARGET_TYPE (this_type), |
4736 | TYPE_FIELDS (this_type), | |
4737 | TYPE_NFIELDS (this_type), | |
4738 | TYPE_VARARGS (this_type)); | |
c906108c SS |
4739 | |
4740 | /* Handle static member functions. | |
c5aa993b JM |
4741 | Dwarf2 has no clean way to discern C++ static and non-static |
4742 | member functions. G++ helps GDB by marking the first | |
4743 | parameter for non-static member functions (which is the | |
4744 | this pointer) as artificial. We obtain this information | |
4745 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 4746 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
4747 | fnp->voffset = VOFFSET_STATIC; |
4748 | } | |
4749 | else | |
e2e0b3e5 | 4750 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 4751 | physname); |
c906108c SS |
4752 | |
4753 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 4754 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 4755 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
4756 | |
4757 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
4758 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
4759 | ||
4760 | /* Get accessibility. */ | |
e142c38c | 4761 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4762 | if (attr) |
4763 | { | |
4764 | switch (DW_UNSND (attr)) | |
4765 | { | |
c5aa993b JM |
4766 | case DW_ACCESS_private: |
4767 | fnp->is_private = 1; | |
4768 | break; | |
4769 | case DW_ACCESS_protected: | |
4770 | fnp->is_protected = 1; | |
4771 | break; | |
c906108c SS |
4772 | } |
4773 | } | |
4774 | ||
b02dede2 | 4775 | /* Check for artificial methods. */ |
e142c38c | 4776 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
4777 | if (attr && DW_UNSND (attr) != 0) |
4778 | fnp->is_artificial = 1; | |
4779 | ||
0d564a31 DJ |
4780 | /* Get index in virtual function table if it is a virtual member |
4781 | function. For GCC, this is an offset in the appropriate | |
4782 | virtual table, as specified by DW_AT_containing_type. For | |
4783 | everyone else, it is an expression to be evaluated relative | |
4784 | to the object address. */ | |
4785 | ||
e142c38c | 4786 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
0d564a31 | 4787 | if (attr && fnp->fcontext) |
8e19ed76 PS |
4788 | { |
4789 | /* Support the .debug_loc offsets */ | |
4790 | if (attr_form_is_block (attr)) | |
4791 | { | |
e7c27a73 | 4792 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 4793 | } |
3690dd37 | 4794 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4795 | { |
4d3c2250 | 4796 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4797 | } |
4798 | else | |
4799 | { | |
4d3c2250 KB |
4800 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
4801 | fieldname); | |
8e19ed76 | 4802 | } |
0d564a31 DJ |
4803 | } |
4804 | else if (attr) | |
4805 | { | |
4806 | /* We only support trivial expressions here. This hack will work | |
ba950e4d | 4807 | for v3 classes, which always start with the vtable pointer. */ |
0d564a31 DJ |
4808 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0 |
4809 | && DW_BLOCK (attr)->data[0] == DW_OP_deref) | |
4810 | { | |
4811 | struct dwarf_block blk; | |
4812 | blk.size = DW_BLOCK (attr)->size - 1; | |
4813 | blk.data = DW_BLOCK (attr)->data + 1; | |
ba950e4d DJ |
4814 | fnp->voffset = decode_locdesc (&blk, cu); |
4815 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
4816 | dwarf2_complex_location_expr_complaint (); | |
4817 | else | |
4818 | fnp->voffset /= cu->header.addr_size; | |
0d564a31 DJ |
4819 | fnp->voffset += 2; |
4820 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
4821 | } | |
4822 | else | |
4823 | dwarf2_complex_location_expr_complaint (); | |
4824 | } | |
d48cc9dd DJ |
4825 | else |
4826 | { | |
4827 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
4828 | if (attr && DW_UNSND (attr)) | |
4829 | { | |
4830 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
4831 | complaint (&symfile_complaints, | |
4832 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
4833 | fieldname, die->offset); | |
4834 | TYPE_CPLUS_DYNAMIC (type) = 1; | |
4835 | } | |
4836 | } | |
c906108c SS |
4837 | } |
4838 | ||
4839 | /* Create the vector of member function fields, and attach it to the type. */ | |
4840 | ||
4841 | static void | |
fba45db2 | 4842 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4843 | struct dwarf2_cu *cu) |
c906108c SS |
4844 | { |
4845 | struct fnfieldlist *flp; | |
4846 | int total_length = 0; | |
4847 | int i; | |
4848 | ||
b4ba55a1 JB |
4849 | if (cu->language == language_ada) |
4850 | error ("unexpected member functions in Ada type"); | |
4851 | ||
c906108c SS |
4852 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
4853 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
4854 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
4855 | ||
4856 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
4857 | { | |
4858 | struct nextfnfield *nfp = flp->head; | |
4859 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
4860 | int k; | |
4861 | ||
4862 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
4863 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
4864 | fn_flp->fn_fields = (struct fn_field *) | |
4865 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
4866 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 4867 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
4868 | |
4869 | total_length += flp->length; | |
4870 | } | |
4871 | ||
4872 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
4873 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
4874 | } | |
4875 | ||
1168df01 JB |
4876 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
4877 | language, zero otherwise. */ | |
4878 | static int | |
4879 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
4880 | { | |
4881 | static const char vptr[] = "_vptr"; | |
987504bb | 4882 | static const char vtable[] = "vtable"; |
1168df01 | 4883 | |
987504bb JJ |
4884 | /* Look for the C++ and Java forms of the vtable. */ |
4885 | if ((cu->language == language_java | |
4886 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
4887 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
4888 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
4889 | return 1; |
4890 | ||
4891 | return 0; | |
4892 | } | |
4893 | ||
c0dd20ea | 4894 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
4895 | functions, with the ABI-specified layout. If TYPE describes |
4896 | such a structure, smash it into a member function type. | |
61049d3b DJ |
4897 | |
4898 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
4899 | This is GCC PR debug/28767. */ | |
c0dd20ea | 4900 | |
0b92b5bb TT |
4901 | static void |
4902 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 4903 | { |
0b92b5bb | 4904 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
4905 | |
4906 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
4907 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
4908 | return; | |
c0dd20ea DJ |
4909 | |
4910 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
4911 | if (TYPE_FIELD_NAME (type, 0) == NULL |
4912 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
4913 | || TYPE_FIELD_NAME (type, 1) == NULL | |
4914 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
4915 | return; | |
c0dd20ea DJ |
4916 | |
4917 | /* Find the type of the method. */ | |
0b92b5bb | 4918 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
4919 | if (pfn_type == NULL |
4920 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
4921 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 4922 | return; |
c0dd20ea DJ |
4923 | |
4924 | /* Look for the "this" argument. */ | |
4925 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
4926 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 4927 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 4928 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 4929 | return; |
c0dd20ea DJ |
4930 | |
4931 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
4932 | new_type = alloc_type (objfile); |
4933 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
4934 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
4935 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 4936 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 4937 | } |
1168df01 | 4938 | |
c906108c SS |
4939 | /* Called when we find the DIE that starts a structure or union scope |
4940 | (definition) to process all dies that define the members of the | |
4941 | structure or union. | |
4942 | ||
4943 | NOTE: we need to call struct_type regardless of whether or not the | |
4944 | DIE has an at_name attribute, since it might be an anonymous | |
4945 | structure or union. This gets the type entered into our set of | |
4946 | user defined types. | |
4947 | ||
4948 | However, if the structure is incomplete (an opaque struct/union) | |
4949 | then suppress creating a symbol table entry for it since gdb only | |
4950 | wants to find the one with the complete definition. Note that if | |
4951 | it is complete, we just call new_symbol, which does it's own | |
4952 | checking about whether the struct/union is anonymous or not (and | |
4953 | suppresses creating a symbol table entry itself). */ | |
4954 | ||
f792889a | 4955 | static struct type * |
134d01f1 | 4956 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4957 | { |
e7c27a73 | 4958 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4959 | struct type *type; |
4960 | struct attribute *attr; | |
39cbfefa | 4961 | char *name; |
0114d602 | 4962 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c | 4963 | |
348e048f DE |
4964 | /* If the definition of this type lives in .debug_types, read that type. |
4965 | Don't follow DW_AT_specification though, that will take us back up | |
4966 | the chain and we want to go down. */ | |
4967 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
4968 | if (attr) | |
4969 | { | |
4970 | struct dwarf2_cu *type_cu = cu; | |
4971 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
4972 | /* We could just recurse on read_structure_type, but we need to call | |
4973 | get_die_type to ensure only one type for this DIE is created. | |
4974 | This is important, for example, because for c++ classes we need | |
4975 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
4976 | type = read_type_die (type_die, type_cu); | |
4977 | return set_die_type (die, type, cu); | |
4978 | } | |
4979 | ||
c0dd20ea | 4980 | type = alloc_type (objfile); |
c906108c | 4981 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 4982 | |
39cbfefa DJ |
4983 | name = dwarf2_name (die, cu); |
4984 | if (name != NULL) | |
c906108c | 4985 | { |
987504bb JJ |
4986 | if (cu->language == language_cplus |
4987 | || cu->language == language_java) | |
63d06c5c | 4988 | { |
0114d602 DJ |
4989 | const char *new_prefix = determine_class_name (die, cu); |
4990 | TYPE_TAG_NAME (type) = (char *) new_prefix; | |
63d06c5c DC |
4991 | } |
4992 | else | |
4993 | { | |
d8151005 DJ |
4994 | /* The name is already allocated along with this objfile, so |
4995 | we don't need to duplicate it for the type. */ | |
39cbfefa | 4996 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 4997 | } |
c906108c SS |
4998 | } |
4999 | ||
5000 | if (die->tag == DW_TAG_structure_type) | |
5001 | { | |
5002 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
5003 | } | |
5004 | else if (die->tag == DW_TAG_union_type) | |
5005 | { | |
5006 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
5007 | } | |
5008 | else | |
5009 | { | |
5010 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 5011 | in gdbtypes.h. */ |
c906108c SS |
5012 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
5013 | } | |
5014 | ||
e142c38c | 5015 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5016 | if (attr) |
5017 | { | |
5018 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5019 | } | |
5020 | else | |
5021 | { | |
5022 | TYPE_LENGTH (type) = 0; | |
5023 | } | |
5024 | ||
876cecd0 | 5025 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 5026 | if (die_is_declaration (die, cu)) |
876cecd0 | 5027 | TYPE_STUB (type) = 1; |
dc718098 | 5028 | |
b4ba55a1 JB |
5029 | set_descriptive_type (type, die, cu); |
5030 | ||
c906108c SS |
5031 | /* We need to add the type field to the die immediately so we don't |
5032 | infinitely recurse when dealing with pointers to the structure | |
5033 | type within the structure itself. */ | |
1c379e20 | 5034 | set_die_type (die, type, cu); |
c906108c | 5035 | |
e142c38c | 5036 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
5037 | { |
5038 | struct field_info fi; | |
5039 | struct die_info *child_die; | |
c906108c SS |
5040 | |
5041 | memset (&fi, 0, sizeof (struct field_info)); | |
5042 | ||
639d11d3 | 5043 | child_die = die->child; |
c906108c SS |
5044 | |
5045 | while (child_die && child_die->tag) | |
5046 | { | |
a9a9bd0f DC |
5047 | if (child_die->tag == DW_TAG_member |
5048 | || child_die->tag == DW_TAG_variable) | |
c906108c | 5049 | { |
a9a9bd0f DC |
5050 | /* NOTE: carlton/2002-11-05: A C++ static data member |
5051 | should be a DW_TAG_member that is a declaration, but | |
5052 | all versions of G++ as of this writing (so through at | |
5053 | least 3.2.1) incorrectly generate DW_TAG_variable | |
5054 | tags for them instead. */ | |
e7c27a73 | 5055 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5056 | } |
8713b1b1 | 5057 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
5058 | { |
5059 | /* C++ member function. */ | |
e7c27a73 | 5060 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
5061 | } |
5062 | else if (child_die->tag == DW_TAG_inheritance) | |
5063 | { | |
5064 | /* C++ base class field. */ | |
e7c27a73 | 5065 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 5066 | } |
c906108c SS |
5067 | child_die = sibling_die (child_die); |
5068 | } | |
5069 | ||
5070 | /* Attach fields and member functions to the type. */ | |
5071 | if (fi.nfields) | |
e7c27a73 | 5072 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
5073 | if (fi.nfnfields) |
5074 | { | |
e7c27a73 | 5075 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 5076 | |
c5aa993b | 5077 | /* Get the type which refers to the base class (possibly this |
c906108c | 5078 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
5079 | class from the DW_AT_containing_type attribute. This use of |
5080 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 5081 | |
e142c38c | 5082 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 5083 | { |
e7c27a73 | 5084 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
5085 | |
5086 | TYPE_VPTR_BASETYPE (type) = t; | |
5087 | if (type == t) | |
5088 | { | |
c906108c SS |
5089 | int i; |
5090 | ||
5091 | /* Our own class provides vtbl ptr. */ | |
5092 | for (i = TYPE_NFIELDS (t) - 1; | |
5093 | i >= TYPE_N_BASECLASSES (t); | |
5094 | --i) | |
5095 | { | |
5096 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
5097 | ||
1168df01 | 5098 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
5099 | { |
5100 | TYPE_VPTR_FIELDNO (type) = i; | |
5101 | break; | |
5102 | } | |
5103 | } | |
5104 | ||
5105 | /* Complain if virtual function table field not found. */ | |
5106 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 5107 | complaint (&symfile_complaints, |
e2e0b3e5 | 5108 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
5109 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
5110 | ""); | |
c906108c SS |
5111 | } |
5112 | else | |
5113 | { | |
5114 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
5115 | } | |
5116 | } | |
f6235d4c EZ |
5117 | else if (cu->producer |
5118 | && strncmp (cu->producer, | |
5119 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
5120 | { | |
5121 | /* The IBM XLC compiler does not provide direct indication | |
5122 | of the containing type, but the vtable pointer is | |
5123 | always named __vfp. */ | |
5124 | ||
5125 | int i; | |
5126 | ||
5127 | for (i = TYPE_NFIELDS (type) - 1; | |
5128 | i >= TYPE_N_BASECLASSES (type); | |
5129 | --i) | |
5130 | { | |
5131 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
5132 | { | |
5133 | TYPE_VPTR_FIELDNO (type) = i; | |
5134 | TYPE_VPTR_BASETYPE (type) = type; | |
5135 | break; | |
5136 | } | |
5137 | } | |
5138 | } | |
c906108c | 5139 | } |
c906108c | 5140 | } |
63d06c5c | 5141 | |
0b92b5bb TT |
5142 | quirk_gcc_member_function_pointer (type, cu->objfile); |
5143 | ||
0114d602 | 5144 | do_cleanups (back_to); |
f792889a | 5145 | return type; |
c906108c SS |
5146 | } |
5147 | ||
134d01f1 DJ |
5148 | static void |
5149 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5150 | { | |
5151 | struct objfile *objfile = cu->objfile; | |
90aeadfc | 5152 | struct die_info *child_die = die->child; |
f792889a | 5153 | struct type *this_type; |
c906108c | 5154 | |
f792889a DJ |
5155 | this_type = get_die_type (die, cu); |
5156 | if (this_type == NULL) | |
5157 | this_type = read_structure_type (die, cu); | |
c906108c | 5158 | |
90aeadfc DC |
5159 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
5160 | snapshots) has been known to create a die giving a declaration | |
5161 | for a class that has, as a child, a die giving a definition for a | |
5162 | nested class. So we have to process our children even if the | |
5163 | current die is a declaration. Normally, of course, a declaration | |
5164 | won't have any children at all. */ | |
134d01f1 | 5165 | |
90aeadfc DC |
5166 | while (child_die != NULL && child_die->tag) |
5167 | { | |
5168 | if (child_die->tag == DW_TAG_member | |
5169 | || child_die->tag == DW_TAG_variable | |
5170 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 5171 | { |
90aeadfc | 5172 | /* Do nothing. */ |
134d01f1 | 5173 | } |
90aeadfc DC |
5174 | else |
5175 | process_die (child_die, cu); | |
134d01f1 | 5176 | |
90aeadfc | 5177 | child_die = sibling_die (child_die); |
134d01f1 DJ |
5178 | } |
5179 | ||
fa4028e9 JB |
5180 | /* Do not consider external references. According to the DWARF standard, |
5181 | these DIEs are identified by the fact that they have no byte_size | |
5182 | attribute, and a declaration attribute. */ | |
5183 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
5184 | || !die_is_declaration (die, cu)) | |
f792889a | 5185 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
5186 | } |
5187 | ||
5188 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
5189 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 5190 | |
f792889a | 5191 | static struct type * |
134d01f1 | 5192 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5193 | { |
e7c27a73 | 5194 | struct objfile *objfile = cu->objfile; |
c906108c | 5195 | struct type *type; |
c906108c | 5196 | struct attribute *attr; |
0114d602 | 5197 | const char *name; |
134d01f1 | 5198 | |
348e048f DE |
5199 | /* If the definition of this type lives in .debug_types, read that type. |
5200 | Don't follow DW_AT_specification though, that will take us back up | |
5201 | the chain and we want to go down. */ | |
5202 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
5203 | if (attr) | |
5204 | { | |
5205 | struct dwarf2_cu *type_cu = cu; | |
5206 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
5207 | type = read_type_die (type_die, type_cu); | |
5208 | return set_die_type (die, type, cu); | |
5209 | } | |
5210 | ||
c906108c SS |
5211 | type = alloc_type (objfile); |
5212 | ||
5213 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
0114d602 | 5214 | name = dwarf2_full_name (die, cu); |
39cbfefa | 5215 | if (name != NULL) |
0114d602 | 5216 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 5217 | |
e142c38c | 5218 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5219 | if (attr) |
5220 | { | |
5221 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5222 | } | |
5223 | else | |
5224 | { | |
5225 | TYPE_LENGTH (type) = 0; | |
5226 | } | |
5227 | ||
137033e9 JB |
5228 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
5229 | declared as private in the package spec, and then defined only | |
5230 | inside the package body. Such types are known as Taft Amendment | |
5231 | Types. When another package uses such a type, an incomplete DIE | |
5232 | may be generated by the compiler. */ | |
02eb380e | 5233 | if (die_is_declaration (die, cu)) |
876cecd0 | 5234 | TYPE_STUB (type) = 1; |
02eb380e | 5235 | |
f792889a | 5236 | return set_die_type (die, type, cu); |
134d01f1 DJ |
5237 | } |
5238 | ||
8176b9b8 | 5239 | /* Determine the name of the type represented by DIE, which should be |
0114d602 DJ |
5240 | a named C++ or Java compound type. Return the name in question, |
5241 | allocated on the objfile obstack. */ | |
8176b9b8 | 5242 | |
0114d602 | 5243 | static const char * |
8176b9b8 DC |
5244 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) |
5245 | { | |
0114d602 | 5246 | const char *new_prefix = NULL; |
8176b9b8 DC |
5247 | |
5248 | /* If we don't have namespace debug info, guess the name by trying | |
5249 | to demangle the names of members, just like we did in | |
72bf9492 | 5250 | guess_structure_name. */ |
8176b9b8 DC |
5251 | if (!processing_has_namespace_info) |
5252 | { | |
5253 | struct die_info *child; | |
5254 | ||
5255 | for (child = die->child; | |
5256 | child != NULL && child->tag != 0; | |
5257 | child = sibling_die (child)) | |
5258 | { | |
5259 | if (child->tag == DW_TAG_subprogram) | |
5260 | { | |
0114d602 | 5261 | char *phys_prefix |
31c27f77 JJ |
5262 | = language_class_name_from_physname (cu->language_defn, |
5263 | dwarf2_linkage_name | |
8176b9b8 DC |
5264 | (child, cu)); |
5265 | ||
0114d602 DJ |
5266 | if (phys_prefix != NULL) |
5267 | { | |
5268 | new_prefix | |
5269 | = obsavestring (phys_prefix, strlen (phys_prefix), | |
5270 | &cu->objfile->objfile_obstack); | |
5271 | xfree (phys_prefix); | |
5272 | break; | |
5273 | } | |
8176b9b8 DC |
5274 | } |
5275 | } | |
5276 | } | |
5277 | ||
5278 | if (new_prefix == NULL) | |
0114d602 | 5279 | new_prefix = dwarf2_full_name (die, cu); |
8176b9b8 DC |
5280 | |
5281 | return new_prefix; | |
5282 | } | |
5283 | ||
134d01f1 DJ |
5284 | /* Given a pointer to a die which begins an enumeration, process all |
5285 | the dies that define the members of the enumeration, and create the | |
5286 | symbol for the enumeration type. | |
5287 | ||
5288 | NOTE: We reverse the order of the element list. */ | |
5289 | ||
5290 | static void | |
5291 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5292 | { | |
5293 | struct objfile *objfile = cu->objfile; | |
5294 | struct die_info *child_die; | |
5295 | struct field *fields; | |
134d01f1 DJ |
5296 | struct symbol *sym; |
5297 | int num_fields; | |
5298 | int unsigned_enum = 1; | |
39cbfefa | 5299 | char *name; |
f792889a | 5300 | struct type *this_type; |
134d01f1 | 5301 | |
c906108c SS |
5302 | num_fields = 0; |
5303 | fields = NULL; | |
f792889a DJ |
5304 | this_type = get_die_type (die, cu); |
5305 | if (this_type == NULL) | |
5306 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 5307 | if (die->child != NULL) |
c906108c | 5308 | { |
639d11d3 | 5309 | child_die = die->child; |
c906108c SS |
5310 | while (child_die && child_die->tag) |
5311 | { | |
5312 | if (child_die->tag != DW_TAG_enumerator) | |
5313 | { | |
e7c27a73 | 5314 | process_die (child_die, cu); |
c906108c SS |
5315 | } |
5316 | else | |
5317 | { | |
39cbfefa DJ |
5318 | name = dwarf2_name (child_die, cu); |
5319 | if (name) | |
c906108c | 5320 | { |
f792889a | 5321 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
5322 | if (SYMBOL_VALUE (sym) < 0) |
5323 | unsigned_enum = 0; | |
5324 | ||
5325 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
5326 | { | |
5327 | fields = (struct field *) | |
5328 | xrealloc (fields, | |
5329 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 5330 | * sizeof (struct field)); |
c906108c SS |
5331 | } |
5332 | ||
3567439c | 5333 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 5334 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 5335 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
5336 | FIELD_BITSIZE (fields[num_fields]) = 0; |
5337 | ||
5338 | num_fields++; | |
5339 | } | |
5340 | } | |
5341 | ||
5342 | child_die = sibling_die (child_die); | |
5343 | } | |
5344 | ||
5345 | if (num_fields) | |
5346 | { | |
f792889a DJ |
5347 | TYPE_NFIELDS (this_type) = num_fields; |
5348 | TYPE_FIELDS (this_type) = (struct field *) | |
5349 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
5350 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 5351 | sizeof (struct field) * num_fields); |
b8c9b27d | 5352 | xfree (fields); |
c906108c SS |
5353 | } |
5354 | if (unsigned_enum) | |
876cecd0 | 5355 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 5356 | } |
134d01f1 | 5357 | |
f792889a | 5358 | new_symbol (die, this_type, cu); |
c906108c SS |
5359 | } |
5360 | ||
5361 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
5362 | the DIE's type field. For now, this only handles one dimensional | |
5363 | arrays. */ | |
5364 | ||
f792889a | 5365 | static struct type * |
e7c27a73 | 5366 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5367 | { |
e7c27a73 | 5368 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5369 | struct die_info *child_die; |
5370 | struct type *type = NULL; | |
5371 | struct type *element_type, *range_type, *index_type; | |
5372 | struct type **range_types = NULL; | |
5373 | struct attribute *attr; | |
5374 | int ndim = 0; | |
5375 | struct cleanup *back_to; | |
39cbfefa | 5376 | char *name; |
c906108c | 5377 | |
e7c27a73 | 5378 | element_type = die_type (die, cu); |
c906108c SS |
5379 | |
5380 | /* Irix 6.2 native cc creates array types without children for | |
5381 | arrays with unspecified length. */ | |
639d11d3 | 5382 | if (die->child == NULL) |
c906108c | 5383 | { |
46bf5051 | 5384 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5385 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
5386 | type = create_array_type (NULL, element_type, range_type); |
5387 | return set_die_type (die, type, cu); | |
c906108c SS |
5388 | } |
5389 | ||
5390 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 5391 | child_die = die->child; |
c906108c SS |
5392 | while (child_die && child_die->tag) |
5393 | { | |
5394 | if (child_die->tag == DW_TAG_subrange_type) | |
5395 | { | |
f792889a DJ |
5396 | struct type *child_type = read_type_die (child_die, cu); |
5397 | if (child_type != NULL) | |
a02abb62 JB |
5398 | { |
5399 | /* The range type was succesfully read. Save it for | |
5400 | the array type creation. */ | |
5401 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
5402 | { | |
5403 | range_types = (struct type **) | |
5404 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
5405 | * sizeof (struct type *)); | |
5406 | if (ndim == 0) | |
5407 | make_cleanup (free_current_contents, &range_types); | |
5408 | } | |
f792889a | 5409 | range_types[ndim++] = child_type; |
a02abb62 | 5410 | } |
c906108c SS |
5411 | } |
5412 | child_die = sibling_die (child_die); | |
5413 | } | |
5414 | ||
5415 | /* Dwarf2 dimensions are output from left to right, create the | |
5416 | necessary array types in backwards order. */ | |
7ca2d3a3 | 5417 | |
c906108c | 5418 | type = element_type; |
7ca2d3a3 DL |
5419 | |
5420 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
5421 | { | |
5422 | int i = 0; | |
5423 | while (i < ndim) | |
5424 | type = create_array_type (NULL, type, range_types[i++]); | |
5425 | } | |
5426 | else | |
5427 | { | |
5428 | while (ndim-- > 0) | |
5429 | type = create_array_type (NULL, type, range_types[ndim]); | |
5430 | } | |
c906108c | 5431 | |
f5f8a009 EZ |
5432 | /* Understand Dwarf2 support for vector types (like they occur on |
5433 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
5434 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
5435 | custom vendor extension. The main difference between a regular | |
5436 | array and the vector variant is that vectors are passed by value | |
5437 | to functions. */ | |
e142c38c | 5438 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 5439 | if (attr) |
ea37ba09 | 5440 | make_vector_type (type); |
f5f8a009 | 5441 | |
39cbfefa DJ |
5442 | name = dwarf2_name (die, cu); |
5443 | if (name) | |
5444 | TYPE_NAME (type) = name; | |
714e295e | 5445 | |
b4ba55a1 JB |
5446 | set_descriptive_type (type, die, cu); |
5447 | ||
c906108c SS |
5448 | do_cleanups (back_to); |
5449 | ||
5450 | /* Install the type in the die. */ | |
f792889a | 5451 | return set_die_type (die, type, cu); |
c906108c SS |
5452 | } |
5453 | ||
7ca2d3a3 DL |
5454 | static enum dwarf_array_dim_ordering |
5455 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
5456 | { | |
5457 | struct attribute *attr; | |
5458 | ||
5459 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
5460 | ||
5461 | if (attr) return DW_SND (attr); | |
5462 | ||
5463 | /* | |
5464 | GNU F77 is a special case, as at 08/2004 array type info is the | |
5465 | opposite order to the dwarf2 specification, but data is still | |
5466 | laid out as per normal fortran. | |
5467 | ||
5468 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
5469 | version checking. | |
5470 | */ | |
5471 | ||
905e0470 PM |
5472 | if (cu->language == language_fortran |
5473 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
5474 | { |
5475 | return DW_ORD_row_major; | |
5476 | } | |
5477 | ||
5478 | switch (cu->language_defn->la_array_ordering) | |
5479 | { | |
5480 | case array_column_major: | |
5481 | return DW_ORD_col_major; | |
5482 | case array_row_major: | |
5483 | default: | |
5484 | return DW_ORD_row_major; | |
5485 | }; | |
5486 | } | |
5487 | ||
72019c9c GM |
5488 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
5489 | the DIE's type field. */ | |
5490 | ||
f792889a | 5491 | static struct type * |
72019c9c GM |
5492 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
5493 | { | |
f792889a DJ |
5494 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
5495 | ||
5496 | return set_die_type (die, set_type, cu); | |
72019c9c | 5497 | } |
7ca2d3a3 | 5498 | |
c906108c SS |
5499 | /* First cut: install each common block member as a global variable. */ |
5500 | ||
5501 | static void | |
e7c27a73 | 5502 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5503 | { |
5504 | struct die_info *child_die; | |
5505 | struct attribute *attr; | |
5506 | struct symbol *sym; | |
5507 | CORE_ADDR base = (CORE_ADDR) 0; | |
5508 | ||
e142c38c | 5509 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
5510 | if (attr) |
5511 | { | |
8e19ed76 PS |
5512 | /* Support the .debug_loc offsets */ |
5513 | if (attr_form_is_block (attr)) | |
5514 | { | |
e7c27a73 | 5515 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 5516 | } |
3690dd37 | 5517 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 5518 | { |
4d3c2250 | 5519 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5520 | } |
5521 | else | |
5522 | { | |
4d3c2250 KB |
5523 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5524 | "common block member"); | |
8e19ed76 | 5525 | } |
c906108c | 5526 | } |
639d11d3 | 5527 | if (die->child != NULL) |
c906108c | 5528 | { |
639d11d3 | 5529 | child_die = die->child; |
c906108c SS |
5530 | while (child_die && child_die->tag) |
5531 | { | |
e7c27a73 | 5532 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 5533 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
5534 | if (attr) |
5535 | { | |
d4b96c9a JK |
5536 | CORE_ADDR byte_offset = 0; |
5537 | ||
5538 | if (attr_form_is_section_offset (attr)) | |
5539 | dwarf2_complex_location_expr_complaint (); | |
5540 | else if (attr_form_is_constant (attr)) | |
5541 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
5542 | else if (attr_form_is_block (attr)) | |
5543 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
5544 | else | |
5545 | dwarf2_complex_location_expr_complaint (); | |
5546 | ||
5547 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
5548 | add_symbol_to_list (sym, &global_symbols); |
5549 | } | |
5550 | child_die = sibling_die (child_die); | |
5551 | } | |
5552 | } | |
5553 | } | |
5554 | ||
0114d602 | 5555 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 5556 | |
0114d602 DJ |
5557 | static struct type * |
5558 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 5559 | { |
e7c27a73 | 5560 | struct objfile *objfile = cu->objfile; |
0114d602 | 5561 | const char *previous_prefix, *name; |
9219021c | 5562 | int is_anonymous; |
0114d602 DJ |
5563 | struct type *type; |
5564 | ||
5565 | /* For extensions, reuse the type of the original namespace. */ | |
5566 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
5567 | { | |
5568 | struct die_info *ext_die; | |
5569 | struct dwarf2_cu *ext_cu = cu; | |
5570 | ext_die = dwarf2_extension (die, &ext_cu); | |
5571 | type = read_type_die (ext_die, ext_cu); | |
5572 | return set_die_type (die, type, cu); | |
5573 | } | |
9219021c | 5574 | |
e142c38c | 5575 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
5576 | |
5577 | /* Now build the name of the current namespace. */ | |
5578 | ||
0114d602 DJ |
5579 | previous_prefix = determine_prefix (die, cu); |
5580 | if (previous_prefix[0] != '\0') | |
5581 | name = typename_concat (&objfile->objfile_obstack, | |
5582 | previous_prefix, name, cu); | |
5583 | ||
5584 | /* Create the type. */ | |
5585 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
5586 | objfile); | |
5587 | TYPE_NAME (type) = (char *) name; | |
5588 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5589 | ||
5590 | set_die_type (die, type, cu); | |
5591 | ||
5592 | return type; | |
5593 | } | |
5594 | ||
5595 | /* Read a C++ namespace. */ | |
5596 | ||
5597 | static void | |
5598 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
5599 | { | |
5600 | struct objfile *objfile = cu->objfile; | |
5601 | const char *name; | |
5602 | int is_anonymous; | |
9219021c | 5603 | |
5c4e30ca DC |
5604 | /* Add a symbol associated to this if we haven't seen the namespace |
5605 | before. Also, add a using directive if it's an anonymous | |
5606 | namespace. */ | |
9219021c | 5607 | |
f2f0e013 | 5608 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
5609 | { |
5610 | struct type *type; | |
5611 | ||
0114d602 | 5612 | type = read_type_die (die, cu); |
e7c27a73 | 5613 | new_symbol (die, type, cu); |
5c4e30ca | 5614 | |
0114d602 | 5615 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 5616 | if (is_anonymous) |
0114d602 DJ |
5617 | { |
5618 | const char *previous_prefix = determine_prefix (die, cu); | |
794684b6 | 5619 | cp_add_using_directive (previous_prefix, TYPE_NAME (type)); |
0114d602 | 5620 | } |
5c4e30ca | 5621 | } |
9219021c | 5622 | |
639d11d3 | 5623 | if (die->child != NULL) |
d9fa45fe | 5624 | { |
639d11d3 | 5625 | struct die_info *child_die = die->child; |
d9fa45fe DC |
5626 | |
5627 | while (child_die && child_die->tag) | |
5628 | { | |
e7c27a73 | 5629 | process_die (child_die, cu); |
d9fa45fe DC |
5630 | child_die = sibling_die (child_die); |
5631 | } | |
5632 | } | |
38d518c9 EZ |
5633 | } |
5634 | ||
5d7cb8df JK |
5635 | /* Read a Fortran module. */ |
5636 | ||
5637 | static void | |
5638 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
5639 | { | |
5640 | struct die_info *child_die = die->child; | |
5641 | ||
5642 | /* FIXME: Support the separate Fortran module namespaces. */ | |
5643 | ||
5644 | while (child_die && child_die->tag) | |
5645 | { | |
5646 | process_die (child_die, cu); | |
5647 | child_die = sibling_die (child_die); | |
5648 | } | |
5649 | } | |
5650 | ||
38d518c9 EZ |
5651 | /* Return the name of the namespace represented by DIE. Set |
5652 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
5653 | namespace. */ | |
5654 | ||
5655 | static const char * | |
e142c38c | 5656 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
5657 | { |
5658 | struct die_info *current_die; | |
5659 | const char *name = NULL; | |
5660 | ||
5661 | /* Loop through the extensions until we find a name. */ | |
5662 | ||
5663 | for (current_die = die; | |
5664 | current_die != NULL; | |
f2f0e013 | 5665 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 5666 | { |
e142c38c | 5667 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
5668 | if (name != NULL) |
5669 | break; | |
5670 | } | |
5671 | ||
5672 | /* Is it an anonymous namespace? */ | |
5673 | ||
5674 | *is_anonymous = (name == NULL); | |
5675 | if (*is_anonymous) | |
5676 | name = "(anonymous namespace)"; | |
5677 | ||
5678 | return name; | |
d9fa45fe DC |
5679 | } |
5680 | ||
c906108c SS |
5681 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
5682 | the user defined type vector. */ | |
5683 | ||
f792889a | 5684 | static struct type * |
e7c27a73 | 5685 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5686 | { |
5e2b427d | 5687 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 5688 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 5689 | struct type *type; |
8b2dbe47 KB |
5690 | struct attribute *attr_byte_size; |
5691 | struct attribute *attr_address_class; | |
5692 | int byte_size, addr_class; | |
c906108c | 5693 | |
e7c27a73 | 5694 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 5695 | |
e142c38c | 5696 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
5697 | if (attr_byte_size) |
5698 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 5699 | else |
8b2dbe47 KB |
5700 | byte_size = cu_header->addr_size; |
5701 | ||
e142c38c | 5702 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
5703 | if (attr_address_class) |
5704 | addr_class = DW_UNSND (attr_address_class); | |
5705 | else | |
5706 | addr_class = DW_ADDR_none; | |
5707 | ||
5708 | /* If the pointer size or address class is different than the | |
5709 | default, create a type variant marked as such and set the | |
5710 | length accordingly. */ | |
5711 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 5712 | { |
5e2b427d | 5713 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
5714 | { |
5715 | int type_flags; | |
5716 | ||
849957d9 | 5717 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 5718 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
5719 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
5720 | == 0); | |
8b2dbe47 KB |
5721 | type = make_type_with_address_space (type, type_flags); |
5722 | } | |
5723 | else if (TYPE_LENGTH (type) != byte_size) | |
5724 | { | |
e2e0b3e5 | 5725 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
5726 | } |
5727 | else { | |
5728 | /* Should we also complain about unhandled address classes? */ | |
5729 | } | |
c906108c | 5730 | } |
8b2dbe47 KB |
5731 | |
5732 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 5733 | return set_die_type (die, type, cu); |
c906108c SS |
5734 | } |
5735 | ||
5736 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
5737 | the user defined type vector. */ | |
5738 | ||
f792889a | 5739 | static struct type * |
e7c27a73 | 5740 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5741 | { |
e7c27a73 | 5742 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5743 | struct type *type; |
5744 | struct type *to_type; | |
5745 | struct type *domain; | |
5746 | ||
e7c27a73 DJ |
5747 | to_type = die_type (die, cu); |
5748 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
5749 | |
5750 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
5751 | type = lookup_methodptr_type (to_type); | |
5752 | else | |
5753 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 5754 | |
f792889a | 5755 | return set_die_type (die, type, cu); |
c906108c SS |
5756 | } |
5757 | ||
5758 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
5759 | the user defined type vector. */ | |
5760 | ||
f792889a | 5761 | static struct type * |
e7c27a73 | 5762 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5763 | { |
e7c27a73 | 5764 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5765 | struct type *type; |
5766 | struct attribute *attr; | |
5767 | ||
e7c27a73 | 5768 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 5769 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5770 | if (attr) |
5771 | { | |
5772 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5773 | } | |
5774 | else | |
5775 | { | |
107d2387 | 5776 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 5777 | } |
f792889a | 5778 | return set_die_type (die, type, cu); |
c906108c SS |
5779 | } |
5780 | ||
f792889a | 5781 | static struct type * |
e7c27a73 | 5782 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5783 | { |
f792889a | 5784 | struct type *base_type, *cv_type; |
c906108c | 5785 | |
e7c27a73 | 5786 | base_type = die_type (die, cu); |
f792889a DJ |
5787 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
5788 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5789 | } |
5790 | ||
f792889a | 5791 | static struct type * |
e7c27a73 | 5792 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5793 | { |
f792889a | 5794 | struct type *base_type, *cv_type; |
c906108c | 5795 | |
e7c27a73 | 5796 | base_type = die_type (die, cu); |
f792889a DJ |
5797 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
5798 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5799 | } |
5800 | ||
5801 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
5802 | the user defined type vector. It isn't really a user defined type, | |
5803 | but it behaves like one, with other DIE's using an AT_user_def_type | |
5804 | attribute to reference it. */ | |
5805 | ||
f792889a | 5806 | static struct type * |
e7c27a73 | 5807 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5808 | { |
e7c27a73 | 5809 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 5810 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5811 | struct type *type, *range_type, *index_type, *char_type; |
5812 | struct attribute *attr; | |
5813 | unsigned int length; | |
5814 | ||
e142c38c | 5815 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
5816 | if (attr) |
5817 | { | |
5818 | length = DW_UNSND (attr); | |
5819 | } | |
5820 | else | |
5821 | { | |
b21b22e0 | 5822 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 5823 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
5824 | if (attr) |
5825 | { | |
5826 | length = DW_UNSND (attr); | |
5827 | } | |
5828 | else | |
5829 | { | |
5830 | length = 1; | |
5831 | } | |
c906108c | 5832 | } |
6ccb9162 | 5833 | |
46bf5051 | 5834 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 5835 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
5836 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
5837 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 5838 | |
f792889a | 5839 | return set_die_type (die, type, cu); |
c906108c SS |
5840 | } |
5841 | ||
5842 | /* Handle DIES due to C code like: | |
5843 | ||
5844 | struct foo | |
c5aa993b JM |
5845 | { |
5846 | int (*funcp)(int a, long l); | |
5847 | int b; | |
5848 | }; | |
c906108c SS |
5849 | |
5850 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 5851 | */ |
c906108c | 5852 | |
f792889a | 5853 | static struct type * |
e7c27a73 | 5854 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5855 | { |
5856 | struct type *type; /* Type that this function returns */ | |
5857 | struct type *ftype; /* Function that returns above type */ | |
5858 | struct attribute *attr; | |
5859 | ||
e7c27a73 | 5860 | type = die_type (die, cu); |
0c8b41f1 | 5861 | ftype = lookup_function_type (type); |
c906108c | 5862 | |
5b8101ae | 5863 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 5864 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 5865 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 5866 | || cu->language == language_cplus |
5b8101ae PM |
5867 | || cu->language == language_java |
5868 | || cu->language == language_pascal) | |
876cecd0 | 5869 | TYPE_PROTOTYPED (ftype) = 1; |
c906108c | 5870 | |
c055b101 CV |
5871 | /* Store the calling convention in the type if it's available in |
5872 | the subroutine die. Otherwise set the calling convention to | |
5873 | the default value DW_CC_normal. */ | |
5874 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
5875 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
5876 | |
5877 | /* We need to add the subroutine type to the die immediately so | |
5878 | we don't infinitely recurse when dealing with parameters | |
5879 | declared as the same subroutine type. */ | |
5880 | set_die_type (die, ftype, cu); | |
c055b101 | 5881 | |
639d11d3 | 5882 | if (die->child != NULL) |
c906108c SS |
5883 | { |
5884 | struct die_info *child_die; | |
5885 | int nparams = 0; | |
5886 | int iparams = 0; | |
5887 | ||
5888 | /* Count the number of parameters. | |
5889 | FIXME: GDB currently ignores vararg functions, but knows about | |
5890 | vararg member functions. */ | |
639d11d3 | 5891 | child_die = die->child; |
c906108c SS |
5892 | while (child_die && child_die->tag) |
5893 | { | |
5894 | if (child_die->tag == DW_TAG_formal_parameter) | |
5895 | nparams++; | |
5896 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 5897 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
5898 | child_die = sibling_die (child_die); |
5899 | } | |
5900 | ||
5901 | /* Allocate storage for parameters and fill them in. */ | |
5902 | TYPE_NFIELDS (ftype) = nparams; | |
5903 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 5904 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 5905 | |
639d11d3 | 5906 | child_die = die->child; |
c906108c SS |
5907 | while (child_die && child_die->tag) |
5908 | { | |
5909 | if (child_die->tag == DW_TAG_formal_parameter) | |
5910 | { | |
5911 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
5912 | member functions. G++ helps GDB by marking the first |
5913 | parameter for non-static member functions (which is the | |
5914 | this pointer) as artificial. We pass this information | |
5915 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 5916 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
5917 | if (attr) |
5918 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
5919 | else | |
5920 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 5921 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
5922 | iparams++; |
5923 | } | |
5924 | child_die = sibling_die (child_die); | |
5925 | } | |
5926 | } | |
5927 | ||
76c10ea2 | 5928 | return ftype; |
c906108c SS |
5929 | } |
5930 | ||
f792889a | 5931 | static struct type * |
e7c27a73 | 5932 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5933 | { |
e7c27a73 | 5934 | struct objfile *objfile = cu->objfile; |
2f038fcb | 5935 | struct attribute *attr; |
0114d602 | 5936 | const char *name = NULL; |
f792889a | 5937 | struct type *this_type; |
c906108c | 5938 | |
0114d602 | 5939 | name = dwarf2_full_name (die, cu); |
f792889a | 5940 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
5941 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
5942 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
5943 | set_die_type (die, this_type, cu); |
5944 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
5945 | return this_type; | |
c906108c SS |
5946 | } |
5947 | ||
5948 | /* Find a representation of a given base type and install | |
5949 | it in the TYPE field of the die. */ | |
5950 | ||
f792889a | 5951 | static struct type * |
e7c27a73 | 5952 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5953 | { |
e7c27a73 | 5954 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5955 | struct type *type; |
5956 | struct attribute *attr; | |
5957 | int encoding = 0, size = 0; | |
39cbfefa | 5958 | char *name; |
6ccb9162 UW |
5959 | enum type_code code = TYPE_CODE_INT; |
5960 | int type_flags = 0; | |
5961 | struct type *target_type = NULL; | |
c906108c | 5962 | |
e142c38c | 5963 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
5964 | if (attr) |
5965 | { | |
5966 | encoding = DW_UNSND (attr); | |
5967 | } | |
e142c38c | 5968 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5969 | if (attr) |
5970 | { | |
5971 | size = DW_UNSND (attr); | |
5972 | } | |
39cbfefa | 5973 | name = dwarf2_name (die, cu); |
6ccb9162 | 5974 | if (!name) |
c906108c | 5975 | { |
6ccb9162 UW |
5976 | complaint (&symfile_complaints, |
5977 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 5978 | } |
6ccb9162 UW |
5979 | |
5980 | switch (encoding) | |
c906108c | 5981 | { |
6ccb9162 UW |
5982 | case DW_ATE_address: |
5983 | /* Turn DW_ATE_address into a void * pointer. */ | |
5984 | code = TYPE_CODE_PTR; | |
5985 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5986 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
5987 | break; | |
5988 | case DW_ATE_boolean: | |
5989 | code = TYPE_CODE_BOOL; | |
5990 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5991 | break; | |
5992 | case DW_ATE_complex_float: | |
5993 | code = TYPE_CODE_COMPLEX; | |
5994 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
5995 | break; | |
5996 | case DW_ATE_decimal_float: | |
5997 | code = TYPE_CODE_DECFLOAT; | |
5998 | break; | |
5999 | case DW_ATE_float: | |
6000 | code = TYPE_CODE_FLT; | |
6001 | break; | |
6002 | case DW_ATE_signed: | |
6003 | break; | |
6004 | case DW_ATE_unsigned: | |
6005 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6006 | break; | |
6007 | case DW_ATE_signed_char: | |
868a0084 PM |
6008 | if (cu->language == language_ada || cu->language == language_m2 |
6009 | || cu->language == language_pascal) | |
6ccb9162 UW |
6010 | code = TYPE_CODE_CHAR; |
6011 | break; | |
6012 | case DW_ATE_unsigned_char: | |
868a0084 PM |
6013 | if (cu->language == language_ada || cu->language == language_m2 |
6014 | || cu->language == language_pascal) | |
6ccb9162 UW |
6015 | code = TYPE_CODE_CHAR; |
6016 | type_flags |= TYPE_FLAG_UNSIGNED; | |
6017 | break; | |
6018 | default: | |
6019 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
6020 | dwarf_type_encoding_name (encoding)); | |
6021 | break; | |
c906108c | 6022 | } |
6ccb9162 | 6023 | |
0114d602 DJ |
6024 | type = init_type (code, size, type_flags, NULL, objfile); |
6025 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
6026 | TYPE_TARGET_TYPE (type) = target_type; |
6027 | ||
0114d602 | 6028 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 6029 | TYPE_NOSIGN (type) = 1; |
0114d602 | 6030 | |
f792889a | 6031 | return set_die_type (die, type, cu); |
c906108c SS |
6032 | } |
6033 | ||
a02abb62 JB |
6034 | /* Read the given DW_AT_subrange DIE. */ |
6035 | ||
f792889a | 6036 | static struct type * |
a02abb62 JB |
6037 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
6038 | { | |
5e2b427d | 6039 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
6040 | struct type *base_type; |
6041 | struct type *range_type; | |
6042 | struct attribute *attr; | |
43bbcdc2 PH |
6043 | LONGEST low = 0; |
6044 | LONGEST high = -1; | |
39cbfefa | 6045 | char *name; |
43bbcdc2 | 6046 | LONGEST negative_mask; |
a02abb62 | 6047 | |
a02abb62 | 6048 | base_type = die_type (die, cu); |
3d1f72c2 | 6049 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
6050 | { |
6051 | complaint (&symfile_complaints, | |
e2e0b3e5 | 6052 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 6053 | base_type |
5e2b427d | 6054 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 6055 | 0, NULL, cu->objfile); |
a02abb62 JB |
6056 | } |
6057 | ||
e142c38c | 6058 | if (cu->language == language_fortran) |
a02abb62 JB |
6059 | { |
6060 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
6061 | low = 1; | |
6062 | } | |
6063 | ||
dd5e6932 DJ |
6064 | /* FIXME: For variable sized arrays either of these could be |
6065 | a variable rather than a constant value. We'll allow it, | |
6066 | but we don't know how to handle it. */ | |
e142c38c | 6067 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
6068 | if (attr) |
6069 | low = dwarf2_get_attr_constant_value (attr, 0); | |
6070 | ||
e142c38c | 6071 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
6072 | if (attr) |
6073 | { | |
6074 | if (attr->form == DW_FORM_block1) | |
6075 | { | |
6076 | /* GCC encodes arrays with unspecified or dynamic length | |
6077 | with a DW_FORM_block1 attribute. | |
6078 | FIXME: GDB does not yet know how to handle dynamic | |
6079 | arrays properly, treat them as arrays with unspecified | |
6080 | length for now. | |
6081 | ||
6082 | FIXME: jimb/2003-09-22: GDB does not really know | |
6083 | how to handle arrays of unspecified length | |
6084 | either; we just represent them as zero-length | |
6085 | arrays. Choose an appropriate upper bound given | |
6086 | the lower bound we've computed above. */ | |
6087 | high = low - 1; | |
6088 | } | |
6089 | else | |
6090 | high = dwarf2_get_attr_constant_value (attr, 1); | |
6091 | } | |
6092 | ||
43bbcdc2 PH |
6093 | negative_mask = |
6094 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); | |
6095 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
6096 | low |= negative_mask; | |
6097 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
6098 | high |= negative_mask; | |
6099 | ||
a02abb62 JB |
6100 | range_type = create_range_type (NULL, base_type, low, high); |
6101 | ||
39cbfefa DJ |
6102 | name = dwarf2_name (die, cu); |
6103 | if (name) | |
6104 | TYPE_NAME (range_type) = name; | |
a02abb62 | 6105 | |
e142c38c | 6106 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
6107 | if (attr) |
6108 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
6109 | ||
b4ba55a1 JB |
6110 | set_descriptive_type (range_type, die, cu); |
6111 | ||
f792889a | 6112 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
6113 | } |
6114 | ||
f792889a | 6115 | static struct type * |
81a17f79 JB |
6116 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
6117 | { | |
6118 | struct type *type; | |
81a17f79 | 6119 | |
81a17f79 JB |
6120 | /* For now, we only support the C meaning of an unspecified type: void. */ |
6121 | ||
0114d602 DJ |
6122 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
6123 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 6124 | |
f792889a | 6125 | return set_die_type (die, type, cu); |
81a17f79 | 6126 | } |
a02abb62 | 6127 | |
51545339 DJ |
6128 | /* Trivial hash function for die_info: the hash value of a DIE |
6129 | is its offset in .debug_info for this objfile. */ | |
6130 | ||
6131 | static hashval_t | |
6132 | die_hash (const void *item) | |
6133 | { | |
6134 | const struct die_info *die = item; | |
6135 | return die->offset; | |
6136 | } | |
6137 | ||
6138 | /* Trivial comparison function for die_info structures: two DIEs | |
6139 | are equal if they have the same offset. */ | |
6140 | ||
6141 | static int | |
6142 | die_eq (const void *item_lhs, const void *item_rhs) | |
6143 | { | |
6144 | const struct die_info *die_lhs = item_lhs; | |
6145 | const struct die_info *die_rhs = item_rhs; | |
6146 | return die_lhs->offset == die_rhs->offset; | |
6147 | } | |
6148 | ||
c906108c SS |
6149 | /* Read a whole compilation unit into a linked list of dies. */ |
6150 | ||
f9aca02d | 6151 | static struct die_info * |
93311388 | 6152 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 6153 | { |
93311388 DE |
6154 | struct die_reader_specs reader_specs; |
6155 | ||
348e048f | 6156 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
6157 | cu->die_hash |
6158 | = htab_create_alloc_ex (cu->header.length / 12, | |
6159 | die_hash, | |
6160 | die_eq, | |
6161 | NULL, | |
6162 | &cu->comp_unit_obstack, | |
6163 | hashtab_obstack_allocate, | |
6164 | dummy_obstack_deallocate); | |
6165 | ||
93311388 DE |
6166 | init_cu_die_reader (&reader_specs, cu); |
6167 | ||
6168 | return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); | |
639d11d3 DC |
6169 | } |
6170 | ||
d97bc12b DE |
6171 | /* Main entry point for reading a DIE and all children. |
6172 | Read the DIE and dump it if requested. */ | |
6173 | ||
6174 | static struct die_info * | |
93311388 DE |
6175 | read_die_and_children (const struct die_reader_specs *reader, |
6176 | gdb_byte *info_ptr, | |
d97bc12b DE |
6177 | gdb_byte **new_info_ptr, |
6178 | struct die_info *parent) | |
6179 | { | |
93311388 | 6180 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
6181 | new_info_ptr, parent); |
6182 | ||
6183 | if (dwarf2_die_debug) | |
6184 | { | |
348e048f DE |
6185 | fprintf_unfiltered (gdb_stdlog, |
6186 | "\nRead die from %s of %s:\n", | |
6187 | reader->buffer == dwarf2_per_objfile->info.buffer | |
6188 | ? ".debug_info" | |
6189 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
6190 | ? ".debug_types" | |
6191 | : "unknown section", | |
6192 | reader->abfd->filename); | |
d97bc12b DE |
6193 | dump_die (result, dwarf2_die_debug); |
6194 | } | |
6195 | ||
6196 | return result; | |
6197 | } | |
6198 | ||
639d11d3 DC |
6199 | /* Read a single die and all its descendents. Set the die's sibling |
6200 | field to NULL; set other fields in the die correctly, and set all | |
6201 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
6202 | location of the info_ptr after reading all of those dies. PARENT | |
6203 | is the parent of the die in question. */ | |
6204 | ||
6205 | static struct die_info * | |
93311388 DE |
6206 | read_die_and_children_1 (const struct die_reader_specs *reader, |
6207 | gdb_byte *info_ptr, | |
d97bc12b DE |
6208 | gdb_byte **new_info_ptr, |
6209 | struct die_info *parent) | |
639d11d3 DC |
6210 | { |
6211 | struct die_info *die; | |
fe1b8b76 | 6212 | gdb_byte *cur_ptr; |
639d11d3 DC |
6213 | int has_children; |
6214 | ||
93311388 | 6215 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
6216 | if (die == NULL) |
6217 | { | |
6218 | *new_info_ptr = cur_ptr; | |
6219 | return NULL; | |
6220 | } | |
93311388 | 6221 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
6222 | |
6223 | if (has_children) | |
348e048f | 6224 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
6225 | else |
6226 | { | |
6227 | die->child = NULL; | |
6228 | *new_info_ptr = cur_ptr; | |
6229 | } | |
6230 | ||
6231 | die->sibling = NULL; | |
6232 | die->parent = parent; | |
6233 | return die; | |
6234 | } | |
6235 | ||
6236 | /* Read a die, all of its descendents, and all of its siblings; set | |
6237 | all of the fields of all of the dies correctly. Arguments are as | |
6238 | in read_die_and_children. */ | |
6239 | ||
6240 | static struct die_info * | |
93311388 DE |
6241 | read_die_and_siblings (const struct die_reader_specs *reader, |
6242 | gdb_byte *info_ptr, | |
fe1b8b76 | 6243 | gdb_byte **new_info_ptr, |
639d11d3 DC |
6244 | struct die_info *parent) |
6245 | { | |
6246 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 6247 | gdb_byte *cur_ptr; |
639d11d3 | 6248 | |
c906108c | 6249 | cur_ptr = info_ptr; |
639d11d3 DC |
6250 | first_die = last_sibling = NULL; |
6251 | ||
6252 | while (1) | |
c906108c | 6253 | { |
639d11d3 | 6254 | struct die_info *die |
93311388 | 6255 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 6256 | |
1d325ec1 | 6257 | if (die == NULL) |
c906108c | 6258 | { |
639d11d3 DC |
6259 | *new_info_ptr = cur_ptr; |
6260 | return first_die; | |
c906108c | 6261 | } |
1d325ec1 DJ |
6262 | |
6263 | if (!first_die) | |
6264 | first_die = die; | |
c906108c | 6265 | else |
1d325ec1 DJ |
6266 | last_sibling->sibling = die; |
6267 | ||
6268 | last_sibling = die; | |
c906108c | 6269 | } |
c906108c SS |
6270 | } |
6271 | ||
93311388 DE |
6272 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6273 | point to a newly allocated die with its information, except for its | |
6274 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6275 | whether the die has children or not. */ | |
6276 | ||
6277 | static gdb_byte * | |
6278 | read_full_die (const struct die_reader_specs *reader, | |
6279 | struct die_info **diep, gdb_byte *info_ptr, | |
6280 | int *has_children) | |
6281 | { | |
6282 | unsigned int abbrev_number, bytes_read, i, offset; | |
6283 | struct abbrev_info *abbrev; | |
6284 | struct die_info *die; | |
6285 | struct dwarf2_cu *cu = reader->cu; | |
6286 | bfd *abfd = reader->abfd; | |
6287 | ||
6288 | offset = info_ptr - reader->buffer; | |
6289 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6290 | info_ptr += bytes_read; | |
6291 | if (!abbrev_number) | |
6292 | { | |
6293 | *diep = NULL; | |
6294 | *has_children = 0; | |
6295 | return info_ptr; | |
6296 | } | |
6297 | ||
6298 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
6299 | if (!abbrev) | |
348e048f DE |
6300 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
6301 | abbrev_number, | |
6302 | bfd_get_filename (abfd)); | |
6303 | ||
93311388 DE |
6304 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
6305 | die->offset = offset; | |
6306 | die->tag = abbrev->tag; | |
6307 | die->abbrev = abbrev_number; | |
6308 | ||
6309 | die->num_attrs = abbrev->num_attrs; | |
6310 | ||
6311 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6312 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
6313 | abfd, info_ptr, cu); | |
6314 | ||
6315 | *diep = die; | |
6316 | *has_children = abbrev->has_children; | |
6317 | return info_ptr; | |
6318 | } | |
6319 | ||
c906108c SS |
6320 | /* In DWARF version 2, the description of the debugging information is |
6321 | stored in a separate .debug_abbrev section. Before we read any | |
6322 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
6323 | in a hash table. This function also sets flags in CU describing |
6324 | the data found in the abbrev table. */ | |
c906108c SS |
6325 | |
6326 | static void | |
e7c27a73 | 6327 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 6328 | { |
e7c27a73 | 6329 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 6330 | gdb_byte *abbrev_ptr; |
c906108c SS |
6331 | struct abbrev_info *cur_abbrev; |
6332 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
6333 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
6334 | struct attr_abbrev *cur_attrs; |
6335 | unsigned int allocated_attrs; | |
c906108c | 6336 | |
57349743 | 6337 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
6338 | obstack_init (&cu->abbrev_obstack); |
6339 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
6340 | (ABBREV_HASH_SIZE | |
6341 | * sizeof (struct abbrev_info *))); | |
6342 | memset (cu->dwarf2_abbrevs, 0, | |
6343 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 6344 | |
dce234bc | 6345 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
6346 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6347 | abbrev_ptr += bytes_read; | |
6348 | ||
f3dd6933 DJ |
6349 | allocated_attrs = ATTR_ALLOC_CHUNK; |
6350 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6351 | ||
c906108c SS |
6352 | /* loop until we reach an abbrev number of 0 */ |
6353 | while (abbrev_number) | |
6354 | { | |
f3dd6933 | 6355 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
6356 | |
6357 | /* read in abbrev header */ | |
6358 | cur_abbrev->number = abbrev_number; | |
6359 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6360 | abbrev_ptr += bytes_read; | |
6361 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
6362 | abbrev_ptr += 1; | |
6363 | ||
72bf9492 DJ |
6364 | if (cur_abbrev->tag == DW_TAG_namespace) |
6365 | cu->has_namespace_info = 1; | |
6366 | ||
c906108c SS |
6367 | /* now read in declarations */ |
6368 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6369 | abbrev_ptr += bytes_read; | |
6370 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6371 | abbrev_ptr += bytes_read; | |
6372 | while (abbrev_name) | |
6373 | { | |
f3dd6933 | 6374 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 6375 | { |
f3dd6933 DJ |
6376 | allocated_attrs += ATTR_ALLOC_CHUNK; |
6377 | cur_attrs | |
6378 | = xrealloc (cur_attrs, (allocated_attrs | |
6379 | * sizeof (struct attr_abbrev))); | |
c906108c | 6380 | } |
ae038cb0 DJ |
6381 | |
6382 | /* Record whether this compilation unit might have | |
6383 | inter-compilation-unit references. If we don't know what form | |
6384 | this attribute will have, then it might potentially be a | |
6385 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
6386 | references. */ | |
6387 | ||
6388 | if (abbrev_form == DW_FORM_ref_addr | |
6389 | || abbrev_form == DW_FORM_indirect) | |
6390 | cu->has_form_ref_addr = 1; | |
6391 | ||
f3dd6933 DJ |
6392 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
6393 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
6394 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
6395 | abbrev_ptr += bytes_read; | |
6396 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6397 | abbrev_ptr += bytes_read; | |
6398 | } | |
6399 | ||
f3dd6933 DJ |
6400 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
6401 | (cur_abbrev->num_attrs | |
6402 | * sizeof (struct attr_abbrev))); | |
6403 | memcpy (cur_abbrev->attrs, cur_attrs, | |
6404 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
6405 | ||
c906108c | 6406 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
6407 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
6408 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
6409 | |
6410 | /* Get next abbreviation. | |
6411 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
6412 | always properly terminated with an abbrev number of 0. |
6413 | Exit loop if we encounter an abbreviation which we have | |
6414 | already read (which means we are about to read the abbreviations | |
6415 | for the next compile unit) or if the end of the abbreviation | |
6416 | table is reached. */ | |
dce234bc PP |
6417 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
6418 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
6419 | break; |
6420 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
6421 | abbrev_ptr += bytes_read; | |
e7c27a73 | 6422 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
6423 | break; |
6424 | } | |
f3dd6933 DJ |
6425 | |
6426 | xfree (cur_attrs); | |
c906108c SS |
6427 | } |
6428 | ||
f3dd6933 | 6429 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 6430 | |
c906108c | 6431 | static void |
f3dd6933 | 6432 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 6433 | { |
f3dd6933 | 6434 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 6435 | |
f3dd6933 DJ |
6436 | obstack_free (&cu->abbrev_obstack, NULL); |
6437 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
6438 | } |
6439 | ||
6440 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
6441 | ||
6442 | static struct abbrev_info * | |
e7c27a73 | 6443 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
6444 | { |
6445 | unsigned int hash_number; | |
6446 | struct abbrev_info *abbrev; | |
6447 | ||
6448 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 6449 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
6450 | |
6451 | while (abbrev) | |
6452 | { | |
6453 | if (abbrev->number == number) | |
6454 | return abbrev; | |
6455 | else | |
6456 | abbrev = abbrev->next; | |
6457 | } | |
6458 | return NULL; | |
6459 | } | |
6460 | ||
72bf9492 DJ |
6461 | /* Returns nonzero if TAG represents a type that we might generate a partial |
6462 | symbol for. */ | |
6463 | ||
6464 | static int | |
6465 | is_type_tag_for_partial (int tag) | |
6466 | { | |
6467 | switch (tag) | |
6468 | { | |
6469 | #if 0 | |
6470 | /* Some types that would be reasonable to generate partial symbols for, | |
6471 | that we don't at present. */ | |
6472 | case DW_TAG_array_type: | |
6473 | case DW_TAG_file_type: | |
6474 | case DW_TAG_ptr_to_member_type: | |
6475 | case DW_TAG_set_type: | |
6476 | case DW_TAG_string_type: | |
6477 | case DW_TAG_subroutine_type: | |
6478 | #endif | |
6479 | case DW_TAG_base_type: | |
6480 | case DW_TAG_class_type: | |
680b30c7 | 6481 | case DW_TAG_interface_type: |
72bf9492 DJ |
6482 | case DW_TAG_enumeration_type: |
6483 | case DW_TAG_structure_type: | |
6484 | case DW_TAG_subrange_type: | |
6485 | case DW_TAG_typedef: | |
6486 | case DW_TAG_union_type: | |
6487 | return 1; | |
6488 | default: | |
6489 | return 0; | |
6490 | } | |
6491 | } | |
6492 | ||
6493 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
6494 | ||
6495 | static struct partial_die_info * | |
93311388 DE |
6496 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
6497 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
6498 | { |
6499 | struct partial_die_info *part_die; | |
6500 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
6501 | struct abbrev_info *abbrev; | |
6502 | unsigned int bytes_read; | |
5afb4e99 | 6503 | unsigned int load_all = 0; |
72bf9492 DJ |
6504 | |
6505 | int nesting_level = 1; | |
6506 | ||
6507 | parent_die = NULL; | |
6508 | last_die = NULL; | |
6509 | ||
5afb4e99 DJ |
6510 | if (cu->per_cu && cu->per_cu->load_all_dies) |
6511 | load_all = 1; | |
6512 | ||
72bf9492 DJ |
6513 | cu->partial_dies |
6514 | = htab_create_alloc_ex (cu->header.length / 12, | |
6515 | partial_die_hash, | |
6516 | partial_die_eq, | |
6517 | NULL, | |
6518 | &cu->comp_unit_obstack, | |
6519 | hashtab_obstack_allocate, | |
6520 | dummy_obstack_deallocate); | |
6521 | ||
6522 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6523 | sizeof (struct partial_die_info)); | |
6524 | ||
6525 | while (1) | |
6526 | { | |
6527 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
6528 | ||
6529 | /* A NULL abbrev means the end of a series of children. */ | |
6530 | if (abbrev == NULL) | |
6531 | { | |
6532 | if (--nesting_level == 0) | |
6533 | { | |
6534 | /* PART_DIE was probably the last thing allocated on the | |
6535 | comp_unit_obstack, so we could call obstack_free | |
6536 | here. We don't do that because the waste is small, | |
6537 | and will be cleaned up when we're done with this | |
6538 | compilation unit. This way, we're also more robust | |
6539 | against other users of the comp_unit_obstack. */ | |
6540 | return first_die; | |
6541 | } | |
6542 | info_ptr += bytes_read; | |
6543 | last_die = parent_die; | |
6544 | parent_die = parent_die->die_parent; | |
6545 | continue; | |
6546 | } | |
6547 | ||
5afb4e99 DJ |
6548 | /* Check whether this DIE is interesting enough to save. Normally |
6549 | we would not be interested in members here, but there may be | |
6550 | later variables referencing them via DW_AT_specification (for | |
6551 | static members). */ | |
6552 | if (!load_all | |
6553 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
6554 | && abbrev->tag != DW_TAG_enumerator |
6555 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 6556 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 6557 | && abbrev->tag != DW_TAG_variable |
5afb4e99 DJ |
6558 | && abbrev->tag != DW_TAG_namespace |
6559 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
6560 | { |
6561 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6562 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
6563 | continue; |
6564 | } | |
6565 | ||
93311388 DE |
6566 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
6567 | buffer, info_ptr, cu); | |
72bf9492 DJ |
6568 | |
6569 | /* This two-pass algorithm for processing partial symbols has a | |
6570 | high cost in cache pressure. Thus, handle some simple cases | |
6571 | here which cover the majority of C partial symbols. DIEs | |
6572 | which neither have specification tags in them, nor could have | |
6573 | specification tags elsewhere pointing at them, can simply be | |
6574 | processed and discarded. | |
6575 | ||
6576 | This segment is also optional; scan_partial_symbols and | |
6577 | add_partial_symbol will handle these DIEs if we chain | |
6578 | them in normally. When compilers which do not emit large | |
6579 | quantities of duplicate debug information are more common, | |
6580 | this code can probably be removed. */ | |
6581 | ||
6582 | /* Any complete simple types at the top level (pretty much all | |
6583 | of them, for a language without namespaces), can be processed | |
6584 | directly. */ | |
6585 | if (parent_die == NULL | |
6586 | && part_die->has_specification == 0 | |
6587 | && part_die->is_declaration == 0 | |
6588 | && (part_die->tag == DW_TAG_typedef | |
6589 | || part_die->tag == DW_TAG_base_type | |
6590 | || part_die->tag == DW_TAG_subrange_type)) | |
6591 | { | |
6592 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 6593 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
6594 | VAR_DOMAIN, LOC_TYPEDEF, |
6595 | &cu->objfile->static_psymbols, | |
6596 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 6597 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6598 | continue; |
6599 | } | |
6600 | ||
6601 | /* If we're at the second level, and we're an enumerator, and | |
6602 | our parent has no specification (meaning possibly lives in a | |
6603 | namespace elsewhere), then we can add the partial symbol now | |
6604 | instead of queueing it. */ | |
6605 | if (part_die->tag == DW_TAG_enumerator | |
6606 | && parent_die != NULL | |
6607 | && parent_die->die_parent == NULL | |
6608 | && parent_die->tag == DW_TAG_enumeration_type | |
6609 | && parent_die->has_specification == 0) | |
6610 | { | |
6611 | if (part_die->name == NULL) | |
e2e0b3e5 | 6612 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 6613 | else if (building_psymtab) |
04a679b8 | 6614 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 6615 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
6616 | (cu->language == language_cplus |
6617 | || cu->language == language_java) | |
72bf9492 DJ |
6618 | ? &cu->objfile->global_psymbols |
6619 | : &cu->objfile->static_psymbols, | |
6620 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
6621 | ||
93311388 | 6622 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6623 | continue; |
6624 | } | |
6625 | ||
6626 | /* We'll save this DIE so link it in. */ | |
6627 | part_die->die_parent = parent_die; | |
6628 | part_die->die_sibling = NULL; | |
6629 | part_die->die_child = NULL; | |
6630 | ||
6631 | if (last_die && last_die == parent_die) | |
6632 | last_die->die_child = part_die; | |
6633 | else if (last_die) | |
6634 | last_die->die_sibling = part_die; | |
6635 | ||
6636 | last_die = part_die; | |
6637 | ||
6638 | if (first_die == NULL) | |
6639 | first_die = part_die; | |
6640 | ||
6641 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
6642 | find interesting need to be in the hash table, because we | |
6643 | also have the parent/sibling/child chains; only those that we | |
6644 | might refer to by offset later during partial symbol reading. | |
6645 | ||
6646 | For now this means things that might have be the target of a | |
6647 | DW_AT_specification, DW_AT_abstract_origin, or | |
6648 | DW_AT_extension. DW_AT_extension will refer only to | |
6649 | namespaces; DW_AT_abstract_origin refers to functions (and | |
6650 | many things under the function DIE, but we do not recurse | |
6651 | into function DIEs during partial symbol reading) and | |
6652 | possibly variables as well; DW_AT_specification refers to | |
6653 | declarations. Declarations ought to have the DW_AT_declaration | |
6654 | flag. It happens that GCC forgets to put it in sometimes, but | |
6655 | only for functions, not for types. | |
6656 | ||
6657 | Adding more things than necessary to the hash table is harmless | |
6658 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
6659 | wasted time in find_partial_die, when we reread the compilation |
6660 | unit with load_all_dies set. */ | |
72bf9492 | 6661 | |
5afb4e99 DJ |
6662 | if (load_all |
6663 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
6664 | || abbrev->tag == DW_TAG_variable |
6665 | || abbrev->tag == DW_TAG_namespace | |
6666 | || part_die->is_declaration) | |
6667 | { | |
6668 | void **slot; | |
6669 | ||
6670 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
6671 | part_die->offset, INSERT); | |
6672 | *slot = part_die; | |
6673 | } | |
6674 | ||
6675 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
6676 | sizeof (struct partial_die_info)); | |
6677 | ||
6678 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 6679 | we have no reason to follow the children of structures; for other |
72bf9492 | 6680 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
6681 | to infer fully qualified class names, and for DW_AT_specification. |
6682 | ||
6683 | For Ada, we need to scan the children of subprograms and lexical | |
6684 | blocks as well because Ada allows the definition of nested | |
6685 | entities that could be interesting for the debugger, such as | |
6686 | nested subprograms for instance. */ | |
72bf9492 | 6687 | if (last_die->has_children |
5afb4e99 DJ |
6688 | && (load_all |
6689 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
6690 | || last_die->tag == DW_TAG_enumeration_type |
6691 | || (cu->language != language_c | |
6692 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 6693 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 6694 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
6695 | || last_die->tag == DW_TAG_union_type)) |
6696 | || (cu->language == language_ada | |
6697 | && (last_die->tag == DW_TAG_subprogram | |
6698 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
6699 | { |
6700 | nesting_level++; | |
6701 | parent_die = last_die; | |
6702 | continue; | |
6703 | } | |
6704 | ||
6705 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 6706 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
6707 | |
6708 | /* Back to the top, do it again. */ | |
6709 | } | |
6710 | } | |
6711 | ||
c906108c SS |
6712 | /* Read a minimal amount of information into the minimal die structure. */ |
6713 | ||
fe1b8b76 | 6714 | static gdb_byte * |
72bf9492 DJ |
6715 | read_partial_die (struct partial_die_info *part_die, |
6716 | struct abbrev_info *abbrev, | |
6717 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
6718 | gdb_byte *buffer, gdb_byte *info_ptr, |
6719 | struct dwarf2_cu *cu) | |
c906108c | 6720 | { |
72bf9492 | 6721 | unsigned int bytes_read, i; |
c906108c | 6722 | struct attribute attr; |
c5aa993b | 6723 | int has_low_pc_attr = 0; |
c906108c SS |
6724 | int has_high_pc_attr = 0; |
6725 | ||
72bf9492 | 6726 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 6727 | |
93311388 | 6728 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
6729 | |
6730 | info_ptr += abbrev_len; | |
6731 | ||
6732 | if (abbrev == NULL) | |
6733 | return info_ptr; | |
6734 | ||
c906108c SS |
6735 | part_die->tag = abbrev->tag; |
6736 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
6737 | |
6738 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6739 | { | |
e7c27a73 | 6740 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
6741 | |
6742 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 6743 | partial symbol table. */ |
c906108c SS |
6744 | switch (attr.name) |
6745 | { | |
6746 | case DW_AT_name: | |
71c25dea TT |
6747 | switch (part_die->tag) |
6748 | { | |
6749 | case DW_TAG_compile_unit: | |
348e048f | 6750 | case DW_TAG_type_unit: |
71c25dea TT |
6751 | /* Compilation units have a DW_AT_name that is a filename, not |
6752 | a source language identifier. */ | |
6753 | case DW_TAG_enumeration_type: | |
6754 | case DW_TAG_enumerator: | |
6755 | /* These tags always have simple identifiers already; no need | |
6756 | to canonicalize them. */ | |
6757 | part_die->name = DW_STRING (&attr); | |
6758 | break; | |
6759 | default: | |
6760 | part_die->name | |
6761 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 6762 | &cu->objfile->objfile_obstack); |
71c25dea TT |
6763 | break; |
6764 | } | |
c906108c SS |
6765 | break; |
6766 | case DW_AT_MIPS_linkage_name: | |
6767 | part_die->name = DW_STRING (&attr); | |
6768 | break; | |
6769 | case DW_AT_low_pc: | |
6770 | has_low_pc_attr = 1; | |
6771 | part_die->lowpc = DW_ADDR (&attr); | |
6772 | break; | |
6773 | case DW_AT_high_pc: | |
6774 | has_high_pc_attr = 1; | |
6775 | part_die->highpc = DW_ADDR (&attr); | |
6776 | break; | |
6777 | case DW_AT_location: | |
8e19ed76 PS |
6778 | /* Support the .debug_loc offsets */ |
6779 | if (attr_form_is_block (&attr)) | |
6780 | { | |
6781 | part_die->locdesc = DW_BLOCK (&attr); | |
6782 | } | |
3690dd37 | 6783 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 6784 | { |
4d3c2250 | 6785 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6786 | } |
6787 | else | |
6788 | { | |
4d3c2250 KB |
6789 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6790 | "partial symbol information"); | |
8e19ed76 | 6791 | } |
c906108c | 6792 | break; |
c906108c SS |
6793 | case DW_AT_external: |
6794 | part_die->is_external = DW_UNSND (&attr); | |
6795 | break; | |
6796 | case DW_AT_declaration: | |
6797 | part_die->is_declaration = DW_UNSND (&attr); | |
6798 | break; | |
6799 | case DW_AT_type: | |
6800 | part_die->has_type = 1; | |
6801 | break; | |
6802 | case DW_AT_abstract_origin: | |
6803 | case DW_AT_specification: | |
72bf9492 DJ |
6804 | case DW_AT_extension: |
6805 | part_die->has_specification = 1; | |
c764a876 | 6806 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
6807 | break; |
6808 | case DW_AT_sibling: | |
6809 | /* Ignore absolute siblings, they might point outside of | |
6810 | the current compile unit. */ | |
6811 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 6812 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 6813 | else |
93311388 | 6814 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 6815 | break; |
fa4028e9 JB |
6816 | case DW_AT_byte_size: |
6817 | part_die->has_byte_size = 1; | |
6818 | break; | |
68511cec CES |
6819 | case DW_AT_calling_convention: |
6820 | /* DWARF doesn't provide a way to identify a program's source-level | |
6821 | entry point. DW_AT_calling_convention attributes are only meant | |
6822 | to describe functions' calling conventions. | |
6823 | ||
6824 | However, because it's a necessary piece of information in | |
6825 | Fortran, and because DW_CC_program is the only piece of debugging | |
6826 | information whose definition refers to a 'main program' at all, | |
6827 | several compilers have begun marking Fortran main programs with | |
6828 | DW_CC_program --- even when those functions use the standard | |
6829 | calling conventions. | |
6830 | ||
6831 | So until DWARF specifies a way to provide this information and | |
6832 | compilers pick up the new representation, we'll support this | |
6833 | practice. */ | |
6834 | if (DW_UNSND (&attr) == DW_CC_program | |
6835 | && cu->language == language_fortran) | |
6836 | set_main_name (part_die->name); | |
6837 | break; | |
c906108c SS |
6838 | default: |
6839 | break; | |
6840 | } | |
6841 | } | |
6842 | ||
c906108c SS |
6843 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
6844 | eliminate duplicate copies of functions and vtables and such. | |
6845 | The linker will arbitrarily choose one and discard the others. | |
6846 | The AT_*_pc values for such functions refer to local labels in | |
6847 | these sections. If the section from that file was discarded, the | |
6848 | labels are not in the output, so the relocs get a value of 0. | |
6849 | If this is a discarded function, mark the pc bounds as invalid, | |
6850 | so that GDB will ignore it. */ | |
6851 | if (has_low_pc_attr && has_high_pc_attr | |
6852 | && part_die->lowpc < part_die->highpc | |
6853 | && (part_die->lowpc != 0 | |
72dca2f5 | 6854 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 6855 | part_die->has_pc_info = 1; |
85cbf3d3 | 6856 | |
c906108c SS |
6857 | return info_ptr; |
6858 | } | |
6859 | ||
72bf9492 DJ |
6860 | /* Find a cached partial DIE at OFFSET in CU. */ |
6861 | ||
6862 | static struct partial_die_info * | |
c764a876 | 6863 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
6864 | { |
6865 | struct partial_die_info *lookup_die = NULL; | |
6866 | struct partial_die_info part_die; | |
6867 | ||
6868 | part_die.offset = offset; | |
6869 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
6870 | ||
72bf9492 DJ |
6871 | return lookup_die; |
6872 | } | |
6873 | ||
348e048f DE |
6874 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
6875 | except in the case of .debug_types DIEs which do not reference | |
6876 | outside their CU (they do however referencing other types via | |
6877 | DW_FORM_sig8). */ | |
72bf9492 DJ |
6878 | |
6879 | static struct partial_die_info * | |
c764a876 | 6880 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 6881 | { |
5afb4e99 DJ |
6882 | struct dwarf2_per_cu_data *per_cu = NULL; |
6883 | struct partial_die_info *pd = NULL; | |
72bf9492 | 6884 | |
348e048f DE |
6885 | if (cu->per_cu->from_debug_types) |
6886 | { | |
6887 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6888 | if (pd != NULL) | |
6889 | return pd; | |
6890 | goto not_found; | |
6891 | } | |
6892 | ||
45452591 | 6893 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
6894 | { |
6895 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6896 | if (pd != NULL) | |
6897 | return pd; | |
6898 | } | |
72bf9492 | 6899 | |
ae038cb0 DJ |
6900 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
6901 | ||
ae038cb0 DJ |
6902 | if (per_cu->cu == NULL) |
6903 | { | |
93311388 | 6904 | load_partial_comp_unit (per_cu, cu->objfile); |
ae038cb0 DJ |
6905 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
6906 | dwarf2_per_objfile->read_in_chain = per_cu; | |
6907 | } | |
6908 | ||
6909 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
6910 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
6911 | ||
6912 | if (pd == NULL && per_cu->load_all_dies == 0) | |
6913 | { | |
6914 | struct cleanup *back_to; | |
6915 | struct partial_die_info comp_unit_die; | |
6916 | struct abbrev_info *abbrev; | |
6917 | unsigned int bytes_read; | |
6918 | char *info_ptr; | |
6919 | ||
6920 | per_cu->load_all_dies = 1; | |
6921 | ||
6922 | /* Re-read the DIEs. */ | |
6923 | back_to = make_cleanup (null_cleanup, 0); | |
6924 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
6925 | { | |
6926 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 6927 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 6928 | } |
dce234bc | 6929 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
6930 | + per_cu->cu->header.offset |
6931 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
6932 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
6933 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
6934 | per_cu->cu->objfile->obfd, |
6935 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
6936 | per_cu->cu); |
6937 | if (comp_unit_die.has_children) | |
93311388 DE |
6938 | load_partial_dies (per_cu->cu->objfile->obfd, |
6939 | dwarf2_per_objfile->info.buffer, info_ptr, | |
6940 | 0, per_cu->cu); | |
5afb4e99 DJ |
6941 | do_cleanups (back_to); |
6942 | ||
6943 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
6944 | } | |
6945 | ||
348e048f DE |
6946 | not_found: |
6947 | ||
5afb4e99 DJ |
6948 | if (pd == NULL) |
6949 | internal_error (__FILE__, __LINE__, | |
c764a876 | 6950 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
6951 | offset, bfd_get_filename (cu->objfile->obfd)); |
6952 | return pd; | |
72bf9492 DJ |
6953 | } |
6954 | ||
6955 | /* Adjust PART_DIE before generating a symbol for it. This function | |
6956 | may set the is_external flag or change the DIE's name. */ | |
6957 | ||
6958 | static void | |
6959 | fixup_partial_die (struct partial_die_info *part_die, | |
6960 | struct dwarf2_cu *cu) | |
6961 | { | |
6962 | /* If we found a reference attribute and the DIE has no name, try | |
6963 | to find a name in the referred to DIE. */ | |
6964 | ||
6965 | if (part_die->name == NULL && part_die->has_specification) | |
6966 | { | |
6967 | struct partial_die_info *spec_die; | |
72bf9492 | 6968 | |
10b3939b | 6969 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6970 | |
10b3939b | 6971 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6972 | |
6973 | if (spec_die->name) | |
6974 | { | |
6975 | part_die->name = spec_die->name; | |
6976 | ||
6977 | /* Copy DW_AT_external attribute if it is set. */ | |
6978 | if (spec_die->is_external) | |
6979 | part_die->is_external = spec_die->is_external; | |
6980 | } | |
6981 | } | |
6982 | ||
6983 | /* Set default names for some unnamed DIEs. */ | |
6984 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
6985 | || part_die->tag == DW_TAG_class_type)) | |
6986 | part_die->name = "(anonymous class)"; | |
6987 | ||
6988 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
6989 | part_die->name = "(anonymous namespace)"; | |
6990 | ||
6991 | if (part_die->tag == DW_TAG_structure_type | |
6992 | || part_die->tag == DW_TAG_class_type | |
6993 | || part_die->tag == DW_TAG_union_type) | |
6994 | guess_structure_name (part_die, cu); | |
6995 | } | |
6996 | ||
a8329558 | 6997 | /* Read an attribute value described by an attribute form. */ |
c906108c | 6998 | |
fe1b8b76 | 6999 | static gdb_byte * |
a8329558 | 7000 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 7001 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 7002 | struct dwarf2_cu *cu) |
c906108c | 7003 | { |
e7c27a73 | 7004 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7005 | unsigned int bytes_read; |
7006 | struct dwarf_block *blk; | |
7007 | ||
a8329558 KW |
7008 | attr->form = form; |
7009 | switch (form) | |
c906108c SS |
7010 | { |
7011 | case DW_FORM_addr: | |
7012 | case DW_FORM_ref_addr: | |
e7c27a73 | 7013 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 7014 | info_ptr += bytes_read; |
c906108c SS |
7015 | break; |
7016 | case DW_FORM_block2: | |
7b5a2f43 | 7017 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7018 | blk->size = read_2_bytes (abfd, info_ptr); |
7019 | info_ptr += 2; | |
7020 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7021 | info_ptr += blk->size; | |
7022 | DW_BLOCK (attr) = blk; | |
7023 | break; | |
7024 | case DW_FORM_block4: | |
7b5a2f43 | 7025 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7026 | blk->size = read_4_bytes (abfd, info_ptr); |
7027 | info_ptr += 4; | |
7028 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7029 | info_ptr += blk->size; | |
7030 | DW_BLOCK (attr) = blk; | |
7031 | break; | |
7032 | case DW_FORM_data2: | |
7033 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
7034 | info_ptr += 2; | |
7035 | break; | |
7036 | case DW_FORM_data4: | |
7037 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
7038 | info_ptr += 4; | |
7039 | break; | |
7040 | case DW_FORM_data8: | |
7041 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
7042 | info_ptr += 8; | |
7043 | break; | |
7044 | case DW_FORM_string: | |
7045 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
8285870a | 7046 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
7047 | info_ptr += bytes_read; |
7048 | break; | |
4bdf3d34 JJ |
7049 | case DW_FORM_strp: |
7050 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
7051 | &bytes_read); | |
8285870a | 7052 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
7053 | info_ptr += bytes_read; |
7054 | break; | |
c906108c | 7055 | case DW_FORM_block: |
7b5a2f43 | 7056 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7057 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7058 | info_ptr += bytes_read; | |
7059 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7060 | info_ptr += blk->size; | |
7061 | DW_BLOCK (attr) = blk; | |
7062 | break; | |
7063 | case DW_FORM_block1: | |
7b5a2f43 | 7064 | blk = dwarf_alloc_block (cu); |
c906108c SS |
7065 | blk->size = read_1_byte (abfd, info_ptr); |
7066 | info_ptr += 1; | |
7067 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
7068 | info_ptr += blk->size; | |
7069 | DW_BLOCK (attr) = blk; | |
7070 | break; | |
7071 | case DW_FORM_data1: | |
7072 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7073 | info_ptr += 1; | |
7074 | break; | |
7075 | case DW_FORM_flag: | |
7076 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
7077 | info_ptr += 1; | |
7078 | break; | |
7079 | case DW_FORM_sdata: | |
7080 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
7081 | info_ptr += bytes_read; | |
7082 | break; | |
7083 | case DW_FORM_udata: | |
7084 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7085 | info_ptr += bytes_read; | |
7086 | break; | |
7087 | case DW_FORM_ref1: | |
10b3939b | 7088 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
7089 | info_ptr += 1; |
7090 | break; | |
7091 | case DW_FORM_ref2: | |
10b3939b | 7092 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
7093 | info_ptr += 2; |
7094 | break; | |
7095 | case DW_FORM_ref4: | |
10b3939b | 7096 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
7097 | info_ptr += 4; |
7098 | break; | |
613e1657 | 7099 | case DW_FORM_ref8: |
10b3939b | 7100 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
7101 | info_ptr += 8; |
7102 | break; | |
348e048f DE |
7103 | case DW_FORM_sig8: |
7104 | /* Convert the signature to something we can record in DW_UNSND | |
7105 | for later lookup. | |
7106 | NOTE: This is NULL if the type wasn't found. */ | |
7107 | DW_SIGNATURED_TYPE (attr) = | |
7108 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
7109 | info_ptr += 8; | |
7110 | break; | |
c906108c | 7111 | case DW_FORM_ref_udata: |
10b3939b DJ |
7112 | DW_ADDR (attr) = (cu->header.offset |
7113 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
7114 | info_ptr += bytes_read; |
7115 | break; | |
c906108c | 7116 | case DW_FORM_indirect: |
a8329558 KW |
7117 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
7118 | info_ptr += bytes_read; | |
e7c27a73 | 7119 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 7120 | break; |
c906108c | 7121 | default: |
8a3fe4f8 | 7122 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
7123 | dwarf_form_name (form), |
7124 | bfd_get_filename (abfd)); | |
c906108c | 7125 | } |
28e94949 JB |
7126 | |
7127 | /* We have seen instances where the compiler tried to emit a byte | |
7128 | size attribute of -1 which ended up being encoded as an unsigned | |
7129 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
7130 | an object of this size seems pretty unlikely so we can relatively | |
7131 | safely treat these cases as if the size attribute was invalid and | |
7132 | treat them as zero by default. */ | |
7133 | if (attr->name == DW_AT_byte_size | |
7134 | && form == DW_FORM_data4 | |
7135 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
7136 | { |
7137 | complaint | |
7138 | (&symfile_complaints, | |
43bbcdc2 PH |
7139 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
7140 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
7141 | DW_UNSND (attr) = 0; |
7142 | } | |
28e94949 | 7143 | |
c906108c SS |
7144 | return info_ptr; |
7145 | } | |
7146 | ||
a8329558 KW |
7147 | /* Read an attribute described by an abbreviated attribute. */ |
7148 | ||
fe1b8b76 | 7149 | static gdb_byte * |
a8329558 | 7150 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 7151 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
7152 | { |
7153 | attr->name = abbrev->name; | |
e7c27a73 | 7154 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
7155 | } |
7156 | ||
c906108c SS |
7157 | /* read dwarf information from a buffer */ |
7158 | ||
7159 | static unsigned int | |
fe1b8b76 | 7160 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7161 | { |
fe1b8b76 | 7162 | return bfd_get_8 (abfd, buf); |
c906108c SS |
7163 | } |
7164 | ||
7165 | static int | |
fe1b8b76 | 7166 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 7167 | { |
fe1b8b76 | 7168 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
7169 | } |
7170 | ||
7171 | static unsigned int | |
fe1b8b76 | 7172 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7173 | { |
fe1b8b76 | 7174 | return bfd_get_16 (abfd, buf); |
c906108c SS |
7175 | } |
7176 | ||
7177 | static int | |
fe1b8b76 | 7178 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7179 | { |
fe1b8b76 | 7180 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
7181 | } |
7182 | ||
7183 | static unsigned int | |
fe1b8b76 | 7184 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7185 | { |
fe1b8b76 | 7186 | return bfd_get_32 (abfd, buf); |
c906108c SS |
7187 | } |
7188 | ||
7189 | static int | |
fe1b8b76 | 7190 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7191 | { |
fe1b8b76 | 7192 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
7193 | } |
7194 | ||
93311388 | 7195 | static ULONGEST |
fe1b8b76 | 7196 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 7197 | { |
fe1b8b76 | 7198 | return bfd_get_64 (abfd, buf); |
c906108c SS |
7199 | } |
7200 | ||
7201 | static CORE_ADDR | |
fe1b8b76 | 7202 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 7203 | unsigned int *bytes_read) |
c906108c | 7204 | { |
e7c27a73 | 7205 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
7206 | CORE_ADDR retval = 0; |
7207 | ||
107d2387 | 7208 | if (cu_header->signed_addr_p) |
c906108c | 7209 | { |
107d2387 AC |
7210 | switch (cu_header->addr_size) |
7211 | { | |
7212 | case 2: | |
fe1b8b76 | 7213 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
7214 | break; |
7215 | case 4: | |
fe1b8b76 | 7216 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
7217 | break; |
7218 | case 8: | |
fe1b8b76 | 7219 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
7220 | break; |
7221 | default: | |
8e65ff28 | 7222 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7223 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 7224 | bfd_get_filename (abfd)); |
107d2387 AC |
7225 | } |
7226 | } | |
7227 | else | |
7228 | { | |
7229 | switch (cu_header->addr_size) | |
7230 | { | |
7231 | case 2: | |
fe1b8b76 | 7232 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
7233 | break; |
7234 | case 4: | |
fe1b8b76 | 7235 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
7236 | break; |
7237 | case 8: | |
fe1b8b76 | 7238 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
7239 | break; |
7240 | default: | |
8e65ff28 | 7241 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 7242 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 7243 | bfd_get_filename (abfd)); |
107d2387 | 7244 | } |
c906108c | 7245 | } |
64367e0a | 7246 | |
107d2387 AC |
7247 | *bytes_read = cu_header->addr_size; |
7248 | return retval; | |
c906108c SS |
7249 | } |
7250 | ||
f7ef9339 | 7251 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
7252 | specification allows the initial length to take up either 4 bytes |
7253 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
7254 | bytes describe the length and all offsets will be 8 bytes in length | |
7255 | instead of 4. | |
7256 | ||
f7ef9339 KB |
7257 | An older, non-standard 64-bit format is also handled by this |
7258 | function. The older format in question stores the initial length | |
7259 | as an 8-byte quantity without an escape value. Lengths greater | |
7260 | than 2^32 aren't very common which means that the initial 4 bytes | |
7261 | is almost always zero. Since a length value of zero doesn't make | |
7262 | sense for the 32-bit format, this initial zero can be considered to | |
7263 | be an escape value which indicates the presence of the older 64-bit | |
7264 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
7265 | greater than 4GB. If it becomes necessary to handle lengths |
7266 | somewhat larger than 4GB, we could allow other small values (such | |
7267 | as the non-sensical values of 1, 2, and 3) to also be used as | |
7268 | escape values indicating the presence of the old format. | |
f7ef9339 | 7269 | |
917c78fc MK |
7270 | The value returned via bytes_read should be used to increment the |
7271 | relevant pointer after calling read_initial_length(). | |
c764a876 | 7272 | |
613e1657 KB |
7273 | [ Note: read_initial_length() and read_offset() are based on the |
7274 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 7275 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
7276 | from: |
7277 | ||
f7ef9339 | 7278 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
7279 | |
7280 | This document is only a draft and is subject to change. (So beware.) | |
7281 | ||
f7ef9339 | 7282 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
7283 | determined empirically by examining 64-bit ELF files produced by |
7284 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
7285 | |
7286 | - Kevin, July 16, 2002 | |
613e1657 KB |
7287 | ] */ |
7288 | ||
7289 | static LONGEST | |
c764a876 | 7290 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 7291 | { |
fe1b8b76 | 7292 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 7293 | |
dd373385 | 7294 | if (length == 0xffffffff) |
613e1657 | 7295 | { |
fe1b8b76 | 7296 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 7297 | *bytes_read = 12; |
613e1657 | 7298 | } |
dd373385 | 7299 | else if (length == 0) |
f7ef9339 | 7300 | { |
dd373385 | 7301 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 7302 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 7303 | *bytes_read = 8; |
f7ef9339 | 7304 | } |
613e1657 KB |
7305 | else |
7306 | { | |
7307 | *bytes_read = 4; | |
613e1657 KB |
7308 | } |
7309 | ||
c764a876 DE |
7310 | return length; |
7311 | } | |
dd373385 | 7312 | |
c764a876 DE |
7313 | /* Cover function for read_initial_length. |
7314 | Returns the length of the object at BUF, and stores the size of the | |
7315 | initial length in *BYTES_READ and stores the size that offsets will be in | |
7316 | *OFFSET_SIZE. | |
7317 | If the initial length size is not equivalent to that specified in | |
7318 | CU_HEADER then issue a complaint. | |
7319 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 7320 | |
c764a876 DE |
7321 | static LONGEST |
7322 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
7323 | const struct comp_unit_head *cu_header, | |
7324 | unsigned int *bytes_read, | |
7325 | unsigned int *offset_size) | |
7326 | { | |
7327 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
7328 | ||
7329 | gdb_assert (cu_header->initial_length_size == 4 | |
7330 | || cu_header->initial_length_size == 8 | |
7331 | || cu_header->initial_length_size == 12); | |
7332 | ||
7333 | if (cu_header->initial_length_size != *bytes_read) | |
7334 | complaint (&symfile_complaints, | |
7335 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 7336 | |
c764a876 | 7337 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 7338 | return length; |
613e1657 KB |
7339 | } |
7340 | ||
7341 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 7342 | given by cu_header->offset_size. */ |
613e1657 KB |
7343 | |
7344 | static LONGEST | |
fe1b8b76 | 7345 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 7346 | unsigned int *bytes_read) |
c764a876 DE |
7347 | { |
7348 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
7349 | *bytes_read = cu_header->offset_size; | |
7350 | return offset; | |
7351 | } | |
7352 | ||
7353 | /* Read an offset from the data stream. */ | |
7354 | ||
7355 | static LONGEST | |
7356 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
7357 | { |
7358 | LONGEST retval = 0; | |
7359 | ||
c764a876 | 7360 | switch (offset_size) |
613e1657 KB |
7361 | { |
7362 | case 4: | |
fe1b8b76 | 7363 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
7364 | break; |
7365 | case 8: | |
fe1b8b76 | 7366 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
7367 | break; |
7368 | default: | |
8e65ff28 | 7369 | internal_error (__FILE__, __LINE__, |
c764a876 | 7370 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 7371 | bfd_get_filename (abfd)); |
613e1657 KB |
7372 | } |
7373 | ||
917c78fc | 7374 | return retval; |
613e1657 KB |
7375 | } |
7376 | ||
fe1b8b76 JB |
7377 | static gdb_byte * |
7378 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
7379 | { |
7380 | /* If the size of a host char is 8 bits, we can return a pointer | |
7381 | to the buffer, otherwise we have to copy the data to a buffer | |
7382 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7383 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 7384 | return buf; |
c906108c SS |
7385 | } |
7386 | ||
7387 | static char * | |
fe1b8b76 | 7388 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
7389 | { |
7390 | /* If the size of a host char is 8 bits, we can return a pointer | |
7391 | to the string, otherwise we have to copy the string to a buffer | |
7392 | allocated on the temporary obstack. */ | |
4bdf3d34 | 7393 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
7394 | if (*buf == '\0') |
7395 | { | |
7396 | *bytes_read_ptr = 1; | |
7397 | return NULL; | |
7398 | } | |
fe1b8b76 JB |
7399 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
7400 | return (char *) buf; | |
4bdf3d34 JJ |
7401 | } |
7402 | ||
7403 | static char * | |
fe1b8b76 | 7404 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
7405 | const struct comp_unit_head *cu_header, |
7406 | unsigned int *bytes_read_ptr) | |
7407 | { | |
c764a876 | 7408 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 7409 | |
dce234bc | 7410 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 7411 | { |
8a3fe4f8 | 7412 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 7413 | bfd_get_filename (abfd)); |
4bdf3d34 | 7414 | return NULL; |
c906108c | 7415 | } |
dce234bc | 7416 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 7417 | { |
8a3fe4f8 | 7418 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 7419 | bfd_get_filename (abfd)); |
c906108c SS |
7420 | return NULL; |
7421 | } | |
4bdf3d34 | 7422 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 7423 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 7424 | return NULL; |
dce234bc | 7425 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
7426 | } |
7427 | ||
ce5d95e1 | 7428 | static unsigned long |
fe1b8b76 | 7429 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7430 | { |
ce5d95e1 JB |
7431 | unsigned long result; |
7432 | unsigned int num_read; | |
c906108c SS |
7433 | int i, shift; |
7434 | unsigned char byte; | |
7435 | ||
7436 | result = 0; | |
7437 | shift = 0; | |
7438 | num_read = 0; | |
7439 | i = 0; | |
7440 | while (1) | |
7441 | { | |
fe1b8b76 | 7442 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7443 | buf++; |
7444 | num_read++; | |
ce5d95e1 | 7445 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
7446 | if ((byte & 128) == 0) |
7447 | { | |
7448 | break; | |
7449 | } | |
7450 | shift += 7; | |
7451 | } | |
7452 | *bytes_read_ptr = num_read; | |
7453 | return result; | |
7454 | } | |
7455 | ||
ce5d95e1 | 7456 | static long |
fe1b8b76 | 7457 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 7458 | { |
ce5d95e1 | 7459 | long result; |
77e0b926 | 7460 | int i, shift, num_read; |
c906108c SS |
7461 | unsigned char byte; |
7462 | ||
7463 | result = 0; | |
7464 | shift = 0; | |
c906108c SS |
7465 | num_read = 0; |
7466 | i = 0; | |
7467 | while (1) | |
7468 | { | |
fe1b8b76 | 7469 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
7470 | buf++; |
7471 | num_read++; | |
ce5d95e1 | 7472 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
7473 | shift += 7; |
7474 | if ((byte & 128) == 0) | |
7475 | { | |
7476 | break; | |
7477 | } | |
7478 | } | |
77e0b926 DJ |
7479 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
7480 | result |= -(((long)1) << shift); | |
c906108c SS |
7481 | *bytes_read_ptr = num_read; |
7482 | return result; | |
7483 | } | |
7484 | ||
4bb7a0a7 DJ |
7485 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
7486 | ||
fe1b8b76 JB |
7487 | static gdb_byte * |
7488 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
7489 | { |
7490 | int byte; | |
7491 | ||
7492 | while (1) | |
7493 | { | |
fe1b8b76 | 7494 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
7495 | buf++; |
7496 | if ((byte & 128) == 0) | |
7497 | return buf; | |
7498 | } | |
7499 | } | |
7500 | ||
c906108c | 7501 | static void |
e142c38c | 7502 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
7503 | { |
7504 | switch (lang) | |
7505 | { | |
7506 | case DW_LANG_C89: | |
76bee0cc | 7507 | case DW_LANG_C99: |
c906108c | 7508 | case DW_LANG_C: |
e142c38c | 7509 | cu->language = language_c; |
c906108c SS |
7510 | break; |
7511 | case DW_LANG_C_plus_plus: | |
e142c38c | 7512 | cu->language = language_cplus; |
c906108c SS |
7513 | break; |
7514 | case DW_LANG_Fortran77: | |
7515 | case DW_LANG_Fortran90: | |
b21b22e0 | 7516 | case DW_LANG_Fortran95: |
e142c38c | 7517 | cu->language = language_fortran; |
c906108c SS |
7518 | break; |
7519 | case DW_LANG_Mips_Assembler: | |
e142c38c | 7520 | cu->language = language_asm; |
c906108c | 7521 | break; |
bebd888e | 7522 | case DW_LANG_Java: |
e142c38c | 7523 | cu->language = language_java; |
bebd888e | 7524 | break; |
c906108c | 7525 | case DW_LANG_Ada83: |
8aaf0b47 | 7526 | case DW_LANG_Ada95: |
bc5f45f8 JB |
7527 | cu->language = language_ada; |
7528 | break; | |
72019c9c GM |
7529 | case DW_LANG_Modula2: |
7530 | cu->language = language_m2; | |
7531 | break; | |
fe8e67fd PM |
7532 | case DW_LANG_Pascal83: |
7533 | cu->language = language_pascal; | |
7534 | break; | |
22566fbd DJ |
7535 | case DW_LANG_ObjC: |
7536 | cu->language = language_objc; | |
7537 | break; | |
c906108c SS |
7538 | case DW_LANG_Cobol74: |
7539 | case DW_LANG_Cobol85: | |
c906108c | 7540 | default: |
e142c38c | 7541 | cu->language = language_minimal; |
c906108c SS |
7542 | break; |
7543 | } | |
e142c38c | 7544 | cu->language_defn = language_def (cu->language); |
c906108c SS |
7545 | } |
7546 | ||
7547 | /* Return the named attribute or NULL if not there. */ | |
7548 | ||
7549 | static struct attribute * | |
e142c38c | 7550 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
7551 | { |
7552 | unsigned int i; | |
7553 | struct attribute *spec = NULL; | |
7554 | ||
7555 | for (i = 0; i < die->num_attrs; ++i) | |
7556 | { | |
7557 | if (die->attrs[i].name == name) | |
10b3939b | 7558 | return &die->attrs[i]; |
c906108c SS |
7559 | if (die->attrs[i].name == DW_AT_specification |
7560 | || die->attrs[i].name == DW_AT_abstract_origin) | |
7561 | spec = &die->attrs[i]; | |
7562 | } | |
c906108c | 7563 | |
10b3939b | 7564 | if (spec) |
f2f0e013 DJ |
7565 | { |
7566 | die = follow_die_ref (die, spec, &cu); | |
7567 | return dwarf2_attr (die, name, cu); | |
7568 | } | |
c5aa993b | 7569 | |
c906108c SS |
7570 | return NULL; |
7571 | } | |
7572 | ||
348e048f DE |
7573 | /* Return the named attribute or NULL if not there, |
7574 | but do not follow DW_AT_specification, etc. | |
7575 | This is for use in contexts where we're reading .debug_types dies. | |
7576 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
7577 | back up the chain, and we want to go down. */ | |
7578 | ||
7579 | static struct attribute * | |
7580 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
7581 | struct dwarf2_cu *cu) | |
7582 | { | |
7583 | unsigned int i; | |
7584 | ||
7585 | for (i = 0; i < die->num_attrs; ++i) | |
7586 | if (die->attrs[i].name == name) | |
7587 | return &die->attrs[i]; | |
7588 | ||
7589 | return NULL; | |
7590 | } | |
7591 | ||
05cf31d1 JB |
7592 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
7593 | and holds a non-zero value. This function should only be used for | |
7594 | DW_FORM_flag attributes. */ | |
7595 | ||
7596 | static int | |
7597 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
7598 | { | |
7599 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
7600 | ||
7601 | return (attr && DW_UNSND (attr)); | |
7602 | } | |
7603 | ||
3ca72b44 | 7604 | static int |
e142c38c | 7605 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 7606 | { |
05cf31d1 JB |
7607 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
7608 | which value is non-zero. However, we have to be careful with | |
7609 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
7610 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
7611 | end up accidently finding a declaration attribute that belongs | |
7612 | to a different DIE referenced by the specification attribute, | |
7613 | even though the given DIE does not have a declaration attribute. */ | |
7614 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
7615 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
7616 | } |
7617 | ||
63d06c5c | 7618 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 7619 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
7620 | containing the return value on output. If there is no |
7621 | specification, but there is an abstract origin, that is | |
7622 | returned. */ | |
63d06c5c DC |
7623 | |
7624 | static struct die_info * | |
f2f0e013 | 7625 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 7626 | { |
f2f0e013 DJ |
7627 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
7628 | *spec_cu); | |
63d06c5c | 7629 | |
edb3359d DJ |
7630 | if (spec_attr == NULL) |
7631 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
7632 | ||
63d06c5c DC |
7633 | if (spec_attr == NULL) |
7634 | return NULL; | |
7635 | else | |
f2f0e013 | 7636 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 7637 | } |
c906108c | 7638 | |
debd256d JB |
7639 | /* Free the line_header structure *LH, and any arrays and strings it |
7640 | refers to. */ | |
7641 | static void | |
7642 | free_line_header (struct line_header *lh) | |
7643 | { | |
7644 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 7645 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
7646 | |
7647 | /* Remember that all the lh->file_names[i].name pointers are | |
7648 | pointers into debug_line_buffer, and don't need to be freed. */ | |
7649 | if (lh->file_names) | |
a8bc7b56 | 7650 | xfree (lh->file_names); |
debd256d JB |
7651 | |
7652 | /* Similarly for the include directory names. */ | |
7653 | if (lh->include_dirs) | |
a8bc7b56 | 7654 | xfree (lh->include_dirs); |
debd256d | 7655 | |
a8bc7b56 | 7656 | xfree (lh); |
debd256d JB |
7657 | } |
7658 | ||
7659 | ||
7660 | /* Add an entry to LH's include directory table. */ | |
7661 | static void | |
7662 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 7663 | { |
debd256d JB |
7664 | /* Grow the array if necessary. */ |
7665 | if (lh->include_dirs_size == 0) | |
c5aa993b | 7666 | { |
debd256d JB |
7667 | lh->include_dirs_size = 1; /* for testing */ |
7668 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
7669 | * sizeof (*lh->include_dirs)); | |
7670 | } | |
7671 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
7672 | { | |
7673 | lh->include_dirs_size *= 2; | |
7674 | lh->include_dirs = xrealloc (lh->include_dirs, | |
7675 | (lh->include_dirs_size | |
7676 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 7677 | } |
c906108c | 7678 | |
debd256d JB |
7679 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
7680 | } | |
7681 | ||
7682 | ||
7683 | /* Add an entry to LH's file name table. */ | |
7684 | static void | |
7685 | add_file_name (struct line_header *lh, | |
7686 | char *name, | |
7687 | unsigned int dir_index, | |
7688 | unsigned int mod_time, | |
7689 | unsigned int length) | |
7690 | { | |
7691 | struct file_entry *fe; | |
7692 | ||
7693 | /* Grow the array if necessary. */ | |
7694 | if (lh->file_names_size == 0) | |
7695 | { | |
7696 | lh->file_names_size = 1; /* for testing */ | |
7697 | lh->file_names = xmalloc (lh->file_names_size | |
7698 | * sizeof (*lh->file_names)); | |
7699 | } | |
7700 | else if (lh->num_file_names >= lh->file_names_size) | |
7701 | { | |
7702 | lh->file_names_size *= 2; | |
7703 | lh->file_names = xrealloc (lh->file_names, | |
7704 | (lh->file_names_size | |
7705 | * sizeof (*lh->file_names))); | |
7706 | } | |
7707 | ||
7708 | fe = &lh->file_names[lh->num_file_names++]; | |
7709 | fe->name = name; | |
7710 | fe->dir_index = dir_index; | |
7711 | fe->mod_time = mod_time; | |
7712 | fe->length = length; | |
aaa75496 | 7713 | fe->included_p = 0; |
cb1df416 | 7714 | fe->symtab = NULL; |
debd256d JB |
7715 | } |
7716 | ||
7717 | ||
7718 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
7719 | .debug_line, according to the endianness of ABFD. Return a pointer |
7720 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
7721 | |
7722 | NOTE: the strings in the include directory and file name tables of | |
7723 | the returned object point into debug_line_buffer, and must not be | |
7724 | freed. */ | |
7725 | static struct line_header * | |
7726 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 7727 | struct dwarf2_cu *cu) |
debd256d JB |
7728 | { |
7729 | struct cleanup *back_to; | |
7730 | struct line_header *lh; | |
fe1b8b76 | 7731 | gdb_byte *line_ptr; |
c764a876 | 7732 | unsigned int bytes_read, offset_size; |
debd256d JB |
7733 | int i; |
7734 | char *cur_dir, *cur_file; | |
7735 | ||
dce234bc | 7736 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 7737 | { |
e2e0b3e5 | 7738 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
7739 | return 0; |
7740 | } | |
7741 | ||
a738430d MK |
7742 | /* Make sure that at least there's room for the total_length field. |
7743 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 7744 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 7745 | { |
4d3c2250 | 7746 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7747 | return 0; |
7748 | } | |
7749 | ||
7750 | lh = xmalloc (sizeof (*lh)); | |
7751 | memset (lh, 0, sizeof (*lh)); | |
7752 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
7753 | (void *) lh); | |
7754 | ||
dce234bc | 7755 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 7756 | |
a738430d | 7757 | /* Read in the header. */ |
dd373385 | 7758 | lh->total_length = |
c764a876 DE |
7759 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
7760 | &bytes_read, &offset_size); | |
debd256d | 7761 | line_ptr += bytes_read; |
dce234bc PP |
7762 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
7763 | + dwarf2_per_objfile->line.size)) | |
debd256d | 7764 | { |
4d3c2250 | 7765 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7766 | return 0; |
7767 | } | |
7768 | lh->statement_program_end = line_ptr + lh->total_length; | |
7769 | lh->version = read_2_bytes (abfd, line_ptr); | |
7770 | line_ptr += 2; | |
c764a876 DE |
7771 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
7772 | line_ptr += offset_size; | |
debd256d JB |
7773 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
7774 | line_ptr += 1; | |
7775 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
7776 | line_ptr += 1; | |
7777 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
7778 | line_ptr += 1; | |
7779 | lh->line_range = read_1_byte (abfd, line_ptr); | |
7780 | line_ptr += 1; | |
7781 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
7782 | line_ptr += 1; | |
7783 | lh->standard_opcode_lengths | |
fe1b8b76 | 7784 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
7785 | |
7786 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
7787 | for (i = 1; i < lh->opcode_base; ++i) | |
7788 | { | |
7789 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
7790 | line_ptr += 1; | |
7791 | } | |
7792 | ||
a738430d | 7793 | /* Read directory table. */ |
debd256d JB |
7794 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7795 | { | |
7796 | line_ptr += bytes_read; | |
7797 | add_include_dir (lh, cur_dir); | |
7798 | } | |
7799 | line_ptr += bytes_read; | |
7800 | ||
a738430d | 7801 | /* Read file name table. */ |
debd256d JB |
7802 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7803 | { | |
7804 | unsigned int dir_index, mod_time, length; | |
7805 | ||
7806 | line_ptr += bytes_read; | |
7807 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7808 | line_ptr += bytes_read; | |
7809 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7810 | line_ptr += bytes_read; | |
7811 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7812 | line_ptr += bytes_read; | |
7813 | ||
7814 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7815 | } | |
7816 | line_ptr += bytes_read; | |
7817 | lh->statement_program_start = line_ptr; | |
7818 | ||
dce234bc PP |
7819 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
7820 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 7821 | complaint (&symfile_complaints, |
e2e0b3e5 | 7822 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
7823 | |
7824 | discard_cleanups (back_to); | |
7825 | return lh; | |
7826 | } | |
c906108c | 7827 | |
5fb290d7 DJ |
7828 | /* This function exists to work around a bug in certain compilers |
7829 | (particularly GCC 2.95), in which the first line number marker of a | |
7830 | function does not show up until after the prologue, right before | |
7831 | the second line number marker. This function shifts ADDRESS down | |
7832 | to the beginning of the function if necessary, and is called on | |
7833 | addresses passed to record_line. */ | |
7834 | ||
7835 | static CORE_ADDR | |
e142c38c | 7836 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
7837 | { |
7838 | struct function_range *fn; | |
7839 | ||
7840 | /* Find the function_range containing address. */ | |
e142c38c | 7841 | if (!cu->first_fn) |
5fb290d7 DJ |
7842 | return address; |
7843 | ||
e142c38c DJ |
7844 | if (!cu->cached_fn) |
7845 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 7846 | |
e142c38c | 7847 | fn = cu->cached_fn; |
5fb290d7 DJ |
7848 | while (fn) |
7849 | if (fn->lowpc <= address && fn->highpc > address) | |
7850 | goto found; | |
7851 | else | |
7852 | fn = fn->next; | |
7853 | ||
e142c38c DJ |
7854 | fn = cu->first_fn; |
7855 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
7856 | if (fn->lowpc <= address && fn->highpc > address) |
7857 | goto found; | |
7858 | else | |
7859 | fn = fn->next; | |
7860 | ||
7861 | return address; | |
7862 | ||
7863 | found: | |
7864 | if (fn->seen_line) | |
7865 | return address; | |
7866 | if (address != fn->lowpc) | |
4d3c2250 | 7867 | complaint (&symfile_complaints, |
e2e0b3e5 | 7868 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 7869 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
7870 | fn->seen_line = 1; |
7871 | return fn->lowpc; | |
7872 | } | |
7873 | ||
aaa75496 JB |
7874 | /* Decode the Line Number Program (LNP) for the given line_header |
7875 | structure and CU. The actual information extracted and the type | |
7876 | of structures created from the LNP depends on the value of PST. | |
7877 | ||
7878 | 1. If PST is NULL, then this procedure uses the data from the program | |
7879 | to create all necessary symbol tables, and their linetables. | |
7880 | The compilation directory of the file is passed in COMP_DIR, | |
7881 | and must not be NULL. | |
7882 | ||
7883 | 2. If PST is not NULL, this procedure reads the program to determine | |
7884 | the list of files included by the unit represented by PST, and | |
7885 | builds all the associated partial symbol tables. In this case, | |
7886 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
7887 | is not used to compute the full name of the symtab, and therefore | |
7888 | omitting it when building the partial symtab does not introduce | |
7889 | the potential for inconsistency - a partial symtab and its associated | |
7890 | symbtab having a different fullname -). */ | |
debd256d | 7891 | |
c906108c | 7892 | static void |
debd256d | 7893 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 7894 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 7895 | { |
a8c50c1f | 7896 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 7897 | gdb_byte *line_end; |
a8c50c1f | 7898 | unsigned int bytes_read, extended_len; |
c906108c | 7899 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
7900 | CORE_ADDR baseaddr; |
7901 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 7902 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 7903 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 7904 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
7905 | |
7906 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7907 | |
debd256d JB |
7908 | line_ptr = lh->statement_program_start; |
7909 | line_end = lh->statement_program_end; | |
c906108c SS |
7910 | |
7911 | /* Read the statement sequences until there's nothing left. */ | |
7912 | while (line_ptr < line_end) | |
7913 | { | |
7914 | /* state machine registers */ | |
7915 | CORE_ADDR address = 0; | |
7916 | unsigned int file = 1; | |
7917 | unsigned int line = 1; | |
7918 | unsigned int column = 0; | |
debd256d | 7919 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
7920 | int basic_block = 0; |
7921 | int end_sequence = 0; | |
fbf65064 | 7922 | CORE_ADDR addr; |
c906108c | 7923 | |
aaa75496 | 7924 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 7925 | { |
aaa75496 | 7926 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
7927 | /* lh->include_dirs and lh->file_names are 0-based, but the |
7928 | directory and file name numbers in the statement program | |
7929 | are 1-based. */ | |
7930 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 7931 | char *dir = NULL; |
a738430d | 7932 | |
debd256d JB |
7933 | if (fe->dir_index) |
7934 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
7935 | |
7936 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
7937 | } |
7938 | ||
a738430d | 7939 | /* Decode the table. */ |
c5aa993b | 7940 | while (!end_sequence) |
c906108c SS |
7941 | { |
7942 | op_code = read_1_byte (abfd, line_ptr); | |
7943 | line_ptr += 1; | |
59205f5a JB |
7944 | if (line_ptr > line_end) |
7945 | { | |
7946 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
7947 | break; | |
7948 | } | |
9aa1fe7e | 7949 | |
debd256d | 7950 | if (op_code >= lh->opcode_base) |
a738430d MK |
7951 | { |
7952 | /* Special operand. */ | |
debd256d JB |
7953 | adj_opcode = op_code - lh->opcode_base; |
7954 | address += (adj_opcode / lh->line_range) | |
7955 | * lh->minimum_instruction_length; | |
7956 | line += lh->line_base + (adj_opcode % lh->line_range); | |
59205f5a | 7957 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
7958 | dwarf2_debug_line_missing_file_complaint (); |
7959 | else | |
7960 | { | |
7961 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 7962 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
7963 | { |
7964 | if (last_subfile != current_subfile) | |
7965 | { | |
7966 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
7967 | if (last_subfile) | |
7968 | record_line (last_subfile, 0, addr); | |
7969 | last_subfile = current_subfile; | |
7970 | } | |
25e43795 | 7971 | /* Append row to matrix using current values. */ |
fbf65064 UW |
7972 | addr = check_cu_functions (address, cu); |
7973 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
7974 | record_line (current_subfile, line, addr); | |
366da635 | 7975 | } |
25e43795 | 7976 | } |
ca5f395d | 7977 | basic_block = 0; |
9aa1fe7e GK |
7978 | } |
7979 | else switch (op_code) | |
c906108c SS |
7980 | { |
7981 | case DW_LNS_extended_op: | |
a8c50c1f | 7982 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 7983 | line_ptr += bytes_read; |
a8c50c1f | 7984 | extended_end = line_ptr + extended_len; |
c906108c SS |
7985 | extended_op = read_1_byte (abfd, line_ptr); |
7986 | line_ptr += 1; | |
7987 | switch (extended_op) | |
7988 | { | |
7989 | case DW_LNE_end_sequence: | |
7990 | end_sequence = 1; | |
c906108c SS |
7991 | break; |
7992 | case DW_LNE_set_address: | |
e7c27a73 | 7993 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
7994 | line_ptr += bytes_read; |
7995 | address += baseaddr; | |
c906108c SS |
7996 | break; |
7997 | case DW_LNE_define_file: | |
debd256d JB |
7998 | { |
7999 | char *cur_file; | |
8000 | unsigned int dir_index, mod_time, length; | |
8001 | ||
8002 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
8003 | line_ptr += bytes_read; | |
8004 | dir_index = | |
8005 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8006 | line_ptr += bytes_read; | |
8007 | mod_time = | |
8008 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8009 | line_ptr += bytes_read; | |
8010 | length = | |
8011 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8012 | line_ptr += bytes_read; | |
8013 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
8014 | } | |
c906108c | 8015 | break; |
d0c6ba3d CC |
8016 | case DW_LNE_set_discriminator: |
8017 | /* The discriminator is not interesting to the debugger; | |
8018 | just ignore it. */ | |
8019 | line_ptr = extended_end; | |
8020 | break; | |
c906108c | 8021 | default: |
4d3c2250 | 8022 | complaint (&symfile_complaints, |
e2e0b3e5 | 8023 | _("mangled .debug_line section")); |
debd256d | 8024 | return; |
c906108c | 8025 | } |
a8c50c1f DJ |
8026 | /* Make sure that we parsed the extended op correctly. If e.g. |
8027 | we expected a different address size than the producer used, | |
8028 | we may have read the wrong number of bytes. */ | |
8029 | if (line_ptr != extended_end) | |
8030 | { | |
8031 | complaint (&symfile_complaints, | |
8032 | _("mangled .debug_line section")); | |
8033 | return; | |
8034 | } | |
c906108c SS |
8035 | break; |
8036 | case DW_LNS_copy: | |
59205f5a | 8037 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8038 | dwarf2_debug_line_missing_file_complaint (); |
8039 | else | |
366da635 | 8040 | { |
25e43795 | 8041 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 8042 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
8043 | { |
8044 | if (last_subfile != current_subfile) | |
8045 | { | |
8046 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8047 | if (last_subfile) | |
8048 | record_line (last_subfile, 0, addr); | |
8049 | last_subfile = current_subfile; | |
8050 | } | |
8051 | addr = check_cu_functions (address, cu); | |
8052 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
8053 | record_line (current_subfile, line, addr); | |
8054 | } | |
366da635 | 8055 | } |
c906108c SS |
8056 | basic_block = 0; |
8057 | break; | |
8058 | case DW_LNS_advance_pc: | |
debd256d | 8059 | address += lh->minimum_instruction_length |
c906108c SS |
8060 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8061 | line_ptr += bytes_read; | |
8062 | break; | |
8063 | case DW_LNS_advance_line: | |
8064 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
8065 | line_ptr += bytes_read; | |
8066 | break; | |
8067 | case DW_LNS_set_file: | |
debd256d | 8068 | { |
a738430d MK |
8069 | /* The arrays lh->include_dirs and lh->file_names are |
8070 | 0-based, but the directory and file name numbers in | |
8071 | the statement program are 1-based. */ | |
debd256d | 8072 | struct file_entry *fe; |
4f1520fb | 8073 | char *dir = NULL; |
a738430d | 8074 | |
debd256d JB |
8075 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
8076 | line_ptr += bytes_read; | |
59205f5a | 8077 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
8078 | dwarf2_debug_line_missing_file_complaint (); |
8079 | else | |
8080 | { | |
8081 | fe = &lh->file_names[file - 1]; | |
8082 | if (fe->dir_index) | |
8083 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8084 | if (!decode_for_pst_p) | |
8085 | { | |
8086 | last_subfile = current_subfile; | |
8087 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8088 | } | |
8089 | } | |
debd256d | 8090 | } |
c906108c SS |
8091 | break; |
8092 | case DW_LNS_set_column: | |
8093 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8094 | line_ptr += bytes_read; | |
8095 | break; | |
8096 | case DW_LNS_negate_stmt: | |
8097 | is_stmt = (!is_stmt); | |
8098 | break; | |
8099 | case DW_LNS_set_basic_block: | |
8100 | basic_block = 1; | |
8101 | break; | |
c2c6d25f JM |
8102 | /* Add to the address register of the state machine the |
8103 | address increment value corresponding to special opcode | |
a738430d MK |
8104 | 255. I.e., this value is scaled by the minimum |
8105 | instruction length since special opcode 255 would have | |
8106 | scaled the the increment. */ | |
c906108c | 8107 | case DW_LNS_const_add_pc: |
debd256d JB |
8108 | address += (lh->minimum_instruction_length |
8109 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
8110 | break; |
8111 | case DW_LNS_fixed_advance_pc: | |
8112 | address += read_2_bytes (abfd, line_ptr); | |
8113 | line_ptr += 2; | |
8114 | break; | |
9aa1fe7e | 8115 | default: |
a738430d MK |
8116 | { |
8117 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 8118 | int i; |
a738430d | 8119 | |
debd256d | 8120 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
8121 | { |
8122 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
8123 | line_ptr += bytes_read; | |
8124 | } | |
8125 | } | |
c906108c SS |
8126 | } |
8127 | } | |
59205f5a JB |
8128 | if (lh->num_file_names < file || file == 0) |
8129 | dwarf2_debug_line_missing_file_complaint (); | |
8130 | else | |
8131 | { | |
8132 | lh->file_names[file - 1].included_p = 1; | |
8133 | if (!decode_for_pst_p) | |
fbf65064 UW |
8134 | { |
8135 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
8136 | record_line (current_subfile, 0, addr); | |
8137 | } | |
59205f5a | 8138 | } |
c906108c | 8139 | } |
aaa75496 JB |
8140 | |
8141 | if (decode_for_pst_p) | |
8142 | { | |
8143 | int file_index; | |
8144 | ||
8145 | /* Now that we're done scanning the Line Header Program, we can | |
8146 | create the psymtab of each included file. */ | |
8147 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
8148 | if (lh->file_names[file_index].included_p == 1) | |
8149 | { | |
5b5464ad JB |
8150 | const struct file_entry fe = lh->file_names [file_index]; |
8151 | char *include_name = fe.name; | |
8152 | char *dir_name = NULL; | |
8153 | char *pst_filename = pst->filename; | |
8154 | ||
8155 | if (fe.dir_index) | |
8156 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
8157 | ||
8158 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
8159 | { | |
1754f103 MK |
8160 | include_name = concat (dir_name, SLASH_STRING, |
8161 | include_name, (char *)NULL); | |
5b5464ad JB |
8162 | make_cleanup (xfree, include_name); |
8163 | } | |
8164 | ||
8165 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
8166 | { | |
1754f103 MK |
8167 | pst_filename = concat (pst->dirname, SLASH_STRING, |
8168 | pst_filename, (char *)NULL); | |
5b5464ad JB |
8169 | make_cleanup (xfree, pst_filename); |
8170 | } | |
8171 | ||
8172 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
8173 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
8174 | } | |
8175 | } | |
cb1df416 DJ |
8176 | else |
8177 | { | |
8178 | /* Make sure a symtab is created for every file, even files | |
8179 | which contain only variables (i.e. no code with associated | |
8180 | line numbers). */ | |
8181 | ||
8182 | int i; | |
8183 | struct file_entry *fe; | |
8184 | ||
8185 | for (i = 0; i < lh->num_file_names; i++) | |
8186 | { | |
8187 | char *dir = NULL; | |
8188 | fe = &lh->file_names[i]; | |
8189 | if (fe->dir_index) | |
8190 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8191 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
8192 | ||
8193 | /* Skip the main file; we don't need it, and it must be | |
8194 | allocated last, so that it will show up before the | |
8195 | non-primary symtabs in the objfile's symtab list. */ | |
8196 | if (current_subfile == first_subfile) | |
8197 | continue; | |
8198 | ||
8199 | if (current_subfile->symtab == NULL) | |
8200 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
8201 | cu->objfile); | |
8202 | fe->symtab = current_subfile->symtab; | |
8203 | } | |
8204 | } | |
c906108c SS |
8205 | } |
8206 | ||
8207 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
8208 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
8209 | or NULL if not known. COMP_DIR is the compilation directory for the |
8210 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
8211 | This routine tries to keep line numbers from identical absolute and |
8212 | relative file names in a common subfile. | |
8213 | ||
8214 | Using the `list' example from the GDB testsuite, which resides in | |
8215 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
8216 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
8217 | ||
c5aa993b JM |
8218 | DW_AT_name: /srcdir/list0.c |
8219 | DW_AT_comp_dir: /compdir | |
357e46e7 | 8220 | files.files[0].name: list0.h |
c5aa993b | 8221 | files.files[0].dir: /srcdir |
357e46e7 | 8222 | files.files[1].name: list0.c |
c5aa993b | 8223 | files.files[1].dir: /srcdir |
c906108c SS |
8224 | |
8225 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
8226 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
8227 | start_subfile will ensure that this happens provided that we pass the | |
8228 | concatenation of files.files[1].dir and files.files[1].name as the | |
8229 | subfile's name. */ | |
c906108c SS |
8230 | |
8231 | static void | |
4f1520fb | 8232 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 8233 | { |
4f1520fb FR |
8234 | char *fullname; |
8235 | ||
8236 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
8237 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
8238 | second argument to start_subfile. To be consistent, we do the | |
8239 | same here. In order not to lose the line information directory, | |
8240 | we concatenate it to the filename when it makes sense. | |
8241 | Note that the Dwarf3 standard says (speaking of filenames in line | |
8242 | information): ``The directory index is ignored for file names | |
8243 | that represent full path names''. Thus ignoring dirname in the | |
8244 | `else' branch below isn't an issue. */ | |
c906108c | 8245 | |
d5166ae1 | 8246 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
8247 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
8248 | else | |
8249 | fullname = filename; | |
c906108c | 8250 | |
4f1520fb FR |
8251 | start_subfile (fullname, comp_dir); |
8252 | ||
8253 | if (fullname != filename) | |
8254 | xfree (fullname); | |
c906108c SS |
8255 | } |
8256 | ||
4c2df51b DJ |
8257 | static void |
8258 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8259 | struct dwarf2_cu *cu) |
4c2df51b | 8260 | { |
e7c27a73 DJ |
8261 | struct objfile *objfile = cu->objfile; |
8262 | struct comp_unit_head *cu_header = &cu->header; | |
8263 | ||
4c2df51b DJ |
8264 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
8265 | code here to turn a symbol with DW_AT_external and a | |
8266 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
8267 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
8268 | with some versions of binutils) where shared libraries could have | |
8269 | relocations against symbols in their debug information - the | |
8270 | minimal symbol would have the right address, but the debug info | |
8271 | would not. It's no longer necessary, because we will explicitly | |
8272 | apply relocations when we read in the debug information now. */ | |
8273 | ||
8274 | /* A DW_AT_location attribute with no contents indicates that a | |
8275 | variable has been optimized away. */ | |
8276 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
8277 | { | |
8278 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
8279 | return; | |
8280 | } | |
8281 | ||
8282 | /* Handle one degenerate form of location expression specially, to | |
8283 | preserve GDB's previous behavior when section offsets are | |
8284 | specified. If this is just a DW_OP_addr then mark this symbol | |
8285 | as LOC_STATIC. */ | |
8286 | ||
8287 | if (attr_form_is_block (attr) | |
8288 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
8289 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
8290 | { | |
891d2f0b | 8291 | unsigned int dummy; |
4c2df51b DJ |
8292 | |
8293 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 8294 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 8295 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
8296 | fixup_symbol_section (sym, objfile); |
8297 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
8298 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
8299 | return; |
8300 | } | |
8301 | ||
8302 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
8303 | expression evaluator, and use LOC_COMPUTED only when necessary | |
8304 | (i.e. when the value of a register or memory location is | |
8305 | referenced, or a thread-local block, etc.). Then again, it might | |
8306 | not be worthwhile. I'm assuming that it isn't unless performance | |
8307 | or memory numbers show me otherwise. */ | |
8308 | ||
e7c27a73 | 8309 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
8310 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8311 | } | |
8312 | ||
c906108c SS |
8313 | /* Given a pointer to a DWARF information entry, figure out if we need |
8314 | to make a symbol table entry for it, and if so, create a new entry | |
8315 | and return a pointer to it. | |
8316 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 8317 | used the passed type. */ |
c906108c SS |
8318 | |
8319 | static struct symbol * | |
e7c27a73 | 8320 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 8321 | { |
e7c27a73 | 8322 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8323 | struct symbol *sym = NULL; |
8324 | char *name; | |
8325 | struct attribute *attr = NULL; | |
8326 | struct attribute *attr2 = NULL; | |
e142c38c | 8327 | CORE_ADDR baseaddr; |
edb3359d | 8328 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
8329 | |
8330 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 8331 | |
5c4e30ca | 8332 | if (die->tag != DW_TAG_namespace) |
e142c38c | 8333 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
8334 | else |
8335 | name = TYPE_NAME (type); | |
8336 | ||
c906108c SS |
8337 | if (name) |
8338 | { | |
4a146b47 | 8339 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
8340 | sizeof (struct symbol)); |
8341 | OBJSTAT (objfile, n_syms++); | |
8342 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
8343 | |
8344 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 8345 | SYMBOL_LANGUAGE (sym) = cu->language; |
04a679b8 | 8346 | SYMBOL_SET_NAMES (sym, name, strlen (name), 0, objfile); |
c906108c SS |
8347 | |
8348 | /* Default assumptions. | |
c5aa993b | 8349 | Use the passed type or decode it from the die. */ |
176620f1 | 8350 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 8351 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
8352 | if (type != NULL) |
8353 | SYMBOL_TYPE (sym) = type; | |
8354 | else | |
e7c27a73 | 8355 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
8356 | attr = dwarf2_attr (die, |
8357 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
8358 | cu); | |
c906108c SS |
8359 | if (attr) |
8360 | { | |
8361 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
8362 | } | |
cb1df416 | 8363 | |
edb3359d DJ |
8364 | attr = dwarf2_attr (die, |
8365 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
8366 | cu); | |
cb1df416 DJ |
8367 | if (attr) |
8368 | { | |
8369 | int file_index = DW_UNSND (attr); | |
8370 | if (cu->line_header == NULL | |
8371 | || file_index > cu->line_header->num_file_names) | |
8372 | complaint (&symfile_complaints, | |
8373 | _("file index out of range")); | |
1c3d648d | 8374 | else if (file_index > 0) |
cb1df416 DJ |
8375 | { |
8376 | struct file_entry *fe; | |
8377 | fe = &cu->line_header->file_names[file_index - 1]; | |
8378 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
8379 | } | |
8380 | } | |
8381 | ||
c906108c SS |
8382 | switch (die->tag) |
8383 | { | |
8384 | case DW_TAG_label: | |
e142c38c | 8385 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
8386 | if (attr) |
8387 | { | |
8388 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
8389 | } | |
8390 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
8391 | break; | |
8392 | case DW_TAG_subprogram: | |
8393 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8394 | finish_block. */ | |
8395 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 8396 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
8397 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
8398 | || cu->language == language_ada) | |
c906108c | 8399 | { |
2cfa0c8d JB |
8400 | /* Subprograms marked external are stored as a global symbol. |
8401 | Ada subprograms, whether marked external or not, are always | |
8402 | stored as a global symbol, because we want to be able to | |
8403 | access them globally. For instance, we want to be able | |
8404 | to break on a nested subprogram without having to | |
8405 | specify the context. */ | |
c906108c SS |
8406 | add_symbol_to_list (sym, &global_symbols); |
8407 | } | |
8408 | else | |
8409 | { | |
e142c38c | 8410 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8411 | } |
8412 | break; | |
edb3359d DJ |
8413 | case DW_TAG_inlined_subroutine: |
8414 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
8415 | finish_block. */ | |
8416 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
8417 | SYMBOL_INLINED (sym) = 1; | |
8418 | /* Do not add the symbol to any lists. It will be found via | |
8419 | BLOCK_FUNCTION from the blockvector. */ | |
8420 | break; | |
c906108c SS |
8421 | case DW_TAG_variable: |
8422 | /* Compilation with minimal debug info may result in variables | |
8423 | with missing type entries. Change the misleading `void' type | |
8424 | to something sensible. */ | |
8425 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 8426 | SYMBOL_TYPE (sym) |
46bf5051 | 8427 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 8428 | |
e142c38c | 8429 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8430 | if (attr) |
8431 | { | |
e7c27a73 | 8432 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 8433 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
8434 | if (attr2 && (DW_UNSND (attr2) != 0)) |
8435 | add_symbol_to_list (sym, &global_symbols); | |
8436 | else | |
e142c38c | 8437 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8438 | break; |
8439 | } | |
e142c38c | 8440 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8441 | if (attr) |
8442 | { | |
e7c27a73 | 8443 | var_decode_location (attr, sym, cu); |
e142c38c | 8444 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8445 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 8446 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 8447 | else |
e142c38c | 8448 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8449 | } |
8450 | else | |
8451 | { | |
8452 | /* We do not know the address of this symbol. | |
c5aa993b JM |
8453 | If it is an external symbol and we have type information |
8454 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
8455 | The address of the variable will then be determined from | |
8456 | the minimal symbol table whenever the variable is | |
8457 | referenced. */ | |
e142c38c | 8458 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 8459 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 8460 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 8461 | { |
0fe7935b DJ |
8462 | struct pending **list_to_add; |
8463 | ||
8464 | /* A variable with DW_AT_external is never static, but it | |
8465 | may be block-scoped. */ | |
8466 | list_to_add = (cu->list_in_scope == &file_symbols | |
8467 | ? &global_symbols : cu->list_in_scope); | |
8468 | ||
c906108c | 8469 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
0fe7935b | 8470 | add_symbol_to_list (sym, list_to_add); |
c906108c | 8471 | } |
442ddf59 JK |
8472 | else if (!die_is_declaration (die, cu)) |
8473 | { | |
8474 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
8475 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
8476 | add_symbol_to_list (sym, cu->list_in_scope); | |
8477 | } | |
c906108c SS |
8478 | } |
8479 | break; | |
8480 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
8481 | /* If we are inside a function, mark this as an argument. If |
8482 | not, we might be looking at an argument to an inlined function | |
8483 | when we do not have enough information to show inlined frames; | |
8484 | pretend it's a local variable in that case so that the user can | |
8485 | still see it. */ | |
8486 | if (context_stack_depth > 0 | |
8487 | && context_stack[context_stack_depth - 1].name != NULL) | |
8488 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 8489 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8490 | if (attr) |
8491 | { | |
e7c27a73 | 8492 | var_decode_location (attr, sym, cu); |
c906108c | 8493 | } |
e142c38c | 8494 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8495 | if (attr) |
8496 | { | |
e7c27a73 | 8497 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8498 | } |
e142c38c | 8499 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8500 | break; |
8501 | case DW_TAG_unspecified_parameters: | |
8502 | /* From varargs functions; gdb doesn't seem to have any | |
8503 | interest in this information, so just ignore it for now. | |
8504 | (FIXME?) */ | |
8505 | break; | |
8506 | case DW_TAG_class_type: | |
680b30c7 | 8507 | case DW_TAG_interface_type: |
c906108c SS |
8508 | case DW_TAG_structure_type: |
8509 | case DW_TAG_union_type: | |
72019c9c | 8510 | case DW_TAG_set_type: |
c906108c SS |
8511 | case DW_TAG_enumeration_type: |
8512 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 8513 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 8514 | |
63d06c5c DC |
8515 | /* Make sure that the symbol includes appropriate enclosing |
8516 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 8517 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
8518 | the type. */ |
8519 | ||
987504bb JJ |
8520 | if (cu->language == language_cplus |
8521 | || cu->language == language_java) | |
c906108c | 8522 | { |
63d06c5c DC |
8523 | struct type *type = SYMBOL_TYPE (sym); |
8524 | ||
8525 | if (TYPE_TAG_NAME (type) != NULL) | |
8526 | { | |
8527 | /* FIXME: carlton/2003-11-10: Should this use | |
8528 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
8529 | arises further down in this function.) */ |
8530 | /* The type's name is already allocated along with | |
8531 | this objfile, so we don't need to duplicate it | |
8532 | for the symbol. */ | |
8533 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 8534 | } |
c906108c | 8535 | } |
63d06c5c DC |
8536 | |
8537 | { | |
987504bb | 8538 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
8539 | really ever be static objects: otherwise, if you try |
8540 | to, say, break of a class's method and you're in a file | |
8541 | which doesn't mention that class, it won't work unless | |
8542 | the check for all static symbols in lookup_symbol_aux | |
8543 | saves you. See the OtherFileClass tests in | |
8544 | gdb.c++/namespace.exp. */ | |
8545 | ||
8546 | struct pending **list_to_add; | |
8547 | ||
e142c38c | 8548 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8549 | && (cu->language == language_cplus |
8550 | || cu->language == language_java) | |
e142c38c | 8551 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8552 | |
8553 | add_symbol_to_list (sym, list_to_add); | |
8554 | ||
8555 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 8556 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 8557 | defines a typedef for the class. */ |
987504bb | 8558 | if (cu->language == language_cplus |
8c6860bb JB |
8559 | || cu->language == language_java |
8560 | || cu->language == language_ada) | |
63d06c5c | 8561 | { |
d8151005 DJ |
8562 | /* The symbol's name is already allocated along with |
8563 | this objfile, so we don't need to duplicate it for | |
8564 | the type. */ | |
63d06c5c | 8565 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 8566 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
8567 | } |
8568 | } | |
c906108c SS |
8569 | break; |
8570 | case DW_TAG_typedef: | |
0114d602 | 8571 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
63d06c5c DC |
8572 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
8573 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 8574 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 8575 | break; |
c906108c | 8576 | case DW_TAG_base_type: |
a02abb62 | 8577 | case DW_TAG_subrange_type: |
c906108c | 8578 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 8579 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 8580 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
8581 | break; |
8582 | case DW_TAG_enumerator: | |
0114d602 | 8583 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
e142c38c | 8584 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
8585 | if (attr) |
8586 | { | |
e7c27a73 | 8587 | dwarf2_const_value (attr, sym, cu); |
c906108c | 8588 | } |
63d06c5c DC |
8589 | { |
8590 | /* NOTE: carlton/2003-11-10: See comment above in the | |
8591 | DW_TAG_class_type, etc. block. */ | |
8592 | ||
8593 | struct pending **list_to_add; | |
8594 | ||
e142c38c | 8595 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
8596 | && (cu->language == language_cplus |
8597 | || cu->language == language_java) | |
e142c38c | 8598 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
8599 | |
8600 | add_symbol_to_list (sym, list_to_add); | |
8601 | } | |
c906108c | 8602 | break; |
5c4e30ca DC |
8603 | case DW_TAG_namespace: |
8604 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
8605 | add_symbol_to_list (sym, &global_symbols); | |
8606 | break; | |
c906108c SS |
8607 | default: |
8608 | /* Not a tag we recognize. Hopefully we aren't processing | |
8609 | trash data, but since we must specifically ignore things | |
8610 | we don't recognize, there is nothing else we should do at | |
8611 | this point. */ | |
e2e0b3e5 | 8612 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 8613 | dwarf_tag_name (die->tag)); |
c906108c SS |
8614 | break; |
8615 | } | |
df8a16a1 DJ |
8616 | |
8617 | /* For the benefit of old versions of GCC, check for anonymous | |
8618 | namespaces based on the demangled name. */ | |
8619 | if (!processing_has_namespace_info | |
8620 | && cu->language == language_cplus | |
8621 | && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL) | |
8622 | cp_scan_for_anonymous_namespaces (sym); | |
c906108c SS |
8623 | } |
8624 | return (sym); | |
8625 | } | |
8626 | ||
8627 | /* Copy constant value from an attribute to a symbol. */ | |
8628 | ||
8629 | static void | |
107d2387 | 8630 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 8631 | struct dwarf2_cu *cu) |
c906108c | 8632 | { |
e7c27a73 DJ |
8633 | struct objfile *objfile = cu->objfile; |
8634 | struct comp_unit_head *cu_header = &cu->header; | |
e17a4113 UW |
8635 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
8636 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
c906108c SS |
8637 | struct dwarf_block *blk; |
8638 | ||
8639 | switch (attr->form) | |
8640 | { | |
8641 | case DW_FORM_addr: | |
107d2387 | 8642 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
3567439c | 8643 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8644 | cu_header->addr_size, |
8645 | TYPE_LENGTH (SYMBOL_TYPE | |
8646 | (sym))); | |
4e38b386 | 8647 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8648 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
8649 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
8650 | it's body - store_unsigned_integer. */ | |
8651 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
72f2769e | 8652 | byte_order, DW_ADDR (attr)); |
c906108c SS |
8653 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
8654 | break; | |
4ac36638 | 8655 | case DW_FORM_string: |
93b5768b PA |
8656 | case DW_FORM_strp: |
8657 | /* DW_STRING is already allocated on the obstack, point directly | |
8658 | to it. */ | |
8659 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
8660 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8661 | break; | |
c906108c SS |
8662 | case DW_FORM_block1: |
8663 | case DW_FORM_block2: | |
8664 | case DW_FORM_block4: | |
8665 | case DW_FORM_block: | |
8666 | blk = DW_BLOCK (attr); | |
8667 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 8668 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
8669 | blk->size, |
8670 | TYPE_LENGTH (SYMBOL_TYPE | |
8671 | (sym))); | |
4e38b386 | 8672 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 8673 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
8674 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
8675 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
8676 | break; | |
2df3850c JM |
8677 | |
8678 | /* The DW_AT_const_value attributes are supposed to carry the | |
8679 | symbol's value "represented as it would be on the target | |
8680 | architecture." By the time we get here, it's already been | |
8681 | converted to host endianness, so we just need to sign- or | |
8682 | zero-extend it as appropriate. */ | |
8683 | case DW_FORM_data1: | |
8684 | dwarf2_const_value_data (attr, sym, 8); | |
8685 | break; | |
c906108c | 8686 | case DW_FORM_data2: |
2df3850c JM |
8687 | dwarf2_const_value_data (attr, sym, 16); |
8688 | break; | |
c906108c | 8689 | case DW_FORM_data4: |
2df3850c JM |
8690 | dwarf2_const_value_data (attr, sym, 32); |
8691 | break; | |
c906108c | 8692 | case DW_FORM_data8: |
2df3850c JM |
8693 | dwarf2_const_value_data (attr, sym, 64); |
8694 | break; | |
8695 | ||
c906108c | 8696 | case DW_FORM_sdata: |
2df3850c JM |
8697 | SYMBOL_VALUE (sym) = DW_SND (attr); |
8698 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8699 | break; | |
8700 | ||
c906108c SS |
8701 | case DW_FORM_udata: |
8702 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
8703 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8704 | break; | |
2df3850c | 8705 | |
c906108c | 8706 | default: |
4d3c2250 | 8707 | complaint (&symfile_complaints, |
e2e0b3e5 | 8708 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 8709 | dwarf_form_name (attr->form)); |
c906108c SS |
8710 | SYMBOL_VALUE (sym) = 0; |
8711 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8712 | break; | |
8713 | } | |
8714 | } | |
8715 | ||
2df3850c JM |
8716 | |
8717 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
8718 | or zero-extend it as appropriate for the symbol's type. */ | |
8719 | static void | |
8720 | dwarf2_const_value_data (struct attribute *attr, | |
8721 | struct symbol *sym, | |
8722 | int bits) | |
8723 | { | |
8724 | LONGEST l = DW_UNSND (attr); | |
8725 | ||
8726 | if (bits < sizeof (l) * 8) | |
8727 | { | |
8728 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
8729 | l &= ((LONGEST) 1 << bits) - 1; | |
8730 | else | |
bf9198f1 | 8731 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
8732 | } |
8733 | ||
8734 | SYMBOL_VALUE (sym) = l; | |
8735 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8736 | } | |
8737 | ||
8738 | ||
c906108c SS |
8739 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
8740 | ||
8741 | static struct type * | |
e7c27a73 | 8742 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8743 | { |
8744 | struct type *type; | |
8745 | struct attribute *type_attr; | |
8746 | struct die_info *type_die; | |
c906108c | 8747 | |
e142c38c | 8748 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
8749 | if (!type_attr) |
8750 | { | |
8751 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 8752 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 8753 | } |
348e048f DE |
8754 | |
8755 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10b3939b | 8756 | |
e7c27a73 | 8757 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8758 | if (!type) |
8759 | { | |
d97bc12b | 8760 | dump_die_for_error (type_die); |
8a3fe4f8 | 8761 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 8762 | cu->objfile->name); |
c906108c SS |
8763 | } |
8764 | return type; | |
8765 | } | |
8766 | ||
b4ba55a1 JB |
8767 | /* True iff CU's producer generates GNAT Ada auxiliary information |
8768 | that allows to find parallel types through that information instead | |
8769 | of having to do expensive parallel lookups by type name. */ | |
8770 | ||
8771 | static int | |
8772 | need_gnat_info (struct dwarf2_cu *cu) | |
8773 | { | |
8774 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
8775 | of GNAT produces this auxiliary information, without any indication | |
8776 | that it is produced. Part of enhancing the FSF version of GNAT | |
8777 | to produce that information will be to put in place an indicator | |
8778 | that we can use in order to determine whether the descriptive type | |
8779 | info is available or not. One suggestion that has been made is | |
8780 | to use a new attribute, attached to the CU die. For now, assume | |
8781 | that the descriptive type info is not available. */ | |
8782 | return 0; | |
8783 | } | |
8784 | ||
8785 | ||
8786 | /* Return the auxiliary type of the die in question using its | |
8787 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
8788 | attribute is not present. */ | |
8789 | ||
8790 | static struct type * | |
8791 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
8792 | { | |
8793 | struct type *type; | |
8794 | struct attribute *type_attr; | |
8795 | struct die_info *type_die; | |
8796 | ||
8797 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
8798 | if (!type_attr) | |
8799 | return NULL; | |
8800 | ||
8801 | type_die = follow_die_ref (die, type_attr, &cu); | |
8802 | type = tag_type_to_type (type_die, cu); | |
8803 | if (!type) | |
8804 | { | |
8805 | dump_die_for_error (type_die); | |
8806 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), | |
8807 | cu->objfile->name); | |
8808 | } | |
8809 | return type; | |
8810 | } | |
8811 | ||
8812 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
8813 | descriptive type accordingly. */ | |
8814 | ||
8815 | static void | |
8816 | set_descriptive_type (struct type *type, struct die_info *die, | |
8817 | struct dwarf2_cu *cu) | |
8818 | { | |
8819 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
8820 | ||
8821 | if (descriptive_type) | |
8822 | { | |
8823 | ALLOCATE_GNAT_AUX_TYPE (type); | |
8824 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
8825 | } | |
8826 | } | |
8827 | ||
c906108c SS |
8828 | /* Return the containing type of the die in question using its |
8829 | DW_AT_containing_type attribute. */ | |
8830 | ||
8831 | static struct type * | |
e7c27a73 | 8832 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8833 | { |
8834 | struct type *type = NULL; | |
8835 | struct attribute *type_attr; | |
8836 | struct die_info *type_die = NULL; | |
c906108c | 8837 | |
e142c38c | 8838 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
8839 | if (type_attr) |
8840 | { | |
348e048f | 8841 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); |
e7c27a73 | 8842 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8843 | } |
8844 | if (!type) | |
8845 | { | |
8846 | if (type_die) | |
d97bc12b | 8847 | dump_die_for_error (type_die); |
8a3fe4f8 | 8848 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 8849 | cu->objfile->name); |
c906108c SS |
8850 | } |
8851 | return type; | |
8852 | } | |
8853 | ||
c906108c | 8854 | static struct type * |
e7c27a73 | 8855 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8856 | { |
f792889a DJ |
8857 | struct type *this_type; |
8858 | ||
8859 | this_type = read_type_die (die, cu); | |
8860 | if (!this_type) | |
c906108c | 8861 | { |
d97bc12b | 8862 | dump_die_for_error (die); |
f792889a DJ |
8863 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
8864 | cu->objfile->name); | |
c906108c | 8865 | } |
f792889a | 8866 | return this_type; |
c906108c SS |
8867 | } |
8868 | ||
f792889a | 8869 | static struct type * |
e7c27a73 | 8870 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8871 | { |
f792889a DJ |
8872 | struct type *this_type; |
8873 | ||
8874 | this_type = get_die_type (die, cu); | |
8875 | if (this_type) | |
8876 | return this_type; | |
8877 | ||
c906108c SS |
8878 | switch (die->tag) |
8879 | { | |
8880 | case DW_TAG_class_type: | |
680b30c7 | 8881 | case DW_TAG_interface_type: |
c906108c SS |
8882 | case DW_TAG_structure_type: |
8883 | case DW_TAG_union_type: | |
f792889a | 8884 | this_type = read_structure_type (die, cu); |
c906108c SS |
8885 | break; |
8886 | case DW_TAG_enumeration_type: | |
f792889a | 8887 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
8888 | break; |
8889 | case DW_TAG_subprogram: | |
8890 | case DW_TAG_subroutine_type: | |
edb3359d | 8891 | case DW_TAG_inlined_subroutine: |
f792889a | 8892 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
8893 | break; |
8894 | case DW_TAG_array_type: | |
f792889a | 8895 | this_type = read_array_type (die, cu); |
c906108c | 8896 | break; |
72019c9c | 8897 | case DW_TAG_set_type: |
f792889a | 8898 | this_type = read_set_type (die, cu); |
72019c9c | 8899 | break; |
c906108c | 8900 | case DW_TAG_pointer_type: |
f792889a | 8901 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
8902 | break; |
8903 | case DW_TAG_ptr_to_member_type: | |
f792889a | 8904 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
8905 | break; |
8906 | case DW_TAG_reference_type: | |
f792889a | 8907 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
8908 | break; |
8909 | case DW_TAG_const_type: | |
f792889a | 8910 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
8911 | break; |
8912 | case DW_TAG_volatile_type: | |
f792889a | 8913 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
8914 | break; |
8915 | case DW_TAG_string_type: | |
f792889a | 8916 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
8917 | break; |
8918 | case DW_TAG_typedef: | |
f792889a | 8919 | this_type = read_typedef (die, cu); |
c906108c | 8920 | break; |
a02abb62 | 8921 | case DW_TAG_subrange_type: |
f792889a | 8922 | this_type = read_subrange_type (die, cu); |
a02abb62 | 8923 | break; |
c906108c | 8924 | case DW_TAG_base_type: |
f792889a | 8925 | this_type = read_base_type (die, cu); |
c906108c | 8926 | break; |
81a17f79 | 8927 | case DW_TAG_unspecified_type: |
f792889a | 8928 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 8929 | break; |
0114d602 DJ |
8930 | case DW_TAG_namespace: |
8931 | this_type = read_namespace_type (die, cu); | |
8932 | break; | |
c906108c | 8933 | default: |
a1f5b845 | 8934 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 8935 | dwarf_tag_name (die->tag)); |
c906108c SS |
8936 | break; |
8937 | } | |
63d06c5c | 8938 | |
f792889a | 8939 | return this_type; |
63d06c5c DC |
8940 | } |
8941 | ||
fdde2d81 | 8942 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 8943 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 8944 | |
0114d602 DJ |
8945 | For example, if we're within the method foo() in the following |
8946 | code: | |
8947 | ||
8948 | namespace N { | |
8949 | class C { | |
8950 | void foo () { | |
8951 | } | |
8952 | }; | |
8953 | } | |
8954 | ||
8955 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
8956 | |
8957 | static char * | |
e142c38c | 8958 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 8959 | { |
0114d602 DJ |
8960 | struct die_info *parent, *spec_die; |
8961 | struct dwarf2_cu *spec_cu; | |
8962 | struct type *parent_type; | |
63d06c5c | 8963 | |
987504bb JJ |
8964 | if (cu->language != language_cplus |
8965 | && cu->language != language_java) | |
0114d602 DJ |
8966 | return ""; |
8967 | ||
8968 | /* We have to be careful in the presence of DW_AT_specification. | |
8969 | For example, with GCC 3.4, given the code | |
8970 | ||
8971 | namespace N { | |
8972 | void foo() { | |
8973 | // Definition of N::foo. | |
8974 | } | |
8975 | } | |
8976 | ||
8977 | then we'll have a tree of DIEs like this: | |
8978 | ||
8979 | 1: DW_TAG_compile_unit | |
8980 | 2: DW_TAG_namespace // N | |
8981 | 3: DW_TAG_subprogram // declaration of N::foo | |
8982 | 4: DW_TAG_subprogram // definition of N::foo | |
8983 | DW_AT_specification // refers to die #3 | |
8984 | ||
8985 | Thus, when processing die #4, we have to pretend that we're in | |
8986 | the context of its DW_AT_specification, namely the contex of die | |
8987 | #3. */ | |
8988 | spec_cu = cu; | |
8989 | spec_die = die_specification (die, &spec_cu); | |
8990 | if (spec_die == NULL) | |
8991 | parent = die->parent; | |
8992 | else | |
63d06c5c | 8993 | { |
0114d602 DJ |
8994 | parent = spec_die->parent; |
8995 | cu = spec_cu; | |
63d06c5c | 8996 | } |
0114d602 DJ |
8997 | |
8998 | if (parent == NULL) | |
8999 | return ""; | |
63d06c5c | 9000 | else |
0114d602 DJ |
9001 | switch (parent->tag) |
9002 | { | |
63d06c5c | 9003 | case DW_TAG_namespace: |
0114d602 DJ |
9004 | parent_type = read_type_die (parent, cu); |
9005 | /* We give a name to even anonymous namespaces. */ | |
9006 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 9007 | case DW_TAG_class_type: |
680b30c7 | 9008 | case DW_TAG_interface_type: |
63d06c5c | 9009 | case DW_TAG_structure_type: |
0114d602 DJ |
9010 | case DW_TAG_union_type: |
9011 | parent_type = read_type_die (parent, cu); | |
9012 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
9013 | return TYPE_TAG_NAME (parent_type); | |
9014 | else | |
9015 | /* An anonymous structure is only allowed non-static data | |
9016 | members; no typedefs, no member functions, et cetera. | |
9017 | So it does not need a prefix. */ | |
9018 | return ""; | |
63d06c5c | 9019 | default: |
8176b9b8 | 9020 | return determine_prefix (parent, cu); |
63d06c5c | 9021 | } |
63d06c5c DC |
9022 | } |
9023 | ||
987504bb JJ |
9024 | /* Return a newly-allocated string formed by concatenating PREFIX and |
9025 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
9026 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
9027 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
9028 | is used to determine the language and hence, the appropriate separator. */ | |
9029 | ||
9030 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
9031 | |
9032 | static char * | |
987504bb JJ |
9033 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
9034 | struct dwarf2_cu *cu) | |
63d06c5c | 9035 | { |
987504bb | 9036 | char *sep; |
63d06c5c | 9037 | |
987504bb JJ |
9038 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
9039 | sep = ""; | |
9040 | else if (cu->language == language_java) | |
9041 | sep = "."; | |
9042 | else | |
9043 | sep = "::"; | |
63d06c5c | 9044 | |
6dd47d34 DE |
9045 | if (prefix == NULL) |
9046 | prefix = ""; | |
9047 | if (suffix == NULL) | |
9048 | suffix = ""; | |
9049 | ||
987504bb JJ |
9050 | if (obs == NULL) |
9051 | { | |
9052 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
6dd47d34 DE |
9053 | strcpy (retval, prefix); |
9054 | strcat (retval, sep); | |
9055 | strcat (retval, suffix); | |
63d06c5c DC |
9056 | return retval; |
9057 | } | |
987504bb JJ |
9058 | else |
9059 | { | |
9060 | /* We have an obstack. */ | |
9061 | return obconcat (obs, prefix, sep, suffix); | |
9062 | } | |
63d06c5c DC |
9063 | } |
9064 | ||
c906108c SS |
9065 | /* Return sibling of die, NULL if no sibling. */ |
9066 | ||
f9aca02d | 9067 | static struct die_info * |
fba45db2 | 9068 | sibling_die (struct die_info *die) |
c906108c | 9069 | { |
639d11d3 | 9070 | return die->sibling; |
c906108c SS |
9071 | } |
9072 | ||
9073 | /* Get linkage name of a die, return NULL if not found. */ | |
9074 | ||
9075 | static char * | |
e142c38c | 9076 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
9077 | { |
9078 | struct attribute *attr; | |
9079 | ||
e142c38c | 9080 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
9081 | if (attr && DW_STRING (attr)) |
9082 | return DW_STRING (attr); | |
71c25dea TT |
9083 | return dwarf2_name (die, cu); |
9084 | } | |
9085 | ||
9086 | /* Get name of a die, return NULL if not found. */ | |
9087 | ||
9088 | static char * | |
9089 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
9090 | struct obstack *obstack) | |
9091 | { | |
9092 | if (name && cu->language == language_cplus) | |
9093 | { | |
9094 | char *canon_name = cp_canonicalize_string (name); | |
9095 | ||
9096 | if (canon_name != NULL) | |
9097 | { | |
9098 | if (strcmp (canon_name, name) != 0) | |
9099 | name = obsavestring (canon_name, strlen (canon_name), | |
9100 | obstack); | |
9101 | xfree (canon_name); | |
9102 | } | |
9103 | } | |
9104 | ||
9105 | return name; | |
c906108c SS |
9106 | } |
9107 | ||
9219021c DC |
9108 | /* Get name of a die, return NULL if not found. */ |
9109 | ||
9110 | static char * | |
e142c38c | 9111 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
9112 | { |
9113 | struct attribute *attr; | |
9114 | ||
e142c38c | 9115 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
9116 | if (!attr || !DW_STRING (attr)) |
9117 | return NULL; | |
9118 | ||
9119 | switch (die->tag) | |
9120 | { | |
9121 | case DW_TAG_compile_unit: | |
9122 | /* Compilation units have a DW_AT_name that is a filename, not | |
9123 | a source language identifier. */ | |
9124 | case DW_TAG_enumeration_type: | |
9125 | case DW_TAG_enumerator: | |
9126 | /* These tags always have simple identifiers already; no need | |
9127 | to canonicalize them. */ | |
9128 | return DW_STRING (attr); | |
9129 | default: | |
8285870a | 9130 | if (!DW_STRING_IS_CANONICAL (attr)) |
71c25dea TT |
9131 | { |
9132 | DW_STRING (attr) | |
9133 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
9134 | &cu->objfile->objfile_obstack); | |
8285870a | 9135 | DW_STRING_IS_CANONICAL (attr) = 1; |
71c25dea TT |
9136 | } |
9137 | return DW_STRING (attr); | |
9138 | } | |
9219021c DC |
9139 | } |
9140 | ||
9141 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
9142 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
9143 | containing the return value on output. */ | |
9219021c DC |
9144 | |
9145 | static struct die_info * | |
f2f0e013 | 9146 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
9147 | { |
9148 | struct attribute *attr; | |
9219021c | 9149 | |
f2f0e013 | 9150 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
9151 | if (attr == NULL) |
9152 | return NULL; | |
9153 | ||
f2f0e013 | 9154 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
9155 | } |
9156 | ||
c906108c SS |
9157 | /* Convert a DIE tag into its string name. */ |
9158 | ||
9159 | static char * | |
aa1ee363 | 9160 | dwarf_tag_name (unsigned tag) |
c906108c SS |
9161 | { |
9162 | switch (tag) | |
9163 | { | |
9164 | case DW_TAG_padding: | |
9165 | return "DW_TAG_padding"; | |
9166 | case DW_TAG_array_type: | |
9167 | return "DW_TAG_array_type"; | |
9168 | case DW_TAG_class_type: | |
9169 | return "DW_TAG_class_type"; | |
9170 | case DW_TAG_entry_point: | |
9171 | return "DW_TAG_entry_point"; | |
9172 | case DW_TAG_enumeration_type: | |
9173 | return "DW_TAG_enumeration_type"; | |
9174 | case DW_TAG_formal_parameter: | |
9175 | return "DW_TAG_formal_parameter"; | |
9176 | case DW_TAG_imported_declaration: | |
9177 | return "DW_TAG_imported_declaration"; | |
9178 | case DW_TAG_label: | |
9179 | return "DW_TAG_label"; | |
9180 | case DW_TAG_lexical_block: | |
9181 | return "DW_TAG_lexical_block"; | |
9182 | case DW_TAG_member: | |
9183 | return "DW_TAG_member"; | |
9184 | case DW_TAG_pointer_type: | |
9185 | return "DW_TAG_pointer_type"; | |
9186 | case DW_TAG_reference_type: | |
9187 | return "DW_TAG_reference_type"; | |
9188 | case DW_TAG_compile_unit: | |
9189 | return "DW_TAG_compile_unit"; | |
9190 | case DW_TAG_string_type: | |
9191 | return "DW_TAG_string_type"; | |
9192 | case DW_TAG_structure_type: | |
9193 | return "DW_TAG_structure_type"; | |
9194 | case DW_TAG_subroutine_type: | |
9195 | return "DW_TAG_subroutine_type"; | |
9196 | case DW_TAG_typedef: | |
9197 | return "DW_TAG_typedef"; | |
9198 | case DW_TAG_union_type: | |
9199 | return "DW_TAG_union_type"; | |
9200 | case DW_TAG_unspecified_parameters: | |
9201 | return "DW_TAG_unspecified_parameters"; | |
9202 | case DW_TAG_variant: | |
9203 | return "DW_TAG_variant"; | |
9204 | case DW_TAG_common_block: | |
9205 | return "DW_TAG_common_block"; | |
9206 | case DW_TAG_common_inclusion: | |
9207 | return "DW_TAG_common_inclusion"; | |
9208 | case DW_TAG_inheritance: | |
9209 | return "DW_TAG_inheritance"; | |
9210 | case DW_TAG_inlined_subroutine: | |
9211 | return "DW_TAG_inlined_subroutine"; | |
9212 | case DW_TAG_module: | |
9213 | return "DW_TAG_module"; | |
9214 | case DW_TAG_ptr_to_member_type: | |
9215 | return "DW_TAG_ptr_to_member_type"; | |
9216 | case DW_TAG_set_type: | |
9217 | return "DW_TAG_set_type"; | |
9218 | case DW_TAG_subrange_type: | |
9219 | return "DW_TAG_subrange_type"; | |
9220 | case DW_TAG_with_stmt: | |
9221 | return "DW_TAG_with_stmt"; | |
9222 | case DW_TAG_access_declaration: | |
9223 | return "DW_TAG_access_declaration"; | |
9224 | case DW_TAG_base_type: | |
9225 | return "DW_TAG_base_type"; | |
9226 | case DW_TAG_catch_block: | |
9227 | return "DW_TAG_catch_block"; | |
9228 | case DW_TAG_const_type: | |
9229 | return "DW_TAG_const_type"; | |
9230 | case DW_TAG_constant: | |
9231 | return "DW_TAG_constant"; | |
9232 | case DW_TAG_enumerator: | |
9233 | return "DW_TAG_enumerator"; | |
9234 | case DW_TAG_file_type: | |
9235 | return "DW_TAG_file_type"; | |
9236 | case DW_TAG_friend: | |
9237 | return "DW_TAG_friend"; | |
9238 | case DW_TAG_namelist: | |
9239 | return "DW_TAG_namelist"; | |
9240 | case DW_TAG_namelist_item: | |
9241 | return "DW_TAG_namelist_item"; | |
9242 | case DW_TAG_packed_type: | |
9243 | return "DW_TAG_packed_type"; | |
9244 | case DW_TAG_subprogram: | |
9245 | return "DW_TAG_subprogram"; | |
9246 | case DW_TAG_template_type_param: | |
9247 | return "DW_TAG_template_type_param"; | |
9248 | case DW_TAG_template_value_param: | |
9249 | return "DW_TAG_template_value_param"; | |
9250 | case DW_TAG_thrown_type: | |
9251 | return "DW_TAG_thrown_type"; | |
9252 | case DW_TAG_try_block: | |
9253 | return "DW_TAG_try_block"; | |
9254 | case DW_TAG_variant_part: | |
9255 | return "DW_TAG_variant_part"; | |
9256 | case DW_TAG_variable: | |
9257 | return "DW_TAG_variable"; | |
9258 | case DW_TAG_volatile_type: | |
9259 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
9260 | case DW_TAG_dwarf_procedure: |
9261 | return "DW_TAG_dwarf_procedure"; | |
9262 | case DW_TAG_restrict_type: | |
9263 | return "DW_TAG_restrict_type"; | |
9264 | case DW_TAG_interface_type: | |
9265 | return "DW_TAG_interface_type"; | |
9266 | case DW_TAG_namespace: | |
9267 | return "DW_TAG_namespace"; | |
9268 | case DW_TAG_imported_module: | |
9269 | return "DW_TAG_imported_module"; | |
9270 | case DW_TAG_unspecified_type: | |
9271 | return "DW_TAG_unspecified_type"; | |
9272 | case DW_TAG_partial_unit: | |
9273 | return "DW_TAG_partial_unit"; | |
9274 | case DW_TAG_imported_unit: | |
9275 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
9276 | case DW_TAG_condition: |
9277 | return "DW_TAG_condition"; | |
9278 | case DW_TAG_shared_type: | |
9279 | return "DW_TAG_shared_type"; | |
348e048f DE |
9280 | case DW_TAG_type_unit: |
9281 | return "DW_TAG_type_unit"; | |
c906108c SS |
9282 | case DW_TAG_MIPS_loop: |
9283 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
9284 | case DW_TAG_HP_array_descriptor: |
9285 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
9286 | case DW_TAG_format_label: |
9287 | return "DW_TAG_format_label"; | |
9288 | case DW_TAG_function_template: | |
9289 | return "DW_TAG_function_template"; | |
9290 | case DW_TAG_class_template: | |
9291 | return "DW_TAG_class_template"; | |
b7619582 GF |
9292 | case DW_TAG_GNU_BINCL: |
9293 | return "DW_TAG_GNU_BINCL"; | |
9294 | case DW_TAG_GNU_EINCL: | |
9295 | return "DW_TAG_GNU_EINCL"; | |
9296 | case DW_TAG_upc_shared_type: | |
9297 | return "DW_TAG_upc_shared_type"; | |
9298 | case DW_TAG_upc_strict_type: | |
9299 | return "DW_TAG_upc_strict_type"; | |
9300 | case DW_TAG_upc_relaxed_type: | |
9301 | return "DW_TAG_upc_relaxed_type"; | |
9302 | case DW_TAG_PGI_kanji_type: | |
9303 | return "DW_TAG_PGI_kanji_type"; | |
9304 | case DW_TAG_PGI_interface_block: | |
9305 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
9306 | default: |
9307 | return "DW_TAG_<unknown>"; | |
9308 | } | |
9309 | } | |
9310 | ||
9311 | /* Convert a DWARF attribute code into its string name. */ | |
9312 | ||
9313 | static char * | |
aa1ee363 | 9314 | dwarf_attr_name (unsigned attr) |
c906108c SS |
9315 | { |
9316 | switch (attr) | |
9317 | { | |
9318 | case DW_AT_sibling: | |
9319 | return "DW_AT_sibling"; | |
9320 | case DW_AT_location: | |
9321 | return "DW_AT_location"; | |
9322 | case DW_AT_name: | |
9323 | return "DW_AT_name"; | |
9324 | case DW_AT_ordering: | |
9325 | return "DW_AT_ordering"; | |
9326 | case DW_AT_subscr_data: | |
9327 | return "DW_AT_subscr_data"; | |
9328 | case DW_AT_byte_size: | |
9329 | return "DW_AT_byte_size"; | |
9330 | case DW_AT_bit_offset: | |
9331 | return "DW_AT_bit_offset"; | |
9332 | case DW_AT_bit_size: | |
9333 | return "DW_AT_bit_size"; | |
9334 | case DW_AT_element_list: | |
9335 | return "DW_AT_element_list"; | |
9336 | case DW_AT_stmt_list: | |
9337 | return "DW_AT_stmt_list"; | |
9338 | case DW_AT_low_pc: | |
9339 | return "DW_AT_low_pc"; | |
9340 | case DW_AT_high_pc: | |
9341 | return "DW_AT_high_pc"; | |
9342 | case DW_AT_language: | |
9343 | return "DW_AT_language"; | |
9344 | case DW_AT_member: | |
9345 | return "DW_AT_member"; | |
9346 | case DW_AT_discr: | |
9347 | return "DW_AT_discr"; | |
9348 | case DW_AT_discr_value: | |
9349 | return "DW_AT_discr_value"; | |
9350 | case DW_AT_visibility: | |
9351 | return "DW_AT_visibility"; | |
9352 | case DW_AT_import: | |
9353 | return "DW_AT_import"; | |
9354 | case DW_AT_string_length: | |
9355 | return "DW_AT_string_length"; | |
9356 | case DW_AT_common_reference: | |
9357 | return "DW_AT_common_reference"; | |
9358 | case DW_AT_comp_dir: | |
9359 | return "DW_AT_comp_dir"; | |
9360 | case DW_AT_const_value: | |
9361 | return "DW_AT_const_value"; | |
9362 | case DW_AT_containing_type: | |
9363 | return "DW_AT_containing_type"; | |
9364 | case DW_AT_default_value: | |
9365 | return "DW_AT_default_value"; | |
9366 | case DW_AT_inline: | |
9367 | return "DW_AT_inline"; | |
9368 | case DW_AT_is_optional: | |
9369 | return "DW_AT_is_optional"; | |
9370 | case DW_AT_lower_bound: | |
9371 | return "DW_AT_lower_bound"; | |
9372 | case DW_AT_producer: | |
9373 | return "DW_AT_producer"; | |
9374 | case DW_AT_prototyped: | |
9375 | return "DW_AT_prototyped"; | |
9376 | case DW_AT_return_addr: | |
9377 | return "DW_AT_return_addr"; | |
9378 | case DW_AT_start_scope: | |
9379 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
9380 | case DW_AT_bit_stride: |
9381 | return "DW_AT_bit_stride"; | |
c906108c SS |
9382 | case DW_AT_upper_bound: |
9383 | return "DW_AT_upper_bound"; | |
9384 | case DW_AT_abstract_origin: | |
9385 | return "DW_AT_abstract_origin"; | |
9386 | case DW_AT_accessibility: | |
9387 | return "DW_AT_accessibility"; | |
9388 | case DW_AT_address_class: | |
9389 | return "DW_AT_address_class"; | |
9390 | case DW_AT_artificial: | |
9391 | return "DW_AT_artificial"; | |
9392 | case DW_AT_base_types: | |
9393 | return "DW_AT_base_types"; | |
9394 | case DW_AT_calling_convention: | |
9395 | return "DW_AT_calling_convention"; | |
9396 | case DW_AT_count: | |
9397 | return "DW_AT_count"; | |
9398 | case DW_AT_data_member_location: | |
9399 | return "DW_AT_data_member_location"; | |
9400 | case DW_AT_decl_column: | |
9401 | return "DW_AT_decl_column"; | |
9402 | case DW_AT_decl_file: | |
9403 | return "DW_AT_decl_file"; | |
9404 | case DW_AT_decl_line: | |
9405 | return "DW_AT_decl_line"; | |
9406 | case DW_AT_declaration: | |
9407 | return "DW_AT_declaration"; | |
9408 | case DW_AT_discr_list: | |
9409 | return "DW_AT_discr_list"; | |
9410 | case DW_AT_encoding: | |
9411 | return "DW_AT_encoding"; | |
9412 | case DW_AT_external: | |
9413 | return "DW_AT_external"; | |
9414 | case DW_AT_frame_base: | |
9415 | return "DW_AT_frame_base"; | |
9416 | case DW_AT_friend: | |
9417 | return "DW_AT_friend"; | |
9418 | case DW_AT_identifier_case: | |
9419 | return "DW_AT_identifier_case"; | |
9420 | case DW_AT_macro_info: | |
9421 | return "DW_AT_macro_info"; | |
9422 | case DW_AT_namelist_items: | |
9423 | return "DW_AT_namelist_items"; | |
9424 | case DW_AT_priority: | |
9425 | return "DW_AT_priority"; | |
9426 | case DW_AT_segment: | |
9427 | return "DW_AT_segment"; | |
9428 | case DW_AT_specification: | |
9429 | return "DW_AT_specification"; | |
9430 | case DW_AT_static_link: | |
9431 | return "DW_AT_static_link"; | |
9432 | case DW_AT_type: | |
9433 | return "DW_AT_type"; | |
9434 | case DW_AT_use_location: | |
9435 | return "DW_AT_use_location"; | |
9436 | case DW_AT_variable_parameter: | |
9437 | return "DW_AT_variable_parameter"; | |
9438 | case DW_AT_virtuality: | |
9439 | return "DW_AT_virtuality"; | |
9440 | case DW_AT_vtable_elem_location: | |
9441 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 9442 | /* DWARF 3 values. */ |
d9fa45fe DC |
9443 | case DW_AT_allocated: |
9444 | return "DW_AT_allocated"; | |
9445 | case DW_AT_associated: | |
9446 | return "DW_AT_associated"; | |
9447 | case DW_AT_data_location: | |
9448 | return "DW_AT_data_location"; | |
09fa0d7c JK |
9449 | case DW_AT_byte_stride: |
9450 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
9451 | case DW_AT_entry_pc: |
9452 | return "DW_AT_entry_pc"; | |
9453 | case DW_AT_use_UTF8: | |
9454 | return "DW_AT_use_UTF8"; | |
9455 | case DW_AT_extension: | |
9456 | return "DW_AT_extension"; | |
9457 | case DW_AT_ranges: | |
9458 | return "DW_AT_ranges"; | |
9459 | case DW_AT_trampoline: | |
9460 | return "DW_AT_trampoline"; | |
9461 | case DW_AT_call_column: | |
9462 | return "DW_AT_call_column"; | |
9463 | case DW_AT_call_file: | |
9464 | return "DW_AT_call_file"; | |
9465 | case DW_AT_call_line: | |
9466 | return "DW_AT_call_line"; | |
b7619582 GF |
9467 | case DW_AT_description: |
9468 | return "DW_AT_description"; | |
9469 | case DW_AT_binary_scale: | |
9470 | return "DW_AT_binary_scale"; | |
9471 | case DW_AT_decimal_scale: | |
9472 | return "DW_AT_decimal_scale"; | |
9473 | case DW_AT_small: | |
9474 | return "DW_AT_small"; | |
9475 | case DW_AT_decimal_sign: | |
9476 | return "DW_AT_decimal_sign"; | |
9477 | case DW_AT_digit_count: | |
9478 | return "DW_AT_digit_count"; | |
9479 | case DW_AT_picture_string: | |
9480 | return "DW_AT_picture_string"; | |
9481 | case DW_AT_mutable: | |
9482 | return "DW_AT_mutable"; | |
9483 | case DW_AT_threads_scaled: | |
9484 | return "DW_AT_threads_scaled"; | |
9485 | case DW_AT_explicit: | |
9486 | return "DW_AT_explicit"; | |
9487 | case DW_AT_object_pointer: | |
9488 | return "DW_AT_object_pointer"; | |
9489 | case DW_AT_endianity: | |
9490 | return "DW_AT_endianity"; | |
9491 | case DW_AT_elemental: | |
9492 | return "DW_AT_elemental"; | |
9493 | case DW_AT_pure: | |
9494 | return "DW_AT_pure"; | |
9495 | case DW_AT_recursive: | |
9496 | return "DW_AT_recursive"; | |
348e048f DE |
9497 | /* DWARF 4 values. */ |
9498 | case DW_AT_signature: | |
9499 | return "DW_AT_signature"; | |
b7619582 | 9500 | /* SGI/MIPS extensions. */ |
c764a876 | 9501 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
9502 | case DW_AT_MIPS_fde: |
9503 | return "DW_AT_MIPS_fde"; | |
c764a876 | 9504 | #endif |
c906108c SS |
9505 | case DW_AT_MIPS_loop_begin: |
9506 | return "DW_AT_MIPS_loop_begin"; | |
9507 | case DW_AT_MIPS_tail_loop_begin: | |
9508 | return "DW_AT_MIPS_tail_loop_begin"; | |
9509 | case DW_AT_MIPS_epilog_begin: | |
9510 | return "DW_AT_MIPS_epilog_begin"; | |
9511 | case DW_AT_MIPS_loop_unroll_factor: | |
9512 | return "DW_AT_MIPS_loop_unroll_factor"; | |
9513 | case DW_AT_MIPS_software_pipeline_depth: | |
9514 | return "DW_AT_MIPS_software_pipeline_depth"; | |
9515 | case DW_AT_MIPS_linkage_name: | |
9516 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
9517 | case DW_AT_MIPS_stride: |
9518 | return "DW_AT_MIPS_stride"; | |
9519 | case DW_AT_MIPS_abstract_name: | |
9520 | return "DW_AT_MIPS_abstract_name"; | |
9521 | case DW_AT_MIPS_clone_origin: | |
9522 | return "DW_AT_MIPS_clone_origin"; | |
9523 | case DW_AT_MIPS_has_inlines: | |
9524 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 9525 | /* HP extensions. */ |
c764a876 | 9526 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
9527 | case DW_AT_HP_block_index: |
9528 | return "DW_AT_HP_block_index"; | |
c764a876 | 9529 | #endif |
b7619582 GF |
9530 | case DW_AT_HP_unmodifiable: |
9531 | return "DW_AT_HP_unmodifiable"; | |
9532 | case DW_AT_HP_actuals_stmt_list: | |
9533 | return "DW_AT_HP_actuals_stmt_list"; | |
9534 | case DW_AT_HP_proc_per_section: | |
9535 | return "DW_AT_HP_proc_per_section"; | |
9536 | case DW_AT_HP_raw_data_ptr: | |
9537 | return "DW_AT_HP_raw_data_ptr"; | |
9538 | case DW_AT_HP_pass_by_reference: | |
9539 | return "DW_AT_HP_pass_by_reference"; | |
9540 | case DW_AT_HP_opt_level: | |
9541 | return "DW_AT_HP_opt_level"; | |
9542 | case DW_AT_HP_prof_version_id: | |
9543 | return "DW_AT_HP_prof_version_id"; | |
9544 | case DW_AT_HP_opt_flags: | |
9545 | return "DW_AT_HP_opt_flags"; | |
9546 | case DW_AT_HP_cold_region_low_pc: | |
9547 | return "DW_AT_HP_cold_region_low_pc"; | |
9548 | case DW_AT_HP_cold_region_high_pc: | |
9549 | return "DW_AT_HP_cold_region_high_pc"; | |
9550 | case DW_AT_HP_all_variables_modifiable: | |
9551 | return "DW_AT_HP_all_variables_modifiable"; | |
9552 | case DW_AT_HP_linkage_name: | |
9553 | return "DW_AT_HP_linkage_name"; | |
9554 | case DW_AT_HP_prof_flags: | |
9555 | return "DW_AT_HP_prof_flags"; | |
9556 | /* GNU extensions. */ | |
c906108c SS |
9557 | case DW_AT_sf_names: |
9558 | return "DW_AT_sf_names"; | |
9559 | case DW_AT_src_info: | |
9560 | return "DW_AT_src_info"; | |
9561 | case DW_AT_mac_info: | |
9562 | return "DW_AT_mac_info"; | |
9563 | case DW_AT_src_coords: | |
9564 | return "DW_AT_src_coords"; | |
9565 | case DW_AT_body_begin: | |
9566 | return "DW_AT_body_begin"; | |
9567 | case DW_AT_body_end: | |
9568 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
9569 | case DW_AT_GNU_vector: |
9570 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
9571 | /* VMS extensions. */ |
9572 | case DW_AT_VMS_rtnbeg_pd_address: | |
9573 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
9574 | /* UPC extension. */ | |
9575 | case DW_AT_upc_threads_scaled: | |
9576 | return "DW_AT_upc_threads_scaled"; | |
9577 | /* PGI (STMicroelectronics) extensions. */ | |
9578 | case DW_AT_PGI_lbase: | |
9579 | return "DW_AT_PGI_lbase"; | |
9580 | case DW_AT_PGI_soffset: | |
9581 | return "DW_AT_PGI_soffset"; | |
9582 | case DW_AT_PGI_lstride: | |
9583 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
9584 | default: |
9585 | return "DW_AT_<unknown>"; | |
9586 | } | |
9587 | } | |
9588 | ||
9589 | /* Convert a DWARF value form code into its string name. */ | |
9590 | ||
9591 | static char * | |
aa1ee363 | 9592 | dwarf_form_name (unsigned form) |
c906108c SS |
9593 | { |
9594 | switch (form) | |
9595 | { | |
9596 | case DW_FORM_addr: | |
9597 | return "DW_FORM_addr"; | |
9598 | case DW_FORM_block2: | |
9599 | return "DW_FORM_block2"; | |
9600 | case DW_FORM_block4: | |
9601 | return "DW_FORM_block4"; | |
9602 | case DW_FORM_data2: | |
9603 | return "DW_FORM_data2"; | |
9604 | case DW_FORM_data4: | |
9605 | return "DW_FORM_data4"; | |
9606 | case DW_FORM_data8: | |
9607 | return "DW_FORM_data8"; | |
9608 | case DW_FORM_string: | |
9609 | return "DW_FORM_string"; | |
9610 | case DW_FORM_block: | |
9611 | return "DW_FORM_block"; | |
9612 | case DW_FORM_block1: | |
9613 | return "DW_FORM_block1"; | |
9614 | case DW_FORM_data1: | |
9615 | return "DW_FORM_data1"; | |
9616 | case DW_FORM_flag: | |
9617 | return "DW_FORM_flag"; | |
9618 | case DW_FORM_sdata: | |
9619 | return "DW_FORM_sdata"; | |
9620 | case DW_FORM_strp: | |
9621 | return "DW_FORM_strp"; | |
9622 | case DW_FORM_udata: | |
9623 | return "DW_FORM_udata"; | |
9624 | case DW_FORM_ref_addr: | |
9625 | return "DW_FORM_ref_addr"; | |
9626 | case DW_FORM_ref1: | |
9627 | return "DW_FORM_ref1"; | |
9628 | case DW_FORM_ref2: | |
9629 | return "DW_FORM_ref2"; | |
9630 | case DW_FORM_ref4: | |
9631 | return "DW_FORM_ref4"; | |
9632 | case DW_FORM_ref8: | |
9633 | return "DW_FORM_ref8"; | |
9634 | case DW_FORM_ref_udata: | |
9635 | return "DW_FORM_ref_udata"; | |
9636 | case DW_FORM_indirect: | |
9637 | return "DW_FORM_indirect"; | |
348e048f DE |
9638 | case DW_FORM_sec_offset: |
9639 | return "DW_FORM_sec_offset"; | |
9640 | case DW_FORM_exprloc: | |
9641 | return "DW_FORM_exprloc"; | |
9642 | case DW_FORM_flag_present: | |
9643 | return "DW_FORM_flag_present"; | |
9644 | case DW_FORM_sig8: | |
9645 | return "DW_FORM_sig8"; | |
c906108c SS |
9646 | default: |
9647 | return "DW_FORM_<unknown>"; | |
9648 | } | |
9649 | } | |
9650 | ||
9651 | /* Convert a DWARF stack opcode into its string name. */ | |
9652 | ||
9653 | static char * | |
aa1ee363 | 9654 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
9655 | { |
9656 | switch (op) | |
9657 | { | |
9658 | case DW_OP_addr: | |
9659 | return "DW_OP_addr"; | |
9660 | case DW_OP_deref: | |
9661 | return "DW_OP_deref"; | |
9662 | case DW_OP_const1u: | |
9663 | return "DW_OP_const1u"; | |
9664 | case DW_OP_const1s: | |
9665 | return "DW_OP_const1s"; | |
9666 | case DW_OP_const2u: | |
9667 | return "DW_OP_const2u"; | |
9668 | case DW_OP_const2s: | |
9669 | return "DW_OP_const2s"; | |
9670 | case DW_OP_const4u: | |
9671 | return "DW_OP_const4u"; | |
9672 | case DW_OP_const4s: | |
9673 | return "DW_OP_const4s"; | |
9674 | case DW_OP_const8u: | |
9675 | return "DW_OP_const8u"; | |
9676 | case DW_OP_const8s: | |
9677 | return "DW_OP_const8s"; | |
9678 | case DW_OP_constu: | |
9679 | return "DW_OP_constu"; | |
9680 | case DW_OP_consts: | |
9681 | return "DW_OP_consts"; | |
9682 | case DW_OP_dup: | |
9683 | return "DW_OP_dup"; | |
9684 | case DW_OP_drop: | |
9685 | return "DW_OP_drop"; | |
9686 | case DW_OP_over: | |
9687 | return "DW_OP_over"; | |
9688 | case DW_OP_pick: | |
9689 | return "DW_OP_pick"; | |
9690 | case DW_OP_swap: | |
9691 | return "DW_OP_swap"; | |
9692 | case DW_OP_rot: | |
9693 | return "DW_OP_rot"; | |
9694 | case DW_OP_xderef: | |
9695 | return "DW_OP_xderef"; | |
9696 | case DW_OP_abs: | |
9697 | return "DW_OP_abs"; | |
9698 | case DW_OP_and: | |
9699 | return "DW_OP_and"; | |
9700 | case DW_OP_div: | |
9701 | return "DW_OP_div"; | |
9702 | case DW_OP_minus: | |
9703 | return "DW_OP_minus"; | |
9704 | case DW_OP_mod: | |
9705 | return "DW_OP_mod"; | |
9706 | case DW_OP_mul: | |
9707 | return "DW_OP_mul"; | |
9708 | case DW_OP_neg: | |
9709 | return "DW_OP_neg"; | |
9710 | case DW_OP_not: | |
9711 | return "DW_OP_not"; | |
9712 | case DW_OP_or: | |
9713 | return "DW_OP_or"; | |
9714 | case DW_OP_plus: | |
9715 | return "DW_OP_plus"; | |
9716 | case DW_OP_plus_uconst: | |
9717 | return "DW_OP_plus_uconst"; | |
9718 | case DW_OP_shl: | |
9719 | return "DW_OP_shl"; | |
9720 | case DW_OP_shr: | |
9721 | return "DW_OP_shr"; | |
9722 | case DW_OP_shra: | |
9723 | return "DW_OP_shra"; | |
9724 | case DW_OP_xor: | |
9725 | return "DW_OP_xor"; | |
9726 | case DW_OP_bra: | |
9727 | return "DW_OP_bra"; | |
9728 | case DW_OP_eq: | |
9729 | return "DW_OP_eq"; | |
9730 | case DW_OP_ge: | |
9731 | return "DW_OP_ge"; | |
9732 | case DW_OP_gt: | |
9733 | return "DW_OP_gt"; | |
9734 | case DW_OP_le: | |
9735 | return "DW_OP_le"; | |
9736 | case DW_OP_lt: | |
9737 | return "DW_OP_lt"; | |
9738 | case DW_OP_ne: | |
9739 | return "DW_OP_ne"; | |
9740 | case DW_OP_skip: | |
9741 | return "DW_OP_skip"; | |
9742 | case DW_OP_lit0: | |
9743 | return "DW_OP_lit0"; | |
9744 | case DW_OP_lit1: | |
9745 | return "DW_OP_lit1"; | |
9746 | case DW_OP_lit2: | |
9747 | return "DW_OP_lit2"; | |
9748 | case DW_OP_lit3: | |
9749 | return "DW_OP_lit3"; | |
9750 | case DW_OP_lit4: | |
9751 | return "DW_OP_lit4"; | |
9752 | case DW_OP_lit5: | |
9753 | return "DW_OP_lit5"; | |
9754 | case DW_OP_lit6: | |
9755 | return "DW_OP_lit6"; | |
9756 | case DW_OP_lit7: | |
9757 | return "DW_OP_lit7"; | |
9758 | case DW_OP_lit8: | |
9759 | return "DW_OP_lit8"; | |
9760 | case DW_OP_lit9: | |
9761 | return "DW_OP_lit9"; | |
9762 | case DW_OP_lit10: | |
9763 | return "DW_OP_lit10"; | |
9764 | case DW_OP_lit11: | |
9765 | return "DW_OP_lit11"; | |
9766 | case DW_OP_lit12: | |
9767 | return "DW_OP_lit12"; | |
9768 | case DW_OP_lit13: | |
9769 | return "DW_OP_lit13"; | |
9770 | case DW_OP_lit14: | |
9771 | return "DW_OP_lit14"; | |
9772 | case DW_OP_lit15: | |
9773 | return "DW_OP_lit15"; | |
9774 | case DW_OP_lit16: | |
9775 | return "DW_OP_lit16"; | |
9776 | case DW_OP_lit17: | |
9777 | return "DW_OP_lit17"; | |
9778 | case DW_OP_lit18: | |
9779 | return "DW_OP_lit18"; | |
9780 | case DW_OP_lit19: | |
9781 | return "DW_OP_lit19"; | |
9782 | case DW_OP_lit20: | |
9783 | return "DW_OP_lit20"; | |
9784 | case DW_OP_lit21: | |
9785 | return "DW_OP_lit21"; | |
9786 | case DW_OP_lit22: | |
9787 | return "DW_OP_lit22"; | |
9788 | case DW_OP_lit23: | |
9789 | return "DW_OP_lit23"; | |
9790 | case DW_OP_lit24: | |
9791 | return "DW_OP_lit24"; | |
9792 | case DW_OP_lit25: | |
9793 | return "DW_OP_lit25"; | |
9794 | case DW_OP_lit26: | |
9795 | return "DW_OP_lit26"; | |
9796 | case DW_OP_lit27: | |
9797 | return "DW_OP_lit27"; | |
9798 | case DW_OP_lit28: | |
9799 | return "DW_OP_lit28"; | |
9800 | case DW_OP_lit29: | |
9801 | return "DW_OP_lit29"; | |
9802 | case DW_OP_lit30: | |
9803 | return "DW_OP_lit30"; | |
9804 | case DW_OP_lit31: | |
9805 | return "DW_OP_lit31"; | |
9806 | case DW_OP_reg0: | |
9807 | return "DW_OP_reg0"; | |
9808 | case DW_OP_reg1: | |
9809 | return "DW_OP_reg1"; | |
9810 | case DW_OP_reg2: | |
9811 | return "DW_OP_reg2"; | |
9812 | case DW_OP_reg3: | |
9813 | return "DW_OP_reg3"; | |
9814 | case DW_OP_reg4: | |
9815 | return "DW_OP_reg4"; | |
9816 | case DW_OP_reg5: | |
9817 | return "DW_OP_reg5"; | |
9818 | case DW_OP_reg6: | |
9819 | return "DW_OP_reg6"; | |
9820 | case DW_OP_reg7: | |
9821 | return "DW_OP_reg7"; | |
9822 | case DW_OP_reg8: | |
9823 | return "DW_OP_reg8"; | |
9824 | case DW_OP_reg9: | |
9825 | return "DW_OP_reg9"; | |
9826 | case DW_OP_reg10: | |
9827 | return "DW_OP_reg10"; | |
9828 | case DW_OP_reg11: | |
9829 | return "DW_OP_reg11"; | |
9830 | case DW_OP_reg12: | |
9831 | return "DW_OP_reg12"; | |
9832 | case DW_OP_reg13: | |
9833 | return "DW_OP_reg13"; | |
9834 | case DW_OP_reg14: | |
9835 | return "DW_OP_reg14"; | |
9836 | case DW_OP_reg15: | |
9837 | return "DW_OP_reg15"; | |
9838 | case DW_OP_reg16: | |
9839 | return "DW_OP_reg16"; | |
9840 | case DW_OP_reg17: | |
9841 | return "DW_OP_reg17"; | |
9842 | case DW_OP_reg18: | |
9843 | return "DW_OP_reg18"; | |
9844 | case DW_OP_reg19: | |
9845 | return "DW_OP_reg19"; | |
9846 | case DW_OP_reg20: | |
9847 | return "DW_OP_reg20"; | |
9848 | case DW_OP_reg21: | |
9849 | return "DW_OP_reg21"; | |
9850 | case DW_OP_reg22: | |
9851 | return "DW_OP_reg22"; | |
9852 | case DW_OP_reg23: | |
9853 | return "DW_OP_reg23"; | |
9854 | case DW_OP_reg24: | |
9855 | return "DW_OP_reg24"; | |
9856 | case DW_OP_reg25: | |
9857 | return "DW_OP_reg25"; | |
9858 | case DW_OP_reg26: | |
9859 | return "DW_OP_reg26"; | |
9860 | case DW_OP_reg27: | |
9861 | return "DW_OP_reg27"; | |
9862 | case DW_OP_reg28: | |
9863 | return "DW_OP_reg28"; | |
9864 | case DW_OP_reg29: | |
9865 | return "DW_OP_reg29"; | |
9866 | case DW_OP_reg30: | |
9867 | return "DW_OP_reg30"; | |
9868 | case DW_OP_reg31: | |
9869 | return "DW_OP_reg31"; | |
9870 | case DW_OP_breg0: | |
9871 | return "DW_OP_breg0"; | |
9872 | case DW_OP_breg1: | |
9873 | return "DW_OP_breg1"; | |
9874 | case DW_OP_breg2: | |
9875 | return "DW_OP_breg2"; | |
9876 | case DW_OP_breg3: | |
9877 | return "DW_OP_breg3"; | |
9878 | case DW_OP_breg4: | |
9879 | return "DW_OP_breg4"; | |
9880 | case DW_OP_breg5: | |
9881 | return "DW_OP_breg5"; | |
9882 | case DW_OP_breg6: | |
9883 | return "DW_OP_breg6"; | |
9884 | case DW_OP_breg7: | |
9885 | return "DW_OP_breg7"; | |
9886 | case DW_OP_breg8: | |
9887 | return "DW_OP_breg8"; | |
9888 | case DW_OP_breg9: | |
9889 | return "DW_OP_breg9"; | |
9890 | case DW_OP_breg10: | |
9891 | return "DW_OP_breg10"; | |
9892 | case DW_OP_breg11: | |
9893 | return "DW_OP_breg11"; | |
9894 | case DW_OP_breg12: | |
9895 | return "DW_OP_breg12"; | |
9896 | case DW_OP_breg13: | |
9897 | return "DW_OP_breg13"; | |
9898 | case DW_OP_breg14: | |
9899 | return "DW_OP_breg14"; | |
9900 | case DW_OP_breg15: | |
9901 | return "DW_OP_breg15"; | |
9902 | case DW_OP_breg16: | |
9903 | return "DW_OP_breg16"; | |
9904 | case DW_OP_breg17: | |
9905 | return "DW_OP_breg17"; | |
9906 | case DW_OP_breg18: | |
9907 | return "DW_OP_breg18"; | |
9908 | case DW_OP_breg19: | |
9909 | return "DW_OP_breg19"; | |
9910 | case DW_OP_breg20: | |
9911 | return "DW_OP_breg20"; | |
9912 | case DW_OP_breg21: | |
9913 | return "DW_OP_breg21"; | |
9914 | case DW_OP_breg22: | |
9915 | return "DW_OP_breg22"; | |
9916 | case DW_OP_breg23: | |
9917 | return "DW_OP_breg23"; | |
9918 | case DW_OP_breg24: | |
9919 | return "DW_OP_breg24"; | |
9920 | case DW_OP_breg25: | |
9921 | return "DW_OP_breg25"; | |
9922 | case DW_OP_breg26: | |
9923 | return "DW_OP_breg26"; | |
9924 | case DW_OP_breg27: | |
9925 | return "DW_OP_breg27"; | |
9926 | case DW_OP_breg28: | |
9927 | return "DW_OP_breg28"; | |
9928 | case DW_OP_breg29: | |
9929 | return "DW_OP_breg29"; | |
9930 | case DW_OP_breg30: | |
9931 | return "DW_OP_breg30"; | |
9932 | case DW_OP_breg31: | |
9933 | return "DW_OP_breg31"; | |
9934 | case DW_OP_regx: | |
9935 | return "DW_OP_regx"; | |
9936 | case DW_OP_fbreg: | |
9937 | return "DW_OP_fbreg"; | |
9938 | case DW_OP_bregx: | |
9939 | return "DW_OP_bregx"; | |
9940 | case DW_OP_piece: | |
9941 | return "DW_OP_piece"; | |
9942 | case DW_OP_deref_size: | |
9943 | return "DW_OP_deref_size"; | |
9944 | case DW_OP_xderef_size: | |
9945 | return "DW_OP_xderef_size"; | |
9946 | case DW_OP_nop: | |
9947 | return "DW_OP_nop"; | |
b7619582 | 9948 | /* DWARF 3 extensions. */ |
ed348acc EZ |
9949 | case DW_OP_push_object_address: |
9950 | return "DW_OP_push_object_address"; | |
9951 | case DW_OP_call2: | |
9952 | return "DW_OP_call2"; | |
9953 | case DW_OP_call4: | |
9954 | return "DW_OP_call4"; | |
9955 | case DW_OP_call_ref: | |
9956 | return "DW_OP_call_ref"; | |
b7619582 GF |
9957 | /* GNU extensions. */ |
9958 | case DW_OP_form_tls_address: | |
9959 | return "DW_OP_form_tls_address"; | |
9960 | case DW_OP_call_frame_cfa: | |
9961 | return "DW_OP_call_frame_cfa"; | |
9962 | case DW_OP_bit_piece: | |
9963 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
9964 | case DW_OP_GNU_push_tls_address: |
9965 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
9966 | case DW_OP_GNU_uninit: |
9967 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
9968 | /* HP extensions. */ |
9969 | case DW_OP_HP_is_value: | |
9970 | return "DW_OP_HP_is_value"; | |
9971 | case DW_OP_HP_fltconst4: | |
9972 | return "DW_OP_HP_fltconst4"; | |
9973 | case DW_OP_HP_fltconst8: | |
9974 | return "DW_OP_HP_fltconst8"; | |
9975 | case DW_OP_HP_mod_range: | |
9976 | return "DW_OP_HP_mod_range"; | |
9977 | case DW_OP_HP_unmod_range: | |
9978 | return "DW_OP_HP_unmod_range"; | |
9979 | case DW_OP_HP_tls: | |
9980 | return "DW_OP_HP_tls"; | |
c906108c SS |
9981 | default: |
9982 | return "OP_<unknown>"; | |
9983 | } | |
9984 | } | |
9985 | ||
9986 | static char * | |
fba45db2 | 9987 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
9988 | { |
9989 | if (mybool) | |
9990 | return "TRUE"; | |
9991 | else | |
9992 | return "FALSE"; | |
9993 | } | |
9994 | ||
9995 | /* Convert a DWARF type code into its string name. */ | |
9996 | ||
9997 | static char * | |
aa1ee363 | 9998 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
9999 | { |
10000 | switch (enc) | |
10001 | { | |
b7619582 GF |
10002 | case DW_ATE_void: |
10003 | return "DW_ATE_void"; | |
c906108c SS |
10004 | case DW_ATE_address: |
10005 | return "DW_ATE_address"; | |
10006 | case DW_ATE_boolean: | |
10007 | return "DW_ATE_boolean"; | |
10008 | case DW_ATE_complex_float: | |
10009 | return "DW_ATE_complex_float"; | |
10010 | case DW_ATE_float: | |
10011 | return "DW_ATE_float"; | |
10012 | case DW_ATE_signed: | |
10013 | return "DW_ATE_signed"; | |
10014 | case DW_ATE_signed_char: | |
10015 | return "DW_ATE_signed_char"; | |
10016 | case DW_ATE_unsigned: | |
10017 | return "DW_ATE_unsigned"; | |
10018 | case DW_ATE_unsigned_char: | |
10019 | return "DW_ATE_unsigned_char"; | |
b7619582 | 10020 | /* DWARF 3. */ |
d9fa45fe DC |
10021 | case DW_ATE_imaginary_float: |
10022 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
10023 | case DW_ATE_packed_decimal: |
10024 | return "DW_ATE_packed_decimal"; | |
10025 | case DW_ATE_numeric_string: | |
10026 | return "DW_ATE_numeric_string"; | |
10027 | case DW_ATE_edited: | |
10028 | return "DW_ATE_edited"; | |
10029 | case DW_ATE_signed_fixed: | |
10030 | return "DW_ATE_signed_fixed"; | |
10031 | case DW_ATE_unsigned_fixed: | |
10032 | return "DW_ATE_unsigned_fixed"; | |
10033 | case DW_ATE_decimal_float: | |
10034 | return "DW_ATE_decimal_float"; | |
10035 | /* HP extensions. */ | |
10036 | case DW_ATE_HP_float80: | |
10037 | return "DW_ATE_HP_float80"; | |
10038 | case DW_ATE_HP_complex_float80: | |
10039 | return "DW_ATE_HP_complex_float80"; | |
10040 | case DW_ATE_HP_float128: | |
10041 | return "DW_ATE_HP_float128"; | |
10042 | case DW_ATE_HP_complex_float128: | |
10043 | return "DW_ATE_HP_complex_float128"; | |
10044 | case DW_ATE_HP_floathpintel: | |
10045 | return "DW_ATE_HP_floathpintel"; | |
10046 | case DW_ATE_HP_imaginary_float80: | |
10047 | return "DW_ATE_HP_imaginary_float80"; | |
10048 | case DW_ATE_HP_imaginary_float128: | |
10049 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
10050 | default: |
10051 | return "DW_ATE_<unknown>"; | |
10052 | } | |
10053 | } | |
10054 | ||
10055 | /* Convert a DWARF call frame info operation to its string name. */ | |
10056 | ||
10057 | #if 0 | |
10058 | static char * | |
aa1ee363 | 10059 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
10060 | { |
10061 | switch (cfi_opc) | |
10062 | { | |
10063 | case DW_CFA_advance_loc: | |
10064 | return "DW_CFA_advance_loc"; | |
10065 | case DW_CFA_offset: | |
10066 | return "DW_CFA_offset"; | |
10067 | case DW_CFA_restore: | |
10068 | return "DW_CFA_restore"; | |
10069 | case DW_CFA_nop: | |
10070 | return "DW_CFA_nop"; | |
10071 | case DW_CFA_set_loc: | |
10072 | return "DW_CFA_set_loc"; | |
10073 | case DW_CFA_advance_loc1: | |
10074 | return "DW_CFA_advance_loc1"; | |
10075 | case DW_CFA_advance_loc2: | |
10076 | return "DW_CFA_advance_loc2"; | |
10077 | case DW_CFA_advance_loc4: | |
10078 | return "DW_CFA_advance_loc4"; | |
10079 | case DW_CFA_offset_extended: | |
10080 | return "DW_CFA_offset_extended"; | |
10081 | case DW_CFA_restore_extended: | |
10082 | return "DW_CFA_restore_extended"; | |
10083 | case DW_CFA_undefined: | |
10084 | return "DW_CFA_undefined"; | |
10085 | case DW_CFA_same_value: | |
10086 | return "DW_CFA_same_value"; | |
10087 | case DW_CFA_register: | |
10088 | return "DW_CFA_register"; | |
10089 | case DW_CFA_remember_state: | |
10090 | return "DW_CFA_remember_state"; | |
10091 | case DW_CFA_restore_state: | |
10092 | return "DW_CFA_restore_state"; | |
10093 | case DW_CFA_def_cfa: | |
10094 | return "DW_CFA_def_cfa"; | |
10095 | case DW_CFA_def_cfa_register: | |
10096 | return "DW_CFA_def_cfa_register"; | |
10097 | case DW_CFA_def_cfa_offset: | |
10098 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 10099 | /* DWARF 3. */ |
985cb1a3 JM |
10100 | case DW_CFA_def_cfa_expression: |
10101 | return "DW_CFA_def_cfa_expression"; | |
10102 | case DW_CFA_expression: | |
10103 | return "DW_CFA_expression"; | |
10104 | case DW_CFA_offset_extended_sf: | |
10105 | return "DW_CFA_offset_extended_sf"; | |
10106 | case DW_CFA_def_cfa_sf: | |
10107 | return "DW_CFA_def_cfa_sf"; | |
10108 | case DW_CFA_def_cfa_offset_sf: | |
10109 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
10110 | case DW_CFA_val_offset: |
10111 | return "DW_CFA_val_offset"; | |
10112 | case DW_CFA_val_offset_sf: | |
10113 | return "DW_CFA_val_offset_sf"; | |
10114 | case DW_CFA_val_expression: | |
10115 | return "DW_CFA_val_expression"; | |
10116 | /* SGI/MIPS specific. */ | |
c906108c SS |
10117 | case DW_CFA_MIPS_advance_loc8: |
10118 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 10119 | /* GNU extensions. */ |
985cb1a3 JM |
10120 | case DW_CFA_GNU_window_save: |
10121 | return "DW_CFA_GNU_window_save"; | |
10122 | case DW_CFA_GNU_args_size: | |
10123 | return "DW_CFA_GNU_args_size"; | |
10124 | case DW_CFA_GNU_negative_offset_extended: | |
10125 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
10126 | default: |
10127 | return "DW_CFA_<unknown>"; | |
10128 | } | |
10129 | } | |
10130 | #endif | |
10131 | ||
f9aca02d | 10132 | static void |
d97bc12b | 10133 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
10134 | { |
10135 | unsigned int i; | |
10136 | ||
d97bc12b DE |
10137 | print_spaces (indent, f); |
10138 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 10139 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
10140 | |
10141 | if (die->parent != NULL) | |
10142 | { | |
10143 | print_spaces (indent, f); | |
10144 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
10145 | die->parent->offset); | |
10146 | } | |
10147 | ||
10148 | print_spaces (indent, f); | |
10149 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 10150 | dwarf_bool_name (die->child != NULL)); |
c906108c | 10151 | |
d97bc12b DE |
10152 | print_spaces (indent, f); |
10153 | fprintf_unfiltered (f, " attributes:\n"); | |
10154 | ||
c906108c SS |
10155 | for (i = 0; i < die->num_attrs; ++i) |
10156 | { | |
d97bc12b DE |
10157 | print_spaces (indent, f); |
10158 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
10159 | dwarf_attr_name (die->attrs[i].name), |
10160 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 10161 | |
c906108c SS |
10162 | switch (die->attrs[i].form) |
10163 | { | |
10164 | case DW_FORM_ref_addr: | |
10165 | case DW_FORM_addr: | |
d97bc12b | 10166 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 10167 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
10168 | break; |
10169 | case DW_FORM_block2: | |
10170 | case DW_FORM_block4: | |
10171 | case DW_FORM_block: | |
10172 | case DW_FORM_block1: | |
d97bc12b | 10173 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 10174 | break; |
10b3939b DJ |
10175 | case DW_FORM_ref1: |
10176 | case DW_FORM_ref2: | |
10177 | case DW_FORM_ref4: | |
d97bc12b | 10178 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
10179 | (long) (DW_ADDR (&die->attrs[i]))); |
10180 | break; | |
c906108c SS |
10181 | case DW_FORM_data1: |
10182 | case DW_FORM_data2: | |
10183 | case DW_FORM_data4: | |
ce5d95e1 | 10184 | case DW_FORM_data8: |
c906108c SS |
10185 | case DW_FORM_udata: |
10186 | case DW_FORM_sdata: | |
43bbcdc2 PH |
10187 | fprintf_unfiltered (f, "constant: %s", |
10188 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 10189 | break; |
348e048f DE |
10190 | case DW_FORM_sig8: |
10191 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
10192 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
10193 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
10194 | else | |
10195 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
10196 | break; | |
c906108c | 10197 | case DW_FORM_string: |
4bdf3d34 | 10198 | case DW_FORM_strp: |
8285870a | 10199 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 10200 | DW_STRING (&die->attrs[i]) |
8285870a JK |
10201 | ? DW_STRING (&die->attrs[i]) : "", |
10202 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
10203 | break; |
10204 | case DW_FORM_flag: | |
10205 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 10206 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 10207 | else |
d97bc12b | 10208 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 10209 | break; |
a8329558 KW |
10210 | case DW_FORM_indirect: |
10211 | /* the reader will have reduced the indirect form to | |
10212 | the "base form" so this form should not occur */ | |
d97bc12b | 10213 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 10214 | break; |
c906108c | 10215 | default: |
d97bc12b | 10216 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 10217 | die->attrs[i].form); |
d97bc12b | 10218 | break; |
c906108c | 10219 | } |
d97bc12b | 10220 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
10221 | } |
10222 | } | |
10223 | ||
f9aca02d | 10224 | static void |
d97bc12b | 10225 | dump_die_for_error (struct die_info *die) |
c906108c | 10226 | { |
d97bc12b DE |
10227 | dump_die_shallow (gdb_stderr, 0, die); |
10228 | } | |
10229 | ||
10230 | static void | |
10231 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
10232 | { | |
10233 | int indent = level * 4; | |
10234 | ||
10235 | gdb_assert (die != NULL); | |
10236 | ||
10237 | if (level >= max_level) | |
10238 | return; | |
10239 | ||
10240 | dump_die_shallow (f, indent, die); | |
10241 | ||
10242 | if (die->child != NULL) | |
c906108c | 10243 | { |
d97bc12b DE |
10244 | print_spaces (indent, f); |
10245 | fprintf_unfiltered (f, " Children:"); | |
10246 | if (level + 1 < max_level) | |
10247 | { | |
10248 | fprintf_unfiltered (f, "\n"); | |
10249 | dump_die_1 (f, level + 1, max_level, die->child); | |
10250 | } | |
10251 | else | |
10252 | { | |
10253 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
10254 | } | |
10255 | } | |
10256 | ||
10257 | if (die->sibling != NULL && level > 0) | |
10258 | { | |
10259 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
10260 | } |
10261 | } | |
10262 | ||
d97bc12b DE |
10263 | /* This is called from the pdie macro in gdbinit.in. |
10264 | It's not static so gcc will keep a copy callable from gdb. */ | |
10265 | ||
10266 | void | |
10267 | dump_die (struct die_info *die, int max_level) | |
10268 | { | |
10269 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
10270 | } | |
10271 | ||
f9aca02d | 10272 | static void |
51545339 | 10273 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10274 | { |
51545339 | 10275 | void **slot; |
c906108c | 10276 | |
51545339 DJ |
10277 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
10278 | ||
10279 | *slot = die; | |
c906108c SS |
10280 | } |
10281 | ||
93311388 DE |
10282 | static int |
10283 | is_ref_attr (struct attribute *attr) | |
c906108c | 10284 | { |
c906108c SS |
10285 | switch (attr->form) |
10286 | { | |
10287 | case DW_FORM_ref_addr: | |
c906108c SS |
10288 | case DW_FORM_ref1: |
10289 | case DW_FORM_ref2: | |
10290 | case DW_FORM_ref4: | |
613e1657 | 10291 | case DW_FORM_ref8: |
c906108c | 10292 | case DW_FORM_ref_udata: |
93311388 | 10293 | return 1; |
c906108c | 10294 | default: |
93311388 | 10295 | return 0; |
c906108c | 10296 | } |
93311388 DE |
10297 | } |
10298 | ||
10299 | static unsigned int | |
10300 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
10301 | { | |
10302 | if (is_ref_attr (attr)) | |
10303 | return DW_ADDR (attr); | |
10304 | ||
10305 | complaint (&symfile_complaints, | |
10306 | _("unsupported die ref attribute form: '%s'"), | |
10307 | dwarf_form_name (attr->form)); | |
10308 | return 0; | |
c906108c SS |
10309 | } |
10310 | ||
43bbcdc2 PH |
10311 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
10312 | * the value held by the attribute is not constant. */ | |
a02abb62 | 10313 | |
43bbcdc2 | 10314 | static LONGEST |
a02abb62 JB |
10315 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
10316 | { | |
10317 | if (attr->form == DW_FORM_sdata) | |
10318 | return DW_SND (attr); | |
10319 | else if (attr->form == DW_FORM_udata | |
10320 | || attr->form == DW_FORM_data1 | |
10321 | || attr->form == DW_FORM_data2 | |
10322 | || attr->form == DW_FORM_data4 | |
10323 | || attr->form == DW_FORM_data8) | |
10324 | return DW_UNSND (attr); | |
10325 | else | |
10326 | { | |
e2e0b3e5 | 10327 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
10328 | dwarf_form_name (attr->form)); |
10329 | return default_value; | |
10330 | } | |
10331 | } | |
10332 | ||
03dd20cc | 10333 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
10334 | unit and add it to our queue. |
10335 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
10336 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 10337 | |
348e048f | 10338 | static int |
03dd20cc DJ |
10339 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
10340 | struct dwarf2_per_cu_data *per_cu) | |
10341 | { | |
10342 | /* Mark the dependence relation so that we don't flush PER_CU | |
10343 | too early. */ | |
10344 | dwarf2_add_dependence (this_cu, per_cu); | |
10345 | ||
10346 | /* If it's already on the queue, we have nothing to do. */ | |
10347 | if (per_cu->queued) | |
348e048f | 10348 | return 0; |
03dd20cc DJ |
10349 | |
10350 | /* If the compilation unit is already loaded, just mark it as | |
10351 | used. */ | |
10352 | if (per_cu->cu != NULL) | |
10353 | { | |
10354 | per_cu->cu->last_used = 0; | |
348e048f | 10355 | return 0; |
03dd20cc DJ |
10356 | } |
10357 | ||
10358 | /* Add it to the queue. */ | |
10359 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
10360 | |
10361 | return 1; | |
10362 | } | |
10363 | ||
10364 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
10365 | On entry *REF_CU is the CU of SRC_DIE. | |
10366 | On exit *REF_CU is the CU of the result. */ | |
10367 | ||
10368 | static struct die_info * | |
10369 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
10370 | struct dwarf2_cu **ref_cu) | |
10371 | { | |
10372 | struct die_info *die; | |
10373 | ||
10374 | if (is_ref_attr (attr)) | |
10375 | die = follow_die_ref (src_die, attr, ref_cu); | |
10376 | else if (attr->form == DW_FORM_sig8) | |
10377 | die = follow_die_sig (src_die, attr, ref_cu); | |
10378 | else | |
10379 | { | |
10380 | dump_die_for_error (src_die); | |
10381 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
10382 | (*ref_cu)->objfile->name); | |
10383 | } | |
10384 | ||
10385 | return die; | |
03dd20cc DJ |
10386 | } |
10387 | ||
f504f079 DE |
10388 | /* Follow reference attribute ATTR of SRC_DIE. |
10389 | On entry *REF_CU is the CU of SRC_DIE. | |
10390 | On exit *REF_CU is the CU of the result. */ | |
10391 | ||
f9aca02d | 10392 | static struct die_info * |
10b3939b | 10393 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 10394 | struct dwarf2_cu **ref_cu) |
c906108c SS |
10395 | { |
10396 | struct die_info *die; | |
10b3939b | 10397 | unsigned int offset; |
10b3939b | 10398 | struct die_info temp_die; |
f2f0e013 | 10399 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 10400 | |
348e048f DE |
10401 | gdb_assert (cu->per_cu != NULL); |
10402 | ||
c764a876 | 10403 | offset = dwarf2_get_ref_die_offset (attr); |
10b3939b | 10404 | |
348e048f DE |
10405 | if (cu->per_cu->from_debug_types) |
10406 | { | |
10407 | /* .debug_types CUs cannot reference anything outside their CU. | |
10408 | If they need to, they have to reference a signatured type via | |
10409 | DW_FORM_sig8. */ | |
10410 | if (! offset_in_cu_p (&cu->header, offset)) | |
10411 | goto not_found; | |
10412 | target_cu = cu; | |
10413 | } | |
10414 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
10415 | { |
10416 | struct dwarf2_per_cu_data *per_cu; | |
45452591 | 10417 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
10418 | |
10419 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
10420 | if (maybe_queue_comp_unit (cu, per_cu)) |
10421 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 10422 | |
10b3939b DJ |
10423 | target_cu = per_cu->cu; |
10424 | } | |
10425 | else | |
10426 | target_cu = cu; | |
c906108c | 10427 | |
f2f0e013 | 10428 | *ref_cu = target_cu; |
51545339 DJ |
10429 | temp_die.offset = offset; |
10430 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
10431 | if (die) | |
10432 | return die; | |
10b3939b | 10433 | |
348e048f DE |
10434 | not_found: |
10435 | ||
10436 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
10437 | "at 0x%x [in module %s]"), | |
10438 | offset, src_die->offset, cu->objfile->name); | |
10439 | } | |
10440 | ||
10441 | /* Follow the signature attribute ATTR in SRC_DIE. | |
10442 | On entry *REF_CU is the CU of SRC_DIE. | |
10443 | On exit *REF_CU is the CU of the result. */ | |
10444 | ||
10445 | static struct die_info * | |
10446 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
10447 | struct dwarf2_cu **ref_cu) | |
10448 | { | |
10449 | struct objfile *objfile = (*ref_cu)->objfile; | |
10450 | struct die_info temp_die; | |
10451 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
10452 | struct dwarf2_cu *sig_cu; | |
10453 | struct die_info *die; | |
10454 | ||
10455 | /* sig_type will be NULL if the signatured type is missing from | |
10456 | the debug info. */ | |
10457 | if (sig_type == NULL) | |
10458 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
10459 | "at 0x%x [in module %s]"), | |
10460 | src_die->offset, objfile->name); | |
10461 | ||
10462 | /* If necessary, add it to the queue and load its DIEs. */ | |
10463 | ||
10464 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
10465 | read_signatured_type (objfile, sig_type); | |
10466 | ||
10467 | gdb_assert (sig_type->per_cu.cu != NULL); | |
10468 | ||
10469 | sig_cu = sig_type->per_cu.cu; | |
10470 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
10471 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
10472 | if (die) | |
10473 | { | |
10474 | *ref_cu = sig_cu; | |
10475 | return die; | |
10476 | } | |
10477 | ||
10478 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
10479 | "at 0x%x [in module %s]"), | |
10480 | sig_type->type_offset, src_die->offset, objfile->name); | |
10481 | } | |
10482 | ||
10483 | /* Given an offset of a signatured type, return its signatured_type. */ | |
10484 | ||
10485 | static struct signatured_type * | |
10486 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
10487 | { | |
10488 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
10489 | unsigned int length, initial_length_size; | |
10490 | unsigned int sig_offset; | |
10491 | struct signatured_type find_entry, *type_sig; | |
10492 | ||
10493 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
10494 | sig_offset = (initial_length_size | |
10495 | + 2 /*version*/ | |
10496 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
10497 | + 1 /*address_size*/); | |
10498 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
10499 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
10500 | ||
10501 | /* This is only used to lookup previously recorded types. | |
10502 | If we didn't find it, it's our bug. */ | |
10503 | gdb_assert (type_sig != NULL); | |
10504 | gdb_assert (offset == type_sig->offset); | |
10505 | ||
10506 | return type_sig; | |
10507 | } | |
10508 | ||
10509 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
10510 | ||
10511 | static void | |
10512 | read_signatured_type_at_offset (struct objfile *objfile, | |
10513 | unsigned int offset) | |
10514 | { | |
10515 | struct signatured_type *type_sig; | |
10516 | ||
10517 | /* We have the section offset, but we need the signature to do the | |
10518 | hash table lookup. */ | |
10519 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
10520 | ||
10521 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10522 | ||
10523 | read_signatured_type (objfile, type_sig); | |
10524 | ||
10525 | gdb_assert (type_sig->per_cu.cu != NULL); | |
10526 | } | |
10527 | ||
10528 | /* Read in a signatured type and build its CU and DIEs. */ | |
10529 | ||
10530 | static void | |
10531 | read_signatured_type (struct objfile *objfile, | |
10532 | struct signatured_type *type_sig) | |
10533 | { | |
10534 | gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
10535 | struct die_reader_specs reader_specs; | |
10536 | struct dwarf2_cu *cu; | |
10537 | ULONGEST signature; | |
10538 | struct cleanup *back_to, *free_cu_cleanup; | |
10539 | struct attribute *attr; | |
10540 | ||
10541 | gdb_assert (type_sig->per_cu.cu == NULL); | |
10542 | ||
10543 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
10544 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
10545 | obstack_init (&cu->comp_unit_obstack); | |
10546 | cu->objfile = objfile; | |
10547 | type_sig->per_cu.cu = cu; | |
10548 | cu->per_cu = &type_sig->per_cu; | |
10549 | ||
10550 | /* If an error occurs while loading, release our storage. */ | |
10551 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
10552 | ||
10553 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
10554 | types_ptr, objfile->obfd); | |
10555 | gdb_assert (signature == type_sig->signature); | |
10556 | ||
10557 | cu->die_hash | |
10558 | = htab_create_alloc_ex (cu->header.length / 12, | |
10559 | die_hash, | |
10560 | die_eq, | |
10561 | NULL, | |
10562 | &cu->comp_unit_obstack, | |
10563 | hashtab_obstack_allocate, | |
10564 | dummy_obstack_deallocate); | |
10565 | ||
10566 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
10567 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10568 | ||
10569 | init_cu_die_reader (&reader_specs, cu); | |
10570 | ||
10571 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
10572 | NULL /*parent*/); | |
10573 | ||
10574 | /* We try not to read any attributes in this function, because not | |
10575 | all objfiles needed for references have been loaded yet, and symbol | |
10576 | table processing isn't initialized. But we have to set the CU language, | |
10577 | or we won't be able to build types correctly. */ | |
10578 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
10579 | if (attr) | |
10580 | set_cu_language (DW_UNSND (attr), cu); | |
10581 | else | |
10582 | set_cu_language (language_minimal, cu); | |
10583 | ||
10584 | do_cleanups (back_to); | |
10585 | ||
10586 | /* We've successfully allocated this compilation unit. Let our caller | |
10587 | clean it up when finished with it. */ | |
10588 | discard_cleanups (free_cu_cleanup); | |
10589 | ||
10590 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
10591 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
10592 | } |
10593 | ||
c906108c SS |
10594 | /* Decode simple location descriptions. |
10595 | Given a pointer to a dwarf block that defines a location, compute | |
10596 | the location and return the value. | |
10597 | ||
4cecd739 DJ |
10598 | NOTE drow/2003-11-18: This function is called in two situations |
10599 | now: for the address of static or global variables (partial symbols | |
10600 | only) and for offsets into structures which are expected to be | |
10601 | (more or less) constant. The partial symbol case should go away, | |
10602 | and only the constant case should remain. That will let this | |
10603 | function complain more accurately. A few special modes are allowed | |
10604 | without complaint for global variables (for instance, global | |
10605 | register values and thread-local values). | |
c906108c SS |
10606 | |
10607 | A location description containing no operations indicates that the | |
4cecd739 | 10608 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
10609 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
10610 | callers will only want a very basic result and this can become a | |
10611 | complaint. | |
c906108c | 10612 | |
c906108c SS |
10613 | Note that stack[0] is unused except as a default error return. |
10614 | Note that stack overflow is not yet handled. */ | |
10615 | ||
10616 | static CORE_ADDR | |
e7c27a73 | 10617 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 10618 | { |
e7c27a73 DJ |
10619 | struct objfile *objfile = cu->objfile; |
10620 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
10621 | int i; |
10622 | int size = blk->size; | |
fe1b8b76 | 10623 | gdb_byte *data = blk->data; |
c906108c SS |
10624 | CORE_ADDR stack[64]; |
10625 | int stacki; | |
10626 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 10627 | gdb_byte op; |
c906108c SS |
10628 | |
10629 | i = 0; | |
10630 | stacki = 0; | |
10631 | stack[stacki] = 0; | |
c906108c SS |
10632 | |
10633 | while (i < size) | |
10634 | { | |
c906108c SS |
10635 | op = data[i++]; |
10636 | switch (op) | |
10637 | { | |
f1bea926 JM |
10638 | case DW_OP_lit0: |
10639 | case DW_OP_lit1: | |
10640 | case DW_OP_lit2: | |
10641 | case DW_OP_lit3: | |
10642 | case DW_OP_lit4: | |
10643 | case DW_OP_lit5: | |
10644 | case DW_OP_lit6: | |
10645 | case DW_OP_lit7: | |
10646 | case DW_OP_lit8: | |
10647 | case DW_OP_lit9: | |
10648 | case DW_OP_lit10: | |
10649 | case DW_OP_lit11: | |
10650 | case DW_OP_lit12: | |
10651 | case DW_OP_lit13: | |
10652 | case DW_OP_lit14: | |
10653 | case DW_OP_lit15: | |
10654 | case DW_OP_lit16: | |
10655 | case DW_OP_lit17: | |
10656 | case DW_OP_lit18: | |
10657 | case DW_OP_lit19: | |
10658 | case DW_OP_lit20: | |
10659 | case DW_OP_lit21: | |
10660 | case DW_OP_lit22: | |
10661 | case DW_OP_lit23: | |
10662 | case DW_OP_lit24: | |
10663 | case DW_OP_lit25: | |
10664 | case DW_OP_lit26: | |
10665 | case DW_OP_lit27: | |
10666 | case DW_OP_lit28: | |
10667 | case DW_OP_lit29: | |
10668 | case DW_OP_lit30: | |
10669 | case DW_OP_lit31: | |
10670 | stack[++stacki] = op - DW_OP_lit0; | |
10671 | break; | |
10672 | ||
c906108c SS |
10673 | case DW_OP_reg0: |
10674 | case DW_OP_reg1: | |
10675 | case DW_OP_reg2: | |
10676 | case DW_OP_reg3: | |
10677 | case DW_OP_reg4: | |
10678 | case DW_OP_reg5: | |
10679 | case DW_OP_reg6: | |
10680 | case DW_OP_reg7: | |
10681 | case DW_OP_reg8: | |
10682 | case DW_OP_reg9: | |
10683 | case DW_OP_reg10: | |
10684 | case DW_OP_reg11: | |
10685 | case DW_OP_reg12: | |
10686 | case DW_OP_reg13: | |
10687 | case DW_OP_reg14: | |
10688 | case DW_OP_reg15: | |
10689 | case DW_OP_reg16: | |
10690 | case DW_OP_reg17: | |
10691 | case DW_OP_reg18: | |
10692 | case DW_OP_reg19: | |
10693 | case DW_OP_reg20: | |
10694 | case DW_OP_reg21: | |
10695 | case DW_OP_reg22: | |
10696 | case DW_OP_reg23: | |
10697 | case DW_OP_reg24: | |
10698 | case DW_OP_reg25: | |
10699 | case DW_OP_reg26: | |
10700 | case DW_OP_reg27: | |
10701 | case DW_OP_reg28: | |
10702 | case DW_OP_reg29: | |
10703 | case DW_OP_reg30: | |
10704 | case DW_OP_reg31: | |
c906108c | 10705 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
10706 | if (i < size) |
10707 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10708 | break; |
10709 | ||
10710 | case DW_OP_regx: | |
c906108c SS |
10711 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
10712 | i += bytes_read; | |
c906108c | 10713 | stack[++stacki] = unsnd; |
4cecd739 DJ |
10714 | if (i < size) |
10715 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
10716 | break; |
10717 | ||
10718 | case DW_OP_addr: | |
107d2387 | 10719 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 10720 | cu, &bytes_read); |
107d2387 | 10721 | i += bytes_read; |
c906108c SS |
10722 | break; |
10723 | ||
10724 | case DW_OP_const1u: | |
10725 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
10726 | i += 1; | |
10727 | break; | |
10728 | ||
10729 | case DW_OP_const1s: | |
10730 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
10731 | i += 1; | |
10732 | break; | |
10733 | ||
10734 | case DW_OP_const2u: | |
10735 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
10736 | i += 2; | |
10737 | break; | |
10738 | ||
10739 | case DW_OP_const2s: | |
10740 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
10741 | i += 2; | |
10742 | break; | |
10743 | ||
10744 | case DW_OP_const4u: | |
10745 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
10746 | i += 4; | |
10747 | break; | |
10748 | ||
10749 | case DW_OP_const4s: | |
10750 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
10751 | i += 4; | |
10752 | break; | |
10753 | ||
10754 | case DW_OP_constu: | |
10755 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 10756 | &bytes_read); |
c906108c SS |
10757 | i += bytes_read; |
10758 | break; | |
10759 | ||
10760 | case DW_OP_consts: | |
10761 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
10762 | i += bytes_read; | |
10763 | break; | |
10764 | ||
f1bea926 JM |
10765 | case DW_OP_dup: |
10766 | stack[stacki + 1] = stack[stacki]; | |
10767 | stacki++; | |
10768 | break; | |
10769 | ||
c906108c SS |
10770 | case DW_OP_plus: |
10771 | stack[stacki - 1] += stack[stacki]; | |
10772 | stacki--; | |
10773 | break; | |
10774 | ||
10775 | case DW_OP_plus_uconst: | |
10776 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
10777 | i += bytes_read; | |
10778 | break; | |
10779 | ||
10780 | case DW_OP_minus: | |
f1bea926 | 10781 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
10782 | stacki--; |
10783 | break; | |
10784 | ||
7a292a7a | 10785 | case DW_OP_deref: |
7a292a7a | 10786 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
10787 | this using GDB's address_class enum. This is valid for partial |
10788 | global symbols, although the variable's address will be bogus | |
10789 | in the psymtab. */ | |
7a292a7a | 10790 | if (i < size) |
4d3c2250 | 10791 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
10792 | break; |
10793 | ||
9d774e44 | 10794 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
10795 | /* The top of the stack has the offset from the beginning |
10796 | of the thread control block at which the variable is located. */ | |
10797 | /* Nothing should follow this operator, so the top of stack would | |
10798 | be returned. */ | |
4cecd739 DJ |
10799 | /* This is valid for partial global symbols, but the variable's |
10800 | address will be bogus in the psymtab. */ | |
9d774e44 | 10801 | if (i < size) |
4d3c2250 | 10802 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
10803 | break; |
10804 | ||
42be36b3 CT |
10805 | case DW_OP_GNU_uninit: |
10806 | break; | |
10807 | ||
c906108c | 10808 | default: |
e2e0b3e5 | 10809 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 10810 | dwarf_stack_op_name (op)); |
c906108c SS |
10811 | return (stack[stacki]); |
10812 | } | |
10813 | } | |
10814 | return (stack[stacki]); | |
10815 | } | |
10816 | ||
10817 | /* memory allocation interface */ | |
10818 | ||
c906108c | 10819 | static struct dwarf_block * |
7b5a2f43 | 10820 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
10821 | { |
10822 | struct dwarf_block *blk; | |
10823 | ||
10824 | blk = (struct dwarf_block *) | |
7b5a2f43 | 10825 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
10826 | return (blk); |
10827 | } | |
10828 | ||
10829 | static struct abbrev_info * | |
f3dd6933 | 10830 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
10831 | { |
10832 | struct abbrev_info *abbrev; | |
10833 | ||
f3dd6933 DJ |
10834 | abbrev = (struct abbrev_info *) |
10835 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
10836 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
10837 | return (abbrev); | |
10838 | } | |
10839 | ||
10840 | static struct die_info * | |
b60c80d6 | 10841 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
10842 | { |
10843 | struct die_info *die; | |
b60c80d6 DJ |
10844 | size_t size = sizeof (struct die_info); |
10845 | ||
10846 | if (num_attrs > 1) | |
10847 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 10848 | |
b60c80d6 | 10849 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
10850 | memset (die, 0, sizeof (struct die_info)); |
10851 | return (die); | |
10852 | } | |
2e276125 JB |
10853 | |
10854 | \f | |
10855 | /* Macro support. */ | |
10856 | ||
10857 | ||
10858 | /* Return the full name of file number I in *LH's file name table. | |
10859 | Use COMP_DIR as the name of the current directory of the | |
10860 | compilation. The result is allocated using xmalloc; the caller is | |
10861 | responsible for freeing it. */ | |
10862 | static char * | |
10863 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
10864 | { | |
6a83a1e6 EZ |
10865 | /* Is the file number a valid index into the line header's file name |
10866 | table? Remember that file numbers start with one, not zero. */ | |
10867 | if (1 <= file && file <= lh->num_file_names) | |
10868 | { | |
10869 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 10870 | |
6a83a1e6 EZ |
10871 | if (IS_ABSOLUTE_PATH (fe->name)) |
10872 | return xstrdup (fe->name); | |
10873 | else | |
10874 | { | |
10875 | const char *dir; | |
10876 | int dir_len; | |
10877 | char *full_name; | |
10878 | ||
10879 | if (fe->dir_index) | |
10880 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10881 | else | |
10882 | dir = comp_dir; | |
10883 | ||
10884 | if (dir) | |
10885 | { | |
10886 | dir_len = strlen (dir); | |
10887 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
10888 | strcpy (full_name, dir); | |
10889 | full_name[dir_len] = '/'; | |
10890 | strcpy (full_name + dir_len + 1, fe->name); | |
10891 | return full_name; | |
10892 | } | |
10893 | else | |
10894 | return xstrdup (fe->name); | |
10895 | } | |
10896 | } | |
2e276125 JB |
10897 | else |
10898 | { | |
6a83a1e6 EZ |
10899 | /* The compiler produced a bogus file number. We can at least |
10900 | record the macro definitions made in the file, even if we | |
10901 | won't be able to find the file by name. */ | |
10902 | char fake_name[80]; | |
10903 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 10904 | |
6a83a1e6 EZ |
10905 | complaint (&symfile_complaints, |
10906 | _("bad file number in macro information (%d)"), | |
10907 | file); | |
2e276125 | 10908 | |
6a83a1e6 | 10909 | return xstrdup (fake_name); |
2e276125 JB |
10910 | } |
10911 | } | |
10912 | ||
10913 | ||
10914 | static struct macro_source_file * | |
10915 | macro_start_file (int file, int line, | |
10916 | struct macro_source_file *current_file, | |
10917 | const char *comp_dir, | |
10918 | struct line_header *lh, struct objfile *objfile) | |
10919 | { | |
10920 | /* The full name of this source file. */ | |
10921 | char *full_name = file_full_name (file, lh, comp_dir); | |
10922 | ||
10923 | /* We don't create a macro table for this compilation unit | |
10924 | at all until we actually get a filename. */ | |
10925 | if (! pending_macros) | |
4a146b47 | 10926 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 10927 | objfile->macro_cache); |
2e276125 JB |
10928 | |
10929 | if (! current_file) | |
10930 | /* If we have no current file, then this must be the start_file | |
10931 | directive for the compilation unit's main source file. */ | |
10932 | current_file = macro_set_main (pending_macros, full_name); | |
10933 | else | |
10934 | current_file = macro_include (current_file, line, full_name); | |
10935 | ||
10936 | xfree (full_name); | |
10937 | ||
10938 | return current_file; | |
10939 | } | |
10940 | ||
10941 | ||
10942 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
10943 | followed by a null byte. */ | |
10944 | static char * | |
10945 | copy_string (const char *buf, int len) | |
10946 | { | |
10947 | char *s = xmalloc (len + 1); | |
10948 | memcpy (s, buf, len); | |
10949 | s[len] = '\0'; | |
10950 | ||
10951 | return s; | |
10952 | } | |
10953 | ||
10954 | ||
10955 | static const char * | |
10956 | consume_improper_spaces (const char *p, const char *body) | |
10957 | { | |
10958 | if (*p == ' ') | |
10959 | { | |
4d3c2250 | 10960 | complaint (&symfile_complaints, |
e2e0b3e5 | 10961 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 10962 | body); |
2e276125 JB |
10963 | |
10964 | while (*p == ' ') | |
10965 | p++; | |
10966 | } | |
10967 | ||
10968 | return p; | |
10969 | } | |
10970 | ||
10971 | ||
10972 | static void | |
10973 | parse_macro_definition (struct macro_source_file *file, int line, | |
10974 | const char *body) | |
10975 | { | |
10976 | const char *p; | |
10977 | ||
10978 | /* The body string takes one of two forms. For object-like macro | |
10979 | definitions, it should be: | |
10980 | ||
10981 | <macro name> " " <definition> | |
10982 | ||
10983 | For function-like macro definitions, it should be: | |
10984 | ||
10985 | <macro name> "() " <definition> | |
10986 | or | |
10987 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
10988 | ||
10989 | Spaces may appear only where explicitly indicated, and in the | |
10990 | <definition>. | |
10991 | ||
10992 | The Dwarf 2 spec says that an object-like macro's name is always | |
10993 | followed by a space, but versions of GCC around March 2002 omit | |
10994 | the space when the macro's definition is the empty string. | |
10995 | ||
10996 | The Dwarf 2 spec says that there should be no spaces between the | |
10997 | formal arguments in a function-like macro's formal argument list, | |
10998 | but versions of GCC around March 2002 include spaces after the | |
10999 | commas. */ | |
11000 | ||
11001 | ||
11002 | /* Find the extent of the macro name. The macro name is terminated | |
11003 | by either a space or null character (for an object-like macro) or | |
11004 | an opening paren (for a function-like macro). */ | |
11005 | for (p = body; *p; p++) | |
11006 | if (*p == ' ' || *p == '(') | |
11007 | break; | |
11008 | ||
11009 | if (*p == ' ' || *p == '\0') | |
11010 | { | |
11011 | /* It's an object-like macro. */ | |
11012 | int name_len = p - body; | |
11013 | char *name = copy_string (body, name_len); | |
11014 | const char *replacement; | |
11015 | ||
11016 | if (*p == ' ') | |
11017 | replacement = body + name_len + 1; | |
11018 | else | |
11019 | { | |
4d3c2250 | 11020 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11021 | replacement = body + name_len; |
11022 | } | |
11023 | ||
11024 | macro_define_object (file, line, name, replacement); | |
11025 | ||
11026 | xfree (name); | |
11027 | } | |
11028 | else if (*p == '(') | |
11029 | { | |
11030 | /* It's a function-like macro. */ | |
11031 | char *name = copy_string (body, p - body); | |
11032 | int argc = 0; | |
11033 | int argv_size = 1; | |
11034 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
11035 | ||
11036 | p++; | |
11037 | ||
11038 | p = consume_improper_spaces (p, body); | |
11039 | ||
11040 | /* Parse the formal argument list. */ | |
11041 | while (*p && *p != ')') | |
11042 | { | |
11043 | /* Find the extent of the current argument name. */ | |
11044 | const char *arg_start = p; | |
11045 | ||
11046 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
11047 | p++; | |
11048 | ||
11049 | if (! *p || p == arg_start) | |
4d3c2250 | 11050 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11051 | else |
11052 | { | |
11053 | /* Make sure argv has room for the new argument. */ | |
11054 | if (argc >= argv_size) | |
11055 | { | |
11056 | argv_size *= 2; | |
11057 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
11058 | } | |
11059 | ||
11060 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
11061 | } | |
11062 | ||
11063 | p = consume_improper_spaces (p, body); | |
11064 | ||
11065 | /* Consume the comma, if present. */ | |
11066 | if (*p == ',') | |
11067 | { | |
11068 | p++; | |
11069 | ||
11070 | p = consume_improper_spaces (p, body); | |
11071 | } | |
11072 | } | |
11073 | ||
11074 | if (*p == ')') | |
11075 | { | |
11076 | p++; | |
11077 | ||
11078 | if (*p == ' ') | |
11079 | /* Perfectly formed definition, no complaints. */ | |
11080 | macro_define_function (file, line, name, | |
11081 | argc, (const char **) argv, | |
11082 | p + 1); | |
11083 | else if (*p == '\0') | |
11084 | { | |
11085 | /* Complain, but do define it. */ | |
4d3c2250 | 11086 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11087 | macro_define_function (file, line, name, |
11088 | argc, (const char **) argv, | |
11089 | p); | |
11090 | } | |
11091 | else | |
11092 | /* Just complain. */ | |
4d3c2250 | 11093 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11094 | } |
11095 | else | |
11096 | /* Just complain. */ | |
4d3c2250 | 11097 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11098 | |
11099 | xfree (name); | |
11100 | { | |
11101 | int i; | |
11102 | ||
11103 | for (i = 0; i < argc; i++) | |
11104 | xfree (argv[i]); | |
11105 | } | |
11106 | xfree (argv); | |
11107 | } | |
11108 | else | |
4d3c2250 | 11109 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
11110 | } |
11111 | ||
11112 | ||
11113 | static void | |
11114 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
11115 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 11116 | struct dwarf2_cu *cu) |
2e276125 | 11117 | { |
fe1b8b76 | 11118 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 11119 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
11120 | enum dwarf_macinfo_record_type macinfo_type; |
11121 | int at_commandline; | |
2e276125 | 11122 | |
dce234bc | 11123 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 11124 | { |
e2e0b3e5 | 11125 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
11126 | return; |
11127 | } | |
11128 | ||
757a13d0 JK |
11129 | /* First pass: Find the name of the base filename. |
11130 | This filename is needed in order to process all macros whose definition | |
11131 | (or undefinition) comes from the command line. These macros are defined | |
11132 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
11133 | associated to the base file. | |
11134 | ||
11135 | To determine the base file name, we scan the macro definitions until we | |
11136 | reach the first DW_MACINFO_start_file entry. We then initialize | |
11137 | CURRENT_FILE accordingly so that any macro definition found before the | |
11138 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
11139 | ||
dce234bc PP |
11140 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
11141 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
11142 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 11143 | |
757a13d0 | 11144 | do |
2e276125 | 11145 | { |
2e276125 JB |
11146 | /* Do we at least have room for a macinfo type byte? */ |
11147 | if (mac_ptr >= mac_end) | |
11148 | { | |
757a13d0 JK |
11149 | /* Complaint is printed during the second pass as GDB will probably |
11150 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
11151 | break; | |
2e276125 JB |
11152 | } |
11153 | ||
11154 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11155 | mac_ptr++; | |
11156 | ||
11157 | switch (macinfo_type) | |
11158 | { | |
11159 | /* A zero macinfo type indicates the end of the macro | |
11160 | information. */ | |
11161 | case 0: | |
757a13d0 JK |
11162 | break; |
11163 | ||
11164 | case DW_MACINFO_define: | |
11165 | case DW_MACINFO_undef: | |
11166 | /* Only skip the data by MAC_PTR. */ | |
11167 | { | |
11168 | unsigned int bytes_read; | |
11169 | ||
11170 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11171 | mac_ptr += bytes_read; | |
11172 | read_string (abfd, mac_ptr, &bytes_read); | |
11173 | mac_ptr += bytes_read; | |
11174 | } | |
11175 | break; | |
11176 | ||
11177 | case DW_MACINFO_start_file: | |
11178 | { | |
11179 | unsigned int bytes_read; | |
11180 | int line, file; | |
11181 | ||
11182 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11183 | mac_ptr += bytes_read; | |
11184 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11185 | mac_ptr += bytes_read; | |
11186 | ||
11187 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
11188 | lh, cu->objfile); | |
11189 | } | |
11190 | break; | |
11191 | ||
11192 | case DW_MACINFO_end_file: | |
11193 | /* No data to skip by MAC_PTR. */ | |
11194 | break; | |
11195 | ||
11196 | case DW_MACINFO_vendor_ext: | |
11197 | /* Only skip the data by MAC_PTR. */ | |
11198 | { | |
11199 | unsigned int bytes_read; | |
11200 | ||
11201 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11202 | mac_ptr += bytes_read; | |
11203 | read_string (abfd, mac_ptr, &bytes_read); | |
11204 | mac_ptr += bytes_read; | |
11205 | } | |
11206 | break; | |
11207 | ||
11208 | default: | |
11209 | break; | |
11210 | } | |
11211 | } while (macinfo_type != 0 && current_file == NULL); | |
11212 | ||
11213 | /* Second pass: Process all entries. | |
11214 | ||
11215 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
11216 | command-line macro definitions/undefinitions. This flag is unset when we | |
11217 | reach the first DW_MACINFO_start_file entry. */ | |
11218 | ||
dce234bc | 11219 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
11220 | |
11221 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
11222 | GDB is still reading the definitions from command line. First | |
11223 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
11224 | to create CURRENT_FILE for the main source holding also the command line | |
11225 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
11226 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
11227 | ||
11228 | at_commandline = 1; | |
11229 | ||
11230 | do | |
11231 | { | |
11232 | /* Do we at least have room for a macinfo type byte? */ | |
11233 | if (mac_ptr >= mac_end) | |
11234 | { | |
11235 | dwarf2_macros_too_long_complaint (); | |
11236 | break; | |
11237 | } | |
11238 | ||
11239 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
11240 | mac_ptr++; | |
11241 | ||
11242 | switch (macinfo_type) | |
11243 | { | |
11244 | /* A zero macinfo type indicates the end of the macro | |
11245 | information. */ | |
11246 | case 0: | |
11247 | break; | |
2e276125 JB |
11248 | |
11249 | case DW_MACINFO_define: | |
11250 | case DW_MACINFO_undef: | |
11251 | { | |
891d2f0b | 11252 | unsigned int bytes_read; |
2e276125 JB |
11253 | int line; |
11254 | char *body; | |
11255 | ||
11256 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11257 | mac_ptr += bytes_read; | |
11258 | body = read_string (abfd, mac_ptr, &bytes_read); | |
11259 | mac_ptr += bytes_read; | |
11260 | ||
11261 | if (! current_file) | |
757a13d0 JK |
11262 | { |
11263 | /* DWARF violation as no main source is present. */ | |
11264 | complaint (&symfile_complaints, | |
11265 | _("debug info with no main source gives macro %s " | |
11266 | "on line %d: %s"), | |
905e0470 PM |
11267 | macinfo_type == DW_MACINFO_define ? |
11268 | _("definition") : | |
11269 | macinfo_type == DW_MACINFO_undef ? | |
11270 | _("undefinition") : | |
11271 | _("something-or-other"), line, body); | |
757a13d0 JK |
11272 | break; |
11273 | } | |
11274 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 11275 | complaint (&symfile_complaints, |
757a13d0 JK |
11276 | _("debug info gives %s macro %s with %s line %d: %s"), |
11277 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 PM |
11278 | macinfo_type == DW_MACINFO_define ? |
11279 | _("definition") : | |
11280 | macinfo_type == DW_MACINFO_undef ? | |
11281 | _("undefinition") : | |
11282 | _("something-or-other"), | |
757a13d0 JK |
11283 | line == 0 ? _("zero") : _("non-zero"), line, body); |
11284 | ||
11285 | if (macinfo_type == DW_MACINFO_define) | |
11286 | parse_macro_definition (current_file, line, body); | |
11287 | else if (macinfo_type == DW_MACINFO_undef) | |
11288 | macro_undef (current_file, line, body); | |
2e276125 JB |
11289 | } |
11290 | break; | |
11291 | ||
11292 | case DW_MACINFO_start_file: | |
11293 | { | |
891d2f0b | 11294 | unsigned int bytes_read; |
2e276125 JB |
11295 | int line, file; |
11296 | ||
11297 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11298 | mac_ptr += bytes_read; | |
11299 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11300 | mac_ptr += bytes_read; | |
11301 | ||
757a13d0 JK |
11302 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
11303 | complaint (&symfile_complaints, | |
11304 | _("debug info gives source %d included " | |
11305 | "from %s at %s line %d"), | |
11306 | file, at_commandline ? _("command-line") : _("file"), | |
11307 | line == 0 ? _("zero") : _("non-zero"), line); | |
11308 | ||
11309 | if (at_commandline) | |
11310 | { | |
11311 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
11312 | at_commandline = 0; | |
11313 | } | |
11314 | else | |
11315 | current_file = macro_start_file (file, line, | |
11316 | current_file, comp_dir, | |
11317 | lh, cu->objfile); | |
2e276125 JB |
11318 | } |
11319 | break; | |
11320 | ||
11321 | case DW_MACINFO_end_file: | |
11322 | if (! current_file) | |
4d3c2250 | 11323 | complaint (&symfile_complaints, |
e2e0b3e5 | 11324 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
11325 | else |
11326 | { | |
11327 | current_file = current_file->included_by; | |
11328 | if (! current_file) | |
11329 | { | |
11330 | enum dwarf_macinfo_record_type next_type; | |
11331 | ||
11332 | /* GCC circa March 2002 doesn't produce the zero | |
11333 | type byte marking the end of the compilation | |
11334 | unit. Complain if it's not there, but exit no | |
11335 | matter what. */ | |
11336 | ||
11337 | /* Do we at least have room for a macinfo type byte? */ | |
11338 | if (mac_ptr >= mac_end) | |
11339 | { | |
4d3c2250 | 11340 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
11341 | return; |
11342 | } | |
11343 | ||
11344 | /* We don't increment mac_ptr here, so this is just | |
11345 | a look-ahead. */ | |
11346 | next_type = read_1_byte (abfd, mac_ptr); | |
11347 | if (next_type != 0) | |
4d3c2250 | 11348 | complaint (&symfile_complaints, |
e2e0b3e5 | 11349 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
11350 | |
11351 | return; | |
11352 | } | |
11353 | } | |
11354 | break; | |
11355 | ||
11356 | case DW_MACINFO_vendor_ext: | |
11357 | { | |
891d2f0b | 11358 | unsigned int bytes_read; |
2e276125 JB |
11359 | int constant; |
11360 | char *string; | |
11361 | ||
11362 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
11363 | mac_ptr += bytes_read; | |
11364 | string = read_string (abfd, mac_ptr, &bytes_read); | |
11365 | mac_ptr += bytes_read; | |
11366 | ||
11367 | /* We don't recognize any vendor extensions. */ | |
11368 | } | |
11369 | break; | |
11370 | } | |
757a13d0 | 11371 | } while (macinfo_type != 0); |
2e276125 | 11372 | } |
8e19ed76 PS |
11373 | |
11374 | /* Check if the attribute's form is a DW_FORM_block* | |
11375 | if so return true else false. */ | |
11376 | static int | |
11377 | attr_form_is_block (struct attribute *attr) | |
11378 | { | |
11379 | return (attr == NULL ? 0 : | |
11380 | attr->form == DW_FORM_block1 | |
11381 | || attr->form == DW_FORM_block2 | |
11382 | || attr->form == DW_FORM_block4 | |
11383 | || attr->form == DW_FORM_block); | |
11384 | } | |
4c2df51b | 11385 | |
c6a0999f JB |
11386 | /* Return non-zero if ATTR's value is a section offset --- classes |
11387 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
11388 | You may use DW_UNSND (attr) to retrieve such offsets. | |
11389 | ||
11390 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
11391 | may have a value that belongs to more than one of these classes; it | |
11392 | would be ambiguous if we did, because we use the same forms for all | |
11393 | of them. */ | |
3690dd37 JB |
11394 | static int |
11395 | attr_form_is_section_offset (struct attribute *attr) | |
11396 | { | |
11397 | return (attr->form == DW_FORM_data4 | |
11398 | || attr->form == DW_FORM_data8); | |
11399 | } | |
11400 | ||
11401 | ||
11402 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
11403 | zero otherwise. When this function returns true, you can apply | |
11404 | dwarf2_get_attr_constant_value to it. | |
11405 | ||
11406 | However, note that for some attributes you must check | |
11407 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
11408 | and DW_FORM_data8 are members of both the constant class, and of | |
11409 | the classes that contain offsets into other debug sections | |
11410 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
11411 | that, if an attribute's can be either a constant or one of the | |
11412 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
11413 | taken as section offsets, not constants. */ | |
11414 | static int | |
11415 | attr_form_is_constant (struct attribute *attr) | |
11416 | { | |
11417 | switch (attr->form) | |
11418 | { | |
11419 | case DW_FORM_sdata: | |
11420 | case DW_FORM_udata: | |
11421 | case DW_FORM_data1: | |
11422 | case DW_FORM_data2: | |
11423 | case DW_FORM_data4: | |
11424 | case DW_FORM_data8: | |
11425 | return 1; | |
11426 | default: | |
11427 | return 0; | |
11428 | } | |
11429 | } | |
11430 | ||
4c2df51b DJ |
11431 | static void |
11432 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11433 | struct dwarf2_cu *cu) |
4c2df51b | 11434 | { |
3690dd37 | 11435 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
11436 | /* ".debug_loc" may not exist at all, or the offset may be outside |
11437 | the section. If so, fall through to the complaint in the | |
11438 | other branch. */ | |
dce234bc | 11439 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 11440 | { |
0d53c4c4 | 11441 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 11442 | |
4a146b47 | 11443 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11444 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
11445 | baton->per_cu = cu->per_cu; |
11446 | gdb_assert (baton->per_cu); | |
4c2df51b | 11447 | |
0d53c4c4 DJ |
11448 | /* We don't know how long the location list is, but make sure we |
11449 | don't run off the edge of the section. */ | |
dce234bc PP |
11450 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
11451 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
11452 | baton->base_address = cu->base_address; |
11453 | if (cu->base_known == 0) | |
0d53c4c4 | 11454 | complaint (&symfile_complaints, |
e2e0b3e5 | 11455 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 11456 | |
768a979c | 11457 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
11458 | SYMBOL_LOCATION_BATON (sym) = baton; |
11459 | } | |
11460 | else | |
11461 | { | |
11462 | struct dwarf2_locexpr_baton *baton; | |
11463 | ||
4a146b47 | 11464 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 11465 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
11466 | baton->per_cu = cu->per_cu; |
11467 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
11468 | |
11469 | if (attr_form_is_block (attr)) | |
11470 | { | |
11471 | /* Note that we're just copying the block's data pointer | |
11472 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
11473 | info_buffer for SYM's objfile; right now we never release |
11474 | that buffer, but when we do clean up properly this may | |
11475 | need to change. */ | |
0d53c4c4 DJ |
11476 | baton->size = DW_BLOCK (attr)->size; |
11477 | baton->data = DW_BLOCK (attr)->data; | |
11478 | } | |
11479 | else | |
11480 | { | |
11481 | dwarf2_invalid_attrib_class_complaint ("location description", | |
11482 | SYMBOL_NATURAL_NAME (sym)); | |
11483 | baton->size = 0; | |
11484 | baton->data = NULL; | |
11485 | } | |
11486 | ||
768a979c | 11487 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
11488 | SYMBOL_LOCATION_BATON (sym) = baton; |
11489 | } | |
4c2df51b | 11490 | } |
6502dd73 | 11491 | |
ae0d2f24 UW |
11492 | /* Return the OBJFILE associated with the compilation unit CU. */ |
11493 | ||
11494 | struct objfile * | |
11495 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
11496 | { | |
11497 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11498 | ||
11499 | /* Return the master objfile, so that we can report and look up the | |
11500 | correct file containing this variable. */ | |
11501 | if (objfile->separate_debug_objfile_backlink) | |
11502 | objfile = objfile->separate_debug_objfile_backlink; | |
11503 | ||
11504 | return objfile; | |
11505 | } | |
11506 | ||
11507 | /* Return the address size given in the compilation unit header for CU. */ | |
11508 | ||
11509 | CORE_ADDR | |
11510 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
11511 | { | |
11512 | if (per_cu->cu) | |
11513 | return per_cu->cu->header.addr_size; | |
11514 | else | |
11515 | { | |
11516 | /* If the CU is not currently read in, we re-read its header. */ | |
11517 | struct objfile *objfile = per_cu->psymtab->objfile; | |
11518 | struct dwarf2_per_objfile *per_objfile | |
11519 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 11520 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 UW |
11521 | |
11522 | struct comp_unit_head cu_header; | |
11523 | memset (&cu_header, 0, sizeof cu_header); | |
11524 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
11525 | return cu_header.addr_size; | |
11526 | } | |
11527 | } | |
11528 | ||
348e048f DE |
11529 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
11530 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
11531 | |
11532 | static struct dwarf2_per_cu_data * | |
c764a876 | 11533 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
11534 | struct objfile *objfile) |
11535 | { | |
11536 | struct dwarf2_per_cu_data *this_cu; | |
11537 | int low, high; | |
11538 | ||
ae038cb0 DJ |
11539 | low = 0; |
11540 | high = dwarf2_per_objfile->n_comp_units - 1; | |
11541 | while (high > low) | |
11542 | { | |
11543 | int mid = low + (high - low) / 2; | |
11544 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
11545 | high = mid; | |
11546 | else | |
11547 | low = mid + 1; | |
11548 | } | |
11549 | gdb_assert (low == high); | |
11550 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
11551 | { | |
10b3939b | 11552 | if (low == 0) |
8a3fe4f8 AC |
11553 | error (_("Dwarf Error: could not find partial DIE containing " |
11554 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
11555 | (long) offset, bfd_get_filename (objfile->obfd)); |
11556 | ||
ae038cb0 DJ |
11557 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
11558 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
11559 | } | |
11560 | else | |
11561 | { | |
11562 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
11563 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
11564 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 11565 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
11566 | gdb_assert (offset < this_cu->offset + this_cu->length); |
11567 | return this_cu; | |
11568 | } | |
11569 | } | |
11570 | ||
10b3939b DJ |
11571 | /* Locate the compilation unit from OBJFILE which is located at exactly |
11572 | OFFSET. Raises an error on failure. */ | |
11573 | ||
ae038cb0 | 11574 | static struct dwarf2_per_cu_data * |
c764a876 | 11575 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
11576 | { |
11577 | struct dwarf2_per_cu_data *this_cu; | |
11578 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
11579 | if (this_cu->offset != offset) | |
c764a876 | 11580 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
11581 | return this_cu; |
11582 | } | |
11583 | ||
93311388 DE |
11584 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
11585 | ||
11586 | static struct dwarf2_cu * | |
11587 | alloc_one_comp_unit (struct objfile *objfile) | |
11588 | { | |
11589 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
11590 | cu->objfile = objfile; | |
11591 | obstack_init (&cu->comp_unit_obstack); | |
11592 | return cu; | |
11593 | } | |
11594 | ||
ae038cb0 DJ |
11595 | /* Release one cached compilation unit, CU. We unlink it from the tree |
11596 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
11597 | the caller is responsible for that. |
11598 | NOTE: DATA is a void * because this function is also used as a | |
11599 | cleanup routine. */ | |
ae038cb0 DJ |
11600 | |
11601 | static void | |
11602 | free_one_comp_unit (void *data) | |
11603 | { | |
11604 | struct dwarf2_cu *cu = data; | |
11605 | ||
11606 | if (cu->per_cu != NULL) | |
11607 | cu->per_cu->cu = NULL; | |
11608 | cu->per_cu = NULL; | |
11609 | ||
11610 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11611 | ||
11612 | xfree (cu); | |
11613 | } | |
11614 | ||
72bf9492 | 11615 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
11616 | when we're finished with it. We can't free the pointer itself, but be |
11617 | sure to unlink it from the cache. Also release any associated storage | |
11618 | and perform cache maintenance. | |
72bf9492 DJ |
11619 | |
11620 | Only used during partial symbol parsing. */ | |
11621 | ||
11622 | static void | |
11623 | free_stack_comp_unit (void *data) | |
11624 | { | |
11625 | struct dwarf2_cu *cu = data; | |
11626 | ||
11627 | obstack_free (&cu->comp_unit_obstack, NULL); | |
11628 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
11629 | |
11630 | if (cu->per_cu != NULL) | |
11631 | { | |
11632 | /* This compilation unit is on the stack in our caller, so we | |
11633 | should not xfree it. Just unlink it. */ | |
11634 | cu->per_cu->cu = NULL; | |
11635 | cu->per_cu = NULL; | |
11636 | ||
11637 | /* If we had a per-cu pointer, then we may have other compilation | |
11638 | units loaded, so age them now. */ | |
11639 | age_cached_comp_units (); | |
11640 | } | |
11641 | } | |
11642 | ||
11643 | /* Free all cached compilation units. */ | |
11644 | ||
11645 | static void | |
11646 | free_cached_comp_units (void *data) | |
11647 | { | |
11648 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11649 | ||
11650 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11651 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11652 | while (per_cu != NULL) | |
11653 | { | |
11654 | struct dwarf2_per_cu_data *next_cu; | |
11655 | ||
11656 | next_cu = per_cu->cu->read_in_chain; | |
11657 | ||
11658 | free_one_comp_unit (per_cu->cu); | |
11659 | *last_chain = next_cu; | |
11660 | ||
11661 | per_cu = next_cu; | |
11662 | } | |
11663 | } | |
11664 | ||
11665 | /* Increase the age counter on each cached compilation unit, and free | |
11666 | any that are too old. */ | |
11667 | ||
11668 | static void | |
11669 | age_cached_comp_units (void) | |
11670 | { | |
11671 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11672 | ||
11673 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
11674 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11675 | while (per_cu != NULL) | |
11676 | { | |
11677 | per_cu->cu->last_used ++; | |
11678 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
11679 | dwarf2_mark (per_cu->cu); | |
11680 | per_cu = per_cu->cu->read_in_chain; | |
11681 | } | |
11682 | ||
11683 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11684 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11685 | while (per_cu != NULL) | |
11686 | { | |
11687 | struct dwarf2_per_cu_data *next_cu; | |
11688 | ||
11689 | next_cu = per_cu->cu->read_in_chain; | |
11690 | ||
11691 | if (!per_cu->cu->mark) | |
11692 | { | |
11693 | free_one_comp_unit (per_cu->cu); | |
11694 | *last_chain = next_cu; | |
11695 | } | |
11696 | else | |
11697 | last_chain = &per_cu->cu->read_in_chain; | |
11698 | ||
11699 | per_cu = next_cu; | |
11700 | } | |
11701 | } | |
11702 | ||
11703 | /* Remove a single compilation unit from the cache. */ | |
11704 | ||
11705 | static void | |
11706 | free_one_cached_comp_unit (void *target_cu) | |
11707 | { | |
11708 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
11709 | ||
11710 | per_cu = dwarf2_per_objfile->read_in_chain; | |
11711 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
11712 | while (per_cu != NULL) | |
11713 | { | |
11714 | struct dwarf2_per_cu_data *next_cu; | |
11715 | ||
11716 | next_cu = per_cu->cu->read_in_chain; | |
11717 | ||
11718 | if (per_cu->cu == target_cu) | |
11719 | { | |
11720 | free_one_comp_unit (per_cu->cu); | |
11721 | *last_chain = next_cu; | |
11722 | break; | |
11723 | } | |
11724 | else | |
11725 | last_chain = &per_cu->cu->read_in_chain; | |
11726 | ||
11727 | per_cu = next_cu; | |
11728 | } | |
11729 | } | |
11730 | ||
fe3e1990 DJ |
11731 | /* Release all extra memory associated with OBJFILE. */ |
11732 | ||
11733 | void | |
11734 | dwarf2_free_objfile (struct objfile *objfile) | |
11735 | { | |
11736 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
11737 | ||
11738 | if (dwarf2_per_objfile == NULL) | |
11739 | return; | |
11740 | ||
11741 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
11742 | free_cached_comp_units (NULL); | |
11743 | ||
11744 | /* Everything else should be on the objfile obstack. */ | |
11745 | } | |
11746 | ||
1c379e20 DJ |
11747 | /* A pair of DIE offset and GDB type pointer. We store these |
11748 | in a hash table separate from the DIEs, and preserve them | |
11749 | when the DIEs are flushed out of cache. */ | |
11750 | ||
11751 | struct dwarf2_offset_and_type | |
11752 | { | |
11753 | unsigned int offset; | |
11754 | struct type *type; | |
11755 | }; | |
11756 | ||
11757 | /* Hash function for a dwarf2_offset_and_type. */ | |
11758 | ||
11759 | static hashval_t | |
11760 | offset_and_type_hash (const void *item) | |
11761 | { | |
11762 | const struct dwarf2_offset_and_type *ofs = item; | |
11763 | return ofs->offset; | |
11764 | } | |
11765 | ||
11766 | /* Equality function for a dwarf2_offset_and_type. */ | |
11767 | ||
11768 | static int | |
11769 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
11770 | { | |
11771 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
11772 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
11773 | return ofs_lhs->offset == ofs_rhs->offset; | |
11774 | } | |
11775 | ||
11776 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 11777 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 11778 | |
f792889a | 11779 | static struct type * |
1c379e20 DJ |
11780 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
11781 | { | |
11782 | struct dwarf2_offset_and_type **slot, ofs; | |
11783 | ||
b4ba55a1 JB |
11784 | /* For Ada types, make sure that the gnat-specific data is always |
11785 | initialized (if not already set). There are a few types where | |
11786 | we should not be doing so, because the type-specific area is | |
11787 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
11788 | where the type-specific area is used to store the floatformat). | |
11789 | But this is not a problem, because the gnat-specific information | |
11790 | is actually not needed for these types. */ | |
11791 | if (need_gnat_info (cu) | |
11792 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
11793 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
11794 | && !HAVE_GNAT_AUX_INFO (type)) | |
11795 | INIT_GNAT_SPECIFIC (type); | |
11796 | ||
f792889a DJ |
11797 | if (cu->type_hash == NULL) |
11798 | { | |
11799 | gdb_assert (cu->per_cu != NULL); | |
11800 | cu->per_cu->type_hash | |
11801 | = htab_create_alloc_ex (cu->header.length / 24, | |
11802 | offset_and_type_hash, | |
11803 | offset_and_type_eq, | |
11804 | NULL, | |
11805 | &cu->objfile->objfile_obstack, | |
11806 | hashtab_obstack_allocate, | |
11807 | dummy_obstack_deallocate); | |
11808 | cu->type_hash = cu->per_cu->type_hash; | |
11809 | } | |
1c379e20 DJ |
11810 | |
11811 | ofs.offset = die->offset; | |
11812 | ofs.type = type; | |
11813 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 11814 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
11815 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
11816 | **slot = ofs; | |
f792889a | 11817 | return type; |
1c379e20 DJ |
11818 | } |
11819 | ||
f792889a DJ |
11820 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
11821 | not have a saved type. */ | |
1c379e20 DJ |
11822 | |
11823 | static struct type * | |
f792889a | 11824 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
11825 | { |
11826 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
11827 | htab_t type_hash = cu->type_hash; |
11828 | ||
11829 | if (type_hash == NULL) | |
11830 | return NULL; | |
1c379e20 DJ |
11831 | |
11832 | ofs.offset = die->offset; | |
11833 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
11834 | if (slot) | |
11835 | return slot->type; | |
11836 | else | |
11837 | return NULL; | |
11838 | } | |
11839 | ||
10b3939b DJ |
11840 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
11841 | ||
11842 | static void | |
11843 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
11844 | struct dwarf2_per_cu_data *ref_per_cu) | |
11845 | { | |
11846 | void **slot; | |
11847 | ||
11848 | if (cu->dependencies == NULL) | |
11849 | cu->dependencies | |
11850 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
11851 | NULL, &cu->comp_unit_obstack, | |
11852 | hashtab_obstack_allocate, | |
11853 | dummy_obstack_deallocate); | |
11854 | ||
11855 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
11856 | if (*slot == NULL) | |
11857 | *slot = ref_per_cu; | |
11858 | } | |
1c379e20 | 11859 | |
f504f079 DE |
11860 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
11861 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
11862 | cache that we must keep because we are keeping CU. */ |
11863 | ||
10b3939b DJ |
11864 | static int |
11865 | dwarf2_mark_helper (void **slot, void *data) | |
11866 | { | |
11867 | struct dwarf2_per_cu_data *per_cu; | |
11868 | ||
11869 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
11870 | if (per_cu->cu->mark) | |
11871 | return 1; | |
11872 | per_cu->cu->mark = 1; | |
11873 | ||
11874 | if (per_cu->cu->dependencies != NULL) | |
11875 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
11876 | ||
11877 | return 1; | |
11878 | } | |
11879 | ||
f504f079 DE |
11880 | /* Set the mark field in CU and in every other compilation unit in the |
11881 | cache that we must keep because we are keeping CU. */ | |
11882 | ||
ae038cb0 DJ |
11883 | static void |
11884 | dwarf2_mark (struct dwarf2_cu *cu) | |
11885 | { | |
11886 | if (cu->mark) | |
11887 | return; | |
11888 | cu->mark = 1; | |
10b3939b DJ |
11889 | if (cu->dependencies != NULL) |
11890 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
11891 | } |
11892 | ||
11893 | static void | |
11894 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
11895 | { | |
11896 | while (per_cu) | |
11897 | { | |
11898 | per_cu->cu->mark = 0; | |
11899 | per_cu = per_cu->cu->read_in_chain; | |
11900 | } | |
72bf9492 DJ |
11901 | } |
11902 | ||
72bf9492 DJ |
11903 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
11904 | is its offset in .debug_info for this objfile. */ | |
11905 | ||
11906 | static hashval_t | |
11907 | partial_die_hash (const void *item) | |
11908 | { | |
11909 | const struct partial_die_info *part_die = item; | |
11910 | return part_die->offset; | |
11911 | } | |
11912 | ||
11913 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
11914 | are equal if they have the same offset. */ | |
11915 | ||
11916 | static int | |
11917 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
11918 | { | |
11919 | const struct partial_die_info *part_die_lhs = item_lhs; | |
11920 | const struct partial_die_info *part_die_rhs = item_rhs; | |
11921 | return part_die_lhs->offset == part_die_rhs->offset; | |
11922 | } | |
11923 | ||
ae038cb0 DJ |
11924 | static struct cmd_list_element *set_dwarf2_cmdlist; |
11925 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
11926 | ||
11927 | static void | |
11928 | set_dwarf2_cmd (char *args, int from_tty) | |
11929 | { | |
11930 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
11931 | } | |
11932 | ||
11933 | static void | |
11934 | show_dwarf2_cmd (char *args, int from_tty) | |
11935 | { | |
11936 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
11937 | } | |
11938 | ||
dce234bc PP |
11939 | /* If section described by INFO was mmapped, munmap it now. */ |
11940 | ||
11941 | static void | |
11942 | munmap_section_buffer (struct dwarf2_section_info *info) | |
11943 | { | |
11944 | if (info->was_mmapped) | |
11945 | { | |
11946 | #ifdef HAVE_MMAP | |
11947 | intptr_t begin = (intptr_t) info->buffer; | |
11948 | intptr_t map_begin = begin & ~(pagesize - 1); | |
11949 | size_t map_length = info->size + begin - map_begin; | |
11950 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); | |
11951 | #else | |
11952 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
11953 | gdb_assert (0); | |
11954 | #endif | |
11955 | } | |
11956 | } | |
11957 | ||
11958 | /* munmap debug sections for OBJFILE, if necessary. */ | |
11959 | ||
11960 | static void | |
c1bd65d0 | 11961 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
11962 | { |
11963 | struct dwarf2_per_objfile *data = d; | |
11964 | munmap_section_buffer (&data->info); | |
11965 | munmap_section_buffer (&data->abbrev); | |
11966 | munmap_section_buffer (&data->line); | |
11967 | munmap_section_buffer (&data->str); | |
11968 | munmap_section_buffer (&data->macinfo); | |
11969 | munmap_section_buffer (&data->ranges); | |
11970 | munmap_section_buffer (&data->loc); | |
11971 | munmap_section_buffer (&data->frame); | |
11972 | munmap_section_buffer (&data->eh_frame); | |
11973 | } | |
11974 | ||
6502dd73 DJ |
11975 | void _initialize_dwarf2_read (void); |
11976 | ||
11977 | void | |
11978 | _initialize_dwarf2_read (void) | |
11979 | { | |
dce234bc | 11980 | dwarf2_objfile_data_key |
c1bd65d0 | 11981 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 11982 | |
1bedd215 AC |
11983 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
11984 | Set DWARF 2 specific variables.\n\ | |
11985 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
11986 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
11987 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
11988 | ||
1bedd215 AC |
11989 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
11990 | Show DWARF 2 specific variables\n\ | |
11991 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
11992 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
11993 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
11994 | ||
11995 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
11996 | &dwarf2_max_cache_age, _("\ |
11997 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
11998 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
11999 | A higher limit means that cached compilation units will be stored\n\ | |
12000 | in memory longer, and more total memory will be used. Zero disables\n\ | |
12001 | caching, which can slow down startup."), | |
2c5b56ce | 12002 | NULL, |
920d2a44 | 12003 | show_dwarf2_max_cache_age, |
2c5b56ce | 12004 | &set_dwarf2_cmdlist, |
ae038cb0 | 12005 | &show_dwarf2_cmdlist); |
d97bc12b DE |
12006 | |
12007 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ | |
12008 | Set debugging of the dwarf2 DIE reader."), _("\ | |
12009 | Show debugging of the dwarf2 DIE reader."), _("\ | |
12010 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
12011 | The value is the maximum depth to print."), | |
12012 | NULL, | |
12013 | NULL, | |
12014 | &setdebuglist, &showdebuglist); | |
6502dd73 | 12015 | } |