Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
0b302171 | 3 | Copyright (C) 1994-2012 Free Software Foundation, Inc. |
c906108c SS |
4 | |
5 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
6 | Inc. with support from Florida State University (under contract | |
7 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
8 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
9 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 10 | support. |
c906108c | 11 | |
c5aa993b | 12 | This file is part of GDB. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is free software; you can redistribute it and/or modify |
15 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
16 | the Free Software Foundation; either version 3 of the License, or |
17 | (at your option) any later version. | |
c906108c | 18 | |
a9762ec7 JB |
19 | This program is distributed in the hope that it will be useful, |
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | GNU General Public License for more details. | |
c906108c | 23 | |
c5aa993b | 24 | You should have received a copy of the GNU General Public License |
a9762ec7 | 25 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 26 | |
21b2bd31 DE |
27 | /* FIXME: Various die-reading functions need to be more careful with |
28 | reading off the end of the section. | |
29 | E.g., load_partial_dies, read_partial_die. */ | |
30 | ||
c906108c SS |
31 | #include "defs.h" |
32 | #include "bfd.h" | |
c906108c SS |
33 | #include "symtab.h" |
34 | #include "gdbtypes.h" | |
c906108c | 35 | #include "objfiles.h" |
fa8f86ff | 36 | #include "dwarf2.h" |
c906108c SS |
37 | #include "buildsym.h" |
38 | #include "demangle.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
c906108c | 40 | #include "expression.h" |
d5166ae1 | 41 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 42 | #include "macrotab.h" |
c906108c SS |
43 | #include "language.h" |
44 | #include "complaints.h" | |
357e46e7 | 45 | #include "bcache.h" |
4c2df51b DJ |
46 | #include "dwarf2expr.h" |
47 | #include "dwarf2loc.h" | |
9219021c | 48 | #include "cp-support.h" |
72bf9492 | 49 | #include "hashtab.h" |
ae038cb0 DJ |
50 | #include "command.h" |
51 | #include "gdbcmd.h" | |
edb3359d | 52 | #include "block.h" |
ff013f42 | 53 | #include "addrmap.h" |
94af9270 KS |
54 | #include "typeprint.h" |
55 | #include "jv-lang.h" | |
ccefe4c4 | 56 | #include "psympriv.h" |
9291a0cd TT |
57 | #include "exceptions.h" |
58 | #include "gdb_stat.h" | |
96d19272 | 59 | #include "completer.h" |
34eaf542 | 60 | #include "vec.h" |
98bfdba5 PA |
61 | #include "c-lang.h" |
62 | #include "valprint.h" | |
60d5a603 | 63 | #include <ctype.h> |
4c2df51b | 64 | |
c906108c SS |
65 | #include <fcntl.h> |
66 | #include "gdb_string.h" | |
4bdf3d34 | 67 | #include "gdb_assert.h" |
c906108c | 68 | #include <sys/types.h> |
233a11ab CS |
69 | #ifdef HAVE_ZLIB_H |
70 | #include <zlib.h> | |
71 | #endif | |
dce234bc PP |
72 | #ifdef HAVE_MMAP |
73 | #include <sys/mman.h> | |
85d9bd0e TT |
74 | #ifndef MAP_FAILED |
75 | #define MAP_FAILED ((void *) -1) | |
76 | #endif | |
dce234bc | 77 | #endif |
d8151005 | 78 | |
34eaf542 TT |
79 | typedef struct symbol *symbolp; |
80 | DEF_VEC_P (symbolp); | |
81 | ||
d97bc12b DE |
82 | /* When non-zero, dump DIEs after they are read in. */ |
83 | static int dwarf2_die_debug = 0; | |
84 | ||
900e11f9 JK |
85 | /* When non-zero, cross-check physname against demangler. */ |
86 | static int check_physname = 0; | |
87 | ||
dce234bc PP |
88 | static int pagesize; |
89 | ||
df8a16a1 DJ |
90 | /* When set, the file that we're processing is known to have debugging |
91 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
92 | but later versions do. */ | |
93 | ||
94 | static int processing_has_namespace_info; | |
95 | ||
6502dd73 DJ |
96 | static const struct objfile_data *dwarf2_objfile_data_key; |
97 | ||
dce234bc PP |
98 | struct dwarf2_section_info |
99 | { | |
100 | asection *asection; | |
101 | gdb_byte *buffer; | |
102 | bfd_size_type size; | |
b315ab21 TG |
103 | /* Not NULL if the section was actually mmapped. */ |
104 | void *map_addr; | |
105 | /* Page aligned size of mmapped area. */ | |
106 | bfd_size_type map_len; | |
be391dca TT |
107 | /* True if we have tried to read this section. */ |
108 | int readin; | |
dce234bc PP |
109 | }; |
110 | ||
8b70b953 TT |
111 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
112 | DEF_VEC_O (dwarf2_section_info_def); | |
113 | ||
9291a0cd TT |
114 | /* All offsets in the index are of this type. It must be |
115 | architecture-independent. */ | |
116 | typedef uint32_t offset_type; | |
117 | ||
118 | DEF_VEC_I (offset_type); | |
119 | ||
120 | /* A description of the mapped index. The file format is described in | |
121 | a comment by the code that writes the index. */ | |
122 | struct mapped_index | |
123 | { | |
559a7a62 JK |
124 | /* Index data format version. */ |
125 | int version; | |
126 | ||
9291a0cd TT |
127 | /* The total length of the buffer. */ |
128 | off_t total_size; | |
b11b1f88 | 129 | |
9291a0cd TT |
130 | /* A pointer to the address table data. */ |
131 | const gdb_byte *address_table; | |
b11b1f88 | 132 | |
9291a0cd TT |
133 | /* Size of the address table data in bytes. */ |
134 | offset_type address_table_size; | |
b11b1f88 | 135 | |
3876f04e DE |
136 | /* The symbol table, implemented as a hash table. */ |
137 | const offset_type *symbol_table; | |
b11b1f88 | 138 | |
9291a0cd | 139 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 140 | offset_type symbol_table_slots; |
b11b1f88 | 141 | |
9291a0cd TT |
142 | /* A pointer to the constant pool. */ |
143 | const char *constant_pool; | |
144 | }; | |
145 | ||
9cdd5dbd DE |
146 | /* Collection of data recorded per objfile. |
147 | This hangs off of dwarf2_objfile_data_key. */ | |
148 | ||
6502dd73 DJ |
149 | struct dwarf2_per_objfile |
150 | { | |
dce234bc PP |
151 | struct dwarf2_section_info info; |
152 | struct dwarf2_section_info abbrev; | |
153 | struct dwarf2_section_info line; | |
dce234bc PP |
154 | struct dwarf2_section_info loc; |
155 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 156 | struct dwarf2_section_info macro; |
dce234bc PP |
157 | struct dwarf2_section_info str; |
158 | struct dwarf2_section_info ranges; | |
159 | struct dwarf2_section_info frame; | |
160 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 161 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 162 | |
8b70b953 TT |
163 | VEC (dwarf2_section_info_def) *types; |
164 | ||
be391dca TT |
165 | /* Back link. */ |
166 | struct objfile *objfile; | |
167 | ||
d467dd73 | 168 | /* Table of all the compilation units. This is used to locate |
10b3939b | 169 | the target compilation unit of a particular reference. */ |
ae038cb0 DJ |
170 | struct dwarf2_per_cu_data **all_comp_units; |
171 | ||
172 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
173 | int n_comp_units; | |
174 | ||
1fd400ff | 175 | /* The number of .debug_types-related CUs. */ |
d467dd73 | 176 | int n_type_units; |
1fd400ff | 177 | |
d467dd73 DE |
178 | /* The .debug_types-related CUs (TUs). */ |
179 | struct dwarf2_per_cu_data **all_type_units; | |
1fd400ff | 180 | |
ae038cb0 DJ |
181 | /* A chain of compilation units that are currently read in, so that |
182 | they can be freed later. */ | |
183 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 184 | |
348e048f DE |
185 | /* A table mapping .debug_types signatures to its signatured_type entry. |
186 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
187 | htab_t signatured_types; | |
188 | ||
72dca2f5 FR |
189 | /* A flag indicating wether this objfile has a section loaded at a |
190 | VMA of 0. */ | |
191 | int has_section_at_zero; | |
9291a0cd | 192 | |
ae2de4f8 DE |
193 | /* True if we are using the mapped index, |
194 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
195 | unsigned char using_index; |
196 | ||
ae2de4f8 | 197 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 198 | struct mapped_index *index_table; |
98bfdba5 | 199 | |
7b9f3c50 DE |
200 | /* When using index_table, this keeps track of all quick_file_names entries. |
201 | TUs can share line table entries with CUs or other TUs, and there can be | |
202 | a lot more TUs than unique line tables, so we maintain a separate table | |
203 | of all line table entries to support the sharing. */ | |
204 | htab_t quick_file_names_table; | |
205 | ||
98bfdba5 PA |
206 | /* Set during partial symbol reading, to prevent queueing of full |
207 | symbols. */ | |
208 | int reading_partial_symbols; | |
673bfd45 DE |
209 | |
210 | /* Table mapping type .debug_info DIE offsets to types. | |
211 | This is NULL if not allocated yet. | |
212 | It (currently) makes sense to allocate debug_types_type_hash lazily. | |
213 | To keep things simple we allocate both lazily. */ | |
214 | htab_t debug_info_type_hash; | |
215 | ||
216 | /* Table mapping type .debug_types DIE offsets to types. | |
217 | This is NULL if not allocated yet. */ | |
218 | htab_t debug_types_type_hash; | |
6502dd73 DJ |
219 | }; |
220 | ||
221 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 222 | |
251d32d9 | 223 | /* Default names of the debugging sections. */ |
c906108c | 224 | |
233a11ab CS |
225 | /* Note that if the debugging section has been compressed, it might |
226 | have a name like .zdebug_info. */ | |
227 | ||
9cdd5dbd DE |
228 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
229 | { | |
251d32d9 TG |
230 | { ".debug_info", ".zdebug_info" }, |
231 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
232 | { ".debug_line", ".zdebug_line" }, | |
233 | { ".debug_loc", ".zdebug_loc" }, | |
234 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 235 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
236 | { ".debug_str", ".zdebug_str" }, |
237 | { ".debug_ranges", ".zdebug_ranges" }, | |
238 | { ".debug_types", ".zdebug_types" }, | |
239 | { ".debug_frame", ".zdebug_frame" }, | |
240 | { ".eh_frame", NULL }, | |
24d3216f TT |
241 | { ".gdb_index", ".zgdb_index" }, |
242 | 23 | |
251d32d9 | 243 | }; |
c906108c SS |
244 | |
245 | /* local data types */ | |
246 | ||
0963b4bd | 247 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
248 | #ifndef ABBREV_HASH_SIZE |
249 | #define ABBREV_HASH_SIZE 121 | |
250 | #endif | |
251 | ||
107d2387 AC |
252 | /* The data in a compilation unit header, after target2host |
253 | translation, looks like this. */ | |
c906108c | 254 | struct comp_unit_head |
a738430d | 255 | { |
c764a876 | 256 | unsigned int length; |
a738430d | 257 | short version; |
a738430d MK |
258 | unsigned char addr_size; |
259 | unsigned char signed_addr_p; | |
9cbfa09e | 260 | unsigned int abbrev_offset; |
57349743 | 261 | |
a738430d MK |
262 | /* Size of file offsets; either 4 or 8. */ |
263 | unsigned int offset_size; | |
57349743 | 264 | |
a738430d MK |
265 | /* Size of the length field; either 4 or 12. */ |
266 | unsigned int initial_length_size; | |
57349743 | 267 | |
a738430d MK |
268 | /* Offset to the first byte of this compilation unit header in the |
269 | .debug_info section, for resolving relative reference dies. */ | |
270 | unsigned int offset; | |
57349743 | 271 | |
d00adf39 DE |
272 | /* Offset to first die in this cu from the start of the cu. |
273 | This will be the first byte following the compilation unit header. */ | |
274 | unsigned int first_die_offset; | |
a738430d | 275 | }; |
c906108c | 276 | |
3da10d80 KS |
277 | /* Type used for delaying computation of method physnames. |
278 | See comments for compute_delayed_physnames. */ | |
279 | struct delayed_method_info | |
280 | { | |
281 | /* The type to which the method is attached, i.e., its parent class. */ | |
282 | struct type *type; | |
283 | ||
284 | /* The index of the method in the type's function fieldlists. */ | |
285 | int fnfield_index; | |
286 | ||
287 | /* The index of the method in the fieldlist. */ | |
288 | int index; | |
289 | ||
290 | /* The name of the DIE. */ | |
291 | const char *name; | |
292 | ||
293 | /* The DIE associated with this method. */ | |
294 | struct die_info *die; | |
295 | }; | |
296 | ||
297 | typedef struct delayed_method_info delayed_method_info; | |
298 | DEF_VEC_O (delayed_method_info); | |
299 | ||
e7c27a73 DJ |
300 | /* Internal state when decoding a particular compilation unit. */ |
301 | struct dwarf2_cu | |
302 | { | |
303 | /* The objfile containing this compilation unit. */ | |
304 | struct objfile *objfile; | |
305 | ||
d00adf39 | 306 | /* The header of the compilation unit. */ |
e7c27a73 | 307 | struct comp_unit_head header; |
e142c38c | 308 | |
d00adf39 DE |
309 | /* Base address of this compilation unit. */ |
310 | CORE_ADDR base_address; | |
311 | ||
312 | /* Non-zero if base_address has been set. */ | |
313 | int base_known; | |
314 | ||
e142c38c DJ |
315 | /* The language we are debugging. */ |
316 | enum language language; | |
317 | const struct language_defn *language_defn; | |
318 | ||
b0f35d58 DL |
319 | const char *producer; |
320 | ||
e142c38c DJ |
321 | /* The generic symbol table building routines have separate lists for |
322 | file scope symbols and all all other scopes (local scopes). So | |
323 | we need to select the right one to pass to add_symbol_to_list(). | |
324 | We do it by keeping a pointer to the correct list in list_in_scope. | |
325 | ||
326 | FIXME: The original dwarf code just treated the file scope as the | |
327 | first local scope, and all other local scopes as nested local | |
328 | scopes, and worked fine. Check to see if we really need to | |
329 | distinguish these in buildsym.c. */ | |
330 | struct pending **list_in_scope; | |
331 | ||
f3dd6933 DJ |
332 | /* DWARF abbreviation table associated with this compilation unit. */ |
333 | struct abbrev_info **dwarf2_abbrevs; | |
334 | ||
335 | /* Storage for the abbrev table. */ | |
336 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
337 | |
338 | /* Hash table holding all the loaded partial DIEs. */ | |
339 | htab_t partial_dies; | |
340 | ||
341 | /* Storage for things with the same lifetime as this read-in compilation | |
342 | unit, including partial DIEs. */ | |
343 | struct obstack comp_unit_obstack; | |
344 | ||
ae038cb0 DJ |
345 | /* When multiple dwarf2_cu structures are living in memory, this field |
346 | chains them all together, so that they can be released efficiently. | |
347 | We will probably also want a generation counter so that most-recently-used | |
348 | compilation units are cached... */ | |
349 | struct dwarf2_per_cu_data *read_in_chain; | |
350 | ||
351 | /* Backchain to our per_cu entry if the tree has been built. */ | |
352 | struct dwarf2_per_cu_data *per_cu; | |
353 | ||
354 | /* How many compilation units ago was this CU last referenced? */ | |
355 | int last_used; | |
356 | ||
10b3939b | 357 | /* A hash table of die offsets for following references. */ |
51545339 | 358 | htab_t die_hash; |
10b3939b DJ |
359 | |
360 | /* Full DIEs if read in. */ | |
361 | struct die_info *dies; | |
362 | ||
363 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
364 | units referenced by this one. Only set during full symbol processing; | |
365 | partial symbol tables do not have dependencies. */ | |
366 | htab_t dependencies; | |
367 | ||
cb1df416 DJ |
368 | /* Header data from the line table, during full symbol processing. */ |
369 | struct line_header *line_header; | |
370 | ||
3da10d80 KS |
371 | /* A list of methods which need to have physnames computed |
372 | after all type information has been read. */ | |
373 | VEC (delayed_method_info) *method_list; | |
374 | ||
96408a79 SA |
375 | /* To be copied to symtab->call_site_htab. */ |
376 | htab_t call_site_htab; | |
377 | ||
ae038cb0 DJ |
378 | /* Mark used when releasing cached dies. */ |
379 | unsigned int mark : 1; | |
380 | ||
381 | /* This flag will be set if this compilation unit might include | |
382 | inter-compilation-unit references. */ | |
383 | unsigned int has_form_ref_addr : 1; | |
384 | ||
72bf9492 DJ |
385 | /* This flag will be set if this compilation unit includes any |
386 | DW_TAG_namespace DIEs. If we know that there are explicit | |
387 | DIEs for namespaces, we don't need to try to infer them | |
388 | from mangled names. */ | |
389 | unsigned int has_namespace_info : 1; | |
8be455d7 JK |
390 | |
391 | /* This CU references .debug_loc. See the symtab->locations_valid field. | |
392 | This test is imperfect as there may exist optimized debug code not using | |
393 | any location list and still facing inlining issues if handled as | |
394 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 395 | unsigned int has_loclist : 1; |
e7c27a73 DJ |
396 | }; |
397 | ||
10b3939b DJ |
398 | /* Persistent data held for a compilation unit, even when not |
399 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 400 | read_symtab_private field of the psymtab. */ |
10b3939b | 401 | |
ae038cb0 DJ |
402 | struct dwarf2_per_cu_data |
403 | { | |
348e048f | 404 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 405 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
406 | - if it doesn't, GDB will fall over anyway. |
407 | NOTE: Unlike comp_unit_head.length, this length includes | |
408 | initial_length_size. */ | |
c764a876 | 409 | unsigned int offset; |
348e048f | 410 | unsigned int length : 29; |
ae038cb0 DJ |
411 | |
412 | /* Flag indicating this compilation unit will be read in before | |
413 | any of the current compilation units are processed. */ | |
c764a876 | 414 | unsigned int queued : 1; |
ae038cb0 | 415 | |
5afb4e99 DJ |
416 | /* This flag will be set if we need to load absolutely all DIEs |
417 | for this compilation unit, instead of just the ones we think | |
418 | are interesting. It gets set if we look for a DIE in the | |
419 | hash table and don't find it. */ | |
420 | unsigned int load_all_dies : 1; | |
421 | ||
8b70b953 TT |
422 | /* Non-null if this CU is from .debug_types; in which case it points |
423 | to the section. Otherwise it's from .debug_info. */ | |
b0df02fd | 424 | struct dwarf2_section_info *debug_types_section; |
348e048f | 425 | |
17ea53c3 JK |
426 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
427 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 428 | struct dwarf2_cu *cu; |
1c379e20 | 429 | |
9cdd5dbd DE |
430 | /* The corresponding objfile. |
431 | Normally we can get the objfile from dwarf2_per_objfile. | |
432 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
433 | struct objfile *objfile; |
434 | ||
435 | /* When using partial symbol tables, the 'psymtab' field is active. | |
436 | Otherwise the 'quick' field is active. */ | |
437 | union | |
438 | { | |
439 | /* The partial symbol table associated with this compilation unit, | |
440 | or NULL for partial units (which do not have an associated | |
441 | symtab). */ | |
442 | struct partial_symtab *psymtab; | |
443 | ||
444 | /* Data needed by the "quick" functions. */ | |
445 | struct dwarf2_per_cu_quick_data *quick; | |
446 | } v; | |
ae038cb0 DJ |
447 | }; |
448 | ||
348e048f DE |
449 | /* Entry in the signatured_types hash table. */ |
450 | ||
451 | struct signatured_type | |
452 | { | |
453 | ULONGEST signature; | |
454 | ||
348e048f DE |
455 | /* Offset in .debug_types of the type defined by this TU. */ |
456 | unsigned int type_offset; | |
457 | ||
458 | /* The CU(/TU) of this type. */ | |
459 | struct dwarf2_per_cu_data per_cu; | |
460 | }; | |
461 | ||
0963b4bd MS |
462 | /* Struct used to pass misc. parameters to read_die_and_children, et |
463 | al. which are used for both .debug_info and .debug_types dies. | |
464 | All parameters here are unchanging for the life of the call. This | |
465 | struct exists to abstract away the constant parameters of die | |
466 | reading. */ | |
93311388 DE |
467 | |
468 | struct die_reader_specs | |
469 | { | |
470 | /* The bfd of this objfile. */ | |
471 | bfd* abfd; | |
472 | ||
473 | /* The CU of the DIE we are parsing. */ | |
474 | struct dwarf2_cu *cu; | |
475 | ||
476 | /* Pointer to start of section buffer. | |
477 | This is either the start of .debug_info or .debug_types. */ | |
478 | const gdb_byte *buffer; | |
479 | }; | |
480 | ||
debd256d JB |
481 | /* The line number information for a compilation unit (found in the |
482 | .debug_line section) begins with a "statement program header", | |
483 | which contains the following information. */ | |
484 | struct line_header | |
485 | { | |
486 | unsigned int total_length; | |
487 | unsigned short version; | |
488 | unsigned int header_length; | |
489 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 490 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
491 | unsigned char default_is_stmt; |
492 | int line_base; | |
493 | unsigned char line_range; | |
494 | unsigned char opcode_base; | |
495 | ||
496 | /* standard_opcode_lengths[i] is the number of operands for the | |
497 | standard opcode whose value is i. This means that | |
498 | standard_opcode_lengths[0] is unused, and the last meaningful | |
499 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
500 | unsigned char *standard_opcode_lengths; | |
501 | ||
502 | /* The include_directories table. NOTE! These strings are not | |
503 | allocated with xmalloc; instead, they are pointers into | |
504 | debug_line_buffer. If you try to free them, `free' will get | |
505 | indigestion. */ | |
506 | unsigned int num_include_dirs, include_dirs_size; | |
507 | char **include_dirs; | |
508 | ||
509 | /* The file_names table. NOTE! These strings are not allocated | |
510 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
511 | Don't try to free them directly. */ | |
512 | unsigned int num_file_names, file_names_size; | |
513 | struct file_entry | |
c906108c | 514 | { |
debd256d JB |
515 | char *name; |
516 | unsigned int dir_index; | |
517 | unsigned int mod_time; | |
518 | unsigned int length; | |
aaa75496 | 519 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 520 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
521 | } *file_names; |
522 | ||
523 | /* The start and end of the statement program following this | |
6502dd73 | 524 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 525 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 526 | }; |
c906108c SS |
527 | |
528 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 529 | need this much information. */ |
c906108c SS |
530 | struct partial_die_info |
531 | { | |
72bf9492 | 532 | /* Offset of this DIE. */ |
c906108c | 533 | unsigned int offset; |
72bf9492 DJ |
534 | |
535 | /* DWARF-2 tag for this DIE. */ | |
536 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
537 | ||
72bf9492 DJ |
538 | /* Assorted flags describing the data found in this DIE. */ |
539 | unsigned int has_children : 1; | |
540 | unsigned int is_external : 1; | |
541 | unsigned int is_declaration : 1; | |
542 | unsigned int has_type : 1; | |
543 | unsigned int has_specification : 1; | |
544 | unsigned int has_pc_info : 1; | |
545 | ||
546 | /* Flag set if the SCOPE field of this structure has been | |
547 | computed. */ | |
548 | unsigned int scope_set : 1; | |
549 | ||
fa4028e9 JB |
550 | /* Flag set if the DIE has a byte_size attribute. */ |
551 | unsigned int has_byte_size : 1; | |
552 | ||
98bfdba5 PA |
553 | /* Flag set if any of the DIE's children are template arguments. */ |
554 | unsigned int has_template_arguments : 1; | |
555 | ||
abc72ce4 DE |
556 | /* Flag set if fixup_partial_die has been called on this die. */ |
557 | unsigned int fixup_called : 1; | |
558 | ||
72bf9492 | 559 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 560 | sometimes a default name for unnamed DIEs. */ |
c906108c | 561 | char *name; |
72bf9492 | 562 | |
abc72ce4 DE |
563 | /* The linkage name, if present. */ |
564 | const char *linkage_name; | |
565 | ||
72bf9492 DJ |
566 | /* The scope to prepend to our children. This is generally |
567 | allocated on the comp_unit_obstack, so will disappear | |
568 | when this compilation unit leaves the cache. */ | |
569 | char *scope; | |
570 | ||
571 | /* The location description associated with this DIE, if any. */ | |
572 | struct dwarf_block *locdesc; | |
573 | ||
574 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
575 | CORE_ADDR lowpc; |
576 | CORE_ADDR highpc; | |
72bf9492 | 577 | |
93311388 | 578 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 579 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
580 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
581 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 582 | gdb_byte *sibling; |
72bf9492 DJ |
583 | |
584 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
585 | DW_AT_specification (or DW_AT_abstract_origin or | |
586 | DW_AT_extension). */ | |
587 | unsigned int spec_offset; | |
588 | ||
589 | /* Pointers to this DIE's parent, first child, and next sibling, | |
590 | if any. */ | |
591 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
592 | }; |
593 | ||
0963b4bd | 594 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
595 | struct abbrev_info |
596 | { | |
597 | unsigned int number; /* number identifying abbrev */ | |
598 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
599 | unsigned short has_children; /* boolean */ |
600 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
601 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
602 | struct abbrev_info *next; /* next in chain */ | |
603 | }; | |
604 | ||
605 | struct attr_abbrev | |
606 | { | |
9d25dd43 DE |
607 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
608 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
609 | }; |
610 | ||
0963b4bd | 611 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
612 | struct attribute |
613 | { | |
9d25dd43 | 614 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
615 | ENUM_BITFIELD(dwarf_form) form : 15; |
616 | ||
617 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
618 | field should be in u.str (existing only for DW_STRING) but it is kept | |
619 | here for better struct attribute alignment. */ | |
620 | unsigned int string_is_canonical : 1; | |
621 | ||
b60c80d6 DJ |
622 | union |
623 | { | |
624 | char *str; | |
625 | struct dwarf_block *blk; | |
43bbcdc2 PH |
626 | ULONGEST unsnd; |
627 | LONGEST snd; | |
b60c80d6 | 628 | CORE_ADDR addr; |
348e048f | 629 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
630 | } |
631 | u; | |
632 | }; | |
633 | ||
0963b4bd | 634 | /* This data structure holds a complete die structure. */ |
c906108c SS |
635 | struct die_info |
636 | { | |
76815b17 DE |
637 | /* DWARF-2 tag for this DIE. */ |
638 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
639 | ||
640 | /* Number of attributes */ | |
98bfdba5 PA |
641 | unsigned char num_attrs; |
642 | ||
643 | /* True if we're presently building the full type name for the | |
644 | type derived from this DIE. */ | |
645 | unsigned char building_fullname : 1; | |
76815b17 DE |
646 | |
647 | /* Abbrev number */ | |
648 | unsigned int abbrev; | |
649 | ||
93311388 | 650 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 651 | unsigned int offset; |
78ba4af6 JB |
652 | |
653 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
654 | points to this die's parent; CHILD points to the first child of | |
655 | this node; and all the children of a given node are chained | |
4950bc1c | 656 | together via their SIBLING fields. */ |
639d11d3 DC |
657 | struct die_info *child; /* Its first child, if any. */ |
658 | struct die_info *sibling; /* Its next sibling, if any. */ | |
659 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 660 | |
b60c80d6 DJ |
661 | /* An array of attributes, with NUM_ATTRS elements. There may be |
662 | zero, but it's not common and zero-sized arrays are not | |
663 | sufficiently portable C. */ | |
664 | struct attribute attrs[1]; | |
c906108c SS |
665 | }; |
666 | ||
0963b4bd | 667 | /* Get at parts of an attribute structure. */ |
c906108c SS |
668 | |
669 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 670 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
671 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
672 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
673 | #define DW_SND(attr) ((attr)->u.snd) | |
674 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 675 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 676 | |
0963b4bd | 677 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
678 | struct dwarf_block |
679 | { | |
680 | unsigned int size; | |
1d6edc3c JK |
681 | |
682 | /* Valid only if SIZE is not zero. */ | |
fe1b8b76 | 683 | gdb_byte *data; |
c906108c SS |
684 | }; |
685 | ||
c906108c SS |
686 | #ifndef ATTR_ALLOC_CHUNK |
687 | #define ATTR_ALLOC_CHUNK 4 | |
688 | #endif | |
689 | ||
c906108c SS |
690 | /* Allocate fields for structs, unions and enums in this size. */ |
691 | #ifndef DW_FIELD_ALLOC_CHUNK | |
692 | #define DW_FIELD_ALLOC_CHUNK 4 | |
693 | #endif | |
694 | ||
c906108c SS |
695 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
696 | but this would require a corresponding change in unpack_field_as_long | |
697 | and friends. */ | |
698 | static int bits_per_byte = 8; | |
699 | ||
700 | /* The routines that read and process dies for a C struct or C++ class | |
701 | pass lists of data member fields and lists of member function fields | |
702 | in an instance of a field_info structure, as defined below. */ | |
703 | struct field_info | |
c5aa993b | 704 | { |
0963b4bd | 705 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
706 | struct nextfield |
707 | { | |
708 | struct nextfield *next; | |
709 | int accessibility; | |
710 | int virtuality; | |
711 | struct field field; | |
712 | } | |
7d0ccb61 | 713 | *fields, *baseclasses; |
c906108c | 714 | |
7d0ccb61 | 715 | /* Number of fields (including baseclasses). */ |
c5aa993b | 716 | int nfields; |
c906108c | 717 | |
c5aa993b JM |
718 | /* Number of baseclasses. */ |
719 | int nbaseclasses; | |
c906108c | 720 | |
c5aa993b JM |
721 | /* Set if the accesibility of one of the fields is not public. */ |
722 | int non_public_fields; | |
c906108c | 723 | |
c5aa993b JM |
724 | /* Member function fields array, entries are allocated in the order they |
725 | are encountered in the object file. */ | |
726 | struct nextfnfield | |
727 | { | |
728 | struct nextfnfield *next; | |
729 | struct fn_field fnfield; | |
730 | } | |
731 | *fnfields; | |
c906108c | 732 | |
c5aa993b JM |
733 | /* Member function fieldlist array, contains name of possibly overloaded |
734 | member function, number of overloaded member functions and a pointer | |
735 | to the head of the member function field chain. */ | |
736 | struct fnfieldlist | |
737 | { | |
738 | char *name; | |
739 | int length; | |
740 | struct nextfnfield *head; | |
741 | } | |
742 | *fnfieldlists; | |
c906108c | 743 | |
c5aa993b JM |
744 | /* Number of entries in the fnfieldlists array. */ |
745 | int nfnfields; | |
98751a41 JK |
746 | |
747 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
748 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
749 | struct typedef_field_list | |
750 | { | |
751 | struct typedef_field field; | |
752 | struct typedef_field_list *next; | |
753 | } | |
754 | *typedef_field_list; | |
755 | unsigned typedef_field_list_count; | |
c5aa993b | 756 | }; |
c906108c | 757 | |
10b3939b DJ |
758 | /* One item on the queue of compilation units to read in full symbols |
759 | for. */ | |
760 | struct dwarf2_queue_item | |
761 | { | |
762 | struct dwarf2_per_cu_data *per_cu; | |
763 | struct dwarf2_queue_item *next; | |
764 | }; | |
765 | ||
766 | /* The current queue. */ | |
767 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
768 | ||
ae038cb0 DJ |
769 | /* Loaded secondary compilation units are kept in memory until they |
770 | have not been referenced for the processing of this many | |
771 | compilation units. Set this to zero to disable caching. Cache | |
772 | sizes of up to at least twenty will improve startup time for | |
773 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
774 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
775 | static void |
776 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
777 | struct cmd_list_element *c, const char *value) | |
778 | { | |
3e43a32a MS |
779 | fprintf_filtered (file, _("The upper bound on the age of cached " |
780 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
781 | value); |
782 | } | |
783 | ||
ae038cb0 | 784 | |
0963b4bd | 785 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 786 | |
4d3c2250 KB |
787 | static void |
788 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 789 | { |
4d3c2250 | 790 | complaint (&symfile_complaints, |
e2e0b3e5 | 791 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
792 | } |
793 | ||
25e43795 DJ |
794 | static void |
795 | dwarf2_debug_line_missing_file_complaint (void) | |
796 | { | |
797 | complaint (&symfile_complaints, | |
798 | _(".debug_line section has line data without a file")); | |
799 | } | |
800 | ||
59205f5a JB |
801 | static void |
802 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
803 | { | |
804 | complaint (&symfile_complaints, | |
3e43a32a MS |
805 | _(".debug_line section has line " |
806 | "program sequence without an end")); | |
59205f5a JB |
807 | } |
808 | ||
4d3c2250 KB |
809 | static void |
810 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 811 | { |
e2e0b3e5 | 812 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
813 | } |
814 | ||
4d3c2250 KB |
815 | static void |
816 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
817 | int arg3) | |
2e276125 | 818 | { |
4d3c2250 | 819 | complaint (&symfile_complaints, |
3e43a32a MS |
820 | _("const value length mismatch for '%s', got %d, expected %d"), |
821 | arg1, arg2, arg3); | |
4d3c2250 KB |
822 | } |
823 | ||
824 | static void | |
cf2c3c16 | 825 | dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section) |
2e276125 | 826 | { |
4d3c2250 | 827 | complaint (&symfile_complaints, |
cf2c3c16 TT |
828 | _("macro info runs off end of `%s' section"), |
829 | section->asection->name); | |
4d3c2250 KB |
830 | } |
831 | ||
832 | static void | |
833 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 834 | { |
4d3c2250 | 835 | complaint (&symfile_complaints, |
3e43a32a MS |
836 | _("macro debug info contains a " |
837 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
838 | arg1); |
839 | } | |
840 | ||
841 | static void | |
842 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 843 | { |
4d3c2250 | 844 | complaint (&symfile_complaints, |
3e43a32a MS |
845 | _("invalid attribute class or form for '%s' in '%s'"), |
846 | arg1, arg2); | |
4d3c2250 | 847 | } |
c906108c | 848 | |
c906108c SS |
849 | /* local function prototypes */ |
850 | ||
4efb68b1 | 851 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 852 | |
aaa75496 JB |
853 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
854 | struct objfile *); | |
855 | ||
918dd910 JK |
856 | static void dwarf2_find_base_address (struct die_info *die, |
857 | struct dwarf2_cu *cu); | |
858 | ||
c67a9c90 | 859 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 860 | |
72bf9492 DJ |
861 | static void scan_partial_symbols (struct partial_die_info *, |
862 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 863 | int, struct dwarf2_cu *); |
c906108c | 864 | |
72bf9492 DJ |
865 | static void add_partial_symbol (struct partial_die_info *, |
866 | struct dwarf2_cu *); | |
63d06c5c | 867 | |
72bf9492 DJ |
868 | static void add_partial_namespace (struct partial_die_info *pdi, |
869 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 870 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 871 | |
5d7cb8df JK |
872 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
873 | CORE_ADDR *highpc, int need_pc, | |
874 | struct dwarf2_cu *cu); | |
875 | ||
72bf9492 DJ |
876 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
877 | struct dwarf2_cu *cu); | |
91c24f0a | 878 | |
bc30ff58 JB |
879 | static void add_partial_subprogram (struct partial_die_info *pdi, |
880 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 881 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 882 | |
fe1b8b76 | 883 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
884 | gdb_byte *buffer, gdb_byte *info_ptr, |
885 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 886 | |
a14ed312 | 887 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 888 | |
a14ed312 | 889 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 890 | |
e5fe5e75 | 891 | static void dwarf2_read_abbrevs (struct dwarf2_cu *cu); |
c906108c | 892 | |
f3dd6933 | 893 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 894 | |
6caca83c CC |
895 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
896 | ||
fe1b8b76 | 897 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 898 | struct dwarf2_cu *); |
72bf9492 | 899 | |
57349743 | 900 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 901 | struct dwarf2_cu *); |
c906108c | 902 | |
93311388 DE |
903 | static struct partial_die_info *load_partial_dies (bfd *, |
904 | gdb_byte *, gdb_byte *, | |
905 | int, struct dwarf2_cu *); | |
72bf9492 | 906 | |
fe1b8b76 | 907 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
908 | struct abbrev_info *abbrev, |
909 | unsigned int, bfd *, | |
910 | gdb_byte *, gdb_byte *, | |
911 | struct dwarf2_cu *); | |
c906108c | 912 | |
c764a876 | 913 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 914 | struct dwarf2_cu *); |
72bf9492 DJ |
915 | |
916 | static void fixup_partial_die (struct partial_die_info *, | |
917 | struct dwarf2_cu *); | |
918 | ||
fe1b8b76 JB |
919 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
920 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 921 | |
fe1b8b76 JB |
922 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
923 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 924 | |
fe1b8b76 | 925 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 926 | |
fe1b8b76 | 927 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 928 | |
fe1b8b76 | 929 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 930 | |
fe1b8b76 | 931 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 932 | |
93311388 | 933 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 934 | |
fe1b8b76 | 935 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 936 | unsigned int *); |
c906108c | 937 | |
c764a876 DE |
938 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
939 | ||
940 | static LONGEST read_checked_initial_length_and_offset | |
941 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
942 | unsigned int *, unsigned int *); | |
613e1657 | 943 | |
fe1b8b76 | 944 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
945 | unsigned int *); |
946 | ||
947 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 948 | |
fe1b8b76 | 949 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 950 | |
9b1c24c8 | 951 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 952 | |
fe1b8b76 JB |
953 | static char *read_indirect_string (bfd *, gdb_byte *, |
954 | const struct comp_unit_head *, | |
955 | unsigned int *); | |
4bdf3d34 | 956 | |
fe1b8b76 | 957 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 958 | |
fe1b8b76 | 959 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 960 | |
fe1b8b76 | 961 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 962 | |
e142c38c | 963 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 964 | |
e142c38c DJ |
965 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
966 | struct dwarf2_cu *); | |
c906108c | 967 | |
348e048f DE |
968 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
969 | unsigned int, | |
970 | struct dwarf2_cu *); | |
971 | ||
05cf31d1 JB |
972 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
973 | struct dwarf2_cu *cu); | |
974 | ||
e142c38c | 975 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 976 | |
e142c38c | 977 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 978 | struct dwarf2_cu **); |
63d06c5c | 979 | |
debd256d JB |
980 | static void free_line_header (struct line_header *lh); |
981 | ||
aaa75496 JB |
982 | static void add_file_name (struct line_header *, char *, unsigned int, |
983 | unsigned int, unsigned int); | |
984 | ||
debd256d JB |
985 | static struct line_header *(dwarf_decode_line_header |
986 | (unsigned int offset, | |
e7c27a73 | 987 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d | 988 | |
f3f5162e DE |
989 | static void dwarf_decode_lines (struct line_header *, const char *, |
990 | struct dwarf2_cu *, struct partial_symtab *, | |
991 | int); | |
c906108c | 992 | |
72b9f47f | 993 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 994 | |
a14ed312 | 995 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 996 | struct dwarf2_cu *); |
c906108c | 997 | |
34eaf542 TT |
998 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
999 | struct dwarf2_cu *, struct symbol *); | |
1000 | ||
a14ed312 | 1001 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1002 | struct dwarf2_cu *); |
c906108c | 1003 | |
98bfdba5 PA |
1004 | static void dwarf2_const_value_attr (struct attribute *attr, |
1005 | struct type *type, | |
1006 | const char *name, | |
1007 | struct obstack *obstack, | |
1008 | struct dwarf2_cu *cu, long *value, | |
1009 | gdb_byte **bytes, | |
1010 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1011 | |
e7c27a73 | 1012 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1013 | |
b4ba55a1 JB |
1014 | static int need_gnat_info (struct dwarf2_cu *); |
1015 | ||
3e43a32a MS |
1016 | static struct type *die_descriptive_type (struct die_info *, |
1017 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1018 | |
1019 | static void set_descriptive_type (struct type *, struct die_info *, | |
1020 | struct dwarf2_cu *); | |
1021 | ||
e7c27a73 DJ |
1022 | static struct type *die_containing_type (struct die_info *, |
1023 | struct dwarf2_cu *); | |
c906108c | 1024 | |
673bfd45 DE |
1025 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1026 | struct dwarf2_cu *); | |
c906108c | 1027 | |
f792889a | 1028 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1029 | |
673bfd45 DE |
1030 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1031 | ||
086ed43d | 1032 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1033 | |
6e70227d | 1034 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1035 | const char *suffix, int physname, |
1036 | struct dwarf2_cu *cu); | |
63d06c5c | 1037 | |
e7c27a73 | 1038 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1039 | |
348e048f DE |
1040 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1041 | ||
e7c27a73 | 1042 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1043 | |
e7c27a73 | 1044 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1045 | |
96408a79 SA |
1046 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1047 | ||
ff013f42 JK |
1048 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1049 | struct dwarf2_cu *, struct partial_symtab *); | |
1050 | ||
a14ed312 | 1051 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1052 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1053 | struct partial_symtab *); | |
c906108c | 1054 | |
fae299cd DC |
1055 | static void get_scope_pc_bounds (struct die_info *, |
1056 | CORE_ADDR *, CORE_ADDR *, | |
1057 | struct dwarf2_cu *); | |
1058 | ||
801e3a5b JB |
1059 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1060 | CORE_ADDR, struct dwarf2_cu *); | |
1061 | ||
a14ed312 | 1062 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1063 | struct dwarf2_cu *); |
c906108c | 1064 | |
a14ed312 | 1065 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1066 | struct type *, struct dwarf2_cu *); |
c906108c | 1067 | |
a14ed312 | 1068 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1069 | struct die_info *, struct type *, |
e7c27a73 | 1070 | struct dwarf2_cu *); |
c906108c | 1071 | |
a14ed312 | 1072 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1073 | struct type *, |
1074 | struct dwarf2_cu *); | |
c906108c | 1075 | |
134d01f1 | 1076 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1077 | |
e7c27a73 | 1078 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1079 | |
e7c27a73 | 1080 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1081 | |
5d7cb8df JK |
1082 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1083 | ||
27aa8d6a SW |
1084 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1085 | ||
f55ee35c JK |
1086 | static struct type *read_module_type (struct die_info *die, |
1087 | struct dwarf2_cu *cu); | |
1088 | ||
38d518c9 | 1089 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1090 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1091 | |
134d01f1 | 1092 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1093 | |
e7c27a73 | 1094 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1095 | |
6e70227d | 1096 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1097 | struct dwarf2_cu *); |
1098 | ||
93311388 | 1099 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1100 | |
93311388 DE |
1101 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1102 | gdb_byte *info_ptr, | |
d97bc12b DE |
1103 | gdb_byte **new_info_ptr, |
1104 | struct die_info *parent); | |
1105 | ||
93311388 DE |
1106 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1107 | gdb_byte *info_ptr, | |
fe1b8b76 | 1108 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1109 | struct die_info *parent); |
1110 | ||
93311388 DE |
1111 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1112 | gdb_byte *info_ptr, | |
fe1b8b76 | 1113 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1114 | struct die_info *parent); |
1115 | ||
93311388 DE |
1116 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1117 | struct die_info **, gdb_byte *, | |
1118 | int *); | |
1119 | ||
e7c27a73 | 1120 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1121 | |
71c25dea TT |
1122 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1123 | struct obstack *); | |
1124 | ||
e142c38c | 1125 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1126 | |
98bfdba5 PA |
1127 | static const char *dwarf2_full_name (char *name, |
1128 | struct die_info *die, | |
1129 | struct dwarf2_cu *cu); | |
1130 | ||
e142c38c | 1131 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1132 | struct dwarf2_cu **); |
9219021c | 1133 | |
a14ed312 | 1134 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1135 | |
a14ed312 | 1136 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1137 | |
a14ed312 | 1138 | static char *dwarf_form_name (unsigned int); |
c906108c | 1139 | |
a14ed312 | 1140 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1141 | |
a14ed312 | 1142 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1143 | |
1144 | #if 0 | |
a14ed312 | 1145 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1146 | #endif |
1147 | ||
f9aca02d | 1148 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1149 | |
d97bc12b DE |
1150 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1151 | ||
1152 | static void dump_die_for_error (struct die_info *); | |
1153 | ||
1154 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1155 | struct die_info *); | |
c906108c | 1156 | |
d97bc12b | 1157 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1158 | |
51545339 | 1159 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1160 | struct dwarf2_cu *); |
c906108c | 1161 | |
93311388 DE |
1162 | static int is_ref_attr (struct attribute *); |
1163 | ||
c764a876 | 1164 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1165 | |
43bbcdc2 | 1166 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1167 | |
348e048f DE |
1168 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1169 | struct attribute *, | |
1170 | struct dwarf2_cu **); | |
1171 | ||
10b3939b DJ |
1172 | static struct die_info *follow_die_ref (struct die_info *, |
1173 | struct attribute *, | |
f2f0e013 | 1174 | struct dwarf2_cu **); |
c906108c | 1175 | |
348e048f DE |
1176 | static struct die_info *follow_die_sig (struct die_info *, |
1177 | struct attribute *, | |
1178 | struct dwarf2_cu **); | |
1179 | ||
6c83ed52 TT |
1180 | static struct signatured_type *lookup_signatured_type_at_offset |
1181 | (struct objfile *objfile, | |
1182 | struct dwarf2_section_info *section, | |
1183 | unsigned int offset); | |
1184 | ||
e5fe5e75 | 1185 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1186 | |
a0f42c21 | 1187 | static void read_signatured_type (struct signatured_type *type_sig); |
348e048f | 1188 | |
c906108c SS |
1189 | /* memory allocation interface */ |
1190 | ||
7b5a2f43 | 1191 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1192 | |
f3dd6933 | 1193 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1194 | |
b60c80d6 | 1195 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1196 | |
2e276125 | 1197 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
cf2c3c16 TT |
1198 | char *, bfd *, struct dwarf2_cu *, |
1199 | struct dwarf2_section_info *, | |
1200 | int); | |
2e276125 | 1201 | |
8e19ed76 PS |
1202 | static int attr_form_is_block (struct attribute *); |
1203 | ||
3690dd37 JB |
1204 | static int attr_form_is_section_offset (struct attribute *); |
1205 | ||
1206 | static int attr_form_is_constant (struct attribute *); | |
1207 | ||
8cf6f0b1 TT |
1208 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1209 | struct dwarf2_loclist_baton *baton, | |
1210 | struct attribute *attr); | |
1211 | ||
93e7bd98 DJ |
1212 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1213 | struct symbol *sym, | |
1214 | struct dwarf2_cu *cu); | |
4c2df51b | 1215 | |
93311388 DE |
1216 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1217 | struct abbrev_info *abbrev, | |
1218 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1219 | |
72bf9492 DJ |
1220 | static void free_stack_comp_unit (void *); |
1221 | ||
72bf9492 DJ |
1222 | static hashval_t partial_die_hash (const void *item); |
1223 | ||
1224 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1225 | ||
ae038cb0 | 1226 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1227 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1228 | |
9816fde3 | 1229 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1230 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1231 | |
1232 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1233 | struct die_info *comp_unit_die); | |
93311388 | 1234 | |
68dc6402 | 1235 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1236 | |
1237 | static void free_cached_comp_units (void *); | |
1238 | ||
1239 | static void age_cached_comp_units (void); | |
1240 | ||
1241 | static void free_one_cached_comp_unit (void *); | |
1242 | ||
f792889a DJ |
1243 | static struct type *set_die_type (struct die_info *, struct type *, |
1244 | struct dwarf2_cu *); | |
1c379e20 | 1245 | |
ae038cb0 DJ |
1246 | static void create_all_comp_units (struct objfile *); |
1247 | ||
1fd400ff TT |
1248 | static int create_debug_types_hash_table (struct objfile *objfile); |
1249 | ||
a0f42c21 | 1250 | static void load_full_comp_unit (struct dwarf2_per_cu_data *); |
10b3939b DJ |
1251 | |
1252 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1253 | ||
1254 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1255 | struct dwarf2_per_cu_data *); | |
1256 | ||
ae038cb0 DJ |
1257 | static void dwarf2_mark (struct dwarf2_cu *); |
1258 | ||
1259 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1260 | ||
673bfd45 DE |
1261 | static struct type *get_die_type_at_offset (unsigned int, |
1262 | struct dwarf2_per_cu_data *per_cu); | |
1263 | ||
f792889a | 1264 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1265 | |
9291a0cd TT |
1266 | static void dwarf2_release_queue (void *dummy); |
1267 | ||
a0f42c21 | 1268 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu); |
9291a0cd | 1269 | |
a0f42c21 | 1270 | static void process_queue (void); |
9291a0cd TT |
1271 | |
1272 | static void find_file_and_directory (struct die_info *die, | |
1273 | struct dwarf2_cu *cu, | |
1274 | char **name, char **comp_dir); | |
1275 | ||
1276 | static char *file_full_name (int file, struct line_header *lh, | |
1277 | const char *comp_dir); | |
1278 | ||
9ff913ba DE |
1279 | static gdb_byte *read_and_check_comp_unit_head |
1280 | (struct comp_unit_head *header, | |
1281 | struct dwarf2_section_info *section, gdb_byte *info_ptr, | |
1282 | int is_debug_types_section); | |
9291a0cd TT |
1283 | |
1284 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1285 | struct dwarf2_cu *cu); | |
1286 | ||
673bfd45 | 1287 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1288 | |
9291a0cd TT |
1289 | #if WORDS_BIGENDIAN |
1290 | ||
1291 | /* Convert VALUE between big- and little-endian. */ | |
1292 | static offset_type | |
1293 | byte_swap (offset_type value) | |
1294 | { | |
1295 | offset_type result; | |
1296 | ||
1297 | result = (value & 0xff) << 24; | |
1298 | result |= (value & 0xff00) << 8; | |
1299 | result |= (value & 0xff0000) >> 8; | |
1300 | result |= (value & 0xff000000) >> 24; | |
1301 | return result; | |
1302 | } | |
1303 | ||
1304 | #define MAYBE_SWAP(V) byte_swap (V) | |
1305 | ||
1306 | #else | |
1307 | #define MAYBE_SWAP(V) (V) | |
1308 | #endif /* WORDS_BIGENDIAN */ | |
1309 | ||
1310 | /* The suffix for an index file. */ | |
1311 | #define INDEX_SUFFIX ".gdb-index" | |
1312 | ||
3da10d80 KS |
1313 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1314 | struct dwarf2_cu *cu); | |
1315 | ||
c906108c | 1316 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1317 | information and return true if we have enough to do something. |
1318 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1319 | ELF names are used. */ | |
c906108c SS |
1320 | |
1321 | int | |
251d32d9 TG |
1322 | dwarf2_has_info (struct objfile *objfile, |
1323 | const struct dwarf2_debug_sections *names) | |
c906108c | 1324 | { |
be391dca TT |
1325 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1326 | if (!dwarf2_per_objfile) | |
1327 | { | |
1328 | /* Initialize per-objfile state. */ | |
1329 | struct dwarf2_per_objfile *data | |
1330 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1331 | |
be391dca TT |
1332 | memset (data, 0, sizeof (*data)); |
1333 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1334 | dwarf2_per_objfile = data; | |
6502dd73 | 1335 | |
251d32d9 TG |
1336 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1337 | (void *) names); | |
be391dca TT |
1338 | dwarf2_per_objfile->objfile = objfile; |
1339 | } | |
1340 | return (dwarf2_per_objfile->info.asection != NULL | |
1341 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1342 | } |
1343 | ||
251d32d9 TG |
1344 | /* When loading sections, we look either for uncompressed section or for |
1345 | compressed section names. */ | |
233a11ab CS |
1346 | |
1347 | static int | |
251d32d9 TG |
1348 | section_is_p (const char *section_name, |
1349 | const struct dwarf2_section_names *names) | |
233a11ab | 1350 | { |
251d32d9 TG |
1351 | if (names->normal != NULL |
1352 | && strcmp (section_name, names->normal) == 0) | |
1353 | return 1; | |
1354 | if (names->compressed != NULL | |
1355 | && strcmp (section_name, names->compressed) == 0) | |
1356 | return 1; | |
1357 | return 0; | |
233a11ab CS |
1358 | } |
1359 | ||
c906108c SS |
1360 | /* This function is mapped across the sections and remembers the |
1361 | offset and size of each of the debugging sections we are interested | |
1362 | in. */ | |
1363 | ||
1364 | static void | |
251d32d9 | 1365 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1366 | { |
251d32d9 TG |
1367 | const struct dwarf2_debug_sections *names; |
1368 | ||
1369 | if (vnames == NULL) | |
1370 | names = &dwarf2_elf_names; | |
1371 | else | |
1372 | names = (const struct dwarf2_debug_sections *) vnames; | |
1373 | ||
1374 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1375 | { |
dce234bc PP |
1376 | dwarf2_per_objfile->info.asection = sectp; |
1377 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1378 | } |
251d32d9 | 1379 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1380 | { |
dce234bc PP |
1381 | dwarf2_per_objfile->abbrev.asection = sectp; |
1382 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1383 | } |
251d32d9 | 1384 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1385 | { |
dce234bc PP |
1386 | dwarf2_per_objfile->line.asection = sectp; |
1387 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1388 | } |
251d32d9 | 1389 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1390 | { |
dce234bc PP |
1391 | dwarf2_per_objfile->loc.asection = sectp; |
1392 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1393 | } |
251d32d9 | 1394 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1395 | { |
dce234bc PP |
1396 | dwarf2_per_objfile->macinfo.asection = sectp; |
1397 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1398 | } |
cf2c3c16 TT |
1399 | else if (section_is_p (sectp->name, &names->macro)) |
1400 | { | |
1401 | dwarf2_per_objfile->macro.asection = sectp; | |
1402 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1403 | } | |
251d32d9 | 1404 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1405 | { |
dce234bc PP |
1406 | dwarf2_per_objfile->str.asection = sectp; |
1407 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1408 | } |
251d32d9 | 1409 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1410 | { |
dce234bc PP |
1411 | dwarf2_per_objfile->frame.asection = sectp; |
1412 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1413 | } |
251d32d9 | 1414 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1415 | { |
3799ccc6 | 1416 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1417 | |
3799ccc6 EZ |
1418 | if (aflag & SEC_HAS_CONTENTS) |
1419 | { | |
dce234bc PP |
1420 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1421 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1422 | } |
b6af0555 | 1423 | } |
251d32d9 | 1424 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1425 | { |
dce234bc PP |
1426 | dwarf2_per_objfile->ranges.asection = sectp; |
1427 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1428 | } |
251d32d9 | 1429 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1430 | { |
8b70b953 TT |
1431 | struct dwarf2_section_info type_section; |
1432 | ||
1433 | memset (&type_section, 0, sizeof (type_section)); | |
1434 | type_section.asection = sectp; | |
1435 | type_section.size = bfd_get_section_size (sectp); | |
1436 | ||
1437 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1438 | &type_section); | |
348e048f | 1439 | } |
251d32d9 | 1440 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1441 | { |
1442 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1443 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1444 | } | |
dce234bc | 1445 | |
72dca2f5 FR |
1446 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1447 | && bfd_section_vma (abfd, sectp) == 0) | |
1448 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1449 | } |
1450 | ||
dce234bc PP |
1451 | /* Decompress a section that was compressed using zlib. Store the |
1452 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1453 | |
1454 | static void | |
dce234bc PP |
1455 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1456 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1457 | { | |
1458 | bfd *abfd = objfile->obfd; | |
1459 | #ifndef HAVE_ZLIB_H | |
1460 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1461 | "is disabled in this copy of GDB"), | |
1462 | bfd_get_filename (abfd)); | |
1463 | #else | |
1464 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1465 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1466 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1467 | bfd_size_type uncompressed_size; |
1468 | gdb_byte *uncompressed_buffer; | |
1469 | z_stream strm; | |
1470 | int rc; | |
1471 | int header_size = 12; | |
1472 | ||
1473 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1474 | || bfd_bread (compressed_buffer, |
1475 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1476 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1477 | bfd_get_filename (abfd)); | |
1478 | ||
1479 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1480 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1481 | if (compressed_size < header_size | |
1482 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1483 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1484 | bfd_get_filename (abfd)); | |
1485 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1486 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1487 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1488 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1489 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1490 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1491 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1492 | uncompressed_size += compressed_buffer[11]; | |
1493 | ||
1494 | /* It is possible the section consists of several compressed | |
1495 | buffers concatenated together, so we uncompress in a loop. */ | |
1496 | strm.zalloc = NULL; | |
1497 | strm.zfree = NULL; | |
1498 | strm.opaque = NULL; | |
1499 | strm.avail_in = compressed_size - header_size; | |
1500 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1501 | strm.avail_out = uncompressed_size; | |
1502 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1503 | uncompressed_size); | |
1504 | rc = inflateInit (&strm); | |
1505 | while (strm.avail_in > 0) | |
1506 | { | |
1507 | if (rc != Z_OK) | |
1508 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1509 | bfd_get_filename (abfd), rc); | |
1510 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1511 | + (uncompressed_size - strm.avail_out)); | |
1512 | rc = inflate (&strm, Z_FINISH); | |
1513 | if (rc != Z_STREAM_END) | |
1514 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1515 | bfd_get_filename (abfd), rc); | |
1516 | rc = inflateReset (&strm); | |
1517 | } | |
1518 | rc = inflateEnd (&strm); | |
1519 | if (rc != Z_OK | |
1520 | || strm.avail_out != 0) | |
1521 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1522 | bfd_get_filename (abfd), rc); | |
1523 | ||
affddf13 | 1524 | do_cleanups (cleanup); |
dce234bc PP |
1525 | *outbuf = uncompressed_buffer; |
1526 | *outsize = uncompressed_size; | |
1527 | #endif | |
233a11ab CS |
1528 | } |
1529 | ||
9e0ac564 TT |
1530 | /* A helper function that decides whether a section is empty. */ |
1531 | ||
1532 | static int | |
1533 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1534 | { | |
1535 | return info->asection == NULL || info->size == 0; | |
1536 | } | |
1537 | ||
9cdd5dbd | 1538 | /* Read the contents of the section INFO from object file specified by |
dce234bc PP |
1539 | OBJFILE, store info about the section into INFO. |
1540 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1541 | |
dce234bc PP |
1542 | static void |
1543 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1544 | { |
dce234bc PP |
1545 | bfd *abfd = objfile->obfd; |
1546 | asection *sectp = info->asection; | |
1547 | gdb_byte *buf, *retbuf; | |
1548 | unsigned char header[4]; | |
c906108c | 1549 | |
be391dca TT |
1550 | if (info->readin) |
1551 | return; | |
dce234bc | 1552 | info->buffer = NULL; |
b315ab21 | 1553 | info->map_addr = NULL; |
be391dca | 1554 | info->readin = 1; |
188dd5d6 | 1555 | |
9e0ac564 | 1556 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1557 | return; |
c906108c | 1558 | |
dce234bc PP |
1559 | /* Check if the file has a 4-byte header indicating compression. */ |
1560 | if (info->size > sizeof (header) | |
1561 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1562 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1563 | { | |
1564 | /* Upon decompression, update the buffer and its size. */ | |
1565 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1566 | { | |
1567 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1568 | &info->size); | |
1569 | return; | |
1570 | } | |
1571 | } | |
4bdf3d34 | 1572 | |
dce234bc PP |
1573 | #ifdef HAVE_MMAP |
1574 | if (pagesize == 0) | |
1575 | pagesize = getpagesize (); | |
2e276125 | 1576 | |
dce234bc PP |
1577 | /* Only try to mmap sections which are large enough: we don't want to |
1578 | waste space due to fragmentation. Also, only try mmap for sections | |
1579 | without relocations. */ | |
1580 | ||
1581 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1582 | { | |
b315ab21 TG |
1583 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1584 | MAP_PRIVATE, sectp->filepos, | |
1585 | &info->map_addr, &info->map_len); | |
dce234bc | 1586 | |
b315ab21 | 1587 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1588 | { |
be391dca | 1589 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1590 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1591 | #endif |
dce234bc PP |
1592 | return; |
1593 | } | |
1594 | } | |
1595 | #endif | |
1596 | ||
1597 | /* If we get here, we are a normal, not-compressed section. */ | |
1598 | info->buffer = buf | |
1599 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1600 | ||
1601 | /* When debugging .o files, we may need to apply relocations; see | |
1602 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1603 | We never compress sections in .o files, so we only need to | |
1604 | try this when the section is not compressed. */ | |
ac8035ab | 1605 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1606 | if (retbuf != NULL) |
1607 | { | |
1608 | info->buffer = retbuf; | |
1609 | return; | |
1610 | } | |
1611 | ||
1612 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1613 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1614 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1615 | bfd_get_filename (abfd)); | |
1616 | } | |
1617 | ||
9e0ac564 TT |
1618 | /* A helper function that returns the size of a section in a safe way. |
1619 | If you are positive that the section has been read before using the | |
1620 | size, then it is safe to refer to the dwarf2_section_info object's | |
1621 | "size" field directly. In other cases, you must call this | |
1622 | function, because for compressed sections the size field is not set | |
1623 | correctly until the section has been read. */ | |
1624 | ||
1625 | static bfd_size_type | |
1626 | dwarf2_section_size (struct objfile *objfile, | |
1627 | struct dwarf2_section_info *info) | |
1628 | { | |
1629 | if (!info->readin) | |
1630 | dwarf2_read_section (objfile, info); | |
1631 | return info->size; | |
1632 | } | |
1633 | ||
dce234bc | 1634 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1635 | SECTION_NAME. */ |
af34e669 | 1636 | |
dce234bc | 1637 | void |
3017a003 TG |
1638 | dwarf2_get_section_info (struct objfile *objfile, |
1639 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1640 | asection **sectp, gdb_byte **bufp, |
1641 | bfd_size_type *sizep) | |
1642 | { | |
1643 | struct dwarf2_per_objfile *data | |
1644 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1645 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1646 | |
1647 | /* We may see an objfile without any DWARF, in which case we just | |
1648 | return nothing. */ | |
1649 | if (data == NULL) | |
1650 | { | |
1651 | *sectp = NULL; | |
1652 | *bufp = NULL; | |
1653 | *sizep = 0; | |
1654 | return; | |
1655 | } | |
3017a003 TG |
1656 | switch (sect) |
1657 | { | |
1658 | case DWARF2_DEBUG_FRAME: | |
1659 | info = &data->frame; | |
1660 | break; | |
1661 | case DWARF2_EH_FRAME: | |
1662 | info = &data->eh_frame; | |
1663 | break; | |
1664 | default: | |
1665 | gdb_assert_not_reached ("unexpected section"); | |
1666 | } | |
dce234bc | 1667 | |
9e0ac564 | 1668 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1669 | |
1670 | *sectp = info->asection; | |
1671 | *bufp = info->buffer; | |
1672 | *sizep = info->size; | |
1673 | } | |
1674 | ||
9291a0cd | 1675 | \f |
7b9f3c50 DE |
1676 | /* DWARF quick_symbols_functions support. */ |
1677 | ||
1678 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1679 | unique line tables, so we maintain a separate table of all .debug_line | |
1680 | derived entries to support the sharing. | |
1681 | All the quick functions need is the list of file names. We discard the | |
1682 | line_header when we're done and don't need to record it here. */ | |
1683 | struct quick_file_names | |
1684 | { | |
1685 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1686 | unsigned int offset; | |
1687 | ||
1688 | /* The number of entries in file_names, real_names. */ | |
1689 | unsigned int num_file_names; | |
1690 | ||
1691 | /* The file names from the line table, after being run through | |
1692 | file_full_name. */ | |
1693 | const char **file_names; | |
1694 | ||
1695 | /* The file names from the line table after being run through | |
1696 | gdb_realpath. These are computed lazily. */ | |
1697 | const char **real_names; | |
1698 | }; | |
1699 | ||
1700 | /* When using the index (and thus not using psymtabs), each CU has an | |
1701 | object of this type. This is used to hold information needed by | |
1702 | the various "quick" methods. */ | |
1703 | struct dwarf2_per_cu_quick_data | |
1704 | { | |
1705 | /* The file table. This can be NULL if there was no file table | |
1706 | or it's currently not read in. | |
1707 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1708 | struct quick_file_names *file_names; | |
1709 | ||
1710 | /* The corresponding symbol table. This is NULL if symbols for this | |
1711 | CU have not yet been read. */ | |
1712 | struct symtab *symtab; | |
1713 | ||
1714 | /* A temporary mark bit used when iterating over all CUs in | |
1715 | expand_symtabs_matching. */ | |
1716 | unsigned int mark : 1; | |
1717 | ||
1718 | /* True if we've tried to read the file table and found there isn't one. | |
1719 | There will be no point in trying to read it again next time. */ | |
1720 | unsigned int no_file_data : 1; | |
1721 | }; | |
1722 | ||
1723 | /* Hash function for a quick_file_names. */ | |
1724 | ||
1725 | static hashval_t | |
1726 | hash_file_name_entry (const void *e) | |
1727 | { | |
1728 | const struct quick_file_names *file_data = e; | |
1729 | ||
1730 | return file_data->offset; | |
1731 | } | |
1732 | ||
1733 | /* Equality function for a quick_file_names. */ | |
1734 | ||
1735 | static int | |
1736 | eq_file_name_entry (const void *a, const void *b) | |
1737 | { | |
1738 | const struct quick_file_names *ea = a; | |
1739 | const struct quick_file_names *eb = b; | |
1740 | ||
1741 | return ea->offset == eb->offset; | |
1742 | } | |
1743 | ||
1744 | /* Delete function for a quick_file_names. */ | |
1745 | ||
1746 | static void | |
1747 | delete_file_name_entry (void *e) | |
1748 | { | |
1749 | struct quick_file_names *file_data = e; | |
1750 | int i; | |
1751 | ||
1752 | for (i = 0; i < file_data->num_file_names; ++i) | |
1753 | { | |
1754 | xfree ((void*) file_data->file_names[i]); | |
1755 | if (file_data->real_names) | |
1756 | xfree ((void*) file_data->real_names[i]); | |
1757 | } | |
1758 | ||
1759 | /* The space for the struct itself lives on objfile_obstack, | |
1760 | so we don't free it here. */ | |
1761 | } | |
1762 | ||
1763 | /* Create a quick_file_names hash table. */ | |
1764 | ||
1765 | static htab_t | |
1766 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1767 | { | |
1768 | return htab_create_alloc (nr_initial_entries, | |
1769 | hash_file_name_entry, eq_file_name_entry, | |
1770 | delete_file_name_entry, xcalloc, xfree); | |
1771 | } | |
9291a0cd | 1772 | |
918dd910 JK |
1773 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1774 | have to be created afterwards. You should call age_cached_comp_units after | |
1775 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1776 | ||
1777 | static void | |
1778 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1779 | { | |
b0df02fd | 1780 | if (per_cu->debug_types_section) |
e5fe5e75 | 1781 | load_full_type_unit (per_cu); |
918dd910 | 1782 | else |
a0f42c21 | 1783 | load_full_comp_unit (per_cu); |
918dd910 | 1784 | |
918dd910 | 1785 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
1786 | |
1787 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
1788 | } |
1789 | ||
a0f42c21 | 1790 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 1791 | |
9291a0cd | 1792 | static void |
a0f42c21 | 1793 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1794 | { |
1795 | struct cleanup *back_to; | |
1796 | ||
1797 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1798 | ||
a0f42c21 | 1799 | queue_comp_unit (per_cu); |
9291a0cd | 1800 | |
918dd910 | 1801 | load_cu (per_cu); |
9291a0cd | 1802 | |
a0f42c21 | 1803 | process_queue (); |
9291a0cd TT |
1804 | |
1805 | /* Age the cache, releasing compilation units that have not | |
1806 | been used recently. */ | |
1807 | age_cached_comp_units (); | |
1808 | ||
1809 | do_cleanups (back_to); | |
1810 | } | |
1811 | ||
1812 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1813 | the objfile from which this CU came. Returns the resulting symbol | |
1814 | table. */ | |
2fdf6df6 | 1815 | |
9291a0cd | 1816 | static struct symtab * |
a0f42c21 | 1817 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1818 | { |
1819 | if (!per_cu->v.quick->symtab) | |
1820 | { | |
1821 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1822 | increment_reading_symtab (); | |
a0f42c21 | 1823 | dw2_do_instantiate_symtab (per_cu); |
9291a0cd TT |
1824 | do_cleanups (back_to); |
1825 | } | |
1826 | return per_cu->v.quick->symtab; | |
1827 | } | |
1828 | ||
1fd400ff | 1829 | /* Return the CU given its index. */ |
2fdf6df6 | 1830 | |
1fd400ff TT |
1831 | static struct dwarf2_per_cu_data * |
1832 | dw2_get_cu (int index) | |
1833 | { | |
1834 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1835 | { | |
1836 | index -= dwarf2_per_objfile->n_comp_units; | |
d467dd73 | 1837 | return dwarf2_per_objfile->all_type_units[index]; |
1fd400ff TT |
1838 | } |
1839 | return dwarf2_per_objfile->all_comp_units[index]; | |
1840 | } | |
1841 | ||
9291a0cd TT |
1842 | /* A helper function that knows how to read a 64-bit value in a way |
1843 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1844 | otherwise. */ | |
2fdf6df6 | 1845 | |
9291a0cd TT |
1846 | static int |
1847 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1848 | { | |
1849 | if (sizeof (ULONGEST) < 8) | |
1850 | { | |
1851 | int i; | |
1852 | ||
1853 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1854 | for (i = 0; i < 4; ++i) | |
1855 | if (bytes[i + 4] != 0) | |
1856 | return 0; | |
1857 | ||
1858 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1859 | } | |
1860 | else | |
1861 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1862 | return 1; | |
1863 | } | |
1864 | ||
1865 | /* Read the CU list from the mapped index, and use it to create all | |
1866 | the CU objects for this objfile. Return 0 if something went wrong, | |
1867 | 1 if everything went ok. */ | |
2fdf6df6 | 1868 | |
9291a0cd | 1869 | static int |
1fd400ff TT |
1870 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1871 | offset_type cu_list_elements) | |
9291a0cd TT |
1872 | { |
1873 | offset_type i; | |
9291a0cd TT |
1874 | |
1875 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1876 | dwarf2_per_objfile->all_comp_units | |
1877 | = obstack_alloc (&objfile->objfile_obstack, | |
1878 | dwarf2_per_objfile->n_comp_units | |
1879 | * sizeof (struct dwarf2_per_cu_data *)); | |
1880 | ||
1881 | for (i = 0; i < cu_list_elements; i += 2) | |
1882 | { | |
1883 | struct dwarf2_per_cu_data *the_cu; | |
1884 | ULONGEST offset, length; | |
1885 | ||
1886 | if (!extract_cu_value (cu_list, &offset) | |
1887 | || !extract_cu_value (cu_list + 8, &length)) | |
1888 | return 0; | |
1889 | cu_list += 2 * 8; | |
1890 | ||
1891 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1892 | struct dwarf2_per_cu_data); | |
1893 | the_cu->offset = offset; | |
1894 | the_cu->length = length; | |
1895 | the_cu->objfile = objfile; | |
1896 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1897 | struct dwarf2_per_cu_quick_data); | |
1898 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1899 | } | |
1900 | ||
1901 | return 1; | |
1902 | } | |
1903 | ||
1fd400ff | 1904 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1905 | |
1fd400ff | 1906 | static int |
673bfd45 | 1907 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 1908 | struct dwarf2_section_info *section, |
673bfd45 DE |
1909 | const gdb_byte *bytes, |
1910 | offset_type elements) | |
1fd400ff TT |
1911 | { |
1912 | offset_type i; | |
673bfd45 | 1913 | htab_t sig_types_hash; |
1fd400ff | 1914 | |
d467dd73 DE |
1915 | dwarf2_per_objfile->n_type_units = elements / 3; |
1916 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 1917 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 1918 | dwarf2_per_objfile->n_type_units |
1fd400ff TT |
1919 | * sizeof (struct dwarf2_per_cu_data *)); |
1920 | ||
673bfd45 | 1921 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1922 | |
1923 | for (i = 0; i < elements; i += 3) | |
1924 | { | |
1925 | struct signatured_type *type_sig; | |
1926 | ULONGEST offset, type_offset, signature; | |
1927 | void **slot; | |
1928 | ||
1929 | if (!extract_cu_value (bytes, &offset) | |
1930 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1931 | return 0; | |
1932 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1933 | bytes += 3 * 8; | |
1934 | ||
1935 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1936 | struct signatured_type); | |
1937 | type_sig->signature = signature; | |
1fd400ff | 1938 | type_sig->type_offset = type_offset; |
b0df02fd | 1939 | type_sig->per_cu.debug_types_section = section; |
1fd400ff TT |
1940 | type_sig->per_cu.offset = offset; |
1941 | type_sig->per_cu.objfile = objfile; | |
1942 | type_sig->per_cu.v.quick | |
1943 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1944 | struct dwarf2_per_cu_quick_data); | |
1945 | ||
673bfd45 | 1946 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
1947 | *slot = type_sig; |
1948 | ||
d467dd73 | 1949 | dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu; |
1fd400ff TT |
1950 | } |
1951 | ||
673bfd45 | 1952 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1953 | |
1954 | return 1; | |
1955 | } | |
1956 | ||
9291a0cd TT |
1957 | /* Read the address map data from the mapped index, and use it to |
1958 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 1959 | |
9291a0cd TT |
1960 | static void |
1961 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1962 | { | |
1963 | const gdb_byte *iter, *end; | |
1964 | struct obstack temp_obstack; | |
1965 | struct addrmap *mutable_map; | |
1966 | struct cleanup *cleanup; | |
1967 | CORE_ADDR baseaddr; | |
1968 | ||
1969 | obstack_init (&temp_obstack); | |
1970 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1971 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1972 | ||
1973 | iter = index->address_table; | |
1974 | end = iter + index->address_table_size; | |
1975 | ||
1976 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1977 | ||
1978 | while (iter < end) | |
1979 | { | |
1980 | ULONGEST hi, lo, cu_index; | |
1981 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1982 | iter += 8; | |
1983 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1984 | iter += 8; | |
1985 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1986 | iter += 4; | |
1987 | ||
1988 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1989 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1990 | } |
1991 | ||
1992 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1993 | &objfile->objfile_obstack); | |
1994 | do_cleanups (cleanup); | |
1995 | } | |
1996 | ||
59d7bcaf JK |
1997 | /* The hash function for strings in the mapped index. This is the same as |
1998 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
1999 | implementation. This is necessary because the hash function is tied to the | |
2000 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2001 | SYMBOL_HASH_NEXT. |
2002 | ||
2003 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2004 | |
9291a0cd | 2005 | static hashval_t |
559a7a62 | 2006 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2007 | { |
2008 | const unsigned char *str = (const unsigned char *) p; | |
2009 | hashval_t r = 0; | |
2010 | unsigned char c; | |
2011 | ||
2012 | while ((c = *str++) != 0) | |
559a7a62 JK |
2013 | { |
2014 | if (index_version >= 5) | |
2015 | c = tolower (c); | |
2016 | r = r * 67 + c - 113; | |
2017 | } | |
9291a0cd TT |
2018 | |
2019 | return r; | |
2020 | } | |
2021 | ||
2022 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2023 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2024 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2025 | |
9291a0cd TT |
2026 | static int |
2027 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2028 | offset_type **vec_out) | |
2029 | { | |
0cf03b49 JK |
2030 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2031 | offset_type hash; | |
9291a0cd | 2032 | offset_type slot, step; |
559a7a62 | 2033 | int (*cmp) (const char *, const char *); |
9291a0cd | 2034 | |
0cf03b49 JK |
2035 | if (current_language->la_language == language_cplus |
2036 | || current_language->la_language == language_java | |
2037 | || current_language->la_language == language_fortran) | |
2038 | { | |
2039 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2040 | not contain any. */ | |
2041 | const char *paren = strchr (name, '('); | |
2042 | ||
2043 | if (paren) | |
2044 | { | |
2045 | char *dup; | |
2046 | ||
2047 | dup = xmalloc (paren - name + 1); | |
2048 | memcpy (dup, name, paren - name); | |
2049 | dup[paren - name] = 0; | |
2050 | ||
2051 | make_cleanup (xfree, dup); | |
2052 | name = dup; | |
2053 | } | |
2054 | } | |
2055 | ||
559a7a62 JK |
2056 | /* Index version 4 did not support case insensitive searches. But the |
2057 | indexes for case insensitive languages are built in lowercase, therefore | |
2058 | simulate our NAME being searched is also lowercased. */ | |
2059 | hash = mapped_index_string_hash ((index->version == 4 | |
2060 | && case_sensitivity == case_sensitive_off | |
2061 | ? 5 : index->version), | |
2062 | name); | |
2063 | ||
3876f04e DE |
2064 | slot = hash & (index->symbol_table_slots - 1); |
2065 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2066 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2067 | |
2068 | for (;;) | |
2069 | { | |
2070 | /* Convert a slot number to an offset into the table. */ | |
2071 | offset_type i = 2 * slot; | |
2072 | const char *str; | |
3876f04e | 2073 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2074 | { |
2075 | do_cleanups (back_to); | |
2076 | return 0; | |
2077 | } | |
9291a0cd | 2078 | |
3876f04e | 2079 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2080 | if (!cmp (name, str)) |
9291a0cd TT |
2081 | { |
2082 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2083 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2084 | do_cleanups (back_to); |
9291a0cd TT |
2085 | return 1; |
2086 | } | |
2087 | ||
3876f04e | 2088 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2089 | } |
2090 | } | |
2091 | ||
2092 | /* Read the index file. If everything went ok, initialize the "quick" | |
2093 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2094 | |
9291a0cd TT |
2095 | static int |
2096 | dwarf2_read_index (struct objfile *objfile) | |
2097 | { | |
9291a0cd TT |
2098 | char *addr; |
2099 | struct mapped_index *map; | |
b3b272e1 | 2100 | offset_type *metadata; |
ac0b195c KW |
2101 | const gdb_byte *cu_list; |
2102 | const gdb_byte *types_list = NULL; | |
2103 | offset_type version, cu_list_elements; | |
2104 | offset_type types_list_elements = 0; | |
1fd400ff | 2105 | int i; |
9291a0cd | 2106 | |
9e0ac564 | 2107 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2108 | return 0; |
82430852 JK |
2109 | |
2110 | /* Older elfutils strip versions could keep the section in the main | |
2111 | executable while splitting it for the separate debug info file. */ | |
2112 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2113 | & SEC_HAS_CONTENTS) == 0) | |
2114 | return 0; | |
2115 | ||
9291a0cd TT |
2116 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2117 | ||
2118 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2119 | /* Version check. */ | |
1fd400ff | 2120 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2121 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2122 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2123 | contained incomplete addrmap. So, it seems better to just ignore such |
559a7a62 JK |
2124 | indices. Index version 4 uses a different hash function than index |
2125 | version 5 and later. */ | |
831adc1f | 2126 | if (version < 4) |
9291a0cd | 2127 | return 0; |
594e8718 JK |
2128 | /* Indexes with higher version than the one supported by GDB may be no |
2129 | longer backward compatible. */ | |
559a7a62 | 2130 | if (version > 5) |
594e8718 | 2131 | return 0; |
9291a0cd TT |
2132 | |
2133 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2134 | map->version = version; |
b3b272e1 | 2135 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2136 | |
2137 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2138 | |
2139 | i = 0; | |
2140 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2141 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2142 | / 8); |
1fd400ff TT |
2143 | ++i; |
2144 | ||
987d643c TT |
2145 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2146 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2147 | - MAYBE_SWAP (metadata[i])) | |
2148 | / 8); | |
2149 | ++i; | |
1fd400ff TT |
2150 | |
2151 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2152 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2153 | - MAYBE_SWAP (metadata[i])); | |
2154 | ++i; | |
2155 | ||
3876f04e DE |
2156 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2157 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2158 | - MAYBE_SWAP (metadata[i])) | |
2159 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2160 | ++i; |
9291a0cd | 2161 | |
1fd400ff TT |
2162 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2163 | ||
2164 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
2165 | return 0; | |
2166 | ||
8b70b953 TT |
2167 | if (types_list_elements) |
2168 | { | |
2169 | struct dwarf2_section_info *section; | |
2170 | ||
2171 | /* We can only handle a single .debug_types when we have an | |
2172 | index. */ | |
2173 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2174 | return 0; | |
2175 | ||
2176 | section = VEC_index (dwarf2_section_info_def, | |
2177 | dwarf2_per_objfile->types, 0); | |
2178 | ||
2179 | if (!create_signatured_type_table_from_index (objfile, section, | |
2180 | types_list, | |
2181 | types_list_elements)) | |
2182 | return 0; | |
2183 | } | |
9291a0cd TT |
2184 | |
2185 | create_addrmap_from_index (objfile, map); | |
2186 | ||
2187 | dwarf2_per_objfile->index_table = map; | |
2188 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2189 | dwarf2_per_objfile->quick_file_names_table = |
2190 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2191 | |
2192 | return 1; | |
2193 | } | |
2194 | ||
2195 | /* A helper for the "quick" functions which sets the global | |
2196 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2197 | |
9291a0cd TT |
2198 | static void |
2199 | dw2_setup (struct objfile *objfile) | |
2200 | { | |
2201 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2202 | gdb_assert (dwarf2_per_objfile); | |
2203 | } | |
2204 | ||
2205 | /* A helper for the "quick" functions which attempts to read the line | |
2206 | table for THIS_CU. */ | |
2fdf6df6 | 2207 | |
7b9f3c50 DE |
2208 | static struct quick_file_names * |
2209 | dw2_get_file_names (struct objfile *objfile, | |
2210 | struct dwarf2_per_cu_data *this_cu) | |
9291a0cd TT |
2211 | { |
2212 | bfd *abfd = objfile->obfd; | |
7b9f3c50 | 2213 | struct line_header *lh; |
9291a0cd TT |
2214 | struct attribute *attr; |
2215 | struct cleanup *cleanups; | |
2216 | struct die_info *comp_unit_die; | |
36374493 | 2217 | struct dwarf2_section_info* sec; |
9ff913ba | 2218 | gdb_byte *info_ptr; |
9291a0cd TT |
2219 | int has_children, i; |
2220 | struct dwarf2_cu cu; | |
9ff913ba | 2221 | unsigned int bytes_read; |
9291a0cd TT |
2222 | struct die_reader_specs reader_specs; |
2223 | char *name, *comp_dir; | |
7b9f3c50 DE |
2224 | void **slot; |
2225 | struct quick_file_names *qfn; | |
2226 | unsigned int line_offset; | |
9291a0cd | 2227 | |
7b9f3c50 DE |
2228 | if (this_cu->v.quick->file_names != NULL) |
2229 | return this_cu->v.quick->file_names; | |
2230 | /* If we know there is no line data, no point in looking again. */ | |
2231 | if (this_cu->v.quick->no_file_data) | |
2232 | return NULL; | |
9291a0cd | 2233 | |
23745b47 | 2234 | init_one_comp_unit (&cu, this_cu); |
9291a0cd TT |
2235 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
2236 | ||
b0df02fd DE |
2237 | if (this_cu->debug_types_section) |
2238 | sec = this_cu->debug_types_section; | |
36374493 DE |
2239 | else |
2240 | sec = &dwarf2_per_objfile->info; | |
2241 | dwarf2_read_section (objfile, sec); | |
9ff913ba | 2242 | info_ptr = sec->buffer + this_cu->offset; |
9291a0cd | 2243 | |
9ff913ba DE |
2244 | info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr, |
2245 | this_cu->debug_types_section != NULL); | |
9291a0cd | 2246 | |
6caca83c | 2247 | /* Skip dummy compilation units. */ |
9ff913ba | 2248 | if (info_ptr >= (sec->buffer + sec->size) |
6caca83c CC |
2249 | || peek_abbrev_code (abfd, info_ptr) == 0) |
2250 | { | |
2251 | do_cleanups (cleanups); | |
2252 | return NULL; | |
2253 | } | |
2254 | ||
e5fe5e75 | 2255 | dwarf2_read_abbrevs (&cu); |
9291a0cd TT |
2256 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
2257 | ||
9291a0cd | 2258 | init_cu_die_reader (&reader_specs, &cu); |
e8e80198 MS |
2259 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
2260 | &has_children); | |
9291a0cd | 2261 | |
7b9f3c50 DE |
2262 | lh = NULL; |
2263 | slot = NULL; | |
2264 | line_offset = 0; | |
9291a0cd TT |
2265 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
2266 | if (attr) | |
2267 | { | |
7b9f3c50 DE |
2268 | struct quick_file_names find_entry; |
2269 | ||
2270 | line_offset = DW_UNSND (attr); | |
2271 | ||
2272 | /* We may have already read in this line header (TU line header sharing). | |
2273 | If we have we're done. */ | |
2274 | find_entry.offset = line_offset; | |
2275 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2276 | &find_entry, INSERT); | |
2277 | if (*slot != NULL) | |
2278 | { | |
2279 | do_cleanups (cleanups); | |
2280 | this_cu->v.quick->file_names = *slot; | |
2281 | return *slot; | |
2282 | } | |
2283 | ||
9291a0cd TT |
2284 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
2285 | } | |
2286 | if (lh == NULL) | |
2287 | { | |
2288 | do_cleanups (cleanups); | |
7b9f3c50 DE |
2289 | this_cu->v.quick->no_file_data = 1; |
2290 | return NULL; | |
9291a0cd TT |
2291 | } |
2292 | ||
7b9f3c50 DE |
2293 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2294 | qfn->offset = line_offset; | |
2295 | gdb_assert (slot != NULL); | |
2296 | *slot = qfn; | |
9291a0cd | 2297 | |
7b9f3c50 | 2298 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
9291a0cd | 2299 | |
7b9f3c50 DE |
2300 | qfn->num_file_names = lh->num_file_names; |
2301 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2302 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2303 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2304 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2305 | qfn->real_names = NULL; | |
9291a0cd | 2306 | |
7b9f3c50 | 2307 | free_line_header (lh); |
9291a0cd | 2308 | do_cleanups (cleanups); |
7b9f3c50 DE |
2309 | |
2310 | this_cu->v.quick->file_names = qfn; | |
2311 | return qfn; | |
9291a0cd TT |
2312 | } |
2313 | ||
2314 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2315 | real path for a given file name from the line table. */ |
2fdf6df6 | 2316 | |
9291a0cd | 2317 | static const char * |
7b9f3c50 DE |
2318 | dw2_get_real_path (struct objfile *objfile, |
2319 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2320 | { |
7b9f3c50 DE |
2321 | if (qfn->real_names == NULL) |
2322 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2323 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2324 | |
7b9f3c50 DE |
2325 | if (qfn->real_names[index] == NULL) |
2326 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2327 | |
7b9f3c50 | 2328 | return qfn->real_names[index]; |
9291a0cd TT |
2329 | } |
2330 | ||
2331 | static struct symtab * | |
2332 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2333 | { | |
2334 | int index; | |
ae2de4f8 | 2335 | |
9291a0cd TT |
2336 | dw2_setup (objfile); |
2337 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2338 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2339 | } |
2340 | ||
7b9f3c50 DE |
2341 | /* Traversal function for dw2_forget_cached_source_info. */ |
2342 | ||
2343 | static int | |
2344 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2345 | { |
7b9f3c50 | 2346 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2347 | |
7b9f3c50 | 2348 | if (file_data->real_names) |
9291a0cd | 2349 | { |
7b9f3c50 | 2350 | int i; |
9291a0cd | 2351 | |
7b9f3c50 | 2352 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2353 | { |
7b9f3c50 DE |
2354 | xfree ((void*) file_data->real_names[i]); |
2355 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2356 | } |
2357 | } | |
7b9f3c50 DE |
2358 | |
2359 | return 1; | |
2360 | } | |
2361 | ||
2362 | static void | |
2363 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2364 | { | |
2365 | dw2_setup (objfile); | |
2366 | ||
2367 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2368 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2369 | } |
2370 | ||
f8eba3c6 TT |
2371 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
2372 | the symtabs and calls the iterator. */ | |
2373 | ||
2374 | static int | |
2375 | dw2_map_expand_apply (struct objfile *objfile, | |
2376 | struct dwarf2_per_cu_data *per_cu, | |
2377 | const char *name, | |
2378 | const char *full_path, const char *real_path, | |
2379 | int (*callback) (struct symtab *, void *), | |
2380 | void *data) | |
2381 | { | |
2382 | struct symtab *last_made = objfile->symtabs; | |
2383 | ||
2384 | /* Don't visit already-expanded CUs. */ | |
2385 | if (per_cu->v.quick->symtab) | |
2386 | return 0; | |
2387 | ||
2388 | /* This may expand more than one symtab, and we want to iterate over | |
2389 | all of them. */ | |
a0f42c21 | 2390 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
2391 | |
2392 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
2393 | objfile->symtabs, last_made); | |
2394 | } | |
2395 | ||
2396 | /* Implementation of the map_symtabs_matching_filename method. */ | |
2397 | ||
9291a0cd | 2398 | static int |
f8eba3c6 TT |
2399 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
2400 | const char *full_path, const char *real_path, | |
2401 | int (*callback) (struct symtab *, void *), | |
2402 | void *data) | |
9291a0cd TT |
2403 | { |
2404 | int i; | |
c011a4f4 DE |
2405 | const char *name_basename = lbasename (name); |
2406 | int check_basename = name_basename == name; | |
9291a0cd TT |
2407 | struct dwarf2_per_cu_data *base_cu = NULL; |
2408 | ||
2409 | dw2_setup (objfile); | |
ae2de4f8 | 2410 | |
1fd400ff | 2411 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2412 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2413 | { |
2414 | int j; | |
e254ef6a | 2415 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2416 | struct quick_file_names *file_data; |
9291a0cd | 2417 | |
3d7bb9d9 | 2418 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2419 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2420 | continue; |
2421 | ||
7b9f3c50 DE |
2422 | file_data = dw2_get_file_names (objfile, per_cu); |
2423 | if (file_data == NULL) | |
9291a0cd TT |
2424 | continue; |
2425 | ||
7b9f3c50 | 2426 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2427 | { |
7b9f3c50 | 2428 | const char *this_name = file_data->file_names[j]; |
9291a0cd TT |
2429 | |
2430 | if (FILENAME_CMP (name, this_name) == 0) | |
2431 | { | |
f8eba3c6 TT |
2432 | if (dw2_map_expand_apply (objfile, per_cu, |
2433 | name, full_path, real_path, | |
2434 | callback, data)) | |
2435 | return 1; | |
9291a0cd TT |
2436 | } |
2437 | ||
2438 | if (check_basename && ! base_cu | |
2439 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2440 | base_cu = per_cu; |
9291a0cd | 2441 | |
c011a4f4 DE |
2442 | /* Before we invoke realpath, which can get expensive when many |
2443 | files are involved, do a quick comparison of the basenames. */ | |
2444 | if (! basenames_may_differ | |
2445 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
2446 | continue; | |
2447 | ||
9291a0cd TT |
2448 | if (full_path != NULL) |
2449 | { | |
7b9f3c50 DE |
2450 | const char *this_real_name = dw2_get_real_path (objfile, |
2451 | file_data, j); | |
9291a0cd | 2452 | |
7b9f3c50 DE |
2453 | if (this_real_name != NULL |
2454 | && FILENAME_CMP (full_path, this_real_name) == 0) | |
9291a0cd | 2455 | { |
f8eba3c6 TT |
2456 | if (dw2_map_expand_apply (objfile, per_cu, |
2457 | name, full_path, real_path, | |
2458 | callback, data)) | |
2459 | return 1; | |
9291a0cd TT |
2460 | } |
2461 | } | |
2462 | ||
2463 | if (real_path != NULL) | |
2464 | { | |
7b9f3c50 DE |
2465 | const char *this_real_name = dw2_get_real_path (objfile, |
2466 | file_data, j); | |
9291a0cd | 2467 | |
7b9f3c50 DE |
2468 | if (this_real_name != NULL |
2469 | && FILENAME_CMP (real_path, this_real_name) == 0) | |
9291a0cd | 2470 | { |
f8eba3c6 TT |
2471 | if (dw2_map_expand_apply (objfile, per_cu, |
2472 | name, full_path, real_path, | |
2473 | callback, data)) | |
2474 | return 1; | |
9291a0cd TT |
2475 | } |
2476 | } | |
2477 | } | |
2478 | } | |
2479 | ||
2480 | if (base_cu) | |
2481 | { | |
f8eba3c6 TT |
2482 | if (dw2_map_expand_apply (objfile, base_cu, |
2483 | name, full_path, real_path, | |
2484 | callback, data)) | |
2485 | return 1; | |
9291a0cd TT |
2486 | } |
2487 | ||
2488 | return 0; | |
2489 | } | |
2490 | ||
2491 | static struct symtab * | |
2492 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2493 | const char *name, domain_enum domain) | |
2494 | { | |
774b6a14 | 2495 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2496 | instead. */ |
2497 | return NULL; | |
2498 | } | |
2499 | ||
2500 | /* A helper function that expands all symtabs that hold an object | |
2501 | named NAME. */ | |
2fdf6df6 | 2502 | |
9291a0cd TT |
2503 | static void |
2504 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2505 | { | |
2506 | dw2_setup (objfile); | |
2507 | ||
ae2de4f8 | 2508 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2509 | if (dwarf2_per_objfile->index_table) |
2510 | { | |
2511 | offset_type *vec; | |
2512 | ||
2513 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2514 | name, &vec)) | |
2515 | { | |
2516 | offset_type i, len = MAYBE_SWAP (*vec); | |
2517 | for (i = 0; i < len; ++i) | |
2518 | { | |
2519 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2520 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2521 | |
a0f42c21 | 2522 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2523 | } |
2524 | } | |
2525 | } | |
2526 | } | |
2527 | ||
774b6a14 TT |
2528 | static void |
2529 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2530 | enum block_enum block_kind, const char *name, |
774b6a14 | 2531 | domain_enum domain) |
9291a0cd | 2532 | { |
774b6a14 | 2533 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2534 | } |
2535 | ||
2536 | static void | |
2537 | dw2_print_stats (struct objfile *objfile) | |
2538 | { | |
2539 | int i, count; | |
2540 | ||
2541 | dw2_setup (objfile); | |
2542 | count = 0; | |
1fd400ff | 2543 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2544 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2545 | { |
e254ef6a | 2546 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2547 | |
e254ef6a | 2548 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2549 | ++count; |
2550 | } | |
2551 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2552 | } | |
2553 | ||
2554 | static void | |
2555 | dw2_dump (struct objfile *objfile) | |
2556 | { | |
2557 | /* Nothing worth printing. */ | |
2558 | } | |
2559 | ||
2560 | static void | |
2561 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2562 | struct section_offsets *delta) | |
2563 | { | |
2564 | /* There's nothing to relocate here. */ | |
2565 | } | |
2566 | ||
2567 | static void | |
2568 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2569 | const char *func_name) | |
2570 | { | |
2571 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2572 | } | |
2573 | ||
2574 | static void | |
2575 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2576 | { | |
2577 | int i; | |
2578 | ||
2579 | dw2_setup (objfile); | |
1fd400ff TT |
2580 | |
2581 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2582 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2583 | { |
e254ef6a | 2584 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2585 | |
a0f42c21 | 2586 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2587 | } |
2588 | } | |
2589 | ||
2590 | static void | |
2591 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2592 | const char *filename) | |
2593 | { | |
2594 | int i; | |
2595 | ||
2596 | dw2_setup (objfile); | |
d4637a04 DE |
2597 | |
2598 | /* We don't need to consider type units here. | |
2599 | This is only called for examining code, e.g. expand_line_sal. | |
2600 | There can be an order of magnitude (or more) more type units | |
2601 | than comp units, and we avoid them if we can. */ | |
2602 | ||
2603 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2604 | { |
2605 | int j; | |
e254ef6a | 2606 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2607 | struct quick_file_names *file_data; |
9291a0cd | 2608 | |
3d7bb9d9 | 2609 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2610 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2611 | continue; |
2612 | ||
7b9f3c50 DE |
2613 | file_data = dw2_get_file_names (objfile, per_cu); |
2614 | if (file_data == NULL) | |
9291a0cd TT |
2615 | continue; |
2616 | ||
7b9f3c50 | 2617 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2618 | { |
7b9f3c50 | 2619 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2620 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2621 | { |
a0f42c21 | 2622 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2623 | break; |
2624 | } | |
2625 | } | |
2626 | } | |
2627 | } | |
2628 | ||
dd786858 | 2629 | static const char * |
9291a0cd TT |
2630 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2631 | { | |
e254ef6a | 2632 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2633 | offset_type *vec; |
7b9f3c50 | 2634 | struct quick_file_names *file_data; |
9291a0cd TT |
2635 | |
2636 | dw2_setup (objfile); | |
2637 | ||
ae2de4f8 | 2638 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2639 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2640 | { |
2641 | struct symtab *s; | |
2642 | ||
2643 | ALL_OBJFILE_SYMTABS (objfile, s) | |
2644 | if (s->primary) | |
2645 | { | |
2646 | struct blockvector *bv = BLOCKVECTOR (s); | |
2647 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2648 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2649 | ||
2650 | if (sym) | |
2651 | return sym->symtab->filename; | |
2652 | } | |
2653 | return NULL; | |
2654 | } | |
9291a0cd TT |
2655 | |
2656 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2657 | name, &vec)) | |
2658 | return NULL; | |
2659 | ||
2660 | /* Note that this just looks at the very first one named NAME -- but | |
2661 | actually we are looking for a function. find_main_filename | |
2662 | should be rewritten so that it doesn't require a custom hook. It | |
2663 | could just use the ordinary symbol tables. */ | |
2664 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2665 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2666 | |
7b9f3c50 DE |
2667 | file_data = dw2_get_file_names (objfile, per_cu); |
2668 | if (file_data == NULL) | |
9291a0cd TT |
2669 | return NULL; |
2670 | ||
7b9f3c50 | 2671 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2672 | } |
2673 | ||
2674 | static void | |
40658b94 PH |
2675 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2676 | struct objfile *objfile, int global, | |
2677 | int (*callback) (struct block *, | |
2678 | struct symbol *, void *), | |
2edb89d3 JK |
2679 | void *data, symbol_compare_ftype *match, |
2680 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2681 | { |
40658b94 | 2682 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2683 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2684 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2685 | } |
2686 | ||
2687 | static void | |
f8eba3c6 TT |
2688 | dw2_expand_symtabs_matching |
2689 | (struct objfile *objfile, | |
2690 | int (*file_matcher) (const char *, void *), | |
2691 | int (*name_matcher) (const struct language_defn *, const char *, void *), | |
2692 | enum search_domain kind, | |
2693 | void *data) | |
9291a0cd TT |
2694 | { |
2695 | int i; | |
2696 | offset_type iter; | |
4b5246aa | 2697 | struct mapped_index *index; |
9291a0cd TT |
2698 | |
2699 | dw2_setup (objfile); | |
ae2de4f8 DE |
2700 | |
2701 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2702 | if (!dwarf2_per_objfile->index_table) |
2703 | return; | |
4b5246aa | 2704 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2705 | |
7b08b9eb JK |
2706 | if (file_matcher != NULL) |
2707 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2708 | + dwarf2_per_objfile->n_type_units); ++i) |
7b08b9eb JK |
2709 | { |
2710 | int j; | |
2711 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2712 | struct quick_file_names *file_data; | |
2713 | ||
2714 | per_cu->v.quick->mark = 0; | |
3d7bb9d9 DE |
2715 | |
2716 | /* We only need to look at symtabs not already expanded. */ | |
7b08b9eb JK |
2717 | if (per_cu->v.quick->symtab) |
2718 | continue; | |
2719 | ||
2720 | file_data = dw2_get_file_names (objfile, per_cu); | |
2721 | if (file_data == NULL) | |
2722 | continue; | |
2723 | ||
2724 | for (j = 0; j < file_data->num_file_names; ++j) | |
2725 | { | |
2726 | if (file_matcher (file_data->file_names[j], data)) | |
2727 | { | |
2728 | per_cu->v.quick->mark = 1; | |
2729 | break; | |
2730 | } | |
2731 | } | |
2732 | } | |
9291a0cd | 2733 | |
3876f04e | 2734 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2735 | { |
2736 | offset_type idx = 2 * iter; | |
2737 | const char *name; | |
2738 | offset_type *vec, vec_len, vec_idx; | |
2739 | ||
3876f04e | 2740 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2741 | continue; |
2742 | ||
3876f04e | 2743 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 2744 | |
f8eba3c6 | 2745 | if (! (*name_matcher) (current_language, name, data)) |
9291a0cd TT |
2746 | continue; |
2747 | ||
2748 | /* The name was matched, now expand corresponding CUs that were | |
2749 | marked. */ | |
4b5246aa | 2750 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2751 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2752 | vec_len = MAYBE_SWAP (vec[0]); |
2753 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2754 | { | |
e254ef6a | 2755 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2756 | |
e254ef6a | 2757 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2758 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 2759 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2760 | } |
2761 | } | |
2762 | } | |
2763 | ||
2764 | static struct symtab * | |
2765 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2766 | struct minimal_symbol *msymbol, | |
2767 | CORE_ADDR pc, | |
2768 | struct obj_section *section, | |
2769 | int warn_if_readin) | |
2770 | { | |
2771 | struct dwarf2_per_cu_data *data; | |
2772 | ||
2773 | dw2_setup (objfile); | |
2774 | ||
2775 | if (!objfile->psymtabs_addrmap) | |
2776 | return NULL; | |
2777 | ||
2778 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2779 | if (!data) | |
2780 | return NULL; | |
2781 | ||
2782 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2783 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2784 | paddress (get_objfile_arch (objfile), pc)); |
2785 | ||
a0f42c21 | 2786 | return dw2_instantiate_symtab (data); |
9291a0cd TT |
2787 | } |
2788 | ||
9291a0cd | 2789 | static void |
44b13c5a | 2790 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 2791 | void *data, int need_fullname) |
9291a0cd TT |
2792 | { |
2793 | int i; | |
2794 | ||
2795 | dw2_setup (objfile); | |
ae2de4f8 | 2796 | |
1fd400ff | 2797 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2798 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2799 | { |
2800 | int j; | |
e254ef6a | 2801 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2802 | struct quick_file_names *file_data; |
9291a0cd | 2803 | |
3d7bb9d9 | 2804 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2805 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2806 | continue; |
2807 | ||
7b9f3c50 DE |
2808 | file_data = dw2_get_file_names (objfile, per_cu); |
2809 | if (file_data == NULL) | |
9291a0cd TT |
2810 | continue; |
2811 | ||
7b9f3c50 | 2812 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2813 | { |
74e2f255 DE |
2814 | const char *this_real_name; |
2815 | ||
2816 | if (need_fullname) | |
2817 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
2818 | else | |
2819 | this_real_name = NULL; | |
7b9f3c50 | 2820 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
2821 | } |
2822 | } | |
2823 | } | |
2824 | ||
2825 | static int | |
2826 | dw2_has_symbols (struct objfile *objfile) | |
2827 | { | |
2828 | return 1; | |
2829 | } | |
2830 | ||
2831 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2832 | { | |
2833 | dw2_has_symbols, | |
2834 | dw2_find_last_source_symtab, | |
2835 | dw2_forget_cached_source_info, | |
f8eba3c6 | 2836 | dw2_map_symtabs_matching_filename, |
9291a0cd | 2837 | dw2_lookup_symbol, |
774b6a14 | 2838 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2839 | dw2_print_stats, |
2840 | dw2_dump, | |
2841 | dw2_relocate, | |
2842 | dw2_expand_symtabs_for_function, | |
2843 | dw2_expand_all_symtabs, | |
2844 | dw2_expand_symtabs_with_filename, | |
2845 | dw2_find_symbol_file, | |
40658b94 | 2846 | dw2_map_matching_symbols, |
9291a0cd TT |
2847 | dw2_expand_symtabs_matching, |
2848 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
2849 | dw2_map_symbol_filenames |
2850 | }; | |
2851 | ||
2852 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2853 | file will use psymtabs, or 1 if using the GNU index. */ | |
2854 | ||
2855 | int | |
2856 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2857 | { | |
2858 | /* If we're about to read full symbols, don't bother with the | |
2859 | indices. In this case we also don't care if some other debug | |
2860 | format is making psymtabs, because they are all about to be | |
2861 | expanded anyway. */ | |
2862 | if ((objfile->flags & OBJF_READNOW)) | |
2863 | { | |
2864 | int i; | |
2865 | ||
2866 | dwarf2_per_objfile->using_index = 1; | |
2867 | create_all_comp_units (objfile); | |
1fd400ff | 2868 | create_debug_types_hash_table (objfile); |
7b9f3c50 DE |
2869 | dwarf2_per_objfile->quick_file_names_table = |
2870 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2871 | |
1fd400ff | 2872 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2873 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2874 | { |
e254ef6a | 2875 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2876 | |
e254ef6a DE |
2877 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2878 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2879 | } |
2880 | ||
2881 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2882 | these functions will be no-ops because we will have expanded | |
2883 | all symtabs. */ | |
2884 | return 1; | |
2885 | } | |
2886 | ||
2887 | if (dwarf2_read_index (objfile)) | |
2888 | return 1; | |
2889 | ||
9291a0cd TT |
2890 | return 0; |
2891 | } | |
2892 | ||
2893 | \f | |
2894 | ||
dce234bc PP |
2895 | /* Build a partial symbol table. */ |
2896 | ||
2897 | void | |
f29dff0a | 2898 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2899 | { |
f29dff0a | 2900 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2901 | { |
2902 | init_psymbol_list (objfile, 1024); | |
2903 | } | |
2904 | ||
d146bf1e | 2905 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2906 | } |
c906108c | 2907 | |
45452591 DE |
2908 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2909 | ||
2910 | static inline int | |
2911 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2912 | { | |
2913 | unsigned int bottom = cu_header->offset; | |
2914 | unsigned int top = (cu_header->offset | |
2915 | + cu_header->length | |
2916 | + cu_header->initial_length_size); | |
9a619af0 | 2917 | |
45452591 DE |
2918 | return (offset >= bottom && offset < top); |
2919 | } | |
2920 | ||
93311388 DE |
2921 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2922 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2923 | by the caller. */ | |
107d2387 | 2924 | |
fe1b8b76 | 2925 | static gdb_byte * |
107d2387 | 2926 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2927 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2928 | { |
2929 | int signed_addr; | |
891d2f0b | 2930 | unsigned int bytes_read; |
c764a876 DE |
2931 | |
2932 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2933 | cu_header->initial_length_size = bytes_read; | |
2934 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2935 | info_ptr += bytes_read; |
107d2387 AC |
2936 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2937 | info_ptr += 2; | |
613e1657 | 2938 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2939 | &bytes_read); |
613e1657 | 2940 | info_ptr += bytes_read; |
107d2387 AC |
2941 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2942 | info_ptr += 1; | |
2943 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2944 | if (signed_addr < 0) | |
8e65ff28 | 2945 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2946 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2947 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2948 | |
107d2387 AC |
2949 | return info_ptr; |
2950 | } | |
2951 | ||
9ff913ba DE |
2952 | /* Subroutine of read_and_check_comp_unit_head and |
2953 | read_and_check_type_unit_head to simplify them. | |
2954 | Perform various error checking on the header. */ | |
2955 | ||
2956 | static void | |
2957 | error_check_comp_unit_head (struct comp_unit_head *header, | |
2958 | struct dwarf2_section_info *section) | |
2959 | { | |
2960 | bfd *abfd = section->asection->owner; | |
2961 | const char *filename = bfd_get_filename (abfd); | |
2962 | ||
2963 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
2964 | error (_("Dwarf Error: wrong version in compilation unit header " | |
2965 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
2966 | filename); | |
2967 | ||
2968 | if (header->abbrev_offset | |
2969 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, | |
2970 | &dwarf2_per_objfile->abbrev)) | |
2971 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
2972 | "(offset 0x%lx + 6) [in module %s]"), | |
2973 | (long) header->abbrev_offset, (long) header->offset, | |
2974 | filename); | |
2975 | ||
2976 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
2977 | avoid potential 32-bit overflow. */ | |
2978 | if (((unsigned long) header->offset | |
2979 | + header->length + header->initial_length_size) | |
2980 | > section->size) | |
2981 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
2982 | "(offset 0x%lx + 0) [in module %s]"), | |
2983 | (long) header->length, (long) header->offset, | |
2984 | filename); | |
2985 | } | |
2986 | ||
2987 | /* Read in a CU/TU header and perform some basic error checking. | |
2988 | The contents of the header are stored in HEADER. | |
2989 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 2990 | |
fe1b8b76 | 2991 | static gdb_byte * |
9ff913ba DE |
2992 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
2993 | struct dwarf2_section_info *section, | |
2994 | gdb_byte *info_ptr, | |
2995 | int is_debug_types_section) | |
72bf9492 | 2996 | { |
fe1b8b76 | 2997 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 2998 | bfd *abfd = section->asection->owner; |
72bf9492 | 2999 | |
9ff913ba | 3000 | header->offset = beg_of_comp_unit - section->buffer; |
adabb602 | 3001 | |
72bf9492 DJ |
3002 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3003 | ||
460c1c54 CC |
3004 | /* If we're reading a type unit, skip over the signature and |
3005 | type_offset fields. */ | |
b0df02fd | 3006 | if (is_debug_types_section) |
460c1c54 CC |
3007 | info_ptr += 8 /*signature*/ + header->offset_size; |
3008 | ||
adabb602 DE |
3009 | header->first_die_offset = info_ptr - beg_of_comp_unit; |
3010 | ||
9ff913ba | 3011 | error_check_comp_unit_head (header, section); |
72bf9492 DJ |
3012 | |
3013 | return info_ptr; | |
3014 | } | |
3015 | ||
348e048f DE |
3016 | /* Read in the types comp unit header information from .debug_types entry at |
3017 | types_ptr. The result is a pointer to one past the end of the header. */ | |
3018 | ||
3019 | static gdb_byte * | |
9ff913ba DE |
3020 | read_and_check_type_unit_head (struct comp_unit_head *header, |
3021 | struct dwarf2_section_info *section, | |
3022 | gdb_byte *info_ptr, | |
3023 | ULONGEST *signature, unsigned int *type_offset) | |
348e048f | 3024 | { |
9ff913ba DE |
3025 | gdb_byte *beg_of_comp_unit = info_ptr; |
3026 | bfd *abfd = section->asection->owner; | |
348e048f | 3027 | |
9ff913ba | 3028 | header->offset = beg_of_comp_unit - section->buffer; |
348e048f | 3029 | |
9ff913ba | 3030 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 3031 | |
9ff913ba DE |
3032 | /* If we're reading a type unit, skip over the signature and |
3033 | type_offset fields. */ | |
3034 | if (signature != NULL) | |
3035 | *signature = read_8_bytes (abfd, info_ptr); | |
3036 | info_ptr += 8; | |
3037 | if (type_offset != NULL) | |
3038 | *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size); | |
3039 | info_ptr += header->offset_size; | |
3040 | ||
3041 | header->first_die_offset = info_ptr - beg_of_comp_unit; | |
348e048f | 3042 | |
9ff913ba DE |
3043 | error_check_comp_unit_head (header, section); |
3044 | ||
3045 | return info_ptr; | |
348e048f DE |
3046 | } |
3047 | ||
aaa75496 JB |
3048 | /* Allocate a new partial symtab for file named NAME and mark this new |
3049 | partial symtab as being an include of PST. */ | |
3050 | ||
3051 | static void | |
3052 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3053 | struct objfile *objfile) | |
3054 | { | |
3055 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3056 | ||
3057 | subpst->section_offsets = pst->section_offsets; | |
3058 | subpst->textlow = 0; | |
3059 | subpst->texthigh = 0; | |
3060 | ||
3061 | subpst->dependencies = (struct partial_symtab **) | |
3062 | obstack_alloc (&objfile->objfile_obstack, | |
3063 | sizeof (struct partial_symtab *)); | |
3064 | subpst->dependencies[0] = pst; | |
3065 | subpst->number_of_dependencies = 1; | |
3066 | ||
3067 | subpst->globals_offset = 0; | |
3068 | subpst->n_global_syms = 0; | |
3069 | subpst->statics_offset = 0; | |
3070 | subpst->n_static_syms = 0; | |
3071 | subpst->symtab = NULL; | |
3072 | subpst->read_symtab = pst->read_symtab; | |
3073 | subpst->readin = 0; | |
3074 | ||
3075 | /* No private part is necessary for include psymtabs. This property | |
3076 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3077 | the regular ones. */ |
58a9656e | 3078 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3079 | } |
3080 | ||
3081 | /* Read the Line Number Program data and extract the list of files | |
3082 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3083 | partial symtab for each of these included files. */ |
aaa75496 JB |
3084 | |
3085 | static void | |
3086 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 3087 | struct die_info *die, |
aaa75496 JB |
3088 | struct partial_symtab *pst) |
3089 | { | |
3090 | struct objfile *objfile = cu->objfile; | |
3091 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
3092 | struct line_header *lh = NULL; |
3093 | struct attribute *attr; | |
aaa75496 | 3094 | |
d85a05f0 DJ |
3095 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3096 | if (attr) | |
3097 | { | |
3098 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 3099 | |
d85a05f0 DJ |
3100 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
3101 | } | |
aaa75496 JB |
3102 | if (lh == NULL) |
3103 | return; /* No linetable, so no includes. */ | |
3104 | ||
c6da4cef | 3105 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
f3f5162e | 3106 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
aaa75496 JB |
3107 | |
3108 | free_line_header (lh); | |
3109 | } | |
3110 | ||
348e048f DE |
3111 | static hashval_t |
3112 | hash_type_signature (const void *item) | |
3113 | { | |
3114 | const struct signatured_type *type_sig = item; | |
9a619af0 | 3115 | |
348e048f DE |
3116 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
3117 | return type_sig->signature; | |
3118 | } | |
3119 | ||
3120 | static int | |
3121 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
3122 | { | |
3123 | const struct signatured_type *lhs = item_lhs; | |
3124 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3125 | |
348e048f DE |
3126 | return lhs->signature == rhs->signature; |
3127 | } | |
3128 | ||
1fd400ff TT |
3129 | /* Allocate a hash table for signatured types. */ |
3130 | ||
3131 | static htab_t | |
673bfd45 | 3132 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3133 | { |
3134 | return htab_create_alloc_ex (41, | |
3135 | hash_type_signature, | |
3136 | eq_type_signature, | |
3137 | NULL, | |
3138 | &objfile->objfile_obstack, | |
3139 | hashtab_obstack_allocate, | |
3140 | dummy_obstack_deallocate); | |
3141 | } | |
3142 | ||
d467dd73 | 3143 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
3144 | |
3145 | static int | |
d467dd73 | 3146 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
3147 | { |
3148 | struct signatured_type *sigt = *slot; | |
3149 | struct dwarf2_per_cu_data ***datap = datum; | |
3150 | ||
3151 | **datap = &sigt->per_cu; | |
3152 | ++*datap; | |
3153 | ||
3154 | return 1; | |
3155 | } | |
3156 | ||
d467dd73 | 3157 | /* Create the hash table of all entries in the .debug_types section(s). |
348e048f DE |
3158 | The result is zero if there is an error (e.g. missing .debug_types section), |
3159 | otherwise non-zero. */ | |
3160 | ||
3161 | static int | |
3162 | create_debug_types_hash_table (struct objfile *objfile) | |
3163 | { | |
8b70b953 | 3164 | htab_t types_htab = NULL; |
1fd400ff | 3165 | struct dwarf2_per_cu_data **iter; |
8b70b953 TT |
3166 | int ix; |
3167 | struct dwarf2_section_info *section; | |
348e048f | 3168 | |
8b70b953 | 3169 | if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)) |
348e048f DE |
3170 | { |
3171 | dwarf2_per_objfile->signatured_types = NULL; | |
3172 | return 0; | |
3173 | } | |
3174 | ||
8b70b953 TT |
3175 | for (ix = 0; |
3176 | VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
3177 | ix, section); | |
3178 | ++ix) | |
3179 | { | |
3180 | gdb_byte *info_ptr, *end_ptr; | |
348e048f | 3181 | |
8b70b953 TT |
3182 | dwarf2_read_section (objfile, section); |
3183 | info_ptr = section->buffer; | |
348e048f | 3184 | |
8b70b953 TT |
3185 | if (info_ptr == NULL) |
3186 | continue; | |
348e048f | 3187 | |
8b70b953 TT |
3188 | if (types_htab == NULL) |
3189 | types_htab = allocate_signatured_type_table (objfile); | |
348e048f | 3190 | |
8b70b953 TT |
3191 | if (dwarf2_die_debug) |
3192 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
3193 | ||
3194 | end_ptr = info_ptr + section->size; | |
3195 | while (info_ptr < end_ptr) | |
3196 | { | |
3197 | unsigned int offset; | |
8b70b953 | 3198 | unsigned int type_offset; |
8b70b953 TT |
3199 | ULONGEST signature; |
3200 | struct signatured_type *type_sig; | |
3201 | void **slot; | |
3202 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 3203 | struct comp_unit_head header; |
348e048f | 3204 | |
8b70b953 | 3205 | offset = ptr - section->buffer; |
348e048f | 3206 | |
8b70b953 | 3207 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 3208 | table, but we don't need anything else just yet. */ |
348e048f | 3209 | |
9ff913ba DE |
3210 | ptr = read_and_check_type_unit_head (&header, section, ptr, |
3211 | &signature, &type_offset); | |
6caca83c CC |
3212 | |
3213 | /* Skip dummy type units. */ | |
3214 | if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0) | |
3215 | { | |
9ff913ba | 3216 | info_ptr = info_ptr + header.initial_length_size + header.length; |
6caca83c CC |
3217 | continue; |
3218 | } | |
8b70b953 TT |
3219 | |
3220 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
3221 | memset (type_sig, 0, sizeof (*type_sig)); | |
3222 | type_sig->signature = signature; | |
3223 | type_sig->type_offset = type_offset; | |
3224 | type_sig->per_cu.objfile = objfile; | |
b0df02fd | 3225 | type_sig->per_cu.debug_types_section = section; |
8b70b953 TT |
3226 | type_sig->per_cu.offset = offset; |
3227 | ||
3228 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
3229 | gdb_assert (slot != NULL); | |
3230 | if (*slot != NULL) | |
3231 | { | |
3232 | const struct signatured_type *dup_sig = *slot; | |
b3c8eb43 | 3233 | |
8b70b953 TT |
3234 | complaint (&symfile_complaints, |
3235 | _("debug type entry at offset 0x%x is duplicate to the " | |
3236 | "entry at offset 0x%x, signature 0x%s"), | |
3237 | offset, dup_sig->per_cu.offset, | |
3238 | phex (signature, sizeof (signature))); | |
3239 | gdb_assert (signature == dup_sig->signature); | |
3240 | } | |
3241 | *slot = type_sig; | |
348e048f | 3242 | |
8b70b953 TT |
3243 | if (dwarf2_die_debug) |
3244 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
3245 | offset, phex (signature, sizeof (signature))); | |
348e048f | 3246 | |
9ff913ba | 3247 | info_ptr = info_ptr + header.initial_length_size + header.length; |
8b70b953 | 3248 | } |
348e048f DE |
3249 | } |
3250 | ||
3251 | dwarf2_per_objfile->signatured_types = types_htab; | |
3252 | ||
d467dd73 DE |
3253 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
3254 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 3255 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 3256 | dwarf2_per_objfile->n_type_units |
1fd400ff | 3257 | * sizeof (struct dwarf2_per_cu_data *)); |
d467dd73 DE |
3258 | iter = &dwarf2_per_objfile->all_type_units[0]; |
3259 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
3260 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
3261 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3262 | |
348e048f DE |
3263 | return 1; |
3264 | } | |
3265 | ||
3266 | /* Lookup a signature based type. | |
3267 | Returns NULL if SIG is not present in the table. */ | |
3268 | ||
3269 | static struct signatured_type * | |
3270 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
3271 | { | |
3272 | struct signatured_type find_entry, *entry; | |
3273 | ||
3274 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3275 | { | |
3276 | complaint (&symfile_complaints, | |
55f1336d | 3277 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
348e048f DE |
3278 | return 0; |
3279 | } | |
3280 | ||
3281 | find_entry.signature = sig; | |
3282 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3283 | return entry; | |
3284 | } | |
3285 | ||
d85a05f0 DJ |
3286 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3287 | ||
3288 | static void | |
3289 | init_cu_die_reader (struct die_reader_specs *reader, | |
3290 | struct dwarf2_cu *cu) | |
3291 | { | |
3292 | reader->abfd = cu->objfile->obfd; | |
3293 | reader->cu = cu; | |
b0df02fd | 3294 | if (cu->per_cu->debug_types_section) |
be391dca | 3295 | { |
b0df02fd DE |
3296 | gdb_assert (cu->per_cu->debug_types_section->readin); |
3297 | reader->buffer = cu->per_cu->debug_types_section->buffer; | |
be391dca | 3298 | } |
d85a05f0 | 3299 | else |
be391dca TT |
3300 | { |
3301 | gdb_assert (dwarf2_per_objfile->info.readin); | |
3302 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
3303 | } | |
d85a05f0 DJ |
3304 | } |
3305 | ||
3306 | /* Find the base address of the compilation unit for range lists and | |
3307 | location lists. It will normally be specified by DW_AT_low_pc. | |
3308 | In DWARF-3 draft 4, the base address could be overridden by | |
3309 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3310 | compilation units with discontinuous ranges. */ | |
3311 | ||
3312 | static void | |
3313 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3314 | { | |
3315 | struct attribute *attr; | |
3316 | ||
3317 | cu->base_known = 0; | |
3318 | cu->base_address = 0; | |
3319 | ||
3320 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3321 | if (attr) | |
3322 | { | |
3323 | cu->base_address = DW_ADDR (attr); | |
3324 | cu->base_known = 1; | |
3325 | } | |
3326 | else | |
3327 | { | |
3328 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3329 | if (attr) | |
3330 | { | |
3331 | cu->base_address = DW_ADDR (attr); | |
3332 | cu->base_known = 1; | |
3333 | } | |
3334 | } | |
3335 | } | |
3336 | ||
348e048f DE |
3337 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
3338 | to combine the common parts. | |
21b2bd31 DE |
3339 | Process compilation unit THIS_CU for a psymtab. |
3340 | SECTION is the section the CU/TU comes from, | |
3341 | either .debug_info or .debug_types. */ | |
aaa75496 | 3342 | |
21b2bd31 | 3343 | void |
a0f42c21 | 3344 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
21b2bd31 DE |
3345 | struct dwarf2_section_info *section, |
3346 | int is_debug_types_section) | |
c906108c | 3347 | { |
a0f42c21 | 3348 | struct objfile *objfile = this_cu->objfile; |
c906108c | 3349 | bfd *abfd = objfile->obfd; |
21b2bd31 DE |
3350 | gdb_byte *buffer = section->buffer; |
3351 | gdb_byte *info_ptr = buffer + this_cu->offset; | |
3352 | unsigned int buffer_size = section->size; | |
93311388 | 3353 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3354 | struct die_info *comp_unit_die; |
c906108c | 3355 | struct partial_symtab *pst; |
5734ee8b | 3356 | CORE_ADDR baseaddr; |
93311388 DE |
3357 | struct cleanup *back_to_inner; |
3358 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3359 | int has_children, has_pc_info; |
3360 | struct attribute *attr; | |
d85a05f0 DJ |
3361 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3362 | struct die_reader_specs reader_specs; | |
3e2a0cee | 3363 | const char *filename; |
c906108c | 3364 | |
23745b47 DE |
3365 | /* If this compilation unit was already read in, free the |
3366 | cached copy in order to read it in again. This is | |
3367 | necessary because we skipped some symbols when we first | |
3368 | read in the compilation unit (see load_partial_dies). | |
3369 | This problem could be avoided, but the benefit is | |
3370 | unclear. */ | |
3371 | if (this_cu->cu != NULL) | |
3372 | free_one_cached_comp_unit (this_cu->cu); | |
3373 | ||
3374 | /* Note that this is a pointer to our stack frame, being | |
3375 | added to a global data structure. It will be cleaned up | |
3376 | in free_stack_comp_unit when we finish with this | |
3377 | compilation unit. */ | |
3378 | init_one_comp_unit (&cu, this_cu); | |
93311388 | 3379 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3380 | |
9ff913ba DE |
3381 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr, |
3382 | is_debug_types_section); | |
10b3939b | 3383 | |
6caca83c CC |
3384 | /* Skip dummy compilation units. */ |
3385 | if (info_ptr >= buffer + buffer_size | |
3386 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
3387 | { | |
6caca83c | 3388 | do_cleanups (back_to_inner); |
21b2bd31 | 3389 | return; |
6caca83c CC |
3390 | } |
3391 | ||
93311388 | 3392 | cu.list_in_scope = &file_symbols; |
af703f96 | 3393 | |
93311388 | 3394 | /* Read the abbrevs for this compilation unit into a table. */ |
e5fe5e75 | 3395 | dwarf2_read_abbrevs (&cu); |
93311388 | 3396 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
af703f96 | 3397 | |
93311388 | 3398 | /* Read the compilation unit die. */ |
d85a05f0 DJ |
3399 | init_cu_die_reader (&reader_specs, &cu); |
3400 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3401 | &has_children); | |
93311388 | 3402 | |
21b2bd31 | 3403 | if (is_debug_types_section) |
348e048f | 3404 | { |
b3c8eb43 JK |
3405 | /* LENGTH has not been set yet for type units. */ |
3406 | gdb_assert (this_cu->offset == cu.header.offset); | |
348e048f DE |
3407 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
3408 | } | |
d85a05f0 | 3409 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3410 | { |
93311388 | 3411 | do_cleanups (back_to_inner); |
21b2bd31 | 3412 | return; |
93311388 | 3413 | } |
72bf9492 | 3414 | |
9816fde3 | 3415 | prepare_one_comp_unit (&cu, comp_unit_die); |
c906108c | 3416 | |
93311388 | 3417 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3418 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
3e2a0cee TT |
3419 | if (attr == NULL || !DW_STRING (attr)) |
3420 | filename = ""; | |
3421 | else | |
3422 | filename = DW_STRING (attr); | |
93311388 | 3423 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3424 | filename, |
93311388 DE |
3425 | /* TEXTLOW and TEXTHIGH are set below. */ |
3426 | 0, | |
3427 | objfile->global_psymbols.next, | |
3428 | objfile->static_psymbols.next); | |
9750bca9 | 3429 | pst->psymtabs_addrmap_supported = 1; |
72bf9492 | 3430 | |
d85a05f0 DJ |
3431 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3432 | if (attr != NULL) | |
3433 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3434 | |
e38df1d0 | 3435 | pst->read_symtab_private = this_cu; |
72bf9492 | 3436 | |
93311388 | 3437 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3438 | |
0963b4bd | 3439 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3440 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3441 | |
9291a0cd | 3442 | this_cu->v.psymtab = pst; |
c906108c | 3443 | |
d85a05f0 DJ |
3444 | dwarf2_find_base_address (comp_unit_die, &cu); |
3445 | ||
93311388 DE |
3446 | /* Possibly set the default values of LOWPC and HIGHPC from |
3447 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3448 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3449 | &best_highpc, &cu, pst); | |
3450 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3451 | /* Store the contiguous range if it is not empty; it can be empty for |
3452 | CUs with no code. */ | |
3453 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3454 | best_lowpc + baseaddr, |
3455 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3456 | |
3457 | /* Check if comp unit has_children. | |
3458 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3459 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3460 | if (has_children) |
93311388 DE |
3461 | { |
3462 | struct partial_die_info *first_die; | |
3463 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3464 | |
93311388 DE |
3465 | lowpc = ((CORE_ADDR) -1); |
3466 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3467 | |
93311388 | 3468 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3469 | |
93311388 | 3470 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3471 | ! has_pc_info, &cu); |
57c22c6c | 3472 | |
93311388 DE |
3473 | /* If we didn't find a lowpc, set it to highpc to avoid |
3474 | complaints from `maint check'. */ | |
3475 | if (lowpc == ((CORE_ADDR) -1)) | |
3476 | lowpc = highpc; | |
10b3939b | 3477 | |
93311388 DE |
3478 | /* If the compilation unit didn't have an explicit address range, |
3479 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3480 | if (! has_pc_info) |
93311388 | 3481 | { |
d85a05f0 DJ |
3482 | best_lowpc = lowpc; |
3483 | best_highpc = highpc; | |
93311388 DE |
3484 | } |
3485 | } | |
d85a05f0 DJ |
3486 | pst->textlow = best_lowpc + baseaddr; |
3487 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3488 | |
93311388 DE |
3489 | pst->n_global_syms = objfile->global_psymbols.next - |
3490 | (objfile->global_psymbols.list + pst->globals_offset); | |
3491 | pst->n_static_syms = objfile->static_psymbols.next - | |
3492 | (objfile->static_psymbols.list + pst->statics_offset); | |
3493 | sort_pst_symbols (pst); | |
c906108c | 3494 | |
21b2bd31 | 3495 | if (is_debug_types_section) |
348e048f DE |
3496 | { |
3497 | /* It's not clear we want to do anything with stmt lists here. | |
3498 | Waiting to see what gcc ultimately does. */ | |
3499 | } | |
d85a05f0 | 3500 | else |
93311388 DE |
3501 | { |
3502 | /* Get the list of files included in the current compilation unit, | |
3503 | and build a psymtab for each of them. */ | |
d85a05f0 | 3504 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3505 | } |
ae038cb0 | 3506 | |
93311388 | 3507 | do_cleanups (back_to_inner); |
93311388 | 3508 | } |
ff013f42 | 3509 | |
348e048f DE |
3510 | /* Traversal function for htab_traverse_noresize. |
3511 | Process one .debug_types comp-unit. */ | |
3512 | ||
3513 | static int | |
3514 | process_type_comp_unit (void **slot, void *info) | |
3515 | { | |
3516 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
348e048f DE |
3517 | struct dwarf2_per_cu_data *this_cu; |
3518 | ||
a0f42c21 | 3519 | gdb_assert (info == NULL); |
348e048f | 3520 | this_cu = &entry->per_cu; |
348e048f | 3521 | |
b0df02fd | 3522 | gdb_assert (this_cu->debug_types_section->readin); |
21b2bd31 | 3523 | process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1); |
348e048f DE |
3524 | |
3525 | return 1; | |
3526 | } | |
3527 | ||
3528 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3529 | Build partial symbol tables for the .debug_types comp-units. */ | |
3530 | ||
3531 | static void | |
3532 | build_type_psymtabs (struct objfile *objfile) | |
3533 | { | |
3534 | if (! create_debug_types_hash_table (objfile)) | |
3535 | return; | |
3536 | ||
3537 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
a0f42c21 | 3538 | process_type_comp_unit, NULL); |
348e048f DE |
3539 | } |
3540 | ||
60606b2c TT |
3541 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3542 | ||
3543 | static void | |
3544 | psymtabs_addrmap_cleanup (void *o) | |
3545 | { | |
3546 | struct objfile *objfile = o; | |
ec61707d | 3547 | |
60606b2c TT |
3548 | objfile->psymtabs_addrmap = NULL; |
3549 | } | |
3550 | ||
93311388 DE |
3551 | /* Build the partial symbol table by doing a quick pass through the |
3552 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3553 | |
93311388 | 3554 | static void |
c67a9c90 | 3555 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3556 | { |
60606b2c TT |
3557 | struct cleanup *back_to, *addrmap_cleanup; |
3558 | struct obstack temp_obstack; | |
21b2bd31 | 3559 | int i; |
93311388 | 3560 | |
98bfdba5 PA |
3561 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3562 | ||
be391dca | 3563 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 3564 | |
93311388 DE |
3565 | /* Any cached compilation units will be linked by the per-objfile |
3566 | read_in_chain. Make sure to free them when we're done. */ | |
3567 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3568 | |
348e048f DE |
3569 | build_type_psymtabs (objfile); |
3570 | ||
93311388 | 3571 | create_all_comp_units (objfile); |
c906108c | 3572 | |
60606b2c TT |
3573 | /* Create a temporary address map on a temporary obstack. We later |
3574 | copy this to the final obstack. */ | |
3575 | obstack_init (&temp_obstack); | |
3576 | make_cleanup_obstack_free (&temp_obstack); | |
3577 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3578 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3579 | |
21b2bd31 | 3580 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 3581 | { |
21b2bd31 | 3582 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 3583 | |
21b2bd31 | 3584 | process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0); |
c906108c | 3585 | } |
ff013f42 JK |
3586 | |
3587 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3588 | &objfile->objfile_obstack); | |
60606b2c | 3589 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3590 | |
ae038cb0 DJ |
3591 | do_cleanups (back_to); |
3592 | } | |
3593 | ||
93311388 | 3594 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3595 | |
3596 | static void | |
a0f42c21 | 3597 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) |
ae038cb0 | 3598 | { |
a0f42c21 | 3599 | struct objfile *objfile = this_cu->objfile; |
ae038cb0 | 3600 | bfd *abfd = objfile->obfd; |
adabb602 | 3601 | gdb_byte *info_ptr; |
d85a05f0 | 3602 | struct die_info *comp_unit_die; |
ae038cb0 | 3603 | struct dwarf2_cu *cu; |
1d9ec526 | 3604 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3605 | int has_children; |
3606 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3607 | int read_cu = 0; |
9ff913ba | 3608 | struct dwarf2_section_info *section = &dwarf2_per_objfile->info; |
ae038cb0 | 3609 | |
b0df02fd | 3610 | gdb_assert (! this_cu->debug_types_section); |
348e048f | 3611 | |
9ff913ba DE |
3612 | gdb_assert (section->readin); |
3613 | info_ptr = section->buffer + this_cu->offset; | |
ae038cb0 | 3614 | |
98bfdba5 PA |
3615 | if (this_cu->cu == NULL) |
3616 | { | |
9816fde3 | 3617 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 3618 | init_one_comp_unit (cu, this_cu); |
ae038cb0 | 3619 | |
98bfdba5 | 3620 | read_cu = 1; |
ae038cb0 | 3621 | |
98bfdba5 | 3622 | /* If an error occurs while loading, release our storage. */ |
68dc6402 | 3623 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
328c9494 | 3624 | |
9ff913ba DE |
3625 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr, |
3626 | 0); | |
ae038cb0 | 3627 | |
6caca83c | 3628 | /* Skip dummy compilation units. */ |
9ff913ba | 3629 | if (info_ptr >= (section->buffer + section->size) |
6caca83c CC |
3630 | || peek_abbrev_code (abfd, info_ptr) == 0) |
3631 | { | |
3632 | do_cleanups (free_cu_cleanup); | |
3633 | return; | |
3634 | } | |
3635 | ||
98bfdba5 PA |
3636 | /* Link this CU into read_in_chain. */ |
3637 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3638 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3639 | } | |
3640 | else | |
3641 | { | |
3642 | cu = this_cu->cu; | |
3643 | info_ptr += cu->header.first_die_offset; | |
3644 | } | |
ae038cb0 DJ |
3645 | |
3646 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3647 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
e5fe5e75 | 3648 | dwarf2_read_abbrevs (cu); |
98bfdba5 | 3649 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3650 | |
3651 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3652 | init_cu_die_reader (&reader_specs, cu); |
3653 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3654 | &has_children); | |
ae038cb0 | 3655 | |
9816fde3 | 3656 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3657 | |
ae038cb0 DJ |
3658 | /* Check if comp unit has_children. |
3659 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3660 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3661 | if (has_children) |
9ff913ba | 3662 | load_partial_dies (abfd, section->buffer, info_ptr, 0, cu); |
ae038cb0 | 3663 | |
98bfdba5 PA |
3664 | do_cleanups (free_abbrevs_cleanup); |
3665 | ||
3666 | if (read_cu) | |
3667 | { | |
3668 | /* We've successfully allocated this compilation unit. Let our | |
3669 | caller clean it up when finished with it. */ | |
3670 | discard_cleanups (free_cu_cleanup); | |
3671 | } | |
ae038cb0 DJ |
3672 | } |
3673 | ||
9cdd5dbd DE |
3674 | /* Create a list of all compilation units in OBJFILE. |
3675 | This is only done for -readnow and building partial symtabs. */ | |
ae038cb0 DJ |
3676 | |
3677 | static void | |
3678 | create_all_comp_units (struct objfile *objfile) | |
3679 | { | |
3680 | int n_allocated; | |
3681 | int n_comp_units; | |
3682 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3683 | gdb_byte *info_ptr; |
3684 | ||
3685 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3686 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3687 | |
3688 | n_comp_units = 0; | |
3689 | n_allocated = 10; | |
3690 | all_comp_units = xmalloc (n_allocated | |
3691 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3692 | |
3e43a32a MS |
3693 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3694 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3695 | { |
c764a876 | 3696 | unsigned int length, initial_length_size; |
ae038cb0 | 3697 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3698 | unsigned int offset; |
ae038cb0 | 3699 | |
dce234bc | 3700 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3701 | |
3702 | /* Read just enough information to find out where the next | |
3703 | compilation unit is. */ | |
c764a876 DE |
3704 | length = read_initial_length (objfile->obfd, info_ptr, |
3705 | &initial_length_size); | |
ae038cb0 DJ |
3706 | |
3707 | /* Save the compilation unit for later lookup. */ | |
3708 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3709 | sizeof (struct dwarf2_per_cu_data)); | |
3710 | memset (this_cu, 0, sizeof (*this_cu)); | |
3711 | this_cu->offset = offset; | |
c764a876 | 3712 | this_cu->length = length + initial_length_size; |
9291a0cd | 3713 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3714 | |
3715 | if (n_comp_units == n_allocated) | |
3716 | { | |
3717 | n_allocated *= 2; | |
3718 | all_comp_units = xrealloc (all_comp_units, | |
3719 | n_allocated | |
3720 | * sizeof (struct dwarf2_per_cu_data *)); | |
3721 | } | |
3722 | all_comp_units[n_comp_units++] = this_cu; | |
3723 | ||
3724 | info_ptr = info_ptr + this_cu->length; | |
3725 | } | |
3726 | ||
3727 | dwarf2_per_objfile->all_comp_units | |
3728 | = obstack_alloc (&objfile->objfile_obstack, | |
3729 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3730 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3731 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3732 | xfree (all_comp_units); | |
3733 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3734 | } |
3735 | ||
5734ee8b DJ |
3736 | /* Process all loaded DIEs for compilation unit CU, starting at |
3737 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3738 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3739 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3740 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3741 | and record the covered ranges in the addrmap. */ | |
c906108c | 3742 | |
72bf9492 DJ |
3743 | static void |
3744 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3745 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3746 | { |
72bf9492 | 3747 | struct partial_die_info *pdi; |
c906108c | 3748 | |
91c24f0a DC |
3749 | /* Now, march along the PDI's, descending into ones which have |
3750 | interesting children but skipping the children of the other ones, | |
3751 | until we reach the end of the compilation unit. */ | |
c906108c | 3752 | |
72bf9492 | 3753 | pdi = first_die; |
91c24f0a | 3754 | |
72bf9492 DJ |
3755 | while (pdi != NULL) |
3756 | { | |
3757 | fixup_partial_die (pdi, cu); | |
c906108c | 3758 | |
f55ee35c | 3759 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3760 | children, so we need to look at them. Ditto for anonymous |
3761 | enums. */ | |
933c6fe4 | 3762 | |
72bf9492 | 3763 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3764 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3765 | { |
72bf9492 | 3766 | switch (pdi->tag) |
c906108c SS |
3767 | { |
3768 | case DW_TAG_subprogram: | |
5734ee8b | 3769 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 3770 | break; |
72929c62 | 3771 | case DW_TAG_constant: |
c906108c SS |
3772 | case DW_TAG_variable: |
3773 | case DW_TAG_typedef: | |
91c24f0a | 3774 | case DW_TAG_union_type: |
72bf9492 | 3775 | if (!pdi->is_declaration) |
63d06c5c | 3776 | { |
72bf9492 | 3777 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3778 | } |
3779 | break; | |
c906108c | 3780 | case DW_TAG_class_type: |
680b30c7 | 3781 | case DW_TAG_interface_type: |
c906108c | 3782 | case DW_TAG_structure_type: |
72bf9492 | 3783 | if (!pdi->is_declaration) |
c906108c | 3784 | { |
72bf9492 | 3785 | add_partial_symbol (pdi, cu); |
c906108c SS |
3786 | } |
3787 | break; | |
91c24f0a | 3788 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3789 | if (!pdi->is_declaration) |
3790 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3791 | break; |
3792 | case DW_TAG_base_type: | |
a02abb62 | 3793 | case DW_TAG_subrange_type: |
c906108c | 3794 | /* File scope base type definitions are added to the partial |
c5aa993b | 3795 | symbol table. */ |
72bf9492 | 3796 | add_partial_symbol (pdi, cu); |
c906108c | 3797 | break; |
d9fa45fe | 3798 | case DW_TAG_namespace: |
5734ee8b | 3799 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3800 | break; |
5d7cb8df JK |
3801 | case DW_TAG_module: |
3802 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3803 | break; | |
c906108c SS |
3804 | default: |
3805 | break; | |
3806 | } | |
3807 | } | |
3808 | ||
72bf9492 DJ |
3809 | /* If the die has a sibling, skip to the sibling. */ |
3810 | ||
3811 | pdi = pdi->die_sibling; | |
3812 | } | |
3813 | } | |
3814 | ||
3815 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3816 | |
72bf9492 | 3817 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3818 | name is concatenated with "::" and the partial DIE's name. For |
3819 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3820 | Enumerators are an exception; they use the scope of their parent |
3821 | enumeration type, i.e. the name of the enumeration type is not | |
3822 | prepended to the enumerator. | |
91c24f0a | 3823 | |
72bf9492 DJ |
3824 | There are two complexities. One is DW_AT_specification; in this |
3825 | case "parent" means the parent of the target of the specification, | |
3826 | instead of the direct parent of the DIE. The other is compilers | |
3827 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3828 | the fully qualified name of structure types from their members' | |
3829 | linkage names. This must be done using the DIE's children rather | |
3830 | than the children of any DW_AT_specification target. We only need | |
3831 | to do this for structures at the top level, i.e. if the target of | |
3832 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3833 | have a parent. */ | |
3834 | ||
3835 | /* Compute the scope prefix associated with PDI's parent, in | |
3836 | compilation unit CU. The result will be allocated on CU's | |
3837 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3838 | field. NULL is returned if no prefix is necessary. */ | |
3839 | static char * | |
3840 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3841 | struct dwarf2_cu *cu) | |
3842 | { | |
3843 | char *grandparent_scope; | |
3844 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3845 | |
72bf9492 DJ |
3846 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3847 | then this means the parent of the specification DIE. */ | |
3848 | ||
3849 | real_pdi = pdi; | |
72bf9492 | 3850 | while (real_pdi->has_specification) |
10b3939b | 3851 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3852 | |
3853 | parent = real_pdi->die_parent; | |
3854 | if (parent == NULL) | |
3855 | return NULL; | |
3856 | ||
3857 | if (parent->scope_set) | |
3858 | return parent->scope; | |
3859 | ||
3860 | fixup_partial_die (parent, cu); | |
3861 | ||
10b3939b | 3862 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3863 | |
acebe513 UW |
3864 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3865 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3866 | Work around this problem here. */ | |
3867 | if (cu->language == language_cplus | |
6e70227d | 3868 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3869 | && strcmp (parent->name, "::") == 0 |
3870 | && grandparent_scope == NULL) | |
3871 | { | |
3872 | parent->scope = NULL; | |
3873 | parent->scope_set = 1; | |
3874 | return NULL; | |
3875 | } | |
3876 | ||
9c6c53f7 SA |
3877 | if (pdi->tag == DW_TAG_enumerator) |
3878 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
3879 | parent->scope = grandparent_scope; | |
3880 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 3881 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3882 | || parent->tag == DW_TAG_structure_type |
3883 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3884 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3885 | || parent->tag == DW_TAG_union_type |
3886 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3887 | { |
3888 | if (grandparent_scope == NULL) | |
3889 | parent->scope = parent->name; | |
3890 | else | |
3e43a32a MS |
3891 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
3892 | grandparent_scope, | |
f55ee35c | 3893 | parent->name, 0, cu); |
72bf9492 | 3894 | } |
72bf9492 DJ |
3895 | else |
3896 | { | |
3897 | /* FIXME drow/2004-04-01: What should we be doing with | |
3898 | function-local names? For partial symbols, we should probably be | |
3899 | ignoring them. */ | |
3900 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3901 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3902 | parent->tag, pdi->offset); |
3903 | parent->scope = grandparent_scope; | |
c906108c SS |
3904 | } |
3905 | ||
72bf9492 DJ |
3906 | parent->scope_set = 1; |
3907 | return parent->scope; | |
3908 | } | |
3909 | ||
3910 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3911 | CU. The result will be allocated with malloc. */ | |
3912 | static char * | |
3913 | partial_die_full_name (struct partial_die_info *pdi, | |
3914 | struct dwarf2_cu *cu) | |
3915 | { | |
3916 | char *parent_scope; | |
3917 | ||
98bfdba5 PA |
3918 | /* If this is a template instantiation, we can not work out the |
3919 | template arguments from partial DIEs. So, unfortunately, we have | |
3920 | to go through the full DIEs. At least any work we do building | |
3921 | types here will be reused if full symbols are loaded later. */ | |
3922 | if (pdi->has_template_arguments) | |
3923 | { | |
3924 | fixup_partial_die (pdi, cu); | |
3925 | ||
3926 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3927 | { | |
3928 | struct die_info *die; | |
3929 | struct attribute attr; | |
3930 | struct dwarf2_cu *ref_cu = cu; | |
3931 | ||
3932 | attr.name = 0; | |
3933 | attr.form = DW_FORM_ref_addr; | |
3934 | attr.u.addr = pdi->offset; | |
3935 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3936 | ||
3937 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3938 | } | |
3939 | } | |
3940 | ||
72bf9492 DJ |
3941 | parent_scope = partial_die_parent_scope (pdi, cu); |
3942 | if (parent_scope == NULL) | |
3943 | return NULL; | |
3944 | else | |
f55ee35c | 3945 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3946 | } |
3947 | ||
3948 | static void | |
72bf9492 | 3949 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3950 | { |
e7c27a73 | 3951 | struct objfile *objfile = cu->objfile; |
c906108c | 3952 | CORE_ADDR addr = 0; |
decbce07 | 3953 | char *actual_name = NULL; |
5c4e30ca | 3954 | const struct partial_symbol *psym = NULL; |
e142c38c | 3955 | CORE_ADDR baseaddr; |
72bf9492 | 3956 | int built_actual_name = 0; |
e142c38c DJ |
3957 | |
3958 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3959 | |
94af9270 KS |
3960 | actual_name = partial_die_full_name (pdi, cu); |
3961 | if (actual_name) | |
3962 | built_actual_name = 1; | |
63d06c5c | 3963 | |
72bf9492 DJ |
3964 | if (actual_name == NULL) |
3965 | actual_name = pdi->name; | |
3966 | ||
c906108c SS |
3967 | switch (pdi->tag) |
3968 | { | |
3969 | case DW_TAG_subprogram: | |
2cfa0c8d | 3970 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3971 | { |
2cfa0c8d JB |
3972 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3973 | of the global scope. But in Ada, we want to be able to access | |
3974 | nested procedures globally. So all Ada subprograms are stored | |
3975 | in the global scope. */ | |
f47fb265 | 3976 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3977 | mst_text, objfile); */ |
f47fb265 MS |
3978 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3979 | built_actual_name, | |
3980 | VAR_DOMAIN, LOC_BLOCK, | |
3981 | &objfile->global_psymbols, | |
3982 | 0, pdi->lowpc + baseaddr, | |
3983 | cu->language, objfile); | |
c906108c SS |
3984 | } |
3985 | else | |
3986 | { | |
f47fb265 | 3987 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3988 | mst_file_text, objfile); */ |
f47fb265 MS |
3989 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3990 | built_actual_name, | |
3991 | VAR_DOMAIN, LOC_BLOCK, | |
3992 | &objfile->static_psymbols, | |
3993 | 0, pdi->lowpc + baseaddr, | |
3994 | cu->language, objfile); | |
c906108c SS |
3995 | } |
3996 | break; | |
72929c62 JB |
3997 | case DW_TAG_constant: |
3998 | { | |
3999 | struct psymbol_allocation_list *list; | |
4000 | ||
4001 | if (pdi->is_external) | |
4002 | list = &objfile->global_psymbols; | |
4003 | else | |
4004 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4005 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4006 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4007 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4008 | } |
4009 | break; | |
c906108c | 4010 | case DW_TAG_variable: |
caac4577 JG |
4011 | if (pdi->locdesc) |
4012 | addr = decode_locdesc (pdi->locdesc, cu); | |
4013 | ||
4014 | if (pdi->locdesc | |
4015 | && addr == 0 | |
4016 | && !dwarf2_per_objfile->has_section_at_zero) | |
4017 | { | |
4018 | /* A global or static variable may also have been stripped | |
4019 | out by the linker if unused, in which case its address | |
4020 | will be nullified; do not add such variables into partial | |
4021 | symbol table then. */ | |
4022 | } | |
4023 | else if (pdi->is_external) | |
c906108c SS |
4024 | { |
4025 | /* Global Variable. | |
4026 | Don't enter into the minimal symbol tables as there is | |
4027 | a minimal symbol table entry from the ELF symbols already. | |
4028 | Enter into partial symbol table if it has a location | |
4029 | descriptor or a type. | |
4030 | If the location descriptor is missing, new_symbol will create | |
4031 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4032 | be determined from the minimal symbol table whenever the variable | |
4033 | is referenced. | |
4034 | The address for the partial symbol table entry is not | |
4035 | used by GDB, but it comes in handy for debugging partial symbol | |
4036 | table building. */ | |
4037 | ||
c906108c | 4038 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
4039 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4040 | built_actual_name, | |
4041 | VAR_DOMAIN, LOC_STATIC, | |
4042 | &objfile->global_psymbols, | |
4043 | 0, addr + baseaddr, | |
4044 | cu->language, objfile); | |
c906108c SS |
4045 | } |
4046 | else | |
4047 | { | |
0963b4bd | 4048 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 4049 | if (pdi->locdesc == NULL) |
decbce07 MS |
4050 | { |
4051 | if (built_actual_name) | |
4052 | xfree (actual_name); | |
4053 | return; | |
4054 | } | |
f47fb265 | 4055 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4056 | mst_file_data, objfile); */ |
f47fb265 MS |
4057 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4058 | built_actual_name, | |
4059 | VAR_DOMAIN, LOC_STATIC, | |
4060 | &objfile->static_psymbols, | |
4061 | 0, addr + baseaddr, | |
4062 | cu->language, objfile); | |
c906108c SS |
4063 | } |
4064 | break; | |
4065 | case DW_TAG_typedef: | |
4066 | case DW_TAG_base_type: | |
a02abb62 | 4067 | case DW_TAG_subrange_type: |
38d518c9 | 4068 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4069 | built_actual_name, |
176620f1 | 4070 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4071 | &objfile->static_psymbols, |
e142c38c | 4072 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4073 | break; |
72bf9492 DJ |
4074 | case DW_TAG_namespace: |
4075 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4076 | built_actual_name, |
72bf9492 DJ |
4077 | VAR_DOMAIN, LOC_TYPEDEF, |
4078 | &objfile->global_psymbols, | |
4079 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4080 | break; | |
c906108c | 4081 | case DW_TAG_class_type: |
680b30c7 | 4082 | case DW_TAG_interface_type: |
c906108c SS |
4083 | case DW_TAG_structure_type: |
4084 | case DW_TAG_union_type: | |
4085 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4086 | /* Skip external references. The DWARF standard says in the section |
4087 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4088 | structure, union or class type is represented by a structure, | |
4089 | union or class entry that does not have a byte size attribute | |
4090 | and that has a DW_AT_declaration attribute." */ | |
4091 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4092 | { |
4093 | if (built_actual_name) | |
4094 | xfree (actual_name); | |
4095 | return; | |
4096 | } | |
fa4028e9 | 4097 | |
63d06c5c DC |
4098 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4099 | static vs. global. */ | |
38d518c9 | 4100 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4101 | built_actual_name, |
176620f1 | 4102 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4103 | (cu->language == language_cplus |
4104 | || cu->language == language_java) | |
63d06c5c DC |
4105 | ? &objfile->global_psymbols |
4106 | : &objfile->static_psymbols, | |
e142c38c | 4107 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4108 | |
c906108c SS |
4109 | break; |
4110 | case DW_TAG_enumerator: | |
38d518c9 | 4111 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4112 | built_actual_name, |
176620f1 | 4113 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4114 | (cu->language == language_cplus |
4115 | || cu->language == language_java) | |
f6fe98ef DJ |
4116 | ? &objfile->global_psymbols |
4117 | : &objfile->static_psymbols, | |
e142c38c | 4118 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4119 | break; |
4120 | default: | |
4121 | break; | |
4122 | } | |
5c4e30ca | 4123 | |
72bf9492 DJ |
4124 | if (built_actual_name) |
4125 | xfree (actual_name); | |
c906108c SS |
4126 | } |
4127 | ||
5c4e30ca DC |
4128 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4129 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4130 | the name of the enclosing namespace. */ | |
91c24f0a | 4131 | |
72bf9492 DJ |
4132 | static void |
4133 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4134 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4135 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4136 | { |
72bf9492 | 4137 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4138 | |
72bf9492 | 4139 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4140 | |
4141 | /* Now scan partial symbols in that namespace. */ | |
4142 | ||
91c24f0a | 4143 | if (pdi->has_children) |
5734ee8b | 4144 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4145 | } |
4146 | ||
5d7cb8df JK |
4147 | /* Read a partial die corresponding to a Fortran module. */ |
4148 | ||
4149 | static void | |
4150 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4151 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4152 | { | |
f55ee35c | 4153 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4154 | |
4155 | if (pdi->has_children) | |
4156 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4157 | } | |
4158 | ||
bc30ff58 JB |
4159 | /* Read a partial die corresponding to a subprogram and create a partial |
4160 | symbol for that subprogram. When the CU language allows it, this | |
4161 | routine also defines a partial symbol for each nested subprogram | |
4162 | that this subprogram contains. | |
6e70227d | 4163 | |
bc30ff58 JB |
4164 | DIE my also be a lexical block, in which case we simply search |
4165 | recursively for suprograms defined inside that lexical block. | |
4166 | Again, this is only performed when the CU language allows this | |
4167 | type of definitions. */ | |
4168 | ||
4169 | static void | |
4170 | add_partial_subprogram (struct partial_die_info *pdi, | |
4171 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4172 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4173 | { |
4174 | if (pdi->tag == DW_TAG_subprogram) | |
4175 | { | |
4176 | if (pdi->has_pc_info) | |
4177 | { | |
4178 | if (pdi->lowpc < *lowpc) | |
4179 | *lowpc = pdi->lowpc; | |
4180 | if (pdi->highpc > *highpc) | |
4181 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4182 | if (need_pc) |
4183 | { | |
4184 | CORE_ADDR baseaddr; | |
4185 | struct objfile *objfile = cu->objfile; | |
4186 | ||
4187 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4188 | SECT_OFF_TEXT (objfile)); | |
4189 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4190 | pdi->lowpc + baseaddr, |
4191 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4192 | cu->per_cu->v.psymtab); |
5734ee8b | 4193 | } |
bc30ff58 | 4194 | if (!pdi->is_declaration) |
e8d05480 JB |
4195 | /* Ignore subprogram DIEs that do not have a name, they are |
4196 | illegal. Do not emit a complaint at this point, we will | |
4197 | do so when we convert this psymtab into a symtab. */ | |
4198 | if (pdi->name) | |
4199 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4200 | } |
4201 | } | |
6e70227d | 4202 | |
bc30ff58 JB |
4203 | if (! pdi->has_children) |
4204 | return; | |
4205 | ||
4206 | if (cu->language == language_ada) | |
4207 | { | |
4208 | pdi = pdi->die_child; | |
4209 | while (pdi != NULL) | |
4210 | { | |
4211 | fixup_partial_die (pdi, cu); | |
4212 | if (pdi->tag == DW_TAG_subprogram | |
4213 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4214 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4215 | pdi = pdi->die_sibling; |
4216 | } | |
4217 | } | |
4218 | } | |
4219 | ||
91c24f0a DC |
4220 | /* Read a partial die corresponding to an enumeration type. */ |
4221 | ||
72bf9492 DJ |
4222 | static void |
4223 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4224 | struct dwarf2_cu *cu) | |
91c24f0a | 4225 | { |
72bf9492 | 4226 | struct partial_die_info *pdi; |
91c24f0a DC |
4227 | |
4228 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4229 | add_partial_symbol (enum_pdi, cu); |
4230 | ||
4231 | pdi = enum_pdi->die_child; | |
4232 | while (pdi) | |
91c24f0a | 4233 | { |
72bf9492 | 4234 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4235 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4236 | else |
72bf9492 DJ |
4237 | add_partial_symbol (pdi, cu); |
4238 | pdi = pdi->die_sibling; | |
91c24f0a | 4239 | } |
91c24f0a DC |
4240 | } |
4241 | ||
6caca83c CC |
4242 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
4243 | ||
4244 | static unsigned int | |
4245 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
4246 | { | |
4247 | unsigned int bytes_read; | |
4248 | ||
4249 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4250 | } | |
4251 | ||
4bb7a0a7 DJ |
4252 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4253 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4254 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4255 | the initial number. */ | |
4256 | ||
4257 | static struct abbrev_info * | |
fe1b8b76 | 4258 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4259 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4260 | { |
4261 | bfd *abfd = cu->objfile->obfd; | |
4262 | unsigned int abbrev_number; | |
4263 | struct abbrev_info *abbrev; | |
4264 | ||
4265 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4266 | ||
4267 | if (abbrev_number == 0) | |
4268 | return NULL; | |
4269 | ||
4270 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4271 | if (!abbrev) | |
4272 | { | |
3e43a32a MS |
4273 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4274 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4275 | } |
4276 | ||
4277 | return abbrev; | |
4278 | } | |
4279 | ||
93311388 DE |
4280 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4281 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4282 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4283 | ||
fe1b8b76 | 4284 | static gdb_byte * |
93311388 | 4285 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4286 | { |
4287 | struct abbrev_info *abbrev; | |
4288 | unsigned int bytes_read; | |
4289 | ||
4290 | while (1) | |
4291 | { | |
4292 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4293 | if (abbrev == NULL) | |
4294 | return info_ptr + bytes_read; | |
4295 | else | |
93311388 | 4296 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4297 | } |
4298 | } | |
4299 | ||
93311388 DE |
4300 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4301 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4302 | abbrev corresponding to that skipped uleb128 should be passed in |
4303 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4304 | children. */ | |
4305 | ||
fe1b8b76 | 4306 | static gdb_byte * |
93311388 DE |
4307 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4308 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4309 | { |
4310 | unsigned int bytes_read; | |
4311 | struct attribute attr; | |
4312 | bfd *abfd = cu->objfile->obfd; | |
4313 | unsigned int form, i; | |
4314 | ||
4315 | for (i = 0; i < abbrev->num_attrs; i++) | |
4316 | { | |
4317 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4318 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4319 | { | |
4320 | read_attribute (&attr, &abbrev->attrs[i], | |
4321 | abfd, info_ptr, cu); | |
4322 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
4323 | complaint (&symfile_complaints, |
4324 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4325 | else |
93311388 | 4326 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4327 | } |
4328 | ||
4329 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4330 | form = abbrev->attrs[i].form; | |
4331 | skip_attribute: | |
4332 | switch (form) | |
4333 | { | |
4bb7a0a7 | 4334 | case DW_FORM_ref_addr: |
ae411497 TT |
4335 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4336 | and later it is offset sized. */ | |
4337 | if (cu->header.version == 2) | |
4338 | info_ptr += cu->header.addr_size; | |
4339 | else | |
4340 | info_ptr += cu->header.offset_size; | |
4341 | break; | |
4342 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4343 | info_ptr += cu->header.addr_size; |
4344 | break; | |
4345 | case DW_FORM_data1: | |
4346 | case DW_FORM_ref1: | |
4347 | case DW_FORM_flag: | |
4348 | info_ptr += 1; | |
4349 | break; | |
2dc7f7b3 TT |
4350 | case DW_FORM_flag_present: |
4351 | break; | |
4bb7a0a7 DJ |
4352 | case DW_FORM_data2: |
4353 | case DW_FORM_ref2: | |
4354 | info_ptr += 2; | |
4355 | break; | |
4356 | case DW_FORM_data4: | |
4357 | case DW_FORM_ref4: | |
4358 | info_ptr += 4; | |
4359 | break; | |
4360 | case DW_FORM_data8: | |
4361 | case DW_FORM_ref8: | |
55f1336d | 4362 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4363 | info_ptr += 8; |
4364 | break; | |
4365 | case DW_FORM_string: | |
9b1c24c8 | 4366 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4367 | info_ptr += bytes_read; |
4368 | break; | |
2dc7f7b3 | 4369 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4370 | case DW_FORM_strp: |
4371 | info_ptr += cu->header.offset_size; | |
4372 | break; | |
2dc7f7b3 | 4373 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4374 | case DW_FORM_block: |
4375 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4376 | info_ptr += bytes_read; | |
4377 | break; | |
4378 | case DW_FORM_block1: | |
4379 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4380 | break; | |
4381 | case DW_FORM_block2: | |
4382 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4383 | break; | |
4384 | case DW_FORM_block4: | |
4385 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4386 | break; | |
4387 | case DW_FORM_sdata: | |
4388 | case DW_FORM_udata: | |
4389 | case DW_FORM_ref_udata: | |
4390 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4391 | break; | |
4392 | case DW_FORM_indirect: | |
4393 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4394 | info_ptr += bytes_read; | |
4395 | /* We need to continue parsing from here, so just go back to | |
4396 | the top. */ | |
4397 | goto skip_attribute; | |
4398 | ||
4399 | default: | |
3e43a32a MS |
4400 | error (_("Dwarf Error: Cannot handle %s " |
4401 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4402 | dwarf_form_name (form), |
4403 | bfd_get_filename (abfd)); | |
4404 | } | |
4405 | } | |
4406 | ||
4407 | if (abbrev->has_children) | |
93311388 | 4408 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4409 | else |
4410 | return info_ptr; | |
4411 | } | |
4412 | ||
93311388 DE |
4413 | /* Locate ORIG_PDI's sibling. |
4414 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4415 | in BUFFER. */ | |
91c24f0a | 4416 | |
fe1b8b76 | 4417 | static gdb_byte * |
93311388 DE |
4418 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4419 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4420 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4421 | { |
4422 | /* Do we know the sibling already? */ | |
72bf9492 | 4423 | |
91c24f0a DC |
4424 | if (orig_pdi->sibling) |
4425 | return orig_pdi->sibling; | |
4426 | ||
4427 | /* Are there any children to deal with? */ | |
4428 | ||
4429 | if (!orig_pdi->has_children) | |
4430 | return info_ptr; | |
4431 | ||
4bb7a0a7 | 4432 | /* Skip the children the long way. */ |
91c24f0a | 4433 | |
93311388 | 4434 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4435 | } |
4436 | ||
c906108c SS |
4437 | /* Expand this partial symbol table into a full symbol table. */ |
4438 | ||
4439 | static void | |
fba45db2 | 4440 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4441 | { |
c906108c SS |
4442 | if (pst != NULL) |
4443 | { | |
4444 | if (pst->readin) | |
4445 | { | |
3e43a32a MS |
4446 | warning (_("bug: psymtab for %s is already read in."), |
4447 | pst->filename); | |
c906108c SS |
4448 | } |
4449 | else | |
4450 | { | |
4451 | if (info_verbose) | |
4452 | { | |
3e43a32a MS |
4453 | printf_filtered (_("Reading in symbols for %s..."), |
4454 | pst->filename); | |
c906108c SS |
4455 | gdb_flush (gdb_stdout); |
4456 | } | |
4457 | ||
10b3939b DJ |
4458 | /* Restore our global data. */ |
4459 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4460 | dwarf2_objfile_data_key); | |
4461 | ||
b2ab525c KB |
4462 | /* If this psymtab is constructed from a debug-only objfile, the |
4463 | has_section_at_zero flag will not necessarily be correct. We | |
4464 | can get the correct value for this flag by looking at the data | |
4465 | associated with the (presumably stripped) associated objfile. */ | |
4466 | if (pst->objfile->separate_debug_objfile_backlink) | |
4467 | { | |
4468 | struct dwarf2_per_objfile *dpo_backlink | |
4469 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4470 | dwarf2_objfile_data_key); | |
9a619af0 | 4471 | |
b2ab525c KB |
4472 | dwarf2_per_objfile->has_section_at_zero |
4473 | = dpo_backlink->has_section_at_zero; | |
4474 | } | |
4475 | ||
98bfdba5 PA |
4476 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4477 | ||
c906108c SS |
4478 | psymtab_to_symtab_1 (pst); |
4479 | ||
4480 | /* Finish up the debug error message. */ | |
4481 | if (info_verbose) | |
a3f17187 | 4482 | printf_filtered (_("done.\n")); |
c906108c SS |
4483 | } |
4484 | } | |
4485 | } | |
9cdd5dbd DE |
4486 | \f |
4487 | /* Reading in full CUs. */ | |
c906108c | 4488 | |
10b3939b DJ |
4489 | /* Add PER_CU to the queue. */ |
4490 | ||
4491 | static void | |
a0f42c21 | 4492 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b DJ |
4493 | { |
4494 | struct dwarf2_queue_item *item; | |
4495 | ||
4496 | per_cu->queued = 1; | |
4497 | item = xmalloc (sizeof (*item)); | |
4498 | item->per_cu = per_cu; | |
4499 | item->next = NULL; | |
4500 | ||
4501 | if (dwarf2_queue == NULL) | |
4502 | dwarf2_queue = item; | |
4503 | else | |
4504 | dwarf2_queue_tail->next = item; | |
4505 | ||
4506 | dwarf2_queue_tail = item; | |
4507 | } | |
4508 | ||
4509 | /* Process the queue. */ | |
4510 | ||
4511 | static void | |
a0f42c21 | 4512 | process_queue (void) |
10b3939b DJ |
4513 | { |
4514 | struct dwarf2_queue_item *item, *next_item; | |
4515 | ||
03dd20cc DJ |
4516 | /* The queue starts out with one item, but following a DIE reference |
4517 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4518 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4519 | { | |
9291a0cd TT |
4520 | if (dwarf2_per_objfile->using_index |
4521 | ? !item->per_cu->v.quick->symtab | |
4522 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4523 | process_full_comp_unit (item->per_cu); |
4524 | ||
4525 | item->per_cu->queued = 0; | |
4526 | next_item = item->next; | |
4527 | xfree (item); | |
4528 | } | |
4529 | ||
4530 | dwarf2_queue_tail = NULL; | |
4531 | } | |
4532 | ||
4533 | /* Free all allocated queue entries. This function only releases anything if | |
4534 | an error was thrown; if the queue was processed then it would have been | |
4535 | freed as we went along. */ | |
4536 | ||
4537 | static void | |
4538 | dwarf2_release_queue (void *dummy) | |
4539 | { | |
4540 | struct dwarf2_queue_item *item, *last; | |
4541 | ||
4542 | item = dwarf2_queue; | |
4543 | while (item) | |
4544 | { | |
4545 | /* Anything still marked queued is likely to be in an | |
4546 | inconsistent state, so discard it. */ | |
4547 | if (item->per_cu->queued) | |
4548 | { | |
4549 | if (item->per_cu->cu != NULL) | |
4550 | free_one_cached_comp_unit (item->per_cu->cu); | |
4551 | item->per_cu->queued = 0; | |
4552 | } | |
4553 | ||
4554 | last = item; | |
4555 | item = item->next; | |
4556 | xfree (last); | |
4557 | } | |
4558 | ||
4559 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4560 | } | |
4561 | ||
4562 | /* Read in full symbols for PST, and anything it depends on. */ | |
4563 | ||
c906108c | 4564 | static void |
fba45db2 | 4565 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4566 | { |
10b3939b | 4567 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4568 | struct cleanup *back_to; |
aaa75496 JB |
4569 | int i; |
4570 | ||
4571 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4572 | if (!pst->dependencies[i]->readin) | |
4573 | { | |
4574 | /* Inform about additional files that need to be read in. */ | |
4575 | if (info_verbose) | |
4576 | { | |
a3f17187 | 4577 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4578 | fputs_filtered (" ", gdb_stdout); |
4579 | wrap_here (""); | |
4580 | fputs_filtered ("and ", gdb_stdout); | |
4581 | wrap_here (""); | |
4582 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4583 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4584 | gdb_flush (gdb_stdout); |
4585 | } | |
4586 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4587 | } | |
4588 | ||
e38df1d0 | 4589 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4590 | |
4591 | if (per_cu == NULL) | |
aaa75496 JB |
4592 | { |
4593 | /* It's an include file, no symbols to read for it. | |
4594 | Everything is in the parent symtab. */ | |
4595 | pst->readin = 1; | |
4596 | return; | |
4597 | } | |
c906108c | 4598 | |
a0f42c21 | 4599 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
4600 | } |
4601 | ||
93311388 | 4602 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4603 | |
93311388 | 4604 | static void |
a0f42c21 | 4605 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b | 4606 | { |
a0f42c21 | 4607 | struct objfile *objfile = per_cu->objfile; |
31ffec48 | 4608 | bfd *abfd = objfile->obfd; |
10b3939b | 4609 | struct dwarf2_cu *cu; |
c764a876 | 4610 | unsigned int offset; |
93311388 | 4611 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4612 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4613 | struct attribute *attr; |
98bfdba5 | 4614 | int read_cu = 0; |
6502dd73 | 4615 | |
b0df02fd | 4616 | gdb_assert (! per_cu->debug_types_section); |
348e048f | 4617 | |
c906108c | 4618 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4619 | offset = per_cu->offset; |
6502dd73 | 4620 | |
be391dca | 4621 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4622 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4623 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4624 | |
98bfdba5 PA |
4625 | if (per_cu->cu == NULL) |
4626 | { | |
9816fde3 | 4627 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 4628 | init_one_comp_unit (cu, per_cu); |
98bfdba5 PA |
4629 | |
4630 | read_cu = 1; | |
c906108c | 4631 | |
98bfdba5 | 4632 | /* If an error occurs while loading, release our storage. */ |
68dc6402 | 4633 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
c906108c | 4634 | |
98bfdba5 PA |
4635 | /* Read in the comp_unit header. */ |
4636 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4637 | |
6caca83c CC |
4638 | /* Skip dummy compilation units. */ |
4639 | if (info_ptr >= (dwarf2_per_objfile->info.buffer | |
4640 | + dwarf2_per_objfile->info.size) | |
4641 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
4642 | { | |
4643 | do_cleanups (free_cu_cleanup); | |
4644 | return; | |
4645 | } | |
4646 | ||
98bfdba5 PA |
4647 | /* Complete the cu_header. */ |
4648 | cu->header.offset = offset; | |
4649 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4650 | |
98bfdba5 | 4651 | /* Read the abbrevs for this compilation unit. */ |
e5fe5e75 | 4652 | dwarf2_read_abbrevs (cu); |
98bfdba5 | 4653 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
10b3939b | 4654 | |
98bfdba5 PA |
4655 | /* Link this CU into read_in_chain. */ |
4656 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4657 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4658 | } | |
4659 | else | |
4660 | { | |
4661 | cu = per_cu->cu; | |
4662 | info_ptr += cu->header.first_die_offset; | |
4663 | } | |
e142c38c | 4664 | |
93311388 | 4665 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4666 | |
4667 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 4668 | all CUs needed for references have been loaded yet, and symbol |
10b3939b DJ |
4669 | table processing isn't initialized. But we have to set the CU language, |
4670 | or we won't be able to build types correctly. */ | |
9816fde3 | 4671 | prepare_one_comp_unit (cu, cu->dies); |
10b3939b | 4672 | |
a6c727b2 DJ |
4673 | /* Similarly, if we do not read the producer, we can not apply |
4674 | producer-specific interpretation. */ | |
4675 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4676 | if (attr) | |
4677 | cu->producer = DW_STRING (attr); | |
4678 | ||
98bfdba5 PA |
4679 | if (read_cu) |
4680 | { | |
4681 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4682 | |
98bfdba5 PA |
4683 | /* We've successfully allocated this compilation unit. Let our |
4684 | caller clean it up when finished with it. */ | |
4685 | discard_cleanups (free_cu_cleanup); | |
4686 | } | |
10b3939b DJ |
4687 | } |
4688 | ||
3da10d80 KS |
4689 | /* Add a DIE to the delayed physname list. */ |
4690 | ||
4691 | static void | |
4692 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4693 | const char *name, struct die_info *die, | |
4694 | struct dwarf2_cu *cu) | |
4695 | { | |
4696 | struct delayed_method_info mi; | |
4697 | mi.type = type; | |
4698 | mi.fnfield_index = fnfield_index; | |
4699 | mi.index = index; | |
4700 | mi.name = name; | |
4701 | mi.die = die; | |
4702 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4703 | } | |
4704 | ||
4705 | /* A cleanup for freeing the delayed method list. */ | |
4706 | ||
4707 | static void | |
4708 | free_delayed_list (void *ptr) | |
4709 | { | |
4710 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4711 | if (cu->method_list != NULL) | |
4712 | { | |
4713 | VEC_free (delayed_method_info, cu->method_list); | |
4714 | cu->method_list = NULL; | |
4715 | } | |
4716 | } | |
4717 | ||
4718 | /* Compute the physnames of any methods on the CU's method list. | |
4719 | ||
4720 | The computation of method physnames is delayed in order to avoid the | |
4721 | (bad) condition that one of the method's formal parameters is of an as yet | |
4722 | incomplete type. */ | |
4723 | ||
4724 | static void | |
4725 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4726 | { | |
4727 | int i; | |
4728 | struct delayed_method_info *mi; | |
4729 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4730 | { | |
1d06ead6 | 4731 | const char *physname; |
3da10d80 KS |
4732 | struct fn_fieldlist *fn_flp |
4733 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 4734 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
4735 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
4736 | } | |
4737 | } | |
4738 | ||
9cdd5dbd | 4739 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
4740 | already been loaded into memory. */ |
4741 | ||
4742 | static void | |
4743 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4744 | { | |
10b3939b | 4745 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4746 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4747 | CORE_ADDR lowpc, highpc; |
4748 | struct symtab *symtab; | |
3da10d80 | 4749 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4750 | CORE_ADDR baseaddr; |
4751 | ||
4752 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4753 | ||
10b3939b DJ |
4754 | buildsym_init (); |
4755 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4756 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4757 | |
4758 | cu->list_in_scope = &file_symbols; | |
c906108c SS |
4759 | |
4760 | /* Do line number decoding in read_file_scope () */ | |
10b3939b | 4761 | process_die (cu->dies, cu); |
c906108c | 4762 | |
3da10d80 KS |
4763 | /* Now that we have processed all the DIEs in the CU, all the types |
4764 | should be complete, and it should now be safe to compute all of the | |
4765 | physnames. */ | |
4766 | compute_delayed_physnames (cu); | |
4767 | do_cleanups (delayed_list_cleanup); | |
4768 | ||
fae299cd DC |
4769 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4770 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4771 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4772 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4773 | |
613e1657 | 4774 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 4775 | |
8be455d7 | 4776 | if (symtab != NULL) |
c906108c | 4777 | { |
df15bd07 | 4778 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 4779 | |
8be455d7 JK |
4780 | /* Set symtab language to language from DW_AT_language. If the |
4781 | compilation is from a C file generated by language preprocessors, do | |
4782 | not set the language if it was already deduced by start_subfile. */ | |
4783 | if (!(cu->language == language_c && symtab->language != language_c)) | |
4784 | symtab->language = cu->language; | |
4785 | ||
4786 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
4787 | produce DW_AT_location with location lists but it can be possibly | |
4788 | invalid without -fvar-tracking. | |
4789 | ||
4790 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
4791 | needed, it would be wrong due to missing DW_AT_producer there. | |
4792 | ||
4793 | Still one can confuse GDB by using non-standard GCC compilation | |
4794 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
4795 | */ | |
4632c0d0 | 4796 | if (cu->has_loclist && gcc_4_minor >= 0) |
8be455d7 | 4797 | symtab->locations_valid = 1; |
e0d00bc7 JK |
4798 | |
4799 | if (gcc_4_minor >= 5) | |
4800 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
4801 | |
4802 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 4803 | } |
9291a0cd TT |
4804 | |
4805 | if (dwarf2_per_objfile->using_index) | |
4806 | per_cu->v.quick->symtab = symtab; | |
4807 | else | |
4808 | { | |
4809 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4810 | pst->symtab = symtab; | |
4811 | pst->readin = 1; | |
4812 | } | |
c906108c SS |
4813 | |
4814 | do_cleanups (back_to); | |
4815 | } | |
4816 | ||
4817 | /* Process a die and its children. */ | |
4818 | ||
4819 | static void | |
e7c27a73 | 4820 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4821 | { |
4822 | switch (die->tag) | |
4823 | { | |
4824 | case DW_TAG_padding: | |
4825 | break; | |
4826 | case DW_TAG_compile_unit: | |
e7c27a73 | 4827 | read_file_scope (die, cu); |
c906108c | 4828 | break; |
348e048f DE |
4829 | case DW_TAG_type_unit: |
4830 | read_type_unit_scope (die, cu); | |
4831 | break; | |
c906108c | 4832 | case DW_TAG_subprogram: |
c906108c | 4833 | case DW_TAG_inlined_subroutine: |
edb3359d | 4834 | read_func_scope (die, cu); |
c906108c SS |
4835 | break; |
4836 | case DW_TAG_lexical_block: | |
14898363 L |
4837 | case DW_TAG_try_block: |
4838 | case DW_TAG_catch_block: | |
e7c27a73 | 4839 | read_lexical_block_scope (die, cu); |
c906108c | 4840 | break; |
96408a79 SA |
4841 | case DW_TAG_GNU_call_site: |
4842 | read_call_site_scope (die, cu); | |
4843 | break; | |
c906108c | 4844 | case DW_TAG_class_type: |
680b30c7 | 4845 | case DW_TAG_interface_type: |
c906108c SS |
4846 | case DW_TAG_structure_type: |
4847 | case DW_TAG_union_type: | |
134d01f1 | 4848 | process_structure_scope (die, cu); |
c906108c SS |
4849 | break; |
4850 | case DW_TAG_enumeration_type: | |
134d01f1 | 4851 | process_enumeration_scope (die, cu); |
c906108c | 4852 | break; |
134d01f1 | 4853 | |
f792889a DJ |
4854 | /* These dies have a type, but processing them does not create |
4855 | a symbol or recurse to process the children. Therefore we can | |
4856 | read them on-demand through read_type_die. */ | |
c906108c | 4857 | case DW_TAG_subroutine_type: |
72019c9c | 4858 | case DW_TAG_set_type: |
c906108c | 4859 | case DW_TAG_array_type: |
c906108c | 4860 | case DW_TAG_pointer_type: |
c906108c | 4861 | case DW_TAG_ptr_to_member_type: |
c906108c | 4862 | case DW_TAG_reference_type: |
c906108c | 4863 | case DW_TAG_string_type: |
c906108c | 4864 | break; |
134d01f1 | 4865 | |
c906108c | 4866 | case DW_TAG_base_type: |
a02abb62 | 4867 | case DW_TAG_subrange_type: |
cb249c71 | 4868 | case DW_TAG_typedef: |
134d01f1 DJ |
4869 | /* Add a typedef symbol for the type definition, if it has a |
4870 | DW_AT_name. */ | |
f792889a | 4871 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4872 | break; |
c906108c | 4873 | case DW_TAG_common_block: |
e7c27a73 | 4874 | read_common_block (die, cu); |
c906108c SS |
4875 | break; |
4876 | case DW_TAG_common_inclusion: | |
4877 | break; | |
d9fa45fe | 4878 | case DW_TAG_namespace: |
63d06c5c | 4879 | processing_has_namespace_info = 1; |
e7c27a73 | 4880 | read_namespace (die, cu); |
d9fa45fe | 4881 | break; |
5d7cb8df | 4882 | case DW_TAG_module: |
f55ee35c | 4883 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4884 | read_module (die, cu); |
4885 | break; | |
d9fa45fe DC |
4886 | case DW_TAG_imported_declaration: |
4887 | case DW_TAG_imported_module: | |
63d06c5c | 4888 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4889 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4890 | || cu->language != language_fortran)) | |
4891 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4892 | dwarf_tag_name (die->tag)); | |
4893 | read_import_statement (die, cu); | |
d9fa45fe | 4894 | break; |
c906108c | 4895 | default: |
e7c27a73 | 4896 | new_symbol (die, NULL, cu); |
c906108c SS |
4897 | break; |
4898 | } | |
4899 | } | |
4900 | ||
94af9270 KS |
4901 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4902 | needs to have the name of the scope prepended to the name listed in the | |
4903 | die. */ | |
4904 | ||
4905 | static int | |
4906 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4907 | { | |
1c809c68 TT |
4908 | struct attribute *attr; |
4909 | ||
94af9270 KS |
4910 | switch (die->tag) |
4911 | { | |
4912 | case DW_TAG_namespace: | |
4913 | case DW_TAG_typedef: | |
4914 | case DW_TAG_class_type: | |
4915 | case DW_TAG_interface_type: | |
4916 | case DW_TAG_structure_type: | |
4917 | case DW_TAG_union_type: | |
4918 | case DW_TAG_enumeration_type: | |
4919 | case DW_TAG_enumerator: | |
4920 | case DW_TAG_subprogram: | |
4921 | case DW_TAG_member: | |
4922 | return 1; | |
4923 | ||
4924 | case DW_TAG_variable: | |
c2b0a229 | 4925 | case DW_TAG_constant: |
94af9270 KS |
4926 | /* We only need to prefix "globally" visible variables. These include |
4927 | any variable marked with DW_AT_external or any variable that | |
4928 | lives in a namespace. [Variables in anonymous namespaces | |
4929 | require prefixing, but they are not DW_AT_external.] */ | |
4930 | ||
4931 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4932 | { | |
4933 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4934 | |
94af9270 KS |
4935 | return die_needs_namespace (die_specification (die, &spec_cu), |
4936 | spec_cu); | |
4937 | } | |
4938 | ||
1c809c68 | 4939 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4940 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4941 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4942 | return 0; |
4943 | /* A variable in a lexical block of some kind does not need a | |
4944 | namespace, even though in C++ such variables may be external | |
4945 | and have a mangled name. */ | |
4946 | if (die->parent->tag == DW_TAG_lexical_block | |
4947 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4948 | || die->parent->tag == DW_TAG_catch_block |
4949 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4950 | return 0; |
4951 | return 1; | |
94af9270 KS |
4952 | |
4953 | default: | |
4954 | return 0; | |
4955 | } | |
4956 | } | |
4957 | ||
98bfdba5 PA |
4958 | /* Retrieve the last character from a mem_file. */ |
4959 | ||
4960 | static void | |
4961 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4962 | { | |
4963 | char *last_char_p = (char *) object; | |
4964 | ||
4965 | if (length > 0) | |
4966 | *last_char_p = buffer[length - 1]; | |
4967 | } | |
4968 | ||
94af9270 KS |
4969 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4970 | compute the physname for the object, which include a method's | |
4971 | formal parameters (C++/Java) and return type (Java). | |
4972 | ||
af6b7be1 JB |
4973 | For Ada, return the DIE's linkage name rather than the fully qualified |
4974 | name. PHYSNAME is ignored.. | |
4975 | ||
94af9270 KS |
4976 | The result is allocated on the objfile_obstack and canonicalized. */ |
4977 | ||
4978 | static const char * | |
4979 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4980 | int physname) | |
4981 | { | |
bb5ed363 DE |
4982 | struct objfile *objfile = cu->objfile; |
4983 | ||
94af9270 KS |
4984 | if (name == NULL) |
4985 | name = dwarf2_name (die, cu); | |
4986 | ||
f55ee35c JK |
4987 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4988 | compute it by typename_concat inside GDB. */ | |
4989 | if (cu->language == language_ada | |
4990 | || (cu->language == language_fortran && physname)) | |
4991 | { | |
4992 | /* For Ada unit, we prefer the linkage name over the name, as | |
4993 | the former contains the exported name, which the user expects | |
4994 | to be able to reference. Ideally, we want the user to be able | |
4995 | to reference this entity using either natural or linkage name, | |
4996 | but we haven't started looking at this enhancement yet. */ | |
4997 | struct attribute *attr; | |
4998 | ||
4999 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5000 | if (attr == NULL) | |
5001 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5002 | if (attr && DW_STRING (attr)) | |
5003 | return DW_STRING (attr); | |
5004 | } | |
5005 | ||
94af9270 KS |
5006 | /* These are the only languages we know how to qualify names in. */ |
5007 | if (name != NULL | |
f55ee35c JK |
5008 | && (cu->language == language_cplus || cu->language == language_java |
5009 | || cu->language == language_fortran)) | |
94af9270 KS |
5010 | { |
5011 | if (die_needs_namespace (die, cu)) | |
5012 | { | |
5013 | long length; | |
5014 | char *prefix; | |
5015 | struct ui_file *buf; | |
5016 | ||
5017 | prefix = determine_prefix (die, cu); | |
5018 | buf = mem_fileopen (); | |
5019 | if (*prefix != '\0') | |
5020 | { | |
f55ee35c JK |
5021 | char *prefixed_name = typename_concat (NULL, prefix, name, |
5022 | physname, cu); | |
9a619af0 | 5023 | |
94af9270 KS |
5024 | fputs_unfiltered (prefixed_name, buf); |
5025 | xfree (prefixed_name); | |
5026 | } | |
5027 | else | |
62d5b8da | 5028 | fputs_unfiltered (name, buf); |
94af9270 | 5029 | |
98bfdba5 PA |
5030 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
5031 | as children with DW_TAG_template_type_param or | |
5032 | DW_TAG_value_type_param. If the latter, add them to the name | |
5033 | here. If the name already has template parameters, then | |
5034 | skip this step; some versions of GCC emit both, and | |
5035 | it is more efficient to use the pre-computed name. | |
5036 | ||
5037 | Something to keep in mind about this process: it is very | |
5038 | unlikely, or in some cases downright impossible, to produce | |
5039 | something that will match the mangled name of a function. | |
5040 | If the definition of the function has the same debug info, | |
5041 | we should be able to match up with it anyway. But fallbacks | |
5042 | using the minimal symbol, for instance to find a method | |
5043 | implemented in a stripped copy of libstdc++, will not work. | |
5044 | If we do not have debug info for the definition, we will have to | |
5045 | match them up some other way. | |
5046 | ||
5047 | When we do name matching there is a related problem with function | |
5048 | templates; two instantiated function templates are allowed to | |
5049 | differ only by their return types, which we do not add here. */ | |
5050 | ||
5051 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
5052 | { | |
5053 | struct attribute *attr; | |
5054 | struct die_info *child; | |
5055 | int first = 1; | |
5056 | ||
5057 | die->building_fullname = 1; | |
5058 | ||
5059 | for (child = die->child; child != NULL; child = child->sibling) | |
5060 | { | |
5061 | struct type *type; | |
5062 | long value; | |
5063 | gdb_byte *bytes; | |
5064 | struct dwarf2_locexpr_baton *baton; | |
5065 | struct value *v; | |
5066 | ||
5067 | if (child->tag != DW_TAG_template_type_param | |
5068 | && child->tag != DW_TAG_template_value_param) | |
5069 | continue; | |
5070 | ||
5071 | if (first) | |
5072 | { | |
5073 | fputs_unfiltered ("<", buf); | |
5074 | first = 0; | |
5075 | } | |
5076 | else | |
5077 | fputs_unfiltered (", ", buf); | |
5078 | ||
5079 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5080 | if (attr == NULL) | |
5081 | { | |
5082 | complaint (&symfile_complaints, | |
5083 | _("template parameter missing DW_AT_type")); | |
5084 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5085 | continue; | |
5086 | } | |
5087 | type = die_type (child, cu); | |
5088 | ||
5089 | if (child->tag == DW_TAG_template_type_param) | |
5090 | { | |
5091 | c_print_type (type, "", buf, -1, 0); | |
5092 | continue; | |
5093 | } | |
5094 | ||
5095 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5096 | if (attr == NULL) | |
5097 | { | |
5098 | complaint (&symfile_complaints, | |
3e43a32a MS |
5099 | _("template parameter missing " |
5100 | "DW_AT_const_value")); | |
98bfdba5 PA |
5101 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5102 | continue; | |
5103 | } | |
5104 | ||
5105 | dwarf2_const_value_attr (attr, type, name, | |
5106 | &cu->comp_unit_obstack, cu, | |
5107 | &value, &bytes, &baton); | |
5108 | ||
5109 | if (TYPE_NOSIGN (type)) | |
5110 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5111 | changed, this can use value_print instead. */ | |
5112 | c_printchar (value, type, buf); | |
5113 | else | |
5114 | { | |
5115 | struct value_print_options opts; | |
5116 | ||
5117 | if (baton != NULL) | |
5118 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5119 | baton->data, | |
5120 | baton->size, | |
5121 | baton->per_cu); | |
5122 | else if (bytes != NULL) | |
5123 | { | |
5124 | v = allocate_value (type); | |
5125 | memcpy (value_contents_writeable (v), bytes, | |
5126 | TYPE_LENGTH (type)); | |
5127 | } | |
5128 | else | |
5129 | v = value_from_longest (type, value); | |
5130 | ||
3e43a32a MS |
5131 | /* Specify decimal so that we do not depend on |
5132 | the radix. */ | |
98bfdba5 PA |
5133 | get_formatted_print_options (&opts, 'd'); |
5134 | opts.raw = 1; | |
5135 | value_print (v, buf, &opts); | |
5136 | release_value (v); | |
5137 | value_free (v); | |
5138 | } | |
5139 | } | |
5140 | ||
5141 | die->building_fullname = 0; | |
5142 | ||
5143 | if (!first) | |
5144 | { | |
5145 | /* Close the argument list, with a space if necessary | |
5146 | (nested templates). */ | |
5147 | char last_char = '\0'; | |
5148 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5149 | if (last_char == '>') | |
5150 | fputs_unfiltered (" >", buf); | |
5151 | else | |
5152 | fputs_unfiltered (">", buf); | |
5153 | } | |
5154 | } | |
5155 | ||
94af9270 KS |
5156 | /* For Java and C++ methods, append formal parameter type |
5157 | information, if PHYSNAME. */ | |
6e70227d | 5158 | |
94af9270 KS |
5159 | if (physname && die->tag == DW_TAG_subprogram |
5160 | && (cu->language == language_cplus | |
5161 | || cu->language == language_java)) | |
5162 | { | |
5163 | struct type *type = read_type_die (die, cu); | |
5164 | ||
3167638f | 5165 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5166 | |
5167 | if (cu->language == language_java) | |
5168 | { | |
5169 | /* For java, we must append the return type to method | |
0963b4bd | 5170 | names. */ |
94af9270 KS |
5171 | if (die->tag == DW_TAG_subprogram) |
5172 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5173 | 0, 0); | |
5174 | } | |
5175 | else if (cu->language == language_cplus) | |
5176 | { | |
60430eff DJ |
5177 | /* Assume that an artificial first parameter is |
5178 | "this", but do not crash if it is not. RealView | |
5179 | marks unnamed (and thus unused) parameters as | |
5180 | artificial; there is no way to differentiate | |
5181 | the two cases. */ | |
94af9270 KS |
5182 | if (TYPE_NFIELDS (type) > 0 |
5183 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5184 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5185 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5186 | 0)))) | |
94af9270 KS |
5187 | fputs_unfiltered (" const", buf); |
5188 | } | |
5189 | } | |
5190 | ||
bb5ed363 | 5191 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
5192 | &length); |
5193 | ui_file_delete (buf); | |
5194 | ||
5195 | if (cu->language == language_cplus) | |
5196 | { | |
5197 | char *cname | |
5198 | = dwarf2_canonicalize_name (name, cu, | |
bb5ed363 | 5199 | &objfile->objfile_obstack); |
9a619af0 | 5200 | |
94af9270 KS |
5201 | if (cname != NULL) |
5202 | name = cname; | |
5203 | } | |
5204 | } | |
5205 | } | |
5206 | ||
5207 | return name; | |
5208 | } | |
5209 | ||
0114d602 DJ |
5210 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5211 | If scope qualifiers are appropriate they will be added. The result | |
5212 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5213 | not have a name. NAME may either be from a previous call to |
5214 | dwarf2_name or NULL. | |
5215 | ||
0963b4bd | 5216 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5217 | |
5218 | static const char * | |
94af9270 | 5219 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5220 | { |
94af9270 KS |
5221 | return dwarf2_compute_name (name, die, cu, 0); |
5222 | } | |
0114d602 | 5223 | |
94af9270 KS |
5224 | /* Construct a physname for the given DIE in CU. NAME may either be |
5225 | from a previous call to dwarf2_name or NULL. The result will be | |
5226 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5227 | name. | |
0114d602 | 5228 | |
94af9270 | 5229 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5230 | |
94af9270 KS |
5231 | static const char * |
5232 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5233 | { | |
bb5ed363 | 5234 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
5235 | struct attribute *attr; |
5236 | const char *retval, *mangled = NULL, *canon = NULL; | |
5237 | struct cleanup *back_to; | |
5238 | int need_copy = 1; | |
5239 | ||
5240 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
5241 | on its own. */ | |
5242 | if (!die_needs_namespace (die, cu)) | |
5243 | return dwarf2_compute_name (name, die, cu, 1); | |
5244 | ||
5245 | back_to = make_cleanup (null_cleanup, NULL); | |
5246 | ||
5247 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5248 | if (!attr) | |
5249 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5250 | ||
5251 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
5252 | has computed. */ | |
5253 | if (attr && DW_STRING (attr)) | |
5254 | { | |
5255 | char *demangled; | |
5256 | ||
5257 | mangled = DW_STRING (attr); | |
5258 | ||
5259 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
5260 | type. It is easier for GDB users to search for such functions as | |
5261 | `name(params)' than `long name(params)'. In such case the minimal | |
5262 | symbol names do not match the full symbol names but for template | |
5263 | functions there is never a need to look up their definition from their | |
5264 | declaration so the only disadvantage remains the minimal symbol | |
5265 | variant `long name(params)' does not have the proper inferior type. | |
5266 | */ | |
5267 | ||
5268 | demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI | |
5269 | | (cu->language == language_java | |
5270 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
5271 | : DMGL_RET_DROP))); | |
5272 | if (demangled) | |
5273 | { | |
5274 | make_cleanup (xfree, demangled); | |
5275 | canon = demangled; | |
5276 | } | |
5277 | else | |
5278 | { | |
5279 | canon = mangled; | |
5280 | need_copy = 0; | |
5281 | } | |
5282 | } | |
5283 | ||
5284 | if (canon == NULL || check_physname) | |
5285 | { | |
5286 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
5287 | ||
5288 | if (canon != NULL && strcmp (physname, canon) != 0) | |
5289 | { | |
5290 | /* It may not mean a bug in GDB. The compiler could also | |
5291 | compute DW_AT_linkage_name incorrectly. But in such case | |
5292 | GDB would need to be bug-to-bug compatible. */ | |
5293 | ||
5294 | complaint (&symfile_complaints, | |
5295 | _("Computed physname <%s> does not match demangled <%s> " | |
5296 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5297 | physname, canon, mangled, die->offset, objfile->name); |
900e11f9 JK |
5298 | |
5299 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
5300 | is available here - over computed PHYSNAME. It is safer | |
5301 | against both buggy GDB and buggy compilers. */ | |
5302 | ||
5303 | retval = canon; | |
5304 | } | |
5305 | else | |
5306 | { | |
5307 | retval = physname; | |
5308 | need_copy = 0; | |
5309 | } | |
5310 | } | |
5311 | else | |
5312 | retval = canon; | |
5313 | ||
5314 | if (need_copy) | |
5315 | retval = obsavestring (retval, strlen (retval), | |
bb5ed363 | 5316 | &objfile->objfile_obstack); |
900e11f9 JK |
5317 | |
5318 | do_cleanups (back_to); | |
5319 | return retval; | |
0114d602 DJ |
5320 | } |
5321 | ||
27aa8d6a SW |
5322 | /* Read the import statement specified by the given die and record it. */ |
5323 | ||
5324 | static void | |
5325 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5326 | { | |
bb5ed363 | 5327 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 5328 | struct attribute *import_attr; |
32019081 | 5329 | struct die_info *imported_die, *child_die; |
de4affc9 | 5330 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5331 | const char *imported_name; |
794684b6 | 5332 | const char *imported_name_prefix; |
13387711 SW |
5333 | const char *canonical_name; |
5334 | const char *import_alias; | |
5335 | const char *imported_declaration = NULL; | |
794684b6 | 5336 | const char *import_prefix; |
32019081 JK |
5337 | VEC (const_char_ptr) *excludes = NULL; |
5338 | struct cleanup *cleanups; | |
13387711 SW |
5339 | |
5340 | char *temp; | |
27aa8d6a SW |
5341 | |
5342 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5343 | if (import_attr == NULL) | |
5344 | { | |
5345 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5346 | dwarf_tag_name (die->tag)); | |
5347 | return; | |
5348 | } | |
5349 | ||
de4affc9 CC |
5350 | imported_cu = cu; |
5351 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5352 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5353 | if (imported_name == NULL) |
5354 | { | |
5355 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5356 | ||
5357 | The import in the following code: | |
5358 | namespace A | |
5359 | { | |
5360 | typedef int B; | |
5361 | } | |
5362 | ||
5363 | int main () | |
5364 | { | |
5365 | using A::B; | |
5366 | B b; | |
5367 | return b; | |
5368 | } | |
5369 | ||
5370 | ... | |
5371 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5372 | <52> DW_AT_decl_file : 1 | |
5373 | <53> DW_AT_decl_line : 6 | |
5374 | <54> DW_AT_import : <0x75> | |
5375 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5376 | <59> DW_AT_name : B | |
5377 | <5b> DW_AT_decl_file : 1 | |
5378 | <5c> DW_AT_decl_line : 2 | |
5379 | <5d> DW_AT_type : <0x6e> | |
5380 | ... | |
5381 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5382 | <76> DW_AT_byte_size : 4 | |
5383 | <77> DW_AT_encoding : 5 (signed) | |
5384 | ||
5385 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5386 | This case will be ignored until the gcc bug is fixed. */ | |
5387 | return; | |
5388 | } | |
5389 | ||
82856980 SW |
5390 | /* Figure out the local name after import. */ |
5391 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5392 | |
794684b6 SW |
5393 | /* Figure out where the statement is being imported to. */ |
5394 | import_prefix = determine_prefix (die, cu); | |
5395 | ||
5396 | /* Figure out what the scope of the imported die is and prepend it | |
5397 | to the name of the imported die. */ | |
de4affc9 | 5398 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5399 | |
f55ee35c JK |
5400 | if (imported_die->tag != DW_TAG_namespace |
5401 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5402 | { |
13387711 SW |
5403 | imported_declaration = imported_name; |
5404 | canonical_name = imported_name_prefix; | |
794684b6 | 5405 | } |
13387711 | 5406 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5407 | { |
13387711 SW |
5408 | temp = alloca (strlen (imported_name_prefix) |
5409 | + 2 + strlen (imported_name) + 1); | |
5410 | strcpy (temp, imported_name_prefix); | |
5411 | strcat (temp, "::"); | |
5412 | strcat (temp, imported_name); | |
5413 | canonical_name = temp; | |
794684b6 | 5414 | } |
13387711 SW |
5415 | else |
5416 | canonical_name = imported_name; | |
794684b6 | 5417 | |
32019081 JK |
5418 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
5419 | ||
5420 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
5421 | for (child_die = die->child; child_die && child_die->tag; | |
5422 | child_die = sibling_die (child_die)) | |
5423 | { | |
5424 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
5425 | represented by an imported module entry with an import attribute | |
5426 | referring to the module and owned entries corresponding to those | |
5427 | entities that are renamed as part of being imported. */ | |
5428 | ||
5429 | if (child_die->tag != DW_TAG_imported_declaration) | |
5430 | { | |
5431 | complaint (&symfile_complaints, | |
5432 | _("child DW_TAG_imported_declaration expected " | |
5433 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5434 | child_die->offset, objfile->name); |
32019081 JK |
5435 | continue; |
5436 | } | |
5437 | ||
5438 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
5439 | if (import_attr == NULL) | |
5440 | { | |
5441 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5442 | dwarf_tag_name (child_die->tag)); | |
5443 | continue; | |
5444 | } | |
5445 | ||
5446 | imported_cu = cu; | |
5447 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
5448 | &imported_cu); | |
5449 | imported_name = dwarf2_name (imported_die, imported_cu); | |
5450 | if (imported_name == NULL) | |
5451 | { | |
5452 | complaint (&symfile_complaints, | |
5453 | _("child DW_TAG_imported_declaration has unknown " | |
5454 | "imported name - DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5455 | child_die->offset, objfile->name); |
32019081 JK |
5456 | continue; |
5457 | } | |
5458 | ||
5459 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
5460 | ||
5461 | process_die (child_die, cu); | |
5462 | } | |
5463 | ||
c0cc3a76 SW |
5464 | cp_add_using_directive (import_prefix, |
5465 | canonical_name, | |
5466 | import_alias, | |
13387711 | 5467 | imported_declaration, |
32019081 | 5468 | excludes, |
bb5ed363 | 5469 | &objfile->objfile_obstack); |
32019081 JK |
5470 | |
5471 | do_cleanups (cleanups); | |
27aa8d6a SW |
5472 | } |
5473 | ||
ae2de4f8 DE |
5474 | /* Cleanup function for read_file_scope. */ |
5475 | ||
cb1df416 DJ |
5476 | static void |
5477 | free_cu_line_header (void *arg) | |
5478 | { | |
5479 | struct dwarf2_cu *cu = arg; | |
5480 | ||
5481 | free_line_header (cu->line_header); | |
5482 | cu->line_header = NULL; | |
5483 | } | |
5484 | ||
9291a0cd TT |
5485 | static void |
5486 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5487 | char **name, char **comp_dir) | |
5488 | { | |
5489 | struct attribute *attr; | |
5490 | ||
5491 | *name = NULL; | |
5492 | *comp_dir = NULL; | |
5493 | ||
5494 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5495 | is not a source language identifier. */ | |
5496 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5497 | if (attr) | |
5498 | { | |
5499 | *name = DW_STRING (attr); | |
5500 | } | |
5501 | ||
5502 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5503 | if (attr) | |
5504 | *comp_dir = DW_STRING (attr); | |
5505 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5506 | { | |
5507 | *comp_dir = ldirname (*name); | |
5508 | if (*comp_dir != NULL) | |
5509 | make_cleanup (xfree, *comp_dir); | |
5510 | } | |
5511 | if (*comp_dir != NULL) | |
5512 | { | |
5513 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5514 | directory, get rid of it. */ | |
5515 | char *cp = strchr (*comp_dir, ':'); | |
5516 | ||
5517 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5518 | *comp_dir = cp + 1; | |
5519 | } | |
5520 | ||
5521 | if (*name == NULL) | |
5522 | *name = "<unknown>"; | |
5523 | } | |
5524 | ||
f3f5162e DE |
5525 | /* Handle DW_AT_stmt_list for a compilation unit or type unit. |
5526 | DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU. | |
5527 | COMP_DIR is the compilation directory. | |
5528 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ | |
2ab95328 TT |
5529 | |
5530 | static void | |
5531 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
f3f5162e | 5532 | const char *comp_dir, int want_line_info) |
2ab95328 TT |
5533 | { |
5534 | struct attribute *attr; | |
5535 | struct objfile *objfile = cu->objfile; | |
5536 | bfd *abfd = objfile->obfd; | |
5537 | ||
2ab95328 TT |
5538 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5539 | if (attr) | |
5540 | { | |
5541 | unsigned int line_offset = DW_UNSND (attr); | |
5542 | struct line_header *line_header | |
5543 | = dwarf_decode_line_header (line_offset, abfd, cu); | |
5544 | ||
5545 | if (line_header) | |
5546 | { | |
5547 | cu->line_header = line_header; | |
5548 | make_cleanup (free_cu_line_header, cu); | |
f3f5162e | 5549 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info); |
2ab95328 TT |
5550 | } |
5551 | } | |
5552 | } | |
5553 | ||
ae2de4f8 DE |
5554 | /* Process DW_TAG_compile_unit. */ |
5555 | ||
c906108c | 5556 | static void |
e7c27a73 | 5557 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5558 | { |
e7c27a73 | 5559 | struct objfile *objfile = cu->objfile; |
debd256d | 5560 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5561 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5562 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5563 | struct attribute *attr; | |
e1024ff1 | 5564 | char *name = NULL; |
c906108c SS |
5565 | char *comp_dir = NULL; |
5566 | struct die_info *child_die; | |
5567 | bfd *abfd = objfile->obfd; | |
e142c38c | 5568 | CORE_ADDR baseaddr; |
6e70227d | 5569 | |
e142c38c | 5570 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5571 | |
fae299cd | 5572 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5573 | |
5574 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5575 | from finish_block. */ | |
2acceee2 | 5576 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5577 | lowpc = highpc; |
5578 | lowpc += baseaddr; | |
5579 | highpc += baseaddr; | |
5580 | ||
9291a0cd | 5581 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5582 | |
e142c38c | 5583 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5584 | if (attr) |
5585 | { | |
e142c38c | 5586 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5587 | } |
5588 | ||
b0f35d58 | 5589 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5590 | if (attr) |
b0f35d58 | 5591 | cu->producer = DW_STRING (attr); |
303b6f5d | 5592 | |
f4b8a18d KW |
5593 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5594 | standardised yet. As a workaround for the language detection we fall | |
5595 | back to the DW_AT_producer string. */ | |
5596 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5597 | cu->language = language_opencl; | |
5598 | ||
0963b4bd | 5599 | /* We assume that we're processing GCC output. */ |
c906108c | 5600 | processing_gcc_compilation = 2; |
c906108c | 5601 | |
df8a16a1 DJ |
5602 | processing_has_namespace_info = 0; |
5603 | ||
c906108c SS |
5604 | start_symtab (name, comp_dir, lowpc); |
5605 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5606 | record_producer (cu->producer); |
c906108c | 5607 | |
f3f5162e DE |
5608 | /* Decode line number information if present. We do this before |
5609 | processing child DIEs, so that the line header table is available | |
5610 | for DW_AT_decl_file. */ | |
5611 | handle_DW_AT_stmt_list (die, cu, comp_dir, 1); | |
debd256d | 5612 | |
cb1df416 DJ |
5613 | /* Process all dies in compilation unit. */ |
5614 | if (die->child != NULL) | |
5615 | { | |
5616 | child_die = die->child; | |
5617 | while (child_die && child_die->tag) | |
5618 | { | |
5619 | process_die (child_die, cu); | |
5620 | child_die = sibling_die (child_die); | |
5621 | } | |
5622 | } | |
5623 | ||
2e276125 JB |
5624 | /* Decode macro information, if present. Dwarf 2 macro information |
5625 | refers to information in the line number info statement program | |
5626 | header, so we can only read it if we've read the header | |
5627 | successfully. */ | |
cf2c3c16 | 5628 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
2ab95328 | 5629 | if (attr && cu->line_header) |
2e276125 | 5630 | { |
cf2c3c16 TT |
5631 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
5632 | complaint (&symfile_complaints, | |
5633 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
5634 | ||
5635 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), | |
5636 | comp_dir, abfd, cu, | |
5637 | &dwarf2_per_objfile->macro, 1); | |
5638 | } | |
5639 | else | |
5640 | { | |
5641 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
5642 | if (attr && cu->line_header) | |
5643 | { | |
5644 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5645 | |
cf2c3c16 TT |
5646 | dwarf_decode_macros (cu->line_header, macro_offset, |
5647 | comp_dir, abfd, cu, | |
5648 | &dwarf2_per_objfile->macinfo, 0); | |
5649 | } | |
2e276125 | 5650 | } |
9cdd5dbd | 5651 | |
debd256d | 5652 | do_cleanups (back_to); |
5fb290d7 DJ |
5653 | } |
5654 | ||
ae2de4f8 DE |
5655 | /* Process DW_TAG_type_unit. |
5656 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
5657 | actual type being defined by this TU. In this case the first top |
5658 | level sibling is there to provide context only. */ | |
5659 | ||
5660 | static void | |
5661 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5662 | { | |
5663 | struct objfile *objfile = cu->objfile; | |
5664 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5665 | CORE_ADDR lowpc; | |
5666 | struct attribute *attr; | |
5667 | char *name = NULL; | |
5668 | char *comp_dir = NULL; | |
5669 | struct die_info *child_die; | |
5670 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5671 | |
5672 | /* start_symtab needs a low pc, but we don't really have one. | |
5673 | Do what read_file_scope would do in the absence of such info. */ | |
5674 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5675 | ||
5676 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5677 | is not a source language identifier. */ | |
5678 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5679 | if (attr) | |
5680 | name = DW_STRING (attr); | |
5681 | ||
5682 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5683 | if (attr) | |
5684 | comp_dir = DW_STRING (attr); | |
5685 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5686 | { | |
5687 | comp_dir = ldirname (name); | |
5688 | if (comp_dir != NULL) | |
5689 | make_cleanup (xfree, comp_dir); | |
5690 | } | |
5691 | ||
5692 | if (name == NULL) | |
5693 | name = "<unknown>"; | |
5694 | ||
5695 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5696 | if (attr) | |
5697 | set_cu_language (DW_UNSND (attr), cu); | |
5698 | ||
5699 | /* This isn't technically needed today. It is done for symmetry | |
5700 | with read_file_scope. */ | |
5701 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5702 | if (attr) |
348e048f DE |
5703 | cu->producer = DW_STRING (attr); |
5704 | ||
0963b4bd | 5705 | /* We assume that we're processing GCC output. */ |
348e048f DE |
5706 | processing_gcc_compilation = 2; |
5707 | ||
5708 | processing_has_namespace_info = 0; | |
5709 | ||
5710 | start_symtab (name, comp_dir, lowpc); | |
5711 | record_debugformat ("DWARF 2"); | |
5712 | record_producer (cu->producer); | |
5713 | ||
f3f5162e DE |
5714 | /* Decode line number information if present. We do this before |
5715 | processing child DIEs, so that the line header table is available | |
5716 | for DW_AT_decl_file. | |
5717 | We don't need the pc/line-number mapping for type units. */ | |
5718 | handle_DW_AT_stmt_list (die, cu, comp_dir, 0); | |
2ab95328 | 5719 | |
348e048f DE |
5720 | /* Process the dies in the type unit. */ |
5721 | if (die->child == NULL) | |
5722 | { | |
5723 | dump_die_for_error (die); | |
5724 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5725 | bfd_get_filename (abfd)); | |
5726 | } | |
5727 | ||
5728 | child_die = die->child; | |
5729 | ||
5730 | while (child_die && child_die->tag) | |
5731 | { | |
5732 | process_die (child_die, cu); | |
5733 | ||
5734 | child_die = sibling_die (child_die); | |
5735 | } | |
5736 | ||
5737 | do_cleanups (back_to); | |
5738 | } | |
5739 | ||
d389af10 JK |
5740 | /* qsort helper for inherit_abstract_dies. */ |
5741 | ||
5742 | static int | |
5743 | unsigned_int_compar (const void *ap, const void *bp) | |
5744 | { | |
5745 | unsigned int a = *(unsigned int *) ap; | |
5746 | unsigned int b = *(unsigned int *) bp; | |
5747 | ||
5748 | return (a > b) - (b > a); | |
5749 | } | |
5750 | ||
5751 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
5752 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
5753 | already referenced by DW_AT_abstract_origin from the children of the | |
5754 | current DIE. */ | |
d389af10 JK |
5755 | |
5756 | static void | |
5757 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5758 | { | |
5759 | struct die_info *child_die; | |
5760 | unsigned die_children_count; | |
5761 | /* CU offsets which were referenced by children of the current DIE. */ | |
5762 | unsigned *offsets; | |
5763 | unsigned *offsets_end, *offsetp; | |
5764 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5765 | struct die_info *origin_die; | |
5766 | /* Iterator of the ORIGIN_DIE children. */ | |
5767 | struct die_info *origin_child_die; | |
5768 | struct cleanup *cleanups; | |
5769 | struct attribute *attr; | |
cd02d79d PA |
5770 | struct dwarf2_cu *origin_cu; |
5771 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5772 | |
5773 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5774 | if (!attr) | |
5775 | return; | |
5776 | ||
cd02d79d PA |
5777 | /* Note that following die references may follow to a die in a |
5778 | different cu. */ | |
5779 | ||
5780 | origin_cu = cu; | |
5781 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5782 | ||
5783 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5784 | symbols in. */ | |
5785 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5786 | origin_cu->list_in_scope = cu->list_in_scope; | |
5787 | ||
edb3359d DJ |
5788 | if (die->tag != origin_die->tag |
5789 | && !(die->tag == DW_TAG_inlined_subroutine | |
5790 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5791 | complaint (&symfile_complaints, |
5792 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5793 | die->offset, origin_die->offset); | |
5794 | ||
5795 | child_die = die->child; | |
5796 | die_children_count = 0; | |
5797 | while (child_die && child_die->tag) | |
5798 | { | |
5799 | child_die = sibling_die (child_die); | |
5800 | die_children_count++; | |
5801 | } | |
5802 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5803 | cleanups = make_cleanup (xfree, offsets); | |
5804 | ||
5805 | offsets_end = offsets; | |
5806 | child_die = die->child; | |
5807 | while (child_die && child_die->tag) | |
5808 | { | |
c38f313d DJ |
5809 | /* For each CHILD_DIE, find the corresponding child of |
5810 | ORIGIN_DIE. If there is more than one layer of | |
5811 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5812 | but GCC versions at least through 4.4 generate this (GCC PR | |
5813 | 40573). */ | |
5814 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5815 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5816 | |
c38f313d DJ |
5817 | while (1) |
5818 | { | |
cd02d79d PA |
5819 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5820 | child_origin_cu); | |
c38f313d DJ |
5821 | if (attr == NULL) |
5822 | break; | |
cd02d79d PA |
5823 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5824 | &child_origin_cu); | |
c38f313d DJ |
5825 | } |
5826 | ||
d389af10 JK |
5827 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5828 | counterpart may exist. */ | |
c38f313d | 5829 | if (child_origin_die != child_die) |
d389af10 | 5830 | { |
edb3359d DJ |
5831 | if (child_die->tag != child_origin_die->tag |
5832 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5833 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5834 | complaint (&symfile_complaints, |
5835 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5836 | "different tags"), child_die->offset, | |
5837 | child_origin_die->offset); | |
c38f313d DJ |
5838 | if (child_origin_die->parent != origin_die) |
5839 | complaint (&symfile_complaints, | |
5840 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5841 | "different parents"), child_die->offset, | |
5842 | child_origin_die->offset); | |
5843 | else | |
5844 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5845 | } |
5846 | child_die = sibling_die (child_die); | |
5847 | } | |
5848 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5849 | unsigned_int_compar); | |
5850 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5851 | if (offsetp[-1] == *offsetp) | |
3e43a32a MS |
5852 | complaint (&symfile_complaints, |
5853 | _("Multiple children of DIE 0x%x refer " | |
5854 | "to DIE 0x%x as their abstract origin"), | |
d389af10 JK |
5855 | die->offset, *offsetp); |
5856 | ||
5857 | offsetp = offsets; | |
5858 | origin_child_die = origin_die->child; | |
5859 | while (origin_child_die && origin_child_die->tag) | |
5860 | { | |
5861 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5862 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5863 | offsetp++; | |
5864 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5865 | { | |
5866 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5867 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5868 | } |
5869 | origin_child_die = sibling_die (origin_child_die); | |
5870 | } | |
cd02d79d | 5871 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5872 | |
5873 | do_cleanups (cleanups); | |
5874 | } | |
5875 | ||
c906108c | 5876 | static void |
e7c27a73 | 5877 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5878 | { |
e7c27a73 | 5879 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5880 | struct context_stack *new; |
c906108c SS |
5881 | CORE_ADDR lowpc; |
5882 | CORE_ADDR highpc; | |
5883 | struct die_info *child_die; | |
edb3359d | 5884 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5885 | char *name; |
e142c38c | 5886 | CORE_ADDR baseaddr; |
801e3a5b | 5887 | struct block *block; |
edb3359d | 5888 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5889 | VEC (symbolp) *template_args = NULL; |
5890 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5891 | |
5892 | if (inlined_func) | |
5893 | { | |
5894 | /* If we do not have call site information, we can't show the | |
5895 | caller of this inlined function. That's too confusing, so | |
5896 | only use the scope for local variables. */ | |
5897 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5898 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5899 | if (call_line == NULL || call_file == NULL) | |
5900 | { | |
5901 | read_lexical_block_scope (die, cu); | |
5902 | return; | |
5903 | } | |
5904 | } | |
c906108c | 5905 | |
e142c38c DJ |
5906 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5907 | ||
94af9270 | 5908 | name = dwarf2_name (die, cu); |
c906108c | 5909 | |
e8d05480 JB |
5910 | /* Ignore functions with missing or empty names. These are actually |
5911 | illegal according to the DWARF standard. */ | |
5912 | if (name == NULL) | |
5913 | { | |
5914 | complaint (&symfile_complaints, | |
5915 | _("missing name for subprogram DIE at %d"), die->offset); | |
5916 | return; | |
5917 | } | |
5918 | ||
5919 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5920 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5921 | { | |
ae4d0c03 PM |
5922 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5923 | if (!attr || !DW_UNSND (attr)) | |
5924 | complaint (&symfile_complaints, | |
3e43a32a MS |
5925 | _("cannot get low and high bounds " |
5926 | "for subprogram DIE at %d"), | |
ae4d0c03 | 5927 | die->offset); |
e8d05480 JB |
5928 | return; |
5929 | } | |
c906108c SS |
5930 | |
5931 | lowpc += baseaddr; | |
5932 | highpc += baseaddr; | |
5933 | ||
34eaf542 TT |
5934 | /* If we have any template arguments, then we must allocate a |
5935 | different sort of symbol. */ | |
5936 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5937 | { | |
5938 | if (child_die->tag == DW_TAG_template_type_param | |
5939 | || child_die->tag == DW_TAG_template_value_param) | |
5940 | { | |
5941 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5942 | struct template_symbol); | |
5943 | templ_func->base.is_cplus_template_function = 1; | |
5944 | break; | |
5945 | } | |
5946 | } | |
5947 | ||
c906108c | 5948 | new = push_context (0, lowpc); |
34eaf542 TT |
5949 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5950 | (struct symbol *) templ_func); | |
4c2df51b | 5951 | |
4cecd739 DJ |
5952 | /* If there is a location expression for DW_AT_frame_base, record |
5953 | it. */ | |
e142c38c | 5954 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5955 | if (attr) |
c034e007 AC |
5956 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5957 | expression is being recorded directly in the function's symbol | |
5958 | and not in a separate frame-base object. I guess this hack is | |
5959 | to avoid adding some sort of frame-base adjunct/annex to the | |
5960 | function's symbol :-(. The problem with doing this is that it | |
5961 | results in a function symbol with a location expression that | |
5962 | has nothing to do with the location of the function, ouch! The | |
5963 | relationship should be: a function's symbol has-a frame base; a | |
5964 | frame-base has-a location expression. */ | |
e7c27a73 | 5965 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5966 | |
e142c38c | 5967 | cu->list_in_scope = &local_symbols; |
c906108c | 5968 | |
639d11d3 | 5969 | if (die->child != NULL) |
c906108c | 5970 | { |
639d11d3 | 5971 | child_die = die->child; |
c906108c SS |
5972 | while (child_die && child_die->tag) |
5973 | { | |
34eaf542 TT |
5974 | if (child_die->tag == DW_TAG_template_type_param |
5975 | || child_die->tag == DW_TAG_template_value_param) | |
5976 | { | |
5977 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5978 | ||
f1078f66 DJ |
5979 | if (arg != NULL) |
5980 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
5981 | } |
5982 | else | |
5983 | process_die (child_die, cu); | |
c906108c SS |
5984 | child_die = sibling_die (child_die); |
5985 | } | |
5986 | } | |
5987 | ||
d389af10 JK |
5988 | inherit_abstract_dies (die, cu); |
5989 | ||
4a811a97 UW |
5990 | /* If we have a DW_AT_specification, we might need to import using |
5991 | directives from the context of the specification DIE. See the | |
5992 | comment in determine_prefix. */ | |
5993 | if (cu->language == language_cplus | |
5994 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
5995 | { | |
5996 | struct dwarf2_cu *spec_cu = cu; | |
5997 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
5998 | ||
5999 | while (spec_die) | |
6000 | { | |
6001 | child_die = spec_die->child; | |
6002 | while (child_die && child_die->tag) | |
6003 | { | |
6004 | if (child_die->tag == DW_TAG_imported_module) | |
6005 | process_die (child_die, spec_cu); | |
6006 | child_die = sibling_die (child_die); | |
6007 | } | |
6008 | ||
6009 | /* In some cases, GCC generates specification DIEs that | |
6010 | themselves contain DW_AT_specification attributes. */ | |
6011 | spec_die = die_specification (spec_die, &spec_cu); | |
6012 | } | |
6013 | } | |
6014 | ||
c906108c SS |
6015 | new = pop_context (); |
6016 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
6017 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
6018 | lowpc, highpc, objfile); | |
6019 | ||
df8a16a1 | 6020 | /* For C++, set the block's scope. */ |
f55ee35c | 6021 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 6022 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 6023 | determine_prefix (die, cu), |
df8a16a1 DJ |
6024 | processing_has_namespace_info); |
6025 | ||
801e3a5b JB |
6026 | /* If we have address ranges, record them. */ |
6027 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 6028 | |
34eaf542 TT |
6029 | /* Attach template arguments to function. */ |
6030 | if (! VEC_empty (symbolp, template_args)) | |
6031 | { | |
6032 | gdb_assert (templ_func != NULL); | |
6033 | ||
6034 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
6035 | templ_func->template_arguments | |
6036 | = obstack_alloc (&objfile->objfile_obstack, | |
6037 | (templ_func->n_template_arguments | |
6038 | * sizeof (struct symbol *))); | |
6039 | memcpy (templ_func->template_arguments, | |
6040 | VEC_address (symbolp, template_args), | |
6041 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
6042 | VEC_free (symbolp, template_args); | |
6043 | } | |
6044 | ||
208d8187 JB |
6045 | /* In C++, we can have functions nested inside functions (e.g., when |
6046 | a function declares a class that has methods). This means that | |
6047 | when we finish processing a function scope, we may need to go | |
6048 | back to building a containing block's symbol lists. */ | |
6049 | local_symbols = new->locals; | |
6050 | param_symbols = new->params; | |
27aa8d6a | 6051 | using_directives = new->using_directives; |
208d8187 | 6052 | |
921e78cf JB |
6053 | /* If we've finished processing a top-level function, subsequent |
6054 | symbols go in the file symbol list. */ | |
6055 | if (outermost_context_p ()) | |
e142c38c | 6056 | cu->list_in_scope = &file_symbols; |
c906108c SS |
6057 | } |
6058 | ||
6059 | /* Process all the DIES contained within a lexical block scope. Start | |
6060 | a new scope, process the dies, and then close the scope. */ | |
6061 | ||
6062 | static void | |
e7c27a73 | 6063 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6064 | { |
e7c27a73 | 6065 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 6066 | struct context_stack *new; |
c906108c SS |
6067 | CORE_ADDR lowpc, highpc; |
6068 | struct die_info *child_die; | |
e142c38c DJ |
6069 | CORE_ADDR baseaddr; |
6070 | ||
6071 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
6072 | |
6073 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
6074 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
6075 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 6076 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 6077 | describe ranges. */ |
d85a05f0 | 6078 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
6079 | return; |
6080 | lowpc += baseaddr; | |
6081 | highpc += baseaddr; | |
6082 | ||
6083 | push_context (0, lowpc); | |
639d11d3 | 6084 | if (die->child != NULL) |
c906108c | 6085 | { |
639d11d3 | 6086 | child_die = die->child; |
c906108c SS |
6087 | while (child_die && child_die->tag) |
6088 | { | |
e7c27a73 | 6089 | process_die (child_die, cu); |
c906108c SS |
6090 | child_die = sibling_die (child_die); |
6091 | } | |
6092 | } | |
6093 | new = pop_context (); | |
6094 | ||
8540c487 | 6095 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 6096 | { |
801e3a5b JB |
6097 | struct block *block |
6098 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
6099 | highpc, objfile); | |
6100 | ||
6101 | /* Note that recording ranges after traversing children, as we | |
6102 | do here, means that recording a parent's ranges entails | |
6103 | walking across all its children's ranges as they appear in | |
6104 | the address map, which is quadratic behavior. | |
6105 | ||
6106 | It would be nicer to record the parent's ranges before | |
6107 | traversing its children, simply overriding whatever you find | |
6108 | there. But since we don't even decide whether to create a | |
6109 | block until after we've traversed its children, that's hard | |
6110 | to do. */ | |
6111 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
6112 | } |
6113 | local_symbols = new->locals; | |
27aa8d6a | 6114 | using_directives = new->using_directives; |
c906108c SS |
6115 | } |
6116 | ||
96408a79 SA |
6117 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
6118 | ||
6119 | static void | |
6120 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6121 | { | |
6122 | struct objfile *objfile = cu->objfile; | |
6123 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6124 | CORE_ADDR pc, baseaddr; | |
6125 | struct attribute *attr; | |
6126 | struct call_site *call_site, call_site_local; | |
6127 | void **slot; | |
6128 | int nparams; | |
6129 | struct die_info *child_die; | |
6130 | ||
6131 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6132 | ||
6133 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
6134 | if (!attr) | |
6135 | { | |
6136 | complaint (&symfile_complaints, | |
6137 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
6138 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6139 | die->offset, objfile->name); |
96408a79 SA |
6140 | return; |
6141 | } | |
6142 | pc = DW_ADDR (attr) + baseaddr; | |
6143 | ||
6144 | if (cu->call_site_htab == NULL) | |
6145 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
6146 | NULL, &objfile->objfile_obstack, | |
6147 | hashtab_obstack_allocate, NULL); | |
6148 | call_site_local.pc = pc; | |
6149 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
6150 | if (*slot != NULL) | |
6151 | { | |
6152 | complaint (&symfile_complaints, | |
6153 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
6154 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6155 | paddress (gdbarch, pc), die->offset, objfile->name); |
96408a79 SA |
6156 | return; |
6157 | } | |
6158 | ||
6159 | /* Count parameters at the caller. */ | |
6160 | ||
6161 | nparams = 0; | |
6162 | for (child_die = die->child; child_die && child_die->tag; | |
6163 | child_die = sibling_die (child_die)) | |
6164 | { | |
6165 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6166 | { | |
6167 | complaint (&symfile_complaints, | |
6168 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
6169 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6170 | child_die->tag, child_die->offset, objfile->name); |
96408a79 SA |
6171 | continue; |
6172 | } | |
6173 | ||
6174 | nparams++; | |
6175 | } | |
6176 | ||
6177 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
6178 | (sizeof (*call_site) | |
6179 | + (sizeof (*call_site->parameter) | |
6180 | * (nparams - 1)))); | |
6181 | *slot = call_site; | |
6182 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
6183 | call_site->pc = pc; | |
6184 | ||
6185 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
6186 | { | |
6187 | struct die_info *func_die; | |
6188 | ||
6189 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
6190 | for (func_die = die->parent; | |
6191 | func_die && func_die->tag != DW_TAG_subprogram | |
6192 | && func_die->tag != DW_TAG_subroutine_type; | |
6193 | func_die = func_die->parent); | |
6194 | ||
6195 | /* DW_AT_GNU_all_call_sites is a superset | |
6196 | of DW_AT_GNU_all_tail_call_sites. */ | |
6197 | if (func_die | |
6198 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
6199 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
6200 | { | |
6201 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
6202 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
6203 | both the initial caller containing the real return address PC and | |
6204 | the final callee containing the current PC of a chain of tail | |
6205 | calls do not need to have the tail call list complete. But any | |
6206 | function candidate for a virtual tail call frame searched via | |
6207 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
6208 | determined unambiguously. */ | |
6209 | } | |
6210 | else | |
6211 | { | |
6212 | struct type *func_type = NULL; | |
6213 | ||
6214 | if (func_die) | |
6215 | func_type = get_die_type (func_die, cu); | |
6216 | if (func_type != NULL) | |
6217 | { | |
6218 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
6219 | ||
6220 | /* Enlist this call site to the function. */ | |
6221 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
6222 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
6223 | } | |
6224 | else | |
6225 | complaint (&symfile_complaints, | |
6226 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
6227 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6228 | die->offset, objfile->name); |
96408a79 SA |
6229 | } |
6230 | } | |
6231 | ||
6232 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
6233 | if (attr == NULL) | |
6234 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
6235 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
6236 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
6237 | /* Keep NULL DWARF_BLOCK. */; | |
6238 | else if (attr_form_is_block (attr)) | |
6239 | { | |
6240 | struct dwarf2_locexpr_baton *dlbaton; | |
6241 | ||
6242 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
6243 | dlbaton->data = DW_BLOCK (attr)->data; | |
6244 | dlbaton->size = DW_BLOCK (attr)->size; | |
6245 | dlbaton->per_cu = cu->per_cu; | |
6246 | ||
6247 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
6248 | } | |
6249 | else if (is_ref_attr (attr)) | |
6250 | { | |
96408a79 SA |
6251 | struct dwarf2_cu *target_cu = cu; |
6252 | struct die_info *target_die; | |
6253 | ||
6254 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
6255 | gdb_assert (target_cu->objfile == objfile); | |
6256 | if (die_is_declaration (target_die, target_cu)) | |
6257 | { | |
6258 | const char *target_physname; | |
6259 | ||
6260 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
6261 | if (target_physname == NULL) | |
6262 | complaint (&symfile_complaints, | |
6263 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6264 | "physname, for referencing DIE 0x%x [in module %s]"), | |
bb5ed363 | 6265 | die->offset, objfile->name); |
96408a79 SA |
6266 | else |
6267 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
6268 | } | |
6269 | else | |
6270 | { | |
6271 | CORE_ADDR lowpc; | |
6272 | ||
6273 | /* DW_AT_entry_pc should be preferred. */ | |
6274 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
6275 | complaint (&symfile_complaints, | |
6276 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6277 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
bb5ed363 | 6278 | die->offset, objfile->name); |
96408a79 SA |
6279 | else |
6280 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
6281 | } | |
6282 | } | |
6283 | else | |
6284 | complaint (&symfile_complaints, | |
6285 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
6286 | "block nor reference, for DIE 0x%x [in module %s]"), | |
bb5ed363 | 6287 | die->offset, objfile->name); |
96408a79 SA |
6288 | |
6289 | call_site->per_cu = cu->per_cu; | |
6290 | ||
6291 | for (child_die = die->child; | |
6292 | child_die && child_die->tag; | |
6293 | child_die = sibling_die (child_die)) | |
6294 | { | |
6295 | struct dwarf2_locexpr_baton *dlbaton; | |
6296 | struct call_site_parameter *parameter; | |
6297 | ||
6298 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6299 | { | |
6300 | /* Already printed the complaint above. */ | |
6301 | continue; | |
6302 | } | |
6303 | ||
6304 | gdb_assert (call_site->parameter_count < nparams); | |
6305 | parameter = &call_site->parameter[call_site->parameter_count]; | |
6306 | ||
6307 | /* DW_AT_location specifies the register number. Value of the data | |
6308 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ | |
6309 | ||
6310 | attr = dwarf2_attr (child_die, DW_AT_location, cu); | |
6311 | if (!attr || !attr_form_is_block (attr)) | |
6312 | { | |
6313 | complaint (&symfile_complaints, | |
6314 | _("No DW_FORM_block* DW_AT_location for " | |
6315 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6316 | child_die->offset, objfile->name); |
96408a79 SA |
6317 | continue; |
6318 | } | |
6319 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, | |
6320 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); | |
6321 | if (parameter->dwarf_reg == -1 | |
6322 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, | |
6323 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], | |
6324 | ¶meter->fb_offset)) | |
6325 | { | |
6326 | complaint (&symfile_complaints, | |
6327 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
6328 | "for DW_FORM_block* DW_AT_location for " | |
6329 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6330 | child_die->offset, objfile->name); |
96408a79 SA |
6331 | continue; |
6332 | } | |
6333 | ||
6334 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
6335 | if (!attr_form_is_block (attr)) | |
6336 | { | |
6337 | complaint (&symfile_complaints, | |
6338 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
6339 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6340 | child_die->offset, objfile->name); |
96408a79 SA |
6341 | continue; |
6342 | } | |
6343 | parameter->value = DW_BLOCK (attr)->data; | |
6344 | parameter->value_size = DW_BLOCK (attr)->size; | |
6345 | ||
6346 | /* Parameters are not pre-cleared by memset above. */ | |
6347 | parameter->data_value = NULL; | |
6348 | parameter->data_value_size = 0; | |
6349 | call_site->parameter_count++; | |
6350 | ||
6351 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
6352 | if (attr) | |
6353 | { | |
6354 | if (!attr_form_is_block (attr)) | |
6355 | complaint (&symfile_complaints, | |
6356 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
6357 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6358 | child_die->offset, objfile->name); |
96408a79 SA |
6359 | else |
6360 | { | |
6361 | parameter->data_value = DW_BLOCK (attr)->data; | |
6362 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
6363 | } | |
6364 | } | |
6365 | } | |
6366 | } | |
6367 | ||
43039443 | 6368 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
6369 | Return 1 if the attributes are present and valid, otherwise, return 0. |
6370 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
6371 | |
6372 | static int | |
6373 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
6374 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
6375 | struct partial_symtab *ranges_pst) | |
43039443 JK |
6376 | { |
6377 | struct objfile *objfile = cu->objfile; | |
6378 | struct comp_unit_head *cu_header = &cu->header; | |
6379 | bfd *obfd = objfile->obfd; | |
6380 | unsigned int addr_size = cu_header->addr_size; | |
6381 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6382 | /* Base address selection entry. */ | |
6383 | CORE_ADDR base; | |
6384 | int found_base; | |
6385 | unsigned int dummy; | |
6386 | gdb_byte *buffer; | |
6387 | CORE_ADDR marker; | |
6388 | int low_set; | |
6389 | CORE_ADDR low = 0; | |
6390 | CORE_ADDR high = 0; | |
ff013f42 | 6391 | CORE_ADDR baseaddr; |
43039443 | 6392 | |
d00adf39 DE |
6393 | found_base = cu->base_known; |
6394 | base = cu->base_address; | |
43039443 | 6395 | |
be391dca | 6396 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 6397 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
6398 | { |
6399 | complaint (&symfile_complaints, | |
6400 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
6401 | offset); | |
6402 | return 0; | |
6403 | } | |
dce234bc | 6404 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
6405 | |
6406 | /* Read in the largest possible address. */ | |
6407 | marker = read_address (obfd, buffer, cu, &dummy); | |
6408 | if ((marker & mask) == mask) | |
6409 | { | |
6410 | /* If we found the largest possible address, then | |
6411 | read the base address. */ | |
6412 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6413 | buffer += 2 * addr_size; | |
6414 | offset += 2 * addr_size; | |
6415 | found_base = 1; | |
6416 | } | |
6417 | ||
6418 | low_set = 0; | |
6419 | ||
e7030f15 | 6420 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 6421 | |
43039443 JK |
6422 | while (1) |
6423 | { | |
6424 | CORE_ADDR range_beginning, range_end; | |
6425 | ||
6426 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
6427 | buffer += addr_size; | |
6428 | range_end = read_address (obfd, buffer, cu, &dummy); | |
6429 | buffer += addr_size; | |
6430 | offset += 2 * addr_size; | |
6431 | ||
6432 | /* An end of list marker is a pair of zero addresses. */ | |
6433 | if (range_beginning == 0 && range_end == 0) | |
6434 | /* Found the end of list entry. */ | |
6435 | break; | |
6436 | ||
6437 | /* Each base address selection entry is a pair of 2 values. | |
6438 | The first is the largest possible address, the second is | |
6439 | the base address. Check for a base address here. */ | |
6440 | if ((range_beginning & mask) == mask) | |
6441 | { | |
6442 | /* If we found the largest possible address, then | |
6443 | read the base address. */ | |
6444 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6445 | found_base = 1; | |
6446 | continue; | |
6447 | } | |
6448 | ||
6449 | if (!found_base) | |
6450 | { | |
6451 | /* We have no valid base address for the ranges | |
6452 | data. */ | |
6453 | complaint (&symfile_complaints, | |
6454 | _("Invalid .debug_ranges data (no base address)")); | |
6455 | return 0; | |
6456 | } | |
6457 | ||
9277c30c UW |
6458 | if (range_beginning > range_end) |
6459 | { | |
6460 | /* Inverted range entries are invalid. */ | |
6461 | complaint (&symfile_complaints, | |
6462 | _("Invalid .debug_ranges data (inverted range)")); | |
6463 | return 0; | |
6464 | } | |
6465 | ||
6466 | /* Empty range entries have no effect. */ | |
6467 | if (range_beginning == range_end) | |
6468 | continue; | |
6469 | ||
43039443 JK |
6470 | range_beginning += base; |
6471 | range_end += base; | |
6472 | ||
9277c30c | 6473 | if (ranges_pst != NULL) |
ff013f42 | 6474 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
6475 | range_beginning + baseaddr, |
6476 | range_end - 1 + baseaddr, | |
ff013f42 JK |
6477 | ranges_pst); |
6478 | ||
43039443 JK |
6479 | /* FIXME: This is recording everything as a low-high |
6480 | segment of consecutive addresses. We should have a | |
6481 | data structure for discontiguous block ranges | |
6482 | instead. */ | |
6483 | if (! low_set) | |
6484 | { | |
6485 | low = range_beginning; | |
6486 | high = range_end; | |
6487 | low_set = 1; | |
6488 | } | |
6489 | else | |
6490 | { | |
6491 | if (range_beginning < low) | |
6492 | low = range_beginning; | |
6493 | if (range_end > high) | |
6494 | high = range_end; | |
6495 | } | |
6496 | } | |
6497 | ||
6498 | if (! low_set) | |
6499 | /* If the first entry is an end-of-list marker, the range | |
6500 | describes an empty scope, i.e. no instructions. */ | |
6501 | return 0; | |
6502 | ||
6503 | if (low_return) | |
6504 | *low_return = low; | |
6505 | if (high_return) | |
6506 | *high_return = high; | |
6507 | return 1; | |
6508 | } | |
6509 | ||
af34e669 DJ |
6510 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
6511 | are present and valid, otherwise, return 0. Return -1 if the range is | |
6512 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 6513 | static int |
af34e669 | 6514 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
6515 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
6516 | struct partial_symtab *pst) | |
c906108c SS |
6517 | { |
6518 | struct attribute *attr; | |
af34e669 DJ |
6519 | CORE_ADDR low = 0; |
6520 | CORE_ADDR high = 0; | |
6521 | int ret = 0; | |
c906108c | 6522 | |
e142c38c | 6523 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 6524 | if (attr) |
af34e669 DJ |
6525 | { |
6526 | high = DW_ADDR (attr); | |
e142c38c | 6527 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
6528 | if (attr) |
6529 | low = DW_ADDR (attr); | |
6530 | else | |
6531 | /* Found high w/o low attribute. */ | |
6532 | return 0; | |
6533 | ||
6534 | /* Found consecutive range of addresses. */ | |
6535 | ret = 1; | |
6536 | } | |
c906108c | 6537 | else |
af34e669 | 6538 | { |
e142c38c | 6539 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6540 | if (attr != NULL) |
6541 | { | |
af34e669 | 6542 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6543 | .debug_ranges section. */ |
d85a05f0 | 6544 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6545 | return 0; |
43039443 | 6546 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6547 | ret = -1; |
6548 | } | |
6549 | } | |
c906108c | 6550 | |
9373cf26 JK |
6551 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6552 | if (high <= low) | |
c906108c SS |
6553 | return 0; |
6554 | ||
6555 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6556 | eliminate duplicate copies of functions and vtables and such. | |
6557 | The linker will arbitrarily choose one and discard the others. | |
6558 | The AT_*_pc values for such functions refer to local labels in | |
6559 | these sections. If the section from that file was discarded, the | |
6560 | labels are not in the output, so the relocs get a value of 0. | |
6561 | If this is a discarded function, mark the pc bounds as invalid, | |
6562 | so that GDB will ignore it. */ | |
72dca2f5 | 6563 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6564 | return 0; |
6565 | ||
6566 | *lowpc = low; | |
96408a79 SA |
6567 | if (highpc) |
6568 | *highpc = high; | |
af34e669 | 6569 | return ret; |
c906108c SS |
6570 | } |
6571 | ||
b084d499 JB |
6572 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6573 | its low and high PC addresses. Do nothing if these addresses could not | |
6574 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6575 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6576 | ||
6577 | static void | |
6578 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6579 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6580 | struct dwarf2_cu *cu) | |
6581 | { | |
6582 | CORE_ADDR low, high; | |
6583 | struct die_info *child = die->child; | |
6584 | ||
d85a05f0 | 6585 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6586 | { |
6587 | *lowpc = min (*lowpc, low); | |
6588 | *highpc = max (*highpc, high); | |
6589 | } | |
6590 | ||
6591 | /* If the language does not allow nested subprograms (either inside | |
6592 | subprograms or lexical blocks), we're done. */ | |
6593 | if (cu->language != language_ada) | |
6594 | return; | |
6e70227d | 6595 | |
b084d499 JB |
6596 | /* Check all the children of the given DIE. If it contains nested |
6597 | subprograms, then check their pc bounds. Likewise, we need to | |
6598 | check lexical blocks as well, as they may also contain subprogram | |
6599 | definitions. */ | |
6600 | while (child && child->tag) | |
6601 | { | |
6602 | if (child->tag == DW_TAG_subprogram | |
6603 | || child->tag == DW_TAG_lexical_block) | |
6604 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6605 | child = sibling_die (child); | |
6606 | } | |
6607 | } | |
6608 | ||
fae299cd DC |
6609 | /* Get the low and high pc's represented by the scope DIE, and store |
6610 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6611 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6612 | ||
6613 | static void | |
6614 | get_scope_pc_bounds (struct die_info *die, | |
6615 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6616 | struct dwarf2_cu *cu) | |
6617 | { | |
6618 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6619 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6620 | CORE_ADDR current_low, current_high; | |
6621 | ||
d85a05f0 | 6622 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6623 | { |
6624 | best_low = current_low; | |
6625 | best_high = current_high; | |
6626 | } | |
6627 | else | |
6628 | { | |
6629 | struct die_info *child = die->child; | |
6630 | ||
6631 | while (child && child->tag) | |
6632 | { | |
6633 | switch (child->tag) { | |
6634 | case DW_TAG_subprogram: | |
b084d499 | 6635 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6636 | break; |
6637 | case DW_TAG_namespace: | |
f55ee35c | 6638 | case DW_TAG_module: |
fae299cd DC |
6639 | /* FIXME: carlton/2004-01-16: Should we do this for |
6640 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6641 | that current GCC's always emit the DIEs corresponding | |
6642 | to definitions of methods of classes as children of a | |
6643 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6644 | the DIEs giving the declarations, which could be | |
6645 | anywhere). But I don't see any reason why the | |
6646 | standards says that they have to be there. */ | |
6647 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6648 | ||
6649 | if (current_low != ((CORE_ADDR) -1)) | |
6650 | { | |
6651 | best_low = min (best_low, current_low); | |
6652 | best_high = max (best_high, current_high); | |
6653 | } | |
6654 | break; | |
6655 | default: | |
0963b4bd | 6656 | /* Ignore. */ |
fae299cd DC |
6657 | break; |
6658 | } | |
6659 | ||
6660 | child = sibling_die (child); | |
6661 | } | |
6662 | } | |
6663 | ||
6664 | *lowpc = best_low; | |
6665 | *highpc = best_high; | |
6666 | } | |
6667 | ||
801e3a5b JB |
6668 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
6669 | in DIE. */ | |
6670 | static void | |
6671 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
6672 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
6673 | { | |
bb5ed363 | 6674 | struct objfile *objfile = cu->objfile; |
801e3a5b JB |
6675 | struct attribute *attr; |
6676 | ||
6677 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
6678 | if (attr) | |
6679 | { | |
6680 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 6681 | |
801e3a5b JB |
6682 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
6683 | if (attr) | |
6684 | { | |
6685 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 6686 | |
801e3a5b JB |
6687 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
6688 | } | |
6689 | } | |
6690 | ||
6691 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
6692 | if (attr) | |
6693 | { | |
bb5ed363 | 6694 | bfd *obfd = objfile->obfd; |
801e3a5b JB |
6695 | |
6696 | /* The value of the DW_AT_ranges attribute is the offset of the | |
6697 | address range list in the .debug_ranges section. */ | |
6698 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 6699 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
6700 | |
6701 | /* For some target architectures, but not others, the | |
6702 | read_address function sign-extends the addresses it returns. | |
6703 | To recognize base address selection entries, we need a | |
6704 | mask. */ | |
6705 | unsigned int addr_size = cu->header.addr_size; | |
6706 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6707 | ||
6708 | /* The base address, to which the next pair is relative. Note | |
6709 | that this 'base' is a DWARF concept: most entries in a range | |
6710 | list are relative, to reduce the number of relocs against the | |
6711 | debugging information. This is separate from this function's | |
6712 | 'baseaddr' argument, which GDB uses to relocate debugging | |
6713 | information from a shared library based on the address at | |
6714 | which the library was loaded. */ | |
d00adf39 DE |
6715 | CORE_ADDR base = cu->base_address; |
6716 | int base_known = cu->base_known; | |
801e3a5b | 6717 | |
be391dca | 6718 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 6719 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
6720 | { |
6721 | complaint (&symfile_complaints, | |
6722 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
6723 | offset); | |
6724 | return; | |
6725 | } | |
6726 | ||
6727 | for (;;) | |
6728 | { | |
6729 | unsigned int bytes_read; | |
6730 | CORE_ADDR start, end; | |
6731 | ||
6732 | start = read_address (obfd, buffer, cu, &bytes_read); | |
6733 | buffer += bytes_read; | |
6734 | end = read_address (obfd, buffer, cu, &bytes_read); | |
6735 | buffer += bytes_read; | |
6736 | ||
6737 | /* Did we find the end of the range list? */ | |
6738 | if (start == 0 && end == 0) | |
6739 | break; | |
6740 | ||
6741 | /* Did we find a base address selection entry? */ | |
6742 | else if ((start & base_select_mask) == base_select_mask) | |
6743 | { | |
6744 | base = end; | |
6745 | base_known = 1; | |
6746 | } | |
6747 | ||
6748 | /* We found an ordinary address range. */ | |
6749 | else | |
6750 | { | |
6751 | if (!base_known) | |
6752 | { | |
6753 | complaint (&symfile_complaints, | |
3e43a32a MS |
6754 | _("Invalid .debug_ranges data " |
6755 | "(no base address)")); | |
801e3a5b JB |
6756 | return; |
6757 | } | |
6758 | ||
9277c30c UW |
6759 | if (start > end) |
6760 | { | |
6761 | /* Inverted range entries are invalid. */ | |
6762 | complaint (&symfile_complaints, | |
6763 | _("Invalid .debug_ranges data " | |
6764 | "(inverted range)")); | |
6765 | return; | |
6766 | } | |
6767 | ||
6768 | /* Empty range entries have no effect. */ | |
6769 | if (start == end) | |
6770 | continue; | |
6771 | ||
6e70227d DE |
6772 | record_block_range (block, |
6773 | baseaddr + base + start, | |
801e3a5b JB |
6774 | baseaddr + base + end - 1); |
6775 | } | |
6776 | } | |
6777 | } | |
6778 | } | |
6779 | ||
60d5a603 JK |
6780 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
6781 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
6782 | during 4.6.0 experimental. */ | |
6783 | ||
6784 | static int | |
6785 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
6786 | { | |
6787 | const char *cs; | |
6788 | int major, minor, release; | |
6789 | ||
6790 | if (cu->producer == NULL) | |
6791 | { | |
6792 | /* For unknown compilers expect their behavior is DWARF version | |
6793 | compliant. | |
6794 | ||
6795 | GCC started to support .debug_types sections by -gdwarf-4 since | |
6796 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
6797 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
6798 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
6799 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
6800 | ||
6801 | return 0; | |
6802 | } | |
6803 | ||
6804 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ | |
6805 | ||
6806 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
6807 | { | |
6808 | /* For non-GCC compilers expect their behavior is DWARF version | |
6809 | compliant. */ | |
6810 | ||
6811 | return 0; | |
6812 | } | |
6813 | cs = &cu->producer[strlen ("GNU ")]; | |
6814 | while (*cs && !isdigit (*cs)) | |
6815 | cs++; | |
6816 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
6817 | { | |
6818 | /* Not recognized as GCC. */ | |
6819 | ||
6820 | return 0; | |
6821 | } | |
6822 | ||
6823 | return major < 4 || (major == 4 && minor < 6); | |
6824 | } | |
6825 | ||
6826 | /* Return the default accessibility type if it is not overriden by | |
6827 | DW_AT_accessibility. */ | |
6828 | ||
6829 | static enum dwarf_access_attribute | |
6830 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
6831 | { | |
6832 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
6833 | { | |
6834 | /* The default DWARF 2 accessibility for members is public, the default | |
6835 | accessibility for inheritance is private. */ | |
6836 | ||
6837 | if (die->tag != DW_TAG_inheritance) | |
6838 | return DW_ACCESS_public; | |
6839 | else | |
6840 | return DW_ACCESS_private; | |
6841 | } | |
6842 | else | |
6843 | { | |
6844 | /* DWARF 3+ defines the default accessibility a different way. The same | |
6845 | rules apply now for DW_TAG_inheritance as for the members and it only | |
6846 | depends on the container kind. */ | |
6847 | ||
6848 | if (die->parent->tag == DW_TAG_class_type) | |
6849 | return DW_ACCESS_private; | |
6850 | else | |
6851 | return DW_ACCESS_public; | |
6852 | } | |
6853 | } | |
6854 | ||
74ac6d43 TT |
6855 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
6856 | offset. If the attribute was not found return 0, otherwise return | |
6857 | 1. If it was found but could not properly be handled, set *OFFSET | |
6858 | to 0. */ | |
6859 | ||
6860 | static int | |
6861 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
6862 | LONGEST *offset) | |
6863 | { | |
6864 | struct attribute *attr; | |
6865 | ||
6866 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
6867 | if (attr != NULL) | |
6868 | { | |
6869 | *offset = 0; | |
6870 | ||
6871 | /* Note that we do not check for a section offset first here. | |
6872 | This is because DW_AT_data_member_location is new in DWARF 4, | |
6873 | so if we see it, we can assume that a constant form is really | |
6874 | a constant and not a section offset. */ | |
6875 | if (attr_form_is_constant (attr)) | |
6876 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
6877 | else if (attr_form_is_section_offset (attr)) | |
6878 | dwarf2_complex_location_expr_complaint (); | |
6879 | else if (attr_form_is_block (attr)) | |
6880 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6881 | else | |
6882 | dwarf2_complex_location_expr_complaint (); | |
6883 | ||
6884 | return 1; | |
6885 | } | |
6886 | ||
6887 | return 0; | |
6888 | } | |
6889 | ||
c906108c SS |
6890 | /* Add an aggregate field to the field list. */ |
6891 | ||
6892 | static void | |
107d2387 | 6893 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6894 | struct dwarf2_cu *cu) |
6e70227d | 6895 | { |
e7c27a73 | 6896 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6897 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6898 | struct nextfield *new_field; |
6899 | struct attribute *attr; | |
6900 | struct field *fp; | |
6901 | char *fieldname = ""; | |
6902 | ||
6903 | /* Allocate a new field list entry and link it in. */ | |
6904 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6905 | make_cleanup (xfree, new_field); |
c906108c | 6906 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6907 | |
6908 | if (die->tag == DW_TAG_inheritance) | |
6909 | { | |
6910 | new_field->next = fip->baseclasses; | |
6911 | fip->baseclasses = new_field; | |
6912 | } | |
6913 | else | |
6914 | { | |
6915 | new_field->next = fip->fields; | |
6916 | fip->fields = new_field; | |
6917 | } | |
c906108c SS |
6918 | fip->nfields++; |
6919 | ||
e142c38c | 6920 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6921 | if (attr) |
6922 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
6923 | else |
6924 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
6925 | if (new_field->accessibility != DW_ACCESS_public) |
6926 | fip->non_public_fields = 1; | |
60d5a603 | 6927 | |
e142c38c | 6928 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6929 | if (attr) |
6930 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
6931 | else |
6932 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
6933 | |
6934 | fp = &new_field->field; | |
a9a9bd0f | 6935 | |
e142c38c | 6936 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6937 | { |
74ac6d43 TT |
6938 | LONGEST offset; |
6939 | ||
a9a9bd0f | 6940 | /* Data member other than a C++ static data member. */ |
6e70227d | 6941 | |
c906108c | 6942 | /* Get type of field. */ |
e7c27a73 | 6943 | fp->type = die_type (die, cu); |
c906108c | 6944 | |
d6a843b5 | 6945 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6946 | |
c906108c | 6947 | /* Get bit size of field (zero if none). */ |
e142c38c | 6948 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6949 | if (attr) |
6950 | { | |
6951 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6952 | } | |
6953 | else | |
6954 | { | |
6955 | FIELD_BITSIZE (*fp) = 0; | |
6956 | } | |
6957 | ||
6958 | /* Get bit offset of field. */ | |
74ac6d43 TT |
6959 | if (handle_data_member_location (die, cu, &offset)) |
6960 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 6961 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6962 | if (attr) |
6963 | { | |
5e2b427d | 6964 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6965 | { |
6966 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6967 | additional bit offset from the MSB of the containing |
6968 | anonymous object to the MSB of the field. We don't | |
6969 | have to do anything special since we don't need to | |
6970 | know the size of the anonymous object. */ | |
c906108c SS |
6971 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6972 | } | |
6973 | else | |
6974 | { | |
6975 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6976 | MSB of the anonymous object, subtract off the number of |
6977 | bits from the MSB of the field to the MSB of the | |
6978 | object, and then subtract off the number of bits of | |
6979 | the field itself. The result is the bit offset of | |
6980 | the LSB of the field. */ | |
c906108c SS |
6981 | int anonymous_size; |
6982 | int bit_offset = DW_UNSND (attr); | |
6983 | ||
e142c38c | 6984 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6985 | if (attr) |
6986 | { | |
6987 | /* The size of the anonymous object containing | |
6988 | the bit field is explicit, so use the | |
6989 | indicated size (in bytes). */ | |
6990 | anonymous_size = DW_UNSND (attr); | |
6991 | } | |
6992 | else | |
6993 | { | |
6994 | /* The size of the anonymous object containing | |
6995 | the bit field must be inferred from the type | |
6996 | attribute of the data member containing the | |
6997 | bit field. */ | |
6998 | anonymous_size = TYPE_LENGTH (fp->type); | |
6999 | } | |
7000 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
7001 | - bit_offset - FIELD_BITSIZE (*fp); | |
7002 | } | |
7003 | } | |
7004 | ||
7005 | /* Get name of field. */ | |
39cbfefa DJ |
7006 | fieldname = dwarf2_name (die, cu); |
7007 | if (fieldname == NULL) | |
7008 | fieldname = ""; | |
d8151005 DJ |
7009 | |
7010 | /* The name is already allocated along with this objfile, so we don't | |
7011 | need to duplicate it for the type. */ | |
7012 | fp->name = fieldname; | |
c906108c SS |
7013 | |
7014 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 7015 | pointer or virtual base class pointer) to private. */ |
e142c38c | 7016 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 7017 | { |
d48cc9dd | 7018 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
7019 | new_field->accessibility = DW_ACCESS_private; |
7020 | fip->non_public_fields = 1; | |
7021 | } | |
7022 | } | |
a9a9bd0f | 7023 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 7024 | { |
a9a9bd0f DC |
7025 | /* C++ static member. */ |
7026 | ||
7027 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
7028 | is a declaration, but all versions of G++ as of this writing | |
7029 | (so through at least 3.2.1) incorrectly generate | |
7030 | DW_TAG_variable tags. */ | |
6e70227d | 7031 | |
ff355380 | 7032 | const char *physname; |
c906108c | 7033 | |
a9a9bd0f | 7034 | /* Get name of field. */ |
39cbfefa DJ |
7035 | fieldname = dwarf2_name (die, cu); |
7036 | if (fieldname == NULL) | |
c906108c SS |
7037 | return; |
7038 | ||
254e6b9e | 7039 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
7040 | if (attr |
7041 | /* Only create a symbol if this is an external value. | |
7042 | new_symbol checks this and puts the value in the global symbol | |
7043 | table, which we want. If it is not external, new_symbol | |
7044 | will try to put the value in cu->list_in_scope which is wrong. */ | |
7045 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
7046 | { |
7047 | /* A static const member, not much different than an enum as far as | |
7048 | we're concerned, except that we can support more types. */ | |
7049 | new_symbol (die, NULL, cu); | |
7050 | } | |
7051 | ||
2df3850c | 7052 | /* Get physical name. */ |
ff355380 | 7053 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 7054 | |
d8151005 DJ |
7055 | /* The name is already allocated along with this objfile, so we don't |
7056 | need to duplicate it for the type. */ | |
7057 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 7058 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 7059 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
7060 | } |
7061 | else if (die->tag == DW_TAG_inheritance) | |
7062 | { | |
74ac6d43 | 7063 | LONGEST offset; |
d4b96c9a | 7064 | |
74ac6d43 TT |
7065 | /* C++ base class field. */ |
7066 | if (handle_data_member_location (die, cu, &offset)) | |
7067 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 7068 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 7069 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
7070 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
7071 | fip->nbaseclasses++; | |
7072 | } | |
7073 | } | |
7074 | ||
98751a41 JK |
7075 | /* Add a typedef defined in the scope of the FIP's class. */ |
7076 | ||
7077 | static void | |
7078 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
7079 | struct dwarf2_cu *cu) | |
6e70227d | 7080 | { |
98751a41 | 7081 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
7082 | struct typedef_field_list *new_field; |
7083 | struct attribute *attr; | |
7084 | struct typedef_field *fp; | |
7085 | char *fieldname = ""; | |
7086 | ||
7087 | /* Allocate a new field list entry and link it in. */ | |
7088 | new_field = xzalloc (sizeof (*new_field)); | |
7089 | make_cleanup (xfree, new_field); | |
7090 | ||
7091 | gdb_assert (die->tag == DW_TAG_typedef); | |
7092 | ||
7093 | fp = &new_field->field; | |
7094 | ||
7095 | /* Get name of field. */ | |
7096 | fp->name = dwarf2_name (die, cu); | |
7097 | if (fp->name == NULL) | |
7098 | return; | |
7099 | ||
7100 | fp->type = read_type_die (die, cu); | |
7101 | ||
7102 | new_field->next = fip->typedef_field_list; | |
7103 | fip->typedef_field_list = new_field; | |
7104 | fip->typedef_field_list_count++; | |
7105 | } | |
7106 | ||
c906108c SS |
7107 | /* Create the vector of fields, and attach it to the type. */ |
7108 | ||
7109 | static void | |
fba45db2 | 7110 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7111 | struct dwarf2_cu *cu) |
c906108c SS |
7112 | { |
7113 | int nfields = fip->nfields; | |
7114 | ||
7115 | /* Record the field count, allocate space for the array of fields, | |
7116 | and create blank accessibility bitfields if necessary. */ | |
7117 | TYPE_NFIELDS (type) = nfields; | |
7118 | TYPE_FIELDS (type) = (struct field *) | |
7119 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
7120 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
7121 | ||
b4ba55a1 | 7122 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
7123 | { |
7124 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7125 | ||
7126 | TYPE_FIELD_PRIVATE_BITS (type) = | |
7127 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7128 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
7129 | ||
7130 | TYPE_FIELD_PROTECTED_BITS (type) = | |
7131 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7132 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
7133 | ||
774b6a14 TT |
7134 | TYPE_FIELD_IGNORE_BITS (type) = |
7135 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7136 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
7137 | } |
7138 | ||
7139 | /* If the type has baseclasses, allocate and clear a bit vector for | |
7140 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 7141 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
7142 | { |
7143 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 7144 | unsigned char *pointer; |
c906108c SS |
7145 | |
7146 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
7147 | pointer = TYPE_ALLOC (type, num_bytes); |
7148 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
7149 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
7150 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
7151 | } | |
7152 | ||
3e43a32a MS |
7153 | /* Copy the saved-up fields into the field vector. Start from the head of |
7154 | the list, adding to the tail of the field array, so that they end up in | |
7155 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
7156 | while (nfields-- > 0) |
7157 | { | |
7d0ccb61 DJ |
7158 | struct nextfield *fieldp; |
7159 | ||
7160 | if (fip->fields) | |
7161 | { | |
7162 | fieldp = fip->fields; | |
7163 | fip->fields = fieldp->next; | |
7164 | } | |
7165 | else | |
7166 | { | |
7167 | fieldp = fip->baseclasses; | |
7168 | fip->baseclasses = fieldp->next; | |
7169 | } | |
7170 | ||
7171 | TYPE_FIELD (type, nfields) = fieldp->field; | |
7172 | switch (fieldp->accessibility) | |
c906108c | 7173 | { |
c5aa993b | 7174 | case DW_ACCESS_private: |
b4ba55a1 JB |
7175 | if (cu->language != language_ada) |
7176 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 7177 | break; |
c906108c | 7178 | |
c5aa993b | 7179 | case DW_ACCESS_protected: |
b4ba55a1 JB |
7180 | if (cu->language != language_ada) |
7181 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 7182 | break; |
c906108c | 7183 | |
c5aa993b JM |
7184 | case DW_ACCESS_public: |
7185 | break; | |
c906108c | 7186 | |
c5aa993b JM |
7187 | default: |
7188 | /* Unknown accessibility. Complain and treat it as public. */ | |
7189 | { | |
e2e0b3e5 | 7190 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 7191 | fieldp->accessibility); |
c5aa993b JM |
7192 | } |
7193 | break; | |
c906108c SS |
7194 | } |
7195 | if (nfields < fip->nbaseclasses) | |
7196 | { | |
7d0ccb61 | 7197 | switch (fieldp->virtuality) |
c906108c | 7198 | { |
c5aa993b JM |
7199 | case DW_VIRTUALITY_virtual: |
7200 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 7201 | if (cu->language == language_ada) |
a73c6dcd | 7202 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
7203 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
7204 | break; | |
c906108c SS |
7205 | } |
7206 | } | |
c906108c SS |
7207 | } |
7208 | } | |
7209 | ||
c906108c SS |
7210 | /* Add a member function to the proper fieldlist. */ |
7211 | ||
7212 | static void | |
107d2387 | 7213 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 7214 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 7215 | { |
e7c27a73 | 7216 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7217 | struct attribute *attr; |
7218 | struct fnfieldlist *flp; | |
7219 | int i; | |
7220 | struct fn_field *fnp; | |
7221 | char *fieldname; | |
c906108c | 7222 | struct nextfnfield *new_fnfield; |
f792889a | 7223 | struct type *this_type; |
60d5a603 | 7224 | enum dwarf_access_attribute accessibility; |
c906108c | 7225 | |
b4ba55a1 | 7226 | if (cu->language == language_ada) |
a73c6dcd | 7227 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 7228 | |
2df3850c | 7229 | /* Get name of member function. */ |
39cbfefa DJ |
7230 | fieldname = dwarf2_name (die, cu); |
7231 | if (fieldname == NULL) | |
2df3850c | 7232 | return; |
c906108c | 7233 | |
c906108c SS |
7234 | /* Look up member function name in fieldlist. */ |
7235 | for (i = 0; i < fip->nfnfields; i++) | |
7236 | { | |
27bfe10e | 7237 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
7238 | break; |
7239 | } | |
7240 | ||
7241 | /* Create new list element if necessary. */ | |
7242 | if (i < fip->nfnfields) | |
7243 | flp = &fip->fnfieldlists[i]; | |
7244 | else | |
7245 | { | |
7246 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7247 | { | |
7248 | fip->fnfieldlists = (struct fnfieldlist *) | |
7249 | xrealloc (fip->fnfieldlists, | |
7250 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7251 | * sizeof (struct fnfieldlist)); |
c906108c | 7252 | if (fip->nfnfields == 0) |
c13c43fd | 7253 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
7254 | } |
7255 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
7256 | flp->name = fieldname; | |
7257 | flp->length = 0; | |
7258 | flp->head = NULL; | |
3da10d80 | 7259 | i = fip->nfnfields++; |
c906108c SS |
7260 | } |
7261 | ||
7262 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 7263 | entry. */ |
c906108c | 7264 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 7265 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
7266 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
7267 | new_fnfield->next = flp->head; | |
7268 | flp->head = new_fnfield; | |
7269 | flp->length++; | |
7270 | ||
7271 | /* Fill in the member function field info. */ | |
7272 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
7273 | |
7274 | /* Delay processing of the physname until later. */ | |
7275 | if (cu->language == language_cplus || cu->language == language_java) | |
7276 | { | |
7277 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
7278 | die, cu); | |
7279 | } | |
7280 | else | |
7281 | { | |
1d06ead6 | 7282 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
7283 | fnp->physname = physname ? physname : ""; |
7284 | } | |
7285 | ||
c906108c | 7286 | fnp->type = alloc_type (objfile); |
f792889a DJ |
7287 | this_type = read_type_die (die, cu); |
7288 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 7289 | { |
f792889a | 7290 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 7291 | |
f792889a | 7292 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
7293 | of the method itself (TYPE_CODE_METHOD). */ |
7294 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
7295 | TYPE_TARGET_TYPE (this_type), |
7296 | TYPE_FIELDS (this_type), | |
7297 | TYPE_NFIELDS (this_type), | |
7298 | TYPE_VARARGS (this_type)); | |
c906108c SS |
7299 | |
7300 | /* Handle static member functions. | |
c5aa993b | 7301 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
7302 | member functions. G++ helps GDB by marking the first |
7303 | parameter for non-static member functions (which is the this | |
7304 | pointer) as artificial. We obtain this information from | |
7305 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 7306 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
7307 | fnp->voffset = VOFFSET_STATIC; |
7308 | } | |
7309 | else | |
e2e0b3e5 | 7310 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 7311 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
7312 | |
7313 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 7314 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 7315 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 7316 | |
3e43a32a MS |
7317 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
7318 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
7319 | |
7320 | /* Get accessibility. */ | |
e142c38c | 7321 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 7322 | if (attr) |
60d5a603 JK |
7323 | accessibility = DW_UNSND (attr); |
7324 | else | |
7325 | accessibility = dwarf2_default_access_attribute (die, cu); | |
7326 | switch (accessibility) | |
c906108c | 7327 | { |
60d5a603 JK |
7328 | case DW_ACCESS_private: |
7329 | fnp->is_private = 1; | |
7330 | break; | |
7331 | case DW_ACCESS_protected: | |
7332 | fnp->is_protected = 1; | |
7333 | break; | |
c906108c SS |
7334 | } |
7335 | ||
b02dede2 | 7336 | /* Check for artificial methods. */ |
e142c38c | 7337 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
7338 | if (attr && DW_UNSND (attr) != 0) |
7339 | fnp->is_artificial = 1; | |
7340 | ||
0d564a31 | 7341 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
7342 | function. For older versions of GCC, this is an offset in the |
7343 | appropriate virtual table, as specified by DW_AT_containing_type. | |
7344 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
7345 | to the object address. */ |
7346 | ||
e142c38c | 7347 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 7348 | if (attr) |
8e19ed76 | 7349 | { |
aec5aa8b | 7350 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 7351 | { |
aec5aa8b TT |
7352 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
7353 | { | |
7354 | /* Old-style GCC. */ | |
7355 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
7356 | } | |
7357 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7358 | || (DW_BLOCK (attr)->size > 1 | |
7359 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
7360 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
7361 | { | |
7362 | struct dwarf_block blk; | |
7363 | int offset; | |
7364 | ||
7365 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7366 | ? 1 : 2); | |
7367 | blk.size = DW_BLOCK (attr)->size - offset; | |
7368 | blk.data = DW_BLOCK (attr)->data + offset; | |
7369 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
7370 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
7371 | dwarf2_complex_location_expr_complaint (); | |
7372 | else | |
7373 | fnp->voffset /= cu->header.addr_size; | |
7374 | fnp->voffset += 2; | |
7375 | } | |
7376 | else | |
7377 | dwarf2_complex_location_expr_complaint (); | |
7378 | ||
7379 | if (!fnp->fcontext) | |
7380 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
7381 | } | |
3690dd37 | 7382 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7383 | { |
4d3c2250 | 7384 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7385 | } |
7386 | else | |
7387 | { | |
4d3c2250 KB |
7388 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
7389 | fieldname); | |
8e19ed76 | 7390 | } |
0d564a31 | 7391 | } |
d48cc9dd DJ |
7392 | else |
7393 | { | |
7394 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
7395 | if (attr && DW_UNSND (attr)) | |
7396 | { | |
7397 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
7398 | complaint (&symfile_complaints, | |
3e43a32a MS |
7399 | _("Member function \"%s\" (offset %d) is virtual " |
7400 | "but the vtable offset is not specified"), | |
d48cc9dd | 7401 | fieldname, die->offset); |
9655fd1a | 7402 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
7403 | TYPE_CPLUS_DYNAMIC (type) = 1; |
7404 | } | |
7405 | } | |
c906108c SS |
7406 | } |
7407 | ||
7408 | /* Create the vector of member function fields, and attach it to the type. */ | |
7409 | ||
7410 | static void | |
fba45db2 | 7411 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7412 | struct dwarf2_cu *cu) |
c906108c SS |
7413 | { |
7414 | struct fnfieldlist *flp; | |
c906108c SS |
7415 | int i; |
7416 | ||
b4ba55a1 | 7417 | if (cu->language == language_ada) |
a73c6dcd | 7418 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 7419 | |
c906108c SS |
7420 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
7421 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
7422 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
7423 | ||
7424 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
7425 | { | |
7426 | struct nextfnfield *nfp = flp->head; | |
7427 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
7428 | int k; | |
7429 | ||
7430 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
7431 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
7432 | fn_flp->fn_fields = (struct fn_field *) | |
7433 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
7434 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 7435 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
7436 | } |
7437 | ||
7438 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
7439 | } |
7440 | ||
1168df01 JB |
7441 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
7442 | language, zero otherwise. */ | |
7443 | static int | |
7444 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
7445 | { | |
7446 | static const char vptr[] = "_vptr"; | |
987504bb | 7447 | static const char vtable[] = "vtable"; |
1168df01 | 7448 | |
987504bb JJ |
7449 | /* Look for the C++ and Java forms of the vtable. */ |
7450 | if ((cu->language == language_java | |
7451 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
7452 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
7453 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
7454 | return 1; |
7455 | ||
7456 | return 0; | |
7457 | } | |
7458 | ||
c0dd20ea | 7459 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
7460 | functions, with the ABI-specified layout. If TYPE describes |
7461 | such a structure, smash it into a member function type. | |
61049d3b DJ |
7462 | |
7463 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
7464 | This is GCC PR debug/28767. */ | |
c0dd20ea | 7465 | |
0b92b5bb TT |
7466 | static void |
7467 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 7468 | { |
0b92b5bb | 7469 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
7470 | |
7471 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
7472 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
7473 | return; | |
c0dd20ea DJ |
7474 | |
7475 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
7476 | if (TYPE_FIELD_NAME (type, 0) == NULL |
7477 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
7478 | || TYPE_FIELD_NAME (type, 1) == NULL | |
7479 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
7480 | return; | |
c0dd20ea DJ |
7481 | |
7482 | /* Find the type of the method. */ | |
0b92b5bb | 7483 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
7484 | if (pfn_type == NULL |
7485 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
7486 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 7487 | return; |
c0dd20ea DJ |
7488 | |
7489 | /* Look for the "this" argument. */ | |
7490 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
7491 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 7492 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 7493 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 7494 | return; |
c0dd20ea DJ |
7495 | |
7496 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
7497 | new_type = alloc_type (objfile); |
7498 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
7499 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
7500 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 7501 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 7502 | } |
1168df01 | 7503 | |
c906108c | 7504 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
7505 | (definition) to create a type for the structure or union. Fill in |
7506 | the type's name and general properties; the members will not be | |
7507 | processed until process_structure_type. | |
c906108c | 7508 | |
c767944b DJ |
7509 | NOTE: we need to call these functions regardless of whether or not the |
7510 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
7511 | structure or union. This gets the type entered into our set of |
7512 | user defined types. | |
7513 | ||
7514 | However, if the structure is incomplete (an opaque struct/union) | |
7515 | then suppress creating a symbol table entry for it since gdb only | |
7516 | wants to find the one with the complete definition. Note that if | |
7517 | it is complete, we just call new_symbol, which does it's own | |
7518 | checking about whether the struct/union is anonymous or not (and | |
7519 | suppresses creating a symbol table entry itself). */ | |
7520 | ||
f792889a | 7521 | static struct type * |
134d01f1 | 7522 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7523 | { |
e7c27a73 | 7524 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7525 | struct type *type; |
7526 | struct attribute *attr; | |
39cbfefa | 7527 | char *name; |
c906108c | 7528 | |
348e048f DE |
7529 | /* If the definition of this type lives in .debug_types, read that type. |
7530 | Don't follow DW_AT_specification though, that will take us back up | |
7531 | the chain and we want to go down. */ | |
7532 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7533 | if (attr) | |
7534 | { | |
7535 | struct dwarf2_cu *type_cu = cu; | |
7536 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7537 | |
348e048f DE |
7538 | /* We could just recurse on read_structure_type, but we need to call |
7539 | get_die_type to ensure only one type for this DIE is created. | |
7540 | This is important, for example, because for c++ classes we need | |
7541 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
7542 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
7543 | |
7544 | /* TYPE_CU may not be the same as CU. | |
7545 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7546 | return set_die_type (die, type, cu); |
7547 | } | |
7548 | ||
c0dd20ea | 7549 | type = alloc_type (objfile); |
c906108c | 7550 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 7551 | |
39cbfefa DJ |
7552 | name = dwarf2_name (die, cu); |
7553 | if (name != NULL) | |
c906108c | 7554 | { |
987504bb JJ |
7555 | if (cu->language == language_cplus |
7556 | || cu->language == language_java) | |
63d06c5c | 7557 | { |
3da10d80 KS |
7558 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
7559 | ||
7560 | /* dwarf2_full_name might have already finished building the DIE's | |
7561 | type. If so, there is no need to continue. */ | |
7562 | if (get_die_type (die, cu) != NULL) | |
7563 | return get_die_type (die, cu); | |
7564 | ||
7565 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
7566 | if (die->tag == DW_TAG_structure_type |
7567 | || die->tag == DW_TAG_class_type) | |
7568 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
7569 | } |
7570 | else | |
7571 | { | |
d8151005 DJ |
7572 | /* The name is already allocated along with this objfile, so |
7573 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
7574 | TYPE_TAG_NAME (type) = (char *) name; |
7575 | if (die->tag == DW_TAG_class_type) | |
7576 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 7577 | } |
c906108c SS |
7578 | } |
7579 | ||
7580 | if (die->tag == DW_TAG_structure_type) | |
7581 | { | |
7582 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
7583 | } | |
7584 | else if (die->tag == DW_TAG_union_type) | |
7585 | { | |
7586 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
7587 | } | |
7588 | else | |
7589 | { | |
c906108c SS |
7590 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
7591 | } | |
7592 | ||
0cc2414c TT |
7593 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
7594 | TYPE_DECLARED_CLASS (type) = 1; | |
7595 | ||
e142c38c | 7596 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7597 | if (attr) |
7598 | { | |
7599 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7600 | } | |
7601 | else | |
7602 | { | |
7603 | TYPE_LENGTH (type) = 0; | |
7604 | } | |
7605 | ||
876cecd0 | 7606 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 7607 | if (die_is_declaration (die, cu)) |
876cecd0 | 7608 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
7609 | else if (attr == NULL && die->child == NULL |
7610 | && producer_is_realview (cu->producer)) | |
7611 | /* RealView does not output the required DW_AT_declaration | |
7612 | on incomplete types. */ | |
7613 | TYPE_STUB (type) = 1; | |
dc718098 | 7614 | |
c906108c SS |
7615 | /* We need to add the type field to the die immediately so we don't |
7616 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 7617 | type within the structure itself. */ |
1c379e20 | 7618 | set_die_type (die, type, cu); |
c906108c | 7619 | |
7e314c57 JK |
7620 | /* set_die_type should be already done. */ |
7621 | set_descriptive_type (type, die, cu); | |
7622 | ||
c767944b DJ |
7623 | return type; |
7624 | } | |
7625 | ||
7626 | /* Finish creating a structure or union type, including filling in | |
7627 | its members and creating a symbol for it. */ | |
7628 | ||
7629 | static void | |
7630 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7631 | { | |
7632 | struct objfile *objfile = cu->objfile; | |
7633 | struct die_info *child_die = die->child; | |
7634 | struct type *type; | |
7635 | ||
7636 | type = get_die_type (die, cu); | |
7637 | if (type == NULL) | |
7638 | type = read_structure_type (die, cu); | |
7639 | ||
e142c38c | 7640 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
7641 | { |
7642 | struct field_info fi; | |
7643 | struct die_info *child_die; | |
34eaf542 | 7644 | VEC (symbolp) *template_args = NULL; |
c767944b | 7645 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
7646 | |
7647 | memset (&fi, 0, sizeof (struct field_info)); | |
7648 | ||
639d11d3 | 7649 | child_die = die->child; |
c906108c SS |
7650 | |
7651 | while (child_die && child_die->tag) | |
7652 | { | |
a9a9bd0f DC |
7653 | if (child_die->tag == DW_TAG_member |
7654 | || child_die->tag == DW_TAG_variable) | |
c906108c | 7655 | { |
a9a9bd0f DC |
7656 | /* NOTE: carlton/2002-11-05: A C++ static data member |
7657 | should be a DW_TAG_member that is a declaration, but | |
7658 | all versions of G++ as of this writing (so through at | |
7659 | least 3.2.1) incorrectly generate DW_TAG_variable | |
7660 | tags for them instead. */ | |
e7c27a73 | 7661 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7662 | } |
8713b1b1 | 7663 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 7664 | { |
0963b4bd | 7665 | /* C++ member function. */ |
e7c27a73 | 7666 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
7667 | } |
7668 | else if (child_die->tag == DW_TAG_inheritance) | |
7669 | { | |
7670 | /* C++ base class field. */ | |
e7c27a73 | 7671 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7672 | } |
98751a41 JK |
7673 | else if (child_die->tag == DW_TAG_typedef) |
7674 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
7675 | else if (child_die->tag == DW_TAG_template_type_param |
7676 | || child_die->tag == DW_TAG_template_value_param) | |
7677 | { | |
7678 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7679 | ||
f1078f66 DJ |
7680 | if (arg != NULL) |
7681 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7682 | } |
7683 | ||
c906108c SS |
7684 | child_die = sibling_die (child_die); |
7685 | } | |
7686 | ||
34eaf542 TT |
7687 | /* Attach template arguments to type. */ |
7688 | if (! VEC_empty (symbolp, template_args)) | |
7689 | { | |
7690 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7691 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7692 | = VEC_length (symbolp, template_args); | |
7693 | TYPE_TEMPLATE_ARGUMENTS (type) | |
7694 | = obstack_alloc (&objfile->objfile_obstack, | |
7695 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7696 | * sizeof (struct symbol *))); | |
7697 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
7698 | VEC_address (symbolp, template_args), | |
7699 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7700 | * sizeof (struct symbol *))); | |
7701 | VEC_free (symbolp, template_args); | |
7702 | } | |
7703 | ||
c906108c SS |
7704 | /* Attach fields and member functions to the type. */ |
7705 | if (fi.nfields) | |
e7c27a73 | 7706 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
7707 | if (fi.nfnfields) |
7708 | { | |
e7c27a73 | 7709 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 7710 | |
c5aa993b | 7711 | /* Get the type which refers to the base class (possibly this |
c906108c | 7712 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
7713 | class from the DW_AT_containing_type attribute. This use of |
7714 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 7715 | |
e142c38c | 7716 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 7717 | { |
e7c27a73 | 7718 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
7719 | |
7720 | TYPE_VPTR_BASETYPE (type) = t; | |
7721 | if (type == t) | |
7722 | { | |
c906108c SS |
7723 | int i; |
7724 | ||
7725 | /* Our own class provides vtbl ptr. */ | |
7726 | for (i = TYPE_NFIELDS (t) - 1; | |
7727 | i >= TYPE_N_BASECLASSES (t); | |
7728 | --i) | |
7729 | { | |
7730 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
7731 | ||
1168df01 | 7732 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
7733 | { |
7734 | TYPE_VPTR_FIELDNO (type) = i; | |
7735 | break; | |
7736 | } | |
7737 | } | |
7738 | ||
7739 | /* Complain if virtual function table field not found. */ | |
7740 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 7741 | complaint (&symfile_complaints, |
3e43a32a MS |
7742 | _("virtual function table pointer " |
7743 | "not found when defining class '%s'"), | |
4d3c2250 KB |
7744 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
7745 | ""); | |
c906108c SS |
7746 | } |
7747 | else | |
7748 | { | |
7749 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
7750 | } | |
7751 | } | |
f6235d4c EZ |
7752 | else if (cu->producer |
7753 | && strncmp (cu->producer, | |
7754 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
7755 | { | |
7756 | /* The IBM XLC compiler does not provide direct indication | |
7757 | of the containing type, but the vtable pointer is | |
7758 | always named __vfp. */ | |
7759 | ||
7760 | int i; | |
7761 | ||
7762 | for (i = TYPE_NFIELDS (type) - 1; | |
7763 | i >= TYPE_N_BASECLASSES (type); | |
7764 | --i) | |
7765 | { | |
7766 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
7767 | { | |
7768 | TYPE_VPTR_FIELDNO (type) = i; | |
7769 | TYPE_VPTR_BASETYPE (type) = type; | |
7770 | break; | |
7771 | } | |
7772 | } | |
7773 | } | |
c906108c | 7774 | } |
98751a41 JK |
7775 | |
7776 | /* Copy fi.typedef_field_list linked list elements content into the | |
7777 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
7778 | if (fi.typedef_field_list) | |
7779 | { | |
7780 | int i = fi.typedef_field_list_count; | |
7781 | ||
a0d7a4ff | 7782 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
7783 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
7784 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
7785 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
7786 | ||
7787 | /* Reverse the list order to keep the debug info elements order. */ | |
7788 | while (--i >= 0) | |
7789 | { | |
7790 | struct typedef_field *dest, *src; | |
6e70227d | 7791 | |
98751a41 JK |
7792 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
7793 | src = &fi.typedef_field_list->field; | |
7794 | fi.typedef_field_list = fi.typedef_field_list->next; | |
7795 | *dest = *src; | |
7796 | } | |
7797 | } | |
c767944b DJ |
7798 | |
7799 | do_cleanups (back_to); | |
eb2a6f42 TT |
7800 | |
7801 | if (HAVE_CPLUS_STRUCT (type)) | |
7802 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 7803 | } |
63d06c5c | 7804 | |
bb5ed363 | 7805 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 7806 | |
90aeadfc DC |
7807 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
7808 | snapshots) has been known to create a die giving a declaration | |
7809 | for a class that has, as a child, a die giving a definition for a | |
7810 | nested class. So we have to process our children even if the | |
7811 | current die is a declaration. Normally, of course, a declaration | |
7812 | won't have any children at all. */ | |
134d01f1 | 7813 | |
90aeadfc DC |
7814 | while (child_die != NULL && child_die->tag) |
7815 | { | |
7816 | if (child_die->tag == DW_TAG_member | |
7817 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
7818 | || child_die->tag == DW_TAG_inheritance |
7819 | || child_die->tag == DW_TAG_template_value_param | |
7820 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 7821 | { |
90aeadfc | 7822 | /* Do nothing. */ |
134d01f1 | 7823 | } |
90aeadfc DC |
7824 | else |
7825 | process_die (child_die, cu); | |
134d01f1 | 7826 | |
90aeadfc | 7827 | child_die = sibling_die (child_die); |
134d01f1 DJ |
7828 | } |
7829 | ||
fa4028e9 JB |
7830 | /* Do not consider external references. According to the DWARF standard, |
7831 | these DIEs are identified by the fact that they have no byte_size | |
7832 | attribute, and a declaration attribute. */ | |
7833 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
7834 | || !die_is_declaration (die, cu)) | |
c767944b | 7835 | new_symbol (die, type, cu); |
134d01f1 DJ |
7836 | } |
7837 | ||
7838 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
7839 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 7840 | |
f792889a | 7841 | static struct type * |
134d01f1 | 7842 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7843 | { |
e7c27a73 | 7844 | struct objfile *objfile = cu->objfile; |
c906108c | 7845 | struct type *type; |
c906108c | 7846 | struct attribute *attr; |
0114d602 | 7847 | const char *name; |
134d01f1 | 7848 | |
348e048f DE |
7849 | /* If the definition of this type lives in .debug_types, read that type. |
7850 | Don't follow DW_AT_specification though, that will take us back up | |
7851 | the chain and we want to go down. */ | |
7852 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7853 | if (attr) | |
7854 | { | |
7855 | struct dwarf2_cu *type_cu = cu; | |
7856 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7857 | |
348e048f | 7858 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7859 | |
7860 | /* TYPE_CU may not be the same as CU. | |
7861 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7862 | return set_die_type (die, type, cu); |
7863 | } | |
7864 | ||
c906108c SS |
7865 | type = alloc_type (objfile); |
7866 | ||
7867 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7868 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7869 | if (name != NULL) |
0114d602 | 7870 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7871 | |
e142c38c | 7872 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7873 | if (attr) |
7874 | { | |
7875 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7876 | } | |
7877 | else | |
7878 | { | |
7879 | TYPE_LENGTH (type) = 0; | |
7880 | } | |
7881 | ||
137033e9 JB |
7882 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7883 | declared as private in the package spec, and then defined only | |
7884 | inside the package body. Such types are known as Taft Amendment | |
7885 | Types. When another package uses such a type, an incomplete DIE | |
7886 | may be generated by the compiler. */ | |
02eb380e | 7887 | if (die_is_declaration (die, cu)) |
876cecd0 | 7888 | TYPE_STUB (type) = 1; |
02eb380e | 7889 | |
f792889a | 7890 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7891 | } |
7892 | ||
7893 | /* Given a pointer to a die which begins an enumeration, process all | |
7894 | the dies that define the members of the enumeration, and create the | |
7895 | symbol for the enumeration type. | |
7896 | ||
7897 | NOTE: We reverse the order of the element list. */ | |
7898 | ||
7899 | static void | |
7900 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7901 | { | |
f792889a | 7902 | struct type *this_type; |
134d01f1 | 7903 | |
f792889a DJ |
7904 | this_type = get_die_type (die, cu); |
7905 | if (this_type == NULL) | |
7906 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7907 | |
639d11d3 | 7908 | if (die->child != NULL) |
c906108c | 7909 | { |
9dc481d3 DE |
7910 | struct die_info *child_die; |
7911 | struct symbol *sym; | |
7912 | struct field *fields = NULL; | |
7913 | int num_fields = 0; | |
7914 | int unsigned_enum = 1; | |
7915 | char *name; | |
7916 | ||
639d11d3 | 7917 | child_die = die->child; |
c906108c SS |
7918 | while (child_die && child_die->tag) |
7919 | { | |
7920 | if (child_die->tag != DW_TAG_enumerator) | |
7921 | { | |
e7c27a73 | 7922 | process_die (child_die, cu); |
c906108c SS |
7923 | } |
7924 | else | |
7925 | { | |
39cbfefa DJ |
7926 | name = dwarf2_name (child_die, cu); |
7927 | if (name) | |
c906108c | 7928 | { |
f792889a | 7929 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7930 | if (SYMBOL_VALUE (sym) < 0) |
7931 | unsigned_enum = 0; | |
7932 | ||
7933 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7934 | { | |
7935 | fields = (struct field *) | |
7936 | xrealloc (fields, | |
7937 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7938 | * sizeof (struct field)); |
c906108c SS |
7939 | } |
7940 | ||
3567439c | 7941 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7942 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7943 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7944 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7945 | ||
7946 | num_fields++; | |
7947 | } | |
7948 | } | |
7949 | ||
7950 | child_die = sibling_die (child_die); | |
7951 | } | |
7952 | ||
7953 | if (num_fields) | |
7954 | { | |
f792889a DJ |
7955 | TYPE_NFIELDS (this_type) = num_fields; |
7956 | TYPE_FIELDS (this_type) = (struct field *) | |
7957 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7958 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7959 | sizeof (struct field) * num_fields); |
b8c9b27d | 7960 | xfree (fields); |
c906108c SS |
7961 | } |
7962 | if (unsigned_enum) | |
876cecd0 | 7963 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7964 | } |
134d01f1 | 7965 | |
6c83ed52 TT |
7966 | /* If we are reading an enum from a .debug_types unit, and the enum |
7967 | is a declaration, and the enum is not the signatured type in the | |
7968 | unit, then we do not want to add a symbol for it. Adding a | |
7969 | symbol would in some cases obscure the true definition of the | |
7970 | enum, giving users an incomplete type when the definition is | |
7971 | actually available. Note that we do not want to do this for all | |
7972 | enums which are just declarations, because C++0x allows forward | |
7973 | enum declarations. */ | |
b0df02fd | 7974 | if (cu->per_cu->debug_types_section |
6c83ed52 TT |
7975 | && die_is_declaration (die, cu)) |
7976 | { | |
7977 | struct signatured_type *type_sig; | |
7978 | ||
7979 | type_sig | |
7980 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, | |
b0df02fd | 7981 | cu->per_cu->debug_types_section, |
6c83ed52 TT |
7982 | cu->per_cu->offset); |
7983 | if (type_sig->type_offset != die->offset) | |
7984 | return; | |
7985 | } | |
7986 | ||
f792889a | 7987 | new_symbol (die, this_type, cu); |
c906108c SS |
7988 | } |
7989 | ||
7990 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
7991 | the DIE's type field. For now, this only handles one dimensional | |
7992 | arrays. */ | |
7993 | ||
f792889a | 7994 | static struct type * |
e7c27a73 | 7995 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7996 | { |
e7c27a73 | 7997 | struct objfile *objfile = cu->objfile; |
c906108c | 7998 | struct die_info *child_die; |
7e314c57 | 7999 | struct type *type; |
c906108c SS |
8000 | struct type *element_type, *range_type, *index_type; |
8001 | struct type **range_types = NULL; | |
8002 | struct attribute *attr; | |
8003 | int ndim = 0; | |
8004 | struct cleanup *back_to; | |
39cbfefa | 8005 | char *name; |
c906108c | 8006 | |
e7c27a73 | 8007 | element_type = die_type (die, cu); |
c906108c | 8008 | |
7e314c57 JK |
8009 | /* The die_type call above may have already set the type for this DIE. */ |
8010 | type = get_die_type (die, cu); | |
8011 | if (type) | |
8012 | return type; | |
8013 | ||
c906108c SS |
8014 | /* Irix 6.2 native cc creates array types without children for |
8015 | arrays with unspecified length. */ | |
639d11d3 | 8016 | if (die->child == NULL) |
c906108c | 8017 | { |
46bf5051 | 8018 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8019 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
8020 | type = create_array_type (NULL, element_type, range_type); |
8021 | return set_die_type (die, type, cu); | |
c906108c SS |
8022 | } |
8023 | ||
8024 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 8025 | child_die = die->child; |
c906108c SS |
8026 | while (child_die && child_die->tag) |
8027 | { | |
8028 | if (child_die->tag == DW_TAG_subrange_type) | |
8029 | { | |
f792889a | 8030 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 8031 | |
f792889a | 8032 | if (child_type != NULL) |
a02abb62 | 8033 | { |
0963b4bd MS |
8034 | /* The range type was succesfully read. Save it for the |
8035 | array type creation. */ | |
a02abb62 JB |
8036 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
8037 | { | |
8038 | range_types = (struct type **) | |
8039 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
8040 | * sizeof (struct type *)); | |
8041 | if (ndim == 0) | |
8042 | make_cleanup (free_current_contents, &range_types); | |
8043 | } | |
f792889a | 8044 | range_types[ndim++] = child_type; |
a02abb62 | 8045 | } |
c906108c SS |
8046 | } |
8047 | child_die = sibling_die (child_die); | |
8048 | } | |
8049 | ||
8050 | /* Dwarf2 dimensions are output from left to right, create the | |
8051 | necessary array types in backwards order. */ | |
7ca2d3a3 | 8052 | |
c906108c | 8053 | type = element_type; |
7ca2d3a3 DL |
8054 | |
8055 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
8056 | { | |
8057 | int i = 0; | |
9a619af0 | 8058 | |
7ca2d3a3 DL |
8059 | while (i < ndim) |
8060 | type = create_array_type (NULL, type, range_types[i++]); | |
8061 | } | |
8062 | else | |
8063 | { | |
8064 | while (ndim-- > 0) | |
8065 | type = create_array_type (NULL, type, range_types[ndim]); | |
8066 | } | |
c906108c | 8067 | |
f5f8a009 EZ |
8068 | /* Understand Dwarf2 support for vector types (like they occur on |
8069 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
8070 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
8071 | custom vendor extension. The main difference between a regular | |
8072 | array and the vector variant is that vectors are passed by value | |
8073 | to functions. */ | |
e142c38c | 8074 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 8075 | if (attr) |
ea37ba09 | 8076 | make_vector_type (type); |
f5f8a009 | 8077 | |
dbc98a8b KW |
8078 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
8079 | implementation may choose to implement triple vectors using this | |
8080 | attribute. */ | |
8081 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
8082 | if (attr) | |
8083 | { | |
8084 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
8085 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8086 | else | |
3e43a32a MS |
8087 | complaint (&symfile_complaints, |
8088 | _("DW_AT_byte_size for array type smaller " | |
8089 | "than the total size of elements")); | |
dbc98a8b KW |
8090 | } |
8091 | ||
39cbfefa DJ |
8092 | name = dwarf2_name (die, cu); |
8093 | if (name) | |
8094 | TYPE_NAME (type) = name; | |
6e70227d | 8095 | |
0963b4bd | 8096 | /* Install the type in the die. */ |
7e314c57 JK |
8097 | set_die_type (die, type, cu); |
8098 | ||
8099 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8100 | set_descriptive_type (type, die, cu); |
8101 | ||
c906108c SS |
8102 | do_cleanups (back_to); |
8103 | ||
7e314c57 | 8104 | return type; |
c906108c SS |
8105 | } |
8106 | ||
7ca2d3a3 | 8107 | static enum dwarf_array_dim_ordering |
6e70227d | 8108 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
8109 | { |
8110 | struct attribute *attr; | |
8111 | ||
8112 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
8113 | ||
8114 | if (attr) return DW_SND (attr); | |
8115 | ||
0963b4bd MS |
8116 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
8117 | opposite order to the dwarf2 specification, but data is still | |
8118 | laid out as per normal fortran. | |
7ca2d3a3 | 8119 | |
0963b4bd MS |
8120 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
8121 | version checking. */ | |
7ca2d3a3 | 8122 | |
905e0470 PM |
8123 | if (cu->language == language_fortran |
8124 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
8125 | { |
8126 | return DW_ORD_row_major; | |
8127 | } | |
8128 | ||
6e70227d | 8129 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
8130 | { |
8131 | case array_column_major: | |
8132 | return DW_ORD_col_major; | |
8133 | case array_row_major: | |
8134 | default: | |
8135 | return DW_ORD_row_major; | |
8136 | }; | |
8137 | } | |
8138 | ||
72019c9c | 8139 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 8140 | the DIE's type field. */ |
72019c9c | 8141 | |
f792889a | 8142 | static struct type * |
72019c9c GM |
8143 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
8144 | { | |
7e314c57 JK |
8145 | struct type *domain_type, *set_type; |
8146 | struct attribute *attr; | |
f792889a | 8147 | |
7e314c57 JK |
8148 | domain_type = die_type (die, cu); |
8149 | ||
8150 | /* The die_type call above may have already set the type for this DIE. */ | |
8151 | set_type = get_die_type (die, cu); | |
8152 | if (set_type) | |
8153 | return set_type; | |
8154 | ||
8155 | set_type = create_set_type (NULL, domain_type); | |
8156 | ||
8157 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
8158 | if (attr) |
8159 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 8160 | |
f792889a | 8161 | return set_die_type (die, set_type, cu); |
72019c9c | 8162 | } |
7ca2d3a3 | 8163 | |
c906108c SS |
8164 | /* First cut: install each common block member as a global variable. */ |
8165 | ||
8166 | static void | |
e7c27a73 | 8167 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8168 | { |
8169 | struct die_info *child_die; | |
8170 | struct attribute *attr; | |
8171 | struct symbol *sym; | |
8172 | CORE_ADDR base = (CORE_ADDR) 0; | |
8173 | ||
e142c38c | 8174 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8175 | if (attr) |
8176 | { | |
0963b4bd | 8177 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
8178 | if (attr_form_is_block (attr)) |
8179 | { | |
e7c27a73 | 8180 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 8181 | } |
3690dd37 | 8182 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 8183 | { |
4d3c2250 | 8184 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8185 | } |
8186 | else | |
8187 | { | |
4d3c2250 KB |
8188 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8189 | "common block member"); | |
8e19ed76 | 8190 | } |
c906108c | 8191 | } |
639d11d3 | 8192 | if (die->child != NULL) |
c906108c | 8193 | { |
639d11d3 | 8194 | child_die = die->child; |
c906108c SS |
8195 | while (child_die && child_die->tag) |
8196 | { | |
74ac6d43 TT |
8197 | LONGEST offset; |
8198 | ||
e7c27a73 | 8199 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
8200 | if (sym != NULL |
8201 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 8202 | { |
74ac6d43 | 8203 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
8204 | add_symbol_to_list (sym, &global_symbols); |
8205 | } | |
8206 | child_die = sibling_die (child_die); | |
8207 | } | |
8208 | } | |
8209 | } | |
8210 | ||
0114d602 | 8211 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 8212 | |
0114d602 DJ |
8213 | static struct type * |
8214 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 8215 | { |
e7c27a73 | 8216 | struct objfile *objfile = cu->objfile; |
0114d602 | 8217 | const char *previous_prefix, *name; |
9219021c | 8218 | int is_anonymous; |
0114d602 DJ |
8219 | struct type *type; |
8220 | ||
8221 | /* For extensions, reuse the type of the original namespace. */ | |
8222 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
8223 | { | |
8224 | struct die_info *ext_die; | |
8225 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 8226 | |
0114d602 DJ |
8227 | ext_die = dwarf2_extension (die, &ext_cu); |
8228 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
8229 | |
8230 | /* EXT_CU may not be the same as CU. | |
8231 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
8232 | return set_die_type (die, type, cu); |
8233 | } | |
9219021c | 8234 | |
e142c38c | 8235 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
8236 | |
8237 | /* Now build the name of the current namespace. */ | |
8238 | ||
0114d602 DJ |
8239 | previous_prefix = determine_prefix (die, cu); |
8240 | if (previous_prefix[0] != '\0') | |
8241 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 8242 | previous_prefix, name, 0, cu); |
0114d602 DJ |
8243 | |
8244 | /* Create the type. */ | |
8245 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
8246 | objfile); | |
8247 | TYPE_NAME (type) = (char *) name; | |
8248 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8249 | ||
60531b24 | 8250 | return set_die_type (die, type, cu); |
0114d602 DJ |
8251 | } |
8252 | ||
8253 | /* Read a C++ namespace. */ | |
8254 | ||
8255 | static void | |
8256 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
8257 | { | |
8258 | struct objfile *objfile = cu->objfile; | |
0114d602 | 8259 | int is_anonymous; |
9219021c | 8260 | |
5c4e30ca DC |
8261 | /* Add a symbol associated to this if we haven't seen the namespace |
8262 | before. Also, add a using directive if it's an anonymous | |
8263 | namespace. */ | |
9219021c | 8264 | |
f2f0e013 | 8265 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
8266 | { |
8267 | struct type *type; | |
8268 | ||
0114d602 | 8269 | type = read_type_die (die, cu); |
e7c27a73 | 8270 | new_symbol (die, type, cu); |
5c4e30ca | 8271 | |
e8e80198 | 8272 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 8273 | if (is_anonymous) |
0114d602 DJ |
8274 | { |
8275 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 8276 | |
c0cc3a76 | 8277 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 8278 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 8279 | } |
5c4e30ca | 8280 | } |
9219021c | 8281 | |
639d11d3 | 8282 | if (die->child != NULL) |
d9fa45fe | 8283 | { |
639d11d3 | 8284 | struct die_info *child_die = die->child; |
6e70227d | 8285 | |
d9fa45fe DC |
8286 | while (child_die && child_die->tag) |
8287 | { | |
e7c27a73 | 8288 | process_die (child_die, cu); |
d9fa45fe DC |
8289 | child_die = sibling_die (child_die); |
8290 | } | |
8291 | } | |
38d518c9 EZ |
8292 | } |
8293 | ||
f55ee35c JK |
8294 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
8295 | imported module. Still we need that type as local Fortran "use ... only" | |
8296 | declaration imports depend on the created type in determine_prefix. */ | |
8297 | ||
8298 | static struct type * | |
8299 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
8300 | { | |
8301 | struct objfile *objfile = cu->objfile; | |
8302 | char *module_name; | |
8303 | struct type *type; | |
8304 | ||
8305 | module_name = dwarf2_name (die, cu); | |
8306 | if (!module_name) | |
3e43a32a MS |
8307 | complaint (&symfile_complaints, |
8308 | _("DW_TAG_module has no name, offset 0x%x"), | |
f55ee35c JK |
8309 | die->offset); |
8310 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
8311 | ||
8312 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
8313 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8314 | ||
8315 | return set_die_type (die, type, cu); | |
8316 | } | |
8317 | ||
5d7cb8df JK |
8318 | /* Read a Fortran module. */ |
8319 | ||
8320 | static void | |
8321 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
8322 | { | |
8323 | struct die_info *child_die = die->child; | |
8324 | ||
5d7cb8df JK |
8325 | while (child_die && child_die->tag) |
8326 | { | |
8327 | process_die (child_die, cu); | |
8328 | child_die = sibling_die (child_die); | |
8329 | } | |
8330 | } | |
8331 | ||
38d518c9 EZ |
8332 | /* Return the name of the namespace represented by DIE. Set |
8333 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
8334 | namespace. */ | |
8335 | ||
8336 | static const char * | |
e142c38c | 8337 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
8338 | { |
8339 | struct die_info *current_die; | |
8340 | const char *name = NULL; | |
8341 | ||
8342 | /* Loop through the extensions until we find a name. */ | |
8343 | ||
8344 | for (current_die = die; | |
8345 | current_die != NULL; | |
f2f0e013 | 8346 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 8347 | { |
e142c38c | 8348 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
8349 | if (name != NULL) |
8350 | break; | |
8351 | } | |
8352 | ||
8353 | /* Is it an anonymous namespace? */ | |
8354 | ||
8355 | *is_anonymous = (name == NULL); | |
8356 | if (*is_anonymous) | |
2b1dbab0 | 8357 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
8358 | |
8359 | return name; | |
d9fa45fe DC |
8360 | } |
8361 | ||
c906108c SS |
8362 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
8363 | the user defined type vector. */ | |
8364 | ||
f792889a | 8365 | static struct type * |
e7c27a73 | 8366 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8367 | { |
5e2b427d | 8368 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 8369 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 8370 | struct type *type; |
8b2dbe47 KB |
8371 | struct attribute *attr_byte_size; |
8372 | struct attribute *attr_address_class; | |
8373 | int byte_size, addr_class; | |
7e314c57 JK |
8374 | struct type *target_type; |
8375 | ||
8376 | target_type = die_type (die, cu); | |
c906108c | 8377 | |
7e314c57 JK |
8378 | /* The die_type call above may have already set the type for this DIE. */ |
8379 | type = get_die_type (die, cu); | |
8380 | if (type) | |
8381 | return type; | |
8382 | ||
8383 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 8384 | |
e142c38c | 8385 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
8386 | if (attr_byte_size) |
8387 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 8388 | else |
8b2dbe47 KB |
8389 | byte_size = cu_header->addr_size; |
8390 | ||
e142c38c | 8391 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
8392 | if (attr_address_class) |
8393 | addr_class = DW_UNSND (attr_address_class); | |
8394 | else | |
8395 | addr_class = DW_ADDR_none; | |
8396 | ||
8397 | /* If the pointer size or address class is different than the | |
8398 | default, create a type variant marked as such and set the | |
8399 | length accordingly. */ | |
8400 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 8401 | { |
5e2b427d | 8402 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
8403 | { |
8404 | int type_flags; | |
8405 | ||
849957d9 | 8406 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 8407 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
8408 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
8409 | == 0); | |
8b2dbe47 KB |
8410 | type = make_type_with_address_space (type, type_flags); |
8411 | } | |
8412 | else if (TYPE_LENGTH (type) != byte_size) | |
8413 | { | |
3e43a32a MS |
8414 | complaint (&symfile_complaints, |
8415 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 8416 | } |
6e70227d | 8417 | else |
9a619af0 MS |
8418 | { |
8419 | /* Should we also complain about unhandled address classes? */ | |
8420 | } | |
c906108c | 8421 | } |
8b2dbe47 KB |
8422 | |
8423 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 8424 | return set_die_type (die, type, cu); |
c906108c SS |
8425 | } |
8426 | ||
8427 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
8428 | the user defined type vector. */ | |
8429 | ||
f792889a | 8430 | static struct type * |
e7c27a73 | 8431 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8432 | { |
8433 | struct type *type; | |
8434 | struct type *to_type; | |
8435 | struct type *domain; | |
8436 | ||
e7c27a73 DJ |
8437 | to_type = die_type (die, cu); |
8438 | domain = die_containing_type (die, cu); | |
0d5de010 | 8439 | |
7e314c57 JK |
8440 | /* The calls above may have already set the type for this DIE. */ |
8441 | type = get_die_type (die, cu); | |
8442 | if (type) | |
8443 | return type; | |
8444 | ||
0d5de010 DJ |
8445 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
8446 | type = lookup_methodptr_type (to_type); | |
8447 | else | |
8448 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 8449 | |
f792889a | 8450 | return set_die_type (die, type, cu); |
c906108c SS |
8451 | } |
8452 | ||
8453 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
8454 | the user defined type vector. */ | |
8455 | ||
f792889a | 8456 | static struct type * |
e7c27a73 | 8457 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8458 | { |
e7c27a73 | 8459 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 8460 | struct type *type, *target_type; |
c906108c SS |
8461 | struct attribute *attr; |
8462 | ||
7e314c57 JK |
8463 | target_type = die_type (die, cu); |
8464 | ||
8465 | /* The die_type call above may have already set the type for this DIE. */ | |
8466 | type = get_die_type (die, cu); | |
8467 | if (type) | |
8468 | return type; | |
8469 | ||
8470 | type = lookup_reference_type (target_type); | |
e142c38c | 8471 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8472 | if (attr) |
8473 | { | |
8474 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8475 | } | |
8476 | else | |
8477 | { | |
107d2387 | 8478 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 8479 | } |
f792889a | 8480 | return set_die_type (die, type, cu); |
c906108c SS |
8481 | } |
8482 | ||
f792889a | 8483 | static struct type * |
e7c27a73 | 8484 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8485 | { |
f792889a | 8486 | struct type *base_type, *cv_type; |
c906108c | 8487 | |
e7c27a73 | 8488 | base_type = die_type (die, cu); |
7e314c57 JK |
8489 | |
8490 | /* The die_type call above may have already set the type for this DIE. */ | |
8491 | cv_type = get_die_type (die, cu); | |
8492 | if (cv_type) | |
8493 | return cv_type; | |
8494 | ||
2f608a3a KW |
8495 | /* In case the const qualifier is applied to an array type, the element type |
8496 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
8497 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
8498 | { | |
8499 | struct type *el_type, *inner_array; | |
8500 | ||
8501 | base_type = copy_type (base_type); | |
8502 | inner_array = base_type; | |
8503 | ||
8504 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
8505 | { | |
8506 | TYPE_TARGET_TYPE (inner_array) = | |
8507 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
8508 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
8509 | } | |
8510 | ||
8511 | el_type = TYPE_TARGET_TYPE (inner_array); | |
8512 | TYPE_TARGET_TYPE (inner_array) = | |
8513 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
8514 | ||
8515 | return set_die_type (die, base_type, cu); | |
8516 | } | |
8517 | ||
f792889a DJ |
8518 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
8519 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8520 | } |
8521 | ||
f792889a | 8522 | static struct type * |
e7c27a73 | 8523 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8524 | { |
f792889a | 8525 | struct type *base_type, *cv_type; |
c906108c | 8526 | |
e7c27a73 | 8527 | base_type = die_type (die, cu); |
7e314c57 JK |
8528 | |
8529 | /* The die_type call above may have already set the type for this DIE. */ | |
8530 | cv_type = get_die_type (die, cu); | |
8531 | if (cv_type) | |
8532 | return cv_type; | |
8533 | ||
f792889a DJ |
8534 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
8535 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8536 | } |
8537 | ||
8538 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
8539 | the user defined type vector. It isn't really a user defined type, | |
8540 | but it behaves like one, with other DIE's using an AT_user_def_type | |
8541 | attribute to reference it. */ | |
8542 | ||
f792889a | 8543 | static struct type * |
e7c27a73 | 8544 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8545 | { |
e7c27a73 | 8546 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 8547 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8548 | struct type *type, *range_type, *index_type, *char_type; |
8549 | struct attribute *attr; | |
8550 | unsigned int length; | |
8551 | ||
e142c38c | 8552 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
8553 | if (attr) |
8554 | { | |
8555 | length = DW_UNSND (attr); | |
8556 | } | |
8557 | else | |
8558 | { | |
0963b4bd | 8559 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 8560 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
8561 | if (attr) |
8562 | { | |
8563 | length = DW_UNSND (attr); | |
8564 | } | |
8565 | else | |
8566 | { | |
8567 | length = 1; | |
8568 | } | |
c906108c | 8569 | } |
6ccb9162 | 8570 | |
46bf5051 | 8571 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8572 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
8573 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
8574 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 8575 | |
f792889a | 8576 | return set_die_type (die, type, cu); |
c906108c SS |
8577 | } |
8578 | ||
8579 | /* Handle DIES due to C code like: | |
8580 | ||
8581 | struct foo | |
c5aa993b JM |
8582 | { |
8583 | int (*funcp)(int a, long l); | |
8584 | int b; | |
8585 | }; | |
c906108c | 8586 | |
0963b4bd | 8587 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 8588 | |
f792889a | 8589 | static struct type * |
e7c27a73 | 8590 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8591 | { |
bb5ed363 | 8592 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
8593 | struct type *type; /* Type that this function returns. */ |
8594 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
8595 | struct attribute *attr; |
8596 | ||
e7c27a73 | 8597 | type = die_type (die, cu); |
7e314c57 JK |
8598 | |
8599 | /* The die_type call above may have already set the type for this DIE. */ | |
8600 | ftype = get_die_type (die, cu); | |
8601 | if (ftype) | |
8602 | return ftype; | |
8603 | ||
0c8b41f1 | 8604 | ftype = lookup_function_type (type); |
c906108c | 8605 | |
5b8101ae | 8606 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 8607 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 8608 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 8609 | || cu->language == language_cplus |
5b8101ae PM |
8610 | || cu->language == language_java |
8611 | || cu->language == language_pascal) | |
876cecd0 | 8612 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
8613 | else if (producer_is_realview (cu->producer)) |
8614 | /* RealView does not emit DW_AT_prototyped. We can not | |
8615 | distinguish prototyped and unprototyped functions; default to | |
8616 | prototyped, since that is more common in modern code (and | |
8617 | RealView warns about unprototyped functions). */ | |
8618 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 8619 | |
c055b101 CV |
8620 | /* Store the calling convention in the type if it's available in |
8621 | the subroutine die. Otherwise set the calling convention to | |
8622 | the default value DW_CC_normal. */ | |
8623 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
8624 | if (attr) |
8625 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
8626 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
8627 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
8628 | else | |
8629 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
8630 | |
8631 | /* We need to add the subroutine type to the die immediately so | |
8632 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 8633 | declared as the same subroutine type. */ |
76c10ea2 | 8634 | set_die_type (die, ftype, cu); |
6e70227d | 8635 | |
639d11d3 | 8636 | if (die->child != NULL) |
c906108c | 8637 | { |
bb5ed363 | 8638 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 8639 | struct die_info *child_die; |
8072405b | 8640 | int nparams, iparams; |
c906108c SS |
8641 | |
8642 | /* Count the number of parameters. | |
8643 | FIXME: GDB currently ignores vararg functions, but knows about | |
8644 | vararg member functions. */ | |
8072405b | 8645 | nparams = 0; |
639d11d3 | 8646 | child_die = die->child; |
c906108c SS |
8647 | while (child_die && child_die->tag) |
8648 | { | |
8649 | if (child_die->tag == DW_TAG_formal_parameter) | |
8650 | nparams++; | |
8651 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 8652 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
8653 | child_die = sibling_die (child_die); |
8654 | } | |
8655 | ||
8656 | /* Allocate storage for parameters and fill them in. */ | |
8657 | TYPE_NFIELDS (ftype) = nparams; | |
8658 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 8659 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 8660 | |
8072405b JK |
8661 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
8662 | even if we error out during the parameters reading below. */ | |
8663 | for (iparams = 0; iparams < nparams; iparams++) | |
8664 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
8665 | ||
8666 | iparams = 0; | |
639d11d3 | 8667 | child_die = die->child; |
c906108c SS |
8668 | while (child_die && child_die->tag) |
8669 | { | |
8670 | if (child_die->tag == DW_TAG_formal_parameter) | |
8671 | { | |
3ce3b1ba PA |
8672 | struct type *arg_type; |
8673 | ||
8674 | /* DWARF version 2 has no clean way to discern C++ | |
8675 | static and non-static member functions. G++ helps | |
8676 | GDB by marking the first parameter for non-static | |
8677 | member functions (which is the this pointer) as | |
8678 | artificial. We pass this information to | |
8679 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
8680 | ||
8681 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
8682 | 4.5 does not yet generate. */ | |
e142c38c | 8683 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
8684 | if (attr) |
8685 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
8686 | else | |
418835cc KS |
8687 | { |
8688 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
8689 | ||
8690 | /* GCC/43521: In java, the formal parameter | |
8691 | "this" is sometimes not marked with DW_AT_artificial. */ | |
8692 | if (cu->language == language_java) | |
8693 | { | |
8694 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 8695 | |
418835cc KS |
8696 | if (name && !strcmp (name, "this")) |
8697 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
8698 | } | |
8699 | } | |
3ce3b1ba PA |
8700 | arg_type = die_type (child_die, cu); |
8701 | ||
8702 | /* RealView does not mark THIS as const, which the testsuite | |
8703 | expects. GCC marks THIS as const in method definitions, | |
8704 | but not in the class specifications (GCC PR 43053). */ | |
8705 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
8706 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
8707 | { | |
8708 | int is_this = 0; | |
8709 | struct dwarf2_cu *arg_cu = cu; | |
8710 | const char *name = dwarf2_name (child_die, cu); | |
8711 | ||
8712 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
8713 | if (attr) | |
8714 | { | |
8715 | /* If the compiler emits this, use it. */ | |
8716 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
8717 | is_this = 1; | |
8718 | } | |
8719 | else if (name && strcmp (name, "this") == 0) | |
8720 | /* Function definitions will have the argument names. */ | |
8721 | is_this = 1; | |
8722 | else if (name == NULL && iparams == 0) | |
8723 | /* Declarations may not have the names, so like | |
8724 | elsewhere in GDB, assume an artificial first | |
8725 | argument is "this". */ | |
8726 | is_this = 1; | |
8727 | ||
8728 | if (is_this) | |
8729 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
8730 | arg_type, 0); | |
8731 | } | |
8732 | ||
8733 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
8734 | iparams++; |
8735 | } | |
8736 | child_die = sibling_die (child_die); | |
8737 | } | |
8738 | } | |
8739 | ||
76c10ea2 | 8740 | return ftype; |
c906108c SS |
8741 | } |
8742 | ||
f792889a | 8743 | static struct type * |
e7c27a73 | 8744 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8745 | { |
e7c27a73 | 8746 | struct objfile *objfile = cu->objfile; |
0114d602 | 8747 | const char *name = NULL; |
3c8e0968 | 8748 | struct type *this_type, *target_type; |
c906108c | 8749 | |
94af9270 | 8750 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 8751 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
8752 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
8753 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 8754 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
8755 | target_type = die_type (die, cu); |
8756 | if (target_type != this_type) | |
8757 | TYPE_TARGET_TYPE (this_type) = target_type; | |
8758 | else | |
8759 | { | |
8760 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
8761 | spec and cause infinite loops in GDB. */ | |
8762 | complaint (&symfile_complaints, | |
8763 | _("Self-referential DW_TAG_typedef " | |
8764 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 8765 | die->offset, objfile->name); |
3c8e0968 DE |
8766 | TYPE_TARGET_TYPE (this_type) = NULL; |
8767 | } | |
f792889a | 8768 | return this_type; |
c906108c SS |
8769 | } |
8770 | ||
8771 | /* Find a representation of a given base type and install | |
8772 | it in the TYPE field of the die. */ | |
8773 | ||
f792889a | 8774 | static struct type * |
e7c27a73 | 8775 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8776 | { |
e7c27a73 | 8777 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8778 | struct type *type; |
8779 | struct attribute *attr; | |
8780 | int encoding = 0, size = 0; | |
39cbfefa | 8781 | char *name; |
6ccb9162 UW |
8782 | enum type_code code = TYPE_CODE_INT; |
8783 | int type_flags = 0; | |
8784 | struct type *target_type = NULL; | |
c906108c | 8785 | |
e142c38c | 8786 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
8787 | if (attr) |
8788 | { | |
8789 | encoding = DW_UNSND (attr); | |
8790 | } | |
e142c38c | 8791 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8792 | if (attr) |
8793 | { | |
8794 | size = DW_UNSND (attr); | |
8795 | } | |
39cbfefa | 8796 | name = dwarf2_name (die, cu); |
6ccb9162 | 8797 | if (!name) |
c906108c | 8798 | { |
6ccb9162 UW |
8799 | complaint (&symfile_complaints, |
8800 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 8801 | } |
6ccb9162 UW |
8802 | |
8803 | switch (encoding) | |
c906108c | 8804 | { |
6ccb9162 UW |
8805 | case DW_ATE_address: |
8806 | /* Turn DW_ATE_address into a void * pointer. */ | |
8807 | code = TYPE_CODE_PTR; | |
8808 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8809 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
8810 | break; | |
8811 | case DW_ATE_boolean: | |
8812 | code = TYPE_CODE_BOOL; | |
8813 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8814 | break; | |
8815 | case DW_ATE_complex_float: | |
8816 | code = TYPE_CODE_COMPLEX; | |
8817 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
8818 | break; | |
8819 | case DW_ATE_decimal_float: | |
8820 | code = TYPE_CODE_DECFLOAT; | |
8821 | break; | |
8822 | case DW_ATE_float: | |
8823 | code = TYPE_CODE_FLT; | |
8824 | break; | |
8825 | case DW_ATE_signed: | |
8826 | break; | |
8827 | case DW_ATE_unsigned: | |
8828 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
8829 | if (cu->language == language_fortran |
8830 | && name | |
8831 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
8832 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
8833 | break; |
8834 | case DW_ATE_signed_char: | |
6e70227d | 8835 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8836 | || cu->language == language_pascal |
8837 | || cu->language == language_fortran) | |
6ccb9162 UW |
8838 | code = TYPE_CODE_CHAR; |
8839 | break; | |
8840 | case DW_ATE_unsigned_char: | |
868a0084 | 8841 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8842 | || cu->language == language_pascal |
8843 | || cu->language == language_fortran) | |
6ccb9162 UW |
8844 | code = TYPE_CODE_CHAR; |
8845 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8846 | break; | |
75079b2b TT |
8847 | case DW_ATE_UTF: |
8848 | /* We just treat this as an integer and then recognize the | |
8849 | type by name elsewhere. */ | |
8850 | break; | |
8851 | ||
6ccb9162 UW |
8852 | default: |
8853 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
8854 | dwarf_type_encoding_name (encoding)); | |
8855 | break; | |
c906108c | 8856 | } |
6ccb9162 | 8857 | |
0114d602 DJ |
8858 | type = init_type (code, size, type_flags, NULL, objfile); |
8859 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
8860 | TYPE_TARGET_TYPE (type) = target_type; |
8861 | ||
0114d602 | 8862 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 8863 | TYPE_NOSIGN (type) = 1; |
0114d602 | 8864 | |
f792889a | 8865 | return set_die_type (die, type, cu); |
c906108c SS |
8866 | } |
8867 | ||
a02abb62 JB |
8868 | /* Read the given DW_AT_subrange DIE. */ |
8869 | ||
f792889a | 8870 | static struct type * |
a02abb62 JB |
8871 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
8872 | { | |
8873 | struct type *base_type; | |
8874 | struct type *range_type; | |
8875 | struct attribute *attr; | |
43bbcdc2 PH |
8876 | LONGEST low = 0; |
8877 | LONGEST high = -1; | |
39cbfefa | 8878 | char *name; |
43bbcdc2 | 8879 | LONGEST negative_mask; |
e77813c8 | 8880 | |
a02abb62 | 8881 | base_type = die_type (die, cu); |
953ac07e JK |
8882 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
8883 | check_typedef (base_type); | |
a02abb62 | 8884 | |
7e314c57 JK |
8885 | /* The die_type call above may have already set the type for this DIE. */ |
8886 | range_type = get_die_type (die, cu); | |
8887 | if (range_type) | |
8888 | return range_type; | |
8889 | ||
e142c38c | 8890 | if (cu->language == language_fortran) |
6e70227d | 8891 | { |
a02abb62 JB |
8892 | /* FORTRAN implies a lower bound of 1, if not given. */ |
8893 | low = 1; | |
8894 | } | |
8895 | ||
dd5e6932 DJ |
8896 | /* FIXME: For variable sized arrays either of these could be |
8897 | a variable rather than a constant value. We'll allow it, | |
8898 | but we don't know how to handle it. */ | |
e142c38c | 8899 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
8900 | if (attr) |
8901 | low = dwarf2_get_attr_constant_value (attr, 0); | |
8902 | ||
e142c38c | 8903 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 8904 | if (attr) |
6e70227d | 8905 | { |
d48323d8 | 8906 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
8907 | { |
8908 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 8909 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
8910 | FIXME: GDB does not yet know how to handle dynamic |
8911 | arrays properly, treat them as arrays with unspecified | |
8912 | length for now. | |
8913 | ||
8914 | FIXME: jimb/2003-09-22: GDB does not really know | |
8915 | how to handle arrays of unspecified length | |
8916 | either; we just represent them as zero-length | |
8917 | arrays. Choose an appropriate upper bound given | |
8918 | the lower bound we've computed above. */ | |
8919 | high = low - 1; | |
8920 | } | |
8921 | else | |
8922 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8923 | } | |
e77813c8 PM |
8924 | else |
8925 | { | |
8926 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8927 | if (attr) | |
8928 | { | |
8929 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8930 | high = low + count - 1; | |
8931 | } | |
c2ff108b JK |
8932 | else |
8933 | { | |
8934 | /* Unspecified array length. */ | |
8935 | high = low - 1; | |
8936 | } | |
e77813c8 PM |
8937 | } |
8938 | ||
8939 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8940 | without specifying a base type. | |
8941 | In that case, the base type must be set to the type of | |
8942 | the lower bound, upper bound or count, in that order, if any of these | |
8943 | three attributes references an object that has a type. | |
8944 | If no base type is found, the Dwarf-2 specifications say that | |
8945 | a signed integer type of size equal to the size of an address should | |
8946 | be used. | |
8947 | For the following C code: `extern char gdb_int [];' | |
8948 | GCC produces an empty range DIE. | |
8949 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 8950 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
8951 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
8952 | { | |
8953 | struct objfile *objfile = cu->objfile; | |
8954 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8955 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8956 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8957 | ||
8958 | /* Test "int", "long int", and "long long int" objfile types, | |
8959 | and select the first one having a size above or equal to the | |
8960 | architecture address size. */ | |
8961 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8962 | base_type = int_type; | |
8963 | else | |
8964 | { | |
8965 | int_type = objfile_type (objfile)->builtin_long; | |
8966 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8967 | base_type = int_type; | |
8968 | else | |
8969 | { | |
8970 | int_type = objfile_type (objfile)->builtin_long_long; | |
8971 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8972 | base_type = int_type; | |
8973 | } | |
8974 | } | |
8975 | } | |
a02abb62 | 8976 | |
6e70227d | 8977 | negative_mask = |
43bbcdc2 PH |
8978 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8979 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8980 | low |= negative_mask; | |
8981 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8982 | high |= negative_mask; | |
8983 | ||
a02abb62 JB |
8984 | range_type = create_range_type (NULL, base_type, low, high); |
8985 | ||
bbb0eef6 JK |
8986 | /* Mark arrays with dynamic length at least as an array of unspecified |
8987 | length. GDB could check the boundary but before it gets implemented at | |
8988 | least allow accessing the array elements. */ | |
d48323d8 | 8989 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
8990 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
8991 | ||
c2ff108b JK |
8992 | /* Ada expects an empty array on no boundary attributes. */ |
8993 | if (attr == NULL && cu->language != language_ada) | |
8994 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8995 | ||
39cbfefa DJ |
8996 | name = dwarf2_name (die, cu); |
8997 | if (name) | |
8998 | TYPE_NAME (range_type) = name; | |
6e70227d | 8999 | |
e142c38c | 9000 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
9001 | if (attr) |
9002 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
9003 | ||
7e314c57 JK |
9004 | set_die_type (die, range_type, cu); |
9005 | ||
9006 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
9007 | set_descriptive_type (range_type, die, cu); |
9008 | ||
7e314c57 | 9009 | return range_type; |
a02abb62 | 9010 | } |
6e70227d | 9011 | |
f792889a | 9012 | static struct type * |
81a17f79 JB |
9013 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
9014 | { | |
9015 | struct type *type; | |
81a17f79 | 9016 | |
81a17f79 JB |
9017 | /* For now, we only support the C meaning of an unspecified type: void. */ |
9018 | ||
0114d602 DJ |
9019 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
9020 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 9021 | |
f792889a | 9022 | return set_die_type (die, type, cu); |
81a17f79 | 9023 | } |
a02abb62 | 9024 | |
51545339 DJ |
9025 | /* Trivial hash function for die_info: the hash value of a DIE |
9026 | is its offset in .debug_info for this objfile. */ | |
9027 | ||
9028 | static hashval_t | |
9029 | die_hash (const void *item) | |
9030 | { | |
9031 | const struct die_info *die = item; | |
9a619af0 | 9032 | |
51545339 DJ |
9033 | return die->offset; |
9034 | } | |
9035 | ||
9036 | /* Trivial comparison function for die_info structures: two DIEs | |
9037 | are equal if they have the same offset. */ | |
9038 | ||
9039 | static int | |
9040 | die_eq (const void *item_lhs, const void *item_rhs) | |
9041 | { | |
9042 | const struct die_info *die_lhs = item_lhs; | |
9043 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 9044 | |
51545339 DJ |
9045 | return die_lhs->offset == die_rhs->offset; |
9046 | } | |
9047 | ||
c906108c SS |
9048 | /* Read a whole compilation unit into a linked list of dies. */ |
9049 | ||
f9aca02d | 9050 | static struct die_info * |
93311388 | 9051 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 9052 | { |
93311388 | 9053 | struct die_reader_specs reader_specs; |
98bfdba5 | 9054 | int read_abbrevs = 0; |
1d9ec526 | 9055 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
9056 | struct die_info *die; |
9057 | ||
9058 | if (cu->dwarf2_abbrevs == NULL) | |
9059 | { | |
e5fe5e75 | 9060 | dwarf2_read_abbrevs (cu); |
98bfdba5 PA |
9061 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
9062 | read_abbrevs = 1; | |
9063 | } | |
93311388 | 9064 | |
348e048f | 9065 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
9066 | cu->die_hash |
9067 | = htab_create_alloc_ex (cu->header.length / 12, | |
9068 | die_hash, | |
9069 | die_eq, | |
9070 | NULL, | |
9071 | &cu->comp_unit_obstack, | |
9072 | hashtab_obstack_allocate, | |
9073 | dummy_obstack_deallocate); | |
9074 | ||
93311388 DE |
9075 | init_cu_die_reader (&reader_specs, cu); |
9076 | ||
98bfdba5 PA |
9077 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
9078 | ||
9079 | if (read_abbrevs) | |
9080 | do_cleanups (back_to); | |
9081 | ||
9082 | return die; | |
639d11d3 DC |
9083 | } |
9084 | ||
d97bc12b DE |
9085 | /* Main entry point for reading a DIE and all children. |
9086 | Read the DIE and dump it if requested. */ | |
9087 | ||
9088 | static struct die_info * | |
93311388 DE |
9089 | read_die_and_children (const struct die_reader_specs *reader, |
9090 | gdb_byte *info_ptr, | |
d97bc12b DE |
9091 | gdb_byte **new_info_ptr, |
9092 | struct die_info *parent) | |
9093 | { | |
93311388 | 9094 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
9095 | new_info_ptr, parent); |
9096 | ||
9097 | if (dwarf2_die_debug) | |
9098 | { | |
348e048f DE |
9099 | fprintf_unfiltered (gdb_stdlog, |
9100 | "\nRead die from %s of %s:\n", | |
b0df02fd | 9101 | (reader->cu->per_cu->debug_types_section |
8b70b953 TT |
9102 | ? ".debug_types" |
9103 | : ".debug_info"), | |
348e048f | 9104 | reader->abfd->filename); |
d97bc12b DE |
9105 | dump_die (result, dwarf2_die_debug); |
9106 | } | |
9107 | ||
9108 | return result; | |
9109 | } | |
9110 | ||
639d11d3 DC |
9111 | /* Read a single die and all its descendents. Set the die's sibling |
9112 | field to NULL; set other fields in the die correctly, and set all | |
9113 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
9114 | location of the info_ptr after reading all of those dies. PARENT | |
9115 | is the parent of the die in question. */ | |
9116 | ||
9117 | static struct die_info * | |
93311388 DE |
9118 | read_die_and_children_1 (const struct die_reader_specs *reader, |
9119 | gdb_byte *info_ptr, | |
d97bc12b DE |
9120 | gdb_byte **new_info_ptr, |
9121 | struct die_info *parent) | |
639d11d3 DC |
9122 | { |
9123 | struct die_info *die; | |
fe1b8b76 | 9124 | gdb_byte *cur_ptr; |
639d11d3 DC |
9125 | int has_children; |
9126 | ||
93311388 | 9127 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
9128 | if (die == NULL) |
9129 | { | |
9130 | *new_info_ptr = cur_ptr; | |
9131 | return NULL; | |
9132 | } | |
93311388 | 9133 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
9134 | |
9135 | if (has_children) | |
348e048f | 9136 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
9137 | else |
9138 | { | |
9139 | die->child = NULL; | |
9140 | *new_info_ptr = cur_ptr; | |
9141 | } | |
9142 | ||
9143 | die->sibling = NULL; | |
9144 | die->parent = parent; | |
9145 | return die; | |
9146 | } | |
9147 | ||
9148 | /* Read a die, all of its descendents, and all of its siblings; set | |
9149 | all of the fields of all of the dies correctly. Arguments are as | |
9150 | in read_die_and_children. */ | |
9151 | ||
9152 | static struct die_info * | |
93311388 DE |
9153 | read_die_and_siblings (const struct die_reader_specs *reader, |
9154 | gdb_byte *info_ptr, | |
fe1b8b76 | 9155 | gdb_byte **new_info_ptr, |
639d11d3 DC |
9156 | struct die_info *parent) |
9157 | { | |
9158 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 9159 | gdb_byte *cur_ptr; |
639d11d3 | 9160 | |
c906108c | 9161 | cur_ptr = info_ptr; |
639d11d3 DC |
9162 | first_die = last_sibling = NULL; |
9163 | ||
9164 | while (1) | |
c906108c | 9165 | { |
639d11d3 | 9166 | struct die_info *die |
93311388 | 9167 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 9168 | |
1d325ec1 | 9169 | if (die == NULL) |
c906108c | 9170 | { |
639d11d3 DC |
9171 | *new_info_ptr = cur_ptr; |
9172 | return first_die; | |
c906108c | 9173 | } |
1d325ec1 DJ |
9174 | |
9175 | if (!first_die) | |
9176 | first_die = die; | |
c906108c | 9177 | else |
1d325ec1 DJ |
9178 | last_sibling->sibling = die; |
9179 | ||
9180 | last_sibling = die; | |
c906108c | 9181 | } |
c906108c SS |
9182 | } |
9183 | ||
93311388 DE |
9184 | /* Read the die from the .debug_info section buffer. Set DIEP to |
9185 | point to a newly allocated die with its information, except for its | |
9186 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
9187 | whether the die has children or not. */ | |
9188 | ||
9189 | static gdb_byte * | |
9190 | read_full_die (const struct die_reader_specs *reader, | |
9191 | struct die_info **diep, gdb_byte *info_ptr, | |
9192 | int *has_children) | |
9193 | { | |
9194 | unsigned int abbrev_number, bytes_read, i, offset; | |
9195 | struct abbrev_info *abbrev; | |
9196 | struct die_info *die; | |
9197 | struct dwarf2_cu *cu = reader->cu; | |
9198 | bfd *abfd = reader->abfd; | |
9199 | ||
9200 | offset = info_ptr - reader->buffer; | |
9201 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9202 | info_ptr += bytes_read; | |
9203 | if (!abbrev_number) | |
9204 | { | |
9205 | *diep = NULL; | |
9206 | *has_children = 0; | |
9207 | return info_ptr; | |
9208 | } | |
9209 | ||
9210 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
9211 | if (!abbrev) | |
348e048f DE |
9212 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
9213 | abbrev_number, | |
9214 | bfd_get_filename (abfd)); | |
9215 | ||
93311388 DE |
9216 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
9217 | die->offset = offset; | |
9218 | die->tag = abbrev->tag; | |
9219 | die->abbrev = abbrev_number; | |
9220 | ||
9221 | die->num_attrs = abbrev->num_attrs; | |
9222 | ||
9223 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9224 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
9225 | abfd, info_ptr, cu); | |
9226 | ||
9227 | *diep = die; | |
9228 | *has_children = abbrev->has_children; | |
9229 | return info_ptr; | |
9230 | } | |
9231 | ||
c906108c SS |
9232 | /* In DWARF version 2, the description of the debugging information is |
9233 | stored in a separate .debug_abbrev section. Before we read any | |
9234 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
9235 | in a hash table. This function also sets flags in CU describing |
9236 | the data found in the abbrev table. */ | |
c906108c SS |
9237 | |
9238 | static void | |
e5fe5e75 | 9239 | dwarf2_read_abbrevs (struct dwarf2_cu *cu) |
c906108c | 9240 | { |
e5fe5e75 | 9241 | bfd *abfd = cu->objfile->obfd; |
e7c27a73 | 9242 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 9243 | gdb_byte *abbrev_ptr; |
c906108c SS |
9244 | struct abbrev_info *cur_abbrev; |
9245 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
9246 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
9247 | struct attr_abbrev *cur_attrs; |
9248 | unsigned int allocated_attrs; | |
c906108c | 9249 | |
0963b4bd | 9250 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
9251 | obstack_init (&cu->abbrev_obstack); |
9252 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
9253 | (ABBREV_HASH_SIZE | |
9254 | * sizeof (struct abbrev_info *))); | |
9255 | memset (cu->dwarf2_abbrevs, 0, | |
9256 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 9257 | |
be391dca TT |
9258 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
9259 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 9260 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
9261 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9262 | abbrev_ptr += bytes_read; | |
9263 | ||
f3dd6933 DJ |
9264 | allocated_attrs = ATTR_ALLOC_CHUNK; |
9265 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 9266 | |
0963b4bd | 9267 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
9268 | while (abbrev_number) |
9269 | { | |
f3dd6933 | 9270 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
9271 | |
9272 | /* read in abbrev header */ | |
9273 | cur_abbrev->number = abbrev_number; | |
9274 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9275 | abbrev_ptr += bytes_read; | |
9276 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
9277 | abbrev_ptr += 1; | |
9278 | ||
72bf9492 DJ |
9279 | if (cur_abbrev->tag == DW_TAG_namespace) |
9280 | cu->has_namespace_info = 1; | |
9281 | ||
c906108c SS |
9282 | /* now read in declarations */ |
9283 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9284 | abbrev_ptr += bytes_read; | |
9285 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9286 | abbrev_ptr += bytes_read; | |
9287 | while (abbrev_name) | |
9288 | { | |
f3dd6933 | 9289 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 9290 | { |
f3dd6933 DJ |
9291 | allocated_attrs += ATTR_ALLOC_CHUNK; |
9292 | cur_attrs | |
9293 | = xrealloc (cur_attrs, (allocated_attrs | |
9294 | * sizeof (struct attr_abbrev))); | |
c906108c | 9295 | } |
ae038cb0 DJ |
9296 | |
9297 | /* Record whether this compilation unit might have | |
9298 | inter-compilation-unit references. If we don't know what form | |
9299 | this attribute will have, then it might potentially be a | |
9300 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
9301 | references. */ | |
9302 | ||
9303 | if (abbrev_form == DW_FORM_ref_addr | |
9304 | || abbrev_form == DW_FORM_indirect) | |
9305 | cu->has_form_ref_addr = 1; | |
9306 | ||
f3dd6933 DJ |
9307 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
9308 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
9309 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9310 | abbrev_ptr += bytes_read; | |
9311 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9312 | abbrev_ptr += bytes_read; | |
9313 | } | |
9314 | ||
f3dd6933 DJ |
9315 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
9316 | (cur_abbrev->num_attrs | |
9317 | * sizeof (struct attr_abbrev))); | |
9318 | memcpy (cur_abbrev->attrs, cur_attrs, | |
9319 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
9320 | ||
c906108c | 9321 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
9322 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
9323 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
9324 | |
9325 | /* Get next abbreviation. | |
9326 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
9327 | always properly terminated with an abbrev number of 0. |
9328 | Exit loop if we encounter an abbreviation which we have | |
9329 | already read (which means we are about to read the abbreviations | |
9330 | for the next compile unit) or if the end of the abbreviation | |
9331 | table is reached. */ | |
dce234bc PP |
9332 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
9333 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
9334 | break; |
9335 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9336 | abbrev_ptr += bytes_read; | |
e7c27a73 | 9337 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
9338 | break; |
9339 | } | |
f3dd6933 DJ |
9340 | |
9341 | xfree (cur_attrs); | |
c906108c SS |
9342 | } |
9343 | ||
f3dd6933 | 9344 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 9345 | |
c906108c | 9346 | static void |
f3dd6933 | 9347 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 9348 | { |
f3dd6933 | 9349 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 9350 | |
f3dd6933 DJ |
9351 | obstack_free (&cu->abbrev_obstack, NULL); |
9352 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
9353 | } |
9354 | ||
9355 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
9356 | ||
9357 | static struct abbrev_info * | |
e7c27a73 | 9358 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
9359 | { |
9360 | unsigned int hash_number; | |
9361 | struct abbrev_info *abbrev; | |
9362 | ||
9363 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 9364 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
9365 | |
9366 | while (abbrev) | |
9367 | { | |
9368 | if (abbrev->number == number) | |
9369 | return abbrev; | |
9370 | else | |
9371 | abbrev = abbrev->next; | |
9372 | } | |
9373 | return NULL; | |
9374 | } | |
9375 | ||
72bf9492 DJ |
9376 | /* Returns nonzero if TAG represents a type that we might generate a partial |
9377 | symbol for. */ | |
9378 | ||
9379 | static int | |
9380 | is_type_tag_for_partial (int tag) | |
9381 | { | |
9382 | switch (tag) | |
9383 | { | |
9384 | #if 0 | |
9385 | /* Some types that would be reasonable to generate partial symbols for, | |
9386 | that we don't at present. */ | |
9387 | case DW_TAG_array_type: | |
9388 | case DW_TAG_file_type: | |
9389 | case DW_TAG_ptr_to_member_type: | |
9390 | case DW_TAG_set_type: | |
9391 | case DW_TAG_string_type: | |
9392 | case DW_TAG_subroutine_type: | |
9393 | #endif | |
9394 | case DW_TAG_base_type: | |
9395 | case DW_TAG_class_type: | |
680b30c7 | 9396 | case DW_TAG_interface_type: |
72bf9492 DJ |
9397 | case DW_TAG_enumeration_type: |
9398 | case DW_TAG_structure_type: | |
9399 | case DW_TAG_subrange_type: | |
9400 | case DW_TAG_typedef: | |
9401 | case DW_TAG_union_type: | |
9402 | return 1; | |
9403 | default: | |
9404 | return 0; | |
9405 | } | |
9406 | } | |
9407 | ||
9408 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
9409 | ||
9410 | static struct partial_die_info * | |
93311388 DE |
9411 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
9412 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 | 9413 | { |
bb5ed363 | 9414 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
9415 | struct partial_die_info *part_die; |
9416 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
9417 | struct abbrev_info *abbrev; | |
9418 | unsigned int bytes_read; | |
5afb4e99 | 9419 | unsigned int load_all = 0; |
72bf9492 DJ |
9420 | |
9421 | int nesting_level = 1; | |
9422 | ||
9423 | parent_die = NULL; | |
9424 | last_die = NULL; | |
9425 | ||
5afb4e99 DJ |
9426 | if (cu->per_cu && cu->per_cu->load_all_dies) |
9427 | load_all = 1; | |
9428 | ||
72bf9492 DJ |
9429 | cu->partial_dies |
9430 | = htab_create_alloc_ex (cu->header.length / 12, | |
9431 | partial_die_hash, | |
9432 | partial_die_eq, | |
9433 | NULL, | |
9434 | &cu->comp_unit_obstack, | |
9435 | hashtab_obstack_allocate, | |
9436 | dummy_obstack_deallocate); | |
9437 | ||
9438 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9439 | sizeof (struct partial_die_info)); | |
9440 | ||
9441 | while (1) | |
9442 | { | |
9443 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
9444 | ||
9445 | /* A NULL abbrev means the end of a series of children. */ | |
9446 | if (abbrev == NULL) | |
9447 | { | |
9448 | if (--nesting_level == 0) | |
9449 | { | |
9450 | /* PART_DIE was probably the last thing allocated on the | |
9451 | comp_unit_obstack, so we could call obstack_free | |
9452 | here. We don't do that because the waste is small, | |
9453 | and will be cleaned up when we're done with this | |
9454 | compilation unit. This way, we're also more robust | |
9455 | against other users of the comp_unit_obstack. */ | |
9456 | return first_die; | |
9457 | } | |
9458 | info_ptr += bytes_read; | |
9459 | last_die = parent_die; | |
9460 | parent_die = parent_die->die_parent; | |
9461 | continue; | |
9462 | } | |
9463 | ||
98bfdba5 PA |
9464 | /* Check for template arguments. We never save these; if |
9465 | they're seen, we just mark the parent, and go on our way. */ | |
9466 | if (parent_die != NULL | |
9467 | && cu->language == language_cplus | |
9468 | && (abbrev->tag == DW_TAG_template_type_param | |
9469 | || abbrev->tag == DW_TAG_template_value_param)) | |
9470 | { | |
9471 | parent_die->has_template_arguments = 1; | |
9472 | ||
9473 | if (!load_all) | |
9474 | { | |
9475 | /* We don't need a partial DIE for the template argument. */ | |
9476 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
9477 | cu); | |
9478 | continue; | |
9479 | } | |
9480 | } | |
9481 | ||
9482 | /* We only recurse into subprograms looking for template arguments. | |
9483 | Skip their other children. */ | |
9484 | if (!load_all | |
9485 | && cu->language == language_cplus | |
9486 | && parent_die != NULL | |
9487 | && parent_die->tag == DW_TAG_subprogram) | |
9488 | { | |
9489 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
9490 | continue; | |
9491 | } | |
9492 | ||
5afb4e99 DJ |
9493 | /* Check whether this DIE is interesting enough to save. Normally |
9494 | we would not be interested in members here, but there may be | |
9495 | later variables referencing them via DW_AT_specification (for | |
9496 | static members). */ | |
9497 | if (!load_all | |
9498 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 9499 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
9500 | && abbrev->tag != DW_TAG_enumerator |
9501 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 9502 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 9503 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 9504 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 9505 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 9506 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
9507 | { |
9508 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9509 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
9510 | continue; |
9511 | } | |
9512 | ||
93311388 DE |
9513 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
9514 | buffer, info_ptr, cu); | |
72bf9492 DJ |
9515 | |
9516 | /* This two-pass algorithm for processing partial symbols has a | |
9517 | high cost in cache pressure. Thus, handle some simple cases | |
9518 | here which cover the majority of C partial symbols. DIEs | |
9519 | which neither have specification tags in them, nor could have | |
9520 | specification tags elsewhere pointing at them, can simply be | |
9521 | processed and discarded. | |
9522 | ||
9523 | This segment is also optional; scan_partial_symbols and | |
9524 | add_partial_symbol will handle these DIEs if we chain | |
9525 | them in normally. When compilers which do not emit large | |
9526 | quantities of duplicate debug information are more common, | |
9527 | this code can probably be removed. */ | |
9528 | ||
9529 | /* Any complete simple types at the top level (pretty much all | |
9530 | of them, for a language without namespaces), can be processed | |
9531 | directly. */ | |
9532 | if (parent_die == NULL | |
9533 | && part_die->has_specification == 0 | |
9534 | && part_die->is_declaration == 0 | |
d8228535 | 9535 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
9536 | || part_die->tag == DW_TAG_base_type |
9537 | || part_die->tag == DW_TAG_subrange_type)) | |
9538 | { | |
9539 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 9540 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9541 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
9542 | &objfile->static_psymbols, |
9543 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
93311388 | 9544 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9545 | continue; |
9546 | } | |
9547 | ||
d8228535 JK |
9548 | /* The exception for DW_TAG_typedef with has_children above is |
9549 | a workaround of GCC PR debug/47510. In the case of this complaint | |
9550 | type_name_no_tag_or_error will error on such types later. | |
9551 | ||
9552 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
9553 | it could not find the child DIEs referenced later, this is checked | |
9554 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
9555 | ||
9556 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
9557 | complaint (&symfile_complaints, | |
9558 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
9559 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 9560 | part_die->offset, objfile->name); |
d8228535 | 9561 | |
72bf9492 DJ |
9562 | /* If we're at the second level, and we're an enumerator, and |
9563 | our parent has no specification (meaning possibly lives in a | |
9564 | namespace elsewhere), then we can add the partial symbol now | |
9565 | instead of queueing it. */ | |
9566 | if (part_die->tag == DW_TAG_enumerator | |
9567 | && parent_die != NULL | |
9568 | && parent_die->die_parent == NULL | |
9569 | && parent_die->tag == DW_TAG_enumeration_type | |
9570 | && parent_die->has_specification == 0) | |
9571 | { | |
9572 | if (part_die->name == NULL) | |
3e43a32a MS |
9573 | complaint (&symfile_complaints, |
9574 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 9575 | else if (building_psymtab) |
04a679b8 | 9576 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9577 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
9578 | (cu->language == language_cplus |
9579 | || cu->language == language_java) | |
bb5ed363 DE |
9580 | ? &objfile->global_psymbols |
9581 | : &objfile->static_psymbols, | |
9582 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 9583 | |
93311388 | 9584 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9585 | continue; |
9586 | } | |
9587 | ||
9588 | /* We'll save this DIE so link it in. */ | |
9589 | part_die->die_parent = parent_die; | |
9590 | part_die->die_sibling = NULL; | |
9591 | part_die->die_child = NULL; | |
9592 | ||
9593 | if (last_die && last_die == parent_die) | |
9594 | last_die->die_child = part_die; | |
9595 | else if (last_die) | |
9596 | last_die->die_sibling = part_die; | |
9597 | ||
9598 | last_die = part_die; | |
9599 | ||
9600 | if (first_die == NULL) | |
9601 | first_die = part_die; | |
9602 | ||
9603 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
9604 | find interesting need to be in the hash table, because we | |
9605 | also have the parent/sibling/child chains; only those that we | |
9606 | might refer to by offset later during partial symbol reading. | |
9607 | ||
9608 | For now this means things that might have be the target of a | |
9609 | DW_AT_specification, DW_AT_abstract_origin, or | |
9610 | DW_AT_extension. DW_AT_extension will refer only to | |
9611 | namespaces; DW_AT_abstract_origin refers to functions (and | |
9612 | many things under the function DIE, but we do not recurse | |
9613 | into function DIEs during partial symbol reading) and | |
9614 | possibly variables as well; DW_AT_specification refers to | |
9615 | declarations. Declarations ought to have the DW_AT_declaration | |
9616 | flag. It happens that GCC forgets to put it in sometimes, but | |
9617 | only for functions, not for types. | |
9618 | ||
9619 | Adding more things than necessary to the hash table is harmless | |
9620 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
9621 | wasted time in find_partial_die, when we reread the compilation |
9622 | unit with load_all_dies set. */ | |
72bf9492 | 9623 | |
5afb4e99 | 9624 | if (load_all |
72929c62 | 9625 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 9626 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
9627 | || abbrev->tag == DW_TAG_variable |
9628 | || abbrev->tag == DW_TAG_namespace | |
9629 | || part_die->is_declaration) | |
9630 | { | |
9631 | void **slot; | |
9632 | ||
9633 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
9634 | part_die->offset, INSERT); | |
9635 | *slot = part_die; | |
9636 | } | |
9637 | ||
9638 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9639 | sizeof (struct partial_die_info)); | |
9640 | ||
9641 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 9642 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
9643 | languages we have to, so that we can get at method physnames |
9644 | to infer fully qualified class names, for DW_AT_specification, | |
9645 | and for C++ template arguments. For C++, we also look one level | |
9646 | inside functions to find template arguments (if the name of the | |
9647 | function does not already contain the template arguments). | |
bc30ff58 JB |
9648 | |
9649 | For Ada, we need to scan the children of subprograms and lexical | |
9650 | blocks as well because Ada allows the definition of nested | |
9651 | entities that could be interesting for the debugger, such as | |
9652 | nested subprograms for instance. */ | |
72bf9492 | 9653 | if (last_die->has_children |
5afb4e99 DJ |
9654 | && (load_all |
9655 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 9656 | || last_die->tag == DW_TAG_module |
72bf9492 | 9657 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
9658 | || (cu->language == language_cplus |
9659 | && last_die->tag == DW_TAG_subprogram | |
9660 | && (last_die->name == NULL | |
9661 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
9662 | || (cu->language != language_c |
9663 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 9664 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 9665 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
9666 | || last_die->tag == DW_TAG_union_type)) |
9667 | || (cu->language == language_ada | |
9668 | && (last_die->tag == DW_TAG_subprogram | |
9669 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9670 | { |
9671 | nesting_level++; | |
9672 | parent_die = last_die; | |
9673 | continue; | |
9674 | } | |
9675 | ||
9676 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9677 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9678 | |
9679 | /* Back to the top, do it again. */ | |
9680 | } | |
9681 | } | |
9682 | ||
c906108c SS |
9683 | /* Read a minimal amount of information into the minimal die structure. */ |
9684 | ||
fe1b8b76 | 9685 | static gdb_byte * |
72bf9492 DJ |
9686 | read_partial_die (struct partial_die_info *part_die, |
9687 | struct abbrev_info *abbrev, | |
9688 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
9689 | gdb_byte *buffer, gdb_byte *info_ptr, |
9690 | struct dwarf2_cu *cu) | |
c906108c | 9691 | { |
bb5ed363 | 9692 | struct objfile *objfile = cu->objfile; |
fa238c03 | 9693 | unsigned int i; |
c906108c | 9694 | struct attribute attr; |
c5aa993b | 9695 | int has_low_pc_attr = 0; |
c906108c SS |
9696 | int has_high_pc_attr = 0; |
9697 | ||
72bf9492 | 9698 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 9699 | |
93311388 | 9700 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
9701 | |
9702 | info_ptr += abbrev_len; | |
9703 | ||
9704 | if (abbrev == NULL) | |
9705 | return info_ptr; | |
9706 | ||
c906108c SS |
9707 | part_die->tag = abbrev->tag; |
9708 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
9709 | |
9710 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9711 | { | |
e7c27a73 | 9712 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
9713 | |
9714 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 9715 | partial symbol table. */ |
c906108c SS |
9716 | switch (attr.name) |
9717 | { | |
9718 | case DW_AT_name: | |
71c25dea TT |
9719 | switch (part_die->tag) |
9720 | { | |
9721 | case DW_TAG_compile_unit: | |
348e048f | 9722 | case DW_TAG_type_unit: |
71c25dea TT |
9723 | /* Compilation units have a DW_AT_name that is a filename, not |
9724 | a source language identifier. */ | |
9725 | case DW_TAG_enumeration_type: | |
9726 | case DW_TAG_enumerator: | |
9727 | /* These tags always have simple identifiers already; no need | |
9728 | to canonicalize them. */ | |
9729 | part_die->name = DW_STRING (&attr); | |
9730 | break; | |
9731 | default: | |
9732 | part_die->name | |
9733 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 9734 | &objfile->objfile_obstack); |
71c25dea TT |
9735 | break; |
9736 | } | |
c906108c | 9737 | break; |
31ef98ae | 9738 | case DW_AT_linkage_name: |
c906108c | 9739 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
9740 | /* Note that both forms of linkage name might appear. We |
9741 | assume they will be the same, and we only store the last | |
9742 | one we see. */ | |
94af9270 KS |
9743 | if (cu->language == language_ada) |
9744 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 9745 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
9746 | break; |
9747 | case DW_AT_low_pc: | |
9748 | has_low_pc_attr = 1; | |
9749 | part_die->lowpc = DW_ADDR (&attr); | |
9750 | break; | |
9751 | case DW_AT_high_pc: | |
9752 | has_high_pc_attr = 1; | |
9753 | part_die->highpc = DW_ADDR (&attr); | |
9754 | break; | |
9755 | case DW_AT_location: | |
0963b4bd | 9756 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9757 | if (attr_form_is_block (&attr)) |
9758 | { | |
9759 | part_die->locdesc = DW_BLOCK (&attr); | |
9760 | } | |
3690dd37 | 9761 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 9762 | { |
4d3c2250 | 9763 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9764 | } |
9765 | else | |
9766 | { | |
4d3c2250 KB |
9767 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9768 | "partial symbol information"); | |
8e19ed76 | 9769 | } |
c906108c | 9770 | break; |
c906108c SS |
9771 | case DW_AT_external: |
9772 | part_die->is_external = DW_UNSND (&attr); | |
9773 | break; | |
9774 | case DW_AT_declaration: | |
9775 | part_die->is_declaration = DW_UNSND (&attr); | |
9776 | break; | |
9777 | case DW_AT_type: | |
9778 | part_die->has_type = 1; | |
9779 | break; | |
9780 | case DW_AT_abstract_origin: | |
9781 | case DW_AT_specification: | |
72bf9492 DJ |
9782 | case DW_AT_extension: |
9783 | part_die->has_specification = 1; | |
c764a876 | 9784 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
9785 | break; |
9786 | case DW_AT_sibling: | |
9787 | /* Ignore absolute siblings, they might point outside of | |
9788 | the current compile unit. */ | |
9789 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
9790 | complaint (&symfile_complaints, |
9791 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 9792 | else |
93311388 | 9793 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 9794 | break; |
fa4028e9 JB |
9795 | case DW_AT_byte_size: |
9796 | part_die->has_byte_size = 1; | |
9797 | break; | |
68511cec CES |
9798 | case DW_AT_calling_convention: |
9799 | /* DWARF doesn't provide a way to identify a program's source-level | |
9800 | entry point. DW_AT_calling_convention attributes are only meant | |
9801 | to describe functions' calling conventions. | |
9802 | ||
9803 | However, because it's a necessary piece of information in | |
9804 | Fortran, and because DW_CC_program is the only piece of debugging | |
9805 | information whose definition refers to a 'main program' at all, | |
9806 | several compilers have begun marking Fortran main programs with | |
9807 | DW_CC_program --- even when those functions use the standard | |
9808 | calling conventions. | |
9809 | ||
9810 | So until DWARF specifies a way to provide this information and | |
9811 | compilers pick up the new representation, we'll support this | |
9812 | practice. */ | |
9813 | if (DW_UNSND (&attr) == DW_CC_program | |
9814 | && cu->language == language_fortran) | |
01f8c46d JK |
9815 | { |
9816 | set_main_name (part_die->name); | |
9817 | ||
9818 | /* As this DIE has a static linkage the name would be difficult | |
9819 | to look up later. */ | |
9820 | language_of_main = language_fortran; | |
9821 | } | |
68511cec | 9822 | break; |
c906108c SS |
9823 | default: |
9824 | break; | |
9825 | } | |
9826 | } | |
9827 | ||
9373cf26 JK |
9828 | if (has_low_pc_attr && has_high_pc_attr) |
9829 | { | |
9830 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
9831 | eliminate duplicate copies of functions and vtables and such. | |
9832 | The linker will arbitrarily choose one and discard the others. | |
9833 | The AT_*_pc values for such functions refer to local labels in | |
9834 | these sections. If the section from that file was discarded, the | |
9835 | labels are not in the output, so the relocs get a value of 0. | |
9836 | If this is a discarded function, mark the pc bounds as invalid, | |
9837 | so that GDB will ignore it. */ | |
9838 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
9839 | { | |
bb5ed363 | 9840 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
9841 | |
9842 | complaint (&symfile_complaints, | |
9843 | _("DW_AT_low_pc %s is zero " | |
9844 | "for DIE at 0x%x [in module %s]"), | |
9845 | paddress (gdbarch, part_die->lowpc), | |
bb5ed363 | 9846 | part_die->offset, objfile->name); |
9373cf26 JK |
9847 | } |
9848 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
9849 | else if (part_die->lowpc >= part_die->highpc) | |
9850 | { | |
bb5ed363 | 9851 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
9852 | |
9853 | complaint (&symfile_complaints, | |
9854 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
9855 | "for DIE at 0x%x [in module %s]"), | |
9856 | paddress (gdbarch, part_die->lowpc), | |
9857 | paddress (gdbarch, part_die->highpc), | |
bb5ed363 | 9858 | part_die->offset, objfile->name); |
9373cf26 JK |
9859 | } |
9860 | else | |
9861 | part_die->has_pc_info = 1; | |
9862 | } | |
85cbf3d3 | 9863 | |
c906108c SS |
9864 | return info_ptr; |
9865 | } | |
9866 | ||
72bf9492 DJ |
9867 | /* Find a cached partial DIE at OFFSET in CU. */ |
9868 | ||
9869 | static struct partial_die_info * | |
c764a876 | 9870 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
9871 | { |
9872 | struct partial_die_info *lookup_die = NULL; | |
9873 | struct partial_die_info part_die; | |
9874 | ||
9875 | part_die.offset = offset; | |
9876 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
9877 | ||
72bf9492 DJ |
9878 | return lookup_die; |
9879 | } | |
9880 | ||
348e048f DE |
9881 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
9882 | except in the case of .debug_types DIEs which do not reference | |
9883 | outside their CU (they do however referencing other types via | |
55f1336d | 9884 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
9885 | |
9886 | static struct partial_die_info * | |
c764a876 | 9887 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 9888 | { |
bb5ed363 | 9889 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
9890 | struct dwarf2_per_cu_data *per_cu = NULL; |
9891 | struct partial_die_info *pd = NULL; | |
72bf9492 | 9892 | |
b0df02fd | 9893 | if (cu->per_cu->debug_types_section) |
348e048f DE |
9894 | { |
9895 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9896 | if (pd != NULL) | |
9897 | return pd; | |
9898 | goto not_found; | |
9899 | } | |
9900 | ||
45452591 | 9901 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
9902 | { |
9903 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9904 | if (pd != NULL) | |
9905 | return pd; | |
9906 | } | |
72bf9492 | 9907 | |
bb5ed363 | 9908 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
ae038cb0 | 9909 | |
98bfdba5 | 9910 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
a0f42c21 | 9911 | load_partial_comp_unit (per_cu); |
ae038cb0 DJ |
9912 | |
9913 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
9914 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
9915 | ||
9916 | if (pd == NULL && per_cu->load_all_dies == 0) | |
9917 | { | |
9918 | struct cleanup *back_to; | |
9919 | struct partial_die_info comp_unit_die; | |
9920 | struct abbrev_info *abbrev; | |
9921 | unsigned int bytes_read; | |
9922 | char *info_ptr; | |
9923 | ||
9924 | per_cu->load_all_dies = 1; | |
9925 | ||
9926 | /* Re-read the DIEs. */ | |
9927 | back_to = make_cleanup (null_cleanup, 0); | |
9928 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
9929 | { | |
e5fe5e75 | 9930 | dwarf2_read_abbrevs (per_cu->cu); |
53d72f98 | 9931 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 9932 | } |
dce234bc | 9933 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
9934 | + per_cu->cu->header.offset |
9935 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
9936 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
9937 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
bb5ed363 | 9938 | objfile->obfd, |
93311388 | 9939 | dwarf2_per_objfile->info.buffer, info_ptr, |
5afb4e99 DJ |
9940 | per_cu->cu); |
9941 | if (comp_unit_die.has_children) | |
bb5ed363 | 9942 | load_partial_dies (objfile->obfd, |
93311388 DE |
9943 | dwarf2_per_objfile->info.buffer, info_ptr, |
9944 | 0, per_cu->cu); | |
5afb4e99 DJ |
9945 | do_cleanups (back_to); |
9946 | ||
9947 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
9948 | } | |
9949 | ||
348e048f DE |
9950 | not_found: |
9951 | ||
5afb4e99 DJ |
9952 | if (pd == NULL) |
9953 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
9954 | _("could not find partial DIE 0x%x " |
9955 | "in cache [from module %s]\n"), | |
bb5ed363 | 9956 | offset, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 9957 | return pd; |
72bf9492 DJ |
9958 | } |
9959 | ||
abc72ce4 DE |
9960 | /* See if we can figure out if the class lives in a namespace. We do |
9961 | this by looking for a member function; its demangled name will | |
9962 | contain namespace info, if there is any. */ | |
9963 | ||
9964 | static void | |
9965 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
9966 | struct dwarf2_cu *cu) | |
9967 | { | |
9968 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
9969 | what template types look like, because the demangler | |
9970 | frequently doesn't give the same name as the debug info. We | |
9971 | could fix this by only using the demangled name to get the | |
9972 | prefix (but see comment in read_structure_type). */ | |
9973 | ||
9974 | struct partial_die_info *real_pdi; | |
9975 | struct partial_die_info *child_pdi; | |
9976 | ||
9977 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
9978 | we should not do this. We'll prepend the parent's fully qualified | |
9979 | name when we create the partial symbol. */ | |
9980 | ||
9981 | real_pdi = struct_pdi; | |
9982 | while (real_pdi->has_specification) | |
9983 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
9984 | ||
9985 | if (real_pdi->die_parent != NULL) | |
9986 | return; | |
9987 | ||
9988 | for (child_pdi = struct_pdi->die_child; | |
9989 | child_pdi != NULL; | |
9990 | child_pdi = child_pdi->die_sibling) | |
9991 | { | |
9992 | if (child_pdi->tag == DW_TAG_subprogram | |
9993 | && child_pdi->linkage_name != NULL) | |
9994 | { | |
9995 | char *actual_class_name | |
9996 | = language_class_name_from_physname (cu->language_defn, | |
9997 | child_pdi->linkage_name); | |
9998 | if (actual_class_name != NULL) | |
9999 | { | |
10000 | struct_pdi->name | |
10001 | = obsavestring (actual_class_name, | |
10002 | strlen (actual_class_name), | |
10003 | &cu->objfile->objfile_obstack); | |
10004 | xfree (actual_class_name); | |
10005 | } | |
10006 | break; | |
10007 | } | |
10008 | } | |
10009 | } | |
10010 | ||
72bf9492 DJ |
10011 | /* Adjust PART_DIE before generating a symbol for it. This function |
10012 | may set the is_external flag or change the DIE's name. */ | |
10013 | ||
10014 | static void | |
10015 | fixup_partial_die (struct partial_die_info *part_die, | |
10016 | struct dwarf2_cu *cu) | |
10017 | { | |
abc72ce4 DE |
10018 | /* Once we've fixed up a die, there's no point in doing so again. |
10019 | This also avoids a memory leak if we were to call | |
10020 | guess_partial_die_structure_name multiple times. */ | |
10021 | if (part_die->fixup_called) | |
10022 | return; | |
10023 | ||
72bf9492 DJ |
10024 | /* If we found a reference attribute and the DIE has no name, try |
10025 | to find a name in the referred to DIE. */ | |
10026 | ||
10027 | if (part_die->name == NULL && part_die->has_specification) | |
10028 | { | |
10029 | struct partial_die_info *spec_die; | |
72bf9492 | 10030 | |
10b3939b | 10031 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 10032 | |
10b3939b | 10033 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
10034 | |
10035 | if (spec_die->name) | |
10036 | { | |
10037 | part_die->name = spec_die->name; | |
10038 | ||
10039 | /* Copy DW_AT_external attribute if it is set. */ | |
10040 | if (spec_die->is_external) | |
10041 | part_die->is_external = spec_die->is_external; | |
10042 | } | |
10043 | } | |
10044 | ||
10045 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
10046 | |
10047 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 10048 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 10049 | |
abc72ce4 DE |
10050 | /* If there is no parent die to provide a namespace, and there are |
10051 | children, see if we can determine the namespace from their linkage | |
10052 | name. | |
10053 | NOTE: We need to do this even if cu->has_namespace_info != 0. | |
10054 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ | |
10055 | if (cu->language == language_cplus | |
8b70b953 | 10056 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
10057 | && part_die->die_parent == NULL |
10058 | && part_die->has_children | |
10059 | && (part_die->tag == DW_TAG_class_type | |
10060 | || part_die->tag == DW_TAG_structure_type | |
10061 | || part_die->tag == DW_TAG_union_type)) | |
10062 | guess_partial_die_structure_name (part_die, cu); | |
10063 | ||
53832f31 TT |
10064 | /* GCC might emit a nameless struct or union that has a linkage |
10065 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
10066 | if (part_die->name == NULL | |
96408a79 SA |
10067 | && (part_die->tag == DW_TAG_class_type |
10068 | || part_die->tag == DW_TAG_interface_type | |
10069 | || part_die->tag == DW_TAG_structure_type | |
10070 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
10071 | && part_die->linkage_name != NULL) |
10072 | { | |
10073 | char *demangled; | |
10074 | ||
10075 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
10076 | if (demangled) | |
10077 | { | |
96408a79 SA |
10078 | const char *base; |
10079 | ||
10080 | /* Strip any leading namespaces/classes, keep only the base name. | |
10081 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
10082 | base = strrchr (demangled, ':'); | |
10083 | if (base && base > demangled && base[-1] == ':') | |
10084 | base++; | |
10085 | else | |
10086 | base = demangled; | |
10087 | ||
10088 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
10089 | &cu->objfile->objfile_obstack); |
10090 | xfree (demangled); | |
10091 | } | |
10092 | } | |
10093 | ||
abc72ce4 | 10094 | part_die->fixup_called = 1; |
72bf9492 DJ |
10095 | } |
10096 | ||
a8329558 | 10097 | /* Read an attribute value described by an attribute form. */ |
c906108c | 10098 | |
fe1b8b76 | 10099 | static gdb_byte * |
a8329558 | 10100 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 10101 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 10102 | struct dwarf2_cu *cu) |
c906108c | 10103 | { |
e7c27a73 | 10104 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10105 | unsigned int bytes_read; |
10106 | struct dwarf_block *blk; | |
10107 | ||
a8329558 KW |
10108 | attr->form = form; |
10109 | switch (form) | |
c906108c | 10110 | { |
c906108c | 10111 | case DW_FORM_ref_addr: |
ae411497 TT |
10112 | if (cu->header.version == 2) |
10113 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
10114 | else | |
3e43a32a MS |
10115 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
10116 | &cu->header, &bytes_read); | |
ae411497 TT |
10117 | info_ptr += bytes_read; |
10118 | break; | |
10119 | case DW_FORM_addr: | |
e7c27a73 | 10120 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 10121 | info_ptr += bytes_read; |
c906108c SS |
10122 | break; |
10123 | case DW_FORM_block2: | |
7b5a2f43 | 10124 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10125 | blk->size = read_2_bytes (abfd, info_ptr); |
10126 | info_ptr += 2; | |
10127 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10128 | info_ptr += blk->size; | |
10129 | DW_BLOCK (attr) = blk; | |
10130 | break; | |
10131 | case DW_FORM_block4: | |
7b5a2f43 | 10132 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10133 | blk->size = read_4_bytes (abfd, info_ptr); |
10134 | info_ptr += 4; | |
10135 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10136 | info_ptr += blk->size; | |
10137 | DW_BLOCK (attr) = blk; | |
10138 | break; | |
10139 | case DW_FORM_data2: | |
10140 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
10141 | info_ptr += 2; | |
10142 | break; | |
10143 | case DW_FORM_data4: | |
10144 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
10145 | info_ptr += 4; | |
10146 | break; | |
10147 | case DW_FORM_data8: | |
10148 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
10149 | info_ptr += 8; | |
10150 | break; | |
2dc7f7b3 TT |
10151 | case DW_FORM_sec_offset: |
10152 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
10153 | info_ptr += bytes_read; | |
10154 | break; | |
c906108c | 10155 | case DW_FORM_string: |
9b1c24c8 | 10156 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 10157 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
10158 | info_ptr += bytes_read; |
10159 | break; | |
4bdf3d34 JJ |
10160 | case DW_FORM_strp: |
10161 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
10162 | &bytes_read); | |
8285870a | 10163 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
10164 | info_ptr += bytes_read; |
10165 | break; | |
2dc7f7b3 | 10166 | case DW_FORM_exprloc: |
c906108c | 10167 | case DW_FORM_block: |
7b5a2f43 | 10168 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10169 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10170 | info_ptr += bytes_read; | |
10171 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10172 | info_ptr += blk->size; | |
10173 | DW_BLOCK (attr) = blk; | |
10174 | break; | |
10175 | case DW_FORM_block1: | |
7b5a2f43 | 10176 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10177 | blk->size = read_1_byte (abfd, info_ptr); |
10178 | info_ptr += 1; | |
10179 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10180 | info_ptr += blk->size; | |
10181 | DW_BLOCK (attr) = blk; | |
10182 | break; | |
10183 | case DW_FORM_data1: | |
10184 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10185 | info_ptr += 1; | |
10186 | break; | |
10187 | case DW_FORM_flag: | |
10188 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10189 | info_ptr += 1; | |
10190 | break; | |
2dc7f7b3 TT |
10191 | case DW_FORM_flag_present: |
10192 | DW_UNSND (attr) = 1; | |
10193 | break; | |
c906108c SS |
10194 | case DW_FORM_sdata: |
10195 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
10196 | info_ptr += bytes_read; | |
10197 | break; | |
10198 | case DW_FORM_udata: | |
10199 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
10200 | info_ptr += bytes_read; | |
10201 | break; | |
10202 | case DW_FORM_ref1: | |
10b3939b | 10203 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
10204 | info_ptr += 1; |
10205 | break; | |
10206 | case DW_FORM_ref2: | |
10b3939b | 10207 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
10208 | info_ptr += 2; |
10209 | break; | |
10210 | case DW_FORM_ref4: | |
10b3939b | 10211 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
10212 | info_ptr += 4; |
10213 | break; | |
613e1657 | 10214 | case DW_FORM_ref8: |
10b3939b | 10215 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
10216 | info_ptr += 8; |
10217 | break; | |
55f1336d | 10218 | case DW_FORM_ref_sig8: |
348e048f DE |
10219 | /* Convert the signature to something we can record in DW_UNSND |
10220 | for later lookup. | |
10221 | NOTE: This is NULL if the type wasn't found. */ | |
10222 | DW_SIGNATURED_TYPE (attr) = | |
10223 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
10224 | info_ptr += 8; | |
10225 | break; | |
c906108c | 10226 | case DW_FORM_ref_udata: |
10b3939b DJ |
10227 | DW_ADDR (attr) = (cu->header.offset |
10228 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
10229 | info_ptr += bytes_read; |
10230 | break; | |
c906108c | 10231 | case DW_FORM_indirect: |
a8329558 KW |
10232 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10233 | info_ptr += bytes_read; | |
e7c27a73 | 10234 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 10235 | break; |
c906108c | 10236 | default: |
8a3fe4f8 | 10237 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
10238 | dwarf_form_name (form), |
10239 | bfd_get_filename (abfd)); | |
c906108c | 10240 | } |
28e94949 JB |
10241 | |
10242 | /* We have seen instances where the compiler tried to emit a byte | |
10243 | size attribute of -1 which ended up being encoded as an unsigned | |
10244 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
10245 | an object of this size seems pretty unlikely so we can relatively | |
10246 | safely treat these cases as if the size attribute was invalid and | |
10247 | treat them as zero by default. */ | |
10248 | if (attr->name == DW_AT_byte_size | |
10249 | && form == DW_FORM_data4 | |
10250 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
10251 | { |
10252 | complaint | |
10253 | (&symfile_complaints, | |
43bbcdc2 PH |
10254 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
10255 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
10256 | DW_UNSND (attr) = 0; |
10257 | } | |
28e94949 | 10258 | |
c906108c SS |
10259 | return info_ptr; |
10260 | } | |
10261 | ||
a8329558 KW |
10262 | /* Read an attribute described by an abbreviated attribute. */ |
10263 | ||
fe1b8b76 | 10264 | static gdb_byte * |
a8329558 | 10265 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 10266 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
10267 | { |
10268 | attr->name = abbrev->name; | |
e7c27a73 | 10269 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
10270 | } |
10271 | ||
0963b4bd | 10272 | /* Read dwarf information from a buffer. */ |
c906108c SS |
10273 | |
10274 | static unsigned int | |
fe1b8b76 | 10275 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10276 | { |
fe1b8b76 | 10277 | return bfd_get_8 (abfd, buf); |
c906108c SS |
10278 | } |
10279 | ||
10280 | static int | |
fe1b8b76 | 10281 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10282 | { |
fe1b8b76 | 10283 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
10284 | } |
10285 | ||
10286 | static unsigned int | |
fe1b8b76 | 10287 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10288 | { |
fe1b8b76 | 10289 | return bfd_get_16 (abfd, buf); |
c906108c SS |
10290 | } |
10291 | ||
21ae7a4d JK |
10292 | static int |
10293 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10294 | { | |
10295 | return bfd_get_signed_16 (abfd, buf); | |
10296 | } | |
10297 | ||
c906108c | 10298 | static unsigned int |
fe1b8b76 | 10299 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10300 | { |
fe1b8b76 | 10301 | return bfd_get_32 (abfd, buf); |
c906108c SS |
10302 | } |
10303 | ||
21ae7a4d JK |
10304 | static int |
10305 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10306 | { | |
10307 | return bfd_get_signed_32 (abfd, buf); | |
10308 | } | |
10309 | ||
93311388 | 10310 | static ULONGEST |
fe1b8b76 | 10311 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10312 | { |
fe1b8b76 | 10313 | return bfd_get_64 (abfd, buf); |
c906108c SS |
10314 | } |
10315 | ||
10316 | static CORE_ADDR | |
fe1b8b76 | 10317 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 10318 | unsigned int *bytes_read) |
c906108c | 10319 | { |
e7c27a73 | 10320 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10321 | CORE_ADDR retval = 0; |
10322 | ||
107d2387 | 10323 | if (cu_header->signed_addr_p) |
c906108c | 10324 | { |
107d2387 AC |
10325 | switch (cu_header->addr_size) |
10326 | { | |
10327 | case 2: | |
fe1b8b76 | 10328 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
10329 | break; |
10330 | case 4: | |
fe1b8b76 | 10331 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
10332 | break; |
10333 | case 8: | |
fe1b8b76 | 10334 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
10335 | break; |
10336 | default: | |
8e65ff28 | 10337 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 10338 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 10339 | bfd_get_filename (abfd)); |
107d2387 AC |
10340 | } |
10341 | } | |
10342 | else | |
10343 | { | |
10344 | switch (cu_header->addr_size) | |
10345 | { | |
10346 | case 2: | |
fe1b8b76 | 10347 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
10348 | break; |
10349 | case 4: | |
fe1b8b76 | 10350 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
10351 | break; |
10352 | case 8: | |
fe1b8b76 | 10353 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
10354 | break; |
10355 | default: | |
8e65ff28 | 10356 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
10357 | _("read_address: bad switch, " |
10358 | "unsigned [in module %s]"), | |
659b0389 | 10359 | bfd_get_filename (abfd)); |
107d2387 | 10360 | } |
c906108c | 10361 | } |
64367e0a | 10362 | |
107d2387 AC |
10363 | *bytes_read = cu_header->addr_size; |
10364 | return retval; | |
c906108c SS |
10365 | } |
10366 | ||
f7ef9339 | 10367 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
10368 | specification allows the initial length to take up either 4 bytes |
10369 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
10370 | bytes describe the length and all offsets will be 8 bytes in length | |
10371 | instead of 4. | |
10372 | ||
f7ef9339 KB |
10373 | An older, non-standard 64-bit format is also handled by this |
10374 | function. The older format in question stores the initial length | |
10375 | as an 8-byte quantity without an escape value. Lengths greater | |
10376 | than 2^32 aren't very common which means that the initial 4 bytes | |
10377 | is almost always zero. Since a length value of zero doesn't make | |
10378 | sense for the 32-bit format, this initial zero can be considered to | |
10379 | be an escape value which indicates the presence of the older 64-bit | |
10380 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
10381 | greater than 4GB. If it becomes necessary to handle lengths |
10382 | somewhat larger than 4GB, we could allow other small values (such | |
10383 | as the non-sensical values of 1, 2, and 3) to also be used as | |
10384 | escape values indicating the presence of the old format. | |
f7ef9339 | 10385 | |
917c78fc MK |
10386 | The value returned via bytes_read should be used to increment the |
10387 | relevant pointer after calling read_initial_length(). | |
c764a876 | 10388 | |
613e1657 KB |
10389 | [ Note: read_initial_length() and read_offset() are based on the |
10390 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 10391 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
10392 | from: |
10393 | ||
f7ef9339 | 10394 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 10395 | |
613e1657 KB |
10396 | This document is only a draft and is subject to change. (So beware.) |
10397 | ||
f7ef9339 | 10398 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
10399 | determined empirically by examining 64-bit ELF files produced by |
10400 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
10401 | |
10402 | - Kevin, July 16, 2002 | |
613e1657 KB |
10403 | ] */ |
10404 | ||
10405 | static LONGEST | |
c764a876 | 10406 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 10407 | { |
fe1b8b76 | 10408 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 10409 | |
dd373385 | 10410 | if (length == 0xffffffff) |
613e1657 | 10411 | { |
fe1b8b76 | 10412 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 10413 | *bytes_read = 12; |
613e1657 | 10414 | } |
dd373385 | 10415 | else if (length == 0) |
f7ef9339 | 10416 | { |
dd373385 | 10417 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 10418 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 10419 | *bytes_read = 8; |
f7ef9339 | 10420 | } |
613e1657 KB |
10421 | else |
10422 | { | |
10423 | *bytes_read = 4; | |
613e1657 KB |
10424 | } |
10425 | ||
c764a876 DE |
10426 | return length; |
10427 | } | |
dd373385 | 10428 | |
c764a876 DE |
10429 | /* Cover function for read_initial_length. |
10430 | Returns the length of the object at BUF, and stores the size of the | |
10431 | initial length in *BYTES_READ and stores the size that offsets will be in | |
10432 | *OFFSET_SIZE. | |
10433 | If the initial length size is not equivalent to that specified in | |
10434 | CU_HEADER then issue a complaint. | |
10435 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 10436 | |
c764a876 DE |
10437 | static LONGEST |
10438 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
10439 | const struct comp_unit_head *cu_header, | |
10440 | unsigned int *bytes_read, | |
10441 | unsigned int *offset_size) | |
10442 | { | |
10443 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
10444 | ||
10445 | gdb_assert (cu_header->initial_length_size == 4 | |
10446 | || cu_header->initial_length_size == 8 | |
10447 | || cu_header->initial_length_size == 12); | |
10448 | ||
10449 | if (cu_header->initial_length_size != *bytes_read) | |
10450 | complaint (&symfile_complaints, | |
10451 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 10452 | |
c764a876 | 10453 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 10454 | return length; |
613e1657 KB |
10455 | } |
10456 | ||
10457 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 10458 | given by cu_header->offset_size. */ |
613e1657 KB |
10459 | |
10460 | static LONGEST | |
fe1b8b76 | 10461 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 10462 | unsigned int *bytes_read) |
c764a876 DE |
10463 | { |
10464 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 10465 | |
c764a876 DE |
10466 | *bytes_read = cu_header->offset_size; |
10467 | return offset; | |
10468 | } | |
10469 | ||
10470 | /* Read an offset from the data stream. */ | |
10471 | ||
10472 | static LONGEST | |
10473 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
10474 | { |
10475 | LONGEST retval = 0; | |
10476 | ||
c764a876 | 10477 | switch (offset_size) |
613e1657 KB |
10478 | { |
10479 | case 4: | |
fe1b8b76 | 10480 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
10481 | break; |
10482 | case 8: | |
fe1b8b76 | 10483 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
10484 | break; |
10485 | default: | |
8e65ff28 | 10486 | internal_error (__FILE__, __LINE__, |
c764a876 | 10487 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 10488 | bfd_get_filename (abfd)); |
613e1657 KB |
10489 | } |
10490 | ||
917c78fc | 10491 | return retval; |
613e1657 KB |
10492 | } |
10493 | ||
fe1b8b76 JB |
10494 | static gdb_byte * |
10495 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
10496 | { |
10497 | /* If the size of a host char is 8 bits, we can return a pointer | |
10498 | to the buffer, otherwise we have to copy the data to a buffer | |
10499 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10500 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 10501 | return buf; |
c906108c SS |
10502 | } |
10503 | ||
10504 | static char * | |
9b1c24c8 | 10505 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
10506 | { |
10507 | /* If the size of a host char is 8 bits, we can return a pointer | |
10508 | to the string, otherwise we have to copy the string to a buffer | |
10509 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10510 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
10511 | if (*buf == '\0') |
10512 | { | |
10513 | *bytes_read_ptr = 1; | |
10514 | return NULL; | |
10515 | } | |
fe1b8b76 JB |
10516 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
10517 | return (char *) buf; | |
4bdf3d34 JJ |
10518 | } |
10519 | ||
10520 | static char * | |
cf2c3c16 | 10521 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 10522 | { |
be391dca | 10523 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 10524 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
10525 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
10526 | bfd_get_filename (abfd)); | |
dce234bc | 10527 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
10528 | error (_("DW_FORM_strp pointing outside of " |
10529 | ".debug_str section [in module %s]"), | |
10530 | bfd_get_filename (abfd)); | |
4bdf3d34 | 10531 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 10532 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 10533 | return NULL; |
dce234bc | 10534 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
10535 | } |
10536 | ||
cf2c3c16 TT |
10537 | static char * |
10538 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
10539 | const struct comp_unit_head *cu_header, | |
10540 | unsigned int *bytes_read_ptr) | |
10541 | { | |
10542 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
10543 | ||
10544 | return read_indirect_string_at_offset (abfd, str_offset); | |
10545 | } | |
10546 | ||
ce5d95e1 | 10547 | static unsigned long |
fe1b8b76 | 10548 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10549 | { |
ce5d95e1 JB |
10550 | unsigned long result; |
10551 | unsigned int num_read; | |
c906108c SS |
10552 | int i, shift; |
10553 | unsigned char byte; | |
10554 | ||
10555 | result = 0; | |
10556 | shift = 0; | |
10557 | num_read = 0; | |
10558 | i = 0; | |
10559 | while (1) | |
10560 | { | |
fe1b8b76 | 10561 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10562 | buf++; |
10563 | num_read++; | |
ce5d95e1 | 10564 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
10565 | if ((byte & 128) == 0) |
10566 | { | |
10567 | break; | |
10568 | } | |
10569 | shift += 7; | |
10570 | } | |
10571 | *bytes_read_ptr = num_read; | |
10572 | return result; | |
10573 | } | |
10574 | ||
ce5d95e1 | 10575 | static long |
fe1b8b76 | 10576 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10577 | { |
ce5d95e1 | 10578 | long result; |
77e0b926 | 10579 | int i, shift, num_read; |
c906108c SS |
10580 | unsigned char byte; |
10581 | ||
10582 | result = 0; | |
10583 | shift = 0; | |
c906108c SS |
10584 | num_read = 0; |
10585 | i = 0; | |
10586 | while (1) | |
10587 | { | |
fe1b8b76 | 10588 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10589 | buf++; |
10590 | num_read++; | |
ce5d95e1 | 10591 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
10592 | shift += 7; |
10593 | if ((byte & 128) == 0) | |
10594 | { | |
10595 | break; | |
10596 | } | |
10597 | } | |
77e0b926 DJ |
10598 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
10599 | result |= -(((long)1) << shift); | |
c906108c SS |
10600 | *bytes_read_ptr = num_read; |
10601 | return result; | |
10602 | } | |
10603 | ||
4bb7a0a7 DJ |
10604 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
10605 | ||
fe1b8b76 JB |
10606 | static gdb_byte * |
10607 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
10608 | { |
10609 | int byte; | |
10610 | ||
10611 | while (1) | |
10612 | { | |
fe1b8b76 | 10613 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
10614 | buf++; |
10615 | if ((byte & 128) == 0) | |
10616 | return buf; | |
10617 | } | |
10618 | } | |
10619 | ||
c906108c | 10620 | static void |
e142c38c | 10621 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
10622 | { |
10623 | switch (lang) | |
10624 | { | |
10625 | case DW_LANG_C89: | |
76bee0cc | 10626 | case DW_LANG_C99: |
c906108c | 10627 | case DW_LANG_C: |
e142c38c | 10628 | cu->language = language_c; |
c906108c SS |
10629 | break; |
10630 | case DW_LANG_C_plus_plus: | |
e142c38c | 10631 | cu->language = language_cplus; |
c906108c | 10632 | break; |
6aecb9c2 JB |
10633 | case DW_LANG_D: |
10634 | cu->language = language_d; | |
10635 | break; | |
c906108c SS |
10636 | case DW_LANG_Fortran77: |
10637 | case DW_LANG_Fortran90: | |
b21b22e0 | 10638 | case DW_LANG_Fortran95: |
e142c38c | 10639 | cu->language = language_fortran; |
c906108c SS |
10640 | break; |
10641 | case DW_LANG_Mips_Assembler: | |
e142c38c | 10642 | cu->language = language_asm; |
c906108c | 10643 | break; |
bebd888e | 10644 | case DW_LANG_Java: |
e142c38c | 10645 | cu->language = language_java; |
bebd888e | 10646 | break; |
c906108c | 10647 | case DW_LANG_Ada83: |
8aaf0b47 | 10648 | case DW_LANG_Ada95: |
bc5f45f8 JB |
10649 | cu->language = language_ada; |
10650 | break; | |
72019c9c GM |
10651 | case DW_LANG_Modula2: |
10652 | cu->language = language_m2; | |
10653 | break; | |
fe8e67fd PM |
10654 | case DW_LANG_Pascal83: |
10655 | cu->language = language_pascal; | |
10656 | break; | |
22566fbd DJ |
10657 | case DW_LANG_ObjC: |
10658 | cu->language = language_objc; | |
10659 | break; | |
c906108c SS |
10660 | case DW_LANG_Cobol74: |
10661 | case DW_LANG_Cobol85: | |
c906108c | 10662 | default: |
e142c38c | 10663 | cu->language = language_minimal; |
c906108c SS |
10664 | break; |
10665 | } | |
e142c38c | 10666 | cu->language_defn = language_def (cu->language); |
c906108c SS |
10667 | } |
10668 | ||
10669 | /* Return the named attribute or NULL if not there. */ | |
10670 | ||
10671 | static struct attribute * | |
e142c38c | 10672 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
10673 | { |
10674 | unsigned int i; | |
10675 | struct attribute *spec = NULL; | |
10676 | ||
10677 | for (i = 0; i < die->num_attrs; ++i) | |
10678 | { | |
10679 | if (die->attrs[i].name == name) | |
10b3939b | 10680 | return &die->attrs[i]; |
c906108c SS |
10681 | if (die->attrs[i].name == DW_AT_specification |
10682 | || die->attrs[i].name == DW_AT_abstract_origin) | |
10683 | spec = &die->attrs[i]; | |
10684 | } | |
c906108c | 10685 | |
10b3939b | 10686 | if (spec) |
f2f0e013 DJ |
10687 | { |
10688 | die = follow_die_ref (die, spec, &cu); | |
10689 | return dwarf2_attr (die, name, cu); | |
10690 | } | |
c5aa993b | 10691 | |
c906108c SS |
10692 | return NULL; |
10693 | } | |
10694 | ||
348e048f DE |
10695 | /* Return the named attribute or NULL if not there, |
10696 | but do not follow DW_AT_specification, etc. | |
10697 | This is for use in contexts where we're reading .debug_types dies. | |
10698 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
10699 | back up the chain, and we want to go down. */ | |
10700 | ||
10701 | static struct attribute * | |
10702 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
10703 | struct dwarf2_cu *cu) | |
10704 | { | |
10705 | unsigned int i; | |
10706 | ||
10707 | for (i = 0; i < die->num_attrs; ++i) | |
10708 | if (die->attrs[i].name == name) | |
10709 | return &die->attrs[i]; | |
10710 | ||
10711 | return NULL; | |
10712 | } | |
10713 | ||
05cf31d1 JB |
10714 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
10715 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 10716 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
10717 | |
10718 | static int | |
10719 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
10720 | { | |
10721 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
10722 | ||
10723 | return (attr && DW_UNSND (attr)); | |
10724 | } | |
10725 | ||
3ca72b44 | 10726 | static int |
e142c38c | 10727 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 10728 | { |
05cf31d1 JB |
10729 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
10730 | which value is non-zero. However, we have to be careful with | |
10731 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
10732 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
10733 | end up accidently finding a declaration attribute that belongs | |
10734 | to a different DIE referenced by the specification attribute, | |
10735 | even though the given DIE does not have a declaration attribute. */ | |
10736 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
10737 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
10738 | } |
10739 | ||
63d06c5c | 10740 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 10741 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
10742 | containing the return value on output. If there is no |
10743 | specification, but there is an abstract origin, that is | |
10744 | returned. */ | |
63d06c5c DC |
10745 | |
10746 | static struct die_info * | |
f2f0e013 | 10747 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 10748 | { |
f2f0e013 DJ |
10749 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
10750 | *spec_cu); | |
63d06c5c | 10751 | |
edb3359d DJ |
10752 | if (spec_attr == NULL) |
10753 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
10754 | ||
63d06c5c DC |
10755 | if (spec_attr == NULL) |
10756 | return NULL; | |
10757 | else | |
f2f0e013 | 10758 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 10759 | } |
c906108c | 10760 | |
debd256d | 10761 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
10762 | refers to. |
10763 | NOTE: This is also used as a "cleanup" function. */ | |
10764 | ||
debd256d JB |
10765 | static void |
10766 | free_line_header (struct line_header *lh) | |
10767 | { | |
10768 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 10769 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
10770 | |
10771 | /* Remember that all the lh->file_names[i].name pointers are | |
10772 | pointers into debug_line_buffer, and don't need to be freed. */ | |
10773 | if (lh->file_names) | |
a8bc7b56 | 10774 | xfree (lh->file_names); |
debd256d JB |
10775 | |
10776 | /* Similarly for the include directory names. */ | |
10777 | if (lh->include_dirs) | |
a8bc7b56 | 10778 | xfree (lh->include_dirs); |
debd256d | 10779 | |
a8bc7b56 | 10780 | xfree (lh); |
debd256d JB |
10781 | } |
10782 | ||
debd256d | 10783 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 10784 | |
debd256d JB |
10785 | static void |
10786 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 10787 | { |
debd256d JB |
10788 | /* Grow the array if necessary. */ |
10789 | if (lh->include_dirs_size == 0) | |
c5aa993b | 10790 | { |
debd256d JB |
10791 | lh->include_dirs_size = 1; /* for testing */ |
10792 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
10793 | * sizeof (*lh->include_dirs)); | |
10794 | } | |
10795 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
10796 | { | |
10797 | lh->include_dirs_size *= 2; | |
10798 | lh->include_dirs = xrealloc (lh->include_dirs, | |
10799 | (lh->include_dirs_size | |
10800 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 10801 | } |
c906108c | 10802 | |
debd256d JB |
10803 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
10804 | } | |
6e70227d | 10805 | |
debd256d | 10806 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 10807 | |
debd256d JB |
10808 | static void |
10809 | add_file_name (struct line_header *lh, | |
10810 | char *name, | |
10811 | unsigned int dir_index, | |
10812 | unsigned int mod_time, | |
10813 | unsigned int length) | |
10814 | { | |
10815 | struct file_entry *fe; | |
10816 | ||
10817 | /* Grow the array if necessary. */ | |
10818 | if (lh->file_names_size == 0) | |
10819 | { | |
10820 | lh->file_names_size = 1; /* for testing */ | |
10821 | lh->file_names = xmalloc (lh->file_names_size | |
10822 | * sizeof (*lh->file_names)); | |
10823 | } | |
10824 | else if (lh->num_file_names >= lh->file_names_size) | |
10825 | { | |
10826 | lh->file_names_size *= 2; | |
10827 | lh->file_names = xrealloc (lh->file_names, | |
10828 | (lh->file_names_size | |
10829 | * sizeof (*lh->file_names))); | |
10830 | } | |
10831 | ||
10832 | fe = &lh->file_names[lh->num_file_names++]; | |
10833 | fe->name = name; | |
10834 | fe->dir_index = dir_index; | |
10835 | fe->mod_time = mod_time; | |
10836 | fe->length = length; | |
aaa75496 | 10837 | fe->included_p = 0; |
cb1df416 | 10838 | fe->symtab = NULL; |
debd256d | 10839 | } |
6e70227d | 10840 | |
debd256d | 10841 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
10842 | .debug_line, according to the endianness of ABFD. Return a pointer |
10843 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
10844 | |
10845 | NOTE: the strings in the include directory and file name tables of | |
10846 | the returned object point into debug_line_buffer, and must not be | |
10847 | freed. */ | |
ae2de4f8 | 10848 | |
debd256d JB |
10849 | static struct line_header * |
10850 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 10851 | struct dwarf2_cu *cu) |
debd256d JB |
10852 | { |
10853 | struct cleanup *back_to; | |
10854 | struct line_header *lh; | |
fe1b8b76 | 10855 | gdb_byte *line_ptr; |
c764a876 | 10856 | unsigned int bytes_read, offset_size; |
debd256d JB |
10857 | int i; |
10858 | char *cur_dir, *cur_file; | |
10859 | ||
be391dca | 10860 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 10861 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 10862 | { |
e2e0b3e5 | 10863 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
10864 | return 0; |
10865 | } | |
10866 | ||
a738430d MK |
10867 | /* Make sure that at least there's room for the total_length field. |
10868 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 10869 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 10870 | { |
4d3c2250 | 10871 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10872 | return 0; |
10873 | } | |
10874 | ||
10875 | lh = xmalloc (sizeof (*lh)); | |
10876 | memset (lh, 0, sizeof (*lh)); | |
10877 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
10878 | (void *) lh); | |
10879 | ||
dce234bc | 10880 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 10881 | |
a738430d | 10882 | /* Read in the header. */ |
6e70227d | 10883 | lh->total_length = |
c764a876 DE |
10884 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
10885 | &bytes_read, &offset_size); | |
debd256d | 10886 | line_ptr += bytes_read; |
dce234bc PP |
10887 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
10888 | + dwarf2_per_objfile->line.size)) | |
debd256d | 10889 | { |
4d3c2250 | 10890 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10891 | return 0; |
10892 | } | |
10893 | lh->statement_program_end = line_ptr + lh->total_length; | |
10894 | lh->version = read_2_bytes (abfd, line_ptr); | |
10895 | line_ptr += 2; | |
c764a876 DE |
10896 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
10897 | line_ptr += offset_size; | |
debd256d JB |
10898 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
10899 | line_ptr += 1; | |
2dc7f7b3 TT |
10900 | if (lh->version >= 4) |
10901 | { | |
10902 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
10903 | line_ptr += 1; | |
10904 | } | |
10905 | else | |
10906 | lh->maximum_ops_per_instruction = 1; | |
10907 | ||
10908 | if (lh->maximum_ops_per_instruction == 0) | |
10909 | { | |
10910 | lh->maximum_ops_per_instruction = 1; | |
10911 | complaint (&symfile_complaints, | |
3e43a32a MS |
10912 | _("invalid maximum_ops_per_instruction " |
10913 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
10914 | } |
10915 | ||
debd256d JB |
10916 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
10917 | line_ptr += 1; | |
10918 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
10919 | line_ptr += 1; | |
10920 | lh->line_range = read_1_byte (abfd, line_ptr); | |
10921 | line_ptr += 1; | |
10922 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
10923 | line_ptr += 1; | |
10924 | lh->standard_opcode_lengths | |
fe1b8b76 | 10925 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
10926 | |
10927 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
10928 | for (i = 1; i < lh->opcode_base; ++i) | |
10929 | { | |
10930 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
10931 | line_ptr += 1; | |
10932 | } | |
10933 | ||
a738430d | 10934 | /* Read directory table. */ |
9b1c24c8 | 10935 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10936 | { |
10937 | line_ptr += bytes_read; | |
10938 | add_include_dir (lh, cur_dir); | |
10939 | } | |
10940 | line_ptr += bytes_read; | |
10941 | ||
a738430d | 10942 | /* Read file name table. */ |
9b1c24c8 | 10943 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10944 | { |
10945 | unsigned int dir_index, mod_time, length; | |
10946 | ||
10947 | line_ptr += bytes_read; | |
10948 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10949 | line_ptr += bytes_read; | |
10950 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10951 | line_ptr += bytes_read; | |
10952 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10953 | line_ptr += bytes_read; | |
10954 | ||
10955 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10956 | } | |
10957 | line_ptr += bytes_read; | |
6e70227d | 10958 | lh->statement_program_start = line_ptr; |
debd256d | 10959 | |
dce234bc PP |
10960 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
10961 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 10962 | complaint (&symfile_complaints, |
3e43a32a MS |
10963 | _("line number info header doesn't " |
10964 | "fit in `.debug_line' section")); | |
debd256d JB |
10965 | |
10966 | discard_cleanups (back_to); | |
10967 | return lh; | |
10968 | } | |
c906108c | 10969 | |
c6da4cef DE |
10970 | /* Subroutine of dwarf_decode_lines to simplify it. |
10971 | Return the file name of the psymtab for included file FILE_INDEX | |
10972 | in line header LH of PST. | |
10973 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10974 | If space for the result is malloc'd, it will be freed by a cleanup. | |
10975 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
10976 | ||
10977 | static char * | |
10978 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
10979 | const struct partial_symtab *pst, | |
10980 | const char *comp_dir) | |
10981 | { | |
10982 | const struct file_entry fe = lh->file_names [file_index]; | |
10983 | char *include_name = fe.name; | |
10984 | char *include_name_to_compare = include_name; | |
10985 | char *dir_name = NULL; | |
72b9f47f TT |
10986 | const char *pst_filename; |
10987 | char *copied_name = NULL; | |
c6da4cef DE |
10988 | int file_is_pst; |
10989 | ||
10990 | if (fe.dir_index) | |
10991 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
10992 | ||
10993 | if (!IS_ABSOLUTE_PATH (include_name) | |
10994 | && (dir_name != NULL || comp_dir != NULL)) | |
10995 | { | |
10996 | /* Avoid creating a duplicate psymtab for PST. | |
10997 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
10998 | Before we do the comparison, however, we need to account | |
10999 | for DIR_NAME and COMP_DIR. | |
11000 | First prepend dir_name (if non-NULL). If we still don't | |
11001 | have an absolute path prepend comp_dir (if non-NULL). | |
11002 | However, the directory we record in the include-file's | |
11003 | psymtab does not contain COMP_DIR (to match the | |
11004 | corresponding symtab(s)). | |
11005 | ||
11006 | Example: | |
11007 | ||
11008 | bash$ cd /tmp | |
11009 | bash$ gcc -g ./hello.c | |
11010 | include_name = "hello.c" | |
11011 | dir_name = "." | |
11012 | DW_AT_comp_dir = comp_dir = "/tmp" | |
11013 | DW_AT_name = "./hello.c" */ | |
11014 | ||
11015 | if (dir_name != NULL) | |
11016 | { | |
11017 | include_name = concat (dir_name, SLASH_STRING, | |
11018 | include_name, (char *)NULL); | |
11019 | include_name_to_compare = include_name; | |
11020 | make_cleanup (xfree, include_name); | |
11021 | } | |
11022 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
11023 | { | |
11024 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
11025 | include_name, (char *)NULL); | |
11026 | } | |
11027 | } | |
11028 | ||
11029 | pst_filename = pst->filename; | |
11030 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
11031 | { | |
72b9f47f TT |
11032 | copied_name = concat (pst->dirname, SLASH_STRING, |
11033 | pst_filename, (char *)NULL); | |
11034 | pst_filename = copied_name; | |
c6da4cef DE |
11035 | } |
11036 | ||
1e3fad37 | 11037 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
11038 | |
11039 | if (include_name_to_compare != include_name) | |
11040 | xfree (include_name_to_compare); | |
72b9f47f TT |
11041 | if (copied_name != NULL) |
11042 | xfree (copied_name); | |
c6da4cef DE |
11043 | |
11044 | if (file_is_pst) | |
11045 | return NULL; | |
11046 | return include_name; | |
11047 | } | |
11048 | ||
c91513d8 PP |
11049 | /* Ignore this record_line request. */ |
11050 | ||
11051 | static void | |
11052 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
11053 | { | |
11054 | return; | |
11055 | } | |
11056 | ||
f3f5162e DE |
11057 | /* Subroutine of dwarf_decode_lines to simplify it. |
11058 | Process the line number information in LH. */ | |
debd256d | 11059 | |
c906108c | 11060 | static void |
f3f5162e DE |
11061 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
11062 | struct dwarf2_cu *cu, struct partial_symtab *pst) | |
c906108c | 11063 | { |
a8c50c1f | 11064 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 11065 | gdb_byte *line_end; |
a8c50c1f | 11066 | unsigned int bytes_read, extended_len; |
c906108c | 11067 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
11068 | CORE_ADDR baseaddr; |
11069 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 11070 | bfd *abfd = objfile->obfd; |
fbf65064 | 11071 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 11072 | const int decode_for_pst_p = (pst != NULL); |
f3f5162e | 11073 | struct subfile *last_subfile = NULL; |
c91513d8 PP |
11074 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
11075 | = record_line; | |
e142c38c DJ |
11076 | |
11077 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11078 | |
debd256d JB |
11079 | line_ptr = lh->statement_program_start; |
11080 | line_end = lh->statement_program_end; | |
c906108c SS |
11081 | |
11082 | /* Read the statement sequences until there's nothing left. */ | |
11083 | while (line_ptr < line_end) | |
11084 | { | |
11085 | /* state machine registers */ | |
11086 | CORE_ADDR address = 0; | |
11087 | unsigned int file = 1; | |
11088 | unsigned int line = 1; | |
11089 | unsigned int column = 0; | |
debd256d | 11090 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
11091 | int basic_block = 0; |
11092 | int end_sequence = 0; | |
fbf65064 | 11093 | CORE_ADDR addr; |
2dc7f7b3 | 11094 | unsigned char op_index = 0; |
c906108c | 11095 | |
aaa75496 | 11096 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 11097 | { |
aaa75496 | 11098 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
11099 | /* lh->include_dirs and lh->file_names are 0-based, but the |
11100 | directory and file name numbers in the statement program | |
11101 | are 1-based. */ | |
11102 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 11103 | char *dir = NULL; |
a738430d | 11104 | |
debd256d JB |
11105 | if (fe->dir_index) |
11106 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
11107 | |
11108 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
11109 | } |
11110 | ||
a738430d | 11111 | /* Decode the table. */ |
c5aa993b | 11112 | while (!end_sequence) |
c906108c SS |
11113 | { |
11114 | op_code = read_1_byte (abfd, line_ptr); | |
11115 | line_ptr += 1; | |
59205f5a JB |
11116 | if (line_ptr > line_end) |
11117 | { | |
11118 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
11119 | break; | |
11120 | } | |
9aa1fe7e | 11121 | |
debd256d | 11122 | if (op_code >= lh->opcode_base) |
6e70227d | 11123 | { |
a738430d | 11124 | /* Special operand. */ |
debd256d | 11125 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
11126 | address += (((op_index + (adj_opcode / lh->line_range)) |
11127 | / lh->maximum_ops_per_instruction) | |
11128 | * lh->minimum_instruction_length); | |
11129 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
11130 | % lh->maximum_ops_per_instruction); | |
debd256d | 11131 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 11132 | if (lh->num_file_names < file || file == 0) |
25e43795 | 11133 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
11134 | /* For now we ignore lines not starting on an |
11135 | instruction boundary. */ | |
11136 | else if (op_index == 0) | |
25e43795 DJ |
11137 | { |
11138 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 11139 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11140 | { |
11141 | if (last_subfile != current_subfile) | |
11142 | { | |
11143 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11144 | if (last_subfile) | |
c91513d8 | 11145 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11146 | last_subfile = current_subfile; |
11147 | } | |
25e43795 | 11148 | /* Append row to matrix using current values. */ |
7019d805 | 11149 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11150 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 11151 | } |
25e43795 | 11152 | } |
ca5f395d | 11153 | basic_block = 0; |
9aa1fe7e GK |
11154 | } |
11155 | else switch (op_code) | |
c906108c SS |
11156 | { |
11157 | case DW_LNS_extended_op: | |
3e43a32a MS |
11158 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
11159 | &bytes_read); | |
473b7be6 | 11160 | line_ptr += bytes_read; |
a8c50c1f | 11161 | extended_end = line_ptr + extended_len; |
c906108c SS |
11162 | extended_op = read_1_byte (abfd, line_ptr); |
11163 | line_ptr += 1; | |
11164 | switch (extended_op) | |
11165 | { | |
11166 | case DW_LNE_end_sequence: | |
c91513d8 | 11167 | p_record_line = record_line; |
c906108c | 11168 | end_sequence = 1; |
c906108c SS |
11169 | break; |
11170 | case DW_LNE_set_address: | |
e7c27a73 | 11171 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
11172 | |
11173 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11174 | { | |
11175 | /* This line table is for a function which has been | |
11176 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
11177 | ||
11178 | long line_offset | |
11179 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
11180 | ||
11181 | complaint (&symfile_complaints, | |
11182 | _(".debug_line address at offset 0x%lx is 0 " | |
11183 | "[in module %s]"), | |
bb5ed363 | 11184 | line_offset, objfile->name); |
c91513d8 PP |
11185 | p_record_line = noop_record_line; |
11186 | } | |
11187 | ||
2dc7f7b3 | 11188 | op_index = 0; |
107d2387 AC |
11189 | line_ptr += bytes_read; |
11190 | address += baseaddr; | |
c906108c SS |
11191 | break; |
11192 | case DW_LNE_define_file: | |
debd256d JB |
11193 | { |
11194 | char *cur_file; | |
11195 | unsigned int dir_index, mod_time, length; | |
6e70227d | 11196 | |
3e43a32a MS |
11197 | cur_file = read_direct_string (abfd, line_ptr, |
11198 | &bytes_read); | |
debd256d JB |
11199 | line_ptr += bytes_read; |
11200 | dir_index = | |
11201 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11202 | line_ptr += bytes_read; | |
11203 | mod_time = | |
11204 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11205 | line_ptr += bytes_read; | |
11206 | length = | |
11207 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11208 | line_ptr += bytes_read; | |
11209 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
11210 | } | |
c906108c | 11211 | break; |
d0c6ba3d CC |
11212 | case DW_LNE_set_discriminator: |
11213 | /* The discriminator is not interesting to the debugger; | |
11214 | just ignore it. */ | |
11215 | line_ptr = extended_end; | |
11216 | break; | |
c906108c | 11217 | default: |
4d3c2250 | 11218 | complaint (&symfile_complaints, |
e2e0b3e5 | 11219 | _("mangled .debug_line section")); |
debd256d | 11220 | return; |
c906108c | 11221 | } |
a8c50c1f DJ |
11222 | /* Make sure that we parsed the extended op correctly. If e.g. |
11223 | we expected a different address size than the producer used, | |
11224 | we may have read the wrong number of bytes. */ | |
11225 | if (line_ptr != extended_end) | |
11226 | { | |
11227 | complaint (&symfile_complaints, | |
11228 | _("mangled .debug_line section")); | |
11229 | return; | |
11230 | } | |
c906108c SS |
11231 | break; |
11232 | case DW_LNS_copy: | |
59205f5a | 11233 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11234 | dwarf2_debug_line_missing_file_complaint (); |
11235 | else | |
366da635 | 11236 | { |
25e43795 | 11237 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 11238 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11239 | { |
11240 | if (last_subfile != current_subfile) | |
11241 | { | |
11242 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11243 | if (last_subfile) | |
c91513d8 | 11244 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11245 | last_subfile = current_subfile; |
11246 | } | |
7019d805 | 11247 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11248 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 11249 | } |
366da635 | 11250 | } |
c906108c SS |
11251 | basic_block = 0; |
11252 | break; | |
11253 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
11254 | { |
11255 | CORE_ADDR adjust | |
11256 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11257 | ||
11258 | address += (((op_index + adjust) | |
11259 | / lh->maximum_ops_per_instruction) | |
11260 | * lh->minimum_instruction_length); | |
11261 | op_index = ((op_index + adjust) | |
11262 | % lh->maximum_ops_per_instruction); | |
11263 | line_ptr += bytes_read; | |
11264 | } | |
c906108c SS |
11265 | break; |
11266 | case DW_LNS_advance_line: | |
11267 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
11268 | line_ptr += bytes_read; | |
11269 | break; | |
11270 | case DW_LNS_set_file: | |
debd256d | 11271 | { |
a738430d MK |
11272 | /* The arrays lh->include_dirs and lh->file_names are |
11273 | 0-based, but the directory and file name numbers in | |
11274 | the statement program are 1-based. */ | |
debd256d | 11275 | struct file_entry *fe; |
4f1520fb | 11276 | char *dir = NULL; |
a738430d | 11277 | |
debd256d JB |
11278 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
11279 | line_ptr += bytes_read; | |
59205f5a | 11280 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11281 | dwarf2_debug_line_missing_file_complaint (); |
11282 | else | |
11283 | { | |
11284 | fe = &lh->file_names[file - 1]; | |
11285 | if (fe->dir_index) | |
11286 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11287 | if (!decode_for_pst_p) | |
11288 | { | |
11289 | last_subfile = current_subfile; | |
11290 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11291 | } | |
11292 | } | |
debd256d | 11293 | } |
c906108c SS |
11294 | break; |
11295 | case DW_LNS_set_column: | |
11296 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11297 | line_ptr += bytes_read; | |
11298 | break; | |
11299 | case DW_LNS_negate_stmt: | |
11300 | is_stmt = (!is_stmt); | |
11301 | break; | |
11302 | case DW_LNS_set_basic_block: | |
11303 | basic_block = 1; | |
11304 | break; | |
c2c6d25f JM |
11305 | /* Add to the address register of the state machine the |
11306 | address increment value corresponding to special opcode | |
a738430d MK |
11307 | 255. I.e., this value is scaled by the minimum |
11308 | instruction length since special opcode 255 would have | |
b021a221 | 11309 | scaled the increment. */ |
c906108c | 11310 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
11311 | { |
11312 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
11313 | ||
11314 | address += (((op_index + adjust) | |
11315 | / lh->maximum_ops_per_instruction) | |
11316 | * lh->minimum_instruction_length); | |
11317 | op_index = ((op_index + adjust) | |
11318 | % lh->maximum_ops_per_instruction); | |
11319 | } | |
c906108c SS |
11320 | break; |
11321 | case DW_LNS_fixed_advance_pc: | |
11322 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 11323 | op_index = 0; |
c906108c SS |
11324 | line_ptr += 2; |
11325 | break; | |
9aa1fe7e | 11326 | default: |
a738430d MK |
11327 | { |
11328 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 11329 | int i; |
a738430d | 11330 | |
debd256d | 11331 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
11332 | { |
11333 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11334 | line_ptr += bytes_read; | |
11335 | } | |
11336 | } | |
c906108c SS |
11337 | } |
11338 | } | |
59205f5a JB |
11339 | if (lh->num_file_names < file || file == 0) |
11340 | dwarf2_debug_line_missing_file_complaint (); | |
11341 | else | |
11342 | { | |
11343 | lh->file_names[file - 1].included_p = 1; | |
11344 | if (!decode_for_pst_p) | |
fbf65064 UW |
11345 | { |
11346 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 11347 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 11348 | } |
59205f5a | 11349 | } |
c906108c | 11350 | } |
f3f5162e DE |
11351 | } |
11352 | ||
11353 | /* Decode the Line Number Program (LNP) for the given line_header | |
11354 | structure and CU. The actual information extracted and the type | |
11355 | of structures created from the LNP depends on the value of PST. | |
11356 | ||
11357 | 1. If PST is NULL, then this procedure uses the data from the program | |
11358 | to create all necessary symbol tables, and their linetables. | |
11359 | ||
11360 | 2. If PST is not NULL, this procedure reads the program to determine | |
11361 | the list of files included by the unit represented by PST, and | |
11362 | builds all the associated partial symbol tables. | |
11363 | ||
11364 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11365 | It is used for relative paths in the line table. | |
11366 | NOTE: When processing partial symtabs (pst != NULL), | |
11367 | comp_dir == pst->dirname. | |
11368 | ||
11369 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
11370 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
11371 | symtab we don't use it in the name of the psymtabs we create. | |
11372 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
11373 | A good testcase for this is mb-inline.exp. */ | |
11374 | ||
11375 | static void | |
11376 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
11377 | struct dwarf2_cu *cu, struct partial_symtab *pst, | |
11378 | int want_line_info) | |
11379 | { | |
11380 | struct objfile *objfile = cu->objfile; | |
11381 | const int decode_for_pst_p = (pst != NULL); | |
11382 | struct subfile *first_subfile = current_subfile; | |
11383 | ||
11384 | if (want_line_info) | |
11385 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); | |
aaa75496 JB |
11386 | |
11387 | if (decode_for_pst_p) | |
11388 | { | |
11389 | int file_index; | |
11390 | ||
11391 | /* Now that we're done scanning the Line Header Program, we can | |
11392 | create the psymtab of each included file. */ | |
11393 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
11394 | if (lh->file_names[file_index].included_p == 1) | |
11395 | { | |
c6da4cef DE |
11396 | char *include_name = |
11397 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
11398 | if (include_name != NULL) | |
aaa75496 JB |
11399 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
11400 | } | |
11401 | } | |
cb1df416 DJ |
11402 | else |
11403 | { | |
11404 | /* Make sure a symtab is created for every file, even files | |
11405 | which contain only variables (i.e. no code with associated | |
11406 | line numbers). */ | |
cb1df416 | 11407 | int i; |
cb1df416 DJ |
11408 | |
11409 | for (i = 0; i < lh->num_file_names; i++) | |
11410 | { | |
11411 | char *dir = NULL; | |
f3f5162e | 11412 | struct file_entry *fe; |
9a619af0 | 11413 | |
cb1df416 DJ |
11414 | fe = &lh->file_names[i]; |
11415 | if (fe->dir_index) | |
11416 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11417 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11418 | ||
11419 | /* Skip the main file; we don't need it, and it must be | |
11420 | allocated last, so that it will show up before the | |
11421 | non-primary symtabs in the objfile's symtab list. */ | |
11422 | if (current_subfile == first_subfile) | |
11423 | continue; | |
11424 | ||
11425 | if (current_subfile->symtab == NULL) | |
11426 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 11427 | objfile); |
cb1df416 DJ |
11428 | fe->symtab = current_subfile->symtab; |
11429 | } | |
11430 | } | |
c906108c SS |
11431 | } |
11432 | ||
11433 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
11434 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
11435 | or NULL if not known. COMP_DIR is the compilation directory for the |
11436 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
11437 | This routine tries to keep line numbers from identical absolute and |
11438 | relative file names in a common subfile. | |
11439 | ||
11440 | Using the `list' example from the GDB testsuite, which resides in | |
11441 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
11442 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
11443 | ||
c5aa993b JM |
11444 | DW_AT_name: /srcdir/list0.c |
11445 | DW_AT_comp_dir: /compdir | |
357e46e7 | 11446 | files.files[0].name: list0.h |
c5aa993b | 11447 | files.files[0].dir: /srcdir |
357e46e7 | 11448 | files.files[1].name: list0.c |
c5aa993b | 11449 | files.files[1].dir: /srcdir |
c906108c SS |
11450 | |
11451 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
11452 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
11453 | start_subfile will ensure that this happens provided that we pass the | |
11454 | concatenation of files.files[1].dir and files.files[1].name as the | |
11455 | subfile's name. */ | |
c906108c SS |
11456 | |
11457 | static void | |
3e43a32a MS |
11458 | dwarf2_start_subfile (char *filename, const char *dirname, |
11459 | const char *comp_dir) | |
c906108c | 11460 | { |
4f1520fb FR |
11461 | char *fullname; |
11462 | ||
11463 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
11464 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
11465 | second argument to start_subfile. To be consistent, we do the | |
11466 | same here. In order not to lose the line information directory, | |
11467 | we concatenate it to the filename when it makes sense. | |
11468 | Note that the Dwarf3 standard says (speaking of filenames in line | |
11469 | information): ``The directory index is ignored for file names | |
11470 | that represent full path names''. Thus ignoring dirname in the | |
11471 | `else' branch below isn't an issue. */ | |
c906108c | 11472 | |
d5166ae1 | 11473 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
11474 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
11475 | else | |
11476 | fullname = filename; | |
c906108c | 11477 | |
4f1520fb FR |
11478 | start_subfile (fullname, comp_dir); |
11479 | ||
11480 | if (fullname != filename) | |
11481 | xfree (fullname); | |
c906108c SS |
11482 | } |
11483 | ||
4c2df51b DJ |
11484 | static void |
11485 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11486 | struct dwarf2_cu *cu) |
4c2df51b | 11487 | { |
e7c27a73 DJ |
11488 | struct objfile *objfile = cu->objfile; |
11489 | struct comp_unit_head *cu_header = &cu->header; | |
11490 | ||
4c2df51b DJ |
11491 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
11492 | code here to turn a symbol with DW_AT_external and a | |
11493 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
11494 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
11495 | with some versions of binutils) where shared libraries could have | |
11496 | relocations against symbols in their debug information - the | |
11497 | minimal symbol would have the right address, but the debug info | |
11498 | would not. It's no longer necessary, because we will explicitly | |
11499 | apply relocations when we read in the debug information now. */ | |
11500 | ||
11501 | /* A DW_AT_location attribute with no contents indicates that a | |
11502 | variable has been optimized away. */ | |
11503 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
11504 | { | |
11505 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
11506 | return; | |
11507 | } | |
11508 | ||
11509 | /* Handle one degenerate form of location expression specially, to | |
11510 | preserve GDB's previous behavior when section offsets are | |
11511 | specified. If this is just a DW_OP_addr then mark this symbol | |
11512 | as LOC_STATIC. */ | |
11513 | ||
11514 | if (attr_form_is_block (attr) | |
11515 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
11516 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
11517 | { | |
891d2f0b | 11518 | unsigned int dummy; |
4c2df51b DJ |
11519 | |
11520 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 11521 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 11522 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
11523 | fixup_symbol_section (sym, objfile); |
11524 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
11525 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
11526 | return; |
11527 | } | |
11528 | ||
11529 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
11530 | expression evaluator, and use LOC_COMPUTED only when necessary | |
11531 | (i.e. when the value of a register or memory location is | |
11532 | referenced, or a thread-local block, etc.). Then again, it might | |
11533 | not be worthwhile. I'm assuming that it isn't unless performance | |
11534 | or memory numbers show me otherwise. */ | |
11535 | ||
e7c27a73 | 11536 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 11537 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
11538 | |
11539 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
11540 | cu->has_loclist = 1; | |
4c2df51b DJ |
11541 | } |
11542 | ||
c906108c SS |
11543 | /* Given a pointer to a DWARF information entry, figure out if we need |
11544 | to make a symbol table entry for it, and if so, create a new entry | |
11545 | and return a pointer to it. | |
11546 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
11547 | used the passed type. |
11548 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
11549 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
11550 | |
11551 | static struct symbol * | |
34eaf542 TT |
11552 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
11553 | struct symbol *space) | |
c906108c | 11554 | { |
e7c27a73 | 11555 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11556 | struct symbol *sym = NULL; |
11557 | char *name; | |
11558 | struct attribute *attr = NULL; | |
11559 | struct attribute *attr2 = NULL; | |
e142c38c | 11560 | CORE_ADDR baseaddr; |
e37fd15a SW |
11561 | struct pending **list_to_add = NULL; |
11562 | ||
edb3359d | 11563 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
11564 | |
11565 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11566 | |
94af9270 | 11567 | name = dwarf2_name (die, cu); |
c906108c SS |
11568 | if (name) |
11569 | { | |
94af9270 | 11570 | const char *linkagename; |
34eaf542 | 11571 | int suppress_add = 0; |
94af9270 | 11572 | |
34eaf542 TT |
11573 | if (space) |
11574 | sym = space; | |
11575 | else | |
11576 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 11577 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
11578 | |
11579 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 11580 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
11581 | linkagename = dwarf2_physname (name, die, cu); |
11582 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 11583 | |
f55ee35c JK |
11584 | /* Fortran does not have mangling standard and the mangling does differ |
11585 | between gfortran, iFort etc. */ | |
11586 | if (cu->language == language_fortran | |
b250c185 | 11587 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
11588 | symbol_set_demangled_name (&(sym->ginfo), |
11589 | (char *) dwarf2_full_name (name, die, cu), | |
11590 | NULL); | |
f55ee35c | 11591 | |
c906108c | 11592 | /* Default assumptions. |
c5aa993b | 11593 | Use the passed type or decode it from the die. */ |
176620f1 | 11594 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 11595 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
11596 | if (type != NULL) |
11597 | SYMBOL_TYPE (sym) = type; | |
11598 | else | |
e7c27a73 | 11599 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
11600 | attr = dwarf2_attr (die, |
11601 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
11602 | cu); | |
c906108c SS |
11603 | if (attr) |
11604 | { | |
11605 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
11606 | } | |
cb1df416 | 11607 | |
edb3359d DJ |
11608 | attr = dwarf2_attr (die, |
11609 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
11610 | cu); | |
cb1df416 DJ |
11611 | if (attr) |
11612 | { | |
11613 | int file_index = DW_UNSND (attr); | |
9a619af0 | 11614 | |
cb1df416 DJ |
11615 | if (cu->line_header == NULL |
11616 | || file_index > cu->line_header->num_file_names) | |
11617 | complaint (&symfile_complaints, | |
11618 | _("file index out of range")); | |
1c3d648d | 11619 | else if (file_index > 0) |
cb1df416 DJ |
11620 | { |
11621 | struct file_entry *fe; | |
9a619af0 | 11622 | |
cb1df416 DJ |
11623 | fe = &cu->line_header->file_names[file_index - 1]; |
11624 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
11625 | } | |
11626 | } | |
11627 | ||
c906108c SS |
11628 | switch (die->tag) |
11629 | { | |
11630 | case DW_TAG_label: | |
e142c38c | 11631 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
11632 | if (attr) |
11633 | { | |
11634 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
11635 | } | |
0f5238ed TT |
11636 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
11637 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 11638 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 11639 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
11640 | break; |
11641 | case DW_TAG_subprogram: | |
11642 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11643 | finish_block. */ | |
11644 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 11645 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
11646 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
11647 | || cu->language == language_ada) | |
c906108c | 11648 | { |
2cfa0c8d JB |
11649 | /* Subprograms marked external are stored as a global symbol. |
11650 | Ada subprograms, whether marked external or not, are always | |
11651 | stored as a global symbol, because we want to be able to | |
11652 | access them globally. For instance, we want to be able | |
11653 | to break on a nested subprogram without having to | |
11654 | specify the context. */ | |
e37fd15a | 11655 | list_to_add = &global_symbols; |
c906108c SS |
11656 | } |
11657 | else | |
11658 | { | |
e37fd15a | 11659 | list_to_add = cu->list_in_scope; |
c906108c SS |
11660 | } |
11661 | break; | |
edb3359d DJ |
11662 | case DW_TAG_inlined_subroutine: |
11663 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11664 | finish_block. */ | |
11665 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11666 | SYMBOL_INLINED (sym) = 1; | |
11667 | /* Do not add the symbol to any lists. It will be found via | |
11668 | BLOCK_FUNCTION from the blockvector. */ | |
11669 | break; | |
34eaf542 TT |
11670 | case DW_TAG_template_value_param: |
11671 | suppress_add = 1; | |
11672 | /* Fall through. */ | |
72929c62 | 11673 | case DW_TAG_constant: |
c906108c | 11674 | case DW_TAG_variable: |
254e6b9e | 11675 | case DW_TAG_member: |
0963b4bd MS |
11676 | /* Compilation with minimal debug info may result in |
11677 | variables with missing type entries. Change the | |
11678 | misleading `void' type to something sensible. */ | |
c906108c | 11679 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 11680 | SYMBOL_TYPE (sym) |
46bf5051 | 11681 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 11682 | |
e142c38c | 11683 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
11684 | /* In the case of DW_TAG_member, we should only be called for |
11685 | static const members. */ | |
11686 | if (die->tag == DW_TAG_member) | |
11687 | { | |
3863f96c DE |
11688 | /* dwarf2_add_field uses die_is_declaration, |
11689 | so we do the same. */ | |
254e6b9e DE |
11690 | gdb_assert (die_is_declaration (die, cu)); |
11691 | gdb_assert (attr); | |
11692 | } | |
c906108c SS |
11693 | if (attr) |
11694 | { | |
e7c27a73 | 11695 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 11696 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 11697 | if (!suppress_add) |
34eaf542 TT |
11698 | { |
11699 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 11700 | list_to_add = &global_symbols; |
34eaf542 | 11701 | else |
e37fd15a | 11702 | list_to_add = cu->list_in_scope; |
34eaf542 | 11703 | } |
c906108c SS |
11704 | break; |
11705 | } | |
e142c38c | 11706 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11707 | if (attr) |
11708 | { | |
e7c27a73 | 11709 | var_decode_location (attr, sym, cu); |
e142c38c | 11710 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
11711 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
11712 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
11713 | && !dwarf2_per_objfile->has_section_at_zero) | |
11714 | { | |
11715 | /* When a static variable is eliminated by the linker, | |
11716 | the corresponding debug information is not stripped | |
11717 | out, but the variable address is set to null; | |
11718 | do not add such variables into symbol table. */ | |
11719 | } | |
11720 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 11721 | { |
f55ee35c JK |
11722 | /* Workaround gfortran PR debug/40040 - it uses |
11723 | DW_AT_location for variables in -fPIC libraries which may | |
11724 | get overriden by other libraries/executable and get | |
11725 | a different address. Resolve it by the minimal symbol | |
11726 | which may come from inferior's executable using copy | |
11727 | relocation. Make this workaround only for gfortran as for | |
11728 | other compilers GDB cannot guess the minimal symbol | |
11729 | Fortran mangling kind. */ | |
11730 | if (cu->language == language_fortran && die->parent | |
11731 | && die->parent->tag == DW_TAG_module | |
11732 | && cu->producer | |
11733 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
11734 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
11735 | ||
1c809c68 TT |
11736 | /* A variable with DW_AT_external is never static, |
11737 | but it may be block-scoped. */ | |
11738 | list_to_add = (cu->list_in_scope == &file_symbols | |
11739 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 11740 | } |
c906108c | 11741 | else |
e37fd15a | 11742 | list_to_add = cu->list_in_scope; |
c906108c SS |
11743 | } |
11744 | else | |
11745 | { | |
11746 | /* We do not know the address of this symbol. | |
c5aa993b JM |
11747 | If it is an external symbol and we have type information |
11748 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
11749 | The address of the variable will then be determined from | |
11750 | the minimal symbol table whenever the variable is | |
11751 | referenced. */ | |
e142c38c | 11752 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 11753 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 11754 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 11755 | { |
0fe7935b DJ |
11756 | /* A variable with DW_AT_external is never static, but it |
11757 | may be block-scoped. */ | |
11758 | list_to_add = (cu->list_in_scope == &file_symbols | |
11759 | ? &global_symbols : cu->list_in_scope); | |
11760 | ||
c906108c | 11761 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 11762 | } |
442ddf59 JK |
11763 | else if (!die_is_declaration (die, cu)) |
11764 | { | |
11765 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
11766 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
11767 | if (!suppress_add) |
11768 | list_to_add = cu->list_in_scope; | |
442ddf59 | 11769 | } |
c906108c SS |
11770 | } |
11771 | break; | |
11772 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
11773 | /* If we are inside a function, mark this as an argument. If |
11774 | not, we might be looking at an argument to an inlined function | |
11775 | when we do not have enough information to show inlined frames; | |
11776 | pretend it's a local variable in that case so that the user can | |
11777 | still see it. */ | |
11778 | if (context_stack_depth > 0 | |
11779 | && context_stack[context_stack_depth - 1].name != NULL) | |
11780 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 11781 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11782 | if (attr) |
11783 | { | |
e7c27a73 | 11784 | var_decode_location (attr, sym, cu); |
c906108c | 11785 | } |
e142c38c | 11786 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11787 | if (attr) |
11788 | { | |
e7c27a73 | 11789 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11790 | } |
f346a30d | 11791 | |
e37fd15a | 11792 | list_to_add = cu->list_in_scope; |
c906108c SS |
11793 | break; |
11794 | case DW_TAG_unspecified_parameters: | |
11795 | /* From varargs functions; gdb doesn't seem to have any | |
11796 | interest in this information, so just ignore it for now. | |
11797 | (FIXME?) */ | |
11798 | break; | |
34eaf542 TT |
11799 | case DW_TAG_template_type_param: |
11800 | suppress_add = 1; | |
11801 | /* Fall through. */ | |
c906108c | 11802 | case DW_TAG_class_type: |
680b30c7 | 11803 | case DW_TAG_interface_type: |
c906108c SS |
11804 | case DW_TAG_structure_type: |
11805 | case DW_TAG_union_type: | |
72019c9c | 11806 | case DW_TAG_set_type: |
c906108c SS |
11807 | case DW_TAG_enumeration_type: |
11808 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 11809 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 11810 | |
63d06c5c | 11811 | { |
987504bb | 11812 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
11813 | really ever be static objects: otherwise, if you try |
11814 | to, say, break of a class's method and you're in a file | |
11815 | which doesn't mention that class, it won't work unless | |
11816 | the check for all static symbols in lookup_symbol_aux | |
11817 | saves you. See the OtherFileClass tests in | |
11818 | gdb.c++/namespace.exp. */ | |
11819 | ||
e37fd15a | 11820 | if (!suppress_add) |
34eaf542 | 11821 | { |
34eaf542 TT |
11822 | list_to_add = (cu->list_in_scope == &file_symbols |
11823 | && (cu->language == language_cplus | |
11824 | || cu->language == language_java) | |
11825 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 11826 | |
64382290 TT |
11827 | /* The semantics of C++ state that "struct foo { |
11828 | ... }" also defines a typedef for "foo". A Java | |
11829 | class declaration also defines a typedef for the | |
11830 | class. */ | |
11831 | if (cu->language == language_cplus | |
11832 | || cu->language == language_java | |
11833 | || cu->language == language_ada) | |
11834 | { | |
11835 | /* The symbol's name is already allocated along | |
11836 | with this objfile, so we don't need to | |
11837 | duplicate it for the type. */ | |
11838 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
11839 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
11840 | } | |
63d06c5c DC |
11841 | } |
11842 | } | |
c906108c SS |
11843 | break; |
11844 | case DW_TAG_typedef: | |
63d06c5c DC |
11845 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
11846 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 11847 | list_to_add = cu->list_in_scope; |
63d06c5c | 11848 | break; |
c906108c | 11849 | case DW_TAG_base_type: |
a02abb62 | 11850 | case DW_TAG_subrange_type: |
c906108c | 11851 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 11852 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 11853 | list_to_add = cu->list_in_scope; |
c906108c SS |
11854 | break; |
11855 | case DW_TAG_enumerator: | |
e142c38c | 11856 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11857 | if (attr) |
11858 | { | |
e7c27a73 | 11859 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11860 | } |
63d06c5c DC |
11861 | { |
11862 | /* NOTE: carlton/2003-11-10: See comment above in the | |
11863 | DW_TAG_class_type, etc. block. */ | |
11864 | ||
e142c38c | 11865 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
11866 | && (cu->language == language_cplus |
11867 | || cu->language == language_java) | |
e142c38c | 11868 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 11869 | } |
c906108c | 11870 | break; |
5c4e30ca DC |
11871 | case DW_TAG_namespace: |
11872 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 11873 | list_to_add = &global_symbols; |
5c4e30ca | 11874 | break; |
c906108c SS |
11875 | default: |
11876 | /* Not a tag we recognize. Hopefully we aren't processing | |
11877 | trash data, but since we must specifically ignore things | |
11878 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 11879 | this point. */ |
e2e0b3e5 | 11880 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 11881 | dwarf_tag_name (die->tag)); |
c906108c SS |
11882 | break; |
11883 | } | |
df8a16a1 | 11884 | |
e37fd15a SW |
11885 | if (suppress_add) |
11886 | { | |
11887 | sym->hash_next = objfile->template_symbols; | |
11888 | objfile->template_symbols = sym; | |
11889 | list_to_add = NULL; | |
11890 | } | |
11891 | ||
11892 | if (list_to_add != NULL) | |
11893 | add_symbol_to_list (sym, list_to_add); | |
11894 | ||
df8a16a1 DJ |
11895 | /* For the benefit of old versions of GCC, check for anonymous |
11896 | namespaces based on the demangled name. */ | |
11897 | if (!processing_has_namespace_info | |
94af9270 | 11898 | && cu->language == language_cplus) |
a10964d1 | 11899 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
11900 | } |
11901 | return (sym); | |
11902 | } | |
11903 | ||
34eaf542 TT |
11904 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
11905 | ||
11906 | static struct symbol * | |
11907 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
11908 | { | |
11909 | return new_symbol_full (die, type, cu, NULL); | |
11910 | } | |
11911 | ||
98bfdba5 PA |
11912 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
11913 | zero-extend it as appropriate for the symbol's type. The DWARF | |
11914 | standard (v4) is not entirely clear about the meaning of using | |
11915 | DW_FORM_dataN for a constant with a signed type, where the type is | |
11916 | wider than the data. The conclusion of a discussion on the DWARF | |
11917 | list was that this is unspecified. We choose to always zero-extend | |
11918 | because that is the interpretation long in use by GCC. */ | |
c906108c | 11919 | |
98bfdba5 PA |
11920 | static gdb_byte * |
11921 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
11922 | const char *name, struct obstack *obstack, | |
11923 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 11924 | { |
e7c27a73 | 11925 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
11926 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
11927 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
11928 | LONGEST l = DW_UNSND (attr); |
11929 | ||
11930 | if (bits < sizeof (*value) * 8) | |
11931 | { | |
11932 | l &= ((LONGEST) 1 << bits) - 1; | |
11933 | *value = l; | |
11934 | } | |
11935 | else if (bits == sizeof (*value) * 8) | |
11936 | *value = l; | |
11937 | else | |
11938 | { | |
11939 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
11940 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
11941 | return bytes; | |
11942 | } | |
11943 | ||
11944 | return NULL; | |
11945 | } | |
11946 | ||
11947 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
11948 | the value does not fit in *VALUE, set *BYTES - either already | |
11949 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
11950 | or, set *BATON, if we translated the constant to a location | |
11951 | expression. */ | |
11952 | ||
11953 | static void | |
11954 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
11955 | const char *name, struct obstack *obstack, | |
11956 | struct dwarf2_cu *cu, | |
11957 | long *value, gdb_byte **bytes, | |
11958 | struct dwarf2_locexpr_baton **baton) | |
11959 | { | |
11960 | struct objfile *objfile = cu->objfile; | |
11961 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 11962 | struct dwarf_block *blk; |
98bfdba5 PA |
11963 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
11964 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
11965 | ||
11966 | *value = 0; | |
11967 | *bytes = NULL; | |
11968 | *baton = NULL; | |
c906108c SS |
11969 | |
11970 | switch (attr->form) | |
11971 | { | |
11972 | case DW_FORM_addr: | |
ac56253d | 11973 | { |
ac56253d TT |
11974 | gdb_byte *data; |
11975 | ||
98bfdba5 PA |
11976 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
11977 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 11978 | cu_header->addr_size, |
98bfdba5 | 11979 | TYPE_LENGTH (type)); |
ac56253d TT |
11980 | /* Symbols of this form are reasonably rare, so we just |
11981 | piggyback on the existing location code rather than writing | |
11982 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
11983 | *baton = obstack_alloc (&objfile->objfile_obstack, |
11984 | sizeof (struct dwarf2_locexpr_baton)); | |
11985 | (*baton)->per_cu = cu->per_cu; | |
11986 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 11987 | |
98bfdba5 PA |
11988 | (*baton)->size = 2 + cu_header->addr_size; |
11989 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
11990 | (*baton)->data = data; | |
ac56253d TT |
11991 | |
11992 | data[0] = DW_OP_addr; | |
11993 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
11994 | byte_order, DW_ADDR (attr)); | |
11995 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 11996 | } |
c906108c | 11997 | break; |
4ac36638 | 11998 | case DW_FORM_string: |
93b5768b | 11999 | case DW_FORM_strp: |
98bfdba5 PA |
12000 | /* DW_STRING is already allocated on the objfile obstack, point |
12001 | directly to it. */ | |
12002 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 12003 | break; |
c906108c SS |
12004 | case DW_FORM_block1: |
12005 | case DW_FORM_block2: | |
12006 | case DW_FORM_block4: | |
12007 | case DW_FORM_block: | |
2dc7f7b3 | 12008 | case DW_FORM_exprloc: |
c906108c | 12009 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
12010 | if (TYPE_LENGTH (type) != blk->size) |
12011 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
12012 | TYPE_LENGTH (type)); | |
12013 | *bytes = blk->data; | |
c906108c | 12014 | break; |
2df3850c JM |
12015 | |
12016 | /* The DW_AT_const_value attributes are supposed to carry the | |
12017 | symbol's value "represented as it would be on the target | |
12018 | architecture." By the time we get here, it's already been | |
12019 | converted to host endianness, so we just need to sign- or | |
12020 | zero-extend it as appropriate. */ | |
12021 | case DW_FORM_data1: | |
3e43a32a MS |
12022 | *bytes = dwarf2_const_value_data (attr, type, name, |
12023 | obstack, cu, value, 8); | |
2df3850c | 12024 | break; |
c906108c | 12025 | case DW_FORM_data2: |
3e43a32a MS |
12026 | *bytes = dwarf2_const_value_data (attr, type, name, |
12027 | obstack, cu, value, 16); | |
2df3850c | 12028 | break; |
c906108c | 12029 | case DW_FORM_data4: |
3e43a32a MS |
12030 | *bytes = dwarf2_const_value_data (attr, type, name, |
12031 | obstack, cu, value, 32); | |
2df3850c | 12032 | break; |
c906108c | 12033 | case DW_FORM_data8: |
3e43a32a MS |
12034 | *bytes = dwarf2_const_value_data (attr, type, name, |
12035 | obstack, cu, value, 64); | |
2df3850c JM |
12036 | break; |
12037 | ||
c906108c | 12038 | case DW_FORM_sdata: |
98bfdba5 | 12039 | *value = DW_SND (attr); |
2df3850c JM |
12040 | break; |
12041 | ||
c906108c | 12042 | case DW_FORM_udata: |
98bfdba5 | 12043 | *value = DW_UNSND (attr); |
c906108c | 12044 | break; |
2df3850c | 12045 | |
c906108c | 12046 | default: |
4d3c2250 | 12047 | complaint (&symfile_complaints, |
e2e0b3e5 | 12048 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 12049 | dwarf_form_name (attr->form)); |
98bfdba5 | 12050 | *value = 0; |
c906108c SS |
12051 | break; |
12052 | } | |
12053 | } | |
12054 | ||
2df3850c | 12055 | |
98bfdba5 PA |
12056 | /* Copy constant value from an attribute to a symbol. */ |
12057 | ||
2df3850c | 12058 | static void |
98bfdba5 PA |
12059 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
12060 | struct dwarf2_cu *cu) | |
2df3850c | 12061 | { |
98bfdba5 PA |
12062 | struct objfile *objfile = cu->objfile; |
12063 | struct comp_unit_head *cu_header = &cu->header; | |
12064 | long value; | |
12065 | gdb_byte *bytes; | |
12066 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 12067 | |
98bfdba5 PA |
12068 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
12069 | SYMBOL_PRINT_NAME (sym), | |
12070 | &objfile->objfile_obstack, cu, | |
12071 | &value, &bytes, &baton); | |
2df3850c | 12072 | |
98bfdba5 PA |
12073 | if (baton != NULL) |
12074 | { | |
12075 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
12076 | SYMBOL_LOCATION_BATON (sym) = baton; | |
12077 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
12078 | } | |
12079 | else if (bytes != NULL) | |
12080 | { | |
12081 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
12082 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
12083 | } | |
12084 | else | |
12085 | { | |
12086 | SYMBOL_VALUE (sym) = value; | |
12087 | SYMBOL_CLASS (sym) = LOC_CONST; | |
12088 | } | |
2df3850c JM |
12089 | } |
12090 | ||
c906108c SS |
12091 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
12092 | ||
12093 | static struct type * | |
e7c27a73 | 12094 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12095 | { |
c906108c | 12096 | struct attribute *type_attr; |
c906108c | 12097 | |
e142c38c | 12098 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
12099 | if (!type_attr) |
12100 | { | |
12101 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 12102 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 12103 | } |
348e048f | 12104 | |
673bfd45 | 12105 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12106 | } |
12107 | ||
b4ba55a1 JB |
12108 | /* True iff CU's producer generates GNAT Ada auxiliary information |
12109 | that allows to find parallel types through that information instead | |
12110 | of having to do expensive parallel lookups by type name. */ | |
12111 | ||
12112 | static int | |
12113 | need_gnat_info (struct dwarf2_cu *cu) | |
12114 | { | |
12115 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
12116 | of GNAT produces this auxiliary information, without any indication | |
12117 | that it is produced. Part of enhancing the FSF version of GNAT | |
12118 | to produce that information will be to put in place an indicator | |
12119 | that we can use in order to determine whether the descriptive type | |
12120 | info is available or not. One suggestion that has been made is | |
12121 | to use a new attribute, attached to the CU die. For now, assume | |
12122 | that the descriptive type info is not available. */ | |
12123 | return 0; | |
12124 | } | |
12125 | ||
b4ba55a1 JB |
12126 | /* Return the auxiliary type of the die in question using its |
12127 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
12128 | attribute is not present. */ | |
12129 | ||
12130 | static struct type * | |
12131 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
12132 | { | |
b4ba55a1 | 12133 | struct attribute *type_attr; |
b4ba55a1 JB |
12134 | |
12135 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
12136 | if (!type_attr) | |
12137 | return NULL; | |
12138 | ||
673bfd45 | 12139 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
12140 | } |
12141 | ||
12142 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
12143 | descriptive type accordingly. */ | |
12144 | ||
12145 | static void | |
12146 | set_descriptive_type (struct type *type, struct die_info *die, | |
12147 | struct dwarf2_cu *cu) | |
12148 | { | |
12149 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
12150 | ||
12151 | if (descriptive_type) | |
12152 | { | |
12153 | ALLOCATE_GNAT_AUX_TYPE (type); | |
12154 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
12155 | } | |
12156 | } | |
12157 | ||
c906108c SS |
12158 | /* Return the containing type of the die in question using its |
12159 | DW_AT_containing_type attribute. */ | |
12160 | ||
12161 | static struct type * | |
e7c27a73 | 12162 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12163 | { |
c906108c | 12164 | struct attribute *type_attr; |
c906108c | 12165 | |
e142c38c | 12166 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
12167 | if (!type_attr) |
12168 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
12169 | "[in module %s]"), cu->objfile->name); | |
12170 | ||
673bfd45 | 12171 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12172 | } |
12173 | ||
673bfd45 DE |
12174 | /* Look up the type of DIE in CU using its type attribute ATTR. |
12175 | If there is no type substitute an error marker. */ | |
12176 | ||
c906108c | 12177 | static struct type * |
673bfd45 DE |
12178 | lookup_die_type (struct die_info *die, struct attribute *attr, |
12179 | struct dwarf2_cu *cu) | |
c906108c | 12180 | { |
bb5ed363 | 12181 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
12182 | struct type *this_type; |
12183 | ||
673bfd45 DE |
12184 | /* First see if we have it cached. */ |
12185 | ||
12186 | if (is_ref_attr (attr)) | |
12187 | { | |
12188 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
12189 | ||
12190 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
12191 | } | |
55f1336d | 12192 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
12193 | { |
12194 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
12195 | struct dwarf2_cu *sig_cu; | |
12196 | unsigned int offset; | |
12197 | ||
12198 | /* sig_type will be NULL if the signatured type is missing from | |
12199 | the debug info. */ | |
12200 | if (sig_type == NULL) | |
12201 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12202 | "at 0x%x [in module %s]"), | |
bb5ed363 | 12203 | die->offset, objfile->name); |
673bfd45 | 12204 | |
b0df02fd | 12205 | gdb_assert (sig_type->per_cu.debug_types_section); |
b3c8eb43 | 12206 | offset = sig_type->per_cu.offset + sig_type->type_offset; |
673bfd45 DE |
12207 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
12208 | } | |
12209 | else | |
12210 | { | |
12211 | dump_die_for_error (die); | |
12212 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 12213 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
12214 | } |
12215 | ||
12216 | /* If not cached we need to read it in. */ | |
12217 | ||
12218 | if (this_type == NULL) | |
12219 | { | |
12220 | struct die_info *type_die; | |
12221 | struct dwarf2_cu *type_cu = cu; | |
12222 | ||
12223 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
12224 | /* If the type is cached, we should have found it above. */ | |
12225 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
12226 | this_type = read_type_die_1 (type_die, type_cu); | |
12227 | } | |
12228 | ||
12229 | /* If we still don't have a type use an error marker. */ | |
12230 | ||
12231 | if (this_type == NULL) | |
c906108c | 12232 | { |
b00fdb78 TT |
12233 | char *message, *saved; |
12234 | ||
12235 | /* read_type_die already issued a complaint. */ | |
12236 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 12237 | objfile->name, |
b00fdb78 TT |
12238 | cu->header.offset, |
12239 | die->offset); | |
bb5ed363 | 12240 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
12241 | message, strlen (message)); |
12242 | xfree (message); | |
12243 | ||
bb5ed363 | 12244 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 12245 | } |
673bfd45 | 12246 | |
f792889a | 12247 | return this_type; |
c906108c SS |
12248 | } |
12249 | ||
673bfd45 DE |
12250 | /* Return the type in DIE, CU. |
12251 | Returns NULL for invalid types. | |
12252 | ||
12253 | This first does a lookup in the appropriate type_hash table, | |
12254 | and only reads the die in if necessary. | |
12255 | ||
12256 | NOTE: This can be called when reading in partial or full symbols. */ | |
12257 | ||
f792889a | 12258 | static struct type * |
e7c27a73 | 12259 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12260 | { |
f792889a DJ |
12261 | struct type *this_type; |
12262 | ||
12263 | this_type = get_die_type (die, cu); | |
12264 | if (this_type) | |
12265 | return this_type; | |
12266 | ||
673bfd45 DE |
12267 | return read_type_die_1 (die, cu); |
12268 | } | |
12269 | ||
12270 | /* Read the type in DIE, CU. | |
12271 | Returns NULL for invalid types. */ | |
12272 | ||
12273 | static struct type * | |
12274 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
12275 | { | |
12276 | struct type *this_type = NULL; | |
12277 | ||
c906108c SS |
12278 | switch (die->tag) |
12279 | { | |
12280 | case DW_TAG_class_type: | |
680b30c7 | 12281 | case DW_TAG_interface_type: |
c906108c SS |
12282 | case DW_TAG_structure_type: |
12283 | case DW_TAG_union_type: | |
f792889a | 12284 | this_type = read_structure_type (die, cu); |
c906108c SS |
12285 | break; |
12286 | case DW_TAG_enumeration_type: | |
f792889a | 12287 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
12288 | break; |
12289 | case DW_TAG_subprogram: | |
12290 | case DW_TAG_subroutine_type: | |
edb3359d | 12291 | case DW_TAG_inlined_subroutine: |
f792889a | 12292 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
12293 | break; |
12294 | case DW_TAG_array_type: | |
f792889a | 12295 | this_type = read_array_type (die, cu); |
c906108c | 12296 | break; |
72019c9c | 12297 | case DW_TAG_set_type: |
f792889a | 12298 | this_type = read_set_type (die, cu); |
72019c9c | 12299 | break; |
c906108c | 12300 | case DW_TAG_pointer_type: |
f792889a | 12301 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
12302 | break; |
12303 | case DW_TAG_ptr_to_member_type: | |
f792889a | 12304 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
12305 | break; |
12306 | case DW_TAG_reference_type: | |
f792889a | 12307 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
12308 | break; |
12309 | case DW_TAG_const_type: | |
f792889a | 12310 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
12311 | break; |
12312 | case DW_TAG_volatile_type: | |
f792889a | 12313 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
12314 | break; |
12315 | case DW_TAG_string_type: | |
f792889a | 12316 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
12317 | break; |
12318 | case DW_TAG_typedef: | |
f792889a | 12319 | this_type = read_typedef (die, cu); |
c906108c | 12320 | break; |
a02abb62 | 12321 | case DW_TAG_subrange_type: |
f792889a | 12322 | this_type = read_subrange_type (die, cu); |
a02abb62 | 12323 | break; |
c906108c | 12324 | case DW_TAG_base_type: |
f792889a | 12325 | this_type = read_base_type (die, cu); |
c906108c | 12326 | break; |
81a17f79 | 12327 | case DW_TAG_unspecified_type: |
f792889a | 12328 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 12329 | break; |
0114d602 DJ |
12330 | case DW_TAG_namespace: |
12331 | this_type = read_namespace_type (die, cu); | |
12332 | break; | |
f55ee35c JK |
12333 | case DW_TAG_module: |
12334 | this_type = read_module_type (die, cu); | |
12335 | break; | |
c906108c | 12336 | default: |
3e43a32a MS |
12337 | complaint (&symfile_complaints, |
12338 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 12339 | dwarf_tag_name (die->tag)); |
c906108c SS |
12340 | break; |
12341 | } | |
63d06c5c | 12342 | |
f792889a | 12343 | return this_type; |
63d06c5c DC |
12344 | } |
12345 | ||
abc72ce4 DE |
12346 | /* See if we can figure out if the class lives in a namespace. We do |
12347 | this by looking for a member function; its demangled name will | |
12348 | contain namespace info, if there is any. | |
12349 | Return the computed name or NULL. | |
12350 | Space for the result is allocated on the objfile's obstack. | |
12351 | This is the full-die version of guess_partial_die_structure_name. | |
12352 | In this case we know DIE has no useful parent. */ | |
12353 | ||
12354 | static char * | |
12355 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
12356 | { | |
12357 | struct die_info *spec_die; | |
12358 | struct dwarf2_cu *spec_cu; | |
12359 | struct die_info *child; | |
12360 | ||
12361 | spec_cu = cu; | |
12362 | spec_die = die_specification (die, &spec_cu); | |
12363 | if (spec_die != NULL) | |
12364 | { | |
12365 | die = spec_die; | |
12366 | cu = spec_cu; | |
12367 | } | |
12368 | ||
12369 | for (child = die->child; | |
12370 | child != NULL; | |
12371 | child = child->sibling) | |
12372 | { | |
12373 | if (child->tag == DW_TAG_subprogram) | |
12374 | { | |
12375 | struct attribute *attr; | |
12376 | ||
12377 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
12378 | if (attr == NULL) | |
12379 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
12380 | if (attr != NULL) | |
12381 | { | |
12382 | char *actual_name | |
12383 | = language_class_name_from_physname (cu->language_defn, | |
12384 | DW_STRING (attr)); | |
12385 | char *name = NULL; | |
12386 | ||
12387 | if (actual_name != NULL) | |
12388 | { | |
12389 | char *die_name = dwarf2_name (die, cu); | |
12390 | ||
12391 | if (die_name != NULL | |
12392 | && strcmp (die_name, actual_name) != 0) | |
12393 | { | |
12394 | /* Strip off the class name from the full name. | |
12395 | We want the prefix. */ | |
12396 | int die_name_len = strlen (die_name); | |
12397 | int actual_name_len = strlen (actual_name); | |
12398 | ||
12399 | /* Test for '::' as a sanity check. */ | |
12400 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
12401 | && actual_name[actual_name_len |
12402 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
12403 | name = |
12404 | obsavestring (actual_name, | |
12405 | actual_name_len - die_name_len - 2, | |
12406 | &cu->objfile->objfile_obstack); | |
12407 | } | |
12408 | } | |
12409 | xfree (actual_name); | |
12410 | return name; | |
12411 | } | |
12412 | } | |
12413 | } | |
12414 | ||
12415 | return NULL; | |
12416 | } | |
12417 | ||
96408a79 SA |
12418 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
12419 | prefix part in such case. See | |
12420 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12421 | ||
12422 | static char * | |
12423 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
12424 | { | |
12425 | struct attribute *attr; | |
12426 | char *base; | |
12427 | ||
12428 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
12429 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
12430 | return NULL; | |
12431 | ||
12432 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
12433 | if (attr != NULL && DW_STRING (attr) != NULL) | |
12434 | return NULL; | |
12435 | ||
12436 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12437 | if (attr == NULL) | |
12438 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12439 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12440 | return NULL; | |
12441 | ||
12442 | /* dwarf2_name had to be already called. */ | |
12443 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
12444 | ||
12445 | /* Strip the base name, keep any leading namespaces/classes. */ | |
12446 | base = strrchr (DW_STRING (attr), ':'); | |
12447 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
12448 | return ""; | |
12449 | ||
12450 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
12451 | &cu->objfile->objfile_obstack); | |
12452 | } | |
12453 | ||
fdde2d81 | 12454 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 12455 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 12456 | |
0114d602 DJ |
12457 | For example, if we're within the method foo() in the following |
12458 | code: | |
12459 | ||
12460 | namespace N { | |
12461 | class C { | |
12462 | void foo () { | |
12463 | } | |
12464 | }; | |
12465 | } | |
12466 | ||
12467 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
12468 | |
12469 | static char * | |
e142c38c | 12470 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 12471 | { |
0114d602 DJ |
12472 | struct die_info *parent, *spec_die; |
12473 | struct dwarf2_cu *spec_cu; | |
12474 | struct type *parent_type; | |
96408a79 | 12475 | char *retval; |
63d06c5c | 12476 | |
f55ee35c JK |
12477 | if (cu->language != language_cplus && cu->language != language_java |
12478 | && cu->language != language_fortran) | |
0114d602 DJ |
12479 | return ""; |
12480 | ||
96408a79 SA |
12481 | retval = anonymous_struct_prefix (die, cu); |
12482 | if (retval) | |
12483 | return retval; | |
12484 | ||
0114d602 DJ |
12485 | /* We have to be careful in the presence of DW_AT_specification. |
12486 | For example, with GCC 3.4, given the code | |
12487 | ||
12488 | namespace N { | |
12489 | void foo() { | |
12490 | // Definition of N::foo. | |
12491 | } | |
12492 | } | |
12493 | ||
12494 | then we'll have a tree of DIEs like this: | |
12495 | ||
12496 | 1: DW_TAG_compile_unit | |
12497 | 2: DW_TAG_namespace // N | |
12498 | 3: DW_TAG_subprogram // declaration of N::foo | |
12499 | 4: DW_TAG_subprogram // definition of N::foo | |
12500 | DW_AT_specification // refers to die #3 | |
12501 | ||
12502 | Thus, when processing die #4, we have to pretend that we're in | |
12503 | the context of its DW_AT_specification, namely the contex of die | |
12504 | #3. */ | |
12505 | spec_cu = cu; | |
12506 | spec_die = die_specification (die, &spec_cu); | |
12507 | if (spec_die == NULL) | |
12508 | parent = die->parent; | |
12509 | else | |
63d06c5c | 12510 | { |
0114d602 DJ |
12511 | parent = spec_die->parent; |
12512 | cu = spec_cu; | |
63d06c5c | 12513 | } |
0114d602 DJ |
12514 | |
12515 | if (parent == NULL) | |
12516 | return ""; | |
98bfdba5 PA |
12517 | else if (parent->building_fullname) |
12518 | { | |
12519 | const char *name; | |
12520 | const char *parent_name; | |
12521 | ||
12522 | /* It has been seen on RealView 2.2 built binaries, | |
12523 | DW_TAG_template_type_param types actually _defined_ as | |
12524 | children of the parent class: | |
12525 | ||
12526 | enum E {}; | |
12527 | template class <class Enum> Class{}; | |
12528 | Class<enum E> class_e; | |
12529 | ||
12530 | 1: DW_TAG_class_type (Class) | |
12531 | 2: DW_TAG_enumeration_type (E) | |
12532 | 3: DW_TAG_enumerator (enum1:0) | |
12533 | 3: DW_TAG_enumerator (enum2:1) | |
12534 | ... | |
12535 | 2: DW_TAG_template_type_param | |
12536 | DW_AT_type DW_FORM_ref_udata (E) | |
12537 | ||
12538 | Besides being broken debug info, it can put GDB into an | |
12539 | infinite loop. Consider: | |
12540 | ||
12541 | When we're building the full name for Class<E>, we'll start | |
12542 | at Class, and go look over its template type parameters, | |
12543 | finding E. We'll then try to build the full name of E, and | |
12544 | reach here. We're now trying to build the full name of E, | |
12545 | and look over the parent DIE for containing scope. In the | |
12546 | broken case, if we followed the parent DIE of E, we'd again | |
12547 | find Class, and once again go look at its template type | |
12548 | arguments, etc., etc. Simply don't consider such parent die | |
12549 | as source-level parent of this die (it can't be, the language | |
12550 | doesn't allow it), and break the loop here. */ | |
12551 | name = dwarf2_name (die, cu); | |
12552 | parent_name = dwarf2_name (parent, cu); | |
12553 | complaint (&symfile_complaints, | |
12554 | _("template param type '%s' defined within parent '%s'"), | |
12555 | name ? name : "<unknown>", | |
12556 | parent_name ? parent_name : "<unknown>"); | |
12557 | return ""; | |
12558 | } | |
63d06c5c | 12559 | else |
0114d602 DJ |
12560 | switch (parent->tag) |
12561 | { | |
63d06c5c | 12562 | case DW_TAG_namespace: |
0114d602 | 12563 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
12564 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
12565 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
12566 | Work around this problem here. */ | |
12567 | if (cu->language == language_cplus | |
12568 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
12569 | return ""; | |
0114d602 DJ |
12570 | /* We give a name to even anonymous namespaces. */ |
12571 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 12572 | case DW_TAG_class_type: |
680b30c7 | 12573 | case DW_TAG_interface_type: |
63d06c5c | 12574 | case DW_TAG_structure_type: |
0114d602 | 12575 | case DW_TAG_union_type: |
f55ee35c | 12576 | case DW_TAG_module: |
0114d602 DJ |
12577 | parent_type = read_type_die (parent, cu); |
12578 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
12579 | return TYPE_TAG_NAME (parent_type); | |
12580 | else | |
12581 | /* An anonymous structure is only allowed non-static data | |
12582 | members; no typedefs, no member functions, et cetera. | |
12583 | So it does not need a prefix. */ | |
12584 | return ""; | |
abc72ce4 DE |
12585 | case DW_TAG_compile_unit: |
12586 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
12587 | if (cu->language == language_cplus | |
8b70b953 | 12588 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
12589 | && die->child != NULL |
12590 | && (die->tag == DW_TAG_class_type | |
12591 | || die->tag == DW_TAG_structure_type | |
12592 | || die->tag == DW_TAG_union_type)) | |
12593 | { | |
12594 | char *name = guess_full_die_structure_name (die, cu); | |
12595 | if (name != NULL) | |
12596 | return name; | |
12597 | } | |
12598 | return ""; | |
63d06c5c | 12599 | default: |
8176b9b8 | 12600 | return determine_prefix (parent, cu); |
63d06c5c | 12601 | } |
63d06c5c DC |
12602 | } |
12603 | ||
3e43a32a MS |
12604 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
12605 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
12606 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
12607 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
12608 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 12609 | |
f55ee35c | 12610 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
12611 | |
12612 | static char * | |
f55ee35c JK |
12613 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
12614 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 12615 | { |
f55ee35c | 12616 | const char *lead = ""; |
5c315b68 | 12617 | const char *sep; |
63d06c5c | 12618 | |
3e43a32a MS |
12619 | if (suffix == NULL || suffix[0] == '\0' |
12620 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
12621 | sep = ""; |
12622 | else if (cu->language == language_java) | |
12623 | sep = "."; | |
f55ee35c JK |
12624 | else if (cu->language == language_fortran && physname) |
12625 | { | |
12626 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
12627 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
12628 | ||
12629 | lead = "__"; | |
12630 | sep = "_MOD_"; | |
12631 | } | |
987504bb JJ |
12632 | else |
12633 | sep = "::"; | |
63d06c5c | 12634 | |
6dd47d34 DE |
12635 | if (prefix == NULL) |
12636 | prefix = ""; | |
12637 | if (suffix == NULL) | |
12638 | suffix = ""; | |
12639 | ||
987504bb JJ |
12640 | if (obs == NULL) |
12641 | { | |
3e43a32a MS |
12642 | char *retval |
12643 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 12644 | |
f55ee35c JK |
12645 | strcpy (retval, lead); |
12646 | strcat (retval, prefix); | |
6dd47d34 DE |
12647 | strcat (retval, sep); |
12648 | strcat (retval, suffix); | |
63d06c5c DC |
12649 | return retval; |
12650 | } | |
987504bb JJ |
12651 | else |
12652 | { | |
12653 | /* We have an obstack. */ | |
f55ee35c | 12654 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 12655 | } |
63d06c5c DC |
12656 | } |
12657 | ||
c906108c SS |
12658 | /* Return sibling of die, NULL if no sibling. */ |
12659 | ||
f9aca02d | 12660 | static struct die_info * |
fba45db2 | 12661 | sibling_die (struct die_info *die) |
c906108c | 12662 | { |
639d11d3 | 12663 | return die->sibling; |
c906108c SS |
12664 | } |
12665 | ||
71c25dea TT |
12666 | /* Get name of a die, return NULL if not found. */ |
12667 | ||
12668 | static char * | |
12669 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
12670 | struct obstack *obstack) | |
12671 | { | |
12672 | if (name && cu->language == language_cplus) | |
12673 | { | |
12674 | char *canon_name = cp_canonicalize_string (name); | |
12675 | ||
12676 | if (canon_name != NULL) | |
12677 | { | |
12678 | if (strcmp (canon_name, name) != 0) | |
12679 | name = obsavestring (canon_name, strlen (canon_name), | |
12680 | obstack); | |
12681 | xfree (canon_name); | |
12682 | } | |
12683 | } | |
12684 | ||
12685 | return name; | |
c906108c SS |
12686 | } |
12687 | ||
9219021c DC |
12688 | /* Get name of a die, return NULL if not found. */ |
12689 | ||
12690 | static char * | |
e142c38c | 12691 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
12692 | { |
12693 | struct attribute *attr; | |
12694 | ||
e142c38c | 12695 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
12696 | if ((!attr || !DW_STRING (attr)) |
12697 | && die->tag != DW_TAG_class_type | |
12698 | && die->tag != DW_TAG_interface_type | |
12699 | && die->tag != DW_TAG_structure_type | |
12700 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
12701 | return NULL; |
12702 | ||
12703 | switch (die->tag) | |
12704 | { | |
12705 | case DW_TAG_compile_unit: | |
12706 | /* Compilation units have a DW_AT_name that is a filename, not | |
12707 | a source language identifier. */ | |
12708 | case DW_TAG_enumeration_type: | |
12709 | case DW_TAG_enumerator: | |
12710 | /* These tags always have simple identifiers already; no need | |
12711 | to canonicalize them. */ | |
12712 | return DW_STRING (attr); | |
907af001 | 12713 | |
418835cc KS |
12714 | case DW_TAG_subprogram: |
12715 | /* Java constructors will all be named "<init>", so return | |
12716 | the class name when we see this special case. */ | |
12717 | if (cu->language == language_java | |
12718 | && DW_STRING (attr) != NULL | |
12719 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
12720 | { | |
12721 | struct dwarf2_cu *spec_cu = cu; | |
12722 | struct die_info *spec_die; | |
12723 | ||
12724 | /* GCJ will output '<init>' for Java constructor names. | |
12725 | For this special case, return the name of the parent class. */ | |
12726 | ||
12727 | /* GCJ may output suprogram DIEs with AT_specification set. | |
12728 | If so, use the name of the specified DIE. */ | |
12729 | spec_die = die_specification (die, &spec_cu); | |
12730 | if (spec_die != NULL) | |
12731 | return dwarf2_name (spec_die, spec_cu); | |
12732 | ||
12733 | do | |
12734 | { | |
12735 | die = die->parent; | |
12736 | if (die->tag == DW_TAG_class_type) | |
12737 | return dwarf2_name (die, cu); | |
12738 | } | |
12739 | while (die->tag != DW_TAG_compile_unit); | |
12740 | } | |
907af001 UW |
12741 | break; |
12742 | ||
12743 | case DW_TAG_class_type: | |
12744 | case DW_TAG_interface_type: | |
12745 | case DW_TAG_structure_type: | |
12746 | case DW_TAG_union_type: | |
12747 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
12748 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
12749 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
12750 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
12751 | if (attr && DW_STRING (attr) |
12752 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
12753 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 12754 | return NULL; |
53832f31 TT |
12755 | |
12756 | /* GCC might emit a nameless typedef that has a linkage name. See | |
12757 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12758 | if (!attr || DW_STRING (attr) == NULL) | |
12759 | { | |
df5c6c50 | 12760 | char *demangled = NULL; |
53832f31 TT |
12761 | |
12762 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12763 | if (attr == NULL) | |
12764 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12765 | ||
12766 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12767 | return NULL; | |
12768 | ||
df5c6c50 JK |
12769 | /* Avoid demangling DW_STRING (attr) the second time on a second |
12770 | call for the same DIE. */ | |
12771 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12772 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
12773 | |
12774 | if (demangled) | |
12775 | { | |
96408a79 SA |
12776 | char *base; |
12777 | ||
53832f31 | 12778 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
12779 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
12780 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
12781 | DW_STRING_IS_CANONICAL (attr) = 1; |
12782 | xfree (demangled); | |
96408a79 SA |
12783 | |
12784 | /* Strip any leading namespaces/classes, keep only the base name. | |
12785 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
12786 | base = strrchr (DW_STRING (attr), ':'); | |
12787 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
12788 | return &base[1]; | |
12789 | else | |
12790 | return DW_STRING (attr); | |
53832f31 TT |
12791 | } |
12792 | } | |
907af001 UW |
12793 | break; |
12794 | ||
71c25dea | 12795 | default: |
907af001 UW |
12796 | break; |
12797 | } | |
12798 | ||
12799 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12800 | { | |
12801 | DW_STRING (attr) | |
12802 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
12803 | &cu->objfile->objfile_obstack); | |
12804 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 12805 | } |
907af001 | 12806 | return DW_STRING (attr); |
9219021c DC |
12807 | } |
12808 | ||
12809 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
12810 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
12811 | containing the return value on output. */ | |
9219021c DC |
12812 | |
12813 | static struct die_info * | |
f2f0e013 | 12814 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
12815 | { |
12816 | struct attribute *attr; | |
9219021c | 12817 | |
f2f0e013 | 12818 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
12819 | if (attr == NULL) |
12820 | return NULL; | |
12821 | ||
f2f0e013 | 12822 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
12823 | } |
12824 | ||
c906108c SS |
12825 | /* Convert a DIE tag into its string name. */ |
12826 | ||
12827 | static char * | |
aa1ee363 | 12828 | dwarf_tag_name (unsigned tag) |
c906108c SS |
12829 | { |
12830 | switch (tag) | |
12831 | { | |
12832 | case DW_TAG_padding: | |
12833 | return "DW_TAG_padding"; | |
12834 | case DW_TAG_array_type: | |
12835 | return "DW_TAG_array_type"; | |
12836 | case DW_TAG_class_type: | |
12837 | return "DW_TAG_class_type"; | |
12838 | case DW_TAG_entry_point: | |
12839 | return "DW_TAG_entry_point"; | |
12840 | case DW_TAG_enumeration_type: | |
12841 | return "DW_TAG_enumeration_type"; | |
12842 | case DW_TAG_formal_parameter: | |
12843 | return "DW_TAG_formal_parameter"; | |
12844 | case DW_TAG_imported_declaration: | |
12845 | return "DW_TAG_imported_declaration"; | |
12846 | case DW_TAG_label: | |
12847 | return "DW_TAG_label"; | |
12848 | case DW_TAG_lexical_block: | |
12849 | return "DW_TAG_lexical_block"; | |
12850 | case DW_TAG_member: | |
12851 | return "DW_TAG_member"; | |
12852 | case DW_TAG_pointer_type: | |
12853 | return "DW_TAG_pointer_type"; | |
12854 | case DW_TAG_reference_type: | |
12855 | return "DW_TAG_reference_type"; | |
12856 | case DW_TAG_compile_unit: | |
12857 | return "DW_TAG_compile_unit"; | |
12858 | case DW_TAG_string_type: | |
12859 | return "DW_TAG_string_type"; | |
12860 | case DW_TAG_structure_type: | |
12861 | return "DW_TAG_structure_type"; | |
12862 | case DW_TAG_subroutine_type: | |
12863 | return "DW_TAG_subroutine_type"; | |
12864 | case DW_TAG_typedef: | |
12865 | return "DW_TAG_typedef"; | |
12866 | case DW_TAG_union_type: | |
12867 | return "DW_TAG_union_type"; | |
12868 | case DW_TAG_unspecified_parameters: | |
12869 | return "DW_TAG_unspecified_parameters"; | |
12870 | case DW_TAG_variant: | |
12871 | return "DW_TAG_variant"; | |
12872 | case DW_TAG_common_block: | |
12873 | return "DW_TAG_common_block"; | |
12874 | case DW_TAG_common_inclusion: | |
12875 | return "DW_TAG_common_inclusion"; | |
12876 | case DW_TAG_inheritance: | |
12877 | return "DW_TAG_inheritance"; | |
12878 | case DW_TAG_inlined_subroutine: | |
12879 | return "DW_TAG_inlined_subroutine"; | |
12880 | case DW_TAG_module: | |
12881 | return "DW_TAG_module"; | |
12882 | case DW_TAG_ptr_to_member_type: | |
12883 | return "DW_TAG_ptr_to_member_type"; | |
12884 | case DW_TAG_set_type: | |
12885 | return "DW_TAG_set_type"; | |
12886 | case DW_TAG_subrange_type: | |
12887 | return "DW_TAG_subrange_type"; | |
12888 | case DW_TAG_with_stmt: | |
12889 | return "DW_TAG_with_stmt"; | |
12890 | case DW_TAG_access_declaration: | |
12891 | return "DW_TAG_access_declaration"; | |
12892 | case DW_TAG_base_type: | |
12893 | return "DW_TAG_base_type"; | |
12894 | case DW_TAG_catch_block: | |
12895 | return "DW_TAG_catch_block"; | |
12896 | case DW_TAG_const_type: | |
12897 | return "DW_TAG_const_type"; | |
12898 | case DW_TAG_constant: | |
12899 | return "DW_TAG_constant"; | |
12900 | case DW_TAG_enumerator: | |
12901 | return "DW_TAG_enumerator"; | |
12902 | case DW_TAG_file_type: | |
12903 | return "DW_TAG_file_type"; | |
12904 | case DW_TAG_friend: | |
12905 | return "DW_TAG_friend"; | |
12906 | case DW_TAG_namelist: | |
12907 | return "DW_TAG_namelist"; | |
12908 | case DW_TAG_namelist_item: | |
12909 | return "DW_TAG_namelist_item"; | |
12910 | case DW_TAG_packed_type: | |
12911 | return "DW_TAG_packed_type"; | |
12912 | case DW_TAG_subprogram: | |
12913 | return "DW_TAG_subprogram"; | |
12914 | case DW_TAG_template_type_param: | |
12915 | return "DW_TAG_template_type_param"; | |
12916 | case DW_TAG_template_value_param: | |
12917 | return "DW_TAG_template_value_param"; | |
12918 | case DW_TAG_thrown_type: | |
12919 | return "DW_TAG_thrown_type"; | |
12920 | case DW_TAG_try_block: | |
12921 | return "DW_TAG_try_block"; | |
12922 | case DW_TAG_variant_part: | |
12923 | return "DW_TAG_variant_part"; | |
12924 | case DW_TAG_variable: | |
12925 | return "DW_TAG_variable"; | |
12926 | case DW_TAG_volatile_type: | |
12927 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
12928 | case DW_TAG_dwarf_procedure: |
12929 | return "DW_TAG_dwarf_procedure"; | |
12930 | case DW_TAG_restrict_type: | |
12931 | return "DW_TAG_restrict_type"; | |
12932 | case DW_TAG_interface_type: | |
12933 | return "DW_TAG_interface_type"; | |
12934 | case DW_TAG_namespace: | |
12935 | return "DW_TAG_namespace"; | |
12936 | case DW_TAG_imported_module: | |
12937 | return "DW_TAG_imported_module"; | |
12938 | case DW_TAG_unspecified_type: | |
12939 | return "DW_TAG_unspecified_type"; | |
12940 | case DW_TAG_partial_unit: | |
12941 | return "DW_TAG_partial_unit"; | |
12942 | case DW_TAG_imported_unit: | |
12943 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
12944 | case DW_TAG_condition: |
12945 | return "DW_TAG_condition"; | |
12946 | case DW_TAG_shared_type: | |
12947 | return "DW_TAG_shared_type"; | |
348e048f DE |
12948 | case DW_TAG_type_unit: |
12949 | return "DW_TAG_type_unit"; | |
c906108c SS |
12950 | case DW_TAG_MIPS_loop: |
12951 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
12952 | case DW_TAG_HP_array_descriptor: |
12953 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
12954 | case DW_TAG_format_label: |
12955 | return "DW_TAG_format_label"; | |
12956 | case DW_TAG_function_template: | |
12957 | return "DW_TAG_function_template"; | |
12958 | case DW_TAG_class_template: | |
12959 | return "DW_TAG_class_template"; | |
b7619582 GF |
12960 | case DW_TAG_GNU_BINCL: |
12961 | return "DW_TAG_GNU_BINCL"; | |
12962 | case DW_TAG_GNU_EINCL: | |
12963 | return "DW_TAG_GNU_EINCL"; | |
12964 | case DW_TAG_upc_shared_type: | |
12965 | return "DW_TAG_upc_shared_type"; | |
12966 | case DW_TAG_upc_strict_type: | |
12967 | return "DW_TAG_upc_strict_type"; | |
12968 | case DW_TAG_upc_relaxed_type: | |
12969 | return "DW_TAG_upc_relaxed_type"; | |
12970 | case DW_TAG_PGI_kanji_type: | |
12971 | return "DW_TAG_PGI_kanji_type"; | |
12972 | case DW_TAG_PGI_interface_block: | |
12973 | return "DW_TAG_PGI_interface_block"; | |
96408a79 SA |
12974 | case DW_TAG_GNU_call_site: |
12975 | return "DW_TAG_GNU_call_site"; | |
c906108c SS |
12976 | default: |
12977 | return "DW_TAG_<unknown>"; | |
12978 | } | |
12979 | } | |
12980 | ||
12981 | /* Convert a DWARF attribute code into its string name. */ | |
12982 | ||
12983 | static char * | |
aa1ee363 | 12984 | dwarf_attr_name (unsigned attr) |
c906108c SS |
12985 | { |
12986 | switch (attr) | |
12987 | { | |
12988 | case DW_AT_sibling: | |
12989 | return "DW_AT_sibling"; | |
12990 | case DW_AT_location: | |
12991 | return "DW_AT_location"; | |
12992 | case DW_AT_name: | |
12993 | return "DW_AT_name"; | |
12994 | case DW_AT_ordering: | |
12995 | return "DW_AT_ordering"; | |
12996 | case DW_AT_subscr_data: | |
12997 | return "DW_AT_subscr_data"; | |
12998 | case DW_AT_byte_size: | |
12999 | return "DW_AT_byte_size"; | |
13000 | case DW_AT_bit_offset: | |
13001 | return "DW_AT_bit_offset"; | |
13002 | case DW_AT_bit_size: | |
13003 | return "DW_AT_bit_size"; | |
13004 | case DW_AT_element_list: | |
13005 | return "DW_AT_element_list"; | |
13006 | case DW_AT_stmt_list: | |
13007 | return "DW_AT_stmt_list"; | |
13008 | case DW_AT_low_pc: | |
13009 | return "DW_AT_low_pc"; | |
13010 | case DW_AT_high_pc: | |
13011 | return "DW_AT_high_pc"; | |
13012 | case DW_AT_language: | |
13013 | return "DW_AT_language"; | |
13014 | case DW_AT_member: | |
13015 | return "DW_AT_member"; | |
13016 | case DW_AT_discr: | |
13017 | return "DW_AT_discr"; | |
13018 | case DW_AT_discr_value: | |
13019 | return "DW_AT_discr_value"; | |
13020 | case DW_AT_visibility: | |
13021 | return "DW_AT_visibility"; | |
13022 | case DW_AT_import: | |
13023 | return "DW_AT_import"; | |
13024 | case DW_AT_string_length: | |
13025 | return "DW_AT_string_length"; | |
13026 | case DW_AT_common_reference: | |
13027 | return "DW_AT_common_reference"; | |
13028 | case DW_AT_comp_dir: | |
13029 | return "DW_AT_comp_dir"; | |
13030 | case DW_AT_const_value: | |
13031 | return "DW_AT_const_value"; | |
13032 | case DW_AT_containing_type: | |
13033 | return "DW_AT_containing_type"; | |
13034 | case DW_AT_default_value: | |
13035 | return "DW_AT_default_value"; | |
13036 | case DW_AT_inline: | |
13037 | return "DW_AT_inline"; | |
13038 | case DW_AT_is_optional: | |
13039 | return "DW_AT_is_optional"; | |
13040 | case DW_AT_lower_bound: | |
13041 | return "DW_AT_lower_bound"; | |
13042 | case DW_AT_producer: | |
13043 | return "DW_AT_producer"; | |
13044 | case DW_AT_prototyped: | |
13045 | return "DW_AT_prototyped"; | |
13046 | case DW_AT_return_addr: | |
13047 | return "DW_AT_return_addr"; | |
13048 | case DW_AT_start_scope: | |
13049 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
13050 | case DW_AT_bit_stride: |
13051 | return "DW_AT_bit_stride"; | |
c906108c SS |
13052 | case DW_AT_upper_bound: |
13053 | return "DW_AT_upper_bound"; | |
13054 | case DW_AT_abstract_origin: | |
13055 | return "DW_AT_abstract_origin"; | |
13056 | case DW_AT_accessibility: | |
13057 | return "DW_AT_accessibility"; | |
13058 | case DW_AT_address_class: | |
13059 | return "DW_AT_address_class"; | |
13060 | case DW_AT_artificial: | |
13061 | return "DW_AT_artificial"; | |
13062 | case DW_AT_base_types: | |
13063 | return "DW_AT_base_types"; | |
13064 | case DW_AT_calling_convention: | |
13065 | return "DW_AT_calling_convention"; | |
13066 | case DW_AT_count: | |
13067 | return "DW_AT_count"; | |
13068 | case DW_AT_data_member_location: | |
13069 | return "DW_AT_data_member_location"; | |
13070 | case DW_AT_decl_column: | |
13071 | return "DW_AT_decl_column"; | |
13072 | case DW_AT_decl_file: | |
13073 | return "DW_AT_decl_file"; | |
13074 | case DW_AT_decl_line: | |
13075 | return "DW_AT_decl_line"; | |
13076 | case DW_AT_declaration: | |
13077 | return "DW_AT_declaration"; | |
13078 | case DW_AT_discr_list: | |
13079 | return "DW_AT_discr_list"; | |
13080 | case DW_AT_encoding: | |
13081 | return "DW_AT_encoding"; | |
13082 | case DW_AT_external: | |
13083 | return "DW_AT_external"; | |
13084 | case DW_AT_frame_base: | |
13085 | return "DW_AT_frame_base"; | |
13086 | case DW_AT_friend: | |
13087 | return "DW_AT_friend"; | |
13088 | case DW_AT_identifier_case: | |
13089 | return "DW_AT_identifier_case"; | |
13090 | case DW_AT_macro_info: | |
13091 | return "DW_AT_macro_info"; | |
13092 | case DW_AT_namelist_items: | |
13093 | return "DW_AT_namelist_items"; | |
13094 | case DW_AT_priority: | |
13095 | return "DW_AT_priority"; | |
13096 | case DW_AT_segment: | |
13097 | return "DW_AT_segment"; | |
13098 | case DW_AT_specification: | |
13099 | return "DW_AT_specification"; | |
13100 | case DW_AT_static_link: | |
13101 | return "DW_AT_static_link"; | |
13102 | case DW_AT_type: | |
13103 | return "DW_AT_type"; | |
13104 | case DW_AT_use_location: | |
13105 | return "DW_AT_use_location"; | |
13106 | case DW_AT_variable_parameter: | |
13107 | return "DW_AT_variable_parameter"; | |
13108 | case DW_AT_virtuality: | |
13109 | return "DW_AT_virtuality"; | |
13110 | case DW_AT_vtable_elem_location: | |
13111 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 13112 | /* DWARF 3 values. */ |
d9fa45fe DC |
13113 | case DW_AT_allocated: |
13114 | return "DW_AT_allocated"; | |
13115 | case DW_AT_associated: | |
13116 | return "DW_AT_associated"; | |
13117 | case DW_AT_data_location: | |
13118 | return "DW_AT_data_location"; | |
09fa0d7c JK |
13119 | case DW_AT_byte_stride: |
13120 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
13121 | case DW_AT_entry_pc: |
13122 | return "DW_AT_entry_pc"; | |
13123 | case DW_AT_use_UTF8: | |
13124 | return "DW_AT_use_UTF8"; | |
13125 | case DW_AT_extension: | |
13126 | return "DW_AT_extension"; | |
13127 | case DW_AT_ranges: | |
13128 | return "DW_AT_ranges"; | |
13129 | case DW_AT_trampoline: | |
13130 | return "DW_AT_trampoline"; | |
13131 | case DW_AT_call_column: | |
13132 | return "DW_AT_call_column"; | |
13133 | case DW_AT_call_file: | |
13134 | return "DW_AT_call_file"; | |
13135 | case DW_AT_call_line: | |
13136 | return "DW_AT_call_line"; | |
b7619582 GF |
13137 | case DW_AT_description: |
13138 | return "DW_AT_description"; | |
13139 | case DW_AT_binary_scale: | |
13140 | return "DW_AT_binary_scale"; | |
13141 | case DW_AT_decimal_scale: | |
13142 | return "DW_AT_decimal_scale"; | |
13143 | case DW_AT_small: | |
13144 | return "DW_AT_small"; | |
13145 | case DW_AT_decimal_sign: | |
13146 | return "DW_AT_decimal_sign"; | |
13147 | case DW_AT_digit_count: | |
13148 | return "DW_AT_digit_count"; | |
13149 | case DW_AT_picture_string: | |
13150 | return "DW_AT_picture_string"; | |
13151 | case DW_AT_mutable: | |
13152 | return "DW_AT_mutable"; | |
13153 | case DW_AT_threads_scaled: | |
13154 | return "DW_AT_threads_scaled"; | |
13155 | case DW_AT_explicit: | |
13156 | return "DW_AT_explicit"; | |
13157 | case DW_AT_object_pointer: | |
13158 | return "DW_AT_object_pointer"; | |
13159 | case DW_AT_endianity: | |
13160 | return "DW_AT_endianity"; | |
13161 | case DW_AT_elemental: | |
13162 | return "DW_AT_elemental"; | |
13163 | case DW_AT_pure: | |
13164 | return "DW_AT_pure"; | |
13165 | case DW_AT_recursive: | |
13166 | return "DW_AT_recursive"; | |
348e048f DE |
13167 | /* DWARF 4 values. */ |
13168 | case DW_AT_signature: | |
13169 | return "DW_AT_signature"; | |
31ef98ae TT |
13170 | case DW_AT_linkage_name: |
13171 | return "DW_AT_linkage_name"; | |
b7619582 | 13172 | /* SGI/MIPS extensions. */ |
c764a876 | 13173 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
13174 | case DW_AT_MIPS_fde: |
13175 | return "DW_AT_MIPS_fde"; | |
c764a876 | 13176 | #endif |
c906108c SS |
13177 | case DW_AT_MIPS_loop_begin: |
13178 | return "DW_AT_MIPS_loop_begin"; | |
13179 | case DW_AT_MIPS_tail_loop_begin: | |
13180 | return "DW_AT_MIPS_tail_loop_begin"; | |
13181 | case DW_AT_MIPS_epilog_begin: | |
13182 | return "DW_AT_MIPS_epilog_begin"; | |
13183 | case DW_AT_MIPS_loop_unroll_factor: | |
13184 | return "DW_AT_MIPS_loop_unroll_factor"; | |
13185 | case DW_AT_MIPS_software_pipeline_depth: | |
13186 | return "DW_AT_MIPS_software_pipeline_depth"; | |
13187 | case DW_AT_MIPS_linkage_name: | |
13188 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
13189 | case DW_AT_MIPS_stride: |
13190 | return "DW_AT_MIPS_stride"; | |
13191 | case DW_AT_MIPS_abstract_name: | |
13192 | return "DW_AT_MIPS_abstract_name"; | |
13193 | case DW_AT_MIPS_clone_origin: | |
13194 | return "DW_AT_MIPS_clone_origin"; | |
13195 | case DW_AT_MIPS_has_inlines: | |
13196 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 13197 | /* HP extensions. */ |
c764a876 | 13198 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
13199 | case DW_AT_HP_block_index: |
13200 | return "DW_AT_HP_block_index"; | |
c764a876 | 13201 | #endif |
b7619582 GF |
13202 | case DW_AT_HP_unmodifiable: |
13203 | return "DW_AT_HP_unmodifiable"; | |
13204 | case DW_AT_HP_actuals_stmt_list: | |
13205 | return "DW_AT_HP_actuals_stmt_list"; | |
13206 | case DW_AT_HP_proc_per_section: | |
13207 | return "DW_AT_HP_proc_per_section"; | |
13208 | case DW_AT_HP_raw_data_ptr: | |
13209 | return "DW_AT_HP_raw_data_ptr"; | |
13210 | case DW_AT_HP_pass_by_reference: | |
13211 | return "DW_AT_HP_pass_by_reference"; | |
13212 | case DW_AT_HP_opt_level: | |
13213 | return "DW_AT_HP_opt_level"; | |
13214 | case DW_AT_HP_prof_version_id: | |
13215 | return "DW_AT_HP_prof_version_id"; | |
13216 | case DW_AT_HP_opt_flags: | |
13217 | return "DW_AT_HP_opt_flags"; | |
13218 | case DW_AT_HP_cold_region_low_pc: | |
13219 | return "DW_AT_HP_cold_region_low_pc"; | |
13220 | case DW_AT_HP_cold_region_high_pc: | |
13221 | return "DW_AT_HP_cold_region_high_pc"; | |
13222 | case DW_AT_HP_all_variables_modifiable: | |
13223 | return "DW_AT_HP_all_variables_modifiable"; | |
13224 | case DW_AT_HP_linkage_name: | |
13225 | return "DW_AT_HP_linkage_name"; | |
13226 | case DW_AT_HP_prof_flags: | |
13227 | return "DW_AT_HP_prof_flags"; | |
13228 | /* GNU extensions. */ | |
c906108c SS |
13229 | case DW_AT_sf_names: |
13230 | return "DW_AT_sf_names"; | |
13231 | case DW_AT_src_info: | |
13232 | return "DW_AT_src_info"; | |
13233 | case DW_AT_mac_info: | |
13234 | return "DW_AT_mac_info"; | |
13235 | case DW_AT_src_coords: | |
13236 | return "DW_AT_src_coords"; | |
13237 | case DW_AT_body_begin: | |
13238 | return "DW_AT_body_begin"; | |
13239 | case DW_AT_body_end: | |
13240 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
13241 | case DW_AT_GNU_vector: |
13242 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
13243 | case DW_AT_GNU_odr_signature: |
13244 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
13245 | /* VMS extensions. */ |
13246 | case DW_AT_VMS_rtnbeg_pd_address: | |
13247 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
13248 | /* UPC extension. */ | |
13249 | case DW_AT_upc_threads_scaled: | |
13250 | return "DW_AT_upc_threads_scaled"; | |
13251 | /* PGI (STMicroelectronics) extensions. */ | |
13252 | case DW_AT_PGI_lbase: | |
13253 | return "DW_AT_PGI_lbase"; | |
13254 | case DW_AT_PGI_soffset: | |
13255 | return "DW_AT_PGI_soffset"; | |
13256 | case DW_AT_PGI_lstride: | |
13257 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
13258 | default: |
13259 | return "DW_AT_<unknown>"; | |
13260 | } | |
13261 | } | |
13262 | ||
13263 | /* Convert a DWARF value form code into its string name. */ | |
13264 | ||
13265 | static char * | |
aa1ee363 | 13266 | dwarf_form_name (unsigned form) |
c906108c SS |
13267 | { |
13268 | switch (form) | |
13269 | { | |
13270 | case DW_FORM_addr: | |
13271 | return "DW_FORM_addr"; | |
13272 | case DW_FORM_block2: | |
13273 | return "DW_FORM_block2"; | |
13274 | case DW_FORM_block4: | |
13275 | return "DW_FORM_block4"; | |
13276 | case DW_FORM_data2: | |
13277 | return "DW_FORM_data2"; | |
13278 | case DW_FORM_data4: | |
13279 | return "DW_FORM_data4"; | |
13280 | case DW_FORM_data8: | |
13281 | return "DW_FORM_data8"; | |
13282 | case DW_FORM_string: | |
13283 | return "DW_FORM_string"; | |
13284 | case DW_FORM_block: | |
13285 | return "DW_FORM_block"; | |
13286 | case DW_FORM_block1: | |
13287 | return "DW_FORM_block1"; | |
13288 | case DW_FORM_data1: | |
13289 | return "DW_FORM_data1"; | |
13290 | case DW_FORM_flag: | |
13291 | return "DW_FORM_flag"; | |
13292 | case DW_FORM_sdata: | |
13293 | return "DW_FORM_sdata"; | |
13294 | case DW_FORM_strp: | |
13295 | return "DW_FORM_strp"; | |
13296 | case DW_FORM_udata: | |
13297 | return "DW_FORM_udata"; | |
13298 | case DW_FORM_ref_addr: | |
13299 | return "DW_FORM_ref_addr"; | |
13300 | case DW_FORM_ref1: | |
13301 | return "DW_FORM_ref1"; | |
13302 | case DW_FORM_ref2: | |
13303 | return "DW_FORM_ref2"; | |
13304 | case DW_FORM_ref4: | |
13305 | return "DW_FORM_ref4"; | |
13306 | case DW_FORM_ref8: | |
13307 | return "DW_FORM_ref8"; | |
13308 | case DW_FORM_ref_udata: | |
13309 | return "DW_FORM_ref_udata"; | |
13310 | case DW_FORM_indirect: | |
13311 | return "DW_FORM_indirect"; | |
348e048f DE |
13312 | case DW_FORM_sec_offset: |
13313 | return "DW_FORM_sec_offset"; | |
13314 | case DW_FORM_exprloc: | |
13315 | return "DW_FORM_exprloc"; | |
13316 | case DW_FORM_flag_present: | |
13317 | return "DW_FORM_flag_present"; | |
55f1336d TT |
13318 | case DW_FORM_ref_sig8: |
13319 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
13320 | default: |
13321 | return "DW_FORM_<unknown>"; | |
13322 | } | |
13323 | } | |
13324 | ||
13325 | /* Convert a DWARF stack opcode into its string name. */ | |
13326 | ||
9eae7c52 | 13327 | const char * |
b1bfef65 | 13328 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
13329 | { |
13330 | switch (op) | |
13331 | { | |
13332 | case DW_OP_addr: | |
13333 | return "DW_OP_addr"; | |
13334 | case DW_OP_deref: | |
13335 | return "DW_OP_deref"; | |
13336 | case DW_OP_const1u: | |
13337 | return "DW_OP_const1u"; | |
13338 | case DW_OP_const1s: | |
13339 | return "DW_OP_const1s"; | |
13340 | case DW_OP_const2u: | |
13341 | return "DW_OP_const2u"; | |
13342 | case DW_OP_const2s: | |
13343 | return "DW_OP_const2s"; | |
13344 | case DW_OP_const4u: | |
13345 | return "DW_OP_const4u"; | |
13346 | case DW_OP_const4s: | |
13347 | return "DW_OP_const4s"; | |
13348 | case DW_OP_const8u: | |
13349 | return "DW_OP_const8u"; | |
13350 | case DW_OP_const8s: | |
13351 | return "DW_OP_const8s"; | |
13352 | case DW_OP_constu: | |
13353 | return "DW_OP_constu"; | |
13354 | case DW_OP_consts: | |
13355 | return "DW_OP_consts"; | |
13356 | case DW_OP_dup: | |
13357 | return "DW_OP_dup"; | |
13358 | case DW_OP_drop: | |
13359 | return "DW_OP_drop"; | |
13360 | case DW_OP_over: | |
13361 | return "DW_OP_over"; | |
13362 | case DW_OP_pick: | |
13363 | return "DW_OP_pick"; | |
13364 | case DW_OP_swap: | |
13365 | return "DW_OP_swap"; | |
13366 | case DW_OP_rot: | |
13367 | return "DW_OP_rot"; | |
13368 | case DW_OP_xderef: | |
13369 | return "DW_OP_xderef"; | |
13370 | case DW_OP_abs: | |
13371 | return "DW_OP_abs"; | |
13372 | case DW_OP_and: | |
13373 | return "DW_OP_and"; | |
13374 | case DW_OP_div: | |
13375 | return "DW_OP_div"; | |
13376 | case DW_OP_minus: | |
13377 | return "DW_OP_minus"; | |
13378 | case DW_OP_mod: | |
13379 | return "DW_OP_mod"; | |
13380 | case DW_OP_mul: | |
13381 | return "DW_OP_mul"; | |
13382 | case DW_OP_neg: | |
13383 | return "DW_OP_neg"; | |
13384 | case DW_OP_not: | |
13385 | return "DW_OP_not"; | |
13386 | case DW_OP_or: | |
13387 | return "DW_OP_or"; | |
13388 | case DW_OP_plus: | |
13389 | return "DW_OP_plus"; | |
13390 | case DW_OP_plus_uconst: | |
13391 | return "DW_OP_plus_uconst"; | |
13392 | case DW_OP_shl: | |
13393 | return "DW_OP_shl"; | |
13394 | case DW_OP_shr: | |
13395 | return "DW_OP_shr"; | |
13396 | case DW_OP_shra: | |
13397 | return "DW_OP_shra"; | |
13398 | case DW_OP_xor: | |
13399 | return "DW_OP_xor"; | |
13400 | case DW_OP_bra: | |
13401 | return "DW_OP_bra"; | |
13402 | case DW_OP_eq: | |
13403 | return "DW_OP_eq"; | |
13404 | case DW_OP_ge: | |
13405 | return "DW_OP_ge"; | |
13406 | case DW_OP_gt: | |
13407 | return "DW_OP_gt"; | |
13408 | case DW_OP_le: | |
13409 | return "DW_OP_le"; | |
13410 | case DW_OP_lt: | |
13411 | return "DW_OP_lt"; | |
13412 | case DW_OP_ne: | |
13413 | return "DW_OP_ne"; | |
13414 | case DW_OP_skip: | |
13415 | return "DW_OP_skip"; | |
13416 | case DW_OP_lit0: | |
13417 | return "DW_OP_lit0"; | |
13418 | case DW_OP_lit1: | |
13419 | return "DW_OP_lit1"; | |
13420 | case DW_OP_lit2: | |
13421 | return "DW_OP_lit2"; | |
13422 | case DW_OP_lit3: | |
13423 | return "DW_OP_lit3"; | |
13424 | case DW_OP_lit4: | |
13425 | return "DW_OP_lit4"; | |
13426 | case DW_OP_lit5: | |
13427 | return "DW_OP_lit5"; | |
13428 | case DW_OP_lit6: | |
13429 | return "DW_OP_lit6"; | |
13430 | case DW_OP_lit7: | |
13431 | return "DW_OP_lit7"; | |
13432 | case DW_OP_lit8: | |
13433 | return "DW_OP_lit8"; | |
13434 | case DW_OP_lit9: | |
13435 | return "DW_OP_lit9"; | |
13436 | case DW_OP_lit10: | |
13437 | return "DW_OP_lit10"; | |
13438 | case DW_OP_lit11: | |
13439 | return "DW_OP_lit11"; | |
13440 | case DW_OP_lit12: | |
13441 | return "DW_OP_lit12"; | |
13442 | case DW_OP_lit13: | |
13443 | return "DW_OP_lit13"; | |
13444 | case DW_OP_lit14: | |
13445 | return "DW_OP_lit14"; | |
13446 | case DW_OP_lit15: | |
13447 | return "DW_OP_lit15"; | |
13448 | case DW_OP_lit16: | |
13449 | return "DW_OP_lit16"; | |
13450 | case DW_OP_lit17: | |
13451 | return "DW_OP_lit17"; | |
13452 | case DW_OP_lit18: | |
13453 | return "DW_OP_lit18"; | |
13454 | case DW_OP_lit19: | |
13455 | return "DW_OP_lit19"; | |
13456 | case DW_OP_lit20: | |
13457 | return "DW_OP_lit20"; | |
13458 | case DW_OP_lit21: | |
13459 | return "DW_OP_lit21"; | |
13460 | case DW_OP_lit22: | |
13461 | return "DW_OP_lit22"; | |
13462 | case DW_OP_lit23: | |
13463 | return "DW_OP_lit23"; | |
13464 | case DW_OP_lit24: | |
13465 | return "DW_OP_lit24"; | |
13466 | case DW_OP_lit25: | |
13467 | return "DW_OP_lit25"; | |
13468 | case DW_OP_lit26: | |
13469 | return "DW_OP_lit26"; | |
13470 | case DW_OP_lit27: | |
13471 | return "DW_OP_lit27"; | |
13472 | case DW_OP_lit28: | |
13473 | return "DW_OP_lit28"; | |
13474 | case DW_OP_lit29: | |
13475 | return "DW_OP_lit29"; | |
13476 | case DW_OP_lit30: | |
13477 | return "DW_OP_lit30"; | |
13478 | case DW_OP_lit31: | |
13479 | return "DW_OP_lit31"; | |
13480 | case DW_OP_reg0: | |
13481 | return "DW_OP_reg0"; | |
13482 | case DW_OP_reg1: | |
13483 | return "DW_OP_reg1"; | |
13484 | case DW_OP_reg2: | |
13485 | return "DW_OP_reg2"; | |
13486 | case DW_OP_reg3: | |
13487 | return "DW_OP_reg3"; | |
13488 | case DW_OP_reg4: | |
13489 | return "DW_OP_reg4"; | |
13490 | case DW_OP_reg5: | |
13491 | return "DW_OP_reg5"; | |
13492 | case DW_OP_reg6: | |
13493 | return "DW_OP_reg6"; | |
13494 | case DW_OP_reg7: | |
13495 | return "DW_OP_reg7"; | |
13496 | case DW_OP_reg8: | |
13497 | return "DW_OP_reg8"; | |
13498 | case DW_OP_reg9: | |
13499 | return "DW_OP_reg9"; | |
13500 | case DW_OP_reg10: | |
13501 | return "DW_OP_reg10"; | |
13502 | case DW_OP_reg11: | |
13503 | return "DW_OP_reg11"; | |
13504 | case DW_OP_reg12: | |
13505 | return "DW_OP_reg12"; | |
13506 | case DW_OP_reg13: | |
13507 | return "DW_OP_reg13"; | |
13508 | case DW_OP_reg14: | |
13509 | return "DW_OP_reg14"; | |
13510 | case DW_OP_reg15: | |
13511 | return "DW_OP_reg15"; | |
13512 | case DW_OP_reg16: | |
13513 | return "DW_OP_reg16"; | |
13514 | case DW_OP_reg17: | |
13515 | return "DW_OP_reg17"; | |
13516 | case DW_OP_reg18: | |
13517 | return "DW_OP_reg18"; | |
13518 | case DW_OP_reg19: | |
13519 | return "DW_OP_reg19"; | |
13520 | case DW_OP_reg20: | |
13521 | return "DW_OP_reg20"; | |
13522 | case DW_OP_reg21: | |
13523 | return "DW_OP_reg21"; | |
13524 | case DW_OP_reg22: | |
13525 | return "DW_OP_reg22"; | |
13526 | case DW_OP_reg23: | |
13527 | return "DW_OP_reg23"; | |
13528 | case DW_OP_reg24: | |
13529 | return "DW_OP_reg24"; | |
13530 | case DW_OP_reg25: | |
13531 | return "DW_OP_reg25"; | |
13532 | case DW_OP_reg26: | |
13533 | return "DW_OP_reg26"; | |
13534 | case DW_OP_reg27: | |
13535 | return "DW_OP_reg27"; | |
13536 | case DW_OP_reg28: | |
13537 | return "DW_OP_reg28"; | |
13538 | case DW_OP_reg29: | |
13539 | return "DW_OP_reg29"; | |
13540 | case DW_OP_reg30: | |
13541 | return "DW_OP_reg30"; | |
13542 | case DW_OP_reg31: | |
13543 | return "DW_OP_reg31"; | |
13544 | case DW_OP_breg0: | |
13545 | return "DW_OP_breg0"; | |
13546 | case DW_OP_breg1: | |
13547 | return "DW_OP_breg1"; | |
13548 | case DW_OP_breg2: | |
13549 | return "DW_OP_breg2"; | |
13550 | case DW_OP_breg3: | |
13551 | return "DW_OP_breg3"; | |
13552 | case DW_OP_breg4: | |
13553 | return "DW_OP_breg4"; | |
13554 | case DW_OP_breg5: | |
13555 | return "DW_OP_breg5"; | |
13556 | case DW_OP_breg6: | |
13557 | return "DW_OP_breg6"; | |
13558 | case DW_OP_breg7: | |
13559 | return "DW_OP_breg7"; | |
13560 | case DW_OP_breg8: | |
13561 | return "DW_OP_breg8"; | |
13562 | case DW_OP_breg9: | |
13563 | return "DW_OP_breg9"; | |
13564 | case DW_OP_breg10: | |
13565 | return "DW_OP_breg10"; | |
13566 | case DW_OP_breg11: | |
13567 | return "DW_OP_breg11"; | |
13568 | case DW_OP_breg12: | |
13569 | return "DW_OP_breg12"; | |
13570 | case DW_OP_breg13: | |
13571 | return "DW_OP_breg13"; | |
13572 | case DW_OP_breg14: | |
13573 | return "DW_OP_breg14"; | |
13574 | case DW_OP_breg15: | |
13575 | return "DW_OP_breg15"; | |
13576 | case DW_OP_breg16: | |
13577 | return "DW_OP_breg16"; | |
13578 | case DW_OP_breg17: | |
13579 | return "DW_OP_breg17"; | |
13580 | case DW_OP_breg18: | |
13581 | return "DW_OP_breg18"; | |
13582 | case DW_OP_breg19: | |
13583 | return "DW_OP_breg19"; | |
13584 | case DW_OP_breg20: | |
13585 | return "DW_OP_breg20"; | |
13586 | case DW_OP_breg21: | |
13587 | return "DW_OP_breg21"; | |
13588 | case DW_OP_breg22: | |
13589 | return "DW_OP_breg22"; | |
13590 | case DW_OP_breg23: | |
13591 | return "DW_OP_breg23"; | |
13592 | case DW_OP_breg24: | |
13593 | return "DW_OP_breg24"; | |
13594 | case DW_OP_breg25: | |
13595 | return "DW_OP_breg25"; | |
13596 | case DW_OP_breg26: | |
13597 | return "DW_OP_breg26"; | |
13598 | case DW_OP_breg27: | |
13599 | return "DW_OP_breg27"; | |
13600 | case DW_OP_breg28: | |
13601 | return "DW_OP_breg28"; | |
13602 | case DW_OP_breg29: | |
13603 | return "DW_OP_breg29"; | |
13604 | case DW_OP_breg30: | |
13605 | return "DW_OP_breg30"; | |
13606 | case DW_OP_breg31: | |
13607 | return "DW_OP_breg31"; | |
13608 | case DW_OP_regx: | |
13609 | return "DW_OP_regx"; | |
13610 | case DW_OP_fbreg: | |
13611 | return "DW_OP_fbreg"; | |
13612 | case DW_OP_bregx: | |
13613 | return "DW_OP_bregx"; | |
13614 | case DW_OP_piece: | |
13615 | return "DW_OP_piece"; | |
13616 | case DW_OP_deref_size: | |
13617 | return "DW_OP_deref_size"; | |
13618 | case DW_OP_xderef_size: | |
13619 | return "DW_OP_xderef_size"; | |
13620 | case DW_OP_nop: | |
13621 | return "DW_OP_nop"; | |
b7619582 | 13622 | /* DWARF 3 extensions. */ |
ed348acc EZ |
13623 | case DW_OP_push_object_address: |
13624 | return "DW_OP_push_object_address"; | |
13625 | case DW_OP_call2: | |
13626 | return "DW_OP_call2"; | |
13627 | case DW_OP_call4: | |
13628 | return "DW_OP_call4"; | |
13629 | case DW_OP_call_ref: | |
13630 | return "DW_OP_call_ref"; | |
b7619582 GF |
13631 | case DW_OP_form_tls_address: |
13632 | return "DW_OP_form_tls_address"; | |
13633 | case DW_OP_call_frame_cfa: | |
13634 | return "DW_OP_call_frame_cfa"; | |
13635 | case DW_OP_bit_piece: | |
13636 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
13637 | /* DWARF 4 extensions. */ |
13638 | case DW_OP_implicit_value: | |
13639 | return "DW_OP_implicit_value"; | |
13640 | case DW_OP_stack_value: | |
13641 | return "DW_OP_stack_value"; | |
13642 | /* GNU extensions. */ | |
ed348acc EZ |
13643 | case DW_OP_GNU_push_tls_address: |
13644 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
13645 | case DW_OP_GNU_uninit: |
13646 | return "DW_OP_GNU_uninit"; | |
8cf6f0b1 TT |
13647 | case DW_OP_GNU_implicit_pointer: |
13648 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
13649 | case DW_OP_GNU_entry_value: |
13650 | return "DW_OP_GNU_entry_value"; | |
13651 | case DW_OP_GNU_const_type: | |
13652 | return "DW_OP_GNU_const_type"; | |
13653 | case DW_OP_GNU_regval_type: | |
13654 | return "DW_OP_GNU_regval_type"; | |
13655 | case DW_OP_GNU_deref_type: | |
13656 | return "DW_OP_GNU_deref_type"; | |
13657 | case DW_OP_GNU_convert: | |
13658 | return "DW_OP_GNU_convert"; | |
13659 | case DW_OP_GNU_reinterpret: | |
13660 | return "DW_OP_GNU_reinterpret"; | |
c906108c | 13661 | default: |
b1bfef65 | 13662 | return NULL; |
c906108c SS |
13663 | } |
13664 | } | |
13665 | ||
13666 | static char * | |
fba45db2 | 13667 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
13668 | { |
13669 | if (mybool) | |
13670 | return "TRUE"; | |
13671 | else | |
13672 | return "FALSE"; | |
13673 | } | |
13674 | ||
13675 | /* Convert a DWARF type code into its string name. */ | |
13676 | ||
13677 | static char * | |
aa1ee363 | 13678 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
13679 | { |
13680 | switch (enc) | |
13681 | { | |
b7619582 GF |
13682 | case DW_ATE_void: |
13683 | return "DW_ATE_void"; | |
c906108c SS |
13684 | case DW_ATE_address: |
13685 | return "DW_ATE_address"; | |
13686 | case DW_ATE_boolean: | |
13687 | return "DW_ATE_boolean"; | |
13688 | case DW_ATE_complex_float: | |
13689 | return "DW_ATE_complex_float"; | |
13690 | case DW_ATE_float: | |
13691 | return "DW_ATE_float"; | |
13692 | case DW_ATE_signed: | |
13693 | return "DW_ATE_signed"; | |
13694 | case DW_ATE_signed_char: | |
13695 | return "DW_ATE_signed_char"; | |
13696 | case DW_ATE_unsigned: | |
13697 | return "DW_ATE_unsigned"; | |
13698 | case DW_ATE_unsigned_char: | |
13699 | return "DW_ATE_unsigned_char"; | |
b7619582 | 13700 | /* DWARF 3. */ |
d9fa45fe DC |
13701 | case DW_ATE_imaginary_float: |
13702 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
13703 | case DW_ATE_packed_decimal: |
13704 | return "DW_ATE_packed_decimal"; | |
13705 | case DW_ATE_numeric_string: | |
13706 | return "DW_ATE_numeric_string"; | |
13707 | case DW_ATE_edited: | |
13708 | return "DW_ATE_edited"; | |
13709 | case DW_ATE_signed_fixed: | |
13710 | return "DW_ATE_signed_fixed"; | |
13711 | case DW_ATE_unsigned_fixed: | |
13712 | return "DW_ATE_unsigned_fixed"; | |
13713 | case DW_ATE_decimal_float: | |
13714 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
13715 | /* DWARF 4. */ |
13716 | case DW_ATE_UTF: | |
13717 | return "DW_ATE_UTF"; | |
b7619582 GF |
13718 | /* HP extensions. */ |
13719 | case DW_ATE_HP_float80: | |
13720 | return "DW_ATE_HP_float80"; | |
13721 | case DW_ATE_HP_complex_float80: | |
13722 | return "DW_ATE_HP_complex_float80"; | |
13723 | case DW_ATE_HP_float128: | |
13724 | return "DW_ATE_HP_float128"; | |
13725 | case DW_ATE_HP_complex_float128: | |
13726 | return "DW_ATE_HP_complex_float128"; | |
13727 | case DW_ATE_HP_floathpintel: | |
13728 | return "DW_ATE_HP_floathpintel"; | |
13729 | case DW_ATE_HP_imaginary_float80: | |
13730 | return "DW_ATE_HP_imaginary_float80"; | |
13731 | case DW_ATE_HP_imaginary_float128: | |
13732 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
13733 | default: |
13734 | return "DW_ATE_<unknown>"; | |
13735 | } | |
13736 | } | |
13737 | ||
0963b4bd | 13738 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
13739 | |
13740 | #if 0 | |
13741 | static char * | |
aa1ee363 | 13742 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
13743 | { |
13744 | switch (cfi_opc) | |
13745 | { | |
13746 | case DW_CFA_advance_loc: | |
13747 | return "DW_CFA_advance_loc"; | |
13748 | case DW_CFA_offset: | |
13749 | return "DW_CFA_offset"; | |
13750 | case DW_CFA_restore: | |
13751 | return "DW_CFA_restore"; | |
13752 | case DW_CFA_nop: | |
13753 | return "DW_CFA_nop"; | |
13754 | case DW_CFA_set_loc: | |
13755 | return "DW_CFA_set_loc"; | |
13756 | case DW_CFA_advance_loc1: | |
13757 | return "DW_CFA_advance_loc1"; | |
13758 | case DW_CFA_advance_loc2: | |
13759 | return "DW_CFA_advance_loc2"; | |
13760 | case DW_CFA_advance_loc4: | |
13761 | return "DW_CFA_advance_loc4"; | |
13762 | case DW_CFA_offset_extended: | |
13763 | return "DW_CFA_offset_extended"; | |
13764 | case DW_CFA_restore_extended: | |
13765 | return "DW_CFA_restore_extended"; | |
13766 | case DW_CFA_undefined: | |
13767 | return "DW_CFA_undefined"; | |
13768 | case DW_CFA_same_value: | |
13769 | return "DW_CFA_same_value"; | |
13770 | case DW_CFA_register: | |
13771 | return "DW_CFA_register"; | |
13772 | case DW_CFA_remember_state: | |
13773 | return "DW_CFA_remember_state"; | |
13774 | case DW_CFA_restore_state: | |
13775 | return "DW_CFA_restore_state"; | |
13776 | case DW_CFA_def_cfa: | |
13777 | return "DW_CFA_def_cfa"; | |
13778 | case DW_CFA_def_cfa_register: | |
13779 | return "DW_CFA_def_cfa_register"; | |
13780 | case DW_CFA_def_cfa_offset: | |
13781 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 13782 | /* DWARF 3. */ |
985cb1a3 JM |
13783 | case DW_CFA_def_cfa_expression: |
13784 | return "DW_CFA_def_cfa_expression"; | |
13785 | case DW_CFA_expression: | |
13786 | return "DW_CFA_expression"; | |
13787 | case DW_CFA_offset_extended_sf: | |
13788 | return "DW_CFA_offset_extended_sf"; | |
13789 | case DW_CFA_def_cfa_sf: | |
13790 | return "DW_CFA_def_cfa_sf"; | |
13791 | case DW_CFA_def_cfa_offset_sf: | |
13792 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
13793 | case DW_CFA_val_offset: |
13794 | return "DW_CFA_val_offset"; | |
13795 | case DW_CFA_val_offset_sf: | |
13796 | return "DW_CFA_val_offset_sf"; | |
13797 | case DW_CFA_val_expression: | |
13798 | return "DW_CFA_val_expression"; | |
13799 | /* SGI/MIPS specific. */ | |
c906108c SS |
13800 | case DW_CFA_MIPS_advance_loc8: |
13801 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 13802 | /* GNU extensions. */ |
985cb1a3 JM |
13803 | case DW_CFA_GNU_window_save: |
13804 | return "DW_CFA_GNU_window_save"; | |
13805 | case DW_CFA_GNU_args_size: | |
13806 | return "DW_CFA_GNU_args_size"; | |
13807 | case DW_CFA_GNU_negative_offset_extended: | |
13808 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
13809 | default: |
13810 | return "DW_CFA_<unknown>"; | |
13811 | } | |
13812 | } | |
13813 | #endif | |
13814 | ||
f9aca02d | 13815 | static void |
d97bc12b | 13816 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
13817 | { |
13818 | unsigned int i; | |
13819 | ||
d97bc12b DE |
13820 | print_spaces (indent, f); |
13821 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 13822 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
13823 | |
13824 | if (die->parent != NULL) | |
13825 | { | |
13826 | print_spaces (indent, f); | |
13827 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
13828 | die->parent->offset); | |
13829 | } | |
13830 | ||
13831 | print_spaces (indent, f); | |
13832 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 13833 | dwarf_bool_name (die->child != NULL)); |
c906108c | 13834 | |
d97bc12b DE |
13835 | print_spaces (indent, f); |
13836 | fprintf_unfiltered (f, " attributes:\n"); | |
13837 | ||
c906108c SS |
13838 | for (i = 0; i < die->num_attrs; ++i) |
13839 | { | |
d97bc12b DE |
13840 | print_spaces (indent, f); |
13841 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
13842 | dwarf_attr_name (die->attrs[i].name), |
13843 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 13844 | |
c906108c SS |
13845 | switch (die->attrs[i].form) |
13846 | { | |
13847 | case DW_FORM_ref_addr: | |
13848 | case DW_FORM_addr: | |
d97bc12b | 13849 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 13850 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
13851 | break; |
13852 | case DW_FORM_block2: | |
13853 | case DW_FORM_block4: | |
13854 | case DW_FORM_block: | |
13855 | case DW_FORM_block1: | |
3e43a32a MS |
13856 | fprintf_unfiltered (f, "block: size %d", |
13857 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 13858 | break; |
2dc7f7b3 TT |
13859 | case DW_FORM_exprloc: |
13860 | fprintf_unfiltered (f, "expression: size %u", | |
13861 | DW_BLOCK (&die->attrs[i])->size); | |
13862 | break; | |
10b3939b DJ |
13863 | case DW_FORM_ref1: |
13864 | case DW_FORM_ref2: | |
13865 | case DW_FORM_ref4: | |
d97bc12b | 13866 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
13867 | (long) (DW_ADDR (&die->attrs[i]))); |
13868 | break; | |
c906108c SS |
13869 | case DW_FORM_data1: |
13870 | case DW_FORM_data2: | |
13871 | case DW_FORM_data4: | |
ce5d95e1 | 13872 | case DW_FORM_data8: |
c906108c SS |
13873 | case DW_FORM_udata: |
13874 | case DW_FORM_sdata: | |
43bbcdc2 PH |
13875 | fprintf_unfiltered (f, "constant: %s", |
13876 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 13877 | break; |
2dc7f7b3 TT |
13878 | case DW_FORM_sec_offset: |
13879 | fprintf_unfiltered (f, "section offset: %s", | |
13880 | pulongest (DW_UNSND (&die->attrs[i]))); | |
13881 | break; | |
55f1336d | 13882 | case DW_FORM_ref_sig8: |
348e048f DE |
13883 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
13884 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b3c8eb43 | 13885 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset); |
348e048f DE |
13886 | else |
13887 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
13888 | break; | |
c906108c | 13889 | case DW_FORM_string: |
4bdf3d34 | 13890 | case DW_FORM_strp: |
8285870a | 13891 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 13892 | DW_STRING (&die->attrs[i]) |
8285870a JK |
13893 | ? DW_STRING (&die->attrs[i]) : "", |
13894 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
13895 | break; |
13896 | case DW_FORM_flag: | |
13897 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 13898 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 13899 | else |
d97bc12b | 13900 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 13901 | break; |
2dc7f7b3 TT |
13902 | case DW_FORM_flag_present: |
13903 | fprintf_unfiltered (f, "flag: TRUE"); | |
13904 | break; | |
a8329558 | 13905 | case DW_FORM_indirect: |
0963b4bd MS |
13906 | /* The reader will have reduced the indirect form to |
13907 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
13908 | fprintf_unfiltered (f, |
13909 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 13910 | break; |
c906108c | 13911 | default: |
d97bc12b | 13912 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 13913 | die->attrs[i].form); |
d97bc12b | 13914 | break; |
c906108c | 13915 | } |
d97bc12b | 13916 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
13917 | } |
13918 | } | |
13919 | ||
f9aca02d | 13920 | static void |
d97bc12b | 13921 | dump_die_for_error (struct die_info *die) |
c906108c | 13922 | { |
d97bc12b DE |
13923 | dump_die_shallow (gdb_stderr, 0, die); |
13924 | } | |
13925 | ||
13926 | static void | |
13927 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
13928 | { | |
13929 | int indent = level * 4; | |
13930 | ||
13931 | gdb_assert (die != NULL); | |
13932 | ||
13933 | if (level >= max_level) | |
13934 | return; | |
13935 | ||
13936 | dump_die_shallow (f, indent, die); | |
13937 | ||
13938 | if (die->child != NULL) | |
c906108c | 13939 | { |
d97bc12b DE |
13940 | print_spaces (indent, f); |
13941 | fprintf_unfiltered (f, " Children:"); | |
13942 | if (level + 1 < max_level) | |
13943 | { | |
13944 | fprintf_unfiltered (f, "\n"); | |
13945 | dump_die_1 (f, level + 1, max_level, die->child); | |
13946 | } | |
13947 | else | |
13948 | { | |
3e43a32a MS |
13949 | fprintf_unfiltered (f, |
13950 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
13951 | } |
13952 | } | |
13953 | ||
13954 | if (die->sibling != NULL && level > 0) | |
13955 | { | |
13956 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
13957 | } |
13958 | } | |
13959 | ||
d97bc12b DE |
13960 | /* This is called from the pdie macro in gdbinit.in. |
13961 | It's not static so gcc will keep a copy callable from gdb. */ | |
13962 | ||
13963 | void | |
13964 | dump_die (struct die_info *die, int max_level) | |
13965 | { | |
13966 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
13967 | } | |
13968 | ||
f9aca02d | 13969 | static void |
51545339 | 13970 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13971 | { |
51545339 | 13972 | void **slot; |
c906108c | 13973 | |
51545339 DJ |
13974 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
13975 | ||
13976 | *slot = die; | |
c906108c SS |
13977 | } |
13978 | ||
93311388 DE |
13979 | static int |
13980 | is_ref_attr (struct attribute *attr) | |
c906108c | 13981 | { |
c906108c SS |
13982 | switch (attr->form) |
13983 | { | |
13984 | case DW_FORM_ref_addr: | |
c906108c SS |
13985 | case DW_FORM_ref1: |
13986 | case DW_FORM_ref2: | |
13987 | case DW_FORM_ref4: | |
613e1657 | 13988 | case DW_FORM_ref8: |
c906108c | 13989 | case DW_FORM_ref_udata: |
93311388 | 13990 | return 1; |
c906108c | 13991 | default: |
93311388 | 13992 | return 0; |
c906108c | 13993 | } |
93311388 DE |
13994 | } |
13995 | ||
13996 | static unsigned int | |
13997 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
13998 | { | |
13999 | if (is_ref_attr (attr)) | |
14000 | return DW_ADDR (attr); | |
14001 | ||
14002 | complaint (&symfile_complaints, | |
14003 | _("unsupported die ref attribute form: '%s'"), | |
14004 | dwarf_form_name (attr->form)); | |
14005 | return 0; | |
c906108c SS |
14006 | } |
14007 | ||
43bbcdc2 PH |
14008 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
14009 | * the value held by the attribute is not constant. */ | |
a02abb62 | 14010 | |
43bbcdc2 | 14011 | static LONGEST |
a02abb62 JB |
14012 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
14013 | { | |
14014 | if (attr->form == DW_FORM_sdata) | |
14015 | return DW_SND (attr); | |
14016 | else if (attr->form == DW_FORM_udata | |
14017 | || attr->form == DW_FORM_data1 | |
14018 | || attr->form == DW_FORM_data2 | |
14019 | || attr->form == DW_FORM_data4 | |
14020 | || attr->form == DW_FORM_data8) | |
14021 | return DW_UNSND (attr); | |
14022 | else | |
14023 | { | |
3e43a32a MS |
14024 | complaint (&symfile_complaints, |
14025 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
14026 | dwarf_form_name (attr->form)); |
14027 | return default_value; | |
14028 | } | |
14029 | } | |
14030 | ||
03dd20cc | 14031 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
14032 | unit and add it to our queue. |
14033 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
14034 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 14035 | |
348e048f | 14036 | static int |
03dd20cc DJ |
14037 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
14038 | struct dwarf2_per_cu_data *per_cu) | |
14039 | { | |
98bfdba5 PA |
14040 | /* We may arrive here during partial symbol reading, if we need full |
14041 | DIEs to process an unusual case (e.g. template arguments). Do | |
14042 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
14043 | if (dwarf2_per_objfile->reading_partial_symbols) | |
14044 | { | |
14045 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
14046 | return 1; | |
14047 | return 0; | |
14048 | } | |
14049 | ||
03dd20cc DJ |
14050 | /* Mark the dependence relation so that we don't flush PER_CU |
14051 | too early. */ | |
14052 | dwarf2_add_dependence (this_cu, per_cu); | |
14053 | ||
14054 | /* If it's already on the queue, we have nothing to do. */ | |
14055 | if (per_cu->queued) | |
348e048f | 14056 | return 0; |
03dd20cc DJ |
14057 | |
14058 | /* If the compilation unit is already loaded, just mark it as | |
14059 | used. */ | |
14060 | if (per_cu->cu != NULL) | |
14061 | { | |
14062 | per_cu->cu->last_used = 0; | |
348e048f | 14063 | return 0; |
03dd20cc DJ |
14064 | } |
14065 | ||
14066 | /* Add it to the queue. */ | |
a0f42c21 | 14067 | queue_comp_unit (per_cu); |
348e048f DE |
14068 | |
14069 | return 1; | |
14070 | } | |
14071 | ||
14072 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
14073 | On entry *REF_CU is the CU of SRC_DIE. | |
14074 | On exit *REF_CU is the CU of the result. */ | |
14075 | ||
14076 | static struct die_info * | |
14077 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
14078 | struct dwarf2_cu **ref_cu) | |
14079 | { | |
14080 | struct die_info *die; | |
14081 | ||
14082 | if (is_ref_attr (attr)) | |
14083 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 14084 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
14085 | die = follow_die_sig (src_die, attr, ref_cu); |
14086 | else | |
14087 | { | |
14088 | dump_die_for_error (src_die); | |
14089 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
14090 | (*ref_cu)->objfile->name); | |
14091 | } | |
14092 | ||
14093 | return die; | |
03dd20cc DJ |
14094 | } |
14095 | ||
5c631832 | 14096 | /* Follow reference OFFSET. |
673bfd45 DE |
14097 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
14098 | On exit *REF_CU is the CU of the result. | |
14099 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 14100 | |
f9aca02d | 14101 | static struct die_info * |
5c631832 | 14102 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 14103 | { |
10b3939b | 14104 | struct die_info temp_die; |
f2f0e013 | 14105 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 14106 | |
348e048f DE |
14107 | gdb_assert (cu->per_cu != NULL); |
14108 | ||
98bfdba5 PA |
14109 | target_cu = cu; |
14110 | ||
b0df02fd | 14111 | if (cu->per_cu->debug_types_section) |
348e048f DE |
14112 | { |
14113 | /* .debug_types CUs cannot reference anything outside their CU. | |
14114 | If they need to, they have to reference a signatured type via | |
55f1336d | 14115 | DW_FORM_ref_sig8. */ |
348e048f | 14116 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 14117 | return NULL; |
348e048f DE |
14118 | } |
14119 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
14120 | { |
14121 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 14122 | |
45452591 | 14123 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
14124 | |
14125 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f | 14126 | if (maybe_queue_comp_unit (cu, per_cu)) |
a0f42c21 | 14127 | load_full_comp_unit (per_cu); |
03dd20cc | 14128 | |
10b3939b DJ |
14129 | target_cu = per_cu->cu; |
14130 | } | |
98bfdba5 PA |
14131 | else if (cu->dies == NULL) |
14132 | { | |
14133 | /* We're loading full DIEs during partial symbol reading. */ | |
14134 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
a0f42c21 | 14135 | load_full_comp_unit (cu->per_cu); |
98bfdba5 | 14136 | } |
c906108c | 14137 | |
f2f0e013 | 14138 | *ref_cu = target_cu; |
51545339 | 14139 | temp_die.offset = offset; |
5c631832 JK |
14140 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
14141 | } | |
10b3939b | 14142 | |
5c631832 JK |
14143 | /* Follow reference attribute ATTR of SRC_DIE. |
14144 | On entry *REF_CU is the CU of SRC_DIE. | |
14145 | On exit *REF_CU is the CU of the result. */ | |
14146 | ||
14147 | static struct die_info * | |
14148 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
14149 | struct dwarf2_cu **ref_cu) | |
14150 | { | |
14151 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
14152 | struct dwarf2_cu *cu = *ref_cu; | |
14153 | struct die_info *die; | |
14154 | ||
14155 | die = follow_die_offset (offset, ref_cu); | |
14156 | if (!die) | |
14157 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
14158 | "at 0x%x [in module %s]"), | |
14159 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 14160 | |
5c631832 JK |
14161 | return die; |
14162 | } | |
14163 | ||
d83e736b JK |
14164 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
14165 | Returned value is intended for DW_OP_call*. Returned | |
14166 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
14167 | |
14168 | struct dwarf2_locexpr_baton | |
14169 | dwarf2_fetch_die_location_block (unsigned int offset, | |
8cf6f0b1 TT |
14170 | struct dwarf2_per_cu_data *per_cu, |
14171 | CORE_ADDR (*get_frame_pc) (void *baton), | |
14172 | void *baton) | |
5c631832 | 14173 | { |
918dd910 | 14174 | struct dwarf2_cu *cu; |
5c631832 JK |
14175 | struct die_info *die; |
14176 | struct attribute *attr; | |
14177 | struct dwarf2_locexpr_baton retval; | |
14178 | ||
8cf6f0b1 TT |
14179 | dw2_setup (per_cu->objfile); |
14180 | ||
918dd910 JK |
14181 | if (per_cu->cu == NULL) |
14182 | load_cu (per_cu); | |
14183 | cu = per_cu->cu; | |
14184 | ||
5c631832 JK |
14185 | die = follow_die_offset (offset, &cu); |
14186 | if (!die) | |
14187 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
bb5ed363 | 14188 | offset, per_cu->objfile->name); |
5c631832 JK |
14189 | |
14190 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
14191 | if (!attr) | |
14192 | { | |
e103e986 JK |
14193 | /* DWARF: "If there is no such attribute, then there is no effect.". |
14194 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 14195 | |
e103e986 | 14196 | retval.data = NULL; |
5c631832 JK |
14197 | retval.size = 0; |
14198 | } | |
8cf6f0b1 TT |
14199 | else if (attr_form_is_section_offset (attr)) |
14200 | { | |
14201 | struct dwarf2_loclist_baton loclist_baton; | |
14202 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
14203 | size_t size; | |
14204 | ||
14205 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
14206 | ||
14207 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
14208 | &size, pc); | |
14209 | retval.size = size; | |
14210 | } | |
5c631832 JK |
14211 | else |
14212 | { | |
14213 | if (!attr_form_is_block (attr)) | |
14214 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
14215 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
bb5ed363 | 14216 | offset, per_cu->objfile->name); |
5c631832 JK |
14217 | |
14218 | retval.data = DW_BLOCK (attr)->data; | |
14219 | retval.size = DW_BLOCK (attr)->size; | |
14220 | } | |
14221 | retval.per_cu = cu->per_cu; | |
918dd910 | 14222 | |
918dd910 JK |
14223 | age_cached_comp_units (); |
14224 | ||
5c631832 | 14225 | return retval; |
348e048f DE |
14226 | } |
14227 | ||
8a9b8146 TT |
14228 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
14229 | PER_CU. */ | |
14230 | ||
14231 | struct type * | |
14232 | dwarf2_get_die_type (unsigned int die_offset, | |
14233 | struct dwarf2_per_cu_data *per_cu) | |
14234 | { | |
8a9b8146 | 14235 | dw2_setup (per_cu->objfile); |
9ff3b74f | 14236 | return get_die_type_at_offset (die_offset, per_cu); |
8a9b8146 TT |
14237 | } |
14238 | ||
348e048f DE |
14239 | /* Follow the signature attribute ATTR in SRC_DIE. |
14240 | On entry *REF_CU is the CU of SRC_DIE. | |
14241 | On exit *REF_CU is the CU of the result. */ | |
14242 | ||
14243 | static struct die_info * | |
14244 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
14245 | struct dwarf2_cu **ref_cu) | |
14246 | { | |
14247 | struct objfile *objfile = (*ref_cu)->objfile; | |
14248 | struct die_info temp_die; | |
14249 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
14250 | struct dwarf2_cu *sig_cu; | |
14251 | struct die_info *die; | |
14252 | ||
14253 | /* sig_type will be NULL if the signatured type is missing from | |
14254 | the debug info. */ | |
14255 | if (sig_type == NULL) | |
14256 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
14257 | "at 0x%x [in module %s]"), | |
14258 | src_die->offset, objfile->name); | |
14259 | ||
14260 | /* If necessary, add it to the queue and load its DIEs. */ | |
14261 | ||
14262 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
a0f42c21 | 14263 | read_signatured_type (sig_type); |
348e048f DE |
14264 | |
14265 | gdb_assert (sig_type->per_cu.cu != NULL); | |
14266 | ||
14267 | sig_cu = sig_type->per_cu.cu; | |
14268 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
14269 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
14270 | if (die) | |
14271 | { | |
14272 | *ref_cu = sig_cu; | |
14273 | return die; | |
14274 | } | |
14275 | ||
3e43a32a MS |
14276 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
14277 | "from DIE at 0x%x [in module %s]"), | |
348e048f DE |
14278 | sig_type->type_offset, src_die->offset, objfile->name); |
14279 | } | |
14280 | ||
14281 | /* Given an offset of a signatured type, return its signatured_type. */ | |
14282 | ||
14283 | static struct signatured_type * | |
8b70b953 TT |
14284 | lookup_signatured_type_at_offset (struct objfile *objfile, |
14285 | struct dwarf2_section_info *section, | |
14286 | unsigned int offset) | |
348e048f | 14287 | { |
8b70b953 | 14288 | gdb_byte *info_ptr = section->buffer + offset; |
348e048f DE |
14289 | unsigned int length, initial_length_size; |
14290 | unsigned int sig_offset; | |
14291 | struct signatured_type find_entry, *type_sig; | |
14292 | ||
14293 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
14294 | sig_offset = (initial_length_size | |
14295 | + 2 /*version*/ | |
14296 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
14297 | + 1 /*address_size*/); | |
14298 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
14299 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
14300 | ||
14301 | /* This is only used to lookup previously recorded types. | |
14302 | If we didn't find it, it's our bug. */ | |
14303 | gdb_assert (type_sig != NULL); | |
b3c8eb43 | 14304 | gdb_assert (offset == type_sig->per_cu.offset); |
348e048f DE |
14305 | |
14306 | return type_sig; | |
14307 | } | |
14308 | ||
e5fe5e75 | 14309 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
14310 | |
14311 | static void | |
e5fe5e75 | 14312 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 14313 | { |
e5fe5e75 DE |
14314 | struct objfile *objfile = per_cu->objfile; |
14315 | struct dwarf2_section_info *sect = per_cu->debug_types_section; | |
14316 | unsigned int offset = per_cu->offset; | |
348e048f DE |
14317 | struct signatured_type *type_sig; |
14318 | ||
8b70b953 | 14319 | dwarf2_read_section (objfile, sect); |
be391dca | 14320 | |
348e048f | 14321 | /* We have the section offset, but we need the signature to do the |
e5fe5e75 DE |
14322 | hash table lookup. */ |
14323 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses | |
14324 | the signature to assert we found the right one. | |
14325 | Ok, but it's a lot of work. We should simplify things so any needed | |
14326 | assert doesn't require all this clumsiness. */ | |
8b70b953 | 14327 | type_sig = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f DE |
14328 | |
14329 | gdb_assert (type_sig->per_cu.cu == NULL); | |
14330 | ||
a0f42c21 | 14331 | read_signatured_type (type_sig); |
348e048f DE |
14332 | |
14333 | gdb_assert (type_sig->per_cu.cu != NULL); | |
14334 | } | |
14335 | ||
14336 | /* Read in a signatured type and build its CU and DIEs. */ | |
14337 | ||
14338 | static void | |
a0f42c21 | 14339 | read_signatured_type (struct signatured_type *type_sig) |
348e048f | 14340 | { |
a0f42c21 | 14341 | struct objfile *objfile = type_sig->per_cu.objfile; |
1fd400ff | 14342 | gdb_byte *types_ptr; |
348e048f DE |
14343 | struct die_reader_specs reader_specs; |
14344 | struct dwarf2_cu *cu; | |
14345 | ULONGEST signature; | |
14346 | struct cleanup *back_to, *free_cu_cleanup; | |
b0df02fd | 14347 | struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section; |
348e048f | 14348 | |
8b70b953 TT |
14349 | dwarf2_read_section (objfile, section); |
14350 | types_ptr = section->buffer + type_sig->per_cu.offset; | |
1fd400ff | 14351 | |
348e048f DE |
14352 | gdb_assert (type_sig->per_cu.cu == NULL); |
14353 | ||
9816fde3 | 14354 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 14355 | init_one_comp_unit (cu, &type_sig->per_cu); |
348e048f DE |
14356 | |
14357 | /* If an error occurs while loading, release our storage. */ | |
68dc6402 | 14358 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
348e048f | 14359 | |
9ff913ba DE |
14360 | types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr, |
14361 | &signature, NULL); | |
348e048f DE |
14362 | gdb_assert (signature == type_sig->signature); |
14363 | ||
14364 | cu->die_hash | |
14365 | = htab_create_alloc_ex (cu->header.length / 12, | |
14366 | die_hash, | |
14367 | die_eq, | |
14368 | NULL, | |
14369 | &cu->comp_unit_obstack, | |
14370 | hashtab_obstack_allocate, | |
14371 | dummy_obstack_deallocate); | |
14372 | ||
e5fe5e75 | 14373 | dwarf2_read_abbrevs (cu); |
348e048f DE |
14374 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
14375 | ||
14376 | init_cu_die_reader (&reader_specs, cu); | |
14377 | ||
14378 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
14379 | NULL /*parent*/); | |
14380 | ||
14381 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 14382 | all CUs needed for references have been loaded yet, and symbol |
348e048f DE |
14383 | table processing isn't initialized. But we have to set the CU language, |
14384 | or we won't be able to build types correctly. */ | |
9816fde3 | 14385 | prepare_one_comp_unit (cu, cu->dies); |
348e048f DE |
14386 | |
14387 | do_cleanups (back_to); | |
14388 | ||
14389 | /* We've successfully allocated this compilation unit. Let our caller | |
14390 | clean it up when finished with it. */ | |
14391 | discard_cleanups (free_cu_cleanup); | |
14392 | ||
14393 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
14394 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
14395 | } |
14396 | ||
c906108c SS |
14397 | /* Decode simple location descriptions. |
14398 | Given a pointer to a dwarf block that defines a location, compute | |
14399 | the location and return the value. | |
14400 | ||
4cecd739 DJ |
14401 | NOTE drow/2003-11-18: This function is called in two situations |
14402 | now: for the address of static or global variables (partial symbols | |
14403 | only) and for offsets into structures which are expected to be | |
14404 | (more or less) constant. The partial symbol case should go away, | |
14405 | and only the constant case should remain. That will let this | |
14406 | function complain more accurately. A few special modes are allowed | |
14407 | without complaint for global variables (for instance, global | |
14408 | register values and thread-local values). | |
c906108c SS |
14409 | |
14410 | A location description containing no operations indicates that the | |
4cecd739 | 14411 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
14412 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
14413 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
14414 | complaint. |
14415 | ||
14416 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
14417 | |
14418 | static CORE_ADDR | |
e7c27a73 | 14419 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 14420 | { |
e7c27a73 | 14421 | struct objfile *objfile = cu->objfile; |
21ae7a4d JK |
14422 | int i; |
14423 | int size = blk->size; | |
14424 | gdb_byte *data = blk->data; | |
14425 | CORE_ADDR stack[64]; | |
14426 | int stacki; | |
14427 | unsigned int bytes_read, unsnd; | |
14428 | gdb_byte op; | |
c906108c | 14429 | |
21ae7a4d JK |
14430 | i = 0; |
14431 | stacki = 0; | |
14432 | stack[stacki] = 0; | |
14433 | stack[++stacki] = 0; | |
14434 | ||
14435 | while (i < size) | |
14436 | { | |
14437 | op = data[i++]; | |
14438 | switch (op) | |
14439 | { | |
14440 | case DW_OP_lit0: | |
14441 | case DW_OP_lit1: | |
14442 | case DW_OP_lit2: | |
14443 | case DW_OP_lit3: | |
14444 | case DW_OP_lit4: | |
14445 | case DW_OP_lit5: | |
14446 | case DW_OP_lit6: | |
14447 | case DW_OP_lit7: | |
14448 | case DW_OP_lit8: | |
14449 | case DW_OP_lit9: | |
14450 | case DW_OP_lit10: | |
14451 | case DW_OP_lit11: | |
14452 | case DW_OP_lit12: | |
14453 | case DW_OP_lit13: | |
14454 | case DW_OP_lit14: | |
14455 | case DW_OP_lit15: | |
14456 | case DW_OP_lit16: | |
14457 | case DW_OP_lit17: | |
14458 | case DW_OP_lit18: | |
14459 | case DW_OP_lit19: | |
14460 | case DW_OP_lit20: | |
14461 | case DW_OP_lit21: | |
14462 | case DW_OP_lit22: | |
14463 | case DW_OP_lit23: | |
14464 | case DW_OP_lit24: | |
14465 | case DW_OP_lit25: | |
14466 | case DW_OP_lit26: | |
14467 | case DW_OP_lit27: | |
14468 | case DW_OP_lit28: | |
14469 | case DW_OP_lit29: | |
14470 | case DW_OP_lit30: | |
14471 | case DW_OP_lit31: | |
14472 | stack[++stacki] = op - DW_OP_lit0; | |
14473 | break; | |
f1bea926 | 14474 | |
21ae7a4d JK |
14475 | case DW_OP_reg0: |
14476 | case DW_OP_reg1: | |
14477 | case DW_OP_reg2: | |
14478 | case DW_OP_reg3: | |
14479 | case DW_OP_reg4: | |
14480 | case DW_OP_reg5: | |
14481 | case DW_OP_reg6: | |
14482 | case DW_OP_reg7: | |
14483 | case DW_OP_reg8: | |
14484 | case DW_OP_reg9: | |
14485 | case DW_OP_reg10: | |
14486 | case DW_OP_reg11: | |
14487 | case DW_OP_reg12: | |
14488 | case DW_OP_reg13: | |
14489 | case DW_OP_reg14: | |
14490 | case DW_OP_reg15: | |
14491 | case DW_OP_reg16: | |
14492 | case DW_OP_reg17: | |
14493 | case DW_OP_reg18: | |
14494 | case DW_OP_reg19: | |
14495 | case DW_OP_reg20: | |
14496 | case DW_OP_reg21: | |
14497 | case DW_OP_reg22: | |
14498 | case DW_OP_reg23: | |
14499 | case DW_OP_reg24: | |
14500 | case DW_OP_reg25: | |
14501 | case DW_OP_reg26: | |
14502 | case DW_OP_reg27: | |
14503 | case DW_OP_reg28: | |
14504 | case DW_OP_reg29: | |
14505 | case DW_OP_reg30: | |
14506 | case DW_OP_reg31: | |
14507 | stack[++stacki] = op - DW_OP_reg0; | |
14508 | if (i < size) | |
14509 | dwarf2_complex_location_expr_complaint (); | |
14510 | break; | |
c906108c | 14511 | |
21ae7a4d JK |
14512 | case DW_OP_regx: |
14513 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
14514 | i += bytes_read; | |
14515 | stack[++stacki] = unsnd; | |
14516 | if (i < size) | |
14517 | dwarf2_complex_location_expr_complaint (); | |
14518 | break; | |
c906108c | 14519 | |
21ae7a4d JK |
14520 | case DW_OP_addr: |
14521 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
14522 | cu, &bytes_read); | |
14523 | i += bytes_read; | |
14524 | break; | |
d53d4ac5 | 14525 | |
21ae7a4d JK |
14526 | case DW_OP_const1u: |
14527 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
14528 | i += 1; | |
14529 | break; | |
14530 | ||
14531 | case DW_OP_const1s: | |
14532 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
14533 | i += 1; | |
14534 | break; | |
14535 | ||
14536 | case DW_OP_const2u: | |
14537 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
14538 | i += 2; | |
14539 | break; | |
14540 | ||
14541 | case DW_OP_const2s: | |
14542 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
14543 | i += 2; | |
14544 | break; | |
d53d4ac5 | 14545 | |
21ae7a4d JK |
14546 | case DW_OP_const4u: |
14547 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
14548 | i += 4; | |
14549 | break; | |
14550 | ||
14551 | case DW_OP_const4s: | |
14552 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
14553 | i += 4; | |
14554 | break; | |
14555 | ||
585861ea JK |
14556 | case DW_OP_const8u: |
14557 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
14558 | i += 8; | |
14559 | break; | |
14560 | ||
21ae7a4d JK |
14561 | case DW_OP_constu: |
14562 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
14563 | &bytes_read); | |
14564 | i += bytes_read; | |
14565 | break; | |
14566 | ||
14567 | case DW_OP_consts: | |
14568 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
14569 | i += bytes_read; | |
14570 | break; | |
14571 | ||
14572 | case DW_OP_dup: | |
14573 | stack[stacki + 1] = stack[stacki]; | |
14574 | stacki++; | |
14575 | break; | |
14576 | ||
14577 | case DW_OP_plus: | |
14578 | stack[stacki - 1] += stack[stacki]; | |
14579 | stacki--; | |
14580 | break; | |
14581 | ||
14582 | case DW_OP_plus_uconst: | |
14583 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
14584 | &bytes_read); | |
14585 | i += bytes_read; | |
14586 | break; | |
14587 | ||
14588 | case DW_OP_minus: | |
14589 | stack[stacki - 1] -= stack[stacki]; | |
14590 | stacki--; | |
14591 | break; | |
14592 | ||
14593 | case DW_OP_deref: | |
14594 | /* If we're not the last op, then we definitely can't encode | |
14595 | this using GDB's address_class enum. This is valid for partial | |
14596 | global symbols, although the variable's address will be bogus | |
14597 | in the psymtab. */ | |
14598 | if (i < size) | |
14599 | dwarf2_complex_location_expr_complaint (); | |
14600 | break; | |
14601 | ||
14602 | case DW_OP_GNU_push_tls_address: | |
14603 | /* The top of the stack has the offset from the beginning | |
14604 | of the thread control block at which the variable is located. */ | |
14605 | /* Nothing should follow this operator, so the top of stack would | |
14606 | be returned. */ | |
14607 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
14608 | address will be bogus in the psymtab. Make it always at least |
14609 | non-zero to not look as a variable garbage collected by linker | |
14610 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
14611 | if (i < size) |
14612 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 14613 | stack[stacki]++; |
21ae7a4d JK |
14614 | break; |
14615 | ||
14616 | case DW_OP_GNU_uninit: | |
14617 | break; | |
14618 | ||
14619 | default: | |
14620 | { | |
14621 | const char *name = dwarf_stack_op_name (op); | |
14622 | ||
14623 | if (name) | |
14624 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
14625 | name); | |
14626 | else | |
14627 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
14628 | op); | |
14629 | } | |
14630 | ||
14631 | return (stack[stacki]); | |
d53d4ac5 | 14632 | } |
3c6e0cb3 | 14633 | |
21ae7a4d JK |
14634 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
14635 | outside of the allocated space. Also enforce minimum>0. */ | |
14636 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
14637 | { | |
14638 | complaint (&symfile_complaints, | |
14639 | _("location description stack overflow")); | |
14640 | return 0; | |
14641 | } | |
14642 | ||
14643 | if (stacki <= 0) | |
14644 | { | |
14645 | complaint (&symfile_complaints, | |
14646 | _("location description stack underflow")); | |
14647 | return 0; | |
14648 | } | |
14649 | } | |
14650 | return (stack[stacki]); | |
c906108c SS |
14651 | } |
14652 | ||
14653 | /* memory allocation interface */ | |
14654 | ||
c906108c | 14655 | static struct dwarf_block * |
7b5a2f43 | 14656 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
14657 | { |
14658 | struct dwarf_block *blk; | |
14659 | ||
14660 | blk = (struct dwarf_block *) | |
7b5a2f43 | 14661 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
14662 | return (blk); |
14663 | } | |
14664 | ||
14665 | static struct abbrev_info * | |
f3dd6933 | 14666 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
14667 | { |
14668 | struct abbrev_info *abbrev; | |
14669 | ||
f3dd6933 DJ |
14670 | abbrev = (struct abbrev_info *) |
14671 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
14672 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
14673 | return (abbrev); | |
14674 | } | |
14675 | ||
14676 | static struct die_info * | |
b60c80d6 | 14677 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
14678 | { |
14679 | struct die_info *die; | |
b60c80d6 DJ |
14680 | size_t size = sizeof (struct die_info); |
14681 | ||
14682 | if (num_attrs > 1) | |
14683 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 14684 | |
b60c80d6 | 14685 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
14686 | memset (die, 0, sizeof (struct die_info)); |
14687 | return (die); | |
14688 | } | |
2e276125 JB |
14689 | |
14690 | \f | |
14691 | /* Macro support. */ | |
14692 | ||
2e276125 JB |
14693 | /* Return the full name of file number I in *LH's file name table. |
14694 | Use COMP_DIR as the name of the current directory of the | |
14695 | compilation. The result is allocated using xmalloc; the caller is | |
14696 | responsible for freeing it. */ | |
14697 | static char * | |
14698 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
14699 | { | |
6a83a1e6 EZ |
14700 | /* Is the file number a valid index into the line header's file name |
14701 | table? Remember that file numbers start with one, not zero. */ | |
14702 | if (1 <= file && file <= lh->num_file_names) | |
14703 | { | |
14704 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 14705 | |
6a83a1e6 EZ |
14706 | if (IS_ABSOLUTE_PATH (fe->name)) |
14707 | return xstrdup (fe->name); | |
14708 | else | |
14709 | { | |
14710 | const char *dir; | |
14711 | int dir_len; | |
14712 | char *full_name; | |
14713 | ||
14714 | if (fe->dir_index) | |
14715 | dir = lh->include_dirs[fe->dir_index - 1]; | |
14716 | else | |
14717 | dir = comp_dir; | |
14718 | ||
14719 | if (dir) | |
14720 | { | |
14721 | dir_len = strlen (dir); | |
14722 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
14723 | strcpy (full_name, dir); | |
14724 | full_name[dir_len] = '/'; | |
14725 | strcpy (full_name + dir_len + 1, fe->name); | |
14726 | return full_name; | |
14727 | } | |
14728 | else | |
14729 | return xstrdup (fe->name); | |
14730 | } | |
14731 | } | |
2e276125 JB |
14732 | else |
14733 | { | |
6a83a1e6 EZ |
14734 | /* The compiler produced a bogus file number. We can at least |
14735 | record the macro definitions made in the file, even if we | |
14736 | won't be able to find the file by name. */ | |
14737 | char fake_name[80]; | |
9a619af0 | 14738 | |
6a83a1e6 | 14739 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 14740 | |
6e70227d | 14741 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
14742 | _("bad file number in macro information (%d)"), |
14743 | file); | |
2e276125 | 14744 | |
6a83a1e6 | 14745 | return xstrdup (fake_name); |
2e276125 JB |
14746 | } |
14747 | } | |
14748 | ||
14749 | ||
14750 | static struct macro_source_file * | |
14751 | macro_start_file (int file, int line, | |
14752 | struct macro_source_file *current_file, | |
14753 | const char *comp_dir, | |
14754 | struct line_header *lh, struct objfile *objfile) | |
14755 | { | |
14756 | /* The full name of this source file. */ | |
14757 | char *full_name = file_full_name (file, lh, comp_dir); | |
14758 | ||
14759 | /* We don't create a macro table for this compilation unit | |
14760 | at all until we actually get a filename. */ | |
14761 | if (! pending_macros) | |
4a146b47 | 14762 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 14763 | objfile->macro_cache); |
2e276125 JB |
14764 | |
14765 | if (! current_file) | |
14766 | /* If we have no current file, then this must be the start_file | |
14767 | directive for the compilation unit's main source file. */ | |
14768 | current_file = macro_set_main (pending_macros, full_name); | |
14769 | else | |
14770 | current_file = macro_include (current_file, line, full_name); | |
14771 | ||
14772 | xfree (full_name); | |
6e70227d | 14773 | |
2e276125 JB |
14774 | return current_file; |
14775 | } | |
14776 | ||
14777 | ||
14778 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
14779 | followed by a null byte. */ | |
14780 | static char * | |
14781 | copy_string (const char *buf, int len) | |
14782 | { | |
14783 | char *s = xmalloc (len + 1); | |
9a619af0 | 14784 | |
2e276125 JB |
14785 | memcpy (s, buf, len); |
14786 | s[len] = '\0'; | |
2e276125 JB |
14787 | return s; |
14788 | } | |
14789 | ||
14790 | ||
14791 | static const char * | |
14792 | consume_improper_spaces (const char *p, const char *body) | |
14793 | { | |
14794 | if (*p == ' ') | |
14795 | { | |
4d3c2250 | 14796 | complaint (&symfile_complaints, |
3e43a32a MS |
14797 | _("macro definition contains spaces " |
14798 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 14799 | body); |
2e276125 JB |
14800 | |
14801 | while (*p == ' ') | |
14802 | p++; | |
14803 | } | |
14804 | ||
14805 | return p; | |
14806 | } | |
14807 | ||
14808 | ||
14809 | static void | |
14810 | parse_macro_definition (struct macro_source_file *file, int line, | |
14811 | const char *body) | |
14812 | { | |
14813 | const char *p; | |
14814 | ||
14815 | /* The body string takes one of two forms. For object-like macro | |
14816 | definitions, it should be: | |
14817 | ||
14818 | <macro name> " " <definition> | |
14819 | ||
14820 | For function-like macro definitions, it should be: | |
14821 | ||
14822 | <macro name> "() " <definition> | |
14823 | or | |
14824 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
14825 | ||
14826 | Spaces may appear only where explicitly indicated, and in the | |
14827 | <definition>. | |
14828 | ||
14829 | The Dwarf 2 spec says that an object-like macro's name is always | |
14830 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 14831 | the space when the macro's definition is the empty string. |
2e276125 JB |
14832 | |
14833 | The Dwarf 2 spec says that there should be no spaces between the | |
14834 | formal arguments in a function-like macro's formal argument list, | |
14835 | but versions of GCC around March 2002 include spaces after the | |
14836 | commas. */ | |
14837 | ||
14838 | ||
14839 | /* Find the extent of the macro name. The macro name is terminated | |
14840 | by either a space or null character (for an object-like macro) or | |
14841 | an opening paren (for a function-like macro). */ | |
14842 | for (p = body; *p; p++) | |
14843 | if (*p == ' ' || *p == '(') | |
14844 | break; | |
14845 | ||
14846 | if (*p == ' ' || *p == '\0') | |
14847 | { | |
14848 | /* It's an object-like macro. */ | |
14849 | int name_len = p - body; | |
14850 | char *name = copy_string (body, name_len); | |
14851 | const char *replacement; | |
14852 | ||
14853 | if (*p == ' ') | |
14854 | replacement = body + name_len + 1; | |
14855 | else | |
14856 | { | |
4d3c2250 | 14857 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14858 | replacement = body + name_len; |
14859 | } | |
6e70227d | 14860 | |
2e276125 JB |
14861 | macro_define_object (file, line, name, replacement); |
14862 | ||
14863 | xfree (name); | |
14864 | } | |
14865 | else if (*p == '(') | |
14866 | { | |
14867 | /* It's a function-like macro. */ | |
14868 | char *name = copy_string (body, p - body); | |
14869 | int argc = 0; | |
14870 | int argv_size = 1; | |
14871 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
14872 | ||
14873 | p++; | |
14874 | ||
14875 | p = consume_improper_spaces (p, body); | |
14876 | ||
14877 | /* Parse the formal argument list. */ | |
14878 | while (*p && *p != ')') | |
14879 | { | |
14880 | /* Find the extent of the current argument name. */ | |
14881 | const char *arg_start = p; | |
14882 | ||
14883 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
14884 | p++; | |
14885 | ||
14886 | if (! *p || p == arg_start) | |
4d3c2250 | 14887 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14888 | else |
14889 | { | |
14890 | /* Make sure argv has room for the new argument. */ | |
14891 | if (argc >= argv_size) | |
14892 | { | |
14893 | argv_size *= 2; | |
14894 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
14895 | } | |
14896 | ||
14897 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
14898 | } | |
14899 | ||
14900 | p = consume_improper_spaces (p, body); | |
14901 | ||
14902 | /* Consume the comma, if present. */ | |
14903 | if (*p == ',') | |
14904 | { | |
14905 | p++; | |
14906 | ||
14907 | p = consume_improper_spaces (p, body); | |
14908 | } | |
14909 | } | |
14910 | ||
14911 | if (*p == ')') | |
14912 | { | |
14913 | p++; | |
14914 | ||
14915 | if (*p == ' ') | |
14916 | /* Perfectly formed definition, no complaints. */ | |
14917 | macro_define_function (file, line, name, | |
6e70227d | 14918 | argc, (const char **) argv, |
2e276125 JB |
14919 | p + 1); |
14920 | else if (*p == '\0') | |
14921 | { | |
14922 | /* Complain, but do define it. */ | |
4d3c2250 | 14923 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 14924 | macro_define_function (file, line, name, |
6e70227d | 14925 | argc, (const char **) argv, |
2e276125 JB |
14926 | p); |
14927 | } | |
14928 | else | |
14929 | /* Just complain. */ | |
4d3c2250 | 14930 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14931 | } |
14932 | else | |
14933 | /* Just complain. */ | |
4d3c2250 | 14934 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14935 | |
14936 | xfree (name); | |
14937 | { | |
14938 | int i; | |
14939 | ||
14940 | for (i = 0; i < argc; i++) | |
14941 | xfree (argv[i]); | |
14942 | } | |
14943 | xfree (argv); | |
14944 | } | |
14945 | else | |
4d3c2250 | 14946 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14947 | } |
14948 | ||
cf2c3c16 TT |
14949 | /* Skip some bytes from BYTES according to the form given in FORM. |
14950 | Returns the new pointer. */ | |
2e276125 | 14951 | |
cf2c3c16 TT |
14952 | static gdb_byte * |
14953 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, | |
14954 | enum dwarf_form form, | |
14955 | unsigned int offset_size, | |
14956 | struct dwarf2_section_info *section) | |
2e276125 | 14957 | { |
cf2c3c16 | 14958 | unsigned int bytes_read; |
2e276125 | 14959 | |
cf2c3c16 | 14960 | switch (form) |
2e276125 | 14961 | { |
cf2c3c16 TT |
14962 | case DW_FORM_data1: |
14963 | case DW_FORM_flag: | |
14964 | ++bytes; | |
14965 | break; | |
14966 | ||
14967 | case DW_FORM_data2: | |
14968 | bytes += 2; | |
14969 | break; | |
14970 | ||
14971 | case DW_FORM_data4: | |
14972 | bytes += 4; | |
14973 | break; | |
14974 | ||
14975 | case DW_FORM_data8: | |
14976 | bytes += 8; | |
14977 | break; | |
14978 | ||
14979 | case DW_FORM_string: | |
14980 | read_direct_string (abfd, bytes, &bytes_read); | |
14981 | bytes += bytes_read; | |
14982 | break; | |
14983 | ||
14984 | case DW_FORM_sec_offset: | |
14985 | case DW_FORM_strp: | |
14986 | bytes += offset_size; | |
14987 | break; | |
14988 | ||
14989 | case DW_FORM_block: | |
14990 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
14991 | bytes += bytes_read; | |
14992 | break; | |
14993 | ||
14994 | case DW_FORM_block1: | |
14995 | bytes += 1 + read_1_byte (abfd, bytes); | |
14996 | break; | |
14997 | case DW_FORM_block2: | |
14998 | bytes += 2 + read_2_bytes (abfd, bytes); | |
14999 | break; | |
15000 | case DW_FORM_block4: | |
15001 | bytes += 4 + read_4_bytes (abfd, bytes); | |
15002 | break; | |
15003 | ||
15004 | case DW_FORM_sdata: | |
15005 | case DW_FORM_udata: | |
15006 | bytes = skip_leb128 (abfd, bytes); | |
15007 | break; | |
15008 | ||
15009 | default: | |
15010 | { | |
15011 | complain: | |
15012 | complaint (&symfile_complaints, | |
15013 | _("invalid form 0x%x in `%s'"), | |
15014 | form, | |
15015 | section->asection->name); | |
15016 | return NULL; | |
15017 | } | |
2e276125 JB |
15018 | } |
15019 | ||
cf2c3c16 TT |
15020 | return bytes; |
15021 | } | |
757a13d0 | 15022 | |
cf2c3c16 TT |
15023 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
15024 | opcode. Returns an updated pointer to the macro data buffer; or, | |
15025 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 15026 | |
cf2c3c16 TT |
15027 | static gdb_byte * |
15028 | skip_unknown_opcode (unsigned int opcode, | |
15029 | gdb_byte **opcode_definitions, | |
15030 | gdb_byte *mac_ptr, | |
15031 | bfd *abfd, | |
15032 | unsigned int offset_size, | |
15033 | struct dwarf2_section_info *section) | |
15034 | { | |
15035 | unsigned int bytes_read, i; | |
15036 | unsigned long arg; | |
15037 | gdb_byte *defn; | |
2e276125 | 15038 | |
cf2c3c16 | 15039 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 15040 | { |
cf2c3c16 TT |
15041 | complaint (&symfile_complaints, |
15042 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
15043 | opcode); | |
15044 | return NULL; | |
15045 | } | |
2e276125 | 15046 | |
cf2c3c16 TT |
15047 | defn = opcode_definitions[opcode]; |
15048 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
15049 | defn += bytes_read; | |
2e276125 | 15050 | |
cf2c3c16 TT |
15051 | for (i = 0; i < arg; ++i) |
15052 | { | |
15053 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); | |
15054 | if (mac_ptr == NULL) | |
15055 | { | |
15056 | /* skip_form_bytes already issued the complaint. */ | |
15057 | return NULL; | |
15058 | } | |
15059 | } | |
757a13d0 | 15060 | |
cf2c3c16 TT |
15061 | return mac_ptr; |
15062 | } | |
757a13d0 | 15063 | |
cf2c3c16 TT |
15064 | /* A helper function which parses the header of a macro section. |
15065 | If the macro section is the extended (for now called "GNU") type, | |
15066 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
15067 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 15068 | |
cf2c3c16 TT |
15069 | static gdb_byte * |
15070 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
15071 | bfd *abfd, | |
15072 | gdb_byte *mac_ptr, | |
15073 | unsigned int *offset_size, | |
15074 | int section_is_gnu) | |
15075 | { | |
15076 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 15077 | |
cf2c3c16 TT |
15078 | if (section_is_gnu) |
15079 | { | |
15080 | unsigned int version, flags; | |
757a13d0 | 15081 | |
cf2c3c16 TT |
15082 | version = read_2_bytes (abfd, mac_ptr); |
15083 | if (version != 4) | |
15084 | { | |
15085 | complaint (&symfile_complaints, | |
15086 | _("unrecognized version `%d' in .debug_macro section"), | |
15087 | version); | |
15088 | return NULL; | |
15089 | } | |
15090 | mac_ptr += 2; | |
757a13d0 | 15091 | |
cf2c3c16 TT |
15092 | flags = read_1_byte (abfd, mac_ptr); |
15093 | ++mac_ptr; | |
15094 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 15095 | |
cf2c3c16 TT |
15096 | if ((flags & 2) != 0) |
15097 | /* We don't need the line table offset. */ | |
15098 | mac_ptr += *offset_size; | |
757a13d0 | 15099 | |
cf2c3c16 TT |
15100 | /* Vendor opcode descriptions. */ |
15101 | if ((flags & 4) != 0) | |
15102 | { | |
15103 | unsigned int i, count; | |
757a13d0 | 15104 | |
cf2c3c16 TT |
15105 | count = read_1_byte (abfd, mac_ptr); |
15106 | ++mac_ptr; | |
15107 | for (i = 0; i < count; ++i) | |
15108 | { | |
15109 | unsigned int opcode, bytes_read; | |
15110 | unsigned long arg; | |
15111 | ||
15112 | opcode = read_1_byte (abfd, mac_ptr); | |
15113 | ++mac_ptr; | |
15114 | opcode_definitions[opcode] = mac_ptr; | |
15115 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15116 | mac_ptr += bytes_read; | |
15117 | mac_ptr += arg; | |
15118 | } | |
757a13d0 | 15119 | } |
cf2c3c16 | 15120 | } |
757a13d0 | 15121 | |
cf2c3c16 TT |
15122 | return mac_ptr; |
15123 | } | |
757a13d0 | 15124 | |
cf2c3c16 TT |
15125 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
15126 | including DW_GNU_MACINFO_transparent_include. */ | |
15127 | ||
15128 | static void | |
15129 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
15130 | struct macro_source_file *current_file, | |
15131 | struct line_header *lh, char *comp_dir, | |
15132 | struct dwarf2_section_info *section, | |
15133 | int section_is_gnu, | |
15134 | unsigned int offset_size, | |
15135 | struct objfile *objfile) | |
15136 | { | |
15137 | enum dwarf_macro_record_type macinfo_type; | |
15138 | int at_commandline; | |
15139 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 15140 | |
cf2c3c16 TT |
15141 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
15142 | &offset_size, section_is_gnu); | |
15143 | if (mac_ptr == NULL) | |
15144 | { | |
15145 | /* We already issued a complaint. */ | |
15146 | return; | |
15147 | } | |
757a13d0 JK |
15148 | |
15149 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
15150 | GDB is still reading the definitions from command line. First | |
15151 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
15152 | to create CURRENT_FILE for the main source holding also the command line | |
15153 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
15154 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
15155 | ||
15156 | at_commandline = 1; | |
15157 | ||
15158 | do | |
15159 | { | |
15160 | /* Do we at least have room for a macinfo type byte? */ | |
15161 | if (mac_ptr >= mac_end) | |
15162 | { | |
cf2c3c16 | 15163 | dwarf2_macros_too_long_complaint (section); |
757a13d0 JK |
15164 | break; |
15165 | } | |
15166 | ||
15167 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15168 | mac_ptr++; | |
15169 | ||
cf2c3c16 TT |
15170 | /* Note that we rely on the fact that the corresponding GNU and |
15171 | DWARF constants are the same. */ | |
757a13d0 JK |
15172 | switch (macinfo_type) |
15173 | { | |
15174 | /* A zero macinfo type indicates the end of the macro | |
15175 | information. */ | |
15176 | case 0: | |
15177 | break; | |
2e276125 | 15178 | |
cf2c3c16 TT |
15179 | case DW_MACRO_GNU_define: |
15180 | case DW_MACRO_GNU_undef: | |
15181 | case DW_MACRO_GNU_define_indirect: | |
15182 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 15183 | { |
891d2f0b | 15184 | unsigned int bytes_read; |
2e276125 JB |
15185 | int line; |
15186 | char *body; | |
cf2c3c16 | 15187 | int is_define; |
2e276125 | 15188 | |
cf2c3c16 TT |
15189 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15190 | mac_ptr += bytes_read; | |
15191 | ||
15192 | if (macinfo_type == DW_MACRO_GNU_define | |
15193 | || macinfo_type == DW_MACRO_GNU_undef) | |
15194 | { | |
15195 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
15196 | mac_ptr += bytes_read; | |
15197 | } | |
15198 | else | |
15199 | { | |
15200 | LONGEST str_offset; | |
15201 | ||
15202 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15203 | mac_ptr += offset_size; | |
2e276125 | 15204 | |
cf2c3c16 TT |
15205 | body = read_indirect_string_at_offset (abfd, str_offset); |
15206 | } | |
15207 | ||
15208 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
15209 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 15210 | if (! current_file) |
757a13d0 JK |
15211 | { |
15212 | /* DWARF violation as no main source is present. */ | |
15213 | complaint (&symfile_complaints, | |
15214 | _("debug info with no main source gives macro %s " | |
15215 | "on line %d: %s"), | |
cf2c3c16 TT |
15216 | is_define ? _("definition") : _("undefinition"), |
15217 | line, body); | |
757a13d0 JK |
15218 | break; |
15219 | } | |
3e43a32a MS |
15220 | if ((line == 0 && !at_commandline) |
15221 | || (line != 0 && at_commandline)) | |
4d3c2250 | 15222 | complaint (&symfile_complaints, |
757a13d0 JK |
15223 | _("debug info gives %s macro %s with %s line %d: %s"), |
15224 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 15225 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
15226 | line == 0 ? _("zero") : _("non-zero"), line, body); |
15227 | ||
cf2c3c16 | 15228 | if (is_define) |
757a13d0 | 15229 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
15230 | else |
15231 | { | |
15232 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
15233 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
15234 | macro_undef (current_file, line, body); | |
15235 | } | |
2e276125 JB |
15236 | } |
15237 | break; | |
15238 | ||
cf2c3c16 | 15239 | case DW_MACRO_GNU_start_file: |
2e276125 | 15240 | { |
891d2f0b | 15241 | unsigned int bytes_read; |
2e276125 JB |
15242 | int line, file; |
15243 | ||
15244 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15245 | mac_ptr += bytes_read; | |
15246 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15247 | mac_ptr += bytes_read; | |
15248 | ||
3e43a32a MS |
15249 | if ((line == 0 && !at_commandline) |
15250 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
15251 | complaint (&symfile_complaints, |
15252 | _("debug info gives source %d included " | |
15253 | "from %s at %s line %d"), | |
15254 | file, at_commandline ? _("command-line") : _("file"), | |
15255 | line == 0 ? _("zero") : _("non-zero"), line); | |
15256 | ||
15257 | if (at_commandline) | |
15258 | { | |
cf2c3c16 TT |
15259 | /* This DW_MACRO_GNU_start_file was executed in the |
15260 | pass one. */ | |
757a13d0 JK |
15261 | at_commandline = 0; |
15262 | } | |
15263 | else | |
15264 | current_file = macro_start_file (file, line, | |
15265 | current_file, comp_dir, | |
cf2c3c16 | 15266 | lh, objfile); |
2e276125 JB |
15267 | } |
15268 | break; | |
15269 | ||
cf2c3c16 | 15270 | case DW_MACRO_GNU_end_file: |
2e276125 | 15271 | if (! current_file) |
4d3c2250 | 15272 | complaint (&symfile_complaints, |
3e43a32a MS |
15273 | _("macro debug info has an unmatched " |
15274 | "`close_file' directive")); | |
2e276125 JB |
15275 | else |
15276 | { | |
15277 | current_file = current_file->included_by; | |
15278 | if (! current_file) | |
15279 | { | |
cf2c3c16 | 15280 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
15281 | |
15282 | /* GCC circa March 2002 doesn't produce the zero | |
15283 | type byte marking the end of the compilation | |
15284 | unit. Complain if it's not there, but exit no | |
15285 | matter what. */ | |
15286 | ||
15287 | /* Do we at least have room for a macinfo type byte? */ | |
15288 | if (mac_ptr >= mac_end) | |
15289 | { | |
cf2c3c16 | 15290 | dwarf2_macros_too_long_complaint (section); |
2e276125 JB |
15291 | return; |
15292 | } | |
15293 | ||
15294 | /* We don't increment mac_ptr here, so this is just | |
15295 | a look-ahead. */ | |
15296 | next_type = read_1_byte (abfd, mac_ptr); | |
15297 | if (next_type != 0) | |
4d3c2250 | 15298 | complaint (&symfile_complaints, |
3e43a32a MS |
15299 | _("no terminating 0-type entry for " |
15300 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
15301 | |
15302 | return; | |
15303 | } | |
15304 | } | |
15305 | break; | |
15306 | ||
cf2c3c16 TT |
15307 | case DW_MACRO_GNU_transparent_include: |
15308 | { | |
15309 | LONGEST offset; | |
15310 | ||
15311 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15312 | mac_ptr += offset_size; | |
15313 | ||
15314 | dwarf_decode_macro_bytes (abfd, | |
15315 | section->buffer + offset, | |
15316 | mac_end, current_file, | |
15317 | lh, comp_dir, | |
15318 | section, section_is_gnu, | |
15319 | offset_size, objfile); | |
15320 | } | |
15321 | break; | |
15322 | ||
2e276125 | 15323 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
15324 | if (!section_is_gnu) |
15325 | { | |
15326 | unsigned int bytes_read; | |
15327 | int constant; | |
2e276125 | 15328 | |
cf2c3c16 TT |
15329 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15330 | mac_ptr += bytes_read; | |
15331 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15332 | mac_ptr += bytes_read; | |
2e276125 | 15333 | |
cf2c3c16 TT |
15334 | /* We don't recognize any vendor extensions. */ |
15335 | break; | |
15336 | } | |
15337 | /* FALLTHROUGH */ | |
15338 | ||
15339 | default: | |
15340 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15341 | mac_ptr, abfd, offset_size, | |
15342 | section); | |
15343 | if (mac_ptr == NULL) | |
15344 | return; | |
15345 | break; | |
2e276125 | 15346 | } |
757a13d0 | 15347 | } while (macinfo_type != 0); |
2e276125 | 15348 | } |
8e19ed76 | 15349 | |
cf2c3c16 TT |
15350 | static void |
15351 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
15352 | char *comp_dir, bfd *abfd, | |
15353 | struct dwarf2_cu *cu, | |
15354 | struct dwarf2_section_info *section, | |
15355 | int section_is_gnu) | |
15356 | { | |
bb5ed363 | 15357 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
cf2c3c16 TT |
15358 | gdb_byte *mac_ptr, *mac_end; |
15359 | struct macro_source_file *current_file = 0; | |
15360 | enum dwarf_macro_record_type macinfo_type; | |
15361 | unsigned int offset_size = cu->header.offset_size; | |
15362 | gdb_byte *opcode_definitions[256]; | |
15363 | ||
bb5ed363 | 15364 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
15365 | if (section->buffer == NULL) |
15366 | { | |
15367 | complaint (&symfile_complaints, _("missing %s section"), | |
15368 | section->asection->name); | |
15369 | return; | |
15370 | } | |
15371 | ||
15372 | /* First pass: Find the name of the base filename. | |
15373 | This filename is needed in order to process all macros whose definition | |
15374 | (or undefinition) comes from the command line. These macros are defined | |
15375 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
15376 | associated to the base file. | |
15377 | ||
15378 | To determine the base file name, we scan the macro definitions until we | |
15379 | reach the first DW_MACINFO_start_file entry. We then initialize | |
15380 | CURRENT_FILE accordingly so that any macro definition found before the | |
15381 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
15382 | ||
15383 | mac_ptr = section->buffer + offset; | |
15384 | mac_end = section->buffer + section->size; | |
15385 | ||
15386 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
15387 | &offset_size, section_is_gnu); | |
15388 | if (mac_ptr == NULL) | |
15389 | { | |
15390 | /* We already issued a complaint. */ | |
15391 | return; | |
15392 | } | |
15393 | ||
15394 | do | |
15395 | { | |
15396 | /* Do we at least have room for a macinfo type byte? */ | |
15397 | if (mac_ptr >= mac_end) | |
15398 | { | |
15399 | /* Complaint is printed during the second pass as GDB will probably | |
15400 | stop the first pass earlier upon finding | |
15401 | DW_MACINFO_start_file. */ | |
15402 | break; | |
15403 | } | |
15404 | ||
15405 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15406 | mac_ptr++; | |
15407 | ||
15408 | /* Note that we rely on the fact that the corresponding GNU and | |
15409 | DWARF constants are the same. */ | |
15410 | switch (macinfo_type) | |
15411 | { | |
15412 | /* A zero macinfo type indicates the end of the macro | |
15413 | information. */ | |
15414 | case 0: | |
15415 | break; | |
15416 | ||
15417 | case DW_MACRO_GNU_define: | |
15418 | case DW_MACRO_GNU_undef: | |
15419 | /* Only skip the data by MAC_PTR. */ | |
15420 | { | |
15421 | unsigned int bytes_read; | |
15422 | ||
15423 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15424 | mac_ptr += bytes_read; | |
15425 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15426 | mac_ptr += bytes_read; | |
15427 | } | |
15428 | break; | |
15429 | ||
15430 | case DW_MACRO_GNU_start_file: | |
15431 | { | |
15432 | unsigned int bytes_read; | |
15433 | int line, file; | |
15434 | ||
15435 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15436 | mac_ptr += bytes_read; | |
15437 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15438 | mac_ptr += bytes_read; | |
15439 | ||
15440 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 15441 | comp_dir, lh, objfile); |
cf2c3c16 TT |
15442 | } |
15443 | break; | |
15444 | ||
15445 | case DW_MACRO_GNU_end_file: | |
15446 | /* No data to skip by MAC_PTR. */ | |
15447 | break; | |
15448 | ||
15449 | case DW_MACRO_GNU_define_indirect: | |
15450 | case DW_MACRO_GNU_undef_indirect: | |
15451 | { | |
15452 | unsigned int bytes_read; | |
15453 | ||
15454 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15455 | mac_ptr += bytes_read; | |
15456 | mac_ptr += offset_size; | |
15457 | } | |
15458 | break; | |
15459 | ||
15460 | case DW_MACRO_GNU_transparent_include: | |
15461 | /* Note that, according to the spec, a transparent include | |
15462 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
15463 | skip this opcode. */ | |
15464 | mac_ptr += offset_size; | |
15465 | break; | |
15466 | ||
15467 | case DW_MACINFO_vendor_ext: | |
15468 | /* Only skip the data by MAC_PTR. */ | |
15469 | if (!section_is_gnu) | |
15470 | { | |
15471 | unsigned int bytes_read; | |
15472 | ||
15473 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15474 | mac_ptr += bytes_read; | |
15475 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15476 | mac_ptr += bytes_read; | |
15477 | } | |
15478 | /* FALLTHROUGH */ | |
15479 | ||
15480 | default: | |
15481 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15482 | mac_ptr, abfd, offset_size, | |
15483 | section); | |
15484 | if (mac_ptr == NULL) | |
15485 | return; | |
15486 | break; | |
15487 | } | |
15488 | } while (macinfo_type != 0 && current_file == NULL); | |
15489 | ||
15490 | /* Second pass: Process all entries. | |
15491 | ||
15492 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
15493 | command-line macro definitions/undefinitions. This flag is unset when we | |
15494 | reach the first DW_MACINFO_start_file entry. */ | |
15495 | ||
15496 | dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end, | |
15497 | current_file, lh, comp_dir, section, section_is_gnu, | |
bb5ed363 | 15498 | offset_size, objfile); |
cf2c3c16 TT |
15499 | } |
15500 | ||
8e19ed76 | 15501 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 15502 | if so return true else false. */ |
8e19ed76 PS |
15503 | static int |
15504 | attr_form_is_block (struct attribute *attr) | |
15505 | { | |
15506 | return (attr == NULL ? 0 : | |
15507 | attr->form == DW_FORM_block1 | |
15508 | || attr->form == DW_FORM_block2 | |
15509 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
15510 | || attr->form == DW_FORM_block |
15511 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 15512 | } |
4c2df51b | 15513 | |
c6a0999f JB |
15514 | /* Return non-zero if ATTR's value is a section offset --- classes |
15515 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
15516 | You may use DW_UNSND (attr) to retrieve such offsets. | |
15517 | ||
15518 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
15519 | may have a value that belongs to more than one of these classes; it | |
15520 | would be ambiguous if we did, because we use the same forms for all | |
15521 | of them. */ | |
3690dd37 JB |
15522 | static int |
15523 | attr_form_is_section_offset (struct attribute *attr) | |
15524 | { | |
15525 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
15526 | || attr->form == DW_FORM_data8 |
15527 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
15528 | } |
15529 | ||
15530 | ||
15531 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
15532 | zero otherwise. When this function returns true, you can apply | |
15533 | dwarf2_get_attr_constant_value to it. | |
15534 | ||
15535 | However, note that for some attributes you must check | |
15536 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
15537 | and DW_FORM_data8 are members of both the constant class, and of | |
15538 | the classes that contain offsets into other debug sections | |
15539 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
15540 | that, if an attribute's can be either a constant or one of the | |
15541 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
15542 | taken as section offsets, not constants. */ | |
15543 | static int | |
15544 | attr_form_is_constant (struct attribute *attr) | |
15545 | { | |
15546 | switch (attr->form) | |
15547 | { | |
15548 | case DW_FORM_sdata: | |
15549 | case DW_FORM_udata: | |
15550 | case DW_FORM_data1: | |
15551 | case DW_FORM_data2: | |
15552 | case DW_FORM_data4: | |
15553 | case DW_FORM_data8: | |
15554 | return 1; | |
15555 | default: | |
15556 | return 0; | |
15557 | } | |
15558 | } | |
15559 | ||
8cf6f0b1 TT |
15560 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
15561 | ||
15562 | static void | |
15563 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
15564 | struct dwarf2_loclist_baton *baton, | |
15565 | struct attribute *attr) | |
15566 | { | |
15567 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
15568 | &dwarf2_per_objfile->loc); | |
15569 | ||
15570 | baton->per_cu = cu->per_cu; | |
15571 | gdb_assert (baton->per_cu); | |
15572 | /* We don't know how long the location list is, but make sure we | |
15573 | don't run off the edge of the section. */ | |
15574 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
15575 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
15576 | baton->base_address = cu->base_address; | |
15577 | } | |
15578 | ||
4c2df51b DJ |
15579 | static void |
15580 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 15581 | struct dwarf2_cu *cu) |
4c2df51b | 15582 | { |
bb5ed363 DE |
15583 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
15584 | ||
3690dd37 | 15585 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
15586 | /* ".debug_loc" may not exist at all, or the offset may be outside |
15587 | the section. If so, fall through to the complaint in the | |
15588 | other branch. */ | |
bb5ed363 | 15589 | && DW_UNSND (attr) < dwarf2_section_size (objfile, |
9e0ac564 | 15590 | &dwarf2_per_objfile->loc)) |
4c2df51b | 15591 | { |
0d53c4c4 | 15592 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 15593 | |
bb5ed363 | 15594 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15595 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 15596 | |
8cf6f0b1 | 15597 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 15598 | |
d00adf39 | 15599 | if (cu->base_known == 0) |
0d53c4c4 | 15600 | complaint (&symfile_complaints, |
3e43a32a MS |
15601 | _("Location list used without " |
15602 | "specifying the CU base address.")); | |
4c2df51b | 15603 | |
768a979c | 15604 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
15605 | SYMBOL_LOCATION_BATON (sym) = baton; |
15606 | } | |
15607 | else | |
15608 | { | |
15609 | struct dwarf2_locexpr_baton *baton; | |
15610 | ||
bb5ed363 | 15611 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15612 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
15613 | baton->per_cu = cu->per_cu; |
15614 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
15615 | |
15616 | if (attr_form_is_block (attr)) | |
15617 | { | |
15618 | /* Note that we're just copying the block's data pointer | |
15619 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
15620 | info_buffer for SYM's objfile; right now we never release |
15621 | that buffer, but when we do clean up properly this may | |
15622 | need to change. */ | |
0d53c4c4 DJ |
15623 | baton->size = DW_BLOCK (attr)->size; |
15624 | baton->data = DW_BLOCK (attr)->data; | |
15625 | } | |
15626 | else | |
15627 | { | |
15628 | dwarf2_invalid_attrib_class_complaint ("location description", | |
15629 | SYMBOL_NATURAL_NAME (sym)); | |
15630 | baton->size = 0; | |
0d53c4c4 | 15631 | } |
6e70227d | 15632 | |
768a979c | 15633 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
15634 | SYMBOL_LOCATION_BATON (sym) = baton; |
15635 | } | |
4c2df51b | 15636 | } |
6502dd73 | 15637 | |
9aa1f1e3 TT |
15638 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
15639 | came from a separate debuginfo file, then the master objfile is | |
15640 | returned. */ | |
ae0d2f24 UW |
15641 | |
15642 | struct objfile * | |
15643 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
15644 | { | |
9291a0cd | 15645 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
15646 | |
15647 | /* Return the master objfile, so that we can report and look up the | |
15648 | correct file containing this variable. */ | |
15649 | if (objfile->separate_debug_objfile_backlink) | |
15650 | objfile = objfile->separate_debug_objfile_backlink; | |
15651 | ||
15652 | return objfile; | |
15653 | } | |
15654 | ||
96408a79 SA |
15655 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
15656 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
15657 | CU_HEADERP first. */ | |
15658 | ||
15659 | static const struct comp_unit_head * | |
15660 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
15661 | struct dwarf2_per_cu_data *per_cu) | |
15662 | { | |
15663 | struct objfile *objfile; | |
15664 | struct dwarf2_per_objfile *per_objfile; | |
15665 | gdb_byte *info_ptr; | |
15666 | ||
15667 | if (per_cu->cu) | |
15668 | return &per_cu->cu->header; | |
15669 | ||
15670 | objfile = per_cu->objfile; | |
15671 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15672 | info_ptr = per_objfile->info.buffer + per_cu->offset; | |
15673 | ||
15674 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
15675 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); | |
15676 | ||
15677 | return cu_headerp; | |
15678 | } | |
15679 | ||
ae0d2f24 UW |
15680 | /* Return the address size given in the compilation unit header for CU. */ |
15681 | ||
98714339 | 15682 | int |
ae0d2f24 UW |
15683 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
15684 | { | |
96408a79 SA |
15685 | struct comp_unit_head cu_header_local; |
15686 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 15687 | |
96408a79 SA |
15688 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15689 | ||
15690 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
15691 | } |
15692 | ||
9eae7c52 TT |
15693 | /* Return the offset size given in the compilation unit header for CU. */ |
15694 | ||
15695 | int | |
15696 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
15697 | { | |
96408a79 SA |
15698 | struct comp_unit_head cu_header_local; |
15699 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 15700 | |
96408a79 SA |
15701 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15702 | ||
15703 | return cu_headerp->offset_size; | |
15704 | } | |
15705 | ||
15706 | /* See its dwarf2loc.h declaration. */ | |
15707 | ||
15708 | int | |
15709 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
15710 | { | |
15711 | struct comp_unit_head cu_header_local; | |
15712 | const struct comp_unit_head *cu_headerp; | |
15713 | ||
15714 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
15715 | ||
15716 | if (cu_headerp->version == 2) | |
15717 | return cu_headerp->addr_size; | |
15718 | else | |
15719 | return cu_headerp->offset_size; | |
181cebd4 JK |
15720 | } |
15721 | ||
9aa1f1e3 TT |
15722 | /* Return the text offset of the CU. The returned offset comes from |
15723 | this CU's objfile. If this objfile came from a separate debuginfo | |
15724 | file, then the offset may be different from the corresponding | |
15725 | offset in the parent objfile. */ | |
15726 | ||
15727 | CORE_ADDR | |
15728 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
15729 | { | |
bb3fa9d0 | 15730 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
15731 | |
15732 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
15733 | } | |
15734 | ||
348e048f DE |
15735 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
15736 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
15737 | |
15738 | static struct dwarf2_per_cu_data * | |
c764a876 | 15739 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
15740 | struct objfile *objfile) |
15741 | { | |
15742 | struct dwarf2_per_cu_data *this_cu; | |
15743 | int low, high; | |
15744 | ||
ae038cb0 DJ |
15745 | low = 0; |
15746 | high = dwarf2_per_objfile->n_comp_units - 1; | |
15747 | while (high > low) | |
15748 | { | |
15749 | int mid = low + (high - low) / 2; | |
9a619af0 | 15750 | |
ae038cb0 DJ |
15751 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
15752 | high = mid; | |
15753 | else | |
15754 | low = mid + 1; | |
15755 | } | |
15756 | gdb_assert (low == high); | |
15757 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
15758 | { | |
10b3939b | 15759 | if (low == 0) |
8a3fe4f8 AC |
15760 | error (_("Dwarf Error: could not find partial DIE containing " |
15761 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
15762 | (long) offset, bfd_get_filename (objfile->obfd)); |
15763 | ||
ae038cb0 DJ |
15764 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
15765 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
15766 | } | |
15767 | else | |
15768 | { | |
15769 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
15770 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
15771 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 15772 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
15773 | gdb_assert (offset < this_cu->offset + this_cu->length); |
15774 | return this_cu; | |
15775 | } | |
15776 | } | |
15777 | ||
23745b47 | 15778 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 15779 | |
9816fde3 | 15780 | static void |
23745b47 | 15781 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 15782 | { |
9816fde3 | 15783 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
15784 | per_cu->cu = cu; |
15785 | cu->per_cu = per_cu; | |
15786 | cu->objfile = per_cu->objfile; | |
93311388 | 15787 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
15788 | } |
15789 | ||
15790 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
15791 | ||
15792 | static void | |
15793 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
15794 | { | |
15795 | struct attribute *attr; | |
15796 | ||
15797 | /* Set the language we're debugging. */ | |
15798 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
15799 | if (attr) | |
15800 | set_cu_language (DW_UNSND (attr), cu); | |
15801 | else | |
9cded63f TT |
15802 | { |
15803 | cu->language = language_minimal; | |
15804 | cu->language_defn = language_def (cu->language); | |
15805 | } | |
93311388 DE |
15806 | } |
15807 | ||
ae038cb0 DJ |
15808 | /* Release one cached compilation unit, CU. We unlink it from the tree |
15809 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
15810 | the caller is responsible for that. |
15811 | NOTE: DATA is a void * because this function is also used as a | |
15812 | cleanup routine. */ | |
ae038cb0 DJ |
15813 | |
15814 | static void | |
68dc6402 | 15815 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
15816 | { |
15817 | struct dwarf2_cu *cu = data; | |
15818 | ||
23745b47 DE |
15819 | gdb_assert (cu->per_cu != NULL); |
15820 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
15821 | cu->per_cu = NULL; |
15822 | ||
15823 | obstack_free (&cu->comp_unit_obstack, NULL); | |
15824 | ||
15825 | xfree (cu); | |
15826 | } | |
15827 | ||
72bf9492 | 15828 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
15829 | when we're finished with it. We can't free the pointer itself, but be |
15830 | sure to unlink it from the cache. Also release any associated storage | |
15831 | and perform cache maintenance. | |
72bf9492 DJ |
15832 | |
15833 | Only used during partial symbol parsing. */ | |
15834 | ||
15835 | static void | |
15836 | free_stack_comp_unit (void *data) | |
15837 | { | |
15838 | struct dwarf2_cu *cu = data; | |
15839 | ||
23745b47 DE |
15840 | gdb_assert (cu->per_cu != NULL); |
15841 | cu->per_cu->cu = NULL; | |
15842 | cu->per_cu = NULL; | |
15843 | ||
72bf9492 DJ |
15844 | obstack_free (&cu->comp_unit_obstack, NULL); |
15845 | cu->partial_dies = NULL; | |
ae038cb0 | 15846 | |
23745b47 DE |
15847 | /* The previous code only did this if per_cu != NULL. |
15848 | But that would always succeed, so now we just unconditionally do | |
15849 | the aging. This seems like the wrong place to do such aging, | |
15850 | but cleaning that up is left for later. */ | |
15851 | age_cached_comp_units (); | |
ae038cb0 DJ |
15852 | } |
15853 | ||
15854 | /* Free all cached compilation units. */ | |
15855 | ||
15856 | static void | |
15857 | free_cached_comp_units (void *data) | |
15858 | { | |
15859 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15860 | ||
15861 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15862 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15863 | while (per_cu != NULL) | |
15864 | { | |
15865 | struct dwarf2_per_cu_data *next_cu; | |
15866 | ||
15867 | next_cu = per_cu->cu->read_in_chain; | |
15868 | ||
68dc6402 | 15869 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15870 | *last_chain = next_cu; |
15871 | ||
15872 | per_cu = next_cu; | |
15873 | } | |
15874 | } | |
15875 | ||
15876 | /* Increase the age counter on each cached compilation unit, and free | |
15877 | any that are too old. */ | |
15878 | ||
15879 | static void | |
15880 | age_cached_comp_units (void) | |
15881 | { | |
15882 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15883 | ||
15884 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
15885 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15886 | while (per_cu != NULL) | |
15887 | { | |
15888 | per_cu->cu->last_used ++; | |
15889 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
15890 | dwarf2_mark (per_cu->cu); | |
15891 | per_cu = per_cu->cu->read_in_chain; | |
15892 | } | |
15893 | ||
15894 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15895 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15896 | while (per_cu != NULL) | |
15897 | { | |
15898 | struct dwarf2_per_cu_data *next_cu; | |
15899 | ||
15900 | next_cu = per_cu->cu->read_in_chain; | |
15901 | ||
15902 | if (!per_cu->cu->mark) | |
15903 | { | |
68dc6402 | 15904 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15905 | *last_chain = next_cu; |
15906 | } | |
15907 | else | |
15908 | last_chain = &per_cu->cu->read_in_chain; | |
15909 | ||
15910 | per_cu = next_cu; | |
15911 | } | |
15912 | } | |
15913 | ||
15914 | /* Remove a single compilation unit from the cache. */ | |
15915 | ||
15916 | static void | |
15917 | free_one_cached_comp_unit (void *target_cu) | |
15918 | { | |
15919 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15920 | ||
15921 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15922 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15923 | while (per_cu != NULL) | |
15924 | { | |
15925 | struct dwarf2_per_cu_data *next_cu; | |
15926 | ||
15927 | next_cu = per_cu->cu->read_in_chain; | |
15928 | ||
15929 | if (per_cu->cu == target_cu) | |
15930 | { | |
68dc6402 | 15931 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15932 | *last_chain = next_cu; |
15933 | break; | |
15934 | } | |
15935 | else | |
15936 | last_chain = &per_cu->cu->read_in_chain; | |
15937 | ||
15938 | per_cu = next_cu; | |
15939 | } | |
15940 | } | |
15941 | ||
fe3e1990 DJ |
15942 | /* Release all extra memory associated with OBJFILE. */ |
15943 | ||
15944 | void | |
15945 | dwarf2_free_objfile (struct objfile *objfile) | |
15946 | { | |
15947 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15948 | ||
15949 | if (dwarf2_per_objfile == NULL) | |
15950 | return; | |
15951 | ||
15952 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
15953 | free_cached_comp_units (NULL); | |
15954 | ||
7b9f3c50 DE |
15955 | if (dwarf2_per_objfile->quick_file_names_table) |
15956 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 15957 | |
fe3e1990 DJ |
15958 | /* Everything else should be on the objfile obstack. */ |
15959 | } | |
15960 | ||
1c379e20 DJ |
15961 | /* A pair of DIE offset and GDB type pointer. We store these |
15962 | in a hash table separate from the DIEs, and preserve them | |
15963 | when the DIEs are flushed out of cache. */ | |
15964 | ||
15965 | struct dwarf2_offset_and_type | |
15966 | { | |
15967 | unsigned int offset; | |
15968 | struct type *type; | |
15969 | }; | |
15970 | ||
15971 | /* Hash function for a dwarf2_offset_and_type. */ | |
15972 | ||
15973 | static hashval_t | |
15974 | offset_and_type_hash (const void *item) | |
15975 | { | |
15976 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 15977 | |
1c379e20 DJ |
15978 | return ofs->offset; |
15979 | } | |
15980 | ||
15981 | /* Equality function for a dwarf2_offset_and_type. */ | |
15982 | ||
15983 | static int | |
15984 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
15985 | { | |
15986 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
15987 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 15988 | |
1c379e20 DJ |
15989 | return ofs_lhs->offset == ofs_rhs->offset; |
15990 | } | |
15991 | ||
15992 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
15993 | table if necessary. For convenience, return TYPE. |
15994 | ||
15995 | The DIEs reading must have careful ordering to: | |
15996 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
15997 | reading current DIE. | |
15998 | * Not trying to dereference contents of still incompletely read in types | |
15999 | while reading in other DIEs. | |
16000 | * Enable referencing still incompletely read in types just by a pointer to | |
16001 | the type without accessing its fields. | |
16002 | ||
16003 | Therefore caller should follow these rules: | |
16004 | * Try to fetch any prerequisite types we may need to build this DIE type | |
16005 | before building the type and calling set_die_type. | |
e71ec853 | 16006 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
16007 | possible before fetching more types to complete the current type. |
16008 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 16009 | |
f792889a | 16010 | static struct type * |
1c379e20 DJ |
16011 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
16012 | { | |
16013 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
16014 | struct objfile *objfile = cu->objfile; |
16015 | htab_t *type_hash_ptr; | |
1c379e20 | 16016 | |
b4ba55a1 JB |
16017 | /* For Ada types, make sure that the gnat-specific data is always |
16018 | initialized (if not already set). There are a few types where | |
16019 | we should not be doing so, because the type-specific area is | |
16020 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
16021 | where the type-specific area is used to store the floatformat). | |
16022 | But this is not a problem, because the gnat-specific information | |
16023 | is actually not needed for these types. */ | |
16024 | if (need_gnat_info (cu) | |
16025 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
16026 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
16027 | && !HAVE_GNAT_AUX_INFO (type)) | |
16028 | INIT_GNAT_SPECIFIC (type); | |
16029 | ||
b0df02fd | 16030 | if (cu->per_cu->debug_types_section) |
673bfd45 DE |
16031 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; |
16032 | else | |
16033 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
16034 | ||
16035 | if (*type_hash_ptr == NULL) | |
f792889a | 16036 | { |
673bfd45 DE |
16037 | *type_hash_ptr |
16038 | = htab_create_alloc_ex (127, | |
f792889a DJ |
16039 | offset_and_type_hash, |
16040 | offset_and_type_eq, | |
16041 | NULL, | |
673bfd45 | 16042 | &objfile->objfile_obstack, |
f792889a DJ |
16043 | hashtab_obstack_allocate, |
16044 | dummy_obstack_deallocate); | |
f792889a | 16045 | } |
1c379e20 DJ |
16046 | |
16047 | ofs.offset = die->offset; | |
16048 | ofs.type = type; | |
16049 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 16050 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
16051 | if (*slot) |
16052 | complaint (&symfile_complaints, | |
16053 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
16054 | die->offset); | |
673bfd45 | 16055 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 16056 | **slot = ofs; |
f792889a | 16057 | return type; |
1c379e20 DJ |
16058 | } |
16059 | ||
673bfd45 DE |
16060 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
16061 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
16062 | |
16063 | static struct type * | |
673bfd45 DE |
16064 | get_die_type_at_offset (unsigned int offset, |
16065 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
16066 | { |
16067 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 16068 | htab_t type_hash; |
f792889a | 16069 | |
b0df02fd | 16070 | if (per_cu->debug_types_section) |
673bfd45 DE |
16071 | type_hash = dwarf2_per_objfile->debug_types_type_hash; |
16072 | else | |
16073 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
16074 | if (type_hash == NULL) |
16075 | return NULL; | |
1c379e20 | 16076 | |
673bfd45 | 16077 | ofs.offset = offset; |
1c379e20 DJ |
16078 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
16079 | if (slot) | |
16080 | return slot->type; | |
16081 | else | |
16082 | return NULL; | |
16083 | } | |
16084 | ||
673bfd45 DE |
16085 | /* Look up the type for DIE in the appropriate type_hash table, |
16086 | or return NULL if DIE does not have a saved type. */ | |
16087 | ||
16088 | static struct type * | |
16089 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
16090 | { | |
16091 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
16092 | } | |
16093 | ||
10b3939b DJ |
16094 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
16095 | ||
16096 | static void | |
16097 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
16098 | struct dwarf2_per_cu_data *ref_per_cu) | |
16099 | { | |
16100 | void **slot; | |
16101 | ||
16102 | if (cu->dependencies == NULL) | |
16103 | cu->dependencies | |
16104 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
16105 | NULL, &cu->comp_unit_obstack, | |
16106 | hashtab_obstack_allocate, | |
16107 | dummy_obstack_deallocate); | |
16108 | ||
16109 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
16110 | if (*slot == NULL) | |
16111 | *slot = ref_per_cu; | |
16112 | } | |
1c379e20 | 16113 | |
f504f079 DE |
16114 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
16115 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
16116 | cache that we must keep because we are keeping CU. */ |
16117 | ||
10b3939b DJ |
16118 | static int |
16119 | dwarf2_mark_helper (void **slot, void *data) | |
16120 | { | |
16121 | struct dwarf2_per_cu_data *per_cu; | |
16122 | ||
16123 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
16124 | |
16125 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
16126 | reading of the chain. As such dependencies remain valid it is not much | |
16127 | useful to track and undo them during QUIT cleanups. */ | |
16128 | if (per_cu->cu == NULL) | |
16129 | return 1; | |
16130 | ||
10b3939b DJ |
16131 | if (per_cu->cu->mark) |
16132 | return 1; | |
16133 | per_cu->cu->mark = 1; | |
16134 | ||
16135 | if (per_cu->cu->dependencies != NULL) | |
16136 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
16137 | ||
16138 | return 1; | |
16139 | } | |
16140 | ||
f504f079 DE |
16141 | /* Set the mark field in CU and in every other compilation unit in the |
16142 | cache that we must keep because we are keeping CU. */ | |
16143 | ||
ae038cb0 DJ |
16144 | static void |
16145 | dwarf2_mark (struct dwarf2_cu *cu) | |
16146 | { | |
16147 | if (cu->mark) | |
16148 | return; | |
16149 | cu->mark = 1; | |
10b3939b DJ |
16150 | if (cu->dependencies != NULL) |
16151 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
16152 | } |
16153 | ||
16154 | static void | |
16155 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
16156 | { | |
16157 | while (per_cu) | |
16158 | { | |
16159 | per_cu->cu->mark = 0; | |
16160 | per_cu = per_cu->cu->read_in_chain; | |
16161 | } | |
72bf9492 DJ |
16162 | } |
16163 | ||
72bf9492 DJ |
16164 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
16165 | is its offset in .debug_info for this objfile. */ | |
16166 | ||
16167 | static hashval_t | |
16168 | partial_die_hash (const void *item) | |
16169 | { | |
16170 | const struct partial_die_info *part_die = item; | |
9a619af0 | 16171 | |
72bf9492 DJ |
16172 | return part_die->offset; |
16173 | } | |
16174 | ||
16175 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
16176 | are equal if they have the same offset. */ | |
16177 | ||
16178 | static int | |
16179 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
16180 | { | |
16181 | const struct partial_die_info *part_die_lhs = item_lhs; | |
16182 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 16183 | |
72bf9492 DJ |
16184 | return part_die_lhs->offset == part_die_rhs->offset; |
16185 | } | |
16186 | ||
ae038cb0 DJ |
16187 | static struct cmd_list_element *set_dwarf2_cmdlist; |
16188 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
16189 | ||
16190 | static void | |
16191 | set_dwarf2_cmd (char *args, int from_tty) | |
16192 | { | |
16193 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
16194 | } | |
16195 | ||
16196 | static void | |
16197 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 16198 | { |
ae038cb0 DJ |
16199 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
16200 | } | |
16201 | ||
dce234bc PP |
16202 | /* If section described by INFO was mmapped, munmap it now. */ |
16203 | ||
16204 | static void | |
16205 | munmap_section_buffer (struct dwarf2_section_info *info) | |
16206 | { | |
b315ab21 | 16207 | if (info->map_addr != NULL) |
dce234bc PP |
16208 | { |
16209 | #ifdef HAVE_MMAP | |
b315ab21 | 16210 | int res; |
9a619af0 | 16211 | |
b315ab21 TG |
16212 | res = munmap (info->map_addr, info->map_len); |
16213 | gdb_assert (res == 0); | |
dce234bc PP |
16214 | #else |
16215 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 16216 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
16217 | #endif |
16218 | } | |
16219 | } | |
16220 | ||
16221 | /* munmap debug sections for OBJFILE, if necessary. */ | |
16222 | ||
16223 | static void | |
c1bd65d0 | 16224 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
16225 | { |
16226 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
16227 | int ix; |
16228 | struct dwarf2_section_info *section; | |
9a619af0 | 16229 | |
16be1145 DE |
16230 | /* This is sorted according to the order they're defined in to make it easier |
16231 | to keep in sync. */ | |
dce234bc PP |
16232 | munmap_section_buffer (&data->info); |
16233 | munmap_section_buffer (&data->abbrev); | |
16234 | munmap_section_buffer (&data->line); | |
16be1145 | 16235 | munmap_section_buffer (&data->loc); |
dce234bc | 16236 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 16237 | munmap_section_buffer (&data->macro); |
16be1145 | 16238 | munmap_section_buffer (&data->str); |
dce234bc | 16239 | munmap_section_buffer (&data->ranges); |
dce234bc PP |
16240 | munmap_section_buffer (&data->frame); |
16241 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 16242 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
16243 | |
16244 | for (ix = 0; | |
16245 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
16246 | ++ix) | |
16247 | munmap_section_buffer (section); | |
16248 | ||
16249 | VEC_free (dwarf2_section_info_def, data->types); | |
9291a0cd TT |
16250 | } |
16251 | ||
16252 | \f | |
ae2de4f8 | 16253 | /* The "save gdb-index" command. */ |
9291a0cd TT |
16254 | |
16255 | /* The contents of the hash table we create when building the string | |
16256 | table. */ | |
16257 | struct strtab_entry | |
16258 | { | |
16259 | offset_type offset; | |
16260 | const char *str; | |
16261 | }; | |
16262 | ||
559a7a62 JK |
16263 | /* Hash function for a strtab_entry. |
16264 | ||
16265 | Function is used only during write_hash_table so no index format backward | |
16266 | compatibility is needed. */ | |
b89be57b | 16267 | |
9291a0cd TT |
16268 | static hashval_t |
16269 | hash_strtab_entry (const void *e) | |
16270 | { | |
16271 | const struct strtab_entry *entry = e; | |
559a7a62 | 16272 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
16273 | } |
16274 | ||
16275 | /* Equality function for a strtab_entry. */ | |
b89be57b | 16276 | |
9291a0cd TT |
16277 | static int |
16278 | eq_strtab_entry (const void *a, const void *b) | |
16279 | { | |
16280 | const struct strtab_entry *ea = a; | |
16281 | const struct strtab_entry *eb = b; | |
16282 | return !strcmp (ea->str, eb->str); | |
16283 | } | |
16284 | ||
16285 | /* Create a strtab_entry hash table. */ | |
b89be57b | 16286 | |
9291a0cd TT |
16287 | static htab_t |
16288 | create_strtab (void) | |
16289 | { | |
16290 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
16291 | xfree, xcalloc, xfree); | |
16292 | } | |
16293 | ||
16294 | /* Add a string to the constant pool. Return the string's offset in | |
16295 | host order. */ | |
b89be57b | 16296 | |
9291a0cd TT |
16297 | static offset_type |
16298 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
16299 | { | |
16300 | void **slot; | |
16301 | struct strtab_entry entry; | |
16302 | struct strtab_entry *result; | |
16303 | ||
16304 | entry.str = str; | |
16305 | slot = htab_find_slot (table, &entry, INSERT); | |
16306 | if (*slot) | |
16307 | result = *slot; | |
16308 | else | |
16309 | { | |
16310 | result = XNEW (struct strtab_entry); | |
16311 | result->offset = obstack_object_size (cpool); | |
16312 | result->str = str; | |
16313 | obstack_grow_str0 (cpool, str); | |
16314 | *slot = result; | |
16315 | } | |
16316 | return result->offset; | |
16317 | } | |
16318 | ||
16319 | /* An entry in the symbol table. */ | |
16320 | struct symtab_index_entry | |
16321 | { | |
16322 | /* The name of the symbol. */ | |
16323 | const char *name; | |
16324 | /* The offset of the name in the constant pool. */ | |
16325 | offset_type index_offset; | |
16326 | /* A sorted vector of the indices of all the CUs that hold an object | |
16327 | of this name. */ | |
16328 | VEC (offset_type) *cu_indices; | |
16329 | }; | |
16330 | ||
16331 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
16332 | struct mapped_symtab | |
16333 | { | |
16334 | offset_type n_elements; | |
16335 | offset_type size; | |
16336 | struct symtab_index_entry **data; | |
16337 | }; | |
16338 | ||
16339 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 16340 | |
9291a0cd TT |
16341 | static hashval_t |
16342 | hash_symtab_entry (const void *e) | |
16343 | { | |
16344 | const struct symtab_index_entry *entry = e; | |
16345 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
16346 | sizeof (offset_type) * VEC_length (offset_type, | |
16347 | entry->cu_indices), | |
16348 | 0); | |
16349 | } | |
16350 | ||
16351 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 16352 | |
9291a0cd TT |
16353 | static int |
16354 | eq_symtab_entry (const void *a, const void *b) | |
16355 | { | |
16356 | const struct symtab_index_entry *ea = a; | |
16357 | const struct symtab_index_entry *eb = b; | |
16358 | int len = VEC_length (offset_type, ea->cu_indices); | |
16359 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
16360 | return 0; | |
16361 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
16362 | VEC_address (offset_type, eb->cu_indices), | |
16363 | sizeof (offset_type) * len); | |
16364 | } | |
16365 | ||
16366 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 16367 | |
9291a0cd TT |
16368 | static void |
16369 | delete_symtab_entry (void *p) | |
16370 | { | |
16371 | struct symtab_index_entry *entry = p; | |
16372 | VEC_free (offset_type, entry->cu_indices); | |
16373 | xfree (entry); | |
16374 | } | |
16375 | ||
16376 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 16377 | |
9291a0cd | 16378 | static htab_t |
3876f04e | 16379 | create_symbol_hash_table (void) |
9291a0cd TT |
16380 | { |
16381 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
16382 | delete_symtab_entry, xcalloc, xfree); | |
16383 | } | |
16384 | ||
16385 | /* Create a new mapped symtab object. */ | |
b89be57b | 16386 | |
9291a0cd TT |
16387 | static struct mapped_symtab * |
16388 | create_mapped_symtab (void) | |
16389 | { | |
16390 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
16391 | symtab->n_elements = 0; | |
16392 | symtab->size = 1024; | |
16393 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16394 | return symtab; | |
16395 | } | |
16396 | ||
16397 | /* Destroy a mapped_symtab. */ | |
b89be57b | 16398 | |
9291a0cd TT |
16399 | static void |
16400 | cleanup_mapped_symtab (void *p) | |
16401 | { | |
16402 | struct mapped_symtab *symtab = p; | |
16403 | /* The contents of the array are freed when the other hash table is | |
16404 | destroyed. */ | |
16405 | xfree (symtab->data); | |
16406 | xfree (symtab); | |
16407 | } | |
16408 | ||
16409 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
16410 | the slot. |
16411 | ||
16412 | Function is used only during write_hash_table so no index format backward | |
16413 | compatibility is needed. */ | |
b89be57b | 16414 | |
9291a0cd TT |
16415 | static struct symtab_index_entry ** |
16416 | find_slot (struct mapped_symtab *symtab, const char *name) | |
16417 | { | |
559a7a62 | 16418 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
16419 | |
16420 | index = hash & (symtab->size - 1); | |
16421 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
16422 | ||
16423 | for (;;) | |
16424 | { | |
16425 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
16426 | return &symtab->data[index]; | |
16427 | index = (index + step) & (symtab->size - 1); | |
16428 | } | |
16429 | } | |
16430 | ||
16431 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 16432 | |
9291a0cd TT |
16433 | static void |
16434 | hash_expand (struct mapped_symtab *symtab) | |
16435 | { | |
16436 | offset_type old_size = symtab->size; | |
16437 | offset_type i; | |
16438 | struct symtab_index_entry **old_entries = symtab->data; | |
16439 | ||
16440 | symtab->size *= 2; | |
16441 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16442 | ||
16443 | for (i = 0; i < old_size; ++i) | |
16444 | { | |
16445 | if (old_entries[i]) | |
16446 | { | |
16447 | struct symtab_index_entry **slot = find_slot (symtab, | |
16448 | old_entries[i]->name); | |
16449 | *slot = old_entries[i]; | |
16450 | } | |
16451 | } | |
16452 | ||
16453 | xfree (old_entries); | |
16454 | } | |
16455 | ||
16456 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
16457 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 16458 | |
9291a0cd TT |
16459 | static void |
16460 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
16461 | offset_type cu_index) | |
16462 | { | |
16463 | struct symtab_index_entry **slot; | |
16464 | ||
16465 | ++symtab->n_elements; | |
16466 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
16467 | hash_expand (symtab); | |
16468 | ||
16469 | slot = find_slot (symtab, name); | |
16470 | if (!*slot) | |
16471 | { | |
16472 | *slot = XNEW (struct symtab_index_entry); | |
16473 | (*slot)->name = name; | |
16474 | (*slot)->cu_indices = NULL; | |
16475 | } | |
16476 | /* Don't push an index twice. Due to how we add entries we only | |
16477 | have to check the last one. */ | |
16478 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 16479 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
16480 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
16481 | } | |
16482 | ||
16483 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 16484 | |
9291a0cd | 16485 | static offset_type |
3876f04e | 16486 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
16487 | struct symtab_index_entry *entry) |
16488 | { | |
16489 | void **slot; | |
16490 | ||
3876f04e | 16491 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
16492 | if (!*slot) |
16493 | { | |
16494 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
16495 | offset_type val = MAYBE_SWAP (len); | |
16496 | offset_type iter; | |
16497 | int i; | |
16498 | ||
16499 | *slot = entry; | |
16500 | entry->index_offset = obstack_object_size (cpool); | |
16501 | ||
16502 | obstack_grow (cpool, &val, sizeof (val)); | |
16503 | for (i = 0; | |
16504 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
16505 | ++i) | |
16506 | { | |
16507 | val = MAYBE_SWAP (iter); | |
16508 | obstack_grow (cpool, &val, sizeof (val)); | |
16509 | } | |
16510 | } | |
16511 | else | |
16512 | { | |
16513 | struct symtab_index_entry *old_entry = *slot; | |
16514 | entry->index_offset = old_entry->index_offset; | |
16515 | entry = old_entry; | |
16516 | } | |
16517 | return entry->index_offset; | |
16518 | } | |
16519 | ||
16520 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
16521 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 16522 | |
9291a0cd TT |
16523 | static void |
16524 | write_hash_table (struct mapped_symtab *symtab, | |
16525 | struct obstack *output, struct obstack *cpool) | |
16526 | { | |
16527 | offset_type i; | |
3876f04e | 16528 | htab_t symbol_hash_table; |
9291a0cd TT |
16529 | htab_t str_table; |
16530 | ||
3876f04e | 16531 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 16532 | str_table = create_strtab (); |
3876f04e | 16533 | |
9291a0cd TT |
16534 | /* We add all the index vectors to the constant pool first, to |
16535 | ensure alignment is ok. */ | |
16536 | for (i = 0; i < symtab->size; ++i) | |
16537 | { | |
16538 | if (symtab->data[i]) | |
3876f04e | 16539 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
16540 | } |
16541 | ||
16542 | /* Now write out the hash table. */ | |
16543 | for (i = 0; i < symtab->size; ++i) | |
16544 | { | |
16545 | offset_type str_off, vec_off; | |
16546 | ||
16547 | if (symtab->data[i]) | |
16548 | { | |
16549 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
16550 | vec_off = symtab->data[i]->index_offset; | |
16551 | } | |
16552 | else | |
16553 | { | |
16554 | /* While 0 is a valid constant pool index, it is not valid | |
16555 | to have 0 for both offsets. */ | |
16556 | str_off = 0; | |
16557 | vec_off = 0; | |
16558 | } | |
16559 | ||
16560 | str_off = MAYBE_SWAP (str_off); | |
16561 | vec_off = MAYBE_SWAP (vec_off); | |
16562 | ||
16563 | obstack_grow (output, &str_off, sizeof (str_off)); | |
16564 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
16565 | } | |
16566 | ||
16567 | htab_delete (str_table); | |
3876f04e | 16568 | htab_delete (symbol_hash_table); |
9291a0cd TT |
16569 | } |
16570 | ||
0a5429f6 DE |
16571 | /* Struct to map psymtab to CU index in the index file. */ |
16572 | struct psymtab_cu_index_map | |
16573 | { | |
16574 | struct partial_symtab *psymtab; | |
16575 | unsigned int cu_index; | |
16576 | }; | |
16577 | ||
16578 | static hashval_t | |
16579 | hash_psymtab_cu_index (const void *item) | |
16580 | { | |
16581 | const struct psymtab_cu_index_map *map = item; | |
16582 | ||
16583 | return htab_hash_pointer (map->psymtab); | |
16584 | } | |
16585 | ||
16586 | static int | |
16587 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
16588 | { | |
16589 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
16590 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
16591 | ||
16592 | return lhs->psymtab == rhs->psymtab; | |
16593 | } | |
16594 | ||
16595 | /* Helper struct for building the address table. */ | |
16596 | struct addrmap_index_data | |
16597 | { | |
16598 | struct objfile *objfile; | |
16599 | struct obstack *addr_obstack; | |
16600 | htab_t cu_index_htab; | |
16601 | ||
16602 | /* Non-zero if the previous_* fields are valid. | |
16603 | We can't write an entry until we see the next entry (since it is only then | |
16604 | that we know the end of the entry). */ | |
16605 | int previous_valid; | |
16606 | /* Index of the CU in the table of all CUs in the index file. */ | |
16607 | unsigned int previous_cu_index; | |
0963b4bd | 16608 | /* Start address of the CU. */ |
0a5429f6 DE |
16609 | CORE_ADDR previous_cu_start; |
16610 | }; | |
16611 | ||
16612 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 16613 | |
9291a0cd | 16614 | static void |
0a5429f6 DE |
16615 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
16616 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 16617 | { |
0a5429f6 | 16618 | offset_type cu_index_to_write; |
9291a0cd TT |
16619 | char addr[8]; |
16620 | CORE_ADDR baseaddr; | |
16621 | ||
16622 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16623 | ||
0a5429f6 DE |
16624 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
16625 | obstack_grow (obstack, addr, 8); | |
16626 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
16627 | obstack_grow (obstack, addr, 8); | |
16628 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
16629 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
16630 | } | |
16631 | ||
16632 | /* Worker function for traversing an addrmap to build the address table. */ | |
16633 | ||
16634 | static int | |
16635 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
16636 | { | |
16637 | struct addrmap_index_data *data = datap; | |
16638 | struct partial_symtab *pst = obj; | |
16639 | offset_type cu_index; | |
16640 | void **slot; | |
16641 | ||
16642 | if (data->previous_valid) | |
16643 | add_address_entry (data->objfile, data->addr_obstack, | |
16644 | data->previous_cu_start, start_addr, | |
16645 | data->previous_cu_index); | |
16646 | ||
16647 | data->previous_cu_start = start_addr; | |
16648 | if (pst != NULL) | |
16649 | { | |
16650 | struct psymtab_cu_index_map find_map, *map; | |
16651 | find_map.psymtab = pst; | |
16652 | map = htab_find (data->cu_index_htab, &find_map); | |
16653 | gdb_assert (map != NULL); | |
16654 | data->previous_cu_index = map->cu_index; | |
16655 | data->previous_valid = 1; | |
16656 | } | |
16657 | else | |
16658 | data->previous_valid = 0; | |
16659 | ||
16660 | return 0; | |
16661 | } | |
16662 | ||
16663 | /* Write OBJFILE's address map to OBSTACK. | |
16664 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
16665 | in the index file. */ | |
16666 | ||
16667 | static void | |
16668 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
16669 | htab_t cu_index_htab) | |
16670 | { | |
16671 | struct addrmap_index_data addrmap_index_data; | |
16672 | ||
16673 | /* When writing the address table, we have to cope with the fact that | |
16674 | the addrmap iterator only provides the start of a region; we have to | |
16675 | wait until the next invocation to get the start of the next region. */ | |
16676 | ||
16677 | addrmap_index_data.objfile = objfile; | |
16678 | addrmap_index_data.addr_obstack = obstack; | |
16679 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
16680 | addrmap_index_data.previous_valid = 0; | |
16681 | ||
16682 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
16683 | &addrmap_index_data); | |
16684 | ||
16685 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
16686 | is valid, but we should still handle it. | |
16687 | The end address is recorded as the start of the next region, but that | |
16688 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
16689 | anyway. */ | |
16690 | if (addrmap_index_data.previous_valid) | |
16691 | add_address_entry (objfile, obstack, | |
16692 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
16693 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
16694 | } |
16695 | ||
16696 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 16697 | |
9291a0cd TT |
16698 | static void |
16699 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 16700 | htab_t psyms_seen, |
9291a0cd TT |
16701 | struct partial_symbol **psymp, |
16702 | int count, | |
987d643c TT |
16703 | offset_type cu_index, |
16704 | int is_static) | |
9291a0cd TT |
16705 | { |
16706 | for (; count-- > 0; ++psymp) | |
16707 | { | |
987d643c TT |
16708 | void **slot, *lookup; |
16709 | ||
9291a0cd TT |
16710 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
16711 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
16712 | |
16713 | /* We only want to add a given psymbol once. However, we also | |
16714 | want to account for whether it is global or static. So, we | |
16715 | may add it twice, using slightly different values. */ | |
16716 | if (is_static) | |
16717 | { | |
16718 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
16719 | ||
16720 | lookup = (void *) val; | |
16721 | } | |
16722 | else | |
16723 | lookup = *psymp; | |
16724 | ||
16725 | /* Only add a given psymbol once. */ | |
16726 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
16727 | if (!*slot) | |
16728 | { | |
16729 | *slot = lookup; | |
bb2f58dc | 16730 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index); |
987d643c | 16731 | } |
9291a0cd TT |
16732 | } |
16733 | } | |
16734 | ||
16735 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
16736 | exception if there is an error. */ | |
b89be57b | 16737 | |
9291a0cd TT |
16738 | static void |
16739 | write_obstack (FILE *file, struct obstack *obstack) | |
16740 | { | |
16741 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
16742 | file) | |
16743 | != obstack_object_size (obstack)) | |
16744 | error (_("couldn't data write to file")); | |
16745 | } | |
16746 | ||
16747 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 16748 | |
9291a0cd TT |
16749 | static void |
16750 | unlink_if_set (void *p) | |
16751 | { | |
16752 | char **filename = p; | |
16753 | if (*filename) | |
16754 | unlink (*filename); | |
16755 | } | |
16756 | ||
1fd400ff TT |
16757 | /* A helper struct used when iterating over debug_types. */ |
16758 | struct signatured_type_index_data | |
16759 | { | |
16760 | struct objfile *objfile; | |
16761 | struct mapped_symtab *symtab; | |
16762 | struct obstack *types_list; | |
987d643c | 16763 | htab_t psyms_seen; |
1fd400ff TT |
16764 | int cu_index; |
16765 | }; | |
16766 | ||
16767 | /* A helper function that writes a single signatured_type to an | |
16768 | obstack. */ | |
b89be57b | 16769 | |
1fd400ff TT |
16770 | static int |
16771 | write_one_signatured_type (void **slot, void *d) | |
16772 | { | |
16773 | struct signatured_type_index_data *info = d; | |
16774 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
16775 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
16776 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
16777 | gdb_byte val[8]; |
16778 | ||
16779 | write_psymbols (info->symtab, | |
987d643c | 16780 | info->psyms_seen, |
3e43a32a MS |
16781 | info->objfile->global_psymbols.list |
16782 | + psymtab->globals_offset, | |
987d643c TT |
16783 | psymtab->n_global_syms, info->cu_index, |
16784 | 0); | |
1fd400ff | 16785 | write_psymbols (info->symtab, |
987d643c | 16786 | info->psyms_seen, |
3e43a32a MS |
16787 | info->objfile->static_psymbols.list |
16788 | + psymtab->statics_offset, | |
987d643c TT |
16789 | psymtab->n_static_syms, info->cu_index, |
16790 | 1); | |
1fd400ff | 16791 | |
b3c8eb43 | 16792 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset); |
1fd400ff TT |
16793 | obstack_grow (info->types_list, val, 8); |
16794 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
16795 | obstack_grow (info->types_list, val, 8); | |
16796 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
16797 | obstack_grow (info->types_list, val, 8); | |
16798 | ||
16799 | ++info->cu_index; | |
16800 | ||
16801 | return 1; | |
16802 | } | |
16803 | ||
9291a0cd | 16804 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 16805 | |
9291a0cd TT |
16806 | static void |
16807 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
16808 | { | |
16809 | struct cleanup *cleanup; | |
16810 | char *filename, *cleanup_filename; | |
1fd400ff TT |
16811 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
16812 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
16813 | int i; |
16814 | FILE *out_file; | |
16815 | struct mapped_symtab *symtab; | |
16816 | offset_type val, size_of_contents, total_len; | |
16817 | struct stat st; | |
16818 | char buf[8]; | |
987d643c | 16819 | htab_t psyms_seen; |
0a5429f6 DE |
16820 | htab_t cu_index_htab; |
16821 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 16822 | |
b4f2f049 | 16823 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 16824 | return; |
b4f2f049 | 16825 | |
9291a0cd TT |
16826 | if (dwarf2_per_objfile->using_index) |
16827 | error (_("Cannot use an index to create the index")); | |
16828 | ||
8b70b953 TT |
16829 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
16830 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
16831 | ||
9291a0cd | 16832 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 16833 | perror_with_name (objfile->name); |
9291a0cd TT |
16834 | |
16835 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
16836 | INDEX_SUFFIX, (char *) NULL); | |
16837 | cleanup = make_cleanup (xfree, filename); | |
16838 | ||
16839 | out_file = fopen (filename, "wb"); | |
16840 | if (!out_file) | |
16841 | error (_("Can't open `%s' for writing"), filename); | |
16842 | ||
16843 | cleanup_filename = filename; | |
16844 | make_cleanup (unlink_if_set, &cleanup_filename); | |
16845 | ||
16846 | symtab = create_mapped_symtab (); | |
16847 | make_cleanup (cleanup_mapped_symtab, symtab); | |
16848 | ||
16849 | obstack_init (&addr_obstack); | |
16850 | make_cleanup_obstack_free (&addr_obstack); | |
16851 | ||
16852 | obstack_init (&cu_list); | |
16853 | make_cleanup_obstack_free (&cu_list); | |
16854 | ||
1fd400ff TT |
16855 | obstack_init (&types_cu_list); |
16856 | make_cleanup_obstack_free (&types_cu_list); | |
16857 | ||
987d643c TT |
16858 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
16859 | NULL, xcalloc, xfree); | |
96408a79 | 16860 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 16861 | |
0a5429f6 DE |
16862 | /* While we're scanning CU's create a table that maps a psymtab pointer |
16863 | (which is what addrmap records) to its index (which is what is recorded | |
16864 | in the index file). This will later be needed to write the address | |
16865 | table. */ | |
16866 | cu_index_htab = htab_create_alloc (100, | |
16867 | hash_psymtab_cu_index, | |
16868 | eq_psymtab_cu_index, | |
16869 | NULL, xcalloc, xfree); | |
96408a79 | 16870 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
16871 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
16872 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
16873 | * dwarf2_per_objfile->n_comp_units); | |
16874 | make_cleanup (xfree, psymtab_cu_index_map); | |
16875 | ||
16876 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
16877 | work here. Also, the debug_types entries do not appear in |
16878 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
16879 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
16880 | { | |
3e43a32a MS |
16881 | struct dwarf2_per_cu_data *per_cu |
16882 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 16883 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 16884 | gdb_byte val[8]; |
0a5429f6 DE |
16885 | struct psymtab_cu_index_map *map; |
16886 | void **slot; | |
9291a0cd TT |
16887 | |
16888 | write_psymbols (symtab, | |
987d643c | 16889 | psyms_seen, |
9291a0cd | 16890 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
16891 | psymtab->n_global_syms, i, |
16892 | 0); | |
9291a0cd | 16893 | write_psymbols (symtab, |
987d643c | 16894 | psyms_seen, |
9291a0cd | 16895 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
16896 | psymtab->n_static_syms, i, |
16897 | 1); | |
9291a0cd | 16898 | |
0a5429f6 DE |
16899 | map = &psymtab_cu_index_map[i]; |
16900 | map->psymtab = psymtab; | |
16901 | map->cu_index = i; | |
16902 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
16903 | gdb_assert (slot != NULL); | |
16904 | gdb_assert (*slot == NULL); | |
16905 | *slot = map; | |
9291a0cd | 16906 | |
e254ef6a | 16907 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 16908 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 16909 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
16910 | obstack_grow (&cu_list, val, 8); |
16911 | } | |
16912 | ||
0a5429f6 DE |
16913 | /* Dump the address map. */ |
16914 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
16915 | ||
1fd400ff TT |
16916 | /* Write out the .debug_type entries, if any. */ |
16917 | if (dwarf2_per_objfile->signatured_types) | |
16918 | { | |
16919 | struct signatured_type_index_data sig_data; | |
16920 | ||
16921 | sig_data.objfile = objfile; | |
16922 | sig_data.symtab = symtab; | |
16923 | sig_data.types_list = &types_cu_list; | |
987d643c | 16924 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
16925 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
16926 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
16927 | write_one_signatured_type, &sig_data); | |
16928 | } | |
16929 | ||
9291a0cd TT |
16930 | obstack_init (&constant_pool); |
16931 | make_cleanup_obstack_free (&constant_pool); | |
16932 | obstack_init (&symtab_obstack); | |
16933 | make_cleanup_obstack_free (&symtab_obstack); | |
16934 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
16935 | ||
16936 | obstack_init (&contents); | |
16937 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 16938 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
16939 | total_len = size_of_contents; |
16940 | ||
16941 | /* The version number. */ | |
559a7a62 | 16942 | val = MAYBE_SWAP (5); |
9291a0cd TT |
16943 | obstack_grow (&contents, &val, sizeof (val)); |
16944 | ||
16945 | /* The offset of the CU list from the start of the file. */ | |
16946 | val = MAYBE_SWAP (total_len); | |
16947 | obstack_grow (&contents, &val, sizeof (val)); | |
16948 | total_len += obstack_object_size (&cu_list); | |
16949 | ||
1fd400ff TT |
16950 | /* The offset of the types CU list from the start of the file. */ |
16951 | val = MAYBE_SWAP (total_len); | |
16952 | obstack_grow (&contents, &val, sizeof (val)); | |
16953 | total_len += obstack_object_size (&types_cu_list); | |
16954 | ||
9291a0cd TT |
16955 | /* The offset of the address table from the start of the file. */ |
16956 | val = MAYBE_SWAP (total_len); | |
16957 | obstack_grow (&contents, &val, sizeof (val)); | |
16958 | total_len += obstack_object_size (&addr_obstack); | |
16959 | ||
16960 | /* The offset of the symbol table from the start of the file. */ | |
16961 | val = MAYBE_SWAP (total_len); | |
16962 | obstack_grow (&contents, &val, sizeof (val)); | |
16963 | total_len += obstack_object_size (&symtab_obstack); | |
16964 | ||
16965 | /* The offset of the constant pool from the start of the file. */ | |
16966 | val = MAYBE_SWAP (total_len); | |
16967 | obstack_grow (&contents, &val, sizeof (val)); | |
16968 | total_len += obstack_object_size (&constant_pool); | |
16969 | ||
16970 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
16971 | ||
16972 | write_obstack (out_file, &contents); | |
16973 | write_obstack (out_file, &cu_list); | |
1fd400ff | 16974 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
16975 | write_obstack (out_file, &addr_obstack); |
16976 | write_obstack (out_file, &symtab_obstack); | |
16977 | write_obstack (out_file, &constant_pool); | |
16978 | ||
16979 | fclose (out_file); | |
16980 | ||
16981 | /* We want to keep the file, so we set cleanup_filename to NULL | |
16982 | here. See unlink_if_set. */ | |
16983 | cleanup_filename = NULL; | |
16984 | ||
16985 | do_cleanups (cleanup); | |
16986 | } | |
16987 | ||
90476074 TT |
16988 | /* Implementation of the `save gdb-index' command. |
16989 | ||
16990 | Note that the file format used by this command is documented in the | |
16991 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 16992 | |
9291a0cd TT |
16993 | static void |
16994 | save_gdb_index_command (char *arg, int from_tty) | |
16995 | { | |
16996 | struct objfile *objfile; | |
16997 | ||
16998 | if (!arg || !*arg) | |
96d19272 | 16999 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
17000 | |
17001 | ALL_OBJFILES (objfile) | |
17002 | { | |
17003 | struct stat st; | |
17004 | ||
17005 | /* If the objfile does not correspond to an actual file, skip it. */ | |
17006 | if (stat (objfile->name, &st) < 0) | |
17007 | continue; | |
17008 | ||
17009 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
17010 | if (dwarf2_per_objfile) | |
17011 | { | |
17012 | volatile struct gdb_exception except; | |
17013 | ||
17014 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
17015 | { | |
17016 | write_psymtabs_to_index (objfile, arg); | |
17017 | } | |
17018 | if (except.reason < 0) | |
17019 | exception_fprintf (gdb_stderr, except, | |
17020 | _("Error while writing index for `%s': "), | |
17021 | objfile->name); | |
17022 | } | |
17023 | } | |
dce234bc PP |
17024 | } |
17025 | ||
9291a0cd TT |
17026 | \f |
17027 | ||
9eae7c52 TT |
17028 | int dwarf2_always_disassemble; |
17029 | ||
17030 | static void | |
17031 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
17032 | struct cmd_list_element *c, const char *value) | |
17033 | { | |
3e43a32a MS |
17034 | fprintf_filtered (file, |
17035 | _("Whether to always disassemble " | |
17036 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
17037 | value); |
17038 | } | |
17039 | ||
900e11f9 JK |
17040 | static void |
17041 | show_check_physname (struct ui_file *file, int from_tty, | |
17042 | struct cmd_list_element *c, const char *value) | |
17043 | { | |
17044 | fprintf_filtered (file, | |
17045 | _("Whether to check \"physname\" is %s.\n"), | |
17046 | value); | |
17047 | } | |
17048 | ||
6502dd73 DJ |
17049 | void _initialize_dwarf2_read (void); |
17050 | ||
17051 | void | |
17052 | _initialize_dwarf2_read (void) | |
17053 | { | |
96d19272 JK |
17054 | struct cmd_list_element *c; |
17055 | ||
dce234bc | 17056 | dwarf2_objfile_data_key |
c1bd65d0 | 17057 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 17058 | |
1bedd215 AC |
17059 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
17060 | Set DWARF 2 specific variables.\n\ | |
17061 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17062 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
17063 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
17064 | ||
1bedd215 AC |
17065 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
17066 | Show DWARF 2 specific variables\n\ | |
17067 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17068 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
17069 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
17070 | ||
17071 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
17072 | &dwarf2_max_cache_age, _("\ |
17073 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17074 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17075 | A higher limit means that cached compilation units will be stored\n\ | |
17076 | in memory longer, and more total memory will be used. Zero disables\n\ | |
17077 | caching, which can slow down startup."), | |
2c5b56ce | 17078 | NULL, |
920d2a44 | 17079 | show_dwarf2_max_cache_age, |
2c5b56ce | 17080 | &set_dwarf2_cmdlist, |
ae038cb0 | 17081 | &show_dwarf2_cmdlist); |
d97bc12b | 17082 | |
9eae7c52 TT |
17083 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
17084 | &dwarf2_always_disassemble, _("\ | |
17085 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
17086 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
17087 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
17088 | syntax. When disabled, expressions will be printed in a more\n\ | |
17089 | conversational style, when possible."), | |
17090 | NULL, | |
17091 | show_dwarf2_always_disassemble, | |
17092 | &set_dwarf2_cmdlist, | |
17093 | &show_dwarf2_cmdlist); | |
17094 | ||
d97bc12b DE |
17095 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
17096 | Set debugging of the dwarf2 DIE reader."), _("\ | |
17097 | Show debugging of the dwarf2 DIE reader."), _("\ | |
17098 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
17099 | The value is the maximum depth to print."), | |
17100 | NULL, | |
17101 | NULL, | |
17102 | &setdebuglist, &showdebuglist); | |
9291a0cd | 17103 | |
900e11f9 JK |
17104 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
17105 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
17106 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
17107 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
17108 | the demangler."), | |
17109 | NULL, show_check_physname, | |
17110 | &setdebuglist, &showdebuglist); | |
17111 | ||
96d19272 | 17112 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 17113 | _("\ |
fc1a9d6e | 17114 | Save a gdb-index file.\n\ |
11570e71 | 17115 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
17116 | &save_cmdlist); |
17117 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 17118 | } |