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, |
7b6bb8da | 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
0fb0cc75 | 5 | Free Software Foundation, Inc. |
c906108c SS |
6 | |
7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
8 | Inc. with support from Florida State University (under contract | |
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 12 | support. |
c906108c | 13 | |
c5aa993b | 14 | This file is part of GDB. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
18 | the Free Software Foundation; either version 3 of the License, or |
19 | (at your option) any later version. | |
c906108c | 20 | |
a9762ec7 JB |
21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
c906108c | 25 | |
c5aa993b | 26 | You should have received a copy of the GNU General Public License |
a9762ec7 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
28 | |
29 | #include "defs.h" | |
30 | #include "bfd.h" | |
c906108c SS |
31 | #include "symtab.h" |
32 | #include "gdbtypes.h" | |
c906108c | 33 | #include "objfiles.h" |
fa8f86ff | 34 | #include "dwarf2.h" |
c906108c SS |
35 | #include "buildsym.h" |
36 | #include "demangle.h" | |
37 | #include "expression.h" | |
d5166ae1 | 38 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 39 | #include "macrotab.h" |
c906108c SS |
40 | #include "language.h" |
41 | #include "complaints.h" | |
357e46e7 | 42 | #include "bcache.h" |
4c2df51b DJ |
43 | #include "dwarf2expr.h" |
44 | #include "dwarf2loc.h" | |
9219021c | 45 | #include "cp-support.h" |
72bf9492 | 46 | #include "hashtab.h" |
ae038cb0 DJ |
47 | #include "command.h" |
48 | #include "gdbcmd.h" | |
edb3359d | 49 | #include "block.h" |
ff013f42 | 50 | #include "addrmap.h" |
94af9270 KS |
51 | #include "typeprint.h" |
52 | #include "jv-lang.h" | |
ccefe4c4 | 53 | #include "psympriv.h" |
9291a0cd TT |
54 | #include "exceptions.h" |
55 | #include "gdb_stat.h" | |
96d19272 | 56 | #include "completer.h" |
34eaf542 | 57 | #include "vec.h" |
98bfdba5 PA |
58 | #include "c-lang.h" |
59 | #include "valprint.h" | |
60d5a603 | 60 | #include <ctype.h> |
4c2df51b | 61 | |
c906108c SS |
62 | #include <fcntl.h> |
63 | #include "gdb_string.h" | |
4bdf3d34 | 64 | #include "gdb_assert.h" |
c906108c | 65 | #include <sys/types.h> |
233a11ab CS |
66 | #ifdef HAVE_ZLIB_H |
67 | #include <zlib.h> | |
68 | #endif | |
dce234bc PP |
69 | #ifdef HAVE_MMAP |
70 | #include <sys/mman.h> | |
85d9bd0e TT |
71 | #ifndef MAP_FAILED |
72 | #define MAP_FAILED ((void *) -1) | |
73 | #endif | |
dce234bc | 74 | #endif |
d8151005 | 75 | |
34eaf542 TT |
76 | typedef struct symbol *symbolp; |
77 | DEF_VEC_P (symbolp); | |
78 | ||
107d2387 | 79 | #if 0 |
357e46e7 | 80 | /* .debug_info header for a compilation unit |
c906108c SS |
81 | Because of alignment constraints, this structure has padding and cannot |
82 | be mapped directly onto the beginning of the .debug_info section. */ | |
83 | typedef struct comp_unit_header | |
84 | { | |
85 | unsigned int length; /* length of the .debug_info | |
86 | contribution */ | |
87 | unsigned short version; /* version number -- 2 for DWARF | |
88 | version 2 */ | |
89 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
90 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
91 | } | |
92 | _COMP_UNIT_HEADER; | |
93 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 94 | #endif |
c906108c | 95 | |
c906108c SS |
96 | /* .debug_line statement program prologue |
97 | Because of alignment constraints, this structure has padding and cannot | |
98 | be mapped directly onto the beginning of the .debug_info section. */ | |
99 | typedef struct statement_prologue | |
100 | { | |
101 | unsigned int total_length; /* byte length of the statement | |
102 | information */ | |
103 | unsigned short version; /* version number -- 2 for DWARF | |
104 | version 2 */ | |
105 | unsigned int prologue_length; /* # bytes between prologue & | |
106 | stmt program */ | |
107 | unsigned char minimum_instruction_length; /* byte size of | |
108 | smallest instr */ | |
109 | unsigned char default_is_stmt; /* initial value of is_stmt | |
110 | register */ | |
111 | char line_base; | |
112 | unsigned char line_range; | |
113 | unsigned char opcode_base; /* number assigned to first special | |
114 | opcode */ | |
115 | unsigned char *standard_opcode_lengths; | |
116 | } | |
117 | _STATEMENT_PROLOGUE; | |
118 | ||
d97bc12b DE |
119 | /* When non-zero, dump DIEs after they are read in. */ |
120 | static int dwarf2_die_debug = 0; | |
121 | ||
900e11f9 JK |
122 | /* When non-zero, cross-check physname against demangler. */ |
123 | static int check_physname = 0; | |
124 | ||
dce234bc PP |
125 | static int pagesize; |
126 | ||
df8a16a1 DJ |
127 | /* When set, the file that we're processing is known to have debugging |
128 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
129 | but later versions do. */ | |
130 | ||
131 | static int processing_has_namespace_info; | |
132 | ||
6502dd73 DJ |
133 | static const struct objfile_data *dwarf2_objfile_data_key; |
134 | ||
dce234bc PP |
135 | struct dwarf2_section_info |
136 | { | |
137 | asection *asection; | |
138 | gdb_byte *buffer; | |
139 | bfd_size_type size; | |
b315ab21 TG |
140 | /* Not NULL if the section was actually mmapped. */ |
141 | void *map_addr; | |
142 | /* Page aligned size of mmapped area. */ | |
143 | bfd_size_type map_len; | |
be391dca TT |
144 | /* True if we have tried to read this section. */ |
145 | int readin; | |
dce234bc PP |
146 | }; |
147 | ||
8b70b953 TT |
148 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
149 | DEF_VEC_O (dwarf2_section_info_def); | |
150 | ||
9291a0cd TT |
151 | /* All offsets in the index are of this type. It must be |
152 | architecture-independent. */ | |
153 | typedef uint32_t offset_type; | |
154 | ||
155 | DEF_VEC_I (offset_type); | |
156 | ||
157 | /* A description of the mapped index. The file format is described in | |
158 | a comment by the code that writes the index. */ | |
159 | struct mapped_index | |
160 | { | |
559a7a62 JK |
161 | /* Index data format version. */ |
162 | int version; | |
163 | ||
9291a0cd TT |
164 | /* The total length of the buffer. */ |
165 | off_t total_size; | |
b11b1f88 | 166 | |
9291a0cd TT |
167 | /* A pointer to the address table data. */ |
168 | const gdb_byte *address_table; | |
b11b1f88 | 169 | |
9291a0cd TT |
170 | /* Size of the address table data in bytes. */ |
171 | offset_type address_table_size; | |
b11b1f88 | 172 | |
3876f04e DE |
173 | /* The symbol table, implemented as a hash table. */ |
174 | const offset_type *symbol_table; | |
b11b1f88 | 175 | |
9291a0cd | 176 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 177 | offset_type symbol_table_slots; |
b11b1f88 | 178 | |
9291a0cd TT |
179 | /* A pointer to the constant pool. */ |
180 | const char *constant_pool; | |
181 | }; | |
182 | ||
6502dd73 DJ |
183 | struct dwarf2_per_objfile |
184 | { | |
dce234bc PP |
185 | struct dwarf2_section_info info; |
186 | struct dwarf2_section_info abbrev; | |
187 | struct dwarf2_section_info line; | |
dce234bc PP |
188 | struct dwarf2_section_info loc; |
189 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 190 | struct dwarf2_section_info macro; |
dce234bc PP |
191 | struct dwarf2_section_info str; |
192 | struct dwarf2_section_info ranges; | |
193 | struct dwarf2_section_info frame; | |
194 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 195 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 196 | |
8b70b953 TT |
197 | VEC (dwarf2_section_info_def) *types; |
198 | ||
be391dca TT |
199 | /* Back link. */ |
200 | struct objfile *objfile; | |
201 | ||
10b3939b DJ |
202 | /* A list of all the compilation units. This is used to locate |
203 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
204 | struct dwarf2_per_cu_data **all_comp_units; |
205 | ||
206 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
207 | int n_comp_units; | |
208 | ||
1fd400ff TT |
209 | /* The number of .debug_types-related CUs. */ |
210 | int n_type_comp_units; | |
211 | ||
212 | /* The .debug_types-related CUs. */ | |
213 | struct dwarf2_per_cu_data **type_comp_units; | |
214 | ||
ae038cb0 DJ |
215 | /* A chain of compilation units that are currently read in, so that |
216 | they can be freed later. */ | |
217 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 218 | |
348e048f DE |
219 | /* A table mapping .debug_types signatures to its signatured_type entry. |
220 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
221 | htab_t signatured_types; | |
222 | ||
72dca2f5 FR |
223 | /* A flag indicating wether this objfile has a section loaded at a |
224 | VMA of 0. */ | |
225 | int has_section_at_zero; | |
9291a0cd | 226 | |
ae2de4f8 DE |
227 | /* True if we are using the mapped index, |
228 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
229 | unsigned char using_index; |
230 | ||
ae2de4f8 | 231 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 232 | struct mapped_index *index_table; |
98bfdba5 | 233 | |
7b9f3c50 DE |
234 | /* When using index_table, this keeps track of all quick_file_names entries. |
235 | TUs can share line table entries with CUs or other TUs, and there can be | |
236 | a lot more TUs than unique line tables, so we maintain a separate table | |
237 | of all line table entries to support the sharing. */ | |
238 | htab_t quick_file_names_table; | |
239 | ||
98bfdba5 PA |
240 | /* Set during partial symbol reading, to prevent queueing of full |
241 | symbols. */ | |
242 | int reading_partial_symbols; | |
673bfd45 DE |
243 | |
244 | /* Table mapping type .debug_info DIE offsets to types. | |
245 | This is NULL if not allocated yet. | |
246 | It (currently) makes sense to allocate debug_types_type_hash lazily. | |
247 | To keep things simple we allocate both lazily. */ | |
248 | htab_t debug_info_type_hash; | |
249 | ||
250 | /* Table mapping type .debug_types DIE offsets to types. | |
251 | This is NULL if not allocated yet. */ | |
252 | htab_t debug_types_type_hash; | |
6502dd73 DJ |
253 | }; |
254 | ||
255 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 256 | |
251d32d9 | 257 | /* Default names of the debugging sections. */ |
c906108c | 258 | |
233a11ab CS |
259 | /* Note that if the debugging section has been compressed, it might |
260 | have a name like .zdebug_info. */ | |
261 | ||
251d32d9 TG |
262 | static const struct dwarf2_debug_sections dwarf2_elf_names = { |
263 | { ".debug_info", ".zdebug_info" }, | |
264 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
265 | { ".debug_line", ".zdebug_line" }, | |
266 | { ".debug_loc", ".zdebug_loc" }, | |
267 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 268 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
269 | { ".debug_str", ".zdebug_str" }, |
270 | { ".debug_ranges", ".zdebug_ranges" }, | |
271 | { ".debug_types", ".zdebug_types" }, | |
272 | { ".debug_frame", ".zdebug_frame" }, | |
273 | { ".eh_frame", NULL }, | |
24d3216f TT |
274 | { ".gdb_index", ".zgdb_index" }, |
275 | 23 | |
251d32d9 | 276 | }; |
c906108c SS |
277 | |
278 | /* local data types */ | |
279 | ||
0963b4bd | 280 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
281 | #ifndef ABBREV_HASH_SIZE |
282 | #define ABBREV_HASH_SIZE 121 | |
283 | #endif | |
284 | ||
107d2387 AC |
285 | /* The data in a compilation unit header, after target2host |
286 | translation, looks like this. */ | |
c906108c | 287 | struct comp_unit_head |
a738430d | 288 | { |
c764a876 | 289 | unsigned int length; |
a738430d | 290 | short version; |
a738430d MK |
291 | unsigned char addr_size; |
292 | unsigned char signed_addr_p; | |
9cbfa09e | 293 | unsigned int abbrev_offset; |
57349743 | 294 | |
a738430d MK |
295 | /* Size of file offsets; either 4 or 8. */ |
296 | unsigned int offset_size; | |
57349743 | 297 | |
a738430d MK |
298 | /* Size of the length field; either 4 or 12. */ |
299 | unsigned int initial_length_size; | |
57349743 | 300 | |
a738430d MK |
301 | /* Offset to the first byte of this compilation unit header in the |
302 | .debug_info section, for resolving relative reference dies. */ | |
303 | unsigned int offset; | |
57349743 | 304 | |
d00adf39 DE |
305 | /* Offset to first die in this cu from the start of the cu. |
306 | This will be the first byte following the compilation unit header. */ | |
307 | unsigned int first_die_offset; | |
a738430d | 308 | }; |
c906108c | 309 | |
3da10d80 KS |
310 | /* Type used for delaying computation of method physnames. |
311 | See comments for compute_delayed_physnames. */ | |
312 | struct delayed_method_info | |
313 | { | |
314 | /* The type to which the method is attached, i.e., its parent class. */ | |
315 | struct type *type; | |
316 | ||
317 | /* The index of the method in the type's function fieldlists. */ | |
318 | int fnfield_index; | |
319 | ||
320 | /* The index of the method in the fieldlist. */ | |
321 | int index; | |
322 | ||
323 | /* The name of the DIE. */ | |
324 | const char *name; | |
325 | ||
326 | /* The DIE associated with this method. */ | |
327 | struct die_info *die; | |
328 | }; | |
329 | ||
330 | typedef struct delayed_method_info delayed_method_info; | |
331 | DEF_VEC_O (delayed_method_info); | |
332 | ||
e7c27a73 DJ |
333 | /* Internal state when decoding a particular compilation unit. */ |
334 | struct dwarf2_cu | |
335 | { | |
336 | /* The objfile containing this compilation unit. */ | |
337 | struct objfile *objfile; | |
338 | ||
d00adf39 | 339 | /* The header of the compilation unit. */ |
e7c27a73 | 340 | struct comp_unit_head header; |
e142c38c | 341 | |
d00adf39 DE |
342 | /* Base address of this compilation unit. */ |
343 | CORE_ADDR base_address; | |
344 | ||
345 | /* Non-zero if base_address has been set. */ | |
346 | int base_known; | |
347 | ||
e142c38c DJ |
348 | struct function_range *first_fn, *last_fn, *cached_fn; |
349 | ||
350 | /* The language we are debugging. */ | |
351 | enum language language; | |
352 | const struct language_defn *language_defn; | |
353 | ||
b0f35d58 DL |
354 | const char *producer; |
355 | ||
e142c38c DJ |
356 | /* The generic symbol table building routines have separate lists for |
357 | file scope symbols and all all other scopes (local scopes). So | |
358 | we need to select the right one to pass to add_symbol_to_list(). | |
359 | We do it by keeping a pointer to the correct list in list_in_scope. | |
360 | ||
361 | FIXME: The original dwarf code just treated the file scope as the | |
362 | first local scope, and all other local scopes as nested local | |
363 | scopes, and worked fine. Check to see if we really need to | |
364 | distinguish these in buildsym.c. */ | |
365 | struct pending **list_in_scope; | |
366 | ||
f3dd6933 DJ |
367 | /* DWARF abbreviation table associated with this compilation unit. */ |
368 | struct abbrev_info **dwarf2_abbrevs; | |
369 | ||
370 | /* Storage for the abbrev table. */ | |
371 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
372 | |
373 | /* Hash table holding all the loaded partial DIEs. */ | |
374 | htab_t partial_dies; | |
375 | ||
376 | /* Storage for things with the same lifetime as this read-in compilation | |
377 | unit, including partial DIEs. */ | |
378 | struct obstack comp_unit_obstack; | |
379 | ||
ae038cb0 DJ |
380 | /* When multiple dwarf2_cu structures are living in memory, this field |
381 | chains them all together, so that they can be released efficiently. | |
382 | We will probably also want a generation counter so that most-recently-used | |
383 | compilation units are cached... */ | |
384 | struct dwarf2_per_cu_data *read_in_chain; | |
385 | ||
386 | /* Backchain to our per_cu entry if the tree has been built. */ | |
387 | struct dwarf2_per_cu_data *per_cu; | |
388 | ||
389 | /* How many compilation units ago was this CU last referenced? */ | |
390 | int last_used; | |
391 | ||
10b3939b | 392 | /* A hash table of die offsets for following references. */ |
51545339 | 393 | htab_t die_hash; |
10b3939b DJ |
394 | |
395 | /* Full DIEs if read in. */ | |
396 | struct die_info *dies; | |
397 | ||
398 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
399 | units referenced by this one. Only set during full symbol processing; | |
400 | partial symbol tables do not have dependencies. */ | |
401 | htab_t dependencies; | |
402 | ||
cb1df416 DJ |
403 | /* Header data from the line table, during full symbol processing. */ |
404 | struct line_header *line_header; | |
405 | ||
3da10d80 KS |
406 | /* A list of methods which need to have physnames computed |
407 | after all type information has been read. */ | |
408 | VEC (delayed_method_info) *method_list; | |
409 | ||
96408a79 SA |
410 | /* To be copied to symtab->call_site_htab. */ |
411 | htab_t call_site_htab; | |
412 | ||
ae038cb0 DJ |
413 | /* Mark used when releasing cached dies. */ |
414 | unsigned int mark : 1; | |
415 | ||
416 | /* This flag will be set if this compilation unit might include | |
417 | inter-compilation-unit references. */ | |
418 | unsigned int has_form_ref_addr : 1; | |
419 | ||
72bf9492 DJ |
420 | /* This flag will be set if this compilation unit includes any |
421 | DW_TAG_namespace DIEs. If we know that there are explicit | |
422 | DIEs for namespaces, we don't need to try to infer them | |
423 | from mangled names. */ | |
424 | unsigned int has_namespace_info : 1; | |
8be455d7 JK |
425 | |
426 | /* This CU references .debug_loc. See the symtab->locations_valid field. | |
427 | This test is imperfect as there may exist optimized debug code not using | |
428 | any location list and still facing inlining issues if handled as | |
429 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
430 | ||
431 | unsigned int has_loclist : 1; | |
e7c27a73 DJ |
432 | }; |
433 | ||
10b3939b DJ |
434 | /* Persistent data held for a compilation unit, even when not |
435 | processing it. We put a pointer to this structure in the | |
436 | read_symtab_private field of the psymtab. If we encounter | |
437 | inter-compilation-unit references, we also maintain a sorted | |
438 | list of all compilation units. */ | |
439 | ||
ae038cb0 DJ |
440 | struct dwarf2_per_cu_data |
441 | { | |
348e048f | 442 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 443 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
444 | - if it doesn't, GDB will fall over anyway. |
445 | NOTE: Unlike comp_unit_head.length, this length includes | |
446 | initial_length_size. */ | |
c764a876 | 447 | unsigned int offset; |
348e048f | 448 | unsigned int length : 29; |
ae038cb0 DJ |
449 | |
450 | /* Flag indicating this compilation unit will be read in before | |
451 | any of the current compilation units are processed. */ | |
c764a876 | 452 | unsigned int queued : 1; |
ae038cb0 | 453 | |
5afb4e99 DJ |
454 | /* This flag will be set if we need to load absolutely all DIEs |
455 | for this compilation unit, instead of just the ones we think | |
456 | are interesting. It gets set if we look for a DIE in the | |
457 | hash table and don't find it. */ | |
458 | unsigned int load_all_dies : 1; | |
459 | ||
8b70b953 TT |
460 | /* Non-null if this CU is from .debug_types; in which case it points |
461 | to the section. Otherwise it's from .debug_info. */ | |
462 | struct dwarf2_section_info *debug_type_section; | |
348e048f | 463 | |
17ea53c3 JK |
464 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
465 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 466 | struct dwarf2_cu *cu; |
1c379e20 | 467 | |
9291a0cd TT |
468 | /* The corresponding objfile. */ |
469 | struct objfile *objfile; | |
470 | ||
471 | /* When using partial symbol tables, the 'psymtab' field is active. | |
472 | Otherwise the 'quick' field is active. */ | |
473 | union | |
474 | { | |
475 | /* The partial symbol table associated with this compilation unit, | |
476 | or NULL for partial units (which do not have an associated | |
477 | symtab). */ | |
478 | struct partial_symtab *psymtab; | |
479 | ||
480 | /* Data needed by the "quick" functions. */ | |
481 | struct dwarf2_per_cu_quick_data *quick; | |
482 | } v; | |
ae038cb0 DJ |
483 | }; |
484 | ||
348e048f DE |
485 | /* Entry in the signatured_types hash table. */ |
486 | ||
487 | struct signatured_type | |
488 | { | |
489 | ULONGEST signature; | |
490 | ||
348e048f DE |
491 | /* Offset in .debug_types of the type defined by this TU. */ |
492 | unsigned int type_offset; | |
493 | ||
494 | /* The CU(/TU) of this type. */ | |
495 | struct dwarf2_per_cu_data per_cu; | |
496 | }; | |
497 | ||
0963b4bd MS |
498 | /* Struct used to pass misc. parameters to read_die_and_children, et |
499 | al. which are used for both .debug_info and .debug_types dies. | |
500 | All parameters here are unchanging for the life of the call. This | |
501 | struct exists to abstract away the constant parameters of die | |
502 | reading. */ | |
93311388 DE |
503 | |
504 | struct die_reader_specs | |
505 | { | |
506 | /* The bfd of this objfile. */ | |
507 | bfd* abfd; | |
508 | ||
509 | /* The CU of the DIE we are parsing. */ | |
510 | struct dwarf2_cu *cu; | |
511 | ||
512 | /* Pointer to start of section buffer. | |
513 | This is either the start of .debug_info or .debug_types. */ | |
514 | const gdb_byte *buffer; | |
515 | }; | |
516 | ||
debd256d JB |
517 | /* The line number information for a compilation unit (found in the |
518 | .debug_line section) begins with a "statement program header", | |
519 | which contains the following information. */ | |
520 | struct line_header | |
521 | { | |
522 | unsigned int total_length; | |
523 | unsigned short version; | |
524 | unsigned int header_length; | |
525 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 526 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
527 | unsigned char default_is_stmt; |
528 | int line_base; | |
529 | unsigned char line_range; | |
530 | unsigned char opcode_base; | |
531 | ||
532 | /* standard_opcode_lengths[i] is the number of operands for the | |
533 | standard opcode whose value is i. This means that | |
534 | standard_opcode_lengths[0] is unused, and the last meaningful | |
535 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
536 | unsigned char *standard_opcode_lengths; | |
537 | ||
538 | /* The include_directories table. NOTE! These strings are not | |
539 | allocated with xmalloc; instead, they are pointers into | |
540 | debug_line_buffer. If you try to free them, `free' will get | |
541 | indigestion. */ | |
542 | unsigned int num_include_dirs, include_dirs_size; | |
543 | char **include_dirs; | |
544 | ||
545 | /* The file_names table. NOTE! These strings are not allocated | |
546 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
547 | Don't try to free them directly. */ | |
548 | unsigned int num_file_names, file_names_size; | |
549 | struct file_entry | |
c906108c | 550 | { |
debd256d JB |
551 | char *name; |
552 | unsigned int dir_index; | |
553 | unsigned int mod_time; | |
554 | unsigned int length; | |
aaa75496 | 555 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 556 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
557 | } *file_names; |
558 | ||
559 | /* The start and end of the statement program following this | |
6502dd73 | 560 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 561 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 562 | }; |
c906108c SS |
563 | |
564 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 565 | need this much information. */ |
c906108c SS |
566 | struct partial_die_info |
567 | { | |
72bf9492 | 568 | /* Offset of this DIE. */ |
c906108c | 569 | unsigned int offset; |
72bf9492 DJ |
570 | |
571 | /* DWARF-2 tag for this DIE. */ | |
572 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
573 | ||
72bf9492 DJ |
574 | /* Assorted flags describing the data found in this DIE. */ |
575 | unsigned int has_children : 1; | |
576 | unsigned int is_external : 1; | |
577 | unsigned int is_declaration : 1; | |
578 | unsigned int has_type : 1; | |
579 | unsigned int has_specification : 1; | |
580 | unsigned int has_pc_info : 1; | |
581 | ||
582 | /* Flag set if the SCOPE field of this structure has been | |
583 | computed. */ | |
584 | unsigned int scope_set : 1; | |
585 | ||
fa4028e9 JB |
586 | /* Flag set if the DIE has a byte_size attribute. */ |
587 | unsigned int has_byte_size : 1; | |
588 | ||
98bfdba5 PA |
589 | /* Flag set if any of the DIE's children are template arguments. */ |
590 | unsigned int has_template_arguments : 1; | |
591 | ||
abc72ce4 DE |
592 | /* Flag set if fixup_partial_die has been called on this die. */ |
593 | unsigned int fixup_called : 1; | |
594 | ||
72bf9492 | 595 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 596 | sometimes a default name for unnamed DIEs. */ |
c906108c | 597 | char *name; |
72bf9492 | 598 | |
abc72ce4 DE |
599 | /* The linkage name, if present. */ |
600 | const char *linkage_name; | |
601 | ||
72bf9492 DJ |
602 | /* The scope to prepend to our children. This is generally |
603 | allocated on the comp_unit_obstack, so will disappear | |
604 | when this compilation unit leaves the cache. */ | |
605 | char *scope; | |
606 | ||
607 | /* The location description associated with this DIE, if any. */ | |
608 | struct dwarf_block *locdesc; | |
609 | ||
610 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
611 | CORE_ADDR lowpc; |
612 | CORE_ADDR highpc; | |
72bf9492 | 613 | |
93311388 | 614 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 615 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
616 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
617 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 618 | gdb_byte *sibling; |
72bf9492 DJ |
619 | |
620 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
621 | DW_AT_specification (or DW_AT_abstract_origin or | |
622 | DW_AT_extension). */ | |
623 | unsigned int spec_offset; | |
624 | ||
625 | /* Pointers to this DIE's parent, first child, and next sibling, | |
626 | if any. */ | |
627 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
628 | }; |
629 | ||
0963b4bd | 630 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
631 | struct abbrev_info |
632 | { | |
633 | unsigned int number; /* number identifying abbrev */ | |
634 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
635 | unsigned short has_children; /* boolean */ |
636 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
637 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
638 | struct abbrev_info *next; /* next in chain */ | |
639 | }; | |
640 | ||
641 | struct attr_abbrev | |
642 | { | |
9d25dd43 DE |
643 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
644 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
645 | }; |
646 | ||
0963b4bd | 647 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
648 | struct attribute |
649 | { | |
9d25dd43 | 650 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
651 | ENUM_BITFIELD(dwarf_form) form : 15; |
652 | ||
653 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
654 | field should be in u.str (existing only for DW_STRING) but it is kept | |
655 | here for better struct attribute alignment. */ | |
656 | unsigned int string_is_canonical : 1; | |
657 | ||
b60c80d6 DJ |
658 | union |
659 | { | |
660 | char *str; | |
661 | struct dwarf_block *blk; | |
43bbcdc2 PH |
662 | ULONGEST unsnd; |
663 | LONGEST snd; | |
b60c80d6 | 664 | CORE_ADDR addr; |
348e048f | 665 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
666 | } |
667 | u; | |
668 | }; | |
669 | ||
0963b4bd | 670 | /* This data structure holds a complete die structure. */ |
c906108c SS |
671 | struct die_info |
672 | { | |
76815b17 DE |
673 | /* DWARF-2 tag for this DIE. */ |
674 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
675 | ||
676 | /* Number of attributes */ | |
98bfdba5 PA |
677 | unsigned char num_attrs; |
678 | ||
679 | /* True if we're presently building the full type name for the | |
680 | type derived from this DIE. */ | |
681 | unsigned char building_fullname : 1; | |
76815b17 DE |
682 | |
683 | /* Abbrev number */ | |
684 | unsigned int abbrev; | |
685 | ||
93311388 | 686 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 687 | unsigned int offset; |
78ba4af6 JB |
688 | |
689 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
690 | points to this die's parent; CHILD points to the first child of | |
691 | this node; and all the children of a given node are chained | |
4950bc1c | 692 | together via their SIBLING fields. */ |
639d11d3 DC |
693 | struct die_info *child; /* Its first child, if any. */ |
694 | struct die_info *sibling; /* Its next sibling, if any. */ | |
695 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 696 | |
b60c80d6 DJ |
697 | /* An array of attributes, with NUM_ATTRS elements. There may be |
698 | zero, but it's not common and zero-sized arrays are not | |
699 | sufficiently portable C. */ | |
700 | struct attribute attrs[1]; | |
c906108c SS |
701 | }; |
702 | ||
5fb290d7 DJ |
703 | struct function_range |
704 | { | |
705 | const char *name; | |
706 | CORE_ADDR lowpc, highpc; | |
707 | int seen_line; | |
708 | struct function_range *next; | |
709 | }; | |
710 | ||
0963b4bd | 711 | /* Get at parts of an attribute structure. */ |
c906108c SS |
712 | |
713 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 714 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
715 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
716 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
717 | #define DW_SND(attr) ((attr)->u.snd) | |
718 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 719 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 720 | |
0963b4bd | 721 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
722 | struct dwarf_block |
723 | { | |
724 | unsigned int size; | |
fe1b8b76 | 725 | gdb_byte *data; |
c906108c SS |
726 | }; |
727 | ||
c906108c SS |
728 | #ifndef ATTR_ALLOC_CHUNK |
729 | #define ATTR_ALLOC_CHUNK 4 | |
730 | #endif | |
731 | ||
c906108c SS |
732 | /* Allocate fields for structs, unions and enums in this size. */ |
733 | #ifndef DW_FIELD_ALLOC_CHUNK | |
734 | #define DW_FIELD_ALLOC_CHUNK 4 | |
735 | #endif | |
736 | ||
c906108c SS |
737 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
738 | but this would require a corresponding change in unpack_field_as_long | |
739 | and friends. */ | |
740 | static int bits_per_byte = 8; | |
741 | ||
742 | /* The routines that read and process dies for a C struct or C++ class | |
743 | pass lists of data member fields and lists of member function fields | |
744 | in an instance of a field_info structure, as defined below. */ | |
745 | struct field_info | |
c5aa993b | 746 | { |
0963b4bd | 747 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
748 | struct nextfield |
749 | { | |
750 | struct nextfield *next; | |
751 | int accessibility; | |
752 | int virtuality; | |
753 | struct field field; | |
754 | } | |
7d0ccb61 | 755 | *fields, *baseclasses; |
c906108c | 756 | |
7d0ccb61 | 757 | /* Number of fields (including baseclasses). */ |
c5aa993b | 758 | int nfields; |
c906108c | 759 | |
c5aa993b JM |
760 | /* Number of baseclasses. */ |
761 | int nbaseclasses; | |
c906108c | 762 | |
c5aa993b JM |
763 | /* Set if the accesibility of one of the fields is not public. */ |
764 | int non_public_fields; | |
c906108c | 765 | |
c5aa993b JM |
766 | /* Member function fields array, entries are allocated in the order they |
767 | are encountered in the object file. */ | |
768 | struct nextfnfield | |
769 | { | |
770 | struct nextfnfield *next; | |
771 | struct fn_field fnfield; | |
772 | } | |
773 | *fnfields; | |
c906108c | 774 | |
c5aa993b JM |
775 | /* Member function fieldlist array, contains name of possibly overloaded |
776 | member function, number of overloaded member functions and a pointer | |
777 | to the head of the member function field chain. */ | |
778 | struct fnfieldlist | |
779 | { | |
780 | char *name; | |
781 | int length; | |
782 | struct nextfnfield *head; | |
783 | } | |
784 | *fnfieldlists; | |
c906108c | 785 | |
c5aa993b JM |
786 | /* Number of entries in the fnfieldlists array. */ |
787 | int nfnfields; | |
98751a41 JK |
788 | |
789 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
790 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
791 | struct typedef_field_list | |
792 | { | |
793 | struct typedef_field field; | |
794 | struct typedef_field_list *next; | |
795 | } | |
796 | *typedef_field_list; | |
797 | unsigned typedef_field_list_count; | |
c5aa993b | 798 | }; |
c906108c | 799 | |
10b3939b DJ |
800 | /* One item on the queue of compilation units to read in full symbols |
801 | for. */ | |
802 | struct dwarf2_queue_item | |
803 | { | |
804 | struct dwarf2_per_cu_data *per_cu; | |
805 | struct dwarf2_queue_item *next; | |
806 | }; | |
807 | ||
808 | /* The current queue. */ | |
809 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
810 | ||
ae038cb0 DJ |
811 | /* Loaded secondary compilation units are kept in memory until they |
812 | have not been referenced for the processing of this many | |
813 | compilation units. Set this to zero to disable caching. Cache | |
814 | sizes of up to at least twenty will improve startup time for | |
815 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
816 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
817 | static void |
818 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
819 | struct cmd_list_element *c, const char *value) | |
820 | { | |
3e43a32a MS |
821 | fprintf_filtered (file, _("The upper bound on the age of cached " |
822 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
823 | value); |
824 | } | |
825 | ||
ae038cb0 | 826 | |
0963b4bd | 827 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 828 | |
4d3c2250 KB |
829 | static void |
830 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 831 | { |
4d3c2250 | 832 | complaint (&symfile_complaints, |
e2e0b3e5 | 833 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
834 | } |
835 | ||
25e43795 DJ |
836 | static void |
837 | dwarf2_debug_line_missing_file_complaint (void) | |
838 | { | |
839 | complaint (&symfile_complaints, | |
840 | _(".debug_line section has line data without a file")); | |
841 | } | |
842 | ||
59205f5a JB |
843 | static void |
844 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
845 | { | |
846 | complaint (&symfile_complaints, | |
3e43a32a MS |
847 | _(".debug_line section has line " |
848 | "program sequence without an end")); | |
59205f5a JB |
849 | } |
850 | ||
4d3c2250 KB |
851 | static void |
852 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 853 | { |
e2e0b3e5 | 854 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
855 | } |
856 | ||
4d3c2250 KB |
857 | static void |
858 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
859 | int arg3) | |
2e276125 | 860 | { |
4d3c2250 | 861 | complaint (&symfile_complaints, |
3e43a32a MS |
862 | _("const value length mismatch for '%s', got %d, expected %d"), |
863 | arg1, arg2, arg3); | |
4d3c2250 KB |
864 | } |
865 | ||
866 | static void | |
cf2c3c16 | 867 | dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section) |
2e276125 | 868 | { |
4d3c2250 | 869 | complaint (&symfile_complaints, |
cf2c3c16 TT |
870 | _("macro info runs off end of `%s' section"), |
871 | section->asection->name); | |
4d3c2250 KB |
872 | } |
873 | ||
874 | static void | |
875 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 876 | { |
4d3c2250 | 877 | complaint (&symfile_complaints, |
3e43a32a MS |
878 | _("macro debug info contains a " |
879 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
880 | arg1); |
881 | } | |
882 | ||
883 | static void | |
884 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 885 | { |
4d3c2250 | 886 | complaint (&symfile_complaints, |
3e43a32a MS |
887 | _("invalid attribute class or form for '%s' in '%s'"), |
888 | arg1, arg2); | |
4d3c2250 | 889 | } |
c906108c | 890 | |
c906108c SS |
891 | /* local function prototypes */ |
892 | ||
4efb68b1 | 893 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 894 | |
aaa75496 JB |
895 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
896 | struct objfile *); | |
897 | ||
918dd910 JK |
898 | static void dwarf2_find_base_address (struct die_info *die, |
899 | struct dwarf2_cu *cu); | |
900 | ||
c67a9c90 | 901 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 902 | |
72bf9492 DJ |
903 | static void scan_partial_symbols (struct partial_die_info *, |
904 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 905 | int, struct dwarf2_cu *); |
c906108c | 906 | |
72bf9492 DJ |
907 | static void add_partial_symbol (struct partial_die_info *, |
908 | struct dwarf2_cu *); | |
63d06c5c | 909 | |
72bf9492 DJ |
910 | static void add_partial_namespace (struct partial_die_info *pdi, |
911 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 912 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 913 | |
5d7cb8df JK |
914 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
915 | CORE_ADDR *highpc, int need_pc, | |
916 | struct dwarf2_cu *cu); | |
917 | ||
72bf9492 DJ |
918 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
919 | struct dwarf2_cu *cu); | |
91c24f0a | 920 | |
bc30ff58 JB |
921 | static void add_partial_subprogram (struct partial_die_info *pdi, |
922 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 923 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 924 | |
fe1b8b76 | 925 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
926 | gdb_byte *buffer, gdb_byte *info_ptr, |
927 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 928 | |
a14ed312 | 929 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 930 | |
a14ed312 | 931 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 932 | |
e7c27a73 | 933 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 934 | |
f3dd6933 | 935 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 936 | |
fe1b8b76 | 937 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 938 | struct dwarf2_cu *); |
72bf9492 | 939 | |
57349743 | 940 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 941 | struct dwarf2_cu *); |
c906108c | 942 | |
93311388 DE |
943 | static struct partial_die_info *load_partial_dies (bfd *, |
944 | gdb_byte *, gdb_byte *, | |
945 | int, struct dwarf2_cu *); | |
72bf9492 | 946 | |
fe1b8b76 | 947 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
948 | struct abbrev_info *abbrev, |
949 | unsigned int, bfd *, | |
950 | gdb_byte *, gdb_byte *, | |
951 | struct dwarf2_cu *); | |
c906108c | 952 | |
c764a876 | 953 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 954 | struct dwarf2_cu *); |
72bf9492 DJ |
955 | |
956 | static void fixup_partial_die (struct partial_die_info *, | |
957 | struct dwarf2_cu *); | |
958 | ||
fe1b8b76 JB |
959 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
960 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 961 | |
fe1b8b76 JB |
962 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
963 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 964 | |
fe1b8b76 | 965 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 966 | |
fe1b8b76 | 967 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 968 | |
fe1b8b76 | 969 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 970 | |
fe1b8b76 | 971 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 972 | |
93311388 | 973 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 974 | |
fe1b8b76 | 975 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 976 | unsigned int *); |
c906108c | 977 | |
c764a876 DE |
978 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
979 | ||
980 | static LONGEST read_checked_initial_length_and_offset | |
981 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
982 | unsigned int *, unsigned int *); | |
613e1657 | 983 | |
fe1b8b76 | 984 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
985 | unsigned int *); |
986 | ||
987 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 988 | |
fe1b8b76 | 989 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 990 | |
9b1c24c8 | 991 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 992 | |
fe1b8b76 JB |
993 | static char *read_indirect_string (bfd *, gdb_byte *, |
994 | const struct comp_unit_head *, | |
995 | unsigned int *); | |
4bdf3d34 | 996 | |
fe1b8b76 | 997 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 998 | |
fe1b8b76 | 999 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1000 | |
fe1b8b76 | 1001 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 1002 | |
e142c38c | 1003 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 1004 | |
e142c38c DJ |
1005 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
1006 | struct dwarf2_cu *); | |
c906108c | 1007 | |
348e048f DE |
1008 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
1009 | unsigned int, | |
1010 | struct dwarf2_cu *); | |
1011 | ||
05cf31d1 JB |
1012 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
1013 | struct dwarf2_cu *cu); | |
1014 | ||
e142c38c | 1015 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 1016 | |
e142c38c | 1017 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 1018 | struct dwarf2_cu **); |
63d06c5c | 1019 | |
debd256d JB |
1020 | static void free_line_header (struct line_header *lh); |
1021 | ||
aaa75496 JB |
1022 | static void add_file_name (struct line_header *, char *, unsigned int, |
1023 | unsigned int, unsigned int); | |
1024 | ||
debd256d JB |
1025 | static struct line_header *(dwarf_decode_line_header |
1026 | (unsigned int offset, | |
e7c27a73 | 1027 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d | 1028 | |
72b9f47f | 1029 | static void dwarf_decode_lines (struct line_header *, const char *, bfd *, |
aaa75496 | 1030 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 1031 | |
72b9f47f | 1032 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 1033 | |
a14ed312 | 1034 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1035 | struct dwarf2_cu *); |
c906108c | 1036 | |
34eaf542 TT |
1037 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1038 | struct dwarf2_cu *, struct symbol *); | |
1039 | ||
a14ed312 | 1040 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1041 | struct dwarf2_cu *); |
c906108c | 1042 | |
98bfdba5 PA |
1043 | static void dwarf2_const_value_attr (struct attribute *attr, |
1044 | struct type *type, | |
1045 | const char *name, | |
1046 | struct obstack *obstack, | |
1047 | struct dwarf2_cu *cu, long *value, | |
1048 | gdb_byte **bytes, | |
1049 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1050 | |
e7c27a73 | 1051 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1052 | |
b4ba55a1 JB |
1053 | static int need_gnat_info (struct dwarf2_cu *); |
1054 | ||
3e43a32a MS |
1055 | static struct type *die_descriptive_type (struct die_info *, |
1056 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1057 | |
1058 | static void set_descriptive_type (struct type *, struct die_info *, | |
1059 | struct dwarf2_cu *); | |
1060 | ||
e7c27a73 DJ |
1061 | static struct type *die_containing_type (struct die_info *, |
1062 | struct dwarf2_cu *); | |
c906108c | 1063 | |
673bfd45 DE |
1064 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1065 | struct dwarf2_cu *); | |
c906108c | 1066 | |
f792889a | 1067 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1068 | |
673bfd45 DE |
1069 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1070 | ||
086ed43d | 1071 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1072 | |
6e70227d | 1073 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1074 | const char *suffix, int physname, |
1075 | struct dwarf2_cu *cu); | |
63d06c5c | 1076 | |
e7c27a73 | 1077 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1078 | |
348e048f DE |
1079 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1080 | ||
e7c27a73 | 1081 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1082 | |
e7c27a73 | 1083 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1084 | |
96408a79 SA |
1085 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1086 | ||
ff013f42 JK |
1087 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1088 | struct dwarf2_cu *, struct partial_symtab *); | |
1089 | ||
a14ed312 | 1090 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1091 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1092 | struct partial_symtab *); | |
c906108c | 1093 | |
fae299cd DC |
1094 | static void get_scope_pc_bounds (struct die_info *, |
1095 | CORE_ADDR *, CORE_ADDR *, | |
1096 | struct dwarf2_cu *); | |
1097 | ||
801e3a5b JB |
1098 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1099 | CORE_ADDR, struct dwarf2_cu *); | |
1100 | ||
a14ed312 | 1101 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1102 | struct dwarf2_cu *); |
c906108c | 1103 | |
a14ed312 | 1104 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1105 | struct type *, struct dwarf2_cu *); |
c906108c | 1106 | |
a14ed312 | 1107 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1108 | struct die_info *, struct type *, |
e7c27a73 | 1109 | struct dwarf2_cu *); |
c906108c | 1110 | |
a14ed312 | 1111 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1112 | struct type *, |
1113 | struct dwarf2_cu *); | |
c906108c | 1114 | |
134d01f1 | 1115 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1116 | |
e7c27a73 | 1117 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1118 | |
e7c27a73 | 1119 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1120 | |
5d7cb8df JK |
1121 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1122 | ||
27aa8d6a SW |
1123 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1124 | ||
f55ee35c JK |
1125 | static struct type *read_module_type (struct die_info *die, |
1126 | struct dwarf2_cu *cu); | |
1127 | ||
38d518c9 | 1128 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1129 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1130 | |
134d01f1 | 1131 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1132 | |
e7c27a73 | 1133 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1134 | |
6e70227d | 1135 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1136 | struct dwarf2_cu *); |
1137 | ||
93311388 | 1138 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1139 | |
93311388 DE |
1140 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1141 | gdb_byte *info_ptr, | |
d97bc12b DE |
1142 | gdb_byte **new_info_ptr, |
1143 | struct die_info *parent); | |
1144 | ||
93311388 DE |
1145 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1146 | gdb_byte *info_ptr, | |
fe1b8b76 | 1147 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1148 | struct die_info *parent); |
1149 | ||
93311388 DE |
1150 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1151 | gdb_byte *info_ptr, | |
fe1b8b76 | 1152 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1153 | struct die_info *parent); |
1154 | ||
93311388 DE |
1155 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1156 | struct die_info **, gdb_byte *, | |
1157 | int *); | |
1158 | ||
e7c27a73 | 1159 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1160 | |
71c25dea TT |
1161 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1162 | struct obstack *); | |
1163 | ||
e142c38c | 1164 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1165 | |
98bfdba5 PA |
1166 | static const char *dwarf2_full_name (char *name, |
1167 | struct die_info *die, | |
1168 | struct dwarf2_cu *cu); | |
1169 | ||
e142c38c | 1170 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1171 | struct dwarf2_cu **); |
9219021c | 1172 | |
a14ed312 | 1173 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1174 | |
a14ed312 | 1175 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1176 | |
a14ed312 | 1177 | static char *dwarf_form_name (unsigned int); |
c906108c | 1178 | |
a14ed312 | 1179 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1180 | |
a14ed312 | 1181 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1182 | |
1183 | #if 0 | |
a14ed312 | 1184 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1185 | #endif |
1186 | ||
f9aca02d | 1187 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1188 | |
d97bc12b DE |
1189 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1190 | ||
1191 | static void dump_die_for_error (struct die_info *); | |
1192 | ||
1193 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1194 | struct die_info *); | |
c906108c | 1195 | |
d97bc12b | 1196 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1197 | |
51545339 | 1198 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1199 | struct dwarf2_cu *); |
c906108c | 1200 | |
93311388 DE |
1201 | static int is_ref_attr (struct attribute *); |
1202 | ||
c764a876 | 1203 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1204 | |
43bbcdc2 | 1205 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1206 | |
348e048f DE |
1207 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1208 | struct attribute *, | |
1209 | struct dwarf2_cu **); | |
1210 | ||
10b3939b DJ |
1211 | static struct die_info *follow_die_ref (struct die_info *, |
1212 | struct attribute *, | |
f2f0e013 | 1213 | struct dwarf2_cu **); |
c906108c | 1214 | |
348e048f DE |
1215 | static struct die_info *follow_die_sig (struct die_info *, |
1216 | struct attribute *, | |
1217 | struct dwarf2_cu **); | |
1218 | ||
6c83ed52 TT |
1219 | static struct signatured_type *lookup_signatured_type_at_offset |
1220 | (struct objfile *objfile, | |
1221 | struct dwarf2_section_info *section, | |
1222 | unsigned int offset); | |
1223 | ||
348e048f | 1224 | static void read_signatured_type_at_offset (struct objfile *objfile, |
8b70b953 | 1225 | struct dwarf2_section_info *sect, |
348e048f DE |
1226 | unsigned int offset); |
1227 | ||
1228 | static void read_signatured_type (struct objfile *, | |
1229 | struct signatured_type *type_sig); | |
1230 | ||
c906108c SS |
1231 | /* memory allocation interface */ |
1232 | ||
7b5a2f43 | 1233 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1234 | |
f3dd6933 | 1235 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1236 | |
b60c80d6 | 1237 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1238 | |
e142c38c | 1239 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1240 | |
e142c38c DJ |
1241 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1242 | struct dwarf2_cu *); | |
5fb290d7 | 1243 | |
2e276125 | 1244 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
cf2c3c16 TT |
1245 | char *, bfd *, struct dwarf2_cu *, |
1246 | struct dwarf2_section_info *, | |
1247 | int); | |
2e276125 | 1248 | |
8e19ed76 PS |
1249 | static int attr_form_is_block (struct attribute *); |
1250 | ||
3690dd37 JB |
1251 | static int attr_form_is_section_offset (struct attribute *); |
1252 | ||
1253 | static int attr_form_is_constant (struct attribute *); | |
1254 | ||
8cf6f0b1 TT |
1255 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1256 | struct dwarf2_loclist_baton *baton, | |
1257 | struct attribute *attr); | |
1258 | ||
93e7bd98 DJ |
1259 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1260 | struct symbol *sym, | |
1261 | struct dwarf2_cu *cu); | |
4c2df51b | 1262 | |
93311388 DE |
1263 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1264 | struct abbrev_info *abbrev, | |
1265 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1266 | |
72bf9492 DJ |
1267 | static void free_stack_comp_unit (void *); |
1268 | ||
72bf9492 DJ |
1269 | static hashval_t partial_die_hash (const void *item); |
1270 | ||
1271 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1272 | ||
ae038cb0 | 1273 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1274 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1275 | |
1276 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1277 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1278 | |
9816fde3 JK |
1279 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
1280 | struct objfile *objfile); | |
1281 | ||
1282 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1283 | struct die_info *comp_unit_die); | |
93311388 | 1284 | |
ae038cb0 DJ |
1285 | static void free_one_comp_unit (void *); |
1286 | ||
1287 | static void free_cached_comp_units (void *); | |
1288 | ||
1289 | static void age_cached_comp_units (void); | |
1290 | ||
1291 | static void free_one_cached_comp_unit (void *); | |
1292 | ||
f792889a DJ |
1293 | static struct type *set_die_type (struct die_info *, struct type *, |
1294 | struct dwarf2_cu *); | |
1c379e20 | 1295 | |
ae038cb0 DJ |
1296 | static void create_all_comp_units (struct objfile *); |
1297 | ||
1fd400ff TT |
1298 | static int create_debug_types_hash_table (struct objfile *objfile); |
1299 | ||
93311388 DE |
1300 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1301 | struct objfile *); | |
10b3939b DJ |
1302 | |
1303 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1304 | ||
1305 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1306 | struct dwarf2_per_cu_data *); | |
1307 | ||
ae038cb0 DJ |
1308 | static void dwarf2_mark (struct dwarf2_cu *); |
1309 | ||
1310 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1311 | ||
673bfd45 DE |
1312 | static struct type *get_die_type_at_offset (unsigned int, |
1313 | struct dwarf2_per_cu_data *per_cu); | |
1314 | ||
f792889a | 1315 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1316 | |
9291a0cd TT |
1317 | static void dwarf2_release_queue (void *dummy); |
1318 | ||
1319 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, | |
1320 | struct objfile *objfile); | |
1321 | ||
1322 | static void process_queue (struct objfile *objfile); | |
1323 | ||
1324 | static void find_file_and_directory (struct die_info *die, | |
1325 | struct dwarf2_cu *cu, | |
1326 | char **name, char **comp_dir); | |
1327 | ||
1328 | static char *file_full_name (int file, struct line_header *lh, | |
1329 | const char *comp_dir); | |
1330 | ||
1331 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, | |
1332 | gdb_byte *info_ptr, | |
1333 | gdb_byte *buffer, | |
1334 | unsigned int buffer_size, | |
1335 | bfd *abfd); | |
1336 | ||
1337 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1338 | struct dwarf2_cu *cu); | |
1339 | ||
673bfd45 | 1340 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1341 | |
9291a0cd TT |
1342 | #if WORDS_BIGENDIAN |
1343 | ||
1344 | /* Convert VALUE between big- and little-endian. */ | |
1345 | static offset_type | |
1346 | byte_swap (offset_type value) | |
1347 | { | |
1348 | offset_type result; | |
1349 | ||
1350 | result = (value & 0xff) << 24; | |
1351 | result |= (value & 0xff00) << 8; | |
1352 | result |= (value & 0xff0000) >> 8; | |
1353 | result |= (value & 0xff000000) >> 24; | |
1354 | return result; | |
1355 | } | |
1356 | ||
1357 | #define MAYBE_SWAP(V) byte_swap (V) | |
1358 | ||
1359 | #else | |
1360 | #define MAYBE_SWAP(V) (V) | |
1361 | #endif /* WORDS_BIGENDIAN */ | |
1362 | ||
1363 | /* The suffix for an index file. */ | |
1364 | #define INDEX_SUFFIX ".gdb-index" | |
1365 | ||
3da10d80 KS |
1366 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1367 | struct dwarf2_cu *cu); | |
1368 | ||
c906108c | 1369 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1370 | information and return true if we have enough to do something. |
1371 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1372 | ELF names are used. */ | |
c906108c SS |
1373 | |
1374 | int | |
251d32d9 TG |
1375 | dwarf2_has_info (struct objfile *objfile, |
1376 | const struct dwarf2_debug_sections *names) | |
c906108c | 1377 | { |
be391dca TT |
1378 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1379 | if (!dwarf2_per_objfile) | |
1380 | { | |
1381 | /* Initialize per-objfile state. */ | |
1382 | struct dwarf2_per_objfile *data | |
1383 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1384 | |
be391dca TT |
1385 | memset (data, 0, sizeof (*data)); |
1386 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1387 | dwarf2_per_objfile = data; | |
6502dd73 | 1388 | |
251d32d9 TG |
1389 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1390 | (void *) names); | |
be391dca TT |
1391 | dwarf2_per_objfile->objfile = objfile; |
1392 | } | |
1393 | return (dwarf2_per_objfile->info.asection != NULL | |
1394 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1395 | } |
1396 | ||
251d32d9 TG |
1397 | /* When loading sections, we look either for uncompressed section or for |
1398 | compressed section names. */ | |
233a11ab CS |
1399 | |
1400 | static int | |
251d32d9 TG |
1401 | section_is_p (const char *section_name, |
1402 | const struct dwarf2_section_names *names) | |
233a11ab | 1403 | { |
251d32d9 TG |
1404 | if (names->normal != NULL |
1405 | && strcmp (section_name, names->normal) == 0) | |
1406 | return 1; | |
1407 | if (names->compressed != NULL | |
1408 | && strcmp (section_name, names->compressed) == 0) | |
1409 | return 1; | |
1410 | return 0; | |
233a11ab CS |
1411 | } |
1412 | ||
c906108c SS |
1413 | /* This function is mapped across the sections and remembers the |
1414 | offset and size of each of the debugging sections we are interested | |
1415 | in. */ | |
1416 | ||
1417 | static void | |
251d32d9 | 1418 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1419 | { |
251d32d9 TG |
1420 | const struct dwarf2_debug_sections *names; |
1421 | ||
1422 | if (vnames == NULL) | |
1423 | names = &dwarf2_elf_names; | |
1424 | else | |
1425 | names = (const struct dwarf2_debug_sections *) vnames; | |
1426 | ||
1427 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1428 | { |
dce234bc PP |
1429 | dwarf2_per_objfile->info.asection = sectp; |
1430 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1431 | } |
251d32d9 | 1432 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1433 | { |
dce234bc PP |
1434 | dwarf2_per_objfile->abbrev.asection = sectp; |
1435 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1436 | } |
251d32d9 | 1437 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1438 | { |
dce234bc PP |
1439 | dwarf2_per_objfile->line.asection = sectp; |
1440 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1441 | } |
251d32d9 | 1442 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1443 | { |
dce234bc PP |
1444 | dwarf2_per_objfile->loc.asection = sectp; |
1445 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1446 | } |
251d32d9 | 1447 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1448 | { |
dce234bc PP |
1449 | dwarf2_per_objfile->macinfo.asection = sectp; |
1450 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1451 | } |
cf2c3c16 TT |
1452 | else if (section_is_p (sectp->name, &names->macro)) |
1453 | { | |
1454 | dwarf2_per_objfile->macro.asection = sectp; | |
1455 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1456 | } | |
251d32d9 | 1457 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1458 | { |
dce234bc PP |
1459 | dwarf2_per_objfile->str.asection = sectp; |
1460 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1461 | } |
251d32d9 | 1462 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1463 | { |
dce234bc PP |
1464 | dwarf2_per_objfile->frame.asection = sectp; |
1465 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1466 | } |
251d32d9 | 1467 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1468 | { |
3799ccc6 | 1469 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1470 | |
3799ccc6 EZ |
1471 | if (aflag & SEC_HAS_CONTENTS) |
1472 | { | |
dce234bc PP |
1473 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1474 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1475 | } |
b6af0555 | 1476 | } |
251d32d9 | 1477 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1478 | { |
dce234bc PP |
1479 | dwarf2_per_objfile->ranges.asection = sectp; |
1480 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1481 | } |
251d32d9 | 1482 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1483 | { |
8b70b953 TT |
1484 | struct dwarf2_section_info type_section; |
1485 | ||
1486 | memset (&type_section, 0, sizeof (type_section)); | |
1487 | type_section.asection = sectp; | |
1488 | type_section.size = bfd_get_section_size (sectp); | |
1489 | ||
1490 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1491 | &type_section); | |
348e048f | 1492 | } |
251d32d9 | 1493 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1494 | { |
1495 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1496 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1497 | } | |
dce234bc | 1498 | |
72dca2f5 FR |
1499 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1500 | && bfd_section_vma (abfd, sectp) == 0) | |
1501 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1502 | } |
1503 | ||
dce234bc PP |
1504 | /* Decompress a section that was compressed using zlib. Store the |
1505 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1506 | |
1507 | static void | |
dce234bc PP |
1508 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1509 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1510 | { | |
1511 | bfd *abfd = objfile->obfd; | |
1512 | #ifndef HAVE_ZLIB_H | |
1513 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1514 | "is disabled in this copy of GDB"), | |
1515 | bfd_get_filename (abfd)); | |
1516 | #else | |
1517 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1518 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1519 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1520 | bfd_size_type uncompressed_size; |
1521 | gdb_byte *uncompressed_buffer; | |
1522 | z_stream strm; | |
1523 | int rc; | |
1524 | int header_size = 12; | |
1525 | ||
1526 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1527 | || bfd_bread (compressed_buffer, |
1528 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1529 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1530 | bfd_get_filename (abfd)); | |
1531 | ||
1532 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1533 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1534 | if (compressed_size < header_size | |
1535 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1536 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1537 | bfd_get_filename (abfd)); | |
1538 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1539 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1540 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1541 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1542 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1543 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1544 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1545 | uncompressed_size += compressed_buffer[11]; | |
1546 | ||
1547 | /* It is possible the section consists of several compressed | |
1548 | buffers concatenated together, so we uncompress in a loop. */ | |
1549 | strm.zalloc = NULL; | |
1550 | strm.zfree = NULL; | |
1551 | strm.opaque = NULL; | |
1552 | strm.avail_in = compressed_size - header_size; | |
1553 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1554 | strm.avail_out = uncompressed_size; | |
1555 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1556 | uncompressed_size); | |
1557 | rc = inflateInit (&strm); | |
1558 | while (strm.avail_in > 0) | |
1559 | { | |
1560 | if (rc != Z_OK) | |
1561 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1562 | bfd_get_filename (abfd), rc); | |
1563 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1564 | + (uncompressed_size - strm.avail_out)); | |
1565 | rc = inflate (&strm, Z_FINISH); | |
1566 | if (rc != Z_STREAM_END) | |
1567 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1568 | bfd_get_filename (abfd), rc); | |
1569 | rc = inflateReset (&strm); | |
1570 | } | |
1571 | rc = inflateEnd (&strm); | |
1572 | if (rc != Z_OK | |
1573 | || strm.avail_out != 0) | |
1574 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1575 | bfd_get_filename (abfd), rc); | |
1576 | ||
affddf13 | 1577 | do_cleanups (cleanup); |
dce234bc PP |
1578 | *outbuf = uncompressed_buffer; |
1579 | *outsize = uncompressed_size; | |
1580 | #endif | |
233a11ab CS |
1581 | } |
1582 | ||
9e0ac564 TT |
1583 | /* A helper function that decides whether a section is empty. */ |
1584 | ||
1585 | static int | |
1586 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1587 | { | |
1588 | return info->asection == NULL || info->size == 0; | |
1589 | } | |
1590 | ||
dce234bc PP |
1591 | /* Read the contents of the section SECTP from object file specified by |
1592 | OBJFILE, store info about the section into INFO. | |
1593 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1594 | |
dce234bc PP |
1595 | static void |
1596 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1597 | { |
dce234bc PP |
1598 | bfd *abfd = objfile->obfd; |
1599 | asection *sectp = info->asection; | |
1600 | gdb_byte *buf, *retbuf; | |
1601 | unsigned char header[4]; | |
c906108c | 1602 | |
be391dca TT |
1603 | if (info->readin) |
1604 | return; | |
dce234bc | 1605 | info->buffer = NULL; |
b315ab21 | 1606 | info->map_addr = NULL; |
be391dca | 1607 | info->readin = 1; |
188dd5d6 | 1608 | |
9e0ac564 | 1609 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1610 | return; |
c906108c | 1611 | |
dce234bc PP |
1612 | /* Check if the file has a 4-byte header indicating compression. */ |
1613 | if (info->size > sizeof (header) | |
1614 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1615 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1616 | { | |
1617 | /* Upon decompression, update the buffer and its size. */ | |
1618 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1619 | { | |
1620 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1621 | &info->size); | |
1622 | return; | |
1623 | } | |
1624 | } | |
4bdf3d34 | 1625 | |
dce234bc PP |
1626 | #ifdef HAVE_MMAP |
1627 | if (pagesize == 0) | |
1628 | pagesize = getpagesize (); | |
2e276125 | 1629 | |
dce234bc PP |
1630 | /* Only try to mmap sections which are large enough: we don't want to |
1631 | waste space due to fragmentation. Also, only try mmap for sections | |
1632 | without relocations. */ | |
1633 | ||
1634 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1635 | { | |
b315ab21 TG |
1636 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1637 | MAP_PRIVATE, sectp->filepos, | |
1638 | &info->map_addr, &info->map_len); | |
dce234bc | 1639 | |
b315ab21 | 1640 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1641 | { |
be391dca | 1642 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1643 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1644 | #endif |
dce234bc PP |
1645 | return; |
1646 | } | |
1647 | } | |
1648 | #endif | |
1649 | ||
1650 | /* If we get here, we are a normal, not-compressed section. */ | |
1651 | info->buffer = buf | |
1652 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1653 | ||
1654 | /* When debugging .o files, we may need to apply relocations; see | |
1655 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1656 | We never compress sections in .o files, so we only need to | |
1657 | try this when the section is not compressed. */ | |
ac8035ab | 1658 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1659 | if (retbuf != NULL) |
1660 | { | |
1661 | info->buffer = retbuf; | |
1662 | return; | |
1663 | } | |
1664 | ||
1665 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1666 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1667 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1668 | bfd_get_filename (abfd)); | |
1669 | } | |
1670 | ||
9e0ac564 TT |
1671 | /* A helper function that returns the size of a section in a safe way. |
1672 | If you are positive that the section has been read before using the | |
1673 | size, then it is safe to refer to the dwarf2_section_info object's | |
1674 | "size" field directly. In other cases, you must call this | |
1675 | function, because for compressed sections the size field is not set | |
1676 | correctly until the section has been read. */ | |
1677 | ||
1678 | static bfd_size_type | |
1679 | dwarf2_section_size (struct objfile *objfile, | |
1680 | struct dwarf2_section_info *info) | |
1681 | { | |
1682 | if (!info->readin) | |
1683 | dwarf2_read_section (objfile, info); | |
1684 | return info->size; | |
1685 | } | |
1686 | ||
dce234bc | 1687 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1688 | SECTION_NAME. */ |
af34e669 | 1689 | |
dce234bc | 1690 | void |
3017a003 TG |
1691 | dwarf2_get_section_info (struct objfile *objfile, |
1692 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1693 | asection **sectp, gdb_byte **bufp, |
1694 | bfd_size_type *sizep) | |
1695 | { | |
1696 | struct dwarf2_per_objfile *data | |
1697 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1698 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1699 | |
1700 | /* We may see an objfile without any DWARF, in which case we just | |
1701 | return nothing. */ | |
1702 | if (data == NULL) | |
1703 | { | |
1704 | *sectp = NULL; | |
1705 | *bufp = NULL; | |
1706 | *sizep = 0; | |
1707 | return; | |
1708 | } | |
3017a003 TG |
1709 | switch (sect) |
1710 | { | |
1711 | case DWARF2_DEBUG_FRAME: | |
1712 | info = &data->frame; | |
1713 | break; | |
1714 | case DWARF2_EH_FRAME: | |
1715 | info = &data->eh_frame; | |
1716 | break; | |
1717 | default: | |
1718 | gdb_assert_not_reached ("unexpected section"); | |
1719 | } | |
dce234bc | 1720 | |
9e0ac564 | 1721 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1722 | |
1723 | *sectp = info->asection; | |
1724 | *bufp = info->buffer; | |
1725 | *sizep = info->size; | |
1726 | } | |
1727 | ||
9291a0cd | 1728 | \f |
7b9f3c50 DE |
1729 | /* DWARF quick_symbols_functions support. */ |
1730 | ||
1731 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1732 | unique line tables, so we maintain a separate table of all .debug_line | |
1733 | derived entries to support the sharing. | |
1734 | All the quick functions need is the list of file names. We discard the | |
1735 | line_header when we're done and don't need to record it here. */ | |
1736 | struct quick_file_names | |
1737 | { | |
1738 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1739 | unsigned int offset; | |
1740 | ||
1741 | /* The number of entries in file_names, real_names. */ | |
1742 | unsigned int num_file_names; | |
1743 | ||
1744 | /* The file names from the line table, after being run through | |
1745 | file_full_name. */ | |
1746 | const char **file_names; | |
1747 | ||
1748 | /* The file names from the line table after being run through | |
1749 | gdb_realpath. These are computed lazily. */ | |
1750 | const char **real_names; | |
1751 | }; | |
1752 | ||
1753 | /* When using the index (and thus not using psymtabs), each CU has an | |
1754 | object of this type. This is used to hold information needed by | |
1755 | the various "quick" methods. */ | |
1756 | struct dwarf2_per_cu_quick_data | |
1757 | { | |
1758 | /* The file table. This can be NULL if there was no file table | |
1759 | or it's currently not read in. | |
1760 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1761 | struct quick_file_names *file_names; | |
1762 | ||
1763 | /* The corresponding symbol table. This is NULL if symbols for this | |
1764 | CU have not yet been read. */ | |
1765 | struct symtab *symtab; | |
1766 | ||
1767 | /* A temporary mark bit used when iterating over all CUs in | |
1768 | expand_symtabs_matching. */ | |
1769 | unsigned int mark : 1; | |
1770 | ||
1771 | /* True if we've tried to read the file table and found there isn't one. | |
1772 | There will be no point in trying to read it again next time. */ | |
1773 | unsigned int no_file_data : 1; | |
1774 | }; | |
1775 | ||
1776 | /* Hash function for a quick_file_names. */ | |
1777 | ||
1778 | static hashval_t | |
1779 | hash_file_name_entry (const void *e) | |
1780 | { | |
1781 | const struct quick_file_names *file_data = e; | |
1782 | ||
1783 | return file_data->offset; | |
1784 | } | |
1785 | ||
1786 | /* Equality function for a quick_file_names. */ | |
1787 | ||
1788 | static int | |
1789 | eq_file_name_entry (const void *a, const void *b) | |
1790 | { | |
1791 | const struct quick_file_names *ea = a; | |
1792 | const struct quick_file_names *eb = b; | |
1793 | ||
1794 | return ea->offset == eb->offset; | |
1795 | } | |
1796 | ||
1797 | /* Delete function for a quick_file_names. */ | |
1798 | ||
1799 | static void | |
1800 | delete_file_name_entry (void *e) | |
1801 | { | |
1802 | struct quick_file_names *file_data = e; | |
1803 | int i; | |
1804 | ||
1805 | for (i = 0; i < file_data->num_file_names; ++i) | |
1806 | { | |
1807 | xfree ((void*) file_data->file_names[i]); | |
1808 | if (file_data->real_names) | |
1809 | xfree ((void*) file_data->real_names[i]); | |
1810 | } | |
1811 | ||
1812 | /* The space for the struct itself lives on objfile_obstack, | |
1813 | so we don't free it here. */ | |
1814 | } | |
1815 | ||
1816 | /* Create a quick_file_names hash table. */ | |
1817 | ||
1818 | static htab_t | |
1819 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1820 | { | |
1821 | return htab_create_alloc (nr_initial_entries, | |
1822 | hash_file_name_entry, eq_file_name_entry, | |
1823 | delete_file_name_entry, xcalloc, xfree); | |
1824 | } | |
9291a0cd | 1825 | |
918dd910 JK |
1826 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1827 | have to be created afterwards. You should call age_cached_comp_units after | |
1828 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1829 | ||
1830 | static void | |
1831 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1832 | { | |
8b70b953 TT |
1833 | if (per_cu->debug_type_section) |
1834 | read_signatured_type_at_offset (per_cu->objfile, | |
1835 | per_cu->debug_type_section, | |
1836 | per_cu->offset); | |
918dd910 JK |
1837 | else |
1838 | load_full_comp_unit (per_cu, per_cu->objfile); | |
1839 | ||
1840 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
1841 | ||
1842 | gdb_assert (per_cu->cu != NULL); | |
1843 | } | |
1844 | ||
9291a0cd TT |
1845 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which |
1846 | this CU came. */ | |
2fdf6df6 | 1847 | |
9291a0cd TT |
1848 | static void |
1849 | dw2_do_instantiate_symtab (struct objfile *objfile, | |
1850 | struct dwarf2_per_cu_data *per_cu) | |
1851 | { | |
1852 | struct cleanup *back_to; | |
1853 | ||
1854 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1855 | ||
1856 | queue_comp_unit (per_cu, objfile); | |
1857 | ||
918dd910 | 1858 | load_cu (per_cu); |
9291a0cd TT |
1859 | |
1860 | process_queue (objfile); | |
1861 | ||
1862 | /* Age the cache, releasing compilation units that have not | |
1863 | been used recently. */ | |
1864 | age_cached_comp_units (); | |
1865 | ||
1866 | do_cleanups (back_to); | |
1867 | } | |
1868 | ||
1869 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1870 | the objfile from which this CU came. Returns the resulting symbol | |
1871 | table. */ | |
2fdf6df6 | 1872 | |
9291a0cd TT |
1873 | static struct symtab * |
1874 | dw2_instantiate_symtab (struct objfile *objfile, | |
1875 | struct dwarf2_per_cu_data *per_cu) | |
1876 | { | |
1877 | if (!per_cu->v.quick->symtab) | |
1878 | { | |
1879 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1880 | increment_reading_symtab (); | |
1881 | dw2_do_instantiate_symtab (objfile, per_cu); | |
1882 | do_cleanups (back_to); | |
1883 | } | |
1884 | return per_cu->v.quick->symtab; | |
1885 | } | |
1886 | ||
1fd400ff | 1887 | /* Return the CU given its index. */ |
2fdf6df6 | 1888 | |
1fd400ff TT |
1889 | static struct dwarf2_per_cu_data * |
1890 | dw2_get_cu (int index) | |
1891 | { | |
1892 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1893 | { | |
1894 | index -= dwarf2_per_objfile->n_comp_units; | |
1895 | return dwarf2_per_objfile->type_comp_units[index]; | |
1896 | } | |
1897 | return dwarf2_per_objfile->all_comp_units[index]; | |
1898 | } | |
1899 | ||
9291a0cd TT |
1900 | /* A helper function that knows how to read a 64-bit value in a way |
1901 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1902 | otherwise. */ | |
2fdf6df6 | 1903 | |
9291a0cd TT |
1904 | static int |
1905 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1906 | { | |
1907 | if (sizeof (ULONGEST) < 8) | |
1908 | { | |
1909 | int i; | |
1910 | ||
1911 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1912 | for (i = 0; i < 4; ++i) | |
1913 | if (bytes[i + 4] != 0) | |
1914 | return 0; | |
1915 | ||
1916 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1917 | } | |
1918 | else | |
1919 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1920 | return 1; | |
1921 | } | |
1922 | ||
1923 | /* Read the CU list from the mapped index, and use it to create all | |
1924 | the CU objects for this objfile. Return 0 if something went wrong, | |
1925 | 1 if everything went ok. */ | |
2fdf6df6 | 1926 | |
9291a0cd | 1927 | static int |
1fd400ff TT |
1928 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1929 | offset_type cu_list_elements) | |
9291a0cd TT |
1930 | { |
1931 | offset_type i; | |
9291a0cd TT |
1932 | |
1933 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1934 | dwarf2_per_objfile->all_comp_units | |
1935 | = obstack_alloc (&objfile->objfile_obstack, | |
1936 | dwarf2_per_objfile->n_comp_units | |
1937 | * sizeof (struct dwarf2_per_cu_data *)); | |
1938 | ||
1939 | for (i = 0; i < cu_list_elements; i += 2) | |
1940 | { | |
1941 | struct dwarf2_per_cu_data *the_cu; | |
1942 | ULONGEST offset, length; | |
1943 | ||
1944 | if (!extract_cu_value (cu_list, &offset) | |
1945 | || !extract_cu_value (cu_list + 8, &length)) | |
1946 | return 0; | |
1947 | cu_list += 2 * 8; | |
1948 | ||
1949 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1950 | struct dwarf2_per_cu_data); | |
1951 | the_cu->offset = offset; | |
1952 | the_cu->length = length; | |
1953 | the_cu->objfile = objfile; | |
1954 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1955 | struct dwarf2_per_cu_quick_data); | |
1956 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1957 | } | |
1958 | ||
1959 | return 1; | |
1960 | } | |
1961 | ||
1fd400ff | 1962 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1963 | |
1fd400ff | 1964 | static int |
673bfd45 | 1965 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 1966 | struct dwarf2_section_info *section, |
673bfd45 DE |
1967 | const gdb_byte *bytes, |
1968 | offset_type elements) | |
1fd400ff TT |
1969 | { |
1970 | offset_type i; | |
673bfd45 | 1971 | htab_t sig_types_hash; |
1fd400ff TT |
1972 | |
1973 | dwarf2_per_objfile->n_type_comp_units = elements / 3; | |
1974 | dwarf2_per_objfile->type_comp_units | |
1975 | = obstack_alloc (&objfile->objfile_obstack, | |
1976 | dwarf2_per_objfile->n_type_comp_units | |
1977 | * sizeof (struct dwarf2_per_cu_data *)); | |
1978 | ||
673bfd45 | 1979 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1980 | |
1981 | for (i = 0; i < elements; i += 3) | |
1982 | { | |
1983 | struct signatured_type *type_sig; | |
1984 | ULONGEST offset, type_offset, signature; | |
1985 | void **slot; | |
1986 | ||
1987 | if (!extract_cu_value (bytes, &offset) | |
1988 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1989 | return 0; | |
1990 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1991 | bytes += 3 * 8; | |
1992 | ||
1993 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1994 | struct signatured_type); | |
1995 | type_sig->signature = signature; | |
1fd400ff | 1996 | type_sig->type_offset = type_offset; |
8b70b953 | 1997 | type_sig->per_cu.debug_type_section = section; |
1fd400ff TT |
1998 | type_sig->per_cu.offset = offset; |
1999 | type_sig->per_cu.objfile = objfile; | |
2000 | type_sig->per_cu.v.quick | |
2001 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
2002 | struct dwarf2_per_cu_quick_data); | |
2003 | ||
673bfd45 | 2004 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
2005 | *slot = type_sig; |
2006 | ||
2007 | dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu; | |
2008 | } | |
2009 | ||
673bfd45 | 2010 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
2011 | |
2012 | return 1; | |
2013 | } | |
2014 | ||
9291a0cd TT |
2015 | /* Read the address map data from the mapped index, and use it to |
2016 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 2017 | |
9291a0cd TT |
2018 | static void |
2019 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
2020 | { | |
2021 | const gdb_byte *iter, *end; | |
2022 | struct obstack temp_obstack; | |
2023 | struct addrmap *mutable_map; | |
2024 | struct cleanup *cleanup; | |
2025 | CORE_ADDR baseaddr; | |
2026 | ||
2027 | obstack_init (&temp_obstack); | |
2028 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
2029 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
2030 | ||
2031 | iter = index->address_table; | |
2032 | end = iter + index->address_table_size; | |
2033 | ||
2034 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2035 | ||
2036 | while (iter < end) | |
2037 | { | |
2038 | ULONGEST hi, lo, cu_index; | |
2039 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2040 | iter += 8; | |
2041 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2042 | iter += 8; | |
2043 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
2044 | iter += 4; | |
2045 | ||
2046 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 2047 | dw2_get_cu (cu_index)); |
9291a0cd TT |
2048 | } |
2049 | ||
2050 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
2051 | &objfile->objfile_obstack); | |
2052 | do_cleanups (cleanup); | |
2053 | } | |
2054 | ||
59d7bcaf JK |
2055 | /* The hash function for strings in the mapped index. This is the same as |
2056 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
2057 | implementation. This is necessary because the hash function is tied to the | |
2058 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2059 | SYMBOL_HASH_NEXT. |
2060 | ||
2061 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2062 | |
9291a0cd | 2063 | static hashval_t |
559a7a62 | 2064 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2065 | { |
2066 | const unsigned char *str = (const unsigned char *) p; | |
2067 | hashval_t r = 0; | |
2068 | unsigned char c; | |
2069 | ||
2070 | while ((c = *str++) != 0) | |
559a7a62 JK |
2071 | { |
2072 | if (index_version >= 5) | |
2073 | c = tolower (c); | |
2074 | r = r * 67 + c - 113; | |
2075 | } | |
9291a0cd TT |
2076 | |
2077 | return r; | |
2078 | } | |
2079 | ||
2080 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2081 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2082 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2083 | |
9291a0cd TT |
2084 | static int |
2085 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2086 | offset_type **vec_out) | |
2087 | { | |
0cf03b49 JK |
2088 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2089 | offset_type hash; | |
9291a0cd | 2090 | offset_type slot, step; |
559a7a62 | 2091 | int (*cmp) (const char *, const char *); |
9291a0cd | 2092 | |
0cf03b49 JK |
2093 | if (current_language->la_language == language_cplus |
2094 | || current_language->la_language == language_java | |
2095 | || current_language->la_language == language_fortran) | |
2096 | { | |
2097 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2098 | not contain any. */ | |
2099 | const char *paren = strchr (name, '('); | |
2100 | ||
2101 | if (paren) | |
2102 | { | |
2103 | char *dup; | |
2104 | ||
2105 | dup = xmalloc (paren - name + 1); | |
2106 | memcpy (dup, name, paren - name); | |
2107 | dup[paren - name] = 0; | |
2108 | ||
2109 | make_cleanup (xfree, dup); | |
2110 | name = dup; | |
2111 | } | |
2112 | } | |
2113 | ||
559a7a62 JK |
2114 | /* Index version 4 did not support case insensitive searches. But the |
2115 | indexes for case insensitive languages are built in lowercase, therefore | |
2116 | simulate our NAME being searched is also lowercased. */ | |
2117 | hash = mapped_index_string_hash ((index->version == 4 | |
2118 | && case_sensitivity == case_sensitive_off | |
2119 | ? 5 : index->version), | |
2120 | name); | |
2121 | ||
3876f04e DE |
2122 | slot = hash & (index->symbol_table_slots - 1); |
2123 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2124 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2125 | |
2126 | for (;;) | |
2127 | { | |
2128 | /* Convert a slot number to an offset into the table. */ | |
2129 | offset_type i = 2 * slot; | |
2130 | const char *str; | |
3876f04e | 2131 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2132 | { |
2133 | do_cleanups (back_to); | |
2134 | return 0; | |
2135 | } | |
9291a0cd | 2136 | |
3876f04e | 2137 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2138 | if (!cmp (name, str)) |
9291a0cd TT |
2139 | { |
2140 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2141 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2142 | do_cleanups (back_to); |
9291a0cd TT |
2143 | return 1; |
2144 | } | |
2145 | ||
3876f04e | 2146 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2147 | } |
2148 | } | |
2149 | ||
2150 | /* Read the index file. If everything went ok, initialize the "quick" | |
2151 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2152 | |
9291a0cd TT |
2153 | static int |
2154 | dwarf2_read_index (struct objfile *objfile) | |
2155 | { | |
9291a0cd TT |
2156 | char *addr; |
2157 | struct mapped_index *map; | |
b3b272e1 | 2158 | offset_type *metadata; |
ac0b195c KW |
2159 | const gdb_byte *cu_list; |
2160 | const gdb_byte *types_list = NULL; | |
2161 | offset_type version, cu_list_elements; | |
2162 | offset_type types_list_elements = 0; | |
1fd400ff | 2163 | int i; |
9291a0cd | 2164 | |
9e0ac564 | 2165 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2166 | return 0; |
82430852 JK |
2167 | |
2168 | /* Older elfutils strip versions could keep the section in the main | |
2169 | executable while splitting it for the separate debug info file. */ | |
2170 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2171 | & SEC_HAS_CONTENTS) == 0) | |
2172 | return 0; | |
2173 | ||
9291a0cd TT |
2174 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2175 | ||
2176 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2177 | /* Version check. */ | |
1fd400ff | 2178 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2179 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2180 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2181 | contained incomplete addrmap. So, it seems better to just ignore such |
559a7a62 JK |
2182 | indices. Index version 4 uses a different hash function than index |
2183 | version 5 and later. */ | |
831adc1f | 2184 | if (version < 4) |
9291a0cd | 2185 | return 0; |
594e8718 JK |
2186 | /* Indexes with higher version than the one supported by GDB may be no |
2187 | longer backward compatible. */ | |
559a7a62 | 2188 | if (version > 5) |
594e8718 | 2189 | return 0; |
9291a0cd TT |
2190 | |
2191 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2192 | map->version = version; |
b3b272e1 | 2193 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2194 | |
2195 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2196 | |
2197 | i = 0; | |
2198 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2199 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2200 | / 8); |
1fd400ff TT |
2201 | ++i; |
2202 | ||
987d643c TT |
2203 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2204 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2205 | - MAYBE_SWAP (metadata[i])) | |
2206 | / 8); | |
2207 | ++i; | |
1fd400ff TT |
2208 | |
2209 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2210 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2211 | - MAYBE_SWAP (metadata[i])); | |
2212 | ++i; | |
2213 | ||
3876f04e DE |
2214 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2215 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2216 | - MAYBE_SWAP (metadata[i])) | |
2217 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2218 | ++i; |
9291a0cd | 2219 | |
1fd400ff TT |
2220 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2221 | ||
2222 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
2223 | return 0; | |
2224 | ||
8b70b953 TT |
2225 | if (types_list_elements) |
2226 | { | |
2227 | struct dwarf2_section_info *section; | |
2228 | ||
2229 | /* We can only handle a single .debug_types when we have an | |
2230 | index. */ | |
2231 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2232 | return 0; | |
2233 | ||
2234 | section = VEC_index (dwarf2_section_info_def, | |
2235 | dwarf2_per_objfile->types, 0); | |
2236 | ||
2237 | if (!create_signatured_type_table_from_index (objfile, section, | |
2238 | types_list, | |
2239 | types_list_elements)) | |
2240 | return 0; | |
2241 | } | |
9291a0cd TT |
2242 | |
2243 | create_addrmap_from_index (objfile, map); | |
2244 | ||
2245 | dwarf2_per_objfile->index_table = map; | |
2246 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2247 | dwarf2_per_objfile->quick_file_names_table = |
2248 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2249 | |
2250 | return 1; | |
2251 | } | |
2252 | ||
2253 | /* A helper for the "quick" functions which sets the global | |
2254 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2255 | |
9291a0cd TT |
2256 | static void |
2257 | dw2_setup (struct objfile *objfile) | |
2258 | { | |
2259 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2260 | gdb_assert (dwarf2_per_objfile); | |
2261 | } | |
2262 | ||
2263 | /* A helper for the "quick" functions which attempts to read the line | |
2264 | table for THIS_CU. */ | |
2fdf6df6 | 2265 | |
7b9f3c50 DE |
2266 | static struct quick_file_names * |
2267 | dw2_get_file_names (struct objfile *objfile, | |
2268 | struct dwarf2_per_cu_data *this_cu) | |
9291a0cd TT |
2269 | { |
2270 | bfd *abfd = objfile->obfd; | |
7b9f3c50 | 2271 | struct line_header *lh; |
9291a0cd TT |
2272 | struct attribute *attr; |
2273 | struct cleanup *cleanups; | |
2274 | struct die_info *comp_unit_die; | |
36374493 | 2275 | struct dwarf2_section_info* sec; |
adabb602 | 2276 | gdb_byte *info_ptr, *buffer; |
9291a0cd TT |
2277 | int has_children, i; |
2278 | struct dwarf2_cu cu; | |
2279 | unsigned int bytes_read, buffer_size; | |
2280 | struct die_reader_specs reader_specs; | |
2281 | char *name, *comp_dir; | |
7b9f3c50 DE |
2282 | void **slot; |
2283 | struct quick_file_names *qfn; | |
2284 | unsigned int line_offset; | |
9291a0cd | 2285 | |
7b9f3c50 DE |
2286 | if (this_cu->v.quick->file_names != NULL) |
2287 | return this_cu->v.quick->file_names; | |
2288 | /* If we know there is no line data, no point in looking again. */ | |
2289 | if (this_cu->v.quick->no_file_data) | |
2290 | return NULL; | |
9291a0cd | 2291 | |
9816fde3 | 2292 | init_one_comp_unit (&cu, objfile); |
9291a0cd TT |
2293 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
2294 | ||
8b70b953 TT |
2295 | if (this_cu->debug_type_section) |
2296 | sec = this_cu->debug_type_section; | |
36374493 DE |
2297 | else |
2298 | sec = &dwarf2_per_objfile->info; | |
2299 | dwarf2_read_section (objfile, sec); | |
2300 | buffer_size = sec->size; | |
2301 | buffer = sec->buffer; | |
9291a0cd | 2302 | info_ptr = buffer + this_cu->offset; |
9291a0cd TT |
2303 | |
2304 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
2305 | buffer, buffer_size, | |
2306 | abfd); | |
2307 | ||
9291a0cd TT |
2308 | this_cu->cu = &cu; |
2309 | cu.per_cu = this_cu; | |
2310 | ||
2311 | dwarf2_read_abbrevs (abfd, &cu); | |
2312 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
2313 | ||
8b70b953 | 2314 | if (this_cu->debug_type_section) |
9291a0cd TT |
2315 | info_ptr += 8 /*signature*/ + cu.header.offset_size; |
2316 | init_cu_die_reader (&reader_specs, &cu); | |
e8e80198 MS |
2317 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
2318 | &has_children); | |
9291a0cd | 2319 | |
7b9f3c50 DE |
2320 | lh = NULL; |
2321 | slot = NULL; | |
2322 | line_offset = 0; | |
9291a0cd TT |
2323 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
2324 | if (attr) | |
2325 | { | |
7b9f3c50 DE |
2326 | struct quick_file_names find_entry; |
2327 | ||
2328 | line_offset = DW_UNSND (attr); | |
2329 | ||
2330 | /* We may have already read in this line header (TU line header sharing). | |
2331 | If we have we're done. */ | |
2332 | find_entry.offset = line_offset; | |
2333 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2334 | &find_entry, INSERT); | |
2335 | if (*slot != NULL) | |
2336 | { | |
2337 | do_cleanups (cleanups); | |
2338 | this_cu->v.quick->file_names = *slot; | |
2339 | return *slot; | |
2340 | } | |
2341 | ||
9291a0cd TT |
2342 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
2343 | } | |
2344 | if (lh == NULL) | |
2345 | { | |
2346 | do_cleanups (cleanups); | |
7b9f3c50 DE |
2347 | this_cu->v.quick->no_file_data = 1; |
2348 | return NULL; | |
9291a0cd TT |
2349 | } |
2350 | ||
7b9f3c50 DE |
2351 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2352 | qfn->offset = line_offset; | |
2353 | gdb_assert (slot != NULL); | |
2354 | *slot = qfn; | |
9291a0cd | 2355 | |
7b9f3c50 | 2356 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
9291a0cd | 2357 | |
7b9f3c50 DE |
2358 | qfn->num_file_names = lh->num_file_names; |
2359 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2360 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2361 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2362 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2363 | qfn->real_names = NULL; | |
9291a0cd | 2364 | |
7b9f3c50 | 2365 | free_line_header (lh); |
9291a0cd | 2366 | do_cleanups (cleanups); |
7b9f3c50 DE |
2367 | |
2368 | this_cu->v.quick->file_names = qfn; | |
2369 | return qfn; | |
9291a0cd TT |
2370 | } |
2371 | ||
2372 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2373 | real path for a given file name from the line table. */ |
2fdf6df6 | 2374 | |
9291a0cd | 2375 | static const char * |
7b9f3c50 DE |
2376 | dw2_get_real_path (struct objfile *objfile, |
2377 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2378 | { |
7b9f3c50 DE |
2379 | if (qfn->real_names == NULL) |
2380 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2381 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2382 | |
7b9f3c50 DE |
2383 | if (qfn->real_names[index] == NULL) |
2384 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2385 | |
7b9f3c50 | 2386 | return qfn->real_names[index]; |
9291a0cd TT |
2387 | } |
2388 | ||
2389 | static struct symtab * | |
2390 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2391 | { | |
2392 | int index; | |
ae2de4f8 | 2393 | |
9291a0cd TT |
2394 | dw2_setup (objfile); |
2395 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1fd400ff | 2396 | return dw2_instantiate_symtab (objfile, dw2_get_cu (index)); |
9291a0cd TT |
2397 | } |
2398 | ||
7b9f3c50 DE |
2399 | /* Traversal function for dw2_forget_cached_source_info. */ |
2400 | ||
2401 | static int | |
2402 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2403 | { |
7b9f3c50 | 2404 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2405 | |
7b9f3c50 | 2406 | if (file_data->real_names) |
9291a0cd | 2407 | { |
7b9f3c50 | 2408 | int i; |
9291a0cd | 2409 | |
7b9f3c50 | 2410 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2411 | { |
7b9f3c50 DE |
2412 | xfree ((void*) file_data->real_names[i]); |
2413 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2414 | } |
2415 | } | |
7b9f3c50 DE |
2416 | |
2417 | return 1; | |
2418 | } | |
2419 | ||
2420 | static void | |
2421 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2422 | { | |
2423 | dw2_setup (objfile); | |
2424 | ||
2425 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2426 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2427 | } |
2428 | ||
2429 | static int | |
2430 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
2431 | const char *full_path, const char *real_path, | |
2432 | struct symtab **result) | |
2433 | { | |
2434 | int i; | |
2435 | int check_basename = lbasename (name) == name; | |
2436 | struct dwarf2_per_cu_data *base_cu = NULL; | |
2437 | ||
2438 | dw2_setup (objfile); | |
ae2de4f8 | 2439 | |
1fd400ff TT |
2440 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2441 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2442 | { |
2443 | int j; | |
e254ef6a | 2444 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2445 | struct quick_file_names *file_data; |
9291a0cd | 2446 | |
e254ef6a | 2447 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2448 | continue; |
2449 | ||
7b9f3c50 DE |
2450 | file_data = dw2_get_file_names (objfile, per_cu); |
2451 | if (file_data == NULL) | |
9291a0cd TT |
2452 | continue; |
2453 | ||
7b9f3c50 | 2454 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2455 | { |
7b9f3c50 | 2456 | const char *this_name = file_data->file_names[j]; |
9291a0cd TT |
2457 | |
2458 | if (FILENAME_CMP (name, this_name) == 0) | |
2459 | { | |
e254ef6a | 2460 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2461 | return 1; |
2462 | } | |
2463 | ||
2464 | if (check_basename && ! base_cu | |
2465 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2466 | base_cu = per_cu; |
9291a0cd TT |
2467 | |
2468 | if (full_path != NULL) | |
2469 | { | |
7b9f3c50 DE |
2470 | const char *this_real_name = dw2_get_real_path (objfile, |
2471 | file_data, j); | |
9291a0cd | 2472 | |
7b9f3c50 DE |
2473 | if (this_real_name != NULL |
2474 | && FILENAME_CMP (full_path, this_real_name) == 0) | |
9291a0cd | 2475 | { |
e254ef6a | 2476 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2477 | return 1; |
2478 | } | |
2479 | } | |
2480 | ||
2481 | if (real_path != NULL) | |
2482 | { | |
7b9f3c50 DE |
2483 | const char *this_real_name = dw2_get_real_path (objfile, |
2484 | file_data, j); | |
9291a0cd | 2485 | |
7b9f3c50 DE |
2486 | if (this_real_name != NULL |
2487 | && FILENAME_CMP (real_path, this_real_name) == 0) | |
9291a0cd | 2488 | { |
74dd2ca6 DE |
2489 | *result = dw2_instantiate_symtab (objfile, per_cu); |
2490 | return 1; | |
9291a0cd TT |
2491 | } |
2492 | } | |
2493 | } | |
2494 | } | |
2495 | ||
2496 | if (base_cu) | |
2497 | { | |
2498 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2499 | return 1; | |
2500 | } | |
2501 | ||
2502 | return 0; | |
2503 | } | |
2504 | ||
2505 | static struct symtab * | |
2506 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2507 | const char *name, domain_enum domain) | |
2508 | { | |
774b6a14 | 2509 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2510 | instead. */ |
2511 | return NULL; | |
2512 | } | |
2513 | ||
2514 | /* A helper function that expands all symtabs that hold an object | |
2515 | named NAME. */ | |
2fdf6df6 | 2516 | |
9291a0cd TT |
2517 | static void |
2518 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2519 | { | |
2520 | dw2_setup (objfile); | |
2521 | ||
ae2de4f8 | 2522 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2523 | if (dwarf2_per_objfile->index_table) |
2524 | { | |
2525 | offset_type *vec; | |
2526 | ||
2527 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2528 | name, &vec)) | |
2529 | { | |
2530 | offset_type i, len = MAYBE_SWAP (*vec); | |
2531 | for (i = 0; i < len; ++i) | |
2532 | { | |
2533 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2534 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2535 | |
e254ef6a | 2536 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2537 | } |
2538 | } | |
2539 | } | |
2540 | } | |
2541 | ||
774b6a14 TT |
2542 | static void |
2543 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2544 | enum block_enum block_kind, const char *name, |
774b6a14 | 2545 | domain_enum domain) |
9291a0cd | 2546 | { |
774b6a14 | 2547 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2548 | } |
2549 | ||
2550 | static void | |
2551 | dw2_print_stats (struct objfile *objfile) | |
2552 | { | |
2553 | int i, count; | |
2554 | ||
2555 | dw2_setup (objfile); | |
2556 | count = 0; | |
1fd400ff TT |
2557 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2558 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2559 | { |
e254ef6a | 2560 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2561 | |
e254ef6a | 2562 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2563 | ++count; |
2564 | } | |
2565 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2566 | } | |
2567 | ||
2568 | static void | |
2569 | dw2_dump (struct objfile *objfile) | |
2570 | { | |
2571 | /* Nothing worth printing. */ | |
2572 | } | |
2573 | ||
2574 | static void | |
2575 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2576 | struct section_offsets *delta) | |
2577 | { | |
2578 | /* There's nothing to relocate here. */ | |
2579 | } | |
2580 | ||
2581 | static void | |
2582 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2583 | const char *func_name) | |
2584 | { | |
2585 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2586 | } | |
2587 | ||
2588 | static void | |
2589 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2590 | { | |
2591 | int i; | |
2592 | ||
2593 | dw2_setup (objfile); | |
1fd400ff TT |
2594 | |
2595 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2596 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2597 | { |
e254ef6a | 2598 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2599 | |
e254ef6a | 2600 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2601 | } |
2602 | } | |
2603 | ||
2604 | static void | |
2605 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2606 | const char *filename) | |
2607 | { | |
2608 | int i; | |
2609 | ||
2610 | dw2_setup (objfile); | |
d4637a04 DE |
2611 | |
2612 | /* We don't need to consider type units here. | |
2613 | This is only called for examining code, e.g. expand_line_sal. | |
2614 | There can be an order of magnitude (or more) more type units | |
2615 | than comp units, and we avoid them if we can. */ | |
2616 | ||
2617 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2618 | { |
2619 | int j; | |
e254ef6a | 2620 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2621 | struct quick_file_names *file_data; |
9291a0cd | 2622 | |
e254ef6a | 2623 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2624 | continue; |
2625 | ||
7b9f3c50 DE |
2626 | file_data = dw2_get_file_names (objfile, per_cu); |
2627 | if (file_data == NULL) | |
9291a0cd TT |
2628 | continue; |
2629 | ||
7b9f3c50 | 2630 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2631 | { |
7b9f3c50 | 2632 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2633 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2634 | { |
e254ef6a | 2635 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2636 | break; |
2637 | } | |
2638 | } | |
2639 | } | |
2640 | } | |
2641 | ||
dd786858 | 2642 | static const char * |
9291a0cd TT |
2643 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2644 | { | |
e254ef6a | 2645 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2646 | offset_type *vec; |
7b9f3c50 | 2647 | struct quick_file_names *file_data; |
9291a0cd TT |
2648 | |
2649 | dw2_setup (objfile); | |
2650 | ||
ae2de4f8 | 2651 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2652 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2653 | { |
2654 | struct symtab *s; | |
2655 | ||
2656 | ALL_OBJFILE_SYMTABS (objfile, s) | |
2657 | if (s->primary) | |
2658 | { | |
2659 | struct blockvector *bv = BLOCKVECTOR (s); | |
2660 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2661 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2662 | ||
2663 | if (sym) | |
2664 | return sym->symtab->filename; | |
2665 | } | |
2666 | return NULL; | |
2667 | } | |
9291a0cd TT |
2668 | |
2669 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2670 | name, &vec)) | |
2671 | return NULL; | |
2672 | ||
2673 | /* Note that this just looks at the very first one named NAME -- but | |
2674 | actually we are looking for a function. find_main_filename | |
2675 | should be rewritten so that it doesn't require a custom hook. It | |
2676 | could just use the ordinary symbol tables. */ | |
2677 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2678 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2679 | |
7b9f3c50 DE |
2680 | file_data = dw2_get_file_names (objfile, per_cu); |
2681 | if (file_data == NULL) | |
9291a0cd TT |
2682 | return NULL; |
2683 | ||
7b9f3c50 | 2684 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2685 | } |
2686 | ||
2687 | static void | |
40658b94 PH |
2688 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2689 | struct objfile *objfile, int global, | |
2690 | int (*callback) (struct block *, | |
2691 | struct symbol *, void *), | |
2edb89d3 JK |
2692 | void *data, symbol_compare_ftype *match, |
2693 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2694 | { |
40658b94 | 2695 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2696 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2697 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2698 | } |
2699 | ||
2700 | static void | |
2701 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2702 | int (*file_matcher) (const char *, void *), | |
2703 | int (*name_matcher) (const char *, void *), | |
8903c50d | 2704 | enum search_domain kind, |
9291a0cd TT |
2705 | void *data) |
2706 | { | |
2707 | int i; | |
2708 | offset_type iter; | |
4b5246aa | 2709 | struct mapped_index *index; |
9291a0cd TT |
2710 | |
2711 | dw2_setup (objfile); | |
ae2de4f8 DE |
2712 | |
2713 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2714 | if (!dwarf2_per_objfile->index_table) |
2715 | return; | |
4b5246aa | 2716 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2717 | |
7b08b9eb JK |
2718 | if (file_matcher != NULL) |
2719 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2720 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
2721 | { | |
2722 | int j; | |
2723 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2724 | struct quick_file_names *file_data; | |
2725 | ||
2726 | per_cu->v.quick->mark = 0; | |
2727 | if (per_cu->v.quick->symtab) | |
2728 | continue; | |
2729 | ||
2730 | file_data = dw2_get_file_names (objfile, per_cu); | |
2731 | if (file_data == NULL) | |
2732 | continue; | |
2733 | ||
2734 | for (j = 0; j < file_data->num_file_names; ++j) | |
2735 | { | |
2736 | if (file_matcher (file_data->file_names[j], data)) | |
2737 | { | |
2738 | per_cu->v.quick->mark = 1; | |
2739 | break; | |
2740 | } | |
2741 | } | |
2742 | } | |
9291a0cd | 2743 | |
3876f04e | 2744 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2745 | { |
2746 | offset_type idx = 2 * iter; | |
2747 | const char *name; | |
2748 | offset_type *vec, vec_len, vec_idx; | |
2749 | ||
3876f04e | 2750 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2751 | continue; |
2752 | ||
3876f04e | 2753 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd TT |
2754 | |
2755 | if (! (*name_matcher) (name, data)) | |
2756 | continue; | |
2757 | ||
2758 | /* The name was matched, now expand corresponding CUs that were | |
2759 | marked. */ | |
4b5246aa | 2760 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2761 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2762 | vec_len = MAYBE_SWAP (vec[0]); |
2763 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2764 | { | |
e254ef6a | 2765 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2766 | |
e254ef6a | 2767 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2768 | if (file_matcher == NULL || per_cu->v.quick->mark) |
e254ef6a | 2769 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2770 | } |
2771 | } | |
2772 | } | |
2773 | ||
2774 | static struct symtab * | |
2775 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2776 | struct minimal_symbol *msymbol, | |
2777 | CORE_ADDR pc, | |
2778 | struct obj_section *section, | |
2779 | int warn_if_readin) | |
2780 | { | |
2781 | struct dwarf2_per_cu_data *data; | |
2782 | ||
2783 | dw2_setup (objfile); | |
2784 | ||
2785 | if (!objfile->psymtabs_addrmap) | |
2786 | return NULL; | |
2787 | ||
2788 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2789 | if (!data) | |
2790 | return NULL; | |
2791 | ||
2792 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2793 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2794 | paddress (get_objfile_arch (objfile), pc)); |
2795 | ||
2796 | return dw2_instantiate_symtab (objfile, data); | |
2797 | } | |
2798 | ||
9291a0cd | 2799 | static void |
44b13c5a | 2800 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
9291a0cd TT |
2801 | void *data) |
2802 | { | |
2803 | int i; | |
2804 | ||
2805 | dw2_setup (objfile); | |
ae2de4f8 | 2806 | |
1fd400ff TT |
2807 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2808 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2809 | { |
2810 | int j; | |
e254ef6a | 2811 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2812 | struct quick_file_names *file_data; |
9291a0cd | 2813 | |
e254ef6a | 2814 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2815 | continue; |
2816 | ||
7b9f3c50 DE |
2817 | file_data = dw2_get_file_names (objfile, per_cu); |
2818 | if (file_data == NULL) | |
9291a0cd TT |
2819 | continue; |
2820 | ||
7b9f3c50 | 2821 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2822 | { |
7b9f3c50 DE |
2823 | const char *this_real_name = dw2_get_real_path (objfile, file_data, |
2824 | j); | |
2825 | (*fun) (file_data->file_names[j], this_real_name, data); | |
9291a0cd TT |
2826 | } |
2827 | } | |
2828 | } | |
2829 | ||
2830 | static int | |
2831 | dw2_has_symbols (struct objfile *objfile) | |
2832 | { | |
2833 | return 1; | |
2834 | } | |
2835 | ||
2836 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2837 | { | |
2838 | dw2_has_symbols, | |
2839 | dw2_find_last_source_symtab, | |
2840 | dw2_forget_cached_source_info, | |
2841 | dw2_lookup_symtab, | |
2842 | dw2_lookup_symbol, | |
774b6a14 | 2843 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2844 | dw2_print_stats, |
2845 | dw2_dump, | |
2846 | dw2_relocate, | |
2847 | dw2_expand_symtabs_for_function, | |
2848 | dw2_expand_all_symtabs, | |
2849 | dw2_expand_symtabs_with_filename, | |
2850 | dw2_find_symbol_file, | |
40658b94 | 2851 | dw2_map_matching_symbols, |
9291a0cd TT |
2852 | dw2_expand_symtabs_matching, |
2853 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
2854 | dw2_map_symbol_filenames |
2855 | }; | |
2856 | ||
2857 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2858 | file will use psymtabs, or 1 if using the GNU index. */ | |
2859 | ||
2860 | int | |
2861 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2862 | { | |
2863 | /* If we're about to read full symbols, don't bother with the | |
2864 | indices. In this case we also don't care if some other debug | |
2865 | format is making psymtabs, because they are all about to be | |
2866 | expanded anyway. */ | |
2867 | if ((objfile->flags & OBJF_READNOW)) | |
2868 | { | |
2869 | int i; | |
2870 | ||
2871 | dwarf2_per_objfile->using_index = 1; | |
2872 | create_all_comp_units (objfile); | |
1fd400ff | 2873 | create_debug_types_hash_table (objfile); |
7b9f3c50 DE |
2874 | dwarf2_per_objfile->quick_file_names_table = |
2875 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2876 | |
1fd400ff TT |
2877 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2878 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2879 | { |
e254ef6a | 2880 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2881 | |
e254ef6a DE |
2882 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2883 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2884 | } |
2885 | ||
2886 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2887 | these functions will be no-ops because we will have expanded | |
2888 | all symtabs. */ | |
2889 | return 1; | |
2890 | } | |
2891 | ||
2892 | if (dwarf2_read_index (objfile)) | |
2893 | return 1; | |
2894 | ||
9291a0cd TT |
2895 | return 0; |
2896 | } | |
2897 | ||
2898 | \f | |
2899 | ||
dce234bc PP |
2900 | /* Build a partial symbol table. */ |
2901 | ||
2902 | void | |
f29dff0a | 2903 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2904 | { |
f29dff0a | 2905 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2906 | { |
2907 | init_psymbol_list (objfile, 1024); | |
2908 | } | |
2909 | ||
d146bf1e | 2910 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2911 | } |
c906108c | 2912 | |
45452591 DE |
2913 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2914 | ||
2915 | static inline int | |
2916 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2917 | { | |
2918 | unsigned int bottom = cu_header->offset; | |
2919 | unsigned int top = (cu_header->offset | |
2920 | + cu_header->length | |
2921 | + cu_header->initial_length_size); | |
9a619af0 | 2922 | |
45452591 DE |
2923 | return (offset >= bottom && offset < top); |
2924 | } | |
2925 | ||
93311388 DE |
2926 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2927 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2928 | by the caller. */ | |
107d2387 | 2929 | |
fe1b8b76 | 2930 | static gdb_byte * |
107d2387 | 2931 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2932 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2933 | { |
2934 | int signed_addr; | |
891d2f0b | 2935 | unsigned int bytes_read; |
c764a876 DE |
2936 | |
2937 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2938 | cu_header->initial_length_size = bytes_read; | |
2939 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2940 | info_ptr += bytes_read; |
107d2387 AC |
2941 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2942 | info_ptr += 2; | |
613e1657 | 2943 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2944 | &bytes_read); |
613e1657 | 2945 | info_ptr += bytes_read; |
107d2387 AC |
2946 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2947 | info_ptr += 1; | |
2948 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2949 | if (signed_addr < 0) | |
8e65ff28 | 2950 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2951 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2952 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2953 | |
107d2387 AC |
2954 | return info_ptr; |
2955 | } | |
2956 | ||
adabb602 DE |
2957 | /* Read in a CU header and perform some basic error checking. */ |
2958 | ||
fe1b8b76 JB |
2959 | static gdb_byte * |
2960 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2961 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2962 | bfd *abfd) |
2963 | { | |
fe1b8b76 | 2964 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 | 2965 | |
adabb602 DE |
2966 | header->offset = beg_of_comp_unit - buffer; |
2967 | ||
72bf9492 DJ |
2968 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
2969 | ||
adabb602 DE |
2970 | header->first_die_offset = info_ptr - beg_of_comp_unit; |
2971 | ||
2dc7f7b3 | 2972 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2973 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2974 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2975 | bfd_get_filename (abfd)); | |
72bf9492 | 2976 | |
9e0ac564 TT |
2977 | if (header->abbrev_offset |
2978 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, | |
2979 | &dwarf2_per_objfile->abbrev)) | |
8a3fe4f8 AC |
2980 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2981 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2982 | (long) header->abbrev_offset, |
93311388 | 2983 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2984 | bfd_get_filename (abfd)); |
2985 | ||
2986 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2987 | > buffer + buffer_size) |
8a3fe4f8 AC |
2988 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2989 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2990 | (long) header->length, |
93311388 | 2991 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2992 | bfd_get_filename (abfd)); |
2993 | ||
2994 | return info_ptr; | |
2995 | } | |
2996 | ||
348e048f DE |
2997 | /* Read in the types comp unit header information from .debug_types entry at |
2998 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2999 | ||
3000 | static gdb_byte * | |
3001 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
8b70b953 | 3002 | struct dwarf2_section_info *section, |
348e048f DE |
3003 | ULONGEST *signature, |
3004 | gdb_byte *types_ptr, bfd *abfd) | |
3005 | { | |
348e048f DE |
3006 | gdb_byte *initial_types_ptr = types_ptr; |
3007 | ||
8b70b953 TT |
3008 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
3009 | cu_header->offset = types_ptr - section->buffer; | |
348e048f DE |
3010 | |
3011 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
3012 | ||
3013 | *signature = read_8_bytes (abfd, types_ptr); | |
3014 | types_ptr += 8; | |
3015 | types_ptr += cu_header->offset_size; | |
3016 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
3017 | ||
3018 | return types_ptr; | |
3019 | } | |
3020 | ||
aaa75496 JB |
3021 | /* Allocate a new partial symtab for file named NAME and mark this new |
3022 | partial symtab as being an include of PST. */ | |
3023 | ||
3024 | static void | |
3025 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3026 | struct objfile *objfile) | |
3027 | { | |
3028 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3029 | ||
3030 | subpst->section_offsets = pst->section_offsets; | |
3031 | subpst->textlow = 0; | |
3032 | subpst->texthigh = 0; | |
3033 | ||
3034 | subpst->dependencies = (struct partial_symtab **) | |
3035 | obstack_alloc (&objfile->objfile_obstack, | |
3036 | sizeof (struct partial_symtab *)); | |
3037 | subpst->dependencies[0] = pst; | |
3038 | subpst->number_of_dependencies = 1; | |
3039 | ||
3040 | subpst->globals_offset = 0; | |
3041 | subpst->n_global_syms = 0; | |
3042 | subpst->statics_offset = 0; | |
3043 | subpst->n_static_syms = 0; | |
3044 | subpst->symtab = NULL; | |
3045 | subpst->read_symtab = pst->read_symtab; | |
3046 | subpst->readin = 0; | |
3047 | ||
3048 | /* No private part is necessary for include psymtabs. This property | |
3049 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3050 | the regular ones. */ |
58a9656e | 3051 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3052 | } |
3053 | ||
3054 | /* Read the Line Number Program data and extract the list of files | |
3055 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3056 | partial symtab for each of these included files. */ |
aaa75496 JB |
3057 | |
3058 | static void | |
3059 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 3060 | struct die_info *die, |
aaa75496 JB |
3061 | struct partial_symtab *pst) |
3062 | { | |
3063 | struct objfile *objfile = cu->objfile; | |
3064 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
3065 | struct line_header *lh = NULL; |
3066 | struct attribute *attr; | |
aaa75496 | 3067 | |
d85a05f0 DJ |
3068 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3069 | if (attr) | |
3070 | { | |
3071 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 3072 | |
d85a05f0 DJ |
3073 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
3074 | } | |
aaa75496 JB |
3075 | if (lh == NULL) |
3076 | return; /* No linetable, so no includes. */ | |
3077 | ||
c6da4cef DE |
3078 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
3079 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); | |
aaa75496 JB |
3080 | |
3081 | free_line_header (lh); | |
3082 | } | |
3083 | ||
348e048f DE |
3084 | static hashval_t |
3085 | hash_type_signature (const void *item) | |
3086 | { | |
3087 | const struct signatured_type *type_sig = item; | |
9a619af0 | 3088 | |
348e048f DE |
3089 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
3090 | return type_sig->signature; | |
3091 | } | |
3092 | ||
3093 | static int | |
3094 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
3095 | { | |
3096 | const struct signatured_type *lhs = item_lhs; | |
3097 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3098 | |
348e048f DE |
3099 | return lhs->signature == rhs->signature; |
3100 | } | |
3101 | ||
1fd400ff TT |
3102 | /* Allocate a hash table for signatured types. */ |
3103 | ||
3104 | static htab_t | |
673bfd45 | 3105 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3106 | { |
3107 | return htab_create_alloc_ex (41, | |
3108 | hash_type_signature, | |
3109 | eq_type_signature, | |
3110 | NULL, | |
3111 | &objfile->objfile_obstack, | |
3112 | hashtab_obstack_allocate, | |
3113 | dummy_obstack_deallocate); | |
3114 | } | |
3115 | ||
3116 | /* A helper function to add a signatured type CU to a list. */ | |
3117 | ||
3118 | static int | |
3119 | add_signatured_type_cu_to_list (void **slot, void *datum) | |
3120 | { | |
3121 | struct signatured_type *sigt = *slot; | |
3122 | struct dwarf2_per_cu_data ***datap = datum; | |
3123 | ||
3124 | **datap = &sigt->per_cu; | |
3125 | ++*datap; | |
3126 | ||
3127 | return 1; | |
3128 | } | |
3129 | ||
348e048f DE |
3130 | /* Create the hash table of all entries in the .debug_types section. |
3131 | The result is zero if there is an error (e.g. missing .debug_types section), | |
3132 | otherwise non-zero. */ | |
3133 | ||
3134 | static int | |
3135 | create_debug_types_hash_table (struct objfile *objfile) | |
3136 | { | |
8b70b953 | 3137 | htab_t types_htab = NULL; |
1fd400ff | 3138 | struct dwarf2_per_cu_data **iter; |
8b70b953 TT |
3139 | int ix; |
3140 | struct dwarf2_section_info *section; | |
348e048f | 3141 | |
8b70b953 | 3142 | if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)) |
348e048f DE |
3143 | { |
3144 | dwarf2_per_objfile->signatured_types = NULL; | |
3145 | return 0; | |
3146 | } | |
3147 | ||
8b70b953 TT |
3148 | for (ix = 0; |
3149 | VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
3150 | ix, section); | |
3151 | ++ix) | |
3152 | { | |
3153 | gdb_byte *info_ptr, *end_ptr; | |
348e048f | 3154 | |
8b70b953 TT |
3155 | dwarf2_read_section (objfile, section); |
3156 | info_ptr = section->buffer; | |
348e048f | 3157 | |
8b70b953 TT |
3158 | if (info_ptr == NULL) |
3159 | continue; | |
348e048f | 3160 | |
8b70b953 TT |
3161 | if (types_htab == NULL) |
3162 | types_htab = allocate_signatured_type_table (objfile); | |
348e048f | 3163 | |
8b70b953 TT |
3164 | if (dwarf2_die_debug) |
3165 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
3166 | ||
3167 | end_ptr = info_ptr + section->size; | |
3168 | while (info_ptr < end_ptr) | |
3169 | { | |
3170 | unsigned int offset; | |
3171 | unsigned int offset_size; | |
3172 | unsigned int type_offset; | |
3173 | unsigned int length, initial_length_size; | |
3174 | unsigned short version; | |
3175 | ULONGEST signature; | |
3176 | struct signatured_type *type_sig; | |
3177 | void **slot; | |
3178 | gdb_byte *ptr = info_ptr; | |
348e048f | 3179 | |
8b70b953 | 3180 | offset = ptr - section->buffer; |
348e048f | 3181 | |
8b70b953 TT |
3182 | /* We need to read the type's signature in order to build the hash |
3183 | table, but we don't need to read anything else just yet. */ | |
348e048f | 3184 | |
8b70b953 TT |
3185 | /* Sanity check to ensure entire cu is present. */ |
3186 | length = read_initial_length (objfile->obfd, ptr, | |
3187 | &initial_length_size); | |
3188 | if (ptr + length + initial_length_size > end_ptr) | |
3189 | { | |
3190 | complaint (&symfile_complaints, | |
3191 | _("debug type entry runs off end " | |
3192 | "of `.debug_types' section, ignored")); | |
3193 | break; | |
3194 | } | |
348e048f | 3195 | |
8b70b953 TT |
3196 | offset_size = initial_length_size == 4 ? 4 : 8; |
3197 | ptr += initial_length_size; | |
3198 | version = bfd_get_16 (objfile->obfd, ptr); | |
3199 | ptr += 2; | |
3200 | ptr += offset_size; /* abbrev offset */ | |
3201 | ptr += 1; /* address size */ | |
3202 | signature = bfd_get_64 (objfile->obfd, ptr); | |
3203 | ptr += 8; | |
3204 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
3205 | ||
3206 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
3207 | memset (type_sig, 0, sizeof (*type_sig)); | |
3208 | type_sig->signature = signature; | |
3209 | type_sig->type_offset = type_offset; | |
3210 | type_sig->per_cu.objfile = objfile; | |
3211 | type_sig->per_cu.debug_type_section = section; | |
3212 | type_sig->per_cu.offset = offset; | |
3213 | ||
3214 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
3215 | gdb_assert (slot != NULL); | |
3216 | if (*slot != NULL) | |
3217 | { | |
3218 | const struct signatured_type *dup_sig = *slot; | |
b3c8eb43 | 3219 | |
8b70b953 TT |
3220 | complaint (&symfile_complaints, |
3221 | _("debug type entry at offset 0x%x is duplicate to the " | |
3222 | "entry at offset 0x%x, signature 0x%s"), | |
3223 | offset, dup_sig->per_cu.offset, | |
3224 | phex (signature, sizeof (signature))); | |
3225 | gdb_assert (signature == dup_sig->signature); | |
3226 | } | |
3227 | *slot = type_sig; | |
348e048f | 3228 | |
8b70b953 TT |
3229 | if (dwarf2_die_debug) |
3230 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
3231 | offset, phex (signature, sizeof (signature))); | |
348e048f | 3232 | |
8b70b953 TT |
3233 | info_ptr = info_ptr + initial_length_size + length; |
3234 | } | |
348e048f DE |
3235 | } |
3236 | ||
3237 | dwarf2_per_objfile->signatured_types = types_htab; | |
3238 | ||
1fd400ff TT |
3239 | dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab); |
3240 | dwarf2_per_objfile->type_comp_units | |
3241 | = obstack_alloc (&objfile->objfile_obstack, | |
3242 | dwarf2_per_objfile->n_type_comp_units | |
3243 | * sizeof (struct dwarf2_per_cu_data *)); | |
3244 | iter = &dwarf2_per_objfile->type_comp_units[0]; | |
3245 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter); | |
3246 | gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0] | |
3247 | == dwarf2_per_objfile->n_type_comp_units); | |
3248 | ||
348e048f DE |
3249 | return 1; |
3250 | } | |
3251 | ||
3252 | /* Lookup a signature based type. | |
3253 | Returns NULL if SIG is not present in the table. */ | |
3254 | ||
3255 | static struct signatured_type * | |
3256 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
3257 | { | |
3258 | struct signatured_type find_entry, *entry; | |
3259 | ||
3260 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3261 | { | |
3262 | complaint (&symfile_complaints, | |
55f1336d | 3263 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
348e048f DE |
3264 | return 0; |
3265 | } | |
3266 | ||
3267 | find_entry.signature = sig; | |
3268 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3269 | return entry; | |
3270 | } | |
3271 | ||
d85a05f0 DJ |
3272 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3273 | ||
3274 | static void | |
3275 | init_cu_die_reader (struct die_reader_specs *reader, | |
3276 | struct dwarf2_cu *cu) | |
3277 | { | |
3278 | reader->abfd = cu->objfile->obfd; | |
3279 | reader->cu = cu; | |
8b70b953 | 3280 | if (cu->per_cu->debug_type_section) |
be391dca | 3281 | { |
8b70b953 TT |
3282 | gdb_assert (cu->per_cu->debug_type_section->readin); |
3283 | reader->buffer = cu->per_cu->debug_type_section->buffer; | |
be391dca | 3284 | } |
d85a05f0 | 3285 | else |
be391dca TT |
3286 | { |
3287 | gdb_assert (dwarf2_per_objfile->info.readin); | |
3288 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
3289 | } | |
d85a05f0 DJ |
3290 | } |
3291 | ||
3292 | /* Find the base address of the compilation unit for range lists and | |
3293 | location lists. It will normally be specified by DW_AT_low_pc. | |
3294 | In DWARF-3 draft 4, the base address could be overridden by | |
3295 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3296 | compilation units with discontinuous ranges. */ | |
3297 | ||
3298 | static void | |
3299 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3300 | { | |
3301 | struct attribute *attr; | |
3302 | ||
3303 | cu->base_known = 0; | |
3304 | cu->base_address = 0; | |
3305 | ||
3306 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3307 | if (attr) | |
3308 | { | |
3309 | cu->base_address = DW_ADDR (attr); | |
3310 | cu->base_known = 1; | |
3311 | } | |
3312 | else | |
3313 | { | |
3314 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3315 | if (attr) | |
3316 | { | |
3317 | cu->base_address = DW_ADDR (attr); | |
3318 | cu->base_known = 1; | |
3319 | } | |
3320 | } | |
3321 | } | |
3322 | ||
348e048f DE |
3323 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
3324 | to combine the common parts. | |
93311388 | 3325 | Process a compilation unit for a psymtab. |
348e048f DE |
3326 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
3327 | either .debug_info or debug_types. | |
93311388 DE |
3328 | INFO_PTR is a pointer to the start of the CU. |
3329 | Returns a pointer to the next CU. */ | |
aaa75496 | 3330 | |
93311388 DE |
3331 | static gdb_byte * |
3332 | process_psymtab_comp_unit (struct objfile *objfile, | |
3333 | struct dwarf2_per_cu_data *this_cu, | |
3334 | gdb_byte *buffer, gdb_byte *info_ptr, | |
3335 | unsigned int buffer_size) | |
c906108c | 3336 | { |
c906108c | 3337 | bfd *abfd = objfile->obfd; |
93311388 | 3338 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3339 | struct die_info *comp_unit_die; |
c906108c | 3340 | struct partial_symtab *pst; |
5734ee8b | 3341 | CORE_ADDR baseaddr; |
93311388 DE |
3342 | struct cleanup *back_to_inner; |
3343 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3344 | int has_children, has_pc_info; |
3345 | struct attribute *attr; | |
d85a05f0 DJ |
3346 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3347 | struct die_reader_specs reader_specs; | |
3e2a0cee | 3348 | const char *filename; |
c906108c | 3349 | |
9816fde3 | 3350 | init_one_comp_unit (&cu, objfile); |
93311388 | 3351 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3352 | |
93311388 DE |
3353 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
3354 | buffer, buffer_size, | |
3355 | abfd); | |
10b3939b | 3356 | |
93311388 | 3357 | cu.list_in_scope = &file_symbols; |
af703f96 | 3358 | |
328c9494 DJ |
3359 | /* If this compilation unit was already read in, free the |
3360 | cached copy in order to read it in again. This is | |
3361 | necessary because we skipped some symbols when we first | |
3362 | read in the compilation unit (see load_partial_dies). | |
3363 | This problem could be avoided, but the benefit is | |
3364 | unclear. */ | |
3365 | if (this_cu->cu != NULL) | |
3366 | free_one_cached_comp_unit (this_cu->cu); | |
3367 | ||
3368 | /* Note that this is a pointer to our stack frame, being | |
3369 | added to a global data structure. It will be cleaned up | |
3370 | in free_stack_comp_unit when we finish with this | |
3371 | compilation unit. */ | |
3372 | this_cu->cu = &cu; | |
d85a05f0 DJ |
3373 | cu.per_cu = this_cu; |
3374 | ||
93311388 DE |
3375 | /* Read the abbrevs for this compilation unit into a table. */ |
3376 | dwarf2_read_abbrevs (abfd, &cu); | |
3377 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 3378 | |
93311388 | 3379 | /* Read the compilation unit die. */ |
8b70b953 | 3380 | if (this_cu->debug_type_section) |
348e048f | 3381 | info_ptr += 8 /*signature*/ + cu.header.offset_size; |
d85a05f0 DJ |
3382 | init_cu_die_reader (&reader_specs, &cu); |
3383 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3384 | &has_children); | |
93311388 | 3385 | |
8b70b953 | 3386 | if (this_cu->debug_type_section) |
348e048f | 3387 | { |
b3c8eb43 JK |
3388 | /* LENGTH has not been set yet for type units. */ |
3389 | gdb_assert (this_cu->offset == cu.header.offset); | |
348e048f DE |
3390 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
3391 | } | |
d85a05f0 | 3392 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3393 | { |
93311388 DE |
3394 | info_ptr = (beg_of_comp_unit + cu.header.length |
3395 | + cu.header.initial_length_size); | |
3396 | do_cleanups (back_to_inner); | |
3397 | return info_ptr; | |
3398 | } | |
72bf9492 | 3399 | |
9816fde3 | 3400 | prepare_one_comp_unit (&cu, comp_unit_die); |
c906108c | 3401 | |
93311388 | 3402 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3403 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
3e2a0cee TT |
3404 | if (attr == NULL || !DW_STRING (attr)) |
3405 | filename = ""; | |
3406 | else | |
3407 | filename = DW_STRING (attr); | |
93311388 | 3408 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3409 | filename, |
93311388 DE |
3410 | /* TEXTLOW and TEXTHIGH are set below. */ |
3411 | 0, | |
3412 | objfile->global_psymbols.next, | |
3413 | objfile->static_psymbols.next); | |
72bf9492 | 3414 | |
d85a05f0 DJ |
3415 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3416 | if (attr != NULL) | |
3417 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3418 | |
e38df1d0 | 3419 | pst->read_symtab_private = this_cu; |
72bf9492 | 3420 | |
93311388 | 3421 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3422 | |
0963b4bd | 3423 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3424 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3425 | |
9291a0cd | 3426 | this_cu->v.psymtab = pst; |
c906108c | 3427 | |
d85a05f0 DJ |
3428 | dwarf2_find_base_address (comp_unit_die, &cu); |
3429 | ||
93311388 DE |
3430 | /* Possibly set the default values of LOWPC and HIGHPC from |
3431 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3432 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3433 | &best_highpc, &cu, pst); | |
3434 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3435 | /* Store the contiguous range if it is not empty; it can be empty for |
3436 | CUs with no code. */ | |
3437 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3438 | best_lowpc + baseaddr, |
3439 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3440 | |
3441 | /* Check if comp unit has_children. | |
3442 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3443 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3444 | if (has_children) |
93311388 DE |
3445 | { |
3446 | struct partial_die_info *first_die; | |
3447 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3448 | |
93311388 DE |
3449 | lowpc = ((CORE_ADDR) -1); |
3450 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3451 | |
93311388 | 3452 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3453 | |
93311388 | 3454 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3455 | ! has_pc_info, &cu); |
57c22c6c | 3456 | |
93311388 DE |
3457 | /* If we didn't find a lowpc, set it to highpc to avoid |
3458 | complaints from `maint check'. */ | |
3459 | if (lowpc == ((CORE_ADDR) -1)) | |
3460 | lowpc = highpc; | |
10b3939b | 3461 | |
93311388 DE |
3462 | /* If the compilation unit didn't have an explicit address range, |
3463 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3464 | if (! has_pc_info) |
93311388 | 3465 | { |
d85a05f0 DJ |
3466 | best_lowpc = lowpc; |
3467 | best_highpc = highpc; | |
93311388 DE |
3468 | } |
3469 | } | |
d85a05f0 DJ |
3470 | pst->textlow = best_lowpc + baseaddr; |
3471 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3472 | |
93311388 DE |
3473 | pst->n_global_syms = objfile->global_psymbols.next - |
3474 | (objfile->global_psymbols.list + pst->globals_offset); | |
3475 | pst->n_static_syms = objfile->static_psymbols.next - | |
3476 | (objfile->static_psymbols.list + pst->statics_offset); | |
3477 | sort_pst_symbols (pst); | |
c906108c | 3478 | |
93311388 DE |
3479 | info_ptr = (beg_of_comp_unit + cu.header.length |
3480 | + cu.header.initial_length_size); | |
ae038cb0 | 3481 | |
8b70b953 | 3482 | if (this_cu->debug_type_section) |
348e048f DE |
3483 | { |
3484 | /* It's not clear we want to do anything with stmt lists here. | |
3485 | Waiting to see what gcc ultimately does. */ | |
3486 | } | |
d85a05f0 | 3487 | else |
93311388 DE |
3488 | { |
3489 | /* Get the list of files included in the current compilation unit, | |
3490 | and build a psymtab for each of them. */ | |
d85a05f0 | 3491 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3492 | } |
ae038cb0 | 3493 | |
93311388 | 3494 | do_cleanups (back_to_inner); |
ae038cb0 | 3495 | |
93311388 DE |
3496 | return info_ptr; |
3497 | } | |
ff013f42 | 3498 | |
348e048f DE |
3499 | /* Traversal function for htab_traverse_noresize. |
3500 | Process one .debug_types comp-unit. */ | |
3501 | ||
3502 | static int | |
3503 | process_type_comp_unit (void **slot, void *info) | |
3504 | { | |
3505 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
3506 | struct objfile *objfile = (struct objfile *) info; | |
3507 | struct dwarf2_per_cu_data *this_cu; | |
3508 | ||
3509 | this_cu = &entry->per_cu; | |
348e048f | 3510 | |
8b70b953 | 3511 | gdb_assert (this_cu->debug_type_section->readin); |
348e048f | 3512 | process_psymtab_comp_unit (objfile, this_cu, |
8b70b953 TT |
3513 | this_cu->debug_type_section->buffer, |
3514 | (this_cu->debug_type_section->buffer | |
3515 | + this_cu->offset), | |
3516 | this_cu->debug_type_section->size); | |
348e048f DE |
3517 | |
3518 | return 1; | |
3519 | } | |
3520 | ||
3521 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3522 | Build partial symbol tables for the .debug_types comp-units. */ | |
3523 | ||
3524 | static void | |
3525 | build_type_psymtabs (struct objfile *objfile) | |
3526 | { | |
3527 | if (! create_debug_types_hash_table (objfile)) | |
3528 | return; | |
3529 | ||
3530 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
3531 | process_type_comp_unit, objfile); | |
3532 | } | |
3533 | ||
60606b2c TT |
3534 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3535 | ||
3536 | static void | |
3537 | psymtabs_addrmap_cleanup (void *o) | |
3538 | { | |
3539 | struct objfile *objfile = o; | |
ec61707d | 3540 | |
60606b2c TT |
3541 | objfile->psymtabs_addrmap = NULL; |
3542 | } | |
3543 | ||
93311388 DE |
3544 | /* Build the partial symbol table by doing a quick pass through the |
3545 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3546 | |
93311388 | 3547 | static void |
c67a9c90 | 3548 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3549 | { |
93311388 | 3550 | gdb_byte *info_ptr; |
60606b2c TT |
3551 | struct cleanup *back_to, *addrmap_cleanup; |
3552 | struct obstack temp_obstack; | |
93311388 | 3553 | |
98bfdba5 PA |
3554 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3555 | ||
be391dca | 3556 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3557 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3558 | |
93311388 DE |
3559 | /* Any cached compilation units will be linked by the per-objfile |
3560 | read_in_chain. Make sure to free them when we're done. */ | |
3561 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3562 | |
348e048f DE |
3563 | build_type_psymtabs (objfile); |
3564 | ||
93311388 | 3565 | create_all_comp_units (objfile); |
c906108c | 3566 | |
60606b2c TT |
3567 | /* Create a temporary address map on a temporary obstack. We later |
3568 | copy this to the final obstack. */ | |
3569 | obstack_init (&temp_obstack); | |
3570 | make_cleanup_obstack_free (&temp_obstack); | |
3571 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3572 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3573 | |
93311388 DE |
3574 | /* Since the objects we're extracting from .debug_info vary in |
3575 | length, only the individual functions to extract them (like | |
3576 | read_comp_unit_head and load_partial_die) can really know whether | |
3577 | the buffer is large enough to hold another complete object. | |
c906108c | 3578 | |
93311388 DE |
3579 | At the moment, they don't actually check that. If .debug_info |
3580 | holds just one extra byte after the last compilation unit's dies, | |
3581 | then read_comp_unit_head will happily read off the end of the | |
3582 | buffer. read_partial_die is similarly casual. Those functions | |
3583 | should be fixed. | |
c906108c | 3584 | |
93311388 DE |
3585 | For this loop condition, simply checking whether there's any data |
3586 | left at all should be sufficient. */ | |
c906108c | 3587 | |
93311388 DE |
3588 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3589 | + dwarf2_per_objfile->info.size)) | |
3590 | { | |
3591 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3592 | |
3e43a32a MS |
3593 | this_cu = dwarf2_find_comp_unit (info_ptr |
3594 | - dwarf2_per_objfile->info.buffer, | |
93311388 | 3595 | objfile); |
aaa75496 | 3596 | |
93311388 DE |
3597 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3598 | dwarf2_per_objfile->info.buffer, | |
3599 | info_ptr, | |
3600 | dwarf2_per_objfile->info.size); | |
c906108c | 3601 | } |
ff013f42 JK |
3602 | |
3603 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3604 | &objfile->objfile_obstack); | |
60606b2c | 3605 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3606 | |
ae038cb0 DJ |
3607 | do_cleanups (back_to); |
3608 | } | |
3609 | ||
93311388 | 3610 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3611 | |
3612 | static void | |
93311388 DE |
3613 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3614 | struct objfile *objfile) | |
ae038cb0 DJ |
3615 | { |
3616 | bfd *abfd = objfile->obfd; | |
adabb602 | 3617 | gdb_byte *info_ptr; |
d85a05f0 | 3618 | struct die_info *comp_unit_die; |
ae038cb0 | 3619 | struct dwarf2_cu *cu; |
1d9ec526 | 3620 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3621 | int has_children; |
3622 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3623 | int read_cu = 0; |
ae038cb0 | 3624 | |
8b70b953 | 3625 | gdb_assert (! this_cu->debug_type_section); |
348e048f | 3626 | |
be391dca | 3627 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3628 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 | 3629 | |
98bfdba5 PA |
3630 | if (this_cu->cu == NULL) |
3631 | { | |
9816fde3 JK |
3632 | cu = xmalloc (sizeof (*cu)); |
3633 | init_one_comp_unit (cu, objfile); | |
ae038cb0 | 3634 | |
98bfdba5 | 3635 | read_cu = 1; |
ae038cb0 | 3636 | |
98bfdba5 PA |
3637 | /* If an error occurs while loading, release our storage. */ |
3638 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
328c9494 | 3639 | |
98bfdba5 PA |
3640 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3641 | dwarf2_per_objfile->info.buffer, | |
3642 | dwarf2_per_objfile->info.size, | |
3643 | abfd); | |
ae038cb0 | 3644 | |
98bfdba5 PA |
3645 | /* Link this compilation unit into the compilation unit tree. */ |
3646 | this_cu->cu = cu; | |
3647 | cu->per_cu = this_cu; | |
98bfdba5 PA |
3648 | |
3649 | /* Link this CU into read_in_chain. */ | |
3650 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3651 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3652 | } | |
3653 | else | |
3654 | { | |
3655 | cu = this_cu->cu; | |
3656 | info_ptr += cu->header.first_die_offset; | |
3657 | } | |
ae038cb0 DJ |
3658 | |
3659 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3660 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
ae038cb0 | 3661 | dwarf2_read_abbrevs (abfd, cu); |
98bfdba5 | 3662 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3663 | |
3664 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3665 | init_cu_die_reader (&reader_specs, cu); |
3666 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3667 | &has_children); | |
ae038cb0 | 3668 | |
9816fde3 | 3669 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3670 | |
ae038cb0 DJ |
3671 | /* Check if comp unit has_children. |
3672 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3673 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3674 | if (has_children) |
93311388 | 3675 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 | 3676 | |
98bfdba5 PA |
3677 | do_cleanups (free_abbrevs_cleanup); |
3678 | ||
3679 | if (read_cu) | |
3680 | { | |
3681 | /* We've successfully allocated this compilation unit. Let our | |
3682 | caller clean it up when finished with it. */ | |
3683 | discard_cleanups (free_cu_cleanup); | |
3684 | } | |
ae038cb0 DJ |
3685 | } |
3686 | ||
3687 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3688 | if an inter-comp-unit reference is found; presumably if there is one, | |
3689 | there will be many, and one will occur early in the .debug_info section. | |
3690 | So there's no point in building this list incrementally. */ | |
3691 | ||
3692 | static void | |
3693 | create_all_comp_units (struct objfile *objfile) | |
3694 | { | |
3695 | int n_allocated; | |
3696 | int n_comp_units; | |
3697 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3698 | gdb_byte *info_ptr; |
3699 | ||
3700 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3701 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3702 | |
3703 | n_comp_units = 0; | |
3704 | n_allocated = 10; | |
3705 | all_comp_units = xmalloc (n_allocated | |
3706 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3707 | |
3e43a32a MS |
3708 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3709 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3710 | { |
c764a876 | 3711 | unsigned int length, initial_length_size; |
ae038cb0 | 3712 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3713 | unsigned int offset; |
ae038cb0 | 3714 | |
dce234bc | 3715 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3716 | |
3717 | /* Read just enough information to find out where the next | |
3718 | compilation unit is. */ | |
c764a876 DE |
3719 | length = read_initial_length (objfile->obfd, info_ptr, |
3720 | &initial_length_size); | |
ae038cb0 DJ |
3721 | |
3722 | /* Save the compilation unit for later lookup. */ | |
3723 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3724 | sizeof (struct dwarf2_per_cu_data)); | |
3725 | memset (this_cu, 0, sizeof (*this_cu)); | |
3726 | this_cu->offset = offset; | |
c764a876 | 3727 | this_cu->length = length + initial_length_size; |
9291a0cd | 3728 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3729 | |
3730 | if (n_comp_units == n_allocated) | |
3731 | { | |
3732 | n_allocated *= 2; | |
3733 | all_comp_units = xrealloc (all_comp_units, | |
3734 | n_allocated | |
3735 | * sizeof (struct dwarf2_per_cu_data *)); | |
3736 | } | |
3737 | all_comp_units[n_comp_units++] = this_cu; | |
3738 | ||
3739 | info_ptr = info_ptr + this_cu->length; | |
3740 | } | |
3741 | ||
3742 | dwarf2_per_objfile->all_comp_units | |
3743 | = obstack_alloc (&objfile->objfile_obstack, | |
3744 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3745 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3746 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3747 | xfree (all_comp_units); | |
3748 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3749 | } |
3750 | ||
5734ee8b DJ |
3751 | /* Process all loaded DIEs for compilation unit CU, starting at |
3752 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3753 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3754 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3755 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3756 | and record the covered ranges in the addrmap. */ | |
c906108c | 3757 | |
72bf9492 DJ |
3758 | static void |
3759 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3760 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3761 | { |
72bf9492 | 3762 | struct partial_die_info *pdi; |
c906108c | 3763 | |
91c24f0a DC |
3764 | /* Now, march along the PDI's, descending into ones which have |
3765 | interesting children but skipping the children of the other ones, | |
3766 | until we reach the end of the compilation unit. */ | |
c906108c | 3767 | |
72bf9492 | 3768 | pdi = first_die; |
91c24f0a | 3769 | |
72bf9492 DJ |
3770 | while (pdi != NULL) |
3771 | { | |
3772 | fixup_partial_die (pdi, cu); | |
c906108c | 3773 | |
f55ee35c | 3774 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3775 | children, so we need to look at them. Ditto for anonymous |
3776 | enums. */ | |
933c6fe4 | 3777 | |
72bf9492 | 3778 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3779 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3780 | { |
72bf9492 | 3781 | switch (pdi->tag) |
c906108c SS |
3782 | { |
3783 | case DW_TAG_subprogram: | |
5734ee8b | 3784 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 3785 | break; |
72929c62 | 3786 | case DW_TAG_constant: |
c906108c SS |
3787 | case DW_TAG_variable: |
3788 | case DW_TAG_typedef: | |
91c24f0a | 3789 | case DW_TAG_union_type: |
72bf9492 | 3790 | if (!pdi->is_declaration) |
63d06c5c | 3791 | { |
72bf9492 | 3792 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3793 | } |
3794 | break; | |
c906108c | 3795 | case DW_TAG_class_type: |
680b30c7 | 3796 | case DW_TAG_interface_type: |
c906108c | 3797 | case DW_TAG_structure_type: |
72bf9492 | 3798 | if (!pdi->is_declaration) |
c906108c | 3799 | { |
72bf9492 | 3800 | add_partial_symbol (pdi, cu); |
c906108c SS |
3801 | } |
3802 | break; | |
91c24f0a | 3803 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3804 | if (!pdi->is_declaration) |
3805 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3806 | break; |
3807 | case DW_TAG_base_type: | |
a02abb62 | 3808 | case DW_TAG_subrange_type: |
c906108c | 3809 | /* File scope base type definitions are added to the partial |
c5aa993b | 3810 | symbol table. */ |
72bf9492 | 3811 | add_partial_symbol (pdi, cu); |
c906108c | 3812 | break; |
d9fa45fe | 3813 | case DW_TAG_namespace: |
5734ee8b | 3814 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3815 | break; |
5d7cb8df JK |
3816 | case DW_TAG_module: |
3817 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3818 | break; | |
c906108c SS |
3819 | default: |
3820 | break; | |
3821 | } | |
3822 | } | |
3823 | ||
72bf9492 DJ |
3824 | /* If the die has a sibling, skip to the sibling. */ |
3825 | ||
3826 | pdi = pdi->die_sibling; | |
3827 | } | |
3828 | } | |
3829 | ||
3830 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3831 | |
72bf9492 | 3832 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3833 | name is concatenated with "::" and the partial DIE's name. For |
3834 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3835 | Enumerators are an exception; they use the scope of their parent |
3836 | enumeration type, i.e. the name of the enumeration type is not | |
3837 | prepended to the enumerator. | |
91c24f0a | 3838 | |
72bf9492 DJ |
3839 | There are two complexities. One is DW_AT_specification; in this |
3840 | case "parent" means the parent of the target of the specification, | |
3841 | instead of the direct parent of the DIE. The other is compilers | |
3842 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3843 | the fully qualified name of structure types from their members' | |
3844 | linkage names. This must be done using the DIE's children rather | |
3845 | than the children of any DW_AT_specification target. We only need | |
3846 | to do this for structures at the top level, i.e. if the target of | |
3847 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3848 | have a parent. */ | |
3849 | ||
3850 | /* Compute the scope prefix associated with PDI's parent, in | |
3851 | compilation unit CU. The result will be allocated on CU's | |
3852 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3853 | field. NULL is returned if no prefix is necessary. */ | |
3854 | static char * | |
3855 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3856 | struct dwarf2_cu *cu) | |
3857 | { | |
3858 | char *grandparent_scope; | |
3859 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3860 | |
72bf9492 DJ |
3861 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3862 | then this means the parent of the specification DIE. */ | |
3863 | ||
3864 | real_pdi = pdi; | |
72bf9492 | 3865 | while (real_pdi->has_specification) |
10b3939b | 3866 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3867 | |
3868 | parent = real_pdi->die_parent; | |
3869 | if (parent == NULL) | |
3870 | return NULL; | |
3871 | ||
3872 | if (parent->scope_set) | |
3873 | return parent->scope; | |
3874 | ||
3875 | fixup_partial_die (parent, cu); | |
3876 | ||
10b3939b | 3877 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3878 | |
acebe513 UW |
3879 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3880 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3881 | Work around this problem here. */ | |
3882 | if (cu->language == language_cplus | |
6e70227d | 3883 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3884 | && strcmp (parent->name, "::") == 0 |
3885 | && grandparent_scope == NULL) | |
3886 | { | |
3887 | parent->scope = NULL; | |
3888 | parent->scope_set = 1; | |
3889 | return NULL; | |
3890 | } | |
3891 | ||
9c6c53f7 SA |
3892 | if (pdi->tag == DW_TAG_enumerator) |
3893 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
3894 | parent->scope = grandparent_scope; | |
3895 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 3896 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3897 | || parent->tag == DW_TAG_structure_type |
3898 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3899 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3900 | || parent->tag == DW_TAG_union_type |
3901 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3902 | { |
3903 | if (grandparent_scope == NULL) | |
3904 | parent->scope = parent->name; | |
3905 | else | |
3e43a32a MS |
3906 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
3907 | grandparent_scope, | |
f55ee35c | 3908 | parent->name, 0, cu); |
72bf9492 | 3909 | } |
72bf9492 DJ |
3910 | else |
3911 | { | |
3912 | /* FIXME drow/2004-04-01: What should we be doing with | |
3913 | function-local names? For partial symbols, we should probably be | |
3914 | ignoring them. */ | |
3915 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3916 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3917 | parent->tag, pdi->offset); |
3918 | parent->scope = grandparent_scope; | |
c906108c SS |
3919 | } |
3920 | ||
72bf9492 DJ |
3921 | parent->scope_set = 1; |
3922 | return parent->scope; | |
3923 | } | |
3924 | ||
3925 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3926 | CU. The result will be allocated with malloc. */ | |
3927 | static char * | |
3928 | partial_die_full_name (struct partial_die_info *pdi, | |
3929 | struct dwarf2_cu *cu) | |
3930 | { | |
3931 | char *parent_scope; | |
3932 | ||
98bfdba5 PA |
3933 | /* If this is a template instantiation, we can not work out the |
3934 | template arguments from partial DIEs. So, unfortunately, we have | |
3935 | to go through the full DIEs. At least any work we do building | |
3936 | types here will be reused if full symbols are loaded later. */ | |
3937 | if (pdi->has_template_arguments) | |
3938 | { | |
3939 | fixup_partial_die (pdi, cu); | |
3940 | ||
3941 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3942 | { | |
3943 | struct die_info *die; | |
3944 | struct attribute attr; | |
3945 | struct dwarf2_cu *ref_cu = cu; | |
3946 | ||
3947 | attr.name = 0; | |
3948 | attr.form = DW_FORM_ref_addr; | |
3949 | attr.u.addr = pdi->offset; | |
3950 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3951 | ||
3952 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3953 | } | |
3954 | } | |
3955 | ||
72bf9492 DJ |
3956 | parent_scope = partial_die_parent_scope (pdi, cu); |
3957 | if (parent_scope == NULL) | |
3958 | return NULL; | |
3959 | else | |
f55ee35c | 3960 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3961 | } |
3962 | ||
3963 | static void | |
72bf9492 | 3964 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3965 | { |
e7c27a73 | 3966 | struct objfile *objfile = cu->objfile; |
c906108c | 3967 | CORE_ADDR addr = 0; |
decbce07 | 3968 | char *actual_name = NULL; |
5c4e30ca | 3969 | const struct partial_symbol *psym = NULL; |
e142c38c | 3970 | CORE_ADDR baseaddr; |
72bf9492 | 3971 | int built_actual_name = 0; |
e142c38c DJ |
3972 | |
3973 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3974 | |
94af9270 KS |
3975 | actual_name = partial_die_full_name (pdi, cu); |
3976 | if (actual_name) | |
3977 | built_actual_name = 1; | |
63d06c5c | 3978 | |
72bf9492 DJ |
3979 | if (actual_name == NULL) |
3980 | actual_name = pdi->name; | |
3981 | ||
c906108c SS |
3982 | switch (pdi->tag) |
3983 | { | |
3984 | case DW_TAG_subprogram: | |
2cfa0c8d | 3985 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3986 | { |
2cfa0c8d JB |
3987 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3988 | of the global scope. But in Ada, we want to be able to access | |
3989 | nested procedures globally. So all Ada subprograms are stored | |
3990 | in the global scope. */ | |
f47fb265 | 3991 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3992 | mst_text, objfile); */ |
f47fb265 MS |
3993 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3994 | built_actual_name, | |
3995 | VAR_DOMAIN, LOC_BLOCK, | |
3996 | &objfile->global_psymbols, | |
3997 | 0, pdi->lowpc + baseaddr, | |
3998 | cu->language, objfile); | |
c906108c SS |
3999 | } |
4000 | else | |
4001 | { | |
f47fb265 | 4002 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4003 | mst_file_text, objfile); */ |
f47fb265 MS |
4004 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4005 | built_actual_name, | |
4006 | VAR_DOMAIN, LOC_BLOCK, | |
4007 | &objfile->static_psymbols, | |
4008 | 0, pdi->lowpc + baseaddr, | |
4009 | cu->language, objfile); | |
c906108c SS |
4010 | } |
4011 | break; | |
72929c62 JB |
4012 | case DW_TAG_constant: |
4013 | { | |
4014 | struct psymbol_allocation_list *list; | |
4015 | ||
4016 | if (pdi->is_external) | |
4017 | list = &objfile->global_psymbols; | |
4018 | else | |
4019 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4020 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4021 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4022 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4023 | } |
4024 | break; | |
c906108c | 4025 | case DW_TAG_variable: |
caac4577 JG |
4026 | if (pdi->locdesc) |
4027 | addr = decode_locdesc (pdi->locdesc, cu); | |
4028 | ||
4029 | if (pdi->locdesc | |
4030 | && addr == 0 | |
4031 | && !dwarf2_per_objfile->has_section_at_zero) | |
4032 | { | |
4033 | /* A global or static variable may also have been stripped | |
4034 | out by the linker if unused, in which case its address | |
4035 | will be nullified; do not add such variables into partial | |
4036 | symbol table then. */ | |
4037 | } | |
4038 | else if (pdi->is_external) | |
c906108c SS |
4039 | { |
4040 | /* Global Variable. | |
4041 | Don't enter into the minimal symbol tables as there is | |
4042 | a minimal symbol table entry from the ELF symbols already. | |
4043 | Enter into partial symbol table if it has a location | |
4044 | descriptor or a type. | |
4045 | If the location descriptor is missing, new_symbol will create | |
4046 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4047 | be determined from the minimal symbol table whenever the variable | |
4048 | is referenced. | |
4049 | The address for the partial symbol table entry is not | |
4050 | used by GDB, but it comes in handy for debugging partial symbol | |
4051 | table building. */ | |
4052 | ||
c906108c | 4053 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
4054 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4055 | built_actual_name, | |
4056 | VAR_DOMAIN, LOC_STATIC, | |
4057 | &objfile->global_psymbols, | |
4058 | 0, addr + baseaddr, | |
4059 | cu->language, objfile); | |
c906108c SS |
4060 | } |
4061 | else | |
4062 | { | |
0963b4bd | 4063 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 4064 | if (pdi->locdesc == NULL) |
decbce07 MS |
4065 | { |
4066 | if (built_actual_name) | |
4067 | xfree (actual_name); | |
4068 | return; | |
4069 | } | |
f47fb265 | 4070 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4071 | mst_file_data, objfile); */ |
f47fb265 MS |
4072 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4073 | built_actual_name, | |
4074 | VAR_DOMAIN, LOC_STATIC, | |
4075 | &objfile->static_psymbols, | |
4076 | 0, addr + baseaddr, | |
4077 | cu->language, objfile); | |
c906108c SS |
4078 | } |
4079 | break; | |
4080 | case DW_TAG_typedef: | |
4081 | case DW_TAG_base_type: | |
a02abb62 | 4082 | case DW_TAG_subrange_type: |
38d518c9 | 4083 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4084 | built_actual_name, |
176620f1 | 4085 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4086 | &objfile->static_psymbols, |
e142c38c | 4087 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4088 | break; |
72bf9492 DJ |
4089 | case DW_TAG_namespace: |
4090 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4091 | built_actual_name, |
72bf9492 DJ |
4092 | VAR_DOMAIN, LOC_TYPEDEF, |
4093 | &objfile->global_psymbols, | |
4094 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4095 | break; | |
c906108c | 4096 | case DW_TAG_class_type: |
680b30c7 | 4097 | case DW_TAG_interface_type: |
c906108c SS |
4098 | case DW_TAG_structure_type: |
4099 | case DW_TAG_union_type: | |
4100 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4101 | /* Skip external references. The DWARF standard says in the section |
4102 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4103 | structure, union or class type is represented by a structure, | |
4104 | union or class entry that does not have a byte size attribute | |
4105 | and that has a DW_AT_declaration attribute." */ | |
4106 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4107 | { |
4108 | if (built_actual_name) | |
4109 | xfree (actual_name); | |
4110 | return; | |
4111 | } | |
fa4028e9 | 4112 | |
63d06c5c DC |
4113 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4114 | static vs. global. */ | |
38d518c9 | 4115 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4116 | built_actual_name, |
176620f1 | 4117 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4118 | (cu->language == language_cplus |
4119 | || cu->language == language_java) | |
63d06c5c DC |
4120 | ? &objfile->global_psymbols |
4121 | : &objfile->static_psymbols, | |
e142c38c | 4122 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4123 | |
c906108c SS |
4124 | break; |
4125 | case DW_TAG_enumerator: | |
38d518c9 | 4126 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4127 | built_actual_name, |
176620f1 | 4128 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4129 | (cu->language == language_cplus |
4130 | || cu->language == language_java) | |
f6fe98ef DJ |
4131 | ? &objfile->global_psymbols |
4132 | : &objfile->static_psymbols, | |
e142c38c | 4133 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4134 | break; |
4135 | default: | |
4136 | break; | |
4137 | } | |
5c4e30ca | 4138 | |
72bf9492 DJ |
4139 | if (built_actual_name) |
4140 | xfree (actual_name); | |
c906108c SS |
4141 | } |
4142 | ||
5c4e30ca DC |
4143 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4144 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4145 | the name of the enclosing namespace. */ | |
91c24f0a | 4146 | |
72bf9492 DJ |
4147 | static void |
4148 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4149 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4150 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4151 | { |
72bf9492 | 4152 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4153 | |
72bf9492 | 4154 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4155 | |
4156 | /* Now scan partial symbols in that namespace. */ | |
4157 | ||
91c24f0a | 4158 | if (pdi->has_children) |
5734ee8b | 4159 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4160 | } |
4161 | ||
5d7cb8df JK |
4162 | /* Read a partial die corresponding to a Fortran module. */ |
4163 | ||
4164 | static void | |
4165 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4166 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4167 | { | |
f55ee35c | 4168 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4169 | |
4170 | if (pdi->has_children) | |
4171 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4172 | } | |
4173 | ||
bc30ff58 JB |
4174 | /* Read a partial die corresponding to a subprogram and create a partial |
4175 | symbol for that subprogram. When the CU language allows it, this | |
4176 | routine also defines a partial symbol for each nested subprogram | |
4177 | that this subprogram contains. | |
6e70227d | 4178 | |
bc30ff58 JB |
4179 | DIE my also be a lexical block, in which case we simply search |
4180 | recursively for suprograms defined inside that lexical block. | |
4181 | Again, this is only performed when the CU language allows this | |
4182 | type of definitions. */ | |
4183 | ||
4184 | static void | |
4185 | add_partial_subprogram (struct partial_die_info *pdi, | |
4186 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4187 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4188 | { |
4189 | if (pdi->tag == DW_TAG_subprogram) | |
4190 | { | |
4191 | if (pdi->has_pc_info) | |
4192 | { | |
4193 | if (pdi->lowpc < *lowpc) | |
4194 | *lowpc = pdi->lowpc; | |
4195 | if (pdi->highpc > *highpc) | |
4196 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4197 | if (need_pc) |
4198 | { | |
4199 | CORE_ADDR baseaddr; | |
4200 | struct objfile *objfile = cu->objfile; | |
4201 | ||
4202 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4203 | SECT_OFF_TEXT (objfile)); | |
4204 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4205 | pdi->lowpc + baseaddr, |
4206 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4207 | cu->per_cu->v.psymtab); |
5734ee8b | 4208 | } |
bc30ff58 | 4209 | if (!pdi->is_declaration) |
e8d05480 JB |
4210 | /* Ignore subprogram DIEs that do not have a name, they are |
4211 | illegal. Do not emit a complaint at this point, we will | |
4212 | do so when we convert this psymtab into a symtab. */ | |
4213 | if (pdi->name) | |
4214 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4215 | } |
4216 | } | |
6e70227d | 4217 | |
bc30ff58 JB |
4218 | if (! pdi->has_children) |
4219 | return; | |
4220 | ||
4221 | if (cu->language == language_ada) | |
4222 | { | |
4223 | pdi = pdi->die_child; | |
4224 | while (pdi != NULL) | |
4225 | { | |
4226 | fixup_partial_die (pdi, cu); | |
4227 | if (pdi->tag == DW_TAG_subprogram | |
4228 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4229 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4230 | pdi = pdi->die_sibling; |
4231 | } | |
4232 | } | |
4233 | } | |
4234 | ||
91c24f0a DC |
4235 | /* Read a partial die corresponding to an enumeration type. */ |
4236 | ||
72bf9492 DJ |
4237 | static void |
4238 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4239 | struct dwarf2_cu *cu) | |
91c24f0a | 4240 | { |
72bf9492 | 4241 | struct partial_die_info *pdi; |
91c24f0a DC |
4242 | |
4243 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4244 | add_partial_symbol (enum_pdi, cu); |
4245 | ||
4246 | pdi = enum_pdi->die_child; | |
4247 | while (pdi) | |
91c24f0a | 4248 | { |
72bf9492 | 4249 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4250 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4251 | else |
72bf9492 DJ |
4252 | add_partial_symbol (pdi, cu); |
4253 | pdi = pdi->die_sibling; | |
91c24f0a | 4254 | } |
91c24f0a DC |
4255 | } |
4256 | ||
4bb7a0a7 DJ |
4257 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4258 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4259 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4260 | the initial number. */ | |
4261 | ||
4262 | static struct abbrev_info * | |
fe1b8b76 | 4263 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4264 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4265 | { |
4266 | bfd *abfd = cu->objfile->obfd; | |
4267 | unsigned int abbrev_number; | |
4268 | struct abbrev_info *abbrev; | |
4269 | ||
4270 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4271 | ||
4272 | if (abbrev_number == 0) | |
4273 | return NULL; | |
4274 | ||
4275 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4276 | if (!abbrev) | |
4277 | { | |
3e43a32a MS |
4278 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4279 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4280 | } |
4281 | ||
4282 | return abbrev; | |
4283 | } | |
4284 | ||
93311388 DE |
4285 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4286 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4287 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4288 | ||
fe1b8b76 | 4289 | static gdb_byte * |
93311388 | 4290 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4291 | { |
4292 | struct abbrev_info *abbrev; | |
4293 | unsigned int bytes_read; | |
4294 | ||
4295 | while (1) | |
4296 | { | |
4297 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4298 | if (abbrev == NULL) | |
4299 | return info_ptr + bytes_read; | |
4300 | else | |
93311388 | 4301 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4302 | } |
4303 | } | |
4304 | ||
93311388 DE |
4305 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4306 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4307 | abbrev corresponding to that skipped uleb128 should be passed in |
4308 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4309 | children. */ | |
4310 | ||
fe1b8b76 | 4311 | static gdb_byte * |
93311388 DE |
4312 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4313 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4314 | { |
4315 | unsigned int bytes_read; | |
4316 | struct attribute attr; | |
4317 | bfd *abfd = cu->objfile->obfd; | |
4318 | unsigned int form, i; | |
4319 | ||
4320 | for (i = 0; i < abbrev->num_attrs; i++) | |
4321 | { | |
4322 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4323 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4324 | { | |
4325 | read_attribute (&attr, &abbrev->attrs[i], | |
4326 | abfd, info_ptr, cu); | |
4327 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
4328 | complaint (&symfile_complaints, |
4329 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4330 | else |
93311388 | 4331 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4332 | } |
4333 | ||
4334 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4335 | form = abbrev->attrs[i].form; | |
4336 | skip_attribute: | |
4337 | switch (form) | |
4338 | { | |
4bb7a0a7 | 4339 | case DW_FORM_ref_addr: |
ae411497 TT |
4340 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4341 | and later it is offset sized. */ | |
4342 | if (cu->header.version == 2) | |
4343 | info_ptr += cu->header.addr_size; | |
4344 | else | |
4345 | info_ptr += cu->header.offset_size; | |
4346 | break; | |
4347 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4348 | info_ptr += cu->header.addr_size; |
4349 | break; | |
4350 | case DW_FORM_data1: | |
4351 | case DW_FORM_ref1: | |
4352 | case DW_FORM_flag: | |
4353 | info_ptr += 1; | |
4354 | break; | |
2dc7f7b3 TT |
4355 | case DW_FORM_flag_present: |
4356 | break; | |
4bb7a0a7 DJ |
4357 | case DW_FORM_data2: |
4358 | case DW_FORM_ref2: | |
4359 | info_ptr += 2; | |
4360 | break; | |
4361 | case DW_FORM_data4: | |
4362 | case DW_FORM_ref4: | |
4363 | info_ptr += 4; | |
4364 | break; | |
4365 | case DW_FORM_data8: | |
4366 | case DW_FORM_ref8: | |
55f1336d | 4367 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4368 | info_ptr += 8; |
4369 | break; | |
4370 | case DW_FORM_string: | |
9b1c24c8 | 4371 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4372 | info_ptr += bytes_read; |
4373 | break; | |
2dc7f7b3 | 4374 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4375 | case DW_FORM_strp: |
4376 | info_ptr += cu->header.offset_size; | |
4377 | break; | |
2dc7f7b3 | 4378 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4379 | case DW_FORM_block: |
4380 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4381 | info_ptr += bytes_read; | |
4382 | break; | |
4383 | case DW_FORM_block1: | |
4384 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4385 | break; | |
4386 | case DW_FORM_block2: | |
4387 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4388 | break; | |
4389 | case DW_FORM_block4: | |
4390 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4391 | break; | |
4392 | case DW_FORM_sdata: | |
4393 | case DW_FORM_udata: | |
4394 | case DW_FORM_ref_udata: | |
4395 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4396 | break; | |
4397 | case DW_FORM_indirect: | |
4398 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4399 | info_ptr += bytes_read; | |
4400 | /* We need to continue parsing from here, so just go back to | |
4401 | the top. */ | |
4402 | goto skip_attribute; | |
4403 | ||
4404 | default: | |
3e43a32a MS |
4405 | error (_("Dwarf Error: Cannot handle %s " |
4406 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4407 | dwarf_form_name (form), |
4408 | bfd_get_filename (abfd)); | |
4409 | } | |
4410 | } | |
4411 | ||
4412 | if (abbrev->has_children) | |
93311388 | 4413 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4414 | else |
4415 | return info_ptr; | |
4416 | } | |
4417 | ||
93311388 DE |
4418 | /* Locate ORIG_PDI's sibling. |
4419 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4420 | in BUFFER. */ | |
91c24f0a | 4421 | |
fe1b8b76 | 4422 | static gdb_byte * |
93311388 DE |
4423 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4424 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4425 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4426 | { |
4427 | /* Do we know the sibling already? */ | |
72bf9492 | 4428 | |
91c24f0a DC |
4429 | if (orig_pdi->sibling) |
4430 | return orig_pdi->sibling; | |
4431 | ||
4432 | /* Are there any children to deal with? */ | |
4433 | ||
4434 | if (!orig_pdi->has_children) | |
4435 | return info_ptr; | |
4436 | ||
4bb7a0a7 | 4437 | /* Skip the children the long way. */ |
91c24f0a | 4438 | |
93311388 | 4439 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4440 | } |
4441 | ||
c906108c SS |
4442 | /* Expand this partial symbol table into a full symbol table. */ |
4443 | ||
4444 | static void | |
fba45db2 | 4445 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4446 | { |
c906108c SS |
4447 | if (pst != NULL) |
4448 | { | |
4449 | if (pst->readin) | |
4450 | { | |
3e43a32a MS |
4451 | warning (_("bug: psymtab for %s is already read in."), |
4452 | pst->filename); | |
c906108c SS |
4453 | } |
4454 | else | |
4455 | { | |
4456 | if (info_verbose) | |
4457 | { | |
3e43a32a MS |
4458 | printf_filtered (_("Reading in symbols for %s..."), |
4459 | pst->filename); | |
c906108c SS |
4460 | gdb_flush (gdb_stdout); |
4461 | } | |
4462 | ||
10b3939b DJ |
4463 | /* Restore our global data. */ |
4464 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4465 | dwarf2_objfile_data_key); | |
4466 | ||
b2ab525c KB |
4467 | /* If this psymtab is constructed from a debug-only objfile, the |
4468 | has_section_at_zero flag will not necessarily be correct. We | |
4469 | can get the correct value for this flag by looking at the data | |
4470 | associated with the (presumably stripped) associated objfile. */ | |
4471 | if (pst->objfile->separate_debug_objfile_backlink) | |
4472 | { | |
4473 | struct dwarf2_per_objfile *dpo_backlink | |
4474 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4475 | dwarf2_objfile_data_key); | |
9a619af0 | 4476 | |
b2ab525c KB |
4477 | dwarf2_per_objfile->has_section_at_zero |
4478 | = dpo_backlink->has_section_at_zero; | |
4479 | } | |
4480 | ||
98bfdba5 PA |
4481 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4482 | ||
c906108c SS |
4483 | psymtab_to_symtab_1 (pst); |
4484 | ||
4485 | /* Finish up the debug error message. */ | |
4486 | if (info_verbose) | |
a3f17187 | 4487 | printf_filtered (_("done.\n")); |
c906108c SS |
4488 | } |
4489 | } | |
4490 | } | |
4491 | ||
10b3939b DJ |
4492 | /* Add PER_CU to the queue. */ |
4493 | ||
4494 | static void | |
03dd20cc | 4495 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
4496 | { |
4497 | struct dwarf2_queue_item *item; | |
4498 | ||
4499 | per_cu->queued = 1; | |
4500 | item = xmalloc (sizeof (*item)); | |
4501 | item->per_cu = per_cu; | |
4502 | item->next = NULL; | |
4503 | ||
4504 | if (dwarf2_queue == NULL) | |
4505 | dwarf2_queue = item; | |
4506 | else | |
4507 | dwarf2_queue_tail->next = item; | |
4508 | ||
4509 | dwarf2_queue_tail = item; | |
4510 | } | |
4511 | ||
4512 | /* Process the queue. */ | |
4513 | ||
4514 | static void | |
4515 | process_queue (struct objfile *objfile) | |
4516 | { | |
4517 | struct dwarf2_queue_item *item, *next_item; | |
4518 | ||
03dd20cc DJ |
4519 | /* The queue starts out with one item, but following a DIE reference |
4520 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4521 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4522 | { | |
9291a0cd TT |
4523 | if (dwarf2_per_objfile->using_index |
4524 | ? !item->per_cu->v.quick->symtab | |
4525 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4526 | process_full_comp_unit (item->per_cu); |
4527 | ||
4528 | item->per_cu->queued = 0; | |
4529 | next_item = item->next; | |
4530 | xfree (item); | |
4531 | } | |
4532 | ||
4533 | dwarf2_queue_tail = NULL; | |
4534 | } | |
4535 | ||
4536 | /* Free all allocated queue entries. This function only releases anything if | |
4537 | an error was thrown; if the queue was processed then it would have been | |
4538 | freed as we went along. */ | |
4539 | ||
4540 | static void | |
4541 | dwarf2_release_queue (void *dummy) | |
4542 | { | |
4543 | struct dwarf2_queue_item *item, *last; | |
4544 | ||
4545 | item = dwarf2_queue; | |
4546 | while (item) | |
4547 | { | |
4548 | /* Anything still marked queued is likely to be in an | |
4549 | inconsistent state, so discard it. */ | |
4550 | if (item->per_cu->queued) | |
4551 | { | |
4552 | if (item->per_cu->cu != NULL) | |
4553 | free_one_cached_comp_unit (item->per_cu->cu); | |
4554 | item->per_cu->queued = 0; | |
4555 | } | |
4556 | ||
4557 | last = item; | |
4558 | item = item->next; | |
4559 | xfree (last); | |
4560 | } | |
4561 | ||
4562 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4563 | } | |
4564 | ||
4565 | /* Read in full symbols for PST, and anything it depends on. */ | |
4566 | ||
c906108c | 4567 | static void |
fba45db2 | 4568 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4569 | { |
10b3939b | 4570 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4571 | struct cleanup *back_to; |
aaa75496 JB |
4572 | int i; |
4573 | ||
4574 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4575 | if (!pst->dependencies[i]->readin) | |
4576 | { | |
4577 | /* Inform about additional files that need to be read in. */ | |
4578 | if (info_verbose) | |
4579 | { | |
a3f17187 | 4580 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4581 | fputs_filtered (" ", gdb_stdout); |
4582 | wrap_here (""); | |
4583 | fputs_filtered ("and ", gdb_stdout); | |
4584 | wrap_here (""); | |
4585 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4586 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4587 | gdb_flush (gdb_stdout); |
4588 | } | |
4589 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4590 | } | |
4591 | ||
e38df1d0 | 4592 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4593 | |
4594 | if (per_cu == NULL) | |
aaa75496 JB |
4595 | { |
4596 | /* It's an include file, no symbols to read for it. | |
4597 | Everything is in the parent symtab. */ | |
4598 | pst->readin = 1; | |
4599 | return; | |
4600 | } | |
c906108c | 4601 | |
9291a0cd | 4602 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4603 | } |
4604 | ||
93311388 | 4605 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4606 | |
93311388 | 4607 | static void |
3e43a32a MS |
4608 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
4609 | struct objfile *objfile) | |
10b3939b | 4610 | { |
31ffec48 | 4611 | bfd *abfd = objfile->obfd; |
10b3939b | 4612 | struct dwarf2_cu *cu; |
c764a876 | 4613 | unsigned int offset; |
93311388 | 4614 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4615 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4616 | struct attribute *attr; |
98bfdba5 | 4617 | int read_cu = 0; |
6502dd73 | 4618 | |
8b70b953 | 4619 | gdb_assert (! per_cu->debug_type_section); |
348e048f | 4620 | |
c906108c | 4621 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4622 | offset = per_cu->offset; |
6502dd73 | 4623 | |
be391dca | 4624 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4625 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4626 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4627 | |
98bfdba5 PA |
4628 | if (per_cu->cu == NULL) |
4629 | { | |
9816fde3 JK |
4630 | cu = xmalloc (sizeof (*cu)); |
4631 | init_one_comp_unit (cu, objfile); | |
98bfdba5 PA |
4632 | |
4633 | read_cu = 1; | |
c906108c | 4634 | |
98bfdba5 PA |
4635 | /* If an error occurs while loading, release our storage. */ |
4636 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4637 | |
98bfdba5 PA |
4638 | /* Read in the comp_unit header. */ |
4639 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4640 | |
98bfdba5 PA |
4641 | /* Complete the cu_header. */ |
4642 | cu->header.offset = offset; | |
4643 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4644 | |
98bfdba5 PA |
4645 | /* Read the abbrevs for this compilation unit. */ |
4646 | dwarf2_read_abbrevs (abfd, cu); | |
4647 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10b3939b | 4648 | |
98bfdba5 PA |
4649 | /* Link this compilation unit into the compilation unit tree. */ |
4650 | per_cu->cu = cu; | |
4651 | cu->per_cu = per_cu; | |
98bfdba5 PA |
4652 | |
4653 | /* Link this CU into read_in_chain. */ | |
4654 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4655 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4656 | } | |
4657 | else | |
4658 | { | |
4659 | cu = per_cu->cu; | |
4660 | info_ptr += cu->header.first_die_offset; | |
4661 | } | |
e142c38c | 4662 | |
93311388 | 4663 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4664 | |
4665 | /* We try not to read any attributes in this function, because not | |
4666 | all objfiles needed for references have been loaded yet, and symbol | |
4667 | table processing isn't initialized. But we have to set the CU language, | |
4668 | or we won't be able to build types correctly. */ | |
9816fde3 | 4669 | prepare_one_comp_unit (cu, cu->dies); |
10b3939b | 4670 | |
a6c727b2 DJ |
4671 | /* Similarly, if we do not read the producer, we can not apply |
4672 | producer-specific interpretation. */ | |
4673 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4674 | if (attr) | |
4675 | cu->producer = DW_STRING (attr); | |
4676 | ||
98bfdba5 PA |
4677 | if (read_cu) |
4678 | { | |
4679 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4680 | |
98bfdba5 PA |
4681 | /* We've successfully allocated this compilation unit. Let our |
4682 | caller clean it up when finished with it. */ | |
4683 | discard_cleanups (free_cu_cleanup); | |
4684 | } | |
10b3939b DJ |
4685 | } |
4686 | ||
3da10d80 KS |
4687 | /* Add a DIE to the delayed physname list. */ |
4688 | ||
4689 | static void | |
4690 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4691 | const char *name, struct die_info *die, | |
4692 | struct dwarf2_cu *cu) | |
4693 | { | |
4694 | struct delayed_method_info mi; | |
4695 | mi.type = type; | |
4696 | mi.fnfield_index = fnfield_index; | |
4697 | mi.index = index; | |
4698 | mi.name = name; | |
4699 | mi.die = die; | |
4700 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4701 | } | |
4702 | ||
4703 | /* A cleanup for freeing the delayed method list. */ | |
4704 | ||
4705 | static void | |
4706 | free_delayed_list (void *ptr) | |
4707 | { | |
4708 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4709 | if (cu->method_list != NULL) | |
4710 | { | |
4711 | VEC_free (delayed_method_info, cu->method_list); | |
4712 | cu->method_list = NULL; | |
4713 | } | |
4714 | } | |
4715 | ||
4716 | /* Compute the physnames of any methods on the CU's method list. | |
4717 | ||
4718 | The computation of method physnames is delayed in order to avoid the | |
4719 | (bad) condition that one of the method's formal parameters is of an as yet | |
4720 | incomplete type. */ | |
4721 | ||
4722 | static void | |
4723 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4724 | { | |
4725 | int i; | |
4726 | struct delayed_method_info *mi; | |
4727 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4728 | { | |
1d06ead6 | 4729 | const char *physname; |
3da10d80 KS |
4730 | struct fn_fieldlist *fn_flp |
4731 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 4732 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
4733 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
4734 | } | |
4735 | } | |
4736 | ||
10b3939b DJ |
4737 | /* Generate full symbol information for PST and CU, whose DIEs have |
4738 | already been loaded into memory. */ | |
4739 | ||
4740 | static void | |
4741 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4742 | { | |
10b3939b | 4743 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4744 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4745 | CORE_ADDR lowpc, highpc; |
4746 | struct symtab *symtab; | |
3da10d80 | 4747 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4748 | CORE_ADDR baseaddr; |
4749 | ||
4750 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4751 | ||
10b3939b DJ |
4752 | buildsym_init (); |
4753 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4754 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4755 | |
4756 | cu->list_in_scope = &file_symbols; | |
c906108c SS |
4757 | |
4758 | /* Do line number decoding in read_file_scope () */ | |
10b3939b | 4759 | process_die (cu->dies, cu); |
c906108c | 4760 | |
3da10d80 KS |
4761 | /* Now that we have processed all the DIEs in the CU, all the types |
4762 | should be complete, and it should now be safe to compute all of the | |
4763 | physnames. */ | |
4764 | compute_delayed_physnames (cu); | |
4765 | do_cleanups (delayed_list_cleanup); | |
4766 | ||
fae299cd DC |
4767 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4768 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4769 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4770 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4771 | |
613e1657 | 4772 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 4773 | |
8be455d7 | 4774 | if (symtab != NULL) |
c906108c | 4775 | { |
df15bd07 | 4776 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 4777 | |
8be455d7 JK |
4778 | /* Set symtab language to language from DW_AT_language. If the |
4779 | compilation is from a C file generated by language preprocessors, do | |
4780 | not set the language if it was already deduced by start_subfile. */ | |
4781 | if (!(cu->language == language_c && symtab->language != language_c)) | |
4782 | symtab->language = cu->language; | |
4783 | ||
4784 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
4785 | produce DW_AT_location with location lists but it can be possibly | |
4786 | invalid without -fvar-tracking. | |
4787 | ||
4788 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
4789 | needed, it would be wrong due to missing DW_AT_producer there. | |
4790 | ||
4791 | Still one can confuse GDB by using non-standard GCC compilation | |
4792 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
4793 | */ | |
4632c0d0 | 4794 | if (cu->has_loclist && gcc_4_minor >= 0) |
8be455d7 | 4795 | symtab->locations_valid = 1; |
e0d00bc7 JK |
4796 | |
4797 | if (gcc_4_minor >= 5) | |
4798 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
4799 | |
4800 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 4801 | } |
9291a0cd TT |
4802 | |
4803 | if (dwarf2_per_objfile->using_index) | |
4804 | per_cu->v.quick->symtab = symtab; | |
4805 | else | |
4806 | { | |
4807 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4808 | pst->symtab = symtab; | |
4809 | pst->readin = 1; | |
4810 | } | |
c906108c SS |
4811 | |
4812 | do_cleanups (back_to); | |
4813 | } | |
4814 | ||
4815 | /* Process a die and its children. */ | |
4816 | ||
4817 | static void | |
e7c27a73 | 4818 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4819 | { |
4820 | switch (die->tag) | |
4821 | { | |
4822 | case DW_TAG_padding: | |
4823 | break; | |
4824 | case DW_TAG_compile_unit: | |
e7c27a73 | 4825 | read_file_scope (die, cu); |
c906108c | 4826 | break; |
348e048f DE |
4827 | case DW_TAG_type_unit: |
4828 | read_type_unit_scope (die, cu); | |
4829 | break; | |
c906108c | 4830 | case DW_TAG_subprogram: |
c906108c | 4831 | case DW_TAG_inlined_subroutine: |
edb3359d | 4832 | read_func_scope (die, cu); |
c906108c SS |
4833 | break; |
4834 | case DW_TAG_lexical_block: | |
14898363 L |
4835 | case DW_TAG_try_block: |
4836 | case DW_TAG_catch_block: | |
e7c27a73 | 4837 | read_lexical_block_scope (die, cu); |
c906108c | 4838 | break; |
96408a79 SA |
4839 | case DW_TAG_GNU_call_site: |
4840 | read_call_site_scope (die, cu); | |
4841 | break; | |
c906108c | 4842 | case DW_TAG_class_type: |
680b30c7 | 4843 | case DW_TAG_interface_type: |
c906108c SS |
4844 | case DW_TAG_structure_type: |
4845 | case DW_TAG_union_type: | |
134d01f1 | 4846 | process_structure_scope (die, cu); |
c906108c SS |
4847 | break; |
4848 | case DW_TAG_enumeration_type: | |
134d01f1 | 4849 | process_enumeration_scope (die, cu); |
c906108c | 4850 | break; |
134d01f1 | 4851 | |
f792889a DJ |
4852 | /* These dies have a type, but processing them does not create |
4853 | a symbol or recurse to process the children. Therefore we can | |
4854 | read them on-demand through read_type_die. */ | |
c906108c | 4855 | case DW_TAG_subroutine_type: |
72019c9c | 4856 | case DW_TAG_set_type: |
c906108c | 4857 | case DW_TAG_array_type: |
c906108c | 4858 | case DW_TAG_pointer_type: |
c906108c | 4859 | case DW_TAG_ptr_to_member_type: |
c906108c | 4860 | case DW_TAG_reference_type: |
c906108c | 4861 | case DW_TAG_string_type: |
c906108c | 4862 | break; |
134d01f1 | 4863 | |
c906108c | 4864 | case DW_TAG_base_type: |
a02abb62 | 4865 | case DW_TAG_subrange_type: |
cb249c71 | 4866 | case DW_TAG_typedef: |
134d01f1 DJ |
4867 | /* Add a typedef symbol for the type definition, if it has a |
4868 | DW_AT_name. */ | |
f792889a | 4869 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4870 | break; |
c906108c | 4871 | case DW_TAG_common_block: |
e7c27a73 | 4872 | read_common_block (die, cu); |
c906108c SS |
4873 | break; |
4874 | case DW_TAG_common_inclusion: | |
4875 | break; | |
d9fa45fe | 4876 | case DW_TAG_namespace: |
63d06c5c | 4877 | processing_has_namespace_info = 1; |
e7c27a73 | 4878 | read_namespace (die, cu); |
d9fa45fe | 4879 | break; |
5d7cb8df | 4880 | case DW_TAG_module: |
f55ee35c | 4881 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4882 | read_module (die, cu); |
4883 | break; | |
d9fa45fe DC |
4884 | case DW_TAG_imported_declaration: |
4885 | case DW_TAG_imported_module: | |
63d06c5c | 4886 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4887 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4888 | || cu->language != language_fortran)) | |
4889 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4890 | dwarf_tag_name (die->tag)); | |
4891 | read_import_statement (die, cu); | |
d9fa45fe | 4892 | break; |
c906108c | 4893 | default: |
e7c27a73 | 4894 | new_symbol (die, NULL, cu); |
c906108c SS |
4895 | break; |
4896 | } | |
4897 | } | |
4898 | ||
94af9270 KS |
4899 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4900 | needs to have the name of the scope prepended to the name listed in the | |
4901 | die. */ | |
4902 | ||
4903 | static int | |
4904 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4905 | { | |
1c809c68 TT |
4906 | struct attribute *attr; |
4907 | ||
94af9270 KS |
4908 | switch (die->tag) |
4909 | { | |
4910 | case DW_TAG_namespace: | |
4911 | case DW_TAG_typedef: | |
4912 | case DW_TAG_class_type: | |
4913 | case DW_TAG_interface_type: | |
4914 | case DW_TAG_structure_type: | |
4915 | case DW_TAG_union_type: | |
4916 | case DW_TAG_enumeration_type: | |
4917 | case DW_TAG_enumerator: | |
4918 | case DW_TAG_subprogram: | |
4919 | case DW_TAG_member: | |
4920 | return 1; | |
4921 | ||
4922 | case DW_TAG_variable: | |
c2b0a229 | 4923 | case DW_TAG_constant: |
94af9270 KS |
4924 | /* We only need to prefix "globally" visible variables. These include |
4925 | any variable marked with DW_AT_external or any variable that | |
4926 | lives in a namespace. [Variables in anonymous namespaces | |
4927 | require prefixing, but they are not DW_AT_external.] */ | |
4928 | ||
4929 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4930 | { | |
4931 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4932 | |
94af9270 KS |
4933 | return die_needs_namespace (die_specification (die, &spec_cu), |
4934 | spec_cu); | |
4935 | } | |
4936 | ||
1c809c68 | 4937 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4938 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4939 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4940 | return 0; |
4941 | /* A variable in a lexical block of some kind does not need a | |
4942 | namespace, even though in C++ such variables may be external | |
4943 | and have a mangled name. */ | |
4944 | if (die->parent->tag == DW_TAG_lexical_block | |
4945 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4946 | || die->parent->tag == DW_TAG_catch_block |
4947 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4948 | return 0; |
4949 | return 1; | |
94af9270 KS |
4950 | |
4951 | default: | |
4952 | return 0; | |
4953 | } | |
4954 | } | |
4955 | ||
98bfdba5 PA |
4956 | /* Retrieve the last character from a mem_file. */ |
4957 | ||
4958 | static void | |
4959 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4960 | { | |
4961 | char *last_char_p = (char *) object; | |
4962 | ||
4963 | if (length > 0) | |
4964 | *last_char_p = buffer[length - 1]; | |
4965 | } | |
4966 | ||
94af9270 KS |
4967 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4968 | compute the physname for the object, which include a method's | |
4969 | formal parameters (C++/Java) and return type (Java). | |
4970 | ||
af6b7be1 JB |
4971 | For Ada, return the DIE's linkage name rather than the fully qualified |
4972 | name. PHYSNAME is ignored.. | |
4973 | ||
94af9270 KS |
4974 | The result is allocated on the objfile_obstack and canonicalized. */ |
4975 | ||
4976 | static const char * | |
4977 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4978 | int physname) | |
4979 | { | |
4980 | if (name == NULL) | |
4981 | name = dwarf2_name (die, cu); | |
4982 | ||
f55ee35c JK |
4983 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4984 | compute it by typename_concat inside GDB. */ | |
4985 | if (cu->language == language_ada | |
4986 | || (cu->language == language_fortran && physname)) | |
4987 | { | |
4988 | /* For Ada unit, we prefer the linkage name over the name, as | |
4989 | the former contains the exported name, which the user expects | |
4990 | to be able to reference. Ideally, we want the user to be able | |
4991 | to reference this entity using either natural or linkage name, | |
4992 | but we haven't started looking at this enhancement yet. */ | |
4993 | struct attribute *attr; | |
4994 | ||
4995 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4996 | if (attr == NULL) | |
4997 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4998 | if (attr && DW_STRING (attr)) | |
4999 | return DW_STRING (attr); | |
5000 | } | |
5001 | ||
94af9270 KS |
5002 | /* These are the only languages we know how to qualify names in. */ |
5003 | if (name != NULL | |
f55ee35c JK |
5004 | && (cu->language == language_cplus || cu->language == language_java |
5005 | || cu->language == language_fortran)) | |
94af9270 KS |
5006 | { |
5007 | if (die_needs_namespace (die, cu)) | |
5008 | { | |
5009 | long length; | |
5010 | char *prefix; | |
5011 | struct ui_file *buf; | |
5012 | ||
5013 | prefix = determine_prefix (die, cu); | |
5014 | buf = mem_fileopen (); | |
5015 | if (*prefix != '\0') | |
5016 | { | |
f55ee35c JK |
5017 | char *prefixed_name = typename_concat (NULL, prefix, name, |
5018 | physname, cu); | |
9a619af0 | 5019 | |
94af9270 KS |
5020 | fputs_unfiltered (prefixed_name, buf); |
5021 | xfree (prefixed_name); | |
5022 | } | |
5023 | else | |
62d5b8da | 5024 | fputs_unfiltered (name, buf); |
94af9270 | 5025 | |
98bfdba5 PA |
5026 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
5027 | as children with DW_TAG_template_type_param or | |
5028 | DW_TAG_value_type_param. If the latter, add them to the name | |
5029 | here. If the name already has template parameters, then | |
5030 | skip this step; some versions of GCC emit both, and | |
5031 | it is more efficient to use the pre-computed name. | |
5032 | ||
5033 | Something to keep in mind about this process: it is very | |
5034 | unlikely, or in some cases downright impossible, to produce | |
5035 | something that will match the mangled name of a function. | |
5036 | If the definition of the function has the same debug info, | |
5037 | we should be able to match up with it anyway. But fallbacks | |
5038 | using the minimal symbol, for instance to find a method | |
5039 | implemented in a stripped copy of libstdc++, will not work. | |
5040 | If we do not have debug info for the definition, we will have to | |
5041 | match them up some other way. | |
5042 | ||
5043 | When we do name matching there is a related problem with function | |
5044 | templates; two instantiated function templates are allowed to | |
5045 | differ only by their return types, which we do not add here. */ | |
5046 | ||
5047 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
5048 | { | |
5049 | struct attribute *attr; | |
5050 | struct die_info *child; | |
5051 | int first = 1; | |
5052 | ||
5053 | die->building_fullname = 1; | |
5054 | ||
5055 | for (child = die->child; child != NULL; child = child->sibling) | |
5056 | { | |
5057 | struct type *type; | |
5058 | long value; | |
5059 | gdb_byte *bytes; | |
5060 | struct dwarf2_locexpr_baton *baton; | |
5061 | struct value *v; | |
5062 | ||
5063 | if (child->tag != DW_TAG_template_type_param | |
5064 | && child->tag != DW_TAG_template_value_param) | |
5065 | continue; | |
5066 | ||
5067 | if (first) | |
5068 | { | |
5069 | fputs_unfiltered ("<", buf); | |
5070 | first = 0; | |
5071 | } | |
5072 | else | |
5073 | fputs_unfiltered (", ", buf); | |
5074 | ||
5075 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5076 | if (attr == NULL) | |
5077 | { | |
5078 | complaint (&symfile_complaints, | |
5079 | _("template parameter missing DW_AT_type")); | |
5080 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5081 | continue; | |
5082 | } | |
5083 | type = die_type (child, cu); | |
5084 | ||
5085 | if (child->tag == DW_TAG_template_type_param) | |
5086 | { | |
5087 | c_print_type (type, "", buf, -1, 0); | |
5088 | continue; | |
5089 | } | |
5090 | ||
5091 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5092 | if (attr == NULL) | |
5093 | { | |
5094 | complaint (&symfile_complaints, | |
3e43a32a MS |
5095 | _("template parameter missing " |
5096 | "DW_AT_const_value")); | |
98bfdba5 PA |
5097 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5098 | continue; | |
5099 | } | |
5100 | ||
5101 | dwarf2_const_value_attr (attr, type, name, | |
5102 | &cu->comp_unit_obstack, cu, | |
5103 | &value, &bytes, &baton); | |
5104 | ||
5105 | if (TYPE_NOSIGN (type)) | |
5106 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5107 | changed, this can use value_print instead. */ | |
5108 | c_printchar (value, type, buf); | |
5109 | else | |
5110 | { | |
5111 | struct value_print_options opts; | |
5112 | ||
5113 | if (baton != NULL) | |
5114 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5115 | baton->data, | |
5116 | baton->size, | |
5117 | baton->per_cu); | |
5118 | else if (bytes != NULL) | |
5119 | { | |
5120 | v = allocate_value (type); | |
5121 | memcpy (value_contents_writeable (v), bytes, | |
5122 | TYPE_LENGTH (type)); | |
5123 | } | |
5124 | else | |
5125 | v = value_from_longest (type, value); | |
5126 | ||
3e43a32a MS |
5127 | /* Specify decimal so that we do not depend on |
5128 | the radix. */ | |
98bfdba5 PA |
5129 | get_formatted_print_options (&opts, 'd'); |
5130 | opts.raw = 1; | |
5131 | value_print (v, buf, &opts); | |
5132 | release_value (v); | |
5133 | value_free (v); | |
5134 | } | |
5135 | } | |
5136 | ||
5137 | die->building_fullname = 0; | |
5138 | ||
5139 | if (!first) | |
5140 | { | |
5141 | /* Close the argument list, with a space if necessary | |
5142 | (nested templates). */ | |
5143 | char last_char = '\0'; | |
5144 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5145 | if (last_char == '>') | |
5146 | fputs_unfiltered (" >", buf); | |
5147 | else | |
5148 | fputs_unfiltered (">", buf); | |
5149 | } | |
5150 | } | |
5151 | ||
94af9270 KS |
5152 | /* For Java and C++ methods, append formal parameter type |
5153 | information, if PHYSNAME. */ | |
6e70227d | 5154 | |
94af9270 KS |
5155 | if (physname && die->tag == DW_TAG_subprogram |
5156 | && (cu->language == language_cplus | |
5157 | || cu->language == language_java)) | |
5158 | { | |
5159 | struct type *type = read_type_die (die, cu); | |
5160 | ||
3167638f | 5161 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5162 | |
5163 | if (cu->language == language_java) | |
5164 | { | |
5165 | /* For java, we must append the return type to method | |
0963b4bd | 5166 | names. */ |
94af9270 KS |
5167 | if (die->tag == DW_TAG_subprogram) |
5168 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5169 | 0, 0); | |
5170 | } | |
5171 | else if (cu->language == language_cplus) | |
5172 | { | |
60430eff DJ |
5173 | /* Assume that an artificial first parameter is |
5174 | "this", but do not crash if it is not. RealView | |
5175 | marks unnamed (and thus unused) parameters as | |
5176 | artificial; there is no way to differentiate | |
5177 | the two cases. */ | |
94af9270 KS |
5178 | if (TYPE_NFIELDS (type) > 0 |
5179 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5180 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5181 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5182 | 0)))) | |
94af9270 KS |
5183 | fputs_unfiltered (" const", buf); |
5184 | } | |
5185 | } | |
5186 | ||
5187 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
5188 | &length); | |
5189 | ui_file_delete (buf); | |
5190 | ||
5191 | if (cu->language == language_cplus) | |
5192 | { | |
5193 | char *cname | |
5194 | = dwarf2_canonicalize_name (name, cu, | |
5195 | &cu->objfile->objfile_obstack); | |
9a619af0 | 5196 | |
94af9270 KS |
5197 | if (cname != NULL) |
5198 | name = cname; | |
5199 | } | |
5200 | } | |
5201 | } | |
5202 | ||
5203 | return name; | |
5204 | } | |
5205 | ||
0114d602 DJ |
5206 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5207 | If scope qualifiers are appropriate they will be added. The result | |
5208 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5209 | not have a name. NAME may either be from a previous call to |
5210 | dwarf2_name or NULL. | |
5211 | ||
0963b4bd | 5212 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5213 | |
5214 | static const char * | |
94af9270 | 5215 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5216 | { |
94af9270 KS |
5217 | return dwarf2_compute_name (name, die, cu, 0); |
5218 | } | |
0114d602 | 5219 | |
94af9270 KS |
5220 | /* Construct a physname for the given DIE in CU. NAME may either be |
5221 | from a previous call to dwarf2_name or NULL. The result will be | |
5222 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5223 | name. | |
0114d602 | 5224 | |
94af9270 | 5225 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5226 | |
94af9270 KS |
5227 | static const char * |
5228 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5229 | { | |
900e11f9 JK |
5230 | struct attribute *attr; |
5231 | const char *retval, *mangled = NULL, *canon = NULL; | |
5232 | struct cleanup *back_to; | |
5233 | int need_copy = 1; | |
5234 | ||
5235 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
5236 | on its own. */ | |
5237 | if (!die_needs_namespace (die, cu)) | |
5238 | return dwarf2_compute_name (name, die, cu, 1); | |
5239 | ||
5240 | back_to = make_cleanup (null_cleanup, NULL); | |
5241 | ||
5242 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5243 | if (!attr) | |
5244 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5245 | ||
5246 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
5247 | has computed. */ | |
5248 | if (attr && DW_STRING (attr)) | |
5249 | { | |
5250 | char *demangled; | |
5251 | ||
5252 | mangled = DW_STRING (attr); | |
5253 | ||
5254 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
5255 | type. It is easier for GDB users to search for such functions as | |
5256 | `name(params)' than `long name(params)'. In such case the minimal | |
5257 | symbol names do not match the full symbol names but for template | |
5258 | functions there is never a need to look up their definition from their | |
5259 | declaration so the only disadvantage remains the minimal symbol | |
5260 | variant `long name(params)' does not have the proper inferior type. | |
5261 | */ | |
5262 | ||
5263 | demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI | |
5264 | | (cu->language == language_java | |
5265 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
5266 | : DMGL_RET_DROP))); | |
5267 | if (demangled) | |
5268 | { | |
5269 | make_cleanup (xfree, demangled); | |
5270 | canon = demangled; | |
5271 | } | |
5272 | else | |
5273 | { | |
5274 | canon = mangled; | |
5275 | need_copy = 0; | |
5276 | } | |
5277 | } | |
5278 | ||
5279 | if (canon == NULL || check_physname) | |
5280 | { | |
5281 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
5282 | ||
5283 | if (canon != NULL && strcmp (physname, canon) != 0) | |
5284 | { | |
5285 | /* It may not mean a bug in GDB. The compiler could also | |
5286 | compute DW_AT_linkage_name incorrectly. But in such case | |
5287 | GDB would need to be bug-to-bug compatible. */ | |
5288 | ||
5289 | complaint (&symfile_complaints, | |
5290 | _("Computed physname <%s> does not match demangled <%s> " | |
5291 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
5292 | physname, canon, mangled, die->offset, cu->objfile->name); | |
5293 | ||
5294 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
5295 | is available here - over computed PHYSNAME. It is safer | |
5296 | against both buggy GDB and buggy compilers. */ | |
5297 | ||
5298 | retval = canon; | |
5299 | } | |
5300 | else | |
5301 | { | |
5302 | retval = physname; | |
5303 | need_copy = 0; | |
5304 | } | |
5305 | } | |
5306 | else | |
5307 | retval = canon; | |
5308 | ||
5309 | if (need_copy) | |
5310 | retval = obsavestring (retval, strlen (retval), | |
5311 | &cu->objfile->objfile_obstack); | |
5312 | ||
5313 | do_cleanups (back_to); | |
5314 | return retval; | |
0114d602 DJ |
5315 | } |
5316 | ||
27aa8d6a SW |
5317 | /* Read the import statement specified by the given die and record it. */ |
5318 | ||
5319 | static void | |
5320 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5321 | { | |
5322 | struct attribute *import_attr; | |
32019081 | 5323 | struct die_info *imported_die, *child_die; |
de4affc9 | 5324 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5325 | const char *imported_name; |
794684b6 | 5326 | const char *imported_name_prefix; |
13387711 SW |
5327 | const char *canonical_name; |
5328 | const char *import_alias; | |
5329 | const char *imported_declaration = NULL; | |
794684b6 | 5330 | const char *import_prefix; |
32019081 JK |
5331 | VEC (const_char_ptr) *excludes = NULL; |
5332 | struct cleanup *cleanups; | |
13387711 SW |
5333 | |
5334 | char *temp; | |
27aa8d6a SW |
5335 | |
5336 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5337 | if (import_attr == NULL) | |
5338 | { | |
5339 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5340 | dwarf_tag_name (die->tag)); | |
5341 | return; | |
5342 | } | |
5343 | ||
de4affc9 CC |
5344 | imported_cu = cu; |
5345 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5346 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5347 | if (imported_name == NULL) |
5348 | { | |
5349 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5350 | ||
5351 | The import in the following code: | |
5352 | namespace A | |
5353 | { | |
5354 | typedef int B; | |
5355 | } | |
5356 | ||
5357 | int main () | |
5358 | { | |
5359 | using A::B; | |
5360 | B b; | |
5361 | return b; | |
5362 | } | |
5363 | ||
5364 | ... | |
5365 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5366 | <52> DW_AT_decl_file : 1 | |
5367 | <53> DW_AT_decl_line : 6 | |
5368 | <54> DW_AT_import : <0x75> | |
5369 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5370 | <59> DW_AT_name : B | |
5371 | <5b> DW_AT_decl_file : 1 | |
5372 | <5c> DW_AT_decl_line : 2 | |
5373 | <5d> DW_AT_type : <0x6e> | |
5374 | ... | |
5375 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5376 | <76> DW_AT_byte_size : 4 | |
5377 | <77> DW_AT_encoding : 5 (signed) | |
5378 | ||
5379 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5380 | This case will be ignored until the gcc bug is fixed. */ | |
5381 | return; | |
5382 | } | |
5383 | ||
82856980 SW |
5384 | /* Figure out the local name after import. */ |
5385 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5386 | |
794684b6 SW |
5387 | /* Figure out where the statement is being imported to. */ |
5388 | import_prefix = determine_prefix (die, cu); | |
5389 | ||
5390 | /* Figure out what the scope of the imported die is and prepend it | |
5391 | to the name of the imported die. */ | |
de4affc9 | 5392 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5393 | |
f55ee35c JK |
5394 | if (imported_die->tag != DW_TAG_namespace |
5395 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5396 | { |
13387711 SW |
5397 | imported_declaration = imported_name; |
5398 | canonical_name = imported_name_prefix; | |
794684b6 | 5399 | } |
13387711 | 5400 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5401 | { |
13387711 SW |
5402 | temp = alloca (strlen (imported_name_prefix) |
5403 | + 2 + strlen (imported_name) + 1); | |
5404 | strcpy (temp, imported_name_prefix); | |
5405 | strcat (temp, "::"); | |
5406 | strcat (temp, imported_name); | |
5407 | canonical_name = temp; | |
794684b6 | 5408 | } |
13387711 SW |
5409 | else |
5410 | canonical_name = imported_name; | |
794684b6 | 5411 | |
32019081 JK |
5412 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
5413 | ||
5414 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
5415 | for (child_die = die->child; child_die && child_die->tag; | |
5416 | child_die = sibling_die (child_die)) | |
5417 | { | |
5418 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
5419 | represented by an imported module entry with an import attribute | |
5420 | referring to the module and owned entries corresponding to those | |
5421 | entities that are renamed as part of being imported. */ | |
5422 | ||
5423 | if (child_die->tag != DW_TAG_imported_declaration) | |
5424 | { | |
5425 | complaint (&symfile_complaints, | |
5426 | _("child DW_TAG_imported_declaration expected " | |
5427 | "- DIE at 0x%x [in module %s]"), | |
5428 | child_die->offset, cu->objfile->name); | |
5429 | continue; | |
5430 | } | |
5431 | ||
5432 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
5433 | if (import_attr == NULL) | |
5434 | { | |
5435 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5436 | dwarf_tag_name (child_die->tag)); | |
5437 | continue; | |
5438 | } | |
5439 | ||
5440 | imported_cu = cu; | |
5441 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
5442 | &imported_cu); | |
5443 | imported_name = dwarf2_name (imported_die, imported_cu); | |
5444 | if (imported_name == NULL) | |
5445 | { | |
5446 | complaint (&symfile_complaints, | |
5447 | _("child DW_TAG_imported_declaration has unknown " | |
5448 | "imported name - DIE at 0x%x [in module %s]"), | |
5449 | child_die->offset, cu->objfile->name); | |
5450 | continue; | |
5451 | } | |
5452 | ||
5453 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
5454 | ||
5455 | process_die (child_die, cu); | |
5456 | } | |
5457 | ||
c0cc3a76 SW |
5458 | cp_add_using_directive (import_prefix, |
5459 | canonical_name, | |
5460 | import_alias, | |
13387711 | 5461 | imported_declaration, |
32019081 | 5462 | excludes, |
c0cc3a76 | 5463 | &cu->objfile->objfile_obstack); |
32019081 JK |
5464 | |
5465 | do_cleanups (cleanups); | |
27aa8d6a SW |
5466 | } |
5467 | ||
5fb290d7 | 5468 | static void |
e142c38c | 5469 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 5470 | { |
e142c38c | 5471 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
5472 | } |
5473 | ||
ae2de4f8 DE |
5474 | /* Cleanup function for read_file_scope. */ |
5475 | ||
cb1df416 DJ |
5476 | static void |
5477 | free_cu_line_header (void *arg) | |
5478 | { | |
5479 | struct dwarf2_cu *cu = arg; | |
5480 | ||
5481 | free_line_header (cu->line_header); | |
5482 | cu->line_header = NULL; | |
5483 | } | |
5484 | ||
9291a0cd TT |
5485 | static void |
5486 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5487 | char **name, char **comp_dir) | |
5488 | { | |
5489 | struct attribute *attr; | |
5490 | ||
5491 | *name = NULL; | |
5492 | *comp_dir = NULL; | |
5493 | ||
5494 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5495 | is not a source language identifier. */ | |
5496 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5497 | if (attr) | |
5498 | { | |
5499 | *name = DW_STRING (attr); | |
5500 | } | |
5501 | ||
5502 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5503 | if (attr) | |
5504 | *comp_dir = DW_STRING (attr); | |
5505 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5506 | { | |
5507 | *comp_dir = ldirname (*name); | |
5508 | if (*comp_dir != NULL) | |
5509 | make_cleanup (xfree, *comp_dir); | |
5510 | } | |
5511 | if (*comp_dir != NULL) | |
5512 | { | |
5513 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5514 | directory, get rid of it. */ | |
5515 | char *cp = strchr (*comp_dir, ':'); | |
5516 | ||
5517 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5518 | *comp_dir = cp + 1; | |
5519 | } | |
5520 | ||
5521 | if (*name == NULL) | |
5522 | *name = "<unknown>"; | |
5523 | } | |
5524 | ||
2ab95328 TT |
5525 | /* Handle DW_AT_stmt_list for a compilation unit. */ |
5526 | ||
5527 | static void | |
5528 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
5529 | const char *comp_dir) | |
5530 | { | |
5531 | struct attribute *attr; | |
5532 | struct objfile *objfile = cu->objfile; | |
5533 | bfd *abfd = objfile->obfd; | |
5534 | ||
5535 | /* Decode line number information if present. We do this before | |
5536 | processing child DIEs, so that the line header table is available | |
5537 | for DW_AT_decl_file. */ | |
5538 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); | |
5539 | if (attr) | |
5540 | { | |
5541 | unsigned int line_offset = DW_UNSND (attr); | |
5542 | struct line_header *line_header | |
5543 | = dwarf_decode_line_header (line_offset, abfd, cu); | |
5544 | ||
5545 | if (line_header) | |
5546 | { | |
5547 | cu->line_header = line_header; | |
5548 | make_cleanup (free_cu_line_header, cu); | |
5549 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); | |
5550 | } | |
5551 | } | |
5552 | } | |
5553 | ||
ae2de4f8 DE |
5554 | /* Process DW_TAG_compile_unit. */ |
5555 | ||
c906108c | 5556 | static void |
e7c27a73 | 5557 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5558 | { |
e7c27a73 | 5559 | struct objfile *objfile = cu->objfile; |
debd256d | 5560 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5561 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5562 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5563 | struct attribute *attr; | |
e1024ff1 | 5564 | char *name = NULL; |
c906108c SS |
5565 | char *comp_dir = NULL; |
5566 | struct die_info *child_die; | |
5567 | bfd *abfd = objfile->obfd; | |
e142c38c | 5568 | CORE_ADDR baseaddr; |
6e70227d | 5569 | |
e142c38c | 5570 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5571 | |
fae299cd | 5572 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5573 | |
5574 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5575 | from finish_block. */ | |
2acceee2 | 5576 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5577 | lowpc = highpc; |
5578 | lowpc += baseaddr; | |
5579 | highpc += baseaddr; | |
5580 | ||
9291a0cd | 5581 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5582 | |
e142c38c | 5583 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5584 | if (attr) |
5585 | { | |
e142c38c | 5586 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5587 | } |
5588 | ||
b0f35d58 | 5589 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5590 | if (attr) |
b0f35d58 | 5591 | cu->producer = DW_STRING (attr); |
303b6f5d | 5592 | |
f4b8a18d KW |
5593 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5594 | standardised yet. As a workaround for the language detection we fall | |
5595 | back to the DW_AT_producer string. */ | |
5596 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5597 | cu->language = language_opencl; | |
5598 | ||
0963b4bd | 5599 | /* We assume that we're processing GCC output. */ |
c906108c | 5600 | processing_gcc_compilation = 2; |
c906108c | 5601 | |
df8a16a1 DJ |
5602 | processing_has_namespace_info = 0; |
5603 | ||
c906108c SS |
5604 | start_symtab (name, comp_dir, lowpc); |
5605 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5606 | record_producer (cu->producer); |
c906108c | 5607 | |
e142c38c | 5608 | initialize_cu_func_list (cu); |
c906108c | 5609 | |
2ab95328 | 5610 | handle_DW_AT_stmt_list (die, cu, comp_dir); |
debd256d | 5611 | |
cb1df416 DJ |
5612 | /* Process all dies in compilation unit. */ |
5613 | if (die->child != NULL) | |
5614 | { | |
5615 | child_die = die->child; | |
5616 | while (child_die && child_die->tag) | |
5617 | { | |
5618 | process_die (child_die, cu); | |
5619 | child_die = sibling_die (child_die); | |
5620 | } | |
5621 | } | |
5622 | ||
2e276125 JB |
5623 | /* Decode macro information, if present. Dwarf 2 macro information |
5624 | refers to information in the line number info statement program | |
5625 | header, so we can only read it if we've read the header | |
5626 | successfully. */ | |
cf2c3c16 | 5627 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
2ab95328 | 5628 | if (attr && cu->line_header) |
2e276125 | 5629 | { |
cf2c3c16 TT |
5630 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
5631 | complaint (&symfile_complaints, | |
5632 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
5633 | ||
5634 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), | |
5635 | comp_dir, abfd, cu, | |
5636 | &dwarf2_per_objfile->macro, 1); | |
5637 | } | |
5638 | else | |
5639 | { | |
5640 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
5641 | if (attr && cu->line_header) | |
5642 | { | |
5643 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5644 | |
cf2c3c16 TT |
5645 | dwarf_decode_macros (cu->line_header, macro_offset, |
5646 | comp_dir, abfd, cu, | |
5647 | &dwarf2_per_objfile->macinfo, 0); | |
5648 | } | |
2e276125 | 5649 | } |
debd256d | 5650 | do_cleanups (back_to); |
5fb290d7 DJ |
5651 | } |
5652 | ||
ae2de4f8 DE |
5653 | /* Process DW_TAG_type_unit. |
5654 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
5655 | actual type being defined by this TU. In this case the first top |
5656 | level sibling is there to provide context only. */ | |
5657 | ||
5658 | static void | |
5659 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5660 | { | |
5661 | struct objfile *objfile = cu->objfile; | |
5662 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5663 | CORE_ADDR lowpc; | |
5664 | struct attribute *attr; | |
5665 | char *name = NULL; | |
5666 | char *comp_dir = NULL; | |
5667 | struct die_info *child_die; | |
5668 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5669 | |
5670 | /* start_symtab needs a low pc, but we don't really have one. | |
5671 | Do what read_file_scope would do in the absence of such info. */ | |
5672 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5673 | ||
5674 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5675 | is not a source language identifier. */ | |
5676 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5677 | if (attr) | |
5678 | name = DW_STRING (attr); | |
5679 | ||
5680 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5681 | if (attr) | |
5682 | comp_dir = DW_STRING (attr); | |
5683 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5684 | { | |
5685 | comp_dir = ldirname (name); | |
5686 | if (comp_dir != NULL) | |
5687 | make_cleanup (xfree, comp_dir); | |
5688 | } | |
5689 | ||
5690 | if (name == NULL) | |
5691 | name = "<unknown>"; | |
5692 | ||
5693 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5694 | if (attr) | |
5695 | set_cu_language (DW_UNSND (attr), cu); | |
5696 | ||
5697 | /* This isn't technically needed today. It is done for symmetry | |
5698 | with read_file_scope. */ | |
5699 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5700 | if (attr) |
348e048f DE |
5701 | cu->producer = DW_STRING (attr); |
5702 | ||
0963b4bd | 5703 | /* We assume that we're processing GCC output. */ |
348e048f DE |
5704 | processing_gcc_compilation = 2; |
5705 | ||
5706 | processing_has_namespace_info = 0; | |
5707 | ||
5708 | start_symtab (name, comp_dir, lowpc); | |
5709 | record_debugformat ("DWARF 2"); | |
5710 | record_producer (cu->producer); | |
5711 | ||
2ab95328 TT |
5712 | handle_DW_AT_stmt_list (die, cu, comp_dir); |
5713 | ||
348e048f DE |
5714 | /* Process the dies in the type unit. */ |
5715 | if (die->child == NULL) | |
5716 | { | |
5717 | dump_die_for_error (die); | |
5718 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5719 | bfd_get_filename (abfd)); | |
5720 | } | |
5721 | ||
5722 | child_die = die->child; | |
5723 | ||
5724 | while (child_die && child_die->tag) | |
5725 | { | |
5726 | process_die (child_die, cu); | |
5727 | ||
5728 | child_die = sibling_die (child_die); | |
5729 | } | |
5730 | ||
5731 | do_cleanups (back_to); | |
5732 | } | |
5733 | ||
5fb290d7 | 5734 | static void |
e142c38c DJ |
5735 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
5736 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
5737 | { |
5738 | struct function_range *thisfn; | |
5739 | ||
5740 | thisfn = (struct function_range *) | |
7b5a2f43 | 5741 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
5742 | thisfn->name = name; |
5743 | thisfn->lowpc = lowpc; | |
5744 | thisfn->highpc = highpc; | |
5745 | thisfn->seen_line = 0; | |
5746 | thisfn->next = NULL; | |
5747 | ||
e142c38c DJ |
5748 | if (cu->last_fn == NULL) |
5749 | cu->first_fn = thisfn; | |
5fb290d7 | 5750 | else |
e142c38c | 5751 | cu->last_fn->next = thisfn; |
5fb290d7 | 5752 | |
e142c38c | 5753 | cu->last_fn = thisfn; |
c906108c SS |
5754 | } |
5755 | ||
d389af10 JK |
5756 | /* qsort helper for inherit_abstract_dies. */ |
5757 | ||
5758 | static int | |
5759 | unsigned_int_compar (const void *ap, const void *bp) | |
5760 | { | |
5761 | unsigned int a = *(unsigned int *) ap; | |
5762 | unsigned int b = *(unsigned int *) bp; | |
5763 | ||
5764 | return (a > b) - (b > a); | |
5765 | } | |
5766 | ||
5767 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
5768 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
5769 | already referenced by DW_AT_abstract_origin from the children of the | |
5770 | current DIE. */ | |
d389af10 JK |
5771 | |
5772 | static void | |
5773 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5774 | { | |
5775 | struct die_info *child_die; | |
5776 | unsigned die_children_count; | |
5777 | /* CU offsets which were referenced by children of the current DIE. */ | |
5778 | unsigned *offsets; | |
5779 | unsigned *offsets_end, *offsetp; | |
5780 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5781 | struct die_info *origin_die; | |
5782 | /* Iterator of the ORIGIN_DIE children. */ | |
5783 | struct die_info *origin_child_die; | |
5784 | struct cleanup *cleanups; | |
5785 | struct attribute *attr; | |
cd02d79d PA |
5786 | struct dwarf2_cu *origin_cu; |
5787 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5788 | |
5789 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5790 | if (!attr) | |
5791 | return; | |
5792 | ||
cd02d79d PA |
5793 | /* Note that following die references may follow to a die in a |
5794 | different cu. */ | |
5795 | ||
5796 | origin_cu = cu; | |
5797 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5798 | ||
5799 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5800 | symbols in. */ | |
5801 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5802 | origin_cu->list_in_scope = cu->list_in_scope; | |
5803 | ||
edb3359d DJ |
5804 | if (die->tag != origin_die->tag |
5805 | && !(die->tag == DW_TAG_inlined_subroutine | |
5806 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5807 | complaint (&symfile_complaints, |
5808 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5809 | die->offset, origin_die->offset); | |
5810 | ||
5811 | child_die = die->child; | |
5812 | die_children_count = 0; | |
5813 | while (child_die && child_die->tag) | |
5814 | { | |
5815 | child_die = sibling_die (child_die); | |
5816 | die_children_count++; | |
5817 | } | |
5818 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5819 | cleanups = make_cleanup (xfree, offsets); | |
5820 | ||
5821 | offsets_end = offsets; | |
5822 | child_die = die->child; | |
5823 | while (child_die && child_die->tag) | |
5824 | { | |
c38f313d DJ |
5825 | /* For each CHILD_DIE, find the corresponding child of |
5826 | ORIGIN_DIE. If there is more than one layer of | |
5827 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5828 | but GCC versions at least through 4.4 generate this (GCC PR | |
5829 | 40573). */ | |
5830 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5831 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5832 | |
c38f313d DJ |
5833 | while (1) |
5834 | { | |
cd02d79d PA |
5835 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5836 | child_origin_cu); | |
c38f313d DJ |
5837 | if (attr == NULL) |
5838 | break; | |
cd02d79d PA |
5839 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5840 | &child_origin_cu); | |
c38f313d DJ |
5841 | } |
5842 | ||
d389af10 JK |
5843 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5844 | counterpart may exist. */ | |
c38f313d | 5845 | if (child_origin_die != child_die) |
d389af10 | 5846 | { |
edb3359d DJ |
5847 | if (child_die->tag != child_origin_die->tag |
5848 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5849 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5850 | complaint (&symfile_complaints, |
5851 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5852 | "different tags"), child_die->offset, | |
5853 | child_origin_die->offset); | |
c38f313d DJ |
5854 | if (child_origin_die->parent != origin_die) |
5855 | complaint (&symfile_complaints, | |
5856 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5857 | "different parents"), child_die->offset, | |
5858 | child_origin_die->offset); | |
5859 | else | |
5860 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5861 | } |
5862 | child_die = sibling_die (child_die); | |
5863 | } | |
5864 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5865 | unsigned_int_compar); | |
5866 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5867 | if (offsetp[-1] == *offsetp) | |
3e43a32a MS |
5868 | complaint (&symfile_complaints, |
5869 | _("Multiple children of DIE 0x%x refer " | |
5870 | "to DIE 0x%x as their abstract origin"), | |
d389af10 JK |
5871 | die->offset, *offsetp); |
5872 | ||
5873 | offsetp = offsets; | |
5874 | origin_child_die = origin_die->child; | |
5875 | while (origin_child_die && origin_child_die->tag) | |
5876 | { | |
5877 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5878 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5879 | offsetp++; | |
5880 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5881 | { | |
5882 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5883 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5884 | } |
5885 | origin_child_die = sibling_die (origin_child_die); | |
5886 | } | |
cd02d79d | 5887 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5888 | |
5889 | do_cleanups (cleanups); | |
5890 | } | |
5891 | ||
c906108c | 5892 | static void |
e7c27a73 | 5893 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5894 | { |
e7c27a73 | 5895 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5896 | struct context_stack *new; |
c906108c SS |
5897 | CORE_ADDR lowpc; |
5898 | CORE_ADDR highpc; | |
5899 | struct die_info *child_die; | |
edb3359d | 5900 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5901 | char *name; |
e142c38c | 5902 | CORE_ADDR baseaddr; |
801e3a5b | 5903 | struct block *block; |
edb3359d | 5904 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5905 | VEC (symbolp) *template_args = NULL; |
5906 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5907 | |
5908 | if (inlined_func) | |
5909 | { | |
5910 | /* If we do not have call site information, we can't show the | |
5911 | caller of this inlined function. That's too confusing, so | |
5912 | only use the scope for local variables. */ | |
5913 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5914 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5915 | if (call_line == NULL || call_file == NULL) | |
5916 | { | |
5917 | read_lexical_block_scope (die, cu); | |
5918 | return; | |
5919 | } | |
5920 | } | |
c906108c | 5921 | |
e142c38c DJ |
5922 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5923 | ||
94af9270 | 5924 | name = dwarf2_name (die, cu); |
c906108c | 5925 | |
e8d05480 JB |
5926 | /* Ignore functions with missing or empty names. These are actually |
5927 | illegal according to the DWARF standard. */ | |
5928 | if (name == NULL) | |
5929 | { | |
5930 | complaint (&symfile_complaints, | |
5931 | _("missing name for subprogram DIE at %d"), die->offset); | |
5932 | return; | |
5933 | } | |
5934 | ||
5935 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5936 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5937 | { | |
ae4d0c03 PM |
5938 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5939 | if (!attr || !DW_UNSND (attr)) | |
5940 | complaint (&symfile_complaints, | |
3e43a32a MS |
5941 | _("cannot get low and high bounds " |
5942 | "for subprogram DIE at %d"), | |
ae4d0c03 | 5943 | die->offset); |
e8d05480 JB |
5944 | return; |
5945 | } | |
c906108c SS |
5946 | |
5947 | lowpc += baseaddr; | |
5948 | highpc += baseaddr; | |
5949 | ||
5fb290d7 | 5950 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 5951 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 5952 | |
34eaf542 TT |
5953 | /* If we have any template arguments, then we must allocate a |
5954 | different sort of symbol. */ | |
5955 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5956 | { | |
5957 | if (child_die->tag == DW_TAG_template_type_param | |
5958 | || child_die->tag == DW_TAG_template_value_param) | |
5959 | { | |
5960 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5961 | struct template_symbol); | |
5962 | templ_func->base.is_cplus_template_function = 1; | |
5963 | break; | |
5964 | } | |
5965 | } | |
5966 | ||
c906108c | 5967 | new = push_context (0, lowpc); |
34eaf542 TT |
5968 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5969 | (struct symbol *) templ_func); | |
4c2df51b | 5970 | |
4cecd739 DJ |
5971 | /* If there is a location expression for DW_AT_frame_base, record |
5972 | it. */ | |
e142c38c | 5973 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5974 | if (attr) |
c034e007 AC |
5975 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5976 | expression is being recorded directly in the function's symbol | |
5977 | and not in a separate frame-base object. I guess this hack is | |
5978 | to avoid adding some sort of frame-base adjunct/annex to the | |
5979 | function's symbol :-(. The problem with doing this is that it | |
5980 | results in a function symbol with a location expression that | |
5981 | has nothing to do with the location of the function, ouch! The | |
5982 | relationship should be: a function's symbol has-a frame base; a | |
5983 | frame-base has-a location expression. */ | |
e7c27a73 | 5984 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5985 | |
e142c38c | 5986 | cu->list_in_scope = &local_symbols; |
c906108c | 5987 | |
639d11d3 | 5988 | if (die->child != NULL) |
c906108c | 5989 | { |
639d11d3 | 5990 | child_die = die->child; |
c906108c SS |
5991 | while (child_die && child_die->tag) |
5992 | { | |
34eaf542 TT |
5993 | if (child_die->tag == DW_TAG_template_type_param |
5994 | || child_die->tag == DW_TAG_template_value_param) | |
5995 | { | |
5996 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5997 | ||
f1078f66 DJ |
5998 | if (arg != NULL) |
5999 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
6000 | } |
6001 | else | |
6002 | process_die (child_die, cu); | |
c906108c SS |
6003 | child_die = sibling_die (child_die); |
6004 | } | |
6005 | } | |
6006 | ||
d389af10 JK |
6007 | inherit_abstract_dies (die, cu); |
6008 | ||
4a811a97 UW |
6009 | /* If we have a DW_AT_specification, we might need to import using |
6010 | directives from the context of the specification DIE. See the | |
6011 | comment in determine_prefix. */ | |
6012 | if (cu->language == language_cplus | |
6013 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
6014 | { | |
6015 | struct dwarf2_cu *spec_cu = cu; | |
6016 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
6017 | ||
6018 | while (spec_die) | |
6019 | { | |
6020 | child_die = spec_die->child; | |
6021 | while (child_die && child_die->tag) | |
6022 | { | |
6023 | if (child_die->tag == DW_TAG_imported_module) | |
6024 | process_die (child_die, spec_cu); | |
6025 | child_die = sibling_die (child_die); | |
6026 | } | |
6027 | ||
6028 | /* In some cases, GCC generates specification DIEs that | |
6029 | themselves contain DW_AT_specification attributes. */ | |
6030 | spec_die = die_specification (spec_die, &spec_cu); | |
6031 | } | |
6032 | } | |
6033 | ||
c906108c SS |
6034 | new = pop_context (); |
6035 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
6036 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
6037 | lowpc, highpc, objfile); | |
6038 | ||
df8a16a1 | 6039 | /* For C++, set the block's scope. */ |
f55ee35c | 6040 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 6041 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 6042 | determine_prefix (die, cu), |
df8a16a1 DJ |
6043 | processing_has_namespace_info); |
6044 | ||
801e3a5b JB |
6045 | /* If we have address ranges, record them. */ |
6046 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 6047 | |
34eaf542 TT |
6048 | /* Attach template arguments to function. */ |
6049 | if (! VEC_empty (symbolp, template_args)) | |
6050 | { | |
6051 | gdb_assert (templ_func != NULL); | |
6052 | ||
6053 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
6054 | templ_func->template_arguments | |
6055 | = obstack_alloc (&objfile->objfile_obstack, | |
6056 | (templ_func->n_template_arguments | |
6057 | * sizeof (struct symbol *))); | |
6058 | memcpy (templ_func->template_arguments, | |
6059 | VEC_address (symbolp, template_args), | |
6060 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
6061 | VEC_free (symbolp, template_args); | |
6062 | } | |
6063 | ||
208d8187 JB |
6064 | /* In C++, we can have functions nested inside functions (e.g., when |
6065 | a function declares a class that has methods). This means that | |
6066 | when we finish processing a function scope, we may need to go | |
6067 | back to building a containing block's symbol lists. */ | |
6068 | local_symbols = new->locals; | |
6069 | param_symbols = new->params; | |
27aa8d6a | 6070 | using_directives = new->using_directives; |
208d8187 | 6071 | |
921e78cf JB |
6072 | /* If we've finished processing a top-level function, subsequent |
6073 | symbols go in the file symbol list. */ | |
6074 | if (outermost_context_p ()) | |
e142c38c | 6075 | cu->list_in_scope = &file_symbols; |
c906108c SS |
6076 | } |
6077 | ||
6078 | /* Process all the DIES contained within a lexical block scope. Start | |
6079 | a new scope, process the dies, and then close the scope. */ | |
6080 | ||
6081 | static void | |
e7c27a73 | 6082 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6083 | { |
e7c27a73 | 6084 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 6085 | struct context_stack *new; |
c906108c SS |
6086 | CORE_ADDR lowpc, highpc; |
6087 | struct die_info *child_die; | |
e142c38c DJ |
6088 | CORE_ADDR baseaddr; |
6089 | ||
6090 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
6091 | |
6092 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
6093 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
6094 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 6095 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 6096 | describe ranges. */ |
d85a05f0 | 6097 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
6098 | return; |
6099 | lowpc += baseaddr; | |
6100 | highpc += baseaddr; | |
6101 | ||
6102 | push_context (0, lowpc); | |
639d11d3 | 6103 | if (die->child != NULL) |
c906108c | 6104 | { |
639d11d3 | 6105 | child_die = die->child; |
c906108c SS |
6106 | while (child_die && child_die->tag) |
6107 | { | |
e7c27a73 | 6108 | process_die (child_die, cu); |
c906108c SS |
6109 | child_die = sibling_die (child_die); |
6110 | } | |
6111 | } | |
6112 | new = pop_context (); | |
6113 | ||
8540c487 | 6114 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 6115 | { |
801e3a5b JB |
6116 | struct block *block |
6117 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
6118 | highpc, objfile); | |
6119 | ||
6120 | /* Note that recording ranges after traversing children, as we | |
6121 | do here, means that recording a parent's ranges entails | |
6122 | walking across all its children's ranges as they appear in | |
6123 | the address map, which is quadratic behavior. | |
6124 | ||
6125 | It would be nicer to record the parent's ranges before | |
6126 | traversing its children, simply overriding whatever you find | |
6127 | there. But since we don't even decide whether to create a | |
6128 | block until after we've traversed its children, that's hard | |
6129 | to do. */ | |
6130 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
6131 | } |
6132 | local_symbols = new->locals; | |
27aa8d6a | 6133 | using_directives = new->using_directives; |
c906108c SS |
6134 | } |
6135 | ||
96408a79 SA |
6136 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
6137 | ||
6138 | static void | |
6139 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6140 | { | |
6141 | struct objfile *objfile = cu->objfile; | |
6142 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6143 | CORE_ADDR pc, baseaddr; | |
6144 | struct attribute *attr; | |
6145 | struct call_site *call_site, call_site_local; | |
6146 | void **slot; | |
6147 | int nparams; | |
6148 | struct die_info *child_die; | |
6149 | ||
6150 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6151 | ||
6152 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
6153 | if (!attr) | |
6154 | { | |
6155 | complaint (&symfile_complaints, | |
6156 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
6157 | "DIE 0x%x [in module %s]"), | |
6158 | die->offset, cu->objfile->name); | |
6159 | return; | |
6160 | } | |
6161 | pc = DW_ADDR (attr) + baseaddr; | |
6162 | ||
6163 | if (cu->call_site_htab == NULL) | |
6164 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
6165 | NULL, &objfile->objfile_obstack, | |
6166 | hashtab_obstack_allocate, NULL); | |
6167 | call_site_local.pc = pc; | |
6168 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
6169 | if (*slot != NULL) | |
6170 | { | |
6171 | complaint (&symfile_complaints, | |
6172 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
6173 | "DIE 0x%x [in module %s]"), | |
6174 | paddress (gdbarch, pc), die->offset, cu->objfile->name); | |
6175 | return; | |
6176 | } | |
6177 | ||
6178 | /* Count parameters at the caller. */ | |
6179 | ||
6180 | nparams = 0; | |
6181 | for (child_die = die->child; child_die && child_die->tag; | |
6182 | child_die = sibling_die (child_die)) | |
6183 | { | |
6184 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6185 | { | |
6186 | complaint (&symfile_complaints, | |
6187 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
6188 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
6189 | child_die->tag, child_die->offset, cu->objfile->name); | |
6190 | continue; | |
6191 | } | |
6192 | ||
6193 | nparams++; | |
6194 | } | |
6195 | ||
6196 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
6197 | (sizeof (*call_site) | |
6198 | + (sizeof (*call_site->parameter) | |
6199 | * (nparams - 1)))); | |
6200 | *slot = call_site; | |
6201 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
6202 | call_site->pc = pc; | |
6203 | ||
6204 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
6205 | { | |
6206 | struct die_info *func_die; | |
6207 | ||
6208 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
6209 | for (func_die = die->parent; | |
6210 | func_die && func_die->tag != DW_TAG_subprogram | |
6211 | && func_die->tag != DW_TAG_subroutine_type; | |
6212 | func_die = func_die->parent); | |
6213 | ||
6214 | /* DW_AT_GNU_all_call_sites is a superset | |
6215 | of DW_AT_GNU_all_tail_call_sites. */ | |
6216 | if (func_die | |
6217 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
6218 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
6219 | { | |
6220 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
6221 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
6222 | both the initial caller containing the real return address PC and | |
6223 | the final callee containing the current PC of a chain of tail | |
6224 | calls do not need to have the tail call list complete. But any | |
6225 | function candidate for a virtual tail call frame searched via | |
6226 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
6227 | determined unambiguously. */ | |
6228 | } | |
6229 | else | |
6230 | { | |
6231 | struct type *func_type = NULL; | |
6232 | ||
6233 | if (func_die) | |
6234 | func_type = get_die_type (func_die, cu); | |
6235 | if (func_type != NULL) | |
6236 | { | |
6237 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
6238 | ||
6239 | /* Enlist this call site to the function. */ | |
6240 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
6241 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
6242 | } | |
6243 | else | |
6244 | complaint (&symfile_complaints, | |
6245 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
6246 | "DIE 0x%x [in module %s]"), | |
6247 | die->offset, cu->objfile->name); | |
6248 | } | |
6249 | } | |
6250 | ||
6251 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
6252 | if (attr == NULL) | |
6253 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
6254 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
6255 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
6256 | /* Keep NULL DWARF_BLOCK. */; | |
6257 | else if (attr_form_is_block (attr)) | |
6258 | { | |
6259 | struct dwarf2_locexpr_baton *dlbaton; | |
6260 | ||
6261 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
6262 | dlbaton->data = DW_BLOCK (attr)->data; | |
6263 | dlbaton->size = DW_BLOCK (attr)->size; | |
6264 | dlbaton->per_cu = cu->per_cu; | |
6265 | ||
6266 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
6267 | } | |
6268 | else if (is_ref_attr (attr)) | |
6269 | { | |
6270 | struct objfile *objfile = cu->objfile; | |
6271 | struct dwarf2_cu *target_cu = cu; | |
6272 | struct die_info *target_die; | |
6273 | ||
6274 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
6275 | gdb_assert (target_cu->objfile == objfile); | |
6276 | if (die_is_declaration (target_die, target_cu)) | |
6277 | { | |
6278 | const char *target_physname; | |
6279 | ||
6280 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
6281 | if (target_physname == NULL) | |
6282 | complaint (&symfile_complaints, | |
6283 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6284 | "physname, for referencing DIE 0x%x [in module %s]"), | |
6285 | die->offset, cu->objfile->name); | |
6286 | else | |
6287 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
6288 | } | |
6289 | else | |
6290 | { | |
6291 | CORE_ADDR lowpc; | |
6292 | ||
6293 | /* DW_AT_entry_pc should be preferred. */ | |
6294 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
6295 | complaint (&symfile_complaints, | |
6296 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6297 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
6298 | die->offset, cu->objfile->name); | |
6299 | else | |
6300 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
6301 | } | |
6302 | } | |
6303 | else | |
6304 | complaint (&symfile_complaints, | |
6305 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
6306 | "block nor reference, for DIE 0x%x [in module %s]"), | |
6307 | die->offset, cu->objfile->name); | |
6308 | ||
6309 | call_site->per_cu = cu->per_cu; | |
6310 | ||
6311 | for (child_die = die->child; | |
6312 | child_die && child_die->tag; | |
6313 | child_die = sibling_die (child_die)) | |
6314 | { | |
6315 | struct dwarf2_locexpr_baton *dlbaton; | |
6316 | struct call_site_parameter *parameter; | |
6317 | ||
6318 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6319 | { | |
6320 | /* Already printed the complaint above. */ | |
6321 | continue; | |
6322 | } | |
6323 | ||
6324 | gdb_assert (call_site->parameter_count < nparams); | |
6325 | parameter = &call_site->parameter[call_site->parameter_count]; | |
6326 | ||
6327 | /* DW_AT_location specifies the register number. Value of the data | |
6328 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ | |
6329 | ||
6330 | attr = dwarf2_attr (child_die, DW_AT_location, cu); | |
6331 | if (!attr || !attr_form_is_block (attr)) | |
6332 | { | |
6333 | complaint (&symfile_complaints, | |
6334 | _("No DW_FORM_block* DW_AT_location for " | |
6335 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
6336 | child_die->offset, cu->objfile->name); | |
6337 | continue; | |
6338 | } | |
6339 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, | |
6340 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); | |
6341 | if (parameter->dwarf_reg == -1 | |
6342 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, | |
6343 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], | |
6344 | ¶meter->fb_offset)) | |
6345 | { | |
6346 | complaint (&symfile_complaints, | |
6347 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
6348 | "for DW_FORM_block* DW_AT_location for " | |
6349 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
6350 | child_die->offset, cu->objfile->name); | |
6351 | continue; | |
6352 | } | |
6353 | ||
6354 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
6355 | if (!attr_form_is_block (attr)) | |
6356 | { | |
6357 | complaint (&symfile_complaints, | |
6358 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
6359 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
6360 | child_die->offset, cu->objfile->name); | |
6361 | continue; | |
6362 | } | |
6363 | parameter->value = DW_BLOCK (attr)->data; | |
6364 | parameter->value_size = DW_BLOCK (attr)->size; | |
6365 | ||
6366 | /* Parameters are not pre-cleared by memset above. */ | |
6367 | parameter->data_value = NULL; | |
6368 | parameter->data_value_size = 0; | |
6369 | call_site->parameter_count++; | |
6370 | ||
6371 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
6372 | if (attr) | |
6373 | { | |
6374 | if (!attr_form_is_block (attr)) | |
6375 | complaint (&symfile_complaints, | |
6376 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
6377 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
6378 | child_die->offset, cu->objfile->name); | |
6379 | else | |
6380 | { | |
6381 | parameter->data_value = DW_BLOCK (attr)->data; | |
6382 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
6383 | } | |
6384 | } | |
6385 | } | |
6386 | } | |
6387 | ||
43039443 | 6388 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
6389 | Return 1 if the attributes are present and valid, otherwise, return 0. |
6390 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
6391 | |
6392 | static int | |
6393 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
6394 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
6395 | struct partial_symtab *ranges_pst) | |
43039443 JK |
6396 | { |
6397 | struct objfile *objfile = cu->objfile; | |
6398 | struct comp_unit_head *cu_header = &cu->header; | |
6399 | bfd *obfd = objfile->obfd; | |
6400 | unsigned int addr_size = cu_header->addr_size; | |
6401 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6402 | /* Base address selection entry. */ | |
6403 | CORE_ADDR base; | |
6404 | int found_base; | |
6405 | unsigned int dummy; | |
6406 | gdb_byte *buffer; | |
6407 | CORE_ADDR marker; | |
6408 | int low_set; | |
6409 | CORE_ADDR low = 0; | |
6410 | CORE_ADDR high = 0; | |
ff013f42 | 6411 | CORE_ADDR baseaddr; |
43039443 | 6412 | |
d00adf39 DE |
6413 | found_base = cu->base_known; |
6414 | base = cu->base_address; | |
43039443 | 6415 | |
be391dca | 6416 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 6417 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
6418 | { |
6419 | complaint (&symfile_complaints, | |
6420 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
6421 | offset); | |
6422 | return 0; | |
6423 | } | |
dce234bc | 6424 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
6425 | |
6426 | /* Read in the largest possible address. */ | |
6427 | marker = read_address (obfd, buffer, cu, &dummy); | |
6428 | if ((marker & mask) == mask) | |
6429 | { | |
6430 | /* If we found the largest possible address, then | |
6431 | read the base address. */ | |
6432 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6433 | buffer += 2 * addr_size; | |
6434 | offset += 2 * addr_size; | |
6435 | found_base = 1; | |
6436 | } | |
6437 | ||
6438 | low_set = 0; | |
6439 | ||
e7030f15 | 6440 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 6441 | |
43039443 JK |
6442 | while (1) |
6443 | { | |
6444 | CORE_ADDR range_beginning, range_end; | |
6445 | ||
6446 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
6447 | buffer += addr_size; | |
6448 | range_end = read_address (obfd, buffer, cu, &dummy); | |
6449 | buffer += addr_size; | |
6450 | offset += 2 * addr_size; | |
6451 | ||
6452 | /* An end of list marker is a pair of zero addresses. */ | |
6453 | if (range_beginning == 0 && range_end == 0) | |
6454 | /* Found the end of list entry. */ | |
6455 | break; | |
6456 | ||
6457 | /* Each base address selection entry is a pair of 2 values. | |
6458 | The first is the largest possible address, the second is | |
6459 | the base address. Check for a base address here. */ | |
6460 | if ((range_beginning & mask) == mask) | |
6461 | { | |
6462 | /* If we found the largest possible address, then | |
6463 | read the base address. */ | |
6464 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6465 | found_base = 1; | |
6466 | continue; | |
6467 | } | |
6468 | ||
6469 | if (!found_base) | |
6470 | { | |
6471 | /* We have no valid base address for the ranges | |
6472 | data. */ | |
6473 | complaint (&symfile_complaints, | |
6474 | _("Invalid .debug_ranges data (no base address)")); | |
6475 | return 0; | |
6476 | } | |
6477 | ||
9277c30c UW |
6478 | if (range_beginning > range_end) |
6479 | { | |
6480 | /* Inverted range entries are invalid. */ | |
6481 | complaint (&symfile_complaints, | |
6482 | _("Invalid .debug_ranges data (inverted range)")); | |
6483 | return 0; | |
6484 | } | |
6485 | ||
6486 | /* Empty range entries have no effect. */ | |
6487 | if (range_beginning == range_end) | |
6488 | continue; | |
6489 | ||
43039443 JK |
6490 | range_beginning += base; |
6491 | range_end += base; | |
6492 | ||
9277c30c | 6493 | if (ranges_pst != NULL) |
ff013f42 | 6494 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
6495 | range_beginning + baseaddr, |
6496 | range_end - 1 + baseaddr, | |
ff013f42 JK |
6497 | ranges_pst); |
6498 | ||
43039443 JK |
6499 | /* FIXME: This is recording everything as a low-high |
6500 | segment of consecutive addresses. We should have a | |
6501 | data structure for discontiguous block ranges | |
6502 | instead. */ | |
6503 | if (! low_set) | |
6504 | { | |
6505 | low = range_beginning; | |
6506 | high = range_end; | |
6507 | low_set = 1; | |
6508 | } | |
6509 | else | |
6510 | { | |
6511 | if (range_beginning < low) | |
6512 | low = range_beginning; | |
6513 | if (range_end > high) | |
6514 | high = range_end; | |
6515 | } | |
6516 | } | |
6517 | ||
6518 | if (! low_set) | |
6519 | /* If the first entry is an end-of-list marker, the range | |
6520 | describes an empty scope, i.e. no instructions. */ | |
6521 | return 0; | |
6522 | ||
6523 | if (low_return) | |
6524 | *low_return = low; | |
6525 | if (high_return) | |
6526 | *high_return = high; | |
6527 | return 1; | |
6528 | } | |
6529 | ||
af34e669 DJ |
6530 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
6531 | are present and valid, otherwise, return 0. Return -1 if the range is | |
6532 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 6533 | static int |
af34e669 | 6534 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
6535 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
6536 | struct partial_symtab *pst) | |
c906108c SS |
6537 | { |
6538 | struct attribute *attr; | |
af34e669 DJ |
6539 | CORE_ADDR low = 0; |
6540 | CORE_ADDR high = 0; | |
6541 | int ret = 0; | |
c906108c | 6542 | |
e142c38c | 6543 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 6544 | if (attr) |
af34e669 DJ |
6545 | { |
6546 | high = DW_ADDR (attr); | |
e142c38c | 6547 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
6548 | if (attr) |
6549 | low = DW_ADDR (attr); | |
6550 | else | |
6551 | /* Found high w/o low attribute. */ | |
6552 | return 0; | |
6553 | ||
6554 | /* Found consecutive range of addresses. */ | |
6555 | ret = 1; | |
6556 | } | |
c906108c | 6557 | else |
af34e669 | 6558 | { |
e142c38c | 6559 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6560 | if (attr != NULL) |
6561 | { | |
af34e669 | 6562 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6563 | .debug_ranges section. */ |
d85a05f0 | 6564 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6565 | return 0; |
43039443 | 6566 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6567 | ret = -1; |
6568 | } | |
6569 | } | |
c906108c | 6570 | |
9373cf26 JK |
6571 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6572 | if (high <= low) | |
c906108c SS |
6573 | return 0; |
6574 | ||
6575 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6576 | eliminate duplicate copies of functions and vtables and such. | |
6577 | The linker will arbitrarily choose one and discard the others. | |
6578 | The AT_*_pc values for such functions refer to local labels in | |
6579 | these sections. If the section from that file was discarded, the | |
6580 | labels are not in the output, so the relocs get a value of 0. | |
6581 | If this is a discarded function, mark the pc bounds as invalid, | |
6582 | so that GDB will ignore it. */ | |
72dca2f5 | 6583 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6584 | return 0; |
6585 | ||
6586 | *lowpc = low; | |
96408a79 SA |
6587 | if (highpc) |
6588 | *highpc = high; | |
af34e669 | 6589 | return ret; |
c906108c SS |
6590 | } |
6591 | ||
b084d499 JB |
6592 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6593 | its low and high PC addresses. Do nothing if these addresses could not | |
6594 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6595 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6596 | ||
6597 | static void | |
6598 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6599 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6600 | struct dwarf2_cu *cu) | |
6601 | { | |
6602 | CORE_ADDR low, high; | |
6603 | struct die_info *child = die->child; | |
6604 | ||
d85a05f0 | 6605 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6606 | { |
6607 | *lowpc = min (*lowpc, low); | |
6608 | *highpc = max (*highpc, high); | |
6609 | } | |
6610 | ||
6611 | /* If the language does not allow nested subprograms (either inside | |
6612 | subprograms or lexical blocks), we're done. */ | |
6613 | if (cu->language != language_ada) | |
6614 | return; | |
6e70227d | 6615 | |
b084d499 JB |
6616 | /* Check all the children of the given DIE. If it contains nested |
6617 | subprograms, then check their pc bounds. Likewise, we need to | |
6618 | check lexical blocks as well, as they may also contain subprogram | |
6619 | definitions. */ | |
6620 | while (child && child->tag) | |
6621 | { | |
6622 | if (child->tag == DW_TAG_subprogram | |
6623 | || child->tag == DW_TAG_lexical_block) | |
6624 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6625 | child = sibling_die (child); | |
6626 | } | |
6627 | } | |
6628 | ||
fae299cd DC |
6629 | /* Get the low and high pc's represented by the scope DIE, and store |
6630 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6631 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6632 | ||
6633 | static void | |
6634 | get_scope_pc_bounds (struct die_info *die, | |
6635 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6636 | struct dwarf2_cu *cu) | |
6637 | { | |
6638 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6639 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6640 | CORE_ADDR current_low, current_high; | |
6641 | ||
d85a05f0 | 6642 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6643 | { |
6644 | best_low = current_low; | |
6645 | best_high = current_high; | |
6646 | } | |
6647 | else | |
6648 | { | |
6649 | struct die_info *child = die->child; | |
6650 | ||
6651 | while (child && child->tag) | |
6652 | { | |
6653 | switch (child->tag) { | |
6654 | case DW_TAG_subprogram: | |
b084d499 | 6655 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6656 | break; |
6657 | case DW_TAG_namespace: | |
f55ee35c | 6658 | case DW_TAG_module: |
fae299cd DC |
6659 | /* FIXME: carlton/2004-01-16: Should we do this for |
6660 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6661 | that current GCC's always emit the DIEs corresponding | |
6662 | to definitions of methods of classes as children of a | |
6663 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6664 | the DIEs giving the declarations, which could be | |
6665 | anywhere). But I don't see any reason why the | |
6666 | standards says that they have to be there. */ | |
6667 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6668 | ||
6669 | if (current_low != ((CORE_ADDR) -1)) | |
6670 | { | |
6671 | best_low = min (best_low, current_low); | |
6672 | best_high = max (best_high, current_high); | |
6673 | } | |
6674 | break; | |
6675 | default: | |
0963b4bd | 6676 | /* Ignore. */ |
fae299cd DC |
6677 | break; |
6678 | } | |
6679 | ||
6680 | child = sibling_die (child); | |
6681 | } | |
6682 | } | |
6683 | ||
6684 | *lowpc = best_low; | |
6685 | *highpc = best_high; | |
6686 | } | |
6687 | ||
801e3a5b JB |
6688 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
6689 | in DIE. */ | |
6690 | static void | |
6691 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
6692 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
6693 | { | |
6694 | struct attribute *attr; | |
6695 | ||
6696 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
6697 | if (attr) | |
6698 | { | |
6699 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 6700 | |
801e3a5b JB |
6701 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
6702 | if (attr) | |
6703 | { | |
6704 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 6705 | |
801e3a5b JB |
6706 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
6707 | } | |
6708 | } | |
6709 | ||
6710 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
6711 | if (attr) | |
6712 | { | |
6713 | bfd *obfd = cu->objfile->obfd; | |
6714 | ||
6715 | /* The value of the DW_AT_ranges attribute is the offset of the | |
6716 | address range list in the .debug_ranges section. */ | |
6717 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 6718 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
6719 | |
6720 | /* For some target architectures, but not others, the | |
6721 | read_address function sign-extends the addresses it returns. | |
6722 | To recognize base address selection entries, we need a | |
6723 | mask. */ | |
6724 | unsigned int addr_size = cu->header.addr_size; | |
6725 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6726 | ||
6727 | /* The base address, to which the next pair is relative. Note | |
6728 | that this 'base' is a DWARF concept: most entries in a range | |
6729 | list are relative, to reduce the number of relocs against the | |
6730 | debugging information. This is separate from this function's | |
6731 | 'baseaddr' argument, which GDB uses to relocate debugging | |
6732 | information from a shared library based on the address at | |
6733 | which the library was loaded. */ | |
d00adf39 DE |
6734 | CORE_ADDR base = cu->base_address; |
6735 | int base_known = cu->base_known; | |
801e3a5b | 6736 | |
be391dca | 6737 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 6738 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
6739 | { |
6740 | complaint (&symfile_complaints, | |
6741 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
6742 | offset); | |
6743 | return; | |
6744 | } | |
6745 | ||
6746 | for (;;) | |
6747 | { | |
6748 | unsigned int bytes_read; | |
6749 | CORE_ADDR start, end; | |
6750 | ||
6751 | start = read_address (obfd, buffer, cu, &bytes_read); | |
6752 | buffer += bytes_read; | |
6753 | end = read_address (obfd, buffer, cu, &bytes_read); | |
6754 | buffer += bytes_read; | |
6755 | ||
6756 | /* Did we find the end of the range list? */ | |
6757 | if (start == 0 && end == 0) | |
6758 | break; | |
6759 | ||
6760 | /* Did we find a base address selection entry? */ | |
6761 | else if ((start & base_select_mask) == base_select_mask) | |
6762 | { | |
6763 | base = end; | |
6764 | base_known = 1; | |
6765 | } | |
6766 | ||
6767 | /* We found an ordinary address range. */ | |
6768 | else | |
6769 | { | |
6770 | if (!base_known) | |
6771 | { | |
6772 | complaint (&symfile_complaints, | |
3e43a32a MS |
6773 | _("Invalid .debug_ranges data " |
6774 | "(no base address)")); | |
801e3a5b JB |
6775 | return; |
6776 | } | |
6777 | ||
9277c30c UW |
6778 | if (start > end) |
6779 | { | |
6780 | /* Inverted range entries are invalid. */ | |
6781 | complaint (&symfile_complaints, | |
6782 | _("Invalid .debug_ranges data " | |
6783 | "(inverted range)")); | |
6784 | return; | |
6785 | } | |
6786 | ||
6787 | /* Empty range entries have no effect. */ | |
6788 | if (start == end) | |
6789 | continue; | |
6790 | ||
6e70227d DE |
6791 | record_block_range (block, |
6792 | baseaddr + base + start, | |
801e3a5b JB |
6793 | baseaddr + base + end - 1); |
6794 | } | |
6795 | } | |
6796 | } | |
6797 | } | |
6798 | ||
60d5a603 JK |
6799 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
6800 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
6801 | during 4.6.0 experimental. */ | |
6802 | ||
6803 | static int | |
6804 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
6805 | { | |
6806 | const char *cs; | |
6807 | int major, minor, release; | |
6808 | ||
6809 | if (cu->producer == NULL) | |
6810 | { | |
6811 | /* For unknown compilers expect their behavior is DWARF version | |
6812 | compliant. | |
6813 | ||
6814 | GCC started to support .debug_types sections by -gdwarf-4 since | |
6815 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
6816 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
6817 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
6818 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
6819 | ||
6820 | return 0; | |
6821 | } | |
6822 | ||
6823 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ | |
6824 | ||
6825 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
6826 | { | |
6827 | /* For non-GCC compilers expect their behavior is DWARF version | |
6828 | compliant. */ | |
6829 | ||
6830 | return 0; | |
6831 | } | |
6832 | cs = &cu->producer[strlen ("GNU ")]; | |
6833 | while (*cs && !isdigit (*cs)) | |
6834 | cs++; | |
6835 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
6836 | { | |
6837 | /* Not recognized as GCC. */ | |
6838 | ||
6839 | return 0; | |
6840 | } | |
6841 | ||
6842 | return major < 4 || (major == 4 && minor < 6); | |
6843 | } | |
6844 | ||
6845 | /* Return the default accessibility type if it is not overriden by | |
6846 | DW_AT_accessibility. */ | |
6847 | ||
6848 | static enum dwarf_access_attribute | |
6849 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
6850 | { | |
6851 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
6852 | { | |
6853 | /* The default DWARF 2 accessibility for members is public, the default | |
6854 | accessibility for inheritance is private. */ | |
6855 | ||
6856 | if (die->tag != DW_TAG_inheritance) | |
6857 | return DW_ACCESS_public; | |
6858 | else | |
6859 | return DW_ACCESS_private; | |
6860 | } | |
6861 | else | |
6862 | { | |
6863 | /* DWARF 3+ defines the default accessibility a different way. The same | |
6864 | rules apply now for DW_TAG_inheritance as for the members and it only | |
6865 | depends on the container kind. */ | |
6866 | ||
6867 | if (die->parent->tag == DW_TAG_class_type) | |
6868 | return DW_ACCESS_private; | |
6869 | else | |
6870 | return DW_ACCESS_public; | |
6871 | } | |
6872 | } | |
6873 | ||
74ac6d43 TT |
6874 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
6875 | offset. If the attribute was not found return 0, otherwise return | |
6876 | 1. If it was found but could not properly be handled, set *OFFSET | |
6877 | to 0. */ | |
6878 | ||
6879 | static int | |
6880 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
6881 | LONGEST *offset) | |
6882 | { | |
6883 | struct attribute *attr; | |
6884 | ||
6885 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
6886 | if (attr != NULL) | |
6887 | { | |
6888 | *offset = 0; | |
6889 | ||
6890 | /* Note that we do not check for a section offset first here. | |
6891 | This is because DW_AT_data_member_location is new in DWARF 4, | |
6892 | so if we see it, we can assume that a constant form is really | |
6893 | a constant and not a section offset. */ | |
6894 | if (attr_form_is_constant (attr)) | |
6895 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
6896 | else if (attr_form_is_section_offset (attr)) | |
6897 | dwarf2_complex_location_expr_complaint (); | |
6898 | else if (attr_form_is_block (attr)) | |
6899 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6900 | else | |
6901 | dwarf2_complex_location_expr_complaint (); | |
6902 | ||
6903 | return 1; | |
6904 | } | |
6905 | ||
6906 | return 0; | |
6907 | } | |
6908 | ||
c906108c SS |
6909 | /* Add an aggregate field to the field list. */ |
6910 | ||
6911 | static void | |
107d2387 | 6912 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6913 | struct dwarf2_cu *cu) |
6e70227d | 6914 | { |
e7c27a73 | 6915 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6916 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6917 | struct nextfield *new_field; |
6918 | struct attribute *attr; | |
6919 | struct field *fp; | |
6920 | char *fieldname = ""; | |
6921 | ||
6922 | /* Allocate a new field list entry and link it in. */ | |
6923 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6924 | make_cleanup (xfree, new_field); |
c906108c | 6925 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6926 | |
6927 | if (die->tag == DW_TAG_inheritance) | |
6928 | { | |
6929 | new_field->next = fip->baseclasses; | |
6930 | fip->baseclasses = new_field; | |
6931 | } | |
6932 | else | |
6933 | { | |
6934 | new_field->next = fip->fields; | |
6935 | fip->fields = new_field; | |
6936 | } | |
c906108c SS |
6937 | fip->nfields++; |
6938 | ||
e142c38c | 6939 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6940 | if (attr) |
6941 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
6942 | else |
6943 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
6944 | if (new_field->accessibility != DW_ACCESS_public) |
6945 | fip->non_public_fields = 1; | |
60d5a603 | 6946 | |
e142c38c | 6947 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6948 | if (attr) |
6949 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
6950 | else |
6951 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
6952 | |
6953 | fp = &new_field->field; | |
a9a9bd0f | 6954 | |
e142c38c | 6955 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6956 | { |
74ac6d43 TT |
6957 | LONGEST offset; |
6958 | ||
a9a9bd0f | 6959 | /* Data member other than a C++ static data member. */ |
6e70227d | 6960 | |
c906108c | 6961 | /* Get type of field. */ |
e7c27a73 | 6962 | fp->type = die_type (die, cu); |
c906108c | 6963 | |
d6a843b5 | 6964 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6965 | |
c906108c | 6966 | /* Get bit size of field (zero if none). */ |
e142c38c | 6967 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6968 | if (attr) |
6969 | { | |
6970 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6971 | } | |
6972 | else | |
6973 | { | |
6974 | FIELD_BITSIZE (*fp) = 0; | |
6975 | } | |
6976 | ||
6977 | /* Get bit offset of field. */ | |
74ac6d43 TT |
6978 | if (handle_data_member_location (die, cu, &offset)) |
6979 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 6980 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6981 | if (attr) |
6982 | { | |
5e2b427d | 6983 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6984 | { |
6985 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6986 | additional bit offset from the MSB of the containing |
6987 | anonymous object to the MSB of the field. We don't | |
6988 | have to do anything special since we don't need to | |
6989 | know the size of the anonymous object. */ | |
c906108c SS |
6990 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6991 | } | |
6992 | else | |
6993 | { | |
6994 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6995 | MSB of the anonymous object, subtract off the number of |
6996 | bits from the MSB of the field to the MSB of the | |
6997 | object, and then subtract off the number of bits of | |
6998 | the field itself. The result is the bit offset of | |
6999 | the LSB of the field. */ | |
c906108c SS |
7000 | int anonymous_size; |
7001 | int bit_offset = DW_UNSND (attr); | |
7002 | ||
e142c38c | 7003 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7004 | if (attr) |
7005 | { | |
7006 | /* The size of the anonymous object containing | |
7007 | the bit field is explicit, so use the | |
7008 | indicated size (in bytes). */ | |
7009 | anonymous_size = DW_UNSND (attr); | |
7010 | } | |
7011 | else | |
7012 | { | |
7013 | /* The size of the anonymous object containing | |
7014 | the bit field must be inferred from the type | |
7015 | attribute of the data member containing the | |
7016 | bit field. */ | |
7017 | anonymous_size = TYPE_LENGTH (fp->type); | |
7018 | } | |
7019 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
7020 | - bit_offset - FIELD_BITSIZE (*fp); | |
7021 | } | |
7022 | } | |
7023 | ||
7024 | /* Get name of field. */ | |
39cbfefa DJ |
7025 | fieldname = dwarf2_name (die, cu); |
7026 | if (fieldname == NULL) | |
7027 | fieldname = ""; | |
d8151005 DJ |
7028 | |
7029 | /* The name is already allocated along with this objfile, so we don't | |
7030 | need to duplicate it for the type. */ | |
7031 | fp->name = fieldname; | |
c906108c SS |
7032 | |
7033 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 7034 | pointer or virtual base class pointer) to private. */ |
e142c38c | 7035 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 7036 | { |
d48cc9dd | 7037 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
7038 | new_field->accessibility = DW_ACCESS_private; |
7039 | fip->non_public_fields = 1; | |
7040 | } | |
7041 | } | |
a9a9bd0f | 7042 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 7043 | { |
a9a9bd0f DC |
7044 | /* C++ static member. */ |
7045 | ||
7046 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
7047 | is a declaration, but all versions of G++ as of this writing | |
7048 | (so through at least 3.2.1) incorrectly generate | |
7049 | DW_TAG_variable tags. */ | |
6e70227d | 7050 | |
ff355380 | 7051 | const char *physname; |
c906108c | 7052 | |
a9a9bd0f | 7053 | /* Get name of field. */ |
39cbfefa DJ |
7054 | fieldname = dwarf2_name (die, cu); |
7055 | if (fieldname == NULL) | |
c906108c SS |
7056 | return; |
7057 | ||
254e6b9e | 7058 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
7059 | if (attr |
7060 | /* Only create a symbol if this is an external value. | |
7061 | new_symbol checks this and puts the value in the global symbol | |
7062 | table, which we want. If it is not external, new_symbol | |
7063 | will try to put the value in cu->list_in_scope which is wrong. */ | |
7064 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
7065 | { |
7066 | /* A static const member, not much different than an enum as far as | |
7067 | we're concerned, except that we can support more types. */ | |
7068 | new_symbol (die, NULL, cu); | |
7069 | } | |
7070 | ||
2df3850c | 7071 | /* Get physical name. */ |
ff355380 | 7072 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 7073 | |
d8151005 DJ |
7074 | /* The name is already allocated along with this objfile, so we don't |
7075 | need to duplicate it for the type. */ | |
7076 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 7077 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 7078 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
7079 | } |
7080 | else if (die->tag == DW_TAG_inheritance) | |
7081 | { | |
74ac6d43 | 7082 | LONGEST offset; |
d4b96c9a | 7083 | |
74ac6d43 TT |
7084 | /* C++ base class field. */ |
7085 | if (handle_data_member_location (die, cu, &offset)) | |
7086 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 7087 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 7088 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
7089 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
7090 | fip->nbaseclasses++; | |
7091 | } | |
7092 | } | |
7093 | ||
98751a41 JK |
7094 | /* Add a typedef defined in the scope of the FIP's class. */ |
7095 | ||
7096 | static void | |
7097 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
7098 | struct dwarf2_cu *cu) | |
6e70227d | 7099 | { |
98751a41 | 7100 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
7101 | struct typedef_field_list *new_field; |
7102 | struct attribute *attr; | |
7103 | struct typedef_field *fp; | |
7104 | char *fieldname = ""; | |
7105 | ||
7106 | /* Allocate a new field list entry and link it in. */ | |
7107 | new_field = xzalloc (sizeof (*new_field)); | |
7108 | make_cleanup (xfree, new_field); | |
7109 | ||
7110 | gdb_assert (die->tag == DW_TAG_typedef); | |
7111 | ||
7112 | fp = &new_field->field; | |
7113 | ||
7114 | /* Get name of field. */ | |
7115 | fp->name = dwarf2_name (die, cu); | |
7116 | if (fp->name == NULL) | |
7117 | return; | |
7118 | ||
7119 | fp->type = read_type_die (die, cu); | |
7120 | ||
7121 | new_field->next = fip->typedef_field_list; | |
7122 | fip->typedef_field_list = new_field; | |
7123 | fip->typedef_field_list_count++; | |
7124 | } | |
7125 | ||
c906108c SS |
7126 | /* Create the vector of fields, and attach it to the type. */ |
7127 | ||
7128 | static void | |
fba45db2 | 7129 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7130 | struct dwarf2_cu *cu) |
c906108c SS |
7131 | { |
7132 | int nfields = fip->nfields; | |
7133 | ||
7134 | /* Record the field count, allocate space for the array of fields, | |
7135 | and create blank accessibility bitfields if necessary. */ | |
7136 | TYPE_NFIELDS (type) = nfields; | |
7137 | TYPE_FIELDS (type) = (struct field *) | |
7138 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
7139 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
7140 | ||
b4ba55a1 | 7141 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
7142 | { |
7143 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7144 | ||
7145 | TYPE_FIELD_PRIVATE_BITS (type) = | |
7146 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7147 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
7148 | ||
7149 | TYPE_FIELD_PROTECTED_BITS (type) = | |
7150 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7151 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
7152 | ||
774b6a14 TT |
7153 | TYPE_FIELD_IGNORE_BITS (type) = |
7154 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7155 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
7156 | } |
7157 | ||
7158 | /* If the type has baseclasses, allocate and clear a bit vector for | |
7159 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 7160 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
7161 | { |
7162 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 7163 | unsigned char *pointer; |
c906108c SS |
7164 | |
7165 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
7166 | pointer = TYPE_ALLOC (type, num_bytes); |
7167 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
7168 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
7169 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
7170 | } | |
7171 | ||
3e43a32a MS |
7172 | /* Copy the saved-up fields into the field vector. Start from the head of |
7173 | the list, adding to the tail of the field array, so that they end up in | |
7174 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
7175 | while (nfields-- > 0) |
7176 | { | |
7d0ccb61 DJ |
7177 | struct nextfield *fieldp; |
7178 | ||
7179 | if (fip->fields) | |
7180 | { | |
7181 | fieldp = fip->fields; | |
7182 | fip->fields = fieldp->next; | |
7183 | } | |
7184 | else | |
7185 | { | |
7186 | fieldp = fip->baseclasses; | |
7187 | fip->baseclasses = fieldp->next; | |
7188 | } | |
7189 | ||
7190 | TYPE_FIELD (type, nfields) = fieldp->field; | |
7191 | switch (fieldp->accessibility) | |
c906108c | 7192 | { |
c5aa993b | 7193 | case DW_ACCESS_private: |
b4ba55a1 JB |
7194 | if (cu->language != language_ada) |
7195 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 7196 | break; |
c906108c | 7197 | |
c5aa993b | 7198 | case DW_ACCESS_protected: |
b4ba55a1 JB |
7199 | if (cu->language != language_ada) |
7200 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 7201 | break; |
c906108c | 7202 | |
c5aa993b JM |
7203 | case DW_ACCESS_public: |
7204 | break; | |
c906108c | 7205 | |
c5aa993b JM |
7206 | default: |
7207 | /* Unknown accessibility. Complain and treat it as public. */ | |
7208 | { | |
e2e0b3e5 | 7209 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 7210 | fieldp->accessibility); |
c5aa993b JM |
7211 | } |
7212 | break; | |
c906108c SS |
7213 | } |
7214 | if (nfields < fip->nbaseclasses) | |
7215 | { | |
7d0ccb61 | 7216 | switch (fieldp->virtuality) |
c906108c | 7217 | { |
c5aa993b JM |
7218 | case DW_VIRTUALITY_virtual: |
7219 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 7220 | if (cu->language == language_ada) |
a73c6dcd | 7221 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
7222 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
7223 | break; | |
c906108c SS |
7224 | } |
7225 | } | |
c906108c SS |
7226 | } |
7227 | } | |
7228 | ||
c906108c SS |
7229 | /* Add a member function to the proper fieldlist. */ |
7230 | ||
7231 | static void | |
107d2387 | 7232 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 7233 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 7234 | { |
e7c27a73 | 7235 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7236 | struct attribute *attr; |
7237 | struct fnfieldlist *flp; | |
7238 | int i; | |
7239 | struct fn_field *fnp; | |
7240 | char *fieldname; | |
c906108c | 7241 | struct nextfnfield *new_fnfield; |
f792889a | 7242 | struct type *this_type; |
60d5a603 | 7243 | enum dwarf_access_attribute accessibility; |
c906108c | 7244 | |
b4ba55a1 | 7245 | if (cu->language == language_ada) |
a73c6dcd | 7246 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 7247 | |
2df3850c | 7248 | /* Get name of member function. */ |
39cbfefa DJ |
7249 | fieldname = dwarf2_name (die, cu); |
7250 | if (fieldname == NULL) | |
2df3850c | 7251 | return; |
c906108c | 7252 | |
c906108c SS |
7253 | /* Look up member function name in fieldlist. */ |
7254 | for (i = 0; i < fip->nfnfields; i++) | |
7255 | { | |
27bfe10e | 7256 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
7257 | break; |
7258 | } | |
7259 | ||
7260 | /* Create new list element if necessary. */ | |
7261 | if (i < fip->nfnfields) | |
7262 | flp = &fip->fnfieldlists[i]; | |
7263 | else | |
7264 | { | |
7265 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7266 | { | |
7267 | fip->fnfieldlists = (struct fnfieldlist *) | |
7268 | xrealloc (fip->fnfieldlists, | |
7269 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7270 | * sizeof (struct fnfieldlist)); |
c906108c | 7271 | if (fip->nfnfields == 0) |
c13c43fd | 7272 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
7273 | } |
7274 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
7275 | flp->name = fieldname; | |
7276 | flp->length = 0; | |
7277 | flp->head = NULL; | |
3da10d80 | 7278 | i = fip->nfnfields++; |
c906108c SS |
7279 | } |
7280 | ||
7281 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 7282 | entry. */ |
c906108c | 7283 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 7284 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
7285 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
7286 | new_fnfield->next = flp->head; | |
7287 | flp->head = new_fnfield; | |
7288 | flp->length++; | |
7289 | ||
7290 | /* Fill in the member function field info. */ | |
7291 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
7292 | |
7293 | /* Delay processing of the physname until later. */ | |
7294 | if (cu->language == language_cplus || cu->language == language_java) | |
7295 | { | |
7296 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
7297 | die, cu); | |
7298 | } | |
7299 | else | |
7300 | { | |
1d06ead6 | 7301 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
7302 | fnp->physname = physname ? physname : ""; |
7303 | } | |
7304 | ||
c906108c | 7305 | fnp->type = alloc_type (objfile); |
f792889a DJ |
7306 | this_type = read_type_die (die, cu); |
7307 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 7308 | { |
f792889a | 7309 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 7310 | |
f792889a | 7311 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
7312 | of the method itself (TYPE_CODE_METHOD). */ |
7313 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
7314 | TYPE_TARGET_TYPE (this_type), |
7315 | TYPE_FIELDS (this_type), | |
7316 | TYPE_NFIELDS (this_type), | |
7317 | TYPE_VARARGS (this_type)); | |
c906108c SS |
7318 | |
7319 | /* Handle static member functions. | |
c5aa993b | 7320 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
7321 | member functions. G++ helps GDB by marking the first |
7322 | parameter for non-static member functions (which is the this | |
7323 | pointer) as artificial. We obtain this information from | |
7324 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 7325 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
7326 | fnp->voffset = VOFFSET_STATIC; |
7327 | } | |
7328 | else | |
e2e0b3e5 | 7329 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 7330 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
7331 | |
7332 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 7333 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 7334 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 7335 | |
3e43a32a MS |
7336 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
7337 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
7338 | |
7339 | /* Get accessibility. */ | |
e142c38c | 7340 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 7341 | if (attr) |
60d5a603 JK |
7342 | accessibility = DW_UNSND (attr); |
7343 | else | |
7344 | accessibility = dwarf2_default_access_attribute (die, cu); | |
7345 | switch (accessibility) | |
c906108c | 7346 | { |
60d5a603 JK |
7347 | case DW_ACCESS_private: |
7348 | fnp->is_private = 1; | |
7349 | break; | |
7350 | case DW_ACCESS_protected: | |
7351 | fnp->is_protected = 1; | |
7352 | break; | |
c906108c SS |
7353 | } |
7354 | ||
b02dede2 | 7355 | /* Check for artificial methods. */ |
e142c38c | 7356 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
7357 | if (attr && DW_UNSND (attr) != 0) |
7358 | fnp->is_artificial = 1; | |
7359 | ||
0d564a31 | 7360 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
7361 | function. For older versions of GCC, this is an offset in the |
7362 | appropriate virtual table, as specified by DW_AT_containing_type. | |
7363 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
7364 | to the object address. */ |
7365 | ||
e142c38c | 7366 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 7367 | if (attr) |
8e19ed76 | 7368 | { |
aec5aa8b | 7369 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 7370 | { |
aec5aa8b TT |
7371 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
7372 | { | |
7373 | /* Old-style GCC. */ | |
7374 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
7375 | } | |
7376 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7377 | || (DW_BLOCK (attr)->size > 1 | |
7378 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
7379 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
7380 | { | |
7381 | struct dwarf_block blk; | |
7382 | int offset; | |
7383 | ||
7384 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7385 | ? 1 : 2); | |
7386 | blk.size = DW_BLOCK (attr)->size - offset; | |
7387 | blk.data = DW_BLOCK (attr)->data + offset; | |
7388 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
7389 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
7390 | dwarf2_complex_location_expr_complaint (); | |
7391 | else | |
7392 | fnp->voffset /= cu->header.addr_size; | |
7393 | fnp->voffset += 2; | |
7394 | } | |
7395 | else | |
7396 | dwarf2_complex_location_expr_complaint (); | |
7397 | ||
7398 | if (!fnp->fcontext) | |
7399 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
7400 | } | |
3690dd37 | 7401 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7402 | { |
4d3c2250 | 7403 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7404 | } |
7405 | else | |
7406 | { | |
4d3c2250 KB |
7407 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
7408 | fieldname); | |
8e19ed76 | 7409 | } |
0d564a31 | 7410 | } |
d48cc9dd DJ |
7411 | else |
7412 | { | |
7413 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
7414 | if (attr && DW_UNSND (attr)) | |
7415 | { | |
7416 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
7417 | complaint (&symfile_complaints, | |
3e43a32a MS |
7418 | _("Member function \"%s\" (offset %d) is virtual " |
7419 | "but the vtable offset is not specified"), | |
d48cc9dd | 7420 | fieldname, die->offset); |
9655fd1a | 7421 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
7422 | TYPE_CPLUS_DYNAMIC (type) = 1; |
7423 | } | |
7424 | } | |
c906108c SS |
7425 | } |
7426 | ||
7427 | /* Create the vector of member function fields, and attach it to the type. */ | |
7428 | ||
7429 | static void | |
fba45db2 | 7430 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7431 | struct dwarf2_cu *cu) |
c906108c SS |
7432 | { |
7433 | struct fnfieldlist *flp; | |
7434 | int total_length = 0; | |
7435 | int i; | |
7436 | ||
b4ba55a1 | 7437 | if (cu->language == language_ada) |
a73c6dcd | 7438 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 7439 | |
c906108c SS |
7440 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
7441 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
7442 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
7443 | ||
7444 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
7445 | { | |
7446 | struct nextfnfield *nfp = flp->head; | |
7447 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
7448 | int k; | |
7449 | ||
7450 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
7451 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
7452 | fn_flp->fn_fields = (struct fn_field *) | |
7453 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
7454 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 7455 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
7456 | |
7457 | total_length += flp->length; | |
7458 | } | |
7459 | ||
7460 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
7461 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
7462 | } | |
7463 | ||
1168df01 JB |
7464 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
7465 | language, zero otherwise. */ | |
7466 | static int | |
7467 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
7468 | { | |
7469 | static const char vptr[] = "_vptr"; | |
987504bb | 7470 | static const char vtable[] = "vtable"; |
1168df01 | 7471 | |
987504bb JJ |
7472 | /* Look for the C++ and Java forms of the vtable. */ |
7473 | if ((cu->language == language_java | |
7474 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
7475 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
7476 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
7477 | return 1; |
7478 | ||
7479 | return 0; | |
7480 | } | |
7481 | ||
c0dd20ea | 7482 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
7483 | functions, with the ABI-specified layout. If TYPE describes |
7484 | such a structure, smash it into a member function type. | |
61049d3b DJ |
7485 | |
7486 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
7487 | This is GCC PR debug/28767. */ | |
c0dd20ea | 7488 | |
0b92b5bb TT |
7489 | static void |
7490 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 7491 | { |
0b92b5bb | 7492 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
7493 | |
7494 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
7495 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
7496 | return; | |
c0dd20ea DJ |
7497 | |
7498 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
7499 | if (TYPE_FIELD_NAME (type, 0) == NULL |
7500 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
7501 | || TYPE_FIELD_NAME (type, 1) == NULL | |
7502 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
7503 | return; | |
c0dd20ea DJ |
7504 | |
7505 | /* Find the type of the method. */ | |
0b92b5bb | 7506 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
7507 | if (pfn_type == NULL |
7508 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
7509 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 7510 | return; |
c0dd20ea DJ |
7511 | |
7512 | /* Look for the "this" argument. */ | |
7513 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
7514 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 7515 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 7516 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 7517 | return; |
c0dd20ea DJ |
7518 | |
7519 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
7520 | new_type = alloc_type (objfile); |
7521 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
7522 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
7523 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 7524 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 7525 | } |
1168df01 | 7526 | |
c906108c | 7527 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
7528 | (definition) to create a type for the structure or union. Fill in |
7529 | the type's name and general properties; the members will not be | |
7530 | processed until process_structure_type. | |
c906108c | 7531 | |
c767944b DJ |
7532 | NOTE: we need to call these functions regardless of whether or not the |
7533 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
7534 | structure or union. This gets the type entered into our set of |
7535 | user defined types. | |
7536 | ||
7537 | However, if the structure is incomplete (an opaque struct/union) | |
7538 | then suppress creating a symbol table entry for it since gdb only | |
7539 | wants to find the one with the complete definition. Note that if | |
7540 | it is complete, we just call new_symbol, which does it's own | |
7541 | checking about whether the struct/union is anonymous or not (and | |
7542 | suppresses creating a symbol table entry itself). */ | |
7543 | ||
f792889a | 7544 | static struct type * |
134d01f1 | 7545 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7546 | { |
e7c27a73 | 7547 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7548 | struct type *type; |
7549 | struct attribute *attr; | |
39cbfefa | 7550 | char *name; |
c906108c | 7551 | |
348e048f DE |
7552 | /* If the definition of this type lives in .debug_types, read that type. |
7553 | Don't follow DW_AT_specification though, that will take us back up | |
7554 | the chain and we want to go down. */ | |
7555 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7556 | if (attr) | |
7557 | { | |
7558 | struct dwarf2_cu *type_cu = cu; | |
7559 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7560 | |
348e048f DE |
7561 | /* We could just recurse on read_structure_type, but we need to call |
7562 | get_die_type to ensure only one type for this DIE is created. | |
7563 | This is important, for example, because for c++ classes we need | |
7564 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
7565 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
7566 | |
7567 | /* TYPE_CU may not be the same as CU. | |
7568 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7569 | return set_die_type (die, type, cu); |
7570 | } | |
7571 | ||
c0dd20ea | 7572 | type = alloc_type (objfile); |
c906108c | 7573 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 7574 | |
39cbfefa DJ |
7575 | name = dwarf2_name (die, cu); |
7576 | if (name != NULL) | |
c906108c | 7577 | { |
987504bb JJ |
7578 | if (cu->language == language_cplus |
7579 | || cu->language == language_java) | |
63d06c5c | 7580 | { |
3da10d80 KS |
7581 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
7582 | ||
7583 | /* dwarf2_full_name might have already finished building the DIE's | |
7584 | type. If so, there is no need to continue. */ | |
7585 | if (get_die_type (die, cu) != NULL) | |
7586 | return get_die_type (die, cu); | |
7587 | ||
7588 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
7589 | if (die->tag == DW_TAG_structure_type |
7590 | || die->tag == DW_TAG_class_type) | |
7591 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
7592 | } |
7593 | else | |
7594 | { | |
d8151005 DJ |
7595 | /* The name is already allocated along with this objfile, so |
7596 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
7597 | TYPE_TAG_NAME (type) = (char *) name; |
7598 | if (die->tag == DW_TAG_class_type) | |
7599 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 7600 | } |
c906108c SS |
7601 | } |
7602 | ||
7603 | if (die->tag == DW_TAG_structure_type) | |
7604 | { | |
7605 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
7606 | } | |
7607 | else if (die->tag == DW_TAG_union_type) | |
7608 | { | |
7609 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
7610 | } | |
7611 | else | |
7612 | { | |
c906108c SS |
7613 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
7614 | } | |
7615 | ||
0cc2414c TT |
7616 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
7617 | TYPE_DECLARED_CLASS (type) = 1; | |
7618 | ||
e142c38c | 7619 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7620 | if (attr) |
7621 | { | |
7622 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7623 | } | |
7624 | else | |
7625 | { | |
7626 | TYPE_LENGTH (type) = 0; | |
7627 | } | |
7628 | ||
876cecd0 | 7629 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 7630 | if (die_is_declaration (die, cu)) |
876cecd0 | 7631 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
7632 | else if (attr == NULL && die->child == NULL |
7633 | && producer_is_realview (cu->producer)) | |
7634 | /* RealView does not output the required DW_AT_declaration | |
7635 | on incomplete types. */ | |
7636 | TYPE_STUB (type) = 1; | |
dc718098 | 7637 | |
c906108c SS |
7638 | /* We need to add the type field to the die immediately so we don't |
7639 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 7640 | type within the structure itself. */ |
1c379e20 | 7641 | set_die_type (die, type, cu); |
c906108c | 7642 | |
7e314c57 JK |
7643 | /* set_die_type should be already done. */ |
7644 | set_descriptive_type (type, die, cu); | |
7645 | ||
c767944b DJ |
7646 | return type; |
7647 | } | |
7648 | ||
7649 | /* Finish creating a structure or union type, including filling in | |
7650 | its members and creating a symbol for it. */ | |
7651 | ||
7652 | static void | |
7653 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7654 | { | |
7655 | struct objfile *objfile = cu->objfile; | |
7656 | struct die_info *child_die = die->child; | |
7657 | struct type *type; | |
7658 | ||
7659 | type = get_die_type (die, cu); | |
7660 | if (type == NULL) | |
7661 | type = read_structure_type (die, cu); | |
7662 | ||
e142c38c | 7663 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
7664 | { |
7665 | struct field_info fi; | |
7666 | struct die_info *child_die; | |
34eaf542 | 7667 | VEC (symbolp) *template_args = NULL; |
c767944b | 7668 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
7669 | |
7670 | memset (&fi, 0, sizeof (struct field_info)); | |
7671 | ||
639d11d3 | 7672 | child_die = die->child; |
c906108c SS |
7673 | |
7674 | while (child_die && child_die->tag) | |
7675 | { | |
a9a9bd0f DC |
7676 | if (child_die->tag == DW_TAG_member |
7677 | || child_die->tag == DW_TAG_variable) | |
c906108c | 7678 | { |
a9a9bd0f DC |
7679 | /* NOTE: carlton/2002-11-05: A C++ static data member |
7680 | should be a DW_TAG_member that is a declaration, but | |
7681 | all versions of G++ as of this writing (so through at | |
7682 | least 3.2.1) incorrectly generate DW_TAG_variable | |
7683 | tags for them instead. */ | |
e7c27a73 | 7684 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7685 | } |
8713b1b1 | 7686 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 7687 | { |
0963b4bd | 7688 | /* C++ member function. */ |
e7c27a73 | 7689 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
7690 | } |
7691 | else if (child_die->tag == DW_TAG_inheritance) | |
7692 | { | |
7693 | /* C++ base class field. */ | |
e7c27a73 | 7694 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7695 | } |
98751a41 JK |
7696 | else if (child_die->tag == DW_TAG_typedef) |
7697 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
7698 | else if (child_die->tag == DW_TAG_template_type_param |
7699 | || child_die->tag == DW_TAG_template_value_param) | |
7700 | { | |
7701 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7702 | ||
f1078f66 DJ |
7703 | if (arg != NULL) |
7704 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7705 | } |
7706 | ||
c906108c SS |
7707 | child_die = sibling_die (child_die); |
7708 | } | |
7709 | ||
34eaf542 TT |
7710 | /* Attach template arguments to type. */ |
7711 | if (! VEC_empty (symbolp, template_args)) | |
7712 | { | |
7713 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7714 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7715 | = VEC_length (symbolp, template_args); | |
7716 | TYPE_TEMPLATE_ARGUMENTS (type) | |
7717 | = obstack_alloc (&objfile->objfile_obstack, | |
7718 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7719 | * sizeof (struct symbol *))); | |
7720 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
7721 | VEC_address (symbolp, template_args), | |
7722 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7723 | * sizeof (struct symbol *))); | |
7724 | VEC_free (symbolp, template_args); | |
7725 | } | |
7726 | ||
c906108c SS |
7727 | /* Attach fields and member functions to the type. */ |
7728 | if (fi.nfields) | |
e7c27a73 | 7729 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
7730 | if (fi.nfnfields) |
7731 | { | |
e7c27a73 | 7732 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 7733 | |
c5aa993b | 7734 | /* Get the type which refers to the base class (possibly this |
c906108c | 7735 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
7736 | class from the DW_AT_containing_type attribute. This use of |
7737 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 7738 | |
e142c38c | 7739 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 7740 | { |
e7c27a73 | 7741 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
7742 | |
7743 | TYPE_VPTR_BASETYPE (type) = t; | |
7744 | if (type == t) | |
7745 | { | |
c906108c SS |
7746 | int i; |
7747 | ||
7748 | /* Our own class provides vtbl ptr. */ | |
7749 | for (i = TYPE_NFIELDS (t) - 1; | |
7750 | i >= TYPE_N_BASECLASSES (t); | |
7751 | --i) | |
7752 | { | |
7753 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
7754 | ||
1168df01 | 7755 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
7756 | { |
7757 | TYPE_VPTR_FIELDNO (type) = i; | |
7758 | break; | |
7759 | } | |
7760 | } | |
7761 | ||
7762 | /* Complain if virtual function table field not found. */ | |
7763 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 7764 | complaint (&symfile_complaints, |
3e43a32a MS |
7765 | _("virtual function table pointer " |
7766 | "not found when defining class '%s'"), | |
4d3c2250 KB |
7767 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
7768 | ""); | |
c906108c SS |
7769 | } |
7770 | else | |
7771 | { | |
7772 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
7773 | } | |
7774 | } | |
f6235d4c EZ |
7775 | else if (cu->producer |
7776 | && strncmp (cu->producer, | |
7777 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
7778 | { | |
7779 | /* The IBM XLC compiler does not provide direct indication | |
7780 | of the containing type, but the vtable pointer is | |
7781 | always named __vfp. */ | |
7782 | ||
7783 | int i; | |
7784 | ||
7785 | for (i = TYPE_NFIELDS (type) - 1; | |
7786 | i >= TYPE_N_BASECLASSES (type); | |
7787 | --i) | |
7788 | { | |
7789 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
7790 | { | |
7791 | TYPE_VPTR_FIELDNO (type) = i; | |
7792 | TYPE_VPTR_BASETYPE (type) = type; | |
7793 | break; | |
7794 | } | |
7795 | } | |
7796 | } | |
c906108c | 7797 | } |
98751a41 JK |
7798 | |
7799 | /* Copy fi.typedef_field_list linked list elements content into the | |
7800 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
7801 | if (fi.typedef_field_list) | |
7802 | { | |
7803 | int i = fi.typedef_field_list_count; | |
7804 | ||
a0d7a4ff | 7805 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
7806 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
7807 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
7808 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
7809 | ||
7810 | /* Reverse the list order to keep the debug info elements order. */ | |
7811 | while (--i >= 0) | |
7812 | { | |
7813 | struct typedef_field *dest, *src; | |
6e70227d | 7814 | |
98751a41 JK |
7815 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
7816 | src = &fi.typedef_field_list->field; | |
7817 | fi.typedef_field_list = fi.typedef_field_list->next; | |
7818 | *dest = *src; | |
7819 | } | |
7820 | } | |
c767944b DJ |
7821 | |
7822 | do_cleanups (back_to); | |
eb2a6f42 TT |
7823 | |
7824 | if (HAVE_CPLUS_STRUCT (type)) | |
7825 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 7826 | } |
63d06c5c | 7827 | |
0b92b5bb TT |
7828 | quirk_gcc_member_function_pointer (type, cu->objfile); |
7829 | ||
90aeadfc DC |
7830 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
7831 | snapshots) has been known to create a die giving a declaration | |
7832 | for a class that has, as a child, a die giving a definition for a | |
7833 | nested class. So we have to process our children even if the | |
7834 | current die is a declaration. Normally, of course, a declaration | |
7835 | won't have any children at all. */ | |
134d01f1 | 7836 | |
90aeadfc DC |
7837 | while (child_die != NULL && child_die->tag) |
7838 | { | |
7839 | if (child_die->tag == DW_TAG_member | |
7840 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
7841 | || child_die->tag == DW_TAG_inheritance |
7842 | || child_die->tag == DW_TAG_template_value_param | |
7843 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 7844 | { |
90aeadfc | 7845 | /* Do nothing. */ |
134d01f1 | 7846 | } |
90aeadfc DC |
7847 | else |
7848 | process_die (child_die, cu); | |
134d01f1 | 7849 | |
90aeadfc | 7850 | child_die = sibling_die (child_die); |
134d01f1 DJ |
7851 | } |
7852 | ||
fa4028e9 JB |
7853 | /* Do not consider external references. According to the DWARF standard, |
7854 | these DIEs are identified by the fact that they have no byte_size | |
7855 | attribute, and a declaration attribute. */ | |
7856 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
7857 | || !die_is_declaration (die, cu)) | |
c767944b | 7858 | new_symbol (die, type, cu); |
134d01f1 DJ |
7859 | } |
7860 | ||
7861 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
7862 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 7863 | |
f792889a | 7864 | static struct type * |
134d01f1 | 7865 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7866 | { |
e7c27a73 | 7867 | struct objfile *objfile = cu->objfile; |
c906108c | 7868 | struct type *type; |
c906108c | 7869 | struct attribute *attr; |
0114d602 | 7870 | const char *name; |
134d01f1 | 7871 | |
348e048f DE |
7872 | /* If the definition of this type lives in .debug_types, read that type. |
7873 | Don't follow DW_AT_specification though, that will take us back up | |
7874 | the chain and we want to go down. */ | |
7875 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7876 | if (attr) | |
7877 | { | |
7878 | struct dwarf2_cu *type_cu = cu; | |
7879 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7880 | |
348e048f | 7881 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7882 | |
7883 | /* TYPE_CU may not be the same as CU. | |
7884 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7885 | return set_die_type (die, type, cu); |
7886 | } | |
7887 | ||
c906108c SS |
7888 | type = alloc_type (objfile); |
7889 | ||
7890 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7891 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7892 | if (name != NULL) |
0114d602 | 7893 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7894 | |
e142c38c | 7895 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7896 | if (attr) |
7897 | { | |
7898 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7899 | } | |
7900 | else | |
7901 | { | |
7902 | TYPE_LENGTH (type) = 0; | |
7903 | } | |
7904 | ||
137033e9 JB |
7905 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7906 | declared as private in the package spec, and then defined only | |
7907 | inside the package body. Such types are known as Taft Amendment | |
7908 | Types. When another package uses such a type, an incomplete DIE | |
7909 | may be generated by the compiler. */ | |
02eb380e | 7910 | if (die_is_declaration (die, cu)) |
876cecd0 | 7911 | TYPE_STUB (type) = 1; |
02eb380e | 7912 | |
f792889a | 7913 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7914 | } |
7915 | ||
7916 | /* Given a pointer to a die which begins an enumeration, process all | |
7917 | the dies that define the members of the enumeration, and create the | |
7918 | symbol for the enumeration type. | |
7919 | ||
7920 | NOTE: We reverse the order of the element list. */ | |
7921 | ||
7922 | static void | |
7923 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7924 | { | |
f792889a | 7925 | struct type *this_type; |
134d01f1 | 7926 | |
f792889a DJ |
7927 | this_type = get_die_type (die, cu); |
7928 | if (this_type == NULL) | |
7929 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7930 | |
639d11d3 | 7931 | if (die->child != NULL) |
c906108c | 7932 | { |
9dc481d3 DE |
7933 | struct die_info *child_die; |
7934 | struct symbol *sym; | |
7935 | struct field *fields = NULL; | |
7936 | int num_fields = 0; | |
7937 | int unsigned_enum = 1; | |
7938 | char *name; | |
7939 | ||
639d11d3 | 7940 | child_die = die->child; |
c906108c SS |
7941 | while (child_die && child_die->tag) |
7942 | { | |
7943 | if (child_die->tag != DW_TAG_enumerator) | |
7944 | { | |
e7c27a73 | 7945 | process_die (child_die, cu); |
c906108c SS |
7946 | } |
7947 | else | |
7948 | { | |
39cbfefa DJ |
7949 | name = dwarf2_name (child_die, cu); |
7950 | if (name) | |
c906108c | 7951 | { |
f792889a | 7952 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7953 | if (SYMBOL_VALUE (sym) < 0) |
7954 | unsigned_enum = 0; | |
7955 | ||
7956 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7957 | { | |
7958 | fields = (struct field *) | |
7959 | xrealloc (fields, | |
7960 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7961 | * sizeof (struct field)); |
c906108c SS |
7962 | } |
7963 | ||
3567439c | 7964 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7965 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7966 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7967 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7968 | ||
7969 | num_fields++; | |
7970 | } | |
7971 | } | |
7972 | ||
7973 | child_die = sibling_die (child_die); | |
7974 | } | |
7975 | ||
7976 | if (num_fields) | |
7977 | { | |
f792889a DJ |
7978 | TYPE_NFIELDS (this_type) = num_fields; |
7979 | TYPE_FIELDS (this_type) = (struct field *) | |
7980 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7981 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7982 | sizeof (struct field) * num_fields); |
b8c9b27d | 7983 | xfree (fields); |
c906108c SS |
7984 | } |
7985 | if (unsigned_enum) | |
876cecd0 | 7986 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7987 | } |
134d01f1 | 7988 | |
6c83ed52 TT |
7989 | /* If we are reading an enum from a .debug_types unit, and the enum |
7990 | is a declaration, and the enum is not the signatured type in the | |
7991 | unit, then we do not want to add a symbol for it. Adding a | |
7992 | symbol would in some cases obscure the true definition of the | |
7993 | enum, giving users an incomplete type when the definition is | |
7994 | actually available. Note that we do not want to do this for all | |
7995 | enums which are just declarations, because C++0x allows forward | |
7996 | enum declarations. */ | |
7997 | if (cu->per_cu->debug_type_section | |
7998 | && die_is_declaration (die, cu)) | |
7999 | { | |
8000 | struct signatured_type *type_sig; | |
8001 | ||
8002 | type_sig | |
8003 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, | |
8004 | cu->per_cu->debug_type_section, | |
8005 | cu->per_cu->offset); | |
8006 | if (type_sig->type_offset != die->offset) | |
8007 | return; | |
8008 | } | |
8009 | ||
f792889a | 8010 | new_symbol (die, this_type, cu); |
c906108c SS |
8011 | } |
8012 | ||
8013 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
8014 | the DIE's type field. For now, this only handles one dimensional | |
8015 | arrays. */ | |
8016 | ||
f792889a | 8017 | static struct type * |
e7c27a73 | 8018 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8019 | { |
e7c27a73 | 8020 | struct objfile *objfile = cu->objfile; |
c906108c | 8021 | struct die_info *child_die; |
7e314c57 | 8022 | struct type *type; |
c906108c SS |
8023 | struct type *element_type, *range_type, *index_type; |
8024 | struct type **range_types = NULL; | |
8025 | struct attribute *attr; | |
8026 | int ndim = 0; | |
8027 | struct cleanup *back_to; | |
39cbfefa | 8028 | char *name; |
c906108c | 8029 | |
e7c27a73 | 8030 | element_type = die_type (die, cu); |
c906108c | 8031 | |
7e314c57 JK |
8032 | /* The die_type call above may have already set the type for this DIE. */ |
8033 | type = get_die_type (die, cu); | |
8034 | if (type) | |
8035 | return type; | |
8036 | ||
c906108c SS |
8037 | /* Irix 6.2 native cc creates array types without children for |
8038 | arrays with unspecified length. */ | |
639d11d3 | 8039 | if (die->child == NULL) |
c906108c | 8040 | { |
46bf5051 | 8041 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8042 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
8043 | type = create_array_type (NULL, element_type, range_type); |
8044 | return set_die_type (die, type, cu); | |
c906108c SS |
8045 | } |
8046 | ||
8047 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 8048 | child_die = die->child; |
c906108c SS |
8049 | while (child_die && child_die->tag) |
8050 | { | |
8051 | if (child_die->tag == DW_TAG_subrange_type) | |
8052 | { | |
f792889a | 8053 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 8054 | |
f792889a | 8055 | if (child_type != NULL) |
a02abb62 | 8056 | { |
0963b4bd MS |
8057 | /* The range type was succesfully read. Save it for the |
8058 | array type creation. */ | |
a02abb62 JB |
8059 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
8060 | { | |
8061 | range_types = (struct type **) | |
8062 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
8063 | * sizeof (struct type *)); | |
8064 | if (ndim == 0) | |
8065 | make_cleanup (free_current_contents, &range_types); | |
8066 | } | |
f792889a | 8067 | range_types[ndim++] = child_type; |
a02abb62 | 8068 | } |
c906108c SS |
8069 | } |
8070 | child_die = sibling_die (child_die); | |
8071 | } | |
8072 | ||
8073 | /* Dwarf2 dimensions are output from left to right, create the | |
8074 | necessary array types in backwards order. */ | |
7ca2d3a3 | 8075 | |
c906108c | 8076 | type = element_type; |
7ca2d3a3 DL |
8077 | |
8078 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
8079 | { | |
8080 | int i = 0; | |
9a619af0 | 8081 | |
7ca2d3a3 DL |
8082 | while (i < ndim) |
8083 | type = create_array_type (NULL, type, range_types[i++]); | |
8084 | } | |
8085 | else | |
8086 | { | |
8087 | while (ndim-- > 0) | |
8088 | type = create_array_type (NULL, type, range_types[ndim]); | |
8089 | } | |
c906108c | 8090 | |
f5f8a009 EZ |
8091 | /* Understand Dwarf2 support for vector types (like they occur on |
8092 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
8093 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
8094 | custom vendor extension. The main difference between a regular | |
8095 | array and the vector variant is that vectors are passed by value | |
8096 | to functions. */ | |
e142c38c | 8097 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 8098 | if (attr) |
ea37ba09 | 8099 | make_vector_type (type); |
f5f8a009 | 8100 | |
dbc98a8b KW |
8101 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
8102 | implementation may choose to implement triple vectors using this | |
8103 | attribute. */ | |
8104 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
8105 | if (attr) | |
8106 | { | |
8107 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
8108 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8109 | else | |
3e43a32a MS |
8110 | complaint (&symfile_complaints, |
8111 | _("DW_AT_byte_size for array type smaller " | |
8112 | "than the total size of elements")); | |
dbc98a8b KW |
8113 | } |
8114 | ||
39cbfefa DJ |
8115 | name = dwarf2_name (die, cu); |
8116 | if (name) | |
8117 | TYPE_NAME (type) = name; | |
6e70227d | 8118 | |
0963b4bd | 8119 | /* Install the type in the die. */ |
7e314c57 JK |
8120 | set_die_type (die, type, cu); |
8121 | ||
8122 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8123 | set_descriptive_type (type, die, cu); |
8124 | ||
c906108c SS |
8125 | do_cleanups (back_to); |
8126 | ||
7e314c57 | 8127 | return type; |
c906108c SS |
8128 | } |
8129 | ||
7ca2d3a3 | 8130 | static enum dwarf_array_dim_ordering |
6e70227d | 8131 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
8132 | { |
8133 | struct attribute *attr; | |
8134 | ||
8135 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
8136 | ||
8137 | if (attr) return DW_SND (attr); | |
8138 | ||
0963b4bd MS |
8139 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
8140 | opposite order to the dwarf2 specification, but data is still | |
8141 | laid out as per normal fortran. | |
7ca2d3a3 | 8142 | |
0963b4bd MS |
8143 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
8144 | version checking. */ | |
7ca2d3a3 | 8145 | |
905e0470 PM |
8146 | if (cu->language == language_fortran |
8147 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
8148 | { |
8149 | return DW_ORD_row_major; | |
8150 | } | |
8151 | ||
6e70227d | 8152 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
8153 | { |
8154 | case array_column_major: | |
8155 | return DW_ORD_col_major; | |
8156 | case array_row_major: | |
8157 | default: | |
8158 | return DW_ORD_row_major; | |
8159 | }; | |
8160 | } | |
8161 | ||
72019c9c | 8162 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 8163 | the DIE's type field. */ |
72019c9c | 8164 | |
f792889a | 8165 | static struct type * |
72019c9c GM |
8166 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
8167 | { | |
7e314c57 JK |
8168 | struct type *domain_type, *set_type; |
8169 | struct attribute *attr; | |
f792889a | 8170 | |
7e314c57 JK |
8171 | domain_type = die_type (die, cu); |
8172 | ||
8173 | /* The die_type call above may have already set the type for this DIE. */ | |
8174 | set_type = get_die_type (die, cu); | |
8175 | if (set_type) | |
8176 | return set_type; | |
8177 | ||
8178 | set_type = create_set_type (NULL, domain_type); | |
8179 | ||
8180 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
8181 | if (attr) |
8182 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 8183 | |
f792889a | 8184 | return set_die_type (die, set_type, cu); |
72019c9c | 8185 | } |
7ca2d3a3 | 8186 | |
c906108c SS |
8187 | /* First cut: install each common block member as a global variable. */ |
8188 | ||
8189 | static void | |
e7c27a73 | 8190 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8191 | { |
8192 | struct die_info *child_die; | |
8193 | struct attribute *attr; | |
8194 | struct symbol *sym; | |
8195 | CORE_ADDR base = (CORE_ADDR) 0; | |
8196 | ||
e142c38c | 8197 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8198 | if (attr) |
8199 | { | |
0963b4bd | 8200 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
8201 | if (attr_form_is_block (attr)) |
8202 | { | |
e7c27a73 | 8203 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 8204 | } |
3690dd37 | 8205 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 8206 | { |
4d3c2250 | 8207 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8208 | } |
8209 | else | |
8210 | { | |
4d3c2250 KB |
8211 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8212 | "common block member"); | |
8e19ed76 | 8213 | } |
c906108c | 8214 | } |
639d11d3 | 8215 | if (die->child != NULL) |
c906108c | 8216 | { |
639d11d3 | 8217 | child_die = die->child; |
c906108c SS |
8218 | while (child_die && child_die->tag) |
8219 | { | |
74ac6d43 TT |
8220 | LONGEST offset; |
8221 | ||
e7c27a73 | 8222 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
8223 | if (sym != NULL |
8224 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 8225 | { |
74ac6d43 | 8226 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
8227 | add_symbol_to_list (sym, &global_symbols); |
8228 | } | |
8229 | child_die = sibling_die (child_die); | |
8230 | } | |
8231 | } | |
8232 | } | |
8233 | ||
0114d602 | 8234 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 8235 | |
0114d602 DJ |
8236 | static struct type * |
8237 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 8238 | { |
e7c27a73 | 8239 | struct objfile *objfile = cu->objfile; |
0114d602 | 8240 | const char *previous_prefix, *name; |
9219021c | 8241 | int is_anonymous; |
0114d602 DJ |
8242 | struct type *type; |
8243 | ||
8244 | /* For extensions, reuse the type of the original namespace. */ | |
8245 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
8246 | { | |
8247 | struct die_info *ext_die; | |
8248 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 8249 | |
0114d602 DJ |
8250 | ext_die = dwarf2_extension (die, &ext_cu); |
8251 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
8252 | |
8253 | /* EXT_CU may not be the same as CU. | |
8254 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
8255 | return set_die_type (die, type, cu); |
8256 | } | |
9219021c | 8257 | |
e142c38c | 8258 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
8259 | |
8260 | /* Now build the name of the current namespace. */ | |
8261 | ||
0114d602 DJ |
8262 | previous_prefix = determine_prefix (die, cu); |
8263 | if (previous_prefix[0] != '\0') | |
8264 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 8265 | previous_prefix, name, 0, cu); |
0114d602 DJ |
8266 | |
8267 | /* Create the type. */ | |
8268 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
8269 | objfile); | |
8270 | TYPE_NAME (type) = (char *) name; | |
8271 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8272 | ||
60531b24 | 8273 | return set_die_type (die, type, cu); |
0114d602 DJ |
8274 | } |
8275 | ||
8276 | /* Read a C++ namespace. */ | |
8277 | ||
8278 | static void | |
8279 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
8280 | { | |
8281 | struct objfile *objfile = cu->objfile; | |
0114d602 | 8282 | int is_anonymous; |
9219021c | 8283 | |
5c4e30ca DC |
8284 | /* Add a symbol associated to this if we haven't seen the namespace |
8285 | before. Also, add a using directive if it's an anonymous | |
8286 | namespace. */ | |
9219021c | 8287 | |
f2f0e013 | 8288 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
8289 | { |
8290 | struct type *type; | |
8291 | ||
0114d602 | 8292 | type = read_type_die (die, cu); |
e7c27a73 | 8293 | new_symbol (die, type, cu); |
5c4e30ca | 8294 | |
e8e80198 | 8295 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 8296 | if (is_anonymous) |
0114d602 DJ |
8297 | { |
8298 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 8299 | |
c0cc3a76 | 8300 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 8301 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 8302 | } |
5c4e30ca | 8303 | } |
9219021c | 8304 | |
639d11d3 | 8305 | if (die->child != NULL) |
d9fa45fe | 8306 | { |
639d11d3 | 8307 | struct die_info *child_die = die->child; |
6e70227d | 8308 | |
d9fa45fe DC |
8309 | while (child_die && child_die->tag) |
8310 | { | |
e7c27a73 | 8311 | process_die (child_die, cu); |
d9fa45fe DC |
8312 | child_die = sibling_die (child_die); |
8313 | } | |
8314 | } | |
38d518c9 EZ |
8315 | } |
8316 | ||
f55ee35c JK |
8317 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
8318 | imported module. Still we need that type as local Fortran "use ... only" | |
8319 | declaration imports depend on the created type in determine_prefix. */ | |
8320 | ||
8321 | static struct type * | |
8322 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
8323 | { | |
8324 | struct objfile *objfile = cu->objfile; | |
8325 | char *module_name; | |
8326 | struct type *type; | |
8327 | ||
8328 | module_name = dwarf2_name (die, cu); | |
8329 | if (!module_name) | |
3e43a32a MS |
8330 | complaint (&symfile_complaints, |
8331 | _("DW_TAG_module has no name, offset 0x%x"), | |
f55ee35c JK |
8332 | die->offset); |
8333 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
8334 | ||
8335 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
8336 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8337 | ||
8338 | return set_die_type (die, type, cu); | |
8339 | } | |
8340 | ||
5d7cb8df JK |
8341 | /* Read a Fortran module. */ |
8342 | ||
8343 | static void | |
8344 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
8345 | { | |
8346 | struct die_info *child_die = die->child; | |
8347 | ||
5d7cb8df JK |
8348 | while (child_die && child_die->tag) |
8349 | { | |
8350 | process_die (child_die, cu); | |
8351 | child_die = sibling_die (child_die); | |
8352 | } | |
8353 | } | |
8354 | ||
38d518c9 EZ |
8355 | /* Return the name of the namespace represented by DIE. Set |
8356 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
8357 | namespace. */ | |
8358 | ||
8359 | static const char * | |
e142c38c | 8360 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
8361 | { |
8362 | struct die_info *current_die; | |
8363 | const char *name = NULL; | |
8364 | ||
8365 | /* Loop through the extensions until we find a name. */ | |
8366 | ||
8367 | for (current_die = die; | |
8368 | current_die != NULL; | |
f2f0e013 | 8369 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 8370 | { |
e142c38c | 8371 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
8372 | if (name != NULL) |
8373 | break; | |
8374 | } | |
8375 | ||
8376 | /* Is it an anonymous namespace? */ | |
8377 | ||
8378 | *is_anonymous = (name == NULL); | |
8379 | if (*is_anonymous) | |
2b1dbab0 | 8380 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
8381 | |
8382 | return name; | |
d9fa45fe DC |
8383 | } |
8384 | ||
c906108c SS |
8385 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
8386 | the user defined type vector. */ | |
8387 | ||
f792889a | 8388 | static struct type * |
e7c27a73 | 8389 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8390 | { |
5e2b427d | 8391 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 8392 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 8393 | struct type *type; |
8b2dbe47 KB |
8394 | struct attribute *attr_byte_size; |
8395 | struct attribute *attr_address_class; | |
8396 | int byte_size, addr_class; | |
7e314c57 JK |
8397 | struct type *target_type; |
8398 | ||
8399 | target_type = die_type (die, cu); | |
c906108c | 8400 | |
7e314c57 JK |
8401 | /* The die_type call above may have already set the type for this DIE. */ |
8402 | type = get_die_type (die, cu); | |
8403 | if (type) | |
8404 | return type; | |
8405 | ||
8406 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 8407 | |
e142c38c | 8408 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
8409 | if (attr_byte_size) |
8410 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 8411 | else |
8b2dbe47 KB |
8412 | byte_size = cu_header->addr_size; |
8413 | ||
e142c38c | 8414 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
8415 | if (attr_address_class) |
8416 | addr_class = DW_UNSND (attr_address_class); | |
8417 | else | |
8418 | addr_class = DW_ADDR_none; | |
8419 | ||
8420 | /* If the pointer size or address class is different than the | |
8421 | default, create a type variant marked as such and set the | |
8422 | length accordingly. */ | |
8423 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 8424 | { |
5e2b427d | 8425 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
8426 | { |
8427 | int type_flags; | |
8428 | ||
849957d9 | 8429 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 8430 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
8431 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
8432 | == 0); | |
8b2dbe47 KB |
8433 | type = make_type_with_address_space (type, type_flags); |
8434 | } | |
8435 | else if (TYPE_LENGTH (type) != byte_size) | |
8436 | { | |
3e43a32a MS |
8437 | complaint (&symfile_complaints, |
8438 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 8439 | } |
6e70227d | 8440 | else |
9a619af0 MS |
8441 | { |
8442 | /* Should we also complain about unhandled address classes? */ | |
8443 | } | |
c906108c | 8444 | } |
8b2dbe47 KB |
8445 | |
8446 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 8447 | return set_die_type (die, type, cu); |
c906108c SS |
8448 | } |
8449 | ||
8450 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
8451 | the user defined type vector. */ | |
8452 | ||
f792889a | 8453 | static struct type * |
e7c27a73 | 8454 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8455 | { |
8456 | struct type *type; | |
8457 | struct type *to_type; | |
8458 | struct type *domain; | |
8459 | ||
e7c27a73 DJ |
8460 | to_type = die_type (die, cu); |
8461 | domain = die_containing_type (die, cu); | |
0d5de010 | 8462 | |
7e314c57 JK |
8463 | /* The calls above may have already set the type for this DIE. */ |
8464 | type = get_die_type (die, cu); | |
8465 | if (type) | |
8466 | return type; | |
8467 | ||
0d5de010 DJ |
8468 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
8469 | type = lookup_methodptr_type (to_type); | |
8470 | else | |
8471 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 8472 | |
f792889a | 8473 | return set_die_type (die, type, cu); |
c906108c SS |
8474 | } |
8475 | ||
8476 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
8477 | the user defined type vector. */ | |
8478 | ||
f792889a | 8479 | static struct type * |
e7c27a73 | 8480 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8481 | { |
e7c27a73 | 8482 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 8483 | struct type *type, *target_type; |
c906108c SS |
8484 | struct attribute *attr; |
8485 | ||
7e314c57 JK |
8486 | target_type = die_type (die, cu); |
8487 | ||
8488 | /* The die_type call above may have already set the type for this DIE. */ | |
8489 | type = get_die_type (die, cu); | |
8490 | if (type) | |
8491 | return type; | |
8492 | ||
8493 | type = lookup_reference_type (target_type); | |
e142c38c | 8494 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8495 | if (attr) |
8496 | { | |
8497 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8498 | } | |
8499 | else | |
8500 | { | |
107d2387 | 8501 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 8502 | } |
f792889a | 8503 | return set_die_type (die, type, cu); |
c906108c SS |
8504 | } |
8505 | ||
f792889a | 8506 | static struct type * |
e7c27a73 | 8507 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8508 | { |
f792889a | 8509 | struct type *base_type, *cv_type; |
c906108c | 8510 | |
e7c27a73 | 8511 | base_type = die_type (die, cu); |
7e314c57 JK |
8512 | |
8513 | /* The die_type call above may have already set the type for this DIE. */ | |
8514 | cv_type = get_die_type (die, cu); | |
8515 | if (cv_type) | |
8516 | return cv_type; | |
8517 | ||
2f608a3a KW |
8518 | /* In case the const qualifier is applied to an array type, the element type |
8519 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
8520 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
8521 | { | |
8522 | struct type *el_type, *inner_array; | |
8523 | ||
8524 | base_type = copy_type (base_type); | |
8525 | inner_array = base_type; | |
8526 | ||
8527 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
8528 | { | |
8529 | TYPE_TARGET_TYPE (inner_array) = | |
8530 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
8531 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
8532 | } | |
8533 | ||
8534 | el_type = TYPE_TARGET_TYPE (inner_array); | |
8535 | TYPE_TARGET_TYPE (inner_array) = | |
8536 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
8537 | ||
8538 | return set_die_type (die, base_type, cu); | |
8539 | } | |
8540 | ||
f792889a DJ |
8541 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
8542 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8543 | } |
8544 | ||
f792889a | 8545 | static struct type * |
e7c27a73 | 8546 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8547 | { |
f792889a | 8548 | struct type *base_type, *cv_type; |
c906108c | 8549 | |
e7c27a73 | 8550 | base_type = die_type (die, cu); |
7e314c57 JK |
8551 | |
8552 | /* The die_type call above may have already set the type for this DIE. */ | |
8553 | cv_type = get_die_type (die, cu); | |
8554 | if (cv_type) | |
8555 | return cv_type; | |
8556 | ||
f792889a DJ |
8557 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
8558 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8559 | } |
8560 | ||
8561 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
8562 | the user defined type vector. It isn't really a user defined type, | |
8563 | but it behaves like one, with other DIE's using an AT_user_def_type | |
8564 | attribute to reference it. */ | |
8565 | ||
f792889a | 8566 | static struct type * |
e7c27a73 | 8567 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8568 | { |
e7c27a73 | 8569 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 8570 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8571 | struct type *type, *range_type, *index_type, *char_type; |
8572 | struct attribute *attr; | |
8573 | unsigned int length; | |
8574 | ||
e142c38c | 8575 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
8576 | if (attr) |
8577 | { | |
8578 | length = DW_UNSND (attr); | |
8579 | } | |
8580 | else | |
8581 | { | |
0963b4bd | 8582 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 8583 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
8584 | if (attr) |
8585 | { | |
8586 | length = DW_UNSND (attr); | |
8587 | } | |
8588 | else | |
8589 | { | |
8590 | length = 1; | |
8591 | } | |
c906108c | 8592 | } |
6ccb9162 | 8593 | |
46bf5051 | 8594 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8595 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
8596 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
8597 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 8598 | |
f792889a | 8599 | return set_die_type (die, type, cu); |
c906108c SS |
8600 | } |
8601 | ||
8602 | /* Handle DIES due to C code like: | |
8603 | ||
8604 | struct foo | |
c5aa993b JM |
8605 | { |
8606 | int (*funcp)(int a, long l); | |
8607 | int b; | |
8608 | }; | |
c906108c | 8609 | |
0963b4bd | 8610 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 8611 | |
f792889a | 8612 | static struct type * |
e7c27a73 | 8613 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8614 | { |
0963b4bd MS |
8615 | struct type *type; /* Type that this function returns. */ |
8616 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
8617 | struct attribute *attr; |
8618 | ||
e7c27a73 | 8619 | type = die_type (die, cu); |
7e314c57 JK |
8620 | |
8621 | /* The die_type call above may have already set the type for this DIE. */ | |
8622 | ftype = get_die_type (die, cu); | |
8623 | if (ftype) | |
8624 | return ftype; | |
8625 | ||
0c8b41f1 | 8626 | ftype = lookup_function_type (type); |
c906108c | 8627 | |
5b8101ae | 8628 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 8629 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 8630 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 8631 | || cu->language == language_cplus |
5b8101ae PM |
8632 | || cu->language == language_java |
8633 | || cu->language == language_pascal) | |
876cecd0 | 8634 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
8635 | else if (producer_is_realview (cu->producer)) |
8636 | /* RealView does not emit DW_AT_prototyped. We can not | |
8637 | distinguish prototyped and unprototyped functions; default to | |
8638 | prototyped, since that is more common in modern code (and | |
8639 | RealView warns about unprototyped functions). */ | |
8640 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 8641 | |
c055b101 CV |
8642 | /* Store the calling convention in the type if it's available in |
8643 | the subroutine die. Otherwise set the calling convention to | |
8644 | the default value DW_CC_normal. */ | |
8645 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
8646 | if (attr) |
8647 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
8648 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
8649 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
8650 | else | |
8651 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
8652 | |
8653 | /* We need to add the subroutine type to the die immediately so | |
8654 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 8655 | declared as the same subroutine type. */ |
76c10ea2 | 8656 | set_die_type (die, ftype, cu); |
6e70227d | 8657 | |
639d11d3 | 8658 | if (die->child != NULL) |
c906108c | 8659 | { |
8072405b | 8660 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 8661 | struct die_info *child_die; |
8072405b | 8662 | int nparams, iparams; |
c906108c SS |
8663 | |
8664 | /* Count the number of parameters. | |
8665 | FIXME: GDB currently ignores vararg functions, but knows about | |
8666 | vararg member functions. */ | |
8072405b | 8667 | nparams = 0; |
639d11d3 | 8668 | child_die = die->child; |
c906108c SS |
8669 | while (child_die && child_die->tag) |
8670 | { | |
8671 | if (child_die->tag == DW_TAG_formal_parameter) | |
8672 | nparams++; | |
8673 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 8674 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
8675 | child_die = sibling_die (child_die); |
8676 | } | |
8677 | ||
8678 | /* Allocate storage for parameters and fill them in. */ | |
8679 | TYPE_NFIELDS (ftype) = nparams; | |
8680 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 8681 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 8682 | |
8072405b JK |
8683 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
8684 | even if we error out during the parameters reading below. */ | |
8685 | for (iparams = 0; iparams < nparams; iparams++) | |
8686 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
8687 | ||
8688 | iparams = 0; | |
639d11d3 | 8689 | child_die = die->child; |
c906108c SS |
8690 | while (child_die && child_die->tag) |
8691 | { | |
8692 | if (child_die->tag == DW_TAG_formal_parameter) | |
8693 | { | |
3ce3b1ba PA |
8694 | struct type *arg_type; |
8695 | ||
8696 | /* DWARF version 2 has no clean way to discern C++ | |
8697 | static and non-static member functions. G++ helps | |
8698 | GDB by marking the first parameter for non-static | |
8699 | member functions (which is the this pointer) as | |
8700 | artificial. We pass this information to | |
8701 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
8702 | ||
8703 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
8704 | 4.5 does not yet generate. */ | |
e142c38c | 8705 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
8706 | if (attr) |
8707 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
8708 | else | |
418835cc KS |
8709 | { |
8710 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
8711 | ||
8712 | /* GCC/43521: In java, the formal parameter | |
8713 | "this" is sometimes not marked with DW_AT_artificial. */ | |
8714 | if (cu->language == language_java) | |
8715 | { | |
8716 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 8717 | |
418835cc KS |
8718 | if (name && !strcmp (name, "this")) |
8719 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
8720 | } | |
8721 | } | |
3ce3b1ba PA |
8722 | arg_type = die_type (child_die, cu); |
8723 | ||
8724 | /* RealView does not mark THIS as const, which the testsuite | |
8725 | expects. GCC marks THIS as const in method definitions, | |
8726 | but not in the class specifications (GCC PR 43053). */ | |
8727 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
8728 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
8729 | { | |
8730 | int is_this = 0; | |
8731 | struct dwarf2_cu *arg_cu = cu; | |
8732 | const char *name = dwarf2_name (child_die, cu); | |
8733 | ||
8734 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
8735 | if (attr) | |
8736 | { | |
8737 | /* If the compiler emits this, use it. */ | |
8738 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
8739 | is_this = 1; | |
8740 | } | |
8741 | else if (name && strcmp (name, "this") == 0) | |
8742 | /* Function definitions will have the argument names. */ | |
8743 | is_this = 1; | |
8744 | else if (name == NULL && iparams == 0) | |
8745 | /* Declarations may not have the names, so like | |
8746 | elsewhere in GDB, assume an artificial first | |
8747 | argument is "this". */ | |
8748 | is_this = 1; | |
8749 | ||
8750 | if (is_this) | |
8751 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
8752 | arg_type, 0); | |
8753 | } | |
8754 | ||
8755 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
8756 | iparams++; |
8757 | } | |
8758 | child_die = sibling_die (child_die); | |
8759 | } | |
8760 | } | |
8761 | ||
76c10ea2 | 8762 | return ftype; |
c906108c SS |
8763 | } |
8764 | ||
f792889a | 8765 | static struct type * |
e7c27a73 | 8766 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8767 | { |
e7c27a73 | 8768 | struct objfile *objfile = cu->objfile; |
0114d602 | 8769 | const char *name = NULL; |
f792889a | 8770 | struct type *this_type; |
c906108c | 8771 | |
94af9270 | 8772 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 8773 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
8774 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
8775 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
8776 | set_die_type (die, this_type, cu); |
8777 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
8778 | return this_type; | |
c906108c SS |
8779 | } |
8780 | ||
8781 | /* Find a representation of a given base type and install | |
8782 | it in the TYPE field of the die. */ | |
8783 | ||
f792889a | 8784 | static struct type * |
e7c27a73 | 8785 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8786 | { |
e7c27a73 | 8787 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8788 | struct type *type; |
8789 | struct attribute *attr; | |
8790 | int encoding = 0, size = 0; | |
39cbfefa | 8791 | char *name; |
6ccb9162 UW |
8792 | enum type_code code = TYPE_CODE_INT; |
8793 | int type_flags = 0; | |
8794 | struct type *target_type = NULL; | |
c906108c | 8795 | |
e142c38c | 8796 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
8797 | if (attr) |
8798 | { | |
8799 | encoding = DW_UNSND (attr); | |
8800 | } | |
e142c38c | 8801 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8802 | if (attr) |
8803 | { | |
8804 | size = DW_UNSND (attr); | |
8805 | } | |
39cbfefa | 8806 | name = dwarf2_name (die, cu); |
6ccb9162 | 8807 | if (!name) |
c906108c | 8808 | { |
6ccb9162 UW |
8809 | complaint (&symfile_complaints, |
8810 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 8811 | } |
6ccb9162 UW |
8812 | |
8813 | switch (encoding) | |
c906108c | 8814 | { |
6ccb9162 UW |
8815 | case DW_ATE_address: |
8816 | /* Turn DW_ATE_address into a void * pointer. */ | |
8817 | code = TYPE_CODE_PTR; | |
8818 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8819 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
8820 | break; | |
8821 | case DW_ATE_boolean: | |
8822 | code = TYPE_CODE_BOOL; | |
8823 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8824 | break; | |
8825 | case DW_ATE_complex_float: | |
8826 | code = TYPE_CODE_COMPLEX; | |
8827 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
8828 | break; | |
8829 | case DW_ATE_decimal_float: | |
8830 | code = TYPE_CODE_DECFLOAT; | |
8831 | break; | |
8832 | case DW_ATE_float: | |
8833 | code = TYPE_CODE_FLT; | |
8834 | break; | |
8835 | case DW_ATE_signed: | |
8836 | break; | |
8837 | case DW_ATE_unsigned: | |
8838 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
8839 | if (cu->language == language_fortran |
8840 | && name | |
8841 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
8842 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
8843 | break; |
8844 | case DW_ATE_signed_char: | |
6e70227d | 8845 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8846 | || cu->language == language_pascal |
8847 | || cu->language == language_fortran) | |
6ccb9162 UW |
8848 | code = TYPE_CODE_CHAR; |
8849 | break; | |
8850 | case DW_ATE_unsigned_char: | |
868a0084 | 8851 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8852 | || cu->language == language_pascal |
8853 | || cu->language == language_fortran) | |
6ccb9162 UW |
8854 | code = TYPE_CODE_CHAR; |
8855 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8856 | break; | |
75079b2b TT |
8857 | case DW_ATE_UTF: |
8858 | /* We just treat this as an integer and then recognize the | |
8859 | type by name elsewhere. */ | |
8860 | break; | |
8861 | ||
6ccb9162 UW |
8862 | default: |
8863 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
8864 | dwarf_type_encoding_name (encoding)); | |
8865 | break; | |
c906108c | 8866 | } |
6ccb9162 | 8867 | |
0114d602 DJ |
8868 | type = init_type (code, size, type_flags, NULL, objfile); |
8869 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
8870 | TYPE_TARGET_TYPE (type) = target_type; |
8871 | ||
0114d602 | 8872 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 8873 | TYPE_NOSIGN (type) = 1; |
0114d602 | 8874 | |
f792889a | 8875 | return set_die_type (die, type, cu); |
c906108c SS |
8876 | } |
8877 | ||
a02abb62 JB |
8878 | /* Read the given DW_AT_subrange DIE. */ |
8879 | ||
f792889a | 8880 | static struct type * |
a02abb62 JB |
8881 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
8882 | { | |
8883 | struct type *base_type; | |
8884 | struct type *range_type; | |
8885 | struct attribute *attr; | |
43bbcdc2 PH |
8886 | LONGEST low = 0; |
8887 | LONGEST high = -1; | |
39cbfefa | 8888 | char *name; |
43bbcdc2 | 8889 | LONGEST negative_mask; |
e77813c8 | 8890 | |
a02abb62 | 8891 | base_type = die_type (die, cu); |
953ac07e JK |
8892 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
8893 | check_typedef (base_type); | |
a02abb62 | 8894 | |
7e314c57 JK |
8895 | /* The die_type call above may have already set the type for this DIE. */ |
8896 | range_type = get_die_type (die, cu); | |
8897 | if (range_type) | |
8898 | return range_type; | |
8899 | ||
e142c38c | 8900 | if (cu->language == language_fortran) |
6e70227d | 8901 | { |
a02abb62 JB |
8902 | /* FORTRAN implies a lower bound of 1, if not given. */ |
8903 | low = 1; | |
8904 | } | |
8905 | ||
dd5e6932 DJ |
8906 | /* FIXME: For variable sized arrays either of these could be |
8907 | a variable rather than a constant value. We'll allow it, | |
8908 | but we don't know how to handle it. */ | |
e142c38c | 8909 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
8910 | if (attr) |
8911 | low = dwarf2_get_attr_constant_value (attr, 0); | |
8912 | ||
e142c38c | 8913 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 8914 | if (attr) |
6e70227d | 8915 | { |
d48323d8 | 8916 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
8917 | { |
8918 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 8919 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
8920 | FIXME: GDB does not yet know how to handle dynamic |
8921 | arrays properly, treat them as arrays with unspecified | |
8922 | length for now. | |
8923 | ||
8924 | FIXME: jimb/2003-09-22: GDB does not really know | |
8925 | how to handle arrays of unspecified length | |
8926 | either; we just represent them as zero-length | |
8927 | arrays. Choose an appropriate upper bound given | |
8928 | the lower bound we've computed above. */ | |
8929 | high = low - 1; | |
8930 | } | |
8931 | else | |
8932 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8933 | } | |
e77813c8 PM |
8934 | else |
8935 | { | |
8936 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8937 | if (attr) | |
8938 | { | |
8939 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8940 | high = low + count - 1; | |
8941 | } | |
c2ff108b JK |
8942 | else |
8943 | { | |
8944 | /* Unspecified array length. */ | |
8945 | high = low - 1; | |
8946 | } | |
e77813c8 PM |
8947 | } |
8948 | ||
8949 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8950 | without specifying a base type. | |
8951 | In that case, the base type must be set to the type of | |
8952 | the lower bound, upper bound or count, in that order, if any of these | |
8953 | three attributes references an object that has a type. | |
8954 | If no base type is found, the Dwarf-2 specifications say that | |
8955 | a signed integer type of size equal to the size of an address should | |
8956 | be used. | |
8957 | For the following C code: `extern char gdb_int [];' | |
8958 | GCC produces an empty range DIE. | |
8959 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 8960 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
8961 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
8962 | { | |
8963 | struct objfile *objfile = cu->objfile; | |
8964 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8965 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8966 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8967 | ||
8968 | /* Test "int", "long int", and "long long int" objfile types, | |
8969 | and select the first one having a size above or equal to the | |
8970 | architecture address size. */ | |
8971 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8972 | base_type = int_type; | |
8973 | else | |
8974 | { | |
8975 | int_type = objfile_type (objfile)->builtin_long; | |
8976 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8977 | base_type = int_type; | |
8978 | else | |
8979 | { | |
8980 | int_type = objfile_type (objfile)->builtin_long_long; | |
8981 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8982 | base_type = int_type; | |
8983 | } | |
8984 | } | |
8985 | } | |
a02abb62 | 8986 | |
6e70227d | 8987 | negative_mask = |
43bbcdc2 PH |
8988 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8989 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8990 | low |= negative_mask; | |
8991 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8992 | high |= negative_mask; | |
8993 | ||
a02abb62 JB |
8994 | range_type = create_range_type (NULL, base_type, low, high); |
8995 | ||
bbb0eef6 JK |
8996 | /* Mark arrays with dynamic length at least as an array of unspecified |
8997 | length. GDB could check the boundary but before it gets implemented at | |
8998 | least allow accessing the array elements. */ | |
d48323d8 | 8999 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
9000 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
9001 | ||
c2ff108b JK |
9002 | /* Ada expects an empty array on no boundary attributes. */ |
9003 | if (attr == NULL && cu->language != language_ada) | |
9004 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
9005 | ||
39cbfefa DJ |
9006 | name = dwarf2_name (die, cu); |
9007 | if (name) | |
9008 | TYPE_NAME (range_type) = name; | |
6e70227d | 9009 | |
e142c38c | 9010 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
9011 | if (attr) |
9012 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
9013 | ||
7e314c57 JK |
9014 | set_die_type (die, range_type, cu); |
9015 | ||
9016 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
9017 | set_descriptive_type (range_type, die, cu); |
9018 | ||
7e314c57 | 9019 | return range_type; |
a02abb62 | 9020 | } |
6e70227d | 9021 | |
f792889a | 9022 | static struct type * |
81a17f79 JB |
9023 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
9024 | { | |
9025 | struct type *type; | |
81a17f79 | 9026 | |
81a17f79 JB |
9027 | /* For now, we only support the C meaning of an unspecified type: void. */ |
9028 | ||
0114d602 DJ |
9029 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
9030 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 9031 | |
f792889a | 9032 | return set_die_type (die, type, cu); |
81a17f79 | 9033 | } |
a02abb62 | 9034 | |
51545339 DJ |
9035 | /* Trivial hash function for die_info: the hash value of a DIE |
9036 | is its offset in .debug_info for this objfile. */ | |
9037 | ||
9038 | static hashval_t | |
9039 | die_hash (const void *item) | |
9040 | { | |
9041 | const struct die_info *die = item; | |
9a619af0 | 9042 | |
51545339 DJ |
9043 | return die->offset; |
9044 | } | |
9045 | ||
9046 | /* Trivial comparison function for die_info structures: two DIEs | |
9047 | are equal if they have the same offset. */ | |
9048 | ||
9049 | static int | |
9050 | die_eq (const void *item_lhs, const void *item_rhs) | |
9051 | { | |
9052 | const struct die_info *die_lhs = item_lhs; | |
9053 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 9054 | |
51545339 DJ |
9055 | return die_lhs->offset == die_rhs->offset; |
9056 | } | |
9057 | ||
c906108c SS |
9058 | /* Read a whole compilation unit into a linked list of dies. */ |
9059 | ||
f9aca02d | 9060 | static struct die_info * |
93311388 | 9061 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 9062 | { |
93311388 | 9063 | struct die_reader_specs reader_specs; |
98bfdba5 | 9064 | int read_abbrevs = 0; |
1d9ec526 | 9065 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
9066 | struct die_info *die; |
9067 | ||
9068 | if (cu->dwarf2_abbrevs == NULL) | |
9069 | { | |
9070 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
9071 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
9072 | read_abbrevs = 1; | |
9073 | } | |
93311388 | 9074 | |
348e048f | 9075 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
9076 | cu->die_hash |
9077 | = htab_create_alloc_ex (cu->header.length / 12, | |
9078 | die_hash, | |
9079 | die_eq, | |
9080 | NULL, | |
9081 | &cu->comp_unit_obstack, | |
9082 | hashtab_obstack_allocate, | |
9083 | dummy_obstack_deallocate); | |
9084 | ||
93311388 DE |
9085 | init_cu_die_reader (&reader_specs, cu); |
9086 | ||
98bfdba5 PA |
9087 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
9088 | ||
9089 | if (read_abbrevs) | |
9090 | do_cleanups (back_to); | |
9091 | ||
9092 | return die; | |
639d11d3 DC |
9093 | } |
9094 | ||
d97bc12b DE |
9095 | /* Main entry point for reading a DIE and all children. |
9096 | Read the DIE and dump it if requested. */ | |
9097 | ||
9098 | static struct die_info * | |
93311388 DE |
9099 | read_die_and_children (const struct die_reader_specs *reader, |
9100 | gdb_byte *info_ptr, | |
d97bc12b DE |
9101 | gdb_byte **new_info_ptr, |
9102 | struct die_info *parent) | |
9103 | { | |
93311388 | 9104 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
9105 | new_info_ptr, parent); |
9106 | ||
9107 | if (dwarf2_die_debug) | |
9108 | { | |
348e048f DE |
9109 | fprintf_unfiltered (gdb_stdlog, |
9110 | "\nRead die from %s of %s:\n", | |
8b70b953 TT |
9111 | (reader->cu->per_cu->debug_type_section |
9112 | ? ".debug_types" | |
9113 | : ".debug_info"), | |
348e048f | 9114 | reader->abfd->filename); |
d97bc12b DE |
9115 | dump_die (result, dwarf2_die_debug); |
9116 | } | |
9117 | ||
9118 | return result; | |
9119 | } | |
9120 | ||
639d11d3 DC |
9121 | /* Read a single die and all its descendents. Set the die's sibling |
9122 | field to NULL; set other fields in the die correctly, and set all | |
9123 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
9124 | location of the info_ptr after reading all of those dies. PARENT | |
9125 | is the parent of the die in question. */ | |
9126 | ||
9127 | static struct die_info * | |
93311388 DE |
9128 | read_die_and_children_1 (const struct die_reader_specs *reader, |
9129 | gdb_byte *info_ptr, | |
d97bc12b DE |
9130 | gdb_byte **new_info_ptr, |
9131 | struct die_info *parent) | |
639d11d3 DC |
9132 | { |
9133 | struct die_info *die; | |
fe1b8b76 | 9134 | gdb_byte *cur_ptr; |
639d11d3 DC |
9135 | int has_children; |
9136 | ||
93311388 | 9137 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
9138 | if (die == NULL) |
9139 | { | |
9140 | *new_info_ptr = cur_ptr; | |
9141 | return NULL; | |
9142 | } | |
93311388 | 9143 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
9144 | |
9145 | if (has_children) | |
348e048f | 9146 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
9147 | else |
9148 | { | |
9149 | die->child = NULL; | |
9150 | *new_info_ptr = cur_ptr; | |
9151 | } | |
9152 | ||
9153 | die->sibling = NULL; | |
9154 | die->parent = parent; | |
9155 | return die; | |
9156 | } | |
9157 | ||
9158 | /* Read a die, all of its descendents, and all of its siblings; set | |
9159 | all of the fields of all of the dies correctly. Arguments are as | |
9160 | in read_die_and_children. */ | |
9161 | ||
9162 | static struct die_info * | |
93311388 DE |
9163 | read_die_and_siblings (const struct die_reader_specs *reader, |
9164 | gdb_byte *info_ptr, | |
fe1b8b76 | 9165 | gdb_byte **new_info_ptr, |
639d11d3 DC |
9166 | struct die_info *parent) |
9167 | { | |
9168 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 9169 | gdb_byte *cur_ptr; |
639d11d3 | 9170 | |
c906108c | 9171 | cur_ptr = info_ptr; |
639d11d3 DC |
9172 | first_die = last_sibling = NULL; |
9173 | ||
9174 | while (1) | |
c906108c | 9175 | { |
639d11d3 | 9176 | struct die_info *die |
93311388 | 9177 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 9178 | |
1d325ec1 | 9179 | if (die == NULL) |
c906108c | 9180 | { |
639d11d3 DC |
9181 | *new_info_ptr = cur_ptr; |
9182 | return first_die; | |
c906108c | 9183 | } |
1d325ec1 DJ |
9184 | |
9185 | if (!first_die) | |
9186 | first_die = die; | |
c906108c | 9187 | else |
1d325ec1 DJ |
9188 | last_sibling->sibling = die; |
9189 | ||
9190 | last_sibling = die; | |
c906108c | 9191 | } |
c906108c SS |
9192 | } |
9193 | ||
93311388 DE |
9194 | /* Read the die from the .debug_info section buffer. Set DIEP to |
9195 | point to a newly allocated die with its information, except for its | |
9196 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
9197 | whether the die has children or not. */ | |
9198 | ||
9199 | static gdb_byte * | |
9200 | read_full_die (const struct die_reader_specs *reader, | |
9201 | struct die_info **diep, gdb_byte *info_ptr, | |
9202 | int *has_children) | |
9203 | { | |
9204 | unsigned int abbrev_number, bytes_read, i, offset; | |
9205 | struct abbrev_info *abbrev; | |
9206 | struct die_info *die; | |
9207 | struct dwarf2_cu *cu = reader->cu; | |
9208 | bfd *abfd = reader->abfd; | |
9209 | ||
9210 | offset = info_ptr - reader->buffer; | |
9211 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9212 | info_ptr += bytes_read; | |
9213 | if (!abbrev_number) | |
9214 | { | |
9215 | *diep = NULL; | |
9216 | *has_children = 0; | |
9217 | return info_ptr; | |
9218 | } | |
9219 | ||
9220 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
9221 | if (!abbrev) | |
348e048f DE |
9222 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
9223 | abbrev_number, | |
9224 | bfd_get_filename (abfd)); | |
9225 | ||
93311388 DE |
9226 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
9227 | die->offset = offset; | |
9228 | die->tag = abbrev->tag; | |
9229 | die->abbrev = abbrev_number; | |
9230 | ||
9231 | die->num_attrs = abbrev->num_attrs; | |
9232 | ||
9233 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9234 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
9235 | abfd, info_ptr, cu); | |
9236 | ||
9237 | *diep = die; | |
9238 | *has_children = abbrev->has_children; | |
9239 | return info_ptr; | |
9240 | } | |
9241 | ||
c906108c SS |
9242 | /* In DWARF version 2, the description of the debugging information is |
9243 | stored in a separate .debug_abbrev section. Before we read any | |
9244 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
9245 | in a hash table. This function also sets flags in CU describing |
9246 | the data found in the abbrev table. */ | |
c906108c SS |
9247 | |
9248 | static void | |
e7c27a73 | 9249 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 9250 | { |
e7c27a73 | 9251 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 9252 | gdb_byte *abbrev_ptr; |
c906108c SS |
9253 | struct abbrev_info *cur_abbrev; |
9254 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
9255 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
9256 | struct attr_abbrev *cur_attrs; |
9257 | unsigned int allocated_attrs; | |
c906108c | 9258 | |
0963b4bd | 9259 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
9260 | obstack_init (&cu->abbrev_obstack); |
9261 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
9262 | (ABBREV_HASH_SIZE | |
9263 | * sizeof (struct abbrev_info *))); | |
9264 | memset (cu->dwarf2_abbrevs, 0, | |
9265 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 9266 | |
be391dca TT |
9267 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
9268 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 9269 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
9270 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9271 | abbrev_ptr += bytes_read; | |
9272 | ||
f3dd6933 DJ |
9273 | allocated_attrs = ATTR_ALLOC_CHUNK; |
9274 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 9275 | |
0963b4bd | 9276 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
9277 | while (abbrev_number) |
9278 | { | |
f3dd6933 | 9279 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
9280 | |
9281 | /* read in abbrev header */ | |
9282 | cur_abbrev->number = abbrev_number; | |
9283 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9284 | abbrev_ptr += bytes_read; | |
9285 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
9286 | abbrev_ptr += 1; | |
9287 | ||
72bf9492 DJ |
9288 | if (cur_abbrev->tag == DW_TAG_namespace) |
9289 | cu->has_namespace_info = 1; | |
9290 | ||
c906108c SS |
9291 | /* now read in declarations */ |
9292 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9293 | abbrev_ptr += bytes_read; | |
9294 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9295 | abbrev_ptr += bytes_read; | |
9296 | while (abbrev_name) | |
9297 | { | |
f3dd6933 | 9298 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 9299 | { |
f3dd6933 DJ |
9300 | allocated_attrs += ATTR_ALLOC_CHUNK; |
9301 | cur_attrs | |
9302 | = xrealloc (cur_attrs, (allocated_attrs | |
9303 | * sizeof (struct attr_abbrev))); | |
c906108c | 9304 | } |
ae038cb0 DJ |
9305 | |
9306 | /* Record whether this compilation unit might have | |
9307 | inter-compilation-unit references. If we don't know what form | |
9308 | this attribute will have, then it might potentially be a | |
9309 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
9310 | references. */ | |
9311 | ||
9312 | if (abbrev_form == DW_FORM_ref_addr | |
9313 | || abbrev_form == DW_FORM_indirect) | |
9314 | cu->has_form_ref_addr = 1; | |
9315 | ||
f3dd6933 DJ |
9316 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
9317 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
9318 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9319 | abbrev_ptr += bytes_read; | |
9320 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9321 | abbrev_ptr += bytes_read; | |
9322 | } | |
9323 | ||
f3dd6933 DJ |
9324 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
9325 | (cur_abbrev->num_attrs | |
9326 | * sizeof (struct attr_abbrev))); | |
9327 | memcpy (cur_abbrev->attrs, cur_attrs, | |
9328 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
9329 | ||
c906108c | 9330 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
9331 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
9332 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
9333 | |
9334 | /* Get next abbreviation. | |
9335 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
9336 | always properly terminated with an abbrev number of 0. |
9337 | Exit loop if we encounter an abbreviation which we have | |
9338 | already read (which means we are about to read the abbreviations | |
9339 | for the next compile unit) or if the end of the abbreviation | |
9340 | table is reached. */ | |
dce234bc PP |
9341 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
9342 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
9343 | break; |
9344 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9345 | abbrev_ptr += bytes_read; | |
e7c27a73 | 9346 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
9347 | break; |
9348 | } | |
f3dd6933 DJ |
9349 | |
9350 | xfree (cur_attrs); | |
c906108c SS |
9351 | } |
9352 | ||
f3dd6933 | 9353 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 9354 | |
c906108c | 9355 | static void |
f3dd6933 | 9356 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 9357 | { |
f3dd6933 | 9358 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 9359 | |
f3dd6933 DJ |
9360 | obstack_free (&cu->abbrev_obstack, NULL); |
9361 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
9362 | } |
9363 | ||
9364 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
9365 | ||
9366 | static struct abbrev_info * | |
e7c27a73 | 9367 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
9368 | { |
9369 | unsigned int hash_number; | |
9370 | struct abbrev_info *abbrev; | |
9371 | ||
9372 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 9373 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
9374 | |
9375 | while (abbrev) | |
9376 | { | |
9377 | if (abbrev->number == number) | |
9378 | return abbrev; | |
9379 | else | |
9380 | abbrev = abbrev->next; | |
9381 | } | |
9382 | return NULL; | |
9383 | } | |
9384 | ||
72bf9492 DJ |
9385 | /* Returns nonzero if TAG represents a type that we might generate a partial |
9386 | symbol for. */ | |
9387 | ||
9388 | static int | |
9389 | is_type_tag_for_partial (int tag) | |
9390 | { | |
9391 | switch (tag) | |
9392 | { | |
9393 | #if 0 | |
9394 | /* Some types that would be reasonable to generate partial symbols for, | |
9395 | that we don't at present. */ | |
9396 | case DW_TAG_array_type: | |
9397 | case DW_TAG_file_type: | |
9398 | case DW_TAG_ptr_to_member_type: | |
9399 | case DW_TAG_set_type: | |
9400 | case DW_TAG_string_type: | |
9401 | case DW_TAG_subroutine_type: | |
9402 | #endif | |
9403 | case DW_TAG_base_type: | |
9404 | case DW_TAG_class_type: | |
680b30c7 | 9405 | case DW_TAG_interface_type: |
72bf9492 DJ |
9406 | case DW_TAG_enumeration_type: |
9407 | case DW_TAG_structure_type: | |
9408 | case DW_TAG_subrange_type: | |
9409 | case DW_TAG_typedef: | |
9410 | case DW_TAG_union_type: | |
9411 | return 1; | |
9412 | default: | |
9413 | return 0; | |
9414 | } | |
9415 | } | |
9416 | ||
9417 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
9418 | ||
9419 | static struct partial_die_info * | |
93311388 DE |
9420 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
9421 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
9422 | { |
9423 | struct partial_die_info *part_die; | |
9424 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
9425 | struct abbrev_info *abbrev; | |
9426 | unsigned int bytes_read; | |
5afb4e99 | 9427 | unsigned int load_all = 0; |
72bf9492 DJ |
9428 | |
9429 | int nesting_level = 1; | |
9430 | ||
9431 | parent_die = NULL; | |
9432 | last_die = NULL; | |
9433 | ||
5afb4e99 DJ |
9434 | if (cu->per_cu && cu->per_cu->load_all_dies) |
9435 | load_all = 1; | |
9436 | ||
72bf9492 DJ |
9437 | cu->partial_dies |
9438 | = htab_create_alloc_ex (cu->header.length / 12, | |
9439 | partial_die_hash, | |
9440 | partial_die_eq, | |
9441 | NULL, | |
9442 | &cu->comp_unit_obstack, | |
9443 | hashtab_obstack_allocate, | |
9444 | dummy_obstack_deallocate); | |
9445 | ||
9446 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9447 | sizeof (struct partial_die_info)); | |
9448 | ||
9449 | while (1) | |
9450 | { | |
9451 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
9452 | ||
9453 | /* A NULL abbrev means the end of a series of children. */ | |
9454 | if (abbrev == NULL) | |
9455 | { | |
9456 | if (--nesting_level == 0) | |
9457 | { | |
9458 | /* PART_DIE was probably the last thing allocated on the | |
9459 | comp_unit_obstack, so we could call obstack_free | |
9460 | here. We don't do that because the waste is small, | |
9461 | and will be cleaned up when we're done with this | |
9462 | compilation unit. This way, we're also more robust | |
9463 | against other users of the comp_unit_obstack. */ | |
9464 | return first_die; | |
9465 | } | |
9466 | info_ptr += bytes_read; | |
9467 | last_die = parent_die; | |
9468 | parent_die = parent_die->die_parent; | |
9469 | continue; | |
9470 | } | |
9471 | ||
98bfdba5 PA |
9472 | /* Check for template arguments. We never save these; if |
9473 | they're seen, we just mark the parent, and go on our way. */ | |
9474 | if (parent_die != NULL | |
9475 | && cu->language == language_cplus | |
9476 | && (abbrev->tag == DW_TAG_template_type_param | |
9477 | || abbrev->tag == DW_TAG_template_value_param)) | |
9478 | { | |
9479 | parent_die->has_template_arguments = 1; | |
9480 | ||
9481 | if (!load_all) | |
9482 | { | |
9483 | /* We don't need a partial DIE for the template argument. */ | |
9484 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
9485 | cu); | |
9486 | continue; | |
9487 | } | |
9488 | } | |
9489 | ||
9490 | /* We only recurse into subprograms looking for template arguments. | |
9491 | Skip their other children. */ | |
9492 | if (!load_all | |
9493 | && cu->language == language_cplus | |
9494 | && parent_die != NULL | |
9495 | && parent_die->tag == DW_TAG_subprogram) | |
9496 | { | |
9497 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
9498 | continue; | |
9499 | } | |
9500 | ||
5afb4e99 DJ |
9501 | /* Check whether this DIE is interesting enough to save. Normally |
9502 | we would not be interested in members here, but there may be | |
9503 | later variables referencing them via DW_AT_specification (for | |
9504 | static members). */ | |
9505 | if (!load_all | |
9506 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 9507 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
9508 | && abbrev->tag != DW_TAG_enumerator |
9509 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 9510 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 9511 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 9512 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 9513 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 9514 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
9515 | { |
9516 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9517 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
9518 | continue; |
9519 | } | |
9520 | ||
93311388 DE |
9521 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
9522 | buffer, info_ptr, cu); | |
72bf9492 DJ |
9523 | |
9524 | /* This two-pass algorithm for processing partial symbols has a | |
9525 | high cost in cache pressure. Thus, handle some simple cases | |
9526 | here which cover the majority of C partial symbols. DIEs | |
9527 | which neither have specification tags in them, nor could have | |
9528 | specification tags elsewhere pointing at them, can simply be | |
9529 | processed and discarded. | |
9530 | ||
9531 | This segment is also optional; scan_partial_symbols and | |
9532 | add_partial_symbol will handle these DIEs if we chain | |
9533 | them in normally. When compilers which do not emit large | |
9534 | quantities of duplicate debug information are more common, | |
9535 | this code can probably be removed. */ | |
9536 | ||
9537 | /* Any complete simple types at the top level (pretty much all | |
9538 | of them, for a language without namespaces), can be processed | |
9539 | directly. */ | |
9540 | if (parent_die == NULL | |
9541 | && part_die->has_specification == 0 | |
9542 | && part_die->is_declaration == 0 | |
d8228535 | 9543 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
9544 | || part_die->tag == DW_TAG_base_type |
9545 | || part_die->tag == DW_TAG_subrange_type)) | |
9546 | { | |
9547 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 9548 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
9549 | VAR_DOMAIN, LOC_TYPEDEF, |
9550 | &cu->objfile->static_psymbols, | |
9551 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 9552 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9553 | continue; |
9554 | } | |
9555 | ||
d8228535 JK |
9556 | /* The exception for DW_TAG_typedef with has_children above is |
9557 | a workaround of GCC PR debug/47510. In the case of this complaint | |
9558 | type_name_no_tag_or_error will error on such types later. | |
9559 | ||
9560 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
9561 | it could not find the child DIEs referenced later, this is checked | |
9562 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
9563 | ||
9564 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
9565 | complaint (&symfile_complaints, | |
9566 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
9567 | "- DIE at 0x%x [in module %s]"), | |
9568 | part_die->offset, cu->objfile->name); | |
9569 | ||
72bf9492 DJ |
9570 | /* If we're at the second level, and we're an enumerator, and |
9571 | our parent has no specification (meaning possibly lives in a | |
9572 | namespace elsewhere), then we can add the partial symbol now | |
9573 | instead of queueing it. */ | |
9574 | if (part_die->tag == DW_TAG_enumerator | |
9575 | && parent_die != NULL | |
9576 | && parent_die->die_parent == NULL | |
9577 | && parent_die->tag == DW_TAG_enumeration_type | |
9578 | && parent_die->has_specification == 0) | |
9579 | { | |
9580 | if (part_die->name == NULL) | |
3e43a32a MS |
9581 | complaint (&symfile_complaints, |
9582 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 9583 | else if (building_psymtab) |
04a679b8 | 9584 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9585 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
9586 | (cu->language == language_cplus |
9587 | || cu->language == language_java) | |
72bf9492 DJ |
9588 | ? &cu->objfile->global_psymbols |
9589 | : &cu->objfile->static_psymbols, | |
9590 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
9591 | ||
93311388 | 9592 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9593 | continue; |
9594 | } | |
9595 | ||
9596 | /* We'll save this DIE so link it in. */ | |
9597 | part_die->die_parent = parent_die; | |
9598 | part_die->die_sibling = NULL; | |
9599 | part_die->die_child = NULL; | |
9600 | ||
9601 | if (last_die && last_die == parent_die) | |
9602 | last_die->die_child = part_die; | |
9603 | else if (last_die) | |
9604 | last_die->die_sibling = part_die; | |
9605 | ||
9606 | last_die = part_die; | |
9607 | ||
9608 | if (first_die == NULL) | |
9609 | first_die = part_die; | |
9610 | ||
9611 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
9612 | find interesting need to be in the hash table, because we | |
9613 | also have the parent/sibling/child chains; only those that we | |
9614 | might refer to by offset later during partial symbol reading. | |
9615 | ||
9616 | For now this means things that might have be the target of a | |
9617 | DW_AT_specification, DW_AT_abstract_origin, or | |
9618 | DW_AT_extension. DW_AT_extension will refer only to | |
9619 | namespaces; DW_AT_abstract_origin refers to functions (and | |
9620 | many things under the function DIE, but we do not recurse | |
9621 | into function DIEs during partial symbol reading) and | |
9622 | possibly variables as well; DW_AT_specification refers to | |
9623 | declarations. Declarations ought to have the DW_AT_declaration | |
9624 | flag. It happens that GCC forgets to put it in sometimes, but | |
9625 | only for functions, not for types. | |
9626 | ||
9627 | Adding more things than necessary to the hash table is harmless | |
9628 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
9629 | wasted time in find_partial_die, when we reread the compilation |
9630 | unit with load_all_dies set. */ | |
72bf9492 | 9631 | |
5afb4e99 | 9632 | if (load_all |
72929c62 | 9633 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 9634 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
9635 | || abbrev->tag == DW_TAG_variable |
9636 | || abbrev->tag == DW_TAG_namespace | |
9637 | || part_die->is_declaration) | |
9638 | { | |
9639 | void **slot; | |
9640 | ||
9641 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
9642 | part_die->offset, INSERT); | |
9643 | *slot = part_die; | |
9644 | } | |
9645 | ||
9646 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9647 | sizeof (struct partial_die_info)); | |
9648 | ||
9649 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 9650 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
9651 | languages we have to, so that we can get at method physnames |
9652 | to infer fully qualified class names, for DW_AT_specification, | |
9653 | and for C++ template arguments. For C++, we also look one level | |
9654 | inside functions to find template arguments (if the name of the | |
9655 | function does not already contain the template arguments). | |
bc30ff58 JB |
9656 | |
9657 | For Ada, we need to scan the children of subprograms and lexical | |
9658 | blocks as well because Ada allows the definition of nested | |
9659 | entities that could be interesting for the debugger, such as | |
9660 | nested subprograms for instance. */ | |
72bf9492 | 9661 | if (last_die->has_children |
5afb4e99 DJ |
9662 | && (load_all |
9663 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 9664 | || last_die->tag == DW_TAG_module |
72bf9492 | 9665 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
9666 | || (cu->language == language_cplus |
9667 | && last_die->tag == DW_TAG_subprogram | |
9668 | && (last_die->name == NULL | |
9669 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
9670 | || (cu->language != language_c |
9671 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 9672 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 9673 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
9674 | || last_die->tag == DW_TAG_union_type)) |
9675 | || (cu->language == language_ada | |
9676 | && (last_die->tag == DW_TAG_subprogram | |
9677 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9678 | { |
9679 | nesting_level++; | |
9680 | parent_die = last_die; | |
9681 | continue; | |
9682 | } | |
9683 | ||
9684 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9685 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9686 | |
9687 | /* Back to the top, do it again. */ | |
9688 | } | |
9689 | } | |
9690 | ||
c906108c SS |
9691 | /* Read a minimal amount of information into the minimal die structure. */ |
9692 | ||
fe1b8b76 | 9693 | static gdb_byte * |
72bf9492 DJ |
9694 | read_partial_die (struct partial_die_info *part_die, |
9695 | struct abbrev_info *abbrev, | |
9696 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
9697 | gdb_byte *buffer, gdb_byte *info_ptr, |
9698 | struct dwarf2_cu *cu) | |
c906108c | 9699 | { |
fa238c03 | 9700 | unsigned int i; |
c906108c | 9701 | struct attribute attr; |
c5aa993b | 9702 | int has_low_pc_attr = 0; |
c906108c SS |
9703 | int has_high_pc_attr = 0; |
9704 | ||
72bf9492 | 9705 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 9706 | |
93311388 | 9707 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
9708 | |
9709 | info_ptr += abbrev_len; | |
9710 | ||
9711 | if (abbrev == NULL) | |
9712 | return info_ptr; | |
9713 | ||
c906108c SS |
9714 | part_die->tag = abbrev->tag; |
9715 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
9716 | |
9717 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9718 | { | |
e7c27a73 | 9719 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
9720 | |
9721 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 9722 | partial symbol table. */ |
c906108c SS |
9723 | switch (attr.name) |
9724 | { | |
9725 | case DW_AT_name: | |
71c25dea TT |
9726 | switch (part_die->tag) |
9727 | { | |
9728 | case DW_TAG_compile_unit: | |
348e048f | 9729 | case DW_TAG_type_unit: |
71c25dea TT |
9730 | /* Compilation units have a DW_AT_name that is a filename, not |
9731 | a source language identifier. */ | |
9732 | case DW_TAG_enumeration_type: | |
9733 | case DW_TAG_enumerator: | |
9734 | /* These tags always have simple identifiers already; no need | |
9735 | to canonicalize them. */ | |
9736 | part_die->name = DW_STRING (&attr); | |
9737 | break; | |
9738 | default: | |
9739 | part_die->name | |
9740 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 9741 | &cu->objfile->objfile_obstack); |
71c25dea TT |
9742 | break; |
9743 | } | |
c906108c | 9744 | break; |
31ef98ae | 9745 | case DW_AT_linkage_name: |
c906108c | 9746 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
9747 | /* Note that both forms of linkage name might appear. We |
9748 | assume they will be the same, and we only store the last | |
9749 | one we see. */ | |
94af9270 KS |
9750 | if (cu->language == language_ada) |
9751 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 9752 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
9753 | break; |
9754 | case DW_AT_low_pc: | |
9755 | has_low_pc_attr = 1; | |
9756 | part_die->lowpc = DW_ADDR (&attr); | |
9757 | break; | |
9758 | case DW_AT_high_pc: | |
9759 | has_high_pc_attr = 1; | |
9760 | part_die->highpc = DW_ADDR (&attr); | |
9761 | break; | |
9762 | case DW_AT_location: | |
0963b4bd | 9763 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9764 | if (attr_form_is_block (&attr)) |
9765 | { | |
9766 | part_die->locdesc = DW_BLOCK (&attr); | |
9767 | } | |
3690dd37 | 9768 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 9769 | { |
4d3c2250 | 9770 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9771 | } |
9772 | else | |
9773 | { | |
4d3c2250 KB |
9774 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9775 | "partial symbol information"); | |
8e19ed76 | 9776 | } |
c906108c | 9777 | break; |
c906108c SS |
9778 | case DW_AT_external: |
9779 | part_die->is_external = DW_UNSND (&attr); | |
9780 | break; | |
9781 | case DW_AT_declaration: | |
9782 | part_die->is_declaration = DW_UNSND (&attr); | |
9783 | break; | |
9784 | case DW_AT_type: | |
9785 | part_die->has_type = 1; | |
9786 | break; | |
9787 | case DW_AT_abstract_origin: | |
9788 | case DW_AT_specification: | |
72bf9492 DJ |
9789 | case DW_AT_extension: |
9790 | part_die->has_specification = 1; | |
c764a876 | 9791 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
9792 | break; |
9793 | case DW_AT_sibling: | |
9794 | /* Ignore absolute siblings, they might point outside of | |
9795 | the current compile unit. */ | |
9796 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
9797 | complaint (&symfile_complaints, |
9798 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 9799 | else |
93311388 | 9800 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 9801 | break; |
fa4028e9 JB |
9802 | case DW_AT_byte_size: |
9803 | part_die->has_byte_size = 1; | |
9804 | break; | |
68511cec CES |
9805 | case DW_AT_calling_convention: |
9806 | /* DWARF doesn't provide a way to identify a program's source-level | |
9807 | entry point. DW_AT_calling_convention attributes are only meant | |
9808 | to describe functions' calling conventions. | |
9809 | ||
9810 | However, because it's a necessary piece of information in | |
9811 | Fortran, and because DW_CC_program is the only piece of debugging | |
9812 | information whose definition refers to a 'main program' at all, | |
9813 | several compilers have begun marking Fortran main programs with | |
9814 | DW_CC_program --- even when those functions use the standard | |
9815 | calling conventions. | |
9816 | ||
9817 | So until DWARF specifies a way to provide this information and | |
9818 | compilers pick up the new representation, we'll support this | |
9819 | practice. */ | |
9820 | if (DW_UNSND (&attr) == DW_CC_program | |
9821 | && cu->language == language_fortran) | |
01f8c46d JK |
9822 | { |
9823 | set_main_name (part_die->name); | |
9824 | ||
9825 | /* As this DIE has a static linkage the name would be difficult | |
9826 | to look up later. */ | |
9827 | language_of_main = language_fortran; | |
9828 | } | |
68511cec | 9829 | break; |
c906108c SS |
9830 | default: |
9831 | break; | |
9832 | } | |
9833 | } | |
9834 | ||
9373cf26 JK |
9835 | if (has_low_pc_attr && has_high_pc_attr) |
9836 | { | |
9837 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
9838 | eliminate duplicate copies of functions and vtables and such. | |
9839 | The linker will arbitrarily choose one and discard the others. | |
9840 | The AT_*_pc values for such functions refer to local labels in | |
9841 | these sections. If the section from that file was discarded, the | |
9842 | labels are not in the output, so the relocs get a value of 0. | |
9843 | If this is a discarded function, mark the pc bounds as invalid, | |
9844 | so that GDB will ignore it. */ | |
9845 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
9846 | { | |
9847 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); | |
9848 | ||
9849 | complaint (&symfile_complaints, | |
9850 | _("DW_AT_low_pc %s is zero " | |
9851 | "for DIE at 0x%x [in module %s]"), | |
9852 | paddress (gdbarch, part_die->lowpc), | |
9853 | part_die->offset, cu->objfile->name); | |
9854 | } | |
9855 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
9856 | else if (part_die->lowpc >= part_die->highpc) | |
9857 | { | |
9858 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); | |
9859 | ||
9860 | complaint (&symfile_complaints, | |
9861 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
9862 | "for DIE at 0x%x [in module %s]"), | |
9863 | paddress (gdbarch, part_die->lowpc), | |
9864 | paddress (gdbarch, part_die->highpc), | |
9865 | part_die->offset, cu->objfile->name); | |
9866 | } | |
9867 | else | |
9868 | part_die->has_pc_info = 1; | |
9869 | } | |
85cbf3d3 | 9870 | |
c906108c SS |
9871 | return info_ptr; |
9872 | } | |
9873 | ||
72bf9492 DJ |
9874 | /* Find a cached partial DIE at OFFSET in CU. */ |
9875 | ||
9876 | static struct partial_die_info * | |
c764a876 | 9877 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
9878 | { |
9879 | struct partial_die_info *lookup_die = NULL; | |
9880 | struct partial_die_info part_die; | |
9881 | ||
9882 | part_die.offset = offset; | |
9883 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
9884 | ||
72bf9492 DJ |
9885 | return lookup_die; |
9886 | } | |
9887 | ||
348e048f DE |
9888 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
9889 | except in the case of .debug_types DIEs which do not reference | |
9890 | outside their CU (they do however referencing other types via | |
55f1336d | 9891 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
9892 | |
9893 | static struct partial_die_info * | |
c764a876 | 9894 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 9895 | { |
5afb4e99 DJ |
9896 | struct dwarf2_per_cu_data *per_cu = NULL; |
9897 | struct partial_die_info *pd = NULL; | |
72bf9492 | 9898 | |
8b70b953 | 9899 | if (cu->per_cu->debug_type_section) |
348e048f DE |
9900 | { |
9901 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9902 | if (pd != NULL) | |
9903 | return pd; | |
9904 | goto not_found; | |
9905 | } | |
9906 | ||
45452591 | 9907 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
9908 | { |
9909 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9910 | if (pd != NULL) | |
9911 | return pd; | |
9912 | } | |
72bf9492 | 9913 | |
ae038cb0 DJ |
9914 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
9915 | ||
98bfdba5 PA |
9916 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
9917 | load_partial_comp_unit (per_cu, cu->objfile); | |
ae038cb0 DJ |
9918 | |
9919 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
9920 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
9921 | ||
9922 | if (pd == NULL && per_cu->load_all_dies == 0) | |
9923 | { | |
9924 | struct cleanup *back_to; | |
9925 | struct partial_die_info comp_unit_die; | |
9926 | struct abbrev_info *abbrev; | |
9927 | unsigned int bytes_read; | |
9928 | char *info_ptr; | |
9929 | ||
9930 | per_cu->load_all_dies = 1; | |
9931 | ||
9932 | /* Re-read the DIEs. */ | |
9933 | back_to = make_cleanup (null_cleanup, 0); | |
9934 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
9935 | { | |
9936 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 9937 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 9938 | } |
dce234bc | 9939 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
9940 | + per_cu->cu->header.offset |
9941 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
9942 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
9943 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
9944 | per_cu->cu->objfile->obfd, |
9945 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
9946 | per_cu->cu); |
9947 | if (comp_unit_die.has_children) | |
93311388 DE |
9948 | load_partial_dies (per_cu->cu->objfile->obfd, |
9949 | dwarf2_per_objfile->info.buffer, info_ptr, | |
9950 | 0, per_cu->cu); | |
5afb4e99 DJ |
9951 | do_cleanups (back_to); |
9952 | ||
9953 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
9954 | } | |
9955 | ||
348e048f DE |
9956 | not_found: |
9957 | ||
5afb4e99 DJ |
9958 | if (pd == NULL) |
9959 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
9960 | _("could not find partial DIE 0x%x " |
9961 | "in cache [from module %s]\n"), | |
5afb4e99 DJ |
9962 | offset, bfd_get_filename (cu->objfile->obfd)); |
9963 | return pd; | |
72bf9492 DJ |
9964 | } |
9965 | ||
abc72ce4 DE |
9966 | /* See if we can figure out if the class lives in a namespace. We do |
9967 | this by looking for a member function; its demangled name will | |
9968 | contain namespace info, if there is any. */ | |
9969 | ||
9970 | static void | |
9971 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
9972 | struct dwarf2_cu *cu) | |
9973 | { | |
9974 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
9975 | what template types look like, because the demangler | |
9976 | frequently doesn't give the same name as the debug info. We | |
9977 | could fix this by only using the demangled name to get the | |
9978 | prefix (but see comment in read_structure_type). */ | |
9979 | ||
9980 | struct partial_die_info *real_pdi; | |
9981 | struct partial_die_info *child_pdi; | |
9982 | ||
9983 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
9984 | we should not do this. We'll prepend the parent's fully qualified | |
9985 | name when we create the partial symbol. */ | |
9986 | ||
9987 | real_pdi = struct_pdi; | |
9988 | while (real_pdi->has_specification) | |
9989 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
9990 | ||
9991 | if (real_pdi->die_parent != NULL) | |
9992 | return; | |
9993 | ||
9994 | for (child_pdi = struct_pdi->die_child; | |
9995 | child_pdi != NULL; | |
9996 | child_pdi = child_pdi->die_sibling) | |
9997 | { | |
9998 | if (child_pdi->tag == DW_TAG_subprogram | |
9999 | && child_pdi->linkage_name != NULL) | |
10000 | { | |
10001 | char *actual_class_name | |
10002 | = language_class_name_from_physname (cu->language_defn, | |
10003 | child_pdi->linkage_name); | |
10004 | if (actual_class_name != NULL) | |
10005 | { | |
10006 | struct_pdi->name | |
10007 | = obsavestring (actual_class_name, | |
10008 | strlen (actual_class_name), | |
10009 | &cu->objfile->objfile_obstack); | |
10010 | xfree (actual_class_name); | |
10011 | } | |
10012 | break; | |
10013 | } | |
10014 | } | |
10015 | } | |
10016 | ||
72bf9492 DJ |
10017 | /* Adjust PART_DIE before generating a symbol for it. This function |
10018 | may set the is_external flag or change the DIE's name. */ | |
10019 | ||
10020 | static void | |
10021 | fixup_partial_die (struct partial_die_info *part_die, | |
10022 | struct dwarf2_cu *cu) | |
10023 | { | |
abc72ce4 DE |
10024 | /* Once we've fixed up a die, there's no point in doing so again. |
10025 | This also avoids a memory leak if we were to call | |
10026 | guess_partial_die_structure_name multiple times. */ | |
10027 | if (part_die->fixup_called) | |
10028 | return; | |
10029 | ||
72bf9492 DJ |
10030 | /* If we found a reference attribute and the DIE has no name, try |
10031 | to find a name in the referred to DIE. */ | |
10032 | ||
10033 | if (part_die->name == NULL && part_die->has_specification) | |
10034 | { | |
10035 | struct partial_die_info *spec_die; | |
72bf9492 | 10036 | |
10b3939b | 10037 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 10038 | |
10b3939b | 10039 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
10040 | |
10041 | if (spec_die->name) | |
10042 | { | |
10043 | part_die->name = spec_die->name; | |
10044 | ||
10045 | /* Copy DW_AT_external attribute if it is set. */ | |
10046 | if (spec_die->is_external) | |
10047 | part_die->is_external = spec_die->is_external; | |
10048 | } | |
10049 | } | |
10050 | ||
10051 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
10052 | |
10053 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 10054 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 10055 | |
abc72ce4 DE |
10056 | /* If there is no parent die to provide a namespace, and there are |
10057 | children, see if we can determine the namespace from their linkage | |
10058 | name. | |
10059 | NOTE: We need to do this even if cu->has_namespace_info != 0. | |
10060 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ | |
10061 | if (cu->language == language_cplus | |
8b70b953 | 10062 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
10063 | && part_die->die_parent == NULL |
10064 | && part_die->has_children | |
10065 | && (part_die->tag == DW_TAG_class_type | |
10066 | || part_die->tag == DW_TAG_structure_type | |
10067 | || part_die->tag == DW_TAG_union_type)) | |
10068 | guess_partial_die_structure_name (part_die, cu); | |
10069 | ||
53832f31 TT |
10070 | /* GCC might emit a nameless struct or union that has a linkage |
10071 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
10072 | if (part_die->name == NULL | |
96408a79 SA |
10073 | && (part_die->tag == DW_TAG_class_type |
10074 | || part_die->tag == DW_TAG_interface_type | |
10075 | || part_die->tag == DW_TAG_structure_type | |
10076 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
10077 | && part_die->linkage_name != NULL) |
10078 | { | |
10079 | char *demangled; | |
10080 | ||
10081 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
10082 | if (demangled) | |
10083 | { | |
96408a79 SA |
10084 | const char *base; |
10085 | ||
10086 | /* Strip any leading namespaces/classes, keep only the base name. | |
10087 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
10088 | base = strrchr (demangled, ':'); | |
10089 | if (base && base > demangled && base[-1] == ':') | |
10090 | base++; | |
10091 | else | |
10092 | base = demangled; | |
10093 | ||
10094 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
10095 | &cu->objfile->objfile_obstack); |
10096 | xfree (demangled); | |
10097 | } | |
10098 | } | |
10099 | ||
abc72ce4 | 10100 | part_die->fixup_called = 1; |
72bf9492 DJ |
10101 | } |
10102 | ||
a8329558 | 10103 | /* Read an attribute value described by an attribute form. */ |
c906108c | 10104 | |
fe1b8b76 | 10105 | static gdb_byte * |
a8329558 | 10106 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 10107 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 10108 | struct dwarf2_cu *cu) |
c906108c | 10109 | { |
e7c27a73 | 10110 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10111 | unsigned int bytes_read; |
10112 | struct dwarf_block *blk; | |
10113 | ||
a8329558 KW |
10114 | attr->form = form; |
10115 | switch (form) | |
c906108c | 10116 | { |
c906108c | 10117 | case DW_FORM_ref_addr: |
ae411497 TT |
10118 | if (cu->header.version == 2) |
10119 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
10120 | else | |
3e43a32a MS |
10121 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
10122 | &cu->header, &bytes_read); | |
ae411497 TT |
10123 | info_ptr += bytes_read; |
10124 | break; | |
10125 | case DW_FORM_addr: | |
e7c27a73 | 10126 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 10127 | info_ptr += bytes_read; |
c906108c SS |
10128 | break; |
10129 | case DW_FORM_block2: | |
7b5a2f43 | 10130 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10131 | blk->size = read_2_bytes (abfd, info_ptr); |
10132 | info_ptr += 2; | |
10133 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10134 | info_ptr += blk->size; | |
10135 | DW_BLOCK (attr) = blk; | |
10136 | break; | |
10137 | case DW_FORM_block4: | |
7b5a2f43 | 10138 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10139 | blk->size = read_4_bytes (abfd, info_ptr); |
10140 | info_ptr += 4; | |
10141 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10142 | info_ptr += blk->size; | |
10143 | DW_BLOCK (attr) = blk; | |
10144 | break; | |
10145 | case DW_FORM_data2: | |
10146 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
10147 | info_ptr += 2; | |
10148 | break; | |
10149 | case DW_FORM_data4: | |
10150 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
10151 | info_ptr += 4; | |
10152 | break; | |
10153 | case DW_FORM_data8: | |
10154 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
10155 | info_ptr += 8; | |
10156 | break; | |
2dc7f7b3 TT |
10157 | case DW_FORM_sec_offset: |
10158 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
10159 | info_ptr += bytes_read; | |
10160 | break; | |
c906108c | 10161 | case DW_FORM_string: |
9b1c24c8 | 10162 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 10163 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
10164 | info_ptr += bytes_read; |
10165 | break; | |
4bdf3d34 JJ |
10166 | case DW_FORM_strp: |
10167 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
10168 | &bytes_read); | |
8285870a | 10169 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
10170 | info_ptr += bytes_read; |
10171 | break; | |
2dc7f7b3 | 10172 | case DW_FORM_exprloc: |
c906108c | 10173 | case DW_FORM_block: |
7b5a2f43 | 10174 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10175 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10176 | info_ptr += bytes_read; | |
10177 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10178 | info_ptr += blk->size; | |
10179 | DW_BLOCK (attr) = blk; | |
10180 | break; | |
10181 | case DW_FORM_block1: | |
7b5a2f43 | 10182 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10183 | blk->size = read_1_byte (abfd, info_ptr); |
10184 | info_ptr += 1; | |
10185 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10186 | info_ptr += blk->size; | |
10187 | DW_BLOCK (attr) = blk; | |
10188 | break; | |
10189 | case DW_FORM_data1: | |
10190 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10191 | info_ptr += 1; | |
10192 | break; | |
10193 | case DW_FORM_flag: | |
10194 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10195 | info_ptr += 1; | |
10196 | break; | |
2dc7f7b3 TT |
10197 | case DW_FORM_flag_present: |
10198 | DW_UNSND (attr) = 1; | |
10199 | break; | |
c906108c SS |
10200 | case DW_FORM_sdata: |
10201 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
10202 | info_ptr += bytes_read; | |
10203 | break; | |
10204 | case DW_FORM_udata: | |
10205 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
10206 | info_ptr += bytes_read; | |
10207 | break; | |
10208 | case DW_FORM_ref1: | |
10b3939b | 10209 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
10210 | info_ptr += 1; |
10211 | break; | |
10212 | case DW_FORM_ref2: | |
10b3939b | 10213 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
10214 | info_ptr += 2; |
10215 | break; | |
10216 | case DW_FORM_ref4: | |
10b3939b | 10217 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
10218 | info_ptr += 4; |
10219 | break; | |
613e1657 | 10220 | case DW_FORM_ref8: |
10b3939b | 10221 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
10222 | info_ptr += 8; |
10223 | break; | |
55f1336d | 10224 | case DW_FORM_ref_sig8: |
348e048f DE |
10225 | /* Convert the signature to something we can record in DW_UNSND |
10226 | for later lookup. | |
10227 | NOTE: This is NULL if the type wasn't found. */ | |
10228 | DW_SIGNATURED_TYPE (attr) = | |
10229 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
10230 | info_ptr += 8; | |
10231 | break; | |
c906108c | 10232 | case DW_FORM_ref_udata: |
10b3939b DJ |
10233 | DW_ADDR (attr) = (cu->header.offset |
10234 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
10235 | info_ptr += bytes_read; |
10236 | break; | |
c906108c | 10237 | case DW_FORM_indirect: |
a8329558 KW |
10238 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10239 | info_ptr += bytes_read; | |
e7c27a73 | 10240 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 10241 | break; |
c906108c | 10242 | default: |
8a3fe4f8 | 10243 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
10244 | dwarf_form_name (form), |
10245 | bfd_get_filename (abfd)); | |
c906108c | 10246 | } |
28e94949 JB |
10247 | |
10248 | /* We have seen instances where the compiler tried to emit a byte | |
10249 | size attribute of -1 which ended up being encoded as an unsigned | |
10250 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
10251 | an object of this size seems pretty unlikely so we can relatively | |
10252 | safely treat these cases as if the size attribute was invalid and | |
10253 | treat them as zero by default. */ | |
10254 | if (attr->name == DW_AT_byte_size | |
10255 | && form == DW_FORM_data4 | |
10256 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
10257 | { |
10258 | complaint | |
10259 | (&symfile_complaints, | |
43bbcdc2 PH |
10260 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
10261 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
10262 | DW_UNSND (attr) = 0; |
10263 | } | |
28e94949 | 10264 | |
c906108c SS |
10265 | return info_ptr; |
10266 | } | |
10267 | ||
a8329558 KW |
10268 | /* Read an attribute described by an abbreviated attribute. */ |
10269 | ||
fe1b8b76 | 10270 | static gdb_byte * |
a8329558 | 10271 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 10272 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
10273 | { |
10274 | attr->name = abbrev->name; | |
e7c27a73 | 10275 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
10276 | } |
10277 | ||
0963b4bd | 10278 | /* Read dwarf information from a buffer. */ |
c906108c SS |
10279 | |
10280 | static unsigned int | |
fe1b8b76 | 10281 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10282 | { |
fe1b8b76 | 10283 | return bfd_get_8 (abfd, buf); |
c906108c SS |
10284 | } |
10285 | ||
10286 | static int | |
fe1b8b76 | 10287 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10288 | { |
fe1b8b76 | 10289 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
10290 | } |
10291 | ||
10292 | static unsigned int | |
fe1b8b76 | 10293 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10294 | { |
fe1b8b76 | 10295 | return bfd_get_16 (abfd, buf); |
c906108c SS |
10296 | } |
10297 | ||
c906108c | 10298 | static unsigned int |
fe1b8b76 | 10299 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10300 | { |
fe1b8b76 | 10301 | return bfd_get_32 (abfd, buf); |
c906108c SS |
10302 | } |
10303 | ||
93311388 | 10304 | static ULONGEST |
fe1b8b76 | 10305 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10306 | { |
fe1b8b76 | 10307 | return bfd_get_64 (abfd, buf); |
c906108c SS |
10308 | } |
10309 | ||
10310 | static CORE_ADDR | |
fe1b8b76 | 10311 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 10312 | unsigned int *bytes_read) |
c906108c | 10313 | { |
e7c27a73 | 10314 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10315 | CORE_ADDR retval = 0; |
10316 | ||
107d2387 | 10317 | if (cu_header->signed_addr_p) |
c906108c | 10318 | { |
107d2387 AC |
10319 | switch (cu_header->addr_size) |
10320 | { | |
10321 | case 2: | |
fe1b8b76 | 10322 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
10323 | break; |
10324 | case 4: | |
fe1b8b76 | 10325 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
10326 | break; |
10327 | case 8: | |
fe1b8b76 | 10328 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
10329 | break; |
10330 | default: | |
8e65ff28 | 10331 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 10332 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 10333 | bfd_get_filename (abfd)); |
107d2387 AC |
10334 | } |
10335 | } | |
10336 | else | |
10337 | { | |
10338 | switch (cu_header->addr_size) | |
10339 | { | |
10340 | case 2: | |
fe1b8b76 | 10341 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
10342 | break; |
10343 | case 4: | |
fe1b8b76 | 10344 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
10345 | break; |
10346 | case 8: | |
fe1b8b76 | 10347 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
10348 | break; |
10349 | default: | |
8e65ff28 | 10350 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
10351 | _("read_address: bad switch, " |
10352 | "unsigned [in module %s]"), | |
659b0389 | 10353 | bfd_get_filename (abfd)); |
107d2387 | 10354 | } |
c906108c | 10355 | } |
64367e0a | 10356 | |
107d2387 AC |
10357 | *bytes_read = cu_header->addr_size; |
10358 | return retval; | |
c906108c SS |
10359 | } |
10360 | ||
f7ef9339 | 10361 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
10362 | specification allows the initial length to take up either 4 bytes |
10363 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
10364 | bytes describe the length and all offsets will be 8 bytes in length | |
10365 | instead of 4. | |
10366 | ||
f7ef9339 KB |
10367 | An older, non-standard 64-bit format is also handled by this |
10368 | function. The older format in question stores the initial length | |
10369 | as an 8-byte quantity without an escape value. Lengths greater | |
10370 | than 2^32 aren't very common which means that the initial 4 bytes | |
10371 | is almost always zero. Since a length value of zero doesn't make | |
10372 | sense for the 32-bit format, this initial zero can be considered to | |
10373 | be an escape value which indicates the presence of the older 64-bit | |
10374 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
10375 | greater than 4GB. If it becomes necessary to handle lengths |
10376 | somewhat larger than 4GB, we could allow other small values (such | |
10377 | as the non-sensical values of 1, 2, and 3) to also be used as | |
10378 | escape values indicating the presence of the old format. | |
f7ef9339 | 10379 | |
917c78fc MK |
10380 | The value returned via bytes_read should be used to increment the |
10381 | relevant pointer after calling read_initial_length(). | |
c764a876 | 10382 | |
613e1657 KB |
10383 | [ Note: read_initial_length() and read_offset() are based on the |
10384 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 10385 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
10386 | from: |
10387 | ||
f7ef9339 | 10388 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 10389 | |
613e1657 KB |
10390 | This document is only a draft and is subject to change. (So beware.) |
10391 | ||
f7ef9339 | 10392 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
10393 | determined empirically by examining 64-bit ELF files produced by |
10394 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
10395 | |
10396 | - Kevin, July 16, 2002 | |
613e1657 KB |
10397 | ] */ |
10398 | ||
10399 | static LONGEST | |
c764a876 | 10400 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 10401 | { |
fe1b8b76 | 10402 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 10403 | |
dd373385 | 10404 | if (length == 0xffffffff) |
613e1657 | 10405 | { |
fe1b8b76 | 10406 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 10407 | *bytes_read = 12; |
613e1657 | 10408 | } |
dd373385 | 10409 | else if (length == 0) |
f7ef9339 | 10410 | { |
dd373385 | 10411 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 10412 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 10413 | *bytes_read = 8; |
f7ef9339 | 10414 | } |
613e1657 KB |
10415 | else |
10416 | { | |
10417 | *bytes_read = 4; | |
613e1657 KB |
10418 | } |
10419 | ||
c764a876 DE |
10420 | return length; |
10421 | } | |
dd373385 | 10422 | |
c764a876 DE |
10423 | /* Cover function for read_initial_length. |
10424 | Returns the length of the object at BUF, and stores the size of the | |
10425 | initial length in *BYTES_READ and stores the size that offsets will be in | |
10426 | *OFFSET_SIZE. | |
10427 | If the initial length size is not equivalent to that specified in | |
10428 | CU_HEADER then issue a complaint. | |
10429 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 10430 | |
c764a876 DE |
10431 | static LONGEST |
10432 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
10433 | const struct comp_unit_head *cu_header, | |
10434 | unsigned int *bytes_read, | |
10435 | unsigned int *offset_size) | |
10436 | { | |
10437 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
10438 | ||
10439 | gdb_assert (cu_header->initial_length_size == 4 | |
10440 | || cu_header->initial_length_size == 8 | |
10441 | || cu_header->initial_length_size == 12); | |
10442 | ||
10443 | if (cu_header->initial_length_size != *bytes_read) | |
10444 | complaint (&symfile_complaints, | |
10445 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 10446 | |
c764a876 | 10447 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 10448 | return length; |
613e1657 KB |
10449 | } |
10450 | ||
10451 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 10452 | given by cu_header->offset_size. */ |
613e1657 KB |
10453 | |
10454 | static LONGEST | |
fe1b8b76 | 10455 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 10456 | unsigned int *bytes_read) |
c764a876 DE |
10457 | { |
10458 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 10459 | |
c764a876 DE |
10460 | *bytes_read = cu_header->offset_size; |
10461 | return offset; | |
10462 | } | |
10463 | ||
10464 | /* Read an offset from the data stream. */ | |
10465 | ||
10466 | static LONGEST | |
10467 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
10468 | { |
10469 | LONGEST retval = 0; | |
10470 | ||
c764a876 | 10471 | switch (offset_size) |
613e1657 KB |
10472 | { |
10473 | case 4: | |
fe1b8b76 | 10474 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
10475 | break; |
10476 | case 8: | |
fe1b8b76 | 10477 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
10478 | break; |
10479 | default: | |
8e65ff28 | 10480 | internal_error (__FILE__, __LINE__, |
c764a876 | 10481 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 10482 | bfd_get_filename (abfd)); |
613e1657 KB |
10483 | } |
10484 | ||
917c78fc | 10485 | return retval; |
613e1657 KB |
10486 | } |
10487 | ||
fe1b8b76 JB |
10488 | static gdb_byte * |
10489 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
10490 | { |
10491 | /* If the size of a host char is 8 bits, we can return a pointer | |
10492 | to the buffer, otherwise we have to copy the data to a buffer | |
10493 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10494 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 10495 | return buf; |
c906108c SS |
10496 | } |
10497 | ||
10498 | static char * | |
9b1c24c8 | 10499 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
10500 | { |
10501 | /* If the size of a host char is 8 bits, we can return a pointer | |
10502 | to the string, otherwise we have to copy the string to a buffer | |
10503 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10504 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
10505 | if (*buf == '\0') |
10506 | { | |
10507 | *bytes_read_ptr = 1; | |
10508 | return NULL; | |
10509 | } | |
fe1b8b76 JB |
10510 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
10511 | return (char *) buf; | |
4bdf3d34 JJ |
10512 | } |
10513 | ||
10514 | static char * | |
cf2c3c16 | 10515 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 10516 | { |
be391dca | 10517 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 10518 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
10519 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
10520 | bfd_get_filename (abfd)); | |
dce234bc | 10521 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
10522 | error (_("DW_FORM_strp pointing outside of " |
10523 | ".debug_str section [in module %s]"), | |
10524 | bfd_get_filename (abfd)); | |
4bdf3d34 | 10525 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 10526 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 10527 | return NULL; |
dce234bc | 10528 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
10529 | } |
10530 | ||
cf2c3c16 TT |
10531 | static char * |
10532 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
10533 | const struct comp_unit_head *cu_header, | |
10534 | unsigned int *bytes_read_ptr) | |
10535 | { | |
10536 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
10537 | ||
10538 | return read_indirect_string_at_offset (abfd, str_offset); | |
10539 | } | |
10540 | ||
ce5d95e1 | 10541 | static unsigned long |
fe1b8b76 | 10542 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10543 | { |
ce5d95e1 JB |
10544 | unsigned long result; |
10545 | unsigned int num_read; | |
c906108c SS |
10546 | int i, shift; |
10547 | unsigned char byte; | |
10548 | ||
10549 | result = 0; | |
10550 | shift = 0; | |
10551 | num_read = 0; | |
10552 | i = 0; | |
10553 | while (1) | |
10554 | { | |
fe1b8b76 | 10555 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10556 | buf++; |
10557 | num_read++; | |
ce5d95e1 | 10558 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
10559 | if ((byte & 128) == 0) |
10560 | { | |
10561 | break; | |
10562 | } | |
10563 | shift += 7; | |
10564 | } | |
10565 | *bytes_read_ptr = num_read; | |
10566 | return result; | |
10567 | } | |
10568 | ||
ce5d95e1 | 10569 | static long |
fe1b8b76 | 10570 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10571 | { |
ce5d95e1 | 10572 | long result; |
77e0b926 | 10573 | int i, shift, num_read; |
c906108c SS |
10574 | unsigned char byte; |
10575 | ||
10576 | result = 0; | |
10577 | shift = 0; | |
c906108c SS |
10578 | num_read = 0; |
10579 | i = 0; | |
10580 | while (1) | |
10581 | { | |
fe1b8b76 | 10582 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10583 | buf++; |
10584 | num_read++; | |
ce5d95e1 | 10585 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
10586 | shift += 7; |
10587 | if ((byte & 128) == 0) | |
10588 | { | |
10589 | break; | |
10590 | } | |
10591 | } | |
77e0b926 DJ |
10592 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
10593 | result |= -(((long)1) << shift); | |
c906108c SS |
10594 | *bytes_read_ptr = num_read; |
10595 | return result; | |
10596 | } | |
10597 | ||
4bb7a0a7 DJ |
10598 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
10599 | ||
fe1b8b76 JB |
10600 | static gdb_byte * |
10601 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
10602 | { |
10603 | int byte; | |
10604 | ||
10605 | while (1) | |
10606 | { | |
fe1b8b76 | 10607 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
10608 | buf++; |
10609 | if ((byte & 128) == 0) | |
10610 | return buf; | |
10611 | } | |
10612 | } | |
10613 | ||
c906108c | 10614 | static void |
e142c38c | 10615 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
10616 | { |
10617 | switch (lang) | |
10618 | { | |
10619 | case DW_LANG_C89: | |
76bee0cc | 10620 | case DW_LANG_C99: |
c906108c | 10621 | case DW_LANG_C: |
e142c38c | 10622 | cu->language = language_c; |
c906108c SS |
10623 | break; |
10624 | case DW_LANG_C_plus_plus: | |
e142c38c | 10625 | cu->language = language_cplus; |
c906108c | 10626 | break; |
6aecb9c2 JB |
10627 | case DW_LANG_D: |
10628 | cu->language = language_d; | |
10629 | break; | |
c906108c SS |
10630 | case DW_LANG_Fortran77: |
10631 | case DW_LANG_Fortran90: | |
b21b22e0 | 10632 | case DW_LANG_Fortran95: |
e142c38c | 10633 | cu->language = language_fortran; |
c906108c SS |
10634 | break; |
10635 | case DW_LANG_Mips_Assembler: | |
e142c38c | 10636 | cu->language = language_asm; |
c906108c | 10637 | break; |
bebd888e | 10638 | case DW_LANG_Java: |
e142c38c | 10639 | cu->language = language_java; |
bebd888e | 10640 | break; |
c906108c | 10641 | case DW_LANG_Ada83: |
8aaf0b47 | 10642 | case DW_LANG_Ada95: |
bc5f45f8 JB |
10643 | cu->language = language_ada; |
10644 | break; | |
72019c9c GM |
10645 | case DW_LANG_Modula2: |
10646 | cu->language = language_m2; | |
10647 | break; | |
fe8e67fd PM |
10648 | case DW_LANG_Pascal83: |
10649 | cu->language = language_pascal; | |
10650 | break; | |
22566fbd DJ |
10651 | case DW_LANG_ObjC: |
10652 | cu->language = language_objc; | |
10653 | break; | |
c906108c SS |
10654 | case DW_LANG_Cobol74: |
10655 | case DW_LANG_Cobol85: | |
c906108c | 10656 | default: |
e142c38c | 10657 | cu->language = language_minimal; |
c906108c SS |
10658 | break; |
10659 | } | |
e142c38c | 10660 | cu->language_defn = language_def (cu->language); |
c906108c SS |
10661 | } |
10662 | ||
10663 | /* Return the named attribute or NULL if not there. */ | |
10664 | ||
10665 | static struct attribute * | |
e142c38c | 10666 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
10667 | { |
10668 | unsigned int i; | |
10669 | struct attribute *spec = NULL; | |
10670 | ||
10671 | for (i = 0; i < die->num_attrs; ++i) | |
10672 | { | |
10673 | if (die->attrs[i].name == name) | |
10b3939b | 10674 | return &die->attrs[i]; |
c906108c SS |
10675 | if (die->attrs[i].name == DW_AT_specification |
10676 | || die->attrs[i].name == DW_AT_abstract_origin) | |
10677 | spec = &die->attrs[i]; | |
10678 | } | |
c906108c | 10679 | |
10b3939b | 10680 | if (spec) |
f2f0e013 DJ |
10681 | { |
10682 | die = follow_die_ref (die, spec, &cu); | |
10683 | return dwarf2_attr (die, name, cu); | |
10684 | } | |
c5aa993b | 10685 | |
c906108c SS |
10686 | return NULL; |
10687 | } | |
10688 | ||
348e048f DE |
10689 | /* Return the named attribute or NULL if not there, |
10690 | but do not follow DW_AT_specification, etc. | |
10691 | This is for use in contexts where we're reading .debug_types dies. | |
10692 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
10693 | back up the chain, and we want to go down. */ | |
10694 | ||
10695 | static struct attribute * | |
10696 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
10697 | struct dwarf2_cu *cu) | |
10698 | { | |
10699 | unsigned int i; | |
10700 | ||
10701 | for (i = 0; i < die->num_attrs; ++i) | |
10702 | if (die->attrs[i].name == name) | |
10703 | return &die->attrs[i]; | |
10704 | ||
10705 | return NULL; | |
10706 | } | |
10707 | ||
05cf31d1 JB |
10708 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
10709 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 10710 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
10711 | |
10712 | static int | |
10713 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
10714 | { | |
10715 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
10716 | ||
10717 | return (attr && DW_UNSND (attr)); | |
10718 | } | |
10719 | ||
3ca72b44 | 10720 | static int |
e142c38c | 10721 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 10722 | { |
05cf31d1 JB |
10723 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
10724 | which value is non-zero. However, we have to be careful with | |
10725 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
10726 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
10727 | end up accidently finding a declaration attribute that belongs | |
10728 | to a different DIE referenced by the specification attribute, | |
10729 | even though the given DIE does not have a declaration attribute. */ | |
10730 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
10731 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
10732 | } |
10733 | ||
63d06c5c | 10734 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 10735 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
10736 | containing the return value on output. If there is no |
10737 | specification, but there is an abstract origin, that is | |
10738 | returned. */ | |
63d06c5c DC |
10739 | |
10740 | static struct die_info * | |
f2f0e013 | 10741 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 10742 | { |
f2f0e013 DJ |
10743 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
10744 | *spec_cu); | |
63d06c5c | 10745 | |
edb3359d DJ |
10746 | if (spec_attr == NULL) |
10747 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
10748 | ||
63d06c5c DC |
10749 | if (spec_attr == NULL) |
10750 | return NULL; | |
10751 | else | |
f2f0e013 | 10752 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 10753 | } |
c906108c | 10754 | |
debd256d | 10755 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
10756 | refers to. |
10757 | NOTE: This is also used as a "cleanup" function. */ | |
10758 | ||
debd256d JB |
10759 | static void |
10760 | free_line_header (struct line_header *lh) | |
10761 | { | |
10762 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 10763 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
10764 | |
10765 | /* Remember that all the lh->file_names[i].name pointers are | |
10766 | pointers into debug_line_buffer, and don't need to be freed. */ | |
10767 | if (lh->file_names) | |
a8bc7b56 | 10768 | xfree (lh->file_names); |
debd256d JB |
10769 | |
10770 | /* Similarly for the include directory names. */ | |
10771 | if (lh->include_dirs) | |
a8bc7b56 | 10772 | xfree (lh->include_dirs); |
debd256d | 10773 | |
a8bc7b56 | 10774 | xfree (lh); |
debd256d JB |
10775 | } |
10776 | ||
debd256d | 10777 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 10778 | |
debd256d JB |
10779 | static void |
10780 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 10781 | { |
debd256d JB |
10782 | /* Grow the array if necessary. */ |
10783 | if (lh->include_dirs_size == 0) | |
c5aa993b | 10784 | { |
debd256d JB |
10785 | lh->include_dirs_size = 1; /* for testing */ |
10786 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
10787 | * sizeof (*lh->include_dirs)); | |
10788 | } | |
10789 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
10790 | { | |
10791 | lh->include_dirs_size *= 2; | |
10792 | lh->include_dirs = xrealloc (lh->include_dirs, | |
10793 | (lh->include_dirs_size | |
10794 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 10795 | } |
c906108c | 10796 | |
debd256d JB |
10797 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
10798 | } | |
6e70227d | 10799 | |
debd256d | 10800 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 10801 | |
debd256d JB |
10802 | static void |
10803 | add_file_name (struct line_header *lh, | |
10804 | char *name, | |
10805 | unsigned int dir_index, | |
10806 | unsigned int mod_time, | |
10807 | unsigned int length) | |
10808 | { | |
10809 | struct file_entry *fe; | |
10810 | ||
10811 | /* Grow the array if necessary. */ | |
10812 | if (lh->file_names_size == 0) | |
10813 | { | |
10814 | lh->file_names_size = 1; /* for testing */ | |
10815 | lh->file_names = xmalloc (lh->file_names_size | |
10816 | * sizeof (*lh->file_names)); | |
10817 | } | |
10818 | else if (lh->num_file_names >= lh->file_names_size) | |
10819 | { | |
10820 | lh->file_names_size *= 2; | |
10821 | lh->file_names = xrealloc (lh->file_names, | |
10822 | (lh->file_names_size | |
10823 | * sizeof (*lh->file_names))); | |
10824 | } | |
10825 | ||
10826 | fe = &lh->file_names[lh->num_file_names++]; | |
10827 | fe->name = name; | |
10828 | fe->dir_index = dir_index; | |
10829 | fe->mod_time = mod_time; | |
10830 | fe->length = length; | |
aaa75496 | 10831 | fe->included_p = 0; |
cb1df416 | 10832 | fe->symtab = NULL; |
debd256d | 10833 | } |
6e70227d | 10834 | |
debd256d | 10835 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
10836 | .debug_line, according to the endianness of ABFD. Return a pointer |
10837 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
10838 | |
10839 | NOTE: the strings in the include directory and file name tables of | |
10840 | the returned object point into debug_line_buffer, and must not be | |
10841 | freed. */ | |
ae2de4f8 | 10842 | |
debd256d JB |
10843 | static struct line_header * |
10844 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 10845 | struct dwarf2_cu *cu) |
debd256d JB |
10846 | { |
10847 | struct cleanup *back_to; | |
10848 | struct line_header *lh; | |
fe1b8b76 | 10849 | gdb_byte *line_ptr; |
c764a876 | 10850 | unsigned int bytes_read, offset_size; |
debd256d JB |
10851 | int i; |
10852 | char *cur_dir, *cur_file; | |
10853 | ||
be391dca | 10854 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 10855 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 10856 | { |
e2e0b3e5 | 10857 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
10858 | return 0; |
10859 | } | |
10860 | ||
a738430d MK |
10861 | /* Make sure that at least there's room for the total_length field. |
10862 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 10863 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 10864 | { |
4d3c2250 | 10865 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10866 | return 0; |
10867 | } | |
10868 | ||
10869 | lh = xmalloc (sizeof (*lh)); | |
10870 | memset (lh, 0, sizeof (*lh)); | |
10871 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
10872 | (void *) lh); | |
10873 | ||
dce234bc | 10874 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 10875 | |
a738430d | 10876 | /* Read in the header. */ |
6e70227d | 10877 | lh->total_length = |
c764a876 DE |
10878 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
10879 | &bytes_read, &offset_size); | |
debd256d | 10880 | line_ptr += bytes_read; |
dce234bc PP |
10881 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
10882 | + dwarf2_per_objfile->line.size)) | |
debd256d | 10883 | { |
4d3c2250 | 10884 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10885 | return 0; |
10886 | } | |
10887 | lh->statement_program_end = line_ptr + lh->total_length; | |
10888 | lh->version = read_2_bytes (abfd, line_ptr); | |
10889 | line_ptr += 2; | |
c764a876 DE |
10890 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
10891 | line_ptr += offset_size; | |
debd256d JB |
10892 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
10893 | line_ptr += 1; | |
2dc7f7b3 TT |
10894 | if (lh->version >= 4) |
10895 | { | |
10896 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
10897 | line_ptr += 1; | |
10898 | } | |
10899 | else | |
10900 | lh->maximum_ops_per_instruction = 1; | |
10901 | ||
10902 | if (lh->maximum_ops_per_instruction == 0) | |
10903 | { | |
10904 | lh->maximum_ops_per_instruction = 1; | |
10905 | complaint (&symfile_complaints, | |
3e43a32a MS |
10906 | _("invalid maximum_ops_per_instruction " |
10907 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
10908 | } |
10909 | ||
debd256d JB |
10910 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
10911 | line_ptr += 1; | |
10912 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
10913 | line_ptr += 1; | |
10914 | lh->line_range = read_1_byte (abfd, line_ptr); | |
10915 | line_ptr += 1; | |
10916 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
10917 | line_ptr += 1; | |
10918 | lh->standard_opcode_lengths | |
fe1b8b76 | 10919 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
10920 | |
10921 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
10922 | for (i = 1; i < lh->opcode_base; ++i) | |
10923 | { | |
10924 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
10925 | line_ptr += 1; | |
10926 | } | |
10927 | ||
a738430d | 10928 | /* Read directory table. */ |
9b1c24c8 | 10929 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10930 | { |
10931 | line_ptr += bytes_read; | |
10932 | add_include_dir (lh, cur_dir); | |
10933 | } | |
10934 | line_ptr += bytes_read; | |
10935 | ||
a738430d | 10936 | /* Read file name table. */ |
9b1c24c8 | 10937 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10938 | { |
10939 | unsigned int dir_index, mod_time, length; | |
10940 | ||
10941 | line_ptr += bytes_read; | |
10942 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10943 | line_ptr += bytes_read; | |
10944 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10945 | line_ptr += bytes_read; | |
10946 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10947 | line_ptr += bytes_read; | |
10948 | ||
10949 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10950 | } | |
10951 | line_ptr += bytes_read; | |
6e70227d | 10952 | lh->statement_program_start = line_ptr; |
debd256d | 10953 | |
dce234bc PP |
10954 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
10955 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 10956 | complaint (&symfile_complaints, |
3e43a32a MS |
10957 | _("line number info header doesn't " |
10958 | "fit in `.debug_line' section")); | |
debd256d JB |
10959 | |
10960 | discard_cleanups (back_to); | |
10961 | return lh; | |
10962 | } | |
c906108c | 10963 | |
5fb290d7 DJ |
10964 | /* This function exists to work around a bug in certain compilers |
10965 | (particularly GCC 2.95), in which the first line number marker of a | |
10966 | function does not show up until after the prologue, right before | |
10967 | the second line number marker. This function shifts ADDRESS down | |
10968 | to the beginning of the function if necessary, and is called on | |
10969 | addresses passed to record_line. */ | |
10970 | ||
10971 | static CORE_ADDR | |
e142c38c | 10972 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
10973 | { |
10974 | struct function_range *fn; | |
10975 | ||
10976 | /* Find the function_range containing address. */ | |
e142c38c | 10977 | if (!cu->first_fn) |
5fb290d7 DJ |
10978 | return address; |
10979 | ||
e142c38c DJ |
10980 | if (!cu->cached_fn) |
10981 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 10982 | |
e142c38c | 10983 | fn = cu->cached_fn; |
5fb290d7 DJ |
10984 | while (fn) |
10985 | if (fn->lowpc <= address && fn->highpc > address) | |
10986 | goto found; | |
10987 | else | |
10988 | fn = fn->next; | |
10989 | ||
e142c38c DJ |
10990 | fn = cu->first_fn; |
10991 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
10992 | if (fn->lowpc <= address && fn->highpc > address) |
10993 | goto found; | |
10994 | else | |
10995 | fn = fn->next; | |
10996 | ||
10997 | return address; | |
10998 | ||
10999 | found: | |
11000 | if (fn->seen_line) | |
11001 | return address; | |
11002 | if (address != fn->lowpc) | |
4d3c2250 | 11003 | complaint (&symfile_complaints, |
e2e0b3e5 | 11004 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 11005 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
11006 | fn->seen_line = 1; |
11007 | return fn->lowpc; | |
11008 | } | |
11009 | ||
c6da4cef DE |
11010 | /* Subroutine of dwarf_decode_lines to simplify it. |
11011 | Return the file name of the psymtab for included file FILE_INDEX | |
11012 | in line header LH of PST. | |
11013 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11014 | If space for the result is malloc'd, it will be freed by a cleanup. | |
11015 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
11016 | ||
11017 | static char * | |
11018 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
11019 | const struct partial_symtab *pst, | |
11020 | const char *comp_dir) | |
11021 | { | |
11022 | const struct file_entry fe = lh->file_names [file_index]; | |
11023 | char *include_name = fe.name; | |
11024 | char *include_name_to_compare = include_name; | |
11025 | char *dir_name = NULL; | |
72b9f47f TT |
11026 | const char *pst_filename; |
11027 | char *copied_name = NULL; | |
c6da4cef DE |
11028 | int file_is_pst; |
11029 | ||
11030 | if (fe.dir_index) | |
11031 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
11032 | ||
11033 | if (!IS_ABSOLUTE_PATH (include_name) | |
11034 | && (dir_name != NULL || comp_dir != NULL)) | |
11035 | { | |
11036 | /* Avoid creating a duplicate psymtab for PST. | |
11037 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
11038 | Before we do the comparison, however, we need to account | |
11039 | for DIR_NAME and COMP_DIR. | |
11040 | First prepend dir_name (if non-NULL). If we still don't | |
11041 | have an absolute path prepend comp_dir (if non-NULL). | |
11042 | However, the directory we record in the include-file's | |
11043 | psymtab does not contain COMP_DIR (to match the | |
11044 | corresponding symtab(s)). | |
11045 | ||
11046 | Example: | |
11047 | ||
11048 | bash$ cd /tmp | |
11049 | bash$ gcc -g ./hello.c | |
11050 | include_name = "hello.c" | |
11051 | dir_name = "." | |
11052 | DW_AT_comp_dir = comp_dir = "/tmp" | |
11053 | DW_AT_name = "./hello.c" */ | |
11054 | ||
11055 | if (dir_name != NULL) | |
11056 | { | |
11057 | include_name = concat (dir_name, SLASH_STRING, | |
11058 | include_name, (char *)NULL); | |
11059 | include_name_to_compare = include_name; | |
11060 | make_cleanup (xfree, include_name); | |
11061 | } | |
11062 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
11063 | { | |
11064 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
11065 | include_name, (char *)NULL); | |
11066 | } | |
11067 | } | |
11068 | ||
11069 | pst_filename = pst->filename; | |
11070 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
11071 | { | |
72b9f47f TT |
11072 | copied_name = concat (pst->dirname, SLASH_STRING, |
11073 | pst_filename, (char *)NULL); | |
11074 | pst_filename = copied_name; | |
c6da4cef DE |
11075 | } |
11076 | ||
1e3fad37 | 11077 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
11078 | |
11079 | if (include_name_to_compare != include_name) | |
11080 | xfree (include_name_to_compare); | |
72b9f47f TT |
11081 | if (copied_name != NULL) |
11082 | xfree (copied_name); | |
c6da4cef DE |
11083 | |
11084 | if (file_is_pst) | |
11085 | return NULL; | |
11086 | return include_name; | |
11087 | } | |
11088 | ||
c91513d8 PP |
11089 | /* Ignore this record_line request. */ |
11090 | ||
11091 | static void | |
11092 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
11093 | { | |
11094 | return; | |
11095 | } | |
11096 | ||
aaa75496 JB |
11097 | /* Decode the Line Number Program (LNP) for the given line_header |
11098 | structure and CU. The actual information extracted and the type | |
11099 | of structures created from the LNP depends on the value of PST. | |
11100 | ||
11101 | 1. If PST is NULL, then this procedure uses the data from the program | |
11102 | to create all necessary symbol tables, and their linetables. | |
6e70227d | 11103 | |
aaa75496 JB |
11104 | 2. If PST is not NULL, this procedure reads the program to determine |
11105 | the list of files included by the unit represented by PST, and | |
c6da4cef DE |
11106 | builds all the associated partial symbol tables. |
11107 | ||
11108 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11109 | It is used for relative paths in the line table. | |
11110 | NOTE: When processing partial symtabs (pst != NULL), | |
11111 | comp_dir == pst->dirname. | |
11112 | ||
11113 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
11114 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
11115 | symtab we don't use it in the name of the psymtabs we create. | |
11116 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
11117 | A good testcase for this is mb-inline.exp. */ | |
debd256d | 11118 | |
c906108c | 11119 | static void |
72b9f47f | 11120 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd, |
aaa75496 | 11121 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 11122 | { |
a8c50c1f | 11123 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 11124 | gdb_byte *line_end; |
a8c50c1f | 11125 | unsigned int bytes_read, extended_len; |
c906108c | 11126 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
11127 | CORE_ADDR baseaddr; |
11128 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 11129 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 11130 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 11131 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
c91513d8 PP |
11132 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
11133 | = record_line; | |
e142c38c DJ |
11134 | |
11135 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11136 | |
debd256d JB |
11137 | line_ptr = lh->statement_program_start; |
11138 | line_end = lh->statement_program_end; | |
c906108c SS |
11139 | |
11140 | /* Read the statement sequences until there's nothing left. */ | |
11141 | while (line_ptr < line_end) | |
11142 | { | |
11143 | /* state machine registers */ | |
11144 | CORE_ADDR address = 0; | |
11145 | unsigned int file = 1; | |
11146 | unsigned int line = 1; | |
11147 | unsigned int column = 0; | |
debd256d | 11148 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
11149 | int basic_block = 0; |
11150 | int end_sequence = 0; | |
fbf65064 | 11151 | CORE_ADDR addr; |
2dc7f7b3 | 11152 | unsigned char op_index = 0; |
c906108c | 11153 | |
aaa75496 | 11154 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 11155 | { |
aaa75496 | 11156 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
11157 | /* lh->include_dirs and lh->file_names are 0-based, but the |
11158 | directory and file name numbers in the statement program | |
11159 | are 1-based. */ | |
11160 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 11161 | char *dir = NULL; |
a738430d | 11162 | |
debd256d JB |
11163 | if (fe->dir_index) |
11164 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
11165 | |
11166 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
11167 | } |
11168 | ||
a738430d | 11169 | /* Decode the table. */ |
c5aa993b | 11170 | while (!end_sequence) |
c906108c SS |
11171 | { |
11172 | op_code = read_1_byte (abfd, line_ptr); | |
11173 | line_ptr += 1; | |
59205f5a JB |
11174 | if (line_ptr > line_end) |
11175 | { | |
11176 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
11177 | break; | |
11178 | } | |
9aa1fe7e | 11179 | |
debd256d | 11180 | if (op_code >= lh->opcode_base) |
6e70227d | 11181 | { |
a738430d | 11182 | /* Special operand. */ |
debd256d | 11183 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
11184 | address += (((op_index + (adj_opcode / lh->line_range)) |
11185 | / lh->maximum_ops_per_instruction) | |
11186 | * lh->minimum_instruction_length); | |
11187 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
11188 | % lh->maximum_ops_per_instruction); | |
debd256d | 11189 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 11190 | if (lh->num_file_names < file || file == 0) |
25e43795 | 11191 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
11192 | /* For now we ignore lines not starting on an |
11193 | instruction boundary. */ | |
11194 | else if (op_index == 0) | |
25e43795 DJ |
11195 | { |
11196 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 11197 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11198 | { |
11199 | if (last_subfile != current_subfile) | |
11200 | { | |
11201 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11202 | if (last_subfile) | |
c91513d8 | 11203 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11204 | last_subfile = current_subfile; |
11205 | } | |
25e43795 | 11206 | /* Append row to matrix using current values. */ |
fbf65064 UW |
11207 | addr = check_cu_functions (address, cu); |
11208 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
c91513d8 | 11209 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 11210 | } |
25e43795 | 11211 | } |
ca5f395d | 11212 | basic_block = 0; |
9aa1fe7e GK |
11213 | } |
11214 | else switch (op_code) | |
c906108c SS |
11215 | { |
11216 | case DW_LNS_extended_op: | |
3e43a32a MS |
11217 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
11218 | &bytes_read); | |
473b7be6 | 11219 | line_ptr += bytes_read; |
a8c50c1f | 11220 | extended_end = line_ptr + extended_len; |
c906108c SS |
11221 | extended_op = read_1_byte (abfd, line_ptr); |
11222 | line_ptr += 1; | |
11223 | switch (extended_op) | |
11224 | { | |
11225 | case DW_LNE_end_sequence: | |
c91513d8 | 11226 | p_record_line = record_line; |
c906108c | 11227 | end_sequence = 1; |
c906108c SS |
11228 | break; |
11229 | case DW_LNE_set_address: | |
e7c27a73 | 11230 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
11231 | |
11232 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11233 | { | |
11234 | /* This line table is for a function which has been | |
11235 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
11236 | ||
11237 | long line_offset | |
11238 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
11239 | ||
11240 | complaint (&symfile_complaints, | |
11241 | _(".debug_line address at offset 0x%lx is 0 " | |
11242 | "[in module %s]"), | |
11243 | line_offset, cu->objfile->name); | |
11244 | p_record_line = noop_record_line; | |
11245 | } | |
11246 | ||
2dc7f7b3 | 11247 | op_index = 0; |
107d2387 AC |
11248 | line_ptr += bytes_read; |
11249 | address += baseaddr; | |
c906108c SS |
11250 | break; |
11251 | case DW_LNE_define_file: | |
debd256d JB |
11252 | { |
11253 | char *cur_file; | |
11254 | unsigned int dir_index, mod_time, length; | |
6e70227d | 11255 | |
3e43a32a MS |
11256 | cur_file = read_direct_string (abfd, line_ptr, |
11257 | &bytes_read); | |
debd256d JB |
11258 | line_ptr += bytes_read; |
11259 | dir_index = | |
11260 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11261 | line_ptr += bytes_read; | |
11262 | mod_time = | |
11263 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11264 | line_ptr += bytes_read; | |
11265 | length = | |
11266 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11267 | line_ptr += bytes_read; | |
11268 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
11269 | } | |
c906108c | 11270 | break; |
d0c6ba3d CC |
11271 | case DW_LNE_set_discriminator: |
11272 | /* The discriminator is not interesting to the debugger; | |
11273 | just ignore it. */ | |
11274 | line_ptr = extended_end; | |
11275 | break; | |
c906108c | 11276 | default: |
4d3c2250 | 11277 | complaint (&symfile_complaints, |
e2e0b3e5 | 11278 | _("mangled .debug_line section")); |
debd256d | 11279 | return; |
c906108c | 11280 | } |
a8c50c1f DJ |
11281 | /* Make sure that we parsed the extended op correctly. If e.g. |
11282 | we expected a different address size than the producer used, | |
11283 | we may have read the wrong number of bytes. */ | |
11284 | if (line_ptr != extended_end) | |
11285 | { | |
11286 | complaint (&symfile_complaints, | |
11287 | _("mangled .debug_line section")); | |
11288 | return; | |
11289 | } | |
c906108c SS |
11290 | break; |
11291 | case DW_LNS_copy: | |
59205f5a | 11292 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11293 | dwarf2_debug_line_missing_file_complaint (); |
11294 | else | |
366da635 | 11295 | { |
25e43795 | 11296 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 11297 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11298 | { |
11299 | if (last_subfile != current_subfile) | |
11300 | { | |
11301 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11302 | if (last_subfile) | |
c91513d8 | 11303 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11304 | last_subfile = current_subfile; |
11305 | } | |
11306 | addr = check_cu_functions (address, cu); | |
11307 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
c91513d8 | 11308 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 11309 | } |
366da635 | 11310 | } |
c906108c SS |
11311 | basic_block = 0; |
11312 | break; | |
11313 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
11314 | { |
11315 | CORE_ADDR adjust | |
11316 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11317 | ||
11318 | address += (((op_index + adjust) | |
11319 | / lh->maximum_ops_per_instruction) | |
11320 | * lh->minimum_instruction_length); | |
11321 | op_index = ((op_index + adjust) | |
11322 | % lh->maximum_ops_per_instruction); | |
11323 | line_ptr += bytes_read; | |
11324 | } | |
c906108c SS |
11325 | break; |
11326 | case DW_LNS_advance_line: | |
11327 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
11328 | line_ptr += bytes_read; | |
11329 | break; | |
11330 | case DW_LNS_set_file: | |
debd256d | 11331 | { |
a738430d MK |
11332 | /* The arrays lh->include_dirs and lh->file_names are |
11333 | 0-based, but the directory and file name numbers in | |
11334 | the statement program are 1-based. */ | |
debd256d | 11335 | struct file_entry *fe; |
4f1520fb | 11336 | char *dir = NULL; |
a738430d | 11337 | |
debd256d JB |
11338 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
11339 | line_ptr += bytes_read; | |
59205f5a | 11340 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11341 | dwarf2_debug_line_missing_file_complaint (); |
11342 | else | |
11343 | { | |
11344 | fe = &lh->file_names[file - 1]; | |
11345 | if (fe->dir_index) | |
11346 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11347 | if (!decode_for_pst_p) | |
11348 | { | |
11349 | last_subfile = current_subfile; | |
11350 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11351 | } | |
11352 | } | |
debd256d | 11353 | } |
c906108c SS |
11354 | break; |
11355 | case DW_LNS_set_column: | |
11356 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11357 | line_ptr += bytes_read; | |
11358 | break; | |
11359 | case DW_LNS_negate_stmt: | |
11360 | is_stmt = (!is_stmt); | |
11361 | break; | |
11362 | case DW_LNS_set_basic_block: | |
11363 | basic_block = 1; | |
11364 | break; | |
c2c6d25f JM |
11365 | /* Add to the address register of the state machine the |
11366 | address increment value corresponding to special opcode | |
a738430d MK |
11367 | 255. I.e., this value is scaled by the minimum |
11368 | instruction length since special opcode 255 would have | |
b021a221 | 11369 | scaled the increment. */ |
c906108c | 11370 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
11371 | { |
11372 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
11373 | ||
11374 | address += (((op_index + adjust) | |
11375 | / lh->maximum_ops_per_instruction) | |
11376 | * lh->minimum_instruction_length); | |
11377 | op_index = ((op_index + adjust) | |
11378 | % lh->maximum_ops_per_instruction); | |
11379 | } | |
c906108c SS |
11380 | break; |
11381 | case DW_LNS_fixed_advance_pc: | |
11382 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 11383 | op_index = 0; |
c906108c SS |
11384 | line_ptr += 2; |
11385 | break; | |
9aa1fe7e | 11386 | default: |
a738430d MK |
11387 | { |
11388 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 11389 | int i; |
a738430d | 11390 | |
debd256d | 11391 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
11392 | { |
11393 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11394 | line_ptr += bytes_read; | |
11395 | } | |
11396 | } | |
c906108c SS |
11397 | } |
11398 | } | |
59205f5a JB |
11399 | if (lh->num_file_names < file || file == 0) |
11400 | dwarf2_debug_line_missing_file_complaint (); | |
11401 | else | |
11402 | { | |
11403 | lh->file_names[file - 1].included_p = 1; | |
11404 | if (!decode_for_pst_p) | |
fbf65064 UW |
11405 | { |
11406 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 11407 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 11408 | } |
59205f5a | 11409 | } |
c906108c | 11410 | } |
aaa75496 JB |
11411 | |
11412 | if (decode_for_pst_p) | |
11413 | { | |
11414 | int file_index; | |
11415 | ||
11416 | /* Now that we're done scanning the Line Header Program, we can | |
11417 | create the psymtab of each included file. */ | |
11418 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
11419 | if (lh->file_names[file_index].included_p == 1) | |
11420 | { | |
c6da4cef DE |
11421 | char *include_name = |
11422 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
11423 | if (include_name != NULL) | |
aaa75496 JB |
11424 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
11425 | } | |
11426 | } | |
cb1df416 DJ |
11427 | else |
11428 | { | |
11429 | /* Make sure a symtab is created for every file, even files | |
11430 | which contain only variables (i.e. no code with associated | |
11431 | line numbers). */ | |
11432 | ||
11433 | int i; | |
11434 | struct file_entry *fe; | |
11435 | ||
11436 | for (i = 0; i < lh->num_file_names; i++) | |
11437 | { | |
11438 | char *dir = NULL; | |
9a619af0 | 11439 | |
cb1df416 DJ |
11440 | fe = &lh->file_names[i]; |
11441 | if (fe->dir_index) | |
11442 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11443 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11444 | ||
11445 | /* Skip the main file; we don't need it, and it must be | |
11446 | allocated last, so that it will show up before the | |
11447 | non-primary symtabs in the objfile's symtab list. */ | |
11448 | if (current_subfile == first_subfile) | |
11449 | continue; | |
11450 | ||
11451 | if (current_subfile->symtab == NULL) | |
11452 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
11453 | cu->objfile); | |
11454 | fe->symtab = current_subfile->symtab; | |
11455 | } | |
11456 | } | |
c906108c SS |
11457 | } |
11458 | ||
11459 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
11460 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
11461 | or NULL if not known. COMP_DIR is the compilation directory for the |
11462 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
11463 | This routine tries to keep line numbers from identical absolute and |
11464 | relative file names in a common subfile. | |
11465 | ||
11466 | Using the `list' example from the GDB testsuite, which resides in | |
11467 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
11468 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
11469 | ||
c5aa993b JM |
11470 | DW_AT_name: /srcdir/list0.c |
11471 | DW_AT_comp_dir: /compdir | |
357e46e7 | 11472 | files.files[0].name: list0.h |
c5aa993b | 11473 | files.files[0].dir: /srcdir |
357e46e7 | 11474 | files.files[1].name: list0.c |
c5aa993b | 11475 | files.files[1].dir: /srcdir |
c906108c SS |
11476 | |
11477 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
11478 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
11479 | start_subfile will ensure that this happens provided that we pass the | |
11480 | concatenation of files.files[1].dir and files.files[1].name as the | |
11481 | subfile's name. */ | |
c906108c SS |
11482 | |
11483 | static void | |
3e43a32a MS |
11484 | dwarf2_start_subfile (char *filename, const char *dirname, |
11485 | const char *comp_dir) | |
c906108c | 11486 | { |
4f1520fb FR |
11487 | char *fullname; |
11488 | ||
11489 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
11490 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
11491 | second argument to start_subfile. To be consistent, we do the | |
11492 | same here. In order not to lose the line information directory, | |
11493 | we concatenate it to the filename when it makes sense. | |
11494 | Note that the Dwarf3 standard says (speaking of filenames in line | |
11495 | information): ``The directory index is ignored for file names | |
11496 | that represent full path names''. Thus ignoring dirname in the | |
11497 | `else' branch below isn't an issue. */ | |
c906108c | 11498 | |
d5166ae1 | 11499 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
11500 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
11501 | else | |
11502 | fullname = filename; | |
c906108c | 11503 | |
4f1520fb FR |
11504 | start_subfile (fullname, comp_dir); |
11505 | ||
11506 | if (fullname != filename) | |
11507 | xfree (fullname); | |
c906108c SS |
11508 | } |
11509 | ||
4c2df51b DJ |
11510 | static void |
11511 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11512 | struct dwarf2_cu *cu) |
4c2df51b | 11513 | { |
e7c27a73 DJ |
11514 | struct objfile *objfile = cu->objfile; |
11515 | struct comp_unit_head *cu_header = &cu->header; | |
11516 | ||
4c2df51b DJ |
11517 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
11518 | code here to turn a symbol with DW_AT_external and a | |
11519 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
11520 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
11521 | with some versions of binutils) where shared libraries could have | |
11522 | relocations against symbols in their debug information - the | |
11523 | minimal symbol would have the right address, but the debug info | |
11524 | would not. It's no longer necessary, because we will explicitly | |
11525 | apply relocations when we read in the debug information now. */ | |
11526 | ||
11527 | /* A DW_AT_location attribute with no contents indicates that a | |
11528 | variable has been optimized away. */ | |
11529 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
11530 | { | |
11531 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
11532 | return; | |
11533 | } | |
11534 | ||
11535 | /* Handle one degenerate form of location expression specially, to | |
11536 | preserve GDB's previous behavior when section offsets are | |
11537 | specified. If this is just a DW_OP_addr then mark this symbol | |
11538 | as LOC_STATIC. */ | |
11539 | ||
11540 | if (attr_form_is_block (attr) | |
11541 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
11542 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
11543 | { | |
891d2f0b | 11544 | unsigned int dummy; |
4c2df51b DJ |
11545 | |
11546 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 11547 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 11548 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
11549 | fixup_symbol_section (sym, objfile); |
11550 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
11551 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
11552 | return; |
11553 | } | |
11554 | ||
11555 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
11556 | expression evaluator, and use LOC_COMPUTED only when necessary | |
11557 | (i.e. when the value of a register or memory location is | |
11558 | referenced, or a thread-local block, etc.). Then again, it might | |
11559 | not be worthwhile. I'm assuming that it isn't unless performance | |
11560 | or memory numbers show me otherwise. */ | |
11561 | ||
e7c27a73 | 11562 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 11563 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
11564 | |
11565 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
11566 | cu->has_loclist = 1; | |
4c2df51b DJ |
11567 | } |
11568 | ||
c906108c SS |
11569 | /* Given a pointer to a DWARF information entry, figure out if we need |
11570 | to make a symbol table entry for it, and if so, create a new entry | |
11571 | and return a pointer to it. | |
11572 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
11573 | used the passed type. |
11574 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
11575 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
11576 | |
11577 | static struct symbol * | |
34eaf542 TT |
11578 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
11579 | struct symbol *space) | |
c906108c | 11580 | { |
e7c27a73 | 11581 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11582 | struct symbol *sym = NULL; |
11583 | char *name; | |
11584 | struct attribute *attr = NULL; | |
11585 | struct attribute *attr2 = NULL; | |
e142c38c | 11586 | CORE_ADDR baseaddr; |
e37fd15a SW |
11587 | struct pending **list_to_add = NULL; |
11588 | ||
edb3359d | 11589 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
11590 | |
11591 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11592 | |
94af9270 | 11593 | name = dwarf2_name (die, cu); |
c906108c SS |
11594 | if (name) |
11595 | { | |
94af9270 | 11596 | const char *linkagename; |
34eaf542 | 11597 | int suppress_add = 0; |
94af9270 | 11598 | |
34eaf542 TT |
11599 | if (space) |
11600 | sym = space; | |
11601 | else | |
11602 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 11603 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
11604 | |
11605 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 11606 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
11607 | linkagename = dwarf2_physname (name, die, cu); |
11608 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 11609 | |
f55ee35c JK |
11610 | /* Fortran does not have mangling standard and the mangling does differ |
11611 | between gfortran, iFort etc. */ | |
11612 | if (cu->language == language_fortran | |
b250c185 | 11613 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
11614 | symbol_set_demangled_name (&(sym->ginfo), |
11615 | (char *) dwarf2_full_name (name, die, cu), | |
11616 | NULL); | |
f55ee35c | 11617 | |
c906108c | 11618 | /* Default assumptions. |
c5aa993b | 11619 | Use the passed type or decode it from the die. */ |
176620f1 | 11620 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 11621 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
11622 | if (type != NULL) |
11623 | SYMBOL_TYPE (sym) = type; | |
11624 | else | |
e7c27a73 | 11625 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
11626 | attr = dwarf2_attr (die, |
11627 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
11628 | cu); | |
c906108c SS |
11629 | if (attr) |
11630 | { | |
11631 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
11632 | } | |
cb1df416 | 11633 | |
edb3359d DJ |
11634 | attr = dwarf2_attr (die, |
11635 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
11636 | cu); | |
cb1df416 DJ |
11637 | if (attr) |
11638 | { | |
11639 | int file_index = DW_UNSND (attr); | |
9a619af0 | 11640 | |
cb1df416 DJ |
11641 | if (cu->line_header == NULL |
11642 | || file_index > cu->line_header->num_file_names) | |
11643 | complaint (&symfile_complaints, | |
11644 | _("file index out of range")); | |
1c3d648d | 11645 | else if (file_index > 0) |
cb1df416 DJ |
11646 | { |
11647 | struct file_entry *fe; | |
9a619af0 | 11648 | |
cb1df416 DJ |
11649 | fe = &cu->line_header->file_names[file_index - 1]; |
11650 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
11651 | } | |
11652 | } | |
11653 | ||
c906108c SS |
11654 | switch (die->tag) |
11655 | { | |
11656 | case DW_TAG_label: | |
e142c38c | 11657 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
11658 | if (attr) |
11659 | { | |
11660 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
11661 | } | |
0f5238ed TT |
11662 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
11663 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 11664 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 11665 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
11666 | break; |
11667 | case DW_TAG_subprogram: | |
11668 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11669 | finish_block. */ | |
11670 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 11671 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
11672 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
11673 | || cu->language == language_ada) | |
c906108c | 11674 | { |
2cfa0c8d JB |
11675 | /* Subprograms marked external are stored as a global symbol. |
11676 | Ada subprograms, whether marked external or not, are always | |
11677 | stored as a global symbol, because we want to be able to | |
11678 | access them globally. For instance, we want to be able | |
11679 | to break on a nested subprogram without having to | |
11680 | specify the context. */ | |
e37fd15a | 11681 | list_to_add = &global_symbols; |
c906108c SS |
11682 | } |
11683 | else | |
11684 | { | |
e37fd15a | 11685 | list_to_add = cu->list_in_scope; |
c906108c SS |
11686 | } |
11687 | break; | |
edb3359d DJ |
11688 | case DW_TAG_inlined_subroutine: |
11689 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11690 | finish_block. */ | |
11691 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11692 | SYMBOL_INLINED (sym) = 1; | |
11693 | /* Do not add the symbol to any lists. It will be found via | |
11694 | BLOCK_FUNCTION from the blockvector. */ | |
11695 | break; | |
34eaf542 TT |
11696 | case DW_TAG_template_value_param: |
11697 | suppress_add = 1; | |
11698 | /* Fall through. */ | |
72929c62 | 11699 | case DW_TAG_constant: |
c906108c | 11700 | case DW_TAG_variable: |
254e6b9e | 11701 | case DW_TAG_member: |
0963b4bd MS |
11702 | /* Compilation with minimal debug info may result in |
11703 | variables with missing type entries. Change the | |
11704 | misleading `void' type to something sensible. */ | |
c906108c | 11705 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 11706 | SYMBOL_TYPE (sym) |
46bf5051 | 11707 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 11708 | |
e142c38c | 11709 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
11710 | /* In the case of DW_TAG_member, we should only be called for |
11711 | static const members. */ | |
11712 | if (die->tag == DW_TAG_member) | |
11713 | { | |
3863f96c DE |
11714 | /* dwarf2_add_field uses die_is_declaration, |
11715 | so we do the same. */ | |
254e6b9e DE |
11716 | gdb_assert (die_is_declaration (die, cu)); |
11717 | gdb_assert (attr); | |
11718 | } | |
c906108c SS |
11719 | if (attr) |
11720 | { | |
e7c27a73 | 11721 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 11722 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 11723 | if (!suppress_add) |
34eaf542 TT |
11724 | { |
11725 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 11726 | list_to_add = &global_symbols; |
34eaf542 | 11727 | else |
e37fd15a | 11728 | list_to_add = cu->list_in_scope; |
34eaf542 | 11729 | } |
c906108c SS |
11730 | break; |
11731 | } | |
e142c38c | 11732 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11733 | if (attr) |
11734 | { | |
e7c27a73 | 11735 | var_decode_location (attr, sym, cu); |
e142c38c | 11736 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
11737 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
11738 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
11739 | && !dwarf2_per_objfile->has_section_at_zero) | |
11740 | { | |
11741 | /* When a static variable is eliminated by the linker, | |
11742 | the corresponding debug information is not stripped | |
11743 | out, but the variable address is set to null; | |
11744 | do not add such variables into symbol table. */ | |
11745 | } | |
11746 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 11747 | { |
f55ee35c JK |
11748 | /* Workaround gfortran PR debug/40040 - it uses |
11749 | DW_AT_location for variables in -fPIC libraries which may | |
11750 | get overriden by other libraries/executable and get | |
11751 | a different address. Resolve it by the minimal symbol | |
11752 | which may come from inferior's executable using copy | |
11753 | relocation. Make this workaround only for gfortran as for | |
11754 | other compilers GDB cannot guess the minimal symbol | |
11755 | Fortran mangling kind. */ | |
11756 | if (cu->language == language_fortran && die->parent | |
11757 | && die->parent->tag == DW_TAG_module | |
11758 | && cu->producer | |
11759 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
11760 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
11761 | ||
1c809c68 TT |
11762 | /* A variable with DW_AT_external is never static, |
11763 | but it may be block-scoped. */ | |
11764 | list_to_add = (cu->list_in_scope == &file_symbols | |
11765 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 11766 | } |
c906108c | 11767 | else |
e37fd15a | 11768 | list_to_add = cu->list_in_scope; |
c906108c SS |
11769 | } |
11770 | else | |
11771 | { | |
11772 | /* We do not know the address of this symbol. | |
c5aa993b JM |
11773 | If it is an external symbol and we have type information |
11774 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
11775 | The address of the variable will then be determined from | |
11776 | the minimal symbol table whenever the variable is | |
11777 | referenced. */ | |
e142c38c | 11778 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 11779 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 11780 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 11781 | { |
0fe7935b DJ |
11782 | /* A variable with DW_AT_external is never static, but it |
11783 | may be block-scoped. */ | |
11784 | list_to_add = (cu->list_in_scope == &file_symbols | |
11785 | ? &global_symbols : cu->list_in_scope); | |
11786 | ||
c906108c | 11787 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 11788 | } |
442ddf59 JK |
11789 | else if (!die_is_declaration (die, cu)) |
11790 | { | |
11791 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
11792 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
11793 | if (!suppress_add) |
11794 | list_to_add = cu->list_in_scope; | |
442ddf59 | 11795 | } |
c906108c SS |
11796 | } |
11797 | break; | |
11798 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
11799 | /* If we are inside a function, mark this as an argument. If |
11800 | not, we might be looking at an argument to an inlined function | |
11801 | when we do not have enough information to show inlined frames; | |
11802 | pretend it's a local variable in that case so that the user can | |
11803 | still see it. */ | |
11804 | if (context_stack_depth > 0 | |
11805 | && context_stack[context_stack_depth - 1].name != NULL) | |
11806 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 11807 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11808 | if (attr) |
11809 | { | |
e7c27a73 | 11810 | var_decode_location (attr, sym, cu); |
c906108c | 11811 | } |
e142c38c | 11812 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11813 | if (attr) |
11814 | { | |
e7c27a73 | 11815 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11816 | } |
f346a30d | 11817 | |
e37fd15a | 11818 | list_to_add = cu->list_in_scope; |
c906108c SS |
11819 | break; |
11820 | case DW_TAG_unspecified_parameters: | |
11821 | /* From varargs functions; gdb doesn't seem to have any | |
11822 | interest in this information, so just ignore it for now. | |
11823 | (FIXME?) */ | |
11824 | break; | |
34eaf542 TT |
11825 | case DW_TAG_template_type_param: |
11826 | suppress_add = 1; | |
11827 | /* Fall through. */ | |
c906108c | 11828 | case DW_TAG_class_type: |
680b30c7 | 11829 | case DW_TAG_interface_type: |
c906108c SS |
11830 | case DW_TAG_structure_type: |
11831 | case DW_TAG_union_type: | |
72019c9c | 11832 | case DW_TAG_set_type: |
c906108c SS |
11833 | case DW_TAG_enumeration_type: |
11834 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 11835 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 11836 | |
63d06c5c | 11837 | { |
987504bb | 11838 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
11839 | really ever be static objects: otherwise, if you try |
11840 | to, say, break of a class's method and you're in a file | |
11841 | which doesn't mention that class, it won't work unless | |
11842 | the check for all static symbols in lookup_symbol_aux | |
11843 | saves you. See the OtherFileClass tests in | |
11844 | gdb.c++/namespace.exp. */ | |
11845 | ||
e37fd15a | 11846 | if (!suppress_add) |
34eaf542 | 11847 | { |
34eaf542 TT |
11848 | list_to_add = (cu->list_in_scope == &file_symbols |
11849 | && (cu->language == language_cplus | |
11850 | || cu->language == language_java) | |
11851 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 11852 | |
64382290 TT |
11853 | /* The semantics of C++ state that "struct foo { |
11854 | ... }" also defines a typedef for "foo". A Java | |
11855 | class declaration also defines a typedef for the | |
11856 | class. */ | |
11857 | if (cu->language == language_cplus | |
11858 | || cu->language == language_java | |
11859 | || cu->language == language_ada) | |
11860 | { | |
11861 | /* The symbol's name is already allocated along | |
11862 | with this objfile, so we don't need to | |
11863 | duplicate it for the type. */ | |
11864 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
11865 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
11866 | } | |
63d06c5c DC |
11867 | } |
11868 | } | |
c906108c SS |
11869 | break; |
11870 | case DW_TAG_typedef: | |
63d06c5c DC |
11871 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
11872 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 11873 | list_to_add = cu->list_in_scope; |
63d06c5c | 11874 | break; |
c906108c | 11875 | case DW_TAG_base_type: |
a02abb62 | 11876 | case DW_TAG_subrange_type: |
c906108c | 11877 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 11878 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 11879 | list_to_add = cu->list_in_scope; |
c906108c SS |
11880 | break; |
11881 | case DW_TAG_enumerator: | |
e142c38c | 11882 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11883 | if (attr) |
11884 | { | |
e7c27a73 | 11885 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11886 | } |
63d06c5c DC |
11887 | { |
11888 | /* NOTE: carlton/2003-11-10: See comment above in the | |
11889 | DW_TAG_class_type, etc. block. */ | |
11890 | ||
e142c38c | 11891 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
11892 | && (cu->language == language_cplus |
11893 | || cu->language == language_java) | |
e142c38c | 11894 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 11895 | } |
c906108c | 11896 | break; |
5c4e30ca DC |
11897 | case DW_TAG_namespace: |
11898 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 11899 | list_to_add = &global_symbols; |
5c4e30ca | 11900 | break; |
c906108c SS |
11901 | default: |
11902 | /* Not a tag we recognize. Hopefully we aren't processing | |
11903 | trash data, but since we must specifically ignore things | |
11904 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 11905 | this point. */ |
e2e0b3e5 | 11906 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 11907 | dwarf_tag_name (die->tag)); |
c906108c SS |
11908 | break; |
11909 | } | |
df8a16a1 | 11910 | |
e37fd15a SW |
11911 | if (suppress_add) |
11912 | { | |
11913 | sym->hash_next = objfile->template_symbols; | |
11914 | objfile->template_symbols = sym; | |
11915 | list_to_add = NULL; | |
11916 | } | |
11917 | ||
11918 | if (list_to_add != NULL) | |
11919 | add_symbol_to_list (sym, list_to_add); | |
11920 | ||
df8a16a1 DJ |
11921 | /* For the benefit of old versions of GCC, check for anonymous |
11922 | namespaces based on the demangled name. */ | |
11923 | if (!processing_has_namespace_info | |
94af9270 | 11924 | && cu->language == language_cplus) |
df8a16a1 | 11925 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
11926 | } |
11927 | return (sym); | |
11928 | } | |
11929 | ||
34eaf542 TT |
11930 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
11931 | ||
11932 | static struct symbol * | |
11933 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
11934 | { | |
11935 | return new_symbol_full (die, type, cu, NULL); | |
11936 | } | |
11937 | ||
98bfdba5 PA |
11938 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
11939 | zero-extend it as appropriate for the symbol's type. The DWARF | |
11940 | standard (v4) is not entirely clear about the meaning of using | |
11941 | DW_FORM_dataN for a constant with a signed type, where the type is | |
11942 | wider than the data. The conclusion of a discussion on the DWARF | |
11943 | list was that this is unspecified. We choose to always zero-extend | |
11944 | because that is the interpretation long in use by GCC. */ | |
c906108c | 11945 | |
98bfdba5 PA |
11946 | static gdb_byte * |
11947 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
11948 | const char *name, struct obstack *obstack, | |
11949 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 11950 | { |
e7c27a73 | 11951 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
11952 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
11953 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
11954 | LONGEST l = DW_UNSND (attr); |
11955 | ||
11956 | if (bits < sizeof (*value) * 8) | |
11957 | { | |
11958 | l &= ((LONGEST) 1 << bits) - 1; | |
11959 | *value = l; | |
11960 | } | |
11961 | else if (bits == sizeof (*value) * 8) | |
11962 | *value = l; | |
11963 | else | |
11964 | { | |
11965 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
11966 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
11967 | return bytes; | |
11968 | } | |
11969 | ||
11970 | return NULL; | |
11971 | } | |
11972 | ||
11973 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
11974 | the value does not fit in *VALUE, set *BYTES - either already | |
11975 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
11976 | or, set *BATON, if we translated the constant to a location | |
11977 | expression. */ | |
11978 | ||
11979 | static void | |
11980 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
11981 | const char *name, struct obstack *obstack, | |
11982 | struct dwarf2_cu *cu, | |
11983 | long *value, gdb_byte **bytes, | |
11984 | struct dwarf2_locexpr_baton **baton) | |
11985 | { | |
11986 | struct objfile *objfile = cu->objfile; | |
11987 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 11988 | struct dwarf_block *blk; |
98bfdba5 PA |
11989 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
11990 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
11991 | ||
11992 | *value = 0; | |
11993 | *bytes = NULL; | |
11994 | *baton = NULL; | |
c906108c SS |
11995 | |
11996 | switch (attr->form) | |
11997 | { | |
11998 | case DW_FORM_addr: | |
ac56253d | 11999 | { |
ac56253d TT |
12000 | gdb_byte *data; |
12001 | ||
98bfdba5 PA |
12002 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
12003 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 12004 | cu_header->addr_size, |
98bfdba5 | 12005 | TYPE_LENGTH (type)); |
ac56253d TT |
12006 | /* Symbols of this form are reasonably rare, so we just |
12007 | piggyback on the existing location code rather than writing | |
12008 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
12009 | *baton = obstack_alloc (&objfile->objfile_obstack, |
12010 | sizeof (struct dwarf2_locexpr_baton)); | |
12011 | (*baton)->per_cu = cu->per_cu; | |
12012 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 12013 | |
98bfdba5 PA |
12014 | (*baton)->size = 2 + cu_header->addr_size; |
12015 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
12016 | (*baton)->data = data; | |
ac56253d TT |
12017 | |
12018 | data[0] = DW_OP_addr; | |
12019 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
12020 | byte_order, DW_ADDR (attr)); | |
12021 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 12022 | } |
c906108c | 12023 | break; |
4ac36638 | 12024 | case DW_FORM_string: |
93b5768b | 12025 | case DW_FORM_strp: |
98bfdba5 PA |
12026 | /* DW_STRING is already allocated on the objfile obstack, point |
12027 | directly to it. */ | |
12028 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 12029 | break; |
c906108c SS |
12030 | case DW_FORM_block1: |
12031 | case DW_FORM_block2: | |
12032 | case DW_FORM_block4: | |
12033 | case DW_FORM_block: | |
2dc7f7b3 | 12034 | case DW_FORM_exprloc: |
c906108c | 12035 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
12036 | if (TYPE_LENGTH (type) != blk->size) |
12037 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
12038 | TYPE_LENGTH (type)); | |
12039 | *bytes = blk->data; | |
c906108c | 12040 | break; |
2df3850c JM |
12041 | |
12042 | /* The DW_AT_const_value attributes are supposed to carry the | |
12043 | symbol's value "represented as it would be on the target | |
12044 | architecture." By the time we get here, it's already been | |
12045 | converted to host endianness, so we just need to sign- or | |
12046 | zero-extend it as appropriate. */ | |
12047 | case DW_FORM_data1: | |
3e43a32a MS |
12048 | *bytes = dwarf2_const_value_data (attr, type, name, |
12049 | obstack, cu, value, 8); | |
2df3850c | 12050 | break; |
c906108c | 12051 | case DW_FORM_data2: |
3e43a32a MS |
12052 | *bytes = dwarf2_const_value_data (attr, type, name, |
12053 | obstack, cu, value, 16); | |
2df3850c | 12054 | break; |
c906108c | 12055 | case DW_FORM_data4: |
3e43a32a MS |
12056 | *bytes = dwarf2_const_value_data (attr, type, name, |
12057 | obstack, cu, value, 32); | |
2df3850c | 12058 | break; |
c906108c | 12059 | case DW_FORM_data8: |
3e43a32a MS |
12060 | *bytes = dwarf2_const_value_data (attr, type, name, |
12061 | obstack, cu, value, 64); | |
2df3850c JM |
12062 | break; |
12063 | ||
c906108c | 12064 | case DW_FORM_sdata: |
98bfdba5 | 12065 | *value = DW_SND (attr); |
2df3850c JM |
12066 | break; |
12067 | ||
c906108c | 12068 | case DW_FORM_udata: |
98bfdba5 | 12069 | *value = DW_UNSND (attr); |
c906108c | 12070 | break; |
2df3850c | 12071 | |
c906108c | 12072 | default: |
4d3c2250 | 12073 | complaint (&symfile_complaints, |
e2e0b3e5 | 12074 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 12075 | dwarf_form_name (attr->form)); |
98bfdba5 | 12076 | *value = 0; |
c906108c SS |
12077 | break; |
12078 | } | |
12079 | } | |
12080 | ||
2df3850c | 12081 | |
98bfdba5 PA |
12082 | /* Copy constant value from an attribute to a symbol. */ |
12083 | ||
2df3850c | 12084 | static void |
98bfdba5 PA |
12085 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
12086 | struct dwarf2_cu *cu) | |
2df3850c | 12087 | { |
98bfdba5 PA |
12088 | struct objfile *objfile = cu->objfile; |
12089 | struct comp_unit_head *cu_header = &cu->header; | |
12090 | long value; | |
12091 | gdb_byte *bytes; | |
12092 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 12093 | |
98bfdba5 PA |
12094 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
12095 | SYMBOL_PRINT_NAME (sym), | |
12096 | &objfile->objfile_obstack, cu, | |
12097 | &value, &bytes, &baton); | |
2df3850c | 12098 | |
98bfdba5 PA |
12099 | if (baton != NULL) |
12100 | { | |
12101 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
12102 | SYMBOL_LOCATION_BATON (sym) = baton; | |
12103 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
12104 | } | |
12105 | else if (bytes != NULL) | |
12106 | { | |
12107 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
12108 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
12109 | } | |
12110 | else | |
12111 | { | |
12112 | SYMBOL_VALUE (sym) = value; | |
12113 | SYMBOL_CLASS (sym) = LOC_CONST; | |
12114 | } | |
2df3850c JM |
12115 | } |
12116 | ||
c906108c SS |
12117 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
12118 | ||
12119 | static struct type * | |
e7c27a73 | 12120 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12121 | { |
c906108c | 12122 | struct attribute *type_attr; |
c906108c | 12123 | |
e142c38c | 12124 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
12125 | if (!type_attr) |
12126 | { | |
12127 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 12128 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 12129 | } |
348e048f | 12130 | |
673bfd45 | 12131 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12132 | } |
12133 | ||
b4ba55a1 JB |
12134 | /* True iff CU's producer generates GNAT Ada auxiliary information |
12135 | that allows to find parallel types through that information instead | |
12136 | of having to do expensive parallel lookups by type name. */ | |
12137 | ||
12138 | static int | |
12139 | need_gnat_info (struct dwarf2_cu *cu) | |
12140 | { | |
12141 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
12142 | of GNAT produces this auxiliary information, without any indication | |
12143 | that it is produced. Part of enhancing the FSF version of GNAT | |
12144 | to produce that information will be to put in place an indicator | |
12145 | that we can use in order to determine whether the descriptive type | |
12146 | info is available or not. One suggestion that has been made is | |
12147 | to use a new attribute, attached to the CU die. For now, assume | |
12148 | that the descriptive type info is not available. */ | |
12149 | return 0; | |
12150 | } | |
12151 | ||
b4ba55a1 JB |
12152 | /* Return the auxiliary type of the die in question using its |
12153 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
12154 | attribute is not present. */ | |
12155 | ||
12156 | static struct type * | |
12157 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
12158 | { | |
b4ba55a1 | 12159 | struct attribute *type_attr; |
b4ba55a1 JB |
12160 | |
12161 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
12162 | if (!type_attr) | |
12163 | return NULL; | |
12164 | ||
673bfd45 | 12165 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
12166 | } |
12167 | ||
12168 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
12169 | descriptive type accordingly. */ | |
12170 | ||
12171 | static void | |
12172 | set_descriptive_type (struct type *type, struct die_info *die, | |
12173 | struct dwarf2_cu *cu) | |
12174 | { | |
12175 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
12176 | ||
12177 | if (descriptive_type) | |
12178 | { | |
12179 | ALLOCATE_GNAT_AUX_TYPE (type); | |
12180 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
12181 | } | |
12182 | } | |
12183 | ||
c906108c SS |
12184 | /* Return the containing type of the die in question using its |
12185 | DW_AT_containing_type attribute. */ | |
12186 | ||
12187 | static struct type * | |
e7c27a73 | 12188 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12189 | { |
c906108c | 12190 | struct attribute *type_attr; |
c906108c | 12191 | |
e142c38c | 12192 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
12193 | if (!type_attr) |
12194 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
12195 | "[in module %s]"), cu->objfile->name); | |
12196 | ||
673bfd45 | 12197 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12198 | } |
12199 | ||
673bfd45 DE |
12200 | /* Look up the type of DIE in CU using its type attribute ATTR. |
12201 | If there is no type substitute an error marker. */ | |
12202 | ||
c906108c | 12203 | static struct type * |
673bfd45 DE |
12204 | lookup_die_type (struct die_info *die, struct attribute *attr, |
12205 | struct dwarf2_cu *cu) | |
c906108c | 12206 | { |
f792889a DJ |
12207 | struct type *this_type; |
12208 | ||
673bfd45 DE |
12209 | /* First see if we have it cached. */ |
12210 | ||
12211 | if (is_ref_attr (attr)) | |
12212 | { | |
12213 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
12214 | ||
12215 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
12216 | } | |
55f1336d | 12217 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
12218 | { |
12219 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
12220 | struct dwarf2_cu *sig_cu; | |
12221 | unsigned int offset; | |
12222 | ||
12223 | /* sig_type will be NULL if the signatured type is missing from | |
12224 | the debug info. */ | |
12225 | if (sig_type == NULL) | |
12226 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12227 | "at 0x%x [in module %s]"), | |
12228 | die->offset, cu->objfile->name); | |
12229 | ||
8b70b953 | 12230 | gdb_assert (sig_type->per_cu.debug_type_section); |
b3c8eb43 | 12231 | offset = sig_type->per_cu.offset + sig_type->type_offset; |
673bfd45 DE |
12232 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
12233 | } | |
12234 | else | |
12235 | { | |
12236 | dump_die_for_error (die); | |
12237 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
12238 | dwarf_attr_name (attr->name), cu->objfile->name); | |
12239 | } | |
12240 | ||
12241 | /* If not cached we need to read it in. */ | |
12242 | ||
12243 | if (this_type == NULL) | |
12244 | { | |
12245 | struct die_info *type_die; | |
12246 | struct dwarf2_cu *type_cu = cu; | |
12247 | ||
12248 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
12249 | /* If the type is cached, we should have found it above. */ | |
12250 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
12251 | this_type = read_type_die_1 (type_die, type_cu); | |
12252 | } | |
12253 | ||
12254 | /* If we still don't have a type use an error marker. */ | |
12255 | ||
12256 | if (this_type == NULL) | |
c906108c | 12257 | { |
b00fdb78 TT |
12258 | char *message, *saved; |
12259 | ||
12260 | /* read_type_die already issued a complaint. */ | |
12261 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
12262 | cu->objfile->name, | |
12263 | cu->header.offset, | |
12264 | die->offset); | |
12265 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
12266 | message, strlen (message)); | |
12267 | xfree (message); | |
12268 | ||
12269 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 12270 | } |
673bfd45 | 12271 | |
f792889a | 12272 | return this_type; |
c906108c SS |
12273 | } |
12274 | ||
673bfd45 DE |
12275 | /* Return the type in DIE, CU. |
12276 | Returns NULL for invalid types. | |
12277 | ||
12278 | This first does a lookup in the appropriate type_hash table, | |
12279 | and only reads the die in if necessary. | |
12280 | ||
12281 | NOTE: This can be called when reading in partial or full symbols. */ | |
12282 | ||
f792889a | 12283 | static struct type * |
e7c27a73 | 12284 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12285 | { |
f792889a DJ |
12286 | struct type *this_type; |
12287 | ||
12288 | this_type = get_die_type (die, cu); | |
12289 | if (this_type) | |
12290 | return this_type; | |
12291 | ||
673bfd45 DE |
12292 | return read_type_die_1 (die, cu); |
12293 | } | |
12294 | ||
12295 | /* Read the type in DIE, CU. | |
12296 | Returns NULL for invalid types. */ | |
12297 | ||
12298 | static struct type * | |
12299 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
12300 | { | |
12301 | struct type *this_type = NULL; | |
12302 | ||
c906108c SS |
12303 | switch (die->tag) |
12304 | { | |
12305 | case DW_TAG_class_type: | |
680b30c7 | 12306 | case DW_TAG_interface_type: |
c906108c SS |
12307 | case DW_TAG_structure_type: |
12308 | case DW_TAG_union_type: | |
f792889a | 12309 | this_type = read_structure_type (die, cu); |
c906108c SS |
12310 | break; |
12311 | case DW_TAG_enumeration_type: | |
f792889a | 12312 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
12313 | break; |
12314 | case DW_TAG_subprogram: | |
12315 | case DW_TAG_subroutine_type: | |
edb3359d | 12316 | case DW_TAG_inlined_subroutine: |
f792889a | 12317 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
12318 | break; |
12319 | case DW_TAG_array_type: | |
f792889a | 12320 | this_type = read_array_type (die, cu); |
c906108c | 12321 | break; |
72019c9c | 12322 | case DW_TAG_set_type: |
f792889a | 12323 | this_type = read_set_type (die, cu); |
72019c9c | 12324 | break; |
c906108c | 12325 | case DW_TAG_pointer_type: |
f792889a | 12326 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
12327 | break; |
12328 | case DW_TAG_ptr_to_member_type: | |
f792889a | 12329 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
12330 | break; |
12331 | case DW_TAG_reference_type: | |
f792889a | 12332 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
12333 | break; |
12334 | case DW_TAG_const_type: | |
f792889a | 12335 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
12336 | break; |
12337 | case DW_TAG_volatile_type: | |
f792889a | 12338 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
12339 | break; |
12340 | case DW_TAG_string_type: | |
f792889a | 12341 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
12342 | break; |
12343 | case DW_TAG_typedef: | |
f792889a | 12344 | this_type = read_typedef (die, cu); |
c906108c | 12345 | break; |
a02abb62 | 12346 | case DW_TAG_subrange_type: |
f792889a | 12347 | this_type = read_subrange_type (die, cu); |
a02abb62 | 12348 | break; |
c906108c | 12349 | case DW_TAG_base_type: |
f792889a | 12350 | this_type = read_base_type (die, cu); |
c906108c | 12351 | break; |
81a17f79 | 12352 | case DW_TAG_unspecified_type: |
f792889a | 12353 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 12354 | break; |
0114d602 DJ |
12355 | case DW_TAG_namespace: |
12356 | this_type = read_namespace_type (die, cu); | |
12357 | break; | |
f55ee35c JK |
12358 | case DW_TAG_module: |
12359 | this_type = read_module_type (die, cu); | |
12360 | break; | |
c906108c | 12361 | default: |
3e43a32a MS |
12362 | complaint (&symfile_complaints, |
12363 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 12364 | dwarf_tag_name (die->tag)); |
c906108c SS |
12365 | break; |
12366 | } | |
63d06c5c | 12367 | |
f792889a | 12368 | return this_type; |
63d06c5c DC |
12369 | } |
12370 | ||
abc72ce4 DE |
12371 | /* See if we can figure out if the class lives in a namespace. We do |
12372 | this by looking for a member function; its demangled name will | |
12373 | contain namespace info, if there is any. | |
12374 | Return the computed name or NULL. | |
12375 | Space for the result is allocated on the objfile's obstack. | |
12376 | This is the full-die version of guess_partial_die_structure_name. | |
12377 | In this case we know DIE has no useful parent. */ | |
12378 | ||
12379 | static char * | |
12380 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
12381 | { | |
12382 | struct die_info *spec_die; | |
12383 | struct dwarf2_cu *spec_cu; | |
12384 | struct die_info *child; | |
12385 | ||
12386 | spec_cu = cu; | |
12387 | spec_die = die_specification (die, &spec_cu); | |
12388 | if (spec_die != NULL) | |
12389 | { | |
12390 | die = spec_die; | |
12391 | cu = spec_cu; | |
12392 | } | |
12393 | ||
12394 | for (child = die->child; | |
12395 | child != NULL; | |
12396 | child = child->sibling) | |
12397 | { | |
12398 | if (child->tag == DW_TAG_subprogram) | |
12399 | { | |
12400 | struct attribute *attr; | |
12401 | ||
12402 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
12403 | if (attr == NULL) | |
12404 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
12405 | if (attr != NULL) | |
12406 | { | |
12407 | char *actual_name | |
12408 | = language_class_name_from_physname (cu->language_defn, | |
12409 | DW_STRING (attr)); | |
12410 | char *name = NULL; | |
12411 | ||
12412 | if (actual_name != NULL) | |
12413 | { | |
12414 | char *die_name = dwarf2_name (die, cu); | |
12415 | ||
12416 | if (die_name != NULL | |
12417 | && strcmp (die_name, actual_name) != 0) | |
12418 | { | |
12419 | /* Strip off the class name from the full name. | |
12420 | We want the prefix. */ | |
12421 | int die_name_len = strlen (die_name); | |
12422 | int actual_name_len = strlen (actual_name); | |
12423 | ||
12424 | /* Test for '::' as a sanity check. */ | |
12425 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
12426 | && actual_name[actual_name_len |
12427 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
12428 | name = |
12429 | obsavestring (actual_name, | |
12430 | actual_name_len - die_name_len - 2, | |
12431 | &cu->objfile->objfile_obstack); | |
12432 | } | |
12433 | } | |
12434 | xfree (actual_name); | |
12435 | return name; | |
12436 | } | |
12437 | } | |
12438 | } | |
12439 | ||
12440 | return NULL; | |
12441 | } | |
12442 | ||
96408a79 SA |
12443 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
12444 | prefix part in such case. See | |
12445 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12446 | ||
12447 | static char * | |
12448 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
12449 | { | |
12450 | struct attribute *attr; | |
12451 | char *base; | |
12452 | ||
12453 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
12454 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
12455 | return NULL; | |
12456 | ||
12457 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
12458 | if (attr != NULL && DW_STRING (attr) != NULL) | |
12459 | return NULL; | |
12460 | ||
12461 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12462 | if (attr == NULL) | |
12463 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12464 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12465 | return NULL; | |
12466 | ||
12467 | /* dwarf2_name had to be already called. */ | |
12468 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
12469 | ||
12470 | /* Strip the base name, keep any leading namespaces/classes. */ | |
12471 | base = strrchr (DW_STRING (attr), ':'); | |
12472 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
12473 | return ""; | |
12474 | ||
12475 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
12476 | &cu->objfile->objfile_obstack); | |
12477 | } | |
12478 | ||
fdde2d81 | 12479 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 12480 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 12481 | |
0114d602 DJ |
12482 | For example, if we're within the method foo() in the following |
12483 | code: | |
12484 | ||
12485 | namespace N { | |
12486 | class C { | |
12487 | void foo () { | |
12488 | } | |
12489 | }; | |
12490 | } | |
12491 | ||
12492 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
12493 | |
12494 | static char * | |
e142c38c | 12495 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 12496 | { |
0114d602 DJ |
12497 | struct die_info *parent, *spec_die; |
12498 | struct dwarf2_cu *spec_cu; | |
12499 | struct type *parent_type; | |
96408a79 | 12500 | char *retval; |
63d06c5c | 12501 | |
f55ee35c JK |
12502 | if (cu->language != language_cplus && cu->language != language_java |
12503 | && cu->language != language_fortran) | |
0114d602 DJ |
12504 | return ""; |
12505 | ||
96408a79 SA |
12506 | retval = anonymous_struct_prefix (die, cu); |
12507 | if (retval) | |
12508 | return retval; | |
12509 | ||
0114d602 DJ |
12510 | /* We have to be careful in the presence of DW_AT_specification. |
12511 | For example, with GCC 3.4, given the code | |
12512 | ||
12513 | namespace N { | |
12514 | void foo() { | |
12515 | // Definition of N::foo. | |
12516 | } | |
12517 | } | |
12518 | ||
12519 | then we'll have a tree of DIEs like this: | |
12520 | ||
12521 | 1: DW_TAG_compile_unit | |
12522 | 2: DW_TAG_namespace // N | |
12523 | 3: DW_TAG_subprogram // declaration of N::foo | |
12524 | 4: DW_TAG_subprogram // definition of N::foo | |
12525 | DW_AT_specification // refers to die #3 | |
12526 | ||
12527 | Thus, when processing die #4, we have to pretend that we're in | |
12528 | the context of its DW_AT_specification, namely the contex of die | |
12529 | #3. */ | |
12530 | spec_cu = cu; | |
12531 | spec_die = die_specification (die, &spec_cu); | |
12532 | if (spec_die == NULL) | |
12533 | parent = die->parent; | |
12534 | else | |
63d06c5c | 12535 | { |
0114d602 DJ |
12536 | parent = spec_die->parent; |
12537 | cu = spec_cu; | |
63d06c5c | 12538 | } |
0114d602 DJ |
12539 | |
12540 | if (parent == NULL) | |
12541 | return ""; | |
98bfdba5 PA |
12542 | else if (parent->building_fullname) |
12543 | { | |
12544 | const char *name; | |
12545 | const char *parent_name; | |
12546 | ||
12547 | /* It has been seen on RealView 2.2 built binaries, | |
12548 | DW_TAG_template_type_param types actually _defined_ as | |
12549 | children of the parent class: | |
12550 | ||
12551 | enum E {}; | |
12552 | template class <class Enum> Class{}; | |
12553 | Class<enum E> class_e; | |
12554 | ||
12555 | 1: DW_TAG_class_type (Class) | |
12556 | 2: DW_TAG_enumeration_type (E) | |
12557 | 3: DW_TAG_enumerator (enum1:0) | |
12558 | 3: DW_TAG_enumerator (enum2:1) | |
12559 | ... | |
12560 | 2: DW_TAG_template_type_param | |
12561 | DW_AT_type DW_FORM_ref_udata (E) | |
12562 | ||
12563 | Besides being broken debug info, it can put GDB into an | |
12564 | infinite loop. Consider: | |
12565 | ||
12566 | When we're building the full name for Class<E>, we'll start | |
12567 | at Class, and go look over its template type parameters, | |
12568 | finding E. We'll then try to build the full name of E, and | |
12569 | reach here. We're now trying to build the full name of E, | |
12570 | and look over the parent DIE for containing scope. In the | |
12571 | broken case, if we followed the parent DIE of E, we'd again | |
12572 | find Class, and once again go look at its template type | |
12573 | arguments, etc., etc. Simply don't consider such parent die | |
12574 | as source-level parent of this die (it can't be, the language | |
12575 | doesn't allow it), and break the loop here. */ | |
12576 | name = dwarf2_name (die, cu); | |
12577 | parent_name = dwarf2_name (parent, cu); | |
12578 | complaint (&symfile_complaints, | |
12579 | _("template param type '%s' defined within parent '%s'"), | |
12580 | name ? name : "<unknown>", | |
12581 | parent_name ? parent_name : "<unknown>"); | |
12582 | return ""; | |
12583 | } | |
63d06c5c | 12584 | else |
0114d602 DJ |
12585 | switch (parent->tag) |
12586 | { | |
63d06c5c | 12587 | case DW_TAG_namespace: |
0114d602 | 12588 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
12589 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
12590 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
12591 | Work around this problem here. */ | |
12592 | if (cu->language == language_cplus | |
12593 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
12594 | return ""; | |
0114d602 DJ |
12595 | /* We give a name to even anonymous namespaces. */ |
12596 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 12597 | case DW_TAG_class_type: |
680b30c7 | 12598 | case DW_TAG_interface_type: |
63d06c5c | 12599 | case DW_TAG_structure_type: |
0114d602 | 12600 | case DW_TAG_union_type: |
f55ee35c | 12601 | case DW_TAG_module: |
0114d602 DJ |
12602 | parent_type = read_type_die (parent, cu); |
12603 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
12604 | return TYPE_TAG_NAME (parent_type); | |
12605 | else | |
12606 | /* An anonymous structure is only allowed non-static data | |
12607 | members; no typedefs, no member functions, et cetera. | |
12608 | So it does not need a prefix. */ | |
12609 | return ""; | |
abc72ce4 DE |
12610 | case DW_TAG_compile_unit: |
12611 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
12612 | if (cu->language == language_cplus | |
8b70b953 | 12613 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
12614 | && die->child != NULL |
12615 | && (die->tag == DW_TAG_class_type | |
12616 | || die->tag == DW_TAG_structure_type | |
12617 | || die->tag == DW_TAG_union_type)) | |
12618 | { | |
12619 | char *name = guess_full_die_structure_name (die, cu); | |
12620 | if (name != NULL) | |
12621 | return name; | |
12622 | } | |
12623 | return ""; | |
63d06c5c | 12624 | default: |
8176b9b8 | 12625 | return determine_prefix (parent, cu); |
63d06c5c | 12626 | } |
63d06c5c DC |
12627 | } |
12628 | ||
3e43a32a MS |
12629 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
12630 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
12631 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
12632 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
12633 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 12634 | |
f55ee35c | 12635 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
12636 | |
12637 | static char * | |
f55ee35c JK |
12638 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
12639 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 12640 | { |
f55ee35c | 12641 | const char *lead = ""; |
5c315b68 | 12642 | const char *sep; |
63d06c5c | 12643 | |
3e43a32a MS |
12644 | if (suffix == NULL || suffix[0] == '\0' |
12645 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
12646 | sep = ""; |
12647 | else if (cu->language == language_java) | |
12648 | sep = "."; | |
f55ee35c JK |
12649 | else if (cu->language == language_fortran && physname) |
12650 | { | |
12651 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
12652 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
12653 | ||
12654 | lead = "__"; | |
12655 | sep = "_MOD_"; | |
12656 | } | |
987504bb JJ |
12657 | else |
12658 | sep = "::"; | |
63d06c5c | 12659 | |
6dd47d34 DE |
12660 | if (prefix == NULL) |
12661 | prefix = ""; | |
12662 | if (suffix == NULL) | |
12663 | suffix = ""; | |
12664 | ||
987504bb JJ |
12665 | if (obs == NULL) |
12666 | { | |
3e43a32a MS |
12667 | char *retval |
12668 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 12669 | |
f55ee35c JK |
12670 | strcpy (retval, lead); |
12671 | strcat (retval, prefix); | |
6dd47d34 DE |
12672 | strcat (retval, sep); |
12673 | strcat (retval, suffix); | |
63d06c5c DC |
12674 | return retval; |
12675 | } | |
987504bb JJ |
12676 | else |
12677 | { | |
12678 | /* We have an obstack. */ | |
f55ee35c | 12679 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 12680 | } |
63d06c5c DC |
12681 | } |
12682 | ||
c906108c SS |
12683 | /* Return sibling of die, NULL if no sibling. */ |
12684 | ||
f9aca02d | 12685 | static struct die_info * |
fba45db2 | 12686 | sibling_die (struct die_info *die) |
c906108c | 12687 | { |
639d11d3 | 12688 | return die->sibling; |
c906108c SS |
12689 | } |
12690 | ||
71c25dea TT |
12691 | /* Get name of a die, return NULL if not found. */ |
12692 | ||
12693 | static char * | |
12694 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
12695 | struct obstack *obstack) | |
12696 | { | |
12697 | if (name && cu->language == language_cplus) | |
12698 | { | |
12699 | char *canon_name = cp_canonicalize_string (name); | |
12700 | ||
12701 | if (canon_name != NULL) | |
12702 | { | |
12703 | if (strcmp (canon_name, name) != 0) | |
12704 | name = obsavestring (canon_name, strlen (canon_name), | |
12705 | obstack); | |
12706 | xfree (canon_name); | |
12707 | } | |
12708 | } | |
12709 | ||
12710 | return name; | |
c906108c SS |
12711 | } |
12712 | ||
9219021c DC |
12713 | /* Get name of a die, return NULL if not found. */ |
12714 | ||
12715 | static char * | |
e142c38c | 12716 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
12717 | { |
12718 | struct attribute *attr; | |
12719 | ||
e142c38c | 12720 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
12721 | if ((!attr || !DW_STRING (attr)) |
12722 | && die->tag != DW_TAG_class_type | |
12723 | && die->tag != DW_TAG_interface_type | |
12724 | && die->tag != DW_TAG_structure_type | |
12725 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
12726 | return NULL; |
12727 | ||
12728 | switch (die->tag) | |
12729 | { | |
12730 | case DW_TAG_compile_unit: | |
12731 | /* Compilation units have a DW_AT_name that is a filename, not | |
12732 | a source language identifier. */ | |
12733 | case DW_TAG_enumeration_type: | |
12734 | case DW_TAG_enumerator: | |
12735 | /* These tags always have simple identifiers already; no need | |
12736 | to canonicalize them. */ | |
12737 | return DW_STRING (attr); | |
907af001 | 12738 | |
418835cc KS |
12739 | case DW_TAG_subprogram: |
12740 | /* Java constructors will all be named "<init>", so return | |
12741 | the class name when we see this special case. */ | |
12742 | if (cu->language == language_java | |
12743 | && DW_STRING (attr) != NULL | |
12744 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
12745 | { | |
12746 | struct dwarf2_cu *spec_cu = cu; | |
12747 | struct die_info *spec_die; | |
12748 | ||
12749 | /* GCJ will output '<init>' for Java constructor names. | |
12750 | For this special case, return the name of the parent class. */ | |
12751 | ||
12752 | /* GCJ may output suprogram DIEs with AT_specification set. | |
12753 | If so, use the name of the specified DIE. */ | |
12754 | spec_die = die_specification (die, &spec_cu); | |
12755 | if (spec_die != NULL) | |
12756 | return dwarf2_name (spec_die, spec_cu); | |
12757 | ||
12758 | do | |
12759 | { | |
12760 | die = die->parent; | |
12761 | if (die->tag == DW_TAG_class_type) | |
12762 | return dwarf2_name (die, cu); | |
12763 | } | |
12764 | while (die->tag != DW_TAG_compile_unit); | |
12765 | } | |
907af001 UW |
12766 | break; |
12767 | ||
12768 | case DW_TAG_class_type: | |
12769 | case DW_TAG_interface_type: | |
12770 | case DW_TAG_structure_type: | |
12771 | case DW_TAG_union_type: | |
12772 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
12773 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
12774 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
12775 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
12776 | if (attr && DW_STRING (attr) |
12777 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
12778 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 12779 | return NULL; |
53832f31 TT |
12780 | |
12781 | /* GCC might emit a nameless typedef that has a linkage name. See | |
12782 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12783 | if (!attr || DW_STRING (attr) == NULL) | |
12784 | { | |
df5c6c50 | 12785 | char *demangled = NULL; |
53832f31 TT |
12786 | |
12787 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12788 | if (attr == NULL) | |
12789 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12790 | ||
12791 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12792 | return NULL; | |
12793 | ||
df5c6c50 JK |
12794 | /* Avoid demangling DW_STRING (attr) the second time on a second |
12795 | call for the same DIE. */ | |
12796 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12797 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
12798 | |
12799 | if (demangled) | |
12800 | { | |
96408a79 SA |
12801 | char *base; |
12802 | ||
53832f31 | 12803 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
12804 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
12805 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
12806 | DW_STRING_IS_CANONICAL (attr) = 1; |
12807 | xfree (demangled); | |
96408a79 SA |
12808 | |
12809 | /* Strip any leading namespaces/classes, keep only the base name. | |
12810 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
12811 | base = strrchr (DW_STRING (attr), ':'); | |
12812 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
12813 | return &base[1]; | |
12814 | else | |
12815 | return DW_STRING (attr); | |
53832f31 TT |
12816 | } |
12817 | } | |
907af001 UW |
12818 | break; |
12819 | ||
71c25dea | 12820 | default: |
907af001 UW |
12821 | break; |
12822 | } | |
12823 | ||
12824 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12825 | { | |
12826 | DW_STRING (attr) | |
12827 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
12828 | &cu->objfile->objfile_obstack); | |
12829 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 12830 | } |
907af001 | 12831 | return DW_STRING (attr); |
9219021c DC |
12832 | } |
12833 | ||
12834 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
12835 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
12836 | containing the return value on output. */ | |
9219021c DC |
12837 | |
12838 | static struct die_info * | |
f2f0e013 | 12839 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
12840 | { |
12841 | struct attribute *attr; | |
9219021c | 12842 | |
f2f0e013 | 12843 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
12844 | if (attr == NULL) |
12845 | return NULL; | |
12846 | ||
f2f0e013 | 12847 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
12848 | } |
12849 | ||
c906108c SS |
12850 | /* Convert a DIE tag into its string name. */ |
12851 | ||
12852 | static char * | |
aa1ee363 | 12853 | dwarf_tag_name (unsigned tag) |
c906108c SS |
12854 | { |
12855 | switch (tag) | |
12856 | { | |
12857 | case DW_TAG_padding: | |
12858 | return "DW_TAG_padding"; | |
12859 | case DW_TAG_array_type: | |
12860 | return "DW_TAG_array_type"; | |
12861 | case DW_TAG_class_type: | |
12862 | return "DW_TAG_class_type"; | |
12863 | case DW_TAG_entry_point: | |
12864 | return "DW_TAG_entry_point"; | |
12865 | case DW_TAG_enumeration_type: | |
12866 | return "DW_TAG_enumeration_type"; | |
12867 | case DW_TAG_formal_parameter: | |
12868 | return "DW_TAG_formal_parameter"; | |
12869 | case DW_TAG_imported_declaration: | |
12870 | return "DW_TAG_imported_declaration"; | |
12871 | case DW_TAG_label: | |
12872 | return "DW_TAG_label"; | |
12873 | case DW_TAG_lexical_block: | |
12874 | return "DW_TAG_lexical_block"; | |
12875 | case DW_TAG_member: | |
12876 | return "DW_TAG_member"; | |
12877 | case DW_TAG_pointer_type: | |
12878 | return "DW_TAG_pointer_type"; | |
12879 | case DW_TAG_reference_type: | |
12880 | return "DW_TAG_reference_type"; | |
12881 | case DW_TAG_compile_unit: | |
12882 | return "DW_TAG_compile_unit"; | |
12883 | case DW_TAG_string_type: | |
12884 | return "DW_TAG_string_type"; | |
12885 | case DW_TAG_structure_type: | |
12886 | return "DW_TAG_structure_type"; | |
12887 | case DW_TAG_subroutine_type: | |
12888 | return "DW_TAG_subroutine_type"; | |
12889 | case DW_TAG_typedef: | |
12890 | return "DW_TAG_typedef"; | |
12891 | case DW_TAG_union_type: | |
12892 | return "DW_TAG_union_type"; | |
12893 | case DW_TAG_unspecified_parameters: | |
12894 | return "DW_TAG_unspecified_parameters"; | |
12895 | case DW_TAG_variant: | |
12896 | return "DW_TAG_variant"; | |
12897 | case DW_TAG_common_block: | |
12898 | return "DW_TAG_common_block"; | |
12899 | case DW_TAG_common_inclusion: | |
12900 | return "DW_TAG_common_inclusion"; | |
12901 | case DW_TAG_inheritance: | |
12902 | return "DW_TAG_inheritance"; | |
12903 | case DW_TAG_inlined_subroutine: | |
12904 | return "DW_TAG_inlined_subroutine"; | |
12905 | case DW_TAG_module: | |
12906 | return "DW_TAG_module"; | |
12907 | case DW_TAG_ptr_to_member_type: | |
12908 | return "DW_TAG_ptr_to_member_type"; | |
12909 | case DW_TAG_set_type: | |
12910 | return "DW_TAG_set_type"; | |
12911 | case DW_TAG_subrange_type: | |
12912 | return "DW_TAG_subrange_type"; | |
12913 | case DW_TAG_with_stmt: | |
12914 | return "DW_TAG_with_stmt"; | |
12915 | case DW_TAG_access_declaration: | |
12916 | return "DW_TAG_access_declaration"; | |
12917 | case DW_TAG_base_type: | |
12918 | return "DW_TAG_base_type"; | |
12919 | case DW_TAG_catch_block: | |
12920 | return "DW_TAG_catch_block"; | |
12921 | case DW_TAG_const_type: | |
12922 | return "DW_TAG_const_type"; | |
12923 | case DW_TAG_constant: | |
12924 | return "DW_TAG_constant"; | |
12925 | case DW_TAG_enumerator: | |
12926 | return "DW_TAG_enumerator"; | |
12927 | case DW_TAG_file_type: | |
12928 | return "DW_TAG_file_type"; | |
12929 | case DW_TAG_friend: | |
12930 | return "DW_TAG_friend"; | |
12931 | case DW_TAG_namelist: | |
12932 | return "DW_TAG_namelist"; | |
12933 | case DW_TAG_namelist_item: | |
12934 | return "DW_TAG_namelist_item"; | |
12935 | case DW_TAG_packed_type: | |
12936 | return "DW_TAG_packed_type"; | |
12937 | case DW_TAG_subprogram: | |
12938 | return "DW_TAG_subprogram"; | |
12939 | case DW_TAG_template_type_param: | |
12940 | return "DW_TAG_template_type_param"; | |
12941 | case DW_TAG_template_value_param: | |
12942 | return "DW_TAG_template_value_param"; | |
12943 | case DW_TAG_thrown_type: | |
12944 | return "DW_TAG_thrown_type"; | |
12945 | case DW_TAG_try_block: | |
12946 | return "DW_TAG_try_block"; | |
12947 | case DW_TAG_variant_part: | |
12948 | return "DW_TAG_variant_part"; | |
12949 | case DW_TAG_variable: | |
12950 | return "DW_TAG_variable"; | |
12951 | case DW_TAG_volatile_type: | |
12952 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
12953 | case DW_TAG_dwarf_procedure: |
12954 | return "DW_TAG_dwarf_procedure"; | |
12955 | case DW_TAG_restrict_type: | |
12956 | return "DW_TAG_restrict_type"; | |
12957 | case DW_TAG_interface_type: | |
12958 | return "DW_TAG_interface_type"; | |
12959 | case DW_TAG_namespace: | |
12960 | return "DW_TAG_namespace"; | |
12961 | case DW_TAG_imported_module: | |
12962 | return "DW_TAG_imported_module"; | |
12963 | case DW_TAG_unspecified_type: | |
12964 | return "DW_TAG_unspecified_type"; | |
12965 | case DW_TAG_partial_unit: | |
12966 | return "DW_TAG_partial_unit"; | |
12967 | case DW_TAG_imported_unit: | |
12968 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
12969 | case DW_TAG_condition: |
12970 | return "DW_TAG_condition"; | |
12971 | case DW_TAG_shared_type: | |
12972 | return "DW_TAG_shared_type"; | |
348e048f DE |
12973 | case DW_TAG_type_unit: |
12974 | return "DW_TAG_type_unit"; | |
c906108c SS |
12975 | case DW_TAG_MIPS_loop: |
12976 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
12977 | case DW_TAG_HP_array_descriptor: |
12978 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
12979 | case DW_TAG_format_label: |
12980 | return "DW_TAG_format_label"; | |
12981 | case DW_TAG_function_template: | |
12982 | return "DW_TAG_function_template"; | |
12983 | case DW_TAG_class_template: | |
12984 | return "DW_TAG_class_template"; | |
b7619582 GF |
12985 | case DW_TAG_GNU_BINCL: |
12986 | return "DW_TAG_GNU_BINCL"; | |
12987 | case DW_TAG_GNU_EINCL: | |
12988 | return "DW_TAG_GNU_EINCL"; | |
12989 | case DW_TAG_upc_shared_type: | |
12990 | return "DW_TAG_upc_shared_type"; | |
12991 | case DW_TAG_upc_strict_type: | |
12992 | return "DW_TAG_upc_strict_type"; | |
12993 | case DW_TAG_upc_relaxed_type: | |
12994 | return "DW_TAG_upc_relaxed_type"; | |
12995 | case DW_TAG_PGI_kanji_type: | |
12996 | return "DW_TAG_PGI_kanji_type"; | |
12997 | case DW_TAG_PGI_interface_block: | |
12998 | return "DW_TAG_PGI_interface_block"; | |
96408a79 SA |
12999 | case DW_TAG_GNU_call_site: |
13000 | return "DW_TAG_GNU_call_site"; | |
c906108c SS |
13001 | default: |
13002 | return "DW_TAG_<unknown>"; | |
13003 | } | |
13004 | } | |
13005 | ||
13006 | /* Convert a DWARF attribute code into its string name. */ | |
13007 | ||
13008 | static char * | |
aa1ee363 | 13009 | dwarf_attr_name (unsigned attr) |
c906108c SS |
13010 | { |
13011 | switch (attr) | |
13012 | { | |
13013 | case DW_AT_sibling: | |
13014 | return "DW_AT_sibling"; | |
13015 | case DW_AT_location: | |
13016 | return "DW_AT_location"; | |
13017 | case DW_AT_name: | |
13018 | return "DW_AT_name"; | |
13019 | case DW_AT_ordering: | |
13020 | return "DW_AT_ordering"; | |
13021 | case DW_AT_subscr_data: | |
13022 | return "DW_AT_subscr_data"; | |
13023 | case DW_AT_byte_size: | |
13024 | return "DW_AT_byte_size"; | |
13025 | case DW_AT_bit_offset: | |
13026 | return "DW_AT_bit_offset"; | |
13027 | case DW_AT_bit_size: | |
13028 | return "DW_AT_bit_size"; | |
13029 | case DW_AT_element_list: | |
13030 | return "DW_AT_element_list"; | |
13031 | case DW_AT_stmt_list: | |
13032 | return "DW_AT_stmt_list"; | |
13033 | case DW_AT_low_pc: | |
13034 | return "DW_AT_low_pc"; | |
13035 | case DW_AT_high_pc: | |
13036 | return "DW_AT_high_pc"; | |
13037 | case DW_AT_language: | |
13038 | return "DW_AT_language"; | |
13039 | case DW_AT_member: | |
13040 | return "DW_AT_member"; | |
13041 | case DW_AT_discr: | |
13042 | return "DW_AT_discr"; | |
13043 | case DW_AT_discr_value: | |
13044 | return "DW_AT_discr_value"; | |
13045 | case DW_AT_visibility: | |
13046 | return "DW_AT_visibility"; | |
13047 | case DW_AT_import: | |
13048 | return "DW_AT_import"; | |
13049 | case DW_AT_string_length: | |
13050 | return "DW_AT_string_length"; | |
13051 | case DW_AT_common_reference: | |
13052 | return "DW_AT_common_reference"; | |
13053 | case DW_AT_comp_dir: | |
13054 | return "DW_AT_comp_dir"; | |
13055 | case DW_AT_const_value: | |
13056 | return "DW_AT_const_value"; | |
13057 | case DW_AT_containing_type: | |
13058 | return "DW_AT_containing_type"; | |
13059 | case DW_AT_default_value: | |
13060 | return "DW_AT_default_value"; | |
13061 | case DW_AT_inline: | |
13062 | return "DW_AT_inline"; | |
13063 | case DW_AT_is_optional: | |
13064 | return "DW_AT_is_optional"; | |
13065 | case DW_AT_lower_bound: | |
13066 | return "DW_AT_lower_bound"; | |
13067 | case DW_AT_producer: | |
13068 | return "DW_AT_producer"; | |
13069 | case DW_AT_prototyped: | |
13070 | return "DW_AT_prototyped"; | |
13071 | case DW_AT_return_addr: | |
13072 | return "DW_AT_return_addr"; | |
13073 | case DW_AT_start_scope: | |
13074 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
13075 | case DW_AT_bit_stride: |
13076 | return "DW_AT_bit_stride"; | |
c906108c SS |
13077 | case DW_AT_upper_bound: |
13078 | return "DW_AT_upper_bound"; | |
13079 | case DW_AT_abstract_origin: | |
13080 | return "DW_AT_abstract_origin"; | |
13081 | case DW_AT_accessibility: | |
13082 | return "DW_AT_accessibility"; | |
13083 | case DW_AT_address_class: | |
13084 | return "DW_AT_address_class"; | |
13085 | case DW_AT_artificial: | |
13086 | return "DW_AT_artificial"; | |
13087 | case DW_AT_base_types: | |
13088 | return "DW_AT_base_types"; | |
13089 | case DW_AT_calling_convention: | |
13090 | return "DW_AT_calling_convention"; | |
13091 | case DW_AT_count: | |
13092 | return "DW_AT_count"; | |
13093 | case DW_AT_data_member_location: | |
13094 | return "DW_AT_data_member_location"; | |
13095 | case DW_AT_decl_column: | |
13096 | return "DW_AT_decl_column"; | |
13097 | case DW_AT_decl_file: | |
13098 | return "DW_AT_decl_file"; | |
13099 | case DW_AT_decl_line: | |
13100 | return "DW_AT_decl_line"; | |
13101 | case DW_AT_declaration: | |
13102 | return "DW_AT_declaration"; | |
13103 | case DW_AT_discr_list: | |
13104 | return "DW_AT_discr_list"; | |
13105 | case DW_AT_encoding: | |
13106 | return "DW_AT_encoding"; | |
13107 | case DW_AT_external: | |
13108 | return "DW_AT_external"; | |
13109 | case DW_AT_frame_base: | |
13110 | return "DW_AT_frame_base"; | |
13111 | case DW_AT_friend: | |
13112 | return "DW_AT_friend"; | |
13113 | case DW_AT_identifier_case: | |
13114 | return "DW_AT_identifier_case"; | |
13115 | case DW_AT_macro_info: | |
13116 | return "DW_AT_macro_info"; | |
13117 | case DW_AT_namelist_items: | |
13118 | return "DW_AT_namelist_items"; | |
13119 | case DW_AT_priority: | |
13120 | return "DW_AT_priority"; | |
13121 | case DW_AT_segment: | |
13122 | return "DW_AT_segment"; | |
13123 | case DW_AT_specification: | |
13124 | return "DW_AT_specification"; | |
13125 | case DW_AT_static_link: | |
13126 | return "DW_AT_static_link"; | |
13127 | case DW_AT_type: | |
13128 | return "DW_AT_type"; | |
13129 | case DW_AT_use_location: | |
13130 | return "DW_AT_use_location"; | |
13131 | case DW_AT_variable_parameter: | |
13132 | return "DW_AT_variable_parameter"; | |
13133 | case DW_AT_virtuality: | |
13134 | return "DW_AT_virtuality"; | |
13135 | case DW_AT_vtable_elem_location: | |
13136 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 13137 | /* DWARF 3 values. */ |
d9fa45fe DC |
13138 | case DW_AT_allocated: |
13139 | return "DW_AT_allocated"; | |
13140 | case DW_AT_associated: | |
13141 | return "DW_AT_associated"; | |
13142 | case DW_AT_data_location: | |
13143 | return "DW_AT_data_location"; | |
09fa0d7c JK |
13144 | case DW_AT_byte_stride: |
13145 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
13146 | case DW_AT_entry_pc: |
13147 | return "DW_AT_entry_pc"; | |
13148 | case DW_AT_use_UTF8: | |
13149 | return "DW_AT_use_UTF8"; | |
13150 | case DW_AT_extension: | |
13151 | return "DW_AT_extension"; | |
13152 | case DW_AT_ranges: | |
13153 | return "DW_AT_ranges"; | |
13154 | case DW_AT_trampoline: | |
13155 | return "DW_AT_trampoline"; | |
13156 | case DW_AT_call_column: | |
13157 | return "DW_AT_call_column"; | |
13158 | case DW_AT_call_file: | |
13159 | return "DW_AT_call_file"; | |
13160 | case DW_AT_call_line: | |
13161 | return "DW_AT_call_line"; | |
b7619582 GF |
13162 | case DW_AT_description: |
13163 | return "DW_AT_description"; | |
13164 | case DW_AT_binary_scale: | |
13165 | return "DW_AT_binary_scale"; | |
13166 | case DW_AT_decimal_scale: | |
13167 | return "DW_AT_decimal_scale"; | |
13168 | case DW_AT_small: | |
13169 | return "DW_AT_small"; | |
13170 | case DW_AT_decimal_sign: | |
13171 | return "DW_AT_decimal_sign"; | |
13172 | case DW_AT_digit_count: | |
13173 | return "DW_AT_digit_count"; | |
13174 | case DW_AT_picture_string: | |
13175 | return "DW_AT_picture_string"; | |
13176 | case DW_AT_mutable: | |
13177 | return "DW_AT_mutable"; | |
13178 | case DW_AT_threads_scaled: | |
13179 | return "DW_AT_threads_scaled"; | |
13180 | case DW_AT_explicit: | |
13181 | return "DW_AT_explicit"; | |
13182 | case DW_AT_object_pointer: | |
13183 | return "DW_AT_object_pointer"; | |
13184 | case DW_AT_endianity: | |
13185 | return "DW_AT_endianity"; | |
13186 | case DW_AT_elemental: | |
13187 | return "DW_AT_elemental"; | |
13188 | case DW_AT_pure: | |
13189 | return "DW_AT_pure"; | |
13190 | case DW_AT_recursive: | |
13191 | return "DW_AT_recursive"; | |
348e048f DE |
13192 | /* DWARF 4 values. */ |
13193 | case DW_AT_signature: | |
13194 | return "DW_AT_signature"; | |
31ef98ae TT |
13195 | case DW_AT_linkage_name: |
13196 | return "DW_AT_linkage_name"; | |
b7619582 | 13197 | /* SGI/MIPS extensions. */ |
c764a876 | 13198 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
13199 | case DW_AT_MIPS_fde: |
13200 | return "DW_AT_MIPS_fde"; | |
c764a876 | 13201 | #endif |
c906108c SS |
13202 | case DW_AT_MIPS_loop_begin: |
13203 | return "DW_AT_MIPS_loop_begin"; | |
13204 | case DW_AT_MIPS_tail_loop_begin: | |
13205 | return "DW_AT_MIPS_tail_loop_begin"; | |
13206 | case DW_AT_MIPS_epilog_begin: | |
13207 | return "DW_AT_MIPS_epilog_begin"; | |
13208 | case DW_AT_MIPS_loop_unroll_factor: | |
13209 | return "DW_AT_MIPS_loop_unroll_factor"; | |
13210 | case DW_AT_MIPS_software_pipeline_depth: | |
13211 | return "DW_AT_MIPS_software_pipeline_depth"; | |
13212 | case DW_AT_MIPS_linkage_name: | |
13213 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
13214 | case DW_AT_MIPS_stride: |
13215 | return "DW_AT_MIPS_stride"; | |
13216 | case DW_AT_MIPS_abstract_name: | |
13217 | return "DW_AT_MIPS_abstract_name"; | |
13218 | case DW_AT_MIPS_clone_origin: | |
13219 | return "DW_AT_MIPS_clone_origin"; | |
13220 | case DW_AT_MIPS_has_inlines: | |
13221 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 13222 | /* HP extensions. */ |
c764a876 | 13223 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
13224 | case DW_AT_HP_block_index: |
13225 | return "DW_AT_HP_block_index"; | |
c764a876 | 13226 | #endif |
b7619582 GF |
13227 | case DW_AT_HP_unmodifiable: |
13228 | return "DW_AT_HP_unmodifiable"; | |
13229 | case DW_AT_HP_actuals_stmt_list: | |
13230 | return "DW_AT_HP_actuals_stmt_list"; | |
13231 | case DW_AT_HP_proc_per_section: | |
13232 | return "DW_AT_HP_proc_per_section"; | |
13233 | case DW_AT_HP_raw_data_ptr: | |
13234 | return "DW_AT_HP_raw_data_ptr"; | |
13235 | case DW_AT_HP_pass_by_reference: | |
13236 | return "DW_AT_HP_pass_by_reference"; | |
13237 | case DW_AT_HP_opt_level: | |
13238 | return "DW_AT_HP_opt_level"; | |
13239 | case DW_AT_HP_prof_version_id: | |
13240 | return "DW_AT_HP_prof_version_id"; | |
13241 | case DW_AT_HP_opt_flags: | |
13242 | return "DW_AT_HP_opt_flags"; | |
13243 | case DW_AT_HP_cold_region_low_pc: | |
13244 | return "DW_AT_HP_cold_region_low_pc"; | |
13245 | case DW_AT_HP_cold_region_high_pc: | |
13246 | return "DW_AT_HP_cold_region_high_pc"; | |
13247 | case DW_AT_HP_all_variables_modifiable: | |
13248 | return "DW_AT_HP_all_variables_modifiable"; | |
13249 | case DW_AT_HP_linkage_name: | |
13250 | return "DW_AT_HP_linkage_name"; | |
13251 | case DW_AT_HP_prof_flags: | |
13252 | return "DW_AT_HP_prof_flags"; | |
13253 | /* GNU extensions. */ | |
c906108c SS |
13254 | case DW_AT_sf_names: |
13255 | return "DW_AT_sf_names"; | |
13256 | case DW_AT_src_info: | |
13257 | return "DW_AT_src_info"; | |
13258 | case DW_AT_mac_info: | |
13259 | return "DW_AT_mac_info"; | |
13260 | case DW_AT_src_coords: | |
13261 | return "DW_AT_src_coords"; | |
13262 | case DW_AT_body_begin: | |
13263 | return "DW_AT_body_begin"; | |
13264 | case DW_AT_body_end: | |
13265 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
13266 | case DW_AT_GNU_vector: |
13267 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
13268 | case DW_AT_GNU_odr_signature: |
13269 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
13270 | /* VMS extensions. */ |
13271 | case DW_AT_VMS_rtnbeg_pd_address: | |
13272 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
13273 | /* UPC extension. */ | |
13274 | case DW_AT_upc_threads_scaled: | |
13275 | return "DW_AT_upc_threads_scaled"; | |
13276 | /* PGI (STMicroelectronics) extensions. */ | |
13277 | case DW_AT_PGI_lbase: | |
13278 | return "DW_AT_PGI_lbase"; | |
13279 | case DW_AT_PGI_soffset: | |
13280 | return "DW_AT_PGI_soffset"; | |
13281 | case DW_AT_PGI_lstride: | |
13282 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
13283 | default: |
13284 | return "DW_AT_<unknown>"; | |
13285 | } | |
13286 | } | |
13287 | ||
13288 | /* Convert a DWARF value form code into its string name. */ | |
13289 | ||
13290 | static char * | |
aa1ee363 | 13291 | dwarf_form_name (unsigned form) |
c906108c SS |
13292 | { |
13293 | switch (form) | |
13294 | { | |
13295 | case DW_FORM_addr: | |
13296 | return "DW_FORM_addr"; | |
13297 | case DW_FORM_block2: | |
13298 | return "DW_FORM_block2"; | |
13299 | case DW_FORM_block4: | |
13300 | return "DW_FORM_block4"; | |
13301 | case DW_FORM_data2: | |
13302 | return "DW_FORM_data2"; | |
13303 | case DW_FORM_data4: | |
13304 | return "DW_FORM_data4"; | |
13305 | case DW_FORM_data8: | |
13306 | return "DW_FORM_data8"; | |
13307 | case DW_FORM_string: | |
13308 | return "DW_FORM_string"; | |
13309 | case DW_FORM_block: | |
13310 | return "DW_FORM_block"; | |
13311 | case DW_FORM_block1: | |
13312 | return "DW_FORM_block1"; | |
13313 | case DW_FORM_data1: | |
13314 | return "DW_FORM_data1"; | |
13315 | case DW_FORM_flag: | |
13316 | return "DW_FORM_flag"; | |
13317 | case DW_FORM_sdata: | |
13318 | return "DW_FORM_sdata"; | |
13319 | case DW_FORM_strp: | |
13320 | return "DW_FORM_strp"; | |
13321 | case DW_FORM_udata: | |
13322 | return "DW_FORM_udata"; | |
13323 | case DW_FORM_ref_addr: | |
13324 | return "DW_FORM_ref_addr"; | |
13325 | case DW_FORM_ref1: | |
13326 | return "DW_FORM_ref1"; | |
13327 | case DW_FORM_ref2: | |
13328 | return "DW_FORM_ref2"; | |
13329 | case DW_FORM_ref4: | |
13330 | return "DW_FORM_ref4"; | |
13331 | case DW_FORM_ref8: | |
13332 | return "DW_FORM_ref8"; | |
13333 | case DW_FORM_ref_udata: | |
13334 | return "DW_FORM_ref_udata"; | |
13335 | case DW_FORM_indirect: | |
13336 | return "DW_FORM_indirect"; | |
348e048f DE |
13337 | case DW_FORM_sec_offset: |
13338 | return "DW_FORM_sec_offset"; | |
13339 | case DW_FORM_exprloc: | |
13340 | return "DW_FORM_exprloc"; | |
13341 | case DW_FORM_flag_present: | |
13342 | return "DW_FORM_flag_present"; | |
55f1336d TT |
13343 | case DW_FORM_ref_sig8: |
13344 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
13345 | default: |
13346 | return "DW_FORM_<unknown>"; | |
13347 | } | |
13348 | } | |
13349 | ||
13350 | /* Convert a DWARF stack opcode into its string name. */ | |
13351 | ||
9eae7c52 | 13352 | const char * |
b1bfef65 | 13353 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
13354 | { |
13355 | switch (op) | |
13356 | { | |
13357 | case DW_OP_addr: | |
13358 | return "DW_OP_addr"; | |
13359 | case DW_OP_deref: | |
13360 | return "DW_OP_deref"; | |
13361 | case DW_OP_const1u: | |
13362 | return "DW_OP_const1u"; | |
13363 | case DW_OP_const1s: | |
13364 | return "DW_OP_const1s"; | |
13365 | case DW_OP_const2u: | |
13366 | return "DW_OP_const2u"; | |
13367 | case DW_OP_const2s: | |
13368 | return "DW_OP_const2s"; | |
13369 | case DW_OP_const4u: | |
13370 | return "DW_OP_const4u"; | |
13371 | case DW_OP_const4s: | |
13372 | return "DW_OP_const4s"; | |
13373 | case DW_OP_const8u: | |
13374 | return "DW_OP_const8u"; | |
13375 | case DW_OP_const8s: | |
13376 | return "DW_OP_const8s"; | |
13377 | case DW_OP_constu: | |
13378 | return "DW_OP_constu"; | |
13379 | case DW_OP_consts: | |
13380 | return "DW_OP_consts"; | |
13381 | case DW_OP_dup: | |
13382 | return "DW_OP_dup"; | |
13383 | case DW_OP_drop: | |
13384 | return "DW_OP_drop"; | |
13385 | case DW_OP_over: | |
13386 | return "DW_OP_over"; | |
13387 | case DW_OP_pick: | |
13388 | return "DW_OP_pick"; | |
13389 | case DW_OP_swap: | |
13390 | return "DW_OP_swap"; | |
13391 | case DW_OP_rot: | |
13392 | return "DW_OP_rot"; | |
13393 | case DW_OP_xderef: | |
13394 | return "DW_OP_xderef"; | |
13395 | case DW_OP_abs: | |
13396 | return "DW_OP_abs"; | |
13397 | case DW_OP_and: | |
13398 | return "DW_OP_and"; | |
13399 | case DW_OP_div: | |
13400 | return "DW_OP_div"; | |
13401 | case DW_OP_minus: | |
13402 | return "DW_OP_minus"; | |
13403 | case DW_OP_mod: | |
13404 | return "DW_OP_mod"; | |
13405 | case DW_OP_mul: | |
13406 | return "DW_OP_mul"; | |
13407 | case DW_OP_neg: | |
13408 | return "DW_OP_neg"; | |
13409 | case DW_OP_not: | |
13410 | return "DW_OP_not"; | |
13411 | case DW_OP_or: | |
13412 | return "DW_OP_or"; | |
13413 | case DW_OP_plus: | |
13414 | return "DW_OP_plus"; | |
13415 | case DW_OP_plus_uconst: | |
13416 | return "DW_OP_plus_uconst"; | |
13417 | case DW_OP_shl: | |
13418 | return "DW_OP_shl"; | |
13419 | case DW_OP_shr: | |
13420 | return "DW_OP_shr"; | |
13421 | case DW_OP_shra: | |
13422 | return "DW_OP_shra"; | |
13423 | case DW_OP_xor: | |
13424 | return "DW_OP_xor"; | |
13425 | case DW_OP_bra: | |
13426 | return "DW_OP_bra"; | |
13427 | case DW_OP_eq: | |
13428 | return "DW_OP_eq"; | |
13429 | case DW_OP_ge: | |
13430 | return "DW_OP_ge"; | |
13431 | case DW_OP_gt: | |
13432 | return "DW_OP_gt"; | |
13433 | case DW_OP_le: | |
13434 | return "DW_OP_le"; | |
13435 | case DW_OP_lt: | |
13436 | return "DW_OP_lt"; | |
13437 | case DW_OP_ne: | |
13438 | return "DW_OP_ne"; | |
13439 | case DW_OP_skip: | |
13440 | return "DW_OP_skip"; | |
13441 | case DW_OP_lit0: | |
13442 | return "DW_OP_lit0"; | |
13443 | case DW_OP_lit1: | |
13444 | return "DW_OP_lit1"; | |
13445 | case DW_OP_lit2: | |
13446 | return "DW_OP_lit2"; | |
13447 | case DW_OP_lit3: | |
13448 | return "DW_OP_lit3"; | |
13449 | case DW_OP_lit4: | |
13450 | return "DW_OP_lit4"; | |
13451 | case DW_OP_lit5: | |
13452 | return "DW_OP_lit5"; | |
13453 | case DW_OP_lit6: | |
13454 | return "DW_OP_lit6"; | |
13455 | case DW_OP_lit7: | |
13456 | return "DW_OP_lit7"; | |
13457 | case DW_OP_lit8: | |
13458 | return "DW_OP_lit8"; | |
13459 | case DW_OP_lit9: | |
13460 | return "DW_OP_lit9"; | |
13461 | case DW_OP_lit10: | |
13462 | return "DW_OP_lit10"; | |
13463 | case DW_OP_lit11: | |
13464 | return "DW_OP_lit11"; | |
13465 | case DW_OP_lit12: | |
13466 | return "DW_OP_lit12"; | |
13467 | case DW_OP_lit13: | |
13468 | return "DW_OP_lit13"; | |
13469 | case DW_OP_lit14: | |
13470 | return "DW_OP_lit14"; | |
13471 | case DW_OP_lit15: | |
13472 | return "DW_OP_lit15"; | |
13473 | case DW_OP_lit16: | |
13474 | return "DW_OP_lit16"; | |
13475 | case DW_OP_lit17: | |
13476 | return "DW_OP_lit17"; | |
13477 | case DW_OP_lit18: | |
13478 | return "DW_OP_lit18"; | |
13479 | case DW_OP_lit19: | |
13480 | return "DW_OP_lit19"; | |
13481 | case DW_OP_lit20: | |
13482 | return "DW_OP_lit20"; | |
13483 | case DW_OP_lit21: | |
13484 | return "DW_OP_lit21"; | |
13485 | case DW_OP_lit22: | |
13486 | return "DW_OP_lit22"; | |
13487 | case DW_OP_lit23: | |
13488 | return "DW_OP_lit23"; | |
13489 | case DW_OP_lit24: | |
13490 | return "DW_OP_lit24"; | |
13491 | case DW_OP_lit25: | |
13492 | return "DW_OP_lit25"; | |
13493 | case DW_OP_lit26: | |
13494 | return "DW_OP_lit26"; | |
13495 | case DW_OP_lit27: | |
13496 | return "DW_OP_lit27"; | |
13497 | case DW_OP_lit28: | |
13498 | return "DW_OP_lit28"; | |
13499 | case DW_OP_lit29: | |
13500 | return "DW_OP_lit29"; | |
13501 | case DW_OP_lit30: | |
13502 | return "DW_OP_lit30"; | |
13503 | case DW_OP_lit31: | |
13504 | return "DW_OP_lit31"; | |
13505 | case DW_OP_reg0: | |
13506 | return "DW_OP_reg0"; | |
13507 | case DW_OP_reg1: | |
13508 | return "DW_OP_reg1"; | |
13509 | case DW_OP_reg2: | |
13510 | return "DW_OP_reg2"; | |
13511 | case DW_OP_reg3: | |
13512 | return "DW_OP_reg3"; | |
13513 | case DW_OP_reg4: | |
13514 | return "DW_OP_reg4"; | |
13515 | case DW_OP_reg5: | |
13516 | return "DW_OP_reg5"; | |
13517 | case DW_OP_reg6: | |
13518 | return "DW_OP_reg6"; | |
13519 | case DW_OP_reg7: | |
13520 | return "DW_OP_reg7"; | |
13521 | case DW_OP_reg8: | |
13522 | return "DW_OP_reg8"; | |
13523 | case DW_OP_reg9: | |
13524 | return "DW_OP_reg9"; | |
13525 | case DW_OP_reg10: | |
13526 | return "DW_OP_reg10"; | |
13527 | case DW_OP_reg11: | |
13528 | return "DW_OP_reg11"; | |
13529 | case DW_OP_reg12: | |
13530 | return "DW_OP_reg12"; | |
13531 | case DW_OP_reg13: | |
13532 | return "DW_OP_reg13"; | |
13533 | case DW_OP_reg14: | |
13534 | return "DW_OP_reg14"; | |
13535 | case DW_OP_reg15: | |
13536 | return "DW_OP_reg15"; | |
13537 | case DW_OP_reg16: | |
13538 | return "DW_OP_reg16"; | |
13539 | case DW_OP_reg17: | |
13540 | return "DW_OP_reg17"; | |
13541 | case DW_OP_reg18: | |
13542 | return "DW_OP_reg18"; | |
13543 | case DW_OP_reg19: | |
13544 | return "DW_OP_reg19"; | |
13545 | case DW_OP_reg20: | |
13546 | return "DW_OP_reg20"; | |
13547 | case DW_OP_reg21: | |
13548 | return "DW_OP_reg21"; | |
13549 | case DW_OP_reg22: | |
13550 | return "DW_OP_reg22"; | |
13551 | case DW_OP_reg23: | |
13552 | return "DW_OP_reg23"; | |
13553 | case DW_OP_reg24: | |
13554 | return "DW_OP_reg24"; | |
13555 | case DW_OP_reg25: | |
13556 | return "DW_OP_reg25"; | |
13557 | case DW_OP_reg26: | |
13558 | return "DW_OP_reg26"; | |
13559 | case DW_OP_reg27: | |
13560 | return "DW_OP_reg27"; | |
13561 | case DW_OP_reg28: | |
13562 | return "DW_OP_reg28"; | |
13563 | case DW_OP_reg29: | |
13564 | return "DW_OP_reg29"; | |
13565 | case DW_OP_reg30: | |
13566 | return "DW_OP_reg30"; | |
13567 | case DW_OP_reg31: | |
13568 | return "DW_OP_reg31"; | |
13569 | case DW_OP_breg0: | |
13570 | return "DW_OP_breg0"; | |
13571 | case DW_OP_breg1: | |
13572 | return "DW_OP_breg1"; | |
13573 | case DW_OP_breg2: | |
13574 | return "DW_OP_breg2"; | |
13575 | case DW_OP_breg3: | |
13576 | return "DW_OP_breg3"; | |
13577 | case DW_OP_breg4: | |
13578 | return "DW_OP_breg4"; | |
13579 | case DW_OP_breg5: | |
13580 | return "DW_OP_breg5"; | |
13581 | case DW_OP_breg6: | |
13582 | return "DW_OP_breg6"; | |
13583 | case DW_OP_breg7: | |
13584 | return "DW_OP_breg7"; | |
13585 | case DW_OP_breg8: | |
13586 | return "DW_OP_breg8"; | |
13587 | case DW_OP_breg9: | |
13588 | return "DW_OP_breg9"; | |
13589 | case DW_OP_breg10: | |
13590 | return "DW_OP_breg10"; | |
13591 | case DW_OP_breg11: | |
13592 | return "DW_OP_breg11"; | |
13593 | case DW_OP_breg12: | |
13594 | return "DW_OP_breg12"; | |
13595 | case DW_OP_breg13: | |
13596 | return "DW_OP_breg13"; | |
13597 | case DW_OP_breg14: | |
13598 | return "DW_OP_breg14"; | |
13599 | case DW_OP_breg15: | |
13600 | return "DW_OP_breg15"; | |
13601 | case DW_OP_breg16: | |
13602 | return "DW_OP_breg16"; | |
13603 | case DW_OP_breg17: | |
13604 | return "DW_OP_breg17"; | |
13605 | case DW_OP_breg18: | |
13606 | return "DW_OP_breg18"; | |
13607 | case DW_OP_breg19: | |
13608 | return "DW_OP_breg19"; | |
13609 | case DW_OP_breg20: | |
13610 | return "DW_OP_breg20"; | |
13611 | case DW_OP_breg21: | |
13612 | return "DW_OP_breg21"; | |
13613 | case DW_OP_breg22: | |
13614 | return "DW_OP_breg22"; | |
13615 | case DW_OP_breg23: | |
13616 | return "DW_OP_breg23"; | |
13617 | case DW_OP_breg24: | |
13618 | return "DW_OP_breg24"; | |
13619 | case DW_OP_breg25: | |
13620 | return "DW_OP_breg25"; | |
13621 | case DW_OP_breg26: | |
13622 | return "DW_OP_breg26"; | |
13623 | case DW_OP_breg27: | |
13624 | return "DW_OP_breg27"; | |
13625 | case DW_OP_breg28: | |
13626 | return "DW_OP_breg28"; | |
13627 | case DW_OP_breg29: | |
13628 | return "DW_OP_breg29"; | |
13629 | case DW_OP_breg30: | |
13630 | return "DW_OP_breg30"; | |
13631 | case DW_OP_breg31: | |
13632 | return "DW_OP_breg31"; | |
13633 | case DW_OP_regx: | |
13634 | return "DW_OP_regx"; | |
13635 | case DW_OP_fbreg: | |
13636 | return "DW_OP_fbreg"; | |
13637 | case DW_OP_bregx: | |
13638 | return "DW_OP_bregx"; | |
13639 | case DW_OP_piece: | |
13640 | return "DW_OP_piece"; | |
13641 | case DW_OP_deref_size: | |
13642 | return "DW_OP_deref_size"; | |
13643 | case DW_OP_xderef_size: | |
13644 | return "DW_OP_xderef_size"; | |
13645 | case DW_OP_nop: | |
13646 | return "DW_OP_nop"; | |
b7619582 | 13647 | /* DWARF 3 extensions. */ |
ed348acc EZ |
13648 | case DW_OP_push_object_address: |
13649 | return "DW_OP_push_object_address"; | |
13650 | case DW_OP_call2: | |
13651 | return "DW_OP_call2"; | |
13652 | case DW_OP_call4: | |
13653 | return "DW_OP_call4"; | |
13654 | case DW_OP_call_ref: | |
13655 | return "DW_OP_call_ref"; | |
b7619582 GF |
13656 | case DW_OP_form_tls_address: |
13657 | return "DW_OP_form_tls_address"; | |
13658 | case DW_OP_call_frame_cfa: | |
13659 | return "DW_OP_call_frame_cfa"; | |
13660 | case DW_OP_bit_piece: | |
13661 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
13662 | /* DWARF 4 extensions. */ |
13663 | case DW_OP_implicit_value: | |
13664 | return "DW_OP_implicit_value"; | |
13665 | case DW_OP_stack_value: | |
13666 | return "DW_OP_stack_value"; | |
13667 | /* GNU extensions. */ | |
ed348acc EZ |
13668 | case DW_OP_GNU_push_tls_address: |
13669 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
13670 | case DW_OP_GNU_uninit: |
13671 | return "DW_OP_GNU_uninit"; | |
8cf6f0b1 TT |
13672 | case DW_OP_GNU_implicit_pointer: |
13673 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
13674 | case DW_OP_GNU_entry_value: |
13675 | return "DW_OP_GNU_entry_value"; | |
13676 | case DW_OP_GNU_const_type: | |
13677 | return "DW_OP_GNU_const_type"; | |
13678 | case DW_OP_GNU_regval_type: | |
13679 | return "DW_OP_GNU_regval_type"; | |
13680 | case DW_OP_GNU_deref_type: | |
13681 | return "DW_OP_GNU_deref_type"; | |
13682 | case DW_OP_GNU_convert: | |
13683 | return "DW_OP_GNU_convert"; | |
13684 | case DW_OP_GNU_reinterpret: | |
13685 | return "DW_OP_GNU_reinterpret"; | |
c906108c | 13686 | default: |
b1bfef65 | 13687 | return NULL; |
c906108c SS |
13688 | } |
13689 | } | |
13690 | ||
13691 | static char * | |
fba45db2 | 13692 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
13693 | { |
13694 | if (mybool) | |
13695 | return "TRUE"; | |
13696 | else | |
13697 | return "FALSE"; | |
13698 | } | |
13699 | ||
13700 | /* Convert a DWARF type code into its string name. */ | |
13701 | ||
13702 | static char * | |
aa1ee363 | 13703 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
13704 | { |
13705 | switch (enc) | |
13706 | { | |
b7619582 GF |
13707 | case DW_ATE_void: |
13708 | return "DW_ATE_void"; | |
c906108c SS |
13709 | case DW_ATE_address: |
13710 | return "DW_ATE_address"; | |
13711 | case DW_ATE_boolean: | |
13712 | return "DW_ATE_boolean"; | |
13713 | case DW_ATE_complex_float: | |
13714 | return "DW_ATE_complex_float"; | |
13715 | case DW_ATE_float: | |
13716 | return "DW_ATE_float"; | |
13717 | case DW_ATE_signed: | |
13718 | return "DW_ATE_signed"; | |
13719 | case DW_ATE_signed_char: | |
13720 | return "DW_ATE_signed_char"; | |
13721 | case DW_ATE_unsigned: | |
13722 | return "DW_ATE_unsigned"; | |
13723 | case DW_ATE_unsigned_char: | |
13724 | return "DW_ATE_unsigned_char"; | |
b7619582 | 13725 | /* DWARF 3. */ |
d9fa45fe DC |
13726 | case DW_ATE_imaginary_float: |
13727 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
13728 | case DW_ATE_packed_decimal: |
13729 | return "DW_ATE_packed_decimal"; | |
13730 | case DW_ATE_numeric_string: | |
13731 | return "DW_ATE_numeric_string"; | |
13732 | case DW_ATE_edited: | |
13733 | return "DW_ATE_edited"; | |
13734 | case DW_ATE_signed_fixed: | |
13735 | return "DW_ATE_signed_fixed"; | |
13736 | case DW_ATE_unsigned_fixed: | |
13737 | return "DW_ATE_unsigned_fixed"; | |
13738 | case DW_ATE_decimal_float: | |
13739 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
13740 | /* DWARF 4. */ |
13741 | case DW_ATE_UTF: | |
13742 | return "DW_ATE_UTF"; | |
b7619582 GF |
13743 | /* HP extensions. */ |
13744 | case DW_ATE_HP_float80: | |
13745 | return "DW_ATE_HP_float80"; | |
13746 | case DW_ATE_HP_complex_float80: | |
13747 | return "DW_ATE_HP_complex_float80"; | |
13748 | case DW_ATE_HP_float128: | |
13749 | return "DW_ATE_HP_float128"; | |
13750 | case DW_ATE_HP_complex_float128: | |
13751 | return "DW_ATE_HP_complex_float128"; | |
13752 | case DW_ATE_HP_floathpintel: | |
13753 | return "DW_ATE_HP_floathpintel"; | |
13754 | case DW_ATE_HP_imaginary_float80: | |
13755 | return "DW_ATE_HP_imaginary_float80"; | |
13756 | case DW_ATE_HP_imaginary_float128: | |
13757 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
13758 | default: |
13759 | return "DW_ATE_<unknown>"; | |
13760 | } | |
13761 | } | |
13762 | ||
0963b4bd | 13763 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
13764 | |
13765 | #if 0 | |
13766 | static char * | |
aa1ee363 | 13767 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
13768 | { |
13769 | switch (cfi_opc) | |
13770 | { | |
13771 | case DW_CFA_advance_loc: | |
13772 | return "DW_CFA_advance_loc"; | |
13773 | case DW_CFA_offset: | |
13774 | return "DW_CFA_offset"; | |
13775 | case DW_CFA_restore: | |
13776 | return "DW_CFA_restore"; | |
13777 | case DW_CFA_nop: | |
13778 | return "DW_CFA_nop"; | |
13779 | case DW_CFA_set_loc: | |
13780 | return "DW_CFA_set_loc"; | |
13781 | case DW_CFA_advance_loc1: | |
13782 | return "DW_CFA_advance_loc1"; | |
13783 | case DW_CFA_advance_loc2: | |
13784 | return "DW_CFA_advance_loc2"; | |
13785 | case DW_CFA_advance_loc4: | |
13786 | return "DW_CFA_advance_loc4"; | |
13787 | case DW_CFA_offset_extended: | |
13788 | return "DW_CFA_offset_extended"; | |
13789 | case DW_CFA_restore_extended: | |
13790 | return "DW_CFA_restore_extended"; | |
13791 | case DW_CFA_undefined: | |
13792 | return "DW_CFA_undefined"; | |
13793 | case DW_CFA_same_value: | |
13794 | return "DW_CFA_same_value"; | |
13795 | case DW_CFA_register: | |
13796 | return "DW_CFA_register"; | |
13797 | case DW_CFA_remember_state: | |
13798 | return "DW_CFA_remember_state"; | |
13799 | case DW_CFA_restore_state: | |
13800 | return "DW_CFA_restore_state"; | |
13801 | case DW_CFA_def_cfa: | |
13802 | return "DW_CFA_def_cfa"; | |
13803 | case DW_CFA_def_cfa_register: | |
13804 | return "DW_CFA_def_cfa_register"; | |
13805 | case DW_CFA_def_cfa_offset: | |
13806 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 13807 | /* DWARF 3. */ |
985cb1a3 JM |
13808 | case DW_CFA_def_cfa_expression: |
13809 | return "DW_CFA_def_cfa_expression"; | |
13810 | case DW_CFA_expression: | |
13811 | return "DW_CFA_expression"; | |
13812 | case DW_CFA_offset_extended_sf: | |
13813 | return "DW_CFA_offset_extended_sf"; | |
13814 | case DW_CFA_def_cfa_sf: | |
13815 | return "DW_CFA_def_cfa_sf"; | |
13816 | case DW_CFA_def_cfa_offset_sf: | |
13817 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
13818 | case DW_CFA_val_offset: |
13819 | return "DW_CFA_val_offset"; | |
13820 | case DW_CFA_val_offset_sf: | |
13821 | return "DW_CFA_val_offset_sf"; | |
13822 | case DW_CFA_val_expression: | |
13823 | return "DW_CFA_val_expression"; | |
13824 | /* SGI/MIPS specific. */ | |
c906108c SS |
13825 | case DW_CFA_MIPS_advance_loc8: |
13826 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 13827 | /* GNU extensions. */ |
985cb1a3 JM |
13828 | case DW_CFA_GNU_window_save: |
13829 | return "DW_CFA_GNU_window_save"; | |
13830 | case DW_CFA_GNU_args_size: | |
13831 | return "DW_CFA_GNU_args_size"; | |
13832 | case DW_CFA_GNU_negative_offset_extended: | |
13833 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
13834 | default: |
13835 | return "DW_CFA_<unknown>"; | |
13836 | } | |
13837 | } | |
13838 | #endif | |
13839 | ||
f9aca02d | 13840 | static void |
d97bc12b | 13841 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
13842 | { |
13843 | unsigned int i; | |
13844 | ||
d97bc12b DE |
13845 | print_spaces (indent, f); |
13846 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 13847 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
13848 | |
13849 | if (die->parent != NULL) | |
13850 | { | |
13851 | print_spaces (indent, f); | |
13852 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
13853 | die->parent->offset); | |
13854 | } | |
13855 | ||
13856 | print_spaces (indent, f); | |
13857 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 13858 | dwarf_bool_name (die->child != NULL)); |
c906108c | 13859 | |
d97bc12b DE |
13860 | print_spaces (indent, f); |
13861 | fprintf_unfiltered (f, " attributes:\n"); | |
13862 | ||
c906108c SS |
13863 | for (i = 0; i < die->num_attrs; ++i) |
13864 | { | |
d97bc12b DE |
13865 | print_spaces (indent, f); |
13866 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
13867 | dwarf_attr_name (die->attrs[i].name), |
13868 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 13869 | |
c906108c SS |
13870 | switch (die->attrs[i].form) |
13871 | { | |
13872 | case DW_FORM_ref_addr: | |
13873 | case DW_FORM_addr: | |
d97bc12b | 13874 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 13875 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
13876 | break; |
13877 | case DW_FORM_block2: | |
13878 | case DW_FORM_block4: | |
13879 | case DW_FORM_block: | |
13880 | case DW_FORM_block1: | |
3e43a32a MS |
13881 | fprintf_unfiltered (f, "block: size %d", |
13882 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 13883 | break; |
2dc7f7b3 TT |
13884 | case DW_FORM_exprloc: |
13885 | fprintf_unfiltered (f, "expression: size %u", | |
13886 | DW_BLOCK (&die->attrs[i])->size); | |
13887 | break; | |
10b3939b DJ |
13888 | case DW_FORM_ref1: |
13889 | case DW_FORM_ref2: | |
13890 | case DW_FORM_ref4: | |
d97bc12b | 13891 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
13892 | (long) (DW_ADDR (&die->attrs[i]))); |
13893 | break; | |
c906108c SS |
13894 | case DW_FORM_data1: |
13895 | case DW_FORM_data2: | |
13896 | case DW_FORM_data4: | |
ce5d95e1 | 13897 | case DW_FORM_data8: |
c906108c SS |
13898 | case DW_FORM_udata: |
13899 | case DW_FORM_sdata: | |
43bbcdc2 PH |
13900 | fprintf_unfiltered (f, "constant: %s", |
13901 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 13902 | break; |
2dc7f7b3 TT |
13903 | case DW_FORM_sec_offset: |
13904 | fprintf_unfiltered (f, "section offset: %s", | |
13905 | pulongest (DW_UNSND (&die->attrs[i]))); | |
13906 | break; | |
55f1336d | 13907 | case DW_FORM_ref_sig8: |
348e048f DE |
13908 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
13909 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b3c8eb43 | 13910 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset); |
348e048f DE |
13911 | else |
13912 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
13913 | break; | |
c906108c | 13914 | case DW_FORM_string: |
4bdf3d34 | 13915 | case DW_FORM_strp: |
8285870a | 13916 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 13917 | DW_STRING (&die->attrs[i]) |
8285870a JK |
13918 | ? DW_STRING (&die->attrs[i]) : "", |
13919 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
13920 | break; |
13921 | case DW_FORM_flag: | |
13922 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 13923 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 13924 | else |
d97bc12b | 13925 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 13926 | break; |
2dc7f7b3 TT |
13927 | case DW_FORM_flag_present: |
13928 | fprintf_unfiltered (f, "flag: TRUE"); | |
13929 | break; | |
a8329558 | 13930 | case DW_FORM_indirect: |
0963b4bd MS |
13931 | /* The reader will have reduced the indirect form to |
13932 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
13933 | fprintf_unfiltered (f, |
13934 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 13935 | break; |
c906108c | 13936 | default: |
d97bc12b | 13937 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 13938 | die->attrs[i].form); |
d97bc12b | 13939 | break; |
c906108c | 13940 | } |
d97bc12b | 13941 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
13942 | } |
13943 | } | |
13944 | ||
f9aca02d | 13945 | static void |
d97bc12b | 13946 | dump_die_for_error (struct die_info *die) |
c906108c | 13947 | { |
d97bc12b DE |
13948 | dump_die_shallow (gdb_stderr, 0, die); |
13949 | } | |
13950 | ||
13951 | static void | |
13952 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
13953 | { | |
13954 | int indent = level * 4; | |
13955 | ||
13956 | gdb_assert (die != NULL); | |
13957 | ||
13958 | if (level >= max_level) | |
13959 | return; | |
13960 | ||
13961 | dump_die_shallow (f, indent, die); | |
13962 | ||
13963 | if (die->child != NULL) | |
c906108c | 13964 | { |
d97bc12b DE |
13965 | print_spaces (indent, f); |
13966 | fprintf_unfiltered (f, " Children:"); | |
13967 | if (level + 1 < max_level) | |
13968 | { | |
13969 | fprintf_unfiltered (f, "\n"); | |
13970 | dump_die_1 (f, level + 1, max_level, die->child); | |
13971 | } | |
13972 | else | |
13973 | { | |
3e43a32a MS |
13974 | fprintf_unfiltered (f, |
13975 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
13976 | } |
13977 | } | |
13978 | ||
13979 | if (die->sibling != NULL && level > 0) | |
13980 | { | |
13981 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
13982 | } |
13983 | } | |
13984 | ||
d97bc12b DE |
13985 | /* This is called from the pdie macro in gdbinit.in. |
13986 | It's not static so gcc will keep a copy callable from gdb. */ | |
13987 | ||
13988 | void | |
13989 | dump_die (struct die_info *die, int max_level) | |
13990 | { | |
13991 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
13992 | } | |
13993 | ||
f9aca02d | 13994 | static void |
51545339 | 13995 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13996 | { |
51545339 | 13997 | void **slot; |
c906108c | 13998 | |
51545339 DJ |
13999 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
14000 | ||
14001 | *slot = die; | |
c906108c SS |
14002 | } |
14003 | ||
93311388 DE |
14004 | static int |
14005 | is_ref_attr (struct attribute *attr) | |
c906108c | 14006 | { |
c906108c SS |
14007 | switch (attr->form) |
14008 | { | |
14009 | case DW_FORM_ref_addr: | |
c906108c SS |
14010 | case DW_FORM_ref1: |
14011 | case DW_FORM_ref2: | |
14012 | case DW_FORM_ref4: | |
613e1657 | 14013 | case DW_FORM_ref8: |
c906108c | 14014 | case DW_FORM_ref_udata: |
93311388 | 14015 | return 1; |
c906108c | 14016 | default: |
93311388 | 14017 | return 0; |
c906108c | 14018 | } |
93311388 DE |
14019 | } |
14020 | ||
14021 | static unsigned int | |
14022 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
14023 | { | |
14024 | if (is_ref_attr (attr)) | |
14025 | return DW_ADDR (attr); | |
14026 | ||
14027 | complaint (&symfile_complaints, | |
14028 | _("unsupported die ref attribute form: '%s'"), | |
14029 | dwarf_form_name (attr->form)); | |
14030 | return 0; | |
c906108c SS |
14031 | } |
14032 | ||
43bbcdc2 PH |
14033 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
14034 | * the value held by the attribute is not constant. */ | |
a02abb62 | 14035 | |
43bbcdc2 | 14036 | static LONGEST |
a02abb62 JB |
14037 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
14038 | { | |
14039 | if (attr->form == DW_FORM_sdata) | |
14040 | return DW_SND (attr); | |
14041 | else if (attr->form == DW_FORM_udata | |
14042 | || attr->form == DW_FORM_data1 | |
14043 | || attr->form == DW_FORM_data2 | |
14044 | || attr->form == DW_FORM_data4 | |
14045 | || attr->form == DW_FORM_data8) | |
14046 | return DW_UNSND (attr); | |
14047 | else | |
14048 | { | |
3e43a32a MS |
14049 | complaint (&symfile_complaints, |
14050 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
14051 | dwarf_form_name (attr->form)); |
14052 | return default_value; | |
14053 | } | |
14054 | } | |
14055 | ||
03dd20cc | 14056 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
14057 | unit and add it to our queue. |
14058 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
14059 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 14060 | |
348e048f | 14061 | static int |
03dd20cc DJ |
14062 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
14063 | struct dwarf2_per_cu_data *per_cu) | |
14064 | { | |
98bfdba5 PA |
14065 | /* We may arrive here during partial symbol reading, if we need full |
14066 | DIEs to process an unusual case (e.g. template arguments). Do | |
14067 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
14068 | if (dwarf2_per_objfile->reading_partial_symbols) | |
14069 | { | |
14070 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
14071 | return 1; | |
14072 | return 0; | |
14073 | } | |
14074 | ||
03dd20cc DJ |
14075 | /* Mark the dependence relation so that we don't flush PER_CU |
14076 | too early. */ | |
14077 | dwarf2_add_dependence (this_cu, per_cu); | |
14078 | ||
14079 | /* If it's already on the queue, we have nothing to do. */ | |
14080 | if (per_cu->queued) | |
348e048f | 14081 | return 0; |
03dd20cc DJ |
14082 | |
14083 | /* If the compilation unit is already loaded, just mark it as | |
14084 | used. */ | |
14085 | if (per_cu->cu != NULL) | |
14086 | { | |
14087 | per_cu->cu->last_used = 0; | |
348e048f | 14088 | return 0; |
03dd20cc DJ |
14089 | } |
14090 | ||
14091 | /* Add it to the queue. */ | |
14092 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
14093 | |
14094 | return 1; | |
14095 | } | |
14096 | ||
14097 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
14098 | On entry *REF_CU is the CU of SRC_DIE. | |
14099 | On exit *REF_CU is the CU of the result. */ | |
14100 | ||
14101 | static struct die_info * | |
14102 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
14103 | struct dwarf2_cu **ref_cu) | |
14104 | { | |
14105 | struct die_info *die; | |
14106 | ||
14107 | if (is_ref_attr (attr)) | |
14108 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 14109 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
14110 | die = follow_die_sig (src_die, attr, ref_cu); |
14111 | else | |
14112 | { | |
14113 | dump_die_for_error (src_die); | |
14114 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
14115 | (*ref_cu)->objfile->name); | |
14116 | } | |
14117 | ||
14118 | return die; | |
03dd20cc DJ |
14119 | } |
14120 | ||
5c631832 | 14121 | /* Follow reference OFFSET. |
673bfd45 DE |
14122 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
14123 | On exit *REF_CU is the CU of the result. | |
14124 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 14125 | |
f9aca02d | 14126 | static struct die_info * |
5c631832 | 14127 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 14128 | { |
10b3939b | 14129 | struct die_info temp_die; |
f2f0e013 | 14130 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 14131 | |
348e048f DE |
14132 | gdb_assert (cu->per_cu != NULL); |
14133 | ||
98bfdba5 PA |
14134 | target_cu = cu; |
14135 | ||
8b70b953 | 14136 | if (cu->per_cu->debug_type_section) |
348e048f DE |
14137 | { |
14138 | /* .debug_types CUs cannot reference anything outside their CU. | |
14139 | If they need to, they have to reference a signatured type via | |
55f1336d | 14140 | DW_FORM_ref_sig8. */ |
348e048f | 14141 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 14142 | return NULL; |
348e048f DE |
14143 | } |
14144 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
14145 | { |
14146 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 14147 | |
45452591 | 14148 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
14149 | |
14150 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
14151 | if (maybe_queue_comp_unit (cu, per_cu)) |
14152 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 14153 | |
10b3939b DJ |
14154 | target_cu = per_cu->cu; |
14155 | } | |
98bfdba5 PA |
14156 | else if (cu->dies == NULL) |
14157 | { | |
14158 | /* We're loading full DIEs during partial symbol reading. */ | |
14159 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
14160 | load_full_comp_unit (cu->per_cu, cu->objfile); | |
14161 | } | |
c906108c | 14162 | |
f2f0e013 | 14163 | *ref_cu = target_cu; |
51545339 | 14164 | temp_die.offset = offset; |
5c631832 JK |
14165 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
14166 | } | |
10b3939b | 14167 | |
5c631832 JK |
14168 | /* Follow reference attribute ATTR of SRC_DIE. |
14169 | On entry *REF_CU is the CU of SRC_DIE. | |
14170 | On exit *REF_CU is the CU of the result. */ | |
14171 | ||
14172 | static struct die_info * | |
14173 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
14174 | struct dwarf2_cu **ref_cu) | |
14175 | { | |
14176 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
14177 | struct dwarf2_cu *cu = *ref_cu; | |
14178 | struct die_info *die; | |
14179 | ||
14180 | die = follow_die_offset (offset, ref_cu); | |
14181 | if (!die) | |
14182 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
14183 | "at 0x%x [in module %s]"), | |
14184 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 14185 | |
5c631832 JK |
14186 | return die; |
14187 | } | |
14188 | ||
d83e736b JK |
14189 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
14190 | Returned value is intended for DW_OP_call*. Returned | |
14191 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
14192 | |
14193 | struct dwarf2_locexpr_baton | |
14194 | dwarf2_fetch_die_location_block (unsigned int offset, | |
8cf6f0b1 TT |
14195 | struct dwarf2_per_cu_data *per_cu, |
14196 | CORE_ADDR (*get_frame_pc) (void *baton), | |
14197 | void *baton) | |
5c631832 | 14198 | { |
918dd910 | 14199 | struct dwarf2_cu *cu; |
5c631832 JK |
14200 | struct die_info *die; |
14201 | struct attribute *attr; | |
14202 | struct dwarf2_locexpr_baton retval; | |
14203 | ||
8cf6f0b1 TT |
14204 | dw2_setup (per_cu->objfile); |
14205 | ||
918dd910 JK |
14206 | if (per_cu->cu == NULL) |
14207 | load_cu (per_cu); | |
14208 | cu = per_cu->cu; | |
14209 | ||
5c631832 JK |
14210 | die = follow_die_offset (offset, &cu); |
14211 | if (!die) | |
14212 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
14213 | offset, per_cu->cu->objfile->name); | |
14214 | ||
14215 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
14216 | if (!attr) | |
14217 | { | |
14218 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
14219 | ||
14220 | retval.data = NULL; | |
14221 | retval.size = 0; | |
14222 | } | |
8cf6f0b1 TT |
14223 | else if (attr_form_is_section_offset (attr)) |
14224 | { | |
14225 | struct dwarf2_loclist_baton loclist_baton; | |
14226 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
14227 | size_t size; | |
14228 | ||
14229 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
14230 | ||
14231 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
14232 | &size, pc); | |
14233 | retval.size = size; | |
14234 | } | |
5c631832 JK |
14235 | else |
14236 | { | |
14237 | if (!attr_form_is_block (attr)) | |
14238 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
14239 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
14240 | offset, per_cu->cu->objfile->name); | |
14241 | ||
14242 | retval.data = DW_BLOCK (attr)->data; | |
14243 | retval.size = DW_BLOCK (attr)->size; | |
14244 | } | |
14245 | retval.per_cu = cu->per_cu; | |
918dd910 | 14246 | |
918dd910 JK |
14247 | age_cached_comp_units (); |
14248 | ||
5c631832 | 14249 | return retval; |
348e048f DE |
14250 | } |
14251 | ||
8a9b8146 TT |
14252 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
14253 | PER_CU. */ | |
14254 | ||
14255 | struct type * | |
14256 | dwarf2_get_die_type (unsigned int die_offset, | |
14257 | struct dwarf2_per_cu_data *per_cu) | |
14258 | { | |
8a9b8146 | 14259 | dw2_setup (per_cu->objfile); |
9ff3b74f | 14260 | return get_die_type_at_offset (die_offset, per_cu); |
8a9b8146 TT |
14261 | } |
14262 | ||
348e048f DE |
14263 | /* Follow the signature attribute ATTR in SRC_DIE. |
14264 | On entry *REF_CU is the CU of SRC_DIE. | |
14265 | On exit *REF_CU is the CU of the result. */ | |
14266 | ||
14267 | static struct die_info * | |
14268 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
14269 | struct dwarf2_cu **ref_cu) | |
14270 | { | |
14271 | struct objfile *objfile = (*ref_cu)->objfile; | |
14272 | struct die_info temp_die; | |
14273 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
14274 | struct dwarf2_cu *sig_cu; | |
14275 | struct die_info *die; | |
14276 | ||
14277 | /* sig_type will be NULL if the signatured type is missing from | |
14278 | the debug info. */ | |
14279 | if (sig_type == NULL) | |
14280 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
14281 | "at 0x%x [in module %s]"), | |
14282 | src_die->offset, objfile->name); | |
14283 | ||
14284 | /* If necessary, add it to the queue and load its DIEs. */ | |
14285 | ||
14286 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
14287 | read_signatured_type (objfile, sig_type); | |
14288 | ||
14289 | gdb_assert (sig_type->per_cu.cu != NULL); | |
14290 | ||
14291 | sig_cu = sig_type->per_cu.cu; | |
14292 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
14293 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
14294 | if (die) | |
14295 | { | |
14296 | *ref_cu = sig_cu; | |
14297 | return die; | |
14298 | } | |
14299 | ||
3e43a32a MS |
14300 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
14301 | "from DIE at 0x%x [in module %s]"), | |
348e048f DE |
14302 | sig_type->type_offset, src_die->offset, objfile->name); |
14303 | } | |
14304 | ||
14305 | /* Given an offset of a signatured type, return its signatured_type. */ | |
14306 | ||
14307 | static struct signatured_type * | |
8b70b953 TT |
14308 | lookup_signatured_type_at_offset (struct objfile *objfile, |
14309 | struct dwarf2_section_info *section, | |
14310 | unsigned int offset) | |
348e048f | 14311 | { |
8b70b953 | 14312 | gdb_byte *info_ptr = section->buffer + offset; |
348e048f DE |
14313 | unsigned int length, initial_length_size; |
14314 | unsigned int sig_offset; | |
14315 | struct signatured_type find_entry, *type_sig; | |
14316 | ||
14317 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
14318 | sig_offset = (initial_length_size | |
14319 | + 2 /*version*/ | |
14320 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
14321 | + 1 /*address_size*/); | |
14322 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
14323 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
14324 | ||
14325 | /* This is only used to lookup previously recorded types. | |
14326 | If we didn't find it, it's our bug. */ | |
14327 | gdb_assert (type_sig != NULL); | |
b3c8eb43 | 14328 | gdb_assert (offset == type_sig->per_cu.offset); |
348e048f DE |
14329 | |
14330 | return type_sig; | |
14331 | } | |
14332 | ||
14333 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
14334 | ||
14335 | static void | |
14336 | read_signatured_type_at_offset (struct objfile *objfile, | |
8b70b953 | 14337 | struct dwarf2_section_info *sect, |
348e048f DE |
14338 | unsigned int offset) |
14339 | { | |
14340 | struct signatured_type *type_sig; | |
14341 | ||
8b70b953 | 14342 | dwarf2_read_section (objfile, sect); |
be391dca | 14343 | |
348e048f DE |
14344 | /* We have the section offset, but we need the signature to do the |
14345 | hash table lookup. */ | |
8b70b953 | 14346 | type_sig = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f DE |
14347 | |
14348 | gdb_assert (type_sig->per_cu.cu == NULL); | |
14349 | ||
14350 | read_signatured_type (objfile, type_sig); | |
14351 | ||
14352 | gdb_assert (type_sig->per_cu.cu != NULL); | |
14353 | } | |
14354 | ||
14355 | /* Read in a signatured type and build its CU and DIEs. */ | |
14356 | ||
14357 | static void | |
14358 | read_signatured_type (struct objfile *objfile, | |
14359 | struct signatured_type *type_sig) | |
14360 | { | |
1fd400ff | 14361 | gdb_byte *types_ptr; |
348e048f DE |
14362 | struct die_reader_specs reader_specs; |
14363 | struct dwarf2_cu *cu; | |
14364 | ULONGEST signature; | |
14365 | struct cleanup *back_to, *free_cu_cleanup; | |
8b70b953 | 14366 | struct dwarf2_section_info *section = type_sig->per_cu.debug_type_section; |
348e048f | 14367 | |
8b70b953 TT |
14368 | dwarf2_read_section (objfile, section); |
14369 | types_ptr = section->buffer + type_sig->per_cu.offset; | |
1fd400ff | 14370 | |
348e048f DE |
14371 | gdb_assert (type_sig->per_cu.cu == NULL); |
14372 | ||
9816fde3 JK |
14373 | cu = xmalloc (sizeof (*cu)); |
14374 | init_one_comp_unit (cu, objfile); | |
14375 | ||
348e048f DE |
14376 | type_sig->per_cu.cu = cu; |
14377 | cu->per_cu = &type_sig->per_cu; | |
14378 | ||
14379 | /* If an error occurs while loading, release our storage. */ | |
14380 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
14381 | ||
8b70b953 | 14382 | types_ptr = read_type_comp_unit_head (&cu->header, section, &signature, |
348e048f DE |
14383 | types_ptr, objfile->obfd); |
14384 | gdb_assert (signature == type_sig->signature); | |
14385 | ||
14386 | cu->die_hash | |
14387 | = htab_create_alloc_ex (cu->header.length / 12, | |
14388 | die_hash, | |
14389 | die_eq, | |
14390 | NULL, | |
14391 | &cu->comp_unit_obstack, | |
14392 | hashtab_obstack_allocate, | |
14393 | dummy_obstack_deallocate); | |
14394 | ||
14395 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
14396 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
14397 | ||
14398 | init_cu_die_reader (&reader_specs, cu); | |
14399 | ||
14400 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
14401 | NULL /*parent*/); | |
14402 | ||
14403 | /* We try not to read any attributes in this function, because not | |
14404 | all objfiles needed for references have been loaded yet, and symbol | |
14405 | table processing isn't initialized. But we have to set the CU language, | |
14406 | or we won't be able to build types correctly. */ | |
9816fde3 | 14407 | prepare_one_comp_unit (cu, cu->dies); |
348e048f DE |
14408 | |
14409 | do_cleanups (back_to); | |
14410 | ||
14411 | /* We've successfully allocated this compilation unit. Let our caller | |
14412 | clean it up when finished with it. */ | |
14413 | discard_cleanups (free_cu_cleanup); | |
14414 | ||
14415 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
14416 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
14417 | } |
14418 | ||
3c6e0cb3 JK |
14419 | /* Workaround as dwarf_expr_context_funcs.read_mem implementation before |
14420 | a proper runtime DWARF expressions evaluator gets implemented. | |
14421 | Otherwise gnuv3_baseclass_offset would error by: | |
14422 | Expected a negative vbase offset (old compiler?) */ | |
14423 | ||
14424 | static void | |
14425 | decode_locdesc_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, | |
14426 | size_t length) | |
14427 | { | |
14428 | struct dwarf_expr_context *ctx = baton; | |
14429 | struct gdbarch *gdbarch = ctx->gdbarch; | |
14430 | struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; | |
14431 | ||
14432 | memset (buf, 0, length); | |
14433 | ||
14434 | if (TYPE_LENGTH (ptr_type) == length) | |
14435 | store_typed_address (buf, ptr_type, addr); | |
14436 | } | |
14437 | ||
14438 | static const struct dwarf_expr_context_funcs decode_locdesc_ctx_funcs = | |
14439 | { | |
14440 | ctx_no_read_reg, | |
14441 | decode_locdesc_read_mem, | |
14442 | ctx_no_get_frame_base, | |
14443 | ctx_no_get_frame_cfa, | |
14444 | ctx_no_get_frame_pc, | |
14445 | ctx_no_get_tls_address, | |
14446 | ctx_no_dwarf_call, | |
14447 | ctx_no_get_base_type | |
14448 | }; | |
14449 | ||
c906108c SS |
14450 | /* Decode simple location descriptions. |
14451 | Given a pointer to a dwarf block that defines a location, compute | |
14452 | the location and return the value. | |
14453 | ||
4cecd739 DJ |
14454 | NOTE drow/2003-11-18: This function is called in two situations |
14455 | now: for the address of static or global variables (partial symbols | |
14456 | only) and for offsets into structures which are expected to be | |
14457 | (more or less) constant. The partial symbol case should go away, | |
14458 | and only the constant case should remain. That will let this | |
14459 | function complain more accurately. A few special modes are allowed | |
14460 | without complaint for global variables (for instance, global | |
14461 | register values and thread-local values). | |
c906108c SS |
14462 | |
14463 | A location description containing no operations indicates that the | |
4cecd739 | 14464 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
14465 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
14466 | callers will only want a very basic result and this can become a | |
3c6e0cb3 | 14467 | complaint. */ |
c906108c SS |
14468 | |
14469 | static CORE_ADDR | |
e7c27a73 | 14470 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 14471 | { |
e7c27a73 | 14472 | struct objfile *objfile = cu->objfile; |
3c6e0cb3 JK |
14473 | struct dwarf_expr_context *ctx; |
14474 | struct cleanup *old_chain; | |
14475 | volatile struct gdb_exception ex; | |
c906108c | 14476 | |
3c6e0cb3 JK |
14477 | ctx = new_dwarf_expr_context (); |
14478 | old_chain = make_cleanup_free_dwarf_expr_context (ctx); | |
14479 | make_cleanup_value_free_to_mark (value_mark ()); | |
f1bea926 | 14480 | |
3c6e0cb3 JK |
14481 | ctx->gdbarch = get_objfile_arch (objfile); |
14482 | ctx->addr_size = cu->header.addr_size; | |
96408a79 | 14483 | ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (cu->per_cu); |
3c6e0cb3 JK |
14484 | ctx->offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
14485 | ctx->baton = ctx; | |
14486 | ctx->funcs = &decode_locdesc_ctx_funcs; | |
c906108c | 14487 | |
3c6e0cb3 JK |
14488 | /* DW_AT_data_member_location expects the structure address to be pushed on |
14489 | the stack. Simulate the offset by address 0. */ | |
14490 | dwarf_expr_push_address (ctx, 0, 0); | |
c906108c | 14491 | |
3c6e0cb3 JK |
14492 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
14493 | { | |
14494 | dwarf_expr_eval (ctx, blk->data, blk->size); | |
14495 | } | |
14496 | if (ex.reason < 0) | |
14497 | { | |
14498 | if (ex.message) | |
14499 | complaint (&symfile_complaints, "%s", ex.message); | |
14500 | } | |
14501 | else if (ctx->num_pieces == 0) | |
14502 | switch (ctx->location) | |
14503 | { | |
14504 | /* The returned number will be bogus, just do not complain for locations | |
14505 | in global registers - it is here only a partial symbol address. */ | |
14506 | case DWARF_VALUE_REGISTER: | |
d53d4ac5 | 14507 | |
3c6e0cb3 JK |
14508 | case DWARF_VALUE_MEMORY: |
14509 | case DWARF_VALUE_STACK: | |
d53d4ac5 | 14510 | { |
3c6e0cb3 | 14511 | CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0); |
d53d4ac5 | 14512 | |
3c6e0cb3 JK |
14513 | do_cleanups (old_chain); |
14514 | return address; | |
d53d4ac5 | 14515 | } |
3c6e0cb3 JK |
14516 | } |
14517 | ||
14518 | do_cleanups (old_chain); | |
14519 | dwarf2_complex_location_expr_complaint (); | |
14520 | return 0; | |
c906108c SS |
14521 | } |
14522 | ||
14523 | /* memory allocation interface */ | |
14524 | ||
c906108c | 14525 | static struct dwarf_block * |
7b5a2f43 | 14526 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
14527 | { |
14528 | struct dwarf_block *blk; | |
14529 | ||
14530 | blk = (struct dwarf_block *) | |
7b5a2f43 | 14531 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
14532 | return (blk); |
14533 | } | |
14534 | ||
14535 | static struct abbrev_info * | |
f3dd6933 | 14536 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
14537 | { |
14538 | struct abbrev_info *abbrev; | |
14539 | ||
f3dd6933 DJ |
14540 | abbrev = (struct abbrev_info *) |
14541 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
14542 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
14543 | return (abbrev); | |
14544 | } | |
14545 | ||
14546 | static struct die_info * | |
b60c80d6 | 14547 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
14548 | { |
14549 | struct die_info *die; | |
b60c80d6 DJ |
14550 | size_t size = sizeof (struct die_info); |
14551 | ||
14552 | if (num_attrs > 1) | |
14553 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 14554 | |
b60c80d6 | 14555 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
14556 | memset (die, 0, sizeof (struct die_info)); |
14557 | return (die); | |
14558 | } | |
2e276125 JB |
14559 | |
14560 | \f | |
14561 | /* Macro support. */ | |
14562 | ||
2e276125 JB |
14563 | /* Return the full name of file number I in *LH's file name table. |
14564 | Use COMP_DIR as the name of the current directory of the | |
14565 | compilation. The result is allocated using xmalloc; the caller is | |
14566 | responsible for freeing it. */ | |
14567 | static char * | |
14568 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
14569 | { | |
6a83a1e6 EZ |
14570 | /* Is the file number a valid index into the line header's file name |
14571 | table? Remember that file numbers start with one, not zero. */ | |
14572 | if (1 <= file && file <= lh->num_file_names) | |
14573 | { | |
14574 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 14575 | |
6a83a1e6 EZ |
14576 | if (IS_ABSOLUTE_PATH (fe->name)) |
14577 | return xstrdup (fe->name); | |
14578 | else | |
14579 | { | |
14580 | const char *dir; | |
14581 | int dir_len; | |
14582 | char *full_name; | |
14583 | ||
14584 | if (fe->dir_index) | |
14585 | dir = lh->include_dirs[fe->dir_index - 1]; | |
14586 | else | |
14587 | dir = comp_dir; | |
14588 | ||
14589 | if (dir) | |
14590 | { | |
14591 | dir_len = strlen (dir); | |
14592 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
14593 | strcpy (full_name, dir); | |
14594 | full_name[dir_len] = '/'; | |
14595 | strcpy (full_name + dir_len + 1, fe->name); | |
14596 | return full_name; | |
14597 | } | |
14598 | else | |
14599 | return xstrdup (fe->name); | |
14600 | } | |
14601 | } | |
2e276125 JB |
14602 | else |
14603 | { | |
6a83a1e6 EZ |
14604 | /* The compiler produced a bogus file number. We can at least |
14605 | record the macro definitions made in the file, even if we | |
14606 | won't be able to find the file by name. */ | |
14607 | char fake_name[80]; | |
9a619af0 | 14608 | |
6a83a1e6 | 14609 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 14610 | |
6e70227d | 14611 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
14612 | _("bad file number in macro information (%d)"), |
14613 | file); | |
2e276125 | 14614 | |
6a83a1e6 | 14615 | return xstrdup (fake_name); |
2e276125 JB |
14616 | } |
14617 | } | |
14618 | ||
14619 | ||
14620 | static struct macro_source_file * | |
14621 | macro_start_file (int file, int line, | |
14622 | struct macro_source_file *current_file, | |
14623 | const char *comp_dir, | |
14624 | struct line_header *lh, struct objfile *objfile) | |
14625 | { | |
14626 | /* The full name of this source file. */ | |
14627 | char *full_name = file_full_name (file, lh, comp_dir); | |
14628 | ||
14629 | /* We don't create a macro table for this compilation unit | |
14630 | at all until we actually get a filename. */ | |
14631 | if (! pending_macros) | |
4a146b47 | 14632 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 14633 | objfile->macro_cache); |
2e276125 JB |
14634 | |
14635 | if (! current_file) | |
14636 | /* If we have no current file, then this must be the start_file | |
14637 | directive for the compilation unit's main source file. */ | |
14638 | current_file = macro_set_main (pending_macros, full_name); | |
14639 | else | |
14640 | current_file = macro_include (current_file, line, full_name); | |
14641 | ||
14642 | xfree (full_name); | |
6e70227d | 14643 | |
2e276125 JB |
14644 | return current_file; |
14645 | } | |
14646 | ||
14647 | ||
14648 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
14649 | followed by a null byte. */ | |
14650 | static char * | |
14651 | copy_string (const char *buf, int len) | |
14652 | { | |
14653 | char *s = xmalloc (len + 1); | |
9a619af0 | 14654 | |
2e276125 JB |
14655 | memcpy (s, buf, len); |
14656 | s[len] = '\0'; | |
2e276125 JB |
14657 | return s; |
14658 | } | |
14659 | ||
14660 | ||
14661 | static const char * | |
14662 | consume_improper_spaces (const char *p, const char *body) | |
14663 | { | |
14664 | if (*p == ' ') | |
14665 | { | |
4d3c2250 | 14666 | complaint (&symfile_complaints, |
3e43a32a MS |
14667 | _("macro definition contains spaces " |
14668 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 14669 | body); |
2e276125 JB |
14670 | |
14671 | while (*p == ' ') | |
14672 | p++; | |
14673 | } | |
14674 | ||
14675 | return p; | |
14676 | } | |
14677 | ||
14678 | ||
14679 | static void | |
14680 | parse_macro_definition (struct macro_source_file *file, int line, | |
14681 | const char *body) | |
14682 | { | |
14683 | const char *p; | |
14684 | ||
14685 | /* The body string takes one of two forms. For object-like macro | |
14686 | definitions, it should be: | |
14687 | ||
14688 | <macro name> " " <definition> | |
14689 | ||
14690 | For function-like macro definitions, it should be: | |
14691 | ||
14692 | <macro name> "() " <definition> | |
14693 | or | |
14694 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
14695 | ||
14696 | Spaces may appear only where explicitly indicated, and in the | |
14697 | <definition>. | |
14698 | ||
14699 | The Dwarf 2 spec says that an object-like macro's name is always | |
14700 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 14701 | the space when the macro's definition is the empty string. |
2e276125 JB |
14702 | |
14703 | The Dwarf 2 spec says that there should be no spaces between the | |
14704 | formal arguments in a function-like macro's formal argument list, | |
14705 | but versions of GCC around March 2002 include spaces after the | |
14706 | commas. */ | |
14707 | ||
14708 | ||
14709 | /* Find the extent of the macro name. The macro name is terminated | |
14710 | by either a space or null character (for an object-like macro) or | |
14711 | an opening paren (for a function-like macro). */ | |
14712 | for (p = body; *p; p++) | |
14713 | if (*p == ' ' || *p == '(') | |
14714 | break; | |
14715 | ||
14716 | if (*p == ' ' || *p == '\0') | |
14717 | { | |
14718 | /* It's an object-like macro. */ | |
14719 | int name_len = p - body; | |
14720 | char *name = copy_string (body, name_len); | |
14721 | const char *replacement; | |
14722 | ||
14723 | if (*p == ' ') | |
14724 | replacement = body + name_len + 1; | |
14725 | else | |
14726 | { | |
4d3c2250 | 14727 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14728 | replacement = body + name_len; |
14729 | } | |
6e70227d | 14730 | |
2e276125 JB |
14731 | macro_define_object (file, line, name, replacement); |
14732 | ||
14733 | xfree (name); | |
14734 | } | |
14735 | else if (*p == '(') | |
14736 | { | |
14737 | /* It's a function-like macro. */ | |
14738 | char *name = copy_string (body, p - body); | |
14739 | int argc = 0; | |
14740 | int argv_size = 1; | |
14741 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
14742 | ||
14743 | p++; | |
14744 | ||
14745 | p = consume_improper_spaces (p, body); | |
14746 | ||
14747 | /* Parse the formal argument list. */ | |
14748 | while (*p && *p != ')') | |
14749 | { | |
14750 | /* Find the extent of the current argument name. */ | |
14751 | const char *arg_start = p; | |
14752 | ||
14753 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
14754 | p++; | |
14755 | ||
14756 | if (! *p || p == arg_start) | |
4d3c2250 | 14757 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14758 | else |
14759 | { | |
14760 | /* Make sure argv has room for the new argument. */ | |
14761 | if (argc >= argv_size) | |
14762 | { | |
14763 | argv_size *= 2; | |
14764 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
14765 | } | |
14766 | ||
14767 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
14768 | } | |
14769 | ||
14770 | p = consume_improper_spaces (p, body); | |
14771 | ||
14772 | /* Consume the comma, if present. */ | |
14773 | if (*p == ',') | |
14774 | { | |
14775 | p++; | |
14776 | ||
14777 | p = consume_improper_spaces (p, body); | |
14778 | } | |
14779 | } | |
14780 | ||
14781 | if (*p == ')') | |
14782 | { | |
14783 | p++; | |
14784 | ||
14785 | if (*p == ' ') | |
14786 | /* Perfectly formed definition, no complaints. */ | |
14787 | macro_define_function (file, line, name, | |
6e70227d | 14788 | argc, (const char **) argv, |
2e276125 JB |
14789 | p + 1); |
14790 | else if (*p == '\0') | |
14791 | { | |
14792 | /* Complain, but do define it. */ | |
4d3c2250 | 14793 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 14794 | macro_define_function (file, line, name, |
6e70227d | 14795 | argc, (const char **) argv, |
2e276125 JB |
14796 | p); |
14797 | } | |
14798 | else | |
14799 | /* Just complain. */ | |
4d3c2250 | 14800 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14801 | } |
14802 | else | |
14803 | /* Just complain. */ | |
4d3c2250 | 14804 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14805 | |
14806 | xfree (name); | |
14807 | { | |
14808 | int i; | |
14809 | ||
14810 | for (i = 0; i < argc; i++) | |
14811 | xfree (argv[i]); | |
14812 | } | |
14813 | xfree (argv); | |
14814 | } | |
14815 | else | |
4d3c2250 | 14816 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14817 | } |
14818 | ||
cf2c3c16 TT |
14819 | /* Skip some bytes from BYTES according to the form given in FORM. |
14820 | Returns the new pointer. */ | |
2e276125 | 14821 | |
cf2c3c16 TT |
14822 | static gdb_byte * |
14823 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, | |
14824 | enum dwarf_form form, | |
14825 | unsigned int offset_size, | |
14826 | struct dwarf2_section_info *section) | |
2e276125 | 14827 | { |
cf2c3c16 | 14828 | unsigned int bytes_read; |
2e276125 | 14829 | |
cf2c3c16 | 14830 | switch (form) |
2e276125 | 14831 | { |
cf2c3c16 TT |
14832 | case DW_FORM_data1: |
14833 | case DW_FORM_flag: | |
14834 | ++bytes; | |
14835 | break; | |
14836 | ||
14837 | case DW_FORM_data2: | |
14838 | bytes += 2; | |
14839 | break; | |
14840 | ||
14841 | case DW_FORM_data4: | |
14842 | bytes += 4; | |
14843 | break; | |
14844 | ||
14845 | case DW_FORM_data8: | |
14846 | bytes += 8; | |
14847 | break; | |
14848 | ||
14849 | case DW_FORM_string: | |
14850 | read_direct_string (abfd, bytes, &bytes_read); | |
14851 | bytes += bytes_read; | |
14852 | break; | |
14853 | ||
14854 | case DW_FORM_sec_offset: | |
14855 | case DW_FORM_strp: | |
14856 | bytes += offset_size; | |
14857 | break; | |
14858 | ||
14859 | case DW_FORM_block: | |
14860 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
14861 | bytes += bytes_read; | |
14862 | break; | |
14863 | ||
14864 | case DW_FORM_block1: | |
14865 | bytes += 1 + read_1_byte (abfd, bytes); | |
14866 | break; | |
14867 | case DW_FORM_block2: | |
14868 | bytes += 2 + read_2_bytes (abfd, bytes); | |
14869 | break; | |
14870 | case DW_FORM_block4: | |
14871 | bytes += 4 + read_4_bytes (abfd, bytes); | |
14872 | break; | |
14873 | ||
14874 | case DW_FORM_sdata: | |
14875 | case DW_FORM_udata: | |
14876 | bytes = skip_leb128 (abfd, bytes); | |
14877 | break; | |
14878 | ||
14879 | default: | |
14880 | { | |
14881 | complain: | |
14882 | complaint (&symfile_complaints, | |
14883 | _("invalid form 0x%x in `%s'"), | |
14884 | form, | |
14885 | section->asection->name); | |
14886 | return NULL; | |
14887 | } | |
2e276125 JB |
14888 | } |
14889 | ||
cf2c3c16 TT |
14890 | return bytes; |
14891 | } | |
757a13d0 | 14892 | |
cf2c3c16 TT |
14893 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
14894 | opcode. Returns an updated pointer to the macro data buffer; or, | |
14895 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 14896 | |
cf2c3c16 TT |
14897 | static gdb_byte * |
14898 | skip_unknown_opcode (unsigned int opcode, | |
14899 | gdb_byte **opcode_definitions, | |
14900 | gdb_byte *mac_ptr, | |
14901 | bfd *abfd, | |
14902 | unsigned int offset_size, | |
14903 | struct dwarf2_section_info *section) | |
14904 | { | |
14905 | unsigned int bytes_read, i; | |
14906 | unsigned long arg; | |
14907 | gdb_byte *defn; | |
2e276125 | 14908 | |
cf2c3c16 | 14909 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 14910 | { |
cf2c3c16 TT |
14911 | complaint (&symfile_complaints, |
14912 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
14913 | opcode); | |
14914 | return NULL; | |
14915 | } | |
2e276125 | 14916 | |
cf2c3c16 TT |
14917 | defn = opcode_definitions[opcode]; |
14918 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
14919 | defn += bytes_read; | |
2e276125 | 14920 | |
cf2c3c16 TT |
14921 | for (i = 0; i < arg; ++i) |
14922 | { | |
14923 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); | |
14924 | if (mac_ptr == NULL) | |
14925 | { | |
14926 | /* skip_form_bytes already issued the complaint. */ | |
14927 | return NULL; | |
14928 | } | |
14929 | } | |
757a13d0 | 14930 | |
cf2c3c16 TT |
14931 | return mac_ptr; |
14932 | } | |
757a13d0 | 14933 | |
cf2c3c16 TT |
14934 | /* A helper function which parses the header of a macro section. |
14935 | If the macro section is the extended (for now called "GNU") type, | |
14936 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
14937 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 14938 | |
cf2c3c16 TT |
14939 | static gdb_byte * |
14940 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
14941 | bfd *abfd, | |
14942 | gdb_byte *mac_ptr, | |
14943 | unsigned int *offset_size, | |
14944 | int section_is_gnu) | |
14945 | { | |
14946 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 14947 | |
cf2c3c16 TT |
14948 | if (section_is_gnu) |
14949 | { | |
14950 | unsigned int version, flags; | |
757a13d0 | 14951 | |
cf2c3c16 TT |
14952 | version = read_2_bytes (abfd, mac_ptr); |
14953 | if (version != 4) | |
14954 | { | |
14955 | complaint (&symfile_complaints, | |
14956 | _("unrecognized version `%d' in .debug_macro section"), | |
14957 | version); | |
14958 | return NULL; | |
14959 | } | |
14960 | mac_ptr += 2; | |
757a13d0 | 14961 | |
cf2c3c16 TT |
14962 | flags = read_1_byte (abfd, mac_ptr); |
14963 | ++mac_ptr; | |
14964 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 14965 | |
cf2c3c16 TT |
14966 | if ((flags & 2) != 0) |
14967 | /* We don't need the line table offset. */ | |
14968 | mac_ptr += *offset_size; | |
757a13d0 | 14969 | |
cf2c3c16 TT |
14970 | /* Vendor opcode descriptions. */ |
14971 | if ((flags & 4) != 0) | |
14972 | { | |
14973 | unsigned int i, count; | |
757a13d0 | 14974 | |
cf2c3c16 TT |
14975 | count = read_1_byte (abfd, mac_ptr); |
14976 | ++mac_ptr; | |
14977 | for (i = 0; i < count; ++i) | |
14978 | { | |
14979 | unsigned int opcode, bytes_read; | |
14980 | unsigned long arg; | |
14981 | ||
14982 | opcode = read_1_byte (abfd, mac_ptr); | |
14983 | ++mac_ptr; | |
14984 | opcode_definitions[opcode] = mac_ptr; | |
14985 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14986 | mac_ptr += bytes_read; | |
14987 | mac_ptr += arg; | |
14988 | } | |
757a13d0 | 14989 | } |
cf2c3c16 | 14990 | } |
757a13d0 | 14991 | |
cf2c3c16 TT |
14992 | return mac_ptr; |
14993 | } | |
757a13d0 | 14994 | |
cf2c3c16 TT |
14995 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
14996 | including DW_GNU_MACINFO_transparent_include. */ | |
14997 | ||
14998 | static void | |
14999 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
15000 | struct macro_source_file *current_file, | |
15001 | struct line_header *lh, char *comp_dir, | |
15002 | struct dwarf2_section_info *section, | |
15003 | int section_is_gnu, | |
15004 | unsigned int offset_size, | |
15005 | struct objfile *objfile) | |
15006 | { | |
15007 | enum dwarf_macro_record_type macinfo_type; | |
15008 | int at_commandline; | |
15009 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 15010 | |
cf2c3c16 TT |
15011 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
15012 | &offset_size, section_is_gnu); | |
15013 | if (mac_ptr == NULL) | |
15014 | { | |
15015 | /* We already issued a complaint. */ | |
15016 | return; | |
15017 | } | |
757a13d0 JK |
15018 | |
15019 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
15020 | GDB is still reading the definitions from command line. First | |
15021 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
15022 | to create CURRENT_FILE for the main source holding also the command line | |
15023 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
15024 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
15025 | ||
15026 | at_commandline = 1; | |
15027 | ||
15028 | do | |
15029 | { | |
15030 | /* Do we at least have room for a macinfo type byte? */ | |
15031 | if (mac_ptr >= mac_end) | |
15032 | { | |
cf2c3c16 | 15033 | dwarf2_macros_too_long_complaint (section); |
757a13d0 JK |
15034 | break; |
15035 | } | |
15036 | ||
15037 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15038 | mac_ptr++; | |
15039 | ||
cf2c3c16 TT |
15040 | /* Note that we rely on the fact that the corresponding GNU and |
15041 | DWARF constants are the same. */ | |
757a13d0 JK |
15042 | switch (macinfo_type) |
15043 | { | |
15044 | /* A zero macinfo type indicates the end of the macro | |
15045 | information. */ | |
15046 | case 0: | |
15047 | break; | |
2e276125 | 15048 | |
cf2c3c16 TT |
15049 | case DW_MACRO_GNU_define: |
15050 | case DW_MACRO_GNU_undef: | |
15051 | case DW_MACRO_GNU_define_indirect: | |
15052 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 15053 | { |
891d2f0b | 15054 | unsigned int bytes_read; |
2e276125 JB |
15055 | int line; |
15056 | char *body; | |
cf2c3c16 | 15057 | int is_define; |
2e276125 | 15058 | |
cf2c3c16 TT |
15059 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15060 | mac_ptr += bytes_read; | |
15061 | ||
15062 | if (macinfo_type == DW_MACRO_GNU_define | |
15063 | || macinfo_type == DW_MACRO_GNU_undef) | |
15064 | { | |
15065 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
15066 | mac_ptr += bytes_read; | |
15067 | } | |
15068 | else | |
15069 | { | |
15070 | LONGEST str_offset; | |
15071 | ||
15072 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15073 | mac_ptr += offset_size; | |
2e276125 | 15074 | |
cf2c3c16 TT |
15075 | body = read_indirect_string_at_offset (abfd, str_offset); |
15076 | } | |
15077 | ||
15078 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
15079 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 15080 | if (! current_file) |
757a13d0 JK |
15081 | { |
15082 | /* DWARF violation as no main source is present. */ | |
15083 | complaint (&symfile_complaints, | |
15084 | _("debug info with no main source gives macro %s " | |
15085 | "on line %d: %s"), | |
cf2c3c16 TT |
15086 | is_define ? _("definition") : _("undefinition"), |
15087 | line, body); | |
757a13d0 JK |
15088 | break; |
15089 | } | |
3e43a32a MS |
15090 | if ((line == 0 && !at_commandline) |
15091 | || (line != 0 && at_commandline)) | |
4d3c2250 | 15092 | complaint (&symfile_complaints, |
757a13d0 JK |
15093 | _("debug info gives %s macro %s with %s line %d: %s"), |
15094 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 15095 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
15096 | line == 0 ? _("zero") : _("non-zero"), line, body); |
15097 | ||
cf2c3c16 | 15098 | if (is_define) |
757a13d0 | 15099 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
15100 | else |
15101 | { | |
15102 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
15103 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
15104 | macro_undef (current_file, line, body); | |
15105 | } | |
2e276125 JB |
15106 | } |
15107 | break; | |
15108 | ||
cf2c3c16 | 15109 | case DW_MACRO_GNU_start_file: |
2e276125 | 15110 | { |
891d2f0b | 15111 | unsigned int bytes_read; |
2e276125 JB |
15112 | int line, file; |
15113 | ||
15114 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15115 | mac_ptr += bytes_read; | |
15116 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15117 | mac_ptr += bytes_read; | |
15118 | ||
3e43a32a MS |
15119 | if ((line == 0 && !at_commandline) |
15120 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
15121 | complaint (&symfile_complaints, |
15122 | _("debug info gives source %d included " | |
15123 | "from %s at %s line %d"), | |
15124 | file, at_commandline ? _("command-line") : _("file"), | |
15125 | line == 0 ? _("zero") : _("non-zero"), line); | |
15126 | ||
15127 | if (at_commandline) | |
15128 | { | |
cf2c3c16 TT |
15129 | /* This DW_MACRO_GNU_start_file was executed in the |
15130 | pass one. */ | |
757a13d0 JK |
15131 | at_commandline = 0; |
15132 | } | |
15133 | else | |
15134 | current_file = macro_start_file (file, line, | |
15135 | current_file, comp_dir, | |
cf2c3c16 | 15136 | lh, objfile); |
2e276125 JB |
15137 | } |
15138 | break; | |
15139 | ||
cf2c3c16 | 15140 | case DW_MACRO_GNU_end_file: |
2e276125 | 15141 | if (! current_file) |
4d3c2250 | 15142 | complaint (&symfile_complaints, |
3e43a32a MS |
15143 | _("macro debug info has an unmatched " |
15144 | "`close_file' directive")); | |
2e276125 JB |
15145 | else |
15146 | { | |
15147 | current_file = current_file->included_by; | |
15148 | if (! current_file) | |
15149 | { | |
cf2c3c16 | 15150 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
15151 | |
15152 | /* GCC circa March 2002 doesn't produce the zero | |
15153 | type byte marking the end of the compilation | |
15154 | unit. Complain if it's not there, but exit no | |
15155 | matter what. */ | |
15156 | ||
15157 | /* Do we at least have room for a macinfo type byte? */ | |
15158 | if (mac_ptr >= mac_end) | |
15159 | { | |
cf2c3c16 | 15160 | dwarf2_macros_too_long_complaint (section); |
2e276125 JB |
15161 | return; |
15162 | } | |
15163 | ||
15164 | /* We don't increment mac_ptr here, so this is just | |
15165 | a look-ahead. */ | |
15166 | next_type = read_1_byte (abfd, mac_ptr); | |
15167 | if (next_type != 0) | |
4d3c2250 | 15168 | complaint (&symfile_complaints, |
3e43a32a MS |
15169 | _("no terminating 0-type entry for " |
15170 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
15171 | |
15172 | return; | |
15173 | } | |
15174 | } | |
15175 | break; | |
15176 | ||
cf2c3c16 TT |
15177 | case DW_MACRO_GNU_transparent_include: |
15178 | { | |
15179 | LONGEST offset; | |
15180 | ||
15181 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15182 | mac_ptr += offset_size; | |
15183 | ||
15184 | dwarf_decode_macro_bytes (abfd, | |
15185 | section->buffer + offset, | |
15186 | mac_end, current_file, | |
15187 | lh, comp_dir, | |
15188 | section, section_is_gnu, | |
15189 | offset_size, objfile); | |
15190 | } | |
15191 | break; | |
15192 | ||
2e276125 | 15193 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
15194 | if (!section_is_gnu) |
15195 | { | |
15196 | unsigned int bytes_read; | |
15197 | int constant; | |
2e276125 | 15198 | |
cf2c3c16 TT |
15199 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15200 | mac_ptr += bytes_read; | |
15201 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15202 | mac_ptr += bytes_read; | |
2e276125 | 15203 | |
cf2c3c16 TT |
15204 | /* We don't recognize any vendor extensions. */ |
15205 | break; | |
15206 | } | |
15207 | /* FALLTHROUGH */ | |
15208 | ||
15209 | default: | |
15210 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15211 | mac_ptr, abfd, offset_size, | |
15212 | section); | |
15213 | if (mac_ptr == NULL) | |
15214 | return; | |
15215 | break; | |
2e276125 | 15216 | } |
757a13d0 | 15217 | } while (macinfo_type != 0); |
2e276125 | 15218 | } |
8e19ed76 | 15219 | |
cf2c3c16 TT |
15220 | static void |
15221 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
15222 | char *comp_dir, bfd *abfd, | |
15223 | struct dwarf2_cu *cu, | |
15224 | struct dwarf2_section_info *section, | |
15225 | int section_is_gnu) | |
15226 | { | |
15227 | gdb_byte *mac_ptr, *mac_end; | |
15228 | struct macro_source_file *current_file = 0; | |
15229 | enum dwarf_macro_record_type macinfo_type; | |
15230 | unsigned int offset_size = cu->header.offset_size; | |
15231 | gdb_byte *opcode_definitions[256]; | |
15232 | ||
15233 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
15234 | if (section->buffer == NULL) | |
15235 | { | |
15236 | complaint (&symfile_complaints, _("missing %s section"), | |
15237 | section->asection->name); | |
15238 | return; | |
15239 | } | |
15240 | ||
15241 | /* First pass: Find the name of the base filename. | |
15242 | This filename is needed in order to process all macros whose definition | |
15243 | (or undefinition) comes from the command line. These macros are defined | |
15244 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
15245 | associated to the base file. | |
15246 | ||
15247 | To determine the base file name, we scan the macro definitions until we | |
15248 | reach the first DW_MACINFO_start_file entry. We then initialize | |
15249 | CURRENT_FILE accordingly so that any macro definition found before the | |
15250 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
15251 | ||
15252 | mac_ptr = section->buffer + offset; | |
15253 | mac_end = section->buffer + section->size; | |
15254 | ||
15255 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
15256 | &offset_size, section_is_gnu); | |
15257 | if (mac_ptr == NULL) | |
15258 | { | |
15259 | /* We already issued a complaint. */ | |
15260 | return; | |
15261 | } | |
15262 | ||
15263 | do | |
15264 | { | |
15265 | /* Do we at least have room for a macinfo type byte? */ | |
15266 | if (mac_ptr >= mac_end) | |
15267 | { | |
15268 | /* Complaint is printed during the second pass as GDB will probably | |
15269 | stop the first pass earlier upon finding | |
15270 | DW_MACINFO_start_file. */ | |
15271 | break; | |
15272 | } | |
15273 | ||
15274 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15275 | mac_ptr++; | |
15276 | ||
15277 | /* Note that we rely on the fact that the corresponding GNU and | |
15278 | DWARF constants are the same. */ | |
15279 | switch (macinfo_type) | |
15280 | { | |
15281 | /* A zero macinfo type indicates the end of the macro | |
15282 | information. */ | |
15283 | case 0: | |
15284 | break; | |
15285 | ||
15286 | case DW_MACRO_GNU_define: | |
15287 | case DW_MACRO_GNU_undef: | |
15288 | /* Only skip the data by MAC_PTR. */ | |
15289 | { | |
15290 | unsigned int bytes_read; | |
15291 | ||
15292 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15293 | mac_ptr += bytes_read; | |
15294 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15295 | mac_ptr += bytes_read; | |
15296 | } | |
15297 | break; | |
15298 | ||
15299 | case DW_MACRO_GNU_start_file: | |
15300 | { | |
15301 | unsigned int bytes_read; | |
15302 | int line, file; | |
15303 | ||
15304 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15305 | mac_ptr += bytes_read; | |
15306 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15307 | mac_ptr += bytes_read; | |
15308 | ||
15309 | current_file = macro_start_file (file, line, current_file, | |
15310 | comp_dir, lh, cu->objfile); | |
15311 | } | |
15312 | break; | |
15313 | ||
15314 | case DW_MACRO_GNU_end_file: | |
15315 | /* No data to skip by MAC_PTR. */ | |
15316 | break; | |
15317 | ||
15318 | case DW_MACRO_GNU_define_indirect: | |
15319 | case DW_MACRO_GNU_undef_indirect: | |
15320 | { | |
15321 | unsigned int bytes_read; | |
15322 | ||
15323 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15324 | mac_ptr += bytes_read; | |
15325 | mac_ptr += offset_size; | |
15326 | } | |
15327 | break; | |
15328 | ||
15329 | case DW_MACRO_GNU_transparent_include: | |
15330 | /* Note that, according to the spec, a transparent include | |
15331 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
15332 | skip this opcode. */ | |
15333 | mac_ptr += offset_size; | |
15334 | break; | |
15335 | ||
15336 | case DW_MACINFO_vendor_ext: | |
15337 | /* Only skip the data by MAC_PTR. */ | |
15338 | if (!section_is_gnu) | |
15339 | { | |
15340 | unsigned int bytes_read; | |
15341 | ||
15342 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15343 | mac_ptr += bytes_read; | |
15344 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15345 | mac_ptr += bytes_read; | |
15346 | } | |
15347 | /* FALLTHROUGH */ | |
15348 | ||
15349 | default: | |
15350 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15351 | mac_ptr, abfd, offset_size, | |
15352 | section); | |
15353 | if (mac_ptr == NULL) | |
15354 | return; | |
15355 | break; | |
15356 | } | |
15357 | } while (macinfo_type != 0 && current_file == NULL); | |
15358 | ||
15359 | /* Second pass: Process all entries. | |
15360 | ||
15361 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
15362 | command-line macro definitions/undefinitions. This flag is unset when we | |
15363 | reach the first DW_MACINFO_start_file entry. */ | |
15364 | ||
15365 | dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end, | |
15366 | current_file, lh, comp_dir, section, section_is_gnu, | |
15367 | offset_size, cu->objfile); | |
15368 | } | |
15369 | ||
8e19ed76 | 15370 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 15371 | if so return true else false. */ |
8e19ed76 PS |
15372 | static int |
15373 | attr_form_is_block (struct attribute *attr) | |
15374 | { | |
15375 | return (attr == NULL ? 0 : | |
15376 | attr->form == DW_FORM_block1 | |
15377 | || attr->form == DW_FORM_block2 | |
15378 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
15379 | || attr->form == DW_FORM_block |
15380 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 15381 | } |
4c2df51b | 15382 | |
c6a0999f JB |
15383 | /* Return non-zero if ATTR's value is a section offset --- classes |
15384 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
15385 | You may use DW_UNSND (attr) to retrieve such offsets. | |
15386 | ||
15387 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
15388 | may have a value that belongs to more than one of these classes; it | |
15389 | would be ambiguous if we did, because we use the same forms for all | |
15390 | of them. */ | |
3690dd37 JB |
15391 | static int |
15392 | attr_form_is_section_offset (struct attribute *attr) | |
15393 | { | |
15394 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
15395 | || attr->form == DW_FORM_data8 |
15396 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
15397 | } |
15398 | ||
15399 | ||
15400 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
15401 | zero otherwise. When this function returns true, you can apply | |
15402 | dwarf2_get_attr_constant_value to it. | |
15403 | ||
15404 | However, note that for some attributes you must check | |
15405 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
15406 | and DW_FORM_data8 are members of both the constant class, and of | |
15407 | the classes that contain offsets into other debug sections | |
15408 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
15409 | that, if an attribute's can be either a constant or one of the | |
15410 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
15411 | taken as section offsets, not constants. */ | |
15412 | static int | |
15413 | attr_form_is_constant (struct attribute *attr) | |
15414 | { | |
15415 | switch (attr->form) | |
15416 | { | |
15417 | case DW_FORM_sdata: | |
15418 | case DW_FORM_udata: | |
15419 | case DW_FORM_data1: | |
15420 | case DW_FORM_data2: | |
15421 | case DW_FORM_data4: | |
15422 | case DW_FORM_data8: | |
15423 | return 1; | |
15424 | default: | |
15425 | return 0; | |
15426 | } | |
15427 | } | |
15428 | ||
8cf6f0b1 TT |
15429 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
15430 | ||
15431 | static void | |
15432 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
15433 | struct dwarf2_loclist_baton *baton, | |
15434 | struct attribute *attr) | |
15435 | { | |
15436 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
15437 | &dwarf2_per_objfile->loc); | |
15438 | ||
15439 | baton->per_cu = cu->per_cu; | |
15440 | gdb_assert (baton->per_cu); | |
15441 | /* We don't know how long the location list is, but make sure we | |
15442 | don't run off the edge of the section. */ | |
15443 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
15444 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
15445 | baton->base_address = cu->base_address; | |
15446 | } | |
15447 | ||
4c2df51b DJ |
15448 | static void |
15449 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 15450 | struct dwarf2_cu *cu) |
4c2df51b | 15451 | { |
3690dd37 | 15452 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
15453 | /* ".debug_loc" may not exist at all, or the offset may be outside |
15454 | the section. If so, fall through to the complaint in the | |
15455 | other branch. */ | |
9e0ac564 TT |
15456 | && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile, |
15457 | &dwarf2_per_objfile->loc)) | |
4c2df51b | 15458 | { |
0d53c4c4 | 15459 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 15460 | |
4a146b47 | 15461 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 15462 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 15463 | |
8cf6f0b1 | 15464 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 15465 | |
d00adf39 | 15466 | if (cu->base_known == 0) |
0d53c4c4 | 15467 | complaint (&symfile_complaints, |
3e43a32a MS |
15468 | _("Location list used without " |
15469 | "specifying the CU base address.")); | |
4c2df51b | 15470 | |
768a979c | 15471 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
15472 | SYMBOL_LOCATION_BATON (sym) = baton; |
15473 | } | |
15474 | else | |
15475 | { | |
15476 | struct dwarf2_locexpr_baton *baton; | |
15477 | ||
4a146b47 | 15478 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 15479 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
15480 | baton->per_cu = cu->per_cu; |
15481 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
15482 | |
15483 | if (attr_form_is_block (attr)) | |
15484 | { | |
15485 | /* Note that we're just copying the block's data pointer | |
15486 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
15487 | info_buffer for SYM's objfile; right now we never release |
15488 | that buffer, but when we do clean up properly this may | |
15489 | need to change. */ | |
0d53c4c4 DJ |
15490 | baton->size = DW_BLOCK (attr)->size; |
15491 | baton->data = DW_BLOCK (attr)->data; | |
15492 | } | |
15493 | else | |
15494 | { | |
15495 | dwarf2_invalid_attrib_class_complaint ("location description", | |
15496 | SYMBOL_NATURAL_NAME (sym)); | |
15497 | baton->size = 0; | |
15498 | baton->data = NULL; | |
15499 | } | |
6e70227d | 15500 | |
768a979c | 15501 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
15502 | SYMBOL_LOCATION_BATON (sym) = baton; |
15503 | } | |
4c2df51b | 15504 | } |
6502dd73 | 15505 | |
9aa1f1e3 TT |
15506 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
15507 | came from a separate debuginfo file, then the master objfile is | |
15508 | returned. */ | |
ae0d2f24 UW |
15509 | |
15510 | struct objfile * | |
15511 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
15512 | { | |
9291a0cd | 15513 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
15514 | |
15515 | /* Return the master objfile, so that we can report and look up the | |
15516 | correct file containing this variable. */ | |
15517 | if (objfile->separate_debug_objfile_backlink) | |
15518 | objfile = objfile->separate_debug_objfile_backlink; | |
15519 | ||
15520 | return objfile; | |
15521 | } | |
15522 | ||
96408a79 SA |
15523 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
15524 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
15525 | CU_HEADERP first. */ | |
15526 | ||
15527 | static const struct comp_unit_head * | |
15528 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
15529 | struct dwarf2_per_cu_data *per_cu) | |
15530 | { | |
15531 | struct objfile *objfile; | |
15532 | struct dwarf2_per_objfile *per_objfile; | |
15533 | gdb_byte *info_ptr; | |
15534 | ||
15535 | if (per_cu->cu) | |
15536 | return &per_cu->cu->header; | |
15537 | ||
15538 | objfile = per_cu->objfile; | |
15539 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15540 | info_ptr = per_objfile->info.buffer + per_cu->offset; | |
15541 | ||
15542 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
15543 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); | |
15544 | ||
15545 | return cu_headerp; | |
15546 | } | |
15547 | ||
ae0d2f24 UW |
15548 | /* Return the address size given in the compilation unit header for CU. */ |
15549 | ||
15550 | CORE_ADDR | |
15551 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
15552 | { | |
96408a79 SA |
15553 | struct comp_unit_head cu_header_local; |
15554 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 15555 | |
96408a79 SA |
15556 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15557 | ||
15558 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
15559 | } |
15560 | ||
9eae7c52 TT |
15561 | /* Return the offset size given in the compilation unit header for CU. */ |
15562 | ||
15563 | int | |
15564 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
15565 | { | |
96408a79 SA |
15566 | struct comp_unit_head cu_header_local; |
15567 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 15568 | |
96408a79 SA |
15569 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15570 | ||
15571 | return cu_headerp->offset_size; | |
15572 | } | |
15573 | ||
15574 | /* See its dwarf2loc.h declaration. */ | |
15575 | ||
15576 | int | |
15577 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
15578 | { | |
15579 | struct comp_unit_head cu_header_local; | |
15580 | const struct comp_unit_head *cu_headerp; | |
15581 | ||
15582 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
15583 | ||
15584 | if (cu_headerp->version == 2) | |
15585 | return cu_headerp->addr_size; | |
15586 | else | |
15587 | return cu_headerp->offset_size; | |
181cebd4 JK |
15588 | } |
15589 | ||
9aa1f1e3 TT |
15590 | /* Return the text offset of the CU. The returned offset comes from |
15591 | this CU's objfile. If this objfile came from a separate debuginfo | |
15592 | file, then the offset may be different from the corresponding | |
15593 | offset in the parent objfile. */ | |
15594 | ||
15595 | CORE_ADDR | |
15596 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
15597 | { | |
bb3fa9d0 | 15598 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
15599 | |
15600 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
15601 | } | |
15602 | ||
348e048f DE |
15603 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
15604 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
15605 | |
15606 | static struct dwarf2_per_cu_data * | |
c764a876 | 15607 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
15608 | struct objfile *objfile) |
15609 | { | |
15610 | struct dwarf2_per_cu_data *this_cu; | |
15611 | int low, high; | |
15612 | ||
ae038cb0 DJ |
15613 | low = 0; |
15614 | high = dwarf2_per_objfile->n_comp_units - 1; | |
15615 | while (high > low) | |
15616 | { | |
15617 | int mid = low + (high - low) / 2; | |
9a619af0 | 15618 | |
ae038cb0 DJ |
15619 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
15620 | high = mid; | |
15621 | else | |
15622 | low = mid + 1; | |
15623 | } | |
15624 | gdb_assert (low == high); | |
15625 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
15626 | { | |
10b3939b | 15627 | if (low == 0) |
8a3fe4f8 AC |
15628 | error (_("Dwarf Error: could not find partial DIE containing " |
15629 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
15630 | (long) offset, bfd_get_filename (objfile->obfd)); |
15631 | ||
ae038cb0 DJ |
15632 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
15633 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
15634 | } | |
15635 | else | |
15636 | { | |
15637 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
15638 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
15639 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 15640 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
15641 | gdb_assert (offset < this_cu->offset + this_cu->length); |
15642 | return this_cu; | |
15643 | } | |
15644 | } | |
15645 | ||
10b3939b DJ |
15646 | /* Locate the compilation unit from OBJFILE which is located at exactly |
15647 | OFFSET. Raises an error on failure. */ | |
15648 | ||
ae038cb0 | 15649 | static struct dwarf2_per_cu_data * |
c764a876 | 15650 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
15651 | { |
15652 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 15653 | |
ae038cb0 DJ |
15654 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
15655 | if (this_cu->offset != offset) | |
c764a876 | 15656 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
15657 | return this_cu; |
15658 | } | |
15659 | ||
9816fde3 | 15660 | /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */ |
93311388 | 15661 | |
9816fde3 JK |
15662 | static void |
15663 | init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile) | |
93311388 | 15664 | { |
9816fde3 | 15665 | memset (cu, 0, sizeof (*cu)); |
93311388 DE |
15666 | cu->objfile = objfile; |
15667 | obstack_init (&cu->comp_unit_obstack); | |
9816fde3 JK |
15668 | } |
15669 | ||
15670 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
15671 | ||
15672 | static void | |
15673 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
15674 | { | |
15675 | struct attribute *attr; | |
15676 | ||
15677 | /* Set the language we're debugging. */ | |
15678 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
15679 | if (attr) | |
15680 | set_cu_language (DW_UNSND (attr), cu); | |
15681 | else | |
9cded63f TT |
15682 | { |
15683 | cu->language = language_minimal; | |
15684 | cu->language_defn = language_def (cu->language); | |
15685 | } | |
93311388 DE |
15686 | } |
15687 | ||
ae038cb0 DJ |
15688 | /* Release one cached compilation unit, CU. We unlink it from the tree |
15689 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
15690 | the caller is responsible for that. |
15691 | NOTE: DATA is a void * because this function is also used as a | |
15692 | cleanup routine. */ | |
ae038cb0 DJ |
15693 | |
15694 | static void | |
15695 | free_one_comp_unit (void *data) | |
15696 | { | |
15697 | struct dwarf2_cu *cu = data; | |
15698 | ||
15699 | if (cu->per_cu != NULL) | |
15700 | cu->per_cu->cu = NULL; | |
15701 | cu->per_cu = NULL; | |
15702 | ||
15703 | obstack_free (&cu->comp_unit_obstack, NULL); | |
15704 | ||
15705 | xfree (cu); | |
15706 | } | |
15707 | ||
72bf9492 | 15708 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
15709 | when we're finished with it. We can't free the pointer itself, but be |
15710 | sure to unlink it from the cache. Also release any associated storage | |
15711 | and perform cache maintenance. | |
72bf9492 DJ |
15712 | |
15713 | Only used during partial symbol parsing. */ | |
15714 | ||
15715 | static void | |
15716 | free_stack_comp_unit (void *data) | |
15717 | { | |
15718 | struct dwarf2_cu *cu = data; | |
15719 | ||
15720 | obstack_free (&cu->comp_unit_obstack, NULL); | |
15721 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
15722 | |
15723 | if (cu->per_cu != NULL) | |
15724 | { | |
15725 | /* This compilation unit is on the stack in our caller, so we | |
15726 | should not xfree it. Just unlink it. */ | |
15727 | cu->per_cu->cu = NULL; | |
15728 | cu->per_cu = NULL; | |
15729 | ||
15730 | /* If we had a per-cu pointer, then we may have other compilation | |
15731 | units loaded, so age them now. */ | |
15732 | age_cached_comp_units (); | |
15733 | } | |
15734 | } | |
15735 | ||
15736 | /* Free all cached compilation units. */ | |
15737 | ||
15738 | static void | |
15739 | free_cached_comp_units (void *data) | |
15740 | { | |
15741 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15742 | ||
15743 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15744 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15745 | while (per_cu != NULL) | |
15746 | { | |
15747 | struct dwarf2_per_cu_data *next_cu; | |
15748 | ||
15749 | next_cu = per_cu->cu->read_in_chain; | |
15750 | ||
15751 | free_one_comp_unit (per_cu->cu); | |
15752 | *last_chain = next_cu; | |
15753 | ||
15754 | per_cu = next_cu; | |
15755 | } | |
15756 | } | |
15757 | ||
15758 | /* Increase the age counter on each cached compilation unit, and free | |
15759 | any that are too old. */ | |
15760 | ||
15761 | static void | |
15762 | age_cached_comp_units (void) | |
15763 | { | |
15764 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15765 | ||
15766 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
15767 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15768 | while (per_cu != NULL) | |
15769 | { | |
15770 | per_cu->cu->last_used ++; | |
15771 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
15772 | dwarf2_mark (per_cu->cu); | |
15773 | per_cu = per_cu->cu->read_in_chain; | |
15774 | } | |
15775 | ||
15776 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15777 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15778 | while (per_cu != NULL) | |
15779 | { | |
15780 | struct dwarf2_per_cu_data *next_cu; | |
15781 | ||
15782 | next_cu = per_cu->cu->read_in_chain; | |
15783 | ||
15784 | if (!per_cu->cu->mark) | |
15785 | { | |
15786 | free_one_comp_unit (per_cu->cu); | |
15787 | *last_chain = next_cu; | |
15788 | } | |
15789 | else | |
15790 | last_chain = &per_cu->cu->read_in_chain; | |
15791 | ||
15792 | per_cu = next_cu; | |
15793 | } | |
15794 | } | |
15795 | ||
15796 | /* Remove a single compilation unit from the cache. */ | |
15797 | ||
15798 | static void | |
15799 | free_one_cached_comp_unit (void *target_cu) | |
15800 | { | |
15801 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15802 | ||
15803 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15804 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15805 | while (per_cu != NULL) | |
15806 | { | |
15807 | struct dwarf2_per_cu_data *next_cu; | |
15808 | ||
15809 | next_cu = per_cu->cu->read_in_chain; | |
15810 | ||
15811 | if (per_cu->cu == target_cu) | |
15812 | { | |
15813 | free_one_comp_unit (per_cu->cu); | |
15814 | *last_chain = next_cu; | |
15815 | break; | |
15816 | } | |
15817 | else | |
15818 | last_chain = &per_cu->cu->read_in_chain; | |
15819 | ||
15820 | per_cu = next_cu; | |
15821 | } | |
15822 | } | |
15823 | ||
fe3e1990 DJ |
15824 | /* Release all extra memory associated with OBJFILE. */ |
15825 | ||
15826 | void | |
15827 | dwarf2_free_objfile (struct objfile *objfile) | |
15828 | { | |
15829 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15830 | ||
15831 | if (dwarf2_per_objfile == NULL) | |
15832 | return; | |
15833 | ||
15834 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
15835 | free_cached_comp_units (NULL); | |
15836 | ||
7b9f3c50 DE |
15837 | if (dwarf2_per_objfile->quick_file_names_table) |
15838 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 15839 | |
fe3e1990 DJ |
15840 | /* Everything else should be on the objfile obstack. */ |
15841 | } | |
15842 | ||
1c379e20 DJ |
15843 | /* A pair of DIE offset and GDB type pointer. We store these |
15844 | in a hash table separate from the DIEs, and preserve them | |
15845 | when the DIEs are flushed out of cache. */ | |
15846 | ||
15847 | struct dwarf2_offset_and_type | |
15848 | { | |
15849 | unsigned int offset; | |
15850 | struct type *type; | |
15851 | }; | |
15852 | ||
15853 | /* Hash function for a dwarf2_offset_and_type. */ | |
15854 | ||
15855 | static hashval_t | |
15856 | offset_and_type_hash (const void *item) | |
15857 | { | |
15858 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 15859 | |
1c379e20 DJ |
15860 | return ofs->offset; |
15861 | } | |
15862 | ||
15863 | /* Equality function for a dwarf2_offset_and_type. */ | |
15864 | ||
15865 | static int | |
15866 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
15867 | { | |
15868 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
15869 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 15870 | |
1c379e20 DJ |
15871 | return ofs_lhs->offset == ofs_rhs->offset; |
15872 | } | |
15873 | ||
15874 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
15875 | table if necessary. For convenience, return TYPE. |
15876 | ||
15877 | The DIEs reading must have careful ordering to: | |
15878 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
15879 | reading current DIE. | |
15880 | * Not trying to dereference contents of still incompletely read in types | |
15881 | while reading in other DIEs. | |
15882 | * Enable referencing still incompletely read in types just by a pointer to | |
15883 | the type without accessing its fields. | |
15884 | ||
15885 | Therefore caller should follow these rules: | |
15886 | * Try to fetch any prerequisite types we may need to build this DIE type | |
15887 | before building the type and calling set_die_type. | |
e71ec853 | 15888 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
15889 | possible before fetching more types to complete the current type. |
15890 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 15891 | |
f792889a | 15892 | static struct type * |
1c379e20 DJ |
15893 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
15894 | { | |
15895 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
15896 | struct objfile *objfile = cu->objfile; |
15897 | htab_t *type_hash_ptr; | |
1c379e20 | 15898 | |
b4ba55a1 JB |
15899 | /* For Ada types, make sure that the gnat-specific data is always |
15900 | initialized (if not already set). There are a few types where | |
15901 | we should not be doing so, because the type-specific area is | |
15902 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
15903 | where the type-specific area is used to store the floatformat). | |
15904 | But this is not a problem, because the gnat-specific information | |
15905 | is actually not needed for these types. */ | |
15906 | if (need_gnat_info (cu) | |
15907 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
15908 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
15909 | && !HAVE_GNAT_AUX_INFO (type)) | |
15910 | INIT_GNAT_SPECIFIC (type); | |
15911 | ||
8b70b953 | 15912 | if (cu->per_cu->debug_type_section) |
673bfd45 DE |
15913 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; |
15914 | else | |
15915 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
15916 | ||
15917 | if (*type_hash_ptr == NULL) | |
f792889a | 15918 | { |
673bfd45 DE |
15919 | *type_hash_ptr |
15920 | = htab_create_alloc_ex (127, | |
f792889a DJ |
15921 | offset_and_type_hash, |
15922 | offset_and_type_eq, | |
15923 | NULL, | |
673bfd45 | 15924 | &objfile->objfile_obstack, |
f792889a DJ |
15925 | hashtab_obstack_allocate, |
15926 | dummy_obstack_deallocate); | |
f792889a | 15927 | } |
1c379e20 DJ |
15928 | |
15929 | ofs.offset = die->offset; | |
15930 | ofs.type = type; | |
15931 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 15932 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
15933 | if (*slot) |
15934 | complaint (&symfile_complaints, | |
15935 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
15936 | die->offset); | |
673bfd45 | 15937 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 15938 | **slot = ofs; |
f792889a | 15939 | return type; |
1c379e20 DJ |
15940 | } |
15941 | ||
673bfd45 DE |
15942 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
15943 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
15944 | |
15945 | static struct type * | |
673bfd45 DE |
15946 | get_die_type_at_offset (unsigned int offset, |
15947 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
15948 | { |
15949 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 15950 | htab_t type_hash; |
f792889a | 15951 | |
8b70b953 | 15952 | if (per_cu->debug_type_section) |
673bfd45 DE |
15953 | type_hash = dwarf2_per_objfile->debug_types_type_hash; |
15954 | else | |
15955 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
15956 | if (type_hash == NULL) |
15957 | return NULL; | |
1c379e20 | 15958 | |
673bfd45 | 15959 | ofs.offset = offset; |
1c379e20 DJ |
15960 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
15961 | if (slot) | |
15962 | return slot->type; | |
15963 | else | |
15964 | return NULL; | |
15965 | } | |
15966 | ||
673bfd45 DE |
15967 | /* Look up the type for DIE in the appropriate type_hash table, |
15968 | or return NULL if DIE does not have a saved type. */ | |
15969 | ||
15970 | static struct type * | |
15971 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
15972 | { | |
15973 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
15974 | } | |
15975 | ||
10b3939b DJ |
15976 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
15977 | ||
15978 | static void | |
15979 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
15980 | struct dwarf2_per_cu_data *ref_per_cu) | |
15981 | { | |
15982 | void **slot; | |
15983 | ||
15984 | if (cu->dependencies == NULL) | |
15985 | cu->dependencies | |
15986 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
15987 | NULL, &cu->comp_unit_obstack, | |
15988 | hashtab_obstack_allocate, | |
15989 | dummy_obstack_deallocate); | |
15990 | ||
15991 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
15992 | if (*slot == NULL) | |
15993 | *slot = ref_per_cu; | |
15994 | } | |
1c379e20 | 15995 | |
f504f079 DE |
15996 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
15997 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
15998 | cache that we must keep because we are keeping CU. */ |
15999 | ||
10b3939b DJ |
16000 | static int |
16001 | dwarf2_mark_helper (void **slot, void *data) | |
16002 | { | |
16003 | struct dwarf2_per_cu_data *per_cu; | |
16004 | ||
16005 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
16006 | |
16007 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
16008 | reading of the chain. As such dependencies remain valid it is not much | |
16009 | useful to track and undo them during QUIT cleanups. */ | |
16010 | if (per_cu->cu == NULL) | |
16011 | return 1; | |
16012 | ||
10b3939b DJ |
16013 | if (per_cu->cu->mark) |
16014 | return 1; | |
16015 | per_cu->cu->mark = 1; | |
16016 | ||
16017 | if (per_cu->cu->dependencies != NULL) | |
16018 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
16019 | ||
16020 | return 1; | |
16021 | } | |
16022 | ||
f504f079 DE |
16023 | /* Set the mark field in CU and in every other compilation unit in the |
16024 | cache that we must keep because we are keeping CU. */ | |
16025 | ||
ae038cb0 DJ |
16026 | static void |
16027 | dwarf2_mark (struct dwarf2_cu *cu) | |
16028 | { | |
16029 | if (cu->mark) | |
16030 | return; | |
16031 | cu->mark = 1; | |
10b3939b DJ |
16032 | if (cu->dependencies != NULL) |
16033 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
16034 | } |
16035 | ||
16036 | static void | |
16037 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
16038 | { | |
16039 | while (per_cu) | |
16040 | { | |
16041 | per_cu->cu->mark = 0; | |
16042 | per_cu = per_cu->cu->read_in_chain; | |
16043 | } | |
72bf9492 DJ |
16044 | } |
16045 | ||
72bf9492 DJ |
16046 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
16047 | is its offset in .debug_info for this objfile. */ | |
16048 | ||
16049 | static hashval_t | |
16050 | partial_die_hash (const void *item) | |
16051 | { | |
16052 | const struct partial_die_info *part_die = item; | |
9a619af0 | 16053 | |
72bf9492 DJ |
16054 | return part_die->offset; |
16055 | } | |
16056 | ||
16057 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
16058 | are equal if they have the same offset. */ | |
16059 | ||
16060 | static int | |
16061 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
16062 | { | |
16063 | const struct partial_die_info *part_die_lhs = item_lhs; | |
16064 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 16065 | |
72bf9492 DJ |
16066 | return part_die_lhs->offset == part_die_rhs->offset; |
16067 | } | |
16068 | ||
ae038cb0 DJ |
16069 | static struct cmd_list_element *set_dwarf2_cmdlist; |
16070 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
16071 | ||
16072 | static void | |
16073 | set_dwarf2_cmd (char *args, int from_tty) | |
16074 | { | |
16075 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
16076 | } | |
16077 | ||
16078 | static void | |
16079 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 16080 | { |
ae038cb0 DJ |
16081 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
16082 | } | |
16083 | ||
dce234bc PP |
16084 | /* If section described by INFO was mmapped, munmap it now. */ |
16085 | ||
16086 | static void | |
16087 | munmap_section_buffer (struct dwarf2_section_info *info) | |
16088 | { | |
b315ab21 | 16089 | if (info->map_addr != NULL) |
dce234bc PP |
16090 | { |
16091 | #ifdef HAVE_MMAP | |
b315ab21 | 16092 | int res; |
9a619af0 | 16093 | |
b315ab21 TG |
16094 | res = munmap (info->map_addr, info->map_len); |
16095 | gdb_assert (res == 0); | |
dce234bc PP |
16096 | #else |
16097 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 16098 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
16099 | #endif |
16100 | } | |
16101 | } | |
16102 | ||
16103 | /* munmap debug sections for OBJFILE, if necessary. */ | |
16104 | ||
16105 | static void | |
c1bd65d0 | 16106 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
16107 | { |
16108 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
16109 | int ix; |
16110 | struct dwarf2_section_info *section; | |
9a619af0 | 16111 | |
16be1145 DE |
16112 | /* This is sorted according to the order they're defined in to make it easier |
16113 | to keep in sync. */ | |
dce234bc PP |
16114 | munmap_section_buffer (&data->info); |
16115 | munmap_section_buffer (&data->abbrev); | |
16116 | munmap_section_buffer (&data->line); | |
16be1145 | 16117 | munmap_section_buffer (&data->loc); |
dce234bc | 16118 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 16119 | munmap_section_buffer (&data->macro); |
16be1145 | 16120 | munmap_section_buffer (&data->str); |
dce234bc | 16121 | munmap_section_buffer (&data->ranges); |
dce234bc PP |
16122 | munmap_section_buffer (&data->frame); |
16123 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 16124 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
16125 | |
16126 | for (ix = 0; | |
16127 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
16128 | ++ix) | |
16129 | munmap_section_buffer (section); | |
16130 | ||
16131 | VEC_free (dwarf2_section_info_def, data->types); | |
9291a0cd TT |
16132 | } |
16133 | ||
16134 | \f | |
ae2de4f8 | 16135 | /* The "save gdb-index" command. */ |
9291a0cd TT |
16136 | |
16137 | /* The contents of the hash table we create when building the string | |
16138 | table. */ | |
16139 | struct strtab_entry | |
16140 | { | |
16141 | offset_type offset; | |
16142 | const char *str; | |
16143 | }; | |
16144 | ||
559a7a62 JK |
16145 | /* Hash function for a strtab_entry. |
16146 | ||
16147 | Function is used only during write_hash_table so no index format backward | |
16148 | compatibility is needed. */ | |
b89be57b | 16149 | |
9291a0cd TT |
16150 | static hashval_t |
16151 | hash_strtab_entry (const void *e) | |
16152 | { | |
16153 | const struct strtab_entry *entry = e; | |
559a7a62 | 16154 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
16155 | } |
16156 | ||
16157 | /* Equality function for a strtab_entry. */ | |
b89be57b | 16158 | |
9291a0cd TT |
16159 | static int |
16160 | eq_strtab_entry (const void *a, const void *b) | |
16161 | { | |
16162 | const struct strtab_entry *ea = a; | |
16163 | const struct strtab_entry *eb = b; | |
16164 | return !strcmp (ea->str, eb->str); | |
16165 | } | |
16166 | ||
16167 | /* Create a strtab_entry hash table. */ | |
b89be57b | 16168 | |
9291a0cd TT |
16169 | static htab_t |
16170 | create_strtab (void) | |
16171 | { | |
16172 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
16173 | xfree, xcalloc, xfree); | |
16174 | } | |
16175 | ||
16176 | /* Add a string to the constant pool. Return the string's offset in | |
16177 | host order. */ | |
b89be57b | 16178 | |
9291a0cd TT |
16179 | static offset_type |
16180 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
16181 | { | |
16182 | void **slot; | |
16183 | struct strtab_entry entry; | |
16184 | struct strtab_entry *result; | |
16185 | ||
16186 | entry.str = str; | |
16187 | slot = htab_find_slot (table, &entry, INSERT); | |
16188 | if (*slot) | |
16189 | result = *slot; | |
16190 | else | |
16191 | { | |
16192 | result = XNEW (struct strtab_entry); | |
16193 | result->offset = obstack_object_size (cpool); | |
16194 | result->str = str; | |
16195 | obstack_grow_str0 (cpool, str); | |
16196 | *slot = result; | |
16197 | } | |
16198 | return result->offset; | |
16199 | } | |
16200 | ||
16201 | /* An entry in the symbol table. */ | |
16202 | struct symtab_index_entry | |
16203 | { | |
16204 | /* The name of the symbol. */ | |
16205 | const char *name; | |
16206 | /* The offset of the name in the constant pool. */ | |
16207 | offset_type index_offset; | |
16208 | /* A sorted vector of the indices of all the CUs that hold an object | |
16209 | of this name. */ | |
16210 | VEC (offset_type) *cu_indices; | |
16211 | }; | |
16212 | ||
16213 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
16214 | struct mapped_symtab | |
16215 | { | |
16216 | offset_type n_elements; | |
16217 | offset_type size; | |
16218 | struct symtab_index_entry **data; | |
16219 | }; | |
16220 | ||
16221 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 16222 | |
9291a0cd TT |
16223 | static hashval_t |
16224 | hash_symtab_entry (const void *e) | |
16225 | { | |
16226 | const struct symtab_index_entry *entry = e; | |
16227 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
16228 | sizeof (offset_type) * VEC_length (offset_type, | |
16229 | entry->cu_indices), | |
16230 | 0); | |
16231 | } | |
16232 | ||
16233 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 16234 | |
9291a0cd TT |
16235 | static int |
16236 | eq_symtab_entry (const void *a, const void *b) | |
16237 | { | |
16238 | const struct symtab_index_entry *ea = a; | |
16239 | const struct symtab_index_entry *eb = b; | |
16240 | int len = VEC_length (offset_type, ea->cu_indices); | |
16241 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
16242 | return 0; | |
16243 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
16244 | VEC_address (offset_type, eb->cu_indices), | |
16245 | sizeof (offset_type) * len); | |
16246 | } | |
16247 | ||
16248 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 16249 | |
9291a0cd TT |
16250 | static void |
16251 | delete_symtab_entry (void *p) | |
16252 | { | |
16253 | struct symtab_index_entry *entry = p; | |
16254 | VEC_free (offset_type, entry->cu_indices); | |
16255 | xfree (entry); | |
16256 | } | |
16257 | ||
16258 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 16259 | |
9291a0cd | 16260 | static htab_t |
3876f04e | 16261 | create_symbol_hash_table (void) |
9291a0cd TT |
16262 | { |
16263 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
16264 | delete_symtab_entry, xcalloc, xfree); | |
16265 | } | |
16266 | ||
16267 | /* Create a new mapped symtab object. */ | |
b89be57b | 16268 | |
9291a0cd TT |
16269 | static struct mapped_symtab * |
16270 | create_mapped_symtab (void) | |
16271 | { | |
16272 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
16273 | symtab->n_elements = 0; | |
16274 | symtab->size = 1024; | |
16275 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16276 | return symtab; | |
16277 | } | |
16278 | ||
16279 | /* Destroy a mapped_symtab. */ | |
b89be57b | 16280 | |
9291a0cd TT |
16281 | static void |
16282 | cleanup_mapped_symtab (void *p) | |
16283 | { | |
16284 | struct mapped_symtab *symtab = p; | |
16285 | /* The contents of the array are freed when the other hash table is | |
16286 | destroyed. */ | |
16287 | xfree (symtab->data); | |
16288 | xfree (symtab); | |
16289 | } | |
16290 | ||
16291 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
16292 | the slot. |
16293 | ||
16294 | Function is used only during write_hash_table so no index format backward | |
16295 | compatibility is needed. */ | |
b89be57b | 16296 | |
9291a0cd TT |
16297 | static struct symtab_index_entry ** |
16298 | find_slot (struct mapped_symtab *symtab, const char *name) | |
16299 | { | |
559a7a62 | 16300 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
16301 | |
16302 | index = hash & (symtab->size - 1); | |
16303 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
16304 | ||
16305 | for (;;) | |
16306 | { | |
16307 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
16308 | return &symtab->data[index]; | |
16309 | index = (index + step) & (symtab->size - 1); | |
16310 | } | |
16311 | } | |
16312 | ||
16313 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 16314 | |
9291a0cd TT |
16315 | static void |
16316 | hash_expand (struct mapped_symtab *symtab) | |
16317 | { | |
16318 | offset_type old_size = symtab->size; | |
16319 | offset_type i; | |
16320 | struct symtab_index_entry **old_entries = symtab->data; | |
16321 | ||
16322 | symtab->size *= 2; | |
16323 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16324 | ||
16325 | for (i = 0; i < old_size; ++i) | |
16326 | { | |
16327 | if (old_entries[i]) | |
16328 | { | |
16329 | struct symtab_index_entry **slot = find_slot (symtab, | |
16330 | old_entries[i]->name); | |
16331 | *slot = old_entries[i]; | |
16332 | } | |
16333 | } | |
16334 | ||
16335 | xfree (old_entries); | |
16336 | } | |
16337 | ||
16338 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
16339 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 16340 | |
9291a0cd TT |
16341 | static void |
16342 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
16343 | offset_type cu_index) | |
16344 | { | |
16345 | struct symtab_index_entry **slot; | |
16346 | ||
16347 | ++symtab->n_elements; | |
16348 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
16349 | hash_expand (symtab); | |
16350 | ||
16351 | slot = find_slot (symtab, name); | |
16352 | if (!*slot) | |
16353 | { | |
16354 | *slot = XNEW (struct symtab_index_entry); | |
16355 | (*slot)->name = name; | |
16356 | (*slot)->cu_indices = NULL; | |
16357 | } | |
16358 | /* Don't push an index twice. Due to how we add entries we only | |
16359 | have to check the last one. */ | |
16360 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 16361 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
16362 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
16363 | } | |
16364 | ||
16365 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 16366 | |
9291a0cd | 16367 | static offset_type |
3876f04e | 16368 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
16369 | struct symtab_index_entry *entry) |
16370 | { | |
16371 | void **slot; | |
16372 | ||
3876f04e | 16373 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
16374 | if (!*slot) |
16375 | { | |
16376 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
16377 | offset_type val = MAYBE_SWAP (len); | |
16378 | offset_type iter; | |
16379 | int i; | |
16380 | ||
16381 | *slot = entry; | |
16382 | entry->index_offset = obstack_object_size (cpool); | |
16383 | ||
16384 | obstack_grow (cpool, &val, sizeof (val)); | |
16385 | for (i = 0; | |
16386 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
16387 | ++i) | |
16388 | { | |
16389 | val = MAYBE_SWAP (iter); | |
16390 | obstack_grow (cpool, &val, sizeof (val)); | |
16391 | } | |
16392 | } | |
16393 | else | |
16394 | { | |
16395 | struct symtab_index_entry *old_entry = *slot; | |
16396 | entry->index_offset = old_entry->index_offset; | |
16397 | entry = old_entry; | |
16398 | } | |
16399 | return entry->index_offset; | |
16400 | } | |
16401 | ||
16402 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
16403 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 16404 | |
9291a0cd TT |
16405 | static void |
16406 | write_hash_table (struct mapped_symtab *symtab, | |
16407 | struct obstack *output, struct obstack *cpool) | |
16408 | { | |
16409 | offset_type i; | |
3876f04e | 16410 | htab_t symbol_hash_table; |
9291a0cd TT |
16411 | htab_t str_table; |
16412 | ||
3876f04e | 16413 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 16414 | str_table = create_strtab (); |
3876f04e | 16415 | |
9291a0cd TT |
16416 | /* We add all the index vectors to the constant pool first, to |
16417 | ensure alignment is ok. */ | |
16418 | for (i = 0; i < symtab->size; ++i) | |
16419 | { | |
16420 | if (symtab->data[i]) | |
3876f04e | 16421 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
16422 | } |
16423 | ||
16424 | /* Now write out the hash table. */ | |
16425 | for (i = 0; i < symtab->size; ++i) | |
16426 | { | |
16427 | offset_type str_off, vec_off; | |
16428 | ||
16429 | if (symtab->data[i]) | |
16430 | { | |
16431 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
16432 | vec_off = symtab->data[i]->index_offset; | |
16433 | } | |
16434 | else | |
16435 | { | |
16436 | /* While 0 is a valid constant pool index, it is not valid | |
16437 | to have 0 for both offsets. */ | |
16438 | str_off = 0; | |
16439 | vec_off = 0; | |
16440 | } | |
16441 | ||
16442 | str_off = MAYBE_SWAP (str_off); | |
16443 | vec_off = MAYBE_SWAP (vec_off); | |
16444 | ||
16445 | obstack_grow (output, &str_off, sizeof (str_off)); | |
16446 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
16447 | } | |
16448 | ||
16449 | htab_delete (str_table); | |
3876f04e | 16450 | htab_delete (symbol_hash_table); |
9291a0cd TT |
16451 | } |
16452 | ||
0a5429f6 DE |
16453 | /* Struct to map psymtab to CU index in the index file. */ |
16454 | struct psymtab_cu_index_map | |
16455 | { | |
16456 | struct partial_symtab *psymtab; | |
16457 | unsigned int cu_index; | |
16458 | }; | |
16459 | ||
16460 | static hashval_t | |
16461 | hash_psymtab_cu_index (const void *item) | |
16462 | { | |
16463 | const struct psymtab_cu_index_map *map = item; | |
16464 | ||
16465 | return htab_hash_pointer (map->psymtab); | |
16466 | } | |
16467 | ||
16468 | static int | |
16469 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
16470 | { | |
16471 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
16472 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
16473 | ||
16474 | return lhs->psymtab == rhs->psymtab; | |
16475 | } | |
16476 | ||
16477 | /* Helper struct for building the address table. */ | |
16478 | struct addrmap_index_data | |
16479 | { | |
16480 | struct objfile *objfile; | |
16481 | struct obstack *addr_obstack; | |
16482 | htab_t cu_index_htab; | |
16483 | ||
16484 | /* Non-zero if the previous_* fields are valid. | |
16485 | We can't write an entry until we see the next entry (since it is only then | |
16486 | that we know the end of the entry). */ | |
16487 | int previous_valid; | |
16488 | /* Index of the CU in the table of all CUs in the index file. */ | |
16489 | unsigned int previous_cu_index; | |
0963b4bd | 16490 | /* Start address of the CU. */ |
0a5429f6 DE |
16491 | CORE_ADDR previous_cu_start; |
16492 | }; | |
16493 | ||
16494 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 16495 | |
9291a0cd | 16496 | static void |
0a5429f6 DE |
16497 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
16498 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 16499 | { |
0a5429f6 | 16500 | offset_type cu_index_to_write; |
9291a0cd TT |
16501 | char addr[8]; |
16502 | CORE_ADDR baseaddr; | |
16503 | ||
16504 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16505 | ||
0a5429f6 DE |
16506 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
16507 | obstack_grow (obstack, addr, 8); | |
16508 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
16509 | obstack_grow (obstack, addr, 8); | |
16510 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
16511 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
16512 | } | |
16513 | ||
16514 | /* Worker function for traversing an addrmap to build the address table. */ | |
16515 | ||
16516 | static int | |
16517 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
16518 | { | |
16519 | struct addrmap_index_data *data = datap; | |
16520 | struct partial_symtab *pst = obj; | |
16521 | offset_type cu_index; | |
16522 | void **slot; | |
16523 | ||
16524 | if (data->previous_valid) | |
16525 | add_address_entry (data->objfile, data->addr_obstack, | |
16526 | data->previous_cu_start, start_addr, | |
16527 | data->previous_cu_index); | |
16528 | ||
16529 | data->previous_cu_start = start_addr; | |
16530 | if (pst != NULL) | |
16531 | { | |
16532 | struct psymtab_cu_index_map find_map, *map; | |
16533 | find_map.psymtab = pst; | |
16534 | map = htab_find (data->cu_index_htab, &find_map); | |
16535 | gdb_assert (map != NULL); | |
16536 | data->previous_cu_index = map->cu_index; | |
16537 | data->previous_valid = 1; | |
16538 | } | |
16539 | else | |
16540 | data->previous_valid = 0; | |
16541 | ||
16542 | return 0; | |
16543 | } | |
16544 | ||
16545 | /* Write OBJFILE's address map to OBSTACK. | |
16546 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
16547 | in the index file. */ | |
16548 | ||
16549 | static void | |
16550 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
16551 | htab_t cu_index_htab) | |
16552 | { | |
16553 | struct addrmap_index_data addrmap_index_data; | |
16554 | ||
16555 | /* When writing the address table, we have to cope with the fact that | |
16556 | the addrmap iterator only provides the start of a region; we have to | |
16557 | wait until the next invocation to get the start of the next region. */ | |
16558 | ||
16559 | addrmap_index_data.objfile = objfile; | |
16560 | addrmap_index_data.addr_obstack = obstack; | |
16561 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
16562 | addrmap_index_data.previous_valid = 0; | |
16563 | ||
16564 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
16565 | &addrmap_index_data); | |
16566 | ||
16567 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
16568 | is valid, but we should still handle it. | |
16569 | The end address is recorded as the start of the next region, but that | |
16570 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
16571 | anyway. */ | |
16572 | if (addrmap_index_data.previous_valid) | |
16573 | add_address_entry (objfile, obstack, | |
16574 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
16575 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
16576 | } |
16577 | ||
16578 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 16579 | |
9291a0cd TT |
16580 | static void |
16581 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 16582 | htab_t psyms_seen, |
9291a0cd TT |
16583 | struct partial_symbol **psymp, |
16584 | int count, | |
987d643c TT |
16585 | offset_type cu_index, |
16586 | int is_static) | |
9291a0cd TT |
16587 | { |
16588 | for (; count-- > 0; ++psymp) | |
16589 | { | |
987d643c TT |
16590 | void **slot, *lookup; |
16591 | ||
9291a0cd TT |
16592 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
16593 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
16594 | |
16595 | /* We only want to add a given psymbol once. However, we also | |
16596 | want to account for whether it is global or static. So, we | |
16597 | may add it twice, using slightly different values. */ | |
16598 | if (is_static) | |
16599 | { | |
16600 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
16601 | ||
16602 | lookup = (void *) val; | |
16603 | } | |
16604 | else | |
16605 | lookup = *psymp; | |
16606 | ||
16607 | /* Only add a given psymbol once. */ | |
16608 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
16609 | if (!*slot) | |
16610 | { | |
16611 | *slot = lookup; | |
16612 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
16613 | } | |
9291a0cd TT |
16614 | } |
16615 | } | |
16616 | ||
16617 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
16618 | exception if there is an error. */ | |
b89be57b | 16619 | |
9291a0cd TT |
16620 | static void |
16621 | write_obstack (FILE *file, struct obstack *obstack) | |
16622 | { | |
16623 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
16624 | file) | |
16625 | != obstack_object_size (obstack)) | |
16626 | error (_("couldn't data write to file")); | |
16627 | } | |
16628 | ||
16629 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 16630 | |
9291a0cd TT |
16631 | static void |
16632 | unlink_if_set (void *p) | |
16633 | { | |
16634 | char **filename = p; | |
16635 | if (*filename) | |
16636 | unlink (*filename); | |
16637 | } | |
16638 | ||
1fd400ff TT |
16639 | /* A helper struct used when iterating over debug_types. */ |
16640 | struct signatured_type_index_data | |
16641 | { | |
16642 | struct objfile *objfile; | |
16643 | struct mapped_symtab *symtab; | |
16644 | struct obstack *types_list; | |
987d643c | 16645 | htab_t psyms_seen; |
1fd400ff TT |
16646 | int cu_index; |
16647 | }; | |
16648 | ||
16649 | /* A helper function that writes a single signatured_type to an | |
16650 | obstack. */ | |
b89be57b | 16651 | |
1fd400ff TT |
16652 | static int |
16653 | write_one_signatured_type (void **slot, void *d) | |
16654 | { | |
16655 | struct signatured_type_index_data *info = d; | |
16656 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
16657 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
16658 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
16659 | gdb_byte val[8]; |
16660 | ||
16661 | write_psymbols (info->symtab, | |
987d643c | 16662 | info->psyms_seen, |
3e43a32a MS |
16663 | info->objfile->global_psymbols.list |
16664 | + psymtab->globals_offset, | |
987d643c TT |
16665 | psymtab->n_global_syms, info->cu_index, |
16666 | 0); | |
1fd400ff | 16667 | write_psymbols (info->symtab, |
987d643c | 16668 | info->psyms_seen, |
3e43a32a MS |
16669 | info->objfile->static_psymbols.list |
16670 | + psymtab->statics_offset, | |
987d643c TT |
16671 | psymtab->n_static_syms, info->cu_index, |
16672 | 1); | |
1fd400ff | 16673 | |
b3c8eb43 | 16674 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset); |
1fd400ff TT |
16675 | obstack_grow (info->types_list, val, 8); |
16676 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
16677 | obstack_grow (info->types_list, val, 8); | |
16678 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
16679 | obstack_grow (info->types_list, val, 8); | |
16680 | ||
16681 | ++info->cu_index; | |
16682 | ||
16683 | return 1; | |
16684 | } | |
16685 | ||
9291a0cd | 16686 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 16687 | |
9291a0cd TT |
16688 | static void |
16689 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
16690 | { | |
16691 | struct cleanup *cleanup; | |
16692 | char *filename, *cleanup_filename; | |
1fd400ff TT |
16693 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
16694 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
16695 | int i; |
16696 | FILE *out_file; | |
16697 | struct mapped_symtab *symtab; | |
16698 | offset_type val, size_of_contents, total_len; | |
16699 | struct stat st; | |
16700 | char buf[8]; | |
987d643c | 16701 | htab_t psyms_seen; |
0a5429f6 DE |
16702 | htab_t cu_index_htab; |
16703 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 16704 | |
b4f2f049 | 16705 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 16706 | return; |
b4f2f049 | 16707 | |
9291a0cd TT |
16708 | if (dwarf2_per_objfile->using_index) |
16709 | error (_("Cannot use an index to create the index")); | |
16710 | ||
8b70b953 TT |
16711 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
16712 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
16713 | ||
9291a0cd | 16714 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 16715 | perror_with_name (objfile->name); |
9291a0cd TT |
16716 | |
16717 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
16718 | INDEX_SUFFIX, (char *) NULL); | |
16719 | cleanup = make_cleanup (xfree, filename); | |
16720 | ||
16721 | out_file = fopen (filename, "wb"); | |
16722 | if (!out_file) | |
16723 | error (_("Can't open `%s' for writing"), filename); | |
16724 | ||
16725 | cleanup_filename = filename; | |
16726 | make_cleanup (unlink_if_set, &cleanup_filename); | |
16727 | ||
16728 | symtab = create_mapped_symtab (); | |
16729 | make_cleanup (cleanup_mapped_symtab, symtab); | |
16730 | ||
16731 | obstack_init (&addr_obstack); | |
16732 | make_cleanup_obstack_free (&addr_obstack); | |
16733 | ||
16734 | obstack_init (&cu_list); | |
16735 | make_cleanup_obstack_free (&cu_list); | |
16736 | ||
1fd400ff TT |
16737 | obstack_init (&types_cu_list); |
16738 | make_cleanup_obstack_free (&types_cu_list); | |
16739 | ||
987d643c TT |
16740 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
16741 | NULL, xcalloc, xfree); | |
96408a79 | 16742 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 16743 | |
0a5429f6 DE |
16744 | /* While we're scanning CU's create a table that maps a psymtab pointer |
16745 | (which is what addrmap records) to its index (which is what is recorded | |
16746 | in the index file). This will later be needed to write the address | |
16747 | table. */ | |
16748 | cu_index_htab = htab_create_alloc (100, | |
16749 | hash_psymtab_cu_index, | |
16750 | eq_psymtab_cu_index, | |
16751 | NULL, xcalloc, xfree); | |
96408a79 | 16752 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
16753 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
16754 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
16755 | * dwarf2_per_objfile->n_comp_units); | |
16756 | make_cleanup (xfree, psymtab_cu_index_map); | |
16757 | ||
16758 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
16759 | work here. Also, the debug_types entries do not appear in |
16760 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
16761 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
16762 | { | |
3e43a32a MS |
16763 | struct dwarf2_per_cu_data *per_cu |
16764 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 16765 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 16766 | gdb_byte val[8]; |
0a5429f6 DE |
16767 | struct psymtab_cu_index_map *map; |
16768 | void **slot; | |
9291a0cd TT |
16769 | |
16770 | write_psymbols (symtab, | |
987d643c | 16771 | psyms_seen, |
9291a0cd | 16772 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
16773 | psymtab->n_global_syms, i, |
16774 | 0); | |
9291a0cd | 16775 | write_psymbols (symtab, |
987d643c | 16776 | psyms_seen, |
9291a0cd | 16777 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
16778 | psymtab->n_static_syms, i, |
16779 | 1); | |
9291a0cd | 16780 | |
0a5429f6 DE |
16781 | map = &psymtab_cu_index_map[i]; |
16782 | map->psymtab = psymtab; | |
16783 | map->cu_index = i; | |
16784 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
16785 | gdb_assert (slot != NULL); | |
16786 | gdb_assert (*slot == NULL); | |
16787 | *slot = map; | |
9291a0cd | 16788 | |
e254ef6a | 16789 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 16790 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 16791 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
16792 | obstack_grow (&cu_list, val, 8); |
16793 | } | |
16794 | ||
0a5429f6 DE |
16795 | /* Dump the address map. */ |
16796 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
16797 | ||
1fd400ff TT |
16798 | /* Write out the .debug_type entries, if any. */ |
16799 | if (dwarf2_per_objfile->signatured_types) | |
16800 | { | |
16801 | struct signatured_type_index_data sig_data; | |
16802 | ||
16803 | sig_data.objfile = objfile; | |
16804 | sig_data.symtab = symtab; | |
16805 | sig_data.types_list = &types_cu_list; | |
987d643c | 16806 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
16807 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
16808 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
16809 | write_one_signatured_type, &sig_data); | |
16810 | } | |
16811 | ||
9291a0cd TT |
16812 | obstack_init (&constant_pool); |
16813 | make_cleanup_obstack_free (&constant_pool); | |
16814 | obstack_init (&symtab_obstack); | |
16815 | make_cleanup_obstack_free (&symtab_obstack); | |
16816 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
16817 | ||
16818 | obstack_init (&contents); | |
16819 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 16820 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
16821 | total_len = size_of_contents; |
16822 | ||
16823 | /* The version number. */ | |
559a7a62 | 16824 | val = MAYBE_SWAP (5); |
9291a0cd TT |
16825 | obstack_grow (&contents, &val, sizeof (val)); |
16826 | ||
16827 | /* The offset of the CU list from the start of the file. */ | |
16828 | val = MAYBE_SWAP (total_len); | |
16829 | obstack_grow (&contents, &val, sizeof (val)); | |
16830 | total_len += obstack_object_size (&cu_list); | |
16831 | ||
1fd400ff TT |
16832 | /* The offset of the types CU list from the start of the file. */ |
16833 | val = MAYBE_SWAP (total_len); | |
16834 | obstack_grow (&contents, &val, sizeof (val)); | |
16835 | total_len += obstack_object_size (&types_cu_list); | |
16836 | ||
9291a0cd TT |
16837 | /* The offset of the address table from the start of the file. */ |
16838 | val = MAYBE_SWAP (total_len); | |
16839 | obstack_grow (&contents, &val, sizeof (val)); | |
16840 | total_len += obstack_object_size (&addr_obstack); | |
16841 | ||
16842 | /* The offset of the symbol table from the start of the file. */ | |
16843 | val = MAYBE_SWAP (total_len); | |
16844 | obstack_grow (&contents, &val, sizeof (val)); | |
16845 | total_len += obstack_object_size (&symtab_obstack); | |
16846 | ||
16847 | /* The offset of the constant pool from the start of the file. */ | |
16848 | val = MAYBE_SWAP (total_len); | |
16849 | obstack_grow (&contents, &val, sizeof (val)); | |
16850 | total_len += obstack_object_size (&constant_pool); | |
16851 | ||
16852 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
16853 | ||
16854 | write_obstack (out_file, &contents); | |
16855 | write_obstack (out_file, &cu_list); | |
1fd400ff | 16856 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
16857 | write_obstack (out_file, &addr_obstack); |
16858 | write_obstack (out_file, &symtab_obstack); | |
16859 | write_obstack (out_file, &constant_pool); | |
16860 | ||
16861 | fclose (out_file); | |
16862 | ||
16863 | /* We want to keep the file, so we set cleanup_filename to NULL | |
16864 | here. See unlink_if_set. */ | |
16865 | cleanup_filename = NULL; | |
16866 | ||
16867 | do_cleanups (cleanup); | |
16868 | } | |
16869 | ||
90476074 TT |
16870 | /* Implementation of the `save gdb-index' command. |
16871 | ||
16872 | Note that the file format used by this command is documented in the | |
16873 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 16874 | |
9291a0cd TT |
16875 | static void |
16876 | save_gdb_index_command (char *arg, int from_tty) | |
16877 | { | |
16878 | struct objfile *objfile; | |
16879 | ||
16880 | if (!arg || !*arg) | |
96d19272 | 16881 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
16882 | |
16883 | ALL_OBJFILES (objfile) | |
16884 | { | |
16885 | struct stat st; | |
16886 | ||
16887 | /* If the objfile does not correspond to an actual file, skip it. */ | |
16888 | if (stat (objfile->name, &st) < 0) | |
16889 | continue; | |
16890 | ||
16891 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
16892 | if (dwarf2_per_objfile) | |
16893 | { | |
16894 | volatile struct gdb_exception except; | |
16895 | ||
16896 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
16897 | { | |
16898 | write_psymtabs_to_index (objfile, arg); | |
16899 | } | |
16900 | if (except.reason < 0) | |
16901 | exception_fprintf (gdb_stderr, except, | |
16902 | _("Error while writing index for `%s': "), | |
16903 | objfile->name); | |
16904 | } | |
16905 | } | |
dce234bc PP |
16906 | } |
16907 | ||
9291a0cd TT |
16908 | \f |
16909 | ||
9eae7c52 TT |
16910 | int dwarf2_always_disassemble; |
16911 | ||
16912 | static void | |
16913 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
16914 | struct cmd_list_element *c, const char *value) | |
16915 | { | |
3e43a32a MS |
16916 | fprintf_filtered (file, |
16917 | _("Whether to always disassemble " | |
16918 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
16919 | value); |
16920 | } | |
16921 | ||
900e11f9 JK |
16922 | static void |
16923 | show_check_physname (struct ui_file *file, int from_tty, | |
16924 | struct cmd_list_element *c, const char *value) | |
16925 | { | |
16926 | fprintf_filtered (file, | |
16927 | _("Whether to check \"physname\" is %s.\n"), | |
16928 | value); | |
16929 | } | |
16930 | ||
6502dd73 DJ |
16931 | void _initialize_dwarf2_read (void); |
16932 | ||
16933 | void | |
16934 | _initialize_dwarf2_read (void) | |
16935 | { | |
96d19272 JK |
16936 | struct cmd_list_element *c; |
16937 | ||
dce234bc | 16938 | dwarf2_objfile_data_key |
c1bd65d0 | 16939 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 16940 | |
1bedd215 AC |
16941 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
16942 | Set DWARF 2 specific variables.\n\ | |
16943 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
16944 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
16945 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
16946 | ||
1bedd215 AC |
16947 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
16948 | Show DWARF 2 specific variables\n\ | |
16949 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
16950 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
16951 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
16952 | ||
16953 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
16954 | &dwarf2_max_cache_age, _("\ |
16955 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
16956 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
16957 | A higher limit means that cached compilation units will be stored\n\ | |
16958 | in memory longer, and more total memory will be used. Zero disables\n\ | |
16959 | caching, which can slow down startup."), | |
2c5b56ce | 16960 | NULL, |
920d2a44 | 16961 | show_dwarf2_max_cache_age, |
2c5b56ce | 16962 | &set_dwarf2_cmdlist, |
ae038cb0 | 16963 | &show_dwarf2_cmdlist); |
d97bc12b | 16964 | |
9eae7c52 TT |
16965 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
16966 | &dwarf2_always_disassemble, _("\ | |
16967 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
16968 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
16969 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
16970 | syntax. When disabled, expressions will be printed in a more\n\ | |
16971 | conversational style, when possible."), | |
16972 | NULL, | |
16973 | show_dwarf2_always_disassemble, | |
16974 | &set_dwarf2_cmdlist, | |
16975 | &show_dwarf2_cmdlist); | |
16976 | ||
d97bc12b DE |
16977 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
16978 | Set debugging of the dwarf2 DIE reader."), _("\ | |
16979 | Show debugging of the dwarf2 DIE reader."), _("\ | |
16980 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
16981 | The value is the maximum depth to print."), | |
16982 | NULL, | |
16983 | NULL, | |
16984 | &setdebuglist, &showdebuglist); | |
9291a0cd | 16985 | |
900e11f9 JK |
16986 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
16987 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
16988 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
16989 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
16990 | the demangler."), | |
16991 | NULL, show_check_physname, | |
16992 | &setdebuglist, &showdebuglist); | |
16993 | ||
96d19272 | 16994 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 16995 | _("\ |
fc1a9d6e | 16996 | Save a gdb-index file.\n\ |
11570e71 | 16997 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
16998 | &save_cmdlist); |
16999 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 17000 | } |