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 | ||
dce234bc PP |
122 | static int pagesize; |
123 | ||
df8a16a1 DJ |
124 | /* When set, the file that we're processing is known to have debugging |
125 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
126 | but later versions do. */ | |
127 | ||
128 | static int processing_has_namespace_info; | |
129 | ||
6502dd73 DJ |
130 | static const struct objfile_data *dwarf2_objfile_data_key; |
131 | ||
dce234bc PP |
132 | struct dwarf2_section_info |
133 | { | |
134 | asection *asection; | |
135 | gdb_byte *buffer; | |
136 | bfd_size_type size; | |
137 | int was_mmapped; | |
be391dca TT |
138 | /* True if we have tried to read this section. */ |
139 | int readin; | |
dce234bc PP |
140 | }; |
141 | ||
9291a0cd TT |
142 | /* All offsets in the index are of this type. It must be |
143 | architecture-independent. */ | |
144 | typedef uint32_t offset_type; | |
145 | ||
146 | DEF_VEC_I (offset_type); | |
147 | ||
148 | /* A description of the mapped index. The file format is described in | |
149 | a comment by the code that writes the index. */ | |
150 | struct mapped_index | |
151 | { | |
559a7a62 JK |
152 | /* Index data format version. */ |
153 | int version; | |
154 | ||
9291a0cd TT |
155 | /* The total length of the buffer. */ |
156 | off_t total_size; | |
b11b1f88 | 157 | |
9291a0cd TT |
158 | /* A pointer to the address table data. */ |
159 | const gdb_byte *address_table; | |
b11b1f88 | 160 | |
9291a0cd TT |
161 | /* Size of the address table data in bytes. */ |
162 | offset_type address_table_size; | |
b11b1f88 | 163 | |
3876f04e DE |
164 | /* The symbol table, implemented as a hash table. */ |
165 | const offset_type *symbol_table; | |
b11b1f88 | 166 | |
9291a0cd | 167 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 168 | offset_type symbol_table_slots; |
b11b1f88 | 169 | |
9291a0cd TT |
170 | /* A pointer to the constant pool. */ |
171 | const char *constant_pool; | |
172 | }; | |
173 | ||
6502dd73 DJ |
174 | struct dwarf2_per_objfile |
175 | { | |
dce234bc PP |
176 | struct dwarf2_section_info info; |
177 | struct dwarf2_section_info abbrev; | |
178 | struct dwarf2_section_info line; | |
dce234bc PP |
179 | struct dwarf2_section_info loc; |
180 | struct dwarf2_section_info macinfo; | |
181 | struct dwarf2_section_info str; | |
182 | struct dwarf2_section_info ranges; | |
348e048f | 183 | struct dwarf2_section_info types; |
dce234bc PP |
184 | struct dwarf2_section_info frame; |
185 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 186 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 187 | |
be391dca TT |
188 | /* Back link. */ |
189 | struct objfile *objfile; | |
190 | ||
10b3939b DJ |
191 | /* A list of all the compilation units. This is used to locate |
192 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
193 | struct dwarf2_per_cu_data **all_comp_units; |
194 | ||
195 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
196 | int n_comp_units; | |
197 | ||
1fd400ff TT |
198 | /* The number of .debug_types-related CUs. */ |
199 | int n_type_comp_units; | |
200 | ||
201 | /* The .debug_types-related CUs. */ | |
202 | struct dwarf2_per_cu_data **type_comp_units; | |
203 | ||
ae038cb0 DJ |
204 | /* A chain of compilation units that are currently read in, so that |
205 | they can be freed later. */ | |
206 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 207 | |
348e048f DE |
208 | /* A table mapping .debug_types signatures to its signatured_type entry. |
209 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
210 | htab_t signatured_types; | |
211 | ||
72dca2f5 FR |
212 | /* A flag indicating wether this objfile has a section loaded at a |
213 | VMA of 0. */ | |
214 | int has_section_at_zero; | |
9291a0cd | 215 | |
ae2de4f8 DE |
216 | /* True if we are using the mapped index, |
217 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
218 | unsigned char using_index; |
219 | ||
ae2de4f8 | 220 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 221 | struct mapped_index *index_table; |
98bfdba5 | 222 | |
7b9f3c50 DE |
223 | /* When using index_table, this keeps track of all quick_file_names entries. |
224 | TUs can share line table entries with CUs or other TUs, and there can be | |
225 | a lot more TUs than unique line tables, so we maintain a separate table | |
226 | of all line table entries to support the sharing. */ | |
227 | htab_t quick_file_names_table; | |
228 | ||
98bfdba5 PA |
229 | /* Set during partial symbol reading, to prevent queueing of full |
230 | symbols. */ | |
231 | int reading_partial_symbols; | |
673bfd45 DE |
232 | |
233 | /* Table mapping type .debug_info DIE offsets to types. | |
234 | This is NULL if not allocated yet. | |
235 | It (currently) makes sense to allocate debug_types_type_hash lazily. | |
236 | To keep things simple we allocate both lazily. */ | |
237 | htab_t debug_info_type_hash; | |
238 | ||
239 | /* Table mapping type .debug_types DIE offsets to types. | |
240 | This is NULL if not allocated yet. */ | |
241 | htab_t debug_types_type_hash; | |
6502dd73 DJ |
242 | }; |
243 | ||
244 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 245 | |
251d32d9 | 246 | /* Default names of the debugging sections. */ |
c906108c | 247 | |
233a11ab CS |
248 | /* Note that if the debugging section has been compressed, it might |
249 | have a name like .zdebug_info. */ | |
250 | ||
251d32d9 TG |
251 | static const struct dwarf2_debug_sections dwarf2_elf_names = { |
252 | { ".debug_info", ".zdebug_info" }, | |
253 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
254 | { ".debug_line", ".zdebug_line" }, | |
255 | { ".debug_loc", ".zdebug_loc" }, | |
256 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
257 | { ".debug_str", ".zdebug_str" }, | |
258 | { ".debug_ranges", ".zdebug_ranges" }, | |
259 | { ".debug_types", ".zdebug_types" }, | |
260 | { ".debug_frame", ".zdebug_frame" }, | |
261 | { ".eh_frame", NULL }, | |
262 | { ".gdb_index", ".zgdb_index" } | |
263 | }; | |
c906108c SS |
264 | |
265 | /* local data types */ | |
266 | ||
0963b4bd | 267 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
268 | #ifndef ABBREV_HASH_SIZE |
269 | #define ABBREV_HASH_SIZE 121 | |
270 | #endif | |
271 | ||
107d2387 AC |
272 | /* The data in a compilation unit header, after target2host |
273 | translation, looks like this. */ | |
c906108c | 274 | struct comp_unit_head |
a738430d | 275 | { |
c764a876 | 276 | unsigned int length; |
a738430d | 277 | short version; |
a738430d MK |
278 | unsigned char addr_size; |
279 | unsigned char signed_addr_p; | |
9cbfa09e | 280 | unsigned int abbrev_offset; |
57349743 | 281 | |
a738430d MK |
282 | /* Size of file offsets; either 4 or 8. */ |
283 | unsigned int offset_size; | |
57349743 | 284 | |
a738430d MK |
285 | /* Size of the length field; either 4 or 12. */ |
286 | unsigned int initial_length_size; | |
57349743 | 287 | |
a738430d MK |
288 | /* Offset to the first byte of this compilation unit header in the |
289 | .debug_info section, for resolving relative reference dies. */ | |
290 | unsigned int offset; | |
57349743 | 291 | |
d00adf39 DE |
292 | /* Offset to first die in this cu from the start of the cu. |
293 | This will be the first byte following the compilation unit header. */ | |
294 | unsigned int first_die_offset; | |
a738430d | 295 | }; |
c906108c | 296 | |
3da10d80 KS |
297 | /* Type used for delaying computation of method physnames. |
298 | See comments for compute_delayed_physnames. */ | |
299 | struct delayed_method_info | |
300 | { | |
301 | /* The type to which the method is attached, i.e., its parent class. */ | |
302 | struct type *type; | |
303 | ||
304 | /* The index of the method in the type's function fieldlists. */ | |
305 | int fnfield_index; | |
306 | ||
307 | /* The index of the method in the fieldlist. */ | |
308 | int index; | |
309 | ||
310 | /* The name of the DIE. */ | |
311 | const char *name; | |
312 | ||
313 | /* The DIE associated with this method. */ | |
314 | struct die_info *die; | |
315 | }; | |
316 | ||
317 | typedef struct delayed_method_info delayed_method_info; | |
318 | DEF_VEC_O (delayed_method_info); | |
319 | ||
e7c27a73 DJ |
320 | /* Internal state when decoding a particular compilation unit. */ |
321 | struct dwarf2_cu | |
322 | { | |
323 | /* The objfile containing this compilation unit. */ | |
324 | struct objfile *objfile; | |
325 | ||
d00adf39 | 326 | /* The header of the compilation unit. */ |
e7c27a73 | 327 | struct comp_unit_head header; |
e142c38c | 328 | |
d00adf39 DE |
329 | /* Base address of this compilation unit. */ |
330 | CORE_ADDR base_address; | |
331 | ||
332 | /* Non-zero if base_address has been set. */ | |
333 | int base_known; | |
334 | ||
e142c38c DJ |
335 | struct function_range *first_fn, *last_fn, *cached_fn; |
336 | ||
337 | /* The language we are debugging. */ | |
338 | enum language language; | |
339 | const struct language_defn *language_defn; | |
340 | ||
b0f35d58 DL |
341 | const char *producer; |
342 | ||
e142c38c DJ |
343 | /* The generic symbol table building routines have separate lists for |
344 | file scope symbols and all all other scopes (local scopes). So | |
345 | we need to select the right one to pass to add_symbol_to_list(). | |
346 | We do it by keeping a pointer to the correct list in list_in_scope. | |
347 | ||
348 | FIXME: The original dwarf code just treated the file scope as the | |
349 | first local scope, and all other local scopes as nested local | |
350 | scopes, and worked fine. Check to see if we really need to | |
351 | distinguish these in buildsym.c. */ | |
352 | struct pending **list_in_scope; | |
353 | ||
f3dd6933 DJ |
354 | /* DWARF abbreviation table associated with this compilation unit. */ |
355 | struct abbrev_info **dwarf2_abbrevs; | |
356 | ||
357 | /* Storage for the abbrev table. */ | |
358 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
359 | |
360 | /* Hash table holding all the loaded partial DIEs. */ | |
361 | htab_t partial_dies; | |
362 | ||
363 | /* Storage for things with the same lifetime as this read-in compilation | |
364 | unit, including partial DIEs. */ | |
365 | struct obstack comp_unit_obstack; | |
366 | ||
ae038cb0 DJ |
367 | /* When multiple dwarf2_cu structures are living in memory, this field |
368 | chains them all together, so that they can be released efficiently. | |
369 | We will probably also want a generation counter so that most-recently-used | |
370 | compilation units are cached... */ | |
371 | struct dwarf2_per_cu_data *read_in_chain; | |
372 | ||
373 | /* Backchain to our per_cu entry if the tree has been built. */ | |
374 | struct dwarf2_per_cu_data *per_cu; | |
375 | ||
376 | /* How many compilation units ago was this CU last referenced? */ | |
377 | int last_used; | |
378 | ||
10b3939b | 379 | /* A hash table of die offsets for following references. */ |
51545339 | 380 | htab_t die_hash; |
10b3939b DJ |
381 | |
382 | /* Full DIEs if read in. */ | |
383 | struct die_info *dies; | |
384 | ||
385 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
386 | units referenced by this one. Only set during full symbol processing; | |
387 | partial symbol tables do not have dependencies. */ | |
388 | htab_t dependencies; | |
389 | ||
cb1df416 DJ |
390 | /* Header data from the line table, during full symbol processing. */ |
391 | struct line_header *line_header; | |
392 | ||
3da10d80 KS |
393 | /* A list of methods which need to have physnames computed |
394 | after all type information has been read. */ | |
395 | VEC (delayed_method_info) *method_list; | |
396 | ||
ae038cb0 DJ |
397 | /* Mark used when releasing cached dies. */ |
398 | unsigned int mark : 1; | |
399 | ||
400 | /* This flag will be set if this compilation unit might include | |
401 | inter-compilation-unit references. */ | |
402 | unsigned int has_form_ref_addr : 1; | |
403 | ||
72bf9492 DJ |
404 | /* This flag will be set if this compilation unit includes any |
405 | DW_TAG_namespace DIEs. If we know that there are explicit | |
406 | DIEs for namespaces, we don't need to try to infer them | |
407 | from mangled names. */ | |
408 | unsigned int has_namespace_info : 1; | |
8be455d7 JK |
409 | |
410 | /* This CU references .debug_loc. See the symtab->locations_valid field. | |
411 | This test is imperfect as there may exist optimized debug code not using | |
412 | any location list and still facing inlining issues if handled as | |
413 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
414 | ||
415 | unsigned int has_loclist : 1; | |
e7c27a73 DJ |
416 | }; |
417 | ||
10b3939b DJ |
418 | /* Persistent data held for a compilation unit, even when not |
419 | processing it. We put a pointer to this structure in the | |
420 | read_symtab_private field of the psymtab. If we encounter | |
421 | inter-compilation-unit references, we also maintain a sorted | |
422 | list of all compilation units. */ | |
423 | ||
ae038cb0 DJ |
424 | struct dwarf2_per_cu_data |
425 | { | |
348e048f | 426 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 427 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
428 | - if it doesn't, GDB will fall over anyway. |
429 | NOTE: Unlike comp_unit_head.length, this length includes | |
430 | initial_length_size. */ | |
c764a876 | 431 | unsigned int offset; |
348e048f | 432 | unsigned int length : 29; |
ae038cb0 DJ |
433 | |
434 | /* Flag indicating this compilation unit will be read in before | |
435 | any of the current compilation units are processed. */ | |
c764a876 | 436 | unsigned int queued : 1; |
ae038cb0 | 437 | |
5afb4e99 DJ |
438 | /* This flag will be set if we need to load absolutely all DIEs |
439 | for this compilation unit, instead of just the ones we think | |
440 | are interesting. It gets set if we look for a DIE in the | |
441 | hash table and don't find it. */ | |
442 | unsigned int load_all_dies : 1; | |
443 | ||
348e048f DE |
444 | /* Non-zero if this CU is from .debug_types. |
445 | Otherwise it's from .debug_info. */ | |
446 | unsigned int from_debug_types : 1; | |
447 | ||
17ea53c3 JK |
448 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
449 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 450 | struct dwarf2_cu *cu; |
1c379e20 | 451 | |
9291a0cd TT |
452 | /* The corresponding objfile. */ |
453 | struct objfile *objfile; | |
454 | ||
455 | /* When using partial symbol tables, the 'psymtab' field is active. | |
456 | Otherwise the 'quick' field is active. */ | |
457 | union | |
458 | { | |
459 | /* The partial symbol table associated with this compilation unit, | |
460 | or NULL for partial units (which do not have an associated | |
461 | symtab). */ | |
462 | struct partial_symtab *psymtab; | |
463 | ||
464 | /* Data needed by the "quick" functions. */ | |
465 | struct dwarf2_per_cu_quick_data *quick; | |
466 | } v; | |
ae038cb0 DJ |
467 | }; |
468 | ||
348e048f DE |
469 | /* Entry in the signatured_types hash table. */ |
470 | ||
471 | struct signatured_type | |
472 | { | |
473 | ULONGEST signature; | |
474 | ||
348e048f DE |
475 | /* Offset in .debug_types of the type defined by this TU. */ |
476 | unsigned int type_offset; | |
477 | ||
478 | /* The CU(/TU) of this type. */ | |
479 | struct dwarf2_per_cu_data per_cu; | |
480 | }; | |
481 | ||
0963b4bd MS |
482 | /* Struct used to pass misc. parameters to read_die_and_children, et |
483 | al. which are used for both .debug_info and .debug_types dies. | |
484 | All parameters here are unchanging for the life of the call. This | |
485 | struct exists to abstract away the constant parameters of die | |
486 | reading. */ | |
93311388 DE |
487 | |
488 | struct die_reader_specs | |
489 | { | |
490 | /* The bfd of this objfile. */ | |
491 | bfd* abfd; | |
492 | ||
493 | /* The CU of the DIE we are parsing. */ | |
494 | struct dwarf2_cu *cu; | |
495 | ||
496 | /* Pointer to start of section buffer. | |
497 | This is either the start of .debug_info or .debug_types. */ | |
498 | const gdb_byte *buffer; | |
499 | }; | |
500 | ||
debd256d JB |
501 | /* The line number information for a compilation unit (found in the |
502 | .debug_line section) begins with a "statement program header", | |
503 | which contains the following information. */ | |
504 | struct line_header | |
505 | { | |
506 | unsigned int total_length; | |
507 | unsigned short version; | |
508 | unsigned int header_length; | |
509 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 510 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
511 | unsigned char default_is_stmt; |
512 | int line_base; | |
513 | unsigned char line_range; | |
514 | unsigned char opcode_base; | |
515 | ||
516 | /* standard_opcode_lengths[i] is the number of operands for the | |
517 | standard opcode whose value is i. This means that | |
518 | standard_opcode_lengths[0] is unused, and the last meaningful | |
519 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
520 | unsigned char *standard_opcode_lengths; | |
521 | ||
522 | /* The include_directories table. NOTE! These strings are not | |
523 | allocated with xmalloc; instead, they are pointers into | |
524 | debug_line_buffer. If you try to free them, `free' will get | |
525 | indigestion. */ | |
526 | unsigned int num_include_dirs, include_dirs_size; | |
527 | char **include_dirs; | |
528 | ||
529 | /* The file_names table. NOTE! These strings are not allocated | |
530 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
531 | Don't try to free them directly. */ | |
532 | unsigned int num_file_names, file_names_size; | |
533 | struct file_entry | |
c906108c | 534 | { |
debd256d JB |
535 | char *name; |
536 | unsigned int dir_index; | |
537 | unsigned int mod_time; | |
538 | unsigned int length; | |
aaa75496 | 539 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 540 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
541 | } *file_names; |
542 | ||
543 | /* The start and end of the statement program following this | |
6502dd73 | 544 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 545 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 546 | }; |
c906108c SS |
547 | |
548 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 549 | need this much information. */ |
c906108c SS |
550 | struct partial_die_info |
551 | { | |
72bf9492 | 552 | /* Offset of this DIE. */ |
c906108c | 553 | unsigned int offset; |
72bf9492 DJ |
554 | |
555 | /* DWARF-2 tag for this DIE. */ | |
556 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
557 | ||
72bf9492 DJ |
558 | /* Assorted flags describing the data found in this DIE. */ |
559 | unsigned int has_children : 1; | |
560 | unsigned int is_external : 1; | |
561 | unsigned int is_declaration : 1; | |
562 | unsigned int has_type : 1; | |
563 | unsigned int has_specification : 1; | |
564 | unsigned int has_pc_info : 1; | |
565 | ||
566 | /* Flag set if the SCOPE field of this structure has been | |
567 | computed. */ | |
568 | unsigned int scope_set : 1; | |
569 | ||
fa4028e9 JB |
570 | /* Flag set if the DIE has a byte_size attribute. */ |
571 | unsigned int has_byte_size : 1; | |
572 | ||
98bfdba5 PA |
573 | /* Flag set if any of the DIE's children are template arguments. */ |
574 | unsigned int has_template_arguments : 1; | |
575 | ||
abc72ce4 DE |
576 | /* Flag set if fixup_partial_die has been called on this die. */ |
577 | unsigned int fixup_called : 1; | |
578 | ||
72bf9492 | 579 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 580 | sometimes a default name for unnamed DIEs. */ |
c906108c | 581 | char *name; |
72bf9492 | 582 | |
abc72ce4 DE |
583 | /* The linkage name, if present. */ |
584 | const char *linkage_name; | |
585 | ||
72bf9492 DJ |
586 | /* The scope to prepend to our children. This is generally |
587 | allocated on the comp_unit_obstack, so will disappear | |
588 | when this compilation unit leaves the cache. */ | |
589 | char *scope; | |
590 | ||
591 | /* The location description associated with this DIE, if any. */ | |
592 | struct dwarf_block *locdesc; | |
593 | ||
594 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
595 | CORE_ADDR lowpc; |
596 | CORE_ADDR highpc; | |
72bf9492 | 597 | |
93311388 | 598 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 599 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
600 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
601 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 602 | gdb_byte *sibling; |
72bf9492 DJ |
603 | |
604 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
605 | DW_AT_specification (or DW_AT_abstract_origin or | |
606 | DW_AT_extension). */ | |
607 | unsigned int spec_offset; | |
608 | ||
609 | /* Pointers to this DIE's parent, first child, and next sibling, | |
610 | if any. */ | |
611 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
612 | }; |
613 | ||
0963b4bd | 614 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
615 | struct abbrev_info |
616 | { | |
617 | unsigned int number; /* number identifying abbrev */ | |
618 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
619 | unsigned short has_children; /* boolean */ |
620 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
621 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
622 | struct abbrev_info *next; /* next in chain */ | |
623 | }; | |
624 | ||
625 | struct attr_abbrev | |
626 | { | |
9d25dd43 DE |
627 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
628 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
629 | }; |
630 | ||
0963b4bd | 631 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
632 | struct attribute |
633 | { | |
9d25dd43 | 634 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
635 | ENUM_BITFIELD(dwarf_form) form : 15; |
636 | ||
637 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
638 | field should be in u.str (existing only for DW_STRING) but it is kept | |
639 | here for better struct attribute alignment. */ | |
640 | unsigned int string_is_canonical : 1; | |
641 | ||
b60c80d6 DJ |
642 | union |
643 | { | |
644 | char *str; | |
645 | struct dwarf_block *blk; | |
43bbcdc2 PH |
646 | ULONGEST unsnd; |
647 | LONGEST snd; | |
b60c80d6 | 648 | CORE_ADDR addr; |
348e048f | 649 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
650 | } |
651 | u; | |
652 | }; | |
653 | ||
0963b4bd | 654 | /* This data structure holds a complete die structure. */ |
c906108c SS |
655 | struct die_info |
656 | { | |
76815b17 DE |
657 | /* DWARF-2 tag for this DIE. */ |
658 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
659 | ||
660 | /* Number of attributes */ | |
98bfdba5 PA |
661 | unsigned char num_attrs; |
662 | ||
663 | /* True if we're presently building the full type name for the | |
664 | type derived from this DIE. */ | |
665 | unsigned char building_fullname : 1; | |
76815b17 DE |
666 | |
667 | /* Abbrev number */ | |
668 | unsigned int abbrev; | |
669 | ||
93311388 | 670 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 671 | unsigned int offset; |
78ba4af6 JB |
672 | |
673 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
674 | points to this die's parent; CHILD points to the first child of | |
675 | this node; and all the children of a given node are chained | |
4950bc1c | 676 | together via their SIBLING fields. */ |
639d11d3 DC |
677 | struct die_info *child; /* Its first child, if any. */ |
678 | struct die_info *sibling; /* Its next sibling, if any. */ | |
679 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 680 | |
b60c80d6 DJ |
681 | /* An array of attributes, with NUM_ATTRS elements. There may be |
682 | zero, but it's not common and zero-sized arrays are not | |
683 | sufficiently portable C. */ | |
684 | struct attribute attrs[1]; | |
c906108c SS |
685 | }; |
686 | ||
5fb290d7 DJ |
687 | struct function_range |
688 | { | |
689 | const char *name; | |
690 | CORE_ADDR lowpc, highpc; | |
691 | int seen_line; | |
692 | struct function_range *next; | |
693 | }; | |
694 | ||
0963b4bd | 695 | /* Get at parts of an attribute structure. */ |
c906108c SS |
696 | |
697 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 698 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
699 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
700 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
701 | #define DW_SND(attr) ((attr)->u.snd) | |
702 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 703 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 704 | |
0963b4bd | 705 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
706 | struct dwarf_block |
707 | { | |
708 | unsigned int size; | |
fe1b8b76 | 709 | gdb_byte *data; |
c906108c SS |
710 | }; |
711 | ||
c906108c SS |
712 | #ifndef ATTR_ALLOC_CHUNK |
713 | #define ATTR_ALLOC_CHUNK 4 | |
714 | #endif | |
715 | ||
c906108c SS |
716 | /* Allocate fields for structs, unions and enums in this size. */ |
717 | #ifndef DW_FIELD_ALLOC_CHUNK | |
718 | #define DW_FIELD_ALLOC_CHUNK 4 | |
719 | #endif | |
720 | ||
c906108c SS |
721 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
722 | but this would require a corresponding change in unpack_field_as_long | |
723 | and friends. */ | |
724 | static int bits_per_byte = 8; | |
725 | ||
726 | /* The routines that read and process dies for a C struct or C++ class | |
727 | pass lists of data member fields and lists of member function fields | |
728 | in an instance of a field_info structure, as defined below. */ | |
729 | struct field_info | |
c5aa993b | 730 | { |
0963b4bd | 731 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
732 | struct nextfield |
733 | { | |
734 | struct nextfield *next; | |
735 | int accessibility; | |
736 | int virtuality; | |
737 | struct field field; | |
738 | } | |
7d0ccb61 | 739 | *fields, *baseclasses; |
c906108c | 740 | |
7d0ccb61 | 741 | /* Number of fields (including baseclasses). */ |
c5aa993b | 742 | int nfields; |
c906108c | 743 | |
c5aa993b JM |
744 | /* Number of baseclasses. */ |
745 | int nbaseclasses; | |
c906108c | 746 | |
c5aa993b JM |
747 | /* Set if the accesibility of one of the fields is not public. */ |
748 | int non_public_fields; | |
c906108c | 749 | |
c5aa993b JM |
750 | /* Member function fields array, entries are allocated in the order they |
751 | are encountered in the object file. */ | |
752 | struct nextfnfield | |
753 | { | |
754 | struct nextfnfield *next; | |
755 | struct fn_field fnfield; | |
756 | } | |
757 | *fnfields; | |
c906108c | 758 | |
c5aa993b JM |
759 | /* Member function fieldlist array, contains name of possibly overloaded |
760 | member function, number of overloaded member functions and a pointer | |
761 | to the head of the member function field chain. */ | |
762 | struct fnfieldlist | |
763 | { | |
764 | char *name; | |
765 | int length; | |
766 | struct nextfnfield *head; | |
767 | } | |
768 | *fnfieldlists; | |
c906108c | 769 | |
c5aa993b JM |
770 | /* Number of entries in the fnfieldlists array. */ |
771 | int nfnfields; | |
98751a41 JK |
772 | |
773 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
774 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
775 | struct typedef_field_list | |
776 | { | |
777 | struct typedef_field field; | |
778 | struct typedef_field_list *next; | |
779 | } | |
780 | *typedef_field_list; | |
781 | unsigned typedef_field_list_count; | |
c5aa993b | 782 | }; |
c906108c | 783 | |
10b3939b DJ |
784 | /* One item on the queue of compilation units to read in full symbols |
785 | for. */ | |
786 | struct dwarf2_queue_item | |
787 | { | |
788 | struct dwarf2_per_cu_data *per_cu; | |
789 | struct dwarf2_queue_item *next; | |
790 | }; | |
791 | ||
792 | /* The current queue. */ | |
793 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
794 | ||
ae038cb0 DJ |
795 | /* Loaded secondary compilation units are kept in memory until they |
796 | have not been referenced for the processing of this many | |
797 | compilation units. Set this to zero to disable caching. Cache | |
798 | sizes of up to at least twenty will improve startup time for | |
799 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
800 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
801 | static void |
802 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
803 | struct cmd_list_element *c, const char *value) | |
804 | { | |
3e43a32a MS |
805 | fprintf_filtered (file, _("The upper bound on the age of cached " |
806 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
807 | value); |
808 | } | |
809 | ||
ae038cb0 | 810 | |
0963b4bd | 811 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 812 | |
4d3c2250 KB |
813 | static void |
814 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 815 | { |
4d3c2250 | 816 | complaint (&symfile_complaints, |
e2e0b3e5 | 817 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
818 | } |
819 | ||
25e43795 DJ |
820 | static void |
821 | dwarf2_debug_line_missing_file_complaint (void) | |
822 | { | |
823 | complaint (&symfile_complaints, | |
824 | _(".debug_line section has line data without a file")); | |
825 | } | |
826 | ||
59205f5a JB |
827 | static void |
828 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
829 | { | |
830 | complaint (&symfile_complaints, | |
3e43a32a MS |
831 | _(".debug_line section has line " |
832 | "program sequence without an end")); | |
59205f5a JB |
833 | } |
834 | ||
4d3c2250 KB |
835 | static void |
836 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 837 | { |
e2e0b3e5 | 838 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
839 | } |
840 | ||
4d3c2250 KB |
841 | static void |
842 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
843 | int arg3) | |
2e276125 | 844 | { |
4d3c2250 | 845 | complaint (&symfile_complaints, |
3e43a32a MS |
846 | _("const value length mismatch for '%s', got %d, expected %d"), |
847 | arg1, arg2, arg3); | |
4d3c2250 KB |
848 | } |
849 | ||
850 | static void | |
851 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 852 | { |
4d3c2250 | 853 | complaint (&symfile_complaints, |
e2e0b3e5 | 854 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
855 | } |
856 | ||
857 | static void | |
858 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 859 | { |
4d3c2250 | 860 | complaint (&symfile_complaints, |
3e43a32a MS |
861 | _("macro debug info contains a " |
862 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
863 | arg1); |
864 | } | |
865 | ||
866 | static void | |
867 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 868 | { |
4d3c2250 | 869 | complaint (&symfile_complaints, |
3e43a32a MS |
870 | _("invalid attribute class or form for '%s' in '%s'"), |
871 | arg1, arg2); | |
4d3c2250 | 872 | } |
c906108c | 873 | |
c906108c SS |
874 | /* local function prototypes */ |
875 | ||
4efb68b1 | 876 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 877 | |
aaa75496 JB |
878 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
879 | struct objfile *); | |
880 | ||
c67a9c90 | 881 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 882 | |
72bf9492 DJ |
883 | static void scan_partial_symbols (struct partial_die_info *, |
884 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 885 | int, struct dwarf2_cu *); |
c906108c | 886 | |
72bf9492 DJ |
887 | static void add_partial_symbol (struct partial_die_info *, |
888 | struct dwarf2_cu *); | |
63d06c5c | 889 | |
72bf9492 DJ |
890 | static void add_partial_namespace (struct partial_die_info *pdi, |
891 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 892 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 893 | |
5d7cb8df JK |
894 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
895 | CORE_ADDR *highpc, int need_pc, | |
896 | struct dwarf2_cu *cu); | |
897 | ||
72bf9492 DJ |
898 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
899 | struct dwarf2_cu *cu); | |
91c24f0a | 900 | |
bc30ff58 JB |
901 | static void add_partial_subprogram (struct partial_die_info *pdi, |
902 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 903 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 904 | |
fe1b8b76 | 905 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
906 | gdb_byte *buffer, gdb_byte *info_ptr, |
907 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 908 | |
a14ed312 | 909 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 910 | |
a14ed312 | 911 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 912 | |
e7c27a73 | 913 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 914 | |
f3dd6933 | 915 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 916 | |
fe1b8b76 | 917 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 918 | struct dwarf2_cu *); |
72bf9492 | 919 | |
57349743 | 920 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 921 | struct dwarf2_cu *); |
c906108c | 922 | |
93311388 DE |
923 | static struct partial_die_info *load_partial_dies (bfd *, |
924 | gdb_byte *, gdb_byte *, | |
925 | int, struct dwarf2_cu *); | |
72bf9492 | 926 | |
fe1b8b76 | 927 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
928 | struct abbrev_info *abbrev, |
929 | unsigned int, bfd *, | |
930 | gdb_byte *, gdb_byte *, | |
931 | struct dwarf2_cu *); | |
c906108c | 932 | |
c764a876 | 933 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 934 | struct dwarf2_cu *); |
72bf9492 DJ |
935 | |
936 | static void fixup_partial_die (struct partial_die_info *, | |
937 | struct dwarf2_cu *); | |
938 | ||
fe1b8b76 JB |
939 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
940 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 941 | |
fe1b8b76 JB |
942 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
943 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 944 | |
fe1b8b76 | 945 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 946 | |
fe1b8b76 | 947 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 948 | |
fe1b8b76 | 949 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 950 | |
fe1b8b76 | 951 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 952 | |
93311388 | 953 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 954 | |
fe1b8b76 | 955 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 956 | unsigned int *); |
c906108c | 957 | |
c764a876 DE |
958 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
959 | ||
960 | static LONGEST read_checked_initial_length_and_offset | |
961 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
962 | unsigned int *, unsigned int *); | |
613e1657 | 963 | |
fe1b8b76 | 964 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
965 | unsigned int *); |
966 | ||
967 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 968 | |
fe1b8b76 | 969 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 970 | |
9b1c24c8 | 971 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 972 | |
fe1b8b76 JB |
973 | static char *read_indirect_string (bfd *, gdb_byte *, |
974 | const struct comp_unit_head *, | |
975 | unsigned int *); | |
4bdf3d34 | 976 | |
fe1b8b76 | 977 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 978 | |
fe1b8b76 | 979 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 980 | |
fe1b8b76 | 981 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 982 | |
e142c38c | 983 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 984 | |
e142c38c DJ |
985 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
986 | struct dwarf2_cu *); | |
c906108c | 987 | |
348e048f DE |
988 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
989 | unsigned int, | |
990 | struct dwarf2_cu *); | |
991 | ||
05cf31d1 JB |
992 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
993 | struct dwarf2_cu *cu); | |
994 | ||
e142c38c | 995 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 996 | |
e142c38c | 997 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 998 | struct dwarf2_cu **); |
63d06c5c | 999 | |
debd256d JB |
1000 | static void free_line_header (struct line_header *lh); |
1001 | ||
aaa75496 JB |
1002 | static void add_file_name (struct line_header *, char *, unsigned int, |
1003 | unsigned int, unsigned int); | |
1004 | ||
debd256d JB |
1005 | static struct line_header *(dwarf_decode_line_header |
1006 | (unsigned int offset, | |
e7c27a73 | 1007 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d | 1008 | |
72b9f47f | 1009 | static void dwarf_decode_lines (struct line_header *, const char *, bfd *, |
aaa75496 | 1010 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 1011 | |
72b9f47f | 1012 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 1013 | |
a14ed312 | 1014 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1015 | struct dwarf2_cu *); |
c906108c | 1016 | |
34eaf542 TT |
1017 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1018 | struct dwarf2_cu *, struct symbol *); | |
1019 | ||
a14ed312 | 1020 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1021 | struct dwarf2_cu *); |
c906108c | 1022 | |
98bfdba5 PA |
1023 | static void dwarf2_const_value_attr (struct attribute *attr, |
1024 | struct type *type, | |
1025 | const char *name, | |
1026 | struct obstack *obstack, | |
1027 | struct dwarf2_cu *cu, long *value, | |
1028 | gdb_byte **bytes, | |
1029 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1030 | |
e7c27a73 | 1031 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1032 | |
b4ba55a1 JB |
1033 | static int need_gnat_info (struct dwarf2_cu *); |
1034 | ||
3e43a32a MS |
1035 | static struct type *die_descriptive_type (struct die_info *, |
1036 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1037 | |
1038 | static void set_descriptive_type (struct type *, struct die_info *, | |
1039 | struct dwarf2_cu *); | |
1040 | ||
e7c27a73 DJ |
1041 | static struct type *die_containing_type (struct die_info *, |
1042 | struct dwarf2_cu *); | |
c906108c | 1043 | |
673bfd45 DE |
1044 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1045 | struct dwarf2_cu *); | |
c906108c | 1046 | |
f792889a | 1047 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1048 | |
673bfd45 DE |
1049 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1050 | ||
086ed43d | 1051 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1052 | |
6e70227d | 1053 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1054 | const char *suffix, int physname, |
1055 | struct dwarf2_cu *cu); | |
63d06c5c | 1056 | |
e7c27a73 | 1057 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1058 | |
348e048f DE |
1059 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1060 | ||
e7c27a73 | 1061 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1062 | |
e7c27a73 | 1063 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1064 | |
ff013f42 JK |
1065 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1066 | struct dwarf2_cu *, struct partial_symtab *); | |
1067 | ||
a14ed312 | 1068 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1069 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1070 | struct partial_symtab *); | |
c906108c | 1071 | |
fae299cd DC |
1072 | static void get_scope_pc_bounds (struct die_info *, |
1073 | CORE_ADDR *, CORE_ADDR *, | |
1074 | struct dwarf2_cu *); | |
1075 | ||
801e3a5b JB |
1076 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1077 | CORE_ADDR, struct dwarf2_cu *); | |
1078 | ||
a14ed312 | 1079 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1080 | struct dwarf2_cu *); |
c906108c | 1081 | |
a14ed312 | 1082 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1083 | struct type *, struct dwarf2_cu *); |
c906108c | 1084 | |
a14ed312 | 1085 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1086 | struct die_info *, struct type *, |
e7c27a73 | 1087 | struct dwarf2_cu *); |
c906108c | 1088 | |
a14ed312 | 1089 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1090 | struct type *, |
1091 | struct dwarf2_cu *); | |
c906108c | 1092 | |
134d01f1 | 1093 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1094 | |
e7c27a73 | 1095 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1096 | |
e7c27a73 | 1097 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1098 | |
5d7cb8df JK |
1099 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1100 | ||
27aa8d6a SW |
1101 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1102 | ||
f55ee35c JK |
1103 | static struct type *read_module_type (struct die_info *die, |
1104 | struct dwarf2_cu *cu); | |
1105 | ||
38d518c9 | 1106 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1107 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1108 | |
134d01f1 | 1109 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1110 | |
e7c27a73 | 1111 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1112 | |
6e70227d | 1113 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1114 | struct dwarf2_cu *); |
1115 | ||
93311388 | 1116 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1117 | |
93311388 DE |
1118 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1119 | gdb_byte *info_ptr, | |
d97bc12b DE |
1120 | gdb_byte **new_info_ptr, |
1121 | struct die_info *parent); | |
1122 | ||
93311388 DE |
1123 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1124 | gdb_byte *info_ptr, | |
fe1b8b76 | 1125 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1126 | struct die_info *parent); |
1127 | ||
93311388 DE |
1128 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1129 | gdb_byte *info_ptr, | |
fe1b8b76 | 1130 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1131 | struct die_info *parent); |
1132 | ||
93311388 DE |
1133 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1134 | struct die_info **, gdb_byte *, | |
1135 | int *); | |
1136 | ||
e7c27a73 | 1137 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1138 | |
71c25dea TT |
1139 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1140 | struct obstack *); | |
1141 | ||
e142c38c | 1142 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1143 | |
98bfdba5 PA |
1144 | static const char *dwarf2_full_name (char *name, |
1145 | struct die_info *die, | |
1146 | struct dwarf2_cu *cu); | |
1147 | ||
e142c38c | 1148 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1149 | struct dwarf2_cu **); |
9219021c | 1150 | |
a14ed312 | 1151 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1152 | |
a14ed312 | 1153 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1154 | |
a14ed312 | 1155 | static char *dwarf_form_name (unsigned int); |
c906108c | 1156 | |
a14ed312 | 1157 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1158 | |
a14ed312 | 1159 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1160 | |
1161 | #if 0 | |
a14ed312 | 1162 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1163 | #endif |
1164 | ||
f9aca02d | 1165 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1166 | |
d97bc12b DE |
1167 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1168 | ||
1169 | static void dump_die_for_error (struct die_info *); | |
1170 | ||
1171 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1172 | struct die_info *); | |
c906108c | 1173 | |
d97bc12b | 1174 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1175 | |
51545339 | 1176 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1177 | struct dwarf2_cu *); |
c906108c | 1178 | |
93311388 DE |
1179 | static int is_ref_attr (struct attribute *); |
1180 | ||
c764a876 | 1181 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1182 | |
43bbcdc2 | 1183 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1184 | |
348e048f DE |
1185 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1186 | struct attribute *, | |
1187 | struct dwarf2_cu **); | |
1188 | ||
10b3939b DJ |
1189 | static struct die_info *follow_die_ref (struct die_info *, |
1190 | struct attribute *, | |
f2f0e013 | 1191 | struct dwarf2_cu **); |
c906108c | 1192 | |
348e048f DE |
1193 | static struct die_info *follow_die_sig (struct die_info *, |
1194 | struct attribute *, | |
1195 | struct dwarf2_cu **); | |
1196 | ||
1197 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1198 | unsigned int offset); | |
1199 | ||
1200 | static void read_signatured_type (struct objfile *, | |
1201 | struct signatured_type *type_sig); | |
1202 | ||
c906108c SS |
1203 | /* memory allocation interface */ |
1204 | ||
7b5a2f43 | 1205 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1206 | |
f3dd6933 | 1207 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1208 | |
b60c80d6 | 1209 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1210 | |
e142c38c | 1211 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1212 | |
e142c38c DJ |
1213 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1214 | struct dwarf2_cu *); | |
5fb290d7 | 1215 | |
2e276125 | 1216 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1217 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1218 | |
8e19ed76 PS |
1219 | static int attr_form_is_block (struct attribute *); |
1220 | ||
3690dd37 JB |
1221 | static int attr_form_is_section_offset (struct attribute *); |
1222 | ||
1223 | static int attr_form_is_constant (struct attribute *); | |
1224 | ||
8cf6f0b1 TT |
1225 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1226 | struct dwarf2_loclist_baton *baton, | |
1227 | struct attribute *attr); | |
1228 | ||
93e7bd98 DJ |
1229 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1230 | struct symbol *sym, | |
1231 | struct dwarf2_cu *cu); | |
4c2df51b | 1232 | |
93311388 DE |
1233 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1234 | struct abbrev_info *abbrev, | |
1235 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1236 | |
72bf9492 DJ |
1237 | static void free_stack_comp_unit (void *); |
1238 | ||
72bf9492 DJ |
1239 | static hashval_t partial_die_hash (const void *item); |
1240 | ||
1241 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1242 | ||
ae038cb0 | 1243 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1244 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1245 | |
1246 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1247 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1248 | |
9816fde3 JK |
1249 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
1250 | struct objfile *objfile); | |
1251 | ||
1252 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1253 | struct die_info *comp_unit_die); | |
93311388 | 1254 | |
ae038cb0 DJ |
1255 | static void free_one_comp_unit (void *); |
1256 | ||
1257 | static void free_cached_comp_units (void *); | |
1258 | ||
1259 | static void age_cached_comp_units (void); | |
1260 | ||
1261 | static void free_one_cached_comp_unit (void *); | |
1262 | ||
f792889a DJ |
1263 | static struct type *set_die_type (struct die_info *, struct type *, |
1264 | struct dwarf2_cu *); | |
1c379e20 | 1265 | |
ae038cb0 DJ |
1266 | static void create_all_comp_units (struct objfile *); |
1267 | ||
1fd400ff TT |
1268 | static int create_debug_types_hash_table (struct objfile *objfile); |
1269 | ||
93311388 DE |
1270 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1271 | struct objfile *); | |
10b3939b DJ |
1272 | |
1273 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1274 | ||
1275 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1276 | struct dwarf2_per_cu_data *); | |
1277 | ||
ae038cb0 DJ |
1278 | static void dwarf2_mark (struct dwarf2_cu *); |
1279 | ||
1280 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1281 | ||
673bfd45 DE |
1282 | static struct type *get_die_type_at_offset (unsigned int, |
1283 | struct dwarf2_per_cu_data *per_cu); | |
1284 | ||
f792889a | 1285 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1286 | |
9291a0cd TT |
1287 | static void dwarf2_release_queue (void *dummy); |
1288 | ||
1289 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, | |
1290 | struct objfile *objfile); | |
1291 | ||
1292 | static void process_queue (struct objfile *objfile); | |
1293 | ||
1294 | static void find_file_and_directory (struct die_info *die, | |
1295 | struct dwarf2_cu *cu, | |
1296 | char **name, char **comp_dir); | |
1297 | ||
1298 | static char *file_full_name (int file, struct line_header *lh, | |
1299 | const char *comp_dir); | |
1300 | ||
1301 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, | |
1302 | gdb_byte *info_ptr, | |
1303 | gdb_byte *buffer, | |
1304 | unsigned int buffer_size, | |
1305 | bfd *abfd); | |
1306 | ||
1307 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1308 | struct dwarf2_cu *cu); | |
1309 | ||
673bfd45 | 1310 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1311 | |
9291a0cd TT |
1312 | #if WORDS_BIGENDIAN |
1313 | ||
1314 | /* Convert VALUE between big- and little-endian. */ | |
1315 | static offset_type | |
1316 | byte_swap (offset_type value) | |
1317 | { | |
1318 | offset_type result; | |
1319 | ||
1320 | result = (value & 0xff) << 24; | |
1321 | result |= (value & 0xff00) << 8; | |
1322 | result |= (value & 0xff0000) >> 8; | |
1323 | result |= (value & 0xff000000) >> 24; | |
1324 | return result; | |
1325 | } | |
1326 | ||
1327 | #define MAYBE_SWAP(V) byte_swap (V) | |
1328 | ||
1329 | #else | |
1330 | #define MAYBE_SWAP(V) (V) | |
1331 | #endif /* WORDS_BIGENDIAN */ | |
1332 | ||
1333 | /* The suffix for an index file. */ | |
1334 | #define INDEX_SUFFIX ".gdb-index" | |
1335 | ||
3da10d80 KS |
1336 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1337 | struct dwarf2_cu *cu); | |
1338 | ||
c906108c | 1339 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1340 | information and return true if we have enough to do something. |
1341 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1342 | ELF names are used. */ | |
c906108c SS |
1343 | |
1344 | int | |
251d32d9 TG |
1345 | dwarf2_has_info (struct objfile *objfile, |
1346 | const struct dwarf2_debug_sections *names) | |
c906108c | 1347 | { |
be391dca TT |
1348 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1349 | if (!dwarf2_per_objfile) | |
1350 | { | |
1351 | /* Initialize per-objfile state. */ | |
1352 | struct dwarf2_per_objfile *data | |
1353 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1354 | |
be391dca TT |
1355 | memset (data, 0, sizeof (*data)); |
1356 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1357 | dwarf2_per_objfile = data; | |
6502dd73 | 1358 | |
251d32d9 TG |
1359 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1360 | (void *) names); | |
be391dca TT |
1361 | dwarf2_per_objfile->objfile = objfile; |
1362 | } | |
1363 | return (dwarf2_per_objfile->info.asection != NULL | |
1364 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1365 | } |
1366 | ||
251d32d9 TG |
1367 | /* When loading sections, we look either for uncompressed section or for |
1368 | compressed section names. */ | |
233a11ab CS |
1369 | |
1370 | static int | |
251d32d9 TG |
1371 | section_is_p (const char *section_name, |
1372 | const struct dwarf2_section_names *names) | |
233a11ab | 1373 | { |
251d32d9 TG |
1374 | if (names->normal != NULL |
1375 | && strcmp (section_name, names->normal) == 0) | |
1376 | return 1; | |
1377 | if (names->compressed != NULL | |
1378 | && strcmp (section_name, names->compressed) == 0) | |
1379 | return 1; | |
1380 | return 0; | |
233a11ab CS |
1381 | } |
1382 | ||
c906108c SS |
1383 | /* This function is mapped across the sections and remembers the |
1384 | offset and size of each of the debugging sections we are interested | |
1385 | in. */ | |
1386 | ||
1387 | static void | |
251d32d9 | 1388 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1389 | { |
251d32d9 TG |
1390 | const struct dwarf2_debug_sections *names; |
1391 | ||
1392 | if (vnames == NULL) | |
1393 | names = &dwarf2_elf_names; | |
1394 | else | |
1395 | names = (const struct dwarf2_debug_sections *) vnames; | |
1396 | ||
1397 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1398 | { |
dce234bc PP |
1399 | dwarf2_per_objfile->info.asection = sectp; |
1400 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1401 | } |
251d32d9 | 1402 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1403 | { |
dce234bc PP |
1404 | dwarf2_per_objfile->abbrev.asection = sectp; |
1405 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1406 | } |
251d32d9 | 1407 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1408 | { |
dce234bc PP |
1409 | dwarf2_per_objfile->line.asection = sectp; |
1410 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1411 | } |
251d32d9 | 1412 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1413 | { |
dce234bc PP |
1414 | dwarf2_per_objfile->loc.asection = sectp; |
1415 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1416 | } |
251d32d9 | 1417 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1418 | { |
dce234bc PP |
1419 | dwarf2_per_objfile->macinfo.asection = sectp; |
1420 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1421 | } |
251d32d9 | 1422 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1423 | { |
dce234bc PP |
1424 | dwarf2_per_objfile->str.asection = sectp; |
1425 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1426 | } |
251d32d9 | 1427 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1428 | { |
dce234bc PP |
1429 | dwarf2_per_objfile->frame.asection = sectp; |
1430 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1431 | } |
251d32d9 | 1432 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1433 | { |
3799ccc6 | 1434 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1435 | |
3799ccc6 EZ |
1436 | if (aflag & SEC_HAS_CONTENTS) |
1437 | { | |
dce234bc PP |
1438 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1439 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1440 | } |
b6af0555 | 1441 | } |
251d32d9 | 1442 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1443 | { |
dce234bc PP |
1444 | dwarf2_per_objfile->ranges.asection = sectp; |
1445 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1446 | } |
251d32d9 | 1447 | else if (section_is_p (sectp->name, &names->types)) |
348e048f DE |
1448 | { |
1449 | dwarf2_per_objfile->types.asection = sectp; | |
1450 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1451 | } | |
251d32d9 | 1452 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1453 | { |
1454 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1455 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1456 | } | |
dce234bc | 1457 | |
72dca2f5 FR |
1458 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1459 | && bfd_section_vma (abfd, sectp) == 0) | |
1460 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1461 | } |
1462 | ||
dce234bc PP |
1463 | /* Decompress a section that was compressed using zlib. Store the |
1464 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1465 | |
1466 | static void | |
dce234bc PP |
1467 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1468 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1469 | { | |
1470 | bfd *abfd = objfile->obfd; | |
1471 | #ifndef HAVE_ZLIB_H | |
1472 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1473 | "is disabled in this copy of GDB"), | |
1474 | bfd_get_filename (abfd)); | |
1475 | #else | |
1476 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1477 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1478 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1479 | bfd_size_type uncompressed_size; |
1480 | gdb_byte *uncompressed_buffer; | |
1481 | z_stream strm; | |
1482 | int rc; | |
1483 | int header_size = 12; | |
1484 | ||
1485 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1486 | || bfd_bread (compressed_buffer, |
1487 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1488 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1489 | bfd_get_filename (abfd)); | |
1490 | ||
1491 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1492 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1493 | if (compressed_size < header_size | |
1494 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1495 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1496 | bfd_get_filename (abfd)); | |
1497 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1498 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1499 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1500 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1501 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1502 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1503 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1504 | uncompressed_size += compressed_buffer[11]; | |
1505 | ||
1506 | /* It is possible the section consists of several compressed | |
1507 | buffers concatenated together, so we uncompress in a loop. */ | |
1508 | strm.zalloc = NULL; | |
1509 | strm.zfree = NULL; | |
1510 | strm.opaque = NULL; | |
1511 | strm.avail_in = compressed_size - header_size; | |
1512 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1513 | strm.avail_out = uncompressed_size; | |
1514 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1515 | uncompressed_size); | |
1516 | rc = inflateInit (&strm); | |
1517 | while (strm.avail_in > 0) | |
1518 | { | |
1519 | if (rc != Z_OK) | |
1520 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1521 | bfd_get_filename (abfd), rc); | |
1522 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1523 | + (uncompressed_size - strm.avail_out)); | |
1524 | rc = inflate (&strm, Z_FINISH); | |
1525 | if (rc != Z_STREAM_END) | |
1526 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1527 | bfd_get_filename (abfd), rc); | |
1528 | rc = inflateReset (&strm); | |
1529 | } | |
1530 | rc = inflateEnd (&strm); | |
1531 | if (rc != Z_OK | |
1532 | || strm.avail_out != 0) | |
1533 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1534 | bfd_get_filename (abfd), rc); | |
1535 | ||
affddf13 | 1536 | do_cleanups (cleanup); |
dce234bc PP |
1537 | *outbuf = uncompressed_buffer; |
1538 | *outsize = uncompressed_size; | |
1539 | #endif | |
233a11ab CS |
1540 | } |
1541 | ||
9e0ac564 TT |
1542 | /* A helper function that decides whether a section is empty. */ |
1543 | ||
1544 | static int | |
1545 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1546 | { | |
1547 | return info->asection == NULL || info->size == 0; | |
1548 | } | |
1549 | ||
dce234bc PP |
1550 | /* Read the contents of the section SECTP from object file specified by |
1551 | OBJFILE, store info about the section into INFO. | |
1552 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1553 | |
dce234bc PP |
1554 | static void |
1555 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1556 | { |
dce234bc PP |
1557 | bfd *abfd = objfile->obfd; |
1558 | asection *sectp = info->asection; | |
1559 | gdb_byte *buf, *retbuf; | |
1560 | unsigned char header[4]; | |
c906108c | 1561 | |
be391dca TT |
1562 | if (info->readin) |
1563 | return; | |
dce234bc PP |
1564 | info->buffer = NULL; |
1565 | info->was_mmapped = 0; | |
be391dca | 1566 | info->readin = 1; |
188dd5d6 | 1567 | |
9e0ac564 | 1568 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1569 | return; |
c906108c | 1570 | |
dce234bc PP |
1571 | /* Check if the file has a 4-byte header indicating compression. */ |
1572 | if (info->size > sizeof (header) | |
1573 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1574 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1575 | { | |
1576 | /* Upon decompression, update the buffer and its size. */ | |
1577 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1578 | { | |
1579 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1580 | &info->size); | |
1581 | return; | |
1582 | } | |
1583 | } | |
4bdf3d34 | 1584 | |
dce234bc PP |
1585 | #ifdef HAVE_MMAP |
1586 | if (pagesize == 0) | |
1587 | pagesize = getpagesize (); | |
2e276125 | 1588 | |
dce234bc PP |
1589 | /* Only try to mmap sections which are large enough: we don't want to |
1590 | waste space due to fragmentation. Also, only try mmap for sections | |
1591 | without relocations. */ | |
1592 | ||
1593 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1594 | { | |
1595 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1596 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1597 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1598 | MAP_PRIVATE, pg_offset); | |
1599 | ||
1600 | if (retbuf != MAP_FAILED) | |
1601 | { | |
1602 | info->was_mmapped = 1; | |
1603 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
be391dca TT |
1604 | #if HAVE_POSIX_MADVISE |
1605 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); | |
1606 | #endif | |
dce234bc PP |
1607 | return; |
1608 | } | |
1609 | } | |
1610 | #endif | |
1611 | ||
1612 | /* If we get here, we are a normal, not-compressed section. */ | |
1613 | info->buffer = buf | |
1614 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1615 | ||
1616 | /* When debugging .o files, we may need to apply relocations; see | |
1617 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1618 | We never compress sections in .o files, so we only need to | |
1619 | try this when the section is not compressed. */ | |
ac8035ab | 1620 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1621 | if (retbuf != NULL) |
1622 | { | |
1623 | info->buffer = retbuf; | |
1624 | return; | |
1625 | } | |
1626 | ||
1627 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1628 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1629 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1630 | bfd_get_filename (abfd)); | |
1631 | } | |
1632 | ||
9e0ac564 TT |
1633 | /* A helper function that returns the size of a section in a safe way. |
1634 | If you are positive that the section has been read before using the | |
1635 | size, then it is safe to refer to the dwarf2_section_info object's | |
1636 | "size" field directly. In other cases, you must call this | |
1637 | function, because for compressed sections the size field is not set | |
1638 | correctly until the section has been read. */ | |
1639 | ||
1640 | static bfd_size_type | |
1641 | dwarf2_section_size (struct objfile *objfile, | |
1642 | struct dwarf2_section_info *info) | |
1643 | { | |
1644 | if (!info->readin) | |
1645 | dwarf2_read_section (objfile, info); | |
1646 | return info->size; | |
1647 | } | |
1648 | ||
dce234bc | 1649 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1650 | SECTION_NAME. */ |
af34e669 | 1651 | |
dce234bc | 1652 | void |
3017a003 TG |
1653 | dwarf2_get_section_info (struct objfile *objfile, |
1654 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1655 | asection **sectp, gdb_byte **bufp, |
1656 | bfd_size_type *sizep) | |
1657 | { | |
1658 | struct dwarf2_per_objfile *data | |
1659 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1660 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1661 | |
1662 | /* We may see an objfile without any DWARF, in which case we just | |
1663 | return nothing. */ | |
1664 | if (data == NULL) | |
1665 | { | |
1666 | *sectp = NULL; | |
1667 | *bufp = NULL; | |
1668 | *sizep = 0; | |
1669 | return; | |
1670 | } | |
3017a003 TG |
1671 | switch (sect) |
1672 | { | |
1673 | case DWARF2_DEBUG_FRAME: | |
1674 | info = &data->frame; | |
1675 | break; | |
1676 | case DWARF2_EH_FRAME: | |
1677 | info = &data->eh_frame; | |
1678 | break; | |
1679 | default: | |
1680 | gdb_assert_not_reached ("unexpected section"); | |
1681 | } | |
dce234bc | 1682 | |
9e0ac564 | 1683 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1684 | |
1685 | *sectp = info->asection; | |
1686 | *bufp = info->buffer; | |
1687 | *sizep = info->size; | |
1688 | } | |
1689 | ||
9291a0cd | 1690 | \f |
7b9f3c50 DE |
1691 | /* DWARF quick_symbols_functions support. */ |
1692 | ||
1693 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1694 | unique line tables, so we maintain a separate table of all .debug_line | |
1695 | derived entries to support the sharing. | |
1696 | All the quick functions need is the list of file names. We discard the | |
1697 | line_header when we're done and don't need to record it here. */ | |
1698 | struct quick_file_names | |
1699 | { | |
1700 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1701 | unsigned int offset; | |
1702 | ||
1703 | /* The number of entries in file_names, real_names. */ | |
1704 | unsigned int num_file_names; | |
1705 | ||
1706 | /* The file names from the line table, after being run through | |
1707 | file_full_name. */ | |
1708 | const char **file_names; | |
1709 | ||
1710 | /* The file names from the line table after being run through | |
1711 | gdb_realpath. These are computed lazily. */ | |
1712 | const char **real_names; | |
1713 | }; | |
1714 | ||
1715 | /* When using the index (and thus not using psymtabs), each CU has an | |
1716 | object of this type. This is used to hold information needed by | |
1717 | the various "quick" methods. */ | |
1718 | struct dwarf2_per_cu_quick_data | |
1719 | { | |
1720 | /* The file table. This can be NULL if there was no file table | |
1721 | or it's currently not read in. | |
1722 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1723 | struct quick_file_names *file_names; | |
1724 | ||
1725 | /* The corresponding symbol table. This is NULL if symbols for this | |
1726 | CU have not yet been read. */ | |
1727 | struct symtab *symtab; | |
1728 | ||
1729 | /* A temporary mark bit used when iterating over all CUs in | |
1730 | expand_symtabs_matching. */ | |
1731 | unsigned int mark : 1; | |
1732 | ||
1733 | /* True if we've tried to read the file table and found there isn't one. | |
1734 | There will be no point in trying to read it again next time. */ | |
1735 | unsigned int no_file_data : 1; | |
1736 | }; | |
1737 | ||
1738 | /* Hash function for a quick_file_names. */ | |
1739 | ||
1740 | static hashval_t | |
1741 | hash_file_name_entry (const void *e) | |
1742 | { | |
1743 | const struct quick_file_names *file_data = e; | |
1744 | ||
1745 | return file_data->offset; | |
1746 | } | |
1747 | ||
1748 | /* Equality function for a quick_file_names. */ | |
1749 | ||
1750 | static int | |
1751 | eq_file_name_entry (const void *a, const void *b) | |
1752 | { | |
1753 | const struct quick_file_names *ea = a; | |
1754 | const struct quick_file_names *eb = b; | |
1755 | ||
1756 | return ea->offset == eb->offset; | |
1757 | } | |
1758 | ||
1759 | /* Delete function for a quick_file_names. */ | |
1760 | ||
1761 | static void | |
1762 | delete_file_name_entry (void *e) | |
1763 | { | |
1764 | struct quick_file_names *file_data = e; | |
1765 | int i; | |
1766 | ||
1767 | for (i = 0; i < file_data->num_file_names; ++i) | |
1768 | { | |
1769 | xfree ((void*) file_data->file_names[i]); | |
1770 | if (file_data->real_names) | |
1771 | xfree ((void*) file_data->real_names[i]); | |
1772 | } | |
1773 | ||
1774 | /* The space for the struct itself lives on objfile_obstack, | |
1775 | so we don't free it here. */ | |
1776 | } | |
1777 | ||
1778 | /* Create a quick_file_names hash table. */ | |
1779 | ||
1780 | static htab_t | |
1781 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1782 | { | |
1783 | return htab_create_alloc (nr_initial_entries, | |
1784 | hash_file_name_entry, eq_file_name_entry, | |
1785 | delete_file_name_entry, xcalloc, xfree); | |
1786 | } | |
9291a0cd TT |
1787 | |
1788 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which | |
1789 | this CU came. */ | |
2fdf6df6 | 1790 | |
9291a0cd TT |
1791 | static void |
1792 | dw2_do_instantiate_symtab (struct objfile *objfile, | |
1793 | struct dwarf2_per_cu_data *per_cu) | |
1794 | { | |
1795 | struct cleanup *back_to; | |
1796 | ||
1797 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1798 | ||
1799 | queue_comp_unit (per_cu, objfile); | |
1800 | ||
1801 | if (per_cu->from_debug_types) | |
1802 | read_signatured_type_at_offset (objfile, per_cu->offset); | |
1803 | else | |
1804 | load_full_comp_unit (per_cu, objfile); | |
1805 | ||
1806 | process_queue (objfile); | |
1807 | ||
1808 | /* Age the cache, releasing compilation units that have not | |
1809 | been used recently. */ | |
1810 | age_cached_comp_units (); | |
1811 | ||
1812 | do_cleanups (back_to); | |
1813 | } | |
1814 | ||
1815 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1816 | the objfile from which this CU came. Returns the resulting symbol | |
1817 | table. */ | |
2fdf6df6 | 1818 | |
9291a0cd TT |
1819 | static struct symtab * |
1820 | dw2_instantiate_symtab (struct objfile *objfile, | |
1821 | struct dwarf2_per_cu_data *per_cu) | |
1822 | { | |
1823 | if (!per_cu->v.quick->symtab) | |
1824 | { | |
1825 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1826 | increment_reading_symtab (); | |
1827 | dw2_do_instantiate_symtab (objfile, per_cu); | |
1828 | do_cleanups (back_to); | |
1829 | } | |
1830 | return per_cu->v.quick->symtab; | |
1831 | } | |
1832 | ||
1fd400ff | 1833 | /* Return the CU given its index. */ |
2fdf6df6 | 1834 | |
1fd400ff TT |
1835 | static struct dwarf2_per_cu_data * |
1836 | dw2_get_cu (int index) | |
1837 | { | |
1838 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1839 | { | |
1840 | index -= dwarf2_per_objfile->n_comp_units; | |
1841 | return dwarf2_per_objfile->type_comp_units[index]; | |
1842 | } | |
1843 | return dwarf2_per_objfile->all_comp_units[index]; | |
1844 | } | |
1845 | ||
9291a0cd TT |
1846 | /* A helper function that knows how to read a 64-bit value in a way |
1847 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1848 | otherwise. */ | |
2fdf6df6 | 1849 | |
9291a0cd TT |
1850 | static int |
1851 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1852 | { | |
1853 | if (sizeof (ULONGEST) < 8) | |
1854 | { | |
1855 | int i; | |
1856 | ||
1857 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1858 | for (i = 0; i < 4; ++i) | |
1859 | if (bytes[i + 4] != 0) | |
1860 | return 0; | |
1861 | ||
1862 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1863 | } | |
1864 | else | |
1865 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1866 | return 1; | |
1867 | } | |
1868 | ||
1869 | /* Read the CU list from the mapped index, and use it to create all | |
1870 | the CU objects for this objfile. Return 0 if something went wrong, | |
1871 | 1 if everything went ok. */ | |
2fdf6df6 | 1872 | |
9291a0cd | 1873 | static int |
1fd400ff TT |
1874 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1875 | offset_type cu_list_elements) | |
9291a0cd TT |
1876 | { |
1877 | offset_type i; | |
9291a0cd TT |
1878 | |
1879 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1880 | dwarf2_per_objfile->all_comp_units | |
1881 | = obstack_alloc (&objfile->objfile_obstack, | |
1882 | dwarf2_per_objfile->n_comp_units | |
1883 | * sizeof (struct dwarf2_per_cu_data *)); | |
1884 | ||
1885 | for (i = 0; i < cu_list_elements; i += 2) | |
1886 | { | |
1887 | struct dwarf2_per_cu_data *the_cu; | |
1888 | ULONGEST offset, length; | |
1889 | ||
1890 | if (!extract_cu_value (cu_list, &offset) | |
1891 | || !extract_cu_value (cu_list + 8, &length)) | |
1892 | return 0; | |
1893 | cu_list += 2 * 8; | |
1894 | ||
1895 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1896 | struct dwarf2_per_cu_data); | |
1897 | the_cu->offset = offset; | |
1898 | the_cu->length = length; | |
1899 | the_cu->objfile = objfile; | |
1900 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1901 | struct dwarf2_per_cu_quick_data); | |
1902 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1903 | } | |
1904 | ||
1905 | return 1; | |
1906 | } | |
1907 | ||
1fd400ff | 1908 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1909 | |
1fd400ff | 1910 | static int |
673bfd45 DE |
1911 | create_signatured_type_table_from_index (struct objfile *objfile, |
1912 | const gdb_byte *bytes, | |
1913 | offset_type elements) | |
1fd400ff TT |
1914 | { |
1915 | offset_type i; | |
673bfd45 | 1916 | htab_t sig_types_hash; |
1fd400ff TT |
1917 | |
1918 | dwarf2_per_objfile->n_type_comp_units = elements / 3; | |
1919 | dwarf2_per_objfile->type_comp_units | |
1920 | = obstack_alloc (&objfile->objfile_obstack, | |
1921 | dwarf2_per_objfile->n_type_comp_units | |
1922 | * sizeof (struct dwarf2_per_cu_data *)); | |
1923 | ||
673bfd45 | 1924 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1925 | |
1926 | for (i = 0; i < elements; i += 3) | |
1927 | { | |
1928 | struct signatured_type *type_sig; | |
1929 | ULONGEST offset, type_offset, signature; | |
1930 | void **slot; | |
1931 | ||
1932 | if (!extract_cu_value (bytes, &offset) | |
1933 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1934 | return 0; | |
1935 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1936 | bytes += 3 * 8; | |
1937 | ||
1938 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1939 | struct signatured_type); | |
1940 | type_sig->signature = signature; | |
1fd400ff TT |
1941 | type_sig->type_offset = type_offset; |
1942 | type_sig->per_cu.from_debug_types = 1; | |
1943 | type_sig->per_cu.offset = offset; | |
1944 | type_sig->per_cu.objfile = objfile; | |
1945 | type_sig->per_cu.v.quick | |
1946 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1947 | struct dwarf2_per_cu_quick_data); | |
1948 | ||
673bfd45 | 1949 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
1950 | *slot = type_sig; |
1951 | ||
1952 | dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu; | |
1953 | } | |
1954 | ||
673bfd45 | 1955 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1956 | |
1957 | return 1; | |
1958 | } | |
1959 | ||
9291a0cd TT |
1960 | /* Read the address map data from the mapped index, and use it to |
1961 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 1962 | |
9291a0cd TT |
1963 | static void |
1964 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1965 | { | |
1966 | const gdb_byte *iter, *end; | |
1967 | struct obstack temp_obstack; | |
1968 | struct addrmap *mutable_map; | |
1969 | struct cleanup *cleanup; | |
1970 | CORE_ADDR baseaddr; | |
1971 | ||
1972 | obstack_init (&temp_obstack); | |
1973 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1974 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1975 | ||
1976 | iter = index->address_table; | |
1977 | end = iter + index->address_table_size; | |
1978 | ||
1979 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1980 | ||
1981 | while (iter < end) | |
1982 | { | |
1983 | ULONGEST hi, lo, cu_index; | |
1984 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1985 | iter += 8; | |
1986 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1987 | iter += 8; | |
1988 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1989 | iter += 4; | |
1990 | ||
1991 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1992 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1993 | } |
1994 | ||
1995 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1996 | &objfile->objfile_obstack); | |
1997 | do_cleanups (cleanup); | |
1998 | } | |
1999 | ||
59d7bcaf JK |
2000 | /* The hash function for strings in the mapped index. This is the same as |
2001 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
2002 | implementation. This is necessary because the hash function is tied to the | |
2003 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2004 | SYMBOL_HASH_NEXT. |
2005 | ||
2006 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2007 | |
9291a0cd | 2008 | static hashval_t |
559a7a62 | 2009 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2010 | { |
2011 | const unsigned char *str = (const unsigned char *) p; | |
2012 | hashval_t r = 0; | |
2013 | unsigned char c; | |
2014 | ||
2015 | while ((c = *str++) != 0) | |
559a7a62 JK |
2016 | { |
2017 | if (index_version >= 5) | |
2018 | c = tolower (c); | |
2019 | r = r * 67 + c - 113; | |
2020 | } | |
9291a0cd TT |
2021 | |
2022 | return r; | |
2023 | } | |
2024 | ||
2025 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2026 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2027 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2028 | |
9291a0cd TT |
2029 | static int |
2030 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2031 | offset_type **vec_out) | |
2032 | { | |
0cf03b49 JK |
2033 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2034 | offset_type hash; | |
9291a0cd | 2035 | offset_type slot, step; |
559a7a62 | 2036 | int (*cmp) (const char *, const char *); |
9291a0cd | 2037 | |
0cf03b49 JK |
2038 | if (current_language->la_language == language_cplus |
2039 | || current_language->la_language == language_java | |
2040 | || current_language->la_language == language_fortran) | |
2041 | { | |
2042 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2043 | not contain any. */ | |
2044 | const char *paren = strchr (name, '('); | |
2045 | ||
2046 | if (paren) | |
2047 | { | |
2048 | char *dup; | |
2049 | ||
2050 | dup = xmalloc (paren - name + 1); | |
2051 | memcpy (dup, name, paren - name); | |
2052 | dup[paren - name] = 0; | |
2053 | ||
2054 | make_cleanup (xfree, dup); | |
2055 | name = dup; | |
2056 | } | |
2057 | } | |
2058 | ||
559a7a62 JK |
2059 | /* Index version 4 did not support case insensitive searches. But the |
2060 | indexes for case insensitive languages are built in lowercase, therefore | |
2061 | simulate our NAME being searched is also lowercased. */ | |
2062 | hash = mapped_index_string_hash ((index->version == 4 | |
2063 | && case_sensitivity == case_sensitive_off | |
2064 | ? 5 : index->version), | |
2065 | name); | |
2066 | ||
3876f04e DE |
2067 | slot = hash & (index->symbol_table_slots - 1); |
2068 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2069 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2070 | |
2071 | for (;;) | |
2072 | { | |
2073 | /* Convert a slot number to an offset into the table. */ | |
2074 | offset_type i = 2 * slot; | |
2075 | const char *str; | |
3876f04e | 2076 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2077 | { |
2078 | do_cleanups (back_to); | |
2079 | return 0; | |
2080 | } | |
9291a0cd | 2081 | |
3876f04e | 2082 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2083 | if (!cmp (name, str)) |
9291a0cd TT |
2084 | { |
2085 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2086 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2087 | do_cleanups (back_to); |
9291a0cd TT |
2088 | return 1; |
2089 | } | |
2090 | ||
3876f04e | 2091 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2092 | } |
2093 | } | |
2094 | ||
2095 | /* Read the index file. If everything went ok, initialize the "quick" | |
2096 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2097 | |
9291a0cd TT |
2098 | static int |
2099 | dwarf2_read_index (struct objfile *objfile) | |
2100 | { | |
9291a0cd TT |
2101 | char *addr; |
2102 | struct mapped_index *map; | |
b3b272e1 | 2103 | offset_type *metadata; |
ac0b195c KW |
2104 | const gdb_byte *cu_list; |
2105 | const gdb_byte *types_list = NULL; | |
2106 | offset_type version, cu_list_elements; | |
2107 | offset_type types_list_elements = 0; | |
1fd400ff | 2108 | int i; |
9291a0cd | 2109 | |
9e0ac564 | 2110 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2111 | return 0; |
82430852 JK |
2112 | |
2113 | /* Older elfutils strip versions could keep the section in the main | |
2114 | executable while splitting it for the separate debug info file. */ | |
2115 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2116 | & SEC_HAS_CONTENTS) == 0) | |
2117 | return 0; | |
2118 | ||
9291a0cd TT |
2119 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2120 | ||
2121 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2122 | /* Version check. */ | |
1fd400ff | 2123 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2124 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2125 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2126 | contained incomplete addrmap. So, it seems better to just ignore such |
559a7a62 JK |
2127 | indices. Index version 4 uses a different hash function than index |
2128 | version 5 and later. */ | |
831adc1f | 2129 | if (version < 4) |
9291a0cd | 2130 | return 0; |
594e8718 JK |
2131 | /* Indexes with higher version than the one supported by GDB may be no |
2132 | longer backward compatible. */ | |
559a7a62 | 2133 | if (version > 5) |
594e8718 | 2134 | return 0; |
9291a0cd TT |
2135 | |
2136 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2137 | map->version = version; |
b3b272e1 | 2138 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2139 | |
2140 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2141 | |
2142 | i = 0; | |
2143 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2144 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2145 | / 8); |
1fd400ff TT |
2146 | ++i; |
2147 | ||
987d643c TT |
2148 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2149 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2150 | - MAYBE_SWAP (metadata[i])) | |
2151 | / 8); | |
2152 | ++i; | |
1fd400ff TT |
2153 | |
2154 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2155 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2156 | - MAYBE_SWAP (metadata[i])); | |
2157 | ++i; | |
2158 | ||
3876f04e DE |
2159 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2160 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2161 | - MAYBE_SWAP (metadata[i])) | |
2162 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2163 | ++i; |
9291a0cd | 2164 | |
1fd400ff TT |
2165 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2166 | ||
2167 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
2168 | return 0; | |
2169 | ||
987d643c | 2170 | if (types_list_elements |
673bfd45 DE |
2171 | && !create_signatured_type_table_from_index (objfile, types_list, |
2172 | types_list_elements)) | |
9291a0cd TT |
2173 | return 0; |
2174 | ||
2175 | create_addrmap_from_index (objfile, map); | |
2176 | ||
2177 | dwarf2_per_objfile->index_table = map; | |
2178 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2179 | dwarf2_per_objfile->quick_file_names_table = |
2180 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2181 | |
2182 | return 1; | |
2183 | } | |
2184 | ||
2185 | /* A helper for the "quick" functions which sets the global | |
2186 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2187 | |
9291a0cd TT |
2188 | static void |
2189 | dw2_setup (struct objfile *objfile) | |
2190 | { | |
2191 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2192 | gdb_assert (dwarf2_per_objfile); | |
2193 | } | |
2194 | ||
2195 | /* A helper for the "quick" functions which attempts to read the line | |
2196 | table for THIS_CU. */ | |
2fdf6df6 | 2197 | |
7b9f3c50 DE |
2198 | static struct quick_file_names * |
2199 | dw2_get_file_names (struct objfile *objfile, | |
2200 | struct dwarf2_per_cu_data *this_cu) | |
9291a0cd TT |
2201 | { |
2202 | bfd *abfd = objfile->obfd; | |
7b9f3c50 | 2203 | struct line_header *lh; |
9291a0cd TT |
2204 | struct attribute *attr; |
2205 | struct cleanup *cleanups; | |
2206 | struct die_info *comp_unit_die; | |
36374493 | 2207 | struct dwarf2_section_info* sec; |
9291a0cd TT |
2208 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; |
2209 | int has_children, i; | |
2210 | struct dwarf2_cu cu; | |
2211 | unsigned int bytes_read, buffer_size; | |
2212 | struct die_reader_specs reader_specs; | |
2213 | char *name, *comp_dir; | |
7b9f3c50 DE |
2214 | void **slot; |
2215 | struct quick_file_names *qfn; | |
2216 | unsigned int line_offset; | |
9291a0cd | 2217 | |
7b9f3c50 DE |
2218 | if (this_cu->v.quick->file_names != NULL) |
2219 | return this_cu->v.quick->file_names; | |
2220 | /* If we know there is no line data, no point in looking again. */ | |
2221 | if (this_cu->v.quick->no_file_data) | |
2222 | return NULL; | |
9291a0cd | 2223 | |
9816fde3 | 2224 | init_one_comp_unit (&cu, objfile); |
9291a0cd TT |
2225 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
2226 | ||
36374493 DE |
2227 | if (this_cu->from_debug_types) |
2228 | sec = &dwarf2_per_objfile->types; | |
2229 | else | |
2230 | sec = &dwarf2_per_objfile->info; | |
2231 | dwarf2_read_section (objfile, sec); | |
2232 | buffer_size = sec->size; | |
2233 | buffer = sec->buffer; | |
9291a0cd TT |
2234 | info_ptr = buffer + this_cu->offset; |
2235 | beg_of_comp_unit = info_ptr; | |
2236 | ||
2237 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
2238 | buffer, buffer_size, | |
2239 | abfd); | |
2240 | ||
2241 | /* Complete the cu_header. */ | |
2242 | cu.header.offset = beg_of_comp_unit - buffer; | |
2243 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
2244 | ||
2245 | this_cu->cu = &cu; | |
2246 | cu.per_cu = this_cu; | |
2247 | ||
2248 | dwarf2_read_abbrevs (abfd, &cu); | |
2249 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
2250 | ||
2251 | if (this_cu->from_debug_types) | |
2252 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
2253 | init_cu_die_reader (&reader_specs, &cu); | |
e8e80198 MS |
2254 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
2255 | &has_children); | |
9291a0cd | 2256 | |
7b9f3c50 DE |
2257 | lh = NULL; |
2258 | slot = NULL; | |
2259 | line_offset = 0; | |
9291a0cd TT |
2260 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
2261 | if (attr) | |
2262 | { | |
7b9f3c50 DE |
2263 | struct quick_file_names find_entry; |
2264 | ||
2265 | line_offset = DW_UNSND (attr); | |
2266 | ||
2267 | /* We may have already read in this line header (TU line header sharing). | |
2268 | If we have we're done. */ | |
2269 | find_entry.offset = line_offset; | |
2270 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2271 | &find_entry, INSERT); | |
2272 | if (*slot != NULL) | |
2273 | { | |
2274 | do_cleanups (cleanups); | |
2275 | this_cu->v.quick->file_names = *slot; | |
2276 | return *slot; | |
2277 | } | |
2278 | ||
9291a0cd TT |
2279 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
2280 | } | |
2281 | if (lh == NULL) | |
2282 | { | |
2283 | do_cleanups (cleanups); | |
7b9f3c50 DE |
2284 | this_cu->v.quick->no_file_data = 1; |
2285 | return NULL; | |
9291a0cd TT |
2286 | } |
2287 | ||
7b9f3c50 DE |
2288 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2289 | qfn->offset = line_offset; | |
2290 | gdb_assert (slot != NULL); | |
2291 | *slot = qfn; | |
9291a0cd | 2292 | |
7b9f3c50 | 2293 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
9291a0cd | 2294 | |
7b9f3c50 DE |
2295 | qfn->num_file_names = lh->num_file_names; |
2296 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2297 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2298 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2299 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2300 | qfn->real_names = NULL; | |
9291a0cd | 2301 | |
7b9f3c50 | 2302 | free_line_header (lh); |
9291a0cd | 2303 | do_cleanups (cleanups); |
7b9f3c50 DE |
2304 | |
2305 | this_cu->v.quick->file_names = qfn; | |
2306 | return qfn; | |
9291a0cd TT |
2307 | } |
2308 | ||
2309 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2310 | real path for a given file name from the line table. */ |
2fdf6df6 | 2311 | |
9291a0cd | 2312 | static const char * |
7b9f3c50 DE |
2313 | dw2_get_real_path (struct objfile *objfile, |
2314 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2315 | { |
7b9f3c50 DE |
2316 | if (qfn->real_names == NULL) |
2317 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2318 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2319 | |
7b9f3c50 DE |
2320 | if (qfn->real_names[index] == NULL) |
2321 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2322 | |
7b9f3c50 | 2323 | return qfn->real_names[index]; |
9291a0cd TT |
2324 | } |
2325 | ||
2326 | static struct symtab * | |
2327 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2328 | { | |
2329 | int index; | |
ae2de4f8 | 2330 | |
9291a0cd TT |
2331 | dw2_setup (objfile); |
2332 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1fd400ff | 2333 | return dw2_instantiate_symtab (objfile, dw2_get_cu (index)); |
9291a0cd TT |
2334 | } |
2335 | ||
7b9f3c50 DE |
2336 | /* Traversal function for dw2_forget_cached_source_info. */ |
2337 | ||
2338 | static int | |
2339 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2340 | { |
7b9f3c50 | 2341 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2342 | |
7b9f3c50 | 2343 | if (file_data->real_names) |
9291a0cd | 2344 | { |
7b9f3c50 | 2345 | int i; |
9291a0cd | 2346 | |
7b9f3c50 | 2347 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2348 | { |
7b9f3c50 DE |
2349 | xfree ((void*) file_data->real_names[i]); |
2350 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2351 | } |
2352 | } | |
7b9f3c50 DE |
2353 | |
2354 | return 1; | |
2355 | } | |
2356 | ||
2357 | static void | |
2358 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2359 | { | |
2360 | dw2_setup (objfile); | |
2361 | ||
2362 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2363 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2364 | } |
2365 | ||
2366 | static int | |
2367 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
2368 | const char *full_path, const char *real_path, | |
2369 | struct symtab **result) | |
2370 | { | |
2371 | int i; | |
2372 | int check_basename = lbasename (name) == name; | |
2373 | struct dwarf2_per_cu_data *base_cu = NULL; | |
2374 | ||
2375 | dw2_setup (objfile); | |
ae2de4f8 | 2376 | |
1fd400ff TT |
2377 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2378 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2379 | { |
2380 | int j; | |
e254ef6a | 2381 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2382 | struct quick_file_names *file_data; |
9291a0cd | 2383 | |
e254ef6a | 2384 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2385 | continue; |
2386 | ||
7b9f3c50 DE |
2387 | file_data = dw2_get_file_names (objfile, per_cu); |
2388 | if (file_data == NULL) | |
9291a0cd TT |
2389 | continue; |
2390 | ||
7b9f3c50 | 2391 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2392 | { |
7b9f3c50 | 2393 | const char *this_name = file_data->file_names[j]; |
9291a0cd TT |
2394 | |
2395 | if (FILENAME_CMP (name, this_name) == 0) | |
2396 | { | |
e254ef6a | 2397 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2398 | return 1; |
2399 | } | |
2400 | ||
2401 | if (check_basename && ! base_cu | |
2402 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2403 | base_cu = per_cu; |
9291a0cd TT |
2404 | |
2405 | if (full_path != NULL) | |
2406 | { | |
7b9f3c50 DE |
2407 | const char *this_real_name = dw2_get_real_path (objfile, |
2408 | file_data, j); | |
9291a0cd | 2409 | |
7b9f3c50 DE |
2410 | if (this_real_name != NULL |
2411 | && FILENAME_CMP (full_path, this_real_name) == 0) | |
9291a0cd | 2412 | { |
e254ef6a | 2413 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2414 | return 1; |
2415 | } | |
2416 | } | |
2417 | ||
2418 | if (real_path != NULL) | |
2419 | { | |
7b9f3c50 DE |
2420 | const char *this_real_name = dw2_get_real_path (objfile, |
2421 | file_data, j); | |
9291a0cd | 2422 | |
7b9f3c50 DE |
2423 | if (this_real_name != NULL |
2424 | && FILENAME_CMP (real_path, this_real_name) == 0) | |
9291a0cd | 2425 | { |
74dd2ca6 DE |
2426 | *result = dw2_instantiate_symtab (objfile, per_cu); |
2427 | return 1; | |
9291a0cd TT |
2428 | } |
2429 | } | |
2430 | } | |
2431 | } | |
2432 | ||
2433 | if (base_cu) | |
2434 | { | |
2435 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2436 | return 1; | |
2437 | } | |
2438 | ||
2439 | return 0; | |
2440 | } | |
2441 | ||
2442 | static struct symtab * | |
2443 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2444 | const char *name, domain_enum domain) | |
2445 | { | |
774b6a14 | 2446 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2447 | instead. */ |
2448 | return NULL; | |
2449 | } | |
2450 | ||
2451 | /* A helper function that expands all symtabs that hold an object | |
2452 | named NAME. */ | |
2fdf6df6 | 2453 | |
9291a0cd TT |
2454 | static void |
2455 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2456 | { | |
2457 | dw2_setup (objfile); | |
2458 | ||
ae2de4f8 | 2459 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2460 | if (dwarf2_per_objfile->index_table) |
2461 | { | |
2462 | offset_type *vec; | |
2463 | ||
2464 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2465 | name, &vec)) | |
2466 | { | |
2467 | offset_type i, len = MAYBE_SWAP (*vec); | |
2468 | for (i = 0; i < len; ++i) | |
2469 | { | |
2470 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2471 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2472 | |
e254ef6a | 2473 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2474 | } |
2475 | } | |
2476 | } | |
2477 | } | |
2478 | ||
774b6a14 TT |
2479 | static void |
2480 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2481 | enum block_enum block_kind, const char *name, |
774b6a14 | 2482 | domain_enum domain) |
9291a0cd | 2483 | { |
774b6a14 | 2484 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2485 | } |
2486 | ||
2487 | static void | |
2488 | dw2_print_stats (struct objfile *objfile) | |
2489 | { | |
2490 | int i, count; | |
2491 | ||
2492 | dw2_setup (objfile); | |
2493 | count = 0; | |
1fd400ff TT |
2494 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2495 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2496 | { |
e254ef6a | 2497 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2498 | |
e254ef6a | 2499 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2500 | ++count; |
2501 | } | |
2502 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2503 | } | |
2504 | ||
2505 | static void | |
2506 | dw2_dump (struct objfile *objfile) | |
2507 | { | |
2508 | /* Nothing worth printing. */ | |
2509 | } | |
2510 | ||
2511 | static void | |
2512 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2513 | struct section_offsets *delta) | |
2514 | { | |
2515 | /* There's nothing to relocate here. */ | |
2516 | } | |
2517 | ||
2518 | static void | |
2519 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2520 | const char *func_name) | |
2521 | { | |
2522 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2523 | } | |
2524 | ||
2525 | static void | |
2526 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2527 | { | |
2528 | int i; | |
2529 | ||
2530 | dw2_setup (objfile); | |
1fd400ff TT |
2531 | |
2532 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2533 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2534 | { |
e254ef6a | 2535 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2536 | |
e254ef6a | 2537 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2538 | } |
2539 | } | |
2540 | ||
2541 | static void | |
2542 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2543 | const char *filename) | |
2544 | { | |
2545 | int i; | |
2546 | ||
2547 | dw2_setup (objfile); | |
d4637a04 DE |
2548 | |
2549 | /* We don't need to consider type units here. | |
2550 | This is only called for examining code, e.g. expand_line_sal. | |
2551 | There can be an order of magnitude (or more) more type units | |
2552 | than comp units, and we avoid them if we can. */ | |
2553 | ||
2554 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2555 | { |
2556 | int j; | |
e254ef6a | 2557 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2558 | struct quick_file_names *file_data; |
9291a0cd | 2559 | |
e254ef6a | 2560 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2561 | continue; |
2562 | ||
7b9f3c50 DE |
2563 | file_data = dw2_get_file_names (objfile, per_cu); |
2564 | if (file_data == NULL) | |
9291a0cd TT |
2565 | continue; |
2566 | ||
7b9f3c50 | 2567 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2568 | { |
7b9f3c50 | 2569 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2570 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2571 | { |
e254ef6a | 2572 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2573 | break; |
2574 | } | |
2575 | } | |
2576 | } | |
2577 | } | |
2578 | ||
dd786858 | 2579 | static const char * |
9291a0cd TT |
2580 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2581 | { | |
e254ef6a | 2582 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2583 | offset_type *vec; |
7b9f3c50 | 2584 | struct quick_file_names *file_data; |
9291a0cd TT |
2585 | |
2586 | dw2_setup (objfile); | |
2587 | ||
ae2de4f8 | 2588 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2589 | if (!dwarf2_per_objfile->index_table) |
2590 | return NULL; | |
2591 | ||
2592 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2593 | name, &vec)) | |
2594 | return NULL; | |
2595 | ||
2596 | /* Note that this just looks at the very first one named NAME -- but | |
2597 | actually we are looking for a function. find_main_filename | |
2598 | should be rewritten so that it doesn't require a custom hook. It | |
2599 | could just use the ordinary symbol tables. */ | |
2600 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2601 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2602 | |
7b9f3c50 DE |
2603 | file_data = dw2_get_file_names (objfile, per_cu); |
2604 | if (file_data == NULL) | |
9291a0cd TT |
2605 | return NULL; |
2606 | ||
7b9f3c50 | 2607 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2608 | } |
2609 | ||
2610 | static void | |
40658b94 PH |
2611 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2612 | struct objfile *objfile, int global, | |
2613 | int (*callback) (struct block *, | |
2614 | struct symbol *, void *), | |
2edb89d3 JK |
2615 | void *data, symbol_compare_ftype *match, |
2616 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2617 | { |
40658b94 | 2618 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2619 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2620 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2621 | } |
2622 | ||
2623 | static void | |
2624 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2625 | int (*file_matcher) (const char *, void *), | |
2626 | int (*name_matcher) (const char *, void *), | |
8903c50d | 2627 | enum search_domain kind, |
9291a0cd TT |
2628 | void *data) |
2629 | { | |
2630 | int i; | |
2631 | offset_type iter; | |
4b5246aa | 2632 | struct mapped_index *index; |
9291a0cd TT |
2633 | |
2634 | dw2_setup (objfile); | |
ae2de4f8 DE |
2635 | |
2636 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2637 | if (!dwarf2_per_objfile->index_table) |
2638 | return; | |
4b5246aa | 2639 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2640 | |
7b08b9eb JK |
2641 | if (file_matcher != NULL) |
2642 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2643 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
2644 | { | |
2645 | int j; | |
2646 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2647 | struct quick_file_names *file_data; | |
2648 | ||
2649 | per_cu->v.quick->mark = 0; | |
2650 | if (per_cu->v.quick->symtab) | |
2651 | continue; | |
2652 | ||
2653 | file_data = dw2_get_file_names (objfile, per_cu); | |
2654 | if (file_data == NULL) | |
2655 | continue; | |
2656 | ||
2657 | for (j = 0; j < file_data->num_file_names; ++j) | |
2658 | { | |
2659 | if (file_matcher (file_data->file_names[j], data)) | |
2660 | { | |
2661 | per_cu->v.quick->mark = 1; | |
2662 | break; | |
2663 | } | |
2664 | } | |
2665 | } | |
9291a0cd | 2666 | |
3876f04e | 2667 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2668 | { |
2669 | offset_type idx = 2 * iter; | |
2670 | const char *name; | |
2671 | offset_type *vec, vec_len, vec_idx; | |
2672 | ||
3876f04e | 2673 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2674 | continue; |
2675 | ||
3876f04e | 2676 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd TT |
2677 | |
2678 | if (! (*name_matcher) (name, data)) | |
2679 | continue; | |
2680 | ||
2681 | /* The name was matched, now expand corresponding CUs that were | |
2682 | marked. */ | |
4b5246aa | 2683 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2684 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2685 | vec_len = MAYBE_SWAP (vec[0]); |
2686 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2687 | { | |
e254ef6a | 2688 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2689 | |
e254ef6a | 2690 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2691 | if (file_matcher == NULL || per_cu->v.quick->mark) |
e254ef6a | 2692 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2693 | } |
2694 | } | |
2695 | } | |
2696 | ||
2697 | static struct symtab * | |
2698 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2699 | struct minimal_symbol *msymbol, | |
2700 | CORE_ADDR pc, | |
2701 | struct obj_section *section, | |
2702 | int warn_if_readin) | |
2703 | { | |
2704 | struct dwarf2_per_cu_data *data; | |
2705 | ||
2706 | dw2_setup (objfile); | |
2707 | ||
2708 | if (!objfile->psymtabs_addrmap) | |
2709 | return NULL; | |
2710 | ||
2711 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2712 | if (!data) | |
2713 | return NULL; | |
2714 | ||
2715 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2716 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2717 | paddress (get_objfile_arch (objfile), pc)); |
2718 | ||
2719 | return dw2_instantiate_symtab (objfile, data); | |
2720 | } | |
2721 | ||
9291a0cd TT |
2722 | static void |
2723 | dw2_map_symbol_filenames (struct objfile *objfile, | |
2724 | void (*fun) (const char *, const char *, void *), | |
2725 | void *data) | |
2726 | { | |
2727 | int i; | |
2728 | ||
2729 | dw2_setup (objfile); | |
ae2de4f8 | 2730 | |
1fd400ff TT |
2731 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2732 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2733 | { |
2734 | int j; | |
e254ef6a | 2735 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2736 | struct quick_file_names *file_data; |
9291a0cd | 2737 | |
e254ef6a | 2738 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2739 | continue; |
2740 | ||
7b9f3c50 DE |
2741 | file_data = dw2_get_file_names (objfile, per_cu); |
2742 | if (file_data == NULL) | |
9291a0cd TT |
2743 | continue; |
2744 | ||
7b9f3c50 | 2745 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2746 | { |
7b9f3c50 DE |
2747 | const char *this_real_name = dw2_get_real_path (objfile, file_data, |
2748 | j); | |
2749 | (*fun) (file_data->file_names[j], this_real_name, data); | |
9291a0cd TT |
2750 | } |
2751 | } | |
2752 | } | |
2753 | ||
2754 | static int | |
2755 | dw2_has_symbols (struct objfile *objfile) | |
2756 | { | |
2757 | return 1; | |
2758 | } | |
2759 | ||
2760 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2761 | { | |
2762 | dw2_has_symbols, | |
2763 | dw2_find_last_source_symtab, | |
2764 | dw2_forget_cached_source_info, | |
2765 | dw2_lookup_symtab, | |
2766 | dw2_lookup_symbol, | |
774b6a14 | 2767 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2768 | dw2_print_stats, |
2769 | dw2_dump, | |
2770 | dw2_relocate, | |
2771 | dw2_expand_symtabs_for_function, | |
2772 | dw2_expand_all_symtabs, | |
2773 | dw2_expand_symtabs_with_filename, | |
2774 | dw2_find_symbol_file, | |
40658b94 | 2775 | dw2_map_matching_symbols, |
9291a0cd TT |
2776 | dw2_expand_symtabs_matching, |
2777 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
2778 | dw2_map_symbol_filenames |
2779 | }; | |
2780 | ||
2781 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2782 | file will use psymtabs, or 1 if using the GNU index. */ | |
2783 | ||
2784 | int | |
2785 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2786 | { | |
2787 | /* If we're about to read full symbols, don't bother with the | |
2788 | indices. In this case we also don't care if some other debug | |
2789 | format is making psymtabs, because they are all about to be | |
2790 | expanded anyway. */ | |
2791 | if ((objfile->flags & OBJF_READNOW)) | |
2792 | { | |
2793 | int i; | |
2794 | ||
2795 | dwarf2_per_objfile->using_index = 1; | |
2796 | create_all_comp_units (objfile); | |
1fd400ff | 2797 | create_debug_types_hash_table (objfile); |
7b9f3c50 DE |
2798 | dwarf2_per_objfile->quick_file_names_table = |
2799 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2800 | |
1fd400ff TT |
2801 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2802 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2803 | { |
e254ef6a | 2804 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2805 | |
e254ef6a DE |
2806 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2807 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2808 | } |
2809 | ||
2810 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2811 | these functions will be no-ops because we will have expanded | |
2812 | all symtabs. */ | |
2813 | return 1; | |
2814 | } | |
2815 | ||
2816 | if (dwarf2_read_index (objfile)) | |
2817 | return 1; | |
2818 | ||
9291a0cd TT |
2819 | return 0; |
2820 | } | |
2821 | ||
2822 | \f | |
2823 | ||
dce234bc PP |
2824 | /* Build a partial symbol table. */ |
2825 | ||
2826 | void | |
f29dff0a | 2827 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2828 | { |
f29dff0a | 2829 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2830 | { |
2831 | init_psymbol_list (objfile, 1024); | |
2832 | } | |
2833 | ||
d146bf1e | 2834 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2835 | } |
c906108c | 2836 | |
45452591 DE |
2837 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2838 | ||
2839 | static inline int | |
2840 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2841 | { | |
2842 | unsigned int bottom = cu_header->offset; | |
2843 | unsigned int top = (cu_header->offset | |
2844 | + cu_header->length | |
2845 | + cu_header->initial_length_size); | |
9a619af0 | 2846 | |
45452591 DE |
2847 | return (offset >= bottom && offset < top); |
2848 | } | |
2849 | ||
93311388 DE |
2850 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2851 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2852 | by the caller. */ | |
107d2387 | 2853 | |
fe1b8b76 | 2854 | static gdb_byte * |
107d2387 | 2855 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2856 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2857 | { |
2858 | int signed_addr; | |
891d2f0b | 2859 | unsigned int bytes_read; |
c764a876 DE |
2860 | |
2861 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2862 | cu_header->initial_length_size = bytes_read; | |
2863 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2864 | info_ptr += bytes_read; |
107d2387 AC |
2865 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2866 | info_ptr += 2; | |
613e1657 | 2867 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2868 | &bytes_read); |
613e1657 | 2869 | info_ptr += bytes_read; |
107d2387 AC |
2870 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2871 | info_ptr += 1; | |
2872 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2873 | if (signed_addr < 0) | |
8e65ff28 | 2874 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2875 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2876 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2877 | |
107d2387 AC |
2878 | return info_ptr; |
2879 | } | |
2880 | ||
fe1b8b76 JB |
2881 | static gdb_byte * |
2882 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2883 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2884 | bfd *abfd) |
2885 | { | |
fe1b8b76 | 2886 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
2887 | |
2888 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
2889 | ||
2dc7f7b3 | 2890 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2891 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2892 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2893 | bfd_get_filename (abfd)); | |
72bf9492 | 2894 | |
9e0ac564 TT |
2895 | if (header->abbrev_offset |
2896 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, | |
2897 | &dwarf2_per_objfile->abbrev)) | |
8a3fe4f8 AC |
2898 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2899 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2900 | (long) header->abbrev_offset, |
93311388 | 2901 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2902 | bfd_get_filename (abfd)); |
2903 | ||
2904 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2905 | > buffer + buffer_size) |
8a3fe4f8 AC |
2906 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2907 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2908 | (long) header->length, |
93311388 | 2909 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2910 | bfd_get_filename (abfd)); |
2911 | ||
2912 | return info_ptr; | |
2913 | } | |
2914 | ||
348e048f DE |
2915 | /* Read in the types comp unit header information from .debug_types entry at |
2916 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2917 | ||
2918 | static gdb_byte * | |
2919 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
2920 | ULONGEST *signature, | |
2921 | gdb_byte *types_ptr, bfd *abfd) | |
2922 | { | |
348e048f DE |
2923 | gdb_byte *initial_types_ptr = types_ptr; |
2924 | ||
6e70227d | 2925 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
fa238c03 | 2926 | &dwarf2_per_objfile->types); |
348e048f DE |
2927 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
2928 | ||
2929 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
2930 | ||
2931 | *signature = read_8_bytes (abfd, types_ptr); | |
2932 | types_ptr += 8; | |
2933 | types_ptr += cu_header->offset_size; | |
2934 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
2935 | ||
2936 | return types_ptr; | |
2937 | } | |
2938 | ||
aaa75496 JB |
2939 | /* Allocate a new partial symtab for file named NAME and mark this new |
2940 | partial symtab as being an include of PST. */ | |
2941 | ||
2942 | static void | |
2943 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
2944 | struct objfile *objfile) | |
2945 | { | |
2946 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
2947 | ||
2948 | subpst->section_offsets = pst->section_offsets; | |
2949 | subpst->textlow = 0; | |
2950 | subpst->texthigh = 0; | |
2951 | ||
2952 | subpst->dependencies = (struct partial_symtab **) | |
2953 | obstack_alloc (&objfile->objfile_obstack, | |
2954 | sizeof (struct partial_symtab *)); | |
2955 | subpst->dependencies[0] = pst; | |
2956 | subpst->number_of_dependencies = 1; | |
2957 | ||
2958 | subpst->globals_offset = 0; | |
2959 | subpst->n_global_syms = 0; | |
2960 | subpst->statics_offset = 0; | |
2961 | subpst->n_static_syms = 0; | |
2962 | subpst->symtab = NULL; | |
2963 | subpst->read_symtab = pst->read_symtab; | |
2964 | subpst->readin = 0; | |
2965 | ||
2966 | /* No private part is necessary for include psymtabs. This property | |
2967 | can be used to differentiate between such include psymtabs and | |
10b3939b | 2968 | the regular ones. */ |
58a9656e | 2969 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
2970 | } |
2971 | ||
2972 | /* Read the Line Number Program data and extract the list of files | |
2973 | included by the source file represented by PST. Build an include | |
d85a05f0 | 2974 | partial symtab for each of these included files. */ |
aaa75496 JB |
2975 | |
2976 | static void | |
2977 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 2978 | struct die_info *die, |
aaa75496 JB |
2979 | struct partial_symtab *pst) |
2980 | { | |
2981 | struct objfile *objfile = cu->objfile; | |
2982 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
2983 | struct line_header *lh = NULL; |
2984 | struct attribute *attr; | |
aaa75496 | 2985 | |
d85a05f0 DJ |
2986 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
2987 | if (attr) | |
2988 | { | |
2989 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 2990 | |
d85a05f0 DJ |
2991 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
2992 | } | |
aaa75496 JB |
2993 | if (lh == NULL) |
2994 | return; /* No linetable, so no includes. */ | |
2995 | ||
c6da4cef DE |
2996 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
2997 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); | |
aaa75496 JB |
2998 | |
2999 | free_line_header (lh); | |
3000 | } | |
3001 | ||
348e048f DE |
3002 | static hashval_t |
3003 | hash_type_signature (const void *item) | |
3004 | { | |
3005 | const struct signatured_type *type_sig = item; | |
9a619af0 | 3006 | |
348e048f DE |
3007 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
3008 | return type_sig->signature; | |
3009 | } | |
3010 | ||
3011 | static int | |
3012 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
3013 | { | |
3014 | const struct signatured_type *lhs = item_lhs; | |
3015 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3016 | |
348e048f DE |
3017 | return lhs->signature == rhs->signature; |
3018 | } | |
3019 | ||
1fd400ff TT |
3020 | /* Allocate a hash table for signatured types. */ |
3021 | ||
3022 | static htab_t | |
673bfd45 | 3023 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3024 | { |
3025 | return htab_create_alloc_ex (41, | |
3026 | hash_type_signature, | |
3027 | eq_type_signature, | |
3028 | NULL, | |
3029 | &objfile->objfile_obstack, | |
3030 | hashtab_obstack_allocate, | |
3031 | dummy_obstack_deallocate); | |
3032 | } | |
3033 | ||
3034 | /* A helper function to add a signatured type CU to a list. */ | |
3035 | ||
3036 | static int | |
3037 | add_signatured_type_cu_to_list (void **slot, void *datum) | |
3038 | { | |
3039 | struct signatured_type *sigt = *slot; | |
3040 | struct dwarf2_per_cu_data ***datap = datum; | |
3041 | ||
3042 | **datap = &sigt->per_cu; | |
3043 | ++*datap; | |
3044 | ||
3045 | return 1; | |
3046 | } | |
3047 | ||
348e048f DE |
3048 | /* Create the hash table of all entries in the .debug_types section. |
3049 | The result is zero if there is an error (e.g. missing .debug_types section), | |
3050 | otherwise non-zero. */ | |
3051 | ||
3052 | static int | |
3053 | create_debug_types_hash_table (struct objfile *objfile) | |
3054 | { | |
be391dca | 3055 | gdb_byte *info_ptr; |
348e048f | 3056 | htab_t types_htab; |
1fd400ff | 3057 | struct dwarf2_per_cu_data **iter; |
348e048f | 3058 | |
be391dca TT |
3059 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
3060 | info_ptr = dwarf2_per_objfile->types.buffer; | |
3061 | ||
348e048f DE |
3062 | if (info_ptr == NULL) |
3063 | { | |
3064 | dwarf2_per_objfile->signatured_types = NULL; | |
3065 | return 0; | |
3066 | } | |
3067 | ||
673bfd45 | 3068 | types_htab = allocate_signatured_type_table (objfile); |
348e048f DE |
3069 | |
3070 | if (dwarf2_die_debug) | |
3071 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
3072 | ||
3e43a32a MS |
3073 | while (info_ptr < dwarf2_per_objfile->types.buffer |
3074 | + dwarf2_per_objfile->types.size) | |
348e048f DE |
3075 | { |
3076 | unsigned int offset; | |
3077 | unsigned int offset_size; | |
3078 | unsigned int type_offset; | |
3079 | unsigned int length, initial_length_size; | |
3080 | unsigned short version; | |
3081 | ULONGEST signature; | |
3082 | struct signatured_type *type_sig; | |
3083 | void **slot; | |
3084 | gdb_byte *ptr = info_ptr; | |
3085 | ||
3086 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
3087 | ||
3088 | /* We need to read the type's signature in order to build the hash | |
3089 | table, but we don't need to read anything else just yet. */ | |
3090 | ||
3091 | /* Sanity check to ensure entire cu is present. */ | |
3092 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
3093 | if (ptr + length + initial_length_size | |
3094 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
3095 | { | |
3096 | complaint (&symfile_complaints, | |
3e43a32a MS |
3097 | _("debug type entry runs off end " |
3098 | "of `.debug_types' section, ignored")); | |
348e048f DE |
3099 | break; |
3100 | } | |
3101 | ||
3102 | offset_size = initial_length_size == 4 ? 4 : 8; | |
3103 | ptr += initial_length_size; | |
3104 | version = bfd_get_16 (objfile->obfd, ptr); | |
3105 | ptr += 2; | |
3106 | ptr += offset_size; /* abbrev offset */ | |
3107 | ptr += 1; /* address size */ | |
3108 | signature = bfd_get_64 (objfile->obfd, ptr); | |
3109 | ptr += 8; | |
3110 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
3111 | ||
3112 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
3113 | memset (type_sig, 0, sizeof (*type_sig)); | |
3114 | type_sig->signature = signature; | |
348e048f | 3115 | type_sig->type_offset = type_offset; |
ca1f3406 | 3116 | type_sig->per_cu.objfile = objfile; |
1fd400ff | 3117 | type_sig->per_cu.from_debug_types = 1; |
b3c8eb43 | 3118 | type_sig->per_cu.offset = offset; |
348e048f DE |
3119 | |
3120 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
3121 | gdb_assert (slot != NULL); | |
b3c8eb43 JK |
3122 | if (*slot != NULL) |
3123 | { | |
3124 | const struct signatured_type *dup_sig = *slot; | |
3125 | ||
3126 | complaint (&symfile_complaints, | |
3127 | _("debug type entry at offset 0x%x is duplicate to the " | |
3128 | "entry at offset 0x%x, signature 0x%s"), | |
3129 | offset, dup_sig->per_cu.offset, | |
3130 | phex (signature, sizeof (signature))); | |
3131 | gdb_assert (signature == dup_sig->signature); | |
3132 | } | |
348e048f DE |
3133 | *slot = type_sig; |
3134 | ||
3135 | if (dwarf2_die_debug) | |
3136 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
3137 | offset, phex (signature, sizeof (signature))); | |
3138 | ||
3139 | info_ptr = info_ptr + initial_length_size + length; | |
3140 | } | |
3141 | ||
3142 | dwarf2_per_objfile->signatured_types = types_htab; | |
3143 | ||
1fd400ff TT |
3144 | dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab); |
3145 | dwarf2_per_objfile->type_comp_units | |
3146 | = obstack_alloc (&objfile->objfile_obstack, | |
3147 | dwarf2_per_objfile->n_type_comp_units | |
3148 | * sizeof (struct dwarf2_per_cu_data *)); | |
3149 | iter = &dwarf2_per_objfile->type_comp_units[0]; | |
3150 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter); | |
3151 | gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0] | |
3152 | == dwarf2_per_objfile->n_type_comp_units); | |
3153 | ||
348e048f DE |
3154 | return 1; |
3155 | } | |
3156 | ||
3157 | /* Lookup a signature based type. | |
3158 | Returns NULL if SIG is not present in the table. */ | |
3159 | ||
3160 | static struct signatured_type * | |
3161 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
3162 | { | |
3163 | struct signatured_type find_entry, *entry; | |
3164 | ||
3165 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3166 | { | |
3167 | complaint (&symfile_complaints, | |
55f1336d | 3168 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
348e048f DE |
3169 | return 0; |
3170 | } | |
3171 | ||
3172 | find_entry.signature = sig; | |
3173 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3174 | return entry; | |
3175 | } | |
3176 | ||
d85a05f0 DJ |
3177 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3178 | ||
3179 | static void | |
3180 | init_cu_die_reader (struct die_reader_specs *reader, | |
3181 | struct dwarf2_cu *cu) | |
3182 | { | |
3183 | reader->abfd = cu->objfile->obfd; | |
3184 | reader->cu = cu; | |
3185 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
3186 | { |
3187 | gdb_assert (dwarf2_per_objfile->types.readin); | |
3188 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
3189 | } | |
d85a05f0 | 3190 | else |
be391dca TT |
3191 | { |
3192 | gdb_assert (dwarf2_per_objfile->info.readin); | |
3193 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
3194 | } | |
d85a05f0 DJ |
3195 | } |
3196 | ||
3197 | /* Find the base address of the compilation unit for range lists and | |
3198 | location lists. It will normally be specified by DW_AT_low_pc. | |
3199 | In DWARF-3 draft 4, the base address could be overridden by | |
3200 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3201 | compilation units with discontinuous ranges. */ | |
3202 | ||
3203 | static void | |
3204 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3205 | { | |
3206 | struct attribute *attr; | |
3207 | ||
3208 | cu->base_known = 0; | |
3209 | cu->base_address = 0; | |
3210 | ||
3211 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3212 | if (attr) | |
3213 | { | |
3214 | cu->base_address = DW_ADDR (attr); | |
3215 | cu->base_known = 1; | |
3216 | } | |
3217 | else | |
3218 | { | |
3219 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3220 | if (attr) | |
3221 | { | |
3222 | cu->base_address = DW_ADDR (attr); | |
3223 | cu->base_known = 1; | |
3224 | } | |
3225 | } | |
3226 | } | |
3227 | ||
348e048f DE |
3228 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
3229 | to combine the common parts. | |
93311388 | 3230 | Process a compilation unit for a psymtab. |
348e048f DE |
3231 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
3232 | either .debug_info or debug_types. | |
93311388 DE |
3233 | INFO_PTR is a pointer to the start of the CU. |
3234 | Returns a pointer to the next CU. */ | |
aaa75496 | 3235 | |
93311388 DE |
3236 | static gdb_byte * |
3237 | process_psymtab_comp_unit (struct objfile *objfile, | |
3238 | struct dwarf2_per_cu_data *this_cu, | |
3239 | gdb_byte *buffer, gdb_byte *info_ptr, | |
3240 | unsigned int buffer_size) | |
c906108c | 3241 | { |
c906108c | 3242 | bfd *abfd = objfile->obfd; |
93311388 | 3243 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3244 | struct die_info *comp_unit_die; |
c906108c | 3245 | struct partial_symtab *pst; |
5734ee8b | 3246 | CORE_ADDR baseaddr; |
93311388 DE |
3247 | struct cleanup *back_to_inner; |
3248 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3249 | int has_children, has_pc_info; |
3250 | struct attribute *attr; | |
d85a05f0 DJ |
3251 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3252 | struct die_reader_specs reader_specs; | |
3e2a0cee | 3253 | const char *filename; |
c906108c | 3254 | |
9816fde3 | 3255 | init_one_comp_unit (&cu, objfile); |
93311388 | 3256 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3257 | |
93311388 DE |
3258 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
3259 | buffer, buffer_size, | |
3260 | abfd); | |
10b3939b | 3261 | |
93311388 DE |
3262 | /* Complete the cu_header. */ |
3263 | cu.header.offset = beg_of_comp_unit - buffer; | |
3264 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 3265 | |
93311388 | 3266 | cu.list_in_scope = &file_symbols; |
af703f96 | 3267 | |
328c9494 DJ |
3268 | /* If this compilation unit was already read in, free the |
3269 | cached copy in order to read it in again. This is | |
3270 | necessary because we skipped some symbols when we first | |
3271 | read in the compilation unit (see load_partial_dies). | |
3272 | This problem could be avoided, but the benefit is | |
3273 | unclear. */ | |
3274 | if (this_cu->cu != NULL) | |
3275 | free_one_cached_comp_unit (this_cu->cu); | |
3276 | ||
3277 | /* Note that this is a pointer to our stack frame, being | |
3278 | added to a global data structure. It will be cleaned up | |
3279 | in free_stack_comp_unit when we finish with this | |
3280 | compilation unit. */ | |
3281 | this_cu->cu = &cu; | |
d85a05f0 DJ |
3282 | cu.per_cu = this_cu; |
3283 | ||
93311388 DE |
3284 | /* Read the abbrevs for this compilation unit into a table. */ |
3285 | dwarf2_read_abbrevs (abfd, &cu); | |
3286 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 3287 | |
93311388 | 3288 | /* Read the compilation unit die. */ |
348e048f DE |
3289 | if (this_cu->from_debug_types) |
3290 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
3291 | init_cu_die_reader (&reader_specs, &cu); |
3292 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3293 | &has_children); | |
93311388 | 3294 | |
348e048f DE |
3295 | if (this_cu->from_debug_types) |
3296 | { | |
b3c8eb43 JK |
3297 | /* LENGTH has not been set yet for type units. */ |
3298 | gdb_assert (this_cu->offset == cu.header.offset); | |
348e048f DE |
3299 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
3300 | } | |
d85a05f0 | 3301 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3302 | { |
93311388 DE |
3303 | info_ptr = (beg_of_comp_unit + cu.header.length |
3304 | + cu.header.initial_length_size); | |
3305 | do_cleanups (back_to_inner); | |
3306 | return info_ptr; | |
3307 | } | |
72bf9492 | 3308 | |
9816fde3 | 3309 | prepare_one_comp_unit (&cu, comp_unit_die); |
c906108c | 3310 | |
93311388 | 3311 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3312 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
3e2a0cee TT |
3313 | if (attr == NULL || !DW_STRING (attr)) |
3314 | filename = ""; | |
3315 | else | |
3316 | filename = DW_STRING (attr); | |
93311388 | 3317 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3318 | filename, |
93311388 DE |
3319 | /* TEXTLOW and TEXTHIGH are set below. */ |
3320 | 0, | |
3321 | objfile->global_psymbols.next, | |
3322 | objfile->static_psymbols.next); | |
72bf9492 | 3323 | |
d85a05f0 DJ |
3324 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3325 | if (attr != NULL) | |
3326 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3327 | |
e38df1d0 | 3328 | pst->read_symtab_private = this_cu; |
72bf9492 | 3329 | |
93311388 | 3330 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3331 | |
0963b4bd | 3332 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3333 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3334 | |
9291a0cd | 3335 | this_cu->v.psymtab = pst; |
c906108c | 3336 | |
d85a05f0 DJ |
3337 | dwarf2_find_base_address (comp_unit_die, &cu); |
3338 | ||
93311388 DE |
3339 | /* Possibly set the default values of LOWPC and HIGHPC from |
3340 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3341 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3342 | &best_highpc, &cu, pst); | |
3343 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3344 | /* Store the contiguous range if it is not empty; it can be empty for |
3345 | CUs with no code. */ | |
3346 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3347 | best_lowpc + baseaddr, |
3348 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3349 | |
3350 | /* Check if comp unit has_children. | |
3351 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3352 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3353 | if (has_children) |
93311388 DE |
3354 | { |
3355 | struct partial_die_info *first_die; | |
3356 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3357 | |
93311388 DE |
3358 | lowpc = ((CORE_ADDR) -1); |
3359 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3360 | |
93311388 | 3361 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3362 | |
93311388 | 3363 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3364 | ! has_pc_info, &cu); |
57c22c6c | 3365 | |
93311388 DE |
3366 | /* If we didn't find a lowpc, set it to highpc to avoid |
3367 | complaints from `maint check'. */ | |
3368 | if (lowpc == ((CORE_ADDR) -1)) | |
3369 | lowpc = highpc; | |
10b3939b | 3370 | |
93311388 DE |
3371 | /* If the compilation unit didn't have an explicit address range, |
3372 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3373 | if (! has_pc_info) |
93311388 | 3374 | { |
d85a05f0 DJ |
3375 | best_lowpc = lowpc; |
3376 | best_highpc = highpc; | |
93311388 DE |
3377 | } |
3378 | } | |
d85a05f0 DJ |
3379 | pst->textlow = best_lowpc + baseaddr; |
3380 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3381 | |
93311388 DE |
3382 | pst->n_global_syms = objfile->global_psymbols.next - |
3383 | (objfile->global_psymbols.list + pst->globals_offset); | |
3384 | pst->n_static_syms = objfile->static_psymbols.next - | |
3385 | (objfile->static_psymbols.list + pst->statics_offset); | |
3386 | sort_pst_symbols (pst); | |
c906108c | 3387 | |
93311388 DE |
3388 | info_ptr = (beg_of_comp_unit + cu.header.length |
3389 | + cu.header.initial_length_size); | |
ae038cb0 | 3390 | |
348e048f DE |
3391 | if (this_cu->from_debug_types) |
3392 | { | |
3393 | /* It's not clear we want to do anything with stmt lists here. | |
3394 | Waiting to see what gcc ultimately does. */ | |
3395 | } | |
d85a05f0 | 3396 | else |
93311388 DE |
3397 | { |
3398 | /* Get the list of files included in the current compilation unit, | |
3399 | and build a psymtab for each of them. */ | |
d85a05f0 | 3400 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3401 | } |
ae038cb0 | 3402 | |
93311388 | 3403 | do_cleanups (back_to_inner); |
ae038cb0 | 3404 | |
93311388 DE |
3405 | return info_ptr; |
3406 | } | |
ff013f42 | 3407 | |
348e048f DE |
3408 | /* Traversal function for htab_traverse_noresize. |
3409 | Process one .debug_types comp-unit. */ | |
3410 | ||
3411 | static int | |
3412 | process_type_comp_unit (void **slot, void *info) | |
3413 | { | |
3414 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
3415 | struct objfile *objfile = (struct objfile *) info; | |
3416 | struct dwarf2_per_cu_data *this_cu; | |
3417 | ||
3418 | this_cu = &entry->per_cu; | |
348e048f | 3419 | |
be391dca | 3420 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
3421 | process_psymtab_comp_unit (objfile, this_cu, |
3422 | dwarf2_per_objfile->types.buffer, | |
b3c8eb43 | 3423 | dwarf2_per_objfile->types.buffer + this_cu->offset, |
348e048f DE |
3424 | dwarf2_per_objfile->types.size); |
3425 | ||
3426 | return 1; | |
3427 | } | |
3428 | ||
3429 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3430 | Build partial symbol tables for the .debug_types comp-units. */ | |
3431 | ||
3432 | static void | |
3433 | build_type_psymtabs (struct objfile *objfile) | |
3434 | { | |
3435 | if (! create_debug_types_hash_table (objfile)) | |
3436 | return; | |
3437 | ||
3438 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
3439 | process_type_comp_unit, objfile); | |
3440 | } | |
3441 | ||
60606b2c TT |
3442 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3443 | ||
3444 | static void | |
3445 | psymtabs_addrmap_cleanup (void *o) | |
3446 | { | |
3447 | struct objfile *objfile = o; | |
ec61707d | 3448 | |
60606b2c TT |
3449 | objfile->psymtabs_addrmap = NULL; |
3450 | } | |
3451 | ||
93311388 DE |
3452 | /* Build the partial symbol table by doing a quick pass through the |
3453 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3454 | |
93311388 | 3455 | static void |
c67a9c90 | 3456 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3457 | { |
93311388 | 3458 | gdb_byte *info_ptr; |
60606b2c TT |
3459 | struct cleanup *back_to, *addrmap_cleanup; |
3460 | struct obstack temp_obstack; | |
93311388 | 3461 | |
98bfdba5 PA |
3462 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3463 | ||
be391dca | 3464 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3465 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3466 | |
93311388 DE |
3467 | /* Any cached compilation units will be linked by the per-objfile |
3468 | read_in_chain. Make sure to free them when we're done. */ | |
3469 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3470 | |
348e048f DE |
3471 | build_type_psymtabs (objfile); |
3472 | ||
93311388 | 3473 | create_all_comp_units (objfile); |
c906108c | 3474 | |
60606b2c TT |
3475 | /* Create a temporary address map on a temporary obstack. We later |
3476 | copy this to the final obstack. */ | |
3477 | obstack_init (&temp_obstack); | |
3478 | make_cleanup_obstack_free (&temp_obstack); | |
3479 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3480 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3481 | |
93311388 DE |
3482 | /* Since the objects we're extracting from .debug_info vary in |
3483 | length, only the individual functions to extract them (like | |
3484 | read_comp_unit_head and load_partial_die) can really know whether | |
3485 | the buffer is large enough to hold another complete object. | |
c906108c | 3486 | |
93311388 DE |
3487 | At the moment, they don't actually check that. If .debug_info |
3488 | holds just one extra byte after the last compilation unit's dies, | |
3489 | then read_comp_unit_head will happily read off the end of the | |
3490 | buffer. read_partial_die is similarly casual. Those functions | |
3491 | should be fixed. | |
c906108c | 3492 | |
93311388 DE |
3493 | For this loop condition, simply checking whether there's any data |
3494 | left at all should be sufficient. */ | |
c906108c | 3495 | |
93311388 DE |
3496 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3497 | + dwarf2_per_objfile->info.size)) | |
3498 | { | |
3499 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3500 | |
3e43a32a MS |
3501 | this_cu = dwarf2_find_comp_unit (info_ptr |
3502 | - dwarf2_per_objfile->info.buffer, | |
93311388 | 3503 | objfile); |
aaa75496 | 3504 | |
93311388 DE |
3505 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3506 | dwarf2_per_objfile->info.buffer, | |
3507 | info_ptr, | |
3508 | dwarf2_per_objfile->info.size); | |
c906108c | 3509 | } |
ff013f42 JK |
3510 | |
3511 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3512 | &objfile->objfile_obstack); | |
60606b2c | 3513 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3514 | |
ae038cb0 DJ |
3515 | do_cleanups (back_to); |
3516 | } | |
3517 | ||
93311388 | 3518 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3519 | |
3520 | static void | |
93311388 DE |
3521 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3522 | struct objfile *objfile) | |
ae038cb0 DJ |
3523 | { |
3524 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 3525 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 3526 | struct die_info *comp_unit_die; |
ae038cb0 | 3527 | struct dwarf2_cu *cu; |
1d9ec526 | 3528 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3529 | int has_children; |
3530 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3531 | int read_cu = 0; |
ae038cb0 | 3532 | |
348e048f DE |
3533 | gdb_assert (! this_cu->from_debug_types); |
3534 | ||
be391dca | 3535 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3536 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
3537 | beg_of_comp_unit = info_ptr; |
3538 | ||
98bfdba5 PA |
3539 | if (this_cu->cu == NULL) |
3540 | { | |
9816fde3 JK |
3541 | cu = xmalloc (sizeof (*cu)); |
3542 | init_one_comp_unit (cu, objfile); | |
ae038cb0 | 3543 | |
98bfdba5 | 3544 | read_cu = 1; |
ae038cb0 | 3545 | |
98bfdba5 PA |
3546 | /* If an error occurs while loading, release our storage. */ |
3547 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
328c9494 | 3548 | |
98bfdba5 PA |
3549 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3550 | dwarf2_per_objfile->info.buffer, | |
3551 | dwarf2_per_objfile->info.size, | |
3552 | abfd); | |
ae038cb0 | 3553 | |
98bfdba5 PA |
3554 | /* Complete the cu_header. */ |
3555 | cu->header.offset = this_cu->offset; | |
3556 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3557 | ||
3558 | /* Link this compilation unit into the compilation unit tree. */ | |
3559 | this_cu->cu = cu; | |
3560 | cu->per_cu = this_cu; | |
98bfdba5 PA |
3561 | |
3562 | /* Link this CU into read_in_chain. */ | |
3563 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3564 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3565 | } | |
3566 | else | |
3567 | { | |
3568 | cu = this_cu->cu; | |
3569 | info_ptr += cu->header.first_die_offset; | |
3570 | } | |
ae038cb0 DJ |
3571 | |
3572 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3573 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
ae038cb0 | 3574 | dwarf2_read_abbrevs (abfd, cu); |
98bfdba5 | 3575 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3576 | |
3577 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3578 | init_cu_die_reader (&reader_specs, cu); |
3579 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3580 | &has_children); | |
ae038cb0 | 3581 | |
9816fde3 | 3582 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3583 | |
ae038cb0 DJ |
3584 | /* Check if comp unit has_children. |
3585 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3586 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3587 | if (has_children) |
93311388 | 3588 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 | 3589 | |
98bfdba5 PA |
3590 | do_cleanups (free_abbrevs_cleanup); |
3591 | ||
3592 | if (read_cu) | |
3593 | { | |
3594 | /* We've successfully allocated this compilation unit. Let our | |
3595 | caller clean it up when finished with it. */ | |
3596 | discard_cleanups (free_cu_cleanup); | |
3597 | } | |
ae038cb0 DJ |
3598 | } |
3599 | ||
3600 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3601 | if an inter-comp-unit reference is found; presumably if there is one, | |
3602 | there will be many, and one will occur early in the .debug_info section. | |
3603 | So there's no point in building this list incrementally. */ | |
3604 | ||
3605 | static void | |
3606 | create_all_comp_units (struct objfile *objfile) | |
3607 | { | |
3608 | int n_allocated; | |
3609 | int n_comp_units; | |
3610 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3611 | gdb_byte *info_ptr; |
3612 | ||
3613 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3614 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3615 | |
3616 | n_comp_units = 0; | |
3617 | n_allocated = 10; | |
3618 | all_comp_units = xmalloc (n_allocated | |
3619 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3620 | |
3e43a32a MS |
3621 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3622 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3623 | { |
c764a876 | 3624 | unsigned int length, initial_length_size; |
ae038cb0 | 3625 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3626 | unsigned int offset; |
ae038cb0 | 3627 | |
dce234bc | 3628 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3629 | |
3630 | /* Read just enough information to find out where the next | |
3631 | compilation unit is. */ | |
c764a876 DE |
3632 | length = read_initial_length (objfile->obfd, info_ptr, |
3633 | &initial_length_size); | |
ae038cb0 DJ |
3634 | |
3635 | /* Save the compilation unit for later lookup. */ | |
3636 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3637 | sizeof (struct dwarf2_per_cu_data)); | |
3638 | memset (this_cu, 0, sizeof (*this_cu)); | |
3639 | this_cu->offset = offset; | |
c764a876 | 3640 | this_cu->length = length + initial_length_size; |
9291a0cd | 3641 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3642 | |
3643 | if (n_comp_units == n_allocated) | |
3644 | { | |
3645 | n_allocated *= 2; | |
3646 | all_comp_units = xrealloc (all_comp_units, | |
3647 | n_allocated | |
3648 | * sizeof (struct dwarf2_per_cu_data *)); | |
3649 | } | |
3650 | all_comp_units[n_comp_units++] = this_cu; | |
3651 | ||
3652 | info_ptr = info_ptr + this_cu->length; | |
3653 | } | |
3654 | ||
3655 | dwarf2_per_objfile->all_comp_units | |
3656 | = obstack_alloc (&objfile->objfile_obstack, | |
3657 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3658 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3659 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3660 | xfree (all_comp_units); | |
3661 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3662 | } |
3663 | ||
5734ee8b DJ |
3664 | /* Process all loaded DIEs for compilation unit CU, starting at |
3665 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3666 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3667 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3668 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3669 | and record the covered ranges in the addrmap. */ | |
c906108c | 3670 | |
72bf9492 DJ |
3671 | static void |
3672 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3673 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3674 | { |
72bf9492 | 3675 | struct partial_die_info *pdi; |
c906108c | 3676 | |
91c24f0a DC |
3677 | /* Now, march along the PDI's, descending into ones which have |
3678 | interesting children but skipping the children of the other ones, | |
3679 | until we reach the end of the compilation unit. */ | |
c906108c | 3680 | |
72bf9492 | 3681 | pdi = first_die; |
91c24f0a | 3682 | |
72bf9492 DJ |
3683 | while (pdi != NULL) |
3684 | { | |
3685 | fixup_partial_die (pdi, cu); | |
c906108c | 3686 | |
f55ee35c | 3687 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3688 | children, so we need to look at them. Ditto for anonymous |
3689 | enums. */ | |
933c6fe4 | 3690 | |
72bf9492 | 3691 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3692 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3693 | { |
72bf9492 | 3694 | switch (pdi->tag) |
c906108c SS |
3695 | { |
3696 | case DW_TAG_subprogram: | |
5734ee8b | 3697 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 3698 | break; |
72929c62 | 3699 | case DW_TAG_constant: |
c906108c SS |
3700 | case DW_TAG_variable: |
3701 | case DW_TAG_typedef: | |
91c24f0a | 3702 | case DW_TAG_union_type: |
72bf9492 | 3703 | if (!pdi->is_declaration) |
63d06c5c | 3704 | { |
72bf9492 | 3705 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3706 | } |
3707 | break; | |
c906108c | 3708 | case DW_TAG_class_type: |
680b30c7 | 3709 | case DW_TAG_interface_type: |
c906108c | 3710 | case DW_TAG_structure_type: |
72bf9492 | 3711 | if (!pdi->is_declaration) |
c906108c | 3712 | { |
72bf9492 | 3713 | add_partial_symbol (pdi, cu); |
c906108c SS |
3714 | } |
3715 | break; | |
91c24f0a | 3716 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3717 | if (!pdi->is_declaration) |
3718 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3719 | break; |
3720 | case DW_TAG_base_type: | |
a02abb62 | 3721 | case DW_TAG_subrange_type: |
c906108c | 3722 | /* File scope base type definitions are added to the partial |
c5aa993b | 3723 | symbol table. */ |
72bf9492 | 3724 | add_partial_symbol (pdi, cu); |
c906108c | 3725 | break; |
d9fa45fe | 3726 | case DW_TAG_namespace: |
5734ee8b | 3727 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3728 | break; |
5d7cb8df JK |
3729 | case DW_TAG_module: |
3730 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3731 | break; | |
c906108c SS |
3732 | default: |
3733 | break; | |
3734 | } | |
3735 | } | |
3736 | ||
72bf9492 DJ |
3737 | /* If the die has a sibling, skip to the sibling. */ |
3738 | ||
3739 | pdi = pdi->die_sibling; | |
3740 | } | |
3741 | } | |
3742 | ||
3743 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3744 | |
72bf9492 | 3745 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3746 | name is concatenated with "::" and the partial DIE's name. For |
3747 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3748 | Enumerators are an exception; they use the scope of their parent |
3749 | enumeration type, i.e. the name of the enumeration type is not | |
3750 | prepended to the enumerator. | |
91c24f0a | 3751 | |
72bf9492 DJ |
3752 | There are two complexities. One is DW_AT_specification; in this |
3753 | case "parent" means the parent of the target of the specification, | |
3754 | instead of the direct parent of the DIE. The other is compilers | |
3755 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3756 | the fully qualified name of structure types from their members' | |
3757 | linkage names. This must be done using the DIE's children rather | |
3758 | than the children of any DW_AT_specification target. We only need | |
3759 | to do this for structures at the top level, i.e. if the target of | |
3760 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3761 | have a parent. */ | |
3762 | ||
3763 | /* Compute the scope prefix associated with PDI's parent, in | |
3764 | compilation unit CU. The result will be allocated on CU's | |
3765 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3766 | field. NULL is returned if no prefix is necessary. */ | |
3767 | static char * | |
3768 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3769 | struct dwarf2_cu *cu) | |
3770 | { | |
3771 | char *grandparent_scope; | |
3772 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3773 | |
72bf9492 DJ |
3774 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3775 | then this means the parent of the specification DIE. */ | |
3776 | ||
3777 | real_pdi = pdi; | |
72bf9492 | 3778 | while (real_pdi->has_specification) |
10b3939b | 3779 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3780 | |
3781 | parent = real_pdi->die_parent; | |
3782 | if (parent == NULL) | |
3783 | return NULL; | |
3784 | ||
3785 | if (parent->scope_set) | |
3786 | return parent->scope; | |
3787 | ||
3788 | fixup_partial_die (parent, cu); | |
3789 | ||
10b3939b | 3790 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3791 | |
acebe513 UW |
3792 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3793 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3794 | Work around this problem here. */ | |
3795 | if (cu->language == language_cplus | |
6e70227d | 3796 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3797 | && strcmp (parent->name, "::") == 0 |
3798 | && grandparent_scope == NULL) | |
3799 | { | |
3800 | parent->scope = NULL; | |
3801 | parent->scope_set = 1; | |
3802 | return NULL; | |
3803 | } | |
3804 | ||
72bf9492 | 3805 | if (parent->tag == DW_TAG_namespace |
f55ee35c | 3806 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3807 | || parent->tag == DW_TAG_structure_type |
3808 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3809 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3810 | || parent->tag == DW_TAG_union_type |
3811 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3812 | { |
3813 | if (grandparent_scope == NULL) | |
3814 | parent->scope = parent->name; | |
3815 | else | |
3e43a32a MS |
3816 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
3817 | grandparent_scope, | |
f55ee35c | 3818 | parent->name, 0, cu); |
72bf9492 | 3819 | } |
ceeb3d5a | 3820 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
3821 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
3822 | parent->scope = grandparent_scope; | |
3823 | else | |
3824 | { | |
3825 | /* FIXME drow/2004-04-01: What should we be doing with | |
3826 | function-local names? For partial symbols, we should probably be | |
3827 | ignoring them. */ | |
3828 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3829 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3830 | parent->tag, pdi->offset); |
3831 | parent->scope = grandparent_scope; | |
c906108c SS |
3832 | } |
3833 | ||
72bf9492 DJ |
3834 | parent->scope_set = 1; |
3835 | return parent->scope; | |
3836 | } | |
3837 | ||
3838 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3839 | CU. The result will be allocated with malloc. */ | |
3840 | static char * | |
3841 | partial_die_full_name (struct partial_die_info *pdi, | |
3842 | struct dwarf2_cu *cu) | |
3843 | { | |
3844 | char *parent_scope; | |
3845 | ||
98bfdba5 PA |
3846 | /* If this is a template instantiation, we can not work out the |
3847 | template arguments from partial DIEs. So, unfortunately, we have | |
3848 | to go through the full DIEs. At least any work we do building | |
3849 | types here will be reused if full symbols are loaded later. */ | |
3850 | if (pdi->has_template_arguments) | |
3851 | { | |
3852 | fixup_partial_die (pdi, cu); | |
3853 | ||
3854 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3855 | { | |
3856 | struct die_info *die; | |
3857 | struct attribute attr; | |
3858 | struct dwarf2_cu *ref_cu = cu; | |
3859 | ||
3860 | attr.name = 0; | |
3861 | attr.form = DW_FORM_ref_addr; | |
3862 | attr.u.addr = pdi->offset; | |
3863 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3864 | ||
3865 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3866 | } | |
3867 | } | |
3868 | ||
72bf9492 DJ |
3869 | parent_scope = partial_die_parent_scope (pdi, cu); |
3870 | if (parent_scope == NULL) | |
3871 | return NULL; | |
3872 | else | |
f55ee35c | 3873 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3874 | } |
3875 | ||
3876 | static void | |
72bf9492 | 3877 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3878 | { |
e7c27a73 | 3879 | struct objfile *objfile = cu->objfile; |
c906108c | 3880 | CORE_ADDR addr = 0; |
decbce07 | 3881 | char *actual_name = NULL; |
5c4e30ca | 3882 | const struct partial_symbol *psym = NULL; |
e142c38c | 3883 | CORE_ADDR baseaddr; |
72bf9492 | 3884 | int built_actual_name = 0; |
e142c38c DJ |
3885 | |
3886 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3887 | |
94af9270 KS |
3888 | actual_name = partial_die_full_name (pdi, cu); |
3889 | if (actual_name) | |
3890 | built_actual_name = 1; | |
63d06c5c | 3891 | |
72bf9492 DJ |
3892 | if (actual_name == NULL) |
3893 | actual_name = pdi->name; | |
3894 | ||
c906108c SS |
3895 | switch (pdi->tag) |
3896 | { | |
3897 | case DW_TAG_subprogram: | |
2cfa0c8d | 3898 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3899 | { |
2cfa0c8d JB |
3900 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3901 | of the global scope. But in Ada, we want to be able to access | |
3902 | nested procedures globally. So all Ada subprograms are stored | |
3903 | in the global scope. */ | |
f47fb265 | 3904 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3905 | mst_text, objfile); */ |
f47fb265 MS |
3906 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3907 | built_actual_name, | |
3908 | VAR_DOMAIN, LOC_BLOCK, | |
3909 | &objfile->global_psymbols, | |
3910 | 0, pdi->lowpc + baseaddr, | |
3911 | cu->language, objfile); | |
c906108c SS |
3912 | } |
3913 | else | |
3914 | { | |
f47fb265 | 3915 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3916 | mst_file_text, objfile); */ |
f47fb265 MS |
3917 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3918 | built_actual_name, | |
3919 | VAR_DOMAIN, LOC_BLOCK, | |
3920 | &objfile->static_psymbols, | |
3921 | 0, pdi->lowpc + baseaddr, | |
3922 | cu->language, objfile); | |
c906108c SS |
3923 | } |
3924 | break; | |
72929c62 JB |
3925 | case DW_TAG_constant: |
3926 | { | |
3927 | struct psymbol_allocation_list *list; | |
3928 | ||
3929 | if (pdi->is_external) | |
3930 | list = &objfile->global_psymbols; | |
3931 | else | |
3932 | list = &objfile->static_psymbols; | |
f47fb265 MS |
3933 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3934 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
3935 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
3936 | } |
3937 | break; | |
c906108c | 3938 | case DW_TAG_variable: |
caac4577 JG |
3939 | if (pdi->locdesc) |
3940 | addr = decode_locdesc (pdi->locdesc, cu); | |
3941 | ||
3942 | if (pdi->locdesc | |
3943 | && addr == 0 | |
3944 | && !dwarf2_per_objfile->has_section_at_zero) | |
3945 | { | |
3946 | /* A global or static variable may also have been stripped | |
3947 | out by the linker if unused, in which case its address | |
3948 | will be nullified; do not add such variables into partial | |
3949 | symbol table then. */ | |
3950 | } | |
3951 | else if (pdi->is_external) | |
c906108c SS |
3952 | { |
3953 | /* Global Variable. | |
3954 | Don't enter into the minimal symbol tables as there is | |
3955 | a minimal symbol table entry from the ELF symbols already. | |
3956 | Enter into partial symbol table if it has a location | |
3957 | descriptor or a type. | |
3958 | If the location descriptor is missing, new_symbol will create | |
3959 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
3960 | be determined from the minimal symbol table whenever the variable | |
3961 | is referenced. | |
3962 | The address for the partial symbol table entry is not | |
3963 | used by GDB, but it comes in handy for debugging partial symbol | |
3964 | table building. */ | |
3965 | ||
c906108c | 3966 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
3967 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3968 | built_actual_name, | |
3969 | VAR_DOMAIN, LOC_STATIC, | |
3970 | &objfile->global_psymbols, | |
3971 | 0, addr + baseaddr, | |
3972 | cu->language, objfile); | |
c906108c SS |
3973 | } |
3974 | else | |
3975 | { | |
0963b4bd | 3976 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 3977 | if (pdi->locdesc == NULL) |
decbce07 MS |
3978 | { |
3979 | if (built_actual_name) | |
3980 | xfree (actual_name); | |
3981 | return; | |
3982 | } | |
f47fb265 | 3983 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 3984 | mst_file_data, objfile); */ |
f47fb265 MS |
3985 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3986 | built_actual_name, | |
3987 | VAR_DOMAIN, LOC_STATIC, | |
3988 | &objfile->static_psymbols, | |
3989 | 0, addr + baseaddr, | |
3990 | cu->language, objfile); | |
c906108c SS |
3991 | } |
3992 | break; | |
3993 | case DW_TAG_typedef: | |
3994 | case DW_TAG_base_type: | |
a02abb62 | 3995 | case DW_TAG_subrange_type: |
38d518c9 | 3996 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3997 | built_actual_name, |
176620f1 | 3998 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 3999 | &objfile->static_psymbols, |
e142c38c | 4000 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4001 | break; |
72bf9492 DJ |
4002 | case DW_TAG_namespace: |
4003 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4004 | built_actual_name, |
72bf9492 DJ |
4005 | VAR_DOMAIN, LOC_TYPEDEF, |
4006 | &objfile->global_psymbols, | |
4007 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4008 | break; | |
c906108c | 4009 | case DW_TAG_class_type: |
680b30c7 | 4010 | case DW_TAG_interface_type: |
c906108c SS |
4011 | case DW_TAG_structure_type: |
4012 | case DW_TAG_union_type: | |
4013 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4014 | /* Skip external references. The DWARF standard says in the section |
4015 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4016 | structure, union or class type is represented by a structure, | |
4017 | union or class entry that does not have a byte size attribute | |
4018 | and that has a DW_AT_declaration attribute." */ | |
4019 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4020 | { |
4021 | if (built_actual_name) | |
4022 | xfree (actual_name); | |
4023 | return; | |
4024 | } | |
fa4028e9 | 4025 | |
63d06c5c DC |
4026 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4027 | static vs. global. */ | |
38d518c9 | 4028 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4029 | built_actual_name, |
176620f1 | 4030 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4031 | (cu->language == language_cplus |
4032 | || cu->language == language_java) | |
63d06c5c DC |
4033 | ? &objfile->global_psymbols |
4034 | : &objfile->static_psymbols, | |
e142c38c | 4035 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4036 | |
c906108c SS |
4037 | break; |
4038 | case DW_TAG_enumerator: | |
38d518c9 | 4039 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4040 | built_actual_name, |
176620f1 | 4041 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4042 | (cu->language == language_cplus |
4043 | || cu->language == language_java) | |
f6fe98ef DJ |
4044 | ? &objfile->global_psymbols |
4045 | : &objfile->static_psymbols, | |
e142c38c | 4046 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4047 | break; |
4048 | default: | |
4049 | break; | |
4050 | } | |
5c4e30ca | 4051 | |
72bf9492 DJ |
4052 | if (built_actual_name) |
4053 | xfree (actual_name); | |
c906108c SS |
4054 | } |
4055 | ||
5c4e30ca DC |
4056 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4057 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4058 | the name of the enclosing namespace. */ | |
91c24f0a | 4059 | |
72bf9492 DJ |
4060 | static void |
4061 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4062 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4063 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4064 | { |
72bf9492 | 4065 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4066 | |
72bf9492 | 4067 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4068 | |
4069 | /* Now scan partial symbols in that namespace. */ | |
4070 | ||
91c24f0a | 4071 | if (pdi->has_children) |
5734ee8b | 4072 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4073 | } |
4074 | ||
5d7cb8df JK |
4075 | /* Read a partial die corresponding to a Fortran module. */ |
4076 | ||
4077 | static void | |
4078 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4079 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4080 | { | |
f55ee35c | 4081 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4082 | |
4083 | if (pdi->has_children) | |
4084 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4085 | } | |
4086 | ||
bc30ff58 JB |
4087 | /* Read a partial die corresponding to a subprogram and create a partial |
4088 | symbol for that subprogram. When the CU language allows it, this | |
4089 | routine also defines a partial symbol for each nested subprogram | |
4090 | that this subprogram contains. | |
6e70227d | 4091 | |
bc30ff58 JB |
4092 | DIE my also be a lexical block, in which case we simply search |
4093 | recursively for suprograms defined inside that lexical block. | |
4094 | Again, this is only performed when the CU language allows this | |
4095 | type of definitions. */ | |
4096 | ||
4097 | static void | |
4098 | add_partial_subprogram (struct partial_die_info *pdi, | |
4099 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4100 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4101 | { |
4102 | if (pdi->tag == DW_TAG_subprogram) | |
4103 | { | |
4104 | if (pdi->has_pc_info) | |
4105 | { | |
4106 | if (pdi->lowpc < *lowpc) | |
4107 | *lowpc = pdi->lowpc; | |
4108 | if (pdi->highpc > *highpc) | |
4109 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4110 | if (need_pc) |
4111 | { | |
4112 | CORE_ADDR baseaddr; | |
4113 | struct objfile *objfile = cu->objfile; | |
4114 | ||
4115 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4116 | SECT_OFF_TEXT (objfile)); | |
4117 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4118 | pdi->lowpc + baseaddr, |
4119 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4120 | cu->per_cu->v.psymtab); |
5734ee8b | 4121 | } |
bc30ff58 | 4122 | if (!pdi->is_declaration) |
e8d05480 JB |
4123 | /* Ignore subprogram DIEs that do not have a name, they are |
4124 | illegal. Do not emit a complaint at this point, we will | |
4125 | do so when we convert this psymtab into a symtab. */ | |
4126 | if (pdi->name) | |
4127 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4128 | } |
4129 | } | |
6e70227d | 4130 | |
bc30ff58 JB |
4131 | if (! pdi->has_children) |
4132 | return; | |
4133 | ||
4134 | if (cu->language == language_ada) | |
4135 | { | |
4136 | pdi = pdi->die_child; | |
4137 | while (pdi != NULL) | |
4138 | { | |
4139 | fixup_partial_die (pdi, cu); | |
4140 | if (pdi->tag == DW_TAG_subprogram | |
4141 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4142 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4143 | pdi = pdi->die_sibling; |
4144 | } | |
4145 | } | |
4146 | } | |
4147 | ||
91c24f0a DC |
4148 | /* Read a partial die corresponding to an enumeration type. */ |
4149 | ||
72bf9492 DJ |
4150 | static void |
4151 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4152 | struct dwarf2_cu *cu) | |
91c24f0a | 4153 | { |
72bf9492 | 4154 | struct partial_die_info *pdi; |
91c24f0a DC |
4155 | |
4156 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4157 | add_partial_symbol (enum_pdi, cu); |
4158 | ||
4159 | pdi = enum_pdi->die_child; | |
4160 | while (pdi) | |
91c24f0a | 4161 | { |
72bf9492 | 4162 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4163 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4164 | else |
72bf9492 DJ |
4165 | add_partial_symbol (pdi, cu); |
4166 | pdi = pdi->die_sibling; | |
91c24f0a | 4167 | } |
91c24f0a DC |
4168 | } |
4169 | ||
4bb7a0a7 DJ |
4170 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4171 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4172 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4173 | the initial number. */ | |
4174 | ||
4175 | static struct abbrev_info * | |
fe1b8b76 | 4176 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4177 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4178 | { |
4179 | bfd *abfd = cu->objfile->obfd; | |
4180 | unsigned int abbrev_number; | |
4181 | struct abbrev_info *abbrev; | |
4182 | ||
4183 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4184 | ||
4185 | if (abbrev_number == 0) | |
4186 | return NULL; | |
4187 | ||
4188 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4189 | if (!abbrev) | |
4190 | { | |
3e43a32a MS |
4191 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4192 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4193 | } |
4194 | ||
4195 | return abbrev; | |
4196 | } | |
4197 | ||
93311388 DE |
4198 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4199 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4200 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4201 | ||
fe1b8b76 | 4202 | static gdb_byte * |
93311388 | 4203 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4204 | { |
4205 | struct abbrev_info *abbrev; | |
4206 | unsigned int bytes_read; | |
4207 | ||
4208 | while (1) | |
4209 | { | |
4210 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4211 | if (abbrev == NULL) | |
4212 | return info_ptr + bytes_read; | |
4213 | else | |
93311388 | 4214 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4215 | } |
4216 | } | |
4217 | ||
93311388 DE |
4218 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4219 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4220 | abbrev corresponding to that skipped uleb128 should be passed in |
4221 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4222 | children. */ | |
4223 | ||
fe1b8b76 | 4224 | static gdb_byte * |
93311388 DE |
4225 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4226 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4227 | { |
4228 | unsigned int bytes_read; | |
4229 | struct attribute attr; | |
4230 | bfd *abfd = cu->objfile->obfd; | |
4231 | unsigned int form, i; | |
4232 | ||
4233 | for (i = 0; i < abbrev->num_attrs; i++) | |
4234 | { | |
4235 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4236 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4237 | { | |
4238 | read_attribute (&attr, &abbrev->attrs[i], | |
4239 | abfd, info_ptr, cu); | |
4240 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
4241 | complaint (&symfile_complaints, |
4242 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4243 | else |
93311388 | 4244 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4245 | } |
4246 | ||
4247 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4248 | form = abbrev->attrs[i].form; | |
4249 | skip_attribute: | |
4250 | switch (form) | |
4251 | { | |
4bb7a0a7 | 4252 | case DW_FORM_ref_addr: |
ae411497 TT |
4253 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4254 | and later it is offset sized. */ | |
4255 | if (cu->header.version == 2) | |
4256 | info_ptr += cu->header.addr_size; | |
4257 | else | |
4258 | info_ptr += cu->header.offset_size; | |
4259 | break; | |
4260 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4261 | info_ptr += cu->header.addr_size; |
4262 | break; | |
4263 | case DW_FORM_data1: | |
4264 | case DW_FORM_ref1: | |
4265 | case DW_FORM_flag: | |
4266 | info_ptr += 1; | |
4267 | break; | |
2dc7f7b3 TT |
4268 | case DW_FORM_flag_present: |
4269 | break; | |
4bb7a0a7 DJ |
4270 | case DW_FORM_data2: |
4271 | case DW_FORM_ref2: | |
4272 | info_ptr += 2; | |
4273 | break; | |
4274 | case DW_FORM_data4: | |
4275 | case DW_FORM_ref4: | |
4276 | info_ptr += 4; | |
4277 | break; | |
4278 | case DW_FORM_data8: | |
4279 | case DW_FORM_ref8: | |
55f1336d | 4280 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4281 | info_ptr += 8; |
4282 | break; | |
4283 | case DW_FORM_string: | |
9b1c24c8 | 4284 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4285 | info_ptr += bytes_read; |
4286 | break; | |
2dc7f7b3 | 4287 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4288 | case DW_FORM_strp: |
4289 | info_ptr += cu->header.offset_size; | |
4290 | break; | |
2dc7f7b3 | 4291 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4292 | case DW_FORM_block: |
4293 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4294 | info_ptr += bytes_read; | |
4295 | break; | |
4296 | case DW_FORM_block1: | |
4297 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4298 | break; | |
4299 | case DW_FORM_block2: | |
4300 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4301 | break; | |
4302 | case DW_FORM_block4: | |
4303 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4304 | break; | |
4305 | case DW_FORM_sdata: | |
4306 | case DW_FORM_udata: | |
4307 | case DW_FORM_ref_udata: | |
4308 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4309 | break; | |
4310 | case DW_FORM_indirect: | |
4311 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4312 | info_ptr += bytes_read; | |
4313 | /* We need to continue parsing from here, so just go back to | |
4314 | the top. */ | |
4315 | goto skip_attribute; | |
4316 | ||
4317 | default: | |
3e43a32a MS |
4318 | error (_("Dwarf Error: Cannot handle %s " |
4319 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4320 | dwarf_form_name (form), |
4321 | bfd_get_filename (abfd)); | |
4322 | } | |
4323 | } | |
4324 | ||
4325 | if (abbrev->has_children) | |
93311388 | 4326 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4327 | else |
4328 | return info_ptr; | |
4329 | } | |
4330 | ||
93311388 DE |
4331 | /* Locate ORIG_PDI's sibling. |
4332 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4333 | in BUFFER. */ | |
91c24f0a | 4334 | |
fe1b8b76 | 4335 | static gdb_byte * |
93311388 DE |
4336 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4337 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4338 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4339 | { |
4340 | /* Do we know the sibling already? */ | |
72bf9492 | 4341 | |
91c24f0a DC |
4342 | if (orig_pdi->sibling) |
4343 | return orig_pdi->sibling; | |
4344 | ||
4345 | /* Are there any children to deal with? */ | |
4346 | ||
4347 | if (!orig_pdi->has_children) | |
4348 | return info_ptr; | |
4349 | ||
4bb7a0a7 | 4350 | /* Skip the children the long way. */ |
91c24f0a | 4351 | |
93311388 | 4352 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4353 | } |
4354 | ||
c906108c SS |
4355 | /* Expand this partial symbol table into a full symbol table. */ |
4356 | ||
4357 | static void | |
fba45db2 | 4358 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4359 | { |
c906108c SS |
4360 | if (pst != NULL) |
4361 | { | |
4362 | if (pst->readin) | |
4363 | { | |
3e43a32a MS |
4364 | warning (_("bug: psymtab for %s is already read in."), |
4365 | pst->filename); | |
c906108c SS |
4366 | } |
4367 | else | |
4368 | { | |
4369 | if (info_verbose) | |
4370 | { | |
3e43a32a MS |
4371 | printf_filtered (_("Reading in symbols for %s..."), |
4372 | pst->filename); | |
c906108c SS |
4373 | gdb_flush (gdb_stdout); |
4374 | } | |
4375 | ||
10b3939b DJ |
4376 | /* Restore our global data. */ |
4377 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4378 | dwarf2_objfile_data_key); | |
4379 | ||
b2ab525c KB |
4380 | /* If this psymtab is constructed from a debug-only objfile, the |
4381 | has_section_at_zero flag will not necessarily be correct. We | |
4382 | can get the correct value for this flag by looking at the data | |
4383 | associated with the (presumably stripped) associated objfile. */ | |
4384 | if (pst->objfile->separate_debug_objfile_backlink) | |
4385 | { | |
4386 | struct dwarf2_per_objfile *dpo_backlink | |
4387 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4388 | dwarf2_objfile_data_key); | |
9a619af0 | 4389 | |
b2ab525c KB |
4390 | dwarf2_per_objfile->has_section_at_zero |
4391 | = dpo_backlink->has_section_at_zero; | |
4392 | } | |
4393 | ||
98bfdba5 PA |
4394 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4395 | ||
c906108c SS |
4396 | psymtab_to_symtab_1 (pst); |
4397 | ||
4398 | /* Finish up the debug error message. */ | |
4399 | if (info_verbose) | |
a3f17187 | 4400 | printf_filtered (_("done.\n")); |
c906108c SS |
4401 | } |
4402 | } | |
4403 | } | |
4404 | ||
10b3939b DJ |
4405 | /* Add PER_CU to the queue. */ |
4406 | ||
4407 | static void | |
03dd20cc | 4408 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
4409 | { |
4410 | struct dwarf2_queue_item *item; | |
4411 | ||
4412 | per_cu->queued = 1; | |
4413 | item = xmalloc (sizeof (*item)); | |
4414 | item->per_cu = per_cu; | |
4415 | item->next = NULL; | |
4416 | ||
4417 | if (dwarf2_queue == NULL) | |
4418 | dwarf2_queue = item; | |
4419 | else | |
4420 | dwarf2_queue_tail->next = item; | |
4421 | ||
4422 | dwarf2_queue_tail = item; | |
4423 | } | |
4424 | ||
4425 | /* Process the queue. */ | |
4426 | ||
4427 | static void | |
4428 | process_queue (struct objfile *objfile) | |
4429 | { | |
4430 | struct dwarf2_queue_item *item, *next_item; | |
4431 | ||
03dd20cc DJ |
4432 | /* The queue starts out with one item, but following a DIE reference |
4433 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4434 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4435 | { | |
9291a0cd TT |
4436 | if (dwarf2_per_objfile->using_index |
4437 | ? !item->per_cu->v.quick->symtab | |
4438 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4439 | process_full_comp_unit (item->per_cu); |
4440 | ||
4441 | item->per_cu->queued = 0; | |
4442 | next_item = item->next; | |
4443 | xfree (item); | |
4444 | } | |
4445 | ||
4446 | dwarf2_queue_tail = NULL; | |
4447 | } | |
4448 | ||
4449 | /* Free all allocated queue entries. This function only releases anything if | |
4450 | an error was thrown; if the queue was processed then it would have been | |
4451 | freed as we went along. */ | |
4452 | ||
4453 | static void | |
4454 | dwarf2_release_queue (void *dummy) | |
4455 | { | |
4456 | struct dwarf2_queue_item *item, *last; | |
4457 | ||
4458 | item = dwarf2_queue; | |
4459 | while (item) | |
4460 | { | |
4461 | /* Anything still marked queued is likely to be in an | |
4462 | inconsistent state, so discard it. */ | |
4463 | if (item->per_cu->queued) | |
4464 | { | |
4465 | if (item->per_cu->cu != NULL) | |
4466 | free_one_cached_comp_unit (item->per_cu->cu); | |
4467 | item->per_cu->queued = 0; | |
4468 | } | |
4469 | ||
4470 | last = item; | |
4471 | item = item->next; | |
4472 | xfree (last); | |
4473 | } | |
4474 | ||
4475 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4476 | } | |
4477 | ||
4478 | /* Read in full symbols for PST, and anything it depends on. */ | |
4479 | ||
c906108c | 4480 | static void |
fba45db2 | 4481 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4482 | { |
10b3939b | 4483 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4484 | struct cleanup *back_to; |
aaa75496 JB |
4485 | int i; |
4486 | ||
4487 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4488 | if (!pst->dependencies[i]->readin) | |
4489 | { | |
4490 | /* Inform about additional files that need to be read in. */ | |
4491 | if (info_verbose) | |
4492 | { | |
a3f17187 | 4493 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4494 | fputs_filtered (" ", gdb_stdout); |
4495 | wrap_here (""); | |
4496 | fputs_filtered ("and ", gdb_stdout); | |
4497 | wrap_here (""); | |
4498 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4499 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4500 | gdb_flush (gdb_stdout); |
4501 | } | |
4502 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4503 | } | |
4504 | ||
e38df1d0 | 4505 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4506 | |
4507 | if (per_cu == NULL) | |
aaa75496 JB |
4508 | { |
4509 | /* It's an include file, no symbols to read for it. | |
4510 | Everything is in the parent symtab. */ | |
4511 | pst->readin = 1; | |
4512 | return; | |
4513 | } | |
c906108c | 4514 | |
9291a0cd | 4515 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4516 | } |
4517 | ||
93311388 | 4518 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4519 | |
93311388 | 4520 | static void |
3e43a32a MS |
4521 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
4522 | struct objfile *objfile) | |
10b3939b | 4523 | { |
31ffec48 | 4524 | bfd *abfd = objfile->obfd; |
10b3939b | 4525 | struct dwarf2_cu *cu; |
c764a876 | 4526 | unsigned int offset; |
93311388 | 4527 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4528 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4529 | struct attribute *attr; |
98bfdba5 | 4530 | int read_cu = 0; |
6502dd73 | 4531 | |
348e048f DE |
4532 | gdb_assert (! per_cu->from_debug_types); |
4533 | ||
c906108c | 4534 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4535 | offset = per_cu->offset; |
6502dd73 | 4536 | |
be391dca | 4537 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4538 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4539 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4540 | |
98bfdba5 PA |
4541 | if (per_cu->cu == NULL) |
4542 | { | |
9816fde3 JK |
4543 | cu = xmalloc (sizeof (*cu)); |
4544 | init_one_comp_unit (cu, objfile); | |
98bfdba5 PA |
4545 | |
4546 | read_cu = 1; | |
c906108c | 4547 | |
98bfdba5 PA |
4548 | /* If an error occurs while loading, release our storage. */ |
4549 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4550 | |
98bfdba5 PA |
4551 | /* Read in the comp_unit header. */ |
4552 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4553 | |
98bfdba5 PA |
4554 | /* Complete the cu_header. */ |
4555 | cu->header.offset = offset; | |
4556 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4557 | |
98bfdba5 PA |
4558 | /* Read the abbrevs for this compilation unit. */ |
4559 | dwarf2_read_abbrevs (abfd, cu); | |
4560 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10b3939b | 4561 | |
98bfdba5 PA |
4562 | /* Link this compilation unit into the compilation unit tree. */ |
4563 | per_cu->cu = cu; | |
4564 | cu->per_cu = per_cu; | |
98bfdba5 PA |
4565 | |
4566 | /* Link this CU into read_in_chain. */ | |
4567 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4568 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4569 | } | |
4570 | else | |
4571 | { | |
4572 | cu = per_cu->cu; | |
4573 | info_ptr += cu->header.first_die_offset; | |
4574 | } | |
e142c38c | 4575 | |
93311388 | 4576 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4577 | |
4578 | /* We try not to read any attributes in this function, because not | |
4579 | all objfiles needed for references have been loaded yet, and symbol | |
4580 | table processing isn't initialized. But we have to set the CU language, | |
4581 | or we won't be able to build types correctly. */ | |
9816fde3 | 4582 | prepare_one_comp_unit (cu, cu->dies); |
10b3939b | 4583 | |
a6c727b2 DJ |
4584 | /* Similarly, if we do not read the producer, we can not apply |
4585 | producer-specific interpretation. */ | |
4586 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4587 | if (attr) | |
4588 | cu->producer = DW_STRING (attr); | |
4589 | ||
98bfdba5 PA |
4590 | if (read_cu) |
4591 | { | |
4592 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4593 | |
98bfdba5 PA |
4594 | /* We've successfully allocated this compilation unit. Let our |
4595 | caller clean it up when finished with it. */ | |
4596 | discard_cleanups (free_cu_cleanup); | |
4597 | } | |
10b3939b DJ |
4598 | } |
4599 | ||
3da10d80 KS |
4600 | /* Add a DIE to the delayed physname list. */ |
4601 | ||
4602 | static void | |
4603 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4604 | const char *name, struct die_info *die, | |
4605 | struct dwarf2_cu *cu) | |
4606 | { | |
4607 | struct delayed_method_info mi; | |
4608 | mi.type = type; | |
4609 | mi.fnfield_index = fnfield_index; | |
4610 | mi.index = index; | |
4611 | mi.name = name; | |
4612 | mi.die = die; | |
4613 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4614 | } | |
4615 | ||
4616 | /* A cleanup for freeing the delayed method list. */ | |
4617 | ||
4618 | static void | |
4619 | free_delayed_list (void *ptr) | |
4620 | { | |
4621 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4622 | if (cu->method_list != NULL) | |
4623 | { | |
4624 | VEC_free (delayed_method_info, cu->method_list); | |
4625 | cu->method_list = NULL; | |
4626 | } | |
4627 | } | |
4628 | ||
4629 | /* Compute the physnames of any methods on the CU's method list. | |
4630 | ||
4631 | The computation of method physnames is delayed in order to avoid the | |
4632 | (bad) condition that one of the method's formal parameters is of an as yet | |
4633 | incomplete type. */ | |
4634 | ||
4635 | static void | |
4636 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4637 | { | |
4638 | int i; | |
4639 | struct delayed_method_info *mi; | |
4640 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4641 | { | |
1d06ead6 | 4642 | const char *physname; |
3da10d80 KS |
4643 | struct fn_fieldlist *fn_flp |
4644 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 4645 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
4646 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
4647 | } | |
4648 | } | |
4649 | ||
8be455d7 JK |
4650 | /* Check for GCC >= 4.0. */ |
4651 | ||
4652 | static int | |
4653 | producer_is_gcc_ge_4_0 (struct dwarf2_cu *cu) | |
4654 | { | |
4655 | const char *cs; | |
4656 | int major, minor; | |
4657 | ||
4658 | if (cu->producer == NULL) | |
4659 | { | |
4660 | /* For unknown compilers expect their behavior is not compliant. For GCC | |
4661 | this case can also happen for -gdwarf-4 type units supported since | |
4662 | gcc-4.5. */ | |
4663 | ||
4664 | return 0; | |
4665 | } | |
4666 | ||
4667 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ | |
4668 | ||
4669 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
4670 | { | |
4671 | /* For non-GCC compilers expect their behavior is not compliant. */ | |
4672 | ||
4673 | return 0; | |
4674 | } | |
4675 | cs = &cu->producer[strlen ("GNU ")]; | |
4676 | while (*cs && !isdigit (*cs)) | |
4677 | cs++; | |
4678 | if (sscanf (cs, "%d.%d", &major, &minor) != 2) | |
4679 | { | |
4680 | /* Not recognized as GCC. */ | |
4681 | ||
4682 | return 0; | |
4683 | } | |
4684 | ||
4685 | return major >= 4; | |
4686 | } | |
4687 | ||
10b3939b DJ |
4688 | /* Generate full symbol information for PST and CU, whose DIEs have |
4689 | already been loaded into memory. */ | |
4690 | ||
4691 | static void | |
4692 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4693 | { | |
10b3939b | 4694 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4695 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4696 | CORE_ADDR lowpc, highpc; |
4697 | struct symtab *symtab; | |
3da10d80 | 4698 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4699 | CORE_ADDR baseaddr; |
4700 | ||
4701 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4702 | ||
10b3939b DJ |
4703 | buildsym_init (); |
4704 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4705 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4706 | |
4707 | cu->list_in_scope = &file_symbols; | |
c906108c | 4708 | |
d85a05f0 | 4709 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 4710 | |
c906108c | 4711 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 4712 | process_die (cu->dies, cu); |
c906108c | 4713 | |
3da10d80 KS |
4714 | /* Now that we have processed all the DIEs in the CU, all the types |
4715 | should be complete, and it should now be safe to compute all of the | |
4716 | physnames. */ | |
4717 | compute_delayed_physnames (cu); | |
4718 | do_cleanups (delayed_list_cleanup); | |
4719 | ||
fae299cd DC |
4720 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4721 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4722 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4723 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4724 | |
613e1657 | 4725 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 4726 | |
8be455d7 | 4727 | if (symtab != NULL) |
c906108c | 4728 | { |
8be455d7 JK |
4729 | /* Set symtab language to language from DW_AT_language. If the |
4730 | compilation is from a C file generated by language preprocessors, do | |
4731 | not set the language if it was already deduced by start_subfile. */ | |
4732 | if (!(cu->language == language_c && symtab->language != language_c)) | |
4733 | symtab->language = cu->language; | |
4734 | ||
4735 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
4736 | produce DW_AT_location with location lists but it can be possibly | |
4737 | invalid without -fvar-tracking. | |
4738 | ||
4739 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
4740 | needed, it would be wrong due to missing DW_AT_producer there. | |
4741 | ||
4742 | Still one can confuse GDB by using non-standard GCC compilation | |
4743 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
4744 | */ | |
4745 | if (cu->has_loclist && producer_is_gcc_ge_4_0 (cu)) | |
4746 | symtab->locations_valid = 1; | |
c906108c | 4747 | } |
9291a0cd TT |
4748 | |
4749 | if (dwarf2_per_objfile->using_index) | |
4750 | per_cu->v.quick->symtab = symtab; | |
4751 | else | |
4752 | { | |
4753 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4754 | pst->symtab = symtab; | |
4755 | pst->readin = 1; | |
4756 | } | |
c906108c SS |
4757 | |
4758 | do_cleanups (back_to); | |
4759 | } | |
4760 | ||
4761 | /* Process a die and its children. */ | |
4762 | ||
4763 | static void | |
e7c27a73 | 4764 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4765 | { |
4766 | switch (die->tag) | |
4767 | { | |
4768 | case DW_TAG_padding: | |
4769 | break; | |
4770 | case DW_TAG_compile_unit: | |
e7c27a73 | 4771 | read_file_scope (die, cu); |
c906108c | 4772 | break; |
348e048f DE |
4773 | case DW_TAG_type_unit: |
4774 | read_type_unit_scope (die, cu); | |
4775 | break; | |
c906108c | 4776 | case DW_TAG_subprogram: |
c906108c | 4777 | case DW_TAG_inlined_subroutine: |
edb3359d | 4778 | read_func_scope (die, cu); |
c906108c SS |
4779 | break; |
4780 | case DW_TAG_lexical_block: | |
14898363 L |
4781 | case DW_TAG_try_block: |
4782 | case DW_TAG_catch_block: | |
e7c27a73 | 4783 | read_lexical_block_scope (die, cu); |
c906108c SS |
4784 | break; |
4785 | case DW_TAG_class_type: | |
680b30c7 | 4786 | case DW_TAG_interface_type: |
c906108c SS |
4787 | case DW_TAG_structure_type: |
4788 | case DW_TAG_union_type: | |
134d01f1 | 4789 | process_structure_scope (die, cu); |
c906108c SS |
4790 | break; |
4791 | case DW_TAG_enumeration_type: | |
134d01f1 | 4792 | process_enumeration_scope (die, cu); |
c906108c | 4793 | break; |
134d01f1 | 4794 | |
f792889a DJ |
4795 | /* These dies have a type, but processing them does not create |
4796 | a symbol or recurse to process the children. Therefore we can | |
4797 | read them on-demand through read_type_die. */ | |
c906108c | 4798 | case DW_TAG_subroutine_type: |
72019c9c | 4799 | case DW_TAG_set_type: |
c906108c | 4800 | case DW_TAG_array_type: |
c906108c | 4801 | case DW_TAG_pointer_type: |
c906108c | 4802 | case DW_TAG_ptr_to_member_type: |
c906108c | 4803 | case DW_TAG_reference_type: |
c906108c | 4804 | case DW_TAG_string_type: |
c906108c | 4805 | break; |
134d01f1 | 4806 | |
c906108c | 4807 | case DW_TAG_base_type: |
a02abb62 | 4808 | case DW_TAG_subrange_type: |
cb249c71 | 4809 | case DW_TAG_typedef: |
134d01f1 DJ |
4810 | /* Add a typedef symbol for the type definition, if it has a |
4811 | DW_AT_name. */ | |
f792889a | 4812 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4813 | break; |
c906108c | 4814 | case DW_TAG_common_block: |
e7c27a73 | 4815 | read_common_block (die, cu); |
c906108c SS |
4816 | break; |
4817 | case DW_TAG_common_inclusion: | |
4818 | break; | |
d9fa45fe | 4819 | case DW_TAG_namespace: |
63d06c5c | 4820 | processing_has_namespace_info = 1; |
e7c27a73 | 4821 | read_namespace (die, cu); |
d9fa45fe | 4822 | break; |
5d7cb8df | 4823 | case DW_TAG_module: |
f55ee35c | 4824 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4825 | read_module (die, cu); |
4826 | break; | |
d9fa45fe DC |
4827 | case DW_TAG_imported_declaration: |
4828 | case DW_TAG_imported_module: | |
63d06c5c | 4829 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4830 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4831 | || cu->language != language_fortran)) | |
4832 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4833 | dwarf_tag_name (die->tag)); | |
4834 | read_import_statement (die, cu); | |
d9fa45fe | 4835 | break; |
c906108c | 4836 | default: |
e7c27a73 | 4837 | new_symbol (die, NULL, cu); |
c906108c SS |
4838 | break; |
4839 | } | |
4840 | } | |
4841 | ||
94af9270 KS |
4842 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4843 | needs to have the name of the scope prepended to the name listed in the | |
4844 | die. */ | |
4845 | ||
4846 | static int | |
4847 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4848 | { | |
1c809c68 TT |
4849 | struct attribute *attr; |
4850 | ||
94af9270 KS |
4851 | switch (die->tag) |
4852 | { | |
4853 | case DW_TAG_namespace: | |
4854 | case DW_TAG_typedef: | |
4855 | case DW_TAG_class_type: | |
4856 | case DW_TAG_interface_type: | |
4857 | case DW_TAG_structure_type: | |
4858 | case DW_TAG_union_type: | |
4859 | case DW_TAG_enumeration_type: | |
4860 | case DW_TAG_enumerator: | |
4861 | case DW_TAG_subprogram: | |
4862 | case DW_TAG_member: | |
4863 | return 1; | |
4864 | ||
4865 | case DW_TAG_variable: | |
c2b0a229 | 4866 | case DW_TAG_constant: |
94af9270 KS |
4867 | /* We only need to prefix "globally" visible variables. These include |
4868 | any variable marked with DW_AT_external or any variable that | |
4869 | lives in a namespace. [Variables in anonymous namespaces | |
4870 | require prefixing, but they are not DW_AT_external.] */ | |
4871 | ||
4872 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4873 | { | |
4874 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4875 | |
94af9270 KS |
4876 | return die_needs_namespace (die_specification (die, &spec_cu), |
4877 | spec_cu); | |
4878 | } | |
4879 | ||
1c809c68 | 4880 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4881 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4882 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4883 | return 0; |
4884 | /* A variable in a lexical block of some kind does not need a | |
4885 | namespace, even though in C++ such variables may be external | |
4886 | and have a mangled name. */ | |
4887 | if (die->parent->tag == DW_TAG_lexical_block | |
4888 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4889 | || die->parent->tag == DW_TAG_catch_block |
4890 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4891 | return 0; |
4892 | return 1; | |
94af9270 KS |
4893 | |
4894 | default: | |
4895 | return 0; | |
4896 | } | |
4897 | } | |
4898 | ||
98bfdba5 PA |
4899 | /* Retrieve the last character from a mem_file. */ |
4900 | ||
4901 | static void | |
4902 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4903 | { | |
4904 | char *last_char_p = (char *) object; | |
4905 | ||
4906 | if (length > 0) | |
4907 | *last_char_p = buffer[length - 1]; | |
4908 | } | |
4909 | ||
94af9270 KS |
4910 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4911 | compute the physname for the object, which include a method's | |
4912 | formal parameters (C++/Java) and return type (Java). | |
4913 | ||
af6b7be1 JB |
4914 | For Ada, return the DIE's linkage name rather than the fully qualified |
4915 | name. PHYSNAME is ignored.. | |
4916 | ||
94af9270 KS |
4917 | The result is allocated on the objfile_obstack and canonicalized. */ |
4918 | ||
4919 | static const char * | |
4920 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4921 | int physname) | |
4922 | { | |
4923 | if (name == NULL) | |
4924 | name = dwarf2_name (die, cu); | |
4925 | ||
f55ee35c JK |
4926 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4927 | compute it by typename_concat inside GDB. */ | |
4928 | if (cu->language == language_ada | |
4929 | || (cu->language == language_fortran && physname)) | |
4930 | { | |
4931 | /* For Ada unit, we prefer the linkage name over the name, as | |
4932 | the former contains the exported name, which the user expects | |
4933 | to be able to reference. Ideally, we want the user to be able | |
4934 | to reference this entity using either natural or linkage name, | |
4935 | but we haven't started looking at this enhancement yet. */ | |
4936 | struct attribute *attr; | |
4937 | ||
4938 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4939 | if (attr == NULL) | |
4940 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4941 | if (attr && DW_STRING (attr)) | |
4942 | return DW_STRING (attr); | |
4943 | } | |
4944 | ||
94af9270 KS |
4945 | /* These are the only languages we know how to qualify names in. */ |
4946 | if (name != NULL | |
f55ee35c JK |
4947 | && (cu->language == language_cplus || cu->language == language_java |
4948 | || cu->language == language_fortran)) | |
94af9270 KS |
4949 | { |
4950 | if (die_needs_namespace (die, cu)) | |
4951 | { | |
4952 | long length; | |
4953 | char *prefix; | |
4954 | struct ui_file *buf; | |
4955 | ||
4956 | prefix = determine_prefix (die, cu); | |
4957 | buf = mem_fileopen (); | |
4958 | if (*prefix != '\0') | |
4959 | { | |
f55ee35c JK |
4960 | char *prefixed_name = typename_concat (NULL, prefix, name, |
4961 | physname, cu); | |
9a619af0 | 4962 | |
94af9270 KS |
4963 | fputs_unfiltered (prefixed_name, buf); |
4964 | xfree (prefixed_name); | |
4965 | } | |
4966 | else | |
62d5b8da | 4967 | fputs_unfiltered (name, buf); |
94af9270 | 4968 | |
98bfdba5 PA |
4969 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
4970 | as children with DW_TAG_template_type_param or | |
4971 | DW_TAG_value_type_param. If the latter, add them to the name | |
4972 | here. If the name already has template parameters, then | |
4973 | skip this step; some versions of GCC emit both, and | |
4974 | it is more efficient to use the pre-computed name. | |
4975 | ||
4976 | Something to keep in mind about this process: it is very | |
4977 | unlikely, or in some cases downright impossible, to produce | |
4978 | something that will match the mangled name of a function. | |
4979 | If the definition of the function has the same debug info, | |
4980 | we should be able to match up with it anyway. But fallbacks | |
4981 | using the minimal symbol, for instance to find a method | |
4982 | implemented in a stripped copy of libstdc++, will not work. | |
4983 | If we do not have debug info for the definition, we will have to | |
4984 | match them up some other way. | |
4985 | ||
4986 | When we do name matching there is a related problem with function | |
4987 | templates; two instantiated function templates are allowed to | |
4988 | differ only by their return types, which we do not add here. */ | |
4989 | ||
4990 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
4991 | { | |
4992 | struct attribute *attr; | |
4993 | struct die_info *child; | |
4994 | int first = 1; | |
4995 | ||
4996 | die->building_fullname = 1; | |
4997 | ||
4998 | for (child = die->child; child != NULL; child = child->sibling) | |
4999 | { | |
5000 | struct type *type; | |
5001 | long value; | |
5002 | gdb_byte *bytes; | |
5003 | struct dwarf2_locexpr_baton *baton; | |
5004 | struct value *v; | |
5005 | ||
5006 | if (child->tag != DW_TAG_template_type_param | |
5007 | && child->tag != DW_TAG_template_value_param) | |
5008 | continue; | |
5009 | ||
5010 | if (first) | |
5011 | { | |
5012 | fputs_unfiltered ("<", buf); | |
5013 | first = 0; | |
5014 | } | |
5015 | else | |
5016 | fputs_unfiltered (", ", buf); | |
5017 | ||
5018 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5019 | if (attr == NULL) | |
5020 | { | |
5021 | complaint (&symfile_complaints, | |
5022 | _("template parameter missing DW_AT_type")); | |
5023 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5024 | continue; | |
5025 | } | |
5026 | type = die_type (child, cu); | |
5027 | ||
5028 | if (child->tag == DW_TAG_template_type_param) | |
5029 | { | |
5030 | c_print_type (type, "", buf, -1, 0); | |
5031 | continue; | |
5032 | } | |
5033 | ||
5034 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5035 | if (attr == NULL) | |
5036 | { | |
5037 | complaint (&symfile_complaints, | |
3e43a32a MS |
5038 | _("template parameter missing " |
5039 | "DW_AT_const_value")); | |
98bfdba5 PA |
5040 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5041 | continue; | |
5042 | } | |
5043 | ||
5044 | dwarf2_const_value_attr (attr, type, name, | |
5045 | &cu->comp_unit_obstack, cu, | |
5046 | &value, &bytes, &baton); | |
5047 | ||
5048 | if (TYPE_NOSIGN (type)) | |
5049 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5050 | changed, this can use value_print instead. */ | |
5051 | c_printchar (value, type, buf); | |
5052 | else | |
5053 | { | |
5054 | struct value_print_options opts; | |
5055 | ||
5056 | if (baton != NULL) | |
5057 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5058 | baton->data, | |
5059 | baton->size, | |
5060 | baton->per_cu); | |
5061 | else if (bytes != NULL) | |
5062 | { | |
5063 | v = allocate_value (type); | |
5064 | memcpy (value_contents_writeable (v), bytes, | |
5065 | TYPE_LENGTH (type)); | |
5066 | } | |
5067 | else | |
5068 | v = value_from_longest (type, value); | |
5069 | ||
3e43a32a MS |
5070 | /* Specify decimal so that we do not depend on |
5071 | the radix. */ | |
98bfdba5 PA |
5072 | get_formatted_print_options (&opts, 'd'); |
5073 | opts.raw = 1; | |
5074 | value_print (v, buf, &opts); | |
5075 | release_value (v); | |
5076 | value_free (v); | |
5077 | } | |
5078 | } | |
5079 | ||
5080 | die->building_fullname = 0; | |
5081 | ||
5082 | if (!first) | |
5083 | { | |
5084 | /* Close the argument list, with a space if necessary | |
5085 | (nested templates). */ | |
5086 | char last_char = '\0'; | |
5087 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5088 | if (last_char == '>') | |
5089 | fputs_unfiltered (" >", buf); | |
5090 | else | |
5091 | fputs_unfiltered (">", buf); | |
5092 | } | |
5093 | } | |
5094 | ||
94af9270 KS |
5095 | /* For Java and C++ methods, append formal parameter type |
5096 | information, if PHYSNAME. */ | |
6e70227d | 5097 | |
94af9270 KS |
5098 | if (physname && die->tag == DW_TAG_subprogram |
5099 | && (cu->language == language_cplus | |
5100 | || cu->language == language_java)) | |
5101 | { | |
5102 | struct type *type = read_type_die (die, cu); | |
5103 | ||
3167638f | 5104 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5105 | |
5106 | if (cu->language == language_java) | |
5107 | { | |
5108 | /* For java, we must append the return type to method | |
0963b4bd | 5109 | names. */ |
94af9270 KS |
5110 | if (die->tag == DW_TAG_subprogram) |
5111 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5112 | 0, 0); | |
5113 | } | |
5114 | else if (cu->language == language_cplus) | |
5115 | { | |
60430eff DJ |
5116 | /* Assume that an artificial first parameter is |
5117 | "this", but do not crash if it is not. RealView | |
5118 | marks unnamed (and thus unused) parameters as | |
5119 | artificial; there is no way to differentiate | |
5120 | the two cases. */ | |
94af9270 KS |
5121 | if (TYPE_NFIELDS (type) > 0 |
5122 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5123 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5124 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5125 | 0)))) | |
94af9270 KS |
5126 | fputs_unfiltered (" const", buf); |
5127 | } | |
5128 | } | |
5129 | ||
5130 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
5131 | &length); | |
5132 | ui_file_delete (buf); | |
5133 | ||
5134 | if (cu->language == language_cplus) | |
5135 | { | |
5136 | char *cname | |
5137 | = dwarf2_canonicalize_name (name, cu, | |
5138 | &cu->objfile->objfile_obstack); | |
9a619af0 | 5139 | |
94af9270 KS |
5140 | if (cname != NULL) |
5141 | name = cname; | |
5142 | } | |
5143 | } | |
5144 | } | |
5145 | ||
5146 | return name; | |
5147 | } | |
5148 | ||
0114d602 DJ |
5149 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5150 | If scope qualifiers are appropriate they will be added. The result | |
5151 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5152 | not have a name. NAME may either be from a previous call to |
5153 | dwarf2_name or NULL. | |
5154 | ||
0963b4bd | 5155 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5156 | |
5157 | static const char * | |
94af9270 | 5158 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5159 | { |
94af9270 KS |
5160 | return dwarf2_compute_name (name, die, cu, 0); |
5161 | } | |
0114d602 | 5162 | |
94af9270 KS |
5163 | /* Construct a physname for the given DIE in CU. NAME may either be |
5164 | from a previous call to dwarf2_name or NULL. The result will be | |
5165 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5166 | name. | |
0114d602 | 5167 | |
94af9270 | 5168 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5169 | |
94af9270 KS |
5170 | static const char * |
5171 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5172 | { | |
5173 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
5174 | } |
5175 | ||
27aa8d6a SW |
5176 | /* Read the import statement specified by the given die and record it. */ |
5177 | ||
5178 | static void | |
5179 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5180 | { | |
5181 | struct attribute *import_attr; | |
5182 | struct die_info *imported_die; | |
de4affc9 | 5183 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5184 | const char *imported_name; |
794684b6 | 5185 | const char *imported_name_prefix; |
13387711 SW |
5186 | const char *canonical_name; |
5187 | const char *import_alias; | |
5188 | const char *imported_declaration = NULL; | |
794684b6 | 5189 | const char *import_prefix; |
13387711 SW |
5190 | |
5191 | char *temp; | |
27aa8d6a SW |
5192 | |
5193 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5194 | if (import_attr == NULL) | |
5195 | { | |
5196 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5197 | dwarf_tag_name (die->tag)); | |
5198 | return; | |
5199 | } | |
5200 | ||
de4affc9 CC |
5201 | imported_cu = cu; |
5202 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5203 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5204 | if (imported_name == NULL) |
5205 | { | |
5206 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5207 | ||
5208 | The import in the following code: | |
5209 | namespace A | |
5210 | { | |
5211 | typedef int B; | |
5212 | } | |
5213 | ||
5214 | int main () | |
5215 | { | |
5216 | using A::B; | |
5217 | B b; | |
5218 | return b; | |
5219 | } | |
5220 | ||
5221 | ... | |
5222 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5223 | <52> DW_AT_decl_file : 1 | |
5224 | <53> DW_AT_decl_line : 6 | |
5225 | <54> DW_AT_import : <0x75> | |
5226 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5227 | <59> DW_AT_name : B | |
5228 | <5b> DW_AT_decl_file : 1 | |
5229 | <5c> DW_AT_decl_line : 2 | |
5230 | <5d> DW_AT_type : <0x6e> | |
5231 | ... | |
5232 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5233 | <76> DW_AT_byte_size : 4 | |
5234 | <77> DW_AT_encoding : 5 (signed) | |
5235 | ||
5236 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5237 | This case will be ignored until the gcc bug is fixed. */ | |
5238 | return; | |
5239 | } | |
5240 | ||
82856980 SW |
5241 | /* Figure out the local name after import. */ |
5242 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5243 | |
794684b6 SW |
5244 | /* Figure out where the statement is being imported to. */ |
5245 | import_prefix = determine_prefix (die, cu); | |
5246 | ||
5247 | /* Figure out what the scope of the imported die is and prepend it | |
5248 | to the name of the imported die. */ | |
de4affc9 | 5249 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5250 | |
f55ee35c JK |
5251 | if (imported_die->tag != DW_TAG_namespace |
5252 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5253 | { |
13387711 SW |
5254 | imported_declaration = imported_name; |
5255 | canonical_name = imported_name_prefix; | |
794684b6 | 5256 | } |
13387711 | 5257 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5258 | { |
13387711 SW |
5259 | temp = alloca (strlen (imported_name_prefix) |
5260 | + 2 + strlen (imported_name) + 1); | |
5261 | strcpy (temp, imported_name_prefix); | |
5262 | strcat (temp, "::"); | |
5263 | strcat (temp, imported_name); | |
5264 | canonical_name = temp; | |
794684b6 | 5265 | } |
13387711 SW |
5266 | else |
5267 | canonical_name = imported_name; | |
794684b6 | 5268 | |
c0cc3a76 SW |
5269 | cp_add_using_directive (import_prefix, |
5270 | canonical_name, | |
5271 | import_alias, | |
13387711 | 5272 | imported_declaration, |
c0cc3a76 | 5273 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
5274 | } |
5275 | ||
5fb290d7 | 5276 | static void |
e142c38c | 5277 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 5278 | { |
e142c38c | 5279 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
5280 | } |
5281 | ||
ae2de4f8 DE |
5282 | /* Cleanup function for read_file_scope. */ |
5283 | ||
cb1df416 DJ |
5284 | static void |
5285 | free_cu_line_header (void *arg) | |
5286 | { | |
5287 | struct dwarf2_cu *cu = arg; | |
5288 | ||
5289 | free_line_header (cu->line_header); | |
5290 | cu->line_header = NULL; | |
5291 | } | |
5292 | ||
9291a0cd TT |
5293 | static void |
5294 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5295 | char **name, char **comp_dir) | |
5296 | { | |
5297 | struct attribute *attr; | |
5298 | ||
5299 | *name = NULL; | |
5300 | *comp_dir = NULL; | |
5301 | ||
5302 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5303 | is not a source language identifier. */ | |
5304 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5305 | if (attr) | |
5306 | { | |
5307 | *name = DW_STRING (attr); | |
5308 | } | |
5309 | ||
5310 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5311 | if (attr) | |
5312 | *comp_dir = DW_STRING (attr); | |
5313 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5314 | { | |
5315 | *comp_dir = ldirname (*name); | |
5316 | if (*comp_dir != NULL) | |
5317 | make_cleanup (xfree, *comp_dir); | |
5318 | } | |
5319 | if (*comp_dir != NULL) | |
5320 | { | |
5321 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5322 | directory, get rid of it. */ | |
5323 | char *cp = strchr (*comp_dir, ':'); | |
5324 | ||
5325 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5326 | *comp_dir = cp + 1; | |
5327 | } | |
5328 | ||
5329 | if (*name == NULL) | |
5330 | *name = "<unknown>"; | |
5331 | } | |
5332 | ||
ae2de4f8 DE |
5333 | /* Process DW_TAG_compile_unit. */ |
5334 | ||
c906108c | 5335 | static void |
e7c27a73 | 5336 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5337 | { |
e7c27a73 | 5338 | struct objfile *objfile = cu->objfile; |
debd256d | 5339 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5340 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5341 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5342 | struct attribute *attr; | |
e1024ff1 | 5343 | char *name = NULL; |
c906108c SS |
5344 | char *comp_dir = NULL; |
5345 | struct die_info *child_die; | |
5346 | bfd *abfd = objfile->obfd; | |
debd256d | 5347 | struct line_header *line_header = 0; |
e142c38c | 5348 | CORE_ADDR baseaddr; |
6e70227d | 5349 | |
e142c38c | 5350 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5351 | |
fae299cd | 5352 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5353 | |
5354 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5355 | from finish_block. */ | |
2acceee2 | 5356 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5357 | lowpc = highpc; |
5358 | lowpc += baseaddr; | |
5359 | highpc += baseaddr; | |
5360 | ||
9291a0cd | 5361 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5362 | |
e142c38c | 5363 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5364 | if (attr) |
5365 | { | |
e142c38c | 5366 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5367 | } |
5368 | ||
b0f35d58 | 5369 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5370 | if (attr) |
b0f35d58 | 5371 | cu->producer = DW_STRING (attr); |
303b6f5d | 5372 | |
f4b8a18d KW |
5373 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5374 | standardised yet. As a workaround for the language detection we fall | |
5375 | back to the DW_AT_producer string. */ | |
5376 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5377 | cu->language = language_opencl; | |
5378 | ||
0963b4bd | 5379 | /* We assume that we're processing GCC output. */ |
c906108c | 5380 | processing_gcc_compilation = 2; |
c906108c | 5381 | |
df8a16a1 DJ |
5382 | processing_has_namespace_info = 0; |
5383 | ||
c906108c SS |
5384 | start_symtab (name, comp_dir, lowpc); |
5385 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5386 | record_producer (cu->producer); |
c906108c | 5387 | |
e142c38c | 5388 | initialize_cu_func_list (cu); |
c906108c | 5389 | |
cb1df416 DJ |
5390 | /* Decode line number information if present. We do this before |
5391 | processing child DIEs, so that the line header table is available | |
5392 | for DW_AT_decl_file. */ | |
e142c38c | 5393 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
5394 | if (attr) |
5395 | { | |
debd256d | 5396 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 5397 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
5398 | if (line_header) |
5399 | { | |
cb1df416 DJ |
5400 | cu->line_header = line_header; |
5401 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 5402 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 5403 | } |
5fb290d7 | 5404 | } |
debd256d | 5405 | |
cb1df416 DJ |
5406 | /* Process all dies in compilation unit. */ |
5407 | if (die->child != NULL) | |
5408 | { | |
5409 | child_die = die->child; | |
5410 | while (child_die && child_die->tag) | |
5411 | { | |
5412 | process_die (child_die, cu); | |
5413 | child_die = sibling_die (child_die); | |
5414 | } | |
5415 | } | |
5416 | ||
2e276125 JB |
5417 | /* Decode macro information, if present. Dwarf 2 macro information |
5418 | refers to information in the line number info statement program | |
5419 | header, so we can only read it if we've read the header | |
5420 | successfully. */ | |
e142c38c | 5421 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 5422 | if (attr && line_header) |
2e276125 JB |
5423 | { |
5424 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5425 | |
2e276125 | 5426 | dwarf_decode_macros (line_header, macro_offset, |
e7c27a73 | 5427 | comp_dir, abfd, cu); |
2e276125 | 5428 | } |
debd256d | 5429 | do_cleanups (back_to); |
5fb290d7 DJ |
5430 | } |
5431 | ||
ae2de4f8 DE |
5432 | /* Process DW_TAG_type_unit. |
5433 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
5434 | actual type being defined by this TU. In this case the first top |
5435 | level sibling is there to provide context only. */ | |
5436 | ||
5437 | static void | |
5438 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5439 | { | |
5440 | struct objfile *objfile = cu->objfile; | |
5441 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5442 | CORE_ADDR lowpc; | |
5443 | struct attribute *attr; | |
5444 | char *name = NULL; | |
5445 | char *comp_dir = NULL; | |
5446 | struct die_info *child_die; | |
5447 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5448 | |
5449 | /* start_symtab needs a low pc, but we don't really have one. | |
5450 | Do what read_file_scope would do in the absence of such info. */ | |
5451 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5452 | ||
5453 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5454 | is not a source language identifier. */ | |
5455 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5456 | if (attr) | |
5457 | name = DW_STRING (attr); | |
5458 | ||
5459 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5460 | if (attr) | |
5461 | comp_dir = DW_STRING (attr); | |
5462 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5463 | { | |
5464 | comp_dir = ldirname (name); | |
5465 | if (comp_dir != NULL) | |
5466 | make_cleanup (xfree, comp_dir); | |
5467 | } | |
5468 | ||
5469 | if (name == NULL) | |
5470 | name = "<unknown>"; | |
5471 | ||
5472 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5473 | if (attr) | |
5474 | set_cu_language (DW_UNSND (attr), cu); | |
5475 | ||
5476 | /* This isn't technically needed today. It is done for symmetry | |
5477 | with read_file_scope. */ | |
5478 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5479 | if (attr) |
348e048f DE |
5480 | cu->producer = DW_STRING (attr); |
5481 | ||
0963b4bd | 5482 | /* We assume that we're processing GCC output. */ |
348e048f DE |
5483 | processing_gcc_compilation = 2; |
5484 | ||
5485 | processing_has_namespace_info = 0; | |
5486 | ||
5487 | start_symtab (name, comp_dir, lowpc); | |
5488 | record_debugformat ("DWARF 2"); | |
5489 | record_producer (cu->producer); | |
5490 | ||
5491 | /* Process the dies in the type unit. */ | |
5492 | if (die->child == NULL) | |
5493 | { | |
5494 | dump_die_for_error (die); | |
5495 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5496 | bfd_get_filename (abfd)); | |
5497 | } | |
5498 | ||
5499 | child_die = die->child; | |
5500 | ||
5501 | while (child_die && child_die->tag) | |
5502 | { | |
5503 | process_die (child_die, cu); | |
5504 | ||
5505 | child_die = sibling_die (child_die); | |
5506 | } | |
5507 | ||
5508 | do_cleanups (back_to); | |
5509 | } | |
5510 | ||
5fb290d7 | 5511 | static void |
e142c38c DJ |
5512 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
5513 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
5514 | { |
5515 | struct function_range *thisfn; | |
5516 | ||
5517 | thisfn = (struct function_range *) | |
7b5a2f43 | 5518 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
5519 | thisfn->name = name; |
5520 | thisfn->lowpc = lowpc; | |
5521 | thisfn->highpc = highpc; | |
5522 | thisfn->seen_line = 0; | |
5523 | thisfn->next = NULL; | |
5524 | ||
e142c38c DJ |
5525 | if (cu->last_fn == NULL) |
5526 | cu->first_fn = thisfn; | |
5fb290d7 | 5527 | else |
e142c38c | 5528 | cu->last_fn->next = thisfn; |
5fb290d7 | 5529 | |
e142c38c | 5530 | cu->last_fn = thisfn; |
c906108c SS |
5531 | } |
5532 | ||
d389af10 JK |
5533 | /* qsort helper for inherit_abstract_dies. */ |
5534 | ||
5535 | static int | |
5536 | unsigned_int_compar (const void *ap, const void *bp) | |
5537 | { | |
5538 | unsigned int a = *(unsigned int *) ap; | |
5539 | unsigned int b = *(unsigned int *) bp; | |
5540 | ||
5541 | return (a > b) - (b > a); | |
5542 | } | |
5543 | ||
5544 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
5545 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
5546 | already referenced by DW_AT_abstract_origin from the children of the | |
5547 | current DIE. */ | |
d389af10 JK |
5548 | |
5549 | static void | |
5550 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5551 | { | |
5552 | struct die_info *child_die; | |
5553 | unsigned die_children_count; | |
5554 | /* CU offsets which were referenced by children of the current DIE. */ | |
5555 | unsigned *offsets; | |
5556 | unsigned *offsets_end, *offsetp; | |
5557 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5558 | struct die_info *origin_die; | |
5559 | /* Iterator of the ORIGIN_DIE children. */ | |
5560 | struct die_info *origin_child_die; | |
5561 | struct cleanup *cleanups; | |
5562 | struct attribute *attr; | |
cd02d79d PA |
5563 | struct dwarf2_cu *origin_cu; |
5564 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5565 | |
5566 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5567 | if (!attr) | |
5568 | return; | |
5569 | ||
cd02d79d PA |
5570 | /* Note that following die references may follow to a die in a |
5571 | different cu. */ | |
5572 | ||
5573 | origin_cu = cu; | |
5574 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5575 | ||
5576 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5577 | symbols in. */ | |
5578 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5579 | origin_cu->list_in_scope = cu->list_in_scope; | |
5580 | ||
edb3359d DJ |
5581 | if (die->tag != origin_die->tag |
5582 | && !(die->tag == DW_TAG_inlined_subroutine | |
5583 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5584 | complaint (&symfile_complaints, |
5585 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5586 | die->offset, origin_die->offset); | |
5587 | ||
5588 | child_die = die->child; | |
5589 | die_children_count = 0; | |
5590 | while (child_die && child_die->tag) | |
5591 | { | |
5592 | child_die = sibling_die (child_die); | |
5593 | die_children_count++; | |
5594 | } | |
5595 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5596 | cleanups = make_cleanup (xfree, offsets); | |
5597 | ||
5598 | offsets_end = offsets; | |
5599 | child_die = die->child; | |
5600 | while (child_die && child_die->tag) | |
5601 | { | |
c38f313d DJ |
5602 | /* For each CHILD_DIE, find the corresponding child of |
5603 | ORIGIN_DIE. If there is more than one layer of | |
5604 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5605 | but GCC versions at least through 4.4 generate this (GCC PR | |
5606 | 40573). */ | |
5607 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5608 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5609 | |
c38f313d DJ |
5610 | while (1) |
5611 | { | |
cd02d79d PA |
5612 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5613 | child_origin_cu); | |
c38f313d DJ |
5614 | if (attr == NULL) |
5615 | break; | |
cd02d79d PA |
5616 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5617 | &child_origin_cu); | |
c38f313d DJ |
5618 | } |
5619 | ||
d389af10 JK |
5620 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5621 | counterpart may exist. */ | |
c38f313d | 5622 | if (child_origin_die != child_die) |
d389af10 | 5623 | { |
edb3359d DJ |
5624 | if (child_die->tag != child_origin_die->tag |
5625 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5626 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5627 | complaint (&symfile_complaints, |
5628 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5629 | "different tags"), child_die->offset, | |
5630 | child_origin_die->offset); | |
c38f313d DJ |
5631 | if (child_origin_die->parent != origin_die) |
5632 | complaint (&symfile_complaints, | |
5633 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5634 | "different parents"), child_die->offset, | |
5635 | child_origin_die->offset); | |
5636 | else | |
5637 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5638 | } |
5639 | child_die = sibling_die (child_die); | |
5640 | } | |
5641 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5642 | unsigned_int_compar); | |
5643 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5644 | if (offsetp[-1] == *offsetp) | |
3e43a32a MS |
5645 | complaint (&symfile_complaints, |
5646 | _("Multiple children of DIE 0x%x refer " | |
5647 | "to DIE 0x%x as their abstract origin"), | |
d389af10 JK |
5648 | die->offset, *offsetp); |
5649 | ||
5650 | offsetp = offsets; | |
5651 | origin_child_die = origin_die->child; | |
5652 | while (origin_child_die && origin_child_die->tag) | |
5653 | { | |
5654 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5655 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5656 | offsetp++; | |
5657 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5658 | { | |
5659 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5660 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5661 | } |
5662 | origin_child_die = sibling_die (origin_child_die); | |
5663 | } | |
cd02d79d | 5664 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5665 | |
5666 | do_cleanups (cleanups); | |
5667 | } | |
5668 | ||
c906108c | 5669 | static void |
e7c27a73 | 5670 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5671 | { |
e7c27a73 | 5672 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5673 | struct context_stack *new; |
c906108c SS |
5674 | CORE_ADDR lowpc; |
5675 | CORE_ADDR highpc; | |
5676 | struct die_info *child_die; | |
edb3359d | 5677 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5678 | char *name; |
e142c38c | 5679 | CORE_ADDR baseaddr; |
801e3a5b | 5680 | struct block *block; |
edb3359d | 5681 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5682 | VEC (symbolp) *template_args = NULL; |
5683 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5684 | |
5685 | if (inlined_func) | |
5686 | { | |
5687 | /* If we do not have call site information, we can't show the | |
5688 | caller of this inlined function. That's too confusing, so | |
5689 | only use the scope for local variables. */ | |
5690 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5691 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5692 | if (call_line == NULL || call_file == NULL) | |
5693 | { | |
5694 | read_lexical_block_scope (die, cu); | |
5695 | return; | |
5696 | } | |
5697 | } | |
c906108c | 5698 | |
e142c38c DJ |
5699 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5700 | ||
94af9270 | 5701 | name = dwarf2_name (die, cu); |
c906108c | 5702 | |
e8d05480 JB |
5703 | /* Ignore functions with missing or empty names. These are actually |
5704 | illegal according to the DWARF standard. */ | |
5705 | if (name == NULL) | |
5706 | { | |
5707 | complaint (&symfile_complaints, | |
5708 | _("missing name for subprogram DIE at %d"), die->offset); | |
5709 | return; | |
5710 | } | |
5711 | ||
5712 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5713 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5714 | { | |
ae4d0c03 PM |
5715 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5716 | if (!attr || !DW_UNSND (attr)) | |
5717 | complaint (&symfile_complaints, | |
3e43a32a MS |
5718 | _("cannot get low and high bounds " |
5719 | "for subprogram DIE at %d"), | |
ae4d0c03 | 5720 | die->offset); |
e8d05480 JB |
5721 | return; |
5722 | } | |
c906108c SS |
5723 | |
5724 | lowpc += baseaddr; | |
5725 | highpc += baseaddr; | |
5726 | ||
5fb290d7 | 5727 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 5728 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 5729 | |
34eaf542 TT |
5730 | /* If we have any template arguments, then we must allocate a |
5731 | different sort of symbol. */ | |
5732 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5733 | { | |
5734 | if (child_die->tag == DW_TAG_template_type_param | |
5735 | || child_die->tag == DW_TAG_template_value_param) | |
5736 | { | |
5737 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5738 | struct template_symbol); | |
5739 | templ_func->base.is_cplus_template_function = 1; | |
5740 | break; | |
5741 | } | |
5742 | } | |
5743 | ||
c906108c | 5744 | new = push_context (0, lowpc); |
34eaf542 TT |
5745 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5746 | (struct symbol *) templ_func); | |
4c2df51b | 5747 | |
4cecd739 DJ |
5748 | /* If there is a location expression for DW_AT_frame_base, record |
5749 | it. */ | |
e142c38c | 5750 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5751 | if (attr) |
c034e007 AC |
5752 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5753 | expression is being recorded directly in the function's symbol | |
5754 | and not in a separate frame-base object. I guess this hack is | |
5755 | to avoid adding some sort of frame-base adjunct/annex to the | |
5756 | function's symbol :-(. The problem with doing this is that it | |
5757 | results in a function symbol with a location expression that | |
5758 | has nothing to do with the location of the function, ouch! The | |
5759 | relationship should be: a function's symbol has-a frame base; a | |
5760 | frame-base has-a location expression. */ | |
e7c27a73 | 5761 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5762 | |
e142c38c | 5763 | cu->list_in_scope = &local_symbols; |
c906108c | 5764 | |
639d11d3 | 5765 | if (die->child != NULL) |
c906108c | 5766 | { |
639d11d3 | 5767 | child_die = die->child; |
c906108c SS |
5768 | while (child_die && child_die->tag) |
5769 | { | |
34eaf542 TT |
5770 | if (child_die->tag == DW_TAG_template_type_param |
5771 | || child_die->tag == DW_TAG_template_value_param) | |
5772 | { | |
5773 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5774 | ||
f1078f66 DJ |
5775 | if (arg != NULL) |
5776 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
5777 | } |
5778 | else | |
5779 | process_die (child_die, cu); | |
c906108c SS |
5780 | child_die = sibling_die (child_die); |
5781 | } | |
5782 | } | |
5783 | ||
d389af10 JK |
5784 | inherit_abstract_dies (die, cu); |
5785 | ||
4a811a97 UW |
5786 | /* If we have a DW_AT_specification, we might need to import using |
5787 | directives from the context of the specification DIE. See the | |
5788 | comment in determine_prefix. */ | |
5789 | if (cu->language == language_cplus | |
5790 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
5791 | { | |
5792 | struct dwarf2_cu *spec_cu = cu; | |
5793 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
5794 | ||
5795 | while (spec_die) | |
5796 | { | |
5797 | child_die = spec_die->child; | |
5798 | while (child_die && child_die->tag) | |
5799 | { | |
5800 | if (child_die->tag == DW_TAG_imported_module) | |
5801 | process_die (child_die, spec_cu); | |
5802 | child_die = sibling_die (child_die); | |
5803 | } | |
5804 | ||
5805 | /* In some cases, GCC generates specification DIEs that | |
5806 | themselves contain DW_AT_specification attributes. */ | |
5807 | spec_die = die_specification (spec_die, &spec_cu); | |
5808 | } | |
5809 | } | |
5810 | ||
c906108c SS |
5811 | new = pop_context (); |
5812 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
5813 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
5814 | lowpc, highpc, objfile); | |
5815 | ||
df8a16a1 | 5816 | /* For C++, set the block's scope. */ |
f55ee35c | 5817 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 5818 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 5819 | determine_prefix (die, cu), |
df8a16a1 DJ |
5820 | processing_has_namespace_info); |
5821 | ||
801e3a5b JB |
5822 | /* If we have address ranges, record them. */ |
5823 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 5824 | |
34eaf542 TT |
5825 | /* Attach template arguments to function. */ |
5826 | if (! VEC_empty (symbolp, template_args)) | |
5827 | { | |
5828 | gdb_assert (templ_func != NULL); | |
5829 | ||
5830 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
5831 | templ_func->template_arguments | |
5832 | = obstack_alloc (&objfile->objfile_obstack, | |
5833 | (templ_func->n_template_arguments | |
5834 | * sizeof (struct symbol *))); | |
5835 | memcpy (templ_func->template_arguments, | |
5836 | VEC_address (symbolp, template_args), | |
5837 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
5838 | VEC_free (symbolp, template_args); | |
5839 | } | |
5840 | ||
208d8187 JB |
5841 | /* In C++, we can have functions nested inside functions (e.g., when |
5842 | a function declares a class that has methods). This means that | |
5843 | when we finish processing a function scope, we may need to go | |
5844 | back to building a containing block's symbol lists. */ | |
5845 | local_symbols = new->locals; | |
5846 | param_symbols = new->params; | |
27aa8d6a | 5847 | using_directives = new->using_directives; |
208d8187 | 5848 | |
921e78cf JB |
5849 | /* If we've finished processing a top-level function, subsequent |
5850 | symbols go in the file symbol list. */ | |
5851 | if (outermost_context_p ()) | |
e142c38c | 5852 | cu->list_in_scope = &file_symbols; |
c906108c SS |
5853 | } |
5854 | ||
5855 | /* Process all the DIES contained within a lexical block scope. Start | |
5856 | a new scope, process the dies, and then close the scope. */ | |
5857 | ||
5858 | static void | |
e7c27a73 | 5859 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5860 | { |
e7c27a73 | 5861 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5862 | struct context_stack *new; |
c906108c SS |
5863 | CORE_ADDR lowpc, highpc; |
5864 | struct die_info *child_die; | |
e142c38c DJ |
5865 | CORE_ADDR baseaddr; |
5866 | ||
5867 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
5868 | |
5869 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
5870 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
5871 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 5872 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 5873 | describe ranges. */ |
d85a05f0 | 5874 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
5875 | return; |
5876 | lowpc += baseaddr; | |
5877 | highpc += baseaddr; | |
5878 | ||
5879 | push_context (0, lowpc); | |
639d11d3 | 5880 | if (die->child != NULL) |
c906108c | 5881 | { |
639d11d3 | 5882 | child_die = die->child; |
c906108c SS |
5883 | while (child_die && child_die->tag) |
5884 | { | |
e7c27a73 | 5885 | process_die (child_die, cu); |
c906108c SS |
5886 | child_die = sibling_die (child_die); |
5887 | } | |
5888 | } | |
5889 | new = pop_context (); | |
5890 | ||
8540c487 | 5891 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 5892 | { |
801e3a5b JB |
5893 | struct block *block |
5894 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
5895 | highpc, objfile); | |
5896 | ||
5897 | /* Note that recording ranges after traversing children, as we | |
5898 | do here, means that recording a parent's ranges entails | |
5899 | walking across all its children's ranges as they appear in | |
5900 | the address map, which is quadratic behavior. | |
5901 | ||
5902 | It would be nicer to record the parent's ranges before | |
5903 | traversing its children, simply overriding whatever you find | |
5904 | there. But since we don't even decide whether to create a | |
5905 | block until after we've traversed its children, that's hard | |
5906 | to do. */ | |
5907 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
5908 | } |
5909 | local_symbols = new->locals; | |
27aa8d6a | 5910 | using_directives = new->using_directives; |
c906108c SS |
5911 | } |
5912 | ||
43039443 | 5913 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
5914 | Return 1 if the attributes are present and valid, otherwise, return 0. |
5915 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
5916 | |
5917 | static int | |
5918 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
5919 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
5920 | struct partial_symtab *ranges_pst) | |
43039443 JK |
5921 | { |
5922 | struct objfile *objfile = cu->objfile; | |
5923 | struct comp_unit_head *cu_header = &cu->header; | |
5924 | bfd *obfd = objfile->obfd; | |
5925 | unsigned int addr_size = cu_header->addr_size; | |
5926 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5927 | /* Base address selection entry. */ | |
5928 | CORE_ADDR base; | |
5929 | int found_base; | |
5930 | unsigned int dummy; | |
5931 | gdb_byte *buffer; | |
5932 | CORE_ADDR marker; | |
5933 | int low_set; | |
5934 | CORE_ADDR low = 0; | |
5935 | CORE_ADDR high = 0; | |
ff013f42 | 5936 | CORE_ADDR baseaddr; |
43039443 | 5937 | |
d00adf39 DE |
5938 | found_base = cu->base_known; |
5939 | base = cu->base_address; | |
43039443 | 5940 | |
be391dca | 5941 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 5942 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
5943 | { |
5944 | complaint (&symfile_complaints, | |
5945 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
5946 | offset); | |
5947 | return 0; | |
5948 | } | |
dce234bc | 5949 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
5950 | |
5951 | /* Read in the largest possible address. */ | |
5952 | marker = read_address (obfd, buffer, cu, &dummy); | |
5953 | if ((marker & mask) == mask) | |
5954 | { | |
5955 | /* If we found the largest possible address, then | |
5956 | read the base address. */ | |
5957 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5958 | buffer += 2 * addr_size; | |
5959 | offset += 2 * addr_size; | |
5960 | found_base = 1; | |
5961 | } | |
5962 | ||
5963 | low_set = 0; | |
5964 | ||
e7030f15 | 5965 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 5966 | |
43039443 JK |
5967 | while (1) |
5968 | { | |
5969 | CORE_ADDR range_beginning, range_end; | |
5970 | ||
5971 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
5972 | buffer += addr_size; | |
5973 | range_end = read_address (obfd, buffer, cu, &dummy); | |
5974 | buffer += addr_size; | |
5975 | offset += 2 * addr_size; | |
5976 | ||
5977 | /* An end of list marker is a pair of zero addresses. */ | |
5978 | if (range_beginning == 0 && range_end == 0) | |
5979 | /* Found the end of list entry. */ | |
5980 | break; | |
5981 | ||
5982 | /* Each base address selection entry is a pair of 2 values. | |
5983 | The first is the largest possible address, the second is | |
5984 | the base address. Check for a base address here. */ | |
5985 | if ((range_beginning & mask) == mask) | |
5986 | { | |
5987 | /* If we found the largest possible address, then | |
5988 | read the base address. */ | |
5989 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5990 | found_base = 1; | |
5991 | continue; | |
5992 | } | |
5993 | ||
5994 | if (!found_base) | |
5995 | { | |
5996 | /* We have no valid base address for the ranges | |
5997 | data. */ | |
5998 | complaint (&symfile_complaints, | |
5999 | _("Invalid .debug_ranges data (no base address)")); | |
6000 | return 0; | |
6001 | } | |
6002 | ||
9277c30c UW |
6003 | if (range_beginning > range_end) |
6004 | { | |
6005 | /* Inverted range entries are invalid. */ | |
6006 | complaint (&symfile_complaints, | |
6007 | _("Invalid .debug_ranges data (inverted range)")); | |
6008 | return 0; | |
6009 | } | |
6010 | ||
6011 | /* Empty range entries have no effect. */ | |
6012 | if (range_beginning == range_end) | |
6013 | continue; | |
6014 | ||
43039443 JK |
6015 | range_beginning += base; |
6016 | range_end += base; | |
6017 | ||
9277c30c | 6018 | if (ranges_pst != NULL) |
ff013f42 | 6019 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
6020 | range_beginning + baseaddr, |
6021 | range_end - 1 + baseaddr, | |
ff013f42 JK |
6022 | ranges_pst); |
6023 | ||
43039443 JK |
6024 | /* FIXME: This is recording everything as a low-high |
6025 | segment of consecutive addresses. We should have a | |
6026 | data structure for discontiguous block ranges | |
6027 | instead. */ | |
6028 | if (! low_set) | |
6029 | { | |
6030 | low = range_beginning; | |
6031 | high = range_end; | |
6032 | low_set = 1; | |
6033 | } | |
6034 | else | |
6035 | { | |
6036 | if (range_beginning < low) | |
6037 | low = range_beginning; | |
6038 | if (range_end > high) | |
6039 | high = range_end; | |
6040 | } | |
6041 | } | |
6042 | ||
6043 | if (! low_set) | |
6044 | /* If the first entry is an end-of-list marker, the range | |
6045 | describes an empty scope, i.e. no instructions. */ | |
6046 | return 0; | |
6047 | ||
6048 | if (low_return) | |
6049 | *low_return = low; | |
6050 | if (high_return) | |
6051 | *high_return = high; | |
6052 | return 1; | |
6053 | } | |
6054 | ||
af34e669 DJ |
6055 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
6056 | are present and valid, otherwise, return 0. Return -1 if the range is | |
6057 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 6058 | static int |
af34e669 | 6059 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
6060 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
6061 | struct partial_symtab *pst) | |
c906108c SS |
6062 | { |
6063 | struct attribute *attr; | |
af34e669 DJ |
6064 | CORE_ADDR low = 0; |
6065 | CORE_ADDR high = 0; | |
6066 | int ret = 0; | |
c906108c | 6067 | |
e142c38c | 6068 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 6069 | if (attr) |
af34e669 DJ |
6070 | { |
6071 | high = DW_ADDR (attr); | |
e142c38c | 6072 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
6073 | if (attr) |
6074 | low = DW_ADDR (attr); | |
6075 | else | |
6076 | /* Found high w/o low attribute. */ | |
6077 | return 0; | |
6078 | ||
6079 | /* Found consecutive range of addresses. */ | |
6080 | ret = 1; | |
6081 | } | |
c906108c | 6082 | else |
af34e669 | 6083 | { |
e142c38c | 6084 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6085 | if (attr != NULL) |
6086 | { | |
af34e669 | 6087 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6088 | .debug_ranges section. */ |
d85a05f0 | 6089 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6090 | return 0; |
43039443 | 6091 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6092 | ret = -1; |
6093 | } | |
6094 | } | |
c906108c | 6095 | |
9373cf26 JK |
6096 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6097 | if (high <= low) | |
c906108c SS |
6098 | return 0; |
6099 | ||
6100 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6101 | eliminate duplicate copies of functions and vtables and such. | |
6102 | The linker will arbitrarily choose one and discard the others. | |
6103 | The AT_*_pc values for such functions refer to local labels in | |
6104 | these sections. If the section from that file was discarded, the | |
6105 | labels are not in the output, so the relocs get a value of 0. | |
6106 | If this is a discarded function, mark the pc bounds as invalid, | |
6107 | so that GDB will ignore it. */ | |
72dca2f5 | 6108 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6109 | return 0; |
6110 | ||
6111 | *lowpc = low; | |
6112 | *highpc = high; | |
af34e669 | 6113 | return ret; |
c906108c SS |
6114 | } |
6115 | ||
b084d499 JB |
6116 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6117 | its low and high PC addresses. Do nothing if these addresses could not | |
6118 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6119 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6120 | ||
6121 | static void | |
6122 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6123 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6124 | struct dwarf2_cu *cu) | |
6125 | { | |
6126 | CORE_ADDR low, high; | |
6127 | struct die_info *child = die->child; | |
6128 | ||
d85a05f0 | 6129 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6130 | { |
6131 | *lowpc = min (*lowpc, low); | |
6132 | *highpc = max (*highpc, high); | |
6133 | } | |
6134 | ||
6135 | /* If the language does not allow nested subprograms (either inside | |
6136 | subprograms or lexical blocks), we're done. */ | |
6137 | if (cu->language != language_ada) | |
6138 | return; | |
6e70227d | 6139 | |
b084d499 JB |
6140 | /* Check all the children of the given DIE. If it contains nested |
6141 | subprograms, then check their pc bounds. Likewise, we need to | |
6142 | check lexical blocks as well, as they may also contain subprogram | |
6143 | definitions. */ | |
6144 | while (child && child->tag) | |
6145 | { | |
6146 | if (child->tag == DW_TAG_subprogram | |
6147 | || child->tag == DW_TAG_lexical_block) | |
6148 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6149 | child = sibling_die (child); | |
6150 | } | |
6151 | } | |
6152 | ||
fae299cd DC |
6153 | /* Get the low and high pc's represented by the scope DIE, and store |
6154 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6155 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6156 | ||
6157 | static void | |
6158 | get_scope_pc_bounds (struct die_info *die, | |
6159 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6160 | struct dwarf2_cu *cu) | |
6161 | { | |
6162 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6163 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6164 | CORE_ADDR current_low, current_high; | |
6165 | ||
d85a05f0 | 6166 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6167 | { |
6168 | best_low = current_low; | |
6169 | best_high = current_high; | |
6170 | } | |
6171 | else | |
6172 | { | |
6173 | struct die_info *child = die->child; | |
6174 | ||
6175 | while (child && child->tag) | |
6176 | { | |
6177 | switch (child->tag) { | |
6178 | case DW_TAG_subprogram: | |
b084d499 | 6179 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6180 | break; |
6181 | case DW_TAG_namespace: | |
f55ee35c | 6182 | case DW_TAG_module: |
fae299cd DC |
6183 | /* FIXME: carlton/2004-01-16: Should we do this for |
6184 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6185 | that current GCC's always emit the DIEs corresponding | |
6186 | to definitions of methods of classes as children of a | |
6187 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6188 | the DIEs giving the declarations, which could be | |
6189 | anywhere). But I don't see any reason why the | |
6190 | standards says that they have to be there. */ | |
6191 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6192 | ||
6193 | if (current_low != ((CORE_ADDR) -1)) | |
6194 | { | |
6195 | best_low = min (best_low, current_low); | |
6196 | best_high = max (best_high, current_high); | |
6197 | } | |
6198 | break; | |
6199 | default: | |
0963b4bd | 6200 | /* Ignore. */ |
fae299cd DC |
6201 | break; |
6202 | } | |
6203 | ||
6204 | child = sibling_die (child); | |
6205 | } | |
6206 | } | |
6207 | ||
6208 | *lowpc = best_low; | |
6209 | *highpc = best_high; | |
6210 | } | |
6211 | ||
801e3a5b JB |
6212 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
6213 | in DIE. */ | |
6214 | static void | |
6215 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
6216 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
6217 | { | |
6218 | struct attribute *attr; | |
6219 | ||
6220 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
6221 | if (attr) | |
6222 | { | |
6223 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 6224 | |
801e3a5b JB |
6225 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
6226 | if (attr) | |
6227 | { | |
6228 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 6229 | |
801e3a5b JB |
6230 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
6231 | } | |
6232 | } | |
6233 | ||
6234 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
6235 | if (attr) | |
6236 | { | |
6237 | bfd *obfd = cu->objfile->obfd; | |
6238 | ||
6239 | /* The value of the DW_AT_ranges attribute is the offset of the | |
6240 | address range list in the .debug_ranges section. */ | |
6241 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 6242 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
6243 | |
6244 | /* For some target architectures, but not others, the | |
6245 | read_address function sign-extends the addresses it returns. | |
6246 | To recognize base address selection entries, we need a | |
6247 | mask. */ | |
6248 | unsigned int addr_size = cu->header.addr_size; | |
6249 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6250 | ||
6251 | /* The base address, to which the next pair is relative. Note | |
6252 | that this 'base' is a DWARF concept: most entries in a range | |
6253 | list are relative, to reduce the number of relocs against the | |
6254 | debugging information. This is separate from this function's | |
6255 | 'baseaddr' argument, which GDB uses to relocate debugging | |
6256 | information from a shared library based on the address at | |
6257 | which the library was loaded. */ | |
d00adf39 DE |
6258 | CORE_ADDR base = cu->base_address; |
6259 | int base_known = cu->base_known; | |
801e3a5b | 6260 | |
be391dca | 6261 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 6262 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
6263 | { |
6264 | complaint (&symfile_complaints, | |
6265 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
6266 | offset); | |
6267 | return; | |
6268 | } | |
6269 | ||
6270 | for (;;) | |
6271 | { | |
6272 | unsigned int bytes_read; | |
6273 | CORE_ADDR start, end; | |
6274 | ||
6275 | start = read_address (obfd, buffer, cu, &bytes_read); | |
6276 | buffer += bytes_read; | |
6277 | end = read_address (obfd, buffer, cu, &bytes_read); | |
6278 | buffer += bytes_read; | |
6279 | ||
6280 | /* Did we find the end of the range list? */ | |
6281 | if (start == 0 && end == 0) | |
6282 | break; | |
6283 | ||
6284 | /* Did we find a base address selection entry? */ | |
6285 | else if ((start & base_select_mask) == base_select_mask) | |
6286 | { | |
6287 | base = end; | |
6288 | base_known = 1; | |
6289 | } | |
6290 | ||
6291 | /* We found an ordinary address range. */ | |
6292 | else | |
6293 | { | |
6294 | if (!base_known) | |
6295 | { | |
6296 | complaint (&symfile_complaints, | |
3e43a32a MS |
6297 | _("Invalid .debug_ranges data " |
6298 | "(no base address)")); | |
801e3a5b JB |
6299 | return; |
6300 | } | |
6301 | ||
9277c30c UW |
6302 | if (start > end) |
6303 | { | |
6304 | /* Inverted range entries are invalid. */ | |
6305 | complaint (&symfile_complaints, | |
6306 | _("Invalid .debug_ranges data " | |
6307 | "(inverted range)")); | |
6308 | return; | |
6309 | } | |
6310 | ||
6311 | /* Empty range entries have no effect. */ | |
6312 | if (start == end) | |
6313 | continue; | |
6314 | ||
6e70227d DE |
6315 | record_block_range (block, |
6316 | baseaddr + base + start, | |
801e3a5b JB |
6317 | baseaddr + base + end - 1); |
6318 | } | |
6319 | } | |
6320 | } | |
6321 | } | |
6322 | ||
60d5a603 JK |
6323 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
6324 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
6325 | during 4.6.0 experimental. */ | |
6326 | ||
6327 | static int | |
6328 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
6329 | { | |
6330 | const char *cs; | |
6331 | int major, minor, release; | |
6332 | ||
6333 | if (cu->producer == NULL) | |
6334 | { | |
6335 | /* For unknown compilers expect their behavior is DWARF version | |
6336 | compliant. | |
6337 | ||
6338 | GCC started to support .debug_types sections by -gdwarf-4 since | |
6339 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
6340 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
6341 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
6342 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
6343 | ||
6344 | return 0; | |
6345 | } | |
6346 | ||
6347 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ | |
6348 | ||
6349 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
6350 | { | |
6351 | /* For non-GCC compilers expect their behavior is DWARF version | |
6352 | compliant. */ | |
6353 | ||
6354 | return 0; | |
6355 | } | |
6356 | cs = &cu->producer[strlen ("GNU ")]; | |
6357 | while (*cs && !isdigit (*cs)) | |
6358 | cs++; | |
6359 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
6360 | { | |
6361 | /* Not recognized as GCC. */ | |
6362 | ||
6363 | return 0; | |
6364 | } | |
6365 | ||
6366 | return major < 4 || (major == 4 && minor < 6); | |
6367 | } | |
6368 | ||
6369 | /* Return the default accessibility type if it is not overriden by | |
6370 | DW_AT_accessibility. */ | |
6371 | ||
6372 | static enum dwarf_access_attribute | |
6373 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
6374 | { | |
6375 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
6376 | { | |
6377 | /* The default DWARF 2 accessibility for members is public, the default | |
6378 | accessibility for inheritance is private. */ | |
6379 | ||
6380 | if (die->tag != DW_TAG_inheritance) | |
6381 | return DW_ACCESS_public; | |
6382 | else | |
6383 | return DW_ACCESS_private; | |
6384 | } | |
6385 | else | |
6386 | { | |
6387 | /* DWARF 3+ defines the default accessibility a different way. The same | |
6388 | rules apply now for DW_TAG_inheritance as for the members and it only | |
6389 | depends on the container kind. */ | |
6390 | ||
6391 | if (die->parent->tag == DW_TAG_class_type) | |
6392 | return DW_ACCESS_private; | |
6393 | else | |
6394 | return DW_ACCESS_public; | |
6395 | } | |
6396 | } | |
6397 | ||
74ac6d43 TT |
6398 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
6399 | offset. If the attribute was not found return 0, otherwise return | |
6400 | 1. If it was found but could not properly be handled, set *OFFSET | |
6401 | to 0. */ | |
6402 | ||
6403 | static int | |
6404 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
6405 | LONGEST *offset) | |
6406 | { | |
6407 | struct attribute *attr; | |
6408 | ||
6409 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
6410 | if (attr != NULL) | |
6411 | { | |
6412 | *offset = 0; | |
6413 | ||
6414 | /* Note that we do not check for a section offset first here. | |
6415 | This is because DW_AT_data_member_location is new in DWARF 4, | |
6416 | so if we see it, we can assume that a constant form is really | |
6417 | a constant and not a section offset. */ | |
6418 | if (attr_form_is_constant (attr)) | |
6419 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
6420 | else if (attr_form_is_section_offset (attr)) | |
6421 | dwarf2_complex_location_expr_complaint (); | |
6422 | else if (attr_form_is_block (attr)) | |
6423 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6424 | else | |
6425 | dwarf2_complex_location_expr_complaint (); | |
6426 | ||
6427 | return 1; | |
6428 | } | |
6429 | ||
6430 | return 0; | |
6431 | } | |
6432 | ||
c906108c SS |
6433 | /* Add an aggregate field to the field list. */ |
6434 | ||
6435 | static void | |
107d2387 | 6436 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6437 | struct dwarf2_cu *cu) |
6e70227d | 6438 | { |
e7c27a73 | 6439 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6440 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6441 | struct nextfield *new_field; |
6442 | struct attribute *attr; | |
6443 | struct field *fp; | |
6444 | char *fieldname = ""; | |
6445 | ||
6446 | /* Allocate a new field list entry and link it in. */ | |
6447 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6448 | make_cleanup (xfree, new_field); |
c906108c | 6449 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6450 | |
6451 | if (die->tag == DW_TAG_inheritance) | |
6452 | { | |
6453 | new_field->next = fip->baseclasses; | |
6454 | fip->baseclasses = new_field; | |
6455 | } | |
6456 | else | |
6457 | { | |
6458 | new_field->next = fip->fields; | |
6459 | fip->fields = new_field; | |
6460 | } | |
c906108c SS |
6461 | fip->nfields++; |
6462 | ||
e142c38c | 6463 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6464 | if (attr) |
6465 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
6466 | else |
6467 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
6468 | if (new_field->accessibility != DW_ACCESS_public) |
6469 | fip->non_public_fields = 1; | |
60d5a603 | 6470 | |
e142c38c | 6471 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6472 | if (attr) |
6473 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
6474 | else |
6475 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
6476 | |
6477 | fp = &new_field->field; | |
a9a9bd0f | 6478 | |
e142c38c | 6479 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6480 | { |
74ac6d43 TT |
6481 | LONGEST offset; |
6482 | ||
a9a9bd0f | 6483 | /* Data member other than a C++ static data member. */ |
6e70227d | 6484 | |
c906108c | 6485 | /* Get type of field. */ |
e7c27a73 | 6486 | fp->type = die_type (die, cu); |
c906108c | 6487 | |
d6a843b5 | 6488 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6489 | |
c906108c | 6490 | /* Get bit size of field (zero if none). */ |
e142c38c | 6491 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6492 | if (attr) |
6493 | { | |
6494 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6495 | } | |
6496 | else | |
6497 | { | |
6498 | FIELD_BITSIZE (*fp) = 0; | |
6499 | } | |
6500 | ||
6501 | /* Get bit offset of field. */ | |
74ac6d43 TT |
6502 | if (handle_data_member_location (die, cu, &offset)) |
6503 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 6504 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6505 | if (attr) |
6506 | { | |
5e2b427d | 6507 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6508 | { |
6509 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6510 | additional bit offset from the MSB of the containing |
6511 | anonymous object to the MSB of the field. We don't | |
6512 | have to do anything special since we don't need to | |
6513 | know the size of the anonymous object. */ | |
c906108c SS |
6514 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6515 | } | |
6516 | else | |
6517 | { | |
6518 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6519 | MSB of the anonymous object, subtract off the number of |
6520 | bits from the MSB of the field to the MSB of the | |
6521 | object, and then subtract off the number of bits of | |
6522 | the field itself. The result is the bit offset of | |
6523 | the LSB of the field. */ | |
c906108c SS |
6524 | int anonymous_size; |
6525 | int bit_offset = DW_UNSND (attr); | |
6526 | ||
e142c38c | 6527 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6528 | if (attr) |
6529 | { | |
6530 | /* The size of the anonymous object containing | |
6531 | the bit field is explicit, so use the | |
6532 | indicated size (in bytes). */ | |
6533 | anonymous_size = DW_UNSND (attr); | |
6534 | } | |
6535 | else | |
6536 | { | |
6537 | /* The size of the anonymous object containing | |
6538 | the bit field must be inferred from the type | |
6539 | attribute of the data member containing the | |
6540 | bit field. */ | |
6541 | anonymous_size = TYPE_LENGTH (fp->type); | |
6542 | } | |
6543 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
6544 | - bit_offset - FIELD_BITSIZE (*fp); | |
6545 | } | |
6546 | } | |
6547 | ||
6548 | /* Get name of field. */ | |
39cbfefa DJ |
6549 | fieldname = dwarf2_name (die, cu); |
6550 | if (fieldname == NULL) | |
6551 | fieldname = ""; | |
d8151005 DJ |
6552 | |
6553 | /* The name is already allocated along with this objfile, so we don't | |
6554 | need to duplicate it for the type. */ | |
6555 | fp->name = fieldname; | |
c906108c SS |
6556 | |
6557 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 6558 | pointer or virtual base class pointer) to private. */ |
e142c38c | 6559 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 6560 | { |
d48cc9dd | 6561 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
6562 | new_field->accessibility = DW_ACCESS_private; |
6563 | fip->non_public_fields = 1; | |
6564 | } | |
6565 | } | |
a9a9bd0f | 6566 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 6567 | { |
a9a9bd0f DC |
6568 | /* C++ static member. */ |
6569 | ||
6570 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
6571 | is a declaration, but all versions of G++ as of this writing | |
6572 | (so through at least 3.2.1) incorrectly generate | |
6573 | DW_TAG_variable tags. */ | |
6e70227d | 6574 | |
ff355380 | 6575 | const char *physname; |
c906108c | 6576 | |
a9a9bd0f | 6577 | /* Get name of field. */ |
39cbfefa DJ |
6578 | fieldname = dwarf2_name (die, cu); |
6579 | if (fieldname == NULL) | |
c906108c SS |
6580 | return; |
6581 | ||
254e6b9e | 6582 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
6583 | if (attr |
6584 | /* Only create a symbol if this is an external value. | |
6585 | new_symbol checks this and puts the value in the global symbol | |
6586 | table, which we want. If it is not external, new_symbol | |
6587 | will try to put the value in cu->list_in_scope which is wrong. */ | |
6588 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
6589 | { |
6590 | /* A static const member, not much different than an enum as far as | |
6591 | we're concerned, except that we can support more types. */ | |
6592 | new_symbol (die, NULL, cu); | |
6593 | } | |
6594 | ||
2df3850c | 6595 | /* Get physical name. */ |
ff355380 | 6596 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 6597 | |
d8151005 DJ |
6598 | /* The name is already allocated along with this objfile, so we don't |
6599 | need to duplicate it for the type. */ | |
6600 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 6601 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 6602 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
6603 | } |
6604 | else if (die->tag == DW_TAG_inheritance) | |
6605 | { | |
74ac6d43 | 6606 | LONGEST offset; |
d4b96c9a | 6607 | |
74ac6d43 TT |
6608 | /* C++ base class field. */ |
6609 | if (handle_data_member_location (die, cu, &offset)) | |
6610 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 6611 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 6612 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
6613 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
6614 | fip->nbaseclasses++; | |
6615 | } | |
6616 | } | |
6617 | ||
98751a41 JK |
6618 | /* Add a typedef defined in the scope of the FIP's class. */ |
6619 | ||
6620 | static void | |
6621 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
6622 | struct dwarf2_cu *cu) | |
6e70227d | 6623 | { |
98751a41 | 6624 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
6625 | struct typedef_field_list *new_field; |
6626 | struct attribute *attr; | |
6627 | struct typedef_field *fp; | |
6628 | char *fieldname = ""; | |
6629 | ||
6630 | /* Allocate a new field list entry and link it in. */ | |
6631 | new_field = xzalloc (sizeof (*new_field)); | |
6632 | make_cleanup (xfree, new_field); | |
6633 | ||
6634 | gdb_assert (die->tag == DW_TAG_typedef); | |
6635 | ||
6636 | fp = &new_field->field; | |
6637 | ||
6638 | /* Get name of field. */ | |
6639 | fp->name = dwarf2_name (die, cu); | |
6640 | if (fp->name == NULL) | |
6641 | return; | |
6642 | ||
6643 | fp->type = read_type_die (die, cu); | |
6644 | ||
6645 | new_field->next = fip->typedef_field_list; | |
6646 | fip->typedef_field_list = new_field; | |
6647 | fip->typedef_field_list_count++; | |
6648 | } | |
6649 | ||
c906108c SS |
6650 | /* Create the vector of fields, and attach it to the type. */ |
6651 | ||
6652 | static void | |
fba45db2 | 6653 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6654 | struct dwarf2_cu *cu) |
c906108c SS |
6655 | { |
6656 | int nfields = fip->nfields; | |
6657 | ||
6658 | /* Record the field count, allocate space for the array of fields, | |
6659 | and create blank accessibility bitfields if necessary. */ | |
6660 | TYPE_NFIELDS (type) = nfields; | |
6661 | TYPE_FIELDS (type) = (struct field *) | |
6662 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
6663 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
6664 | ||
b4ba55a1 | 6665 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
6666 | { |
6667 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
6668 | ||
6669 | TYPE_FIELD_PRIVATE_BITS (type) = | |
6670 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6671 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
6672 | ||
6673 | TYPE_FIELD_PROTECTED_BITS (type) = | |
6674 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6675 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
6676 | ||
774b6a14 TT |
6677 | TYPE_FIELD_IGNORE_BITS (type) = |
6678 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6679 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
6680 | } |
6681 | ||
6682 | /* If the type has baseclasses, allocate and clear a bit vector for | |
6683 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 6684 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
6685 | { |
6686 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 6687 | unsigned char *pointer; |
c906108c SS |
6688 | |
6689 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
6690 | pointer = TYPE_ALLOC (type, num_bytes); |
6691 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
6692 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
6693 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
6694 | } | |
6695 | ||
3e43a32a MS |
6696 | /* Copy the saved-up fields into the field vector. Start from the head of |
6697 | the list, adding to the tail of the field array, so that they end up in | |
6698 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
6699 | while (nfields-- > 0) |
6700 | { | |
7d0ccb61 DJ |
6701 | struct nextfield *fieldp; |
6702 | ||
6703 | if (fip->fields) | |
6704 | { | |
6705 | fieldp = fip->fields; | |
6706 | fip->fields = fieldp->next; | |
6707 | } | |
6708 | else | |
6709 | { | |
6710 | fieldp = fip->baseclasses; | |
6711 | fip->baseclasses = fieldp->next; | |
6712 | } | |
6713 | ||
6714 | TYPE_FIELD (type, nfields) = fieldp->field; | |
6715 | switch (fieldp->accessibility) | |
c906108c | 6716 | { |
c5aa993b | 6717 | case DW_ACCESS_private: |
b4ba55a1 JB |
6718 | if (cu->language != language_ada) |
6719 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 6720 | break; |
c906108c | 6721 | |
c5aa993b | 6722 | case DW_ACCESS_protected: |
b4ba55a1 JB |
6723 | if (cu->language != language_ada) |
6724 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 6725 | break; |
c906108c | 6726 | |
c5aa993b JM |
6727 | case DW_ACCESS_public: |
6728 | break; | |
c906108c | 6729 | |
c5aa993b JM |
6730 | default: |
6731 | /* Unknown accessibility. Complain and treat it as public. */ | |
6732 | { | |
e2e0b3e5 | 6733 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 6734 | fieldp->accessibility); |
c5aa993b JM |
6735 | } |
6736 | break; | |
c906108c SS |
6737 | } |
6738 | if (nfields < fip->nbaseclasses) | |
6739 | { | |
7d0ccb61 | 6740 | switch (fieldp->virtuality) |
c906108c | 6741 | { |
c5aa993b JM |
6742 | case DW_VIRTUALITY_virtual: |
6743 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 6744 | if (cu->language == language_ada) |
a73c6dcd | 6745 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
6746 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
6747 | break; | |
c906108c SS |
6748 | } |
6749 | } | |
c906108c SS |
6750 | } |
6751 | } | |
6752 | ||
c906108c SS |
6753 | /* Add a member function to the proper fieldlist. */ |
6754 | ||
6755 | static void | |
107d2387 | 6756 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6757 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 6758 | { |
e7c27a73 | 6759 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6760 | struct attribute *attr; |
6761 | struct fnfieldlist *flp; | |
6762 | int i; | |
6763 | struct fn_field *fnp; | |
6764 | char *fieldname; | |
c906108c | 6765 | struct nextfnfield *new_fnfield; |
f792889a | 6766 | struct type *this_type; |
60d5a603 | 6767 | enum dwarf_access_attribute accessibility; |
c906108c | 6768 | |
b4ba55a1 | 6769 | if (cu->language == language_ada) |
a73c6dcd | 6770 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 6771 | |
2df3850c | 6772 | /* Get name of member function. */ |
39cbfefa DJ |
6773 | fieldname = dwarf2_name (die, cu); |
6774 | if (fieldname == NULL) | |
2df3850c | 6775 | return; |
c906108c | 6776 | |
c906108c SS |
6777 | /* Look up member function name in fieldlist. */ |
6778 | for (i = 0; i < fip->nfnfields; i++) | |
6779 | { | |
27bfe10e | 6780 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
6781 | break; |
6782 | } | |
6783 | ||
6784 | /* Create new list element if necessary. */ | |
6785 | if (i < fip->nfnfields) | |
6786 | flp = &fip->fnfieldlists[i]; | |
6787 | else | |
6788 | { | |
6789 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
6790 | { | |
6791 | fip->fnfieldlists = (struct fnfieldlist *) | |
6792 | xrealloc (fip->fnfieldlists, | |
6793 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 6794 | * sizeof (struct fnfieldlist)); |
c906108c | 6795 | if (fip->nfnfields == 0) |
c13c43fd | 6796 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
6797 | } |
6798 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
6799 | flp->name = fieldname; | |
6800 | flp->length = 0; | |
6801 | flp->head = NULL; | |
3da10d80 | 6802 | i = fip->nfnfields++; |
c906108c SS |
6803 | } |
6804 | ||
6805 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 6806 | entry. */ |
c906108c | 6807 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 6808 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
6809 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
6810 | new_fnfield->next = flp->head; | |
6811 | flp->head = new_fnfield; | |
6812 | flp->length++; | |
6813 | ||
6814 | /* Fill in the member function field info. */ | |
6815 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
6816 | |
6817 | /* Delay processing of the physname until later. */ | |
6818 | if (cu->language == language_cplus || cu->language == language_java) | |
6819 | { | |
6820 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
6821 | die, cu); | |
6822 | } | |
6823 | else | |
6824 | { | |
1d06ead6 | 6825 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
6826 | fnp->physname = physname ? physname : ""; |
6827 | } | |
6828 | ||
c906108c | 6829 | fnp->type = alloc_type (objfile); |
f792889a DJ |
6830 | this_type = read_type_die (die, cu); |
6831 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 6832 | { |
f792889a | 6833 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 6834 | |
f792889a | 6835 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
6836 | of the method itself (TYPE_CODE_METHOD). */ |
6837 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
6838 | TYPE_TARGET_TYPE (this_type), |
6839 | TYPE_FIELDS (this_type), | |
6840 | TYPE_NFIELDS (this_type), | |
6841 | TYPE_VARARGS (this_type)); | |
c906108c SS |
6842 | |
6843 | /* Handle static member functions. | |
c5aa993b | 6844 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
6845 | member functions. G++ helps GDB by marking the first |
6846 | parameter for non-static member functions (which is the this | |
6847 | pointer) as artificial. We obtain this information from | |
6848 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 6849 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
6850 | fnp->voffset = VOFFSET_STATIC; |
6851 | } | |
6852 | else | |
e2e0b3e5 | 6853 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 6854 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
6855 | |
6856 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 6857 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 6858 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 6859 | |
3e43a32a MS |
6860 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
6861 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
6862 | |
6863 | /* Get accessibility. */ | |
e142c38c | 6864 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 6865 | if (attr) |
60d5a603 JK |
6866 | accessibility = DW_UNSND (attr); |
6867 | else | |
6868 | accessibility = dwarf2_default_access_attribute (die, cu); | |
6869 | switch (accessibility) | |
c906108c | 6870 | { |
60d5a603 JK |
6871 | case DW_ACCESS_private: |
6872 | fnp->is_private = 1; | |
6873 | break; | |
6874 | case DW_ACCESS_protected: | |
6875 | fnp->is_protected = 1; | |
6876 | break; | |
c906108c SS |
6877 | } |
6878 | ||
b02dede2 | 6879 | /* Check for artificial methods. */ |
e142c38c | 6880 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
6881 | if (attr && DW_UNSND (attr) != 0) |
6882 | fnp->is_artificial = 1; | |
6883 | ||
0d564a31 | 6884 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
6885 | function. For older versions of GCC, this is an offset in the |
6886 | appropriate virtual table, as specified by DW_AT_containing_type. | |
6887 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
6888 | to the object address. */ |
6889 | ||
e142c38c | 6890 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 6891 | if (attr) |
8e19ed76 | 6892 | { |
aec5aa8b | 6893 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 6894 | { |
aec5aa8b TT |
6895 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
6896 | { | |
6897 | /* Old-style GCC. */ | |
6898 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
6899 | } | |
6900 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6901 | || (DW_BLOCK (attr)->size > 1 | |
6902 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
6903 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
6904 | { | |
6905 | struct dwarf_block blk; | |
6906 | int offset; | |
6907 | ||
6908 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6909 | ? 1 : 2); | |
6910 | blk.size = DW_BLOCK (attr)->size - offset; | |
6911 | blk.data = DW_BLOCK (attr)->data + offset; | |
6912 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
6913 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
6914 | dwarf2_complex_location_expr_complaint (); | |
6915 | else | |
6916 | fnp->voffset /= cu->header.addr_size; | |
6917 | fnp->voffset += 2; | |
6918 | } | |
6919 | else | |
6920 | dwarf2_complex_location_expr_complaint (); | |
6921 | ||
6922 | if (!fnp->fcontext) | |
6923 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
6924 | } | |
3690dd37 | 6925 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 6926 | { |
4d3c2250 | 6927 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6928 | } |
6929 | else | |
6930 | { | |
4d3c2250 KB |
6931 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
6932 | fieldname); | |
8e19ed76 | 6933 | } |
0d564a31 | 6934 | } |
d48cc9dd DJ |
6935 | else |
6936 | { | |
6937 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
6938 | if (attr && DW_UNSND (attr)) | |
6939 | { | |
6940 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
6941 | complaint (&symfile_complaints, | |
3e43a32a MS |
6942 | _("Member function \"%s\" (offset %d) is virtual " |
6943 | "but the vtable offset is not specified"), | |
d48cc9dd | 6944 | fieldname, die->offset); |
9655fd1a | 6945 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
6946 | TYPE_CPLUS_DYNAMIC (type) = 1; |
6947 | } | |
6948 | } | |
c906108c SS |
6949 | } |
6950 | ||
6951 | /* Create the vector of member function fields, and attach it to the type. */ | |
6952 | ||
6953 | static void | |
fba45db2 | 6954 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6955 | struct dwarf2_cu *cu) |
c906108c SS |
6956 | { |
6957 | struct fnfieldlist *flp; | |
6958 | int total_length = 0; | |
6959 | int i; | |
6960 | ||
b4ba55a1 | 6961 | if (cu->language == language_ada) |
a73c6dcd | 6962 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 6963 | |
c906108c SS |
6964 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
6965 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
6966 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
6967 | ||
6968 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
6969 | { | |
6970 | struct nextfnfield *nfp = flp->head; | |
6971 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
6972 | int k; | |
6973 | ||
6974 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
6975 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
6976 | fn_flp->fn_fields = (struct fn_field *) | |
6977 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
6978 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 6979 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
6980 | |
6981 | total_length += flp->length; | |
6982 | } | |
6983 | ||
6984 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
6985 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
6986 | } | |
6987 | ||
1168df01 JB |
6988 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
6989 | language, zero otherwise. */ | |
6990 | static int | |
6991 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
6992 | { | |
6993 | static const char vptr[] = "_vptr"; | |
987504bb | 6994 | static const char vtable[] = "vtable"; |
1168df01 | 6995 | |
987504bb JJ |
6996 | /* Look for the C++ and Java forms of the vtable. */ |
6997 | if ((cu->language == language_java | |
6998 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
6999 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
7000 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
7001 | return 1; |
7002 | ||
7003 | return 0; | |
7004 | } | |
7005 | ||
c0dd20ea | 7006 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
7007 | functions, with the ABI-specified layout. If TYPE describes |
7008 | such a structure, smash it into a member function type. | |
61049d3b DJ |
7009 | |
7010 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
7011 | This is GCC PR debug/28767. */ | |
c0dd20ea | 7012 | |
0b92b5bb TT |
7013 | static void |
7014 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 7015 | { |
0b92b5bb | 7016 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
7017 | |
7018 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
7019 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
7020 | return; | |
c0dd20ea DJ |
7021 | |
7022 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
7023 | if (TYPE_FIELD_NAME (type, 0) == NULL |
7024 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
7025 | || TYPE_FIELD_NAME (type, 1) == NULL | |
7026 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
7027 | return; | |
c0dd20ea DJ |
7028 | |
7029 | /* Find the type of the method. */ | |
0b92b5bb | 7030 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
7031 | if (pfn_type == NULL |
7032 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
7033 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 7034 | return; |
c0dd20ea DJ |
7035 | |
7036 | /* Look for the "this" argument. */ | |
7037 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
7038 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 7039 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 7040 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 7041 | return; |
c0dd20ea DJ |
7042 | |
7043 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
7044 | new_type = alloc_type (objfile); |
7045 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
7046 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
7047 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 7048 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 7049 | } |
1168df01 | 7050 | |
c906108c | 7051 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
7052 | (definition) to create a type for the structure or union. Fill in |
7053 | the type's name and general properties; the members will not be | |
7054 | processed until process_structure_type. | |
c906108c | 7055 | |
c767944b DJ |
7056 | NOTE: we need to call these functions regardless of whether or not the |
7057 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
7058 | structure or union. This gets the type entered into our set of |
7059 | user defined types. | |
7060 | ||
7061 | However, if the structure is incomplete (an opaque struct/union) | |
7062 | then suppress creating a symbol table entry for it since gdb only | |
7063 | wants to find the one with the complete definition. Note that if | |
7064 | it is complete, we just call new_symbol, which does it's own | |
7065 | checking about whether the struct/union is anonymous or not (and | |
7066 | suppresses creating a symbol table entry itself). */ | |
7067 | ||
f792889a | 7068 | static struct type * |
134d01f1 | 7069 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7070 | { |
e7c27a73 | 7071 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7072 | struct type *type; |
7073 | struct attribute *attr; | |
39cbfefa | 7074 | char *name; |
c906108c | 7075 | |
348e048f DE |
7076 | /* If the definition of this type lives in .debug_types, read that type. |
7077 | Don't follow DW_AT_specification though, that will take us back up | |
7078 | the chain and we want to go down. */ | |
7079 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7080 | if (attr) | |
7081 | { | |
7082 | struct dwarf2_cu *type_cu = cu; | |
7083 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7084 | |
348e048f DE |
7085 | /* We could just recurse on read_structure_type, but we need to call |
7086 | get_die_type to ensure only one type for this DIE is created. | |
7087 | This is important, for example, because for c++ classes we need | |
7088 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
7089 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
7090 | |
7091 | /* TYPE_CU may not be the same as CU. | |
7092 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7093 | return set_die_type (die, type, cu); |
7094 | } | |
7095 | ||
c0dd20ea | 7096 | type = alloc_type (objfile); |
c906108c | 7097 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 7098 | |
39cbfefa DJ |
7099 | name = dwarf2_name (die, cu); |
7100 | if (name != NULL) | |
c906108c | 7101 | { |
987504bb JJ |
7102 | if (cu->language == language_cplus |
7103 | || cu->language == language_java) | |
63d06c5c | 7104 | { |
3da10d80 KS |
7105 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
7106 | ||
7107 | /* dwarf2_full_name might have already finished building the DIE's | |
7108 | type. If so, there is no need to continue. */ | |
7109 | if (get_die_type (die, cu) != NULL) | |
7110 | return get_die_type (die, cu); | |
7111 | ||
7112 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
7113 | if (die->tag == DW_TAG_structure_type |
7114 | || die->tag == DW_TAG_class_type) | |
7115 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
7116 | } |
7117 | else | |
7118 | { | |
d8151005 DJ |
7119 | /* The name is already allocated along with this objfile, so |
7120 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
7121 | TYPE_TAG_NAME (type) = (char *) name; |
7122 | if (die->tag == DW_TAG_class_type) | |
7123 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 7124 | } |
c906108c SS |
7125 | } |
7126 | ||
7127 | if (die->tag == DW_TAG_structure_type) | |
7128 | { | |
7129 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
7130 | } | |
7131 | else if (die->tag == DW_TAG_union_type) | |
7132 | { | |
7133 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
7134 | } | |
7135 | else | |
7136 | { | |
c906108c SS |
7137 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
7138 | } | |
7139 | ||
0cc2414c TT |
7140 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
7141 | TYPE_DECLARED_CLASS (type) = 1; | |
7142 | ||
e142c38c | 7143 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7144 | if (attr) |
7145 | { | |
7146 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7147 | } | |
7148 | else | |
7149 | { | |
7150 | TYPE_LENGTH (type) = 0; | |
7151 | } | |
7152 | ||
876cecd0 | 7153 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 7154 | if (die_is_declaration (die, cu)) |
876cecd0 | 7155 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
7156 | else if (attr == NULL && die->child == NULL |
7157 | && producer_is_realview (cu->producer)) | |
7158 | /* RealView does not output the required DW_AT_declaration | |
7159 | on incomplete types. */ | |
7160 | TYPE_STUB (type) = 1; | |
dc718098 | 7161 | |
c906108c SS |
7162 | /* We need to add the type field to the die immediately so we don't |
7163 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 7164 | type within the structure itself. */ |
1c379e20 | 7165 | set_die_type (die, type, cu); |
c906108c | 7166 | |
7e314c57 JK |
7167 | /* set_die_type should be already done. */ |
7168 | set_descriptive_type (type, die, cu); | |
7169 | ||
c767944b DJ |
7170 | return type; |
7171 | } | |
7172 | ||
7173 | /* Finish creating a structure or union type, including filling in | |
7174 | its members and creating a symbol for it. */ | |
7175 | ||
7176 | static void | |
7177 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7178 | { | |
7179 | struct objfile *objfile = cu->objfile; | |
7180 | struct die_info *child_die = die->child; | |
7181 | struct type *type; | |
7182 | ||
7183 | type = get_die_type (die, cu); | |
7184 | if (type == NULL) | |
7185 | type = read_structure_type (die, cu); | |
7186 | ||
e142c38c | 7187 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
7188 | { |
7189 | struct field_info fi; | |
7190 | struct die_info *child_die; | |
34eaf542 | 7191 | VEC (symbolp) *template_args = NULL; |
c767944b | 7192 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
7193 | |
7194 | memset (&fi, 0, sizeof (struct field_info)); | |
7195 | ||
639d11d3 | 7196 | child_die = die->child; |
c906108c SS |
7197 | |
7198 | while (child_die && child_die->tag) | |
7199 | { | |
a9a9bd0f DC |
7200 | if (child_die->tag == DW_TAG_member |
7201 | || child_die->tag == DW_TAG_variable) | |
c906108c | 7202 | { |
a9a9bd0f DC |
7203 | /* NOTE: carlton/2002-11-05: A C++ static data member |
7204 | should be a DW_TAG_member that is a declaration, but | |
7205 | all versions of G++ as of this writing (so through at | |
7206 | least 3.2.1) incorrectly generate DW_TAG_variable | |
7207 | tags for them instead. */ | |
e7c27a73 | 7208 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7209 | } |
8713b1b1 | 7210 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 7211 | { |
0963b4bd | 7212 | /* C++ member function. */ |
e7c27a73 | 7213 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
7214 | } |
7215 | else if (child_die->tag == DW_TAG_inheritance) | |
7216 | { | |
7217 | /* C++ base class field. */ | |
e7c27a73 | 7218 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7219 | } |
98751a41 JK |
7220 | else if (child_die->tag == DW_TAG_typedef) |
7221 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
7222 | else if (child_die->tag == DW_TAG_template_type_param |
7223 | || child_die->tag == DW_TAG_template_value_param) | |
7224 | { | |
7225 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7226 | ||
f1078f66 DJ |
7227 | if (arg != NULL) |
7228 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7229 | } |
7230 | ||
c906108c SS |
7231 | child_die = sibling_die (child_die); |
7232 | } | |
7233 | ||
34eaf542 TT |
7234 | /* Attach template arguments to type. */ |
7235 | if (! VEC_empty (symbolp, template_args)) | |
7236 | { | |
7237 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7238 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7239 | = VEC_length (symbolp, template_args); | |
7240 | TYPE_TEMPLATE_ARGUMENTS (type) | |
7241 | = obstack_alloc (&objfile->objfile_obstack, | |
7242 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7243 | * sizeof (struct symbol *))); | |
7244 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
7245 | VEC_address (symbolp, template_args), | |
7246 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7247 | * sizeof (struct symbol *))); | |
7248 | VEC_free (symbolp, template_args); | |
7249 | } | |
7250 | ||
c906108c SS |
7251 | /* Attach fields and member functions to the type. */ |
7252 | if (fi.nfields) | |
e7c27a73 | 7253 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
7254 | if (fi.nfnfields) |
7255 | { | |
e7c27a73 | 7256 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 7257 | |
c5aa993b | 7258 | /* Get the type which refers to the base class (possibly this |
c906108c | 7259 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
7260 | class from the DW_AT_containing_type attribute. This use of |
7261 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 7262 | |
e142c38c | 7263 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 7264 | { |
e7c27a73 | 7265 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
7266 | |
7267 | TYPE_VPTR_BASETYPE (type) = t; | |
7268 | if (type == t) | |
7269 | { | |
c906108c SS |
7270 | int i; |
7271 | ||
7272 | /* Our own class provides vtbl ptr. */ | |
7273 | for (i = TYPE_NFIELDS (t) - 1; | |
7274 | i >= TYPE_N_BASECLASSES (t); | |
7275 | --i) | |
7276 | { | |
7277 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
7278 | ||
1168df01 | 7279 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
7280 | { |
7281 | TYPE_VPTR_FIELDNO (type) = i; | |
7282 | break; | |
7283 | } | |
7284 | } | |
7285 | ||
7286 | /* Complain if virtual function table field not found. */ | |
7287 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 7288 | complaint (&symfile_complaints, |
3e43a32a MS |
7289 | _("virtual function table pointer " |
7290 | "not found when defining class '%s'"), | |
4d3c2250 KB |
7291 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
7292 | ""); | |
c906108c SS |
7293 | } |
7294 | else | |
7295 | { | |
7296 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
7297 | } | |
7298 | } | |
f6235d4c EZ |
7299 | else if (cu->producer |
7300 | && strncmp (cu->producer, | |
7301 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
7302 | { | |
7303 | /* The IBM XLC compiler does not provide direct indication | |
7304 | of the containing type, but the vtable pointer is | |
7305 | always named __vfp. */ | |
7306 | ||
7307 | int i; | |
7308 | ||
7309 | for (i = TYPE_NFIELDS (type) - 1; | |
7310 | i >= TYPE_N_BASECLASSES (type); | |
7311 | --i) | |
7312 | { | |
7313 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
7314 | { | |
7315 | TYPE_VPTR_FIELDNO (type) = i; | |
7316 | TYPE_VPTR_BASETYPE (type) = type; | |
7317 | break; | |
7318 | } | |
7319 | } | |
7320 | } | |
c906108c | 7321 | } |
98751a41 JK |
7322 | |
7323 | /* Copy fi.typedef_field_list linked list elements content into the | |
7324 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
7325 | if (fi.typedef_field_list) | |
7326 | { | |
7327 | int i = fi.typedef_field_list_count; | |
7328 | ||
a0d7a4ff | 7329 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
7330 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
7331 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
7332 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
7333 | ||
7334 | /* Reverse the list order to keep the debug info elements order. */ | |
7335 | while (--i >= 0) | |
7336 | { | |
7337 | struct typedef_field *dest, *src; | |
6e70227d | 7338 | |
98751a41 JK |
7339 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
7340 | src = &fi.typedef_field_list->field; | |
7341 | fi.typedef_field_list = fi.typedef_field_list->next; | |
7342 | *dest = *src; | |
7343 | } | |
7344 | } | |
c767944b DJ |
7345 | |
7346 | do_cleanups (back_to); | |
c906108c | 7347 | } |
63d06c5c | 7348 | |
0b92b5bb TT |
7349 | quirk_gcc_member_function_pointer (type, cu->objfile); |
7350 | ||
90aeadfc DC |
7351 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
7352 | snapshots) has been known to create a die giving a declaration | |
7353 | for a class that has, as a child, a die giving a definition for a | |
7354 | nested class. So we have to process our children even if the | |
7355 | current die is a declaration. Normally, of course, a declaration | |
7356 | won't have any children at all. */ | |
134d01f1 | 7357 | |
90aeadfc DC |
7358 | while (child_die != NULL && child_die->tag) |
7359 | { | |
7360 | if (child_die->tag == DW_TAG_member | |
7361 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
7362 | || child_die->tag == DW_TAG_inheritance |
7363 | || child_die->tag == DW_TAG_template_value_param | |
7364 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 7365 | { |
90aeadfc | 7366 | /* Do nothing. */ |
134d01f1 | 7367 | } |
90aeadfc DC |
7368 | else |
7369 | process_die (child_die, cu); | |
134d01f1 | 7370 | |
90aeadfc | 7371 | child_die = sibling_die (child_die); |
134d01f1 DJ |
7372 | } |
7373 | ||
fa4028e9 JB |
7374 | /* Do not consider external references. According to the DWARF standard, |
7375 | these DIEs are identified by the fact that they have no byte_size | |
7376 | attribute, and a declaration attribute. */ | |
7377 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
7378 | || !die_is_declaration (die, cu)) | |
c767944b | 7379 | new_symbol (die, type, cu); |
134d01f1 DJ |
7380 | } |
7381 | ||
7382 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
7383 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 7384 | |
f792889a | 7385 | static struct type * |
134d01f1 | 7386 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7387 | { |
e7c27a73 | 7388 | struct objfile *objfile = cu->objfile; |
c906108c | 7389 | struct type *type; |
c906108c | 7390 | struct attribute *attr; |
0114d602 | 7391 | const char *name; |
134d01f1 | 7392 | |
348e048f DE |
7393 | /* If the definition of this type lives in .debug_types, read that type. |
7394 | Don't follow DW_AT_specification though, that will take us back up | |
7395 | the chain and we want to go down. */ | |
7396 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7397 | if (attr) | |
7398 | { | |
7399 | struct dwarf2_cu *type_cu = cu; | |
7400 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7401 | |
348e048f | 7402 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7403 | |
7404 | /* TYPE_CU may not be the same as CU. | |
7405 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7406 | return set_die_type (die, type, cu); |
7407 | } | |
7408 | ||
c906108c SS |
7409 | type = alloc_type (objfile); |
7410 | ||
7411 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7412 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7413 | if (name != NULL) |
0114d602 | 7414 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7415 | |
e142c38c | 7416 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7417 | if (attr) |
7418 | { | |
7419 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7420 | } | |
7421 | else | |
7422 | { | |
7423 | TYPE_LENGTH (type) = 0; | |
7424 | } | |
7425 | ||
137033e9 JB |
7426 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7427 | declared as private in the package spec, and then defined only | |
7428 | inside the package body. Such types are known as Taft Amendment | |
7429 | Types. When another package uses such a type, an incomplete DIE | |
7430 | may be generated by the compiler. */ | |
02eb380e | 7431 | if (die_is_declaration (die, cu)) |
876cecd0 | 7432 | TYPE_STUB (type) = 1; |
02eb380e | 7433 | |
f792889a | 7434 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7435 | } |
7436 | ||
7437 | /* Given a pointer to a die which begins an enumeration, process all | |
7438 | the dies that define the members of the enumeration, and create the | |
7439 | symbol for the enumeration type. | |
7440 | ||
7441 | NOTE: We reverse the order of the element list. */ | |
7442 | ||
7443 | static void | |
7444 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7445 | { | |
f792889a | 7446 | struct type *this_type; |
134d01f1 | 7447 | |
f792889a DJ |
7448 | this_type = get_die_type (die, cu); |
7449 | if (this_type == NULL) | |
7450 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7451 | |
639d11d3 | 7452 | if (die->child != NULL) |
c906108c | 7453 | { |
9dc481d3 DE |
7454 | struct die_info *child_die; |
7455 | struct symbol *sym; | |
7456 | struct field *fields = NULL; | |
7457 | int num_fields = 0; | |
7458 | int unsigned_enum = 1; | |
7459 | char *name; | |
7460 | ||
639d11d3 | 7461 | child_die = die->child; |
c906108c SS |
7462 | while (child_die && child_die->tag) |
7463 | { | |
7464 | if (child_die->tag != DW_TAG_enumerator) | |
7465 | { | |
e7c27a73 | 7466 | process_die (child_die, cu); |
c906108c SS |
7467 | } |
7468 | else | |
7469 | { | |
39cbfefa DJ |
7470 | name = dwarf2_name (child_die, cu); |
7471 | if (name) | |
c906108c | 7472 | { |
f792889a | 7473 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7474 | if (SYMBOL_VALUE (sym) < 0) |
7475 | unsigned_enum = 0; | |
7476 | ||
7477 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7478 | { | |
7479 | fields = (struct field *) | |
7480 | xrealloc (fields, | |
7481 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7482 | * sizeof (struct field)); |
c906108c SS |
7483 | } |
7484 | ||
3567439c | 7485 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7486 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7487 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7488 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7489 | ||
7490 | num_fields++; | |
7491 | } | |
7492 | } | |
7493 | ||
7494 | child_die = sibling_die (child_die); | |
7495 | } | |
7496 | ||
7497 | if (num_fields) | |
7498 | { | |
f792889a DJ |
7499 | TYPE_NFIELDS (this_type) = num_fields; |
7500 | TYPE_FIELDS (this_type) = (struct field *) | |
7501 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7502 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7503 | sizeof (struct field) * num_fields); |
b8c9b27d | 7504 | xfree (fields); |
c906108c SS |
7505 | } |
7506 | if (unsigned_enum) | |
876cecd0 | 7507 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7508 | } |
134d01f1 | 7509 | |
f792889a | 7510 | new_symbol (die, this_type, cu); |
c906108c SS |
7511 | } |
7512 | ||
7513 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
7514 | the DIE's type field. For now, this only handles one dimensional | |
7515 | arrays. */ | |
7516 | ||
f792889a | 7517 | static struct type * |
e7c27a73 | 7518 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7519 | { |
e7c27a73 | 7520 | struct objfile *objfile = cu->objfile; |
c906108c | 7521 | struct die_info *child_die; |
7e314c57 | 7522 | struct type *type; |
c906108c SS |
7523 | struct type *element_type, *range_type, *index_type; |
7524 | struct type **range_types = NULL; | |
7525 | struct attribute *attr; | |
7526 | int ndim = 0; | |
7527 | struct cleanup *back_to; | |
39cbfefa | 7528 | char *name; |
c906108c | 7529 | |
e7c27a73 | 7530 | element_type = die_type (die, cu); |
c906108c | 7531 | |
7e314c57 JK |
7532 | /* The die_type call above may have already set the type for this DIE. */ |
7533 | type = get_die_type (die, cu); | |
7534 | if (type) | |
7535 | return type; | |
7536 | ||
c906108c SS |
7537 | /* Irix 6.2 native cc creates array types without children for |
7538 | arrays with unspecified length. */ | |
639d11d3 | 7539 | if (die->child == NULL) |
c906108c | 7540 | { |
46bf5051 | 7541 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7542 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
7543 | type = create_array_type (NULL, element_type, range_type); |
7544 | return set_die_type (die, type, cu); | |
c906108c SS |
7545 | } |
7546 | ||
7547 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 7548 | child_die = die->child; |
c906108c SS |
7549 | while (child_die && child_die->tag) |
7550 | { | |
7551 | if (child_die->tag == DW_TAG_subrange_type) | |
7552 | { | |
f792889a | 7553 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 7554 | |
f792889a | 7555 | if (child_type != NULL) |
a02abb62 | 7556 | { |
0963b4bd MS |
7557 | /* The range type was succesfully read. Save it for the |
7558 | array type creation. */ | |
a02abb62 JB |
7559 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
7560 | { | |
7561 | range_types = (struct type **) | |
7562 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
7563 | * sizeof (struct type *)); | |
7564 | if (ndim == 0) | |
7565 | make_cleanup (free_current_contents, &range_types); | |
7566 | } | |
f792889a | 7567 | range_types[ndim++] = child_type; |
a02abb62 | 7568 | } |
c906108c SS |
7569 | } |
7570 | child_die = sibling_die (child_die); | |
7571 | } | |
7572 | ||
7573 | /* Dwarf2 dimensions are output from left to right, create the | |
7574 | necessary array types in backwards order. */ | |
7ca2d3a3 | 7575 | |
c906108c | 7576 | type = element_type; |
7ca2d3a3 DL |
7577 | |
7578 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
7579 | { | |
7580 | int i = 0; | |
9a619af0 | 7581 | |
7ca2d3a3 DL |
7582 | while (i < ndim) |
7583 | type = create_array_type (NULL, type, range_types[i++]); | |
7584 | } | |
7585 | else | |
7586 | { | |
7587 | while (ndim-- > 0) | |
7588 | type = create_array_type (NULL, type, range_types[ndim]); | |
7589 | } | |
c906108c | 7590 | |
f5f8a009 EZ |
7591 | /* Understand Dwarf2 support for vector types (like they occur on |
7592 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
7593 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
7594 | custom vendor extension. The main difference between a regular | |
7595 | array and the vector variant is that vectors are passed by value | |
7596 | to functions. */ | |
e142c38c | 7597 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 7598 | if (attr) |
ea37ba09 | 7599 | make_vector_type (type); |
f5f8a009 | 7600 | |
dbc98a8b KW |
7601 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
7602 | implementation may choose to implement triple vectors using this | |
7603 | attribute. */ | |
7604 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
7605 | if (attr) | |
7606 | { | |
7607 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
7608 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7609 | else | |
3e43a32a MS |
7610 | complaint (&symfile_complaints, |
7611 | _("DW_AT_byte_size for array type smaller " | |
7612 | "than the total size of elements")); | |
dbc98a8b KW |
7613 | } |
7614 | ||
39cbfefa DJ |
7615 | name = dwarf2_name (die, cu); |
7616 | if (name) | |
7617 | TYPE_NAME (type) = name; | |
6e70227d | 7618 | |
0963b4bd | 7619 | /* Install the type in the die. */ |
7e314c57 JK |
7620 | set_die_type (die, type, cu); |
7621 | ||
7622 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
7623 | set_descriptive_type (type, die, cu); |
7624 | ||
c906108c SS |
7625 | do_cleanups (back_to); |
7626 | ||
7e314c57 | 7627 | return type; |
c906108c SS |
7628 | } |
7629 | ||
7ca2d3a3 | 7630 | static enum dwarf_array_dim_ordering |
6e70227d | 7631 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
7632 | { |
7633 | struct attribute *attr; | |
7634 | ||
7635 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
7636 | ||
7637 | if (attr) return DW_SND (attr); | |
7638 | ||
0963b4bd MS |
7639 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
7640 | opposite order to the dwarf2 specification, but data is still | |
7641 | laid out as per normal fortran. | |
7ca2d3a3 | 7642 | |
0963b4bd MS |
7643 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
7644 | version checking. */ | |
7ca2d3a3 | 7645 | |
905e0470 PM |
7646 | if (cu->language == language_fortran |
7647 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
7648 | { |
7649 | return DW_ORD_row_major; | |
7650 | } | |
7651 | ||
6e70227d | 7652 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
7653 | { |
7654 | case array_column_major: | |
7655 | return DW_ORD_col_major; | |
7656 | case array_row_major: | |
7657 | default: | |
7658 | return DW_ORD_row_major; | |
7659 | }; | |
7660 | } | |
7661 | ||
72019c9c | 7662 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 7663 | the DIE's type field. */ |
72019c9c | 7664 | |
f792889a | 7665 | static struct type * |
72019c9c GM |
7666 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
7667 | { | |
7e314c57 JK |
7668 | struct type *domain_type, *set_type; |
7669 | struct attribute *attr; | |
f792889a | 7670 | |
7e314c57 JK |
7671 | domain_type = die_type (die, cu); |
7672 | ||
7673 | /* The die_type call above may have already set the type for this DIE. */ | |
7674 | set_type = get_die_type (die, cu); | |
7675 | if (set_type) | |
7676 | return set_type; | |
7677 | ||
7678 | set_type = create_set_type (NULL, domain_type); | |
7679 | ||
7680 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
7681 | if (attr) |
7682 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 7683 | |
f792889a | 7684 | return set_die_type (die, set_type, cu); |
72019c9c | 7685 | } |
7ca2d3a3 | 7686 | |
c906108c SS |
7687 | /* First cut: install each common block member as a global variable. */ |
7688 | ||
7689 | static void | |
e7c27a73 | 7690 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7691 | { |
7692 | struct die_info *child_die; | |
7693 | struct attribute *attr; | |
7694 | struct symbol *sym; | |
7695 | CORE_ADDR base = (CORE_ADDR) 0; | |
7696 | ||
e142c38c | 7697 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7698 | if (attr) |
7699 | { | |
0963b4bd | 7700 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
7701 | if (attr_form_is_block (attr)) |
7702 | { | |
e7c27a73 | 7703 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 7704 | } |
3690dd37 | 7705 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7706 | { |
4d3c2250 | 7707 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7708 | } |
7709 | else | |
7710 | { | |
4d3c2250 KB |
7711 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
7712 | "common block member"); | |
8e19ed76 | 7713 | } |
c906108c | 7714 | } |
639d11d3 | 7715 | if (die->child != NULL) |
c906108c | 7716 | { |
639d11d3 | 7717 | child_die = die->child; |
c906108c SS |
7718 | while (child_die && child_die->tag) |
7719 | { | |
74ac6d43 TT |
7720 | LONGEST offset; |
7721 | ||
e7c27a73 | 7722 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
7723 | if (sym != NULL |
7724 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 7725 | { |
74ac6d43 | 7726 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
7727 | add_symbol_to_list (sym, &global_symbols); |
7728 | } | |
7729 | child_die = sibling_die (child_die); | |
7730 | } | |
7731 | } | |
7732 | } | |
7733 | ||
0114d602 | 7734 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 7735 | |
0114d602 DJ |
7736 | static struct type * |
7737 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 7738 | { |
e7c27a73 | 7739 | struct objfile *objfile = cu->objfile; |
0114d602 | 7740 | const char *previous_prefix, *name; |
9219021c | 7741 | int is_anonymous; |
0114d602 DJ |
7742 | struct type *type; |
7743 | ||
7744 | /* For extensions, reuse the type of the original namespace. */ | |
7745 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
7746 | { | |
7747 | struct die_info *ext_die; | |
7748 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 7749 | |
0114d602 DJ |
7750 | ext_die = dwarf2_extension (die, &ext_cu); |
7751 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
7752 | |
7753 | /* EXT_CU may not be the same as CU. | |
7754 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
7755 | return set_die_type (die, type, cu); |
7756 | } | |
9219021c | 7757 | |
e142c38c | 7758 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
7759 | |
7760 | /* Now build the name of the current namespace. */ | |
7761 | ||
0114d602 DJ |
7762 | previous_prefix = determine_prefix (die, cu); |
7763 | if (previous_prefix[0] != '\0') | |
7764 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 7765 | previous_prefix, name, 0, cu); |
0114d602 DJ |
7766 | |
7767 | /* Create the type. */ | |
7768 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
7769 | objfile); | |
7770 | TYPE_NAME (type) = (char *) name; | |
7771 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7772 | ||
60531b24 | 7773 | return set_die_type (die, type, cu); |
0114d602 DJ |
7774 | } |
7775 | ||
7776 | /* Read a C++ namespace. */ | |
7777 | ||
7778 | static void | |
7779 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
7780 | { | |
7781 | struct objfile *objfile = cu->objfile; | |
0114d602 | 7782 | int is_anonymous; |
9219021c | 7783 | |
5c4e30ca DC |
7784 | /* Add a symbol associated to this if we haven't seen the namespace |
7785 | before. Also, add a using directive if it's an anonymous | |
7786 | namespace. */ | |
9219021c | 7787 | |
f2f0e013 | 7788 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
7789 | { |
7790 | struct type *type; | |
7791 | ||
0114d602 | 7792 | type = read_type_die (die, cu); |
e7c27a73 | 7793 | new_symbol (die, type, cu); |
5c4e30ca | 7794 | |
e8e80198 | 7795 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 7796 | if (is_anonymous) |
0114d602 DJ |
7797 | { |
7798 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 7799 | |
c0cc3a76 | 7800 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 7801 | NULL, &objfile->objfile_obstack); |
0114d602 | 7802 | } |
5c4e30ca | 7803 | } |
9219021c | 7804 | |
639d11d3 | 7805 | if (die->child != NULL) |
d9fa45fe | 7806 | { |
639d11d3 | 7807 | struct die_info *child_die = die->child; |
6e70227d | 7808 | |
d9fa45fe DC |
7809 | while (child_die && child_die->tag) |
7810 | { | |
e7c27a73 | 7811 | process_die (child_die, cu); |
d9fa45fe DC |
7812 | child_die = sibling_die (child_die); |
7813 | } | |
7814 | } | |
38d518c9 EZ |
7815 | } |
7816 | ||
f55ee35c JK |
7817 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
7818 | imported module. Still we need that type as local Fortran "use ... only" | |
7819 | declaration imports depend on the created type in determine_prefix. */ | |
7820 | ||
7821 | static struct type * | |
7822 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
7823 | { | |
7824 | struct objfile *objfile = cu->objfile; | |
7825 | char *module_name; | |
7826 | struct type *type; | |
7827 | ||
7828 | module_name = dwarf2_name (die, cu); | |
7829 | if (!module_name) | |
3e43a32a MS |
7830 | complaint (&symfile_complaints, |
7831 | _("DW_TAG_module has no name, offset 0x%x"), | |
f55ee35c JK |
7832 | die->offset); |
7833 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
7834 | ||
7835 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
7836 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7837 | ||
7838 | return set_die_type (die, type, cu); | |
7839 | } | |
7840 | ||
5d7cb8df JK |
7841 | /* Read a Fortran module. */ |
7842 | ||
7843 | static void | |
7844 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
7845 | { | |
7846 | struct die_info *child_die = die->child; | |
7847 | ||
5d7cb8df JK |
7848 | while (child_die && child_die->tag) |
7849 | { | |
7850 | process_die (child_die, cu); | |
7851 | child_die = sibling_die (child_die); | |
7852 | } | |
7853 | } | |
7854 | ||
38d518c9 EZ |
7855 | /* Return the name of the namespace represented by DIE. Set |
7856 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
7857 | namespace. */ | |
7858 | ||
7859 | static const char * | |
e142c38c | 7860 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
7861 | { |
7862 | struct die_info *current_die; | |
7863 | const char *name = NULL; | |
7864 | ||
7865 | /* Loop through the extensions until we find a name. */ | |
7866 | ||
7867 | for (current_die = die; | |
7868 | current_die != NULL; | |
f2f0e013 | 7869 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 7870 | { |
e142c38c | 7871 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
7872 | if (name != NULL) |
7873 | break; | |
7874 | } | |
7875 | ||
7876 | /* Is it an anonymous namespace? */ | |
7877 | ||
7878 | *is_anonymous = (name == NULL); | |
7879 | if (*is_anonymous) | |
2b1dbab0 | 7880 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
7881 | |
7882 | return name; | |
d9fa45fe DC |
7883 | } |
7884 | ||
c906108c SS |
7885 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
7886 | the user defined type vector. */ | |
7887 | ||
f792889a | 7888 | static struct type * |
e7c27a73 | 7889 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7890 | { |
5e2b427d | 7891 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 7892 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 7893 | struct type *type; |
8b2dbe47 KB |
7894 | struct attribute *attr_byte_size; |
7895 | struct attribute *attr_address_class; | |
7896 | int byte_size, addr_class; | |
7e314c57 JK |
7897 | struct type *target_type; |
7898 | ||
7899 | target_type = die_type (die, cu); | |
c906108c | 7900 | |
7e314c57 JK |
7901 | /* The die_type call above may have already set the type for this DIE. */ |
7902 | type = get_die_type (die, cu); | |
7903 | if (type) | |
7904 | return type; | |
7905 | ||
7906 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 7907 | |
e142c38c | 7908 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
7909 | if (attr_byte_size) |
7910 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 7911 | else |
8b2dbe47 KB |
7912 | byte_size = cu_header->addr_size; |
7913 | ||
e142c38c | 7914 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
7915 | if (attr_address_class) |
7916 | addr_class = DW_UNSND (attr_address_class); | |
7917 | else | |
7918 | addr_class = DW_ADDR_none; | |
7919 | ||
7920 | /* If the pointer size or address class is different than the | |
7921 | default, create a type variant marked as such and set the | |
7922 | length accordingly. */ | |
7923 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 7924 | { |
5e2b427d | 7925 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
7926 | { |
7927 | int type_flags; | |
7928 | ||
849957d9 | 7929 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 7930 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
7931 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
7932 | == 0); | |
8b2dbe47 KB |
7933 | type = make_type_with_address_space (type, type_flags); |
7934 | } | |
7935 | else if (TYPE_LENGTH (type) != byte_size) | |
7936 | { | |
3e43a32a MS |
7937 | complaint (&symfile_complaints, |
7938 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 7939 | } |
6e70227d | 7940 | else |
9a619af0 MS |
7941 | { |
7942 | /* Should we also complain about unhandled address classes? */ | |
7943 | } | |
c906108c | 7944 | } |
8b2dbe47 KB |
7945 | |
7946 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 7947 | return set_die_type (die, type, cu); |
c906108c SS |
7948 | } |
7949 | ||
7950 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
7951 | the user defined type vector. */ | |
7952 | ||
f792889a | 7953 | static struct type * |
e7c27a73 | 7954 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7955 | { |
7956 | struct type *type; | |
7957 | struct type *to_type; | |
7958 | struct type *domain; | |
7959 | ||
e7c27a73 DJ |
7960 | to_type = die_type (die, cu); |
7961 | domain = die_containing_type (die, cu); | |
0d5de010 | 7962 | |
7e314c57 JK |
7963 | /* The calls above may have already set the type for this DIE. */ |
7964 | type = get_die_type (die, cu); | |
7965 | if (type) | |
7966 | return type; | |
7967 | ||
0d5de010 DJ |
7968 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
7969 | type = lookup_methodptr_type (to_type); | |
7970 | else | |
7971 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 7972 | |
f792889a | 7973 | return set_die_type (die, type, cu); |
c906108c SS |
7974 | } |
7975 | ||
7976 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
7977 | the user defined type vector. */ | |
7978 | ||
f792889a | 7979 | static struct type * |
e7c27a73 | 7980 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7981 | { |
e7c27a73 | 7982 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 7983 | struct type *type, *target_type; |
c906108c SS |
7984 | struct attribute *attr; |
7985 | ||
7e314c57 JK |
7986 | target_type = die_type (die, cu); |
7987 | ||
7988 | /* The die_type call above may have already set the type for this DIE. */ | |
7989 | type = get_die_type (die, cu); | |
7990 | if (type) | |
7991 | return type; | |
7992 | ||
7993 | type = lookup_reference_type (target_type); | |
e142c38c | 7994 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7995 | if (attr) |
7996 | { | |
7997 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7998 | } | |
7999 | else | |
8000 | { | |
107d2387 | 8001 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 8002 | } |
f792889a | 8003 | return set_die_type (die, type, cu); |
c906108c SS |
8004 | } |
8005 | ||
f792889a | 8006 | static struct type * |
e7c27a73 | 8007 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8008 | { |
f792889a | 8009 | struct type *base_type, *cv_type; |
c906108c | 8010 | |
e7c27a73 | 8011 | base_type = die_type (die, cu); |
7e314c57 JK |
8012 | |
8013 | /* The die_type call above may have already set the type for this DIE. */ | |
8014 | cv_type = get_die_type (die, cu); | |
8015 | if (cv_type) | |
8016 | return cv_type; | |
8017 | ||
2f608a3a KW |
8018 | /* In case the const qualifier is applied to an array type, the element type |
8019 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
8020 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
8021 | { | |
8022 | struct type *el_type, *inner_array; | |
8023 | ||
8024 | base_type = copy_type (base_type); | |
8025 | inner_array = base_type; | |
8026 | ||
8027 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
8028 | { | |
8029 | TYPE_TARGET_TYPE (inner_array) = | |
8030 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
8031 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
8032 | } | |
8033 | ||
8034 | el_type = TYPE_TARGET_TYPE (inner_array); | |
8035 | TYPE_TARGET_TYPE (inner_array) = | |
8036 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
8037 | ||
8038 | return set_die_type (die, base_type, cu); | |
8039 | } | |
8040 | ||
f792889a DJ |
8041 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
8042 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8043 | } |
8044 | ||
f792889a | 8045 | static struct type * |
e7c27a73 | 8046 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8047 | { |
f792889a | 8048 | struct type *base_type, *cv_type; |
c906108c | 8049 | |
e7c27a73 | 8050 | base_type = die_type (die, cu); |
7e314c57 JK |
8051 | |
8052 | /* The die_type call above may have already set the type for this DIE. */ | |
8053 | cv_type = get_die_type (die, cu); | |
8054 | if (cv_type) | |
8055 | return cv_type; | |
8056 | ||
f792889a DJ |
8057 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
8058 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8059 | } |
8060 | ||
8061 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
8062 | the user defined type vector. It isn't really a user defined type, | |
8063 | but it behaves like one, with other DIE's using an AT_user_def_type | |
8064 | attribute to reference it. */ | |
8065 | ||
f792889a | 8066 | static struct type * |
e7c27a73 | 8067 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8068 | { |
e7c27a73 | 8069 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 8070 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8071 | struct type *type, *range_type, *index_type, *char_type; |
8072 | struct attribute *attr; | |
8073 | unsigned int length; | |
8074 | ||
e142c38c | 8075 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
8076 | if (attr) |
8077 | { | |
8078 | length = DW_UNSND (attr); | |
8079 | } | |
8080 | else | |
8081 | { | |
0963b4bd | 8082 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 8083 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
8084 | if (attr) |
8085 | { | |
8086 | length = DW_UNSND (attr); | |
8087 | } | |
8088 | else | |
8089 | { | |
8090 | length = 1; | |
8091 | } | |
c906108c | 8092 | } |
6ccb9162 | 8093 | |
46bf5051 | 8094 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8095 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
8096 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
8097 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 8098 | |
f792889a | 8099 | return set_die_type (die, type, cu); |
c906108c SS |
8100 | } |
8101 | ||
8102 | /* Handle DIES due to C code like: | |
8103 | ||
8104 | struct foo | |
c5aa993b JM |
8105 | { |
8106 | int (*funcp)(int a, long l); | |
8107 | int b; | |
8108 | }; | |
c906108c | 8109 | |
0963b4bd | 8110 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 8111 | |
f792889a | 8112 | static struct type * |
e7c27a73 | 8113 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8114 | { |
0963b4bd MS |
8115 | struct type *type; /* Type that this function returns. */ |
8116 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
8117 | struct attribute *attr; |
8118 | ||
e7c27a73 | 8119 | type = die_type (die, cu); |
7e314c57 JK |
8120 | |
8121 | /* The die_type call above may have already set the type for this DIE. */ | |
8122 | ftype = get_die_type (die, cu); | |
8123 | if (ftype) | |
8124 | return ftype; | |
8125 | ||
0c8b41f1 | 8126 | ftype = lookup_function_type (type); |
c906108c | 8127 | |
5b8101ae | 8128 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 8129 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 8130 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 8131 | || cu->language == language_cplus |
5b8101ae PM |
8132 | || cu->language == language_java |
8133 | || cu->language == language_pascal) | |
876cecd0 | 8134 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
8135 | else if (producer_is_realview (cu->producer)) |
8136 | /* RealView does not emit DW_AT_prototyped. We can not | |
8137 | distinguish prototyped and unprototyped functions; default to | |
8138 | prototyped, since that is more common in modern code (and | |
8139 | RealView warns about unprototyped functions). */ | |
8140 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 8141 | |
c055b101 CV |
8142 | /* Store the calling convention in the type if it's available in |
8143 | the subroutine die. Otherwise set the calling convention to | |
8144 | the default value DW_CC_normal. */ | |
8145 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
8146 | if (attr) |
8147 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
8148 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
8149 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
8150 | else | |
8151 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
8152 | |
8153 | /* We need to add the subroutine type to the die immediately so | |
8154 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 8155 | declared as the same subroutine type. */ |
76c10ea2 | 8156 | set_die_type (die, ftype, cu); |
6e70227d | 8157 | |
639d11d3 | 8158 | if (die->child != NULL) |
c906108c | 8159 | { |
8072405b | 8160 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 8161 | struct die_info *child_die; |
8072405b | 8162 | int nparams, iparams; |
c906108c SS |
8163 | |
8164 | /* Count the number of parameters. | |
8165 | FIXME: GDB currently ignores vararg functions, but knows about | |
8166 | vararg member functions. */ | |
8072405b | 8167 | nparams = 0; |
639d11d3 | 8168 | child_die = die->child; |
c906108c SS |
8169 | while (child_die && child_die->tag) |
8170 | { | |
8171 | if (child_die->tag == DW_TAG_formal_parameter) | |
8172 | nparams++; | |
8173 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 8174 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
8175 | child_die = sibling_die (child_die); |
8176 | } | |
8177 | ||
8178 | /* Allocate storage for parameters and fill them in. */ | |
8179 | TYPE_NFIELDS (ftype) = nparams; | |
8180 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 8181 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 8182 | |
8072405b JK |
8183 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
8184 | even if we error out during the parameters reading below. */ | |
8185 | for (iparams = 0; iparams < nparams; iparams++) | |
8186 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
8187 | ||
8188 | iparams = 0; | |
639d11d3 | 8189 | child_die = die->child; |
c906108c SS |
8190 | while (child_die && child_die->tag) |
8191 | { | |
8192 | if (child_die->tag == DW_TAG_formal_parameter) | |
8193 | { | |
3ce3b1ba PA |
8194 | struct type *arg_type; |
8195 | ||
8196 | /* DWARF version 2 has no clean way to discern C++ | |
8197 | static and non-static member functions. G++ helps | |
8198 | GDB by marking the first parameter for non-static | |
8199 | member functions (which is the this pointer) as | |
8200 | artificial. We pass this information to | |
8201 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
8202 | ||
8203 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
8204 | 4.5 does not yet generate. */ | |
e142c38c | 8205 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
8206 | if (attr) |
8207 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
8208 | else | |
418835cc KS |
8209 | { |
8210 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
8211 | ||
8212 | /* GCC/43521: In java, the formal parameter | |
8213 | "this" is sometimes not marked with DW_AT_artificial. */ | |
8214 | if (cu->language == language_java) | |
8215 | { | |
8216 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 8217 | |
418835cc KS |
8218 | if (name && !strcmp (name, "this")) |
8219 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
8220 | } | |
8221 | } | |
3ce3b1ba PA |
8222 | arg_type = die_type (child_die, cu); |
8223 | ||
8224 | /* RealView does not mark THIS as const, which the testsuite | |
8225 | expects. GCC marks THIS as const in method definitions, | |
8226 | but not in the class specifications (GCC PR 43053). */ | |
8227 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
8228 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
8229 | { | |
8230 | int is_this = 0; | |
8231 | struct dwarf2_cu *arg_cu = cu; | |
8232 | const char *name = dwarf2_name (child_die, cu); | |
8233 | ||
8234 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
8235 | if (attr) | |
8236 | { | |
8237 | /* If the compiler emits this, use it. */ | |
8238 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
8239 | is_this = 1; | |
8240 | } | |
8241 | else if (name && strcmp (name, "this") == 0) | |
8242 | /* Function definitions will have the argument names. */ | |
8243 | is_this = 1; | |
8244 | else if (name == NULL && iparams == 0) | |
8245 | /* Declarations may not have the names, so like | |
8246 | elsewhere in GDB, assume an artificial first | |
8247 | argument is "this". */ | |
8248 | is_this = 1; | |
8249 | ||
8250 | if (is_this) | |
8251 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
8252 | arg_type, 0); | |
8253 | } | |
8254 | ||
8255 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
8256 | iparams++; |
8257 | } | |
8258 | child_die = sibling_die (child_die); | |
8259 | } | |
8260 | } | |
8261 | ||
76c10ea2 | 8262 | return ftype; |
c906108c SS |
8263 | } |
8264 | ||
f792889a | 8265 | static struct type * |
e7c27a73 | 8266 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8267 | { |
e7c27a73 | 8268 | struct objfile *objfile = cu->objfile; |
0114d602 | 8269 | const char *name = NULL; |
f792889a | 8270 | struct type *this_type; |
c906108c | 8271 | |
94af9270 | 8272 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 8273 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
8274 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
8275 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
8276 | set_die_type (die, this_type, cu); |
8277 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
8278 | return this_type; | |
c906108c SS |
8279 | } |
8280 | ||
8281 | /* Find a representation of a given base type and install | |
8282 | it in the TYPE field of the die. */ | |
8283 | ||
f792889a | 8284 | static struct type * |
e7c27a73 | 8285 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8286 | { |
e7c27a73 | 8287 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8288 | struct type *type; |
8289 | struct attribute *attr; | |
8290 | int encoding = 0, size = 0; | |
39cbfefa | 8291 | char *name; |
6ccb9162 UW |
8292 | enum type_code code = TYPE_CODE_INT; |
8293 | int type_flags = 0; | |
8294 | struct type *target_type = NULL; | |
c906108c | 8295 | |
e142c38c | 8296 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
8297 | if (attr) |
8298 | { | |
8299 | encoding = DW_UNSND (attr); | |
8300 | } | |
e142c38c | 8301 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8302 | if (attr) |
8303 | { | |
8304 | size = DW_UNSND (attr); | |
8305 | } | |
39cbfefa | 8306 | name = dwarf2_name (die, cu); |
6ccb9162 | 8307 | if (!name) |
c906108c | 8308 | { |
6ccb9162 UW |
8309 | complaint (&symfile_complaints, |
8310 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 8311 | } |
6ccb9162 UW |
8312 | |
8313 | switch (encoding) | |
c906108c | 8314 | { |
6ccb9162 UW |
8315 | case DW_ATE_address: |
8316 | /* Turn DW_ATE_address into a void * pointer. */ | |
8317 | code = TYPE_CODE_PTR; | |
8318 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8319 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
8320 | break; | |
8321 | case DW_ATE_boolean: | |
8322 | code = TYPE_CODE_BOOL; | |
8323 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8324 | break; | |
8325 | case DW_ATE_complex_float: | |
8326 | code = TYPE_CODE_COMPLEX; | |
8327 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
8328 | break; | |
8329 | case DW_ATE_decimal_float: | |
8330 | code = TYPE_CODE_DECFLOAT; | |
8331 | break; | |
8332 | case DW_ATE_float: | |
8333 | code = TYPE_CODE_FLT; | |
8334 | break; | |
8335 | case DW_ATE_signed: | |
8336 | break; | |
8337 | case DW_ATE_unsigned: | |
8338 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8339 | break; | |
8340 | case DW_ATE_signed_char: | |
6e70227d | 8341 | if (cu->language == language_ada || cu->language == language_m2 |
868a0084 | 8342 | || cu->language == language_pascal) |
6ccb9162 UW |
8343 | code = TYPE_CODE_CHAR; |
8344 | break; | |
8345 | case DW_ATE_unsigned_char: | |
868a0084 PM |
8346 | if (cu->language == language_ada || cu->language == language_m2 |
8347 | || cu->language == language_pascal) | |
6ccb9162 UW |
8348 | code = TYPE_CODE_CHAR; |
8349 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8350 | break; | |
75079b2b TT |
8351 | case DW_ATE_UTF: |
8352 | /* We just treat this as an integer and then recognize the | |
8353 | type by name elsewhere. */ | |
8354 | break; | |
8355 | ||
6ccb9162 UW |
8356 | default: |
8357 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
8358 | dwarf_type_encoding_name (encoding)); | |
8359 | break; | |
c906108c | 8360 | } |
6ccb9162 | 8361 | |
0114d602 DJ |
8362 | type = init_type (code, size, type_flags, NULL, objfile); |
8363 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
8364 | TYPE_TARGET_TYPE (type) = target_type; |
8365 | ||
0114d602 | 8366 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 8367 | TYPE_NOSIGN (type) = 1; |
0114d602 | 8368 | |
f792889a | 8369 | return set_die_type (die, type, cu); |
c906108c SS |
8370 | } |
8371 | ||
a02abb62 JB |
8372 | /* Read the given DW_AT_subrange DIE. */ |
8373 | ||
f792889a | 8374 | static struct type * |
a02abb62 JB |
8375 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
8376 | { | |
8377 | struct type *base_type; | |
8378 | struct type *range_type; | |
8379 | struct attribute *attr; | |
43bbcdc2 PH |
8380 | LONGEST low = 0; |
8381 | LONGEST high = -1; | |
39cbfefa | 8382 | char *name; |
43bbcdc2 | 8383 | LONGEST negative_mask; |
e77813c8 | 8384 | |
a02abb62 | 8385 | base_type = die_type (die, cu); |
953ac07e JK |
8386 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
8387 | check_typedef (base_type); | |
a02abb62 | 8388 | |
7e314c57 JK |
8389 | /* The die_type call above may have already set the type for this DIE. */ |
8390 | range_type = get_die_type (die, cu); | |
8391 | if (range_type) | |
8392 | return range_type; | |
8393 | ||
e142c38c | 8394 | if (cu->language == language_fortran) |
6e70227d | 8395 | { |
a02abb62 JB |
8396 | /* FORTRAN implies a lower bound of 1, if not given. */ |
8397 | low = 1; | |
8398 | } | |
8399 | ||
dd5e6932 DJ |
8400 | /* FIXME: For variable sized arrays either of these could be |
8401 | a variable rather than a constant value. We'll allow it, | |
8402 | but we don't know how to handle it. */ | |
e142c38c | 8403 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
8404 | if (attr) |
8405 | low = dwarf2_get_attr_constant_value (attr, 0); | |
8406 | ||
e142c38c | 8407 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 8408 | if (attr) |
6e70227d | 8409 | { |
e77813c8 | 8410 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
a02abb62 JB |
8411 | { |
8412 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 8413 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
8414 | FIXME: GDB does not yet know how to handle dynamic |
8415 | arrays properly, treat them as arrays with unspecified | |
8416 | length for now. | |
8417 | ||
8418 | FIXME: jimb/2003-09-22: GDB does not really know | |
8419 | how to handle arrays of unspecified length | |
8420 | either; we just represent them as zero-length | |
8421 | arrays. Choose an appropriate upper bound given | |
8422 | the lower bound we've computed above. */ | |
8423 | high = low - 1; | |
8424 | } | |
8425 | else | |
8426 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8427 | } | |
e77813c8 PM |
8428 | else |
8429 | { | |
8430 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8431 | if (attr) | |
8432 | { | |
8433 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8434 | high = low + count - 1; | |
8435 | } | |
c2ff108b JK |
8436 | else |
8437 | { | |
8438 | /* Unspecified array length. */ | |
8439 | high = low - 1; | |
8440 | } | |
e77813c8 PM |
8441 | } |
8442 | ||
8443 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8444 | without specifying a base type. | |
8445 | In that case, the base type must be set to the type of | |
8446 | the lower bound, upper bound or count, in that order, if any of these | |
8447 | three attributes references an object that has a type. | |
8448 | If no base type is found, the Dwarf-2 specifications say that | |
8449 | a signed integer type of size equal to the size of an address should | |
8450 | be used. | |
8451 | For the following C code: `extern char gdb_int [];' | |
8452 | GCC produces an empty range DIE. | |
8453 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 8454 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
8455 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
8456 | { | |
8457 | struct objfile *objfile = cu->objfile; | |
8458 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8459 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8460 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8461 | ||
8462 | /* Test "int", "long int", and "long long int" objfile types, | |
8463 | and select the first one having a size above or equal to the | |
8464 | architecture address size. */ | |
8465 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8466 | base_type = int_type; | |
8467 | else | |
8468 | { | |
8469 | int_type = objfile_type (objfile)->builtin_long; | |
8470 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8471 | base_type = int_type; | |
8472 | else | |
8473 | { | |
8474 | int_type = objfile_type (objfile)->builtin_long_long; | |
8475 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8476 | base_type = int_type; | |
8477 | } | |
8478 | } | |
8479 | } | |
a02abb62 | 8480 | |
6e70227d | 8481 | negative_mask = |
43bbcdc2 PH |
8482 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8483 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8484 | low |= negative_mask; | |
8485 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8486 | high |= negative_mask; | |
8487 | ||
a02abb62 JB |
8488 | range_type = create_range_type (NULL, base_type, low, high); |
8489 | ||
bbb0eef6 JK |
8490 | /* Mark arrays with dynamic length at least as an array of unspecified |
8491 | length. GDB could check the boundary but before it gets implemented at | |
8492 | least allow accessing the array elements. */ | |
8493 | if (attr && attr->form == DW_FORM_block1) | |
8494 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8495 | ||
c2ff108b JK |
8496 | /* Ada expects an empty array on no boundary attributes. */ |
8497 | if (attr == NULL && cu->language != language_ada) | |
8498 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8499 | ||
39cbfefa DJ |
8500 | name = dwarf2_name (die, cu); |
8501 | if (name) | |
8502 | TYPE_NAME (range_type) = name; | |
6e70227d | 8503 | |
e142c38c | 8504 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
8505 | if (attr) |
8506 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
8507 | ||
7e314c57 JK |
8508 | set_die_type (die, range_type, cu); |
8509 | ||
8510 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8511 | set_descriptive_type (range_type, die, cu); |
8512 | ||
7e314c57 | 8513 | return range_type; |
a02abb62 | 8514 | } |
6e70227d | 8515 | |
f792889a | 8516 | static struct type * |
81a17f79 JB |
8517 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
8518 | { | |
8519 | struct type *type; | |
81a17f79 | 8520 | |
81a17f79 JB |
8521 | /* For now, we only support the C meaning of an unspecified type: void. */ |
8522 | ||
0114d602 DJ |
8523 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
8524 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 8525 | |
f792889a | 8526 | return set_die_type (die, type, cu); |
81a17f79 | 8527 | } |
a02abb62 | 8528 | |
51545339 DJ |
8529 | /* Trivial hash function for die_info: the hash value of a DIE |
8530 | is its offset in .debug_info for this objfile. */ | |
8531 | ||
8532 | static hashval_t | |
8533 | die_hash (const void *item) | |
8534 | { | |
8535 | const struct die_info *die = item; | |
9a619af0 | 8536 | |
51545339 DJ |
8537 | return die->offset; |
8538 | } | |
8539 | ||
8540 | /* Trivial comparison function for die_info structures: two DIEs | |
8541 | are equal if they have the same offset. */ | |
8542 | ||
8543 | static int | |
8544 | die_eq (const void *item_lhs, const void *item_rhs) | |
8545 | { | |
8546 | const struct die_info *die_lhs = item_lhs; | |
8547 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 8548 | |
51545339 DJ |
8549 | return die_lhs->offset == die_rhs->offset; |
8550 | } | |
8551 | ||
c906108c SS |
8552 | /* Read a whole compilation unit into a linked list of dies. */ |
8553 | ||
f9aca02d | 8554 | static struct die_info * |
93311388 | 8555 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 8556 | { |
93311388 | 8557 | struct die_reader_specs reader_specs; |
98bfdba5 | 8558 | int read_abbrevs = 0; |
1d9ec526 | 8559 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
8560 | struct die_info *die; |
8561 | ||
8562 | if (cu->dwarf2_abbrevs == NULL) | |
8563 | { | |
8564 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
8565 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
8566 | read_abbrevs = 1; | |
8567 | } | |
93311388 | 8568 | |
348e048f | 8569 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
8570 | cu->die_hash |
8571 | = htab_create_alloc_ex (cu->header.length / 12, | |
8572 | die_hash, | |
8573 | die_eq, | |
8574 | NULL, | |
8575 | &cu->comp_unit_obstack, | |
8576 | hashtab_obstack_allocate, | |
8577 | dummy_obstack_deallocate); | |
8578 | ||
93311388 DE |
8579 | init_cu_die_reader (&reader_specs, cu); |
8580 | ||
98bfdba5 PA |
8581 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
8582 | ||
8583 | if (read_abbrevs) | |
8584 | do_cleanups (back_to); | |
8585 | ||
8586 | return die; | |
639d11d3 DC |
8587 | } |
8588 | ||
d97bc12b DE |
8589 | /* Main entry point for reading a DIE and all children. |
8590 | Read the DIE and dump it if requested. */ | |
8591 | ||
8592 | static struct die_info * | |
93311388 DE |
8593 | read_die_and_children (const struct die_reader_specs *reader, |
8594 | gdb_byte *info_ptr, | |
d97bc12b DE |
8595 | gdb_byte **new_info_ptr, |
8596 | struct die_info *parent) | |
8597 | { | |
93311388 | 8598 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
8599 | new_info_ptr, parent); |
8600 | ||
8601 | if (dwarf2_die_debug) | |
8602 | { | |
348e048f DE |
8603 | fprintf_unfiltered (gdb_stdlog, |
8604 | "\nRead die from %s of %s:\n", | |
8605 | reader->buffer == dwarf2_per_objfile->info.buffer | |
8606 | ? ".debug_info" | |
8607 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
8608 | ? ".debug_types" | |
8609 | : "unknown section", | |
8610 | reader->abfd->filename); | |
d97bc12b DE |
8611 | dump_die (result, dwarf2_die_debug); |
8612 | } | |
8613 | ||
8614 | return result; | |
8615 | } | |
8616 | ||
639d11d3 DC |
8617 | /* Read a single die and all its descendents. Set the die's sibling |
8618 | field to NULL; set other fields in the die correctly, and set all | |
8619 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
8620 | location of the info_ptr after reading all of those dies. PARENT | |
8621 | is the parent of the die in question. */ | |
8622 | ||
8623 | static struct die_info * | |
93311388 DE |
8624 | read_die_and_children_1 (const struct die_reader_specs *reader, |
8625 | gdb_byte *info_ptr, | |
d97bc12b DE |
8626 | gdb_byte **new_info_ptr, |
8627 | struct die_info *parent) | |
639d11d3 DC |
8628 | { |
8629 | struct die_info *die; | |
fe1b8b76 | 8630 | gdb_byte *cur_ptr; |
639d11d3 DC |
8631 | int has_children; |
8632 | ||
93311388 | 8633 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
8634 | if (die == NULL) |
8635 | { | |
8636 | *new_info_ptr = cur_ptr; | |
8637 | return NULL; | |
8638 | } | |
93311388 | 8639 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
8640 | |
8641 | if (has_children) | |
348e048f | 8642 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
8643 | else |
8644 | { | |
8645 | die->child = NULL; | |
8646 | *new_info_ptr = cur_ptr; | |
8647 | } | |
8648 | ||
8649 | die->sibling = NULL; | |
8650 | die->parent = parent; | |
8651 | return die; | |
8652 | } | |
8653 | ||
8654 | /* Read a die, all of its descendents, and all of its siblings; set | |
8655 | all of the fields of all of the dies correctly. Arguments are as | |
8656 | in read_die_and_children. */ | |
8657 | ||
8658 | static struct die_info * | |
93311388 DE |
8659 | read_die_and_siblings (const struct die_reader_specs *reader, |
8660 | gdb_byte *info_ptr, | |
fe1b8b76 | 8661 | gdb_byte **new_info_ptr, |
639d11d3 DC |
8662 | struct die_info *parent) |
8663 | { | |
8664 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 8665 | gdb_byte *cur_ptr; |
639d11d3 | 8666 | |
c906108c | 8667 | cur_ptr = info_ptr; |
639d11d3 DC |
8668 | first_die = last_sibling = NULL; |
8669 | ||
8670 | while (1) | |
c906108c | 8671 | { |
639d11d3 | 8672 | struct die_info *die |
93311388 | 8673 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 8674 | |
1d325ec1 | 8675 | if (die == NULL) |
c906108c | 8676 | { |
639d11d3 DC |
8677 | *new_info_ptr = cur_ptr; |
8678 | return first_die; | |
c906108c | 8679 | } |
1d325ec1 DJ |
8680 | |
8681 | if (!first_die) | |
8682 | first_die = die; | |
c906108c | 8683 | else |
1d325ec1 DJ |
8684 | last_sibling->sibling = die; |
8685 | ||
8686 | last_sibling = die; | |
c906108c | 8687 | } |
c906108c SS |
8688 | } |
8689 | ||
93311388 DE |
8690 | /* Read the die from the .debug_info section buffer. Set DIEP to |
8691 | point to a newly allocated die with its information, except for its | |
8692 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
8693 | whether the die has children or not. */ | |
8694 | ||
8695 | static gdb_byte * | |
8696 | read_full_die (const struct die_reader_specs *reader, | |
8697 | struct die_info **diep, gdb_byte *info_ptr, | |
8698 | int *has_children) | |
8699 | { | |
8700 | unsigned int abbrev_number, bytes_read, i, offset; | |
8701 | struct abbrev_info *abbrev; | |
8702 | struct die_info *die; | |
8703 | struct dwarf2_cu *cu = reader->cu; | |
8704 | bfd *abfd = reader->abfd; | |
8705 | ||
8706 | offset = info_ptr - reader->buffer; | |
8707 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
8708 | info_ptr += bytes_read; | |
8709 | if (!abbrev_number) | |
8710 | { | |
8711 | *diep = NULL; | |
8712 | *has_children = 0; | |
8713 | return info_ptr; | |
8714 | } | |
8715 | ||
8716 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
8717 | if (!abbrev) | |
348e048f DE |
8718 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
8719 | abbrev_number, | |
8720 | bfd_get_filename (abfd)); | |
8721 | ||
93311388 DE |
8722 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
8723 | die->offset = offset; | |
8724 | die->tag = abbrev->tag; | |
8725 | die->abbrev = abbrev_number; | |
8726 | ||
8727 | die->num_attrs = abbrev->num_attrs; | |
8728 | ||
8729 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8730 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
8731 | abfd, info_ptr, cu); | |
8732 | ||
8733 | *diep = die; | |
8734 | *has_children = abbrev->has_children; | |
8735 | return info_ptr; | |
8736 | } | |
8737 | ||
c906108c SS |
8738 | /* In DWARF version 2, the description of the debugging information is |
8739 | stored in a separate .debug_abbrev section. Before we read any | |
8740 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
8741 | in a hash table. This function also sets flags in CU describing |
8742 | the data found in the abbrev table. */ | |
c906108c SS |
8743 | |
8744 | static void | |
e7c27a73 | 8745 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 8746 | { |
e7c27a73 | 8747 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 8748 | gdb_byte *abbrev_ptr; |
c906108c SS |
8749 | struct abbrev_info *cur_abbrev; |
8750 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
8751 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
8752 | struct attr_abbrev *cur_attrs; |
8753 | unsigned int allocated_attrs; | |
c906108c | 8754 | |
0963b4bd | 8755 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
8756 | obstack_init (&cu->abbrev_obstack); |
8757 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
8758 | (ABBREV_HASH_SIZE | |
8759 | * sizeof (struct abbrev_info *))); | |
8760 | memset (cu->dwarf2_abbrevs, 0, | |
8761 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 8762 | |
be391dca TT |
8763 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
8764 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 8765 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
8766 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8767 | abbrev_ptr += bytes_read; | |
8768 | ||
f3dd6933 DJ |
8769 | allocated_attrs = ATTR_ALLOC_CHUNK; |
8770 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 8771 | |
0963b4bd | 8772 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
8773 | while (abbrev_number) |
8774 | { | |
f3dd6933 | 8775 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
8776 | |
8777 | /* read in abbrev header */ | |
8778 | cur_abbrev->number = abbrev_number; | |
8779 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8780 | abbrev_ptr += bytes_read; | |
8781 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
8782 | abbrev_ptr += 1; | |
8783 | ||
72bf9492 DJ |
8784 | if (cur_abbrev->tag == DW_TAG_namespace) |
8785 | cu->has_namespace_info = 1; | |
8786 | ||
c906108c SS |
8787 | /* now read in declarations */ |
8788 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8789 | abbrev_ptr += bytes_read; | |
8790 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8791 | abbrev_ptr += bytes_read; | |
8792 | while (abbrev_name) | |
8793 | { | |
f3dd6933 | 8794 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 8795 | { |
f3dd6933 DJ |
8796 | allocated_attrs += ATTR_ALLOC_CHUNK; |
8797 | cur_attrs | |
8798 | = xrealloc (cur_attrs, (allocated_attrs | |
8799 | * sizeof (struct attr_abbrev))); | |
c906108c | 8800 | } |
ae038cb0 DJ |
8801 | |
8802 | /* Record whether this compilation unit might have | |
8803 | inter-compilation-unit references. If we don't know what form | |
8804 | this attribute will have, then it might potentially be a | |
8805 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
8806 | references. */ | |
8807 | ||
8808 | if (abbrev_form == DW_FORM_ref_addr | |
8809 | || abbrev_form == DW_FORM_indirect) | |
8810 | cu->has_form_ref_addr = 1; | |
8811 | ||
f3dd6933 DJ |
8812 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
8813 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
8814 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8815 | abbrev_ptr += bytes_read; | |
8816 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8817 | abbrev_ptr += bytes_read; | |
8818 | } | |
8819 | ||
f3dd6933 DJ |
8820 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
8821 | (cur_abbrev->num_attrs | |
8822 | * sizeof (struct attr_abbrev))); | |
8823 | memcpy (cur_abbrev->attrs, cur_attrs, | |
8824 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
8825 | ||
c906108c | 8826 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
8827 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
8828 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
8829 | |
8830 | /* Get next abbreviation. | |
8831 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
8832 | always properly terminated with an abbrev number of 0. |
8833 | Exit loop if we encounter an abbreviation which we have | |
8834 | already read (which means we are about to read the abbreviations | |
8835 | for the next compile unit) or if the end of the abbreviation | |
8836 | table is reached. */ | |
dce234bc PP |
8837 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
8838 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
8839 | break; |
8840 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8841 | abbrev_ptr += bytes_read; | |
e7c27a73 | 8842 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
8843 | break; |
8844 | } | |
f3dd6933 DJ |
8845 | |
8846 | xfree (cur_attrs); | |
c906108c SS |
8847 | } |
8848 | ||
f3dd6933 | 8849 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 8850 | |
c906108c | 8851 | static void |
f3dd6933 | 8852 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 8853 | { |
f3dd6933 | 8854 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 8855 | |
f3dd6933 DJ |
8856 | obstack_free (&cu->abbrev_obstack, NULL); |
8857 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
8858 | } |
8859 | ||
8860 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
8861 | ||
8862 | static struct abbrev_info * | |
e7c27a73 | 8863 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
8864 | { |
8865 | unsigned int hash_number; | |
8866 | struct abbrev_info *abbrev; | |
8867 | ||
8868 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 8869 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
8870 | |
8871 | while (abbrev) | |
8872 | { | |
8873 | if (abbrev->number == number) | |
8874 | return abbrev; | |
8875 | else | |
8876 | abbrev = abbrev->next; | |
8877 | } | |
8878 | return NULL; | |
8879 | } | |
8880 | ||
72bf9492 DJ |
8881 | /* Returns nonzero if TAG represents a type that we might generate a partial |
8882 | symbol for. */ | |
8883 | ||
8884 | static int | |
8885 | is_type_tag_for_partial (int tag) | |
8886 | { | |
8887 | switch (tag) | |
8888 | { | |
8889 | #if 0 | |
8890 | /* Some types that would be reasonable to generate partial symbols for, | |
8891 | that we don't at present. */ | |
8892 | case DW_TAG_array_type: | |
8893 | case DW_TAG_file_type: | |
8894 | case DW_TAG_ptr_to_member_type: | |
8895 | case DW_TAG_set_type: | |
8896 | case DW_TAG_string_type: | |
8897 | case DW_TAG_subroutine_type: | |
8898 | #endif | |
8899 | case DW_TAG_base_type: | |
8900 | case DW_TAG_class_type: | |
680b30c7 | 8901 | case DW_TAG_interface_type: |
72bf9492 DJ |
8902 | case DW_TAG_enumeration_type: |
8903 | case DW_TAG_structure_type: | |
8904 | case DW_TAG_subrange_type: | |
8905 | case DW_TAG_typedef: | |
8906 | case DW_TAG_union_type: | |
8907 | return 1; | |
8908 | default: | |
8909 | return 0; | |
8910 | } | |
8911 | } | |
8912 | ||
8913 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
8914 | ||
8915 | static struct partial_die_info * | |
93311388 DE |
8916 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
8917 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
8918 | { |
8919 | struct partial_die_info *part_die; | |
8920 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
8921 | struct abbrev_info *abbrev; | |
8922 | unsigned int bytes_read; | |
5afb4e99 | 8923 | unsigned int load_all = 0; |
72bf9492 DJ |
8924 | |
8925 | int nesting_level = 1; | |
8926 | ||
8927 | parent_die = NULL; | |
8928 | last_die = NULL; | |
8929 | ||
5afb4e99 DJ |
8930 | if (cu->per_cu && cu->per_cu->load_all_dies) |
8931 | load_all = 1; | |
8932 | ||
72bf9492 DJ |
8933 | cu->partial_dies |
8934 | = htab_create_alloc_ex (cu->header.length / 12, | |
8935 | partial_die_hash, | |
8936 | partial_die_eq, | |
8937 | NULL, | |
8938 | &cu->comp_unit_obstack, | |
8939 | hashtab_obstack_allocate, | |
8940 | dummy_obstack_deallocate); | |
8941 | ||
8942 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8943 | sizeof (struct partial_die_info)); | |
8944 | ||
8945 | while (1) | |
8946 | { | |
8947 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
8948 | ||
8949 | /* A NULL abbrev means the end of a series of children. */ | |
8950 | if (abbrev == NULL) | |
8951 | { | |
8952 | if (--nesting_level == 0) | |
8953 | { | |
8954 | /* PART_DIE was probably the last thing allocated on the | |
8955 | comp_unit_obstack, so we could call obstack_free | |
8956 | here. We don't do that because the waste is small, | |
8957 | and will be cleaned up when we're done with this | |
8958 | compilation unit. This way, we're also more robust | |
8959 | against other users of the comp_unit_obstack. */ | |
8960 | return first_die; | |
8961 | } | |
8962 | info_ptr += bytes_read; | |
8963 | last_die = parent_die; | |
8964 | parent_die = parent_die->die_parent; | |
8965 | continue; | |
8966 | } | |
8967 | ||
98bfdba5 PA |
8968 | /* Check for template arguments. We never save these; if |
8969 | they're seen, we just mark the parent, and go on our way. */ | |
8970 | if (parent_die != NULL | |
8971 | && cu->language == language_cplus | |
8972 | && (abbrev->tag == DW_TAG_template_type_param | |
8973 | || abbrev->tag == DW_TAG_template_value_param)) | |
8974 | { | |
8975 | parent_die->has_template_arguments = 1; | |
8976 | ||
8977 | if (!load_all) | |
8978 | { | |
8979 | /* We don't need a partial DIE for the template argument. */ | |
8980 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
8981 | cu); | |
8982 | continue; | |
8983 | } | |
8984 | } | |
8985 | ||
8986 | /* We only recurse into subprograms looking for template arguments. | |
8987 | Skip their other children. */ | |
8988 | if (!load_all | |
8989 | && cu->language == language_cplus | |
8990 | && parent_die != NULL | |
8991 | && parent_die->tag == DW_TAG_subprogram) | |
8992 | { | |
8993 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
8994 | continue; | |
8995 | } | |
8996 | ||
5afb4e99 DJ |
8997 | /* Check whether this DIE is interesting enough to save. Normally |
8998 | we would not be interested in members here, but there may be | |
8999 | later variables referencing them via DW_AT_specification (for | |
9000 | static members). */ | |
9001 | if (!load_all | |
9002 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 9003 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
9004 | && abbrev->tag != DW_TAG_enumerator |
9005 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 9006 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 9007 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 9008 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 9009 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 9010 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
9011 | { |
9012 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9013 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
9014 | continue; |
9015 | } | |
9016 | ||
93311388 DE |
9017 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
9018 | buffer, info_ptr, cu); | |
72bf9492 DJ |
9019 | |
9020 | /* This two-pass algorithm for processing partial symbols has a | |
9021 | high cost in cache pressure. Thus, handle some simple cases | |
9022 | here which cover the majority of C partial symbols. DIEs | |
9023 | which neither have specification tags in them, nor could have | |
9024 | specification tags elsewhere pointing at them, can simply be | |
9025 | processed and discarded. | |
9026 | ||
9027 | This segment is also optional; scan_partial_symbols and | |
9028 | add_partial_symbol will handle these DIEs if we chain | |
9029 | them in normally. When compilers which do not emit large | |
9030 | quantities of duplicate debug information are more common, | |
9031 | this code can probably be removed. */ | |
9032 | ||
9033 | /* Any complete simple types at the top level (pretty much all | |
9034 | of them, for a language without namespaces), can be processed | |
9035 | directly. */ | |
9036 | if (parent_die == NULL | |
9037 | && part_die->has_specification == 0 | |
9038 | && part_die->is_declaration == 0 | |
d8228535 | 9039 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
9040 | || part_die->tag == DW_TAG_base_type |
9041 | || part_die->tag == DW_TAG_subrange_type)) | |
9042 | { | |
9043 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 9044 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
9045 | VAR_DOMAIN, LOC_TYPEDEF, |
9046 | &cu->objfile->static_psymbols, | |
9047 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 9048 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9049 | continue; |
9050 | } | |
9051 | ||
d8228535 JK |
9052 | /* The exception for DW_TAG_typedef with has_children above is |
9053 | a workaround of GCC PR debug/47510. In the case of this complaint | |
9054 | type_name_no_tag_or_error will error on such types later. | |
9055 | ||
9056 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
9057 | it could not find the child DIEs referenced later, this is checked | |
9058 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
9059 | ||
9060 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
9061 | complaint (&symfile_complaints, | |
9062 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
9063 | "- DIE at 0x%x [in module %s]"), | |
9064 | part_die->offset, cu->objfile->name); | |
9065 | ||
72bf9492 DJ |
9066 | /* If we're at the second level, and we're an enumerator, and |
9067 | our parent has no specification (meaning possibly lives in a | |
9068 | namespace elsewhere), then we can add the partial symbol now | |
9069 | instead of queueing it. */ | |
9070 | if (part_die->tag == DW_TAG_enumerator | |
9071 | && parent_die != NULL | |
9072 | && parent_die->die_parent == NULL | |
9073 | && parent_die->tag == DW_TAG_enumeration_type | |
9074 | && parent_die->has_specification == 0) | |
9075 | { | |
9076 | if (part_die->name == NULL) | |
3e43a32a MS |
9077 | complaint (&symfile_complaints, |
9078 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 9079 | else if (building_psymtab) |
04a679b8 | 9080 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9081 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
9082 | (cu->language == language_cplus |
9083 | || cu->language == language_java) | |
72bf9492 DJ |
9084 | ? &cu->objfile->global_psymbols |
9085 | : &cu->objfile->static_psymbols, | |
9086 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
9087 | ||
93311388 | 9088 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9089 | continue; |
9090 | } | |
9091 | ||
9092 | /* We'll save this DIE so link it in. */ | |
9093 | part_die->die_parent = parent_die; | |
9094 | part_die->die_sibling = NULL; | |
9095 | part_die->die_child = NULL; | |
9096 | ||
9097 | if (last_die && last_die == parent_die) | |
9098 | last_die->die_child = part_die; | |
9099 | else if (last_die) | |
9100 | last_die->die_sibling = part_die; | |
9101 | ||
9102 | last_die = part_die; | |
9103 | ||
9104 | if (first_die == NULL) | |
9105 | first_die = part_die; | |
9106 | ||
9107 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
9108 | find interesting need to be in the hash table, because we | |
9109 | also have the parent/sibling/child chains; only those that we | |
9110 | might refer to by offset later during partial symbol reading. | |
9111 | ||
9112 | For now this means things that might have be the target of a | |
9113 | DW_AT_specification, DW_AT_abstract_origin, or | |
9114 | DW_AT_extension. DW_AT_extension will refer only to | |
9115 | namespaces; DW_AT_abstract_origin refers to functions (and | |
9116 | many things under the function DIE, but we do not recurse | |
9117 | into function DIEs during partial symbol reading) and | |
9118 | possibly variables as well; DW_AT_specification refers to | |
9119 | declarations. Declarations ought to have the DW_AT_declaration | |
9120 | flag. It happens that GCC forgets to put it in sometimes, but | |
9121 | only for functions, not for types. | |
9122 | ||
9123 | Adding more things than necessary to the hash table is harmless | |
9124 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
9125 | wasted time in find_partial_die, when we reread the compilation |
9126 | unit with load_all_dies set. */ | |
72bf9492 | 9127 | |
5afb4e99 | 9128 | if (load_all |
72929c62 | 9129 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 9130 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
9131 | || abbrev->tag == DW_TAG_variable |
9132 | || abbrev->tag == DW_TAG_namespace | |
9133 | || part_die->is_declaration) | |
9134 | { | |
9135 | void **slot; | |
9136 | ||
9137 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
9138 | part_die->offset, INSERT); | |
9139 | *slot = part_die; | |
9140 | } | |
9141 | ||
9142 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9143 | sizeof (struct partial_die_info)); | |
9144 | ||
9145 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 9146 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
9147 | languages we have to, so that we can get at method physnames |
9148 | to infer fully qualified class names, for DW_AT_specification, | |
9149 | and for C++ template arguments. For C++, we also look one level | |
9150 | inside functions to find template arguments (if the name of the | |
9151 | function does not already contain the template arguments). | |
bc30ff58 JB |
9152 | |
9153 | For Ada, we need to scan the children of subprograms and lexical | |
9154 | blocks as well because Ada allows the definition of nested | |
9155 | entities that could be interesting for the debugger, such as | |
9156 | nested subprograms for instance. */ | |
72bf9492 | 9157 | if (last_die->has_children |
5afb4e99 DJ |
9158 | && (load_all |
9159 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 9160 | || last_die->tag == DW_TAG_module |
72bf9492 | 9161 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
9162 | || (cu->language == language_cplus |
9163 | && last_die->tag == DW_TAG_subprogram | |
9164 | && (last_die->name == NULL | |
9165 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
9166 | || (cu->language != language_c |
9167 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 9168 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 9169 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
9170 | || last_die->tag == DW_TAG_union_type)) |
9171 | || (cu->language == language_ada | |
9172 | && (last_die->tag == DW_TAG_subprogram | |
9173 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9174 | { |
9175 | nesting_level++; | |
9176 | parent_die = last_die; | |
9177 | continue; | |
9178 | } | |
9179 | ||
9180 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9181 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9182 | |
9183 | /* Back to the top, do it again. */ | |
9184 | } | |
9185 | } | |
9186 | ||
c906108c SS |
9187 | /* Read a minimal amount of information into the minimal die structure. */ |
9188 | ||
fe1b8b76 | 9189 | static gdb_byte * |
72bf9492 DJ |
9190 | read_partial_die (struct partial_die_info *part_die, |
9191 | struct abbrev_info *abbrev, | |
9192 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
9193 | gdb_byte *buffer, gdb_byte *info_ptr, |
9194 | struct dwarf2_cu *cu) | |
c906108c | 9195 | { |
fa238c03 | 9196 | unsigned int i; |
c906108c | 9197 | struct attribute attr; |
c5aa993b | 9198 | int has_low_pc_attr = 0; |
c906108c SS |
9199 | int has_high_pc_attr = 0; |
9200 | ||
72bf9492 | 9201 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 9202 | |
93311388 | 9203 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
9204 | |
9205 | info_ptr += abbrev_len; | |
9206 | ||
9207 | if (abbrev == NULL) | |
9208 | return info_ptr; | |
9209 | ||
c906108c SS |
9210 | part_die->tag = abbrev->tag; |
9211 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
9212 | |
9213 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9214 | { | |
e7c27a73 | 9215 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
9216 | |
9217 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 9218 | partial symbol table. */ |
c906108c SS |
9219 | switch (attr.name) |
9220 | { | |
9221 | case DW_AT_name: | |
71c25dea TT |
9222 | switch (part_die->tag) |
9223 | { | |
9224 | case DW_TAG_compile_unit: | |
348e048f | 9225 | case DW_TAG_type_unit: |
71c25dea TT |
9226 | /* Compilation units have a DW_AT_name that is a filename, not |
9227 | a source language identifier. */ | |
9228 | case DW_TAG_enumeration_type: | |
9229 | case DW_TAG_enumerator: | |
9230 | /* These tags always have simple identifiers already; no need | |
9231 | to canonicalize them. */ | |
9232 | part_die->name = DW_STRING (&attr); | |
9233 | break; | |
9234 | default: | |
9235 | part_die->name | |
9236 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 9237 | &cu->objfile->objfile_obstack); |
71c25dea TT |
9238 | break; |
9239 | } | |
c906108c | 9240 | break; |
31ef98ae | 9241 | case DW_AT_linkage_name: |
c906108c | 9242 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
9243 | /* Note that both forms of linkage name might appear. We |
9244 | assume they will be the same, and we only store the last | |
9245 | one we see. */ | |
94af9270 KS |
9246 | if (cu->language == language_ada) |
9247 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 9248 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
9249 | break; |
9250 | case DW_AT_low_pc: | |
9251 | has_low_pc_attr = 1; | |
9252 | part_die->lowpc = DW_ADDR (&attr); | |
9253 | break; | |
9254 | case DW_AT_high_pc: | |
9255 | has_high_pc_attr = 1; | |
9256 | part_die->highpc = DW_ADDR (&attr); | |
9257 | break; | |
9258 | case DW_AT_location: | |
0963b4bd | 9259 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9260 | if (attr_form_is_block (&attr)) |
9261 | { | |
9262 | part_die->locdesc = DW_BLOCK (&attr); | |
9263 | } | |
3690dd37 | 9264 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 9265 | { |
4d3c2250 | 9266 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9267 | } |
9268 | else | |
9269 | { | |
4d3c2250 KB |
9270 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9271 | "partial symbol information"); | |
8e19ed76 | 9272 | } |
c906108c | 9273 | break; |
c906108c SS |
9274 | case DW_AT_external: |
9275 | part_die->is_external = DW_UNSND (&attr); | |
9276 | break; | |
9277 | case DW_AT_declaration: | |
9278 | part_die->is_declaration = DW_UNSND (&attr); | |
9279 | break; | |
9280 | case DW_AT_type: | |
9281 | part_die->has_type = 1; | |
9282 | break; | |
9283 | case DW_AT_abstract_origin: | |
9284 | case DW_AT_specification: | |
72bf9492 DJ |
9285 | case DW_AT_extension: |
9286 | part_die->has_specification = 1; | |
c764a876 | 9287 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
9288 | break; |
9289 | case DW_AT_sibling: | |
9290 | /* Ignore absolute siblings, they might point outside of | |
9291 | the current compile unit. */ | |
9292 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
9293 | complaint (&symfile_complaints, |
9294 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 9295 | else |
93311388 | 9296 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 9297 | break; |
fa4028e9 JB |
9298 | case DW_AT_byte_size: |
9299 | part_die->has_byte_size = 1; | |
9300 | break; | |
68511cec CES |
9301 | case DW_AT_calling_convention: |
9302 | /* DWARF doesn't provide a way to identify a program's source-level | |
9303 | entry point. DW_AT_calling_convention attributes are only meant | |
9304 | to describe functions' calling conventions. | |
9305 | ||
9306 | However, because it's a necessary piece of information in | |
9307 | Fortran, and because DW_CC_program is the only piece of debugging | |
9308 | information whose definition refers to a 'main program' at all, | |
9309 | several compilers have begun marking Fortran main programs with | |
9310 | DW_CC_program --- even when those functions use the standard | |
9311 | calling conventions. | |
9312 | ||
9313 | So until DWARF specifies a way to provide this information and | |
9314 | compilers pick up the new representation, we'll support this | |
9315 | practice. */ | |
9316 | if (DW_UNSND (&attr) == DW_CC_program | |
9317 | && cu->language == language_fortran) | |
01f8c46d JK |
9318 | { |
9319 | set_main_name (part_die->name); | |
9320 | ||
9321 | /* As this DIE has a static linkage the name would be difficult | |
9322 | to look up later. */ | |
9323 | language_of_main = language_fortran; | |
9324 | } | |
68511cec | 9325 | break; |
c906108c SS |
9326 | default: |
9327 | break; | |
9328 | } | |
9329 | } | |
9330 | ||
9373cf26 JK |
9331 | if (has_low_pc_attr && has_high_pc_attr) |
9332 | { | |
9333 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
9334 | eliminate duplicate copies of functions and vtables and such. | |
9335 | The linker will arbitrarily choose one and discard the others. | |
9336 | The AT_*_pc values for such functions refer to local labels in | |
9337 | these sections. If the section from that file was discarded, the | |
9338 | labels are not in the output, so the relocs get a value of 0. | |
9339 | If this is a discarded function, mark the pc bounds as invalid, | |
9340 | so that GDB will ignore it. */ | |
9341 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
9342 | { | |
9343 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); | |
9344 | ||
9345 | complaint (&symfile_complaints, | |
9346 | _("DW_AT_low_pc %s is zero " | |
9347 | "for DIE at 0x%x [in module %s]"), | |
9348 | paddress (gdbarch, part_die->lowpc), | |
9349 | part_die->offset, cu->objfile->name); | |
9350 | } | |
9351 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
9352 | else if (part_die->lowpc >= part_die->highpc) | |
9353 | { | |
9354 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); | |
9355 | ||
9356 | complaint (&symfile_complaints, | |
9357 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
9358 | "for DIE at 0x%x [in module %s]"), | |
9359 | paddress (gdbarch, part_die->lowpc), | |
9360 | paddress (gdbarch, part_die->highpc), | |
9361 | part_die->offset, cu->objfile->name); | |
9362 | } | |
9363 | else | |
9364 | part_die->has_pc_info = 1; | |
9365 | } | |
85cbf3d3 | 9366 | |
c906108c SS |
9367 | return info_ptr; |
9368 | } | |
9369 | ||
72bf9492 DJ |
9370 | /* Find a cached partial DIE at OFFSET in CU. */ |
9371 | ||
9372 | static struct partial_die_info * | |
c764a876 | 9373 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
9374 | { |
9375 | struct partial_die_info *lookup_die = NULL; | |
9376 | struct partial_die_info part_die; | |
9377 | ||
9378 | part_die.offset = offset; | |
9379 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
9380 | ||
72bf9492 DJ |
9381 | return lookup_die; |
9382 | } | |
9383 | ||
348e048f DE |
9384 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
9385 | except in the case of .debug_types DIEs which do not reference | |
9386 | outside their CU (they do however referencing other types via | |
55f1336d | 9387 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
9388 | |
9389 | static struct partial_die_info * | |
c764a876 | 9390 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 9391 | { |
5afb4e99 DJ |
9392 | struct dwarf2_per_cu_data *per_cu = NULL; |
9393 | struct partial_die_info *pd = NULL; | |
72bf9492 | 9394 | |
348e048f DE |
9395 | if (cu->per_cu->from_debug_types) |
9396 | { | |
9397 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9398 | if (pd != NULL) | |
9399 | return pd; | |
9400 | goto not_found; | |
9401 | } | |
9402 | ||
45452591 | 9403 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
9404 | { |
9405 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9406 | if (pd != NULL) | |
9407 | return pd; | |
9408 | } | |
72bf9492 | 9409 | |
ae038cb0 DJ |
9410 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
9411 | ||
98bfdba5 PA |
9412 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
9413 | load_partial_comp_unit (per_cu, cu->objfile); | |
ae038cb0 DJ |
9414 | |
9415 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
9416 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
9417 | ||
9418 | if (pd == NULL && per_cu->load_all_dies == 0) | |
9419 | { | |
9420 | struct cleanup *back_to; | |
9421 | struct partial_die_info comp_unit_die; | |
9422 | struct abbrev_info *abbrev; | |
9423 | unsigned int bytes_read; | |
9424 | char *info_ptr; | |
9425 | ||
9426 | per_cu->load_all_dies = 1; | |
9427 | ||
9428 | /* Re-read the DIEs. */ | |
9429 | back_to = make_cleanup (null_cleanup, 0); | |
9430 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
9431 | { | |
9432 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 9433 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 9434 | } |
dce234bc | 9435 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
9436 | + per_cu->cu->header.offset |
9437 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
9438 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
9439 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
9440 | per_cu->cu->objfile->obfd, |
9441 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
9442 | per_cu->cu); |
9443 | if (comp_unit_die.has_children) | |
93311388 DE |
9444 | load_partial_dies (per_cu->cu->objfile->obfd, |
9445 | dwarf2_per_objfile->info.buffer, info_ptr, | |
9446 | 0, per_cu->cu); | |
5afb4e99 DJ |
9447 | do_cleanups (back_to); |
9448 | ||
9449 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
9450 | } | |
9451 | ||
348e048f DE |
9452 | not_found: |
9453 | ||
5afb4e99 DJ |
9454 | if (pd == NULL) |
9455 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
9456 | _("could not find partial DIE 0x%x " |
9457 | "in cache [from module %s]\n"), | |
5afb4e99 DJ |
9458 | offset, bfd_get_filename (cu->objfile->obfd)); |
9459 | return pd; | |
72bf9492 DJ |
9460 | } |
9461 | ||
abc72ce4 DE |
9462 | /* See if we can figure out if the class lives in a namespace. We do |
9463 | this by looking for a member function; its demangled name will | |
9464 | contain namespace info, if there is any. */ | |
9465 | ||
9466 | static void | |
9467 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
9468 | struct dwarf2_cu *cu) | |
9469 | { | |
9470 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
9471 | what template types look like, because the demangler | |
9472 | frequently doesn't give the same name as the debug info. We | |
9473 | could fix this by only using the demangled name to get the | |
9474 | prefix (but see comment in read_structure_type). */ | |
9475 | ||
9476 | struct partial_die_info *real_pdi; | |
9477 | struct partial_die_info *child_pdi; | |
9478 | ||
9479 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
9480 | we should not do this. We'll prepend the parent's fully qualified | |
9481 | name when we create the partial symbol. */ | |
9482 | ||
9483 | real_pdi = struct_pdi; | |
9484 | while (real_pdi->has_specification) | |
9485 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
9486 | ||
9487 | if (real_pdi->die_parent != NULL) | |
9488 | return; | |
9489 | ||
9490 | for (child_pdi = struct_pdi->die_child; | |
9491 | child_pdi != NULL; | |
9492 | child_pdi = child_pdi->die_sibling) | |
9493 | { | |
9494 | if (child_pdi->tag == DW_TAG_subprogram | |
9495 | && child_pdi->linkage_name != NULL) | |
9496 | { | |
9497 | char *actual_class_name | |
9498 | = language_class_name_from_physname (cu->language_defn, | |
9499 | child_pdi->linkage_name); | |
9500 | if (actual_class_name != NULL) | |
9501 | { | |
9502 | struct_pdi->name | |
9503 | = obsavestring (actual_class_name, | |
9504 | strlen (actual_class_name), | |
9505 | &cu->objfile->objfile_obstack); | |
9506 | xfree (actual_class_name); | |
9507 | } | |
9508 | break; | |
9509 | } | |
9510 | } | |
9511 | } | |
9512 | ||
72bf9492 DJ |
9513 | /* Adjust PART_DIE before generating a symbol for it. This function |
9514 | may set the is_external flag or change the DIE's name. */ | |
9515 | ||
9516 | static void | |
9517 | fixup_partial_die (struct partial_die_info *part_die, | |
9518 | struct dwarf2_cu *cu) | |
9519 | { | |
abc72ce4 DE |
9520 | /* Once we've fixed up a die, there's no point in doing so again. |
9521 | This also avoids a memory leak if we were to call | |
9522 | guess_partial_die_structure_name multiple times. */ | |
9523 | if (part_die->fixup_called) | |
9524 | return; | |
9525 | ||
72bf9492 DJ |
9526 | /* If we found a reference attribute and the DIE has no name, try |
9527 | to find a name in the referred to DIE. */ | |
9528 | ||
9529 | if (part_die->name == NULL && part_die->has_specification) | |
9530 | { | |
9531 | struct partial_die_info *spec_die; | |
72bf9492 | 9532 | |
10b3939b | 9533 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 9534 | |
10b3939b | 9535 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
9536 | |
9537 | if (spec_die->name) | |
9538 | { | |
9539 | part_die->name = spec_die->name; | |
9540 | ||
9541 | /* Copy DW_AT_external attribute if it is set. */ | |
9542 | if (spec_die->is_external) | |
9543 | part_die->is_external = spec_die->is_external; | |
9544 | } | |
9545 | } | |
9546 | ||
9547 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
9548 | |
9549 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 9550 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 9551 | |
abc72ce4 DE |
9552 | /* If there is no parent die to provide a namespace, and there are |
9553 | children, see if we can determine the namespace from their linkage | |
9554 | name. | |
9555 | NOTE: We need to do this even if cu->has_namespace_info != 0. | |
9556 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ | |
9557 | if (cu->language == language_cplus | |
9558 | && dwarf2_per_objfile->types.asection != NULL | |
9559 | && part_die->die_parent == NULL | |
9560 | && part_die->has_children | |
9561 | && (part_die->tag == DW_TAG_class_type | |
9562 | || part_die->tag == DW_TAG_structure_type | |
9563 | || part_die->tag == DW_TAG_union_type)) | |
9564 | guess_partial_die_structure_name (part_die, cu); | |
9565 | ||
53832f31 TT |
9566 | /* GCC might emit a nameless struct or union that has a linkage |
9567 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
9568 | if (part_die->name == NULL | |
9569 | && (part_die->tag == DW_TAG_structure_type | |
9570 | || part_die->tag == DW_TAG_union_type | |
9571 | || part_die->tag == DW_TAG_class_type) | |
9572 | && part_die->linkage_name != NULL) | |
9573 | { | |
9574 | char *demangled; | |
9575 | ||
9576 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
9577 | if (demangled) | |
9578 | { | |
9579 | part_die->name = obsavestring (demangled, strlen (demangled), | |
9580 | &cu->objfile->objfile_obstack); | |
9581 | xfree (demangled); | |
9582 | } | |
9583 | } | |
9584 | ||
abc72ce4 | 9585 | part_die->fixup_called = 1; |
72bf9492 DJ |
9586 | } |
9587 | ||
a8329558 | 9588 | /* Read an attribute value described by an attribute form. */ |
c906108c | 9589 | |
fe1b8b76 | 9590 | static gdb_byte * |
a8329558 | 9591 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 9592 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 9593 | struct dwarf2_cu *cu) |
c906108c | 9594 | { |
e7c27a73 | 9595 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9596 | unsigned int bytes_read; |
9597 | struct dwarf_block *blk; | |
9598 | ||
a8329558 KW |
9599 | attr->form = form; |
9600 | switch (form) | |
c906108c | 9601 | { |
c906108c | 9602 | case DW_FORM_ref_addr: |
ae411497 TT |
9603 | if (cu->header.version == 2) |
9604 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
9605 | else | |
3e43a32a MS |
9606 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
9607 | &cu->header, &bytes_read); | |
ae411497 TT |
9608 | info_ptr += bytes_read; |
9609 | break; | |
9610 | case DW_FORM_addr: | |
e7c27a73 | 9611 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 9612 | info_ptr += bytes_read; |
c906108c SS |
9613 | break; |
9614 | case DW_FORM_block2: | |
7b5a2f43 | 9615 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9616 | blk->size = read_2_bytes (abfd, info_ptr); |
9617 | info_ptr += 2; | |
9618 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9619 | info_ptr += blk->size; | |
9620 | DW_BLOCK (attr) = blk; | |
9621 | break; | |
9622 | case DW_FORM_block4: | |
7b5a2f43 | 9623 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9624 | blk->size = read_4_bytes (abfd, info_ptr); |
9625 | info_ptr += 4; | |
9626 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9627 | info_ptr += blk->size; | |
9628 | DW_BLOCK (attr) = blk; | |
9629 | break; | |
9630 | case DW_FORM_data2: | |
9631 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
9632 | info_ptr += 2; | |
9633 | break; | |
9634 | case DW_FORM_data4: | |
9635 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
9636 | info_ptr += 4; | |
9637 | break; | |
9638 | case DW_FORM_data8: | |
9639 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
9640 | info_ptr += 8; | |
9641 | break; | |
2dc7f7b3 TT |
9642 | case DW_FORM_sec_offset: |
9643 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
9644 | info_ptr += bytes_read; | |
9645 | break; | |
c906108c | 9646 | case DW_FORM_string: |
9b1c24c8 | 9647 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 9648 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
9649 | info_ptr += bytes_read; |
9650 | break; | |
4bdf3d34 JJ |
9651 | case DW_FORM_strp: |
9652 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
9653 | &bytes_read); | |
8285870a | 9654 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
9655 | info_ptr += bytes_read; |
9656 | break; | |
2dc7f7b3 | 9657 | case DW_FORM_exprloc: |
c906108c | 9658 | case DW_FORM_block: |
7b5a2f43 | 9659 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9660 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9661 | info_ptr += bytes_read; | |
9662 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9663 | info_ptr += blk->size; | |
9664 | DW_BLOCK (attr) = blk; | |
9665 | break; | |
9666 | case DW_FORM_block1: | |
7b5a2f43 | 9667 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9668 | blk->size = read_1_byte (abfd, info_ptr); |
9669 | info_ptr += 1; | |
9670 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9671 | info_ptr += blk->size; | |
9672 | DW_BLOCK (attr) = blk; | |
9673 | break; | |
9674 | case DW_FORM_data1: | |
9675 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9676 | info_ptr += 1; | |
9677 | break; | |
9678 | case DW_FORM_flag: | |
9679 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9680 | info_ptr += 1; | |
9681 | break; | |
2dc7f7b3 TT |
9682 | case DW_FORM_flag_present: |
9683 | DW_UNSND (attr) = 1; | |
9684 | break; | |
c906108c SS |
9685 | case DW_FORM_sdata: |
9686 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
9687 | info_ptr += bytes_read; | |
9688 | break; | |
9689 | case DW_FORM_udata: | |
9690 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9691 | info_ptr += bytes_read; | |
9692 | break; | |
9693 | case DW_FORM_ref1: | |
10b3939b | 9694 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
9695 | info_ptr += 1; |
9696 | break; | |
9697 | case DW_FORM_ref2: | |
10b3939b | 9698 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
9699 | info_ptr += 2; |
9700 | break; | |
9701 | case DW_FORM_ref4: | |
10b3939b | 9702 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
9703 | info_ptr += 4; |
9704 | break; | |
613e1657 | 9705 | case DW_FORM_ref8: |
10b3939b | 9706 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
9707 | info_ptr += 8; |
9708 | break; | |
55f1336d | 9709 | case DW_FORM_ref_sig8: |
348e048f DE |
9710 | /* Convert the signature to something we can record in DW_UNSND |
9711 | for later lookup. | |
9712 | NOTE: This is NULL if the type wasn't found. */ | |
9713 | DW_SIGNATURED_TYPE (attr) = | |
9714 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
9715 | info_ptr += 8; | |
9716 | break; | |
c906108c | 9717 | case DW_FORM_ref_udata: |
10b3939b DJ |
9718 | DW_ADDR (attr) = (cu->header.offset |
9719 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
9720 | info_ptr += bytes_read; |
9721 | break; | |
c906108c | 9722 | case DW_FORM_indirect: |
a8329558 KW |
9723 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9724 | info_ptr += bytes_read; | |
e7c27a73 | 9725 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 9726 | break; |
c906108c | 9727 | default: |
8a3fe4f8 | 9728 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
9729 | dwarf_form_name (form), |
9730 | bfd_get_filename (abfd)); | |
c906108c | 9731 | } |
28e94949 JB |
9732 | |
9733 | /* We have seen instances where the compiler tried to emit a byte | |
9734 | size attribute of -1 which ended up being encoded as an unsigned | |
9735 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
9736 | an object of this size seems pretty unlikely so we can relatively | |
9737 | safely treat these cases as if the size attribute was invalid and | |
9738 | treat them as zero by default. */ | |
9739 | if (attr->name == DW_AT_byte_size | |
9740 | && form == DW_FORM_data4 | |
9741 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
9742 | { |
9743 | complaint | |
9744 | (&symfile_complaints, | |
43bbcdc2 PH |
9745 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
9746 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
9747 | DW_UNSND (attr) = 0; |
9748 | } | |
28e94949 | 9749 | |
c906108c SS |
9750 | return info_ptr; |
9751 | } | |
9752 | ||
a8329558 KW |
9753 | /* Read an attribute described by an abbreviated attribute. */ |
9754 | ||
fe1b8b76 | 9755 | static gdb_byte * |
a8329558 | 9756 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 9757 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
9758 | { |
9759 | attr->name = abbrev->name; | |
e7c27a73 | 9760 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
9761 | } |
9762 | ||
0963b4bd | 9763 | /* Read dwarf information from a buffer. */ |
c906108c SS |
9764 | |
9765 | static unsigned int | |
fe1b8b76 | 9766 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9767 | { |
fe1b8b76 | 9768 | return bfd_get_8 (abfd, buf); |
c906108c SS |
9769 | } |
9770 | ||
9771 | static int | |
fe1b8b76 | 9772 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9773 | { |
fe1b8b76 | 9774 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
9775 | } |
9776 | ||
9777 | static unsigned int | |
fe1b8b76 | 9778 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9779 | { |
fe1b8b76 | 9780 | return bfd_get_16 (abfd, buf); |
c906108c SS |
9781 | } |
9782 | ||
9783 | static int | |
fe1b8b76 | 9784 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9785 | { |
fe1b8b76 | 9786 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
9787 | } |
9788 | ||
9789 | static unsigned int | |
fe1b8b76 | 9790 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9791 | { |
fe1b8b76 | 9792 | return bfd_get_32 (abfd, buf); |
c906108c SS |
9793 | } |
9794 | ||
9795 | static int | |
fe1b8b76 | 9796 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9797 | { |
fe1b8b76 | 9798 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
9799 | } |
9800 | ||
93311388 | 9801 | static ULONGEST |
fe1b8b76 | 9802 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9803 | { |
fe1b8b76 | 9804 | return bfd_get_64 (abfd, buf); |
c906108c SS |
9805 | } |
9806 | ||
9807 | static CORE_ADDR | |
fe1b8b76 | 9808 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 9809 | unsigned int *bytes_read) |
c906108c | 9810 | { |
e7c27a73 | 9811 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9812 | CORE_ADDR retval = 0; |
9813 | ||
107d2387 | 9814 | if (cu_header->signed_addr_p) |
c906108c | 9815 | { |
107d2387 AC |
9816 | switch (cu_header->addr_size) |
9817 | { | |
9818 | case 2: | |
fe1b8b76 | 9819 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
9820 | break; |
9821 | case 4: | |
fe1b8b76 | 9822 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
9823 | break; |
9824 | case 8: | |
fe1b8b76 | 9825 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
9826 | break; |
9827 | default: | |
8e65ff28 | 9828 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 9829 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 9830 | bfd_get_filename (abfd)); |
107d2387 AC |
9831 | } |
9832 | } | |
9833 | else | |
9834 | { | |
9835 | switch (cu_header->addr_size) | |
9836 | { | |
9837 | case 2: | |
fe1b8b76 | 9838 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
9839 | break; |
9840 | case 4: | |
fe1b8b76 | 9841 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
9842 | break; |
9843 | case 8: | |
fe1b8b76 | 9844 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
9845 | break; |
9846 | default: | |
8e65ff28 | 9847 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
9848 | _("read_address: bad switch, " |
9849 | "unsigned [in module %s]"), | |
659b0389 | 9850 | bfd_get_filename (abfd)); |
107d2387 | 9851 | } |
c906108c | 9852 | } |
64367e0a | 9853 | |
107d2387 AC |
9854 | *bytes_read = cu_header->addr_size; |
9855 | return retval; | |
c906108c SS |
9856 | } |
9857 | ||
f7ef9339 | 9858 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
9859 | specification allows the initial length to take up either 4 bytes |
9860 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
9861 | bytes describe the length and all offsets will be 8 bytes in length | |
9862 | instead of 4. | |
9863 | ||
f7ef9339 KB |
9864 | An older, non-standard 64-bit format is also handled by this |
9865 | function. The older format in question stores the initial length | |
9866 | as an 8-byte quantity without an escape value. Lengths greater | |
9867 | than 2^32 aren't very common which means that the initial 4 bytes | |
9868 | is almost always zero. Since a length value of zero doesn't make | |
9869 | sense for the 32-bit format, this initial zero can be considered to | |
9870 | be an escape value which indicates the presence of the older 64-bit | |
9871 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
9872 | greater than 4GB. If it becomes necessary to handle lengths |
9873 | somewhat larger than 4GB, we could allow other small values (such | |
9874 | as the non-sensical values of 1, 2, and 3) to also be used as | |
9875 | escape values indicating the presence of the old format. | |
f7ef9339 | 9876 | |
917c78fc MK |
9877 | The value returned via bytes_read should be used to increment the |
9878 | relevant pointer after calling read_initial_length(). | |
c764a876 | 9879 | |
613e1657 KB |
9880 | [ Note: read_initial_length() and read_offset() are based on the |
9881 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 9882 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
9883 | from: |
9884 | ||
f7ef9339 | 9885 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 9886 | |
613e1657 KB |
9887 | This document is only a draft and is subject to change. (So beware.) |
9888 | ||
f7ef9339 | 9889 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
9890 | determined empirically by examining 64-bit ELF files produced by |
9891 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
9892 | |
9893 | - Kevin, July 16, 2002 | |
613e1657 KB |
9894 | ] */ |
9895 | ||
9896 | static LONGEST | |
c764a876 | 9897 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 9898 | { |
fe1b8b76 | 9899 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 9900 | |
dd373385 | 9901 | if (length == 0xffffffff) |
613e1657 | 9902 | { |
fe1b8b76 | 9903 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 9904 | *bytes_read = 12; |
613e1657 | 9905 | } |
dd373385 | 9906 | else if (length == 0) |
f7ef9339 | 9907 | { |
dd373385 | 9908 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 9909 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 9910 | *bytes_read = 8; |
f7ef9339 | 9911 | } |
613e1657 KB |
9912 | else |
9913 | { | |
9914 | *bytes_read = 4; | |
613e1657 KB |
9915 | } |
9916 | ||
c764a876 DE |
9917 | return length; |
9918 | } | |
dd373385 | 9919 | |
c764a876 DE |
9920 | /* Cover function for read_initial_length. |
9921 | Returns the length of the object at BUF, and stores the size of the | |
9922 | initial length in *BYTES_READ and stores the size that offsets will be in | |
9923 | *OFFSET_SIZE. | |
9924 | If the initial length size is not equivalent to that specified in | |
9925 | CU_HEADER then issue a complaint. | |
9926 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 9927 | |
c764a876 DE |
9928 | static LONGEST |
9929 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
9930 | const struct comp_unit_head *cu_header, | |
9931 | unsigned int *bytes_read, | |
9932 | unsigned int *offset_size) | |
9933 | { | |
9934 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
9935 | ||
9936 | gdb_assert (cu_header->initial_length_size == 4 | |
9937 | || cu_header->initial_length_size == 8 | |
9938 | || cu_header->initial_length_size == 12); | |
9939 | ||
9940 | if (cu_header->initial_length_size != *bytes_read) | |
9941 | complaint (&symfile_complaints, | |
9942 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 9943 | |
c764a876 | 9944 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 9945 | return length; |
613e1657 KB |
9946 | } |
9947 | ||
9948 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 9949 | given by cu_header->offset_size. */ |
613e1657 KB |
9950 | |
9951 | static LONGEST | |
fe1b8b76 | 9952 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 9953 | unsigned int *bytes_read) |
c764a876 DE |
9954 | { |
9955 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 9956 | |
c764a876 DE |
9957 | *bytes_read = cu_header->offset_size; |
9958 | return offset; | |
9959 | } | |
9960 | ||
9961 | /* Read an offset from the data stream. */ | |
9962 | ||
9963 | static LONGEST | |
9964 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
9965 | { |
9966 | LONGEST retval = 0; | |
9967 | ||
c764a876 | 9968 | switch (offset_size) |
613e1657 KB |
9969 | { |
9970 | case 4: | |
fe1b8b76 | 9971 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
9972 | break; |
9973 | case 8: | |
fe1b8b76 | 9974 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
9975 | break; |
9976 | default: | |
8e65ff28 | 9977 | internal_error (__FILE__, __LINE__, |
c764a876 | 9978 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 9979 | bfd_get_filename (abfd)); |
613e1657 KB |
9980 | } |
9981 | ||
917c78fc | 9982 | return retval; |
613e1657 KB |
9983 | } |
9984 | ||
fe1b8b76 JB |
9985 | static gdb_byte * |
9986 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
9987 | { |
9988 | /* If the size of a host char is 8 bits, we can return a pointer | |
9989 | to the buffer, otherwise we have to copy the data to a buffer | |
9990 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9991 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 9992 | return buf; |
c906108c SS |
9993 | } |
9994 | ||
9995 | static char * | |
9b1c24c8 | 9996 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
9997 | { |
9998 | /* If the size of a host char is 8 bits, we can return a pointer | |
9999 | to the string, otherwise we have to copy the string to a buffer | |
10000 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10001 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
10002 | if (*buf == '\0') |
10003 | { | |
10004 | *bytes_read_ptr = 1; | |
10005 | return NULL; | |
10006 | } | |
fe1b8b76 JB |
10007 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
10008 | return (char *) buf; | |
4bdf3d34 JJ |
10009 | } |
10010 | ||
10011 | static char * | |
fe1b8b76 | 10012 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
10013 | const struct comp_unit_head *cu_header, |
10014 | unsigned int *bytes_read_ptr) | |
10015 | { | |
c764a876 | 10016 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 10017 | |
be391dca | 10018 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 10019 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 10020 | { |
8a3fe4f8 | 10021 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 10022 | bfd_get_filename (abfd)); |
4bdf3d34 | 10023 | return NULL; |
c906108c | 10024 | } |
dce234bc | 10025 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 10026 | { |
3e43a32a MS |
10027 | error (_("DW_FORM_strp pointing outside of " |
10028 | ".debug_str section [in module %s]"), | |
10029 | bfd_get_filename (abfd)); | |
c906108c SS |
10030 | return NULL; |
10031 | } | |
4bdf3d34 | 10032 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 10033 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 10034 | return NULL; |
dce234bc | 10035 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
10036 | } |
10037 | ||
ce5d95e1 | 10038 | static unsigned long |
fe1b8b76 | 10039 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10040 | { |
ce5d95e1 JB |
10041 | unsigned long result; |
10042 | unsigned int num_read; | |
c906108c SS |
10043 | int i, shift; |
10044 | unsigned char byte; | |
10045 | ||
10046 | result = 0; | |
10047 | shift = 0; | |
10048 | num_read = 0; | |
10049 | i = 0; | |
10050 | while (1) | |
10051 | { | |
fe1b8b76 | 10052 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10053 | buf++; |
10054 | num_read++; | |
ce5d95e1 | 10055 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
10056 | if ((byte & 128) == 0) |
10057 | { | |
10058 | break; | |
10059 | } | |
10060 | shift += 7; | |
10061 | } | |
10062 | *bytes_read_ptr = num_read; | |
10063 | return result; | |
10064 | } | |
10065 | ||
ce5d95e1 | 10066 | static long |
fe1b8b76 | 10067 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10068 | { |
ce5d95e1 | 10069 | long result; |
77e0b926 | 10070 | int i, shift, num_read; |
c906108c SS |
10071 | unsigned char byte; |
10072 | ||
10073 | result = 0; | |
10074 | shift = 0; | |
c906108c SS |
10075 | num_read = 0; |
10076 | i = 0; | |
10077 | while (1) | |
10078 | { | |
fe1b8b76 | 10079 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10080 | buf++; |
10081 | num_read++; | |
ce5d95e1 | 10082 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
10083 | shift += 7; |
10084 | if ((byte & 128) == 0) | |
10085 | { | |
10086 | break; | |
10087 | } | |
10088 | } | |
77e0b926 DJ |
10089 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
10090 | result |= -(((long)1) << shift); | |
c906108c SS |
10091 | *bytes_read_ptr = num_read; |
10092 | return result; | |
10093 | } | |
10094 | ||
4bb7a0a7 DJ |
10095 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
10096 | ||
fe1b8b76 JB |
10097 | static gdb_byte * |
10098 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
10099 | { |
10100 | int byte; | |
10101 | ||
10102 | while (1) | |
10103 | { | |
fe1b8b76 | 10104 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
10105 | buf++; |
10106 | if ((byte & 128) == 0) | |
10107 | return buf; | |
10108 | } | |
10109 | } | |
10110 | ||
c906108c | 10111 | static void |
e142c38c | 10112 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
10113 | { |
10114 | switch (lang) | |
10115 | { | |
10116 | case DW_LANG_C89: | |
76bee0cc | 10117 | case DW_LANG_C99: |
c906108c | 10118 | case DW_LANG_C: |
e142c38c | 10119 | cu->language = language_c; |
c906108c SS |
10120 | break; |
10121 | case DW_LANG_C_plus_plus: | |
e142c38c | 10122 | cu->language = language_cplus; |
c906108c | 10123 | break; |
6aecb9c2 JB |
10124 | case DW_LANG_D: |
10125 | cu->language = language_d; | |
10126 | break; | |
c906108c SS |
10127 | case DW_LANG_Fortran77: |
10128 | case DW_LANG_Fortran90: | |
b21b22e0 | 10129 | case DW_LANG_Fortran95: |
e142c38c | 10130 | cu->language = language_fortran; |
c906108c SS |
10131 | break; |
10132 | case DW_LANG_Mips_Assembler: | |
e142c38c | 10133 | cu->language = language_asm; |
c906108c | 10134 | break; |
bebd888e | 10135 | case DW_LANG_Java: |
e142c38c | 10136 | cu->language = language_java; |
bebd888e | 10137 | break; |
c906108c | 10138 | case DW_LANG_Ada83: |
8aaf0b47 | 10139 | case DW_LANG_Ada95: |
bc5f45f8 JB |
10140 | cu->language = language_ada; |
10141 | break; | |
72019c9c GM |
10142 | case DW_LANG_Modula2: |
10143 | cu->language = language_m2; | |
10144 | break; | |
fe8e67fd PM |
10145 | case DW_LANG_Pascal83: |
10146 | cu->language = language_pascal; | |
10147 | break; | |
22566fbd DJ |
10148 | case DW_LANG_ObjC: |
10149 | cu->language = language_objc; | |
10150 | break; | |
c906108c SS |
10151 | case DW_LANG_Cobol74: |
10152 | case DW_LANG_Cobol85: | |
c906108c | 10153 | default: |
e142c38c | 10154 | cu->language = language_minimal; |
c906108c SS |
10155 | break; |
10156 | } | |
e142c38c | 10157 | cu->language_defn = language_def (cu->language); |
c906108c SS |
10158 | } |
10159 | ||
10160 | /* Return the named attribute or NULL if not there. */ | |
10161 | ||
10162 | static struct attribute * | |
e142c38c | 10163 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
10164 | { |
10165 | unsigned int i; | |
10166 | struct attribute *spec = NULL; | |
10167 | ||
10168 | for (i = 0; i < die->num_attrs; ++i) | |
10169 | { | |
10170 | if (die->attrs[i].name == name) | |
10b3939b | 10171 | return &die->attrs[i]; |
c906108c SS |
10172 | if (die->attrs[i].name == DW_AT_specification |
10173 | || die->attrs[i].name == DW_AT_abstract_origin) | |
10174 | spec = &die->attrs[i]; | |
10175 | } | |
c906108c | 10176 | |
10b3939b | 10177 | if (spec) |
f2f0e013 DJ |
10178 | { |
10179 | die = follow_die_ref (die, spec, &cu); | |
10180 | return dwarf2_attr (die, name, cu); | |
10181 | } | |
c5aa993b | 10182 | |
c906108c SS |
10183 | return NULL; |
10184 | } | |
10185 | ||
348e048f DE |
10186 | /* Return the named attribute or NULL if not there, |
10187 | but do not follow DW_AT_specification, etc. | |
10188 | This is for use in contexts where we're reading .debug_types dies. | |
10189 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
10190 | back up the chain, and we want to go down. */ | |
10191 | ||
10192 | static struct attribute * | |
10193 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
10194 | struct dwarf2_cu *cu) | |
10195 | { | |
10196 | unsigned int i; | |
10197 | ||
10198 | for (i = 0; i < die->num_attrs; ++i) | |
10199 | if (die->attrs[i].name == name) | |
10200 | return &die->attrs[i]; | |
10201 | ||
10202 | return NULL; | |
10203 | } | |
10204 | ||
05cf31d1 JB |
10205 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
10206 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 10207 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
10208 | |
10209 | static int | |
10210 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
10211 | { | |
10212 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
10213 | ||
10214 | return (attr && DW_UNSND (attr)); | |
10215 | } | |
10216 | ||
3ca72b44 | 10217 | static int |
e142c38c | 10218 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 10219 | { |
05cf31d1 JB |
10220 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
10221 | which value is non-zero. However, we have to be careful with | |
10222 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
10223 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
10224 | end up accidently finding a declaration attribute that belongs | |
10225 | to a different DIE referenced by the specification attribute, | |
10226 | even though the given DIE does not have a declaration attribute. */ | |
10227 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
10228 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
10229 | } |
10230 | ||
63d06c5c | 10231 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 10232 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
10233 | containing the return value on output. If there is no |
10234 | specification, but there is an abstract origin, that is | |
10235 | returned. */ | |
63d06c5c DC |
10236 | |
10237 | static struct die_info * | |
f2f0e013 | 10238 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 10239 | { |
f2f0e013 DJ |
10240 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
10241 | *spec_cu); | |
63d06c5c | 10242 | |
edb3359d DJ |
10243 | if (spec_attr == NULL) |
10244 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
10245 | ||
63d06c5c DC |
10246 | if (spec_attr == NULL) |
10247 | return NULL; | |
10248 | else | |
f2f0e013 | 10249 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 10250 | } |
c906108c | 10251 | |
debd256d | 10252 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
10253 | refers to. |
10254 | NOTE: This is also used as a "cleanup" function. */ | |
10255 | ||
debd256d JB |
10256 | static void |
10257 | free_line_header (struct line_header *lh) | |
10258 | { | |
10259 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 10260 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
10261 | |
10262 | /* Remember that all the lh->file_names[i].name pointers are | |
10263 | pointers into debug_line_buffer, and don't need to be freed. */ | |
10264 | if (lh->file_names) | |
a8bc7b56 | 10265 | xfree (lh->file_names); |
debd256d JB |
10266 | |
10267 | /* Similarly for the include directory names. */ | |
10268 | if (lh->include_dirs) | |
a8bc7b56 | 10269 | xfree (lh->include_dirs); |
debd256d | 10270 | |
a8bc7b56 | 10271 | xfree (lh); |
debd256d JB |
10272 | } |
10273 | ||
debd256d | 10274 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 10275 | |
debd256d JB |
10276 | static void |
10277 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 10278 | { |
debd256d JB |
10279 | /* Grow the array if necessary. */ |
10280 | if (lh->include_dirs_size == 0) | |
c5aa993b | 10281 | { |
debd256d JB |
10282 | lh->include_dirs_size = 1; /* for testing */ |
10283 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
10284 | * sizeof (*lh->include_dirs)); | |
10285 | } | |
10286 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
10287 | { | |
10288 | lh->include_dirs_size *= 2; | |
10289 | lh->include_dirs = xrealloc (lh->include_dirs, | |
10290 | (lh->include_dirs_size | |
10291 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 10292 | } |
c906108c | 10293 | |
debd256d JB |
10294 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
10295 | } | |
6e70227d | 10296 | |
debd256d | 10297 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 10298 | |
debd256d JB |
10299 | static void |
10300 | add_file_name (struct line_header *lh, | |
10301 | char *name, | |
10302 | unsigned int dir_index, | |
10303 | unsigned int mod_time, | |
10304 | unsigned int length) | |
10305 | { | |
10306 | struct file_entry *fe; | |
10307 | ||
10308 | /* Grow the array if necessary. */ | |
10309 | if (lh->file_names_size == 0) | |
10310 | { | |
10311 | lh->file_names_size = 1; /* for testing */ | |
10312 | lh->file_names = xmalloc (lh->file_names_size | |
10313 | * sizeof (*lh->file_names)); | |
10314 | } | |
10315 | else if (lh->num_file_names >= lh->file_names_size) | |
10316 | { | |
10317 | lh->file_names_size *= 2; | |
10318 | lh->file_names = xrealloc (lh->file_names, | |
10319 | (lh->file_names_size | |
10320 | * sizeof (*lh->file_names))); | |
10321 | } | |
10322 | ||
10323 | fe = &lh->file_names[lh->num_file_names++]; | |
10324 | fe->name = name; | |
10325 | fe->dir_index = dir_index; | |
10326 | fe->mod_time = mod_time; | |
10327 | fe->length = length; | |
aaa75496 | 10328 | fe->included_p = 0; |
cb1df416 | 10329 | fe->symtab = NULL; |
debd256d | 10330 | } |
6e70227d | 10331 | |
debd256d | 10332 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
10333 | .debug_line, according to the endianness of ABFD. Return a pointer |
10334 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
10335 | |
10336 | NOTE: the strings in the include directory and file name tables of | |
10337 | the returned object point into debug_line_buffer, and must not be | |
10338 | freed. */ | |
ae2de4f8 | 10339 | |
debd256d JB |
10340 | static struct line_header * |
10341 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 10342 | struct dwarf2_cu *cu) |
debd256d JB |
10343 | { |
10344 | struct cleanup *back_to; | |
10345 | struct line_header *lh; | |
fe1b8b76 | 10346 | gdb_byte *line_ptr; |
c764a876 | 10347 | unsigned int bytes_read, offset_size; |
debd256d JB |
10348 | int i; |
10349 | char *cur_dir, *cur_file; | |
10350 | ||
be391dca | 10351 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 10352 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 10353 | { |
e2e0b3e5 | 10354 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
10355 | return 0; |
10356 | } | |
10357 | ||
a738430d MK |
10358 | /* Make sure that at least there's room for the total_length field. |
10359 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 10360 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 10361 | { |
4d3c2250 | 10362 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10363 | return 0; |
10364 | } | |
10365 | ||
10366 | lh = xmalloc (sizeof (*lh)); | |
10367 | memset (lh, 0, sizeof (*lh)); | |
10368 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
10369 | (void *) lh); | |
10370 | ||
dce234bc | 10371 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 10372 | |
a738430d | 10373 | /* Read in the header. */ |
6e70227d | 10374 | lh->total_length = |
c764a876 DE |
10375 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
10376 | &bytes_read, &offset_size); | |
debd256d | 10377 | line_ptr += bytes_read; |
dce234bc PP |
10378 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
10379 | + dwarf2_per_objfile->line.size)) | |
debd256d | 10380 | { |
4d3c2250 | 10381 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10382 | return 0; |
10383 | } | |
10384 | lh->statement_program_end = line_ptr + lh->total_length; | |
10385 | lh->version = read_2_bytes (abfd, line_ptr); | |
10386 | line_ptr += 2; | |
c764a876 DE |
10387 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
10388 | line_ptr += offset_size; | |
debd256d JB |
10389 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
10390 | line_ptr += 1; | |
2dc7f7b3 TT |
10391 | if (lh->version >= 4) |
10392 | { | |
10393 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
10394 | line_ptr += 1; | |
10395 | } | |
10396 | else | |
10397 | lh->maximum_ops_per_instruction = 1; | |
10398 | ||
10399 | if (lh->maximum_ops_per_instruction == 0) | |
10400 | { | |
10401 | lh->maximum_ops_per_instruction = 1; | |
10402 | complaint (&symfile_complaints, | |
3e43a32a MS |
10403 | _("invalid maximum_ops_per_instruction " |
10404 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
10405 | } |
10406 | ||
debd256d JB |
10407 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
10408 | line_ptr += 1; | |
10409 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
10410 | line_ptr += 1; | |
10411 | lh->line_range = read_1_byte (abfd, line_ptr); | |
10412 | line_ptr += 1; | |
10413 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
10414 | line_ptr += 1; | |
10415 | lh->standard_opcode_lengths | |
fe1b8b76 | 10416 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
10417 | |
10418 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
10419 | for (i = 1; i < lh->opcode_base; ++i) | |
10420 | { | |
10421 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
10422 | line_ptr += 1; | |
10423 | } | |
10424 | ||
a738430d | 10425 | /* Read directory table. */ |
9b1c24c8 | 10426 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10427 | { |
10428 | line_ptr += bytes_read; | |
10429 | add_include_dir (lh, cur_dir); | |
10430 | } | |
10431 | line_ptr += bytes_read; | |
10432 | ||
a738430d | 10433 | /* Read file name table. */ |
9b1c24c8 | 10434 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10435 | { |
10436 | unsigned int dir_index, mod_time, length; | |
10437 | ||
10438 | line_ptr += bytes_read; | |
10439 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10440 | line_ptr += bytes_read; | |
10441 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10442 | line_ptr += bytes_read; | |
10443 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10444 | line_ptr += bytes_read; | |
10445 | ||
10446 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10447 | } | |
10448 | line_ptr += bytes_read; | |
6e70227d | 10449 | lh->statement_program_start = line_ptr; |
debd256d | 10450 | |
dce234bc PP |
10451 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
10452 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 10453 | complaint (&symfile_complaints, |
3e43a32a MS |
10454 | _("line number info header doesn't " |
10455 | "fit in `.debug_line' section")); | |
debd256d JB |
10456 | |
10457 | discard_cleanups (back_to); | |
10458 | return lh; | |
10459 | } | |
c906108c | 10460 | |
5fb290d7 DJ |
10461 | /* This function exists to work around a bug in certain compilers |
10462 | (particularly GCC 2.95), in which the first line number marker of a | |
10463 | function does not show up until after the prologue, right before | |
10464 | the second line number marker. This function shifts ADDRESS down | |
10465 | to the beginning of the function if necessary, and is called on | |
10466 | addresses passed to record_line. */ | |
10467 | ||
10468 | static CORE_ADDR | |
e142c38c | 10469 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
10470 | { |
10471 | struct function_range *fn; | |
10472 | ||
10473 | /* Find the function_range containing address. */ | |
e142c38c | 10474 | if (!cu->first_fn) |
5fb290d7 DJ |
10475 | return address; |
10476 | ||
e142c38c DJ |
10477 | if (!cu->cached_fn) |
10478 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 10479 | |
e142c38c | 10480 | fn = cu->cached_fn; |
5fb290d7 DJ |
10481 | while (fn) |
10482 | if (fn->lowpc <= address && fn->highpc > address) | |
10483 | goto found; | |
10484 | else | |
10485 | fn = fn->next; | |
10486 | ||
e142c38c DJ |
10487 | fn = cu->first_fn; |
10488 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
10489 | if (fn->lowpc <= address && fn->highpc > address) |
10490 | goto found; | |
10491 | else | |
10492 | fn = fn->next; | |
10493 | ||
10494 | return address; | |
10495 | ||
10496 | found: | |
10497 | if (fn->seen_line) | |
10498 | return address; | |
10499 | if (address != fn->lowpc) | |
4d3c2250 | 10500 | complaint (&symfile_complaints, |
e2e0b3e5 | 10501 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 10502 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
10503 | fn->seen_line = 1; |
10504 | return fn->lowpc; | |
10505 | } | |
10506 | ||
c6da4cef DE |
10507 | /* Subroutine of dwarf_decode_lines to simplify it. |
10508 | Return the file name of the psymtab for included file FILE_INDEX | |
10509 | in line header LH of PST. | |
10510 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10511 | If space for the result is malloc'd, it will be freed by a cleanup. | |
10512 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
10513 | ||
10514 | static char * | |
10515 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
10516 | const struct partial_symtab *pst, | |
10517 | const char *comp_dir) | |
10518 | { | |
10519 | const struct file_entry fe = lh->file_names [file_index]; | |
10520 | char *include_name = fe.name; | |
10521 | char *include_name_to_compare = include_name; | |
10522 | char *dir_name = NULL; | |
72b9f47f TT |
10523 | const char *pst_filename; |
10524 | char *copied_name = NULL; | |
c6da4cef DE |
10525 | int file_is_pst; |
10526 | ||
10527 | if (fe.dir_index) | |
10528 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
10529 | ||
10530 | if (!IS_ABSOLUTE_PATH (include_name) | |
10531 | && (dir_name != NULL || comp_dir != NULL)) | |
10532 | { | |
10533 | /* Avoid creating a duplicate psymtab for PST. | |
10534 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
10535 | Before we do the comparison, however, we need to account | |
10536 | for DIR_NAME and COMP_DIR. | |
10537 | First prepend dir_name (if non-NULL). If we still don't | |
10538 | have an absolute path prepend comp_dir (if non-NULL). | |
10539 | However, the directory we record in the include-file's | |
10540 | psymtab does not contain COMP_DIR (to match the | |
10541 | corresponding symtab(s)). | |
10542 | ||
10543 | Example: | |
10544 | ||
10545 | bash$ cd /tmp | |
10546 | bash$ gcc -g ./hello.c | |
10547 | include_name = "hello.c" | |
10548 | dir_name = "." | |
10549 | DW_AT_comp_dir = comp_dir = "/tmp" | |
10550 | DW_AT_name = "./hello.c" */ | |
10551 | ||
10552 | if (dir_name != NULL) | |
10553 | { | |
10554 | include_name = concat (dir_name, SLASH_STRING, | |
10555 | include_name, (char *)NULL); | |
10556 | include_name_to_compare = include_name; | |
10557 | make_cleanup (xfree, include_name); | |
10558 | } | |
10559 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
10560 | { | |
10561 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
10562 | include_name, (char *)NULL); | |
10563 | } | |
10564 | } | |
10565 | ||
10566 | pst_filename = pst->filename; | |
10567 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
10568 | { | |
72b9f47f TT |
10569 | copied_name = concat (pst->dirname, SLASH_STRING, |
10570 | pst_filename, (char *)NULL); | |
10571 | pst_filename = copied_name; | |
c6da4cef DE |
10572 | } |
10573 | ||
1e3fad37 | 10574 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
10575 | |
10576 | if (include_name_to_compare != include_name) | |
10577 | xfree (include_name_to_compare); | |
72b9f47f TT |
10578 | if (copied_name != NULL) |
10579 | xfree (copied_name); | |
c6da4cef DE |
10580 | |
10581 | if (file_is_pst) | |
10582 | return NULL; | |
10583 | return include_name; | |
10584 | } | |
10585 | ||
c91513d8 PP |
10586 | /* Ignore this record_line request. */ |
10587 | ||
10588 | static void | |
10589 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
10590 | { | |
10591 | return; | |
10592 | } | |
10593 | ||
aaa75496 JB |
10594 | /* Decode the Line Number Program (LNP) for the given line_header |
10595 | structure and CU. The actual information extracted and the type | |
10596 | of structures created from the LNP depends on the value of PST. | |
10597 | ||
10598 | 1. If PST is NULL, then this procedure uses the data from the program | |
10599 | to create all necessary symbol tables, and their linetables. | |
6e70227d | 10600 | |
aaa75496 JB |
10601 | 2. If PST is not NULL, this procedure reads the program to determine |
10602 | the list of files included by the unit represented by PST, and | |
c6da4cef DE |
10603 | builds all the associated partial symbol tables. |
10604 | ||
10605 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10606 | It is used for relative paths in the line table. | |
10607 | NOTE: When processing partial symtabs (pst != NULL), | |
10608 | comp_dir == pst->dirname. | |
10609 | ||
10610 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
10611 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
10612 | symtab we don't use it in the name of the psymtabs we create. | |
10613 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
10614 | A good testcase for this is mb-inline.exp. */ | |
debd256d | 10615 | |
c906108c | 10616 | static void |
72b9f47f | 10617 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd, |
aaa75496 | 10618 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 10619 | { |
a8c50c1f | 10620 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 10621 | gdb_byte *line_end; |
a8c50c1f | 10622 | unsigned int bytes_read, extended_len; |
c906108c | 10623 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
10624 | CORE_ADDR baseaddr; |
10625 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 10626 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 10627 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 10628 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
c91513d8 PP |
10629 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
10630 | = record_line; | |
e142c38c DJ |
10631 | |
10632 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10633 | |
debd256d JB |
10634 | line_ptr = lh->statement_program_start; |
10635 | line_end = lh->statement_program_end; | |
c906108c SS |
10636 | |
10637 | /* Read the statement sequences until there's nothing left. */ | |
10638 | while (line_ptr < line_end) | |
10639 | { | |
10640 | /* state machine registers */ | |
10641 | CORE_ADDR address = 0; | |
10642 | unsigned int file = 1; | |
10643 | unsigned int line = 1; | |
10644 | unsigned int column = 0; | |
debd256d | 10645 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
10646 | int basic_block = 0; |
10647 | int end_sequence = 0; | |
fbf65064 | 10648 | CORE_ADDR addr; |
2dc7f7b3 | 10649 | unsigned char op_index = 0; |
c906108c | 10650 | |
aaa75496 | 10651 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 10652 | { |
aaa75496 | 10653 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
10654 | /* lh->include_dirs and lh->file_names are 0-based, but the |
10655 | directory and file name numbers in the statement program | |
10656 | are 1-based. */ | |
10657 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 10658 | char *dir = NULL; |
a738430d | 10659 | |
debd256d JB |
10660 | if (fe->dir_index) |
10661 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
10662 | |
10663 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
10664 | } |
10665 | ||
a738430d | 10666 | /* Decode the table. */ |
c5aa993b | 10667 | while (!end_sequence) |
c906108c SS |
10668 | { |
10669 | op_code = read_1_byte (abfd, line_ptr); | |
10670 | line_ptr += 1; | |
59205f5a JB |
10671 | if (line_ptr > line_end) |
10672 | { | |
10673 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
10674 | break; | |
10675 | } | |
9aa1fe7e | 10676 | |
debd256d | 10677 | if (op_code >= lh->opcode_base) |
6e70227d | 10678 | { |
a738430d | 10679 | /* Special operand. */ |
debd256d | 10680 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
10681 | address += (((op_index + (adj_opcode / lh->line_range)) |
10682 | / lh->maximum_ops_per_instruction) | |
10683 | * lh->minimum_instruction_length); | |
10684 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
10685 | % lh->maximum_ops_per_instruction); | |
debd256d | 10686 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 10687 | if (lh->num_file_names < file || file == 0) |
25e43795 | 10688 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
10689 | /* For now we ignore lines not starting on an |
10690 | instruction boundary. */ | |
10691 | else if (op_index == 0) | |
25e43795 DJ |
10692 | { |
10693 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 10694 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10695 | { |
10696 | if (last_subfile != current_subfile) | |
10697 | { | |
10698 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10699 | if (last_subfile) | |
c91513d8 | 10700 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
10701 | last_subfile = current_subfile; |
10702 | } | |
25e43795 | 10703 | /* Append row to matrix using current values. */ |
fbf65064 UW |
10704 | addr = check_cu_functions (address, cu); |
10705 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
c91513d8 | 10706 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 10707 | } |
25e43795 | 10708 | } |
ca5f395d | 10709 | basic_block = 0; |
9aa1fe7e GK |
10710 | } |
10711 | else switch (op_code) | |
c906108c SS |
10712 | { |
10713 | case DW_LNS_extended_op: | |
3e43a32a MS |
10714 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
10715 | &bytes_read); | |
473b7be6 | 10716 | line_ptr += bytes_read; |
a8c50c1f | 10717 | extended_end = line_ptr + extended_len; |
c906108c SS |
10718 | extended_op = read_1_byte (abfd, line_ptr); |
10719 | line_ptr += 1; | |
10720 | switch (extended_op) | |
10721 | { | |
10722 | case DW_LNE_end_sequence: | |
c91513d8 | 10723 | p_record_line = record_line; |
c906108c | 10724 | end_sequence = 1; |
c906108c SS |
10725 | break; |
10726 | case DW_LNE_set_address: | |
e7c27a73 | 10727 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
10728 | |
10729 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
10730 | { | |
10731 | /* This line table is for a function which has been | |
10732 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
10733 | ||
10734 | long line_offset | |
10735 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
10736 | ||
10737 | complaint (&symfile_complaints, | |
10738 | _(".debug_line address at offset 0x%lx is 0 " | |
10739 | "[in module %s]"), | |
10740 | line_offset, cu->objfile->name); | |
10741 | p_record_line = noop_record_line; | |
10742 | } | |
10743 | ||
2dc7f7b3 | 10744 | op_index = 0; |
107d2387 AC |
10745 | line_ptr += bytes_read; |
10746 | address += baseaddr; | |
c906108c SS |
10747 | break; |
10748 | case DW_LNE_define_file: | |
debd256d JB |
10749 | { |
10750 | char *cur_file; | |
10751 | unsigned int dir_index, mod_time, length; | |
6e70227d | 10752 | |
3e43a32a MS |
10753 | cur_file = read_direct_string (abfd, line_ptr, |
10754 | &bytes_read); | |
debd256d JB |
10755 | line_ptr += bytes_read; |
10756 | dir_index = | |
10757 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10758 | line_ptr += bytes_read; | |
10759 | mod_time = | |
10760 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10761 | line_ptr += bytes_read; | |
10762 | length = | |
10763 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10764 | line_ptr += bytes_read; | |
10765 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10766 | } | |
c906108c | 10767 | break; |
d0c6ba3d CC |
10768 | case DW_LNE_set_discriminator: |
10769 | /* The discriminator is not interesting to the debugger; | |
10770 | just ignore it. */ | |
10771 | line_ptr = extended_end; | |
10772 | break; | |
c906108c | 10773 | default: |
4d3c2250 | 10774 | complaint (&symfile_complaints, |
e2e0b3e5 | 10775 | _("mangled .debug_line section")); |
debd256d | 10776 | return; |
c906108c | 10777 | } |
a8c50c1f DJ |
10778 | /* Make sure that we parsed the extended op correctly. If e.g. |
10779 | we expected a different address size than the producer used, | |
10780 | we may have read the wrong number of bytes. */ | |
10781 | if (line_ptr != extended_end) | |
10782 | { | |
10783 | complaint (&symfile_complaints, | |
10784 | _("mangled .debug_line section")); | |
10785 | return; | |
10786 | } | |
c906108c SS |
10787 | break; |
10788 | case DW_LNS_copy: | |
59205f5a | 10789 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10790 | dwarf2_debug_line_missing_file_complaint (); |
10791 | else | |
366da635 | 10792 | { |
25e43795 | 10793 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 10794 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10795 | { |
10796 | if (last_subfile != current_subfile) | |
10797 | { | |
10798 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10799 | if (last_subfile) | |
c91513d8 | 10800 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
10801 | last_subfile = current_subfile; |
10802 | } | |
10803 | addr = check_cu_functions (address, cu); | |
10804 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
c91513d8 | 10805 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 10806 | } |
366da635 | 10807 | } |
c906108c SS |
10808 | basic_block = 0; |
10809 | break; | |
10810 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
10811 | { |
10812 | CORE_ADDR adjust | |
10813 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10814 | ||
10815 | address += (((op_index + adjust) | |
10816 | / lh->maximum_ops_per_instruction) | |
10817 | * lh->minimum_instruction_length); | |
10818 | op_index = ((op_index + adjust) | |
10819 | % lh->maximum_ops_per_instruction); | |
10820 | line_ptr += bytes_read; | |
10821 | } | |
c906108c SS |
10822 | break; |
10823 | case DW_LNS_advance_line: | |
10824 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
10825 | line_ptr += bytes_read; | |
10826 | break; | |
10827 | case DW_LNS_set_file: | |
debd256d | 10828 | { |
a738430d MK |
10829 | /* The arrays lh->include_dirs and lh->file_names are |
10830 | 0-based, but the directory and file name numbers in | |
10831 | the statement program are 1-based. */ | |
debd256d | 10832 | struct file_entry *fe; |
4f1520fb | 10833 | char *dir = NULL; |
a738430d | 10834 | |
debd256d JB |
10835 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
10836 | line_ptr += bytes_read; | |
59205f5a | 10837 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10838 | dwarf2_debug_line_missing_file_complaint (); |
10839 | else | |
10840 | { | |
10841 | fe = &lh->file_names[file - 1]; | |
10842 | if (fe->dir_index) | |
10843 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10844 | if (!decode_for_pst_p) | |
10845 | { | |
10846 | last_subfile = current_subfile; | |
10847 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10848 | } | |
10849 | } | |
debd256d | 10850 | } |
c906108c SS |
10851 | break; |
10852 | case DW_LNS_set_column: | |
10853 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10854 | line_ptr += bytes_read; | |
10855 | break; | |
10856 | case DW_LNS_negate_stmt: | |
10857 | is_stmt = (!is_stmt); | |
10858 | break; | |
10859 | case DW_LNS_set_basic_block: | |
10860 | basic_block = 1; | |
10861 | break; | |
c2c6d25f JM |
10862 | /* Add to the address register of the state machine the |
10863 | address increment value corresponding to special opcode | |
a738430d MK |
10864 | 255. I.e., this value is scaled by the minimum |
10865 | instruction length since special opcode 255 would have | |
b021a221 | 10866 | scaled the increment. */ |
c906108c | 10867 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
10868 | { |
10869 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
10870 | ||
10871 | address += (((op_index + adjust) | |
10872 | / lh->maximum_ops_per_instruction) | |
10873 | * lh->minimum_instruction_length); | |
10874 | op_index = ((op_index + adjust) | |
10875 | % lh->maximum_ops_per_instruction); | |
10876 | } | |
c906108c SS |
10877 | break; |
10878 | case DW_LNS_fixed_advance_pc: | |
10879 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 10880 | op_index = 0; |
c906108c SS |
10881 | line_ptr += 2; |
10882 | break; | |
9aa1fe7e | 10883 | default: |
a738430d MK |
10884 | { |
10885 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 10886 | int i; |
a738430d | 10887 | |
debd256d | 10888 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
10889 | { |
10890 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10891 | line_ptr += bytes_read; | |
10892 | } | |
10893 | } | |
c906108c SS |
10894 | } |
10895 | } | |
59205f5a JB |
10896 | if (lh->num_file_names < file || file == 0) |
10897 | dwarf2_debug_line_missing_file_complaint (); | |
10898 | else | |
10899 | { | |
10900 | lh->file_names[file - 1].included_p = 1; | |
10901 | if (!decode_for_pst_p) | |
fbf65064 UW |
10902 | { |
10903 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 10904 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 10905 | } |
59205f5a | 10906 | } |
c906108c | 10907 | } |
aaa75496 JB |
10908 | |
10909 | if (decode_for_pst_p) | |
10910 | { | |
10911 | int file_index; | |
10912 | ||
10913 | /* Now that we're done scanning the Line Header Program, we can | |
10914 | create the psymtab of each included file. */ | |
10915 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
10916 | if (lh->file_names[file_index].included_p == 1) | |
10917 | { | |
c6da4cef DE |
10918 | char *include_name = |
10919 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
10920 | if (include_name != NULL) | |
aaa75496 JB |
10921 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
10922 | } | |
10923 | } | |
cb1df416 DJ |
10924 | else |
10925 | { | |
10926 | /* Make sure a symtab is created for every file, even files | |
10927 | which contain only variables (i.e. no code with associated | |
10928 | line numbers). */ | |
10929 | ||
10930 | int i; | |
10931 | struct file_entry *fe; | |
10932 | ||
10933 | for (i = 0; i < lh->num_file_names; i++) | |
10934 | { | |
10935 | char *dir = NULL; | |
9a619af0 | 10936 | |
cb1df416 DJ |
10937 | fe = &lh->file_names[i]; |
10938 | if (fe->dir_index) | |
10939 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10940 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10941 | ||
10942 | /* Skip the main file; we don't need it, and it must be | |
10943 | allocated last, so that it will show up before the | |
10944 | non-primary symtabs in the objfile's symtab list. */ | |
10945 | if (current_subfile == first_subfile) | |
10946 | continue; | |
10947 | ||
10948 | if (current_subfile->symtab == NULL) | |
10949 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
10950 | cu->objfile); | |
10951 | fe->symtab = current_subfile->symtab; | |
10952 | } | |
10953 | } | |
c906108c SS |
10954 | } |
10955 | ||
10956 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
10957 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
10958 | or NULL if not known. COMP_DIR is the compilation directory for the |
10959 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
10960 | This routine tries to keep line numbers from identical absolute and |
10961 | relative file names in a common subfile. | |
10962 | ||
10963 | Using the `list' example from the GDB testsuite, which resides in | |
10964 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
10965 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
10966 | ||
c5aa993b JM |
10967 | DW_AT_name: /srcdir/list0.c |
10968 | DW_AT_comp_dir: /compdir | |
357e46e7 | 10969 | files.files[0].name: list0.h |
c5aa993b | 10970 | files.files[0].dir: /srcdir |
357e46e7 | 10971 | files.files[1].name: list0.c |
c5aa993b | 10972 | files.files[1].dir: /srcdir |
c906108c SS |
10973 | |
10974 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
10975 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
10976 | start_subfile will ensure that this happens provided that we pass the | |
10977 | concatenation of files.files[1].dir and files.files[1].name as the | |
10978 | subfile's name. */ | |
c906108c SS |
10979 | |
10980 | static void | |
3e43a32a MS |
10981 | dwarf2_start_subfile (char *filename, const char *dirname, |
10982 | const char *comp_dir) | |
c906108c | 10983 | { |
4f1520fb FR |
10984 | char *fullname; |
10985 | ||
10986 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
10987 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
10988 | second argument to start_subfile. To be consistent, we do the | |
10989 | same here. In order not to lose the line information directory, | |
10990 | we concatenate it to the filename when it makes sense. | |
10991 | Note that the Dwarf3 standard says (speaking of filenames in line | |
10992 | information): ``The directory index is ignored for file names | |
10993 | that represent full path names''. Thus ignoring dirname in the | |
10994 | `else' branch below isn't an issue. */ | |
c906108c | 10995 | |
d5166ae1 | 10996 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
10997 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
10998 | else | |
10999 | fullname = filename; | |
c906108c | 11000 | |
4f1520fb FR |
11001 | start_subfile (fullname, comp_dir); |
11002 | ||
11003 | if (fullname != filename) | |
11004 | xfree (fullname); | |
c906108c SS |
11005 | } |
11006 | ||
4c2df51b DJ |
11007 | static void |
11008 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11009 | struct dwarf2_cu *cu) |
4c2df51b | 11010 | { |
e7c27a73 DJ |
11011 | struct objfile *objfile = cu->objfile; |
11012 | struct comp_unit_head *cu_header = &cu->header; | |
11013 | ||
4c2df51b DJ |
11014 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
11015 | code here to turn a symbol with DW_AT_external and a | |
11016 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
11017 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
11018 | with some versions of binutils) where shared libraries could have | |
11019 | relocations against symbols in their debug information - the | |
11020 | minimal symbol would have the right address, but the debug info | |
11021 | would not. It's no longer necessary, because we will explicitly | |
11022 | apply relocations when we read in the debug information now. */ | |
11023 | ||
11024 | /* A DW_AT_location attribute with no contents indicates that a | |
11025 | variable has been optimized away. */ | |
11026 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
11027 | { | |
11028 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
11029 | return; | |
11030 | } | |
11031 | ||
11032 | /* Handle one degenerate form of location expression specially, to | |
11033 | preserve GDB's previous behavior when section offsets are | |
11034 | specified. If this is just a DW_OP_addr then mark this symbol | |
11035 | as LOC_STATIC. */ | |
11036 | ||
11037 | if (attr_form_is_block (attr) | |
11038 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
11039 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
11040 | { | |
891d2f0b | 11041 | unsigned int dummy; |
4c2df51b DJ |
11042 | |
11043 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 11044 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 11045 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
11046 | fixup_symbol_section (sym, objfile); |
11047 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
11048 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
11049 | return; |
11050 | } | |
11051 | ||
11052 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
11053 | expression evaluator, and use LOC_COMPUTED only when necessary | |
11054 | (i.e. when the value of a register or memory location is | |
11055 | referenced, or a thread-local block, etc.). Then again, it might | |
11056 | not be worthwhile. I'm assuming that it isn't unless performance | |
11057 | or memory numbers show me otherwise. */ | |
11058 | ||
e7c27a73 | 11059 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 11060 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
11061 | |
11062 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
11063 | cu->has_loclist = 1; | |
4c2df51b DJ |
11064 | } |
11065 | ||
c906108c SS |
11066 | /* Given a pointer to a DWARF information entry, figure out if we need |
11067 | to make a symbol table entry for it, and if so, create a new entry | |
11068 | and return a pointer to it. | |
11069 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
11070 | used the passed type. |
11071 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
11072 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
11073 | |
11074 | static struct symbol * | |
34eaf542 TT |
11075 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
11076 | struct symbol *space) | |
c906108c | 11077 | { |
e7c27a73 | 11078 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11079 | struct symbol *sym = NULL; |
11080 | char *name; | |
11081 | struct attribute *attr = NULL; | |
11082 | struct attribute *attr2 = NULL; | |
e142c38c | 11083 | CORE_ADDR baseaddr; |
e37fd15a SW |
11084 | struct pending **list_to_add = NULL; |
11085 | ||
edb3359d | 11086 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
11087 | |
11088 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11089 | |
94af9270 | 11090 | name = dwarf2_name (die, cu); |
c906108c SS |
11091 | if (name) |
11092 | { | |
94af9270 | 11093 | const char *linkagename; |
34eaf542 | 11094 | int suppress_add = 0; |
94af9270 | 11095 | |
34eaf542 TT |
11096 | if (space) |
11097 | sym = space; | |
11098 | else | |
11099 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 11100 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
11101 | |
11102 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 11103 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
11104 | linkagename = dwarf2_physname (name, die, cu); |
11105 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 11106 | |
f55ee35c JK |
11107 | /* Fortran does not have mangling standard and the mangling does differ |
11108 | between gfortran, iFort etc. */ | |
11109 | if (cu->language == language_fortran | |
b250c185 | 11110 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
11111 | symbol_set_demangled_name (&(sym->ginfo), |
11112 | (char *) dwarf2_full_name (name, die, cu), | |
11113 | NULL); | |
f55ee35c | 11114 | |
c906108c | 11115 | /* Default assumptions. |
c5aa993b | 11116 | Use the passed type or decode it from the die. */ |
176620f1 | 11117 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 11118 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
11119 | if (type != NULL) |
11120 | SYMBOL_TYPE (sym) = type; | |
11121 | else | |
e7c27a73 | 11122 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
11123 | attr = dwarf2_attr (die, |
11124 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
11125 | cu); | |
c906108c SS |
11126 | if (attr) |
11127 | { | |
11128 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
11129 | } | |
cb1df416 | 11130 | |
edb3359d DJ |
11131 | attr = dwarf2_attr (die, |
11132 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
11133 | cu); | |
cb1df416 DJ |
11134 | if (attr) |
11135 | { | |
11136 | int file_index = DW_UNSND (attr); | |
9a619af0 | 11137 | |
cb1df416 DJ |
11138 | if (cu->line_header == NULL |
11139 | || file_index > cu->line_header->num_file_names) | |
11140 | complaint (&symfile_complaints, | |
11141 | _("file index out of range")); | |
1c3d648d | 11142 | else if (file_index > 0) |
cb1df416 DJ |
11143 | { |
11144 | struct file_entry *fe; | |
9a619af0 | 11145 | |
cb1df416 DJ |
11146 | fe = &cu->line_header->file_names[file_index - 1]; |
11147 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
11148 | } | |
11149 | } | |
11150 | ||
c906108c SS |
11151 | switch (die->tag) |
11152 | { | |
11153 | case DW_TAG_label: | |
e142c38c | 11154 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
11155 | if (attr) |
11156 | { | |
11157 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
11158 | } | |
0f5238ed TT |
11159 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
11160 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 11161 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 11162 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
11163 | break; |
11164 | case DW_TAG_subprogram: | |
11165 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11166 | finish_block. */ | |
11167 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 11168 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
11169 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
11170 | || cu->language == language_ada) | |
c906108c | 11171 | { |
2cfa0c8d JB |
11172 | /* Subprograms marked external are stored as a global symbol. |
11173 | Ada subprograms, whether marked external or not, are always | |
11174 | stored as a global symbol, because we want to be able to | |
11175 | access them globally. For instance, we want to be able | |
11176 | to break on a nested subprogram without having to | |
11177 | specify the context. */ | |
e37fd15a | 11178 | list_to_add = &global_symbols; |
c906108c SS |
11179 | } |
11180 | else | |
11181 | { | |
e37fd15a | 11182 | list_to_add = cu->list_in_scope; |
c906108c SS |
11183 | } |
11184 | break; | |
edb3359d DJ |
11185 | case DW_TAG_inlined_subroutine: |
11186 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11187 | finish_block. */ | |
11188 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11189 | SYMBOL_INLINED (sym) = 1; | |
11190 | /* Do not add the symbol to any lists. It will be found via | |
11191 | BLOCK_FUNCTION from the blockvector. */ | |
11192 | break; | |
34eaf542 TT |
11193 | case DW_TAG_template_value_param: |
11194 | suppress_add = 1; | |
11195 | /* Fall through. */ | |
72929c62 | 11196 | case DW_TAG_constant: |
c906108c | 11197 | case DW_TAG_variable: |
254e6b9e | 11198 | case DW_TAG_member: |
0963b4bd MS |
11199 | /* Compilation with minimal debug info may result in |
11200 | variables with missing type entries. Change the | |
11201 | misleading `void' type to something sensible. */ | |
c906108c | 11202 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 11203 | SYMBOL_TYPE (sym) |
46bf5051 | 11204 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 11205 | |
e142c38c | 11206 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
11207 | /* In the case of DW_TAG_member, we should only be called for |
11208 | static const members. */ | |
11209 | if (die->tag == DW_TAG_member) | |
11210 | { | |
3863f96c DE |
11211 | /* dwarf2_add_field uses die_is_declaration, |
11212 | so we do the same. */ | |
254e6b9e DE |
11213 | gdb_assert (die_is_declaration (die, cu)); |
11214 | gdb_assert (attr); | |
11215 | } | |
c906108c SS |
11216 | if (attr) |
11217 | { | |
e7c27a73 | 11218 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 11219 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 11220 | if (!suppress_add) |
34eaf542 TT |
11221 | { |
11222 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 11223 | list_to_add = &global_symbols; |
34eaf542 | 11224 | else |
e37fd15a | 11225 | list_to_add = cu->list_in_scope; |
34eaf542 | 11226 | } |
c906108c SS |
11227 | break; |
11228 | } | |
e142c38c | 11229 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11230 | if (attr) |
11231 | { | |
e7c27a73 | 11232 | var_decode_location (attr, sym, cu); |
e142c38c | 11233 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
11234 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
11235 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
11236 | && !dwarf2_per_objfile->has_section_at_zero) | |
11237 | { | |
11238 | /* When a static variable is eliminated by the linker, | |
11239 | the corresponding debug information is not stripped | |
11240 | out, but the variable address is set to null; | |
11241 | do not add such variables into symbol table. */ | |
11242 | } | |
11243 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 11244 | { |
f55ee35c JK |
11245 | /* Workaround gfortran PR debug/40040 - it uses |
11246 | DW_AT_location for variables in -fPIC libraries which may | |
11247 | get overriden by other libraries/executable and get | |
11248 | a different address. Resolve it by the minimal symbol | |
11249 | which may come from inferior's executable using copy | |
11250 | relocation. Make this workaround only for gfortran as for | |
11251 | other compilers GDB cannot guess the minimal symbol | |
11252 | Fortran mangling kind. */ | |
11253 | if (cu->language == language_fortran && die->parent | |
11254 | && die->parent->tag == DW_TAG_module | |
11255 | && cu->producer | |
11256 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
11257 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
11258 | ||
1c809c68 TT |
11259 | /* A variable with DW_AT_external is never static, |
11260 | but it may be block-scoped. */ | |
11261 | list_to_add = (cu->list_in_scope == &file_symbols | |
11262 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 11263 | } |
c906108c | 11264 | else |
e37fd15a | 11265 | list_to_add = cu->list_in_scope; |
c906108c SS |
11266 | } |
11267 | else | |
11268 | { | |
11269 | /* We do not know the address of this symbol. | |
c5aa993b JM |
11270 | If it is an external symbol and we have type information |
11271 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
11272 | The address of the variable will then be determined from | |
11273 | the minimal symbol table whenever the variable is | |
11274 | referenced. */ | |
e142c38c | 11275 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 11276 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 11277 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 11278 | { |
0fe7935b DJ |
11279 | /* A variable with DW_AT_external is never static, but it |
11280 | may be block-scoped. */ | |
11281 | list_to_add = (cu->list_in_scope == &file_symbols | |
11282 | ? &global_symbols : cu->list_in_scope); | |
11283 | ||
c906108c | 11284 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 11285 | } |
442ddf59 JK |
11286 | else if (!die_is_declaration (die, cu)) |
11287 | { | |
11288 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
11289 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
11290 | if (!suppress_add) |
11291 | list_to_add = cu->list_in_scope; | |
442ddf59 | 11292 | } |
c906108c SS |
11293 | } |
11294 | break; | |
11295 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
11296 | /* If we are inside a function, mark this as an argument. If |
11297 | not, we might be looking at an argument to an inlined function | |
11298 | when we do not have enough information to show inlined frames; | |
11299 | pretend it's a local variable in that case so that the user can | |
11300 | still see it. */ | |
11301 | if (context_stack_depth > 0 | |
11302 | && context_stack[context_stack_depth - 1].name != NULL) | |
11303 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 11304 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11305 | if (attr) |
11306 | { | |
e7c27a73 | 11307 | var_decode_location (attr, sym, cu); |
c906108c | 11308 | } |
e142c38c | 11309 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11310 | if (attr) |
11311 | { | |
e7c27a73 | 11312 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11313 | } |
f346a30d PM |
11314 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
11315 | if (attr && DW_UNSND (attr)) | |
11316 | { | |
11317 | struct type *ref_type; | |
11318 | ||
11319 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); | |
11320 | SYMBOL_TYPE (sym) = ref_type; | |
11321 | } | |
11322 | ||
e37fd15a | 11323 | list_to_add = cu->list_in_scope; |
c906108c SS |
11324 | break; |
11325 | case DW_TAG_unspecified_parameters: | |
11326 | /* From varargs functions; gdb doesn't seem to have any | |
11327 | interest in this information, so just ignore it for now. | |
11328 | (FIXME?) */ | |
11329 | break; | |
34eaf542 TT |
11330 | case DW_TAG_template_type_param: |
11331 | suppress_add = 1; | |
11332 | /* Fall through. */ | |
c906108c | 11333 | case DW_TAG_class_type: |
680b30c7 | 11334 | case DW_TAG_interface_type: |
c906108c SS |
11335 | case DW_TAG_structure_type: |
11336 | case DW_TAG_union_type: | |
72019c9c | 11337 | case DW_TAG_set_type: |
c906108c SS |
11338 | case DW_TAG_enumeration_type: |
11339 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 11340 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 11341 | |
63d06c5c | 11342 | { |
987504bb | 11343 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
11344 | really ever be static objects: otherwise, if you try |
11345 | to, say, break of a class's method and you're in a file | |
11346 | which doesn't mention that class, it won't work unless | |
11347 | the check for all static symbols in lookup_symbol_aux | |
11348 | saves you. See the OtherFileClass tests in | |
11349 | gdb.c++/namespace.exp. */ | |
11350 | ||
e37fd15a | 11351 | if (!suppress_add) |
34eaf542 | 11352 | { |
34eaf542 TT |
11353 | list_to_add = (cu->list_in_scope == &file_symbols |
11354 | && (cu->language == language_cplus | |
11355 | || cu->language == language_java) | |
11356 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 11357 | |
64382290 TT |
11358 | /* The semantics of C++ state that "struct foo { |
11359 | ... }" also defines a typedef for "foo". A Java | |
11360 | class declaration also defines a typedef for the | |
11361 | class. */ | |
11362 | if (cu->language == language_cplus | |
11363 | || cu->language == language_java | |
11364 | || cu->language == language_ada) | |
11365 | { | |
11366 | /* The symbol's name is already allocated along | |
11367 | with this objfile, so we don't need to | |
11368 | duplicate it for the type. */ | |
11369 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
11370 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
11371 | } | |
63d06c5c DC |
11372 | } |
11373 | } | |
c906108c SS |
11374 | break; |
11375 | case DW_TAG_typedef: | |
63d06c5c DC |
11376 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
11377 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 11378 | list_to_add = cu->list_in_scope; |
63d06c5c | 11379 | break; |
c906108c | 11380 | case DW_TAG_base_type: |
a02abb62 | 11381 | case DW_TAG_subrange_type: |
c906108c | 11382 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 11383 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 11384 | list_to_add = cu->list_in_scope; |
c906108c SS |
11385 | break; |
11386 | case DW_TAG_enumerator: | |
e142c38c | 11387 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11388 | if (attr) |
11389 | { | |
e7c27a73 | 11390 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11391 | } |
63d06c5c DC |
11392 | { |
11393 | /* NOTE: carlton/2003-11-10: See comment above in the | |
11394 | DW_TAG_class_type, etc. block. */ | |
11395 | ||
e142c38c | 11396 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
11397 | && (cu->language == language_cplus |
11398 | || cu->language == language_java) | |
e142c38c | 11399 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 11400 | } |
c906108c | 11401 | break; |
5c4e30ca DC |
11402 | case DW_TAG_namespace: |
11403 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 11404 | list_to_add = &global_symbols; |
5c4e30ca | 11405 | break; |
c906108c SS |
11406 | default: |
11407 | /* Not a tag we recognize. Hopefully we aren't processing | |
11408 | trash data, but since we must specifically ignore things | |
11409 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 11410 | this point. */ |
e2e0b3e5 | 11411 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 11412 | dwarf_tag_name (die->tag)); |
c906108c SS |
11413 | break; |
11414 | } | |
df8a16a1 | 11415 | |
e37fd15a SW |
11416 | if (suppress_add) |
11417 | { | |
11418 | sym->hash_next = objfile->template_symbols; | |
11419 | objfile->template_symbols = sym; | |
11420 | list_to_add = NULL; | |
11421 | } | |
11422 | ||
11423 | if (list_to_add != NULL) | |
11424 | add_symbol_to_list (sym, list_to_add); | |
11425 | ||
df8a16a1 DJ |
11426 | /* For the benefit of old versions of GCC, check for anonymous |
11427 | namespaces based on the demangled name. */ | |
11428 | if (!processing_has_namespace_info | |
94af9270 | 11429 | && cu->language == language_cplus) |
df8a16a1 | 11430 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
11431 | } |
11432 | return (sym); | |
11433 | } | |
11434 | ||
34eaf542 TT |
11435 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
11436 | ||
11437 | static struct symbol * | |
11438 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
11439 | { | |
11440 | return new_symbol_full (die, type, cu, NULL); | |
11441 | } | |
11442 | ||
98bfdba5 PA |
11443 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
11444 | zero-extend it as appropriate for the symbol's type. The DWARF | |
11445 | standard (v4) is not entirely clear about the meaning of using | |
11446 | DW_FORM_dataN for a constant with a signed type, where the type is | |
11447 | wider than the data. The conclusion of a discussion on the DWARF | |
11448 | list was that this is unspecified. We choose to always zero-extend | |
11449 | because that is the interpretation long in use by GCC. */ | |
c906108c | 11450 | |
98bfdba5 PA |
11451 | static gdb_byte * |
11452 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
11453 | const char *name, struct obstack *obstack, | |
11454 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 11455 | { |
e7c27a73 | 11456 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
11457 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
11458 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
11459 | LONGEST l = DW_UNSND (attr); |
11460 | ||
11461 | if (bits < sizeof (*value) * 8) | |
11462 | { | |
11463 | l &= ((LONGEST) 1 << bits) - 1; | |
11464 | *value = l; | |
11465 | } | |
11466 | else if (bits == sizeof (*value) * 8) | |
11467 | *value = l; | |
11468 | else | |
11469 | { | |
11470 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
11471 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
11472 | return bytes; | |
11473 | } | |
11474 | ||
11475 | return NULL; | |
11476 | } | |
11477 | ||
11478 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
11479 | the value does not fit in *VALUE, set *BYTES - either already | |
11480 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
11481 | or, set *BATON, if we translated the constant to a location | |
11482 | expression. */ | |
11483 | ||
11484 | static void | |
11485 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
11486 | const char *name, struct obstack *obstack, | |
11487 | struct dwarf2_cu *cu, | |
11488 | long *value, gdb_byte **bytes, | |
11489 | struct dwarf2_locexpr_baton **baton) | |
11490 | { | |
11491 | struct objfile *objfile = cu->objfile; | |
11492 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 11493 | struct dwarf_block *blk; |
98bfdba5 PA |
11494 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
11495 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
11496 | ||
11497 | *value = 0; | |
11498 | *bytes = NULL; | |
11499 | *baton = NULL; | |
c906108c SS |
11500 | |
11501 | switch (attr->form) | |
11502 | { | |
11503 | case DW_FORM_addr: | |
ac56253d | 11504 | { |
ac56253d TT |
11505 | gdb_byte *data; |
11506 | ||
98bfdba5 PA |
11507 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
11508 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 11509 | cu_header->addr_size, |
98bfdba5 | 11510 | TYPE_LENGTH (type)); |
ac56253d TT |
11511 | /* Symbols of this form are reasonably rare, so we just |
11512 | piggyback on the existing location code rather than writing | |
11513 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
11514 | *baton = obstack_alloc (&objfile->objfile_obstack, |
11515 | sizeof (struct dwarf2_locexpr_baton)); | |
11516 | (*baton)->per_cu = cu->per_cu; | |
11517 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 11518 | |
98bfdba5 PA |
11519 | (*baton)->size = 2 + cu_header->addr_size; |
11520 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
11521 | (*baton)->data = data; | |
ac56253d TT |
11522 | |
11523 | data[0] = DW_OP_addr; | |
11524 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
11525 | byte_order, DW_ADDR (attr)); | |
11526 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 11527 | } |
c906108c | 11528 | break; |
4ac36638 | 11529 | case DW_FORM_string: |
93b5768b | 11530 | case DW_FORM_strp: |
98bfdba5 PA |
11531 | /* DW_STRING is already allocated on the objfile obstack, point |
11532 | directly to it. */ | |
11533 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 11534 | break; |
c906108c SS |
11535 | case DW_FORM_block1: |
11536 | case DW_FORM_block2: | |
11537 | case DW_FORM_block4: | |
11538 | case DW_FORM_block: | |
2dc7f7b3 | 11539 | case DW_FORM_exprloc: |
c906108c | 11540 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
11541 | if (TYPE_LENGTH (type) != blk->size) |
11542 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
11543 | TYPE_LENGTH (type)); | |
11544 | *bytes = blk->data; | |
c906108c | 11545 | break; |
2df3850c JM |
11546 | |
11547 | /* The DW_AT_const_value attributes are supposed to carry the | |
11548 | symbol's value "represented as it would be on the target | |
11549 | architecture." By the time we get here, it's already been | |
11550 | converted to host endianness, so we just need to sign- or | |
11551 | zero-extend it as appropriate. */ | |
11552 | case DW_FORM_data1: | |
3e43a32a MS |
11553 | *bytes = dwarf2_const_value_data (attr, type, name, |
11554 | obstack, cu, value, 8); | |
2df3850c | 11555 | break; |
c906108c | 11556 | case DW_FORM_data2: |
3e43a32a MS |
11557 | *bytes = dwarf2_const_value_data (attr, type, name, |
11558 | obstack, cu, value, 16); | |
2df3850c | 11559 | break; |
c906108c | 11560 | case DW_FORM_data4: |
3e43a32a MS |
11561 | *bytes = dwarf2_const_value_data (attr, type, name, |
11562 | obstack, cu, value, 32); | |
2df3850c | 11563 | break; |
c906108c | 11564 | case DW_FORM_data8: |
3e43a32a MS |
11565 | *bytes = dwarf2_const_value_data (attr, type, name, |
11566 | obstack, cu, value, 64); | |
2df3850c JM |
11567 | break; |
11568 | ||
c906108c | 11569 | case DW_FORM_sdata: |
98bfdba5 | 11570 | *value = DW_SND (attr); |
2df3850c JM |
11571 | break; |
11572 | ||
c906108c | 11573 | case DW_FORM_udata: |
98bfdba5 | 11574 | *value = DW_UNSND (attr); |
c906108c | 11575 | break; |
2df3850c | 11576 | |
c906108c | 11577 | default: |
4d3c2250 | 11578 | complaint (&symfile_complaints, |
e2e0b3e5 | 11579 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 11580 | dwarf_form_name (attr->form)); |
98bfdba5 | 11581 | *value = 0; |
c906108c SS |
11582 | break; |
11583 | } | |
11584 | } | |
11585 | ||
2df3850c | 11586 | |
98bfdba5 PA |
11587 | /* Copy constant value from an attribute to a symbol. */ |
11588 | ||
2df3850c | 11589 | static void |
98bfdba5 PA |
11590 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
11591 | struct dwarf2_cu *cu) | |
2df3850c | 11592 | { |
98bfdba5 PA |
11593 | struct objfile *objfile = cu->objfile; |
11594 | struct comp_unit_head *cu_header = &cu->header; | |
11595 | long value; | |
11596 | gdb_byte *bytes; | |
11597 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 11598 | |
98bfdba5 PA |
11599 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
11600 | SYMBOL_PRINT_NAME (sym), | |
11601 | &objfile->objfile_obstack, cu, | |
11602 | &value, &bytes, &baton); | |
2df3850c | 11603 | |
98bfdba5 PA |
11604 | if (baton != NULL) |
11605 | { | |
11606 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
11607 | SYMBOL_LOCATION_BATON (sym) = baton; | |
11608 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
11609 | } | |
11610 | else if (bytes != NULL) | |
11611 | { | |
11612 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
11613 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
11614 | } | |
11615 | else | |
11616 | { | |
11617 | SYMBOL_VALUE (sym) = value; | |
11618 | SYMBOL_CLASS (sym) = LOC_CONST; | |
11619 | } | |
2df3850c JM |
11620 | } |
11621 | ||
c906108c SS |
11622 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
11623 | ||
11624 | static struct type * | |
e7c27a73 | 11625 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11626 | { |
c906108c | 11627 | struct attribute *type_attr; |
c906108c | 11628 | |
e142c38c | 11629 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
11630 | if (!type_attr) |
11631 | { | |
11632 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 11633 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 11634 | } |
348e048f | 11635 | |
673bfd45 | 11636 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11637 | } |
11638 | ||
b4ba55a1 JB |
11639 | /* True iff CU's producer generates GNAT Ada auxiliary information |
11640 | that allows to find parallel types through that information instead | |
11641 | of having to do expensive parallel lookups by type name. */ | |
11642 | ||
11643 | static int | |
11644 | need_gnat_info (struct dwarf2_cu *cu) | |
11645 | { | |
11646 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
11647 | of GNAT produces this auxiliary information, without any indication | |
11648 | that it is produced. Part of enhancing the FSF version of GNAT | |
11649 | to produce that information will be to put in place an indicator | |
11650 | that we can use in order to determine whether the descriptive type | |
11651 | info is available or not. One suggestion that has been made is | |
11652 | to use a new attribute, attached to the CU die. For now, assume | |
11653 | that the descriptive type info is not available. */ | |
11654 | return 0; | |
11655 | } | |
11656 | ||
b4ba55a1 JB |
11657 | /* Return the auxiliary type of the die in question using its |
11658 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
11659 | attribute is not present. */ | |
11660 | ||
11661 | static struct type * | |
11662 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
11663 | { | |
b4ba55a1 | 11664 | struct attribute *type_attr; |
b4ba55a1 JB |
11665 | |
11666 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
11667 | if (!type_attr) | |
11668 | return NULL; | |
11669 | ||
673bfd45 | 11670 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
11671 | } |
11672 | ||
11673 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
11674 | descriptive type accordingly. */ | |
11675 | ||
11676 | static void | |
11677 | set_descriptive_type (struct type *type, struct die_info *die, | |
11678 | struct dwarf2_cu *cu) | |
11679 | { | |
11680 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
11681 | ||
11682 | if (descriptive_type) | |
11683 | { | |
11684 | ALLOCATE_GNAT_AUX_TYPE (type); | |
11685 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
11686 | } | |
11687 | } | |
11688 | ||
c906108c SS |
11689 | /* Return the containing type of the die in question using its |
11690 | DW_AT_containing_type attribute. */ | |
11691 | ||
11692 | static struct type * | |
e7c27a73 | 11693 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11694 | { |
c906108c | 11695 | struct attribute *type_attr; |
c906108c | 11696 | |
e142c38c | 11697 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
11698 | if (!type_attr) |
11699 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
11700 | "[in module %s]"), cu->objfile->name); | |
11701 | ||
673bfd45 | 11702 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11703 | } |
11704 | ||
673bfd45 DE |
11705 | /* Look up the type of DIE in CU using its type attribute ATTR. |
11706 | If there is no type substitute an error marker. */ | |
11707 | ||
c906108c | 11708 | static struct type * |
673bfd45 DE |
11709 | lookup_die_type (struct die_info *die, struct attribute *attr, |
11710 | struct dwarf2_cu *cu) | |
c906108c | 11711 | { |
f792889a DJ |
11712 | struct type *this_type; |
11713 | ||
673bfd45 DE |
11714 | /* First see if we have it cached. */ |
11715 | ||
11716 | if (is_ref_attr (attr)) | |
11717 | { | |
11718 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
11719 | ||
11720 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
11721 | } | |
55f1336d | 11722 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
11723 | { |
11724 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
11725 | struct dwarf2_cu *sig_cu; | |
11726 | unsigned int offset; | |
11727 | ||
11728 | /* sig_type will be NULL if the signatured type is missing from | |
11729 | the debug info. */ | |
11730 | if (sig_type == NULL) | |
11731 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
11732 | "at 0x%x [in module %s]"), | |
11733 | die->offset, cu->objfile->name); | |
11734 | ||
11735 | gdb_assert (sig_type->per_cu.from_debug_types); | |
b3c8eb43 | 11736 | offset = sig_type->per_cu.offset + sig_type->type_offset; |
673bfd45 DE |
11737 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
11738 | } | |
11739 | else | |
11740 | { | |
11741 | dump_die_for_error (die); | |
11742 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
11743 | dwarf_attr_name (attr->name), cu->objfile->name); | |
11744 | } | |
11745 | ||
11746 | /* If not cached we need to read it in. */ | |
11747 | ||
11748 | if (this_type == NULL) | |
11749 | { | |
11750 | struct die_info *type_die; | |
11751 | struct dwarf2_cu *type_cu = cu; | |
11752 | ||
11753 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
11754 | /* If the type is cached, we should have found it above. */ | |
11755 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
11756 | this_type = read_type_die_1 (type_die, type_cu); | |
11757 | } | |
11758 | ||
11759 | /* If we still don't have a type use an error marker. */ | |
11760 | ||
11761 | if (this_type == NULL) | |
c906108c | 11762 | { |
b00fdb78 TT |
11763 | char *message, *saved; |
11764 | ||
11765 | /* read_type_die already issued a complaint. */ | |
11766 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
11767 | cu->objfile->name, | |
11768 | cu->header.offset, | |
11769 | die->offset); | |
11770 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
11771 | message, strlen (message)); | |
11772 | xfree (message); | |
11773 | ||
11774 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 11775 | } |
673bfd45 | 11776 | |
f792889a | 11777 | return this_type; |
c906108c SS |
11778 | } |
11779 | ||
673bfd45 DE |
11780 | /* Return the type in DIE, CU. |
11781 | Returns NULL for invalid types. | |
11782 | ||
11783 | This first does a lookup in the appropriate type_hash table, | |
11784 | and only reads the die in if necessary. | |
11785 | ||
11786 | NOTE: This can be called when reading in partial or full symbols. */ | |
11787 | ||
f792889a | 11788 | static struct type * |
e7c27a73 | 11789 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11790 | { |
f792889a DJ |
11791 | struct type *this_type; |
11792 | ||
11793 | this_type = get_die_type (die, cu); | |
11794 | if (this_type) | |
11795 | return this_type; | |
11796 | ||
673bfd45 DE |
11797 | return read_type_die_1 (die, cu); |
11798 | } | |
11799 | ||
11800 | /* Read the type in DIE, CU. | |
11801 | Returns NULL for invalid types. */ | |
11802 | ||
11803 | static struct type * | |
11804 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
11805 | { | |
11806 | struct type *this_type = NULL; | |
11807 | ||
c906108c SS |
11808 | switch (die->tag) |
11809 | { | |
11810 | case DW_TAG_class_type: | |
680b30c7 | 11811 | case DW_TAG_interface_type: |
c906108c SS |
11812 | case DW_TAG_structure_type: |
11813 | case DW_TAG_union_type: | |
f792889a | 11814 | this_type = read_structure_type (die, cu); |
c906108c SS |
11815 | break; |
11816 | case DW_TAG_enumeration_type: | |
f792889a | 11817 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
11818 | break; |
11819 | case DW_TAG_subprogram: | |
11820 | case DW_TAG_subroutine_type: | |
edb3359d | 11821 | case DW_TAG_inlined_subroutine: |
f792889a | 11822 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
11823 | break; |
11824 | case DW_TAG_array_type: | |
f792889a | 11825 | this_type = read_array_type (die, cu); |
c906108c | 11826 | break; |
72019c9c | 11827 | case DW_TAG_set_type: |
f792889a | 11828 | this_type = read_set_type (die, cu); |
72019c9c | 11829 | break; |
c906108c | 11830 | case DW_TAG_pointer_type: |
f792889a | 11831 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
11832 | break; |
11833 | case DW_TAG_ptr_to_member_type: | |
f792889a | 11834 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
11835 | break; |
11836 | case DW_TAG_reference_type: | |
f792889a | 11837 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
11838 | break; |
11839 | case DW_TAG_const_type: | |
f792889a | 11840 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
11841 | break; |
11842 | case DW_TAG_volatile_type: | |
f792889a | 11843 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
11844 | break; |
11845 | case DW_TAG_string_type: | |
f792889a | 11846 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
11847 | break; |
11848 | case DW_TAG_typedef: | |
f792889a | 11849 | this_type = read_typedef (die, cu); |
c906108c | 11850 | break; |
a02abb62 | 11851 | case DW_TAG_subrange_type: |
f792889a | 11852 | this_type = read_subrange_type (die, cu); |
a02abb62 | 11853 | break; |
c906108c | 11854 | case DW_TAG_base_type: |
f792889a | 11855 | this_type = read_base_type (die, cu); |
c906108c | 11856 | break; |
81a17f79 | 11857 | case DW_TAG_unspecified_type: |
f792889a | 11858 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 11859 | break; |
0114d602 DJ |
11860 | case DW_TAG_namespace: |
11861 | this_type = read_namespace_type (die, cu); | |
11862 | break; | |
f55ee35c JK |
11863 | case DW_TAG_module: |
11864 | this_type = read_module_type (die, cu); | |
11865 | break; | |
c906108c | 11866 | default: |
3e43a32a MS |
11867 | complaint (&symfile_complaints, |
11868 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 11869 | dwarf_tag_name (die->tag)); |
c906108c SS |
11870 | break; |
11871 | } | |
63d06c5c | 11872 | |
f792889a | 11873 | return this_type; |
63d06c5c DC |
11874 | } |
11875 | ||
abc72ce4 DE |
11876 | /* See if we can figure out if the class lives in a namespace. We do |
11877 | this by looking for a member function; its demangled name will | |
11878 | contain namespace info, if there is any. | |
11879 | Return the computed name or NULL. | |
11880 | Space for the result is allocated on the objfile's obstack. | |
11881 | This is the full-die version of guess_partial_die_structure_name. | |
11882 | In this case we know DIE has no useful parent. */ | |
11883 | ||
11884 | static char * | |
11885 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
11886 | { | |
11887 | struct die_info *spec_die; | |
11888 | struct dwarf2_cu *spec_cu; | |
11889 | struct die_info *child; | |
11890 | ||
11891 | spec_cu = cu; | |
11892 | spec_die = die_specification (die, &spec_cu); | |
11893 | if (spec_die != NULL) | |
11894 | { | |
11895 | die = spec_die; | |
11896 | cu = spec_cu; | |
11897 | } | |
11898 | ||
11899 | for (child = die->child; | |
11900 | child != NULL; | |
11901 | child = child->sibling) | |
11902 | { | |
11903 | if (child->tag == DW_TAG_subprogram) | |
11904 | { | |
11905 | struct attribute *attr; | |
11906 | ||
11907 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
11908 | if (attr == NULL) | |
11909 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
11910 | if (attr != NULL) | |
11911 | { | |
11912 | char *actual_name | |
11913 | = language_class_name_from_physname (cu->language_defn, | |
11914 | DW_STRING (attr)); | |
11915 | char *name = NULL; | |
11916 | ||
11917 | if (actual_name != NULL) | |
11918 | { | |
11919 | char *die_name = dwarf2_name (die, cu); | |
11920 | ||
11921 | if (die_name != NULL | |
11922 | && strcmp (die_name, actual_name) != 0) | |
11923 | { | |
11924 | /* Strip off the class name from the full name. | |
11925 | We want the prefix. */ | |
11926 | int die_name_len = strlen (die_name); | |
11927 | int actual_name_len = strlen (actual_name); | |
11928 | ||
11929 | /* Test for '::' as a sanity check. */ | |
11930 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
11931 | && actual_name[actual_name_len |
11932 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
11933 | name = |
11934 | obsavestring (actual_name, | |
11935 | actual_name_len - die_name_len - 2, | |
11936 | &cu->objfile->objfile_obstack); | |
11937 | } | |
11938 | } | |
11939 | xfree (actual_name); | |
11940 | return name; | |
11941 | } | |
11942 | } | |
11943 | } | |
11944 | ||
11945 | return NULL; | |
11946 | } | |
11947 | ||
fdde2d81 | 11948 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 11949 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 11950 | |
0114d602 DJ |
11951 | For example, if we're within the method foo() in the following |
11952 | code: | |
11953 | ||
11954 | namespace N { | |
11955 | class C { | |
11956 | void foo () { | |
11957 | } | |
11958 | }; | |
11959 | } | |
11960 | ||
11961 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
11962 | |
11963 | static char * | |
e142c38c | 11964 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 11965 | { |
0114d602 DJ |
11966 | struct die_info *parent, *spec_die; |
11967 | struct dwarf2_cu *spec_cu; | |
11968 | struct type *parent_type; | |
63d06c5c | 11969 | |
f55ee35c JK |
11970 | if (cu->language != language_cplus && cu->language != language_java |
11971 | && cu->language != language_fortran) | |
0114d602 DJ |
11972 | return ""; |
11973 | ||
11974 | /* We have to be careful in the presence of DW_AT_specification. | |
11975 | For example, with GCC 3.4, given the code | |
11976 | ||
11977 | namespace N { | |
11978 | void foo() { | |
11979 | // Definition of N::foo. | |
11980 | } | |
11981 | } | |
11982 | ||
11983 | then we'll have a tree of DIEs like this: | |
11984 | ||
11985 | 1: DW_TAG_compile_unit | |
11986 | 2: DW_TAG_namespace // N | |
11987 | 3: DW_TAG_subprogram // declaration of N::foo | |
11988 | 4: DW_TAG_subprogram // definition of N::foo | |
11989 | DW_AT_specification // refers to die #3 | |
11990 | ||
11991 | Thus, when processing die #4, we have to pretend that we're in | |
11992 | the context of its DW_AT_specification, namely the contex of die | |
11993 | #3. */ | |
11994 | spec_cu = cu; | |
11995 | spec_die = die_specification (die, &spec_cu); | |
11996 | if (spec_die == NULL) | |
11997 | parent = die->parent; | |
11998 | else | |
63d06c5c | 11999 | { |
0114d602 DJ |
12000 | parent = spec_die->parent; |
12001 | cu = spec_cu; | |
63d06c5c | 12002 | } |
0114d602 DJ |
12003 | |
12004 | if (parent == NULL) | |
12005 | return ""; | |
98bfdba5 PA |
12006 | else if (parent->building_fullname) |
12007 | { | |
12008 | const char *name; | |
12009 | const char *parent_name; | |
12010 | ||
12011 | /* It has been seen on RealView 2.2 built binaries, | |
12012 | DW_TAG_template_type_param types actually _defined_ as | |
12013 | children of the parent class: | |
12014 | ||
12015 | enum E {}; | |
12016 | template class <class Enum> Class{}; | |
12017 | Class<enum E> class_e; | |
12018 | ||
12019 | 1: DW_TAG_class_type (Class) | |
12020 | 2: DW_TAG_enumeration_type (E) | |
12021 | 3: DW_TAG_enumerator (enum1:0) | |
12022 | 3: DW_TAG_enumerator (enum2:1) | |
12023 | ... | |
12024 | 2: DW_TAG_template_type_param | |
12025 | DW_AT_type DW_FORM_ref_udata (E) | |
12026 | ||
12027 | Besides being broken debug info, it can put GDB into an | |
12028 | infinite loop. Consider: | |
12029 | ||
12030 | When we're building the full name for Class<E>, we'll start | |
12031 | at Class, and go look over its template type parameters, | |
12032 | finding E. We'll then try to build the full name of E, and | |
12033 | reach here. We're now trying to build the full name of E, | |
12034 | and look over the parent DIE for containing scope. In the | |
12035 | broken case, if we followed the parent DIE of E, we'd again | |
12036 | find Class, and once again go look at its template type | |
12037 | arguments, etc., etc. Simply don't consider such parent die | |
12038 | as source-level parent of this die (it can't be, the language | |
12039 | doesn't allow it), and break the loop here. */ | |
12040 | name = dwarf2_name (die, cu); | |
12041 | parent_name = dwarf2_name (parent, cu); | |
12042 | complaint (&symfile_complaints, | |
12043 | _("template param type '%s' defined within parent '%s'"), | |
12044 | name ? name : "<unknown>", | |
12045 | parent_name ? parent_name : "<unknown>"); | |
12046 | return ""; | |
12047 | } | |
63d06c5c | 12048 | else |
0114d602 DJ |
12049 | switch (parent->tag) |
12050 | { | |
63d06c5c | 12051 | case DW_TAG_namespace: |
0114d602 | 12052 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
12053 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
12054 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
12055 | Work around this problem here. */ | |
12056 | if (cu->language == language_cplus | |
12057 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
12058 | return ""; | |
0114d602 DJ |
12059 | /* We give a name to even anonymous namespaces. */ |
12060 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 12061 | case DW_TAG_class_type: |
680b30c7 | 12062 | case DW_TAG_interface_type: |
63d06c5c | 12063 | case DW_TAG_structure_type: |
0114d602 | 12064 | case DW_TAG_union_type: |
f55ee35c | 12065 | case DW_TAG_module: |
0114d602 DJ |
12066 | parent_type = read_type_die (parent, cu); |
12067 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
12068 | return TYPE_TAG_NAME (parent_type); | |
12069 | else | |
12070 | /* An anonymous structure is only allowed non-static data | |
12071 | members; no typedefs, no member functions, et cetera. | |
12072 | So it does not need a prefix. */ | |
12073 | return ""; | |
abc72ce4 DE |
12074 | case DW_TAG_compile_unit: |
12075 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
12076 | if (cu->language == language_cplus | |
12077 | && dwarf2_per_objfile->types.asection != NULL | |
12078 | && die->child != NULL | |
12079 | && (die->tag == DW_TAG_class_type | |
12080 | || die->tag == DW_TAG_structure_type | |
12081 | || die->tag == DW_TAG_union_type)) | |
12082 | { | |
12083 | char *name = guess_full_die_structure_name (die, cu); | |
12084 | if (name != NULL) | |
12085 | return name; | |
12086 | } | |
12087 | return ""; | |
63d06c5c | 12088 | default: |
8176b9b8 | 12089 | return determine_prefix (parent, cu); |
63d06c5c | 12090 | } |
63d06c5c DC |
12091 | } |
12092 | ||
3e43a32a MS |
12093 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
12094 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
12095 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
12096 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
12097 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 12098 | |
f55ee35c | 12099 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
12100 | |
12101 | static char * | |
f55ee35c JK |
12102 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
12103 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 12104 | { |
f55ee35c | 12105 | const char *lead = ""; |
5c315b68 | 12106 | const char *sep; |
63d06c5c | 12107 | |
3e43a32a MS |
12108 | if (suffix == NULL || suffix[0] == '\0' |
12109 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
12110 | sep = ""; |
12111 | else if (cu->language == language_java) | |
12112 | sep = "."; | |
f55ee35c JK |
12113 | else if (cu->language == language_fortran && physname) |
12114 | { | |
12115 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
12116 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
12117 | ||
12118 | lead = "__"; | |
12119 | sep = "_MOD_"; | |
12120 | } | |
987504bb JJ |
12121 | else |
12122 | sep = "::"; | |
63d06c5c | 12123 | |
6dd47d34 DE |
12124 | if (prefix == NULL) |
12125 | prefix = ""; | |
12126 | if (suffix == NULL) | |
12127 | suffix = ""; | |
12128 | ||
987504bb JJ |
12129 | if (obs == NULL) |
12130 | { | |
3e43a32a MS |
12131 | char *retval |
12132 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 12133 | |
f55ee35c JK |
12134 | strcpy (retval, lead); |
12135 | strcat (retval, prefix); | |
6dd47d34 DE |
12136 | strcat (retval, sep); |
12137 | strcat (retval, suffix); | |
63d06c5c DC |
12138 | return retval; |
12139 | } | |
987504bb JJ |
12140 | else |
12141 | { | |
12142 | /* We have an obstack. */ | |
f55ee35c | 12143 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 12144 | } |
63d06c5c DC |
12145 | } |
12146 | ||
c906108c SS |
12147 | /* Return sibling of die, NULL if no sibling. */ |
12148 | ||
f9aca02d | 12149 | static struct die_info * |
fba45db2 | 12150 | sibling_die (struct die_info *die) |
c906108c | 12151 | { |
639d11d3 | 12152 | return die->sibling; |
c906108c SS |
12153 | } |
12154 | ||
71c25dea TT |
12155 | /* Get name of a die, return NULL if not found. */ |
12156 | ||
12157 | static char * | |
12158 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
12159 | struct obstack *obstack) | |
12160 | { | |
12161 | if (name && cu->language == language_cplus) | |
12162 | { | |
12163 | char *canon_name = cp_canonicalize_string (name); | |
12164 | ||
12165 | if (canon_name != NULL) | |
12166 | { | |
12167 | if (strcmp (canon_name, name) != 0) | |
12168 | name = obsavestring (canon_name, strlen (canon_name), | |
12169 | obstack); | |
12170 | xfree (canon_name); | |
12171 | } | |
12172 | } | |
12173 | ||
12174 | return name; | |
c906108c SS |
12175 | } |
12176 | ||
9219021c DC |
12177 | /* Get name of a die, return NULL if not found. */ |
12178 | ||
12179 | static char * | |
e142c38c | 12180 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
12181 | { |
12182 | struct attribute *attr; | |
12183 | ||
e142c38c | 12184 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
12185 | if ((!attr || !DW_STRING (attr)) |
12186 | && die->tag != DW_TAG_class_type | |
12187 | && die->tag != DW_TAG_interface_type | |
12188 | && die->tag != DW_TAG_structure_type | |
12189 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
12190 | return NULL; |
12191 | ||
12192 | switch (die->tag) | |
12193 | { | |
12194 | case DW_TAG_compile_unit: | |
12195 | /* Compilation units have a DW_AT_name that is a filename, not | |
12196 | a source language identifier. */ | |
12197 | case DW_TAG_enumeration_type: | |
12198 | case DW_TAG_enumerator: | |
12199 | /* These tags always have simple identifiers already; no need | |
12200 | to canonicalize them. */ | |
12201 | return DW_STRING (attr); | |
907af001 | 12202 | |
418835cc KS |
12203 | case DW_TAG_subprogram: |
12204 | /* Java constructors will all be named "<init>", so return | |
12205 | the class name when we see this special case. */ | |
12206 | if (cu->language == language_java | |
12207 | && DW_STRING (attr) != NULL | |
12208 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
12209 | { | |
12210 | struct dwarf2_cu *spec_cu = cu; | |
12211 | struct die_info *spec_die; | |
12212 | ||
12213 | /* GCJ will output '<init>' for Java constructor names. | |
12214 | For this special case, return the name of the parent class. */ | |
12215 | ||
12216 | /* GCJ may output suprogram DIEs with AT_specification set. | |
12217 | If so, use the name of the specified DIE. */ | |
12218 | spec_die = die_specification (die, &spec_cu); | |
12219 | if (spec_die != NULL) | |
12220 | return dwarf2_name (spec_die, spec_cu); | |
12221 | ||
12222 | do | |
12223 | { | |
12224 | die = die->parent; | |
12225 | if (die->tag == DW_TAG_class_type) | |
12226 | return dwarf2_name (die, cu); | |
12227 | } | |
12228 | while (die->tag != DW_TAG_compile_unit); | |
12229 | } | |
907af001 UW |
12230 | break; |
12231 | ||
12232 | case DW_TAG_class_type: | |
12233 | case DW_TAG_interface_type: | |
12234 | case DW_TAG_structure_type: | |
12235 | case DW_TAG_union_type: | |
12236 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
12237 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
12238 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
12239 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
12240 | if (attr && DW_STRING (attr) |
12241 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
12242 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 12243 | return NULL; |
53832f31 TT |
12244 | |
12245 | /* GCC might emit a nameless typedef that has a linkage name. See | |
12246 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12247 | if (!attr || DW_STRING (attr) == NULL) | |
12248 | { | |
df5c6c50 | 12249 | char *demangled = NULL; |
53832f31 TT |
12250 | |
12251 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12252 | if (attr == NULL) | |
12253 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12254 | ||
12255 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12256 | return NULL; | |
12257 | ||
df5c6c50 JK |
12258 | /* Avoid demangling DW_STRING (attr) the second time on a second |
12259 | call for the same DIE. */ | |
12260 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12261 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
12262 | |
12263 | if (demangled) | |
12264 | { | |
12265 | /* FIXME: we already did this for the partial symbol... */ | |
12266 | DW_STRING (attr) | |
12267 | = obsavestring (demangled, strlen (demangled), | |
12268 | &cu->objfile->objfile_obstack); | |
12269 | DW_STRING_IS_CANONICAL (attr) = 1; | |
12270 | xfree (demangled); | |
12271 | } | |
12272 | } | |
907af001 UW |
12273 | break; |
12274 | ||
71c25dea | 12275 | default: |
907af001 UW |
12276 | break; |
12277 | } | |
12278 | ||
12279 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12280 | { | |
12281 | DW_STRING (attr) | |
12282 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
12283 | &cu->objfile->objfile_obstack); | |
12284 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 12285 | } |
907af001 | 12286 | return DW_STRING (attr); |
9219021c DC |
12287 | } |
12288 | ||
12289 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
12290 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
12291 | containing the return value on output. */ | |
9219021c DC |
12292 | |
12293 | static struct die_info * | |
f2f0e013 | 12294 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
12295 | { |
12296 | struct attribute *attr; | |
9219021c | 12297 | |
f2f0e013 | 12298 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
12299 | if (attr == NULL) |
12300 | return NULL; | |
12301 | ||
f2f0e013 | 12302 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
12303 | } |
12304 | ||
c906108c SS |
12305 | /* Convert a DIE tag into its string name. */ |
12306 | ||
12307 | static char * | |
aa1ee363 | 12308 | dwarf_tag_name (unsigned tag) |
c906108c SS |
12309 | { |
12310 | switch (tag) | |
12311 | { | |
12312 | case DW_TAG_padding: | |
12313 | return "DW_TAG_padding"; | |
12314 | case DW_TAG_array_type: | |
12315 | return "DW_TAG_array_type"; | |
12316 | case DW_TAG_class_type: | |
12317 | return "DW_TAG_class_type"; | |
12318 | case DW_TAG_entry_point: | |
12319 | return "DW_TAG_entry_point"; | |
12320 | case DW_TAG_enumeration_type: | |
12321 | return "DW_TAG_enumeration_type"; | |
12322 | case DW_TAG_formal_parameter: | |
12323 | return "DW_TAG_formal_parameter"; | |
12324 | case DW_TAG_imported_declaration: | |
12325 | return "DW_TAG_imported_declaration"; | |
12326 | case DW_TAG_label: | |
12327 | return "DW_TAG_label"; | |
12328 | case DW_TAG_lexical_block: | |
12329 | return "DW_TAG_lexical_block"; | |
12330 | case DW_TAG_member: | |
12331 | return "DW_TAG_member"; | |
12332 | case DW_TAG_pointer_type: | |
12333 | return "DW_TAG_pointer_type"; | |
12334 | case DW_TAG_reference_type: | |
12335 | return "DW_TAG_reference_type"; | |
12336 | case DW_TAG_compile_unit: | |
12337 | return "DW_TAG_compile_unit"; | |
12338 | case DW_TAG_string_type: | |
12339 | return "DW_TAG_string_type"; | |
12340 | case DW_TAG_structure_type: | |
12341 | return "DW_TAG_structure_type"; | |
12342 | case DW_TAG_subroutine_type: | |
12343 | return "DW_TAG_subroutine_type"; | |
12344 | case DW_TAG_typedef: | |
12345 | return "DW_TAG_typedef"; | |
12346 | case DW_TAG_union_type: | |
12347 | return "DW_TAG_union_type"; | |
12348 | case DW_TAG_unspecified_parameters: | |
12349 | return "DW_TAG_unspecified_parameters"; | |
12350 | case DW_TAG_variant: | |
12351 | return "DW_TAG_variant"; | |
12352 | case DW_TAG_common_block: | |
12353 | return "DW_TAG_common_block"; | |
12354 | case DW_TAG_common_inclusion: | |
12355 | return "DW_TAG_common_inclusion"; | |
12356 | case DW_TAG_inheritance: | |
12357 | return "DW_TAG_inheritance"; | |
12358 | case DW_TAG_inlined_subroutine: | |
12359 | return "DW_TAG_inlined_subroutine"; | |
12360 | case DW_TAG_module: | |
12361 | return "DW_TAG_module"; | |
12362 | case DW_TAG_ptr_to_member_type: | |
12363 | return "DW_TAG_ptr_to_member_type"; | |
12364 | case DW_TAG_set_type: | |
12365 | return "DW_TAG_set_type"; | |
12366 | case DW_TAG_subrange_type: | |
12367 | return "DW_TAG_subrange_type"; | |
12368 | case DW_TAG_with_stmt: | |
12369 | return "DW_TAG_with_stmt"; | |
12370 | case DW_TAG_access_declaration: | |
12371 | return "DW_TAG_access_declaration"; | |
12372 | case DW_TAG_base_type: | |
12373 | return "DW_TAG_base_type"; | |
12374 | case DW_TAG_catch_block: | |
12375 | return "DW_TAG_catch_block"; | |
12376 | case DW_TAG_const_type: | |
12377 | return "DW_TAG_const_type"; | |
12378 | case DW_TAG_constant: | |
12379 | return "DW_TAG_constant"; | |
12380 | case DW_TAG_enumerator: | |
12381 | return "DW_TAG_enumerator"; | |
12382 | case DW_TAG_file_type: | |
12383 | return "DW_TAG_file_type"; | |
12384 | case DW_TAG_friend: | |
12385 | return "DW_TAG_friend"; | |
12386 | case DW_TAG_namelist: | |
12387 | return "DW_TAG_namelist"; | |
12388 | case DW_TAG_namelist_item: | |
12389 | return "DW_TAG_namelist_item"; | |
12390 | case DW_TAG_packed_type: | |
12391 | return "DW_TAG_packed_type"; | |
12392 | case DW_TAG_subprogram: | |
12393 | return "DW_TAG_subprogram"; | |
12394 | case DW_TAG_template_type_param: | |
12395 | return "DW_TAG_template_type_param"; | |
12396 | case DW_TAG_template_value_param: | |
12397 | return "DW_TAG_template_value_param"; | |
12398 | case DW_TAG_thrown_type: | |
12399 | return "DW_TAG_thrown_type"; | |
12400 | case DW_TAG_try_block: | |
12401 | return "DW_TAG_try_block"; | |
12402 | case DW_TAG_variant_part: | |
12403 | return "DW_TAG_variant_part"; | |
12404 | case DW_TAG_variable: | |
12405 | return "DW_TAG_variable"; | |
12406 | case DW_TAG_volatile_type: | |
12407 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
12408 | case DW_TAG_dwarf_procedure: |
12409 | return "DW_TAG_dwarf_procedure"; | |
12410 | case DW_TAG_restrict_type: | |
12411 | return "DW_TAG_restrict_type"; | |
12412 | case DW_TAG_interface_type: | |
12413 | return "DW_TAG_interface_type"; | |
12414 | case DW_TAG_namespace: | |
12415 | return "DW_TAG_namespace"; | |
12416 | case DW_TAG_imported_module: | |
12417 | return "DW_TAG_imported_module"; | |
12418 | case DW_TAG_unspecified_type: | |
12419 | return "DW_TAG_unspecified_type"; | |
12420 | case DW_TAG_partial_unit: | |
12421 | return "DW_TAG_partial_unit"; | |
12422 | case DW_TAG_imported_unit: | |
12423 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
12424 | case DW_TAG_condition: |
12425 | return "DW_TAG_condition"; | |
12426 | case DW_TAG_shared_type: | |
12427 | return "DW_TAG_shared_type"; | |
348e048f DE |
12428 | case DW_TAG_type_unit: |
12429 | return "DW_TAG_type_unit"; | |
c906108c SS |
12430 | case DW_TAG_MIPS_loop: |
12431 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
12432 | case DW_TAG_HP_array_descriptor: |
12433 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
12434 | case DW_TAG_format_label: |
12435 | return "DW_TAG_format_label"; | |
12436 | case DW_TAG_function_template: | |
12437 | return "DW_TAG_function_template"; | |
12438 | case DW_TAG_class_template: | |
12439 | return "DW_TAG_class_template"; | |
b7619582 GF |
12440 | case DW_TAG_GNU_BINCL: |
12441 | return "DW_TAG_GNU_BINCL"; | |
12442 | case DW_TAG_GNU_EINCL: | |
12443 | return "DW_TAG_GNU_EINCL"; | |
12444 | case DW_TAG_upc_shared_type: | |
12445 | return "DW_TAG_upc_shared_type"; | |
12446 | case DW_TAG_upc_strict_type: | |
12447 | return "DW_TAG_upc_strict_type"; | |
12448 | case DW_TAG_upc_relaxed_type: | |
12449 | return "DW_TAG_upc_relaxed_type"; | |
12450 | case DW_TAG_PGI_kanji_type: | |
12451 | return "DW_TAG_PGI_kanji_type"; | |
12452 | case DW_TAG_PGI_interface_block: | |
12453 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
12454 | default: |
12455 | return "DW_TAG_<unknown>"; | |
12456 | } | |
12457 | } | |
12458 | ||
12459 | /* Convert a DWARF attribute code into its string name. */ | |
12460 | ||
12461 | static char * | |
aa1ee363 | 12462 | dwarf_attr_name (unsigned attr) |
c906108c SS |
12463 | { |
12464 | switch (attr) | |
12465 | { | |
12466 | case DW_AT_sibling: | |
12467 | return "DW_AT_sibling"; | |
12468 | case DW_AT_location: | |
12469 | return "DW_AT_location"; | |
12470 | case DW_AT_name: | |
12471 | return "DW_AT_name"; | |
12472 | case DW_AT_ordering: | |
12473 | return "DW_AT_ordering"; | |
12474 | case DW_AT_subscr_data: | |
12475 | return "DW_AT_subscr_data"; | |
12476 | case DW_AT_byte_size: | |
12477 | return "DW_AT_byte_size"; | |
12478 | case DW_AT_bit_offset: | |
12479 | return "DW_AT_bit_offset"; | |
12480 | case DW_AT_bit_size: | |
12481 | return "DW_AT_bit_size"; | |
12482 | case DW_AT_element_list: | |
12483 | return "DW_AT_element_list"; | |
12484 | case DW_AT_stmt_list: | |
12485 | return "DW_AT_stmt_list"; | |
12486 | case DW_AT_low_pc: | |
12487 | return "DW_AT_low_pc"; | |
12488 | case DW_AT_high_pc: | |
12489 | return "DW_AT_high_pc"; | |
12490 | case DW_AT_language: | |
12491 | return "DW_AT_language"; | |
12492 | case DW_AT_member: | |
12493 | return "DW_AT_member"; | |
12494 | case DW_AT_discr: | |
12495 | return "DW_AT_discr"; | |
12496 | case DW_AT_discr_value: | |
12497 | return "DW_AT_discr_value"; | |
12498 | case DW_AT_visibility: | |
12499 | return "DW_AT_visibility"; | |
12500 | case DW_AT_import: | |
12501 | return "DW_AT_import"; | |
12502 | case DW_AT_string_length: | |
12503 | return "DW_AT_string_length"; | |
12504 | case DW_AT_common_reference: | |
12505 | return "DW_AT_common_reference"; | |
12506 | case DW_AT_comp_dir: | |
12507 | return "DW_AT_comp_dir"; | |
12508 | case DW_AT_const_value: | |
12509 | return "DW_AT_const_value"; | |
12510 | case DW_AT_containing_type: | |
12511 | return "DW_AT_containing_type"; | |
12512 | case DW_AT_default_value: | |
12513 | return "DW_AT_default_value"; | |
12514 | case DW_AT_inline: | |
12515 | return "DW_AT_inline"; | |
12516 | case DW_AT_is_optional: | |
12517 | return "DW_AT_is_optional"; | |
12518 | case DW_AT_lower_bound: | |
12519 | return "DW_AT_lower_bound"; | |
12520 | case DW_AT_producer: | |
12521 | return "DW_AT_producer"; | |
12522 | case DW_AT_prototyped: | |
12523 | return "DW_AT_prototyped"; | |
12524 | case DW_AT_return_addr: | |
12525 | return "DW_AT_return_addr"; | |
12526 | case DW_AT_start_scope: | |
12527 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
12528 | case DW_AT_bit_stride: |
12529 | return "DW_AT_bit_stride"; | |
c906108c SS |
12530 | case DW_AT_upper_bound: |
12531 | return "DW_AT_upper_bound"; | |
12532 | case DW_AT_abstract_origin: | |
12533 | return "DW_AT_abstract_origin"; | |
12534 | case DW_AT_accessibility: | |
12535 | return "DW_AT_accessibility"; | |
12536 | case DW_AT_address_class: | |
12537 | return "DW_AT_address_class"; | |
12538 | case DW_AT_artificial: | |
12539 | return "DW_AT_artificial"; | |
12540 | case DW_AT_base_types: | |
12541 | return "DW_AT_base_types"; | |
12542 | case DW_AT_calling_convention: | |
12543 | return "DW_AT_calling_convention"; | |
12544 | case DW_AT_count: | |
12545 | return "DW_AT_count"; | |
12546 | case DW_AT_data_member_location: | |
12547 | return "DW_AT_data_member_location"; | |
12548 | case DW_AT_decl_column: | |
12549 | return "DW_AT_decl_column"; | |
12550 | case DW_AT_decl_file: | |
12551 | return "DW_AT_decl_file"; | |
12552 | case DW_AT_decl_line: | |
12553 | return "DW_AT_decl_line"; | |
12554 | case DW_AT_declaration: | |
12555 | return "DW_AT_declaration"; | |
12556 | case DW_AT_discr_list: | |
12557 | return "DW_AT_discr_list"; | |
12558 | case DW_AT_encoding: | |
12559 | return "DW_AT_encoding"; | |
12560 | case DW_AT_external: | |
12561 | return "DW_AT_external"; | |
12562 | case DW_AT_frame_base: | |
12563 | return "DW_AT_frame_base"; | |
12564 | case DW_AT_friend: | |
12565 | return "DW_AT_friend"; | |
12566 | case DW_AT_identifier_case: | |
12567 | return "DW_AT_identifier_case"; | |
12568 | case DW_AT_macro_info: | |
12569 | return "DW_AT_macro_info"; | |
12570 | case DW_AT_namelist_items: | |
12571 | return "DW_AT_namelist_items"; | |
12572 | case DW_AT_priority: | |
12573 | return "DW_AT_priority"; | |
12574 | case DW_AT_segment: | |
12575 | return "DW_AT_segment"; | |
12576 | case DW_AT_specification: | |
12577 | return "DW_AT_specification"; | |
12578 | case DW_AT_static_link: | |
12579 | return "DW_AT_static_link"; | |
12580 | case DW_AT_type: | |
12581 | return "DW_AT_type"; | |
12582 | case DW_AT_use_location: | |
12583 | return "DW_AT_use_location"; | |
12584 | case DW_AT_variable_parameter: | |
12585 | return "DW_AT_variable_parameter"; | |
12586 | case DW_AT_virtuality: | |
12587 | return "DW_AT_virtuality"; | |
12588 | case DW_AT_vtable_elem_location: | |
12589 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 12590 | /* DWARF 3 values. */ |
d9fa45fe DC |
12591 | case DW_AT_allocated: |
12592 | return "DW_AT_allocated"; | |
12593 | case DW_AT_associated: | |
12594 | return "DW_AT_associated"; | |
12595 | case DW_AT_data_location: | |
12596 | return "DW_AT_data_location"; | |
09fa0d7c JK |
12597 | case DW_AT_byte_stride: |
12598 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
12599 | case DW_AT_entry_pc: |
12600 | return "DW_AT_entry_pc"; | |
12601 | case DW_AT_use_UTF8: | |
12602 | return "DW_AT_use_UTF8"; | |
12603 | case DW_AT_extension: | |
12604 | return "DW_AT_extension"; | |
12605 | case DW_AT_ranges: | |
12606 | return "DW_AT_ranges"; | |
12607 | case DW_AT_trampoline: | |
12608 | return "DW_AT_trampoline"; | |
12609 | case DW_AT_call_column: | |
12610 | return "DW_AT_call_column"; | |
12611 | case DW_AT_call_file: | |
12612 | return "DW_AT_call_file"; | |
12613 | case DW_AT_call_line: | |
12614 | return "DW_AT_call_line"; | |
b7619582 GF |
12615 | case DW_AT_description: |
12616 | return "DW_AT_description"; | |
12617 | case DW_AT_binary_scale: | |
12618 | return "DW_AT_binary_scale"; | |
12619 | case DW_AT_decimal_scale: | |
12620 | return "DW_AT_decimal_scale"; | |
12621 | case DW_AT_small: | |
12622 | return "DW_AT_small"; | |
12623 | case DW_AT_decimal_sign: | |
12624 | return "DW_AT_decimal_sign"; | |
12625 | case DW_AT_digit_count: | |
12626 | return "DW_AT_digit_count"; | |
12627 | case DW_AT_picture_string: | |
12628 | return "DW_AT_picture_string"; | |
12629 | case DW_AT_mutable: | |
12630 | return "DW_AT_mutable"; | |
12631 | case DW_AT_threads_scaled: | |
12632 | return "DW_AT_threads_scaled"; | |
12633 | case DW_AT_explicit: | |
12634 | return "DW_AT_explicit"; | |
12635 | case DW_AT_object_pointer: | |
12636 | return "DW_AT_object_pointer"; | |
12637 | case DW_AT_endianity: | |
12638 | return "DW_AT_endianity"; | |
12639 | case DW_AT_elemental: | |
12640 | return "DW_AT_elemental"; | |
12641 | case DW_AT_pure: | |
12642 | return "DW_AT_pure"; | |
12643 | case DW_AT_recursive: | |
12644 | return "DW_AT_recursive"; | |
348e048f DE |
12645 | /* DWARF 4 values. */ |
12646 | case DW_AT_signature: | |
12647 | return "DW_AT_signature"; | |
31ef98ae TT |
12648 | case DW_AT_linkage_name: |
12649 | return "DW_AT_linkage_name"; | |
b7619582 | 12650 | /* SGI/MIPS extensions. */ |
c764a876 | 12651 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
12652 | case DW_AT_MIPS_fde: |
12653 | return "DW_AT_MIPS_fde"; | |
c764a876 | 12654 | #endif |
c906108c SS |
12655 | case DW_AT_MIPS_loop_begin: |
12656 | return "DW_AT_MIPS_loop_begin"; | |
12657 | case DW_AT_MIPS_tail_loop_begin: | |
12658 | return "DW_AT_MIPS_tail_loop_begin"; | |
12659 | case DW_AT_MIPS_epilog_begin: | |
12660 | return "DW_AT_MIPS_epilog_begin"; | |
12661 | case DW_AT_MIPS_loop_unroll_factor: | |
12662 | return "DW_AT_MIPS_loop_unroll_factor"; | |
12663 | case DW_AT_MIPS_software_pipeline_depth: | |
12664 | return "DW_AT_MIPS_software_pipeline_depth"; | |
12665 | case DW_AT_MIPS_linkage_name: | |
12666 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
12667 | case DW_AT_MIPS_stride: |
12668 | return "DW_AT_MIPS_stride"; | |
12669 | case DW_AT_MIPS_abstract_name: | |
12670 | return "DW_AT_MIPS_abstract_name"; | |
12671 | case DW_AT_MIPS_clone_origin: | |
12672 | return "DW_AT_MIPS_clone_origin"; | |
12673 | case DW_AT_MIPS_has_inlines: | |
12674 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 12675 | /* HP extensions. */ |
c764a876 | 12676 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
12677 | case DW_AT_HP_block_index: |
12678 | return "DW_AT_HP_block_index"; | |
c764a876 | 12679 | #endif |
b7619582 GF |
12680 | case DW_AT_HP_unmodifiable: |
12681 | return "DW_AT_HP_unmodifiable"; | |
12682 | case DW_AT_HP_actuals_stmt_list: | |
12683 | return "DW_AT_HP_actuals_stmt_list"; | |
12684 | case DW_AT_HP_proc_per_section: | |
12685 | return "DW_AT_HP_proc_per_section"; | |
12686 | case DW_AT_HP_raw_data_ptr: | |
12687 | return "DW_AT_HP_raw_data_ptr"; | |
12688 | case DW_AT_HP_pass_by_reference: | |
12689 | return "DW_AT_HP_pass_by_reference"; | |
12690 | case DW_AT_HP_opt_level: | |
12691 | return "DW_AT_HP_opt_level"; | |
12692 | case DW_AT_HP_prof_version_id: | |
12693 | return "DW_AT_HP_prof_version_id"; | |
12694 | case DW_AT_HP_opt_flags: | |
12695 | return "DW_AT_HP_opt_flags"; | |
12696 | case DW_AT_HP_cold_region_low_pc: | |
12697 | return "DW_AT_HP_cold_region_low_pc"; | |
12698 | case DW_AT_HP_cold_region_high_pc: | |
12699 | return "DW_AT_HP_cold_region_high_pc"; | |
12700 | case DW_AT_HP_all_variables_modifiable: | |
12701 | return "DW_AT_HP_all_variables_modifiable"; | |
12702 | case DW_AT_HP_linkage_name: | |
12703 | return "DW_AT_HP_linkage_name"; | |
12704 | case DW_AT_HP_prof_flags: | |
12705 | return "DW_AT_HP_prof_flags"; | |
12706 | /* GNU extensions. */ | |
c906108c SS |
12707 | case DW_AT_sf_names: |
12708 | return "DW_AT_sf_names"; | |
12709 | case DW_AT_src_info: | |
12710 | return "DW_AT_src_info"; | |
12711 | case DW_AT_mac_info: | |
12712 | return "DW_AT_mac_info"; | |
12713 | case DW_AT_src_coords: | |
12714 | return "DW_AT_src_coords"; | |
12715 | case DW_AT_body_begin: | |
12716 | return "DW_AT_body_begin"; | |
12717 | case DW_AT_body_end: | |
12718 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
12719 | case DW_AT_GNU_vector: |
12720 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
12721 | case DW_AT_GNU_odr_signature: |
12722 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
12723 | /* VMS extensions. */ |
12724 | case DW_AT_VMS_rtnbeg_pd_address: | |
12725 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
12726 | /* UPC extension. */ | |
12727 | case DW_AT_upc_threads_scaled: | |
12728 | return "DW_AT_upc_threads_scaled"; | |
12729 | /* PGI (STMicroelectronics) extensions. */ | |
12730 | case DW_AT_PGI_lbase: | |
12731 | return "DW_AT_PGI_lbase"; | |
12732 | case DW_AT_PGI_soffset: | |
12733 | return "DW_AT_PGI_soffset"; | |
12734 | case DW_AT_PGI_lstride: | |
12735 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
12736 | default: |
12737 | return "DW_AT_<unknown>"; | |
12738 | } | |
12739 | } | |
12740 | ||
12741 | /* Convert a DWARF value form code into its string name. */ | |
12742 | ||
12743 | static char * | |
aa1ee363 | 12744 | dwarf_form_name (unsigned form) |
c906108c SS |
12745 | { |
12746 | switch (form) | |
12747 | { | |
12748 | case DW_FORM_addr: | |
12749 | return "DW_FORM_addr"; | |
12750 | case DW_FORM_block2: | |
12751 | return "DW_FORM_block2"; | |
12752 | case DW_FORM_block4: | |
12753 | return "DW_FORM_block4"; | |
12754 | case DW_FORM_data2: | |
12755 | return "DW_FORM_data2"; | |
12756 | case DW_FORM_data4: | |
12757 | return "DW_FORM_data4"; | |
12758 | case DW_FORM_data8: | |
12759 | return "DW_FORM_data8"; | |
12760 | case DW_FORM_string: | |
12761 | return "DW_FORM_string"; | |
12762 | case DW_FORM_block: | |
12763 | return "DW_FORM_block"; | |
12764 | case DW_FORM_block1: | |
12765 | return "DW_FORM_block1"; | |
12766 | case DW_FORM_data1: | |
12767 | return "DW_FORM_data1"; | |
12768 | case DW_FORM_flag: | |
12769 | return "DW_FORM_flag"; | |
12770 | case DW_FORM_sdata: | |
12771 | return "DW_FORM_sdata"; | |
12772 | case DW_FORM_strp: | |
12773 | return "DW_FORM_strp"; | |
12774 | case DW_FORM_udata: | |
12775 | return "DW_FORM_udata"; | |
12776 | case DW_FORM_ref_addr: | |
12777 | return "DW_FORM_ref_addr"; | |
12778 | case DW_FORM_ref1: | |
12779 | return "DW_FORM_ref1"; | |
12780 | case DW_FORM_ref2: | |
12781 | return "DW_FORM_ref2"; | |
12782 | case DW_FORM_ref4: | |
12783 | return "DW_FORM_ref4"; | |
12784 | case DW_FORM_ref8: | |
12785 | return "DW_FORM_ref8"; | |
12786 | case DW_FORM_ref_udata: | |
12787 | return "DW_FORM_ref_udata"; | |
12788 | case DW_FORM_indirect: | |
12789 | return "DW_FORM_indirect"; | |
348e048f DE |
12790 | case DW_FORM_sec_offset: |
12791 | return "DW_FORM_sec_offset"; | |
12792 | case DW_FORM_exprloc: | |
12793 | return "DW_FORM_exprloc"; | |
12794 | case DW_FORM_flag_present: | |
12795 | return "DW_FORM_flag_present"; | |
55f1336d TT |
12796 | case DW_FORM_ref_sig8: |
12797 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
12798 | default: |
12799 | return "DW_FORM_<unknown>"; | |
12800 | } | |
12801 | } | |
12802 | ||
12803 | /* Convert a DWARF stack opcode into its string name. */ | |
12804 | ||
9eae7c52 | 12805 | const char * |
b1bfef65 | 12806 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
12807 | { |
12808 | switch (op) | |
12809 | { | |
12810 | case DW_OP_addr: | |
12811 | return "DW_OP_addr"; | |
12812 | case DW_OP_deref: | |
12813 | return "DW_OP_deref"; | |
12814 | case DW_OP_const1u: | |
12815 | return "DW_OP_const1u"; | |
12816 | case DW_OP_const1s: | |
12817 | return "DW_OP_const1s"; | |
12818 | case DW_OP_const2u: | |
12819 | return "DW_OP_const2u"; | |
12820 | case DW_OP_const2s: | |
12821 | return "DW_OP_const2s"; | |
12822 | case DW_OP_const4u: | |
12823 | return "DW_OP_const4u"; | |
12824 | case DW_OP_const4s: | |
12825 | return "DW_OP_const4s"; | |
12826 | case DW_OP_const8u: | |
12827 | return "DW_OP_const8u"; | |
12828 | case DW_OP_const8s: | |
12829 | return "DW_OP_const8s"; | |
12830 | case DW_OP_constu: | |
12831 | return "DW_OP_constu"; | |
12832 | case DW_OP_consts: | |
12833 | return "DW_OP_consts"; | |
12834 | case DW_OP_dup: | |
12835 | return "DW_OP_dup"; | |
12836 | case DW_OP_drop: | |
12837 | return "DW_OP_drop"; | |
12838 | case DW_OP_over: | |
12839 | return "DW_OP_over"; | |
12840 | case DW_OP_pick: | |
12841 | return "DW_OP_pick"; | |
12842 | case DW_OP_swap: | |
12843 | return "DW_OP_swap"; | |
12844 | case DW_OP_rot: | |
12845 | return "DW_OP_rot"; | |
12846 | case DW_OP_xderef: | |
12847 | return "DW_OP_xderef"; | |
12848 | case DW_OP_abs: | |
12849 | return "DW_OP_abs"; | |
12850 | case DW_OP_and: | |
12851 | return "DW_OP_and"; | |
12852 | case DW_OP_div: | |
12853 | return "DW_OP_div"; | |
12854 | case DW_OP_minus: | |
12855 | return "DW_OP_minus"; | |
12856 | case DW_OP_mod: | |
12857 | return "DW_OP_mod"; | |
12858 | case DW_OP_mul: | |
12859 | return "DW_OP_mul"; | |
12860 | case DW_OP_neg: | |
12861 | return "DW_OP_neg"; | |
12862 | case DW_OP_not: | |
12863 | return "DW_OP_not"; | |
12864 | case DW_OP_or: | |
12865 | return "DW_OP_or"; | |
12866 | case DW_OP_plus: | |
12867 | return "DW_OP_plus"; | |
12868 | case DW_OP_plus_uconst: | |
12869 | return "DW_OP_plus_uconst"; | |
12870 | case DW_OP_shl: | |
12871 | return "DW_OP_shl"; | |
12872 | case DW_OP_shr: | |
12873 | return "DW_OP_shr"; | |
12874 | case DW_OP_shra: | |
12875 | return "DW_OP_shra"; | |
12876 | case DW_OP_xor: | |
12877 | return "DW_OP_xor"; | |
12878 | case DW_OP_bra: | |
12879 | return "DW_OP_bra"; | |
12880 | case DW_OP_eq: | |
12881 | return "DW_OP_eq"; | |
12882 | case DW_OP_ge: | |
12883 | return "DW_OP_ge"; | |
12884 | case DW_OP_gt: | |
12885 | return "DW_OP_gt"; | |
12886 | case DW_OP_le: | |
12887 | return "DW_OP_le"; | |
12888 | case DW_OP_lt: | |
12889 | return "DW_OP_lt"; | |
12890 | case DW_OP_ne: | |
12891 | return "DW_OP_ne"; | |
12892 | case DW_OP_skip: | |
12893 | return "DW_OP_skip"; | |
12894 | case DW_OP_lit0: | |
12895 | return "DW_OP_lit0"; | |
12896 | case DW_OP_lit1: | |
12897 | return "DW_OP_lit1"; | |
12898 | case DW_OP_lit2: | |
12899 | return "DW_OP_lit2"; | |
12900 | case DW_OP_lit3: | |
12901 | return "DW_OP_lit3"; | |
12902 | case DW_OP_lit4: | |
12903 | return "DW_OP_lit4"; | |
12904 | case DW_OP_lit5: | |
12905 | return "DW_OP_lit5"; | |
12906 | case DW_OP_lit6: | |
12907 | return "DW_OP_lit6"; | |
12908 | case DW_OP_lit7: | |
12909 | return "DW_OP_lit7"; | |
12910 | case DW_OP_lit8: | |
12911 | return "DW_OP_lit8"; | |
12912 | case DW_OP_lit9: | |
12913 | return "DW_OP_lit9"; | |
12914 | case DW_OP_lit10: | |
12915 | return "DW_OP_lit10"; | |
12916 | case DW_OP_lit11: | |
12917 | return "DW_OP_lit11"; | |
12918 | case DW_OP_lit12: | |
12919 | return "DW_OP_lit12"; | |
12920 | case DW_OP_lit13: | |
12921 | return "DW_OP_lit13"; | |
12922 | case DW_OP_lit14: | |
12923 | return "DW_OP_lit14"; | |
12924 | case DW_OP_lit15: | |
12925 | return "DW_OP_lit15"; | |
12926 | case DW_OP_lit16: | |
12927 | return "DW_OP_lit16"; | |
12928 | case DW_OP_lit17: | |
12929 | return "DW_OP_lit17"; | |
12930 | case DW_OP_lit18: | |
12931 | return "DW_OP_lit18"; | |
12932 | case DW_OP_lit19: | |
12933 | return "DW_OP_lit19"; | |
12934 | case DW_OP_lit20: | |
12935 | return "DW_OP_lit20"; | |
12936 | case DW_OP_lit21: | |
12937 | return "DW_OP_lit21"; | |
12938 | case DW_OP_lit22: | |
12939 | return "DW_OP_lit22"; | |
12940 | case DW_OP_lit23: | |
12941 | return "DW_OP_lit23"; | |
12942 | case DW_OP_lit24: | |
12943 | return "DW_OP_lit24"; | |
12944 | case DW_OP_lit25: | |
12945 | return "DW_OP_lit25"; | |
12946 | case DW_OP_lit26: | |
12947 | return "DW_OP_lit26"; | |
12948 | case DW_OP_lit27: | |
12949 | return "DW_OP_lit27"; | |
12950 | case DW_OP_lit28: | |
12951 | return "DW_OP_lit28"; | |
12952 | case DW_OP_lit29: | |
12953 | return "DW_OP_lit29"; | |
12954 | case DW_OP_lit30: | |
12955 | return "DW_OP_lit30"; | |
12956 | case DW_OP_lit31: | |
12957 | return "DW_OP_lit31"; | |
12958 | case DW_OP_reg0: | |
12959 | return "DW_OP_reg0"; | |
12960 | case DW_OP_reg1: | |
12961 | return "DW_OP_reg1"; | |
12962 | case DW_OP_reg2: | |
12963 | return "DW_OP_reg2"; | |
12964 | case DW_OP_reg3: | |
12965 | return "DW_OP_reg3"; | |
12966 | case DW_OP_reg4: | |
12967 | return "DW_OP_reg4"; | |
12968 | case DW_OP_reg5: | |
12969 | return "DW_OP_reg5"; | |
12970 | case DW_OP_reg6: | |
12971 | return "DW_OP_reg6"; | |
12972 | case DW_OP_reg7: | |
12973 | return "DW_OP_reg7"; | |
12974 | case DW_OP_reg8: | |
12975 | return "DW_OP_reg8"; | |
12976 | case DW_OP_reg9: | |
12977 | return "DW_OP_reg9"; | |
12978 | case DW_OP_reg10: | |
12979 | return "DW_OP_reg10"; | |
12980 | case DW_OP_reg11: | |
12981 | return "DW_OP_reg11"; | |
12982 | case DW_OP_reg12: | |
12983 | return "DW_OP_reg12"; | |
12984 | case DW_OP_reg13: | |
12985 | return "DW_OP_reg13"; | |
12986 | case DW_OP_reg14: | |
12987 | return "DW_OP_reg14"; | |
12988 | case DW_OP_reg15: | |
12989 | return "DW_OP_reg15"; | |
12990 | case DW_OP_reg16: | |
12991 | return "DW_OP_reg16"; | |
12992 | case DW_OP_reg17: | |
12993 | return "DW_OP_reg17"; | |
12994 | case DW_OP_reg18: | |
12995 | return "DW_OP_reg18"; | |
12996 | case DW_OP_reg19: | |
12997 | return "DW_OP_reg19"; | |
12998 | case DW_OP_reg20: | |
12999 | return "DW_OP_reg20"; | |
13000 | case DW_OP_reg21: | |
13001 | return "DW_OP_reg21"; | |
13002 | case DW_OP_reg22: | |
13003 | return "DW_OP_reg22"; | |
13004 | case DW_OP_reg23: | |
13005 | return "DW_OP_reg23"; | |
13006 | case DW_OP_reg24: | |
13007 | return "DW_OP_reg24"; | |
13008 | case DW_OP_reg25: | |
13009 | return "DW_OP_reg25"; | |
13010 | case DW_OP_reg26: | |
13011 | return "DW_OP_reg26"; | |
13012 | case DW_OP_reg27: | |
13013 | return "DW_OP_reg27"; | |
13014 | case DW_OP_reg28: | |
13015 | return "DW_OP_reg28"; | |
13016 | case DW_OP_reg29: | |
13017 | return "DW_OP_reg29"; | |
13018 | case DW_OP_reg30: | |
13019 | return "DW_OP_reg30"; | |
13020 | case DW_OP_reg31: | |
13021 | return "DW_OP_reg31"; | |
13022 | case DW_OP_breg0: | |
13023 | return "DW_OP_breg0"; | |
13024 | case DW_OP_breg1: | |
13025 | return "DW_OP_breg1"; | |
13026 | case DW_OP_breg2: | |
13027 | return "DW_OP_breg2"; | |
13028 | case DW_OP_breg3: | |
13029 | return "DW_OP_breg3"; | |
13030 | case DW_OP_breg4: | |
13031 | return "DW_OP_breg4"; | |
13032 | case DW_OP_breg5: | |
13033 | return "DW_OP_breg5"; | |
13034 | case DW_OP_breg6: | |
13035 | return "DW_OP_breg6"; | |
13036 | case DW_OP_breg7: | |
13037 | return "DW_OP_breg7"; | |
13038 | case DW_OP_breg8: | |
13039 | return "DW_OP_breg8"; | |
13040 | case DW_OP_breg9: | |
13041 | return "DW_OP_breg9"; | |
13042 | case DW_OP_breg10: | |
13043 | return "DW_OP_breg10"; | |
13044 | case DW_OP_breg11: | |
13045 | return "DW_OP_breg11"; | |
13046 | case DW_OP_breg12: | |
13047 | return "DW_OP_breg12"; | |
13048 | case DW_OP_breg13: | |
13049 | return "DW_OP_breg13"; | |
13050 | case DW_OP_breg14: | |
13051 | return "DW_OP_breg14"; | |
13052 | case DW_OP_breg15: | |
13053 | return "DW_OP_breg15"; | |
13054 | case DW_OP_breg16: | |
13055 | return "DW_OP_breg16"; | |
13056 | case DW_OP_breg17: | |
13057 | return "DW_OP_breg17"; | |
13058 | case DW_OP_breg18: | |
13059 | return "DW_OP_breg18"; | |
13060 | case DW_OP_breg19: | |
13061 | return "DW_OP_breg19"; | |
13062 | case DW_OP_breg20: | |
13063 | return "DW_OP_breg20"; | |
13064 | case DW_OP_breg21: | |
13065 | return "DW_OP_breg21"; | |
13066 | case DW_OP_breg22: | |
13067 | return "DW_OP_breg22"; | |
13068 | case DW_OP_breg23: | |
13069 | return "DW_OP_breg23"; | |
13070 | case DW_OP_breg24: | |
13071 | return "DW_OP_breg24"; | |
13072 | case DW_OP_breg25: | |
13073 | return "DW_OP_breg25"; | |
13074 | case DW_OP_breg26: | |
13075 | return "DW_OP_breg26"; | |
13076 | case DW_OP_breg27: | |
13077 | return "DW_OP_breg27"; | |
13078 | case DW_OP_breg28: | |
13079 | return "DW_OP_breg28"; | |
13080 | case DW_OP_breg29: | |
13081 | return "DW_OP_breg29"; | |
13082 | case DW_OP_breg30: | |
13083 | return "DW_OP_breg30"; | |
13084 | case DW_OP_breg31: | |
13085 | return "DW_OP_breg31"; | |
13086 | case DW_OP_regx: | |
13087 | return "DW_OP_regx"; | |
13088 | case DW_OP_fbreg: | |
13089 | return "DW_OP_fbreg"; | |
13090 | case DW_OP_bregx: | |
13091 | return "DW_OP_bregx"; | |
13092 | case DW_OP_piece: | |
13093 | return "DW_OP_piece"; | |
13094 | case DW_OP_deref_size: | |
13095 | return "DW_OP_deref_size"; | |
13096 | case DW_OP_xderef_size: | |
13097 | return "DW_OP_xderef_size"; | |
13098 | case DW_OP_nop: | |
13099 | return "DW_OP_nop"; | |
b7619582 | 13100 | /* DWARF 3 extensions. */ |
ed348acc EZ |
13101 | case DW_OP_push_object_address: |
13102 | return "DW_OP_push_object_address"; | |
13103 | case DW_OP_call2: | |
13104 | return "DW_OP_call2"; | |
13105 | case DW_OP_call4: | |
13106 | return "DW_OP_call4"; | |
13107 | case DW_OP_call_ref: | |
13108 | return "DW_OP_call_ref"; | |
b7619582 GF |
13109 | case DW_OP_form_tls_address: |
13110 | return "DW_OP_form_tls_address"; | |
13111 | case DW_OP_call_frame_cfa: | |
13112 | return "DW_OP_call_frame_cfa"; | |
13113 | case DW_OP_bit_piece: | |
13114 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
13115 | /* DWARF 4 extensions. */ |
13116 | case DW_OP_implicit_value: | |
13117 | return "DW_OP_implicit_value"; | |
13118 | case DW_OP_stack_value: | |
13119 | return "DW_OP_stack_value"; | |
13120 | /* GNU extensions. */ | |
ed348acc EZ |
13121 | case DW_OP_GNU_push_tls_address: |
13122 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
13123 | case DW_OP_GNU_uninit: |
13124 | return "DW_OP_GNU_uninit"; | |
8cf6f0b1 TT |
13125 | case DW_OP_GNU_implicit_pointer: |
13126 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
13127 | case DW_OP_GNU_entry_value: |
13128 | return "DW_OP_GNU_entry_value"; | |
13129 | case DW_OP_GNU_const_type: | |
13130 | return "DW_OP_GNU_const_type"; | |
13131 | case DW_OP_GNU_regval_type: | |
13132 | return "DW_OP_GNU_regval_type"; | |
13133 | case DW_OP_GNU_deref_type: | |
13134 | return "DW_OP_GNU_deref_type"; | |
13135 | case DW_OP_GNU_convert: | |
13136 | return "DW_OP_GNU_convert"; | |
13137 | case DW_OP_GNU_reinterpret: | |
13138 | return "DW_OP_GNU_reinterpret"; | |
c906108c | 13139 | default: |
b1bfef65 | 13140 | return NULL; |
c906108c SS |
13141 | } |
13142 | } | |
13143 | ||
13144 | static char * | |
fba45db2 | 13145 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
13146 | { |
13147 | if (mybool) | |
13148 | return "TRUE"; | |
13149 | else | |
13150 | return "FALSE"; | |
13151 | } | |
13152 | ||
13153 | /* Convert a DWARF type code into its string name. */ | |
13154 | ||
13155 | static char * | |
aa1ee363 | 13156 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
13157 | { |
13158 | switch (enc) | |
13159 | { | |
b7619582 GF |
13160 | case DW_ATE_void: |
13161 | return "DW_ATE_void"; | |
c906108c SS |
13162 | case DW_ATE_address: |
13163 | return "DW_ATE_address"; | |
13164 | case DW_ATE_boolean: | |
13165 | return "DW_ATE_boolean"; | |
13166 | case DW_ATE_complex_float: | |
13167 | return "DW_ATE_complex_float"; | |
13168 | case DW_ATE_float: | |
13169 | return "DW_ATE_float"; | |
13170 | case DW_ATE_signed: | |
13171 | return "DW_ATE_signed"; | |
13172 | case DW_ATE_signed_char: | |
13173 | return "DW_ATE_signed_char"; | |
13174 | case DW_ATE_unsigned: | |
13175 | return "DW_ATE_unsigned"; | |
13176 | case DW_ATE_unsigned_char: | |
13177 | return "DW_ATE_unsigned_char"; | |
b7619582 | 13178 | /* DWARF 3. */ |
d9fa45fe DC |
13179 | case DW_ATE_imaginary_float: |
13180 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
13181 | case DW_ATE_packed_decimal: |
13182 | return "DW_ATE_packed_decimal"; | |
13183 | case DW_ATE_numeric_string: | |
13184 | return "DW_ATE_numeric_string"; | |
13185 | case DW_ATE_edited: | |
13186 | return "DW_ATE_edited"; | |
13187 | case DW_ATE_signed_fixed: | |
13188 | return "DW_ATE_signed_fixed"; | |
13189 | case DW_ATE_unsigned_fixed: | |
13190 | return "DW_ATE_unsigned_fixed"; | |
13191 | case DW_ATE_decimal_float: | |
13192 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
13193 | /* DWARF 4. */ |
13194 | case DW_ATE_UTF: | |
13195 | return "DW_ATE_UTF"; | |
b7619582 GF |
13196 | /* HP extensions. */ |
13197 | case DW_ATE_HP_float80: | |
13198 | return "DW_ATE_HP_float80"; | |
13199 | case DW_ATE_HP_complex_float80: | |
13200 | return "DW_ATE_HP_complex_float80"; | |
13201 | case DW_ATE_HP_float128: | |
13202 | return "DW_ATE_HP_float128"; | |
13203 | case DW_ATE_HP_complex_float128: | |
13204 | return "DW_ATE_HP_complex_float128"; | |
13205 | case DW_ATE_HP_floathpintel: | |
13206 | return "DW_ATE_HP_floathpintel"; | |
13207 | case DW_ATE_HP_imaginary_float80: | |
13208 | return "DW_ATE_HP_imaginary_float80"; | |
13209 | case DW_ATE_HP_imaginary_float128: | |
13210 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
13211 | default: |
13212 | return "DW_ATE_<unknown>"; | |
13213 | } | |
13214 | } | |
13215 | ||
0963b4bd | 13216 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
13217 | |
13218 | #if 0 | |
13219 | static char * | |
aa1ee363 | 13220 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
13221 | { |
13222 | switch (cfi_opc) | |
13223 | { | |
13224 | case DW_CFA_advance_loc: | |
13225 | return "DW_CFA_advance_loc"; | |
13226 | case DW_CFA_offset: | |
13227 | return "DW_CFA_offset"; | |
13228 | case DW_CFA_restore: | |
13229 | return "DW_CFA_restore"; | |
13230 | case DW_CFA_nop: | |
13231 | return "DW_CFA_nop"; | |
13232 | case DW_CFA_set_loc: | |
13233 | return "DW_CFA_set_loc"; | |
13234 | case DW_CFA_advance_loc1: | |
13235 | return "DW_CFA_advance_loc1"; | |
13236 | case DW_CFA_advance_loc2: | |
13237 | return "DW_CFA_advance_loc2"; | |
13238 | case DW_CFA_advance_loc4: | |
13239 | return "DW_CFA_advance_loc4"; | |
13240 | case DW_CFA_offset_extended: | |
13241 | return "DW_CFA_offset_extended"; | |
13242 | case DW_CFA_restore_extended: | |
13243 | return "DW_CFA_restore_extended"; | |
13244 | case DW_CFA_undefined: | |
13245 | return "DW_CFA_undefined"; | |
13246 | case DW_CFA_same_value: | |
13247 | return "DW_CFA_same_value"; | |
13248 | case DW_CFA_register: | |
13249 | return "DW_CFA_register"; | |
13250 | case DW_CFA_remember_state: | |
13251 | return "DW_CFA_remember_state"; | |
13252 | case DW_CFA_restore_state: | |
13253 | return "DW_CFA_restore_state"; | |
13254 | case DW_CFA_def_cfa: | |
13255 | return "DW_CFA_def_cfa"; | |
13256 | case DW_CFA_def_cfa_register: | |
13257 | return "DW_CFA_def_cfa_register"; | |
13258 | case DW_CFA_def_cfa_offset: | |
13259 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 13260 | /* DWARF 3. */ |
985cb1a3 JM |
13261 | case DW_CFA_def_cfa_expression: |
13262 | return "DW_CFA_def_cfa_expression"; | |
13263 | case DW_CFA_expression: | |
13264 | return "DW_CFA_expression"; | |
13265 | case DW_CFA_offset_extended_sf: | |
13266 | return "DW_CFA_offset_extended_sf"; | |
13267 | case DW_CFA_def_cfa_sf: | |
13268 | return "DW_CFA_def_cfa_sf"; | |
13269 | case DW_CFA_def_cfa_offset_sf: | |
13270 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
13271 | case DW_CFA_val_offset: |
13272 | return "DW_CFA_val_offset"; | |
13273 | case DW_CFA_val_offset_sf: | |
13274 | return "DW_CFA_val_offset_sf"; | |
13275 | case DW_CFA_val_expression: | |
13276 | return "DW_CFA_val_expression"; | |
13277 | /* SGI/MIPS specific. */ | |
c906108c SS |
13278 | case DW_CFA_MIPS_advance_loc8: |
13279 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 13280 | /* GNU extensions. */ |
985cb1a3 JM |
13281 | case DW_CFA_GNU_window_save: |
13282 | return "DW_CFA_GNU_window_save"; | |
13283 | case DW_CFA_GNU_args_size: | |
13284 | return "DW_CFA_GNU_args_size"; | |
13285 | case DW_CFA_GNU_negative_offset_extended: | |
13286 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
13287 | default: |
13288 | return "DW_CFA_<unknown>"; | |
13289 | } | |
13290 | } | |
13291 | #endif | |
13292 | ||
f9aca02d | 13293 | static void |
d97bc12b | 13294 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
13295 | { |
13296 | unsigned int i; | |
13297 | ||
d97bc12b DE |
13298 | print_spaces (indent, f); |
13299 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 13300 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
13301 | |
13302 | if (die->parent != NULL) | |
13303 | { | |
13304 | print_spaces (indent, f); | |
13305 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
13306 | die->parent->offset); | |
13307 | } | |
13308 | ||
13309 | print_spaces (indent, f); | |
13310 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 13311 | dwarf_bool_name (die->child != NULL)); |
c906108c | 13312 | |
d97bc12b DE |
13313 | print_spaces (indent, f); |
13314 | fprintf_unfiltered (f, " attributes:\n"); | |
13315 | ||
c906108c SS |
13316 | for (i = 0; i < die->num_attrs; ++i) |
13317 | { | |
d97bc12b DE |
13318 | print_spaces (indent, f); |
13319 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
13320 | dwarf_attr_name (die->attrs[i].name), |
13321 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 13322 | |
c906108c SS |
13323 | switch (die->attrs[i].form) |
13324 | { | |
13325 | case DW_FORM_ref_addr: | |
13326 | case DW_FORM_addr: | |
d97bc12b | 13327 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 13328 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
13329 | break; |
13330 | case DW_FORM_block2: | |
13331 | case DW_FORM_block4: | |
13332 | case DW_FORM_block: | |
13333 | case DW_FORM_block1: | |
3e43a32a MS |
13334 | fprintf_unfiltered (f, "block: size %d", |
13335 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 13336 | break; |
2dc7f7b3 TT |
13337 | case DW_FORM_exprloc: |
13338 | fprintf_unfiltered (f, "expression: size %u", | |
13339 | DW_BLOCK (&die->attrs[i])->size); | |
13340 | break; | |
10b3939b DJ |
13341 | case DW_FORM_ref1: |
13342 | case DW_FORM_ref2: | |
13343 | case DW_FORM_ref4: | |
d97bc12b | 13344 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
13345 | (long) (DW_ADDR (&die->attrs[i]))); |
13346 | break; | |
c906108c SS |
13347 | case DW_FORM_data1: |
13348 | case DW_FORM_data2: | |
13349 | case DW_FORM_data4: | |
ce5d95e1 | 13350 | case DW_FORM_data8: |
c906108c SS |
13351 | case DW_FORM_udata: |
13352 | case DW_FORM_sdata: | |
43bbcdc2 PH |
13353 | fprintf_unfiltered (f, "constant: %s", |
13354 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 13355 | break; |
2dc7f7b3 TT |
13356 | case DW_FORM_sec_offset: |
13357 | fprintf_unfiltered (f, "section offset: %s", | |
13358 | pulongest (DW_UNSND (&die->attrs[i]))); | |
13359 | break; | |
55f1336d | 13360 | case DW_FORM_ref_sig8: |
348e048f DE |
13361 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
13362 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b3c8eb43 | 13363 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset); |
348e048f DE |
13364 | else |
13365 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
13366 | break; | |
c906108c | 13367 | case DW_FORM_string: |
4bdf3d34 | 13368 | case DW_FORM_strp: |
8285870a | 13369 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 13370 | DW_STRING (&die->attrs[i]) |
8285870a JK |
13371 | ? DW_STRING (&die->attrs[i]) : "", |
13372 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
13373 | break; |
13374 | case DW_FORM_flag: | |
13375 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 13376 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 13377 | else |
d97bc12b | 13378 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 13379 | break; |
2dc7f7b3 TT |
13380 | case DW_FORM_flag_present: |
13381 | fprintf_unfiltered (f, "flag: TRUE"); | |
13382 | break; | |
a8329558 | 13383 | case DW_FORM_indirect: |
0963b4bd MS |
13384 | /* The reader will have reduced the indirect form to |
13385 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
13386 | fprintf_unfiltered (f, |
13387 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 13388 | break; |
c906108c | 13389 | default: |
d97bc12b | 13390 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 13391 | die->attrs[i].form); |
d97bc12b | 13392 | break; |
c906108c | 13393 | } |
d97bc12b | 13394 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
13395 | } |
13396 | } | |
13397 | ||
f9aca02d | 13398 | static void |
d97bc12b | 13399 | dump_die_for_error (struct die_info *die) |
c906108c | 13400 | { |
d97bc12b DE |
13401 | dump_die_shallow (gdb_stderr, 0, die); |
13402 | } | |
13403 | ||
13404 | static void | |
13405 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
13406 | { | |
13407 | int indent = level * 4; | |
13408 | ||
13409 | gdb_assert (die != NULL); | |
13410 | ||
13411 | if (level >= max_level) | |
13412 | return; | |
13413 | ||
13414 | dump_die_shallow (f, indent, die); | |
13415 | ||
13416 | if (die->child != NULL) | |
c906108c | 13417 | { |
d97bc12b DE |
13418 | print_spaces (indent, f); |
13419 | fprintf_unfiltered (f, " Children:"); | |
13420 | if (level + 1 < max_level) | |
13421 | { | |
13422 | fprintf_unfiltered (f, "\n"); | |
13423 | dump_die_1 (f, level + 1, max_level, die->child); | |
13424 | } | |
13425 | else | |
13426 | { | |
3e43a32a MS |
13427 | fprintf_unfiltered (f, |
13428 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
13429 | } |
13430 | } | |
13431 | ||
13432 | if (die->sibling != NULL && level > 0) | |
13433 | { | |
13434 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
13435 | } |
13436 | } | |
13437 | ||
d97bc12b DE |
13438 | /* This is called from the pdie macro in gdbinit.in. |
13439 | It's not static so gcc will keep a copy callable from gdb. */ | |
13440 | ||
13441 | void | |
13442 | dump_die (struct die_info *die, int max_level) | |
13443 | { | |
13444 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
13445 | } | |
13446 | ||
f9aca02d | 13447 | static void |
51545339 | 13448 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13449 | { |
51545339 | 13450 | void **slot; |
c906108c | 13451 | |
51545339 DJ |
13452 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
13453 | ||
13454 | *slot = die; | |
c906108c SS |
13455 | } |
13456 | ||
93311388 DE |
13457 | static int |
13458 | is_ref_attr (struct attribute *attr) | |
c906108c | 13459 | { |
c906108c SS |
13460 | switch (attr->form) |
13461 | { | |
13462 | case DW_FORM_ref_addr: | |
c906108c SS |
13463 | case DW_FORM_ref1: |
13464 | case DW_FORM_ref2: | |
13465 | case DW_FORM_ref4: | |
613e1657 | 13466 | case DW_FORM_ref8: |
c906108c | 13467 | case DW_FORM_ref_udata: |
93311388 | 13468 | return 1; |
c906108c | 13469 | default: |
93311388 | 13470 | return 0; |
c906108c | 13471 | } |
93311388 DE |
13472 | } |
13473 | ||
13474 | static unsigned int | |
13475 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
13476 | { | |
13477 | if (is_ref_attr (attr)) | |
13478 | return DW_ADDR (attr); | |
13479 | ||
13480 | complaint (&symfile_complaints, | |
13481 | _("unsupported die ref attribute form: '%s'"), | |
13482 | dwarf_form_name (attr->form)); | |
13483 | return 0; | |
c906108c SS |
13484 | } |
13485 | ||
43bbcdc2 PH |
13486 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
13487 | * the value held by the attribute is not constant. */ | |
a02abb62 | 13488 | |
43bbcdc2 | 13489 | static LONGEST |
a02abb62 JB |
13490 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
13491 | { | |
13492 | if (attr->form == DW_FORM_sdata) | |
13493 | return DW_SND (attr); | |
13494 | else if (attr->form == DW_FORM_udata | |
13495 | || attr->form == DW_FORM_data1 | |
13496 | || attr->form == DW_FORM_data2 | |
13497 | || attr->form == DW_FORM_data4 | |
13498 | || attr->form == DW_FORM_data8) | |
13499 | return DW_UNSND (attr); | |
13500 | else | |
13501 | { | |
3e43a32a MS |
13502 | complaint (&symfile_complaints, |
13503 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
13504 | dwarf_form_name (attr->form)); |
13505 | return default_value; | |
13506 | } | |
13507 | } | |
13508 | ||
03dd20cc | 13509 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
13510 | unit and add it to our queue. |
13511 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
13512 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 13513 | |
348e048f | 13514 | static int |
03dd20cc DJ |
13515 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
13516 | struct dwarf2_per_cu_data *per_cu) | |
13517 | { | |
98bfdba5 PA |
13518 | /* We may arrive here during partial symbol reading, if we need full |
13519 | DIEs to process an unusual case (e.g. template arguments). Do | |
13520 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
13521 | if (dwarf2_per_objfile->reading_partial_symbols) | |
13522 | { | |
13523 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
13524 | return 1; | |
13525 | return 0; | |
13526 | } | |
13527 | ||
03dd20cc DJ |
13528 | /* Mark the dependence relation so that we don't flush PER_CU |
13529 | too early. */ | |
13530 | dwarf2_add_dependence (this_cu, per_cu); | |
13531 | ||
13532 | /* If it's already on the queue, we have nothing to do. */ | |
13533 | if (per_cu->queued) | |
348e048f | 13534 | return 0; |
03dd20cc DJ |
13535 | |
13536 | /* If the compilation unit is already loaded, just mark it as | |
13537 | used. */ | |
13538 | if (per_cu->cu != NULL) | |
13539 | { | |
13540 | per_cu->cu->last_used = 0; | |
348e048f | 13541 | return 0; |
03dd20cc DJ |
13542 | } |
13543 | ||
13544 | /* Add it to the queue. */ | |
13545 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
13546 | |
13547 | return 1; | |
13548 | } | |
13549 | ||
13550 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
13551 | On entry *REF_CU is the CU of SRC_DIE. | |
13552 | On exit *REF_CU is the CU of the result. */ | |
13553 | ||
13554 | static struct die_info * | |
13555 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
13556 | struct dwarf2_cu **ref_cu) | |
13557 | { | |
13558 | struct die_info *die; | |
13559 | ||
13560 | if (is_ref_attr (attr)) | |
13561 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 13562 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
13563 | die = follow_die_sig (src_die, attr, ref_cu); |
13564 | else | |
13565 | { | |
13566 | dump_die_for_error (src_die); | |
13567 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
13568 | (*ref_cu)->objfile->name); | |
13569 | } | |
13570 | ||
13571 | return die; | |
03dd20cc DJ |
13572 | } |
13573 | ||
5c631832 | 13574 | /* Follow reference OFFSET. |
673bfd45 DE |
13575 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
13576 | On exit *REF_CU is the CU of the result. | |
13577 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 13578 | |
f9aca02d | 13579 | static struct die_info * |
5c631832 | 13580 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 13581 | { |
10b3939b | 13582 | struct die_info temp_die; |
f2f0e013 | 13583 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 13584 | |
348e048f DE |
13585 | gdb_assert (cu->per_cu != NULL); |
13586 | ||
98bfdba5 PA |
13587 | target_cu = cu; |
13588 | ||
348e048f DE |
13589 | if (cu->per_cu->from_debug_types) |
13590 | { | |
13591 | /* .debug_types CUs cannot reference anything outside their CU. | |
13592 | If they need to, they have to reference a signatured type via | |
55f1336d | 13593 | DW_FORM_ref_sig8. */ |
348e048f | 13594 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 13595 | return NULL; |
348e048f DE |
13596 | } |
13597 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
13598 | { |
13599 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 13600 | |
45452591 | 13601 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
13602 | |
13603 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
13604 | if (maybe_queue_comp_unit (cu, per_cu)) |
13605 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 13606 | |
10b3939b DJ |
13607 | target_cu = per_cu->cu; |
13608 | } | |
98bfdba5 PA |
13609 | else if (cu->dies == NULL) |
13610 | { | |
13611 | /* We're loading full DIEs during partial symbol reading. */ | |
13612 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
13613 | load_full_comp_unit (cu->per_cu, cu->objfile); | |
13614 | } | |
c906108c | 13615 | |
f2f0e013 | 13616 | *ref_cu = target_cu; |
51545339 | 13617 | temp_die.offset = offset; |
5c631832 JK |
13618 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
13619 | } | |
10b3939b | 13620 | |
5c631832 JK |
13621 | /* Follow reference attribute ATTR of SRC_DIE. |
13622 | On entry *REF_CU is the CU of SRC_DIE. | |
13623 | On exit *REF_CU is the CU of the result. */ | |
13624 | ||
13625 | static struct die_info * | |
13626 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
13627 | struct dwarf2_cu **ref_cu) | |
13628 | { | |
13629 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
13630 | struct dwarf2_cu *cu = *ref_cu; | |
13631 | struct die_info *die; | |
13632 | ||
13633 | die = follow_die_offset (offset, ref_cu); | |
13634 | if (!die) | |
13635 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
13636 | "at 0x%x [in module %s]"), | |
13637 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 13638 | |
5c631832 JK |
13639 | return die; |
13640 | } | |
13641 | ||
13642 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned | |
13643 | value is intended for DW_OP_call*. */ | |
13644 | ||
13645 | struct dwarf2_locexpr_baton | |
13646 | dwarf2_fetch_die_location_block (unsigned int offset, | |
8cf6f0b1 TT |
13647 | struct dwarf2_per_cu_data *per_cu, |
13648 | CORE_ADDR (*get_frame_pc) (void *baton), | |
13649 | void *baton) | |
5c631832 JK |
13650 | { |
13651 | struct dwarf2_cu *cu = per_cu->cu; | |
13652 | struct die_info *die; | |
13653 | struct attribute *attr; | |
13654 | struct dwarf2_locexpr_baton retval; | |
13655 | ||
8cf6f0b1 TT |
13656 | dw2_setup (per_cu->objfile); |
13657 | ||
5c631832 JK |
13658 | die = follow_die_offset (offset, &cu); |
13659 | if (!die) | |
13660 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
13661 | offset, per_cu->cu->objfile->name); | |
13662 | ||
13663 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
13664 | if (!attr) | |
13665 | { | |
13666 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
13667 | ||
13668 | retval.data = NULL; | |
13669 | retval.size = 0; | |
13670 | } | |
8cf6f0b1 TT |
13671 | else if (attr_form_is_section_offset (attr)) |
13672 | { | |
13673 | struct dwarf2_loclist_baton loclist_baton; | |
13674 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
13675 | size_t size; | |
13676 | ||
13677 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
13678 | ||
13679 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
13680 | &size, pc); | |
13681 | retval.size = size; | |
13682 | } | |
5c631832 JK |
13683 | else |
13684 | { | |
13685 | if (!attr_form_is_block (attr)) | |
13686 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
13687 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
13688 | offset, per_cu->cu->objfile->name); | |
13689 | ||
13690 | retval.data = DW_BLOCK (attr)->data; | |
13691 | retval.size = DW_BLOCK (attr)->size; | |
13692 | } | |
13693 | retval.per_cu = cu->per_cu; | |
13694 | return retval; | |
348e048f DE |
13695 | } |
13696 | ||
8a9b8146 TT |
13697 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
13698 | PER_CU. */ | |
13699 | ||
13700 | struct type * | |
13701 | dwarf2_get_die_type (unsigned int die_offset, | |
13702 | struct dwarf2_per_cu_data *per_cu) | |
13703 | { | |
8a9b8146 | 13704 | dw2_setup (per_cu->objfile); |
9ff3b74f | 13705 | return get_die_type_at_offset (die_offset, per_cu); |
8a9b8146 TT |
13706 | } |
13707 | ||
348e048f DE |
13708 | /* Follow the signature attribute ATTR in SRC_DIE. |
13709 | On entry *REF_CU is the CU of SRC_DIE. | |
13710 | On exit *REF_CU is the CU of the result. */ | |
13711 | ||
13712 | static struct die_info * | |
13713 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
13714 | struct dwarf2_cu **ref_cu) | |
13715 | { | |
13716 | struct objfile *objfile = (*ref_cu)->objfile; | |
13717 | struct die_info temp_die; | |
13718 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
13719 | struct dwarf2_cu *sig_cu; | |
13720 | struct die_info *die; | |
13721 | ||
13722 | /* sig_type will be NULL if the signatured type is missing from | |
13723 | the debug info. */ | |
13724 | if (sig_type == NULL) | |
13725 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
13726 | "at 0x%x [in module %s]"), | |
13727 | src_die->offset, objfile->name); | |
13728 | ||
13729 | /* If necessary, add it to the queue and load its DIEs. */ | |
13730 | ||
13731 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
13732 | read_signatured_type (objfile, sig_type); | |
13733 | ||
13734 | gdb_assert (sig_type->per_cu.cu != NULL); | |
13735 | ||
13736 | sig_cu = sig_type->per_cu.cu; | |
13737 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
13738 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
13739 | if (die) | |
13740 | { | |
13741 | *ref_cu = sig_cu; | |
13742 | return die; | |
13743 | } | |
13744 | ||
3e43a32a MS |
13745 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
13746 | "from DIE at 0x%x [in module %s]"), | |
348e048f DE |
13747 | sig_type->type_offset, src_die->offset, objfile->name); |
13748 | } | |
13749 | ||
13750 | /* Given an offset of a signatured type, return its signatured_type. */ | |
13751 | ||
13752 | static struct signatured_type * | |
13753 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
13754 | { | |
13755 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
13756 | unsigned int length, initial_length_size; | |
13757 | unsigned int sig_offset; | |
13758 | struct signatured_type find_entry, *type_sig; | |
13759 | ||
13760 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
13761 | sig_offset = (initial_length_size | |
13762 | + 2 /*version*/ | |
13763 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
13764 | + 1 /*address_size*/); | |
13765 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
13766 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
13767 | ||
13768 | /* This is only used to lookup previously recorded types. | |
13769 | If we didn't find it, it's our bug. */ | |
13770 | gdb_assert (type_sig != NULL); | |
b3c8eb43 | 13771 | gdb_assert (offset == type_sig->per_cu.offset); |
348e048f DE |
13772 | |
13773 | return type_sig; | |
13774 | } | |
13775 | ||
13776 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
13777 | ||
13778 | static void | |
13779 | read_signatured_type_at_offset (struct objfile *objfile, | |
13780 | unsigned int offset) | |
13781 | { | |
13782 | struct signatured_type *type_sig; | |
13783 | ||
be391dca TT |
13784 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
13785 | ||
348e048f DE |
13786 | /* We have the section offset, but we need the signature to do the |
13787 | hash table lookup. */ | |
13788 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
13789 | ||
13790 | gdb_assert (type_sig->per_cu.cu == NULL); | |
13791 | ||
13792 | read_signatured_type (objfile, type_sig); | |
13793 | ||
13794 | gdb_assert (type_sig->per_cu.cu != NULL); | |
13795 | } | |
13796 | ||
13797 | /* Read in a signatured type and build its CU and DIEs. */ | |
13798 | ||
13799 | static void | |
13800 | read_signatured_type (struct objfile *objfile, | |
13801 | struct signatured_type *type_sig) | |
13802 | { | |
1fd400ff | 13803 | gdb_byte *types_ptr; |
348e048f DE |
13804 | struct die_reader_specs reader_specs; |
13805 | struct dwarf2_cu *cu; | |
13806 | ULONGEST signature; | |
13807 | struct cleanup *back_to, *free_cu_cleanup; | |
348e048f | 13808 | |
1fd400ff | 13809 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
b3c8eb43 | 13810 | types_ptr = dwarf2_per_objfile->types.buffer + type_sig->per_cu.offset; |
1fd400ff | 13811 | |
348e048f DE |
13812 | gdb_assert (type_sig->per_cu.cu == NULL); |
13813 | ||
9816fde3 JK |
13814 | cu = xmalloc (sizeof (*cu)); |
13815 | init_one_comp_unit (cu, objfile); | |
13816 | ||
348e048f DE |
13817 | type_sig->per_cu.cu = cu; |
13818 | cu->per_cu = &type_sig->per_cu; | |
13819 | ||
13820 | /* If an error occurs while loading, release our storage. */ | |
13821 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
13822 | ||
13823 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
13824 | types_ptr, objfile->obfd); | |
13825 | gdb_assert (signature == type_sig->signature); | |
13826 | ||
13827 | cu->die_hash | |
13828 | = htab_create_alloc_ex (cu->header.length / 12, | |
13829 | die_hash, | |
13830 | die_eq, | |
13831 | NULL, | |
13832 | &cu->comp_unit_obstack, | |
13833 | hashtab_obstack_allocate, | |
13834 | dummy_obstack_deallocate); | |
13835 | ||
13836 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
13837 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
13838 | ||
13839 | init_cu_die_reader (&reader_specs, cu); | |
13840 | ||
13841 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
13842 | NULL /*parent*/); | |
13843 | ||
13844 | /* We try not to read any attributes in this function, because not | |
13845 | all objfiles needed for references have been loaded yet, and symbol | |
13846 | table processing isn't initialized. But we have to set the CU language, | |
13847 | or we won't be able to build types correctly. */ | |
9816fde3 | 13848 | prepare_one_comp_unit (cu, cu->dies); |
348e048f DE |
13849 | |
13850 | do_cleanups (back_to); | |
13851 | ||
13852 | /* We've successfully allocated this compilation unit. Let our caller | |
13853 | clean it up when finished with it. */ | |
13854 | discard_cleanups (free_cu_cleanup); | |
13855 | ||
13856 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
13857 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
13858 | } |
13859 | ||
c906108c SS |
13860 | /* Decode simple location descriptions. |
13861 | Given a pointer to a dwarf block that defines a location, compute | |
13862 | the location and return the value. | |
13863 | ||
4cecd739 DJ |
13864 | NOTE drow/2003-11-18: This function is called in two situations |
13865 | now: for the address of static or global variables (partial symbols | |
13866 | only) and for offsets into structures which are expected to be | |
13867 | (more or less) constant. The partial symbol case should go away, | |
13868 | and only the constant case should remain. That will let this | |
13869 | function complain more accurately. A few special modes are allowed | |
13870 | without complaint for global variables (for instance, global | |
13871 | register values and thread-local values). | |
c906108c SS |
13872 | |
13873 | A location description containing no operations indicates that the | |
4cecd739 | 13874 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
13875 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
13876 | callers will only want a very basic result and this can become a | |
13877 | complaint. | |
c906108c | 13878 | |
d53d4ac5 | 13879 | Note that stack[0] is unused except as a default error return. */ |
c906108c SS |
13880 | |
13881 | static CORE_ADDR | |
e7c27a73 | 13882 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 13883 | { |
e7c27a73 | 13884 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13885 | int i; |
13886 | int size = blk->size; | |
fe1b8b76 | 13887 | gdb_byte *data = blk->data; |
c906108c SS |
13888 | CORE_ADDR stack[64]; |
13889 | int stacki; | |
13890 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 13891 | gdb_byte op; |
c906108c SS |
13892 | |
13893 | i = 0; | |
13894 | stacki = 0; | |
13895 | stack[stacki] = 0; | |
d53d4ac5 | 13896 | stack[++stacki] = 0; |
c906108c SS |
13897 | |
13898 | while (i < size) | |
13899 | { | |
c906108c SS |
13900 | op = data[i++]; |
13901 | switch (op) | |
13902 | { | |
f1bea926 JM |
13903 | case DW_OP_lit0: |
13904 | case DW_OP_lit1: | |
13905 | case DW_OP_lit2: | |
13906 | case DW_OP_lit3: | |
13907 | case DW_OP_lit4: | |
13908 | case DW_OP_lit5: | |
13909 | case DW_OP_lit6: | |
13910 | case DW_OP_lit7: | |
13911 | case DW_OP_lit8: | |
13912 | case DW_OP_lit9: | |
13913 | case DW_OP_lit10: | |
13914 | case DW_OP_lit11: | |
13915 | case DW_OP_lit12: | |
13916 | case DW_OP_lit13: | |
13917 | case DW_OP_lit14: | |
13918 | case DW_OP_lit15: | |
13919 | case DW_OP_lit16: | |
13920 | case DW_OP_lit17: | |
13921 | case DW_OP_lit18: | |
13922 | case DW_OP_lit19: | |
13923 | case DW_OP_lit20: | |
13924 | case DW_OP_lit21: | |
13925 | case DW_OP_lit22: | |
13926 | case DW_OP_lit23: | |
13927 | case DW_OP_lit24: | |
13928 | case DW_OP_lit25: | |
13929 | case DW_OP_lit26: | |
13930 | case DW_OP_lit27: | |
13931 | case DW_OP_lit28: | |
13932 | case DW_OP_lit29: | |
13933 | case DW_OP_lit30: | |
13934 | case DW_OP_lit31: | |
13935 | stack[++stacki] = op - DW_OP_lit0; | |
13936 | break; | |
13937 | ||
c906108c SS |
13938 | case DW_OP_reg0: |
13939 | case DW_OP_reg1: | |
13940 | case DW_OP_reg2: | |
13941 | case DW_OP_reg3: | |
13942 | case DW_OP_reg4: | |
13943 | case DW_OP_reg5: | |
13944 | case DW_OP_reg6: | |
13945 | case DW_OP_reg7: | |
13946 | case DW_OP_reg8: | |
13947 | case DW_OP_reg9: | |
13948 | case DW_OP_reg10: | |
13949 | case DW_OP_reg11: | |
13950 | case DW_OP_reg12: | |
13951 | case DW_OP_reg13: | |
13952 | case DW_OP_reg14: | |
13953 | case DW_OP_reg15: | |
13954 | case DW_OP_reg16: | |
13955 | case DW_OP_reg17: | |
13956 | case DW_OP_reg18: | |
13957 | case DW_OP_reg19: | |
13958 | case DW_OP_reg20: | |
13959 | case DW_OP_reg21: | |
13960 | case DW_OP_reg22: | |
13961 | case DW_OP_reg23: | |
13962 | case DW_OP_reg24: | |
13963 | case DW_OP_reg25: | |
13964 | case DW_OP_reg26: | |
13965 | case DW_OP_reg27: | |
13966 | case DW_OP_reg28: | |
13967 | case DW_OP_reg29: | |
13968 | case DW_OP_reg30: | |
13969 | case DW_OP_reg31: | |
c906108c | 13970 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
13971 | if (i < size) |
13972 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13973 | break; |
13974 | ||
13975 | case DW_OP_regx: | |
c906108c SS |
13976 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
13977 | i += bytes_read; | |
c906108c | 13978 | stack[++stacki] = unsnd; |
4cecd739 DJ |
13979 | if (i < size) |
13980 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13981 | break; |
13982 | ||
13983 | case DW_OP_addr: | |
107d2387 | 13984 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 13985 | cu, &bytes_read); |
107d2387 | 13986 | i += bytes_read; |
c906108c SS |
13987 | break; |
13988 | ||
13989 | case DW_OP_const1u: | |
13990 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
13991 | i += 1; | |
13992 | break; | |
13993 | ||
13994 | case DW_OP_const1s: | |
13995 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
13996 | i += 1; | |
13997 | break; | |
13998 | ||
13999 | case DW_OP_const2u: | |
14000 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
14001 | i += 2; | |
14002 | break; | |
14003 | ||
14004 | case DW_OP_const2s: | |
14005 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
14006 | i += 2; | |
14007 | break; | |
14008 | ||
14009 | case DW_OP_const4u: | |
14010 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
14011 | i += 4; | |
14012 | break; | |
14013 | ||
14014 | case DW_OP_const4s: | |
14015 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
14016 | i += 4; | |
14017 | break; | |
14018 | ||
14019 | case DW_OP_constu: | |
14020 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 14021 | &bytes_read); |
c906108c SS |
14022 | i += bytes_read; |
14023 | break; | |
14024 | ||
14025 | case DW_OP_consts: | |
14026 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
14027 | i += bytes_read; | |
14028 | break; | |
14029 | ||
f1bea926 JM |
14030 | case DW_OP_dup: |
14031 | stack[stacki + 1] = stack[stacki]; | |
14032 | stacki++; | |
14033 | break; | |
14034 | ||
c906108c SS |
14035 | case DW_OP_plus: |
14036 | stack[stacki - 1] += stack[stacki]; | |
14037 | stacki--; | |
14038 | break; | |
14039 | ||
14040 | case DW_OP_plus_uconst: | |
3e43a32a MS |
14041 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), |
14042 | &bytes_read); | |
c906108c SS |
14043 | i += bytes_read; |
14044 | break; | |
14045 | ||
14046 | case DW_OP_minus: | |
f1bea926 | 14047 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
14048 | stacki--; |
14049 | break; | |
14050 | ||
7a292a7a | 14051 | case DW_OP_deref: |
7a292a7a | 14052 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
14053 | this using GDB's address_class enum. This is valid for partial |
14054 | global symbols, although the variable's address will be bogus | |
14055 | in the psymtab. */ | |
7a292a7a | 14056 | if (i < size) |
4d3c2250 | 14057 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
14058 | break; |
14059 | ||
9d774e44 | 14060 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
14061 | /* The top of the stack has the offset from the beginning |
14062 | of the thread control block at which the variable is located. */ | |
14063 | /* Nothing should follow this operator, so the top of stack would | |
14064 | be returned. */ | |
4cecd739 DJ |
14065 | /* This is valid for partial global symbols, but the variable's |
14066 | address will be bogus in the psymtab. */ | |
9d774e44 | 14067 | if (i < size) |
4d3c2250 | 14068 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
14069 | break; |
14070 | ||
42be36b3 CT |
14071 | case DW_OP_GNU_uninit: |
14072 | break; | |
14073 | ||
c906108c | 14074 | default: |
b1bfef65 TT |
14075 | { |
14076 | const char *name = dwarf_stack_op_name (op); | |
14077 | ||
14078 | if (name) | |
14079 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
14080 | name); | |
14081 | else | |
14082 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
14083 | op); | |
14084 | } | |
14085 | ||
c906108c SS |
14086 | return (stack[stacki]); |
14087 | } | |
d53d4ac5 TT |
14088 | |
14089 | /* Enforce maximum stack depth of SIZE-1 to avoid writing | |
14090 | outside of the allocated space. Also enforce minimum>0. */ | |
14091 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
14092 | { | |
14093 | complaint (&symfile_complaints, | |
14094 | _("location description stack overflow")); | |
14095 | return 0; | |
14096 | } | |
14097 | ||
14098 | if (stacki <= 0) | |
14099 | { | |
14100 | complaint (&symfile_complaints, | |
14101 | _("location description stack underflow")); | |
14102 | return 0; | |
14103 | } | |
c906108c SS |
14104 | } |
14105 | return (stack[stacki]); | |
14106 | } | |
14107 | ||
14108 | /* memory allocation interface */ | |
14109 | ||
c906108c | 14110 | static struct dwarf_block * |
7b5a2f43 | 14111 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
14112 | { |
14113 | struct dwarf_block *blk; | |
14114 | ||
14115 | blk = (struct dwarf_block *) | |
7b5a2f43 | 14116 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
14117 | return (blk); |
14118 | } | |
14119 | ||
14120 | static struct abbrev_info * | |
f3dd6933 | 14121 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
14122 | { |
14123 | struct abbrev_info *abbrev; | |
14124 | ||
f3dd6933 DJ |
14125 | abbrev = (struct abbrev_info *) |
14126 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
14127 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
14128 | return (abbrev); | |
14129 | } | |
14130 | ||
14131 | static struct die_info * | |
b60c80d6 | 14132 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
14133 | { |
14134 | struct die_info *die; | |
b60c80d6 DJ |
14135 | size_t size = sizeof (struct die_info); |
14136 | ||
14137 | if (num_attrs > 1) | |
14138 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 14139 | |
b60c80d6 | 14140 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
14141 | memset (die, 0, sizeof (struct die_info)); |
14142 | return (die); | |
14143 | } | |
2e276125 JB |
14144 | |
14145 | \f | |
14146 | /* Macro support. */ | |
14147 | ||
2e276125 JB |
14148 | /* Return the full name of file number I in *LH's file name table. |
14149 | Use COMP_DIR as the name of the current directory of the | |
14150 | compilation. The result is allocated using xmalloc; the caller is | |
14151 | responsible for freeing it. */ | |
14152 | static char * | |
14153 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
14154 | { | |
6a83a1e6 EZ |
14155 | /* Is the file number a valid index into the line header's file name |
14156 | table? Remember that file numbers start with one, not zero. */ | |
14157 | if (1 <= file && file <= lh->num_file_names) | |
14158 | { | |
14159 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 14160 | |
6a83a1e6 EZ |
14161 | if (IS_ABSOLUTE_PATH (fe->name)) |
14162 | return xstrdup (fe->name); | |
14163 | else | |
14164 | { | |
14165 | const char *dir; | |
14166 | int dir_len; | |
14167 | char *full_name; | |
14168 | ||
14169 | if (fe->dir_index) | |
14170 | dir = lh->include_dirs[fe->dir_index - 1]; | |
14171 | else | |
14172 | dir = comp_dir; | |
14173 | ||
14174 | if (dir) | |
14175 | { | |
14176 | dir_len = strlen (dir); | |
14177 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
14178 | strcpy (full_name, dir); | |
14179 | full_name[dir_len] = '/'; | |
14180 | strcpy (full_name + dir_len + 1, fe->name); | |
14181 | return full_name; | |
14182 | } | |
14183 | else | |
14184 | return xstrdup (fe->name); | |
14185 | } | |
14186 | } | |
2e276125 JB |
14187 | else |
14188 | { | |
6a83a1e6 EZ |
14189 | /* The compiler produced a bogus file number. We can at least |
14190 | record the macro definitions made in the file, even if we | |
14191 | won't be able to find the file by name. */ | |
14192 | char fake_name[80]; | |
9a619af0 | 14193 | |
6a83a1e6 | 14194 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 14195 | |
6e70227d | 14196 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
14197 | _("bad file number in macro information (%d)"), |
14198 | file); | |
2e276125 | 14199 | |
6a83a1e6 | 14200 | return xstrdup (fake_name); |
2e276125 JB |
14201 | } |
14202 | } | |
14203 | ||
14204 | ||
14205 | static struct macro_source_file * | |
14206 | macro_start_file (int file, int line, | |
14207 | struct macro_source_file *current_file, | |
14208 | const char *comp_dir, | |
14209 | struct line_header *lh, struct objfile *objfile) | |
14210 | { | |
14211 | /* The full name of this source file. */ | |
14212 | char *full_name = file_full_name (file, lh, comp_dir); | |
14213 | ||
14214 | /* We don't create a macro table for this compilation unit | |
14215 | at all until we actually get a filename. */ | |
14216 | if (! pending_macros) | |
4a146b47 | 14217 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 14218 | objfile->macro_cache); |
2e276125 JB |
14219 | |
14220 | if (! current_file) | |
14221 | /* If we have no current file, then this must be the start_file | |
14222 | directive for the compilation unit's main source file. */ | |
14223 | current_file = macro_set_main (pending_macros, full_name); | |
14224 | else | |
14225 | current_file = macro_include (current_file, line, full_name); | |
14226 | ||
14227 | xfree (full_name); | |
6e70227d | 14228 | |
2e276125 JB |
14229 | return current_file; |
14230 | } | |
14231 | ||
14232 | ||
14233 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
14234 | followed by a null byte. */ | |
14235 | static char * | |
14236 | copy_string (const char *buf, int len) | |
14237 | { | |
14238 | char *s = xmalloc (len + 1); | |
9a619af0 | 14239 | |
2e276125 JB |
14240 | memcpy (s, buf, len); |
14241 | s[len] = '\0'; | |
2e276125 JB |
14242 | return s; |
14243 | } | |
14244 | ||
14245 | ||
14246 | static const char * | |
14247 | consume_improper_spaces (const char *p, const char *body) | |
14248 | { | |
14249 | if (*p == ' ') | |
14250 | { | |
4d3c2250 | 14251 | complaint (&symfile_complaints, |
3e43a32a MS |
14252 | _("macro definition contains spaces " |
14253 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 14254 | body); |
2e276125 JB |
14255 | |
14256 | while (*p == ' ') | |
14257 | p++; | |
14258 | } | |
14259 | ||
14260 | return p; | |
14261 | } | |
14262 | ||
14263 | ||
14264 | static void | |
14265 | parse_macro_definition (struct macro_source_file *file, int line, | |
14266 | const char *body) | |
14267 | { | |
14268 | const char *p; | |
14269 | ||
14270 | /* The body string takes one of two forms. For object-like macro | |
14271 | definitions, it should be: | |
14272 | ||
14273 | <macro name> " " <definition> | |
14274 | ||
14275 | For function-like macro definitions, it should be: | |
14276 | ||
14277 | <macro name> "() " <definition> | |
14278 | or | |
14279 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
14280 | ||
14281 | Spaces may appear only where explicitly indicated, and in the | |
14282 | <definition>. | |
14283 | ||
14284 | The Dwarf 2 spec says that an object-like macro's name is always | |
14285 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 14286 | the space when the macro's definition is the empty string. |
2e276125 JB |
14287 | |
14288 | The Dwarf 2 spec says that there should be no spaces between the | |
14289 | formal arguments in a function-like macro's formal argument list, | |
14290 | but versions of GCC around March 2002 include spaces after the | |
14291 | commas. */ | |
14292 | ||
14293 | ||
14294 | /* Find the extent of the macro name. The macro name is terminated | |
14295 | by either a space or null character (for an object-like macro) or | |
14296 | an opening paren (for a function-like macro). */ | |
14297 | for (p = body; *p; p++) | |
14298 | if (*p == ' ' || *p == '(') | |
14299 | break; | |
14300 | ||
14301 | if (*p == ' ' || *p == '\0') | |
14302 | { | |
14303 | /* It's an object-like macro. */ | |
14304 | int name_len = p - body; | |
14305 | char *name = copy_string (body, name_len); | |
14306 | const char *replacement; | |
14307 | ||
14308 | if (*p == ' ') | |
14309 | replacement = body + name_len + 1; | |
14310 | else | |
14311 | { | |
4d3c2250 | 14312 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14313 | replacement = body + name_len; |
14314 | } | |
6e70227d | 14315 | |
2e276125 JB |
14316 | macro_define_object (file, line, name, replacement); |
14317 | ||
14318 | xfree (name); | |
14319 | } | |
14320 | else if (*p == '(') | |
14321 | { | |
14322 | /* It's a function-like macro. */ | |
14323 | char *name = copy_string (body, p - body); | |
14324 | int argc = 0; | |
14325 | int argv_size = 1; | |
14326 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
14327 | ||
14328 | p++; | |
14329 | ||
14330 | p = consume_improper_spaces (p, body); | |
14331 | ||
14332 | /* Parse the formal argument list. */ | |
14333 | while (*p && *p != ')') | |
14334 | { | |
14335 | /* Find the extent of the current argument name. */ | |
14336 | const char *arg_start = p; | |
14337 | ||
14338 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
14339 | p++; | |
14340 | ||
14341 | if (! *p || p == arg_start) | |
4d3c2250 | 14342 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14343 | else |
14344 | { | |
14345 | /* Make sure argv has room for the new argument. */ | |
14346 | if (argc >= argv_size) | |
14347 | { | |
14348 | argv_size *= 2; | |
14349 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
14350 | } | |
14351 | ||
14352 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
14353 | } | |
14354 | ||
14355 | p = consume_improper_spaces (p, body); | |
14356 | ||
14357 | /* Consume the comma, if present. */ | |
14358 | if (*p == ',') | |
14359 | { | |
14360 | p++; | |
14361 | ||
14362 | p = consume_improper_spaces (p, body); | |
14363 | } | |
14364 | } | |
14365 | ||
14366 | if (*p == ')') | |
14367 | { | |
14368 | p++; | |
14369 | ||
14370 | if (*p == ' ') | |
14371 | /* Perfectly formed definition, no complaints. */ | |
14372 | macro_define_function (file, line, name, | |
6e70227d | 14373 | argc, (const char **) argv, |
2e276125 JB |
14374 | p + 1); |
14375 | else if (*p == '\0') | |
14376 | { | |
14377 | /* Complain, but do define it. */ | |
4d3c2250 | 14378 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 14379 | macro_define_function (file, line, name, |
6e70227d | 14380 | argc, (const char **) argv, |
2e276125 JB |
14381 | p); |
14382 | } | |
14383 | else | |
14384 | /* Just complain. */ | |
4d3c2250 | 14385 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14386 | } |
14387 | else | |
14388 | /* Just complain. */ | |
4d3c2250 | 14389 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14390 | |
14391 | xfree (name); | |
14392 | { | |
14393 | int i; | |
14394 | ||
14395 | for (i = 0; i < argc; i++) | |
14396 | xfree (argv[i]); | |
14397 | } | |
14398 | xfree (argv); | |
14399 | } | |
14400 | else | |
4d3c2250 | 14401 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14402 | } |
14403 | ||
14404 | ||
14405 | static void | |
14406 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
14407 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 14408 | struct dwarf2_cu *cu) |
2e276125 | 14409 | { |
fe1b8b76 | 14410 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 14411 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
14412 | enum dwarf_macinfo_record_type macinfo_type; |
14413 | int at_commandline; | |
2e276125 | 14414 | |
be391dca TT |
14415 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
14416 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 14417 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 14418 | { |
e2e0b3e5 | 14419 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
14420 | return; |
14421 | } | |
14422 | ||
757a13d0 JK |
14423 | /* First pass: Find the name of the base filename. |
14424 | This filename is needed in order to process all macros whose definition | |
14425 | (or undefinition) comes from the command line. These macros are defined | |
14426 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
14427 | associated to the base file. | |
14428 | ||
14429 | To determine the base file name, we scan the macro definitions until we | |
14430 | reach the first DW_MACINFO_start_file entry. We then initialize | |
14431 | CURRENT_FILE accordingly so that any macro definition found before the | |
14432 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
14433 | ||
dce234bc PP |
14434 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
14435 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
14436 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 14437 | |
757a13d0 | 14438 | do |
2e276125 | 14439 | { |
2e276125 JB |
14440 | /* Do we at least have room for a macinfo type byte? */ |
14441 | if (mac_ptr >= mac_end) | |
14442 | { | |
757a13d0 | 14443 | /* Complaint is printed during the second pass as GDB will probably |
3e43a32a MS |
14444 | stop the first pass earlier upon finding |
14445 | DW_MACINFO_start_file. */ | |
757a13d0 | 14446 | break; |
2e276125 JB |
14447 | } |
14448 | ||
14449 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
14450 | mac_ptr++; | |
14451 | ||
14452 | switch (macinfo_type) | |
14453 | { | |
14454 | /* A zero macinfo type indicates the end of the macro | |
14455 | information. */ | |
14456 | case 0: | |
757a13d0 JK |
14457 | break; |
14458 | ||
14459 | case DW_MACINFO_define: | |
14460 | case DW_MACINFO_undef: | |
14461 | /* Only skip the data by MAC_PTR. */ | |
14462 | { | |
14463 | unsigned int bytes_read; | |
14464 | ||
14465 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14466 | mac_ptr += bytes_read; | |
9b1c24c8 | 14467 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
14468 | mac_ptr += bytes_read; |
14469 | } | |
14470 | break; | |
14471 | ||
14472 | case DW_MACINFO_start_file: | |
14473 | { | |
14474 | unsigned int bytes_read; | |
14475 | int line, file; | |
14476 | ||
14477 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14478 | mac_ptr += bytes_read; | |
14479 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14480 | mac_ptr += bytes_read; | |
14481 | ||
3e43a32a MS |
14482 | current_file = macro_start_file (file, line, current_file, |
14483 | comp_dir, lh, cu->objfile); | |
757a13d0 JK |
14484 | } |
14485 | break; | |
14486 | ||
14487 | case DW_MACINFO_end_file: | |
14488 | /* No data to skip by MAC_PTR. */ | |
14489 | break; | |
14490 | ||
14491 | case DW_MACINFO_vendor_ext: | |
14492 | /* Only skip the data by MAC_PTR. */ | |
14493 | { | |
14494 | unsigned int bytes_read; | |
14495 | ||
14496 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14497 | mac_ptr += bytes_read; | |
9b1c24c8 | 14498 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
14499 | mac_ptr += bytes_read; |
14500 | } | |
14501 | break; | |
14502 | ||
14503 | default: | |
14504 | break; | |
14505 | } | |
14506 | } while (macinfo_type != 0 && current_file == NULL); | |
14507 | ||
14508 | /* Second pass: Process all entries. | |
14509 | ||
14510 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
14511 | command-line macro definitions/undefinitions. This flag is unset when we | |
14512 | reach the first DW_MACINFO_start_file entry. */ | |
14513 | ||
dce234bc | 14514 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
14515 | |
14516 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
14517 | GDB is still reading the definitions from command line. First | |
14518 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
14519 | to create CURRENT_FILE for the main source holding also the command line | |
14520 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
14521 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
14522 | ||
14523 | at_commandline = 1; | |
14524 | ||
14525 | do | |
14526 | { | |
14527 | /* Do we at least have room for a macinfo type byte? */ | |
14528 | if (mac_ptr >= mac_end) | |
14529 | { | |
14530 | dwarf2_macros_too_long_complaint (); | |
14531 | break; | |
14532 | } | |
14533 | ||
14534 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
14535 | mac_ptr++; | |
14536 | ||
14537 | switch (macinfo_type) | |
14538 | { | |
14539 | /* A zero macinfo type indicates the end of the macro | |
14540 | information. */ | |
14541 | case 0: | |
14542 | break; | |
2e276125 JB |
14543 | |
14544 | case DW_MACINFO_define: | |
14545 | case DW_MACINFO_undef: | |
14546 | { | |
891d2f0b | 14547 | unsigned int bytes_read; |
2e276125 JB |
14548 | int line; |
14549 | char *body; | |
14550 | ||
14551 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14552 | mac_ptr += bytes_read; | |
9b1c24c8 | 14553 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
14554 | mac_ptr += bytes_read; |
14555 | ||
14556 | if (! current_file) | |
757a13d0 JK |
14557 | { |
14558 | /* DWARF violation as no main source is present. */ | |
14559 | complaint (&symfile_complaints, | |
14560 | _("debug info with no main source gives macro %s " | |
14561 | "on line %d: %s"), | |
6e70227d DE |
14562 | macinfo_type == DW_MACINFO_define ? |
14563 | _("definition") : | |
905e0470 PM |
14564 | macinfo_type == DW_MACINFO_undef ? |
14565 | _("undefinition") : | |
14566 | _("something-or-other"), line, body); | |
757a13d0 JK |
14567 | break; |
14568 | } | |
3e43a32a MS |
14569 | if ((line == 0 && !at_commandline) |
14570 | || (line != 0 && at_commandline)) | |
4d3c2250 | 14571 | complaint (&symfile_complaints, |
757a13d0 JK |
14572 | _("debug info gives %s macro %s with %s line %d: %s"), |
14573 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 | 14574 | macinfo_type == DW_MACINFO_define ? |
6e70227d | 14575 | _("definition") : |
905e0470 PM |
14576 | macinfo_type == DW_MACINFO_undef ? |
14577 | _("undefinition") : | |
14578 | _("something-or-other"), | |
757a13d0 JK |
14579 | line == 0 ? _("zero") : _("non-zero"), line, body); |
14580 | ||
14581 | if (macinfo_type == DW_MACINFO_define) | |
14582 | parse_macro_definition (current_file, line, body); | |
14583 | else if (macinfo_type == DW_MACINFO_undef) | |
14584 | macro_undef (current_file, line, body); | |
2e276125 JB |
14585 | } |
14586 | break; | |
14587 | ||
14588 | case DW_MACINFO_start_file: | |
14589 | { | |
891d2f0b | 14590 | unsigned int bytes_read; |
2e276125 JB |
14591 | int line, file; |
14592 | ||
14593 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14594 | mac_ptr += bytes_read; | |
14595 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14596 | mac_ptr += bytes_read; | |
14597 | ||
3e43a32a MS |
14598 | if ((line == 0 && !at_commandline) |
14599 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
14600 | complaint (&symfile_complaints, |
14601 | _("debug info gives source %d included " | |
14602 | "from %s at %s line %d"), | |
14603 | file, at_commandline ? _("command-line") : _("file"), | |
14604 | line == 0 ? _("zero") : _("non-zero"), line); | |
14605 | ||
14606 | if (at_commandline) | |
14607 | { | |
14608 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
14609 | at_commandline = 0; | |
14610 | } | |
14611 | else | |
14612 | current_file = macro_start_file (file, line, | |
14613 | current_file, comp_dir, | |
14614 | lh, cu->objfile); | |
2e276125 JB |
14615 | } |
14616 | break; | |
14617 | ||
14618 | case DW_MACINFO_end_file: | |
14619 | if (! current_file) | |
4d3c2250 | 14620 | complaint (&symfile_complaints, |
3e43a32a MS |
14621 | _("macro debug info has an unmatched " |
14622 | "`close_file' directive")); | |
2e276125 JB |
14623 | else |
14624 | { | |
14625 | current_file = current_file->included_by; | |
14626 | if (! current_file) | |
14627 | { | |
14628 | enum dwarf_macinfo_record_type next_type; | |
14629 | ||
14630 | /* GCC circa March 2002 doesn't produce the zero | |
14631 | type byte marking the end of the compilation | |
14632 | unit. Complain if it's not there, but exit no | |
14633 | matter what. */ | |
14634 | ||
14635 | /* Do we at least have room for a macinfo type byte? */ | |
14636 | if (mac_ptr >= mac_end) | |
14637 | { | |
4d3c2250 | 14638 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
14639 | return; |
14640 | } | |
14641 | ||
14642 | /* We don't increment mac_ptr here, so this is just | |
14643 | a look-ahead. */ | |
14644 | next_type = read_1_byte (abfd, mac_ptr); | |
14645 | if (next_type != 0) | |
4d3c2250 | 14646 | complaint (&symfile_complaints, |
3e43a32a MS |
14647 | _("no terminating 0-type entry for " |
14648 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
14649 | |
14650 | return; | |
14651 | } | |
14652 | } | |
14653 | break; | |
14654 | ||
14655 | case DW_MACINFO_vendor_ext: | |
14656 | { | |
891d2f0b | 14657 | unsigned int bytes_read; |
2e276125 | 14658 | int constant; |
2e276125 JB |
14659 | |
14660 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14661 | mac_ptr += bytes_read; | |
e8e80198 | 14662 | read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
14663 | mac_ptr += bytes_read; |
14664 | ||
14665 | /* We don't recognize any vendor extensions. */ | |
14666 | } | |
14667 | break; | |
14668 | } | |
757a13d0 | 14669 | } while (macinfo_type != 0); |
2e276125 | 14670 | } |
8e19ed76 PS |
14671 | |
14672 | /* Check if the attribute's form is a DW_FORM_block* | |
0963b4bd | 14673 | if so return true else false. */ |
8e19ed76 PS |
14674 | static int |
14675 | attr_form_is_block (struct attribute *attr) | |
14676 | { | |
14677 | return (attr == NULL ? 0 : | |
14678 | attr->form == DW_FORM_block1 | |
14679 | || attr->form == DW_FORM_block2 | |
14680 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
14681 | || attr->form == DW_FORM_block |
14682 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 14683 | } |
4c2df51b | 14684 | |
c6a0999f JB |
14685 | /* Return non-zero if ATTR's value is a section offset --- classes |
14686 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
14687 | You may use DW_UNSND (attr) to retrieve such offsets. | |
14688 | ||
14689 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
14690 | may have a value that belongs to more than one of these classes; it | |
14691 | would be ambiguous if we did, because we use the same forms for all | |
14692 | of them. */ | |
3690dd37 JB |
14693 | static int |
14694 | attr_form_is_section_offset (struct attribute *attr) | |
14695 | { | |
14696 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
14697 | || attr->form == DW_FORM_data8 |
14698 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
14699 | } |
14700 | ||
14701 | ||
14702 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
14703 | zero otherwise. When this function returns true, you can apply | |
14704 | dwarf2_get_attr_constant_value to it. | |
14705 | ||
14706 | However, note that for some attributes you must check | |
14707 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
14708 | and DW_FORM_data8 are members of both the constant class, and of | |
14709 | the classes that contain offsets into other debug sections | |
14710 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
14711 | that, if an attribute's can be either a constant or one of the | |
14712 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
14713 | taken as section offsets, not constants. */ | |
14714 | static int | |
14715 | attr_form_is_constant (struct attribute *attr) | |
14716 | { | |
14717 | switch (attr->form) | |
14718 | { | |
14719 | case DW_FORM_sdata: | |
14720 | case DW_FORM_udata: | |
14721 | case DW_FORM_data1: | |
14722 | case DW_FORM_data2: | |
14723 | case DW_FORM_data4: | |
14724 | case DW_FORM_data8: | |
14725 | return 1; | |
14726 | default: | |
14727 | return 0; | |
14728 | } | |
14729 | } | |
14730 | ||
8cf6f0b1 TT |
14731 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
14732 | ||
14733 | static void | |
14734 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
14735 | struct dwarf2_loclist_baton *baton, | |
14736 | struct attribute *attr) | |
14737 | { | |
14738 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
14739 | &dwarf2_per_objfile->loc); | |
14740 | ||
14741 | baton->per_cu = cu->per_cu; | |
14742 | gdb_assert (baton->per_cu); | |
14743 | /* We don't know how long the location list is, but make sure we | |
14744 | don't run off the edge of the section. */ | |
14745 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
14746 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
14747 | baton->base_address = cu->base_address; | |
14748 | } | |
14749 | ||
4c2df51b DJ |
14750 | static void |
14751 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 14752 | struct dwarf2_cu *cu) |
4c2df51b | 14753 | { |
3690dd37 | 14754 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
14755 | /* ".debug_loc" may not exist at all, or the offset may be outside |
14756 | the section. If so, fall through to the complaint in the | |
14757 | other branch. */ | |
9e0ac564 TT |
14758 | && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile, |
14759 | &dwarf2_per_objfile->loc)) | |
4c2df51b | 14760 | { |
0d53c4c4 | 14761 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 14762 | |
4a146b47 | 14763 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 14764 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 14765 | |
8cf6f0b1 | 14766 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 14767 | |
d00adf39 | 14768 | if (cu->base_known == 0) |
0d53c4c4 | 14769 | complaint (&symfile_complaints, |
3e43a32a MS |
14770 | _("Location list used without " |
14771 | "specifying the CU base address.")); | |
4c2df51b | 14772 | |
768a979c | 14773 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
14774 | SYMBOL_LOCATION_BATON (sym) = baton; |
14775 | } | |
14776 | else | |
14777 | { | |
14778 | struct dwarf2_locexpr_baton *baton; | |
14779 | ||
4a146b47 | 14780 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 14781 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
14782 | baton->per_cu = cu->per_cu; |
14783 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
14784 | |
14785 | if (attr_form_is_block (attr)) | |
14786 | { | |
14787 | /* Note that we're just copying the block's data pointer | |
14788 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
14789 | info_buffer for SYM's objfile; right now we never release |
14790 | that buffer, but when we do clean up properly this may | |
14791 | need to change. */ | |
0d53c4c4 DJ |
14792 | baton->size = DW_BLOCK (attr)->size; |
14793 | baton->data = DW_BLOCK (attr)->data; | |
14794 | } | |
14795 | else | |
14796 | { | |
14797 | dwarf2_invalid_attrib_class_complaint ("location description", | |
14798 | SYMBOL_NATURAL_NAME (sym)); | |
14799 | baton->size = 0; | |
14800 | baton->data = NULL; | |
14801 | } | |
6e70227d | 14802 | |
768a979c | 14803 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
14804 | SYMBOL_LOCATION_BATON (sym) = baton; |
14805 | } | |
4c2df51b | 14806 | } |
6502dd73 | 14807 | |
9aa1f1e3 TT |
14808 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
14809 | came from a separate debuginfo file, then the master objfile is | |
14810 | returned. */ | |
ae0d2f24 UW |
14811 | |
14812 | struct objfile * | |
14813 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
14814 | { | |
9291a0cd | 14815 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
14816 | |
14817 | /* Return the master objfile, so that we can report and look up the | |
14818 | correct file containing this variable. */ | |
14819 | if (objfile->separate_debug_objfile_backlink) | |
14820 | objfile = objfile->separate_debug_objfile_backlink; | |
14821 | ||
14822 | return objfile; | |
14823 | } | |
14824 | ||
14825 | /* Return the address size given in the compilation unit header for CU. */ | |
14826 | ||
14827 | CORE_ADDR | |
14828 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
14829 | { | |
14830 | if (per_cu->cu) | |
14831 | return per_cu->cu->header.addr_size; | |
14832 | else | |
14833 | { | |
14834 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14835 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
14836 | struct dwarf2_per_objfile *per_objfile |
14837 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 14838 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 | 14839 | struct comp_unit_head cu_header; |
9a619af0 | 14840 | |
ae0d2f24 UW |
14841 | memset (&cu_header, 0, sizeof cu_header); |
14842 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14843 | return cu_header.addr_size; | |
14844 | } | |
14845 | } | |
14846 | ||
9eae7c52 TT |
14847 | /* Return the offset size given in the compilation unit header for CU. */ |
14848 | ||
14849 | int | |
14850 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
14851 | { | |
14852 | if (per_cu->cu) | |
14853 | return per_cu->cu->header.offset_size; | |
14854 | else | |
14855 | { | |
14856 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14857 | struct objfile *objfile = per_cu->objfile; |
9eae7c52 TT |
14858 | struct dwarf2_per_objfile *per_objfile |
14859 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
14860 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; | |
14861 | struct comp_unit_head cu_header; | |
14862 | ||
14863 | memset (&cu_header, 0, sizeof cu_header); | |
14864 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14865 | return cu_header.offset_size; | |
14866 | } | |
14867 | } | |
14868 | ||
9aa1f1e3 TT |
14869 | /* Return the text offset of the CU. The returned offset comes from |
14870 | this CU's objfile. If this objfile came from a separate debuginfo | |
14871 | file, then the offset may be different from the corresponding | |
14872 | offset in the parent objfile. */ | |
14873 | ||
14874 | CORE_ADDR | |
14875 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
14876 | { | |
bb3fa9d0 | 14877 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
14878 | |
14879 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
14880 | } | |
14881 | ||
348e048f DE |
14882 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
14883 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
14884 | |
14885 | static struct dwarf2_per_cu_data * | |
c764a876 | 14886 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
14887 | struct objfile *objfile) |
14888 | { | |
14889 | struct dwarf2_per_cu_data *this_cu; | |
14890 | int low, high; | |
14891 | ||
ae038cb0 DJ |
14892 | low = 0; |
14893 | high = dwarf2_per_objfile->n_comp_units - 1; | |
14894 | while (high > low) | |
14895 | { | |
14896 | int mid = low + (high - low) / 2; | |
9a619af0 | 14897 | |
ae038cb0 DJ |
14898 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
14899 | high = mid; | |
14900 | else | |
14901 | low = mid + 1; | |
14902 | } | |
14903 | gdb_assert (low == high); | |
14904 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
14905 | { | |
10b3939b | 14906 | if (low == 0) |
8a3fe4f8 AC |
14907 | error (_("Dwarf Error: could not find partial DIE containing " |
14908 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
14909 | (long) offset, bfd_get_filename (objfile->obfd)); |
14910 | ||
ae038cb0 DJ |
14911 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
14912 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
14913 | } | |
14914 | else | |
14915 | { | |
14916 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
14917 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
14918 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 14919 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
14920 | gdb_assert (offset < this_cu->offset + this_cu->length); |
14921 | return this_cu; | |
14922 | } | |
14923 | } | |
14924 | ||
10b3939b DJ |
14925 | /* Locate the compilation unit from OBJFILE which is located at exactly |
14926 | OFFSET. Raises an error on failure. */ | |
14927 | ||
ae038cb0 | 14928 | static struct dwarf2_per_cu_data * |
c764a876 | 14929 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
14930 | { |
14931 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 14932 | |
ae038cb0 DJ |
14933 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
14934 | if (this_cu->offset != offset) | |
c764a876 | 14935 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
14936 | return this_cu; |
14937 | } | |
14938 | ||
9816fde3 | 14939 | /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */ |
93311388 | 14940 | |
9816fde3 JK |
14941 | static void |
14942 | init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile) | |
93311388 | 14943 | { |
9816fde3 | 14944 | memset (cu, 0, sizeof (*cu)); |
93311388 DE |
14945 | cu->objfile = objfile; |
14946 | obstack_init (&cu->comp_unit_obstack); | |
9816fde3 JK |
14947 | } |
14948 | ||
14949 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
14950 | ||
14951 | static void | |
14952 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
14953 | { | |
14954 | struct attribute *attr; | |
14955 | ||
14956 | /* Set the language we're debugging. */ | |
14957 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
14958 | if (attr) | |
14959 | set_cu_language (DW_UNSND (attr), cu); | |
14960 | else | |
9cded63f TT |
14961 | { |
14962 | cu->language = language_minimal; | |
14963 | cu->language_defn = language_def (cu->language); | |
14964 | } | |
93311388 DE |
14965 | } |
14966 | ||
ae038cb0 DJ |
14967 | /* Release one cached compilation unit, CU. We unlink it from the tree |
14968 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
14969 | the caller is responsible for that. |
14970 | NOTE: DATA is a void * because this function is also used as a | |
14971 | cleanup routine. */ | |
ae038cb0 DJ |
14972 | |
14973 | static void | |
14974 | free_one_comp_unit (void *data) | |
14975 | { | |
14976 | struct dwarf2_cu *cu = data; | |
14977 | ||
14978 | if (cu->per_cu != NULL) | |
14979 | cu->per_cu->cu = NULL; | |
14980 | cu->per_cu = NULL; | |
14981 | ||
14982 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14983 | ||
14984 | xfree (cu); | |
14985 | } | |
14986 | ||
72bf9492 | 14987 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
14988 | when we're finished with it. We can't free the pointer itself, but be |
14989 | sure to unlink it from the cache. Also release any associated storage | |
14990 | and perform cache maintenance. | |
72bf9492 DJ |
14991 | |
14992 | Only used during partial symbol parsing. */ | |
14993 | ||
14994 | static void | |
14995 | free_stack_comp_unit (void *data) | |
14996 | { | |
14997 | struct dwarf2_cu *cu = data; | |
14998 | ||
14999 | obstack_free (&cu->comp_unit_obstack, NULL); | |
15000 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
15001 | |
15002 | if (cu->per_cu != NULL) | |
15003 | { | |
15004 | /* This compilation unit is on the stack in our caller, so we | |
15005 | should not xfree it. Just unlink it. */ | |
15006 | cu->per_cu->cu = NULL; | |
15007 | cu->per_cu = NULL; | |
15008 | ||
15009 | /* If we had a per-cu pointer, then we may have other compilation | |
15010 | units loaded, so age them now. */ | |
15011 | age_cached_comp_units (); | |
15012 | } | |
15013 | } | |
15014 | ||
15015 | /* Free all cached compilation units. */ | |
15016 | ||
15017 | static void | |
15018 | free_cached_comp_units (void *data) | |
15019 | { | |
15020 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15021 | ||
15022 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15023 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15024 | while (per_cu != NULL) | |
15025 | { | |
15026 | struct dwarf2_per_cu_data *next_cu; | |
15027 | ||
15028 | next_cu = per_cu->cu->read_in_chain; | |
15029 | ||
15030 | free_one_comp_unit (per_cu->cu); | |
15031 | *last_chain = next_cu; | |
15032 | ||
15033 | per_cu = next_cu; | |
15034 | } | |
15035 | } | |
15036 | ||
15037 | /* Increase the age counter on each cached compilation unit, and free | |
15038 | any that are too old. */ | |
15039 | ||
15040 | static void | |
15041 | age_cached_comp_units (void) | |
15042 | { | |
15043 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15044 | ||
15045 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
15046 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15047 | while (per_cu != NULL) | |
15048 | { | |
15049 | per_cu->cu->last_used ++; | |
15050 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
15051 | dwarf2_mark (per_cu->cu); | |
15052 | per_cu = per_cu->cu->read_in_chain; | |
15053 | } | |
15054 | ||
15055 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15056 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15057 | while (per_cu != NULL) | |
15058 | { | |
15059 | struct dwarf2_per_cu_data *next_cu; | |
15060 | ||
15061 | next_cu = per_cu->cu->read_in_chain; | |
15062 | ||
15063 | if (!per_cu->cu->mark) | |
15064 | { | |
15065 | free_one_comp_unit (per_cu->cu); | |
15066 | *last_chain = next_cu; | |
15067 | } | |
15068 | else | |
15069 | last_chain = &per_cu->cu->read_in_chain; | |
15070 | ||
15071 | per_cu = next_cu; | |
15072 | } | |
15073 | } | |
15074 | ||
15075 | /* Remove a single compilation unit from the cache. */ | |
15076 | ||
15077 | static void | |
15078 | free_one_cached_comp_unit (void *target_cu) | |
15079 | { | |
15080 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15081 | ||
15082 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15083 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15084 | while (per_cu != NULL) | |
15085 | { | |
15086 | struct dwarf2_per_cu_data *next_cu; | |
15087 | ||
15088 | next_cu = per_cu->cu->read_in_chain; | |
15089 | ||
15090 | if (per_cu->cu == target_cu) | |
15091 | { | |
15092 | free_one_comp_unit (per_cu->cu); | |
15093 | *last_chain = next_cu; | |
15094 | break; | |
15095 | } | |
15096 | else | |
15097 | last_chain = &per_cu->cu->read_in_chain; | |
15098 | ||
15099 | per_cu = next_cu; | |
15100 | } | |
15101 | } | |
15102 | ||
fe3e1990 DJ |
15103 | /* Release all extra memory associated with OBJFILE. */ |
15104 | ||
15105 | void | |
15106 | dwarf2_free_objfile (struct objfile *objfile) | |
15107 | { | |
15108 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15109 | ||
15110 | if (dwarf2_per_objfile == NULL) | |
15111 | return; | |
15112 | ||
15113 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
15114 | free_cached_comp_units (NULL); | |
15115 | ||
7b9f3c50 DE |
15116 | if (dwarf2_per_objfile->quick_file_names_table) |
15117 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 15118 | |
fe3e1990 DJ |
15119 | /* Everything else should be on the objfile obstack. */ |
15120 | } | |
15121 | ||
1c379e20 DJ |
15122 | /* A pair of DIE offset and GDB type pointer. We store these |
15123 | in a hash table separate from the DIEs, and preserve them | |
15124 | when the DIEs are flushed out of cache. */ | |
15125 | ||
15126 | struct dwarf2_offset_and_type | |
15127 | { | |
15128 | unsigned int offset; | |
15129 | struct type *type; | |
15130 | }; | |
15131 | ||
15132 | /* Hash function for a dwarf2_offset_and_type. */ | |
15133 | ||
15134 | static hashval_t | |
15135 | offset_and_type_hash (const void *item) | |
15136 | { | |
15137 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 15138 | |
1c379e20 DJ |
15139 | return ofs->offset; |
15140 | } | |
15141 | ||
15142 | /* Equality function for a dwarf2_offset_and_type. */ | |
15143 | ||
15144 | static int | |
15145 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
15146 | { | |
15147 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
15148 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 15149 | |
1c379e20 DJ |
15150 | return ofs_lhs->offset == ofs_rhs->offset; |
15151 | } | |
15152 | ||
15153 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
15154 | table if necessary. For convenience, return TYPE. |
15155 | ||
15156 | The DIEs reading must have careful ordering to: | |
15157 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
15158 | reading current DIE. | |
15159 | * Not trying to dereference contents of still incompletely read in types | |
15160 | while reading in other DIEs. | |
15161 | * Enable referencing still incompletely read in types just by a pointer to | |
15162 | the type without accessing its fields. | |
15163 | ||
15164 | Therefore caller should follow these rules: | |
15165 | * Try to fetch any prerequisite types we may need to build this DIE type | |
15166 | before building the type and calling set_die_type. | |
e71ec853 | 15167 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
15168 | possible before fetching more types to complete the current type. |
15169 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 15170 | |
f792889a | 15171 | static struct type * |
1c379e20 DJ |
15172 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
15173 | { | |
15174 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
15175 | struct objfile *objfile = cu->objfile; |
15176 | htab_t *type_hash_ptr; | |
1c379e20 | 15177 | |
b4ba55a1 JB |
15178 | /* For Ada types, make sure that the gnat-specific data is always |
15179 | initialized (if not already set). There are a few types where | |
15180 | we should not be doing so, because the type-specific area is | |
15181 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
15182 | where the type-specific area is used to store the floatformat). | |
15183 | But this is not a problem, because the gnat-specific information | |
15184 | is actually not needed for these types. */ | |
15185 | if (need_gnat_info (cu) | |
15186 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
15187 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
15188 | && !HAVE_GNAT_AUX_INFO (type)) | |
15189 | INIT_GNAT_SPECIFIC (type); | |
15190 | ||
673bfd45 DE |
15191 | if (cu->per_cu->from_debug_types) |
15192 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; | |
15193 | else | |
15194 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
15195 | ||
15196 | if (*type_hash_ptr == NULL) | |
f792889a | 15197 | { |
673bfd45 DE |
15198 | *type_hash_ptr |
15199 | = htab_create_alloc_ex (127, | |
f792889a DJ |
15200 | offset_and_type_hash, |
15201 | offset_and_type_eq, | |
15202 | NULL, | |
673bfd45 | 15203 | &objfile->objfile_obstack, |
f792889a DJ |
15204 | hashtab_obstack_allocate, |
15205 | dummy_obstack_deallocate); | |
f792889a | 15206 | } |
1c379e20 DJ |
15207 | |
15208 | ofs.offset = die->offset; | |
15209 | ofs.type = type; | |
15210 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 15211 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
15212 | if (*slot) |
15213 | complaint (&symfile_complaints, | |
15214 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
15215 | die->offset); | |
673bfd45 | 15216 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 15217 | **slot = ofs; |
f792889a | 15218 | return type; |
1c379e20 DJ |
15219 | } |
15220 | ||
673bfd45 DE |
15221 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
15222 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
15223 | |
15224 | static struct type * | |
673bfd45 DE |
15225 | get_die_type_at_offset (unsigned int offset, |
15226 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
15227 | { |
15228 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 15229 | htab_t type_hash; |
f792889a | 15230 | |
673bfd45 DE |
15231 | if (per_cu->from_debug_types) |
15232 | type_hash = dwarf2_per_objfile->debug_types_type_hash; | |
15233 | else | |
15234 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
15235 | if (type_hash == NULL) |
15236 | return NULL; | |
1c379e20 | 15237 | |
673bfd45 | 15238 | ofs.offset = offset; |
1c379e20 DJ |
15239 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
15240 | if (slot) | |
15241 | return slot->type; | |
15242 | else | |
15243 | return NULL; | |
15244 | } | |
15245 | ||
673bfd45 DE |
15246 | /* Look up the type for DIE in the appropriate type_hash table, |
15247 | or return NULL if DIE does not have a saved type. */ | |
15248 | ||
15249 | static struct type * | |
15250 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
15251 | { | |
15252 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
15253 | } | |
15254 | ||
10b3939b DJ |
15255 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
15256 | ||
15257 | static void | |
15258 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
15259 | struct dwarf2_per_cu_data *ref_per_cu) | |
15260 | { | |
15261 | void **slot; | |
15262 | ||
15263 | if (cu->dependencies == NULL) | |
15264 | cu->dependencies | |
15265 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
15266 | NULL, &cu->comp_unit_obstack, | |
15267 | hashtab_obstack_allocate, | |
15268 | dummy_obstack_deallocate); | |
15269 | ||
15270 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
15271 | if (*slot == NULL) | |
15272 | *slot = ref_per_cu; | |
15273 | } | |
1c379e20 | 15274 | |
f504f079 DE |
15275 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
15276 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
15277 | cache that we must keep because we are keeping CU. */ |
15278 | ||
10b3939b DJ |
15279 | static int |
15280 | dwarf2_mark_helper (void **slot, void *data) | |
15281 | { | |
15282 | struct dwarf2_per_cu_data *per_cu; | |
15283 | ||
15284 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
15285 | if (per_cu->cu->mark) | |
15286 | return 1; | |
15287 | per_cu->cu->mark = 1; | |
15288 | ||
15289 | if (per_cu->cu->dependencies != NULL) | |
15290 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
15291 | ||
15292 | return 1; | |
15293 | } | |
15294 | ||
f504f079 DE |
15295 | /* Set the mark field in CU and in every other compilation unit in the |
15296 | cache that we must keep because we are keeping CU. */ | |
15297 | ||
ae038cb0 DJ |
15298 | static void |
15299 | dwarf2_mark (struct dwarf2_cu *cu) | |
15300 | { | |
15301 | if (cu->mark) | |
15302 | return; | |
15303 | cu->mark = 1; | |
10b3939b DJ |
15304 | if (cu->dependencies != NULL) |
15305 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
15306 | } |
15307 | ||
15308 | static void | |
15309 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
15310 | { | |
15311 | while (per_cu) | |
15312 | { | |
15313 | per_cu->cu->mark = 0; | |
15314 | per_cu = per_cu->cu->read_in_chain; | |
15315 | } | |
72bf9492 DJ |
15316 | } |
15317 | ||
72bf9492 DJ |
15318 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
15319 | is its offset in .debug_info for this objfile. */ | |
15320 | ||
15321 | static hashval_t | |
15322 | partial_die_hash (const void *item) | |
15323 | { | |
15324 | const struct partial_die_info *part_die = item; | |
9a619af0 | 15325 | |
72bf9492 DJ |
15326 | return part_die->offset; |
15327 | } | |
15328 | ||
15329 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
15330 | are equal if they have the same offset. */ | |
15331 | ||
15332 | static int | |
15333 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
15334 | { | |
15335 | const struct partial_die_info *part_die_lhs = item_lhs; | |
15336 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 15337 | |
72bf9492 DJ |
15338 | return part_die_lhs->offset == part_die_rhs->offset; |
15339 | } | |
15340 | ||
ae038cb0 DJ |
15341 | static struct cmd_list_element *set_dwarf2_cmdlist; |
15342 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
15343 | ||
15344 | static void | |
15345 | set_dwarf2_cmd (char *args, int from_tty) | |
15346 | { | |
15347 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
15348 | } | |
15349 | ||
15350 | static void | |
15351 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 15352 | { |
ae038cb0 DJ |
15353 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
15354 | } | |
15355 | ||
dce234bc PP |
15356 | /* If section described by INFO was mmapped, munmap it now. */ |
15357 | ||
15358 | static void | |
15359 | munmap_section_buffer (struct dwarf2_section_info *info) | |
15360 | { | |
15361 | if (info->was_mmapped) | |
15362 | { | |
15363 | #ifdef HAVE_MMAP | |
15364 | intptr_t begin = (intptr_t) info->buffer; | |
15365 | intptr_t map_begin = begin & ~(pagesize - 1); | |
15366 | size_t map_length = info->size + begin - map_begin; | |
9a619af0 | 15367 | |
dce234bc PP |
15368 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
15369 | #else | |
15370 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 15371 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
15372 | #endif |
15373 | } | |
15374 | } | |
15375 | ||
15376 | /* munmap debug sections for OBJFILE, if necessary. */ | |
15377 | ||
15378 | static void | |
c1bd65d0 | 15379 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
15380 | { |
15381 | struct dwarf2_per_objfile *data = d; | |
9a619af0 | 15382 | |
16be1145 DE |
15383 | /* This is sorted according to the order they're defined in to make it easier |
15384 | to keep in sync. */ | |
dce234bc PP |
15385 | munmap_section_buffer (&data->info); |
15386 | munmap_section_buffer (&data->abbrev); | |
15387 | munmap_section_buffer (&data->line); | |
16be1145 | 15388 | munmap_section_buffer (&data->loc); |
dce234bc | 15389 | munmap_section_buffer (&data->macinfo); |
16be1145 | 15390 | munmap_section_buffer (&data->str); |
dce234bc | 15391 | munmap_section_buffer (&data->ranges); |
16be1145 | 15392 | munmap_section_buffer (&data->types); |
dce234bc PP |
15393 | munmap_section_buffer (&data->frame); |
15394 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd TT |
15395 | munmap_section_buffer (&data->gdb_index); |
15396 | } | |
15397 | ||
15398 | \f | |
ae2de4f8 | 15399 | /* The "save gdb-index" command. */ |
9291a0cd TT |
15400 | |
15401 | /* The contents of the hash table we create when building the string | |
15402 | table. */ | |
15403 | struct strtab_entry | |
15404 | { | |
15405 | offset_type offset; | |
15406 | const char *str; | |
15407 | }; | |
15408 | ||
559a7a62 JK |
15409 | /* Hash function for a strtab_entry. |
15410 | ||
15411 | Function is used only during write_hash_table so no index format backward | |
15412 | compatibility is needed. */ | |
b89be57b | 15413 | |
9291a0cd TT |
15414 | static hashval_t |
15415 | hash_strtab_entry (const void *e) | |
15416 | { | |
15417 | const struct strtab_entry *entry = e; | |
559a7a62 | 15418 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
15419 | } |
15420 | ||
15421 | /* Equality function for a strtab_entry. */ | |
b89be57b | 15422 | |
9291a0cd TT |
15423 | static int |
15424 | eq_strtab_entry (const void *a, const void *b) | |
15425 | { | |
15426 | const struct strtab_entry *ea = a; | |
15427 | const struct strtab_entry *eb = b; | |
15428 | return !strcmp (ea->str, eb->str); | |
15429 | } | |
15430 | ||
15431 | /* Create a strtab_entry hash table. */ | |
b89be57b | 15432 | |
9291a0cd TT |
15433 | static htab_t |
15434 | create_strtab (void) | |
15435 | { | |
15436 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
15437 | xfree, xcalloc, xfree); | |
15438 | } | |
15439 | ||
15440 | /* Add a string to the constant pool. Return the string's offset in | |
15441 | host order. */ | |
b89be57b | 15442 | |
9291a0cd TT |
15443 | static offset_type |
15444 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
15445 | { | |
15446 | void **slot; | |
15447 | struct strtab_entry entry; | |
15448 | struct strtab_entry *result; | |
15449 | ||
15450 | entry.str = str; | |
15451 | slot = htab_find_slot (table, &entry, INSERT); | |
15452 | if (*slot) | |
15453 | result = *slot; | |
15454 | else | |
15455 | { | |
15456 | result = XNEW (struct strtab_entry); | |
15457 | result->offset = obstack_object_size (cpool); | |
15458 | result->str = str; | |
15459 | obstack_grow_str0 (cpool, str); | |
15460 | *slot = result; | |
15461 | } | |
15462 | return result->offset; | |
15463 | } | |
15464 | ||
15465 | /* An entry in the symbol table. */ | |
15466 | struct symtab_index_entry | |
15467 | { | |
15468 | /* The name of the symbol. */ | |
15469 | const char *name; | |
15470 | /* The offset of the name in the constant pool. */ | |
15471 | offset_type index_offset; | |
15472 | /* A sorted vector of the indices of all the CUs that hold an object | |
15473 | of this name. */ | |
15474 | VEC (offset_type) *cu_indices; | |
15475 | }; | |
15476 | ||
15477 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
15478 | struct mapped_symtab | |
15479 | { | |
15480 | offset_type n_elements; | |
15481 | offset_type size; | |
15482 | struct symtab_index_entry **data; | |
15483 | }; | |
15484 | ||
15485 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 15486 | |
9291a0cd TT |
15487 | static hashval_t |
15488 | hash_symtab_entry (const void *e) | |
15489 | { | |
15490 | const struct symtab_index_entry *entry = e; | |
15491 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
15492 | sizeof (offset_type) * VEC_length (offset_type, | |
15493 | entry->cu_indices), | |
15494 | 0); | |
15495 | } | |
15496 | ||
15497 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 15498 | |
9291a0cd TT |
15499 | static int |
15500 | eq_symtab_entry (const void *a, const void *b) | |
15501 | { | |
15502 | const struct symtab_index_entry *ea = a; | |
15503 | const struct symtab_index_entry *eb = b; | |
15504 | int len = VEC_length (offset_type, ea->cu_indices); | |
15505 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
15506 | return 0; | |
15507 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
15508 | VEC_address (offset_type, eb->cu_indices), | |
15509 | sizeof (offset_type) * len); | |
15510 | } | |
15511 | ||
15512 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 15513 | |
9291a0cd TT |
15514 | static void |
15515 | delete_symtab_entry (void *p) | |
15516 | { | |
15517 | struct symtab_index_entry *entry = p; | |
15518 | VEC_free (offset_type, entry->cu_indices); | |
15519 | xfree (entry); | |
15520 | } | |
15521 | ||
15522 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 15523 | |
9291a0cd | 15524 | static htab_t |
3876f04e | 15525 | create_symbol_hash_table (void) |
9291a0cd TT |
15526 | { |
15527 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
15528 | delete_symtab_entry, xcalloc, xfree); | |
15529 | } | |
15530 | ||
15531 | /* Create a new mapped symtab object. */ | |
b89be57b | 15532 | |
9291a0cd TT |
15533 | static struct mapped_symtab * |
15534 | create_mapped_symtab (void) | |
15535 | { | |
15536 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
15537 | symtab->n_elements = 0; | |
15538 | symtab->size = 1024; | |
15539 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
15540 | return symtab; | |
15541 | } | |
15542 | ||
15543 | /* Destroy a mapped_symtab. */ | |
b89be57b | 15544 | |
9291a0cd TT |
15545 | static void |
15546 | cleanup_mapped_symtab (void *p) | |
15547 | { | |
15548 | struct mapped_symtab *symtab = p; | |
15549 | /* The contents of the array are freed when the other hash table is | |
15550 | destroyed. */ | |
15551 | xfree (symtab->data); | |
15552 | xfree (symtab); | |
15553 | } | |
15554 | ||
15555 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
15556 | the slot. |
15557 | ||
15558 | Function is used only during write_hash_table so no index format backward | |
15559 | compatibility is needed. */ | |
b89be57b | 15560 | |
9291a0cd TT |
15561 | static struct symtab_index_entry ** |
15562 | find_slot (struct mapped_symtab *symtab, const char *name) | |
15563 | { | |
559a7a62 | 15564 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
15565 | |
15566 | index = hash & (symtab->size - 1); | |
15567 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
15568 | ||
15569 | for (;;) | |
15570 | { | |
15571 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
15572 | return &symtab->data[index]; | |
15573 | index = (index + step) & (symtab->size - 1); | |
15574 | } | |
15575 | } | |
15576 | ||
15577 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 15578 | |
9291a0cd TT |
15579 | static void |
15580 | hash_expand (struct mapped_symtab *symtab) | |
15581 | { | |
15582 | offset_type old_size = symtab->size; | |
15583 | offset_type i; | |
15584 | struct symtab_index_entry **old_entries = symtab->data; | |
15585 | ||
15586 | symtab->size *= 2; | |
15587 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
15588 | ||
15589 | for (i = 0; i < old_size; ++i) | |
15590 | { | |
15591 | if (old_entries[i]) | |
15592 | { | |
15593 | struct symtab_index_entry **slot = find_slot (symtab, | |
15594 | old_entries[i]->name); | |
15595 | *slot = old_entries[i]; | |
15596 | } | |
15597 | } | |
15598 | ||
15599 | xfree (old_entries); | |
15600 | } | |
15601 | ||
15602 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
15603 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 15604 | |
9291a0cd TT |
15605 | static void |
15606 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
15607 | offset_type cu_index) | |
15608 | { | |
15609 | struct symtab_index_entry **slot; | |
15610 | ||
15611 | ++symtab->n_elements; | |
15612 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
15613 | hash_expand (symtab); | |
15614 | ||
15615 | slot = find_slot (symtab, name); | |
15616 | if (!*slot) | |
15617 | { | |
15618 | *slot = XNEW (struct symtab_index_entry); | |
15619 | (*slot)->name = name; | |
15620 | (*slot)->cu_indices = NULL; | |
15621 | } | |
15622 | /* Don't push an index twice. Due to how we add entries we only | |
15623 | have to check the last one. */ | |
15624 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 15625 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
15626 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
15627 | } | |
15628 | ||
15629 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 15630 | |
9291a0cd | 15631 | static offset_type |
3876f04e | 15632 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
15633 | struct symtab_index_entry *entry) |
15634 | { | |
15635 | void **slot; | |
15636 | ||
3876f04e | 15637 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
15638 | if (!*slot) |
15639 | { | |
15640 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
15641 | offset_type val = MAYBE_SWAP (len); | |
15642 | offset_type iter; | |
15643 | int i; | |
15644 | ||
15645 | *slot = entry; | |
15646 | entry->index_offset = obstack_object_size (cpool); | |
15647 | ||
15648 | obstack_grow (cpool, &val, sizeof (val)); | |
15649 | for (i = 0; | |
15650 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
15651 | ++i) | |
15652 | { | |
15653 | val = MAYBE_SWAP (iter); | |
15654 | obstack_grow (cpool, &val, sizeof (val)); | |
15655 | } | |
15656 | } | |
15657 | else | |
15658 | { | |
15659 | struct symtab_index_entry *old_entry = *slot; | |
15660 | entry->index_offset = old_entry->index_offset; | |
15661 | entry = old_entry; | |
15662 | } | |
15663 | return entry->index_offset; | |
15664 | } | |
15665 | ||
15666 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
15667 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 15668 | |
9291a0cd TT |
15669 | static void |
15670 | write_hash_table (struct mapped_symtab *symtab, | |
15671 | struct obstack *output, struct obstack *cpool) | |
15672 | { | |
15673 | offset_type i; | |
3876f04e | 15674 | htab_t symbol_hash_table; |
9291a0cd TT |
15675 | htab_t str_table; |
15676 | ||
3876f04e | 15677 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 15678 | str_table = create_strtab (); |
3876f04e | 15679 | |
9291a0cd TT |
15680 | /* We add all the index vectors to the constant pool first, to |
15681 | ensure alignment is ok. */ | |
15682 | for (i = 0; i < symtab->size; ++i) | |
15683 | { | |
15684 | if (symtab->data[i]) | |
3876f04e | 15685 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
15686 | } |
15687 | ||
15688 | /* Now write out the hash table. */ | |
15689 | for (i = 0; i < symtab->size; ++i) | |
15690 | { | |
15691 | offset_type str_off, vec_off; | |
15692 | ||
15693 | if (symtab->data[i]) | |
15694 | { | |
15695 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
15696 | vec_off = symtab->data[i]->index_offset; | |
15697 | } | |
15698 | else | |
15699 | { | |
15700 | /* While 0 is a valid constant pool index, it is not valid | |
15701 | to have 0 for both offsets. */ | |
15702 | str_off = 0; | |
15703 | vec_off = 0; | |
15704 | } | |
15705 | ||
15706 | str_off = MAYBE_SWAP (str_off); | |
15707 | vec_off = MAYBE_SWAP (vec_off); | |
15708 | ||
15709 | obstack_grow (output, &str_off, sizeof (str_off)); | |
15710 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
15711 | } | |
15712 | ||
15713 | htab_delete (str_table); | |
3876f04e | 15714 | htab_delete (symbol_hash_table); |
9291a0cd TT |
15715 | } |
15716 | ||
0a5429f6 DE |
15717 | /* Struct to map psymtab to CU index in the index file. */ |
15718 | struct psymtab_cu_index_map | |
15719 | { | |
15720 | struct partial_symtab *psymtab; | |
15721 | unsigned int cu_index; | |
15722 | }; | |
15723 | ||
15724 | static hashval_t | |
15725 | hash_psymtab_cu_index (const void *item) | |
15726 | { | |
15727 | const struct psymtab_cu_index_map *map = item; | |
15728 | ||
15729 | return htab_hash_pointer (map->psymtab); | |
15730 | } | |
15731 | ||
15732 | static int | |
15733 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
15734 | { | |
15735 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
15736 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
15737 | ||
15738 | return lhs->psymtab == rhs->psymtab; | |
15739 | } | |
15740 | ||
15741 | /* Helper struct for building the address table. */ | |
15742 | struct addrmap_index_data | |
15743 | { | |
15744 | struct objfile *objfile; | |
15745 | struct obstack *addr_obstack; | |
15746 | htab_t cu_index_htab; | |
15747 | ||
15748 | /* Non-zero if the previous_* fields are valid. | |
15749 | We can't write an entry until we see the next entry (since it is only then | |
15750 | that we know the end of the entry). */ | |
15751 | int previous_valid; | |
15752 | /* Index of the CU in the table of all CUs in the index file. */ | |
15753 | unsigned int previous_cu_index; | |
0963b4bd | 15754 | /* Start address of the CU. */ |
0a5429f6 DE |
15755 | CORE_ADDR previous_cu_start; |
15756 | }; | |
15757 | ||
15758 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 15759 | |
9291a0cd | 15760 | static void |
0a5429f6 DE |
15761 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
15762 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 15763 | { |
0a5429f6 | 15764 | offset_type cu_index_to_write; |
9291a0cd TT |
15765 | char addr[8]; |
15766 | CORE_ADDR baseaddr; | |
15767 | ||
15768 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
15769 | ||
0a5429f6 DE |
15770 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
15771 | obstack_grow (obstack, addr, 8); | |
15772 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
15773 | obstack_grow (obstack, addr, 8); | |
15774 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
15775 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
15776 | } | |
15777 | ||
15778 | /* Worker function for traversing an addrmap to build the address table. */ | |
15779 | ||
15780 | static int | |
15781 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
15782 | { | |
15783 | struct addrmap_index_data *data = datap; | |
15784 | struct partial_symtab *pst = obj; | |
15785 | offset_type cu_index; | |
15786 | void **slot; | |
15787 | ||
15788 | if (data->previous_valid) | |
15789 | add_address_entry (data->objfile, data->addr_obstack, | |
15790 | data->previous_cu_start, start_addr, | |
15791 | data->previous_cu_index); | |
15792 | ||
15793 | data->previous_cu_start = start_addr; | |
15794 | if (pst != NULL) | |
15795 | { | |
15796 | struct psymtab_cu_index_map find_map, *map; | |
15797 | find_map.psymtab = pst; | |
15798 | map = htab_find (data->cu_index_htab, &find_map); | |
15799 | gdb_assert (map != NULL); | |
15800 | data->previous_cu_index = map->cu_index; | |
15801 | data->previous_valid = 1; | |
15802 | } | |
15803 | else | |
15804 | data->previous_valid = 0; | |
15805 | ||
15806 | return 0; | |
15807 | } | |
15808 | ||
15809 | /* Write OBJFILE's address map to OBSTACK. | |
15810 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
15811 | in the index file. */ | |
15812 | ||
15813 | static void | |
15814 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
15815 | htab_t cu_index_htab) | |
15816 | { | |
15817 | struct addrmap_index_data addrmap_index_data; | |
15818 | ||
15819 | /* When writing the address table, we have to cope with the fact that | |
15820 | the addrmap iterator only provides the start of a region; we have to | |
15821 | wait until the next invocation to get the start of the next region. */ | |
15822 | ||
15823 | addrmap_index_data.objfile = objfile; | |
15824 | addrmap_index_data.addr_obstack = obstack; | |
15825 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
15826 | addrmap_index_data.previous_valid = 0; | |
15827 | ||
15828 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
15829 | &addrmap_index_data); | |
15830 | ||
15831 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
15832 | is valid, but we should still handle it. | |
15833 | The end address is recorded as the start of the next region, but that | |
15834 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
15835 | anyway. */ | |
15836 | if (addrmap_index_data.previous_valid) | |
15837 | add_address_entry (objfile, obstack, | |
15838 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
15839 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
15840 | } |
15841 | ||
15842 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 15843 | |
9291a0cd TT |
15844 | static void |
15845 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 15846 | htab_t psyms_seen, |
9291a0cd TT |
15847 | struct partial_symbol **psymp, |
15848 | int count, | |
987d643c TT |
15849 | offset_type cu_index, |
15850 | int is_static) | |
9291a0cd TT |
15851 | { |
15852 | for (; count-- > 0; ++psymp) | |
15853 | { | |
987d643c TT |
15854 | void **slot, *lookup; |
15855 | ||
9291a0cd TT |
15856 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
15857 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
15858 | |
15859 | /* We only want to add a given psymbol once. However, we also | |
15860 | want to account for whether it is global or static. So, we | |
15861 | may add it twice, using slightly different values. */ | |
15862 | if (is_static) | |
15863 | { | |
15864 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
15865 | ||
15866 | lookup = (void *) val; | |
15867 | } | |
15868 | else | |
15869 | lookup = *psymp; | |
15870 | ||
15871 | /* Only add a given psymbol once. */ | |
15872 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
15873 | if (!*slot) | |
15874 | { | |
15875 | *slot = lookup; | |
15876 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
15877 | } | |
9291a0cd TT |
15878 | } |
15879 | } | |
15880 | ||
15881 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
15882 | exception if there is an error. */ | |
b89be57b | 15883 | |
9291a0cd TT |
15884 | static void |
15885 | write_obstack (FILE *file, struct obstack *obstack) | |
15886 | { | |
15887 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
15888 | file) | |
15889 | != obstack_object_size (obstack)) | |
15890 | error (_("couldn't data write to file")); | |
15891 | } | |
15892 | ||
15893 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 15894 | |
9291a0cd TT |
15895 | static void |
15896 | unlink_if_set (void *p) | |
15897 | { | |
15898 | char **filename = p; | |
15899 | if (*filename) | |
15900 | unlink (*filename); | |
15901 | } | |
15902 | ||
1fd400ff TT |
15903 | /* A helper struct used when iterating over debug_types. */ |
15904 | struct signatured_type_index_data | |
15905 | { | |
15906 | struct objfile *objfile; | |
15907 | struct mapped_symtab *symtab; | |
15908 | struct obstack *types_list; | |
987d643c | 15909 | htab_t psyms_seen; |
1fd400ff TT |
15910 | int cu_index; |
15911 | }; | |
15912 | ||
15913 | /* A helper function that writes a single signatured_type to an | |
15914 | obstack. */ | |
b89be57b | 15915 | |
1fd400ff TT |
15916 | static int |
15917 | write_one_signatured_type (void **slot, void *d) | |
15918 | { | |
15919 | struct signatured_type_index_data *info = d; | |
15920 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
15921 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
15922 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
15923 | gdb_byte val[8]; |
15924 | ||
15925 | write_psymbols (info->symtab, | |
987d643c | 15926 | info->psyms_seen, |
3e43a32a MS |
15927 | info->objfile->global_psymbols.list |
15928 | + psymtab->globals_offset, | |
987d643c TT |
15929 | psymtab->n_global_syms, info->cu_index, |
15930 | 0); | |
1fd400ff | 15931 | write_psymbols (info->symtab, |
987d643c | 15932 | info->psyms_seen, |
3e43a32a MS |
15933 | info->objfile->static_psymbols.list |
15934 | + psymtab->statics_offset, | |
987d643c TT |
15935 | psymtab->n_static_syms, info->cu_index, |
15936 | 1); | |
1fd400ff | 15937 | |
b3c8eb43 | 15938 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset); |
1fd400ff TT |
15939 | obstack_grow (info->types_list, val, 8); |
15940 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
15941 | obstack_grow (info->types_list, val, 8); | |
15942 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
15943 | obstack_grow (info->types_list, val, 8); | |
15944 | ||
15945 | ++info->cu_index; | |
15946 | ||
15947 | return 1; | |
15948 | } | |
15949 | ||
987d643c TT |
15950 | /* A cleanup function for an htab_t. */ |
15951 | ||
15952 | static void | |
15953 | cleanup_htab (void *arg) | |
15954 | { | |
15955 | htab_delete (arg); | |
15956 | } | |
15957 | ||
9291a0cd | 15958 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 15959 | |
9291a0cd TT |
15960 | static void |
15961 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
15962 | { | |
15963 | struct cleanup *cleanup; | |
15964 | char *filename, *cleanup_filename; | |
1fd400ff TT |
15965 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
15966 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
15967 | int i; |
15968 | FILE *out_file; | |
15969 | struct mapped_symtab *symtab; | |
15970 | offset_type val, size_of_contents, total_len; | |
15971 | struct stat st; | |
15972 | char buf[8]; | |
987d643c | 15973 | htab_t psyms_seen; |
0a5429f6 DE |
15974 | htab_t cu_index_htab; |
15975 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 15976 | |
b4f2f049 | 15977 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 15978 | return; |
b4f2f049 | 15979 | |
9291a0cd TT |
15980 | if (dwarf2_per_objfile->using_index) |
15981 | error (_("Cannot use an index to create the index")); | |
15982 | ||
15983 | if (stat (objfile->name, &st) < 0) | |
7e17e088 | 15984 | perror_with_name (objfile->name); |
9291a0cd TT |
15985 | |
15986 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
15987 | INDEX_SUFFIX, (char *) NULL); | |
15988 | cleanup = make_cleanup (xfree, filename); | |
15989 | ||
15990 | out_file = fopen (filename, "wb"); | |
15991 | if (!out_file) | |
15992 | error (_("Can't open `%s' for writing"), filename); | |
15993 | ||
15994 | cleanup_filename = filename; | |
15995 | make_cleanup (unlink_if_set, &cleanup_filename); | |
15996 | ||
15997 | symtab = create_mapped_symtab (); | |
15998 | make_cleanup (cleanup_mapped_symtab, symtab); | |
15999 | ||
16000 | obstack_init (&addr_obstack); | |
16001 | make_cleanup_obstack_free (&addr_obstack); | |
16002 | ||
16003 | obstack_init (&cu_list); | |
16004 | make_cleanup_obstack_free (&cu_list); | |
16005 | ||
1fd400ff TT |
16006 | obstack_init (&types_cu_list); |
16007 | make_cleanup_obstack_free (&types_cu_list); | |
16008 | ||
987d643c TT |
16009 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
16010 | NULL, xcalloc, xfree); | |
16011 | make_cleanup (cleanup_htab, psyms_seen); | |
16012 | ||
0a5429f6 DE |
16013 | /* While we're scanning CU's create a table that maps a psymtab pointer |
16014 | (which is what addrmap records) to its index (which is what is recorded | |
16015 | in the index file). This will later be needed to write the address | |
16016 | table. */ | |
16017 | cu_index_htab = htab_create_alloc (100, | |
16018 | hash_psymtab_cu_index, | |
16019 | eq_psymtab_cu_index, | |
16020 | NULL, xcalloc, xfree); | |
16021 | make_cleanup (cleanup_htab, cu_index_htab); | |
16022 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) | |
16023 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
16024 | * dwarf2_per_objfile->n_comp_units); | |
16025 | make_cleanup (xfree, psymtab_cu_index_map); | |
16026 | ||
16027 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
16028 | work here. Also, the debug_types entries do not appear in |
16029 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
16030 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
16031 | { | |
3e43a32a MS |
16032 | struct dwarf2_per_cu_data *per_cu |
16033 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 16034 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 16035 | gdb_byte val[8]; |
0a5429f6 DE |
16036 | struct psymtab_cu_index_map *map; |
16037 | void **slot; | |
9291a0cd TT |
16038 | |
16039 | write_psymbols (symtab, | |
987d643c | 16040 | psyms_seen, |
9291a0cd | 16041 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
16042 | psymtab->n_global_syms, i, |
16043 | 0); | |
9291a0cd | 16044 | write_psymbols (symtab, |
987d643c | 16045 | psyms_seen, |
9291a0cd | 16046 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
16047 | psymtab->n_static_syms, i, |
16048 | 1); | |
9291a0cd | 16049 | |
0a5429f6 DE |
16050 | map = &psymtab_cu_index_map[i]; |
16051 | map->psymtab = psymtab; | |
16052 | map->cu_index = i; | |
16053 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
16054 | gdb_assert (slot != NULL); | |
16055 | gdb_assert (*slot == NULL); | |
16056 | *slot = map; | |
9291a0cd | 16057 | |
e254ef6a | 16058 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 16059 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 16060 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
16061 | obstack_grow (&cu_list, val, 8); |
16062 | } | |
16063 | ||
0a5429f6 DE |
16064 | /* Dump the address map. */ |
16065 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
16066 | ||
1fd400ff TT |
16067 | /* Write out the .debug_type entries, if any. */ |
16068 | if (dwarf2_per_objfile->signatured_types) | |
16069 | { | |
16070 | struct signatured_type_index_data sig_data; | |
16071 | ||
16072 | sig_data.objfile = objfile; | |
16073 | sig_data.symtab = symtab; | |
16074 | sig_data.types_list = &types_cu_list; | |
987d643c | 16075 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
16076 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
16077 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
16078 | write_one_signatured_type, &sig_data); | |
16079 | } | |
16080 | ||
9291a0cd TT |
16081 | obstack_init (&constant_pool); |
16082 | make_cleanup_obstack_free (&constant_pool); | |
16083 | obstack_init (&symtab_obstack); | |
16084 | make_cleanup_obstack_free (&symtab_obstack); | |
16085 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
16086 | ||
16087 | obstack_init (&contents); | |
16088 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 16089 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
16090 | total_len = size_of_contents; |
16091 | ||
16092 | /* The version number. */ | |
559a7a62 | 16093 | val = MAYBE_SWAP (5); |
9291a0cd TT |
16094 | obstack_grow (&contents, &val, sizeof (val)); |
16095 | ||
16096 | /* The offset of the CU list from the start of the file. */ | |
16097 | val = MAYBE_SWAP (total_len); | |
16098 | obstack_grow (&contents, &val, sizeof (val)); | |
16099 | total_len += obstack_object_size (&cu_list); | |
16100 | ||
1fd400ff TT |
16101 | /* The offset of the types CU list from the start of the file. */ |
16102 | val = MAYBE_SWAP (total_len); | |
16103 | obstack_grow (&contents, &val, sizeof (val)); | |
16104 | total_len += obstack_object_size (&types_cu_list); | |
16105 | ||
9291a0cd TT |
16106 | /* The offset of the address table from the start of the file. */ |
16107 | val = MAYBE_SWAP (total_len); | |
16108 | obstack_grow (&contents, &val, sizeof (val)); | |
16109 | total_len += obstack_object_size (&addr_obstack); | |
16110 | ||
16111 | /* The offset of the symbol table from the start of the file. */ | |
16112 | val = MAYBE_SWAP (total_len); | |
16113 | obstack_grow (&contents, &val, sizeof (val)); | |
16114 | total_len += obstack_object_size (&symtab_obstack); | |
16115 | ||
16116 | /* The offset of the constant pool from the start of the file. */ | |
16117 | val = MAYBE_SWAP (total_len); | |
16118 | obstack_grow (&contents, &val, sizeof (val)); | |
16119 | total_len += obstack_object_size (&constant_pool); | |
16120 | ||
16121 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
16122 | ||
16123 | write_obstack (out_file, &contents); | |
16124 | write_obstack (out_file, &cu_list); | |
1fd400ff | 16125 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
16126 | write_obstack (out_file, &addr_obstack); |
16127 | write_obstack (out_file, &symtab_obstack); | |
16128 | write_obstack (out_file, &constant_pool); | |
16129 | ||
16130 | fclose (out_file); | |
16131 | ||
16132 | /* We want to keep the file, so we set cleanup_filename to NULL | |
16133 | here. See unlink_if_set. */ | |
16134 | cleanup_filename = NULL; | |
16135 | ||
16136 | do_cleanups (cleanup); | |
16137 | } | |
16138 | ||
90476074 TT |
16139 | /* Implementation of the `save gdb-index' command. |
16140 | ||
16141 | Note that the file format used by this command is documented in the | |
16142 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 16143 | |
9291a0cd TT |
16144 | static void |
16145 | save_gdb_index_command (char *arg, int from_tty) | |
16146 | { | |
16147 | struct objfile *objfile; | |
16148 | ||
16149 | if (!arg || !*arg) | |
96d19272 | 16150 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
16151 | |
16152 | ALL_OBJFILES (objfile) | |
16153 | { | |
16154 | struct stat st; | |
16155 | ||
16156 | /* If the objfile does not correspond to an actual file, skip it. */ | |
16157 | if (stat (objfile->name, &st) < 0) | |
16158 | continue; | |
16159 | ||
16160 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
16161 | if (dwarf2_per_objfile) | |
16162 | { | |
16163 | volatile struct gdb_exception except; | |
16164 | ||
16165 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
16166 | { | |
16167 | write_psymtabs_to_index (objfile, arg); | |
16168 | } | |
16169 | if (except.reason < 0) | |
16170 | exception_fprintf (gdb_stderr, except, | |
16171 | _("Error while writing index for `%s': "), | |
16172 | objfile->name); | |
16173 | } | |
16174 | } | |
dce234bc PP |
16175 | } |
16176 | ||
9291a0cd TT |
16177 | \f |
16178 | ||
9eae7c52 TT |
16179 | int dwarf2_always_disassemble; |
16180 | ||
16181 | static void | |
16182 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
16183 | struct cmd_list_element *c, const char *value) | |
16184 | { | |
3e43a32a MS |
16185 | fprintf_filtered (file, |
16186 | _("Whether to always disassemble " | |
16187 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
16188 | value); |
16189 | } | |
16190 | ||
6502dd73 DJ |
16191 | void _initialize_dwarf2_read (void); |
16192 | ||
16193 | void | |
16194 | _initialize_dwarf2_read (void) | |
16195 | { | |
96d19272 JK |
16196 | struct cmd_list_element *c; |
16197 | ||
dce234bc | 16198 | dwarf2_objfile_data_key |
c1bd65d0 | 16199 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 16200 | |
1bedd215 AC |
16201 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
16202 | Set DWARF 2 specific variables.\n\ | |
16203 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
16204 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
16205 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
16206 | ||
1bedd215 AC |
16207 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
16208 | Show DWARF 2 specific variables\n\ | |
16209 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
16210 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
16211 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
16212 | ||
16213 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
16214 | &dwarf2_max_cache_age, _("\ |
16215 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
16216 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
16217 | A higher limit means that cached compilation units will be stored\n\ | |
16218 | in memory longer, and more total memory will be used. Zero disables\n\ | |
16219 | caching, which can slow down startup."), | |
2c5b56ce | 16220 | NULL, |
920d2a44 | 16221 | show_dwarf2_max_cache_age, |
2c5b56ce | 16222 | &set_dwarf2_cmdlist, |
ae038cb0 | 16223 | &show_dwarf2_cmdlist); |
d97bc12b | 16224 | |
9eae7c52 TT |
16225 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
16226 | &dwarf2_always_disassemble, _("\ | |
16227 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
16228 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
16229 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
16230 | syntax. When disabled, expressions will be printed in a more\n\ | |
16231 | conversational style, when possible."), | |
16232 | NULL, | |
16233 | show_dwarf2_always_disassemble, | |
16234 | &set_dwarf2_cmdlist, | |
16235 | &show_dwarf2_cmdlist); | |
16236 | ||
d97bc12b DE |
16237 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
16238 | Set debugging of the dwarf2 DIE reader."), _("\ | |
16239 | Show debugging of the dwarf2 DIE reader."), _("\ | |
16240 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
16241 | The value is the maximum depth to print."), | |
16242 | NULL, | |
16243 | NULL, | |
16244 | &setdebuglist, &showdebuglist); | |
9291a0cd | 16245 | |
96d19272 | 16246 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 16247 | _("\ |
fc1a9d6e | 16248 | Save a gdb-index file.\n\ |
11570e71 | 16249 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
16250 | &save_cmdlist); |
16251 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 16252 | } |